@printine/pod-editor 0.1.14 → 0.1.16
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/README.md +27 -45
- package/dist/api/asset-client.d.ts +1 -1
- package/dist/components/context.d.ts +2 -2
- package/dist/components/design.d.ts +2 -2
- package/dist/components/preview/index.d.ts +2 -2
- package/dist/components/semi-renderer.d.ts +3 -1
- package/dist/components/upload-types.d.ts +20 -0
- package/dist/{design-C_TmcalT.js → design-CpQzcaGG.js} +5589 -5595
- package/dist/full-designer.js +2 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +134 -146
- package/dist/lib/base-plate.d.ts +3 -0
- package/dist/{pixel-map-dSys7UAx.js → pixel-map-BLlgu5Ix.js} +3 -3
- package/dist/renderer/pixel-map.d.ts +3 -0
- package/dist/renderer/render-layer-output.d.ts +1 -0
- package/dist/{semi-interact-editor-DfzphWy3.js → semi-interact-editor-BVPJX2-9.js} +358 -350
- package/dist/semi-renderer.js +1 -1
- package/dist/style.css +1 -1
- package/dist/types.d.ts +3 -29
- package/docs/HOST_DATA_CONTRACT.md +77 -69
- package/docs/INTEGRATION_API.md +25 -27
- package/docs/SEMI_RENDERER.md +7 -2
- package/package.json +2 -11
- package/dist/api/client.d.ts +0 -8
- package/dist/api/client.js +0 -82
- package/dist/api/common-endpoints.d.ts +0 -12
- package/dist/api/design-endpoints.d.ts +0 -4
- package/dist/api/endpoints.d.ts +0 -23
- package/dist/api/endpoints.js +0 -33
- package/dist/api/files-endpoints.d.ts +0 -1
- package/dist/components/menus/ai.d.ts +0 -5
- package/dist/hooks/use-oss-upload.d.ts +0 -36
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { LAYER_BLACK_LIST as
|
|
4
|
-
import { P as
|
|
1
|
+
import { jsxs as Oe, jsx as z } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as qe, useRef as C, useState as te, useCallback as N, useEffect as ee, useImperativeHandle as He } from "react";
|
|
3
|
+
import { LAYER_BLACK_LIST as Re, BLEND_MODES_MAP as ze } from "./engine/constants.js";
|
|
4
|
+
import { P as ke, r as De } from "./pixel-map-BLlgu5Ix.js";
|
|
5
5
|
import "./engine/fabric.js";
|
|
6
|
-
import { v4 as
|
|
7
|
-
import { cloneObject as
|
|
8
|
-
import { ImageProcessor as
|
|
9
|
-
import { TemplateProcessor as
|
|
10
|
-
import { TextProcessor as
|
|
11
|
-
import { ResizeManager as
|
|
12
|
-
import { loadOverlaySvgImage as
|
|
13
|
-
import { WorkspaceManager as
|
|
14
|
-
import { HistoryManager as
|
|
15
|
-
import
|
|
16
|
-
import { fabric as
|
|
17
|
-
import { setDefaultControls as
|
|
18
|
-
class
|
|
6
|
+
import { v4 as Fe } from "uuid";
|
|
7
|
+
import { cloneObject as J, urlToDataURL as Ne } from "./engine/utils/common.js";
|
|
8
|
+
import { ImageProcessor as Ve } from "./engine/processors/image.js";
|
|
9
|
+
import { TemplateProcessor as Ge } from "./engine/processors/template.js";
|
|
10
|
+
import { TextProcessor as Je } from "./engine/processors/text.js";
|
|
11
|
+
import { ResizeManager as Ke } from "./engine/managers/resize.js";
|
|
12
|
+
import { loadOverlaySvgImage as Qe, loadImage as Ze } from "./engine/utils/image.js";
|
|
13
|
+
import { WorkspaceManager as $e } from "./engine/managers/workspace.js";
|
|
14
|
+
import { HistoryManager as je } from "./engine/history.js";
|
|
15
|
+
import et from "./engine/events.js";
|
|
16
|
+
import { fabric as L } from "fabric";
|
|
17
|
+
import { setDefaultControls as tt } from "./engine/utils/setting.js";
|
|
18
|
+
class xe {
|
|
19
19
|
constructor(e, s, r, t = 0.85) {
|
|
20
20
|
this.imageCache = /* @__PURE__ */ new Map(), this.overlayCache = /* @__PURE__ */ new Map(), this.destroyed = !1, this.deleteObject = (i) => {
|
|
21
21
|
if (i) {
|
|
@@ -28,7 +28,7 @@ class Me {
|
|
|
28
28
|
}), this.canvas.discardActiveObject());
|
|
29
29
|
}
|
|
30
30
|
this.canvas.requestRenderAll();
|
|
31
|
-
}, this.canvas = new
|
|
31
|
+
}, this.canvas = new L.Canvas(e, {
|
|
32
32
|
enableRetinaScaling: !0,
|
|
33
33
|
width: s.width,
|
|
34
34
|
height: s.height,
|
|
@@ -43,7 +43,7 @@ class Me {
|
|
|
43
43
|
controlsAboveOverlay: !0,
|
|
44
44
|
fireRightClick: !0
|
|
45
45
|
// 允许识别右键点击
|
|
46
|
-
}), this.overlayScale = t, this.imageProcessor = new
|
|
46
|
+
}), this.overlayScale = t, this.imageProcessor = new Ve(this), this.templateProcessor = new Ge(this), this.textProcessor = new Je(this), this.resizeManager = new Ke(this, r), this.workspaceManager = new $e(this);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* ImageProcessor/TextProcessor are shared with the interactive editor and
|
|
@@ -97,12 +97,12 @@ class Me {
|
|
|
97
97
|
async getOverlayImage(e) {
|
|
98
98
|
const s = this.overlayCache.get(e);
|
|
99
99
|
if (s) {
|
|
100
|
-
const a = await
|
|
100
|
+
const a = await J(s.image), n = s.clipPath ? await J(s.clipPath) : void 0;
|
|
101
101
|
return { image: a, clipPath: n };
|
|
102
102
|
}
|
|
103
|
-
const r = await
|
|
103
|
+
const r = await Qe(e);
|
|
104
104
|
this.overlayCache.set(e, r);
|
|
105
|
-
const t = await
|
|
105
|
+
const t = await J(r.image), i = r.clipPath ? await J(r.clipPath) : void 0;
|
|
106
106
|
return { image: t, clipPath: i };
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
@@ -129,26 +129,26 @@ class Me {
|
|
|
129
129
|
strokeUniform: !0,
|
|
130
130
|
objectCaching: !1
|
|
131
131
|
}), r.render(t);
|
|
132
|
-
const n = 6, c = (r.getScaledWidth() + n * 2) / r.getScaledWidth(), o = (r.getScaledHeight() + n * 2) / r.getScaledHeight(), m = r.left ?? 0,
|
|
132
|
+
const n = 6, c = (r.getScaledWidth() + n * 2) / r.getScaledWidth(), o = (r.getScaledHeight() + n * 2) / r.getScaledHeight(), m = r.left ?? 0, g = r.top ?? 0, b = r.scaleX ?? 1, h = r.scaleY ?? 1;
|
|
133
133
|
r.set({
|
|
134
134
|
strokeDashArray: [4, 4],
|
|
135
135
|
stroke: "#C3C3CC",
|
|
136
136
|
strokeWidth: 1,
|
|
137
137
|
strokeUniform: !0,
|
|
138
|
-
scaleX:
|
|
139
|
-
scaleY:
|
|
138
|
+
scaleX: b * c,
|
|
139
|
+
scaleY: h * o,
|
|
140
140
|
left: m - n,
|
|
141
|
-
top:
|
|
141
|
+
top: g - n
|
|
142
142
|
}), r.render(t), r.set({
|
|
143
143
|
stroke: a.stroke,
|
|
144
144
|
strokeWidth: a.strokeWidth,
|
|
145
145
|
strokeDashArray: a.strokeDashArray,
|
|
146
146
|
fill: a.fill,
|
|
147
147
|
strokeUniform: a.strokeUniform,
|
|
148
|
-
scaleX:
|
|
149
|
-
scaleY:
|
|
148
|
+
scaleX: b,
|
|
149
|
+
scaleY: h,
|
|
150
150
|
left: m,
|
|
151
|
-
top:
|
|
151
|
+
top: g
|
|
152
152
|
}), t.restore();
|
|
153
153
|
}, this.canvas.on("after:render", this.overlayBorderHandler);
|
|
154
154
|
}
|
|
@@ -185,7 +185,7 @@ class Me {
|
|
|
185
185
|
const s = document.querySelector(".lower-canvas");
|
|
186
186
|
if (s && !e)
|
|
187
187
|
return s.style.backgroundImage = "", Promise.resolve();
|
|
188
|
-
const r = await
|
|
188
|
+
const r = await Ze(e);
|
|
189
189
|
if (r == null) return Promise.resolve();
|
|
190
190
|
r.set({
|
|
191
191
|
scaleX: this.canvas.width / r.width,
|
|
@@ -226,7 +226,7 @@ class Me {
|
|
|
226
226
|
*/
|
|
227
227
|
addObject(e, s = !0) {
|
|
228
228
|
e.set({
|
|
229
|
-
id:
|
|
229
|
+
id: Fe()
|
|
230
230
|
}), this.canvas.add(e), s && this.canvas.setActiveObject(e);
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
@@ -234,7 +234,7 @@ class Me {
|
|
|
234
234
|
*/
|
|
235
235
|
async restoreObject(e) {
|
|
236
236
|
return new Promise((s) => {
|
|
237
|
-
|
|
237
|
+
L.util.enlivenObjects([e], (r) => s(r), "");
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
@@ -263,13 +263,13 @@ class Me {
|
|
|
263
263
|
...typeof t.spacing < "u" ? { spacing: t.spacing } : {}
|
|
264
264
|
});
|
|
265
265
|
if (!c) {
|
|
266
|
-
const
|
|
266
|
+
const v = o ? t.getCenterPoint() : null;
|
|
267
267
|
t.set(s), o && (t.__restoredGeometry = !1);
|
|
268
268
|
try {
|
|
269
269
|
t.initDimensions?.();
|
|
270
270
|
} catch {
|
|
271
271
|
}
|
|
272
|
-
return
|
|
272
|
+
return v && t.setPositionByOrigin(v, "center", "center"), t.setCoords(), {
|
|
273
273
|
...s,
|
|
274
274
|
text: t.text,
|
|
275
275
|
left: t.left,
|
|
@@ -285,45 +285,45 @@ class Me {
|
|
|
285
285
|
...m()
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
|
-
const
|
|
289
|
-
let
|
|
290
|
-
if (
|
|
291
|
-
const
|
|
292
|
-
|
|
288
|
+
const g = e?.__semiTargetInfo, b = !!g && typeof g.width == "number" && g.width > 0 && typeof g.height == "number" && g.height > 0 && typeof g.centerX == "number" && typeof g.centerY == "number";
|
|
289
|
+
let h;
|
|
290
|
+
if (b) {
|
|
291
|
+
const v = t.getCenterPoint();
|
|
292
|
+
h = {
|
|
293
293
|
width: n.originalWidth,
|
|
294
294
|
height: n.originalHeight,
|
|
295
|
-
centerX: typeof
|
|
296
|
-
centerY: typeof
|
|
297
|
-
signX: typeof
|
|
298
|
-
signY: typeof
|
|
295
|
+
centerX: typeof g.centerX == "number" ? g.centerX : v.x,
|
|
296
|
+
centerY: typeof g.centerY == "number" ? g.centerY : v.y,
|
|
297
|
+
signX: typeof g.signX == "number" && g.signX !== 0 ? Math.sign(g.signX) : Math.sign(i) || 1,
|
|
298
|
+
signY: typeof g.signY == "number" && g.signY !== 0 ? Math.sign(g.signY) : Math.sign(a) || 1
|
|
299
299
|
};
|
|
300
300
|
} else {
|
|
301
|
-
const
|
|
302
|
-
|
|
301
|
+
const v = t.getCenterPoint();
|
|
302
|
+
h = {
|
|
303
303
|
width: n.originalWidth,
|
|
304
304
|
height: n.originalHeight,
|
|
305
|
-
centerX:
|
|
306
|
-
centerY:
|
|
305
|
+
centerX: v.x,
|
|
306
|
+
centerY: v.y,
|
|
307
307
|
signX: Math.sign(i) || 1,
|
|
308
308
|
signY: Math.sign(a) || 1
|
|
309
309
|
};
|
|
310
310
|
}
|
|
311
311
|
t.set({
|
|
312
312
|
...s,
|
|
313
|
-
scaleX:
|
|
314
|
-
scaleY:
|
|
313
|
+
scaleX: h.signX,
|
|
314
|
+
scaleY: h.signY
|
|
315
315
|
}), o && (t.__restoredGeometry = !1);
|
|
316
316
|
try {
|
|
317
317
|
t.initDimensions?.();
|
|
318
318
|
} catch {
|
|
319
319
|
}
|
|
320
320
|
t.setCoords();
|
|
321
|
-
const
|
|
322
|
-
let
|
|
323
|
-
return (!Number.isFinite(
|
|
324
|
-
scaleX:
|
|
325
|
-
scaleY:
|
|
326
|
-
}), t.setPositionByOrigin(new
|
|
321
|
+
const X = t.getBoundingRect(!0, !0), x = Math.max(1, X.width || 1), A = Math.max(1, X.height || 1);
|
|
322
|
+
let O = Math.min(h.width / x, h.height / A);
|
|
323
|
+
return (!Number.isFinite(O) || O <= 0) && (O = 1), t.set({
|
|
324
|
+
scaleX: O * h.signX,
|
|
325
|
+
scaleY: O * h.signY
|
|
326
|
+
}), t.setPositionByOrigin(new L.Point(h.centerX, h.centerY), "center", "center"), t.setCoords(), {
|
|
327
327
|
...s,
|
|
328
328
|
text: t.text,
|
|
329
329
|
left: t.left,
|
|
@@ -336,7 +336,7 @@ class Me {
|
|
|
336
336
|
originX: t.originX,
|
|
337
337
|
originY: t.originY,
|
|
338
338
|
selectable: e.selectable,
|
|
339
|
-
__semiTargetInfo:
|
|
339
|
+
__semiTargetInfo: h,
|
|
340
340
|
...m()
|
|
341
341
|
};
|
|
342
342
|
}
|
|
@@ -349,18 +349,18 @@ class Me {
|
|
|
349
349
|
if (!r) return null;
|
|
350
350
|
const [t] = await this.restoreObject(e);
|
|
351
351
|
if (!t) return null;
|
|
352
|
-
const i = t, a = e.scaleX || 1, n = e.scaleY || 1, c = e.width || 1, o = e.height || 1, m = c * Math.abs(a),
|
|
353
|
-
return new Promise((
|
|
352
|
+
const i = t, a = e.scaleX || 1, n = e.scaleY || 1, c = e.width || 1, o = e.height || 1, m = c * Math.abs(a), g = o * Math.abs(n), b = t.getCenterPoint();
|
|
353
|
+
return new Promise((h) => {
|
|
354
354
|
i.setSrc(r, () => {
|
|
355
|
-
const
|
|
355
|
+
const X = i.width || 1, x = i.height || 1, A = Math.max(m / X, g / x);
|
|
356
356
|
i.set({
|
|
357
357
|
...s,
|
|
358
|
-
scaleX:
|
|
359
|
-
scaleY:
|
|
360
|
-
}), i.setPositionByOrigin(
|
|
358
|
+
scaleX: A * Math.sign(a),
|
|
359
|
+
scaleY: A * Math.sign(n)
|
|
360
|
+
}), i.setPositionByOrigin(b, "center", "center"), i.setCoords(), h({
|
|
361
361
|
...s,
|
|
362
|
-
width:
|
|
363
|
-
height:
|
|
362
|
+
width: X,
|
|
363
|
+
height: x,
|
|
364
364
|
left: i.left,
|
|
365
365
|
top: i.top,
|
|
366
366
|
scaleX: i.scaleX,
|
|
@@ -471,7 +471,7 @@ class Me {
|
|
|
471
471
|
* 获取当前可选择的对象,不包括背景图、裁剪区域
|
|
472
472
|
*/
|
|
473
473
|
getLayerList() {
|
|
474
|
-
return this.canvas._objects.filter((e) => !
|
|
474
|
+
return this.canvas._objects.filter((e) => !Re.includes(e.id || ""));
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
477
|
* 设置当前选中的对象
|
|
@@ -484,7 +484,7 @@ class Me {
|
|
|
484
484
|
* 同时选中多个对象
|
|
485
485
|
*/
|
|
486
486
|
setActiveObjects(e) {
|
|
487
|
-
const s = new
|
|
487
|
+
const s = new L.ActiveSelection(e, { canvas: this.canvas });
|
|
488
488
|
this.canvas.setActiveObject(s), this.canvas.requestRenderAll();
|
|
489
489
|
}
|
|
490
490
|
/**
|
|
@@ -503,9 +503,9 @@ class Me {
|
|
|
503
503
|
* 获取当前画布上渲染的对象
|
|
504
504
|
*/
|
|
505
505
|
getRenderedObjects() {
|
|
506
|
-
const { objects: e } = this.canvas.toJSON(
|
|
506
|
+
const { objects: e } = this.canvas.toJSON(je.DEFAULT_SAVE_PROPERTIES), s = this.workspaceManager.dimension;
|
|
507
507
|
return {
|
|
508
|
-
objects: e.filter((r) => !
|
|
508
|
+
objects: e.filter((r) => !Re.includes(r.id || "")),
|
|
509
509
|
workspaceMetadata: {
|
|
510
510
|
width: s.width,
|
|
511
511
|
height: s.height,
|
|
@@ -563,10 +563,10 @@ class Me {
|
|
|
563
563
|
n();
|
|
564
564
|
}) : n();
|
|
565
565
|
}))
|
|
566
|
-
), this.canvas.renderAll(),
|
|
566
|
+
), this.canvas.renderAll(), et.emit("design:layerChange"), t();
|
|
567
567
|
},
|
|
568
568
|
(i, a) => {
|
|
569
|
-
i.clipPath && !r.objects.some((n) => n.id === i.clipPath.id) && (delete a.clipPath,
|
|
569
|
+
i.clipPath && !r.objects.some((n) => n.id === i.clipPath.id) && (delete a.clipPath, L.util.enlivenObjects(
|
|
570
570
|
[i.clipPath],
|
|
571
571
|
(n) => {
|
|
572
572
|
const c = n[0];
|
|
@@ -590,30 +590,30 @@ class Me {
|
|
|
590
590
|
const s = this.workspaceManager.dimension, r = Math.min(
|
|
591
591
|
s.width / e.width,
|
|
592
592
|
s.height / e.height
|
|
593
|
-
), t = e.centerX, i = e.centerY, a = s.center.x, n = s.center.y, c = Math.abs(a - t), o = Math.abs(n - i), m = Math.abs(r - 1) >= 1e-3,
|
|
594
|
-
if (!m && !
|
|
595
|
-
const
|
|
596
|
-
const
|
|
597
|
-
|
|
593
|
+
), t = e.centerX, i = e.centerY, a = s.center.x, n = s.center.y, c = Math.abs(a - t), o = Math.abs(n - i), m = Math.abs(r - 1) >= 1e-3, g = c >= 0.1 || o >= 0.1;
|
|
594
|
+
if (!m && !g) return;
|
|
595
|
+
const b = this.canvas.getObjects(), h = new Set(b), X = /* @__PURE__ */ new Set(), x = (f) => {
|
|
596
|
+
const u = f.clipPath;
|
|
597
|
+
u && h.has(u) && X.add(u);
|
|
598
598
|
};
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
left:
|
|
599
|
+
b.forEach(x);
|
|
600
|
+
const A = (f) => {
|
|
601
|
+
const u = (f.left || 0) - t, T = (f.top || 0) - i, W = a + u * r, l = n + T * r;
|
|
602
|
+
f.set({
|
|
603
|
+
left: W,
|
|
604
604
|
top: l,
|
|
605
|
-
scaleX: (
|
|
606
|
-
scaleY: (
|
|
607
|
-
}),
|
|
608
|
-
},
|
|
609
|
-
!
|
|
605
|
+
scaleX: (f.scaleX || 1) * r,
|
|
606
|
+
scaleY: (f.scaleY || 1) * r
|
|
607
|
+
}), f.setCoords(), f.dirty = !0;
|
|
608
|
+
}, O = /* @__PURE__ */ new Set(), v = (f) => {
|
|
609
|
+
!f.selectable && !X.has(f) || (A(f), O.add(f));
|
|
610
610
|
};
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
const
|
|
614
|
-
|
|
611
|
+
b.forEach(v);
|
|
612
|
+
const E = (f) => {
|
|
613
|
+
const u = f.clipPath;
|
|
614
|
+
u && u.absolutePositioned && !h.has(u) && !O.has(u) && (A(u), O.add(u));
|
|
615
615
|
};
|
|
616
|
-
|
|
616
|
+
b.forEach(E);
|
|
617
617
|
}
|
|
618
618
|
/**
|
|
619
619
|
* 计算对象相对于画布的全局变换矩阵(包括父组的影响)
|
|
@@ -686,7 +686,7 @@ class Me {
|
|
|
686
686
|
}
|
|
687
687
|
return "";
|
|
688
688
|
}
|
|
689
|
-
return await
|
|
689
|
+
return await Ne(e);
|
|
690
690
|
}
|
|
691
691
|
/**
|
|
692
692
|
* 从缓存克隆图片,避免重复下载
|
|
@@ -704,14 +704,14 @@ class Me {
|
|
|
704
704
|
});
|
|
705
705
|
const n = this.imageCache.get(a);
|
|
706
706
|
return n?.element && n.element.complete ? new Promise(async (c) => {
|
|
707
|
-
const o = new
|
|
707
|
+
const o = new L.Image(n.element, {
|
|
708
708
|
width: e.width,
|
|
709
709
|
height: e.height,
|
|
710
710
|
...s
|
|
711
711
|
});
|
|
712
712
|
if (e.clipPath)
|
|
713
713
|
try {
|
|
714
|
-
const m = await
|
|
714
|
+
const m = await J(e.clipPath, ["absolutePositioned"]);
|
|
715
715
|
o.set({ clipPath: m });
|
|
716
716
|
} catch {
|
|
717
717
|
}
|
|
@@ -738,32 +738,32 @@ class Me {
|
|
|
738
738
|
const r = this.workspaceManager.dimension, t = this.workspaceManager.printAreaSize?.width ?? r.width, i = this.workspaceManager.printAreaSize?.height ?? r.height;
|
|
739
739
|
if (!r.width || !r.height || !t || !i)
|
|
740
740
|
throw new Error("Printable workspace has no dimensions");
|
|
741
|
-
const a = Math.max(t, i), n = Math.max(1, e) / a, c = Math.max(1, Math.round(t * n)), o = Math.max(1, Math.round(i * n)), m = this.canvas.viewportTransform?.slice(),
|
|
741
|
+
const a = Math.max(t, i), n = Math.max(1, e) / a, c = Math.max(1, Math.round(t * n)), o = Math.max(1, Math.round(i * n)), m = this.canvas.viewportTransform?.slice(), g = this.canvas.overlayImage?.visible, b = this.canvas.backgroundColor, h = this.canvas.getActiveObject(), X = h ? { hasBorders: h.hasBorders, hasControls: h.hasControls } : null;
|
|
742
742
|
try {
|
|
743
|
-
this.canvas.overlayImage && (this.canvas.overlayImage.visible = !1),
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
if (!
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
r.left *
|
|
752
|
-
r.top *
|
|
753
|
-
r.width *
|
|
754
|
-
r.height *
|
|
743
|
+
this.canvas.overlayImage && (this.canvas.overlayImage.visible = !1), h?.set({ hasBorders: !1, hasControls: !1 }), this.canvas.backgroundColor = s || "transparent", this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0], this.canvas.renderAll();
|
|
744
|
+
const x = document.createElement("canvas");
|
|
745
|
+
x.width = c, x.height = o;
|
|
746
|
+
const A = x.getContext("2d", { alpha: !0 });
|
|
747
|
+
if (!A) throw new Error("Could not create preview canvas context");
|
|
748
|
+
const O = this.canvas, v = O.getRetinaScaling?.() ?? window.devicePixelRatio ?? 1;
|
|
749
|
+
A.drawImage(
|
|
750
|
+
O.lowerCanvasEl,
|
|
751
|
+
r.left * v,
|
|
752
|
+
r.top * v,
|
|
753
|
+
r.width * v,
|
|
754
|
+
r.height * v,
|
|
755
755
|
0,
|
|
756
756
|
0,
|
|
757
757
|
c,
|
|
758
758
|
o
|
|
759
759
|
);
|
|
760
760
|
try {
|
|
761
|
-
return await createImageBitmap(
|
|
761
|
+
return await createImageBitmap(x);
|
|
762
762
|
} finally {
|
|
763
|
-
|
|
763
|
+
x.width = 0, x.height = 0;
|
|
764
764
|
}
|
|
765
765
|
} finally {
|
|
766
|
-
this.canvas.backgroundColor =
|
|
766
|
+
this.canvas.backgroundColor = b, this.canvas.overlayImage && g !== void 0 && (this.canvas.overlayImage.visible = g), h && X && h.set(X), m && (this.canvas.viewportTransform = m), this.destroyed || this.canvas.requestRenderAll();
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
769
|
/**
|
|
@@ -773,8 +773,8 @@ class Me {
|
|
|
773
773
|
* @returns {Promise<string[]>} SVG 字符串
|
|
774
774
|
*/
|
|
775
775
|
async export(e = !1, s, r) {
|
|
776
|
-
const t = this.workspaceManager.dimension, i = this.workspaceManager.printAreaSize?.width ?? t.width, a = this.workspaceManager.printAreaSize?.height ?? t.height, n = window.devicePixelRatio || 1, c = Math.max(i / t.width, a / t.height), o = r?.objectCloneMultiplierCap ?? 8, m = Math.max(1, Math.min(r?.minObjectCloneMultiplier ?? 2, o)),
|
|
777
|
-
let
|
|
776
|
+
const t = this.workspaceManager.dimension, i = this.workspaceManager.printAreaSize?.width ?? t.width, a = this.workspaceManager.printAreaSize?.height ?? t.height, n = window.devicePixelRatio || 1, c = Math.max(i / t.width, a / t.height), o = r?.objectCloneMultiplierCap ?? 8, m = Math.max(1, Math.min(r?.minObjectCloneMultiplier ?? 2, o)), g = Math.max(m, Math.min(o, Math.ceil(c * n)));
|
|
777
|
+
let b = new L.Rect({
|
|
778
778
|
left: 0,
|
|
779
779
|
top: 0,
|
|
780
780
|
width: t.width,
|
|
@@ -782,47 +782,47 @@ class Me {
|
|
|
782
782
|
absolutePositioned: !0,
|
|
783
783
|
strokeWidth: 0
|
|
784
784
|
});
|
|
785
|
-
this.canvas.clipPath && (
|
|
785
|
+
this.canvas.clipPath && (b = await J(this.canvas.clipPath, ["absolutePositioned"]), b.set({
|
|
786
786
|
left: this.canvas.clipPath.left - t.left,
|
|
787
787
|
top: this.canvas.clipPath.top - t.top,
|
|
788
788
|
absolutePositioned: !0
|
|
789
789
|
}));
|
|
790
|
-
const
|
|
790
|
+
const h = new L.StaticCanvas(null, {
|
|
791
791
|
width: t.width,
|
|
792
792
|
height: t.height,
|
|
793
793
|
enableRetinaScaling: !1,
|
|
794
794
|
backgroundColor: s || "transparent",
|
|
795
795
|
preserveObjectStacking: !0,
|
|
796
|
-
clipPath:
|
|
797
|
-
}),
|
|
796
|
+
clipPath: b
|
|
797
|
+
}), X = this.getLayerList();
|
|
798
798
|
(await Promise.all(
|
|
799
|
-
|
|
800
|
-
(l) => new Promise((
|
|
799
|
+
X.map(
|
|
800
|
+
(l) => new Promise((k) => {
|
|
801
801
|
try {
|
|
802
|
-
const
|
|
802
|
+
const M = l.sourceType === "svg";
|
|
803
803
|
if (l.type === "image") {
|
|
804
|
-
const
|
|
805
|
-
let
|
|
804
|
+
const P = l;
|
|
805
|
+
let p = {
|
|
806
806
|
selectable: !1,
|
|
807
807
|
evented: !1,
|
|
808
808
|
flipX: l.flipX || !1,
|
|
809
809
|
flipY: l.flipY || !1
|
|
810
810
|
};
|
|
811
811
|
if (this.isInActiveSelection(l)) {
|
|
812
|
-
const S = this.getGlobalTransformMatrix(l),
|
|
813
|
-
|
|
814
|
-
...
|
|
815
|
-
left: (
|
|
816
|
-
top: (
|
|
817
|
-
angle:
|
|
818
|
-
scaleX:
|
|
819
|
-
scaleY:
|
|
812
|
+
const S = this.getGlobalTransformMatrix(l), y = L.util.qrDecompose(S);
|
|
813
|
+
p = {
|
|
814
|
+
...p,
|
|
815
|
+
left: (y.translateX || 0) - (t.left || 0),
|
|
816
|
+
top: (y.translateY || 0) - (t.top || 0),
|
|
817
|
+
angle: y.angle || 0,
|
|
818
|
+
scaleX: y.scaleX || 1,
|
|
819
|
+
scaleY: y.scaleY || 1,
|
|
820
820
|
originX: "center",
|
|
821
821
|
originY: "center"
|
|
822
822
|
};
|
|
823
823
|
} else
|
|
824
|
-
|
|
825
|
-
...
|
|
824
|
+
p = {
|
|
825
|
+
...p,
|
|
826
826
|
left: l.left - t.left,
|
|
827
827
|
top: l.top - t.top,
|
|
828
828
|
angle: l.angle || 0,
|
|
@@ -831,37 +831,37 @@ class Me {
|
|
|
831
831
|
originX: "left",
|
|
832
832
|
originY: "top"
|
|
833
833
|
};
|
|
834
|
-
this.cloneImageFromCache(
|
|
834
|
+
this.cloneImageFromCache(P, p).then(async (S) => {
|
|
835
835
|
if (S.clipPath) {
|
|
836
|
-
const
|
|
837
|
-
|
|
838
|
-
left: (
|
|
839
|
-
top: (
|
|
836
|
+
const y = S.clipPath;
|
|
837
|
+
y.absolutePositioned && y.set({
|
|
838
|
+
left: (y.left || 0) - t.left,
|
|
839
|
+
top: (y.top || 0) - t.top
|
|
840
840
|
});
|
|
841
841
|
}
|
|
842
842
|
if (e && S.type === "image")
|
|
843
843
|
try {
|
|
844
|
-
const
|
|
845
|
-
if (
|
|
846
|
-
const
|
|
847
|
-
|
|
844
|
+
const y = S, I = y.getSrc() || y.originSrc || "";
|
|
845
|
+
if (I) {
|
|
846
|
+
const q = await this.getCachedDataURL(I);
|
|
847
|
+
y.setSrc(q, () => k(S));
|
|
848
848
|
return;
|
|
849
849
|
}
|
|
850
850
|
} catch {
|
|
851
851
|
}
|
|
852
|
-
|
|
852
|
+
k(S);
|
|
853
853
|
}).catch(() => {
|
|
854
|
-
|
|
854
|
+
k(l);
|
|
855
855
|
});
|
|
856
|
-
} else
|
|
856
|
+
} else M ? J(l, ["absolutePositioned"]).then((P) => {
|
|
857
857
|
if (this.isInActiveSelection(l)) {
|
|
858
|
-
const S = this.getGlobalTransformMatrix(l),
|
|
859
|
-
|
|
860
|
-
left: (
|
|
861
|
-
top: (
|
|
862
|
-
angle:
|
|
863
|
-
scaleX:
|
|
864
|
-
scaleY:
|
|
858
|
+
const S = this.getGlobalTransformMatrix(l), y = L.util.qrDecompose(S);
|
|
859
|
+
P.set({
|
|
860
|
+
left: (y.translateX || 0) - (t.left || 0),
|
|
861
|
+
top: (y.translateY || 0) - (t.top || 0),
|
|
862
|
+
angle: y.angle || 0,
|
|
863
|
+
scaleX: y.scaleX || 1,
|
|
864
|
+
scaleY: y.scaleY || 1,
|
|
865
865
|
flipX: l.flipX || !1,
|
|
866
866
|
flipY: l.flipY || !1,
|
|
867
867
|
selectable: !1,
|
|
@@ -870,7 +870,7 @@ class Me {
|
|
|
870
870
|
originY: "center"
|
|
871
871
|
});
|
|
872
872
|
} else
|
|
873
|
-
|
|
873
|
+
P.set({
|
|
874
874
|
left: (l.left || 0) - t.left,
|
|
875
875
|
top: (l.top || 0) - t.top,
|
|
876
876
|
angle: l.angle || 0,
|
|
@@ -883,21 +883,21 @@ class Me {
|
|
|
883
883
|
originX: l.originX || "left",
|
|
884
884
|
originY: l.originY || "top"
|
|
885
885
|
});
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
left: (
|
|
889
|
-
top: (
|
|
890
|
-
}),
|
|
891
|
-
}).catch(() =>
|
|
892
|
-
(
|
|
886
|
+
const p = P.clipPath;
|
|
887
|
+
p && p.absolutePositioned && p.set({
|
|
888
|
+
left: (p.left || 0) - t.left,
|
|
889
|
+
top: (p.top || 0) - t.top
|
|
890
|
+
}), P.setCoords(), P.dirty = !0, k(P);
|
|
891
|
+
}).catch(() => k(l)) : l.cloneAsImage(
|
|
892
|
+
(P) => {
|
|
893
893
|
if (this.isInActiveSelection(l)) {
|
|
894
|
-
const
|
|
895
|
-
|
|
894
|
+
const p = this.getGlobalTransformMatrix(l), S = L.util.qrDecompose(p);
|
|
895
|
+
P.set({
|
|
896
896
|
left: (S.translateX || 0) - (t.left || 0),
|
|
897
897
|
top: (S.translateY || 0) - (t.top || 0),
|
|
898
898
|
angle: S.angle || 0,
|
|
899
|
-
scaleX: (S.scaleX || 1) /
|
|
900
|
-
scaleY: (S.scaleY || 1) /
|
|
899
|
+
scaleX: (S.scaleX || 1) / g,
|
|
900
|
+
scaleY: (S.scaleY || 1) / g,
|
|
901
901
|
selectable: !1,
|
|
902
902
|
hasControls: !1,
|
|
903
903
|
hasBorders: !1,
|
|
@@ -905,12 +905,12 @@ class Me {
|
|
|
905
905
|
originY: "center"
|
|
906
906
|
});
|
|
907
907
|
} else {
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
left:
|
|
911
|
-
top:
|
|
912
|
-
scaleX: 1 /
|
|
913
|
-
scaleY: 1 /
|
|
908
|
+
const p = l.getBoundingRect(!0, !0);
|
|
909
|
+
P.set({
|
|
910
|
+
left: p.left - t.left,
|
|
911
|
+
top: p.top - t.top,
|
|
912
|
+
scaleX: 1 / g,
|
|
913
|
+
scaleY: 1 / g,
|
|
914
914
|
angle: 0,
|
|
915
915
|
selectable: !1,
|
|
916
916
|
hasControls: !1,
|
|
@@ -919,45 +919,45 @@ class Me {
|
|
|
919
919
|
originY: "top"
|
|
920
920
|
});
|
|
921
921
|
}
|
|
922
|
-
|
|
922
|
+
k(P);
|
|
923
923
|
},
|
|
924
|
-
{ multiplier:
|
|
924
|
+
{ multiplier: g }
|
|
925
925
|
);
|
|
926
926
|
} catch {
|
|
927
|
-
|
|
927
|
+
k(l);
|
|
928
928
|
}
|
|
929
929
|
})
|
|
930
930
|
)
|
|
931
|
-
)).forEach((l) =>
|
|
932
|
-
const
|
|
933
|
-
|
|
934
|
-
const
|
|
935
|
-
let
|
|
936
|
-
(i >
|
|
937
|
-
let
|
|
938
|
-
const
|
|
931
|
+
)).forEach((l) => h.add(l));
|
|
932
|
+
const A = i / t.width, O = a / t.height;
|
|
933
|
+
h.setViewportTransform([A, 0, 0, O, 0, 0]), h.renderAll();
|
|
934
|
+
const v = r?.minOutputSize ?? 1024;
|
|
935
|
+
let E = 1;
|
|
936
|
+
(i > v || a > v) && (E = Math.max(1, v / Math.max(i, a))), typeof r?.outputMultiplierCap == "number" && (E = Math.min(E, r.outputMultiplierCap));
|
|
937
|
+
let f = "";
|
|
938
|
+
const u = () => h.toDataURL({
|
|
939
939
|
format: "webp",
|
|
940
940
|
quality: r?.quality ?? 0.5,
|
|
941
941
|
width: i,
|
|
942
942
|
height: a,
|
|
943
|
-
multiplier:
|
|
944
|
-
}), T = r?.preferImageBitmap ?? !0,
|
|
945
|
-
if (T && window.createImageBitmap && typeof
|
|
946
|
-
const l =
|
|
943
|
+
multiplier: E
|
|
944
|
+
}), T = r?.preferImageBitmap ?? !0, W = r?.returnBlobUrl ?? !1;
|
|
945
|
+
if (T && window.createImageBitmap && typeof h.toCanvasElement == "function") {
|
|
946
|
+
const l = h.toCanvasElement(E, { width: i, height: a });
|
|
947
947
|
try {
|
|
948
|
-
|
|
948
|
+
f = await createImageBitmap(l);
|
|
949
949
|
} finally {
|
|
950
950
|
l.width = 0, l.height = 0;
|
|
951
951
|
}
|
|
952
|
-
} else if (
|
|
953
|
-
const l =
|
|
954
|
-
l.width = 0, l.height = 0,
|
|
952
|
+
} else if (W && typeof h.toCanvasElement == "function") {
|
|
953
|
+
const l = h.toCanvasElement(E, { width: i, height: a }), k = await new Promise((M) => l.toBlob(M, "image/webp", r?.quality ?? 0.5));
|
|
954
|
+
l.width = 0, l.height = 0, f = k ? URL.createObjectURL(k) : u();
|
|
955
955
|
} else
|
|
956
|
-
|
|
957
|
-
return
|
|
956
|
+
f = u();
|
|
957
|
+
return h.dispose(), f;
|
|
958
958
|
}
|
|
959
959
|
}
|
|
960
|
-
class
|
|
960
|
+
class rt {
|
|
961
961
|
constructor(e, s) {
|
|
962
962
|
this.onBusy = e, this.onIdle = s, this.pending = null, this.running = !1;
|
|
963
963
|
}
|
|
@@ -982,7 +982,7 @@ class je {
|
|
|
982
982
|
}
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
|
-
class
|
|
985
|
+
class st {
|
|
986
986
|
constructor(e = 32 * 1024 * 1024, s = 4, r) {
|
|
987
987
|
this.budget = e, this.concurrency = s, this.onEvict = r, this.entries = /* @__PURE__ */ new Map(), this.bytes = 0, this.active = 0, this.waiting = [], this.pinned = /* @__PURE__ */ new Set();
|
|
988
988
|
}
|
|
@@ -1037,9 +1037,9 @@ class et {
|
|
|
1037
1037
|
}), t.ready;
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
|
-
class
|
|
1040
|
+
class Me {
|
|
1041
1041
|
constructor() {
|
|
1042
|
-
this.urls = /* @__PURE__ */ new Map(), this.disposed = !1, this.current = /* @__PURE__ */ new Set(), this.holds = /* @__PURE__ */ new Map(), this.cache = new
|
|
1042
|
+
this.urls = /* @__PURE__ */ new Map(), this.disposed = !1, this.current = /* @__PURE__ */ new Set(), this.holds = /* @__PURE__ */ new Map(), this.cache = new st(32 * 1024 * 1024, 4, (e) => {
|
|
1043
1043
|
const s = this.urls.get(e);
|
|
1044
1044
|
s && URL.revokeObjectURL(s), this.urls.delete(e);
|
|
1045
1045
|
});
|
|
@@ -1099,7 +1099,7 @@ function ge(d) {
|
|
|
1099
1099
|
};
|
|
1100
1100
|
return s(d), [...e];
|
|
1101
1101
|
}
|
|
1102
|
-
async function
|
|
1102
|
+
async function Ye(d, e) {
|
|
1103
1103
|
const s = JSON.parse(JSON.stringify(d)), r = new Map(await Promise.all(ge(s).map(async (i) => [i, await e.url(i)]))), t = (i) => {
|
|
1104
1104
|
if (!i || typeof i != "object") return;
|
|
1105
1105
|
if (Array.isArray(i)) {
|
|
@@ -1111,7 +1111,7 @@ async function xe(d, e) {
|
|
|
1111
1111
|
};
|
|
1112
1112
|
return t(s), s;
|
|
1113
1113
|
}
|
|
1114
|
-
function
|
|
1114
|
+
function it(d, e, s) {
|
|
1115
1115
|
const r = JSON.parse(JSON.stringify(d)), t = new Map(Object.entries(e.urls).map(([n, c]) => [c, n])), i = /* @__PURE__ */ new Map(), a = (n, c) => {
|
|
1116
1116
|
if (!n || typeof n != "object") return;
|
|
1117
1117
|
if (Array.isArray(n)) {
|
|
@@ -1132,38 +1132,42 @@ function tt(d, e, s) {
|
|
|
1132
1132
|
function Z(d) {
|
|
1133
1133
|
return d.designKey || d.area?.name || d.name;
|
|
1134
1134
|
}
|
|
1135
|
-
function
|
|
1135
|
+
function de(d, e, s) {
|
|
1136
|
+
const r = e[Z(d)]?.color;
|
|
1137
|
+
return s ?? (typeof r == "string" ? r : void 0);
|
|
1138
|
+
}
|
|
1139
|
+
function Xe(d, e, s) {
|
|
1136
1140
|
return s ?? d.render_areas.filter((r) => r.design).map((r) => e[Z(r)]?.color).find((r) => typeof r == "string");
|
|
1137
1141
|
}
|
|
1138
|
-
function fe(d, e, s, r = !0) {
|
|
1142
|
+
function fe(d, e, s, r = !0, t = "global") {
|
|
1139
1143
|
if (!r) return d.render_areas;
|
|
1140
|
-
const
|
|
1141
|
-
return d.render_areas.filter((
|
|
1142
|
-
const
|
|
1143
|
-
return
|
|
1144
|
+
const i = t === "global" ? Xe(d, e, s) : void 0;
|
|
1145
|
+
return d.render_areas.filter((a) => {
|
|
1146
|
+
const n = e[Z(a)], c = t === "placement" ? de(a, e, s) : i;
|
|
1147
|
+
return De({ design: a.design }, c, !!(a.area && Array.isArray(n?.objects) && n.objects.length));
|
|
1144
1148
|
});
|
|
1145
1149
|
}
|
|
1146
|
-
function
|
|
1147
|
-
return fe(d, e, s, r).flatMap((
|
|
1148
|
-
const
|
|
1149
|
-
return [
|
|
1150
|
+
function _e(d, e, s, r = !0, t = "global") {
|
|
1151
|
+
return fe(d, e, s, r, t).flatMap((i) => {
|
|
1152
|
+
const a = e[Z(i)];
|
|
1153
|
+
return [i.image, ...i.design && i.area && Array.isArray(a?.objects) && a.objects.length ? [i.area.image, ...ge(a)] : []];
|
|
1150
1154
|
}).filter(Boolean);
|
|
1151
1155
|
}
|
|
1152
|
-
function
|
|
1156
|
+
function nt(d) {
|
|
1153
1157
|
return d.render_areas.find((e) => e.name === "bg")?.image || d.image || "";
|
|
1154
1158
|
}
|
|
1155
|
-
function
|
|
1159
|
+
function at(d, e) {
|
|
1156
1160
|
const s = d.render_areas.find((t) => t.name === "bg") ?? d.render_areas.find((t) => !t.design), r = Math.max(s?.width ?? 0, s?.height ?? 0);
|
|
1157
1161
|
return Math.max(1, Math.min(768, Math.round(r ? r * e : 600)));
|
|
1158
1162
|
}
|
|
1159
|
-
function
|
|
1163
|
+
function ue(d) {
|
|
1160
1164
|
if (typeof d != "string") {
|
|
1161
1165
|
d.close();
|
|
1162
1166
|
return;
|
|
1163
1167
|
}
|
|
1164
1168
|
d.startsWith("blob:") && URL.revokeObjectURL(d);
|
|
1165
1169
|
}
|
|
1166
|
-
const
|
|
1170
|
+
const Rt = qe(
|
|
1167
1171
|
function({
|
|
1168
1172
|
render: e,
|
|
1169
1173
|
designData: s,
|
|
@@ -1172,176 +1176,180 @@ const Ct = Te(
|
|
|
1172
1176
|
preloadDesignData: i,
|
|
1173
1177
|
onAssetReady: a,
|
|
1174
1178
|
backgroundColor: n,
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1179
|
+
colorMode: c = "global",
|
|
1180
|
+
scale: o = 0.8,
|
|
1181
|
+
renderer: m = "pixel-map",
|
|
1182
|
+
className: g,
|
|
1183
|
+
style: b,
|
|
1184
|
+
alt: h = "Product preview",
|
|
1185
|
+
onLoadingChange: X,
|
|
1186
|
+
onRendered: x,
|
|
1187
|
+
onError: A
|
|
1188
|
+
}, O) {
|
|
1189
|
+
const v = C(null), E = C(null), f = C(null), u = C(null), T = C(null), W = C(void 0), l = C(null), k = C(null), M = C(0), P = C(/* @__PURE__ */ new Map()), p = C(null), S = C(0), y = C(!1), I = C(!1), q = C({ onLoadingChange: X, onRendered: x, onError: A, onAssetReady: a });
|
|
1190
|
+
q.current = { onLoadingChange: X, onRendered: x, onError: A, onAssetReady: a };
|
|
1191
|
+
const Y = m === "pixel-map" && ke.isSupported(), re = C(Y);
|
|
1192
|
+
re.current = Y;
|
|
1193
|
+
const [se, R] = te(""), [le, Ae] = te(!1), [Ie, Ee] = te(""), K = N(() => (T.current ??= new Me(), T.current), []), $ = N((w) => {
|
|
1194
|
+
Ae(w), q.current.onLoadingChange?.(w);
|
|
1190
1195
|
}, []), ie = N(() => {
|
|
1191
|
-
if (
|
|
1192
|
-
if (!
|
|
1196
|
+
if (f.current) return f.current;
|
|
1197
|
+
if (!v.current || !E.current) return null;
|
|
1193
1198
|
const w = 800;
|
|
1194
|
-
return
|
|
1195
|
-
|
|
1199
|
+
return v.current.width = w, v.current.height = w, f.current = new xe(
|
|
1200
|
+
v.current,
|
|
1196
1201
|
{ width: w, height: w },
|
|
1197
|
-
|
|
1202
|
+
E.current,
|
|
1198
1203
|
0.85
|
|
1199
|
-
),
|
|
1204
|
+
), f.current;
|
|
1200
1205
|
}, []), pe = N(async () => {
|
|
1201
|
-
if (
|
|
1202
|
-
if (
|
|
1206
|
+
if (u.current) return u.current;
|
|
1207
|
+
if (Y) u.current = new ke();
|
|
1203
1208
|
else {
|
|
1204
1209
|
const { StickerPlugin: w } = await import("./renderer/sticker.js");
|
|
1205
|
-
if (
|
|
1206
|
-
if (
|
|
1207
|
-
|
|
1210
|
+
if (I.current || re.current !== Y) return null;
|
|
1211
|
+
if (u.current) return u.current;
|
|
1212
|
+
u.current = new w({ width: 1, height: 1 }, !0, { subdiv: 8 });
|
|
1208
1213
|
}
|
|
1209
|
-
return
|
|
1210
|
-
}, [
|
|
1211
|
-
|
|
1212
|
-
}, []), me = N(() => (
|
|
1214
|
+
return u.current;
|
|
1215
|
+
}, [Y]), ne = N(() => {
|
|
1216
|
+
f.current?.destroy(), f.current = null, u.current?.destroy(), u.current = null, T.current?.dispose(), T.current = null, W.current = void 0, P.current.forEach(({ texture: w }) => ue(w)), P.current.clear(), k.current && URL.revokeObjectURL(k.current), k.current = null, l.current = null;
|
|
1217
|
+
}, []), me = N(() => (p.current || (p.current = new rt(
|
|
1213
1218
|
() => $(!0),
|
|
1214
1219
|
() => {
|
|
1215
|
-
|
|
1220
|
+
I.current ? ne() : $(!1);
|
|
1216
1221
|
}
|
|
1217
|
-
)),
|
|
1218
|
-
const w = ++
|
|
1222
|
+
)), p.current), [ne, $]), ae = N(() => {
|
|
1223
|
+
const w = ++M.current, Q = S.current;
|
|
1219
1224
|
me().enqueue(async () => {
|
|
1220
1225
|
let D;
|
|
1221
1226
|
try {
|
|
1222
|
-
if (
|
|
1223
|
-
const
|
|
1224
|
-
|
|
1227
|
+
if (I.current || w !== M.current) return;
|
|
1228
|
+
const U = ie();
|
|
1229
|
+
y.current && (u.current?.destroy(), u.current = null, y.current = !1);
|
|
1225
1230
|
const V = await pe();
|
|
1226
|
-
if (!
|
|
1227
|
-
const
|
|
1228
|
-
D =
|
|
1229
|
-
const ve = fe(e, s, n,
|
|
1230
|
-
|
|
1231
|
+
if (!U || !V || I.current || w !== M.current) return;
|
|
1232
|
+
const H = K();
|
|
1233
|
+
D = H.hold(_e(e, s, n, Y, c));
|
|
1234
|
+
const ve = fe(e, s, n, Y, c), ye = c === "global" ? Xe(e, s, n) : n, Be = e.render_areas.filter((_) => !!_.design), ce = at(e, o), be = Promise.all(ve.map(async (_) => [_.image, await H.url(_.image)]));
|
|
1235
|
+
be.catch(() => {
|
|
1231
1236
|
});
|
|
1232
|
-
for (const
|
|
1233
|
-
const
|
|
1234
|
-
if (!Array.isArray(
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
+
for (const _ of Be) {
|
|
1238
|
+
const F = Z(_), B = s[F], G = c === "placement" ? de(_, s, n) ?? "" : typeof B?.color == "string" ? B.color : "", Te = c === "placement" && !Y && n === void 0 && !!G;
|
|
1239
|
+
if (!_.area || (!Array.isArray(B?.objects) || !B.objects.length) && !Te) {
|
|
1240
|
+
const j = P.current.get(F);
|
|
1241
|
+
j && (ue(j.texture), P.current.delete(F));
|
|
1237
1242
|
continue;
|
|
1238
1243
|
}
|
|
1239
|
-
const
|
|
1244
|
+
const Pe = JSON.stringify([
|
|
1240
1245
|
Q,
|
|
1241
1246
|
ce,
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1247
|
+
_.area.id,
|
|
1248
|
+
_.area.image,
|
|
1249
|
+
B,
|
|
1250
|
+
c,
|
|
1251
|
+
G
|
|
1245
1252
|
]);
|
|
1246
|
-
if (
|
|
1247
|
-
const
|
|
1248
|
-
|
|
1249
|
-
|
|
1253
|
+
if (P.current.get(F)?.fingerprint === Pe) continue;
|
|
1254
|
+
const [Le, We] = await Promise.all([
|
|
1255
|
+
H.url(_.area.image),
|
|
1256
|
+
Ye(B, H)
|
|
1250
1257
|
]);
|
|
1251
|
-
if (
|
|
1252
|
-
const
|
|
1258
|
+
if (I.current || w !== M.current || (await U.switchView({ ..._.area, image: Le }, G, We), I.current || w !== M.current)) return;
|
|
1259
|
+
const Se = typeof createImageBitmap == "function" ? await U.exportPreviewBitmap(ce, G) : await U.export(!1, G, {
|
|
1253
1260
|
minOutputSize: ce,
|
|
1254
1261
|
preferImageBitmap: !1,
|
|
1255
1262
|
returnBlobUrl: !1,
|
|
1256
1263
|
outputMultiplierCap: 1,
|
|
1257
1264
|
quality: 0.72
|
|
1258
1265
|
});
|
|
1259
|
-
if (
|
|
1260
|
-
const
|
|
1261
|
-
|
|
1266
|
+
if (Se) {
|
|
1267
|
+
const j = P.current.get(F);
|
|
1268
|
+
j && ue(j.texture), P.current.set(F, { fingerprint: Pe, texture: Se });
|
|
1262
1269
|
}
|
|
1263
|
-
if (
|
|
1270
|
+
if (I.current || w !== M.current) return;
|
|
1264
1271
|
}
|
|
1265
|
-
const
|
|
1266
|
-
if (
|
|
1267
|
-
const
|
|
1268
|
-
const
|
|
1272
|
+
const Ue = new Map(await be);
|
|
1273
|
+
if (I.current || w !== M.current) return;
|
|
1274
|
+
const Ce = ve.map((_) => {
|
|
1275
|
+
const F = _.design ? P.current.get(Z(_))?.texture : void 0, B = _.texture_transform, G = typeof B?.blendMode == "number" ? B.blendMode : typeof B?.blendMode == "string" ? ze[B.blendMode.toLowerCase()] : void 0;
|
|
1269
1276
|
return {
|
|
1270
|
-
...
|
|
1271
|
-
image:
|
|
1277
|
+
..._,
|
|
1278
|
+
image: Ue.get(_.image) ?? _.image,
|
|
1272
1279
|
texture: F,
|
|
1280
|
+
color: c === "placement" && _.design ? de(_, s) : void 0,
|
|
1273
1281
|
// PixelMapRenderer consumes the source blend-mode string; Pixi
|
|
1274
1282
|
// still receives its enum value exactly as before.
|
|
1275
|
-
config:
|
|
1283
|
+
config: B ? Y ? { ...B } : { ...B, blendMode: G } : void 0
|
|
1276
1284
|
};
|
|
1277
|
-
}), oe =
|
|
1278
|
-
color:
|
|
1285
|
+
}), oe = Y ? await V.onOffscreenRender(Ce, {
|
|
1286
|
+
color: ye,
|
|
1279
1287
|
targetSize: ce,
|
|
1280
1288
|
quality: 0.85,
|
|
1281
1289
|
format: "image/png",
|
|
1282
1290
|
cacheKey: e.id
|
|
1283
1291
|
}) : await V.onOffscreenRender(Ce, {
|
|
1284
|
-
color:
|
|
1292
|
+
color: ye,
|
|
1285
1293
|
cleanCache: !1,
|
|
1286
|
-
scale:
|
|
1294
|
+
scale: o,
|
|
1287
1295
|
quality: 0.85
|
|
1288
1296
|
});
|
|
1289
|
-
if (
|
|
1297
|
+
if (I.current || w !== M.current) return;
|
|
1290
1298
|
if (!oe) throw new Error("Could not render the product preview");
|
|
1291
|
-
const
|
|
1292
|
-
|
|
1293
|
-
} catch (
|
|
1294
|
-
!
|
|
1299
|
+
const he = URL.createObjectURL(oe);
|
|
1300
|
+
k.current && URL.revokeObjectURL(k.current), l.current = oe, k.current = he, R(he), q.current.onRendered?.({ renderId: e.id, blob: oe, url: he });
|
|
1301
|
+
} catch (U) {
|
|
1302
|
+
!I.current && w === M.current && q.current.onError?.(U instanceof Error ? U : new Error("Could not render the product preview"));
|
|
1295
1303
|
} finally {
|
|
1296
1304
|
D?.();
|
|
1297
1305
|
}
|
|
1298
1306
|
});
|
|
1299
|
-
}, [n, s, ie, me, pe, K, e,
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
}), [ne]),
|
|
1303
|
-
|
|
1304
|
-
}, [
|
|
1305
|
-
const w = K(), Q = i ?? s, D =
|
|
1307
|
+
}, [n, c, s, ie, me, pe, K, e, o, Y]);
|
|
1308
|
+
ee(() => (I.current = !1, () => {
|
|
1309
|
+
I.current = !0, M.current += 1, p.current?.clear(), p.current?.active || ne();
|
|
1310
|
+
}), [ne]), ee(() => {
|
|
1311
|
+
u.current?.destroy(), u.current = null;
|
|
1312
|
+
}, [m, Y]), ee(() => {
|
|
1313
|
+
const w = K(), Q = i ?? s, D = _e(e, Q, n, Y, c);
|
|
1306
1314
|
w.pin(D);
|
|
1307
|
-
let
|
|
1315
|
+
let U = !0;
|
|
1308
1316
|
return w.preload(D, !0).then(async () => {
|
|
1309
|
-
if (
|
|
1310
|
-
for (const V of fe(e, Q, n,
|
|
1311
|
-
const
|
|
1312
|
-
if (!
|
|
1313
|
-
|
|
1317
|
+
if (U)
|
|
1318
|
+
for (const V of fe(e, Q, n, Y, c).map((H) => H.image).filter(Boolean)) {
|
|
1319
|
+
const H = await w.url(V);
|
|
1320
|
+
if (!U) return;
|
|
1321
|
+
q.current.onAssetReady?.(V, H), V === nt(e) && Ee(H);
|
|
1314
1322
|
}
|
|
1315
1323
|
}).catch(() => {
|
|
1316
1324
|
}).finally(() => {
|
|
1317
|
-
|
|
1325
|
+
U && t?.length && W.current !== t && (W.current = t, w.preload(t).catch(() => {
|
|
1318
1326
|
}));
|
|
1319
1327
|
}), () => {
|
|
1320
|
-
|
|
1328
|
+
U = !1;
|
|
1321
1329
|
};
|
|
1322
|
-
}, [n, s, i, K, t, e,
|
|
1323
|
-
|
|
1324
|
-
}), [r, ae, $]),
|
|
1330
|
+
}, [n, c, s, i, K, t, e, Y]), ee(() => (r ? ae() : $(!1), () => {
|
|
1331
|
+
M.current += 1, p.current?.clear();
|
|
1332
|
+
}), [r, ae, $]), He(O, () => ({
|
|
1325
1333
|
acquireResources: (w) => K().acquire(w),
|
|
1326
|
-
getPreviewBlob: async () =>
|
|
1327
|
-
getPreviewUrl: async () =>
|
|
1334
|
+
getPreviewBlob: async () => l.current,
|
|
1335
|
+
getPreviewUrl: async () => l.current ? URL.createObjectURL(l.current) : null,
|
|
1328
1336
|
refresh: () => {
|
|
1329
|
-
|
|
1337
|
+
S.current += 1, y.current = !0, r && ae();
|
|
1330
1338
|
},
|
|
1331
1339
|
updateText: async (w, Q) => {
|
|
1332
1340
|
const D = ie();
|
|
1333
1341
|
return D ? D.updateText(w, Q) : null;
|
|
1334
1342
|
}
|
|
1335
1343
|
}), [r, ie, K, ae]);
|
|
1336
|
-
const we =
|
|
1337
|
-
return /* @__PURE__ */
|
|
1338
|
-
we && /* @__PURE__ */ z("img", { src: we, alt:
|
|
1339
|
-
|
|
1340
|
-
/* @__PURE__ */ z("div", { "aria-hidden": "true", style: { position: "absolute", width: 1, height: 1, overflow: "hidden", opacity: 0, pointerEvents: "none" }, children: /* @__PURE__ */ z("div", { ref:
|
|
1344
|
+
const we = se || Ie;
|
|
1345
|
+
return /* @__PURE__ */ Oe("div", { className: g, style: { position: "relative", ...b }, children: [
|
|
1346
|
+
we && /* @__PURE__ */ z("img", { src: we, alt: h, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
|
|
1347
|
+
le && /* @__PURE__ */ z("div", { "aria-live": "polite", "aria-label": "Rendering product preview", style: { position: "absolute", inset: 0 } }),
|
|
1348
|
+
/* @__PURE__ */ z("div", { "aria-hidden": "true", style: { position: "absolute", width: 1, height: 1, overflow: "hidden", opacity: 0, pointerEvents: "none" }, children: /* @__PURE__ */ z("div", { ref: E, style: { width: 800, height: 800 }, children: /* @__PURE__ */ z("canvas", { ref: v, width: 800, height: 800 }) }) })
|
|
1341
1349
|
] });
|
|
1342
1350
|
}
|
|
1343
1351
|
);
|
|
1344
|
-
function
|
|
1352
|
+
function kt({
|
|
1345
1353
|
viewArea: d,
|
|
1346
1354
|
viewState: e,
|
|
1347
1355
|
activeObjectId: s,
|
|
@@ -1351,59 +1359,59 @@ function Pt({
|
|
|
1351
1359
|
className: a,
|
|
1352
1360
|
style: n
|
|
1353
1361
|
}) {
|
|
1354
|
-
const c =
|
|
1355
|
-
|
|
1356
|
-
const
|
|
1357
|
-
const
|
|
1358
|
-
if (!
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1362
|
+
const c = C(null), o = C(null), m = C(null), g = C(r), b = C(i), h = C(null), X = C(e), [x, A] = te(!1), [O, v] = te("");
|
|
1363
|
+
g.current = r, b.current = i;
|
|
1364
|
+
const E = N(() => {
|
|
1365
|
+
const f = m.current;
|
|
1366
|
+
if (!f) return;
|
|
1367
|
+
const u = f.getRenderedObjects();
|
|
1368
|
+
g.current(h.current ? it(u, h.current, X.current) : u);
|
|
1361
1369
|
}, []);
|
|
1362
|
-
return
|
|
1363
|
-
let
|
|
1364
|
-
const
|
|
1365
|
-
T || (T = !0,
|
|
1370
|
+
return ee(() => {
|
|
1371
|
+
let f = !1, u = null, T = !1, W = !1, l = null, k = null;
|
|
1372
|
+
const M = () => {
|
|
1373
|
+
T || (T = !0, u?.destroy(), m.current === u && (m.current = null), l?.release(), h.current === l && (h.current = null), k?.dispose());
|
|
1366
1374
|
};
|
|
1367
1375
|
return (async () => {
|
|
1368
|
-
if (
|
|
1369
|
-
const
|
|
1370
|
-
if (!
|
|
1371
|
-
const
|
|
1372
|
-
if (t ? l = await t(
|
|
1373
|
-
|
|
1374
|
-
const
|
|
1375
|
-
if (
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1378
|
-
...
|
|
1379
|
-
objects: (Array.isArray(
|
|
1380
|
-
(
|
|
1376
|
+
if (b.current?.(!0), await new Promise((R) => requestAnimationFrame(() => R())), f) return;
|
|
1377
|
+
const p = c.current, S = o.current;
|
|
1378
|
+
if (!p || !S) return;
|
|
1379
|
+
const y = p.clientWidth || 400, I = p.clientHeight || 400, q = [d.image, ...ge(e)];
|
|
1380
|
+
if (t ? l = await t(q) : (k = new Me(), l = await k.acquire(q)), f) return;
|
|
1381
|
+
h.current = l;
|
|
1382
|
+
const Y = await Ye(e, { url: async (R) => l.urls[R] ?? R });
|
|
1383
|
+
if (f) return;
|
|
1384
|
+
u = new xe(S, { width: y, height: I }, p, 0.85), m.current = u, tt(typeof window < "u" && window.innerWidth < 768 ? 16 : 8);
|
|
1385
|
+
const re = {
|
|
1386
|
+
...Y,
|
|
1387
|
+
objects: (Array.isArray(Y.objects) ? Y.objects : []).map(
|
|
1388
|
+
(R) => R?.selectable === !1 ? { ...R, selectable: !0 } : R
|
|
1381
1389
|
)
|
|
1382
1390
|
};
|
|
1383
|
-
if (await
|
|
1391
|
+
if (await u.switchView({ ...d, image: l.urls[d.image] ?? d.image }, typeof e.color == "string" ? e.color : "", re), f) return;
|
|
1384
1392
|
const se = new Set(
|
|
1385
|
-
(Array.isArray(e.objects) ? e.objects : []).filter((
|
|
1393
|
+
(Array.isArray(e.objects) ? e.objects : []).filter((R) => R?.customConfig?.moveable === !0).map((R) => String(R.id ?? ""))
|
|
1386
1394
|
);
|
|
1387
|
-
if (
|
|
1388
|
-
se.has(String(
|
|
1395
|
+
if (u.canvas.forEachObject((R) => {
|
|
1396
|
+
se.has(String(R.id ?? "")) || R.set({ selectable: !1, evented: !1 });
|
|
1389
1397
|
}), s) {
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1398
|
+
const R = u.canvas.getObjects().find((le) => String(le.id ?? "") === String(s));
|
|
1399
|
+
R && se.has(String(s)) && u.canvas.setActiveObject(R);
|
|
1392
1400
|
}
|
|
1393
|
-
|
|
1394
|
-
})().catch((
|
|
1395
|
-
|
|
1401
|
+
u.canvas.on("object:modified", () => E()), u.canvas.requestRenderAll(), await new Promise((R) => requestAnimationFrame(() => R())), f || A(!0);
|
|
1402
|
+
})().catch((p) => {
|
|
1403
|
+
f || v(p instanceof Error ? p.message : "Could not load the editor.");
|
|
1396
1404
|
}).finally(() => {
|
|
1397
|
-
|
|
1405
|
+
W = !0, f && M(), b.current?.(!1);
|
|
1398
1406
|
}), () => {
|
|
1399
|
-
|
|
1407
|
+
f = !0, A(!1), W && M();
|
|
1400
1408
|
};
|
|
1401
|
-
}, []), /* @__PURE__ */
|
|
1409
|
+
}, []), /* @__PURE__ */ Oe("div", { className: a, style: { position: "relative", width: "100%", height: "100%", ...n }, children: [
|
|
1402
1410
|
/* @__PURE__ */ z("div", { ref: c, style: { position: "absolute", inset: 0, overflow: "hidden" }, children: /* @__PURE__ */ z("canvas", { ref: o }) }),
|
|
1403
|
-
!
|
|
1411
|
+
!x && /* @__PURE__ */ z("div", { style: { position: "absolute", inset: 0, background: "#f2f2f2" }, "aria-label": O ? "Editor failed to load" : "Loading editor", children: O && /* @__PURE__ */ z("span", { role: "alert", children: O }) })
|
|
1404
1412
|
] });
|
|
1405
1413
|
}
|
|
1406
1414
|
export {
|
|
1407
|
-
|
|
1408
|
-
|
|
1415
|
+
kt as P,
|
|
1416
|
+
Rt as a
|
|
1409
1417
|
};
|