@snowcone-app/canvas 0.29.0 → 0.31.0

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.
Files changed (92) hide show
  1. package/ERROR_CONTRACT.md +13 -0
  2. package/STYLING_CONTRACT.md +2 -2
  3. package/dist/{CanvasRenderer-_lFoIoz5.js → CanvasRenderer-hpJ05JGO.js} +4 -4
  4. package/dist/{CanvasRenderer-_lFoIoz5.js.map → CanvasRenderer-hpJ05JGO.js.map} +1 -1
  5. package/dist/{CanvasStateV1-BMxr6xb8.js → CanvasStateV1-jLOibojY.js} +876 -844
  6. package/dist/{CanvasStateV1-BMxr6xb8.js.map → CanvasStateV1-jLOibojY.js.map} +1 -1
  7. package/dist/ContextualToolbars-DRbuUE7W.js +6061 -0
  8. package/dist/ContextualToolbars-DRbuUE7W.js.map +1 -0
  9. package/dist/{EditorCanvasImpl-BNz8TPFs.js → EditorCanvasImpl-P2GHPNA3.js} +19 -20
  10. package/dist/{EditorCanvasImpl-BNz8TPFs.js.map → EditorCanvasImpl-P2GHPNA3.js.map} +1 -1
  11. package/dist/{ExportManager-B8Td7uR5.js → ExportManager-Bkzzyxgw.js} +973 -576
  12. package/dist/ExportManager-Bkzzyxgw.js.map +1 -0
  13. package/dist/{FontAnalyzer-D4Sg-P6_.js → FontAnalyzer-BYhwxDhe.js} +542 -477
  14. package/dist/FontAnalyzer-BYhwxDhe.js.map +1 -0
  15. package/dist/{ImagePanel-CN2Bu3hf.js → ImagePanel-CEr0_FYy.js} +38 -38
  16. package/dist/{ImagePanel-CN2Bu3hf.js.map → ImagePanel-CEr0_FYy.js.map} +1 -1
  17. package/dist/SnowconeCanvas-Fa0isFpO.js +1192 -0
  18. package/dist/SnowconeCanvas-Fa0isFpO.js.map +1 -0
  19. package/dist/advanced.mjs +14 -14
  20. package/dist/api/embed.d.ts +2 -0
  21. package/dist/api/stable.d.ts +2 -0
  22. package/dist/components/CanvasContextMenu.d.ts +15 -0
  23. package/dist/components/CanvasEditor/hooks/useCanvasInteraction.d.ts +27 -0
  24. package/dist/components/CanvasEditor.d.ts +8 -0
  25. package/dist/components/ImageToolbar.d.ts +4 -0
  26. package/dist/components/embed/SnowconeCanvas.d.ts +13 -0
  27. package/dist/components/embed/kernel.d.ts +8 -0
  28. package/dist/components/toolbars/EmbeddedToolbarLayout.d.ts +2 -0
  29. package/dist/components/toolbars/SecondaryPanels.d.ts +17 -1
  30. package/dist/components/toolbars/index.d.ts +2 -2
  31. package/dist/components/ui/SliderRow.d.ts +6 -0
  32. package/dist/components/ui/icons.d.ts +2 -0
  33. package/dist/components/ui/toolbar-button.d.ts +2 -2
  34. package/dist/contexts/CanvasServicesContext.d.ts +17 -0
  35. package/dist/contexts/EditorContext.d.ts +7 -0
  36. package/dist/core/image-adjustments.d.ts +32 -0
  37. package/dist/{custom-icons-B5TRC1Ed.js → custom-icons-Co4rcW0S.js} +7 -7
  38. package/dist/{custom-icons-B5TRC1Ed.js.map → custom-icons-Co4rcW0S.js.map} +1 -1
  39. package/dist/design-builder-CBG2hKc8.js +1672 -0
  40. package/dist/design-builder-CBG2hKc8.js.map +1 -0
  41. package/dist/{embed-BTRtoktw.js → embed-D4TIzO7g.js} +20 -20
  42. package/dist/{embed-BTRtoktw.js.map → embed-D4TIzO7g.js.map} +1 -1
  43. package/dist/embed.mjs +51 -46
  44. package/dist/embed.mjs.map +1 -1
  45. package/dist/errors/editorError.d.ts +8 -0
  46. package/dist/{guards-uQtEQJbs.js → guards-DgZuwVgu.js} +2 -2
  47. package/dist/{guards-uQtEQJbs.js.map → guards-DgZuwVgu.js.map} +1 -1
  48. package/dist/hooks/elementPatch.d.ts +7 -2
  49. package/dist/hooks/useKeyboardShortcuts.d.ts +15 -2
  50. package/dist/hooks/useLayers.d.ts +2 -0
  51. package/dist/index.mjs +57 -52
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/internals.mjs +201 -132
  54. package/dist/internals.mjs.map +1 -1
  55. package/dist/rendering/element-painters.d.ts +0 -13
  56. package/dist/rendering/element-serializer.d.ts +3 -1
  57. package/dist/rendering/image-adjustments.d.ts +24 -0
  58. package/dist/rendering/renderer-types.d.ts +8 -1
  59. package/dist/state/CanvasStateV1.d.ts +36 -3
  60. package/dist/state/index.d.ts +2 -2
  61. package/dist/template-fields-CvFcr5zy.js +505 -0
  62. package/dist/template-fields-CvFcr5zy.js.map +1 -0
  63. package/dist/testing.mjs +46 -47
  64. package/dist/testing.mjs.map +1 -1
  65. package/dist/types/index.d.ts +21 -0
  66. package/dist/{UnifiedFontService-CgYnYTj7.js → useCommands-bPXY9rCh.js} +2429 -2145
  67. package/dist/useCommands-bPXY9rCh.js.map +1 -0
  68. package/dist/{usePieceGuideBundle-CTQszfKA.js → usePieceGuideBundle-Bj98nPk0.js} +2 -2
  69. package/dist/{usePieceGuideBundle-CTQszfKA.js.map → usePieceGuideBundle-Bj98nPk0.js.map} +1 -1
  70. package/dist/utils/custom-fonts.d.ts +99 -0
  71. package/dist/utils/featureApplied.d.ts +2 -0
  72. package/dist/validation-CsTlSvJJ.js +8686 -0
  73. package/dist/validation-CsTlSvJJ.js.map +1 -0
  74. package/dist/workers/export-protocol.d.ts +13 -0
  75. package/dist/workers/export-worker.bundle.string.d.ts +1 -1
  76. package/example/package.json +1 -1
  77. package/package.json +1 -1
  78. package/dist/ContextualToolbars-0jWvnQgp.js +0 -5833
  79. package/dist/ContextualToolbars-0jWvnQgp.js.map +0 -1
  80. package/dist/ExportManager-B8Td7uR5.js.map +0 -1
  81. package/dist/FontAnalyzer-D4Sg-P6_.js.map +0 -1
  82. package/dist/SnowconeCanvas-CR_LdRFP.js +0 -1173
  83. package/dist/SnowconeCanvas-CR_LdRFP.js.map +0 -1
  84. package/dist/UnifiedFontService-CgYnYTj7.js.map +0 -1
  85. package/dist/design-builder-COj0zkxu.js +0 -470
  86. package/dist/design-builder-COj0zkxu.js.map +0 -1
  87. package/dist/editorErrors-CCvoKj_P.js +0 -1219
  88. package/dist/editorErrors-CCvoKj_P.js.map +0 -1
  89. package/dist/template-fields-BLRp84Ny.js +0 -716
  90. package/dist/template-fields-BLRp84Ny.js.map +0 -1
  91. package/dist/validation-eCebhplp.js +0 -8402
  92. package/dist/validation-eCebhplp.js.map +0 -1
@@ -1,12 +1,12 @@
1
- import { c as U, G as me, a2 as Be, a3 as Le, a4 as Ne, a5 as ye, a6 as Wn, a7 as Ue, a8 as Z, a0 as We, a1 as ze, a9 as sn, aa as zn, z as Xn, R as Ge, ab as He, ac as q, ad as Ve, ae as vn, P as je, S as qe, I as En, M as Xe, W as Ye, H as Ke, D as Je, O as Ze, J as Qe, K as nt, A as Yn } from "./FontAnalyzer-D4Sg-P6_.js";
2
- let $e = null;
3
- function et(e) {
4
- $e = e;
1
+ import { c as U, G as xe, a9 as ze, aa as Ge, ab as He, ac as ve, ad as Gn, ae as Ve, af as Q, a7 as je, a8 as qe, ag as on, ah as Hn, C as Jn, R as Xe, ai as Ye, aj as q, ak as Ke, al as wn, P as Je, S as Ze, I as An, Y as Qe, a0 as nt, Q as et, N as tt, _ as at, V as rt, W as st, A as Zn, K as it, E as we } from "./FontAnalyzer-BYhwxDhe.js";
2
+ let Se = null;
3
+ function ot(e) {
4
+ Se = e;
5
5
  }
6
- function Ca() {
7
- return $e;
6
+ function Oa() {
7
+ return Se;
8
8
  }
9
- const tt = U("TextureManager"), cn = class cn {
9
+ const ct = U("TextureManager"), ln = class ln {
10
10
  /**
11
11
  * Load a texture by ID or URL
12
12
  */
@@ -20,7 +20,7 @@ const tt = U("TextureManager"), cn = class cn {
20
20
  s.crossOrigin = "anonymous", s.onload = () => {
21
21
  this.cache.set(n, s), this.cache.set(t, s), this.loading.delete(n), this.loading.delete(t), r(s);
22
22
  }, s.onerror = () => {
23
- tt.error("Failed to load texture:", t), this.loading.delete(n), this.loading.delete(t), o(new Error(`Failed to load texture: ${t}`));
23
+ ct.error("Failed to load texture:", t), this.loading.delete(n), this.loading.delete(t), o(new Error(`Failed to load texture: ${t}`));
24
24
  }, s.src = t;
25
25
  });
26
26
  return this.loading.set(n, a), t !== n && this.loading.set(t, a), a;
@@ -86,7 +86,7 @@ const tt = U("TextureManager"), cn = class cn {
86
86
  return (t == null ? void 0 : t.presetColor) || "#ffffff";
87
87
  }
88
88
  };
89
- cn.cache = /* @__PURE__ */ new Map(), cn.loading = /* @__PURE__ */ new Map(), cn.TEXTURES = [
89
+ ln.cache = /* @__PURE__ */ new Map(), ln.loading = /* @__PURE__ */ new Map(), ln.TEXTURES = [
90
90
  {
91
91
  id: "glass-frame",
92
92
  name: "Glass Frame",
@@ -96,33 +96,33 @@ cn.cache = /* @__PURE__ */ new Map(), cn.loading = /* @__PURE__ */ new Map(), cn
96
96
  // Light gray
97
97
  }
98
98
  ];
99
- let J = cn;
100
- const at = U("ElementPreviewRenderer"), rt = {
99
+ let Z = ln;
100
+ const lt = U("ElementPreviewRenderer"), dt = {
101
101
  width: 40,
102
102
  height: 40,
103
103
  padding: 4,
104
104
  backgroundColor: "transparent"
105
105
  };
106
- function st(e, n = {}) {
107
- Hn();
108
- const t = { ...rt, ...n }, a = document.createElement("canvas");
106
+ function ft(e, n = {}) {
107
+ jn();
108
+ const t = { ...dt, ...n }, a = document.createElement("canvas");
109
109
  a.width = t.width, a.height = t.height;
110
110
  const r = a.getContext("2d");
111
111
  if (!r)
112
112
  return "";
113
113
  t.backgroundColor !== "transparent" && (r.fillStyle = t.backgroundColor, r.fillRect(0, 0, t.width, t.height)), r.save();
114
114
  try {
115
- e instanceof me ? ot(r, e, t) : it(r, e, t);
115
+ e instanceof xe ? pt(r, e, t) : ut(r, e, t);
116
116
  } catch (o) {
117
- at.warn("Failed to generate preview:", o);
117
+ lt.warn("Failed to generate preview:", o);
118
118
  }
119
119
  return r.restore(), a.toDataURL("image/png");
120
120
  }
121
- function it(e, n, t) {
121
+ function ut(e, n, t) {
122
122
  var f;
123
123
  const a = ((f = n.getBoundingBox) == null ? void 0 : f.call(n)) || { x: 0, y: 0, width: 100, height: 100 }, r = a.width, o = a.height;
124
124
  if (r === 0 || o === 0) {
125
- Kn(e, n, t);
125
+ Qn(e, n, t);
126
126
  return;
127
127
  }
128
128
  const s = t.width - t.padding * 2, c = t.height - t.padding * 2, i = Math.min(
@@ -131,14 +131,14 @@ function it(e, n, t) {
131
131
  1
132
132
  // Don't scale up, only down
133
133
  ), l = r * i, d = o * i, u = t.padding + (s - l) / 2, p = t.padding + (c - d) / 2;
134
- e.save(), e.translate(u - a.x * i, p - a.y * i), e.scale(i, i), typeof n.render == "function" ? n.render(e, !1, !1) : Kn(e, n, t), e.restore();
134
+ e.save(), e.translate(u - a.x * i, p - a.y * i), e.scale(i, i), typeof n.render == "function" ? n.render(e, !1, !1) : Qn(e, n, t), e.restore();
135
135
  }
136
- function Kn(e, n, t) {
136
+ function Qn(e, n, t) {
137
137
  e.fillStyle = "#888888", e.font = "10px Arial", e.textAlign = "center", e.textBaseline = "middle";
138
138
  const a = n.transformType || "Element";
139
139
  e.fillText(a, t.width / 2, t.height / 2);
140
140
  }
141
- function ot(e, n, t) {
141
+ function pt(e, n, t) {
142
142
  const a = t.width - t.padding * 2, r = t.height - t.padding * 2, o = t.padding, s = t.padding;
143
143
  e.fillStyle = "#888888", e.strokeStyle = "#666666", e.lineWidth = 1;
144
144
  const c = r * 0.7, i = s + r * 0.3, l = a * 0.4, d = r * 0.2;
@@ -148,21 +148,21 @@ function ot(e, n, t) {
148
148
  i + c / 2
149
149
  ));
150
150
  }
151
- function ka(e, n, t) {
151
+ function Ma(e, n, t) {
152
152
  var l;
153
153
  e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180);
154
154
  const a = n, r = a.fontSize || 24, o = a.fontFamily || "Arial", s = a.bold || !1, c = a.italic || !1;
155
- e.font = Be(r, o, s, c);
155
+ e.font = ze(r, o, s, c);
156
156
  const i = a.text || "";
157
157
  if (n.transformType === "custom") {
158
- const u = ((l = n.transformData) == null ? void 0 : l.width) || 200, p = Le(i, r, o, s, c), f = Math.min(p, u), $ = r * 1.2;
158
+ const u = ((l = n.transformData) == null ? void 0 : l.width) || 200, p = Ge(i, r, o, s, c), f = Math.min(p, u), $ = r * 1.2;
159
159
  e.rect(-f / 2, -$ / 2, f, $);
160
160
  } else {
161
161
  const d = e.measureText(i).width;
162
162
  e.beginPath(), e.moveTo(-d / 2, 0), e.lineTo(d / 2, 0), e.moveTo(-d / 2, -r), e.lineTo(d / 2, -r), e.moveTo(-d / 2, r * 0.2), e.lineTo(d / 2, r * 0.2);
163
163
  }
164
164
  }
165
- function ct(e, n) {
165
+ function ht(e, n) {
166
166
  if (!n.transformData) return;
167
167
  const { borderRadius: t = 0 } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100;
168
168
  if (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), e.beginPath(), t > 0) {
@@ -171,22 +171,22 @@ function ct(e, n) {
171
171
  } else
172
172
  e.rect(-a / 2, -r / 2, a, r);
173
173
  }
174
- function Ta(e, n, t, a) {
174
+ function Ra(e, n, t, a) {
175
175
  e.beginPath(), e.arc(n, t, a, 0, Math.PI * 2), e.closePath();
176
176
  }
177
- function _a(e, n, t, a, r) {
177
+ function Ba(e, n, t, a, r) {
178
178
  e.beginPath(), e.rect(n, t, a, r), e.closePath();
179
179
  }
180
- function xe(e, n) {
180
+ function Ce(e, n) {
181
181
  e.strokeStyle = n.color, e.lineWidth = n.width, e.lineCap = n.lineCap || "butt", e.lineJoin = n.lineJoin || "miter", n.miterLimit !== void 0 && (e.miterLimit = n.miterLimit), n.dashArray && n.dashArray.length > 0 ? e.setLineDash(n.dashArray) : e.setLineDash([]), n.opacity !== void 0 && (e.globalAlpha = n.opacity);
182
182
  }
183
- function lt(e, n) {
183
+ function bt(e, n) {
184
184
  if (typeof OffscreenCanvas < "u")
185
185
  return new OffscreenCanvas(e, n);
186
186
  const t = document.createElement("canvas");
187
187
  return t.width = e, t.height = n, t;
188
188
  }
189
- function ve(e, n, t) {
189
+ function ke(e, n, t) {
190
190
  var i;
191
191
  if (!((i = n.stroke) != null && i.enabled)) return;
192
192
  const a = n;
@@ -194,23 +194,23 @@ function ve(e, n, t) {
194
194
  const o = (t == null ? void 0 : t.isKnockout) === !0, s = n.stroke.opacity ?? 1;
195
195
  if (!o && s < 1)
196
196
  try {
197
- dt(e, n, a, t, s);
197
+ gt(e, n, a, t, s);
198
198
  } catch {
199
- on(e, n, a, t, !1);
199
+ cn(e, n, a, t, !1);
200
200
  }
201
201
  else
202
- on(e, n, a, t, o);
202
+ cn(e, n, a, t, o);
203
203
  }
204
- function dt(e, n, t, a, r) {
204
+ function gt(e, n, t, a, r) {
205
205
  var k, _;
206
206
  const o = t.text || "", s = t.fontSize || 24, c = n.stroke.width, i = n.stroke.feather || 0, l = n.transformType === "custom" && ((k = n.transformData) == null ? void 0 : k.width), d = l ? ((_ = n.transformData) == null ? void 0 : _.width) ?? 200 : 0, u = l ? d + c * 2 + i * 2 + 40 : s * o.length * 0.7 + c * 2 + i * 2 + 40, p = s * 3 + c * 2 + i * 2 + 40, f = e.getTransform(), $ = Math.max(Math.abs(f.a), Math.abs(f.d), 1), h = Math.ceil(u * $ / 2) * 2, b = Math.ceil(p * $ / 2) * 2;
207
207
  if (h <= 0 || b <= 0) {
208
- on(e, n, t, a, !1);
208
+ cn(e, n, t, a, !1);
209
209
  return;
210
210
  }
211
- const v = lt(h, b), y = v.getContext("2d");
211
+ const v = bt(h, b), y = v.getContext("2d");
212
212
  if (!y) {
213
- on(e, n, t, a, !1);
213
+ cn(e, n, t, a, !1);
214
214
  return;
215
215
  }
216
216
  const x = n.x || 0, m = n.y || 0, g = f.a * x + f.c * m + f.e, C = f.b * x + f.d * m + f.f;
@@ -223,21 +223,21 @@ function dt(e, n, t, a, r) {
223
223
  b / 2 - C + f.f
224
224
  );
225
225
  const T = n.stroke.opacity;
226
- n.stroke.opacity = 1, on(y, n, t, a, !1), n.stroke.opacity = T, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
226
+ n.stroke.opacity = 1, cn(y, n, t, a, !1), n.stroke.opacity = T, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
227
227
  v,
228
228
  Math.round(g - h / 2),
229
229
  Math.round(C - b / 2)
230
230
  ), e.restore();
231
231
  }
232
- function on(e, n, t, a, r) {
232
+ function cn(e, n, t, a, r) {
233
233
  var f;
234
234
  const o = t.text || "";
235
235
  e.save(), a != null && a.positionApplied || (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180));
236
236
  const s = t.fontSize || 24, c = t.fontFamily || "Arial", i = t.bold || !1, l = t.italic || !1, d = t.textAlign || "center";
237
237
  e.font = `${l ? "italic " : ""}${i ? "bold " : ""}${s}px ${c}`, e.textAlign = d, e.textBaseline = "alphabetic", r ? (e.strokeStyle = "#000000", e.globalAlpha = 1) : (e.strokeStyle = n.stroke.color, n.stroke.opacity !== void 0 && (e.globalAlpha = n.stroke.opacity)), e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "round", e.lineJoin = n.stroke.lineJoin || "round", n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit), !r && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`);
238
- const u = Ne(s, c, i, l);
238
+ const u = He(s, c, i, l);
239
239
  if (n.transformType === "custom" && ((f = n.transformData) == null ? void 0 : f.width)) {
240
- const $ = n.transformData, h = ($ == null ? void 0 : $.width) ?? 200, b = h - Z * 2, v = t.letterSpacing ?? 0, { lines: y, height: x } = ye(
240
+ const $ = n.transformData, h = ($ == null ? void 0 : $.width) ?? 200, b = h - Q * 2, v = t.letterSpacing ?? 0, { lines: y, height: x } = ve(
241
241
  o,
242
242
  b,
243
243
  s,
@@ -249,7 +249,7 @@ function on(e, n, t, a, r) {
249
249
  !0,
250
250
  // strict: wrap exactly at maxWidth
251
251
  { letterSpacing: v, lineHeight: t.lineHeight }
252
- ), m = -h / 2, g = -x / 2, C = s * (t.lineHeight ?? Wn);
252
+ ), m = -h / 2, g = -x / 2, C = s * (t.lineHeight ?? Gn);
253
253
  y.forEach((T, k) => {
254
254
  const _ = k === 0, w = k === y.length - 1;
255
255
  let A = T;
@@ -261,10 +261,10 @@ function on(e, n, t, a, r) {
261
261
  const P = A.match(/ +$/), I = P ? P[0].length : 0;
262
262
  I > 0 && (A = A.substring(0, A.length - I));
263
263
  }
264
- let E = m + Z;
265
- d === "center" ? E = m + h / 2 : d === "right" && (E = m + h - Z);
264
+ let E = m + Q;
265
+ d === "center" ? E = m + h / 2 : d === "right" && (E = m + h - Q);
266
266
  const S = g + u.ascent + k * C;
267
- Ue(e, A, E, S, v);
267
+ Ve(e, A, E, S, v);
268
268
  });
269
269
  } else {
270
270
  const b = -u.height / 2 + u.ascent;
@@ -272,17 +272,17 @@ function on(e, n, t, a, r) {
272
272
  }
273
273
  e.restore();
274
274
  }
275
- function ft(e, n, t) {
275
+ function mt(e, n, t) {
276
276
  var r;
277
277
  if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
278
278
  const a = (t == null ? void 0 : t.isKnockout) === !0;
279
- e.save(), a ? (e.strokeStyle = "#000000", e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", e.globalAlpha = 1, n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit)) : xe(e, n.stroke), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), ct(e, n), e.stroke(), e.restore();
279
+ e.save(), a ? (e.strokeStyle = "#000000", e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", e.globalAlpha = 1, n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit)) : Ce(e, n.stroke), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), ht(e, n), e.stroke(), e.restore();
280
280
  }
281
- function Ea(e, n, t) {
282
- n.enabled && (e.save(), xe(e, n), n.feather && n.feather > 0 && "filter" in e && (e.filter = `blur(${n.feather}px)`), e.beginPath(), t(), e.stroke(), e.restore());
281
+ function La(e, n, t) {
282
+ n.enabled && (e.save(), Ce(e, n), n.feather && n.feather > 0 && "filter" in e && (e.filter = `blur(${n.feather}px)`), e.beginPath(), t(), e.stroke(), e.restore());
283
283
  }
284
- const Jn = U("GlyphRenderer");
285
- function ut(e, n, t, a, r, o, s, c = {}) {
284
+ const ne = U("GlyphRenderer");
285
+ function yt(e, n, t, a, r, o, s, c = {}) {
286
286
  try {
287
287
  const i = [];
288
288
  Object.entries(s).forEach(([b, v]) => {
@@ -320,7 +320,7 @@ function ut(e, n, t, a, r, o, s, c = {}) {
320
320
  }
321
321
  }
322
322
  } catch (m) {
323
- Jn.warn("Error getting path for glyph:", b.name, m);
323
+ ne.warn("Error getting path for glyph:", b.name, m);
324
324
  }
325
325
  if (x) {
326
326
  const m = new Path2D(x);
@@ -329,10 +329,10 @@ function ut(e, n, t, a, r, o, s, c = {}) {
329
329
  h += b.advanceWidth * p;
330
330
  }), e.restore();
331
331
  } catch (i) {
332
- Jn.error("Error rendering with fontkit:", i), e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
332
+ ne.error("Error rendering with fontkit:", i), e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
333
333
  }
334
334
  }
335
- function pt(e, n, t, a, r, o, s, c = {}) {
335
+ function $t(e, n, t, a, r, o, s, c = {}) {
336
336
  const l = ((b) => {
337
337
  for (const v of b) {
338
338
  const y = v.codePointAt(0);
@@ -385,12 +385,12 @@ function pt(e, n, t, a, r, o, s, c = {}) {
385
385
  }
386
386
  }), e.restore();
387
387
  }
388
- function ht(e, n, t, a, r) {
388
+ function xt(e, n, t, a, r) {
389
389
  e.fillStyle = t.color;
390
- const o = t.textAlign || "center", s = (h) => h.letterSpacing !== void 0 ? h.letterSpacing : t.letterSpacing ?? 0, c = We(n);
390
+ const o = t.textAlign || "center", s = (h) => h.letterSpacing !== void 0 ? h.letterSpacing : t.letterSpacing ?? 0, c = je(n);
391
391
  let i, l;
392
392
  a !== void 0 && a > 0 && !r ? (i = [], l = [], c.forEach((h) => {
393
- const b = ze(h, a, t);
393
+ const b = qe(h, a, t);
394
394
  b.forEach((v, y) => {
395
395
  i.push(v), l.push({
396
396
  isParagraphStart: y === 0,
@@ -407,33 +407,33 @@ function ht(e, n, t, a, r) {
407
407
  let y = 0, x = 0;
408
408
  const m = l[b].isParagraphStart, g = l[b].isParagraphEnd;
409
409
  h.forEach((S) => {
410
- const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, D = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, F = S.style.italic !== void 0 ? S.style.italic : t.italic || !1;
411
- e.font = B(P, I, D, F);
412
- const M = sn(e.measureText(S.text).width, S.text, s(S.style));
413
- v.push(M);
414
- const L = dn(P, I, D, F);
410
+ const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, F = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, D = S.style.italic !== void 0 ? S.style.italic : t.italic || !1;
411
+ e.font = B(P, I, F, D);
412
+ const O = on(e.measureText(S.text).width, S.text, s(S.style));
413
+ v.push(O);
414
+ const L = fn(P, I, F, D);
415
415
  y = Math.max(y, L.height), x = Math.max(x, L.ascent);
416
416
  });
417
417
  const C = h.map((S) => S.text).join(""), T = C.match(/^ +/), k = C.match(/ +$/), _ = T ? T[0].length : 0, w = k ? k[0].length : 0;
418
418
  let A = 0, E = 0;
419
419
  h.forEach((S) => {
420
- const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, D = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, F = S.style.italic !== void 0 ? S.style.italic : t.italic || !1;
421
- let M = S.text;
422
- const L = E, Cn = E + S.text.length;
420
+ const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, F = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, D = S.style.italic !== void 0 ? S.style.italic : t.italic || !1;
421
+ let O = S.text;
422
+ const L = E, kn = E + S.text.length;
423
423
  if (!m && _ > 0 && L < _) {
424
424
  const R = Math.min(_ - L, S.text.length);
425
- M = M.substring(R);
425
+ O = O.substring(R);
426
426
  }
427
427
  if (!g && w > 0) {
428
428
  const R = C.length - w;
429
- if (Cn > R) {
430
- const H = !m && _ > 0 && L < _ ? Math.min(_ - L, S.text.length) : 0, kn = Math.max(0, R - L - H);
431
- M = M.substring(0, kn);
429
+ if (kn > R) {
430
+ const H = !m && _ > 0 && L < _ ? Math.min(_ - L, S.text.length) : 0, Tn = Math.max(0, R - L - H);
431
+ O = O.substring(0, Tn);
432
432
  }
433
433
  }
434
- E += S.text.length, M.length > 0 && (e.save(), e.font = B(P, I, D, F), A += sn(
435
- e.measureText(M).width,
436
- M,
434
+ E += S.text.length, O.length > 0 && (e.save(), e.font = B(P, I, F, D), A += on(
435
+ e.measureText(O).width,
436
+ O,
437
437
  s(S.style)
438
438
  ), e.restore());
439
439
  }), d.push({
@@ -448,7 +448,7 @@ function ht(e, n, t, a, r) {
448
448
  isParagraphEnd: g
449
449
  });
450
450
  });
451
- const u = dn(t.fontSize, t.fontFamily, t.bold, t.italic), p = t.fontSize * (t.lineHeight ?? Wn);
451
+ const u = fn(t.fontSize, t.fontFamily, t.bold, t.italic), p = t.fontSize * (t.lineHeight ?? Gn);
452
452
  let f;
453
453
  d.length === 0 ? f = 0 : d.length === 1 ? f = u.height : f = (d.length - 1) * p + u.height;
454
454
  const $ = -f / 2;
@@ -459,63 +459,63 @@ function ht(e, n, t, a, r) {
459
459
  const C = $ + u.ascent + b * p, T = v.map((S) => S.text).join(""), k = T.match(/^ +/), _ = T.match(/ +$/), w = k ? k[0].length : 0, A = _ ? _[0].length : 0;
460
460
  let E = 0;
461
461
  v.forEach((S) => {
462
- const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, D = S.style.color !== void 0 ? S.style.color : t.color, F = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, M = S.style.italic !== void 0 ? S.style.italic : t.italic || !1, L = S.style.underline !== void 0 ? S.style.underline : t.underline || !1, Cn = S.style.strikethrough !== void 0 ? S.style.strikethrough : t.strikethrough || !1;
463
- let R = S.text, H = E, kn = E + S.text.length;
462
+ const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, F = S.style.color !== void 0 ? S.style.color : t.color, D = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, O = S.style.italic !== void 0 ? S.style.italic : t.italic || !1, L = S.style.underline !== void 0 ? S.style.underline : t.underline || !1, kn = S.style.strikethrough !== void 0 ? S.style.strikethrough : t.strikethrough || !1;
463
+ let R = S.text, H = E, Tn = E + S.text.length;
464
464
  if (!x && w > 0 && H < w) {
465
465
  const V = Math.min(w - H, S.text.length);
466
466
  R = R.substring(V);
467
467
  }
468
468
  if (!m && A > 0) {
469
469
  const V = T.length - A;
470
- if (kn > V) {
471
- const tn = !x && w > 0 && H < w ? Math.min(w - H, S.text.length) : 0, j = Math.max(0, V - H - tn);
470
+ if (Tn > V) {
471
+ const an = !x && w > 0 && H < w ? Math.min(w - H, S.text.length) : 0, j = Math.max(0, V - H - an);
472
472
  R = R.substring(0, j);
473
473
  }
474
474
  }
475
475
  if (E += S.text.length, R.length > 0) {
476
476
  const V = s(S.style);
477
- e.font = B(P, I, F, M), e.fillStyle = D, e.textBaseline = "alphabetic", e.textAlign = "left", zn(e, R, g, C, V);
478
- const tn = sn(e.measureText(R).width, R, V);
477
+ e.font = B(P, I, D, O), e.fillStyle = F, e.textBaseline = "alphabetic", e.textAlign = "left", Hn(e, R, g, C, V);
478
+ const an = on(e.measureText(R).width, R, V);
479
479
  if (L) {
480
480
  const j = C + P * 0.1;
481
- e.beginPath(), e.moveTo(g, j), e.lineTo(g + tn, j), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = D, e.stroke();
481
+ e.beginPath(), e.moveTo(g, j), e.lineTo(g + an, j), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
482
482
  }
483
- if (Cn) {
483
+ if (kn) {
484
484
  const j = C - P * 0.25;
485
- e.beginPath(), e.moveTo(g, j), e.lineTo(g + tn, j), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = D, e.stroke();
485
+ e.beginPath(), e.moveTo(g, j), e.lineTo(g + an, j), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
486
486
  }
487
- g += tn;
487
+ g += an;
488
488
  }
489
489
  });
490
490
  });
491
491
  }
492
- const An = U("canvas-renderer");
493
- let pn = null;
494
- function Gn() {
495
- if (!pn)
492
+ const Pn = U("canvas-renderer");
493
+ let hn = null;
494
+ function Vn() {
495
+ if (!hn)
496
496
  if (typeof OffscreenCanvas < "u")
497
- pn = new OffscreenCanvas(1, 1).getContext("2d");
497
+ hn = new OffscreenCanvas(1, 1).getContext("2d");
498
498
  else if (typeof document < "u")
499
- pn = document.createElement("canvas").getContext("2d");
499
+ hn = document.createElement("canvas").getContext("2d");
500
500
  else
501
501
  throw new Error("No canvas context available");
502
- return pn;
502
+ return hn;
503
503
  }
504
504
  function B(e, n, t = !1, a = !1) {
505
505
  const r = [];
506
506
  return a && r.push("italic"), t && r.push("bold"), r.push(`${e}px`), r.push(n), r.join(" ");
507
507
  }
508
- function Zn(e, n, t, a = !1, r = !1, o = 0) {
509
- const s = Gn();
510
- return s.font = B(n, t, a, r), sn(s.measureText(e).width, e, o);
508
+ function ee(e, n, t, a = !1, r = !1, o = 0) {
509
+ const s = Vn();
510
+ return s.font = B(n, t, a, r), on(s.measureText(e).width, e, o);
511
511
  }
512
- function dn(e, n, t = !1, a = !1) {
513
- const r = Gn();
512
+ function fn(e, n, t = !1, a = !1) {
513
+ const r = Vn();
514
514
  r.font = B(e, n, t, a);
515
515
  const s = r.measureText("ÁÉÍgjpqy"), c = s.actualBoundingBoxAscent || e * 0.8, i = s.actualBoundingBoxDescent || e * 0.2, l = c + i;
516
516
  return { ascent: c, descent: i, height: l };
517
517
  }
518
- function Aa(e, n) {
518
+ function Na(e, n) {
519
519
  const t = e.map((r, o) => ({
520
520
  isParagraphStart: !n && o === 0,
521
521
  isParagraphEnd: !n && o === e.length - 1
@@ -528,14 +528,14 @@ function Aa(e, n) {
528
528
  return s || (i = i.replace(/^ +/, "")), c || (i = i.replace(/ +$/, "")), i;
529
529
  }).filter((r) => r.length > 0);
530
530
  }
531
- function bt(e, n) {
531
+ function vt(e, n) {
532
532
  const t = n.fontSize, a = n.fontFamily, r = n.bold || !1, o = n.italic || !1, s = n.textAlign || "center", c = n.text;
533
533
  e.font = B(t, a, r, o), e.textAlign = s, e.textBaseline = "alphabetic", e.fillStyle = n.color;
534
- const i = dn(t, a, r, o), u = -i.height / 2 + i.ascent;
535
- zn(e, c, 0, u, n.letterSpacing);
534
+ const i = fn(t, a, r, o), u = -i.height / 2 + i.ascent;
535
+ Hn(e, c, 0, u, n.letterSpacing);
536
536
  }
537
- function gt(e, n, t, a, r = !1, o = !1, s) {
538
- const c = Gn();
537
+ function wt(e, n, t, a, r = !1, o = !1, s) {
538
+ const c = Vn();
539
539
  if (c.font = B(t, a, r, o), e.trim().length === 0)
540
540
  return [e];
541
541
  if (e.includes(`
@@ -543,7 +543,7 @@ function gt(e, n, t, a, r = !1, o = !1, s) {
543
543
  const k = e.split(`
544
544
  `), _ = [];
545
545
  for (let w = 0; w < k.length; w++) {
546
- const A = k[w], E = gt(A, n, t, a, r, o);
546
+ const A = k[w], E = wt(A, n, t, a, r, o);
547
547
  _.push(...E);
548
548
  }
549
549
  return _;
@@ -571,7 +571,7 @@ function gt(e, n, t, a, r = !1, o = !1, s) {
571
571
  }
572
572
  return m.push(g), m.length > 0 && (m[0] = d + m[0], m[m.length - 1] = m[m.length - 1] + u), m;
573
573
  }
574
- function Pa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1, p = !1, f = !1, $, h) {
574
+ function Ua(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1, p = !1, f = !1, $, h) {
575
575
  e.font = B(r, o, d, u), e.textBaseline = "alphabetic", e.textAlign = s;
576
576
  const b = (w) => {
577
577
  for (const A of w) {
@@ -580,59 +580,59 @@ function Pa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1,
580
580
  return !0;
581
581
  }
582
582
  return !1;
583
- }, v = $ && Object.values($).some((w) => w), y = h && h.length > 0, x = n.join(" "), m = b(x), g = v || y || m, C = g ? Xn.getFontSync(o, d ? 700 : 400) : null;
584
- g && !C && (An.warn(
583
+ }, v = $ && Object.values($).some((w) => w), y = h && h.length > 0, x = n.join(" "), m = b(x), g = v || y || m, C = g ? Jn.getFontSync(o, d ? 700 : 400) : null;
584
+ g && !C && (Pn.warn(
585
585
  `[renderMultilineText] Font ${o} not loaded for fontkit rendering. Text may not render correctly. Has PUA: ${m}, Text: "${x}"`
586
- ), Xn.loadFont(o, d ? 700 : 400).catch((w) => {
587
- An.error("[renderMultilineText] Error loading font:", w);
586
+ ), Jn.loadFont(o, d ? 700 : 400).catch((w) => {
587
+ Pn.error("[renderMultilineText] Error loading font:", w);
588
588
  }));
589
- const T = dn(r, o, d, u), k = r * l;
589
+ const T = fn(r, o, d, u), k = r * l;
590
590
  let _ = 0;
591
591
  n.forEach((w, A) => {
592
592
  let E = t + i;
593
593
  s === "center" ? E = t + c / 2 : s === "right" && (E = t + c - i);
594
- const S = a + T.ascent + A * k, P = Array.from(w).length, I = y ? h.filter((D) => {
595
- const F = D.charIndex - _;
596
- return F >= 0 && F < P;
597
- }).map((D) => ({
598
- ...D,
599
- charIndex: D.charIndex - _
594
+ const S = a + T.ascent + A * k, P = Array.from(w).length, I = y ? h.filter((F) => {
595
+ const D = F.charIndex - _;
596
+ return D >= 0 && D < P;
597
+ }).map((F) => ({
598
+ ...F,
599
+ charIndex: F.charIndex - _
600
600
  // Adjust to line-relative index
601
601
  })) : [];
602
- if (C && (v || I.length > 0 || m) ? I.length > 0 || b(w) ? pt(e, C, w, E, S, r, I, {
602
+ if (C && (v || I.length > 0 || m) ? I.length > 0 || b(w) ? $t(e, C, w, E, S, r, I, {
603
603
  color: e.fillStyle,
604
604
  align: s === "start" || s === "end" ? "left" : s
605
- }) : $ && ut(e, C, w, E, S, r, $, {
605
+ }) : $ && yt(e, C, w, E, S, r, $, {
606
606
  color: e.fillStyle,
607
607
  align: s === "start" || s === "end" ? "left" : s
608
608
  }) : e.fillText(w, E, S), _ += P + 1, p) {
609
- const D = Zn(w, r, o, d, u);
610
- let F = E;
611
- s === "center" ? F = E - D / 2 : s === "right" && (F = E - D);
612
- const M = S + r * 0.1;
613
- e.beginPath(), e.moveTo(F, M), e.lineTo(F + D, M), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
609
+ const F = ee(w, r, o, d, u);
610
+ let D = E;
611
+ s === "center" ? D = E - F / 2 : s === "right" && (D = E - F);
612
+ const O = S + r * 0.1;
613
+ e.beginPath(), e.moveTo(D, O), e.lineTo(D + F, O), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
614
614
  }
615
615
  if (f) {
616
- const D = Zn(w, r, o, d, u);
617
- let F = E;
618
- s === "center" ? F = E - D / 2 : s === "right" && (F = E - D);
619
- const M = S - r * 0.25;
620
- e.beginPath(), e.moveTo(F, M), e.lineTo(F + D, M), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
616
+ const F = ee(w, r, o, d, u);
617
+ let D = E;
618
+ s === "center" ? D = E - F / 2 : s === "right" && (D = E - F);
619
+ const O = S - r * 0.25;
620
+ e.beginPath(), e.moveTo(D, O), e.lineTo(D + F, O), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
621
621
  }
622
622
  });
623
623
  }
624
- function Pn(e, n) {
625
- mt(e, n);
624
+ function In(e, n) {
625
+ St(e, n);
626
626
  }
627
- function mt(e, n) {
627
+ function St(e, n) {
628
628
  var r;
629
- (r = n.stroke) != null && r.enabled && ve(e, n), e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
630
- const t = n.transformData, a = ((t == null ? void 0 : t.width) ?? 100) - Z * 2;
629
+ (r = n.stroke) != null && r.enabled && ke(e, n), e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
630
+ const t = n.transformData, a = ((t == null ? void 0 : t.width) ?? 100) - Q * 2;
631
631
  if (n.richText) {
632
- const o = Ge.fromJSON(n.richText);
632
+ const o = Xe.fromJSON(n.richText);
633
633
  e.save(), e.translate(0, 0);
634
634
  const s = n._lockedLineCount;
635
- ht(
635
+ xt(
636
636
  e,
637
637
  o,
638
638
  {
@@ -652,7 +652,7 @@ function mt(e, n) {
652
652
  ), e.restore();
653
653
  } else if (n.text) {
654
654
  e.fillStyle = n.color;
655
- const o = n._lockedLineCount, s = n.letterSpacing ?? 0, { lines: c, height: i } = ye(
655
+ const o = n._lockedLineCount, s = n.letterSpacing ?? 0, { lines: c, height: i } = ve(
656
656
  n.text,
657
657
  a,
658
658
  n.fontSize,
@@ -663,12 +663,12 @@ function mt(e, n) {
663
663
  !0,
664
664
  // strict: true
665
665
  { letterSpacing: s, lineHeight: n.lineHeight }
666
- ), l = dn(
666
+ ), l = fn(
667
667
  n.fontSize,
668
668
  n.fontFamily,
669
669
  n.bold,
670
670
  n.italic
671
- ), d = -((t == null ? void 0 : t.width) ?? 100) / 2, u = -i / 2, p = n.fontSize * (n.lineHeight ?? Wn);
671
+ ), d = -((t == null ? void 0 : t.width) ?? 100) / 2, u = -i / 2, p = n.fontSize * (n.lineHeight ?? Gn);
672
672
  e.font = `${n.italic ? "italic " : ""}${n.bold ? "bold " : ""}${n.fontSize}px ${n.fontFamily}`, e.textBaseline = "alphabetic", e.textAlign = n.textAlign, c.forEach((f, $) => {
673
673
  const h = $ === 0, b = $ === c.length - 1;
674
674
  let v = f;
@@ -680,11 +680,11 @@ function mt(e, n) {
680
680
  const m = v.match(/ +$/), g = m ? m[0].length : 0;
681
681
  g > 0 && (v = v.substring(0, v.length - g));
682
682
  }
683
- let y = d + Z;
684
- n.textAlign === "center" ? y = d + ((t == null ? void 0 : t.width) ?? 100) / 2 : n.textAlign === "right" && (y = d + ((t == null ? void 0 : t.width) ?? 100) - Z);
683
+ let y = d + Q;
684
+ n.textAlign === "center" ? y = d + ((t == null ? void 0 : t.width) ?? 100) / 2 : n.textAlign === "right" && (y = d + ((t == null ? void 0 : t.width) ?? 100) - Q);
685
685
  const x = u + l.ascent + $ * p;
686
- if (zn(e, v, y, x, s), v.length > 0) {
687
- const m = sn(e.measureText(v).width, v, s);
686
+ if (Hn(e, v, y, x, s), v.length > 0) {
687
+ const m = on(e.measureText(v).width, v, s);
688
688
  let g = y;
689
689
  if (n.textAlign === "center" ? g -= m / 2 : n.textAlign === "right" && (g -= m), n.underline) {
690
690
  const C = x + n.fontSize * 0.1;
@@ -699,17 +699,17 @@ function mt(e, n) {
699
699
  }
700
700
  e.restore();
701
701
  }
702
- function Ia(e, n) {
702
+ function Wa(e, n) {
703
703
  var s;
704
704
  const t = n.opacity ?? 1, a = !!((s = n.stroke) != null && s.enabled), r = n.type === "custom";
705
705
  if (t < 1 && a && r) {
706
- yt(e, n, t);
706
+ Ct(e, n, t);
707
707
  return;
708
708
  }
709
709
  const o = e.globalAlpha;
710
- t !== 1 && (e.globalAlpha = t), In(e, n), e.globalAlpha = o;
710
+ t !== 1 && (e.globalAlpha = t), Fn(e, n), e.globalAlpha = o;
711
711
  }
712
- function yt(e, n, t) {
712
+ function Ct(e, n, t) {
713
713
  var b;
714
714
  const a = n.transformData, r = n.fontSize || 24, o = ((b = n.stroke) == null ? void 0 : b.width) || 0, s = ((a == null ? void 0 : a.width) ?? r * n.text.length * 0.7) + o * 2 + 40, c = r * 3 + o * 2 + 40, i = e.getTransform(), l = Math.max(Math.abs(i.a), Math.abs(i.d), 1), d = Math.ceil(s * l), u = Math.ceil(c * l);
715
715
  let p;
@@ -717,7 +717,7 @@ function yt(e, n, t) {
717
717
  const f = p.getContext("2d");
718
718
  if (!f) {
719
719
  const v = e.globalAlpha;
720
- e.globalAlpha = t, In(e, n), e.globalAlpha = v;
720
+ e.globalAlpha = t, Fn(e, n), e.globalAlpha = v;
721
721
  return;
722
722
  }
723
723
  const $ = i.a * n.x + i.e, h = i.d * n.y + i.f;
@@ -728,42 +728,42 @@ function yt(e, n, t) {
728
728
  i.d,
729
729
  i.e - $ + d / 2,
730
730
  i.f - h + u / 2
731
- ), In(f, n), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = t, e.drawImage(p, $ - d / 2, h - u / 2), e.restore();
731
+ ), Fn(f, n), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = t, e.drawImage(p, $ - d / 2, h - u / 2), e.restore();
732
732
  }
733
- function In(e, n) {
733
+ function Fn(e, n) {
734
734
  switch (n.type) {
735
735
  case "custom":
736
- Pn(e, n);
736
+ In(e, n);
737
737
  break;
738
738
  case "circle":
739
- we(e, n);
739
+ Te(e, n);
740
740
  break;
741
741
  case "wave":
742
- Se(e, n);
742
+ _e(e, n);
743
743
  break;
744
744
  case "arch":
745
- Ce(e, n);
745
+ Ee(e, n);
746
746
  break;
747
747
  case "ascend":
748
- ke(e, n);
748
+ Ae(e, n);
749
749
  break;
750
750
  case "lean":
751
- Te(e, n);
751
+ Pe(e, n);
752
752
  break;
753
753
  case "flag":
754
- _e(e, n);
754
+ Ie(e, n);
755
755
  break;
756
756
  default:
757
- An.warn(`[canvas-renderer] Unsupported transform type: ${n.type}`), Pn(e, n);
757
+ Pn.warn(`[canvas-renderer] Unsupported transform type: ${n.type}`), In(e, n);
758
758
  }
759
759
  }
760
- function $t(e, n) {
760
+ function kt(e, n) {
761
761
  if (typeof OffscreenCanvas < "u")
762
762
  return new OffscreenCanvas(e, n);
763
763
  const t = document.createElement("canvas");
764
764
  return t.width = e, t.height = n, t;
765
765
  }
766
- function nn(e, n, t) {
766
+ function en(e, n, t) {
767
767
  if (t != null && t.enabled)
768
768
  if (e.strokeStyle = t.color, e.lineWidth = t.width, e.lineCap = t.lineCap || "round", e.lineJoin = t.lineJoin || "round", t.miterLimit !== void 0 && (e.miterLimit = t.miterLimit), t.opacity !== void 0) {
769
769
  const a = e.globalAlpha;
@@ -771,7 +771,7 @@ function nn(e, n, t) {
771
771
  } else
772
772
  e.strokeText(n, 0, 0);
773
773
  }
774
- function en(e, n, t) {
774
+ function tn(e, n, t) {
775
775
  const a = n.stroke, r = (a == null ? void 0 : a.opacity) ?? 1, o = e.globalAlpha, s = (a == null ? void 0 : a.enabled) && r < 1, c = (a == null ? void 0 : a.enabled) && o < 1;
776
776
  if (!(s || c)) {
777
777
  t(e, n);
@@ -782,12 +782,12 @@ function en(e, n, t) {
782
782
  t(e, n);
783
783
  return;
784
784
  }
785
- const _ = $t(T, k), w = _.getContext("2d");
785
+ const _ = kt(T, k), w = _.getContext("2d");
786
786
  if (!w) {
787
787
  t(e, n);
788
788
  return;
789
789
  }
790
- const A = n.x || 0, E = n.y || 0, S = g.a * A + g.c * E + g.e, P = g.b * A + g.d * E + g.f, I = Math.round(S - T / 2), D = Math.round(P - k / 2);
790
+ const A = n.x || 0, E = n.y || 0, S = g.a * A + g.c * E + g.e, P = g.b * A + g.d * E + g.f, I = Math.round(S - T / 2), F = Math.round(P - k / 2);
791
791
  if (w.setTransform(
792
792
  g.a,
793
793
  g.b,
@@ -798,22 +798,22 @@ function en(e, n, t) {
798
798
  ), c) {
799
799
  w.globalAlpha = 1;
800
800
  const L = a.opacity;
801
- s && (a.opacity = 1), t(w, n), s && (a.opacity = L), e.save(), e.resetTransform(), e.globalAlpha = o, e.drawImage(_, I, D), e.restore();
801
+ s && (a.opacity = 1), t(w, n), s && (a.opacity = L), e.save(), e.resetTransform(), e.globalAlpha = o, e.drawImage(_, I, F), e.restore();
802
802
  return;
803
803
  }
804
- const F = a.opacity;
805
- a.opacity = 1, t(w, n), a.opacity = F;
806
- const M = a.enabled;
807
- a.enabled = !1, t(e, n), a.enabled = M, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
804
+ const D = a.opacity;
805
+ a.opacity = 1, t(w, n), a.opacity = D;
806
+ const O = a.enabled;
807
+ a.enabled = !1, t(e, n), a.enabled = O, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
808
808
  _,
809
809
  I,
810
- D
810
+ F
811
811
  ), e.restore();
812
812
  }
813
- function we(e, n) {
814
- en(e, n, xt);
813
+ function Te(e, n) {
814
+ tn(e, n, Tt);
815
815
  }
816
- function xt(e, n) {
816
+ function Tt(e, n) {
817
817
  const t = n.transformData;
818
818
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.scale(t.scale, t.scale);
819
819
  const a = n.bold ? "bold" : "normal", r = n.italic ? "italic" : "normal";
@@ -823,83 +823,83 @@ function xt(e, n) {
823
823
  let i = Math.PI / 2 + c / (2 * t.radius);
824
824
  o.forEach((l, d) => {
825
825
  const p = s[d] / t.radius, f = Math.cos(i - p / 2) * t.radius, $ = Math.sin(i - p / 2) * t.radius;
826
- e.save(), e.translate(f, $), e.rotate(i - p / 2 - Math.PI / 2), nn(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i -= p;
826
+ e.save(), e.translate(f, $), e.rotate(i - p / 2 - Math.PI / 2), en(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i -= p;
827
827
  });
828
828
  } else {
829
829
  let i = -Math.PI / 2 - c / (2 * t.radius);
830
830
  o.forEach((l, d) => {
831
831
  const p = s[d] / t.radius, f = Math.cos(i + p / 2) * t.radius, $ = Math.sin(i + p / 2) * t.radius;
832
- e.save(), e.translate(f, $), e.rotate(i + p / 2 + Math.PI / 2), nn(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i += p;
832
+ e.save(), e.translate(f, $), e.rotate(i + p / 2 + Math.PI / 2), en(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i += p;
833
833
  });
834
834
  }
835
835
  e.restore();
836
836
  }
837
- function Se(e, n) {
838
- en(e, n, vt);
837
+ function _e(e, n) {
838
+ tn(e, n, _t);
839
839
  }
840
- function vt(e, n) {
840
+ function _t(e, n) {
841
841
  const t = n.transformData;
842
842
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
843
843
  const a = n.text.split("");
844
844
  let o = -a.reduce((s, c) => s + e.measureText(c).width, 0) / 2;
845
845
  a.forEach((s) => {
846
846
  const c = e.measureText(s).width, i = o + c / 2, l = i / (t.width / 2), d = t.amplitude * n.fontSize * Math.sin(t.frequency * Math.PI * l), u = t.amplitude * t.frequency * Math.PI * Math.cos(t.frequency * Math.PI * l);
847
- e.save(), e.translate(i, d), e.transform(1, u * He, 0, 1, 0, 0), nn(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
847
+ e.save(), e.translate(i, d), e.transform(1, u * Ye, 0, 1, 0, 0), en(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
848
848
  }), e.restore();
849
849
  }
850
- function Ce(e, n) {
851
- en(e, n, wt);
850
+ function Ee(e, n) {
851
+ tn(e, n, Et);
852
852
  }
853
- function wt(e, n) {
853
+ function Et(e, n) {
854
854
  const t = n.transformData;
855
855
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
856
856
  const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.width / 2;
857
857
  let s = -r / 2;
858
858
  a.forEach((c) => {
859
859
  const i = e.measureText(c).width, l = s + i / 2, d = l / o, u = (Math.pow(d, 2) - 1) * t.archHeight * n.fontSize, p = 2 * d * t.archHeight;
860
- e.save(), e.translate(l, u), e.transform(1, p * 0.3, 0, 1, 0, 0), nn(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
860
+ e.save(), e.translate(l, u), e.transform(1, p * 0.3, 0, 1, 0, 0), en(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
861
861
  }), e.restore();
862
862
  }
863
- function ke(e, n) {
864
- en(e, n, St);
863
+ function Ae(e, n) {
864
+ tn(e, n, At);
865
865
  }
866
- function St(e, n) {
866
+ function At(e, n) {
867
867
  const t = n.transformData;
868
868
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
869
869
  const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.ascendAngle * Math.PI / 180;
870
870
  let s = -r / 2;
871
871
  a.forEach((c) => {
872
872
  const i = e.measureText(c).width, l = s + i / 2, d = l * Math.tan(o), u = Math.tan(o);
873
- e.save(), e.translate(l, d), e.transform(1, u * 1, 0, 1, 0, 0), nn(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
873
+ e.save(), e.translate(l, d), e.transform(1, u * 1, 0, 1, 0, 0), en(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
874
874
  }), e.restore();
875
875
  }
876
- function Te(e, n) {
877
- en(e, n, Ct);
876
+ function Pe(e, n) {
877
+ tn(e, n, Pt);
878
878
  }
879
- function Ct(e, n) {
879
+ function Pt(e, n) {
880
880
  var r;
881
881
  const t = n.transformData;
882
882
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
883
883
  const a = -t.leanAmount * Math.PI / 4;
884
884
  e.transform(1, 0, Math.tan(a), 1, 0, 0), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle", (r = n.stroke) != null && r.enabled && (e.save(), e.strokeStyle = n.stroke.color, e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "round", e.lineJoin = n.stroke.lineJoin || "round", n.stroke.opacity !== void 0 && (e.globalAlpha = n.stroke.opacity), e.strokeText(n.text, 0, 0), e.restore()), e.fillText(n.text, 0, 0), e.restore();
885
885
  }
886
- function _e(e, n) {
887
- en(e, n, kt);
886
+ function Ie(e, n) {
887
+ tn(e, n, It);
888
888
  }
889
- function kt(e, n) {
889
+ function It(e, n) {
890
890
  const t = n.transformData;
891
891
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
892
892
  const a = n.text.split("");
893
893
  let o = -a.reduce((s, c) => s + e.measureText(c).width, 0) / 2;
894
894
  a.forEach((s) => {
895
895
  const c = e.measureText(s).width, i = o + c / 2, l = i / (t.width / 2), d = Math.abs(l), u = t.amplitude * d, p = u * n.fontSize * Math.sin(t.frequency * Math.PI * l), f = u * t.frequency * Math.PI * Math.cos(t.frequency * Math.PI * l), $ = t.amplitude * Math.sign(l) * Math.sin(t.frequency * Math.PI * l), h = f + $;
896
- e.save(), e.translate(i, p), e.transform(1, h * 0.3, 0, 1, 0, 0), nn(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
896
+ e.save(), e.translate(i, p), e.transform(1, h * 0.3, 0, 1, 0, 0), en(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
897
897
  }), e.restore();
898
898
  }
899
- function X(e) {
899
+ function Y(e) {
900
900
  return (n, t) => e(n, t);
901
901
  }
902
- function Tt(e, n) {
902
+ function Ft(e, n) {
903
903
  e.save();
904
904
  const t = e.canvas, a = t.width, r = t.height, o = e.getTransform(), s = [];
905
905
  let c = [];
@@ -929,37 +929,37 @@ function Tt(e, n) {
929
929
  }
930
930
  e.restore();
931
931
  }
932
- var Qn = !1;
933
- function Hn() {
934
- Qn || (Qn = !0, q("arch", X(Ce)), q("ascend", X(ke)), q("circle", X(we)), q("flag", X(_e)), q("lean", X(Te)), q("wave", X(Se)), q(
932
+ var te = !1;
933
+ function jn() {
934
+ te || (te = !0, q("arch", Y(Ee)), q("ascend", Y(Ae)), q("circle", Y(Te)), q("flag", Y(Ie)), q("lean", Y(Pe)), q("wave", Y(_e)), q(
935
935
  "custom",
936
- (e, n) => Pn(e, n)
937
- ), Ve(Tt), et(
938
- (e, n) => st(e, n)
936
+ (e, n) => In(e, n)
937
+ ), Ke(Ft), ot(
938
+ (e, n) => ft(e, n)
939
939
  ), globalThis.__scElementPaintersInstalled = !0);
940
940
  }
941
- Hn();
942
- function Vn(e, n, t = {}) {
941
+ jn();
942
+ function qn(e, n, t = {}) {
943
943
  const a = t.mode || "both";
944
944
  switch (e.save(), e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), n.transformType) {
945
945
  case "image":
946
- Et(e, n, a, t);
946
+ Ot(e, n, a, t);
947
947
  break;
948
948
  case "shape":
949
- At(e, n, a, t);
949
+ Mt(e, n, a, t);
950
950
  break;
951
951
  case "group":
952
952
  break;
953
953
  default:
954
- _t(e, n, a, t);
954
+ Dt(e, n, a, t);
955
955
  break;
956
956
  }
957
957
  e.restore();
958
958
  }
959
- function _t(e, n, t, a) {
959
+ function Dt(e, n, t, a) {
960
960
  var s;
961
961
  const r = n, o = r.text || "";
962
- o && ((t === "stroke" || t === "both") && ((s = n.stroke) != null && s.enabled) && (e.save(), ve(e, n, { ...a.renderingContext, positionApplied: !0 }), e.restore()), (t === "fill" || t === "both") && (e.save(), bt(e, {
962
+ o && ((t === "stroke" || t === "both") && ((s = n.stroke) != null && s.enabled) && (e.save(), ke(e, n, { ...a.renderingContext, positionApplied: !0 }), e.restore()), (t === "fill" || t === "both") && (e.save(), vt(e, {
963
963
  text: o,
964
964
  fontSize: r.fontSize || 24,
965
965
  fontFamily: r.fontFamily || "Arial",
@@ -970,12 +970,12 @@ function _t(e, n, t, a) {
970
970
  letterSpacing: r.letterSpacing
971
971
  }), e.restore()));
972
972
  }
973
- function Et(e, n, t, a) {
973
+ function Ot(e, n, t, a) {
974
974
  var o;
975
975
  if (!n.transformData) return;
976
976
  const r = n.transformData;
977
977
  if (t === "fill" || t === "both")
978
- if (Mt(e, n), a.loadedImage) {
978
+ if (Ut(e, n), a.loadedImage) {
979
979
  e.save(), e.clip();
980
980
  const s = r.flipHorizontal ? -1 : 1, c = r.flipVertical ? -1 : 1;
981
981
  e.scale(s, c);
@@ -983,34 +983,34 @@ function Et(e, n, t, a) {
983
983
  e.drawImage(a.loadedImage, -i / 2, -l / 2, i, l), e.restore();
984
984
  } else
985
985
  e.fillStyle = "#cccccc", e.fill();
986
- (t === "stroke" || t === "both") && ((o = n.stroke) != null && o.enabled) && (e.save(), ft(e, n, a.renderingContext), e.restore());
986
+ (t === "stroke" || t === "both") && ((o = n.stroke) != null && o.enabled) && (e.save(), mt(e, n, a.renderingContext), e.restore());
987
987
  }
988
- function At(e, n, t, a) {
988
+ function Mt(e, n, t, a) {
989
989
  var s, c;
990
990
  if (!n.transformData) return;
991
991
  const r = n.transformData, o = ((s = a.renderingContext) == null ? void 0 : s.isKnockout) === !0;
992
- e.beginPath(), Ee(e, r), (t === "fill" || t === "both") && (e.fillStyle = o ? "#000000" : r.fillColor || "#3b82f6", e.globalAlpha = o ? 1 : r.fillOpacity ?? 1, e.fill()), (t === "stroke" || t === "both") && ((c = n.stroke) != null && c.enabled) && (e.save(), Ft(e, n, a.renderingContext), e.restore());
992
+ e.beginPath(), Fe(e, r), (t === "fill" || t === "both") && (e.fillStyle = o ? "#000000" : r.fillColor || "#3b82f6", e.globalAlpha = o ? 1 : r.fillOpacity ?? 1, e.fill()), (t === "stroke" || t === "both") && ((c = n.stroke) != null && c.enabled) && (e.save(), Nt(e, n, a.renderingContext), e.restore());
993
993
  }
994
- function Ee(e, n) {
994
+ function Fe(e, n) {
995
995
  const { shapeType: t } = n, a = n.width ?? 100, r = n.height ?? 100;
996
996
  switch (t) {
997
997
  case "rectangle":
998
- ne(e, n, a, r);
998
+ ae(e, n, a, r);
999
999
  break;
1000
1000
  case "circle":
1001
- Pt(e, Math.min(a, r) / 2);
1001
+ Rt(e, Math.min(a, r) / 2);
1002
1002
  break;
1003
1003
  case "ellipse":
1004
- It(e, a / 2, r / 2);
1004
+ Bt(e, a / 2, r / 2);
1005
1005
  break;
1006
1006
  case "star":
1007
- Dt(e, n, Math.min(a, r) / 2);
1007
+ Lt(e, n, Math.min(a, r) / 2);
1008
1008
  break;
1009
1009
  default:
1010
- ne(e, n, a, r);
1010
+ ae(e, n, a, r);
1011
1011
  }
1012
1012
  }
1013
- function ne(e, n, t, a) {
1013
+ function ae(e, n, t, a) {
1014
1014
  const r = n.borderRadius || 0, o = -t / 2, s = -a / 2;
1015
1015
  if (r > 0) {
1016
1016
  const c = Math.min(r / 100 * Math.min(t, a), t / 2, a / 2);
@@ -1018,13 +1018,13 @@ function ne(e, n, t, a) {
1018
1018
  } else
1019
1019
  e.rect(o, s, t, a);
1020
1020
  }
1021
- function Pt(e, n) {
1021
+ function Rt(e, n) {
1022
1022
  e.arc(0, 0, n, 0, Math.PI * 2);
1023
1023
  }
1024
- function It(e, n, t) {
1024
+ function Bt(e, n, t) {
1025
1025
  e.ellipse(0, 0, n, t, 0, 0, Math.PI * 2);
1026
1026
  }
1027
- function Dt(e, n, t) {
1027
+ function Lt(e, n, t) {
1028
1028
  const a = Math.max(3, Math.min(20, n.points || 5)), r = Math.max(0.1, Math.min(0.9, n.innerRadius || 0.4)), o = t * r, s = Math.PI / a, c = -Math.PI / 2;
1029
1029
  for (let i = 0; i < a * 2; i++) {
1030
1030
  const l = c + s * i, d = i % 2 === 0 ? t : o, u = Math.cos(l) * d, p = Math.sin(l) * d;
@@ -1032,13 +1032,13 @@ function Dt(e, n, t) {
1032
1032
  }
1033
1033
  e.closePath();
1034
1034
  }
1035
- function Ft(e, n, t) {
1035
+ function Nt(e, n, t) {
1036
1036
  var r;
1037
1037
  if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
1038
1038
  const a = (t == null ? void 0 : t.isKnockout) === !0;
1039
- e.save(), a ? (e.strokeStyle = "#000000", e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", e.globalAlpha = 1) : (e.strokeStyle = n.stroke.color, e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", n.stroke.opacity !== void 0 && (e.globalAlpha = n.stroke.opacity)), n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit), n.stroke.dashArray && n.stroke.dashArray.length > 0 && e.setLineDash(n.stroke.dashArray), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), e.beginPath(), Ee(e, n.transformData), e.stroke(), e.restore();
1039
+ e.save(), a ? (e.strokeStyle = "#000000", e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", e.globalAlpha = 1) : (e.strokeStyle = n.stroke.color, e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", n.stroke.opacity !== void 0 && (e.globalAlpha = n.stroke.opacity)), n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit), n.stroke.dashArray && n.stroke.dashArray.length > 0 && e.setLineDash(n.stroke.dashArray), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), e.beginPath(), Fe(e, n.transformData), e.stroke(), e.restore();
1040
1040
  }
1041
- function Mt(e, n) {
1041
+ function Ut(e, n) {
1042
1042
  if (!n.transformData) return;
1043
1043
  const { borderRadius: t } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100, o = -a / 2, s = -r / 2;
1044
1044
  if (e.beginPath(), t && t > 0) {
@@ -1056,21 +1056,21 @@ function Dn(e, n, t, a, r, o, s = "destination-out") {
1056
1056
  }
1057
1057
  const i = e.getTransform();
1058
1058
  e.save();
1059
- const l = n.knockoutParts.scope || "group", d = Ot(n, l, t);
1059
+ const l = n.knockoutParts.scope || "group", d = Wt(n, l, t);
1060
1060
  if (d.length === 0 && l === "artboard") {
1061
- Bt(e, n, a), e.restore();
1061
+ Gt(e, n, a), e.restore();
1062
1062
  return;
1063
1063
  }
1064
1064
  if (d.length === 0) {
1065
1065
  a(e, n), e.restore();
1066
1066
  return;
1067
1067
  }
1068
- const u = e.canvas, f = e.getTransform().a, $ = Lt(u.width, u.height), h = $.getContext("2d");
1068
+ const u = e.canvas, f = e.getTransform().a, $ = Ht(u.width, u.height), h = $.getContext("2d");
1069
1069
  if (!h) return;
1070
1070
  h.scale(f, f), r && o && (h.fillStyle = r, h.fillRect(o.x, o.y, o.width, o.height));
1071
1071
  for (const m of d)
1072
1072
  a(h, m);
1073
- n.knockoutParts.fill && !n.knockoutParts.stroke && ((x = n.stroke) != null && x.enabled) && (h.save(), Mn(h, n), h.restore()), h.save(), h.globalCompositeOperation = s, n.knockoutParts.fill && Fn(h, n), n.knockoutParts.stroke && Mn(h, n), h.restore(), n.knockoutParts.fill || (h.save(), Fn(h, n), h.restore());
1073
+ n.knockoutParts.fill && !n.knockoutParts.stroke && ((x = n.stroke) != null && x.enabled) && (h.save(), Mn(h, n), h.restore()), h.save(), h.globalCompositeOperation = s, n.knockoutParts.fill && On(h, n), n.knockoutParts.stroke && Mn(h, n), h.restore(), n.knockoutParts.fill || (h.save(), On(h, n), h.restore());
1074
1074
  const b = u.width / f, v = u.height / f;
1075
1075
  e.drawImage($, 0, 0, b, v), e.restore();
1076
1076
  const y = e.getTransform();
@@ -1083,59 +1083,59 @@ function Dn(e, n, t, a, r, o, s = "destination-out") {
1083
1083
  i.f
1084
1084
  );
1085
1085
  }
1086
- function Da(e, n, t, a, r, o) {
1086
+ function za(e, n, t, a, r, o) {
1087
1087
  Dn(e, n, t, a, r, o, "destination-out");
1088
1088
  }
1089
- function Ot(e, n, t) {
1090
- return n === "artboard" ? Ae(e, t) : Rt(e, t);
1089
+ function Wt(e, n, t) {
1090
+ return n === "artboard" ? De(e, t) : zt(e, t);
1091
1091
  }
1092
- function Ae(e, n) {
1092
+ function De(e, n) {
1093
1093
  const t = n.findIndex((a) => a.id === e.id);
1094
1094
  return t === -1 ? [] : n.slice(0, t);
1095
1095
  }
1096
- function Rt(e, n) {
1097
- const t = Pe(e, n);
1096
+ function zt(e, n) {
1097
+ const t = Oe(e, n);
1098
1098
  if (!t)
1099
- return Ae(e, n);
1099
+ return De(e, n);
1100
1100
  if (t.transformType !== "group" || !t.children)
1101
1101
  return [];
1102
1102
  const a = t.children.findIndex((r) => r.id === e.id);
1103
1103
  return a === -1 ? [] : t.children.slice(0, a);
1104
1104
  }
1105
- function Pe(e, n) {
1105
+ function Oe(e, n) {
1106
1106
  for (const t of n)
1107
1107
  if (t.transformType === "group" && t.children) {
1108
1108
  if (t.children.some((r) => r.id === e.id))
1109
1109
  return t;
1110
- const a = Pe(e, t.children);
1110
+ const a = Oe(e, t.children);
1111
1111
  if (a)
1112
1112
  return a;
1113
1113
  }
1114
1114
  return null;
1115
1115
  }
1116
- function Fn(e, n, t) {
1117
- Vn(e, n, {
1116
+ function On(e, n, t) {
1117
+ qn(e, n, {
1118
1118
  mode: "fill",
1119
1119
  renderingContext: { isKnockout: !0 }
1120
1120
  });
1121
1121
  }
1122
1122
  function Mn(e, n) {
1123
1123
  var t;
1124
- (t = n.stroke) != null && t.enabled && Vn(e, n, {
1124
+ (t = n.stroke) != null && t.enabled && qn(e, n, {
1125
1125
  mode: "stroke",
1126
1126
  renderingContext: { isKnockout: !0 }
1127
1127
  });
1128
1128
  }
1129
- function Bt(e, n, t) {
1129
+ function Gt(e, n, t) {
1130
1130
  var r;
1131
1131
  const a = n.knockoutParts;
1132
1132
  if (!a) {
1133
1133
  t(e, n);
1134
1134
  return;
1135
1135
  }
1136
- a.fill || (e.save(), Fn(e, n), e.restore()), !a.stroke && ((r = n.stroke) != null && r.enabled) && (e.save(), Mn(e, n), e.restore());
1136
+ a.fill || (e.save(), On(e, n), e.restore()), !a.stroke && ((r = n.stroke) != null && r.enabled) && (e.save(), Mn(e, n), e.restore());
1137
1137
  }
1138
- function Lt(e, n) {
1138
+ function Ht(e, n) {
1139
1139
  if (typeof OffscreenCanvas < "u")
1140
1140
  return new OffscreenCanvas(e, n);
1141
1141
  if (typeof document < "u") {
@@ -1144,7 +1144,7 @@ function Lt(e, n) {
1144
1144
  }
1145
1145
  throw new Error("No canvas context available");
1146
1146
  }
1147
- function ee(e, n, t, a, r = 0) {
1147
+ function re(e, n, t, a, r = 0) {
1148
1148
  if (t <= 0 || a <= 0 || e <= 0 || n <= 0)
1149
1149
  return { width: e + r, height: n + r };
1150
1150
  const o = t / a, s = e / n;
@@ -1154,11 +1154,11 @@ function ee(e, n, t, a, r = 0) {
1154
1154
  height: i + r
1155
1155
  };
1156
1156
  }
1157
- const an = 64, Tn = 512;
1158
- function Nt(e, n) {
1157
+ const rn = 64, _n = 512;
1158
+ function Vt(e, n) {
1159
1159
  e.beginPath(), e.arc(n / 2, n / 2, n * 0.45, 0, Math.PI * 2), e.fill();
1160
1160
  }
1161
- function Ut(e, n) {
1161
+ function jt(e, n) {
1162
1162
  const t = n / 2, a = n / 2, r = n * 0.45, o = r * 0.4, s = 5;
1163
1163
  e.beginPath();
1164
1164
  for (let c = 0; c < s * 2; c++) {
@@ -1167,15 +1167,15 @@ function Ut(e, n) {
1167
1167
  }
1168
1168
  e.closePath(), e.fill();
1169
1169
  }
1170
- function Wt(e, n) {
1170
+ function qt(e, n) {
1171
1171
  const t = n / 2, a = n * 0.42;
1172
1172
  e.beginPath(), e.moveTo(t, n * 0.82), e.bezierCurveTo(t - a * 1.1, n * 0.6, t - a * 1.3, n * 0.2, t, n * 0.35), e.bezierCurveTo(t + a * 1.3, n * 0.2, t + a * 1.1, n * 0.6, t, n * 0.82), e.closePath(), e.fill();
1173
1173
  }
1174
- function zt(e, n) {
1174
+ function Xt(e, n) {
1175
1175
  const t = n / 2, a = n / 2, r = n * 0.4, o = n * 0.48;
1176
1176
  e.beginPath(), e.moveTo(t, a - o), e.lineTo(t + r, a), e.lineTo(t, a + o), e.lineTo(t - r, a), e.closePath(), e.fill();
1177
1177
  }
1178
- function Gt(e, n) {
1178
+ function Yt(e, n) {
1179
1179
  const t = n / 2, a = n / 2, r = n * 0.44;
1180
1180
  e.beginPath();
1181
1181
  for (let o = 0; o < 6; o++) {
@@ -1184,11 +1184,11 @@ function Gt(e, n) {
1184
1184
  }
1185
1185
  e.closePath(), e.fill();
1186
1186
  }
1187
- function Ht(e, n) {
1187
+ function Kt(e, n) {
1188
1188
  const t = n / 2, a = n * 0.4, r = n * 0.12;
1189
1189
  e.beginPath(), e.moveTo(t, r), e.lineTo(t + a, n * 0.25), e.lineTo(t + a, n * 0.55), e.quadraticCurveTo(t + a * 0.3, n * 0.8, t, n * 0.9), e.quadraticCurveTo(t - a * 0.3, n * 0.8, t - a, n * 0.55), e.lineTo(t - a, n * 0.25), e.closePath(), e.fill();
1190
1190
  }
1191
- function Vt(e, n) {
1191
+ function Jt(e, n) {
1192
1192
  const t = n / 2, a = n / 2;
1193
1193
  let r = 42;
1194
1194
  const o = () => (r = (r * 16807 + 0) % 2147483647, r / 2147483647);
@@ -1198,7 +1198,7 @@ function Vt(e, n) {
1198
1198
  e.beginPath(), e.arc(t + Math.cos(c) * i, a + Math.sin(c) * i, l, 0, Math.PI * 2), e.fill();
1199
1199
  }
1200
1200
  }
1201
- function jt(e, n) {
1201
+ function Zt(e, n) {
1202
1202
  let t = 123;
1203
1203
  const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.08, o = 40;
1204
1204
  e.beginPath(), e.moveTo(r, r);
@@ -1220,7 +1220,7 @@ function jt(e, n) {
1220
1220
  }
1221
1221
  e.closePath(), e.fill();
1222
1222
  }
1223
- function qt(e, n) {
1223
+ function Qt(e, n) {
1224
1224
  let t = 77;
1225
1225
  const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.25, o = n * 0.75, s = n * 0.1;
1226
1226
  e.beginPath(), e.moveTo(s, r + a() * n * 0.05);
@@ -1234,101 +1234,101 @@ function qt(e, n) {
1234
1234
  }
1235
1235
  e.closePath(), e.fill();
1236
1236
  }
1237
- function Xt(e, n) {
1237
+ function na(e, n) {
1238
1238
  const t = n / 2, a = n * 0.55;
1239
1239
  e.beginPath(), e.arc(t, a, n * 0.2, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t - n * 0.18, a + n * 0.02, n * 0.15, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t + n * 0.18, a + n * 0.02, n * 0.16, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t - n * 0.06, a - n * 0.14, n * 0.14, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t + n * 0.1, a - n * 0.12, n * 0.12, 0, Math.PI * 2), e.fill();
1240
1240
  }
1241
- const Yt = [
1241
+ const ea = [
1242
1242
  // Geometric
1243
- { id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw: Nt },
1244
- { id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw: Ut },
1245
- { id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: Wt },
1246
- { id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw: zt },
1247
- { id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw: Gt },
1248
- { id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw: Ht },
1243
+ { id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw: Vt },
1244
+ { id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw: jt },
1245
+ { id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: qt },
1246
+ { id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw: Xt },
1247
+ { id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw: Yt },
1248
+ { id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw: Kt },
1249
1249
  // Organic
1250
- { id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw: Vt },
1251
- { id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw: jt },
1252
- { id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw: qt },
1253
- { id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw: Xt }
1250
+ { id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw: Jt },
1251
+ { id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw: Zt },
1252
+ { id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw: Qt },
1253
+ { id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw: na }
1254
1254
  ];
1255
- let te = !1;
1256
- function ae(e, n) {
1255
+ let se = !1;
1256
+ function ie(e, n) {
1257
1257
  if (typeof document > "u") return null;
1258
1258
  const t = document.createElement("canvas");
1259
1259
  return t.width = e, t.height = n, t;
1260
1260
  }
1261
- function Kt() {
1262
- if (typeof document > "u" || te) return;
1263
- te = !0;
1264
- const e = vn.getInstance();
1265
- for (const n of Yt) {
1266
- const t = ae(Tn, Tn);
1261
+ function ta() {
1262
+ if (typeof document > "u" || se) return;
1263
+ se = !0;
1264
+ const e = wn.getInstance();
1265
+ for (const n of ea) {
1266
+ const t = ie(_n, _n);
1267
1267
  if (!t) continue;
1268
1268
  const a = t.getContext("2d");
1269
1269
  if (!a) continue;
1270
- a.fillStyle = "white", n.draw(a, Tn);
1270
+ a.fillStyle = "white", n.draw(a, _n);
1271
1271
  const r = t.toDataURL("image/png"), o = e.acquire(n.imageUrl);
1272
1272
  o.crossOrigin = "anonymous", o.src = r;
1273
- const s = ae(an, an);
1273
+ const s = ie(rn, rn);
1274
1274
  if (s) {
1275
1275
  const c = s.getContext("2d");
1276
- c && (c.fillStyle = "#1a1a2e", c.fillRect(0, 0, an, an), c.fillStyle = "white", n.draw(c, an), n.thumbnailUrl = s.toDataURL("image/png"));
1276
+ c && (c.fillStyle = "#1a1a2e", c.fillRect(0, 0, rn, rn), c.fillStyle = "white", n.draw(c, rn), n.thumbnailUrl = s.toDataURL("image/png"));
1277
1277
  }
1278
1278
  }
1279
1279
  }
1280
- const Jt = U("MaskRenderer"), On = /* @__PURE__ */ new Map(), Zt = /* @__PURE__ */ new Map();
1281
- function Fa(e) {
1280
+ const aa = U("MaskRenderer"), Rn = /* @__PURE__ */ new Map(), ra = /* @__PURE__ */ new Map();
1281
+ function Ga(e) {
1282
1282
  const n = [];
1283
- On.forEach((t, a) => {
1283
+ Rn.forEach((t, a) => {
1284
1284
  a.startsWith(e) && n.push(a);
1285
- }), n.forEach((t) => On.delete(t));
1285
+ }), n.forEach((t) => Rn.delete(t));
1286
1286
  }
1287
- function Ma() {
1288
- On.clear();
1287
+ function Ha() {
1288
+ Rn.clear();
1289
1289
  }
1290
- function re(e, n, t) {
1290
+ function oe(e, n, t) {
1291
1291
  if (!n.masks || n.masks.length === 0) {
1292
1292
  t(e);
1293
1293
  return;
1294
1294
  }
1295
- const a = e.canvas, r = bn(a.width, a.height), o = r.getContext("2d");
1295
+ const a = e.canvas, r = gn(a.width, a.height), o = r.getContext("2d");
1296
1296
  if (!o) {
1297
- Jt.error("[renderWithMasks] Failed to get offscreen context");
1297
+ aa.error("[renderWithMasks] Failed to get offscreen context");
1298
1298
  return;
1299
1299
  }
1300
1300
  const s = e.getTransform();
1301
1301
  o.setTransform(s), t(o);
1302
1302
  for (const c of n.masks)
1303
- Qt(o, c, n);
1303
+ sa(o, c, n);
1304
1304
  e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(r, 0, 0), e.restore();
1305
1305
  }
1306
- function Qt(e, n, t) {
1306
+ function sa(e, n, t) {
1307
1307
  switch (n.type) {
1308
1308
  case "clip":
1309
- na(e, n, t);
1309
+ ia(e, n, t);
1310
1310
  break;
1311
1311
  case "alpha":
1312
- ea(e, n, t);
1312
+ oa(e, n, t);
1313
1313
  break;
1314
1314
  case "luma":
1315
- ta(e, n, t);
1315
+ ca(e, n, t);
1316
1316
  break;
1317
1317
  case "distress":
1318
- aa(e, n, t);
1318
+ la(e, n, t);
1319
1319
  break;
1320
1320
  }
1321
1321
  }
1322
- function na(e, n, t) {
1323
- e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), wn(e, n.maskElement, t), e.restore();
1322
+ function ia(e, n, t) {
1323
+ e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), Sn(e, n.maskElement, t), e.restore();
1324
1324
  }
1325
- function ea(e, n, t) {
1326
- e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), wn(e, n.maskElement, t), n.feather && n.feather > 0 && Ie(e, n.feather), e.restore();
1325
+ function oa(e, n, t) {
1326
+ e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), Sn(e, n.maskElement, t), n.feather && n.feather > 0 && Me(e, n.feather), e.restore();
1327
1327
  }
1328
- function ta(e, n, t) {
1329
- const a = bn(e.canvas.width, e.canvas.height), r = a.getContext("2d");
1328
+ function ca(e, n, t) {
1329
+ const a = gn(e.canvas.width, e.canvas.height), r = a.getContext("2d");
1330
1330
  if (!r) return;
1331
- wn(r, n.maskElement, t);
1331
+ Sn(r, n.maskElement, t);
1332
1332
  const o = r.getImageData(0, 0, a.width, a.height), s = o.data;
1333
1333
  for (let c = 0; c < s.length; c += 4) {
1334
1334
  const i = s[c], l = s[c + 1], d = s[c + 2], u = 0.299 * i + 0.587 * l + 0.114 * d;
@@ -1336,10 +1336,10 @@ function ta(e, n, t) {
1336
1336
  }
1337
1337
  r.putImageData(o, 0, 0), e.save(), e.globalCompositeOperation = "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), e.drawImage(a, 0, 0), e.restore();
1338
1338
  }
1339
- function aa(e, n, t) {
1340
- e.save(), e.globalCompositeOperation = n.inverted ? "destination-in" : "destination-out", n.opacity !== void 0 && (e.globalAlpha = n.opacity), wn(e, n.maskElement, t), n.feather && n.feather > 0 && Ie(e, n.feather), e.restore();
1339
+ function la(e, n, t) {
1340
+ e.save(), e.globalCompositeOperation = n.inverted ? "destination-in" : "destination-out", n.opacity !== void 0 && (e.globalAlpha = n.opacity), Sn(e, n.maskElement, t), n.feather && n.feather > 0 && Me(e, n.feather), e.restore();
1341
1341
  }
1342
- function wn(e, n, t) {
1342
+ function Sn(e, n, t) {
1343
1343
  const a = t.x || 0, r = t.y || 0, o = n.x || 0, s = n.y || 0, c = {
1344
1344
  ...n,
1345
1345
  x: a + o,
@@ -1357,18 +1357,18 @@ function wn(e, n, t) {
1357
1357
  const m = n;
1358
1358
  if (m.imageUrl)
1359
1359
  if (typeof document < "u") {
1360
- m.imageUrl.startsWith("builtin-mask:") && Kt();
1361
- const g = vn.getInstance(), C = g.acquire(m.imageUrl);
1360
+ m.imageUrl.startsWith("builtin-mask:") && ta();
1361
+ const g = wn.getInstance(), C = g.acquire(m.imageUrl);
1362
1362
  C.complete && C.naturalWidth > 0 && ($ = C), g.release(m.imageUrl);
1363
1363
  } else
1364
- h = Zt.get(m.imageUrl);
1364
+ h = ra.get(m.imageUrl);
1365
1365
  }
1366
1366
  const b = c.transformData, v = (f == null ? void 0 : f.width) || 0, y = (f == null ? void 0 : f.height) || 0, x = v > 0 && y > 0 && u > 0 && p > 0 && Math.abs(v / y - u / p) > 1e-3;
1367
1367
  if (h) {
1368
1368
  e.save();
1369
1369
  const m = (b == null ? void 0 : b.width) || h.width, g = (b == null ? void 0 : b.height) || h.height;
1370
1370
  if (e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), x) {
1371
- const C = ee(
1371
+ const C = re(
1372
1372
  m,
1373
1373
  g,
1374
1374
  v,
@@ -1380,7 +1380,7 @@ function wn(e, n, t) {
1380
1380
  e.drawImage(h, -m / 2, -g / 2, m, g);
1381
1381
  e.restore();
1382
1382
  } else if (x && $) {
1383
- const m = (b == null ? void 0 : b.width) || u, g = (b == null ? void 0 : b.height) || p, C = ee(
1383
+ const m = (b == null ? void 0 : b.width) || u, g = (b == null ? void 0 : b.height) || p, C = re(
1384
1384
  m,
1385
1385
  g,
1386
1386
  v,
@@ -1389,12 +1389,12 @@ function wn(e, n, t) {
1389
1389
  );
1390
1390
  e.save(), e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), e.drawImage($, -C.width / 2, -C.height / 2, C.width, C.height), e.restore();
1391
1391
  } else
1392
- Vn(e, c, { mode: "both", loadedImage: $ });
1392
+ qn(e, c, { mode: "both", loadedImage: $ });
1393
1393
  }
1394
- function Ie(e, n) {
1394
+ function Me(e, n) {
1395
1395
  "filter" in e && (e.filter = `blur(${n}px)`);
1396
1396
  }
1397
- function bn(e, n) {
1397
+ function gn(e, n) {
1398
1398
  if (typeof OffscreenCanvas < "u")
1399
1399
  return new OffscreenCanvas(e, n);
1400
1400
  if (typeof document < "u") {
@@ -1403,9 +1403,9 @@ function bn(e, n) {
1403
1403
  }
1404
1404
  throw new Error("No canvas context available");
1405
1405
  }
1406
- function ra(e, n, t, a) {
1406
+ function da(e, n, t, a) {
1407
1407
  if (!n.enabled || !n.imageUrl || n.opacity <= 0) return;
1408
- const r = vn.getInstance(), o = r.acquire(n.imageUrl);
1408
+ const r = wn.getInstance(), o = r.acquire(n.imageUrl);
1409
1409
  if (!o.complete || o.naturalWidth === 0) {
1410
1410
  r.release(n.imageUrl);
1411
1411
  return;
@@ -1415,7 +1415,7 @@ function ra(e, n, t, a) {
1415
1415
  r.release(n.imageUrl);
1416
1416
  return;
1417
1417
  }
1418
- const v = bn(h, b), y = v.getContext("2d");
1418
+ const v = gn(h, b), y = v.getContext("2d");
1419
1419
  if (!y) {
1420
1420
  r.release(n.imageUrl);
1421
1421
  return;
@@ -1433,7 +1433,7 @@ function ra(e, n, t, a) {
1433
1433
  );
1434
1434
  let x;
1435
1435
  if (n.maskType === "luma" ? x = "destination-in" : x = n.inverted ? "destination-out" : "destination-in", n.maskType === "luma") {
1436
- const m = bn(h, b), g = m.getContext("2d");
1436
+ const m = gn(h, b), g = m.getContext("2d");
1437
1437
  if (g) {
1438
1438
  g.drawImage(o, 0, 0, h, b);
1439
1439
  const C = g.getImageData(0, 0, h, b), T = C.data;
@@ -1447,7 +1447,7 @@ function ra(e, n, t, a) {
1447
1447
  y.globalCompositeOperation = x, y.globalAlpha = n.opacity / 100, y.drawImage(o, 0, 0, h, b);
1448
1448
  y.globalCompositeOperation = "source-over", y.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(u, p, f, $), a && (e.fillStyle = a, e.fillRect(u, p, f, $)), e.drawImage(v, u, p), e.restore(), r.release(n.imageUrl);
1449
1449
  }
1450
- class sa {
1450
+ class fa {
1451
1451
  constructor(n = Math.random()) {
1452
1452
  this.perm = [];
1453
1453
  for (let a = 0; a < 256; a++)
@@ -1485,8 +1485,8 @@ class sa {
1485
1485
  );
1486
1486
  }
1487
1487
  }
1488
- function _n(e, n, t, a = Date.now()) {
1489
- const s = Sn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = new sa(a), l = 0.02, d = 1 - t / 100;
1488
+ function En(e, n, t, a = Date.now()) {
1489
+ const s = Cn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = new fa(a), l = 0.02, d = 1 - t / 100;
1490
1490
  for (let u = 0; u < n; u++)
1491
1491
  for (let p = 0; p < e; p++) {
1492
1492
  const f = (u * e + p) * 4;
@@ -1499,30 +1499,30 @@ function _n(e, n, t, a = Date.now()) {
1499
1499
  }
1500
1500
  return s;
1501
1501
  }
1502
- function ia(e, n, t, a = Date.now()) {
1503
- const o = Sn(e, n).getContext("2d");
1502
+ function ua(e, n, t, a = Date.now()) {
1503
+ const o = Cn(e, n).getContext("2d");
1504
1504
  o.clearRect(0, 0, e, n), o.strokeStyle = "#000000", o.lineWidth = 1 + t / 50, o.lineCap = "round";
1505
- const s = jn(a), c = Math.floor(t / 100 * 30 + 5);
1505
+ const s = Xn(a), c = Math.floor(t / 100 * 30 + 5);
1506
1506
  for (let i = 0; i < c; i++) {
1507
1507
  const l = s() * e, d = s() * n;
1508
- Rn(o, l, d, s() * Math.PI * 2, 50 + s() * 100, s, 0);
1508
+ Bn(o, l, d, s() * Math.PI * 2, 50 + s() * 100, s, 0);
1509
1509
  }
1510
1510
  return o.getImageData(0, 0, e, n);
1511
1511
  }
1512
- function Rn(e, n, t, a, r, o, s) {
1512
+ function Bn(e, n, t, a, r, o, s) {
1513
1513
  if (s > 3 || r < 10) return;
1514
1514
  const c = n + Math.cos(a) * r, i = t + Math.sin(a) * r;
1515
1515
  if (e.beginPath(), e.moveTo(n, t), e.lineTo(c, i), e.stroke(), o() > 0.5) {
1516
1516
  const l = a + (o() - 0.5) * Math.PI / 2;
1517
- Rn(e, c, i, l, r * 0.6, o, s + 1);
1517
+ Bn(e, c, i, l, r * 0.6, o, s + 1);
1518
1518
  }
1519
1519
  if (o() > 0.7) {
1520
1520
  const l = a - (o() - 0.5) * Math.PI / 2;
1521
- Rn(e, c, i, l, r * 0.6, o, s + 1);
1521
+ Bn(e, c, i, l, r * 0.6, o, s + 1);
1522
1522
  }
1523
1523
  }
1524
- function hn(e, n, t, a = Date.now()) {
1525
- const s = Sn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = jn(a), l = t / 100 * 0.5;
1524
+ function bn(e, n, t, a = Date.now()) {
1525
+ const s = Cn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = Xn(a), l = t / 100 * 0.5;
1526
1526
  for (let d = 0; d < n; d++)
1527
1527
  for (let u = 0; u < e; u++) {
1528
1528
  const p = (d * e + u) * 4, $ = i() < l ? 255 : 0;
@@ -1530,10 +1530,10 @@ function hn(e, n, t, a = Date.now()) {
1530
1530
  }
1531
1531
  return s;
1532
1532
  }
1533
- function oa(e, n, t, a = Date.now()) {
1534
- const o = Sn(e, n).getContext("2d");
1533
+ function pa(e, n, t, a = Date.now()) {
1534
+ const o = Cn(e, n).getContext("2d");
1535
1535
  o.fillStyle = "#000000";
1536
- const s = jn(a), c = 4 + t / 100 * 6, i = c * 2;
1536
+ const s = Xn(a), c = 4 + t / 100 * 6, i = c * 2;
1537
1537
  for (let l = 0; l < n; l += i)
1538
1538
  for (let d = 0; d < e; d += i)
1539
1539
  if (s() < t / 100) {
@@ -1542,7 +1542,7 @@ function oa(e, n, t, a = Date.now()) {
1542
1542
  }
1543
1543
  return o.getImageData(0, 0, e, n);
1544
1544
  }
1545
- function Sn(e, n) {
1545
+ function Cn(e, n) {
1546
1546
  if (typeof OffscreenCanvas < "u")
1547
1547
  return new OffscreenCanvas(e, n);
1548
1548
  if (typeof document < "u") {
@@ -1551,31 +1551,31 @@ function Sn(e, n) {
1551
1551
  }
1552
1552
  throw new Error("No canvas context available");
1553
1553
  }
1554
- function jn(e) {
1554
+ function Xn(e) {
1555
1555
  let n = Math.sin(e++) * 1e4;
1556
1556
  return () => (n = Math.sin(e++) * 1e4, n - Math.floor(n));
1557
1557
  }
1558
- const N = 42, Y = 512, K = 64;
1559
- function Bn(e) {
1558
+ const N = 42, K = 512, J = 64;
1559
+ function Ln(e) {
1560
1560
  const n = e.data;
1561
1561
  for (let t = 0; t < n.length; t += 4)
1562
1562
  n[t] = 255, n[t + 1] = 255, n[t + 2] = 255;
1563
1563
  return e;
1564
1564
  }
1565
- function ca(e, n) {
1565
+ function ha(e, n) {
1566
1566
  const t = e.data, a = n.data;
1567
1567
  for (let r = 0; r < t.length; r += 4)
1568
1568
  t[r] = 255, t[r + 1] = 255, t[r + 2] = 255, t[r + 3] = Math.min(255, t[r + 3] + a[r + 3]);
1569
1569
  return e;
1570
1570
  }
1571
- const la = [
1571
+ const ba = [
1572
1572
  {
1573
1573
  id: "grunge-heavy",
1574
1574
  name: "Heavy Grunge",
1575
1575
  textureUrl: "builtin:grunge-heavy",
1576
1576
  thumbnailUrl: "",
1577
1577
  description: "Dense random splatters",
1578
- generate: (e, n) => hn(e, n, 80, N)
1578
+ generate: (e, n) => bn(e, n, 80, N)
1579
1579
  },
1580
1580
  {
1581
1581
  id: "grunge-fine",
@@ -1583,7 +1583,7 @@ const la = [
1583
1583
  textureUrl: "builtin:grunge-fine",
1584
1584
  thumbnailUrl: "",
1585
1585
  description: "Sparse fine grain",
1586
- generate: (e, n) => hn(e, n, 25, N + 1)
1586
+ generate: (e, n) => bn(e, n, 25, N + 1)
1587
1587
  },
1588
1588
  {
1589
1589
  id: "concrete",
@@ -1591,7 +1591,7 @@ const la = [
1591
1591
  textureUrl: "builtin:concrete",
1592
1592
  thumbnailUrl: "",
1593
1593
  description: "Rough surface via Perlin noise",
1594
- generate: (e, n) => _n(e, n, 55, N + 2)
1594
+ generate: (e, n) => En(e, n, 55, N + 2)
1595
1595
  },
1596
1596
  {
1597
1597
  id: "paper",
@@ -1599,7 +1599,7 @@ const la = [
1599
1599
  textureUrl: "builtin:paper",
1600
1600
  thumbnailUrl: "",
1601
1601
  description: "Subtle aging",
1602
- generate: (e, n) => _n(e, n, 20, N + 3)
1602
+ generate: (e, n) => En(e, n, 20, N + 3)
1603
1603
  },
1604
1604
  {
1605
1605
  id: "rust",
@@ -1608,8 +1608,8 @@ const la = [
1608
1608
  thumbnailUrl: "",
1609
1609
  description: "Noise + splatter combined",
1610
1610
  generate: (e, n) => {
1611
- const t = _n(e, n, 45, N + 4), a = hn(e, n, 35, N + 5);
1612
- return ca(Bn(t), Bn(a));
1611
+ const t = En(e, n, 45, N + 4), a = bn(e, n, 35, N + 5);
1612
+ return ha(Ln(t), Ln(a));
1613
1613
  }
1614
1614
  },
1615
1615
  {
@@ -1618,7 +1618,7 @@ const la = [
1618
1618
  textureUrl: "builtin:scratches",
1619
1619
  thumbnailUrl: "",
1620
1620
  description: "Branching crack lines",
1621
- generate: (e, n) => ia(e, n, 55, N + 6)
1621
+ generate: (e, n) => ua(e, n, 55, N + 6)
1622
1622
  },
1623
1623
  {
1624
1624
  id: "halftone",
@@ -1626,7 +1626,7 @@ const la = [
1626
1626
  textureUrl: "builtin:halftone",
1627
1627
  thumbnailUrl: "",
1628
1628
  description: "Dot grid pattern",
1629
- generate: (e, n) => oa(e, n, 55, N + 7)
1629
+ generate: (e, n) => pa(e, n, 55, N + 7)
1630
1630
  },
1631
1631
  {
1632
1632
  id: "spray",
@@ -1634,62 +1634,62 @@ const la = [
1634
1634
  textureUrl: "builtin:spray",
1635
1635
  thumbnailUrl: "",
1636
1636
  description: "Medium random splatter",
1637
- generate: (e, n) => hn(e, n, 55, N + 8)
1637
+ generate: (e, n) => bn(e, n, 55, N + 8)
1638
1638
  }
1639
1639
  ];
1640
- let se = !1;
1641
- function da(e, n) {
1640
+ let ce = !1;
1641
+ function ga(e, n) {
1642
1642
  if (typeof OffscreenCanvas < "u")
1643
1643
  return new OffscreenCanvas(e, n);
1644
1644
  const t = document.createElement("canvas");
1645
1645
  return t.width = e, t.height = n, t;
1646
1646
  }
1647
- function ie(e, n) {
1647
+ function le(e, n) {
1648
1648
  if (typeof document > "u") return null;
1649
1649
  const t = document.createElement("canvas");
1650
1650
  return t.width = e, t.height = n, t;
1651
1651
  }
1652
- function fa(e) {
1653
- const n = ie(e.width, e.height);
1652
+ function ma(e) {
1653
+ const n = le(e.width, e.height);
1654
1654
  if (!n) return "";
1655
1655
  const t = n.getContext("2d");
1656
1656
  if (!t) return "";
1657
1657
  t.putImageData(e, 0, 0);
1658
- const a = ie(K, K);
1658
+ const a = le(J, J);
1659
1659
  if (!a) return "";
1660
1660
  const r = a.getContext("2d");
1661
1661
  if (!r) return "";
1662
- r.drawImage(n, 0, 0, e.width, e.height, 0, 0, K, K);
1663
- const o = r.getImageData(0, 0, K, K), s = o.data;
1662
+ r.drawImage(n, 0, 0, e.width, e.height, 0, 0, J, J);
1663
+ const o = r.getImageData(0, 0, J, J), s = o.data;
1664
1664
  for (let c = 0; c < s.length; c += 4) {
1665
1665
  const i = s[c + 3], l = 255 - Math.round(i / 255 * 195);
1666
1666
  s[c] = l, s[c + 1] = l, s[c + 2] = l, s[c + 3] = 255;
1667
1667
  }
1668
1668
  return r.putImageData(o, 0, 0), a.toDataURL("image/png");
1669
1669
  }
1670
- function ua() {
1671
- if (!se) {
1672
- se = !0;
1673
- for (const e of la) {
1674
- const n = e.generate(Y, Y);
1675
- Bn(n);
1676
- const t = da(Y, Y), a = t.getContext("2d");
1677
- a && (a.putImageData(n, 0, 0), pa(e.textureUrl, t, Y, Y)), typeof document < "u" && (e.thumbnailUrl = fa(n));
1670
+ function ya() {
1671
+ if (!ce) {
1672
+ ce = !0;
1673
+ for (const e of ba) {
1674
+ const n = e.generate(K, K);
1675
+ Ln(n);
1676
+ const t = ga(K, K), a = t.getContext("2d");
1677
+ a && (a.putImageData(n, 0, 0), $a(e.textureUrl, t, K, K)), typeof document < "u" && (e.thumbnailUrl = ma(n));
1678
1678
  }
1679
1679
  }
1680
1680
  }
1681
- const z = /* @__PURE__ */ new Set(), G = /* @__PURE__ */ new Map(), gn = /* @__PURE__ */ new Map();
1682
- function oe(e, n) {
1681
+ const z = /* @__PURE__ */ new Set(), G = /* @__PURE__ */ new Map(), mn = /* @__PURE__ */ new Map();
1682
+ function de(e, n) {
1683
1683
  if (typeof OffscreenCanvas < "u")
1684
1684
  return new OffscreenCanvas(e, n);
1685
1685
  const t = document.createElement("canvas");
1686
1686
  return t.width = e, t.height = n, t;
1687
1687
  }
1688
- function ce(e) {
1688
+ function fe(e) {
1689
1689
  return e.getContext("2d");
1690
1690
  }
1691
- function le(e) {
1692
- const { width: n, height: t } = e, a = oe(n, t), r = ce(a);
1691
+ function ue(e) {
1692
+ const { width: n, height: t } = e, a = de(n, t), r = fe(a);
1693
1693
  if (!r) throw new Error("Failed to get 2d context for temp canvas");
1694
1694
  r.drawImage(e, 0, 0);
1695
1695
  const o = r.getImageData(0, 0, n, t), s = o.data;
@@ -1697,67 +1697,67 @@ function le(e) {
1697
1697
  const d = s[l], u = s[l + 1], p = s[l + 2], $ = 255 - (0.299 * d + 0.587 * u + 0.114 * p);
1698
1698
  s[l] = 255, s[l + 1] = 255, s[l + 2] = 255, s[l + 3] = $;
1699
1699
  }
1700
- const c = oe(n, t), i = ce(c);
1700
+ const c = de(n, t), i = fe(c);
1701
1701
  if (!i) throw new Error("Failed to get 2d context for mask canvas");
1702
1702
  return i.putImageData(o, 0, 0), { alphaMask: c, width: n, height: t };
1703
1703
  }
1704
- function De(e) {
1704
+ function Re(e) {
1705
1705
  const n = G.get(e);
1706
1706
  if (n) return n;
1707
1707
  if (e.startsWith("builtin:")) {
1708
- ua();
1708
+ ya();
1709
1709
  const t = G.get(e);
1710
1710
  return t || null;
1711
1711
  }
1712
- return z.has(e) || (z.add(e), Fe(e)), null;
1712
+ return z.has(e) || (z.add(e), Be(e)), null;
1713
1713
  }
1714
- function Oa(e) {
1714
+ function Va(e) {
1715
1715
  return G.has(e) ? Promise.resolve() : new Promise((n) => {
1716
1716
  if (G.has(e)) {
1717
1717
  n();
1718
1718
  return;
1719
1719
  }
1720
- const t = gn.get(e) || [];
1721
- t.push(n), gn.set(e, t), z.has(e) || (z.add(e), Fe(e));
1720
+ const t = mn.get(e) || [];
1721
+ t.push(n), mn.set(e, t), z.has(e) || (z.add(e), Be(e));
1722
1722
  });
1723
1723
  }
1724
- function pa(e, n, t, a) {
1725
- G.has(e) || (G.set(e, { alphaMask: n, width: t, height: a }), rn(e));
1724
+ function $a(e, n, t, a) {
1725
+ G.has(e) || (G.set(e, { alphaMask: n, width: t, height: a }), sn(e));
1726
1726
  }
1727
- function rn(e) {
1728
- const n = gn.get(e);
1729
- n && (n.forEach((t) => t()), gn.delete(e));
1727
+ function sn(e) {
1728
+ const n = mn.get(e);
1729
+ n && (n.forEach((t) => t()), mn.delete(e));
1730
1730
  }
1731
- function Fe(e) {
1731
+ function Be(e) {
1732
1732
  if (typeof document < "u") {
1733
1733
  const n = new Image();
1734
1734
  n.crossOrigin = "anonymous", n.onload = () => {
1735
- const t = le(n);
1736
- G.set(e, t), z.delete(e), rn(e);
1735
+ const t = ue(n);
1736
+ G.set(e, t), z.delete(e), sn(e);
1737
1737
  }, n.onerror = () => {
1738
- z.delete(e), rn(e);
1738
+ z.delete(e), sn(e);
1739
1739
  }, n.src = e;
1740
1740
  } else
1741
1741
  fetch(e).then((n) => n.blob()).then((n) => createImageBitmap(n)).then((n) => {
1742
- const t = le(n);
1743
- G.set(e, t), z.delete(e), rn(e);
1742
+ const t = ue(n);
1743
+ G.set(e, t), z.delete(e), sn(e);
1744
1744
  }).catch(() => {
1745
- z.delete(e), rn(e);
1745
+ z.delete(e), sn(e);
1746
1746
  });
1747
1747
  }
1748
- function Me(e, n) {
1748
+ function Le(e, n) {
1749
1749
  if (typeof OffscreenCanvas < "u")
1750
1750
  return new OffscreenCanvas(e, n);
1751
1751
  const t = document.createElement("canvas");
1752
1752
  return t.width = e, t.height = n, t;
1753
1753
  }
1754
- function ha(e, n, t, a) {
1754
+ function xa(e, n, t, a) {
1755
1755
  if (!n.enabled || !n.textureUrl || n.intensity <= 0) return;
1756
- const r = De(n.textureUrl);
1756
+ const r = Re(n.textureUrl);
1757
1757
  if (!r) return;
1758
1758
  const { x: o, y: s, width: c, height: i } = t, l = e.getTransform(), d = l.a * o + l.e, u = l.d * s + l.f, p = l.a * c, f = l.d * i, $ = Math.ceil(p), h = Math.ceil(f);
1759
1759
  if ($ <= 0 || h <= 0) return;
1760
- const b = Me($, h), v = b.getContext("2d");
1760
+ const b = Le($, h), v = b.getContext("2d");
1761
1761
  if (!v) return;
1762
1762
  v.drawImage(
1763
1763
  e.canvas,
@@ -1785,9 +1785,9 @@ function ha(e, n, t, a) {
1785
1785
  v.globalCompositeOperation = "destination-out", v.globalAlpha = n.intensity / 100, v.drawImage(r.alphaMask, 0, 0, $, h), v.globalCompositeOperation = "source-over";
1786
1786
  v.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(d, u, p, f), a && (e.fillStyle = a, e.fillRect(d, u, p, f)), e.drawImage(b, d, u), e.restore();
1787
1787
  }
1788
- function de(e, n, t, a) {
1788
+ function pe(e, n, t, a) {
1789
1789
  if (!n.enabled || n.style !== "custom" || !n.textureUrl) return;
1790
- const r = De(n.textureUrl);
1790
+ const r = Re(n.textureUrl);
1791
1791
  if (!r) {
1792
1792
  a(e);
1793
1793
  return;
@@ -1802,7 +1802,7 @@ function de(e, n, t, a) {
1802
1802
  a(e);
1803
1803
  return;
1804
1804
  }
1805
- const m = Me(y, x), g = m.getContext("2d");
1805
+ const m = Le(y, x), g = m.getContext("2d");
1806
1806
  if (!g) {
1807
1807
  a(e);
1808
1808
  return;
@@ -1821,8 +1821,8 @@ function de(e, n, t, a) {
1821
1821
  for (let E = 0; E < x; E++) {
1822
1822
  const S = Math.floor(E / x * _);
1823
1823
  for (let P = 0; P < y; P++) {
1824
- const I = Math.floor(P / y * k), D = T[(S * k + I) * 4 + 3] / 255, F = (E * y + P) * 4;
1825
- A[F + 3] = Math.round(A[F + 3] * (1 - D * o));
1824
+ const I = Math.floor(P / y * k), F = T[(S * k + I) * 4 + 3] / 255, D = (E * y + P) * 4;
1825
+ A[D + 3] = Math.round(A[D + 3] * (1 - F * o));
1826
1826
  }
1827
1827
  }
1828
1828
  g.putImageData(w, 0, 0);
@@ -1830,7 +1830,7 @@ function de(e, n, t, a) {
1830
1830
  g.globalCompositeOperation = "destination-out", g.globalAlpha = o, g.drawImage(r.alphaMask, 0, 0, y, x), g.globalCompositeOperation = "source-over", g.globalAlpha = 1;
1831
1831
  e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(m, $, h), e.restore();
1832
1832
  }
1833
- class mn {
1833
+ class yn {
1834
1834
  /**
1835
1835
  * Create an element instance from a JSON configuration
1836
1836
  * TypeScript ensures all transform types are handled
@@ -1843,33 +1843,33 @@ class mn {
1843
1843
  const { transformType: t } = n;
1844
1844
  switch (t) {
1845
1845
  case "custom":
1846
- return new nt(n);
1846
+ return new st(n);
1847
1847
  case "distort":
1848
1848
  throw new Error("DistortTransform is not yet implemented");
1849
1849
  case "circle":
1850
- return new Qe(n);
1850
+ return new rt(n);
1851
1851
  case "lean":
1852
- return new Ze(n);
1852
+ return new at(n);
1853
1853
  case "arch":
1854
- return new Je(n);
1854
+ return new tt(n);
1855
1855
  case "ascend":
1856
- return new Ke(n);
1856
+ return new et(n);
1857
1857
  case "wave":
1858
- return new Ye(n);
1858
+ return new nt(n);
1859
1859
  case "flag":
1860
- return new Xe(n);
1860
+ return new Qe(n);
1861
1861
  case "image":
1862
- return new En(n);
1862
+ return new An(n);
1863
1863
  case "group": {
1864
1864
  const r = (n.children || []).map(
1865
- (i) => mn.createFromJSON(i)
1866
- ), { children: o, ...s } = n, c = new me(s);
1865
+ (i) => yn.createFromJSON(i)
1866
+ ), { children: o, ...s } = n, c = new xe(s);
1867
1867
  return r.forEach((i) => c.addChild(i)), c;
1868
1868
  }
1869
1869
  case "shape":
1870
- return new qe(n);
1870
+ return new Ze(n);
1871
1871
  case "path":
1872
- return new je(n);
1872
+ return new Je(n);
1873
1873
  default:
1874
1874
  const a = t;
1875
1875
  throw new Error(`Unknown transform type: ${a}`);
@@ -2083,7 +2083,7 @@ class mn {
2083
2083
  return this.createFromJSON(t);
2084
2084
  }
2085
2085
  }
2086
- const fe = U("ImportManager"), qn = class qn {
2086
+ const he = U("ImportManager"), Kn = class Kn {
2087
2087
  /**
2088
2088
  * Import workspace from JSON file
2089
2089
  */
@@ -2098,7 +2098,7 @@ const fe = U("ImportManager"), qn = class qn {
2098
2098
  return this.migrateV1Document(a);
2099
2099
  const r = [], o = [];
2100
2100
  return a.artboards.forEach((s) => {
2101
- const c = Yn.fromJSON({
2101
+ const c = Zn.fromJSON({
2102
2102
  id: s.id,
2103
2103
  name: s.name,
2104
2104
  x: s.x,
@@ -2109,9 +2109,9 @@ const fe = U("ImportManager"), qn = class qn {
2109
2109
  elementIds: s.elements.map((l) => l.id || "")
2110
2110
  }), i = s.elements.map((l) => {
2111
2111
  try {
2112
- return mn.createFromJSON(l);
2112
+ return yn.createFromJSON(l);
2113
2113
  } catch (d) {
2114
- return fe.error("Failed to create element:", l, d), null;
2114
+ return he.error("Failed to create element:", l, d), null;
2115
2115
  }
2116
2116
  }).filter((l) => l !== null);
2117
2117
  r.push(c), o.push(...i);
@@ -2134,7 +2134,7 @@ const fe = U("ImportManager"), qn = class qn {
2134
2134
  static async migrateV1Document(n) {
2135
2135
  var t, a, r;
2136
2136
  try {
2137
- const o = n.elements || [], s = new Yn({
2137
+ const o = n.elements || [], s = new Zn({
2138
2138
  id: "artboard-migrated",
2139
2139
  name: "Artboard 1",
2140
2140
  x: 0,
@@ -2144,9 +2144,9 @@ const fe = U("ImportManager"), qn = class qn {
2144
2144
  backgroundColor: ((r = n.canvas) == null ? void 0 : r.backgroundColor) || "#ffffff"
2145
2145
  }), c = o.map((i) => {
2146
2146
  try {
2147
- return mn.createFromJSON(i);
2147
+ return yn.createFromJSON(i);
2148
2148
  } catch (l) {
2149
- return fe.error("Failed to create element:", i, l), null;
2149
+ return he.error("Failed to create element:", i, l), null;
2150
2150
  }
2151
2151
  }).filter((i) => i !== null);
2152
2152
  return c.forEach((i) => {
@@ -2297,14 +2297,14 @@ const fe = U("ImportManager"), qn = class qn {
2297
2297
  await Promise.all(r);
2298
2298
  }
2299
2299
  };
2300
- qn.SUPPORTED_VERSIONS = ["1.0.0", "2.0.0"];
2301
- let ue = qn;
2302
- const pe = U("element-serializer"), Oe = 4e3, fn = /* @__PURE__ */ new Set();
2303
- function ba(e, n) {
2304
- const t = n ? ga(n) : "no-src";
2300
+ Kn.SUPPORTED_VERSIONS = ["1.0.0", "2.0.0"];
2301
+ let be = Kn;
2302
+ const ge = U("element-serializer"), Ne = 4e3, un = /* @__PURE__ */ new Set();
2303
+ function va(e, n) {
2304
+ const t = n ? wa(n) : "no-src";
2305
2305
  return `${e}:${t}`;
2306
2306
  }
2307
- function ga(e) {
2307
+ function wa(e) {
2308
2308
  let n = 0;
2309
2309
  for (let t = 0; t < e.length; t++) {
2310
2310
  const a = e.charCodeAt(t);
@@ -2312,20 +2312,20 @@ function ga(e) {
2312
2312
  }
2313
2313
  return n.toString(36);
2314
2314
  }
2315
- function Ln() {
2316
- fn.clear();
2315
+ function Nn() {
2316
+ un.clear();
2317
2317
  }
2318
- function Re(e) {
2319
- for (const n of fn)
2320
- n.startsWith(`${e}:`) && fn.delete(n);
2318
+ function Ue(e) {
2319
+ for (const n of un)
2320
+ n.startsWith(`${e}:`) && un.delete(n);
2321
2321
  }
2322
- function ma(e) {
2323
- fn.add(e);
2322
+ function Sa(e) {
2323
+ un.add(e);
2324
2324
  }
2325
- function ya(e) {
2326
- return fn.has(e);
2325
+ function Ca(e) {
2326
+ return un.has(e);
2327
2327
  }
2328
- async function $a(e, n = Oe) {
2328
+ async function ka(e, n = Ne) {
2329
2329
  const { naturalWidth: t, naturalHeight: a } = e;
2330
2330
  if (t <= n && a <= n)
2331
2331
  return createImageBitmap(e);
@@ -2336,20 +2336,20 @@ async function $a(e, n = Oe) {
2336
2336
  resizeQuality: "high"
2337
2337
  });
2338
2338
  }
2339
- let yn = null, $n = null;
2340
- function xa(e, n) {
2341
- yn = e, $n = n;
2339
+ let $n = null, xn = null;
2340
+ function Ta(e, n) {
2341
+ $n = e, xn = n;
2342
2342
  }
2343
- function va() {
2344
- yn = null, $n = null;
2343
+ function _a() {
2344
+ $n = null, xn = null;
2345
2345
  }
2346
- function Ra() {
2347
- Ln(), yn && yn();
2346
+ function ja() {
2347
+ Nn(), $n && $n();
2348
2348
  }
2349
- function Ba(e) {
2350
- Re(e), $n && $n(e);
2349
+ function qa(e) {
2350
+ Ue(e), xn && xn(e);
2351
2351
  }
2352
- function Nn(e, n) {
2352
+ function Un(e, n) {
2353
2353
  const t = e;
2354
2354
  if (typeof t.fontFamily == "string" && n.add(t.fontFamily), t.richText && typeof t.richText == "object") {
2355
2355
  const a = t.richText;
@@ -2364,14 +2364,14 @@ function Nn(e, n) {
2364
2364
  }
2365
2365
  if (t.children && Array.isArray(t.children))
2366
2366
  for (const a of t.children)
2367
- Nn(a, n);
2367
+ Un(a, n);
2368
2368
  if (e.masks && Array.isArray(e.masks))
2369
2369
  for (const a of e.masks)
2370
- a.maskElement && Nn(a.maskElement, n);
2370
+ a.maskElement && Un(a.maskElement, n);
2371
2371
  }
2372
- function he(e) {
2372
+ function me(e) {
2373
2373
  if (typeof document > "u") return e;
2374
- const n = vn.getInstance();
2374
+ const n = wn.getInstance();
2375
2375
  return e.map((t) => {
2376
2376
  if (!(t != null && t.maskElement) || t.maskElement.transformType !== "image") return t;
2377
2377
  const a = t.maskElement.imageUrl;
@@ -2387,20 +2387,20 @@ function he(e) {
2387
2387
  } : t;
2388
2388
  });
2389
2389
  }
2390
- async function be(e, n, t = Oe) {
2390
+ async function ye(e, n, t = Ne) {
2391
2391
  const a = n.filter((i) => e.hasElementId(i.id)), r = [], o = [], s = /* @__PURE__ */ new Set();
2392
2392
  for (const i of a) {
2393
2393
  const l = i.toJSON();
2394
- if (Nn(l, s), i instanceof En && !i.imageElement) {
2395
- pe.warn(`[element-serializer] Skipping image ${i.id}: image not loaded (state: ${i.imageLoadState})`);
2394
+ if (Un(l, s), i instanceof An && !i.imageElement) {
2395
+ ge.warn(`[element-serializer] Skipping image ${i.id}: image not loaded (state: ${i.imageLoadState})`);
2396
2396
  continue;
2397
2397
  }
2398
- if (i instanceof En && i.imageElement)
2398
+ if (i instanceof An && i.imageElement)
2399
2399
  try {
2400
- const d = ba(i.id, i.imageUrl);
2401
- if (!ya(d)) {
2402
- const x = await $a(i.imageElement, t);
2403
- o.push({ cacheKey: d, bitmap: x }), ma(d);
2400
+ const d = va(i.id, i.imageUrl);
2401
+ if (!Ca(d)) {
2402
+ const x = await ka(i.imageElement, t);
2403
+ o.push({ cacheKey: d, bitmap: x }), Sa(d);
2404
2404
  }
2405
2405
  const p = i.transformData || {}, f = l.masks && l.masks.length > 0, $ = f ? p.width : p.width * (p.cropWidth ?? 1), h = f ? p.height : p.height * (p.cropHeight ?? 1), b = {
2406
2406
  id: i.id,
@@ -2417,11 +2417,11 @@ async function be(e, n, t = Oe) {
2417
2417
  let g = 1;
2418
2418
  (x > t || m > t) && (g = t / Math.max(x, m)), b.cropX = p.cropX * x * g, b.cropY = p.cropY * m * g, b.cropWidth = p.cropWidth * x * g, b.cropHeight = p.cropHeight * m * g;
2419
2419
  }
2420
- p.flipHorizontal && (b.flipHorizontal = p.flipHorizontal), p.flipVertical && (b.flipVertical = p.flipVertical), p.borderRadius && (b.borderRadius = p.borderRadius), i.opacity !== void 0 && (b.opacity = i.opacity);
2420
+ p.flipHorizontal && (b.flipHorizontal = p.flipHorizontal), p.flipVertical && (b.flipVertical = p.flipVertical), p.borderRadius && (b.borderRadius = p.borderRadius), it(p.adjustments) || (b.adjustments = { ...p.adjustments }), i.opacity !== void 0 && (b.opacity = i.opacity);
2421
2421
  const y = b;
2422
- i.distressEffect && (y.distressEffect = { ...i.distressEffect }), l.masks && l.masks.length > 0 && (y.masks = he(l.masks)), l.blendMode && (y.blendMode = l.blendMode), l.knockoutParts && (y.knockoutParts = l.knockoutParts), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? y._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && (y._boundingBox = i.getBoundingBox()), r.push(y);
2422
+ i.distressEffect && (y.distressEffect = { ...i.distressEffect }), l.masks && l.masks.length > 0 && (y.masks = me(l.masks)), l.blendMode && (y.blendMode = l.blendMode), l.knockoutParts && (y.knockoutParts = l.knockoutParts), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? y._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && (y._boundingBox = i.getBoundingBox()), r.push(y);
2423
2423
  } catch (d) {
2424
- pe.error(`[element-serializer] Failed to create ImageBitmap for ${l.id}:`, d);
2424
+ ge.error(`[element-serializer] Failed to create ImageBitmap for ${l.id}:`, d);
2425
2425
  }
2426
2426
  else {
2427
2427
  const d = {
@@ -2429,7 +2429,7 @@ async function be(e, n, t = Oe) {
2429
2429
  type: l.transformType
2430
2430
  // Map transformType to type for worker compatibility
2431
2431
  };
2432
- d.masks && Array.isArray(d.masks) && d.masks.length > 0 && (d.masks = he(d.masks)), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? d._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && (d._boundingBox = i.getBoundingBox()), r.push(d);
2432
+ d.masks && Array.isArray(d.masks) && d.masks.length > 0 && (d.masks = me(d.masks)), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? d._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && (d._boundingBox = i.getBoundingBox()), r.push(d);
2433
2433
  }
2434
2434
  }
2435
2435
  const c = Array.from(s);
@@ -2454,7 +2454,7 @@ async function be(e, n, t = Oe) {
2454
2454
  newBitmaps: o
2455
2455
  };
2456
2456
  }
2457
- const wa = `"use strict";
2457
+ const Ea = `"use strict";
2458
2458
  (() => {
2459
2459
  var __create = Object.create;
2460
2460
  var __defProp = Object.defineProperty;
@@ -22778,8 +22778,8 @@ const wa = `"use strict";
22778
22778
  }
22779
22779
  };
22780
22780
  var ScopedLogger = class {
22781
- constructor(logger4, scopeName) {
22782
- this.logger = logger4;
22781
+ constructor(logger5, scopeName) {
22782
+ this.logger = logger5;
22783
22783
  this.scopeName = scopeName;
22784
22784
  }
22785
22785
  debug(message, ...args) {
@@ -24026,6 +24026,141 @@ const wa = `"use strict";
24026
24026
  }
24027
24027
  }
24028
24028
 
24029
+ // src/core/image-adjustments.ts
24030
+ var NEUTRAL_ADJUSTMENTS = Object.freeze({
24031
+ brightness: 1,
24032
+ contrast: 1,
24033
+ saturation: 1
24034
+ });
24035
+ var EPSILON = 1e-3;
24036
+ function isNeutralAdjustments(adjustments) {
24037
+ if (!adjustments) return true;
24038
+ return Math.abs(adjustments.brightness - 1) < EPSILON && Math.abs(adjustments.contrast - 1) < EPSILON && Math.abs(adjustments.saturation - 1) < EPSILON;
24039
+ }
24040
+ function adjustmentsCacheKey(adjustments) {
24041
+ if (isNeutralAdjustments(adjustments)) return "neutral";
24042
+ const a = adjustments;
24043
+ return \`b\${a.brightness}c\${a.contrast}s\${a.saturation}\`;
24044
+ }
24045
+ var adjustedImageSourceProvider = null;
24046
+ function registerAdjustedImageSourceProvider(provider) {
24047
+ adjustedImageSourceProvider = provider;
24048
+ }
24049
+
24050
+ // src/rendering/image-adjustments.ts
24051
+ var logger3 = createLogger("image-adjustments");
24052
+ var EPSILON2 = 1e-3;
24053
+ function applyAdjustmentsToPixels(data, adjustments) {
24054
+ const { brightness, contrast, saturation } = adjustments;
24055
+ const slope = brightness * contrast;
24056
+ const intercept = 127.5 * (1 - contrast);
24057
+ const applyLut = Math.abs(slope - 1) > EPSILON2 || Math.abs(intercept) > EPSILON2;
24058
+ const lut = new Uint8ClampedArray(256);
24059
+ if (applyLut) {
24060
+ for (let v = 0; v < 256; v++) lut[v] = v * slope + intercept;
24061
+ }
24062
+ const applySaturation = Math.abs(saturation - 1) > EPSILON2;
24063
+ const s = saturation;
24064
+ const rr = 0.213 + 0.787 * s;
24065
+ const rg = 0.715 - 0.715 * s;
24066
+ const rb = 0.072 - 0.072 * s;
24067
+ const gr = 0.213 - 0.213 * s;
24068
+ const gg = 0.715 + 0.285 * s;
24069
+ const gb = 0.072 - 0.072 * s;
24070
+ const br = 0.213 - 0.213 * s;
24071
+ const bg = 0.715 - 0.715 * s;
24072
+ const bb = 0.072 + 0.928 * s;
24073
+ for (let i = 0; i < data.length; i += 4) {
24074
+ let r = data[i];
24075
+ let g = data[i + 1];
24076
+ let b = data[i + 2];
24077
+ if (applyLut) {
24078
+ r = lut[r];
24079
+ g = lut[g];
24080
+ b = lut[b];
24081
+ }
24082
+ if (applySaturation) {
24083
+ const r2 = rr * r + rg * g + rb * b;
24084
+ const g2 = gr * r + gg * g + gb * b;
24085
+ const b2 = br * r + bg * g + bb * b;
24086
+ r = r2;
24087
+ g = g2;
24088
+ b = b2;
24089
+ }
24090
+ data[i] = r;
24091
+ data[i + 1] = g;
24092
+ data[i + 2] = b;
24093
+ }
24094
+ }
24095
+ var adjustedSourceCache = /* @__PURE__ */ new WeakMap();
24096
+ var MAX_VARIANTS_PER_SOURCE = 4;
24097
+ function sourcePixelWidth(source) {
24098
+ const natural = source.naturalWidth;
24099
+ return typeof natural === "number" && natural > 0 ? natural : source.width;
24100
+ }
24101
+ function sourcePixelHeight(source) {
24102
+ const natural = source.naturalHeight;
24103
+ return typeof natural === "number" && natural > 0 ? natural : source.height;
24104
+ }
24105
+ function createCanvas(width, height) {
24106
+ if (typeof OffscreenCanvas !== "undefined") {
24107
+ return new OffscreenCanvas(width, height);
24108
+ }
24109
+ if (typeof document !== "undefined") {
24110
+ const canvas = document.createElement("canvas");
24111
+ canvas.width = width;
24112
+ canvas.height = height;
24113
+ return canvas;
24114
+ }
24115
+ throw new Error("image-adjustments: no canvas implementation available (no OffscreenCanvas, no DOM)");
24116
+ }
24117
+ function renderAdjustedSource(source, adjustments) {
24118
+ const width = sourcePixelWidth(source);
24119
+ const height = sourcePixelHeight(source);
24120
+ if (width <= 0 || height <= 0) {
24121
+ throw new Error("image-adjustments: source has no pixels (width/height is 0)");
24122
+ }
24123
+ const canvas = createCanvas(width, height);
24124
+ const ctx = canvas.getContext("2d");
24125
+ if (!ctx) {
24126
+ throw new Error("image-adjustments: could not acquire a 2d context");
24127
+ }
24128
+ ctx.drawImage(source, 0, 0, width, height);
24129
+ const imageData = ctx.getImageData(0, 0, width, height);
24130
+ applyAdjustmentsToPixels(imageData.data, adjustments);
24131
+ ctx.putImageData(imageData, 0, 0);
24132
+ return canvas;
24133
+ }
24134
+ function getAdjustedImageSource(source, adjustments) {
24135
+ if (isNeutralAdjustments(adjustments)) return source;
24136
+ const key = adjustmentsCacheKey(adjustments);
24137
+ let variants = adjustedSourceCache.get(source);
24138
+ const cached = variants?.get(key);
24139
+ if (cached) {
24140
+ variants.delete(key);
24141
+ variants.set(key, cached);
24142
+ return cached;
24143
+ }
24144
+ let result;
24145
+ try {
24146
+ result = renderAdjustedSource(source, adjustments);
24147
+ } catch (error) {
24148
+ logger3.error("adjustment pixel pass failed \\u2014 rendering UNADJUSTED source:", error);
24149
+ result = source;
24150
+ }
24151
+ if (!variants) {
24152
+ variants = /* @__PURE__ */ new Map();
24153
+ adjustedSourceCache.set(source, variants);
24154
+ }
24155
+ variants.set(key, result);
24156
+ while (variants.size > MAX_VARIANTS_PER_SOURCE) {
24157
+ const oldest = variants.keys().next().value;
24158
+ variants.delete(oldest);
24159
+ }
24160
+ return result;
24161
+ }
24162
+ registerAdjustedImageSourceProvider(getAdjustedImageSource);
24163
+
24029
24164
  // src/rendering/image-renderer.ts
24030
24165
  function resolveServerCrop(el, bitmap) {
24031
24166
  if (!el.needsCropPixelConversion || el.cropWidth === void 0) return el;
@@ -24039,6 +24174,10 @@ const wa = `"use strict";
24039
24174
  };
24040
24175
  }
24041
24176
  function renderImageElement(ctx, elementData, imageBitmap) {
24177
+ const source = getAdjustedImageSource(
24178
+ imageBitmap,
24179
+ elementData.adjustments
24180
+ );
24042
24181
  ctx.save();
24043
24182
  ctx.translate(elementData.x, elementData.y);
24044
24183
  if (elementData.rotation) {
@@ -24079,7 +24218,7 @@ const wa = `"use strict";
24079
24218
  }
24080
24219
  if (elementData.cropX !== void 0 && elementData.cropWidth !== void 0) {
24081
24220
  ctx.drawImage(
24082
- imageBitmap,
24221
+ source,
24083
24222
  elementData.cropX,
24084
24223
  elementData.cropY || 0,
24085
24224
  elementData.cropWidth,
@@ -24090,7 +24229,7 @@ const wa = `"use strict";
24090
24229
  elementData.height
24091
24230
  );
24092
24231
  } else {
24093
- ctx.drawImage(imageBitmap, -elementData.width / 2, -elementData.height / 2, elementData.width, elementData.height);
24232
+ ctx.drawImage(source, -elementData.width / 2, -elementData.height / 2, elementData.width, elementData.height);
24094
24233
  }
24095
24234
  ctx.restore();
24096
24235
  if (elementData.stroke?.enabled) {
@@ -24695,7 +24834,7 @@ const wa = `"use strict";
24695
24834
  }
24696
24835
  };
24697
24836
  function generateWornEffect(width, height, intensity, seed = Date.now()) {
24698
- const canvas = createCanvas(width, height);
24837
+ const canvas = createCanvas2(width, height);
24699
24838
  const ctx = canvas.getContext("2d");
24700
24839
  const imageData = ctx.createImageData(width, height);
24701
24840
  const data = imageData.data;
@@ -24724,7 +24863,7 @@ const wa = `"use strict";
24724
24863
  return imageData;
24725
24864
  }
24726
24865
  function generateCrackedEffect(width, height, intensity, seed = Date.now()) {
24727
- const canvas = createCanvas(width, height);
24866
+ const canvas = createCanvas2(width, height);
24728
24867
  const ctx = canvas.getContext("2d");
24729
24868
  ctx.clearRect(0, 0, width, height);
24730
24869
  ctx.strokeStyle = "#000000";
@@ -24757,7 +24896,7 @@ const wa = `"use strict";
24757
24896
  }
24758
24897
  }
24759
24898
  function generateGrungeEffect(width, height, intensity, seed = Date.now()) {
24760
- const canvas = createCanvas(width, height);
24899
+ const canvas = createCanvas2(width, height);
24761
24900
  const ctx = canvas.getContext("2d");
24762
24901
  const imageData = ctx.createImageData(width, height);
24763
24902
  const data = imageData.data;
@@ -24777,7 +24916,7 @@ const wa = `"use strict";
24777
24916
  return imageData;
24778
24917
  }
24779
24918
  function generateRetroEffect(width, height, intensity, seed = Date.now()) {
24780
- const canvas = createCanvas(width, height);
24919
+ const canvas = createCanvas2(width, height);
24781
24920
  const ctx = canvas.getContext("2d");
24782
24921
  ctx.fillStyle = "#000000";
24783
24922
  const random = seededRandom(seed);
@@ -24795,7 +24934,7 @@ const wa = `"use strict";
24795
24934
  }
24796
24935
  return ctx.getImageData(0, 0, width, height);
24797
24936
  }
24798
- function createCanvas(width, height) {
24937
+ function createCanvas2(width, height) {
24799
24938
  if (typeof OffscreenCanvas !== "undefined") {
24800
24939
  return new OffscreenCanvas(width, height);
24801
24940
  } else if (typeof document !== "undefined") {
@@ -24909,7 +25048,7 @@ const wa = `"use strict";
24909
25048
  }
24910
25049
  ];
24911
25050
  var initialized = false;
24912
- function createCanvas2(width, height) {
25051
+ function createCanvas3(width, height) {
24913
25052
  if (typeof OffscreenCanvas !== "undefined") {
24914
25053
  return new OffscreenCanvas(width, height);
24915
25054
  }
@@ -24955,7 +25094,7 @@ const wa = `"use strict";
24955
25094
  for (const preset of DISTRESS_TEXTURE_PRESETS) {
24956
25095
  const imageData = preset.generate(TEX_SIZE, TEX_SIZE);
24957
25096
  toAlphaMask(imageData);
24958
- const maskCanvas = createCanvas2(TEX_SIZE, TEX_SIZE);
25097
+ const maskCanvas = createCanvas3(TEX_SIZE, TEX_SIZE);
24959
25098
  const maskCtx = maskCanvas.getContext("2d");
24960
25099
  if (maskCtx) {
24961
25100
  maskCtx.putImageData(imageData, 0, 0);
@@ -24971,7 +25110,7 @@ const wa = `"use strict";
24971
25110
  var loadingUrls = /* @__PURE__ */ new Set();
24972
25111
  var cache = /* @__PURE__ */ new Map();
24973
25112
  var pendingCallbacks = /* @__PURE__ */ new Map();
24974
- function createCanvas3(width, height) {
25113
+ function createCanvas4(width, height) {
24975
25114
  if (typeof OffscreenCanvas !== "undefined") {
24976
25115
  return new OffscreenCanvas(width, height);
24977
25116
  }
@@ -24985,7 +25124,7 @@ const wa = `"use strict";
24985
25124
  }
24986
25125
  function convertToAlphaMask(source) {
24987
25126
  const { width, height } = source;
24988
- const tempCanvas = createCanvas3(width, height);
25127
+ const tempCanvas = createCanvas4(width, height);
24989
25128
  const tempCtx = getContext(tempCanvas);
24990
25129
  if (!tempCtx) throw new Error("Failed to get 2d context for temp canvas");
24991
25130
  tempCtx.drawImage(source, 0, 0);
@@ -25002,7 +25141,7 @@ const wa = `"use strict";
25002
25141
  data[i + 2] = 255;
25003
25142
  data[i + 3] = alpha;
25004
25143
  }
25005
- const maskCanvas = createCanvas3(width, height);
25144
+ const maskCanvas = createCanvas4(width, height);
25006
25145
  const maskCtx = getContext(maskCanvas);
25007
25146
  if (!maskCtx) throw new Error("Failed to get 2d context for mask canvas");
25008
25147
  maskCtx.putImageData(imageData, 0, 0);
@@ -25576,7 +25715,7 @@ const wa = `"use strict";
25576
25715
  }
25577
25716
 
25578
25717
  // src/rendering/MaskRenderer.ts
25579
- var logger3 = createLogger("MaskRenderer");
25718
+ var logger4 = createLogger("MaskRenderer");
25580
25719
  var workerMaskBitmaps = /* @__PURE__ */ new Map();
25581
25720
  function registerMaskBitmap(imageUrl, bitmap) {
25582
25721
  workerMaskBitmaps.set(imageUrl, bitmap);
@@ -25593,7 +25732,7 @@ const wa = `"use strict";
25593
25732
  const offscreen = createOffscreenCanvas5(canvas.width, canvas.height);
25594
25733
  const offCtx = offscreen.getContext("2d");
25595
25734
  if (!offCtx) {
25596
- logger3.error("[renderWithMasks] Failed to get offscreen context");
25735
+ logger4.error("[renderWithMasks] Failed to get offscreen context");
25597
25736
  return;
25598
25737
  }
25599
25738
  const transform = ctx.getTransform();
@@ -25840,6 +25979,122 @@ const wa = `"use strict";
25840
25979
  }
25841
25980
  }
25842
25981
 
25982
+ // src/errors/editorError.ts
25983
+ var EditorError = class extends Error {
25984
+ constructor(code, message, data = {}) {
25985
+ super(\`[Editor] \${code}: \${message}\`);
25986
+ this.name = "EditorError";
25987
+ this.code = code;
25988
+ this.data = { code, ...data };
25989
+ }
25990
+ };
25991
+
25992
+ // src/utils/custom-fonts.ts
25993
+ function familyKey(family) {
25994
+ return family.trim().toLowerCase();
25995
+ }
25996
+ function faceKey(font) {
25997
+ return \`\${familyKey(font.family)}|\${font.weight ?? 400}|\${font.style ?? "normal"}\`;
25998
+ }
25999
+ var CustomFontRegistryClass = class {
26000
+ constructor() {
26001
+ this.fonts = /* @__PURE__ */ new Map();
26002
+ this.listeners = /* @__PURE__ */ new Set();
26003
+ /** Stable snapshot for \`useSyncExternalStore\` — replaced only on change. */
26004
+ this.snapshot = [];
26005
+ /** All registered custom fonts (stable reference until a change). */
26006
+ this.list = () => {
26007
+ return this.snapshot;
26008
+ };
26009
+ this.subscribe = (listener) => {
26010
+ this.listeners.add(listener);
26011
+ return () => {
26012
+ this.listeners.delete(listener);
26013
+ };
26014
+ };
26015
+ }
26016
+ /**
26017
+ * Register fonts (idempotent; re-registering the same family/weight/style
26018
+ * replaces the URL). Returns true when anything changed.
26019
+ */
26020
+ register(fonts) {
26021
+ let changed = false;
26022
+ for (const font of fonts) {
26023
+ const key = faceKey(font);
26024
+ const existing = this.fonts.get(key);
26025
+ if (existing && existing.url === font.url && existing.family === font.family) continue;
26026
+ this.fonts.set(key, { ...font });
26027
+ changed = true;
26028
+ }
26029
+ if (changed) {
26030
+ this.snapshot = Object.freeze([...this.fonts.values()]);
26031
+ for (const listener of this.listeners) listener();
26032
+ }
26033
+ return changed;
26034
+ }
26035
+ /** Is this family registered as a custom font? (Shadowing check.) */
26036
+ has(family) {
26037
+ const key = familyKey(family);
26038
+ for (const font of this.fonts.values()) {
26039
+ if (familyKey(font.family) === key) return true;
26040
+ }
26041
+ return false;
26042
+ }
26043
+ /** All registered faces of one family (possibly several weights/styles). */
26044
+ facesOf(family) {
26045
+ const key = familyKey(family);
26046
+ return [...this.fonts.values()].filter((f) => familyKey(f.family) === key);
26047
+ }
26048
+ /** Registered faces whose family appears in \`families\` — what the export
26049
+ * path sends to the worker alongside the used-font list. */
26050
+ forFamilies(families) {
26051
+ const keys = new Set(families.map(familyKey));
26052
+ return [...this.fonts.values()].filter((f) => keys.has(familyKey(f.family)));
26053
+ }
26054
+ /** @internal Test helper — wipe registry state between tests. */
26055
+ clear() {
26056
+ this.fonts.clear();
26057
+ this.snapshot = Object.freeze([]);
26058
+ for (const listener of this.listeners) listener();
26059
+ }
26060
+ };
26061
+ var customFontRegistry = new CustomFontRegistryClass();
26062
+ var loadedFaceKeys = /* @__PURE__ */ new Set();
26063
+ async function loadCustomFont(font, options = {}) {
26064
+ const face = await loadFontFaceFromUrl(
26065
+ font.family,
26066
+ {
26067
+ fontFileUrl: font.url,
26068
+ descriptors: {
26069
+ weight: String(font.weight ?? 400),
26070
+ style: font.style ?? "normal"
26071
+ }
26072
+ },
26073
+ options.fetchImpl ?? fetch
26074
+ );
26075
+ if (!face) {
26076
+ throw new EditorError(
26077
+ "E_FONT_LOAD_FAILED",
26078
+ \`Custom font "\${font.family}" failed to load from \${font.url}. The URL must serve the font binary over a plain cross-origin GET (CORS). Verify the URL is reachable and sends Access-Control-Allow-Origin, then re-register the font. Custom fonts never fall back silently \\u2014 the design would render with the wrong typeface.\`,
26079
+ {
26080
+ family: font.family,
26081
+ url: font.url,
26082
+ weight: font.weight ?? 400,
26083
+ style: font.style ?? "normal"
26084
+ }
26085
+ );
26086
+ }
26087
+ const target = options.fonts ?? (typeof document !== "undefined" ? document.fonts : void 0);
26088
+ target?.add(face);
26089
+ loadedFaceKeys.add(faceKey(font));
26090
+ return face;
26091
+ }
26092
+ async function loadCustomFontFaces(fonts, fontFaceSet, fetchImpl = fetch) {
26093
+ await Promise.all(
26094
+ fonts.map((font) => loadCustomFont(font, { fonts: fontFaceSet, fetchImpl }))
26095
+ );
26096
+ }
26097
+
25843
26098
  // src/workers/export-worker.ts
25844
26099
  var MAX_BITMAP_CACHE_SIZE = 50;
25845
26100
  var workerBitmapCache = /* @__PURE__ */ new Map();
@@ -25898,10 +26153,29 @@ const wa = `"use strict";
25898
26153
  }
25899
26154
  var loadedFonts = /* @__PURE__ */ new Set();
25900
26155
  var failedFonts = /* @__PURE__ */ new Set();
25901
- async function loadFonts(fontFamilies) {
26156
+ async function loadFonts(fontFamilies, customFonts = []) {
25902
26157
  if (!fontFamilies || fontFamilies.length === 0) return;
26158
+ const customByFamily = /* @__PURE__ */ new Map();
26159
+ for (const font of customFonts) {
26160
+ const key = font.family.trim().toLowerCase();
26161
+ const faces = customByFamily.get(key) ?? [];
26162
+ faces.push(font);
26163
+ customByFamily.set(key, faces);
26164
+ }
25903
26165
  const loadPromises = fontFamilies.map(async (fontFamily) => {
25904
26166
  if (loadedFonts.has(fontFamily) || failedFonts.has(fontFamily)) return;
26167
+ const customFaces = customByFamily.get(fontFamily.trim().toLowerCase());
26168
+ if (customFaces) {
26169
+ await loadCustomFontFaces(customFaces, self.fonts);
26170
+ if (self.fonts && self.fonts.ready) {
26171
+ await Promise.race([
26172
+ self.fonts.ready,
26173
+ new Promise((resolve) => setTimeout(resolve, 250))
26174
+ ]);
26175
+ }
26176
+ loadedFonts.add(fontFamily);
26177
+ return;
26178
+ }
25905
26179
  if (SYSTEM_FONTS.has(fontFamily)) {
25906
26180
  loadedFonts.add(fontFamily);
25907
26181
  return;
@@ -25987,6 +26261,7 @@ const wa = `"use strict";
25987
26261
  artboardData,
25988
26262
  elements = [],
25989
26263
  fonts = [],
26264
+ customFonts = [],
25990
26265
  scale = 1,
25991
26266
  format = "png",
25992
26267
  quality = 0.95,
@@ -25994,7 +26269,7 @@ const wa = `"use strict";
25994
26269
  } = request;
25995
26270
  try {
25996
26271
  if (fonts && fonts.length > 0) {
25997
- await loadFonts(fonts);
26272
+ await loadFonts(fonts, customFonts);
25998
26273
  }
25999
26274
  const width = artboardData.width * scale;
26000
26275
  const height = artboardData.height * scale;
@@ -26393,8 +26668,120 @@ const wa = `"use strict";
26393
26668
  console.error("[Export Worker] Unhandled promise rejection:", event.reason);
26394
26669
  };
26395
26670
  })();
26396
- `, O = U("WorkerExport");
26397
- class un {
26671
+ `;
26672
+ async function Aa(e, n, t = fetch) {
26673
+ try {
26674
+ const a = await t(n.fontFileUrl, { mode: "cors" });
26675
+ if (!a.ok) return null;
26676
+ const r = await a.arrayBuffer(), o = new FontFace(e, r, n.descriptors);
26677
+ return await o.load(), o;
26678
+ } catch {
26679
+ return null;
26680
+ }
26681
+ }
26682
+ function X(e) {
26683
+ return e.trim().toLowerCase();
26684
+ }
26685
+ function Yn(e) {
26686
+ return `${X(e.family)}|${e.weight ?? 400}|${e.style ?? "normal"}`;
26687
+ }
26688
+ class Pa {
26689
+ constructor() {
26690
+ this.fonts = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.snapshot = [], this.list = () => this.snapshot, this.subscribe = (n) => (this.listeners.add(n), () => {
26691
+ this.listeners.delete(n);
26692
+ });
26693
+ }
26694
+ /**
26695
+ * Register fonts (idempotent; re-registering the same family/weight/style
26696
+ * replaces the URL). Returns true when anything changed.
26697
+ */
26698
+ register(n) {
26699
+ let t = !1;
26700
+ for (const a of n) {
26701
+ const r = Yn(a), o = this.fonts.get(r);
26702
+ o && o.url === a.url && o.family === a.family || (this.fonts.set(r, { ...a }), t = !0);
26703
+ }
26704
+ if (t) {
26705
+ this.snapshot = Object.freeze([...this.fonts.values()]);
26706
+ for (const a of this.listeners) a();
26707
+ }
26708
+ return t;
26709
+ }
26710
+ /** Is this family registered as a custom font? (Shadowing check.) */
26711
+ has(n) {
26712
+ const t = X(n);
26713
+ for (const a of this.fonts.values())
26714
+ if (X(a.family) === t) return !0;
26715
+ return !1;
26716
+ }
26717
+ /** All registered faces of one family (possibly several weights/styles). */
26718
+ facesOf(n) {
26719
+ const t = X(n);
26720
+ return [...this.fonts.values()].filter((a) => X(a.family) === t);
26721
+ }
26722
+ /** Registered faces whose family appears in `families` — what the export
26723
+ * path sends to the worker alongside the used-font list. */
26724
+ forFamilies(n) {
26725
+ const t = new Set(n.map(X));
26726
+ return [...this.fonts.values()].filter((a) => t.has(X(a.family)));
26727
+ }
26728
+ /** @internal Test helper — wipe registry state between tests. */
26729
+ clear() {
26730
+ this.fonts.clear(), this.snapshot = Object.freeze([]);
26731
+ for (const n of this.listeners) n();
26732
+ }
26733
+ }
26734
+ const Wn = new Pa();
26735
+ function Ia(e) {
26736
+ Wn.register(e);
26737
+ }
26738
+ const We = /* @__PURE__ */ new Set();
26739
+ async function Fa(e, n = {}) {
26740
+ const t = await Aa(
26741
+ e.family,
26742
+ {
26743
+ fontFileUrl: e.url,
26744
+ descriptors: {
26745
+ weight: String(e.weight ?? 400),
26746
+ style: e.style ?? "normal"
26747
+ }
26748
+ },
26749
+ n.fetchImpl ?? fetch
26750
+ );
26751
+ if (!t)
26752
+ throw new we(
26753
+ "E_FONT_LOAD_FAILED",
26754
+ `Custom font "${e.family}" failed to load from ${e.url}. The URL must serve the font binary over a plain cross-origin GET (CORS). Verify the URL is reachable and sends Access-Control-Allow-Origin, then re-register the font. Custom fonts never fall back silently — the design would render with the wrong typeface.`,
26755
+ {
26756
+ family: e.family,
26757
+ url: e.url,
26758
+ weight: e.weight ?? 400,
26759
+ style: e.style ?? "normal"
26760
+ }
26761
+ );
26762
+ const a = n.fonts ?? (typeof document < "u" ? document.fonts : void 0);
26763
+ return a == null || a.add(t), We.add(Yn(e)), t;
26764
+ }
26765
+ async function Xa(e, n = {}) {
26766
+ Ia(e);
26767
+ const { onLoadError: t, ...a } = n;
26768
+ await Promise.all(
26769
+ e.map(async (r) => {
26770
+ if (!We.has(Yn(r)))
26771
+ try {
26772
+ await Fa(r, a);
26773
+ } catch (o) {
26774
+ if (t && o instanceof we) {
26775
+ t(o, r);
26776
+ return;
26777
+ }
26778
+ throw o;
26779
+ }
26780
+ })
26781
+ );
26782
+ }
26783
+ const M = U("WorkerExport");
26784
+ class pn {
26398
26785
  constructor() {
26399
26786
  this.worker = null, this.workerBlobUrl = null, this.pendingRequests = /* @__PURE__ */ new Map(), this.requestQueue = [], this.blobRequestQueue = [], this.isProcessingQueue = !1, this.isReady = !1, this.readyPromise = null, this.requestIdCounter = 0, this.workerCrashCount = 0, this.MAX_CRASHES_BEFORE_FALLBACK = 3, this.lastCrashTime = 0, this.CRASH_RESET_TIMEOUT = 6e4, this.progressListeners = /* @__PURE__ */ new Set(), this.idleTimeout = null, this.IDLE_TIMEOUT_MS = 3e4;
26400
26787
  }
@@ -26421,7 +26808,7 @@ class un {
26421
26808
  try {
26422
26809
  t(n);
26423
26810
  } catch (a) {
26424
- O.error("Error in progress listener:", a);
26811
+ M.error("Error in progress listener:", a);
26425
26812
  }
26426
26813
  }
26427
26814
  /**
@@ -26456,7 +26843,7 @@ class un {
26456
26843
  * Call this when exiting editor mode to free memory.
26457
26844
  */
26458
26845
  clearWorkerBitmapCache() {
26459
- if (Ln(), this.worker && this.isReady) {
26846
+ if (Nn(), this.worker && this.isReady) {
26460
26847
  const n = {
26461
26848
  type: "clear-all-bitmaps"
26462
26849
  };
@@ -26468,7 +26855,7 @@ class un {
26468
26855
  * Call this when an element is removed or its image source changes.
26469
26856
  */
26470
26857
  clearWorkerBitmap(n) {
26471
- if (Re(n), this.worker && this.isReady) {
26858
+ if (Ue(n), this.worker && this.isReady) {
26472
26859
  const t = {
26473
26860
  type: "clear-bitmap",
26474
26861
  elementId: n
@@ -26481,9 +26868,9 @@ class un {
26481
26868
  */
26482
26869
  static supportsWorkerExport() {
26483
26870
  try {
26484
- return typeof OffscreenCanvas > "u" ? (O.warn("OffscreenCanvas not supported"), !1) : typeof Worker > "u" ? (O.warn("Web Workers not supported"), !1) : new OffscreenCanvas(1, 1).getContext("2d") ? !0 : (O.warn("OffscreenCanvas 2D context not supported"), !1);
26871
+ return typeof OffscreenCanvas > "u" ? (M.warn("OffscreenCanvas not supported"), !1) : typeof Worker > "u" ? (M.warn("Web Workers not supported"), !1) : new OffscreenCanvas(1, 1).getContext("2d") ? !0 : (M.warn("OffscreenCanvas 2D context not supported"), !1);
26485
26872
  } catch (n) {
26486
- return O.warn("Feature detection failed:", n), !1;
26873
+ return M.warn("Feature detection failed:", n), !1;
26487
26874
  }
26488
26875
  }
26489
26876
  /**
@@ -26492,34 +26879,34 @@ class un {
26492
26879
  async initialize() {
26493
26880
  if (this.worker)
26494
26881
  return this.readyPromise || Promise.resolve();
26495
- if (!un.supportsWorkerExport())
26882
+ if (!pn.supportsWorkerExport())
26496
26883
  throw new Error("Browser does not support OffscreenCanvas or Web Workers");
26497
26884
  return this.readyPromise = new Promise((n, t) => {
26498
26885
  try {
26499
26886
  let a;
26500
26887
  try {
26501
- const s = new Blob([wa], { type: "application/javascript" });
26888
+ const s = new Blob([Ea], { type: "application/javascript" });
26502
26889
  a = URL.createObjectURL(s), this.workerBlobUrl = a;
26503
26890
  } catch (s) {
26504
- O.error("Failed to create worker blob:", s), t(new Error(`Worker creation failed: ${s instanceof Error ? s.message : String(s)}`));
26891
+ M.error("Failed to create worker blob:", s), t(new Error(`Worker creation failed: ${s instanceof Error ? s.message : String(s)}`));
26505
26892
  return;
26506
26893
  }
26507
26894
  this.worker = new Worker(a, { type: "classic" }), this.worker.onmessage = (s) => {
26508
26895
  this.handleWorkerMessage(s.data);
26509
26896
  }, this.worker.onerror = (s) => {
26510
- O.error("Worker error:", s), this.handleWorkerError(s);
26897
+ M.error("Worker error:", s), this.handleWorkerError(s);
26511
26898
  };
26512
26899
  const r = setTimeout(() => {
26513
26900
  t(new Error("Worker initialization timeout"));
26514
26901
  }, 15e3), o = (s) => {
26515
- s.data.type === "ready" && (clearTimeout(r), this.isReady = !0, xa(
26902
+ s.data.type === "ready" && (clearTimeout(r), this.isReady = !0, Ta(
26516
26903
  () => this.clearWorkerBitmapCache(),
26517
26904
  (c) => this.clearWorkerBitmap(c)
26518
26905
  ), n());
26519
26906
  };
26520
26907
  this.worker.addEventListener("message", o, { once: !0 });
26521
26908
  } catch (a) {
26522
- O.error("Failed to create worker:", a), t(a);
26909
+ M.error("Failed to create worker:", a), t(a);
26523
26910
  }
26524
26911
  }), this.readyPromise;
26525
26912
  }
@@ -26528,8 +26915,8 @@ class un {
26528
26915
  */
26529
26916
  async restartWorker() {
26530
26917
  const n = Date.now();
26531
- if (n - this.lastCrashTime > this.CRASH_RESET_TIMEOUT && (this.workerCrashCount = 0), this.workerCrashCount++, this.lastCrashTime = n, O.warn(`Worker crashed (${this.workerCrashCount}/${this.MAX_CRASHES_BEFORE_FALLBACK})`), this.workerCrashCount >= this.MAX_CRASHES_BEFORE_FALLBACK)
26532
- throw O.error("Worker crashed too many times, giving up"), new Error("Worker has crashed too many times. Please refresh the page or use main thread export.");
26918
+ if (n - this.lastCrashTime > this.CRASH_RESET_TIMEOUT && (this.workerCrashCount = 0), this.workerCrashCount++, this.lastCrashTime = n, M.warn(`Worker crashed (${this.workerCrashCount}/${this.MAX_CRASHES_BEFORE_FALLBACK})`), this.workerCrashCount >= this.MAX_CRASHES_BEFORE_FALLBACK)
26919
+ throw M.error("Worker crashed too many times, giving up"), new Error("Worker has crashed too many times. Please refresh the page or use main thread export.");
26533
26920
  this.worker && (this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null));
26534
26921
  const t = Math.min(1e3 * Math.pow(2, this.workerCrashCount - 1), 5e3);
26535
26922
  await new Promise((a) => setTimeout(a, t)), await this.initialize();
@@ -26589,7 +26976,7 @@ class un {
26589
26976
  const { artboard: t, elements: a, config: r } = n;
26590
26977
  if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
26591
26978
  throw new Error("Worker is not initialized");
26592
- const o = `export-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await be(t, a);
26979
+ const o = `export-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await ye(t, a);
26593
26980
  i.length > 0 && this.registerBitmapsWithWorker(i);
26594
26981
  const l = {
26595
26982
  type: "export",
@@ -26597,6 +26984,10 @@ class un {
26597
26984
  artboardData: c.artboard,
26598
26985
  elements: c.elements,
26599
26986
  fonts: c.fonts,
26987
+ // Custom (brand) fonts among the used families — the worker loads
26988
+ // these from their hosted URL instead of Google Fonts (deterministic
26989
+ // shadowing; see utils/custom-fonts.ts).
26990
+ customFonts: Wn.forFamilies(c.fonts ?? []),
26600
26991
  scale: r.scale || 1,
26601
26992
  format: r.format || "png",
26602
26993
  quality: r.quality || 0.95
@@ -26646,7 +27037,7 @@ class un {
26646
27037
  const { artboard: t, elements: a, config: r } = n;
26647
27038
  if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
26648
27039
  throw new Error("Worker is not initialized");
26649
- const o = `export-blob-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await be(t, a);
27040
+ const o = `export-blob-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await ye(t, a);
26650
27041
  i.length > 0 && this.registerBitmapsWithWorker(i);
26651
27042
  const l = {
26652
27043
  type: "export",
@@ -26654,6 +27045,8 @@ class un {
26654
27045
  artboardData: c.artboard,
26655
27046
  elements: c.elements,
26656
27047
  fonts: c.fonts,
27048
+ // Same custom-font threading as the dataUrl path above.
27049
+ customFonts: Wn.forFamilies(c.fonts ?? []),
26657
27050
  scale: r.scale || 1,
26658
27051
  format: r.format || "png",
26659
27052
  quality: r.quality || 0.95,
@@ -26704,7 +27097,7 @@ class un {
26704
27097
  case "ready":
26705
27098
  break;
26706
27099
  default:
26707
- O.warn("Unknown message type:", n);
27100
+ M.warn("Unknown message type:", n);
26708
27101
  }
26709
27102
  }
26710
27103
  /**
@@ -26712,14 +27105,14 @@ class un {
26712
27105
  */
26713
27106
  handleExportComplete(n) {
26714
27107
  const t = this.pendingRequests.get(n.requestId);
26715
- t && t.returnFormat === "dataUrl" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (O.warn("Received dataUrl response for blob request:", n.requestId), t.reject(new Error("Received dataUrl response when expecting blob")), this.pendingRequests.delete(n.requestId)) : O.warn("Received response for unknown request:", n.requestId);
27108
+ t && t.returnFormat === "dataUrl" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (M.warn("Received dataUrl response for blob request:", n.requestId), t.reject(new Error("Received dataUrl response when expecting blob")), this.pendingRequests.delete(n.requestId)) : M.warn("Received response for unknown request:", n.requestId);
26716
27109
  }
26717
27110
  /**
26718
27111
  * Handle successful blob export completion
26719
27112
  */
26720
27113
  handleBlobExportComplete(n) {
26721
27114
  const t = this.pendingRequests.get(n.requestId);
26722
- t && t.returnFormat === "blob" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (O.warn("Received blob response for dataUrl request:", n.requestId), t.reject(new Error("Received blob response when expecting dataUrl")), this.pendingRequests.delete(n.requestId)) : O.warn("Received blob response for unknown request:", n.requestId);
27115
+ t && t.returnFormat === "blob" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (M.warn("Received blob response for dataUrl request:", n.requestId), t.reject(new Error("Received blob response when expecting dataUrl")), this.pendingRequests.delete(n.requestId)) : M.warn("Received blob response for unknown request:", n.requestId);
26723
27116
  }
26724
27117
  /**
26725
27118
  * Handle export error
@@ -26730,13 +27123,13 @@ class un {
26730
27123
  const a = new Error(n.error);
26731
27124
  n.stack && (a.stack = n.stack), t.reject(a), this.pendingRequests.delete(n.requestId);
26732
27125
  } else
26733
- O.warn("Received error for unknown request:", n.requestId);
27126
+ M.warn("Received error for unknown request:", n.requestId);
26734
27127
  }
26735
27128
  /**
26736
27129
  * Handle worker errors
26737
27130
  */
26738
27131
  async handleWorkerError(n) {
26739
- O.error("Worker error:", n);
27132
+ M.error("Worker error:", n);
26740
27133
  const t = Array.from(this.pendingRequests.values());
26741
27134
  for (const [a, r] of this.pendingRequests.entries())
26742
27135
  this.pendingRequests.delete(a);
@@ -26744,7 +27137,7 @@ class un {
26744
27137
  try {
26745
27138
  await this.restartWorker();
26746
27139
  } catch (a) {
26747
- O.error("Failed to restart worker:", a);
27140
+ M.error("Failed to restart worker:", a);
26748
27141
  for (const r of t)
26749
27142
  r.reject(new Error(`Worker crashed and could not be restarted: ${n.message}`));
26750
27143
  for (; this.requestQueue.length > 0; )
@@ -26760,7 +27153,7 @@ class un {
26760
27153
  t.reject(new Error("Worker terminated")), this.pendingRequests.delete(n);
26761
27154
  for (; this.requestQueue.length > 0; )
26762
27155
  this.requestQueue.shift().reject(new Error("Worker terminated"));
26763
- this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, Ln(), va(), this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null);
27156
+ this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, Nn(), _a(), this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null);
26764
27157
  }
26765
27158
  }
26766
27159
  /**
@@ -26775,32 +27168,32 @@ class un {
26775
27168
  };
26776
27169
  }
26777
27170
  }
26778
- let Q = null;
26779
- function La() {
26780
- return Q || (Q = new un()), Q;
27171
+ let nn = null;
27172
+ function Ya() {
27173
+ return nn || (nn = new pn()), nn;
26781
27174
  }
26782
- function Na() {
26783
- Q && (Q.terminate(), Q = null);
27175
+ function Ka() {
27176
+ nn && (nn.terminate(), nn = null);
26784
27177
  }
26785
- Hn();
27178
+ jn();
26786
27179
  const W = U("Export");
26787
- function Un(e, n) {
27180
+ function zn(e, n) {
26788
27181
  var t;
26789
27182
  if (!(!e || typeof e != "object")) {
26790
27183
  if (typeof e.fontFamily == "string" && e.fontFamily.trim() && n.add(e.fontFamily), e.richText && Array.isArray(e.richText.spans))
26791
27184
  for (const a of e.richText.spans)
26792
27185
  (t = a == null ? void 0 : a.style) != null && t.fontFamily && typeof a.style.fontFamily == "string" && n.add(a.style.fontFamily);
26793
27186
  if (Array.isArray(e.children))
26794
- for (const a of e.children) Un(a, n);
27187
+ for (const a of e.children) zn(a, n);
26795
27188
  if (Array.isArray(e.masks))
26796
27189
  for (const a of e.masks)
26797
- a != null && a.maskElement && Un(a.maskElement, n);
27190
+ a != null && a.maskElement && zn(a.maskElement, n);
26798
27191
  }
26799
27192
  }
26800
- async function ge(e) {
27193
+ async function $e(e) {
26801
27194
  if (typeof document > "u" || !document.fonts) return;
26802
27195
  const n = /* @__PURE__ */ new Set();
26803
- for (const a of e) Un(a, n);
27196
+ for (const a of e) zn(a, n);
26804
27197
  if (n.size === 0) return;
26805
27198
  const t = [];
26806
27199
  for (const a of n)
@@ -26808,12 +27201,12 @@ async function ge(e) {
26808
27201
  }));
26809
27202
  await Promise.all(t), document.fonts.ready && await document.fonts.ready;
26810
27203
  }
26811
- const ln = class ln {
27204
+ const dn = class dn {
26812
27205
  /**
26813
27206
  * Check if worker export is supported in this browser
26814
27207
  */
26815
27208
  static supportsWorkerExport() {
26816
- return un.supportsWorkerExport();
27209
+ return pn.supportsWorkerExport();
26817
27210
  }
26818
27211
  /**
26819
27212
  * Get or initialize the worker manager
@@ -26821,7 +27214,7 @@ const ln = class ln {
26821
27214
  static async getWorkerManager() {
26822
27215
  return this.supportsWorkerExport() ? this.workerManager ? this.workerManager : this.workerInitPromise ? (await this.workerInitPromise, this.workerManager) : (this.workerInitPromise = (async () => {
26823
27216
  try {
26824
- this.workerManager = new un(), await this.workerManager.initialize();
27217
+ this.workerManager = new pn(), await this.workerManager.initialize();
26825
27218
  } catch (n) {
26826
27219
  W.error("Failed to initialize worker:", n), this.workerManager = null;
26827
27220
  }
@@ -26968,15 +27361,15 @@ const ln = class ln {
26968
27361
  transparentBackground: i = !1,
26969
27362
  backgroundColor: l = n.backgroundColor
26970
27363
  } = r;
26971
- await ge(t);
27364
+ await $e(t);
26972
27365
  const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
26973
27366
  d.width = u, d.height = p;
26974
27367
  const f = d.getContext("2d");
26975
27368
  if (f.scale(c, c), !i && n.exportBackground) {
26976
27369
  if (f.save(), this.applyExportBackgroundClipPath(f, n), n.backgroundType === "texture" && n.backgroundTexture) {
26977
- const m = J.getTexturePresetColor(n.backgroundTexture);
27370
+ const m = Z.getTexturePresetColor(n.backgroundTexture);
26978
27371
  f.fillStyle = m, f.fillRect(0, 0, n.width, n.height);
26979
- const g = J.getTexture(n.backgroundTexture);
27372
+ const g = Z.getTexture(n.backgroundTexture);
26980
27373
  g && g.complete && f.drawImage(g, 0, 0, n.width, n.height);
26981
27374
  } else
26982
27375
  f.fillStyle = l || n.backgroundColor, f.fillRect(0, 0, n.width, n.height);
@@ -27036,15 +27429,15 @@ const ln = class ln {
27036
27429
  transparentBackground: i = !1,
27037
27430
  backgroundColor: l = n.backgroundColor
27038
27431
  } = r;
27039
- await ge(t);
27432
+ await $e(t);
27040
27433
  const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
27041
27434
  d.width = u, d.height = p;
27042
27435
  const f = d.getContext("2d");
27043
27436
  if (f.scale(c, c), !i && n.exportBackground) {
27044
27437
  if (f.save(), this.applyExportBackgroundClipPath(f, n), n.backgroundType === "texture" && n.backgroundTexture) {
27045
- const T = J.getTexturePresetColor(n.backgroundTexture);
27438
+ const T = Z.getTexturePresetColor(n.backgroundTexture);
27046
27439
  f.fillStyle = T, f.fillRect(0, 0, n.width, n.height);
27047
- const k = J.getTexture(n.backgroundTexture);
27440
+ const k = Z.getTexture(n.backgroundTexture);
27048
27441
  k && k.complete ? f.drawImage(k, 0, 0, n.width, n.height) : W.warn("Texture not loaded for export:", n.backgroundTexture);
27049
27442
  } else
27050
27443
  f.fillStyle = l, f.fillRect(0, 0, n.width, n.height);
@@ -27084,24 +27477,24 @@ const ln = class ln {
27084
27477
  T.render(P, !1);
27085
27478
  };
27086
27479
  if (E && A)
27087
- re(f, w, (P) => {
27480
+ oe(f, w, (P) => {
27088
27481
  const I = T.getVisualBoundingBox();
27089
- de(P, w.distressEffect, I, S);
27482
+ pe(P, w.distressEffect, I, S);
27090
27483
  });
27091
27484
  else if (E)
27092
- re(f, w, S);
27485
+ oe(f, w, S);
27093
27486
  else if (A) {
27094
27487
  const P = T.getVisualBoundingBox();
27095
- de(f, w.distressEffect, P, S);
27488
+ pe(f, w.distressEffect, P, S);
27096
27489
  } else
27097
27490
  T.render(f, !1);
27098
27491
  }
27099
- }), (g = n.distressTexture) != null && g.enabled && ha(f, n.distressTexture, {
27492
+ }), (g = n.distressTexture) != null && g.enabled && xa(f, n.distressTexture, {
27100
27493
  x: n.x,
27101
27494
  y: n.y,
27102
27495
  width: n.width,
27103
27496
  height: n.height
27104
- }), (C = n.imageMask) != null && C.enabled && ra(f, n.imageMask, {
27497
+ }), (C = n.imageMask) != null && C.enabled && da(f, n.imageMask, {
27105
27498
  x: n.x,
27106
27499
  y: n.y,
27107
27500
  width: n.width,
@@ -27340,60 +27733,64 @@ const ln = class ln {
27340
27733
  return "previewBackgroundColor" in t && delete t.previewBackgroundColor, t;
27341
27734
  }
27342
27735
  };
27343
- ln.CURRENT_VERSION = "2.0.0", ln.workerManager = null, ln.workerInitPromise = null;
27344
- let xn = ln;
27345
- const Ua = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
27736
+ dn.CURRENT_VERSION = "2.0.0", dn.workerManager = null, dn.workerInitPromise = null;
27737
+ let vn = dn;
27738
+ const Ja = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
27346
27739
  __proto__: null,
27347
- ExportManager: xn,
27348
- default: xn
27740
+ ExportManager: vn,
27741
+ default: vn
27349
27742
  }, Symbol.toStringTag, { value: "Module" }));
27350
27743
  export {
27351
- Na as A,
27352
- Re as B,
27353
- gt as C,
27354
- Oe as D,
27355
- xn as E,
27356
- mn as F,
27357
- ua as G,
27358
- la as H,
27359
- ue as I,
27360
- Oa as J,
27361
- Dn as K,
27362
- de as L,
27363
- ha as M,
27364
- ra as N,
27365
- Hn as O,
27366
- Kt as P,
27367
- Yt as Q,
27368
- st as R,
27369
- Ua as S,
27370
- J as T,
27371
- un as W,
27372
- Aa as a,
27373
- xe as b,
27374
- B as c,
27375
- Ra as d,
27376
- Ma as e,
27377
- Ln as f,
27378
- Ca as g,
27379
- Ta as h,
27380
- ct as i,
27381
- _a as j,
27382
- ka as k,
27383
- dn as l,
27384
- La as m,
27385
- Fa as n,
27386
- Zn as o,
27387
- Ba as p,
27388
- Pn as q,
27389
- ft as r,
27390
- Pa as s,
27391
- Ea as t,
27392
- ht as u,
27393
- Ia as v,
27394
- bt as w,
27395
- ve as x,
27396
- Da as y,
27397
- re as z
27744
+ vt as A,
27745
+ ke as B,
27746
+ za as C,
27747
+ Ne as D,
27748
+ vn as E,
27749
+ oe as F,
27750
+ Ka as G,
27751
+ Ue as H,
27752
+ be as I,
27753
+ wt as J,
27754
+ yn as K,
27755
+ ya as L,
27756
+ ba as M,
27757
+ Va as N,
27758
+ Dn as O,
27759
+ pe as P,
27760
+ xa as Q,
27761
+ da as R,
27762
+ jn as S,
27763
+ Z as T,
27764
+ ta as U,
27765
+ ea as V,
27766
+ pn as W,
27767
+ ft as X,
27768
+ Ja as Y,
27769
+ mt as a,
27770
+ Na as b,
27771
+ Wn as c,
27772
+ Ce as d,
27773
+ Xa as e,
27774
+ B as f,
27775
+ Oa as g,
27776
+ ja as h,
27777
+ Ha as i,
27778
+ Nn as j,
27779
+ Ra as k,
27780
+ Fa as l,
27781
+ ht as m,
27782
+ Ba as n,
27783
+ Ma as o,
27784
+ fn as p,
27785
+ Ya as q,
27786
+ Ia as r,
27787
+ Ga as s,
27788
+ ee as t,
27789
+ qa as u,
27790
+ In as v,
27791
+ Ua as w,
27792
+ La as x,
27793
+ xt as y,
27794
+ Wa as z
27398
27795
  };
27399
- //# sourceMappingURL=ExportManager-B8Td7uR5.js.map
27796
+ //# sourceMappingURL=ExportManager-Bkzzyxgw.js.map