@nok-integration/storefront-react 0.20.16 → 0.20.17

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
@@ -5189,6 +5189,60 @@ function requireClient() {
5189
5189
  return client;
5190
5190
  }
5191
5191
  var clientExports = requireClient();
5192
+ const TOP = {
5193
+ doc: 0,
5194
+ pane: 0
5195
+ };
5196
+ const places = /* @__PURE__ */ new Map();
5197
+ let returnedTo = null;
5198
+ function here() {
5199
+ if (typeof window === "undefined") return "";
5200
+ const { pathname, search, hash } = window.location;
5201
+ return pathname + search + hash;
5202
+ }
5203
+ if (typeof window !== "undefined") {
5204
+ window.addEventListener("popstate", () => {
5205
+ returnedTo = here();
5206
+ }, {
5207
+ capture: true
5208
+ });
5209
+ }
5210
+ function cameBack() {
5211
+ return returnedTo !== null && returnedTo === here();
5212
+ }
5213
+ function returnOffset(key) {
5214
+ if (!cameBack() || returnedTo !== key) return null;
5215
+ return places.get(key) ?? null;
5216
+ }
5217
+ function settleReturn() {
5218
+ returnedTo = null;
5219
+ }
5220
+ function remember(key, offset) {
5221
+ places.set(key, offset);
5222
+ }
5223
+ let latestScreen = 0;
5224
+ let currentScreen = 0;
5225
+ function claimScreen() {
5226
+ latestScreen += 1;
5227
+ currentScreen = latestScreen;
5228
+ return currentScreen;
5229
+ }
5230
+ function leaveScreen() {
5231
+ currentScreen = 0;
5232
+ settleReturn();
5233
+ }
5234
+ function isCurrentScreen(screen2) {
5235
+ return screen2 === currentScreen;
5236
+ }
5237
+ function placeOf(pane) {
5238
+ return {
5239
+ doc: window.scrollY || document.documentElement.scrollTop || 0,
5240
+ pane: pane ? pane.scrollTop : 0
5241
+ };
5242
+ }
5243
+ function reached(now, at) {
5244
+ return Math.abs(now.doc - at.doc) <= 1 && Math.abs(now.pane - at.pane) <= 1;
5245
+ }
5192
5246
  const HOLD_MS = 2500;
5193
5247
  function withoutRestoration() {
5194
5248
  const history = typeof window !== "undefined" ? window.history : void 0;
@@ -5201,11 +5255,14 @@ function withoutRestoration() {
5201
5255
  };
5202
5256
  }
5203
5257
  function scrollToTop(box2) {
5258
+ scrollToOffset(0, box2);
5259
+ }
5260
+ function scrollToOffset(offset, box2) {
5204
5261
  const target = box2 ?? document.documentElement;
5205
5262
  const behaviour = target.style.scrollBehavior;
5206
5263
  target.style.scrollBehavior = "auto";
5207
- if (box2) box2.scrollTop = 0;
5208
- else window.scrollTo(0, 0);
5264
+ if (box2) box2.scrollTop = offset;
5265
+ else window.scrollTo(0, offset);
5209
5266
  target.style.scrollBehavior = behaviour;
5210
5267
  }
5211
5268
  function scrollerOf(el) {
@@ -5231,17 +5288,20 @@ const holds = /* @__PURE__ */ new Set();
5231
5288
  function releaseHolds() {
5232
5289
  for (const end2 of Array.from(holds)) end2();
5233
5290
  }
5234
- function anchorTop(onMoved = () => true, onEnd, box2 = null) {
5291
+ function anchorTop(onMoved = () => true, onEnd, box2 = null, at = TOP) {
5235
5292
  let released = false;
5236
5293
  let touching = false;
5237
5294
  const top2 = () => {
5238
5295
  if (released || touching) return;
5239
5296
  const document_ = window.scrollY || document.documentElement.scrollTop || 0;
5240
5297
  const pane = box2 ? box2.scrollTop : 0;
5241
- if (document_ <= 0 && pane <= 0) return;
5298
+ const off = (now, want) => want === 0 ? now > 0 : Math.abs(now - want) > 1;
5299
+ const documentOff = off(document_, at.doc);
5300
+ const paneOff = box2 !== null && off(pane, at.pane);
5301
+ if (!documentOff && !paneOff) return;
5242
5302
  if (!onMoved()) return;
5243
- if (document_ > 0) scrollToTop();
5244
- if (box2 && pane > 0) scrollToTop(box2);
5303
+ if (documentOff) scrollToOffset(at.doc);
5304
+ if (box2 && paneOff) scrollToOffset(at.pane, box2);
5245
5305
  };
5246
5306
  const down = (event) => {
5247
5307
  if (event.type !== "pointerdown" || event.pointerType === "touch") {
@@ -5321,6 +5381,7 @@ function onResize(el, resized) {
5321
5381
  }
5322
5382
  function anchorToTop() {
5323
5383
  if (typeof window === "undefined") return;
5384
+ leaveScreen();
5324
5385
  const top2 = () => scrollToTop();
5325
5386
  top2();
5326
5387
  if (typeof window.requestAnimationFrame === "function") window.requestAnimationFrame(top2);
@@ -5867,22 +5928,62 @@ function useScreenAnchor(ref, enabled = true) {
5867
5928
  if (!el || !enabled) return;
5868
5929
  const restore = withoutRestoration();
5869
5930
  let moved = false;
5870
- const hold = () => anchorTop(() => beginsOnTheFirstViewport(el), (end2) => {
5871
- if (end2 === "moved") moved = true;
5872
- }, scrollerOf(el));
5873
- let release = hold();
5874
- const again = () => {
5931
+ let holding = false;
5932
+ let returning = false;
5933
+ let at = TOP;
5934
+ const settle = () => {
5935
+ returning = false;
5936
+ settleReturn();
5937
+ };
5938
+ const hold = (entered) => {
5939
+ if (entered) {
5940
+ const back = returnOffset(here());
5941
+ returning = back !== null;
5942
+ at = back ?? TOP;
5943
+ }
5944
+ holding = true;
5945
+ return anchorTop(() => beginsOnTheFirstViewport(el), (end2) => {
5946
+ holding = false;
5947
+ if (end2 === "moved") moved = true;
5948
+ if (returning && end2 === "moved") settle();
5949
+ }, scrollerOf(el), at);
5950
+ };
5951
+ let screen2 = claimScreen();
5952
+ let release = hold(true);
5953
+ const again = (entered) => {
5875
5954
  release();
5876
- release = hold();
5955
+ release = hold(entered);
5877
5956
  };
5878
5957
  const unobserve = onReveal(el, () => {
5879
5958
  moved = false;
5880
- again();
5959
+ screen2 = claimScreen();
5960
+ again(true);
5881
5961
  });
5882
5962
  const settled = onResize(el, () => {
5883
- if (!moved) again();
5963
+ if (!moved) again(false);
5964
+ });
5965
+ const fan = (event) => {
5966
+ if (movesThePage(event)) moved = true;
5967
+ };
5968
+ for (const type of RELEASES) window.addEventListener(type, fan, {
5969
+ passive: true
5970
+ });
5971
+ const note2 = () => {
5972
+ if (!isCurrentScreen(screen2)) return;
5973
+ const now = placeOf(scrollerOf(el));
5974
+ if (returning && reached(now, at)) settle();
5975
+ if (holding) return;
5976
+ remember(here(), now);
5977
+ };
5978
+ document.addEventListener("scroll", note2, {
5979
+ capture: true,
5980
+ passive: true
5884
5981
  });
5885
5982
  return () => {
5983
+ for (const type of RELEASES) window.removeEventListener(type, fan);
5984
+ document.removeEventListener("scroll", note2, {
5985
+ capture: true
5986
+ });
5886
5987
  settled();
5887
5988
  unobserve();
5888
5989
  release();
@@ -11658,15 +11759,26 @@ function useDocumentSnap(ref, enabled = true) {
11658
11759
  passive: true
11659
11760
  });
11660
11761
  };
11762
+ let at = TOP;
11763
+ let returning = false;
11764
+ let holding = false;
11765
+ const settle = () => {
11766
+ returning = false;
11767
+ settleReturn();
11768
+ };
11661
11769
  const top2 = () => {
11662
- scrollToTop();
11663
- if (pane) scrollToTop(pane);
11770
+ scrollToOffset(at.doc);
11771
+ if (pane) scrollToOffset(at.pane, pane);
11664
11772
  };
11665
11773
  let frame2 = null;
11666
11774
  let release = () => {
11667
11775
  };
11668
11776
  const anchor2 = () => {
11669
11777
  release();
11778
+ const back = returnOffset(here());
11779
+ returning = back !== null;
11780
+ at = back ?? TOP;
11781
+ holding = true;
11670
11782
  if (frame2 !== null && typeof window.cancelAnimationFrame === "function") {
11671
11783
  window.cancelAnimationFrame(frame2);
11672
11784
  }
@@ -11682,18 +11794,42 @@ function useDocumentSnap(ref, enabled = true) {
11682
11794
  snapOnAtTouch();
11683
11795
  }
11684
11796
  return true;
11685
- }, void 0, pane);
11797
+ }, (end2) => {
11798
+ holding = false;
11799
+ if (returning && end2 === "moved") settle();
11800
+ }, pane, at);
11686
11801
  };
11802
+ let screen2 = claimScreen();
11687
11803
  anchor2();
11688
11804
  const history = window.history;
11689
11805
  const previousRestoration = history && "scrollRestoration" in history ? history.scrollRestoration : null;
11690
11806
  if (previousRestoration !== null) history.scrollRestoration = "manual";
11691
11807
  const onPageShow = (event) => {
11692
- if (event.persisted) anchor2();
11808
+ if (event.persisted) {
11809
+ screen2 = claimScreen();
11810
+ anchor2();
11811
+ }
11693
11812
  };
11694
11813
  window.addEventListener("pageshow", onPageShow);
11695
- const unobserve = onReveal(el, anchor2);
11814
+ const unobserve = onReveal(el, () => {
11815
+ screen2 = claimScreen();
11816
+ anchor2();
11817
+ });
11818
+ const note2 = () => {
11819
+ if (!isCurrentScreen(screen2)) return;
11820
+ const now = placeOf(pane);
11821
+ if (returning && reached(now, at)) settle();
11822
+ if (holding) return;
11823
+ remember(here(), now);
11824
+ };
11825
+ document.addEventListener("scroll", note2, {
11826
+ capture: true,
11827
+ passive: true
11828
+ });
11696
11829
  return () => {
11830
+ document.removeEventListener("scroll", note2, {
11831
+ capture: true
11832
+ });
11697
11833
  unobserve();
11698
11834
  release();
11699
11835
  if (frame2 !== null && typeof window.cancelAnimationFrame === "function") {
@@ -5189,6 +5189,60 @@ function requireClient() {
5189
5189
  return client;
5190
5190
  }
5191
5191
  var clientExports = requireClient();
5192
+ const TOP = {
5193
+ doc: 0,
5194
+ pane: 0
5195
+ };
5196
+ const places = /* @__PURE__ */ new Map();
5197
+ let returnedTo = null;
5198
+ function here() {
5199
+ if (typeof window === "undefined") return "";
5200
+ const { pathname, search, hash } = window.location;
5201
+ return pathname + search + hash;
5202
+ }
5203
+ if (typeof window !== "undefined") {
5204
+ window.addEventListener("popstate", () => {
5205
+ returnedTo = here();
5206
+ }, {
5207
+ capture: true
5208
+ });
5209
+ }
5210
+ function cameBack() {
5211
+ return returnedTo !== null && returnedTo === here();
5212
+ }
5213
+ function returnOffset(key) {
5214
+ if (!cameBack() || returnedTo !== key) return null;
5215
+ return places.get(key) ?? null;
5216
+ }
5217
+ function settleReturn() {
5218
+ returnedTo = null;
5219
+ }
5220
+ function remember(key, offset) {
5221
+ places.set(key, offset);
5222
+ }
5223
+ let latestScreen = 0;
5224
+ let currentScreen = 0;
5225
+ function claimScreen() {
5226
+ latestScreen += 1;
5227
+ currentScreen = latestScreen;
5228
+ return currentScreen;
5229
+ }
5230
+ function leaveScreen() {
5231
+ currentScreen = 0;
5232
+ settleReturn();
5233
+ }
5234
+ function isCurrentScreen(screen2) {
5235
+ return screen2 === currentScreen;
5236
+ }
5237
+ function placeOf(pane) {
5238
+ return {
5239
+ doc: window.scrollY || document.documentElement.scrollTop || 0,
5240
+ pane: pane ? pane.scrollTop : 0
5241
+ };
5242
+ }
5243
+ function reached(now, at) {
5244
+ return Math.abs(now.doc - at.doc) <= 1 && Math.abs(now.pane - at.pane) <= 1;
5245
+ }
5192
5246
  const HOLD_MS = 2500;
5193
5247
  function withoutRestoration() {
5194
5248
  const history = typeof window !== "undefined" ? window.history : void 0;
@@ -5201,11 +5255,14 @@ function withoutRestoration() {
5201
5255
  };
5202
5256
  }
5203
5257
  function scrollToTop(box2) {
5258
+ scrollToOffset(0, box2);
5259
+ }
5260
+ function scrollToOffset(offset, box2) {
5204
5261
  const target = box2 ?? document.documentElement;
5205
5262
  const behaviour = target.style.scrollBehavior;
5206
5263
  target.style.scrollBehavior = "auto";
5207
- if (box2) box2.scrollTop = 0;
5208
- else window.scrollTo(0, 0);
5264
+ if (box2) box2.scrollTop = offset;
5265
+ else window.scrollTo(0, offset);
5209
5266
  target.style.scrollBehavior = behaviour;
5210
5267
  }
5211
5268
  function scrollerOf(el) {
@@ -5231,17 +5288,20 @@ const holds = /* @__PURE__ */ new Set();
5231
5288
  function releaseHolds() {
5232
5289
  for (const end2 of Array.from(holds)) end2();
5233
5290
  }
5234
- function anchorTop(onMoved = () => true, onEnd, box2 = null) {
5291
+ function anchorTop(onMoved = () => true, onEnd, box2 = null, at = TOP) {
5235
5292
  let released = false;
5236
5293
  let touching = false;
5237
5294
  const top2 = () => {
5238
5295
  if (released || touching) return;
5239
5296
  const document_ = window.scrollY || document.documentElement.scrollTop || 0;
5240
5297
  const pane = box2 ? box2.scrollTop : 0;
5241
- if (document_ <= 0 && pane <= 0) return;
5298
+ const off = (now, want) => want === 0 ? now > 0 : Math.abs(now - want) > 1;
5299
+ const documentOff = off(document_, at.doc);
5300
+ const paneOff = box2 !== null && off(pane, at.pane);
5301
+ if (!documentOff && !paneOff) return;
5242
5302
  if (!onMoved()) return;
5243
- if (document_ > 0) scrollToTop();
5244
- if (box2 && pane > 0) scrollToTop(box2);
5303
+ if (documentOff) scrollToOffset(at.doc);
5304
+ if (box2 && paneOff) scrollToOffset(at.pane, box2);
5245
5305
  };
5246
5306
  const down = (event) => {
5247
5307
  if (event.type !== "pointerdown" || event.pointerType === "touch") {
@@ -5321,6 +5381,7 @@ function onResize(el, resized) {
5321
5381
  }
5322
5382
  function anchorToTop() {
5323
5383
  if (typeof window === "undefined") return;
5384
+ leaveScreen();
5324
5385
  const top2 = () => scrollToTop();
5325
5386
  top2();
5326
5387
  if (typeof window.requestAnimationFrame === "function") window.requestAnimationFrame(top2);
@@ -5867,22 +5928,62 @@ function useScreenAnchor(ref, enabled = true) {
5867
5928
  if (!el || !enabled) return;
5868
5929
  const restore = withoutRestoration();
5869
5930
  let moved = false;
5870
- const hold = () => anchorTop(() => beginsOnTheFirstViewport(el), (end2) => {
5871
- if (end2 === "moved") moved = true;
5872
- }, scrollerOf(el));
5873
- let release = hold();
5874
- const again = () => {
5931
+ let holding = false;
5932
+ let returning = false;
5933
+ let at = TOP;
5934
+ const settle = () => {
5935
+ returning = false;
5936
+ settleReturn();
5937
+ };
5938
+ const hold = (entered) => {
5939
+ if (entered) {
5940
+ const back = returnOffset(here());
5941
+ returning = back !== null;
5942
+ at = back ?? TOP;
5943
+ }
5944
+ holding = true;
5945
+ return anchorTop(() => beginsOnTheFirstViewport(el), (end2) => {
5946
+ holding = false;
5947
+ if (end2 === "moved") moved = true;
5948
+ if (returning && end2 === "moved") settle();
5949
+ }, scrollerOf(el), at);
5950
+ };
5951
+ let screen2 = claimScreen();
5952
+ let release = hold(true);
5953
+ const again = (entered) => {
5875
5954
  release();
5876
- release = hold();
5955
+ release = hold(entered);
5877
5956
  };
5878
5957
  const unobserve = onReveal(el, () => {
5879
5958
  moved = false;
5880
- again();
5959
+ screen2 = claimScreen();
5960
+ again(true);
5881
5961
  });
5882
5962
  const settled = onResize(el, () => {
5883
- if (!moved) again();
5963
+ if (!moved) again(false);
5964
+ });
5965
+ const fan = (event) => {
5966
+ if (movesThePage(event)) moved = true;
5967
+ };
5968
+ for (const type of RELEASES) window.addEventListener(type, fan, {
5969
+ passive: true
5970
+ });
5971
+ const note2 = () => {
5972
+ if (!isCurrentScreen(screen2)) return;
5973
+ const now = placeOf(scrollerOf(el));
5974
+ if (returning && reached(now, at)) settle();
5975
+ if (holding) return;
5976
+ remember(here(), now);
5977
+ };
5978
+ document.addEventListener("scroll", note2, {
5979
+ capture: true,
5980
+ passive: true
5884
5981
  });
5885
5982
  return () => {
5983
+ for (const type of RELEASES) window.removeEventListener(type, fan);
5984
+ document.removeEventListener("scroll", note2, {
5985
+ capture: true
5986
+ });
5886
5987
  settled();
5887
5988
  unobserve();
5888
5989
  release();
@@ -11658,15 +11759,26 @@ function useDocumentSnap(ref, enabled = true) {
11658
11759
  passive: true
11659
11760
  });
11660
11761
  };
11762
+ let at = TOP;
11763
+ let returning = false;
11764
+ let holding = false;
11765
+ const settle = () => {
11766
+ returning = false;
11767
+ settleReturn();
11768
+ };
11661
11769
  const top2 = () => {
11662
- scrollToTop();
11663
- if (pane) scrollToTop(pane);
11770
+ scrollToOffset(at.doc);
11771
+ if (pane) scrollToOffset(at.pane, pane);
11664
11772
  };
11665
11773
  let frame2 = null;
11666
11774
  let release = () => {
11667
11775
  };
11668
11776
  const anchor2 = () => {
11669
11777
  release();
11778
+ const back = returnOffset(here());
11779
+ returning = back !== null;
11780
+ at = back ?? TOP;
11781
+ holding = true;
11670
11782
  if (frame2 !== null && typeof window.cancelAnimationFrame === "function") {
11671
11783
  window.cancelAnimationFrame(frame2);
11672
11784
  }
@@ -11682,18 +11794,42 @@ function useDocumentSnap(ref, enabled = true) {
11682
11794
  snapOnAtTouch();
11683
11795
  }
11684
11796
  return true;
11685
- }, void 0, pane);
11797
+ }, (end2) => {
11798
+ holding = false;
11799
+ if (returning && end2 === "moved") settle();
11800
+ }, pane, at);
11686
11801
  };
11802
+ let screen2 = claimScreen();
11687
11803
  anchor2();
11688
11804
  const history = window.history;
11689
11805
  const previousRestoration = history && "scrollRestoration" in history ? history.scrollRestoration : null;
11690
11806
  if (previousRestoration !== null) history.scrollRestoration = "manual";
11691
11807
  const onPageShow = (event) => {
11692
- if (event.persisted) anchor2();
11808
+ if (event.persisted) {
11809
+ screen2 = claimScreen();
11810
+ anchor2();
11811
+ }
11693
11812
  };
11694
11813
  window.addEventListener("pageshow", onPageShow);
11695
- const unobserve = onReveal(el, anchor2);
11814
+ const unobserve = onReveal(el, () => {
11815
+ screen2 = claimScreen();
11816
+ anchor2();
11817
+ });
11818
+ const note2 = () => {
11819
+ if (!isCurrentScreen(screen2)) return;
11820
+ const now = placeOf(pane);
11821
+ if (returning && reached(now, at)) settle();
11822
+ if (holding) return;
11823
+ remember(here(), now);
11824
+ };
11825
+ document.addEventListener("scroll", note2, {
11826
+ capture: true,
11827
+ passive: true
11828
+ });
11696
11829
  return () => {
11830
+ document.removeEventListener("scroll", note2, {
11831
+ capture: true
11832
+ });
11697
11833
  unobserve();
11698
11834
  release();
11699
11835
  if (frame2 !== null && typeof window.cancelAnimationFrame === "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nok-integration/storefront-react",
3
- "version": "0.20.16",
3
+ "version": "0.20.17",
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",