@snowcone-app/ui 0.9.6 → 0.9.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/dist/index.d.cts CHANGED
@@ -3090,6 +3090,8 @@ interface RealtimeContextValue {
3090
3090
  * @returns The blob URL (created or passed through)
3091
3091
  */
3092
3092
  registerBlobUrl: (blobOrUrl: Blob | string, placementName?: string) => string;
3093
+ /** A picture's <img> loaded `url` (from getMockupUrl): its older composited frames are released. */
3094
+ markBlobShown: (mockupId: string, url: string) => void;
3093
3095
  }
3094
3096
  interface RealtimeProviderProps {
3095
3097
  children: React__default.ReactNode;
package/dist/index.d.ts CHANGED
@@ -3090,6 +3090,8 @@ interface RealtimeContextValue {
3090
3090
  * @returns The blob URL (created or passed through)
3091
3091
  */
3092
3092
  registerBlobUrl: (blobOrUrl: Blob | string, placementName?: string) => string;
3093
+ /** A picture's <img> loaded `url` (from getMockupUrl): its older composited frames are released. */
3094
+ markBlobShown: (mockupId: string, url: string) => void;
3093
3095
  }
3094
3096
  interface RealtimeProviderProps {
3095
3097
  children: React__default.ReactNode;
package/dist/index.js CHANGED
@@ -5703,6 +5703,7 @@ async function compositeCroppedFrame(args) {
5703
5703
  import { jsx as jsx52 } from "react/jsx-runtime";
5704
5704
  var DEFAULT_ARTBOARD_SIZE = 2e3;
5705
5705
  var MAX_CONCURRENT_BLOBS = 5;
5706
+ var MAX_FRAMES_PER_PICTURE = 3;
5706
5707
  var FRAME_SUPERSEDE_GRACE_MS = 2e3;
5707
5708
  var RERENDER_MIN_INTERVAL_MS = 550;
5708
5709
  function mergeMockupIds(current, extra) {
@@ -5847,6 +5848,8 @@ function RealtimeProvider({
5847
5848
  const configuredMockupIdsRef = useRef12([]);
5848
5849
  const mockupUrlCacheRef = useRef12(/* @__PURE__ */ new Map());
5849
5850
  const registeredBlobUrlsRef = useRef12(/* @__PURE__ */ new Set());
5851
+ const blobsByOwnerRef = useRef12(/* @__PURE__ */ new Map());
5852
+ const shownBlobByOwnerRef = useRef12(/* @__PURE__ */ new Map());
5850
5853
  const pendingPlacementsRef = useRef12(/* @__PURE__ */ new Set());
5851
5854
  const pendingMockupIdsRef = useRef12(/* @__PURE__ */ new Set());
5852
5855
  const backgroundsRef = useRef12(/* @__PURE__ */ new Map());
@@ -5873,31 +5876,48 @@ function RealtimeProvider({
5873
5876
  },
5874
5877
  []
5875
5878
  );
5876
- const registerBlobUrl = useCallback10((blobOrUrl, placementName) => {
5877
- let url;
5878
- if (blobOrUrl instanceof Blob) {
5879
- if (registeredBlobUrlsRef.current.size >= MAX_CONCURRENT_BLOBS) {
5880
- const oldest = registeredBlobUrlsRef.current.values().next().value;
5881
- if (oldest) {
5882
- URL.revokeObjectURL(oldest);
5883
- registeredBlobUrlsRef.current.delete(oldest);
5884
- mockupUrlCacheRef.current.forEach((value, key) => {
5885
- if (value.url === oldest) {
5886
- mockupUrlCacheRef.current.delete(key);
5887
- }
5888
- });
5889
- mockupResultsRef.current = mockupResultsRef.current.filter(
5890
- (r) => r.imageUrl !== oldest
5891
- );
5892
- }
5879
+ const revokeBlobUrl = useCallback10((url) => {
5880
+ URL.revokeObjectURL(url);
5881
+ registeredBlobUrlsRef.current.delete(url);
5882
+ mockupUrlCacheRef.current.forEach((value, key) => {
5883
+ if (value.url === url) mockupUrlCacheRef.current.delete(key);
5884
+ });
5885
+ mockupResultsRef.current = mockupResultsRef.current.filter((r) => r.imageUrl !== url);
5886
+ }, []);
5887
+ const registerBlobUrl = useCallback10((blobOrUrl, _placementName, owner) => {
5888
+ if (!(blobOrUrl instanceof Blob)) return blobOrUrl;
5889
+ const url = URL.createObjectURL(blobOrUrl);
5890
+ if (owner) {
5891
+ const list = [url, ...blobsByOwnerRef.current.get(owner) ?? []];
5892
+ const shown = shownBlobByOwnerRef.current.get(owner);
5893
+ while (list.length > MAX_FRAMES_PER_PICTURE) {
5894
+ const victimIdx = [...list.keys()].reverse().find((i) => i > 0 && list[i] !== shown);
5895
+ if (victimIdx === void 0) break;
5896
+ const [victim] = list.splice(victimIdx, 1);
5897
+ console.error(
5898
+ `[RealtimeProvider] E_BLOB_PICTURE_BOUND: ${owner} has more than ${MAX_FRAMES_PER_PICTURE} frames waiting to be shown; dropping its oldest unshown frame (the picture on screen is kept).`
5899
+ );
5900
+ revokeBlobUrl(victim);
5893
5901
  }
5894
- url = URL.createObjectURL(blobOrUrl);
5895
- registeredBlobUrlsRef.current.add(url);
5896
- } else {
5897
- url = blobOrUrl;
5902
+ blobsByOwnerRef.current.set(owner, list);
5903
+ return url;
5904
+ }
5905
+ if (registeredBlobUrlsRef.current.size >= MAX_CONCURRENT_BLOBS) {
5906
+ const oldest = registeredBlobUrlsRef.current.values().next().value;
5907
+ if (oldest) revokeBlobUrl(oldest);
5898
5908
  }
5909
+ registeredBlobUrlsRef.current.add(url);
5899
5910
  return url;
5900
- }, []);
5911
+ }, [revokeBlobUrl]);
5912
+ const markBlobShown = useCallback10((owner, url) => {
5913
+ const list = blobsByOwnerRef.current.get(owner);
5914
+ if (!list) return;
5915
+ const idx = list.indexOf(url);
5916
+ if (idx < 0) return;
5917
+ shownBlobByOwnerRef.current.set(owner, url);
5918
+ list.slice(idx + 1).forEach(revokeBlobUrl);
5919
+ blobsByOwnerRef.current.set(owner, list.slice(0, idx + 1));
5920
+ }, [revokeBlobUrl]);
5901
5921
  const croppedDeliveryEnabled = delivery !== "full-frame";
5902
5922
  const sendCropConfig = useCallback10(
5903
5923
  (withCrop) => {
@@ -6116,7 +6136,7 @@ function RealtimeProvider({
6116
6136
  canvas: compositeCanvasRef.current ?? void 0
6117
6137
  });
6118
6138
  if (gen !== sceneGenRef.current) return;
6119
- deliverResults([{ ...result, imageUrl: registerBlobUrl(blob) }]);
6139
+ deliverResults([{ ...result, imageUrl: registerBlobUrl(blob, void 0, result.mockupId) }]);
6120
6140
  } catch (err) {
6121
6141
  if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
6122
6142
  return;
@@ -6711,6 +6731,7 @@ function RealtimeProvider({
6711
6731
  getLatestSentVersions: getLatestSentVersionsStable,
6712
6732
  isMockupLoading,
6713
6733
  registerBlobUrl,
6734
+ markBlobShown,
6714
6735
  // WebRTC streaming
6715
6736
  subscribeRTCTiming
6716
6737
  }),
@@ -6743,7 +6764,8 @@ function RealtimeProvider({
6743
6764
  getCanvasVersion,
6744
6765
  getLatestSentVersionsStable,
6745
6766
  isMockupLoading,
6746
- registerBlobUrl
6767
+ registerBlobUrl,
6768
+ markBlobShown
6747
6769
  ]
6748
6770
  );
6749
6771
  return /* @__PURE__ */ jsx52(RealtimeContext.Provider, { value: contextValue, children });
@@ -10537,6 +10559,17 @@ var HeroProductImage = memo3(function HeroProductImage2({
10537
10559
  };
10538
10560
  }, [mode, realtimeContext?.subscribePendingBlob, placement]);
10539
10561
  const renderVersionRef = useRef23(0);
10562
+ const arrivedVersionRef = useRef23(0);
10563
+ const versionByUrlRef = useRef23(/* @__PURE__ */ new Map());
10564
+ const loadedUrlRef = useRef23(null);
10565
+ const frameErrorRef = useRef23(null);
10566
+ const showVersionOf = useCallback18((url) => {
10567
+ const e = versionByUrlRef.current.get(url);
10568
+ if (!e || e.v < renderVersionRef.current) return;
10569
+ renderVersionRef.current = e.v;
10570
+ renderVersionsRef.current = e.versions;
10571
+ frameErrorRef.current = null;
10572
+ }, []);
10540
10573
  const renderVersionsRef = useRef23(null);
10541
10574
  const getLatestSentVersions = realtimeContext?.getLatestSentVersions;
10542
10575
  const refusalCodeRef = useRef23(null);
@@ -10560,8 +10593,13 @@ var HeroProductImage = memo3(function HeroProductImage2({
10560
10593
  const behind = versions && sent ? Object.entries(sent).some(([placement2, v]) => (versions[placement2] ?? -1) < v) : rendered < canvas;
10561
10594
  node.dataset.canvasVersion = String(canvas);
10562
10595
  node.dataset.renderVersion = String(rendered);
10596
+ node.dataset.arrivedVersion = String(arrivedVersionRef.current);
10597
+ if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
10598
+ else delete node.dataset.frameError;
10563
10599
  node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
10564
10600
  }, [getCanvasVersion, getLatestSentVersions]);
10601
+ const applyRenderStampRef = useRef23(applyRenderStamp);
10602
+ applyRenderStampRef.current = applyRenderStamp;
10565
10603
  useEffect32(() => {
10566
10604
  applyRenderStamp();
10567
10605
  });
@@ -10571,9 +10609,13 @@ var HeroProductImage = memo3(function HeroProductImage2({
10571
10609
  if (!actualMockupId || !subscribeSent || !subscribeResult) return;
10572
10610
  const offSent = subscribeSent(() => applyRenderStamp());
10573
10611
  const offResult = subscribeResult(actualMockupId, (result) => {
10574
- if (typeof result?.requestVersion === "number" && result.requestVersion >= renderVersionRef.current) {
10575
- renderVersionRef.current = result.requestVersion;
10576
- renderVersionsRef.current = result.versions ?? null;
10612
+ if (typeof result?.requestVersion === "number") {
10613
+ arrivedVersionRef.current = Math.max(arrivedVersionRef.current, result.requestVersion);
10614
+ const url = realtimeContext?.getMockupUrl?.(result.mockupId) ?? result.imageUrl;
10615
+ if (url) {
10616
+ versionByUrlRef.current.set(url, { v: result.requestVersion, versions: result.versions ?? null });
10617
+ if (url === loadedUrlRef.current) showVersionOf(url);
10618
+ }
10577
10619
  }
10578
10620
  applyRenderStamp();
10579
10621
  });
@@ -10800,8 +10842,13 @@ var HeroProductImage = memo3(function HeroProductImage2({
10800
10842
  };
10801
10843
  if (preload.complete) startCrossfade();
10802
10844
  else preload.onload = startCrossfade;
10845
+ preload.onerror = () => {
10846
+ frameErrorRef.current = "E_FRAME_UNAVAILABLE";
10847
+ applyRenderStampRef.current?.();
10848
+ };
10803
10849
  return () => {
10804
10850
  preload.onload = null;
10851
+ preload.onerror = null;
10805
10852
  };
10806
10853
  }, [displayUrl]);
10807
10854
  const handleCrossfadeEnd = useCallback18(() => {
@@ -10881,6 +10928,12 @@ var HeroProductImage = memo3(function HeroProductImage2({
10881
10928
  onLoad: () => {
10882
10929
  setImgFailed(false);
10883
10930
  setFirstImageLoaded(true);
10931
+ if (renderedUrl) {
10932
+ loadedUrlRef.current = renderedUrl;
10933
+ showVersionOf(renderedUrl);
10934
+ if (actualMockupId) realtimeContext?.markBlobShown?.(actualMockupId, renderedUrl);
10935
+ applyRenderStampRef.current?.();
10936
+ }
10884
10937
  if (!onLoadCalledRef.current && onLoad) {
10885
10938
  onLoadCalledRef.current = true;
10886
10939
  onLoad();