@snowcone-app/canvas 0.41.5 → 0.42.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/dist/embed.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { C as a, g as t, h as o, K as r, N as i, O as n, P as d, Q as m, R as u, b as l, a as E, j as c, k as p, l as g } from "./useCommands-DSapP-w1.js";
2
- import { E as C, R as S, a as T, b as f, S as P, c as R, d as b, e as B, f as k, g as v, i as y, h as F, p as h, s as D, j as I, k as K, l as L, v as w } from "./embed-KG_YnRHA.js";
2
+ import { E as C, R as S, a as T, b as f, S as P, c as R, d as b, e as B, f as k, g as v, i as y, h as F, p as h, s as D, j as I, k as K, l as L, v as w } from "./embed-5W-gg9dt.js";
3
3
  import { t as M, Y as j } from "./FontAnalyzer-Ch1jgTq7.js";
4
4
  import { D as N, e as Y, m as _, k as z, b as H } from "./design-builder-BFM94eA9.js";
5
- import { D as O, T as Q, r as V, u as q, a as U, b as W, c as X, d as Z, e as $, w as ee } from "./template-fields-C0qoE_ZH.js";
5
+ import { D as O, T as Q, r as V, u as q, a as U, b as W, c as X, d as Z, e as $, w as ee } from "./template-fields-CQURvcab.js";
6
6
  import { G as ae, H as te, J as oe, K as re } from "./ExportManager-9_RjQEv0.js";
7
- import { s as ne } from "./CanvasStateV1-C9tFMK5q.js";
7
+ import { s as ne } from "./CanvasStateV1-BQ3cbxt2.js";
8
8
  export {
9
9
  a as CanvasServicesProvider,
10
10
  N as DesignBuilder,
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { e as u } from "./useCommands-DSapP-w1.js";
2
2
  import { C as c, f as x, g as I, h as v, b as A, a as g, j as T, k as B, l as P } from "./useCommands-DSapP-w1.js";
3
- import { E as F, S as L, S as _, u as O, a as R } from "./SnowconeCanvas-BSFMazgl.js";
3
+ import { E as F, S as L, S as _, u as O, a as R } from "./SnowconeCanvas-BzOy46Yw.js";
4
4
  import { b as m, d } from "./design-builder-BFM94eA9.js";
5
5
  import { C as z, D as w, e as K, s as D } from "./design-builder-BFM94eA9.js";
6
- import { T as V, r as b, u as h, a as G, b as H, c as U, d as Y, e as Z, w as j } from "./template-fields-C0qoE_ZH.js";
6
+ import { T as V, r as b, u as h, a as G, b as H, c as U, d as Y, e as Z, w as j } from "./template-fields-CQURvcab.js";
7
7
  import { A as J, C as q, E as Q, M as W, P as X, r as $, v as ee } from "./validation-D6zVSeTh.js";
8
8
  import { G as ae, H as te, J as oe, K as re } from "./ExportManager-9_RjQEv0.js";
9
9
  import { c as ie, e as ue } from "./compose-DtQL_oit.js";
10
- import { d as de, m as Ce, s as Se, v as Ee } from "./CanvasStateV1-C9tFMK5q.js";
10
+ import { d as de, m as Ce, s as Se, v as Ee } from "./CanvasStateV1-BQ3cbxt2.js";
11
11
  function E() {
12
12
  const { isCanvasReady: e } = m();
13
13
  return e;
@@ -3,7 +3,7 @@ import { r as k } from "./ExportManager-9_RjQEv0.js";
3
3
  import { D as hr, a as cr, I as dr, W as fr, b as gr, c as lr, d as ur, e as pr, f as yr, g as kr, h as vr, i as wr, j as Cr, k as Mr, l as Tr, m as Sr, n as br, o as Pr, p as Ir, q as mr, s as Ar, t as Rr, u as Wr, v as Er, w as Or, x as Hr, y as jr, z as Fr, A as Lr, B as Xr, C as zr, F as Nr } from "./ExportManager-9_RjQEv0.js";
4
4
  import { i as H, a as j, c as F, r as L, b as X } from "./FontAnalyzer-Ch1jgTq7.js";
5
5
  import { d as Br, e as Kr, f as Ur, C as Yr, g as Jr, E as Vr, F as qr, H as Gr, L as Qr, h as Zr, W as $r, j as xr, k as Dr, l as ro, m as oo, n as so, o as eo, s as to, w as no } from "./FontAnalyzer-Ch1jgTq7.js";
6
- import { A as io, a as ho, C as co, S as fo } from "./CanvasStateV1-C9tFMK5q.js";
6
+ import { A as io, a as ho, C as co, S as fo } from "./CanvasStateV1-BQ3cbxt2.js";
7
7
  const z = F("image-adjustments"), v = 1e-3;
8
8
  function N(r, o) {
9
9
  const { brightness: a, contrast: s, saturation: h } = o, e = a * s, t = 127.5 * (1 - s), f = Math.abs(e - 1) > v || Math.abs(t) > v, i = new Uint8ClampedArray(256);
@@ -3,14 +3,14 @@ import { j as G, b as ot, k as it, u as O, a as B, m as rt } from "./design-buil
3
3
  import { toOptionAttributes as at, toCombinations as ct, getMissingSelections as lt, validateProductSelection as mt, findBestCombination as F, computeDisabledChoices as ft } from "@snowcone-app/sdk";
4
4
  import { useEffect as ut, useContext as Z, useId as dt, useLayoutEffect as ht, useRef as C, useMemo as A, useCallback as k, useState as q } from "react";
5
5
  import { E as tt, U as gt } from "./useCommands-DSapP-w1.js";
6
- import { b as pt, o as $, c as f, n as bt, l as p, u as z, e as yt } from "./CanvasStateV1-C9tFMK5q.js";
6
+ import { b as pt, o as $, c as f, e as bt, l as h, n as yt, u as z, f as vt } from "./CanvasStateV1-BQ3cbxt2.js";
7
7
  function R(s) {
8
8
  return s.text;
9
9
  }
10
10
  function x(s) {
11
11
  return s.name;
12
12
  }
13
- class jt {
13
+ class Pt {
14
14
  constructor(t) {
15
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
16
  const e = /* @__PURE__ */ new Map();
@@ -129,7 +129,7 @@ class jt {
129
129
  function J(s) {
130
130
  return (s.choices ?? []).map((t) => typeof t == "string" ? t : t.label ?? "").filter((t) => t !== "");
131
131
  }
132
- function vt(s, t) {
132
+ function Nt(s, t) {
133
133
  if (!s.variantId) return {};
134
134
  const e = t.find((n) => n.variantId === s.variantId);
135
135
  if (!e) return {};
@@ -138,9 +138,9 @@ function vt(s, t) {
138
138
  n === "variantId" || n === "price" || (typeof i == "string" ? o[n] = i : typeof i == "number" && (o[n] = String(i)));
139
139
  return o;
140
140
  }
141
- class Pt {
141
+ class Wt {
142
142
  constructor(t) {
143
- this.quantity = 1, this.version = 0, this.listeners = /* @__PURE__ */ new Set(), this.getVersion = () => this.version, this.subscribe = (e) => (this.listeners.add(e), () => this.listeners.delete(e)), this.product = t, this.attrs = at({ options: t.options }), this.combos = ct({ options: t.options }), this.selection = vt(t, this.combos);
143
+ this.quantity = 1, this.version = 0, this.listeners = /* @__PURE__ */ new Set(), this.getVersion = () => this.version, this.subscribe = (e) => (this.listeners.add(e), () => this.listeners.delete(e)), this.product = t, this.attrs = at({ options: t.options }), this.combos = ct({ options: t.options }), this.selection = Nt(t, this.combos);
144
144
  }
145
145
  getAttributes() {
146
146
  return this.attrs;
@@ -237,19 +237,19 @@ class Pt {
237
237
  for (const t of [...this.listeners]) t();
238
238
  }
239
239
  }
240
- function Wt() {
240
+ function Kt() {
241
241
  const { selectedElement: s } = ot();
242
242
  return s ?? null;
243
243
  }
244
- const Nt = 3e3, X = {
244
+ const $t = 3e3, X = {
245
245
  text: "useTextBinding",
246
246
  image: "useImageBinding",
247
247
  font: "useFontBinding"
248
- }, $t = {
248
+ }, xt = {
249
249
  text: "setText",
250
250
  image: "setImageUrl",
251
251
  font: "setFontFamily"
252
- }, xt = {
252
+ }, Ct = {
253
253
  text: "text",
254
254
  image: "image",
255
255
  font: "text"
@@ -257,8 +257,8 @@ const Nt = 3e3, X = {
257
257
  function Q(s) {
258
258
  return s instanceof T ? "text" : s instanceof M ? "image" : "other";
259
259
  }
260
- function Ct(s, t, e) {
261
- const o = `[${X[s]}]`, n = `the binding is dead (isConnected: false, ${$t[s]} is a no-op)`, i = xt[s], a = e.getAllByName(t);
260
+ function Ot(s, t, e) {
261
+ const o = `[${X[s]}]`, n = `the binding is dead (isConnected: false, ${xt[s]} is a no-op)`, i = Ct[s], a = e.getAllByName(t);
262
262
  if (a.length > 0) {
263
263
  const l = [...new Set(a.map(Q))], m = i === "text" ? "image" : "text", N = l.length === 1 && l[0] === m ? ` Bind it with ${X[m]}("${t}") instead.` : "";
264
264
  return `${o} the layer named "${t}" is ${l.join("/")}, not ${i} — ${n}.${N}`;
@@ -273,8 +273,8 @@ function Y(s, t, e, o) {
273
273
  const n = `${s}:${t}`;
274
274
  if (U.has(n)) return;
275
275
  const i = setTimeout(() => {
276
- U.has(n) || (U.add(n), console.warn(Ct(s, t, e)));
277
- }, Nt);
276
+ U.has(n) || (U.add(n), console.warn(Ot(s, t, e)));
277
+ }, $t);
278
278
  return () => clearTimeout(i);
279
279
  }, [s, t, e, o]);
280
280
  }
@@ -288,7 +288,7 @@ function _(s) {
288
288
  function L(s) {
289
289
  return s instanceof T ? "text" : s instanceof M ? "image" : null;
290
290
  }
291
- const Ot = {
291
+ const St = {
292
292
  text: "useTextBinding / useFontBinding",
293
293
  image: "useImageBinding"
294
294
  };
@@ -297,7 +297,7 @@ function j(s, t, e) {
297
297
  if (o && s.kind !== t)
298
298
  throw new v(
299
299
  "E_LAYER_WRONG_KIND",
300
- `layer "${n}" is a ${s.kind} token — this hook binds ${t} layers only (use ${Ot[s.kind]}).`,
300
+ `layer "${n}" is a ${s.kind} token — this hook binds ${t} layers only (use ${St[s.kind]}).`,
301
301
  { layerName: n, actualKind: s.kind, expectedKind: t, docSlug: "embed-mode" }
302
302
  );
303
303
  if (o && i && a.current !== n) {
@@ -325,9 +325,9 @@ function j(s, t, e) {
325
325
  }
326
326
  return n;
327
327
  }
328
- const St = () => {
329
- }, Dt = [];
330
- function Kt(s) {
328
+ const Dt = () => {
329
+ }, Et = [];
330
+ function Ht(s) {
331
331
  const { elementStore: t } = O();
332
332
  _("useTextBinding()");
333
333
  const e = j(s, "text", t), { executeElementUpdate: o } = B(), n = A(() => t.getAllByName(e).filter((r) => r instanceof T), [t, e]), i = k(
@@ -339,7 +339,7 @@ function Kt(s) {
339
339
  },
340
340
  [n, o]
341
341
  );
342
- return Y("text", e, t, n.length > 0), n.length === 0 ? { text: "", setText: St, element: null, elements: Dt, isConnected: !1 } : {
342
+ return Y("text", e, t, n.length > 0), n.length === 0 ? { text: "", setText: Dt, element: null, elements: Et, isConnected: !1 } : {
343
343
  text: n[0].getText(),
344
344
  setText: i,
345
345
  element: n[0],
@@ -347,9 +347,9 @@ function Kt(s) {
347
347
  isConnected: !0
348
348
  };
349
349
  }
350
- const Et = () => {
351
- }, It = [];
352
- function Tt(s, t, e) {
350
+ const It = () => {
351
+ }, Tt = [];
352
+ function Bt(s, t, e) {
353
353
  const o = s / t;
354
354
  if (e >= o) {
355
355
  const n = t, i = n * e, a = s / i;
@@ -373,7 +373,7 @@ function Tt(s, t, e) {
373
373
  };
374
374
  }
375
375
  }
376
- function Ht(s, t) {
376
+ function Vt(s, t) {
377
377
  _("useImageBinding()");
378
378
  const e = (t == null ? void 0 : t.fit) ?? "cover", { elementStore: o, setElements: n } = O(), i = j(s, "image", o), { executeElementUpdate: a } = B(), r = A(() => o.getAllByName(i).filter((b) => b instanceof M), [o, i]), c = C(/* @__PURE__ */ new Map());
379
379
  for (const d of r)
@@ -396,20 +396,20 @@ function Ht(s, t) {
396
396
  for (const D of b) {
397
397
  const W = c.current.get(D.id);
398
398
  if (!W) continue;
399
- const { width: K, height: H } = W, h = D.clone();
400
- h.imageLoaded = !1, h.imageElement = null, h.isCropping = !1, h.imageUrl = d, e === "cover" ? (h.preserveDimensions = !0, h.onLoadCallback = (u) => {
401
- const E = u.imageAspectRatio || 1, g = Tt(K, H, E);
402
- u.transformData.width = g.width, u.transformData.height = g.height, u.transformData.cropX = g.cropX, u.transformData.cropY = g.cropY, u.transformData.cropWidth = g.cropWidth, u.transformData.cropHeight = g.cropHeight, P(D, u);
403
- }) : (h.preserveDimensions = !1, h.onLoadCallback = (u) => {
404
- const E = u.transformData.width, g = u.transformData.height, w = Math.min(K / E, H / g, 1);
405
- w < 1 && (u.transformData.width = E * w, u.transformData.height = g * w), u.transformData.cropX = 0, u.transformData.cropY = 0, u.transformData.cropWidth = 1, u.transformData.cropHeight = 1, P(D, u);
406
- }), h.loadImage(d);
399
+ const { width: K, height: H } = W, g = D.clone();
400
+ g.imageLoaded = !1, g.imageElement = null, g.isCropping = !1, g.imageUrl = d, e === "cover" ? (g.preserveDimensions = !0, g.onLoadCallback = (u) => {
401
+ const E = u.imageAspectRatio || 1, p = Bt(K, H, E);
402
+ u.transformData.width = p.width, u.transformData.height = p.height, u.transformData.cropX = p.cropX, u.transformData.cropY = p.cropY, u.transformData.cropWidth = p.cropWidth, u.transformData.cropHeight = p.cropHeight, P(D, u);
403
+ }) : (g.preserveDimensions = !1, g.onLoadCallback = (u) => {
404
+ const E = u.transformData.width, p = u.transformData.height, w = Math.min(K / E, H / p, 1);
405
+ w < 1 && (u.transformData.width = E * w, u.transformData.height = p * w), u.transformData.cropX = 0, u.transformData.cropY = 0, u.transformData.cropWidth = 1, u.transformData.cropHeight = 1, P(D, u);
406
+ }), g.loadImage(d);
407
407
  }
408
408
  },
409
409
  [e]
410
410
  // Stable deps only — imageElements/executeElementUpdate/setElements accessed via refs
411
411
  );
412
- return Y("image", i, o, r.length > 0), r.length === 0 ? { imageUrl: "", setImageUrl: Et, element: null, elements: It, isConnected: !1 } : {
412
+ return Y("image", i, o, r.length > 0), r.length === 0 ? { imageUrl: "", setImageUrl: It, element: null, elements: Tt, isConnected: !1 } : {
413
413
  imageUrl: r[0].imageUrl,
414
414
  setImageUrl: S,
415
415
  element: r[0],
@@ -417,7 +417,7 @@ function Ht(s, t) {
417
417
  isConnected: !0
418
418
  };
419
419
  }
420
- const Bt = [];
420
+ const At = [];
421
421
  function I(s) {
422
422
  let t = s.trim().toUpperCase();
423
423
  return t.length === 4 && t.startsWith("#") && (t = "#" + t[1] + t[1] + t[2] + t[2] + t[3] + t[3]), t;
@@ -430,13 +430,13 @@ function et(s, t) {
430
430
  const e = s;
431
431
  return y(e.color, t) || y((o = e.transformData) == null ? void 0 : o.fillColor, t) || y((n = e.transformData) == null ? void 0 : n.strokeColor, t) || ((i = e.stroke) == null ? void 0 : i.enabled) === !0 && y(e.stroke.color, t);
432
432
  }
433
- function At(s, t, e) {
433
+ function kt(s, t, e) {
434
434
  var a, r, c;
435
435
  if (!et(s, t)) return null;
436
436
  const o = s.clone(), n = s, i = o;
437
437
  return y(n.color, t) && (typeof i.setColor == "function" ? i.setColor(e) : i.color = e), y((a = n.transformData) == null ? void 0 : a.fillColor, t) && (i.transformData = { ...i.transformData, fillColor: e }), y((r = n.transformData) == null ? void 0 : r.strokeColor, t) && (i.transformData = { ...i.transformData, strokeColor: e }), ((c = n.stroke) == null ? void 0 : c.enabled) === !0 && y(n.stroke.color, t) && (i.stroke = { ...i.stroke, color: e }), o;
438
438
  }
439
- function Vt(s) {
439
+ function Gt(s) {
440
440
  const t = rt(s) ? s.value : s, { elementStore: e } = O(), { executeElementUpdate: o } = B();
441
441
  _("useColorBinding()");
442
442
  const [n, i] = q(() => I(t)), [a, r] = q(t);
@@ -449,7 +449,7 @@ function Vt(s) {
449
449
  const N = I(m);
450
450
  if (N !== n) {
451
451
  for (const S of e.getAll()) {
452
- const d = At(S, n, m);
452
+ const d = kt(S, n, m);
453
453
  d && o(S, d);
454
454
  }
455
455
  i(N);
@@ -457,11 +457,11 @@ function Vt(s) {
457
457
  },
458
458
  [e, n, o]
459
459
  );
460
- return c.length === 0 ? { color: n, setColor: l, elements: Bt, isConnected: !1 } : { color: n, setColor: l, elements: c, isConnected: !0 };
460
+ return c.length === 0 ? { color: n, setColor: l, elements: At, isConnected: !1 } : { color: n, setColor: l, elements: c, isConnected: !0 };
461
461
  }
462
- const kt = () => {
463
- }, _t = [];
464
- function Gt(s) {
462
+ const _t = () => {
463
+ }, wt = [];
464
+ function qt(s) {
465
465
  const { elementStore: t } = O();
466
466
  _("useFontBinding()");
467
467
  const e = j(s, "text", t), { executeElementUpdate: o } = B(), n = A(() => t.getAllByName(e).filter((r) => r instanceof T), [t, e]), i = k(
@@ -476,7 +476,7 @@ function Gt(s) {
476
476
  },
477
477
  [n, o]
478
478
  );
479
- return Y("font", e, t, n.length > 0), n.length === 0 ? { fontFamily: "", setFontFamily: kt, element: null, elements: _t, isConnected: !1 } : {
479
+ return Y("font", e, t, n.length > 0), n.length === 0 ? { fontFamily: "", setFontFamily: _t, element: null, elements: wt, isConnected: !1 } : {
480
480
  fontFamily: n[0].fontFamily,
481
481
  setFontFamily: i,
482
482
  element: n[0],
@@ -484,73 +484,75 @@ function Gt(s) {
484
484
  isConnected: !0
485
485
  };
486
486
  }
487
- function qt(s) {
487
+ function zt(s) {
488
488
  const { elementStore: t } = O();
489
489
  return s ? t.getByName(s) ?? null : null;
490
490
  }
491
- const nt = "personalization", wt = pt("type", [
491
+ const nt = "personalization", Ft = pt("type", [
492
492
  $({
493
- type: p("text"),
493
+ type: h("text"),
494
494
  name: f().min(1),
495
495
  label: f(),
496
496
  placeholder: f().optional(),
497
- maxLength: bt().int().positive().optional(),
497
+ maxLength: yt().int().positive().optional(),
498
+ fit: h("shrink").optional(),
499
+ sample: bt().optional(),
498
500
  artboard: f().min(1).optional(),
499
501
  group: f().optional()
500
502
  }),
501
503
  $({
502
- type: p("image"),
504
+ type: h("image"),
503
505
  name: f().min(1),
504
506
  label: f(),
505
507
  placeholder: f().optional(),
506
- fit: z([p("cover"), p("contain")]).optional(),
508
+ fit: z([h("cover"), h("contain")]).optional(),
507
509
  artboard: f().min(1).optional(),
508
510
  group: f().optional()
509
511
  }),
510
512
  $({
511
- type: p("color"),
513
+ type: h("color"),
512
514
  color: f().min(1),
513
515
  label: f(),
514
516
  artboard: f().min(1).optional(),
515
517
  group: f().optional()
516
518
  }),
517
519
  $({
518
- type: p("select"),
520
+ type: h("select"),
519
521
  name: f().min(1),
520
522
  label: f(),
521
- property: z([p("text"), p("imageUrl"), p("fontFamily")]),
522
- options: yt($({ label: f(), value: f() })).min(1),
523
+ property: z([h("text"), h("imageUrl"), h("fontFamily")]),
524
+ options: vt($({ label: f(), value: f() })).min(1),
523
525
  artboard: f().min(1).optional(),
524
526
  group: f().optional()
525
527
  })
526
528
  ]);
527
- function zt(s) {
529
+ function Jt(s) {
528
530
  if (!s || typeof s != "object") return [];
529
531
  const t = s[nt];
530
532
  if (!Array.isArray(t)) return [];
531
533
  const e = [];
532
534
  for (const o of t) {
533
535
  if (!o || typeof o != "object") continue;
534
- const n = "type" in o ? o : { ...o, type: "text" }, i = wt.safeParse(n);
536
+ const n = "type" in o ? o : { ...o, type: "text" }, i = Ft.safeParse(n);
535
537
  i.success && e.push(i.data);
536
538
  }
537
539
  return e;
538
540
  }
539
- function Jt(s, t) {
541
+ function Xt(s, t) {
540
542
  return { ...s, [nt]: t };
541
543
  }
542
544
  export {
543
- Pt as C,
544
- jt as D,
545
+ Wt as C,
546
+ Pt as D,
545
547
  nt as T,
546
- qt as a,
547
- Gt as b,
548
- Ht as c,
549
- Wt as d,
550
- Kt as e,
548
+ zt as a,
549
+ qt as b,
550
+ Vt as c,
551
+ Kt as d,
552
+ Ht as e,
551
553
  J as f,
552
- zt as r,
553
- Vt as u,
554
- Jt as w
554
+ Jt as r,
555
+ Gt as u,
556
+ Xt as w
555
557
  };
556
- //# sourceMappingURL=template-fields-C0qoE_ZH.js.map
558
+ //# sourceMappingURL=template-fields-CQURvcab.js.map