@snowcone-app/ui 0.11.17 → 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/CHANGELOG.md +6 -0
- package/dist/index.cjs +100 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -59
- package/dist/index.d.ts +124 -59
- package/dist/index.js +95 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/composed/carousels/MobileProductCarousel.tsx +3 -1
- package/src/composed/carousels/firstView.ts +81 -0
- package/src/composed/zoom/EnhancedImageViewer.tsx +68 -1
- package/src/composed/zoom/__tests__/EnhancedImageViewer.firstView.test.tsx +126 -0
- package/src/composed/zoom/types.ts +9 -0
package/package.json
CHANGED
|
@@ -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:
|
|
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
|
}
|