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