@snowcone-app/ui 0.10.1 → 0.10.3

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
@@ -3123,6 +3123,9 @@ interface RealtimeContextValue {
3123
3123
  registerBlobUrl: (blobOrUrl: Blob | string, placementName?: string) => string;
3124
3124
  /** A picture's <img> loaded `url` (from getMockupUrl): its older composited frames are released. */
3125
3125
  markBlobShown: (mockupId: string, url: string, consumer?: string) => void;
3126
+ /** A picture's img failed to load a delivered frame. With frame flow control, every frame must be reported done
3127
+ * (drawn via markBlobShown, or failed here), or the box waits for it until its ack timeout (E_RT_ACK_TIMEOUT). */
3128
+ frameFailed: (url: string) => void;
3126
3129
  /** An element that called markBlobShown unmounted: it no longer holds its frame. */
3127
3130
  releaseBlobConsumer: (mockupId: string, consumer: string) => void;
3128
3131
  }
@@ -4756,6 +4759,12 @@ interface CarouselImage {
4756
4759
  mockupId?: string;
4757
4760
  /** Aspect ratio of the mockup (e.g., 1.78 for 16:9) */
4758
4761
  aspectRatio?: number;
4762
+ /**
4763
+ * What this picture is in the gallery. 'size-picture': the picture of the chosen size (exactly one, last). The
4764
+ * realtime session renders it like any picture (the box renders each mockup at the variant it lists, rc#858).
4765
+ * Stamped data-gallery-role on the slide.
4766
+ */
4767
+ galleryRole?: "size-picture";
4759
4768
  }
4760
4769
  /**
4761
4770
  * Alias for CarouselImage - used in hero contexts for semantic clarity.
package/dist/index.d.ts CHANGED
@@ -3123,6 +3123,9 @@ interface RealtimeContextValue {
3123
3123
  registerBlobUrl: (blobOrUrl: Blob | string, placementName?: string) => string;
3124
3124
  /** A picture's <img> loaded `url` (from getMockupUrl): its older composited frames are released. */
3125
3125
  markBlobShown: (mockupId: string, url: string, consumer?: string) => void;
3126
+ /** A picture's img failed to load a delivered frame. With frame flow control, every frame must be reported done
3127
+ * (drawn via markBlobShown, or failed here), or the box waits for it until its ack timeout (E_RT_ACK_TIMEOUT). */
3128
+ frameFailed: (url: string) => void;
3126
3129
  /** An element that called markBlobShown unmounted: it no longer holds its frame. */
3127
3130
  releaseBlobConsumer: (mockupId: string, consumer: string) => void;
3128
3131
  }
@@ -4756,6 +4759,12 @@ interface CarouselImage {
4756
4759
  mockupId?: string;
4757
4760
  /** Aspect ratio of the mockup (e.g., 1.78 for 16:9) */
4758
4761
  aspectRatio?: number;
4762
+ /**
4763
+ * What this picture is in the gallery. 'size-picture': the picture of the chosen size (exactly one, last). The
4764
+ * realtime session renders it like any picture (the box renders each mockup at the variant it lists, rc#858).
4765
+ * Stamped data-gallery-role on the slide.
4766
+ */
4767
+ galleryRole?: "size-picture";
4759
4768
  }
4760
4769
  /**
4761
4770
  * Alias for CarouselImage - used in hero contexts for semantic clarity.
package/dist/index.js CHANGED
@@ -5625,7 +5625,7 @@ import {
5625
5625
  useMemo as useMemo7
5626
5626
  } from "react";
5627
5627
  import { useRealtimeMockup as useRealtimeMockup2 } from "@snowcone-app/sdk/react";
5628
- import { resolvePreviewVariantId, resolveVariantId as resolveVariantIdUtil } from "@snowcone-app/sdk";
5628
+ import { gallerySizePicture, mockupRole, resolvePreviewVariantId, resolveVariantId as resolveVariantIdUtil } from "@snowcone-app/sdk";
5629
5629
 
5630
5630
  // src/patterns/MockupBackground.tsx
5631
5631
  import { createContext as createContext7, useContext as useContext5 } from "react";
@@ -5790,6 +5790,7 @@ function RealtimeProvider({
5790
5790
  const configSentRef = useRef12(false);
5791
5791
  const placementSettingsOverridesRef = useRef12({});
5792
5792
  const lastSentVariantIdRef = useRef12(null);
5793
+ const lastSentSizePictureRef = useRef12(null);
5793
5794
  const lastSentBgRef = useRef12(void 0);
5794
5795
  const spreadCropsRef = useRef12(void 0);
5795
5796
  const [spreadCropsVersion, setSpreadCropsVersion] = useState17(0);
@@ -5861,7 +5862,8 @@ function RealtimeProvider({
5861
5862
  getLastSentVersion,
5862
5863
  getLatestSentVersions,
5863
5864
  rerender: rerenderRaw,
5864
- isFrameSuperseded
5865
+ isFrameSuperseded,
5866
+ ackFrame
5865
5867
  } = realtimeMockup;
5866
5868
  const isFrameSupersededRef = useRef12(isFrameSuperseded);
5867
5869
  isFrameSupersededRef.current = isFrameSuperseded;
@@ -5886,6 +5888,16 @@ function RealtimeProvider({
5886
5888
  const hasBlobInFlightRef = useRef12(false);
5887
5889
  const pipelineResetCooldownRef = useRef12(false);
5888
5890
  const dueByVersionRef = useRef12(/* @__PURE__ */ new Map());
5891
+ const frameByUrlRef = useRef12(/* @__PURE__ */ new Map());
5892
+ const ackFrameRef = useRef12(null);
5893
+ ackFrameRef.current = ackFrame;
5894
+ const ackUrl = useCallback10((url) => {
5895
+ const f = frameByUrlRef.current.get(url);
5896
+ if (f) ackFrameRef.current?.(f.mockupId, f.seq);
5897
+ }, []);
5898
+ const ackResultFrame = useCallback10((result) => {
5899
+ if (typeof result.seq === "number") ackFrameRef.current?.(result.mockupId, result.seq);
5900
+ }, []);
5889
5901
  const configuredMockupIdsRef = useRef12([]);
5890
5902
  const mockupUrlCacheRef = useRef12(/* @__PURE__ */ new Map());
5891
5903
  const registeredBlobUrlsRef = useRef12(/* @__PURE__ */ new Set());
@@ -5973,13 +5985,17 @@ function RealtimeProvider({
5973
5985
  blobsByOwnerRef.current.set(owner, list.slice(0, oldestShownIdx + 1));
5974
5986
  }, [revokeBlobUrl]);
5975
5987
  const markBlobShown = useCallback10((owner, url, consumer = "default") => {
5988
+ ackUrl(url);
5976
5989
  const list = blobsByOwnerRef.current.get(owner);
5977
5990
  if (!list || list.indexOf(url) < 0) return;
5978
5991
  const shown = shownBlobByOwnerRef.current.get(owner) ?? /* @__PURE__ */ new Map();
5979
5992
  shown.set(consumer, url);
5980
5993
  shownBlobByOwnerRef.current.set(owner, shown);
5981
5994
  releaseOlderFrames(owner);
5982
- }, [releaseOlderFrames]);
5995
+ }, [releaseOlderFrames, ackUrl]);
5996
+ const frameFailed = useCallback10((url) => {
5997
+ ackUrl(url);
5998
+ }, [ackUrl]);
5983
5999
  const releaseBlobConsumer = useCallback10((owner, consumer) => {
5984
6000
  const shown = shownBlobByOwnerRef.current.get(owner);
5985
6001
  if (!shown?.delete(consumer)) return;
@@ -6179,6 +6195,16 @@ function RealtimeProvider({
6179
6195
  const delivered = new Set(results.map((r) => r.mockupId));
6180
6196
  pendingRerenderRef.current = pendingRerenderRef.current.filter((id) => !delivered.has(id));
6181
6197
  }
6198
+ results.forEach((result) => {
6199
+ const seq = result.seq;
6200
+ if (typeof seq !== "number") return;
6201
+ const byUrl = frameByUrlRef.current;
6202
+ byUrl.set(result.imageUrl, { mockupId: result.mockupId, seq });
6203
+ if (byUrl.size > 1024) byUrl.delete(byUrl.keys().next().value);
6204
+ const shownUrl = mockupUrlCacheRef.current.get(result.mockupId)?.url;
6205
+ const watched = (mockupSubscribersByIdRef.current.get(result.mockupId)?.size ?? 0) > 0;
6206
+ if (!watched || shownUrl === result.imageUrl) ackFrameRef.current?.(result.mockupId, seq);
6207
+ });
6182
6208
  const clearedPlacements = /* @__PURE__ */ new Set();
6183
6209
  results.forEach((result) => {
6184
6210
  const wasPending = pendingMockupIdsRef.current.has(result.mockupId);
@@ -6212,17 +6238,21 @@ function RealtimeProvider({
6212
6238
  let newestSettled = 0;
6213
6239
  const due = dueByVersionRef.current;
6214
6240
  results.forEach((result) => {
6215
- const v = result.requestVersion;
6216
- if (v === void 0) return;
6217
- const entry = due.get(v);
6218
- if (!entry) return;
6219
- if (entry.due <= 1) {
6220
- due.delete(v);
6221
- settledVersions += 1;
6222
- newestSettled = Math.max(newestSettled, v);
6223
- } else {
6224
- entry.due -= 1;
6225
- }
6241
+ const w = result.requestVersion;
6242
+ if (w === void 0) return;
6243
+ due.forEach((entry, v) => {
6244
+ if (v > w) return;
6245
+ const seen = entry.seen ??= /* @__PURE__ */ new Set();
6246
+ if (seen.has(result.mockupId)) return;
6247
+ seen.add(result.mockupId);
6248
+ if (entry.due <= 1) {
6249
+ due.delete(v);
6250
+ settledVersions += 1;
6251
+ newestSettled = Math.max(newestSettled, v);
6252
+ } else {
6253
+ entry.due -= 1;
6254
+ }
6255
+ });
6226
6256
  });
6227
6257
  due.forEach((entry, v) => {
6228
6258
  if (now - entry.at > 1e4) due.delete(v);
@@ -6250,6 +6280,7 @@ function RealtimeProvider({
6250
6280
  console.error(
6251
6281
  `[RealtimeProvider] E_OVERLAY_NO_BACKGROUND: cropped frame for ${result.mockupId} has no frozen background \u2014 falling back to full-frame and re-rendering it.`
6252
6282
  );
6283
+ ackResultFrame(result);
6253
6284
  rerenderFullFrame(result.mockupId);
6254
6285
  return;
6255
6286
  }
@@ -6265,9 +6296,13 @@ function RealtimeProvider({
6265
6296
  rect: result.cropRect,
6266
6297
  canvas: compositeCanvasRef.current ?? void 0
6267
6298
  });
6268
- if (gen !== sceneGenRef.current) return;
6299
+ if (gen !== sceneGenRef.current) {
6300
+ ackResultFrame(result);
6301
+ return;
6302
+ }
6269
6303
  deliverResults([{ ...result, imageUrl: registerBlobUrl(blob, void 0, result.mockupId) }]);
6270
6304
  } catch (err) {
6305
+ ackResultFrame(result);
6271
6306
  if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
6272
6307
  return;
6273
6308
  }
@@ -6296,7 +6331,7 @@ function RealtimeProvider({
6296
6331
  rerenderFullFrame(result.mockupId);
6297
6332
  }
6298
6333
  },
6299
- [deliverResults, registerBlobUrl, rerenderFullFrame]
6334
+ [deliverResults, registerBlobUrl, rerenderFullFrame, ackResultFrame]
6300
6335
  );
6301
6336
  const pumpCompositeQueue = useCallback10(
6302
6337
  (mockupId) => {
@@ -6446,10 +6481,13 @@ function RealtimeProvider({
6446
6481
  );
6447
6482
  const isFirstSend = !configSentRef.current;
6448
6483
  const variantChanged = lastSentVariantIdRef.current !== null && lastSentVariantIdRef.current !== variantId;
6484
+ const sizePicture = gallerySizePicture(product.mockups, resolveVariantIdUtil(productContext, void 0, void 0));
6485
+ const sizePictureId = sizePicture?.id ?? null;
6486
+ const sizePictureChanged = configSentRef.current && lastSentSizePictureRef.current !== sizePictureId;
6449
6487
  const bgChanged = configSentRef.current && lastSentBgRef.current !== mockupBg;
6450
6488
  const spreadCropsJson = JSON.stringify(spreadCropsRef.current ?? null);
6451
6489
  const spreadCropsChanged = configSentRef.current && lastSentSpreadCropsRef.current !== spreadCropsJson;
6452
- if (!isFirstSend && !variantChanged && !bgChanged && !spreadCropsChanged) {
6490
+ if (!isFirstSend && !variantChanged && !bgChanged && !spreadCropsChanged && !sizePictureChanged) {
6453
6491
  return;
6454
6492
  }
6455
6493
  if (variantChanged || bgChanged) {
@@ -6458,11 +6496,15 @@ function RealtimeProvider({
6458
6496
  const mockupIds = [];
6459
6497
  if (product.mockups && Array.isArray(product.mockups)) {
6460
6498
  product.mockups.forEach((mockup) => {
6461
- if (mockup.id) {
6499
+ if (mockup.id && mockupRole(mockup) === "ordinary") {
6462
6500
  mockupIds.push(mockup.id);
6463
6501
  }
6464
6502
  });
6465
6503
  }
6504
+ if (sizePictureId) mockupIds.push(sizePictureId);
6505
+ if (croppedActiveRef.current && mockupIds.some((id) => !backgroundsRef.current.has(id))) {
6506
+ croppedActiveRef.current = false;
6507
+ }
6466
6508
  configuredMockupIdsRef.current = mockupIds;
6467
6509
  const shape = currentShape();
6468
6510
  lastShapeRef.current = shape;
@@ -6474,7 +6516,11 @@ function RealtimeProvider({
6474
6516
  width: shape.width,
6475
6517
  ...mockupBg ? { bg: mockupBg } : {},
6476
6518
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6477
- placementSettings: { ...placementSettingsOverridesRef.current }
6519
+ placementSettings: { ...placementSettingsOverridesRef.current },
6520
+ // Frame flow control: this provider acks every frame it is done with (drawn / superseded / not shown /
6521
+ // failed), so the box can coalesce instead of queueing a backlog behind Cloudflare. Dormant on boxes
6522
+ // that don't negotiate it.
6523
+ acks: true
6478
6524
  } : {
6479
6525
  productId,
6480
6526
  mockupIds: shape.mockupIds,
@@ -6484,7 +6530,11 @@ function RealtimeProvider({
6484
6530
  width: shape.width,
6485
6531
  ...mockupBg ? { bg: mockupBg } : {},
6486
6532
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6487
- placementSettings: { ...placementSettingsOverridesRef.current }
6533
+ placementSettings: { ...placementSettingsOverridesRef.current },
6534
+ // Frame flow control: this provider acks every frame it is done with (drawn / superseded / not shown /
6535
+ // failed), so the box can coalesce instead of queueing a backlog behind Cloudflare. Dormant on boxes
6536
+ // that don't negotiate it.
6537
+ acks: true
6488
6538
  };
6489
6539
  if (variantChanged) {
6490
6540
  const imagePlacements = placements.filter((p) => p.type === "image");
@@ -6499,6 +6549,7 @@ function RealtimeProvider({
6499
6549
  );
6500
6550
  configSentRef.current = true;
6501
6551
  lastSentVariantIdRef.current = variantId;
6552
+ lastSentSizePictureRef.current = sizePictureId;
6502
6553
  lastSentBgRef.current = mockupBg;
6503
6554
  lastSentSpreadCropsRef.current = spreadCropsJson;
6504
6555
  setTimeout(() => {
@@ -6702,6 +6753,7 @@ function RealtimeProvider({
6702
6753
  const pendingIds = [];
6703
6754
  if (productContext?.product?.mockups) {
6704
6755
  productContext.product.mockups.forEach((mockup) => {
6756
+ if (mockupRole(mockup) !== "ordinary" && !configuredMockupIdsRef.current.includes(mockup.id)) return;
6705
6757
  if (mockup.placement === placement || !mockup.placement) {
6706
6758
  pendingMockupIdsRef.current.add(mockup.id);
6707
6759
  pendingIds.push(mockup.id);
@@ -6891,6 +6943,7 @@ function RealtimeProvider({
6891
6943
  isMockupLoading,
6892
6944
  registerBlobUrl,
6893
6945
  markBlobShown,
6946
+ frameFailed,
6894
6947
  releaseBlobConsumer,
6895
6948
  // WebRTC streaming
6896
6949
  subscribeRTCTiming
@@ -6928,6 +6981,7 @@ function RealtimeProvider({
6928
6981
  isMockupLoading,
6929
6982
  registerBlobUrl,
6930
6983
  markBlobShown,
6984
+ frameFailed,
6931
6985
  releaseBlobConsumer
6932
6986
  ]
6933
6987
  );
@@ -10747,6 +10801,8 @@ var HeroProductImage = memo3(function HeroProductImage2({
10747
10801
  const getLatestSentVersions = realtimeContext?.getLatestSentVersions;
10748
10802
  const refusalCodeRef = useRef23(null);
10749
10803
  refusalCodeRef.current = unavailable?.code ?? null;
10804
+ const frameFailedRef = useRef23(realtimeContext?.frameFailed);
10805
+ frameFailedRef.current = realtimeContext?.frameFailed;
10750
10806
  const sessionErrorCodeRef = useRef23(null);
10751
10807
  sessionErrorCodeRef.current = realtimeContext?.renderError?.code ?? null;
10752
10808
  const getCanvasVersion = realtimeContext?.getCanvasVersion;
@@ -10754,6 +10810,12 @@ var HeroProductImage = memo3(function HeroProductImage2({
10754
10810
  const applyRenderStamp = useCallback18(() => {
10755
10811
  const node = containerRef.current;
10756
10812
  if (!node) return;
10813
+ if (mode === "static") {
10814
+ delete node.dataset.canvasVersion;
10815
+ delete node.dataset.renderVersion;
10816
+ node.dataset.renderState = "static";
10817
+ return;
10818
+ }
10757
10819
  const canvas = getCanvasVersion?.() ?? 0;
10758
10820
  if (canvas <= 0) {
10759
10821
  delete node.dataset.canvasVersion;
@@ -10778,7 +10840,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
10778
10840
  node.dataset.wantedWidth = String(shape.width);
10779
10841
  node.dataset.sessionPhase = shape.phase;
10780
10842
  }
10781
- }, [getCanvasVersion, getLatestSentVersions, getSessionShape]);
10843
+ }, [getCanvasVersion, getLatestSentVersions, getSessionShape, mode]);
10782
10844
  const applyRenderStampRef = useRef23(applyRenderStamp);
10783
10845
  applyRenderStampRef.current = applyRenderStamp;
10784
10846
  useEffect32(() => {
@@ -11058,6 +11120,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
11058
11120
  else preload.onload = startCrossfade;
11059
11121
  preload.onerror = () => {
11060
11122
  frameErrorRef.current = "E_FRAME_UNAVAILABLE";
11123
+ frameFailedRef.current?.(displayUrl);
11061
11124
  applyRenderStampRef.current?.();
11062
11125
  };
11063
11126
  return () => {
@@ -11163,6 +11226,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
11163
11226
  }
11164
11227
  setImgFailed(true);
11165
11228
  setFirstImageLoaded(true);
11229
+ if (renderedUrl) realtimeContext?.frameFailed?.(renderedUrl);
11166
11230
  onError?.();
11167
11231
  if (process.env.NODE_ENV !== "production" && !signHintShownRef.current && renderedUrl && /\/[A-Za-z0-9]+\?/.test(renderedUrl) && !/[?&]signature=/.test(renderedUrl)) {
11168
11232
  signHintShownRef.current = true;
@@ -13225,6 +13289,8 @@ var MobileProductCarousel = memo4(function MobileProductCarousel2({
13225
13289
  "div",
13226
13290
  {
13227
13291
  className: "w-full h-full flex-shrink-0 relative select-none",
13292
+ "data-gallery-role": image.galleryRole,
13293
+ "data-mockup-id": image.galleryRole ? image.mockupId : void 0,
13228
13294
  children: [
13229
13295
  !isWithinDecodeWindow ? /* @__PURE__ */ jsx74("div", { className: "w-full h-full bg-muted" }) : image.isPlaceholder ? (
13230
13296
  // Rainbow prism loader (same as the /create route) instead of