This commit is contained in:
nik
2025-10-03 22:27:28 +03:00
parent 829fad0e17
commit 871cf7e792
16520 changed files with 2967597 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
import type { ScrollLockStep } from './overflow-store.js';
export declare function adjustScrollbarPadding(): ScrollLockStep;

View File

@@ -0,0 +1 @@
function d(){let r;return{before({doc:e}){var l;let o=e.documentElement,t=(l=e.defaultView)!=null?l:window;r=Math.max(0,t.innerWidth-o.clientWidth)},after({doc:e,d:o}){let t=e.documentElement,l=Math.max(0,t.clientWidth-t.offsetWidth),n=Math.max(0,r-l);o.style(t,"paddingRight",`${n}px`)}}}export{d as adjustScrollbarPadding};

View File

@@ -0,0 +1,6 @@
import type { ScrollLockStep } from './overflow-store.js';
interface ContainerMetadata {
containers: (() => HTMLElement[])[];
}
export declare function handleIOSLocking(): ScrollLockStep<ContainerMetadata>;
export {};

View File

@@ -0,0 +1 @@
import{disposables as u}from'../../utils/disposables.js';import*as i from'../../utils/dom.js';import{isIOS as p}from'../../utils/platform.js';function w(){return p()?{before({doc:o,d:r,meta:m}){function a(s){for(let l of m().containers)for(let c of l())if(c.contains(s))return!0;return!1}r.microTask(()=>{var c;if(window.getComputedStyle(o.documentElement).scrollBehavior!=="auto"){let t=u();t.style(o.documentElement,"scrollBehavior","auto"),r.add(()=>r.microTask(()=>t.dispose()))}let s=(c=window.scrollY)!=null?c:window.pageYOffset,l=null;r.addEventListener(o,"click",t=>{if(i.isHTMLorSVGElement(t.target))try{let e=t.target.closest("a");if(!e)return;let{hash:n}=new URL(e.href),f=o.querySelector(n);i.isHTMLorSVGElement(f)&&!a(f)&&(l=f)}catch{}},!0),r.group(t=>{r.addEventListener(o,"touchstart",e=>{if(t.dispose(),i.isHTMLorSVGElement(e.target)&&i.hasInlineStyle(e.target))if(a(e.target)){let n=e.target;for(;n.parentElement&&a(n.parentElement);)n=n.parentElement;t.style(n,"overscrollBehavior","contain")}else t.style(e.target,"touchAction","none")})}),r.addEventListener(o,"touchmove",t=>{if(i.isHTMLorSVGElement(t.target)){if(i.isHTMLInputElement(t.target))return;if(a(t.target)){let e=t.target;for(;e.parentElement&&e.dataset.headlessuiPortal!==""&&!(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth);)e=e.parentElement;e.dataset.headlessuiPortal===""&&t.preventDefault()}else t.preventDefault()}},{passive:!1}),r.add(()=>{var e;let t=(e=window.scrollY)!=null?e:window.pageYOffset;s!==t&&window.scrollTo(0,s),l&&l.isConnected&&(l.scrollIntoView({block:"nearest"}),l=null)})})}}:{}}export{w as handleIOSLocking};

View File

@@ -0,0 +1,20 @@
import { type Disposables } from '../../utils/disposables.js';
interface DocEntry {
doc: Document;
count: number;
d: Disposables;
meta: Set<MetaFn>;
computedMeta: Record<string, any>;
}
export type MetaFn = (meta: Record<string, any>) => Record<string, any>;
export interface Context<MetaType extends Record<string, any> = any> {
doc: Document;
d: Disposables;
meta: () => MetaType;
}
export interface ScrollLockStep<MetaType extends Record<string, any> = any> {
before?: (ctx: Context<MetaType>) => void;
after?: (ctx: Context<MetaType>) => void;
}
export declare let overflows: import('../../utils/store.js').Store<Map<Document, DocEntry>, "PUSH" | "POP" | "SCROLL_PREVENT" | "SCROLL_ALLOW" | "TEARDOWN">;
export {};

View File

@@ -0,0 +1 @@
import{disposables as s}from'../../utils/disposables.js';import{createStore as d}from'../../utils/store.js';import{adjustScrollbarPadding as i}from'./adjust-scrollbar-padding.js';import{handleIOSLocking as l}from'./handle-ios-locking.js';import{preventScroll as p}from'./prevent-scroll.js';function r(e){let o={};for(let t of e)Object.assign(o,t(o));return o}let c=d(()=>new Map,{PUSH(e,o){var n;let t=(n=this.get(e))!=null?n:{doc:e,count:0,d:s(),meta:new Set,computedMeta:{}};return t.count++,t.meta.add(o),t.computedMeta=r(t.meta),this.set(e,t),this},POP(e,o){let t=this.get(e);return t&&(t.count--,t.meta.delete(o),t.computedMeta=r(t.meta)),this},SCROLL_PREVENT(e){let o={doc:e.doc,d:e.d,meta(){return e.computedMeta}},t=[l(),i(),p()];t.forEach(({before:n})=>n==null?void 0:n(o)),t.forEach(({after:n})=>n==null?void 0:n(o))},SCROLL_ALLOW({d:e}){e.dispose()},TEARDOWN({doc:e}){this.delete(e)}});c.subscribe(()=>{let e=c.getSnapshot(),o=new Map;for(let[t]of e)o.set(t,t.documentElement.style.overflow);for(let t of e.values()){let n=o.get(t.doc)==="hidden",a=t.count!==0;(a&&!n||!a&&n)&&c.dispatch(t.count>0?"SCROLL_PREVENT":"SCROLL_ALLOW",t),t.count===0&&c.dispatch("TEARDOWN",t)}});export{c as overflows};

View File

@@ -0,0 +1,2 @@
import type { ScrollLockStep } from './overflow-store.js';
export declare function preventScroll(): ScrollLockStep;

View File

@@ -0,0 +1 @@
function r(){return{before({doc:e,d:o}){o.style(e.documentElement,"overflow","hidden")}}}export{r as preventScroll};

View File

@@ -0,0 +1 @@
export declare function useDocumentOverflowLockedEffect(shouldBeLocked: boolean, doc: Document | null, meta?: (meta: Record<string, any>) => Record<string, any>): boolean;

View File

@@ -0,0 +1 @@
import{useStore as s}from'../../hooks/use-store.js';import{useIsoMorphicEffect as u}from'../use-iso-morphic-effect.js';import{overflows as t}from'./overflow-store.js';function a(r,e,n=()=>({containers:[]})){let f=s(t),o=e?f.get(e):void 0,i=o?o.count>0:!1;return u(()=>{if(!(!e||!r))return t.dispatch("PUSH",e,n),()=>t.dispatch("POP",e,n)},[r,e]),i}export{a as useDocumentOverflowLockedEffect};