@snowcone-app/ui 0.10.17 → 0.10.20
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 +25 -0
- package/dist/index.cjs +59 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +59 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/composed/HeroProductImage.tsx +42 -7
- package/src/composed/__tests__/HeroProductImage.strip.test.tsx +53 -0
- package/src/composed/carousels/types.ts +6 -0
- package/src/patterns/RealtimeProvider.tsx +63 -2
- package/src/patterns/__tests__/RealtimeProvider.views.test.tsx +90 -0
- package/src/patterns/__tests__/croppedFrameComposite.test.ts +12 -0
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ import * as React$1 from 'react';
|
|
|
5
5
|
import React__default, { ReactNode, CSSProperties, RefObject } from 'react';
|
|
6
6
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
7
7
|
import { VariantProps } from 'class-variance-authority';
|
|
8
|
-
import { ProductPriceOptions, CatalogProduct, ImageAlignment, OptionSelection, ProductContext as ProductContext$1, WebSocketConfig, DesignElement, RealtimeRenderError, ProductArtAlignmentOptions, ProductArtAlignmentContext, ArtworkData } from '@snowcone-app/sdk';
|
|
8
|
+
import { ProductPriceOptions, CatalogProduct, ImageAlignment, OptionSelection, ProductContext as ProductContext$1, WebSocketConfig, DesignElement, RealtimeRenderError, MockupView, ProductArtAlignmentOptions, ProductArtAlignmentContext, ArtworkData } from '@snowcone-app/sdk';
|
|
9
9
|
export { ArtworkData, AspectRatio, ImageAlignment, ProductArtAlignmentContext, ProductArtAlignmentOptions, ProductData, ProductMockupData, ProductPlacement, ProductVariant, WebSocketConfig, describeProductArtAlignment, getMockupUrl, getProduct, getSnapPoints, listProducts } from '@snowcone-app/sdk';
|
|
10
10
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
11
11
|
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
|
|
@@ -3091,6 +3091,17 @@ interface RealtimeContextValue {
|
|
|
3091
3091
|
} | null;
|
|
3092
3092
|
/** The design editor opened or closed (Done). Drives the viewport policy's phase; see `editorOpen`. */
|
|
3093
3093
|
setEditorOpen: (open: boolean) => void;
|
|
3094
|
+
/**
|
|
3095
|
+
* The crop of each plate's 8:3 strip the page's hero shows (`view=<r>@<f>`, lane shapes #5520): those mockups' live
|
|
3096
|
+
* frames come as the same crop (rendercenter rc#898), so an edit drops into the hero's box. Re-sent on every config;
|
|
3097
|
+
* a change re-sends the config and re-seeds the cropped-delivery backgrounds (they are the old crop). `{}` = none.
|
|
3098
|
+
*/
|
|
3099
|
+
setMockupViews: (views: Readonly<Record<string, MockupView>>) => void;
|
|
3100
|
+
/**
|
|
3101
|
+
* What a frame URL this provider handed out is: the view it was rendered as, `null` for a full 16:9 frame, `undefined`
|
|
3102
|
+
* for a URL it did not hand out (a static picture).
|
|
3103
|
+
*/
|
|
3104
|
+
frameViewOf: (url: string) => MockupView | null | undefined;
|
|
3094
3105
|
flushPendingBlobs: () => void;
|
|
3095
3106
|
hasPendingBlobs: () => boolean;
|
|
3096
3107
|
subscribePipelineSettled: (callback: () => void) => () => void;
|
|
@@ -4448,6 +4459,15 @@ interface HeroProductImageProps {
|
|
|
4448
4459
|
* phone, where cover would cut a 16:9 frame to its centre). Stamped as data-fit.
|
|
4449
4460
|
*/
|
|
4450
4461
|
fit?: "cover" | "whole";
|
|
4462
|
+
/**
|
|
4463
|
+
* Ask for a crop of the mockup's 8:3 strip (`aspect=8:3&view=<r>@<f>`, no width: the crop comes at its own px), or
|
|
4464
|
+
* `"whole-strip"` (`aspect=8:3` at the measured width: a window wider than the crop grid), instead of a width-sized
|
|
4465
|
+
* 16:9 picture: the desktop hero of a mockup whose catalog entry carries `strip` (www heroStrip.ts). Only the static
|
|
4466
|
+
* picture follows it; realtime frames (an edit) stay the session's 16:9. Stamped as data-strip-view.
|
|
4467
|
+
*/
|
|
4468
|
+
stripView?: MockupView | "whole-strip";
|
|
4469
|
+
/** Called with the URL of each picture once it is ON SCREEN (its <img> loaded), not when it is asked for. */
|
|
4470
|
+
onShown?: (url: string) => void;
|
|
4451
4471
|
}
|
|
4452
4472
|
/**
|
|
4453
4473
|
* Hero-compatible version of ProductImage that renders as a simple img element
|
|
@@ -4773,6 +4793,14 @@ interface CarouselImage {
|
|
|
4773
4793
|
* Stamped data-gallery-role on the slide.
|
|
4774
4794
|
*/
|
|
4775
4795
|
galleryRole?: "size-picture";
|
|
4796
|
+
/**
|
|
4797
|
+
* A plate's 8:3 strip (the catalog's `mockups[].strip`): the desktop hero asks for the crop its window shows
|
|
4798
|
+
* (`aspect=8:3&view=<r>@<f>`). Absent = the 16:9 hero. Phones ignore it.
|
|
4799
|
+
*/
|
|
4800
|
+
strip?: {
|
|
4801
|
+
shape: "8:3";
|
|
4802
|
+
productX: number;
|
|
4803
|
+
};
|
|
4776
4804
|
}
|
|
4777
4805
|
/**
|
|
4778
4806
|
* Alias for CarouselImage - used in hero contexts for semantic clarity.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as React$1 from 'react';
|
|
|
5
5
|
import React__default, { ReactNode, CSSProperties, RefObject } from 'react';
|
|
6
6
|
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
7
7
|
import { VariantProps } from 'class-variance-authority';
|
|
8
|
-
import { ProductPriceOptions, CatalogProduct, ImageAlignment, OptionSelection, ProductContext as ProductContext$1, WebSocketConfig, DesignElement, RealtimeRenderError, ProductArtAlignmentOptions, ProductArtAlignmentContext, ArtworkData } from '@snowcone-app/sdk';
|
|
8
|
+
import { ProductPriceOptions, CatalogProduct, ImageAlignment, OptionSelection, ProductContext as ProductContext$1, WebSocketConfig, DesignElement, RealtimeRenderError, MockupView, ProductArtAlignmentOptions, ProductArtAlignmentContext, ArtworkData } from '@snowcone-app/sdk';
|
|
9
9
|
export { ArtworkData, AspectRatio, ImageAlignment, ProductArtAlignmentContext, ProductArtAlignmentOptions, ProductData, ProductMockupData, ProductPlacement, ProductVariant, WebSocketConfig, describeProductArtAlignment, getMockupUrl, getProduct, getSnapPoints, listProducts } from '@snowcone-app/sdk';
|
|
10
10
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
11
11
|
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
|
|
@@ -3091,6 +3091,17 @@ interface RealtimeContextValue {
|
|
|
3091
3091
|
} | null;
|
|
3092
3092
|
/** The design editor opened or closed (Done). Drives the viewport policy's phase; see `editorOpen`. */
|
|
3093
3093
|
setEditorOpen: (open: boolean) => void;
|
|
3094
|
+
/**
|
|
3095
|
+
* The crop of each plate's 8:3 strip the page's hero shows (`view=<r>@<f>`, lane shapes #5520): those mockups' live
|
|
3096
|
+
* frames come as the same crop (rendercenter rc#898), so an edit drops into the hero's box. Re-sent on every config;
|
|
3097
|
+
* a change re-sends the config and re-seeds the cropped-delivery backgrounds (they are the old crop). `{}` = none.
|
|
3098
|
+
*/
|
|
3099
|
+
setMockupViews: (views: Readonly<Record<string, MockupView>>) => void;
|
|
3100
|
+
/**
|
|
3101
|
+
* What a frame URL this provider handed out is: the view it was rendered as, `null` for a full 16:9 frame, `undefined`
|
|
3102
|
+
* for a URL it did not hand out (a static picture).
|
|
3103
|
+
*/
|
|
3104
|
+
frameViewOf: (url: string) => MockupView | null | undefined;
|
|
3094
3105
|
flushPendingBlobs: () => void;
|
|
3095
3106
|
hasPendingBlobs: () => boolean;
|
|
3096
3107
|
subscribePipelineSettled: (callback: () => void) => () => void;
|
|
@@ -4448,6 +4459,15 @@ interface HeroProductImageProps {
|
|
|
4448
4459
|
* phone, where cover would cut a 16:9 frame to its centre). Stamped as data-fit.
|
|
4449
4460
|
*/
|
|
4450
4461
|
fit?: "cover" | "whole";
|
|
4462
|
+
/**
|
|
4463
|
+
* Ask for a crop of the mockup's 8:3 strip (`aspect=8:3&view=<r>@<f>`, no width: the crop comes at its own px), or
|
|
4464
|
+
* `"whole-strip"` (`aspect=8:3` at the measured width: a window wider than the crop grid), instead of a width-sized
|
|
4465
|
+
* 16:9 picture: the desktop hero of a mockup whose catalog entry carries `strip` (www heroStrip.ts). Only the static
|
|
4466
|
+
* picture follows it; realtime frames (an edit) stay the session's 16:9. Stamped as data-strip-view.
|
|
4467
|
+
*/
|
|
4468
|
+
stripView?: MockupView | "whole-strip";
|
|
4469
|
+
/** Called with the URL of each picture once it is ON SCREEN (its <img> loaded), not when it is asked for. */
|
|
4470
|
+
onShown?: (url: string) => void;
|
|
4451
4471
|
}
|
|
4452
4472
|
/**
|
|
4453
4473
|
* Hero-compatible version of ProductImage that renders as a simple img element
|
|
@@ -4773,6 +4793,14 @@ interface CarouselImage {
|
|
|
4773
4793
|
* Stamped data-gallery-role on the slide.
|
|
4774
4794
|
*/
|
|
4775
4795
|
galleryRole?: "size-picture";
|
|
4796
|
+
/**
|
|
4797
|
+
* A plate's 8:3 strip (the catalog's `mockups[].strip`): the desktop hero asks for the crop its window shows
|
|
4798
|
+
* (`aspect=8:3&view=<r>@<f>`). Absent = the 16:9 hero. Phones ignore it.
|
|
4799
|
+
*/
|
|
4800
|
+
strip?: {
|
|
4801
|
+
shape: "8:3";
|
|
4802
|
+
productX: number;
|
|
4803
|
+
};
|
|
4776
4804
|
}
|
|
4777
4805
|
/**
|
|
4778
4806
|
* Alias for CarouselImage - used in hero contexts for semantic clarity.
|
package/dist/index.js
CHANGED
|
@@ -5852,7 +5852,7 @@ function RealtimeProvider({
|
|
|
5852
5852
|
sendCanvasBlob: sendCanvasBlobRaw,
|
|
5853
5853
|
sendCanvasState: sendCanvasStateRaw,
|
|
5854
5854
|
sendColorBlob,
|
|
5855
|
-
sendConfig:
|
|
5855
|
+
sendConfig: sendConfigHook,
|
|
5856
5856
|
updateMockupIds: updateMockupIdsRaw,
|
|
5857
5857
|
updatePlacementSettings: updatePlacementSettingsRaw,
|
|
5858
5858
|
connect,
|
|
@@ -5865,6 +5865,18 @@ function RealtimeProvider({
|
|
|
5865
5865
|
isFrameSuperseded,
|
|
5866
5866
|
ackFrame
|
|
5867
5867
|
} = realtimeMockup;
|
|
5868
|
+
const viewsRef = useRef12({});
|
|
5869
|
+
const sentViewsRef = useRef12({});
|
|
5870
|
+
const frameViewsRef = useRef12(/* @__PURE__ */ new Map());
|
|
5871
|
+
const sendConfigRaw = useCallback10(
|
|
5872
|
+
(config) => {
|
|
5873
|
+
const views = viewsRef.current;
|
|
5874
|
+
const withViews = Object.keys(views).length > 0 ? { ...config, views: { ...views } } : config;
|
|
5875
|
+
sentViewsRef.current = withViews.views ?? {};
|
|
5876
|
+
return sendConfigHook(withViews);
|
|
5877
|
+
},
|
|
5878
|
+
[sendConfigHook]
|
|
5879
|
+
);
|
|
5868
5880
|
const isFrameSupersededRef = useRef12(isFrameSuperseded);
|
|
5869
5881
|
isFrameSupersededRef.current = isFrameSuperseded;
|
|
5870
5882
|
const mockupResultsRef = useRef12([]);
|
|
@@ -6123,6 +6135,23 @@ function RealtimeProvider({
|
|
|
6123
6135
|
compositeQueueRef.current.clear();
|
|
6124
6136
|
croppedActiveRef.current = false;
|
|
6125
6137
|
}, []);
|
|
6138
|
+
const setMockupViews = useCallback10(
|
|
6139
|
+
(views) => {
|
|
6140
|
+
const key = (v) => JSON.stringify(Object.keys(v).sort().map((k) => [k, v[k]]));
|
|
6141
|
+
if (key(views) === key(viewsRef.current)) return;
|
|
6142
|
+
viewsRef.current = { ...views };
|
|
6143
|
+
const base = lastConfigBaseRef.current;
|
|
6144
|
+
if (!base || !configSentRef.current) return;
|
|
6145
|
+
invalidateBackgrounds();
|
|
6146
|
+
requestedMockupIdsRef.current = base.mockupIds ?? [];
|
|
6147
|
+
sendConfigRaw({
|
|
6148
|
+
...base,
|
|
6149
|
+
placementSettings: { ...placementSettingsOverridesRef.current }
|
|
6150
|
+
});
|
|
6151
|
+
},
|
|
6152
|
+
[invalidateBackgrounds, sendConfigRaw]
|
|
6153
|
+
);
|
|
6154
|
+
const frameViewOf = useCallback10((url) => frameViewsRef.current.get(url), []);
|
|
6126
6155
|
const currentShape = useCallback10(
|
|
6127
6156
|
() => sessionShape({
|
|
6128
6157
|
allMockupIds: configuredMockupIdsRef.current,
|
|
@@ -6209,6 +6238,10 @@ function RealtimeProvider({
|
|
|
6209
6238
|
const watched = (mockupSubscribersByIdRef.current.get(result.mockupId)?.size ?? 0) > 0;
|
|
6210
6239
|
if (!watched || shownUrl === result.imageUrl) ackFrameRef.current?.(result.mockupId, seq);
|
|
6211
6240
|
});
|
|
6241
|
+
results.forEach((result) => {
|
|
6242
|
+
frameViewsRef.current.set(result.imageUrl, sentViewsRef.current[result.mockupId] ?? null);
|
|
6243
|
+
if (frameViewsRef.current.size > 512) frameViewsRef.current.delete(frameViewsRef.current.keys().next().value);
|
|
6244
|
+
});
|
|
6212
6245
|
const clearedPlacements = /* @__PURE__ */ new Set();
|
|
6213
6246
|
results.forEach((result) => {
|
|
6214
6247
|
const wasPending = pendingMockupIdsRef.current.has(result.mockupId);
|
|
@@ -6944,6 +6977,8 @@ function RealtimeProvider({
|
|
|
6944
6977
|
reportPictureView,
|
|
6945
6978
|
getSessionShape,
|
|
6946
6979
|
setEditorOpen: setEditorOpenState,
|
|
6980
|
+
setMockupViews,
|
|
6981
|
+
frameViewOf,
|
|
6947
6982
|
isMockupLoading,
|
|
6948
6983
|
registerBlobUrl,
|
|
6949
6984
|
markBlobShown,
|
|
@@ -6982,6 +7017,8 @@ function RealtimeProvider({
|
|
|
6982
7017
|
getLatestSentVersionsStable,
|
|
6983
7018
|
reportPictureView,
|
|
6984
7019
|
getSessionShape,
|
|
7020
|
+
setMockupViews,
|
|
7021
|
+
frameViewOf,
|
|
6985
7022
|
isMockupLoading,
|
|
6986
7023
|
registerBlobUrl,
|
|
6987
7024
|
markBlobShown,
|
|
@@ -10541,13 +10578,20 @@ function buildHeroMockupUrl(args) {
|
|
|
10541
10578
|
return getMockupUrl(args.productCode, {
|
|
10542
10579
|
shop: snow.shop,
|
|
10543
10580
|
design: publicDesign,
|
|
10544
|
-
width: args.width,
|
|
10581
|
+
..."stripView" in args.size ? { aspect: "8:3", stripView: args.size.stripView } : { width: args.size.width, ...args.size.aspect ? { aspect: args.size.aspect } : {} },
|
|
10545
10582
|
view: args.mockupId,
|
|
10546
10583
|
variant: args.variantId,
|
|
10547
10584
|
...args.bg ? { bg: args.bg } : {},
|
|
10548
10585
|
...snow.resolver ? { base: snow.resolver } : {}
|
|
10549
10586
|
});
|
|
10550
10587
|
}
|
|
10588
|
+
function isCrop(stripView) {
|
|
10589
|
+
return stripView !== void 0 && stripView !== "whole-strip";
|
|
10590
|
+
}
|
|
10591
|
+
function heroSize(stripView, width) {
|
|
10592
|
+
if (isCrop(stripView)) return { stripView };
|
|
10593
|
+
return stripView === "whole-strip" ? { width, aspect: "8:3" } : { width };
|
|
10594
|
+
}
|
|
10551
10595
|
var EMPTY_IMAGES = [];
|
|
10552
10596
|
var HeroProductImage = memo3(function HeroProductImage2({
|
|
10553
10597
|
productId,
|
|
@@ -10580,7 +10624,9 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10580
10624
|
errorText = "Error loading",
|
|
10581
10625
|
unavailableText = "Preview unavailable",
|
|
10582
10626
|
viewportPolicy = false,
|
|
10583
|
-
fit = "cover"
|
|
10627
|
+
fit = "cover",
|
|
10628
|
+
stripView,
|
|
10629
|
+
onShown
|
|
10584
10630
|
}) {
|
|
10585
10631
|
const context = useProductOptional();
|
|
10586
10632
|
const designContext = useDesignOptional();
|
|
@@ -10617,7 +10663,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10617
10663
|
}
|
|
10618
10664
|
if (context?.loading) return null;
|
|
10619
10665
|
if (!effectiveArtworkSrc || effectiveArtworkSrc.trim() === "") return null;
|
|
10620
|
-
if (!actualProductId || !actualMockupId || !actualGvid || actualGvid === "default" || !width) return null;
|
|
10666
|
+
if (!actualProductId || !actualMockupId || !actualGvid || actualGvid === "default" || !(isCrop(stripView) || width)) return null;
|
|
10621
10667
|
const allPlacements = product?.placements || context?.product?.placements || [];
|
|
10622
10668
|
if (allPlacements.length === 0) return null;
|
|
10623
10669
|
const placementDesigns = {};
|
|
@@ -10642,10 +10688,11 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10642
10688
|
placements: allPlacements,
|
|
10643
10689
|
mockupId: actualMockupId,
|
|
10644
10690
|
variantId: actualGvid,
|
|
10645
|
-
width,
|
|
10691
|
+
size: heroSize(stripView, width),
|
|
10646
10692
|
bg: mockupBg
|
|
10647
10693
|
});
|
|
10648
10694
|
}, [
|
|
10695
|
+
stripView,
|
|
10649
10696
|
realtimeUrl,
|
|
10650
10697
|
mode,
|
|
10651
10698
|
context?.loading,
|
|
@@ -10696,6 +10743,8 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
10696
10743
|
const isPendingExportRef = useRef23(false);
|
|
10697
10744
|
const onUrlGeneratedRef = useRef23(onUrlGenerated);
|
|
10698
10745
|
onUrlGeneratedRef.current = onUrlGenerated;
|
|
10746
|
+
const onShownRef = useRef23(onShown);
|
|
10747
|
+
onShownRef.current = onShown;
|
|
10699
10748
|
const layersLengthRef = useRef23(layers.length);
|
|
10700
10749
|
layersLengthRef.current = layers.length;
|
|
10701
10750
|
useEffect32(() => {
|
|
@@ -11004,7 +11053,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11004
11053
|
setTargetUrl(null);
|
|
11005
11054
|
return;
|
|
11006
11055
|
}
|
|
11007
|
-
if (!actualProductId || !actualMockupId || !actualGvid || actualGvid === "default" || !width) {
|
|
11056
|
+
if (!actualProductId || !actualMockupId || !actualGvid || actualGvid === "default" || !(isCrop(stripView) || width)) {
|
|
11008
11057
|
return;
|
|
11009
11058
|
}
|
|
11010
11059
|
const allPlacements = product?.placements || context?.product?.placements || [];
|
|
@@ -11018,7 +11067,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11018
11067
|
placements: allPlacements,
|
|
11019
11068
|
mockupId: actualMockupId,
|
|
11020
11069
|
variantId: actualGvid,
|
|
11021
|
-
width,
|
|
11070
|
+
size: heroSize(stripView, width),
|
|
11022
11071
|
bg: mockupBg
|
|
11023
11072
|
});
|
|
11024
11073
|
if (!url) return;
|
|
@@ -11063,6 +11112,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11063
11112
|
mockupBg,
|
|
11064
11113
|
images,
|
|
11065
11114
|
width,
|
|
11115
|
+
stripView,
|
|
11066
11116
|
effects,
|
|
11067
11117
|
// Use primitive values extracted at the top of the component
|
|
11068
11118
|
artworkSrc,
|
|
@@ -11197,6 +11247,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11197
11247
|
"data-hero-image": "true",
|
|
11198
11248
|
"data-mockup-id": actualMockupId || void 0,
|
|
11199
11249
|
"data-fit": fit,
|
|
11250
|
+
"data-strip-view": stripView,
|
|
11200
11251
|
"data-picture-failed": imgFailed ? "E_PICTURE_UNDISPLAYED" : void 0,
|
|
11201
11252
|
"data-picture-failed-src": failedSrc,
|
|
11202
11253
|
"data-mockup-unavailable": unavailable ? unavailable.code : void 0,
|
|
@@ -11235,6 +11286,7 @@ var HeroProductImage = memo3(function HeroProductImage2({
|
|
|
11235
11286
|
onLoad();
|
|
11236
11287
|
}
|
|
11237
11288
|
onUrlGeneratedRef.current?.(renderedUrl);
|
|
11289
|
+
if (renderedUrl) onShownRef.current?.(renderedUrl);
|
|
11238
11290
|
},
|
|
11239
11291
|
onError: () => {
|
|
11240
11292
|
if (renderedUrl && retriedUrlRef.current !== renderedUrl) {
|