@webex/ladon-ts 5.9.2 → 5.10.1
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.
- package/CHANGELOG.md +14 -0
- package/build/module/_virtual/_commonjsHelpers.js +7 -0
- package/build/module/_virtual/_commonjsHelpers.js.map +1 -0
- package/build/module/_virtual/logger.js +8 -0
- package/build/module/_virtual/logger.js.map +1 -0
- package/build/module/_virtual/logger2.js +5 -0
- package/build/module/_virtual/logger2.js.map +1 -0
- package/build/module/index.d.ts +1 -0
- package/build/module/index.js +38 -34
- package/build/module/index.js.map +1 -1
- package/build/module/lib/config-builder.js +56 -81
- package/build/module/lib/config-builder.js.map +1 -1
- package/build/module/lib/config.js +10 -9
- package/build/module/lib/config.js.map +1 -1
- package/build/module/lib/logger.d.ts +6 -0
- package/build/module/lib/logger.js +22 -0
- package/build/module/lib/logger.js.map +1 -0
- package/build/module/lib/pipeline.js +35 -37
- package/build/module/lib/pipeline.js.map +1 -1
- package/build/module/lib/renderer/blur-renderer.js +20 -30
- package/build/module/lib/renderer/blur-renderer.js.map +1 -1
- package/build/module/lib/renderer/replacement-renderer.js +7 -8
- package/build/module/lib/renderer/replacement-renderer.js.map +1 -1
- package/build/module/lib/renderer/webgl-renderer.js +14 -27
- package/build/module/lib/renderer/webgl-renderer.js.map +1 -1
- package/build/module/lib/resource-loader.js +8 -11
- package/build/module/lib/resource-loader.js.map +1 -1
- package/build/module/lib/util.js +40 -43
- package/build/module/lib/util.js.map +1 -1
- package/build/module/lib/version.d.ts +1 -1
- package/build/module/lib/version.js +1 -1
- package/build/module/lib/version.js.map +1 -1
- package/build/module/lib/worker-generator.js +7 -6
- package/build/module/lib/worker-generator.js.map +1 -1
- package/build/module/lib/worker-manager.js +14 -19
- package/build/module/lib/worker-manager.js.map +1 -1
- package/build/module/node_modules/js-logger/src/logger.js +108 -0
- package/build/module/node_modules/js-logger/src/logger.js.map +1 -0
- package/build/worker/segmentation.js +826 -822
- package/build/worker/segmentation.js.map +1 -1
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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.10.1 (2026-10-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **ci:** migrate release jobs to supported runner ([#99](https://github.com/beyonddunbar/ladon-ts/issues/99)) ([a66b2e9](https://github.com/beyonddunbar/ladon-ts/commit/a66b2e94963c010024ee0c40aa8b7114e8bbd7ff))
|
|
11
|
+
|
|
12
|
+
## 5.10.0 (2025-07-31)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add logger ([#84](https://github.com/beyonddunbar/ladon-ts/issues/84)) ([93a6b9e](https://github.com/beyonddunbar/ladon-ts/commit/93a6b9e1c2292193faa602ea8093e4f6dac2c3d6))
|
|
18
|
+
|
|
5
19
|
### 5.9.2 (2025-07-23)
|
|
6
20
|
|
|
7
21
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/build/module/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './lib/config';
|
|
|
2
2
|
export * from './lib/config-builder';
|
|
3
3
|
export * from './lib/config-types';
|
|
4
4
|
export * from './lib/generator';
|
|
5
|
+
export * from './lib/logger';
|
|
5
6
|
export * from './lib/pipeline';
|
|
6
7
|
export * from './lib/pipeline-types';
|
|
7
8
|
export * from './lib/preload';
|
package/build/module/index.js
CHANGED
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
import { getBlurConfig as o, getConfig as t, getPreloadConfig as p } from "./lib/config.js";
|
|
2
2
|
import { ConfigurationBuilder as m } from "./lib/config-builder.js";
|
|
3
|
-
import { BlurStrength as
|
|
4
|
-
import { WorkerGenerator as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
3
|
+
import { BlurStrength as l, Quality as n } from "./lib/config-types.js";
|
|
4
|
+
import { WorkerGenerator as i } from "./lib/worker-generator.js";
|
|
5
|
+
import { logger as d } from "./lib/logger.js";
|
|
6
|
+
import { Pipeline as u } from "./lib/pipeline.js";
|
|
7
|
+
import { preload as c } from "./lib/preload.js";
|
|
8
|
+
import { BlurRenderer as B } from "./lib/renderer/blur-renderer.js";
|
|
9
|
+
import { PassthroughRenderer as L } from "./lib/renderer/passthrough-renderer.js";
|
|
10
|
+
import { ReplacementRenderer as C } from "./lib/renderer/replacement-renderer.js";
|
|
11
|
+
import { WebGLRenderer as U } from "./lib/renderer/webgl-renderer.js";
|
|
12
|
+
import { ResourceLoader as M, resourceLoader as S } from "./lib/resource-loader.js";
|
|
13
|
+
import { WorkerManager as z, workerManager as G } from "./lib/worker-manager.js";
|
|
14
|
+
import { InterpolationMethod as w, bilinearUpsample as y, compileShader as A, isResolvedUri as E, lanczos3Upsample as N, linkProgram as O, resizeImage as Q, toAbsoluteURI as V } from "./lib/util.js";
|
|
15
|
+
import { LIB_VERSION as j } from "./lib/version.js";
|
|
16
|
+
import { default as D } from "./_virtual/logger.js";
|
|
15
17
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
B as BlurRenderer,
|
|
19
|
+
l as BlurStrength,
|
|
18
20
|
m as ConfigurationBuilder,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
w as InterpolationMethod,
|
|
22
|
+
j as LIB_VERSION,
|
|
23
|
+
D as Logger,
|
|
24
|
+
L as PassthroughRenderer,
|
|
25
|
+
u as Pipeline,
|
|
26
|
+
n as Quality,
|
|
27
|
+
C as ReplacementRenderer,
|
|
28
|
+
M as ResourceLoader,
|
|
29
|
+
U as WebGLRenderer,
|
|
30
|
+
i as WorkerGenerator,
|
|
31
|
+
z as WorkerManager,
|
|
32
|
+
y as bilinearUpsample,
|
|
33
|
+
A as compileShader,
|
|
31
34
|
o as getBlurConfig,
|
|
32
35
|
t as getConfig,
|
|
33
36
|
p as getPreloadConfig,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
E as isResolvedUri,
|
|
38
|
+
N as lanczos3Upsample,
|
|
39
|
+
O as linkProgram,
|
|
40
|
+
d as logger,
|
|
41
|
+
c as preload,
|
|
42
|
+
Q as resizeImage,
|
|
43
|
+
S as resourceLoader,
|
|
44
|
+
V as toAbsoluteURI,
|
|
45
|
+
G as workerManager
|
|
42
46
|
};
|
|
43
47
|
//# 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":";;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import i from "../config.json.js";
|
|
2
|
+
import { logger as s } from "./logger.js";
|
|
3
|
+
import { LIB_VERSION as d } from "./version.js";
|
|
4
|
+
class g {
|
|
4
5
|
constructor(e = "prod") {
|
|
5
6
|
this.env = e, this.config = {};
|
|
6
7
|
}
|
|
@@ -68,9 +69,7 @@ class a {
|
|
|
68
69
|
* @param horizontalMirror Boolean indicating if horizontal mirror should be applied.
|
|
69
70
|
*/
|
|
70
71
|
setRenderHorizontalMirror(e) {
|
|
71
|
-
|
|
72
|
-
throw new Error("Render config must be set before setting horizontal mirror.");
|
|
73
|
-
return this.config.render.horizontalMirror = e, this;
|
|
72
|
+
return this.config.render || s.errorAndThrow("Render config must be set before setting horizontal mirror."), this.config.render.horizontalMirror = e, this;
|
|
74
73
|
}
|
|
75
74
|
/**
|
|
76
75
|
* Sets the blur strength for the render configuration.
|
|
@@ -78,7 +77,7 @@ class a {
|
|
|
78
77
|
*/
|
|
79
78
|
setBlurStrength(e) {
|
|
80
79
|
var t;
|
|
81
|
-
const r =
|
|
80
|
+
const r = g.getBlurConfig(
|
|
82
81
|
e,
|
|
83
82
|
(t = this.config.render) == null ? void 0 : t.horizontalMirror
|
|
84
83
|
);
|
|
@@ -89,40 +88,32 @@ class a {
|
|
|
89
88
|
* @param kernelSize The kernel size for the blur effect.
|
|
90
89
|
*/
|
|
91
90
|
setBlurKernelSize(e) {
|
|
92
|
-
|
|
93
|
-
throw new Error("Render config must be of type blur to set blur properties.");
|
|
94
|
-
return this.config.render.kernelSize = e, this;
|
|
91
|
+
return (!this.config.render || this.config.render.type !== "blur") && s.errorAndThrow("Render config must be of type blur to set blur properties."), this.config.render.kernelSize = e, this;
|
|
95
92
|
}
|
|
96
93
|
/**
|
|
97
94
|
* Sets the blur sigma value.
|
|
98
95
|
* @param sigma The sigma value for the blur effect.
|
|
99
96
|
*/
|
|
100
97
|
setBlurSigma(e) {
|
|
101
|
-
|
|
102
|
-
throw new Error("Render config must be of type blur to set blur properties.");
|
|
103
|
-
return this.config.render.sigma = e, this;
|
|
98
|
+
return (!this.config.render || this.config.render.type !== "blur") && s.errorAndThrow("Render config must be of type blur to set blur properties."), this.config.render.sigma = e, this;
|
|
104
99
|
}
|
|
105
100
|
/**
|
|
106
101
|
* Sets the replacement background.
|
|
107
102
|
* @param background The background canvas or video element to use for replacement.
|
|
108
103
|
*/
|
|
109
104
|
setReplacementBackground(e) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
return this.config.render.background = e, this;
|
|
105
|
+
return (!this.config.render || this.config.render.type !== "replacement") && s.errorAndThrow(
|
|
106
|
+
"Render config must be of type replacement to set replacement properties."
|
|
107
|
+
), this.config.render.background = e, this;
|
|
115
108
|
}
|
|
116
109
|
/**
|
|
117
110
|
* Sets the replacement static property.
|
|
118
111
|
* @param isStatic Boolean indicating if the replacement is static.
|
|
119
112
|
*/
|
|
120
113
|
setReplacementStatic(e) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
return this.config.render.static = e, this;
|
|
114
|
+
return (!this.config.render || this.config.render.type !== "replacement") && s.errorAndThrow(
|
|
115
|
+
"Render config must be of type replacement to set replacement properties."
|
|
116
|
+
), this.config.render.static = e, this;
|
|
126
117
|
}
|
|
127
118
|
/**
|
|
128
119
|
* Sets the mask configuration.
|
|
@@ -136,7 +127,7 @@ class a {
|
|
|
136
127
|
* @param generator The generator type (most be 'worker'; 'local' is deprecated).
|
|
137
128
|
*/
|
|
138
129
|
setMaskGenerator(e) {
|
|
139
|
-
e !== "worker" &&
|
|
130
|
+
e !== "worker" && s.warn('Mask generator must be "worker". "local" is deprecated.');
|
|
140
131
|
const r = this.getMaskConfig();
|
|
141
132
|
return r.generator = e, this;
|
|
142
133
|
}
|
|
@@ -204,10 +195,8 @@ class a {
|
|
|
204
195
|
* @param quality The desired quality level.
|
|
205
196
|
*/
|
|
206
197
|
setMaskQuality(e) {
|
|
207
|
-
const { modelQualities: r } =
|
|
208
|
-
|
|
209
|
-
throw new Error(`[ladon-ts] unknown quality option: ${e}`);
|
|
210
|
-
return t.qualityKey = i, Object.assign(t, o), this;
|
|
198
|
+
const { modelQualities: r } = i, t = this.getMaskConfig(), n = e.toLowerCase(), a = r[n];
|
|
199
|
+
return a || s.errorAndThrow(`Unknown quality option: ${e}`), t.qualityKey = n, Object.assign(t, a), this;
|
|
211
200
|
}
|
|
212
201
|
/**
|
|
213
202
|
* Builds and returns the PreloadConfig or PipelineConfig object.
|
|
@@ -217,37 +206,31 @@ class a {
|
|
|
217
206
|
*
|
|
218
207
|
*/
|
|
219
208
|
build(e = !0) {
|
|
220
|
-
const r = this.resolveBaseUrl(), t = this.resolveModelUri(),
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
209
|
+
const r = this.resolveBaseUrl(), t = this.resolveModelUri(), n = this.resolveWasmUri(), a = this.resolveWorkerUri(), l = this.config.input, h = this.config.render, o = this.config.mask, c = this.config.executionProviders, u = this.config.assetUrlResolver;
|
|
210
|
+
o || s.errorAndThrow(
|
|
211
|
+
"Mask configuration must be set before building the configuration."
|
|
212
|
+
);
|
|
213
|
+
const m = {
|
|
214
|
+
generator: o.generator,
|
|
215
|
+
generationIntervalMs: o.generationIntervalMs,
|
|
216
|
+
modelRank: o.modelRank,
|
|
217
|
+
inputSize: o.inputSize,
|
|
218
|
+
outputSize: o.outputSize,
|
|
219
|
+
upscaleSize: o.upscaleSize,
|
|
230
220
|
modelUri: t,
|
|
231
|
-
workerUri:
|
|
232
|
-
},
|
|
233
|
-
assetUrlResolver:
|
|
221
|
+
workerUri: a
|
|
222
|
+
}, f = {
|
|
223
|
+
assetUrlResolver: u,
|
|
234
224
|
executionProviders: c,
|
|
235
225
|
baseUrl: r,
|
|
236
|
-
wasmUri:
|
|
237
|
-
mask:
|
|
226
|
+
wasmUri: n,
|
|
227
|
+
mask: m
|
|
238
228
|
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return {
|
|
245
|
-
...h,
|
|
246
|
-
input: l,
|
|
247
|
-
render: g
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
return h;
|
|
229
|
+
return e ? (l || s.errorAndThrow("Input must be set before building the configuration."), h || s.errorAndThrow("Render must be set before building the configuration."), {
|
|
230
|
+
...f,
|
|
231
|
+
input: l,
|
|
232
|
+
render: h
|
|
233
|
+
}) : f;
|
|
251
234
|
}
|
|
252
235
|
/**
|
|
253
236
|
* Returns the mask configuration, initializing it if necessary.
|
|
@@ -259,7 +242,7 @@ class a {
|
|
|
259
242
|
* Returns the base URL for the configuration.
|
|
260
243
|
*/
|
|
261
244
|
resolveBaseUrl() {
|
|
262
|
-
return this.config.baseUrl ||
|
|
245
|
+
return this.config.baseUrl || i.baseUrls[this.env];
|
|
263
246
|
}
|
|
264
247
|
/**
|
|
265
248
|
* Returns the base URL for the configuration.
|
|
@@ -271,26 +254,24 @@ class a {
|
|
|
271
254
|
if ((r = this.config.mask) != null && r.modelUri)
|
|
272
255
|
return this.config.mask.modelUri;
|
|
273
256
|
const e = this.getMaskConfig();
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
MODEL_VERSION: s.modelVersion,
|
|
279
|
-
MODEL_FILE: s.modelQualities[e.qualityKey].modelFile
|
|
257
|
+
return e.qualityKey || s.errorAndThrow("No quality set, cannot infer modelFile."), this.resolveTemplate(i.modelUrlTemplate, {
|
|
258
|
+
BASE_PATH_MODELS: i.basePaths.models,
|
|
259
|
+
MODEL_VERSION: i.modelVersion,
|
|
260
|
+
MODEL_FILE: i.modelQualities[e.qualityKey].modelFile
|
|
280
261
|
});
|
|
281
262
|
}
|
|
282
263
|
resolveWasmUri() {
|
|
283
|
-
return this.config.wasmUri ? this.config.wasmUri : this.resolveTemplate(
|
|
284
|
-
BASE_PATH_WASM:
|
|
285
|
-
ONNX_VERSION:
|
|
264
|
+
return this.config.wasmUri ? this.config.wasmUri : this.resolveTemplate(i.wasmPathTemplate, {
|
|
265
|
+
BASE_PATH_WASM: i.basePaths.wasm,
|
|
266
|
+
ONNX_VERSION: i.onnxVersion
|
|
286
267
|
});
|
|
287
268
|
}
|
|
288
269
|
resolveWorkerUri() {
|
|
289
270
|
var e;
|
|
290
|
-
return (e = this.config.mask) != null && e.workerUri ? this.config.mask.workerUri : this.resolveTemplate(
|
|
291
|
-
BASE_PATH_WORKERS:
|
|
292
|
-
LIB_VERSION:
|
|
293
|
-
WORKER_FILE:
|
|
271
|
+
return (e = this.config.mask) != null && e.workerUri ? this.config.mask.workerUri : this.resolveTemplate(i.workerUrlTemplate, {
|
|
272
|
+
BASE_PATH_WORKERS: i.basePaths.workers,
|
|
273
|
+
LIB_VERSION: g.getLibVersion(),
|
|
274
|
+
WORKER_FILE: i.workerFile
|
|
294
275
|
});
|
|
295
276
|
}
|
|
296
277
|
/**
|
|
@@ -301,11 +282,7 @@ class a {
|
|
|
301
282
|
* @returns The resolved template string.
|
|
302
283
|
*/
|
|
303
284
|
resolveTemplate(e, r) {
|
|
304
|
-
return e.replace(/\$\{([A-Z_]+)\}/g, (t,
|
|
305
|
-
if (!r[i])
|
|
306
|
-
throw new Error(`Missing value for template variable: ${i}`);
|
|
307
|
-
return r[i];
|
|
308
|
-
});
|
|
285
|
+
return e.replace(/\$\{([A-Z_]+)\}/g, (t, n) => (r[n] || s.errorAndThrow(`Missing value for template variable: ${n}`), r[n]));
|
|
309
286
|
}
|
|
310
287
|
/**
|
|
311
288
|
* Generates a blur configuration based on the specified blur strength.
|
|
@@ -313,13 +290,11 @@ class a {
|
|
|
313
290
|
* @param horizontalMirror Whether to apply horizontal mirroring.
|
|
314
291
|
*/
|
|
315
292
|
static getBlurConfig(e, r) {
|
|
316
|
-
const t = e.toLowerCase(),
|
|
317
|
-
|
|
318
|
-
throw new Error(`[ladon-ts] Unknown blur strength: ${e}`);
|
|
319
|
-
return {
|
|
293
|
+
const t = e.toLowerCase(), n = i.blurStrengths[t];
|
|
294
|
+
return n || s.errorAndThrow(`Unknown blur strength: ${e}`), {
|
|
320
295
|
type: "blur",
|
|
321
296
|
horizontalMirror: r,
|
|
322
|
-
...
|
|
297
|
+
...n
|
|
323
298
|
};
|
|
324
299
|
}
|
|
325
300
|
static getPassthroughConfig(e) {
|
|
@@ -334,10 +309,10 @@ class a {
|
|
|
334
309
|
* @returns The library version.
|
|
335
310
|
*/
|
|
336
311
|
static getLibVersion() {
|
|
337
|
-
return
|
|
312
|
+
return d;
|
|
338
313
|
}
|
|
339
314
|
}
|
|
340
315
|
export {
|
|
341
|
-
|
|
316
|
+
g as ConfigurationBuilder
|
|
342
317
|
};
|
|
343
318
|
//# sourceMappingURL=config-builder.js.map
|
|
@@ -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 | HTMLVideoElement;\n static: boolean;\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 canvas or video element to use for replacement.\n */\n public setReplacementBackground(\n background: HTMLCanvasElement | HTMLVideoElement\n ): 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":";;AAyEO,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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qB,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;"}
|
|
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 { logger } from './logger';\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 | HTMLVideoElement;\n static: boolean;\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 logger.errorAndThrow('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 logger.errorAndThrow('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 logger.errorAndThrow('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 canvas or video element to use for replacement.\n */\n public setReplacementBackground(\n background: HTMLCanvasElement | HTMLVideoElement\n ): ConfigurationBuilder {\n if (!this.config.render || this.config.render.type !== 'replacement') {\n logger.errorAndThrow(\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 logger.errorAndThrow(\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 logger.warn('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 logger.errorAndThrow(`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 logger.errorAndThrow(\n 'Mask configuration must be set before building the configuration.'\n );\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 logger.errorAndThrow('Input must be set before building the configuration.');\n }\n\n if (!render) {\n logger.errorAndThrow('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 logger.errorAndThrow('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 logger.errorAndThrow(`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 logger.errorAndThrow(`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","logger","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":";;;AA0EO,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,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from "./logger.js";
|
|
2
3
|
function i(e) {
|
|
3
|
-
|
|
4
|
-
`
|
|
4
|
+
u.warn(
|
|
5
|
+
`Deprecation Warning: ${e} is deprecated and will be removed in a future release. Please migrate to ConfigurationBuilder for future use.`
|
|
5
6
|
);
|
|
6
7
|
}
|
|
7
|
-
const
|
|
8
|
+
const c = (e, t) => (i("getBlurConfig"), n.getBlurConfig(e, t)), m = (e, t, s, o) => {
|
|
8
9
|
i("getPreloadConfig");
|
|
9
|
-
const r = new
|
|
10
|
+
const r = new n().setBaseUrl(o).setMaskQuality(e).setMaskGenerator(t).setAssetUrlResolver(s).build(!1);
|
|
10
11
|
return {
|
|
11
12
|
assetUrlResolver: r.assetUrlResolver,
|
|
12
13
|
baseUrl: r.baseUrl,
|
|
13
14
|
wasmUri: r.wasmUri,
|
|
14
15
|
mask: r.mask
|
|
15
16
|
};
|
|
16
|
-
},
|
|
17
|
+
}, C = (e, t, s, o, a, r, l) => (i("getConfig"), new n().setBaseUrl(l).setMaskQuality(s).setInputSize(e, t).setRenderConfig(a).setMaskGenerator(o).setAssetUrlResolver(r).build());
|
|
17
18
|
export {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
c as getBlurConfig,
|
|
20
|
+
C as getConfig,
|
|
21
|
+
m as getPreloadConfig
|
|
21
22
|
};
|
|
22
23
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sources":["../../../src/lib/config.ts"],"sourcesContent":["/************************************************************************************\n * DEPRECATION NOTICE: This file contains deprecated methods for generating config\n * objects. These methods are retained for backwards compatibility and will be removed\n * in a future release. These methods are retained solely for backwards compatibility.\n *\n * Current release: v4.5.1\n * Deprecation target: v5.0.0\n ************************************************************************************/\n\nimport { ConfigurationBuilder } from './config-builder';\nimport {\n AssetUrlResolver,\n BlurConfig,\n BlurStrength,\n Generator,\n PipelineConfig,\n PreloadConfig,\n Quality,\n RenderConfig,\n ReplacementConfig,\n} from './config-types';\n\nfunction logDeprecationWarning(functionName: string): void {\n
|
|
1
|
+
{"version":3,"file":"config.js","sources":["../../../src/lib/config.ts"],"sourcesContent":["/************************************************************************************\n * DEPRECATION NOTICE: This file contains deprecated methods for generating config\n * objects. These methods are retained for backwards compatibility and will be removed\n * in a future release. These methods are retained solely for backwards compatibility.\n *\n * Current release: v4.5.1\n * Deprecation target: v5.0.0\n ************************************************************************************/\n\nimport { ConfigurationBuilder } from './config-builder';\nimport {\n AssetUrlResolver,\n BlurConfig,\n BlurStrength,\n Generator,\n PipelineConfig,\n PreloadConfig,\n Quality,\n RenderConfig,\n ReplacementConfig,\n} from './config-types';\nimport { logger } from './logger';\n\nfunction logDeprecationWarning(functionName: string): void {\n logger.warn(\n `Deprecation Warning: ${functionName} is deprecated and will be removed in a future release. Please migrate to ConfigurationBuilder for future use.`\n );\n}\n\n/**\n * Generates a blur configuration based on the specified blur strength.\n * This function uses the static method from ConfigurationBuilder.\n * @param blurStrength The desired blur strength.\n * @param horizontalMirror Whether to apply horizontal mirroring.\n */\nexport const getBlurConfig = (\n blurStrength: BlurStrength,\n horizontalMirror?: boolean\n): BlurConfig => {\n logDeprecationWarning('getBlurConfig');\n return ConfigurationBuilder.getBlurConfig(blurStrength, horizontalMirror);\n};\n\n/**\n * Retrieves a PreloadConfig using the ConfigurationBuilder.\n * The function preserves the old signature for compatibility.\n * @param quality The desired model quality.\n * @param generator The mask generator ('local' or 'worker').\n * @param modelUrlResolver A function to resolve model URLs.\n * @param baseUrl The base URL to use.\n */\nexport const getPreloadConfig = (\n quality: Quality,\n generator: Generator,\n modelUrlResolver: AssetUrlResolver,\n baseUrl: string\n): PreloadConfig => {\n logDeprecationWarning('getPreloadConfig');\n const builder = new ConfigurationBuilder()\n .setBaseUrl(baseUrl)\n .setMaskQuality(quality)\n .setMaskGenerator(generator)\n .setAssetUrlResolver(modelUrlResolver);\n\n // Build the preload configuration\n const config = builder.build(false);\n\n return {\n assetUrlResolver: config.assetUrlResolver,\n baseUrl: config.baseUrl,\n wasmUri: config.wasmUri,\n mask: config.mask,\n };\n};\n\n/**\n * Retrieves a PipelineConfig using the ConfigurationBuilder.\n * The function preserves the old signature for compatibility.\n * @param height The height of the input size.\n * @param width The width of the input size.\n * @param quality The desired model quality.\n * @param generator The mask generator ('local' or 'worker').\n * @param renderConfig The render configuration (blur, replacement, etc.).\n * @param modelUrlResolver A function to resolve model URLs.\n * @param baseUrl The base URL to use.\n */\nexport const getConfig = (\n height: number,\n width: number,\n quality: Quality,\n generator: Generator,\n renderConfig: BlurConfig | RenderConfig | ReplacementConfig,\n modelUrlResolver: AssetUrlResolver,\n baseUrl: string\n): PipelineConfig => {\n logDeprecationWarning('getConfig');\n const builder = new ConfigurationBuilder()\n .setBaseUrl(baseUrl)\n .setMaskQuality(quality)\n .setInputSize(height, width)\n .setRenderConfig(renderConfig)\n .setMaskGenerator(generator)\n .setAssetUrlResolver(modelUrlResolver);\n\n // Build the full configuration\n return builder.build() as PipelineConfig;\n};\n"],"names":["logDeprecationWarning","functionName","logger","getBlurConfig","blurStrength","horizontalMirror","ConfigurationBuilder","getPreloadConfig","quality","generator","modelUrlResolver","baseUrl","config","getConfig","height","width","renderConfig"],"mappings":";;AAuBA,SAASA,EAAsBC,GAA4B;AAChD,EAAAC,EAAA;AAAA,IACH,wBAAwBD,CAAY;AAAA,EACxC;AACJ;AAQa,MAAAE,IAAgB,CACzBC,GACAC,OAEAL,EAAsB,eAAe,GAC9BM,EAAqB,cAAcF,GAAcC,CAAgB,IAW/DE,IAAmB,CAC5BC,GACAC,GACAC,GACAC,MACgB;AAChB,EAAAX,EAAsB,kBAAkB;AAQlC,QAAAY,IAPU,IAAIN,IACf,WAAWK,CAAO,EAClB,eAAeH,CAAO,EACtB,iBAAiBC,CAAS,EAC1B,oBAAoBC,CAAgB,EAGlB,MAAM,EAAK;AAE3B,SAAA;AAAA,IACH,kBAAkBE,EAAO;AAAA,IACzB,SAASA,EAAO;AAAA,IAChB,SAASA,EAAO;AAAA,IAChB,MAAMA,EAAO;AAAA,EACjB;AACJ,GAaaC,IAAY,CACrBC,GACAC,GACAP,GACAC,GACAO,GACAN,GACAC,OAEAX,EAAsB,WAAW,GACjB,IAAIM,IACf,WAAWK,CAAO,EAClB,eAAeH,CAAO,EACtB,aAAaM,GAAQC,CAAK,EAC1B,gBAAgBC,CAAY,EAC5B,iBAAiBP,CAAS,EAC1B,oBAAoBC,CAAgB,EAG1B,MAAM;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import o from "../_virtual/logger.js";
|
|
2
|
+
const e = o.get("ladon-ts"), g = Object.assign(e, {
|
|
3
|
+
errorAndThrow(r) {
|
|
4
|
+
throw e.error(r), new Error(r);
|
|
5
|
+
}
|
|
6
|
+
}), n = o.createDefaultHandler({
|
|
7
|
+
/**
|
|
8
|
+
* Formatter for console logs.
|
|
9
|
+
*
|
|
10
|
+
* @param msg - Log message.
|
|
11
|
+
* @param context - Log context.
|
|
12
|
+
*/
|
|
13
|
+
formatter: (r, t) => {
|
|
14
|
+
r.unshift(t.name);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
o.setHandler(n);
|
|
18
|
+
export {
|
|
19
|
+
o as Logger,
|
|
20
|
+
g as logger
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../../../src/lib/logger.ts"],"sourcesContent":["import Logger, { ILogger } from 'js-logger';\n\n// Extend the logger interface to include custom methods.\ninterface ExtendedLogger extends ILogger {\n errorAndThrow(message: string): never;\n}\n\nconst baseLogger = Logger.get('ladon-ts');\n\n// Create an extended logger with custom methods.\nconst logger: ExtendedLogger = Object.assign(baseLogger, {\n errorAndThrow(message: string): never {\n baseLogger.error(message);\n throw new Error(message);\n },\n});\n\n// Create a handler to send logs to the console.\nconst consoleLogHandler = Logger.createDefaultHandler({\n /**\n * Formatter for console logs.\n *\n * @param msg - Log message.\n * @param context - Log context.\n */\n formatter: (msg, context) => {\n msg.unshift(context.name);\n },\n});\n\nLogger.setHandler(consoleLogHandler);\n\nexport { Logger, logger };\n"],"names":["baseLogger","Logger","logger","message","consoleLogHandler","msg","context"],"mappings":";AAOA,MAAMA,IAAaC,EAAO,IAAI,UAAU,GAGlCC,IAAyB,OAAO,OAAOF,GAAY;AAAA,EACrD,cAAcG,GAAwB;AAClC,UAAAH,EAAW,MAAMG,CAAO,GAClB,IAAI,MAAMA,CAAO;AAAA,EAAA;AAE/B,CAAC,GAGKC,IAAoBH,EAAO,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOlD,WAAW,CAACI,GAAKC,MAAY;AACrB,IAAAD,EAAA,QAAQC,EAAQ,IAAI;AAAA,EAAA;AAEhC,CAAC;AAEDL,EAAO,WAAWG,CAAiB;"}
|