@snowcone-app/ui 0.11.17 → 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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#6508](https://github.com/snowcone-app/snowcone-monorepo/pull/6508) [`70129fa`](https://github.com/snowcone-app/snowcone-monorepo/commit/70129faa62d354cfffd1a297894bf81012c999b9) Thanks [@kevinsproles](https://github.com/kevinsproles)! - The tap-to-enlarge viewer (`EnhancedImageViewer`) opens a phone picture on its product, by the same first-view rule as the phone hero: a `ZoomImage` may carry the catalog's `productBox` / `phoneWindow`, and `MobileProductCarousel` hands them over for real mockups. A picture without them opens on its middle, as before. The viewer's `<img>` says where it opened (`data-first-view`, `data-first-view-product`, `data-first-view-slice`, `data-first-view-why`). The rule itself (`firstView`, `firstViewAnchorOfSlide`, `FIRST_VIEW_MARGIN`, `FIRST_VIEW_PICTURE_ASPECT`) and `slideFirstViewFields` are now exported from the package.
8
+
3
9
  ## 0.11.17
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -222,6 +222,8 @@ __export(src_exports, {
222
222
  EdgeSwipeGuards: () => EdgeSwipeGuards,
223
223
  EnhancedImageViewer: () => EnhancedImageViewer,
224
224
  FACET_SECTIONS: () => FACET_SECTIONS,
225
+ FIRST_VIEW_MARGIN: () => FIRST_VIEW_MARGIN,
226
+ FIRST_VIEW_PICTURE_ASPECT: () => FIRST_VIEW_PICTURE_ASPECT,
225
227
  Fieldset: () => Fieldset,
226
228
  Filters: () => Filters,
227
229
  FiltersButton: () => FiltersButton,
@@ -351,6 +353,8 @@ __export(src_exports, {
351
353
  checkThemeTokens: () => checkThemeTokens,
352
354
  createScrollDirectionTracker: () => createScrollDirectionTracker,
353
355
  describeProductArtAlignment: () => import_sdk14.describeProductArtAlignment,
356
+ firstView: () => firstView,
357
+ firstViewAnchorOfSlide: () => firstViewAnchorOfSlide,
354
358
  formatCurrency: () => formatCurrency,
355
359
  formatDate: () => formatDate,
356
360
  formatDateTime: () => formatDateTime,
@@ -374,6 +378,7 @@ __export(src_exports, {
374
378
  runConfigChecks: () => runConfigChecks,
375
379
  scrollInputAboveKeyboard: () => scrollInputAboveKeyboard,
376
380
  searchClient: () => searchClient,
381
+ slideFirstViewFields: () => slideFirstViewFields,
377
382
  slideFirstViewProps: () => slideFirstViewProps,
378
383
  spinnerVariants: () => spinnerVariants,
379
384
  surfaceVariants: () => surfaceVariants,
@@ -12665,9 +12670,73 @@ var import_react55 = require("react");
12665
12670
  var import_react_dom3 = require("react-dom");
12666
12671
  var import_react_zoom_pan_pinch = require("react-zoom-pan-pinch");
12667
12672
  var import_lucide_react8 = require("lucide-react");
12673
+
12674
+ // src/composed/carousels/firstView.ts
12675
+ var SLIDE_FIRST_VIEW_ATTR = "data-first-view";
12676
+ var SLIDE_PRODUCT_BOX_ATTR = "data-product-box";
12677
+ var SLIDE_PHONE_WINDOW_ATTR = "data-phone-window";
12678
+ var SLIDE_FIRST_VIEW_X_VAR = "--first-view-x";
12679
+ var SLIDE_PRODUCT_X0_VAR = "--product-x0";
12680
+ var SLIDE_PRODUCT_X1_VAR = "--product-x1";
12681
+ var r4 = (n) => Math.round(n * 1e4) / 1e4;
12682
+ var FIRST_VIEW_PICTURE_ASPECT = 16 / 9;
12683
+ var FIRST_VIEW_MARGIN = 0.03;
12684
+ function firstViewAnchorOfSlide(image) {
12685
+ const { productBox: product, phoneWindow: window2 } = image;
12686
+ if (window2) return { by: "phone-window", window: window2, product: product ?? null };
12687
+ if (product) return { by: "product", product };
12688
+ return { by: "picture-middle", why: "no-phone-window-no-product-box" };
12689
+ }
12690
+ function firstView(box, anchor, pictureAspect = FIRST_VIEW_PICTURE_ASPECT) {
12691
+ const { width: W, height: H } = box;
12692
+ const pictureWidth = Math.max(W, H * pictureAspect);
12693
+ const product = anchor.by === "picture-middle" ? null : anchor.product;
12694
+ 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;
12695
+ let centrePx = wanted * pictureWidth;
12696
+ if (product) {
12697
+ const mid = (product.x + product.w / 2) * pictureWidth;
12698
+ const lo = (product.x + product.w) * pictureWidth + FIRST_VIEW_MARGIN * W - W / 2;
12699
+ const hi = product.x * pictureWidth - FIRST_VIEW_MARGIN * W + W / 2;
12700
+ centrePx = Math.max(Math.min(lo, mid), Math.min(centrePx, Math.max(hi, mid)));
12701
+ }
12702
+ const left = Math.max(Math.min(0, W - pictureWidth), Math.min(W / 2 - centrePx, 0));
12703
+ const x0 = -left / pictureWidth, x1 = (W - left) / pictureWidth;
12704
+ if (!product) return { x0, x1, pictureWidth, left, product: "unjudged", inView: null, share: null };
12705
+ const seen = Math.max(0, Math.min(product.x + product.w, x1) - Math.max(product.x, x0));
12706
+ const inView = seen / product.w;
12707
+ return { x0, x1, pictureWidth, left, product: inView > 1 - 1e-6 ? "held" : "cut", inView, share: seen / (x1 - x0) };
12708
+ }
12709
+ function slideFirstViewFields(image) {
12710
+ if (!image.isRealMockup) return {};
12711
+ return { ...image.productBox ? { productBox: image.productBox } : {}, ...image.phoneWindow ? { phoneWindow: image.phoneWindow } : {} };
12712
+ }
12713
+ function slideFirstViewProps(image) {
12714
+ const { productBox: box, phoneWindow: phone } = image;
12715
+ if (!box && !phone) return {};
12716
+ const centre = phone ? r4(phone.x + phone.w / 2) : r4(box.x + box.w / 2);
12717
+ const x0 = box ? r4(box.x) : centre, x1 = box ? r4(box.x + box.w) : centre;
12718
+ return {
12719
+ [SLIDE_FIRST_VIEW_ATTR]: phone ? "phone-window" : "product",
12720
+ ...box ? { [SLIDE_PRODUCT_BOX_ATTR]: [box.x, box.y, box.w, box.h].map(r4).join(",") } : {},
12721
+ ...phone ? { [SLIDE_PHONE_WINDOW_ATTR]: [phone.x, phone.w].map(r4).join(",") } : {},
12722
+ style: { [SLIDE_FIRST_VIEW_X_VAR]: String(centre), [SLIDE_PRODUCT_X0_VAR]: String(x0), [SLIDE_PRODUCT_X1_VAR]: String(x1) }
12723
+ };
12724
+ }
12725
+
12726
+ // src/composed/zoom/EnhancedImageViewer.tsx
12668
12727
  var import_jsx_runtime73 = require("react/jsx-runtime");
12669
12728
  var TransformWrapper = import_react_zoom_pan_pinch.TransformWrapper;
12670
12729
  var TransformComponent = import_react_zoom_pan_pinch.TransformComponent;
12730
+ function viewerFirstView(image, screen, pictureAspect) {
12731
+ if (image?.fit === "whole") return { by: "whole" };
12732
+ const anchor = firstViewAnchorOfSlide(image ?? {});
12733
+ if (anchor.by === "picture-middle") return anchor;
12734
+ if (pictureAspect !== void 0 && Math.abs(pictureAspect / FIRST_VIEW_PICTURE_ASPECT - 1) > 0.01) {
12735
+ return { by: "picture-middle", why: "picture-not-16:9" };
12736
+ }
12737
+ return { by: anchor.by, view: firstView(screen, anchor) };
12738
+ }
12739
+ var r42 = (n) => Math.round(n * 1e4) / 1e4;
12671
12740
  var EnhancedImageViewer = ({
12672
12741
  imageUrl,
12673
12742
  alt,
@@ -12682,6 +12751,7 @@ var EnhancedImageViewer = ({
12682
12751
  const [cropDimensions, setCropDimensions] = (0, import_react55.useState)({ width: 0, height: 0 });
12683
12752
  const [currentZoomScale, setCurrentZoomScale] = (0, import_react55.useState)(1);
12684
12753
  const imgRef = (0, import_react55.useRef)(null);
12754
+ const [loadedAspect, setLoadedAspect] = (0, import_react55.useState)(null);
12685
12755
  const touchStartRef = (0, import_react55.useRef)(
12686
12756
  null
12687
12757
  );
@@ -12700,6 +12770,10 @@ var EnhancedImageViewer = ({
12700
12770
  }, []);
12701
12771
  const handleImageLoad = (0, import_react55.useCallback)(() => {
12702
12772
  calculateScale();
12773
+ const img = imgRef.current;
12774
+ if (img && img.naturalWidth > 0 && img.naturalHeight > 0) {
12775
+ setLoadedAspect({ src: img.currentSrc || img.src, aspect: img.naturalWidth / img.naturalHeight });
12776
+ }
12703
12777
  }, [calculateScale]);
12704
12778
  (0, import_react55.useLayoutEffect)(() => {
12705
12779
  setIsClient(true);
@@ -12803,6 +12877,17 @@ var EnhancedImageViewer = ({
12803
12877
  },
12804
12878
  [handleSwipeNavigation]
12805
12879
  );
12880
+ const shownIndex = propCurrentIndex ?? images.findIndex((img) => img.src === imageUrl);
12881
+ const shown = images[shownIndex];
12882
+ const shownAspect = loadedAspect && (loadedAspect.src === imageUrl || loadedAspect.src.endsWith(imageUrl)) ? loadedAspect.aspect : shown?.naturalWidth && shown?.naturalHeight ? shown.naturalWidth / shown.naturalHeight : void 0;
12883
+ const opening = viewerFirstView(
12884
+ shown,
12885
+ {
12886
+ width: cropDimensions.width || (typeof window === "undefined" ? 0 : window.innerWidth),
12887
+ height: cropDimensions.height || (typeof window === "undefined" ? 0 : window.innerHeight)
12888
+ },
12889
+ shownAspect
12890
+ );
12806
12891
  if (!isMounted || !isClient) {
12807
12892
  return (0, import_react_dom3.createPortal)(
12808
12893
  /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
@@ -12937,11 +13022,17 @@ var EnhancedImageViewer = ({
12937
13022
  alt,
12938
13023
  crossOrigin: "anonymous",
12939
13024
  onLoad: handleImageLoad,
13025
+ "data-first-view": opening.by,
13026
+ "data-first-view-why": opening.by === "picture-middle" ? opening.why : void 0,
13027
+ "data-first-view-product": "view" in opening ? opening.view.product : void 0,
13028
+ "data-first-view-slice": "view" in opening ? `${r42(opening.view.x0)},${r42(opening.view.x1)}` : void 0,
12940
13029
  style: {
12941
13030
  width: "100%",
12942
13031
  height: "100%",
12943
13032
  // Crop 16:9 to fill the screen (a hero), or the whole picture for a size picture (a diagram).
12944
- objectFit: images[propCurrentIndex ?? -1]?.fit === "whole" ? "contain" : "cover"
13033
+ objectFit: opening.by === "whole" ? "contain" : "cover",
13034
+ // Opened on the product by the hero's first-view rule; a picture without the fields keeps the middle.
13035
+ ..."view" in opening ? { objectPosition: `${Math.round(opening.view.left * 100) / 100}px 50%` } : {}
12945
13036
  }
12946
13037
  },
12947
13038
  `${imageUrl}-${propCurrentIndex}`
@@ -13178,27 +13269,6 @@ function ResponsiveZoom({
13178
13269
  ] });
13179
13270
  }
13180
13271
 
13181
- // src/composed/carousels/firstView.ts
13182
- var SLIDE_FIRST_VIEW_ATTR = "data-first-view";
13183
- var SLIDE_PRODUCT_BOX_ATTR = "data-product-box";
13184
- var SLIDE_PHONE_WINDOW_ATTR = "data-phone-window";
13185
- var SLIDE_FIRST_VIEW_X_VAR = "--first-view-x";
13186
- var SLIDE_PRODUCT_X0_VAR = "--product-x0";
13187
- var SLIDE_PRODUCT_X1_VAR = "--product-x1";
13188
- var r4 = (n) => Math.round(n * 1e4) / 1e4;
13189
- function slideFirstViewProps(image) {
13190
- const { productBox: box, phoneWindow: phone } = image;
13191
- if (!box && !phone) return {};
13192
- const centre = phone ? r4(phone.x + phone.w / 2) : r4(box.x + box.w / 2);
13193
- const x0 = box ? r4(box.x) : centre, x1 = box ? r4(box.x + box.w) : centre;
13194
- return {
13195
- [SLIDE_FIRST_VIEW_ATTR]: phone ? "phone-window" : "product",
13196
- ...box ? { [SLIDE_PRODUCT_BOX_ATTR]: [box.x, box.y, box.w, box.h].map(r4).join(",") } : {},
13197
- ...phone ? { [SLIDE_PHONE_WINDOW_ATTR]: [phone.x, phone.w].map(r4).join(",") } : {},
13198
- style: { [SLIDE_FIRST_VIEW_X_VAR]: String(centre), [SLIDE_PRODUCT_X0_VAR]: String(x0), [SLIDE_PRODUCT_X1_VAR]: String(x1) }
13199
- };
13200
- }
13201
-
13202
13272
  // src/composed/carousels/MobileProductCarousel.tsx
13203
13273
  var import_react57 = require("react");
13204
13274
 
@@ -13898,7 +13968,9 @@ var MobileProductCarousel = (0, import_react57.memo)(function MobileProductCarou
13898
13968
  alt: img.label,
13899
13969
  naturalWidth: img.naturalWidth,
13900
13970
  naturalHeight: img.naturalHeight,
13901
- ...zoomFit(img.galleryRole) === "whole" ? { fit: "whole" } : {}
13971
+ ...zoomFit(img.galleryRole) === "whole" ? { fit: "whole" } : {},
13972
+ // the viewer opens on the product by the hero's first-view rule (EnhancedImageViewer viewerFirstView)
13973
+ ...slideFirstViewFields(img)
13902
13974
  } : null;
13903
13975
  }).filter((img) => img !== null);
13904
13976
  return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
@@ -17254,6 +17326,8 @@ function usePersonalizationShimmer(containerRef, safetyTimeoutMs = 1e4) {
17254
17326
  EdgeSwipeGuards,
17255
17327
  EnhancedImageViewer,
17256
17328
  FACET_SECTIONS,
17329
+ FIRST_VIEW_MARGIN,
17330
+ FIRST_VIEW_PICTURE_ASPECT,
17257
17331
  Fieldset,
17258
17332
  Filters,
17259
17333
  FiltersButton,
@@ -17383,6 +17457,8 @@ function usePersonalizationShimmer(containerRef, safetyTimeoutMs = 1e4) {
17383
17457
  checkThemeTokens,
17384
17458
  createScrollDirectionTracker,
17385
17459
  describeProductArtAlignment,
17460
+ firstView,
17461
+ firstViewAnchorOfSlide,
17386
17462
  formatCurrency,
17387
17463
  formatDate,
17388
17464
  formatDateTime,
@@ -17406,6 +17482,7 @@ function usePersonalizationShimmer(containerRef, safetyTimeoutMs = 1e4) {
17406
17482
  runConfigChecks,
17407
17483
  scrollInputAboveKeyboard,
17408
17484
  searchClient,
17485
+ slideFirstViewFields,
17409
17486
  slideFirstViewProps,
17410
17487
  spinnerVariants,
17411
17488
  surfaceVariants,