@snowcone-app/canvas 0.40.19 → 0.40.21

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