@snowcone-app/ui 0.11.15 → 0.11.17

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.17",
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.2"
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
  /**
@@ -998,7 +998,7 @@ export function RealtimeProvider({
998
998
  const base = lastConfigBaseRef.current;
999
999
  if (!base) return;
1000
1000
  const ids = (base.mockupIds as string[] | undefined) ?? [];
1001
- // #6369 stopgap (croppedDeliveryLimit.ts): off until the render-side fix.
1001
+ // #6369 (croppedDeliveryLimit.ts): more than 5 mockups stay on full frames.
1002
1002
  if (!croppedDeliveryAllowed(ids.length)) {
1003
1003
  console.log(`[RTP] Cropped delivery OFF: ${ids.length} mockups > ${CROPPED_DELIVERY_MAX_MOCKUPS} (#6369 stopgap, full-frame frames)`);
1004
1004
  return;
@@ -48,10 +48,6 @@ const h = vi.hoisted(() => {
48
48
  };
49
49
  });
50
50
 
51
- // These tests pin the cropped path itself. The #6369 stopgap turns cropped delivery off (croppedDeliveryLimit.ts, tested
52
- // in RealtimeProvider.croppedLimit.test.tsx); lift it here so the path stays covered for the day the stopgap comes out.
53
- vi.mock("../croppedDeliveryLimit", () => ({ CROPPED_DELIVERY_MAX_MOCKUPS: Infinity, croppedDeliveryAllowed: () => true }));
54
-
55
51
  vi.mock("@snowcone-app/sdk/react", () => ({
56
52
  useRealtimeMockup: (opts: unknown) => {
57
53
  h.opts = opts as typeof h.opts;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * #6369 stopgap (croppedDeliveryLimit.ts): cropped delivery is OFF for every session until the render-side fix has rolled
3
- * (why: issue #6369; this package ships its source). Every session stays on full-frame delivery.
2
+ * #6369 stopgap (croppedDeliveryLimit.ts): a realtime session with more than 5 mockups stays on full-frame delivery;
3
+ * 5 or fewer turn on cropped delivery once every background is seeded, as before.
4
4
  */
5
5
  import { describe, expect, it, beforeEach, vi } from "vitest";
6
6
  import React from "react";
@@ -137,23 +137,36 @@ async function seedAll(n: number) {
137
137
  void capturedCtx;
138
138
  }
139
139
 
140
- describe("cropped delivery is off (#6369 stopgap)", () => {
141
- it("no session may use it, in both clients (the limit is 0, the same as the SDK's useMockupStage)", async () => {
142
- expect(CROPPED_DELIVERY_MAX_MOCKUPS).toBe(0);
140
+ // #6369: more than 5 mockups -> full-frame delivery (why: the issue).
141
+ describe("cropped delivery limit (#6369 stopgap)", () => {
142
+ it("the limit is the measured boundary: 5, the same as the SDK's useMockupStage", async () => {
143
+ expect(CROPPED_DELIVERY_MAX_MOCKUPS).toBe(5);
143
144
  const sdk = await vi.importActual<typeof import("@snowcone-app/sdk")>("@snowcone-app/sdk");
144
145
  expect(sdk.CROPPED_DELIVERY_MAX_MOCKUPS).toBe(CROPPED_DELIVERY_MAX_MOCKUPS);
145
- for (const n of [1, 2, 3, 5, 6, 33]) {
146
- expect(croppedDeliveryAllowed(n)).toBe(false);
147
- expect(sdk.croppedDeliveryAllowed(n)).toBe(false);
148
- }
146
+ expect(croppedDeliveryAllowed(5)).toBe(true);
147
+ expect(croppedDeliveryAllowed(6)).toBe(false);
149
148
  });
150
149
 
151
- // 3 at the default width 1400 is the lead's case: cropped before this change.
152
- it.each([1, 2, 3, 5, 6, 33])("%i mockup(s) at the default width: full-frame delivery, overlayCrop is never sent", async (n) => {
153
- await seedAll(n);
150
+ it("2 mockups (a phone session): untouched, cropped delivery turns on", async () => {
151
+ await seedAll(2);
152
+ await waitFor(() => expect(sentConfigs().some((c) => c.overlayCrop === "auto")).toBe(true));
153
+ });
154
+
155
+ it("5 mockups: cropped delivery turns on once every mockup is seeded", async () => {
156
+ await seedAll(5);
157
+ await waitFor(() => expect(sentConfigs().some((c) => c.overlayCrop === "auto")).toBe(true));
158
+ expect(sentConfigs()[0].mockupIds).toHaveLength(5);
159
+ });
160
+
161
+ it("6 mockups: full-frame delivery, overlayCrop is never sent", async () => {
162
+ await seedAll(6);
154
163
  expect(sentConfigs().length).toBeGreaterThan(0);
155
- expect(sentConfigs()[0]).toMatchObject({ width: 1400 });
156
- expect(sentConfigs()[0].mockupIds).toHaveLength(n);
164
+ expect(sentConfigs()[0].mockupIds).toHaveLength(6);
165
+ expect(sentConfigs().some((c) => c.overlayCrop)).toBe(false);
166
+ });
167
+
168
+ it("33 mockups (a desktop gallery): full-frame delivery", async () => {
169
+ await seedAll(33);
157
170
  expect(sentConfigs().some((c) => c.overlayCrop)).toBe(false);
158
171
  });
159
172
  });
@@ -24,10 +24,6 @@ const h = vi.hoisted(() => ({
24
24
  },
25
25
  }));
26
26
 
27
- // These tests pin the cropped path itself. The #6369 stopgap turns cropped delivery off (croppedDeliveryLimit.ts, tested
28
- // in RealtimeProvider.croppedLimit.test.tsx); lift it here so the path stays covered for the day the stopgap comes out.
29
- vi.mock("../croppedDeliveryLimit", () => ({ CROPPED_DELIVERY_MAX_MOCKUPS: Infinity, croppedDeliveryAllowed: () => true }));
30
-
31
27
  vi.mock("@snowcone-app/sdk/react", () => ({
32
28
  useRealtimeMockup: () => ({
33
29
  isConnected: true, isConfigured: true, renderError: null, mockupResults: h.state.results,
@@ -19,10 +19,6 @@ const h = vi.hoisted(() => ({
19
19
  },
20
20
  }));
21
21
 
22
- // These tests pin the cropped path itself. The #6369 stopgap turns cropped delivery off (croppedDeliveryLimit.ts, tested
23
- // in RealtimeProvider.croppedLimit.test.tsx); lift it here so the path stays covered for the day the stopgap comes out.
24
- vi.mock("../croppedDeliveryLimit", () => ({ CROPPED_DELIVERY_MAX_MOCKUPS: Infinity, croppedDeliveryAllowed: () => true }));
25
-
26
22
  vi.mock("@snowcone-app/sdk/react", () => ({
27
23
  useRealtimeMockup: () => ({
28
24
  isConnected: true, isConfigured: true, renderError: null, mockupResults: h.state.results,
@@ -1,17 +1,16 @@
1
1
  /**
2
- * STOPGAP for #6369 (2026-11-25), removable: cropped delivery (`overlayCrop: "auto"`) is OFF for every session; all frames
3
- * are full frames. `croppedDeliveryAllowed` is the one switch for `RealtimeProvider`; the SDK's `useMockupStage`
4
- * holds the same rule (`@snowcone-app/sdk`) and a test pins the two equal.
2
+ * Cropped-delivery size limit (#6369), removable: a realtime session that holds MORE than this many mockups asks for
3
+ * FULL-FRAME delivery and never turns on cropped delivery (`overlayCrop: "auto"`); 5 or fewer use cropped delivery.
5
4
  *
6
- * Why: some cropped frames cannot be rendered safely yet, at ordinary session widths, so neither a picture count nor a
7
- * width floor covers it (details, measurements and the earlier limit of 5: issue #6369, not here, this ships to npm).
5
+ * Why: issue #6369 (details and measurements live there, not here: this package ships its source).
8
6
  *
9
- * REVERT with the render-side fix: set the limit back (or delete this module and its call sites) once it is rolled on
10
- * every box and the editor canary passes with cropped delivery at 33 mockups.
7
+ * The SDK's useMockupStage holds the same rule (`@snowcone-app/sdk` CROPPED_DELIVERY_MAX_MOCKUPS; a test pins the two
8
+ * equal). Remove (delete this module and its three call sites in RealtimeProvider, and the SDK's twin) once the editor
9
+ * canary passes with cropped delivery at 33 mockups.
11
10
  */
12
- export const CROPPED_DELIVERY_MAX_MOCKUPS = 0;
11
+ export const CROPPED_DELIVERY_MAX_MOCKUPS = 5;
13
12
 
14
- /** Whether a session holding `mockupCount` mockups may use cropped delivery (#6369 stopgap: none may). */
13
+ /** Whether a session holding `mockupCount` mockups may use cropped delivery (#6369). */
15
14
  export function croppedDeliveryAllowed(mockupCount: number): boolean {
16
15
  return mockupCount <= CROPPED_DELIVERY_MAX_MOCKUPS;
17
16
  }