@snowcone-app/ui 0.4.6 → 0.4.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.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "React components for merchandise visualization and customization",
5
5
  "keywords": [
6
6
  "react",
@@ -16,6 +16,7 @@ import {
16
16
  import { useShopOptional } from "../patterns/ShopProvider";
17
17
  import { useRealtimeOptional } from "../patterns/RealtimeProvider";
18
18
  import { useMockupPriorityOptional } from "../patterns/MockupPriorityProvider";
19
+ import { useMockupBackgroundOptional } from "../patterns/MockupBackground";
19
20
  import { LoadingOverlayPrismCandyInline } from "../components/LoadingOverlayPrismCandy";
20
21
  import {
21
22
  createDesignForPlacements,
@@ -82,6 +83,8 @@ function buildHeroMockupUrl(args: {
82
83
  mockupId: string;
83
84
  variantId: string;
84
85
  width: number;
86
+ /** Canonical 6-hex background (see MockupBackground) — painted behind alpha scenes. */
87
+ bg?: string;
85
88
  }): string | null {
86
89
  const snow =
87
90
  (typeof window !== "undefined" &&
@@ -97,6 +100,7 @@ function buildHeroMockupUrl(args: {
97
100
  width: args.width,
98
101
  view: args.mockupId,
99
102
  variant: args.variantId,
103
+ ...(args.bg ? { bg: args.bg } : {}),
100
104
  ...(snow.resolver ? { base: snow.resolver } : {}),
101
105
  });
102
106
  }
@@ -204,6 +208,8 @@ export const HeroProductImage = memo(function HeroProductImage({
204
208
  const shopContext = useShopOptional();
205
209
  const realtimeContext = useRealtimeOptional();
206
210
  const priorityContext = useMockupPriorityOptional();
211
+ // Page background baked into static mockup URLs (see MockupBackground).
212
+ const mockupBg = useMockupBackgroundOptional();
207
213
  const priorityContextRef = useRef(priorityContext);
208
214
  priorityContextRef.current = priorityContext;
209
215
 
@@ -295,6 +301,7 @@ export const HeroProductImage = memo(function HeroProductImage({
295
301
  mockupId: actualMockupId,
296
302
  variantId: actualGvid,
297
303
  width,
304
+ bg: mockupBg,
298
305
  });
299
306
  }, [
300
307
  realtimeUrl,
@@ -304,6 +311,7 @@ export const HeroProductImage = memo(function HeroProductImage({
304
311
  actualProductId,
305
312
  actualMockupId,
306
313
  actualGvid,
314
+ mockupBg,
307
315
  product?.placements,
308
316
  context?.product?.placements,
309
317
  images,
@@ -728,6 +736,7 @@ export const HeroProductImage = memo(function HeroProductImage({
728
736
  mockupId: actualMockupId,
729
737
  variantId: actualGvid,
730
738
  width: width,
739
+ bg: mockupBg,
731
740
  });
732
741
  if (!url) return;
733
742
 
@@ -815,6 +824,7 @@ export const HeroProductImage = memo(function HeroProductImage({
815
824
  actualProductId,
816
825
  actualMockupId,
817
826
  actualGvid,
827
+ mockupBg,
818
828
  images,
819
829
  width,
820
830
  effects,
package/src/index.ts CHANGED
@@ -170,6 +170,13 @@ export type {
170
170
  PriorityLevel,
171
171
  } from "./patterns/MockupPriorityProvider";
172
172
 
173
+ // MockupBackground - page background baked into static mockup URLs (bg=)
174
+ export {
175
+ MockupBackground,
176
+ useMockupBackgroundOptional,
177
+ } from "./patterns/MockupBackground";
178
+ export type { MockupBackgroundProps } from "./patterns/MockupBackground";
179
+
173
180
  // ProductPageProvider - Quick-start providers for product pages
174
181
  export {
175
182
  ProductPageProvider,
@@ -0,0 +1,43 @@
1
+ "use client";
2
+
3
+ /**
4
+ * MockupBackground — page-level background color for mockup renders.
5
+ *
6
+ * Wrap a subtree to have every `HeroProductImage` inside it append
7
+ * `bg=<hex>` to the static mockup URLs it builds. The renderer paints the
8
+ * color at the bottom of the stage, so it only shows through mockup scenes
9
+ * whose background has alpha (studio cutouts) — opaque scenes are unaffected.
10
+ *
11
+ * Why: cutout mockups are transparent where the scene ends. Layout tricks
12
+ * that stack a blurred copy of the image behind the sharp one (the PDP
13
+ * edge-blur width extension) bleed through that transparency. Baking the
14
+ * page background into the render makes the image opaque and self-contained
15
+ * (zoom overlays, saved snapshots, and the blur layers all inherit it).
16
+ *
17
+ * `bg` must be the canonical public grammar: lowercase 6-hex, no "#"
18
+ * (URLs are cache keys). Invalid values throw at URL-build time via
19
+ * `getMockupUrl` — loudly, dev and prod.
20
+ */
21
+
22
+ import React, { createContext, useContext } from "react";
23
+
24
+ const MockupBackgroundContext = createContext<string | undefined>(undefined);
25
+
26
+ export interface MockupBackgroundProps {
27
+ /** Canonical background hex (lowercase 6-hex, no "#"), or undefined to leave URLs untouched. */
28
+ bg?: string;
29
+ children: React.ReactNode;
30
+ }
31
+
32
+ export function MockupBackground({ bg, children }: MockupBackgroundProps) {
33
+ return (
34
+ <MockupBackgroundContext.Provider value={bg}>
35
+ {children}
36
+ </MockupBackgroundContext.Provider>
37
+ );
38
+ }
39
+
40
+ /** Background hex from the nearest MockupBackground, or undefined outside one. */
41
+ export function useMockupBackgroundOptional(): string | undefined {
42
+ return useContext(MockupBackgroundContext);
43
+ }