@snowcone-app/canvas 0.38.0 → 0.39.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/{CanvasRenderer-D-E5WWLm.js → CanvasRenderer-COO5UXtZ.js} +704 -669
- package/dist/CanvasRenderer-COO5UXtZ.js.map +1 -0
- package/dist/{CanvasStateV1-C9LQt2J0.js → CanvasStateV1-CJJff7Ci.js} +315 -314
- package/dist/{CanvasStateV1-C9LQt2J0.js.map → CanvasStateV1-CJJff7Ci.js.map} +1 -1
- package/dist/{EditorCanvasImpl-BnxEbr2p.js → EditorCanvasImpl-C_72UKu3.js} +3 -3
- package/dist/{EditorCanvasImpl-BnxEbr2p.js.map → EditorCanvasImpl-C_72UKu3.js.map} +1 -1
- package/dist/FontAnalyzer-DWHS41ba.js.map +1 -1
- package/dist/{SnowconeCanvas-CWSPyqqj.js → SnowconeCanvas-C-YbGCcQ.js} +4 -4
- package/dist/{SnowconeCanvas-CWSPyqqj.js.map → SnowconeCanvas-C-YbGCcQ.js.map} +1 -1
- package/dist/advanced.mjs +358 -360
- package/dist/advanced.mjs.map +1 -1
- package/dist/components/VisualGuideOverlay.d.ts +4 -1
- package/dist/components/embed-realtime/usePieceGuideBundle.d.ts +2 -0
- package/dist/{embed-SOFUZlGB.js → embed-DtlgX9iG.js} +5 -5
- package/dist/{embed-SOFUZlGB.js.map → embed-DtlgX9iG.js.map} +1 -1
- package/dist/embed.mjs +3 -3
- package/dist/index.mjs +4 -4
- package/dist/internals.mjs +2 -2
- package/dist/rendering/PieceGuideRenderer.d.ts +4 -1
- package/dist/state/CanvasStateV1.d.ts +3 -3
- package/dist/{template-fields-CBLHgW7G.js → template-fields-Dltc4Ztb.js} +2 -2
- package/dist/{template-fields-CBLHgW7G.js.map → template-fields-Dltc4Ztb.js.map} +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/{usePieceGuideBundle-C7r06a_x.js → usePieceGuideBundle-Cab2gRnn.js} +19 -16
- package/dist/usePieceGuideBundle-Cab2gRnn.js.map +1 -0
- package/dist/utils/pieceRotation.d.ts +35 -0
- package/dist/{validation-BG-V98h0.js → validation-Dh9sVEb9.js} +1428 -1430
- package/dist/validation-Dh9sVEb9.js.map +1 -0
- package/example/package.json +1 -1
- package/package.json +1 -1
- package/dist/CanvasRenderer-D-E5WWLm.js.map +0 -1
- package/dist/usePieceGuideBundle-C7r06a_x.js.map +0 -1
- package/dist/validation-BG-V98h0.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { p as
|
|
2
|
-
import { useState as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
1
|
+
import { p as a } from "./FontAnalyzer-DWHS41ba.js";
|
|
2
|
+
import { useState as s, useEffect as h } from "react";
|
|
3
|
+
const d = "https://api.snowcone.app";
|
|
4
|
+
function c(e) {
|
|
5
5
|
const i = e.pieces.map((t) => ({
|
|
6
6
|
id: t.id,
|
|
7
7
|
x: t.x,
|
|
@@ -9,6 +9,9 @@ function d(e) {
|
|
|
9
9
|
width: t.width,
|
|
10
10
|
height: t.height,
|
|
11
11
|
rotation: typeof t.rotation == "number" ? t.rotation : void 0,
|
|
12
|
+
// natural (unrotated) size — required at non-right angles (a bandana's 45° folded view)
|
|
13
|
+
naturalWidth: typeof t.naturalWidth == "number" ? t.naturalWidth : void 0,
|
|
14
|
+
naturalHeight: typeof t.naturalHeight == "number" ? t.naturalHeight : void 0,
|
|
12
15
|
safeAreaInsetPx: typeof t.safeAreaInsetInches == "number" && t.safeAreaInsetInches > 0 ? t.safeAreaInsetInches * e.templateDpi : void 0
|
|
13
16
|
}));
|
|
14
17
|
return {
|
|
@@ -22,7 +25,7 @@ function d(e) {
|
|
|
22
25
|
};
|
|
23
26
|
}
|
|
24
27
|
function g(e, i) {
|
|
25
|
-
var
|
|
28
|
+
var o;
|
|
26
29
|
if (!i) return;
|
|
27
30
|
const { pieces: t } = e.config;
|
|
28
31
|
if (t.length > 1 && t.every(
|
|
@@ -30,36 +33,36 @@ function g(e, i) {
|
|
|
30
33
|
) && i.name && t.some((n) => n.id === i.name) && i.width === e.artboardWidth && i.height === e.artboardHeight)
|
|
31
34
|
return { ...e.config, pieces: t.filter((n) => n.id === i.name) };
|
|
32
35
|
if (i.width !== e.artboardWidth || i.height !== e.artboardHeight) {
|
|
33
|
-
typeof
|
|
36
|
+
typeof a < "u" && ((o = a.env) == null ? void 0 : o.NODE_ENV) !== "production" && console.warn(
|
|
34
37
|
`[RealtimeEmbed] This product has printable-area guides (authored at ${e.artboardWidth}×${e.artboardHeight}), but the design's artboard is ${i.width}×${i.height} — the dead-zone overlay is skipped because the coordinates wouldn't line up. Author the design at the placement's dimensions to get it.`
|
|
35
38
|
);
|
|
36
39
|
return;
|
|
37
40
|
}
|
|
38
41
|
return e.config;
|
|
39
42
|
}
|
|
40
|
-
function
|
|
41
|
-
const [t,
|
|
43
|
+
function l(e, i = d) {
|
|
44
|
+
const [t, r] = s(null);
|
|
42
45
|
return h(() => {
|
|
43
46
|
if (!e) {
|
|
44
|
-
|
|
47
|
+
r(null);
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
|
-
let
|
|
50
|
+
let o = !1;
|
|
48
51
|
return fetch(`${i}/printables/by-gvid/${encodeURIComponent(e)}/piece-guides`).then(async (n) => {
|
|
49
52
|
if (!n.ok) throw new Error(`status ${n.status}`);
|
|
50
53
|
return await n.json();
|
|
51
54
|
}).then((n) => {
|
|
52
|
-
|
|
55
|
+
o || r(c(n));
|
|
53
56
|
}).catch(() => {
|
|
54
|
-
|
|
57
|
+
o || r(null);
|
|
55
58
|
}), () => {
|
|
56
|
-
|
|
59
|
+
o = !0;
|
|
57
60
|
};
|
|
58
61
|
}, [e, i]), t;
|
|
59
62
|
}
|
|
60
63
|
export {
|
|
61
|
-
|
|
64
|
+
d as P,
|
|
62
65
|
g as p,
|
|
63
|
-
|
|
66
|
+
l as u
|
|
64
67
|
};
|
|
65
|
-
//# sourceMappingURL=usePieceGuideBundle-
|
|
68
|
+
//# sourceMappingURL=usePieceGuideBundle-Cab2gRnn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePieceGuideBundle-Cab2gRnn.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 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 = 'https://api.snowcone.app';\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","transformPieceGuides","raw","pieces","p","pieceGuidesForArtboard","bundle","artboard","process","usePieceGuideBundle","gvid","apiBase","setBundle","useState","useEffect","cancelled","res"],"mappings":";;AA6BO,MAAMA,IAAwB;AAgC9B,SAASC,EAAqBC,GAA+C;AAClF,QAAMC,IAAoCD,EAAI,OAAO,IAAI,CAACE,OAAO;AAAA,IAC/D,IAAIA,EAAE;AAAA,IACN,GAAGA,EAAE;AAAA,IACL,GAAGA,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AO,cAAc,mCAC7CC,EAAS,KAAK,IAAIA,EAAS,MAAM;AAAA,IAAA;AAI1C;AAAA,EACF;AACA,SAAOD,EAAO;AAChB;AAMO,SAASG,EACdC,GACAC,IAAkBX,GACO;AACzB,QAAM,CAACM,GAAQM,CAAS,IAAIC,EAAkC,IAAI;AAElE,SAAAC,EAAU,MAAM;AACd,QAAI,CAACJ,GAAM;AACT,MAAAE,EAAU,IAAI;AACd;AAAA,IACF;AACA,QAAIG,IAAY;AAChB,iBAAM,GAAGJ,CAAO,uBAAuB,mBAAmBD,CAAI,CAAC,eAAe,EAC3E,KAAK,OAAOM,MAAQ;AACnB,UAAI,CAACA,EAAI,GAAI,OAAM,IAAI,MAAM,UAAUA,EAAI,MAAM,EAAE;AACnD,aAAQ,MAAMA,EAAI,KAAA;AAAA,IACpB,CAAC,EACA,KAAK,CAACd,MAAQ;AACb,MAAKa,KAAWH,EAAUX,EAAqBC,CAAG,CAAC;AAAA,IACrD,CAAC,EACA,MAAM,MAAM;AAGX,MAAKa,KAAWH,EAAU,IAAI;AAAA,IAChC,CAAC,GACI,MAAM;AACX,MAAAG,IAAY;AAAA,IACd;AAAA,EACF,GAAG,CAACL,GAAMC,CAAO,CAAC,GAEXL;AACT;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Setup-time piece rotation on the canvas (mirrors apps/backend/printables/rotation.ts): a piece is displayed turned
|
|
3
|
+
* `rotation`° CLOCKWISE (any multiple of 45 — 90 for sideways panels, 45 for a bandana's folded diamond); its
|
|
4
|
+
* `x, y, width, height` are the DISPLAYED bounding box; guides are authored in its NATURAL (unrotated) frame.
|
|
5
|
+
* Everything maps natural → displayed about the centre: translate(D/2) · rotate(θ) · translate(−N/2).
|
|
6
|
+
*/
|
|
7
|
+
/** Bounding box of a w×h rect turned `deg`° (swapped at 90/270, the diamond's square at 45). */
|
|
8
|
+
export declare function rotatedBounds(w: number, h: number, deg: number): {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
export interface RotatedPieceLike {
|
|
13
|
+
id?: string;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
rotation?: number;
|
|
17
|
+
/** natural (unrotated) size — required for non-right angles, where it can't be recovered from the displayed box */
|
|
18
|
+
naturalWidth?: number;
|
|
19
|
+
naturalHeight?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The piece's natural size: explicit when given; at right angles derived from the displayed box (swap at 90/270).
|
|
23
|
+
* A non-right angle without it throws — guessing would draw every guide at the wrong size.
|
|
24
|
+
*/
|
|
25
|
+
export declare function naturalDims(p: RotatedPieceLike): {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
/** The natural → displayed transform as an SVG `transform` value ("" when unrotated). */
|
|
30
|
+
export declare function pieceSvgTransform(p: RotatedPieceLike): string;
|
|
31
|
+
/** Apply the natural → displayed transform to a 2D context (no-op when unrotated). */
|
|
32
|
+
export declare function applyPieceRotation(ctx: {
|
|
33
|
+
translate(x: number, y: number): void;
|
|
34
|
+
rotate(a: number): void;
|
|
35
|
+
}, p: RotatedPieceLike): void;
|