@nok-integration/storefront-react 0.20.7 → 0.20.8

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, Fragment as Fragment$1 } from "react";
3
+ import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, useLayoutEffect, Fragment as Fragment$1 } from "react";
4
4
  var client = {};
5
5
  var catalog = {};
6
6
  var zod = {};
@@ -5189,8 +5189,8 @@ function resolveAssetUrl(src, base) {
5189
5189
  const MAX_AGE_MS = 5 * 6e4;
5190
5190
  const CAPACITY = 60;
5191
5191
  class ProductCache {
5192
- constructor(now2 = () => Date.now()) {
5193
- this.now = now2;
5192
+ constructor(now = () => Date.now()) {
5193
+ this.now = now;
5194
5194
  }
5195
5195
  now;
5196
5196
  entries = /* @__PURE__ */ new Map();
@@ -5702,17 +5702,16 @@ function useTopOffset(ref, property, enabled = true) {
5702
5702
  };
5703
5703
  }, [ref, property, enabled]);
5704
5704
  }
5705
- const HOLD_MS = 1e3;
5706
- const TRAVERSAL_WINDOW_MS = 1e3;
5707
- const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
5708
- let lastTraversal = -Infinity;
5709
- if (typeof window !== "undefined") {
5710
- window.addEventListener("popstate", () => {
5711
- lastTraversal = now();
5712
- });
5713
- }
5714
- function followsTraversal() {
5715
- return now() - lastTraversal < TRAVERSAL_WINDOW_MS;
5705
+ const HOLD_MS = 2500;
5706
+ function withoutRestoration() {
5707
+ const history = typeof window !== "undefined" ? window.history : void 0;
5708
+ if (!history || !("scrollRestoration" in history)) return () => {
5709
+ };
5710
+ const previous = history.scrollRestoration;
5711
+ history.scrollRestoration = "manual";
5712
+ return () => {
5713
+ history.scrollRestoration = previous;
5714
+ };
5716
5715
  }
5717
5716
  const RELEASES = ["touchstart", "wheel", "keydown", "pointerdown"];
5718
5717
  function anchorTop(shouldHold = () => true) {
@@ -5741,6 +5740,7 @@ function anchorTop(shouldHold = () => true) {
5741
5740
  });
5742
5741
  return release;
5743
5742
  }
5743
+ const useMountEffect$1 = typeof window === "undefined" ? useEffect : useLayoutEffect;
5744
5744
  function documentTop(el) {
5745
5745
  let top2 = 0;
5746
5746
  for (let node = el; node; node = node.offsetParent) {
@@ -5752,11 +5752,15 @@ function beginsOnTheFirstViewport(el) {
5752
5752
  return documentTop(el) < window.innerHeight;
5753
5753
  }
5754
5754
  function useScreenAnchor(ref, enabled = true) {
5755
- useEffect(() => {
5755
+ useMountEffect$1(() => {
5756
5756
  const el = ref.current;
5757
5757
  if (!el || !enabled) return;
5758
- if (followsTraversal()) return;
5759
- return anchorTop(() => beginsOnTheFirstViewport(el));
5758
+ const restore = withoutRestoration();
5759
+ const release = anchorTop(() => beginsOnTheFirstViewport(el));
5760
+ return () => {
5761
+ release();
5762
+ restore();
5763
+ };
5760
5764
  }, [ref, enabled]);
5761
5765
  }
5762
5766
  const ShopSurface = forwardRef(function ShopSurface2({ tone, fill: fill2 = false, children, className, ...rest }, ref) {
@@ -10361,14 +10365,14 @@ function formatRemaining(ms) {
10361
10365
  return `${hh}:${mm}:${ss}`;
10362
10366
  }
10363
10367
  function PromoBanner({ promo: promo2 }) {
10364
- const [now2, setNow] = useState(null);
10368
+ const [now, setNow] = useState(null);
10365
10369
  useEffect(() => {
10366
10370
  if (!promo2.ends_at) return;
10367
10371
  setNow(Date.now());
10368
10372
  const id = setInterval(() => setNow(Date.now()), 1e3);
10369
10373
  return () => clearInterval(id);
10370
10374
  }, [promo2.ends_at]);
10371
- const remaining = promo2.ends_at && now2 !== null ? new Date(promo2.ends_at).getTime() - now2 : null;
10375
+ const remaining = promo2.ends_at && now !== null ? new Date(promo2.ends_at).getTime() - now : null;
10372
10376
  const showTimer = remaining !== null && remaining > 0;
10373
10377
  return jsxs("div", {
10374
10378
  className: styles$b.banner,
@@ -11277,8 +11281,9 @@ const styles$2 = {
11277
11281
  cta,
11278
11282
  mosaic
11279
11283
  };
11284
+ const useMountEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
11280
11285
  function useDocumentSnap(ref, enabled = true) {
11281
- useEffect(() => {
11286
+ useMountEffect(() => {
11282
11287
  const el = ref.current;
11283
11288
  if (!el || !enabled || typeof document === "undefined") return;
11284
11289
  const root2 = document.documentElement;
@@ -11287,11 +11292,9 @@ function useDocumentSnap(ref, enabled = true) {
11287
11292
  root2.style.scrollSnapType = "y mandatory";
11288
11293
  root2.style.scrollPaddingTop = "0px";
11289
11294
  const top2 = () => window.scrollTo(0, 0);
11290
- const entered = !followsTraversal();
11291
- if (entered) top2();
11292
- const frame2 = entered && typeof window.requestAnimationFrame === "function" ? window.requestAnimationFrame(top2) : null;
11293
- const release = entered ? anchorTop() : () => {
11294
- };
11295
+ top2();
11296
+ const frame2 = typeof window.requestAnimationFrame === "function" ? window.requestAnimationFrame(top2) : null;
11297
+ const release = anchorTop();
11295
11298
  const history = window.history;
11296
11299
  const previousRestoration = history && "scrollRestoration" in history ? history.scrollRestoration : null;
11297
11300
  if (previousRestoration !== null) history.scrollRestoration = "manual";
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
- import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, Fragment as Fragment$1 } from "react";
3
+ import { useContext, useEffect, useState, useRef, useCallback, useMemo, createContext, forwardRef, useLayoutEffect, Fragment as Fragment$1 } from "react";
4
4
  var client = {};
5
5
  var catalog = {};
6
6
  var zod = {};
@@ -5189,8 +5189,8 @@ function resolveAssetUrl(src, base) {
5189
5189
  const MAX_AGE_MS = 5 * 6e4;
5190
5190
  const CAPACITY = 60;
5191
5191
  class ProductCache {
5192
- constructor(now2 = () => Date.now()) {
5193
- this.now = now2;
5192
+ constructor(now = () => Date.now()) {
5193
+ this.now = now;
5194
5194
  }
5195
5195
  now;
5196
5196
  entries = /* @__PURE__ */ new Map();
@@ -5702,17 +5702,16 @@ function useTopOffset(ref, property, enabled = true) {
5702
5702
  };
5703
5703
  }, [ref, property, enabled]);
5704
5704
  }
5705
- const HOLD_MS = 1e3;
5706
- const TRAVERSAL_WINDOW_MS = 1e3;
5707
- const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
5708
- let lastTraversal = -Infinity;
5709
- if (typeof window !== "undefined") {
5710
- window.addEventListener("popstate", () => {
5711
- lastTraversal = now();
5712
- });
5713
- }
5714
- function followsTraversal() {
5715
- return now() - lastTraversal < TRAVERSAL_WINDOW_MS;
5705
+ const HOLD_MS = 2500;
5706
+ function withoutRestoration() {
5707
+ const history = typeof window !== "undefined" ? window.history : void 0;
5708
+ if (!history || !("scrollRestoration" in history)) return () => {
5709
+ };
5710
+ const previous = history.scrollRestoration;
5711
+ history.scrollRestoration = "manual";
5712
+ return () => {
5713
+ history.scrollRestoration = previous;
5714
+ };
5716
5715
  }
5717
5716
  const RELEASES = ["touchstart", "wheel", "keydown", "pointerdown"];
5718
5717
  function anchorTop(shouldHold = () => true) {
@@ -5741,6 +5740,7 @@ function anchorTop(shouldHold = () => true) {
5741
5740
  });
5742
5741
  return release;
5743
5742
  }
5743
+ const useMountEffect$1 = typeof window === "undefined" ? useEffect : useLayoutEffect;
5744
5744
  function documentTop(el) {
5745
5745
  let top2 = 0;
5746
5746
  for (let node = el; node; node = node.offsetParent) {
@@ -5752,11 +5752,15 @@ function beginsOnTheFirstViewport(el) {
5752
5752
  return documentTop(el) < window.innerHeight;
5753
5753
  }
5754
5754
  function useScreenAnchor(ref, enabled = true) {
5755
- useEffect(() => {
5755
+ useMountEffect$1(() => {
5756
5756
  const el = ref.current;
5757
5757
  if (!el || !enabled) return;
5758
- if (followsTraversal()) return;
5759
- return anchorTop(() => beginsOnTheFirstViewport(el));
5758
+ const restore = withoutRestoration();
5759
+ const release = anchorTop(() => beginsOnTheFirstViewport(el));
5760
+ return () => {
5761
+ release();
5762
+ restore();
5763
+ };
5760
5764
  }, [ref, enabled]);
5761
5765
  }
5762
5766
  const ShopSurface = forwardRef(function ShopSurface2({ tone, fill: fill2 = false, children, className, ...rest }, ref) {
@@ -10361,14 +10365,14 @@ function formatRemaining(ms) {
10361
10365
  return `${hh}:${mm}:${ss}`;
10362
10366
  }
10363
10367
  function PromoBanner({ promo: promo2 }) {
10364
- const [now2, setNow] = useState(null);
10368
+ const [now, setNow] = useState(null);
10365
10369
  useEffect(() => {
10366
10370
  if (!promo2.ends_at) return;
10367
10371
  setNow(Date.now());
10368
10372
  const id = setInterval(() => setNow(Date.now()), 1e3);
10369
10373
  return () => clearInterval(id);
10370
10374
  }, [promo2.ends_at]);
10371
- const remaining = promo2.ends_at && now2 !== null ? new Date(promo2.ends_at).getTime() - now2 : null;
10375
+ const remaining = promo2.ends_at && now !== null ? new Date(promo2.ends_at).getTime() - now : null;
10372
10376
  const showTimer = remaining !== null && remaining > 0;
10373
10377
  return jsxs("div", {
10374
10378
  className: styles$b.banner,
@@ -11277,8 +11281,9 @@ const styles$2 = {
11277
11281
  cta,
11278
11282
  mosaic
11279
11283
  };
11284
+ const useMountEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
11280
11285
  function useDocumentSnap(ref, enabled = true) {
11281
- useEffect(() => {
11286
+ useMountEffect(() => {
11282
11287
  const el = ref.current;
11283
11288
  if (!el || !enabled || typeof document === "undefined") return;
11284
11289
  const root2 = document.documentElement;
@@ -11287,11 +11292,9 @@ function useDocumentSnap(ref, enabled = true) {
11287
11292
  root2.style.scrollSnapType = "y mandatory";
11288
11293
  root2.style.scrollPaddingTop = "0px";
11289
11294
  const top2 = () => window.scrollTo(0, 0);
11290
- const entered = !followsTraversal();
11291
- if (entered) top2();
11292
- const frame2 = entered && typeof window.requestAnimationFrame === "function" ? window.requestAnimationFrame(top2) : null;
11293
- const release = entered ? anchorTop() : () => {
11294
- };
11295
+ top2();
11296
+ const frame2 = typeof window.requestAnimationFrame === "function" ? window.requestAnimationFrame(top2) : null;
11297
+ const release = anchorTop();
11295
11298
  const history = window.history;
11296
11299
  const previousRestoration = history && "scrollRestoration" in history ? history.scrollRestoration : null;
11297
11300
  if (previousRestoration !== null) history.scrollRestoration = "manual";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nok-integration/storefront-react",
3
- "version": "0.20.7",
3
+ "version": "0.20.8",
4
4
  "description": "Mountable React storefront components: catalogue, product detail and cart, mounted directly into a host DOM tree. No iframe.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",