UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 2.65 kB
{"version":3,"file":"AnimationRegistry.min.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":["runningAnimations","Array","remove","context","index","this","indexOf","splice","cancelAll","animations","forEach","animation","abort","cancelByCanvas","canvas","filter","_animation$target","target","cancelByTarget"],"mappings":"MA0DaA,EAAoB,IAnDjC,cAAgCC,MAK9BC,MAAAA,CAAOC,GACL,MAAMC,EAAQC,KAAKC,QAAQH,GAC3BC,GAAS,GAAKC,KAAKE,OAAOH,EAAO,EACnC,CAKAI,SAAAA,GACE,MAAMC,EAAaJ,KAAKE,OAAO,GAE/B,OADAE,EAAWC,SAASC,GAAcA,EAAUC,UACrCH,CACT,CAMAI,cAAAA,CAAeC,GACb,IAAKA,EACH,MAAO,GAET,MAAML,EAAaJ,KAAKU,QACrBJ,IAAS,IAAAK,EAAA,OACRL,EAAUM,SAAWH,GACQ,iBAArBH,EAAUM,SACC,QAAjBD,EAACL,EAAUM,cAAM,IAAAD,OAAA,EAAjBA,EAAoCF,UAAWA,CAAO,IAG5D,OADAL,EAAWC,SAASC,GAAcA,EAAUC,UACrCH,CACT,CAMAS,cAAAA,CAAeD,GACb,IAAKA,EACH,MAAO,GAET,MAAMR,EAAaJ,KAAKU,QAAQJ,GAAcA,EAAUM,SAAWA,IAEnE,OADAR,EAAWC,SAASC,GAAcA,EAAUC,UACrCH,CACT"}