{"_id":"@273do/winertia","_rev":"2-f4263c80372c8d6d3c6c4843797b7b81","name":"@273do/winertia","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@273do/winertia","version":"1.0.0","keywords":["acceleration","drag","motion","physics","position","shake-detection","typescript","velocity","window"],"author":{"name":"273*"},"license":"MIT","_id":"@273do/winertia@1.0.0","maintainers":[{"name":"273do","email":"273dodev@gmail.com"}],"homepage":"https://github.com/273Do/winertia#readme","bugs":{"url":"https://github.com/273Do/winertia/issues"},"dist":{"shasum":"81bbeb23579beb746170831553cc4b72c33efd1b","tarball":"https://registry.npmjs.org/@273do/winertia/-/winertia-1.0.0.tgz","fileCount":8,"integrity":"sha512-xEf+iJ/G9v3luj96Ocsma4AxzQmfaDjOQnf1xrm6Ztz5a5SfTKCk0U7zbOaVMNJE6kdY3dJYWQ0av0LMBn+QTg==","signatures":[{"sig":"MEUCIQDTQUCAh6o0OR8HBSOpKl7pNG2YEkcq6L15poXXPgat8QIgfoL0iZLV2oKzQh2PBOIhD88nqV0FEmnutubuEa5eXhA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22954},"main":"./dist/index.mjs","type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"}},"gitHead":"b64cefd7f8c948aa716c8ba7d3b5bb74c657c5bf","scripts":{"dev":"vp dev example","test":"vp test run","build":"vp pack"},"_npmUser":{"name":"273do","email":"273dodev@gmail.com"},"overrides":{"vite":"npm:@voidzero-dev/vite-plus-core@0.2.2"},"repository":{"url":"git+https://github.com/273Do/winertia.git","type":"git"},"_npmVersion":"11.18.0","description":"This package measures the position, velocity, acceleration, and direction in real time when you physically drag a browser window.","directories":{},"_nodeVersion":"24.18.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"npm@11.16.0","devDependencies":{"jsdom":"^29.1.1","vite-plus":"0.2.2","typescript":"^6.0.3","@commitlint/cli":"^21.2.0","semantic-release":"^25.0.5","@semantic-release/git":"^10.0.1","@semantic-release/changelog":"^6.0.3","@commitlint/config-conventional":"^21.2.0"},"_npmOperationalInternal":{"tmp":"tmp/winertia_1.0.0_1783148263379_0.5174468761704296","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@273do/winertia","version":"1.1.0","description":"This package measures the position, velocity, acceleration, and direction in real time when you physically drag a browser window.","keywords":["acceleration","drag","motion","physics","position","shake-detection","typescript","velocity","window"],"homepage":"https://github.com/273Do/winertia#readme","bugs":{"url":"https://github.com/273Do/winertia/issues"},"license":"MIT","author":{"name":"273*"},"repository":{"type":"git","url":"git+https://github.com/273Do/winertia.git"},"type":"module","main":"./dist/index.mjs","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"}},"publishConfig":{"access":"public"},"scripts":{"dev":"vp dev example","build":"vp pack","test":"vp test run"},"devDependencies":{"@commitlint/cli":"^21.2.0","@commitlint/config-conventional":"^21.2.0","@semantic-release/changelog":"^6.0.3","@semantic-release/git":"^10.0.1","jsdom":"^29.1.1","semantic-release":"^25.0.5","typescript":"^6.0.3","vite-plus":"0.2.2"},"overrides":{"vite":"npm:@voidzero-dev/vite-plus-core@0.2.2"},"packageManager":"npm@11.16.0","gitHead":"ca803289f6b55764028f8cdb21d6fed540773248","_id":"@273do/winertia@1.1.0","_nodeVersion":"24.18.0","_npmVersion":"11.18.0","dist":{"integrity":"sha512-Y68uczh4dgEwPpsdkJj8iPbf0cohndZ7tLlkf4GfS6wbZQLJzUvgLpn/YYD9Q6AjerrmhDwISeKilaz+wwdLWA==","shasum":"2f61fdeda99f7907be6ee07a6afbc100ca548378","tarball":"https://registry.npmjs.org/@273do/winertia/-/winertia-1.1.0.tgz","fileCount":8,"unpackedSize":25366,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC3Vsb8UBCVLOYcLBG9MXTz7S3bG8B6HFc3ER6wkB+vDgIgNSYpiyyb63cgbYiUczpmUvN3Ii8psTZQky+THJCDo5w="}]},"_npmUser":{"name":"273do","email":"273dodev@gmail.com"},"directories":{},"maintainers":[{"name":"273do","email":"273dodev@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/winertia_1.1.0_1783757467575_0.11042000482907266"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-04T06:57:43.194Z","modified":"2026-07-11T08:11:07.809Z","1.0.0":"2026-07-04T06:57:43.562Z","1.1.0":"2026-07-11T08:11:07.706Z"},"bugs":{"url":"https://github.com/273Do/winertia/issues"},"author":{"name":"273*"},"license":"MIT","homepage":"https://github.com/273Do/winertia#readme","keywords":["acceleration","drag","motion","physics","position","shake-detection","typescript","velocity","window"],"repository":{"type":"git","url":"git+https://github.com/273Do/winertia.git"},"description":"This package measures the position, velocity, acceleration, and direction in real time when you physically drag a browser window.","maintainers":[{"name":"273do","email":"273dodev@gmail.com"}],"readme":"# winertia\n\n[English](./README.md) | [日本語](./README.ja.md)\n\nMeasures the position, velocity, acceleration, and direction in real time when you physically drag a browser window.\n\nhttps://github.com/user-attachments/assets/0a80e880-22ac-4a47-b0c2-5058d45c8176\n\n## Installation\n\n```bash\nnpm install @273do/winertia\n```\n\n## Usage\n\n```ts\nimport { createWindowTracker } from \"@273do/winertia\";\n\nconst tracker = createWindowTracker();\n\nconst loop = () => {\n  const state = tracker.update(performance.now(), 4000);\n\n  if (state) {\n    const {\n      coord,\n      velocity,\n      acceleration,\n      direction,\n      shakeCount,\n      didShake,\n      history,\n      historyLength,\n    } = state;\n\n    console.log(coord);\n    console.log(velocity);\n    console.log(acceleration);\n    console.log(direction);\n    console.log(shakeCount, didShake);\n    console.log(history, historyLength);\n  }\n\n  requestAnimationFrame(loop);\n};\n\nrequestAnimationFrame(loop);\n```\n\n### `createWindowTracker`\n\n```ts\ncreateWindowTracker(options?: WindowTrackerOptions): WindowTrackerObj\n```\n\nCreates a tracker instance. The `options` argument is optional, and so is each of its properties. Returns a `WindowTrackerObj` with the following properties:\n\n| Property           | Type       | Description                                                                                                                                                |\n| ------------------ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `supportsWinertia` | `boolean`  | Whether the current environment supports winertia — requires a non-SSR context, `screenX`/`screenY` availability, and a non-touch (coarse pointer) device. |\n| `update`           | `Function` | Advances the tracker by one frame. See below.                                                                                                              |\n\n| Option               | Type     | Default | Description                                                                               |\n| -------------------- | -------- | ------- | ----------------------------------------------------------------------------------------- |\n| `emaAlpha`           | `number` | `0.25`  | Smoothing factor (0-1) for the exponential moving average used for velocity/acceleration. |\n| `historyLength`      | `number` | `50`    | Maximum number of acceleration samples kept in `history`.                                 |\n| `idleSpeedThreshold` | `number` | `40`    | Speed (px/s) below which direction is considered idle.                                    |\n| `shakeCooldownMs`    | `number` | `300`   | Cooldown (ms) between shake detections.                                                   |\n\n### `update`\n\n```ts\nupdate(now: number, shakeAccelThreshold: number): MotionStateObj | null\n```\n\nAdvances the tracker by one frame and returns the current state. Call this every frame (e.g. inside `requestAnimationFrame`).\n\n| Parameter             | Type     | Description                                                                                             |\n| --------------------- | -------- | ------------------------------------------------------------------------------------------------------- |\n| `now`                 | `number` | Current timestamp, typically `performance.now()`. Used to compute elapsed time since the previous call. |\n| `shakeAccelThreshold` | `number` | Acceleration magnitude (px/s²) above which a shake is detected.                                         |\n\nReturns `null` if `supportsWinertia` is `false`, or if the elapsed time since the previous call is zero or negative (e.g. `update` called twice with the same timestamp). Otherwise returns a `MotionStateObj`:\n\n| Field           | Type                               | Description                                                                    |\n| --------------- | ---------------------------------- | ------------------------------------------------------------------------------ |\n| `coord`         | `{ x, y }`                         | Current window position.                                                       |\n| `velocity`      | `{ x, y, speed }`                  | Smoothed velocity (px/s) and its magnitude.                                    |\n| `acceleration`  | `{ x, y, magnitude }`              | Smoothed acceleration (px/s²) and its magnitude.                               |\n| `direction`     | `{ idle, angleDeg, unitX, unitY }` | Movement direction. `idle` is `true` when speed is below `idleSpeedThreshold`. |\n| `shakeCount`    | `number`                           | Total number of shakes detected so far.                                        |\n| `didShake`      | `boolean`                          | Whether a shake was detected on this call.                                     |\n| `history`       | `{ x, y, magnitude }[]`            | Recent acceleration samples, up to `historyLength`.                            |\n| `historyLength` | `number`                           | The configured history size limit.                                             |\n\n## Disclaimer\n\nI, those associated with me, and any organization or group I belong to accept no responsibility whatsoever for any faults, damages, or defects arising from the use of this work and its accompanying materials. Use it at your own risk.\n","readmeFilename":"README.md"}