@webex/ladon-ts 4.5.1 → 5.0.2

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 (49) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/module/config.json.js +26 -0
  3. package/build/module/config.json.js.map +1 -0
  4. package/build/module/index.d.ts +3 -0
  5. package/build/module/index.js +41 -8
  6. package/build/module/index.js.map +1 -0
  7. package/build/module/lib/config-builder.d.ts +180 -0
  8. package/build/module/lib/config-builder.js +336 -0
  9. package/build/module/lib/config-builder.js.map +1 -0
  10. package/build/module/lib/config-types.d.ts +98 -0
  11. package/build/module/lib/config-types.js +6 -0
  12. package/build/module/lib/config-types.js.map +1 -0
  13. package/build/module/lib/config.d.ts +30 -105
  14. package/build/module/lib/config.js +22 -151
  15. package/build/module/lib/config.js.map +1 -0
  16. package/build/module/lib/generator.d.ts +2 -1
  17. package/build/module/lib/generator.js +212 -273
  18. package/build/module/lib/generator.js.map +1 -0
  19. package/build/module/lib/pipeline.d.ts +3 -2
  20. package/build/module/lib/pipeline.js +158 -218
  21. package/build/module/lib/pipeline.js.map +1 -0
  22. package/build/module/lib/preload.d.ts +9 -0
  23. package/build/module/lib/preload.js +8 -0
  24. package/build/module/lib/preload.js.map +1 -0
  25. package/build/module/lib/renderer/blur-renderer.d.ts +5 -4
  26. package/build/module/lib/renderer/blur-renderer.js +102 -126
  27. package/build/module/lib/renderer/blur-renderer.js.map +1 -0
  28. package/build/module/lib/renderer/ladon-renderer.d.ts +2 -1
  29. package/build/module/lib/renderer/passthrough-renderer.d.ts +5 -4
  30. package/build/module/lib/renderer/passthrough-renderer.js +25 -44
  31. package/build/module/lib/renderer/passthrough-renderer.js.map +1 -0
  32. package/build/module/lib/renderer/replacement-renderer.d.ts +8 -5
  33. package/build/module/lib/renderer/replacement-renderer.js +84 -99
  34. package/build/module/lib/renderer/replacement-renderer.js.map +1 -0
  35. package/build/module/lib/renderer/webgl-renderer.d.ts +11 -3
  36. package/build/module/lib/renderer/webgl-renderer.js +168 -115
  37. package/build/module/lib/renderer/webgl-renderer.js.map +1 -0
  38. package/build/module/lib/shared-resource-manager.d.ts +40 -31
  39. package/build/module/lib/shared-resource-manager.js +151 -189
  40. package/build/module/lib/shared-resource-manager.js.map +1 -0
  41. package/build/module/lib/util.d.ts +10 -0
  42. package/build/module/lib/util.js +92 -179
  43. package/build/module/lib/util.js.map +1 -0
  44. package/build/module/lib/version.d.ts +1 -1
  45. package/build/module/lib/version.js +5 -2
  46. package/build/module/lib/version.js.map +1 -0
  47. package/package.json +21 -5
  48. package/build/module/lib/renderer/ladon-renderer.js +0 -2
  49. package/build/module/lib/renderer.js +0 -6
package/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
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.0.2](https://github.com/beyonddunbar/ladon-ts/compare/v5.0.1...v5.0.2) (2024-12-16)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * yarn build error ([#16](https://github.com/beyonddunbar/ladon-ts/issues/16)) ([38eb5af](https://github.com/beyonddunbar/ladon-ts/commit/38eb5afa8c37947187af3d0b4fe061971b8a2436))
11
+
12
+ ### [5.0.1](https://github.com/beyonddunbar/ladon-ts/compare/v5.0.0...v5.0.1) (2024-12-16)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * vite build arg ([a9593bd](https://github.com/beyonddunbar/ladon-ts/commit/a9593bd8aa235b2946bc7e150faa1d63f5c96abd))
18
+
19
+ ## [5.0.0](https://github.com/beyonddunbar/ladon-ts/compare/v4.5.1...v5.0.0) (2024-12-16)
20
+
21
+
22
+ ### ⚠ BREAKING CHANGES
23
+
24
+ * config builder (#15)
25
+
26
+ ### Features
27
+
28
+ * config builder ([#15](https://github.com/beyonddunbar/ladon-ts/issues/15)) ([eaaa9cf](https://github.com/beyonddunbar/ladon-ts/commit/eaaa9cf9fb2a3a34aa85b49c0b3e8e3b8e44b452))
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * lint ([25062c9](https://github.com/beyonddunbar/ladon-ts/commit/25062c9d4c3d24f808c718a3fb7b4c837c6b974f))
34
+
5
35
  ### [4.5.1](https://github.com/beyonddunbar/ladon-ts/compare/v4.5.0...v4.5.1) (2024-10-24)
6
36
 
7
37
 
@@ -0,0 +1,26 @@
1
+ const e = "1.15.1b", t = "0.7.7.2", i = "segmentation.js", n = { int: "https://models.int.infra.intelligence.webex.com", prod: "https://models.intelligence.webex.com" }, o = { models: "ladon/models", wasm: "ladon/wasm", workers: "ladon/workers" }, l = { weak: { kernelSize: 9, sigma: 2 }, moderate: { kernelSize: 15, sigma: 6 }, strong: { kernelSize: 25, sigma: 11 }, stronger: { kernelSize: 37, sigma: 17 }, strongest: { kernelSize: 49, sigma: 23 } }, h = { tiny: { modelFile: "tiny-640x360.onnx", inputSize: { width: 640, height: 360 }, outputSize: { width: 640, height: 360 }, upscaleSize: { width: 640, height: 360 }, generationIntervalMs: 48, modelRank: 4 }, low: { modelFile: "low-640x360.onnx", inputSize: { width: 640, height: 360 }, outputSize: { width: 640, height: 360 }, upscaleSize: { width: 640, height: 360 }, generationIntervalMs: 48, modelRank: 4 }, medium: { modelFile: "medium-640x360.onnx", inputSize: { width: 640, height: 360 }, outputSize: { width: 640, height: 360 }, upscaleSize: { width: 640, height: 360 }, generationIntervalMs: 36, modelRank: 4 }, high: { modelFile: "medium-640x360.onnx", inputSize: { width: 640, height: 360 }, outputSize: { width: 640, height: 360 }, upscaleSize: { width: 640, height: 360 }, generationIntervalMs: 24, modelRank: 4 }, ultra: { modelFile: "medium-640x360.onnx", inputSize: { width: 640, height: 360 }, outputSize: { width: 640, height: 360 }, upscaleSize: { width: 640, height: 360 }, generationIntervalMs: 0, modelRank: 4 } }, s = "${BASE_PATH_MODELS}/${MODEL_VERSION}/${MODEL_FILE}", a = "${BASE_PATH_WASM}/${ONNX_VERSION}/", d = "${BASE_PATH_WORKERS}/${LIB_VERSION}/${WORKER_FILE}", m = {
2
+ onnxVersion: e,
3
+ modelVersion: t,
4
+ workerFile: i,
5
+ baseUrls: n,
6
+ basePaths: o,
7
+ blurStrengths: l,
8
+ modelQualities: h,
9
+ modelUrlTemplate: s,
10
+ wasmPathTemplate: a,
11
+ workerUrlTemplate: d
12
+ };
13
+ export {
14
+ o as basePaths,
15
+ n as baseUrls,
16
+ l as blurStrengths,
17
+ m as default,
18
+ h as modelQualities,
19
+ s as modelUrlTemplate,
20
+ t as modelVersion,
21
+ e as onnxVersion,
22
+ a as wasmPathTemplate,
23
+ i as workerFile,
24
+ d as workerUrlTemplate
25
+ };
26
+ //# sourceMappingURL=config.json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,7 +1,10 @@
1
1
  export * from './lib/config';
2
+ export * from './lib/config-builder';
3
+ export * from './lib/config-types';
2
4
  export * from './lib/generator';
3
5
  export * from './lib/pipeline';
4
6
  export * from './lib/renderer';
5
7
  export * from './lib/util';
6
8
  export * from './lib/version';
7
9
  export * from './lib/shared-resource-manager';
10
+ export * from './lib/preload';
@@ -1,8 +1,41 @@
1
- export * from './lib/config';
2
- export * from './lib/generator';
3
- export * from './lib/pipeline';
4
- export * from './lib/renderer';
5
- export * from './lib/util';
6
- export * from './lib/version';
7
- export * from './lib/shared-resource-manager';
8
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxjQUFjLENBQUM7QUFDN0IsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLGdCQUFnQixDQUFDO0FBQy9CLGNBQWMsZ0JBQWdCLENBQUM7QUFDL0IsY0FBYyxZQUFZLENBQUM7QUFDM0IsY0FBYyxlQUFlLENBQUM7QUFDOUIsY0FBYywrQkFBK0IsQ0FBQyJ9
1
+ import { getBlurConfig as o, getConfig as t, getPreloadConfig as p } from "./lib/config.js";
2
+ import { ConfigurationBuilder as l } from "./lib/config-builder.js";
3
+ import { BlurStrength as m, Quality as f } from "./lib/config-types.js";
4
+ import { LocalGenerator as x, NullGenerator as g, WorkerGenerator as d } from "./lib/generator.js";
5
+ import { Pipeline as u } from "./lib/pipeline.js";
6
+ import { BlurRenderer as h } from "./lib/renderer/blur-renderer.js";
7
+ import { PassthroughRenderer as B } from "./lib/renderer/passthrough-renderer.js";
8
+ import { ReplacementRenderer as C } 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 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 E } from "./lib/shared-resource-manager.js";
13
+ import { preload as Q } from "./lib/preload.js";
14
+ export {
15
+ h as BlurRenderer,
16
+ m as BlurStrength,
17
+ l as ConfigurationBuilder,
18
+ b as InterpolationMethod,
19
+ y as LIB_VERSION,
20
+ x as LocalGenerator,
21
+ g as NullGenerator,
22
+ B as PassthroughRenderer,
23
+ u as Pipeline,
24
+ f as Quality,
25
+ C as ReplacementRenderer,
26
+ P as WebGLRenderer,
27
+ d as WorkerGenerator,
28
+ L as bilinearUpsample,
29
+ S as compileShader,
30
+ o as getBlurConfig,
31
+ t as getConfig,
32
+ p as getPreloadConfig,
33
+ k as isResolvedUri,
34
+ z as lanczos3Upsample,
35
+ M as linkProgram,
36
+ Q as preload,
37
+ N as resizeImage,
38
+ E as sharedResourceManager,
39
+ W as toAbsoluteURI
40
+ };
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -0,0 +1,180 @@
1
+ import { AssetUrlResolver, BlurConfig, BlurStrength, Generator, InputConfig, MaskConfig, PipelineConfig, PreloadConfig, Quality, RenderConfig } from './config-types';
2
+
3
+ /**
4
+ * A builder class for creating PipelineConfig instances in a flexible and intuitive way.
5
+ */
6
+ export declare class ConfigurationBuilder {
7
+ private env;
8
+ private config;
9
+ constructor(env?: 'int' | 'prod');
10
+ /**
11
+ * Sets the base URL for the configuration.
12
+ * @param baseUrl The base URL to use.
13
+ */
14
+ setBaseUrl(baseUrl: string): ConfigurationBuilder;
15
+ /**
16
+ * Sets the WASM URI for the configuration.
17
+ * @param wasmUri The WASM URI to use.
18
+ */
19
+ setWasmUri(wasmUri: string): ConfigurationBuilder;
20
+ /**
21
+ * Sets the asset URL resolver.
22
+ * @param assetUrlResolver The asset URL resolver to use
23
+ * @returns The current ConfigurationBuilder instance.
24
+ */
25
+ setAssetUrlResolver(assetUrlResolver: AssetUrlResolver): ConfigurationBuilder;
26
+ /**
27
+ * Sets the execution providers for the ONNX runtime.
28
+ *
29
+ * @param executionProviders The execution providers to use.
30
+ */
31
+ setExecutionProviders(executionProviders: string[]): ConfigurationBuilder;
32
+ /**
33
+ * Sets the input size for the configuration.
34
+ * @param height The height of the input.
35
+ * @param width The width of the input.
36
+ */
37
+ setInputSize(height: number, width: number): ConfigurationBuilder;
38
+ /**
39
+ * Sets the input configuration.
40
+ * @param inputConfig The input configuration to use.
41
+ */
42
+ setInputConfig(inputConfig: InputConfig): ConfigurationBuilder;
43
+ /**
44
+ * Sets the render configuration.
45
+ * @param renderConfig The render configuration to use.
46
+ */
47
+ setRenderConfig(renderConfig: RenderConfig): ConfigurationBuilder;
48
+ /**
49
+ * Sets the render type.
50
+ * @param type The render type ('blur', 'passthrough', 'replacement').
51
+ */
52
+ setRenderType(type: 'blur' | 'passthrough' | 'replacement'): ConfigurationBuilder;
53
+ /**
54
+ * Sets the horizontal mirror property for the render configuration.
55
+ * @param horizontalMirror Boolean indicating if horizontal mirror should be applied.
56
+ */
57
+ setRenderHorizontalMirror(horizontalMirror: boolean): ConfigurationBuilder;
58
+ /**
59
+ * Sets the blur strength for the render configuration.
60
+ * @param blurStrength The blur strength to use.
61
+ */
62
+ setBlurStrength(blurStrength: BlurStrength): ConfigurationBuilder;
63
+ /**
64
+ * Sets the blur kernel size.
65
+ * @param kernelSize The kernel size for the blur effect.
66
+ */
67
+ setBlurKernelSize(kernelSize: number): ConfigurationBuilder;
68
+ /**
69
+ * Sets the blur sigma value.
70
+ * @param sigma The sigma value for the blur effect.
71
+ */
72
+ setBlurSigma(sigma: number): ConfigurationBuilder;
73
+ /**
74
+ * Sets the replacement background.
75
+ * @param background The background to use for replacement.
76
+ */
77
+ setReplacementBackground(background: HTMLCanvasElement): ConfigurationBuilder;
78
+ /**
79
+ * Sets the replacement static property.
80
+ * @param isStatic Boolean indicating if the replacement is static.
81
+ */
82
+ setReplacementStatic(isStatic: boolean): ConfigurationBuilder;
83
+ /**
84
+ * Sets the mask configuration.
85
+ * @param maskConfig The mask configuration to use.
86
+ */
87
+ setMaskConfig(maskConfig: MaskConfig): ConfigurationBuilder;
88
+ /**
89
+ * Sets the mask generator.
90
+ * @param generator The generator type ('local' or 'worker').
91
+ */
92
+ setMaskGenerator(generator: Generator): ConfigurationBuilder;
93
+ /**
94
+ * Sets the mask generation interval in milliseconds.
95
+ * @param intervalMs The generation interval in milliseconds.
96
+ */
97
+ setMaskGenerationIntervalMs(intervalMs: number): ConfigurationBuilder;
98
+ /**
99
+ * Sets the mask model rank.
100
+ * @param modelRank The model rank to use.
101
+ */
102
+ setMaskModelRank(modelRank: number): ConfigurationBuilder;
103
+ /**
104
+ * Sets the mask model URI.
105
+ * @param modelUri The model URI to use.
106
+ */
107
+ setMaskModelUri(modelUri: string): ConfigurationBuilder;
108
+ /**
109
+ * Sets the mask worker URI.
110
+ * @param workerUri The worker URI to use.
111
+ */
112
+ setMaskWorkerUri(workerUri: string): ConfigurationBuilder;
113
+ /**
114
+ * Sets the mask input size.
115
+ * @param height The height of the mask input.
116
+ * @param width The width of the mask input.
117
+ */
118
+ setMaskInputSize(height: number, width: number): ConfigurationBuilder;
119
+ /**
120
+ * Sets the mask output size.
121
+ * @param height The height of the mask output.
122
+ * @param width The width of the mask output.
123
+ */
124
+ setMaskOutputSize(height: number, width: number): ConfigurationBuilder;
125
+ /**
126
+ * Sets the mask upscaled size.
127
+ * @param height The height of the upscaled mask.
128
+ * @param width The width of the upscaled mask.
129
+ */
130
+ setMaskUpscaleSize(height: number, width: number): ConfigurationBuilder;
131
+ /**
132
+ * Sets the quality level and updates mask configurations accordingly.
133
+ * @param quality The desired quality level.
134
+ */
135
+ setMaskQuality(quality: Quality): ConfigurationBuilder;
136
+ /**
137
+ * Builds and returns the PreloadConfig or PipelineConfig object.
138
+ *
139
+ * @param requireInputConfig Whether to require the input configuration to be set before building.
140
+ * Input size is not available at preload so this needs to be optional. The default value is true.
141
+ *
142
+ */
143
+ build(requireInputConfig?: boolean): PipelineConfig | PreloadConfig;
144
+ /**
145
+ * Returns the mask configuration, initializing it if necessary.
146
+ */
147
+ private getMaskConfig;
148
+ /**
149
+ * Returns the base URL for the configuration.
150
+ */
151
+ resolveBaseUrl(): string;
152
+ /**
153
+ * Returns the base URL for the configuration.
154
+ *
155
+ * @returns The base URL for the configuration.
156
+ */
157
+ resolveModelUri(): string;
158
+ resolveWasmUri(): string;
159
+ resolveWorkerUri(): string;
160
+ /**
161
+ * Resolves a template string with the specified values.
162
+ *
163
+ * @param template The template string to resolve.
164
+ * @param values The values to use for resolution.
165
+ * @returns The resolved template string.
166
+ */
167
+ private resolveTemplate;
168
+ /**
169
+ * Generates a blur configuration based on the specified blur strength.
170
+ * @param blurStrength The desired blur strength.
171
+ * @param horizontalMirror Whether to apply horizontal mirroring.
172
+ */
173
+ static getBlurConfig(blurStrength: BlurStrength, horizontalMirror?: boolean): BlurConfig;
174
+ /**
175
+ * Returns the library version.
176
+ *
177
+ * @returns The library version.
178
+ */
179
+ static getLibVersion(): string;
180
+ }
@@ -0,0 +1,336 @@
1
+ import i from "../config.json.js";
2
+ import { LIB_VERSION as m } from "./version.js";
3
+ class a {
4
+ constructor(e = "prod") {
5
+ this.env = e, this.config = {};
6
+ }
7
+ /**
8
+ * Sets the base URL for the configuration.
9
+ * @param baseUrl The base URL to use.
10
+ */
11
+ setBaseUrl(e) {
12
+ return this.config.baseUrl = e.replace(/\/+$/, ""), this;
13
+ }
14
+ /**
15
+ * Sets the WASM URI for the configuration.
16
+ * @param wasmUri The WASM URI to use.
17
+ */
18
+ setWasmUri(e) {
19
+ return this.config.wasmUri = e, this;
20
+ }
21
+ /**
22
+ * Sets the asset URL resolver.
23
+ * @param assetUrlResolver The asset URL resolver to use
24
+ * @returns The current ConfigurationBuilder instance.
25
+ */
26
+ setAssetUrlResolver(e) {
27
+ return this.config.assetUrlResolver = e, this;
28
+ }
29
+ /**
30
+ * Sets the execution providers for the ONNX runtime.
31
+ *
32
+ * @param executionProviders The execution providers to use.
33
+ */
34
+ setExecutionProviders(e) {
35
+ return typeof e == "string" && (e = [e]), this.config.executionProviders = e, this;
36
+ }
37
+ /**
38
+ * Sets the input size for the configuration.
39
+ * @param height The height of the input.
40
+ * @param width The width of the input.
41
+ */
42
+ setInputSize(e, r) {
43
+ return this.config.input = { height: e, width: r }, this;
44
+ }
45
+ /**
46
+ * Sets the input configuration.
47
+ * @param inputConfig The input configuration to use.
48
+ */
49
+ setInputConfig(e) {
50
+ return this.config.input = { ...e }, this;
51
+ }
52
+ /**
53
+ * Sets the render configuration.
54
+ * @param renderConfig The render configuration to use.
55
+ */
56
+ setRenderConfig(e) {
57
+ return this.config.render = { ...e }, this;
58
+ }
59
+ /**
60
+ * Sets the render type.
61
+ * @param type The render type ('blur', 'passthrough', 'replacement').
62
+ */
63
+ setRenderType(e) {
64
+ return this.config.render ? this.config.render.type = e : this.config.render = { type: e }, this;
65
+ }
66
+ /**
67
+ * Sets the horizontal mirror property for the render configuration.
68
+ * @param horizontalMirror Boolean indicating if horizontal mirror should be applied.
69
+ */
70
+ setRenderHorizontalMirror(e) {
71
+ if (!this.config.render)
72
+ throw new Error("Render config must be set before setting horizontal mirror.");
73
+ return this.config.render.horizontalMirror = e, this;
74
+ }
75
+ /**
76
+ * Sets the blur strength for the render configuration.
77
+ * @param blurStrength The blur strength to use.
78
+ */
79
+ setBlurStrength(e) {
80
+ var t;
81
+ const r = a.getBlurConfig(
82
+ e,
83
+ (t = this.config.render) == null ? void 0 : t.horizontalMirror
84
+ );
85
+ return this.config.render = { ...this.config.render, ...r }, this;
86
+ }
87
+ /**
88
+ * Sets the blur kernel size.
89
+ * @param kernelSize The kernel size for the blur effect.
90
+ */
91
+ setBlurKernelSize(e) {
92
+ if (!this.config.render || this.config.render.type !== "blur")
93
+ throw new Error("Render config must be of type blur to set blur properties.");
94
+ return this.config.render.kernelSize = e, this;
95
+ }
96
+ /**
97
+ * Sets the blur sigma value.
98
+ * @param sigma The sigma value for the blur effect.
99
+ */
100
+ setBlurSigma(e) {
101
+ if (!this.config.render || this.config.render.type !== "blur")
102
+ throw new Error("Render config must be of type blur to set blur properties.");
103
+ return this.config.render.sigma = e, this;
104
+ }
105
+ /**
106
+ * Sets the replacement background.
107
+ * @param background The background to use for replacement.
108
+ */
109
+ setReplacementBackground(e) {
110
+ if (!this.config.render || this.config.render.type !== "replacement")
111
+ throw new Error(
112
+ "Render config must be of type replacement to set replacement properties."
113
+ );
114
+ return this.config.render.background = e, this;
115
+ }
116
+ /**
117
+ * Sets the replacement static property.
118
+ * @param isStatic Boolean indicating if the replacement is static.
119
+ */
120
+ setReplacementStatic(e) {
121
+ if (!this.config.render || this.config.render.type !== "replacement")
122
+ throw new Error(
123
+ "Render config must be of type replacement to set replacement properties."
124
+ );
125
+ return this.config.render.static = e, this;
126
+ }
127
+ /**
128
+ * Sets the mask configuration.
129
+ * @param maskConfig The mask configuration to use.
130
+ */
131
+ setMaskConfig(e) {
132
+ return this.config.mask = { ...e }, this;
133
+ }
134
+ /**
135
+ * Sets the mask generator.
136
+ * @param generator The generator type ('local' or 'worker').
137
+ */
138
+ setMaskGenerator(e) {
139
+ const r = this.getMaskConfig();
140
+ return r.generator = e, this;
141
+ }
142
+ /**
143
+ * Sets the mask generation interval in milliseconds.
144
+ * @param intervalMs The generation interval in milliseconds.
145
+ */
146
+ setMaskGenerationIntervalMs(e) {
147
+ const r = this.getMaskConfig();
148
+ return r.generationIntervalMs = e, this;
149
+ }
150
+ /**
151
+ * Sets the mask model rank.
152
+ * @param modelRank The model rank to use.
153
+ */
154
+ setMaskModelRank(e) {
155
+ const r = this.getMaskConfig();
156
+ return r.modelRank = e, this;
157
+ }
158
+ /**
159
+ * Sets the mask model URI.
160
+ * @param modelUri The model URI to use.
161
+ */
162
+ setMaskModelUri(e) {
163
+ const r = this.getMaskConfig();
164
+ return r.modelUri = e, this;
165
+ }
166
+ /**
167
+ * Sets the mask worker URI.
168
+ * @param workerUri The worker URI to use.
169
+ */
170
+ setMaskWorkerUri(e) {
171
+ const r = this.getMaskConfig();
172
+ return r.workerUri = e, this;
173
+ }
174
+ /**
175
+ * Sets the mask input size.
176
+ * @param height The height of the mask input.
177
+ * @param width The width of the mask input.
178
+ */
179
+ setMaskInputSize(e, r) {
180
+ const t = this.getMaskConfig();
181
+ return t.inputSize = { height: e, width: r }, this;
182
+ }
183
+ /**
184
+ * Sets the mask output size.
185
+ * @param height The height of the mask output.
186
+ * @param width The width of the mask output.
187
+ */
188
+ setMaskOutputSize(e, r) {
189
+ const t = this.getMaskConfig();
190
+ return t.outputSize = { height: e, width: r }, this;
191
+ }
192
+ /**
193
+ * Sets the mask upscaled size.
194
+ * @param height The height of the upscaled mask.
195
+ * @param width The width of the upscaled mask.
196
+ */
197
+ setMaskUpscaleSize(e, r) {
198
+ const t = this.getMaskConfig();
199
+ return t.upscaleSize = { height: e, width: r }, this;
200
+ }
201
+ /**
202
+ * Sets the quality level and updates mask configurations accordingly.
203
+ * @param quality The desired quality level.
204
+ */
205
+ setMaskQuality(e) {
206
+ const { modelQualities: r } = i, t = this.getMaskConfig(), s = e.toLowerCase(), o = r[s];
207
+ if (!o)
208
+ throw new Error(`[ladon-ts] - unknown quality option: ${e}`);
209
+ return t.qualityKey = s, Object.assign(t, o), this;
210
+ }
211
+ /**
212
+ * Builds and returns the PreloadConfig or PipelineConfig object.
213
+ *
214
+ * @param requireInputConfig Whether to require the input configuration to be set before building.
215
+ * Input size is not available at preload so this needs to be optional. The default value is true.
216
+ *
217
+ */
218
+ build(e = !0) {
219
+ const r = this.resolveBaseUrl(), t = 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
+ if (!n)
221
+ throw new Error("Mask configuration must be set before building the configuration.");
222
+ const u = {
223
+ generator: n.generator,
224
+ generationIntervalMs: n.generationIntervalMs,
225
+ modelRank: n.modelRank,
226
+ inputSize: n.inputSize,
227
+ outputSize: n.outputSize,
228
+ upscaleSize: n.upscaleSize,
229
+ modelUri: t,
230
+ workerUri: o
231
+ }, h = {
232
+ assetUrlResolver: c,
233
+ executionProviders: f,
234
+ baseUrl: r,
235
+ wasmUri: s,
236
+ mask: u
237
+ };
238
+ if (e) {
239
+ if (!l)
240
+ throw new Error("Input must be set before building the configuration.");
241
+ if (!g)
242
+ throw new Error("Render must be set before building the configuration.");
243
+ return {
244
+ ...h,
245
+ input: l,
246
+ render: g
247
+ };
248
+ }
249
+ return h;
250
+ }
251
+ /**
252
+ * Returns the mask configuration, initializing it if necessary.
253
+ */
254
+ getMaskConfig() {
255
+ return this.config.mask || (this.config.mask = {}), this.config.mask;
256
+ }
257
+ /**
258
+ * Returns the base URL for the configuration.
259
+ */
260
+ resolveBaseUrl() {
261
+ return this.config.baseUrl || i.baseUrls[this.env];
262
+ }
263
+ /**
264
+ * Returns the base URL for the configuration.
265
+ *
266
+ * @returns The base URL for the configuration.
267
+ */
268
+ resolveModelUri() {
269
+ var r;
270
+ if ((r = this.config.mask) != null && r.modelUri)
271
+ return this.config.mask.modelUri;
272
+ const e = this.getMaskConfig();
273
+ if (!e.qualityKey)
274
+ 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
279
+ });
280
+ }
281
+ 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
285
+ });
286
+ }
287
+ resolveWorkerUri() {
288
+ 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,
291
+ LIB_VERSION: a.getLibVersion(),
292
+ WORKER_FILE: i.workerFile
293
+ });
294
+ }
295
+ /**
296
+ * Resolves a template string with the specified values.
297
+ *
298
+ * @param template The template string to resolve.
299
+ * @param values The values to use for resolution.
300
+ * @returns The resolved template string.
301
+ */
302
+ resolveTemplate(e, r) {
303
+ return e.replace(/\$\{([A-Z_]+)\}/g, (t, s) => {
304
+ if (!r[s])
305
+ throw new Error(`Missing value for template variable: ${s}`);
306
+ return r[s];
307
+ });
308
+ }
309
+ /**
310
+ * Generates a blur configuration based on the specified blur strength.
311
+ * @param blurStrength The desired blur strength.
312
+ * @param horizontalMirror Whether to apply horizontal mirroring.
313
+ */
314
+ static getBlurConfig(e, r) {
315
+ const t = e.toLowerCase(), s = i.blurStrengths[t];
316
+ if (!s)
317
+ throw new Error(`[ladon-ts] Unknown blur strength: ${e}`);
318
+ return {
319
+ type: "blur",
320
+ horizontalMirror: r,
321
+ ...s
322
+ };
323
+ }
324
+ /**
325
+ * Returns the library version.
326
+ *
327
+ * @returns The library version.
328
+ */
329
+ static getLibVersion() {
330
+ return m;
331
+ }
332
+ }
333
+ export {
334
+ a as ConfigurationBuilder
335
+ };
336
+ //# sourceMappingURL=config-builder.js.map