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