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