@snowcone-app/canvas 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/STYLING_CONTRACT.md +114 -85
- package/dist/{EditorCanvasImpl-BH_bKy-F.js → EditorCanvasImpl-Ckg7WO2j.js} +4 -4
- package/dist/{EditorCanvasImpl-BH_bKy-F.js.map → EditorCanvasImpl-Ckg7WO2j.js.map} +1 -1
- package/dist/{SnowconeCanvas-Cx7nXlBI.js → SnowconeCanvas-D1sLcIja.js} +2 -2
- package/dist/{SnowconeCanvas-Cx7nXlBI.js.map → SnowconeCanvas-D1sLcIja.js.map} +1 -1
- package/dist/api/embed.d.ts +2 -2
- package/dist/design/design-builder.d.ts +67 -12
- package/dist/design-builder-2VUjfmdt.js +422 -0
- package/dist/design-builder-2VUjfmdt.js.map +1 -0
- package/dist/editorErrors-B2mb1sVN.js.map +1 -1
- package/dist/{embed-8ecUMMH-.js → embed-DxsaqZJF.js} +4 -4
- package/dist/{embed-8ecUMMH-.js.map → embed-DxsaqZJF.js.map} +1 -1
- package/dist/embed.mjs +21 -20
- package/dist/errors/editorError.d.ts +10 -0
- package/dist/hooks/bindingGuards.d.ts +16 -0
- package/dist/hooks/useColorBinding.d.ts +2 -1
- package/dist/hooks/useFontBinding.d.ts +2 -1
- package/dist/hooks/useImageBinding.d.ts +2 -1
- package/dist/hooks/useTextBinding.d.ts +2 -1
- package/dist/index.mjs +3 -3
- package/dist/template-fields-CQ6n2P4V.js +548 -0
- package/dist/template-fields-CQ6n2P4V.js.map +1 -0
- package/dist/testing/failureFixtures.d.ts +2 -2
- package/dist/testing.mjs +1 -1
- package/example/package.json +1 -1
- package/package.json +1 -1
- package/dist/design-builder-CT4DHIPe.js +0 -367
- package/dist/design-builder-CT4DHIPe.js.map +0 -1
- package/dist/template-fields-C2pSfMBh.js +0 -494
- package/dist/template-fields-C2pSfMBh.js.map +0 -1
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import { g as C, u as tt, c as O, b as S } from "./editorErrors-B2mb1sVN.js";
|
|
2
|
+
import { l as V, i as it, a as rt } from "./design-builder-2VUjfmdt.js";
|
|
3
|
+
import { toOptionAttributes as at, toCombinations as ct, getMissingSelections as lt, validateProductSelection as ut, findBestCombination as R, computeDisabledChoices as mt } from "@snowcone-app/sdk";
|
|
4
|
+
import { useCallback as N, useEffect as ft, useContext as et, useId as dt, useLayoutEffect as ht, useRef as D, useMemo as A, useState as G } from "react";
|
|
5
|
+
import { c as gt, y as q, T as w, I as Y, z as pt } from "./FontAnalyzer-CwIpgTGd.js";
|
|
6
|
+
import { p as nt, U as yt } from "./UnifiedFontService-CC3CSmH5.js";
|
|
7
|
+
import { a as bt, o as $, b as m, n as xt, l as y, u as z, c as vt } from "./CanvasStateV1-DmZ1Qvvn.js";
|
|
8
|
+
function U(s) {
|
|
9
|
+
return s.text;
|
|
10
|
+
}
|
|
11
|
+
function E(s) {
|
|
12
|
+
return s.name;
|
|
13
|
+
}
|
|
14
|
+
class jt {
|
|
15
|
+
constructor(t) {
|
|
16
|
+
this.listeners = /* @__PURE__ */ new Set(), this.getState = () => this.state, this.subscribe = (o) => (this.listeners.add(o), () => this.listeners.delete(o)), this.state = t;
|
|
17
|
+
const n = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const o of t.elements) {
|
|
19
|
+
const e = E(o), i = U(o);
|
|
20
|
+
e && typeof i == "string" && n.set(e, i);
|
|
21
|
+
}
|
|
22
|
+
this.seedTextByName = n;
|
|
23
|
+
}
|
|
24
|
+
/** Replace the whole state (the canvas `onChange` path). */
|
|
25
|
+
setState(t) {
|
|
26
|
+
this.state = t, this.emit();
|
|
27
|
+
}
|
|
28
|
+
/** The seed value of a named text layer (for completeness rule C3). */
|
|
29
|
+
seedTextOf(t) {
|
|
30
|
+
return this.seedTextByName.get(t);
|
|
31
|
+
}
|
|
32
|
+
/** Current text of a named text layer, or undefined when absent. */
|
|
33
|
+
textOf(t) {
|
|
34
|
+
const n = this.state.elements.find((o) => E(o) === t);
|
|
35
|
+
return n ? U(n) : void 0;
|
|
36
|
+
}
|
|
37
|
+
/** Kind of the named layer in the CURRENT state ('text' | 'image' | null
|
|
38
|
+
* for unbindable), or undefined when no layer has the name. */
|
|
39
|
+
layerKindOf(t) {
|
|
40
|
+
const n = this.state.elements.find((o) => E(o) === t);
|
|
41
|
+
return n ? V(n) : void 0;
|
|
42
|
+
}
|
|
43
|
+
/** Names of bindable layers in the current state, for error messages. */
|
|
44
|
+
bindableLayerNames() {
|
|
45
|
+
return this.state.elements.filter((t) => V(t) !== null).map(E).filter((t) => !!t);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Direct write path for `Editor.TextField` when NO canvas is mounted (with
|
|
49
|
+
* one, writes route through the editor command path and arrive back here
|
|
50
|
+
* via `setState`). Immutable update; last-write-wins.
|
|
51
|
+
*/
|
|
52
|
+
updateTextLayer(t, n) {
|
|
53
|
+
let o = !1;
|
|
54
|
+
const e = this.state.elements.map((i) => E(i) !== t ? i : (o = !0, { ...i, text: n }));
|
|
55
|
+
if (!o)
|
|
56
|
+
throw new C(
|
|
57
|
+
"E_LAYER_NOT_FOUND",
|
|
58
|
+
`no layer "${t}" in the current design state. Bindable layers: ${JSON.stringify(this.bindableLayerNames())}.`,
|
|
59
|
+
{ layerName: t, validNames: this.bindableLayerNames(), docSlug: "embed-mode" }
|
|
60
|
+
);
|
|
61
|
+
this.setState({ ...this.state, elements: e });
|
|
62
|
+
}
|
|
63
|
+
/** ≥1 element with visible content (completeness rule C4): non-empty text,
|
|
64
|
+
* an image with a URL, or a shape. Hidden elements don't count. */
|
|
65
|
+
hasRenderableElement() {
|
|
66
|
+
return this.state.elements.some((t) => {
|
|
67
|
+
if (t.visible === !1) return !1;
|
|
68
|
+
const n = t.transformType;
|
|
69
|
+
if (n === "image") return !!t.imageUrl;
|
|
70
|
+
if (n === "shape" || n === "group" || n === "path") return !0;
|
|
71
|
+
const o = U(t);
|
|
72
|
+
return typeof o == "string" && o.trim().length > 0;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
emit() {
|
|
76
|
+
for (const t of [...this.listeners]) t();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function X(s) {
|
|
80
|
+
return (s.choices ?? []).map((t) => typeof t == "string" ? t : t.label ?? "").filter((t) => t !== "");
|
|
81
|
+
}
|
|
82
|
+
function Ct(s, t) {
|
|
83
|
+
if (!s.variantId) return {};
|
|
84
|
+
const n = t.find((e) => e.variantId === s.variantId);
|
|
85
|
+
if (!n) return {};
|
|
86
|
+
const o = {};
|
|
87
|
+
for (const [e, i] of Object.entries(n))
|
|
88
|
+
e === "variantId" || e === "price" || (typeof i == "string" ? o[e] = i : typeof i == "number" && (o[e] = String(i)));
|
|
89
|
+
return o;
|
|
90
|
+
}
|
|
91
|
+
class Kt {
|
|
92
|
+
constructor(t) {
|
|
93
|
+
this.quantity = 1, this.version = 0, this.listeners = /* @__PURE__ */ new Set(), this.getVersion = () => this.version, this.subscribe = (n) => (this.listeners.add(n), () => this.listeners.delete(n)), this.product = t, this.attrs = at({ options: t.options }), this.combos = ct({ options: t.options }), this.selection = Ct(t, this.combos);
|
|
94
|
+
}
|
|
95
|
+
getAttributes() {
|
|
96
|
+
return this.attrs;
|
|
97
|
+
}
|
|
98
|
+
getSelection() {
|
|
99
|
+
return this.selection;
|
|
100
|
+
}
|
|
101
|
+
getQuantity() {
|
|
102
|
+
return this.quantity;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Select a choice for a variant attribute. Strict + loud (D4/E3): an
|
|
106
|
+
* attribute key or choice that doesn't exist on the product is a wiring
|
|
107
|
+
* mistake, not user state — throws `E_UNKNOWN_OPTION` listing what IS valid.
|
|
108
|
+
*/
|
|
109
|
+
select(t, n) {
|
|
110
|
+
const o = this.attrs[t];
|
|
111
|
+
if (!o)
|
|
112
|
+
throw new C(
|
|
113
|
+
"E_UNKNOWN_OPTION",
|
|
114
|
+
`product ${this.product.productId} has no option "${t}". Valid option keys: ${JSON.stringify(Object.keys(this.attrs))}.`,
|
|
115
|
+
{ key: t, validKeys: Object.keys(this.attrs), docSlug: "embed-mode" }
|
|
116
|
+
);
|
|
117
|
+
const e = X(o);
|
|
118
|
+
if (e.length > 0 && !e.includes(n))
|
|
119
|
+
throw new C(
|
|
120
|
+
"E_UNKNOWN_OPTION",
|
|
121
|
+
`"${n}" is not a choice of option "${t}" on product ${this.product.productId}. Valid choices: ${JSON.stringify(e)}.`,
|
|
122
|
+
{ key: t, choice: n, validChoices: e, docSlug: "embed-mode" }
|
|
123
|
+
);
|
|
124
|
+
this.selection[t] !== n && (this.selection = { ...this.selection, [t]: n }, this.bump());
|
|
125
|
+
}
|
|
126
|
+
/** Quantity is USER state (completeness rule C5 gates on it) — never throws. */
|
|
127
|
+
setQuantity(t) {
|
|
128
|
+
this.quantity !== t && (this.quantity = t, this.bump());
|
|
129
|
+
}
|
|
130
|
+
/** Attribute keys still required (non-optional) but unselected — Buy's
|
|
131
|
+
* `option:<key>` reason codes. */
|
|
132
|
+
missingOptionKeys() {
|
|
133
|
+
return Object.keys(this.attrs).length === 0 ? [] : lt(this.attrs, this.selection);
|
|
134
|
+
}
|
|
135
|
+
/** Full selection resolution (the C1 amendment): true when every required
|
|
136
|
+
* attribute is selected AND the selection matches a valid combination. */
|
|
137
|
+
selectionValid() {
|
|
138
|
+
return Object.keys(this.attrs).length === 0 ? !0 : ut(this.attrs, this.selection, this.combos);
|
|
139
|
+
}
|
|
140
|
+
/** The variant (gvid) the current selection resolves to. Falls back to the
|
|
141
|
+
* product's initial `variantId` while nothing has been selected. */
|
|
142
|
+
resolvedVariantId() {
|
|
143
|
+
if (Object.keys(this.attrs).length === 0 || this.combos.length === 0)
|
|
144
|
+
return this.product.variantId;
|
|
145
|
+
if (!this.selectionValid()) return;
|
|
146
|
+
const t = R(this.selection, this.combos, this.attrs);
|
|
147
|
+
return (typeof (t == null ? void 0 : t.variantId) == "string" && t.variantId !== "" ? t.variantId : void 0) ?? this.product.variantId;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The variant (gvid) to RENDER with — deliberately looser than
|
|
151
|
+
* {@link resolvedVariantId}. That one is Buy's currency: it returns
|
|
152
|
+
* `undefined` while the selection is incomplete so completeness can gate.
|
|
153
|
+
* But the PRODUCT PHOTO must follow the shopper's picks immediately —
|
|
154
|
+
* "choose the Oak frame" should render Oak even while an unrelated axis
|
|
155
|
+
* (size, pocket) is still unselected. This resolves the best combination
|
|
156
|
+
* matching the CURRENT (possibly partial) selection, falling back to the
|
|
157
|
+
* product's initial variant. (Before this split, switching a color swatch
|
|
158
|
+
* with any axis unselected rendered nothing — the mockup silently stayed
|
|
159
|
+
* on the old color.)
|
|
160
|
+
*/
|
|
161
|
+
renderVariantId() {
|
|
162
|
+
if (Object.keys(this.attrs).length === 0 || this.combos.length === 0)
|
|
163
|
+
return this.product.variantId;
|
|
164
|
+
const t = R(this.selection, this.combos, this.attrs);
|
|
165
|
+
return (typeof (t == null ? void 0 : t.variantId) == "string" && t.variantId !== "" ? t.variantId : void 0) ?? this.product.variantId;
|
|
166
|
+
}
|
|
167
|
+
/** Price of the resolved combination, when the catalog carries one. */
|
|
168
|
+
resolvedPrice() {
|
|
169
|
+
if (!this.selectionValid()) return;
|
|
170
|
+
const t = R(this.selection, this.combos, this.attrs);
|
|
171
|
+
return typeof (t == null ? void 0 : t.price) == "number" ? t.price : void 0;
|
|
172
|
+
}
|
|
173
|
+
/** Choices invalid given the rest of the current selection — for hosts to
|
|
174
|
+
* disable/grey out in their variant UI. */
|
|
175
|
+
disabledChoices() {
|
|
176
|
+
const t = {};
|
|
177
|
+
for (const [n, o] of Object.entries(this.attrs))
|
|
178
|
+
t[n] = { ...o, choices: X(o) };
|
|
179
|
+
return mt(this.selection, t, this.combos);
|
|
180
|
+
}
|
|
181
|
+
/** The combinations (for payload assembly via `createCartDetail`). */
|
|
182
|
+
getCombinations() {
|
|
183
|
+
return this.combos;
|
|
184
|
+
}
|
|
185
|
+
bump() {
|
|
186
|
+
this.version++;
|
|
187
|
+
for (const t of [...this.listeners]) t();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const J = gt("useCommands");
|
|
191
|
+
function Vt() {
|
|
192
|
+
const s = tt(), {
|
|
193
|
+
undo: t,
|
|
194
|
+
redo: n,
|
|
195
|
+
canUndo: o,
|
|
196
|
+
canRedo: e,
|
|
197
|
+
executeElementUpdate: i,
|
|
198
|
+
executeAddElement: a,
|
|
199
|
+
executeRemoveElement: r,
|
|
200
|
+
executeReorderElement: l,
|
|
201
|
+
executeCommandBatch: c,
|
|
202
|
+
executeCreateArtboard: u,
|
|
203
|
+
executeDeleteArtboard: b,
|
|
204
|
+
executeUpdateArtboard: v
|
|
205
|
+
} = s, d = N(() => {
|
|
206
|
+
J.warn("[useCommands] clearHistory is not yet implemented in EditorContext");
|
|
207
|
+
}, []), h = N((_) => {
|
|
208
|
+
J.warn("[useCommands] clearArtboardHistory is not yet implemented in EditorContext");
|
|
209
|
+
}, []);
|
|
210
|
+
return {
|
|
211
|
+
// Undo/Redo
|
|
212
|
+
undo: t,
|
|
213
|
+
redo: n,
|
|
214
|
+
canUndo: o,
|
|
215
|
+
canRedo: e,
|
|
216
|
+
// History management
|
|
217
|
+
clearHistory: d,
|
|
218
|
+
clearArtboardHistory: h,
|
|
219
|
+
// Command execution
|
|
220
|
+
executeElementUpdate: i,
|
|
221
|
+
executeAddElement: a,
|
|
222
|
+
executeRemoveElement: r,
|
|
223
|
+
executeReorderElement: l,
|
|
224
|
+
executeCreateArtboard: u,
|
|
225
|
+
executeDeleteArtboard: b,
|
|
226
|
+
executeUpdateArtboard: v,
|
|
227
|
+
// Batch execution
|
|
228
|
+
executeCommandBatch: c
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function Gt() {
|
|
232
|
+
const { selectedElement: s } = tt();
|
|
233
|
+
return s ?? null;
|
|
234
|
+
}
|
|
235
|
+
const Nt = 3e3, Q = {
|
|
236
|
+
text: "useTextBinding",
|
|
237
|
+
image: "useImageBinding",
|
|
238
|
+
font: "useFontBinding"
|
|
239
|
+
}, $t = {
|
|
240
|
+
text: "setText",
|
|
241
|
+
image: "setImageUrl",
|
|
242
|
+
font: "setFontFamily"
|
|
243
|
+
}, Et = {
|
|
244
|
+
text: "text",
|
|
245
|
+
image: "image",
|
|
246
|
+
font: "text"
|
|
247
|
+
}, L = /* @__PURE__ */ new Set();
|
|
248
|
+
function Z(s) {
|
|
249
|
+
return s instanceof w ? "text" : s instanceof Y ? "image" : "other";
|
|
250
|
+
}
|
|
251
|
+
function Dt(s, t, n) {
|
|
252
|
+
const o = `[${Q[s]}]`, e = `the binding is dead (isConnected: false, ${$t[s]} is a no-op)`, i = Et[s], a = n.getAllByName(t);
|
|
253
|
+
if (a.length > 0) {
|
|
254
|
+
const c = [...new Set(a.map(Z))], u = i === "text" ? "image" : "text", b = c.length === 1 && c[0] === u ? ` Bind it with ${Q[u]}("${t}") instead.` : "";
|
|
255
|
+
return `${o} the layer named "${t}" is ${c.join("/")}, not ${i} — ${e}.${b}`;
|
|
256
|
+
}
|
|
257
|
+
const r = n.getAll().filter((c) => c.name).map((c) => `"${c.name}" (${Z(c)})`), l = r.length ? `Named layers on this canvas: ${r.join(", ")}. Check the name for a typo.` : `No element on this canvas has a name — name one via design().${i}(…, { name: '${t}' }) or the element's \`name\` property.`;
|
|
258
|
+
return `${o} no ${i} layer named "${t}" exists — ${e}. ${l}`;
|
|
259
|
+
}
|
|
260
|
+
function H(s, t, n, o) {
|
|
261
|
+
ft(() => {
|
|
262
|
+
var a;
|
|
263
|
+
if (o || typeof q > "u" || ((a = q.env) == null ? void 0 : a.NODE_ENV) === "production") return;
|
|
264
|
+
const e = `${s}:${t}`;
|
|
265
|
+
if (L.has(e)) return;
|
|
266
|
+
const i = setTimeout(() => {
|
|
267
|
+
L.has(e) || (L.add(e), console.warn(Dt(s, t, n)));
|
|
268
|
+
}, Nt);
|
|
269
|
+
return () => clearTimeout(i);
|
|
270
|
+
}, [s, t, n, o]);
|
|
271
|
+
}
|
|
272
|
+
function k(s) {
|
|
273
|
+
const t = et(nt), n = dt();
|
|
274
|
+
ht(() => {
|
|
275
|
+
if (t)
|
|
276
|
+
return t.registry.requireCanvas(n, s);
|
|
277
|
+
}, [t, n, s]);
|
|
278
|
+
}
|
|
279
|
+
function M(s) {
|
|
280
|
+
return s instanceof w ? "text" : s instanceof Y ? "image" : null;
|
|
281
|
+
}
|
|
282
|
+
const Ot = {
|
|
283
|
+
text: "useTextBinding / useFontBinding",
|
|
284
|
+
image: "useImageBinding"
|
|
285
|
+
};
|
|
286
|
+
function P(s, t, n) {
|
|
287
|
+
const o = it(s), e = o ? s.name : s, i = et(nt), a = D(null);
|
|
288
|
+
if (o && s.kind !== t)
|
|
289
|
+
throw new C(
|
|
290
|
+
"E_LAYER_WRONG_KIND",
|
|
291
|
+
`layer "${e}" is a ${s.kind} token — this hook binds ${t} layers only (use ${Ot[s.kind]}).`,
|
|
292
|
+
{ layerName: e, actualKind: s.kind, expectedKind: t, docSlug: "embed-mode" }
|
|
293
|
+
);
|
|
294
|
+
if (o && i && a.current !== e) {
|
|
295
|
+
const r = n.getAll();
|
|
296
|
+
if (r.length > 0) {
|
|
297
|
+
const l = n.getAllByName(e);
|
|
298
|
+
if (l.length === 0) {
|
|
299
|
+
const c = r.map((u) => ({ name: u.name, kind: M(u) })).filter((u) => !!u.name && u.kind !== null);
|
|
300
|
+
throw new C(
|
|
301
|
+
"E_LAYER_NOT_FOUND",
|
|
302
|
+
`no layer "${e}" in this Root's document — the token was minted from a different design than the one passed to <Editor.Root design={…}>, or the layer was deleted. Bindable layers here: ${JSON.stringify(c.map((u) => u.name))}.`,
|
|
303
|
+
{ layerName: e, validNames: c.map((u) => u.name), docSlug: "embed-mode" }
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
if (!l.some((c) => M(c) === t)) {
|
|
307
|
+
const c = M(l[0]) ?? "unbindable";
|
|
308
|
+
throw new C(
|
|
309
|
+
"E_LAYER_WRONG_KIND",
|
|
310
|
+
`layer "${e}" is ${c === "unbindable" ? "not a bindable kind" : `an ${c} layer`} — this hook binds ${t} layers only.`,
|
|
311
|
+
{ layerName: e, actualKind: c, expectedKind: t, docSlug: "embed-mode" }
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
a.current = e;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return e;
|
|
318
|
+
}
|
|
319
|
+
const It = () => {
|
|
320
|
+
}, Tt = [];
|
|
321
|
+
function qt(s) {
|
|
322
|
+
const { elementStore: t } = O();
|
|
323
|
+
k("useTextBinding()");
|
|
324
|
+
const n = P(s, "text", t), { executeElementUpdate: o } = S(), e = A(() => t.getAllByName(n).filter((r) => r instanceof w), [t, n]), i = N(
|
|
325
|
+
(a) => {
|
|
326
|
+
for (const r of e) {
|
|
327
|
+
const l = r.clone();
|
|
328
|
+
l.setText(a), o(r, l);
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
[e, o]
|
|
332
|
+
);
|
|
333
|
+
return H("text", n, t, e.length > 0), e.length === 0 ? { text: "", setText: It, element: null, elements: Tt, isConnected: !1 } : {
|
|
334
|
+
text: e[0].getText(),
|
|
335
|
+
setText: i,
|
|
336
|
+
element: e[0],
|
|
337
|
+
elements: e,
|
|
338
|
+
isConnected: !0
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
const Bt = () => {
|
|
342
|
+
}, St = [];
|
|
343
|
+
function At(s, t, n) {
|
|
344
|
+
const o = s / t;
|
|
345
|
+
if (n >= o) {
|
|
346
|
+
const e = t, i = e * n, a = s / i;
|
|
347
|
+
return {
|
|
348
|
+
width: i,
|
|
349
|
+
height: e,
|
|
350
|
+
cropX: (1 - a) / 2,
|
|
351
|
+
cropY: 0,
|
|
352
|
+
cropWidth: a,
|
|
353
|
+
cropHeight: 1
|
|
354
|
+
};
|
|
355
|
+
} else {
|
|
356
|
+
const e = s, i = e / n, a = t / i;
|
|
357
|
+
return {
|
|
358
|
+
width: e,
|
|
359
|
+
height: i,
|
|
360
|
+
cropX: 0,
|
|
361
|
+
cropY: (1 - a) / 2,
|
|
362
|
+
cropWidth: 1,
|
|
363
|
+
cropHeight: a
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function zt(s, t) {
|
|
368
|
+
k("useImageBinding()");
|
|
369
|
+
const n = (t == null ? void 0 : t.fit) ?? "cover", { elementStore: o, setElements: e } = O(), i = P(s, "image", o), { executeElementUpdate: a } = S(), r = A(() => o.getAllByName(i).filter((h) => h instanceof Y), [o, i]), l = D(/* @__PURE__ */ new Map());
|
|
370
|
+
for (const d of r)
|
|
371
|
+
if (!l.current.has(d.id)) {
|
|
372
|
+
const h = d.transformData;
|
|
373
|
+
l.current.set(d.id, {
|
|
374
|
+
width: h.width * h.cropWidth,
|
|
375
|
+
height: h.height * h.cropHeight
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
const c = D(r);
|
|
379
|
+
c.current = r;
|
|
380
|
+
const u = D(a);
|
|
381
|
+
u.current = a;
|
|
382
|
+
const b = D(e);
|
|
383
|
+
b.current = e;
|
|
384
|
+
const v = N(
|
|
385
|
+
(d) => {
|
|
386
|
+
const h = c.current, _ = u.current;
|
|
387
|
+
for (const I of h) {
|
|
388
|
+
const W = l.current.get(I.id);
|
|
389
|
+
if (!W) continue;
|
|
390
|
+
const { width: j, height: K } = W, g = I.clone();
|
|
391
|
+
g.imageLoaded = !1, g.imageElement = null, g.isCropping = !1, g.imageUrl = d, n === "cover" ? (g.preserveDimensions = !0, g.onLoadCallback = (f) => {
|
|
392
|
+
const T = f.imageAspectRatio || 1, p = At(j, K, T);
|
|
393
|
+
f.transformData.width = p.width, f.transformData.height = p.height, f.transformData.cropX = p.cropX, f.transformData.cropY = p.cropY, f.transformData.cropWidth = p.cropWidth, f.transformData.cropHeight = p.cropHeight, _(I, f);
|
|
394
|
+
}) : (g.preserveDimensions = !1, g.onLoadCallback = (f) => {
|
|
395
|
+
const T = f.transformData.width, p = f.transformData.height, F = Math.min(j / T, K / p, 1);
|
|
396
|
+
F < 1 && (f.transformData.width = T * F, f.transformData.height = p * F), f.transformData.cropX = 0, f.transformData.cropY = 0, f.transformData.cropWidth = 1, f.transformData.cropHeight = 1, _(I, f);
|
|
397
|
+
}), g.loadImage(d);
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
[n]
|
|
401
|
+
// Stable deps only — imageElements/executeElementUpdate/setElements accessed via refs
|
|
402
|
+
);
|
|
403
|
+
return H("image", i, o, r.length > 0), r.length === 0 ? { imageUrl: "", setImageUrl: Bt, element: null, elements: St, isConnected: !1 } : {
|
|
404
|
+
imageUrl: r[0].imageUrl,
|
|
405
|
+
setImageUrl: v,
|
|
406
|
+
element: r[0],
|
|
407
|
+
elements: r,
|
|
408
|
+
isConnected: !0
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
const wt = [];
|
|
412
|
+
function B(s) {
|
|
413
|
+
let t = s.trim().toUpperCase();
|
|
414
|
+
return t.length === 4 && t.startsWith("#") && (t = "#" + t[1] + t[1] + t[2] + t[2] + t[3] + t[3]), t;
|
|
415
|
+
}
|
|
416
|
+
function x(s, t) {
|
|
417
|
+
return typeof s == "string" && B(s) === t;
|
|
418
|
+
}
|
|
419
|
+
function st(s, t) {
|
|
420
|
+
var o, e, i;
|
|
421
|
+
const n = s;
|
|
422
|
+
return x(n.color, t) || x((o = n.transformData) == null ? void 0 : o.fillColor, t) || x((e = n.transformData) == null ? void 0 : e.strokeColor, t) || ((i = n.stroke) == null ? void 0 : i.enabled) === !0 && x(n.stroke.color, t);
|
|
423
|
+
}
|
|
424
|
+
function kt(s, t, n) {
|
|
425
|
+
var a, r, l;
|
|
426
|
+
if (!st(s, t)) return null;
|
|
427
|
+
const o = s.clone(), e = s, i = o;
|
|
428
|
+
return x(e.color, t) && (typeof i.setColor == "function" ? i.setColor(n) : i.color = n), x((a = e.transformData) == null ? void 0 : a.fillColor, t) && (i.transformData = { ...i.transformData, fillColor: n }), x((r = e.transformData) == null ? void 0 : r.strokeColor, t) && (i.transformData = { ...i.transformData, strokeColor: n }), ((l = e.stroke) == null ? void 0 : l.enabled) === !0 && x(e.stroke.color, t) && (i.stroke = { ...i.stroke, color: n }), o;
|
|
429
|
+
}
|
|
430
|
+
function Xt(s) {
|
|
431
|
+
const t = rt(s) ? s.value : s, { elementStore: n } = O(), { executeElementUpdate: o } = S();
|
|
432
|
+
k("useColorBinding()");
|
|
433
|
+
const [e, i] = G(() => B(t)), [a, r] = G(t);
|
|
434
|
+
t !== a && (r(t), i(B(t)));
|
|
435
|
+
const l = A(
|
|
436
|
+
() => n.getAll().filter((u) => st(u, e)),
|
|
437
|
+
[n, e]
|
|
438
|
+
), c = N(
|
|
439
|
+
(u) => {
|
|
440
|
+
const b = B(u);
|
|
441
|
+
if (b !== e) {
|
|
442
|
+
for (const v of n.getAll()) {
|
|
443
|
+
const d = kt(v, e, u);
|
|
444
|
+
d && o(v, d);
|
|
445
|
+
}
|
|
446
|
+
i(b);
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
[n, e, o]
|
|
450
|
+
);
|
|
451
|
+
return l.length === 0 ? { color: e, setColor: c, elements: wt, isConnected: !1 } : { color: e, setColor: c, elements: l, isConnected: !0 };
|
|
452
|
+
}
|
|
453
|
+
const _t = () => {
|
|
454
|
+
}, Ft = [];
|
|
455
|
+
function Jt(s) {
|
|
456
|
+
const { elementStore: t } = O();
|
|
457
|
+
k("useFontBinding()");
|
|
458
|
+
const n = P(s, "text", t), { executeElementUpdate: o } = S(), e = A(() => t.getAllByName(n).filter((r) => r instanceof w), [t, n]), i = N(
|
|
459
|
+
(a) => {
|
|
460
|
+
yt.loadGoogleFontByName(a);
|
|
461
|
+
for (const r of e) {
|
|
462
|
+
if (r.fontFamily === a) continue;
|
|
463
|
+
pt.clearCache(r.fontFamily);
|
|
464
|
+
const l = r.clone();
|
|
465
|
+
l.fontFamily = a, o(r, l);
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
[e, o]
|
|
469
|
+
);
|
|
470
|
+
return H("font", n, t, e.length > 0), e.length === 0 ? { fontFamily: "", setFontFamily: _t, element: null, elements: Ft, isConnected: !1 } : {
|
|
471
|
+
fontFamily: e[0].fontFamily,
|
|
472
|
+
setFontFamily: i,
|
|
473
|
+
element: e[0],
|
|
474
|
+
elements: e,
|
|
475
|
+
isConnected: !0
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function Qt(s) {
|
|
479
|
+
const { elementStore: t } = O();
|
|
480
|
+
return s ? t.getByName(s) ?? null : null;
|
|
481
|
+
}
|
|
482
|
+
const ot = "personalization", Rt = bt("type", [
|
|
483
|
+
$({
|
|
484
|
+
type: y("text"),
|
|
485
|
+
name: m().min(1),
|
|
486
|
+
label: m(),
|
|
487
|
+
placeholder: m().optional(),
|
|
488
|
+
maxLength: xt().int().positive().optional(),
|
|
489
|
+
artboard: m().min(1).optional(),
|
|
490
|
+
group: m().optional()
|
|
491
|
+
}),
|
|
492
|
+
$({
|
|
493
|
+
type: y("image"),
|
|
494
|
+
name: m().min(1),
|
|
495
|
+
label: m(),
|
|
496
|
+
placeholder: m().optional(),
|
|
497
|
+
fit: z([y("cover"), y("contain")]).optional(),
|
|
498
|
+
artboard: m().min(1).optional(),
|
|
499
|
+
group: m().optional()
|
|
500
|
+
}),
|
|
501
|
+
$({
|
|
502
|
+
type: y("color"),
|
|
503
|
+
color: m().min(1),
|
|
504
|
+
label: m(),
|
|
505
|
+
artboard: m().min(1).optional(),
|
|
506
|
+
group: m().optional()
|
|
507
|
+
}),
|
|
508
|
+
$({
|
|
509
|
+
type: y("select"),
|
|
510
|
+
name: m().min(1),
|
|
511
|
+
label: m(),
|
|
512
|
+
property: z([y("text"), y("imageUrl"), y("fontFamily")]),
|
|
513
|
+
options: vt($({ label: m(), value: m() })).min(1),
|
|
514
|
+
artboard: m().min(1).optional(),
|
|
515
|
+
group: m().optional()
|
|
516
|
+
})
|
|
517
|
+
]);
|
|
518
|
+
function Zt(s) {
|
|
519
|
+
if (!s || typeof s != "object") return [];
|
|
520
|
+
const t = s[ot];
|
|
521
|
+
if (!Array.isArray(t)) return [];
|
|
522
|
+
const n = [];
|
|
523
|
+
for (const o of t) {
|
|
524
|
+
if (!o || typeof o != "object") continue;
|
|
525
|
+
const e = "type" in o ? o : { ...o, type: "text" }, i = Rt.safeParse(e);
|
|
526
|
+
i.success && n.push(i.data);
|
|
527
|
+
}
|
|
528
|
+
return n;
|
|
529
|
+
}
|
|
530
|
+
function te(s, t) {
|
|
531
|
+
return { ...s, [ot]: t };
|
|
532
|
+
}
|
|
533
|
+
export {
|
|
534
|
+
Kt as C,
|
|
535
|
+
jt as D,
|
|
536
|
+
ot as T,
|
|
537
|
+
Vt as a,
|
|
538
|
+
Qt as b,
|
|
539
|
+
Jt as c,
|
|
540
|
+
zt as d,
|
|
541
|
+
Gt as e,
|
|
542
|
+
qt as f,
|
|
543
|
+
X as g,
|
|
544
|
+
Zt as r,
|
|
545
|
+
Xt as u,
|
|
546
|
+
te as w
|
|
547
|
+
};
|
|
548
|
+
//# sourceMappingURL=template-fields-CQ6n2P4V.js.map
|