{"version":3,"file":"AnimationRegistry.min.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":"AA0DA,MAAa,EAAoB,IAnDjC,cAAgC,KAAA,CAK9B,OAAO,EAAA,CACL,IAAM,EAAQ,KAAK,QAAQ,EAAA,CAC3B,EAAA,IAAc,KAAK,OAAO,EAAO,EAAA,CAMnC,WAAA,CACE,IAAM,EAAa,KAAK,OAAO,EAAA,CAE/B,OADA,EAAW,QAAS,GAAc,EAAU,OAAA,CAAA,CACrC,EAOT,eAAe,EAAA,CACb,GAAA,CAAK,EACH,MAAO,EAAA,CAET,IAAM,EAAa,KAAK,OACrB,GAAA,CAAA,IAAA,EAAA,OAAA,EACW,SAAW,GACQ,OAArB,EAAU,QAAW,YAAA,EAC1B,EAAU,SAAA,KAAA,IAAA,GAAA,EAAyB,UAAW,GAAA,CAGrD,OADA,EAAW,QAAS,GAAc,EAAU,OAAA,CAAA,CACrC,EAOT,eAAe,EAAA,CACb,GAAA,CAAK,EACH,MAAO,EAAA,CAET,IAAM,EAAa,KAAK,OAAQ,GAAc,EAAU,SAAW,EAAA,CAEnE,OADA,EAAW,QAAS,GAAc,EAAU,OAAA,CAAA,CACrC,IAAA,OAAA,KAAA"}