@webex/ladon-ts 5.4.5 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/module/index.d.ts +3 -2
  3. package/build/module/index.js +35 -34
  4. package/build/module/index.js.map +1 -1
  5. package/build/module/lib/config-builder.d.ts +1 -1
  6. package/build/module/lib/config-builder.js +59 -58
  7. package/build/module/lib/config-builder.js.map +1 -1
  8. package/build/module/lib/config-types.d.ts +1 -1
  9. package/build/module/lib/config-types.js.map +1 -1
  10. package/build/module/lib/generator-types.d.ts +25 -0
  11. package/build/module/lib/generator.d.ts +2 -74
  12. package/build/module/lib/pipeline.js +16 -26
  13. package/build/module/lib/pipeline.js.map +1 -1
  14. package/build/module/lib/preload.js +4 -4
  15. package/build/module/lib/preload.js.map +1 -1
  16. package/build/module/lib/resource-loader.d.ts +22 -0
  17. package/build/module/lib/resource-loader.js +33 -0
  18. package/build/module/lib/resource-loader.js.map +1 -0
  19. package/build/module/lib/util.d.ts +1 -2
  20. package/build/module/lib/util.js +63 -82
  21. package/build/module/lib/util.js.map +1 -1
  22. package/build/module/lib/version.d.ts +1 -1
  23. package/build/module/lib/version.js +1 -1
  24. package/build/module/lib/version.js.map +1 -1
  25. package/build/module/lib/worker-generator.d.ts +15 -0
  26. package/build/module/lib/worker-generator.js +93 -0
  27. package/build/module/lib/worker-generator.js.map +1 -0
  28. package/build/module/lib/worker-manager.d.ts +41 -0
  29. package/build/module/lib/worker-manager.js +63 -0
  30. package/build/module/lib/worker-manager.js.map +1 -0
  31. package/build/worker/segmentation.js +791 -791
  32. package/build/worker/segmentation.js.map +1 -1
  33. package/package.json +1 -4
  34. package/build/module/lib/generator.js +0 -224
  35. package/build/module/lib/generator.js.map +0 -1
  36. package/build/module/lib/shared-resource-manager.d.ts +0 -93
  37. package/build/module/lib/shared-resource-manager.js +0 -166
  38. package/build/module/lib/shared-resource-manager.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### 5.5.0 (2025-04-16)
6
+
7
+
8
+ ### Features
9
+
10
+ * worker only generator (removes onnx dependency) ([#59](https://github.com/beyonddunbar/ladon-ts/issues/59)) ([0ca4ac9](https://github.com/beyonddunbar/ladon-ts/commit/0ca4ac9bd50855099a1674aa0e19a10e0bf88a3d))
11
+
12
+ ### Bug Fixes
13
+
14
+ * github actions build issue ([#60](https://github.com/beyonddunbar/ladon-ts/issues/60)) ([21b7876](https://github.com/beyonddunbar/ladon-ts/commit/21b7876b1bc8d8a07be5760e2648cef48df6d0b6))
15
+
16
+ ### 5.4.6 (2025-04-07)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **worker:** ensure preload completes before initializing ([#57](https://github.com/beyonddunbar/ladon-ts/issues/57)) ([7483c74](https://github.com/beyonddunbar/ladon-ts/commit/7483c748ae4f1f6f061821ba4b0e853719deb00f))
22
+
5
23
  ### 5.4.5 (2025-03-28)
6
24
 
7
25
 
@@ -3,8 +3,9 @@ export * from './lib/config-builder';
3
3
  export * from './lib/config-types';
4
4
  export * from './lib/generator';
5
5
  export * from './lib/pipeline';
6
+ export * from './lib/preload';
6
7
  export * from './lib/renderer';
8
+ export * from './lib/resource-loader';
9
+ export * from './lib/worker-manager';
7
10
  export * from './lib/util';
8
11
  export * from './lib/version';
9
- export * from './lib/shared-resource-manager';
10
- export * from './lib/preload';
@@ -1,42 +1,43 @@
1
- import { getBlurConfig as o, getConfig as t, getPreloadConfig as a } from "./lib/config.js";
2
- import { ConfigurationBuilder as n } from "./lib/config-builder.js";
3
- import { BlurStrength as m, Quality as i } from "./lib/config-types.js";
4
- import { LocalGenerator as d, NullGenerator as x, WorkerGenerator as g } from "./lib/generator.js";
5
- import { Pipeline as u } from "./lib/pipeline.js";
6
- import { BlurRenderer as h } from "./lib/renderer/blur-renderer.js";
1
+ import { getBlurConfig as o, getConfig as t, getPreloadConfig as p } from "./lib/config.js";
2
+ import { ConfigurationBuilder as m } from "./lib/config-builder.js";
3
+ import { BlurStrength as f, Quality as l } from "./lib/config-types.js";
4
+ import { WorkerGenerator as x } from "./lib/worker-generator.js";
5
+ import { Pipeline as d } from "./lib/pipeline.js";
6
+ import { preload as u } from "./lib/preload.js";
7
+ import { BlurRenderer as c } from "./lib/renderer/blur-renderer.js";
7
8
  import { PassthroughRenderer as B } from "./lib/renderer/passthrough-renderer.js";
8
- import { ReplacementRenderer as I } from "./lib/renderer/replacement-renderer.js";
9
- import { WebGLRenderer as P } from "./lib/renderer/webgl-renderer.js";
10
- import { InterpolationMethod as b, bilinearUpsample as L, compileShader as S, isResolvedUri as k, lanczos3Upsample as z, linkProgram as A, loadAndCacheFile as M, resizeImage as N, toAbsoluteURI as W } from "./lib/util.js";
11
- import { LIB_VERSION as y } from "./lib/version.js";
12
- import { sharedResourceManager as F } from "./lib/shared-resource-manager.js";
13
- import { preload as Q } from "./lib/preload.js";
9
+ import { ReplacementRenderer as k } from "./lib/renderer/replacement-renderer.js";
10
+ import { WebGLRenderer as L } from "./lib/renderer/webgl-renderer.js";
11
+ import { ResourceLoader as U, resourceLoader as b } from "./lib/resource-loader.js";
12
+ import { WorkerManager as S, workerManager as W } from "./lib/worker-manager.js";
13
+ import { InterpolationMethod as G, bilinearUpsample as v, compileShader as w, isResolvedUri as y, lanczos3Upsample as A, linkProgram as E, resizeImage as N, toAbsoluteURI as O } from "./lib/util.js";
14
+ import { LIB_VERSION as V } from "./lib/version.js";
14
15
  export {
15
- h as BlurRenderer,
16
- m as BlurStrength,
17
- n as ConfigurationBuilder,
18
- b as InterpolationMethod,
19
- y as LIB_VERSION,
20
- d as LocalGenerator,
21
- x as NullGenerator,
16
+ c as BlurRenderer,
17
+ f as BlurStrength,
18
+ m as ConfigurationBuilder,
19
+ G as InterpolationMethod,
20
+ V as LIB_VERSION,
22
21
  B as PassthroughRenderer,
23
- u as Pipeline,
24
- i as Quality,
25
- I as ReplacementRenderer,
26
- P as WebGLRenderer,
27
- g as WorkerGenerator,
28
- L as bilinearUpsample,
29
- S as compileShader,
22
+ d as Pipeline,
23
+ l as Quality,
24
+ k as ReplacementRenderer,
25
+ U as ResourceLoader,
26
+ L as WebGLRenderer,
27
+ x as WorkerGenerator,
28
+ S as WorkerManager,
29
+ v as bilinearUpsample,
30
+ w as compileShader,
30
31
  o as getBlurConfig,
31
32
  t as getConfig,
32
- a as getPreloadConfig,
33
- k as isResolvedUri,
34
- z as lanczos3Upsample,
35
- A as linkProgram,
36
- M as loadAndCacheFile,
37
- Q as preload,
33
+ p as getPreloadConfig,
34
+ y as isResolvedUri,
35
+ A as lanczos3Upsample,
36
+ E as linkProgram,
37
+ u as preload,
38
38
  N as resizeImage,
39
- F as sharedResourceManager,
40
- W as toAbsoluteURI
39
+ b as resourceLoader,
40
+ O as toAbsoluteURI,
41
+ W as workerManager
41
42
  };
42
43
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -86,7 +86,7 @@ export declare class ConfigurationBuilder {
86
86
  setMaskConfig(maskConfig: MaskConfig): ConfigurationBuilder;
87
87
  /**
88
88
  * Sets the mask generator.
89
- * @param generator The generator type ('local' or 'worker').
89
+ * @param generator The generator type (most be 'worker'; 'local' is deprecated).
90
90
  */
91
91
  setMaskGenerator(generator: Generator): ConfigurationBuilder;
92
92
  /**
@@ -1,4 +1,4 @@
1
- import i from "../config.json.js";
1
+ import s from "../config.json.js";
2
2
  import { LIB_VERSION as m } from "./version.js";
3
3
  class a {
4
4
  constructor(e = "prod") {
@@ -39,8 +39,8 @@ class a {
39
39
  * @param height The height of the input.
40
40
  * @param width The width of the input.
41
41
  */
42
- setInputSize(e, t) {
43
- return this.config.input = { height: e, width: t }, this;
42
+ setInputSize(e, r) {
43
+ return this.config.input = { height: e, width: r }, this;
44
44
  }
45
45
  /**
46
46
  * Sets the input configuration.
@@ -77,12 +77,12 @@ class a {
77
77
  * @param blurStrength The blur strength to use.
78
78
  */
79
79
  setBlurStrength(e) {
80
- var r;
81
- const t = a.getBlurConfig(
80
+ var t;
81
+ const r = a.getBlurConfig(
82
82
  e,
83
- (r = this.config.render) == null ? void 0 : r.horizontalMirror
83
+ (t = this.config.render) == null ? void 0 : t.horizontalMirror
84
84
  );
85
- return this.config.render = { ...this.config.render, ...t }, this;
85
+ return this.config.render = { ...this.config.render, ...r }, this;
86
86
  }
87
87
  /**
88
88
  * Sets the blur kernel size.
@@ -133,80 +133,81 @@ class a {
133
133
  }
134
134
  /**
135
135
  * Sets the mask generator.
136
- * @param generator The generator type ('local' or 'worker').
136
+ * @param generator The generator type (most be 'worker'; 'local' is deprecated).
137
137
  */
138
138
  setMaskGenerator(e) {
139
- const t = this.getMaskConfig();
140
- return t.generator = e, this;
139
+ e !== "worker" && console.warn('[ladon-ts] Mask generator must be "worker". "local" is deprecated.');
140
+ const r = this.getMaskConfig();
141
+ return r.generator = e, this;
141
142
  }
142
143
  /**
143
144
  * Sets the mask generation interval in milliseconds.
144
145
  * @param intervalMs The generation interval in milliseconds.
145
146
  */
146
147
  setMaskGenerationIntervalMs(e) {
147
- const t = this.getMaskConfig();
148
- return t.generationIntervalMs = e, this;
148
+ const r = this.getMaskConfig();
149
+ return r.generationIntervalMs = e, this;
149
150
  }
150
151
  /**
151
152
  * Sets the mask model rank.
152
153
  * @param modelRank The model rank to use.
153
154
  */
154
155
  setMaskModelRank(e) {
155
- const t = this.getMaskConfig();
156
- return t.modelRank = e, this;
156
+ const r = this.getMaskConfig();
157
+ return r.modelRank = e, this;
157
158
  }
158
159
  /**
159
160
  * Sets the mask model URI.
160
161
  * @param modelUri The model URI to use.
161
162
  */
162
163
  setMaskModelUri(e) {
163
- const t = this.getMaskConfig();
164
- return t.modelUri = e, this;
164
+ const r = this.getMaskConfig();
165
+ return r.modelUri = e, this;
165
166
  }
166
167
  /**
167
168
  * Sets the mask worker URI.
168
169
  * @param workerUri The worker URI to use.
169
170
  */
170
171
  setMaskWorkerUri(e) {
171
- const t = this.getMaskConfig();
172
- return t.workerUri = e, this;
172
+ const r = this.getMaskConfig();
173
+ return r.workerUri = e, this;
173
174
  }
174
175
  /**
175
176
  * Sets the mask input size.
176
177
  * @param height The height of the mask input.
177
178
  * @param width The width of the mask input.
178
179
  */
179
- setMaskInputSize(e, t) {
180
- const r = this.getMaskConfig();
181
- return r.inputSize = { height: e, width: t }, this;
180
+ setMaskInputSize(e, r) {
181
+ const t = this.getMaskConfig();
182
+ return t.inputSize = { height: e, width: r }, this;
182
183
  }
183
184
  /**
184
185
  * Sets the mask output size.
185
186
  * @param height The height of the mask output.
186
187
  * @param width The width of the mask output.
187
188
  */
188
- setMaskOutputSize(e, t) {
189
- const r = this.getMaskConfig();
190
- return r.outputSize = { height: e, width: t }, this;
189
+ setMaskOutputSize(e, r) {
190
+ const t = this.getMaskConfig();
191
+ return t.outputSize = { height: e, width: r }, this;
191
192
  }
192
193
  /**
193
194
  * Sets the mask upscaled size.
194
195
  * @param height The height of the upscaled mask.
195
196
  * @param width The width of the upscaled mask.
196
197
  */
197
- setMaskUpscaleSize(e, t) {
198
- const r = this.getMaskConfig();
199
- return r.upscaleSize = { height: e, width: t }, this;
198
+ setMaskUpscaleSize(e, r) {
199
+ const t = this.getMaskConfig();
200
+ return t.upscaleSize = { height: e, width: r }, this;
200
201
  }
201
202
  /**
202
203
  * Sets the quality level and updates mask configurations accordingly.
203
204
  * @param quality The desired quality level.
204
205
  */
205
206
  setMaskQuality(e) {
206
- const { modelQualities: t } = i, r = this.getMaskConfig(), s = e.toLowerCase(), o = t[s];
207
+ const { modelQualities: r } = s, t = this.getMaskConfig(), i = e.toLowerCase(), o = r[i];
207
208
  if (!o)
208
209
  throw new Error(`[ladon-ts] - unknown quality option: ${e}`);
209
- return r.qualityKey = s, Object.assign(r, o), this;
210
+ return t.qualityKey = i, Object.assign(t, o), this;
210
211
  }
211
212
  /**
212
213
  * Builds and returns the PreloadConfig or PipelineConfig object.
@@ -216,7 +217,7 @@ class a {
216
217
  *
217
218
  */
218
219
  build(e = !0) {
219
- const t = this.resolveBaseUrl(), r = this.resolveModelUri(), s = this.resolveWasmUri(), o = this.resolveWorkerUri(), l = this.config.input, g = this.config.render, n = this.config.mask, f = this.config.executionProviders, c = this.config.assetUrlResolver;
220
+ const r = this.resolveBaseUrl(), t = this.resolveModelUri(), i = this.resolveWasmUri(), o = this.resolveWorkerUri(), l = this.config.input, g = this.config.render, n = this.config.mask, c = this.config.executionProviders, f = this.config.assetUrlResolver;
220
221
  if (!n)
221
222
  throw new Error("Mask configuration must be set before building the configuration.");
222
223
  const u = {
@@ -226,13 +227,13 @@ class a {
226
227
  inputSize: n.inputSize,
227
228
  outputSize: n.outputSize,
228
229
  upscaleSize: n.upscaleSize,
229
- modelUri: r,
230
+ modelUri: t,
230
231
  workerUri: o
231
232
  }, h = {
232
- assetUrlResolver: c,
233
- executionProviders: f,
234
- baseUrl: t,
235
- wasmUri: s,
233
+ assetUrlResolver: f,
234
+ executionProviders: c,
235
+ baseUrl: r,
236
+ wasmUri: i,
236
237
  mask: u
237
238
  };
238
239
  if (e) {
@@ -258,7 +259,7 @@ class a {
258
259
  * Returns the base URL for the configuration.
259
260
  */
260
261
  resolveBaseUrl() {
261
- return this.config.baseUrl || i.baseUrls[this.env];
262
+ return this.config.baseUrl || s.baseUrls[this.env];
262
263
  }
263
264
  /**
264
265
  * Returns the base URL for the configuration.
@@ -266,30 +267,30 @@ class a {
266
267
  * @returns The base URL for the configuration.
267
268
  */
268
269
  resolveModelUri() {
269
- var t;
270
- if ((t = this.config.mask) != null && t.modelUri)
270
+ var r;
271
+ if ((r = this.config.mask) != null && r.modelUri)
271
272
  return this.config.mask.modelUri;
272
273
  const e = this.getMaskConfig();
273
274
  if (!e.qualityKey)
274
275
  throw new Error("[ladon-ts] No quality set, cannot infer modelFile.");
275
- return this.resolveTemplate(i.modelUrlTemplate, {
276
- BASE_PATH_MODELS: i.basePaths.models,
277
- MODEL_VERSION: i.modelVersion,
278
- MODEL_FILE: i.modelQualities[e.qualityKey].modelFile
276
+ return this.resolveTemplate(s.modelUrlTemplate, {
277
+ BASE_PATH_MODELS: s.basePaths.models,
278
+ MODEL_VERSION: s.modelVersion,
279
+ MODEL_FILE: s.modelQualities[e.qualityKey].modelFile
279
280
  });
280
281
  }
281
282
  resolveWasmUri() {
282
- return this.config.wasmUri ? this.config.wasmUri : this.resolveTemplate(i.wasmPathTemplate, {
283
- BASE_PATH_WASM: i.basePaths.wasm,
284
- ONNX_VERSION: i.onnxVersion
283
+ return this.config.wasmUri ? this.config.wasmUri : this.resolveTemplate(s.wasmPathTemplate, {
284
+ BASE_PATH_WASM: s.basePaths.wasm,
285
+ ONNX_VERSION: s.onnxVersion
285
286
  });
286
287
  }
287
288
  resolveWorkerUri() {
288
289
  var e;
289
- return (e = this.config.mask) != null && e.workerUri ? this.config.mask.workerUri : this.resolveTemplate(i.workerUrlTemplate, {
290
- BASE_PATH_WORKERS: i.basePaths.workers,
290
+ return (e = this.config.mask) != null && e.workerUri ? this.config.mask.workerUri : this.resolveTemplate(s.workerUrlTemplate, {
291
+ BASE_PATH_WORKERS: s.basePaths.workers,
291
292
  LIB_VERSION: a.getLibVersion(),
292
- WORKER_FILE: i.workerFile
293
+ WORKER_FILE: s.workerFile
293
294
  });
294
295
  }
295
296
  /**
@@ -299,11 +300,11 @@ class a {
299
300
  * @param values The values to use for resolution.
300
301
  * @returns The resolved template string.
301
302
  */
302
- resolveTemplate(e, t) {
303
- return e.replace(/\$\{([A-Z_]+)\}/g, (r, s) => {
304
- if (!t[s])
305
- throw new Error(`Missing value for template variable: ${s}`);
306
- return t[s];
303
+ resolveTemplate(e, r) {
304
+ return e.replace(/\$\{([A-Z_]+)\}/g, (t, i) => {
305
+ if (!r[i])
306
+ throw new Error(`Missing value for template variable: ${i}`);
307
+ return r[i];
307
308
  });
308
309
  }
309
310
  /**
@@ -311,14 +312,14 @@ class a {
311
312
  * @param blurStrength The desired blur strength.
312
313
  * @param horizontalMirror Whether to apply horizontal mirroring.
313
314
  */
314
- static getBlurConfig(e, t) {
315
- const r = e.toLowerCase(), s = i.blurStrengths[r];
316
- if (!s)
315
+ static getBlurConfig(e, r) {
316
+ const t = e.toLowerCase(), i = s.blurStrengths[t];
317
+ if (!i)
317
318
  throw new Error(`[ladon-ts] Unknown blur strength: ${e}`);
318
319
  return {
319
320
  type: "blur",
320
- horizontalMirror: t,
321
- ...s
321
+ horizontalMirror: r,
322
+ ...i
322
323
  };
323
324
  }
324
325
  static getPassthroughConfig(e) {
@@ -1 +1 @@
1
- {"version":3,"file":"config-builder.js","sources":["../../../src/lib/config-builder.ts"],"sourcesContent":["import rawConfig from '../config.json';\n\nimport {\n AssetUrlResolver,\n BlurConfig,\n BlurStrength,\n Generator,\n InputConfig,\n MaskConfig,\n PassthroughConfig,\n PipelineConfig,\n PreloadConfig,\n Quality,\n RawConfig,\n RenderConfig,\n} from './config-types';\nimport { LIB_VERSION } from './version';\n\n/**\n * Internal mutable versions of the configurations used within the builder.\n */\ninterface MutableSizeConfig {\n height: number;\n width: number;\n}\n\ninterface MutableRenderConfig {\n type: 'blur' | 'passthrough' | 'replacement';\n horizontalMirror?: boolean;\n}\n\ninterface MutableBlurConfig extends MutableRenderConfig {\n type: 'blur';\n kernelSize: number;\n sigma: number;\n}\n\ninterface MutableReplacementConfig extends MutableRenderConfig {\n type: 'replacement';\n background: HTMLCanvasElement;\n static: boolean;\n // TODO: add reposition args for presentation mode\n}\n\ninterface MutableBaseMaskConfig {\n generator: Generator;\n generationIntervalMs: number;\n modelRank: number;\n modelUri: string;\n workerUri: string;\n inputSize?: MutableSizeConfig;\n outputSize?: MutableSizeConfig;\n upscaleSize?: MutableSizeConfig;\n}\n\ninterface MutableMaskConfig extends MutableBaseMaskConfig {\n inputSize: MutableSizeConfig;\n outputSize: MutableSizeConfig;\n upscaleSize: MutableSizeConfig;\n qualityKey?: keyof RawConfig['modelQualities'];\n}\n\ninterface MutablePipelineConfig {\n baseUrl?: string;\n wasmUri?: string;\n executionProviders?: string[];\n render?: MutableBlurConfig | MutableRenderConfig | MutableReplacementConfig;\n input?: MutableSizeConfig;\n mask?: MutableMaskConfig;\n assetUrlResolver?: AssetUrlResolver;\n}\n\n/**\n * A builder class for creating PipelineConfig instances in a flexible and intuitive way.\n */\nexport class ConfigurationBuilder {\n private config: MutablePipelineConfig = {};\n\n constructor(private env: 'int' | 'prod' = 'prod') {}\n\n /**\n * Sets the base URL for the configuration.\n * @param baseUrl The base URL to use.\n */\n public setBaseUrl(baseUrl: string): ConfigurationBuilder {\n // Remove trailing slashes from the base URL\n this.config.baseUrl = baseUrl.replace(/\\/+$/, '');\n return this;\n }\n\n /**\n * Sets the WASM URI for the configuration.\n * @param wasmUri The WASM URI to use.\n */\n public setWasmUri(wasmUri: string): ConfigurationBuilder {\n this.config.wasmUri = wasmUri;\n return this;\n }\n\n /**\n * Sets the asset URL resolver.\n * @param assetUrlResolver The asset URL resolver to use\n * @returns The current ConfigurationBuilder instance.\n */\n public setAssetUrlResolver(assetUrlResolver: AssetUrlResolver): ConfigurationBuilder {\n this.config.assetUrlResolver = assetUrlResolver;\n return this;\n }\n\n /**\n * Sets the execution providers for the ONNX runtime.\n *\n * @param executionProviders The execution providers to use.\n */\n public setExecutionProviders(executionProviders: string[]): ConfigurationBuilder {\n // Allow a single string to be passed as well. This is useful for setting a single provider.\n // This will convert the string to an array for consistency.\n if (typeof executionProviders === 'string') {\n executionProviders = [executionProviders];\n }\n this.config.executionProviders = executionProviders;\n return this;\n }\n\n /**\n * Sets the input size for the configuration.\n * @param height The height of the input.\n * @param width The width of the input.\n */\n public setInputSize(height: number, width: number): ConfigurationBuilder {\n this.config.input = { height, width };\n return this;\n }\n\n /**\n * Sets the input configuration.\n * @param inputConfig The input configuration to use.\n */\n public setInputConfig(inputConfig: InputConfig): ConfigurationBuilder {\n this.config.input = { ...inputConfig };\n return this;\n }\n\n /**\n * Sets the render configuration.\n * @param renderConfig The render configuration to use.\n */\n public setRenderConfig(renderConfig: RenderConfig): ConfigurationBuilder {\n this.config.render = { ...renderConfig } as MutableRenderConfig;\n return this;\n }\n\n /**\n * Sets the render type.\n * @param type The render type ('blur', 'passthrough', 'replacement').\n */\n public setRenderType(type: 'blur' | 'passthrough' | 'replacement'): ConfigurationBuilder {\n if (!this.config.render) {\n this.config.render = { type };\n } else {\n this.config.render.type = type;\n }\n return this;\n }\n\n /**\n * Sets the horizontal mirror property for the render configuration.\n * @param horizontalMirror Boolean indicating if horizontal mirror should be applied.\n */\n public setRenderHorizontalMirror(horizontalMirror: boolean): ConfigurationBuilder {\n if (!this.config.render) {\n throw new Error('Render config must be set before setting horizontal mirror.');\n }\n this.config.render.horizontalMirror = horizontalMirror;\n return this;\n }\n\n /**\n * Sets the blur strength for the render configuration.\n * @param blurStrength The blur strength to use.\n */\n public setBlurStrength(blurStrength: BlurStrength): ConfigurationBuilder {\n const blurConfig = ConfigurationBuilder.getBlurConfig(\n blurStrength,\n this.config.render?.horizontalMirror\n );\n this.config.render = { ...this.config.render, ...blurConfig };\n return this;\n }\n\n /**\n * Sets the blur kernel size.\n * @param kernelSize The kernel size for the blur effect.\n */\n public setBlurKernelSize(kernelSize: number): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'blur') {\n throw new Error('Render config must be of type blur to set blur properties.');\n }\n (this.config.render as MutableBlurConfig).kernelSize = kernelSize;\n return this;\n }\n\n /**\n * Sets the blur sigma value.\n * @param sigma The sigma value for the blur effect.\n */\n public setBlurSigma(sigma: number): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'blur') {\n throw new Error('Render config must be of type blur to set blur properties.');\n }\n (this.config.render as MutableBlurConfig).sigma = sigma;\n return this;\n }\n\n /**\n * Sets the replacement background.\n * @param background The background to use for replacement.\n */\n public setReplacementBackground(background: HTMLCanvasElement): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'replacement') {\n throw new Error(\n 'Render config must be of type replacement to set replacement properties.'\n );\n }\n (this.config.render as MutableReplacementConfig).background = background;\n return this;\n }\n\n /**\n * Sets the replacement static property.\n * @param isStatic Boolean indicating if the replacement is static.\n */\n public setReplacementStatic(isStatic: boolean): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'replacement') {\n throw new Error(\n 'Render config must be of type replacement to set replacement properties.'\n );\n }\n (this.config.render as MutableReplacementConfig).static = isStatic;\n return this;\n }\n\n /**\n * Sets the mask configuration.\n * @param maskConfig The mask configuration to use.\n */\n public setMaskConfig(maskConfig: MaskConfig): ConfigurationBuilder {\n this.config.mask = { ...maskConfig } as MutableMaskConfig;\n return this;\n }\n\n /**\n * Sets the mask generator.\n * @param generator The generator type ('local' or 'worker').\n */\n public setMaskGenerator(generator: Generator): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.generator = generator;\n return this;\n }\n\n /**\n * Sets the mask generation interval in milliseconds.\n * @param intervalMs The generation interval in milliseconds.\n */\n public setMaskGenerationIntervalMs(intervalMs: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.generationIntervalMs = intervalMs;\n return this;\n }\n\n /**\n * Sets the mask model rank.\n * @param modelRank The model rank to use.\n */\n public setMaskModelRank(modelRank: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.modelRank = modelRank;\n return this;\n }\n\n /**\n * Sets the mask model URI.\n * @param modelUri The model URI to use.\n */\n public setMaskModelUri(modelUri: string): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.modelUri = modelUri;\n return this;\n }\n\n /**\n * Sets the mask worker URI.\n * @param workerUri The worker URI to use.\n */\n public setMaskWorkerUri(workerUri: string): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.workerUri = workerUri;\n return this;\n }\n\n /**\n * Sets the mask input size.\n * @param height The height of the mask input.\n * @param width The width of the mask input.\n */\n public setMaskInputSize(height: number, width: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.inputSize = { height, width };\n return this;\n }\n\n /**\n * Sets the mask output size.\n * @param height The height of the mask output.\n * @param width The width of the mask output.\n */\n public setMaskOutputSize(height: number, width: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.outputSize = { height, width };\n return this;\n }\n\n /**\n * Sets the mask upscaled size.\n * @param height The height of the upscaled mask.\n * @param width The width of the upscaled mask.\n */\n public setMaskUpscaleSize(height: number, width: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.upscaleSize = { height, width };\n return this;\n }\n\n /**\n * Sets the quality level and updates mask configurations accordingly.\n * @param quality The desired quality level.\n */\n public setMaskQuality(quality: Quality): ConfigurationBuilder {\n const { modelQualities } = rawConfig;\n\n const mask = this.getMaskConfig();\n const qualityKey = quality.toLowerCase() as keyof RawConfig['modelQualities'];\n const qualityConfig = modelQualities[qualityKey];\n\n if (!qualityConfig) {\n throw new Error(`[ladon-ts] - unknown quality option: ${quality}`);\n }\n\n // Store the quality key for dynamic resolution later\n mask.qualityKey = qualityKey;\n\n // Copy other quality-specific properties into the mask config\n Object.assign(mask, qualityConfig);\n\n return this;\n }\n\n /**\n * Builds and returns the PreloadConfig or PipelineConfig object.\n *\n * @param requireInputConfig Whether to require the input configuration to be set before building.\n * Input size is not available at preload so this needs to be optional. The default value is true.\n *\n */\n public build(requireInputConfig = true): PipelineConfig | PreloadConfig {\n const baseUrl = this.resolveBaseUrl();\n const modelUri = this.resolveModelUri();\n const wasmUri = this.resolveWasmUri();\n const workerUri = this.resolveWorkerUri();\n\n const input = this.config.input;\n const render = this.config.render;\n const maskConfig = this.config.mask;\n const executionProviders = this.config.executionProviders;\n const assetUrlResolver = this.config.assetUrlResolver;\n\n if (!maskConfig) {\n throw new Error('Mask configuration must be set before building the configuration.');\n }\n\n const mask: MaskConfig = {\n generator: maskConfig.generator,\n generationIntervalMs: maskConfig.generationIntervalMs,\n modelRank: maskConfig.modelRank,\n inputSize: maskConfig.inputSize,\n outputSize: maskConfig.outputSize,\n upscaleSize: maskConfig.upscaleSize,\n modelUri,\n workerUri,\n };\n\n // Build the preload configuration, which is valid for both preload and pipeline.\n const preloadConfig = {\n assetUrlResolver,\n executionProviders,\n baseUrl,\n wasmUri,\n mask,\n };\n\n if (requireInputConfig) {\n if (!input) {\n throw new Error('Input must be set before building the configuration.');\n }\n\n if (!render) {\n throw new Error('Render must be set before building the configuration.');\n }\n\n // Build the full PipelineConfig\n const pipelineConfig = {\n ...preloadConfig,\n input,\n render,\n } as PipelineConfig;\n\n return pipelineConfig;\n }\n\n return preloadConfig as PreloadConfig;\n }\n\n /**\n * Returns the mask configuration, initializing it if necessary.\n */\n private getMaskConfig(): MutableMaskConfig {\n if (!this.config.mask) {\n this.config.mask = {} as MutableMaskConfig;\n }\n return this.config.mask;\n }\n\n /**\n * Returns the base URL for the configuration.\n */\n public resolveBaseUrl(): string {\n // TODO: Do we want to publish the base URL in the raw config? It seems like the models\n // auth service should be responsible for this, or the user should provide the base url.\n return this.config.baseUrl || rawConfig.baseUrls[this.env];\n }\n\n /**\n * Returns the base URL for the configuration.\n *\n * @returns The base URL for the configuration.\n */\n public resolveModelUri(): string {\n // First check if the property is explicitly set in the config, then fallback to rawConfig\n if (this.config.mask?.modelUri) {\n return this.config.mask.modelUri;\n }\n\n const mask = this.getMaskConfig();\n if (!mask.qualityKey) {\n throw new Error('[ladon-ts] No quality set, cannot infer modelFile.');\n }\n\n return this.resolveTemplate(rawConfig.modelUrlTemplate, {\n BASE_PATH_MODELS: rawConfig.basePaths.models,\n MODEL_VERSION: rawConfig.modelVersion,\n MODEL_FILE: rawConfig.modelQualities[mask.qualityKey].modelFile,\n });\n }\n\n public resolveWasmUri(): string {\n // First check if the property is explicitly set in the config, then fallback to rawConfig\n if (this.config.wasmUri) {\n return this.config.wasmUri;\n }\n\n return this.resolveTemplate(rawConfig.wasmPathTemplate, {\n BASE_PATH_WASM: rawConfig.basePaths.wasm,\n ONNX_VERSION: rawConfig.onnxVersion,\n });\n }\n\n public resolveWorkerUri(): string {\n // First check if the property is explicitly set in the config, then fallback to rawConfig\n if (this.config.mask?.workerUri) {\n return this.config.mask.workerUri;\n }\n\n return this.resolveTemplate(rawConfig.workerUrlTemplate, {\n BASE_PATH_WORKERS: rawConfig.basePaths.workers,\n LIB_VERSION: ConfigurationBuilder.getLibVersion(),\n WORKER_FILE: rawConfig.workerFile,\n });\n }\n\n /**\n * Resolves a template string with the specified values.\n *\n * @param template The template string to resolve.\n * @param values The values to use for resolution.\n * @returns The resolved template string.\n */\n private resolveTemplate(template: string, values: Record<string, string>): string {\n return template.replace(/\\$\\{([A-Z_]+)\\}/g, (_, key) => {\n if (!values[key]) {\n throw new Error(`Missing value for template variable: ${key}`);\n }\n return values[key];\n });\n }\n\n /**\n * Generates a blur configuration based on the specified blur strength.\n * @param blurStrength The desired blur strength.\n * @param horizontalMirror Whether to apply horizontal mirroring.\n */\n public static getBlurConfig(\n blurStrength: BlurStrength,\n horizontalMirror?: boolean\n ): BlurConfig {\n const strengthKey = blurStrength.toLowerCase() as keyof RawConfig['blurStrengths'];\n const blurConfig = rawConfig.blurStrengths[strengthKey];\n\n if (!blurConfig) {\n throw new Error(`[ladon-ts] Unknown blur strength: ${blurStrength}`);\n }\n\n return {\n type: 'blur',\n horizontalMirror,\n ...blurConfig,\n };\n }\n\n public static getPassthroughConfig(horizontalMirror?: boolean): PassthroughConfig {\n return {\n type: 'passthrough',\n horizontalMirror,\n };\n }\n\n /**\n * Returns the library version.\n *\n * @returns The library version.\n */\n public static getLibVersion(): string {\n return LIB_VERSION;\n }\n}\n"],"names":["ConfigurationBuilder","env","baseUrl","wasmUri","assetUrlResolver","executionProviders","height","width","inputConfig","renderConfig","type","horizontalMirror","blurStrength","blurConfig","_a","kernelSize","sigma","background","isStatic","maskConfig","generator","mask","intervalMs","modelRank","modelUri","workerUri","quality","modelQualities","rawConfig","qualityKey","qualityConfig","requireInputConfig","input","render","preloadConfig","template","values","_","key","strengthKey","LIB_VERSION"],"mappings":";;AA2EO,MAAMA,EAAqB;AAAA,EAG9B,YAAoBC,IAAsB,QAAQ;AAA9B,SAAA,MAAAA,GAFpB,KAAQ,SAAgC,CAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,WAAWC,GAAuC;AAErD,gBAAK,OAAO,UAAUA,EAAQ,QAAQ,QAAQ,EAAE,GACzC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOJ,WAAWC,GAAuC;AACrD,gBAAK,OAAO,UAAUA,GACf;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,oBAAoBC,GAA0D;AACjF,gBAAK,OAAO,mBAAmBA,GACxB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,sBAAsBC,GAAoD;AAGzE,WAAA,OAAOA,KAAuB,aAC9BA,IAAqB,CAACA,CAAkB,IAE5C,KAAK,OAAO,qBAAqBA,GAC1B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,aAAaC,GAAgBC,GAAqC;AACrE,gBAAK,OAAO,QAAQ,EAAE,QAAAD,GAAQ,OAAAC,EAAM,GAC7B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOJ,eAAeC,GAAgD;AAClE,gBAAK,OAAO,QAAQ,EAAE,GAAGA,EAAY,GAC9B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOJ,gBAAgBC,GAAkD;AACrE,gBAAK,OAAO,SAAS,EAAE,GAAGA,EAAa,GAChC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOJ,cAAcC,GAAoE;AACjF,WAAC,KAAK,OAAO,SAGR,KAAA,OAAO,OAAO,OAAOA,IAFrB,KAAA,OAAO,SAAS,EAAE,MAAAA,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,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUG,gBAAgBO,GAAkBC,GAAwC;AAC9E,WAAOD,EAAS,QAAQ,oBAAoB,CAACE,GAAGC,MAAQ;AAChD,UAAA,CAACF,EAAOE,CAAG;AACX,cAAM,IAAI,MAAM,wCAAwCA,CAAG,EAAE;AAEjE,aAAOF,EAAOE,CAAG;AAAA,IAAA,CACpB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,OAAc,cACV1B,GACAD,GACU;AACJ,UAAA4B,IAAc3B,EAAa,YAAY,GACvCC,IAAae,EAAU,cAAcW,CAAW;AAEtD,QAAI,CAAC1B;AACD,YAAM,IAAI,MAAM,qCAAqCD,CAAY,EAAE;AAGhE,WAAA;AAAA,MACH,MAAM;AAAA,MACN,kBAAAD;AAAA,MACA,GAAGE;AAAA,IACP;AAAA,EAAA;AAAA,EAGJ,OAAc,qBAAqBF,GAA+C;AACvE,WAAA;AAAA,MACH,MAAM;AAAA,MACN,kBAAAA;AAAA,IACJ;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,OAAc,gBAAwB;AAC3B,WAAA6B;AAAA,EAAA;AAEf;"}
1
+ {"version":3,"file":"config-builder.js","sources":["../../../src/lib/config-builder.ts"],"sourcesContent":["import rawConfig from '../config.json';\n\nimport {\n AssetUrlResolver,\n BlurConfig,\n BlurStrength,\n Generator,\n InputConfig,\n MaskConfig,\n PassthroughConfig,\n PipelineConfig,\n PreloadConfig,\n Quality,\n RawConfig,\n RenderConfig,\n} from './config-types';\nimport { LIB_VERSION } from './version';\n\n/**\n * Internal mutable versions of the configurations used within the builder.\n */\ninterface MutableSizeConfig {\n height: number;\n width: number;\n}\n\ninterface MutableRenderConfig {\n type: 'blur' | 'passthrough' | 'replacement';\n horizontalMirror?: boolean;\n}\n\ninterface MutableBlurConfig extends MutableRenderConfig {\n type: 'blur';\n kernelSize: number;\n sigma: number;\n}\n\ninterface MutableReplacementConfig extends MutableRenderConfig {\n type: 'replacement';\n background: HTMLCanvasElement;\n static: boolean;\n // TODO: add reposition args for presentation mode\n}\n\ninterface MutableBaseMaskConfig {\n generator: Generator;\n generationIntervalMs: number;\n modelRank: number;\n modelUri: string;\n workerUri: string;\n inputSize?: MutableSizeConfig;\n outputSize?: MutableSizeConfig;\n upscaleSize?: MutableSizeConfig;\n}\n\ninterface MutableMaskConfig extends MutableBaseMaskConfig {\n inputSize: MutableSizeConfig;\n outputSize: MutableSizeConfig;\n upscaleSize: MutableSizeConfig;\n qualityKey?: keyof RawConfig['modelQualities'];\n}\n\ninterface MutablePipelineConfig {\n baseUrl?: string;\n wasmUri?: string;\n executionProviders?: string[];\n render?: MutableBlurConfig | MutableRenderConfig | MutableReplacementConfig;\n input?: MutableSizeConfig;\n mask?: MutableMaskConfig;\n assetUrlResolver?: AssetUrlResolver;\n}\n\n/**\n * A builder class for creating PipelineConfig instances in a flexible and intuitive way.\n */\nexport class ConfigurationBuilder {\n private config: MutablePipelineConfig = {};\n\n constructor(private env: 'int' | 'prod' = 'prod') {}\n\n /**\n * Sets the base URL for the configuration.\n * @param baseUrl The base URL to use.\n */\n public setBaseUrl(baseUrl: string): ConfigurationBuilder {\n // Remove trailing slashes from the base URL\n this.config.baseUrl = baseUrl.replace(/\\/+$/, '');\n return this;\n }\n\n /**\n * Sets the WASM URI for the configuration.\n * @param wasmUri The WASM URI to use.\n */\n public setWasmUri(wasmUri: string): ConfigurationBuilder {\n this.config.wasmUri = wasmUri;\n return this;\n }\n\n /**\n * Sets the asset URL resolver.\n * @param assetUrlResolver The asset URL resolver to use\n * @returns The current ConfigurationBuilder instance.\n */\n public setAssetUrlResolver(assetUrlResolver: AssetUrlResolver): ConfigurationBuilder {\n this.config.assetUrlResolver = assetUrlResolver;\n return this;\n }\n\n /**\n * Sets the execution providers for the ONNX runtime.\n *\n * @param executionProviders The execution providers to use.\n */\n public setExecutionProviders(executionProviders: string[]): ConfigurationBuilder {\n // Allow a single string to be passed as well. This is useful for setting a single provider.\n // This will convert the string to an array for consistency.\n if (typeof executionProviders === 'string') {\n executionProviders = [executionProviders];\n }\n this.config.executionProviders = executionProviders;\n return this;\n }\n\n /**\n * Sets the input size for the configuration.\n * @param height The height of the input.\n * @param width The width of the input.\n */\n public setInputSize(height: number, width: number): ConfigurationBuilder {\n this.config.input = { height, width };\n return this;\n }\n\n /**\n * Sets the input configuration.\n * @param inputConfig The input configuration to use.\n */\n public setInputConfig(inputConfig: InputConfig): ConfigurationBuilder {\n this.config.input = { ...inputConfig };\n return this;\n }\n\n /**\n * Sets the render configuration.\n * @param renderConfig The render configuration to use.\n */\n public setRenderConfig(renderConfig: RenderConfig): ConfigurationBuilder {\n this.config.render = { ...renderConfig } as MutableRenderConfig;\n return this;\n }\n\n /**\n * Sets the render type.\n * @param type The render type ('blur', 'passthrough', 'replacement').\n */\n public setRenderType(type: 'blur' | 'passthrough' | 'replacement'): ConfigurationBuilder {\n if (!this.config.render) {\n this.config.render = { type };\n } else {\n this.config.render.type = type;\n }\n return this;\n }\n\n /**\n * Sets the horizontal mirror property for the render configuration.\n * @param horizontalMirror Boolean indicating if horizontal mirror should be applied.\n */\n public setRenderHorizontalMirror(horizontalMirror: boolean): ConfigurationBuilder {\n if (!this.config.render) {\n throw new Error('Render config must be set before setting horizontal mirror.');\n }\n this.config.render.horizontalMirror = horizontalMirror;\n return this;\n }\n\n /**\n * Sets the blur strength for the render configuration.\n * @param blurStrength The blur strength to use.\n */\n public setBlurStrength(blurStrength: BlurStrength): ConfigurationBuilder {\n const blurConfig = ConfigurationBuilder.getBlurConfig(\n blurStrength,\n this.config.render?.horizontalMirror\n );\n this.config.render = { ...this.config.render, ...blurConfig };\n return this;\n }\n\n /**\n * Sets the blur kernel size.\n * @param kernelSize The kernel size for the blur effect.\n */\n public setBlurKernelSize(kernelSize: number): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'blur') {\n throw new Error('Render config must be of type blur to set blur properties.');\n }\n (this.config.render as MutableBlurConfig).kernelSize = kernelSize;\n return this;\n }\n\n /**\n * Sets the blur sigma value.\n * @param sigma The sigma value for the blur effect.\n */\n public setBlurSigma(sigma: number): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'blur') {\n throw new Error('Render config must be of type blur to set blur properties.');\n }\n (this.config.render as MutableBlurConfig).sigma = sigma;\n return this;\n }\n\n /**\n * Sets the replacement background.\n * @param background The background to use for replacement.\n */\n public setReplacementBackground(background: HTMLCanvasElement): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'replacement') {\n throw new Error(\n 'Render config must be of type replacement to set replacement properties.'\n );\n }\n (this.config.render as MutableReplacementConfig).background = background;\n return this;\n }\n\n /**\n * Sets the replacement static property.\n * @param isStatic Boolean indicating if the replacement is static.\n */\n public setReplacementStatic(isStatic: boolean): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'replacement') {\n throw new Error(\n 'Render config must be of type replacement to set replacement properties.'\n );\n }\n (this.config.render as MutableReplacementConfig).static = isStatic;\n return this;\n }\n\n /**\n * Sets the mask configuration.\n * @param maskConfig The mask configuration to use.\n */\n public setMaskConfig(maskConfig: MaskConfig): ConfigurationBuilder {\n this.config.mask = { ...maskConfig } as MutableMaskConfig;\n return this;\n }\n\n /**\n * Sets the mask generator.\n * @param generator The generator type (most be 'worker'; 'local' is deprecated).\n */\n public setMaskGenerator(generator: Generator): ConfigurationBuilder {\n if (generator !== 'worker') {\n console.warn('[ladon-ts] Mask generator must be \"worker\". \"local\" is deprecated.');\n }\n const mask = this.getMaskConfig();\n mask.generator = generator;\n return this;\n }\n\n /**\n * Sets the mask generation interval in milliseconds.\n * @param intervalMs The generation interval in milliseconds.\n */\n public setMaskGenerationIntervalMs(intervalMs: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.generationIntervalMs = intervalMs;\n return this;\n }\n\n /**\n * Sets the mask model rank.\n * @param modelRank The model rank to use.\n */\n public setMaskModelRank(modelRank: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.modelRank = modelRank;\n return this;\n }\n\n /**\n * Sets the mask model URI.\n * @param modelUri The model URI to use.\n */\n public setMaskModelUri(modelUri: string): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.modelUri = modelUri;\n return this;\n }\n\n /**\n * Sets the mask worker URI.\n * @param workerUri The worker URI to use.\n */\n public setMaskWorkerUri(workerUri: string): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.workerUri = workerUri;\n return this;\n }\n\n /**\n * Sets the mask input size.\n * @param height The height of the mask input.\n * @param width The width of the mask input.\n */\n public setMaskInputSize(height: number, width: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.inputSize = { height, width };\n return this;\n }\n\n /**\n * Sets the mask output size.\n * @param height The height of the mask output.\n * @param width The width of the mask output.\n */\n public setMaskOutputSize(height: number, width: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.outputSize = { height, width };\n return this;\n }\n\n /**\n * Sets the mask upscaled size.\n * @param height The height of the upscaled mask.\n * @param width The width of the upscaled mask.\n */\n public setMaskUpscaleSize(height: number, width: number): ConfigurationBuilder {\n const mask = this.getMaskConfig();\n mask.upscaleSize = { height, width };\n return this;\n }\n\n /**\n * Sets the quality level and updates mask configurations accordingly.\n * @param quality The desired quality level.\n */\n public setMaskQuality(quality: Quality): ConfigurationBuilder {\n const { modelQualities } = rawConfig;\n\n const mask = this.getMaskConfig();\n const qualityKey = quality.toLowerCase() as keyof RawConfig['modelQualities'];\n const qualityConfig = modelQualities[qualityKey];\n\n if (!qualityConfig) {\n throw new Error(`[ladon-ts] - unknown quality option: ${quality}`);\n }\n\n // Store the quality key for dynamic resolution later\n mask.qualityKey = qualityKey;\n\n // Copy other quality-specific properties into the mask config\n Object.assign(mask, qualityConfig);\n\n return this;\n }\n\n /**\n * Builds and returns the PreloadConfig or PipelineConfig object.\n *\n * @param requireInputConfig Whether to require the input configuration to be set before building.\n * Input size is not available at preload so this needs to be optional. The default value is true.\n *\n */\n public build(requireInputConfig = true): PipelineConfig | PreloadConfig {\n const baseUrl = this.resolveBaseUrl();\n const modelUri = this.resolveModelUri();\n const wasmUri = this.resolveWasmUri();\n const workerUri = this.resolveWorkerUri();\n\n const input = this.config.input;\n const render = this.config.render;\n const maskConfig = this.config.mask;\n const executionProviders = this.config.executionProviders;\n const assetUrlResolver = this.config.assetUrlResolver;\n\n if (!maskConfig) {\n throw new Error('Mask configuration must be set before building the configuration.');\n }\n\n const mask: MaskConfig = {\n generator: maskConfig.generator,\n generationIntervalMs: maskConfig.generationIntervalMs,\n modelRank: maskConfig.modelRank,\n inputSize: maskConfig.inputSize,\n outputSize: maskConfig.outputSize,\n upscaleSize: maskConfig.upscaleSize,\n modelUri,\n workerUri,\n };\n\n // Build the preload configuration, which is valid for both preload and pipeline.\n const preloadConfig = {\n assetUrlResolver,\n executionProviders,\n baseUrl,\n wasmUri,\n mask,\n };\n\n if (requireInputConfig) {\n if (!input) {\n throw new Error('Input must be set before building the configuration.');\n }\n\n if (!render) {\n throw new Error('Render must be set before building the configuration.');\n }\n\n // Build the full PipelineConfig\n const pipelineConfig = {\n ...preloadConfig,\n input,\n render,\n } as PipelineConfig;\n\n return pipelineConfig;\n }\n\n return preloadConfig as PreloadConfig;\n }\n\n /**\n * Returns the mask configuration, initializing it if necessary.\n */\n private getMaskConfig(): MutableMaskConfig {\n if (!this.config.mask) {\n this.config.mask = {} as MutableMaskConfig;\n }\n return this.config.mask;\n }\n\n /**\n * Returns the base URL for the configuration.\n */\n public resolveBaseUrl(): string {\n // TODO: Do we want to publish the base URL in the raw config? It seems like the models\n // auth service should be responsible for this, or the user should provide the base url.\n return this.config.baseUrl || rawConfig.baseUrls[this.env];\n }\n\n /**\n * Returns the base URL for the configuration.\n *\n * @returns The base URL for the configuration.\n */\n public resolveModelUri(): string {\n // First check if the property is explicitly set in the config, then fallback to rawConfig\n if (this.config.mask?.modelUri) {\n return this.config.mask.modelUri;\n }\n\n const mask = this.getMaskConfig();\n if (!mask.qualityKey) {\n throw new Error('[ladon-ts] No quality set, cannot infer modelFile.');\n }\n\n return this.resolveTemplate(rawConfig.modelUrlTemplate, {\n BASE_PATH_MODELS: rawConfig.basePaths.models,\n MODEL_VERSION: rawConfig.modelVersion,\n MODEL_FILE: rawConfig.modelQualities[mask.qualityKey].modelFile,\n });\n }\n\n public resolveWasmUri(): string {\n // First check if the property is explicitly set in the config, then fallback to rawConfig\n if (this.config.wasmUri) {\n return this.config.wasmUri;\n }\n\n return this.resolveTemplate(rawConfig.wasmPathTemplate, {\n BASE_PATH_WASM: rawConfig.basePaths.wasm,\n ONNX_VERSION: rawConfig.onnxVersion,\n });\n }\n\n public resolveWorkerUri(): string {\n // First check if the property is explicitly set in the config, then fallback to rawConfig\n if (this.config.mask?.workerUri) {\n return this.config.mask.workerUri;\n }\n\n return this.resolveTemplate(rawConfig.workerUrlTemplate, {\n BASE_PATH_WORKERS: rawConfig.basePaths.workers,\n LIB_VERSION: ConfigurationBuilder.getLibVersion(),\n WORKER_FILE: rawConfig.workerFile,\n });\n }\n\n /**\n * Resolves a template string with the specified values.\n *\n * @param template The template string to resolve.\n * @param values The values to use for resolution.\n * @returns The resolved template string.\n */\n private resolveTemplate(template: string, values: Record<string, string>): string {\n return template.replace(/\\$\\{([A-Z_]+)\\}/g, (_, key) => {\n if (!values[key]) {\n throw new Error(`Missing value for template variable: ${key}`);\n }\n return values[key];\n });\n }\n\n /**\n * Generates a blur configuration based on the specified blur strength.\n * @param blurStrength The desired blur strength.\n * @param horizontalMirror Whether to apply horizontal mirroring.\n */\n public static getBlurConfig(\n blurStrength: BlurStrength,\n horizontalMirror?: boolean\n ): BlurConfig {\n const strengthKey = blurStrength.toLowerCase() as keyof RawConfig['blurStrengths'];\n const blurConfig = rawConfig.blurStrengths[strengthKey];\n\n if (!blurConfig) {\n throw new Error(`[ladon-ts] Unknown blur strength: ${blurStrength}`);\n }\n\n return {\n type: 'blur',\n horizontalMirror,\n ...blurConfig,\n };\n }\n\n public static getPassthroughConfig(horizontalMirror?: boolean): PassthroughConfig {\n return {\n type: 'passthrough',\n horizontalMirror,\n };\n }\n\n /**\n * Returns the library version.\n *\n * @returns The library version.\n */\n public static getLibVersion(): string {\n return LIB_VERSION;\n }\n}\n"],"names":["ConfigurationBuilder","env","baseUrl","wasmUri","assetUrlResolver","executionProviders","height","width","inputConfig","renderConfig","type","horizontalMirror","blurStrength","blurConfig","_a","kernelSize","sigma","background","isStatic","maskConfig","generator","mask","intervalMs","modelRank","modelUri","workerUri","quality","modelQualities","rawConfig","qualityKey","qualityConfig","requireInputConfig","input","render","preloadConfig","template","values","_","key","strengthKey","LIB_VERSION"],"mappings":";;AA2EO,MAAMA,EAAqB;AAAA,EAG9B,YAAoBC,IAAsB,QAAQ;AAA9B,SAAA,MAAAA,GAFpB,KAAQ,SAAgC,CAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlC,WAAWC,GAAuC;AAErD,gBAAK,OAAO,UAAUA,EAAQ,QAAQ,QAAQ,EAAE,GACzC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOJ,WAAWC,GAAuC;AACrD,gBAAK,OAAO,UAAUA,GACf;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,oBAAoBC,GAA0D;AACjF,gBAAK,OAAO,mBAAmBA,GACxB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,sBAAsBC,GAAoD;AAGzE,WAAA,OAAOA,KAAuB,aAC9BA,IAAqB,CAACA,CAAkB,IAE5C,KAAK,OAAO,qBAAqBA,GAC1B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,aAAaC,GAAgBC,GAAqC;AACrE,gBAAK,OAAO,QAAQ,EAAE,QAAAD,GAAQ,OAAAC,EAAM,GAC7B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOJ,eAAeC,GAAg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,KAAK,gBAAgBO,EAAU,kBAAkB;AAAA,MACpD,gBAAgBA,EAAU,UAAU;AAAA,MACpC,cAAcA,EAAU;AAAA,IAAA,CAC3B;AAAA,EAAA;AAAA,EAGE,mBAA2B;;AAE1B,YAAAd,IAAA,KAAK,OAAO,SAAZ,QAAAA,EAAkB,YACX,KAAK,OAAO,KAAK,YAGrB,KAAK,gBAAgBc,EAAU,mBAAmB;AAAA,MACrD,mBAAmBA,EAAU,UAAU;AAAA,MACvC,aAAa5B,EAAqB,cAAc;AAAA,MAChD,aAAa4B,EAAU;AAAA,IAAA,CAC1B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUG,gBAAgBO,GAAkBC,GAAwC;AAC9E,WAAOD,EAAS,QAAQ,oBAAoB,CAACE,GAAGC,MAAQ;AAChD,UAAA,CAACF,EAAOE,CAAG;AACX,cAAM,IAAI,MAAM,wCAAwCA,CAAG,EAAE;AAEjE,aAAOF,EAAOE,CAAG;AAAA,IAAA,CACpB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQL,OAAc,cACV1B,GACAD,GACU;AACJ,UAAA4B,IAAc3B,EAAa,YAAY,GACvCC,IAAae,EAAU,cAAcW,CAAW;AAEtD,QAAI,CAAC1B;AACD,YAAM,IAAI,MAAM,qCAAqCD,CAAY,EAAE;AAGhE,WAAA;AAAA,MACH,MAAM;AAAA,MACN,kBAAAD;AAAA,MACA,GAAGE;AAAA,IACP;AAAA,EAAA;AAAA,EAGJ,OAAc,qBAAqBF,GAA+C;AACvE,WAAA;AAAA,MACH,MAAM;AAAA,MACN,kBAAAA;AAAA,IACJ;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,OAAc,gBAAwB;AAC3B,WAAA6B;AAAA,EAAA;AAEf;"}
@@ -48,7 +48,7 @@ export interface ReplacementConfig extends RenderConfig {
48
48
  export interface PassthroughConfig extends RenderConfig {
49
49
  readonly type: 'passthrough';
50
50
  }
51
- export type Generator = 'local' | 'worker';
51
+ export type Generator = 'worker';
52
52
  export type BaseMaskConfig = {
53
53
  readonly generator: Generator;
54
54
  readonly generationIntervalMs: number;
@@ -1 +1 @@
1
- {"version":3,"file":"config-types.js","sources":["../../../src/lib/config-types.ts"],"sourcesContent":["export enum Quality {\n TINY = 'TINY',\n LOW = 'LOW',\n MEDIUM = 'MEDIUM',\n HIGH = 'HIGH',\n ULTRA = 'ULTRA',\n}\n\nexport enum BlurStrength {\n WEAK = 'WEAK',\n MODERATE = 'MODERATE',\n STRONG = 'STRONG',\n STRONGER = 'STRONGER',\n STRONGEST = 'STRONGEST',\n}\n\nexport type ResolutionConfig = {\n readonly height: number;\n readonly width: number;\n};\n\nexport interface SizeConfig {\n readonly inputSize: ResolutionConfig;\n readonly outputSize: ResolutionConfig;\n readonly upscaleSize: ResolutionConfig;\n}\n\nexport interface ModelQualityConfig {\n readonly modelFile: string;\n readonly modelRank: number;\n readonly generationIntervalMs: number;\n readonly inputSize: ResolutionConfig;\n readonly outputSize: ResolutionConfig;\n readonly upscaleSize: ResolutionConfig;\n}\n\nexport type InputConfig = ResolutionConfig;\n\nexport type AssetUrlResolver = (assetUri: string, config: PreloadConfig) => Promise<string>;\n\nexport interface RenderConfig {\n readonly type: 'blur' | 'passthrough' | 'replacement';\n readonly horizontalMirror?: boolean;\n}\n\nexport interface BlurConfig extends RenderConfig {\n readonly type: 'blur';\n readonly kernelSize: number;\n readonly sigma: number;\n}\n\nexport interface ReplacementConfig extends RenderConfig {\n readonly type: 'replacement';\n readonly background: HTMLCanvasElement;\n readonly static: boolean;\n // TODO: add reposition args for presentation mode\n}\n\nexport interface PassthroughConfig extends RenderConfig {\n readonly type: 'passthrough';\n}\n\nexport type Generator = 'local' | 'worker';\n\nexport type BaseMaskConfig = {\n readonly generator: Generator;\n readonly generationIntervalMs: number;\n readonly modelRank: number;\n readonly modelUri: string;\n readonly workerUri: string;\n // These are optional because the input and output sizes are not known when preloading the model.\n // However, the sizes are needed when creating the pipeline to match the models seize requirements.\n readonly inputSize?: ResolutionConfig;\n readonly outputSize?: ResolutionConfig;\n readonly upscaleSize?: ResolutionConfig;\n};\n\nexport type MaskConfig = BaseMaskConfig & SizeConfig;\n\nexport type PreloadConfig = {\n readonly baseUrl?: string;\n readonly wasmUri: string;\n readonly mask: BaseMaskConfig;\n readonly executionProviders?: string[];\n readonly assetUrlResolver?: AssetUrlResolver;\n};\n\nexport type WorkerConfig = Omit<PreloadConfig, 'assetUrlResolver'>;\n\nexport type PipelineConfig = PreloadConfig & {\n readonly render: BlurConfig | RenderConfig | ReplacementConfig;\n readonly input: InputConfig;\n readonly mask: MaskConfig;\n};\n\nexport interface RawConfig {\n readonly baseUrls: {\n readonly int: string;\n readonly prod: string;\n };\n readonly basePaths: {\n readonly models: string;\n readonly wasm: string;\n readonly workers: string;\n };\n readonly blurStrengths: {\n readonly [key in Lowercase<BlurStrength>]: {\n readonly kernelSize: number;\n readonly sigma: number;\n };\n };\n readonly modelQualities: {\n readonly [key in Lowercase<Quality>]: ModelQualityConfig;\n };\n readonly onnxVersion: string;\n readonly modelVersion: string;\n readonly workerFile: string;\n readonly modelUrlTemplate: string;\n readonly wasmPathTemplate: string;\n readonly workerUrlTemplate: string;\n}\n"],"names":["Quality","BlurStrength"],"mappings":"AAAY,IAAAA,sBAAAA,OACRA,EAAA,OAAO,QACPA,EAAA,MAAM,OACNA,EAAA,SAAS,UACTA,EAAA,OAAO,QACPA,EAAA,QAAQ,SALAA,IAAAA,KAAA,CAAA,CAAA,GAQAC,sBAAAA,OACRA,EAAA,OAAO,QACPA,EAAA,WAAW,YACXA,EAAA,SAAS,UACTA,EAAA,WAAW,YACXA,EAAA,YAAY,aALJA,IAAAA,KAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"config-types.js","sources":["../../../src/lib/config-types.ts"],"sourcesContent":["export enum Quality {\n TINY = 'TINY',\n LOW = 'LOW',\n MEDIUM = 'MEDIUM',\n HIGH = 'HIGH',\n ULTRA = 'ULTRA',\n}\n\nexport enum BlurStrength {\n WEAK = 'WEAK',\n MODERATE = 'MODERATE',\n STRONG = 'STRONG',\n STRONGER = 'STRONGER',\n STRONGEST = 'STRONGEST',\n}\n\nexport type ResolutionConfig = {\n readonly height: number;\n readonly width: number;\n};\n\nexport interface SizeConfig {\n readonly inputSize: ResolutionConfig;\n readonly outputSize: ResolutionConfig;\n readonly upscaleSize: ResolutionConfig;\n}\n\nexport interface ModelQualityConfig {\n readonly modelFile: string;\n readonly modelRank: number;\n readonly generationIntervalMs: number;\n readonly inputSize: ResolutionConfig;\n readonly outputSize: ResolutionConfig;\n readonly upscaleSize: ResolutionConfig;\n}\n\nexport type InputConfig = ResolutionConfig;\n\nexport type AssetUrlResolver = (assetUri: string, config: PreloadConfig) => Promise<string>;\n\nexport interface RenderConfig {\n readonly type: 'blur' | 'passthrough' | 'replacement';\n readonly horizontalMirror?: boolean;\n}\n\nexport interface BlurConfig extends RenderConfig {\n readonly type: 'blur';\n readonly kernelSize: number;\n readonly sigma: number;\n}\n\nexport interface ReplacementConfig extends RenderConfig {\n readonly type: 'replacement';\n readonly background: HTMLCanvasElement;\n readonly static: boolean;\n // TODO: add reposition args for presentation mode\n}\n\nexport interface PassthroughConfig extends RenderConfig {\n readonly type: 'passthrough';\n}\n\nexport type Generator = 'worker';\n\nexport type BaseMaskConfig = {\n readonly generator: Generator;\n readonly generationIntervalMs: number;\n readonly modelRank: number;\n readonly modelUri: string;\n readonly workerUri: string;\n // These are optional because the input and output sizes are not known when preloading the model.\n // However, the sizes are needed when creating the pipeline to match the models seize requirements.\n readonly inputSize?: ResolutionConfig;\n readonly outputSize?: ResolutionConfig;\n readonly upscaleSize?: ResolutionConfig;\n};\n\nexport type MaskConfig = BaseMaskConfig & SizeConfig;\n\nexport type PreloadConfig = {\n readonly baseUrl?: string;\n readonly wasmUri: string;\n readonly mask: BaseMaskConfig;\n readonly executionProviders?: string[];\n readonly assetUrlResolver?: AssetUrlResolver;\n};\n\nexport type WorkerConfig = Omit<PreloadConfig, 'assetUrlResolver'>;\n\nexport type PipelineConfig = PreloadConfig & {\n readonly render: BlurConfig | RenderConfig | ReplacementConfig;\n readonly input: InputConfig;\n readonly mask: MaskConfig;\n};\n\nexport interface RawConfig {\n readonly baseUrls: {\n readonly int: string;\n readonly prod: string;\n };\n readonly basePaths: {\n readonly models: string;\n readonly wasm: string;\n readonly workers: string;\n };\n readonly blurStrengths: {\n readonly [key in Lowercase<BlurStrength>]: {\n readonly kernelSize: number;\n readonly sigma: number;\n };\n };\n readonly modelQualities: {\n readonly [key in Lowercase<Quality>]: ModelQualityConfig;\n };\n readonly onnxVersion: string;\n readonly modelVersion: string;\n readonly workerFile: string;\n readonly modelUrlTemplate: string;\n readonly wasmPathTemplate: string;\n readonly workerUrlTemplate: string;\n}\n"],"names":["Quality","BlurStrength"],"mappings":"AAAY,IAAAA,sBAAAA,OACRA,EAAA,OAAO,QACPA,EAAA,MAAM,OACNA,EAAA,SAAS,UACTA,EAAA,OAAO,QACPA,EAAA,QAAQ,SALAA,IAAAA,KAAA,CAAA,CAAA,GAQAC,sBAAAA,OACRA,EAAA,OAAO,QACPA,EAAA,WAAW,YACXA,EAAA,SAAS,UACTA,EAAA,WAAW,YACXA,EAAA,YAAY,aALJA,IAAAA,KAAA,CAAA,CAAA;"}
@@ -0,0 +1,25 @@
1
+ declare global {
2
+ interface ImportMeta {
3
+ url: string;
4
+ }
5
+ }
6
+ export type FrameData = Uint8ClampedArray | HTMLVideoElement;
7
+ export interface FacesAndLandmarks {
8
+ data: Float32Array;
9
+ dims: readonly number[];
10
+ }
11
+ export interface LadonOutput {
12
+ data: Float32Array;
13
+ facesAndLandmarks: FacesAndLandmarks;
14
+ gesture: Float32Array;
15
+ motion: number;
16
+ timestamp: number;
17
+ warm: boolean;
18
+ }
19
+ export interface MaskGenerator {
20
+ getLadonOutput(input: Uint8ClampedArray, timestamp: number): Promise<LadonOutput>;
21
+ load(): Promise<void>;
22
+ isLoaded(): boolean;
23
+ postRender(input: Uint8ClampedArray, timestamp: number): Promise<void>;
24
+ destroy(): void;
25
+ }
@@ -1,74 +1,2 @@
1
- import { PipelineConfig } from './config-types';
2
- declare global {
3
- interface ImportMeta {
4
- url: string;
5
- }
6
- }
7
- export type FrameData = Uint8ClampedArray | HTMLVideoElement;
8
- export interface FacesAndLandmarks {
9
- data: Float32Array;
10
- dims: readonly number[];
11
- }
12
- export interface LadonOutput {
13
- data: Float32Array;
14
- facesAndLandmarks: FacesAndLandmarks;
15
- gesture: Float32Array;
16
- motion: number;
17
- timestamp: number;
18
- warm: boolean;
19
- }
20
- export interface MaskGenerator {
21
- getLadonOutput(input: Uint8ClampedArray, timestamp: number): Promise<LadonOutput>;
22
- load(): Promise<void>;
23
- isLoaded(): boolean;
24
- postRender(input: Uint8ClampedArray, timestamp: number): Promise<void>;
25
- destroy(): void;
26
- }
27
- export declare class LocalGenerator implements MaskGenerator {
28
- readonly config: PipelineConfig;
29
- private lastResult;
30
- private lastMask;
31
- private maskModel?;
32
- private lastMaskGenerationTime;
33
- private output?;
34
- constructor(config: PipelineConfig);
35
- /**
36
- * This method preprocesses an input Uint8ClampedArray to a Float32Array
37
- * while maintaining memory efficiency by reusing a class-scoped output buffer.
38
- * If the model rank is 4 (e.g., newer tiny model), it sets an alpha channel value.
39
- *
40
- * @param {Uint8ClampedArray} input - The input data to be preprocessed
41
- * @param {Float32Array} alpha - The alpha channel data
42
- * @returns {Float32Array} - The processed data
43
- */
44
- private preprocess;
45
- getTimeSinceLastGeneration(): number;
46
- getLadonOutput(input: Uint8ClampedArray, timestamp: number): Promise<LadonOutput>;
47
- load(): Promise<void>;
48
- isLoaded(): boolean;
49
- postRender(_: Uint8ClampedArray): Promise<void>;
50
- destroy(): void;
51
- }
52
- export declare class NullGenerator implements MaskGenerator {
53
- readonly config: PipelineConfig;
54
- private lastMask;
55
- constructor(config: PipelineConfig);
56
- getLadonOutput(_: Uint8ClampedArray): Promise<LadonOutput>;
57
- load(): Promise<void>;
58
- isLoaded(): boolean;
59
- postRender(_: Uint8ClampedArray): Promise<void>;
60
- destroy(): void;
61
- }
62
- export declare class WorkerGenerator implements MaskGenerator {
63
- readonly config: PipelineConfig;
64
- private lastMask;
65
- private newMask;
66
- private worker?;
67
- private lastResult;
68
- constructor(config: PipelineConfig);
69
- getLadonOutput(_: Uint8ClampedArray): Promise<LadonOutput>;
70
- load(): Promise<void>;
71
- isLoaded(): boolean;
72
- postRender(input: Uint8ClampedArray, timestamp: number): Promise<void>;
73
- destroy(): void;
74
- }
1
+ export * from './generator-types';
2
+ export * from './worker-generator';