@snowcone-app/canvas 0.16.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/{CanvasStateV1-BQD8fCBU.js → CanvasStateV1-C6i6vU6p.js} +63 -63
  2. package/dist/{CanvasStateV1-BQD8fCBU.js.map → CanvasStateV1-C6i6vU6p.js.map} +1 -1
  3. package/dist/EditorCanvasImpl-DkgE5-C2.js +68 -0
  4. package/dist/EditorCanvasImpl-DkgE5-C2.js.map +1 -0
  5. package/dist/EditorContext-CyanYzo2.js +1131 -0
  6. package/dist/EditorContext-CyanYzo2.js.map +1 -0
  7. package/dist/{ImportManager-eotl7r5d.js → ElementFactory-C05JJkRp.js} +1510 -5121
  8. package/dist/ElementFactory-C05JJkRp.js.map +1 -0
  9. package/dist/{HybridHistoryManager-NL3zyEl4.js → HybridHistoryManager-Bht98XRv.js} +98 -98
  10. package/dist/{HybridHistoryManager-NL3zyEl4.js.map → HybridHistoryManager-Bht98XRv.js.map} +1 -1
  11. package/dist/ImportManager-kRYfIX-D.js +3617 -0
  12. package/dist/ImportManager-kRYfIX-D.js.map +1 -0
  13. package/dist/SnowconeCanvas-C3eZ9PP8.js +1047 -0
  14. package/dist/SnowconeCanvas-C3eZ9PP8.js.map +1 -0
  15. package/dist/ThemeContext-Rjz25x9X.js +75 -0
  16. package/dist/ThemeContext-Rjz25x9X.js.map +1 -0
  17. package/dist/UnifiedFontService-BAtqqkU4.js +1478 -0
  18. package/dist/UnifiedFontService-BAtqqkU4.js.map +1 -0
  19. package/dist/advanced.mjs +210 -207
  20. package/dist/advanced.mjs.map +1 -1
  21. package/dist/api/embed.d.ts +8 -4
  22. package/dist/api/testing.d.ts +1 -0
  23. package/dist/components/editor/EditorBuy.d.ts +49 -0
  24. package/dist/components/editor/EditorCanvas.d.ts +30 -0
  25. package/dist/components/editor/EditorCanvasImpl.d.ts +33 -0
  26. package/dist/components/editor/EditorPreview.d.ts +39 -0
  27. package/dist/components/editor/EditorRoot.d.ts +86 -0
  28. package/dist/components/editor/EditorTextField.d.ts +22 -0
  29. package/dist/components/editor/RootInternals.d.ts +77 -0
  30. package/dist/components/editor/designStateStore.d.ts +45 -0
  31. package/dist/components/editor/index.d.ts +23 -0
  32. package/dist/components/embed-realtime/RealtimeCanvas.d.ts +1 -1
  33. package/dist/components/embed-realtime/RealtimeEmbed.d.ts +5 -78
  34. package/dist/components/embed-realtime/RealtimeMockup.d.ts +5 -34
  35. package/dist/components/embed-realtime/context.d.ts +12 -2
  36. package/dist/components/embed-realtime/validateEmbed.d.ts +17 -3
  37. package/dist/design/design-builder.d.ts +81 -6
  38. package/dist/editorError-DMENTZ-3.js +19 -0
  39. package/dist/editorError-DMENTZ-3.js.map +1 -0
  40. package/dist/editorErrors-DbIEtCTt.js +29 -0
  41. package/dist/editorErrors-DbIEtCTt.js.map +1 -0
  42. package/dist/embed-Bdj4PKUA.js +737 -0
  43. package/dist/embed-Bdj4PKUA.js.map +1 -0
  44. package/dist/embed.mjs +38 -230
  45. package/dist/embed.mjs.map +1 -1
  46. package/dist/errors/editorError.d.ts +57 -0
  47. package/dist/iconify-D6eVIEy4.js +1089 -0
  48. package/dist/iconify-D6eVIEy4.js.map +1 -0
  49. package/dist/index.mjs +48 -46
  50. package/dist/index.mjs.map +1 -1
  51. package/dist/internals.mjs +105 -104
  52. package/dist/internals.mjs.map +1 -1
  53. package/dist/template-fields-GOM4MNfq.js +643 -0
  54. package/dist/template-fields-GOM4MNfq.js.map +1 -0
  55. package/dist/testing/editorErrors.d.ts +30 -0
  56. package/dist/testing.mjs +28 -23
  57. package/dist/testing.mjs.map +1 -1
  58. package/dist/{usePieceGuideBundle-Cyl695jv.js → usePieceGuideBundle-CGERAQJl.js} +2 -2
  59. package/dist/{usePieceGuideBundle-Cyl695jv.js.map → usePieceGuideBundle-CGERAQJl.js.map} +1 -1
  60. package/dist/validation-DEd6EOCP.js +19947 -0
  61. package/dist/validation-DEd6EOCP.js.map +1 -0
  62. package/dist/workers/export-worker.bundle.string.d.ts +1 -1
  63. package/package.json +9 -4
  64. package/dist/ImportManager-eotl7r5d.js.map +0 -1
  65. package/dist/ThemeContext-D9AaUw9v.js +0 -1200
  66. package/dist/ThemeContext-D9AaUw9v.js.map +0 -1
  67. package/dist/template-fields-PcSPApl5.js +0 -1632
  68. package/dist/template-fields-PcSPApl5.js.map +0 -1
  69. package/dist/validation-BpEod0Rn.js +0 -22953
  70. package/dist/validation-BpEod0Rn.js.map +0 -1
@@ -0,0 +1,1131 @@
1
+ import { jsx as H } from "react/jsx-runtime";
2
+ import { useRef as ue, useState as y, useCallback as l, useEffect as Re, useContext as Q, useMemo as q, createContext as ee } from "react";
3
+ import { O as qe, ak as Me, al as Qe, G as Ve, am as et, an as tt, ao as nt, ap as ot, aq as rt, c as De, z as it, ar as ct, as as st, at as dt, H as at, M as ve, I as lt, g as ut, S as mt, au as ft, av as Oe } from "./HybridHistoryManager-Bht98XRv.js";
4
+ const le = De("useCommandHistory");
5
+ function At(t, e, r, o) {
6
+ const i = ue(new qe(r)), [n, s] = y({
7
+ canUndo: !1,
8
+ canRedo: !1,
9
+ // Per-artboard state for the active artboard
10
+ canUndoActiveArtboard: !1,
11
+ canRedoActiveArtboard: !1
12
+ }), c = l(() => {
13
+ const d = i.current, m = r.getActiveArtboardId();
14
+ s({
15
+ canUndo: d.canUndo(),
16
+ canRedo: d.canRedo(),
17
+ // Per-artboard state - only check active artboard's history
18
+ canUndoActiveArtboard: m ? d.canUndoArtboard(m) : !1,
19
+ canRedoActiveArtboard: m ? d.canRedoArtboard(m) : !1
20
+ });
21
+ }, [r]), V = l(
22
+ (d, m) => {
23
+ const P = new Me(
24
+ m.id,
25
+ d || null,
26
+ m,
27
+ (w) => {
28
+ e((k) => k.map((z) => z.id === w.id ? w : z));
29
+ }
30
+ ), I = r.getArtboardIdForElement(m.id);
31
+ if (I)
32
+ i.current.executeOnArtboard(I, P);
33
+ else {
34
+ const w = r.getActiveArtboardId();
35
+ w && i.current.executeOnArtboard(w, P);
36
+ }
37
+ c();
38
+ },
39
+ [e, r, c]
40
+ ), R = l(
41
+ (d, m, P, I) => {
42
+ const w = m || r.getActiveArtboardId();
43
+ if (!w) {
44
+ le.warn("No active artboard to add element to");
45
+ return;
46
+ }
47
+ const k = new Qe(
48
+ d,
49
+ (z) => {
50
+ const N = z;
51
+ e((v) => {
52
+ if (I) {
53
+ const U = v.findIndex((F) => F.id === I);
54
+ if (U !== -1) {
55
+ const F = [...v];
56
+ return F.splice(U, 0, N), F;
57
+ }
58
+ }
59
+ if (P) {
60
+ const U = v.findIndex((F) => F.id === P);
61
+ if (U !== -1) {
62
+ const F = [...v];
63
+ return F.splice(U + 1, 0, N), F;
64
+ }
65
+ for (let F = 0; F < v.length; F++) {
66
+ const X = v[F];
67
+ if (X instanceof Ve && X.children) {
68
+ const M = X.children.findIndex(($) => $.id === P);
69
+ if (M !== -1) {
70
+ const $ = X.clone();
71
+ $.children.splice(M + 1, 0, N);
72
+ const Y = [...v];
73
+ return Y[F] = $, Y;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ return [...v, N];
79
+ }), r.addElementToArtboard(z.id, w);
80
+ },
81
+ (z) => {
82
+ e((N) => N.filter((v) => v.id !== z)), r.removeElementFromArtboard(z);
83
+ }
84
+ );
85
+ i.current.executeOnArtboard(w, k), c();
86
+ },
87
+ [e, r, c]
88
+ ), D = l(
89
+ (d) => {
90
+ const m = r.getArtboardIdForElement(d.id);
91
+ if (!m) {
92
+ le.warn("Element not found in any artboard");
93
+ return;
94
+ }
95
+ const P = new et(
96
+ d,
97
+ (I) => {
98
+ e((w) => [...w, I]), r.addElementToArtboard(I.id, m);
99
+ },
100
+ (I) => {
101
+ e((w) => w.filter((k) => k.id !== I)), r.removeElementFromArtboard(I);
102
+ }
103
+ );
104
+ i.current.executeOnArtboard(m, P), c();
105
+ },
106
+ [e, r, c]
107
+ ), h = l(
108
+ (d) => {
109
+ const m = new tt(d, r);
110
+ i.current.executeGlobal(m), c(), o == null || o();
111
+ },
112
+ [r, c, o]
113
+ ), _ = l(
114
+ (d) => {
115
+ const m = new nt(d, r);
116
+ i.current.executeGlobal(m), c(), o == null || o();
117
+ },
118
+ [r, c, o]
119
+ ), O = l(
120
+ (d, m, P) => {
121
+ const I = new ot(d, m, P, r);
122
+ i.current.executeGlobal(I), c(), o == null || o();
123
+ },
124
+ [r, c, o]
125
+ ), C = l(
126
+ (d) => {
127
+ if (d.length === 0)
128
+ return;
129
+ const m = r.getActiveArtboardId();
130
+ if (!m) {
131
+ le.warn("No active artboard for batch execution");
132
+ return;
133
+ }
134
+ const P = d.map((I) => new class extends Object {
135
+ execute() {
136
+ I.execute();
137
+ }
138
+ undo() {
139
+ I.undo();
140
+ }
141
+ }());
142
+ i.current.executeBatchOnArtboard(m, P), c();
143
+ },
144
+ [r, c]
145
+ ), p = l(() => {
146
+ i.current.undo() && (c(), o == null || o());
147
+ }, [c, o]), u = l(() => {
148
+ i.current.redo() && (c(), o == null || o());
149
+ }, [c, o]), T = l(() => {
150
+ const d = r.getActiveArtboardId();
151
+ d && i.current.undoArtboard(d) && (c(), o == null || o());
152
+ }, [r, c, o]), f = l(() => {
153
+ const d = r.getActiveArtboardId();
154
+ d && i.current.redoArtboard(d) && (c(), o == null || o());
155
+ }, [r, c, o]), x = l(() => {
156
+ i.current.clear(), c();
157
+ }, [c]), B = l(
158
+ (d) => {
159
+ i.current.clearArtboardHistory(d), c();
160
+ },
161
+ [c]
162
+ ), g = ue(null);
163
+ Re(() => {
164
+ const d = r.getActiveArtboardId();
165
+ d !== g.current && (g.current = d, c());
166
+ });
167
+ const L = l(
168
+ (d, m, P) => {
169
+ const I = t.map((z) => z.id), w = r.getArtboardIdForElement(d);
170
+ if (!w) {
171
+ le.warn("Element not found in any artboard");
172
+ return;
173
+ }
174
+ const k = new rt(d, m, P, I, (z) => {
175
+ e((N) => {
176
+ const v = new Map(N.map((U) => [U.id, U]));
177
+ return z.map((U) => v.get(U)).filter(Boolean);
178
+ });
179
+ });
180
+ i.current.executeOnArtboard(w, k), c();
181
+ },
182
+ [t, e, r, c]
183
+ );
184
+ return {
185
+ // Element operations
186
+ executeElementUpdate: V,
187
+ executeAddElement: R,
188
+ executeRemoveElement: D,
189
+ executeReorderElement: L,
190
+ // Batch operations
191
+ executeCommandBatch: C,
192
+ // Artboard operations
193
+ executeCreateArtboard: h,
194
+ executeDeleteArtboard: _,
195
+ executeUpdateArtboard: O,
196
+ // Undo/redo (smart - considers last operation and active artboard)
197
+ undo: p,
198
+ redo: u,
199
+ // Undo/redo for active artboard only (element operations)
200
+ undoActiveArtboard: T,
201
+ redoActiveArtboard: f,
202
+ clearHistory: x,
203
+ clearArtboardHistory: B,
204
+ // State (smart - considers last operation)
205
+ canUndo: n.canUndo,
206
+ canRedo: n.canRedo,
207
+ // State for active artboard only
208
+ canUndoActiveArtboard: n.canUndoActiveArtboard,
209
+ canRedoActiveArtboard: n.canRedoActiveArtboard,
210
+ historyManager: i.current
211
+ };
212
+ }
213
+ function te(t) {
214
+ return t && "fontSize" in t && "color" in t && "fontFamily" in t;
215
+ }
216
+ function pt(t, e) {
217
+ const [r, o] = y(32), [i, n] = y("#333333"), [s, c] = y("Arial"), [V, R] = y("center");
218
+ Re(() => {
219
+ if (t && te(t)) {
220
+ const p = t.transformType === "circle" && "getEffectiveFontSize" in t ? Math.round(t.getEffectiveFontSize()) : Math.round(t.fontSize), u = t.color, T = t.fontFamily, f = t.textAlign;
221
+ o((x) => x !== p ? p : x), n((x) => x !== u ? u : x), c((x) => x !== T ? T : x), R((x) => x !== f ? f : x);
222
+ }
223
+ }, [t]);
224
+ const D = l(
225
+ (p) => {
226
+ if (!t || !te(t)) return;
227
+ const u = Math.max(ct, Math.min(st, r + p));
228
+ o(u);
229
+ const T = t.clone();
230
+ T.transformType === "circle" && "setEffectiveFontSize" in T ? T.setEffectiveFontSize(u) : T.setFontSize(u), e(T);
231
+ },
232
+ [t, r, e]
233
+ ), h = l(
234
+ (p) => {
235
+ if (!t || !te(t)) return;
236
+ o(p);
237
+ const u = t.clone();
238
+ u.transformType === "circle" && "setEffectiveFontSize" in u ? u.setEffectiveFontSize(p) : u.setFontSize(p), e(u);
239
+ },
240
+ [t, e]
241
+ ), _ = l(
242
+ (p) => {
243
+ if (!t || !te(t)) return;
244
+ n(p);
245
+ const u = t.clone();
246
+ if (u.color = p, u.richText)
247
+ for (const T of u.richText.spans)
248
+ T.style.color = void 0;
249
+ e(u);
250
+ },
251
+ [t, e]
252
+ ), O = l(
253
+ (p) => {
254
+ if (!t || !te(t)) return;
255
+ const u = t.fontFamily;
256
+ u !== p && it.clearCache(u), c(p);
257
+ const T = t.clone();
258
+ T.fontFamily = p, e(T);
259
+ },
260
+ [t, e]
261
+ ), C = l(
262
+ (p) => {
263
+ if (!t || !te(t)) return;
264
+ R(p);
265
+ const u = t.clone();
266
+ u.textAlign = p, e(u);
267
+ },
268
+ [t, e]
269
+ );
270
+ return {
271
+ // State
272
+ fontSize: r,
273
+ fontColor: i,
274
+ fontFamily: s,
275
+ textAlign: V,
276
+ // State setters (for UI only)
277
+ setFontSize: o,
278
+ setFontColor: n,
279
+ setFontFamily: c,
280
+ setTextAlign: R,
281
+ // Update functions (update element + UI)
282
+ updateFontSize: D,
283
+ setFontSizeValue: h,
284
+ updateFontColor: _,
285
+ updateFontFamily: O,
286
+ updateTextAlign: C
287
+ };
288
+ }
289
+ const Ne = "data-preserve-selection";
290
+ function ht(t) {
291
+ if (!(t instanceof Element))
292
+ return !1;
293
+ let e = t;
294
+ const r = [];
295
+ for (; e; ) {
296
+ const o = e.id ? `#${e.id}` : "", i = e.className ? `.${String(e.className).split(" ").slice(0, 2).join(".")}` : "";
297
+ if (r.push(`${e.tagName.toLowerCase()}${o}${i}`), e.hasAttribute(Ne))
298
+ return !0;
299
+ const n = e.getAttribute("role");
300
+ if (n === "dialog" || n === "alertdialog" || n === "menu" || n === "listbox")
301
+ return !0;
302
+ const s = e.getAttribute("data-slot");
303
+ if (s && (s.includes("popover") || s.includes("dialog")) || e.hasAttribute("data-radix-popper-content-wrapper"))
304
+ return !0;
305
+ e = e.parentElement;
306
+ }
307
+ return !1;
308
+ }
309
+ const Nt = {
310
+ [Ne]: ""
311
+ };
312
+ function xt(t) {
313
+ const e = Le(t);
314
+ return e !== null && e < 0.5;
315
+ }
316
+ function Lt(t) {
317
+ const e = Le(t);
318
+ return e !== null && e >= 0.5;
319
+ }
320
+ function Le(t) {
321
+ const e = t.trim();
322
+ if (e.startsWith("#")) {
323
+ const o = e.slice(1);
324
+ let i, n, s;
325
+ if (o.length === 3)
326
+ i = parseInt(o[0] + o[0], 16), n = parseInt(o[1] + o[1], 16), s = parseInt(o[2] + o[2], 16);
327
+ else if (o.length === 6)
328
+ i = parseInt(o.slice(0, 2), 16), n = parseInt(o.slice(2, 4), 16), s = parseInt(o.slice(4, 6), 16);
329
+ else return null;
330
+ return Number.isNaN(i) || Number.isNaN(n) || Number.isNaN(s) ? null : Ue(i, n, s);
331
+ }
332
+ const r = e.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
333
+ return r ? Ue(Number(r[1]), Number(r[2]), Number(r[3])) : null;
334
+ }
335
+ function Ue(t, e, r) {
336
+ const o = (i) => {
337
+ const n = i / 255;
338
+ return n <= 0.03928 ? n / 12.92 : Math.pow((n + 0.055) / 1.055, 2.4);
339
+ };
340
+ return 0.2126 * o(t) + 0.7152 * o(e) + 0.0722 * o(r);
341
+ }
342
+ const yt = "#333333", St = "#f4f4f5";
343
+ function It(t) {
344
+ return t && xt(t) ? St : yt;
345
+ }
346
+ const _e = ee(null), Et = 0.1, wt = 4, He = 0.25, bt = ({
347
+ children: t,
348
+ artboardManager: e,
349
+ canvasRef: r,
350
+ viewPadding: o = 0.9
351
+ }) => {
352
+ const [i, n] = y(1), [s, c] = y({ x: 0, y: 0 }), [V, R] = y(!1), [D, h] = y(1), _ = l(() => {
353
+ h(1), c({ x: 0, y: 0 });
354
+ }, []), O = l(() => {
355
+ n((f) => Math.min(f + He, wt));
356
+ }, []), C = l(() => {
357
+ n((f) => Math.max(f - He, Et));
358
+ }, []), p = l(() => {
359
+ const f = e.getActiveArtboard();
360
+ if (!f || !r.current) return;
361
+ let x = r.current.parentElement, B = 0, g = 0;
362
+ for (; x && (B = x.clientWidth, g = x.clientHeight, !(B > 0 && g > 0)); )
363
+ x = x.parentElement;
364
+ if (!B || !g) return;
365
+ const L = Math.min(
366
+ B * o / f.width,
367
+ g * o / f.height,
368
+ 1
369
+ // Never zoom in beyond 100%
370
+ );
371
+ n(L), c({ x: 0, y: 0 });
372
+ }, [e, r, o]), u = l(() => {
373
+ n(1), c({ x: 0, y: 0 });
374
+ }, []), T = q(
375
+ () => ({
376
+ zoom: i,
377
+ panOffset: s,
378
+ isPanning: V,
379
+ zoomIn: O,
380
+ zoomOut: C,
381
+ zoomToFit: p,
382
+ resetView: u,
383
+ setZoom: n,
384
+ setPanOffset: c,
385
+ setIsPanning: R,
386
+ userZoom: D,
387
+ setUserZoom: h,
388
+ resetUserView: _
389
+ }),
390
+ [i, s, V, O, C, p, u, D, _]
391
+ );
392
+ return /* @__PURE__ */ H(_e.Provider, { value: T, children: t });
393
+ };
394
+ function Tt() {
395
+ const t = Q(_e);
396
+ if (!t)
397
+ throw new Error("useViewportContext must be used within a ViewportProvider (or EditorProvider)");
398
+ return t;
399
+ }
400
+ const ke = ee(null), Ft = ({ children: t }) => {
401
+ const [e, r] = y(null), [o, i] = y([]), [n, s] = y(null), [c, V] = y(null), [R, D] = y(!1), h = l((C) => {
402
+ r(C);
403
+ }, []), _ = l((C) => {
404
+ s(C);
405
+ }, []), O = q(
406
+ () => ({
407
+ selectedId: e,
408
+ multiSelection: o,
409
+ activeChildElement: n,
410
+ hoveredElementId: c,
411
+ hideHandles: R,
412
+ setSelectedId: r,
413
+ setMultiSelection: i,
414
+ setHoveredElementId: V,
415
+ setHideHandles: D,
416
+ handleSelectionChange: h,
417
+ handleActiveChildChange: _
418
+ }),
419
+ [
420
+ e,
421
+ o,
422
+ n,
423
+ c,
424
+ R,
425
+ h,
426
+ _
427
+ ]
428
+ );
429
+ return /* @__PURE__ */ H(ke.Provider, { value: O, children: t });
430
+ };
431
+ function Pt() {
432
+ const t = Q(ke);
433
+ if (!t)
434
+ throw new Error("useSelectionContext must be used within a SelectionProvider (or EditorProvider)");
435
+ return t;
436
+ }
437
+ const Be = ee(null), Rt = ({ children: t, value: e }) => {
438
+ const r = q(
439
+ () => ({
440
+ undo: e.undo,
441
+ redo: e.redo,
442
+ canUndo: e.canUndo,
443
+ canRedo: e.canRedo,
444
+ undoActiveArtboard: e.undoActiveArtboard,
445
+ redoActiveArtboard: e.redoActiveArtboard,
446
+ canUndoActiveArtboard: e.canUndoActiveArtboard,
447
+ canRedoActiveArtboard: e.canRedoActiveArtboard
448
+ }),
449
+ [
450
+ e.undo,
451
+ e.redo,
452
+ e.canUndo,
453
+ e.canRedo,
454
+ e.undoActiveArtboard,
455
+ e.redoActiveArtboard,
456
+ e.canUndoActiveArtboard,
457
+ e.canRedoActiveArtboard
458
+ ]
459
+ );
460
+ return /* @__PURE__ */ H(Be.Provider, { value: r, children: t });
461
+ };
462
+ function _t() {
463
+ const t = Q(Be);
464
+ if (!t)
465
+ throw new Error("useHistoryContext must be used within a HistoryProvider (or EditorProvider)");
466
+ return t;
467
+ }
468
+ const We = ee(null), Ct = ({ children: t }) => {
469
+ const [e, r] = y(null), [o, i] = y(!1), [n, s] = y(0), [c, V] = y(!1), [R, D] = y(!1), h = q(
470
+ () => ({
471
+ expandedPanelType: e,
472
+ setExpandedPanelType: r,
473
+ isToolbarMenuOpen: o,
474
+ setIsToolbarMenuOpen: i,
475
+ textSelectionVersion: n,
476
+ setTextSelectionVersion: s,
477
+ isCanvasReady: c,
478
+ setCanvasReady: V,
479
+ isRotating: R,
480
+ setIsRotating: D
481
+ }),
482
+ [e, o, n, c, R]
483
+ );
484
+ return /* @__PURE__ */ H(We.Provider, { value: h, children: t });
485
+ };
486
+ function gt() {
487
+ const t = Q(We);
488
+ if (!t)
489
+ throw new Error("useToolStateContext must be used within a ToolStateProvider (or EditorProvider)");
490
+ return t;
491
+ }
492
+ const Ze = ee(null), zt = ({ children: t, value: e }) => {
493
+ const r = q(
494
+ () => ({
495
+ elements: e.elements,
496
+ elementStore: e.elementStore,
497
+ artboards: e.artboards,
498
+ artboardManager: e.artboardManager,
499
+ artboardVersion: e.artboardVersion,
500
+ setElements: e.setElements,
501
+ refreshArtboards: e.refreshArtboards,
502
+ getElementById: e.getElementById,
503
+ handleAddElement: e.handleAddElement,
504
+ handleElementUpdate: e.handleElementUpdate,
505
+ handleLoadWorkspace: e.handleLoadWorkspace,
506
+ handleCopyElements: e.handleCopyElements,
507
+ handlePasteElements: e.handlePasteElements,
508
+ fontSize: e.fontSize,
509
+ fontColor: e.fontColor,
510
+ fontFamily: e.fontFamily,
511
+ textAlign: e.textAlign,
512
+ updateFontSize: e.updateFontSize,
513
+ setFontSizeValue: e.setFontSizeValue,
514
+ updateFontColor: e.updateFontColor,
515
+ updateFontFamily: e.updateFontFamily,
516
+ updateTextAlign: e.updateTextAlign,
517
+ canvasRef: e.canvasRef,
518
+ canvasEditorRef: e.canvasEditorRef
519
+ }),
520
+ [
521
+ e.elements,
522
+ e.elementStore,
523
+ e.artboards,
524
+ e.artboardManager,
525
+ e.artboardVersion,
526
+ e.setElements,
527
+ e.refreshArtboards,
528
+ e.getElementById,
529
+ e.handleAddElement,
530
+ e.handleElementUpdate,
531
+ e.handleLoadWorkspace,
532
+ e.handleCopyElements,
533
+ e.handlePasteElements,
534
+ e.fontSize,
535
+ e.fontColor,
536
+ e.fontFamily,
537
+ e.textAlign,
538
+ e.updateFontSize,
539
+ e.setFontSizeValue,
540
+ e.updateFontColor,
541
+ e.updateFontFamily,
542
+ e.updateTextAlign,
543
+ e.canvasRef,
544
+ e.canvasEditorRef
545
+ ]
546
+ );
547
+ return /* @__PURE__ */ H(Ze.Provider, { value: r, children: t });
548
+ };
549
+ function kt() {
550
+ const t = Q(Ze);
551
+ if (!t)
552
+ throw new Error("useElementsContext must be used within an ElementsProvider (or EditorProvider)");
553
+ return t;
554
+ }
555
+ const Ge = ee(null), vt = ({ children: t, value: e }) => {
556
+ const r = q(
557
+ () => ({
558
+ executeElementUpdate: e.executeElementUpdate,
559
+ executeAddElement: e.executeAddElement,
560
+ executeRemoveElement: e.executeRemoveElement,
561
+ executeReorderElement: e.executeReorderElement,
562
+ executeCreateArtboard: e.executeCreateArtboard,
563
+ executeDeleteArtboard: e.executeDeleteArtboard,
564
+ executeUpdateArtboard: e.executeUpdateArtboard,
565
+ executeCommandBatch: e.executeCommandBatch,
566
+ undo: e.undo,
567
+ redo: e.redo,
568
+ canUndo: e.canUndo,
569
+ canRedo: e.canRedo,
570
+ undoActiveArtboard: e.undoActiveArtboard,
571
+ redoActiveArtboard: e.redoActiveArtboard,
572
+ canUndoActiveArtboard: e.canUndoActiveArtboard,
573
+ canRedoActiveArtboard: e.canRedoActiveArtboard,
574
+ historyManager: e.historyManager
575
+ }),
576
+ [
577
+ e.executeElementUpdate,
578
+ e.executeAddElement,
579
+ e.executeRemoveElement,
580
+ e.executeReorderElement,
581
+ e.executeCreateArtboard,
582
+ e.executeDeleteArtboard,
583
+ e.executeUpdateArtboard,
584
+ e.executeCommandBatch,
585
+ e.undo,
586
+ e.redo,
587
+ e.canUndo,
588
+ e.canRedo,
589
+ e.undoActiveArtboard,
590
+ e.redoActiveArtboard,
591
+ e.canUndoActiveArtboard,
592
+ e.canRedoActiveArtboard,
593
+ e.historyManager
594
+ ]
595
+ );
596
+ return /* @__PURE__ */ H(Ge.Provider, { value: r, children: t });
597
+ };
598
+ function Bt() {
599
+ const t = Q(Ge);
600
+ if (!t)
601
+ throw new Error("useCommandContext must be used within a CommandProvider (or EditorProvider)");
602
+ return t;
603
+ }
604
+ const Ot = De("EditorContext"), Xe = ee(null), Ut = ({ children: t, artboardManager: e, canvasRef: r, canvasEditorRef: o }) => {
605
+ const i = Tt(), n = Pt(), s = gt(), [c, V] = y(
606
+ () => e.getAllArtboards()
607
+ ), [R, D] = y(0), [h, _] = y(
608
+ () => new ve()
609
+ ), O = q(() => h.toArray(), [h]), C = l((a) => {
610
+ _((A) => {
611
+ const E = A.toArray(), b = typeof a == "function" ? a(E) : a;
612
+ return b === E ? A : ve.fromArray(b);
613
+ });
614
+ }, []), p = l(
615
+ (a) => h.get(a),
616
+ [h]
617
+ ), [u, T] = y([]), f = n.selectedId ? h.get(n.selectedId) : void 0, x = l(() => {
618
+ V([...e.getAllArtboards()]), D((a) => a + 1);
619
+ }, [e]), {
620
+ historyManager: B,
621
+ executeElementUpdate: g,
622
+ executeAddElement: L,
623
+ executeRemoveElement: d,
624
+ executeReorderElement: m,
625
+ executeCommandBatch: P,
626
+ executeCreateArtboard: I,
627
+ executeDeleteArtboard: w,
628
+ executeUpdateArtboard: k,
629
+ undo: z,
630
+ redo: N,
631
+ canUndo: v,
632
+ canRedo: U,
633
+ undoActiveArtboard: F,
634
+ redoActiveArtboard: X,
635
+ canUndoActiveArtboard: M,
636
+ canRedoActiveArtboard: $
637
+ } = At(
638
+ O,
639
+ C,
640
+ e,
641
+ x
642
+ ), Y = l(
643
+ (a) => {
644
+ const A = h.get(a.id);
645
+ g(A, a);
646
+ },
647
+ [h, g]
648
+ ), $e = l(
649
+ (a) => {
650
+ if (!f || !(f instanceof Ve))
651
+ return;
652
+ const A = f.clone(), E = A.children.findIndex(
653
+ (b) => b.id === a.id
654
+ );
655
+ E >= 0 && (A.children[E] = a, Y(A));
656
+ },
657
+ [f, Y]
658
+ ), Ye = n.activeChildElement || f, Je = n.activeChildElement ? $e : Y, {
659
+ fontSize: me,
660
+ fontColor: fe,
661
+ fontFamily: Ae,
662
+ textAlign: pe,
663
+ updateFontSize: he,
664
+ setFontSizeValue: xe,
665
+ updateFontColor: ye,
666
+ updateFontFamily: Se,
667
+ updateTextAlign: Ie
668
+ } = pt(Ye, Je), Ee = l(
669
+ async (a, A) => {
670
+ var Ce;
671
+ const E = e.getActiveArtboardId();
672
+ if (!E) {
673
+ alert("Please create or select an artboard first");
674
+ return;
675
+ }
676
+ const b = `element-${Date.now()}`, S = e.getActiveArtboard(), ne = S ? S.x + S.width / 2 : window.innerWidth / 2, oe = S ? S.y + S.height / 2 : window.innerHeight / 2, W = ((Ce = o.current) == null ? void 0 : Ce.getZoom()) || i.zoom || 1;
677
+ if (a === "image") {
678
+ const de = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", K = 200 / W, J = A == null ? void 0 : A.src, G = new lt({
679
+ id: b,
680
+ x: ne,
681
+ y: oe,
682
+ // Defer loading `src` until after the element is in the store so a
683
+ // synchronously-cached image can't fire onLoadCallback too early.
684
+ imageUrl: J ? "" : de,
685
+ transformData: {
686
+ type: "image",
687
+ width: K,
688
+ height: K,
689
+ cropX: 0,
690
+ cropY: 0,
691
+ cropWidth: 1,
692
+ cropHeight: 1,
693
+ flipHorizontal: !1,
694
+ flipVertical: !1,
695
+ borderRadius: 0
696
+ }
697
+ });
698
+ J && (G.imageLoaded = !1, G.imageElement = null, G.isCropping = !1, G.imageUrl = J, G.preserveDimensions = !1, G.onLoadCallback = (j) => {
699
+ const ge = j.transformData.width, ze = j.transformData.height, Pe = Math.min(K / ge, K / ze, 1);
700
+ Pe < 1 && (j.transformData.width = ge * Pe, j.transformData.height = ze * Pe), j.transformData.cropX = 0, j.transformData.cropY = 0, j.transformData.cropWidth = 1, j.transformData.cropHeight = 1, g(G, j);
701
+ }), L(G, E), n.setSelectedId(G.id), J && G.loadImage(J);
702
+ return;
703
+ }
704
+ let re;
705
+ const Z = {
706
+ text: "custom",
707
+ circle: "circle",
708
+ wave: "wave",
709
+ arch: "arch",
710
+ shape: "shape"
711
+ }[a] || "custom", ce = ut(Z);
712
+ if (!ce || !ce.Component)
713
+ return;
714
+ const se = e.getActiveArtboard(), Ke = se ? Math.min(se.width, se.height) * 0.1 : 80, Fe = se ? se.width * 0.5 : 300;
715
+ if (a === "shape") {
716
+ const de = (A == null ? void 0 : A.shapeType) ?? "rectangle";
717
+ let K = 200 / W, J = 200 / W;
718
+ de === "ellipse" ? (K = 150 / W, J = 250 / W) : de === "line" && (K = 300 / W, J = 8 / W), re = new mt({
719
+ id: b,
720
+ x: ne,
721
+ y: oe,
722
+ transformData: {
723
+ type: "shape",
724
+ shapeType: de,
725
+ width: K,
726
+ height: J,
727
+ fillColor: "#3b82f6",
728
+ fillOpacity: 1
729
+ }
730
+ });
731
+ } else
732
+ re = new ce.Component({
733
+ id: b,
734
+ text: "New Text",
735
+ x: ne,
736
+ y: oe,
737
+ fontSize: Ke,
738
+ fontFamily: "Poppins",
739
+ color: It(S == null ? void 0 : S.backgroundColor),
740
+ transformData: Z === "arch" ? {
741
+ type: "arch",
742
+ width: Fe,
743
+ archHeight: ft.archHeight
744
+ } : Z === "wave" ? {
745
+ type: "wave",
746
+ width: Fe,
747
+ amplitude: Oe.amplitude,
748
+ frequency: Oe.frequency
749
+ } : Z === "circle" ? {
750
+ type: "circle",
751
+ radius: Fe / 2
752
+ } : void 0
753
+ });
754
+ e.addElementToArtboard(b, E), L(
755
+ re,
756
+ E,
757
+ n.selectedId || void 0
758
+ ), n.setSelectedId(b);
759
+ },
760
+ [e, L, g, n, i.zoom, o]
761
+ ), we = l(() => {
762
+ const a = [];
763
+ if (n.multiSelection.length > 0) {
764
+ const A = O.filter(
765
+ (E) => n.multiSelection.includes(E.id)
766
+ );
767
+ a.push(...A);
768
+ } else f && a.push(f);
769
+ if (a.length > 0) {
770
+ const A = a.map((E) => E.clone());
771
+ T(A);
772
+ }
773
+ }, [f, n.multiSelection, O]), be = l(() => {
774
+ if (u.length === 0) return;
775
+ const a = [], A = 30, E = 30;
776
+ u.forEach((b) => {
777
+ const S = h.get(b.id), ne = S ? S.x : b.x, oe = S ? S.y : b.y, W = b.toJSON();
778
+ delete W.id;
779
+ const re = b.constructor, ie = new re(W);
780
+ ie.x = ne + A, ie.y = oe + E;
781
+ let Z = null;
782
+ if (S && (Z = e.getArtboardIdForElement(
783
+ S.id
784
+ )), Z || (Z = e.getActiveArtboardId()), !Z) {
785
+ Ot.warn("[handlePasteElements] No artboard found for pasting");
786
+ return;
787
+ }
788
+ const ce = S ? S.id : void 0;
789
+ L(ie, Z, ce), a.push(ie.id);
790
+ }), a.length === 1 ? n.handleSelectionChange(a[0]) : a.length > 1 && n.setMultiSelection(a);
791
+ }, [
792
+ u,
793
+ h,
794
+ e,
795
+ L,
796
+ n
797
+ ]), ae = l(() => {
798
+ if (s.expandedPanelType === "crop" && (f == null ? void 0 : f.transformType) === "image") {
799
+ const a = f;
800
+ if (a.isCropping) {
801
+ const A = a.clone();
802
+ A.exitCropMode(), g(a, A);
803
+ }
804
+ }
805
+ s.setExpandedPanelType(null);
806
+ }, [
807
+ s.expandedPanelType,
808
+ s.setExpandedPanelType,
809
+ f,
810
+ g
811
+ ]);
812
+ Re(() => {
813
+ const a = (A) => {
814
+ const E = A.target;
815
+ if (E.tagName === "CANVAS" || ht(E))
816
+ return;
817
+ const S = document.activeElement;
818
+ if (S != null && S.hasAttribute("data-preserve-selection")) {
819
+ S.blur();
820
+ return;
821
+ }
822
+ if (s.expandedPanelType !== null) {
823
+ ae();
824
+ return;
825
+ }
826
+ n.setSelectedId(null), n.setMultiSelection([]);
827
+ };
828
+ return document.addEventListener("pointerdown", a), () => document.removeEventListener("pointerdown", a);
829
+ }, [s.expandedPanelType, ae, n]);
830
+ const Te = l(
831
+ (a, A, E) => {
832
+ e.clear(), a.forEach((b) => {
833
+ e.createArtboard(b.toJSON());
834
+ }), E && e.setActiveArtboard(E), V([...e.getAllArtboards()]), D((b) => b + 1), C(A), n.setSelectedId(null);
835
+ },
836
+ [e, n, C]
837
+ ), je = q(() => ({
838
+ // From ViewportContext
839
+ zoom: i.zoom,
840
+ panOffset: i.panOffset,
841
+ isPanning: i.isPanning,
842
+ zoomIn: i.zoomIn,
843
+ zoomOut: i.zoomOut,
844
+ zoomToFit: i.zoomToFit,
845
+ resetView: i.resetView,
846
+ setZoom: i.setZoom,
847
+ setPanOffset: i.setPanOffset,
848
+ setIsPanning: i.setIsPanning,
849
+ // From SelectionContext
850
+ selectedId: n.selectedId,
851
+ multiSelection: n.multiSelection,
852
+ activeChildElement: n.activeChildElement,
853
+ hoveredElementId: n.hoveredElementId,
854
+ hideHandles: n.hideHandles,
855
+ setSelectedId: n.setSelectedId,
856
+ setMultiSelection: n.setMultiSelection,
857
+ setHoveredElementId: n.setHoveredElementId,
858
+ setHideHandles: n.setHideHandles,
859
+ handleSelectionChange: n.handleSelectionChange,
860
+ handleActiveChildChange: n.handleActiveChildChange,
861
+ // From ToolStateContext
862
+ expandedPanelType: s.expandedPanelType,
863
+ setExpandedPanelType: s.setExpandedPanelType,
864
+ isToolbarMenuOpen: s.isToolbarMenuOpen,
865
+ setIsToolbarMenuOpen: s.setIsToolbarMenuOpen,
866
+ textSelectionVersion: s.textSelectionVersion,
867
+ setTextSelectionVersion: s.setTextSelectionVersion,
868
+ isCanvasReady: s.isCanvasReady,
869
+ setCanvasReady: s.setCanvasReady,
870
+ isRotating: s.isRotating,
871
+ setIsRotating: s.setIsRotating,
872
+ // Cross-context handler
873
+ clearExpandedPanel: ae,
874
+ // Core state (element/artboard domain)
875
+ artboardManager: e,
876
+ artboards: c,
877
+ elements: O,
878
+ elementStore: h,
879
+ getElementById: p,
880
+ // Derived state (cross-context)
881
+ selectedElement: f,
882
+ // Refs
883
+ canvasRef: r,
884
+ canvasEditorRef: o,
885
+ // Element setters
886
+ setElements: C,
887
+ // Artboard version counter
888
+ artboardVersion: R,
889
+ // Handlers
890
+ refreshArtboards: x,
891
+ handleElementUpdate: Y,
892
+ handleAddElement: Ee,
893
+ handleLoadWorkspace: Te,
894
+ handleCopyElements: we,
895
+ handlePasteElements: be,
896
+ // Command history (undo/redo actions + execute functions)
897
+ historyManager: B,
898
+ executeElementUpdate: g,
899
+ executeAddElement: L,
900
+ executeRemoveElement: d,
901
+ executeReorderElement: m,
902
+ executeCommandBatch: P,
903
+ executeCreateArtboard: I,
904
+ executeDeleteArtboard: w,
905
+ executeUpdateArtboard: k,
906
+ undo: z,
907
+ redo: N,
908
+ canUndo: v,
909
+ canRedo: U,
910
+ undoActiveArtboard: F,
911
+ redoActiveArtboard: X,
912
+ canUndoActiveArtboard: M,
913
+ canRedoActiveArtboard: $,
914
+ // Element properties
915
+ fontSize: me,
916
+ fontColor: fe,
917
+ fontFamily: Ae,
918
+ textAlign: pe,
919
+ updateFontSize: he,
920
+ setFontSizeValue: xe,
921
+ updateFontColor: ye,
922
+ updateFontFamily: Se,
923
+ updateTextAlign: Ie
924
+ }), [
925
+ // Viewport
926
+ i.zoom,
927
+ i.panOffset,
928
+ i.isPanning,
929
+ i.zoomIn,
930
+ i.zoomOut,
931
+ i.zoomToFit,
932
+ i.resetView,
933
+ i.setZoom,
934
+ i.setPanOffset,
935
+ i.setIsPanning,
936
+ // Selection
937
+ n.selectedId,
938
+ n.multiSelection,
939
+ n.activeChildElement,
940
+ n.hoveredElementId,
941
+ n.hideHandles,
942
+ n.setSelectedId,
943
+ n.setMultiSelection,
944
+ n.setHoveredElementId,
945
+ n.setHideHandles,
946
+ n.handleSelectionChange,
947
+ n.handleActiveChildChange,
948
+ // Tool state
949
+ s.expandedPanelType,
950
+ s.setExpandedPanelType,
951
+ s.isToolbarMenuOpen,
952
+ s.setIsToolbarMenuOpen,
953
+ s.textSelectionVersion,
954
+ s.setTextSelectionVersion,
955
+ s.isCanvasReady,
956
+ s.setCanvasReady,
957
+ s.isRotating,
958
+ s.setIsRotating,
959
+ ae,
960
+ // Element/artboard domain
961
+ e,
962
+ c,
963
+ O,
964
+ h,
965
+ p,
966
+ f,
967
+ r,
968
+ o,
969
+ C,
970
+ R,
971
+ x,
972
+ Y,
973
+ Ee,
974
+ Te,
975
+ we,
976
+ be,
977
+ // Command history
978
+ B,
979
+ g,
980
+ L,
981
+ d,
982
+ m,
983
+ P,
984
+ I,
985
+ w,
986
+ k,
987
+ z,
988
+ N,
989
+ v,
990
+ U,
991
+ F,
992
+ X,
993
+ M,
994
+ $,
995
+ // Element properties
996
+ me,
997
+ fe,
998
+ Ae,
999
+ pe,
1000
+ he,
1001
+ xe,
1002
+ ye,
1003
+ Se,
1004
+ Ie
1005
+ ]);
1006
+ return /* @__PURE__ */ H(
1007
+ Rt,
1008
+ {
1009
+ value: {
1010
+ undo: z,
1011
+ redo: N,
1012
+ canUndo: v,
1013
+ canRedo: U,
1014
+ undoActiveArtboard: F,
1015
+ redoActiveArtboard: X,
1016
+ canUndoActiveArtboard: M,
1017
+ canRedoActiveArtboard: $
1018
+ },
1019
+ children: /* @__PURE__ */ H(
1020
+ zt,
1021
+ {
1022
+ value: {
1023
+ elements: O,
1024
+ elementStore: h,
1025
+ artboards: c,
1026
+ artboardManager: e,
1027
+ artboardVersion: R,
1028
+ setElements: C,
1029
+ refreshArtboards: x,
1030
+ getElementById: p,
1031
+ handleAddElement: Ee,
1032
+ handleElementUpdate: Y,
1033
+ handleLoadWorkspace: Te,
1034
+ handleCopyElements: we,
1035
+ handlePasteElements: be,
1036
+ fontSize: me,
1037
+ fontColor: fe,
1038
+ fontFamily: Ae,
1039
+ textAlign: pe,
1040
+ updateFontSize: he,
1041
+ setFontSizeValue: xe,
1042
+ updateFontColor: ye,
1043
+ updateFontFamily: Se,
1044
+ updateTextAlign: Ie,
1045
+ canvasRef: r,
1046
+ canvasEditorRef: o
1047
+ },
1048
+ children: /* @__PURE__ */ H(
1049
+ vt,
1050
+ {
1051
+ value: {
1052
+ executeElementUpdate: g,
1053
+ executeAddElement: L,
1054
+ executeRemoveElement: d,
1055
+ executeReorderElement: m,
1056
+ executeCommandBatch: P,
1057
+ executeCreateArtboard: I,
1058
+ executeDeleteArtboard: w,
1059
+ executeUpdateArtboard: k,
1060
+ undo: z,
1061
+ redo: N,
1062
+ canUndo: v,
1063
+ canRedo: U,
1064
+ undoActiveArtboard: F,
1065
+ redoActiveArtboard: X,
1066
+ canUndoActiveArtboard: M,
1067
+ canRedoActiveArtboard: $,
1068
+ historyManager: B
1069
+ },
1070
+ children: /* @__PURE__ */ H(Xe.Provider, { value: je, children: t })
1071
+ }
1072
+ )
1073
+ }
1074
+ )
1075
+ }
1076
+ );
1077
+ }, Wt = ({
1078
+ children: t,
1079
+ initialArtboardConfig: e = {},
1080
+ viewPadding: r = 0.9
1081
+ }) => {
1082
+ const [o] = y(() => {
1083
+ const s = new at(), c = {
1084
+ name: e.name || "Artboard 1",
1085
+ x: e.x ?? 0,
1086
+ y: e.y ?? 0,
1087
+ width: e.width ?? 1e3,
1088
+ height: e.height ?? 1e3,
1089
+ backgroundColor: e.backgroundColor || dt
1090
+ };
1091
+ return s.createArtboard(c), s;
1092
+ }), i = ue(null), n = ue(null);
1093
+ return /* @__PURE__ */ H(
1094
+ bt,
1095
+ {
1096
+ artboardManager: o,
1097
+ canvasRef: i,
1098
+ viewPadding: r,
1099
+ children: /* @__PURE__ */ H(Ft, { children: /* @__PURE__ */ H(Ct, { children: /* @__PURE__ */ H(
1100
+ Ut,
1101
+ {
1102
+ artboardManager: o,
1103
+ canvasRef: i,
1104
+ canvasEditorRef: n,
1105
+ children: t
1106
+ }
1107
+ ) }) })
1108
+ }
1109
+ );
1110
+ }, Zt = () => {
1111
+ const t = Q(Xe);
1112
+ if (!t)
1113
+ throw new Error("useEditor must be used within EditorProvider");
1114
+ return t;
1115
+ };
1116
+ export {
1117
+ Wt as E,
1118
+ Ne as P,
1119
+ Tt as a,
1120
+ Bt as b,
1121
+ kt as c,
1122
+ _t as d,
1123
+ Pt as e,
1124
+ gt as f,
1125
+ Lt as g,
1126
+ xt as i,
1127
+ Nt as p,
1128
+ ht as s,
1129
+ Zt as u
1130
+ };
1131
+ //# sourceMappingURL=EditorContext-CyanYzo2.js.map