{"version":3,"file":"Composed.mjs","sources":["../../../src/filters/Composed.ts"],"sourcesContent":["import { BaseFilter } from './BaseFilter';\nimport type { T2DPipelineState, TWebGLPipelineState } from './typedefs';\nimport { isWebGLPipelineState } from './utils';\nimport { classRegistry } from '../ClassRegistry';\n\n/**\n * A container class that knows how to apply a sequence of filters to an input image.\n */\nexport class Composed extends BaseFilter {\n  /**\n   * A non sparse array of filters to apply\n   */\n  declare subFilters: BaseFilter[];\n\n  static type = 'Composed';\n\n  constructor({\n    subFilters = [],\n    ...options\n  }: { subFilters?: BaseFilter[] } & Record<string, any> = {}) {\n    super(options);\n    this.subFilters = subFilters;\n  }\n\n  /**\n   * Apply this container's filters to the input image provided.\n   *\n   * @param {Object} options\n   * @param {Number} options.passes The number of filters remaining to be applied.\n   */\n  applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n    if (isWebGLPipelineState(options)) {\n      options.passes += this.subFilters.length - 1;\n    }\n    this.subFilters.forEach((filter) => {\n      filter.applyTo(options);\n    });\n  }\n\n  /**\n   * Serialize this filter into JSON.\n   *\n   * @returns {Object} A JSON representation of this filter.\n   */\n  toObject() {\n    return {\n      ...super.toObject(),\n      subFilters: this.subFilters.map((filter) => filter.toObject()),\n    };\n  }\n\n  isNeutralState() {\n    return !this.subFilters.some((filter) => !filter.isNeutralState());\n  }\n\n  /**\n   * Deserialize a JSON definition of a ComposedFilter into a concrete instance.\n   * @static\n   * @param {oject} object Object to create an instance from\n   * @param {object} [options]\n   * @param {AbortSignal} [options.signal] handle aborting `BlendImage` filter loading, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal\n   * @returns {Promise<Composed>}\n   */\n  static fromObject(\n    object: Record<string, any>,\n    options: { signal: AbortSignal }\n  ) {\n    return Promise.all(\n      ((object.subFilters || []) as BaseFilter[]).map((filter) =>\n        classRegistry\n          .getClass<typeof BaseFilter>(filter.type)\n          .fromObject(filter, options)\n      )\n    ).then(\n      (enlivedFilters) => new this({ subFilters: enlivedFilters }) as BaseFilter\n    );\n  }\n}\n\nclassRegistry.setClass(Composed);\n"],"names":["Composed","BaseFilter","constructor","_ref","arguments","length","undefined","subFilters","options","_objectWithoutProperties","_excluded","applyTo","isWebGLPipelineState","passes","forEach","filter","toObject","_objectSpread","map","isNeutralState","some","fromObject","object","Promise","all","classRegistry","getClass","type","then","enlivedFilters","_defineProperty","setClass"],"mappings":";;;;;;;AAKA;AACA;AACA;AACO,MAAMA,QAAQ,SAASC,UAAU,CAAC;AAQvCC,EAAAA,WAAWA,GAGkD;AAAA,IAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAJ,EAAE;AAH/C,MAAA;AACVG,QAAAA,UAAU,GAAG,EAAA;AAEsC,OAAC,GAAAJ,IAAA;AADjDK,MAAAA,OAAO,GAAAC,wBAAA,CAAAN,IAAA,EAAAO,SAAA,CAAA,CAAA;IAEV,KAAK,CAACF,OAAO,CAAC,CAAA;IACd,IAAI,CAACD,UAAU,GAAGA,UAAU,CAAA;AAC9B,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;EACEI,OAAOA,CAACH,OAA+C,EAAE;AACvD,IAAA,IAAII,oBAAoB,CAACJ,OAAO,CAAC,EAAE;MACjCA,OAAO,CAACK,MAAM,IAAI,IAAI,CAACN,UAAU,CAACF,MAAM,GAAG,CAAC,CAAA;AAC9C,KAAA;AACA,IAAA,IAAI,CAACE,UAAU,CAACO,OAAO,CAAEC,MAAM,IAAK;AAClCA,MAAAA,MAAM,CAACJ,OAAO,CAACH,OAAO,CAAC,CAAA;AACzB,KAAC,CAAC,CAAA;AACJ,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACEQ,EAAAA,QAAQA,GAAG;IACT,OAAAC,cAAA,CAAAA,cAAA,CAAA,EAAA,EACK,KAAK,CAACD,QAAQ,EAAE,CAAA,EAAA,EAAA,EAAA;AACn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