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