{"version":3,"file":"Composed.min.mjs","names":[],"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\ntype ComposedOwnProps = {\n  subFilters: BaseFilter<string, object, object>[];\n};\n\ntype ComposedSerializedProps = {\n  subFilters: Record<string, unknown>[];\n};\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  'Composed',\n  ComposedOwnProps,\n  ComposedSerializedProps\n> {\n  /**\n   * A non sparse array of filters to apply\n   */\n  declare subFilters: ComposedOwnProps['subFilters'];\n\n  static type = 'Composed';\n\n  constructor(\n    options: { subFilters?: BaseFilter<string>[] } & Record<string, any> = {},\n  ) {\n    super(options);\n    this.subFilters = options.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   * @returns {Object} A JSON representation of this filter.\n   */\n  toObject() {\n    return {\n      type: this.type,\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   * @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  ): Promise<Composed> {\n    return Promise.all(\n      ((object.subFilters || []) as BaseFilter<string>[]).map((filter) =>\n        classRegistry\n          .getClass<typeof BaseFilter>(filter.type)\n          .fromObject(filter, options),\n      ),\n    ).then((enlivedFilters) => new this({ subFilters: enlivedFilters }));\n  }\n}\n\nclassRegistry.setClass(Composed);\n"],"mappings":"gRAgBA,IAAa,EAAb,cAA8B,CAAA,CAY5B,YACE,EAAuE,EAAA,CAAA,CAEvE,MAAM,EAAA,CACN,KAAK,WAAa,EAAQ,YAAc,EAAA,CAS1C,QAAQ,EAAA,CACF,EAAqB,EAAA,GACvB,EAAQ,QAAU,KAAK,WAAW,OAAS,GAE7C,KAAK,WAAW,QAAS,GAAA,CACvB,EAAO,QAAQ,EAAA,EAAA,CAQnB,UAAA,CACE,MAAO,CACL,KAAM,KAAK,KACX,WAAY,KAAK,WAAW,IAAK,GAAW,EAAO,UAAA,CAAA,CAAA,CAIvD,gBAAA,CACE,MAAA,CAAQ,KAAK,WAAW,KAAM,GAAA,CAAY,EAAO,gBAAA,CAAA,CAUnD,OAAA,WACE,EACA,EAAA,CAEA,OAAO,QAAQ,KACX,EAAO,YAAc,EAAA,EAA6B,IAAK,GACvD,EACG,SAA4B,EAAO,KAAA,CACnC,WAAW,EAAQ,EAAA,CAAA,CAAA,CAExB,KAAM,GAAmB,IAAI,KAAK,CAAE,WAAY,EAAA,CAAA,CAAA,GAAA,EAAA,EAxD7C,OAAO,WAAA,CA4DhB,EAAc,SAAS,EAAA,CAAA,OAAA,KAAA"}