@snowcone-app/canvas 0.41.4 → 0.41.5

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