@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.
@@ -1,21 +1,21 @@
1
- import { jsxs as _e, jsx as z } from "react/jsx-runtime";
2
- import { forwardRef as Te, useRef as R, useState as re, useCallback as N, useEffect as te, useImperativeHandle as Le } from "react";
3
- import { LAYER_BLACK_LIST as Se, BLEND_MODES_MAP as We } from "./engine/constants.js";
4
- import { P as Re, r as qe } from "./pixel-map-dSys7UAx.js";
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 He } from "uuid";
7
- import { cloneObject as G, urlToDataURL as ze } from "./engine/utils/common.js";
8
- import { ImageProcessor as De } from "./engine/processors/image.js";
9
- import { TemplateProcessor as Fe } from "./engine/processors/template.js";
10
- import { TextProcessor as Ne } from "./engine/processors/text.js";
11
- import { ResizeManager as Ve } from "./engine/managers/resize.js";
12
- import { loadOverlaySvgImage as Ge, loadImage as Je } from "./engine/utils/image.js";
13
- import { WorkspaceManager as Ke } from "./engine/managers/workspace.js";
14
- import { HistoryManager as Qe } from "./engine/history.js";
15
- import Ze from "./engine/events.js";
16
- import { fabric as U } from "fabric";
17
- import { setDefaultControls as $e } from "./engine/utils/setting.js";
18
- class Me {
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 U.Canvas(e, {
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 De(this), this.templateProcessor = new Fe(this), this.textProcessor = new Ne(this), this.resizeManager = new Ve(this, r), this.workspaceManager = new Ke(this);
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 G(s.image), n = s.clipPath ? await G(s.clipPath) : void 0;
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 Ge(e);
103
+ const r = await Qe(e);
104
104
  this.overlayCache.set(e, r);
105
- const t = await G(r.image), i = r.clipPath ? await G(r.clipPath) : void 0;
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, f = r.top ?? 0, P = r.scaleX ?? 1, u = 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, 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: P * c,
139
- scaleY: u * o,
138
+ scaleX: b * c,
139
+ scaleY: h * o,
140
140
  left: m - n,
141
- top: f - n
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: P,
149
- scaleY: u,
148
+ scaleX: b,
149
+ scaleY: h,
150
150
  left: m,
151
- top: f
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 Je(e);
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: He()
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
- U.util.enlivenObjects([e], (r) => s(r), "");
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 b = o ? t.getCenterPoint() : null;
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 b && t.setPositionByOrigin(b, "center", "center"), t.setCoords(), {
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 f = e?.__semiTargetInfo, P = !!f && typeof f.width == "number" && f.width > 0 && typeof f.height == "number" && f.height > 0 && typeof f.centerX == "number" && typeof f.centerY == "number";
289
- let u;
290
- if (P) {
291
- const b = t.getCenterPoint();
292
- u = {
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 f.centerX == "number" ? f.centerX : b.x,
296
- centerY: typeof f.centerY == "number" ? f.centerY : b.y,
297
- signX: typeof f.signX == "number" && f.signX !== 0 ? Math.sign(f.signX) : Math.sign(i) || 1,
298
- signY: typeof f.signY == "number" && f.signY !== 0 ? Math.sign(f.signY) : Math.sign(a) || 1
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 b = t.getCenterPoint();
302
- u = {
301
+ const v = t.getCenterPoint();
302
+ h = {
303
303
  width: n.originalWidth,
304
304
  height: n.originalHeight,
305
- centerX: b.x,
306
- centerY: b.y,
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: u.signX,
314
- scaleY: u.signY
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 Y = t.getBoundingRect(!0, !0), M = Math.max(1, Y.width || 1), X = Math.max(1, Y.height || 1);
322
- let C = Math.min(u.width / M, u.height / X);
323
- return (!Number.isFinite(C) || C <= 0) && (C = 1), t.set({
324
- scaleX: C * u.signX,
325
- scaleY: C * u.signY
326
- }), t.setPositionByOrigin(new U.Point(u.centerX, u.centerY), "center", "center"), t.setCoords(), {
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: u,
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), f = o * Math.abs(n), P = t.getCenterPoint();
353
- return new Promise((u) => {
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 Y = i.width || 1, M = i.height || 1, X = Math.max(m / Y, f / M);
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: X * Math.sign(a),
359
- scaleY: X * Math.sign(n)
360
- }), i.setPositionByOrigin(P, "center", "center"), i.setCoords(), u({
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: Y,
363
- height: M,
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) => !Se.includes(e.id || ""));
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 U.ActiveSelection(e, { canvas: this.canvas });
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(Qe.DEFAULT_SAVE_PROPERTIES), s = this.workspaceManager.dimension;
506
+ const { objects: e } = this.canvas.toJSON(je.DEFAULT_SAVE_PROPERTIES), s = this.workspaceManager.dimension;
507
507
  return {
508
- objects: e.filter((r) => !Se.includes(r.id || "")),
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(), Ze.emit("design:layerChange"), t();
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, U.util.enlivenObjects(
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, f = c >= 0.1 || o >= 0.1;
594
- if (!m && !f) return;
595
- const P = this.canvas.getObjects(), u = new Set(P), Y = /* @__PURE__ */ new Set(), M = (h) => {
596
- const p = h.clipPath;
597
- p && u.has(p) && Y.add(p);
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
- P.forEach(M);
600
- const X = (h) => {
601
- const p = (h.left || 0) - t, T = (h.top || 0) - i, E = a + p * r, l = n + T * r;
602
- h.set({
603
- left: E,
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: (h.scaleX || 1) * r,
606
- scaleY: (h.scaleY || 1) * r
607
- }), h.setCoords(), h.dirty = !0;
608
- }, C = /* @__PURE__ */ new Set(), b = (h) => {
609
- !h.selectable && !Y.has(h) || (X(h), C.add(h));
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
- P.forEach(b);
612
- const A = (h) => {
613
- const p = h.clipPath;
614
- p && p.absolutePositioned && !u.has(p) && !C.has(p) && (X(p), C.add(p));
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
- P.forEach(A);
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 ze(e);
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 U.Image(n.element, {
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 G(e.clipPath, ["absolutePositioned"]);
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(), f = this.canvas.overlayImage?.visible, P = this.canvas.backgroundColor, u = this.canvas.getActiveObject(), Y = u ? { hasBorders: u.hasBorders, hasControls: u.hasControls } : null;
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), u?.set({ hasBorders: !1, hasControls: !1 }), this.canvas.backgroundColor = s || "transparent", this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0], this.canvas.renderAll();
744
- const M = document.createElement("canvas");
745
- M.width = c, M.height = o;
746
- const X = M.getContext("2d", { alpha: !0 });
747
- if (!X) throw new Error("Could not create preview canvas context");
748
- const C = this.canvas, b = C.getRetinaScaling?.() ?? window.devicePixelRatio ?? 1;
749
- X.drawImage(
750
- C.lowerCanvasEl,
751
- r.left * b,
752
- r.top * b,
753
- r.width * b,
754
- r.height * b,
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(M);
761
+ return await createImageBitmap(x);
762
762
  } finally {
763
- M.width = 0, M.height = 0;
763
+ x.width = 0, x.height = 0;
764
764
  }
765
765
  } finally {
766
- this.canvas.backgroundColor = P, this.canvas.overlayImage && f !== void 0 && (this.canvas.overlayImage.visible = f), u && Y && u.set(Y), m && (this.canvas.viewportTransform = m), this.destroyed || this.canvas.requestRenderAll();
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)), f = Math.max(m, Math.min(o, Math.ceil(c * n)));
777
- let P = new U.Rect({
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 && (P = await G(this.canvas.clipPath, ["absolutePositioned"]), P.set({
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 u = new U.StaticCanvas(null, {
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: P
797
- }), Y = this.getLayerList();
796
+ clipPath: b
797
+ }), X = this.getLayerList();
798
798
  (await Promise.all(
799
- Y.map(
800
- (l) => new Promise((y) => {
799
+ X.map(
800
+ (l) => new Promise((k) => {
801
801
  try {
802
- const I = l.sourceType === "svg";
802
+ const M = l.sourceType === "svg";
803
803
  if (l.type === "image") {
804
- const _ = l;
805
- let v = {
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), g = U.util.qrDecompose(S);
813
- v = {
814
- ...v,
815
- left: (g.translateX || 0) - (t.left || 0),
816
- top: (g.translateY || 0) - (t.top || 0),
817
- angle: g.angle || 0,
818
- scaleX: g.scaleX || 1,
819
- scaleY: g.scaleY || 1,
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
- v = {
825
- ...v,
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(_, v).then(async (S) => {
834
+ this.cloneImageFromCache(P, p).then(async (S) => {
835
835
  if (S.clipPath) {
836
- const g = S.clipPath;
837
- g.absolutePositioned && g.set({
838
- left: (g.left || 0) - t.left,
839
- top: (g.top || 0) - t.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 g = S, L = g.getSrc() || g.originSrc || "";
845
- if (L) {
846
- const O = await this.getCachedDataURL(L);
847
- g.setSrc(O, () => y(S));
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
- y(S);
852
+ k(S);
853
853
  }).catch(() => {
854
- y(l);
854
+ k(l);
855
855
  });
856
- } else I ? G(l, ["absolutePositioned"]).then((_) => {
856
+ } else M ? J(l, ["absolutePositioned"]).then((P) => {
857
857
  if (this.isInActiveSelection(l)) {
858
- const S = this.getGlobalTransformMatrix(l), g = U.util.qrDecompose(S);
859
- _.set({
860
- left: (g.translateX || 0) - (t.left || 0),
861
- top: (g.translateY || 0) - (t.top || 0),
862
- angle: g.angle || 0,
863
- scaleX: g.scaleX || 1,
864
- scaleY: g.scaleY || 1,
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
- _.set({
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 v = _.clipPath;
887
- v && v.absolutePositioned && v.set({
888
- left: (v.left || 0) - t.left,
889
- top: (v.top || 0) - t.top
890
- }), _.setCoords(), _.dirty = !0, y(_);
891
- }).catch(() => y(l)) : l.cloneAsImage(
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 v = this.getGlobalTransformMatrix(l), S = U.util.qrDecompose(v);
895
- _.set({
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) / f,
900
- scaleY: (S.scaleY || 1) / f,
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 v = l.getBoundingRect(!0, !0);
909
- _.set({
910
- left: v.left - t.left,
911
- top: v.top - t.top,
912
- scaleX: 1 / f,
913
- scaleY: 1 / f,
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
- y(_);
922
+ k(P);
923
923
  },
924
- { multiplier: f }
924
+ { multiplier: g }
925
925
  );
926
926
  } catch {
927
- y(l);
927
+ k(l);
928
928
  }
929
929
  })
930
930
  )
931
- )).forEach((l) => u.add(l));
932
- const X = i / t.width, C = a / t.height;
933
- u.setViewportTransform([X, 0, 0, C, 0, 0]), u.renderAll();
934
- const b = r?.minOutputSize ?? 1024;
935
- let A = 1;
936
- (i > b || a > b) && (A = Math.max(1, b / Math.max(i, a))), typeof r?.outputMultiplierCap == "number" && (A = Math.min(A, r.outputMultiplierCap));
937
- let h = "";
938
- const p = () => u.toDataURL({
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: A
944
- }), T = r?.preferImageBitmap ?? !0, E = r?.returnBlobUrl ?? !1;
945
- if (T && window.createImageBitmap && typeof u.toCanvasElement == "function") {
946
- const l = u.toCanvasElement(A, { width: i, height: a });
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
- h = await createImageBitmap(l);
948
+ f = await createImageBitmap(l);
949
949
  } finally {
950
950
  l.width = 0, l.height = 0;
951
951
  }
952
- } else if (E && typeof u.toCanvasElement == "function") {
953
- const l = u.toCanvasElement(A, { width: i, height: a }), y = await new Promise((I) => l.toBlob(I, "image/webp", r?.quality ?? 0.5));
954
- l.width = 0, l.height = 0, h = y ? URL.createObjectURL(y) : p();
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
- h = p();
957
- return u.dispose(), h;
956
+ f = u();
957
+ return h.dispose(), f;
958
958
  }
959
959
  }
960
- class je {
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 et {
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 Oe {
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 et(32 * 1024 * 1024, 4, (e) => {
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 xe(d, e) {
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 tt(d, e, s) {
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 Ye(d, e, s) {
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 t = Ye(d, e, s);
1141
- return d.render_areas.filter((i) => {
1142
- const a = e[Z(i)];
1143
- return qe(i, t, !!(i.area && Array.isArray(a?.objects) && a.objects.length));
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 ke(d, e, s, r = !0) {
1147
- return fe(d, e, s, r).flatMap((t) => {
1148
- const i = e[Z(t)];
1149
- return [t.image, ...t.design && t.area && Array.isArray(i?.objects) && i.objects.length ? [t.area.image, ...ge(i)] : []];
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 rt(d) {
1156
+ function nt(d) {
1153
1157
  return d.render_areas.find((e) => e.name === "bg")?.image || d.image || "";
1154
1158
  }
1155
- function st(d, e) {
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 de(d) {
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 Ct = Te(
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
- scale: c = 0.8,
1176
- renderer: o = "pixel-map",
1177
- className: m,
1178
- style: f,
1179
- alt: P = "Product preview",
1180
- onLoadingChange: u,
1181
- onRendered: Y,
1182
- onError: M
1183
- }, X) {
1184
- const C = R(null), b = R(null), A = R(null), h = R(null), p = R(null), T = R(void 0), E = R(null), l = R(null), y = R(0), I = R(/* @__PURE__ */ new Map()), _ = R(null), v = R(0), S = R(!1), g = R(!1), L = R({ onLoadingChange: u, onRendered: Y, onError: M, onAssetReady: a });
1185
- L.current = { onLoadingChange: u, onRendered: Y, onError: M, onAssetReady: a };
1186
- const O = o === "pixel-map" && Re.isSupported(), J = R(O);
1187
- J.current = O;
1188
- const [le, se] = re(""), [k, he] = re(!1), [Xe, Ae] = re(""), K = N(() => (p.current ??= new Oe(), p.current), []), $ = N((w) => {
1189
- he(w), L.current.onLoadingChange?.(w);
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 (A.current) return A.current;
1192
- if (!C.current || !b.current) return null;
1196
+ if (f.current) return f.current;
1197
+ if (!v.current || !E.current) return null;
1193
1198
  const w = 800;
1194
- return C.current.width = w, C.current.height = w, A.current = new Me(
1195
- C.current,
1199
+ return v.current.width = w, v.current.height = w, f.current = new xe(
1200
+ v.current,
1196
1201
  { width: w, height: w },
1197
- b.current,
1202
+ E.current,
1198
1203
  0.85
1199
- ), A.current;
1204
+ ), f.current;
1200
1205
  }, []), pe = N(async () => {
1201
- if (h.current) return h.current;
1202
- if (O) h.current = new Re();
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 (g.current || J.current !== O) return null;
1206
- if (h.current) return h.current;
1207
- h.current = new w({ width: 1, height: 1 }, !0, { subdiv: 8 });
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 h.current;
1210
- }, [O]), ne = N(() => {
1211
- A.current?.destroy(), A.current = null, h.current?.destroy(), h.current = null, p.current?.dispose(), p.current = null, T.current = void 0, I.current.forEach(({ texture: w }) => de(w)), I.current.clear(), l.current && URL.revokeObjectURL(l.current), l.current = null, E.current = null;
1212
- }, []), me = N(() => (_.current || (_.current = new je(
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
- g.current ? ne() : $(!1);
1220
+ I.current ? ne() : $(!1);
1216
1221
  }
1217
- )), _.current), [ne, $]), ae = N(() => {
1218
- const w = ++y.current, Q = v.current;
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 (g.current || w !== y.current) return;
1223
- const B = ie();
1224
- S.current && (h.current?.destroy(), h.current = null, S.current = !1);
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 (!B || !V || g.current || w !== y.current) return;
1227
- const q = K();
1228
- D = q.hold(ke(e, s, n, O));
1229
- const ve = fe(e, s, n, O), Ie = e.render_areas.filter((x) => !!x.design), ce = st(e, c), ye = Promise.all(ve.map(async (x) => [x.image, await q.url(x.image)]));
1230
- ye.catch(() => {
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 x of Ie) {
1233
- const H = Z(x), F = s[H];
1234
- if (!Array.isArray(F?.objects) || !F.objects.length || !x.area) {
1235
- const ee = I.current.get(H);
1236
- ee && (de(ee.texture), I.current.delete(H));
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 W = JSON.stringify([
1244
+ const Pe = JSON.stringify([
1240
1245
  Q,
1241
1246
  ce,
1242
- x.area.id,
1243
- x.area.image,
1244
- F
1247
+ _.area.id,
1248
+ _.area.image,
1249
+ B,
1250
+ c,
1251
+ G
1245
1252
  ]);
1246
- if (I.current.get(H)?.fingerprint === W) continue;
1247
- const j = typeof F.color == "string" ? F.color : "", [Be, Ue] = await Promise.all([
1248
- q.url(x.area.image),
1249
- xe(F, q)
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 (g.current || w !== y.current || (await B.switchView({ ...x.area, image: Be }, j, Ue), g.current || w !== y.current)) return;
1252
- const Pe = typeof createImageBitmap == "function" ? await B.exportPreviewBitmap(ce, j) : await B.export(!1, j, {
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 (Pe) {
1260
- const ee = I.current.get(H);
1261
- ee && de(ee.texture), I.current.set(H, { fingerprint: W, texture: Pe });
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 (g.current || w !== y.current) return;
1270
+ if (I.current || w !== M.current) return;
1264
1271
  }
1265
- const Ee = new Map(await ye);
1266
- if (g.current || w !== y.current) return;
1267
- const be = Ye(e, s, n), Ce = ve.map((x) => {
1268
- const H = s[Z(x)], F = x.design && Array.isArray(H?.objects) && H.objects.length ? I.current.get(Z(x))?.texture : void 0, W = x.texture_transform, j = typeof W?.blendMode == "number" ? W.blendMode : typeof W?.blendMode == "string" ? We[W.blendMode.toLowerCase()] : void 0;
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
- ...x,
1271
- image: Ee.get(x.image) ?? x.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: W ? O ? { ...W } : { ...W, blendMode: j } : void 0
1283
+ config: B ? Y ? { ...B } : { ...B, blendMode: G } : void 0
1276
1284
  };
1277
- }), oe = O ? await V.onOffscreenRender(Ce, {
1278
- color: be,
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: be,
1292
+ color: ye,
1285
1293
  cleanCache: !1,
1286
- scale: c,
1294
+ scale: o,
1287
1295
  quality: 0.85
1288
1296
  });
1289
- if (g.current || w !== y.current) return;
1297
+ if (I.current || w !== M.current) return;
1290
1298
  if (!oe) throw new Error("Could not render the product preview");
1291
- const ue = URL.createObjectURL(oe);
1292
- l.current && URL.revokeObjectURL(l.current), E.current = oe, l.current = ue, se(ue), L.current.onRendered?.({ renderId: e.id, blob: oe, url: ue });
1293
- } catch (B) {
1294
- !g.current && w === y.current && L.current.onError?.(B instanceof Error ? B : 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 });
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, c, O]);
1300
- te(() => (g.current = !1, () => {
1301
- g.current = !0, y.current += 1, _.current?.clear(), _.current?.active || ne();
1302
- }), [ne]), te(() => {
1303
- h.current?.destroy(), h.current = null;
1304
- }, [o, O]), te(() => {
1305
- const w = K(), Q = i ?? s, D = ke(e, Q, n, O);
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 B = !0;
1315
+ let U = !0;
1308
1316
  return w.preload(D, !0).then(async () => {
1309
- if (B)
1310
- for (const V of fe(e, Q, n, O).map((q) => q.image).filter(Boolean)) {
1311
- const q = await w.url(V);
1312
- if (!B) return;
1313
- L.current.onAssetReady?.(V, q), V === rt(e) && Ae(q);
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
- B && t?.length && T.current !== t && (T.current = t, w.preload(t).catch(() => {
1325
+ U && t?.length && W.current !== t && (W.current = t, w.preload(t).catch(() => {
1318
1326
  }));
1319
1327
  }), () => {
1320
- B = !1;
1328
+ U = !1;
1321
1329
  };
1322
- }, [n, s, i, K, t, e, O]), te(() => (r ? ae() : $(!1), () => {
1323
- y.current += 1, _.current?.clear();
1324
- }), [r, ae, $]), Le(X, () => ({
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 () => E.current,
1327
- getPreviewUrl: async () => E.current ? URL.createObjectURL(E.current) : null,
1334
+ getPreviewBlob: async () => l.current,
1335
+ getPreviewUrl: async () => l.current ? URL.createObjectURL(l.current) : null,
1328
1336
  refresh: () => {
1329
- v.current += 1, S.current = !0, r && ae();
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 = le || Xe;
1337
- return /* @__PURE__ */ _e("div", { className: m, style: { position: "relative", ...f }, children: [
1338
- we && /* @__PURE__ */ z("img", { src: we, alt: P, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
1339
- k && /* @__PURE__ */ z("div", { "aria-live": "polite", "aria-label": "Rendering product preview", style: { position: "absolute", inset: 0 } }),
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: b, style: { width: 800, height: 800 }, children: /* @__PURE__ */ z("canvas", { ref: C, width: 800, height: 800 }) }) })
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 Pt({
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 = R(null), o = R(null), m = R(null), f = R(r), P = R(i), u = R(null), Y = R(e), [M, X] = re(!1), [C, b] = re("");
1355
- f.current = r, P.current = i;
1356
- const A = N(() => {
1357
- const h = m.current;
1358
- if (!h) return;
1359
- const p = h.getRenderedObjects();
1360
- f.current(u.current ? tt(p, u.current, Y.current) : p);
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 te(() => {
1363
- let h = !1, p = null, T = !1, E = !1, l = null, y = null;
1364
- const I = () => {
1365
- T || (T = !0, p?.destroy(), m.current === p && (m.current = null), l?.release(), u.current === l && (u.current = null), y?.dispose());
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 (P.current?.(!0), await new Promise((k) => requestAnimationFrame(() => k())), h) return;
1369
- const v = c.current, S = o.current;
1370
- if (!v || !S) return;
1371
- const g = v.clientWidth || 400, L = v.clientHeight || 400, O = [d.image, ...ge(e)];
1372
- if (t ? l = await t(O) : (y = new Oe(), l = await y.acquire(O)), h) return;
1373
- u.current = l;
1374
- const J = await xe(e, { url: async (k) => l.urls[k] ?? k });
1375
- if (h) return;
1376
- p = new Me(S, { width: g, height: L }, v, 0.85), m.current = p, $e(typeof window < "u" && window.innerWidth < 768 ? 16 : 8);
1377
- const le = {
1378
- ...J,
1379
- objects: (Array.isArray(J.objects) ? J.objects : []).map(
1380
- (k) => k?.selectable === !1 ? { ...k, selectable: !0 } : k
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 p.switchView({ ...d, image: l.urls[d.image] ?? d.image }, typeof e.color == "string" ? e.color : "", le), h) return;
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((k) => k?.customConfig?.moveable === !0).map((k) => String(k.id ?? ""))
1393
+ (Array.isArray(e.objects) ? e.objects : []).filter((R) => R?.customConfig?.moveable === !0).map((R) => String(R.id ?? ""))
1386
1394
  );
1387
- if (p.canvas.forEachObject((k) => {
1388
- se.has(String(k.id ?? "")) || k.set({ selectable: !1, evented: !1 });
1395
+ if (u.canvas.forEachObject((R) => {
1396
+ se.has(String(R.id ?? "")) || R.set({ selectable: !1, evented: !1 });
1389
1397
  }), s) {
1390
- const k = p.canvas.getObjects().find((he) => String(he.id ?? "") === String(s));
1391
- k && se.has(String(s)) && p.canvas.setActiveObject(k);
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
- p.canvas.on("object:modified", () => A()), p.canvas.requestRenderAll(), await new Promise((k) => requestAnimationFrame(() => k())), h || X(!0);
1394
- })().catch((v) => {
1395
- h || b(v instanceof Error ? v.message : "Could not load the editor.");
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
- E = !0, h && I(), P.current?.(!1);
1405
+ W = !0, f && M(), b.current?.(!1);
1398
1406
  }), () => {
1399
- h = !0, X(!1), E && I();
1407
+ f = !0, A(!1), W && M();
1400
1408
  };
1401
- }, []), /* @__PURE__ */ _e("div", { className: a, style: { position: "relative", width: "100%", height: "100%", ...n }, children: [
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
- !M && /* @__PURE__ */ z("div", { style: { position: "absolute", inset: 0, background: "#f2f2f2" }, "aria-label": C ? "Editor failed to load" : "Loading editor", children: C && /* @__PURE__ */ z("span", { role: "alert", children: C }) })
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
- Pt as P,
1408
- Ct as a
1415
+ kt as P,
1416
+ Rt as a
1409
1417
  };