@snowcone-app/ui 0.10.22 → 0.11.1
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 +13 -0
- package/dist/chunk-MFDCHCN6.js +80 -0
- package/dist/chunk-MFDCHCN6.js.map +1 -0
- package/dist/hero-url.cjs +98 -0
- package/dist/hero-url.cjs.map +1 -0
- package/dist/hero-url.d.cts +66 -0
- package/dist/hero-url.d.ts +66 -0
- package/dist/hero-url.js +15 -0
- package/dist/hero-url.js.map +1 -0
- package/dist/index.cjs +64 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +20 -42
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/composed/HeroProductImage.tsx +19 -63
- package/src/composed/__tests__/HeroProductImage.ssr-match.test.tsx +102 -0
- package/src/composed/__tests__/fixtures/catalog-AKTGA7.json +298 -0
- package/src/composed/__tests__/fixtures/catalog-BC43BE.json +259 -0
- package/src/composed/__tests__/fixtures/catalog-KVJVVA.json +281 -0
- package/src/composed/__tests__/fixtures/catalog-NBYVCX.json +217 -0
- package/src/composed/carousels/MobileProductCarousel.tsx +4 -0
- package/src/composed/heroMockupUrl.ts +136 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`23994a3`](https://github.com/snowcone-app/snowcone-monorepo/commit/23994a31bdce399b150832c38ba7ae3b6ba8d296)]:
|
|
8
|
+
- @snowcone-app/sdk@0.31.7
|
|
9
|
+
|
|
10
|
+
## 0.11.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [#5747](https://github.com/snowcone-app/snowcone-monorepo/pull/5747) [`8e07949`](https://github.com/snowcone-app/snowcone-monorepo/commit/8e07949a739f140c3214a61efde1278933f94589) Thanks [@kevinsproles](https://github.com/kevinsproles)! - `@snowcone-app/ui/hero-url`: the hero's static mockup URL builder (`heroMockupUrl`, `firstMobileHeroUrl`), server-safe, shared by `HeroProductImage` and a server render that preloads the first hero. `HeroProductImage` (and `MobileProductCarousel` via `presignedHeroUrls`) takes `presigned`: server-signed URLs used as-is when the built URL matches, so a preloaded hero is fetched once (`data-hero-presigned="server"`).
|
|
15
|
+
|
|
3
16
|
## 0.10.22
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/composed/heroMockupUrl.ts
|
|
2
|
+
import {
|
|
3
|
+
createDesignForPlacements,
|
|
4
|
+
deriveDefaultSelection,
|
|
5
|
+
getMockupUrl,
|
|
6
|
+
ordinaryMockups,
|
|
7
|
+
resolveMockupId,
|
|
8
|
+
resolvePreviewVariantId,
|
|
9
|
+
resolveVariantId,
|
|
10
|
+
toCombinations,
|
|
11
|
+
toOptionAttributes
|
|
12
|
+
} from "@snowcone-app/sdk";
|
|
13
|
+
function slugifyPlacementKey(label) {
|
|
14
|
+
return label.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
15
|
+
}
|
|
16
|
+
function toPublicDesign(elements, placements) {
|
|
17
|
+
const design = {};
|
|
18
|
+
for (const el of elements) {
|
|
19
|
+
if (!el.placement) continue;
|
|
20
|
+
const match = placements.find((p) => p.label === el.placement);
|
|
21
|
+
const key = match?.key || slugifyPlacementKey(el.placement);
|
|
22
|
+
if (el.type === "color") {
|
|
23
|
+
if (el.hex) design[key] = { color: el.hex };
|
|
24
|
+
} else if (el.imageUrl) {
|
|
25
|
+
const aligned = el.alignment && el.alignment !== "center";
|
|
26
|
+
design[key] = aligned || el.tiles ? {
|
|
27
|
+
src: el.imageUrl,
|
|
28
|
+
...aligned ? { align: el.alignment } : {},
|
|
29
|
+
...el.tiles ? { tile: el.tiles } : {}
|
|
30
|
+
} : el.imageUrl;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return design;
|
|
34
|
+
}
|
|
35
|
+
function heroMockupUrl(args) {
|
|
36
|
+
if (!args.shop) return null;
|
|
37
|
+
const publicDesign = toPublicDesign(args.design, args.placements);
|
|
38
|
+
if (Object.keys(publicDesign).length === 0) return null;
|
|
39
|
+
return getMockupUrl(args.productCode, {
|
|
40
|
+
shop: args.shop,
|
|
41
|
+
design: publicDesign,
|
|
42
|
+
..."stripView" in args.size ? { aspect: "8:3", stripView: args.size.stripView, ...args.size.width !== void 0 ? { width: args.size.width } : {} } : { width: args.size.width },
|
|
43
|
+
view: args.mockupId,
|
|
44
|
+
variant: args.variantId,
|
|
45
|
+
...args.bg ? { bg: args.bg } : {},
|
|
46
|
+
...args.resolver ? { base: args.resolver } : {}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
var MOBILE_HERO_WIDTH = 3e3;
|
|
50
|
+
function firstMobileHeroUrl(args) {
|
|
51
|
+
const product = args.product;
|
|
52
|
+
if (!product?.id || !args.artworkSrc) return null;
|
|
53
|
+
const placements = product.placements ?? [];
|
|
54
|
+
const first = ordinaryMockups(product.mockups ?? [])[0];
|
|
55
|
+
if (!first || placements.length === 0) return null;
|
|
56
|
+
const optionAttributes = toOptionAttributes(product);
|
|
57
|
+
const combinations = toCombinations(product);
|
|
58
|
+
const selection = { ...deriveDefaultSelection(optionAttributes, combinations) };
|
|
59
|
+
for (const p of placements) if (p.type === "color" && !selection[p.label]) selection[p.label] = "#000000";
|
|
60
|
+
const context = { product, optionAttributes, combinations, selection };
|
|
61
|
+
const selected = resolveVariantId(context);
|
|
62
|
+
const mockupId = resolveMockupId(context, selected, first.id);
|
|
63
|
+
if (!mockupId) return null;
|
|
64
|
+
const variantId = resolvePreviewVariantId(context, selected, mockupId);
|
|
65
|
+
if (!variantId || variantId === "default") return null;
|
|
66
|
+
const placementDesigns = {};
|
|
67
|
+
for (const p of placements) if (p.type !== "color") placementDesigns[p.label] = { imageUrl: args.artworkSrc, alignment: "center" };
|
|
68
|
+
const design = createDesignForPlacements(placements, [], { artworkSrc: args.artworkSrc, placementDesigns });
|
|
69
|
+
if (!design || design.length === 0) return null;
|
|
70
|
+
return heroMockupUrl({ shop: args.shop, resolver: args.resolver, productCode: product.id, design, placements, mockupId, variantId, size: { width: MOBILE_HERO_WIDTH }, bg: args.bg });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
slugifyPlacementKey,
|
|
75
|
+
toPublicDesign,
|
|
76
|
+
heroMockupUrl,
|
|
77
|
+
MOBILE_HERO_WIDTH,
|
|
78
|
+
firstMobileHeroUrl
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=chunk-MFDCHCN6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/composed/heroMockupUrl.ts"],"sourcesContent":["/**\n * The hero's static mockup URL — ONE builder for the client (HeroProductImage) and the server (the PDP's first-hero\n * preload, lane shapes 2026-11-19). Server-safe: no window, no React. The server must request exactly the URL the\n * client will, or the phone downloads the hero twice; HeroProductImage.ssr-match.test.tsx renders the real client\n * component and fails when the two differ.\n */\nimport {\n createDesignForPlacements,\n deriveDefaultSelection,\n getMockupUrl,\n ordinaryMockups,\n resolveMockupId,\n resolvePreviewVariantId,\n resolveVariantId,\n toCombinations,\n toOptionAttributes,\n type CatalogProduct,\n type Design,\n type DesignElement,\n type MockupView,\n} from \"@snowcone-app/sdk\";\n\n/** Slugify a placement label into the catalog's `placements[].key` form. */\nexport function slugifyPlacementKey(label: string): string {\n return label\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_+|_+$/g, \"\");\n}\n\nexport type PlacementLike = { label: string; key?: string; type?: string | null };\n\n/**\n * Convert the SDK's `DesignElement[]` (label-keyed, used by the realtime/canvas\n * path) into the public resolver's `Design` (placement-key → fill), so a static\n * `<img>` can be built via the **signing resolver** (`getMockupUrl`) rather than\n * the unsigned direct-renderer builder. The renderer requires a `seal`, which\n * only the resolver adds (ADR-0076).\n */\nexport function toPublicDesign(elements: DesignElement[], placements: PlacementLike[]): Design {\n const design: Design = {};\n for (const el of elements) {\n if (!el.placement) continue;\n const match = placements.find((p) => p.label === el.placement);\n const key = match?.key || slugifyPlacementKey(el.placement);\n if (el.type === \"color\") {\n if (el.hex) design[key] = { color: el.hex };\n } else if (el.imageUrl) {\n const aligned = el.alignment && el.alignment !== \"center\";\n design[key] =\n aligned || el.tiles\n ? {\n src: el.imageUrl,\n ...(aligned ? { align: el.alignment } : {}),\n ...(el.tiles ? { tile: el.tiles } : {}),\n }\n : el.imageUrl;\n }\n }\n return design;\n}\n\n/** A render width (16:9), or a crop of the 8:3 strip (`view=`: at its own px, or downscaled to `width`). */\nexport type HeroSize = { width: number } | { stripView: MockupView; width?: number };\n\n/**\n * Build a static mockup `<img>` URL through the signing resolver (ADR-0076), UNSIGNED (the L3 `&signature` is added by\n * the signer: /api/sign on the client, lib/sign-mockup on the server). Null when the shop is unknown or the design empty.\n */\nexport function heroMockupUrl(args: {\n shop: string | undefined;\n /** The local resolver host (dev); prod falls back to img.snowcone.app. */\n resolver?: string;\n productCode: string;\n design: DesignElement[];\n placements: PlacementLike[];\n mockupId: string;\n variantId: string;\n size: HeroSize;\n /** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */\n bg?: string;\n}): string | null {\n if (!args.shop) return null;\n const publicDesign = toPublicDesign(args.design, args.placements);\n if (Object.keys(publicDesign).length === 0) return null;\n return getMockupUrl(args.productCode, {\n shop: args.shop,\n design: publicDesign,\n ...(\"stripView\" in args.size\n ? { aspect: \"8:3\" as const, stripView: args.size.stripView, ...(args.size.width !== undefined ? { width: args.size.width } : {}) }\n : { width: args.size.width }),\n view: args.mockupId,\n variant: args.variantId,\n ...(args.bg ? { bg: args.bg } : {}),\n ...(args.resolver ? { base: args.resolver } : {}),\n });\n}\n\n/** The phone carousel's render width: ScrollHero covers 70svh and starts zoomed, so it always asks 3000 (page-client). */\nexport const MOBILE_HERO_WIDTH = 3000;\n\n/**\n * The URL the phone PDP's FIRST hero requests on a fresh load — the product's default selection, the artwork centred on\n * every image placement, no tiles — built by the same steps HeroProductImage runs: the first ordinary mockup\n * (page-client heroImages), resolveVariantId → resolvePreviewVariantId, createDesignForPlacements, heroMockupUrl.\n * Null when anything the client would need is missing (it then builds nothing either, or something the server can't know).\n */\nexport function firstMobileHeroUrl(args: {\n product: CatalogProduct | null | undefined;\n /** The artwork the page applies: \"default\" = the product's own catalog art (the only case the server signs). */\n artworkSrc: string;\n shop: string | undefined;\n resolver?: string;\n bg?: string;\n}): string | null {\n const product = args.product as (CatalogProduct & { mockups?: Array<{ id: string }>; placements?: PlacementLike[] }) | null | undefined;\n if (!product?.id || !args.artworkSrc) return null;\n const placements = product.placements ?? [];\n const first = ordinaryMockups(product.mockups ?? [])[0];\n if (!first || placements.length === 0) return null;\n const optionAttributes = toOptionAttributes(product);\n const combinations = toCombinations(product);\n const selection: Record<string, string> = { ...deriveDefaultSelection(optionAttributes, combinations) };\n for (const p of placements) if (p.type === \"color\" && !selection[p.label]) selection[p.label] = \"#000000\";\n const context = { product, optionAttributes, combinations, selection };\n const selected = resolveVariantId(context);\n const mockupId = resolveMockupId(context, selected, first.id);\n if (!mockupId) return null;\n const variantId = resolvePreviewVariantId(context, selected, mockupId);\n if (!variantId || variantId === \"default\") return null;\n const placementDesigns: Record<string, { imageUrl: string; alignment: \"center\" }> = {};\n for (const p of placements) if (p.type !== \"color\") placementDesigns[p.label] = { imageUrl: args.artworkSrc, alignment: \"center\" };\n const design = createDesignForPlacements(placements as never, [], { artworkSrc: args.artworkSrc, placementDesigns } as never);\n if (!design || design.length === 0) return null;\n return heroMockupUrl({ shop: args.shop, resolver: args.resolver, productCode: product.id, design, placements, mockupId, variantId, size: { width: MOBILE_HERO_WIDTH }, bg: args.bg });\n}\n"],"mappings":";AAMA;AAAA,EACE;AAAA,EACA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CAAU;AAC5H,MAAI,CAAC,UAAU,OAAO,WAAW,EAAG,QAAO;AAC3C,SAAO,cAAc,EAAE,MAAM,KAAK,MAAM,UAAU,KAAK,UAAU,aAAa,QAAQ,IAAI,QAAQ,YAAY,UAAU,WAAW,MAAM,EAAE,OAAO,kBAAkB,GAAG,IAAI,KAAK,GAAG,CAAC;AACtL;","names":[]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/composed/heroMockupUrl.ts
|
|
21
|
+
var heroMockupUrl_exports = {};
|
|
22
|
+
__export(heroMockupUrl_exports, {
|
|
23
|
+
MOBILE_HERO_WIDTH: () => MOBILE_HERO_WIDTH,
|
|
24
|
+
firstMobileHeroUrl: () => firstMobileHeroUrl,
|
|
25
|
+
heroMockupUrl: () => heroMockupUrl,
|
|
26
|
+
slugifyPlacementKey: () => slugifyPlacementKey,
|
|
27
|
+
toPublicDesign: () => toPublicDesign
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(heroMockupUrl_exports);
|
|
30
|
+
var import_sdk = require("@snowcone-app/sdk");
|
|
31
|
+
function slugifyPlacementKey(label) {
|
|
32
|
+
return label.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
33
|
+
}
|
|
34
|
+
function toPublicDesign(elements, placements) {
|
|
35
|
+
const design = {};
|
|
36
|
+
for (const el of elements) {
|
|
37
|
+
if (!el.placement) continue;
|
|
38
|
+
const match = placements.find((p) => p.label === el.placement);
|
|
39
|
+
const key = match?.key || slugifyPlacementKey(el.placement);
|
|
40
|
+
if (el.type === "color") {
|
|
41
|
+
if (el.hex) design[key] = { color: el.hex };
|
|
42
|
+
} else if (el.imageUrl) {
|
|
43
|
+
const aligned = el.alignment && el.alignment !== "center";
|
|
44
|
+
design[key] = aligned || el.tiles ? {
|
|
45
|
+
src: el.imageUrl,
|
|
46
|
+
...aligned ? { align: el.alignment } : {},
|
|
47
|
+
...el.tiles ? { tile: el.tiles } : {}
|
|
48
|
+
} : el.imageUrl;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return design;
|
|
52
|
+
}
|
|
53
|
+
function heroMockupUrl(args) {
|
|
54
|
+
if (!args.shop) return null;
|
|
55
|
+
const publicDesign = toPublicDesign(args.design, args.placements);
|
|
56
|
+
if (Object.keys(publicDesign).length === 0) return null;
|
|
57
|
+
return (0, import_sdk.getMockupUrl)(args.productCode, {
|
|
58
|
+
shop: args.shop,
|
|
59
|
+
design: publicDesign,
|
|
60
|
+
..."stripView" in args.size ? { aspect: "8:3", stripView: args.size.stripView, ...args.size.width !== void 0 ? { width: args.size.width } : {} } : { width: args.size.width },
|
|
61
|
+
view: args.mockupId,
|
|
62
|
+
variant: args.variantId,
|
|
63
|
+
...args.bg ? { bg: args.bg } : {},
|
|
64
|
+
...args.resolver ? { base: args.resolver } : {}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
var MOBILE_HERO_WIDTH = 3e3;
|
|
68
|
+
function firstMobileHeroUrl(args) {
|
|
69
|
+
const product = args.product;
|
|
70
|
+
if (!product?.id || !args.artworkSrc) return null;
|
|
71
|
+
const placements = product.placements ?? [];
|
|
72
|
+
const first = (0, import_sdk.ordinaryMockups)(product.mockups ?? [])[0];
|
|
73
|
+
if (!first || placements.length === 0) return null;
|
|
74
|
+
const optionAttributes = (0, import_sdk.toOptionAttributes)(product);
|
|
75
|
+
const combinations = (0, import_sdk.toCombinations)(product);
|
|
76
|
+
const selection = { ...(0, import_sdk.deriveDefaultSelection)(optionAttributes, combinations) };
|
|
77
|
+
for (const p of placements) if (p.type === "color" && !selection[p.label]) selection[p.label] = "#000000";
|
|
78
|
+
const context = { product, optionAttributes, combinations, selection };
|
|
79
|
+
const selected = (0, import_sdk.resolveVariantId)(context);
|
|
80
|
+
const mockupId = (0, import_sdk.resolveMockupId)(context, selected, first.id);
|
|
81
|
+
if (!mockupId) return null;
|
|
82
|
+
const variantId = (0, import_sdk.resolvePreviewVariantId)(context, selected, mockupId);
|
|
83
|
+
if (!variantId || variantId === "default") return null;
|
|
84
|
+
const placementDesigns = {};
|
|
85
|
+
for (const p of placements) if (p.type !== "color") placementDesigns[p.label] = { imageUrl: args.artworkSrc, alignment: "center" };
|
|
86
|
+
const design = (0, import_sdk.createDesignForPlacements)(placements, [], { artworkSrc: args.artworkSrc, placementDesigns });
|
|
87
|
+
if (!design || design.length === 0) return null;
|
|
88
|
+
return heroMockupUrl({ shop: args.shop, resolver: args.resolver, productCode: product.id, design, placements, mockupId, variantId, size: { width: MOBILE_HERO_WIDTH }, bg: args.bg });
|
|
89
|
+
}
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
MOBILE_HERO_WIDTH,
|
|
93
|
+
firstMobileHeroUrl,
|
|
94
|
+
heroMockupUrl,
|
|
95
|
+
slugifyPlacementKey,
|
|
96
|
+
toPublicDesign
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=hero-url.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/composed/heroMockupUrl.ts"],"sourcesContent":["/**\n * The hero's static mockup URL — ONE builder for the client (HeroProductImage) and the server (the PDP's first-hero\n * preload, lane shapes 2026-11-19). Server-safe: no window, no React. The server must request exactly the URL the\n * client will, or the phone downloads the hero twice; HeroProductImage.ssr-match.test.tsx renders the real client\n * component and fails when the two differ.\n */\nimport {\n createDesignForPlacements,\n deriveDefaultSelection,\n getMockupUrl,\n ordinaryMockups,\n resolveMockupId,\n resolvePreviewVariantId,\n resolveVariantId,\n toCombinations,\n toOptionAttributes,\n type CatalogProduct,\n type Design,\n type DesignElement,\n type MockupView,\n} from \"@snowcone-app/sdk\";\n\n/** Slugify a placement label into the catalog's `placements[].key` form. */\nexport function slugifyPlacementKey(label: string): string {\n return label\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_+|_+$/g, \"\");\n}\n\nexport type PlacementLike = { label: string; key?: string; type?: string | null };\n\n/**\n * Convert the SDK's `DesignElement[]` (label-keyed, used by the realtime/canvas\n * path) into the public resolver's `Design` (placement-key → fill), so a static\n * `<img>` can be built via the **signing resolver** (`getMockupUrl`) rather than\n * the unsigned direct-renderer builder. The renderer requires a `seal`, which\n * only the resolver adds (ADR-0076).\n */\nexport function toPublicDesign(elements: DesignElement[], placements: PlacementLike[]): Design {\n const design: Design = {};\n for (const el of elements) {\n if (!el.placement) continue;\n const match = placements.find((p) => p.label === el.placement);\n const key = match?.key || slugifyPlacementKey(el.placement);\n if (el.type === \"color\") {\n if (el.hex) design[key] = { color: el.hex };\n } else if (el.imageUrl) {\n const aligned = el.alignment && el.alignment !== \"center\";\n design[key] =\n aligned || el.tiles\n ? {\n src: el.imageUrl,\n ...(aligned ? { align: el.alignment } : {}),\n ...(el.tiles ? { tile: el.tiles } : {}),\n }\n : el.imageUrl;\n }\n }\n return design;\n}\n\n/** A render width (16:9), or a crop of the 8:3 strip (`view=`: at its own px, or downscaled to `width`). */\nexport type HeroSize = { width: number } | { stripView: MockupView; width?: number };\n\n/**\n * Build a static mockup `<img>` URL through the signing resolver (ADR-0076), UNSIGNED (the L3 `&signature` is added by\n * the signer: /api/sign on the client, lib/sign-mockup on the server). Null when the shop is unknown or the design empty.\n */\nexport function heroMockupUrl(args: {\n shop: string | undefined;\n /** The local resolver host (dev); prod falls back to img.snowcone.app. */\n resolver?: string;\n productCode: string;\n design: DesignElement[];\n placements: PlacementLike[];\n mockupId: string;\n variantId: string;\n size: HeroSize;\n /** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */\n bg?: string;\n}): string | null {\n if (!args.shop) return null;\n const publicDesign = toPublicDesign(args.design, args.placements);\n if (Object.keys(publicDesign).length === 0) return null;\n return getMockupUrl(args.productCode, {\n shop: args.shop,\n design: publicDesign,\n ...(\"stripView\" in args.size\n ? { aspect: \"8:3\" as const, stripView: args.size.stripView, ...(args.size.width !== undefined ? { width: args.size.width } : {}) }\n : { width: args.size.width }),\n view: args.mockupId,\n variant: args.variantId,\n ...(args.bg ? { bg: args.bg } : {}),\n ...(args.resolver ? { base: args.resolver } : {}),\n });\n}\n\n/** The phone carousel's render width: ScrollHero covers 70svh and starts zoomed, so it always asks 3000 (page-client). */\nexport const MOBILE_HERO_WIDTH = 3000;\n\n/**\n * The URL the phone PDP's FIRST hero requests on a fresh load — the product's default selection, the artwork centred on\n * every image placement, no tiles — built by the same steps HeroProductImage runs: the first ordinary mockup\n * (page-client heroImages), resolveVariantId → resolvePreviewVariantId, createDesignForPlacements, heroMockupUrl.\n * Null when anything the client would need is missing (it then builds nothing either, or something the server can't know).\n */\nexport function firstMobileHeroUrl(args: {\n product: CatalogProduct | null | undefined;\n /** The artwork the page applies: \"default\" = the product's own catalog art (the only case the server signs). */\n artworkSrc: string;\n shop: string | undefined;\n resolver?: string;\n bg?: string;\n}): string | null {\n const product = args.product as (CatalogProduct & { mockups?: Array<{ id: string }>; placements?: PlacementLike[] }) | null | undefined;\n if (!product?.id || !args.artworkSrc) return null;\n const placements = product.placements ?? [];\n const first = ordinaryMockups(product.mockups ?? [])[0];\n if (!first || placements.length === 0) return null;\n const optionAttributes = toOptionAttributes(product);\n const combinations = toCombinations(product);\n const selection: Record<string, string> = { ...deriveDefaultSelection(optionAttributes, combinations) };\n for (const p of placements) if (p.type === \"color\" && !selection[p.label]) selection[p.label] = \"#000000\";\n const context = { product, optionAttributes, combinations, selection };\n const selected = resolveVariantId(context);\n const mockupId = resolveMockupId(context, selected, first.id);\n if (!mockupId) return null;\n const variantId = resolvePreviewVariantId(context, selected, mockupId);\n if (!variantId || variantId === \"default\") return null;\n const placementDesigns: Record<string, { imageUrl: string; alignment: \"center\" }> = {};\n for (const p of placements) if (p.type !== \"color\") placementDesigns[p.label] = { imageUrl: args.artworkSrc, alignment: \"center\" };\n const design = createDesignForPlacements(placements as never, [], { artworkSrc: args.artworkSrc, placementDesigns } as never);\n if (!design || design.length === 0) return null;\n return heroMockupUrl({ shop: args.shop, resolver: args.resolver, productCode: product.id, design, placements, mockupId, variantId, size: { width: MOBILE_HERO_WIDTH }, bg: args.bg });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,iBAcO;AAGA,SAAS,oBAAoB,OAAuB;AACzD,SAAO,MACJ,YAAY,EACZ,QAAQ,eAAe,GAAG,EAC1B,QAAQ,YAAY,EAAE;AAC3B;AAWO,SAAS,eAAe,UAA2B,YAAqC;AAC7F,QAAM,SAAiB,CAAC;AACxB,aAAW,MAAM,UAAU;AACzB,QAAI,CAAC,GAAG,UAAW;AACnB,UAAM,QAAQ,WAAW,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS;AAC7D,UAAM,MAAM,OAAO,OAAO,oBAAoB,GAAG,SAAS;AAC1D,QAAI,GAAG,SAAS,SAAS;AACvB,UAAI,GAAG,IAAK,QAAO,GAAG,IA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AC,SAAS,WAAW,WAAW,EAAG,QAAO;AAC9C,QAAM,uBAAmB,+BAAmB,OAAO;AACnD,QAAM,mBAAe,2BAAe,OAAO;AAC3C,QAAM,YAAoC,EAAE,OAAG,mCAAuB,kBAAkB,YAAY,EAAE;AACtG,aAAW,KAAK,WAAY,KAAI,EAAE,SAAS,WAAW,CAAC,UAAU,EAAE,KAAK,EAAG,WAAU,EAAE,KAAK,IAAI;AAChG,QAAM,UAAU,EAAE,SAAS,kBAAkB,cAAc,UAAU;AACrE,QAAM,eAAW,6BAAiB,OAAO;AACzC,QAAM,eAAW,4BAAgB,SAAS,UAAU,MAAM,EAAE;AAC5D,MAAI,CAAC,SAAU,QAAO;AACtB,QAAM,gBAAY,oCAAwB,SAAS,UAAU,QAAQ;AACrE,MAAI,CAAC,aAAa,cAAc,UAAW,QAAO;AAClD,QAAM,mBAA8E,CAAC;AACrF,aAAW,KAAK,WAAY,KAAI,EAAE,SAAS,QAAS,kBAAiB,EAAE,KAAK,IAAI,EAAE,UAAU,KAAK,YAAY,WAAW,SAAS;AACjI,QAAM,aAAS,sCAA0B,YAAqB,CAAC,GAAG,EAAE,YAAY,KAAK,YAAY,iBAAiB,CAAU;AAC5H,MAAI,CAAC,UAAU,OAAO,WAAW,EAAG,QAAO;AAC3C,SAAO,cAAc,EAAE,MAAM,KAAK,MAAM,UAAU,KAAK,UAAU,aAAa,QAAQ,IAAI,QAAQ,YAAY,UAAU,WAAW,MAAM,EAAE,OAAO,kBAAkB,GAAG,IAAI,KAAK,GAAG,CAAC;AACtL;","names":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MockupView, CatalogProduct, DesignElement, Design } from '@snowcone-app/sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The hero's static mockup URL — ONE builder for the client (HeroProductImage) and the server (the PDP's first-hero
|
|
5
|
+
* preload, lane shapes 2026-11-19). Server-safe: no window, no React. The server must request exactly the URL the
|
|
6
|
+
* client will, or the phone downloads the hero twice; HeroProductImage.ssr-match.test.tsx renders the real client
|
|
7
|
+
* component and fails when the two differ.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Slugify a placement label into the catalog's `placements[].key` form. */
|
|
11
|
+
declare function slugifyPlacementKey(label: string): string;
|
|
12
|
+
type PlacementLike = {
|
|
13
|
+
label: string;
|
|
14
|
+
key?: string;
|
|
15
|
+
type?: string | null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Convert the SDK's `DesignElement[]` (label-keyed, used by the realtime/canvas
|
|
19
|
+
* path) into the public resolver's `Design` (placement-key → fill), so a static
|
|
20
|
+
* `<img>` can be built via the **signing resolver** (`getMockupUrl`) rather than
|
|
21
|
+
* the unsigned direct-renderer builder. The renderer requires a `seal`, which
|
|
22
|
+
* only the resolver adds (ADR-0076).
|
|
23
|
+
*/
|
|
24
|
+
declare function toPublicDesign(elements: DesignElement[], placements: PlacementLike[]): Design;
|
|
25
|
+
/** A render width (16:9), or a crop of the 8:3 strip (`view=`: at its own px, or downscaled to `width`). */
|
|
26
|
+
type HeroSize = {
|
|
27
|
+
width: number;
|
|
28
|
+
} | {
|
|
29
|
+
stripView: MockupView;
|
|
30
|
+
width?: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Build a static mockup `<img>` URL through the signing resolver (ADR-0076), UNSIGNED (the L3 `&signature` is added by
|
|
34
|
+
* the signer: /api/sign on the client, lib/sign-mockup on the server). Null when the shop is unknown or the design empty.
|
|
35
|
+
*/
|
|
36
|
+
declare function heroMockupUrl(args: {
|
|
37
|
+
shop: string | undefined;
|
|
38
|
+
/** The local resolver host (dev); prod falls back to img.snowcone.app. */
|
|
39
|
+
resolver?: string;
|
|
40
|
+
productCode: string;
|
|
41
|
+
design: DesignElement[];
|
|
42
|
+
placements: PlacementLike[];
|
|
43
|
+
mockupId: string;
|
|
44
|
+
variantId: string;
|
|
45
|
+
size: HeroSize;
|
|
46
|
+
/** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */
|
|
47
|
+
bg?: string;
|
|
48
|
+
}): string | null;
|
|
49
|
+
/** The phone carousel's render width: ScrollHero covers 70svh and starts zoomed, so it always asks 3000 (page-client). */
|
|
50
|
+
declare const MOBILE_HERO_WIDTH = 3000;
|
|
51
|
+
/**
|
|
52
|
+
* The URL the phone PDP's FIRST hero requests on a fresh load — the product's default selection, the artwork centred on
|
|
53
|
+
* every image placement, no tiles — built by the same steps HeroProductImage runs: the first ordinary mockup
|
|
54
|
+
* (page-client heroImages), resolveVariantId → resolvePreviewVariantId, createDesignForPlacements, heroMockupUrl.
|
|
55
|
+
* Null when anything the client would need is missing (it then builds nothing either, or something the server can't know).
|
|
56
|
+
*/
|
|
57
|
+
declare function firstMobileHeroUrl(args: {
|
|
58
|
+
product: CatalogProduct | null | undefined;
|
|
59
|
+
/** The artwork the page applies: "default" = the product's own catalog art (the only case the server signs). */
|
|
60
|
+
artworkSrc: string;
|
|
61
|
+
shop: string | undefined;
|
|
62
|
+
resolver?: string;
|
|
63
|
+
bg?: string;
|
|
64
|
+
}): string | null;
|
|
65
|
+
|
|
66
|
+
export { type HeroSize, MOBILE_HERO_WIDTH, type PlacementLike, firstMobileHeroUrl, heroMockupUrl, slugifyPlacementKey, toPublicDesign };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MockupView, CatalogProduct, DesignElement, Design } from '@snowcone-app/sdk';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The hero's static mockup URL — ONE builder for the client (HeroProductImage) and the server (the PDP's first-hero
|
|
5
|
+
* preload, lane shapes 2026-11-19). Server-safe: no window, no React. The server must request exactly the URL the
|
|
6
|
+
* client will, or the phone downloads the hero twice; HeroProductImage.ssr-match.test.tsx renders the real client
|
|
7
|
+
* component and fails when the two differ.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Slugify a placement label into the catalog's `placements[].key` form. */
|
|
11
|
+
declare function slugifyPlacementKey(label: string): string;
|
|
12
|
+
type PlacementLike = {
|
|
13
|
+
label: string;
|
|
14
|
+
key?: string;
|
|
15
|
+
type?: string | null;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Convert the SDK's `DesignElement[]` (label-keyed, used by the realtime/canvas
|
|
19
|
+
* path) into the public resolver's `Design` (placement-key → fill), so a static
|
|
20
|
+
* `<img>` can be built via the **signing resolver** (`getMockupUrl`) rather than
|
|
21
|
+
* the unsigned direct-renderer builder. The renderer requires a `seal`, which
|
|
22
|
+
* only the resolver adds (ADR-0076).
|
|
23
|
+
*/
|
|
24
|
+
declare function toPublicDesign(elements: DesignElement[], placements: PlacementLike[]): Design;
|
|
25
|
+
/** A render width (16:9), or a crop of the 8:3 strip (`view=`: at its own px, or downscaled to `width`). */
|
|
26
|
+
type HeroSize = {
|
|
27
|
+
width: number;
|
|
28
|
+
} | {
|
|
29
|
+
stripView: MockupView;
|
|
30
|
+
width?: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Build a static mockup `<img>` URL through the signing resolver (ADR-0076), UNSIGNED (the L3 `&signature` is added by
|
|
34
|
+
* the signer: /api/sign on the client, lib/sign-mockup on the server). Null when the shop is unknown or the design empty.
|
|
35
|
+
*/
|
|
36
|
+
declare function heroMockupUrl(args: {
|
|
37
|
+
shop: string | undefined;
|
|
38
|
+
/** The local resolver host (dev); prod falls back to img.snowcone.app. */
|
|
39
|
+
resolver?: string;
|
|
40
|
+
productCode: string;
|
|
41
|
+
design: DesignElement[];
|
|
42
|
+
placements: PlacementLike[];
|
|
43
|
+
mockupId: string;
|
|
44
|
+
variantId: string;
|
|
45
|
+
size: HeroSize;
|
|
46
|
+
/** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */
|
|
47
|
+
bg?: string;
|
|
48
|
+
}): string | null;
|
|
49
|
+
/** The phone carousel's render width: ScrollHero covers 70svh and starts zoomed, so it always asks 3000 (page-client). */
|
|
50
|
+
declare const MOBILE_HERO_WIDTH = 3000;
|
|
51
|
+
/**
|
|
52
|
+
* The URL the phone PDP's FIRST hero requests on a fresh load — the product's default selection, the artwork centred on
|
|
53
|
+
* every image placement, no tiles — built by the same steps HeroProductImage runs: the first ordinary mockup
|
|
54
|
+
* (page-client heroImages), resolveVariantId → resolvePreviewVariantId, createDesignForPlacements, heroMockupUrl.
|
|
55
|
+
* Null when anything the client would need is missing (it then builds nothing either, or something the server can't know).
|
|
56
|
+
*/
|
|
57
|
+
declare function firstMobileHeroUrl(args: {
|
|
58
|
+
product: CatalogProduct | null | undefined;
|
|
59
|
+
/** The artwork the page applies: "default" = the product's own catalog art (the only case the server signs). */
|
|
60
|
+
artworkSrc: string;
|
|
61
|
+
shop: string | undefined;
|
|
62
|
+
resolver?: string;
|
|
63
|
+
bg?: string;
|
|
64
|
+
}): string | null;
|
|
65
|
+
|
|
66
|
+
export { type HeroSize, MOBILE_HERO_WIDTH, type PlacementLike, firstMobileHeroUrl, heroMockupUrl, slugifyPlacementKey, toPublicDesign };
|
package/dist/hero-url.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MOBILE_HERO_WIDTH,
|
|
3
|
+
firstMobileHeroUrl,
|
|
4
|
+
heroMockupUrl,
|
|
5
|
+
slugifyPlacementKey,
|
|
6
|
+
toPublicDesign
|
|
7
|
+
} from "./chunk-MFDCHCN6.js";
|
|
8
|
+
export {
|
|
9
|
+
MOBILE_HERO_WIDTH,
|
|
10
|
+
firstMobileHeroUrl,
|
|
11
|
+
heroMockupUrl,
|
|
12
|
+
slugifyPlacementKey,
|
|
13
|
+
toPublicDesign
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=hero-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -342,23 +342,23 @@ __export(src_exports, {
|
|
|
342
342
|
checkTailwindConfig: () => checkTailwindConfig,
|
|
343
343
|
checkThemeTokens: () => checkThemeTokens,
|
|
344
344
|
createScrollDirectionTracker: () => createScrollDirectionTracker,
|
|
345
|
-
describeProductArtAlignment: () =>
|
|
345
|
+
describeProductArtAlignment: () => import_sdk14.describeProductArtAlignment,
|
|
346
346
|
formatCurrency: () => formatCurrency,
|
|
347
347
|
formatDate: () => formatDate,
|
|
348
348
|
formatDateTime: () => formatDateTime,
|
|
349
349
|
getBrand: () => getBrand,
|
|
350
|
-
getMockupUrl: () =>
|
|
350
|
+
getMockupUrl: () => import_sdk13.getMockupUrl,
|
|
351
351
|
getObservedElementCount: () => getObservedElementCount,
|
|
352
352
|
getObserverCount: () => getObserverCount,
|
|
353
|
-
getProduct: () =>
|
|
354
|
-
getSnapPoints: () =>
|
|
353
|
+
getProduct: () => import_sdk13.getProduct,
|
|
354
|
+
getSnapPoints: () => import_sdk14.getSnapPoints,
|
|
355
355
|
hasEdgeBlur: () => hasEdgeBlur,
|
|
356
356
|
isObserved: () => isObserved,
|
|
357
357
|
isWideMonitor: () => isWideMonitor,
|
|
358
358
|
kbdVariants: () => kbdVariants,
|
|
359
359
|
linkVariants: () => linkVariants,
|
|
360
360
|
linkedPlacementsLabel: () => linkedPlacementsLabel,
|
|
361
|
-
listProducts: () =>
|
|
361
|
+
listProducts: () => import_sdk13.listProducts,
|
|
362
362
|
normalizeHex: () => normalizeHex,
|
|
363
363
|
observe: () => observe,
|
|
364
364
|
runConfigChecks: () => runConfigChecks,
|
|
@@ -10247,7 +10247,7 @@ var LoadingOverlayPrismCandyInline = (0, import_react41.memo)(
|
|
|
10247
10247
|
|
|
10248
10248
|
// src/index.ts
|
|
10249
10249
|
var import_react71 = require("@snowcone-app/sdk/react");
|
|
10250
|
-
var
|
|
10250
|
+
var import_sdk13 = require("@snowcone-app/sdk");
|
|
10251
10251
|
|
|
10252
10252
|
// src/patterns/ProductPageProvider.tsx
|
|
10253
10253
|
var import_jsx_runtime57 = require("react/jsx-runtime");
|
|
@@ -10841,7 +10841,46 @@ function CanvasEditor({
|
|
|
10841
10841
|
|
|
10842
10842
|
// src/composed/HeroProductImage.tsx
|
|
10843
10843
|
var import_react46 = require("react");
|
|
10844
|
+
var import_sdk12 = require("@snowcone-app/sdk");
|
|
10845
|
+
|
|
10846
|
+
// src/composed/heroMockupUrl.ts
|
|
10844
10847
|
var import_sdk11 = require("@snowcone-app/sdk");
|
|
10848
|
+
function slugifyPlacementKey(label) {
|
|
10849
|
+
return label.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
10850
|
+
}
|
|
10851
|
+
function toPublicDesign(elements, placements) {
|
|
10852
|
+
const design = {};
|
|
10853
|
+
for (const el of elements) {
|
|
10854
|
+
if (!el.placement) continue;
|
|
10855
|
+
const match = placements.find((p) => p.label === el.placement);
|
|
10856
|
+
const key = match?.key || slugifyPlacementKey(el.placement);
|
|
10857
|
+
if (el.type === "color") {
|
|
10858
|
+
if (el.hex) design[key] = { color: el.hex };
|
|
10859
|
+
} else if (el.imageUrl) {
|
|
10860
|
+
const aligned = el.alignment && el.alignment !== "center";
|
|
10861
|
+
design[key] = aligned || el.tiles ? {
|
|
10862
|
+
src: el.imageUrl,
|
|
10863
|
+
...aligned ? { align: el.alignment } : {},
|
|
10864
|
+
...el.tiles ? { tile: el.tiles } : {}
|
|
10865
|
+
} : el.imageUrl;
|
|
10866
|
+
}
|
|
10867
|
+
}
|
|
10868
|
+
return design;
|
|
10869
|
+
}
|
|
10870
|
+
function heroMockupUrl(args) {
|
|
10871
|
+
if (!args.shop) return null;
|
|
10872
|
+
const publicDesign = toPublicDesign(args.design, args.placements);
|
|
10873
|
+
if (Object.keys(publicDesign).length === 0) return null;
|
|
10874
|
+
return (0, import_sdk11.getMockupUrl)(args.productCode, {
|
|
10875
|
+
shop: args.shop,
|
|
10876
|
+
design: publicDesign,
|
|
10877
|
+
..."stripView" in args.size ? { aspect: "8:3", stripView: args.size.stripView, ...args.size.width !== void 0 ? { width: args.size.width } : {} } : { width: args.size.width },
|
|
10878
|
+
view: args.mockupId,
|
|
10879
|
+
variant: args.variantId,
|
|
10880
|
+
...args.bg ? { bg: args.bg } : {},
|
|
10881
|
+
...args.resolver ? { base: args.resolver } : {}
|
|
10882
|
+
});
|
|
10883
|
+
}
|
|
10845
10884
|
|
|
10846
10885
|
// src/hooks/viewport/useContainerWidth.ts
|
|
10847
10886
|
var import_react45 = require("react");
|
|
@@ -10880,42 +10919,9 @@ function useContainerWidth(containerRef, maxWidth = 3e3) {
|
|
|
10880
10919
|
|
|
10881
10920
|
// src/composed/HeroProductImage.tsx
|
|
10882
10921
|
var import_jsx_runtime61 = require("react/jsx-runtime");
|
|
10883
|
-
function slugifyPlacementKey(label) {
|
|
10884
|
-
return label.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
10885
|
-
}
|
|
10886
|
-
function toPublicDesign(elements, placements) {
|
|
10887
|
-
const design = {};
|
|
10888
|
-
for (const el of elements) {
|
|
10889
|
-
if (!el.placement) continue;
|
|
10890
|
-
const match = placements.find((p) => p.label === el.placement);
|
|
10891
|
-
const key = match?.key || slugifyPlacementKey(el.placement);
|
|
10892
|
-
if (el.type === "color") {
|
|
10893
|
-
if (el.hex) design[key] = { color: el.hex };
|
|
10894
|
-
} else if (el.imageUrl) {
|
|
10895
|
-
const aligned = el.alignment && el.alignment !== "center";
|
|
10896
|
-
design[key] = aligned || el.tiles ? {
|
|
10897
|
-
src: el.imageUrl,
|
|
10898
|
-
...aligned ? { align: el.alignment } : {},
|
|
10899
|
-
...el.tiles ? { tile: el.tiles } : {}
|
|
10900
|
-
} : el.imageUrl;
|
|
10901
|
-
}
|
|
10902
|
-
}
|
|
10903
|
-
return design;
|
|
10904
|
-
}
|
|
10905
10922
|
function buildHeroMockupUrl(args) {
|
|
10906
10923
|
const snow = typeof window !== "undefined" && window.snowcone || {};
|
|
10907
|
-
|
|
10908
|
-
const publicDesign = toPublicDesign(args.design, args.placements);
|
|
10909
|
-
if (Object.keys(publicDesign).length === 0) return null;
|
|
10910
|
-
return (0, import_sdk11.getMockupUrl)(args.productCode, {
|
|
10911
|
-
shop: snow.shop,
|
|
10912
|
-
design: publicDesign,
|
|
10913
|
-
..."stripView" in args.size ? { aspect: "8:3", stripView: args.size.stripView, ...args.size.width !== void 0 ? { width: args.size.width } : {} } : { width: args.size.width },
|
|
10914
|
-
view: args.mockupId,
|
|
10915
|
-
variant: args.variantId,
|
|
10916
|
-
...args.bg ? { bg: args.bg } : {},
|
|
10917
|
-
...snow.resolver ? { base: snow.resolver } : {}
|
|
10918
|
-
});
|
|
10924
|
+
return heroMockupUrl({ ...args, shop: snow.shop, resolver: snow.resolver });
|
|
10919
10925
|
}
|
|
10920
10926
|
function isCrop(stripView) {
|
|
10921
10927
|
return stripView !== void 0;
|
|
@@ -10958,7 +10964,8 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10958
10964
|
viewportPolicy = false,
|
|
10959
10965
|
fit = "cover",
|
|
10960
10966
|
stripView: stripViewProp,
|
|
10961
|
-
onShown
|
|
10967
|
+
onShown,
|
|
10968
|
+
presigned
|
|
10962
10969
|
}) {
|
|
10963
10970
|
const stripView = typeof stripViewProp === "object" ? stripViewProp.view : stripViewProp;
|
|
10964
10971
|
const cropWidth = typeof stripViewProp === "object" ? stripViewProp.width : void 0;
|
|
@@ -10974,13 +10981,13 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
10974
10981
|
contextRef.current = context;
|
|
10975
10982
|
const actualProductId = product?.id || productId || context?.product?.id;
|
|
10976
10983
|
const selectedGvid = (0, import_react46.useMemo)(() => {
|
|
10977
|
-
return (0,
|
|
10984
|
+
return (0, import_sdk12.resolveVariantId)(context, gvid, variantId);
|
|
10978
10985
|
}, [gvid, variantId, context?.selection, context?.combinations]);
|
|
10979
10986
|
const actualMockupId = (0, import_react46.useMemo)(() => {
|
|
10980
|
-
return (0,
|
|
10987
|
+
return (0, import_sdk12.resolveMockupId)(context, selectedGvid, mockupId);
|
|
10981
10988
|
}, [mockupId, selectedGvid, context]);
|
|
10982
10989
|
const actualGvid = (0, import_react46.useMemo)(() => {
|
|
10983
|
-
return gvid || variantId ? selectedGvid : (0,
|
|
10990
|
+
return gvid || variantId ? selectedGvid : (0, import_sdk12.resolvePreviewVariantId)(context, selectedGvid, actualMockupId);
|
|
10984
10991
|
}, [gvid, variantId, selectedGvid, actualMockupId, context]);
|
|
10985
10992
|
const unavailable = actualMockupId ? realtimeContext?.unavailableMockups?.get(actualMockupId) ?? null : null;
|
|
10986
10993
|
const artworkSrc = artwork?.src;
|
|
@@ -11011,7 +11018,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11011
11018
|
};
|
|
11012
11019
|
}
|
|
11013
11020
|
}
|
|
11014
|
-
const design = (0,
|
|
11021
|
+
const design = (0, import_sdk12.createDesignForPlacements)(allPlacements, images, {
|
|
11015
11022
|
artworkSrc: effectiveArtworkSrc,
|
|
11016
11023
|
placementDesigns
|
|
11017
11024
|
});
|
|
@@ -11080,6 +11087,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11080
11087
|
onUrlGeneratedRef.current = onUrlGenerated;
|
|
11081
11088
|
const onShownRef = (0, import_react46.useRef)(onShown);
|
|
11082
11089
|
onShownRef.current = onShown;
|
|
11090
|
+
const presignedUsedRef = (0, import_react46.useRef)(false);
|
|
11083
11091
|
const layersLengthRef = (0, import_react46.useRef)(layers.length);
|
|
11084
11092
|
layersLengthRef.current = layers.length;
|
|
11085
11093
|
(0, import_react46.useEffect)(() => {
|
|
@@ -11355,7 +11363,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11355
11363
|
const placementTiles = firstPlacement ? getPlacementDesign?.(firstPlacement.label)?.tiles : void 0;
|
|
11356
11364
|
const isCurrentArtworkPattern = artworkType === "pattern" || selectedArtworkType === "pattern";
|
|
11357
11365
|
const tiles = isCurrentArtworkPattern ? placementTiles ? placementTiles : artworkTileCount ? artworkTileCount : selectedArtworkTileCount ? selectedArtworkTileCount : void 0 : void 0;
|
|
11358
|
-
return (0,
|
|
11366
|
+
return (0, import_sdk12.createDesignForPlacements)(placements, providedImages, {
|
|
11359
11367
|
selection: contextSelectionRef.current,
|
|
11360
11368
|
attributes: contextOptionAttributesRef.current,
|
|
11361
11369
|
artworkSrc: effectiveArtworkSrc2,
|
|
@@ -11429,7 +11437,11 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11429
11437
|
onUrlGeneratedRef.current?.(finalUrl);
|
|
11430
11438
|
};
|
|
11431
11439
|
const signer = typeof window !== "undefined" ? window.snowcone?.signMockupUrl : void 0;
|
|
11432
|
-
|
|
11440
|
+
const serverSigned = presigned?.find((p) => p.url === url)?.signed;
|
|
11441
|
+
if (serverSigned) {
|
|
11442
|
+
presignedUsedRef.current = true;
|
|
11443
|
+
render(serverSigned);
|
|
11444
|
+
} else if (signer) {
|
|
11433
11445
|
signer(url).then((signed) => render(signed || url)).catch(() => render(url));
|
|
11434
11446
|
} else {
|
|
11435
11447
|
render(url);
|
|
@@ -11585,6 +11597,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11585
11597
|
"data-fit": fit,
|
|
11586
11598
|
"data-strip-view": stripView,
|
|
11587
11599
|
"data-strip-width": cropWidth,
|
|
11600
|
+
"data-hero-presigned": presignedUsedRef.current ? "server" : void 0,
|
|
11588
11601
|
"data-picture-failed": imgFailed ? "E_PICTURE_UNDISPLAYED" : void 0,
|
|
11589
11602
|
"data-picture-failed-src": failedSrc,
|
|
11590
11603
|
"data-mockup-unavailable": unavailable ? unavailable.code : void 0,
|
|
@@ -11640,7 +11653,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
|
|
|
11640
11653
|
signHintShownRef.current = true;
|
|
11641
11654
|
const hasSigner = typeof window !== "undefined" && !!window.snowcone?.signMockupUrl;
|
|
11642
11655
|
console.warn(
|
|
11643
|
-
hasSigner ? "[Snowcone] A mockup image failed to load and its URL is unsigned. Your `signMockupUrl` likely errored \u2014 check your /api/sign route and that its secret matches the shop's signing secret." : `[Snowcone] A mockup image failed to load (likely 'Missing required signature'). If your shop requires signed URLs, pass \`signMockupUrl\` to <Shop> so the UI can sign mockup <img> URLs. Docs: ${
|
|
11656
|
+
hasSigner ? "[Snowcone] A mockup image failed to load and its URL is unsigned. Your `signMockupUrl` likely errored \u2014 check your /api/sign route and that its secret matches the shop's signing secret." : `[Snowcone] A mockup image failed to load (likely 'Missing required signature'). If your shop requires signed URLs, pass \`signMockupUrl\` to <Shop> so the UI can sign mockup <img> URLs. Docs: ${import_sdk12.SNOWCONE_HOSTS.docs}/design-system/signing-at-scale`
|
|
11644
11657
|
);
|
|
11645
11658
|
}
|
|
11646
11659
|
}
|
|
@@ -11711,7 +11724,7 @@ var SafeImg = import_react47.default.forwardRef(
|
|
|
11711
11724
|
);
|
|
11712
11725
|
|
|
11713
11726
|
// src/index.ts
|
|
11714
|
-
var
|
|
11727
|
+
var import_sdk14 = require("@snowcone-app/sdk");
|
|
11715
11728
|
|
|
11716
11729
|
// src/composed/search/SearchProvider.tsx
|
|
11717
11730
|
var import_react_instantsearch = require("react-instantsearch");
|
|
@@ -13149,6 +13162,7 @@ var MobileProductCarousel = (0, import_react56.memo)(function MobileProductCarou
|
|
|
13149
13162
|
onZoomChange,
|
|
13150
13163
|
stickyHeroContext,
|
|
13151
13164
|
mockupWidth,
|
|
13165
|
+
presignedHeroUrls,
|
|
13152
13166
|
onMockupUrlGenerated,
|
|
13153
13167
|
renderImageAction,
|
|
13154
13168
|
errorText,
|
|
@@ -13705,6 +13719,7 @@ var MobileProductCarousel = (0, import_react56.memo)(function MobileProductCarou
|
|
|
13705
13719
|
placement: image.placement,
|
|
13706
13720
|
mockupId: image.mockupId,
|
|
13707
13721
|
width: mockupWidth,
|
|
13722
|
+
presigned: presignedHeroUrls,
|
|
13708
13723
|
realtimeUrl: image.mockupId ? realtimeMockupUrls[image.mockupId] ?? generatedUrlsRef.current.get(image.mockupId) ?? void 0 : void 0,
|
|
13709
13724
|
onUrlGenerated: image.mockupId ? (url) => handleUrlGenerated(image.mockupId, url) : void 0,
|
|
13710
13725
|
errorText,
|