@snowcone-app/canvas 0.17.2 → 0.18.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 (65) hide show
  1. package/dist/{ImportManager-C_wBjWaV.js → CanvasRenderer-DUc-MOeR.js} +586 -806
  2. package/dist/CanvasRenderer-DUc-MOeR.js.map +1 -0
  3. package/dist/{CanvasStateV1-BG2hEc3-.js → CanvasStateV1-Bq48qhv5.js} +3 -3
  4. package/dist/{CanvasStateV1-BG2hEc3-.js.map → CanvasStateV1-Bq48qhv5.js.map} +1 -1
  5. package/dist/ContextualToolbars-CkLjHNPn.js +5833 -0
  6. package/dist/ContextualToolbars-CkLjHNPn.js.map +1 -0
  7. package/dist/EditorCanvasImpl-Bv4yagew.js +81 -0
  8. package/dist/EditorCanvasImpl-Bv4yagew.js.map +1 -0
  9. package/dist/EditorContext-5QpqAhjh.js +1184 -0
  10. package/dist/{EditorContext-CGkfmbgo.js.map → EditorContext-5QpqAhjh.js.map} +1 -1
  11. package/dist/{FontAnalyzer-CLv7_msL.js → FontAnalyzer-DIlqmyuf.js} +35 -35
  12. package/dist/FontAnalyzer-DIlqmyuf.js.map +1 -0
  13. package/dist/{ElementFactory-CuHSAPfg.js → ImportManager-D--7JnvW.js} +699 -476
  14. package/dist/ImportManager-D--7JnvW.js.map +1 -0
  15. package/dist/MenuButton-CeoEAtzP.js +7444 -0
  16. package/dist/MenuButton-CeoEAtzP.js.map +1 -0
  17. package/dist/SnowconeCanvas-C_O-aeaQ.js +1166 -0
  18. package/dist/SnowconeCanvas-C_O-aeaQ.js.map +1 -0
  19. package/dist/advanced.mjs +266 -264
  20. package/dist/advanced.mjs.map +1 -1
  21. package/dist/api/embed.d.ts +1 -1
  22. package/dist/components/ContextualToolbars.d.ts +8 -0
  23. package/dist/components/editor/EditorAdd.d.ts +11 -0
  24. package/dist/components/editor/EditorCanvasImpl.d.ts +6 -0
  25. package/dist/components/editor/EditorControls.d.ts +14 -0
  26. package/dist/components/editor/EditorHistory.d.ts +11 -0
  27. package/dist/components/editor/EditorLayers.d.ts +16 -0
  28. package/dist/components/editor/EditorMenu.d.ts +11 -0
  29. package/dist/components/editor/RootInternals.d.ts +7 -0
  30. package/dist/components/editor/index.d.ts +20 -0
  31. package/dist/components/embed/addElementTypes.d.ts +9 -0
  32. package/dist/contexts/EditorContext.d.ts +38 -0
  33. package/dist/core/preview-registry.d.ts +34 -0
  34. package/dist/{editorErrors-BY4Pdg7a.js → editorErrors-DXNfVXtD.js} +2 -2
  35. package/dist/{editorErrors-BY4Pdg7a.js.map → editorErrors-DXNfVXtD.js.map} +1 -1
  36. package/dist/embed-Cdbjay9i.js +961 -0
  37. package/dist/embed-Cdbjay9i.js.map +1 -0
  38. package/dist/embed.mjs +5 -5
  39. package/dist/index.mjs +7 -7
  40. package/dist/internals.mjs +12 -12
  41. package/dist/{template-fields-Z9x13sjM.js → template-fields-DgoBtajp.js} +266 -240
  42. package/dist/template-fields-DgoBtajp.js.map +1 -0
  43. package/dist/testing.mjs +3 -3
  44. package/dist/{usePieceGuideBundle-C1ipFnZd.js → usePieceGuideBundle-DVOISsB1.js} +2 -2
  45. package/dist/{usePieceGuideBundle-C1ipFnZd.js.map → usePieceGuideBundle-DVOISsB1.js.map} +1 -1
  46. package/dist/validation-0IscSfRb.js +9304 -0
  47. package/dist/validation-0IscSfRb.js.map +1 -0
  48. package/package.json +1 -1
  49. package/dist/EditorCanvasImpl-DgXvuWXX.js +0 -70
  50. package/dist/EditorCanvasImpl-DgXvuWXX.js.map +0 -1
  51. package/dist/EditorContext-CGkfmbgo.js +0 -1178
  52. package/dist/ElementFactory-CuHSAPfg.js.map +0 -1
  53. package/dist/FontAnalyzer-CLv7_msL.js.map +0 -1
  54. package/dist/ImportManager-C_wBjWaV.js.map +0 -1
  55. package/dist/SnowconeCanvas-wdckG-6O.js +0 -1179
  56. package/dist/SnowconeCanvas-wdckG-6O.js.map +0 -1
  57. package/dist/UnifiedFontService-Dsu5cwfT.js +0 -1478
  58. package/dist/UnifiedFontService-Dsu5cwfT.js.map +0 -1
  59. package/dist/embed-32ZVWfmj.js +0 -746
  60. package/dist/embed-32ZVWfmj.js.map +0 -1
  61. package/dist/iconify-D6eVIEy4.js +0 -1089
  62. package/dist/iconify-D6eVIEy4.js.map +0 -1
  63. package/dist/template-fields-Z9x13sjM.js.map +0 -1
  64. package/dist/validation-C795COGQ.js +0 -19959
  65. package/dist/validation-C795COGQ.js.map +0 -1
@@ -1,118 +1,143 @@
1
- import { useCallback as C, useEffect as et, useMemo as $, useRef as A, useState as _ } from "react";
2
- import { u as G, c as T, b as H, g as z } from "./EditorContext-CGkfmbgo.js";
3
- import { c as nt, y as P, T as B, I as J, z as ot } from "./FontAnalyzer-CLv7_msL.js";
4
- import { U as rt } from "./UnifiedFontService-Dsu5cwfT.js";
5
- import { a as it, o as E, b as h, n as at, l as b, u as L, c as st } from "./CanvasStateV1-BG2hEc3-.js";
6
- const X = nt("useCommands");
7
- function Bt() {
8
- const t = G(), {
1
+ import { jsxs as rt, jsx as _ } from "react/jsx-runtime";
2
+ import { p as z, o as P, U as it } from "./MenuButton-CeoEAtzP.js";
3
+ import { d as at, u as Q, c as T, b as $, g as L } from "./EditorContext-5QpqAhjh.js";
4
+ import { useCallback as w, useEffect as st, useMemo as H, useRef as R, useState as X } from "react";
5
+ import { c as ct, y as K, T as B, I as Z, z as lt } from "./FontAnalyzer-DIlqmyuf.js";
6
+ import { a as dt, o as E, b as f, n as ft, l as b, u as V, c as ht } from "./CanvasStateV1-Bq48qhv5.js";
7
+ const _t = () => {
8
+ const { undo: t, redo: e, canUndo: n, canRedo: o } = at();
9
+ return /* @__PURE__ */ rt("div", { className: "sc-undo-redo", style: { display: "inline-flex", gap: 4 }, children: [
10
+ /* @__PURE__ */ _(
11
+ z,
12
+ {
13
+ icon: P.undo,
14
+ onClick: t,
15
+ disabled: !n,
16
+ tooltip: "Undo",
17
+ "aria-label": "Undo"
18
+ }
19
+ ),
20
+ /* @__PURE__ */ _(
21
+ z,
22
+ {
23
+ icon: P.redo,
24
+ onClick: e,
25
+ disabled: !o,
26
+ tooltip: "Redo",
27
+ "aria-label": "Redo"
28
+ }
29
+ )
30
+ ] });
31
+ }, j = ct("useCommands");
32
+ function zt() {
33
+ const t = Q(), {
9
34
  undo: e,
10
35
  redo: n,
11
- canUndo: r,
36
+ canUndo: o,
12
37
  canRedo: i,
13
- executeElementUpdate: o,
38
+ executeElementUpdate: r,
14
39
  executeAddElement: a,
15
40
  executeRemoveElement: s,
16
41
  executeReorderElement: l,
17
42
  executeCommandBatch: c,
18
43
  executeCreateArtboard: m,
19
44
  executeDeleteArtboard: u,
20
- executeUpdateArtboard: d
21
- } = t, g = C(() => {
22
- X.warn("[useCommands] clearHistory is not yet implemented in EditorContext");
23
- }, []), N = C((k) => {
24
- X.warn("[useCommands] clearArtboardHistory is not yet implemented in EditorContext");
45
+ executeUpdateArtboard: h
46
+ } = t, g = w(() => {
47
+ j.warn("[useCommands] clearHistory is not yet implemented in EditorContext");
48
+ }, []), N = w((k) => {
49
+ j.warn("[useCommands] clearArtboardHistory is not yet implemented in EditorContext");
25
50
  }, []);
26
51
  return {
27
52
  // Undo/Redo
28
53
  undo: e,
29
54
  redo: n,
30
- canUndo: r,
55
+ canUndo: o,
31
56
  canRedo: i,
32
57
  // History management
33
58
  clearHistory: g,
34
59
  clearArtboardHistory: N,
35
60
  // Command execution
36
- executeElementUpdate: o,
61
+ executeElementUpdate: r,
37
62
  executeAddElement: a,
38
63
  executeRemoveElement: s,
39
64
  executeReorderElement: l,
40
65
  executeCreateArtboard: m,
41
66
  executeDeleteArtboard: u,
42
- executeUpdateArtboard: d,
67
+ executeUpdateArtboard: h,
43
68
  // Batch execution
44
69
  executeCommandBatch: c
45
70
  };
46
71
  }
47
- function Mt() {
48
- const { selectedElement: t } = G();
72
+ function Pt() {
73
+ const { selectedElement: t } = Q();
49
74
  return t ?? null;
50
75
  }
51
- const ct = 3e3, K = {
76
+ const mt = 3e3, G = {
52
77
  text: "useTextBinding",
53
78
  image: "useImageBinding",
54
79
  font: "useFontBinding"
55
- }, lt = {
80
+ }, ut = {
56
81
  text: "setText",
57
82
  image: "setImageUrl",
58
83
  font: "setFontFamily"
59
- }, ft = {
84
+ }, gt = {
60
85
  text: "text",
61
86
  image: "image",
62
87
  font: "text"
63
- }, v = /* @__PURE__ */ new Set();
64
- function V(t) {
65
- return t instanceof B ? "text" : t instanceof J ? "image" : "other";
88
+ }, S = /* @__PURE__ */ new Set();
89
+ function J(t) {
90
+ return t instanceof B ? "text" : t instanceof Z ? "image" : "other";
66
91
  }
67
- function ht(t, e, n) {
68
- const r = `[${K[t]}]`, i = `the binding is dead (isConnected: false, ${lt[t]} is a no-op)`, o = ft[t], a = n.getAllByName(e);
92
+ function pt(t, e, n) {
93
+ const o = `[${G[t]}]`, i = `the binding is dead (isConnected: false, ${ut[t]} is a no-op)`, r = gt[t], a = n.getAllByName(e);
69
94
  if (a.length > 0) {
70
- const c = [...new Set(a.map(V))], m = o === "text" ? "image" : "text", u = c.length === 1 && c[0] === m ? ` Bind it with ${K[m]}("${e}") instead.` : "";
71
- return `${r} the layer named "${e}" is ${c.join("/")}, not ${o} — ${i}.${u}`;
95
+ const c = [...new Set(a.map(J))], m = r === "text" ? "image" : "text", u = c.length === 1 && c[0] === m ? ` Bind it with ${G[m]}("${e}") instead.` : "";
96
+ return `${o} the layer named "${e}" is ${c.join("/")}, not ${r} — ${i}.${u}`;
72
97
  }
73
- const s = n.getAll().filter((c) => c.name).map((c) => `"${c.name}" (${V(c)})`), l = s.length ? `Named layers on this canvas: ${s.join(", ")}. Check the name for a typo.` : `No element on this canvas has a name — name one via design().${o}(…, { name: '${e}' }) or the element's \`name\` property.`;
74
- return `${r} no ${o} layer named "${e}" exists — ${i}. ${l}`;
98
+ const s = n.getAll().filter((c) => c.name).map((c) => `"${c.name}" (${J(c)})`), l = s.length ? `Named layers on this canvas: ${s.join(", ")}. Check the name for a typo.` : `No element on this canvas has a name — name one via design().${r}(…, { name: '${e}' }) or the element's \`name\` property.`;
99
+ return `${o} no ${r} layer named "${e}" exists — ${i}. ${l}`;
75
100
  }
76
- function M(t, e, n, r) {
77
- et(() => {
101
+ function U(t, e, n, o) {
102
+ st(() => {
78
103
  var a;
79
- if (r || typeof P > "u" || ((a = P.env) == null ? void 0 : a.NODE_ENV) === "production") return;
104
+ if (o || typeof K > "u" || ((a = K.env) == null ? void 0 : a.NODE_ENV) === "production") return;
80
105
  const i = `${t}:${e}`;
81
- if (v.has(i)) return;
82
- const o = setTimeout(() => {
83
- v.has(i) || (v.add(i), console.warn(ht(t, e, n)));
84
- }, ct);
85
- return () => clearTimeout(o);
86
- }, [t, e, n, r]);
87
- }
88
- const dt = () => {
89
- }, mt = [];
90
- function Ut(t) {
91
- const { elementStore: e } = T(), { executeElementUpdate: n } = H(), r = $(() => e.getAllByName(t).filter((a) => a instanceof B), [e, t]), i = C(
92
- (o) => {
93
- for (const a of r) {
106
+ if (S.has(i)) return;
107
+ const r = setTimeout(() => {
108
+ S.has(i) || (S.add(i), console.warn(pt(t, e, n)));
109
+ }, mt);
110
+ return () => clearTimeout(r);
111
+ }, [t, e, n, o]);
112
+ }
113
+ const yt = () => {
114
+ }, bt = [];
115
+ function Lt(t) {
116
+ const { elementStore: e } = T(), { executeElementUpdate: n } = $(), o = H(() => e.getAllByName(t).filter((a) => a instanceof B), [e, t]), i = w(
117
+ (r) => {
118
+ for (const a of o) {
94
119
  const s = a.clone();
95
- s.setText(o), n(a, s);
120
+ s.setText(r), n(a, s);
96
121
  }
97
122
  },
98
- [r, n]
123
+ [o, n]
99
124
  );
100
- return M("text", t, e, r.length > 0), r.length === 0 ? { text: "", setText: dt, element: null, elements: mt, isConnected: !1 } : {
101
- text: r[0].getText(),
125
+ return U("text", t, e, o.length > 0), o.length === 0 ? { text: "", setText: yt, element: null, elements: bt, isConnected: !1 } : {
126
+ text: o[0].getText(),
102
127
  setText: i,
103
- element: r[0],
104
- elements: r,
128
+ element: o[0],
129
+ elements: o,
105
130
  isConnected: !0
106
131
  };
107
132
  }
108
- const ut = () => {
109
- }, gt = [];
110
- function pt(t, e, n) {
111
- const r = t / e;
112
- if (n >= r) {
113
- const i = e, o = i * n, a = t / o;
133
+ const xt = () => {
134
+ }, Ct = [];
135
+ function wt(t, e, n) {
136
+ const o = t / e;
137
+ if (n >= o) {
138
+ const i = e, r = i * n, a = t / r;
114
139
  return {
115
- width: o,
140
+ width: r,
116
141
  height: i,
117
142
  cropX: (1 - a) / 2,
118
143
  cropY: 0,
@@ -120,10 +145,10 @@ function pt(t, e, n) {
120
145
  cropHeight: 1
121
146
  };
122
147
  } else {
123
- const i = t, o = i / n, a = e / o;
148
+ const i = t, r = i / n, a = e / r;
124
149
  return {
125
150
  width: i,
126
- height: o,
151
+ height: r,
127
152
  cropX: 0,
128
153
  cropY: (1 - a) / 2,
129
154
  cropWidth: 1,
@@ -131,42 +156,42 @@ function pt(t, e, n) {
131
156
  };
132
157
  }
133
158
  }
134
- function Wt(t, e) {
135
- const n = (e == null ? void 0 : e.fit) ?? "cover", { elementStore: r, setElements: i } = T(), { executeElementUpdate: o } = H(), a = $(() => r.getAllByName(t).filter((g) => g instanceof J), [r, t]), s = A(/* @__PURE__ */ new Map());
136
- for (const d of a)
137
- if (!s.current.has(d.id)) {
138
- const g = d.transformData;
139
- s.current.set(d.id, {
159
+ function Xt(t, e) {
160
+ const n = (e == null ? void 0 : e.fit) ?? "cover", { elementStore: o, setElements: i } = T(), { executeElementUpdate: r } = $(), a = H(() => o.getAllByName(t).filter((g) => g instanceof Z), [o, t]), s = R(/* @__PURE__ */ new Map());
161
+ for (const h of a)
162
+ if (!s.current.has(h.id)) {
163
+ const g = h.transformData;
164
+ s.current.set(h.id, {
140
165
  width: g.width * g.cropWidth,
141
166
  height: g.height * g.cropHeight
142
167
  });
143
168
  }
144
- const l = A(a);
169
+ const l = R(a);
145
170
  l.current = a;
146
- const c = A(o);
147
- c.current = o;
148
- const m = A(i);
171
+ const c = R(r);
172
+ c.current = r;
173
+ const m = R(i);
149
174
  m.current = i;
150
- const u = C(
151
- (d) => {
175
+ const u = w(
176
+ (h) => {
152
177
  const g = l.current, N = c.current;
153
178
  for (const k of g) {
154
179
  const W = s.current.get(k.id);
155
180
  if (!W) continue;
156
181
  const { width: I, height: Y } = W, p = k.clone();
157
- p.imageLoaded = !1, p.imageElement = null, p.isCropping = !1, p.imageUrl = d, n === "cover" ? (p.preserveDimensions = !0, p.onLoadCallback = (f) => {
158
- const D = f.imageAspectRatio || 1, y = pt(I, Y, D);
159
- f.transformData.width = y.width, f.transformData.height = y.height, f.transformData.cropX = y.cropX, f.transformData.cropY = y.cropY, f.transformData.cropWidth = y.cropWidth, f.transformData.cropHeight = y.cropHeight, N(k, f);
160
- }) : (p.preserveDimensions = !1, p.onLoadCallback = (f) => {
161
- const D = f.transformData.width, y = f.transformData.height, S = Math.min(I / D, Y / y, 1);
162
- S < 1 && (f.transformData.width = D * S, f.transformData.height = y * S), f.transformData.cropX = 0, f.transformData.cropY = 0, f.transformData.cropWidth = 1, f.transformData.cropHeight = 1, N(k, f);
163
- }), p.loadImage(d);
182
+ p.imageLoaded = !1, p.imageElement = null, p.isCropping = !1, p.imageUrl = h, n === "cover" ? (p.preserveDimensions = !0, p.onLoadCallback = (d) => {
183
+ const D = d.imageAspectRatio || 1, y = wt(I, Y, D);
184
+ d.transformData.width = y.width, d.transformData.height = y.height, d.transformData.cropX = y.cropX, d.transformData.cropY = y.cropY, d.transformData.cropWidth = y.cropWidth, d.transformData.cropHeight = y.cropHeight, N(k, d);
185
+ }) : (p.preserveDimensions = !1, p.onLoadCallback = (d) => {
186
+ const D = d.transformData.width, y = d.transformData.height, v = Math.min(I / D, Y / y, 1);
187
+ v < 1 && (d.transformData.width = D * v, d.transformData.height = y * v), d.transformData.cropX = 0, d.transformData.cropY = 0, d.transformData.cropWidth = 1, d.transformData.cropHeight = 1, N(k, d);
188
+ }), p.loadImage(h);
164
189
  }
165
190
  },
166
191
  [n]
167
192
  // Stable deps only — imageElements/executeElementUpdate/setElements accessed via refs
168
193
  );
169
- return M("image", t, r, a.length > 0), a.length === 0 ? { imageUrl: "", setImageUrl: ut, element: null, elements: gt, isConnected: !1 } : {
194
+ return U("image", t, o, a.length > 0), a.length === 0 ? { imageUrl: "", setImageUrl: xt, element: null, elements: Ct, isConnected: !1 } : {
170
195
  imageUrl: a[0].imageUrl,
171
196
  setImageUrl: u,
172
197
  element: a[0],
@@ -174,164 +199,164 @@ function Wt(t, e) {
174
199
  isConnected: !0
175
200
  };
176
201
  }
177
- const yt = [];
178
- function R(t) {
202
+ const kt = [];
203
+ function A(t) {
179
204
  let e = t.trim().toUpperCase();
180
205
  return e.length === 4 && e.startsWith("#") && (e = "#" + e[1] + e[1] + e[2] + e[2] + e[3] + e[3]), e;
181
206
  }
182
207
  function x(t, e) {
183
- return typeof t == "string" && R(t) === e;
208
+ return typeof t == "string" && A(t) === e;
184
209
  }
185
- function q(t, e) {
186
- var r, i, o;
210
+ function tt(t, e) {
211
+ var o, i, r;
187
212
  const n = t;
188
- return x(n.color, e) || x((r = n.transformData) == null ? void 0 : r.fillColor, e) || x((i = n.transformData) == null ? void 0 : i.strokeColor, e) || ((o = n.stroke) == null ? void 0 : o.enabled) === !0 && x(n.stroke.color, e);
213
+ return x(n.color, e) || x((o = n.transformData) == null ? void 0 : o.fillColor, e) || x((i = n.transformData) == null ? void 0 : i.strokeColor, e) || ((r = n.stroke) == null ? void 0 : r.enabled) === !0 && x(n.stroke.color, e);
189
214
  }
190
- function bt(t, e, n) {
215
+ function Et(t, e, n) {
191
216
  var a, s, l;
192
- if (!q(t, e)) return null;
193
- const r = t.clone(), i = t, o = r;
194
- return x(i.color, e) && (typeof o.setColor == "function" ? o.setColor(n) : o.color = n), x((a = i.transformData) == null ? void 0 : a.fillColor, e) && (o.transformData = { ...o.transformData, fillColor: n }), x((s = i.transformData) == null ? void 0 : s.strokeColor, e) && (o.transformData = { ...o.transformData, strokeColor: n }), ((l = i.stroke) == null ? void 0 : l.enabled) === !0 && x(i.stroke.color, e) && (o.stroke = { ...o.stroke, color: n }), r;
195
- }
196
- function It(t) {
197
- const { elementStore: e } = T(), { executeElementUpdate: n } = H(), [r, i] = _(() => R(t)), [o, a] = _(t);
198
- t !== o && (a(t), i(R(t)));
199
- const s = $(
200
- () => e.getAll().filter((c) => q(c, r)),
201
- [e, r]
202
- ), l = C(
217
+ if (!tt(t, e)) return null;
218
+ const o = t.clone(), i = t, r = o;
219
+ return x(i.color, e) && (typeof r.setColor == "function" ? r.setColor(n) : r.color = n), x((a = i.transformData) == null ? void 0 : a.fillColor, e) && (r.transformData = { ...r.transformData, fillColor: n }), x((s = i.transformData) == null ? void 0 : s.strokeColor, e) && (r.transformData = { ...r.transformData, strokeColor: n }), ((l = i.stroke) == null ? void 0 : l.enabled) === !0 && x(i.stroke.color, e) && (r.stroke = { ...r.stroke, color: n }), o;
220
+ }
221
+ function Kt(t) {
222
+ const { elementStore: e } = T(), { executeElementUpdate: n } = $(), [o, i] = X(() => A(t)), [r, a] = X(t);
223
+ t !== r && (a(t), i(A(t)));
224
+ const s = H(
225
+ () => e.getAll().filter((c) => tt(c, o)),
226
+ [e, o]
227
+ ), l = w(
203
228
  (c) => {
204
- const m = R(c);
205
- if (m !== r) {
229
+ const m = A(c);
230
+ if (m !== o) {
206
231
  for (const u of e.getAll()) {
207
- const d = bt(u, r, c);
208
- d && n(u, d);
232
+ const h = Et(u, o, c);
233
+ h && n(u, h);
209
234
  }
210
235
  i(m);
211
236
  }
212
237
  },
213
- [e, r, n]
238
+ [e, o, n]
214
239
  );
215
- return s.length === 0 ? { color: r, setColor: l, elements: yt, isConnected: !1 } : { color: r, setColor: l, elements: s, isConnected: !0 };
216
- }
217
- const xt = () => {
218
- }, wt = [];
219
- function Yt(t) {
220
- const { elementStore: e } = T(), { executeElementUpdate: n } = H(), r = $(() => e.getAllByName(t).filter((a) => a instanceof B), [e, t]), i = C(
221
- (o) => {
222
- rt.loadGoogleFontByName(o);
223
- for (const a of r) {
224
- if (a.fontFamily === o) continue;
225
- ot.clearCache(a.fontFamily);
240
+ return s.length === 0 ? { color: o, setColor: l, elements: kt, isConnected: !1 } : { color: o, setColor: l, elements: s, isConnected: !0 };
241
+ }
242
+ const Tt = () => {
243
+ }, Nt = [];
244
+ function Vt(t) {
245
+ const { elementStore: e } = T(), { executeElementUpdate: n } = $(), o = H(() => e.getAllByName(t).filter((a) => a instanceof B), [e, t]), i = w(
246
+ (r) => {
247
+ it.loadGoogleFontByName(r);
248
+ for (const a of o) {
249
+ if (a.fontFamily === r) continue;
250
+ lt.clearCache(a.fontFamily);
226
251
  const s = a.clone();
227
- s.fontFamily = o, n(a, s);
252
+ s.fontFamily = r, n(a, s);
228
253
  }
229
254
  },
230
- [r, n]
255
+ [o, n]
231
256
  );
232
- return M("font", t, e, r.length > 0), r.length === 0 ? { fontFamily: "", setFontFamily: xt, element: null, elements: wt, isConnected: !1 } : {
233
- fontFamily: r[0].fontFamily,
257
+ return U("font", t, e, o.length > 0), o.length === 0 ? { fontFamily: "", setFontFamily: Tt, element: null, elements: Nt, isConnected: !1 } : {
258
+ fontFamily: o[0].fontFamily,
234
259
  setFontFamily: i,
235
- element: r[0],
236
- elements: r,
260
+ element: o[0],
261
+ elements: o,
237
262
  isConnected: !0
238
263
  };
239
264
  }
240
- function _t(t) {
265
+ function jt(t) {
241
266
  const { elementStore: e } = T();
242
267
  return t ? e.getByName(t) ?? null : null;
243
268
  }
244
- const Ct = 1;
245
- function w(t) {
269
+ const Dt = 1;
270
+ function C(t) {
246
271
  return typeof t == "number" && Number.isFinite(t) ? Math.round(t * 100) / 100 : t;
247
272
  }
248
- function Q(t) {
273
+ function et(t) {
249
274
  return {
250
275
  ...t,
251
- ...t.x !== void 0 && { x: w(t.x) },
252
- ...t.y !== void 0 && { y: w(t.y) },
253
- ...t.width !== void 0 && { width: w(t.width) },
254
- ...t.height !== void 0 && { height: w(t.height) },
255
- ...t.rotation !== void 0 && { rotation: w(t.rotation) }
276
+ ...t.x !== void 0 && { x: C(t.x) },
277
+ ...t.y !== void 0 && { y: C(t.y) },
278
+ ...t.width !== void 0 && { width: C(t.width) },
279
+ ...t.height !== void 0 && { height: C(t.height) },
280
+ ...t.rotation !== void 0 && { rotation: C(t.rotation) }
256
281
  };
257
282
  }
258
- function kt(t) {
259
- var r;
260
- const e = (r = t.artboards) != null && r.length ? t.artboards : [{ name: "Front", width: 800, height: 800 }], n = e.map(() => []);
283
+ function Rt(t) {
284
+ var o;
285
+ const e = (o = t.artboards) != null && o.length ? t.artboards : [{ name: "Front", width: 800, height: 800 }], n = e.map(() => []);
261
286
  for (const i of t.elements || []) {
262
- const o = i == null ? void 0 : i.artboard, a = typeof o == "string" ? e.findIndex((s) => (s.name || "Front") === o) : -1;
263
- n[a >= 0 ? a : 0].push(Et(i));
287
+ const r = i == null ? void 0 : i.artboard, a = typeof r == "string" ? e.findIndex((s) => (s.name || "Front") === r) : -1;
288
+ n[a >= 0 ? a : 0].push(At(i));
264
289
  }
265
290
  return {
266
- schemaVersion: Ct,
267
- artboards: e.map((i, o) => ({
268
- id: `artboard-${o + 1}`,
291
+ schemaVersion: Dt,
292
+ artboards: e.map((i, r) => ({
293
+ id: `artboard-${r + 1}`,
269
294
  name: i.name || "Front",
270
295
  x: 0,
271
296
  y: 0,
272
- width: w(i.width || 800),
273
- height: w(i.height || 800),
297
+ width: C(i.width || 800),
298
+ height: C(i.height || 800),
274
299
  backgroundColor: i.backgroundColor || "transparent",
275
300
  // Pass the artboard's flag through — the server worker only paints the
276
301
  // background when this is true. Hardcoding `false` here silently dropped
277
302
  // explicitly-set artboard backgrounds from every realtime mockup while
278
303
  // the editor kept showing them (WYSIWYG drift).
279
304
  exportBackground: i.exportBackground ?? !1,
280
- elements: n[o],
305
+ elements: n[r],
281
306
  distressTexture: i.distressTexture,
282
307
  imageMask: i.imageMask
283
308
  }))
284
309
  };
285
310
  }
286
- function Et(t) {
311
+ function At(t) {
287
312
  const e = t.type || t.transformType;
288
313
  if (e === "image")
289
- return Tt(t);
290
- const { artboard: n, ...r } = t;
291
- return Q({
292
- ...r,
314
+ return $t(t);
315
+ const { artboard: n, ...o } = t;
316
+ return et({
317
+ ...o,
293
318
  type: e
294
319
  });
295
320
  }
296
- function Tt(t) {
321
+ function $t(t) {
297
322
  var c;
298
- const e = t.transformData || {}, n = t.masks && t.masks.length > 0, r = e.width || 0, i = e.height || 0, o = n ? r : r * (e.cropWidth ?? 1), a = n ? i : i * (e.cropHeight ?? 1), s = {
323
+ const e = t.transformData || {}, n = t.masks && t.masks.length > 0, o = e.width || 0, i = e.height || 0, r = n ? o : o * (e.cropWidth ?? 1), a = n ? i : i * (e.cropHeight ?? 1), s = {
299
324
  id: t.id,
300
325
  type: "image",
301
326
  x: t.x || 0,
302
327
  y: t.y || 0,
303
- width: o,
328
+ width: r,
304
329
  height: a,
305
330
  rotation: t.rotation || 0,
306
331
  imageUrl: t.imageUrl,
307
332
  imageAspectRatio: t.imageAspectRatio
308
333
  };
309
- return !n && (e.cropX !== 0 || e.cropY !== 0 || e.cropWidth !== 1 || e.cropHeight !== 1) && (s.cropX = e.cropX, s.cropY = e.cropY, s.cropWidth = e.cropWidth, s.cropHeight = e.cropHeight, s.needsCropPixelConversion = !0), e.flipHorizontal && (s.flipHorizontal = e.flipHorizontal), e.flipVertical && (s.flipVertical = e.flipVertical), e.borderRadius && (s.borderRadius = e.borderRadius), t.opacity !== void 0 && (s.opacity = t.opacity), t.distressEffect && (s.distressEffect = t.distressEffect), ((c = t.masks) == null ? void 0 : c.length) > 0 && (s.masks = t.masks), t.blendMode && (s.blendMode = t.blendMode), t.knockoutParts && (s.knockoutParts = t.knockoutParts), t.stroke && (s.stroke = t.stroke), Q(s);
334
+ return !n && (e.cropX !== 0 || e.cropY !== 0 || e.cropWidth !== 1 || e.cropHeight !== 1) && (s.cropX = e.cropX, s.cropY = e.cropY, s.cropWidth = e.cropWidth, s.cropHeight = e.cropHeight, s.needsCropPixelConversion = !0), e.flipHorizontal && (s.flipHorizontal = e.flipHorizontal), e.flipVertical && (s.flipVertical = e.flipVertical), e.borderRadius && (s.borderRadius = e.borderRadius), t.opacity !== void 0 && (s.opacity = t.opacity), t.distressEffect && (s.distressEffect = t.distressEffect), ((c = t.masks) == null ? void 0 : c.length) > 0 && (s.masks = t.masks), t.blendMode && (s.blendMode = t.blendMode), t.knockoutParts && (s.knockoutParts = t.knockoutParts), t.stroke && (s.stroke = t.stroke), et(s);
310
335
  }
311
- const j = "center", Z = Symbol.for("snowcone.canvas.layerToken");
312
- function zt(t) {
313
- return typeof t == "object" && t !== null && t[Z] === !0 && typeof t.name == "string" && (t.kind === "text" || t.kind === "image");
336
+ const q = "center", nt = Symbol.for("snowcone.canvas.layerToken");
337
+ function Gt(t) {
338
+ return typeof t == "object" && t !== null && t[nt] === !0 && typeof t.name == "string" && (t.kind === "text" || t.kind === "image");
314
339
  }
315
- function Nt(t, e) {
316
- return Object.freeze({ kind: t, name: e, [Z]: !0 });
340
+ function Ht(t, e) {
341
+ return Object.freeze({ kind: t, name: e, [nt]: !0 });
317
342
  }
318
343
  function O(t) {
319
344
  const e = t.transformType;
320
345
  return e === "image" ? "image" : e === "shape" || e === "group" || e === "path" ? null : "text";
321
346
  }
322
- function Dt(t) {
347
+ function vt(t) {
323
348
  return t === "top-left" || t === "left" || t === "bottom-left" ? "left" : t === "top-right" || t === "right" || t === "bottom-right" ? "right" : "center";
324
349
  }
325
- function At(t) {
350
+ function St(t) {
326
351
  return t === "top-left" || t === "top" || t === "top-right" ? "top" : t === "bottom-left" || t === "bottom" || t === "bottom-right" ? "bottom" : "middle";
327
352
  }
328
- function F(t, e, n, r, i, o) {
329
- const a = Dt(t), s = At(t), l = a === "left" ? e / 2 + o : a === "right" ? r - e / 2 - o : r / 2, c = s === "top" ? n / 2 + o : s === "bottom" ? i - n / 2 - o : i / 2;
353
+ function F(t, e, n, o, i, r) {
354
+ const a = vt(t), s = St(t), l = a === "left" ? e / 2 + r : a === "right" ? o - e / 2 - r : o / 2, c = s === "top" ? n / 2 + r : s === "bottom" ? i - n / 2 - r : i / 2;
330
355
  return { x: l, y: c };
331
356
  }
332
- function Rt(t, e, n) {
333
- const r = e / n;
334
- if (t >= r) {
357
+ function Ft(t, e, n) {
358
+ const o = e / n;
359
+ if (t >= o) {
335
360
  const a = n * t, s = e / a;
336
361
  return {
337
362
  width: a,
@@ -342,17 +367,17 @@ function Rt(t, e, n) {
342
367
  cropHeight: 1
343
368
  };
344
369
  }
345
- const i = e / t, o = n / i;
370
+ const i = e / t, r = n / i;
346
371
  return {
347
372
  width: e,
348
373
  height: i,
349
374
  cropX: 0,
350
- cropY: (1 - o) / 2,
375
+ cropY: (1 - r) / 2,
351
376
  cropWidth: 1,
352
- cropHeight: o
377
+ cropHeight: r
353
378
  };
354
379
  }
355
- class U {
380
+ class M {
356
381
  constructor(e) {
357
382
  if (this.els = [], this.idCounter = 0, !(e.width > 0) || !(e.height > 0))
358
383
  throw new Error("design(): artboard width and height must be positive numbers");
@@ -377,25 +402,25 @@ class U {
377
402
  const n = e.artboards.find((i) => i.name === e.activeArtboard) ?? e.artboards[0];
378
403
  if (!n)
379
404
  throw new Error("DesignBuilder.fromState(): state has no artboards");
380
- const r = new U({
405
+ const o = new M({
381
406
  name: n.name,
382
407
  width: n.width,
383
408
  height: n.height,
384
409
  backgroundColor: n.backgroundColor
385
410
  });
386
411
  for (const i of e.elements)
387
- i.artboard && i.artboard !== n.name || r.els.push({ ...i });
388
- return r;
412
+ i.artboard && i.artboard !== n.name || o.els.push({ ...i });
413
+ return o;
389
414
  }
390
415
  nextId(e) {
391
416
  return `${e}-${++this.idCounter}`;
392
417
  }
393
418
  background(e, n = {}) {
394
- const { width: r, height: i } = this.artboard;
395
- let o;
419
+ const { width: o, height: i } = this.artboard;
420
+ let r;
396
421
  if (n.aspectRatio && n.aspectRatio > 0) {
397
- const s = Rt(n.aspectRatio, r, i);
398
- o = {
422
+ const s = Ft(n.aspectRatio, o, i);
423
+ r = {
399
424
  type: "image",
400
425
  width: s.width,
401
426
  height: s.height,
@@ -408,9 +433,9 @@ class U {
408
433
  borderRadius: 0
409
434
  };
410
435
  } else
411
- o = {
436
+ r = {
412
437
  type: "image",
413
- width: r,
438
+ width: o,
414
439
  height: i,
415
440
  cropX: 0,
416
441
  cropY: 0,
@@ -423,19 +448,19 @@ class U {
423
448
  const a = {
424
449
  id: this.nextId("bg"),
425
450
  transformType: "image",
426
- x: r / 2,
451
+ x: o / 2,
427
452
  y: i / 2,
428
453
  rotation: 0,
429
454
  opacity: n.opacity ?? 1,
430
455
  imageUrl: e,
431
456
  imageAspectRatio: n.aspectRatio,
432
- transformData: o,
457
+ transformData: r,
433
458
  name: n.name ?? "Background"
434
459
  };
435
460
  return this.els.unshift(a), this;
436
461
  }
437
462
  image(e, n = {}) {
438
- const { width: r, height: i } = this.artboard, o = n.width ?? Math.round(r / 3), a = n.height ?? (n.aspectRatio ? Math.round(o / n.aspectRatio) : o), { x: s, y: l } = F(n.anchor ?? j, o, a, r, i, n.padding ?? 0), c = {
463
+ const { width: o, height: i } = this.artboard, r = n.width ?? Math.round(o / 3), a = n.height ?? (n.aspectRatio ? Math.round(r / n.aspectRatio) : r), { x: s, y: l } = F(n.anchor ?? q, r, a, o, i, n.padding ?? 0), c = {
439
464
  id: this.nextId("img"),
440
465
  transformType: "image",
441
466
  x: s,
@@ -446,7 +471,7 @@ class U {
446
471
  imageAspectRatio: n.aspectRatio,
447
472
  transformData: {
448
473
  type: "image",
449
- width: o,
474
+ width: r,
450
475
  height: a,
451
476
  cropX: 0,
452
477
  cropY: 0,
@@ -461,14 +486,14 @@ class U {
461
486
  return this.els.push(c), this;
462
487
  }
463
488
  text(e, n = {}) {
464
- const { width: r, height: i } = this.artboard, o = n.fontSize ?? Math.round(this.artboard.height / 12), { x: a, y: s } = F(n.anchor ?? "top", 0, o, r, i, n.padding ?? Math.round(i / 20)), l = {
489
+ const { width: o, height: i } = this.artboard, r = n.fontSize ?? Math.round(this.artboard.height / 12), { x: a, y: s } = F(n.anchor ?? "top", 0, r, o, i, n.padding ?? Math.round(i / 20)), l = {
465
490
  id: this.nextId("text"),
466
491
  transformType: "custom",
467
492
  x: a,
468
493
  y: s,
469
494
  rotation: n.rotation ?? 0,
470
495
  text: e,
471
- fontSize: o,
496
+ fontSize: r,
472
497
  fontFamily: n.fontFamily ?? "Anton",
473
498
  color: n.color ?? "#ffffff",
474
499
  textAlign: n.textAlign ?? "center",
@@ -496,21 +521,21 @@ class U {
496
521
  layer(e) {
497
522
  const n = this.els.find((i) => i.name === e);
498
523
  if (!n) {
499
- const i = this.layerNamesOfKind("text"), o = this.layerNamesOfKind("image");
500
- throw new z(
524
+ const i = this.layerNamesOfKind("text"), r = this.layerNamesOfKind("image");
525
+ throw new L(
501
526
  "E_LAYER_NOT_FOUND",
502
- `no layer "${e}" in this design. Text layers: ${JSON.stringify(i)}; image layers: ${JSON.stringify(o)}. Fix the name, or add the layer first — e.g. design(…).text('…', { name: '${e}' }).`,
503
- { layerName: e, validNames: [...i, ...o], textNames: i, imageNames: o, docSlug: "embed-mode" }
527
+ `no layer "${e}" in this design. Text layers: ${JSON.stringify(i)}; image layers: ${JSON.stringify(r)}. Fix the name, or add the layer first — e.g. design(…).text('…', { name: '${e}' }).`,
528
+ { layerName: e, validNames: [...i, ...r], textNames: i, imageNames: r, docSlug: "embed-mode" }
504
529
  );
505
530
  }
506
- const r = O(n);
507
- if (!r)
508
- throw new z(
531
+ const o = O(n);
532
+ if (!o)
533
+ throw new L(
509
534
  "E_LAYER_WRONG_KIND",
510
535
  `layer "${e}" is a ${n.transformType} element — only text and image layers are bindable. Bindable layers: ${JSON.stringify([...this.layerNamesOfKind("text"), ...this.layerNamesOfKind("image")])}.`,
511
536
  { layerName: e, actualType: n.transformType, docSlug: "embed-mode" }
512
537
  );
513
- return Nt(r, e);
538
+ return Ht(o, e);
514
539
  }
515
540
  /** Names of bindable layers of one kind, in stack order. @internal */
516
541
  layerNamesOfKind(e) {
@@ -518,7 +543,7 @@ class U {
518
543
  }
519
544
  /** An anchored vector shape. */
520
545
  shape(e, n = {}) {
521
- const { width: r, height: i } = this.artboard, o = n.size ?? Math.round(r / 6), a = typeof o == "number" ? o : o.width, s = typeof o == "number" ? o : o.height, { x: l, y: c } = F(n.anchor ?? j, a, s, r, i, n.padding ?? 0), m = {
546
+ const { width: o, height: i } = this.artboard, r = n.size ?? Math.round(o / 6), a = typeof r == "number" ? r : r.width, s = typeof r == "number" ? r : r.height, { x: l, y: c } = F(n.anchor ?? q, a, s, o, i, n.padding ?? 0), m = {
522
547
  type: "shape",
523
548
  shapeType: e,
524
549
  width: a,
@@ -565,78 +590,79 @@ class U {
565
590
  /** Server-render payload for `RenderSession.renderState(placement, …)`.
566
591
  * Equivalent to `serializeStateForServer(design.toJSON())`. */
567
592
  toServerRequest() {
568
- return kt(this.toJSON());
593
+ return Rt(this.toJSON());
569
594
  }
570
595
  }
571
- function Pt(t) {
572
- return new U(t);
596
+ function Jt(t) {
597
+ return new M(t);
573
598
  }
574
- function Lt(t) {
599
+ function qt(t) {
575
600
  return O(t);
576
601
  }
577
- const tt = "personalization", $t = it("type", [
602
+ const ot = "personalization", Ot = dt("type", [
578
603
  E({
579
604
  type: b("text"),
580
- name: h().min(1),
581
- label: h(),
582
- placeholder: h().optional(),
583
- maxLength: at().int().positive().optional(),
584
- group: h().optional()
605
+ name: f().min(1),
606
+ label: f(),
607
+ placeholder: f().optional(),
608
+ maxLength: ft().int().positive().optional(),
609
+ group: f().optional()
585
610
  }),
586
611
  E({
587
612
  type: b("image"),
588
- name: h().min(1),
589
- label: h(),
590
- placeholder: h().optional(),
591
- fit: L([b("cover"), b("contain")]).optional(),
592
- group: h().optional()
613
+ name: f().min(1),
614
+ label: f(),
615
+ placeholder: f().optional(),
616
+ fit: V([b("cover"), b("contain")]).optional(),
617
+ group: f().optional()
593
618
  }),
594
619
  E({
595
620
  type: b("color"),
596
- color: h().min(1),
597
- label: h(),
598
- group: h().optional()
621
+ color: f().min(1),
622
+ label: f(),
623
+ group: f().optional()
599
624
  }),
600
625
  E({
601
626
  type: b("select"),
602
- name: h().min(1),
603
- label: h(),
604
- property: L([b("text"), b("imageUrl"), b("fontFamily")]),
605
- options: st(E({ label: h(), value: h() })).min(1),
606
- group: h().optional()
627
+ name: f().min(1),
628
+ label: f(),
629
+ property: V([b("text"), b("imageUrl"), b("fontFamily")]),
630
+ options: ht(E({ label: f(), value: f() })).min(1),
631
+ group: f().optional()
607
632
  })
608
633
  ]);
609
- function Xt(t) {
634
+ function Qt(t) {
610
635
  if (!t || typeof t != "object") return [];
611
- const e = t[tt];
636
+ const e = t[ot];
612
637
  if (!Array.isArray(e)) return [];
613
638
  const n = [];
614
- for (const r of e) {
615
- if (!r || typeof r != "object") continue;
616
- const i = "type" in r ? r : { ...r, type: "text" }, o = $t.safeParse(i);
617
- o.success && n.push(o.data);
639
+ for (const o of e) {
640
+ if (!o || typeof o != "object") continue;
641
+ const i = "type" in o ? o : { ...o, type: "text" }, r = Ot.safeParse(i);
642
+ r.success && n.push(r.data);
618
643
  }
619
644
  return n;
620
645
  }
621
- function Kt(t, e) {
622
- return { ...t, [tt]: e };
646
+ function Zt(t, e) {
647
+ return { ...t, [ot]: e };
623
648
  }
624
649
  export {
625
- Ct as C,
626
- U as D,
627
- tt as T,
628
- Bt as a,
629
- _t as b,
630
- Yt as c,
631
- Pt as d,
632
- Wt as e,
633
- Mt as f,
634
- Ut as g,
635
- zt as i,
636
- Lt as l,
637
- Xt as r,
638
- kt as s,
639
- It as u,
640
- Kt as w
650
+ Dt as C,
651
+ M as D,
652
+ ot as T,
653
+ _t as U,
654
+ zt as a,
655
+ jt as b,
656
+ Vt as c,
657
+ Jt as d,
658
+ Xt as e,
659
+ Pt as f,
660
+ Lt as g,
661
+ Gt as i,
662
+ qt as l,
663
+ Qt as r,
664
+ Rt as s,
665
+ Kt as u,
666
+ Zt as w
641
667
  };
642
- //# sourceMappingURL=template-fields-Z9x13sjM.js.map
668
+ //# sourceMappingURL=template-fields-DgoBtajp.js.map