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