@snowcone-app/canvas 0.1.9 → 0.1.12

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