@webex/ladon-ts 4.5.0 → 5.0.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 +31 -0
- package/build/module/config.json.js +26 -0
- package/build/module/config.json.js.map +1 -0
- package/build/module/index.d.ts +3 -0
- package/build/module/index.js +41 -8
- package/build/module/index.js.map +1 -0
- package/build/module/lib/config-builder.d.ts +180 -0
- package/build/module/lib/config-builder.js +336 -0
- package/build/module/lib/config-builder.js.map +1 -0
- package/build/module/lib/config-types.d.ts +98 -0
- package/build/module/lib/config-types.js +6 -0
- package/build/module/lib/config-types.js.map +1 -0
- package/build/module/lib/config.d.ts +30 -105
- package/build/module/lib/config.js +22 -151
- package/build/module/lib/config.js.map +1 -0
- package/build/module/lib/generator.d.ts +3 -1
- package/build/module/lib/generator.js +212 -273
- package/build/module/lib/generator.js.map +1 -0
- package/build/module/lib/pipeline.d.ts +11 -8
- package/build/module/lib/pipeline.js +158 -213
- package/build/module/lib/pipeline.js.map +1 -0
- package/build/module/lib/preload.d.ts +9 -0
- package/build/module/lib/preload.js +8 -0
- package/build/module/lib/preload.js.map +1 -0
- package/build/module/lib/renderer/blur-renderer.d.ts +6 -5
- package/build/module/lib/renderer/blur-renderer.js +102 -126
- package/build/module/lib/renderer/blur-renderer.js.map +1 -0
- package/build/module/lib/renderer/ladon-renderer.d.ts +3 -2
- package/build/module/lib/renderer/passthrough-renderer.d.ts +6 -5
- package/build/module/lib/renderer/passthrough-renderer.js +25 -44
- package/build/module/lib/renderer/passthrough-renderer.js.map +1 -0
- package/build/module/lib/renderer/replacement-renderer.d.ts +9 -6
- package/build/module/lib/renderer/replacement-renderer.js +84 -99
- package/build/module/lib/renderer/replacement-renderer.js.map +1 -0
- package/build/module/lib/renderer/webgl-renderer.d.ts +12 -3
- package/build/module/lib/renderer/webgl-renderer.js +168 -115
- package/build/module/lib/renderer/webgl-renderer.js.map +1 -0
- package/build/module/lib/shared-resource-manager.d.ts +40 -31
- package/build/module/lib/shared-resource-manager.js +151 -189
- package/build/module/lib/shared-resource-manager.js.map +1 -0
- package/build/module/lib/util.d.ts +10 -0
- package/build/module/lib/util.js +92 -179
- package/build/module/lib/util.js.map +1 -0
- package/build/module/lib/version.d.ts +1 -1
- package/build/module/lib/version.js +5 -2
- package/build/module/lib/version.js.map +1 -0
- package/package.json +21 -5
- package/build/module/lib/renderer/ladon-renderer.js +0 -2
- package/build/module/lib/renderer.js +0 -6
|
@@ -0,0 +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 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 /**\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":";;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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A;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;AAAA;AAAA;AAAA;AAAA;AAAA,EAQJ,OAAc,gBAAwB;AAC3B,WAAA2B;AAAA,EAAA;AAEf;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export declare enum Quality {
|
|
2
|
+
TINY = "TINY",
|
|
3
|
+
LOW = "LOW",
|
|
4
|
+
MEDIUM = "MEDIUM",
|
|
5
|
+
HIGH = "HIGH",
|
|
6
|
+
ULTRA = "ULTRA"
|
|
7
|
+
}
|
|
8
|
+
export declare enum BlurStrength {
|
|
9
|
+
WEAK = "WEAK",
|
|
10
|
+
MODERATE = "MODERATE",
|
|
11
|
+
STRONG = "STRONG",
|
|
12
|
+
STRONGER = "STRONGER",
|
|
13
|
+
STRONGEST = "STRONGEST"
|
|
14
|
+
}
|
|
15
|
+
export declare type ResolutionConfig = {
|
|
16
|
+
readonly height: number;
|
|
17
|
+
readonly width: number;
|
|
18
|
+
};
|
|
19
|
+
export interface SizeConfig {
|
|
20
|
+
readonly inputSize: ResolutionConfig;
|
|
21
|
+
readonly outputSize: ResolutionConfig;
|
|
22
|
+
readonly upscaleSize: ResolutionConfig;
|
|
23
|
+
}
|
|
24
|
+
export interface ModelQualityConfig {
|
|
25
|
+
readonly modelFile: string;
|
|
26
|
+
readonly modelRank: number;
|
|
27
|
+
readonly generationIntervalMs: number;
|
|
28
|
+
readonly inputSize: ResolutionConfig;
|
|
29
|
+
readonly outputSize: ResolutionConfig;
|
|
30
|
+
readonly upscaleSize: ResolutionConfig;
|
|
31
|
+
}
|
|
32
|
+
export declare type InputConfig = ResolutionConfig;
|
|
33
|
+
export declare type AssetUrlResolver = (assetUri: string, config: PreloadConfig) => Promise<string>;
|
|
34
|
+
export interface RenderConfig {
|
|
35
|
+
readonly type: 'blur' | 'passthrough' | 'replacement';
|
|
36
|
+
readonly horizontalMirror?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface BlurConfig extends RenderConfig {
|
|
39
|
+
readonly type: 'blur';
|
|
40
|
+
readonly kernelSize: number;
|
|
41
|
+
readonly sigma: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ReplacementConfig extends RenderConfig {
|
|
44
|
+
readonly type: 'replacement';
|
|
45
|
+
readonly background: HTMLCanvasElement;
|
|
46
|
+
readonly static: boolean;
|
|
47
|
+
}
|
|
48
|
+
export declare type Generator = 'local' | 'worker';
|
|
49
|
+
export declare type BaseMaskConfig = {
|
|
50
|
+
readonly generator: Generator;
|
|
51
|
+
readonly generationIntervalMs: number;
|
|
52
|
+
readonly modelRank: number;
|
|
53
|
+
readonly modelUri: string;
|
|
54
|
+
readonly workerUri: string;
|
|
55
|
+
readonly inputSize?: ResolutionConfig;
|
|
56
|
+
readonly outputSize?: ResolutionConfig;
|
|
57
|
+
readonly upscaleSize?: ResolutionConfig;
|
|
58
|
+
};
|
|
59
|
+
export declare type MaskConfig = BaseMaskConfig & SizeConfig;
|
|
60
|
+
export declare type PreloadConfig = {
|
|
61
|
+
readonly baseUrl?: string;
|
|
62
|
+
readonly wasmUri: string;
|
|
63
|
+
readonly mask: BaseMaskConfig;
|
|
64
|
+
readonly executionProviders?: string[];
|
|
65
|
+
readonly assetUrlResolver?: AssetUrlResolver;
|
|
66
|
+
};
|
|
67
|
+
export declare type WorkerConfig = Omit<PreloadConfig, 'assetUrlResolver'>;
|
|
68
|
+
export declare type PipelineConfig = PreloadConfig & {
|
|
69
|
+
readonly render: BlurConfig | RenderConfig | ReplacementConfig;
|
|
70
|
+
readonly input: InputConfig;
|
|
71
|
+
readonly mask: MaskConfig;
|
|
72
|
+
};
|
|
73
|
+
export interface RawConfig {
|
|
74
|
+
readonly baseUrls: {
|
|
75
|
+
readonly int: string;
|
|
76
|
+
readonly prod: string;
|
|
77
|
+
};
|
|
78
|
+
readonly basePaths: {
|
|
79
|
+
readonly models: string;
|
|
80
|
+
readonly wasm: string;
|
|
81
|
+
readonly workers: string;
|
|
82
|
+
};
|
|
83
|
+
readonly blurStrengths: {
|
|
84
|
+
readonly [key in Lowercase<BlurStrength>]: {
|
|
85
|
+
readonly kernelSize: number;
|
|
86
|
+
readonly sigma: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
readonly modelQualities: {
|
|
90
|
+
readonly [key in Lowercase<Quality>]: ModelQualityConfig;
|
|
91
|
+
};
|
|
92
|
+
readonly onnxVersion: string;
|
|
93
|
+
readonly modelVersion: string;
|
|
94
|
+
readonly workerFile: string;
|
|
95
|
+
readonly modelUrlTemplate: string;
|
|
96
|
+
readonly wasmPathTemplate: string;
|
|
97
|
+
readonly workerUrlTemplate: string;
|
|
98
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var E = /* @__PURE__ */ ((T) => (T.TINY = "TINY", T.LOW = "LOW", T.MEDIUM = "MEDIUM", T.HIGH = "HIGH", T.ULTRA = "ULTRA", T))(E || {}), R = /* @__PURE__ */ ((T) => (T.WEAK = "WEAK", T.MODERATE = "MODERATE", T.STRONG = "STRONG", T.STRONGER = "STRONGER", T.STRONGEST = "STRONGEST", T))(R || {});
|
|
2
|
+
export {
|
|
3
|
+
R as BlurStrength,
|
|
4
|
+
E as Quality
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=config-types.js.map
|
|
@@ -0,0 +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 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,105 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export interface BlurConfig extends RenderConfig {
|
|
32
|
-
readonly type: 'blur';
|
|
33
|
-
readonly kernel_size: number;
|
|
34
|
-
readonly sigma: number;
|
|
35
|
-
}
|
|
36
|
-
export interface ReplacementConfig extends RenderConfig {
|
|
37
|
-
readonly type: 'replacement';
|
|
38
|
-
background: HTMLCanvasElement;
|
|
39
|
-
readonly static: boolean;
|
|
40
|
-
}
|
|
41
|
-
export declare type Generator = 'local' | 'worker';
|
|
42
|
-
export declare type BaseMaskConfig = {
|
|
43
|
-
readonly generator: Generator;
|
|
44
|
-
readonly generation_interval_ms: number;
|
|
45
|
-
readonly model_rank: number;
|
|
46
|
-
readonly model_url_resolver: ModelUrlResolver;
|
|
47
|
-
readonly model_uri: string;
|
|
48
|
-
readonly worker_uri: string;
|
|
49
|
-
readonly input_size?: SizeConfig;
|
|
50
|
-
readonly output_size?: SizeConfig;
|
|
51
|
-
readonly upscaled_size?: SizeConfig;
|
|
52
|
-
};
|
|
53
|
-
export declare type MaskConfig = BaseMaskConfig & {
|
|
54
|
-
readonly input_size: SizeConfig;
|
|
55
|
-
readonly output_size: SizeConfig;
|
|
56
|
-
readonly upscaled_size: SizeConfig;
|
|
57
|
-
};
|
|
58
|
-
export declare type PreloadConfig = {
|
|
59
|
-
readonly base_url?: string;
|
|
60
|
-
readonly wasm_uri?: string;
|
|
61
|
-
readonly mask: BaseMaskConfig;
|
|
62
|
-
};
|
|
63
|
-
export declare type PipelineConfig = {
|
|
64
|
-
readonly base_url?: string;
|
|
65
|
-
readonly wasm_uri?: string;
|
|
66
|
-
readonly render: BlurConfig | RenderConfig | ReplacementConfig;
|
|
67
|
-
readonly input: InputConfig;
|
|
68
|
-
readonly mask: MaskConfig;
|
|
69
|
-
};
|
|
70
|
-
export declare const getBlurConfig: (blur_strength: BlurStrength, horizontal_mirror?: boolean) => BlurConfig;
|
|
71
|
-
export declare const getPreloadConfig: (quality?: Quality, generator?: Generator, model_url_resolver?: ModelUrlResolver, base_url?: string, useLocalWorker?: boolean) => {
|
|
72
|
-
mask: {
|
|
73
|
-
generator: Generator;
|
|
74
|
-
generation_interval_ms: number;
|
|
75
|
-
model_rank: number;
|
|
76
|
-
model_url_resolver: ModelUrlResolver;
|
|
77
|
-
model_uri: string;
|
|
78
|
-
worker_uri: string;
|
|
79
|
-
input_size?: SizeConfig | undefined;
|
|
80
|
-
output_size?: SizeConfig | undefined;
|
|
81
|
-
upscaled_size?: SizeConfig | undefined;
|
|
82
|
-
};
|
|
83
|
-
base_url?: string | undefined;
|
|
84
|
-
wasm_uri?: string | undefined;
|
|
85
|
-
};
|
|
86
|
-
export declare const getConfig: (height: number, width: number, quality?: Quality, generator?: Generator, renderConfig?: BlurConfig | RenderConfig | ReplacementConfig, modelUrlResolver?: ModelUrlResolver, baseUrl?: string, useLocalWorker?: boolean) => {
|
|
87
|
-
render: RenderConfig | BlurConfig | ReplacementConfig;
|
|
88
|
-
input: {
|
|
89
|
-
height: number;
|
|
90
|
-
width: number;
|
|
91
|
-
};
|
|
92
|
-
mask: {
|
|
93
|
-
input_size: SizeConfig;
|
|
94
|
-
output_size: SizeConfig;
|
|
95
|
-
upscaled_size: SizeConfig;
|
|
96
|
-
generator: Generator;
|
|
97
|
-
generation_interval_ms: number;
|
|
98
|
-
model_rank: number;
|
|
99
|
-
model_url_resolver: ModelUrlResolver;
|
|
100
|
-
model_uri: string;
|
|
101
|
-
worker_uri: string;
|
|
102
|
-
};
|
|
103
|
-
base_url?: string | undefined;
|
|
104
|
-
wasm_uri?: string | undefined;
|
|
105
|
-
};
|
|
1
|
+
import { AssetUrlResolver, BlurConfig, BlurStrength, Generator, PipelineConfig, PreloadConfig, Quality, RenderConfig, ReplacementConfig } from './config-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates a blur configuration based on the specified blur strength.
|
|
5
|
+
* This function uses the static method from ConfigurationBuilder.
|
|
6
|
+
* @param blurStrength The desired blur strength.
|
|
7
|
+
* @param horizontalMirror Whether to apply horizontal mirroring.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getBlurConfig: (blurStrength: BlurStrength, horizontalMirror?: boolean) => BlurConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves a PreloadConfig using the ConfigurationBuilder.
|
|
12
|
+
* The function preserves the old signature for compatibility.
|
|
13
|
+
* @param quality The desired model quality.
|
|
14
|
+
* @param generator The mask generator ('local' or 'worker').
|
|
15
|
+
* @param modelUrlResolver A function to resolve model URLs.
|
|
16
|
+
* @param baseUrl The base URL to use.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getPreloadConfig: (quality: Quality, generator: Generator, modelUrlResolver: AssetUrlResolver, baseUrl: string) => PreloadConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves a PipelineConfig using the ConfigurationBuilder.
|
|
21
|
+
* The function preserves the old signature for compatibility.
|
|
22
|
+
* @param height The height of the input size.
|
|
23
|
+
* @param width The width of the input size.
|
|
24
|
+
* @param quality The desired model quality.
|
|
25
|
+
* @param generator The mask generator ('local' or 'worker').
|
|
26
|
+
* @param renderConfig The render configuration (blur, replacement, etc.).
|
|
27
|
+
* @param modelUrlResolver A function to resolve model URLs.
|
|
28
|
+
* @param baseUrl The base URL to use.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getConfig: (height: number, width: number, quality: Quality, generator: Generator, renderConfig: BlurConfig | RenderConfig | ReplacementConfig, modelUrlResolver: AssetUrlResolver, baseUrl: string) => PipelineConfig;
|
|
@@ -1,151 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
BlurStrength["STRONGEST"] = "STRONGEST";
|
|
24
|
-
})(BlurStrength || (BlurStrength = {}));
|
|
25
|
-
export const getBlurConfig = (blur_strength, horizontal_mirror) => {
|
|
26
|
-
let kernel_size = 25;
|
|
27
|
-
let sigma = 11;
|
|
28
|
-
switch (blur_strength) {
|
|
29
|
-
case BlurStrength.WEAK:
|
|
30
|
-
kernel_size = 9;
|
|
31
|
-
sigma = 2;
|
|
32
|
-
break;
|
|
33
|
-
case BlurStrength.MODERATE:
|
|
34
|
-
kernel_size = 15;
|
|
35
|
-
sigma = 6;
|
|
36
|
-
break;
|
|
37
|
-
case BlurStrength.STRONG:
|
|
38
|
-
kernel_size = 25;
|
|
39
|
-
sigma = 11;
|
|
40
|
-
break;
|
|
41
|
-
case BlurStrength.STRONGER:
|
|
42
|
-
kernel_size = 37;
|
|
43
|
-
sigma = 17;
|
|
44
|
-
break;
|
|
45
|
-
case BlurStrength.STRONGEST:
|
|
46
|
-
kernel_size = 49;
|
|
47
|
-
sigma = 23;
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
type: 'blur',
|
|
54
|
-
horizontal_mirror,
|
|
55
|
-
kernel_size,
|
|
56
|
-
sigma,
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
export const getPreloadConfig = (quality = Quality.LOW, generator = 'local', model_url_resolver = (model_path) => Promise.resolve(toAbsoluteURI(model_path, BASE_URL)), base_url = BASE_URL, useLocalWorker = false) => {
|
|
60
|
-
const model_version = MODEL_VERSION;
|
|
61
|
-
const localBaseUrl = `${LOCAL_BASE_URL}:${LOCAL_PORT}`;
|
|
62
|
-
const workerBaseUrl = useLocalWorker ? localBaseUrl : base_url;
|
|
63
|
-
const workerScriptPath = useLocalWorker
|
|
64
|
-
? LOCAL_WORKER_URI
|
|
65
|
-
: `/${LIB_VERSION}/worker/segmentation.js`;
|
|
66
|
-
const worker_uri = toAbsoluteURI(workerScriptPath, workerBaseUrl);
|
|
67
|
-
const base_config = {
|
|
68
|
-
base_url,
|
|
69
|
-
wasm_uri: WASM_URI,
|
|
70
|
-
mask: {
|
|
71
|
-
generator,
|
|
72
|
-
generation_interval_ms: 48,
|
|
73
|
-
model_uri: `/models/${model_version}/tiny-256x144-256x144.onnx`,
|
|
74
|
-
input_size: { height: 144, width: 256 },
|
|
75
|
-
output_size: { height: 144, width: 256 },
|
|
76
|
-
upscaled_size: { height: 360, width: 640 },
|
|
77
|
-
model_rank: 4,
|
|
78
|
-
model_url_resolver,
|
|
79
|
-
worker_uri,
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
let mask_quality_config = {};
|
|
83
|
-
switch (quality) {
|
|
84
|
-
case Quality.TINY:
|
|
85
|
-
mask_quality_config = {
|
|
86
|
-
generation_interval_ms: 48,
|
|
87
|
-
model_uri: `/models/${model_version}/tiny-256x144-256x144.onnx`,
|
|
88
|
-
input_size: { height: 144, width: 256 },
|
|
89
|
-
output_size: { height: 144, width: 256 },
|
|
90
|
-
upscaled_size: { height: 144, width: 256 },
|
|
91
|
-
model_rank: 4,
|
|
92
|
-
};
|
|
93
|
-
break;
|
|
94
|
-
case Quality.LOW:
|
|
95
|
-
mask_quality_config = {
|
|
96
|
-
generation_interval_ms: 48,
|
|
97
|
-
model_uri: `/models/${model_version}/low-256x144-256x144.onnx`,
|
|
98
|
-
input_size: { height: 144, width: 256 },
|
|
99
|
-
output_size: { height: 144, width: 256 },
|
|
100
|
-
upscaled_size: { height: 360, width: 640 },
|
|
101
|
-
model_rank: 4,
|
|
102
|
-
};
|
|
103
|
-
break;
|
|
104
|
-
case Quality.MEDIUM:
|
|
105
|
-
mask_quality_config = {
|
|
106
|
-
generation_interval_ms: 24,
|
|
107
|
-
model_uri: `/models/${model_version}/medium-256x144-256x144.onnx`,
|
|
108
|
-
input_size: { height: 144, width: 256 },
|
|
109
|
-
output_size: { height: 144, width: 256 },
|
|
110
|
-
upscaled_size: { height: 360, width: 640 },
|
|
111
|
-
model_rank: 4,
|
|
112
|
-
};
|
|
113
|
-
break;
|
|
114
|
-
case Quality.HIGH:
|
|
115
|
-
mask_quality_config = {
|
|
116
|
-
generation_interval_ms: 36,
|
|
117
|
-
model_uri: `/models/${model_version}/medium-640x360-256x144.onnx`,
|
|
118
|
-
input_size: { height: 360, width: 640 },
|
|
119
|
-
output_size: { height: 360, width: 640 },
|
|
120
|
-
upscaled_size: { height: 360, width: 640 },
|
|
121
|
-
model_rank: 4,
|
|
122
|
-
};
|
|
123
|
-
break;
|
|
124
|
-
case Quality.ULTRA:
|
|
125
|
-
mask_quality_config = {
|
|
126
|
-
generation_interval_ms: 0,
|
|
127
|
-
model_uri: `/models/${model_version}/medium-640x360-256x144.onnx`,
|
|
128
|
-
input_size: { height: 360, width: 640 },
|
|
129
|
-
output_size: { height: 360, width: 640 },
|
|
130
|
-
upscaled_size: { height: 360, width: 640 },
|
|
131
|
-
model_rank: 4,
|
|
132
|
-
};
|
|
133
|
-
break;
|
|
134
|
-
default:
|
|
135
|
-
throw new Error('[ladon-ts] - unknown quality option: ' + quality);
|
|
136
|
-
}
|
|
137
|
-
return Object.assign(Object.assign({}, base_config), { mask: Object.assign(Object.assign({}, base_config.mask), mask_quality_config) });
|
|
138
|
-
};
|
|
139
|
-
export const getConfig = (height, width, quality = Quality.LOW, generator = 'local', renderConfig = {
|
|
140
|
-
type: 'blur',
|
|
141
|
-
horizontal_mirror: false,
|
|
142
|
-
kernel_size: 37,
|
|
143
|
-
sigma: 17,
|
|
144
|
-
}, modelUrlResolver = (model_path) => Promise.resolve(toAbsoluteURI(model_path, BASE_URL)), baseUrl = BASE_URL, useLocalWorker = false) => {
|
|
145
|
-
const basePreloadConfig = getPreloadConfig(quality, generator, modelUrlResolver, baseUrl, useLocalWorker);
|
|
146
|
-
const maskConfig = basePreloadConfig.mask;
|
|
147
|
-
return Object.assign(Object.assign({}, basePreloadConfig), { render: renderConfig, input: { height, width }, mask: Object.assign(Object.assign({}, maskConfig), {
|
|
148
|
-
// Need to ensure we don't override the tiny model's input and output sizes.
|
|
149
|
-
input_size: maskConfig.input_size || { height, width }, output_size: maskConfig.output_size || { height, width }, upscaled_size: maskConfig.upsca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QUNULGdCQUFnQixFQUNoQixPQUFPLEVBQ1AsY0FBYyxDQUNqQixDQUFDO0lBQ0YsTUFBTSxVQUFVLEdBQUcsaUJBQWlCLENBQUMsSUFBSSxDQUFDO0lBRTFDLHVDQUNPLGlCQUFpQixLQUNwQixNQUFNLEVBQUUsWUFBWSxFQUNwQixLQUFLLEVBQUUsRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLEVBQ3hCLElBQUksa0NBQ0csVUFBVTtZQUNiLDRFQUE0RTtZQUM1RSxVQUFVLEVBQUUsVUFBVSxDQUFDLFVBQVUsSUFBSSxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsRUFDdEQsV0FBVyxFQUFFLFVBQVUsQ0FBQyxXQUFXLElBQUksRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLEVBQ3hELGFBQWEsRUFBRSxVQUFVLENBQUMsYUFBYSxJQUFJLEVBQUUsTUFBTSxFQUFFLEtBQUssRUFBRSxPQUVsRTtBQUNOLENBQUMsQ0FBQyJ9
|
|
1
|
+
import { ConfigurationBuilder as o } from "./config-builder.js";
|
|
2
|
+
function i(e) {
|
|
3
|
+
console.warn(
|
|
4
|
+
`[ladon-ts] Deprecation Warning: ${e} is deprecated and will be removed in a future release. Please migrate to ConfigurationBuilder for future use.`
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
const f = (e, t) => (i("getBlurConfig"), o.getBlurConfig(e, t)), d = (e, t, s, n) => {
|
|
8
|
+
i("getPreloadConfig");
|
|
9
|
+
const r = new o().setBaseUrl(n).setMaskQuality(e).setMaskGenerator(t).setAssetUrlResolver(s).build(!1);
|
|
10
|
+
return {
|
|
11
|
+
assetUrlResolver: r.assetUrlResolver,
|
|
12
|
+
baseUrl: r.baseUrl,
|
|
13
|
+
wasmUri: r.wasmUri,
|
|
14
|
+
mask: r.mask
|
|
15
|
+
};
|
|
16
|
+
}, c = (e, t, s, n, a, r, l) => (i("getConfig"), new o().setBaseUrl(l).setMaskQuality(s).setInputSize(e, t).setRenderConfig(a).setMaskGenerator(n).setAssetUrlResolver(r).build());
|
|
17
|
+
export {
|
|
18
|
+
f as getBlurConfig,
|
|
19
|
+
c as getConfig,
|
|
20
|
+
d as getPreloadConfig
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +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 console.warn(\n `[ladon-ts] 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","getBlurConfig","blurStrength","horizontalMirror","ConfigurationBuilder","getPreloadConfig","quality","generator","modelUrlResolver","baseUrl","config","getConfig","height","width","renderConfig"],"mappings":";AAsBA,SAASA,EAAsBC,GAA4B;AAC/C,UAAA;AAAA,IACJ,mCAAmCA,CAAY;AAAA,EACnD;AACJ;AAQa,MAAAC,IAAgB,CACzBC,GACAC,OAEAJ,EAAsB,eAAe,GAC9BK,EAAqB,cAAcF,GAAcC,CAAgB,IAW/DE,IAAmB,CAC5BC,GACAC,GACAC,GACAC,MACgB;AAChB,EAAAV,EAAsB,kBAAkB;AAQlC,QAAAW,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,OAEAV,EAAsB,WAAW,GACjB,IAAIK,IACf,WAAWK,CAAO,EAClB,eAAeH,CAAO,EACtB,aAAaM,GAAQC,CAAK,EAC1B,gBAAgBC,CAAY,EAC5B,iBAAiBP,CAAS,EAC1B,oBAAoBC,CAAgB,EAG1B,MAAM;"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { PipelineConfig } from './config';
|
|
1
|
+
import { PipelineConfig } from './config-types';
|
|
2
|
+
|
|
2
3
|
declare global {
|
|
3
4
|
interface ImportMeta {
|
|
4
5
|
url: string;
|
|
5
6
|
}
|
|
6
7
|
}
|
|
8
|
+
export declare type FrameData = Uint8ClampedArray | HTMLVideoElement;
|
|
7
9
|
export interface FacesAndLandmarks {
|
|
8
10
|
data: Float32Array;
|
|
9
11
|
dims: readonly number[];
|