@snowcone-app/ui 0.10.17 → 0.10.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/ui",
3
- "version": "0.10.17",
3
+ "version": "0.10.18",
4
4
  "description": "React components for merchandise visualization and customization",
5
5
  "keywords": [
6
6
  "react",
@@ -103,7 +103,7 @@
103
103
  "react-instantsearch": "^7.15.5",
104
104
  "react-zoom-pan-pinch": "^3.6.4",
105
105
  "tailwind-merge": "^3.0.0",
106
- "@snowcone-app/sdk": "0.31.1"
106
+ "@snowcone-app/sdk": "0.31.2"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@chromatic-com/storybook": "^4.1.2",
@@ -27,6 +27,7 @@ import {
27
27
  resolvePreviewVariantId,
28
28
  resolveMockupId,
29
29
  SNOWCONE_HOSTS,
30
+ type MockupView,
30
31
  } from "@snowcone-app/sdk";
31
32
 
32
33
  /** Slugify a placement label into the catalog's `placements[].key` form. */
@@ -84,7 +85,11 @@ function buildHeroMockupUrl(args: {
84
85
  placements: PlacementLike[];
85
86
  mockupId: string;
86
87
  variantId: string;
87
- width: number;
88
+ /**
89
+ * A render width (16:9); the whole 8:3 strip at a width; or a crop of the strip (`view=`, delivered at its own px: no
90
+ * width).
91
+ */
92
+ size: { width: number; aspect?: "8:3" } | { stripView: MockupView };
88
93
  /** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */
89
94
  bg?: string;
90
95
  }): string | null {
@@ -99,13 +104,25 @@ function buildHeroMockupUrl(args: {
99
104
  return getMockupUrl(args.productCode, {
100
105
  shop: snow.shop,
101
106
  design: publicDesign,
102
- width: args.width,
107
+ ...("stripView" in args.size
108
+ ? { aspect: "8:3" as const, stripView: args.size.stripView }
109
+ : { width: args.size.width, ...(args.size.aspect ? { aspect: args.size.aspect } : {}) }),
103
110
  view: args.mockupId,
104
111
  variant: args.variantId,
105
112
  ...(args.bg ? { bg: args.bg } : {}),
106
113
  ...(snow.resolver ? { base: snow.resolver } : {}),
107
114
  });
108
115
  }
116
+ /** A crop of the strip needs no width: it is delivered at its own px. */
117
+ function isCrop(stripView: MockupView | "whole-strip" | undefined): stripView is MockupView {
118
+ return stripView !== undefined && stripView !== "whole-strip";
119
+ }
120
+
121
+ function heroSize(stripView: MockupView | "whole-strip" | undefined, width: number): { width: number; aspect?: "8:3" } | { stripView: MockupView } {
122
+ if (isCrop(stripView)) return { stripView };
123
+ return stripView === "whole-strip" ? { width, aspect: "8:3" } : { width };
124
+ }
125
+
109
126
  import { useImageTransition } from "../hooks/useImageTransition";
110
127
  import { useContainerWidth } from "../hooks/viewport/useContainerWidth";
111
128
  import { observe } from "../hooks/visibility/observerPool";
@@ -181,6 +198,16 @@ export interface HeroProductImageProps {
181
198
  * phone, where cover would cut a 16:9 frame to its centre). Stamped as data-fit.
182
199
  */
183
200
  fit?: "cover" | "whole";
201
+
202
+ /**
203
+ * Ask for a crop of the mockup's 8:3 strip (`aspect=8:3&view=<r>@<f>`, no width: the crop comes at its own px), or
204
+ * `"whole-strip"` (`aspect=8:3` at the measured width: a window wider than the crop grid), instead of a width-sized
205
+ * 16:9 picture: the desktop hero of a mockup whose catalog entry carries `strip` (www heroStrip.ts). Only the static
206
+ * picture follows it; realtime frames (an edit) stay the session's 16:9. Stamped as data-strip-view.
207
+ */
208
+ stripView?: MockupView | "whole-strip";
209
+ /** Called with the URL of each picture once it is ON SCREEN (its <img> loaded), not when it is asked for. */
210
+ onShown?: (url: string) => void;
184
211
  }
185
212
 
186
213
  /**
@@ -231,6 +258,8 @@ export const HeroProductImage = memo(function HeroProductImage({
231
258
  unavailableText = "Preview unavailable",
232
259
  viewportPolicy = false,
233
260
  fit = "cover",
261
+ stripView,
262
+ onShown,
234
263
  }: HeroProductImageProps) {
235
264
  // Context
236
265
  const context = useProductOptional();
@@ -302,8 +331,8 @@ export const HeroProductImage = memo(function HeroProductImage({
302
331
  if (context?.loading) return null;
303
332
  // Skip if no valid artwork
304
333
  if (!effectiveArtworkSrc || effectiveArtworkSrc.trim() === "") return null;
305
- // Skip if missing required IDs or width not yet measured
306
- if (!actualProductId || !actualMockupId || !actualGvid || actualGvid === "default" || !width) return null;
334
+ // Skip if missing required IDs or width not yet measured (a strip crop needs no width)
335
+ if (!actualProductId || !actualMockupId || !actualGvid || actualGvid === "default" || !(isCrop(stripView) || width)) return null;
307
336
 
308
337
  // Get placements for design creation
309
338
  const allPlacements = product?.placements || context?.product?.placements || [];
@@ -340,10 +369,11 @@ export const HeroProductImage = memo(function HeroProductImage({
340
369
  placements: allPlacements,
341
370
  mockupId: actualMockupId,
342
371
  variantId: actualGvid,
343
- width,
372
+ size: heroSize(stripView, width),
344
373
  bg: mockupBg,
345
374
  });
346
375
  }, [
376
+ stripView,
347
377
  realtimeUrl,
348
378
  mode,
349
379
  context?.loading,
@@ -413,6 +443,8 @@ export const HeroProductImage = memo(function HeroProductImage({
413
443
  // Ref for onUrlGenerated callback (used in realtime subscription without adding to deps)
414
444
  const onUrlGeneratedRef = useRef(onUrlGenerated);
415
445
  onUrlGeneratedRef.current = onUrlGenerated;
446
+ const onShownRef = useRef(onShown);
447
+ onShownRef.current = onShown;
416
448
 
417
449
  // Track layers.length in a ref so we can read it without depending on it
418
450
  // This prevents effect re-runs when layers change (which would cause duplicate requests)
@@ -915,7 +947,7 @@ export const HeroProductImage = memo(function HeroProductImage({
915
947
  !actualMockupId ||
916
948
  !actualGvid ||
917
949
  actualGvid === "default" ||
918
- !width
950
+ !(isCrop(stripView) || width)
919
951
  ) {
920
952
  return;
921
953
  }
@@ -935,7 +967,7 @@ export const HeroProductImage = memo(function HeroProductImage({
935
967
  placements: allPlacements,
936
968
  mockupId: actualMockupId,
937
969
  variantId: actualGvid,
938
- width: width,
970
+ size: heroSize(stripView, width),
939
971
  bg: mockupBg,
940
972
  });
941
973
  if (!url) return;
@@ -1027,6 +1059,7 @@ export const HeroProductImage = memo(function HeroProductImage({
1027
1059
  mockupBg,
1028
1060
  images,
1029
1061
  width,
1062
+ stripView,
1030
1063
  effects,
1031
1064
  // Use primitive values extracted at the top of the component
1032
1065
  artworkSrc,
@@ -1232,6 +1265,7 @@ export const HeroProductImage = memo(function HeroProductImage({
1232
1265
  // Which picture this is (machine-readable: the canary and verify-www name pictures by it, never by DOM order).
1233
1266
  data-mockup-id={actualMockupId || undefined}
1234
1267
  data-fit={fit}
1268
+ data-strip-view={stripView}
1235
1269
  data-picture-failed={imgFailed ? "E_PICTURE_UNDISPLAYED" : undefined}
1236
1270
  data-picture-failed-src={failedSrc}
1237
1271
  data-mockup-unavailable={unavailable ? unavailable.code : undefined}
@@ -1283,6 +1317,7 @@ export const HeroProductImage = memo(function HeroProductImage({
1283
1317
  onLoad();
1284
1318
  }
1285
1319
  onUrlGeneratedRef.current?.(renderedUrl);
1320
+ if (renderedUrl) onShownRef.current?.(renderedUrl);
1286
1321
  }}
1287
1322
  onError={() => {
1288
1323
  // First failure for this URL → retry once before giving up
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A plate's desktop hero asks for the crop of its 8:3 strip the window shows (lane shapes #5520, the hero-crop design):
3
+ * stripView="<r>@<f>" builds `aspect=8:3&view=<r>@<f>` with NO width; "whole-strip" builds aspect=8:3 at a width; no
4
+ * stripView keeps today's width-sized 16:9 URL.
5
+ */
6
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
7
+ import React from "react";
8
+ import { render, waitFor, cleanup } from "@testing-library/react";
9
+ import { HeroProductImage } from "../HeroProductImage";
10
+
11
+ const ART = { type: "regular", src: "https://example.test/art.png" } as const;
12
+ const PRODUCT = { id: "A9AVRY", placements: [{ label: "Front", key: "front" }] };
13
+
14
+ async function heroSrc(props: Partial<React.ComponentProps<typeof HeroProductImage>>): Promise<URL> {
15
+ const { container } = render(
16
+ <HeroProductImage productId="A9AVRY" mockupId="FVC6BW" gvid="gv1" artwork={ART} product={PRODUCT} width={1600} {...props} />,
17
+ );
18
+ await waitFor(() => expect(container.querySelector("img")).not.toBeNull());
19
+ return new URL(container.querySelector("img")!.getAttribute("src")!);
20
+ }
21
+
22
+ describe("HeroProductImage stripView", () => {
23
+ beforeEach(() => {
24
+ (window as unknown as { snowcone?: unknown }).snowcone = { shop: "shop1" };
25
+ });
26
+ afterEach(() => {
27
+ cleanup();
28
+ delete (window as unknown as { snowcone?: unknown }).snowcone;
29
+ });
30
+
31
+ it("a crop: aspect=8:3 and view=, no width, stamped data-strip-view", async () => {
32
+ const src = await heroSrc({ stripView: "1.9@0.375" });
33
+ expect(src.searchParams.get("aspect")).toBe("8:3");
34
+ expect(src.searchParams.get("view")).toBe("1.9@0.375");
35
+ expect(src.searchParams.get("mockup")).toBe("FVC6BW");
36
+ expect(src.searchParams.has("width")).toBe(false);
37
+ expect((document.querySelector("[data-hero-image]") as HTMLElement).dataset.stripView).toBe("1.9@0.375");
38
+ });
39
+
40
+ it("the whole strip: aspect=8:3 at a width, no view", async () => {
41
+ const src = await heroSrc({ stripView: "whole-strip" });
42
+ expect(src.searchParams.get("aspect")).toBe("8:3");
43
+ expect(src.searchParams.has("view")).toBe(false);
44
+ expect(src.searchParams.has("width")).toBe(true);
45
+ });
46
+
47
+ it("no stripView: today's 16:9 URL at a width", async () => {
48
+ const src = await heroSrc({});
49
+ expect(src.searchParams.has("aspect")).toBe(false);
50
+ expect(src.searchParams.has("view")).toBe(false);
51
+ expect(src.searchParams.has("width")).toBe(true);
52
+ });
53
+ });
@@ -57,6 +57,12 @@ export interface CarouselImage {
57
57
  * Stamped data-gallery-role on the slide.
58
58
  */
59
59
  galleryRole?: "size-picture";
60
+
61
+ /**
62
+ * A plate's 8:3 strip (the catalog's `mockups[].strip`): the desktop hero asks for the crop its window shows
63
+ * (`aspect=8:3&view=<r>@<f>`). Absent = the 16:9 hero. Phones ignore it.
64
+ */
65
+ strip?: { shape: "8:3"; productX: number };
60
66
  }
61
67
 
62
68
  /**