@snowcone-app/canvas 0.29.0 → 0.30.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 (72) hide show
  1. package/ERROR_CONTRACT.md +13 -0
  2. package/dist/{CanvasRenderer-_lFoIoz5.js → CanvasRenderer-BEf0hXeF.js} +4 -4
  3. package/dist/{CanvasRenderer-_lFoIoz5.js.map → CanvasRenderer-BEf0hXeF.js.map} +1 -1
  4. package/dist/{CanvasStateV1-BMxr6xb8.js → CanvasStateV1-BDSyYo4A.js} +868 -843
  5. package/dist/{CanvasStateV1-BMxr6xb8.js.map → CanvasStateV1-BDSyYo4A.js.map} +1 -1
  6. package/dist/ContextualToolbars-C3D_6sep.js +5960 -0
  7. package/dist/ContextualToolbars-C3D_6sep.js.map +1 -0
  8. package/dist/{EditorCanvasImpl-BNz8TPFs.js → EditorCanvasImpl-DXeBz2CX.js} +8 -8
  9. package/dist/{EditorCanvasImpl-BNz8TPFs.js.map → EditorCanvasImpl-DXeBz2CX.js.map} +1 -1
  10. package/dist/{ExportManager-B8Td7uR5.js → ExportManager-DUdis6se.js} +794 -536
  11. package/dist/ExportManager-DUdis6se.js.map +1 -0
  12. package/dist/{FontAnalyzer-D4Sg-P6_.js → FontAnalyzer-DKG5JK0x.js} +823 -808
  13. package/dist/FontAnalyzer-DKG5JK0x.js.map +1 -0
  14. package/dist/{ImagePanel-CN2Bu3hf.js → ImagePanel-CBgGqmVV.js} +53 -53
  15. package/dist/{ImagePanel-CN2Bu3hf.js.map → ImagePanel-CBgGqmVV.js.map} +1 -1
  16. package/dist/SnowconeCanvas-BWPBngvI.js +1192 -0
  17. package/dist/SnowconeCanvas-BWPBngvI.js.map +1 -0
  18. package/dist/{UnifiedFontService-CgYnYTj7.js → UnifiedFontService-Co9tQ59z.js} +869 -826
  19. package/dist/UnifiedFontService-Co9tQ59z.js.map +1 -0
  20. package/dist/advanced.mjs +14 -14
  21. package/dist/api/embed.d.ts +2 -0
  22. package/dist/api/stable.d.ts +2 -0
  23. package/dist/components/CanvasContextMenu.d.ts +15 -0
  24. package/dist/components/CanvasEditor/hooks/useCanvasInteraction.d.ts +27 -0
  25. package/dist/components/CanvasEditor.d.ts +8 -0
  26. package/dist/components/embed/SnowconeCanvas.d.ts +13 -0
  27. package/dist/components/embed/kernel.d.ts +8 -0
  28. package/dist/components/ui/icons.d.ts +2 -0
  29. package/dist/contexts/CanvasServicesContext.d.ts +17 -0
  30. package/dist/contexts/EditorContext.d.ts +7 -0
  31. package/dist/{custom-icons-B5TRC1Ed.js → custom-icons-BIaRovwG.js} +2 -2
  32. package/dist/{custom-icons-B5TRC1Ed.js.map → custom-icons-BIaRovwG.js.map} +1 -1
  33. package/dist/{design-builder-COj0zkxu.js → design-builder-JYLO_Hyi.js} +2 -2
  34. package/dist/{design-builder-COj0zkxu.js.map → design-builder-JYLO_Hyi.js.map} +1 -1
  35. package/dist/{editorErrors-CCvoKj_P.js → editorErrors-WzaNxU1Y.js} +181 -194
  36. package/dist/editorErrors-WzaNxU1Y.js.map +1 -0
  37. package/dist/{embed-BTRtoktw.js → embed-Csez1hui.js} +113 -112
  38. package/dist/{embed-BTRtoktw.js.map → embed-Csez1hui.js.map} +1 -1
  39. package/dist/embed.mjs +51 -45
  40. package/dist/embed.mjs.map +1 -1
  41. package/dist/errors/editorError.d.ts +8 -0
  42. package/dist/{guards-uQtEQJbs.js → guards-BSoX73yg.js} +2 -2
  43. package/dist/{guards-uQtEQJbs.js.map → guards-BSoX73yg.js.map} +1 -1
  44. package/dist/hooks/useKeyboardShortcuts.d.ts +15 -2
  45. package/dist/hooks/useLayers.d.ts +2 -0
  46. package/dist/index.mjs +42 -37
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/internals.mjs +47 -47
  49. package/dist/state/CanvasStateV1.d.ts +31 -3
  50. package/dist/state/index.d.ts +2 -2
  51. package/dist/{template-fields-BLRp84Ny.js → template-fields-DYPW7bVU.js} +40 -40
  52. package/dist/{template-fields-BLRp84Ny.js.map → template-fields-DYPW7bVU.js.map} +1 -1
  53. package/dist/testing.mjs +13 -13
  54. package/dist/{usePieceGuideBundle-CTQszfKA.js → usePieceGuideBundle-CRLY2iQa.js} +2 -2
  55. package/dist/{usePieceGuideBundle-CTQszfKA.js.map → usePieceGuideBundle-CRLY2iQa.js.map} +1 -1
  56. package/dist/utils/custom-fonts.d.ts +99 -0
  57. package/dist/validation-BGEl9rrE.js +8686 -0
  58. package/dist/validation-BGEl9rrE.js.map +1 -0
  59. package/dist/workers/export-protocol.d.ts +13 -0
  60. package/dist/workers/export-worker.bundle.string.d.ts +1 -1
  61. package/example/package.json +1 -1
  62. package/package.json +1 -1
  63. package/dist/ContextualToolbars-0jWvnQgp.js +0 -5833
  64. package/dist/ContextualToolbars-0jWvnQgp.js.map +0 -1
  65. package/dist/ExportManager-B8Td7uR5.js.map +0 -1
  66. package/dist/FontAnalyzer-D4Sg-P6_.js.map +0 -1
  67. package/dist/SnowconeCanvas-CR_LdRFP.js +0 -1173
  68. package/dist/SnowconeCanvas-CR_LdRFP.js.map +0 -1
  69. package/dist/UnifiedFontService-CgYnYTj7.js.map +0 -1
  70. package/dist/editorErrors-CCvoKj_P.js.map +0 -1
  71. package/dist/validation-eCebhplp.js +0 -8402
  72. package/dist/validation-eCebhplp.js.map +0 -1
@@ -1,10 +1,10 @@
1
- import { g as C, u as ut, c as Y, b as W } from "./editorErrors-CCvoKj_P.js";
2
- import { l as it, i as gt, a as Nt } from "./design-builder-COj0zkxu.js";
3
- import { toOptionAttributes as St, toCombinations as It, getMissingSelections as wt, validateProductSelection as Ot, findBestCombination as J, computeDisabledChoices as At } from "@snowcone-app/sdk";
4
- import { useRef as E, useCallback as I, useEffect as Tt, useContext as ht, useId as kt, useLayoutEffect as Dt, useMemo as V, useState as ot } from "react";
5
- import { G as Bt, I as z, P as _t, S as Ft, T as K, z as yt, U as st, c as Ut, y as rt } from "./FontAnalyzer-D4Sg-P6_.js";
6
- import { p as pt, U as Rt } from "./UnifiedFontService-CgYnYTj7.js";
7
- import { a as Lt, o as R, b as d, n as Pt, l as b, u as at, c as Yt } from "./CanvasStateV1-BMxr6xb8.js";
1
+ import { E as C, G as Nt, I as W, P as St, S as It, T as Y, C as ut, U as it, c as wt, z as ot } from "./FontAnalyzer-DKG5JK0x.js";
2
+ import { l as st, i as gt, a as Ot } from "./design-builder-JYLO_Hyi.js";
3
+ import { toOptionAttributes as At, toCombinations as Tt, getMissingSelections as kt, validateProductSelection as Dt, findBestCombination as J, computeDisabledChoices as Bt } from "@snowcone-app/sdk";
4
+ import { useRef as E, useCallback as I, useEffect as _t, useContext as ht, useId as Ft, useLayoutEffect as Ut, useMemo as V, useState as rt } from "react";
5
+ import { u as yt, c as K, b as z } from "./editorErrors-WzaNxU1Y.js";
6
+ import { p as pt, U as Rt } from "./UnifiedFontService-Co9tQ59z.js";
7
+ import { a as Lt, o as R, b as d, n as Pt, l as b, u as at, c as Yt } from "./CanvasStateV1-BDSyYo4A.js";
8
8
  function X(e) {
9
9
  return e.text;
10
10
  }
@@ -38,11 +38,11 @@ class $e {
38
38
  * for unbindable), or undefined when no layer has the name. */
39
39
  layerKindOf(t) {
40
40
  const n = this.state.elements.find((o) => L(o) === t);
41
- return n ? it(n) : void 0;
41
+ return n ? st(n) : void 0;
42
42
  }
43
43
  /** Names of bindable layers in the current state, for error messages. */
44
44
  bindableLayerNames() {
45
- return this.state.elements.filter((t) => it(t) !== null).map(L).filter((t) => !!t);
45
+ return this.state.elements.filter((t) => st(t) !== null).map(L).filter((t) => !!t);
46
46
  }
47
47
  /**
48
48
  * Direct write path for `Editor.TextField` when NO canvas is mounted (with
@@ -90,7 +90,7 @@ function Kt(e, t) {
90
90
  }
91
91
  class Ce {
92
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 = St({ options: t.options }), this.combos = It({ options: t.options }), this.selection = Kt(t, this.combos);
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 = Tt({ options: t.options }), this.selection = Kt(t, this.combos);
94
94
  }
95
95
  getAttributes() {
96
96
  return this.attrs;
@@ -130,12 +130,12 @@ class Ce {
130
130
  /** Attribute keys still required (non-optional) but unselected — Buy's
131
131
  * `option:<key>` reason codes. */
132
132
  missingOptionKeys() {
133
- return Object.keys(this.attrs).length === 0 ? [] : wt(this.attrs, this.selection);
133
+ return Object.keys(this.attrs).length === 0 ? [] : kt(this.attrs, this.selection);
134
134
  }
135
135
  /** Full selection resolution (the C1 amendment): true when every required
136
136
  * attribute is selected AND the selection matches a valid combination. */
137
137
  selectionValid() {
138
- return Object.keys(this.attrs).length === 0 ? !0 : Ot(this.attrs, this.selection, this.combos);
138
+ return Object.keys(this.attrs).length === 0 ? !0 : Dt(this.attrs, this.selection, this.combos);
139
139
  }
140
140
  /** The variant (gvid) the current selection resolves to. Falls back to the
141
141
  * product's initial `variantId` while nothing has been selected. */
@@ -176,7 +176,7 @@ class Ce {
176
176
  const t = {};
177
177
  for (const [n, o] of Object.entries(this.attrs))
178
178
  t[n] = { ...o, choices: lt(o) };
179
- return At(this.selection, t, this.combos);
179
+ return Bt(this.selection, t, this.combos);
180
180
  }
181
181
  /** The combinations (for payload assembly via `createCartDetail`). */
182
182
  getCombinations() {
@@ -188,19 +188,19 @@ class Ce {
188
188
  }
189
189
  }
190
190
  function bt(e) {
191
- return e instanceof K;
191
+ return e instanceof Y;
192
192
  }
193
193
  function Mt(e) {
194
- return e instanceof z;
194
+ return e instanceof W;
195
195
  }
196
196
  function Ht(e) {
197
- return e instanceof Ft;
197
+ return e instanceof It;
198
198
  }
199
199
  function jt(e) {
200
- return e instanceof Bt;
200
+ return e instanceof Nt;
201
201
  }
202
202
  function Wt(e) {
203
- return e instanceof _t;
203
+ return e instanceof St;
204
204
  }
205
205
  function Vt(e) {
206
206
  return bt(e) ? "text" : Mt(e) ? "image" : Ht(e) ? "shape" : jt(e) ? "group" : Wt(e) ? "path" : null;
@@ -304,7 +304,7 @@ function Qt(e, t) {
304
304
  function Zt(e, t) {
305
305
  let n = !1;
306
306
  if (t.x !== void 0 && (e.x = t.x), t.y !== void 0 && (e.y = t.y), t.rotation !== void 0 && e.setRotation(t.rotation), t.opacity !== void 0 && (e.opacity = t.opacity), t.name !== void 0 && (e.name = t.name), t.visible !== void 0 && (e.visible = t.visible), t.locked !== void 0 && (e.locked = t.locked), bt(e))
307
- return t.text !== void 0 && e.setText(t.text), t.fontSize !== void 0 && e.setFontSize(t.fontSize), t.color !== void 0 && e.setColor(t.color), t.fontFamily !== void 0 && t.fontFamily !== e.fontFamily && (yt.clearCache(e.fontFamily), e.fontFamily = t.fontFamily), t.bold !== void 0 && (e.bold = t.bold), t.italic !== void 0 && (e.italic = t.italic), t.textAlign !== void 0 && (e.textAlign = t.textAlign), { needsImageLoad: n };
307
+ return t.text !== void 0 && e.setText(t.text), t.fontSize !== void 0 && e.setFontSize(t.fontSize), t.color !== void 0 && e.setColor(t.color), t.fontFamily !== void 0 && t.fontFamily !== e.fontFamily && (ut.clearCache(e.fontFamily), e.fontFamily = t.fontFamily), t.bold !== void 0 && (e.bold = t.bold), t.italic !== void 0 && (e.italic = t.italic), t.textAlign !== void 0 && (e.textAlign = t.textAlign), { needsImageLoad: n };
308
308
  const o = e;
309
309
  if (t.width !== void 0 && (o.transformData.width = t.width), t.height !== void 0 && (o.transformData.height = t.height), t.fillColor !== void 0 && (e.transformData.fillColor = t.fillColor), t.imageUrl !== void 0) {
310
310
  const i = e;
@@ -312,9 +312,9 @@ function Zt(e, t) {
312
312
  }
313
313
  return { needsImageLoad: n };
314
314
  }
315
- const mt = Ut("useCommands");
315
+ const mt = wt("useCommands");
316
316
  function Ne() {
317
- const e = ut(), {
317
+ const e = yt(), {
318
318
  undo: t,
319
319
  redo: n,
320
320
  canUndo: o,
@@ -340,7 +340,7 @@ function Ne() {
340
340
  const Et = _.current;
341
341
  let p = qt(Et, g);
342
342
  const M = O.getArtboardIdForElement(p.id) ?? O.getActiveArtboardId(), F = M ? x.peekArtboard(M) : null;
343
- F instanceof st && F.elementId === p.id && F.newElement && (p = F.newElement), Qt(p, k);
343
+ F instanceof it && F.elementId === p.id && F.newElement && (p = F.newElement), Qt(p, k);
344
344
  const H = p.clone(), { needsImageLoad: $t } = Zt(H, k);
345
345
  if ($t) {
346
346
  const B = H;
@@ -356,7 +356,7 @@ function Ne() {
356
356
  }
357
357
  if (A.current(p, H), D != null && D.coalesce && M) {
358
358
  const B = x.peekArtboard(M);
359
- N.current = B instanceof st ? { elementId: p.id, command: B } : null;
359
+ N.current = B instanceof it ? { elementId: p.id, command: B } : null;
360
360
  } else
361
361
  N.current = null;
362
362
  },
@@ -391,7 +391,7 @@ function Ne() {
391
391
  };
392
392
  }
393
393
  function Se() {
394
- const { selectedElement: e } = ut();
394
+ const { selectedElement: e } = yt();
395
395
  return e ?? null;
396
396
  }
397
397
  const te = 3e3, ft = {
@@ -408,7 +408,7 @@ const te = 3e3, ft = {
408
408
  font: "text"
409
409
  }, Z = /* @__PURE__ */ new Set();
410
410
  function dt(e) {
411
- return e instanceof K ? "text" : e instanceof z ? "image" : "other";
411
+ return e instanceof Y ? "text" : e instanceof W ? "image" : "other";
412
412
  }
413
413
  function ie(e, t, n) {
414
414
  const o = `[${ft[e]}]`, i = `the binding is dead (isConnected: false, ${ee[e]} is a no-op)`, s = ne[e], a = n.getAllByName(t);
@@ -420,9 +420,9 @@ function ie(e, t, n) {
420
420
  return `${o} no ${s} layer named "${t}" exists — ${i}. ${c}`;
421
421
  }
422
422
  function et(e, t, n, o) {
423
- Tt(() => {
423
+ _t(() => {
424
424
  var a;
425
- if (o || typeof rt > "u" || ((a = rt.env) == null ? void 0 : a.NODE_ENV) === "production") return;
425
+ if (o || typeof ot > "u" || ((a = ot.env) == null ? void 0 : a.NODE_ENV) === "production") return;
426
426
  const i = `${e}:${t}`;
427
427
  if (Z.has(i)) return;
428
428
  const s = setTimeout(() => {
@@ -432,14 +432,14 @@ function et(e, t, n, o) {
432
432
  }, [e, t, n, o]);
433
433
  }
434
434
  function G(e) {
435
- const t = ht(pt), n = kt();
436
- Dt(() => {
435
+ const t = ht(pt), n = Ft();
436
+ Ut(() => {
437
437
  if (t)
438
438
  return t.registry.requireCanvas(n, e);
439
439
  }, [t, n, e]);
440
440
  }
441
441
  function tt(e) {
442
- return e instanceof K ? "text" : e instanceof z ? "image" : null;
442
+ return e instanceof Y ? "text" : e instanceof W ? "image" : null;
443
443
  }
444
444
  const oe = {
445
445
  text: "useTextBinding / useFontBinding",
@@ -481,9 +481,9 @@ function nt(e, t, n) {
481
481
  const se = () => {
482
482
  }, re = [];
483
483
  function Ie(e) {
484
- const { elementStore: t } = Y();
484
+ const { elementStore: t } = K();
485
485
  G("useTextBinding()");
486
- const n = nt(e, "text", t), { executeElementUpdate: o } = W(), i = V(() => t.getAllByName(n).filter((r) => r instanceof K), [t, n]), s = I(
486
+ const n = nt(e, "text", t), { executeElementUpdate: o } = z(), i = V(() => t.getAllByName(n).filter((r) => r instanceof Y), [t, n]), s = I(
487
487
  (a) => {
488
488
  for (const r of i) {
489
489
  const c = r.clone();
@@ -528,7 +528,7 @@ function ce(e, t, n) {
528
528
  }
529
529
  function we(e, t) {
530
530
  G("useImageBinding()");
531
- const n = (t == null ? void 0 : t.fit) ?? "cover", { elementStore: o, setElements: i } = Y(), s = nt(e, "image", o), { executeElementUpdate: a } = W(), r = V(() => o.getAllByName(s).filter((h) => h instanceof z), [o, s]), c = E(/* @__PURE__ */ new Map());
531
+ const n = (t == null ? void 0 : t.fit) ?? "cover", { elementStore: o, setElements: i } = K(), s = nt(e, "image", o), { executeElementUpdate: a } = z(), r = V(() => o.getAllByName(s).filter((h) => h instanceof W), [o, s]), c = E(/* @__PURE__ */ new Map());
532
532
  for (const u of r)
533
533
  if (!c.current.has(u.id)) {
534
534
  const h = u.transformData;
@@ -590,9 +590,9 @@ function fe(e, t, n) {
590
590
  return $(i.color, t) && (typeof s.setColor == "function" ? s.setColor(n) : s.color = n), $((a = i.transformData) == null ? void 0 : a.fillColor, t) && (s.transformData = { ...s.transformData, fillColor: n }), $((r = i.transformData) == null ? void 0 : r.strokeColor, t) && (s.transformData = { ...s.transformData, strokeColor: n }), ((c = i.stroke) == null ? void 0 : c.enabled) === !0 && $(i.stroke.color, t) && (s.stroke = { ...s.stroke, color: n }), o;
591
591
  }
592
592
  function Oe(e) {
593
- const t = Nt(e) ? e.value : e, { elementStore: n } = Y(), { executeElementUpdate: o } = W();
593
+ const t = Ot(e) ? e.value : e, { elementStore: n } = K(), { executeElementUpdate: o } = z();
594
594
  G("useColorBinding()");
595
- const [i, s] = ot(() => j(t)), [a, r] = ot(t);
595
+ const [i, s] = rt(() => j(t)), [a, r] = rt(t);
596
596
  t !== a && (r(t), s(j(t)));
597
597
  const c = V(
598
598
  () => n.getAll().filter((m) => vt(m, i)),
@@ -615,14 +615,14 @@ function Oe(e) {
615
615
  const de = () => {
616
616
  }, ue = [];
617
617
  function Ae(e) {
618
- const { elementStore: t } = Y();
618
+ const { elementStore: t } = K();
619
619
  G("useFontBinding()");
620
- const n = nt(e, "text", t), { executeElementUpdate: o } = W(), i = V(() => t.getAllByName(n).filter((r) => r instanceof K), [t, n]), s = I(
620
+ const n = nt(e, "text", t), { executeElementUpdate: o } = z(), i = V(() => t.getAllByName(n).filter((r) => r instanceof Y), [t, n]), s = I(
621
621
  (a) => {
622
622
  Rt.loadGoogleFontByName(a);
623
623
  for (const r of i) {
624
624
  if (r.fontFamily === a) continue;
625
- yt.clearCache(r.fontFamily);
625
+ ut.clearCache(r.fontFamily);
626
626
  const c = r.clone();
627
627
  c.fontFamily = a, o(r, c);
628
628
  }
@@ -638,7 +638,7 @@ function Ae(e) {
638
638
  };
639
639
  }
640
640
  function Te(e) {
641
- const { elementStore: t } = Y();
641
+ const { elementStore: t } = K();
642
642
  return e ? t.getByName(e) ?? null : null;
643
643
  }
644
644
  const xt = "personalization", ge = Lt("type", [
@@ -713,4 +713,4 @@ export {
713
713
  Oe as u,
714
714
  De as w
715
715
  };
716
- //# sourceMappingURL=template-fields-BLRp84Ny.js.map
716
+ //# sourceMappingURL=template-fields-DYPW7bVU.js.map