{"id":18817858,"url":"https://github.com/vitorluizc/animate","last_synced_at":"2025-04-13T23:25:06.903Z","repository":{"id":57092738,"uuid":"163764391","full_name":"VitorLuizC/animate","owner":"VitorLuizC","description":":space_invader: Create and manage animation functions with AnimationFrame API.","archived":false,"fork":false,"pushed_at":"2022-01-09T20:13:54.000Z","size":227,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T17:05:30.667Z","etag":null,"topics":["animation","bili","game-loop","gameloop","interval","javascript","loop","requestanimationframe","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VitorLuizC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-01T20:28:38.000Z","updated_at":"2024-05-05T14:37:50.000Z","dependencies_parsed_at":"2022-08-22T21:40:31.489Z","dependency_job_id":null,"html_url":"https://github.com/VitorLuizC/animate","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Fanimate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Fanimate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Fanimate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorLuizC%2Fanimate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VitorLuizC","download_url":"https://codeload.github.com/VitorLuizC/animate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248795335,"owners_count":21162750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","bili","game-loop","gameloop","interval","javascript","loop","requestanimationframe","typescript"],"created_at":"2024-11-08T00:13:42.459Z","updated_at":"2025-04-13T23:25:06.878Z","avatar_url":"https://github.com/VitorLuizC.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `@bitty/animate`\n\n![License](https://badgen.net/github/license/VitorLuizC/animate)\n[![Library minified size](https://badgen.net/bundlephobia/min/@bitty/animate)](https://bundlephobia.com/result?p=@bitty/animate)\n[![Library minified + gzipped size](https://badgen.net/bundlephobia/minzip/@bitty/animate)](https://bundlephobia.com/result?p=@bitty/animate)\n\n[![Animate bubbles example GIF](https://user-images.githubusercontent.com/9027363/50610043-b251fe00-0eb8-11e9-9df4-f98da8c3beb0.gif)](https://codepen.io/VitorLuizC/full/WLddER)\n\nCreate and manage animation functions with AnimationFrame API.\n\n- :zap: Dependency free and smaller than **170B** (ESM minified + gzipped);\n- :label: Type definitions to TS developers and IDE/Editors intellisense;\n- :package: CommonJS, ESM and UMD distributions (_CDN uses UMD as default_);\n\n#### See bubbles example at [Codepen](https://codepen.io/VitorLuizC/full/WLddER)\n\n## Installation\n\nThis library is published in the NPM registry and can be installed using any compatible package manager.\n\n```sh\nnpm install @vitorluizc/animate --save\n\n# For Yarn, use the command below.\nyarn add @vitorluizc/animate\n```\n\n### Installation from CDN\n\nThis module has an UMD bundle available through JSDelivr and Unpkg CDNs.\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/@bitty/animate\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  // module will be available through `animate` function.\n\n  var animation = animate(function () {\n    // ...\n  });\n\n  animation.start();\n\u003c/script\u003e\n```\n\n## Usage\n\nCall `animate`, the default exported function, with your callback and use returned object to manage your animation.\n\n```js\nimport animate from '@bitty/animate';\n\nconst canvas = document.querySelector('canvas');\nconst context = canvas.getContext('2d');\nconst position = { x: 0, y: 0 };\n\nconst animation = animate(() =\u003e {\n  context.clearRect(0, 0, canvas.width, canvas.height);\n  context.beginPath();\n  context.arc(position.x, position.y, 100 / 2, 0, 2 * Math.PI);\n  context.fillStyle = '#000000';\n  context.fill();\n  context.closePath();\n});\n\nwindow.addEventListener('mousemove', (event) =\u003e {\n  position.x = event.clientX;\n  position.y = event.clientY;\n});\n\nanimation.start();\n```\n\n\u003e See this example on [Codepen](https://codepen.io/VitorLuizC/pen/jXRzVp).\n\n## API\n\n- **`animate`**\n\n  The default exported function, which receives `callback` as argument and returns an **`Animation`**.\n\n  - `callback` is a **synchronous function** running into a AnimationFrame recursion.\n\n  ```js\n  let count = 0;\n\n  const animation = animate(() =\u003e {\n    context.clearRect(0, 0, element.width, element.height);\n    context.font = '4rem monospace';\n    context.textAlign = 'center';\n    context.fillText(count, element.width / 2, element.height / 2);\n\n    count++;\n  });\n\n  animation.start();\n  ```\n\n  \u003e See this example on [Codepen](https://codepen.io/VitorLuizC/pen/yGrvzP).\n\n  \u003cdetails\u003e\n    \u003csummary\u003eTypeScript type definitions.\u003c/summary\u003e\n\n  \u003cbr /\u003e\n\n  ```ts\n  export default function animate(callback: () =\u003e void): Animation;\n  ```\n\n  \u003c/details\u003e\n\n- **`Animation`**\n\n  An object returned by **`animate`** function to manage your animations. It can start, stop and check if animation is running.\n\n  - **`running`**: A getter property that indicates if animation is running.\n\n  - **`start()`**: A method to start the animation.\n\n  - **`stop()`**: A method to stop the animation.\n\n  ```js\n  const animation = animate(() =\u003e { ... });\n\n  animation.start();\n\n  // Stops the animation after 10s\n  setTimeout(() =\u003e animation.stop(), 10 * 1000);\n\n  if (animation.running)\n    console.log('The animation is running...');\n  ```\n\n  \u003cdetails\u003e\n    \u003csummary\u003eTypeScript type definitions.\u003c/summary\u003e\n\n  \u003cbr /\u003e\n\n  ```ts\n  export interface Animation {\n    readonly running: boolean;\n    stop: () =\u003e void;\n    start: () =\u003e void;\n  }\n  ```\n\n  \u003c/details\u003e\n\n## License\n\nReleased under [MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorluizc%2Fanimate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitorluizc%2Fanimate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorluizc%2Fanimate/lists"}