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