@sesionario/blocks 1.22.2 → 1.23.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/dist/index.cjs CHANGED
@@ -5181,7 +5181,7 @@ function VideoPlayer({
5181
5181
  setUserStarted(true);
5182
5182
  revealControls();
5183
5183
  },
5184
- className: "absolute inset-0 flex items-center justify-center bg-cover bg-center",
5184
+ className: "absolute inset-0 flex items-center justify-center bg-black bg-contain bg-center bg-no-repeat",
5185
5185
  style: poster ? { backgroundImage: `url(${poster})` } : void 0,
5186
5186
  children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-16 items-center justify-center rounded-full bg-black/50 backdrop-blur-sm transition group-hover:bg-black/70", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "size-8 translate-x-0.5", fill: "currentColor" }) })
5187
5187
  }
@@ -5646,6 +5646,340 @@ function useSearchHotkey(options = {}) {
5646
5646
  return { open, setOpen, toggle };
5647
5647
  }
5648
5648
 
5649
+ // src/lib/scroll-restoration/store.ts
5650
+ var MAX_MARKS = 30;
5651
+ var MAX_SNAPSHOT_ROUTES = 3;
5652
+ var PENDING_TRAVERSAL_TTL_MS = 1e3;
5653
+ var scrollMarks = /* @__PURE__ */ new Map();
5654
+ var snapshotsByRoute = /* @__PURE__ */ new Map();
5655
+ var pendingTraversalKey = null;
5656
+ var pendingTraversalTimeout = null;
5657
+ var popstateInstalled = false;
5658
+ function touchMapEntry(map, key, value, max) {
5659
+ if (map.has(key)) map.delete(key);
5660
+ map.set(key, value);
5661
+ while (map.size > max) {
5662
+ const oldest = map.keys().next().value;
5663
+ if (oldest === void 0) break;
5664
+ map.delete(oldest);
5665
+ }
5666
+ }
5667
+ function getScrollMark(routeKey) {
5668
+ const mark = scrollMarks.get(routeKey);
5669
+ if (!mark) return void 0;
5670
+ scrollMarks.delete(routeKey);
5671
+ scrollMarks.set(routeKey, mark);
5672
+ return mark;
5673
+ }
5674
+ function setScrollMark(routeKey, mark) {
5675
+ touchMapEntry(scrollMarks, routeKey, mark, MAX_MARKS);
5676
+ }
5677
+ function deleteScrollMark(routeKey) {
5678
+ scrollMarks.delete(routeKey);
5679
+ }
5680
+ function getSnapshot(routeKey, subKey) {
5681
+ const route = snapshotsByRoute.get(routeKey);
5682
+ if (!route) return void 0;
5683
+ snapshotsByRoute.delete(routeKey);
5684
+ snapshotsByRoute.set(routeKey, route);
5685
+ return route.get(subKey);
5686
+ }
5687
+ function setSnapshot(routeKey, subKey, value) {
5688
+ let route = snapshotsByRoute.get(routeKey);
5689
+ if (route) {
5690
+ snapshotsByRoute.delete(routeKey);
5691
+ } else {
5692
+ route = /* @__PURE__ */ new Map();
5693
+ }
5694
+ route.set(subKey, value);
5695
+ snapshotsByRoute.set(routeKey, route);
5696
+ while (snapshotsByRoute.size > MAX_SNAPSHOT_ROUTES) {
5697
+ const oldest = snapshotsByRoute.keys().next().value;
5698
+ if (oldest === void 0) break;
5699
+ snapshotsByRoute.delete(oldest);
5700
+ }
5701
+ }
5702
+ function deleteSnapshotsForRoute(routeKey) {
5703
+ snapshotsByRoute.delete(routeKey);
5704
+ }
5705
+ function clearRoute(routeKey) {
5706
+ deleteScrollMark(routeKey);
5707
+ deleteSnapshotsForRoute(routeKey);
5708
+ }
5709
+ function clearPendingTraversalTimer() {
5710
+ if (pendingTraversalTimeout !== null) {
5711
+ clearTimeout(pendingTraversalTimeout);
5712
+ pendingTraversalTimeout = null;
5713
+ }
5714
+ }
5715
+ function schedulePendingTraversalClear() {
5716
+ clearPendingTraversalTimer();
5717
+ pendingTraversalTimeout = setTimeout(() => {
5718
+ pendingTraversalKey = null;
5719
+ pendingTraversalTimeout = null;
5720
+ }, PENDING_TRAVERSAL_TTL_MS);
5721
+ }
5722
+ function ensurePopstateListener() {
5723
+ if (popstateInstalled || typeof window === "undefined") return;
5724
+ popstateInstalled = true;
5725
+ window.addEventListener("popstate", () => {
5726
+ pendingTraversalKey = window.location.pathname + window.location.search;
5727
+ schedulePendingTraversalClear();
5728
+ });
5729
+ }
5730
+ function isPendingTraversal(routeKey) {
5731
+ ensurePopstateListener();
5732
+ return pendingTraversalKey === routeKey;
5733
+ }
5734
+ function consumePendingTraversal(routeKey) {
5735
+ ensurePopstateListener();
5736
+ if (pendingTraversalKey !== routeKey) return false;
5737
+ pendingTraversalKey = null;
5738
+ clearPendingTraversalTimer();
5739
+ return true;
5740
+ }
5741
+ function getScrollTop(container) {
5742
+ if (!container) {
5743
+ return window.scrollY || document.documentElement.scrollTop || 0;
5744
+ }
5745
+ return container.scrollTop;
5746
+ }
5747
+ function setScrollTop(container, top) {
5748
+ if (!container) {
5749
+ window.scrollTo(0, top);
5750
+ return;
5751
+ }
5752
+ container.scrollTop = top;
5753
+ }
5754
+ function scrollportTop(container) {
5755
+ return container ? container.getBoundingClientRect().top : 0;
5756
+ }
5757
+ function scrollportBottom(container) {
5758
+ if (!container) return window.innerHeight;
5759
+ return container.getBoundingClientRect().bottom;
5760
+ }
5761
+ function escapeAttrValue(value) {
5762
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
5763
+ return CSS.escape(value);
5764
+ }
5765
+ return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
5766
+ }
5767
+ function resolveAnchor(container, attribute) {
5768
+ const scope = container ?? document;
5769
+ const nodes = scope.querySelectorAll(`[${attribute}]`);
5770
+ if (nodes.length === 0) return null;
5771
+ const portTop = scrollportTop(container);
5772
+ const portBottom = scrollportBottom(container);
5773
+ let bestId = null;
5774
+ let bestTop = 0;
5775
+ let bestScore = Infinity;
5776
+ for (const node of nodes) {
5777
+ if (!(node instanceof HTMLElement)) continue;
5778
+ const id = node.getAttribute(attribute);
5779
+ if (!id) continue;
5780
+ const rect = node.getBoundingClientRect();
5781
+ if (rect.bottom <= portTop || rect.top >= portBottom) continue;
5782
+ const relativeTop = rect.top - portTop;
5783
+ const score = Math.abs(relativeTop);
5784
+ if (score < bestScore) {
5785
+ bestScore = score;
5786
+ bestId = id;
5787
+ bestTop = relativeTop;
5788
+ }
5789
+ }
5790
+ if (!bestId) return null;
5791
+ return { id: bestId, top: bestTop };
5792
+ }
5793
+ function captureMark(container, attribute) {
5794
+ const anchor = resolveAnchor(container, attribute);
5795
+ return {
5796
+ top: getScrollTop(container),
5797
+ anchorId: anchor?.id ?? null,
5798
+ anchorTop: anchor?.top ?? 0
5799
+ };
5800
+ }
5801
+ function applyMark(container, mark, attribute) {
5802
+ if (mark.anchorId) {
5803
+ const scope = container ?? document;
5804
+ const el = scope.querySelector(
5805
+ `[${attribute}="${escapeAttrValue(mark.anchorId)}"]`
5806
+ );
5807
+ if (el instanceof HTMLElement) {
5808
+ const portTop = scrollportTop(container);
5809
+ const currentRelativeTop = el.getBoundingClientRect().top - portTop;
5810
+ const delta = currentRelativeTop - mark.anchorTop;
5811
+ setScrollTop(container, getScrollTop(container) + delta);
5812
+ return true;
5813
+ }
5814
+ }
5815
+ setScrollTop(container, mark.top);
5816
+ return false;
5817
+ }
5818
+ function getScrollHeight(container) {
5819
+ if (!container) {
5820
+ return Math.max(
5821
+ document.documentElement.scrollHeight,
5822
+ document.body?.scrollHeight ?? 0
5823
+ );
5824
+ }
5825
+ return container.scrollHeight;
5826
+ }
5827
+ var DEFAULT_ANCHOR_ATTRIBUTE = "data-scroll-anchor";
5828
+ var STABILIZE_MS = 600;
5829
+ var ScrollRestorationContext = React7.createContext(null);
5830
+ function useScrollRestorationContext() {
5831
+ return React7.useContext(ScrollRestorationContext);
5832
+ }
5833
+ function readContainer(containerRef) {
5834
+ return containerRef?.current ?? null;
5835
+ }
5836
+ function ScrollRestorationProvider({
5837
+ routeKey,
5838
+ containerRef,
5839
+ anchorAttribute = DEFAULT_ANCHOR_ATTRIBUTE,
5840
+ children
5841
+ }) {
5842
+ ensurePopstateListener();
5843
+ const traversalForRouteRef = React7.useRef({ routeKey: "", isTraversal: false });
5844
+ if (traversalForRouteRef.current.routeKey !== routeKey) {
5845
+ traversalForRouteRef.current = {
5846
+ routeKey,
5847
+ isTraversal: isPendingTraversal(routeKey)
5848
+ };
5849
+ }
5850
+ const isTraversal = traversalForRouteRef.current.isTraversal;
5851
+ const value = React7.useMemo(
5852
+ () => ({
5853
+ routeKey,
5854
+ isTraversal,
5855
+ anchorAttribute
5856
+ }),
5857
+ [routeKey, isTraversal, anchorAttribute]
5858
+ );
5859
+ React7.useEffect(() => {
5860
+ if (typeof window === "undefined" || !("scrollRestoration" in history)) {
5861
+ return;
5862
+ }
5863
+ const previous = history.scrollRestoration;
5864
+ history.scrollRestoration = "manual";
5865
+ return () => {
5866
+ history.scrollRestoration = previous;
5867
+ };
5868
+ }, []);
5869
+ const prevRouteKeyRef = React7.useRef(routeKey);
5870
+ const anchorAttributeRef = React7.useRef(anchorAttribute);
5871
+ anchorAttributeRef.current = anchorAttribute;
5872
+ React7.useEffect(() => {
5873
+ const container = readContainer(containerRef);
5874
+ const target = container ?? window;
5875
+ let rafId = 0;
5876
+ const onScroll = () => {
5877
+ if (rafId) return;
5878
+ rafId = requestAnimationFrame(() => {
5879
+ rafId = 0;
5880
+ setScrollMark(
5881
+ routeKey,
5882
+ captureMark(readContainer(containerRef), anchorAttribute)
5883
+ );
5884
+ });
5885
+ };
5886
+ target.addEventListener("scroll", onScroll, { passive: true });
5887
+ return () => {
5888
+ target.removeEventListener("scroll", onScroll);
5889
+ if (rafId) cancelAnimationFrame(rafId);
5890
+ };
5891
+ }, [routeKey, containerRef, anchorAttribute]);
5892
+ React7.useLayoutEffect(() => {
5893
+ const container = readContainer(containerRef);
5894
+ const prevKey = prevRouteKeyRef.current;
5895
+ if (prevKey !== routeKey) {
5896
+ setScrollMark(
5897
+ prevKey,
5898
+ captureMark(container, anchorAttributeRef.current)
5899
+ );
5900
+ prevRouteKeyRef.current = routeKey;
5901
+ }
5902
+ const hasHash = typeof window !== "undefined" && window.location.hash.length > 1;
5903
+ if (isTraversal) {
5904
+ consumePendingTraversal(routeKey);
5905
+ const mark = getScrollMark(routeKey);
5906
+ if (!mark) return void 0;
5907
+ applyMark(container, mark, anchorAttribute);
5908
+ return startStabilizationLoop(container, mark, anchorAttribute);
5909
+ }
5910
+ clearRoute(routeKey);
5911
+ if (!hasHash) {
5912
+ setScrollTop(container, 0);
5913
+ }
5914
+ return void 0;
5915
+ }, [routeKey, isTraversal, containerRef, anchorAttribute]);
5916
+ return /* @__PURE__ */ jsxRuntime.jsx(ScrollRestorationContext.Provider, { value, children });
5917
+ }
5918
+ function startStabilizationLoop(container, mark, attribute) {
5919
+ const startedAt = performance.now();
5920
+ let lastHeight = getScrollHeight(container);
5921
+ let rafId = 0;
5922
+ let aborted = false;
5923
+ const abort = () => {
5924
+ aborted = true;
5925
+ };
5926
+ const onUserIntent = () => {
5927
+ abort();
5928
+ };
5929
+ window.addEventListener("wheel", onUserIntent, {
5930
+ passive: true,
5931
+ once: true
5932
+ });
5933
+ window.addEventListener("touchstart", onUserIntent, {
5934
+ passive: true,
5935
+ once: true
5936
+ });
5937
+ window.addEventListener("keydown", onUserIntent, {
5938
+ passive: true,
5939
+ once: true
5940
+ });
5941
+ window.addEventListener("pointerdown", onUserIntent, {
5942
+ passive: true,
5943
+ once: true
5944
+ });
5945
+ const tick = () => {
5946
+ if (aborted) return;
5947
+ if (performance.now() - startedAt > STABILIZE_MS) return;
5948
+ const height = getScrollHeight(container);
5949
+ if (height !== lastHeight) {
5950
+ lastHeight = height;
5951
+ applyMark(container, mark, attribute);
5952
+ }
5953
+ rafId = requestAnimationFrame(tick);
5954
+ };
5955
+ rafId = requestAnimationFrame(tick);
5956
+ return () => {
5957
+ abort();
5958
+ if (rafId) cancelAnimationFrame(rafId);
5959
+ window.removeEventListener("wheel", onUserIntent);
5960
+ window.removeEventListener("touchstart", onUserIntent);
5961
+ window.removeEventListener("keydown", onUserIntent);
5962
+ window.removeEventListener("pointerdown", onUserIntent);
5963
+ };
5964
+ }
5965
+
5966
+ // src/hooks/useRestorableState.ts
5967
+ function useRestorableState(subKey, initializer) {
5968
+ const ctx = useScrollRestorationContext();
5969
+ const [state, setState] = React7.useState(() => {
5970
+ if (!ctx) return initializer();
5971
+ const traversal = ctx.isTraversal || isPendingTraversal(ctx.routeKey);
5972
+ if (!traversal) return initializer();
5973
+ const snap = getSnapshot(ctx.routeKey, subKey);
5974
+ return snap !== void 0 ? snap : initializer();
5975
+ });
5976
+ React7.useEffect(() => {
5977
+ if (!ctx) return;
5978
+ setSnapshot(ctx.routeKey, subKey, state);
5979
+ }, [ctx, subKey, state]);
5980
+ return [state, setState];
5981
+ }
5982
+
5649
5983
  // src/components/search/fuzzy.ts
5650
5984
  function normalize(value) {
5651
5985
  return value.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
@@ -8767,6 +9101,7 @@ exports.PaymentIcon = PaymentIcon;
8767
9101
  exports.PhoneInput = PhoneInput;
8768
9102
  exports.PlatformAccountMenu = PlatformAccountMenu;
8769
9103
  exports.PlatformNavbar = PlatformNavbar;
9104
+ exports.ScrollRestorationProvider = ScrollRestorationProvider;
8770
9105
  exports.SearchCommand = SearchCommand;
8771
9106
  exports.SearchablePicker = SearchablePicker;
8772
9107
  exports.SupportMessengerProvider = SupportMessengerProvider;
@@ -8803,7 +9138,9 @@ exports.useLanguageContext = useLanguageContext;
8803
9138
  exports.useMediaQuery = useMediaQuery2;
8804
9139
  exports.usePlaybackStats = usePlaybackStats;
8805
9140
  exports.useRealtimeChannel = useRealtimeChannel;
9141
+ exports.useRestorableState = useRestorableState;
8806
9142
  exports.useScrollFadeXEdges = useScrollFadeXEdges;
9143
+ exports.useScrollRestorationContext = useScrollRestorationContext;
8807
9144
  exports.useSearchHotkey = useSearchHotkey;
8808
9145
  exports.useSupportConversation = useSupportConversation;
8809
9146
  exports.useSupportMessenger = useSupportMessenger;