@snowcone-app/canvas 0.19.1 → 0.21.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 (86) hide show
  1. package/README.md +124 -13
  2. package/STYLING_CONTRACT.md +427 -0
  3. package/dist/{CanvasRenderer-DUc-MOeR.js → CanvasRenderer-CwiYq8qg.js} +3 -3
  4. package/dist/{CanvasRenderer-DUc-MOeR.js.map → CanvasRenderer-CwiYq8qg.js.map} +1 -1
  5. package/dist/{CanvasStateV1-Bq48qhv5.js → CanvasStateV1-BFabcAKC.js} +35 -30
  6. package/dist/{CanvasStateV1-Bq48qhv5.js.map → CanvasStateV1-BFabcAKC.js.map} +1 -1
  7. package/dist/{ContextualToolbars-CkLjHNPn.js → ContextualToolbars--vTtorNg.js} +5 -5
  8. package/dist/{ContextualToolbars-CkLjHNPn.js.map → ContextualToolbars--vTtorNg.js.map} +1 -1
  9. package/dist/{EditorCanvasImpl-_3xCnLkx.js → EditorCanvasImpl-2ZgIUVpK.js} +18 -17
  10. package/dist/{EditorCanvasImpl-_3xCnLkx.js.map → EditorCanvasImpl-2ZgIUVpK.js.map} +1 -1
  11. package/dist/{ImportManager-D--7JnvW.js → ExportManager-DK7CdI-G.js} +24758 -24758
  12. package/dist/ExportManager-DK7CdI-G.js.map +1 -0
  13. package/dist/{FontAnalyzer-DIlqmyuf.js → FontAnalyzer-BpsTYowD.js} +5 -2
  14. package/dist/FontAnalyzer-BpsTYowD.js.map +1 -0
  15. package/dist/SnowconeCanvas-DqZicdxK.js +1172 -0
  16. package/dist/SnowconeCanvas-DqZicdxK.js.map +1 -0
  17. package/dist/{MenuButton-CeoEAtzP.js → UnifiedFontService-B1PGVu8O.js} +3704 -3429
  18. package/dist/UnifiedFontService-B1PGVu8O.js.map +1 -0
  19. package/dist/advanced.mjs +13 -13
  20. package/dist/api/embed.d.ts +3 -1
  21. package/dist/api/stable.d.ts +2 -2
  22. package/dist/components/editor/EditorAdd.d.ts +2 -1
  23. package/dist/components/editor/EditorBuy.d.ts +2 -1
  24. package/dist/components/editor/EditorCanvas.d.ts +2 -1
  25. package/dist/components/editor/EditorControls.d.ts +2 -1
  26. package/dist/components/editor/EditorHistory.d.ts +2 -1
  27. package/dist/components/editor/EditorLayers.d.ts +2 -1
  28. package/dist/components/editor/EditorMenu.d.ts +2 -1
  29. package/dist/components/editor/EditorPreview.d.ts +2 -1
  30. package/dist/components/editor/EditorRoot.d.ts +2 -1
  31. package/dist/components/editor/EditorTextField.d.ts +2 -1
  32. package/dist/components/editor/useProductSelection.d.ts +2 -1
  33. package/dist/components/embed/SnowconeCanvas.d.ts +10 -2
  34. package/dist/components/embed-realtime/context.d.ts +1 -1
  35. package/dist/contexts/EditorContext.d.ts +1 -1
  36. package/dist/core/ArtboardElement.d.ts +2 -1
  37. package/dist/default-editor/SnowconeEditor.d.ts +40 -0
  38. package/dist/design/design-builder.d.ts +46 -21
  39. package/dist/design/template-fields.d.ts +32 -0
  40. package/dist/design-builder-CPF60RU2.js +367 -0
  41. package/dist/design-builder-CPF60RU2.js.map +1 -0
  42. package/dist/{EditorContext-5QpqAhjh.js → editorErrors-CK1RISFa.js} +382 -358
  43. package/dist/editorErrors-CK1RISFa.js.map +1 -0
  44. package/dist/embed-2tp6Ue90.js +1117 -0
  45. package/dist/embed-2tp6Ue90.js.map +1 -0
  46. package/dist/embed.mjs +33 -31
  47. package/dist/hooks/useArtboards.d.ts +2 -1
  48. package/dist/index.mjs +8 -8
  49. package/dist/internals.mjs +5 -5
  50. package/dist/kits/sections.d.ts +11 -7
  51. package/dist/rendering/serialize-for-server.d.ts +3 -0
  52. package/dist/state/CanvasStateV1.d.ts +12 -0
  53. package/dist/template-fields-FgImixyv.js +476 -0
  54. package/dist/template-fields-FgImixyv.js.map +1 -0
  55. package/dist/testing/assertRenders.d.ts +2 -1
  56. package/dist/testing.mjs +8 -8
  57. package/dist/testing.mjs.map +1 -1
  58. package/dist/types/index.d.ts +10 -0
  59. package/dist/{usePieceGuideBundle-DVOISsB1.js → usePieceGuideBundle-Ctnu5k2D.js} +2 -2
  60. package/dist/{usePieceGuideBundle-DVOISsB1.js.map → usePieceGuideBundle-Ctnu5k2D.js.map} +1 -1
  61. package/dist/{validation-0IscSfRb.js → validation-3YEMnKLB.js} +467 -463
  62. package/dist/validation-3YEMnKLB.js.map +1 -0
  63. package/example/README.md +179 -0
  64. package/example/index.html +12 -0
  65. package/example/package.json +24 -0
  66. package/example/src/Widget.tsx +62 -0
  67. package/example/src/main.tsx +9 -0
  68. package/example/tsconfig.json +14 -0
  69. package/example/vite.config.ts +11 -0
  70. package/llms.txt +45 -0
  71. package/package.json +11 -6
  72. package/dist/EditorContext-5QpqAhjh.js.map +0 -1
  73. package/dist/FontAnalyzer-DIlqmyuf.js.map +0 -1
  74. package/dist/ImportManager-D--7JnvW.js.map +0 -1
  75. package/dist/MenuButton-CeoEAtzP.js.map +0 -1
  76. package/dist/SnowconeCanvas-3PA17na3.js +0 -1166
  77. package/dist/SnowconeCanvas-3PA17na3.js.map +0 -1
  78. package/dist/design-builder-v4935TeS.js +0 -343
  79. package/dist/design-builder-v4935TeS.js.map +0 -1
  80. package/dist/editorErrors-DXNfVXtD.js +0 -29
  81. package/dist/editorErrors-DXNfVXtD.js.map +0 -1
  82. package/dist/embed-D2QOpJXG.js +0 -1090
  83. package/dist/embed-D2QOpJXG.js.map +0 -1
  84. package/dist/template-fields-Dr3fMItw.js +0 -329
  85. package/dist/template-fields-Dr3fMItw.js.map +0 -1
  86. package/dist/validation-0IscSfRb.js.map +0 -1
@@ -1,1166 +0,0 @@
1
- import { y as G, c as Q, al as Be, I as De } from "./FontAnalyzer-DIlqmyuf.js";
2
- import { jsx as w, Fragment as Se, jsxs as V } from "react/jsx-runtime";
3
- import { useMemo as Ae, useRef as F, useEffect as R, Component as We, useState as q, useCallback as z, useImperativeHandle as $e, forwardRef as ke } from "react";
4
- import { l as He, e as Oe, f as ze, I as Ue, G as Ke, a as Xe, Z as je, m as ve, i as Ye, b as Ve, D as Ge, r as Qe, v as Je, S as Ze, g as qe, c as _e } from "./validation-0IscSfRb.js";
5
- import { L as et, M as Ee, C as tt, u as ue, f as rt } from "./MenuButton-CeoEAtzP.js";
6
- import { d as nt, e as at } from "./ContextualToolbars-CkLjHNPn.js";
7
- import { U as ot } from "./template-fields-Dr3fMItw.js";
8
- import { E as st, u as ee } from "./EditorContext-5QpqAhjh.js";
9
- import { T as xe } from "./ThemeContext-Rjz25x9X.js";
10
- import { C as ce } from "./CanvasRenderer-DUc-MOeR.js";
11
- import { C as it } from "./ImportManager-D--7JnvW.js";
12
- const Ie = Q("KitLayout"), Z = "canvas", le = 320;
13
- let ye = !1;
14
- function ct() {
15
- ye || (ye = !0, He({
16
- LayersPanel: et,
17
- EffectsPanel: Oe,
18
- ExportPanel: ze,
19
- ImagePanel: Ue,
20
- GlyphPanel: Ke,
21
- ArtboardTabs: Xe,
22
- ContextualToolbars: nt,
23
- ZoomControls: je,
24
- MenuButton: Ee,
25
- CropPanel: at
26
- }), ve("add-element-menu", {
27
- component: Ee,
28
- label: "Add Element",
29
- icon: "gravity-ui:plus",
30
- position: "topbar"
31
- }), ve("undo-redo-controls", {
32
- component: ot,
33
- label: "Undo / Redo",
34
- icon: "lucide:undo-2",
35
- position: "topbar"
36
- }));
37
- }
38
- function re({ ids: n }) {
39
- return !n || n.length === 0 ? null : /* @__PURE__ */ w(Se, { children: n.map((e) => {
40
- var t;
41
- if (e === Z) return null;
42
- const r = Ye(e);
43
- if (!r)
44
- return typeof G < "u" && ((t = G.env) == null ? void 0 : t.NODE_ENV) === "development" && Ie.warn(
45
- `Kit layout references unknown section "${e}" — skipping. Register it with registerSection("${e}", { ... }).`
46
- ), null;
47
- const a = r.component;
48
- return /* @__PURE__ */ w(a, {}, e);
49
- }) });
50
- }
51
- function lt({ kit: n, canvas: e }) {
52
- var E, f, h, v;
53
- ct();
54
- const r = n.layout.slots, a = !!((E = r.topbar) != null && E.some((g) => g !== Z)), t = !!((f = r.left) != null && f.some((g) => g !== Z)), s = !!((h = r.right) != null && h.some((g) => g !== Z)), c = !!((v = r.bottombar) != null && v.some((g) => g !== Z)), l = Ae(
55
- () => !a && !t && !s && !c,
56
- [a, t, s, c]
57
- ), i = F(null), u = a || t || s || c, m = F(!1);
58
- return R(() => {
59
- var o;
60
- if (typeof G > "u" || ((o = G.env) == null ? void 0 : o.NODE_ENV) !== "development" || !u) return;
61
- const g = i.current;
62
- if (!g || typeof ResizeObserver > "u") return;
63
- const S = (d) => {
64
- d > 0 && d < le && !m.current ? (m.current = !0, Ie.warn(
65
- `Kit "${n.name}" declares chrome (toolbar / panels) but its container is only ${Math.round(d)}px wide — below the ~${le}px needed to render it, so the toolbar / panels are suppressed and the editor looks like a bare canvas. Give the editor more container width, or pass kit="embed-only" if a chrome-less canvas is intended.`
66
- )) : d >= le && (m.current = !1);
67
- };
68
- S(g.getBoundingClientRect().width);
69
- const p = new ResizeObserver((d) => {
70
- for (const x of d) S(x.contentRect.width);
71
- });
72
- return p.observe(g), () => p.disconnect();
73
- }, [u, n.name]), l ? /* @__PURE__ */ w(Se, { children: e }) : /* @__PURE__ */ V("div", { ref: i, className: "sc-kit-layout", style: { display: "flex", flexDirection: "column", height: "100%", minHeight: 0 }, children: [
74
- a && /* @__PURE__ */ w(
75
- "div",
76
- {
77
- className: "sc-kit-topbar sc-toolbar",
78
- style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap", flexShrink: 0 },
79
- children: /* @__PURE__ */ w(re, { ids: r.topbar })
80
- }
81
- ),
82
- /* @__PURE__ */ V("div", { className: "sc-kit-body", style: { display: "flex", flex: 1, minHeight: 0 }, children: [
83
- t && /* @__PURE__ */ w("div", { className: "sc-kit-left", style: { flexShrink: 0, overflow: "auto" }, children: /* @__PURE__ */ w(re, { ids: r.left }) }),
84
- /* @__PURE__ */ w("div", { className: "sc-kit-canvas", style: { flex: 1, minWidth: 0, position: "relative" }, children: e }),
85
- s && /* @__PURE__ */ w("div", { className: "sc-kit-right", style: { flexShrink: 0, overflow: "auto" }, children: /* @__PURE__ */ w(re, { ids: r.right }) })
86
- ] }),
87
- c && /* @__PURE__ */ w(
88
- "div",
89
- {
90
- className: "sc-kit-bottombar sc-toolbar",
91
- style: { display: "flex", alignItems: "center", gap: 8, flexShrink: 0 },
92
- children: /* @__PURE__ */ w(re, { ids: r.bottombar })
93
- }
94
- )
95
- ] });
96
- }
97
- const dt = Q("ErrorBoundary");
98
- class ut extends We {
99
- constructor(e) {
100
- super(e), this.resetError = () => {
101
- this.setState({
102
- hasError: !1,
103
- error: null
104
- });
105
- }, this.state = {
106
- hasError: !1,
107
- error: null
108
- };
109
- }
110
- static getDerivedStateFromError(e) {
111
- return {
112
- hasError: !0,
113
- error: e
114
- };
115
- }
116
- componentDidCatch(e, r) {
117
- if (dt.error("Caught error:", e, r), this.props.onError && this.props.onError(e, r), this.props.onCanvasError) {
118
- const a = {
119
- category: "unknown",
120
- message: e.message,
121
- originalError: e,
122
- recoverable: !1
123
- };
124
- this.props.onCanvasError(a);
125
- }
126
- }
127
- render() {
128
- return this.state.hasError && this.state.error ? this.props.renderError ? this.props.renderError(this.state.error, this.resetError) : this.props.fallback ? typeof this.props.fallback == "function" ? this.props.fallback(this.state.error, this.resetError) : this.props.fallback : /* @__PURE__ */ V(
129
- "div",
130
- {
131
- style: {
132
- padding: "24px",
133
- border: "2px solid var(--danger)",
134
- borderRadius: "8px",
135
- backgroundColor: "color-mix(in oklch, var(--danger) 10%, var(--background))",
136
- color: "var(--danger)",
137
- fontFamily: "system-ui, sans-serif"
138
- },
139
- children: [
140
- /* @__PURE__ */ w("h2", { style: { margin: "0 0 16px 0", fontSize: "18px", fontWeight: 600 }, children: "Something went wrong" }),
141
- /* @__PURE__ */ w(
142
- "pre",
143
- {
144
- style: {
145
- margin: "0 0 16px 0",
146
- padding: "12px",
147
- backgroundColor: "color-mix(in oklch, var(--danger) 15%, var(--background))",
148
- borderRadius: "4px",
149
- fontSize: "14px",
150
- overflow: "auto",
151
- maxHeight: "200px"
152
- },
153
- children: this.state.error.message
154
- }
155
- ),
156
- /* @__PURE__ */ w(
157
- "button",
158
- {
159
- onClick: this.resetError,
160
- style: {
161
- padding: "8px 16px",
162
- backgroundColor: "var(--danger)",
163
- color: "var(--danger-foreground)",
164
- border: "none",
165
- borderRadius: "4px",
166
- fontSize: "14px",
167
- fontWeight: 500,
168
- cursor: "pointer"
169
- },
170
- children: "Try again"
171
- }
172
- )
173
- ]
174
- }
175
- ) : this.props.children;
176
- }
177
- }
178
- function ft({
179
- inheritTheme: n,
180
- externalProvider: e,
181
- services: r,
182
- viewPadding: a,
183
- children: t
184
- }) {
185
- const s = e ? /* @__PURE__ */ w(xe, { defaultTheme: "light", passive: n, children: t }) : /* @__PURE__ */ w(xe, { defaultTheme: "light", passive: n, children: /* @__PURE__ */ w(st, { viewPadding: a, children: t }) });
186
- return r ? /* @__PURE__ */ w(tt, { services: r, children: s }) : s;
187
- }
188
- const mt = Q("useAutoExport");
189
- function ht(n) {
190
- const { config: e, historyManager: r, artboards: a, elements: t, onExport: s, onExportScheduled: c, isCanvasReady: l = !1 } = n, i = F(null), u = F(!1), m = F({
191
- totalExports: 0,
192
- skippedExports: 0,
193
- lastExportTime: null,
194
- avgExportInterval: 0
195
- }), [E, f] = q(m.current), h = F(s);
196
- h.current = s, R(() => {
197
- const o = new Ve({
198
- ...Ge,
199
- ...e
200
- });
201
- return o.onExport(async () => {
202
- try {
203
- await h.current(), m.current = o.getStats();
204
- } catch (d) {
205
- mt.error("[useAutoExport] Export failed:", d);
206
- }
207
- }), i.current = o, () => {
208
- o.destroy();
209
- };
210
- }, []), R(() => {
211
- l && u.current && i.current && (u.current = !1, i.current.forceExport());
212
- }, [l]), R(() => {
213
- i.current && e && i.current.updateConfig(e);
214
- }, [e == null ? void 0 : e.enabled, e == null ? void 0 : e.debounceMs, e == null ? void 0 : e.maxWaitMs]), R(() => {
215
- i.current && c && i.current.onExportScheduled(c);
216
- }, [c]), R(() => {
217
- if (!r || !i.current)
218
- return;
219
- const o = r.onCommandExecuted(() => {
220
- if (i.current) {
221
- if (!l) {
222
- u.current = !0;
223
- return;
224
- }
225
- i.current.scheduleExport();
226
- }
227
- });
228
- return () => {
229
- o();
230
- };
231
- }, [r, l]), R(() => {
232
- if (i.current) {
233
- if (!l) {
234
- u.current = !0;
235
- return;
236
- }
237
- i.current.scheduleExport();
238
- }
239
- }, [t, a, l]), R(() => Be((d) => {
240
- if (!i.current || !l) return;
241
- t.some((y) => y.id === d) && i.current.scheduleExport();
242
- }), [t, l]);
243
- const v = z((o) => {
244
- i.current && i.current.updateConfig(o);
245
- }, []), g = z(async () => {
246
- i.current && (await i.current.forceExport(), m.current = i.current.getStats(), f(m.current));
247
- }, []), S = z(() => {
248
- i.current && (i.current.resetStats(), m.current = i.current.getStats(), f(m.current));
249
- }, []), p = z(() => {
250
- i.current && i.current.resetChangeDetection();
251
- }, []);
252
- return {
253
- stats: E,
254
- updateConfig: v,
255
- forceExport: g,
256
- resetStats: S,
257
- resetChangeDetection: p
258
- };
259
- }
260
- const Re = Q("useContentReady");
261
- function gt(n) {
262
- var r;
263
- const e = /* @__PURE__ */ new Set();
264
- for (const a of n)
265
- if ("fontFamily" in a && typeof a.fontFamily == "string" && a.fontFamily && e.add(a.fontFamily), "getRichText" in a && typeof a.getRichText == "function")
266
- try {
267
- const t = a.getRichText();
268
- if (t != null && t.spans)
269
- for (const s of t.spans)
270
- (r = s.style) != null && r.fontFamily && e.add(s.style.fontFamily);
271
- } catch {
272
- }
273
- return Array.from(e);
274
- }
275
- async function pt(n) {
276
- if (n.length === 0 || typeof document > "u" || !document.fonts) return;
277
- const e = [];
278
- for (const r of n) {
279
- const a = `16px "${r}"`;
280
- e.push(document.fonts.load(a));
281
- }
282
- await Promise.all(e), document.fonts.ready && await Promise.race([
283
- document.fonts.ready,
284
- new Promise((r) => setTimeout(r, 250))
285
- ]), Re.debug(`Awaited ${e.length} font(s)`);
286
- }
287
- function bt() {
288
- return new Promise((n) => requestAnimationFrame(() => n()));
289
- }
290
- function vt(n) {
291
- const { isCanvasReady: e, elements: r, hasInitialElements: a, initialElementsLoaded: t } = n, [s, c] = q(!1), l = F(!1);
292
- return R(() => {
293
- if (s || !e || a && !t || a && r.length === 0 || l.current) return;
294
- l.current = !0;
295
- let i = !1;
296
- return (async () => {
297
- try {
298
- const u = gt(r);
299
- if (u.length > 0 && (await pt(u), i) || (await bt(), i)) return;
300
- c(!0);
301
- } catch (u) {
302
- Re.error("Error during content readiness check:", u), i || c(!0);
303
- } finally {
304
- l.current = !1;
305
- }
306
- })(), () => {
307
- i = !0, l.current = !1;
308
- };
309
- }, [e, r, a, t, s]), s;
310
- }
311
- const Et = {
312
- // Vertical alignments (map to top/center/bottom center)
313
- "far-top": "t",
314
- top: "t",
315
- center: "c",
316
- bottom: "b",
317
- "far-bottom": "b",
318
- // Horizontal alignments (map to left/center/right middle)
319
- "far-left": "l",
320
- left: "l",
321
- right: "r",
322
- "far-right": "r",
323
- // Direct 9-point values
324
- tl: "tl",
325
- t: "t",
326
- tr: "tr",
327
- l: "l",
328
- c: "c",
329
- r: "r",
330
- bl: "bl",
331
- b: "b",
332
- br: "br"
333
- };
334
- function xt(n) {
335
- return n && Et[n] || "c";
336
- }
337
- function yt(n, e) {
338
- const r = e.scaleMode || "cover", a = (r === "contain" ? e.marginTop : 0) || 0, t = (r === "contain" ? e.marginRight : 0) || 0, s = (r === "contain" ? e.marginBottom : 0) || 0, c = (r === "contain" ? e.marginLeft : 0) || 0, l = e.width - c - t, i = e.height - a - s, u = l / n.width, m = i / n.height, E = r === "contain" ? Math.min(u, m) : Math.max(u, m), f = e.scale || 1, h = E * f, v = n.width * h, g = n.height * h, S = e.align || "c";
339
- let p = 0, o = 0;
340
- const d = v - l, x = g - i;
341
- switch (S) {
342
- // Top row
343
- case "tl":
344
- p = 0, o = 0;
345
- break;
346
- case "t":
347
- p = -d / 2, o = 0;
348
- break;
349
- case "tr":
350
- p = -d, o = 0;
351
- break;
352
- // Middle row
353
- case "l":
354
- p = 0, o = -x / 2;
355
- break;
356
- case "c":
357
- // Center (default)
358
- default:
359
- p = -d / 2, o = -x / 2;
360
- break;
361
- case "r":
362
- p = -d, o = -x / 2;
363
- break;
364
- // Bottom row
365
- case "bl":
366
- p = 0, o = -x;
367
- break;
368
- case "b":
369
- p = -d / 2, o = -x;
370
- break;
371
- case "br":
372
- p = -d, o = -x;
373
- break;
374
- }
375
- p += c, o += a;
376
- const y = e.offsetX || 0, A = e.offsetY || 0, b = d, M = x;
377
- return p += y * b, o += A * M, p = Math.round(p), o = Math.round(o), {
378
- // Final scale to apply to artwork
379
- scale: h,
380
- // Final artwork dimensions after scaling
381
- width: Math.round(v),
382
- height: Math.round(g),
383
- // Position to draw artwork (relative to artboard origin)
384
- x: p,
385
- y: o,
386
- // Debug info
387
- debug: {
388
- coverScale: E,
389
- userScale: f,
390
- overflow: { x: d, y: x },
391
- alignment: S,
392
- appliedOffset: { x: y * b, y: A * M }
393
- }
394
- };
395
- }
396
- const wt = {
397
- timeout: 3e4,
398
- retries: 1,
399
- retryDelay: 1e3,
400
- validateUrl: !0
401
- };
402
- function St(n) {
403
- try {
404
- const e = new URL(n);
405
- return ["http:", "https:", "data:", "blob:"].includes(e.protocol);
406
- } catch {
407
- return !1;
408
- }
409
- }
410
- async function At(n, e = {}) {
411
- const r = { ...wt, ...e };
412
- if (r.validateUrl && !St(n))
413
- return {
414
- success: !1,
415
- error: new Error(`Invalid image URL: ${n}`)
416
- };
417
- let a;
418
- for (let t = 0; t <= r.retries; t++)
419
- try {
420
- return await kt(n, r.timeout);
421
- } catch (s) {
422
- a = s instanceof Error ? s : new Error(String(s)), t < r.retries && await Rt(r.retryDelay);
423
- }
424
- return {
425
- success: !1,
426
- error: a || new Error("Failed to load image after retries")
427
- };
428
- }
429
- function kt(n, e) {
430
- return new Promise((r) => {
431
- const a = new Image();
432
- a.crossOrigin = "anonymous";
433
- let t = null, s = !1;
434
- const c = () => {
435
- t && (clearTimeout(t), t = null);
436
- }, l = () => {
437
- if (s) return;
438
- s = !0, c();
439
- const u = a.naturalWidth || a.width, m = a.naturalHeight || a.height;
440
- r({
441
- success: !0,
442
- element: a,
443
- width: u,
444
- height: m,
445
- aspectRatio: m > 0 ? u / m : 1
446
- });
447
- }, i = (u) => {
448
- s || (s = !0, c(), r({
449
- success: !1,
450
- error: new Error(u)
451
- }));
452
- };
453
- a.onload = l, a.onerror = () => {
454
- i(`Failed to load image: ${n}`);
455
- }, t = setTimeout(() => {
456
- i(`Image load timed out after ${e}ms: ${n}`);
457
- }, e), a.src = n;
458
- });
459
- }
460
- async function It(n, e, r = {}, a = {}) {
461
- var f, h, v, g, S, p, o;
462
- const t = await At(n, a);
463
- if (!t.success || !t.width || !t.height)
464
- return {
465
- success: !1,
466
- error: t.error || new Error("Failed to get image dimensions")
467
- };
468
- const s = {
469
- width: e.artboard.width,
470
- height: e.artboard.height,
471
- scale: e.scale,
472
- align: xt(e.alignment),
473
- offsetX: e.offsetX,
474
- offsetY: e.offsetY,
475
- scaleMode: e.scaleMode,
476
- marginTop: e.marginTop,
477
- marginRight: e.marginRight,
478
- marginBottom: e.marginBottom,
479
- marginLeft: e.marginLeft
480
- }, c = yt(
481
- { width: t.width, height: t.height },
482
- s
483
- ), l = e.artboard.x + c.x, i = e.artboard.y + c.y, u = l + c.width / 2, m = i + c.height / 2;
484
- return {
485
- success: !0,
486
- element: new De({
487
- ...r,
488
- x: u,
489
- y: m,
490
- imageUrl: n,
491
- imageAspectRatio: t.aspectRatio,
492
- preserveDimensions: !0,
493
- // Don't recalculate dimensions on image load
494
- transformData: {
495
- type: "image",
496
- width: c.width,
497
- height: c.height,
498
- cropX: ((f = r.transformData) == null ? void 0 : f.cropX) ?? 0,
499
- cropY: ((h = r.transformData) == null ? void 0 : h.cropY) ?? 0,
500
- cropWidth: ((v = r.transformData) == null ? void 0 : v.cropWidth) ?? 1,
501
- cropHeight: ((g = r.transformData) == null ? void 0 : g.cropHeight) ?? 1,
502
- flipHorizontal: ((S = r.transformData) == null ? void 0 : S.flipHorizontal) ?? !1,
503
- flipVertical: ((p = r.transformData) == null ? void 0 : p.flipVertical) ?? !1,
504
- borderRadius: ((o = r.transformData) == null ? void 0 : o.borderRadius) ?? 0
505
- }
506
- }),
507
- placement: {
508
- artworkSize: { width: t.width, height: t.height },
509
- finalSize: { width: c.width, height: c.height },
510
- position: { x: u, y: m },
511
- scale: c.scale
512
- }
513
- };
514
- }
515
- function Rt(n) {
516
- return new Promise((e) => setTimeout(e, n));
517
- }
518
- const _ = Q("SnowconeCanvas");
519
- function de(n, e, r, a) {
520
- if (a <= 0 || !isFinite(a))
521
- return r;
522
- const t = n * r, s = e * r;
523
- if (Math.max(t, s) <= a)
524
- return r;
525
- const l = Math.max(n, e), i = a / l;
526
- return Math.min(i, r);
527
- }
528
- function Ct(n) {
529
- const e = F(n);
530
- e.current = n;
531
- const r = z((t) => {
532
- var s;
533
- _.error(`[${t.category}] ${t.message}`, t.originalError), (s = e.current) == null || s.call(e, t);
534
- }, []);
535
- R(() => (ce.onRenderError = r, () => {
536
- ce.onRenderError === r && (ce.onRenderError = null);
537
- }), [r]);
538
- const a = z((t) => {
539
- r({
540
- category: "unknown",
541
- message: t.message,
542
- originalError: t,
543
- recoverable: !1
544
- });
545
- }, [r]);
546
- return { emitError: r, handleBoundaryError: a };
547
- }
548
- function Mt(n) {
549
- const {
550
- artboardConfigs: e,
551
- width: r,
552
- height: a,
553
- pieceGuides: t,
554
- controlledActiveArtboard: s,
555
- onArtboardChange: c,
556
- resetDocumentOnMount: l
557
- } = n, {
558
- setElements: i,
559
- setSelectedId: u,
560
- setMultiSelection: m,
561
- artboardManager: E,
562
- refreshArtboards: f
563
- } = ee(), { createArtboard: h, selectArtboard: v, artboards: g } = ue(), S = F(!1), p = F(!1);
564
- R(() => {
565
- if (S.current) return;
566
- S.current = !0;
567
- const o = e || [{ name: "Design", width: r, height: a }], d = t ? "transparent" : void 0, x = (A) => A.exportBackground ?? (!!A.backgroundColor && A.backgroundColor !== "transparent");
568
- if (l) {
569
- E.clear(), i([]), u(null), m([]);
570
- for (const b of o)
571
- E.createArtboard({
572
- name: b.name,
573
- width: b.width,
574
- height: b.height,
575
- backgroundColor: b.backgroundColor ?? d,
576
- exportBackground: x(b),
577
- clipShape: b.clipShape
578
- });
579
- const A = E.getAllArtboards();
580
- A.length > 0 && !s && E.setActiveArtboard(A[0].id), f();
581
- return;
582
- }
583
- const y = E.getAllArtboards();
584
- if (y.length > 0) {
585
- const A = o[0], b = y[0];
586
- b.name = A.name, b.width = A.width, b.height = A.height, b.clipShape = A.clipShape, b.exportBackground = x(A), A.backgroundColor ? b.backgroundColor = A.backgroundColor : d && (b.backgroundColor = d);
587
- for (let M = 1; M < o.length; M++)
588
- h(o[M].width, o[M].height, {
589
- name: o[M].name,
590
- backgroundColor: o[M].backgroundColor ?? d,
591
- exportBackground: x(o[M]),
592
- clipShape: o[M].clipShape
593
- });
594
- !s && o.length > 1 && E.setActiveArtboard(b.id);
595
- }
596
- f();
597
- }, []), R(() => {
598
- if (!s) {
599
- p.current = !0;
600
- return;
601
- }
602
- const o = g.find((d) => d.name === s);
603
- if (o) {
604
- const d = E.getActiveArtboard();
605
- (d == null ? void 0 : d.name) !== s && v(o.id), p.current = !0;
606
- }
607
- }, [s, g]), R(() => {
608
- if (!c || !p.current) return;
609
- const o = E.getActiveArtboard();
610
- o && c(o.name);
611
- }, [E.getActiveArtboardId()]);
612
- }
613
- function Ft(n) {
614
- const { initialElements: e, emitError: r } = n, { setElements: a, artboardManager: t } = ee(), s = F(!1), [c, l] = q(!1), i = F(!0);
615
- return R(() => (i.current = !0, () => {
616
- i.current = !1;
617
- }), []), R(() => {
618
- if (!(!e || e.length === 0) && !s.current) {
619
- s.current = !0, l(!0);
620
- try {
621
- const u = it.createManyFromJSON(e), m = t.getAllArtboards();
622
- if (m.length > 0) {
623
- const f = new Map(m.map((h) => [h.name, h]));
624
- u.forEach((h, v) => {
625
- var p;
626
- const g = (p = e[v]) == null ? void 0 : p.artboard, S = g && f.get(g) || m[0];
627
- t.addElementToArtboard(h.id, S.id);
628
- });
629
- }
630
- a(u);
631
- const E = /* @__PURE__ */ new Set();
632
- for (const f of u) {
633
- const h = f.fontFamily;
634
- typeof h == "string" && h.trim().length > 0 && E.add(h);
635
- }
636
- if (E.size > 0 && typeof document < "u") {
637
- const f = document.fonts ?? null, h = Array.from(E).map((v) => {
638
- const g = `font-${v.replace(/\s+/g, "-").toLowerCase()}`;
639
- let S = document.getElementById(g);
640
- return S || (S = document.createElement("link"), S.id = g, S.rel = "stylesheet", S.href = `https://fonts.googleapis.com/css2?family=${v.replace(
641
- /\s+/g,
642
- "+"
643
- )}:wght@400;700&display=swap`, document.head.appendChild(S)), new Promise((p) => {
644
- if (S.sheet) {
645
- p(v);
646
- return;
647
- }
648
- const o = () => p(v);
649
- S.addEventListener("load", o, { once: !0 }), S.addEventListener("error", o, { once: !0 }), setTimeout(o, 4e3);
650
- });
651
- });
652
- Promise.all(h).then((v) => {
653
- if (!(!i.current || !f))
654
- return Promise.all(
655
- v.flatMap((g) => [
656
- f.load(`400 16px "${g}"`).catch(() => {
657
- }),
658
- f.load(`700 16px "${g}"`).catch(() => {
659
- })
660
- ])
661
- );
662
- }).then(() => {
663
- i.current && a((v) => v.slice());
664
- });
665
- }
666
- } catch (u) {
667
- _.error("Failed to load initial elements:", u);
668
- const m = u instanceof Error ? u : new Error(String(u));
669
- r({
670
- category: "import",
671
- message: `Failed to load initial elements: ${m.message}`,
672
- originalError: m,
673
- recoverable: !0
674
- });
675
- }
676
- }
677
- }, [e, t, a, r]), { initialElementsLoadedState: c };
678
- }
679
- function Nt(n) {
680
- const {
681
- initialImage: e,
682
- initialImageAlignment: r,
683
- initialImageScale: a,
684
- initialImageScaleMode: t,
685
- artboardConfigs: s,
686
- onImageLoad: c,
687
- onImageError: l,
688
- emitError: i
689
- } = n, { elements: u, setElements: m, artboardManager: E } = ee(), [f, h] = q("idle"), [v, g] = q(null), S = F(void 0);
690
- return R(() => {
691
- if (!e || S.current === e) return;
692
- if (u.length > 0) {
693
- S.current = e;
694
- return;
695
- }
696
- S.current = e, (async () => {
697
- h("loading"), g(null);
698
- try {
699
- const o = E.getAllArtboards();
700
- if (o.length === 0)
701
- throw new Error("No artboards available");
702
- const d = [];
703
- for (const x of o) {
704
- const y = s == null ? void 0 : s.find((M) => M.name === x.name), A = (y == null ? void 0 : y.scaleMode) || t, b = await It(
705
- e,
706
- {
707
- artboard: {
708
- width: x.width,
709
- height: x.height,
710
- x: x.x,
711
- y: x.y
712
- },
713
- alignment: (y == null ? void 0 : y.fitAlign) || r,
714
- scale: a,
715
- scaleMode: A,
716
- marginTop: y == null ? void 0 : y.fitMarginTop,
717
- marginRight: y == null ? void 0 : y.fitMarginRight,
718
- marginBottom: y == null ? void 0 : y.fitMarginBottom,
719
- marginLeft: y == null ? void 0 : y.fitMarginLeft
720
- }
721
- );
722
- b.success && b.element ? (E.addElementToArtboard(b.element.id, x.id), d.push(b.element)) : _.error("Failed to load image for artboard:", x.name, b.error);
723
- }
724
- if (d.length > 0)
725
- m((x) => [...x, ...d]), h("success"), c == null || c(e);
726
- else {
727
- const x = new Error("Failed to load image into any artboard");
728
- h("error"), g(x), l == null || l(e, x), i({
729
- category: "image",
730
- message: x.message,
731
- originalError: x,
732
- recoverable: !0
733
- });
734
- }
735
- } catch (o) {
736
- const d = o instanceof Error ? o : new Error(String(o));
737
- h("error"), g(d), l == null || l(e, d), i({
738
- category: "image",
739
- message: d.message,
740
- originalError: d,
741
- recoverable: !0
742
- });
743
- }
744
- })();
745
- }, [e, r, a, t]), { imageLoadingState: f, imageError: v };
746
- }
747
- function Lt(n) {
748
- const { onChange: e, onSelectionChange: r } = n, { elements: a, selectedId: t, artboardManager: s } = ee(), { artboards: c } = ue(), l = F(r);
749
- l.current = r, R(() => {
750
- var u;
751
- (u = l.current) == null || u.call(l, t);
752
- }, [t]);
753
- const i = F(e);
754
- i.current = e, R(() => {
755
- const u = i.current;
756
- if (!u) return;
757
- const m = s.getActiveArtboard(), E = {
758
- // Stamp each element with the NAME of the artboard it lives on (the
759
- // manager is the membership source of truth). Without this the public
760
- // state is flat and a multi-placement design cannot round-trip: restore
761
- // collapses everything onto the first artboard, and per-placement render
762
- // states can't be derived from onChange. Pinned by
763
- // SnowconeCanvas.artboard-membership.test.tsx.
764
- elements: a.map((f) => {
765
- const h = f.toJSON(), v = s.getArtboardForElement(f.id);
766
- return v ? { ...h, artboard: v.name } : h;
767
- }),
768
- artboards: c.map((f) => ({
769
- name: f.name,
770
- width: f.width,
771
- height: f.height,
772
- clipShape: f.clipShape,
773
- backgroundColor: f.backgroundColor,
774
- // Carried so serializeStateForServer / saved states keep an
775
- // explicitly-set background renderable (mockup matches editor).
776
- exportBackground: f.exportBackground
777
- })),
778
- activeArtboard: (m == null ? void 0 : m.name) || "Design"
779
- };
780
- u(E);
781
- }, [a, c]);
782
- }
783
- function Tt(n, e) {
784
- const {
785
- autoExportInterval: r,
786
- autoExportConfig: a,
787
- autoExportFormat: t,
788
- autoExportAll: s,
789
- exportScale: c,
790
- maxExportSize: l,
791
- exportImageFormat: i,
792
- exportImageQuality: u,
793
- onExport: m,
794
- onExportScheduled: E,
795
- onExportStatus: f,
796
- onExportReady: h,
797
- onReady: v,
798
- hasInitialElements: g,
799
- initialElementsLoaded: S,
800
- emitError: p
801
- } = n, {
802
- elements: o,
803
- artboardManager: d,
804
- historyManager: x,
805
- isCanvasReady: y,
806
- setCanvasReady: A
807
- } = ee(), { artboards: b } = ue(), { exportArtboard: M, exportAllArtboards: X, exportArtboardAsBlob: O, exportAllArtboardsAsBlobs: j } = rt(), ne = F(0), ae = F(0);
808
- $e(e, () => ({
809
- exportArtboards: async (L = {}) => {
810
- const T = L.format || t, P = L.scale || c, $ = L.all ?? !1;
811
- let B = P;
812
- if (l > 0 && isFinite(l))
813
- for (const C of b) {
814
- const I = de(C.width, C.height, P, l);
815
- B = Math.min(B, I);
816
- }
817
- const k = { scale: B, format: i, quality: u };
818
- if ($) {
819
- const C = T === "blob" ? await j(k) : await X(k), I = {};
820
- for (const [N, U] of Object.entries(C)) {
821
- const D = b.find((K) => K.id === N);
822
- D && (I[D.name] = U);
823
- }
824
- return I;
825
- } else {
826
- const C = d.getActiveArtboard();
827
- if (!C)
828
- throw new Error("[SnowconeCanvas] No active artboard found");
829
- if (T === "blob") {
830
- const I = await O(C.id, k);
831
- return { [C.name]: I };
832
- } else {
833
- const I = await M(C.id, k);
834
- return { [C.name]: I };
835
- }
836
- }
837
- }
838
- }), [M, X, O, j, t, c, l, i, u, d, b]), R(() => {
839
- h && h(async () => {
840
- const T = d.getActiveArtboard();
841
- if (!T)
842
- throw new Error("[SnowconeCanvas] No active artboard found");
843
- const P = de(
844
- T.width,
845
- T.height,
846
- c,
847
- l
848
- ), $ = t === "blob" ? await O(T.id, { scale: P }) : await M(T.id, { scale: P });
849
- return { [T.name]: $ };
850
- });
851
- }, [h, M, O, d, t, c, l]);
852
- const oe = z(async () => {
853
- if (!m && !f) return;
854
- const L = ++ae.current, T = Date.now();
855
- let P = c;
856
- if (l > 0 && isFinite(l))
857
- for (const k of b) {
858
- const C = de(k.width, k.height, c, l);
859
- P = Math.min(P, C);
860
- }
861
- const $ = d.getActiveArtboard(), B = ($ == null ? void 0 : $.id) ?? "unknown";
862
- f == null || f({ status: "rendering", artboardId: B }), ne.current = T;
863
- try {
864
- let k;
865
- const C = {
866
- format: i,
867
- scale: P,
868
- quality: u
869
- };
870
- if (t === "blob")
871
- if (s) {
872
- const I = await j(C);
873
- k = {};
874
- for (const [N, U] of Object.entries(I)) {
875
- const D = b.find((K) => K.id === N);
876
- D && (k[D.name] = U);
877
- }
878
- } else {
879
- const I = d.getActiveArtboard();
880
- if (!I) return;
881
- const N = await O(I.id, C);
882
- k = { [I.name]: N };
883
- }
884
- else if (s) {
885
- const I = await X(C);
886
- k = {};
887
- for (const [N, U] of Object.entries(I)) {
888
- const D = b.find((K) => K.id === N);
889
- D && (k[D.name] = U);
890
- }
891
- } else {
892
- const I = d.getActiveArtboard();
893
- if (!I) return;
894
- const N = await M(I.id, C);
895
- k = { [I.name]: N };
896
- }
897
- m == null || m(k), f == null || f({ status: "complete", artboardId: B, result: k });
898
- } catch (k) {
899
- const C = k instanceof Error ? k.message : String(k);
900
- if (C.includes("Canvas ref not available"))
901
- return;
902
- const I = Date.now() - T;
903
- _.error("Export failed (export #" + L + "):", {
904
- duration: `${I}ms`,
905
- error: C
906
- });
907
- const N = k instanceof Error ? k : new Error(C);
908
- f == null || f({ status: "error", artboardId: B, error: N }), p({
909
- category: "export",
910
- message: N.message,
911
- originalError: N,
912
- artboardId: B,
913
- recoverable: !0
914
- });
915
- }
916
- }, [m, f, s, t, c, l, i, u, M, X, O, j, b, d, o, a, p]);
917
- R(() => {
918
- r !== void 0 && r > 0 && _.warn(
919
- "autoExportInterval is deprecated and ignored. Use autoExportConfig={{ enabled: true, debounceMs: 100, maxWaitMs: 1000 }} instead."
920
- );
921
- }, []);
922
- const se = z(() => {
923
- if (E == null || E(), f) {
924
- const L = d.getActiveArtboard();
925
- f({ status: "scheduled", artboardId: (L == null ? void 0 : L.id) ?? "unknown" });
926
- }
927
- }, [E, f, d]), J = vt({
928
- isCanvasReady: y,
929
- elements: o,
930
- hasInitialElements: g,
931
- initialElementsLoaded: S
932
- }), te = F(!1);
933
- R(() => {
934
- J && !te.current && (te.current = !0, v == null || v());
935
- }, [J, v]), ht({
936
- config: a ? {
937
- enabled: a.enabled ?? !0,
938
- debounceMs: a.debounceMs ?? 100,
939
- maxWaitMs: a.maxWaitMs ?? 1e3
940
- } : {
941
- enabled: !1
942
- // Only use smart export if autoExportConfig is provided
943
- },
944
- historyManager: x,
945
- artboards: b,
946
- elements: o,
947
- onExport: oe,
948
- onExportScheduled: se,
949
- isCanvasReady: J
950
- // Gate exports until content is fully ready (fonts loaded, elements deserialized)
951
- }), R(() => {
952
- if (b.length > 0 && !y) {
953
- const L = requestAnimationFrame(() => {
954
- A(!0);
955
- });
956
- return () => cancelAnimationFrame(L);
957
- }
958
- }, [b.length, y, A]), R(() => () => {
959
- A(!1);
960
- }, [A]);
961
- }
962
- const we = Q("SnowconeCanvas"), Ce = ke((n, e) => {
963
- var be;
964
- const {
965
- exportConfig: r,
966
- imageConfig: a,
967
- layoutConfig: t,
968
- kit: s,
969
- artboards: c,
970
- activeArtboard: l,
971
- onArtboardChange: i,
972
- initialElements: u,
973
- onChange: m,
974
- onSelectionChange: E,
975
- autoExportInterval: f,
976
- onExport: h,
977
- onExportScheduled: v,
978
- onExportStatus: g,
979
- onExportReady: S,
980
- onImageLoad: p,
981
- onImageError: o,
982
- onError: d,
983
- onReady: x,
984
- className: y,
985
- style: A,
986
- enableShortcuts: b,
987
- overlay: M,
988
- resetDocumentOnMount: X
989
- } = n, O = f, j = n.autoExportConfig ?? (r == null ? void 0 : r.autoExportConfig), ne = n.autoExportFormat ?? (r == null ? void 0 : r.format) ?? "dataUrl", ae = n.autoExportAll ?? (r == null ? void 0 : r.exportAll) ?? !1, oe = n.exportScale ?? (r == null ? void 0 : r.scale) ?? 2, se = n.maxExportSize ?? (r == null ? void 0 : r.maxSize) ?? 4e3, J = n.exportImageFormat ?? (r == null ? void 0 : r.imageFormat) ?? "png", te = n.exportImageQuality ?? (r == null ? void 0 : r.imageQuality) ?? 0.92, L = n.initialImage ?? (a == null ? void 0 : a.src), T = n.initialImageAlignment ?? (a == null ? void 0 : a.alignment) ?? "center", P = n.initialImageScale ?? (a == null ? void 0 : a.scale) ?? 1, $ = n.initialImageScaleMode ?? (a == null ? void 0 : a.scaleMode) ?? "cover", B = n.width ?? (t == null ? void 0 : t.width) ?? 1200, k = n.height ?? (t == null ? void 0 : t.height) ?? 1200, C = n.viewPadding ?? (t == null ? void 0 : t.viewPadding) ?? 0.9, I = n.artboardBorderRadius ?? (t == null ? void 0 : t.artboardBorderRadius) ?? 0, N = n.fixedMargin ?? (t == null ? void 0 : t.fixedMargin), U = n.maxHeight ?? (t == null ? void 0 : t.maxHeight), D = n.showRotationHandle ?? (t == null ? void 0 : t.showRotationHandle) ?? !0, K = n.hideCanvas ?? (t == null ? void 0 : t.hideCanvas) ?? !1, fe = n.canvasWrapperClassName ?? (t == null ? void 0 : t.canvasWrapperClassName), me = n.canvasWrapperStyle ?? (t == null ? void 0 : t.canvasWrapperStyle), Me = n.canvasCutouts ?? (t == null ? void 0 : t.canvasCutouts), he = n.pieceGuides, Fe = n.pieceFocus, Ne = b ?? !0, Y = Ae(() => Qe(s ?? "pro-studio"), [s]);
990
- R(() => {
991
- var H;
992
- if (typeof G < "u" && ((H = G.env) == null ? void 0 : H.NODE_ENV) === "development" && Y) {
993
- const W = Je(Y);
994
- W.valid || we.warn("Kit validation warnings:", W.errors), W.warnings.length > 0 && we.warn("Kit validation warnings:", W.warnings);
995
- }
996
- }, [Y]);
997
- const { emitError: ie, handleBoundaryError: Le } = Ct(d);
998
- Mt({
999
- artboardConfigs: c,
1000
- width: B,
1001
- height: k,
1002
- pieceGuides: he,
1003
- controlledActiveArtboard: l,
1004
- onArtboardChange: i,
1005
- resetDocumentOnMount: X
1006
- });
1007
- const { initialElementsLoadedState: Te } = Ft({
1008
- initialElements: u,
1009
- emitError: ie
1010
- }), { imageLoadingState: ge, imageError: pe } = Nt({
1011
- initialImage: L,
1012
- initialImageAlignment: T,
1013
- initialImageScale: P,
1014
- initialImageScaleMode: $,
1015
- artboardConfigs: c,
1016
- onImageLoad: p,
1017
- onImageError: o,
1018
- emitError: ie
1019
- });
1020
- if (Lt({ onChange: m, onSelectionChange: E }), Tt(
1021
- {
1022
- autoExportInterval: O,
1023
- autoExportConfig: j,
1024
- autoExportFormat: ne,
1025
- autoExportAll: ae,
1026
- exportScale: oe,
1027
- maxExportSize: se,
1028
- exportImageFormat: J,
1029
- exportImageQuality: te,
1030
- onExport: h,
1031
- onExportScheduled: v,
1032
- onExportStatus: g,
1033
- onExportReady: S,
1034
- onReady: x,
1035
- hasInitialElements: !!u && u.length > 0,
1036
- initialElementsLoaded: Te,
1037
- emitError: ie
1038
- },
1039
- e
1040
- ), ge === "loading")
1041
- return /* @__PURE__ */ w(
1042
- "div",
1043
- {
1044
- className: y,
1045
- style: {
1046
- ...A,
1047
- display: "flex",
1048
- alignItems: "center",
1049
- justifyContent: "center",
1050
- backgroundColor: "var(--surface, #f5f5f5)"
1051
- },
1052
- children: /* @__PURE__ */ w(Ze, { size: 48 })
1053
- }
1054
- );
1055
- if (ge === "error" && pe)
1056
- return /* @__PURE__ */ w(
1057
- "div",
1058
- {
1059
- className: y,
1060
- style: {
1061
- ...A,
1062
- display: "flex",
1063
- alignItems: "center",
1064
- justifyContent: "center",
1065
- backgroundColor: "var(--surface, #f5f5f5)",
1066
- color: "var(--danger, #dc2626)",
1067
- padding: "1rem"
1068
- },
1069
- children: /* @__PURE__ */ V("div", { className: "sc:text-center", children: [
1070
- /* @__PURE__ */ w("div", { className: "sc:font-medium", children: "Failed to load image" }),
1071
- /* @__PURE__ */ w("div", { className: "sc:text-sm sc:mt-1 sc:opacity-70", children: pe.message })
1072
- ] })
1073
- }
1074
- );
1075
- const Pe = Object.entries(((be = Y.layout) == null ? void 0 : be.slots) ?? {}).every(
1076
- ([H, W]) => H === "canvas" || !W || W.length === 0
1077
- ) ? { "--color-canvas-bg": "transparent" } : void 0;
1078
- return /* @__PURE__ */ w(qe, { kit: Y, children: /* @__PURE__ */ w("div", { className: `sc-root ${y || ""}`, style: { ...Pe, ...A, position: "relative" }, children: /* @__PURE__ */ V(
1079
- ut,
1080
- {
1081
- onError: Le,
1082
- fallback: (H, W) => /* @__PURE__ */ V(
1083
- "div",
1084
- {
1085
- style: {
1086
- display: "flex",
1087
- flexDirection: "column",
1088
- alignItems: "center",
1089
- justifyContent: "center",
1090
- padding: "24px",
1091
- minHeight: "200px",
1092
- backgroundColor: "var(--surface, #f5f5f5)",
1093
- color: "var(--foreground, #333)",
1094
- fontFamily: "system-ui, sans-serif",
1095
- textAlign: "center"
1096
- },
1097
- children: [
1098
- /* @__PURE__ */ w("div", { style: { fontSize: "18px", fontWeight: 600, marginBottom: "8px" }, children: "Something went wrong" }),
1099
- /* @__PURE__ */ w("div", { style: { fontSize: "14px", opacity: 0.7, marginBottom: "16px", maxWidth: "400px" }, children: H.message }),
1100
- /* @__PURE__ */ w(
1101
- "button",
1102
- {
1103
- onClick: W,
1104
- style: {
1105
- padding: "8px 20px",
1106
- backgroundColor: "var(--primary, #333)",
1107
- color: "var(--primary-foreground, #fff)",
1108
- border: "none",
1109
- borderRadius: "6px",
1110
- fontSize: "14px",
1111
- fontWeight: 500,
1112
- cursor: "pointer"
1113
- },
1114
- children: "Try again"
1115
- }
1116
- )
1117
- ]
1118
- }
1119
- ),
1120
- children: [
1121
- !K && /* @__PURE__ */ (() => {
1122
- const H = /* @__PURE__ */ w(
1123
- _e,
1124
- {
1125
- style: { width: "100%" },
1126
- fitPadding: C,
1127
- artboardBorderRadius: I,
1128
- fixedMargin: N,
1129
- maxHeight: U,
1130
- showRotationHandle: D,
1131
- enableShortcuts: Ne,
1132
- canvasCutouts: Me,
1133
- pieceGuides: he,
1134
- pieceFocus: Fe
1135
- }
1136
- );
1137
- return /* @__PURE__ */ w(lt, { kit: Y, canvas: fe || me ? /* @__PURE__ */ w("div", { className: fe, style: me, children: H }) : H });
1138
- })(),
1139
- M
1140
- ]
1141
- }
1142
- ) }) });
1143
- });
1144
- Ce.displayName = "SnowconeCanvasInner";
1145
- const Pt = ke((n, e) => {
1146
- var c;
1147
- const { inheritTheme: r, externalProvider: a, services: t } = n, s = n.viewPadding ?? ((c = n.layoutConfig) == null ? void 0 : c.viewPadding);
1148
- return /* @__PURE__ */ w(
1149
- ft,
1150
- {
1151
- inheritTheme: r,
1152
- externalProvider: a,
1153
- services: t,
1154
- viewPadding: s,
1155
- children: /* @__PURE__ */ w(Ce, { ref: e, ...n })
1156
- }
1157
- );
1158
- });
1159
- Pt.displayName = "SnowconeCanvas";
1160
- export {
1161
- ut as E,
1162
- Pt as S,
1163
- vt as a,
1164
- ht as u
1165
- };
1166
- //# sourceMappingURL=SnowconeCanvas-3PA17na3.js.map