UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 4.63 kB
{"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\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, object>[] } & Record<\n string,\n any\n > = {},\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 * @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 ): Promise<Composed> {\n return Promise.all(\n ((object.subFilters || []) as BaseFilter<string, object>[]).map(\n (filter) =>\n classRegistry\n .getClass<typeof BaseFilter>(filter.type)\n .fromObject(filter, options),\n ),\n ).then(\n (enlivedFilters) => new this({ subFilters: enlivedFilters }) as Composed,\n );\n }\n}\n\nclassRegistry.setClass(Composed);\n"],"names":["Composed","BaseFilter","constructor","options","arguments","length","undefined","subFilters","applyTo","isWebGLPipelineState","passes","forEach","filter","toObject","type","map","isNeutralState","some","fromObject","object","Promise","all","classRegistry","getClass","then","enlivedFilters","_defineProperty","setClass"],"mappings":";;;;;AAaA;AACA;AACA;AACO,MAAMA,QAAQ,SAASC,UAAU,CAItC;AAQAC,EAAAA,WAAWA,GAKT;AAAA,IAAA,IAJAC,OAGC,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE,CAAA;IAEN,KAAK,CAACD,OAAO,CAAC,CAAA;AACd,IAAA,IAAI,CAACI,UAAU,GAAGJ,OAAO,CAACI,UAAU,IAAI,EAAE,CAAA;AAC5C,GAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;EACEC,OAAOA,CAACL,OAA+C,EAAE;AACvD,IAAA,IAAIM,oBAAoB,CAACN,OAAO,CAAC,EAAE;MACjCA,OAAO,CAACO,MAAM,IAAI,IAAI,CAACH,UAAU,CAACF,MAAM,GAAG,CAAC,CAAA;AAC9C,KAAA;AACA,IAAA,IAAI,CAACE,UAAU,CAACI,OAAO,CAAEC,MAAM,IAAK;AAClCA,MAAAA,MAAM,CAACJ,OAAO,CAACL,OAAO,CAAC,CAAA;AACzB,KAAC,CAAC,CAAA;AACJ,GAAA;;AAEA;AACF;AACA;AACA;AACEU,EAAAA,QAAQA,GAAG;IACT,OAAO;MACLC,IAAI,EAAE,IAAI,CAACA,IAAI;AACfP,MAAAA,UAAU,EAAE,IAAI,CA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