@snowcone-app/canvas 0.46.3 → 0.46.5
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/{CanvasRenderer-B8BADU_r.js → CanvasRenderer-CmIQSVCK.js} +4 -4
- package/dist/{CanvasRenderer-B8BADU_r.js.map → CanvasRenderer-CmIQSVCK.js.map} +1 -1
- package/dist/{ContextualToolbars-5tHC6s0Y.js → ContextualToolbars-Dmo86Wd2.js} +323 -322
- package/dist/{ContextualToolbars-5tHC6s0Y.js.map → ContextualToolbars-Dmo86Wd2.js.map} +1 -1
- package/dist/{EditorCanvasImpl-CrP9FSoY.js → EditorCanvasImpl-BHa8q4iO.js} +16 -15
- package/dist/{EditorCanvasImpl-CrP9FSoY.js.map → EditorCanvasImpl-BHa8q4iO.js.map} +1 -1
- package/dist/{ExportManager-xRsXgyNo.js → ExportManager-DEJgxB0S.js} +79 -78
- package/dist/{ExportManager-xRsXgyNo.js.map → ExportManager-DEJgxB0S.js.map} +1 -1
- package/dist/{FontAnalyzer-Ds3Wdba7.js → FontAnalyzer-CLMJi2Sw.js} +374 -409
- package/dist/FontAnalyzer-CLMJi2Sw.js.map +1 -0
- package/dist/{ImagePanel-bW3yr6Ac.js → ImagePanel-4fHABjNT.js} +6 -6
- package/dist/{ImagePanel-bW3yr6Ac.js.map → ImagePanel-4fHABjNT.js.map} +1 -1
- package/dist/{SnowconeCanvas-crxPwbib.js → SnowconeCanvas-GPag5BXG.js} +10 -10
- package/dist/{SnowconeCanvas-crxPwbib.js.map → SnowconeCanvas-GPag5BXG.js.map} +1 -1
- package/dist/advanced.mjs +54 -54
- package/dist/core/image-adjustments.d.ts +2 -4
- package/dist/core/masked-crop.d.ts +3 -55
- package/dist/{custom-icons-DQRp8GhF.js → custom-icons-Dt0Y4VSn.js} +2 -2
- package/dist/{custom-icons-DQRp8GhF.js.map → custom-icons-Dt0Y4VSn.js.map} +1 -1
- package/dist/design-builder-HKRo18WT.js +1798 -0
- package/dist/design-builder-HKRo18WT.js.map +1 -0
- package/dist/{embed-D0f-YvCl.js → embed-DhjsJ3ni.js} +10 -10
- package/dist/{embed-D0f-YvCl.js.map → embed-DhjsJ3ni.js.map} +1 -1
- package/dist/embed.mjs +35 -36
- package/dist/embed.mjs.map +1 -1
- package/dist/{export-worker.bundle.string-BL30CYzH.js → export-worker.bundle.string-CyMb_XjB.js} +27 -25
- package/dist/{export-worker.bundle.string-BL30CYzH.js.map → export-worker.bundle.string-CyMb_XjB.js.map} +1 -1
- package/dist/{guards-DwYEoqcn.js → guards-Dk86a-kH.js} +2 -2
- package/dist/{guards-DwYEoqcn.js.map → guards-Dk86a-kH.js.map} +1 -1
- package/dist/index.mjs +43 -43
- package/dist/internals.mjs +150 -149
- package/dist/internals.mjs.map +1 -1
- package/dist/rendering/serialize-for-server.d.ts +4 -91
- package/dist/state/CanvasStateV1.d.ts +1 -363
- package/dist/{CanvasStateV1-BlDWgOzV.js → template-fields-CKEuUmTM.js} +1997 -1835
- package/dist/template-fields-CKEuUmTM.js.map +1 -0
- package/dist/testing.mjs +61 -60
- package/dist/testing.mjs.map +1 -1
- package/dist/{useCommands-F-b_SwW-.js → useCommands-BI7O5Lf0.js} +225 -225
- package/dist/{useCommands-F-b_SwW-.js.map → useCommands-BI7O5Lf0.js.map} +1 -1
- package/dist/{usePieceGuideBundle-BWdobHQE.js → usePieceGuideBundle-DJfjOVEd.js} +2 -2
- package/dist/{usePieceGuideBundle-BWdobHQE.js.map → usePieceGuideBundle-DJfjOVEd.js.map} +1 -1
- package/dist/utils/custom-fonts.d.ts +2 -16
- package/dist/{validation-hn5ZX8Po.js → validation-au_-Sj-A.js} +11 -11
- package/dist/{validation-hn5ZX8Po.js.map → validation-au_-Sj-A.js.map} +1 -1
- package/dist/workers/export-worker.bundle.string.d.ts +1 -1
- package/example/package.json +1 -1
- package/package.json +3 -2
- package/dist/CanvasStateV1-BlDWgOzV.js.map +0 -1
- package/dist/FontAnalyzer-Ds3Wdba7.js.map +0 -1
- package/dist/design-builder-sH53Og6j.js +0 -1870
- package/dist/design-builder-sH53Og6j.js.map +0 -1
- package/dist/template-fields-BaQG0CJY.js +0 -559
- package/dist/template-fields-BaQG0CJY.js.map +0 -1
|
@@ -0,0 +1,1798 @@
|
|
|
1
|
+
import { jsx as _ } from "react/jsx-runtime";
|
|
2
|
+
import { useContext as K, useSyncExternalStore as bt, useCallback as h, createContext as q, useRef as ge, useState as S, useEffect as ke, useMemo as j } from "react";
|
|
3
|
+
import { H as Et, q as te, U as St, y as Rt, G as qe, R as It, z as Tt, D as Ct, B as Ft, J as vt, c as Qe, K as Pt, M as Ot, N as Nt, I as _e, O as zt, e as Ut, E as Ye, o as Dt, S as Ht, Q as Xe, V as Lt, X as Ke, Y as Vt, Z as _t } from "./FontAnalyzer-CLMJi2Sw.js";
|
|
4
|
+
import { g as et, a as tt } from "./placement-tSiIVhrL.js";
|
|
5
|
+
import { serializeStateForServer as $t } from "@snowcone-app/design/wire";
|
|
6
|
+
const ot = q(null), kt = () => () => {
|
|
7
|
+
}, Ge = () => 0;
|
|
8
|
+
function Co() {
|
|
9
|
+
const t = K(ot), e = bt(
|
|
10
|
+
t ? t.subscribe : kt,
|
|
11
|
+
t ? t.getVersion : Ge,
|
|
12
|
+
t ? t.getVersion : Ge
|
|
13
|
+
);
|
|
14
|
+
return h(
|
|
15
|
+
(o) => !!(t && o && t.getBoundLayer(o)),
|
|
16
|
+
// `version` is the reactivity key: a registry change must mint a new
|
|
17
|
+
// callback so memoized consumers re-evaluate.
|
|
18
|
+
[t, e]
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const we = Qe("useCommandHistory");
|
|
22
|
+
function Bt(t, e, o, n) {
|
|
23
|
+
const i = ge(new Et(o)), r = K(ot), a = h(
|
|
24
|
+
(u, g) => {
|
|
25
|
+
const b = u == null ? void 0 : u.name;
|
|
26
|
+
if (!r || !b) return;
|
|
27
|
+
const A = r.getBoundLayer(b);
|
|
28
|
+
if (A)
|
|
29
|
+
throw new te(
|
|
30
|
+
"E_BOUND_LAYER_MUTATION",
|
|
31
|
+
`cannot ${g} layer "${b}" — a mounted <${A.part} layer={design.layer("${b}")}> is bound to it. Unmount that field first, or keep the layer and set its text through the field / its binding instead.`,
|
|
32
|
+
{ layer: b, part: A.part, operation: g, docSlug: "embed-mode" }
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
[r]
|
|
36
|
+
), [s, d] = S({
|
|
37
|
+
canUndo: !1,
|
|
38
|
+
canRedo: !1,
|
|
39
|
+
// Per-artboard state for the active artboard
|
|
40
|
+
canUndoActiveArtboard: !1,
|
|
41
|
+
canRedoActiveArtboard: !1
|
|
42
|
+
}), c = h(() => {
|
|
43
|
+
const u = i.current, g = o.getActiveArtboardId();
|
|
44
|
+
d({
|
|
45
|
+
canUndo: u.canUndo(),
|
|
46
|
+
canRedo: u.canRedo(),
|
|
47
|
+
// Per-artboard state - only check active artboard's history
|
|
48
|
+
canUndoActiveArtboard: g ? u.canUndoArtboard(g) : !1,
|
|
49
|
+
canRedoActiveArtboard: g ? u.canRedoArtboard(g) : !1
|
|
50
|
+
});
|
|
51
|
+
}, [o]), R = h(
|
|
52
|
+
(u, g) => {
|
|
53
|
+
u && u.name !== g.name && a(u, "rename");
|
|
54
|
+
const b = new St(
|
|
55
|
+
g.id,
|
|
56
|
+
u || null,
|
|
57
|
+
g,
|
|
58
|
+
(F) => {
|
|
59
|
+
e((Y) => Y.map((z) => z.id === F.id ? F : z));
|
|
60
|
+
}
|
|
61
|
+
), A = o.getArtboardIdForElement(g.id);
|
|
62
|
+
if (A)
|
|
63
|
+
i.current.executeOnArtboard(A, b);
|
|
64
|
+
else {
|
|
65
|
+
const F = o.getActiveArtboardId();
|
|
66
|
+
F && i.current.executeOnArtboard(F, b);
|
|
67
|
+
}
|
|
68
|
+
c();
|
|
69
|
+
},
|
|
70
|
+
[e, o, c, a]
|
|
71
|
+
), O = h(
|
|
72
|
+
(u, g, b, A) => {
|
|
73
|
+
const F = g || o.getActiveArtboardId();
|
|
74
|
+
if (!F) {
|
|
75
|
+
we.warn("No active artboard to add element to");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const Y = new Rt(
|
|
79
|
+
u,
|
|
80
|
+
(z) => {
|
|
81
|
+
const $ = z;
|
|
82
|
+
e((U) => {
|
|
83
|
+
if (A) {
|
|
84
|
+
const V = U.findIndex((P) => P.id === A);
|
|
85
|
+
if (V !== -1) {
|
|
86
|
+
const P = [...U];
|
|
87
|
+
return P.splice(V, 0, $), P;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (b) {
|
|
91
|
+
const V = U.findIndex((P) => P.id === b);
|
|
92
|
+
if (V !== -1) {
|
|
93
|
+
const P = [...U];
|
|
94
|
+
return P.splice(V + 1, 0, $), P;
|
|
95
|
+
}
|
|
96
|
+
for (let P = 0; P < U.length; P++) {
|
|
97
|
+
const G = U[P];
|
|
98
|
+
if (G instanceof qe && G.children) {
|
|
99
|
+
const ne = G.children.findIndex((Z) => Z.id === b);
|
|
100
|
+
if (ne !== -1) {
|
|
101
|
+
const Z = G.clone();
|
|
102
|
+
Z.children.splice(ne + 1, 0, $);
|
|
103
|
+
const k = [...U];
|
|
104
|
+
return k[P] = Z, k;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return [...U, $];
|
|
110
|
+
}), o.addElementToArtboard(z.id, F);
|
|
111
|
+
},
|
|
112
|
+
(z) => {
|
|
113
|
+
e(($) => $.filter((U) => U.id !== z)), o.removeElementFromArtboard(z);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
i.current.executeOnArtboard(F, Y), c();
|
|
117
|
+
},
|
|
118
|
+
[e, o, c]
|
|
119
|
+
), H = h(
|
|
120
|
+
(u) => {
|
|
121
|
+
a(u, "delete");
|
|
122
|
+
const g = o.getArtboardIdForElement(u.id);
|
|
123
|
+
if (!g) {
|
|
124
|
+
we.warn("Element not found in any artboard");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const b = new It(
|
|
128
|
+
u,
|
|
129
|
+
(A) => {
|
|
130
|
+
e((F) => [...F, A]), o.addElementToArtboard(A.id, g);
|
|
131
|
+
},
|
|
132
|
+
(A) => {
|
|
133
|
+
e((F) => F.filter((Y) => Y.id !== A)), o.removeElementFromArtboard(A);
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
i.current.executeOnArtboard(g, b), c();
|
|
137
|
+
},
|
|
138
|
+
[e, o, c, a]
|
|
139
|
+
), x = h(
|
|
140
|
+
(u) => {
|
|
141
|
+
const g = new Tt(u, o);
|
|
142
|
+
i.current.executeGlobal(g), c(), n == null || n();
|
|
143
|
+
},
|
|
144
|
+
[o, c, n]
|
|
145
|
+
), L = h(
|
|
146
|
+
(u) => {
|
|
147
|
+
const g = new Ct(u, o);
|
|
148
|
+
i.current.executeGlobal(g), c(), n == null || n();
|
|
149
|
+
},
|
|
150
|
+
[o, c, n]
|
|
151
|
+
), p = h(
|
|
152
|
+
(u, g, b) => {
|
|
153
|
+
const A = new Ft(u, g, b, o);
|
|
154
|
+
i.current.executeGlobal(A), c(), n == null || n();
|
|
155
|
+
},
|
|
156
|
+
[o, c, n]
|
|
157
|
+
), m = h(
|
|
158
|
+
(u) => {
|
|
159
|
+
if (u.length === 0)
|
|
160
|
+
return;
|
|
161
|
+
const g = o.getActiveArtboardId();
|
|
162
|
+
if (!g) {
|
|
163
|
+
we.warn("No active artboard for batch execution");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const b = u.map((A) => new class extends Object {
|
|
167
|
+
execute() {
|
|
168
|
+
A.execute();
|
|
169
|
+
}
|
|
170
|
+
undo() {
|
|
171
|
+
A.undo();
|
|
172
|
+
}
|
|
173
|
+
}());
|
|
174
|
+
i.current.executeBatchOnArtboard(g, b), c();
|
|
175
|
+
},
|
|
176
|
+
[o, c]
|
|
177
|
+
), w = h(() => {
|
|
178
|
+
i.current.undo() && (c(), n == null || n());
|
|
179
|
+
}, [c, n]), T = h(() => {
|
|
180
|
+
i.current.redo() && (c(), n == null || n());
|
|
181
|
+
}, [c, n]), C = h(() => {
|
|
182
|
+
const u = o.getActiveArtboardId();
|
|
183
|
+
u && i.current.undoArtboard(u) && (c(), n == null || n());
|
|
184
|
+
}, [o, c, n]), I = h(() => {
|
|
185
|
+
const u = o.getActiveArtboardId();
|
|
186
|
+
u && i.current.redoArtboard(u) && (c(), n == null || n());
|
|
187
|
+
}, [o, c, n]), W = h(() => {
|
|
188
|
+
i.current.clear(), c();
|
|
189
|
+
}, [c]), oe = h(
|
|
190
|
+
(u) => {
|
|
191
|
+
i.current.clearArtboardHistory(u), c();
|
|
192
|
+
},
|
|
193
|
+
[c]
|
|
194
|
+
), ue = ge(null);
|
|
195
|
+
ke(() => {
|
|
196
|
+
const u = o.getActiveArtboardId();
|
|
197
|
+
u !== ue.current && (ue.current = u, c());
|
|
198
|
+
});
|
|
199
|
+
const M = h(
|
|
200
|
+
(u, g, b) => {
|
|
201
|
+
const A = t.map((z) => z.id), F = o.getArtboardIdForElement(u);
|
|
202
|
+
if (!F) {
|
|
203
|
+
we.warn("Element not found in any artboard");
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const Y = new vt(u, g, b, A, (z) => {
|
|
207
|
+
e(($) => {
|
|
208
|
+
const U = new Map($.map((V) => [V.id, V]));
|
|
209
|
+
return z.map((V) => U.get(V)).filter(Boolean);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
i.current.executeOnArtboard(F, Y), c();
|
|
213
|
+
},
|
|
214
|
+
[t, e, o, c]
|
|
215
|
+
);
|
|
216
|
+
return {
|
|
217
|
+
// Element operations
|
|
218
|
+
executeElementUpdate: R,
|
|
219
|
+
executeAddElement: O,
|
|
220
|
+
executeRemoveElement: H,
|
|
221
|
+
executeReorderElement: M,
|
|
222
|
+
// Batch operations
|
|
223
|
+
executeCommandBatch: m,
|
|
224
|
+
// Artboard operations
|
|
225
|
+
executeCreateArtboard: x,
|
|
226
|
+
executeDeleteArtboard: L,
|
|
227
|
+
executeUpdateArtboard: p,
|
|
228
|
+
// Undo/redo (smart - considers last operation and active artboard)
|
|
229
|
+
undo: w,
|
|
230
|
+
redo: T,
|
|
231
|
+
// Undo/redo for active artboard only (element operations)
|
|
232
|
+
undoActiveArtboard: C,
|
|
233
|
+
redoActiveArtboard: I,
|
|
234
|
+
clearHistory: W,
|
|
235
|
+
clearArtboardHistory: oe,
|
|
236
|
+
// State (smart - considers last operation)
|
|
237
|
+
canUndo: s.canUndo,
|
|
238
|
+
canRedo: s.canRedo,
|
|
239
|
+
// State for active artboard only
|
|
240
|
+
canUndoActiveArtboard: s.canUndoActiveArtboard,
|
|
241
|
+
canRedoActiveArtboard: s.canRedoActiveArtboard,
|
|
242
|
+
historyManager: i.current
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function ce(t) {
|
|
246
|
+
return t && "fontSize" in t && "color" in t && "fontFamily" in t;
|
|
247
|
+
}
|
|
248
|
+
function Wt(t, e) {
|
|
249
|
+
const [o, n] = S(32), [i, r] = S("#333333"), [a, s] = S("Arial"), [d, c] = S("center");
|
|
250
|
+
ke(() => {
|
|
251
|
+
if (t && ce(t)) {
|
|
252
|
+
const p = t.transformType === "circle" && "getEffectiveFontSize" in t ? Math.round(t.getEffectiveFontSize()) : Math.round(t.fontSize), m = t.color, w = t.fontFamily, T = t.textAlign;
|
|
253
|
+
n((C) => C !== p ? p : C), r((C) => C !== m ? m : C), s((C) => C !== w ? w : C), c((C) => C !== T ? T : C);
|
|
254
|
+
}
|
|
255
|
+
}, [t]);
|
|
256
|
+
const R = h(
|
|
257
|
+
(p) => {
|
|
258
|
+
if (!t || !ce(t)) return;
|
|
259
|
+
const m = Math.max(Ot, Math.min(Nt, o + p));
|
|
260
|
+
n(m);
|
|
261
|
+
const w = t.clone();
|
|
262
|
+
w.transformType === "circle" && "setEffectiveFontSize" in w ? w.setEffectiveFontSize(m) : w.setFontSize(m), e(w);
|
|
263
|
+
},
|
|
264
|
+
[t, o, e]
|
|
265
|
+
), O = h(
|
|
266
|
+
(p) => {
|
|
267
|
+
if (!t || !ce(t)) return;
|
|
268
|
+
n(p);
|
|
269
|
+
const m = t.clone();
|
|
270
|
+
m.transformType === "circle" && "setEffectiveFontSize" in m ? m.setEffectiveFontSize(p) : m.setFontSize(p), e(m);
|
|
271
|
+
},
|
|
272
|
+
[t, e]
|
|
273
|
+
), H = h(
|
|
274
|
+
(p) => {
|
|
275
|
+
if (!t || !ce(t)) return;
|
|
276
|
+
r(p);
|
|
277
|
+
const m = t.clone();
|
|
278
|
+
if (m.color = p, m.richText)
|
|
279
|
+
for (const w of m.richText.spans)
|
|
280
|
+
w.style.color = void 0;
|
|
281
|
+
e(m);
|
|
282
|
+
},
|
|
283
|
+
[t, e]
|
|
284
|
+
), x = h(
|
|
285
|
+
(p) => {
|
|
286
|
+
if (!t || !ce(t)) return;
|
|
287
|
+
const m = t.fontFamily;
|
|
288
|
+
m !== p && Pt.clearCache(m), s(p);
|
|
289
|
+
const w = t.clone();
|
|
290
|
+
w.fontFamily = p, e(w);
|
|
291
|
+
},
|
|
292
|
+
[t, e]
|
|
293
|
+
), L = h(
|
|
294
|
+
(p) => {
|
|
295
|
+
if (!t || !ce(t)) return;
|
|
296
|
+
c(p);
|
|
297
|
+
const m = t.clone();
|
|
298
|
+
m.textAlign = p, e(m);
|
|
299
|
+
},
|
|
300
|
+
[t, e]
|
|
301
|
+
);
|
|
302
|
+
return {
|
|
303
|
+
// State
|
|
304
|
+
fontSize: o,
|
|
305
|
+
fontColor: i,
|
|
306
|
+
fontFamily: a,
|
|
307
|
+
textAlign: d,
|
|
308
|
+
// State setters (for UI only)
|
|
309
|
+
setFontSize: n,
|
|
310
|
+
setFontColor: r,
|
|
311
|
+
setFontFamily: s,
|
|
312
|
+
setTextAlign: c,
|
|
313
|
+
// Update functions (update element + UI)
|
|
314
|
+
updateFontSize: R,
|
|
315
|
+
setFontSizeValue: O,
|
|
316
|
+
updateFontColor: H,
|
|
317
|
+
updateFontFamily: x,
|
|
318
|
+
updateTextAlign: L
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
const nt = "data-preserve-selection";
|
|
322
|
+
function Mt(t) {
|
|
323
|
+
if (!(t instanceof Element))
|
|
324
|
+
return !1;
|
|
325
|
+
let e = t;
|
|
326
|
+
const o = [];
|
|
327
|
+
for (; e; ) {
|
|
328
|
+
const n = e.id ? `#${e.id}` : "", i = e.className ? `.${String(e.className).split(" ").slice(0, 2).join(".")}` : "";
|
|
329
|
+
if (o.push(`${e.tagName.toLowerCase()}${n}${i}`), e.hasAttribute(nt))
|
|
330
|
+
return !0;
|
|
331
|
+
const r = e.getAttribute("role");
|
|
332
|
+
if (r === "dialog" || r === "alertdialog" || r === "menu" || r === "listbox")
|
|
333
|
+
return !0;
|
|
334
|
+
const a = e.getAttribute("data-slot");
|
|
335
|
+
if (a && (a.includes("popover") || a.includes("dialog")) || e.hasAttribute("data-radix-popper-content-wrapper"))
|
|
336
|
+
return !0;
|
|
337
|
+
e = e.parentElement;
|
|
338
|
+
}
|
|
339
|
+
return !1;
|
|
340
|
+
}
|
|
341
|
+
const Fo = {
|
|
342
|
+
[nt]: ""
|
|
343
|
+
};
|
|
344
|
+
function Yt(t) {
|
|
345
|
+
const e = rt(t);
|
|
346
|
+
return e !== null && e < 0.5;
|
|
347
|
+
}
|
|
348
|
+
function vo(t) {
|
|
349
|
+
const e = rt(t);
|
|
350
|
+
return e !== null && e >= 0.5;
|
|
351
|
+
}
|
|
352
|
+
function rt(t) {
|
|
353
|
+
const e = t.trim();
|
|
354
|
+
if (e.startsWith("#")) {
|
|
355
|
+
const n = e.slice(1);
|
|
356
|
+
let i, r, a;
|
|
357
|
+
if (n.length === 3)
|
|
358
|
+
i = parseInt(n[0] + n[0], 16), r = parseInt(n[1] + n[1], 16), a = parseInt(n[2] + n[2], 16);
|
|
359
|
+
else if (n.length === 6)
|
|
360
|
+
i = parseInt(n.slice(0, 2), 16), r = parseInt(n.slice(2, 4), 16), a = parseInt(n.slice(4, 6), 16);
|
|
361
|
+
else return null;
|
|
362
|
+
return Number.isNaN(i) || Number.isNaN(r) || Number.isNaN(a) ? null : Ze(i, r, a);
|
|
363
|
+
}
|
|
364
|
+
const o = e.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
|
|
365
|
+
return o ? Ze(Number(o[1]), Number(o[2]), Number(o[3])) : null;
|
|
366
|
+
}
|
|
367
|
+
function Ze(t, e, o) {
|
|
368
|
+
const n = (i) => {
|
|
369
|
+
const r = i / 255;
|
|
370
|
+
return r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
|
|
371
|
+
};
|
|
372
|
+
return 0.2126 * n(t) + 0.7152 * n(e) + 0.0722 * n(o);
|
|
373
|
+
}
|
|
374
|
+
const Xt = "#333333", Kt = "#f4f4f5";
|
|
375
|
+
function Gt(t) {
|
|
376
|
+
return t && Yt(t) ? Kt : Xt;
|
|
377
|
+
}
|
|
378
|
+
const Zt = {
|
|
379
|
+
timeout: 3e4,
|
|
380
|
+
retries: 1,
|
|
381
|
+
retryDelay: 1e3,
|
|
382
|
+
validateUrl: !0
|
|
383
|
+
};
|
|
384
|
+
function Jt(t) {
|
|
385
|
+
try {
|
|
386
|
+
const e = new URL(t);
|
|
387
|
+
return ["http:", "https:", "data:", "blob:"].includes(e.protocol);
|
|
388
|
+
} catch {
|
|
389
|
+
return !1;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async function it(t, e = {}) {
|
|
393
|
+
const o = { ...Zt, ...e };
|
|
394
|
+
if (o.validateUrl && !Jt(t))
|
|
395
|
+
return {
|
|
396
|
+
success: !1,
|
|
397
|
+
error: new Error(`Invalid image URL: ${t}`)
|
|
398
|
+
};
|
|
399
|
+
let n;
|
|
400
|
+
for (let i = 0; i <= o.retries; i++)
|
|
401
|
+
try {
|
|
402
|
+
return await jt(t, o.timeout);
|
|
403
|
+
} catch (r) {
|
|
404
|
+
n = r instanceof Error ? r : new Error(String(r)), i < o.retries && await qt(o.retryDelay);
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
success: !1,
|
|
408
|
+
error: n || new Error("Failed to load image after retries")
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function jt(t, e) {
|
|
412
|
+
return new Promise((o) => {
|
|
413
|
+
const n = new Image();
|
|
414
|
+
n.crossOrigin = "anonymous";
|
|
415
|
+
let i = null, r = !1;
|
|
416
|
+
const a = () => {
|
|
417
|
+
i && (clearTimeout(i), i = null);
|
|
418
|
+
}, s = () => {
|
|
419
|
+
if (r) return;
|
|
420
|
+
r = !0, a();
|
|
421
|
+
const c = n.naturalWidth || n.width, R = n.naturalHeight || n.height;
|
|
422
|
+
o({
|
|
423
|
+
success: !0,
|
|
424
|
+
element: n,
|
|
425
|
+
width: c,
|
|
426
|
+
height: R,
|
|
427
|
+
aspectRatio: R > 0 ? c / R : 1
|
|
428
|
+
});
|
|
429
|
+
}, d = (c) => {
|
|
430
|
+
r || (r = !0, a(), o({
|
|
431
|
+
success: !1,
|
|
432
|
+
error: new Error(c)
|
|
433
|
+
}));
|
|
434
|
+
};
|
|
435
|
+
n.onload = s, n.onerror = () => {
|
|
436
|
+
d(`Failed to load image: ${t}`);
|
|
437
|
+
}, i = setTimeout(() => {
|
|
438
|
+
d(`Image load timed out after ${e}ms: ${t}`);
|
|
439
|
+
}, e), n.src = t;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
async function Po(t, e, o = {}, n = {}) {
|
|
443
|
+
var H, x, L, p, m, w, T;
|
|
444
|
+
const i = await it(t, n);
|
|
445
|
+
if (!i.success || !i.width || !i.height)
|
|
446
|
+
return {
|
|
447
|
+
success: !1,
|
|
448
|
+
error: i.error || new Error("Failed to get image dimensions")
|
|
449
|
+
};
|
|
450
|
+
const r = {
|
|
451
|
+
width: e.artboard.width,
|
|
452
|
+
height: e.artboard.height,
|
|
453
|
+
scale: e.scale,
|
|
454
|
+
align: et(e.alignment),
|
|
455
|
+
offsetX: e.offsetX,
|
|
456
|
+
offsetY: e.offsetY,
|
|
457
|
+
scaleMode: e.scaleMode,
|
|
458
|
+
marginTop: e.marginTop,
|
|
459
|
+
marginRight: e.marginRight,
|
|
460
|
+
marginBottom: e.marginBottom,
|
|
461
|
+
marginLeft: e.marginLeft
|
|
462
|
+
}, a = tt(
|
|
463
|
+
{ width: i.width, height: i.height },
|
|
464
|
+
r
|
|
465
|
+
), s = e.artboard.x + a.x, d = e.artboard.y + a.y, c = s + a.width / 2, R = d + a.height / 2;
|
|
466
|
+
return {
|
|
467
|
+
success: !0,
|
|
468
|
+
element: new _e({
|
|
469
|
+
...o,
|
|
470
|
+
x: c,
|
|
471
|
+
y: R,
|
|
472
|
+
imageUrl: t,
|
|
473
|
+
imageAspectRatio: i.aspectRatio,
|
|
474
|
+
preserveDimensions: !0,
|
|
475
|
+
// Don't recalculate dimensions on image load
|
|
476
|
+
transformData: {
|
|
477
|
+
type: "image",
|
|
478
|
+
width: a.width,
|
|
479
|
+
height: a.height,
|
|
480
|
+
cropX: ((H = o.transformData) == null ? void 0 : H.cropX) ?? 0,
|
|
481
|
+
cropY: ((x = o.transformData) == null ? void 0 : x.cropY) ?? 0,
|
|
482
|
+
cropWidth: ((L = o.transformData) == null ? void 0 : L.cropWidth) ?? 1,
|
|
483
|
+
cropHeight: ((p = o.transformData) == null ? void 0 : p.cropHeight) ?? 1,
|
|
484
|
+
flipHorizontal: ((m = o.transformData) == null ? void 0 : m.flipHorizontal) ?? !1,
|
|
485
|
+
flipVertical: ((w = o.transformData) == null ? void 0 : w.flipVertical) ?? !1,
|
|
486
|
+
borderRadius: ((T = o.transformData) == null ? void 0 : T.borderRadius) ?? 0
|
|
487
|
+
}
|
|
488
|
+
}),
|
|
489
|
+
placement: {
|
|
490
|
+
artworkSize: { width: i.width, height: i.height },
|
|
491
|
+
finalSize: { width: a.width, height: a.height },
|
|
492
|
+
position: { x: c, y: R },
|
|
493
|
+
scale: a.scale
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function qt(t) {
|
|
498
|
+
return new Promise((e) => setTimeout(e, t));
|
|
499
|
+
}
|
|
500
|
+
function Oo(t) {
|
|
501
|
+
if (t != null && t.scaleMode)
|
|
502
|
+
return {
|
|
503
|
+
scaleMode: t.scaleMode,
|
|
504
|
+
marginTop: t.fitMarginTop,
|
|
505
|
+
marginRight: t.fitMarginRight,
|
|
506
|
+
marginBottom: t.fitMarginBottom,
|
|
507
|
+
marginLeft: t.fitMarginLeft,
|
|
508
|
+
align: t.fitAlign
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function st(t) {
|
|
512
|
+
var e;
|
|
513
|
+
return ((e = t == null ? void 0 : t.imageFit) == null ? void 0 : e.scaleMode) === "contain";
|
|
514
|
+
}
|
|
515
|
+
function Qt(t, e) {
|
|
516
|
+
if (!st(t)) return null;
|
|
517
|
+
if (!(e.width > 0) || !(e.height > 0))
|
|
518
|
+
throw new Error(
|
|
519
|
+
`E_NEW_IMAGE_SIZE: a new picture of ${e.width}x${e.height} cannot be placed on a ${t.width}x${t.height} area; pass the picture's natural size (loadImageFromURL).`
|
|
520
|
+
);
|
|
521
|
+
const o = t.imageFit, n = tt(e, {
|
|
522
|
+
width: t.width,
|
|
523
|
+
height: t.height,
|
|
524
|
+
scaleMode: "contain",
|
|
525
|
+
align: et(o.align),
|
|
526
|
+
marginTop: o.marginTop,
|
|
527
|
+
marginRight: o.marginRight,
|
|
528
|
+
marginBottom: o.marginBottom,
|
|
529
|
+
marginLeft: o.marginLeft
|
|
530
|
+
});
|
|
531
|
+
return {
|
|
532
|
+
x: t.x + n.x + n.width / 2,
|
|
533
|
+
y: t.y + n.y + n.height / 2,
|
|
534
|
+
width: n.width,
|
|
535
|
+
height: n.height
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
async function eo(t, e) {
|
|
539
|
+
if (!st(t)) return null;
|
|
540
|
+
const o = await it(e, { validateUrl: !1 });
|
|
541
|
+
return !o.success || !o.width || !o.height ? null : Qt(t, { width: o.width, height: o.height });
|
|
542
|
+
}
|
|
543
|
+
const at = q(null), to = 0.1, oo = 4, Je = 0.25, no = ({
|
|
544
|
+
children: t,
|
|
545
|
+
artboardManager: e,
|
|
546
|
+
canvasRef: o,
|
|
547
|
+
viewPadding: n = 0.9
|
|
548
|
+
}) => {
|
|
549
|
+
const [i, r] = S(1), [a, s] = S({ x: 0, y: 0 }), [d, c] = S(!1), [R, O] = S(1), H = h(() => {
|
|
550
|
+
O(1), s({ x: 0, y: 0 });
|
|
551
|
+
}, []), x = h(() => {
|
|
552
|
+
r((T) => Math.min(T + Je, oo));
|
|
553
|
+
}, []), L = h(() => {
|
|
554
|
+
r((T) => Math.max(T - Je, to));
|
|
555
|
+
}, []), p = h(() => {
|
|
556
|
+
const T = e.getActiveArtboard();
|
|
557
|
+
if (!T || !o.current) return;
|
|
558
|
+
let C = o.current.parentElement, I = 0, W = 0;
|
|
559
|
+
for (; C && (I = C.clientWidth, W = C.clientHeight, !(I > 0 && W > 0)); )
|
|
560
|
+
C = C.parentElement;
|
|
561
|
+
if (!I || !W) return;
|
|
562
|
+
const oe = Math.min(
|
|
563
|
+
I * n / T.width,
|
|
564
|
+
W * n / T.height,
|
|
565
|
+
1
|
|
566
|
+
// Never zoom in beyond 100%
|
|
567
|
+
);
|
|
568
|
+
r(oe), s({ x: 0, y: 0 });
|
|
569
|
+
}, [e, o, n]), m = h(() => {
|
|
570
|
+
r(1), s({ x: 0, y: 0 });
|
|
571
|
+
}, []), w = j(
|
|
572
|
+
() => ({
|
|
573
|
+
zoom: i,
|
|
574
|
+
panOffset: a,
|
|
575
|
+
isPanning: d,
|
|
576
|
+
zoomIn: x,
|
|
577
|
+
zoomOut: L,
|
|
578
|
+
zoomToFit: p,
|
|
579
|
+
resetView: m,
|
|
580
|
+
setZoom: r,
|
|
581
|
+
setPanOffset: s,
|
|
582
|
+
setIsPanning: c,
|
|
583
|
+
userZoom: R,
|
|
584
|
+
setUserZoom: O,
|
|
585
|
+
resetUserView: H
|
|
586
|
+
}),
|
|
587
|
+
[i, a, d, x, L, p, m, R, H]
|
|
588
|
+
);
|
|
589
|
+
return /* @__PURE__ */ _(at.Provider, { value: w, children: t });
|
|
590
|
+
};
|
|
591
|
+
function ro() {
|
|
592
|
+
const t = K(at);
|
|
593
|
+
if (!t)
|
|
594
|
+
throw new Error("useViewportContext must be used within a ViewportProvider (or EditorProvider)");
|
|
595
|
+
return t;
|
|
596
|
+
}
|
|
597
|
+
const ct = q(null), io = ({ children: t }) => {
|
|
598
|
+
const [e, o] = S(null), [n, i] = S([]), [r, a] = S(null), [s, d] = S(null), [c, R] = S(!1), O = h((L) => {
|
|
599
|
+
o(L);
|
|
600
|
+
}, []), H = h((L) => {
|
|
601
|
+
a(L);
|
|
602
|
+
}, []), x = j(
|
|
603
|
+
() => ({
|
|
604
|
+
selectedId: e,
|
|
605
|
+
multiSelection: n,
|
|
606
|
+
activeChildElement: r,
|
|
607
|
+
hoveredElementId: s,
|
|
608
|
+
hideHandles: c,
|
|
609
|
+
setSelectedId: o,
|
|
610
|
+
setMultiSelection: i,
|
|
611
|
+
setHoveredElementId: d,
|
|
612
|
+
setHideHandles: R,
|
|
613
|
+
handleSelectionChange: O,
|
|
614
|
+
handleActiveChildChange: H
|
|
615
|
+
}),
|
|
616
|
+
[
|
|
617
|
+
e,
|
|
618
|
+
n,
|
|
619
|
+
r,
|
|
620
|
+
s,
|
|
621
|
+
c,
|
|
622
|
+
O,
|
|
623
|
+
H
|
|
624
|
+
]
|
|
625
|
+
);
|
|
626
|
+
return /* @__PURE__ */ _(ct.Provider, { value: x, children: t });
|
|
627
|
+
};
|
|
628
|
+
function so() {
|
|
629
|
+
const t = K(ct);
|
|
630
|
+
if (!t)
|
|
631
|
+
throw new Error("useSelectionContext must be used within a SelectionProvider (or EditorProvider)");
|
|
632
|
+
return t;
|
|
633
|
+
}
|
|
634
|
+
const dt = q(null), ao = ({ children: t, value: e }) => {
|
|
635
|
+
const o = j(
|
|
636
|
+
() => ({
|
|
637
|
+
undo: e.undo,
|
|
638
|
+
redo: e.redo,
|
|
639
|
+
canUndo: e.canUndo,
|
|
640
|
+
canRedo: e.canRedo,
|
|
641
|
+
undoActiveArtboard: e.undoActiveArtboard,
|
|
642
|
+
redoActiveArtboard: e.redoActiveArtboard,
|
|
643
|
+
canUndoActiveArtboard: e.canUndoActiveArtboard,
|
|
644
|
+
canRedoActiveArtboard: e.canRedoActiveArtboard
|
|
645
|
+
}),
|
|
646
|
+
[
|
|
647
|
+
e.undo,
|
|
648
|
+
e.redo,
|
|
649
|
+
e.canUndo,
|
|
650
|
+
e.canRedo,
|
|
651
|
+
e.undoActiveArtboard,
|
|
652
|
+
e.redoActiveArtboard,
|
|
653
|
+
e.canUndoActiveArtboard,
|
|
654
|
+
e.canRedoActiveArtboard
|
|
655
|
+
]
|
|
656
|
+
);
|
|
657
|
+
return /* @__PURE__ */ _(dt.Provider, { value: o, children: t });
|
|
658
|
+
};
|
|
659
|
+
function No() {
|
|
660
|
+
const t = K(dt);
|
|
661
|
+
if (!t)
|
|
662
|
+
throw new Error("useHistoryContext must be used within a HistoryProvider (or EditorProvider)");
|
|
663
|
+
return t;
|
|
664
|
+
}
|
|
665
|
+
const lt = q(null), co = ({ children: t }) => {
|
|
666
|
+
const [e, o] = S(null), [n, i] = S(!1), [r, a] = S(0), [s, d] = S(!1), [c, R] = S(!1), O = j(
|
|
667
|
+
() => ({
|
|
668
|
+
expandedPanelType: e,
|
|
669
|
+
setExpandedPanelType: o,
|
|
670
|
+
isToolbarMenuOpen: n,
|
|
671
|
+
setIsToolbarMenuOpen: i,
|
|
672
|
+
textSelectionVersion: r,
|
|
673
|
+
setTextSelectionVersion: a,
|
|
674
|
+
isCanvasReady: s,
|
|
675
|
+
setCanvasReady: d,
|
|
676
|
+
isRotating: c,
|
|
677
|
+
setIsRotating: R
|
|
678
|
+
}),
|
|
679
|
+
[e, n, r, s, c]
|
|
680
|
+
);
|
|
681
|
+
return /* @__PURE__ */ _(lt.Provider, { value: O, children: t });
|
|
682
|
+
};
|
|
683
|
+
function lo() {
|
|
684
|
+
const t = K(lt);
|
|
685
|
+
if (!t)
|
|
686
|
+
throw new Error("useToolStateContext must be used within a ToolStateProvider (or EditorProvider)");
|
|
687
|
+
return t;
|
|
688
|
+
}
|
|
689
|
+
const ut = q(null), uo = ({ children: t, value: e }) => {
|
|
690
|
+
const o = j(
|
|
691
|
+
() => ({
|
|
692
|
+
elements: e.elements,
|
|
693
|
+
elementStore: e.elementStore,
|
|
694
|
+
artboards: e.artboards,
|
|
695
|
+
artboardManager: e.artboardManager,
|
|
696
|
+
artboardVersion: e.artboardVersion,
|
|
697
|
+
setElements: e.setElements,
|
|
698
|
+
refreshArtboards: e.refreshArtboards,
|
|
699
|
+
getElementById: e.getElementById,
|
|
700
|
+
handleAddElement: e.handleAddElement,
|
|
701
|
+
handleElementUpdate: e.handleElementUpdate,
|
|
702
|
+
handleLoadWorkspace: e.handleLoadWorkspace,
|
|
703
|
+
handleCopyElements: e.handleCopyElements,
|
|
704
|
+
handlePasteElements: e.handlePasteElements,
|
|
705
|
+
fontSize: e.fontSize,
|
|
706
|
+
fontColor: e.fontColor,
|
|
707
|
+
fontFamily: e.fontFamily,
|
|
708
|
+
textAlign: e.textAlign,
|
|
709
|
+
updateFontSize: e.updateFontSize,
|
|
710
|
+
setFontSizeValue: e.setFontSizeValue,
|
|
711
|
+
updateFontColor: e.updateFontColor,
|
|
712
|
+
updateFontFamily: e.updateFontFamily,
|
|
713
|
+
updateTextAlign: e.updateTextAlign,
|
|
714
|
+
canvasRef: e.canvasRef,
|
|
715
|
+
canvasEditorRef: e.canvasEditorRef
|
|
716
|
+
}),
|
|
717
|
+
[
|
|
718
|
+
e.elements,
|
|
719
|
+
e.elementStore,
|
|
720
|
+
e.artboards,
|
|
721
|
+
e.artboardManager,
|
|
722
|
+
e.artboardVersion,
|
|
723
|
+
e.setElements,
|
|
724
|
+
e.refreshArtboards,
|
|
725
|
+
e.getElementById,
|
|
726
|
+
e.handleAddElement,
|
|
727
|
+
e.handleElementUpdate,
|
|
728
|
+
e.handleLoadWorkspace,
|
|
729
|
+
e.handleCopyElements,
|
|
730
|
+
e.handlePasteElements,
|
|
731
|
+
e.fontSize,
|
|
732
|
+
e.fontColor,
|
|
733
|
+
e.fontFamily,
|
|
734
|
+
e.textAlign,
|
|
735
|
+
e.updateFontSize,
|
|
736
|
+
e.setFontSizeValue,
|
|
737
|
+
e.updateFontColor,
|
|
738
|
+
e.updateFontFamily,
|
|
739
|
+
e.updateTextAlign,
|
|
740
|
+
e.canvasRef,
|
|
741
|
+
e.canvasEditorRef
|
|
742
|
+
]
|
|
743
|
+
);
|
|
744
|
+
return /* @__PURE__ */ _(ut.Provider, { value: o, children: t });
|
|
745
|
+
};
|
|
746
|
+
function zo() {
|
|
747
|
+
const t = K(ut);
|
|
748
|
+
if (!t)
|
|
749
|
+
throw new Error("useElementsContext must be used within an ElementsProvider (or EditorProvider)");
|
|
750
|
+
return t;
|
|
751
|
+
}
|
|
752
|
+
const ht = q(null), ho = ({ children: t, value: e }) => {
|
|
753
|
+
const o = j(
|
|
754
|
+
() => ({
|
|
755
|
+
executeElementUpdate: e.executeElementUpdate,
|
|
756
|
+
executeAddElement: e.executeAddElement,
|
|
757
|
+
executeRemoveElement: e.executeRemoveElement,
|
|
758
|
+
executeReorderElement: e.executeReorderElement,
|
|
759
|
+
executeCreateArtboard: e.executeCreateArtboard,
|
|
760
|
+
executeDeleteArtboard: e.executeDeleteArtboard,
|
|
761
|
+
executeUpdateArtboard: e.executeUpdateArtboard,
|
|
762
|
+
executeCommandBatch: e.executeCommandBatch,
|
|
763
|
+
undo: e.undo,
|
|
764
|
+
redo: e.redo,
|
|
765
|
+
canUndo: e.canUndo,
|
|
766
|
+
canRedo: e.canRedo,
|
|
767
|
+
undoActiveArtboard: e.undoActiveArtboard,
|
|
768
|
+
redoActiveArtboard: e.redoActiveArtboard,
|
|
769
|
+
canUndoActiveArtboard: e.canUndoActiveArtboard,
|
|
770
|
+
canRedoActiveArtboard: e.canRedoActiveArtboard,
|
|
771
|
+
historyManager: e.historyManager
|
|
772
|
+
}),
|
|
773
|
+
[
|
|
774
|
+
e.executeElementUpdate,
|
|
775
|
+
e.executeAddElement,
|
|
776
|
+
e.executeRemoveElement,
|
|
777
|
+
e.executeReorderElement,
|
|
778
|
+
e.executeCreateArtboard,
|
|
779
|
+
e.executeDeleteArtboard,
|
|
780
|
+
e.executeUpdateArtboard,
|
|
781
|
+
e.executeCommandBatch,
|
|
782
|
+
e.undo,
|
|
783
|
+
e.redo,
|
|
784
|
+
e.canUndo,
|
|
785
|
+
e.canRedo,
|
|
786
|
+
e.undoActiveArtboard,
|
|
787
|
+
e.redoActiveArtboard,
|
|
788
|
+
e.canUndoActiveArtboard,
|
|
789
|
+
e.canRedoActiveArtboard,
|
|
790
|
+
e.historyManager
|
|
791
|
+
]
|
|
792
|
+
);
|
|
793
|
+
return /* @__PURE__ */ _(ht.Provider, { value: o, children: t });
|
|
794
|
+
};
|
|
795
|
+
function Uo() {
|
|
796
|
+
const t = K(ht);
|
|
797
|
+
if (!t)
|
|
798
|
+
throw new Error("useCommandContext must be used within a CommandProvider (or EditorProvider)");
|
|
799
|
+
return t;
|
|
800
|
+
}
|
|
801
|
+
const mo = Qe("EditorContext"), mt = q(null), ft = q(null), Do = () => {
|
|
802
|
+
const t = K(ft);
|
|
803
|
+
if (!t)
|
|
804
|
+
throw new Error("useEditorHandles must be used within EditorProvider");
|
|
805
|
+
return t;
|
|
806
|
+
}, fo = ({ children: t, artboardManager: e, canvasRef: o, canvasEditorRef: n }) => {
|
|
807
|
+
const i = ge(null), r = j(() => ({ get: () => i.current }), []), a = ro(), s = so(), d = lo(), [c, R] = S(
|
|
808
|
+
() => e.getAllArtboards()
|
|
809
|
+
), [O, H] = S(0), [x, L] = S(
|
|
810
|
+
() => new Ye()
|
|
811
|
+
), p = j(() => x.toArray(), [x]), m = h((l) => {
|
|
812
|
+
L((f) => {
|
|
813
|
+
const y = f.toArray(), E = typeof l == "function" ? l(y) : l;
|
|
814
|
+
return E === y ? f : Ye.fromArray(E);
|
|
815
|
+
});
|
|
816
|
+
}, []), w = h(
|
|
817
|
+
(l) => x.get(l),
|
|
818
|
+
[x]
|
|
819
|
+
), [T, C] = S([]), I = s.selectedId ? x.get(s.selectedId) : void 0, W = h(() => {
|
|
820
|
+
R([...e.getAllArtboards()]), H((l) => l + 1);
|
|
821
|
+
}, [e]), {
|
|
822
|
+
historyManager: oe,
|
|
823
|
+
executeElementUpdate: ue,
|
|
824
|
+
executeAddElement: M,
|
|
825
|
+
executeRemoveElement: u,
|
|
826
|
+
executeReorderElement: g,
|
|
827
|
+
executeCommandBatch: b,
|
|
828
|
+
executeCreateArtboard: A,
|
|
829
|
+
executeDeleteArtboard: F,
|
|
830
|
+
executeUpdateArtboard: Y,
|
|
831
|
+
undo: z,
|
|
832
|
+
redo: $,
|
|
833
|
+
canUndo: U,
|
|
834
|
+
canRedo: V,
|
|
835
|
+
undoActiveArtboard: P,
|
|
836
|
+
redoActiveArtboard: G,
|
|
837
|
+
canUndoActiveArtboard: ne,
|
|
838
|
+
canRedoActiveArtboard: Z
|
|
839
|
+
} = Bt(
|
|
840
|
+
p,
|
|
841
|
+
m,
|
|
842
|
+
e,
|
|
843
|
+
W
|
|
844
|
+
), k = h(
|
|
845
|
+
(l, f) => {
|
|
846
|
+
if (f && e.isPlaceholder(f.id)) {
|
|
847
|
+
const y = l == null ? void 0 : l.text, E = f.text;
|
|
848
|
+
typeof E == "string" && y !== E && e.unmarkPlaceholder(f.id);
|
|
849
|
+
}
|
|
850
|
+
return ue(l, f);
|
|
851
|
+
},
|
|
852
|
+
[e, ue]
|
|
853
|
+
), re = h(
|
|
854
|
+
(l) => {
|
|
855
|
+
const f = x.get(l.id);
|
|
856
|
+
k(f, l);
|
|
857
|
+
},
|
|
858
|
+
[x, k]
|
|
859
|
+
), At = h(
|
|
860
|
+
(l) => {
|
|
861
|
+
if (!I || !(I instanceof qe))
|
|
862
|
+
return;
|
|
863
|
+
const f = I.clone(), y = f.children.findIndex(
|
|
864
|
+
(E) => E.id === l.id
|
|
865
|
+
);
|
|
866
|
+
y >= 0 && (f.children[y] = l, re(f));
|
|
867
|
+
},
|
|
868
|
+
[I, re]
|
|
869
|
+
), yt = s.activeChildElement || I, xt = s.activeChildElement ? At : re, {
|
|
870
|
+
fontSize: Ee,
|
|
871
|
+
fontColor: Se,
|
|
872
|
+
fontFamily: Re,
|
|
873
|
+
textAlign: Ie,
|
|
874
|
+
updateFontSize: Te,
|
|
875
|
+
setFontSizeValue: Ce,
|
|
876
|
+
updateFontColor: Fe,
|
|
877
|
+
updateFontFamily: ve,
|
|
878
|
+
updateTextAlign: Pe
|
|
879
|
+
} = Wt(yt, xt), Ae = h(
|
|
880
|
+
async (l) => {
|
|
881
|
+
var We;
|
|
882
|
+
const f = l.type, y = l, E = e.getActiveArtboardId();
|
|
883
|
+
if (!E)
|
|
884
|
+
throw new te(
|
|
885
|
+
"E_NO_ACTIVE_ARTBOARD",
|
|
886
|
+
`addElement({ type: "${f}" }) needs an active artboard and none exists. <Editor.Root> seeds one automatically; with a raw EditorProvider create one first (executeCreateArtboard) or select one (artboardManager.setActiveArtboard).`,
|
|
887
|
+
{ type: f, docSlug: "embed-mode" }
|
|
888
|
+
);
|
|
889
|
+
const v = `element-${Date.now()}`, N = e.getActiveArtboard(), he = N ? N.x + N.width / 2 : window.innerWidth / 2, ie = N ? N.y + N.height / 2 : window.innerHeight / 2, J = ((We = n.current) == null ? void 0 : We.getZoom()) || a.zoom || 1;
|
|
890
|
+
if (f === "image") {
|
|
891
|
+
const fe = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", ee = 200 / J, B = y == null ? void 0 : y.src, pe = B ? await eo(N, B) : null;
|
|
892
|
+
if (pe) {
|
|
893
|
+
const D = new _e({
|
|
894
|
+
id: v,
|
|
895
|
+
name: l.name,
|
|
896
|
+
x: pe.x,
|
|
897
|
+
y: pe.y,
|
|
898
|
+
imageUrl: "",
|
|
899
|
+
preserveDimensions: !0,
|
|
900
|
+
transformData: { type: "image", width: pe.width, height: pe.height }
|
|
901
|
+
});
|
|
902
|
+
return D.imageUrl = B, D.onLoadCallback = (xe) => k(D, xe), M(D, E), s.setSelectedId(D.id), D.loadImage(B), { id: D.id, name: l.name ?? "" };
|
|
903
|
+
}
|
|
904
|
+
const X = new _e({
|
|
905
|
+
id: v,
|
|
906
|
+
name: l.name,
|
|
907
|
+
x: he,
|
|
908
|
+
y: ie,
|
|
909
|
+
// Defer loading `src` until after the element is in the store so a
|
|
910
|
+
// synchronously-cached image can't fire onLoadCallback too early.
|
|
911
|
+
imageUrl: B ? "" : fe,
|
|
912
|
+
transformData: {
|
|
913
|
+
type: "image",
|
|
914
|
+
width: ee,
|
|
915
|
+
height: ee,
|
|
916
|
+
cropX: 0,
|
|
917
|
+
cropY: 0,
|
|
918
|
+
cropWidth: 1,
|
|
919
|
+
cropHeight: 1,
|
|
920
|
+
flipHorizontal: !1,
|
|
921
|
+
flipVertical: !1,
|
|
922
|
+
borderRadius: 0
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
return B && (X.imageLoaded = !1, X.imageElement = null, X.isCropping = !1, X.imageUrl = B, X.preserveDimensions = !1, X.onLoadCallback = (D) => {
|
|
926
|
+
const xe = D.transformData.width, Me = D.transformData.height, Le = Math.min(ee / xe, ee / Me, 1);
|
|
927
|
+
Le < 1 && (D.transformData.width = xe * Le, D.transformData.height = Me * Le), D.transformData.cropX = 0, D.transformData.cropY = 0, D.transformData.cropWidth = 1, D.transformData.cropHeight = 1, k(X, D);
|
|
928
|
+
}), M(X, E), s.setSelectedId(X.id), B && X.loadImage(B), { id: X.id, name: l.name ?? "" };
|
|
929
|
+
}
|
|
930
|
+
let Q;
|
|
931
|
+
const ae = {
|
|
932
|
+
text: "custom",
|
|
933
|
+
circle: "circle",
|
|
934
|
+
wave: "wave",
|
|
935
|
+
arch: "arch",
|
|
936
|
+
shape: "shape"
|
|
937
|
+
}[f] || "custom", De = Dt(ae);
|
|
938
|
+
if (!De || !De.Component)
|
|
939
|
+
throw new Error(`[EditorContext] no transform registered for element type "${f}"`);
|
|
940
|
+
const me = e.getActiveArtboard(), wt = me ? Math.min(me.width, me.height) * 0.1 : 80, He = me ? me.width * 0.5 : 300;
|
|
941
|
+
if (f === "shape") {
|
|
942
|
+
const fe = (y == null ? void 0 : y.shapeType) ?? "rectangle";
|
|
943
|
+
let ee = 200 / J, B = 200 / J;
|
|
944
|
+
fe === "ellipse" ? (ee = 150 / J, B = 250 / J) : fe === "line" && (ee = 300 / J, B = 8 / J), Q = new Ht({
|
|
945
|
+
id: v,
|
|
946
|
+
name: l.name,
|
|
947
|
+
x: he,
|
|
948
|
+
y: ie,
|
|
949
|
+
transformData: {
|
|
950
|
+
type: "shape",
|
|
951
|
+
shapeType: fe,
|
|
952
|
+
width: ee,
|
|
953
|
+
height: B,
|
|
954
|
+
// an engraved area has one ink: black, which the laser cuts
|
|
955
|
+
fillColor: N != null && N.engrave ? Xe : "#3b82f6",
|
|
956
|
+
fillOpacity: 1
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
} else
|
|
960
|
+
Q = new De.Component({
|
|
961
|
+
id: v,
|
|
962
|
+
name: l.name,
|
|
963
|
+
text: "New Text",
|
|
964
|
+
x: he,
|
|
965
|
+
y: ie,
|
|
966
|
+
fontSize: wt,
|
|
967
|
+
fontFamily: "Poppins",
|
|
968
|
+
color: N != null && N.engrave ? Xe : Gt(N == null ? void 0 : N.backgroundColor),
|
|
969
|
+
transformData: ae === "arch" ? {
|
|
970
|
+
type: "arch",
|
|
971
|
+
width: He,
|
|
972
|
+
archHeight: Lt.archHeight
|
|
973
|
+
} : ae === "wave" ? {
|
|
974
|
+
type: "wave",
|
|
975
|
+
width: He,
|
|
976
|
+
amplitude: Ke.amplitude,
|
|
977
|
+
frequency: Ke.frequency
|
|
978
|
+
} : ae === "circle" ? {
|
|
979
|
+
type: "circle",
|
|
980
|
+
radius: He / 2
|
|
981
|
+
} : void 0
|
|
982
|
+
});
|
|
983
|
+
return e.addElementToArtboard(v, E), M(
|
|
984
|
+
Q,
|
|
985
|
+
E,
|
|
986
|
+
s.selectedId || void 0
|
|
987
|
+
), s.setSelectedId(v), { id: v, name: l.name ?? "" };
|
|
988
|
+
},
|
|
989
|
+
[e, M, k, s, a.zoom, n]
|
|
990
|
+
), Oe = h(
|
|
991
|
+
async (l, f) => {
|
|
992
|
+
await Ae({ ...f, type: l });
|
|
993
|
+
},
|
|
994
|
+
[Ae]
|
|
995
|
+
), Ne = h(() => {
|
|
996
|
+
const l = [];
|
|
997
|
+
if (s.multiSelection.length > 0) {
|
|
998
|
+
const f = p.filter(
|
|
999
|
+
(y) => s.multiSelection.includes(y.id)
|
|
1000
|
+
);
|
|
1001
|
+
l.push(...f);
|
|
1002
|
+
} else I && l.push(I);
|
|
1003
|
+
if (l.length > 0) {
|
|
1004
|
+
const f = l.map((y) => y.clone());
|
|
1005
|
+
C(f);
|
|
1006
|
+
}
|
|
1007
|
+
}, [I, s.multiSelection, p]), ze = h(() => {
|
|
1008
|
+
if (T.length === 0) return;
|
|
1009
|
+
const l = [], f = 30, y = 30;
|
|
1010
|
+
T.forEach((E) => {
|
|
1011
|
+
const v = x.get(E.id), N = v ? v.x : E.x, he = v ? v.y : E.y, ie = E.toJSON();
|
|
1012
|
+
delete ie.id;
|
|
1013
|
+
const J = E.constructor, Q = new J(ie);
|
|
1014
|
+
Q.x = N + f, Q.y = he + y;
|
|
1015
|
+
let se = null;
|
|
1016
|
+
if (v && (se = e.getArtboardIdForElement(
|
|
1017
|
+
v.id
|
|
1018
|
+
)), se || (se = e.getActiveArtboardId()), !se) {
|
|
1019
|
+
mo.warn("[handlePasteElements] No artboard found for pasting");
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
const ae = v ? v.id : void 0;
|
|
1023
|
+
M(Q, se, ae), l.push(Q.id);
|
|
1024
|
+
}), l.length === 1 ? s.handleSelectionChange(l[0]) : l.length > 1 && s.setMultiSelection(l);
|
|
1025
|
+
}, [
|
|
1026
|
+
T,
|
|
1027
|
+
x,
|
|
1028
|
+
e,
|
|
1029
|
+
M,
|
|
1030
|
+
s
|
|
1031
|
+
]), ye = h(() => {
|
|
1032
|
+
if (d.expandedPanelType === "crop" && (I == null ? void 0 : I.transformType) === "image") {
|
|
1033
|
+
const l = I;
|
|
1034
|
+
if (l.isCropping) {
|
|
1035
|
+
const f = l.clone();
|
|
1036
|
+
f.exitCropMode(), k(l, f);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
d.setExpandedPanelType(null);
|
|
1040
|
+
}, [
|
|
1041
|
+
d.expandedPanelType,
|
|
1042
|
+
d.setExpandedPanelType,
|
|
1043
|
+
I,
|
|
1044
|
+
k
|
|
1045
|
+
]);
|
|
1046
|
+
ke(() => {
|
|
1047
|
+
const l = (f) => {
|
|
1048
|
+
const y = f.target;
|
|
1049
|
+
if (y.tagName === "CANVAS" || Mt(y))
|
|
1050
|
+
return;
|
|
1051
|
+
const v = document.activeElement;
|
|
1052
|
+
if (v != null && v.hasAttribute("data-preserve-selection")) {
|
|
1053
|
+
v.blur();
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (d.expandedPanelType !== null) {
|
|
1057
|
+
ye();
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
s.selectedId !== null && s.setSelectedId(null), s.multiSelection.length > 0 && s.setMultiSelection([]);
|
|
1061
|
+
};
|
|
1062
|
+
return document.addEventListener("pointerdown", l), () => document.removeEventListener("pointerdown", l);
|
|
1063
|
+
}, [d.expandedPanelType, ye, s]);
|
|
1064
|
+
const Ue = h(
|
|
1065
|
+
(l, f, y) => {
|
|
1066
|
+
e.clear(), l.forEach((E) => {
|
|
1067
|
+
e.createArtboard(E.toJSON());
|
|
1068
|
+
}), y && e.setActiveArtboard(y), R([...e.getAllArtboards()]), H((E) => E + 1), m(f), s.setSelectedId(null);
|
|
1069
|
+
},
|
|
1070
|
+
[e, s, m]
|
|
1071
|
+
), Be = j(() => ({
|
|
1072
|
+
// From ViewportContext
|
|
1073
|
+
zoom: a.zoom,
|
|
1074
|
+
panOffset: a.panOffset,
|
|
1075
|
+
isPanning: a.isPanning,
|
|
1076
|
+
zoomIn: a.zoomIn,
|
|
1077
|
+
zoomOut: a.zoomOut,
|
|
1078
|
+
zoomToFit: a.zoomToFit,
|
|
1079
|
+
resetView: a.resetView,
|
|
1080
|
+
setZoom: a.setZoom,
|
|
1081
|
+
setPanOffset: a.setPanOffset,
|
|
1082
|
+
setIsPanning: a.setIsPanning,
|
|
1083
|
+
// From SelectionContext
|
|
1084
|
+
selectedId: s.selectedId,
|
|
1085
|
+
multiSelection: s.multiSelection,
|
|
1086
|
+
activeChildElement: s.activeChildElement,
|
|
1087
|
+
hoveredElementId: s.hoveredElementId,
|
|
1088
|
+
hideHandles: s.hideHandles,
|
|
1089
|
+
setSelectedId: s.setSelectedId,
|
|
1090
|
+
setMultiSelection: s.setMultiSelection,
|
|
1091
|
+
setHoveredElementId: s.setHoveredElementId,
|
|
1092
|
+
setHideHandles: s.setHideHandles,
|
|
1093
|
+
handleSelectionChange: s.handleSelectionChange,
|
|
1094
|
+
handleActiveChildChange: s.handleActiveChildChange,
|
|
1095
|
+
// From ToolStateContext
|
|
1096
|
+
expandedPanelType: d.expandedPanelType,
|
|
1097
|
+
setExpandedPanelType: d.setExpandedPanelType,
|
|
1098
|
+
isToolbarMenuOpen: d.isToolbarMenuOpen,
|
|
1099
|
+
setIsToolbarMenuOpen: d.setIsToolbarMenuOpen,
|
|
1100
|
+
textSelectionVersion: d.textSelectionVersion,
|
|
1101
|
+
setTextSelectionVersion: d.setTextSelectionVersion,
|
|
1102
|
+
isCanvasReady: d.isCanvasReady,
|
|
1103
|
+
setCanvasReady: d.setCanvasReady,
|
|
1104
|
+
isRotating: d.isRotating,
|
|
1105
|
+
setIsRotating: d.setIsRotating,
|
|
1106
|
+
// Cross-context handler
|
|
1107
|
+
clearExpandedPanel: ye,
|
|
1108
|
+
// Core state (element/artboard domain)
|
|
1109
|
+
artboardManager: e,
|
|
1110
|
+
artboards: c,
|
|
1111
|
+
elements: p,
|
|
1112
|
+
elementStore: x,
|
|
1113
|
+
getElementById: w,
|
|
1114
|
+
// Derived state (cross-context)
|
|
1115
|
+
selectedElement: I,
|
|
1116
|
+
// Refs
|
|
1117
|
+
canvasRef: o,
|
|
1118
|
+
canvasEditorRef: n,
|
|
1119
|
+
// Element setters
|
|
1120
|
+
setElements: m,
|
|
1121
|
+
// Artboard version counter
|
|
1122
|
+
artboardVersion: O,
|
|
1123
|
+
// Handlers
|
|
1124
|
+
refreshArtboards: W,
|
|
1125
|
+
handleElementUpdate: re,
|
|
1126
|
+
addElement: Ae,
|
|
1127
|
+
handleAddElement: Oe,
|
|
1128
|
+
handleLoadWorkspace: Ue,
|
|
1129
|
+
handleCopyElements: Ne,
|
|
1130
|
+
handlePasteElements: ze,
|
|
1131
|
+
hasClipboardContent: T.length > 0,
|
|
1132
|
+
// Command history (undo/redo actions + execute functions)
|
|
1133
|
+
historyManager: oe,
|
|
1134
|
+
executeElementUpdate: k,
|
|
1135
|
+
executeAddElement: M,
|
|
1136
|
+
executeRemoveElement: u,
|
|
1137
|
+
executeReorderElement: g,
|
|
1138
|
+
executeCommandBatch: b,
|
|
1139
|
+
executeCreateArtboard: A,
|
|
1140
|
+
executeDeleteArtboard: F,
|
|
1141
|
+
executeUpdateArtboard: Y,
|
|
1142
|
+
undo: z,
|
|
1143
|
+
redo: $,
|
|
1144
|
+
canUndo: U,
|
|
1145
|
+
canRedo: V,
|
|
1146
|
+
undoActiveArtboard: P,
|
|
1147
|
+
redoActiveArtboard: G,
|
|
1148
|
+
canUndoActiveArtboard: ne,
|
|
1149
|
+
canRedoActiveArtboard: Z,
|
|
1150
|
+
// Element properties
|
|
1151
|
+
fontSize: Ee,
|
|
1152
|
+
fontColor: Se,
|
|
1153
|
+
fontFamily: Re,
|
|
1154
|
+
textAlign: Ie,
|
|
1155
|
+
updateFontSize: Te,
|
|
1156
|
+
setFontSizeValue: Ce,
|
|
1157
|
+
updateFontColor: Fe,
|
|
1158
|
+
updateFontFamily: ve,
|
|
1159
|
+
updateTextAlign: Pe
|
|
1160
|
+
}), [
|
|
1161
|
+
// Viewport
|
|
1162
|
+
a.zoom,
|
|
1163
|
+
a.panOffset,
|
|
1164
|
+
a.isPanning,
|
|
1165
|
+
a.zoomIn,
|
|
1166
|
+
a.zoomOut,
|
|
1167
|
+
a.zoomToFit,
|
|
1168
|
+
a.resetView,
|
|
1169
|
+
a.setZoom,
|
|
1170
|
+
a.setPanOffset,
|
|
1171
|
+
a.setIsPanning,
|
|
1172
|
+
// Selection
|
|
1173
|
+
s.selectedId,
|
|
1174
|
+
s.multiSelection,
|
|
1175
|
+
s.activeChildElement,
|
|
1176
|
+
s.hoveredElementId,
|
|
1177
|
+
s.hideHandles,
|
|
1178
|
+
s.setSelectedId,
|
|
1179
|
+
s.setMultiSelection,
|
|
1180
|
+
s.setHoveredElementId,
|
|
1181
|
+
s.setHideHandles,
|
|
1182
|
+
s.handleSelectionChange,
|
|
1183
|
+
s.handleActiveChildChange,
|
|
1184
|
+
// Tool state
|
|
1185
|
+
d.expandedPanelType,
|
|
1186
|
+
d.setExpandedPanelType,
|
|
1187
|
+
d.isToolbarMenuOpen,
|
|
1188
|
+
d.setIsToolbarMenuOpen,
|
|
1189
|
+
d.textSelectionVersion,
|
|
1190
|
+
d.setTextSelectionVersion,
|
|
1191
|
+
d.isCanvasReady,
|
|
1192
|
+
d.setCanvasReady,
|
|
1193
|
+
d.isRotating,
|
|
1194
|
+
d.setIsRotating,
|
|
1195
|
+
ye,
|
|
1196
|
+
// Element/artboard domain
|
|
1197
|
+
e,
|
|
1198
|
+
c,
|
|
1199
|
+
p,
|
|
1200
|
+
x,
|
|
1201
|
+
w,
|
|
1202
|
+
I,
|
|
1203
|
+
o,
|
|
1204
|
+
n,
|
|
1205
|
+
m,
|
|
1206
|
+
O,
|
|
1207
|
+
W,
|
|
1208
|
+
re,
|
|
1209
|
+
Ae,
|
|
1210
|
+
Oe,
|
|
1211
|
+
Ue,
|
|
1212
|
+
Ne,
|
|
1213
|
+
ze,
|
|
1214
|
+
T,
|
|
1215
|
+
// Command history
|
|
1216
|
+
oe,
|
|
1217
|
+
k,
|
|
1218
|
+
M,
|
|
1219
|
+
u,
|
|
1220
|
+
g,
|
|
1221
|
+
b,
|
|
1222
|
+
A,
|
|
1223
|
+
F,
|
|
1224
|
+
Y,
|
|
1225
|
+
z,
|
|
1226
|
+
$,
|
|
1227
|
+
U,
|
|
1228
|
+
V,
|
|
1229
|
+
P,
|
|
1230
|
+
G,
|
|
1231
|
+
ne,
|
|
1232
|
+
Z,
|
|
1233
|
+
// Element properties
|
|
1234
|
+
Ee,
|
|
1235
|
+
Se,
|
|
1236
|
+
Re,
|
|
1237
|
+
Ie,
|
|
1238
|
+
Te,
|
|
1239
|
+
Ce,
|
|
1240
|
+
Fe,
|
|
1241
|
+
ve,
|
|
1242
|
+
Pe
|
|
1243
|
+
]);
|
|
1244
|
+
return i.current = Be, /* @__PURE__ */ _(ft.Provider, { value: r, children: /* @__PURE__ */ _(
|
|
1245
|
+
ao,
|
|
1246
|
+
{
|
|
1247
|
+
value: {
|
|
1248
|
+
undo: z,
|
|
1249
|
+
redo: $,
|
|
1250
|
+
canUndo: U,
|
|
1251
|
+
canRedo: V,
|
|
1252
|
+
undoActiveArtboard: P,
|
|
1253
|
+
redoActiveArtboard: G,
|
|
1254
|
+
canUndoActiveArtboard: ne,
|
|
1255
|
+
canRedoActiveArtboard: Z
|
|
1256
|
+
},
|
|
1257
|
+
children: /* @__PURE__ */ _(
|
|
1258
|
+
uo,
|
|
1259
|
+
{
|
|
1260
|
+
value: {
|
|
1261
|
+
elements: p,
|
|
1262
|
+
elementStore: x,
|
|
1263
|
+
artboards: c,
|
|
1264
|
+
artboardManager: e,
|
|
1265
|
+
artboardVersion: O,
|
|
1266
|
+
setElements: m,
|
|
1267
|
+
refreshArtboards: W,
|
|
1268
|
+
getElementById: w,
|
|
1269
|
+
handleAddElement: Oe,
|
|
1270
|
+
handleElementUpdate: re,
|
|
1271
|
+
handleLoadWorkspace: Ue,
|
|
1272
|
+
handleCopyElements: Ne,
|
|
1273
|
+
handlePasteElements: ze,
|
|
1274
|
+
fontSize: Ee,
|
|
1275
|
+
fontColor: Se,
|
|
1276
|
+
fontFamily: Re,
|
|
1277
|
+
textAlign: Ie,
|
|
1278
|
+
updateFontSize: Te,
|
|
1279
|
+
setFontSizeValue: Ce,
|
|
1280
|
+
updateFontColor: Fe,
|
|
1281
|
+
updateFontFamily: ve,
|
|
1282
|
+
updateTextAlign: Pe,
|
|
1283
|
+
canvasRef: o,
|
|
1284
|
+
canvasEditorRef: n
|
|
1285
|
+
},
|
|
1286
|
+
children: /* @__PURE__ */ _(
|
|
1287
|
+
ho,
|
|
1288
|
+
{
|
|
1289
|
+
value: {
|
|
1290
|
+
executeElementUpdate: k,
|
|
1291
|
+
executeAddElement: M,
|
|
1292
|
+
executeRemoveElement: u,
|
|
1293
|
+
executeReorderElement: g,
|
|
1294
|
+
executeCommandBatch: b,
|
|
1295
|
+
executeCreateArtboard: A,
|
|
1296
|
+
executeDeleteArtboard: F,
|
|
1297
|
+
executeUpdateArtboard: Y,
|
|
1298
|
+
undo: z,
|
|
1299
|
+
redo: $,
|
|
1300
|
+
canUndo: U,
|
|
1301
|
+
canRedo: V,
|
|
1302
|
+
undoActiveArtboard: P,
|
|
1303
|
+
redoActiveArtboard: G,
|
|
1304
|
+
canUndoActiveArtboard: ne,
|
|
1305
|
+
canRedoActiveArtboard: Z,
|
|
1306
|
+
historyManager: oe
|
|
1307
|
+
},
|
|
1308
|
+
children: /* @__PURE__ */ _(mt.Provider, { value: Be, children: t })
|
|
1309
|
+
}
|
|
1310
|
+
)
|
|
1311
|
+
}
|
|
1312
|
+
)
|
|
1313
|
+
}
|
|
1314
|
+
) });
|
|
1315
|
+
}, Ho = ({
|
|
1316
|
+
children: t,
|
|
1317
|
+
initialArtboardConfig: e = {},
|
|
1318
|
+
viewPadding: o = 0.9
|
|
1319
|
+
}) => {
|
|
1320
|
+
const [n] = S(() => {
|
|
1321
|
+
const a = new Ut(), s = {
|
|
1322
|
+
name: e.name || "Artboard 1",
|
|
1323
|
+
x: e.x ?? 0,
|
|
1324
|
+
y: e.y ?? 0,
|
|
1325
|
+
width: e.width ?? 1e3,
|
|
1326
|
+
height: e.height ?? 1e3,
|
|
1327
|
+
backgroundColor: e.backgroundColor || zt
|
|
1328
|
+
};
|
|
1329
|
+
return a.createArtboard(s), a;
|
|
1330
|
+
}), i = ge(null), r = ge(null);
|
|
1331
|
+
return /* @__PURE__ */ _(
|
|
1332
|
+
no,
|
|
1333
|
+
{
|
|
1334
|
+
artboardManager: n,
|
|
1335
|
+
canvasRef: i,
|
|
1336
|
+
viewPadding: o,
|
|
1337
|
+
children: /* @__PURE__ */ _(io, { children: /* @__PURE__ */ _(co, { children: /* @__PURE__ */ _(
|
|
1338
|
+
fo,
|
|
1339
|
+
{
|
|
1340
|
+
artboardManager: n,
|
|
1341
|
+
canvasRef: i,
|
|
1342
|
+
canvasEditorRef: r,
|
|
1343
|
+
children: t
|
|
1344
|
+
}
|
|
1345
|
+
) }) })
|
|
1346
|
+
}
|
|
1347
|
+
);
|
|
1348
|
+
}, Lo = () => {
|
|
1349
|
+
const t = K(mt);
|
|
1350
|
+
if (!t)
|
|
1351
|
+
throw new Error("useEditor must be used within EditorProvider");
|
|
1352
|
+
return t;
|
|
1353
|
+
}, le = [];
|
|
1354
|
+
function Vo(t) {
|
|
1355
|
+
_t() && le.push(t);
|
|
1356
|
+
}
|
|
1357
|
+
function _o() {
|
|
1358
|
+
return [...le];
|
|
1359
|
+
}
|
|
1360
|
+
function $o() {
|
|
1361
|
+
le.length = 0;
|
|
1362
|
+
}
|
|
1363
|
+
function ko() {
|
|
1364
|
+
if (le.length === 0) return;
|
|
1365
|
+
const t = le.map((e) => Vt(e) ? `${e.code}: ${e.message}` : `${e.name}: ${e.message}`).join(`
|
|
1366
|
+
- `);
|
|
1367
|
+
throw le.length = 0, new Error(
|
|
1368
|
+
`expectNoEditorErrors: ${t.includes(`
|
|
1369
|
+
`) ? "errors were" : "an error was"} contained by <Editor.Root>'s boundary during this test:
|
|
1370
|
+
- ${t}
|
|
1371
|
+
A contained error renders an error card in prod — this composition is broken even if the test rendered "successfully".`
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
const je = "center", pt = Symbol.for("snowcone.canvas.layerToken");
|
|
1375
|
+
function Bo(t) {
|
|
1376
|
+
return typeof t == "object" && t !== null && t[pt] === !0 && typeof t.name == "string" && (t.kind === "text" || t.kind === "image");
|
|
1377
|
+
}
|
|
1378
|
+
function po(t, e) {
|
|
1379
|
+
return Object.freeze({ kind: t, name: e, [pt]: !0 });
|
|
1380
|
+
}
|
|
1381
|
+
const gt = Symbol.for("snowcone.canvas.colorToken");
|
|
1382
|
+
function go(t) {
|
|
1383
|
+
return typeof t == "object" && t !== null && t[gt] === !0 && typeof t.name == "string" && typeof t.value == "string";
|
|
1384
|
+
}
|
|
1385
|
+
function Ao(t, e) {
|
|
1386
|
+
return Object.freeze({ name: t, value: e, [gt]: !0 });
|
|
1387
|
+
}
|
|
1388
|
+
function yo(t) {
|
|
1389
|
+
let e = t.trim().toUpperCase();
|
|
1390
|
+
return /^#[0-9A-F]{3}$/.test(e) && (e = "#" + e[1] + e[1] + e[2] + e[2] + e[3] + e[3]), /^#[0-9A-F]{6}$/.test(e) ? e : null;
|
|
1391
|
+
}
|
|
1392
|
+
function be(t) {
|
|
1393
|
+
return go(t) ? t.value : t;
|
|
1394
|
+
}
|
|
1395
|
+
function $e(t) {
|
|
1396
|
+
const e = t.transformType;
|
|
1397
|
+
return e === "image" ? "image" : e === "shape" || e === "group" || e === "path" ? null : "text";
|
|
1398
|
+
}
|
|
1399
|
+
function xo(t) {
|
|
1400
|
+
return t === "top-left" || t === "left" || t === "bottom-left" ? "left" : t === "top-right" || t === "right" || t === "bottom-right" ? "right" : "center";
|
|
1401
|
+
}
|
|
1402
|
+
function wo(t) {
|
|
1403
|
+
return t === "top-left" || t === "top" || t === "top-right" ? "top" : t === "bottom-left" || t === "bottom" || t === "bottom-right" ? "bottom" : "middle";
|
|
1404
|
+
}
|
|
1405
|
+
function Ve(t, e, o, n, i, r) {
|
|
1406
|
+
const a = xo(t), s = wo(t), d = a === "left" ? e / 2 + r : a === "right" ? n - e / 2 - r : n / 2, c = s === "top" ? o / 2 + r : s === "bottom" ? i - o / 2 - r : i / 2;
|
|
1407
|
+
return { x: d, y: c };
|
|
1408
|
+
}
|
|
1409
|
+
function bo(t, e, o) {
|
|
1410
|
+
const n = e / o;
|
|
1411
|
+
if (t >= n) {
|
|
1412
|
+
const a = o * t, s = e / a;
|
|
1413
|
+
return {
|
|
1414
|
+
width: a,
|
|
1415
|
+
height: o,
|
|
1416
|
+
cropX: (1 - s) / 2,
|
|
1417
|
+
cropY: 0,
|
|
1418
|
+
cropWidth: s,
|
|
1419
|
+
cropHeight: 1
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
const i = e / t, r = o / i;
|
|
1423
|
+
return {
|
|
1424
|
+
width: e,
|
|
1425
|
+
height: i,
|
|
1426
|
+
cropX: 0,
|
|
1427
|
+
cropY: (1 - r) / 2,
|
|
1428
|
+
cropWidth: 1,
|
|
1429
|
+
cropHeight: r
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
class de {
|
|
1433
|
+
constructor(e) {
|
|
1434
|
+
if (this.els = [], this.colorRoles = /* @__PURE__ */ new Map(), this.idCounter = 0, !(e.width > 0) || !(e.height > 0))
|
|
1435
|
+
throw new Error("design(): artboard width and height must be positive numbers");
|
|
1436
|
+
for (const [o, n] of Object.entries(e.colors ?? {})) {
|
|
1437
|
+
const i = yo(n);
|
|
1438
|
+
if (i === null)
|
|
1439
|
+
throw new te(
|
|
1440
|
+
"E_COLOR_ROLE_INVALID",
|
|
1441
|
+
`color role "${o}" is ${JSON.stringify(n)} — roles must be #RGB/#RRGGBB hex (useColorBinding matches by normalized hex value; other syntaxes can't bind).`,
|
|
1442
|
+
{ roleName: o, value: n, docSlug: "embed-mode" }
|
|
1443
|
+
);
|
|
1444
|
+
const r = [...this.colorRoles.entries()].find(([, a]) => a === i);
|
|
1445
|
+
if (r)
|
|
1446
|
+
throw new te(
|
|
1447
|
+
"E_COLOR_ROLE_COLLISION",
|
|
1448
|
+
`color roles "${r[0]}" and "${o}" both normalize to ${i}. useColorBinding matches elements by VALUE, so colliding roles would repaint each other's elements — give every role a distinct hex.`,
|
|
1449
|
+
{ roles: [r[0], o], value: i, docSlug: "embed-mode" }
|
|
1450
|
+
);
|
|
1451
|
+
this.colorRoles.set(o, i);
|
|
1452
|
+
}
|
|
1453
|
+
this.current = {
|
|
1454
|
+
name: e.name || "Front",
|
|
1455
|
+
width: e.width,
|
|
1456
|
+
height: e.height,
|
|
1457
|
+
backgroundColor: be(e.backgroundColor),
|
|
1458
|
+
role: e.role
|
|
1459
|
+
}, this.activeName = this.current.name;
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Seed a builder from a previously saved canvas state — the editor shape
|
|
1463
|
+
* `<SnowconeCanvas onChange>` emits (and `toJSON()` produces).
|
|
1464
|
+
*
|
|
1465
|
+
* This is how a saved editable template re-enters the turnkey embed path:
|
|
1466
|
+
* load the template's state JSON, lift it back into a `DesignBuilder`, and
|
|
1467
|
+
* hand it to `<RealtimeEmbed design={…}>`. By default the active artboard
|
|
1468
|
+
* becomes the builder's artboard; elements tagged for other artboards are
|
|
1469
|
+
* skipped (untagged elements are assumed to belong to the active one).
|
|
1470
|
+
*
|
|
1471
|
+
* Pass `{ artboards: 'all' }` to load a multi-page template (ADR-0086)
|
|
1472
|
+
* whole: every artboard (with its pacing `role`) and every element are
|
|
1473
|
+
* kept, membership tags preserved, so `toJSON()` / `toServerRequest()`
|
|
1474
|
+
* emit all pages and `TemplateField.artboard` can scope fields per page.
|
|
1475
|
+
*/
|
|
1476
|
+
static fromState(e, o = {}) {
|
|
1477
|
+
const n = e.artboards.find((r) => r.name === e.activeArtboard) ?? e.artboards[0];
|
|
1478
|
+
if (!n)
|
|
1479
|
+
throw new Error("DesignBuilder.fromState(): state has no artboards");
|
|
1480
|
+
const i = new de({
|
|
1481
|
+
name: n.name,
|
|
1482
|
+
width: n.width,
|
|
1483
|
+
height: n.height,
|
|
1484
|
+
backgroundColor: n.backgroundColor,
|
|
1485
|
+
role: n.role
|
|
1486
|
+
});
|
|
1487
|
+
if (o.artboards === "all") {
|
|
1488
|
+
i.allArtboards = e.artboards.map((r) => ({ ...r }));
|
|
1489
|
+
for (const r of e.elements)
|
|
1490
|
+
i.els.push(r.artboard ? { ...r } : { ...r, artboard: n.name });
|
|
1491
|
+
return i;
|
|
1492
|
+
}
|
|
1493
|
+
for (const r of e.elements)
|
|
1494
|
+
r.artboard && r.artboard !== n.name || i.els.push({ ...r });
|
|
1495
|
+
return i;
|
|
1496
|
+
}
|
|
1497
|
+
nextId(e) {
|
|
1498
|
+
return `${e}-${++this.idCounter}`;
|
|
1499
|
+
}
|
|
1500
|
+
/** A wire-shape snapshot of an authoring artboard, applying the same
|
|
1501
|
+
* background-export rule everywhere (a design background is part of the
|
|
1502
|
+
* design — exports and server renders paint it). */
|
|
1503
|
+
static snapshotArtboard(e) {
|
|
1504
|
+
return {
|
|
1505
|
+
name: e.name,
|
|
1506
|
+
width: e.width,
|
|
1507
|
+
height: e.height,
|
|
1508
|
+
...e.backgroundColor ? {
|
|
1509
|
+
backgroundColor: e.backgroundColor,
|
|
1510
|
+
exportBackground: e.backgroundColor !== "transparent"
|
|
1511
|
+
} : {},
|
|
1512
|
+
...e.role ? { role: e.role } : {}
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Open a NEW artboard (placement) and make it the authoring context: layer
|
|
1517
|
+
* calls after this target the new artboard — anchor math uses its
|
|
1518
|
+
* dimensions, and the elements carry its membership tag (the public
|
|
1519
|
+
* `artboard` field, PR #482). The FIRST artboard (from `design({ name })`)
|
|
1520
|
+
* remains the initially-active placement when the design mounts; switch at
|
|
1521
|
+
* runtime with `usePlacements()` / `<Editor.Placements/>` (ADR-0088).
|
|
1522
|
+
*
|
|
1523
|
+
* `label` must be the product's placement label (case-sensitive) — the same
|
|
1524
|
+
* artboard-name-is-placement-label rule as `design({ name })`.
|
|
1525
|
+
*
|
|
1526
|
+
* ```ts
|
|
1527
|
+
* const seed = design({ name: 'Front', width: 1480, height: 2328 })
|
|
1528
|
+
* .text('YOUR NAME', { anchor: 'top', name: 'headline' })
|
|
1529
|
+
* .artboard('Back', { width: 1480, height: 2328 })
|
|
1530
|
+
* .text('EST. 2026', { anchor: 'center', name: 'backline' });
|
|
1531
|
+
* ```
|
|
1532
|
+
*
|
|
1533
|
+
* @throws EditorError `E_DUPLICATE_ARTBOARD` — the design already has an
|
|
1534
|
+
* artboard with this label.
|
|
1535
|
+
*/
|
|
1536
|
+
artboard(e, o) {
|
|
1537
|
+
if (!(o.width > 0) || !(o.height > 0))
|
|
1538
|
+
throw new Error("design().artboard(): width and height must be positive numbers");
|
|
1539
|
+
if (this.allArtboards || (this.allArtboards = [de.snapshotArtboard(this.current)]), this.allArtboards.some((n) => n.name === e))
|
|
1540
|
+
throw new te(
|
|
1541
|
+
"E_DUPLICATE_ARTBOARD",
|
|
1542
|
+
`the design already has an artboard "${e}" — artboard names are placement labels and must be unique. Existing: ${JSON.stringify(this.allArtboards.map((n) => n.name))}.`,
|
|
1543
|
+
{ artboardName: e, validNames: this.allArtboards.map((n) => n.name), docSlug: "embed-mode" }
|
|
1544
|
+
);
|
|
1545
|
+
for (const n of this.els)
|
|
1546
|
+
n.artboard || (n.artboard = this.current.name);
|
|
1547
|
+
return this.current = {
|
|
1548
|
+
name: e,
|
|
1549
|
+
width: o.width,
|
|
1550
|
+
height: o.height,
|
|
1551
|
+
backgroundColor: be(o.backgroundColor),
|
|
1552
|
+
role: o.role
|
|
1553
|
+
}, this.allArtboards.push(de.snapshotArtboard(this.current)), this;
|
|
1554
|
+
}
|
|
1555
|
+
background(e, o = {}) {
|
|
1556
|
+
const { width: n, height: i } = this.current;
|
|
1557
|
+
let r;
|
|
1558
|
+
if (o.aspectRatio && o.aspectRatio > 0) {
|
|
1559
|
+
const s = bo(o.aspectRatio, n, i);
|
|
1560
|
+
r = {
|
|
1561
|
+
type: "image",
|
|
1562
|
+
width: s.width,
|
|
1563
|
+
height: s.height,
|
|
1564
|
+
cropX: s.cropX,
|
|
1565
|
+
cropY: s.cropY,
|
|
1566
|
+
cropWidth: s.cropWidth,
|
|
1567
|
+
cropHeight: s.cropHeight,
|
|
1568
|
+
flipHorizontal: !1,
|
|
1569
|
+
flipVertical: !1,
|
|
1570
|
+
borderRadius: 0
|
|
1571
|
+
};
|
|
1572
|
+
} else
|
|
1573
|
+
r = {
|
|
1574
|
+
type: "image",
|
|
1575
|
+
width: n,
|
|
1576
|
+
height: i,
|
|
1577
|
+
cropX: 0,
|
|
1578
|
+
cropY: 0,
|
|
1579
|
+
cropWidth: 1,
|
|
1580
|
+
cropHeight: 1,
|
|
1581
|
+
flipHorizontal: !1,
|
|
1582
|
+
flipVertical: !1,
|
|
1583
|
+
borderRadius: 0
|
|
1584
|
+
};
|
|
1585
|
+
const a = {
|
|
1586
|
+
id: this.nextId("bg"),
|
|
1587
|
+
transformType: "image",
|
|
1588
|
+
x: n / 2,
|
|
1589
|
+
y: i / 2,
|
|
1590
|
+
rotation: 0,
|
|
1591
|
+
opacity: o.opacity ?? 1,
|
|
1592
|
+
imageUrl: e,
|
|
1593
|
+
imageAspectRatio: o.aspectRatio,
|
|
1594
|
+
transformData: r,
|
|
1595
|
+
name: o.name ?? "Background"
|
|
1596
|
+
};
|
|
1597
|
+
return this.els.unshift(a), this;
|
|
1598
|
+
}
|
|
1599
|
+
image(e, o = {}) {
|
|
1600
|
+
const { width: n, height: i } = this.current, r = o.width ?? Math.round(n / 3), a = o.height ?? (o.aspectRatio ? Math.round(r / o.aspectRatio) : r), { x: s, y: d } = Ve(o.anchor ?? je, r, a, n, i, o.padding ?? 0), c = {
|
|
1601
|
+
id: this.nextId("img"),
|
|
1602
|
+
transformType: "image",
|
|
1603
|
+
x: s,
|
|
1604
|
+
y: d,
|
|
1605
|
+
rotation: o.rotation ?? 0,
|
|
1606
|
+
opacity: o.opacity ?? 1,
|
|
1607
|
+
imageUrl: e,
|
|
1608
|
+
imageAspectRatio: o.aspectRatio,
|
|
1609
|
+
transformData: {
|
|
1610
|
+
type: "image",
|
|
1611
|
+
width: r,
|
|
1612
|
+
height: a,
|
|
1613
|
+
cropX: 0,
|
|
1614
|
+
cropY: 0,
|
|
1615
|
+
cropWidth: 1,
|
|
1616
|
+
cropHeight: 1,
|
|
1617
|
+
flipHorizontal: !1,
|
|
1618
|
+
flipVertical: !1,
|
|
1619
|
+
borderRadius: 0
|
|
1620
|
+
},
|
|
1621
|
+
...o.name ? { name: o.name } : {}
|
|
1622
|
+
};
|
|
1623
|
+
return this.els.push(c), this;
|
|
1624
|
+
}
|
|
1625
|
+
text(e, o = {}) {
|
|
1626
|
+
const { width: n, height: i } = this.current, r = o.fontSize ?? Math.round(this.current.height / 12), { x: a, y: s } = Ve(o.anchor ?? "top", 0, r, n, i, o.padding ?? Math.round(i / 20)), d = {
|
|
1627
|
+
id: this.nextId("text"),
|
|
1628
|
+
transformType: "custom",
|
|
1629
|
+
x: a,
|
|
1630
|
+
y: s,
|
|
1631
|
+
rotation: o.rotation ?? 0,
|
|
1632
|
+
text: e,
|
|
1633
|
+
fontSize: r,
|
|
1634
|
+
fontFamily: o.fontFamily ?? "Anton",
|
|
1635
|
+
color: be(o.color) ?? "#ffffff",
|
|
1636
|
+
textAlign: o.textAlign ?? "center",
|
|
1637
|
+
bold: o.bold ?? !1,
|
|
1638
|
+
italic: o.italic ?? !1,
|
|
1639
|
+
transformData: { type: "custom" },
|
|
1640
|
+
...o.name ? { name: o.name } : {}
|
|
1641
|
+
};
|
|
1642
|
+
return this.els.push(d), this;
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Mint a {@link LayerToken} for a named layer — the only currency
|
|
1646
|
+
* `Editor.TextField` accepts (ADR-0085 §1). Compile time: `name` is
|
|
1647
|
+
* constrained to this design's declared layer names, kind inferred from
|
|
1648
|
+
* which per-kind union it falls in. Runtime: validated EAGERLY against the
|
|
1649
|
+
* built elements (nearest the mistake), so CMS/JSON-loaded designs get the
|
|
1650
|
+
* same protection with `string` typing.
|
|
1651
|
+
*
|
|
1652
|
+
* @throws EditorError `E_LAYER_NOT_FOUND` — no layer with this name; lists
|
|
1653
|
+
* the valid names per kind.
|
|
1654
|
+
* @throws EditorError `E_LAYER_WRONG_KIND` — the name matches a layer that
|
|
1655
|
+
* is not bindable (shape/group/path).
|
|
1656
|
+
*/
|
|
1657
|
+
layer(e) {
|
|
1658
|
+
const o = this.els.find((i) => i.name === e);
|
|
1659
|
+
if (!o) {
|
|
1660
|
+
const i = this.layerNamesOfKind("text"), r = this.layerNamesOfKind("image");
|
|
1661
|
+
throw new te(
|
|
1662
|
+
"E_LAYER_NOT_FOUND",
|
|
1663
|
+
`no layer "${e}" in this design. Text layers: ${JSON.stringify(i)}; image layers: ${JSON.stringify(r)}. Fix the name, or add the layer first — e.g. design(…).text('…', { name: '${e}' }).`,
|
|
1664
|
+
{ layerName: e, validNames: [...i, ...r], textNames: i, imageNames: r, docSlug: "embed-mode" }
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
const n = $e(o);
|
|
1668
|
+
if (!n)
|
|
1669
|
+
throw new te(
|
|
1670
|
+
"E_LAYER_WRONG_KIND",
|
|
1671
|
+
`layer "${e}" is a ${o.transformType} element — only text and image layers are bindable. Bindable layers: ${JSON.stringify([...this.layerNamesOfKind("text"), ...this.layerNamesOfKind("image")])}.`,
|
|
1672
|
+
{ layerName: e, actualType: o.transformType, docSlug: "embed-mode" }
|
|
1673
|
+
);
|
|
1674
|
+
return po(n, e);
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Mint a {@link ColorToken} for a declared color role. Compile time: `name`
|
|
1678
|
+
* is constrained to the roles declared in `design({ colors })`. Runtime:
|
|
1679
|
+
* validated against the declared roles (CMS/JSON-built designs degrade to
|
|
1680
|
+
* `string` typing and rely on this throw).
|
|
1681
|
+
*
|
|
1682
|
+
* Use the token wherever the design paints the role (`fill`, `color`) AND
|
|
1683
|
+
* as the `useColorBinding` argument — one source of truth, no hand-synced
|
|
1684
|
+
* hex pairs.
|
|
1685
|
+
*
|
|
1686
|
+
* @throws EditorError `E_COLOR_ROLE_NOT_FOUND` — no role with this name;
|
|
1687
|
+
* lists the declared roles.
|
|
1688
|
+
*/
|
|
1689
|
+
color(e) {
|
|
1690
|
+
const o = this.colorRoles.get(e);
|
|
1691
|
+
if (o === void 0)
|
|
1692
|
+
throw new te(
|
|
1693
|
+
"E_COLOR_ROLE_NOT_FOUND",
|
|
1694
|
+
`no color role "${e}" in this design. Declared roles: ${JSON.stringify([...this.colorRoles.keys()])}. Declare roles up front — design({ …, colors: { ${e}: '#FF2D8A' } }).`,
|
|
1695
|
+
{ roleName: e, validNames: [...this.colorRoles.keys()], docSlug: "embed-mode" }
|
|
1696
|
+
);
|
|
1697
|
+
return Ao(e, o);
|
|
1698
|
+
}
|
|
1699
|
+
/** Names of bindable layers of one kind, in stack order. @internal */
|
|
1700
|
+
layerNamesOfKind(e) {
|
|
1701
|
+
return this.els.filter((o) => $e(o) === e).map((o) => o.name).filter((o) => !!o);
|
|
1702
|
+
}
|
|
1703
|
+
/** An anchored vector shape. */
|
|
1704
|
+
shape(e, o = {}) {
|
|
1705
|
+
const { width: n, height: i } = this.current, r = o.size ?? Math.round(n / 6), a = typeof r == "number" ? r : r.width, s = typeof r == "number" ? r : r.height, { x: d, y: c } = Ve(o.anchor ?? je, a, s, n, i, o.padding ?? 0), R = {
|
|
1706
|
+
type: "shape",
|
|
1707
|
+
shapeType: e,
|
|
1708
|
+
width: a,
|
|
1709
|
+
height: s,
|
|
1710
|
+
fillColor: be(o.fill) ?? "#000000",
|
|
1711
|
+
fillOpacity: o.opacity ?? 1,
|
|
1712
|
+
...o.points !== void 0 ? { points: o.points } : {},
|
|
1713
|
+
...o.sides !== void 0 ? { sides: o.sides } : {}
|
|
1714
|
+
}, O = {
|
|
1715
|
+
id: this.nextId("shape"),
|
|
1716
|
+
transformType: "shape",
|
|
1717
|
+
x: d,
|
|
1718
|
+
y: c,
|
|
1719
|
+
rotation: o.rotation ?? 0,
|
|
1720
|
+
transformData: R,
|
|
1721
|
+
...o.name ? { name: o.name } : {}
|
|
1722
|
+
};
|
|
1723
|
+
return this.els.push(O), this;
|
|
1724
|
+
}
|
|
1725
|
+
/** The composed elements, in render order (background first). Editor shape. */
|
|
1726
|
+
get elements() {
|
|
1727
|
+
return this.els.map((e) => ({ ...e }));
|
|
1728
|
+
}
|
|
1729
|
+
/** Editor-shape canvas state for `<SnowconeCanvas initialElements=… />` and
|
|
1730
|
+
* `serializeStateForServer`. `activeArtboard` is the artboard name. A
|
|
1731
|
+
* builder loaded with `fromState(…, { artboards: 'all' })` emits every
|
|
1732
|
+
* page (artboard `role`s and element membership tags included). */
|
|
1733
|
+
toJSON() {
|
|
1734
|
+
return this.allArtboards ? {
|
|
1735
|
+
// Elements added via builder methods since the last context switch are
|
|
1736
|
+
// untagged — they belong to the CURRENT authoring artboard; stamp them
|
|
1737
|
+
// so the multi-artboard state groups them correctly.
|
|
1738
|
+
elements: this.els.map(
|
|
1739
|
+
(e) => e.artboard ? { ...e } : { ...e, artboard: this.current.name }
|
|
1740
|
+
),
|
|
1741
|
+
artboards: this.allArtboards.map((e) => ({ ...e })),
|
|
1742
|
+
// The initially-active placement (first artboard / saved state's
|
|
1743
|
+
// active) — NOT the last `.artboard()` authoring context.
|
|
1744
|
+
activeArtboard: this.activeName
|
|
1745
|
+
} : {
|
|
1746
|
+
elements: this.elements,
|
|
1747
|
+
// A background set on a design is part of the design: flag it renderable
|
|
1748
|
+
// so exports and server renders paint it, matching the editor (the
|
|
1749
|
+
// export worker skips it without `exportBackground`) — see snapshotArtboard.
|
|
1750
|
+
artboards: [de.snapshotArtboard(this.current)],
|
|
1751
|
+
activeArtboard: this.current.name
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
/** Server-render payload for `RenderSession.renderState(placement, …)`.
|
|
1755
|
+
* Equivalent to `serializeStateForServer(design.toJSON())`. */
|
|
1756
|
+
toServerRequest() {
|
|
1757
|
+
return $t(this.toJSON());
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
function Wo(t) {
|
|
1761
|
+
return new de(t);
|
|
1762
|
+
}
|
|
1763
|
+
function Mo(t) {
|
|
1764
|
+
return $e(t);
|
|
1765
|
+
}
|
|
1766
|
+
export {
|
|
1767
|
+
ot as B,
|
|
1768
|
+
de as D,
|
|
1769
|
+
Ho as E,
|
|
1770
|
+
nt as P,
|
|
1771
|
+
Uo as a,
|
|
1772
|
+
Lo as b,
|
|
1773
|
+
so as c,
|
|
1774
|
+
st as d,
|
|
1775
|
+
ro as e,
|
|
1776
|
+
Wo as f,
|
|
1777
|
+
ko as g,
|
|
1778
|
+
_o as h,
|
|
1779
|
+
Oo as i,
|
|
1780
|
+
Po as j,
|
|
1781
|
+
Fo as k,
|
|
1782
|
+
it as l,
|
|
1783
|
+
No as m,
|
|
1784
|
+
lo as n,
|
|
1785
|
+
Vo as o,
|
|
1786
|
+
eo as p,
|
|
1787
|
+
Bo as q,
|
|
1788
|
+
$o as r,
|
|
1789
|
+
Mt as s,
|
|
1790
|
+
go as t,
|
|
1791
|
+
zo as u,
|
|
1792
|
+
Mo as v,
|
|
1793
|
+
Co as w,
|
|
1794
|
+
Do as x,
|
|
1795
|
+
Yt as y,
|
|
1796
|
+
vo as z
|
|
1797
|
+
};
|
|
1798
|
+
//# sourceMappingURL=design-builder-HKRo18WT.js.map
|