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