@snowcone-app/ui 0.11.16 → 0.12.0
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 +15 -0
- package/dist/index.cjs +101 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -59
- package/dist/index.d.ts +124 -59
- package/dist/index.js +96 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/composed/carousels/MobileProductCarousel.tsx +3 -1
- package/src/composed/carousels/firstView.ts +81 -0
- package/src/composed/zoom/EnhancedImageViewer.tsx +68 -1
- package/src/composed/zoom/__tests__/EnhancedImageViewer.firstView.test.tsx +126 -0
- package/src/composed/zoom/types.ts +9 -0
- package/src/patterns/RealtimeProvider.tsx +1 -1
- package/src/patterns/__tests__/RealtimeProvider.cropDelivery.test.tsx +0 -4
- package/src/patterns/__tests__/RealtimeProvider.croppedLimit.test.tsx +27 -14
- package/src/patterns/__tests__/RealtimeProvider.shapeCrop.test.tsx +0 -4
- package/src/patterns/__tests__/RealtimeProvider.views.test.tsx +0 -4
- package/src/patterns/croppedDeliveryLimit.ts +8 -9
package/dist/index.js
CHANGED
|
@@ -5739,7 +5739,7 @@ async function compositeCroppedFrame(args) {
|
|
|
5739
5739
|
}
|
|
5740
5740
|
|
|
5741
5741
|
// src/patterns/croppedDeliveryLimit.ts
|
|
5742
|
-
var CROPPED_DELIVERY_MAX_MOCKUPS =
|
|
5742
|
+
var CROPPED_DELIVERY_MAX_MOCKUPS = 5;
|
|
5743
5743
|
function croppedDeliveryAllowed(mockupCount) {
|
|
5744
5744
|
return mockupCount <= CROPPED_DELIVERY_MAX_MOCKUPS;
|
|
5745
5745
|
}
|
|
@@ -12295,9 +12295,73 @@ import {
|
|
|
12295
12295
|
TransformComponent as OriginalTransformComponent
|
|
12296
12296
|
} from "react-zoom-pan-pinch";
|
|
12297
12297
|
import { X as X2 } from "lucide-react";
|
|
12298
|
+
|
|
12299
|
+
// src/composed/carousels/firstView.ts
|
|
12300
|
+
var SLIDE_FIRST_VIEW_ATTR = "data-first-view";
|
|
12301
|
+
var SLIDE_PRODUCT_BOX_ATTR = "data-product-box";
|
|
12302
|
+
var SLIDE_PHONE_WINDOW_ATTR = "data-phone-window";
|
|
12303
|
+
var SLIDE_FIRST_VIEW_X_VAR = "--first-view-x";
|
|
12304
|
+
var SLIDE_PRODUCT_X0_VAR = "--product-x0";
|
|
12305
|
+
var SLIDE_PRODUCT_X1_VAR = "--product-x1";
|
|
12306
|
+
var r4 = (n) => Math.round(n * 1e4) / 1e4;
|
|
12307
|
+
var FIRST_VIEW_PICTURE_ASPECT = 16 / 9;
|
|
12308
|
+
var FIRST_VIEW_MARGIN = 0.03;
|
|
12309
|
+
function firstViewAnchorOfSlide(image) {
|
|
12310
|
+
const { productBox: product, phoneWindow: window2 } = image;
|
|
12311
|
+
if (window2) return { by: "phone-window", window: window2, product: product ?? null };
|
|
12312
|
+
if (product) return { by: "product", product };
|
|
12313
|
+
return { by: "picture-middle", why: "no-phone-window-no-product-box" };
|
|
12314
|
+
}
|
|
12315
|
+
function firstView(box, anchor, pictureAspect = FIRST_VIEW_PICTURE_ASPECT) {
|
|
12316
|
+
const { width: W, height: H } = box;
|
|
12317
|
+
const pictureWidth = Math.max(W, H * pictureAspect);
|
|
12318
|
+
const product = anchor.by === "picture-middle" ? null : anchor.product;
|
|
12319
|
+
const wanted = anchor.by === "phone-window" ? anchor.window.x + anchor.window.w / 2 : anchor.by === "product" ? anchor.product.x + anchor.product.w / 2 : 0.5;
|
|
12320
|
+
let centrePx = wanted * pictureWidth;
|
|
12321
|
+
if (product) {
|
|
12322
|
+
const mid = (product.x + product.w / 2) * pictureWidth;
|
|
12323
|
+
const lo = (product.x + product.w) * pictureWidth + FIRST_VIEW_MARGIN * W - W / 2;
|
|
12324
|
+
const hi = product.x * pictureWidth - FIRST_VIEW_MARGIN * W + W / 2;
|
|
12325
|
+
centrePx = Math.max(Math.min(lo, mid), Math.min(centrePx, Math.max(hi, mid)));
|
|
12326
|
+
}
|
|
12327
|
+
const left = Math.max(Math.min(0, W - pictureWidth), Math.min(W / 2 - centrePx, 0));
|
|
12328
|
+
const x0 = -left / pictureWidth, x1 = (W - left) / pictureWidth;
|
|
12329
|
+
if (!product) return { x0, x1, pictureWidth, left, product: "unjudged", inView: null, share: null };
|
|
12330
|
+
const seen = Math.max(0, Math.min(product.x + product.w, x1) - Math.max(product.x, x0));
|
|
12331
|
+
const inView = seen / product.w;
|
|
12332
|
+
return { x0, x1, pictureWidth, left, product: inView > 1 - 1e-6 ? "held" : "cut", inView, share: seen / (x1 - x0) };
|
|
12333
|
+
}
|
|
12334
|
+
function slideFirstViewFields(image) {
|
|
12335
|
+
if (!image.isRealMockup) return {};
|
|
12336
|
+
return { ...image.productBox ? { productBox: image.productBox } : {}, ...image.phoneWindow ? { phoneWindow: image.phoneWindow } : {} };
|
|
12337
|
+
}
|
|
12338
|
+
function slideFirstViewProps(image) {
|
|
12339
|
+
const { productBox: box, phoneWindow: phone } = image;
|
|
12340
|
+
if (!box && !phone) return {};
|
|
12341
|
+
const centre = phone ? r4(phone.x + phone.w / 2) : r4(box.x + box.w / 2);
|
|
12342
|
+
const x0 = box ? r4(box.x) : centre, x1 = box ? r4(box.x + box.w) : centre;
|
|
12343
|
+
return {
|
|
12344
|
+
[SLIDE_FIRST_VIEW_ATTR]: phone ? "phone-window" : "product",
|
|
12345
|
+
...box ? { [SLIDE_PRODUCT_BOX_ATTR]: [box.x, box.y, box.w, box.h].map(r4).join(",") } : {},
|
|
12346
|
+
...phone ? { [SLIDE_PHONE_WINDOW_ATTR]: [phone.x, phone.w].map(r4).join(",") } : {},
|
|
12347
|
+
style: { [SLIDE_FIRST_VIEW_X_VAR]: String(centre), [SLIDE_PRODUCT_X0_VAR]: String(x0), [SLIDE_PRODUCT_X1_VAR]: String(x1) }
|
|
12348
|
+
};
|
|
12349
|
+
}
|
|
12350
|
+
|
|
12351
|
+
// src/composed/zoom/EnhancedImageViewer.tsx
|
|
12298
12352
|
import { Fragment as Fragment17, jsx as jsx73, jsxs as jsxs48 } from "react/jsx-runtime";
|
|
12299
12353
|
var TransformWrapper = OriginalTransformWrapper;
|
|
12300
12354
|
var TransformComponent = OriginalTransformComponent;
|
|
12355
|
+
function viewerFirstView(image, screen, pictureAspect) {
|
|
12356
|
+
if (image?.fit === "whole") return { by: "whole" };
|
|
12357
|
+
const anchor = firstViewAnchorOfSlide(image ?? {});
|
|
12358
|
+
if (anchor.by === "picture-middle") return anchor;
|
|
12359
|
+
if (pictureAspect !== void 0 && Math.abs(pictureAspect / FIRST_VIEW_PICTURE_ASPECT - 1) > 0.01) {
|
|
12360
|
+
return { by: "picture-middle", why: "picture-not-16:9" };
|
|
12361
|
+
}
|
|
12362
|
+
return { by: anchor.by, view: firstView(screen, anchor) };
|
|
12363
|
+
}
|
|
12364
|
+
var r42 = (n) => Math.round(n * 1e4) / 1e4;
|
|
12301
12365
|
var EnhancedImageViewer = ({
|
|
12302
12366
|
imageUrl,
|
|
12303
12367
|
alt,
|
|
@@ -12312,6 +12376,7 @@ var EnhancedImageViewer = ({
|
|
|
12312
12376
|
const [cropDimensions, setCropDimensions] = useState38({ width: 0, height: 0 });
|
|
12313
12377
|
const [currentZoomScale, setCurrentZoomScale] = useState38(1);
|
|
12314
12378
|
const imgRef = useRef25(null);
|
|
12379
|
+
const [loadedAspect, setLoadedAspect] = useState38(null);
|
|
12315
12380
|
const touchStartRef = useRef25(
|
|
12316
12381
|
null
|
|
12317
12382
|
);
|
|
@@ -12330,6 +12395,10 @@ var EnhancedImageViewer = ({
|
|
|
12330
12395
|
}, []);
|
|
12331
12396
|
const handleImageLoad = useCallback21(() => {
|
|
12332
12397
|
calculateScale();
|
|
12398
|
+
const img = imgRef.current;
|
|
12399
|
+
if (img && img.naturalWidth > 0 && img.naturalHeight > 0) {
|
|
12400
|
+
setLoadedAspect({ src: img.currentSrc || img.src, aspect: img.naturalWidth / img.naturalHeight });
|
|
12401
|
+
}
|
|
12333
12402
|
}, [calculateScale]);
|
|
12334
12403
|
useLayoutEffect6(() => {
|
|
12335
12404
|
setIsClient(true);
|
|
@@ -12433,6 +12502,17 @@ var EnhancedImageViewer = ({
|
|
|
12433
12502
|
},
|
|
12434
12503
|
[handleSwipeNavigation]
|
|
12435
12504
|
);
|
|
12505
|
+
const shownIndex = propCurrentIndex ?? images.findIndex((img) => img.src === imageUrl);
|
|
12506
|
+
const shown = images[shownIndex];
|
|
12507
|
+
const shownAspect = loadedAspect && (loadedAspect.src === imageUrl || loadedAspect.src.endsWith(imageUrl)) ? loadedAspect.aspect : shown?.naturalWidth && shown?.naturalHeight ? shown.naturalWidth / shown.naturalHeight : void 0;
|
|
12508
|
+
const opening = viewerFirstView(
|
|
12509
|
+
shown,
|
|
12510
|
+
{
|
|
12511
|
+
width: cropDimensions.width || (typeof window === "undefined" ? 0 : window.innerWidth),
|
|
12512
|
+
height: cropDimensions.height || (typeof window === "undefined" ? 0 : window.innerHeight)
|
|
12513
|
+
},
|
|
12514
|
+
shownAspect
|
|
12515
|
+
);
|
|
12436
12516
|
if (!isMounted || !isClient) {
|
|
12437
12517
|
return createPortal3(
|
|
12438
12518
|
/* @__PURE__ */ jsx73(
|
|
@@ -12567,11 +12647,17 @@ var EnhancedImageViewer = ({
|
|
|
12567
12647
|
alt,
|
|
12568
12648
|
crossOrigin: "anonymous",
|
|
12569
12649
|
onLoad: handleImageLoad,
|
|
12650
|
+
"data-first-view": opening.by,
|
|
12651
|
+
"data-first-view-why": opening.by === "picture-middle" ? opening.why : void 0,
|
|
12652
|
+
"data-first-view-product": "view" in opening ? opening.view.product : void 0,
|
|
12653
|
+
"data-first-view-slice": "view" in opening ? `${r42(opening.view.x0)},${r42(opening.view.x1)}` : void 0,
|
|
12570
12654
|
style: {
|
|
12571
12655
|
width: "100%",
|
|
12572
12656
|
height: "100%",
|
|
12573
12657
|
// Crop 16:9 to fill the screen (a hero), or the whole picture for a size picture (a diagram).
|
|
12574
|
-
objectFit:
|
|
12658
|
+
objectFit: opening.by === "whole" ? "contain" : "cover",
|
|
12659
|
+
// Opened on the product by the hero's first-view rule; a picture without the fields keeps the middle.
|
|
12660
|
+
..."view" in opening ? { objectPosition: `${Math.round(opening.view.left * 100) / 100}px 50%` } : {}
|
|
12575
12661
|
}
|
|
12576
12662
|
},
|
|
12577
12663
|
`${imageUrl}-${propCurrentIndex}`
|
|
@@ -12808,27 +12894,6 @@ function ResponsiveZoom({
|
|
|
12808
12894
|
] });
|
|
12809
12895
|
}
|
|
12810
12896
|
|
|
12811
|
-
// src/composed/carousels/firstView.ts
|
|
12812
|
-
var SLIDE_FIRST_VIEW_ATTR = "data-first-view";
|
|
12813
|
-
var SLIDE_PRODUCT_BOX_ATTR = "data-product-box";
|
|
12814
|
-
var SLIDE_PHONE_WINDOW_ATTR = "data-phone-window";
|
|
12815
|
-
var SLIDE_FIRST_VIEW_X_VAR = "--first-view-x";
|
|
12816
|
-
var SLIDE_PRODUCT_X0_VAR = "--product-x0";
|
|
12817
|
-
var SLIDE_PRODUCT_X1_VAR = "--product-x1";
|
|
12818
|
-
var r4 = (n) => Math.round(n * 1e4) / 1e4;
|
|
12819
|
-
function slideFirstViewProps(image) {
|
|
12820
|
-
const { productBox: box, phoneWindow: phone } = image;
|
|
12821
|
-
if (!box && !phone) return {};
|
|
12822
|
-
const centre = phone ? r4(phone.x + phone.w / 2) : r4(box.x + box.w / 2);
|
|
12823
|
-
const x0 = box ? r4(box.x) : centre, x1 = box ? r4(box.x + box.w) : centre;
|
|
12824
|
-
return {
|
|
12825
|
-
[SLIDE_FIRST_VIEW_ATTR]: phone ? "phone-window" : "product",
|
|
12826
|
-
...box ? { [SLIDE_PRODUCT_BOX_ATTR]: [box.x, box.y, box.w, box.h].map(r4).join(",") } : {},
|
|
12827
|
-
...phone ? { [SLIDE_PHONE_WINDOW_ATTR]: [phone.x, phone.w].map(r4).join(",") } : {},
|
|
12828
|
-
style: { [SLIDE_FIRST_VIEW_X_VAR]: String(centre), [SLIDE_PRODUCT_X0_VAR]: String(x0), [SLIDE_PRODUCT_X1_VAR]: String(x1) }
|
|
12829
|
-
};
|
|
12830
|
-
}
|
|
12831
|
-
|
|
12832
12897
|
// src/composed/carousels/MobileProductCarousel.tsx
|
|
12833
12898
|
import {
|
|
12834
12899
|
useState as useState40,
|
|
@@ -13535,7 +13600,9 @@ var MobileProductCarousel = memo4(function MobileProductCarousel2({
|
|
|
13535
13600
|
alt: img.label,
|
|
13536
13601
|
naturalWidth: img.naturalWidth,
|
|
13537
13602
|
naturalHeight: img.naturalHeight,
|
|
13538
|
-
...zoomFit(img.galleryRole) === "whole" ? { fit: "whole" } : {}
|
|
13603
|
+
...zoomFit(img.galleryRole) === "whole" ? { fit: "whole" } : {},
|
|
13604
|
+
// the viewer opens on the product by the hero's first-view rule (EnhancedImageViewer viewerFirstView)
|
|
13605
|
+
...slideFirstViewFields(img)
|
|
13539
13606
|
} : null;
|
|
13540
13607
|
}).filter((img) => img !== null);
|
|
13541
13608
|
return /* @__PURE__ */ jsx75(
|
|
@@ -15682,6 +15749,8 @@ export {
|
|
|
15682
15749
|
EdgeSwipeGuards,
|
|
15683
15750
|
EnhancedImageViewer,
|
|
15684
15751
|
FACET_SECTIONS,
|
|
15752
|
+
FIRST_VIEW_MARGIN,
|
|
15753
|
+
FIRST_VIEW_PICTURE_ASPECT,
|
|
15685
15754
|
Fieldset,
|
|
15686
15755
|
Filters,
|
|
15687
15756
|
FiltersButton,
|
|
@@ -15811,6 +15880,8 @@ export {
|
|
|
15811
15880
|
checkThemeTokens,
|
|
15812
15881
|
createScrollDirectionTracker,
|
|
15813
15882
|
describeProductArtAlignment2 as describeProductArtAlignment,
|
|
15883
|
+
firstView,
|
|
15884
|
+
firstViewAnchorOfSlide,
|
|
15814
15885
|
formatCurrency,
|
|
15815
15886
|
formatDate,
|
|
15816
15887
|
formatDateTime,
|
|
@@ -15834,6 +15905,7 @@ export {
|
|
|
15834
15905
|
runConfigChecks,
|
|
15835
15906
|
scrollInputAboveKeyboard,
|
|
15836
15907
|
searchClient,
|
|
15908
|
+
slideFirstViewFields,
|
|
15837
15909
|
slideFirstViewProps,
|
|
15838
15910
|
spinnerVariants,
|
|
15839
15911
|
surfaceVariants,
|