@snowcone-app/ui 0.10.22 → 0.11.1

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.
@@ -0,0 +1,217 @@
1
+ {
2
+ "id": "NBYVCX",
3
+ "name": "Custom Sticky Note Cube",
4
+ "slug": "custom-note-cube",
5
+ "tags": [
6
+ "Home and Office"
7
+ ],
8
+ "price": 3900,
9
+ "mockups": [
10
+ {
11
+ "id": "UHN9QM",
12
+ "gvids": [
13
+ "hcxmb7"
14
+ ]
15
+ },
16
+ {
17
+ "id": "AK5RFJ",
18
+ "gvids": [
19
+ "hcxmb7"
20
+ ]
21
+ },
22
+ {
23
+ "id": "HPDN6E",
24
+ "gvids": [
25
+ "hcxmb7"
26
+ ]
27
+ },
28
+ {
29
+ "id": "TFFBEP",
30
+ "gvids": [
31
+ "hcxmb7"
32
+ ]
33
+ },
34
+ {
35
+ "id": "A6EVP3",
36
+ "gvids": [
37
+ "hcxmb7"
38
+ ]
39
+ },
40
+ {
41
+ "id": "HJ6QNM",
42
+ "gvids": [
43
+ "hcxmb7"
44
+ ]
45
+ },
46
+ {
47
+ "id": "7KQA7B",
48
+ "gvids": [
49
+ "hcxmb7"
50
+ ]
51
+ },
52
+ {
53
+ "id": "YQ4FK6",
54
+ "gvids": [
55
+ "hcxmb7"
56
+ ]
57
+ },
58
+ {
59
+ "id": "DQYP5P",
60
+ "gvids": [
61
+ "hcxmb7"
62
+ ]
63
+ },
64
+ {
65
+ "id": "J5CUNW",
66
+ "gvids": [
67
+ "hcxmb7"
68
+ ]
69
+ },
70
+ {
71
+ "id": "JPJ222",
72
+ "gvids": [
73
+ "hcxmb7"
74
+ ]
75
+ },
76
+ {
77
+ "id": "H7H2BB",
78
+ "gvids": [
79
+ "hcxmb7"
80
+ ]
81
+ },
82
+ {
83
+ "id": "WMEPJQ",
84
+ "gvids": [
85
+ "hcxmb7"
86
+ ]
87
+ },
88
+ {
89
+ "id": "452QNM",
90
+ "gvids": [
91
+ "hcxmb7"
92
+ ]
93
+ },
94
+ {
95
+ "id": "HVHGQP",
96
+ "gvids": [
97
+ "hcxmb7"
98
+ ]
99
+ },
100
+ {
101
+ "id": "FTFYJD",
102
+ "gvids": [
103
+ "hcxmb7"
104
+ ]
105
+ },
106
+ {
107
+ "id": "MMY29Q",
108
+ "gvids": [
109
+ "hcxmb7"
110
+ ]
111
+ },
112
+ {
113
+ "id": "KPU6EB",
114
+ "gvids": [
115
+ "hcxmb7"
116
+ ]
117
+ },
118
+ {
119
+ "id": "VVW3NE",
120
+ "gvids": [
121
+ "hcxmb7"
122
+ ]
123
+ },
124
+ {
125
+ "id": "4NCMAP",
126
+ "gvids": [
127
+ "hcxmb7"
128
+ ]
129
+ },
130
+ {
131
+ "id": "5QR92E",
132
+ "gvids": [
133
+ "hcxmb7"
134
+ ]
135
+ },
136
+ {
137
+ "id": "JN36PA",
138
+ "gvids": [
139
+ "hcxmb7"
140
+ ]
141
+ },
142
+ {
143
+ "id": "TMU27B",
144
+ "gvids": [
145
+ "hcxmb7"
146
+ ]
147
+ }
148
+ ],
149
+ "options": {
150
+ "combinations": [
151
+ {
152
+ "price": 3900,
153
+ "variantId": "hcxmb7",
154
+ "printableId": "5TT2G2"
155
+ }
156
+ ]
157
+ },
158
+ "care_guide": null,
159
+ "description": [
160
+ "A cube of 700 sticky notes, 3.375 x 3.375 in and 3.5 in tall (8.6 x 8.6 x 8.9 cm), with your design printed once around all four sides. The top and bottom are plain white. Each sheet is matte white 60 lb paper with a light adhesive strip."
161
+ ],
162
+ "key_features": [
163
+ "<b>\u2b50\ufe0f Your Art on Four Sides</b> \u2013 Your design is printed once around all four sides of the stack.",
164
+ "",
165
+ "<b>\u2b50\ufe0f 700 Sticky Notes</b> \u2013 700 sheets of matte white 60 lb paper, each with a light adhesive strip.",
166
+ "",
167
+ "<b>\u2b50\ufe0f Cube Size</b> \u2013 3.375 x 3.375 in and 3.5 in tall (8.6 x 8.6 x 8.9 cm).",
168
+ "",
169
+ "<b>\u2b50\ufe0f Plain White Top</b> \u2013 The top and bottom are plain white, not printed."
170
+ ],
171
+ "days_to_deliver": "7 - 10",
172
+ "ships_from_country": "US",
173
+ "variants": [
174
+ {
175
+ "gvid": "hcxmb7",
176
+ "gvidForMockup": null,
177
+ "placements": [
178
+ {
179
+ "label": "Front",
180
+ "width": 1088,
181
+ "height": 1125
182
+ }
183
+ ]
184
+ }
185
+ ],
186
+ "placements": [
187
+ {
188
+ "label": "Front",
189
+ "key": "front",
190
+ "type": "image",
191
+ "width": 1088,
192
+ "height": 1125,
193
+ "defaultScaleMode": "fill",
194
+ "fitMarginTop": 0,
195
+ "fitMarginRight": 0,
196
+ "fitMarginBottom": 0,
197
+ "fitMarginLeft": 0,
198
+ "fitAlign": "c",
199
+ "align": "c",
200
+ "scale": 1,
201
+ "offsetX": 0,
202
+ "offsetY": 0
203
+ }
204
+ ],
205
+ "defaultGvid": "hcxmb7",
206
+ "prices": {},
207
+ "currencies": {},
208
+ "ships_to": [],
209
+ "requiredPlacements": [
210
+ {
211
+ "label": "Front",
212
+ "type": "image",
213
+ "autoFilledByVariant": false
214
+ }
215
+ ],
216
+ "album": null
217
+ }
@@ -152,6 +152,8 @@ export interface MobileProductCarouselProps {
152
152
  * cover-adjusted resolution instead of just the container CSS width.
153
153
  */
154
154
  mockupWidth?: number;
155
+ /** Server-signed hero URLs (the PDP's first-hero preload): a slide whose URL matches uses it, never re-signing it. */
156
+ presignedHeroUrls?: ReadonlyArray<{ url: string; signed: string }>;
155
157
 
156
158
  /**
157
159
  * Fires when `HeroProductImage` finishes generating a mockup URL for a
@@ -198,6 +200,7 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
198
200
  onZoomChange,
199
201
  stickyHeroContext,
200
202
  mockupWidth,
203
+ presignedHeroUrls,
201
204
  onMockupUrlGenerated,
202
205
  renderImageAction,
203
206
  errorText,
@@ -905,6 +908,7 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
905
908
  placement={image.placement}
906
909
  mockupId={image.mockupId}
907
910
  width={mockupWidth}
911
+ presigned={presignedHeroUrls}
908
912
  realtimeUrl={
909
913
  image.mockupId
910
914
  ? realtimeMockupUrls[image.mockupId] ??
@@ -0,0 +1,136 @@
1
+ /**
2
+ * The hero's static mockup URL — ONE builder for the client (HeroProductImage) and the server (the PDP's first-hero
3
+ * preload, lane shapes 2026-11-19). Server-safe: no window, no React. The server must request exactly the URL the
4
+ * client will, or the phone downloads the hero twice; HeroProductImage.ssr-match.test.tsx renders the real client
5
+ * component and fails when the two differ.
6
+ */
7
+ import {
8
+ createDesignForPlacements,
9
+ deriveDefaultSelection,
10
+ getMockupUrl,
11
+ ordinaryMockups,
12
+ resolveMockupId,
13
+ resolvePreviewVariantId,
14
+ resolveVariantId,
15
+ toCombinations,
16
+ toOptionAttributes,
17
+ type CatalogProduct,
18
+ type Design,
19
+ type DesignElement,
20
+ type MockupView,
21
+ } from "@snowcone-app/sdk";
22
+
23
+ /** Slugify a placement label into the catalog's `placements[].key` form. */
24
+ export function slugifyPlacementKey(label: string): string {
25
+ return label
26
+ .toLowerCase()
27
+ .replace(/[^a-z0-9]+/g, "_")
28
+ .replace(/^_+|_+$/g, "");
29
+ }
30
+
31
+ export type PlacementLike = { label: string; key?: string; type?: string | null };
32
+
33
+ /**
34
+ * Convert the SDK's `DesignElement[]` (label-keyed, used by the realtime/canvas
35
+ * path) into the public resolver's `Design` (placement-key → fill), so a static
36
+ * `<img>` can be built via the **signing resolver** (`getMockupUrl`) rather than
37
+ * the unsigned direct-renderer builder. The renderer requires a `seal`, which
38
+ * only the resolver adds (ADR-0076).
39
+ */
40
+ export function toPublicDesign(elements: DesignElement[], placements: PlacementLike[]): Design {
41
+ const design: Design = {};
42
+ for (const el of elements) {
43
+ if (!el.placement) continue;
44
+ const match = placements.find((p) => p.label === el.placement);
45
+ const key = match?.key || slugifyPlacementKey(el.placement);
46
+ if (el.type === "color") {
47
+ if (el.hex) design[key] = { color: el.hex };
48
+ } else if (el.imageUrl) {
49
+ const aligned = el.alignment && el.alignment !== "center";
50
+ design[key] =
51
+ aligned || el.tiles
52
+ ? {
53
+ src: el.imageUrl,
54
+ ...(aligned ? { align: el.alignment } : {}),
55
+ ...(el.tiles ? { tile: el.tiles } : {}),
56
+ }
57
+ : el.imageUrl;
58
+ }
59
+ }
60
+ return design;
61
+ }
62
+
63
+ /** A render width (16:9), or a crop of the 8:3 strip (`view=`: at its own px, or downscaled to `width`). */
64
+ export type HeroSize = { width: number } | { stripView: MockupView; width?: number };
65
+
66
+ /**
67
+ * Build a static mockup `<img>` URL through the signing resolver (ADR-0076), UNSIGNED (the L3 `&signature` is added by
68
+ * the signer: /api/sign on the client, lib/sign-mockup on the server). Null when the shop is unknown or the design empty.
69
+ */
70
+ export function heroMockupUrl(args: {
71
+ shop: string | undefined;
72
+ /** The local resolver host (dev); prod falls back to img.snowcone.app. */
73
+ resolver?: string;
74
+ productCode: string;
75
+ design: DesignElement[];
76
+ placements: PlacementLike[];
77
+ mockupId: string;
78
+ variantId: string;
79
+ size: HeroSize;
80
+ /** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */
81
+ bg?: string;
82
+ }): string | null {
83
+ if (!args.shop) return null;
84
+ const publicDesign = toPublicDesign(args.design, args.placements);
85
+ if (Object.keys(publicDesign).length === 0) return null;
86
+ return getMockupUrl(args.productCode, {
87
+ shop: args.shop,
88
+ design: publicDesign,
89
+ ...("stripView" in args.size
90
+ ? { aspect: "8:3" as const, stripView: args.size.stripView, ...(args.size.width !== undefined ? { width: args.size.width } : {}) }
91
+ : { width: args.size.width }),
92
+ view: args.mockupId,
93
+ variant: args.variantId,
94
+ ...(args.bg ? { bg: args.bg } : {}),
95
+ ...(args.resolver ? { base: args.resolver } : {}),
96
+ });
97
+ }
98
+
99
+ /** The phone carousel's render width: ScrollHero covers 70svh and starts zoomed, so it always asks 3000 (page-client). */
100
+ export const MOBILE_HERO_WIDTH = 3000;
101
+
102
+ /**
103
+ * The URL the phone PDP's FIRST hero requests on a fresh load — the product's default selection, the artwork centred on
104
+ * every image placement, no tiles — built by the same steps HeroProductImage runs: the first ordinary mockup
105
+ * (page-client heroImages), resolveVariantId → resolvePreviewVariantId, createDesignForPlacements, heroMockupUrl.
106
+ * Null when anything the client would need is missing (it then builds nothing either, or something the server can't know).
107
+ */
108
+ export function firstMobileHeroUrl(args: {
109
+ product: CatalogProduct | null | undefined;
110
+ /** The artwork the page applies: "default" = the product's own catalog art (the only case the server signs). */
111
+ artworkSrc: string;
112
+ shop: string | undefined;
113
+ resolver?: string;
114
+ bg?: string;
115
+ }): string | null {
116
+ const product = args.product as (CatalogProduct & { mockups?: Array<{ id: string }>; placements?: PlacementLike[] }) | null | undefined;
117
+ if (!product?.id || !args.artworkSrc) return null;
118
+ const placements = product.placements ?? [];
119
+ const first = ordinaryMockups(product.mockups ?? [])[0];
120
+ if (!first || placements.length === 0) return null;
121
+ const optionAttributes = toOptionAttributes(product);
122
+ const combinations = toCombinations(product);
123
+ const selection: Record<string, string> = { ...deriveDefaultSelection(optionAttributes, combinations) };
124
+ for (const p of placements) if (p.type === "color" && !selection[p.label]) selection[p.label] = "#000000";
125
+ const context = { product, optionAttributes, combinations, selection };
126
+ const selected = resolveVariantId(context);
127
+ const mockupId = resolveMockupId(context, selected, first.id);
128
+ if (!mockupId) return null;
129
+ const variantId = resolvePreviewVariantId(context, selected, mockupId);
130
+ if (!variantId || variantId === "default") return null;
131
+ const placementDesigns: Record<string, { imageUrl: string; alignment: "center" }> = {};
132
+ for (const p of placements) if (p.type !== "color") placementDesigns[p.label] = { imageUrl: args.artworkSrc, alignment: "center" };
133
+ const design = createDesignForPlacements(placements as never, [], { artworkSrc: args.artworkSrc, placementDesigns } as never);
134
+ if (!design || design.length === 0) return null;
135
+ return heroMockupUrl({ shop: args.shop, resolver: args.resolver, productCode: product.id, design, placements, mockupId, variantId, size: { width: MOBILE_HERO_WIDTH }, bg: args.bg });
136
+ }