@snowcone-app/ui 0.10.1 → 0.10.4

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,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`72cfddc`](https://github.com/snowcone-app/snowcone-monorepo/commit/72cfddc99569dda4ead08c07c11a8af9fc711f2b)]:
8
+ - @snowcone-app/sdk@0.27.1
9
+
10
+ ## 0.10.3
11
+
12
+ ### Patch Changes
13
+
14
+ - [#4482](https://github.com/snowcone-app/snowcone-monorepo/pull/4482) [`74f36f5`](https://github.com/snowcone-app/snowcone-monorepo/commit/74f36f5690c71d26f1e1a13478062ab458bbdccd) Thanks [@kevinsproles](https://github.com/kevinsproles)! - The chosen size's picture joins the realtime session (the render box renders each mockup at the variant it lists, rendercenter rc#858). Changing the size sends one config with the new size's picture. The other sizes are never rendered and never pending.
15
+
16
+ ## 0.10.2
17
+
18
+ ### Patch Changes
19
+
20
+ - [#4455](https://github.com/snowcone-app/snowcone-monorepo/pull/4455) [`965c3d6`](https://github.com/snowcone-app/snowcone-monorepo/commit/965c3d647258bf8735bdda6080f27cb42305a406) Thanks [@kevinsproles](https://github.com/kevinsproles)! - Realtime frame flow control. With `config.acks`, the box keeps at most `window` un-acked frames per mockup and sends only the newest when the client falls behind, instead of queueing a backlog behind Cloudflare.
21
+ - **SDK:** `ackFrame(mockupId, seq)` is a cumulative per-mockup ack, batched once per animation frame. The service acks superseded and stale-dropped frames itself, and updates state per frame while acking. `E_RT_ACK_TIMEOUT` and `E_RT_ACK_BAD` are typed faults (`state.acks`, `onAckFault`), never `renderError` or a picture refusal.
22
+ - **UI:** `RealtimeProvider` asks for acks and reports every frame done: drawn (`markBlobShown`), failed (`frameFailed`), not shown, or a dropped or failed composite. A version the box coalesced away settles once each mockup has a newer frame.
23
+ - **Older boxes:** stay unchanged. Acks are dormant until `config_received` carries them.
24
+
25
+ - [#4474](https://github.com/snowcone-app/snowcone-monorepo/pull/4474) [`e41bdc8`](https://github.com/snowcone-app/snowcone-monorepo/commit/e41bdc8293a5b20e199402047d416f17b6e9113e) Thanks [@kevinsproles](https://github.com/kevinsproles)! - Size pictures (`linkedAs: 'size-picture'`, the picture of one size). The product gallery shows exactly one, the chosen size's, last. No "picture for this product / variant" lookup ever returns one.
26
+ - **SDK:** `mockupRole`, `ordinaryMockups` (a branded list), `pictureForVariant`, `primaryMockup` and `gallerySizePicture`. `getVariant`, `resolveMockupId` and `resolvePreviewVariantId` search ordinary mockups only. A size that no ordinary mockup lists gets the product's fallback picture. `linkedAs` is declared in the product schema and the zod schema.
27
+ - **UI:** `CarouselImage.galleryRole`. Slides carry `data-gallery-role` and `data-mockup-id`. A size picture renders on the per-picture URL path (`HeroProductImage mode="static"`, which stamps `data-render-state="static"`). Until the render box resolves the variant per mockup, `RealtimeProvider` leaves size pictures out of the session and never marks one pending.
28
+
29
+ - Updated dependencies [[`965c3d6`](https://github.com/snowcone-app/snowcone-monorepo/commit/965c3d647258bf8735bdda6080f27cb42305a406), [`e41bdc8`](https://github.com/snowcone-app/snowcone-monorepo/commit/e41bdc8293a5b20e199402047d416f17b6e9113e)]:
30
+ - @snowcone-app/sdk@0.27.0
31
+
3
32
  ## 0.10.1
4
33
 
5
34
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -6149,6 +6149,7 @@ function RealtimeProvider({
6149
6149
  const configSentRef = (0, import_react25.useRef)(false);
6150
6150
  const placementSettingsOverridesRef = (0, import_react25.useRef)({});
6151
6151
  const lastSentVariantIdRef = (0, import_react25.useRef)(null);
6152
+ const lastSentSizePictureRef = (0, import_react25.useRef)(null);
6152
6153
  const lastSentBgRef = (0, import_react25.useRef)(void 0);
6153
6154
  const spreadCropsRef = (0, import_react25.useRef)(void 0);
6154
6155
  const [spreadCropsVersion, setSpreadCropsVersion] = (0, import_react25.useState)(0);
@@ -6220,7 +6221,8 @@ function RealtimeProvider({
6220
6221
  getLastSentVersion,
6221
6222
  getLatestSentVersions,
6222
6223
  rerender: rerenderRaw,
6223
- isFrameSuperseded
6224
+ isFrameSuperseded,
6225
+ ackFrame
6224
6226
  } = realtimeMockup;
6225
6227
  const isFrameSupersededRef = (0, import_react25.useRef)(isFrameSuperseded);
6226
6228
  isFrameSupersededRef.current = isFrameSuperseded;
@@ -6245,6 +6247,16 @@ function RealtimeProvider({
6245
6247
  const hasBlobInFlightRef = (0, import_react25.useRef)(false);
6246
6248
  const pipelineResetCooldownRef = (0, import_react25.useRef)(false);
6247
6249
  const dueByVersionRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
6250
+ const frameByUrlRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
6251
+ const ackFrameRef = (0, import_react25.useRef)(null);
6252
+ ackFrameRef.current = ackFrame;
6253
+ const ackUrl = (0, import_react25.useCallback)((url) => {
6254
+ const f = frameByUrlRef.current.get(url);
6255
+ if (f) ackFrameRef.current?.(f.mockupId, f.seq);
6256
+ }, []);
6257
+ const ackResultFrame = (0, import_react25.useCallback)((result) => {
6258
+ if (typeof result.seq === "number") ackFrameRef.current?.(result.mockupId, result.seq);
6259
+ }, []);
6248
6260
  const configuredMockupIdsRef = (0, import_react25.useRef)([]);
6249
6261
  const mockupUrlCacheRef = (0, import_react25.useRef)(/* @__PURE__ */ new Map());
6250
6262
  const registeredBlobUrlsRef = (0, import_react25.useRef)(/* @__PURE__ */ new Set());
@@ -6332,13 +6344,17 @@ function RealtimeProvider({
6332
6344
  blobsByOwnerRef.current.set(owner, list.slice(0, oldestShownIdx + 1));
6333
6345
  }, [revokeBlobUrl]);
6334
6346
  const markBlobShown = (0, import_react25.useCallback)((owner, url, consumer = "default") => {
6347
+ ackUrl(url);
6335
6348
  const list = blobsByOwnerRef.current.get(owner);
6336
6349
  if (!list || list.indexOf(url) < 0) return;
6337
6350
  const shown = shownBlobByOwnerRef.current.get(owner) ?? /* @__PURE__ */ new Map();
6338
6351
  shown.set(consumer, url);
6339
6352
  shownBlobByOwnerRef.current.set(owner, shown);
6340
6353
  releaseOlderFrames(owner);
6341
- }, [releaseOlderFrames]);
6354
+ }, [releaseOlderFrames, ackUrl]);
6355
+ const frameFailed = (0, import_react25.useCallback)((url) => {
6356
+ ackUrl(url);
6357
+ }, [ackUrl]);
6342
6358
  const releaseBlobConsumer = (0, import_react25.useCallback)((owner, consumer) => {
6343
6359
  const shown = shownBlobByOwnerRef.current.get(owner);
6344
6360
  if (!shown?.delete(consumer)) return;
@@ -6538,6 +6554,16 @@ function RealtimeProvider({
6538
6554
  const delivered = new Set(results.map((r) => r.mockupId));
6539
6555
  pendingRerenderRef.current = pendingRerenderRef.current.filter((id) => !delivered.has(id));
6540
6556
  }
6557
+ results.forEach((result) => {
6558
+ const seq = result.seq;
6559
+ if (typeof seq !== "number") return;
6560
+ const byUrl = frameByUrlRef.current;
6561
+ byUrl.set(result.imageUrl, { mockupId: result.mockupId, seq });
6562
+ if (byUrl.size > 1024) byUrl.delete(byUrl.keys().next().value);
6563
+ const shownUrl = mockupUrlCacheRef.current.get(result.mockupId)?.url;
6564
+ const watched = (mockupSubscribersByIdRef.current.get(result.mockupId)?.size ?? 0) > 0;
6565
+ if (!watched || shownUrl === result.imageUrl) ackFrameRef.current?.(result.mockupId, seq);
6566
+ });
6541
6567
  const clearedPlacements = /* @__PURE__ */ new Set();
6542
6568
  results.forEach((result) => {
6543
6569
  const wasPending = pendingMockupIdsRef.current.has(result.mockupId);
@@ -6571,17 +6597,21 @@ function RealtimeProvider({
6571
6597
  let newestSettled = 0;
6572
6598
  const due = dueByVersionRef.current;
6573
6599
  results.forEach((result) => {
6574
- const v = result.requestVersion;
6575
- if (v === void 0) return;
6576
- const entry = due.get(v);
6577
- if (!entry) return;
6578
- if (entry.due <= 1) {
6579
- due.delete(v);
6580
- settledVersions += 1;
6581
- newestSettled = Math.max(newestSettled, v);
6582
- } else {
6583
- entry.due -= 1;
6584
- }
6600
+ const w = result.requestVersion;
6601
+ if (w === void 0) return;
6602
+ due.forEach((entry, v) => {
6603
+ if (v > w) return;
6604
+ const seen = entry.seen ??= /* @__PURE__ */ new Set();
6605
+ if (seen.has(result.mockupId)) return;
6606
+ seen.add(result.mockupId);
6607
+ if (entry.due <= 1) {
6608
+ due.delete(v);
6609
+ settledVersions += 1;
6610
+ newestSettled = Math.max(newestSettled, v);
6611
+ } else {
6612
+ entry.due -= 1;
6613
+ }
6614
+ });
6585
6615
  });
6586
6616
  due.forEach((entry, v) => {
6587
6617
  if (now - entry.at > 1e4) due.delete(v);
@@ -6609,6 +6639,7 @@ function RealtimeProvider({
6609
6639
  console.error(
6610
6640
  `[RealtimeProvider] E_OVERLAY_NO_BACKGROUND: cropped frame for ${result.mockupId} has no frozen background \u2014 falling back to full-frame and re-rendering it.`
6611
6641
  );
6642
+ ackResultFrame(result);
6612
6643
  rerenderFullFrame(result.mockupId);
6613
6644
  return;
6614
6645
  }
@@ -6624,9 +6655,13 @@ function RealtimeProvider({
6624
6655
  rect: result.cropRect,
6625
6656
  canvas: compositeCanvasRef.current ?? void 0
6626
6657
  });
6627
- if (gen !== sceneGenRef.current) return;
6658
+ if (gen !== sceneGenRef.current) {
6659
+ ackResultFrame(result);
6660
+ return;
6661
+ }
6628
6662
  deliverResults([{ ...result, imageUrl: registerBlobUrl(blob, void 0, result.mockupId) }]);
6629
6663
  } catch (err) {
6664
+ ackResultFrame(result);
6630
6665
  if (gen !== sceneGenRef.current || compositeQueueRef.current.has(result.mockupId) || processedFrameRef.current.get(result.mockupId) !== result.imageUrl) {
6631
6666
  return;
6632
6667
  }
@@ -6655,7 +6690,7 @@ function RealtimeProvider({
6655
6690
  rerenderFullFrame(result.mockupId);
6656
6691
  }
6657
6692
  },
6658
- [deliverResults, registerBlobUrl, rerenderFullFrame]
6693
+ [deliverResults, registerBlobUrl, rerenderFullFrame, ackResultFrame]
6659
6694
  );
6660
6695
  const pumpCompositeQueue = (0, import_react25.useCallback)(
6661
6696
  (mockupId) => {
@@ -6805,10 +6840,13 @@ function RealtimeProvider({
6805
6840
  );
6806
6841
  const isFirstSend = !configSentRef.current;
6807
6842
  const variantChanged = lastSentVariantIdRef.current !== null && lastSentVariantIdRef.current !== variantId;
6843
+ const sizePicture = (0, import_sdk8.gallerySizePicture)(product.mockups, (0, import_sdk8.resolveVariantId)(productContext, void 0, void 0));
6844
+ const sizePictureId = sizePicture?.id ?? null;
6845
+ const sizePictureChanged = configSentRef.current && lastSentSizePictureRef.current !== sizePictureId;
6808
6846
  const bgChanged = configSentRef.current && lastSentBgRef.current !== mockupBg;
6809
6847
  const spreadCropsJson = JSON.stringify(spreadCropsRef.current ?? null);
6810
6848
  const spreadCropsChanged = configSentRef.current && lastSentSpreadCropsRef.current !== spreadCropsJson;
6811
- if (!isFirstSend && !variantChanged && !bgChanged && !spreadCropsChanged) {
6849
+ if (!isFirstSend && !variantChanged && !bgChanged && !spreadCropsChanged && !sizePictureChanged) {
6812
6850
  return;
6813
6851
  }
6814
6852
  if (variantChanged || bgChanged) {
@@ -6817,11 +6855,15 @@ function RealtimeProvider({
6817
6855
  const mockupIds = [];
6818
6856
  if (product.mockups && Array.isArray(product.mockups)) {
6819
6857
  product.mockups.forEach((mockup) => {
6820
- if (mockup.id) {
6858
+ if (mockup.id && (0, import_sdk8.mockupRole)(mockup) === "ordinary") {
6821
6859
  mockupIds.push(mockup.id);
6822
6860
  }
6823
6861
  });
6824
6862
  }
6863
+ if (sizePictureId) mockupIds.push(sizePictureId);
6864
+ if (croppedActiveRef.current && mockupIds.some((id) => !backgroundsRef.current.has(id))) {
6865
+ croppedActiveRef.current = false;
6866
+ }
6825
6867
  configuredMockupIdsRef.current = mockupIds;
6826
6868
  const shape = currentShape();
6827
6869
  lastShapeRef.current = shape;
@@ -6833,7 +6875,11 @@ function RealtimeProvider({
6833
6875
  width: shape.width,
6834
6876
  ...mockupBg ? { bg: mockupBg } : {},
6835
6877
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6836
- placementSettings: { ...placementSettingsOverridesRef.current }
6878
+ placementSettings: { ...placementSettingsOverridesRef.current },
6879
+ // Frame flow control: this provider acks every frame it is done with (drawn / superseded / not shown /
6880
+ // failed), so the box can coalesce instead of queueing a backlog behind Cloudflare. Dormant on boxes
6881
+ // that don't negotiate it.
6882
+ acks: true
6837
6883
  } : {
6838
6884
  productId,
6839
6885
  mockupIds: shape.mockupIds,
@@ -6843,7 +6889,11 @@ function RealtimeProvider({
6843
6889
  width: shape.width,
6844
6890
  ...mockupBg ? { bg: mockupBg } : {},
6845
6891
  ...spreadCropsRef.current ? { spreadCrops: spreadCropsRef.current } : {},
6846
- placementSettings: { ...placementSettingsOverridesRef.current }
6892
+ placementSettings: { ...placementSettingsOverridesRef.current },
6893
+ // Frame flow control: this provider acks every frame it is done with (drawn / superseded / not shown /
6894
+ // failed), so the box can coalesce instead of queueing a backlog behind Cloudflare. Dormant on boxes
6895
+ // that don't negotiate it.
6896
+ acks: true
6847
6897
  };
6848
6898
  if (variantChanged) {
6849
6899
  const imagePlacements = placements.filter((p) => p.type === "image");
@@ -6858,6 +6908,7 @@ function RealtimeProvider({
6858
6908
  );
6859
6909
  configSentRef.current = true;
6860
6910
  lastSentVariantIdRef.current = variantId;
6911
+ lastSentSizePictureRef.current = sizePictureId;
6861
6912
  lastSentBgRef.current = mockupBg;
6862
6913
  lastSentSpreadCropsRef.current = spreadCropsJson;
6863
6914
  setTimeout(() => {
@@ -7061,6 +7112,7 @@ function RealtimeProvider({
7061
7112
  const pendingIds = [];
7062
7113
  if (productContext?.product?.mockups) {
7063
7114
  productContext.product.mockups.forEach((mockup) => {
7115
+ if ((0, import_sdk8.mockupRole)(mockup) !== "ordinary" && !configuredMockupIdsRef.current.includes(mockup.id)) return;
7064
7116
  if (mockup.placement === placement || !mockup.placement) {
7065
7117
  pendingMockupIdsRef.current.add(mockup.id);
7066
7118
  pendingIds.push(mockup.id);
@@ -7250,6 +7302,7 @@ function RealtimeProvider({
7250
7302
  isMockupLoading,
7251
7303
  registerBlobUrl,
7252
7304
  markBlobShown,
7305
+ frameFailed,
7253
7306
  releaseBlobConsumer,
7254
7307
  // WebRTC streaming
7255
7308
  subscribeRTCTiming
@@ -7287,6 +7340,7 @@ function RealtimeProvider({
7287
7340
  isMockupLoading,
7288
7341
  registerBlobUrl,
7289
7342
  markBlobShown,
7343
+ frameFailed,
7290
7344
  releaseBlobConsumer
7291
7345
  ]
7292
7346
  );
@@ -11065,6 +11119,8 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
11065
11119
  const getLatestSentVersions = realtimeContext?.getLatestSentVersions;
11066
11120
  const refusalCodeRef = (0, import_react46.useRef)(null);
11067
11121
  refusalCodeRef.current = unavailable?.code ?? null;
11122
+ const frameFailedRef = (0, import_react46.useRef)(realtimeContext?.frameFailed);
11123
+ frameFailedRef.current = realtimeContext?.frameFailed;
11068
11124
  const sessionErrorCodeRef = (0, import_react46.useRef)(null);
11069
11125
  sessionErrorCodeRef.current = realtimeContext?.renderError?.code ?? null;
11070
11126
  const getCanvasVersion = realtimeContext?.getCanvasVersion;
@@ -11072,6 +11128,12 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
11072
11128
  const applyRenderStamp = (0, import_react46.useCallback)(() => {
11073
11129
  const node = containerRef.current;
11074
11130
  if (!node) return;
11131
+ if (mode === "static") {
11132
+ delete node.dataset.canvasVersion;
11133
+ delete node.dataset.renderVersion;
11134
+ node.dataset.renderState = "static";
11135
+ return;
11136
+ }
11075
11137
  const canvas = getCanvasVersion?.() ?? 0;
11076
11138
  if (canvas <= 0) {
11077
11139
  delete node.dataset.canvasVersion;
@@ -11096,7 +11158,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
11096
11158
  node.dataset.wantedWidth = String(shape.width);
11097
11159
  node.dataset.sessionPhase = shape.phase;
11098
11160
  }
11099
- }, [getCanvasVersion, getLatestSentVersions, getSessionShape]);
11161
+ }, [getCanvasVersion, getLatestSentVersions, getSessionShape, mode]);
11100
11162
  const applyRenderStampRef = (0, import_react46.useRef)(applyRenderStamp);
11101
11163
  applyRenderStampRef.current = applyRenderStamp;
11102
11164
  (0, import_react46.useEffect)(() => {
@@ -11376,6 +11438,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
11376
11438
  else preload.onload = startCrossfade;
11377
11439
  preload.onerror = () => {
11378
11440
  frameErrorRef.current = "E_FRAME_UNAVAILABLE";
11441
+ frameFailedRef.current?.(displayUrl);
11379
11442
  applyRenderStampRef.current?.();
11380
11443
  };
11381
11444
  return () => {
@@ -11481,6 +11544,7 @@ var HeroProductImage = (0, import_react46.memo)(function HeroProductImage2({
11481
11544
  }
11482
11545
  setImgFailed(true);
11483
11546
  setFirstImageLoaded(true);
11547
+ if (renderedUrl) realtimeContext?.frameFailed?.(renderedUrl);
11484
11548
  onError?.();
11485
11549
  if (process.env.NODE_ENV !== "production" && !signHintShownRef.current && renderedUrl && /\/[A-Za-z0-9]+\?/.test(renderedUrl) && !/[?&]signature=/.test(renderedUrl)) {
11486
11550
  signHintShownRef.current = true;
@@ -13524,6 +13588,8 @@ var MobileProductCarousel = (0, import_react56.memo)(function MobileProductCarou
13524
13588
  "div",
13525
13589
  {
13526
13590
  className: "w-full h-full flex-shrink-0 relative select-none",
13591
+ "data-gallery-role": image.galleryRole,
13592
+ "data-mockup-id": image.galleryRole ? image.mockupId : void 0,
13527
13593
  children: [
13528
13594
  !isWithinDecodeWindow ? /* @__PURE__ */ (0, import_jsx_runtime74.jsx)("div", { className: "w-full h-full bg-muted" }) : image.isPlaceholder ? (
13529
13595
  // Rainbow prism loader (same as the /create route) instead of