@snowcone-app/ui 0.9.6 → 0.9.8
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 +19 -0
- package/dist/index.cjs +109 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +109 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/composed/HeroProductImage.tsx +49 -4
- package/src/patterns/RealtimeProvider.tsx +111 -31
- package/src/patterns/__tests__/RealtimeProvider.blobLifecycle.test.tsx +271 -0
- package/src/patterns/__tests__/RealtimeProvider.cropDelivery.test.tsx +27 -0
package/dist/index.d.cts
CHANGED
|
@@ -3090,6 +3090,10 @@ 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, consumer?: string) => void;
|
|
3095
|
+
/** An element that called markBlobShown unmounted: it no longer holds its frame. */
|
|
3096
|
+
releaseBlobConsumer: (mockupId: string, consumer: string) => void;
|
|
3093
3097
|
}
|
|
3094
3098
|
interface RealtimeProviderProps {
|
|
3095
3099
|
children: React__default.ReactNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -3090,6 +3090,10 @@ 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, consumer?: string) => void;
|
|
3095
|
+
/** An element that called markBlobShown unmounted: it no longer holds its frame. */
|
|
3096
|
+
releaseBlobConsumer: (mockupId: string, consumer: string) => void;
|
|
3093
3097
|
}
|
|
3094
3098
|
interface RealtimeProviderProps {
|
|
3095
3099
|
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) {
|
|
@@ -5821,8 +5822,11 @@ function RealtimeProvider({
|
|
|
5821
5822
|
hasPendingBlobs,
|
|
5822
5823
|
getLastSentVersion,
|
|
5823
5824
|
getLatestSentVersions,
|
|
5824
|
-
rerender: rerenderRaw
|
|
5825
|
+
rerender: rerenderRaw,
|
|
5826
|
+
isFrameSuperseded
|
|
5825
5827
|
} = realtimeMockup;
|
|
5828
|
+
const isFrameSupersededRef = useRef12(isFrameSuperseded);
|
|
5829
|
+
isFrameSupersededRef.current = isFrameSuperseded;
|
|
5826
5830
|
const mockupResultsRef = useRef12([]);
|
|
5827
5831
|
const mockupSubscribersRef = useRef12(
|
|
5828
5832
|
/* @__PURE__ */ new Set()
|
|
@@ -5847,6 +5851,8 @@ function RealtimeProvider({
|
|
|
5847
5851
|
const configuredMockupIdsRef = useRef12([]);
|
|
5848
5852
|
const mockupUrlCacheRef = useRef12(/* @__PURE__ */ new Map());
|
|
5849
5853
|
const registeredBlobUrlsRef = useRef12(/* @__PURE__ */ new Set());
|
|
5854
|
+
const blobsByOwnerRef = useRef12(/* @__PURE__ */ new Map());
|
|
5855
|
+
const shownBlobByOwnerRef = useRef12(/* @__PURE__ */ new Map());
|
|
5850
5856
|
const pendingPlacementsRef = useRef12(/* @__PURE__ */ new Set());
|
|
5851
5857
|
const pendingMockupIdsRef = useRef12(/* @__PURE__ */ new Set());
|
|
5852
5858
|
const backgroundsRef = useRef12(/* @__PURE__ */ new Map());
|
|
@@ -5873,31 +5879,61 @@ function RealtimeProvider({
|
|
|
5873
5879
|
},
|
|
5874
5880
|
[]
|
|
5875
5881
|
);
|
|
5876
|
-
const
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5882
|
+
const revokeBlobUrl = useCallback10((url) => {
|
|
5883
|
+
URL.revokeObjectURL(url);
|
|
5884
|
+
registeredBlobUrlsRef.current.delete(url);
|
|
5885
|
+
mockupUrlCacheRef.current.forEach((value, key) => {
|
|
5886
|
+
if (value.url === url) mockupUrlCacheRef.current.delete(key);
|
|
5887
|
+
});
|
|
5888
|
+
mockupResultsRef.current = mockupResultsRef.current.filter((r) => r.imageUrl !== url);
|
|
5889
|
+
}, []);
|
|
5890
|
+
const registerBlobUrl = useCallback10((blobOrUrl, _placementName, owner) => {
|
|
5891
|
+
if (!(blobOrUrl instanceof Blob)) return blobOrUrl;
|
|
5892
|
+
const url = URL.createObjectURL(blobOrUrl);
|
|
5893
|
+
if (owner) {
|
|
5894
|
+
const list = [url, ...blobsByOwnerRef.current.get(owner) ?? []];
|
|
5895
|
+
const shown = new Set(shownBlobByOwnerRef.current.get(owner)?.values() ?? []);
|
|
5896
|
+
while (list.length > MAX_FRAMES_PER_PICTURE) {
|
|
5897
|
+
const victimIdx = [...list.keys()].reverse().find((i) => i > 0 && !shown.has(list[i]));
|
|
5898
|
+
if (victimIdx === void 0) break;
|
|
5899
|
+
const [victim] = list.splice(victimIdx, 1);
|
|
5900
|
+
console.error(
|
|
5901
|
+
`[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).`
|
|
5902
|
+
);
|
|
5903
|
+
revokeBlobUrl(victim);
|
|
5893
5904
|
}
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
}
|
|
5897
|
-
|
|
5905
|
+
blobsByOwnerRef.current.set(owner, list);
|
|
5906
|
+
return url;
|
|
5907
|
+
}
|
|
5908
|
+
if (registeredBlobUrlsRef.current.size >= MAX_CONCURRENT_BLOBS) {
|
|
5909
|
+
const oldest = registeredBlobUrlsRef.current.values().next().value;
|
|
5910
|
+
if (oldest) revokeBlobUrl(oldest);
|
|
5898
5911
|
}
|
|
5912
|
+
registeredBlobUrlsRef.current.add(url);
|
|
5899
5913
|
return url;
|
|
5900
|
-
}, []);
|
|
5914
|
+
}, [revokeBlobUrl]);
|
|
5915
|
+
const releaseOlderFrames = useCallback10((owner) => {
|
|
5916
|
+
const list = blobsByOwnerRef.current.get(owner);
|
|
5917
|
+
const shown = shownBlobByOwnerRef.current.get(owner);
|
|
5918
|
+
if (!list || !shown || shown.size === 0) return;
|
|
5919
|
+
const oldestShownIdx = Math.max(...[...shown.values()].map((u) => list.indexOf(u)));
|
|
5920
|
+
if (oldestShownIdx < 0) return;
|
|
5921
|
+
list.slice(oldestShownIdx + 1).forEach(revokeBlobUrl);
|
|
5922
|
+
blobsByOwnerRef.current.set(owner, list.slice(0, oldestShownIdx + 1));
|
|
5923
|
+
}, [revokeBlobUrl]);
|
|
5924
|
+
const markBlobShown = useCallback10((owner, url, consumer = "default") => {
|
|
5925
|
+
const list = blobsByOwnerRef.current.get(owner);
|
|
5926
|
+
if (!list || list.indexOf(url) < 0) return;
|
|
5927
|
+
const shown = shownBlobByOwnerRef.current.get(owner) ?? /* @__PURE__ */ new Map();
|
|
5928
|
+
shown.set(consumer, url);
|
|
5929
|
+
shownBlobByOwnerRef.current.set(owner, shown);
|
|
5930
|
+
releaseOlderFrames(owner);
|
|
5931
|
+
}, [releaseOlderFrames]);
|
|
5932
|
+
const releaseBlobConsumer = useCallback10((owner, consumer) => {
|
|
5933
|
+
const shown = shownBlobByOwnerRef.current.get(owner);
|
|
5934
|
+
if (!shown?.delete(consumer)) return;
|
|
5935
|
+
releaseOlderFrames(owner);
|
|
5936
|
+
}, [releaseOlderFrames]);
|
|
5901
5937
|
const croppedDeliveryEnabled = delivery !== "full-frame";
|
|
5902
5938
|
const sendCropConfig = useCallback10(
|
|
5903
5939
|
(withCrop) => {
|
|
@@ -6116,11 +6152,12 @@ function RealtimeProvider({
|
|
|
6116
6152
|
canvas: compositeCanvasRef.current ?? void 0
|
|
6117
6153
|
});
|
|
6118
6154
|
if (gen !== sceneGenRef.current) return;
|
|
6119
|
-
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob) }]);
|
|
6155
|
+
deliverResults([{ ...result, imageUrl: registerBlobUrl(blob, void 0, result.mockupId) }]);
|
|
6120
6156
|
} catch (err) {
|
|
6121
6157
|
if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
|
|
6122
6158
|
return;
|
|
6123
6159
|
}
|
|
6160
|
+
if (isFrameSupersededRef.current?.(result.imageUrl)) return;
|
|
6124
6161
|
const message = err instanceof Error ? err.message : String(err);
|
|
6125
6162
|
if (result.imageUrl.startsWith("blob:") && message.startsWith("E_OVERLAY_FRAME_LOAD") && message.includes(result.imageUrl.slice(0, 160))) {
|
|
6126
6163
|
const failedUrl = result.imageUrl;
|
|
@@ -6711,6 +6748,8 @@ function RealtimeProvider({
|
|
|
6711
6748
|
getLatestSentVersions: getLatestSentVersionsStable,
|
|
6712
6749
|
isMockupLoading,
|
|
6713
6750
|
registerBlobUrl,
|
|
6751
|
+
markBlobShown,
|
|
6752
|
+
releaseBlobConsumer,
|
|
6714
6753
|
// WebRTC streaming
|
|
6715
6754
|
subscribeRTCTiming
|
|
6716
6755
|
}),
|
|
@@ -6743,7 +6782,9 @@ function RealtimeProvider({
|
|
|
6743
6782
|
getCanvasVersion,
|
|
6744
6783
|
getLatestSentVersionsStable,
|
|
6745
6784
|
isMockupLoading,
|
|
6746
|
-
registerBlobUrl
|
|
6785
|
+
registerBlobUrl,
|
|
6786
|
+
markBlobShown,
|
|
6787
|
+
releaseBlobConsumer
|
|
6747
6788
|
]
|
|
6748
6789
|
);
|
|
6749
6790
|
return /* @__PURE__ */ jsx52(RealtimeContext.Provider, { value: contextValue, children });
|
|
@@ -10537,6 +10578,26 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10537
10578
|
};
|
|
10538
10579
|
}, [mode, realtimeContext?.subscribePendingBlob, placement]);
|
|
10539
10580
|
const renderVersionRef = useRef23(0);
|
|
10581
|
+
const arrivedVersionRef = useRef23(0);
|
|
10582
|
+
const versionByUrlRef = useRef23(/* @__PURE__ */ new Map());
|
|
10583
|
+
const loadedUrlRef = useRef23(null);
|
|
10584
|
+
const blobConsumerRef = useRef23(`el-${Math.random().toString(36).slice(2, 10)}`);
|
|
10585
|
+
const releaseBlobConsumer = realtimeContext?.releaseBlobConsumer;
|
|
10586
|
+
useEffect32(() => {
|
|
10587
|
+
const id = actualMockupId;
|
|
10588
|
+
const consumer = blobConsumerRef.current;
|
|
10589
|
+
return () => {
|
|
10590
|
+
if (id) releaseBlobConsumer?.(id, consumer);
|
|
10591
|
+
};
|
|
10592
|
+
}, [actualMockupId, releaseBlobConsumer]);
|
|
10593
|
+
const frameErrorRef = useRef23(null);
|
|
10594
|
+
const showVersionOf = useCallback18((url) => {
|
|
10595
|
+
const e = versionByUrlRef.current.get(url);
|
|
10596
|
+
if (!e || e.v < renderVersionRef.current) return;
|
|
10597
|
+
renderVersionRef.current = e.v;
|
|
10598
|
+
renderVersionsRef.current = e.versions;
|
|
10599
|
+
frameErrorRef.current = null;
|
|
10600
|
+
}, []);
|
|
10540
10601
|
const renderVersionsRef = useRef23(null);
|
|
10541
10602
|
const getLatestSentVersions = realtimeContext?.getLatestSentVersions;
|
|
10542
10603
|
const refusalCodeRef = useRef23(null);
|
|
@@ -10560,8 +10621,13 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10560
10621
|
const behind = versions && sent ? Object.entries(sent).some(([placement2, v]) => (versions[placement2] ?? -1) < v) : rendered < canvas;
|
|
10561
10622
|
node.dataset.canvasVersion = String(canvas);
|
|
10562
10623
|
node.dataset.renderVersion = String(rendered);
|
|
10624
|
+
node.dataset.arrivedVersion = String(arrivedVersionRef.current);
|
|
10625
|
+
if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
|
|
10626
|
+
else delete node.dataset.frameError;
|
|
10563
10627
|
node.dataset.renderState = refusalCodeRef.current || behind && sessionErrorCodeRef.current ? "refused" : behind ? "stale" : "current";
|
|
10564
10628
|
}, [getCanvasVersion, getLatestSentVersions]);
|
|
10629
|
+
const applyRenderStampRef = useRef23(applyRenderStamp);
|
|
10630
|
+
applyRenderStampRef.current = applyRenderStamp;
|
|
10565
10631
|
useEffect32(() => {
|
|
10566
10632
|
applyRenderStamp();
|
|
10567
10633
|
});
|
|
@@ -10571,9 +10637,13 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10571
10637
|
if (!actualMockupId || !subscribeSent || !subscribeResult) return;
|
|
10572
10638
|
const offSent = subscribeSent(() => applyRenderStamp());
|
|
10573
10639
|
const offResult = subscribeResult(actualMockupId, (result) => {
|
|
10574
|
-
if (typeof result?.requestVersion === "number"
|
|
10575
|
-
|
|
10576
|
-
|
|
10640
|
+
if (typeof result?.requestVersion === "number") {
|
|
10641
|
+
arrivedVersionRef.current = Math.max(arrivedVersionRef.current, result.requestVersion);
|
|
10642
|
+
const url = realtimeContext?.getMockupUrl?.(result.mockupId) ?? result.imageUrl;
|
|
10643
|
+
if (url) {
|
|
10644
|
+
versionByUrlRef.current.set(url, { v: result.requestVersion, versions: result.versions ?? null });
|
|
10645
|
+
if (url === loadedUrlRef.current) showVersionOf(url);
|
|
10646
|
+
}
|
|
10577
10647
|
}
|
|
10578
10648
|
applyRenderStamp();
|
|
10579
10649
|
});
|
|
@@ -10800,8 +10870,13 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10800
10870
|
};
|
|
10801
10871
|
if (preload.complete) startCrossfade();
|
|
10802
10872
|
else preload.onload = startCrossfade;
|
|
10873
|
+
preload.onerror = () => {
|
|
10874
|
+
frameErrorRef.current = "E_FRAME_UNAVAILABLE";
|
|
10875
|
+
applyRenderStampRef.current?.();
|
|
10876
|
+
};
|
|
10803
10877
|
return () => {
|
|
10804
10878
|
preload.onload = null;
|
|
10879
|
+
preload.onerror = null;
|
|
10805
10880
|
};
|
|
10806
10881
|
}, [displayUrl]);
|
|
10807
10882
|
const handleCrossfadeEnd = useCallback18(() => {
|
|
@@ -10881,6 +10956,12 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10881
10956
|
onLoad: () => {
|
|
10882
10957
|
setImgFailed(false);
|
|
10883
10958
|
setFirstImageLoaded(true);
|
|
10959
|
+
if (renderedUrl) {
|
|
10960
|
+
loadedUrlRef.current = renderedUrl;
|
|
10961
|
+
showVersionOf(renderedUrl);
|
|
10962
|
+
if (actualMockupId) realtimeContext?.markBlobShown?.(actualMockupId, renderedUrl, blobConsumerRef.current);
|
|
10963
|
+
applyRenderStampRef.current?.();
|
|
10964
|
+
}
|
|
10884
10965
|
if (!onLoadCalledRef.current && onLoad) {
|
|
10885
10966
|
onLoadCalledRef.current = true;
|
|
10886
10967
|
onLoad();
|