@jetprint/editor-sdk 1.2.4 → 1.2.5
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/dist/components/Editor/components/EditorAddToCartDialog.vue.d.ts +1 -0
- package/dist/components/Editor/components/EditorTopbar.vue.d.ts +24 -0
- package/dist/components/Editor/components/EmbroideryStitchPanel.vue.d.ts +9 -0
- package/dist/components/Editor/components/PreviewPanel.vue.d.ts +1 -1
- package/dist/components/Editor/composables/useBackgroundRemoval.d.ts +2 -1
- package/dist/components/Editor/composables/useCanvasStateByDiecut.d.ts +8 -0
- package/dist/components/Editor/composables/useCanvasViewport.d.ts +1 -0
- package/dist/components/Editor/composables/useEmbroidery.d.ts +57 -0
- package/dist/components/Editor/composables/usePreviewRenderer.d.ts +2 -0
- package/dist/components/Editor/headless/headlessFontLoader.d.ts +7 -0
- package/dist/components/Editor/index.vue.d.ts +7 -5
- package/dist/components/Editor/utils/editorSizeOptions.d.ts +6 -0
- package/dist/components/Editor/utils/embroideryStitch.d.ts +25 -0
- package/dist/components/Editor/utils/pillow3dPreview.d.ts +37 -0
- package/dist/components/Editor/workers/embroidery.worker.d.ts +47 -0
- package/dist/editor-sdk.es.js +27141 -25890
- package/dist/index.d.ts +6 -0
- package/dist/style.css +1 -1
- package/dist/types.d.ts +31 -1
- package/dist/utils/backgroundRenderer.d.ts +6 -3
- package/dist/utils/protection/encryptedModules.generated.d.ts +1 -1
- package/dist/utils/renderedImagesDB.d.ts +3 -0
- package/package.json +1 -1
|
@@ -16,6 +16,16 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
16
16
|
type: BooleanConstructor;
|
|
17
17
|
default: boolean;
|
|
18
18
|
};
|
|
19
|
+
/** 特殊设计模式受控值:none|embroidery(刺绣)|pillow3d(异形抱枕),由父组件 specialMode 传入 */
|
|
20
|
+
specialMode: {
|
|
21
|
+
type: StringConstructor;
|
|
22
|
+
default: string;
|
|
23
|
+
};
|
|
24
|
+
/** 是否显示「刺绣 / 异形抱枕」互斥模式开关(default 与 theme1 均可显示) */
|
|
25
|
+
showSpecialMode: {
|
|
26
|
+
type: BooleanConstructor;
|
|
27
|
+
default: boolean;
|
|
28
|
+
};
|
|
19
29
|
colorOptions: {
|
|
20
30
|
type: PropType<string[]>;
|
|
21
31
|
default: () => never[];
|
|
@@ -154,6 +164,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
154
164
|
"toggle-grid": (...args: any[]) => void;
|
|
155
165
|
"clear-canvas": (...args: any[]) => void;
|
|
156
166
|
"clear-guides": (...args: any[]) => void;
|
|
167
|
+
"update:special-mode": (...args: any[]) => void;
|
|
157
168
|
"download-png": (...args: any[]) => void;
|
|
158
169
|
"switch-to-gallery": (...args: any[]) => void;
|
|
159
170
|
"open-shortcuts": (...args: any[]) => void;
|
|
@@ -174,6 +185,16 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
174
185
|
type: BooleanConstructor;
|
|
175
186
|
default: boolean;
|
|
176
187
|
};
|
|
188
|
+
/** 特殊设计模式受控值:none|embroidery(刺绣)|pillow3d(异形抱枕),由父组件 specialMode 传入 */
|
|
189
|
+
specialMode: {
|
|
190
|
+
type: StringConstructor;
|
|
191
|
+
default: string;
|
|
192
|
+
};
|
|
193
|
+
/** 是否显示「刺绣 / 异形抱枕」互斥模式开关(default 与 theme1 均可显示) */
|
|
194
|
+
showSpecialMode: {
|
|
195
|
+
type: BooleanConstructor;
|
|
196
|
+
default: boolean;
|
|
197
|
+
};
|
|
177
198
|
colorOptions: {
|
|
178
199
|
type: PropType<string[]>;
|
|
179
200
|
default: () => never[];
|
|
@@ -312,6 +333,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
312
333
|
"onToggle-grid"?: ((...args: any[]) => any) | undefined;
|
|
313
334
|
"onClear-canvas"?: ((...args: any[]) => any) | undefined;
|
|
314
335
|
"onClear-guides"?: ((...args: any[]) => any) | undefined;
|
|
336
|
+
"onUpdate:special-mode"?: ((...args: any[]) => any) | undefined;
|
|
315
337
|
"onDownload-png"?: ((...args: any[]) => any) | undefined;
|
|
316
338
|
"onSwitch-to-gallery"?: ((...args: any[]) => any) | undefined;
|
|
317
339
|
"onOpen-shortcuts"?: ((...args: any[]) => any) | undefined;
|
|
@@ -330,6 +352,8 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
330
352
|
sizeOptions: string[];
|
|
331
353
|
colorOptions: string[];
|
|
332
354
|
productName: string;
|
|
355
|
+
specialMode: string;
|
|
356
|
+
showSpecialMode: boolean;
|
|
333
357
|
colorLabelByValue: Record<string, string>;
|
|
334
358
|
multiSku: boolean;
|
|
335
359
|
selectedColors: string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
/** useEmbroidery() 的返回对象 */
|
|
3
|
+
embroidery: any;
|
|
4
|
+
variant?: 'default' | 'theme1';
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
7
|
+
variant: "default" | "theme1";
|
|
8
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
export default _default;
|
|
@@ -364,6 +364,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
364
364
|
sizeOptions: string[];
|
|
365
365
|
colorOptions: string[];
|
|
366
366
|
colorLabelByValue: Record<string, string>;
|
|
367
|
+
variant: "default" | "theme1";
|
|
367
368
|
loadingDesign: boolean;
|
|
368
369
|
renderData: IRenderByJson | null;
|
|
369
370
|
previewTitle: string;
|
|
@@ -378,7 +379,6 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
378
379
|
getAllDiecutFabricData: () => Promise<Record<string, unknown>>;
|
|
379
380
|
usePreviewEffect: boolean;
|
|
380
381
|
showDownloadButton: boolean;
|
|
381
|
-
variant: "default" | "theme1";
|
|
382
382
|
mockupShowSave: boolean;
|
|
383
383
|
mockupShowCart: boolean;
|
|
384
384
|
backgroundRenderPaused: boolean;
|
|
@@ -13,7 +13,8 @@ export interface UseBackgroundRemovalOptions {
|
|
|
13
13
|
*/
|
|
14
14
|
publicPath?: string;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* 模型变体(@imgly 1.7.0,与本地自托管 data 配套):'isnet_fp16'(84MB,质量最好) / 'isnet_quint8'(42MB,体积小一半) / 'isnet'。
|
|
17
|
+
* 默认 'isnet_quint8'。
|
|
17
18
|
*/
|
|
18
19
|
model?: 'isnet' | 'isnet_fp16' | 'isnet_quint8';
|
|
19
20
|
/**
|
|
@@ -22,6 +22,14 @@ export interface CanvasStateOptions {
|
|
|
22
22
|
getSelectedSize?: () => string;
|
|
23
23
|
/** 加载 JSON 完成后调用,用于从 customData 重建图案矩形 fill(Fabric 序列化会丢失 Pattern source) */
|
|
24
24
|
afterLoadCanvasJson?: (canvas: any) => void | Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* restore(loadFromJSON)完成、onDone 末尾触发:按存档画布尺寸重算对象坐标到当前画布尺寸。
|
|
27
|
+
* 参数 savedCanvasWidth = 存档时的画布逻辑宽度(state.designCanvasSize)。
|
|
28
|
+
* 根因:存档 json 无原生 width/height,loadFromJSON 不改画布尺寸(画布尺寸由容器决定),
|
|
29
|
+
* 故 objects 的 left/top(存档尺寸下的绝对像素)与「当前容器尺寸」画布不匹配 → 整体平移。
|
|
30
|
+
* 详见 viewport-restore-realign-design.md。
|
|
31
|
+
*/
|
|
32
|
+
onAfterRestore?: (savedCanvasWidth: number) => void | Promise<void>;
|
|
25
33
|
/** 将 HTTP 图片 URL 解析为 blob URL(通过 fetchWithFileToken 加载),用于 loadFromJSON 前预处理 */
|
|
26
34
|
resolveImageUrl?: (url: string) => Promise<string>;
|
|
27
35
|
}
|
|
@@ -70,6 +70,7 @@ export declare function useCanvasViewport(options: CanvasViewportOptions): {
|
|
|
70
70
|
zoomOut: () => void;
|
|
71
71
|
fitCanvas: () => void;
|
|
72
72
|
handleWrapResize: () => void;
|
|
73
|
+
rescaleObjectsFromSavedSize: (savedWidth: number) => void;
|
|
73
74
|
refreshGuideResourcesCentered: () => void;
|
|
74
75
|
setupWindowResize: () => void;
|
|
75
76
|
removeWindowResize: () => void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type StitchKey } from '../utils/embroideryStitch';
|
|
2
|
+
type RGB = [number, number, number];
|
|
3
|
+
export interface EmbroideryRegion {
|
|
4
|
+
id: number;
|
|
5
|
+
clusterIdx: number;
|
|
6
|
+
color: RGB;
|
|
7
|
+
area: number;
|
|
8
|
+
bbox: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
w: number;
|
|
12
|
+
h: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export type EmbroideryStitchKey = StitchKey;
|
|
16
|
+
/** 针法清单(移植自 Ink/Stitch 可纹理化的部分)。 */
|
|
17
|
+
export declare const EMBROIDERY_STITCH_TYPES: ReadonlyArray<{
|
|
18
|
+
key: EmbroideryStitchKey;
|
|
19
|
+
label: string;
|
|
20
|
+
}>;
|
|
21
|
+
export interface UseEmbroideryOptions {
|
|
22
|
+
/** 取 Fabric 画布实例 */
|
|
23
|
+
getCanvas: () => any;
|
|
24
|
+
/** 工作尺寸上限(长边像素),超过则缩放后处理,默认 1000 */
|
|
25
|
+
maxWorkSize?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function useEmbroidery(options: UseEmbroideryOptions): {
|
|
28
|
+
isActive: import("vue").Ref<boolean, boolean>;
|
|
29
|
+
isProcessing: import("vue").Ref<boolean, boolean>;
|
|
30
|
+
error: import("vue").Ref<string | null, string | null>;
|
|
31
|
+
colorCount: import("vue").Ref<number, number>;
|
|
32
|
+
mergeColorDist: import("vue").Ref<number, number>;
|
|
33
|
+
palette: import("vue").Ref<[number, number, number][], RGB[] | [number, number, number][]>;
|
|
34
|
+
regions: import("vue").ShallowRef<EmbroideryRegion[], EmbroideryRegion[]>;
|
|
35
|
+
regionCount: import("vue").Ref<number, number>;
|
|
36
|
+
regionStitch: import("vue").Ref<Record<number, StitchKey>, Record<number, StitchKey>>;
|
|
37
|
+
regionParams: import("vue").Ref<Record<number, {
|
|
38
|
+
spacing?: number;
|
|
39
|
+
angle?: number;
|
|
40
|
+
}>, Record<number, {
|
|
41
|
+
spacing?: number;
|
|
42
|
+
angle?: number;
|
|
43
|
+
}>>;
|
|
44
|
+
selectedRegionId: import("vue").Ref<number | null, number | null>;
|
|
45
|
+
activate: () => Promise<boolean>;
|
|
46
|
+
deactivate: () => Promise<void>;
|
|
47
|
+
setColorCount: (k: number) => Promise<void>;
|
|
48
|
+
selectRegion: (regionId: number) => void;
|
|
49
|
+
setRegionStitch: (regionId: number, type: EmbroideryStitchKey) => void;
|
|
50
|
+
setRegionParams: (regionId: number, patch: {
|
|
51
|
+
spacing?: number;
|
|
52
|
+
angle?: number;
|
|
53
|
+
}) => void;
|
|
54
|
+
getEmbroideryData: () => Record<string, unknown> | null;
|
|
55
|
+
dispose: () => void;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
@@ -47,6 +47,8 @@ export declare function usePreviewRenderer(options: {
|
|
|
47
47
|
getEditorAreaWidth?: () => number;
|
|
48
48
|
/** 当前选中尺码,多尺码时使 fabricScreenshotList id 与 psdJson 一致 */
|
|
49
49
|
getSelectedSize?: () => string;
|
|
50
|
+
/** 特殊设计模式(none|embroidery|pillow3d)。pillow3d 时把设计截图过伪立体效果,作为预览效果图的设计纹理 */
|
|
51
|
+
getSpecialMode?: () => string;
|
|
50
52
|
saveCanvasState: (diecutId: string) => Promise<void>;
|
|
51
53
|
generateDiecutScreenshot: (diecutId: string, opts?: {
|
|
52
54
|
multiplier?: number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 确保给定字体族(来自 fabric 文字对象的 fontFamily)已加载完成。
|
|
3
|
+
* 传空数组则预热全部内置字体。渲染前调用并 await,避免文字用系统兜底字体。
|
|
4
|
+
*/
|
|
5
|
+
export declare function ensureFontsForCanvas(families: string[]): Promise<void>;
|
|
6
|
+
/** 递归收集 fabric 状态对象(含 group 嵌套)里所有文字对象的 fontFamily。 */
|
|
7
|
+
export declare function collectFontFamilies(objects: any[]): string[];
|
|
@@ -29,6 +29,7 @@ type EditorProps = {
|
|
|
29
29
|
onAddToCartSuccess?: (payload?: {
|
|
30
30
|
addedCount?: number;
|
|
31
31
|
psTaskCode?: string;
|
|
32
|
+
psTaskId?: string;
|
|
32
33
|
}) => void;
|
|
33
34
|
onAddToCartError?: (msg?: string) => void;
|
|
34
35
|
onGoHome?: () => void;
|
|
@@ -42,15 +43,15 @@ type EditorProps = {
|
|
|
42
43
|
/** 左侧栏额外 Tab(竖条 + 内容区由宿主传入 Vue 组件) */
|
|
43
44
|
customSidebarTabs?: CustomSidebarTabDef[];
|
|
44
45
|
};
|
|
45
|
-
declare var
|
|
46
|
+
declare var __VLS_22: {}, __VLS_28: {}, __VLS_141: {}, __VLS_147: {};
|
|
46
47
|
type __VLS_Slots = {} & {
|
|
47
|
-
'topbar-left'?: (props: typeof
|
|
48
|
+
'topbar-left'?: (props: typeof __VLS_22) => any;
|
|
48
49
|
} & {
|
|
49
|
-
'topbar-right'?: (props: typeof
|
|
50
|
+
'topbar-right'?: (props: typeof __VLS_28) => any;
|
|
50
51
|
} & {
|
|
51
|
-
'topbar-left'?: (props: typeof
|
|
52
|
+
'topbar-left'?: (props: typeof __VLS_141) => any;
|
|
52
53
|
} & {
|
|
53
|
-
'topbar-right'?: (props: typeof
|
|
54
|
+
'topbar-right'?: (props: typeof __VLS_147) => any;
|
|
54
55
|
};
|
|
55
56
|
declare const __VLS_component: import("vue").DefineComponent<EditorProps, {
|
|
56
57
|
renderAllTemplates: () => Promise<Array<{
|
|
@@ -172,6 +173,7 @@ declare const __VLS_component: import("vue").DefineComponent<EditorProps, {
|
|
|
172
173
|
onAddToCartSuccess: (payload?: {
|
|
173
174
|
addedCount?: number;
|
|
174
175
|
psTaskCode?: string;
|
|
176
|
+
psTaskId?: string;
|
|
175
177
|
}) => void;
|
|
176
178
|
onAddToCartError: (msg?: string) => void;
|
|
177
179
|
messages: Record<string, string>;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/** 编辑器尺码:与刀板里的 "default" 占位一致,大小写不敏感 */
|
|
2
2
|
/** theme1 产品面板「全部」选项值(颜色 / 尺码共用) */
|
|
3
3
|
export declare const SKU_ALL_VALUE = "all";
|
|
4
|
+
/**
|
|
5
|
+
* 服务端"默认" SKU(尺码/颜色)的规范值——接口对默认 SKU 统一返回大写 `Default`。
|
|
6
|
+
* SDK 在【空值兜底 / 输出 / 文件命名】处一律用它,杜绝自造小写 `default` 导致与服务端不一致、第三方匹配不上。
|
|
7
|
+
* 注意:匹配判断仍走大小写不敏感的 isDefaultSkuLabel;本常量只用于"需要产出一个默认值"的场合。
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_SKU_VALUE = "Default";
|
|
4
10
|
export declare function isDefaultSizeLabel(s: string): boolean;
|
|
5
11
|
/** 与 isDefaultSizeLabel 同义,供颜色 SKU 复用 */
|
|
6
12
|
export declare const isDefaultSkuLabel: typeof isDefaultSizeLabel;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 刺绣 · 针法纹理渲染(节点③)
|
|
3
|
+
*
|
|
4
|
+
* 给定一个「色块形状蒙版」(mask,不透明=该色块) + 颜色 + 针法类型,
|
|
5
|
+
* 生成一张同尺寸 canvas:在整块范围画出该针法的纹理,再裁剪(destination-in)到色块形状内。
|
|
6
|
+
* 纯 Canvas 2D,纹理是「视觉效果」近似(非真实绣花机针迹)。
|
|
7
|
+
*/
|
|
8
|
+
export type StitchKey = 'satin' | 'fill' | 'running' | 'cross' | 'frenchKnot' | 'bean' | 'zigzag' | 'estitch' | 'tartan' | 'circular' | 'spiral' | 'meander' | 'contour';
|
|
9
|
+
type RGB = [number, number, number];
|
|
10
|
+
export interface StitchParams {
|
|
11
|
+
/** 针距/纹理密度基准(px),越小越密;默认按类型取值 */
|
|
12
|
+
spacing?: number;
|
|
13
|
+
/** 绣线角度(度),默认 45 */
|
|
14
|
+
angle?: number;
|
|
15
|
+
}
|
|
16
|
+
/** 各针法默认针距(与 drawPattern 内的 ?? 值一致),供面板滑块取初值。 */
|
|
17
|
+
export declare const STITCH_DEFAULT_SPACING: Record<StitchKey, number>;
|
|
18
|
+
/** 哪些针法的「角度」有意义(其余用各自固有朝向,角度无效)。 */
|
|
19
|
+
export declare const STITCH_USES_ANGLE: ReadonlyArray<StitchKey>;
|
|
20
|
+
/**
|
|
21
|
+
* 渲染某色块的针法纹理 canvas:在 mask 范围内画针法,裁剪到 mask 形状。
|
|
22
|
+
* @param mask 色块形状蒙版(不透明=该色块),决定输出尺寸与裁剪
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderStitchCanvas(mask: HTMLCanvasElement, color: RGB, type: StitchKey, params?: StitchParams): HTMLCanvasElement;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 异形抱枕 · 伪立体预览(P3a,仅预览,不改设计)。
|
|
3
|
+
*
|
|
4
|
+
* 输入:一张带透明通道的设计图(抠图后的"扣好的图",其不透明区域即抱枕的异形轮廓)。
|
|
5
|
+
* 输出:一张「蓬松毛绒抱枕」效果的离屏 canvas,可直接 toDataURL 显示在预览浮层。
|
|
6
|
+
*
|
|
7
|
+
* 纯 Canvas 实现(不依赖 Fabric),管线(由下到上):
|
|
8
|
+
* 1) 落地投影 —— 轮廓剪影模糊+下移+变暗,模拟悬浮
|
|
9
|
+
* 2) 主体设计图
|
|
10
|
+
* 3) 内阴影 —— 形状边缘内侧变暗,模拟收边/厚度
|
|
11
|
+
* 4) 中心高光 —— 形状中心提亮,模拟蓬起鼓凸
|
|
12
|
+
* 蓬起的"高度场"用「模糊轮廓再夹回形状内」近似:中心 alpha 高(亮)、边缘 alpha 低(暗)。
|
|
13
|
+
*/
|
|
14
|
+
export interface Pillow3dOptions {
|
|
15
|
+
/** 画布四周留白(给投影空间),默认按尺寸自适应 */
|
|
16
|
+
padding?: number;
|
|
17
|
+
/** 落地投影颜色 */
|
|
18
|
+
shadowColor?: string;
|
|
19
|
+
/** 落地投影模糊半径(px) */
|
|
20
|
+
shadowBlur?: number;
|
|
21
|
+
/** 落地投影下移(px) */
|
|
22
|
+
shadowOffsetY?: number;
|
|
23
|
+
/** 蓬起强度 0~1.5(影响高度场模糊半径与明暗强度),默认 1 */
|
|
24
|
+
puff?: number;
|
|
25
|
+
/** 边缘内阴影色(含 alpha) */
|
|
26
|
+
edgeDark?: string;
|
|
27
|
+
/** 中心高光色(含 alpha) */
|
|
28
|
+
centerLight?: string;
|
|
29
|
+
/** 边缘褶皱 / 布料纹理强度 0~1(噪声布纹,边缘带加强,模拟收边起褶),默认 0.6;0 = 关闭 */
|
|
30
|
+
wrinkle?: number;
|
|
31
|
+
/** 剪影圆角半径(px):把直角等尖角磨圆,更像抱枕。默认按尺寸自适应(≈minSide*0.04);0 = 不圆角 */
|
|
32
|
+
cornerRound?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 生成伪立体抱枕预览。返回离屏 canvas(含投影 padding)。
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildPillow3dPreview(source: HTMLImageElement | HTMLCanvasElement, opts?: Pillow3dOptions): HTMLCanvasElement;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 刺绣 · 颜色量化 + 连通域分割 Worker(节点①)
|
|
3
|
+
*
|
|
4
|
+
* 输入:一张图的 RGBA 像素 + 目标色数 k。
|
|
5
|
+
* 流程:rgb→Lab → K-Means(采样加速)聚类到 k 个「绣线色」→ 像素归类 → 连通域分割(并查集,4 邻接) → 区域汇总。
|
|
6
|
+
* 输出:量化后 RGBA 图 + 色板(k 色) + 区域列表(id/色号/面积/包围盒)。
|
|
7
|
+
*
|
|
8
|
+
* 说明:节点①只做"按相近颜色分块 + 可视化"。区域边界简化 → Fabric Path 留到节点②。
|
|
9
|
+
*/
|
|
10
|
+
type RGB = [number, number, number];
|
|
11
|
+
type Lab = [number, number, number];
|
|
12
|
+
interface QuantizeRequest {
|
|
13
|
+
id: number;
|
|
14
|
+
type: 'quantize';
|
|
15
|
+
pixels: ArrayBuffer;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
k: number;
|
|
19
|
+
/** 面积小于该像素数的区域过滤掉(碎块),默认按总面积自适应 */
|
|
20
|
+
minRegionArea?: number;
|
|
21
|
+
/** alpha 阈值,低于则视为透明不参与,默认 128 */
|
|
22
|
+
alphaThreshold?: number;
|
|
23
|
+
/** 相邻区域 Lab 色差(ΔE)小于此值则合并,默认 14;越大合并越激进、图层越少 */
|
|
24
|
+
mergeColorDist?: number;
|
|
25
|
+
}
|
|
26
|
+
interface RegionSummary {
|
|
27
|
+
id: number;
|
|
28
|
+
clusterIdx: number;
|
|
29
|
+
color: RGB;
|
|
30
|
+
area: number;
|
|
31
|
+
bbox: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
w: number;
|
|
35
|
+
h: number;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
declare function srgbToLinear(c: number): number;
|
|
39
|
+
declare function rgbToLab(r: number, g: number, b: number): Lab;
|
|
40
|
+
declare function labDist2(a: Lab, b: Lab): number;
|
|
41
|
+
declare function kMeansLab(labs: Lab[], // 参与聚类的样本(已采样)
|
|
42
|
+
rgbs: RGB[], // 与 labs 一一对应的原始 rgb(用于反推中心色)
|
|
43
|
+
k: number, iters?: number): {
|
|
44
|
+
centersLab: Lab[];
|
|
45
|
+
centersRgb: RGB[];
|
|
46
|
+
};
|
|
47
|
+
declare function handleQuantize(req: QuantizeRequest): void;
|