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