@printine/pod-editor 0.1.16 → 0.1.18

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.
@@ -1,25 +1,25 @@
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";
1
+ import { jsxs as Ae, jsx as H } from "react/jsx-runtime";
2
+ import { forwardRef as Ge, useRef as S, useState as Z, useCallback as N, useEffect as ie, useImperativeHandle as Je } from "react";
3
+ import { LAYER_BLACK_LIST as Oe, BLEND_MODES_MAP as Ke } from "./engine/constants.js";
4
+ import { P as Ye, h as Qe, r as Ze, i as pe, M as $e, a as je } from "./pixel-map-BvQ0VU_i.js";
5
5
  import "./engine/fabric.js";
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";
6
+ import { v4 as et } from "uuid";
7
+ import { cloneObject as G, urlToDataURL as tt } from "./engine/utils/common.js";
8
+ import { ImageProcessor as rt } from "./engine/processors/image.js";
9
+ import { TemplateProcessor as it } from "./engine/processors/template.js";
10
+ import { TextProcessor as st } from "./engine/processors/text.js";
11
+ import { ResizeManager as nt } from "./engine/managers/resize.js";
12
+ import { loadOverlaySvgImage as at, loadImage as ct } from "./engine/utils/image.js";
13
+ import { WorkspaceManager as ot } from "./engine/managers/workspace.js";
14
+ import { HistoryManager as lt } from "./engine/history.js";
15
+ import ht from "./engine/events.js";
16
16
  import { fabric as L } from "fabric";
17
- import { setDefaultControls as tt } from "./engine/utils/setting.js";
18
- class xe {
19
- constructor(e, s, r, t = 0.85) {
20
- this.imageCache = /* @__PURE__ */ new Map(), this.overlayCache = /* @__PURE__ */ new Map(), this.destroyed = !1, this.deleteObject = (i) => {
21
- if (i) {
22
- const a = this.canvas._objects.find((n) => n.id === i);
17
+ import { setDefaultControls as ut } from "./engine/utils/setting.js";
18
+ class Ie {
19
+ constructor(e, i, r, t = 0.85) {
20
+ this.imageCache = /* @__PURE__ */ new Map(), this.overlayCache = /* @__PURE__ */ new Map(), this.destroyed = !1, this.deleteObject = (s) => {
21
+ if (s) {
22
+ const a = this.canvas._objects.find((n) => n.id === s);
23
23
  a && (this.canvas.remove(a), this.revokeImgBlobLink(a));
24
24
  } else {
25
25
  const a = this.canvas.getActiveObjects();
@@ -30,8 +30,8 @@ class xe {
30
30
  this.canvas.requestRenderAll();
31
31
  }, this.canvas = new L.Canvas(e, {
32
32
  enableRetinaScaling: !0,
33
- width: s.width,
34
- height: s.height,
33
+ width: i.width,
34
+ height: i.height,
35
35
  preserveObjectStacking: !0,
36
36
  stopContextMenu: !1,
37
37
  centeredRotation: !0,
@@ -43,7 +43,7 @@ class xe {
43
43
  controlsAboveOverlay: !0,
44
44
  fireRightClick: !0
45
45
  // 允许识别右键点击
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);
46
+ }), this.overlayScale = t, this.imageProcessor = new rt(this), this.templateProcessor = new it(this), this.textProcessor = new st(this), this.resizeManager = new nt(this, r), this.workspaceManager = new ot(this);
47
47
  }
48
48
  /**
49
49
  * ImageProcessor/TextProcessor are shared with the interactive editor and
@@ -65,8 +65,8 @@ class xe {
65
65
  * @param changeView 是否切换视图,如果为true,则需要重新设置画布和背景图
66
66
 
67
67
  */
68
- async renderOverlayImage(e, s = !1) {
69
- const { image: r, clipPath: t } = await this.getOverlayImage(e.image), i = Math.min(this.canvas.width, this.canvas.height) * this.overlayScale, a = i / r.width, n = i / r.height, c = Math.min(a, n);
68
+ async renderOverlayImage(e, i = !1) {
69
+ const { image: r, clipPath: t } = await this.getOverlayImage(e.image), s = Math.min(this.canvas.width, this.canvas.height) * this.overlayScale, a = s / r.width, n = s / r.height, c = Math.min(a, n);
70
70
  return r.set({
71
71
  scaleX: c,
72
72
  scaleY: c,
@@ -81,7 +81,7 @@ class xe {
81
81
  absolutePositioned: !0,
82
82
  selectable: !1,
83
83
  evented: !1
84
- }), s && this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]), new Promise((o) => {
84
+ }), i && this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]), new Promise((o) => {
85
85
  this.canvas.setOverlayImage(r, async () => {
86
86
  this.workspaceManager.setClipPath(t ?? r, {
87
87
  width: r.width,
@@ -95,25 +95,25 @@ class xe {
95
95
  * 会返回深拷贝,确保不同视图间互不影响
96
96
  */
97
97
  async getOverlayImage(e) {
98
- const s = this.overlayCache.get(e);
99
- if (s) {
100
- const a = await J(s.image), n = s.clipPath ? await J(s.clipPath) : void 0;
98
+ const i = this.overlayCache.get(e);
99
+ if (i) {
100
+ const a = await G(i.image), n = i.clipPath ? await G(i.clipPath) : void 0;
101
101
  return { image: a, clipPath: n };
102
102
  }
103
- const r = await Qe(e);
103
+ const r = await at(e);
104
104
  this.overlayCache.set(e, r);
105
- const t = await J(r.image), i = r.clipPath ? await J(r.clipPath) : void 0;
106
- return { image: t, clipPath: i };
105
+ const t = await G(r.image), s = r.clipPath ? await G(r.clipPath) : void 0;
106
+ return { image: t, clipPath: s };
107
107
  }
108
108
  /**
109
109
  * 绘制可设计区域边框,优先使用 clipPath 的真实形状
110
110
  */
111
- setupOverlayBorders(e, s) {
111
+ setupOverlayBorders(e, i) {
112
112
  this.overlayBorderHandler && this.canvas.off("after:render", this.overlayBorderHandler);
113
- const r = s ?? e;
113
+ const r = i ?? e;
114
114
  this.overlayBorderHandler = () => {
115
- const t = this.canvas.getContext(), i = this.canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
116
- t.save(), t.transform(i[0], i[1], i[2], i[3], i[4], i[5]);
115
+ const t = this.canvas.getContext(), s = this.canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
116
+ t.save(), t.transform(s[0], s[1], s[2], s[3], s[4], s[5]);
117
117
  const a = {
118
118
  stroke: r.stroke,
119
119
  strokeWidth: r.strokeWidth,
@@ -129,13 +129,13 @@ class xe {
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, g = r.top ?? 0, b = r.scaleX ?? 1, h = r.scaleY ?? 1;
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, P = 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: b * c,
138
+ scaleX: P * c,
139
139
  scaleY: h * o,
140
140
  left: m - n,
141
141
  top: g - n
@@ -145,7 +145,7 @@ class xe {
145
145
  strokeDashArray: a.strokeDashArray,
146
146
  fill: a.fill,
147
147
  strokeUniform: a.strokeUniform,
148
- scaleX: b,
148
+ scaleX: P,
149
149
  scaleY: h,
150
150
  left: m,
151
151
  top: g
@@ -182,17 +182,17 @@ class xe {
182
182
  * 设置背景遮罩
183
183
  */
184
184
  async setBackgroundMask(e) {
185
- const s = document.querySelector(".lower-canvas");
186
- if (s && !e)
187
- return s.style.backgroundImage = "", Promise.resolve();
188
- const r = await Ze(e);
185
+ const i = document.querySelector(".lower-canvas");
186
+ if (i && !e)
187
+ return i.style.backgroundImage = "", Promise.resolve();
188
+ const r = await ct(e);
189
189
  if (r == null) return Promise.resolve();
190
190
  r.set({
191
191
  scaleX: this.canvas.width / r.width,
192
192
  scaleY: this.canvas.height / r.height
193
193
  });
194
194
  const t = r.toDataURL({ format: "png" });
195
- s && (s.style.backgroundImage = `url(${t})`, s.style.backgroundSize = "100% 100%");
195
+ i && (i.style.backgroundImage = `url(${t})`, i.style.backgroundSize = "100% 100%");
196
196
  }
197
197
  /**
198
198
  * 设置背景颜色、透明图案
@@ -210,12 +210,12 @@ class xe {
210
210
  * 获取对象经过画布转换后的实际尺寸
211
211
  */
212
212
  getObjectActualSize(e) {
213
- const { left: s = 0, top: r = 0, width: t = 0, height: i = 0 } = e.getBoundingRect(), a = e.getCenterPoint(), n = this.canvas.viewportTransform;
213
+ const { left: i = 0, top: r = 0, width: t = 0, height: s = 0 } = e.getBoundingRect(), a = e.getCenterPoint(), n = this.canvas.viewportTransform;
214
214
  return {
215
- left: s * n[0] + n[4],
215
+ left: i * n[0] + n[4],
216
216
  top: r * n[3] + n[5],
217
217
  width: t * n[0],
218
- height: i * n[3],
218
+ height: s * n[3],
219
219
  centerX: a.x * n[0] + n[4],
220
220
  centerY: a.y * n[3] + n[5]
221
221
  };
@@ -224,29 +224,29 @@ class xe {
224
224
  * 添加对象
225
225
  *
226
226
  */
227
- addObject(e, s = !0) {
227
+ addObject(e, i = !0) {
228
228
  e.set({
229
- id: Fe()
230
- }), this.canvas.add(e), s && this.canvas.setActiveObject(e);
229
+ id: et()
230
+ }), this.canvas.add(e), i && this.canvas.setActiveObject(e);
231
231
  }
232
232
  /**
233
233
  * 恢复对象
234
234
  */
235
235
  async restoreObject(e) {
236
- return new Promise((s) => {
237
- L.util.enlivenObjects([e], (r) => s(r), "");
236
+ return new Promise((i) => {
237
+ L.util.enlivenObjects([e], (r) => i(r), "");
238
238
  });
239
239
  }
240
240
  /**
241
241
  * 半定制文本更新:如果存在 originalWidth / originalHeight,则按固定框重新计算 fitScale;
242
242
  * 否则只更新文本内容/字体等基础属性。
243
243
  */
244
- async updateText(e, s) {
244
+ async updateText(e, i) {
245
245
  if (!(typeof e?.type == "string" && (e.type.includes("i-text") || e.type === "text"))) return null;
246
- await this.textProcessor.ensureFontLoaded(s);
246
+ await this.textProcessor.ensureFontLoaded(i);
247
247
  const [t] = await this.restoreObject(e);
248
248
  if (!t) return null;
249
- const i = e.scaleX || 1, a = e.scaleY || 1, n = e?.customConfig, c = typeof n?.originalWidth == "number" && n.originalWidth > 0 && typeof n?.originalHeight == "number" && n.originalHeight > 0 && !n.moveable, o = t.type === "advanced-i-text" && t.radius, m = () => ({
249
+ const s = e.scaleX || 1, a = e.scaleY || 1, n = e?.customConfig, c = typeof n?.originalWidth == "number" && n.originalWidth > 0 && typeof n?.originalHeight == "number" && n.originalHeight > 0 && !n.moveable, o = t.type === "advanced-i-text" && t.radius, m = () => ({
250
250
  ...typeof t.__baseWidth < "u" ? { __baseWidth: t.__baseWidth } : {},
251
251
  ...typeof t.__baseHeight < "u" ? { __baseHeight: t.__baseHeight } : {},
252
252
  ...typeof t.__basePadding < "u" ? { __basePadding: t.__basePadding } : {},
@@ -263,14 +263,14 @@ class xe {
263
263
  ...typeof t.spacing < "u" ? { spacing: t.spacing } : {}
264
264
  });
265
265
  if (!c) {
266
- const v = o ? t.getCenterPoint() : null;
267
- t.set(s), o && (t.__restoredGeometry = !1);
266
+ const y = o ? t.getCenterPoint() : null;
267
+ t.set(i), o && (t.__restoredGeometry = !1);
268
268
  try {
269
269
  t.initDimensions?.();
270
270
  } catch {
271
271
  }
272
- return v && t.setPositionByOrigin(v, "center", "center"), t.setCoords(), {
273
- ...s,
272
+ return y && t.setPositionByOrigin(y, "center", "center"), t.setCoords(), {
273
+ ...i,
274
274
  text: t.text,
275
275
  left: t.left,
276
276
  top: t.top,
@@ -285,31 +285,31 @@ class xe {
285
285
  ...m()
286
286
  };
287
287
  }
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";
288
+ const g = e?.__semiTargetInfo, P = !!g && typeof g.width == "number" && g.width > 0 && typeof g.height == "number" && g.height > 0 && typeof g.centerX == "number" && typeof g.centerY == "number";
289
289
  let h;
290
- if (b) {
291
- const v = t.getCenterPoint();
290
+ if (P) {
291
+ const y = t.getCenterPoint();
292
292
  h = {
293
293
  width: n.originalWidth,
294
294
  height: n.originalHeight,
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,
295
+ centerX: typeof g.centerX == "number" ? g.centerX : y.x,
296
+ centerY: typeof g.centerY == "number" ? g.centerY : y.y,
297
+ signX: typeof g.signX == "number" && g.signX !== 0 ? Math.sign(g.signX) : Math.sign(s) || 1,
298
298
  signY: typeof g.signY == "number" && g.signY !== 0 ? Math.sign(g.signY) : Math.sign(a) || 1
299
299
  };
300
300
  } else {
301
- const v = t.getCenterPoint();
301
+ const y = t.getCenterPoint();
302
302
  h = {
303
303
  width: n.originalWidth,
304
304
  height: n.originalHeight,
305
- centerX: v.x,
306
- centerY: v.y,
307
- signX: Math.sign(i) || 1,
305
+ centerX: y.x,
306
+ centerY: y.y,
307
+ signX: Math.sign(s) || 1,
308
308
  signY: Math.sign(a) || 1
309
309
  };
310
310
  }
311
311
  t.set({
312
- ...s,
312
+ ...i,
313
313
  scaleX: h.signX,
314
314
  scaleY: h.signY
315
315
  }), o && (t.__restoredGeometry = !1);
@@ -319,12 +319,12 @@ class xe {
319
319
  }
320
320
  t.setCoords();
321
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
322
+ let M = Math.min(h.width / x, h.height / A);
323
+ return (!Number.isFinite(M) || M <= 0) && (M = 1), t.set({
324
+ scaleX: M * h.signX,
325
+ scaleY: M * h.signY
326
326
  }), t.setPositionByOrigin(new L.Point(h.centerX, h.centerY), "center", "center"), t.setCoords(), {
327
- ...s,
327
+ ...i,
328
328
  text: t.text,
329
329
  left: t.left,
330
330
  top: t.top,
@@ -343,31 +343,31 @@ class xe {
343
343
  /**
344
344
  * 半定制图片替换:使用 cover 模式重新计算缩放,保持原始占位框中心不变。
345
345
  */
346
- async updateImage(e, s) {
346
+ async updateImage(e, i) {
347
347
  if (e?.type !== "image") return null;
348
- const r = s.src;
348
+ const r = i.src;
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), g = o * Math.abs(n), b = t.getCenterPoint();
352
+ const s = 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), P = t.getCenterPoint();
353
353
  return new Promise((h) => {
354
- i.setSrc(r, () => {
355
- const X = i.width || 1, x = i.height || 1, A = Math.max(m / X, g / x);
356
- i.set({
357
- ...s,
354
+ s.setSrc(r, () => {
355
+ const X = s.width || 1, x = s.height || 1, A = Math.max(m / X, g / x);
356
+ s.set({
357
+ ...i,
358
358
  scaleX: A * Math.sign(a),
359
359
  scaleY: A * Math.sign(n)
360
- }), i.setPositionByOrigin(b, "center", "center"), i.setCoords(), h({
361
- ...s,
360
+ }), s.setPositionByOrigin(P, "center", "center"), s.setCoords(), h({
361
+ ...i,
362
362
  width: X,
363
363
  height: x,
364
- left: i.left,
365
- top: i.top,
366
- scaleX: i.scaleX,
367
- scaleY: i.scaleY,
368
- angle: i.angle,
369
- originX: i.originX,
370
- originY: i.originY,
364
+ left: s.left,
365
+ top: s.top,
366
+ scaleX: s.scaleX,
367
+ scaleY: s.scaleY,
368
+ angle: s.angle,
369
+ originX: s.originX,
370
+ originY: s.originY,
371
371
  selectable: e.selectable
372
372
  });
373
373
  });
@@ -379,10 +379,10 @@ class xe {
379
379
  */
380
380
  revokeImgBlobLink(e) {
381
381
  if (e.type === "image" && e.getSrc) {
382
- const s = e, r = s.getSrc(), t = s.originSrc || r;
382
+ const i = e, r = i.getSrc(), t = i.originSrc || r;
383
383
  if (r && r.startsWith("blob:")) {
384
- const i = this.imageCache.get(t);
385
- if (!i || i.blobUrl !== r)
384
+ const s = this.imageCache.get(t);
385
+ if (!s || s.blobUrl !== r)
386
386
  try {
387
387
  URL.revokeObjectURL(r);
388
388
  } catch {
@@ -395,14 +395,14 @@ class xe {
395
395
  * @param {String} id 对象id
396
396
  * @param {Record<string, any>} obj 对象属性集合
397
397
  */
398
- updateObject(e, s) {
398
+ updateObject(e, i) {
399
399
  const r = this.canvas._objects.find((t) => t.id === e);
400
400
  if (r) {
401
- if (s.hasOwnProperty("angle"))
402
- r.rotate(s.angle);
403
- else if (s.hasOwnProperty("align")) {
404
- const { left: t, right: i, top: a, bottom: n, center: c } = this.workspaceManager.dimension, o = r.getBoundingRect(!0, !0);
405
- switch (s.align) {
401
+ if (i.hasOwnProperty("angle"))
402
+ r.rotate(i.angle);
403
+ else if (i.hasOwnProperty("align")) {
404
+ const { left: t, right: s, top: a, bottom: n, center: c } = this.workspaceManager.dimension, o = r.getBoundingRect(!0, !0);
405
+ switch (i.align) {
406
406
  case "top":
407
407
  r.set({
408
408
  top: r.top + (a - o.top)
@@ -420,7 +420,7 @@ class xe {
420
420
  break;
421
421
  case "right":
422
422
  r.set({
423
- left: r.left + (i - (o.left + o.width))
423
+ left: r.left + (s - (o.left + o.width))
424
424
  });
425
425
  break;
426
426
  case "vertical-center":
@@ -434,16 +434,16 @@ class xe {
434
434
  });
435
435
  break;
436
436
  }
437
- } else if (s.hasOwnProperty("zIndex"))
438
- this.canvas.moveTo(r, s.zIndex);
439
- else if (s.hasOwnProperty("scale"))
440
- this.updateObjectScale(r, s.scale);
441
- else if (s.hasOwnProperty("width") || s.hasOwnProperty("height")) {
442
- const t = s.hasOwnProperty("width") ? r.width : r.height, a = (s.width || s.height) / t * this.workspaceManager.scale;
437
+ } else if (i.hasOwnProperty("zIndex"))
438
+ this.canvas.moveTo(r, i.zIndex);
439
+ else if (i.hasOwnProperty("scale"))
440
+ this.updateObjectScale(r, i.scale);
441
+ else if (i.hasOwnProperty("width") || i.hasOwnProperty("height")) {
442
+ const t = i.hasOwnProperty("width") ? r.width : r.height, a = (i.width || i.height) / t * this.workspaceManager.scale;
443
443
  this.updateObjectScale(r, a);
444
444
  } else
445
- r.set(s);
446
- r.setCoords(), this.canvas.requestRenderAll(), s.hasOwnProperty("selectable") || this.canvas.fire("object:modified", {
445
+ r.set(i);
446
+ r.setCoords(), this.canvas.requestRenderAll(), i.hasOwnProperty("selectable") || this.canvas.fire("object:modified", {
447
447
  target: r
448
448
  });
449
449
  }
@@ -451,17 +451,17 @@ class xe {
451
451
  /**
452
452
  * 对象缩放
453
453
  */
454
- updateObjectScale(e, s) {
454
+ updateObjectScale(e, i) {
455
455
  const r = e.getCenterPoint(), t = this.workspaceManager.dimension.width * 0.01 / e.width;
456
- e.scale(s < t ? t : s), e.setPositionByOrigin(r, "center", "center");
456
+ e.scale(i < t ? t : i), e.setPositionByOrigin(r, "center", "center");
457
457
  }
458
458
  /**
459
459
  * 修改画布上的对象的选中状态和事件状态
460
460
  * @param status
461
461
  */
462
462
  updateObjectsEvents(e) {
463
- this.canvas.forEachObject((s) => {
464
- s.set({
463
+ this.canvas.forEachObject((i) => {
464
+ i.set({
465
465
  selectable: e,
466
466
  evented: e
467
467
  });
@@ -471,21 +471,21 @@ class xe {
471
471
  * 获取当前可选择的对象,不包括背景图、裁剪区域
472
472
  */
473
473
  getLayerList() {
474
- return this.canvas._objects.filter((e) => !Re.includes(e.id || ""));
474
+ return this.canvas._objects.filter((e) => !Oe.includes(e.id || ""));
475
475
  }
476
476
  /**
477
477
  * 设置当前选中的对象
478
478
  */
479
479
  setActiveObject(e) {
480
- const s = this.canvas.getActiveObjects(), r = s.some((i) => i.id === e), t = this.getLayerList().find((i) => i.id === e);
481
- t && (this.canvas.discardActiveObject(), (!r || s.length > 1) && this.canvas.setActiveObject(t), this.canvas.requestRenderAll());
480
+ const i = this.canvas.getActiveObjects(), r = i.some((s) => s.id === e), t = this.getLayerList().find((s) => s.id === e);
481
+ t && (this.canvas.discardActiveObject(), (!r || i.length > 1) && this.canvas.setActiveObject(t), this.canvas.requestRenderAll());
482
482
  }
483
483
  /**
484
484
  * 同时选中多个对象
485
485
  */
486
486
  setActiveObjects(e) {
487
- const s = new L.ActiveSelection(e, { canvas: this.canvas });
488
- this.canvas.setActiveObject(s), this.canvas.requestRenderAll();
487
+ const i = new L.ActiveSelection(e, { canvas: this.canvas });
488
+ this.canvas.setActiveObject(i), this.canvas.requestRenderAll();
489
489
  }
490
490
  /**
491
491
  * 以画布中心点缩放画布
@@ -494,7 +494,7 @@ class xe {
494
494
  if (e === 1)
495
495
  this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
496
496
  else {
497
- const s = this.canvas.viewportTransform, r = s[0], t = s[4], i = s[5], a = this.canvas.width / 2, n = this.canvas.height / 2, c = e - r, o = t - a * c, m = i - n * c;
497
+ const i = this.canvas.viewportTransform, r = i[0], t = i[4], s = i[5], a = this.canvas.width / 2, n = this.canvas.height / 2, c = e - r, o = t - a * c, m = s - n * c;
498
498
  this.canvas.setViewportTransform([e, 0, 0, e, o, m]);
499
499
  }
500
500
  this.canvas.requestRenderAll();
@@ -503,14 +503,14 @@ class xe {
503
503
  * 获取当前画布上渲染的对象
504
504
  */
505
505
  getRenderedObjects() {
506
- const { objects: e } = this.canvas.toJSON(je.DEFAULT_SAVE_PROPERTIES), s = this.workspaceManager.dimension;
506
+ const { objects: e } = this.canvas.toJSON(lt.DEFAULT_SAVE_PROPERTIES), i = this.workspaceManager.dimension;
507
507
  return {
508
- objects: e.filter((r) => !Re.includes(r.id || "")),
508
+ objects: e.filter((r) => !Oe.includes(r.id || "")),
509
509
  workspaceMetadata: {
510
- width: s.width,
511
- height: s.height,
512
- centerX: s.center.x,
513
- centerY: s.center.y
510
+ width: i.width,
511
+ height: i.height,
512
+ centerX: i.center.x,
513
+ centerY: i.center.y
514
514
  }
515
515
  };
516
516
  }
@@ -524,34 +524,34 @@ class xe {
524
524
  * 将图片对象的 clipPath 重新关联到画布上的对象
525
525
  */
526
526
  relinkClipPaths() {
527
- const e = /* @__PURE__ */ new Map(), s = this.canvas.getObjects(), r = (i) => {
528
- const a = i.id;
529
- a && e.set(String(a), i), i.type === "group" && i._objects?.forEach(r);
527
+ const e = /* @__PURE__ */ new Map(), i = this.canvas.getObjects(), r = (s) => {
528
+ const a = s.id;
529
+ a && e.set(String(a), s), s.type === "group" && s._objects?.forEach(r);
530
530
  };
531
- s.forEach(r);
532
- const t = (i) => {
533
- const n = i.clipPath?.id;
531
+ i.forEach(r);
532
+ const t = (s) => {
533
+ const n = s.clipPath?.id;
534
534
  if (n && e.has(String(n))) {
535
535
  const c = e.get(String(n));
536
- c.set({ absolutePositioned: !0 }), i.set("clipPath", c), i.dirty = !0;
536
+ c.set({ absolutePositioned: !0 }), s.set("clipPath", c), s.dirty = !0;
537
537
  }
538
- i.type === "group" && i._objects?.forEach(t);
538
+ s.type === "group" && s._objects?.forEach(t);
539
539
  };
540
- s.forEach(t);
540
+ i.forEach(t);
541
541
  }
542
542
  /**
543
543
  * 切换视图,重新渲染画布
544
544
  */
545
- async switchView(e, s, r) {
545
+ async switchView(e, i, r) {
546
546
  if (this.canvas.clear(), r && r.objects && r.objects.length)
547
547
  return await this.textProcessor.preloadFontsFromState(r), new Promise((t) => {
548
548
  this.canvas.loadFromJSON(
549
549
  r,
550
550
  async () => {
551
- this.relinkClipPaths(), await this.renderOverlayImage(e, !0), await this.setBackground(s), r.workspaceMetadata && this._scaleObjectsToWorkspace(r.workspaceMetadata);
552
- const i = this.canvas.getObjects().filter((a) => a.type === "image");
553
- i.length > 0 && await Promise.all(
554
- i.map((a) => new Promise((n) => {
551
+ this.relinkClipPaths(), await this.renderOverlayImage(e, !0), await this.setBackground(i), r.workspaceMetadata && this._scaleObjectsToWorkspace(r.workspaceMetadata);
552
+ const s = this.canvas.getObjects().filter((a) => a.type === "image");
553
+ s.length > 0 && await Promise.all(
554
+ s.map((a) => new Promise((n) => {
555
555
  const c = a.getElement(), o = a.getSrc() || a.originSrc;
556
556
  if (!o) {
557
557
  n();
@@ -563,11 +563,11 @@ class xe {
563
563
  n();
564
564
  }) : n();
565
565
  }))
566
- ), this.canvas.renderAll(), et.emit("design:layerChange"), t();
566
+ ), this.canvas.renderAll(), ht.emit("design:layerChange"), t();
567
567
  },
568
- (i, a) => {
569
- i.clipPath && !r.objects.some((n) => n.id === i.clipPath.id) && (delete a.clipPath, L.util.enlivenObjects(
570
- [i.clipPath],
568
+ (s, a) => {
569
+ s.clipPath && !r.objects.some((n) => n.id === s.clipPath.id) && (delete a.clipPath, L.util.enlivenObjects(
570
+ [s.clipPath],
571
571
  (n) => {
572
572
  const c = n[0];
573
573
  c && (a.set("clipPath", c), a.dirty = !0, this.canvas.requestRenderAll());
@@ -577,7 +577,7 @@ class xe {
577
577
  }
578
578
  );
579
579
  });
580
- await this.renderOverlayImage(e, !0), await this.setBackground(s), r && r.object && await this.imageProcessor.addBitmapImage(r.object);
580
+ await this.renderOverlayImage(e, !0), await this.setBackground(i), r && r.object && await this.imageProcessor.addBitmapImage(r.object);
581
581
  }
582
582
  /**
583
583
  * 半定制固定文本在修改内容/字体后,按 originalWidth/originalHeight 重新计算自适应缩放。
@@ -587,33 +587,33 @@ class xe {
587
587
  * 根据 workspace 尺寸变化,按比例缩放所有对象
588
588
  */
589
589
  _scaleObjectsToWorkspace(e) {
590
- const s = this.workspaceManager.dimension, r = Math.min(
591
- s.width / e.width,
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, g = c >= 0.1 || o >= 0.1;
590
+ const i = this.workspaceManager.dimension, r = Math.min(
591
+ i.width / e.width,
592
+ i.height / e.height
593
+ ), t = e.centerX, s = e.centerY, a = i.center.x, n = i.center.y, c = Math.abs(a - t), o = Math.abs(n - s), m = Math.abs(r - 1) >= 1e-3, g = c >= 0.1 || o >= 0.1;
594
594
  if (!m && !g) return;
595
- const b = this.canvas.getObjects(), h = new Set(b), X = /* @__PURE__ */ new Set(), x = (f) => {
595
+ const P = this.canvas.getObjects(), h = new Set(P), X = /* @__PURE__ */ new Set(), x = (f) => {
596
596
  const u = f.clipPath;
597
597
  u && h.has(u) && X.add(u);
598
598
  };
599
- b.forEach(x);
599
+ P.forEach(x);
600
600
  const A = (f) => {
601
- const u = (f.left || 0) - t, T = (f.top || 0) - i, W = a + u * r, l = n + T * r;
601
+ const u = (f.left || 0) - t, T = (f.top || 0) - s, W = a + u * r, l = n + T * r;
602
602
  f.set({
603
603
  left: W,
604
604
  top: l,
605
605
  scaleX: (f.scaleX || 1) * r,
606
606
  scaleY: (f.scaleY || 1) * r
607
607
  }), f.setCoords(), f.dirty = !0;
608
- }, O = /* @__PURE__ */ new Set(), v = (f) => {
609
- !f.selectable && !X.has(f) || (A(f), O.add(f));
608
+ }, M = /* @__PURE__ */ new Set(), y = (f) => {
609
+ !f.selectable && !X.has(f) || (A(f), M.add(f));
610
610
  };
611
- b.forEach(v);
612
- const E = (f) => {
611
+ P.forEach(y);
612
+ const B = (f) => {
613
613
  const u = f.clipPath;
614
- u && u.absolutePositioned && !h.has(u) && !O.has(u) && (A(u), O.add(u));
614
+ u && u.absolutePositioned && !h.has(u) && !M.has(u) && (A(u), M.add(u));
615
615
  };
616
- b.forEach(E);
616
+ P.forEach(B);
617
617
  }
618
618
  /**
619
619
  * 计算对象相对于画布的全局变换矩阵(包括父组的影响)
@@ -625,10 +625,10 @@ class xe {
625
625
  * 判断对象是否位于 activeSelection 中
626
626
  */
627
627
  isInActiveSelection(e) {
628
- let s = e.group;
629
- for (; s; ) {
630
- if (s.type === "activeSelection") return !0;
631
- s = s.group;
628
+ let i = e.group;
629
+ for (; i; ) {
630
+ if (i.type === "activeSelection") return !0;
631
+ i = i.group;
632
632
  }
633
633
  return !1;
634
634
  }
@@ -638,12 +638,12 @@ class xe {
638
638
  * @param img fabric.Image 对象
639
639
  * @param blobUrl 可选的 blob URL(用于撤销/重做)
640
640
  */
641
- registerImageCache(e, s, r) {
641
+ registerImageCache(e, i, r) {
642
642
  if (!e || e.startsWith("data:")) return;
643
- const t = s.getElement(), i = this.imageCache.get(e);
643
+ const t = i.getElement(), s = this.imageCache.get(e);
644
644
  this.imageCache.set(e, {
645
645
  element: t,
646
- blobUrl: r || i?.blobUrl,
646
+ blobUrl: r || s?.blobUrl,
647
647
  lastUsed: Date.now()
648
648
  });
649
649
  }
@@ -674,30 +674,30 @@ class xe {
674
674
  async getCachedDataURL(e) {
675
675
  if (!e)
676
676
  return "";
677
- const s = this.imageCache.get(e);
678
- if (s?.element && s.element.complete) {
677
+ const i = this.imageCache.get(e);
678
+ if (i?.element && i.element.complete) {
679
679
  const r = document.createElement("canvas");
680
- r.width = s.element.naturalWidth || s.element.width, r.height = s.element.naturalHeight || s.element.height;
680
+ r.width = i.element.naturalWidth || i.element.width, r.height = i.element.naturalHeight || i.element.height;
681
681
  const t = r.getContext("2d");
682
682
  if (t) {
683
- t.drawImage(s.element, 0, 0);
684
- const i = r.toDataURL("image/png");
685
- return r.width = 0, r.height = 0, i;
683
+ t.drawImage(i.element, 0, 0);
684
+ const s = r.toDataURL("image/png");
685
+ return r.width = 0, r.height = 0, s;
686
686
  }
687
687
  return "";
688
688
  }
689
- return await Ne(e);
689
+ return await tt(e);
690
690
  }
691
691
  /**
692
692
  * 从缓存克隆图片,避免重复下载
693
693
  */
694
- async cloneImageFromCache(e, s) {
695
- const r = e.getSrc() || "", t = e.originSrc || "", i = e.isCropped, a = t || r;
694
+ async cloneImageFromCache(e, i) {
695
+ const r = e.getSrc() || "", t = e.originSrc || "", s = e.isCropped, a = t || r;
696
696
  if (a.startsWith("data:"))
697
697
  return new Promise((c) => {
698
698
  e.clone(
699
699
  (o) => {
700
- o.set(s), c(o);
700
+ o.set(i), c(o);
701
701
  },
702
702
  ["absolutePositioned"]
703
703
  );
@@ -707,19 +707,19 @@ class xe {
707
707
  const o = new L.Image(n.element, {
708
708
  width: e.width,
709
709
  height: e.height,
710
- ...s
710
+ ...i
711
711
  });
712
712
  if (e.clipPath)
713
713
  try {
714
- const m = await J(e.clipPath, ["absolutePositioned"]);
714
+ const m = await G(e.clipPath, ["absolutePositioned"]);
715
715
  o.set({ clipPath: m });
716
716
  } catch {
717
717
  }
718
- i && (o.isCropped = !0, o.cropBlob = e.cropBlob), c(o);
718
+ s && (o.isCropped = !0, o.cropBlob = e.cropBlob), c(o);
719
719
  }) : new Promise((c) => {
720
720
  e.clone(
721
721
  (o) => {
722
- this.registerImageCache(a, o), o.set(s), i && (o.isCropped = !0, o.cropBlob = e.cropBlob), c(o);
722
+ this.registerImageCache(a, o), o.set(i), s && (o.isCropped = !0, o.cropBlob = e.cropBlob), c(o);
723
723
  },
724
724
  ["absolutePositioned"]
725
725
  );
@@ -733,25 +733,25 @@ class xe {
733
733
  * overlay and selection controls, capture the existing lower canvas, and
734
734
  * scale only the printable workspace to the requested longest edge.
735
735
  */
736
- async exportPreviewBitmap(e = 600, s) {
736
+ async exportPreviewBitmap(e = 600, i) {
737
737
  if (this.destroyed) throw new Error("Canvas is not ready");
738
- const r = this.workspaceManager.dimension, t = this.workspaceManager.printAreaSize?.width ?? r.width, i = this.workspaceManager.printAreaSize?.height ?? r.height;
739
- if (!r.width || !r.height || !t || !i)
738
+ const r = this.workspaceManager.dimension, t = this.workspaceManager.printAreaSize?.width ?? r.width, s = this.workspaceManager.printAreaSize?.height ?? r.height;
739
+ if (!r.width || !r.height || !t || !s)
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(), g = this.canvas.overlayImage?.visible, b = this.canvas.backgroundColor, h = this.canvas.getActiveObject(), X = h ? { hasBorders: h.hasBorders, hasControls: h.hasControls } : null;
741
+ const a = Math.max(t, s), n = Math.max(1, e) / a, c = Math.max(1, Math.round(t * n)), o = Math.max(1, Math.round(s * n)), m = this.canvas.viewportTransform?.slice(), g = this.canvas.overlayImage?.visible, P = 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), h?.set({ hasBorders: !1, hasControls: !1 }), this.canvas.backgroundColor = s || "transparent", this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0], this.canvas.renderAll();
743
+ this.canvas.overlayImage && (this.canvas.overlayImage.visible = !1), h?.set({ hasBorders: !1, hasControls: !1 }), this.canvas.backgroundColor = i || "transparent", this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0], this.canvas.renderAll();
744
744
  const x = document.createElement("canvas");
745
745
  x.width = c, x.height = o;
746
746
  const A = x.getContext("2d", { alpha: !0 });
747
747
  if (!A) throw new Error("Could not create preview canvas context");
748
- const O = this.canvas, v = O.getRetinaScaling?.() ?? window.devicePixelRatio ?? 1;
748
+ const M = this.canvas, y = M.getRetinaScaling?.() ?? window.devicePixelRatio ?? 1;
749
749
  A.drawImage(
750
- O.lowerCanvasEl,
751
- r.left * v,
752
- r.top * v,
753
- r.width * v,
754
- r.height * v,
750
+ M.lowerCanvasEl,
751
+ r.left * y,
752
+ r.top * y,
753
+ r.width * y,
754
+ r.height * y,
755
755
  0,
756
756
  0,
757
757
  c,
@@ -763,7 +763,7 @@ class xe {
763
763
  x.width = 0, x.height = 0;
764
764
  }
765
765
  } finally {
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();
766
+ this.canvas.backgroundColor = P, 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
  /**
@@ -772,9 +772,9 @@ class xe {
772
772
  * @param {String?} color 背景颜色
773
773
  * @returns {Promise<string[]>} SVG 字符串
774
774
  */
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)), g = Math.max(m, Math.min(o, Math.ceil(c * n)));
777
- let b = new L.Rect({
775
+ async export(e = !1, i, r) {
776
+ const t = this.workspaceManager.dimension, s = this.workspaceManager.printAreaSize?.width ?? t.width, a = this.workspaceManager.printAreaSize?.height ?? t.height, n = window.devicePixelRatio || 1, c = Math.max(s / 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 P = new L.Rect({
778
778
  left: 0,
779
779
  top: 0,
780
780
  width: t.width,
@@ -782,7 +782,7 @@ class xe {
782
782
  absolutePositioned: !0,
783
783
  strokeWidth: 0
784
784
  });
785
- this.canvas.clipPath && (b = await J(this.canvas.clipPath, ["absolutePositioned"]), b.set({
785
+ this.canvas.clipPath && (P = await G(this.canvas.clipPath, ["absolutePositioned"]), P.set({
786
786
  left: this.canvas.clipPath.left - t.left,
787
787
  top: this.canvas.clipPath.top - t.top,
788
788
  absolutePositioned: !0
@@ -791,17 +791,17 @@ class xe {
791
791
  width: t.width,
792
792
  height: t.height,
793
793
  enableRetinaScaling: !1,
794
- backgroundColor: s || "transparent",
794
+ backgroundColor: i || "transparent",
795
795
  preserveObjectStacking: !0,
796
- clipPath: b
796
+ clipPath: P
797
797
  }), X = this.getLayerList();
798
798
  (await Promise.all(
799
799
  X.map(
800
- (l) => new Promise((k) => {
800
+ (l) => new Promise((_) => {
801
801
  try {
802
- const M = l.sourceType === "svg";
802
+ const O = l.sourceType === "svg";
803
803
  if (l.type === "image") {
804
- const P = l;
804
+ const R = l;
805
805
  let p = {
806
806
  selectable: !1,
807
807
  evented: !1,
@@ -809,14 +809,14 @@ class xe {
809
809
  flipY: l.flipY || !1
810
810
  };
811
811
  if (this.isInActiveSelection(l)) {
812
- const S = this.getGlobalTransformMatrix(l), y = L.util.qrDecompose(S);
812
+ const C = this.getGlobalTransformMatrix(l), v = L.util.qrDecompose(C);
813
813
  p = {
814
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,
815
+ left: (v.translateX || 0) - (t.left || 0),
816
+ top: (v.translateY || 0) - (t.top || 0),
817
+ angle: v.angle || 0,
818
+ scaleX: v.scaleX || 1,
819
+ scaleY: v.scaleY || 1,
820
820
  originX: "center",
821
821
  originY: "center"
822
822
  };
@@ -831,37 +831,37 @@ class xe {
831
831
  originX: "left",
832
832
  originY: "top"
833
833
  };
834
- this.cloneImageFromCache(P, p).then(async (S) => {
835
- if (S.clipPath) {
836
- const y = S.clipPath;
837
- y.absolutePositioned && y.set({
838
- left: (y.left || 0) - t.left,
839
- top: (y.top || 0) - t.top
834
+ this.cloneImageFromCache(R, p).then(async (C) => {
835
+ if (C.clipPath) {
836
+ const v = C.clipPath;
837
+ v.absolutePositioned && v.set({
838
+ left: (v.left || 0) - t.left,
839
+ top: (v.top || 0) - t.top
840
840
  });
841
841
  }
842
- if (e && S.type === "image")
842
+ if (e && C.type === "image")
843
843
  try {
844
- const y = S, I = y.getSrc() || y.originSrc || "";
844
+ const v = C, I = v.getSrc() || v.originSrc || "";
845
845
  if (I) {
846
846
  const q = await this.getCachedDataURL(I);
847
- y.setSrc(q, () => k(S));
847
+ v.setSrc(q, () => _(C));
848
848
  return;
849
849
  }
850
850
  } catch {
851
851
  }
852
- k(S);
852
+ _(C);
853
853
  }).catch(() => {
854
- k(l);
854
+ _(l);
855
855
  });
856
- } else M ? J(l, ["absolutePositioned"]).then((P) => {
856
+ } else O ? G(l, ["absolutePositioned"]).then((R) => {
857
857
  if (this.isInActiveSelection(l)) {
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,
858
+ const C = this.getGlobalTransformMatrix(l), v = L.util.qrDecompose(C);
859
+ R.set({
860
+ left: (v.translateX || 0) - (t.left || 0),
861
+ top: (v.translateY || 0) - (t.top || 0),
862
+ angle: v.angle || 0,
863
+ scaleX: v.scaleX || 1,
864
+ scaleY: v.scaleY || 1,
865
865
  flipX: l.flipX || !1,
866
866
  flipY: l.flipY || !1,
867
867
  selectable: !1,
@@ -870,7 +870,7 @@ class xe {
870
870
  originY: "center"
871
871
  });
872
872
  } else
873
- P.set({
873
+ R.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 xe {
883
883
  originX: l.originX || "left",
884
884
  originY: l.originY || "top"
885
885
  });
886
- const p = P.clipPath;
886
+ const p = R.clipPath;
887
887
  p && p.absolutePositioned && p.set({
888
888
  left: (p.left || 0) - t.left,
889
889
  top: (p.top || 0) - t.top
890
- }), P.setCoords(), P.dirty = !0, k(P);
891
- }).catch(() => k(l)) : l.cloneAsImage(
892
- (P) => {
890
+ }), R.setCoords(), R.dirty = !0, _(R);
891
+ }).catch(() => _(l)) : l.cloneAsImage(
892
+ (R) => {
893
893
  if (this.isInActiveSelection(l)) {
894
- const p = this.getGlobalTransformMatrix(l), S = L.util.qrDecompose(p);
895
- P.set({
896
- left: (S.translateX || 0) - (t.left || 0),
897
- top: (S.translateY || 0) - (t.top || 0),
898
- angle: S.angle || 0,
899
- scaleX: (S.scaleX || 1) / g,
900
- scaleY: (S.scaleY || 1) / g,
894
+ const p = this.getGlobalTransformMatrix(l), C = L.util.qrDecompose(p);
895
+ R.set({
896
+ left: (C.translateX || 0) - (t.left || 0),
897
+ top: (C.translateY || 0) - (t.top || 0),
898
+ angle: C.angle || 0,
899
+ scaleX: (C.scaleX || 1) / g,
900
+ scaleY: (C.scaleY || 1) / g,
901
901
  selectable: !1,
902
902
  hasControls: !1,
903
903
  hasBorders: !1,
@@ -906,7 +906,7 @@ class xe {
906
906
  });
907
907
  } else {
908
908
  const p = l.getBoundingRect(!0, !0);
909
- P.set({
909
+ R.set({
910
910
  left: p.left - t.left,
911
911
  top: p.top - t.top,
912
912
  scaleX: 1 / g,
@@ -919,47 +919,47 @@ class xe {
919
919
  originY: "top"
920
920
  });
921
921
  }
922
- k(P);
922
+ _(R);
923
923
  },
924
924
  { multiplier: g }
925
925
  );
926
926
  } catch {
927
- k(l);
927
+ _(l);
928
928
  }
929
929
  })
930
930
  )
931
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));
932
+ const A = s / t.width, M = a / t.height;
933
+ h.setViewportTransform([A, 0, 0, M, 0, 0]), h.renderAll();
934
+ const y = r?.minOutputSize ?? 1024;
935
+ let B = 1;
936
+ (s > y || a > y) && (B = Math.max(1, y / Math.max(s, a))), typeof r?.outputMultiplierCap == "number" && (B = Math.min(B, r.outputMultiplierCap));
937
937
  let f = "";
938
938
  const u = () => h.toDataURL({
939
939
  format: "webp",
940
940
  quality: r?.quality ?? 0.5,
941
- width: i,
941
+ width: s,
942
942
  height: a,
943
- multiplier: E
943
+ multiplier: B
944
944
  }), T = r?.preferImageBitmap ?? !0, W = r?.returnBlobUrl ?? !1;
945
945
  if (T && window.createImageBitmap && typeof h.toCanvasElement == "function") {
946
- const l = h.toCanvasElement(E, { width: i, height: a });
946
+ const l = h.toCanvasElement(B, { width: s, 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
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();
953
+ const l = h.toCanvasElement(B, { width: s, height: a }), _ = await new Promise((O) => l.toBlob(O, "image/webp", r?.quality ?? 0.5));
954
+ l.width = 0, l.height = 0, f = _ ? URL.createObjectURL(_) : u();
955
955
  } else
956
956
  f = u();
957
957
  return h.dispose(), f;
958
958
  }
959
959
  }
960
- class rt {
961
- constructor(e, s) {
962
- this.onBusy = e, this.onIdle = s, this.pending = null, this.running = !1;
960
+ class dt {
961
+ constructor(e, i) {
962
+ this.onBusy = e, this.onIdle = i, this.pending = null, this.running = !1;
963
963
  }
964
964
  get active() {
965
965
  return this.running;
@@ -982,19 +982,19 @@ class rt {
982
982
  }
983
983
  }
984
984
  }
985
- class st {
986
- constructor(e = 32 * 1024 * 1024, s = 4, r) {
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();
985
+ class ft {
986
+ constructor(e = 32 * 1024 * 1024, i = 4, r) {
987
+ this.budget = e, this.concurrency = i, this.onEvict = r, this.entries = /* @__PURE__ */ new Map(), this.bytes = 0, this.active = 0, this.waiting = [], this.pinned = /* @__PURE__ */ new Set();
988
988
  }
989
989
  setPinnedSources(e) {
990
- this.pinned = new Set(e), this.waiting.forEach((s) => {
991
- s.foreground = this.pinned.has(s.source);
992
- }), this.waiting.sort((s, r) => Number(r.foreground) - Number(s.foreground)), this.trim();
990
+ this.pinned = new Set(e), this.waiting.forEach((i) => {
991
+ i.foreground = this.pinned.has(i.source);
992
+ }), this.waiting.sort((i, r) => Number(r.foreground) - Number(i.foreground)), this.trim();
993
993
  }
994
994
  trim() {
995
- for (const [e, s] of this.entries) {
995
+ for (const [e, i] of this.entries) {
996
996
  if (this.bytes <= this.budget) break;
997
- !s.bytes || this.pinned.has(e) || (this.entries.delete(e), this.bytes -= s.bytes, this.onEvict?.(e));
997
+ !i.bytes || this.pinned.has(e) || (this.entries.delete(e), this.bytes -= i.bytes, this.onEvict?.(e));
998
998
  }
999
999
  }
1000
1000
  clear() {
@@ -1003,19 +1003,19 @@ class st {
1003
1003
  this.entries.clear(), this.pinned.clear(), this.bytes = 0;
1004
1004
  }
1005
1005
  promote(e) {
1006
- const s = this.waiting.findIndex((i) => i.source === e && !i.foreground);
1007
- if (s < 0) return;
1008
- const [r] = this.waiting.splice(s, 1);
1006
+ const i = this.waiting.findIndex((s) => s.source === e && !s.foreground);
1007
+ if (i < 0) return;
1008
+ const [r] = this.waiting.splice(i, 1);
1009
1009
  r.foreground = !0;
1010
- const t = this.waiting.findIndex((i) => !i.foreground);
1010
+ const t = this.waiting.findIndex((s) => !s.foreground);
1011
1011
  this.waiting.splice(t < 0 ? this.waiting.length : t, 0, r);
1012
1012
  }
1013
- async fetchBlob(e, s) {
1013
+ async fetchBlob(e, i) {
1014
1014
  await new Promise((r, t) => {
1015
- const i = () => {
1015
+ const s = () => {
1016
1016
  this.active += 1, r();
1017
1017
  };
1018
- this.active < this.concurrency ? i() : (this.waiting.push({ source: e, foreground: !1, start: i, cancel: () => t(new Error("Resource cache was released")) }), s && this.promote(e));
1018
+ this.active < this.concurrency ? s() : (this.waiting.push({ source: e, foreground: !1, start: s, cancel: () => t(new Error("Resource cache was released")) }), i && this.promote(e));
1019
1019
  });
1020
1020
  try {
1021
1021
  const r = await fetch(e);
@@ -1025,30 +1025,30 @@ class st {
1025
1025
  this.active -= 1, this.waiting.shift()?.start();
1026
1026
  }
1027
1027
  }
1028
- load(e, s = !0) {
1028
+ load(e, i = !0) {
1029
1029
  const r = this.entries.get(e);
1030
1030
  if (r)
1031
- return this.entries.delete(e), this.entries.set(e, r), s && this.promote(e), r.ready;
1032
- const t = { ready: this.fetchBlob(e, s), bytes: 0 };
1033
- return this.entries.set(e, t), t.ready.then((i) => {
1034
- this.entries.get(e) === t && (t.bytes = i.size, this.bytes += t.bytes, this.trim());
1031
+ return this.entries.delete(e), this.entries.set(e, r), i && this.promote(e), r.ready;
1032
+ const t = { ready: this.fetchBlob(e, i), bytes: 0 };
1033
+ return this.entries.set(e, t), t.ready.then((s) => {
1034
+ this.entries.get(e) === t && (t.bytes = s.size, this.bytes += t.bytes, this.trim());
1035
1035
  }).catch(() => {
1036
1036
  this.entries.get(e) === t && this.entries.delete(e);
1037
1037
  }), t.ready;
1038
1038
  }
1039
1039
  }
1040
- class Me {
1040
+ class Be {
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 st(32 * 1024 * 1024, 4, (e) => {
1043
- const s = this.urls.get(e);
1044
- s && URL.revokeObjectURL(s), this.urls.delete(e);
1042
+ this.urls = /* @__PURE__ */ new Map(), this.disposed = !1, this.current = /* @__PURE__ */ new Set(), this.holds = /* @__PURE__ */ new Map(), this.cache = new ft(32 * 1024 * 1024, 4, (e) => {
1043
+ const i = this.urls.get(e);
1044
+ i && URL.revokeObjectURL(i), this.urls.delete(e);
1045
1045
  });
1046
1046
  }
1047
1047
  key(e) {
1048
1048
  return new URL(e, document.baseURI).href;
1049
1049
  }
1050
1050
  sources(e) {
1051
- return e.filter((s) => s && !s.startsWith("data:") && !s.startsWith("blob:")).map((s) => this.key(s));
1051
+ return e.filter((i) => i && !i.startsWith("data:") && !i.startsWith("blob:")).map((i) => this.key(i));
1052
1052
  }
1053
1053
  updatePins() {
1054
1054
  this.cache.setPinnedSources([...this.current, ...this.holds.keys()]);
@@ -1057,62 +1057,62 @@ class Me {
1057
1057
  this.current = new Set(this.sources(e)), this.updatePins();
1058
1058
  }
1059
1059
  hold(e) {
1060
- const s = new Set(this.sources(e));
1061
- return s.forEach((r) => this.holds.set(r, (this.holds.get(r) ?? 0) + 1)), this.updatePins(), () => {
1062
- s.forEach((r) => {
1060
+ const i = new Set(this.sources(e));
1061
+ return i.forEach((r) => this.holds.set(r, (this.holds.get(r) ?? 0) + 1)), this.updatePins(), () => {
1062
+ i.forEach((r) => {
1063
1063
  const t = (this.holds.get(r) ?? 1) - 1;
1064
1064
  t ? this.holds.set(r, t) : this.holds.delete(r);
1065
1065
  }), this.updatePins();
1066
1066
  };
1067
1067
  }
1068
- async preload(e, s = !1) {
1069
- await Promise.all([...new Set(this.sources(e))].map((r) => this.cache.load(r, s)));
1068
+ async preload(e, i = !1) {
1069
+ await Promise.all([...new Set(this.sources(e))].map((r) => this.cache.load(r, i)));
1070
1070
  }
1071
1071
  async url(e) {
1072
1072
  if (!e || e.startsWith("data:") || e.startsWith("blob:")) return e;
1073
- const s = this.key(e), r = await this.cache.load(s, !0);
1073
+ const i = this.key(e), r = await this.cache.load(i, !0);
1074
1074
  if (this.disposed) throw new Error("Resource session was released");
1075
- let t = this.urls.get(s);
1076
- return t || (t = URL.createObjectURL(r), this.urls.set(s, t)), t;
1075
+ let t = this.urls.get(i);
1076
+ return t || (t = URL.createObjectURL(r), this.urls.set(i, t)), t;
1077
1077
  }
1078
1078
  async acquire(e) {
1079
- const s = this.hold(e);
1079
+ const i = this.hold(e);
1080
1080
  try {
1081
- return { urls: Object.fromEntries(await Promise.all([...new Set(e.filter(Boolean))].map(async (t) => [t, await this.url(t)]))), release: s };
1081
+ return { urls: Object.fromEntries(await Promise.all([...new Set(e.filter(Boolean))].map(async (t) => [t, await this.url(t)]))), release: i };
1082
1082
  } catch (r) {
1083
- throw s(), r;
1083
+ throw i(), r;
1084
1084
  }
1085
1085
  }
1086
1086
  dispose() {
1087
1087
  this.disposed = !0, this.cache.clear();
1088
1088
  }
1089
1089
  }
1090
- function ge(d) {
1091
- const e = /* @__PURE__ */ new Set(), s = (r) => {
1090
+ function ve(d) {
1091
+ const e = /* @__PURE__ */ new Set(), i = (r) => {
1092
1092
  if (!r || typeof r != "object") return;
1093
1093
  if (Array.isArray(r)) {
1094
- r.forEach(s);
1094
+ r.forEach(i);
1095
1095
  return;
1096
1096
  }
1097
1097
  const t = r;
1098
- typeof t.src == "string" && t.src && e.add(t.src), typeof t.sourcePath == "string" && /^(https?:|\/)/.test(t.sourcePath) && e.add(t.sourcePath), Object.values(t).forEach(s);
1098
+ typeof t.src == "string" && t.src && e.add(t.src), typeof t.sourcePath == "string" && /^(https?:|\/)/.test(t.sourcePath) && e.add(t.sourcePath), Object.values(t).forEach(i);
1099
1099
  };
1100
- return s(d), [...e];
1100
+ return i(d), [...e];
1101
1101
  }
1102
- async function Ye(d, e) {
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
- if (!i || typeof i != "object") return;
1105
- if (Array.isArray(i)) {
1106
- i.forEach(t);
1102
+ async function Ee(d, e) {
1103
+ const i = JSON.parse(JSON.stringify(d)), r = new Map(await Promise.all(ve(i).map(async (s) => [s, await e.url(s)]))), t = (s) => {
1104
+ if (!s || typeof s != "object") return;
1105
+ if (Array.isArray(s)) {
1106
+ s.forEach(t);
1107
1107
  return;
1108
1108
  }
1109
- const a = i;
1109
+ const a = s;
1110
1110
  typeof a.src == "string" && (a.src = r.get(a.src) ?? a.src, a.originSrc && (a.originSrc = a.src)), typeof a.sourcePath == "string" && (a.sourcePath = r.get(a.sourcePath) ?? a.sourcePath), Object.values(a).forEach(t);
1111
1111
  };
1112
- return t(s), s;
1112
+ return t(i), i;
1113
1113
  }
1114
- function it(d, e, s) {
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) => {
1114
+ function gt(d, e, i) {
1115
+ const r = JSON.parse(JSON.stringify(d)), t = new Map(Object.entries(e.urls).map(([n, c]) => [c, n])), s = /* @__PURE__ */ new Map(), a = (n, c) => {
1116
1116
  if (!n || typeof n != "object") return;
1117
1117
  if (Array.isArray(n)) {
1118
1118
  n.forEach((m) => a(m, c));
@@ -1121,204 +1121,207 @@ function it(d, e, s) {
1121
1121
  const o = n;
1122
1122
  c(o), Object.values(o).forEach((m) => a(m, c));
1123
1123
  };
1124
- return a(s, (n) => {
1125
- n.id !== void 0 && i.set(String(n.id), n);
1124
+ return a(i, (n) => {
1125
+ n.id !== void 0 && s.set(String(n.id), n);
1126
1126
  }), a(r, (n) => {
1127
- const c = n.id !== void 0 ? i.get(String(n.id)) : void 0;
1127
+ const c = n.id !== void 0 ? s.get(String(n.id)) : void 0;
1128
1128
  for (const o of ["src", "originSrc", "sourcePath"])
1129
1129
  typeof n[o] == "string" && (c && typeof c[o] == "string" ? n[o] = c[o] : n[o] = t.get(n[o]) ?? n[o]);
1130
1130
  }), r;
1131
1131
  }
1132
- function Z(d) {
1132
+ function $(d) {
1133
1133
  return d.designKey || d.area?.name || d.name;
1134
1134
  }
1135
- function de(d, e, s) {
1136
- const r = e[Z(d)]?.color;
1137
- return s ?? (typeof r == "string" ? r : void 0);
1135
+ function me(d, e, i) {
1136
+ const r = e[$(d)]?.color;
1137
+ return i ?? (typeof r == "string" ? r : void 0);
1138
1138
  }
1139
- function Xe(d, e, s) {
1140
- return s ?? d.render_areas.filter((r) => r.design).map((r) => e[Z(r)]?.color).find((r) => typeof r == "string");
1139
+ function Ue(d, e, i) {
1140
+ return i ?? d.render_areas.filter((r) => r.design).map((r) => e[$(r)]?.color).find((r) => typeof r == "string");
1141
1141
  }
1142
- function fe(d, e, s, r = !0, t = "global") {
1142
+ function we(d, e, i, r = !0, t = "global") {
1143
1143
  if (!r) return d.render_areas;
1144
- const i = t === "global" ? Xe(d, e, s) : void 0;
1144
+ const s = t === "global" ? Ue(d, e, i) : void 0;
1145
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));
1146
+ const n = e[$(a)], c = t === "placement" ? me(a, e, i) : s;
1147
+ return je({ design: a.design, defaultPrintColor: pe(a.defaultPrintColor, a.area?.defaultPrintColor, d.defaultPrintColor) }, c, !!(a.area && Array.isArray(n?.objects) && n.objects.length));
1148
1148
  });
1149
1149
  }
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
+ function Xe(d, e, i, r = !0, t = "global") {
1151
+ return we(d, e, i, r, t).flatMap((s) => {
1152
+ const a = e[$(s)];
1153
+ return [s.image, ...s.design && s.area && Array.isArray(a?.objects) && a.objects.length ? [s.area.image, ...ve(a)] : []];
1154
1154
  }).filter(Boolean);
1155
1155
  }
1156
- function nt(d) {
1156
+ function pt(d) {
1157
1157
  return d.render_areas.find((e) => e.name === "bg")?.image || d.image || "";
1158
1158
  }
1159
- function at(d, e) {
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);
1159
+ function mt(d, e) {
1160
+ const i = d.render_areas.find((t) => t.name === "bg") ?? d.render_areas.find((t) => !t.design), r = Math.max(i?.width ?? 0, i?.height ?? 0);
1161
1161
  return Math.max(1, Math.min(768, Math.round(r ? r * e : 600)));
1162
1162
  }
1163
- function ue(d) {
1163
+ function ge(d) {
1164
1164
  if (typeof d != "string") {
1165
1165
  d.close();
1166
1166
  return;
1167
1167
  }
1168
1168
  d.startsWith("blob:") && URL.revokeObjectURL(d);
1169
1169
  }
1170
- const Rt = qe(
1170
+ const Bt = Ge(
1171
1171
  function({
1172
1172
  render: e,
1173
- designData: s,
1173
+ designData: i,
1174
1174
  enabled: r = !0,
1175
1175
  preloadSources: t,
1176
- preloadDesignData: i,
1176
+ preloadDesignData: s,
1177
1177
  onAssetReady: a,
1178
1178
  backgroundColor: n,
1179
1179
  colorMode: c = "global",
1180
1180
  scale: o = 0.8,
1181
1181
  renderer: m = "pixel-map",
1182
1182
  className: g,
1183
- style: b,
1183
+ style: P,
1184
1184
  alt: h = "Product preview",
1185
1185
  onLoadingChange: X,
1186
1186
  onRendered: x,
1187
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 });
1188
+ }, M) {
1189
+ const y = S(null), B = S(null), f = S(null), u = S(null), T = S(null), W = S(void 0), l = S(null), _ = S(null), O = S(0), R = S(/* @__PURE__ */ new Map()), p = S(null), C = S(0), v = S(!1), I = S(!1), q = S({ onLoadingChange: X, onRendered: x, onError: A, onAssetReady: a });
1190
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);
1195
- }, []), ie = N(() => {
1191
+ const Y = m === "pixel-map" && Ye.isSupported(), se = S(Y);
1192
+ se.current = Y;
1193
+ const [j, k] = Z(""), [ne, Te] = Z(!1), [Le, We] = Z(""), [qe, he] = Z(!1), ue = Qe(Ze(e).render_areas), J = N(() => (T.current ??= new Be(), T.current), []), ee = N((w) => {
1194
+ Te(w), q.current.onLoadingChange?.(w);
1195
+ }, []), ae = N(() => {
1196
1196
  if (f.current) return f.current;
1197
- if (!v.current || !E.current) return null;
1197
+ if (!y.current || !B.current) return null;
1198
1198
  const w = 800;
1199
- return v.current.width = w, v.current.height = w, f.current = new xe(
1200
- v.current,
1199
+ return y.current.width = w, y.current.height = w, f.current = new Ie(
1200
+ y.current,
1201
1201
  { width: w, height: w },
1202
- E.current,
1202
+ B.current,
1203
1203
  0.85
1204
1204
  ), f.current;
1205
- }, []), pe = N(async () => {
1205
+ }, []), ye = N(async () => {
1206
1206
  if (u.current) return u.current;
1207
- if (Y) u.current = new ke();
1207
+ if (Y) u.current = new Ye();
1208
1208
  else {
1209
1209
  const { StickerPlugin: w } = await import("./renderer/sticker.js");
1210
- if (I.current || re.current !== Y) return null;
1210
+ if (I.current || se.current !== Y) return null;
1211
1211
  if (u.current) return u.current;
1212
1212
  u.current = new w({ width: 1, height: 1 }, !0, { subdiv: 8 });
1213
1213
  }
1214
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(
1218
- () => $(!0),
1215
+ }, [Y]), ce = N(() => {
1216
+ f.current?.destroy(), f.current = null, u.current?.destroy(), u.current = null, T.current?.dispose(), T.current = null, W.current = void 0, R.current.forEach(({ texture: w }) => ge(w)), R.current.clear(), _.current && URL.revokeObjectURL(_.current), _.current = null, l.current = null;
1217
+ }, []), be = N(() => (p.current || (p.current = new dt(
1218
+ () => ee(!0),
1219
1219
  () => {
1220
- I.current ? ne() : $(!1);
1220
+ I.current ? ce() : ee(!1);
1221
1221
  }
1222
- )), p.current), [ne, $]), ae = N(() => {
1223
- const w = ++M.current, Q = S.current;
1224
- me().enqueue(async () => {
1225
- let D;
1222
+ )), p.current), [ce, ee]), te = N(() => {
1223
+ const w = ++O.current, K = C.current;
1224
+ be().enqueue(async () => {
1225
+ let F;
1226
1226
  try {
1227
- if (I.current || w !== M.current) return;
1228
- const U = ie();
1229
- y.current && (u.current?.destroy(), u.current = null, y.current = !1);
1230
- const V = await pe();
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(() => {
1227
+ if (I.current || w !== O.current) return;
1228
+ he(!1);
1229
+ const U = ae();
1230
+ v.current && (u.current?.destroy(), u.current = null, v.current = !1);
1231
+ const V = await ye();
1232
+ if (!U || !V || I.current || w !== O.current) return;
1233
+ const z = J();
1234
+ F = z.hold(Xe(e, i, n, Y, c));
1235
+ const Ce = we(e, i, n, Y, c), Se = c === "global" ? Ue(e, i, n) : n, ze = e.render_areas.filter((b) => !!b.design), oe = mt(e, o), Re = Promise.all(Ce.map(async (b) => [b.image, await z.url(b.image)]));
1236
+ Re.catch(() => {
1236
1237
  });
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));
1238
+ for (const b of ze) {
1239
+ const D = $(b), E = i[D], Q = c === "placement" ? me(b, i, n) ?? "" : typeof E?.color == "string" ? E.color : "", fe = pe(b.defaultPrintColor, b.area?.defaultPrintColor, e.defaultPrintColor), _e = fe ? "" : Q, De = !fe && c === "placement" && !Y && n === void 0 && !!Q;
1240
+ if (!b.area || (!Array.isArray(E?.objects) || !E.objects.length) && !De) {
1241
+ const re = R.current.get(D);
1242
+ re && (ge(re.texture), R.current.delete(D));
1242
1243
  continue;
1243
1244
  }
1244
- const Pe = JSON.stringify([
1245
- Q,
1246
- ce,
1247
- _.area.id,
1248
- _.area.image,
1249
- B,
1245
+ const Me = JSON.stringify([
1246
+ K,
1247
+ oe,
1248
+ b.area.id,
1249
+ b.area.image,
1250
+ E,
1250
1251
  c,
1251
- G
1252
+ Q,
1253
+ fe
1252
1254
  ]);
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)
1255
+ if (R.current.get(D)?.fingerprint === Me) continue;
1256
+ const [Ne, Ve] = await Promise.all([
1257
+ z.url(b.area.image),
1258
+ Ee(E, z)
1257
1259
  ]);
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, {
1260
- minOutputSize: ce,
1260
+ if (I.current || w !== O.current || (await U.switchView({ ...b.area, image: Ne }, Q, Ve), I.current || w !== O.current)) return;
1261
+ const xe = typeof createImageBitmap == "function" ? await U.exportPreviewBitmap(oe, _e) : await U.export(!1, _e, {
1262
+ minOutputSize: oe,
1261
1263
  preferImageBitmap: !1,
1262
1264
  returnBlobUrl: !1,
1263
1265
  outputMultiplierCap: 1,
1264
1266
  quality: 0.72
1265
1267
  });
1266
- if (Se) {
1267
- const j = P.current.get(F);
1268
- j && ue(j.texture), P.current.set(F, { fingerprint: Pe, texture: Se });
1268
+ if (xe) {
1269
+ const re = R.current.get(D);
1270
+ re && ge(re.texture), R.current.set(D, { fingerprint: Me, texture: xe });
1269
1271
  }
1270
- if (I.current || w !== M.current) return;
1272
+ if (I.current || w !== O.current) return;
1271
1273
  }
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;
1274
+ const Fe = new Map(await Re);
1275
+ if (I.current || w !== O.current) return;
1276
+ const ke = Ce.map((b) => {
1277
+ const D = b.design ? R.current.get($(b))?.texture : void 0, E = b.texture_transform, Q = typeof E?.blendMode == "number" ? E.blendMode : typeof E?.blendMode == "string" ? Ke[E.blendMode.toLowerCase()] : void 0;
1276
1278
  return {
1277
- ..._,
1278
- image: Ue.get(_.image) ?? _.image,
1279
- texture: F,
1280
- color: c === "placement" && _.design ? de(_, s) : void 0,
1279
+ ...b,
1280
+ defaultPrintColor: pe(b.defaultPrintColor, b.area?.defaultPrintColor, e.defaultPrintColor),
1281
+ image: Fe.get(b.image) ?? b.image,
1282
+ texture: D,
1283
+ color: c === "placement" && b.design ? me(b, i) : void 0,
1281
1284
  // PixelMapRenderer consumes the source blend-mode string; Pixi
1282
1285
  // still receives its enum value exactly as before.
1283
- config: B ? Y ? { ...B } : { ...B, blendMode: G } : void 0
1286
+ config: E ? Y ? { ...E } : { ...E, blendMode: Q } : void 0
1284
1287
  };
1285
- }), oe = Y ? await V.onOffscreenRender(Ce, {
1286
- color: ye,
1287
- targetSize: ce,
1288
+ }), le = Y ? await V.onOffscreenRender(ke, {
1289
+ color: Se,
1290
+ targetSize: oe,
1288
1291
  quality: 0.85,
1289
1292
  format: "image/png",
1290
1293
  cacheKey: e.id
1291
- }) : await V.onOffscreenRender(Ce, {
1292
- color: ye,
1294
+ }) : await (await import("./pixi-print-base-CKs4lF7h.js")).renderPixiWithPrintBase(V, ke, {
1295
+ color: Se,
1293
1296
  cleanCache: !1,
1294
1297
  scale: o,
1295
1298
  quality: 0.85
1296
1299
  });
1297
- if (I.current || w !== M.current) return;
1298
- if (!oe) throw new Error("Could not render the product preview");
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 });
1300
+ if (I.current || w !== O.current) return;
1301
+ if (!le) throw new Error("Could not render the product preview");
1302
+ const de = URL.createObjectURL(le);
1303
+ _.current && URL.revokeObjectURL(_.current), l.current = le, _.current = de, k(de), q.current.onRendered?.({ renderId: e.id, blob: le, url: de });
1301
1304
  } catch (U) {
1302
- !I.current && w === M.current && q.current.onError?.(U instanceof Error ? U : new Error("Could not render the product preview"));
1305
+ !I.current && w === O.current && (he(!0), q.current.onError?.(U instanceof Error ? U : new Error("Could not render the product preview")));
1303
1306
  } finally {
1304
- D?.();
1307
+ F?.();
1305
1308
  }
1306
1309
  });
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(() => {
1310
+ }, [n, c, i, ae, be, ye, J, e, o, Y]);
1311
+ ie(() => (I.current = !1, () => {
1312
+ I.current = !0, O.current += 1, p.current?.clear(), p.current?.active || ce();
1313
+ }), [ce]), ie(() => {
1311
1314
  u.current?.destroy(), u.current = null;
1312
- }, [m, Y]), ee(() => {
1313
- const w = K(), Q = i ?? s, D = _e(e, Q, n, Y, c);
1314
- w.pin(D);
1315
+ }, [m, Y]), ie(() => {
1316
+ const w = J(), K = s ?? i, F = Xe(e, K, n, Y, c);
1317
+ w.pin(F);
1315
1318
  let U = !0;
1316
- return w.preload(D, !0).then(async () => {
1319
+ return w.preload(F, !0).then(async () => {
1317
1320
  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);
1321
+ for (const V of we(e, K, n, Y, c).map((z) => z.image).filter(Boolean)) {
1322
+ const z = await w.url(V);
1320
1323
  if (!U) return;
1321
- q.current.onAssetReady?.(V, H), V === nt(e) && Ee(H);
1324
+ q.current.onAssetReady?.(V, z), V === pt(e) && We(z);
1322
1325
  }
1323
1326
  }).catch(() => {
1324
1327
  }).finally(() => {
@@ -1327,91 +1330,93 @@ const Rt = qe(
1327
1330
  }), () => {
1328
1331
  U = !1;
1329
1332
  };
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, () => ({
1333
- acquireResources: (w) => K().acquire(w),
1333
+ }, [n, c, i, s, J, t, e, Y]), ie(() => (r ? te() : ee(!1), () => {
1334
+ O.current += 1, p.current?.clear();
1335
+ }), [r, te, ee]), Je(M, () => ({
1336
+ acquireResources: (w) => J().acquire(w),
1334
1337
  getPreviewBlob: async () => l.current,
1335
1338
  getPreviewUrl: async () => l.current ? URL.createObjectURL(l.current) : null,
1336
1339
  refresh: () => {
1337
- S.current += 1, y.current = !0, r && ae();
1340
+ C.current += 1, v.current = !0, r && te();
1338
1341
  },
1339
- updateText: async (w, Q) => {
1340
- const D = ie();
1341
- return D ? D.updateText(w, Q) : null;
1342
+ updateText: async (w, K) => {
1343
+ const F = ae();
1344
+ return F ? F.updateText(w, K) : null;
1342
1345
  }
1343
- }), [r, ie, K, ae]);
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 }) }) })
1346
+ }), [r, ae, J, te]);
1347
+ const He = () => {
1348
+ C.current += 1, v.current = !0, he(!1), r && te();
1349
+ }, Pe = j || (ue ? "" : Le);
1350
+ return /* @__PURE__ */ Ae("div", { className: g, style: { position: "relative", ...P }, children: [
1351
+ ue ? /* @__PURE__ */ H($e, { image: j, alt: h, loading: ne, failed: qe, onRetry: He }) : Pe && /* @__PURE__ */ H("img", { src: Pe, alt: h, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
1352
+ !ue && ne && /* @__PURE__ */ H("div", { "aria-live": "polite", "aria-label": "Rendering product preview", style: { position: "absolute", inset: 0 } }),
1353
+ /* @__PURE__ */ H("div", { "aria-hidden": "true", style: { position: "absolute", width: 1, height: 1, overflow: "hidden", opacity: 0, pointerEvents: "none" }, children: /* @__PURE__ */ H("div", { ref: B, style: { width: 800, height: 800 }, children: /* @__PURE__ */ H("canvas", { ref: y, width: 800, height: 800 }) }) })
1349
1354
  ] });
1350
1355
  }
1351
1356
  );
1352
- function kt({
1357
+ function Et({
1353
1358
  viewArea: d,
1354
1359
  viewState: e,
1355
- activeObjectId: s,
1360
+ activeObjectId: i,
1356
1361
  onChange: r,
1357
1362
  acquireResources: t,
1358
- onLoadingChange: i,
1363
+ onLoadingChange: s,
1359
1364
  className: a,
1360
1365
  style: n
1361
1366
  }) {
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(() => {
1367
+ const c = S(null), o = S(null), m = S(null), g = S(r), P = S(s), h = S(null), X = S(e), [x, A] = Z(!1), [M, y] = Z("");
1368
+ g.current = r, P.current = s;
1369
+ const B = N(() => {
1365
1370
  const f = m.current;
1366
1371
  if (!f) return;
1367
1372
  const u = f.getRenderedObjects();
1368
- g.current(h.current ? it(u, h.current, X.current) : u);
1373
+ g.current(h.current ? gt(u, h.current, X.current) : u);
1369
1374
  }, []);
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());
1375
+ return ie(() => {
1376
+ let f = !1, u = null, T = !1, W = !1, l = null, _ = null;
1377
+ const O = () => {
1378
+ T || (T = !0, u?.destroy(), m.current === u && (m.current = null), l?.release(), h.current === l && (h.current = null), _?.dispose());
1374
1379
  };
1375
1380
  return (async () => {
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
+ if (P.current?.(!0), await new Promise((k) => requestAnimationFrame(() => k())), f) return;
1382
+ const p = c.current, C = o.current;
1383
+ if (!p || !C) return;
1384
+ const v = p.clientWidth || 400, I = p.clientHeight || 400, q = [d.image, ...ve(e)];
1385
+ if (t ? l = await t(q) : (_ = new Be(), l = await _.acquire(q)), f) return;
1381
1386
  h.current = l;
1382
- const Y = await Ye(e, { url: async (R) => l.urls[R] ?? R });
1387
+ const Y = await Ee(e, { url: async (k) => l.urls[k] ?? k });
1383
1388
  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 = {
1389
+ u = new Ie(C, { width: v, height: I }, p, 0.85), m.current = u, ut(typeof window < "u" && window.innerWidth < 768 ? 16 : 8);
1390
+ const se = {
1386
1391
  ...Y,
1387
1392
  objects: (Array.isArray(Y.objects) ? Y.objects : []).map(
1388
- (R) => R?.selectable === !1 ? { ...R, selectable: !0 } : R
1393
+ (k) => k?.selectable === !1 ? { ...k, selectable: !0 } : k
1389
1394
  )
1390
1395
  };
1391
- if (await u.switchView({ ...d, image: l.urls[d.image] ?? d.image }, typeof e.color == "string" ? e.color : "", re), f) return;
1392
- const se = new Set(
1393
- (Array.isArray(e.objects) ? e.objects : []).filter((R) => R?.customConfig?.moveable === !0).map((R) => String(R.id ?? ""))
1396
+ if (await u.switchView({ ...d, image: l.urls[d.image] ?? d.image }, typeof e.color == "string" ? e.color : "", se), f) return;
1397
+ const j = new Set(
1398
+ (Array.isArray(e.objects) ? e.objects : []).filter((k) => k?.customConfig?.moveable === !0).map((k) => String(k.id ?? ""))
1394
1399
  );
1395
- if (u.canvas.forEachObject((R) => {
1396
- se.has(String(R.id ?? "")) || R.set({ selectable: !1, evented: !1 });
1397
- }), s) {
1398
- const R = u.canvas.getObjects().find((le) => String(le.id ?? "") === String(s));
1399
- R && se.has(String(s)) && u.canvas.setActiveObject(R);
1400
+ if (u.canvas.forEachObject((k) => {
1401
+ j.has(String(k.id ?? "")) || k.set({ selectable: !1, evented: !1 });
1402
+ }), i) {
1403
+ const k = u.canvas.getObjects().find((ne) => String(ne.id ?? "") === String(i));
1404
+ k && j.has(String(i)) && u.canvas.setActiveObject(k);
1400
1405
  }
1401
- u.canvas.on("object:modified", () => E()), u.canvas.requestRenderAll(), await new Promise((R) => requestAnimationFrame(() => R())), f || A(!0);
1406
+ u.canvas.on("object:modified", () => B()), u.canvas.requestRenderAll(), await new Promise((k) => requestAnimationFrame(() => k())), f || A(!0);
1402
1407
  })().catch((p) => {
1403
- f || v(p instanceof Error ? p.message : "Could not load the editor.");
1408
+ f || y(p instanceof Error ? p.message : "Could not load the editor.");
1404
1409
  }).finally(() => {
1405
- W = !0, f && M(), b.current?.(!1);
1410
+ W = !0, f && O(), P.current?.(!1);
1406
1411
  }), () => {
1407
- f = !0, A(!1), W && M();
1412
+ f = !0, A(!1), W && O();
1408
1413
  };
1409
- }, []), /* @__PURE__ */ Oe("div", { className: a, style: { position: "relative", width: "100%", height: "100%", ...n }, children: [
1410
- /* @__PURE__ */ z("div", { ref: c, style: { position: "absolute", inset: 0, overflow: "hidden" }, children: /* @__PURE__ */ z("canvas", { ref: o }) }),
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 }) })
1414
+ }, []), /* @__PURE__ */ Ae("div", { className: a, style: { position: "relative", width: "100%", height: "100%", ...n }, children: [
1415
+ /* @__PURE__ */ H("div", { ref: c, style: { position: "absolute", inset: 0, overflow: "hidden" }, children: /* @__PURE__ */ H("canvas", { ref: o }) }),
1416
+ !x && /* @__PURE__ */ H("div", { style: { position: "absolute", inset: 0, background: "#f2f2f2" }, "aria-label": M ? "Editor failed to load" : "Loading editor", children: M && /* @__PURE__ */ H("span", { role: "alert", children: M }) })
1412
1417
  ] });
1413
1418
  }
1414
1419
  export {
1415
- kt as P,
1416
- Rt as a
1420
+ Et as P,
1421
+ Bt as a
1417
1422
  };