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