@snowcone-app/canvas 0.40.8 → 0.40.10

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 (38) hide show
  1. package/dist/{CanvasRenderer-COO5UXtZ.js → CanvasRenderer-BuZVwUch.js} +2 -2
  2. package/dist/{CanvasRenderer-COO5UXtZ.js.map → CanvasRenderer-BuZVwUch.js.map} +1 -1
  3. package/dist/{CanvasStateV1-V8l7-6PC.js → CanvasStateV1-D-ki3MtP.js} +2 -2
  4. package/dist/{CanvasStateV1-V8l7-6PC.js.map → CanvasStateV1-D-ki3MtP.js.map} +1 -1
  5. package/dist/{ContextualToolbars-_5zqlcSw.js → ContextualToolbars-Cy91bYY9.js} +4 -4
  6. package/dist/{ContextualToolbars-_5zqlcSw.js.map → ContextualToolbars-Cy91bYY9.js.map} +1 -1
  7. package/dist/{EditorCanvasImpl-CBl27o5h.js → EditorCanvasImpl-C8tvgEh8.js} +6 -6
  8. package/dist/{EditorCanvasImpl-CBl27o5h.js.map → EditorCanvasImpl-C8tvgEh8.js.map} +1 -1
  9. package/dist/ExportManager-B_7SG-Ox.js +3640 -0
  10. package/dist/ExportManager-B_7SG-Ox.js.map +1 -0
  11. package/dist/{ImagePanel-BaX0UE-L.js → ImagePanel-CJJzUQWY.js} +3 -3
  12. package/dist/{ImagePanel-BaX0UE-L.js.map → ImagePanel-CJJzUQWY.js.map} +1 -1
  13. package/dist/{SnowconeCanvas-uUJy5mxC.js → SnowconeCanvas-BfxMwXO9.js} +8 -8
  14. package/dist/{SnowconeCanvas-uUJy5mxC.js.map → SnowconeCanvas-BfxMwXO9.js.map} +1 -1
  15. package/dist/advanced.mjs +10 -10
  16. package/dist/components/embed-realtime/usePieceGuideBundle.d.ts +1 -1
  17. package/dist/{custom-icons-o1U13Vcg.js → custom-icons-sebOL9Xd.js} +2 -2
  18. package/dist/{custom-icons-o1U13Vcg.js.map → custom-icons-sebOL9Xd.js.map} +1 -1
  19. package/dist/{embed-BY6gMPTK.js → embed-DO1jibk2.js} +8 -8
  20. package/dist/{embed-BY6gMPTK.js.map → embed-DO1jibk2.js.map} +1 -1
  21. package/dist/embed.mjs +5 -5
  22. package/dist/{ExportManager-BbBfO22S.js → export-worker.bundle.string-DXciOLDt.js} +3 -3618
  23. package/dist/export-worker.bundle.string-DXciOLDt.js.map +1 -0
  24. package/dist/index.mjs +7 -7
  25. package/dist/internals.mjs +4 -4
  26. package/dist/{template-fields-DaLRAR5W.js → template-fields-DwmObbeX.js} +3 -3
  27. package/dist/{template-fields-DaLRAR5W.js.map → template-fields-DwmObbeX.js.map} +1 -1
  28. package/dist/{useCommands-x8J7_Mzy.js → useCommands-f-UTuBI1.js} +5 -5
  29. package/dist/{useCommands-x8J7_Mzy.js.map → useCommands-f-UTuBI1.js.map} +1 -1
  30. package/dist/{usePieceGuideBundle-Cab2gRnn.js → usePieceGuideBundle-BpIz4qow.js} +10 -9
  31. package/dist/usePieceGuideBundle-BpIz4qow.js.map +1 -0
  32. package/dist/utils/WorkerExportManager.d.ts +9 -0
  33. package/dist/{validation-BMB6_hp4.js → validation-B5eH5mzI.js} +9 -9
  34. package/dist/{validation-BMB6_hp4.js.map → validation-B5eH5mzI.js.map} +1 -1
  35. package/example/package.json +1 -1
  36. package/package.json +3 -3
  37. package/dist/ExportManager-BbBfO22S.js.map +0 -1
  38. package/dist/usePieceGuideBundle-Cab2gRnn.js.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import { p as a } from "./FontAnalyzer-DWHS41ba.js";
2
2
  import { useState as s, useEffect as h } from "react";
3
- const d = "https://api.snowcone.app";
4
- function c(e) {
3
+ import { SNOWCONE_HOSTS as d } from "@snowcone-app/sdk";
4
+ const c = d.api;
5
+ function u(e) {
5
6
  const i = e.pieces.map((t) => ({
6
7
  id: t.id,
7
8
  x: t.x,
@@ -24,7 +25,7 @@ function c(e) {
24
25
  }
25
26
  };
26
27
  }
27
- function g(e, i) {
28
+ function m(e, i) {
28
29
  var o;
29
30
  if (!i) return;
30
31
  const { pieces: t } = e.config;
@@ -40,7 +41,7 @@ function g(e, i) {
40
41
  }
41
42
  return e.config;
42
43
  }
43
- function l(e, i = d) {
44
+ function p(e, i = c) {
44
45
  const [t, r] = s(null);
45
46
  return h(() => {
46
47
  if (!e) {
@@ -52,7 +53,7 @@ function l(e, i = d) {
52
53
  if (!n.ok) throw new Error(`status ${n.status}`);
53
54
  return await n.json();
54
55
  }).then((n) => {
55
- o || r(c(n));
56
+ o || r(u(n));
56
57
  }).catch(() => {
57
58
  o || r(null);
58
59
  }), () => {
@@ -61,8 +62,8 @@ function l(e, i = d) {
61
62
  }, [e, i]), t;
62
63
  }
63
64
  export {
64
- d as P,
65
- g as p,
66
- l as u
65
+ c as P,
66
+ m as p,
67
+ p as u
67
68
  };
68
- //# sourceMappingURL=usePieceGuideBundle-Cab2gRnn.js.map
69
+ //# sourceMappingURL=usePieceGuideBundle-BpIz4qow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePieceGuideBundle-BpIz4qow.js","sources":["../src/components/embed-realtime/usePieceGuideBundle.ts"],"sourcesContent":["'use client';\n\n/**\n * usePieceGuideBundle — fetch a product's printable-area guides for the embed.\n *\n * Some products hide part of the print file under hardware (a phone case's\n * camera module, a notebook's spine). snowcone.app's own editor draws the\n * printable-area / dead-zone overlay from the product's piece guides;\n * `<RealtimeEmbed>` uses this hook so embedders get the same overlay with\n * zero config — without it, a buyer can edit artwork the mockup will never\n * show, with no signal anywhere (#566).\n *\n * The endpoint is a public read (geometry only — piece rects, safe areas,\n * authored guides; same exposure class as the public catalog). Errors degrade\n * silently to \"no guides\": the editor keeps working, the overlay just doesn't\n * appear — same posture as snowcone.app's own loader.\n *\n * @module\n */\n\nimport { useEffect, useState } from 'react';\nimport { SNOWCONE_HOSTS } from '@snowcone-app/sdk';\nimport type { PieceGuidesConfig } from '../embed/SnowconeCanvas.js';\nimport type {\n PieceGuide,\n PieceGuideRendererPiece,\n PieceGuideRendererStyle,\n} from '../../rendering/PieceGuideRenderer.js';\n\n/** Backend base hosting `GET /printables/by-gvid/:gvid/piece-guides`. */\nexport const PIECE_GUIDES_API_BASE: string = SNOWCONE_HOSTS.api;\n\n/** Wire shape of the piece-guides endpoint (the consumer-safe subset). */\ninterface RawPieceGuidesResponse {\n artboardWidth: number;\n artboardHeight: number;\n /** Inches→px conversion factor for `safeAreaInsetInches`. */\n templateDpi: number;\n pieces: Array<{\n id: string;\n x: number;\n y: number;\n width: number;\n height: number;\n rotation?: number;\n naturalWidth?: number;\n naturalHeight?: number;\n safeAreaInsetInches?: number;\n }>;\n pieceGuides?: Record<string, PieceGuide>;\n pieceGuidesStyle?: PieceGuideRendererStyle;\n}\n\n/** A fetched bundle: the overlay config plus the artboard frame it was authored in. */\nexport interface PieceGuideBundle {\n /** The print-file frame the piece coords live in. */\n artboardWidth: number;\n artboardHeight: number;\n config: PieceGuidesConfig;\n}\n\n/** Convert the wire response into a renderer-ready bundle (inches → px, etc.). */\nexport function transformPieceGuides(raw: RawPieceGuidesResponse): PieceGuideBundle {\n const pieces: PieceGuideRendererPiece[] = raw.pieces.map((p) => ({\n id: p.id,\n x: p.x,\n y: p.y,\n width: p.width,\n height: p.height,\n rotation: typeof p.rotation === 'number' ? p.rotation : undefined,\n // natural (unrotated) size — required at non-right angles (a bandana's 45° folded view)\n naturalWidth: typeof p.naturalWidth === 'number' ? p.naturalWidth : undefined,\n naturalHeight: typeof p.naturalHeight === 'number' ? p.naturalHeight : undefined,\n safeAreaInsetPx:\n typeof p.safeAreaInsetInches === 'number' && p.safeAreaInsetInches > 0\n ? p.safeAreaInsetInches * raw.templateDpi\n : undefined,\n }));\n return {\n artboardWidth: raw.artboardWidth,\n artboardHeight: raw.artboardHeight,\n config: {\n pieces,\n guides: raw.pieceGuides ?? {},\n style: raw.pieceGuidesStyle,\n },\n };\n}\n\n/**\n * Gate the bundle on the design's artboard matching the print-file frame the\n * guides were authored in — the same gate snowcone.app's editor applies. A\n * design authored at other dims would render the overlay misaligned, so it's\n * skipped (with a dev hint, since the fix — author at the placement's dims —\n * is on the embedder's side).\n */\nexport function pieceGuidesForArtboard(\n bundle: PieceGuideBundle,\n artboard: { width: number; height: number; name?: string } | undefined,\n): PieceGuidesConfig | undefined {\n if (!artboard) return undefined;\n // A SEPARATE-mode printable (slides Left/Right, one print file per area)\n // synthesizes one full-frame piece per placement — identical boxes\n // stacked at (0,0). An artboard named for one of those placements draws\n // ITS piece only: both stacked pieces would double-paint the bleed wash\n // (ADR-0101 §6). Any other bundle (a real spread) draws every piece.\n const { pieces } = bundle.config;\n const stacked =\n pieces.length > 1 &&\n pieces.every(\n (p) => p.x === 0 && p.y === 0 && p.width === bundle.artboardWidth && p.height === bundle.artboardHeight,\n );\n if (stacked && artboard.name && pieces.some((p) => p.id === artboard.name)) {\n if (artboard.width === bundle.artboardWidth && artboard.height === bundle.artboardHeight) {\n return { ...bundle.config, pieces: pieces.filter((p) => p.id === artboard.name) };\n }\n }\n if (artboard.width !== bundle.artboardWidth || artboard.height !== bundle.artboardHeight) {\n if (typeof process !== 'undefined' && process.env?.NODE_ENV !== 'production') {\n console.warn(\n `[RealtimeEmbed] This product has printable-area guides (authored at ` +\n `${bundle.artboardWidth}×${bundle.artboardHeight}), but the design's artboard is ` +\n `${artboard.width}×${artboard.height} — the dead-zone overlay is skipped because the ` +\n `coordinates wouldn't line up. Author the design at the placement's dimensions to get it.`,\n );\n }\n return undefined;\n }\n return bundle.config;\n}\n\n/**\n * Fetch the piece-guide bundle for a variant (gvid). Returns null while\n * loading, when `gvid` is undefined, and on any error (silent degrade).\n */\nexport function usePieceGuideBundle(\n gvid: string | undefined,\n apiBase: string = PIECE_GUIDES_API_BASE,\n): PieceGuideBundle | null {\n const [bundle, setBundle] = useState<PieceGuideBundle | null>(null);\n\n useEffect(() => {\n if (!gvid) {\n setBundle(null);\n return;\n }\n let cancelled = false;\n fetch(`${apiBase}/printables/by-gvid/${encodeURIComponent(gvid)}/piece-guides`)\n .then(async (res) => {\n if (!res.ok) throw new Error(`status ${res.status}`);\n return (await res.json()) as RawPieceGuidesResponse;\n })\n .then((raw) => {\n if (!cancelled) setBundle(transformPieceGuides(raw));\n })\n .catch(() => {\n // No guides is a degraded state, not a failure — the editor keeps\n // working, the overlay just doesn't appear.\n if (!cancelled) setBundle(null);\n });\n return () => {\n cancelled = true;\n };\n }, [gvid, apiBase]);\n\n return bundle;\n}\n"],"names":["PIECE_GUIDES_API_BASE","SNOWCONE_HOSTS","transformPieceGuides","raw","pieces","p","pieceGuidesForArtboard","bundle","artboard","process","usePieceGuideBundle","gvid","apiBase","setBundle","useState","useEffect","cancelled","res"],"mappings":";;;AA8BO,MAAMA,IAAgCC,EAAe;AAgCrD,SAASC,EAAqBC,GAA+C;AAClF,QAAMC,IAAoCD,EAAI,OAAO,IAAI,CAACE,OAAO;AAAA,IAC/D,IAAIA,EAAE;AAAA,IACN,GAAGA,EAAE;AAAA,IACL,GAAGA,EAAE;AAAA,IACL,OAAOA,EAAE;AAAA,IACT,QAAQA,EAAE;AAAA,IACV,UAAU,OAAOA,EAAE,YAAa,WAAWA,EAAE,WAAW;AAAA;AAAA,IAExD,cAAc,OAAOA,EAAE,gBAAiB,WAAWA,EAAE,eAAe;AAAA,IACpE,eAAe,OAAOA,EAAE,iBAAkB,WAAWA,EAAE,gBAAgB;AAAA,IACvE,iBACE,OAAOA,EAAE,uBAAwB,YAAYA,EAAE,sBAAsB,IACjEA,EAAE,sBAAsBF,EAAI,cAC5B;AAAA,EAAA,EACN;AACF,SAAO;AAAA,IACL,eAAeA,EAAI;AAAA,IACnB,gBAAgBA,EAAI;AAAA,IACpB,QAAQ;AAAA,MACN,QAAAC;AAAA,MACA,QAAQD,EAAI,eAAe,CAAA;AAAA,MAC3B,OAAOA,EAAI;AAAA,IAAA;AAAA,EACb;AAEJ;AASO,SAASG,EACdC,GACAC,GAC+B;;AAC/B,MAAI,CAACA,EAAU;AAMf,QAAM,EAAE,QAAAJ,MAAWG,EAAO;AAM1B,M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U,IAAI;AAAA,IAChC,CAAC,GACI,MAAM;AACX,MAAAG,IAAY;AAAA,IACd;AAAA,EACF,GAAG,CAACL,GAAMC,CAAO,CAAC,GAEXL;AACT;"}
@@ -1,6 +1,11 @@
1
1
  import { ExportConfig } from '../workers/export-protocol';
2
2
  import { ArtboardElement } from '../core/ArtboardElement';
3
3
  import { BaseElement } from '../core/BaseElement';
4
+ /**
5
+ * Load the export worker's code (once; later calls share it). Exported for tests and for a host that wants to warm it
6
+ * ahead of a known export; WorkerExportManager.initialize() calls it itself.
7
+ */
8
+ export declare function loadExportWorkerCode(): Promise<string>;
4
9
  /** Result of a worker export operation returning a data URL string. */
5
10
  export interface WorkerExportResult {
6
11
  /** Base64-encoded data URL of the exported image. */
@@ -53,6 +58,8 @@ export declare class WorkerExportManager {
53
58
  private isProcessingQueue;
54
59
  private isReady;
55
60
  private readyPromise;
61
+ /** Bumped by terminate(): an initialize() whose worker code arrives after it never starts a worker. */
62
+ private initGeneration;
56
63
  private requestIdCounter;
57
64
  private workerCrashCount;
58
65
  private readonly MAX_CRASHES_BEFORE_FALLBACK;
@@ -101,6 +108,8 @@ export declare class WorkerExportManager {
101
108
  * Initialize the worker
102
109
  */
103
110
  initialize(): Promise<void>;
111
+ /** Spawn the worker from its code and resolve once it reports `ready`. */
112
+ private startWorker;
104
113
  /**
105
114
  * Restart worker after crash
106
115
  */
@@ -2,16 +2,16 @@ import { jsx as r, jsxs as y, Fragment as Pn } from "react/jsx-runtime";
2
2
  import * as $n from "react";
3
3
  import je, { useState as le, useEffect as Pe, useCallback as ft, useMemo as xs, useContext as Ar, createContext as Nr, useRef as we, useImperativeHandle as nr, forwardRef as Dr } from "react";
4
4
  import { b as rs, o as sr, t as _s, v as $s, d as Ts, j as Br, c as Or, m as zr } from "./design-builder-CoCtjIwj.js";
5
- import { l as rr, I as ze, s as Xr, u as or, c as Fn, v as Qt, i as _e, J as Yr, G as Hr, H as Lr, F as _r, W as $r, T as dn, q as un, r as hn, B as Ct, Y as Fr, Z as Wr, _ as Vr, D as ir, k as Kr, b as ar } from "./useCommands-x8J7_Mzy.js";
5
+ import { l as rr, I as ze, s as Xr, u as or, c as Fn, v as Qt, i as _e, J as Yr, G as Hr, H as Lr, F as _r, W as $r, T as dn, q as un, r as hn, B as Ct, Y as Fr, Z as Wr, _ as Vr, D as ir, k as Kr, b as ar } from "./useCommands-f-UTuBI1.js";
6
6
  import { I as Yt, G as Re, b5 as Is, aO as ys, ab as cr, b6 as Fs, b7 as Ur, Y as Cn, b8 as Gr, b9 as us, P as wn, c as zn, a1 as en, $ as ms, ba as qr, T as Qe, u as jr, bb as Jn, bc as Zr, bd as Jr, be as Qr, a0 as lr, _ as eo, bf as Es, Z as to, g as no, S as Qn, at as so, x as Bn } from "./FontAnalyzer-DWHS41ba.js";
7
7
  import { createPortal as dr } from "react-dom";
8
- import { b as ro, n as ur, g as _n, c as oo, r as io, d as ao, C as Ws, e as Vs, f as gs, T as co, a as lo, A as uo, S as ho, I as fo } from "./CanvasRenderer-COO5UXtZ.js";
8
+ import { b as ro, n as ur, g as _n, c as oo, r as io, d as ao, C as Ws, e as Vs, f as gs, T as co, a as lo, A as uo, S as ho, I as fo } from "./CanvasRenderer-BuZVwUch.js";
9
9
  import { u as po } from "./ThemeContext-Rjz25x9X.js";
10
10
  import { renderToStaticMarkup as mo } from "react-dom/server";
11
- import { D as Ps, n as As, o as hr, p as Ns, e as go, q as Mt } from "./ContextualToolbars-_5zqlcSw.js";
12
- import { L as Tt, S as fr, T as Ot, I as xo } from "./custom-icons-o1U13Vcg.js";
11
+ import { D as Ps, n as As, o as hr, p as Ns, e as go, q as Mt } from "./ContextualToolbars-Cy91bYY9.js";
12
+ import { L as Tt, S as fr, T as Ot, I as xo } from "./custom-icons-sebOL9Xd.js";
13
13
  import * as ts from "@radix-ui/react-radio-group";
14
- import { R as yo, S as Ks, U as Us } from "./ExportManager-BbBfO22S.js";
14
+ import { R as yo, S as Ks, U as Us } from "./ExportManager-B_7SG-Ox.js";
15
15
  import { cva as pr } from "class-variance-authority";
16
16
  import { debounce as Gs } from "lodash-es";
17
17
  const bo = {
@@ -5646,12 +5646,12 @@ async function Za() {
5646
5646
  ] = await Promise.all([
5647
5647
  Promise.resolve().then(() => ba),
5648
5648
  Promise.resolve().then(() => Ca),
5649
- import("./ImagePanel-BaX0UE-L.js"),
5649
+ import("./ImagePanel-CJJzUQWY.js"),
5650
5650
  Promise.resolve().then(() => ka),
5651
5651
  Promise.resolve().then(() => Ma),
5652
- import("./ContextualToolbars-_5zqlcSw.js").then((c) => c.s),
5652
+ import("./ContextualToolbars-Cy91bYY9.js").then((c) => c.s),
5653
5653
  Promise.resolve().then(() => Ta),
5654
- import("./ContextualToolbars-_5zqlcSw.js").then((c) => c.r)
5654
+ import("./ContextualToolbars-Cy91bYY9.js").then((c) => c.r)
5655
5655
  ]);
5656
5656
  It("effects-panel", {
5657
5657
  component: e,
@@ -8681,4 +8681,4 @@ export {
8681
8681
  ja as u,
8682
8682
  rc as v
8683
8683
  };
8684
- //# sourceMappingURL=validation-BMB6_hp4.js.map
8684
+ //# sourceMappingURL=validation-B5eH5mzI.js.map