{"name":"troika-animation","version":"0.50.0","author":{"name":"Jason Johnston","email":"jason.johnston@protectwise.com"},"license":"MIT","_id":"troika-animation@0.50.0","maintainers":[{"name":"lojjic","email":"jason@lojjic.com"}],"homepage":"https://github.com/protectwise/troika#readme","bugs":{"url":"https://github.com/protectwise/troika/issues"},"dist":{"shasum":"461f7ec9b12665e2b8051a47ccb8d2b52a545ea2","tarball":"http://registry-npm.ywwl.com/troika-animation/download/troika-animation-0.50.0.tgz","fileCount":20,"integrity":"sha512-vXA7u/QYuBN04HbzAIFch9dDKu9YsccR71zFji13zxgf8ry0OI080GgCuu05nj3aFkp6FuYNBe6DMUJMnkADJQ==","signatures":[{"sig":"MEUCIC9cE1bY87/dc6USu3WeRqHLQDl1+ZsSpNmKAgusL6MRAiEA0b6mfoOdepE04cf5ZRLOEK2ZCmhJf2KgXHryXnw0cKo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":121204,"size":26806,"noattachment":false,"key":"/troika-animation/-/troika-animation-0.50.0.tgz"},"main":"dist/troika-animation.umd.js","module":"dist/troika-animation.esm.js","gitHead":"57f2e7882ba85389f376bd62d7202355f7fe5d9e","_npmUser":{"name":"lojjic","email":"jason@lojjic.com"},"module:src":"src/index.js","repository":{"url":"git+https://github.com/protectwise/troika.git","type":"git","directory":"packages/troika-animation"},"_npmVersion":"lerna/4.0.0/node@v16.14.0+x64 (darwin)","description":"Troika Animation Utilities","directories":{},"sideEffects":false,"_nodeVersion":"16.14.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/troika-animation_0.50.0_1728687544598_0.8996433860866508","host":"s3://npm-registry-packages"},"readme":"# Troika Animation\n\nThis package provides a small library for \"tweening\" values over time, heavily optimized for performance. It is used by the Troika framework behind the scenes for its declarative `transition` and `animation` features, but can also be used as a standalone library.\n\n## Installation\n\nIf you're using the Troika framework, you don't need to install this directly. If you want to use it standalone, you can get it from [NPM](https://www.npmjs.com/package/troika-animation):\n\n```sh\nnpm install troika-animation\n```\n\n## Usage\n\nTo animate a value, you basically need to:\n\n1. Create a `Tween` describing the start and end values, how the value should change over time, and a callback to invoke on each frame\n2. Create a `Runner`\n3. Start the tween in the runner\n\n### Tween\n\n> See the JSDoc comments in [Tween.js](./src/Tween.js) for more details about each parameter.\n\n```js\nimport { Tween } from 'troika-animation'\n\nfunction onTweenFrame(tweenedValue) {\n  // ...do something with the tweenedValue\n}\n\nconst tween = new Tween(\n  onTweenFrame,  // callback\n  -100,          // fromValue\n  100,           // toValue\n  5000,          // duration in ms\n  0,             // delay\n  'easeOutExpo', // easing\n  1,             // iterations\n  'forward',     // direction\n  'number'       // interpolation\n)\n```\n\n### MultiTween\n\nThis is a specialized `Tween` that, instead of managing a value, manages a list of other `Tween`s. It essentially creates a sub-timeline, whose playback is controlled as a whole. For example you can apply an `easing` to the entire set of tweens as a whole, stretch out their duration, repeat them, etc.\n\n```js\nimport { MultiTween, Tween } from 'troika-animation'\n\nconst tween1 = new Tween(/*...*/)\nconst tween2 = new Tween(/*...*/)\nconst multiTween = new MultiTween(\n  [tween1, tween2], // list of tweens\n  5000,             // duration\n  0,                // delay\n  'easeInOutExpo',  // easing\n  10,               // iterations\n  'alternate'       // direction\n)\n```\n\n### SpringTween\n\n> See the JSDoc comments in [SpringTween.js](./src/SpringTween.js) for more details about each parameter.\n\nThis is a lot like `Tween` but instead of having a fixed duration, its value is transitioned using a simple spring physics simulation.\n\n```js\nimport { SpringTween } from 'troika-animation'\n\nconst tween = new Tween(\n  onTweenFrame,   // callback\n  -100,           // fromValue\n  100,            // toValue\n  {               // spring simulation config, or the name of a preset\n    mass: 1,      // object mass\n    tension: 170, // spring tension force\n    friction: 26  // friction force\n  },\n  0               // delay\n)\n```\n\nThe meanings of the spring configuration parameters match those from [react-spring](https://www.react-spring.io/docs/hooks/api). The [named presets](./src/SpringPresets.js) also match those defined by react-spring.\n\n### Runner\n\n> Also see the JSDoc comments in [Runner.js](./src/Runner.js)\n\n```js\nimport { Tween, Runner } from 'troika-animation'\n\nconst tween = new Tween(/*...*/)\nconst runner = new Runner()\nrunner.start(tween)\n```\n\n\n### Easings\n\nWhen constructing a Tween, the `easing` parameter controls the rate of change over time. You can either specify a string, referring to the name of one of the built-in easing functions, or you can provide a custom easing function.\n\n#### Built-in named easings\n\nThe built-in named easings can be found in [Easings.js](./src/Easings.js). These may be familiar, as they mostly match the ones provided by the popular [jQuery Easing Plugin](https://github.com/danro/jquery-easing/blob/master/jquery.easing.js) and [easings.net](https://easings.net).\n\nThere is also an online [demo of troika-animation easings](https://troika-examples.netlify.app/#easings) that shows the curve for each.\n\n#### Custom easing functions\n\nAn easing function takes a single parameter `t`, which refers to the fraction of time passed in the tween's duration from 0 to 1. It must return a number specifying the progress between the start and end values at `t`; 0 corresponds to the start value and 1 corresponds to the end value. Most easings stay in the range from 0 to 1 but some may exceed it.\n\n\n### Interpolation\n\nThe tween `interpolation` parameter controls how the fractional value returned from the `easing` is applied to the start and end values to calculate the in-between value. In most cases you're probably tweening two numbers, which is handled as the default interpolation. But if you have a different type of value, you may need to change the interpolator.\n\nTwo built-in interpolation types are provided, which can be referred to by their string names (see [Interpolators.js](./src/Interpolators.js))\n\n- `\"number\"` - simple linear interpolation between two numeric values (the default).\n- `\"color\"` - interprets the start/end values as RGB colors, and interpolates each color channel independently. The start/end values can be 24-bit integers or any CSS color string value, and the interpolated values will always be returned as 24-bit integers (8 bits red, 8 bits green, 8 bits blue.)\n\nIf you need a different interpolation, you can provide a custom function. Your function will take three parameters: the start value, the end value, and the progress between them (the output of the easing function) in the range from `0` to `1`. It must return an in-between value of the appropriate type.\n","publish_time":1728687544855,"_cnpm_publish_time":1728687544855,"dist-tags":{"latest":"0.53.1"}}