@snowcone-app/ui 0.10.20 → 0.10.22
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 +16 -0
- package/dist/index.cjs +13 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +13 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/composed/HeroProductImage.tsx +32 -21
- package/src/composed/__tests__/HeroProductImage.strip.test.tsx +14 -6
- package/src/composed/carousels/types.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowcone-app/ui",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.22",
|
|
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.
|
|
106
|
+
"@snowcone-app/sdk": "0.31.6"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
109
|
"@chromatic-com/storybook": "^4.1.2",
|
|
@@ -85,11 +85,8 @@ function buildHeroMockupUrl(args: {
|
|
|
85
85
|
placements: PlacementLike[];
|
|
86
86
|
mockupId: string;
|
|
87
87
|
variantId: string;
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
* width).
|
|
91
|
-
*/
|
|
92
|
-
size: { width: number; aspect?: "8:3" } | { stripView: MockupView };
|
|
88
|
+
/** A render width (16:9), or a crop of the 8:3 strip (`view=`: at its own px, or downscaled to `width`). */
|
|
89
|
+
size: { width: number } | { stripView: MockupView; width?: number };
|
|
93
90
|
/** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */
|
|
94
91
|
bg?: string;
|
|
95
92
|
}): string | null {
|
|
@@ -105,22 +102,27 @@ function buildHeroMockupUrl(args: {
|
|
|
105
102
|
shop: snow.shop,
|
|
106
103
|
design: publicDesign,
|
|
107
104
|
...("stripView" in args.size
|
|
108
|
-
? { aspect: "8:3" as const, stripView: args.size.stripView }
|
|
109
|
-
: { width: args.size.width
|
|
105
|
+
? { aspect: "8:3" as const, stripView: args.size.stripView, ...(args.size.width !== undefined ? { width: args.size.width } : {}) }
|
|
106
|
+
: { width: args.size.width }),
|
|
110
107
|
view: args.mockupId,
|
|
111
108
|
variant: args.variantId,
|
|
112
109
|
...(args.bg ? { bg: args.bg } : {}),
|
|
113
110
|
...(snow.resolver ? { base: snow.resolver } : {}),
|
|
114
111
|
});
|
|
115
112
|
}
|
|
116
|
-
/** A crop of the strip needs no width: it
|
|
117
|
-
function isCrop(stripView: MockupView |
|
|
118
|
-
return stripView !== undefined
|
|
113
|
+
/** A crop of the strip needs no measured width: it comes at its own px (or the width the page asks). */
|
|
114
|
+
function isCrop(stripView: MockupView | undefined): stripView is MockupView {
|
|
115
|
+
return stripView !== undefined;
|
|
119
116
|
}
|
|
120
117
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
/** The size of the picture asked for: a crop (at its own px, or downscaled to `cropWidth`), or 16:9 at a width. */
|
|
119
|
+
function heroSize(
|
|
120
|
+
stripView: MockupView | undefined,
|
|
121
|
+
cropWidth: number | undefined,
|
|
122
|
+
width: number
|
|
123
|
+
): { width: number } | { stripView: MockupView; width?: number } {
|
|
124
|
+
if (isCrop(stripView)) return cropWidth !== undefined ? { stripView, width: cropWidth } : { stripView };
|
|
125
|
+
return { width };
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
import { useImageTransition } from "../hooks/useImageTransition";
|
|
@@ -200,12 +202,15 @@ export interface HeroProductImageProps {
|
|
|
200
202
|
fit?: "cover" | "whole";
|
|
201
203
|
|
|
202
204
|
/**
|
|
203
|
-
* Ask for a crop of the mockup's 8:3 strip
|
|
204
|
-
* `
|
|
205
|
-
*
|
|
206
|
-
*
|
|
205
|
+
* Ask for a crop of the mockup's 8:3 strip instead of a width-sized 16:9 picture: the desktop hero of a mockup whose
|
|
206
|
+
* catalog entry carries `strip` (www heroStrip.ts).
|
|
207
|
+
* - `"<r>@<f>"`: `aspect=8:3&view=<r>@<f>`, at the crop's own px;
|
|
208
|
+
* - `{ view, width }`: the same crop downscaled to `width` (the page's CSS width x devicePixelRatio when that is under
|
|
209
|
+
* the crop's px; the box never enlarges, rendercenter rc#899);
|
|
210
|
+
* The whole strip is a view too: `MOCKUP_VIEW_WHOLE_STRIP` (`2.7@0.25`, a window wider than 2.6).
|
|
211
|
+
* Stamped as data-strip-view (and data-strip-width).
|
|
207
212
|
*/
|
|
208
|
-
stripView?: MockupView |
|
|
213
|
+
stripView?: MockupView | { view: MockupView; width: number };
|
|
209
214
|
/** Called with the URL of each picture once it is ON SCREEN (its <img> loaded), not when it is asked for. */
|
|
210
215
|
onShown?: (url: string) => void;
|
|
211
216
|
}
|
|
@@ -258,9 +263,12 @@ export const HeroProductImage = memo(function HeroProductImage({
|
|
|
258
263
|
unavailableText = "Preview unavailable",
|
|
259
264
|
viewportPolicy = false,
|
|
260
265
|
fit = "cover",
|
|
261
|
-
stripView,
|
|
266
|
+
stripView: stripViewProp,
|
|
262
267
|
onShown,
|
|
263
268
|
}: HeroProductImageProps) {
|
|
269
|
+
// The strip ask as primitives (stable deps): the crop or the whole strip, and the crop's downscale width.
|
|
270
|
+
const stripView = typeof stripViewProp === "object" ? stripViewProp.view : stripViewProp;
|
|
271
|
+
const cropWidth = typeof stripViewProp === "object" ? stripViewProp.width : undefined;
|
|
264
272
|
// Context
|
|
265
273
|
const context = useProductOptional();
|
|
266
274
|
const designContext = useDesignOptional();
|
|
@@ -369,11 +377,12 @@ export const HeroProductImage = memo(function HeroProductImage({
|
|
|
369
377
|
placements: allPlacements,
|
|
370
378
|
mockupId: actualMockupId,
|
|
371
379
|
variantId: actualGvid,
|
|
372
|
-
size: heroSize(stripView, width),
|
|
380
|
+
size: heroSize(stripView, cropWidth, width),
|
|
373
381
|
bg: mockupBg,
|
|
374
382
|
});
|
|
375
383
|
}, [
|
|
376
384
|
stripView,
|
|
385
|
+
cropWidth,
|
|
377
386
|
realtimeUrl,
|
|
378
387
|
mode,
|
|
379
388
|
context?.loading,
|
|
@@ -967,7 +976,7 @@ export const HeroProductImage = memo(function HeroProductImage({
|
|
|
967
976
|
placements: allPlacements,
|
|
968
977
|
mockupId: actualMockupId,
|
|
969
978
|
variantId: actualGvid,
|
|
970
|
-
size: heroSize(stripView, width),
|
|
979
|
+
size: heroSize(stripView, cropWidth, width),
|
|
971
980
|
bg: mockupBg,
|
|
972
981
|
});
|
|
973
982
|
if (!url) return;
|
|
@@ -1060,6 +1069,7 @@ export const HeroProductImage = memo(function HeroProductImage({
|
|
|
1060
1069
|
images,
|
|
1061
1070
|
width,
|
|
1062
1071
|
stripView,
|
|
1072
|
+
cropWidth,
|
|
1063
1073
|
effects,
|
|
1064
1074
|
// Use primitive values extracted at the top of the component
|
|
1065
1075
|
artworkSrc,
|
|
@@ -1266,6 +1276,7 @@ export const HeroProductImage = memo(function HeroProductImage({
|
|
|
1266
1276
|
data-mockup-id={actualMockupId || undefined}
|
|
1267
1277
|
data-fit={fit}
|
|
1268
1278
|
data-strip-view={stripView}
|
|
1279
|
+
data-strip-width={cropWidth}
|
|
1269
1280
|
data-picture-failed={imgFailed ? "E_PICTURE_UNDISPLAYED" : undefined}
|
|
1270
1281
|
data-picture-failed-src={failedSrc}
|
|
1271
1282
|
data-mockup-unavailable={unavailable ? unavailable.code : undefined}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
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
|
|
4
|
-
* stripView keeps today's width-sized 16:9 URL.
|
|
3
|
+
* stripView="<r>@<f>" builds `aspect=8:3&view=<r>@<f>` with NO width (or { view, width }: a downscale); the whole strip is
|
|
4
|
+
* the view 2.7@0.25; no stripView keeps today's width-sized 16:9 URL.
|
|
5
5
|
*/
|
|
6
6
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
7
7
|
import React from "react";
|
|
@@ -37,11 +37,19 @@ describe("HeroProductImage stripView", () => {
|
|
|
37
37
|
expect((document.querySelector("[data-hero-image]") as HTMLElement).dataset.stripView).toBe("1.9@0.375");
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
it("
|
|
41
|
-
const src = await heroSrc({ stripView: "
|
|
40
|
+
it("a crop downscaled: view= and the page's width (rendercenter rc#899), stamped data-strip-width", async () => {
|
|
41
|
+
const src = await heroSrc({ stripView: { view: "1.8@0.35", width: 1600 } });
|
|
42
|
+
expect(src.searchParams.get("view")).toBe("1.8@0.35");
|
|
42
43
|
expect(src.searchParams.get("aspect")).toBe("8:3");
|
|
43
|
-
expect(src.searchParams.
|
|
44
|
-
expect(
|
|
44
|
+
expect(src.searchParams.get("width")).toBe("1600");
|
|
45
|
+
expect((document.querySelector("[data-hero-image]") as HTMLElement).dataset.stripWidth).toBe("1600");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("the whole strip is a view (2.7@0.25, rendercenter rc#900): no width unless the page asks one", async () => {
|
|
49
|
+
const src = await heroSrc({ stripView: "2.7@0.25" });
|
|
50
|
+
expect(src.searchParams.get("aspect")).toBe("8:3");
|
|
51
|
+
expect(src.searchParams.get("view")).toBe("2.7@0.25");
|
|
52
|
+
expect(src.searchParams.has("width")).toBe(false);
|
|
45
53
|
});
|
|
46
54
|
|
|
47
55
|
it("no stripView: today's 16:9 URL at a width", async () => {
|
|
@@ -62,7 +62,7 @@ export interface CarouselImage {
|
|
|
62
62
|
* A plate's 8:3 strip (the catalog's `mockups[].strip`): the desktop hero asks for the crop its window shows
|
|
63
63
|
* (`aspect=8:3&view=<r>@<f>`). Absent = the 16:9 hero. Phones ignore it.
|
|
64
64
|
*/
|
|
65
|
-
strip?: { shape: "8:3"; productX: number };
|
|
65
|
+
strip?: { shape: "8:3"; productX: number; heightPx?: number };
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|