@snowcone-app/ui 0.9.7 → 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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#4396](https://github.com/snowcone-app/snowcone-monorepo/pull/4396) [`3c6ad17`](https://github.com/snowcone-app/snowcone-monorepo/commit/3c6ad17727f576ea82945605c50b9786abf7e65c) Thanks [@kevinsproles](https://github.com/kevinsproles)! - Phone viewport policy for live pictures: a gallery that opts in (`HeroProductImage viewportPolicy`, set by `MobileProductCarousel`) reports what is in view, and the realtime session then renders, while an edit is live, only the pictures in view (+ neighbours) at the width the screen shows them (CSS width × dpr rounded up to a ladder step); when the edit stops, every picture at that width (one catch-up config, cancelled by a new edit); on Done (`setEditorOpen(false)` / `editorOpen`), the picture on screen at `mockupWidth`. One config per change of shape. Pictures carry `data-render-width`, `data-wanted-width` and `data-session-phase`. Without an opted-in gallery (desktop) nothing changes.
8
+
9
+ ## 0.9.8
10
+
11
+ ### Patch Changes
12
+
13
+ - [#4403](https://github.com/snowcone-app/snowcone-monorepo/pull/4403) [`9214d20`](https://github.com/snowcone-app/snowcone-monorepo/commit/9214d20624e19ffbb9e2cb9ac4965d9466d06fee) Thanks [@kevinsproles](https://github.com/kevinsproles)! - A composited frame is released only when EVERY element showing that picture has moved past it (`markBlobShown(mockupId, url, consumer)`, `releaseBlobConsumer` on unmount). The phone product page renders each picture twice; releasing on the first element's load revoked the frame its twin was still loading, so the twin kept its old image.
14
+
15
+ - [#4415](https://github.com/snowcone-app/snowcone-monorepo/pull/4415) [`ccc4cf3`](https://github.com/snowcone-app/snowcone-monorepo/commit/ccc4cf371c5f4845e679b8c295e0335881664e96) Thanks [@kevinsproles](https://github.com/kevinsproles)! - The SDK reports `isFrameSuperseded(url)`: true once a newer ws frame for the same mockup has arrived and the old one was revoked. The UI uses it when a cropped frame fails to load: a superseded frame is dropped at once instead of waiting on the 2 s grace, which a 31-picture batch can outlast (React only sees the newer frame with the batch's `all_mockups_rendered`). Before, the grace fired first, cropped delivery went off for the session and a visible picture could stay one version behind.
16
+
17
+ `all_mockups_rendered` now merges its batch into `mockupResults` instead of replacing it. A short batch (a `rerender` answer) landing right after a full one replaced it, React coalesced the two updates, and every other picture kept its previous version.
18
+
19
+ - Updated dependencies [[`ccc4cf3`](https://github.com/snowcone-app/snowcone-monorepo/commit/ccc4cf371c5f4845e679b8c295e0335881664e96)]:
20
+ - @snowcone-app/sdk@0.26.0
21
+
3
22
  ## 0.9.7
4
23
 
5
24
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -5997,6 +5997,41 @@ function useMockupBackgroundOptional() {
5997
5997
  return (0, import_react24.useContext)(MockupBackgroundContext);
5998
5998
  }
5999
5999
 
6000
+ // src/patterns/sessionShape.ts
6001
+ var WIDTH_LADDER = [400, 600, 800, 1e3, 1200, 1600, 2e3, 3e3, 4e3];
6002
+ function ladderWidth(devicePx) {
6003
+ for (const w of WIDTH_LADDER) if (w >= devicePx) return w;
6004
+ return WIDTH_LADDER[WIDTH_LADDER.length - 1];
6005
+ }
6006
+ function sessionShape(input) {
6007
+ const { allMockupIds, views, heroWidth, editorOpen, editLive } = input;
6008
+ if (views.size === 0) return { mockupIds: [...allMockupIds], width: heroWidth, phase: "no-policy" };
6009
+ const byMockup = /* @__PURE__ */ new Map();
6010
+ views.forEach((v, key) => {
6011
+ const id = v.mockupId ?? key;
6012
+ const prev = byMockup.get(id);
6013
+ 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 });
6014
+ });
6015
+ const ordered = (pick) => allMockupIds.filter((id) => {
6016
+ const v = byMockup.get(id);
6017
+ return v ? pick(v) : false;
6018
+ });
6019
+ const inSet = ordered((v) => v.inSet);
6020
+ const onScreen = ordered((v) => v.onScreen);
6021
+ const shown = [...byMockup.values()].filter((v) => v.inSet && v.devicePx > 0).map((v) => v.devicePx);
6022
+ const editingWidth = shown.length ? ladderWidth(Math.max(...shown)) : heroWidth;
6023
+ if (!editorOpen) {
6024
+ const set = onScreen.length ? onScreen : inSet;
6025
+ return { mockupIds: set.length ? set : [...allMockupIds], width: heroWidth, phase: "done" };
6026
+ }
6027
+ if (editLive && inSet.length) return { mockupIds: inSet, width: editingWidth, phase: "editing" };
6028
+ return { mockupIds: [...allMockupIds], width: editingWidth, phase: "catch-up" };
6029
+ }
6030
+ function sameShape(a, b) {
6031
+ if (!a) return false;
6032
+ return a.width === b.width && [...a.mockupIds].sort().join(",") === [...b.mockupIds].sort().join(",");
6033
+ }
6034
+
6000
6035
  // src/patterns/croppedFrameComposite.ts
6001
6036
  var COMPOSITE_QUALITY = 0.92;
6002
6037
  function isFullRect(rect) {
@@ -6065,6 +6100,7 @@ var MAX_CONCURRENT_BLOBS = 5;
6065
6100
  var MAX_FRAMES_PER_PICTURE = 3;
6066
6101
  var FRAME_SUPERSEDE_GRACE_MS = 2e3;
6067
6102
  var RERENDER_MIN_INTERVAL_MS = 550;
6103
+ var EDIT_QUIET_MS = 600;
6068
6104
  function mergeMockupIds(current, extra) {
6069
6105
  const out = [...current];
6070
6106
  for (const id of extra) if (!out.includes(id)) out.push(id);
@@ -6083,7 +6119,8 @@ function RealtimeProvider({
6083
6119
  shop,
6084
6120
  grantUrl,
6085
6121
  initialGrant,
6086
- delivery = "cropped"
6122
+ delivery = "cropped",
6123
+ editorOpen = true
6087
6124
  }) {
6088
6125
  const productContext = useProductOptional();
6089
6126
  const mockupBg = useMockupBackgroundOptional();
@@ -6181,8 +6218,11 @@ function RealtimeProvider({
6181
6218
  hasPendingBlobs,
6182
6219
  getLastSentVersion,
6183
6220
  getLatestSentVersions,
6184
- rerender: rerenderRaw
6221
+ rerender: rerenderRaw,
6222
+ isFrameSuperseded
6185
6223
  } = realtimeMockup;
6224
+ const isFrameSupersededRef = (0, import_react25.useRef)(isFrameSuperseded);
6225
+ isFrameSupersededRef.current = isFrameSuperseded;
6186
6226
  const mockupResultsRef = (0, import_react25.useRef)([]);
6187
6227
  const mockupSubscribersRef = (0, import_react25.useRef)(
6188
6228
  /* @__PURE__ */ new Set()
@@ -6221,6 +6261,18 @@ function RealtimeProvider({
6221
6261
  const compositeBusyRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
6222
6262
  const compositeCanvasRef = (0, import_react25.useRef)(null);
6223
6263
  const requestedMockupIdsRef = (0, import_react25.useRef)([]);
6264
+ const pictureViewsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
6265
+ const editLiveRef = (0, import_react25.useRef)(false);
6266
+ const editQuietTimerRef = (0, import_react25.useRef)(null);
6267
+ const shapeApplyTimerRef = (0, import_react25.useRef)(null);
6268
+ const lastShapeRef = (0, import_react25.useRef)(null);
6269
+ const applySessionShapeRef = (0, import_react25.useRef)(null);
6270
+ const [editorOpenState, setEditorOpenState] = (0, import_react25.useState)(editorOpen);
6271
+ (0, import_react25.useEffect)(() => setEditorOpenState(editorOpen), [editorOpen]);
6272
+ const editorOpenRef = (0, import_react25.useRef)(editorOpenState);
6273
+ editorOpenRef.current = editorOpenState;
6274
+ const heroWidthRef = (0, import_react25.useRef)(mockupWidth);
6275
+ heroWidthRef.current = mockupWidth;
6224
6276
  const serverStampsVersionsRef = (0, import_react25.useRef)(false);
6225
6277
  const pendingRerenderRef = (0, import_react25.useRef)([]);
6226
6278
  const forceRerenderByConfigRef = (0, import_react25.useRef)(null);
@@ -6248,9 +6300,9 @@ function RealtimeProvider({
6248
6300
  const url = URL.createObjectURL(blobOrUrl);
6249
6301
  if (owner) {
6250
6302
  const list = [url, ...blobsByOwnerRef.current.get(owner) ?? []];
6251
- const shown = shownBlobByOwnerRef.current.get(owner);
6303
+ const shown = new Set(shownBlobByOwnerRef.current.get(owner)?.values() ?? []);
6252
6304
  while (list.length > MAX_FRAMES_PER_PICTURE) {
6253
- const victimIdx = [...list.keys()].reverse().find((i) => i > 0 && list[i] !== shown);
6305
+ const victimIdx = [...list.keys()].reverse().find((i) => i > 0 && !shown.has(list[i]));
6254
6306
  if (victimIdx === void 0) break;
6255
6307
  const [victim] = list.splice(victimIdx, 1);
6256
6308
  console.error(
@@ -6268,15 +6320,28 @@ function RealtimeProvider({
6268
6320
  registeredBlobUrlsRef.current.add(url);
6269
6321
  return url;
6270
6322
  }, [revokeBlobUrl]);
6271
- const markBlobShown = (0, import_react25.useCallback)((owner, url) => {
6323
+ const releaseOlderFrames = (0, import_react25.useCallback)((owner) => {
6272
6324
  const list = blobsByOwnerRef.current.get(owner);
6273
- if (!list) return;
6274
- const idx = list.indexOf(url);
6275
- if (idx < 0) return;
6276
- shownBlobByOwnerRef.current.set(owner, url);
6277
- list.slice(idx + 1).forEach(revokeBlobUrl);
6278
- blobsByOwnerRef.current.set(owner, list.slice(0, idx + 1));
6325
+ const shown = shownBlobByOwnerRef.current.get(owner);
6326
+ if (!list || !shown || shown.size === 0) return;
6327
+ const oldestShownIdx = Math.max(...[...shown.values()].map((u) => list.indexOf(u)));
6328
+ if (oldestShownIdx < 0) return;
6329
+ list.slice(oldestShownIdx + 1).forEach(revokeBlobUrl);
6330
+ blobsByOwnerRef.current.set(owner, list.slice(0, oldestShownIdx + 1));
6279
6331
  }, [revokeBlobUrl]);
6332
+ const markBlobShown = (0, import_react25.useCallback)((owner, url, consumer = "default") => {
6333
+ const list = blobsByOwnerRef.current.get(owner);
6334
+ if (!list || list.indexOf(url) < 0) return;
6335
+ const shown = shownBlobByOwnerRef.current.get(owner) ?? /* @__PURE__ */ new Map();
6336
+ shown.set(consumer, url);
6337
+ shownBlobByOwnerRef.current.set(owner, shown);
6338
+ releaseOlderFrames(owner);
6339
+ }, [releaseOlderFrames]);
6340
+ const releaseBlobConsumer = (0, import_react25.useCallback)((owner, consumer) => {
6341
+ const shown = shownBlobByOwnerRef.current.get(owner);
6342
+ if (!shown?.delete(consumer)) return;
6343
+ releaseOlderFrames(owner);
6344
+ }, [releaseOlderFrames]);
6280
6345
  const croppedDeliveryEnabled = delivery !== "full-frame";
6281
6346
  const sendCropConfig = (0, import_react25.useCallback)(
6282
6347
  (withCrop) => {
@@ -6398,6 +6463,64 @@ function RealtimeProvider({
6398
6463
  compositeQueueRef.current.clear();
6399
6464
  croppedActiveRef.current = false;
6400
6465
  }, []);
6466
+ const currentShape = (0, import_react25.useCallback)(
6467
+ () => sessionShape({
6468
+ allMockupIds: configuredMockupIdsRef.current,
6469
+ views: pictureViewsRef.current,
6470
+ heroWidth: heroWidthRef.current,
6471
+ editorOpen: editorOpenRef.current,
6472
+ editLive: editLiveRef.current
6473
+ }),
6474
+ []
6475
+ );
6476
+ const applySessionShape = (0, import_react25.useCallback)(() => {
6477
+ const base = lastConfigBaseRef.current;
6478
+ if (!base || !configSentRef.current) return;
6479
+ const shape = currentShape();
6480
+ if (sameShape(lastShapeRef.current, shape)) {
6481
+ lastShapeRef.current = shape;
6482
+ return;
6483
+ }
6484
+ if (lastShapeRef.current && lastShapeRef.current.width !== shape.width) invalidateBackgrounds();
6485
+ lastShapeRef.current = shape;
6486
+ base.mockupIds = shape.mockupIds;
6487
+ base.width = shape.width;
6488
+ requestedMockupIdsRef.current = [...shape.mockupIds];
6489
+ sendConfigRaw({
6490
+ ...base,
6491
+ placementSettings: { ...placementSettingsOverridesRef.current },
6492
+ ...croppedActiveRef.current ? { overlayCrop: "auto" } : {}
6493
+ });
6494
+ }, [currentShape, invalidateBackgrounds, sendConfigRaw]);
6495
+ applySessionShapeRef.current = applySessionShape;
6496
+ const markEditLive = (0, import_react25.useCallback)(() => {
6497
+ if (editQuietTimerRef.current) {
6498
+ clearTimeout(editQuietTimerRef.current);
6499
+ editQuietTimerRef.current = null;
6500
+ }
6501
+ if (editLiveRef.current) return;
6502
+ editLiveRef.current = true;
6503
+ applySessionShapeRef.current?.();
6504
+ }, []);
6505
+ const markEditSettled = (0, import_react25.useCallback)(() => {
6506
+ if (!editLiveRef.current) return;
6507
+ if (editQuietTimerRef.current) clearTimeout(editQuietTimerRef.current);
6508
+ editQuietTimerRef.current = setTimeout(() => {
6509
+ editQuietTimerRef.current = null;
6510
+ editLiveRef.current = false;
6511
+ applySessionShapeRef.current?.();
6512
+ }, EDIT_QUIET_MS);
6513
+ }, []);
6514
+ (0, import_react25.useEffect)(() => {
6515
+ applySessionShapeRef.current?.();
6516
+ }, [editorOpenState]);
6517
+ (0, import_react25.useEffect)(
6518
+ () => () => {
6519
+ if (editQuietTimerRef.current) clearTimeout(editQuietTimerRef.current);
6520
+ if (shapeApplyTimerRef.current) clearTimeout(shapeApplyTimerRef.current);
6521
+ },
6522
+ []
6523
+ );
6401
6524
  const deliverResults = (0, import_react25.useCallback)(
6402
6525
  (results) => {
6403
6526
  if (results.length === 0) return;
@@ -6463,13 +6586,15 @@ function RealtimeProvider({
6463
6586
  if (!pipelineResetCooldownRef.current) {
6464
6587
  hasBlobInFlightRef.current = false;
6465
6588
  for (let i = 0; i < settledVersions; i++) pipelineSettledSubscribersRef.current.forEach((cb) => cb());
6589
+ markEditSettled();
6466
6590
  }
6467
6591
  } else if (due.size === 0 && hasBlobInFlightRef.current && !hasPendingBlobs() && !pipelineResetCooldownRef.current) {
6468
6592
  hasBlobInFlightRef.current = false;
6469
6593
  pipelineSettledSubscribersRef.current.forEach((cb) => cb());
6594
+ markEditSettled();
6470
6595
  }
6471
6596
  },
6472
- [hasPendingBlobs]
6597
+ [hasPendingBlobs, markEditSettled]
6473
6598
  );
6474
6599
  const runComposite = (0, import_react25.useCallback)(
6475
6600
  async (result) => {
@@ -6500,6 +6625,7 @@ function RealtimeProvider({
6500
6625
  if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
6501
6626
  return;
6502
6627
  }
6628
+ if (isFrameSupersededRef.current?.(result.imageUrl)) return;
6503
6629
  const message = err instanceof Error ? err.message : String(err);
6504
6630
  if (result.imageUrl.startsWith("blob:") && message.startsWith("E_OVERLAY_FRAME_LOAD") && message.includes(result.imageUrl.slice(0, 160))) {
6505
6631
  const failedUrl = result.imageUrl;
@@ -6595,10 +6721,11 @@ function RealtimeProvider({
6595
6721
  lastBlobSentTimeRef.current = (/* @__PURE__ */ new Date()).toLocaleTimeString();
6596
6722
  isPendingMockupsRef.current = true;
6597
6723
  pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
6724
+ markEditLive();
6598
6725
  }
6599
6726
  return result;
6600
6727
  },
6601
- [sendCanvasBlobRaw]
6728
+ [sendCanvasBlobRaw, markEditLive]
6602
6729
  );
6603
6730
  const sendCanvasState = (0, import_react25.useCallback)(
6604
6731
  (placement, state, mockupCount, baseThrottleMs) => {
@@ -6615,15 +6742,16 @@ function RealtimeProvider({
6615
6742
  isPendingMockupsRef.current = true;
6616
6743
  const version = getLastSentVersion();
6617
6744
  if (version > 0) {
6618
- const configured = configuredMockupIdsRef.current.length;
6745
+ const configured = requestedMockupIdsRef.current.length || configuredMockupIdsRef.current.length;
6619
6746
  const expected = Math.max(1, Math.min(configured || Infinity, mockupCount || Infinity));
6620
6747
  dueByVersionRef.current.set(version, { due: Number.isFinite(expected) ? expected : 1, at: Date.now() });
6621
6748
  }
6622
6749
  pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
6750
+ markEditLive();
6623
6751
  }
6624
6752
  return result;
6625
6753
  },
6626
- [sendCanvasStateRaw, getLastSentVersion]
6754
+ [sendCanvasStateRaw, getLastSentVersion, markEditLive]
6627
6755
  );
6628
6756
  const sendColorBlobTracked = (0, import_react25.useCallback)(
6629
6757
  (placement, color) => {
@@ -6688,22 +6816,24 @@ function RealtimeProvider({
6688
6816
  });
6689
6817
  }
6690
6818
  configuredMockupIdsRef.current = mockupIds;
6819
+ const shape = currentShape();
6820
+ lastShapeRef.current = shape;
6691
6821
  const configPayload = useSessionGrant ? {
6692
6822
  productId,
6693
- mockupIds,
6823
+ mockupIds: shape.mockupIds,
6694
6824
  variantId,
6695
6825
  shop,
6696
- width: mockupWidth,
6826
+ width: shape.width,
6697
6827
  ...mockupBg ? { bg: mockupBg } : {},
6698
6828
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6699
6829
  placementSettings: { ...placementSettingsOverridesRef.current }
6700
6830
  } : {
6701
6831
  productId,
6702
- mockupIds,
6832
+ mockupIds: shape.mockupIds,
6703
6833
  variantId,
6704
6834
  shop: "hTidnpNnNa",
6705
6835
  seal: "bypass-sig-for-k6-load-test",
6706
- width: mockupWidth,
6836
+ width: shape.width,
6707
6837
  ...mockupBg ? { bg: mockupBg } : {},
6708
6838
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6709
6839
  placementSettings: { ...placementSettingsOverridesRef.current }
@@ -6715,7 +6845,7 @@ function RealtimeProvider({
6715
6845
  });
6716
6846
  }
6717
6847
  lastConfigBaseRef.current = configPayload;
6718
- requestedMockupIdsRef.current = mockupIds;
6848
+ requestedMockupIdsRef.current = [...shape.mockupIds];
6719
6849
  sendConfigRaw(
6720
6850
  croppedActiveRef.current ? { ...configPayload, overlayCrop: "auto" } : configPayload
6721
6851
  );
@@ -6741,6 +6871,7 @@ function RealtimeProvider({
6741
6871
  sendConfigRaw,
6742
6872
  sendColorBlobTracked,
6743
6873
  invalidateBackgrounds,
6874
+ currentShape,
6744
6875
  mockupWidth,
6745
6876
  mockupBg,
6746
6877
  spreadCropsVersion
@@ -6930,8 +7061,9 @@ function RealtimeProvider({
6930
7061
  }
6931
7062
  console.log(`[RTP] notifyPendingExport("${placement}"): marked ${pendingIds.length} mockup(s) pending \u2014 [${pendingIds.slice(0, 5).join(", ")}${pendingIds.length > 5 ? "..." : ""}]`);
6932
7063
  pendingBlobSubscribersRef.current.forEach((cb) => cb(placement));
7064
+ markEditLive();
6933
7065
  },
6934
- [productContext?.product?.mockups]
7066
+ [productContext?.product?.mockups, markEditLive]
6935
7067
  );
6936
7068
  const notifyPendingExportCancelled = (0, import_react25.useCallback)(
6937
7069
  (placement) => {
@@ -7038,6 +7170,20 @@ function RealtimeProvider({
7038
7170
  const getLatestSentVersionsRef = (0, import_react25.useRef)(getLatestSentVersions);
7039
7171
  getLatestSentVersionsRef.current = getLatestSentVersions;
7040
7172
  const getLatestSentVersionsStable = (0, import_react25.useCallback)(() => getLatestSentVersionsRef.current?.() ?? {}, []);
7173
+ const reportPictureView = (0, import_react25.useCallback)((elementKey, view) => {
7174
+ const views = pictureViewsRef.current;
7175
+ if (view) views.set(elementKey, view);
7176
+ else views.delete(elementKey);
7177
+ if (shapeApplyTimerRef.current) return;
7178
+ shapeApplyTimerRef.current = setTimeout(() => {
7179
+ shapeApplyTimerRef.current = null;
7180
+ applySessionShapeRef.current?.();
7181
+ }, 100);
7182
+ }, []);
7183
+ const getSessionShape = (0, import_react25.useCallback)(() => {
7184
+ const s = lastShapeRef.current;
7185
+ return s ? { phase: s.phase, width: s.width } : null;
7186
+ }, []);
7041
7187
  const stableSubscribePipelineSettled = (0, import_react25.useCallback)(
7042
7188
  (callback) => {
7043
7189
  return subscribePipelineSettledRef.current(callback);
@@ -7088,9 +7234,13 @@ function RealtimeProvider({
7088
7234
  getMockupUrls,
7089
7235
  getCanvasVersion,
7090
7236
  getLatestSentVersions: getLatestSentVersionsStable,
7237
+ reportPictureView,
7238
+ getSessionShape,
7239
+ setEditorOpen: setEditorOpenState,
7091
7240
  isMockupLoading,
7092
7241
  registerBlobUrl,
7093
7242
  markBlobShown,
7243
+ releaseBlobConsumer,
7094
7244
  // WebRTC streaming
7095
7245
  subscribeRTCTiming
7096
7246
  }),
@@ -7122,9 +7272,12 @@ function RealtimeProvider({
7122
7272
  getMockupUrls,
7123
7273
  getCanvasVersion,
7124
7274
  getLatestSentVersionsStable,
7275
+ reportPictureView,
7276
+ getSessionShape,
7125
7277
  isMockupLoading,
7126
7278
  registerBlobUrl,
7127
- markBlobShown
7279
+ markBlobShown,
7280
+ releaseBlobConsumer
7128
7281
  ]
7129
7282
  );
7130
7283
  return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(RealtimeContext.Provider, { value: contextValue, children });
@@ -10674,7 +10827,8 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
10674
10827
  darkShimmerFadeInDuration = 300,
10675
10828
  emptyText = "No artwork",
10676
10829
  errorText = "Error loading",
10677
- unavailableText = "Preview unavailable"
10830
+ unavailableText = "Preview unavailable",
10831
+ viewportPolicy = false
10678
10832
  }) {
10679
10833
  const context = useProductOptional();
10680
10834
  const designContext = useDesignOptional();
@@ -10880,6 +11034,15 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
10880
11034
  const arrivedVersionRef = (0, import_react46.useRef)(0);
10881
11035
  const versionByUrlRef = (0, import_react46.useRef)(/* @__PURE__ */ new Map());
10882
11036
  const loadedUrlRef = (0, import_react46.useRef)(null);
11037
+ const blobConsumerRef = (0, import_react46.useRef)(`el-${Math.random().toString(36).slice(2, 10)}`);
11038
+ const releaseBlobConsumer = realtimeContext?.releaseBlobConsumer;
11039
+ (0, import_react46.useEffect)(() => {
11040
+ const id = actualMockupId;
11041
+ const consumer = blobConsumerRef.current;
11042
+ return () => {
11043
+ if (id) releaseBlobConsumer?.(id, consumer);
11044
+ };
11045
+ }, [actualMockupId, releaseBlobConsumer]);
10883
11046
  const frameErrorRef = (0, import_react46.useRef)(null);
10884
11047
  const showVersionOf = (0, import_react46.useCallback)((url) => {
10885
11048
  const e = versionByUrlRef.current.get(url);
@@ -10895,6 +11058,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
10895
11058
  const sessionErrorCodeRef = (0, import_react46.useRef)(null);
10896
11059
  sessionErrorCodeRef.current = realtimeContext?.renderError?.code ?? null;
10897
11060
  const getCanvasVersion = realtimeContext?.getCanvasVersion;
11061
+ const getSessionShape = realtimeContext?.getSessionShape;
10898
11062
  const applyRenderStamp = (0, import_react46.useCallback)(() => {
10899
11063
  const node = containerRef.current;
10900
11064
  if (!node) return;
@@ -10915,7 +11079,14 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
10915
11079
  if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
10916
11080
  else delete node.dataset.frameError;
10917
11081
  node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
10918
- }, [getCanvasVersion, getLatestSentVersions]);
11082
+ const img = node.querySelector("img");
11083
+ if (img?.naturalWidth) node.dataset.renderWidth = String(img.naturalWidth);
11084
+ const shape = getSessionShape?.();
11085
+ if (shape) {
11086
+ node.dataset.wantedWidth = String(shape.width);
11087
+ node.dataset.sessionPhase = shape.phase;
11088
+ }
11089
+ }, [getCanvasVersion, getLatestSentVersions, getSessionShape]);
10919
11090
  const applyRenderStampRef = (0, import_react46.useRef)(applyRenderStamp);
10920
11091
  applyRenderStampRef.current = applyRenderStamp;
10921
11092
  (0, import_react46.useEffect)(() => {
@@ -10947,6 +11118,39 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
10947
11118
  realtimeContext?.subscribeMockupResultById,
10948
11119
  applyRenderStamp
10949
11120
  ]);
11121
+ const reportPictureView = realtimeContext?.reportPictureView;
11122
+ (0, import_react46.useEffect)(() => {
11123
+ if (!viewportPolicy || !reportPictureView || !actualMockupId) return;
11124
+ const node = containerRef.current;
11125
+ if (!node || typeof IntersectionObserver === "undefined") return;
11126
+ let inSet = false;
11127
+ const key = `${actualMockupId}#${Math.random().toString(36).slice(2, 9)}`;
11128
+ const report = () => {
11129
+ const r = node.getBoundingClientRect();
11130
+ const onScreen = r.width > 0 && r.right > 0 && r.left < window.innerWidth && r.bottom > 0 && r.top < window.innerHeight;
11131
+ reportPictureView(key, {
11132
+ mockupId: actualMockupId,
11133
+ inSet: inSet || onScreen,
11134
+ onScreen,
11135
+ devicePx: Math.round(r.width * (window.devicePixelRatio || 1))
11136
+ });
11137
+ };
11138
+ const io = new IntersectionObserver(
11139
+ (entries) => {
11140
+ inSet = entries.some((e) => e.isIntersecting);
11141
+ report();
11142
+ },
11143
+ { rootMargin: "0px 100% 0px 100%" }
11144
+ );
11145
+ io.observe(node);
11146
+ const onResize = () => report();
11147
+ window.addEventListener("resize", onResize);
11148
+ return () => {
11149
+ io.disconnect();
11150
+ window.removeEventListener("resize", onResize);
11151
+ reportPictureView(key, null);
11152
+ };
11153
+ }, [viewportPolicy, reportPictureView, actualMockupId]);
10950
11154
  (0, import_react46.useEffect)(() => {
10951
11155
  if (!priorityContext || !actualMockupId || !placement) return;
10952
11156
  priorityContext.registerMockup(actualMockupId, placement, initialPriority);
@@ -11249,7 +11453,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
11249
11453
  if (renderedUrl) {
11250
11454
  loadedUrlRef.current = renderedUrl;
11251
11455
  showVersionOf(renderedUrl);
11252
- if (actualMockupId) realtimeContext?.markBlobShown?.(actualMockupId, renderedUrl);
11456
+ if (actualMockupId) realtimeContext?.markBlobShown?.(actualMockupId, renderedUrl, blobConsumerRef.current);
11253
11457
  applyRenderStampRef.current?.();
11254
11458
  }
11255
11459
  if (!onLoadCalledRef.current && onLoad) {
@@ -13327,7 +13531,8 @@ var MobileProductCarousel = (0, import_react56.memo)(function MobileProductCarou
13327
13531
  onUrlGenerated: image.mockupId ? (url) => handleUrlGenerated(image.mockupId, url) : void 0,
13328
13532
  errorText,
13329
13533
  unavailableText,
13330
- className: "w-full h-full object-cover cursor-pointer pointer-events-none"
13534
+ className: "w-full h-full object-cover cursor-pointer pointer-events-none",
13535
+ viewportPolicy: true
13331
13536
  }
13332
13537
  ) : image.isRealMockup && !currentArtwork ? /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(LoadingOverlayPrismCandyInline, { visible: true, variant: "light" }) : /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
13333
13538
  StaticCarouselImage,