@snowcone-app/ui 0.11.16 → 0.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/ui",
3
- "version": "0.11.16",
3
+ "version": "0.12.0",
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.1"
106
+ "@snowcone-app/sdk": "0.33.2"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@chromatic-com/storybook": "^4.1.2",
@@ -50,7 +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
+ import { slideFirstViewFields, slideFirstViewProps } from "./firstView";
54
54
  import { EnhancedImageViewer } from "../zoom/EnhancedImageViewer";
55
55
  import { HeroProductImage } from "../HeroProductImage";
56
56
  import { LoadingOverlayPrismCandyInline } from "../../components/LoadingOverlayPrismCandy";
@@ -1036,6 +1036,8 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
1036
1036
  naturalWidth: img.naturalWidth,
1037
1037
  naturalHeight: img.naturalHeight,
1038
1038
  ...(zoomFit(img.galleryRole) === "whole" ? { fit: "whole" as const } : {}),
1039
+ // the viewer opens on the product by the hero's first-view rule (EnhancedImageViewer viewerFirstView)
1040
+ ...slideFirstViewFields(img),
1039
1041
  } : null;
1040
1042
  })
1041
1043
  .filter((img): img is NonNullable<typeof img> => img !== null);
@@ -35,6 +35,87 @@ export interface SlideFirstViewProps {
35
35
 
36
36
  const r4 = (n: number) => Math.round(n * 10000) / 10000;
37
37
 
38
+ /** The phone hero's default picture is 16:9 (a plate's `frames['16:9']` window; rendercenter shared/shapes.ts). */
39
+ export const FIRST_VIEW_PICTURE_ASPECT = 16 / 9;
40
+
41
+ /** The share of the view's width kept clear on each side of the product (the frame gate's product-on-a-surface margin). */
42
+ export const FIRST_VIEW_MARGIN = 0.03;
43
+
44
+ /** The product's box in a mockup's default 16:9 picture, as fractions of that picture (`mockups[].productBox`). */
45
+ export type FirstViewProductBox = NonNullable<CarouselImage["productBox"]>;
46
+ /** The mockup's own phone window (its 2:3 frame) along the default picture's width (`mockups[].phoneWindow`). */
47
+ export type FirstViewPhoneWindow = NonNullable<CarouselImage["phoneWindow"]>;
48
+
49
+ /** What a first view is centred on, and the product it then holds. */
50
+ export type FirstViewAnchor =
51
+ /** The mockup's own phone window (a plate). `product` null: its record has no product box, so nothing is held or judged. */
52
+ | { by: "phone-window"; window: FirstViewPhoneWindow; product: FirstViewProductBox | null }
53
+ /** A product box but no phone window. */
54
+ | { by: "product"; product: FirstViewProductBox }
55
+ /** Neither (a mockup from before plates): its phone window is the centred one its 2:3 gate judged. */
56
+ | { by: "picture-middle"; why: "no-phone-window-no-product-box" };
57
+
58
+ export interface FirstView {
59
+ /** The slice of the picture's width the box shows, as fractions of the picture (0 = its left edge, 1 = its right). */
60
+ x0: number;
61
+ x1: number;
62
+ /** The picture's drawn width and its left edge relative to the box's left edge, px (left <= 0). */
63
+ pictureWidth: number;
64
+ left: number;
65
+ /** `held`: the whole product is in view. `cut`: part of it is outside. `unjudged`: no product box to judge by. */
66
+ product: "held" | "cut" | "unjudged";
67
+ /** The share of the product's width that is in view (1 = all of it); null when unjudged. */
68
+ inView: number | null;
69
+ /** The part of the product in view as a share of the view's width; null when unjudged. */
70
+ share: number | null;
71
+ }
72
+
73
+ /** The anchor of a slide's (already parsed) fields: its phone window, else its product, else the picture's middle. */
74
+ export function firstViewAnchorOfSlide(image: Pick<CarouselImage, "productBox" | "phoneWindow">): FirstViewAnchor {
75
+ const { productBox: product, phoneWindow: window } = image;
76
+ if (window) return { by: "phone-window", window, product: product ?? null };
77
+ if (product) return { by: "product", product };
78
+ return { by: "picture-middle", why: "no-phone-window-no-product-box" };
79
+ }
80
+
81
+ /**
82
+ * THE first-view rule (one copy: the www phone hero's CSS, heroFirstView.ts, and the tap-to-enlarge viewer,
83
+ * EnhancedImageViewer, both draw by it). What a box of `width` x `height` CSS px shows of a picture drawn
84
+ * `object-fit: cover`: the picture is the box's height (or its width, when the box is wider than the picture), centred
85
+ * on the anchor, slid as little as it must to hold the whole product with FIRST_VIEW_MARGIN of the view clear on each
86
+ * side (a product too wide for that is centred in the view, reported `cut`), and never past its own edges.
87
+ */
88
+ export function firstView(box: { width: number; height: number }, anchor: FirstViewAnchor, pictureAspect: number = FIRST_VIEW_PICTURE_ASPECT): FirstView {
89
+ const { width: W, height: H } = box;
90
+ const pictureWidth = Math.max(W, H * pictureAspect);
91
+ const product = anchor.by === "picture-middle" ? null : anchor.product;
92
+ const wanted = anchor.by === "phone-window" ? anchor.window.x + anchor.window.w / 2 : anchor.by === "product" ? anchor.product.x + anchor.product.w / 2 : 0.5;
93
+ // the view's centre, px along the picture: the wanted one, held between the two centres that keep the product (with
94
+ // its margin) in view; a product too wide for that leaves no such centre, and its own middle is used
95
+ let centrePx = wanted * pictureWidth;
96
+ if (product) {
97
+ const mid = (product.x + product.w / 2) * pictureWidth;
98
+ const lo = (product.x + product.w) * pictureWidth + FIRST_VIEW_MARGIN * W - W / 2;
99
+ const hi = product.x * pictureWidth - FIRST_VIEW_MARGIN * W + W / 2;
100
+ centrePx = Math.max(Math.min(lo, mid), Math.min(centrePx, Math.max(hi, mid)));
101
+ }
102
+ const left = Math.max(Math.min(0, W - pictureWidth), Math.min(W / 2 - centrePx, 0));
103
+ const x0 = -left / pictureWidth, x1 = (W - left) / pictureWidth;
104
+ if (!product) return { x0, x1, pictureWidth, left, product: "unjudged", inView: null, share: null };
105
+ const seen = Math.max(0, Math.min(product.x + product.w, x1) - Math.max(product.x, x0));
106
+ const inView = seen / product.w;
107
+ return { x0, x1, pictureWidth, left, product: inView > 1 - 1e-6 ? "held" : "cut", inView, share: seen / (x1 - x0) };
108
+ }
109
+
110
+ /**
111
+ * The fields a phone carousel slide hands the tap-to-enlarge viewer: a real mockup's product box and phone window (the
112
+ * same pictures the slide stamps, `image.isRealMockup ? image : {}`), nothing for any other picture.
113
+ */
114
+ export function slideFirstViewFields(image: Pick<CarouselImage, "isRealMockup" | "productBox" | "phoneWindow">): Pick<CarouselImage, "productBox" | "phoneWindow"> {
115
+ if (!image.isRealMockup) return {};
116
+ return { ...(image.productBox ? { productBox: image.productBox } : {}), ...(image.phoneWindow ? { phoneWindow: image.phoneWindow } : {}) };
117
+ }
118
+
38
119
  /** The attributes and CSS variables for one slide; `{}` when the picture has neither a phone window nor a product box. */
39
120
  export function slideFirstViewProps(image: Pick<CarouselImage, "productBox" | "phoneWindow">): SlideFirstViewProps {
40
121
  const { productBox: box, phoneWindow: phone } = image;
@@ -20,6 +20,12 @@ import type {
20
20
  } from "react-zoom-pan-pinch";
21
21
  import { X } from "lucide-react";
22
22
  import type { ZoomImage } from "./types";
23
+ import {
24
+ FIRST_VIEW_PICTURE_ASPECT,
25
+ firstView,
26
+ firstViewAnchorOfSlide,
27
+ type FirstView,
28
+ } from "../carousels/firstView";
23
29
 
24
30
  // Cast to fix React 19 type compatibility with react-zoom-pan-pinch
25
31
  const TransformWrapper = OriginalTransformWrapper as ComponentType<
@@ -41,6 +47,37 @@ interface EnhancedImageViewerProps {
41
47
  currentIndex?: number; // Add explicit current index prop
42
48
  }
43
49
 
50
+ /**
51
+ * Where the viewer opens a picture it draws `object-fit: cover` in the whole screen: by the phone hero's first-view rule
52
+ * (carousels/firstView.ts `firstView`), so a product off the picture's middle is on screen (founder 2026-11-26: "when I
53
+ * tap to view it larger we lose the proper crop and can't see the item in frame anymore"). Stamped on the <img> as
54
+ * `data-first-view` (`phone-window` | `product` | `picture-middle` | `whole`), `data-first-view-why` (why the middle),
55
+ * `data-first-view-product` (`held` | `cut` | `unjudged`) and `data-first-view-slice="x0,x1"` (the picture's width on screen).
56
+ */
57
+ type ViewerFirstView =
58
+ /** A picture opened whole (contain): nothing is cut, no rule. */
59
+ | { by: "whole" }
60
+ /** Drawn by the picture's middle, as before: it carries neither field, or it is not the 16:9 picture they measure. */
61
+ | { by: "picture-middle"; why: "no-phone-window-no-product-box" | "picture-not-16:9" }
62
+ | { by: "phone-window" | "product"; view: FirstView };
63
+
64
+ function viewerFirstView(
65
+ image: ZoomImage | undefined,
66
+ screen: { width: number; height: number },
67
+ pictureAspect: number | undefined,
68
+ ): ViewerFirstView {
69
+ if (image?.fit === "whole") return { by: "whole" };
70
+ const anchor = firstViewAnchorOfSlide(image ?? {});
71
+ if (anchor.by === "picture-middle") return anchor;
72
+ // the fields are fractions of the mockup's default 16:9 picture; on any other picture they would point elsewhere
73
+ if (pictureAspect !== undefined && Math.abs(pictureAspect / FIRST_VIEW_PICTURE_ASPECT - 1) > 0.01) {
74
+ return { by: "picture-middle", why: "picture-not-16:9" };
75
+ }
76
+ return { by: anchor.by, view: firstView(screen, anchor) };
77
+ }
78
+
79
+ const r4 = (n: number) => Math.round(n * 10000) / 10000;
80
+
44
81
  // Enhanced Image Viewer Component with react-zoom-pan-pinch (On.com style)
45
82
  export const EnhancedImageViewer = ({
46
83
  imageUrl,
@@ -56,6 +93,8 @@ export const EnhancedImageViewer = ({
56
93
  const [cropDimensions, setCropDimensions] = useState({ width: 0, height: 0 });
57
94
  const [currentZoomScale, setCurrentZoomScale] = useState(1);
58
95
  const imgRef = useRef<HTMLImageElement>(null);
96
+ // The drawn picture's own shape, once it has loaded (the first-view fields only apply to the 16:9 picture).
97
+ const [loadedAspect, setLoadedAspect] = useState<{ src: string; aspect: number } | null>(null);
59
98
 
60
99
  // Swipe detection refs
61
100
  const touchStartRef = useRef<{ x: number; y: number; time: number } | null>(
@@ -83,6 +122,10 @@ export const EnhancedImageViewer = ({
83
122
 
84
123
  const handleImageLoad = useCallback(() => {
85
124
  calculateScale();
125
+ const img = imgRef.current;
126
+ if (img && img.naturalWidth > 0 && img.naturalHeight > 0) {
127
+ setLoadedAspect({ src: img.currentSrc || img.src, aspect: img.naturalWidth / img.naturalHeight });
128
+ }
86
129
  }, [calculateScale]);
87
130
 
88
131
  // Mark as client-side and calculate initial scale
@@ -216,6 +259,24 @@ export const EnhancedImageViewer = ({
216
259
  [handleSwipeNavigation]
217
260
  );
218
261
 
262
+ // The picture on screen and where it opens (the first-view rule; see viewerFirstView).
263
+ const shownIndex = propCurrentIndex ?? images.findIndex((img) => img.src === imageUrl);
264
+ const shown = images[shownIndex];
265
+ const shownAspect =
266
+ loadedAspect && (loadedAspect.src === imageUrl || loadedAspect.src.endsWith(imageUrl))
267
+ ? loadedAspect.aspect
268
+ : shown?.naturalWidth && shown?.naturalHeight
269
+ ? shown.naturalWidth / shown.naturalHeight
270
+ : undefined;
271
+ const opening = viewerFirstView(
272
+ shown,
273
+ {
274
+ width: cropDimensions.width || (typeof window === "undefined" ? 0 : window.innerWidth),
275
+ height: cropDimensions.height || (typeof window === "undefined" ? 0 : window.innerHeight),
276
+ },
277
+ shownAspect,
278
+ );
279
+
219
280
  if (!isMounted || !isClient) {
220
281
  return createPortal(
221
282
  <div
@@ -340,11 +401,17 @@ export const EnhancedImageViewer = ({
340
401
  crossOrigin="anonymous"
341
402
  key={`${imageUrl}-${propCurrentIndex}`}
342
403
  onLoad={handleImageLoad}
404
+ data-first-view={opening.by}
405
+ data-first-view-why={opening.by === "picture-middle" ? opening.why : undefined}
406
+ data-first-view-product={"view" in opening ? opening.view.product : undefined}
407
+ data-first-view-slice={"view" in opening ? `${r4(opening.view.x0)},${r4(opening.view.x1)}` : undefined}
343
408
  style={{
344
409
  width: "100%",
345
410
  height: "100%",
346
411
  // Crop 16:9 to fill the screen (a hero), or the whole picture for a size picture (a diagram).
347
- objectFit: images[propCurrentIndex ?? -1]?.fit === "whole" ? "contain" : "cover",
412
+ objectFit: opening.by === "whole" ? "contain" : "cover",
413
+ // Opened on the product by the hero's first-view rule; a picture without the fields keeps the middle.
414
+ ...("view" in opening ? { objectPosition: `${Math.round(opening.view.left * 100) / 100}px 50%` } : {}),
348
415
  }}
349
416
  />
350
417
  </div>
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The tap-to-enlarge viewer opens on the PRODUCT, by the same rule as the phone hero's first view (carousels/firstView.ts).
3
+ *
4
+ * Founder, 2026-11-26, on the phone case page: "I think you largely fixed the crop positioning on Snowcone but when I
5
+ * tap to view it larger we lose the proper crop and can't see the item in frame anymore". The hero's first view now
6
+ * holds the product (#6499); the viewer a tap opens drew the 16:9 picture `object-fit: cover` in the whole 390 x 844
7
+ * screen at the picture's MIDDLE (x 0.37-0.63 of its width), so a product left of centre (the beach picture: the case in
8
+ * her hand, left of the picture's middle) or at the side (PR99HD: a key tag at x 0.19-0.26) was off the screen.
9
+ *
10
+ * The tests read the drawn place off the <img> (its object-position) and work out what part of the picture that puts on
11
+ * screen, so they assert what the shopper sees, not the helper's output.
12
+ */
13
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
14
+ import React from "react";
15
+ import { cleanup, render } from "@testing-library/react";
16
+ import { EnhancedImageViewer } from "../EnhancedImageViewer";
17
+ import type { ZoomImage } from "../types";
18
+ import { slideFirstViewFields } from "../../carousels/firstView";
19
+
20
+ // jsdom has no ResizeObserver; react-zoom-pan-pinch observes its wrapper
21
+ globalThis.ResizeObserver ??= class { observe() {} unobserve() {} disconnect() {} } as unknown as typeof ResizeObserver;
22
+
23
+ const PHONE = { width: 390, height: 844 };
24
+ const IMG = "https://img.snowcone.app/m.webp";
25
+
26
+ // prod KMKMX1 / PR99HD (2026-11-26): the key tag at x 0.19-0.26, its phone window x 0.08-0.41
27
+ 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;
28
+ // the beach picture's shape (the case in her hand, left of the picture's middle), a real phone case of the same shape:
29
+ // prod BC43BE / R4EW69 (2026-11-26), the case held up at x 0.12-0.25, its phone window x 0-0.375
30
+ const BEACH = { productBox: { shape: "16:9", x: 0.1193, y: 0.1133, w: 0.131, h: 0.4463 }, phoneWindow: { shape: "2:3", x: 0, w: 0.375 } } as const;
31
+ // a control, product and phone window both centred (what the viewer showed already): prod VAJJMF, a key tag on a plain ground
32
+ const CENTRED = { productBox: { shape: "16:9", x: 0.3808, y: 0.3741, w: 0.2384, h: 0.4272 }, phoneWindow: { shape: "2:3", x: 0.3128, w: 0.3747 } } as const;
33
+ // a product wider than the screen's slice of the picture (0.26 of it at 390 x 844), it cannot be held whole: prod Q3YNJK,
34
+ // a mouse pad at x 0.23-0.78
35
+ const WIDE = { productBox: { shape: "16:9", x: 0.225, y: 0.2472, w: 0.5504, h: 0.4972 }, phoneWindow: { shape: "2:3", x: 0.1711, w: 0.6578 } } as const;
36
+
37
+ function open(image: Omit<ZoomImage, "src">, index = 0) {
38
+ const images: ZoomImage[] = [{ src: `${IMG}?0` }, { src: `${IMG}?1` }];
39
+ images[index] = { src: `${IMG}?${index}`, ...image };
40
+ render(<EnhancedImageViewer imageUrl={images[index].src} alt="" onClose={() => {}} images={images} currentIndex={index} />);
41
+ return document.querySelector<HTMLImageElement>('[role="dialog"] img')!;
42
+ }
43
+
44
+ /** The slice of the picture's width on screen, from the drawn object-position (cover, a 16:9 picture in the screen). */
45
+ function sliceOnScreen(img: HTMLImageElement): [number, number] {
46
+ const pos = img.style.objectPosition;
47
+ const pictureWidth = Math.max(PHONE.width, PHONE.height * (16 / 9));
48
+ const m = /^(-?[\d.]+)px 50%$/.exec(pos);
49
+ // "center" / "" = the picture's middle
50
+ const left = m ? Number(m[1]) : (PHONE.width - pictureWidth) / 2;
51
+ return [-left / pictureWidth, (PHONE.width - left) / pictureWidth];
52
+ }
53
+
54
+ describe("the tap-to-enlarge viewer's first view", () => {
55
+ let saved: { w: number; h: number };
56
+ beforeEach(() => {
57
+ saved = { w: window.innerWidth, h: window.innerHeight };
58
+ Object.defineProperty(window, "innerWidth", { configurable: true, value: PHONE.width });
59
+ Object.defineProperty(window, "innerHeight", { configurable: true, value: PHONE.height });
60
+ });
61
+ afterEach(() => {
62
+ cleanup();
63
+ Object.defineProperty(window, "innerWidth", { configurable: true, value: saved.w });
64
+ Object.defineProperty(window, "innerHeight", { configurable: true, value: saved.h });
65
+ });
66
+
67
+ it("PR99HD: opens with the whole key tag on screen, and says so", () => {
68
+ const img = open(PR99HD);
69
+ const [x0, x1] = sliceOnScreen(img);
70
+ expect(x0).toBeLessThanOrEqual(PR99HD.productBox.x);
71
+ expect(x1).toBeGreaterThanOrEqual(PR99HD.productBox.x + PR99HD.productBox.w);
72
+ expect(img.getAttribute("data-first-view")).toBe("phone-window");
73
+ expect(img.getAttribute("data-first-view-product")).toBe("held");
74
+ });
75
+
76
+ it("the beach picture's shape (product left of the middle): the whole product on screen", () => {
77
+ const img = open(BEACH, 1);
78
+ const [x0, x1] = sliceOnScreen(img);
79
+ expect(x0).toBeLessThanOrEqual(BEACH.productBox.x);
80
+ expect(x1).toBeGreaterThanOrEqual(BEACH.productBox.x + BEACH.productBox.w);
81
+ expect(img.getAttribute("data-first-view-product")).toBe("held");
82
+ });
83
+
84
+ it("a centred product: the same view as before (the picture's middle)", () => {
85
+ const [x0, x1] = sliceOnScreen(open(CENTRED));
86
+ const middle = sliceOnScreen(open({}));
87
+ expect(x0).toBeCloseTo(middle[0], 3);
88
+ expect(x1).toBeCloseTo(middle[1], 3);
89
+ });
90
+
91
+ it("a picture without the fields: today's view, drawn by the picture's middle, and says why", () => {
92
+ const img = open({});
93
+ expect(img.style.objectPosition).toBe("");
94
+ expect(img.getAttribute("data-first-view")).toBe("picture-middle");
95
+ });
96
+
97
+ it("a product wider than the screen: centred on the product, reported cut", () => {
98
+ const img = open(WIDE);
99
+ const [x0, x1] = sliceOnScreen(img);
100
+ const mid = WIDE.productBox.x + WIDE.productBox.w / 2;
101
+ expect((x0 + x1) / 2).toBeCloseTo(mid, 3);
102
+ expect(img.getAttribute("data-first-view-product")).toBe("cut");
103
+ });
104
+
105
+ it("fields on a picture that is not the 16:9 one they measure: the middle, as before, and says why", () => {
106
+ const img = open({ ...PR99HD, naturalWidth: 1000, naturalHeight: 1500 });
107
+ expect(img.style.objectPosition).toBe("");
108
+ expect(img.getAttribute("data-first-view")).toBe("picture-middle");
109
+ expect(img.getAttribute("data-first-view-why")).toBe("picture-not-16:9");
110
+ });
111
+
112
+ it("a size picture opened whole (contain): untouched by the rule", () => {
113
+ const img = open({ ...PR99HD, fit: "whole" });
114
+ expect(img.style.objectFit).toBe("contain");
115
+ expect(img.style.objectPosition).toBe("");
116
+ expect(img.getAttribute("data-first-view")).toBe("whole");
117
+ });
118
+ });
119
+
120
+ describe("what the phone carousel hands the viewer", () => {
121
+ it("a real mockup carries its product box and phone window; anything else carries nothing (as the slide stamp)", () => {
122
+ expect(slideFirstViewFields({ isRealMockup: true, ...PR99HD })).toEqual(PR99HD);
123
+ expect(slideFirstViewFields({ isRealMockup: true })).toEqual({});
124
+ expect(slideFirstViewFields({ isRealMockup: false, ...PR99HD })).toEqual({});
125
+ });
126
+ });
@@ -1,3 +1,5 @@
1
+ import type { CarouselImage } from "../carousels/types";
2
+
1
3
  /**
2
4
  * Image interface for zoom components
3
5
  */
@@ -11,4 +13,11 @@ export interface ZoomImage {
11
13
  mockupId?: string;
12
14
  /** `whole`: open the picture whole (contain), not cropped to the screen: the gallery's size picture (a diagram). */
13
15
  fit?: "cover" | "whole";
16
+ /**
17
+ * Where the product and the mockup's phone window are in this (16:9) picture, as the phone carousel's slide carries
18
+ * them (carousels/firstView.ts). The viewer opens on them by the hero's first-view rule, so the product is on screen.
19
+ * Absent = the picture's middle (as before).
20
+ */
21
+ productBox?: CarouselImage["productBox"];
22
+ phoneWindow?: CarouselImage["phoneWindow"];
14
23
  }
@@ -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
  }