{"version":3,"file":"AnimationRegistry.mjs","names":[],"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"],"mappings":";;;;AAOA,IAAM,oBAAN,cAAgC,MAAqB;;;;;CAKnD,OAAO,SAAwB;EAC7B,MAAM,QAAQ,KAAK,QAAQ,QAAQ;AACnC,UAAQ,MAAM,KAAK,OAAO,OAAO,EAAE;;;;;CAMrC,YAAY;EACV,MAAM,aAAa,KAAK,OAAO,EAAE;AACjC,aAAW,SAAS,cAAc,UAAU,OAAO,CAAC;AACpD,SAAO;;;;;;CAOT,eAAe,QAAsB;AACnC,MAAI,CAAC,OACH,QAAO,EAAE;EAEX,MAAM,aAAa,KAAK,QACrB,cACC;;oBAAU,WAAW,UACpB,OAAO,UAAU,WAAW,cAAA,oBAC1B,UAAU,YAAA,QAAA,sBAAA,KAAA,IAAA,KAAA,IAAA,kBAAyB,YAAW;IACpD;AACD,aAAW,SAAS,cAAc,UAAU,OAAO,CAAC;AACpD,SAAO;;;;;;CAOT,eAAe,QAAiC;AAC9C,MAAI,CAAC,OACH,QAAO,EAAE;EAEX,MAAM,aAAa,KAAK,QAAQ,cAAc,UAAU,WAAW,OAAO;AAC1E,aAAW,SAAS,cAAc,UAAU,OAAO,CAAC;AACpD,SAAO;;;AAIX,MAAa,oBAAoB,IAAI,mBAAmB"}