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