@snowcone-app/ui 0.10.13 → 0.10.15
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 +17 -0
- package/dist/index.cjs +15 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +15 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/composed/carousels/MobileProductCarousel.tsx +3 -4
- package/src/composed/carousels/__tests__/fit.test.ts +16 -0
- package/src/composed/carousels/fit.ts +18 -0
- package/src/personalization/PersonalizationProvider.tsx +7 -3
- package/src/personalization/__tests__/PersonalizationProvider.canvas-import.test.tsx +35 -0
package/package.json
CHANGED
|
@@ -49,6 +49,7 @@ import React, {
|
|
|
49
49
|
memo,
|
|
50
50
|
} from "react";
|
|
51
51
|
import type { CarouselImage } from "./types";
|
|
52
|
+
import { slideFit, zoomFit } from "./fit";
|
|
52
53
|
import { EnhancedImageViewer } from "../zoom/EnhancedImageViewer";
|
|
53
54
|
import { HeroProductImage } from "../HeroProductImage";
|
|
54
55
|
import { LoadingOverlayPrismCandyInline } from "../../components/LoadingOverlayPrismCandy";
|
|
@@ -922,9 +923,7 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
|
|
|
922
923
|
// Edits render only the slides a shopper can see, at the
|
|
923
924
|
// width the screen shows them (sessionShape.ts).
|
|
924
925
|
viewportPolicy
|
|
925
|
-
|
|
926
|
-
// the whole 16:9 frame, never cropped to the slide's centre.
|
|
927
|
-
fit={image.galleryRole === "size-picture" ? "whole" : "cover"}
|
|
926
|
+
fit={slideFit(image.galleryRole)}
|
|
928
927
|
/>
|
|
929
928
|
) : image.isRealMockup && !currentArtwork ? (
|
|
930
929
|
<LoadingOverlayPrismCandyInline visible variant="light" />
|
|
@@ -1028,7 +1027,7 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
|
|
|
1028
1027
|
alt: img.label,
|
|
1029
1028
|
naturalWidth: img.naturalWidth,
|
|
1030
1029
|
naturalHeight: img.naturalHeight,
|
|
1031
|
-
...(img.galleryRole === "
|
|
1030
|
+
...(zoomFit(img.galleryRole) === "whole" ? { fit: "whole" as const } : {}),
|
|
1032
1031
|
} : null;
|
|
1033
1032
|
})
|
|
1034
1033
|
.filter((img): img is NonNullable<typeof img> => img !== null);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { slideFit, zoomFit } from "../fit";
|
|
3
|
+
|
|
4
|
+
// Known case (prod XTNA6J, iPhone 14 at 390 px, 2026-11-13): drawn whole in the phone hero, the size picture's
|
|
5
|
+
// garment was 92-120 px wide and its caption capitals 5 px; cropped it is 214-280 px and 11 px. Lead ruling A: the
|
|
6
|
+
// hero crops it (data-fit "cover"); the zoom viewer still opens it whole.
|
|
7
|
+
describe("size picture fit on a phone", () => {
|
|
8
|
+
it("the phone hero draws the size slide cropped, like every slide", () => {
|
|
9
|
+
expect(slideFit("size-picture")).toBe("cover");
|
|
10
|
+
expect(slideFit(undefined)).toBe("cover");
|
|
11
|
+
});
|
|
12
|
+
it("the zoom viewer opens the size picture whole; other pictures unchanged", () => {
|
|
13
|
+
expect(zoomFit("size-picture")).toBe("whole");
|
|
14
|
+
expect(zoomFit(undefined)).toBe("cover");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CarouselImage } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How the phone carousel draws a picture, and how the zoom viewer opens it.
|
|
5
|
+
*
|
|
6
|
+
* A size picture (galleryRole "size-picture") is a 16:9 diagram with a caption. On a phone the hero is ~342x448, so
|
|
7
|
+
* drawn WHOLE it shrinks to a letterbox: garment 92-120 px wide and caption capitals 5 px (measured on prod XTNA6J,
|
|
8
|
+
* 2026-11-13), against 214-280 px and 11 px cropped. The lead's ruling (A, 2026-11-13): the phone HERO draws it
|
|
9
|
+
* cropped (cover) like every slide; tapping it opens the zoom viewer, which shows it whole.
|
|
10
|
+
*/
|
|
11
|
+
export function slideFit(_galleryRole: CarouselImage["galleryRole"]): "cover" | "whole" {
|
|
12
|
+
return "cover";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The zoom viewer opens a size picture whole (the full 16:9, caption readable); every other picture as before. */
|
|
16
|
+
export function zoomFit(galleryRole: CarouselImage["galleryRole"]): "cover" | "whole" {
|
|
17
|
+
return galleryRole === "size-picture" ? "whole" : "cover";
|
|
18
|
+
}
|
|
@@ -186,7 +186,8 @@ export interface PersonalizationProviderProps {
|
|
|
186
186
|
} | null;
|
|
187
187
|
/**
|
|
188
188
|
* Lazy import for `@snowcone-app/canvas`. Runs in the consumer's webpack context
|
|
189
|
-
* so module resolution works even though this package doesn't depend on canvas.
|
|
189
|
+
* so module resolution works even though this package doesn't depend on canvas. Called only when `fields` is
|
|
190
|
+
* non-empty: a product without personalization never loads the canvas.
|
|
190
191
|
*
|
|
191
192
|
* @example `canvasImport={() => import("@snowcone-app/canvas")}`
|
|
192
193
|
*/
|
|
@@ -249,9 +250,12 @@ export function PersonalizationProvider({
|
|
|
249
250
|
cachedBridgeComponent,
|
|
250
251
|
);
|
|
251
252
|
|
|
253
|
+
// Only a product with personalization fields renders through the hidden canvas, so only then is the canvas
|
|
254
|
+
// imported (it is most of a product page's JS: www's PDP shipped it to every product until 2026-11).
|
|
255
|
+
const hasFields = fields.length > 0;
|
|
252
256
|
useEffect(() => {
|
|
253
257
|
if (CanvasComponent && BridgeComponent) return;
|
|
254
|
-
if (!canvasImport) return;
|
|
258
|
+
if (!canvasImport || !hasFields) return;
|
|
255
259
|
|
|
256
260
|
// Reuse in-flight promise if another instance already started loading
|
|
257
261
|
if (!canvasLoadPromise) {
|
|
@@ -271,7 +275,7 @@ export function PersonalizationProvider({
|
|
|
271
275
|
setBridgeComponent(() => cachedBridgeComponent);
|
|
272
276
|
}
|
|
273
277
|
});
|
|
274
|
-
}, [CanvasComponent, BridgeComponent, canvasImport]);
|
|
278
|
+
}, [CanvasComponent, BridgeComponent, canvasImport, hasFields]);
|
|
275
279
|
|
|
276
280
|
// --- Realtime connection (lazy — only on first export) ---
|
|
277
281
|
const realtimeEnabledRef = useRef(false);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PersonalizationProvider imports @snowcone-app/canvas only for a product with personalization fields: the canvas is
|
|
3
|
+
* most of a product page's JS (www's PDP shipped it to every product until 2026-11, E_PDP_EAGER_EDITOR in www).
|
|
4
|
+
*/
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { render, waitFor } from "@testing-library/react";
|
|
7
|
+
import { describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { PersonalizationProvider } from "../PersonalizationProvider";
|
|
9
|
+
|
|
10
|
+
describe("PersonalizationProvider canvasImport", () => {
|
|
11
|
+
it("never imports the canvas for a product without personalization fields", async () => {
|
|
12
|
+
const canvasImport = vi.fn(() => Promise.resolve({}));
|
|
13
|
+
render(
|
|
14
|
+
<PersonalizationProvider fields={[]} canvasImport={canvasImport} lazy>
|
|
15
|
+
<p>page</p>
|
|
16
|
+
</PersonalizationProvider>,
|
|
17
|
+
);
|
|
18
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
19
|
+
expect(canvasImport).not.toHaveBeenCalled();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("imports it when the product has personalization fields", async () => {
|
|
23
|
+
const canvasImport = vi.fn(() => Promise.resolve({}));
|
|
24
|
+
render(
|
|
25
|
+
<PersonalizationProvider
|
|
26
|
+
fields={[{ type: "text", name: "Name", label: "Name" } as never]}
|
|
27
|
+
canvasImport={canvasImport}
|
|
28
|
+
lazy
|
|
29
|
+
>
|
|
30
|
+
<p>page</p>
|
|
31
|
+
</PersonalizationProvider>,
|
|
32
|
+
);
|
|
33
|
+
await waitFor(() => expect(canvasImport).toHaveBeenCalledTimes(1));
|
|
34
|
+
});
|
|
35
|
+
});
|