{"version":3,"names":["isHtmlElement","node","HTMLElement","nodeType","isScrollable","element","axis","ownerDoc","ownerDocument","document","win","defaultView","window","style","getComputedStyle","overflowY","scrollHeight","clientHeight","overflowX","scrollWidth","clientWidth","hasScrollableAncestor","target","root","axes","parentElement","findScrollableTouchTarget"],"sources":["scrollable.ts"],"sourcesContent":["/**\n * Scroll-axis utilities used by the swipe-dismiss state machine.\n *\n * 1:1 port of Base UI React's `packages/react/src/utils/scrollable.ts`.\n * Identifies scrollable ancestors of a touch target so the swipe hook can\n * arbitrate between \"drag to dismiss\" and \"scroll the container\".\n */\n\nexport type ScrollAxis = \"horizontal\" | \"vertical\";\n\nfunction isHtmlElement(node: unknown): node is HTMLElement {\n\treturn (\n\t\ttypeof HTMLElement !== \"undefined\" &&\n\t\tnode != null &&\n\t\ttypeof (node as { nodeType?: unknown }).nodeType === \"number\" &&\n\t\t(node as HTMLElement).nodeType === 1 &&\n\t\tnode instanceof HTMLElement\n\t);\n}\n\nexport function isScrollable(element: HTMLElement, axis: ScrollAxis): boolean {\n\tconst ownerDoc = element.ownerDocument ?? document;\n\tconst win = ownerDoc.defaultView ?? window;\n\tconst style = win.getComputedStyle(element);\n\n\tif (axis === \"vertical\") {\n\t\tconst overflowY = style.overflowY;\n\t\treturn (\n\t\t\t(overflowY === \"auto\" || overflowY === \"scroll\") &&\n\t\t\telement.scrollHeight > element.clientHeight\n\t\t);\n\t}\n\n\tconst overflowX = style.overflowX;\n\treturn (\n\t\t(overflowX === \"auto\" || overflowX === \"scroll\") &&\n\t\telement.scrollWidth > element.clientWidth\n\t);\n}\n\nexport function hasScrollableAncestor(\n\ttarget: HTMLElement,\n\troot: HTMLElement,\n\taxes: ScrollAxis[],\n): boolean {\n\tlet node: HTMLElement | null = target;\n\twhile (node && node !== root) {\n\t\tfor (const axis of axes) {\n\t\t\tif (isScrollable(node, axis)) return true;\n\t\t}\n\t\tnode = node.parentElement;\n\t}\n\treturn false;\n}\n\nexport function findScrollableTouchTarget(\n\ttarget: EventTarget | null,\n\troot: HTMLElement,\n\taxis: ScrollAxis = \"vertical\",\n): HTMLElement | null {\n\tlet node = isHtmlElement(target) ? target : null;\n\twhile (node && node !== root) {\n\t\tif (isScrollable(node, axis)) return node;\n\t\tnode = node.parentElement;\n\t}\n\treturn isScrollable(root, axis) ? root : null;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,aAAaA,CAACC,IAAa,EAAuB;EAC1D,OACC,OAAOC,WAAW,KAAK,WAAW,IAClCD,IAAI,IAAI,IAAI,IACZ,OAAQA,IAAI,CAA4BE,QAAQ,KAAK,QAAQ,IAC5DF,IAAI,CAAiBE,QAAQ,KAAK,CAAC,IACpCF,IAAI,YAAYC,WAAW;AAE7B;AAEA,OAAO,SAASE,YAAYA,CAACC,OAAoB,EAAEC,IAAgB,EAAW;EAC7E,MAAMC,QAAQ,GAAGF,OAAO,CAACG,aAAa,IAAIC,QAAQ;EAClD,MAAMC,GAAG,GAAGH,QAAQ,CAACI,WAAW,IAAIC,MAAM;EAC1C,MAAMC,KAAK,GAAGH,GAAG,CAACI,gBAAgB,CAACT,OAAO,CAAC;EAE3C,IAAIC,IAAI,KAAK,UAAU,EAAE;IACxB,MAAMS,SAAS,GAAGF,KAAK,CAACE,SAAS;IACjC,OACC,CAACA,SAAS,KAAK,MAAM,IAAIA,SAAS,KAAK,QAAQ,KAC/CV,OAAO,CAACW,YAAY,GAAGX,OAAO,CAACY,YAAY;EAE7C;EAEA,MAAMC,SAAS,GAAGL,KAAK,CAACK,SAAS;EACjC,OACC,CAACA,SAAS,KAAK,MAAM,IAAIA,SAAS,KAAK,QAAQ,KAC/Cb,OAAO,CAACc,WAAW,GAAGd,OAAO,CAACe,WAAW;AAE3C;AAEA,OAAO,SAASC,qBAAqBA,CACpCC,MAAmB,EACnBC,IAAiB,EACjBC,IAAkB,EACR;EACV,IAAIvB,IAAwB,GAAGqB,MAAM;EACrC,OAAOrB,IAAI,IAAIA,IAAI,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