@snowcone-app/ui 0.11.15 → 0.11.16

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.11.15",
3
+ "version": "0.11.16",
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.33.0"
106
+ "@snowcone-app/sdk": "0.33.1"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@chromatic-com/storybook": "^4.1.2",
@@ -50,6 +50,7 @@ import React, {
50
50
  } from "react";
51
51
  import type { CarouselImage } from "./types";
52
52
  import { slideFit, zoomFit } from "./fit";
53
+ import { slideFirstViewProps } from "./firstView";
53
54
  import { EnhancedImageViewer } from "../zoom/EnhancedImageViewer";
54
55
  import { HeroProductImage } from "../HeroProductImage";
55
56
  import { LoadingOverlayPrismCandyInline } from "../../components/LoadingOverlayPrismCandy";
@@ -894,6 +895,9 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
894
895
  className="w-full h-full flex-shrink-0 relative select-none"
895
896
  data-gallery-role={image.galleryRole}
896
897
  data-mockup-id={image.galleryRole ? image.mockupId : undefined}
898
+ // Where this picture's phone window and its PRODUCT are (data-first-view, --first-view-x, --product-x0/x1):
899
+ // a hero that shows only part of the picture looks there, not at the picture's middle (firstView.ts).
900
+ {...slideFirstViewProps(image.isRealMockup ? image : {})}
897
901
  >
898
902
  {!isWithinDecodeWindow ? (
899
903
  <div className="w-full h-full bg-muted" />
@@ -0,0 +1,38 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { slideFirstViewProps } from "../firstView";
3
+
4
+ // Known case (prod KMKMX1 / PR99HD, 2026-11-26): the key tag hangs on a backpack strap at x 0.19-0.26 of the 16:9
5
+ // picture, and the picture's own phone window is x 0.08-0.41; the phone hero drew the picture's middle and showed a blue
6
+ // jacket. The slide now says where its phone window and its product are.
7
+ describe("what a slide says about its picture's first view", () => {
8
+ const PR99HD = { productBox: { shape: "16:9", x: 0.1861, y: 0.437, w: 0.0708, h: 0.1276 }, phoneWindow: { shape: "2:3", x: 0.0787, w: 0.3333 } } as const;
9
+
10
+ it("PR99HD: centred on its phone window, with the product's edges to hold", () => {
11
+ expect(slideFirstViewProps(PR99HD)).toEqual({
12
+ "data-first-view": "phone-window",
13
+ "data-product-box": "0.1861,0.437,0.0708,0.1276",
14
+ "data-phone-window": "0.0787,0.3333",
15
+ style: { "--first-view-x": "0.2454", "--product-x0": "0.1861", "--product-x1": "0.2569" },
16
+ });
17
+ });
18
+
19
+ it("a product box but no phone window: centred on the product", () => {
20
+ expect(slideFirstViewProps({ productBox: PR99HD.productBox })).toEqual({
21
+ "data-first-view": "product",
22
+ "data-product-box": "0.1861,0.437,0.0708,0.1276",
23
+ style: { "--first-view-x": "0.2215", "--product-x0": "0.1861", "--product-x1": "0.2569" },
24
+ });
25
+ });
26
+
27
+ it("a phone window but no product box: centred on the window, nothing to hold (both edges at its centre)", () => {
28
+ expect(slideFirstViewProps({ phoneWindow: PR99HD.phoneWindow })).toEqual({
29
+ "data-first-view": "phone-window",
30
+ "data-phone-window": "0.0787,0.3333",
31
+ style: { "--first-view-x": "0.2454", "--product-x0": "0.2454", "--product-x1": "0.2454" },
32
+ });
33
+ });
34
+
35
+ it("neither (a mockup from before plates): nothing, so the host keeps the picture's middle", () => {
36
+ expect(slideFirstViewProps({})).toEqual({});
37
+ });
38
+ });
@@ -0,0 +1,50 @@
1
+ import type { CSSProperties } from "react";
2
+ import type { CarouselImage } from "./types";
3
+
4
+ /**
5
+ * What a phone carousel slide says about its picture, for a host that shows only PART of the picture.
6
+ *
7
+ * The phone product page draws each 16:9 picture in a tall box (www ScrollHero: 342 x 448 on an iPhone) and so shows a
8
+ * slice of its width until the shopper scrolls. Drawn by the picture's middle, a product at the picture's side is not in
9
+ * that slice at all (prod KMKMX1 / PR99HD, 2026-11-26: a key tag on a backpack strap at x 0.19-0.26; the hero showed a
10
+ * blue jacket). The slide says where to look, and the host's CSS places the picture by it:
11
+ *
12
+ * - `data-first-view`: what the slice is centred on. `"phone-window"`: the mockup's own phone window (its 2:3 frame, the
13
+ * lab's composition for a phone). `"product"`: the product's box (a mockup with a box but no 2:3 window). Absent: the
14
+ * picture's middle (a mockup from before plates: its phone window IS the middle).
15
+ * - `--first-view-x`: that centre along the picture's width, 0..1.
16
+ * - `--product-x0` / `--product-x1`: the product's left and right edges, 0..1: the host slides the slice as little as
17
+ * it must to hold the whole product. A slide with a phone window but no product box carries the window's centre in
18
+ * both (nothing to hold, so the slice stays on the window).
19
+ * - `data-product-box="x,y,w,h"` and `data-phone-window="x,w"`: the catalog's numbers, machine-readable (a test asserts
20
+ * the product's place on screen from them).
21
+ */
22
+ export const SLIDE_FIRST_VIEW_ATTR = "data-first-view";
23
+ export const SLIDE_PRODUCT_BOX_ATTR = "data-product-box";
24
+ export const SLIDE_PHONE_WINDOW_ATTR = "data-phone-window";
25
+ export const SLIDE_FIRST_VIEW_X_VAR = "--first-view-x";
26
+ export const SLIDE_PRODUCT_X0_VAR = "--product-x0";
27
+ export const SLIDE_PRODUCT_X1_VAR = "--product-x1";
28
+
29
+ export interface SlideFirstViewProps {
30
+ [SLIDE_FIRST_VIEW_ATTR]?: "phone-window" | "product";
31
+ [SLIDE_PRODUCT_BOX_ATTR]?: string;
32
+ [SLIDE_PHONE_WINDOW_ATTR]?: string;
33
+ style?: CSSProperties;
34
+ }
35
+
36
+ const r4 = (n: number) => Math.round(n * 10000) / 10000;
37
+
38
+ /** The attributes and CSS variables for one slide; `{}` when the picture has neither a phone window nor a product box. */
39
+ export function slideFirstViewProps(image: Pick<CarouselImage, "productBox" | "phoneWindow">): SlideFirstViewProps {
40
+ const { productBox: box, phoneWindow: phone } = image;
41
+ if (!box && !phone) return {};
42
+ const centre = phone ? r4(phone.x + phone.w / 2) : r4(box!.x + box!.w / 2);
43
+ const x0 = box ? r4(box.x) : centre, x1 = box ? r4(box.x + box.w) : centre;
44
+ return {
45
+ [SLIDE_FIRST_VIEW_ATTR]: phone ? "phone-window" : "product",
46
+ ...(box ? { [SLIDE_PRODUCT_BOX_ATTR]: [box.x, box.y, box.w, box.h].map(r4).join(",") } : {}),
47
+ ...(phone ? { [SLIDE_PHONE_WINDOW_ATTR]: [phone.x, phone.w].map(r4).join(",") } : {}),
48
+ style: { [SLIDE_FIRST_VIEW_X_VAR]: String(centre), [SLIDE_PRODUCT_X0_VAR]: String(x0), [SLIDE_PRODUCT_X1_VAR]: String(x1) } as CSSProperties,
49
+ };
50
+ }
@@ -7,5 +7,6 @@
7
7
  */
8
8
 
9
9
  export * from "./types";
10
+ export * from "./firstView";
10
11
  export * from "./MobileProductCarousel";
11
12
  export * from "./HeroCarousel";
@@ -69,6 +69,21 @@ export interface CarouselImage {
69
69
  * desktop hero puts the product, not the picture's middle, beside the info panel. Absent = a centred picture.
70
70
  */
71
71
  frame?: { shape: "16:9"; productX: number; productY: number };
72
+
73
+ /**
74
+ * The product's box in this picture (the catalog's `mockups[].productBox`: fractions of the mockup's default 16:9
75
+ * picture). The phone carousel stamps it on the slide (firstView.ts), so a hero that shows only part of the picture
76
+ * (www ScrollHero before a scroll) keeps the PRODUCT in view. Absent = a mockup whose record has no product box.
77
+ */
78
+ productBox?: { shape: "16:9"; x: number; y: number; w: number; h: number };
79
+
80
+ /**
81
+ * The mockup's own phone window (the catalog's `mockups[].phoneWindow`: its 2:3 frame's left edge and width along
82
+ * the default 16:9 picture). The phone carousel stamps its centre on the slide (firstView.ts): a hero that shows
83
+ * only part of the picture centres on it, the lab's composition for a phone, not on the picture's middle. Absent =
84
+ * the phone window is the picture's middle (every mockup from before plates).
85
+ */
86
+ phoneWindow?: { shape: "2:3"; x: number; w: number };
72
87
  }
73
88
 
74
89
  /**