fabric
Version:
Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.
1 lines • 3.45 kB
Source Map (JSON)
{"version":3,"file":"AnimationRegistry.mjs","sources":["../../../../src/util/animation/AnimationRegistry.ts"],"sourcesContent":["import type { StaticCanvas } from '../../canvas/StaticCanvas';\nimport type { FabricObject } from '../../shapes/Object/FabricObject';\nimport type { AnimationBase } from './AnimationBase';\n\n/**\n * Array holding all running animations\n */\nclass AnimationRegistry extends Array<AnimationBase> {\n /**\n * Remove a single animation using an animation context\n * @param {AnimationBase} context\n */\n remove(context: AnimationBase) {\n const index = this.indexOf(context);\n index > -1 && this.splice(index, 1);\n }\n\n /**\n * Cancel all running animations on the next frame\n */\n cancelAll() {\n const animations = this.splice(0);\n animations.forEach((animation) => animation.abort());\n return animations;\n }\n\n /**\n * Cancel all running animations attached to a canvas on the next frame\n * @param {StaticCanvas} canvas\n */\n cancelByCanvas(canvas: StaticCanvas) {\n if (!canvas) {\n return [];\n }\n const animations = this.filter(\n (animation) =>\n animation.target === canvas ||\n (typeof animation.target === 'object' &&\n (animation.target as FabricObject)?.canvas === canvas),\n );\n animations.forEach((animation) => animation.abort());\n return animations;\n }\n\n /**\n * Cancel all running animations for target on the next frame\n * @param target\n */\n cancelByTarget(target: AnimationBase['target']) {\n if (!target) {\n return [];\n }\n const animations = this.filter((animation) => animation.target === target);\n animations.forEach((animation) => animation.abort());\n return animations;\n }\n}\n\nexport const runningAnimations = new AnimationRegistry();\n"],"names":["AnimationRegistry","Array","remove","context","index","indexOf","splice","cancelAll","animations","forEach","animation","abort","cancelByCanvas","canvas","filter","_animation$target","target","cancelByTarget","runningAnimations"],"mappings":"AAIA;AACA;AACA;AACA,MAAMA,iBAAiB,SAASC,KAAK,CAAgB;AACnD;AACF;AACA;AACA;EACEC,MAAMA,CAACC,OAAsB,EAAE;AAC7B,IAAA,MAAMC,KAAK,GAAG,IAAI,CAACC,OAAO,CAACF,OAAO,CAAC,CAAA;IACnCC,KAAK,G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