@snowcone-app/canvas 0.17.3 → 0.18.1

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 (65) hide show
  1. package/dist/{ImportManager-C_wBjWaV.js → CanvasRenderer-DUc-MOeR.js} +586 -806
  2. package/dist/CanvasRenderer-DUc-MOeR.js.map +1 -0
  3. package/dist/{CanvasStateV1-BG2hEc3-.js → CanvasStateV1-Bq48qhv5.js} +3 -3
  4. package/dist/{CanvasStateV1-BG2hEc3-.js.map → CanvasStateV1-Bq48qhv5.js.map} +1 -1
  5. package/dist/ContextualToolbars-CkLjHNPn.js +5833 -0
  6. package/dist/ContextualToolbars-CkLjHNPn.js.map +1 -0
  7. package/dist/EditorCanvasImpl-Bv4yagew.js +81 -0
  8. package/dist/EditorCanvasImpl-Bv4yagew.js.map +1 -0
  9. package/dist/EditorContext-5QpqAhjh.js +1184 -0
  10. package/dist/{EditorContext-CGkfmbgo.js.map → EditorContext-5QpqAhjh.js.map} +1 -1
  11. package/dist/{FontAnalyzer-CLv7_msL.js → FontAnalyzer-DIlqmyuf.js} +35 -35
  12. package/dist/FontAnalyzer-DIlqmyuf.js.map +1 -0
  13. package/dist/{ElementFactory-CuHSAPfg.js → ImportManager-D--7JnvW.js} +699 -476
  14. package/dist/ImportManager-D--7JnvW.js.map +1 -0
  15. package/dist/MenuButton-CeoEAtzP.js +7444 -0
  16. package/dist/MenuButton-CeoEAtzP.js.map +1 -0
  17. package/dist/SnowconeCanvas-C_O-aeaQ.js +1166 -0
  18. package/dist/SnowconeCanvas-C_O-aeaQ.js.map +1 -0
  19. package/dist/advanced.mjs +266 -264
  20. package/dist/advanced.mjs.map +1 -1
  21. package/dist/api/embed.d.ts +1 -1
  22. package/dist/components/ContextualToolbars.d.ts +8 -0
  23. package/dist/components/editor/EditorAdd.d.ts +11 -0
  24. package/dist/components/editor/EditorCanvasImpl.d.ts +6 -0
  25. package/dist/components/editor/EditorControls.d.ts +14 -0
  26. package/dist/components/editor/EditorHistory.d.ts +11 -0
  27. package/dist/components/editor/EditorLayers.d.ts +16 -0
  28. package/dist/components/editor/EditorMenu.d.ts +11 -0
  29. package/dist/components/editor/RootInternals.d.ts +7 -0
  30. package/dist/components/editor/index.d.ts +20 -0
  31. package/dist/components/embed/addElementTypes.d.ts +9 -0
  32. package/dist/contexts/EditorContext.d.ts +38 -0
  33. package/dist/core/preview-registry.d.ts +34 -0
  34. package/dist/{editorErrors-BY4Pdg7a.js → editorErrors-DXNfVXtD.js} +2 -2
  35. package/dist/{editorErrors-BY4Pdg7a.js.map → editorErrors-DXNfVXtD.js.map} +1 -1
  36. package/dist/embed-Cdbjay9i.js +961 -0
  37. package/dist/embed-Cdbjay9i.js.map +1 -0
  38. package/dist/embed.mjs +5 -5
  39. package/dist/index.mjs +7 -7
  40. package/dist/internals.mjs +12 -12
  41. package/dist/{template-fields-Z9x13sjM.js → template-fields-DgoBtajp.js} +266 -240
  42. package/dist/template-fields-DgoBtajp.js.map +1 -0
  43. package/dist/testing.mjs +3 -3
  44. package/dist/{usePieceGuideBundle-C1ipFnZd.js → usePieceGuideBundle-DVOISsB1.js} +2 -2
  45. package/dist/{usePieceGuideBundle-C1ipFnZd.js.map → usePieceGuideBundle-DVOISsB1.js.map} +1 -1
  46. package/dist/validation-0IscSfRb.js +9304 -0
  47. package/dist/validation-0IscSfRb.js.map +1 -0
  48. package/package.json +3 -3
  49. package/dist/EditorCanvasImpl-DQxqdgpq.js +0 -70
  50. package/dist/EditorCanvasImpl-DQxqdgpq.js.map +0 -1
  51. package/dist/EditorContext-CGkfmbgo.js +0 -1178
  52. package/dist/ElementFactory-CuHSAPfg.js.map +0 -1
  53. package/dist/FontAnalyzer-CLv7_msL.js.map +0 -1
  54. package/dist/ImportManager-C_wBjWaV.js.map +0 -1
  55. package/dist/SnowconeCanvas-DBbmx9qW.js +0 -1187
  56. package/dist/SnowconeCanvas-DBbmx9qW.js.map +0 -1
  57. package/dist/UnifiedFontService-Dsu5cwfT.js +0 -1478
  58. package/dist/UnifiedFontService-Dsu5cwfT.js.map +0 -1
  59. package/dist/embed--B8ot6Lj.js +0 -746
  60. package/dist/embed--B8ot6Lj.js.map +0 -1
  61. package/dist/iconify-D6eVIEy4.js +0 -1089
  62. package/dist/iconify-D6eVIEy4.js.map +0 -1
  63. package/dist/template-fields-Z9x13sjM.js.map +0 -1
  64. package/dist/validation-C795COGQ.js +0 -19959
  65. package/dist/validation-C795COGQ.js.map +0 -1
@@ -1,19 +1,110 @@
1
- import { a1 as me, a2 as ye, a3 as $e, a4 as ae, a5 as Y, a6 as Fn, c as V, $ as xe, a0 as ve, z as Bn, R as we, a7 as Se, a8 as bn, I as vn, P as Ce, S as ke, G as Te, M as _e, W as Ee, H as Ae, D as Pe, O as Ie, J as De, K as Fe } from "./FontAnalyzer-CLv7_msL.js";
2
- function ta(e, n, t) {
1
+ import { c as G, a1 as ve, a2 as we, a3 as Se, a4 as ce, a5 as Y, a6 as On, $ as Ce, a0 as ke, z as Un, R as Te, a7 as _e, a8 as mn, I as Sn, P as Ee, S as Ae, G as Pe, M as Ie, W as De, H as Fe, D as Me, O as Oe, J as Re, K as Be, A as zn } from "./FontAnalyzer-DIlqmyuf.js";
2
+ const Le = G("TextureManager"), an = class an {
3
+ /**
4
+ * Load a texture by ID or URL
5
+ */
6
+ static async loadTexture(n) {
7
+ if (this.cache.has(n))
8
+ return this.cache.get(n);
9
+ if (this.loading.has(n))
10
+ return this.loading.get(n);
11
+ const t = this.resolveTextureUrl(n), a = new Promise((r, o) => {
12
+ const s = new Image();
13
+ s.crossOrigin = "anonymous", s.onload = () => {
14
+ this.cache.set(n, s), this.cache.set(t, s), this.loading.delete(n), this.loading.delete(t), r(s);
15
+ }, s.onerror = () => {
16
+ Le.error("Failed to load texture:", t), this.loading.delete(n), this.loading.delete(t), o(new Error(`Failed to load texture: ${t}`));
17
+ }, s.src = t;
18
+ });
19
+ return this.loading.set(n, a), t !== n && this.loading.set(t, a), a;
20
+ }
21
+ /**
22
+ * Get a texture synchronously (returns null if not loaded)
23
+ */
24
+ static getTexture(n) {
25
+ const t = this.resolveTextureUrl(n);
26
+ return this.cache.get(n) || this.cache.get(t) || null;
27
+ }
28
+ /**
29
+ * Preload multiple textures
30
+ */
31
+ static async preloadTextures(n) {
32
+ await Promise.all(n.map((t) => this.loadTexture(t)));
33
+ }
34
+ /**
35
+ * Preload all built-in textures
36
+ */
37
+ static async preloadAllTextures() {
38
+ await this.preloadTextures(this.TEXTURES.map((n) => n.id));
39
+ }
40
+ /**
41
+ * Clear cache
42
+ */
43
+ static clearCache() {
44
+ this.cache.clear(), this.loading.clear();
45
+ }
46
+ /**
47
+ * Resolve texture URL from ID
48
+ */
49
+ static resolveTextureUrl(n) {
50
+ if (n.startsWith("http://") || n.startsWith("https://") || n.startsWith("/") || n.startsWith("data:"))
51
+ return n;
52
+ const t = this.TEXTURES.find((a) => a.id === n);
53
+ return t ? t.url : `/textures/${n}`;
54
+ }
55
+ /**
56
+ * Get texture info by ID
57
+ */
58
+ static getTextureInfo(n) {
59
+ return this.TEXTURES.find((t) => t.id === n);
60
+ }
61
+ /**
62
+ * Get all available textures
63
+ */
64
+ static getAllTextures() {
65
+ return [...this.TEXTURES];
66
+ }
67
+ /**
68
+ * Get textures by category
69
+ */
70
+ static getTexturesByCategory(n) {
71
+ return this.TEXTURES.filter((t) => t.category === n);
72
+ }
73
+ /**
74
+ * Get preset color for a texture
75
+ * Each texture has a fixed color that's part of its preset
76
+ */
77
+ static getTexturePresetColor(n) {
78
+ const t = this.TEXTURES.find((a) => a.id === n);
79
+ return (t == null ? void 0 : t.presetColor) || "#ffffff";
80
+ }
81
+ };
82
+ an.cache = /* @__PURE__ */ new Map(), an.loading = /* @__PURE__ */ new Map(), an.TEXTURES = [
83
+ {
84
+ id: "glass-frame",
85
+ name: "Glass Frame",
86
+ url: "/textures/glass-frame.svg",
87
+ category: "glass",
88
+ presetColor: "#ccc"
89
+ // Light gray
90
+ }
91
+ ];
92
+ let X = an;
93
+ function ia(e, n, t) {
3
94
  var l;
4
95
  e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180);
5
96
  const a = n, r = a.fontSize || 24, o = a.fontFamily || "Arial", s = a.bold || !1, c = a.italic || !1;
6
- e.font = me(r, o, s, c);
97
+ e.font = ve(r, o, s, c);
7
98
  const i = a.text || "";
8
99
  if (n.transformType === "custom") {
9
- const u = ((l = n.transformData) == null ? void 0 : l.width) || 200, p = ye(i, r, o, s, c), f = Math.min(p, u), m = r * 1.2;
100
+ const u = ((l = n.transformData) == null ? void 0 : l.width) || 200, p = we(i, r, o, s, c), f = Math.min(p, u), m = r * 1.2;
10
101
  e.rect(-f / 2, -m / 2, f, m);
11
102
  } else {
12
103
  const d = e.measureText(i).width;
13
104
  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);
14
105
  }
15
106
  }
16
- function Me(e, n) {
107
+ function Ne(e, n) {
17
108
  if (!n.transformData) return;
18
109
  const { borderRadius: t = 0 } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100;
19
110
  if (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), e.beginPath(), t > 0) {
@@ -22,22 +113,22 @@ function Me(e, n) {
22
113
  } else
23
114
  e.rect(-a / 2, -r / 2, a, r);
24
115
  }
25
- function aa(e, n, t, a) {
116
+ function oa(e, n, t, a) {
26
117
  e.beginPath(), e.arc(n, t, a, 0, Math.PI * 2), e.closePath();
27
118
  }
28
- function ra(e, n, t, a, r) {
119
+ function ca(e, n, t, a, r) {
29
120
  e.beginPath(), e.rect(n, t, a, r), e.closePath();
30
121
  }
31
- function re(e, n) {
122
+ function le(e, n) {
32
123
  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);
33
124
  }
34
- function Oe(e, n) {
125
+ function Ue(e, n) {
35
126
  if (typeof OffscreenCanvas < "u")
36
127
  return new OffscreenCanvas(e, n);
37
128
  const t = document.createElement("canvas");
38
129
  return t.width = e, t.height = n, t;
39
130
  }
40
- function se(e, n, t) {
131
+ function de(e, n, t) {
41
132
  var i;
42
133
  if (!((i = n.stroke) != null && i.enabled)) return;
43
134
  const a = n;
@@ -45,21 +136,21 @@ function se(e, n, t) {
45
136
  const o = (t == null ? void 0 : t.isKnockout) === !0, s = n.stroke.opacity ?? 1;
46
137
  if (!o && s < 1)
47
138
  try {
48
- Re(e, n, a, t, s);
139
+ ze(e, n, a, t, s);
49
140
  } catch {
50
141
  tn(e, n, a, t, !1);
51
142
  }
52
143
  else
53
144
  tn(e, n, a, t, o);
54
145
  }
55
- function Re(e, n, t, a, r) {
146
+ function ze(e, n, t, a, r) {
56
147
  var C, _;
57
148
  const o = t.text || "", s = t.fontSize || 24, c = n.stroke.width, i = n.stroke.feather || 0, l = n.transformType === "custom" && ((C = n.transformData) == null ? void 0 : C.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(), m = Math.max(Math.abs(f.a), Math.abs(f.d), 1), b = Math.ceil(u * m / 2) * 2, h = Math.ceil(p * m / 2) * 2;
58
149
  if (b <= 0 || h <= 0) {
59
150
  tn(e, n, t, a, !1);
60
151
  return;
61
152
  }
62
- const S = Oe(b, h), $ = S.getContext("2d");
153
+ const S = Ue(b, h), $ = S.getContext("2d");
63
154
  if (!$) {
64
155
  tn(e, n, t, a, !1);
65
156
  return;
@@ -86,9 +177,9 @@ function tn(e, n, t, a, r) {
86
177
  e.save(), a != null && a.positionApplied || (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180));
87
178
  const s = t.fontSize || 24, c = t.fontFamily || "Arial", i = t.bold || !1, l = t.italic || !1, d = t.textAlign || "center";
88
179
  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)`);
89
- const u = $e(s, c, i, l);
180
+ const u = Se(s, c, i, l);
90
181
  if (n.transformType === "custom" && ((f = n.transformData) == null ? void 0 : f.width)) {
91
- const m = n.transformData, b = (m == null ? void 0 : m.width) ?? 200, h = b - Y * 2, { lines: S, height: $ } = ae(
182
+ const m = n.transformData, b = (m == null ? void 0 : m.width) ?? 200, h = b - Y * 2, { lines: S, height: $ } = ce(
92
183
  o,
93
184
  h,
94
185
  s,
@@ -99,7 +190,7 @@ function tn(e, n, t, a, r) {
99
190
  // No locked line count for stroke
100
191
  !0
101
192
  // strict: wrap exactly at maxWidth
102
- ), v = -b / 2, g = -$ / 2, y = s * Fn;
193
+ ), v = -b / 2, g = -$ / 2, y = s * On;
103
194
  S.forEach((k, T) => {
104
195
  const C = T === 0, _ = T === S.length - 1;
105
196
  let w = k;
@@ -122,17 +213,17 @@ function tn(e, n, t, a, r) {
122
213
  }
123
214
  e.restore();
124
215
  }
125
- function Be(e, n, t) {
216
+ function We(e, n, t) {
126
217
  var r;
127
218
  if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
128
219
  const a = (t == null ? void 0 : t.isKnockout) === !0;
129
- 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)) : re(e, n.stroke), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), Me(e, n), e.stroke(), e.restore();
220
+ 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)) : le(e, n.stroke), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), Ne(e, n), e.stroke(), e.restore();
130
221
  }
131
- function sa(e, n, t) {
132
- n.enabled && (e.save(), re(e, n), n.feather && n.feather > 0 && "filter" in e && (e.filter = `blur(${n.feather}px)`), e.beginPath(), t(), e.stroke(), e.restore());
222
+ function la(e, n, t) {
223
+ n.enabled && (e.save(), le(e, n), n.feather && n.feather > 0 && "filter" in e && (e.filter = `blur(${n.feather}px)`), e.beginPath(), t(), e.stroke(), e.restore());
133
224
  }
134
- const Ln = V("GlyphRenderer");
135
- function Le(e, n, t, a, r, o, s, c = {}) {
225
+ const Wn = G("GlyphRenderer");
226
+ function Ge(e, n, t, a, r, o, s, c = {}) {
136
227
  try {
137
228
  const i = [];
138
229
  Object.entries(s).forEach(([h, S]) => {
@@ -170,7 +261,7 @@ function Le(e, n, t, a, r, o, s, c = {}) {
170
261
  }
171
262
  }
172
263
  } catch (g) {
173
- Ln.warn("Error getting path for glyph:", h.name, g);
264
+ Wn.warn("Error getting path for glyph:", h.name, g);
174
265
  }
175
266
  if (v) {
176
267
  const g = new Path2D(v);
@@ -179,10 +270,10 @@ function Le(e, n, t, a, r, o, s, c = {}) {
179
270
  b += h.advanceWidth * p;
180
271
  }), e.restore();
181
272
  } catch (i) {
182
- Ln.error("Error rendering with fontkit:", i), e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
273
+ Wn.error("Error rendering with fontkit:", i), e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
183
274
  }
184
275
  }
185
- function Ne(e, n, t, a, r, o, s, c = {}) {
276
+ function He(e, n, t, a, r, o, s, c = {}) {
186
277
  const l = ((h) => {
187
278
  for (const S of h) {
188
279
  const $ = S.codePointAt(0);
@@ -235,12 +326,12 @@ function Ne(e, n, t, a, r, o, s, c = {}) {
235
326
  }
236
327
  }), e.restore();
237
328
  }
238
- function Ue(e, n, t, a, r) {
329
+ function Ve(e, n, t, a, r) {
239
330
  e.fillStyle = t.color;
240
- const o = t.textAlign || "center", s = xe(n);
331
+ const o = t.textAlign || "center", s = Ce(n);
241
332
  let c, i;
242
333
  a !== void 0 && a > 0 && !r ? (c = [], i = [], s.forEach((m) => {
243
- const b = ve(m, a, t);
334
+ const b = ke(m, a, t);
244
335
  b.forEach((h, S) => {
245
336
  c.push(h), i.push({
246
337
  isParagraphStart: S === 0,
@@ -277,8 +368,8 @@ function Ue(e, n, t, a, r) {
277
368
  if (!g && _ > 0) {
278
369
  const B = y.length - _;
279
370
  if (Q > B) {
280
- const G = !v && C > 0 && M < C ? Math.min(C - M, x.text.length) : 0, yn = Math.max(0, B - M - G);
281
- I = I.substring(0, yn);
371
+ const H = !v && C > 0 && M < C ? Math.min(C - M, x.text.length) : 0, xn = Math.max(0, B - M - H);
372
+ I = I.substring(0, xn);
282
373
  }
283
374
  }
284
375
  E += x.text.length, I.length > 0 && (e.save(), e.font = R(P, A, F, D), w += e.measureText(I).width, e.restore());
@@ -294,7 +385,7 @@ function Ue(e, n, t, a, r) {
294
385
  isParagraphEnd: g
295
386
  });
296
387
  });
297
- const d = sn(t.fontSize, t.fontFamily, t.bold, t.italic), u = t.fontSize * Fn;
388
+ const d = sn(t.fontSize, t.fontFamily, t.bold, t.italic), u = t.fontSize * On;
298
389
  let p;
299
390
  l.length === 0 ? p = 0 : l.length === 1 ? p = d.height : p = (l.length - 1) * u + d.height;
300
391
  const f = -p / 2;
@@ -306,37 +397,37 @@ function Ue(e, n, t, a, r) {
306
397
  let E = 0;
307
398
  h.forEach((x) => {
308
399
  const P = x.style.fontSize !== void 0 ? x.style.fontSize : t.fontSize, A = x.style.fontFamily !== void 0 ? x.style.fontFamily : t.fontFamily, F = x.style.color !== void 0 ? x.style.color : t.color, D = x.style.bold !== void 0 ? x.style.bold : t.bold || !1, I = x.style.italic !== void 0 ? x.style.italic : t.italic || !1, M = x.style.underline !== void 0 ? x.style.underline : t.underline || !1, Q = x.style.strikethrough !== void 0 ? x.style.strikethrough : t.strikethrough || !1;
309
- let B = x.text, G = E, yn = E + x.text.length;
310
- if (!$ && _ > 0 && G < _) {
311
- const N = Math.min(_ - G, x.text.length);
400
+ let B = x.text, H = E, xn = E + x.text.length;
401
+ if (!$ && _ > 0 && H < _) {
402
+ const N = Math.min(_ - H, x.text.length);
312
403
  B = B.substring(N);
313
404
  }
314
405
  if (!v && w > 0) {
315
406
  const N = k.length - w;
316
- if (yn > N) {
317
- const H = !$ && _ > 0 && G < _ ? Math.min(_ - G, x.text.length) : 0, ge = Math.max(0, N - G - H);
318
- B = B.substring(0, ge);
407
+ if (xn > N) {
408
+ const V = !$ && _ > 0 && H < _ ? Math.min(_ - H, x.text.length) : 0, xe = Math.max(0, N - H - V);
409
+ B = B.substring(0, xe);
319
410
  }
320
411
  }
321
412
  if (E += x.text.length, B.length > 0) {
322
413
  e.font = R(P, A, D, I), e.fillStyle = F, e.textBaseline = "alphabetic", e.textAlign = "left", e.fillText(B, g, y);
323
414
  const N = e.measureText(B).width;
324
415
  if (M) {
325
- const H = y + P * 0.1;
326
- e.beginPath(), e.moveTo(g, H), e.lineTo(g + N, H), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
416
+ const V = y + P * 0.1;
417
+ e.beginPath(), e.moveTo(g, V), e.lineTo(g + N, V), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
327
418
  }
328
419
  if (Q) {
329
- const H = y - P * 0.25;
330
- e.beginPath(), e.moveTo(g, H), e.lineTo(g + N, H), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
420
+ const V = y - P * 0.25;
421
+ e.beginPath(), e.moveTo(g, V), e.lineTo(g + N, V), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
331
422
  }
332
423
  g += N;
333
424
  }
334
425
  });
335
426
  });
336
427
  }
337
- const wn = V("canvas-renderer");
428
+ const Cn = G("canvas-renderer");
338
429
  let ln = null;
339
- function Mn() {
430
+ function Rn() {
340
431
  if (!ln)
341
432
  if (typeof OffscreenCanvas < "u")
342
433
  ln = new OffscreenCanvas(1, 1).getContext("2d");
@@ -350,17 +441,17 @@ function R(e, n, t = !1, a = !1) {
350
441
  const r = [];
351
442
  return a && r.push("italic"), t && r.push("bold"), r.push(`${e}px`), r.push(n), r.join(" ");
352
443
  }
353
- function Nn(e, n, t, a = !1, r = !1) {
354
- const o = Mn();
444
+ function Gn(e, n, t, a = !1, r = !1) {
445
+ const o = Rn();
355
446
  return o.font = R(n, t, a, r), o.measureText(e).width;
356
447
  }
357
448
  function sn(e, n, t = !1, a = !1) {
358
- const r = Mn();
449
+ const r = Rn();
359
450
  r.font = R(e, n, t, a);
360
451
  const s = r.measureText("ÁÉÍgjpqy"), c = s.actualBoundingBoxAscent || e * 0.8, i = s.actualBoundingBoxDescent || e * 0.2, l = c + i;
361
452
  return { ascent: c, descent: i, height: l };
362
453
  }
363
- function ia(e, n) {
454
+ function da(e, n) {
364
455
  const t = e.map((r, o) => ({
365
456
  isParagraphStart: !n && o === 0,
366
457
  isParagraphEnd: !n && o === e.length - 1
@@ -373,14 +464,14 @@ function ia(e, n) {
373
464
  return s || (i = i.replace(/^ +/, "")), c || (i = i.replace(/ +$/, "")), i;
374
465
  }).filter((r) => r.length > 0);
375
466
  }
376
- function ze(e, n) {
467
+ function je(e, n) {
377
468
  const t = n.fontSize, a = n.fontFamily, r = n.bold || !1, o = n.italic || !1, s = n.textAlign || "center", c = n.text;
378
469
  e.font = R(t, a, r, o), e.textAlign = s, e.textBaseline = "alphabetic", e.fillStyle = n.color;
379
470
  const i = sn(t, a, r, o), u = -i.height / 2 + i.ascent;
380
471
  e.fillText(c, 0, u);
381
472
  }
382
- function We(e, n, t, a, r = !1, o = !1, s) {
383
- const c = Mn();
473
+ function qe(e, n, t, a, r = !1, o = !1, s) {
474
+ const c = Rn();
384
475
  if (c.font = R(t, a, r, o), e.trim().length === 0)
385
476
  return [e];
386
477
  if (e.includes(`
@@ -388,7 +479,7 @@ function We(e, n, t, a, r = !1, o = !1, s) {
388
479
  const C = e.split(`
389
480
  `), _ = [];
390
481
  for (let w = 0; w < C.length; w++) {
391
- const E = C[w], x = We(E, n, t, a, r, o);
482
+ const E = C[w], x = qe(E, n, t, a, r, o);
392
483
  _.push(...x);
393
484
  }
394
485
  return _;
@@ -416,7 +507,7 @@ function We(e, n, t, a, r = !1, o = !1, s) {
416
507
  }
417
508
  return g.push(y), g.length > 0 && (g[0] = d + g[0], g[g.length - 1] = g[g.length - 1] + u), g;
418
509
  }
419
- function oa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1, p = !1, f = !1, m, b) {
510
+ function fa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1, p = !1, f = !1, m, b) {
420
511
  e.font = R(r, o, d, u), e.textBaseline = "alphabetic", e.textAlign = s;
421
512
  const h = (w) => {
422
513
  for (const E of w) {
@@ -425,11 +516,11 @@ function oa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1,
425
516
  return !0;
426
517
  }
427
518
  return !1;
428
- }, S = m && Object.values(m).some((w) => w), $ = b && b.length > 0, v = n.join(" "), g = h(v), y = S || $ || g, k = y ? Bn.getFontSync(o, d ? 700 : 400) : null;
429
- y && !k && (wn.warn(
519
+ }, S = m && Object.values(m).some((w) => w), $ = b && b.length > 0, v = n.join(" "), g = h(v), y = S || $ || g, k = y ? Un.getFontSync(o, d ? 700 : 400) : null;
520
+ y && !k && (Cn.warn(
430
521
  `[renderMultilineText] Font ${o} not loaded for fontkit rendering. Text may not render correctly. Has PUA: ${g}, Text: "${v}"`
431
- ), Bn.loadFont(o, d ? 700 : 400).catch((w) => {
432
- wn.error("[renderMultilineText] Error loading font:", w);
522
+ ), Un.loadFont(o, d ? 700 : 400).catch((w) => {
523
+ Cn.error("[renderMultilineText] Error loading font:", w);
433
524
  }));
434
525
  const T = sn(r, o, d, u), C = r * l;
435
526
  let _ = 0;
@@ -444,21 +535,21 @@ function oa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1,
444
535
  charIndex: D.charIndex - _
445
536
  // Adjust to line-relative index
446
537
  })) : [];
447
- if (k && (S || F.length > 0 || g) ? F.length > 0 || h(w) ? Ne(e, k, w, x, P, r, F, {
538
+ if (k && (S || F.length > 0 || g) ? F.length > 0 || h(w) ? He(e, k, w, x, P, r, F, {
448
539
  color: e.fillStyle,
449
540
  align: s === "start" || s === "end" ? "left" : s
450
- }) : m && Le(e, k, w, x, P, r, m, {
541
+ }) : m && Ge(e, k, w, x, P, r, m, {
451
542
  color: e.fillStyle,
452
543
  align: s === "start" || s === "end" ? "left" : s
453
544
  }) : e.fillText(w, x, P), _ += A + 1, p) {
454
- const D = Nn(w, r, o, d, u);
545
+ const D = Gn(w, r, o, d, u);
455
546
  let I = x;
456
547
  s === "center" ? I = x - D / 2 : s === "right" && (I = x - D);
457
548
  const M = P + r * 0.1;
458
549
  e.beginPath(), e.moveTo(I, M), e.lineTo(I + D, M), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
459
550
  }
460
551
  if (f) {
461
- const D = Nn(w, r, o, d, u);
552
+ const D = Gn(w, r, o, d, u);
462
553
  let I = x;
463
554
  s === "center" ? I = x - D / 2 : s === "right" && (I = x - D);
464
555
  const M = P - r * 0.25;
@@ -466,18 +557,18 @@ function oa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1,
466
557
  }
467
558
  });
468
559
  }
469
- function Un(e, n) {
470
- Ge(e, n);
560
+ function Hn(e, n) {
561
+ Xe(e, n);
471
562
  }
472
- function Ge(e, n) {
563
+ function Xe(e, n) {
473
564
  var r;
474
- (r = n.stroke) != null && r.enabled && se(e, n), e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
565
+ (r = n.stroke) != null && r.enabled && de(e, n), e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
475
566
  const t = n.transformData, a = ((t == null ? void 0 : t.width) ?? 100) - Y * 2;
476
567
  if (n.richText) {
477
- const o = we.fromJSON(n.richText);
568
+ const o = Te.fromJSON(n.richText);
478
569
  e.save(), e.translate(0, 0);
479
570
  const s = n._lockedLineCount;
480
- Ue(
571
+ Ve(
481
572
  e,
482
573
  o,
483
574
  {
@@ -495,7 +586,7 @@ function Ge(e, n) {
495
586
  ), e.restore();
496
587
  } else if (n.text) {
497
588
  e.fillStyle = n.color;
498
- const o = n._lockedLineCount, { lines: s, height: c } = ae(
589
+ const o = n._lockedLineCount, { lines: s, height: c } = ce(
499
590
  n.text,
500
591
  a,
501
592
  n.fontSize,
@@ -510,7 +601,7 @@ function Ge(e, n) {
510
601
  n.fontFamily,
511
602
  n.bold,
512
603
  n.italic
513
- ), l = -((t == null ? void 0 : t.width) ?? 100) / 2, d = -c / 2, u = n.fontSize * Fn;
604
+ ), l = -((t == null ? void 0 : t.width) ?? 100) / 2, d = -c / 2, u = n.fontSize * On;
514
605
  e.font = `${n.italic ? "italic " : ""}${n.bold ? "bold " : ""}${n.fontSize}px ${n.fontFamily}`, e.textBaseline = "alphabetic", e.textAlign = n.textAlign, s.forEach((p, f) => {
515
606
  const m = f === 0, b = f === s.length - 1;
516
607
  let h = p;
@@ -541,17 +632,17 @@ function Ge(e, n) {
541
632
  }
542
633
  e.restore();
543
634
  }
544
- function ca(e, n) {
635
+ function ua(e, n) {
545
636
  var s;
546
637
  const t = n.opacity ?? 1, a = !!((s = n.stroke) != null && s.enabled), r = n.type === "custom";
547
638
  if (t < 1 && a && r) {
548
- He(e, n, t);
639
+ Ye(e, n, t);
549
640
  return;
550
641
  }
551
642
  const o = e.globalAlpha;
552
- t !== 1 && (e.globalAlpha = t), Sn(e, n), e.globalAlpha = o;
643
+ t !== 1 && (e.globalAlpha = t), kn(e, n), e.globalAlpha = o;
553
644
  }
554
- function He(e, n, t) {
645
+ function Ye(e, n, t) {
555
646
  var h;
556
647
  const a = n.transformData, r = n.fontSize || 24, o = ((h = n.stroke) == null ? void 0 : h.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);
557
648
  let p;
@@ -559,7 +650,7 @@ function He(e, n, t) {
559
650
  const f = p.getContext("2d");
560
651
  if (!f) {
561
652
  const S = e.globalAlpha;
562
- e.globalAlpha = t, Sn(e, n), e.globalAlpha = S;
653
+ e.globalAlpha = t, kn(e, n), e.globalAlpha = S;
563
654
  return;
564
655
  }
565
656
  const m = i.a * n.x + i.e, b = i.d * n.y + i.f;
@@ -570,36 +661,36 @@ function He(e, n, t) {
570
661
  i.d,
571
662
  i.e - m + d / 2,
572
663
  i.f - b + u / 2
573
- ), Sn(f, n), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = t, e.drawImage(p, m - d / 2, b - u / 2), e.restore();
664
+ ), kn(f, n), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = t, e.drawImage(p, m - d / 2, b - u / 2), e.restore();
574
665
  }
575
- function Sn(e, n) {
666
+ function kn(e, n) {
576
667
  switch (n.type) {
577
668
  case "custom":
578
- Un(e, n);
669
+ Hn(e, n);
579
670
  break;
580
671
  case "circle":
581
- je(e, n);
672
+ Je(e, n);
582
673
  break;
583
674
  case "wave":
584
- Xe(e, n);
675
+ Qe(e, n);
585
676
  break;
586
677
  case "arch":
587
- Ke(e, n);
678
+ et(e, n);
588
679
  break;
589
680
  case "ascend":
590
- Ze(e, n);
681
+ at(e, n);
591
682
  break;
592
683
  case "lean":
593
- nt(e, n);
684
+ st(e, n);
594
685
  break;
595
686
  case "flag":
596
- tt(e, n);
687
+ ot(e, n);
597
688
  break;
598
689
  default:
599
- wn.warn(`[canvas-renderer] Unsupported transform type: ${n.type}`), Un(e, n);
690
+ Cn.warn(`[canvas-renderer] Unsupported transform type: ${n.type}`), Hn(e, n);
600
691
  }
601
692
  }
602
- function Ve(e, n) {
693
+ function Ke(e, n) {
603
694
  if (typeof OffscreenCanvas < "u")
604
695
  return new OffscreenCanvas(e, n);
605
696
  const t = document.createElement("canvas");
@@ -624,7 +715,7 @@ function Z(e, n, t) {
624
715
  t(e, n);
625
716
  return;
626
717
  }
627
- const _ = Ve(T, C), w = _.getContext("2d");
718
+ const _ = Ke(T, C), w = _.getContext("2d");
628
719
  if (!w) {
629
720
  t(e, n);
630
721
  return;
@@ -652,10 +743,10 @@ function Z(e, n, t) {
652
743
  D
653
744
  ), e.restore();
654
745
  }
655
- function je(e, n) {
656
- Z(e, n, qe);
746
+ function Je(e, n) {
747
+ Z(e, n, Ze);
657
748
  }
658
- function qe(e, n) {
749
+ function Ze(e, n) {
659
750
  const t = n.transformData;
660
751
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.scale(t.scale, t.scale);
661
752
  const a = n.bold ? "bold" : "normal", r = n.italic ? "italic" : "normal";
@@ -676,23 +767,23 @@ function qe(e, n) {
676
767
  }
677
768
  e.restore();
678
769
  }
679
- function Xe(e, n) {
680
- Z(e, n, Ye);
770
+ function Qe(e, n) {
771
+ Z(e, n, nt);
681
772
  }
682
- function Ye(e, n) {
773
+ function nt(e, n) {
683
774
  const t = n.transformData;
684
775
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
685
776
  const a = n.text.split("");
686
777
  let o = -a.reduce((s, c) => s + e.measureText(c).width, 0) / 2;
687
778
  a.forEach((s) => {
688
779
  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);
689
- e.save(), e.translate(i, d), e.transform(1, u * Se, 0, 1, 0, 0), J(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
780
+ e.save(), e.translate(i, d), e.transform(1, u * _e, 0, 1, 0, 0), J(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
690
781
  }), e.restore();
691
782
  }
692
- function Ke(e, n) {
693
- Z(e, n, Je);
783
+ function et(e, n) {
784
+ Z(e, n, tt);
694
785
  }
695
- function Je(e, n) {
786
+ function tt(e, n) {
696
787
  const t = n.transformData;
697
788
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
698
789
  const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.width / 2;
@@ -702,10 +793,10 @@ function Je(e, n) {
702
793
  e.save(), e.translate(l, u), e.transform(1, p * 0.3, 0, 1, 0, 0), J(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
703
794
  }), e.restore();
704
795
  }
705
- function Ze(e, n) {
706
- Z(e, n, Qe);
796
+ function at(e, n) {
797
+ Z(e, n, rt);
707
798
  }
708
- function Qe(e, n) {
799
+ function rt(e, n) {
709
800
  const t = n.transformData;
710
801
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
711
802
  const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.ascendAngle * Math.PI / 180;
@@ -715,20 +806,20 @@ function Qe(e, n) {
715
806
  e.save(), e.translate(l, d), e.transform(1, u * 1, 0, 1, 0, 0), J(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
716
807
  }), e.restore();
717
808
  }
718
- function nt(e, n) {
719
- Z(e, n, et);
809
+ function st(e, n) {
810
+ Z(e, n, it);
720
811
  }
721
- function et(e, n) {
812
+ function it(e, n) {
722
813
  var r;
723
814
  const t = n.transformData;
724
815
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
725
816
  const a = -t.leanAmount * Math.PI / 4;
726
817
  e.transform(1, 0, Math.tan(a), 1, 0, 0), e.font = R(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();
727
818
  }
728
- function tt(e, n) {
729
- Z(e, n, at);
819
+ function ot(e, n) {
820
+ Z(e, n, ct);
730
821
  }
731
- function at(e, n) {
822
+ function ct(e, n) {
732
823
  const t = n.transformData;
733
824
  e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
734
825
  const a = n.text.split("");
@@ -738,118 +829,27 @@ function at(e, n) {
738
829
  e.save(), e.translate(i, p), e.transform(1, b * 0.3, 0, 1, 0, 0), J(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
739
830
  }), e.restore();
740
831
  }
741
- const rt = V("TextureManager"), an = class an {
742
- /**
743
- * Load a texture by ID or URL
744
- */
745
- static async loadTexture(n) {
746
- if (this.cache.has(n))
747
- return this.cache.get(n);
748
- if (this.loading.has(n))
749
- return this.loading.get(n);
750
- const t = this.resolveTextureUrl(n), a = new Promise((r, o) => {
751
- const s = new Image();
752
- s.crossOrigin = "anonymous", s.onload = () => {
753
- this.cache.set(n, s), this.cache.set(t, s), this.loading.delete(n), this.loading.delete(t), r(s);
754
- }, s.onerror = () => {
755
- rt.error("Failed to load texture:", t), this.loading.delete(n), this.loading.delete(t), o(new Error(`Failed to load texture: ${t}`));
756
- }, s.src = t;
757
- });
758
- return this.loading.set(n, a), t !== n && this.loading.set(t, a), a;
759
- }
760
- /**
761
- * Get a texture synchronously (returns null if not loaded)
762
- */
763
- static getTexture(n) {
764
- const t = this.resolveTextureUrl(n);
765
- return this.cache.get(n) || this.cache.get(t) || null;
766
- }
767
- /**
768
- * Preload multiple textures
769
- */
770
- static async preloadTextures(n) {
771
- await Promise.all(n.map((t) => this.loadTexture(t)));
772
- }
773
- /**
774
- * Preload all built-in textures
775
- */
776
- static async preloadAllTextures() {
777
- await this.preloadTextures(this.TEXTURES.map((n) => n.id));
778
- }
779
- /**
780
- * Clear cache
781
- */
782
- static clearCache() {
783
- this.cache.clear(), this.loading.clear();
784
- }
785
- /**
786
- * Resolve texture URL from ID
787
- */
788
- static resolveTextureUrl(n) {
789
- if (n.startsWith("http://") || n.startsWith("https://") || n.startsWith("/") || n.startsWith("data:"))
790
- return n;
791
- const t = this.TEXTURES.find((a) => a.id === n);
792
- return t ? t.url : `/textures/${n}`;
793
- }
794
- /**
795
- * Get texture info by ID
796
- */
797
- static getTextureInfo(n) {
798
- return this.TEXTURES.find((t) => t.id === n);
799
- }
800
- /**
801
- * Get all available textures
802
- */
803
- static getAllTextures() {
804
- return [...this.TEXTURES];
805
- }
806
- /**
807
- * Get textures by category
808
- */
809
- static getTexturesByCategory(n) {
810
- return this.TEXTURES.filter((t) => t.category === n);
811
- }
812
- /**
813
- * Get preset color for a texture
814
- * Each texture has a fixed color that's part of its preset
815
- */
816
- static getTexturePresetColor(n) {
817
- const t = this.TEXTURES.find((a) => a.id === n);
818
- return (t == null ? void 0 : t.presetColor) || "#ffffff";
819
- }
820
- };
821
- an.cache = /* @__PURE__ */ new Map(), an.loading = /* @__PURE__ */ new Map(), an.TEXTURES = [
822
- {
823
- id: "glass-frame",
824
- name: "Glass Frame",
825
- url: "/textures/glass-frame.svg",
826
- category: "glass",
827
- presetColor: "#ccc"
828
- // Light gray
829
- }
830
- ];
831
- let X = an;
832
- function On(e, n, t = {}) {
832
+ function Bn(e, n, t = {}) {
833
833
  const a = t.mode || "both";
834
834
  switch (e.save(), e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), n.transformType) {
835
835
  case "image":
836
- it(e, n, a, t);
836
+ dt(e, n, a, t);
837
837
  break;
838
838
  case "shape":
839
- ot(e, n, a, t);
839
+ ft(e, n, a, t);
840
840
  break;
841
841
  case "group":
842
842
  break;
843
843
  default:
844
- st(e, n, a, t);
844
+ lt(e, n, a, t);
845
845
  break;
846
846
  }
847
847
  e.restore();
848
848
  }
849
- function st(e, n, t, a) {
849
+ function lt(e, n, t, a) {
850
850
  var s;
851
851
  const r = n, o = r.text || "";
852
- o && ((t === "stroke" || t === "both") && ((s = n.stroke) != null && s.enabled) && (e.save(), se(e, n, { ...a.renderingContext, positionApplied: !0 }), e.restore()), (t === "fill" || t === "both") && (e.save(), ze(e, {
852
+ o && ((t === "stroke" || t === "both") && ((s = n.stroke) != null && s.enabled) && (e.save(), de(e, n, { ...a.renderingContext, positionApplied: !0 }), e.restore()), (t === "fill" || t === "both") && (e.save(), je(e, {
853
853
  text: o,
854
854
  fontSize: r.fontSize || 24,
855
855
  fontFamily: r.fontFamily || "Arial",
@@ -859,12 +859,12 @@ function st(e, n, t, a) {
859
859
  color: r.color || "#000000"
860
860
  }), e.restore()));
861
861
  }
862
- function it(e, n, t, a) {
862
+ function dt(e, n, t, a) {
863
863
  var o;
864
864
  if (!n.transformData) return;
865
865
  const r = n.transformData;
866
866
  if (t === "fill" || t === "both")
867
- if (ut(e, n), a.loadedImage) {
867
+ if (gt(e, n), a.loadedImage) {
868
868
  e.save(), e.clip();
869
869
  const s = r.flipHorizontal ? -1 : 1, c = r.flipVertical ? -1 : 1;
870
870
  e.scale(s, c);
@@ -872,34 +872,34 @@ function it(e, n, t, a) {
872
872
  e.drawImage(a.loadedImage, -i / 2, -l / 2, i, l), e.restore();
873
873
  } else
874
874
  e.fillStyle = "#cccccc", e.fill();
875
- (t === "stroke" || t === "both") && ((o = n.stroke) != null && o.enabled) && (e.save(), Be(e, n, a.renderingContext), e.restore());
875
+ (t === "stroke" || t === "both") && ((o = n.stroke) != null && o.enabled) && (e.save(), We(e, n, a.renderingContext), e.restore());
876
876
  }
877
- function ot(e, n, t, a) {
877
+ function ft(e, n, t, a) {
878
878
  var s, c;
879
879
  if (!n.transformData) return;
880
880
  const r = n.transformData, o = ((s = a.renderingContext) == null ? void 0 : s.isKnockout) === !0;
881
- e.beginPath(), ie(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());
881
+ 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(), bt(e, n, a.renderingContext), e.restore());
882
882
  }
883
- function ie(e, n) {
883
+ function fe(e, n) {
884
884
  const { shapeType: t } = n, a = n.width ?? 100, r = n.height ?? 100;
885
885
  switch (t) {
886
886
  case "rectangle":
887
- zn(e, n, a, r);
887
+ Vn(e, n, a, r);
888
888
  break;
889
889
  case "circle":
890
- ct(e, Math.min(a, r) / 2);
890
+ ut(e, Math.min(a, r) / 2);
891
891
  break;
892
892
  case "ellipse":
893
- lt(e, a / 2, r / 2);
893
+ pt(e, a / 2, r / 2);
894
894
  break;
895
895
  case "star":
896
- dt(e, n, Math.min(a, r) / 2);
896
+ ht(e, n, Math.min(a, r) / 2);
897
897
  break;
898
898
  default:
899
- zn(e, n, a, r);
899
+ Vn(e, n, a, r);
900
900
  }
901
901
  }
902
- function zn(e, n, t, a) {
902
+ function Vn(e, n, t, a) {
903
903
  const r = n.borderRadius || 0, o = -t / 2, s = -a / 2;
904
904
  if (r > 0) {
905
905
  const c = Math.min(r / 100 * Math.min(t, a), t / 2, a / 2);
@@ -907,13 +907,13 @@ function zn(e, n, t, a) {
907
907
  } else
908
908
  e.rect(o, s, t, a);
909
909
  }
910
- function ct(e, n) {
910
+ function ut(e, n) {
911
911
  e.arc(0, 0, n, 0, Math.PI * 2);
912
912
  }
913
- function lt(e, n, t) {
913
+ function pt(e, n, t) {
914
914
  e.ellipse(0, 0, n, t, 0, 0, Math.PI * 2);
915
915
  }
916
- function dt(e, n, t) {
916
+ function ht(e, n, t) {
917
917
  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;
918
918
  for (let i = 0; i < a * 2; i++) {
919
919
  const l = c + s * i, d = i % 2 === 0 ? t : o, u = Math.cos(l) * d, p = Math.sin(l) * d;
@@ -921,13 +921,13 @@ function dt(e, n, t) {
921
921
  }
922
922
  e.closePath();
923
923
  }
924
- function ft(e, n, t) {
924
+ function bt(e, n, t) {
925
925
  var r;
926
926
  if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
927
927
  const a = (t == null ? void 0 : t.isKnockout) === !0;
928
- 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(), ie(e, n.transformData), e.stroke(), e.restore();
928
+ 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();
929
929
  }
930
- function ut(e, n) {
930
+ function gt(e, n) {
931
931
  if (!n.transformData) return;
932
932
  const { borderRadius: t } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100, o = -a / 2, s = -r / 2;
933
933
  if (e.beginPath(), t && t > 0) {
@@ -936,7 +936,7 @@ function ut(e, n) {
936
936
  } else
937
937
  e.rect(o, s, a, r);
938
938
  }
939
- function Cn(e, n, t, a, r, o, s = "destination-out") {
939
+ function Tn(e, n, t, a, r, o, s = "destination-out") {
940
940
  var v;
941
941
  if (!n.knockoutParts) return;
942
942
  if (!(n.knockoutParts.fill || n.knockoutParts.stroke)) {
@@ -945,21 +945,21 @@ function Cn(e, n, t, a, r, o, s = "destination-out") {
945
945
  }
946
946
  const i = e.getTransform();
947
947
  e.save();
948
- const l = n.knockoutParts.scope || "group", d = pt(n, l, t);
948
+ const l = n.knockoutParts.scope || "group", d = mt(n, l, t);
949
949
  if (d.length === 0 && l === "artboard") {
950
- bt(e, n, a), e.restore();
950
+ $t(e, n, a), e.restore();
951
951
  return;
952
952
  }
953
953
  if (d.length === 0) {
954
954
  a(e, n), e.restore();
955
955
  return;
956
956
  }
957
- const u = e.canvas, f = e.getTransform().a, m = gt(u.width, u.height), b = m.getContext("2d");
957
+ const u = e.canvas, f = e.getTransform().a, m = xt(u.width, u.height), b = m.getContext("2d");
958
958
  if (!b) return;
959
959
  b.scale(f, f), r && o && (b.fillStyle = r, b.fillRect(o.x, o.y, o.width, o.height));
960
960
  for (const g of d)
961
961
  a(b, g);
962
- n.knockoutParts.fill && !n.knockoutParts.stroke && ((v = n.stroke) != null && v.enabled) && (b.save(), Tn(b, n), b.restore()), b.save(), b.globalCompositeOperation = s, n.knockoutParts.fill && kn(b, n), n.knockoutParts.stroke && Tn(b, n), b.restore(), n.knockoutParts.fill || (b.save(), kn(b, n), b.restore());
962
+ n.knockoutParts.fill && !n.knockoutParts.stroke && ((v = n.stroke) != null && v.enabled) && (b.save(), En(b, n), b.restore()), b.save(), b.globalCompositeOperation = s, n.knockoutParts.fill && _n(b, n), n.knockoutParts.stroke && En(b, n), b.restore(), n.knockoutParts.fill || (b.save(), _n(b, n), b.restore());
963
963
  const h = u.width / f, S = u.height / f;
964
964
  e.drawImage(m, 0, 0, h, S), e.restore();
965
965
  const $ = e.getTransform();
@@ -972,59 +972,59 @@ function Cn(e, n, t, a, r, o, s = "destination-out") {
972
972
  i.f
973
973
  );
974
974
  }
975
- function la(e, n, t, a, r, o) {
976
- Cn(e, n, t, a, r, o, "destination-out");
975
+ function pa(e, n, t, a, r, o) {
976
+ Tn(e, n, t, a, r, o, "destination-out");
977
977
  }
978
- function pt(e, n, t) {
979
- return n === "artboard" ? oe(e, t) : ht(e, t);
978
+ function mt(e, n, t) {
979
+ return n === "artboard" ? ue(e, t) : yt(e, t);
980
980
  }
981
- function oe(e, n) {
981
+ function ue(e, n) {
982
982
  const t = n.findIndex((a) => a.id === e.id);
983
983
  return t === -1 ? [] : n.slice(0, t);
984
984
  }
985
- function ht(e, n) {
986
- const t = ce(e, n);
985
+ function yt(e, n) {
986
+ const t = pe(e, n);
987
987
  if (!t)
988
- return oe(e, n);
988
+ return ue(e, n);
989
989
  if (t.transformType !== "group" || !t.children)
990
990
  return [];
991
991
  const a = t.children.findIndex((r) => r.id === e.id);
992
992
  return a === -1 ? [] : t.children.slice(0, a);
993
993
  }
994
- function ce(e, n) {
994
+ function pe(e, n) {
995
995
  for (const t of n)
996
996
  if (t.transformType === "group" && t.children) {
997
997
  if (t.children.some((r) => r.id === e.id))
998
998
  return t;
999
- const a = ce(e, t.children);
999
+ const a = pe(e, t.children);
1000
1000
  if (a)
1001
1001
  return a;
1002
1002
  }
1003
1003
  return null;
1004
1004
  }
1005
- function kn(e, n, t) {
1006
- On(e, n, {
1005
+ function _n(e, n, t) {
1006
+ Bn(e, n, {
1007
1007
  mode: "fill",
1008
1008
  renderingContext: { isKnockout: !0 }
1009
1009
  });
1010
1010
  }
1011
- function Tn(e, n) {
1011
+ function En(e, n) {
1012
1012
  var t;
1013
- (t = n.stroke) != null && t.enabled && On(e, n, {
1013
+ (t = n.stroke) != null && t.enabled && Bn(e, n, {
1014
1014
  mode: "stroke",
1015
1015
  renderingContext: { isKnockout: !0 }
1016
1016
  });
1017
1017
  }
1018
- function bt(e, n, t) {
1018
+ function $t(e, n, t) {
1019
1019
  var r;
1020
1020
  const a = n.knockoutParts;
1021
1021
  if (!a) {
1022
1022
  t(e, n);
1023
1023
  return;
1024
1024
  }
1025
- a.fill || (e.save(), kn(e, n), e.restore()), !a.stroke && ((r = n.stroke) != null && r.enabled) && (e.save(), Tn(e, n), e.restore());
1025
+ a.fill || (e.save(), _n(e, n), e.restore()), !a.stroke && ((r = n.stroke) != null && r.enabled) && (e.save(), En(e, n), e.restore());
1026
1026
  }
1027
- function gt(e, n) {
1027
+ function xt(e, n) {
1028
1028
  if (typeof OffscreenCanvas < "u")
1029
1029
  return new OffscreenCanvas(e, n);
1030
1030
  if (typeof document < "u") {
@@ -1033,7 +1033,7 @@ function gt(e, n) {
1033
1033
  }
1034
1034
  throw new Error("No canvas context available");
1035
1035
  }
1036
- function Wn(e, n, t, a, r = 0) {
1036
+ function jn(e, n, t, a, r = 0) {
1037
1037
  if (t <= 0 || a <= 0 || e <= 0 || n <= 0)
1038
1038
  return { width: e + r, height: n + r };
1039
1039
  const o = t / a, s = e / n;
@@ -1043,11 +1043,11 @@ function Wn(e, n, t, a, r = 0) {
1043
1043
  height: i + r
1044
1044
  };
1045
1045
  }
1046
- const nn = 64, $n = 512;
1047
- function mt(e, n) {
1046
+ const nn = 64, vn = 512;
1047
+ function vt(e, n) {
1048
1048
  e.beginPath(), e.arc(n / 2, n / 2, n * 0.45, 0, Math.PI * 2), e.fill();
1049
1049
  }
1050
- function yt(e, n) {
1050
+ function wt(e, n) {
1051
1051
  const t = n / 2, a = n / 2, r = n * 0.45, o = r * 0.4, s = 5;
1052
1052
  e.beginPath();
1053
1053
  for (let c = 0; c < s * 2; c++) {
@@ -1056,15 +1056,15 @@ function yt(e, n) {
1056
1056
  }
1057
1057
  e.closePath(), e.fill();
1058
1058
  }
1059
- function $t(e, n) {
1059
+ function St(e, n) {
1060
1060
  const t = n / 2, a = n * 0.42;
1061
1061
  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();
1062
1062
  }
1063
- function xt(e, n) {
1063
+ function Ct(e, n) {
1064
1064
  const t = n / 2, a = n / 2, r = n * 0.4, o = n * 0.48;
1065
1065
  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();
1066
1066
  }
1067
- function vt(e, n) {
1067
+ function kt(e, n) {
1068
1068
  const t = n / 2, a = n / 2, r = n * 0.44;
1069
1069
  e.beginPath();
1070
1070
  for (let o = 0; o < 6; o++) {
@@ -1073,11 +1073,11 @@ function vt(e, n) {
1073
1073
  }
1074
1074
  e.closePath(), e.fill();
1075
1075
  }
1076
- function wt(e, n) {
1076
+ function Tt(e, n) {
1077
1077
  const t = n / 2, a = n * 0.4, r = n * 0.12;
1078
1078
  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();
1079
1079
  }
1080
- function St(e, n) {
1080
+ function _t(e, n) {
1081
1081
  const t = n / 2, a = n / 2;
1082
1082
  let r = 42;
1083
1083
  const o = () => (r = (r * 16807 + 0) % 2147483647, r / 2147483647);
@@ -1087,7 +1087,7 @@ function St(e, n) {
1087
1087
  e.beginPath(), e.arc(t + Math.cos(c) * i, a + Math.sin(c) * i, l, 0, Math.PI * 2), e.fill();
1088
1088
  }
1089
1089
  }
1090
- function Ct(e, n) {
1090
+ function Et(e, n) {
1091
1091
  let t = 123;
1092
1092
  const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.08, o = 40;
1093
1093
  e.beginPath(), e.moveTo(r, r);
@@ -1109,7 +1109,7 @@ function Ct(e, n) {
1109
1109
  }
1110
1110
  e.closePath(), e.fill();
1111
1111
  }
1112
- function kt(e, n) {
1112
+ function At(e, n) {
1113
1113
  let t = 77;
1114
1114
  const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.25, o = n * 0.75, s = n * 0.1;
1115
1115
  e.beginPath(), e.moveTo(s, r + a() * n * 0.05);
@@ -1123,101 +1123,101 @@ function kt(e, n) {
1123
1123
  }
1124
1124
  e.closePath(), e.fill();
1125
1125
  }
1126
- function Tt(e, n) {
1126
+ function Pt(e, n) {
1127
1127
  const t = n / 2, a = n * 0.55;
1128
1128
  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();
1129
1129
  }
1130
- const _t = [
1130
+ const It = [
1131
1131
  // Geometric
1132
- { id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw: mt },
1133
- { id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw: yt },
1134
- { id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: $t },
1135
- { id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw: xt },
1136
- { id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw: vt },
1137
- { id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw: wt },
1132
+ { id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw: vt },
1133
+ { id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw: wt },
1134
+ { id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: St },
1135
+ { id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw: Ct },
1136
+ { id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw: kt },
1137
+ { id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw: Tt },
1138
1138
  // Organic
1139
- { id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw: St },
1140
- { id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw: Ct },
1141
- { id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw: kt },
1142
- { id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw: Tt }
1139
+ { id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw: _t },
1140
+ { id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw: Et },
1141
+ { id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw: At },
1142
+ { id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw: Pt }
1143
1143
  ];
1144
- let Gn = !1;
1145
- function Hn(e, n) {
1144
+ let qn = !1;
1145
+ function Xn(e, n) {
1146
1146
  if (typeof document > "u") return null;
1147
1147
  const t = document.createElement("canvas");
1148
1148
  return t.width = e, t.height = n, t;
1149
1149
  }
1150
- function Et() {
1151
- if (typeof document > "u" || Gn) return;
1152
- Gn = !0;
1153
- const e = bn.getInstance();
1154
- for (const n of _t) {
1155
- const t = Hn($n, $n);
1150
+ function Dt() {
1151
+ if (typeof document > "u" || qn) return;
1152
+ qn = !0;
1153
+ const e = mn.getInstance();
1154
+ for (const n of It) {
1155
+ const t = Xn(vn, vn);
1156
1156
  if (!t) continue;
1157
1157
  const a = t.getContext("2d");
1158
1158
  if (!a) continue;
1159
- a.fillStyle = "white", n.draw(a, $n);
1159
+ a.fillStyle = "white", n.draw(a, vn);
1160
1160
  const r = t.toDataURL("image/png"), o = e.acquire(n.imageUrl);
1161
1161
  o.crossOrigin = "anonymous", o.src = r;
1162
- const s = Hn(nn, nn);
1162
+ const s = Xn(nn, nn);
1163
1163
  if (s) {
1164
1164
  const c = s.getContext("2d");
1165
1165
  c && (c.fillStyle = "#1a1a2e", c.fillRect(0, 0, nn, nn), c.fillStyle = "white", n.draw(c, nn), n.thumbnailUrl = s.toDataURL("image/png"));
1166
1166
  }
1167
1167
  }
1168
1168
  }
1169
- const At = V("MaskRenderer"), _n = /* @__PURE__ */ new Map(), Pt = /* @__PURE__ */ new Map();
1170
- function da(e) {
1169
+ const Ft = G("MaskRenderer"), An = /* @__PURE__ */ new Map(), Mt = /* @__PURE__ */ new Map();
1170
+ function ha(e) {
1171
1171
  const n = [];
1172
- _n.forEach((t, a) => {
1172
+ An.forEach((t, a) => {
1173
1173
  a.startsWith(e) && n.push(a);
1174
- }), n.forEach((t) => _n.delete(t));
1174
+ }), n.forEach((t) => An.delete(t));
1175
1175
  }
1176
- function fa() {
1177
- _n.clear();
1176
+ function ba() {
1177
+ An.clear();
1178
1178
  }
1179
- function Vn(e, n, t) {
1179
+ function Yn(e, n, t) {
1180
1180
  if (!n.masks || n.masks.length === 0) {
1181
1181
  t(e);
1182
1182
  return;
1183
1183
  }
1184
1184
  const a = e.canvas, r = fn(a.width, a.height), o = r.getContext("2d");
1185
1185
  if (!o) {
1186
- At.error("[renderWithMasks] Failed to get offscreen context");
1186
+ Ft.error("[renderWithMasks] Failed to get offscreen context");
1187
1187
  return;
1188
1188
  }
1189
1189
  const s = e.getTransform();
1190
1190
  o.setTransform(s), t(o);
1191
1191
  for (const c of n.masks)
1192
- It(o, c, n);
1192
+ Ot(o, c, n);
1193
1193
  e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(r, 0, 0), e.restore();
1194
1194
  }
1195
- function It(e, n, t) {
1195
+ function Ot(e, n, t) {
1196
1196
  switch (n.type) {
1197
1197
  case "clip":
1198
- Dt(e, n, t);
1198
+ Rt(e, n, t);
1199
1199
  break;
1200
1200
  case "alpha":
1201
- Ft(e, n, t);
1201
+ Bt(e, n, t);
1202
1202
  break;
1203
1203
  case "luma":
1204
- Mt(e, n, t);
1204
+ Lt(e, n, t);
1205
1205
  break;
1206
1206
  case "distress":
1207
- Ot(e, n, t);
1207
+ Nt(e, n, t);
1208
1208
  break;
1209
1209
  }
1210
1210
  }
1211
- function Dt(e, n, t) {
1212
- e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), gn(e, n.maskElement, t), e.restore();
1211
+ function Rt(e, n, t) {
1212
+ e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), yn(e, n.maskElement, t), e.restore();
1213
1213
  }
1214
- function Ft(e, n, t) {
1215
- e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), gn(e, n.maskElement, t), n.feather && n.feather > 0 && le(e, n.feather), e.restore();
1214
+ function Bt(e, n, t) {
1215
+ e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), yn(e, n.maskElement, t), n.feather && n.feather > 0 && he(e, n.feather), e.restore();
1216
1216
  }
1217
- function Mt(e, n, t) {
1217
+ function Lt(e, n, t) {
1218
1218
  const a = fn(e.canvas.width, e.canvas.height), r = a.getContext("2d");
1219
1219
  if (!r) return;
1220
- gn(r, n.maskElement, t);
1220
+ yn(r, n.maskElement, t);
1221
1221
  const o = r.getImageData(0, 0, a.width, a.height), s = o.data;
1222
1222
  for (let c = 0; c < s.length; c += 4) {
1223
1223
  const i = s[c], l = s[c + 1], d = s[c + 2], u = 0.299 * i + 0.587 * l + 0.114 * d;
@@ -1225,10 +1225,10 @@ function Mt(e, n, t) {
1225
1225
  }
1226
1226
  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();
1227
1227
  }
1228
- function Ot(e, n, t) {
1229
- e.save(), e.globalCompositeOperation = n.inverted ? "destination-in" : "destination-out", n.opacity !== void 0 && (e.globalAlpha = n.opacity), gn(e, n.maskElement, t), n.feather && n.feather > 0 && le(e, n.feather), e.restore();
1228
+ function Nt(e, n, t) {
1229
+ e.save(), e.globalCompositeOperation = n.inverted ? "destination-in" : "destination-out", n.opacity !== void 0 && (e.globalAlpha = n.opacity), yn(e, n.maskElement, t), n.feather && n.feather > 0 && he(e, n.feather), e.restore();
1230
1230
  }
1231
- function gn(e, n, t) {
1231
+ function yn(e, n, t) {
1232
1232
  const a = t.x || 0, r = t.y || 0, o = n.x || 0, s = n.y || 0, c = {
1233
1233
  ...n,
1234
1234
  x: a + o,
@@ -1246,18 +1246,18 @@ function gn(e, n, t) {
1246
1246
  const g = n;
1247
1247
  if (g.imageUrl)
1248
1248
  if (typeof document < "u") {
1249
- g.imageUrl.startsWith("builtin-mask:") && Et();
1250
- const y = bn.getInstance(), k = y.acquire(g.imageUrl);
1249
+ g.imageUrl.startsWith("builtin-mask:") && Dt();
1250
+ const y = mn.getInstance(), k = y.acquire(g.imageUrl);
1251
1251
  k.complete && k.naturalWidth > 0 && (m = k), y.release(g.imageUrl);
1252
1252
  } else
1253
- b = Pt.get(g.imageUrl);
1253
+ b = Mt.get(g.imageUrl);
1254
1254
  }
1255
1255
  const h = c.transformData, S = (f == null ? void 0 : f.width) || 0, $ = (f == null ? void 0 : f.height) || 0, v = S > 0 && $ > 0 && u > 0 && p > 0 && Math.abs(S / $ - u / p) > 1e-3;
1256
1256
  if (b) {
1257
1257
  e.save();
1258
1258
  const g = (h == null ? void 0 : h.width) || b.width, y = (h == null ? void 0 : h.height) || b.height;
1259
1259
  if (e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), v) {
1260
- const k = Wn(
1260
+ const k = jn(
1261
1261
  g,
1262
1262
  y,
1263
1263
  S,
@@ -1269,7 +1269,7 @@ function gn(e, n, t) {
1269
1269
  e.drawImage(b, -g / 2, -y / 2, g, y);
1270
1270
  e.restore();
1271
1271
  } else if (v && m) {
1272
- const g = (h == null ? void 0 : h.width) || u, y = (h == null ? void 0 : h.height) || p, k = Wn(
1272
+ const g = (h == null ? void 0 : h.width) || u, y = (h == null ? void 0 : h.height) || p, k = jn(
1273
1273
  g,
1274
1274
  y,
1275
1275
  S,
@@ -1278,9 +1278,9 @@ function gn(e, n, t) {
1278
1278
  );
1279
1279
  e.save(), e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), e.drawImage(m, -k.width / 2, -k.height / 2, k.width, k.height), e.restore();
1280
1280
  } else
1281
- On(e, c, { mode: "both", loadedImage: m });
1281
+ Bn(e, c, { mode: "both", loadedImage: m });
1282
1282
  }
1283
- function le(e, n) {
1283
+ function he(e, n) {
1284
1284
  "filter" in e && (e.filter = `blur(${n}px)`);
1285
1285
  }
1286
1286
  function fn(e, n) {
@@ -1292,9 +1292,9 @@ function fn(e, n) {
1292
1292
  }
1293
1293
  throw new Error("No canvas context available");
1294
1294
  }
1295
- function Rt(e, n, t, a) {
1295
+ function Ut(e, n, t, a) {
1296
1296
  if (!n.enabled || !n.imageUrl || n.opacity <= 0) return;
1297
- const r = bn.getInstance(), o = r.acquire(n.imageUrl);
1297
+ const r = mn.getInstance(), o = r.acquire(n.imageUrl);
1298
1298
  if (!o.complete || o.naturalWidth === 0) {
1299
1299
  r.release(n.imageUrl);
1300
1300
  return;
@@ -1336,7 +1336,7 @@ function Rt(e, n, t, a) {
1336
1336
  $.globalCompositeOperation = v, $.globalAlpha = n.opacity / 100, $.drawImage(o, 0, 0, b, h);
1337
1337
  $.globalCompositeOperation = "source-over", $.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(u, p, f, m), a && (e.fillStyle = a, e.fillRect(u, p, f, m)), e.drawImage(S, u, p), e.restore(), r.release(n.imageUrl);
1338
1338
  }
1339
- class Bt {
1339
+ class zt {
1340
1340
  constructor(n = Math.random()) {
1341
1341
  this.perm = [];
1342
1342
  for (let a = 0; a < 256; a++)
@@ -1374,8 +1374,8 @@ class Bt {
1374
1374
  );
1375
1375
  }
1376
1376
  }
1377
- function xn(e, n, t, a = Date.now()) {
1378
- const s = mn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = new Bt(a), l = 0.02, d = 1 - t / 100;
1377
+ function wn(e, n, t, a = Date.now()) {
1378
+ const s = $n(e, n).getContext("2d").createImageData(e, n), c = s.data, i = new zt(a), l = 0.02, d = 1 - t / 100;
1379
1379
  for (let u = 0; u < n; u++)
1380
1380
  for (let p = 0; p < e; p++) {
1381
1381
  const f = (u * e + p) * 4;
@@ -1388,30 +1388,30 @@ function xn(e, n, t, a = Date.now()) {
1388
1388
  }
1389
1389
  return s;
1390
1390
  }
1391
- function Lt(e, n, t, a = Date.now()) {
1392
- const o = mn(e, n).getContext("2d");
1391
+ function Wt(e, n, t, a = Date.now()) {
1392
+ const o = $n(e, n).getContext("2d");
1393
1393
  o.clearRect(0, 0, e, n), o.strokeStyle = "#000000", o.lineWidth = 1 + t / 50, o.lineCap = "round";
1394
- const s = Rn(a), c = Math.floor(t / 100 * 30 + 5);
1394
+ const s = Ln(a), c = Math.floor(t / 100 * 30 + 5);
1395
1395
  for (let i = 0; i < c; i++) {
1396
1396
  const l = s() * e, d = s() * n;
1397
- En(o, l, d, s() * Math.PI * 2, 50 + s() * 100, s, 0);
1397
+ Pn(o, l, d, s() * Math.PI * 2, 50 + s() * 100, s, 0);
1398
1398
  }
1399
1399
  return o.getImageData(0, 0, e, n);
1400
1400
  }
1401
- function En(e, n, t, a, r, o, s) {
1401
+ function Pn(e, n, t, a, r, o, s) {
1402
1402
  if (s > 3 || r < 10) return;
1403
1403
  const c = n + Math.cos(a) * r, i = t + Math.sin(a) * r;
1404
1404
  if (e.beginPath(), e.moveTo(n, t), e.lineTo(c, i), e.stroke(), o() > 0.5) {
1405
1405
  const l = a + (o() - 0.5) * Math.PI / 2;
1406
- En(e, c, i, l, r * 0.6, o, s + 1);
1406
+ Pn(e, c, i, l, r * 0.6, o, s + 1);
1407
1407
  }
1408
1408
  if (o() > 0.7) {
1409
1409
  const l = a - (o() - 0.5) * Math.PI / 2;
1410
- En(e, c, i, l, r * 0.6, o, s + 1);
1410
+ Pn(e, c, i, l, r * 0.6, o, s + 1);
1411
1411
  }
1412
1412
  }
1413
1413
  function dn(e, n, t, a = Date.now()) {
1414
- const s = mn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = Rn(a), l = t / 100 * 0.5;
1414
+ const s = $n(e, n).getContext("2d").createImageData(e, n), c = s.data, i = Ln(a), l = t / 100 * 0.5;
1415
1415
  for (let d = 0; d < n; d++)
1416
1416
  for (let u = 0; u < e; u++) {
1417
1417
  const p = (d * e + u) * 4, m = i() < l ? 255 : 0;
@@ -1419,10 +1419,10 @@ function dn(e, n, t, a = Date.now()) {
1419
1419
  }
1420
1420
  return s;
1421
1421
  }
1422
- function Nt(e, n, t, a = Date.now()) {
1423
- const o = mn(e, n).getContext("2d");
1422
+ function Gt(e, n, t, a = Date.now()) {
1423
+ const o = $n(e, n).getContext("2d");
1424
1424
  o.fillStyle = "#000000";
1425
- const s = Rn(a), c = 4 + t / 100 * 6, i = c * 2;
1425
+ const s = Ln(a), c = 4 + t / 100 * 6, i = c * 2;
1426
1426
  for (let l = 0; l < n; l += i)
1427
1427
  for (let d = 0; d < e; d += i)
1428
1428
  if (s() < t / 100) {
@@ -1431,7 +1431,7 @@ function Nt(e, n, t, a = Date.now()) {
1431
1431
  }
1432
1432
  return o.getImageData(0, 0, e, n);
1433
1433
  }
1434
- function mn(e, n) {
1434
+ function $n(e, n) {
1435
1435
  if (typeof OffscreenCanvas < "u")
1436
1436
  return new OffscreenCanvas(e, n);
1437
1437
  if (typeof document < "u") {
@@ -1440,24 +1440,24 @@ function mn(e, n) {
1440
1440
  }
1441
1441
  throw new Error("No canvas context available");
1442
1442
  }
1443
- function Rn(e) {
1443
+ function Ln(e) {
1444
1444
  let n = Math.sin(e++) * 1e4;
1445
1445
  return () => (n = Math.sin(e++) * 1e4, n - Math.floor(n));
1446
1446
  }
1447
1447
  const L = 42, j = 512, q = 64;
1448
- function An(e) {
1448
+ function In(e) {
1449
1449
  const n = e.data;
1450
1450
  for (let t = 0; t < n.length; t += 4)
1451
1451
  n[t] = 255, n[t + 1] = 255, n[t + 2] = 255;
1452
1452
  return e;
1453
1453
  }
1454
- function Ut(e, n) {
1454
+ function Ht(e, n) {
1455
1455
  const t = e.data, a = n.data;
1456
1456
  for (let r = 0; r < t.length; r += 4)
1457
1457
  t[r] = 255, t[r + 1] = 255, t[r + 2] = 255, t[r + 3] = Math.min(255, t[r + 3] + a[r + 3]);
1458
1458
  return e;
1459
1459
  }
1460
- const zt = [
1460
+ const Vt = [
1461
1461
  {
1462
1462
  id: "grunge-heavy",
1463
1463
  name: "Heavy Grunge",
@@ -1480,7 +1480,7 @@ const zt = [
1480
1480
  textureUrl: "builtin:concrete",
1481
1481
  thumbnailUrl: "",
1482
1482
  description: "Rough surface via Perlin noise",
1483
- generate: (e, n) => xn(e, n, 55, L + 2)
1483
+ generate: (e, n) => wn(e, n, 55, L + 2)
1484
1484
  },
1485
1485
  {
1486
1486
  id: "paper",
@@ -1488,7 +1488,7 @@ const zt = [
1488
1488
  textureUrl: "builtin:paper",
1489
1489
  thumbnailUrl: "",
1490
1490
  description: "Subtle aging",
1491
- generate: (e, n) => xn(e, n, 20, L + 3)
1491
+ generate: (e, n) => wn(e, n, 20, L + 3)
1492
1492
  },
1493
1493
  {
1494
1494
  id: "rust",
@@ -1497,8 +1497,8 @@ const zt = [
1497
1497
  thumbnailUrl: "",
1498
1498
  description: "Noise + splatter combined",
1499
1499
  generate: (e, n) => {
1500
- const t = xn(e, n, 45, L + 4), a = dn(e, n, 35, L + 5);
1501
- return Ut(An(t), An(a));
1500
+ const t = wn(e, n, 45, L + 4), a = dn(e, n, 35, L + 5);
1501
+ return Ht(In(t), In(a));
1502
1502
  }
1503
1503
  },
1504
1504
  {
@@ -1507,7 +1507,7 @@ const zt = [
1507
1507
  textureUrl: "builtin:scratches",
1508
1508
  thumbnailUrl: "",
1509
1509
  description: "Branching crack lines",
1510
- generate: (e, n) => Lt(e, n, 55, L + 6)
1510
+ generate: (e, n) => Wt(e, n, 55, L + 6)
1511
1511
  },
1512
1512
  {
1513
1513
  id: "halftone",
@@ -1515,7 +1515,7 @@ const zt = [
1515
1515
  textureUrl: "builtin:halftone",
1516
1516
  thumbnailUrl: "",
1517
1517
  description: "Dot grid pattern",
1518
- generate: (e, n) => Nt(e, n, 55, L + 7)
1518
+ generate: (e, n) => Gt(e, n, 55, L + 7)
1519
1519
  },
1520
1520
  {
1521
1521
  id: "spray",
@@ -1526,25 +1526,25 @@ const zt = [
1526
1526
  generate: (e, n) => dn(e, n, 55, L + 8)
1527
1527
  }
1528
1528
  ];
1529
- let jn = !1;
1530
- function Wt(e, n) {
1529
+ let Kn = !1;
1530
+ function jt(e, n) {
1531
1531
  if (typeof OffscreenCanvas < "u")
1532
1532
  return new OffscreenCanvas(e, n);
1533
1533
  const t = document.createElement("canvas");
1534
1534
  return t.width = e, t.height = n, t;
1535
1535
  }
1536
- function qn(e, n) {
1536
+ function Jn(e, n) {
1537
1537
  if (typeof document > "u") return null;
1538
1538
  const t = document.createElement("canvas");
1539
1539
  return t.width = e, t.height = n, t;
1540
1540
  }
1541
- function Gt(e) {
1542
- const n = qn(e.width, e.height);
1541
+ function qt(e) {
1542
+ const n = Jn(e.width, e.height);
1543
1543
  if (!n) return "";
1544
1544
  const t = n.getContext("2d");
1545
1545
  if (!t) return "";
1546
1546
  t.putImageData(e, 0, 0);
1547
- const a = qn(q, q);
1547
+ const a = Jn(q, q);
1548
1548
  if (!a) return "";
1549
1549
  const r = a.getContext("2d");
1550
1550
  if (!r) return "";
@@ -1556,29 +1556,29 @@ function Gt(e) {
1556
1556
  }
1557
1557
  return r.putImageData(o, 0, 0), a.toDataURL("image/png");
1558
1558
  }
1559
- function Ht() {
1560
- if (!jn) {
1561
- jn = !0;
1562
- for (const e of zt) {
1559
+ function Xt() {
1560
+ if (!Kn) {
1561
+ Kn = !0;
1562
+ for (const e of Vt) {
1563
1563
  const n = e.generate(j, j);
1564
- An(n);
1565
- const t = Wt(j, j), a = t.getContext("2d");
1566
- a && (a.putImageData(n, 0, 0), Vt(e.textureUrl, t, j, j)), typeof document < "u" && (e.thumbnailUrl = Gt(n));
1564
+ In(n);
1565
+ const t = jt(j, j), a = t.getContext("2d");
1566
+ a && (a.putImageData(n, 0, 0), Yt(e.textureUrl, t, j, j)), typeof document < "u" && (e.thumbnailUrl = qt(n));
1567
1567
  }
1568
1568
  }
1569
1569
  }
1570
1570
  const z = /* @__PURE__ */ new Set(), W = /* @__PURE__ */ new Map(), un = /* @__PURE__ */ new Map();
1571
- function Xn(e, n) {
1571
+ function Zn(e, n) {
1572
1572
  if (typeof OffscreenCanvas < "u")
1573
1573
  return new OffscreenCanvas(e, n);
1574
1574
  const t = document.createElement("canvas");
1575
1575
  return t.width = e, t.height = n, t;
1576
1576
  }
1577
- function Yn(e) {
1577
+ function Qn(e) {
1578
1578
  return e.getContext("2d");
1579
1579
  }
1580
- function Kn(e) {
1581
- const { width: n, height: t } = e, a = Xn(n, t), r = Yn(a);
1580
+ function ne(e) {
1581
+ const { width: n, height: t } = e, a = Zn(n, t), r = Qn(a);
1582
1582
  if (!r) throw new Error("Failed to get 2d context for temp canvas");
1583
1583
  r.drawImage(e, 0, 0);
1584
1584
  const o = r.getImageData(0, 0, n, t), s = o.data;
@@ -1586,67 +1586,67 @@ function Kn(e) {
1586
1586
  const d = s[l], u = s[l + 1], p = s[l + 2], m = 255 - (0.299 * d + 0.587 * u + 0.114 * p);
1587
1587
  s[l] = 255, s[l + 1] = 255, s[l + 2] = 255, s[l + 3] = m;
1588
1588
  }
1589
- const c = Xn(n, t), i = Yn(c);
1589
+ const c = Zn(n, t), i = Qn(c);
1590
1590
  if (!i) throw new Error("Failed to get 2d context for mask canvas");
1591
1591
  return i.putImageData(o, 0, 0), { alphaMask: c, width: n, height: t };
1592
1592
  }
1593
- function de(e) {
1593
+ function be(e) {
1594
1594
  const n = W.get(e);
1595
1595
  if (n) return n;
1596
1596
  if (e.startsWith("builtin:")) {
1597
- Ht();
1597
+ Xt();
1598
1598
  const t = W.get(e);
1599
1599
  return t || null;
1600
1600
  }
1601
- return z.has(e) || (z.add(e), fe(e)), null;
1601
+ return z.has(e) || (z.add(e), ge(e)), null;
1602
1602
  }
1603
- function ua(e) {
1603
+ function ga(e) {
1604
1604
  return W.has(e) ? Promise.resolve() : new Promise((n) => {
1605
1605
  if (W.has(e)) {
1606
1606
  n();
1607
1607
  return;
1608
1608
  }
1609
1609
  const t = un.get(e) || [];
1610
- t.push(n), un.set(e, t), z.has(e) || (z.add(e), fe(e));
1610
+ t.push(n), un.set(e, t), z.has(e) || (z.add(e), ge(e));
1611
1611
  });
1612
1612
  }
1613
- function Vt(e, n, t, a) {
1613
+ function Yt(e, n, t, a) {
1614
1614
  W.has(e) || (W.set(e, { alphaMask: n, width: t, height: a }), en(e));
1615
1615
  }
1616
1616
  function en(e) {
1617
1617
  const n = un.get(e);
1618
1618
  n && (n.forEach((t) => t()), un.delete(e));
1619
1619
  }
1620
- function fe(e) {
1620
+ function ge(e) {
1621
1621
  if (typeof document < "u") {
1622
1622
  const n = new Image();
1623
1623
  n.crossOrigin = "anonymous", n.onload = () => {
1624
- const t = Kn(n);
1624
+ const t = ne(n);
1625
1625
  W.set(e, t), z.delete(e), en(e);
1626
1626
  }, n.onerror = () => {
1627
1627
  z.delete(e), en(e);
1628
1628
  }, n.src = e;
1629
1629
  } else
1630
1630
  fetch(e).then((n) => n.blob()).then((n) => createImageBitmap(n)).then((n) => {
1631
- const t = Kn(n);
1631
+ const t = ne(n);
1632
1632
  W.set(e, t), z.delete(e), en(e);
1633
1633
  }).catch(() => {
1634
1634
  z.delete(e), en(e);
1635
1635
  });
1636
1636
  }
1637
- function ue(e, n) {
1637
+ function me(e, n) {
1638
1638
  if (typeof OffscreenCanvas < "u")
1639
1639
  return new OffscreenCanvas(e, n);
1640
1640
  const t = document.createElement("canvas");
1641
1641
  return t.width = e, t.height = n, t;
1642
1642
  }
1643
- function jt(e, n, t, a) {
1643
+ function Kt(e, n, t, a) {
1644
1644
  if (!n.enabled || !n.textureUrl || n.intensity <= 0) return;
1645
- const r = de(n.textureUrl);
1645
+ const r = be(n.textureUrl);
1646
1646
  if (!r) return;
1647
1647
  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, m = Math.ceil(p), b = Math.ceil(f);
1648
1648
  if (m <= 0 || b <= 0) return;
1649
- const h = ue(m, b), S = h.getContext("2d");
1649
+ const h = me(m, b), S = h.getContext("2d");
1650
1650
  if (!S) return;
1651
1651
  S.drawImage(
1652
1652
  e.canvas,
@@ -1674,9 +1674,9 @@ function jt(e, n, t, a) {
1674
1674
  S.globalCompositeOperation = "destination-out", S.globalAlpha = n.intensity / 100, S.drawImage(r.alphaMask, 0, 0, m, b), S.globalCompositeOperation = "source-over";
1675
1675
  S.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(h, d, u), e.restore();
1676
1676
  }
1677
- function Jn(e, n, t, a) {
1677
+ function ee(e, n, t, a) {
1678
1678
  if (!n.enabled || n.style !== "custom" || !n.textureUrl) return;
1679
- const r = de(n.textureUrl);
1679
+ const r = be(n.textureUrl);
1680
1680
  if (!r) {
1681
1681
  a(e);
1682
1682
  return;
@@ -1691,7 +1691,7 @@ function Jn(e, n, t, a) {
1691
1691
  a(e);
1692
1692
  return;
1693
1693
  }
1694
- const g = ue($, v), y = g.getContext("2d");
1694
+ const g = me($, v), y = g.getContext("2d");
1695
1695
  if (!y) {
1696
1696
  a(e);
1697
1697
  return;
@@ -1719,12 +1719,12 @@ function Jn(e, n, t, a) {
1719
1719
  y.globalCompositeOperation = "destination-out", y.globalAlpha = o, y.drawImage(r.alphaMask, 0, 0, $, v), y.globalCompositeOperation = "source-over", y.globalAlpha = 1;
1720
1720
  e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(g, m, b), e.restore();
1721
1721
  }
1722
- const Zn = V("element-serializer"), pe = 4e3, on = /* @__PURE__ */ new Set();
1723
- function qt(e, n) {
1724
- const t = n ? Xt(n) : "no-src";
1722
+ const te = G("element-serializer"), ye = 4e3, on = /* @__PURE__ */ new Set();
1723
+ function Jt(e, n) {
1724
+ const t = n ? Zt(n) : "no-src";
1725
1725
  return `${e}:${t}`;
1726
1726
  }
1727
- function Xt(e) {
1727
+ function Zt(e) {
1728
1728
  let n = 0;
1729
1729
  for (let t = 0; t < e.length; t++) {
1730
1730
  const a = e.charCodeAt(t);
@@ -1732,20 +1732,20 @@ function Xt(e) {
1732
1732
  }
1733
1733
  return n.toString(36);
1734
1734
  }
1735
- function Pn() {
1735
+ function Dn() {
1736
1736
  on.clear();
1737
1737
  }
1738
- function he(e) {
1738
+ function $e(e) {
1739
1739
  for (const n of on)
1740
1740
  n.startsWith(`${e}:`) && on.delete(n);
1741
1741
  }
1742
- function Yt(e) {
1742
+ function Qt(e) {
1743
1743
  on.add(e);
1744
1744
  }
1745
- function Kt(e) {
1745
+ function na(e) {
1746
1746
  return on.has(e);
1747
1747
  }
1748
- async function Jt(e, n = pe) {
1748
+ async function ea(e, n = ye) {
1749
1749
  const { naturalWidth: t, naturalHeight: a } = e;
1750
1750
  if (t <= n && a <= n)
1751
1751
  return createImageBitmap(e);
@@ -1757,19 +1757,19 @@ async function Jt(e, n = pe) {
1757
1757
  });
1758
1758
  }
1759
1759
  let pn = null, hn = null;
1760
- function Zt(e, n) {
1760
+ function ta(e, n) {
1761
1761
  pn = e, hn = n;
1762
1762
  }
1763
- function Qt() {
1763
+ function aa() {
1764
1764
  pn = null, hn = null;
1765
1765
  }
1766
- function pa() {
1767
- Pn(), pn && pn();
1766
+ function ma() {
1767
+ Dn(), pn && pn();
1768
1768
  }
1769
- function ha(e) {
1770
- he(e), hn && hn(e);
1769
+ function ya(e) {
1770
+ $e(e), hn && hn(e);
1771
1771
  }
1772
- function In(e, n) {
1772
+ function Fn(e, n) {
1773
1773
  const t = e;
1774
1774
  if (typeof t.fontFamily == "string" && n.add(t.fontFamily), t.richText && typeof t.richText == "object") {
1775
1775
  const a = t.richText;
@@ -1784,14 +1784,14 @@ function In(e, n) {
1784
1784
  }
1785
1785
  if (t.children && Array.isArray(t.children))
1786
1786
  for (const a of t.children)
1787
- In(a, n);
1787
+ Fn(a, n);
1788
1788
  if (e.masks && Array.isArray(e.masks))
1789
1789
  for (const a of e.masks)
1790
- a.maskElement && In(a.maskElement, n);
1790
+ a.maskElement && Fn(a.maskElement, n);
1791
1791
  }
1792
- function Qn(e) {
1792
+ function ae(e) {
1793
1793
  if (typeof document > "u") return e;
1794
- const n = bn.getInstance();
1794
+ const n = mn.getInstance();
1795
1795
  return e.map((t) => {
1796
1796
  if (!(t != null && t.maskElement) || t.maskElement.transformType !== "image") return t;
1797
1797
  const a = t.maskElement.imageUrl;
@@ -1807,20 +1807,20 @@ function Qn(e) {
1807
1807
  } : t;
1808
1808
  });
1809
1809
  }
1810
- async function ne(e, n, t = pe) {
1810
+ async function re(e, n, t = ye) {
1811
1811
  const a = n.filter((i) => e.hasElementId(i.id)), r = [], o = [], s = /* @__PURE__ */ new Set();
1812
1812
  for (const i of a) {
1813
1813
  const l = i.toJSON();
1814
- if (In(l, s), i instanceof vn && !i.imageElement) {
1815
- Zn.warn(`[element-serializer] Skipping image ${i.id}: image not loaded (state: ${i.imageLoadState})`);
1814
+ if (Fn(l, s), i instanceof Sn && !i.imageElement) {
1815
+ te.warn(`[element-serializer] Skipping image ${i.id}: image not loaded (state: ${i.imageLoadState})`);
1816
1816
  continue;
1817
1817
  }
1818
- if (i instanceof vn && i.imageElement)
1818
+ if (i instanceof Sn && i.imageElement)
1819
1819
  try {
1820
- const d = qt(i.id, i.imageUrl);
1821
- if (!Kt(d)) {
1822
- const v = await Jt(i.imageElement, t);
1823
- o.push({ cacheKey: d, bitmap: v }), Yt(d);
1820
+ const d = Jt(i.id, i.imageUrl);
1821
+ if (!na(d)) {
1822
+ const v = await ea(i.imageElement, t);
1823
+ o.push({ cacheKey: d, bitmap: v }), Qt(d);
1824
1824
  }
1825
1825
  const p = i.transformData || {}, f = l.masks && l.masks.length > 0, m = f ? p.width : p.width * (p.cropWidth ?? 1), b = f ? p.height : p.height * (p.cropHeight ?? 1), h = {
1826
1826
  id: i.id,
@@ -1839,9 +1839,9 @@ async function ne(e, n, t = pe) {
1839
1839
  }
1840
1840
  p.flipHorizontal && (h.flipHorizontal = p.flipHorizontal), p.flipVertical && (h.flipVertical = p.flipVertical), p.borderRadius && (h.borderRadius = p.borderRadius), i.opacity !== void 0 && (h.opacity = i.opacity);
1841
1841
  const $ = h;
1842
- i.distressEffect && ($.distressEffect = { ...i.distressEffect }), l.masks && l.masks.length > 0 && ($.masks = Qn(l.masks)), l.blendMode && ($.blendMode = l.blendMode), l.knockoutParts && ($.knockoutParts = l.knockoutParts), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? $._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && ($._boundingBox = i.getBoundingBox()), r.push($);
1842
+ i.distressEffect && ($.distressEffect = { ...i.distressEffect }), l.masks && l.masks.length > 0 && ($.masks = ae(l.masks)), l.blendMode && ($.blendMode = l.blendMode), l.knockoutParts && ($.knockoutParts = l.knockoutParts), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? $._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && ($._boundingBox = i.getBoundingBox()), r.push($);
1843
1843
  } catch (d) {
1844
- Zn.error(`[element-serializer] Failed to create ImageBitmap for ${l.id}:`, d);
1844
+ te.error(`[element-serializer] Failed to create ImageBitmap for ${l.id}:`, d);
1845
1845
  }
1846
1846
  else {
1847
1847
  const d = {
@@ -1849,7 +1849,7 @@ async function ne(e, n, t = pe) {
1849
1849
  type: l.transformType
1850
1850
  // Map transformType to type for worker compatibility
1851
1851
  };
1852
- d.masks && Array.isArray(d.masks) && d.masks.length > 0 && (d.masks = Qn(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);
1852
+ d.masks && Array.isArray(d.masks) && d.masks.length > 0 && (d.masks = ae(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);
1853
1853
  }
1854
1854
  }
1855
1855
  const c = Array.from(s);
@@ -1874,7 +1874,7 @@ async function ne(e, n, t = pe) {
1874
1874
  newBitmaps: o
1875
1875
  };
1876
1876
  }
1877
- const na = `"use strict";
1877
+ const ra = `"use strict";
1878
1878
  (() => {
1879
1879
  var __create = Object.create;
1880
1880
  var __defProp = Object.defineProperty;
@@ -25744,7 +25744,7 @@ const na = `"use strict";
25744
25744
  console.error("[Export Worker] Unhandled promise rejection:", event.reason);
25745
25745
  };
25746
25746
  })();
25747
- `, O = V("WorkerExport");
25747
+ `, O = G("WorkerExport");
25748
25748
  class cn {
25749
25749
  constructor() {
25750
25750
  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;
@@ -25807,7 +25807,7 @@ class cn {
25807
25807
  * Call this when exiting editor mode to free memory.
25808
25808
  */
25809
25809
  clearWorkerBitmapCache() {
25810
- if (Pn(), this.worker && this.isReady) {
25810
+ if (Dn(), this.worker && this.isReady) {
25811
25811
  const n = {
25812
25812
  type: "clear-all-bitmaps"
25813
25813
  };
@@ -25819,7 +25819,7 @@ class cn {
25819
25819
  * Call this when an element is removed or its image source changes.
25820
25820
  */
25821
25821
  clearWorkerBitmap(n) {
25822
- if (he(n), this.worker && this.isReady) {
25822
+ if ($e(n), this.worker && this.isReady) {
25823
25823
  const t = {
25824
25824
  type: "clear-bitmap",
25825
25825
  elementId: n
@@ -25849,7 +25849,7 @@ class cn {
25849
25849
  try {
25850
25850
  let a;
25851
25851
  try {
25852
- const s = new Blob([na], { type: "application/javascript" });
25852
+ const s = new Blob([ra], { type: "application/javascript" });
25853
25853
  a = URL.createObjectURL(s), this.workerBlobUrl = a;
25854
25854
  } catch (s) {
25855
25855
  O.error("Failed to create worker blob:", s), t(new Error(`Worker creation failed: ${s instanceof Error ? s.message : String(s)}`));
@@ -25863,7 +25863,7 @@ class cn {
25863
25863
  const r = setTimeout(() => {
25864
25864
  t(new Error("Worker initialization timeout"));
25865
25865
  }, 15e3), o = (s) => {
25866
- s.data.type === "ready" && (clearTimeout(r), this.isReady = !0, Zt(
25866
+ s.data.type === "ready" && (clearTimeout(r), this.isReady = !0, ta(
25867
25867
  () => this.clearWorkerBitmapCache(),
25868
25868
  (c) => this.clearWorkerBitmap(c)
25869
25869
  ), n());
@@ -25940,7 +25940,7 @@ class cn {
25940
25940
  const { artboard: t, elements: a, config: r } = n;
25941
25941
  if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
25942
25942
  throw new Error("Worker is not initialized");
25943
- const o = `export-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await ne(t, a);
25943
+ const o = `export-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await re(t, a);
25944
25944
  i.length > 0 && this.registerBitmapsWithWorker(i);
25945
25945
  const l = {
25946
25946
  type: "export",
@@ -25997,7 +25997,7 @@ class cn {
25997
25997
  const { artboard: t, elements: a, config: r } = n;
25998
25998
  if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
25999
25999
  throw new Error("Worker is not initialized");
26000
- const o = `export-blob-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await ne(t, a);
26000
+ const o = `export-blob-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await re(t, a);
26001
26001
  i.length > 0 && this.registerBitmapsWithWorker(i);
26002
26002
  const l = {
26003
26003
  type: "export",
@@ -26111,7 +26111,7 @@ class cn {
26111
26111
  t.reject(new Error("Worker terminated")), this.pendingRequests.delete(n);
26112
26112
  for (; this.requestQueue.length > 0; )
26113
26113
  this.requestQueue.shift().reject(new Error("Worker terminated"));
26114
- this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, Pn(), Qt(), this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null);
26114
+ this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, Dn(), aa(), this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null);
26115
26115
  }
26116
26116
  }
26117
26117
  /**
@@ -26127,30 +26127,30 @@ class cn {
26127
26127
  }
26128
26128
  }
26129
26129
  let K = null;
26130
- function ba() {
26130
+ function $a() {
26131
26131
  return K || (K = new cn()), K;
26132
26132
  }
26133
- function ga() {
26133
+ function xa() {
26134
26134
  K && (K.terminate(), K = null);
26135
26135
  }
26136
- const U = V("Export");
26137
- function Dn(e, n) {
26136
+ const U = G("Export");
26137
+ function Mn(e, n) {
26138
26138
  var t;
26139
26139
  if (!(!e || typeof e != "object")) {
26140
26140
  if (typeof e.fontFamily == "string" && e.fontFamily.trim() && n.add(e.fontFamily), e.richText && Array.isArray(e.richText.spans))
26141
26141
  for (const a of e.richText.spans)
26142
26142
  (t = a == null ? void 0 : a.style) != null && t.fontFamily && typeof a.style.fontFamily == "string" && n.add(a.style.fontFamily);
26143
26143
  if (Array.isArray(e.children))
26144
- for (const a of e.children) Dn(a, n);
26144
+ for (const a of e.children) Mn(a, n);
26145
26145
  if (Array.isArray(e.masks))
26146
26146
  for (const a of e.masks)
26147
- a != null && a.maskElement && Dn(a.maskElement, n);
26147
+ a != null && a.maskElement && Mn(a.maskElement, n);
26148
26148
  }
26149
26149
  }
26150
- async function ee(e) {
26150
+ async function se(e) {
26151
26151
  if (typeof document > "u" || !document.fonts) return;
26152
26152
  const n = /* @__PURE__ */ new Set();
26153
- for (const a of e) Dn(a, n);
26153
+ for (const a of e) Mn(a, n);
26154
26154
  if (n.size === 0) return;
26155
26155
  const t = [];
26156
26156
  for (const a of n)
@@ -26318,7 +26318,7 @@ const rn = class rn {
26318
26318
  transparentBackground: i = !1,
26319
26319
  backgroundColor: l = n.backgroundColor
26320
26320
  } = r;
26321
- await ee(t);
26321
+ await se(t);
26322
26322
  const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
26323
26323
  d.width = u, d.height = p;
26324
26324
  const f = d.getContext("2d");
@@ -26349,7 +26349,7 @@ const rn = class rn {
26349
26349
  const x = $[E].id;
26350
26350
  x && v.add(x);
26351
26351
  }
26352
- Cn(
26352
+ Tn(
26353
26353
  f,
26354
26354
  T,
26355
26355
  $,
@@ -26386,7 +26386,7 @@ const rn = class rn {
26386
26386
  transparentBackground: i = !1,
26387
26387
  backgroundColor: l = n.backgroundColor
26388
26388
  } = r;
26389
- await ee(t);
26389
+ await se(t);
26390
26390
  const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
26391
26391
  d.width = u, d.height = p;
26392
26392
  const f = d.getContext("2d");
@@ -26417,7 +26417,7 @@ const rn = class rn {
26417
26417
  const F = $[A].id;
26418
26418
  F && v.add(F);
26419
26419
  }
26420
- Cn(
26420
+ Tn(
26421
26421
  f,
26422
26422
  w,
26423
26423
  $,
@@ -26434,24 +26434,24 @@ const rn = class rn {
26434
26434
  T.render(A, !1);
26435
26435
  };
26436
26436
  if (x && E)
26437
- Vn(f, w, (A) => {
26437
+ Yn(f, w, (A) => {
26438
26438
  const F = T.getVisualBoundingBox();
26439
- Jn(A, w.distressEffect, F, P);
26439
+ ee(A, w.distressEffect, F, P);
26440
26440
  });
26441
26441
  else if (x)
26442
- Vn(f, w, P);
26442
+ Yn(f, w, P);
26443
26443
  else if (E) {
26444
26444
  const A = T.getVisualBoundingBox();
26445
- Jn(f, w.distressEffect, A, P);
26445
+ ee(f, w.distressEffect, A, P);
26446
26446
  } else
26447
26447
  T.render(f, !1);
26448
26448
  }
26449
- }), (y = n.distressTexture) != null && y.enabled && jt(f, n.distressTexture, {
26449
+ }), (y = n.distressTexture) != null && y.enabled && Kt(f, n.distressTexture, {
26450
26450
  x: n.x,
26451
26451
  y: n.y,
26452
26452
  width: n.width,
26453
26453
  height: n.height
26454
- }), (k = n.imageMask) != null && k.enabled && Rt(f, n.imageMask, {
26454
+ }), (k = n.imageMask) != null && k.enabled && Ut(f, n.imageMask, {
26455
26455
  x: n.x,
26456
26456
  y: n.y,
26457
26457
  width: n.width,
@@ -26691,8 +26691,13 @@ const rn = class rn {
26691
26691
  }
26692
26692
  };
26693
26693
  rn.CURRENT_VERSION = "2.0.0", rn.workerManager = null, rn.workerInitPromise = null;
26694
- let te = rn;
26695
- class be {
26694
+ let bn = rn;
26695
+ const va = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
26696
+ __proto__: null,
26697
+ ExportManager: bn,
26698
+ default: bn
26699
+ }, Symbol.toStringTag, { value: "Module" }));
26700
+ class gn {
26696
26701
  /**
26697
26702
  * Create an element instance from a JSON configuration
26698
26703
  * TypeScript ensures all transform types are handled
@@ -26705,27 +26710,27 @@ class be {
26705
26710
  const { transformType: t } = n;
26706
26711
  switch (t) {
26707
26712
  case "custom":
26708
- return new Fe(n);
26713
+ return new Be(n);
26709
26714
  case "distort":
26710
26715
  throw new Error("DistortTransform is not yet implemented");
26711
26716
  case "circle":
26712
- return new De(n);
26717
+ return new Re(n);
26713
26718
  case "lean":
26714
- return new Ie(n);
26719
+ return new Oe(n);
26715
26720
  case "arch":
26716
- return new Pe(n);
26721
+ return new Me(n);
26717
26722
  case "ascend":
26718
- return new Ae(n);
26723
+ return new Fe(n);
26719
26724
  case "wave":
26720
- return new Ee(n);
26725
+ return new De(n);
26721
26726
  case "flag":
26722
- return new _e(n);
26727
+ return new Ie(n);
26723
26728
  case "image":
26724
- return new vn(n);
26729
+ return new Sn(n);
26725
26730
  case "group":
26726
26731
  const a = (n.children || []).map(
26727
- (s) => be.createFromJSON(s)
26728
- ), r = new Te({
26732
+ (s) => gn.createFromJSON(s)
26733
+ ), r = new Pe({
26729
26734
  id: n.id,
26730
26735
  x: n.x,
26731
26736
  y: n.y,
@@ -26733,9 +26738,9 @@ class be {
26733
26738
  });
26734
26739
  return a.forEach((s) => r.addChild(s)), r;
26735
26740
  case "shape":
26736
- return new ke(n);
26741
+ return new Ae(n);
26737
26742
  case "path":
26738
- return new Ce(n);
26743
+ return new Ee(n);
26739
26744
  default:
26740
26745
  const o = t;
26741
26746
  throw new Error(`Unknown transform type: ${o}`);
@@ -26949,48 +26954,266 @@ class be {
26949
26954
  return this.createFromJSON(t);
26950
26955
  }
26951
26956
  }
26957
+ const ie = G("ImportManager"), Nn = class Nn {
26958
+ /**
26959
+ * Import workspace from JSON file
26960
+ */
26961
+ static async importFromJSON(n) {
26962
+ try {
26963
+ const t = await this.readFileAsText(n), a = JSON.parse(t);
26964
+ if (this.validateDocument(a), !this.SUPPORTED_VERSIONS.includes(a.metadata.version))
26965
+ throw new Error(
26966
+ `Unsupported version: ${a.metadata.version}. Supported versions: ${this.SUPPORTED_VERSIONS.join(", ")}`
26967
+ );
26968
+ if (a.metadata.version === "1.0.0")
26969
+ return this.migrateV1Document(a);
26970
+ const r = [], o = [];
26971
+ return a.artboards.forEach((s) => {
26972
+ const c = zn.fromJSON({
26973
+ id: s.id,
26974
+ name: s.name,
26975
+ x: s.x,
26976
+ y: s.y,
26977
+ width: s.width,
26978
+ height: s.height,
26979
+ backgroundColor: s.backgroundColor,
26980
+ elementIds: s.elements.map((l) => l.id || "")
26981
+ }), i = s.elements.map((l) => {
26982
+ try {
26983
+ return gn.createFromJSON(l);
26984
+ } catch (d) {
26985
+ return ie.error("Failed to create element:", l, d), null;
26986
+ }
26987
+ }).filter((l) => l !== null);
26988
+ r.push(c), o.push(...i);
26989
+ }), await this.preloadAllImages(o), {
26990
+ success: !0,
26991
+ artboards: r,
26992
+ elements: o,
26993
+ activeArtboardId: a.activeArtboardId
26994
+ };
26995
+ } catch (t) {
26996
+ return {
26997
+ success: !1,
26998
+ error: t instanceof Error ? t.message : "Unknown error"
26999
+ };
27000
+ }
27001
+ }
27002
+ /**
27003
+ * Migrate v1 document (no artboards) to v2 (with artboards)
27004
+ */
27005
+ static async migrateV1Document(n) {
27006
+ var t, a, r;
27007
+ try {
27008
+ const o = n.elements || [], s = new zn({
27009
+ id: "artboard-migrated",
27010
+ name: "Artboard 1",
27011
+ x: 0,
27012
+ y: 0,
27013
+ width: ((t = n.canvas) == null ? void 0 : t.width) || 1920,
27014
+ height: ((a = n.canvas) == null ? void 0 : a.height) || 1080,
27015
+ backgroundColor: ((r = n.canvas) == null ? void 0 : r.backgroundColor) || "#ffffff"
27016
+ }), c = o.map((i) => {
27017
+ try {
27018
+ return gn.createFromJSON(i);
27019
+ } catch (l) {
27020
+ return ie.error("Failed to create element:", i, l), null;
27021
+ }
27022
+ }).filter((i) => i !== null);
27023
+ return c.forEach((i) => {
27024
+ s.addElementId(i.id);
27025
+ }), await this.preloadAllImages(c), {
27026
+ success: !0,
27027
+ artboards: [s],
27028
+ elements: c,
27029
+ activeArtboardId: s.id
27030
+ };
27031
+ } catch (o) {
27032
+ return {
27033
+ success: !1,
27034
+ error: o instanceof Error ? o.message : "Migration failed"
27035
+ };
27036
+ }
27037
+ }
27038
+ /**
27039
+ * Import image file
27040
+ */
27041
+ static async importImage(n) {
27042
+ try {
27043
+ if (!n.type.startsWith("image/"))
27044
+ throw new Error("File is not an image");
27045
+ const t = 10 * 1024 * 1024;
27046
+ if (n.size > t)
27047
+ throw new Error("Image file is too large (max 10MB)");
27048
+ const a = await this.readFileAsDataURL(n), { width: r, height: o } = await this.getImageDimensions(a);
27049
+ return {
27050
+ success: !0,
27051
+ dataUrl: a,
27052
+ filename: n.name,
27053
+ width: r,
27054
+ height: o
27055
+ };
27056
+ } catch (t) {
27057
+ return {
27058
+ success: !1,
27059
+ error: t instanceof Error ? t.message : "Unknown error"
27060
+ };
27061
+ }
27062
+ }
27063
+ /**
27064
+ * Validate document structure
27065
+ */
27066
+ static validateDocument(n) {
27067
+ if (!n || typeof n != "object")
27068
+ throw new Error("Invalid document");
27069
+ const t = n;
27070
+ if (!t.metadata)
27071
+ throw new Error("Missing metadata");
27072
+ if (!t.metadata.version)
27073
+ throw new Error("Missing version in metadata");
27074
+ if (!t.artboards && !t.elements)
27075
+ throw new Error("Missing artboards or elements array");
27076
+ if (t.artboards && !Array.isArray(t.artboards))
27077
+ throw new Error("Invalid artboards array");
27078
+ }
27079
+ /**
27080
+ * Read file as text
27081
+ */
27082
+ static readFileAsText(n) {
27083
+ return new Promise((t, a) => {
27084
+ const r = new FileReader();
27085
+ r.onload = (o) => {
27086
+ var s;
27087
+ return t((s = o.target) == null ? void 0 : s.result);
27088
+ }, r.onerror = () => a(new Error("Failed to read file")), r.readAsText(n);
27089
+ });
27090
+ }
27091
+ /**
27092
+ * Read file as data URL
27093
+ */
27094
+ static readFileAsDataURL(n) {
27095
+ return new Promise((t, a) => {
27096
+ const r = new FileReader();
27097
+ r.onload = (o) => {
27098
+ var s;
27099
+ return t((s = o.target) == null ? void 0 : s.result);
27100
+ }, r.onerror = () => a(new Error("Failed to read file")), r.readAsDataURL(n);
27101
+ });
27102
+ }
27103
+ /**
27104
+ * Get image dimensions from data URL
27105
+ */
27106
+ static getImageDimensions(n) {
27107
+ return new Promise((t, a) => {
27108
+ const r = new Image();
27109
+ r.onload = () => {
27110
+ t({ width: r.width, height: r.height });
27111
+ }, r.onerror = () => a(new Error("Failed to load image")), r.src = n;
27112
+ });
27113
+ }
27114
+ /**
27115
+ * Validate imported data before applying to state
27116
+ */
27117
+ static validateImportedData(n, t) {
27118
+ const a = [], r = /* @__PURE__ */ new Set();
27119
+ n.forEach((s) => {
27120
+ r.has(s.id) && a.push(`Duplicate artboard ID: ${s.id}`), r.add(s.id);
27121
+ });
27122
+ const o = /* @__PURE__ */ new Set();
27123
+ return t.forEach((s) => {
27124
+ o.has(s.id) && a.push(`Duplicate element ID: ${s.id}`), o.add(s.id);
27125
+ }), n.forEach((s) => {
27126
+ s.getElementIds().forEach((c) => {
27127
+ o.has(c) || a.push(`Artboard "${s.name}" references missing element: ${c}`);
27128
+ });
27129
+ }), {
27130
+ valid: a.length === 0,
27131
+ errors: a
27132
+ };
27133
+ }
27134
+ /**
27135
+ * Get import summary (for UI display before confirming)
27136
+ */
27137
+ static getImportSummary(n, t) {
27138
+ const a = this.validateImportedData(n, t);
27139
+ return {
27140
+ artboardCount: n.length,
27141
+ elementCount: t.length,
27142
+ artboardNames: n.map((r) => r.name),
27143
+ warnings: a.errors
27144
+ };
27145
+ }
27146
+ /**
27147
+ * Preload all images in parallel for fast artboard switching
27148
+ * Recursively finds all ImageElements (including those in groups)
27149
+ */
27150
+ static async preloadAllImages(n) {
27151
+ const t = [], a = (o) => {
27152
+ o.transformType === "image" ? t.push(o) : o.transformType === "group" && "children" in o && o.children.forEach((s) => a(s));
27153
+ };
27154
+ n.forEach(a);
27155
+ const r = t.map((o) => new Promise((s) => {
27156
+ if (o.imageLoaded)
27157
+ s();
27158
+ else if (o.imageElement) {
27159
+ const c = o.imageElement, i = () => {
27160
+ c.removeEventListener("load", i), c.removeEventListener("error", l), s();
27161
+ }, l = () => {
27162
+ c.removeEventListener("load", i), c.removeEventListener("error", l), s();
27163
+ };
27164
+ c.addEventListener("load", i), c.addEventListener("error", l);
27165
+ } else
27166
+ s();
27167
+ }));
27168
+ await Promise.all(r);
27169
+ }
27170
+ };
27171
+ Nn.SUPPORTED_VERSIONS = ["1.0.0", "2.0.0"];
27172
+ let oe = Nn;
26952
27173
  export {
26953
- he as A,
26954
- We as B,
26955
- be as C,
26956
- pe as D,
26957
- te as E,
26958
- Ht as F,
26959
- zt as G,
26960
- ua as H,
26961
- Et as I,
26962
- Cn as J,
26963
- Jn as K,
26964
- jt as L,
26965
- _t as M,
26966
- Rt as N,
27174
+ $e as A,
27175
+ qe as B,
27176
+ gn as C,
27177
+ ye as D,
27178
+ bn as E,
27179
+ Xt as F,
27180
+ Vt as G,
27181
+ ga as H,
27182
+ oe as I,
27183
+ Tn as J,
27184
+ ee as K,
27185
+ Kt as L,
27186
+ Ut as M,
27187
+ Dt as N,
27188
+ It as O,
27189
+ va as P,
26967
27190
  X as T,
26968
27191
  cn as W,
26969
- ia as a,
26970
- re as b,
27192
+ da as a,
27193
+ le as b,
26971
27194
  R as c,
26972
- pa as d,
26973
- fa as e,
26974
- Pn as f,
26975
- aa as g,
26976
- Me as h,
26977
- ra as i,
26978
- ta as j,
27195
+ ma as d,
27196
+ ba as e,
27197
+ Dn as f,
27198
+ oa as g,
27199
+ Ne as h,
27200
+ ca as i,
27201
+ ia as j,
26979
27202
  sn as k,
26980
- ba as l,
26981
- da as m,
26982
- Nn as n,
26983
- ha as o,
26984
- Un as p,
26985
- oa as q,
26986
- Be as r,
26987
- sa as s,
26988
- Ue as t,
26989
- ca as u,
26990
- ze as v,
26991
- se as w,
26992
- la as x,
26993
- Vn as y,
26994
- ga as z
27203
+ $a as l,
27204
+ ha as m,
27205
+ Gn as n,
27206
+ ya as o,
27207
+ Hn as p,
27208
+ fa as q,
27209
+ We as r,
27210
+ la as s,
27211
+ Ve as t,
27212
+ ua as u,
27213
+ je as v,
27214
+ de as w,
27215
+ pa as x,
27216
+ Yn as y,
27217
+ xa as z
26995
27218
  };
26996
- //# sourceMappingURL=ElementFactory-CuHSAPfg.js.map
27219
+ //# sourceMappingURL=ImportManager-D--7JnvW.js.map