{"version":3,"file":"animate.mjs","sources":["../../../../src/util/animation/animate.ts"],"sourcesContent":["import { ValueAnimation } from './ValueAnimation';\nimport { ArrayAnimation } from './ArrayAnimation';\nimport { ColorAnimation } from './ColorAnimation';\nimport type {\n  ValueAnimationOptions,\n  ArrayAnimationOptions,\n  ColorAnimationOptions,\n} from './types';\nimport type { TColorArg } from '../../color/typedefs';\n\nexport type TAnimation<T extends number | number[] | TColorArg> =\n  T extends TColorArg\n    ? ColorAnimation\n    : T extends number[]\n      ? ArrayAnimation\n      : ValueAnimation;\n\nconst isArrayAnimation = (\n  options: ArrayAnimationOptions | ValueAnimationOptions,\n): options is ArrayAnimationOptions => {\n  return Array.isArray(options.startValue) || Array.isArray(options.endValue);\n};\n\n/**\n * Changes value(s) from startValue to endValue within a certain period of time,\n * invoking callbacks as the value(s) change.\n *\n * @example\n * animate({\n *   startValue: 1,\n *   endValue: 0,\n *   onChange: (v) => {\n *     obj.set('opacity', v);\n *     // since we are running in a requested frame we should call `renderAll` and not `requestRenderAll`\n *     canvas.renderAll();\n *   }\n * });\n *\n * @example Using lists:\n * animate({\n *   startValue: [1, 2, 3],\n *   endValue: [2, 4, 6],\n *   onChange: ([x, y, zoom]) => {\n *     canvas.zoomToPoint(new Point(x, y), zoom);\n *     canvas.renderAll();\n *   }\n * });\n *\n */\nexport function animate(options: ArrayAnimationOptions): ArrayAnimation;\nexport function animate(options: ValueAnimationOptions): ValueAnimation;\nexport function animate<\n  T extends ValueAnimationOptions | ArrayAnimationOptions,\n>(\n  options: T,\n): T extends ArrayAnimationOptions ? ArrayAnimation : ValueAnimation;\nexport function animate<\n  T extends ValueAnimationOptions | ArrayAnimationOptions,\n  R extends T extends ArrayAnimationOptions ? ArrayAnimation : ValueAnimation,\n>(options: T): R {\n  const animation = (\n    isArrayAnimation(options)\n      ? new ArrayAnimation(options)\n      : new ValueAnimation(options)\n  ) as R;\n  animation.start();\n  return animation;\n}\n\nexport function animateColor(options: ColorAnimationOptions) {\n  const animation = new ColorAnimation(options);\n  animation.start();\n  return animation;\n}\n"],"names":["isArrayAnimation","options","Array","isArray","startValue","endValue","animate","animation","ArrayAnimation","ValueAnimation","start","animateColor","ColorAnimation"],"mappings":";;;;AAiBA,MAAMA,gBAAgB,GACpBC,OAAsD,IACjB;AACrC,EAAA,OAAOC,KAAK,CAACC,OAAO,CAACF,OAAO,CAACG,UAAU,CAAC,IAAIF,KAAK,CAACC,OAAO,CAACF,OAAO,CAACI,QAAQ,CAAC,CAAA;AAC7E,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQO,SAASC,OAAOA,CAGrBL,OAAU,EAAK;AACf,EAAA,MAAMM,SAAS,GACbP,gBAAgB,CAACC,OAAO,CAAC,GACrB,IAAIO,cAAc,CAACP,OAAO,CAAC,GAC3B,IAAIQ,cAAc,CAACR,OAAO,CAC1B,CAAA;EACNM,SAAS,CAACG,KAAK,EAAE,CAAA;AACjB,EAAA,OAAOH,SAAS,CAAA;AAClB,CAAA;AAEO,SAASI,YAAYA,CAACV,OAA8B,EAAE;AAC3D,EAAA,MAAMM,SAAS,GAAG,IAAIK,cAAc,CAACX,OAAO,CAAC,CAAA;EAC7CM,SAAS,CAACG,KAAK,EAAE,CAAA;AACjB,EAAA,OAAOH,SAAS,CAAA;AAClB;;;;"}