@snowcone-app/ui 0.9.8 → 0.10.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 +12 -0
- package/dist/index.cjs +202 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +202 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/composed/HeroProductImage.tsx +57 -1
- package/src/composed/carousels/MobileProductCarousel.tsx +3 -0
- package/src/patterns/RealtimeProvider.tsx +179 -11
- package/src/patterns/__tests__/RealtimeProvider.sessionShape.test.tsx +162 -0
- package/src/patterns/__tests__/sessionShape.test.ts +62 -0
- package/src/patterns/sessionShape.ts +82 -0
package/dist/index.d.cts
CHANGED
|
@@ -2925,6 +2925,23 @@ declare function useShop(): ShopContextValue;
|
|
|
2925
2925
|
*/
|
|
2926
2926
|
declare function useShopOptional(): ShopContextValue | undefined;
|
|
2927
2927
|
|
|
2928
|
+
interface PictureView {
|
|
2929
|
+
/** Optional when the map is keyed by mockup id; set when keyed per element (a mockup may render twice). */
|
|
2930
|
+
mockupId?: string;
|
|
2931
|
+
/** In view or a neighbour of the picture in view (the set an edit renders). */
|
|
2932
|
+
inSet: boolean;
|
|
2933
|
+
/** Actually on screen now (the set Done renders at hero width). */
|
|
2934
|
+
onScreen: boolean;
|
|
2935
|
+
/** Displayed width in device pixels (CSS width x devicePixelRatio). */
|
|
2936
|
+
devicePx: number;
|
|
2937
|
+
}
|
|
2938
|
+
interface SessionShape {
|
|
2939
|
+
mockupIds: string[];
|
|
2940
|
+
width: number;
|
|
2941
|
+
/** Why, for traces and data attributes. */
|
|
2942
|
+
phase: "no-policy" | "editing" | "catch-up" | "done";
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2928
2945
|
interface MockupResult {
|
|
2929
2946
|
mockupId: string;
|
|
2930
2947
|
imageUrl: string;
|
|
@@ -3060,6 +3077,20 @@ interface RealtimeContextValue {
|
|
|
3060
3077
|
* placement here, its frame's `versions[placement]` is at least this.
|
|
3061
3078
|
*/
|
|
3062
3079
|
getLatestSentVersions: () => Record<string, number>;
|
|
3080
|
+
/**
|
|
3081
|
+
* Viewport policy (sessionShape.ts): a gallery picture reports whether it is
|
|
3082
|
+
* in the edit set (in view or a neighbour), on screen, and its displayed
|
|
3083
|
+
* width in device pixels; `null` when it unmounts. Only a gallery that opts
|
|
3084
|
+
* in reports (the phone carousel); without reports nothing changes.
|
|
3085
|
+
*/
|
|
3086
|
+
reportPictureView: (elementKey: string, view: PictureView | null) => void;
|
|
3087
|
+
/** The shape the session renders now: its phase and width (for data attributes and checks). */
|
|
3088
|
+
getSessionShape: () => {
|
|
3089
|
+
phase: SessionShape["phase"];
|
|
3090
|
+
width: number;
|
|
3091
|
+
} | null;
|
|
3092
|
+
/** The design editor opened or closed (Done). Drives the viewport policy's phase; see `editorOpen`. */
|
|
3093
|
+
setEditorOpen: (open: boolean) => void;
|
|
3063
3094
|
flushPendingBlobs: () => void;
|
|
3064
3095
|
hasPendingBlobs: () => boolean;
|
|
3065
3096
|
subscribePipelineSettled: (callback: () => void) => () => void;
|
|
@@ -3133,13 +3164,22 @@ interface RealtimeProviderProps {
|
|
|
3133
3164
|
* the rest of the session automatically.
|
|
3134
3165
|
*/
|
|
3135
3166
|
delivery?: "cropped" | "full-frame";
|
|
3167
|
+
/**
|
|
3168
|
+
* Whether the design editor is open. With a gallery that opted into the
|
|
3169
|
+
* viewport policy (`reportPictureView`, the phone carousel), an open editor
|
|
3170
|
+
* renders the pictures in view at the width the screen shows them while an
|
|
3171
|
+
* edit is live, and every picture at that width when it stops; closing it
|
|
3172
|
+
* (Done) renders the picture on screen at `mockupWidth` (see sessionShape.ts).
|
|
3173
|
+
* Without such a gallery it changes nothing. Default true.
|
|
3174
|
+
*/
|
|
3175
|
+
editorOpen?: boolean;
|
|
3136
3176
|
}
|
|
3137
3177
|
/**
|
|
3138
3178
|
* RealtimeProvider - Manages realtime mockup WebSocket connection
|
|
3139
3179
|
*
|
|
3140
3180
|
* Must be used inside a <Product> provider to access product data.
|
|
3141
3181
|
*/
|
|
3142
|
-
declare function RealtimeProvider({ children, wsUrl, mockupWidth, autoEnable, shop, grantUrl, initialGrant, delivery, }: RealtimeProviderProps): react_jsx_runtime.JSX.Element;
|
|
3182
|
+
declare function RealtimeProvider({ children, wsUrl, mockupWidth, autoEnable, shop, grantUrl, initialGrant, delivery, editorOpen, }: RealtimeProviderProps): react_jsx_runtime.JSX.Element;
|
|
3143
3183
|
/**
|
|
3144
3184
|
* Hook to access realtime context
|
|
3145
3185
|
* Throws if not inside RealtimeProvider
|
|
@@ -4391,6 +4431,14 @@ interface HeroProductImageProps {
|
|
|
4391
4431
|
errorText?: string;
|
|
4392
4432
|
/** Label shown when the image fails to load with no stale image to keep. */
|
|
4393
4433
|
unavailableText?: string;
|
|
4434
|
+
/**
|
|
4435
|
+
* Opt this picture into the realtime viewport policy (sessionShape.ts): it
|
|
4436
|
+
* reports whether it is in view (or a neighbour) and its displayed width,
|
|
4437
|
+
* so an edit renders only the pictures a shopper can see, at the width the
|
|
4438
|
+
* screen shows them. The phone carousel sets it; galleries that don't keep
|
|
4439
|
+
* today's behaviour.
|
|
4440
|
+
*/
|
|
4441
|
+
viewportPolicy?: boolean;
|
|
4394
4442
|
}
|
|
4395
4443
|
/**
|
|
4396
4444
|
* Hero-compatible version of ProductImage that renders as a simple img element
|
package/dist/index.d.ts
CHANGED
|
@@ -2925,6 +2925,23 @@ declare function useShop(): ShopContextValue;
|
|
|
2925
2925
|
*/
|
|
2926
2926
|
declare function useShopOptional(): ShopContextValue | undefined;
|
|
2927
2927
|
|
|
2928
|
+
interface PictureView {
|
|
2929
|
+
/** Optional when the map is keyed by mockup id; set when keyed per element (a mockup may render twice). */
|
|
2930
|
+
mockupId?: string;
|
|
2931
|
+
/** In view or a neighbour of the picture in view (the set an edit renders). */
|
|
2932
|
+
inSet: boolean;
|
|
2933
|
+
/** Actually on screen now (the set Done renders at hero width). */
|
|
2934
|
+
onScreen: boolean;
|
|
2935
|
+
/** Displayed width in device pixels (CSS width x devicePixelRatio). */
|
|
2936
|
+
devicePx: number;
|
|
2937
|
+
}
|
|
2938
|
+
interface SessionShape {
|
|
2939
|
+
mockupIds: string[];
|
|
2940
|
+
width: number;
|
|
2941
|
+
/** Why, for traces and data attributes. */
|
|
2942
|
+
phase: "no-policy" | "editing" | "catch-up" | "done";
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2928
2945
|
interface MockupResult {
|
|
2929
2946
|
mockupId: string;
|
|
2930
2947
|
imageUrl: string;
|
|
@@ -3060,6 +3077,20 @@ interface RealtimeContextValue {
|
|
|
3060
3077
|
* placement here, its frame's `versions[placement]` is at least this.
|
|
3061
3078
|
*/
|
|
3062
3079
|
getLatestSentVersions: () => Record<string, number>;
|
|
3080
|
+
/**
|
|
3081
|
+
* Viewport policy (sessionShape.ts): a gallery picture reports whether it is
|
|
3082
|
+
* in the edit set (in view or a neighbour), on screen, and its displayed
|
|
3083
|
+
* width in device pixels; `null` when it unmounts. Only a gallery that opts
|
|
3084
|
+
* in reports (the phone carousel); without reports nothing changes.
|
|
3085
|
+
*/
|
|
3086
|
+
reportPictureView: (elementKey: string, view: PictureView | null) => void;
|
|
3087
|
+
/** The shape the session renders now: its phase and width (for data attributes and checks). */
|
|
3088
|
+
getSessionShape: () => {
|
|
3089
|
+
phase: SessionShape["phase"];
|
|
3090
|
+
width: number;
|
|
3091
|
+
} | null;
|
|
3092
|
+
/** The design editor opened or closed (Done). Drives the viewport policy's phase; see `editorOpen`. */
|
|
3093
|
+
setEditorOpen: (open: boolean) => void;
|
|
3063
3094
|
flushPendingBlobs: () => void;
|
|
3064
3095
|
hasPendingBlobs: () => boolean;
|
|
3065
3096
|
subscribePipelineSettled: (callback: () => void) => () => void;
|
|
@@ -3133,13 +3164,22 @@ interface RealtimeProviderProps {
|
|
|
3133
3164
|
* the rest of the session automatically.
|
|
3134
3165
|
*/
|
|
3135
3166
|
delivery?: "cropped" | "full-frame";
|
|
3167
|
+
/**
|
|
3168
|
+
* Whether the design editor is open. With a gallery that opted into the
|
|
3169
|
+
* viewport policy (`reportPictureView`, the phone carousel), an open editor
|
|
3170
|
+
* renders the pictures in view at the width the screen shows them while an
|
|
3171
|
+
* edit is live, and every picture at that width when it stops; closing it
|
|
3172
|
+
* (Done) renders the picture on screen at `mockupWidth` (see sessionShape.ts).
|
|
3173
|
+
* Without such a gallery it changes nothing. Default true.
|
|
3174
|
+
*/
|
|
3175
|
+
editorOpen?: boolean;
|
|
3136
3176
|
}
|
|
3137
3177
|
/**
|
|
3138
3178
|
* RealtimeProvider - Manages realtime mockup WebSocket connection
|
|
3139
3179
|
*
|
|
3140
3180
|
* Must be used inside a <Product> provider to access product data.
|
|
3141
3181
|
*/
|
|
3142
|
-
declare function RealtimeProvider({ children, wsUrl, mockupWidth, autoEnable, shop, grantUrl, initialGrant, delivery, }: RealtimeProviderProps): react_jsx_runtime.JSX.Element;
|
|
3182
|
+
declare function RealtimeProvider({ children, wsUrl, mockupWidth, autoEnable, shop, grantUrl, initialGrant, delivery, editorOpen, }: RealtimeProviderProps): react_jsx_runtime.JSX.Element;
|
|
3143
3183
|
/**
|
|
3144
3184
|
* Hook to access realtime context
|
|
3145
3185
|
* Throws if not inside RealtimeProvider
|
|
@@ -4391,6 +4431,14 @@ interface HeroProductImageProps {
|
|
|
4391
4431
|
errorText?: string;
|
|
4392
4432
|
/** Label shown when the image fails to load with no stale image to keep. */
|
|
4393
4433
|
unavailableText?: string;
|
|
4434
|
+
/**
|
|
4435
|
+
* Opt this picture into the realtime viewport policy (sessionShape.ts): it
|
|
4436
|
+
* reports whether it is in view (or a neighbour) and its displayed width,
|
|
4437
|
+
* so an edit renders only the pictures a shopper can see, at the width the
|
|
4438
|
+
* screen shows them. The phone carousel sets it; galleries that don't keep
|
|
4439
|
+
* today's behaviour.
|
|
4440
|
+
*/
|
|
4441
|
+
viewportPolicy?: boolean;
|
|
4394
4442
|
}
|
|
4395
4443
|
/**
|
|
4396
4444
|
* Hero-compatible version of ProductImage that renders as a simple img element
|
package/dist/index.js
CHANGED
|
@@ -5638,6 +5638,41 @@ function useMockupBackgroundOptional() {
|
|
|
5638
5638
|
return useContext5(MockupBackgroundContext);
|
|
5639
5639
|
}
|
|
5640
5640
|
|
|
5641
|
+
// src/patterns/sessionShape.ts
|
|
5642
|
+
var WIDTH_LADDER = [400, 600, 800, 1e3, 1200, 1600, 2e3, 3e3, 4e3];
|
|
5643
|
+
function ladderWidth(devicePx) {
|
|
5644
|
+
for (const w of WIDTH_LADDER) if (w >= devicePx) return w;
|
|
5645
|
+
return WIDTH_LADDER[WIDTH_LADDER.length - 1];
|
|
5646
|
+
}
|
|
5647
|
+
function sessionShape(input) {
|
|
5648
|
+
const { allMockupIds, views, heroWidth, editorOpen, editLive } = input;
|
|
5649
|
+
if (views.size === 0) return { mockupIds: [...allMockupIds], width: heroWidth, phase: "no-policy" };
|
|
5650
|
+
const byMockup = /* @__PURE__ */ new Map();
|
|
5651
|
+
views.forEach((v, key) => {
|
|
5652
|
+
const id = v.mockupId ?? key;
|
|
5653
|
+
const prev = byMockup.get(id);
|
|
5654
|
+
byMockup.set(id, prev ? { inSet: prev.inSet || v.inSet, onScreen: prev.onScreen || v.onScreen, devicePx: Math.max(prev.devicePx, v.devicePx) } : { inSet: v.inSet, onScreen: v.onScreen, devicePx: v.devicePx });
|
|
5655
|
+
});
|
|
5656
|
+
const ordered = (pick) => allMockupIds.filter((id) => {
|
|
5657
|
+
const v = byMockup.get(id);
|
|
5658
|
+
return v ? pick(v) : false;
|
|
5659
|
+
});
|
|
5660
|
+
const inSet = ordered((v) => v.inSet);
|
|
5661
|
+
const onScreen = ordered((v) => v.onScreen);
|
|
5662
|
+
const shown = [...byMockup.values()].filter((v) => v.inSet && v.devicePx > 0).map((v) => v.devicePx);
|
|
5663
|
+
const editingWidth = shown.length ? ladderWidth(Math.max(...shown)) : heroWidth;
|
|
5664
|
+
if (!editorOpen) {
|
|
5665
|
+
const set = onScreen.length ? onScreen : inSet;
|
|
5666
|
+
return { mockupIds: set.length ? set : [...allMockupIds], width: heroWidth, phase: "done" };
|
|
5667
|
+
}
|
|
5668
|
+
if (editLive && inSet.length) return { mockupIds: inSet, width: editingWidth, phase: "editing" };
|
|
5669
|
+
return { mockupIds: [...allMockupIds], width: editingWidth, phase: "catch-up" };
|
|
5670
|
+
}
|
|
5671
|
+
function sameShape(a, b) {
|
|
5672
|
+
if (!a) return false;
|
|
5673
|
+
return a.width === b.width && [...a.mockupIds].sort().join(",") === [...b.mockupIds].sort().join(",");
|
|
5674
|
+
}
|
|
5675
|
+
|
|
5641
5676
|
// src/patterns/croppedFrameComposite.ts
|
|
5642
5677
|
var COMPOSITE_QUALITY = 0.92;
|
|
5643
5678
|
function isFullRect(rect) {
|
|
@@ -5706,6 +5741,8 @@ var MAX_CONCURRENT_BLOBS = 5;
|
|
|
5706
5741
|
var MAX_FRAMES_PER_PICTURE = 3;
|
|
5707
5742
|
var FRAME_SUPERSEDE_GRACE_MS = 2e3;
|
|
5708
5743
|
var RERENDER_MIN_INTERVAL_MS = 550;
|
|
5744
|
+
var EDIT_QUIET_MS = 600;
|
|
5745
|
+
var EXPORT_PENDING_MAX_MS = 5e3;
|
|
5709
5746
|
function mergeMockupIds(current, extra) {
|
|
5710
5747
|
const out = [...current];
|
|
5711
5748
|
for (const id of extra) if (!out.includes(id)) out.push(id);
|
|
@@ -5724,7 +5761,8 @@ function RealtimeProvider({
|
|
|
5724
5761
|
shop,
|
|
5725
5762
|
grantUrl,
|
|
5726
5763
|
initialGrant,
|
|
5727
|
-
delivery = "cropped"
|
|
5764
|
+
delivery = "cropped",
|
|
5765
|
+
editorOpen = true
|
|
5728
5766
|
}) {
|
|
5729
5767
|
const productContext = useProductOptional();
|
|
5730
5768
|
const mockupBg = useMockupBackgroundOptional();
|
|
@@ -5865,6 +5903,19 @@ function RealtimeProvider({
|
|
|
5865
5903
|
const compositeBusyRef = useRef12(/* @__PURE__ */ new Set());
|
|
5866
5904
|
const compositeCanvasRef = useRef12(null);
|
|
5867
5905
|
const requestedMockupIdsRef = useRef12([]);
|
|
5906
|
+
const pictureViewsRef = useRef12(/* @__PURE__ */ new Map());
|
|
5907
|
+
const editLiveRef = useRef12(false);
|
|
5908
|
+
const editQuietTimerRef = useRef12(null);
|
|
5909
|
+
const exportPendingSinceRef = useRef12(0);
|
|
5910
|
+
const shapeApplyTimerRef = useRef12(null);
|
|
5911
|
+
const lastShapeRef = useRef12(null);
|
|
5912
|
+
const applySessionShapeRef = useRef12(null);
|
|
5913
|
+
const [editorOpenState, setEditorOpenState] = useState17(editorOpen);
|
|
5914
|
+
useEffect17(() => setEditorOpenState(editorOpen), [editorOpen]);
|
|
5915
|
+
const editorOpenRef = useRef12(editorOpenState);
|
|
5916
|
+
editorOpenRef.current = editorOpenState;
|
|
5917
|
+
const heroWidthRef = useRef12(mockupWidth);
|
|
5918
|
+
heroWidthRef.current = mockupWidth;
|
|
5868
5919
|
const serverStampsVersionsRef = useRef12(false);
|
|
5869
5920
|
const pendingRerenderRef = useRef12([]);
|
|
5870
5921
|
const forceRerenderByConfigRef = useRef12(null);
|
|
@@ -6055,6 +6106,64 @@ function RealtimeProvider({
|
|
|
6055
6106
|
compositeQueueRef.current.clear();
|
|
6056
6107
|
croppedActiveRef.current = false;
|
|
6057
6108
|
}, []);
|
|
6109
|
+
const currentShape = useCallback10(
|
|
6110
|
+
() => sessionShape({
|
|
6111
|
+
allMockupIds: configuredMockupIdsRef.current,
|
|
6112
|
+
views: pictureViewsRef.current,
|
|
6113
|
+
heroWidth: heroWidthRef.current,
|
|
6114
|
+
editorOpen: editorOpenRef.current,
|
|
6115
|
+
editLive: editLiveRef.current
|
|
6116
|
+
}),
|
|
6117
|
+
[]
|
|
6118
|
+
);
|
|
6119
|
+
const applySessionShape = useCallback10(() => {
|
|
6120
|
+
const base = lastConfigBaseRef.current;
|
|
6121
|
+
if (!base || !configSentRef.current) return;
|
|
6122
|
+
const shape = currentShape();
|
|
6123
|
+
if (sameShape(lastShapeRef.current, shape)) {
|
|
6124
|
+
lastShapeRef.current = shape;
|
|
6125
|
+
return;
|
|
6126
|
+
}
|
|
6127
|
+
if (lastShapeRef.current && lastShapeRef.current.width !== shape.width) invalidateBackgrounds();
|
|
6128
|
+
lastShapeRef.current = shape;
|
|
6129
|
+
base.mockupIds = shape.mockupIds;
|
|
6130
|
+
base.width = shape.width;
|
|
6131
|
+
requestedMockupIdsRef.current = [...shape.mockupIds];
|
|
6132
|
+
sendConfigRaw({
|
|
6133
|
+
...base,
|
|
6134
|
+
placementSettings: { ...placementSettingsOverridesRef.current },
|
|
6135
|
+
...croppedActiveRef.current ? { overlayCrop: "auto" } : {}
|
|
6136
|
+
});
|
|
6137
|
+
}, [currentShape, invalidateBackgrounds, sendConfigRaw]);
|
|
6138
|
+
applySessionShapeRef.current = applySessionShape;
|
|
6139
|
+
const markEditLive = useCallback10(() => {
|
|
6140
|
+
if (editQuietTimerRef.current) {
|
|
6141
|
+
clearTimeout(editQuietTimerRef.current);
|
|
6142
|
+
editQuietTimerRef.current = null;
|
|
6143
|
+
}
|
|
6144
|
+
if (editLiveRef.current) return;
|
|
6145
|
+
editLiveRef.current = true;
|
|
6146
|
+
applySessionShapeRef.current?.();
|
|
6147
|
+
}, []);
|
|
6148
|
+
const markEditSettled = useCallback10(() => {
|
|
6149
|
+
if (!editLiveRef.current) return;
|
|
6150
|
+
if (editQuietTimerRef.current) clearTimeout(editQuietTimerRef.current);
|
|
6151
|
+
editQuietTimerRef.current = setTimeout(() => {
|
|
6152
|
+
editQuietTimerRef.current = null;
|
|
6153
|
+
editLiveRef.current = false;
|
|
6154
|
+
applySessionShapeRef.current?.();
|
|
6155
|
+
}, EDIT_QUIET_MS);
|
|
6156
|
+
}, []);
|
|
6157
|
+
useEffect17(() => {
|
|
6158
|
+
applySessionShapeRef.current?.();
|
|
6159
|
+
}, [editorOpenState]);
|
|
6160
|
+
useEffect17(
|
|
6161
|
+
() => () => {
|
|
6162
|
+
if (editQuietTimerRef.current) clearTimeout(editQuietTimerRef.current);
|
|
6163
|
+
if (shapeApplyTimerRef.current) clearTimeout(shapeApplyTimerRef.current);
|
|
6164
|
+
},
|
|
6165
|
+
[]
|
|
6166
|
+
);
|
|
6058
6167
|
const deliverResults = useCallback10(
|
|
6059
6168
|
(results) => {
|
|
6060
6169
|
if (results.length === 0) return;
|
|
@@ -6100,6 +6209,7 @@ function RealtimeProvider({
|
|
|
6100
6209
|
}
|
|
6101
6210
|
});
|
|
6102
6211
|
let settledVersions = 0;
|
|
6212
|
+
let newestSettled = 0;
|
|
6103
6213
|
const due = dueByVersionRef.current;
|
|
6104
6214
|
results.forEach((result) => {
|
|
6105
6215
|
const v = result.requestVersion;
|
|
@@ -6109,6 +6219,7 @@ function RealtimeProvider({
|
|
|
6109
6219
|
if (entry.due <= 1) {
|
|
6110
6220
|
due.delete(v);
|
|
6111
6221
|
settledVersions += 1;
|
|
6222
|
+
newestSettled = Math.max(newestSettled, v);
|
|
6112
6223
|
} else {
|
|
6113
6224
|
entry.due -= 1;
|
|
6114
6225
|
}
|
|
@@ -6120,13 +6231,16 @@ function RealtimeProvider({
|
|
|
6120
6231
|
if (!pipelineResetCooldownRef.current) {
|
|
6121
6232
|
hasBlobInFlightRef.current = false;
|
|
6122
6233
|
for (let i = 0; i < settledVersions; i++) pipelineSettledSubscribersRef.current.forEach((cb) => cb());
|
|
6234
|
+
const exportPending = exportPendingSinceRef.current > 0 && Date.now() - exportPendingSinceRef.current < EXPORT_PENDING_MAX_MS;
|
|
6235
|
+
if (!exportPending && newestSettled >= getLastSentVersion()) markEditSettled();
|
|
6123
6236
|
}
|
|
6124
6237
|
} else if (due.size === 0 && hasBlobInFlightRef.current && !hasPendingBlobs() && !pipelineResetCooldownRef.current) {
|
|
6125
6238
|
hasBlobInFlightRef.current = false;
|
|
6126
6239
|
pipelineSettledSubscribersRef.current.forEach((cb) => cb());
|
|
6240
|
+
if (!(exportPendingSinceRef.current > 0 && Date.now() - exportPendingSinceRef.current < EXPORT_PENDING_MAX_MS)) markEditSettled();
|
|
6127
6241
|
}
|
|
6128
6242
|
},
|
|
6129
|
-
[hasPendingBlobs]
|
|
6243
|
+
[hasPendingBlobs, markEditSettled, getLastSentVersion]
|
|
6130
6244
|
);
|
|
6131
6245
|
const runComposite = useCallback10(
|
|
6132
6246
|
async (result) => {
|
|
@@ -6242,6 +6356,7 @@ function RealtimeProvider({
|
|
|
6242
6356
|
const sendCanvasBlob = useCallback10(
|
|
6243
6357
|
(placement, blob, mockupCount, baseThrottleMs) => {
|
|
6244
6358
|
blobQueuedGenRef.current = pipelineGenRef.current;
|
|
6359
|
+
exportPendingSinceRef.current = 0;
|
|
6245
6360
|
const result = sendCanvasBlobRaw(
|
|
6246
6361
|
placement,
|
|
6247
6362
|
blob,
|
|
@@ -6253,14 +6368,16 @@ function RealtimeProvider({
|
|
|
6253
6368
|
lastBlobSentTimeRef.current = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
6254
6369
|
isPendingMockupsRef.current = true;
|
|
6255
6370
|
pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
|
|
6371
|
+
markEditLive();
|
|
6256
6372
|
}
|
|
6257
6373
|
return result;
|
|
6258
6374
|
},
|
|
6259
|
-
[sendCanvasBlobRaw]
|
|
6375
|
+
[sendCanvasBlobRaw, markEditLive]
|
|
6260
6376
|
);
|
|
6261
6377
|
const sendCanvasState = useCallback10(
|
|
6262
6378
|
(placement, state, mockupCount, baseThrottleMs) => {
|
|
6263
6379
|
blobQueuedGenRef.current = pipelineGenRef.current;
|
|
6380
|
+
exportPendingSinceRef.current = 0;
|
|
6264
6381
|
const result = sendCanvasStateRaw(
|
|
6265
6382
|
placement,
|
|
6266
6383
|
state,
|
|
@@ -6273,15 +6390,16 @@ function RealtimeProvider({
|
|
|
6273
6390
|
isPendingMockupsRef.current = true;
|
|
6274
6391
|
const version = getLastSentVersion();
|
|
6275
6392
|
if (version > 0) {
|
|
6276
|
-
const configured = configuredMockupIdsRef.current.length;
|
|
6393
|
+
const configured = requestedMockupIdsRef.current.length || configuredMockupIdsRef.current.length;
|
|
6277
6394
|
const expected = Math.max(1, Math.min(configured || Infinity, mockupCount || Infinity));
|
|
6278
6395
|
dueByVersionRef.current.set(version, { due: Number.isFinite(expected) ? expected : 1, at: Date.now() });
|
|
6279
6396
|
}
|
|
6280
6397
|
pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
|
|
6398
|
+
markEditLive();
|
|
6281
6399
|
}
|
|
6282
6400
|
return result;
|
|
6283
6401
|
},
|
|
6284
|
-
[sendCanvasStateRaw, getLastSentVersion]
|
|
6402
|
+
[sendCanvasStateRaw, getLastSentVersion, markEditLive]
|
|
6285
6403
|
);
|
|
6286
6404
|
const sendColorBlobTracked = useCallback10(
|
|
6287
6405
|
(placement, color) => {
|
|
@@ -6346,22 +6464,24 @@ function RealtimeProvider({
|
|
|
6346
6464
|
});
|
|
6347
6465
|
}
|
|
6348
6466
|
configuredMockupIdsRef.current = mockupIds;
|
|
6467
|
+
const shape = currentShape();
|
|
6468
|
+
lastShapeRef.current = shape;
|
|
6349
6469
|
const configPayload = useSessionGrant ? {
|
|
6350
6470
|
productId,
|
|
6351
|
-
mockupIds,
|
|
6471
|
+
mockupIds: shape.mockupIds,
|
|
6352
6472
|
variantId,
|
|
6353
6473
|
shop,
|
|
6354
|
-
width:
|
|
6474
|
+
width: shape.width,
|
|
6355
6475
|
...mockupBg ? { bg: mockupBg } : {},
|
|
6356
6476
|
...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
|
|
6357
6477
|
placementSettings: { ...placementSettingsOverridesRef.current }
|
|
6358
6478
|
} : {
|
|
6359
6479
|
productId,
|
|
6360
|
-
mockupIds,
|
|
6480
|
+
mockupIds: shape.mockupIds,
|
|
6361
6481
|
variantId,
|
|
6362
6482
|
shop: "hTidnpNnNa",
|
|
6363
6483
|
seal: "bypass-sig-for-k6-load-test",
|
|
6364
|
-
width:
|
|
6484
|
+
width: shape.width,
|
|
6365
6485
|
...mockupBg ? { bg: mockupBg } : {},
|
|
6366
6486
|
...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
|
|
6367
6487
|
placementSettings: { ...placementSettingsOverridesRef.current }
|
|
@@ -6373,7 +6493,7 @@ function RealtimeProvider({
|
|
|
6373
6493
|
});
|
|
6374
6494
|
}
|
|
6375
6495
|
lastConfigBaseRef.current = configPayload;
|
|
6376
|
-
requestedMockupIdsRef.current = mockupIds;
|
|
6496
|
+
requestedMockupIdsRef.current = [...shape.mockupIds];
|
|
6377
6497
|
sendConfigRaw(
|
|
6378
6498
|
croppedActiveRef.current ? { ...configPayload, overlayCrop: "auto" } : configPayload
|
|
6379
6499
|
);
|
|
@@ -6399,6 +6519,7 @@ function RealtimeProvider({
|
|
|
6399
6519
|
sendConfigRaw,
|
|
6400
6520
|
sendColorBlobTracked,
|
|
6401
6521
|
invalidateBackgrounds,
|
|
6522
|
+
currentShape,
|
|
6402
6523
|
mockupWidth,
|
|
6403
6524
|
mockupBg,
|
|
6404
6525
|
spreadCropsVersion
|
|
@@ -6573,6 +6694,7 @@ function RealtimeProvider({
|
|
|
6573
6694
|
);
|
|
6574
6695
|
const notifyPendingExport = useCallback10(
|
|
6575
6696
|
(placement) => {
|
|
6697
|
+
exportPendingSinceRef.current = Date.now();
|
|
6576
6698
|
if (pendingPlacementsRef.current.has(placement)) {
|
|
6577
6699
|
return;
|
|
6578
6700
|
}
|
|
@@ -6588,11 +6710,14 @@ function RealtimeProvider({
|
|
|
6588
6710
|
}
|
|
6589
6711
|
console.log(`[RTP] notifyPendingExport("${placement}"): marked ${pendingIds.length} mockup(s) pending \u2014 [${pendingIds.slice(0, 5).join(", ")}${pendingIds.length > 5 ? "..." : ""}]`);
|
|
6590
6712
|
pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
|
|
6713
|
+
markEditLive();
|
|
6591
6714
|
},
|
|
6592
|
-
[productContext?.product?.mockups]
|
|
6715
|
+
[productContext?.product?.mockups, markEditLive]
|
|
6593
6716
|
);
|
|
6594
6717
|
const notifyPendingExportCancelled = useCallback10(
|
|
6595
6718
|
(placement) => {
|
|
6719
|
+
exportPendingSinceRef.current = 0;
|
|
6720
|
+
markEditSettled();
|
|
6596
6721
|
if (!pendingPlacementsRef.current.has(placement)) {
|
|
6597
6722
|
return;
|
|
6598
6723
|
}
|
|
@@ -6613,7 +6738,7 @@ function RealtimeProvider({
|
|
|
6613
6738
|
);
|
|
6614
6739
|
pendingExportCancelledSubscribersRef.current.forEach((cb) => cb(placement));
|
|
6615
6740
|
},
|
|
6616
|
-
[productContext?.product?.mockups]
|
|
6741
|
+
[productContext?.product?.mockups, markEditSettled]
|
|
6617
6742
|
);
|
|
6618
6743
|
const getMockupUrl3 = useCallback10((mockupId) => {
|
|
6619
6744
|
if (pendingMockupIdsRef.current.has(mockupId)) {
|
|
@@ -6696,6 +6821,20 @@ function RealtimeProvider({
|
|
|
6696
6821
|
const getLatestSentVersionsRef = useRef12(getLatestSentVersions);
|
|
6697
6822
|
getLatestSentVersionsRef.current = getLatestSentVersions;
|
|
6698
6823
|
const getLatestSentVersionsStable = useCallback10(() => getLatestSentVersionsRef.current?.() ?? {}, []);
|
|
6824
|
+
const reportPictureView = useCallback10((elementKey, view) => {
|
|
6825
|
+
const views = pictureViewsRef.current;
|
|
6826
|
+
if (view) views.set(elementKey, view);
|
|
6827
|
+
else views.delete(elementKey);
|
|
6828
|
+
if (shapeApplyTimerRef.current) return;
|
|
6829
|
+
shapeApplyTimerRef.current = setTimeout(() => {
|
|
6830
|
+
shapeApplyTimerRef.current = null;
|
|
6831
|
+
applySessionShapeRef.current?.();
|
|
6832
|
+
}, 100);
|
|
6833
|
+
}, []);
|
|
6834
|
+
const getSessionShape = useCallback10(() => {
|
|
6835
|
+
const s = lastShapeRef.current;
|
|
6836
|
+
return s ? { phase: s.phase, width: s.width } : null;
|
|
6837
|
+
}, []);
|
|
6699
6838
|
const stableSubscribePipelineSettled = useCallback10(
|
|
6700
6839
|
(callback) => {
|
|
6701
6840
|
return subscribePipelineSettledRef.current(callback);
|
|
@@ -6746,6 +6885,9 @@ function RealtimeProvider({
|
|
|
6746
6885
|
getMockupUrls,
|
|
6747
6886
|
getCanvasVersion,
|
|
6748
6887
|
getLatestSentVersions: getLatestSentVersionsStable,
|
|
6888
|
+
reportPictureView,
|
|
6889
|
+
getSessionShape,
|
|
6890
|
+
setEditorOpen: setEditorOpenState,
|
|
6749
6891
|
isMockupLoading,
|
|
6750
6892
|
registerBlobUrl,
|
|
6751
6893
|
markBlobShown,
|
|
@@ -6781,6 +6923,8 @@ function RealtimeProvider({
|
|
|
6781
6923
|
getMockupUrls,
|
|
6782
6924
|
getCanvasVersion,
|
|
6783
6925
|
getLatestSentVersionsStable,
|
|
6926
|
+
reportPictureView,
|
|
6927
|
+
getSessionShape,
|
|
6784
6928
|
isMockupLoading,
|
|
6785
6929
|
registerBlobUrl,
|
|
6786
6930
|
markBlobShown,
|
|
@@ -10375,7 +10519,8 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10375
10519
|
darkShimmerFadeInDuration = 300,
|
|
10376
10520
|
emptyText = "No artwork",
|
|
10377
10521
|
errorText = "Error loading",
|
|
10378
|
-
unavailableText = "Preview unavailable"
|
|
10522
|
+
unavailableText = "Preview unavailable",
|
|
10523
|
+
viewportPolicy = false
|
|
10379
10524
|
}) {
|
|
10380
10525
|
const context = useProductOptional();
|
|
10381
10526
|
const designContext = useDesignOptional();
|
|
@@ -10605,6 +10750,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10605
10750
|
const sessionErrorCodeRef = useRef23(null);
|
|
10606
10751
|
sessionErrorCodeRef.current = realtimeContext?.renderError?.code ?? null;
|
|
10607
10752
|
const getCanvasVersion = realtimeContext?.getCanvasVersion;
|
|
10753
|
+
const getSessionShape = realtimeContext?.getSessionShape;
|
|
10608
10754
|
const applyRenderStamp = useCallback18(() => {
|
|
10609
10755
|
const node = containerRef.current;
|
|
10610
10756
|
if (!node) return;
|
|
@@ -10625,7 +10771,14 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10625
10771
|
if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
|
|
10626
10772
|
else delete node.dataset.frameError;
|
|
10627
10773
|
node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
|
|
10628
|
-
|
|
10774
|
+
const img = node.querySelector("img");
|
|
10775
|
+
if (img?.naturalWidth) node.dataset.renderWidth = String(img.naturalWidth);
|
|
10776
|
+
const shape = getSessionShape?.();
|
|
10777
|
+
if (shape) {
|
|
10778
|
+
node.dataset.wantedWidth = String(shape.width);
|
|
10779
|
+
node.dataset.sessionPhase = shape.phase;
|
|
10780
|
+
}
|
|
10781
|
+
}, [getCanvasVersion, getLatestSentVersions, getSessionShape]);
|
|
10629
10782
|
const applyRenderStampRef = useRef23(applyRenderStamp);
|
|
10630
10783
|
applyRenderStampRef.current = applyRenderStamp;
|
|
10631
10784
|
useEffect32(() => {
|
|
@@ -10657,6 +10810,39 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10657
10810
|
realtimeContext?.subscribeMockupResultById,
|
|
10658
10811
|
applyRenderStamp
|
|
10659
10812
|
]);
|
|
10813
|
+
const reportPictureView = realtimeContext?.reportPictureView;
|
|
10814
|
+
useEffect32(() => {
|
|
10815
|
+
if (!viewportPolicy || !reportPictureView || !actualMockupId) return;
|
|
10816
|
+
const node = containerRef.current;
|
|
10817
|
+
if (!node || typeof IntersectionObserver === "undefined") return;
|
|
10818
|
+
let inSet = false;
|
|
10819
|
+
const key = `${actualMockupId}#${Math.random().toString(36).slice(2, 9)}`;
|
|
10820
|
+
const report = () => {
|
|
10821
|
+
const r = node.getBoundingClientRect();
|
|
10822
|
+
const onScreen = r.width > 0 && r.right > 0 && r.left < window.innerWidth && r.bottom > 0 && r.top < window.innerHeight;
|
|
10823
|
+
reportPictureView(key, {
|
|
10824
|
+
mockupId: actualMockupId,
|
|
10825
|
+
inSet: inSet || onScreen,
|
|
10826
|
+
onScreen,
|
|
10827
|
+
devicePx: Math.round(r.width * (window.devicePixelRatio || 1))
|
|
10828
|
+
});
|
|
10829
|
+
};
|
|
10830
|
+
const io = new IntersectionObserver(
|
|
10831
|
+
(entries) => {
|
|
10832
|
+
inSet = entries.some((e) => e.isIntersecting);
|
|
10833
|
+
report();
|
|
10834
|
+
},
|
|
10835
|
+
{ rootMargin: "0px 100% 0px 100%" }
|
|
10836
|
+
);
|
|
10837
|
+
io.observe(node);
|
|
10838
|
+
const onResize = () => report();
|
|
10839
|
+
window.addEventListener("resize", onResize);
|
|
10840
|
+
return () => {
|
|
10841
|
+
io.disconnect();
|
|
10842
|
+
window.removeEventListener("resize", onResize);
|
|
10843
|
+
reportPictureView(key, null);
|
|
10844
|
+
};
|
|
10845
|
+
}, [viewportPolicy, reportPictureView, actualMockupId]);
|
|
10660
10846
|
useEffect32(() => {
|
|
10661
10847
|
if (!priorityContext || !actualMockupId || !placement) return;
|
|
10662
10848
|
priorityContext.registerMockup(actualMockupId, placement, initialPriority);
|
|
@@ -13056,7 +13242,8 @@ var MobileProductCarousel = memo4(function MobileProductCarousel2({
|
|
|
13056
13242
|
onUrlGenerated: image.mockupId ? (url) => handleUrlGenerated(image.mockupId, url) : void 0,
|
|
13057
13243
|
errorText,
|
|
13058
13244
|
unavailableText,
|
|
13059
|
-
className: "w-full h-full object-cover cursor-pointer pointer-events-none"
|
|
13245
|
+
className: "w-full h-full object-cover cursor-pointer pointer-events-none",
|
|
13246
|
+
viewportPolicy: true
|
|
13060
13247
|
}
|
|
13061
13248
|
) : image.isRealMockup && !currentArtwork ? /* @__PURE__ */ jsx74(LoadingOverlayPrismCandyInline, { visible: true, variant: "light" }) : /* @__PURE__ */ jsx74(
|
|
13062
13249
|
StaticCarouselImage,
|