@snowcone-app/ui 0.9.8 → 0.10.0

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/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,7 @@ 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;
5709
5745
  function mergeMockupIds(current, extra) {
5710
5746
  const out = [...current];
5711
5747
  for (const id of extra) if (!out.includes(id)) out.push(id);
@@ -5724,7 +5760,8 @@ function RealtimeProvider({
5724
5760
  shop,
5725
5761
  grantUrl,
5726
5762
  initialGrant,
5727
- delivery = "cropped"
5763
+ delivery = "cropped",
5764
+ editorOpen = true
5728
5765
  }) {
5729
5766
  const productContext = useProductOptional();
5730
5767
  const mockupBg = useMockupBackgroundOptional();
@@ -5865,6 +5902,18 @@ function RealtimeProvider({
5865
5902
  const compositeBusyRef = useRef12(/* @__PURE__ */ new Set());
5866
5903
  const compositeCanvasRef = useRef12(null);
5867
5904
  const requestedMockupIdsRef = useRef12([]);
5905
+ const pictureViewsRef = useRef12(/* @__PURE__ */ new Map());
5906
+ const editLiveRef = useRef12(false);
5907
+ const editQuietTimerRef = useRef12(null);
5908
+ const shapeApplyTimerRef = useRef12(null);
5909
+ const lastShapeRef = useRef12(null);
5910
+ const applySessionShapeRef = useRef12(null);
5911
+ const [editorOpenState, setEditorOpenState] = useState17(editorOpen);
5912
+ useEffect17(() => setEditorOpenState(editorOpen), [editorOpen]);
5913
+ const editorOpenRef = useRef12(editorOpenState);
5914
+ editorOpenRef.current = editorOpenState;
5915
+ const heroWidthRef = useRef12(mockupWidth);
5916
+ heroWidthRef.current = mockupWidth;
5868
5917
  const serverStampsVersionsRef = useRef12(false);
5869
5918
  const pendingRerenderRef = useRef12([]);
5870
5919
  const forceRerenderByConfigRef = useRef12(null);
@@ -6055,6 +6104,64 @@ function RealtimeProvider({
6055
6104
  compositeQueueRef.current.clear();
6056
6105
  croppedActiveRef.current = false;
6057
6106
  }, []);
6107
+ const currentShape = useCallback10(
6108
+ () => sessionShape({
6109
+ allMockupIds: configuredMockupIdsRef.current,
6110
+ views: pictureViewsRef.current,
6111
+ heroWidth: heroWidthRef.current,
6112
+ editorOpen: editorOpenRef.current,
6113
+ editLive: editLiveRef.current
6114
+ }),
6115
+ []
6116
+ );
6117
+ const applySessionShape = useCallback10(() => {
6118
+ const base = lastConfigBaseRef.current;
6119
+ if (!base || !configSentRef.current) return;
6120
+ const shape = currentShape();
6121
+ if (sameShape(lastShapeRef.current, shape)) {
6122
+ lastShapeRef.current = shape;
6123
+ return;
6124
+ }
6125
+ if (lastShapeRef.current && lastShapeRef.current.width !== shape.width) invalidateBackgrounds();
6126
+ lastShapeRef.current = shape;
6127
+ base.mockupIds = shape.mockupIds;
6128
+ base.width = shape.width;
6129
+ requestedMockupIdsRef.current = [...shape.mockupIds];
6130
+ sendConfigRaw({
6131
+ ...base,
6132
+ placementSettings: { ...placementSettingsOverridesRef.current },
6133
+ ...croppedActiveRef.current ? { overlayCrop: "auto" } : {}
6134
+ });
6135
+ }, [currentShape, invalidateBackgrounds, sendConfigRaw]);
6136
+ applySessionShapeRef.current = applySessionShape;
6137
+ const markEditLive = useCallback10(() => {
6138
+ if (editQuietTimerRef.current) {
6139
+ clearTimeout(editQuietTimerRef.current);
6140
+ editQuietTimerRef.current = null;
6141
+ }
6142
+ if (editLiveRef.current) return;
6143
+ editLiveRef.current = true;
6144
+ applySessionShapeRef.current?.();
6145
+ }, []);
6146
+ const markEditSettled = useCallback10(() => {
6147
+ if (!editLiveRef.current) return;
6148
+ if (editQuietTimerRef.current) clearTimeout(editQuietTimerRef.current);
6149
+ editQuietTimerRef.current = setTimeout(() => {
6150
+ editQuietTimerRef.current = null;
6151
+ editLiveRef.current = false;
6152
+ applySessionShapeRef.current?.();
6153
+ }, EDIT_QUIET_MS);
6154
+ }, []);
6155
+ useEffect17(() => {
6156
+ applySessionShapeRef.current?.();
6157
+ }, [editorOpenState]);
6158
+ useEffect17(
6159
+ () => () => {
6160
+ if (editQuietTimerRef.current) clearTimeout(editQuietTimerRef.current);
6161
+ if (shapeApplyTimerRef.current) clearTimeout(shapeApplyTimerRef.current);
6162
+ },
6163
+ []
6164
+ );
6058
6165
  const deliverResults = useCallback10(
6059
6166
  (results) => {
6060
6167
  if (results.length === 0) return;
@@ -6120,13 +6227,15 @@ function RealtimeProvider({
6120
6227
  if (!pipelineResetCooldownRef.current) {
6121
6228
  hasBlobInFlightRef.current = false;
6122
6229
  for (let i = 0; i < settledVersions; i++) pipelineSettledSubscribersRef.current.forEach((cb) => cb());
6230
+ markEditSettled();
6123
6231
  }
6124
6232
  } else if (due.size === 0 && hasBlobInFlightRef.current && !hasPendingBlobs() && !pipelineResetCooldownRef.current) {
6125
6233
  hasBlobInFlightRef.current = false;
6126
6234
  pipelineSettledSubscribersRef.current.forEach((cb) => cb());
6235
+ markEditSettled();
6127
6236
  }
6128
6237
  },
6129
- [hasPendingBlobs]
6238
+ [hasPendingBlobs, markEditSettled]
6130
6239
  );
6131
6240
  const runComposite = useCallback10(
6132
6241
  async (result) => {
@@ -6253,10 +6362,11 @@ function RealtimeProvider({
6253
6362
  lastBlobSentTimeRef.current = (/* @__PURE__ */ new Date()).toLocaleTimeString();
6254
6363
  isPendingMockupsRef.current = true;
6255
6364
  pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
6365
+ markEditLive();
6256
6366
  }
6257
6367
  return result;
6258
6368
  },
6259
- [sendCanvasBlobRaw]
6369
+ [sendCanvasBlobRaw, markEditLive]
6260
6370
  );
6261
6371
  const sendCanvasState = useCallback10(
6262
6372
  (placement, state, mockupCount, baseThrottleMs) => {
@@ -6273,15 +6383,16 @@ function RealtimeProvider({
6273
6383
  isPendingMockupsRef.current = true;
6274
6384
  const version = getLastSentVersion();
6275
6385
  if (version > 0) {
6276
- const configured = configuredMockupIdsRef.current.length;
6386
+ const configured = requestedMockupIdsRef.current.length || configuredMockupIdsRef.current.length;
6277
6387
  const expected = Math.max(1, Math.min(configured || Infinity, mockupCount || Infinity));
6278
6388
  dueByVersionRef.current.set(version, { due: Number.isFinite(expected) ? expected : 1, at: Date.now() });
6279
6389
  }
6280
6390
  pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
6391
+ markEditLive();
6281
6392
  }
6282
6393
  return result;
6283
6394
  },
6284
- [sendCanvasStateRaw, getLastSentVersion]
6395
+ [sendCanvasStateRaw, getLastSentVersion, markEditLive]
6285
6396
  );
6286
6397
  const sendColorBlobTracked = useCallback10(
6287
6398
  (placement, color) => {
@@ -6346,22 +6457,24 @@ function RealtimeProvider({
6346
6457
  });
6347
6458
  }
6348
6459
  configuredMockupIdsRef.current = mockupIds;
6460
+ const shape = currentShape();
6461
+ lastShapeRef.current = shape;
6349
6462
  const configPayload = useSessionGrant ? {
6350
6463
  productId,
6351
- mockupIds,
6464
+ mockupIds: shape.mockupIds,
6352
6465
  variantId,
6353
6466
  shop,
6354
- width: mockupWidth,
6467
+ width: shape.width,
6355
6468
  ...mockupBg ? { bg: mockupBg } : {},
6356
6469
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6357
6470
  placementSettings: { ...placementSettingsOverridesRef.current }
6358
6471
  } : {
6359
6472
  productId,
6360
- mockupIds,
6473
+ mockupIds: shape.mockupIds,
6361
6474
  variantId,
6362
6475
  shop: "hTidnpNnNa",
6363
6476
  seal: "bypass-sig-for-k6-load-test",
6364
- width: mockupWidth,
6477
+ width: shape.width,
6365
6478
  ...mockupBg ? { bg: mockupBg } : {},
6366
6479
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6367
6480
  placementSettings: { ...placementSettingsOverridesRef.current }
@@ -6373,7 +6486,7 @@ function RealtimeProvider({
6373
6486
  });
6374
6487
  }
6375
6488
  lastConfigBaseRef.current = configPayload;
6376
- requestedMockupIdsRef.current = mockupIds;
6489
+ requestedMockupIdsRef.current = [...shape.mockupIds];
6377
6490
  sendConfigRaw(
6378
6491
  croppedActiveRef.current ? { ...configPayload, overlayCrop: "auto" } : configPayload
6379
6492
  );
@@ -6399,6 +6512,7 @@ function RealtimeProvider({
6399
6512
  sendConfigRaw,
6400
6513
  sendColorBlobTracked,
6401
6514
  invalidateBackgrounds,
6515
+ currentShape,
6402
6516
  mockupWidth,
6403
6517
  mockupBg,
6404
6518
  spreadCropsVersion
@@ -6588,8 +6702,9 @@ function RealtimeProvider({
6588
6702
  }
6589
6703
  console.log(`[RTP] notifyPendingExport("${placement}"): marked ${pendingIds.length} mockup(s) pending \u2014 [${pendingIds.slice(0, 5).join(", ")}${pendingIds.length > 5 ? "..." : ""}]`);
6590
6704
  pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
6705
+ markEditLive();
6591
6706
  },
6592
- [productContext?.product?.mockups]
6707
+ [productContext?.product?.mockups, markEditLive]
6593
6708
  );
6594
6709
  const notifyPendingExportCancelled = useCallback10(
6595
6710
  (placement) => {
@@ -6696,6 +6811,20 @@ function RealtimeProvider({
6696
6811
  const getLatestSentVersionsRef = useRef12(getLatestSentVersions);
6697
6812
  getLatestSentVersionsRef.current = getLatestSentVersions;
6698
6813
  const getLatestSentVersionsStable = useCallback10(() => getLatestSentVersionsRef.current?.() ?? {}, []);
6814
+ const reportPictureView = useCallback10((elementKey, view) => {
6815
+ const views = pictureViewsRef.current;
6816
+ if (view) views.set(elementKey, view);
6817
+ else views.delete(elementKey);
6818
+ if (shapeApplyTimerRef.current) return;
6819
+ shapeApplyTimerRef.current = setTimeout(() => {
6820
+ shapeApplyTimerRef.current = null;
6821
+ applySessionShapeRef.current?.();
6822
+ }, 100);
6823
+ }, []);
6824
+ const getSessionShape = useCallback10(() => {
6825
+ const s = lastShapeRef.current;
6826
+ return s ? { phase: s.phase, width: s.width } : null;
6827
+ }, []);
6699
6828
  const stableSubscribePipelineSettled = useCallback10(
6700
6829
  (callback) => {
6701
6830
  return subscribePipelineSettledRef.current(callback);
@@ -6746,6 +6875,9 @@ function RealtimeProvider({
6746
6875
  getMockupUrls,
6747
6876
  getCanvasVersion,
6748
6877
  getLatestSentVersions: getLatestSentVersionsStable,
6878
+ reportPictureView,
6879
+ getSessionShape,
6880
+ setEditorOpen: setEditorOpenState,
6749
6881
  isMockupLoading,
6750
6882
  registerBlobUrl,
6751
6883
  markBlobShown,
@@ -6781,6 +6913,8 @@ function RealtimeProvider({
6781
6913
  getMockupUrls,
6782
6914
  getCanvasVersion,
6783
6915
  getLatestSentVersionsStable,
6916
+ reportPictureView,
6917
+ getSessionShape,
6784
6918
  isMockupLoading,
6785
6919
  registerBlobUrl,
6786
6920
  markBlobShown,
@@ -10375,7 +10509,8 @@ var HeroProductImage = memo3(function HeroProductImage2({
10375
10509
  darkShimmerFadeInDuration = 300,
10376
10510
  emptyText = "No artwork",
10377
10511
  errorText = "Error loading",
10378
- unavailableText = "Preview unavailable"
10512
+ unavailableText = "Preview unavailable",
10513
+ viewportPolicy = false
10379
10514
  }) {
10380
10515
  const context = useProductOptional();
10381
10516
  const designContext = useDesignOptional();
@@ -10605,6 +10740,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
10605
10740
  const sessionErrorCodeRef = useRef23(null);
10606
10741
  sessionErrorCodeRef.current = realtimeContext?.renderError?.code ?? null;
10607
10742
  const getCanvasVersion = realtimeContext?.getCanvasVersion;
10743
+ const getSessionShape = realtimeContext?.getSessionShape;
10608
10744
  const applyRenderStamp = useCallback18(() => {
10609
10745
  const node = containerRef.current;
10610
10746
  if (!node) return;
@@ -10625,7 +10761,14 @@ var HeroProductImage = memo3(function HeroProductImage2({
10625
10761
  if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
10626
10762
  else delete node.dataset.frameError;
10627
10763
  node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
10628
- }, [getCanvasVersion, getLatestSentVersions]);
10764
+ const img = node.querySelector("img");
10765
+ if (img?.naturalWidth) node.dataset.renderWidth = String(img.naturalWidth);
10766
+ const shape = getSessionShape?.();
10767
+ if (shape) {
10768
+ node.dataset.wantedWidth = String(shape.width);
10769
+ node.dataset.sessionPhase = shape.phase;
10770
+ }
10771
+ }, [getCanvasVersion, getLatestSentVersions, getSessionShape]);
10629
10772
  const applyRenderStampRef = useRef23(applyRenderStamp);
10630
10773
  applyRenderStampRef.current = applyRenderStamp;
10631
10774
  useEffect32(() => {
@@ -10657,6 +10800,39 @@ var HeroProductImage = memo3(function HeroProductImage2({
10657
10800
  realtimeContext?.subscribeMockupResultById,
10658
10801
  applyRenderStamp
10659
10802
  ]);
10803
+ const reportPictureView = realtimeContext?.reportPictureView;
10804
+ useEffect32(() => {
10805
+ if (!viewportPolicy || !reportPictureView || !actualMockupId) return;
10806
+ const node = containerRef.current;
10807
+ if (!node || typeof IntersectionObserver === "undefined") return;
10808
+ let inSet = false;
10809
+ const key = `${actualMockupId}#${Math.random().toString(36).slice(2, 9)}`;
10810
+ const report = () => {
10811
+ const r = node.getBoundingClientRect();
10812
+ const onScreen = r.width > 0 && r.right > 0 && r.left < window.innerWidth && r.bottom > 0 && r.top < window.innerHeight;
10813
+ reportPictureView(key, {
10814
+ mockupId: actualMockupId,
10815
+ inSet: inSet || onScreen,
10816
+ onScreen,
10817
+ devicePx: Math.round(r.width * (window.devicePixelRatio || 1))
10818
+ });
10819
+ };
10820
+ const io = new IntersectionObserver(
10821
+ (entries) => {
10822
+ inSet = entries.some((e) => e.isIntersecting);
10823
+ report();
10824
+ },
10825
+ { rootMargin: "0px 100% 0px 100%" }
10826
+ );
10827
+ io.observe(node);
10828
+ const onResize = () => report();
10829
+ window.addEventListener("resize", onResize);
10830
+ return () => {
10831
+ io.disconnect();
10832
+ window.removeEventListener("resize", onResize);
10833
+ reportPictureView(key, null);
10834
+ };
10835
+ }, [viewportPolicy, reportPictureView, actualMockupId]);
10660
10836
  useEffect32(() => {
10661
10837
  if (!priorityContext || !actualMockupId || !placement) return;
10662
10838
  priorityContext.registerMockup(actualMockupId, placement, initialPriority);
@@ -13056,7 +13232,8 @@ var MobileProductCarousel = memo4(function MobileProductCarousel2({
13056
13232
  onUrlGenerated: image.mockupId ? (url) => handleUrlGenerated(image.mockupId, url) : void 0,
13057
13233
  errorText,
13058
13234
  unavailableText,
13059
- className: "w-full h-full object-cover cursor-pointer pointer-events-none"
13235
+ className: "w-full h-full object-cover cursor-pointer pointer-events-none",
13236
+ viewportPolicy: true
13060
13237
  }
13061
13238
  ) : image.isRealMockup && !currentArtwork ? /* @__PURE__ */ jsx74(LoadingOverlayPrismCandyInline, { visible: true, variant: "light" }) : /* @__PURE__ */ jsx74(
13062
13239
  StaticCarouselImage,