@printine/pod-editor 0.1.19 → 0.1.20

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.
@@ -15,8 +15,8 @@ import { isSvg as t1, inchToPixel as Vo } from "./engine/utils/measure.js";
15
15
  import { a as ze, A as Bc } from "./designer-store-Da9fICz8.js";
16
16
  import { BLEND_MODES_MAP as jc, DEFAULT_FONT_SIZE as n1, ALIGN_TYPES as r1, ELEMENT_TITLE_MAP as Vc, LAYER_BLACK_LIST as o1 } from "./engine/constants.js";
17
17
  import { StickerPlugin as a1, Sticker3DPlugin as Hc } from "./renderer/sticker.js";
18
- import { P as Va, h as Kn, M as wl, b as i1 } from "./pixel-map-BvQ0VU_i.js";
19
- import { renderPixiWithPrintBase as s1 } from "./pixi-print-base-CKs4lF7h.js";
18
+ import { P as Va, h as Kn, M as wl, b as i1 } from "./pixel-map-CSpWvUYE.js";
19
+ import { renderPixiWithPrintBase as s1 } from "./pixi-print-base-DIvtSF7v.js";
20
20
  import Uc from "lodash-es/throttle";
21
21
  import { debounce as yi } from "lodash-es";
22
22
  import { blobUrlToFile as l1, generateThumbImage as c1, xyToDirectionOffset as d1, directionOffsetToXY as u1, urlToBlob as yl, dataUrlToFile as Cl } from "./engine/utils/common.js";
@@ -4,14 +4,14 @@ import { cloneObject as b, urlToDataURL as E } from "./utils/common.js";
4
4
  import { loadOverlaySvgImage as T, loadImage as B } from "./utils/image.js";
5
5
  import { Loading as Y } from "./utils/loading.js";
6
6
  import { HistoryManager as X } from "./history.js";
7
- import { LAYER_BLACK_LIST as R } from "./constants.js";
7
+ import { LAYER_BLACK_LIST as I } from "./constants.js";
8
8
  import U from "./events.js";
9
9
  import { ImageProcessor as L } from "./processors/image.js";
10
10
  import { TemplateProcessor as W } from "./processors/template.js";
11
11
  import { TextProcessor as D } from "./processors/text.js";
12
12
  import { ResizeManager as _ } from "./managers/resize.js";
13
13
  import { WorkspaceManager as q } from "./managers/workspace.js";
14
- import { fabric as p } from "fabric";
14
+ import { fabric as f } from "fabric";
15
15
  class se {
16
16
  constructor(t, a, e, r = {}) {
17
17
  this.previewExporting = !1, this.imageCache = /* @__PURE__ */ new Map(), this.overlayCache = /* @__PURE__ */ new Map(), this.destroyed = !1, this.deleteObject = (n) => {
@@ -27,7 +27,7 @@ class se {
27
27
  this.canvas.requestRenderAll();
28
28
  };
29
29
  const s = typeof r == "number" ? { overlayScale: r } : r;
30
- this.canvas = new p.Canvas(t, {
30
+ this.canvas = new f.Canvas(t, {
31
31
  enableRetinaScaling: !0,
32
32
  width: a.width,
33
33
  height: a.height,
@@ -60,44 +60,44 @@ class se {
60
60
  * 统一拦截图片创建:优先从会话缓存复用已加载的 HTMLImageElement,避免视图切换或导出时重复请求远程图片
61
61
  */
62
62
  setupImageCacheInterceptor() {
63
- const t = this.imageCache, a = p.Image.fromURL, e = p.Image.fromObject;
64
- if (p.Image._printineCacheHooked) return;
65
- p.Image._printineCacheHooked = !0;
63
+ const t = this.imageCache, a = f.Image.fromURL, e = f.Image.fromObject;
64
+ if (f.Image._printineCacheHooked) return;
65
+ f.Image._printineCacheHooked = !0;
66
66
  const r = (n) => {
67
67
  if (!n) return null;
68
68
  const i = t.get(n);
69
69
  return i?.element && i.element.complete ? (t.set(n, { ...i, lastUsed: Date.now() }), i.element) : null;
70
70
  };
71
- p.Image.fromURL = function(n, i, c) {
71
+ f.Image.fromURL = function(n, i, c) {
72
72
  const o = { ...c, crossOrigin: "anonymous" }, l = r(n);
73
73
  if (l) {
74
- const f = new p.Image(l, o);
75
- f.originSrc = n, i && i(f);
74
+ const m = new f.Image(l, o);
75
+ m.originSrc = n, i && i(m);
76
76
  return;
77
77
  }
78
78
  return a.call(
79
79
  this,
80
80
  n,
81
- (f) => {
82
- f && (f.originSrc = n), i && i(f);
81
+ (m) => {
82
+ m && (m.originSrc = n), i && i(m);
83
83
  },
84
84
  o
85
85
  );
86
86
  };
87
87
  const s = (n) => !!n && typeof n == "object" && typeof n.set == "function" && typeof n.shouldCache == "function";
88
- p.Image.fromObject = function(n, i) {
88
+ f.Image.fromObject = function(n, i) {
89
89
  const c = n?.originSrc || n?.src, o = r(c);
90
90
  if (o) {
91
- const { clipPath: l, ...f } = n ?? {}, v = new p.Image(o, { ...f });
92
- if (v.originSrc = c, !l || s(l)) {
93
- l && (v.clipPath = l), i?.(v);
91
+ const { clipPath: l, ...m } = n ?? {}, u = new f.Image(o, { ...m });
92
+ if (u.originSrc = c, !l || s(l)) {
93
+ l && (u.clipPath = l), i?.(u);
94
94
  return;
95
95
  }
96
- p.util.enlivenObjects(
96
+ f.util.enlivenObjects(
97
97
  [l],
98
- (u) => {
99
- const [C] = u || [];
100
- C && (v.clipPath = C), i?.(v);
98
+ (w) => {
99
+ const [O] = w || [];
100
+ O && (u.clipPath = O), i?.(u);
101
101
  },
102
102
  ""
103
103
  );
@@ -182,26 +182,26 @@ class se {
182
182
  strokeUniform: !0,
183
183
  objectCaching: !1
184
184
  }), e.render(r);
185
- const i = 6, c = (e.getScaledWidth() + i * 2) / e.getScaledWidth(), o = (e.getScaledHeight() + i * 2) / e.getScaledHeight(), l = e.left ?? 0, f = e.top ?? 0, v = e.scaleX ?? 1, u = e.scaleY ?? 1;
185
+ const i = 6, c = (e.getScaledWidth() + i * 2) / e.getScaledWidth(), o = (e.getScaledHeight() + i * 2) / e.getScaledHeight(), l = e.left ?? 0, m = e.top ?? 0, u = e.scaleX ?? 1, w = e.scaleY ?? 1;
186
186
  e.set({
187
187
  strokeDashArray: [4, 4],
188
188
  stroke: "#C3C3CC",
189
189
  strokeWidth: 1,
190
190
  strokeUniform: !0,
191
- scaleX: v * c,
192
- scaleY: u * o,
191
+ scaleX: u * c,
192
+ scaleY: w * o,
193
193
  left: l - i,
194
- top: f - i
194
+ top: m - i
195
195
  }), e.render(r), e.set({
196
196
  stroke: n.stroke,
197
197
  strokeWidth: n.strokeWidth,
198
198
  strokeDashArray: n.strokeDashArray,
199
199
  fill: n.fill,
200
200
  strokeUniform: n.strokeUniform,
201
- scaleX: v,
202
- scaleY: u,
201
+ scaleX: u,
202
+ scaleY: w,
203
203
  left: l,
204
- top: f
204
+ top: m
205
205
  }), r.restore();
206
206
  }, this.canvas.on("after:render", this.overlayBorderHandler);
207
207
  }
@@ -260,7 +260,7 @@ class se {
260
260
  */
261
261
  async restoreObject(t) {
262
262
  return new Promise((a) => {
263
- p.util.enlivenObjects([t], (e) => a(e), "");
263
+ f.util.enlivenObjects([t], (e) => a(e), "");
264
264
  });
265
265
  }
266
266
  /**
@@ -357,7 +357,7 @@ class se {
357
357
  * 获取当前可选择的对象,不包括背景图、裁剪区域
358
358
  */
359
359
  getLayerList() {
360
- return this.canvas._objects.filter((t) => !R.includes(t.id || ""));
360
+ return this.canvas._objects.filter((t) => !I.includes(t.id || ""));
361
361
  }
362
362
  /**
363
363
  * 设置当前选中的对象
@@ -370,7 +370,7 @@ class se {
370
370
  * 同时选中多个对象
371
371
  */
372
372
  setActiveObjects(t) {
373
- const a = new p.ActiveSelection(t, { canvas: this.canvas });
373
+ const a = new f.ActiveSelection(t, { canvas: this.canvas });
374
374
  this.canvas.setActiveObject(a), this.canvas.requestRenderAll();
375
375
  }
376
376
  /**
@@ -391,7 +391,7 @@ class se {
391
391
  getRenderedObjects() {
392
392
  const { objects: t } = this.canvas.toJSON(X.DEFAULT_SAVE_PROPERTIES), a = this.workspaceManager.dimension;
393
393
  return {
394
- objects: t.filter((e) => !R.includes(e.id || "")),
394
+ objects: t.filter((e) => !I.includes(e.id || "")),
395
395
  workspaceMetadata: {
396
396
  width: a.width,
397
397
  height: a.height,
@@ -431,7 +431,7 @@ class se {
431
431
  async switchView(t, a, e) {
432
432
  if (this.isCanvasReady()) {
433
433
  if (this.canvas.clear(), e && e.objects && e.objects.length)
434
- return p.AdvancedIText = A, await this.textProcessor.preloadFontsFromState(e), this.isCanvasReady() ? new Promise((r) => {
434
+ return f.AdvancedIText = A, await this.textProcessor.preloadFontsFromState(e), this.isCanvasReady() ? new Promise((r) => {
435
435
  this.canvas.loadFromJSON(
436
436
  e,
437
437
  async () => {
@@ -465,7 +465,7 @@ class se {
465
465
  this.canvas.renderAll(), this.events.emit("design:layerChange"), r();
466
466
  },
467
467
  (s, n) => {
468
- s.clipPath && !e.objects.some((i) => i.id === s.clipPath.id) && (delete n.clipPath, p.util.enlivenObjects(
468
+ s.clipPath && !e.objects.some((i) => i.id === s.clipPath.id) && (delete n.clipPath, f.util.enlivenObjects(
469
469
  [s.clipPath],
470
470
  (i) => {
471
471
  const c = i[0];
@@ -486,30 +486,30 @@ class se {
486
486
  const a = this.workspaceManager.dimension, e = Math.min(
487
487
  a.width / t.width,
488
488
  a.height / t.height
489
- ), r = t.centerX, s = t.centerY, n = a.center.x, i = a.center.y, c = Math.abs(n - r), o = Math.abs(i - s), l = Math.abs(e - 1) >= 1e-3, f = c >= 0.1 || o >= 0.1;
490
- if (!l && !f) return;
491
- const v = this.canvas.getObjects(), u = new Set(v), C = /* @__PURE__ */ new Set(), P = (d) => {
492
- const g = d.clipPath;
493
- g && u.has(g) && C.add(g);
489
+ ), r = t.centerX, s = t.centerY, n = a.center.x, i = a.center.y, c = Math.abs(n - r), o = Math.abs(i - s), l = Math.abs(e - 1) >= 1e-3, m = c >= 0.1 || o >= 0.1;
490
+ if (!l && !m) return;
491
+ const u = this.canvas.getObjects(), w = new Set(u), O = /* @__PURE__ */ new Set(), k = (d) => {
492
+ const p = d.clipPath;
493
+ p && w.has(p) && O.add(p);
494
494
  };
495
- v.forEach(P);
496
- const O = (d) => {
497
- const g = (d.left || 0) - r, y = (d.top || 0) - s, w = n + g * e, m = i + y * e;
495
+ u.forEach(k);
496
+ const g = (d) => {
497
+ const p = (d.left || 0) - r, P = (d.top || 0) - s, y = n + p * e, v = i + P * e;
498
498
  d.set({
499
- left: w,
500
- top: m,
499
+ left: y,
500
+ top: v,
501
501
  scaleX: (d.scaleX || 1) * e,
502
502
  scaleY: (d.scaleY || 1) * e
503
503
  }), d.setCoords(), d.dirty = !0;
504
- }, k = /* @__PURE__ */ new Set(), S = (d) => {
505
- !d.selectable && !C.has(d) || (O(d), k.add(d));
504
+ }, C = /* @__PURE__ */ new Set(), S = (d) => {
505
+ !d.selectable && !O.has(d) || (g(d), C.add(d));
506
506
  };
507
- v.forEach(S);
507
+ u.forEach(S);
508
508
  const h = (d) => {
509
- const g = d.clipPath;
510
- g && g.absolutePositioned && !u.has(g) && !k.has(g) && (O(g), k.add(g));
509
+ const p = d.clipPath;
510
+ p && p.absolutePositioned && !w.has(p) && !C.has(p) && (g(p), C.add(p));
511
511
  };
512
- v.forEach(h);
512
+ u.forEach(h);
513
513
  }
514
514
  /**
515
515
  * 计算对象相对于画布的全局变换矩阵(包括父组的影响)
@@ -594,7 +594,7 @@ class se {
594
594
  });
595
595
  const i = this.imageCache.get(n);
596
596
  return i?.element && i.element.complete ? new Promise(async (c) => {
597
- const o = new p.Image(i.element, {
597
+ const o = new f.Image(i.element, {
598
598
  width: t.width,
599
599
  height: t.height,
600
600
  ...a
@@ -619,7 +619,7 @@ class se {
619
619
  */
620
620
  async export(t = !1, a) {
621
621
  const e = this.workspaceManager.dimension, r = this.workspaceManager.printAreaSize?.width ?? e.width, s = this.workspaceManager.printAreaSize?.height ?? e.height, n = window.devicePixelRatio || 1, i = Math.max(r / e.width, s / e.height), c = Math.max(4, Math.min(8, Math.ceil(i * n)));
622
- let o = new p.Rect({
622
+ let o = new f.Rect({
623
623
  left: 0,
624
624
  top: 0,
625
625
  width: e.width,
@@ -632,41 +632,41 @@ class se {
632
632
  top: this.canvas.clipPath.top - e.top,
633
633
  absolutePositioned: !0
634
634
  }));
635
- const l = new p.StaticCanvas(null, {
635
+ const l = new f.StaticCanvas(null, {
636
636
  width: e.width,
637
637
  height: e.height,
638
638
  enableRetinaScaling: !1,
639
639
  backgroundColor: a || "transparent",
640
640
  preserveObjectStacking: !0,
641
641
  clipPath: o
642
- }), f = this.getLayerList();
642
+ }), m = this.getLayerList();
643
643
  (await Promise.all(
644
- f.map(
644
+ m.map(
645
645
  (h) => new Promise((d) => {
646
646
  try {
647
647
  if (h.type === "image") {
648
- const g = h;
649
- let y = {
648
+ const p = h;
649
+ let P = {
650
650
  selectable: !1,
651
651
  evented: !1,
652
652
  flipX: h.flipX || !1,
653
653
  flipY: h.flipY || !1
654
654
  };
655
655
  if (this.isInActiveSelection(h)) {
656
- const w = this.getGlobalTransformMatrix(h), m = p.util.qrDecompose(w);
657
- y = {
658
- ...y,
659
- left: (m.translateX || 0) - (e.left || 0),
660
- top: (m.translateY || 0) - (e.top || 0),
661
- angle: m.angle || 0,
662
- scaleX: m.scaleX || 1,
663
- scaleY: m.scaleY || 1,
656
+ const y = this.getGlobalTransformMatrix(h), v = f.util.qrDecompose(y);
657
+ P = {
658
+ ...P,
659
+ left: (v.translateX || 0) - (e.left || 0),
660
+ top: (v.translateY || 0) - (e.top || 0),
661
+ angle: v.angle || 0,
662
+ scaleX: v.scaleX || 1,
663
+ scaleY: v.scaleY || 1,
664
664
  originX: "center",
665
665
  originY: "center"
666
666
  };
667
667
  } else
668
- y = {
669
- ...y,
668
+ P = {
669
+ ...P,
670
670
  left: h.left - e.left,
671
671
  top: h.top - e.top,
672
672
  angle: h.angle || 0,
@@ -675,39 +675,39 @@ class se {
675
675
  originX: "left",
676
676
  originY: "top"
677
677
  };
678
- this.cloneImageFromCache(g, y).then(async (w) => {
679
- if (w.clipPath) {
680
- const m = w.clipPath;
681
- m.absolutePositioned && m.set({
682
- left: (m.left || 0) - e.left,
683
- top: (m.top || 0) - e.top
678
+ this.cloneImageFromCache(p, P).then(async (y) => {
679
+ if (y.clipPath) {
680
+ const v = y.clipPath;
681
+ v.absolutePositioned && v.set({
682
+ left: (v.left || 0) - e.left,
683
+ top: (v.top || 0) - e.top
684
684
  });
685
685
  }
686
- if (t && w.type === "image")
686
+ if (t && y.type === "image")
687
687
  try {
688
- const m = w, I = m.getSrc() || m.originSrc || "";
689
- if (I) {
690
- const x = await this.getCachedDataURL(I);
691
- m.setSrc(x, () => d(w));
688
+ const v = y, R = v.getSrc() || v.originSrc || "";
689
+ if (R) {
690
+ const x = await this.getCachedDataURL(R);
691
+ v.setSrc(x, () => d(y));
692
692
  return;
693
693
  }
694
694
  } catch {
695
695
  }
696
- d(w);
696
+ d(y);
697
697
  }).catch(() => {
698
698
  d(h);
699
699
  });
700
700
  } else
701
701
  h.cloneAsImage(
702
- (g) => {
702
+ (p) => {
703
703
  if (this.isInActiveSelection(h)) {
704
- const y = this.getGlobalTransformMatrix(h), w = p.util.qrDecompose(y);
705
- g.set({
706
- left: (w.translateX || 0) - (e.left || 0),
707
- top: (w.translateY || 0) - (e.top || 0),
708
- angle: w.angle || 0,
709
- scaleX: (w.scaleX || 1) / c,
710
- scaleY: (w.scaleY || 1) / c,
704
+ const P = this.getGlobalTransformMatrix(h), y = f.util.qrDecompose(P);
705
+ p.set({
706
+ left: (y.translateX || 0) - (e.left || 0),
707
+ top: (y.translateY || 0) - (e.top || 0),
708
+ angle: y.angle || 0,
709
+ scaleX: (y.scaleX || 1) / c,
710
+ scaleY: (y.scaleY || 1) / c,
711
711
  selectable: !1,
712
712
  hasControls: !1,
713
713
  hasBorders: !1,
@@ -715,10 +715,10 @@ class se {
715
715
  originY: "center"
716
716
  });
717
717
  } else {
718
- const y = h.getBoundingRect(!0, !0);
719
- g.set({
720
- left: y.left - e.left,
721
- top: y.top - e.top,
718
+ const P = h.getBoundingRect(!0, !0);
719
+ p.set({
720
+ left: P.left - e.left,
721
+ top: P.top - e.top,
722
722
  scaleX: 1 / c,
723
723
  scaleY: 1 / c,
724
724
  angle: 0,
@@ -729,7 +729,7 @@ class se {
729
729
  originY: "top"
730
730
  });
731
731
  }
732
- d(g);
732
+ d(p);
733
733
  },
734
734
  { multiplier: c }
735
735
  );
@@ -739,25 +739,25 @@ class se {
739
739
  })
740
740
  )
741
741
  )).forEach((h) => l.add(h));
742
- const u = r / e.width, C = s / e.height;
743
- l.setViewportTransform([u, 0, 0, C, 0, 0]), l.renderAll();
744
- const P = 1024;
745
- let O = 1;
746
- (r < P || s < P) && (O = Math.max(1, P / Math.max(r, s)));
747
- let k = "";
742
+ const w = r / e.width, O = s / e.height;
743
+ l.setViewportTransform([w, 0, 0, O, 0, 0]), l.renderAll();
744
+ const k = 1024;
745
+ let g = 1;
746
+ (r < k || s < k) && (g = Math.max(1, k / Math.max(r, s)));
747
+ let C = "";
748
748
  const S = () => l.toDataURL({
749
749
  format: "webp",
750
750
  quality: 0.5,
751
751
  width: r,
752
752
  height: s,
753
- multiplier: O
753
+ multiplier: g
754
754
  });
755
755
  if (window.createImageBitmap && typeof l.toCanvasElement == "function") {
756
- const h = l.toCanvasElement(O, { width: r, height: s });
757
- k = await createImageBitmap(h);
756
+ const h = l.toCanvasElement(g, { width: r, height: s });
757
+ C = await createImageBitmap(h);
758
758
  } else
759
- k = S();
760
- return l.dispose(), k;
759
+ C = S();
760
+ return l.dispose(), C;
761
761
  }
762
762
  /**
763
763
  * Rasterize the current design for real-time product previews without
@@ -771,27 +771,31 @@ class se {
771
771
  const e = this.workspaceManager.dimension, r = this.workspaceManager.printAreaSize?.width ?? e.width, s = this.workspaceManager.printAreaSize?.height ?? e.height;
772
772
  if (!e.width || !e.height || !r || !s)
773
773
  throw new Error("Printable workspace has no dimensions");
774
- const n = Math.max(r, s), i = t / n, c = Math.max(1, Math.round(r * i)), o = Math.max(1, Math.round(s * i)), l = this.canvas.viewportTransform?.slice(), f = this.canvas.overlayImage?.visible, v = this.canvas.backgroundColor, u = this.canvas.getActiveObject(), C = u ? { hasBorders: u.hasBorders, hasControls: u.hasControls } : null;
774
+ const n = Math.max(r, s), i = t / n, c = Math.max(1, Math.round(r * i)), o = Math.max(1, Math.round(s * i)), l = this.canvas.viewportTransform?.slice(), m = this.canvas.overlayImage?.visible, u = this.canvas.backgroundColor, w = this.canvas.getActiveObject(), O = w ? { hasBorders: w.hasBorders, hasControls: w.hasControls } : null, k = this.canvas.getObjects().filter((g) => g.id === "loading" || g.id === "cropRect" || g.id === "cropOverlay").map((g) => ({ object: g, visible: g.visible }));
775
775
  try {
776
- this.previewExporting = !0, this.canvas.overlayImage && (this.canvas.overlayImage.visible = !1), u?.set({ hasBorders: !1, hasControls: !1 }), this.canvas.backgroundColor = a || "transparent", this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0], this.canvas.renderAll();
777
- const P = document.createElement("canvas");
778
- P.width = c, P.height = o;
779
- const O = P.getContext("2d", { alpha: !0 });
780
- if (!O) throw new Error("Could not create preview canvas context");
781
- const k = this.canvas, S = k.getRetinaScaling?.() ?? window.devicePixelRatio ?? 1;
782
- return O.drawImage(
783
- k.lowerCanvasEl,
784
- e.left * S,
785
- e.top * S,
786
- e.width * S,
787
- e.height * S,
776
+ this.previewExporting = !0, this.canvas.overlayImage && (this.canvas.overlayImage.visible = !1), w?.set({ hasBorders: !1, hasControls: !1 }), k.forEach(({ object: d }) => {
777
+ d.visible = !1;
778
+ }), this.canvas.backgroundColor = a || "transparent", this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0], this.canvas.renderAll();
779
+ const g = document.createElement("canvas");
780
+ g.width = c, g.height = o;
781
+ const C = g.getContext("2d", { alpha: !0 });
782
+ if (!C) throw new Error("Could not create preview canvas context");
783
+ const S = this.canvas, h = S.getRetinaScaling?.() ?? window.devicePixelRatio ?? 1;
784
+ return C.drawImage(
785
+ S.lowerCanvasEl,
786
+ e.left * h,
787
+ e.top * h,
788
+ e.width * h,
789
+ e.height * h,
788
790
  0,
789
791
  0,
790
792
  c,
791
793
  o
792
- ), await createImageBitmap(P);
794
+ ), await createImageBitmap(g);
793
795
  } finally {
794
- this.canvas.backgroundColor = v, this.canvas.overlayImage && f !== void 0 && (this.canvas.overlayImage.visible = f), u && C && u.set(C), l && (this.canvas.viewportTransform = l), this.previewExporting = !1, this.isCanvasReady() && this.canvas.requestRenderAll();
796
+ this.canvas.backgroundColor = u, this.canvas.overlayImage && m !== void 0 && (this.canvas.overlayImage.visible = m), w && O && w.set(O), k.forEach(({ object: g, visible: C }) => {
797
+ g.visible = C;
798
+ }), l && (this.canvas.viewportTransform = l), this.previewExporting = !1, this.isCanvasReady() && this.canvas.requestRenderAll();
795
799
  }
796
800
  }
797
801
  }
@@ -1,13 +1,13 @@
1
1
  import "react/jsx-runtime";
2
2
  import "react";
3
- import { c as s } from "./design-BXbmX1Tb.js";
3
+ import { c as s } from "./design-Ce0Lyr8f.js";
4
4
  import "./engine/events.js";
5
5
  import "zustand/react/shallow";
6
6
  import "./engine/history.js";
7
7
  import "lodash-es/throttle";
8
8
  import "./engine/constants.js";
9
9
  import "./engine/utils/common.js";
10
- import "./pixel-map-BvQ0VU_i.js";
10
+ import "./pixel-map-CSpWvUYE.js";
11
11
  import "./designer-store-Da9fICz8.js";
12
12
  export {
13
13
  s as default
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { AdvancedIText as G } from "./engine/fabric.js";
2
- import { a as S, s as f, D as L, b as _, c as C, C as F } from "./design-BXbmX1Tb.js";
3
- import { F as K, S as V, u as X } from "./design-BXbmX1Tb.js";
2
+ import { a as S, s as f, D as L, b as _, c as C, C as F } from "./design-Ce0Lyr8f.js";
3
+ import { F as K, S as V, u as X } from "./design-Ce0Lyr8f.js";
4
4
  import { jsx as r, jsxs as R } from "react/jsx-runtime";
5
5
  import { useMemo as b, useEffect as a } from "react";
6
6
  import { DEFAULT_PRINTINE_ASSET_BASE_URL as U, createAssetCenterApiClient as B } from "./api/asset-client.js";
7
7
  import { s as d } from "./designer-store-Da9fICz8.js";
8
8
  import { A as $, u as q } from "./designer-store-Da9fICz8.js";
9
9
  import { d as y, s as M } from "./config-D2qm60gf.js";
10
- import { P as Q, a as ee } from "./semi-interact-editor-nZVBXXQn.js";
11
- import { P as te } from "./pixel-map-BvQ0VU_i.js";
10
+ import { P as Q, a as ee } from "./semi-interact-editor-DpzQN5ZB.js";
11
+ import { P as te } from "./pixel-map-CSpWvUYE.js";
12
12
  import { CanvasDesigner as ae, renderPlacementPreviews as ne } from "./engine/canvas-designer.js";
13
13
  import { Editor as ie } from "./engine/editor.js";
14
14
  import { HistoryManager as me } from "./engine/history.js";
@@ -0,0 +1,315 @@
1
+ import { jsxs as A, jsx as b } from "react/jsx-runtime";
2
+ import { isSvg as B } from "./engine/utils/measure.js";
3
+ function j({ image: r, alt: e = "Product preview", loading: t, failed: n, onRetry: o }) {
4
+ return /* @__PURE__ */ A("div", { "data-print-material-preview": "true", style: { position: "relative", width: "100%", height: "100%", minHeight: 80 }, children: [
5
+ r && /* @__PURE__ */ b("img", { src: r, alt: e, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
6
+ (!r || n) && /* @__PURE__ */ A("div", { role: n ? "alert" : "status", "aria-live": "polite", style: {
7
+ position: "absolute",
8
+ inset: 0,
9
+ minHeight: 80,
10
+ display: "flex",
11
+ flexDirection: "column",
12
+ alignItems: "center",
13
+ justifyContent: "center",
14
+ gap: 8,
15
+ padding: 12,
16
+ textAlign: "center",
17
+ background: "#f3f4f6",
18
+ color: "#374151",
19
+ fontSize: 12
20
+ }, children: [
21
+ /* @__PURE__ */ b("span", { children: n ? "Preview could not be generated." : "Generating preview…" }),
22
+ n && o && /* @__PURE__ */ b(
23
+ "button",
24
+ {
25
+ type: "button",
26
+ disabled: t,
27
+ onClick: (c) => {
28
+ c.stopPropagation(), o();
29
+ },
30
+ style: { border: "1px solid #9ca3af", borderRadius: 4, background: "#fff", padding: "5px 12px", cursor: "pointer" },
31
+ children: "Retry"
32
+ }
33
+ )
34
+ ] })
35
+ ] });
36
+ }
37
+ function E(r) {
38
+ return typeof r == "string" && /^#[\da-f]{6}$/i.test(r) ? r.toLowerCase() : void 0;
39
+ }
40
+ function C(r, e, t = !!r.texture) {
41
+ return !r.design || t || !!(e ?? r.color) || !!E(r.defaultPrintColor);
42
+ }
43
+ function w(...r) {
44
+ for (const e of r) if (e !== void 0) return e === null ? null : E(e) ?? null;
45
+ }
46
+ function I(r, e) {
47
+ const t = w(r.defaultPrintColor, e);
48
+ return { ...r, defaultPrintColor: t, render_areas: r.render_areas.map((n) => ({
49
+ ...n,
50
+ defaultPrintColor: n.design ? w(n.defaultPrintColor, n.area?.defaultPrintColor, t) : void 0
51
+ })) };
52
+ }
53
+ function H(r) {
54
+ return { ...r, areas: r.areas.map((e) => ({
55
+ ...e,
56
+ defaultPrintColor: w(e.defaultPrintColor, r.defaultPrintColor)
57
+ })), renders: (r.renders || []).map((e) => I(e, r.defaultPrintColor)) };
58
+ }
59
+ function q(r) {
60
+ return r.some((e) => e.design && !!E(e.defaultPrintColor));
61
+ }
62
+ const S = `(function(){"use strict";class \${constructor(e=32*1024*1024,n=4,r){this.budget=e,this.concurrency=n,this.onEvict=r,this.entries=new Map,this.bytes=0,this.active=0,this.waiting=[],this.pinned=new Set}setPinnedSources(e){this.pinned=new Set(e),this.waiting.forEach(n=>{n.foreground=this.pinned.has(n.source)}),this.waiting.sort((n,r)=>Number(r.foreground)-Number(n.foreground)),this.trim()}trim(){for(const[e,n]of this.entries){if(this.bytes<=this.budget)break;!n.bytes||this.pinned.has(e)||(this.entries.delete(e),this.bytes-=n.bytes,this.onEvict?.(e))}}clear(){for(const e of this.waiting.splice(0))e.cancel();for(const e of this.entries.keys())this.onEvict?.(e);this.entries.clear(),this.pinned.clear(),this.bytes=0}promote(e){const n=this.waiting.findIndex(o=>o.source===e&&!o.foreground);if(n<0)return;const[r]=this.waiting.splice(n,1);r.foreground=!0;const s=this.waiting.findIndex(o=>!o.foreground);this.waiting.splice(s<0?this.waiting.length:s,0,r)}async fetchBlob(e,n){await new Promise((r,s)=>{const o=()=>{this.active+=1,r()};this.active<this.concurrency?o():(this.waiting.push({source:e,foreground:!1,start:o,cancel:()=>s(new Error("Resource cache was released"))}),n&&this.promote(e))});try{const r=await fetch(e);if(!r.ok)throw new Error(\`Could not load render asset (\${r.status})\`);return await r.blob()}finally{this.active-=1,this.waiting.shift()?.start()}}load(e,n=!0){const r=this.entries.get(e);if(r)return this.entries.delete(e),this.entries.set(e,r),n&&this.promote(e),r.ready;const s={ready:this.fetchBlob(e,n),bytes:0};return this.entries.set(e,s),s.ready.then(o=>{this.entries.get(e)===s&&(s.bytes=o.size,this.bytes+=s.bytes,this.trim())}).catch(()=>{this.entries.get(e)===s&&this.entries.delete(e)}),s.ready}}function I(i){return typeof i=="string"&&/^#[\\da-f]{6}$/i.test(i)?i.toLowerCase():void 0}function P(i,e,n=!!i.texture){return!i.design||n||!!(e??i.color)||!!I(i.defaultPrintColor)}const v=44,V=32*1024*1024,L=new Map;let M=0;const X=new $;function x(i,e=0){return typeof i=="number"&&Number.isFinite(i)?i:e}function U(i,e=1){const n=x(i,e);return Math.max(0,Math.min(1,n>1?n/255:n))}function j(i=new Set){for(const[e,n]of L){if(M<=V)break;i.has(e)||!n.bitmap||(L.delete(e),M-=n.bytes,n.bitmap.close())}}function K(i){return createImageBitmap(i).catch(e=>{const n=e instanceof Error?e.message:String(e);throw new Error(\`Render layer image could not be decoded (\${i.type||"unknown"}): \${n}\`)})}async function k(i,e){if(!i)return null;if(i instanceof ImageBitmap)return i;e.add(i);let n=L.get(i);return n?(L.delete(i),L.set(i,n)):(n={bytes:0,promise:X.load(i).then(K)},L.set(i,n),n.promise.then(r=>{n.bitmap=r,n.bytes=r.width*r.height*4,M+=n.bytes}).catch(()=>L.delete(i))),n.promise}function Q(i){for(const e of i)e.image instanceof ImageBitmap&&e.image.close(),e.texture instanceof ImageBitmap&&e.texture.close()}function J(i){const e=i;return!!e&&Array.isArray(e.uLines)&&e.uLines.length>=2&&Array.isArray(e.vLines)&&e.vLines.length>=2&&Array.isArray(e.grid)&&e.grid.length===e.vLines.length&&e.grid.every(n=>Array.isArray(n)&&n.length===e.uLines.length)}function Z(i){const e=i;if(!e||!Array.isArray(e.vertices)||!Array.isArray(e.uvs)||!Array.isArray(e.indices)||!e.vertices.length||e.vertices.length%2!==0||e.uvs.length!==e.vertices.length||!e.indices.length||e.indices.length%3!==0)return!1;const n=e.vertices.length/2;return e.vertices.every(Number.isFinite)&&e.uvs.every(Number.isFinite)&&e.indices.every(r=>Number.isInteger(r)&&r>=0&&r<n&&r<=65535)}function q(i){return i.some(e=>e.some(n=>["r","l","u","d"].some(r=>{const s=n[r];return typeof s=="object"&&!!s.moved})))}function ee(i,e){const n=i[e];return n?.moved?{dx:x(n.dx)-x(n.baseDx),dy:x(n.dy)-x(n.baseDy)}:{dx:0,dy:0}}function S(i,e,n,r,s){const o=1-s;return{x:o**3*i.x+3*o*o*s*e.x+3*o*s*s*n.x+s**3*r.x,y:o**3*i.y+3*o*o*s*e.y+3*o*s*s*n.y+s**3*r.y}}function te(i,e,n,r,s,o){const d=(c,E)=>({dx:(E.x-c.x)/3,dy:(E.y-c.y)/3}),u=(c,E,w)=>{const f=d(c,E),l=ee(c,w);return{x:c.x+f.dx+l.dx,y:c.y+f.dy+l.dy}},y=S(i,u(i,e,"r"),u(e,i,"l"),e,s),a=S(n,u(n,r,"r"),u(r,n,"l"),r,s),g=S(i,u(i,n,"d"),u(n,i,"u"),n,o),m=S(e,u(e,r,"d"),u(r,e,"u"),r,o),h={x:i.x*(1-s)*(1-o)+e.x*s*(1-o)+n.x*(1-s)*o+r.x*s*o,y:i.y*(1-s)*(1-o)+e.y*s*(1-o)+n.y*(1-s)*o+r.y*s*o};return{x:y.x*(1-o)+a.x*o+g.x*(1-s)+m.x*s-h.x,y:y.y*(1-o)+a.y*o+g.y*(1-s)+m.y*s-h.y}}function C(i,e){if(i.length<=2)return 0;let n=0,r=i.length;const s=e-1e-9;for(;n<r;){const o=n+r>>1;i[o]<s?n=o+1:r=o}return Math.min(Math.max(n-1,0),i.length-2)}function ne(i,e,n,r){const s=C(i.uLines,e),o=C(i.vLines,n),d=i.uLines[s+1]-i.uLines[s],u=i.vLines[o+1]-i.vLines[o],y=d>1e-9?(e-i.uLines[s])/d:0,a=u>1e-9?(n-i.vLines[o])/u:0,[g,m]=[i.grid[o][s],i.grid[o][s+1]],[h,c]=[i.grid[o+1][s],i.grid[o+1][s+1]];return r?te(g,m,h,c,y,a):{x:g.x*(1-y)*(1-a)+m.x*y*(1-a)+h.x*(1-y)*a+c.x*y*a,y:g.y*(1-y)*(1-a)+m.y*y*(1-a)+h.y*(1-y)*a+c.y*y*a}}function D(i){let e=1/0,n=1/0,r=-1/0,s=-1/0;for(const o of i)e=Math.min(e,o.x),n=Math.min(n,o.y),r=Math.max(r,o.x),s=Math.max(s,o.y);return{minX:e,minY:n,maxX:r,maxY:s}}function ie(i,e){const n=i.config??i.texture_transform??{},r=n.transform??{},s=i.textureSize??n.textureSize,o=x(s?.[0]),d=x(s?.[1]),u=e.width,y=e.height;if(!(o>0&&d>0&&u>0&&y>0&&(o!==u||d!==y)))return{...r};const g=o/u,m=d/y,h=Math.sqrt(g*m);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*h}:{},...typeof r.scale=="number"?{scale:r.scale*h}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*g}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*m}:{}}}function re(i,e,n,r){if(r||!i.length)return i;const s=D(i),o={x:(s.minX+s.maxX)/2,y:(s.minY+s.maxY)/2},d=typeof e.scaleX=="number"?e.scaleX:typeof e.scale=="number"?e.scale:n,u=typeof e.scaleY=="number"?e.scaleY:typeof e.scale=="number"?e.scale:n,y=d/(n||1)*x(e.flipX,1),a=u/(n||1)*x(e.flipY,1),g=x(e.rotation)*Math.PI/180,m=Math.cos(g),h=Math.sin(g),c=i.map(l=>{const _=(l.x-o.x)*y,T=(l.y-o.y)*a;return{x:_*m-T*h+o.x,y:_*h+T*m+o.y}}),E=D(c),w=typeof e.translateX=="number"?e.translateX-E.minX:0,f=typeof e.translateY=="number"?e.translateY-E.minY:0;return w||f?c.map(l=>({x:l.x+w,y:l.y+f})):c}function oe(i,e){if(!Z(e))return null;const n=new Float32Array(e.vertices.length);for(let r=0;r<e.vertices.length;r+=2)n[r]=i.x+e.vertices[r],n[r+1]=i.y+e.vertices[r+1];return{vertices:n,uvs:new Float32Array(e.uvs),indices:new Uint16Array(e.indices)}}function N(i,e){const n=i.config??i.texture_transform??{},r=oe(i,n);if(r)return r;const s=ie(i,e),o=J(n.mesh)?n.mesh:null;let d,u=x(s.baseScale,1);if(o){const f=q(o.grid);d=(l,_)=>ne(o,l,_,f)}else{const f=Math.max(i.width/e.width,i.height/e.height);u=typeof s.baseScale=="number"?s.baseScale:Math.min(1,f);const l=e.width*u,_=e.height*u,T=(i.width-l)/2,A=(i.height-_)/2;d=(B,Ee)=>({x:T+l*B,y:A+_*Ee})}const y=[],a=new Float32Array((v+1)**2*2);let g=0;for(let f=0;f<=v;f+=1){const l=f/v;for(let _=0;_<=v;_+=1){const T=_/v;y.push(d(T,l)),a[g++]=T,a[g++]=l}}const m=re(y,s,u,!!s.baked),h=new Float32Array(m.length*2);m.forEach((f,l)=>{h[l*2]=i.x+f.x,h[l*2+1]=i.y+f.y});const c=new Uint16Array(v*v*6);let E=0;const w=v+1;for(let f=0;f<v;f+=1)for(let l=0;l<v;l+=1){const _=f*w+l,T=_+1,A=_+w,B=A+1;c[E++]=_,c[E++]=T,c[E++]=A,c[E++]=T,c[E++]=B,c[E++]=A}return{vertices:h,uvs:a,indices:c}}const p=new OffscreenCanvas(1,1),O=p.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0});if(!O)throw new Error("WebGL2 is unavailable in the render worker");const t=O,se=\`#version 300 es
63
+ in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
64
+ out vec2 v_uv; out vec2 v_position;
65
+ void main() {
66
+ vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
67
+ gl_Position = vec4(clip * vec2(1.0, -1.0), 0.0, 1.0);
68
+ v_uv = a_uv; v_position = a_position;
69
+ }\`,ae=\`#version 300 es
70
+ precision highp float;
71
+ uniform sampler2D u_image; uniform sampler2D u_mask;
72
+ uniform int u_mode; uniform float u_opacity; uniform vec4 u_tint; uniform vec4 u_mask_rect;
73
+ in vec2 v_uv; in vec2 v_position; out vec4 out_color;
74
+ void main() {
75
+ vec4 source = texture(u_image, v_uv);
76
+ if (u_mode == 1) {
77
+ vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
78
+ if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
79
+ vec4 mask = texture(u_mask, maskUv);
80
+ source *= mask.a;
81
+ } else if (u_mode == 2) {
82
+ float tintAlpha = source.a * u_tint.a;
83
+ source = vec4(u_tint.rgb * tintAlpha, tintAlpha);
84
+ } else if (u_mode == 3) {
85
+ vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
86
+ if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
87
+ vec4 mask = texture(u_mask, maskUv);
88
+ // Compose the premultiplied artwork over its fill before clipping. Applying
89
+ // mask alpha to each term separately would count translucent edges twice.
90
+ vec4 fill = vec4(u_tint.rgb * u_tint.a, u_tint.a);
91
+ source = (source + fill * (1.0 - source.a)) * mask.a;
92
+ }
93
+ if (u_mode == 4) source = vec4(u_tint.rgb * u_tint.a, u_tint.a);
94
+ else if (u_mode == 5) source += vec4(u_tint.rgb * u_tint.a, u_tint.a) * (1.0 - source.a);
95
+ out_color = source * u_opacity;
96
+ }\`;function G(i,e){const n=t.createShader(i);if(!n)throw new Error("Could not create WebGL shader");if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(n)||"WebGL shader compilation failed");return n}const b=t.createProgram();if(!b)throw new Error("Could not create WebGL program");if(t.attachShader(b,G(t.VERTEX_SHADER,se)),t.attachShader(b,G(t.FRAGMENT_SHADER,ae)),t.linkProgram(b),!t.getProgramParameter(b,t.LINK_STATUS))throw new Error(t.getProgramInfoLog(b)||"WebGL program link failed");const Y=t.getAttribLocation(b,"a_position"),W=t.getAttribLocation(b,"a_uv"),ce=t.getUniformLocation(b,"u_resolution"),le=t.getUniformLocation(b,"u_image"),ue=t.getUniformLocation(b,"u_mask"),fe=t.getUniformLocation(b,"u_mode"),de=t.getUniformLocation(b,"u_opacity"),me=t.getUniformLocation(b,"u_tint"),he=t.getUniformLocation(b,"u_mask_rect");function H(i,e=!1){if(e)return i;const n=t.createTexture();if(!n)throw new Error("Could not create WebGL texture");return t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i),n}function ge(i){const e=String(i??"normal").toLowerCase();t.enable(t.BLEND),e==="multiply"||e==="2"?t.blendFuncSeparate(t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA):t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)}function F(i){if(!i)return[1,1,1,1];const e=/^#([\\da-f]{3})$/i.exec(i),n=/^#([\\da-f]{6})$/i.exec(i),r=/^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([+-]?(?:\\d*\\.)?\\d+))?/i.exec(i);let s=null;e&&(s=e[1].split("").map(d=>Number.parseInt(d+d,16))),n&&(s=[n[1].slice(0,2),n[1].slice(2,4),n[1].slice(4,6)].map(d=>Number.parseInt(d,16))),r&&(s=[Number(r[1]),Number(r[2]),Number(r[3])]);const o=r?.[4]===void 0?1:Math.max(0,Math.min(1,Number(r[4])));return s?[s[0]/255,s[1]/255,s[2]/255,o]:[1,1,1,1]}function z(i,e,n,r){return{vertices:new Float32Array([i,e,i+n,e,i,e+r,i+n,e+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function R(i,e,n={}){t.useProgram(b),ge(n.blend);const r=t.createBuffer(),s=t.createBuffer(),o=t.createBuffer();if(!r||!s||!o)throw new Error("Could not allocate WebGL geometry");t.bindBuffer(t.ARRAY_BUFFER,r),t.bufferData(t.ARRAY_BUFFER,i.vertices,t.STREAM_DRAW),t.enableVertexAttribArray(Y),t.vertexAttribPointer(Y,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,i.uvs,t.STATIC_DRAW),t.enableVertexAttribArray(W),t.vertexAttribPointer(W,2,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,o),t.bufferData(t.ELEMENT_ARRAY_BUFFER,i.indices,t.STATIC_DRAW),t.activeTexture(t.TEXTURE0);const d=H(e,n.imageIsTexture);t.bindTexture(t.TEXTURE_2D,d),t.uniform1i(le,0);let u=null;n.mask&&(t.activeTexture(t.TEXTURE1),u=H(n.mask),t.bindTexture(t.TEXTURE_2D,u),t.uniform1i(ue,1)),t.uniform2f(ce,p.width,p.height),t.uniform1i(fe,n.mode??0),t.uniform1f(de,n.opacity??1),t.uniform4fv(me,n.tint??[1,1,1,1]),t.uniform4fv(he,n.maskRect??[0,0,1,1]),t.drawElements(t.TRIANGLES,i.indices.length,t.UNSIGNED_SHORT,0),t.deleteBuffer(r),t.deleteBuffer(s),t.deleteBuffer(o),n.imageIsTexture||t.deleteTexture(d),u&&t.deleteTexture(u)}function ye(i,e){const n=t.createTexture(),r=t.createFramebuffer();if(!n||!r)throw new Error("Could not allocate WebGL layer target");if(t.bindTexture(t.TEXTURE_2D,n),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,i,e,0,t.RGBA,t.UNSIGNED_BYTE,null),t.bindFramebuffer(t.FRAMEBUFFER,r),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,n,0),t.checkFramebufferStatus(t.FRAMEBUFFER)!==t.FRAMEBUFFER_COMPLETE)throw new Error("WebGL layer framebuffer is incomplete");return t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindTexture(t.TEXTURE_2D,null),{texture:n,framebuffer:r}}async function _e(i){const e=new Set;let n;try{const r=i.areas.find(a=>a.name==="bg");if(!r)throw new Error("WebGL worker rendering requires a bg render area");const s=x(i.options.targetSize),o=s>0?s/Math.max(r.width,r.height):Math.max(.1,x(i.options.scale,1)),d=i.options.composition==="design-layer";p.width=Math.max(1,Math.round(r.width*o)),p.height=Math.max(1,Math.round(r.height*o)),t.viewport(0,0,p.width,p.height),t.bindFramebuffer(t.FRAMEBUFFER,null),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);const u=new Set;for(const a of i.areas)d&&!a.design||P(a,i.options.color)&&(typeof a.image=="string"&&a.image&&u.add(a.image),typeof a.texture=="string"&&u.add(a.texture));await Promise.all([...u].map(a=>k(a,e)));const y=a=>z(a.x*o,a.y*o,a.width*o,a.height*o);for(const a of i.areas){if(d&&!a.design||!P(a,i.options.color))continue;const g=await k(a.image,e);if(!g)continue;if(!a.design){R(y(a),g,{blend:a.export?.blend,opacity:U(a.export?.opacity)});continue}const m=await k(a.texture,e),h=i.options.color??a.color,c=a.config??a.texture_transform??{},E=d?"normal":c.blendMode??"multiply",w=I(a.defaultPrintColor);if(w){n??=ye(p.width,p.height),t.bindFramebuffer(t.FRAMEBUFFER,n.framebuffer),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);const f=c.textureSize??[a.width,a.height],l=N(a,m??{width:f[0],height:f[1]});for(let A=0;A<l.vertices.length;A++)l.vertices[A]*=o;R(l,g,{mode:4,tint:F(w),blend:"normal"});const _=c.blendMode??(h?"multiply":"normal");m?R(l,m,{mode:h?5:0,tint:F(h),blend:_}):h&&R(l,g,{mode:4,tint:F(h),blend:_}),t.bindFramebuffer(t.FRAMEBUFFER,null);const T=z(0,0,p.width,p.height);T.uvs=new Float32Array([0,1,1,1,0,0,1,0]),R(T,n.texture,{imageIsTexture:!0,mode:1,mask:g,maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:"normal",opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&m?.close();continue}if(m){const f=N(a,m);for(let l=0;l<f.vertices.length;l+=1)f.vertices[l]*=o;d?R(f,m,{mode:1,mask:g,maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:"normal",opacity:U(c.opacity)}):h?R(f,m,{mode:3,mask:g,tint:F(h),maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:E,opacity:U(c.opacity)}):R(f,m,{mode:1,mask:g,maskRect:[a.x*o,a.y*o,a.width*o,a.height*o],blend:d?"normal":c.blendMode,opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&m.close()}else h&&R(y(a),g,{mode:2,tint:F(h),blend:E,opacity:U(c.opacity)})}t.finish();try{return await p.convertToBlob({type:i.options.format??"image/png",quality:i.options.quality??.9})}catch{return p.convertToBlob({type:"image/png"})}}finally{Q(i.areas),n&&(t.deleteFramebuffer(n.framebuffer),t.deleteTexture(n.texture)),j(e)}}self.onmessage=async i=>{const e=i.data;if(e.type==="preload"){try{await Promise.all([...new Set(e.sources)].map(n=>L.has(n)?Promise.resolve():X.load(n,e.priority===!0))),self.postMessage({type:"preloaded",id:e.id})}catch(n){self.postMessage({type:"error",id:e.id,message:n instanceof Error?n.message:String(n)})}return}if(e.type==="render")try{self.postMessage({type:"result",id:e.id,blob:await _e(e)})}catch(n){self.postMessage({type:"error",id:e.id,message:n instanceof Error?n.message:String(n)})}}})();
97
+ `, k = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", S], { type: "text/javascript;charset=utf-8" });
98
+ function N(r) {
99
+ let e;
100
+ try {
101
+ if (e = k && (self.URL || self.webkitURL).createObjectURL(k), !e) throw "";
102
+ const t = new Worker(e, {
103
+ name: r?.name
104
+ });
105
+ return t.addEventListener("error", () => {
106
+ (self.URL || self.webkitURL).revokeObjectURL(e);
107
+ }), t;
108
+ } catch {
109
+ return new Worker(
110
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(S),
111
+ {
112
+ name: r?.name
113
+ }
114
+ );
115
+ }
116
+ }
117
+ const D = 32 * 1024 * 1024;
118
+ function L(r, e = 0) {
119
+ return typeof r == "number" && Number.isFinite(r) ? r : e;
120
+ }
121
+ function X(r, e) {
122
+ const t = r.find((o) => o.name === "bg");
123
+ if (!t) return;
124
+ const n = L(e.targetSize);
125
+ return n > 0 ? n / Math.max(t.width, t.height) : Math.max(0.1, L(e.scale, 1));
126
+ }
127
+ function O(r, e) {
128
+ return e.composition === "design-layer" && !r.design ? !1 : C(r, e.color);
129
+ }
130
+ function U(r, e, t) {
131
+ return `${r}\0${e}\0${t}`;
132
+ }
133
+ async function W(r) {
134
+ if (r.startsWith("blob:"))
135
+ try {
136
+ const e = await fetch(r);
137
+ return e.ok ? (await e.blob()).type.toLowerCase().includes("svg") : !1;
138
+ } catch {
139
+ return !1;
140
+ }
141
+ return B(r);
142
+ }
143
+ function G(r) {
144
+ return new Promise((e, t) => {
145
+ const n = new Image();
146
+ n.onload = () => e(n), n.onerror = () => t(new Error("SVG image load failed")), n.src = r;
147
+ });
148
+ }
149
+ async function Y(r, e, t) {
150
+ if (!Number.isFinite(e) || !Number.isFinite(t) || e < 1 || t < 1)
151
+ throw new Error("Invalid SVG raster size");
152
+ const n = await fetch(r);
153
+ if (!n.ok) throw new Error(`Could not load render asset (${n.status})`);
154
+ const o = await n.blob(), c = o.type.toLowerCase().includes("svg") ? o : new Blob([o], { type: "image/svg+xml" }), a = URL.createObjectURL(c);
155
+ let s;
156
+ try {
157
+ const l = await G(a);
158
+ s = document.createElement("canvas"), s.width = e, s.height = t;
159
+ const d = s.getContext("2d");
160
+ if (!d) throw new Error("Canvas context creation failed");
161
+ return d.drawImage(l, 0, 0, e, t), await createImageBitmap(s);
162
+ } finally {
163
+ URL.revokeObjectURL(a), s && (s.width = 0, s.height = 0);
164
+ }
165
+ }
166
+ function y(r) {
167
+ if (!r) return r;
168
+ const e = typeof document < "u" ? document.baseURI : typeof location < "u" ? location.href : void 0;
169
+ if (!e) return r;
170
+ try {
171
+ return new URL(r, e).href;
172
+ } catch {
173
+ return r;
174
+ }
175
+ }
176
+ class M {
177
+ constructor() {
178
+ this.worker = null, this.nextRequestId = 0, this.pending = /* @__PURE__ */ new Map(), this.renderQueue = Promise.resolve(), this.svgChecks = /* @__PURE__ */ new Map(), this.rasterCache = /* @__PURE__ */ new Map(), this.rasterCacheBytes = 0, this.rasterPins = /* @__PURE__ */ new Set();
179
+ }
180
+ static isSupported() {
181
+ return typeof Worker < "u" && typeof OffscreenCanvas < "u" && typeof createImageBitmap < "u";
182
+ }
183
+ ensureWorker() {
184
+ if (this.worker) return this.worker;
185
+ if (!M.isSupported()) throw new Error("Pixel-map rendering requires Worker, OffscreenCanvas, and ImageBitmap support");
186
+ const e = new N();
187
+ return e.onmessage = (t) => {
188
+ const n = t.data, o = this.pending.get(n.id);
189
+ o && (this.pending.delete(n.id), n.type === "result" ? o.resolve(n.blob) : n.type === "preloaded" ? o.resolve(null) : o.reject(new Error(n.message)));
190
+ }, e.onerror = (t) => {
191
+ const n = t.filename ? ` (${t.filename}:${t.lineno}:${t.colno})` : "", o = t.error instanceof Error ? t.error : new Error(`${t.message || "Pixel-map worker failed"}${n}`);
192
+ this.pending.forEach(({ reject: c }) => c(o)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
193
+ }, e.onmessageerror = () => {
194
+ const t = new Error("Pixel-map worker could not deserialize its render payload");
195
+ this.pending.forEach(({ reject: n }) => n(t)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
196
+ }, this.worker = e, e;
197
+ }
198
+ isSvgImage(e) {
199
+ const t = this.svgChecks.get(e);
200
+ if (t) return t;
201
+ const n = W(e);
202
+ return this.svgChecks.set(e, n), n;
203
+ }
204
+ rasterizeSvgLayer(e, t, n) {
205
+ const o = U(e, t, n), c = this.rasterCache.get(o);
206
+ if (c)
207
+ return this.rasterCache.delete(o), this.rasterCache.set(o, c), c.promise;
208
+ const a = { bytes: 0, promise: Y(e, t, n) };
209
+ return this.rasterCache.set(o, a), a.promise.then((s) => {
210
+ if (this.rasterCache.get(o) !== a) {
211
+ s.close();
212
+ return;
213
+ }
214
+ a.bitmap = s, a.bytes = t * n * 4, this.rasterCacheBytes += a.bytes, this.rasterCache.delete(o), this.rasterCache.set(o, a), this.trimRasterCache();
215
+ }).catch(() => {
216
+ this.rasterCache.get(o) === a && this.rasterCache.delete(o);
217
+ }), a.promise;
218
+ }
219
+ trimRasterCache() {
220
+ for (const [e, t] of this.rasterCache) {
221
+ if (this.rasterCacheBytes <= D) break;
222
+ this.rasterPins.has(e) || !t.bitmap || (this.rasterCache.delete(e), this.rasterCacheBytes -= t.bytes, t.bitmap.close());
223
+ }
224
+ }
225
+ /** Warm compressed resources without exporting Fabric or entering the GPU queue. */
226
+ async preloadAssets(e, t = !1) {
227
+ const n = [...new Set(e.filter(Boolean).map(y))];
228
+ if (!n.length) return;
229
+ const o = this.ensureWorker(), c = ++this.nextRequestId;
230
+ await new Promise((a, s) => {
231
+ this.pending.set(c, { resolve: a, reject: s });
232
+ try {
233
+ o.postMessage({ type: "preload", id: c, sources: n, priority: t });
234
+ } catch (l) {
235
+ this.pending.delete(c), s(l instanceof Error ? l : new Error(String(l)));
236
+ }
237
+ });
238
+ }
239
+ async onOffscreenRender(e, t = {}) {
240
+ const n = e.flatMap((s) => t.composition === "design-layer" && !s.design ? [] : C(s, t.color) ? [s.image, typeof s.texture == "string" ? s.texture : ""] : []), o = this.preloadAssets(n, !0);
241
+ o.catch(() => {
242
+ });
243
+ const c = async () => {
244
+ await o;
245
+ const s = this.ensureWorker(), l = ++this.nextRequestId, d = X(e, t), x = /* @__PURE__ */ new Set(), m = [];
246
+ let v = !0;
247
+ const _ = (f) => (v ? m.push(f) : f.close(), f);
248
+ try {
249
+ const f = d === void 0 ? [] : e.flatMap((i) => {
250
+ if (!O(i, t) || !i.image) return [];
251
+ const u = y(i.image);
252
+ return [{ area: i, source: u, svg: this.isSvgImage(u) }];
253
+ }), g = [];
254
+ for (const i of f)
255
+ await i.svg && g.push(i);
256
+ const R = /* @__PURE__ */ new Map(), P = d === void 0 ? [] : g.map((i) => {
257
+ const u = Math.max(1, Math.round(i.area.width * d)), p = Math.max(1, Math.round(i.area.height * d)), h = U(i.source, u, p);
258
+ return this.rasterPins.add(h), x.add(h), { candidate: i, pending: this.rasterizeSvgLayer(i.source, u, p) };
259
+ });
260
+ for (const i of P)
261
+ try {
262
+ const u = await i.pending;
263
+ R.set(i.candidate.area, _(await createImageBitmap(u)));
264
+ } catch (u) {
265
+ throw new Error(`Could not rasterize SVG render layer "${i.candidate.area.name}"`, { cause: u });
266
+ }
267
+ const T = await Promise.all(e.map(async (i) => {
268
+ const u = i.texture instanceof ImageBitmap ? _(await createImageBitmap(i.texture)) : typeof i.texture == "string" ? y(i.texture) : i.texture;
269
+ return {
270
+ ...i,
271
+ image: R.get(i) ?? y(i.image),
272
+ texture: u
273
+ };
274
+ })), F = T.flatMap((i) => [
275
+ i.texture instanceof ImageBitmap ? i.texture : void 0,
276
+ i.image instanceof ImageBitmap ? i.image : void 0
277
+ ].filter((u) => u instanceof ImageBitmap));
278
+ return await new Promise((i, u) => {
279
+ this.pending.set(l, { resolve: i, reject: u });
280
+ const p = { type: "render", id: l, areas: T, options: t };
281
+ try {
282
+ s.postMessage(p, F), m.length = 0;
283
+ } catch (h) {
284
+ this.pending.delete(l), u(h instanceof Error ? h : new Error(String(h)));
285
+ }
286
+ });
287
+ } catch (f) {
288
+ v = !1;
289
+ for (const g of m) g.close();
290
+ throw m.length = 0, f;
291
+ } finally {
292
+ for (const f of x) this.rasterPins.delete(f);
293
+ this.trimRasterCache();
294
+ }
295
+ }, a = this.renderQueue.then(c, c);
296
+ return this.renderQueue = a.then(() => {
297
+ }, () => {
298
+ }), a;
299
+ }
300
+ destroy() {
301
+ this.worker?.terminate(), this.worker = null, this.pending.forEach(({ reject: e }) => e(new Error("Pixel-map renderer was destroyed"))), this.pending.clear(), this.renderQueue = Promise.resolve();
302
+ for (const e of this.rasterCache.values()) e.bitmap?.close();
303
+ this.rasterCache.clear(), this.rasterCacheBytes = 0, this.rasterPins.clear(), this.svgChecks.clear();
304
+ }
305
+ }
306
+ export {
307
+ j as M,
308
+ M as P,
309
+ C as a,
310
+ H as b,
311
+ q as h,
312
+ w as i,
313
+ E as n,
314
+ I as r
315
+ };
@@ -1,5 +1,5 @@
1
1
  import { ALPHA_MODES as I, BLEND_MODES as g, MeshMaterial as v, Texture as S, Mesh as F, SpriteMaskFilter as O, RenderTexture as _, Assets as L } from "pixi.js";
2
- import { n as T } from "./pixel-map-BvQ0VU_i.js";
2
+ import { n as T } from "./pixel-map-CSpWvUYE.js";
3
3
  const N = (t) => typeof t == "number" && Number.isFinite(t) ? Math.max(0, Math.min(1, t > 1 ? t / 255 : t)) : 1, B = (t) => String(t).toLowerCase() === "multiply" || t === 2 ? g.MULTIPLY : g.NORMAL;
4
4
  let D = 0;
5
5
  async function U(t, c) {
@@ -23,16 +23,23 @@ export interface PixelMapRenderOptions {
23
23
  cacheKey?: string | number;
24
24
  }
25
25
  /**
26
- * A small client for the pixel-mapping Worker. It owns neither textures nor
27
- * object URLs, so callers can keep their current Fabric/Pixi lifecycle rules.
26
+ * A small client for the pixel-mapping Worker. Callers keep their textures
27
+ * and object URLs; SVG rasters cached here are closed in destroy().
28
28
  */
29
29
  export declare class PixelMapRenderer {
30
30
  private worker;
31
31
  private nextRequestId;
32
32
  private pending;
33
33
  private renderQueue;
34
+ private svgChecks;
35
+ private rasterCache;
36
+ private rasterCacheBytes;
37
+ private rasterPins;
34
38
  static isSupported(): boolean;
35
39
  private ensureWorker;
40
+ private isSvgImage;
41
+ private rasterizeSvgLayer;
42
+ private trimRasterCache;
36
43
  /** Warm compressed resources without exporting Fabric or entering the GPU queue. */
37
44
  preloadAssets(sources: string[], priority?: boolean): Promise<void>;
38
45
  onOffscreenRender(areas: PixelMapArea[], options?: PixelMapRenderOptions): Promise<Blob | null>;
@@ -1,7 +1,7 @@
1
1
  import { jsxs as Ae, jsx as H } from "react/jsx-runtime";
2
2
  import { forwardRef as Ge, useRef as S, useState as Z, useCallback as N, useEffect as ie, useImperativeHandle as Je } from "react";
3
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";
4
+ import { P as Ye, h as Qe, r as Ze, i as pe, M as $e, a as je } from "./pixel-map-CSpWvUYE.js";
5
5
  import "./engine/fabric.js";
6
6
  import { v4 as et } from "uuid";
7
7
  import { cloneObject as G, urlToDataURL as tt } from "./engine/utils/common.js";
@@ -1291,7 +1291,7 @@ const Bt = Ge(
1291
1291
  quality: 0.85,
1292
1292
  format: "image/png",
1293
1293
  cacheKey: e.id
1294
- }) : await (await import("./pixi-print-base-CKs4lF7h.js")).renderPixiWithPrintBase(V, ke, {
1294
+ }) : await (await import("./pixi-print-base-DIvtSF7v.js")).renderPixiWithPrintBase(V, ke, {
1295
1295
  color: Se,
1296
1296
  cleanCache: !1,
1297
1297
  scale: o,
@@ -1,4 +1,4 @@
1
- import { P as i, a as n } from "./semi-interact-editor-nZVBXXQn.js";
1
+ import { P as i, a as n } from "./semi-interact-editor-DpzQN5ZB.js";
2
2
  export {
3
3
  i as PrintineSemiInteractEditor,
4
4
  n as PrintineSemiRenderer
@@ -245,7 +245,7 @@ interface RenderArea {
245
245
  }
246
246
  ```
247
247
 
248
- 对于实时 2D 合成,`image`、`texture`、坐标尺寸和 `area.name` 都应返回。`name === "bg"` 的 `image` 也会在合成尚未完成时作为预览回退图。
248
+ 对于实时 2D 合成,`image`、`texture`、坐标尺寸和 `area.name` 都应返回。`name === "bg"` 的 `image` 也会在合成尚未完成时作为预览回退图。`render_areas[].image` 可以是 PNG、JPEG、WebP 或 SVG;SVG 图层会在主线程按合成像素尺寸栅格化后再参与合成,SVG 文件应声明 `width`/`height`(不能只有 `viewBox`),以便所有浏览器都能栅格化。
249
249
 
250
250
  ### 3D 渲染:`TDRender` 与 `TDRenderArea`
251
251
 
@@ -76,7 +76,7 @@ Worker 解码都使用这些本地 URL,不再各自请求远程图片。宿主
76
76
  宿主只需切换 `render` 到当前视角,其他视角不必挂载渲染器。修改设计后,宿主按
77
77
  版本标记旧结果失效;切换到已缓存的最新结果时保持 `enabled={false}`,直接展示缓存图。
78
78
  暂停会清除旧待执行任务,并阻止正在执行的过期结果发布,但不会销毁会话资源缓存。
79
- `updateText()` 在暂停时仍可用于文字适配,`enabled` 默认 `true`,兼容既有调用方。
79
+ `enabled` 默认 `true`。设为 `false` 只暂停合成,不销毁文字适配用的 Fabric 编辑器,因此 `updateText()` 在暂停时仍可调用。
80
80
 
81
81
  非当前视角压缩资源采用 32 MiB LRU 预算,当前视角与在执行任务的资源会保留,即使
82
82
  单个视角超过预算,也不会因后台预加载完成而被淘汰。网络最多同时加载 4 个资源;当前图的请求优先于
@@ -128,6 +128,42 @@ Worker 解码都使用这些本地 URL,不再各自请求远程图片。宿主
128
128
  - `getPreviewUrl()`:为当前结果新建 object URL。调用方负责 `URL.revokeObjectURL()`。
129
129
  - `refresh()`:当图片 URL 的内容原地更新、但 `designData` 引用不变时,使 Fabric
130
130
  纹理和 Worker 资源缓存失效并强制重新合成。
131
+ - `updateText(rawObject, changes)`:按半定制规则计算文字补丁。它不修改 `designData`,
132
+ 也不触发渲染。宿主把返回值合并进对应 Fabric 对象后,再把新的 `designData` 交给渲染器。
133
+
134
+ ### `updateText`
135
+
136
+ 只接受 `type` 为 `text`,或 `type` 字符串中包含 `i-text` 的对象(含 `advanced-i-text`)。
137
+ 其他类型、对象无法恢复,或内部画布尚未挂载时返回 `null`。`changes` 会先作用于恢复出的对象,
138
+ 常见字段是 `text`、`fill`、`fontFamily`、`fontWeight`、`fontStyle`。`changes.fontPath`
139
+ 有值时,会先按 `fontFamily`、`fontWeight`、`fontStyle` 加载字体。
140
+
141
+ 不要只改对象里的 `text`。Fabric 会沿用原来的 `width` 和缩放,更长的字符串会被裁进旧宽度。
142
+
143
+ 固定框由对象自己的 `customConfig` 决定:`originalWidth` 与 `originalHeight` 都是大于 0 的数,
144
+ 且 `moveable` 不为真。此时把未缩放文字放进这个框里,取宽、高两个方向里更小的缩放(contain),
145
+ 再放回框中心。翻转由原来的 `scaleX` / `scaleY` 符号保留。中心和翻转符号会写入返回的
146
+ `__semiTargetInfo`;宿主必须保留该字段,下次更新才会继续锁在这个中心。丢掉它时,中心改取对象当前的 `getCenterPoint()`。
147
+
148
+ 不满足固定框条件时不做框内适配,只更新内容和字体并重新测量。普通文字保持原锚点;
149
+ 带 `radius` 的 `advanced-i-text` 保持中心点。
150
+
151
+ 返回值在 `changes` 之上覆盖这些几何字段,宿主应整份合并:
152
+
153
+ - `text`、`left`、`top`、`width`、`height`
154
+ - `scaleX`、`scaleY`、`angle`、`originX`、`originY`
155
+ - `selectable`:取调用时传入对象上的值
156
+ - 固定框时还有 `__semiTargetInfo`:`{ width, height, centerX, centerY, signX, signY }`
157
+ - 对象上已有的运行时字段会原样带回:`__baseWidth`、`__baseHeight`、`__basePadding`、
158
+ `__baseObjectCaching`、`__curvedCenterX`、`__curvedCenterY`、`__lastCurvedWidth`、
159
+ `__lastCurvedHeight`、`__lastCurvedCenterX`、`__lastCurvedCenterY`、`__rawText`、
160
+ `orientation`、`radius`、`spacing`
161
+
162
+ ```ts
163
+ const patch = await rendererRef.current?.updateText(textObject, { text: nextText });
164
+ if (!patch) return;
165
+ const nextObject = { ...textObject, ...patch };
166
+ ```
131
167
 
132
168
  ## Move 交互
133
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@printine/pod-editor",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "React online product designer with Fabric canvas and host-owned commerce integrations.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -1,199 +0,0 @@
1
- import { jsxs as p, jsx as f } from "react/jsx-runtime";
2
- function A({ image: t, alt: e = "Product preview", loading: r, failed: n, onRetry: i }) {
3
- return /* @__PURE__ */ p("div", { "data-print-material-preview": "true", style: { position: "relative", width: "100%", height: "100%", minHeight: 80 }, children: [
4
- t && /* @__PURE__ */ f("img", { src: t, alt: e, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
5
- (!t || n) && /* @__PURE__ */ p("div", { role: n ? "alert" : "status", "aria-live": "polite", style: {
6
- position: "absolute",
7
- inset: 0,
8
- minHeight: 80,
9
- display: "flex",
10
- flexDirection: "column",
11
- alignItems: "center",
12
- justifyContent: "center",
13
- gap: 8,
14
- padding: 12,
15
- textAlign: "center",
16
- background: "#f3f4f6",
17
- color: "#374151",
18
- fontSize: 12
19
- }, children: [
20
- /* @__PURE__ */ f("span", { children: n ? "Preview could not be generated." : "Generating preview…" }),
21
- n && i && /* @__PURE__ */ f(
22
- "button",
23
- {
24
- type: "button",
25
- disabled: r,
26
- onClick: (s) => {
27
- s.stopPropagation(), i();
28
- },
29
- style: { border: "1px solid #9ca3af", borderRadius: 4, background: "#fff", padding: "5px 12px", cursor: "pointer" },
30
- children: "Retry"
31
- }
32
- )
33
- ] })
34
- ] });
35
- }
36
- function h(t) {
37
- return typeof t == "string" && /^#[\da-f]{6}$/i.test(t) ? t.toLowerCase() : void 0;
38
- }
39
- function w(t, e, r = !!t.texture) {
40
- return !t.design || r || !!(e ?? t.color) || !!h(t.defaultPrintColor);
41
- }
42
- function m(...t) {
43
- for (const e of t) if (e !== void 0) return e === null ? null : h(e) ?? null;
44
- }
45
- function v(t, e) {
46
- const r = m(t.defaultPrintColor, e);
47
- return { ...t, defaultPrintColor: r, render_areas: t.render_areas.map((n) => ({
48
- ...n,
49
- defaultPrintColor: n.design ? m(n.defaultPrintColor, n.area?.defaultPrintColor, r) : void 0
50
- })) };
51
- }
52
- function U(t) {
53
- return { ...t, areas: t.areas.map((e) => ({
54
- ...e,
55
- defaultPrintColor: m(e.defaultPrintColor, t.defaultPrintColor)
56
- })), renders: (t.renders || []).map((e) => v(e, t.defaultPrintColor)) };
57
- }
58
- function L(t) {
59
- return t.some((e) => e.design && !!h(e.defaultPrintColor));
60
- }
61
- const b = `(function(){"use strict";class V{constructor(t=32*1024*1024,n=4,r){this.budget=t,this.concurrency=n,this.onEvict=r,this.entries=new Map,this.bytes=0,this.active=0,this.waiting=[],this.pinned=new Set}setPinnedSources(t){this.pinned=new Set(t),this.waiting.forEach(n=>{n.foreground=this.pinned.has(n.source)}),this.waiting.sort((n,r)=>Number(r.foreground)-Number(n.foreground)),this.trim()}trim(){for(const[t,n]of this.entries){if(this.bytes<=this.budget)break;!n.bytes||this.pinned.has(t)||(this.entries.delete(t),this.bytes-=n.bytes,this.onEvict?.(t))}}clear(){for(const t of this.waiting.splice(0))t.cancel();for(const t of this.entries.keys())this.onEvict?.(t);this.entries.clear(),this.pinned.clear(),this.bytes=0}promote(t){const n=this.waiting.findIndex(s=>s.source===t&&!s.foreground);if(n<0)return;const[r]=this.waiting.splice(n,1);r.foreground=!0;const o=this.waiting.findIndex(s=>!s.foreground);this.waiting.splice(o<0?this.waiting.length:o,0,r)}async fetchBlob(t,n){await new Promise((r,o)=>{const s=()=>{this.active+=1,r()};this.active<this.concurrency?s():(this.waiting.push({source:t,foreground:!1,start:s,cancel:()=>o(new Error("Resource cache was released"))}),n&&this.promote(t))});try{const r=await fetch(t);if(!r.ok)throw new Error(\`Could not load render asset (\${r.status})\`);return await r.blob()}finally{this.active-=1,this.waiting.shift()?.start()}}load(t,n=!0){const r=this.entries.get(t);if(r)return this.entries.delete(t),this.entries.set(t,r),n&&this.promote(t),r.ready;const o={ready:this.fetchBlob(t,n),bytes:0};return this.entries.set(t,o),o.ready.then(s=>{this.entries.get(t)===o&&(o.bytes=s.size,this.bytes+=o.bytes,this.trim())}).catch(()=>{this.entries.get(t)===o&&this.entries.delete(t)}),o.ready}}function I(i){return typeof i=="string"&&/^#[\\da-f]{6}$/i.test(i)?i.toLowerCase():void 0}function P(i,t,n=!!i.texture){return!i.design||n||!!(t??i.color)||!!I(i.defaultPrintColor)}const v=44,$=32*1024*1024,L=new Map;let M=0;const X=new V;function x(i,t=0){return typeof i=="number"&&Number.isFinite(i)?i:t}function U(i,t=1){const n=x(i,t);return Math.max(0,Math.min(1,n>1?n/255:n))}function j(i=new Set){for(const[t,n]of L){if(M<=$)break;i.has(t)||!n.bitmap||(L.delete(t),M-=n.bytes,n.bitmap.close())}}async function k(i,t){if(!i)return null;if(i instanceof ImageBitmap)return i;t.add(i);let n=L.get(i);return n?(L.delete(i),L.set(i,n)):(n={bytes:0,promise:X.load(i).then(createImageBitmap)},L.set(i,n),n.promise.then(r=>{n.bitmap=r,n.bytes=r.width*r.height*4,M+=n.bytes}).catch(()=>L.delete(i))),n.promise}function K(i){const t=i;return!!t&&Array.isArray(t.uLines)&&t.uLines.length>=2&&Array.isArray(t.vLines)&&t.vLines.length>=2&&Array.isArray(t.grid)&&t.grid.length===t.vLines.length&&t.grid.every(n=>Array.isArray(n)&&n.length===t.uLines.length)}function Q(i){const t=i;if(!t||!Array.isArray(t.vertices)||!Array.isArray(t.uvs)||!Array.isArray(t.indices)||!t.vertices.length||t.vertices.length%2!==0||t.uvs.length!==t.vertices.length||!t.indices.length||t.indices.length%3!==0)return!1;const n=t.vertices.length/2;return t.vertices.every(Number.isFinite)&&t.uvs.every(Number.isFinite)&&t.indices.every(r=>Number.isInteger(r)&&r>=0&&r<n&&r<=65535)}function J(i){return i.some(t=>t.some(n=>["r","l","u","d"].some(r=>{const o=n[r];return typeof o=="object"&&!!o.moved})))}function Z(i,t){const n=i[t];return n?.moved?{dx:x(n.dx)-x(n.baseDx),dy:x(n.dy)-x(n.baseDy)}:{dx:0,dy:0}}function S(i,t,n,r,o){const s=1-o;return{x:s**3*i.x+3*s*s*o*t.x+3*s*o*o*n.x+o**3*r.x,y:s**3*i.y+3*s*s*o*t.y+3*s*o*o*n.y+o**3*r.y}}function q(i,t,n,r,o,s){const m=(c,b)=>({dx:(b.x-c.x)/3,dy:(b.y-c.y)/3}),u=(c,b,R)=>{const f=m(c,b),l=Z(c,R);return{x:c.x+f.dx+l.dx,y:c.y+f.dy+l.dy}},d=S(i,u(i,t,"r"),u(t,i,"l"),t,o),a=S(n,u(n,r,"r"),u(r,n,"l"),r,o),g=S(i,u(i,n,"d"),u(n,i,"u"),n,s),h=S(t,u(t,r,"d"),u(r,t,"u"),r,s),y={x:i.x*(1-o)*(1-s)+t.x*o*(1-s)+n.x*(1-o)*s+r.x*o*s,y:i.y*(1-o)*(1-s)+t.y*o*(1-s)+n.y*(1-o)*s+r.y*o*s};return{x:d.x*(1-s)+a.x*s+g.x*(1-o)+h.x*o-y.x,y:d.y*(1-s)+a.y*s+g.y*(1-o)+h.y*o-y.y}}function C(i,t){if(i.length<=2)return 0;let n=0,r=i.length;const o=t-1e-9;for(;n<r;){const s=n+r>>1;i[s]<o?n=s+1:r=s}return Math.min(Math.max(n-1,0),i.length-2)}function ee(i,t,n,r){const o=C(i.uLines,t),s=C(i.vLines,n),m=i.uLines[o+1]-i.uLines[o],u=i.vLines[s+1]-i.vLines[s],d=m>1e-9?(t-i.uLines[o])/m:0,a=u>1e-9?(n-i.vLines[s])/u:0,[g,h]=[i.grid[s][o],i.grid[s][o+1]],[y,c]=[i.grid[s+1][o],i.grid[s+1][o+1]];return r?q(g,h,y,c,d,a):{x:g.x*(1-d)*(1-a)+h.x*d*(1-a)+y.x*(1-d)*a+c.x*d*a,y:g.y*(1-d)*(1-a)+h.y*d*(1-a)+y.y*(1-d)*a+c.y*d*a}}function D(i){let t=1/0,n=1/0,r=-1/0,o=-1/0;for(const s of i)t=Math.min(t,s.x),n=Math.min(n,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return{minX:t,minY:n,maxX:r,maxY:o}}function te(i,t){const n=i.config??i.texture_transform??{},r=n.transform??{},o=i.textureSize??n.textureSize,s=x(o?.[0]),m=x(o?.[1]),u=t.width,d=t.height;if(!(s>0&&m>0&&u>0&&d>0&&(s!==u||m!==d)))return{...r};const g=s/u,h=m/d,y=Math.sqrt(g*h);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*y}:{},...typeof r.scale=="number"?{scale:r.scale*y}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*g}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*h}:{}}}function ne(i,t,n,r){if(r||!i.length)return i;const o=D(i),s={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},m=typeof t.scaleX=="number"?t.scaleX:typeof t.scale=="number"?t.scale:n,u=typeof t.scaleY=="number"?t.scaleY:typeof t.scale=="number"?t.scale:n,d=m/(n||1)*x(t.flipX,1),a=u/(n||1)*x(t.flipY,1),g=x(t.rotation)*Math.PI/180,h=Math.cos(g),y=Math.sin(g),c=i.map(l=>{const _=(l.x-s.x)*d,T=(l.y-s.y)*a;return{x:_*h-T*y+s.x,y:_*y+T*h+s.y}}),b=D(c),R=typeof t.translateX=="number"?t.translateX-b.minX:0,f=typeof t.translateY=="number"?t.translateY-b.minY:0;return R||f?c.map(l=>({x:l.x+R,y:l.y+f})):c}function ie(i,t){if(!Q(t))return null;const n=new Float32Array(t.vertices.length);for(let r=0;r<t.vertices.length;r+=2)n[r]=i.x+t.vertices[r],n[r+1]=i.y+t.vertices[r+1];return{vertices:n,uvs:new Float32Array(t.uvs),indices:new Uint16Array(t.indices)}}function N(i,t){const n=i.config??i.texture_transform??{},r=ie(i,n);if(r)return r;const o=te(i,t),s=K(n.mesh)?n.mesh:null;let m,u=x(o.baseScale,1);if(s){const f=J(s.grid);m=(l,_)=>ee(s,l,_,f)}else{const f=Math.max(i.width/t.width,i.height/t.height);u=typeof o.baseScale=="number"?o.baseScale:Math.min(1,f);const l=t.width*u,_=t.height*u,T=(i.width-l)/2,A=(i.height-_)/2;m=(B,ge)=>({x:T+l*B,y:A+_*ge})}const d=[],a=new Float32Array((v+1)**2*2);let g=0;for(let f=0;f<=v;f+=1){const l=f/v;for(let _=0;_<=v;_+=1){const T=_/v;d.push(m(T,l)),a[g++]=T,a[g++]=l}}const h=ne(d,o,u,!!o.baked),y=new Float32Array(h.length*2);h.forEach((f,l)=>{y[l*2]=i.x+f.x,y[l*2+1]=i.y+f.y});const c=new Uint16Array(v*v*6);let b=0;const R=v+1;for(let f=0;f<v;f+=1)for(let l=0;l<v;l+=1){const _=f*R+l,T=_+1,A=_+R,B=A+1;c[b++]=_,c[b++]=T,c[b++]=A,c[b++]=T,c[b++]=B,c[b++]=A}return{vertices:y,uvs:a,indices:c}}const p=new OffscreenCanvas(1,1),O=p.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0});if(!O)throw new Error("WebGL2 is unavailable in the render worker");const e=O,re=\`#version 300 es
62
- in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
63
- out vec2 v_uv; out vec2 v_position;
64
- void main() {
65
- vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
66
- gl_Position = vec4(clip * vec2(1.0, -1.0), 0.0, 1.0);
67
- v_uv = a_uv; v_position = a_position;
68
- }\`,oe=\`#version 300 es
69
- precision highp float;
70
- uniform sampler2D u_image; uniform sampler2D u_mask;
71
- uniform int u_mode; uniform float u_opacity; uniform vec4 u_tint; uniform vec4 u_mask_rect;
72
- in vec2 v_uv; in vec2 v_position; out vec4 out_color;
73
- void main() {
74
- vec4 source = texture(u_image, v_uv);
75
- if (u_mode == 1) {
76
- vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
77
- if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
78
- vec4 mask = texture(u_mask, maskUv);
79
- source *= mask.a;
80
- } else if (u_mode == 2) {
81
- float tintAlpha = source.a * u_tint.a;
82
- source = vec4(u_tint.rgb * tintAlpha, tintAlpha);
83
- } else if (u_mode == 3) {
84
- vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
85
- if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
86
- vec4 mask = texture(u_mask, maskUv);
87
- // Compose the premultiplied artwork over its fill before clipping. Applying
88
- // mask alpha to each term separately would count translucent edges twice.
89
- vec4 fill = vec4(u_tint.rgb * u_tint.a, u_tint.a);
90
- source = (source + fill * (1.0 - source.a)) * mask.a;
91
- }
92
- if (u_mode == 4) source = vec4(u_tint.rgb * u_tint.a, u_tint.a);
93
- else if (u_mode == 5) source += vec4(u_tint.rgb * u_tint.a, u_tint.a) * (1.0 - source.a);
94
- out_color = source * u_opacity;
95
- }\`;function G(i,t){const n=e.createShader(i);if(!n)throw new Error("Could not create WebGL shader");if(e.shaderSource(n,t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(n)||"WebGL shader compilation failed");return n}const E=e.createProgram();if(!E)throw new Error("Could not create WebGL program");if(e.attachShader(E,G(e.VERTEX_SHADER,re)),e.attachShader(E,G(e.FRAGMENT_SHADER,oe)),e.linkProgram(E),!e.getProgramParameter(E,e.LINK_STATUS))throw new Error(e.getProgramInfoLog(E)||"WebGL program link failed");const Y=e.getAttribLocation(E,"a_position"),W=e.getAttribLocation(E,"a_uv"),se=e.getUniformLocation(E,"u_resolution"),ae=e.getUniformLocation(E,"u_image"),ce=e.getUniformLocation(E,"u_mask"),le=e.getUniformLocation(E,"u_mode"),ue=e.getUniformLocation(E,"u_opacity"),fe=e.getUniformLocation(E,"u_tint"),de=e.getUniformLocation(E,"u_mask_rect");function H(i,t=!1){if(t)return i;const n=e.createTexture();if(!n)throw new Error("Could not create WebGL texture");return e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i),n}function me(i){const t=String(i??"normal").toLowerCase();e.enable(e.BLEND),t==="multiply"||t==="2"?e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}function F(i){if(!i)return[1,1,1,1];const t=/^#([\\da-f]{3})$/i.exec(i),n=/^#([\\da-f]{6})$/i.exec(i),r=/^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([+-]?(?:\\d*\\.)?\\d+))?/i.exec(i);let o=null;t&&(o=t[1].split("").map(m=>Number.parseInt(m+m,16))),n&&(o=[n[1].slice(0,2),n[1].slice(2,4),n[1].slice(4,6)].map(m=>Number.parseInt(m,16))),r&&(o=[Number(r[1]),Number(r[2]),Number(r[3])]);const s=r?.[4]===void 0?1:Math.max(0,Math.min(1,Number(r[4])));return o?[o[0]/255,o[1]/255,o[2]/255,s]:[1,1,1,1]}function z(i,t,n,r){return{vertices:new Float32Array([i,t,i+n,t,i,t+r,i+n,t+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function w(i,t,n={}){e.useProgram(E),me(n.blend);const r=e.createBuffer(),o=e.createBuffer(),s=e.createBuffer();if(!r||!o||!s)throw new Error("Could not allocate WebGL geometry");e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,i.vertices,e.STREAM_DRAW),e.enableVertexAttribArray(Y),e.vertexAttribPointer(Y,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,i.uvs,e.STATIC_DRAW),e.enableVertexAttribArray(W),e.vertexAttribPointer(W,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,s),e.bufferData(e.ELEMENT_ARRAY_BUFFER,i.indices,e.STATIC_DRAW),e.activeTexture(e.TEXTURE0);const m=H(t,n.imageIsTexture);e.bindTexture(e.TEXTURE_2D,m),e.uniform1i(ae,0);let u=null;n.mask&&(e.activeTexture(e.TEXTURE1),u=H(n.mask),e.bindTexture(e.TEXTURE_2D,u),e.uniform1i(ce,1)),e.uniform2f(se,p.width,p.height),e.uniform1i(le,n.mode??0),e.uniform1f(ue,n.opacity??1),e.uniform4fv(fe,n.tint??[1,1,1,1]),e.uniform4fv(de,n.maskRect??[0,0,1,1]),e.drawElements(e.TRIANGLES,i.indices.length,e.UNSIGNED_SHORT,0),e.deleteBuffer(r),e.deleteBuffer(o),e.deleteBuffer(s),n.imageIsTexture||e.deleteTexture(m),u&&e.deleteTexture(u)}function he(i,t){const n=e.createTexture(),r=e.createFramebuffer();if(!n||!r)throw new Error("Could not allocate WebGL layer target");if(e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,i,t,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)throw new Error("WebGL layer framebuffer is incomplete");return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),{texture:n,framebuffer:r}}async function ye(i){const t=i.areas.find(a=>a.name==="bg");if(!t)throw new Error("WebGL worker rendering requires a bg render area");const n=x(i.options.targetSize),r=n>0?n/Math.max(t.width,t.height):Math.max(.1,x(i.options.scale,1)),o=i.options.composition==="design-layer";p.width=Math.max(1,Math.round(t.width*r)),p.height=Math.max(1,Math.round(t.height*r)),e.viewport(0,0,p.width,p.height),e.bindFramebuffer(e.FRAMEBUFFER,null),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);const s=new Set,m=new Set;for(const a of i.areas)o&&!a.design||P(a,i.options.color)&&(a.image&&m.add(a.image),typeof a.texture=="string"&&m.add(a.texture));await Promise.all([...m].map(a=>k(a,s)));const u=a=>z(a.x*r,a.y*r,a.width*r,a.height*r);let d;try{for(const a of i.areas){if(o&&!a.design||!P(a,i.options.color))continue;const g=await k(a.image,s);if(!g)continue;if(!a.design){w(u(a),g,{blend:a.export?.blend,opacity:U(a.export?.opacity)});continue}const h=await k(a.texture,s),y=i.options.color??a.color,c=a.config??a.texture_transform??{},b=o?"normal":c.blendMode??"multiply",R=I(a.defaultPrintColor);if(R){d??=he(p.width,p.height),e.bindFramebuffer(e.FRAMEBUFFER,d.framebuffer),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);const f=c.textureSize??[a.width,a.height],l=N(a,h??{width:f[0],height:f[1]});for(let A=0;A<l.vertices.length;A++)l.vertices[A]*=r;w(l,g,{mode:4,tint:F(R),blend:"normal"});const _=c.blendMode??(y?"multiply":"normal");h?w(l,h,{mode:y?5:0,tint:F(y),blend:_}):y&&w(l,g,{mode:4,tint:F(y),blend:_}),e.bindFramebuffer(e.FRAMEBUFFER,null);const T=z(0,0,p.width,p.height);T.uvs=new Float32Array([0,1,1,1,0,0,1,0]),w(T,d.texture,{imageIsTexture:!0,mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&h?.close();continue}if(h){const f=N(a,h);for(let l=0;l<f.vertices.length;l+=1)f.vertices[l]*=r;o?w(f,h,{mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:U(c.opacity)}):y?w(f,h,{mode:3,mask:g,tint:F(y),maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:b,opacity:U(c.opacity)}):w(f,h,{mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:o?"normal":c.blendMode,opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&h.close()}else y&&w(u(a),g,{mode:2,tint:F(y),blend:b,opacity:U(c.opacity)})}e.finish();try{return await p.convertToBlob({type:i.options.format??"image/png",quality:i.options.quality??.9})}catch{return p.convertToBlob({type:"image/png"})}}finally{d&&(e.deleteFramebuffer(d.framebuffer),e.deleteTexture(d.texture)),j(s)}}self.onmessage=async i=>{const t=i.data;if(t.type==="preload"){try{await Promise.all([...new Set(t.sources)].map(n=>L.has(n)?Promise.resolve():X.load(n,t.priority===!0))),self.postMessage({type:"preloaded",id:t.id})}catch(n){self.postMessage({type:"error",id:t.id,message:n instanceof Error?n.message:String(n)})}return}if(t.type==="render")try{self.postMessage({type:"result",id:t.id,blob:await ye(t)})}catch(n){self.postMessage({type:"error",id:t.id,message:n instanceof Error?n.message:String(n)})}}})();
96
- `, y = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", b], { type: "text/javascript;charset=utf-8" });
97
- function R(t) {
98
- let e;
99
- try {
100
- if (e = y && (self.URL || self.webkitURL).createObjectURL(y), !e) throw "";
101
- const r = new Worker(e, {
102
- name: t?.name
103
- });
104
- return r.addEventListener("error", () => {
105
- (self.URL || self.webkitURL).revokeObjectURL(e);
106
- }), r;
107
- } catch {
108
- return new Worker(
109
- "data:text/javascript;charset=utf-8," + encodeURIComponent(b),
110
- {
111
- name: t?.name
112
- }
113
- );
114
- }
115
- }
116
- function d(t) {
117
- if (!t) return t;
118
- const e = typeof document < "u" ? document.baseURI : typeof location < "u" ? location.href : void 0;
119
- if (!e) return t;
120
- try {
121
- return new URL(t, e).href;
122
- } catch {
123
- return t;
124
- }
125
- }
126
- class E {
127
- constructor() {
128
- this.worker = null, this.nextRequestId = 0, this.pending = /* @__PURE__ */ new Map(), this.renderQueue = Promise.resolve();
129
- }
130
- static isSupported() {
131
- return typeof Worker < "u" && typeof OffscreenCanvas < "u" && typeof createImageBitmap < "u";
132
- }
133
- ensureWorker() {
134
- if (this.worker) return this.worker;
135
- if (!E.isSupported()) throw new Error("Pixel-map rendering requires Worker, OffscreenCanvas, and ImageBitmap support");
136
- const e = new R();
137
- return e.onmessage = (r) => {
138
- const n = r.data, i = this.pending.get(n.id);
139
- i && (this.pending.delete(n.id), n.type === "result" ? i.resolve(n.blob) : n.type === "preloaded" ? i.resolve(null) : i.reject(new Error(n.message)));
140
- }, e.onerror = (r) => {
141
- const n = r.filename ? ` (${r.filename}:${r.lineno}:${r.colno})` : "", i = r.error instanceof Error ? r.error : new Error(`${r.message || "Pixel-map worker failed"}${n}`);
142
- this.pending.forEach(({ reject: s }) => s(i)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
143
- }, e.onmessageerror = () => {
144
- const r = new Error("Pixel-map worker could not deserialize its render payload");
145
- this.pending.forEach(({ reject: n }) => n(r)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
146
- }, this.worker = e, e;
147
- }
148
- /** Warm compressed resources without exporting Fabric or entering the GPU queue. */
149
- async preloadAssets(e, r = !1) {
150
- const n = [...new Set(e.filter(Boolean).map(d))];
151
- if (!n.length) return;
152
- const i = this.ensureWorker(), s = ++this.nextRequestId;
153
- await new Promise((u, a) => {
154
- this.pending.set(s, { resolve: u, reject: a });
155
- try {
156
- i.postMessage({ type: "preload", id: s, sources: n, priority: r });
157
- } catch (c) {
158
- this.pending.delete(s), a(c instanceof Error ? c : new Error(String(c)));
159
- }
160
- });
161
- }
162
- async onOffscreenRender(e, r = {}) {
163
- const n = e.flatMap((a) => r.composition === "design-layer" && !a.design ? [] : w(a, r.color) ? [a.image, typeof a.texture == "string" ? a.texture : ""] : []), i = this.preloadAssets(n, !0);
164
- i.catch(() => {
165
- });
166
- const s = async () => {
167
- await i;
168
- const a = this.ensureWorker(), c = ++this.nextRequestId, g = await Promise.all(e.map(async (o) => {
169
- const l = o.texture instanceof ImageBitmap ? await createImageBitmap(o.texture) : typeof o.texture == "string" ? d(o.texture) : o.texture;
170
- return {
171
- ...o,
172
- image: d(o.image),
173
- texture: l
174
- };
175
- })), x = g.map((o) => o.texture).filter((o) => o instanceof ImageBitmap);
176
- return new Promise((o, l) => {
177
- this.pending.set(c, { resolve: o, reject: l });
178
- const _ = { type: "render", id: c, areas: g, options: r };
179
- a.postMessage(_, x);
180
- });
181
- }, u = this.renderQueue.then(s, s);
182
- return this.renderQueue = u.then(() => {
183
- }, () => {
184
- }), u;
185
- }
186
- destroy() {
187
- this.worker?.terminate(), this.worker = null, this.pending.forEach(({ reject: e }) => e(new Error("Pixel-map renderer was destroyed"))), this.pending.clear(), this.renderQueue = Promise.resolve();
188
- }
189
- }
190
- export {
191
- A as M,
192
- E as P,
193
- w as a,
194
- U as b,
195
- L as h,
196
- m as i,
197
- h as n,
198
- v as r
199
- };