@snowcone-app/ui 0.10.5 → 0.10.7

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.10.5",
3
+ "version": "0.10.7",
4
4
  "description": "React components for merchandise visualization and customization",
5
5
  "keywords": [
6
6
  "react",
@@ -173,6 +173,13 @@ export interface HeroProductImageProps {
173
173
  * today's behaviour.
174
174
  */
175
175
  viewportPolicy?: boolean;
176
+
177
+ /**
178
+ * How the picture fills its box. `cover` (default): fills it, cropping what doesn't fit (a hero). `whole`: the
179
+ * entire picture, letterboxed, nothing cropped: for a diagram with a caption (the gallery's size picture on a
180
+ * phone, where cover would cut a 16:9 frame to its centre). Stamped as data-fit.
181
+ */
182
+ fit?: "cover" | "whole";
176
183
  }
177
184
 
178
185
  /**
@@ -222,6 +229,7 @@ export const HeroProductImage = memo(function HeroProductImage({
222
229
  errorText = "Error loading",
223
230
  unavailableText = "Preview unavailable",
224
231
  viewportPolicy = false,
232
+ fit = "cover",
225
233
  }: HeroProductImageProps) {
226
234
  // Context
227
235
  const context = useProductOptional();
@@ -1213,6 +1221,7 @@ export const HeroProductImage = memo(function HeroProductImage({
1213
1221
  className={`relative overflow-hidden ${className || ""}`}
1214
1222
  style={style}
1215
1223
  data-hero-image="true"
1224
+ data-fit={fit}
1216
1225
  data-mockup-unavailable={unavailable ? unavailable.code : undefined}
1217
1226
  >
1218
1227
  {unavailable && (
@@ -1241,7 +1250,7 @@ export const HeroProductImage = memo(function HeroProductImage({
1241
1250
  key={retryNonce}
1242
1251
  alt={`Product mockup${placement ? ` - ${placement}` : ""}`}
1243
1252
  crossOrigin="anonymous"
1244
- className="absolute inset-0 w-full h-full object-cover"
1253
+ className={`absolute inset-0 w-full h-full ${fit === "whole" ? "object-contain" : "object-cover"}`}
1245
1254
  draggable={draggable}
1246
1255
  src={renderedUrl}
1247
1256
  loading="eager"
@@ -1346,7 +1355,7 @@ export const HeroProductImage = memo(function HeroProductImage({
1346
1355
  <img
1347
1356
  alt=""
1348
1357
  crossOrigin="anonymous"
1349
- className="absolute inset-0 w-full h-full object-cover"
1358
+ className={`absolute inset-0 w-full h-full ${fit === "whole" ? "object-contain" : "object-cover"}`}
1350
1359
  src={prevUrl}
1351
1360
  style={{
1352
1361
  opacity: showNew ? 0 : 1,
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The gallery's size picture is a diagram with a caption, not a hero: on a phone it opens WHOLE (lead, 2026-11-12).
3
+ * HeroProductImage fit="whole" shows the entire picture (object-contain), stamped data-fit; the default stays cover.
4
+ */
5
+ import { describe, expect, it } from "vitest";
6
+ import React from "react";
7
+ import { render, waitFor, cleanup } from "@testing-library/react";
8
+ import { HeroProductImage } from "../HeroProductImage";
9
+
10
+ const ART = { src: "https://example.test/art.png" } as never;
11
+
12
+ describe("HeroProductImage fit", () => {
13
+ it("fit='whole' stamps data-fit and draws the picture whole (object-contain)", async () => {
14
+ cleanup();
15
+ const { container } = render(<HeroProductImage productId="XTNA6J" mockupId="SIZE01" realtimeUrl="https://example.test/size.png" artwork={ART} fit="whole" />);
16
+ const root = container.querySelector("[data-hero-image]") as HTMLElement;
17
+ expect(root.dataset.fit).toBe("whole");
18
+ await waitFor(() => expect(container.querySelector("img")).not.toBeNull());
19
+ expect(container.querySelector("img")!.className).toContain("object-contain");
20
+ expect(container.querySelector("img")!.className).not.toContain("object-cover");
21
+ });
22
+
23
+ it("the default stays cover (every hero today)", async () => {
24
+ cleanup();
25
+ const { container } = render(<HeroProductImage productId="XTNA6J" mockupId="ORD001" realtimeUrl="https://example.test/hero.png" artwork={ART} />);
26
+ expect((container.querySelector("[data-hero-image]") as HTMLElement).dataset.fit).toBe("cover");
27
+ await waitFor(() => expect(container.querySelector("img")).not.toBeNull());
28
+ expect(container.querySelector("img")!.className).toContain("object-cover");
29
+ });
30
+ });
@@ -922,6 +922,9 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
922
922
  // Edits render only the slides a shopper can see, at the
923
923
  // width the screen shows them (sessionShape.ts).
924
924
  viewportPolicy
925
+ // The size picture is a diagram with a caption, not a hero:
926
+ // the whole 16:9 frame, never cropped to the slide's centre.
927
+ fit={image.galleryRole === "size-picture" ? "whole" : "cover"}
925
928
  />
926
929
  ) : image.isRealMockup && !currentArtwork ? (
927
930
  <LoadingOverlayPrismCandyInline visible variant="light" />
@@ -1025,6 +1028,7 @@ export const MobileProductCarousel = memo(function MobileProductCarousel({
1025
1028
  alt: img.label,
1026
1029
  naturalWidth: img.naturalWidth,
1027
1030
  naturalHeight: img.naturalHeight,
1031
+ ...(img.galleryRole === "size-picture" ? { fit: "whole" as const } : {}),
1028
1032
  } : null;
1029
1033
  })
1030
1034
  .filter((img): img is NonNullable<typeof img> => img !== null);
@@ -343,7 +343,8 @@ export const EnhancedImageViewer = ({
343
343
  style={{
344
344
  width: "100%",
345
345
  height: "100%",
346
- objectFit: "cover", // Crop 16:9 to fit 4:3 container
346
+ // 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",
347
348
  }}
348
349
  />
349
350
  </div>
@@ -9,4 +9,6 @@ export interface ZoomImage {
9
9
  isRealMockup?: boolean;
10
10
  placement?: string;
11
11
  mockupId?: string;
12
+ /** `whole`: open the picture whole (contain), not cropped to the screen: the gallery's size picture (a diagram). */
13
+ fit?: "cover" | "whole";
12
14
  }
@@ -1011,6 +1011,13 @@ export function RealtimeProvider({
1011
1011
  return;
1012
1012
  }
1013
1013
  if (lastShapeRef.current && lastShapeRef.current.width !== shape.width) invalidateBackgrounds();
1014
+ // A picture joining the set (the catch-up after an edit, a swipe) has no frozen cropped-delivery background yet:
1015
+ // this config goes full-frame so it seeds one; maybeFlipCrop re-arms cropped delivery once all are seeded.
1016
+ // Asking for cropped frames here sent every new picture a frame it couldn't composite (prod canary, phone
1017
+ // BC43BE, 2026-11-12: 29 E_OVERLAY_NO_BACKGROUND fallbacks on the catch-up, the hero's acks stalled 9.5 s).
1018
+ if (croppedActiveRef.current && shape.mockupIds.some((id) => !backgroundsRef.current.has(id))) {
1019
+ croppedActiveRef.current = false;
1020
+ }
1014
1021
  lastShapeRef.current = shape;
1015
1022
  base.mockupIds = shape.mockupIds;
1016
1023
  base.width = shape.width;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Cropped delivery across a session-shape change: the catch-up adds pictures with no frozen background, so that
3
+ * config goes full-frame (prod canary, phone BC43BE, 2026-11-12: 29 E_OVERLAY_NO_BACKGROUND on the catch-up).
4
+ * Built on the phone viewport policy harness (lane-editor design, approved 2026-11-11). Conditions:
5
+ * 1. ONE config per change, holding the whole set wanted (the server keeps the last config).
6
+ * 3. The catch-up when the edit stops (every picture, editing width, one config) and its cancel by a new edit.
7
+ * 4. A swipe during an edit adds the new slide in one config.
8
+ * Done renders the slide on screen at hero width; desktop (no reports) sends exactly what it sends today.
9
+ */
10
+ import { describe, expect, it, beforeEach, vi } from "vitest";
11
+ import React from "react";
12
+ import { render, waitFor, act, cleanup } from "@testing-library/react";
13
+ import { RealtimeProvider, useRealtime, type RealtimeContextValue } from "../RealtimeProvider";
14
+
15
+ const h = vi.hoisted(() => ({
16
+ state: { results: [] as Array<Record<string, unknown>> },
17
+ sendConfig: vi.fn(),
18
+ version: 0,
19
+ sendCanvasState: vi.fn(() => true),
20
+ stable: {
21
+ sendCanvasBlob: vi.fn(), sendColorBlob: vi.fn(), updateMockupIds: vi.fn(), updatePlacementSettings: vi.fn(),
22
+ connect: vi.fn(), disconnect: vi.fn(), flushPendingBlobs: vi.fn(), hasPendingBlobs: vi.fn(() => false),
23
+ getLatestSentVersions: vi.fn(() => ({})), rerender: vi.fn(() => true),
24
+ },
25
+ }));
26
+
27
+ vi.mock("@snowcone-app/sdk/react", () => ({
28
+ useRealtimeMockup: () => ({
29
+ isConnected: true, isConfigured: true, renderError: null, mockupResults: h.state.results,
30
+ sendConfig: h.sendConfig, sendCanvasState: h.sendCanvasState, getLastSentVersion: () => h.version, ...h.stable,
31
+ }),
32
+ }));
33
+ vi.mock("@snowcone-app/sdk", () => ({ mockupRole: (m: any) => (m?.linkedAs === "size-picture" ? "size-picture" : "ordinary"), gallerySizePicture: () => null, resolveVariantId: () => "gv1", resolvePreviewVariantId: (_c: unknown, v: string) => v }));
34
+ const IDS = ["M0", "M1", "M2", "M3", "M4", "M5"];
35
+ vi.mock("../Product", () => {
36
+ const product = { id: "p1", placements: [{ label: "Front", type: "image" }], mockups: ["M0", "M1", "M2", "M3", "M4", "M5"].map((id) => ({ id })) };
37
+ return { useProductOptional: () => ({ product, selection: {} }) };
38
+ });
39
+ vi.mock("../MockupBackground", () => ({ useMockupBackgroundOptional: () => undefined }));
40
+ vi.mock("../croppedFrameComposite", async (importOriginal) => {
41
+ const actual = await importOriginal<typeof import("../croppedFrameComposite")>();
42
+ return { ...actual, compositeCroppedFrame: vi.fn(async () => new Blob(["x"])), loadImageElement: vi.fn(async () => ({ naturalWidth: 1200, naturalHeight: 675 })) };
43
+ });
44
+
45
+ let ctx: RealtimeContextValue;
46
+ function Capture() { ctx = useRealtime(); return null; }
47
+ function Harness({ v, editorOpen }: { v: number; editorOpen?: boolean }) {
48
+ void v;
49
+ return <RealtimeProvider autoEnable mockupWidth={3000} editorOpen={editorOpen}><Capture /></RealtimeProvider>;
50
+ }
51
+ const configs = () => h.sendConfig.mock.calls.map((c) => c[0] as { mockupIds: string[]; width: number });
52
+ const shapes = () => configs().map((c) => `${c.mockupIds.join(",")}@${c.width}`);
53
+ const wait = (ms: number) => act(async () => { await new Promise((r) => setTimeout(r, ms)); });
54
+ // iPhone 14 in the editor: M0 on screen (342 css px x 3), M1 its neighbour.
55
+ function phoneGallery(onScreen = "M0", neighbours = ["M1"]) {
56
+ IDS.forEach((id) => ctx.reportPictureView(`${id}#el`, {
57
+ mockupId: id, onScreen: id === onScreen, inSet: id === onScreen || neighbours.includes(id), devicePx: id === onScreen || neighbours.includes(id) ? 1026 : 0,
58
+ }));
59
+ }
60
+ function edit() { h.version += 1; ctx.sendCanvasState("Front", { v: h.version }); }
61
+ const frame = (id: string, v: number) => ({ mockupId: id, imageUrl: `https://r/${id}-v${v}`, renderUrl: `https://r/${id}-v${v}`, imageSize: 1, placement: "Front", requestVersion: v });
62
+
63
+ beforeEach(() => {
64
+ cleanup();
65
+ vi.clearAllMocks();
66
+ h.state.results = [];
67
+ h.version = 0;
68
+ h.sendCanvasState.mockImplementation(() => true);
69
+ });
70
+
71
+ describe("cropped delivery across a session-shape change", () => {
72
+ it("the catch-up that adds unseeded pictures is sent full-frame (no overlayCrop); cropped delivery re-arms after", async () => {
73
+ globalThis.URL.createObjectURL = vi.fn(() => "blob:c");
74
+ const { rerender } = render(<Harness v={1} />);
75
+ await waitFor(() => expect(h.sendConfig).toHaveBeenCalled());
76
+ await act(async () => phoneGallery());
77
+ await wait(150);
78
+ await act(async () => edit()); // the edit narrows the session to M0, M1 at 1200
79
+ // v1's full frames for the set land at 1200: both seed, cropped delivery flips on for {M0, M1}
80
+ h.state.results = [frame("M0", 1), frame("M1", 1)];
81
+ await act(async () => rerender(<Harness v={2} />));
82
+ await waitFor(() => expect(configs().some((c: any) => c.overlayCrop === "auto")).toBe(true));
83
+ // A second edit while cropped delivery is on: its cropped frames composite, it settles, the catch-up follows.
84
+ await act(async () => edit());
85
+ const crop = { x: 0.2, y: 0.1, w: 0.5, h: 0.6 };
86
+ h.state.results = [{ ...frame("M0", 2), imageUrl: "blob:m0v2", cropRect: crop }, { ...frame("M1", 2), imageUrl: "blob:m1v2", cropRect: crop }];
87
+ await act(async () => rerender(<Harness v={3} />));
88
+ await wait(900); // the edit settles: the catch-up asks for every picture, M2..M5 have no background yet
89
+ const flipAt = configs().findIndex((c: any) => c.overlayCrop === "auto");
90
+ const catchUp = configs().slice(flipAt + 1).find((c) => c.mockupIds.length === IDS.length) as any;
91
+ expect(catchUp, "a catch-up config was sent").toBeTruthy();
92
+ expect(catchUp.overlayCrop).toBeUndefined();
93
+ });
94
+ });