UNPKG

sui-explorer-local

Version:
13 lines (12 loc) 27.6 kB
import{r as s,a as be}from"./index-76fb7be0.js";import{u as ye,P as De,L as Ne}from"./motion-b354e7ba.js";import{f as $e,u as Be}from"./SVGVisualElement-4900b852.js";import{u as Ke}from"./use-unmount-effect-01fa1bae.js";import{c as ze,b as ce,g as Y}from"./floating-ui.dom-e51562ba.js";import{r as Ee}from"./index-d3ea75b5.js";function Re(){const t=s.useRef(!1);return ye(()=>(t.current=!0,()=>{t.current=!1}),[]),t}function We(){const t=Re(),[e,n]=s.useState(0),r=s.useCallback(()=>{t.current&&n(e+1)},[e]);return[s.useCallback(()=>$e.postRender(r),[r]),e]}class Ve extends s.Component{getSnapshotBeforeUpdate(e){const n=this.props.childRef.current;if(n&&e.isPresent&&!this.props.isPresent){const r=this.props.sizeRef.current;r.height=n.offsetHeight||0,r.width=n.offsetWidth||0,r.top=n.offsetTop,r.left=n.offsetLeft}return null}componentDidUpdate(){}render(){return this.props.children}}function He({children:t,isPresent:e}){const n=s.useId(),r=s.useRef(null),o=s.useRef({width:0,height:0,top:0,left:0});return s.useInsertionEffect(()=>{const{width:u,height:i,top:a,left:f}=o.current;if(e||!r.current||!u||!i)return;r.current.dataset.motionPopId=n;const c=document.createElement("style");return document.head.appendChild(c),c.sheet&&c.sheet.insertRule(` [data-motion-pop-id="${n}"] { position: absolute !important; width: ${u}px !important; height: ${i}px !important; top: ${a}px !important; left: ${f}px !important; } `),()=>{document.head.removeChild(c)}},[e]),s.createElement(Ve,{isPresent:e,childRef:r,sizeRef:o},s.cloneElement(t,{ref:r}))}const Z=({children:t,initial:e,isPresent:n,onExitComplete:r,custom:o,presenceAffectsLayout:u,mode:i})=>{const a=Be(je),f=s.useId(),c=s.useMemo(()=>({id:f,initial:e,isPresent:n,custom:o,onExitComplete:v=>{a.set(v,!0);for(const p of a.values())if(!p)return;r&&r()},register:v=>(a.set(v,!1),()=>a.delete(v))}),u?void 0:[n]);return s.useMemo(()=>{a.forEach((v,p)=>a.set(p,!1))},[n]),s.useEffect(()=>{!n&&!a.size&&r&&r()},[n]),i==="popLayout"&&(t=s.createElement(He,{isPresent:n},t)),s.createElement(De.Provider,{value:c},t)};function je(){return new Map}const z=t=>t.key||"";function Ue(t,e){t.forEach(n=>{const r=z(n);e.set(r,n)})}function _e(t){const e=[];return s.Children.forEach(t,n=>{s.isValidElement(n)&&e.push(n)}),e}const Ht=({children:t,custom:e,initial:n=!0,onExitComplete:r,exitBeforeEnter:o,presenceAffectsLayout:u=!0,mode:i="sync"})=>{const a=s.useContext(Ne).forceRender||We()[0],f=Re(),c=_e(t);let v=c;const p=s.useRef(new Map).current,h=s.useRef(v),d=s.useRef(new Map).current,g=s.useRef(!0);if(ye(()=>{g.current=!1,Ue(c,d),h.current=v}),Ke(()=>{g.current=!0,d.clear(),p.clear()}),g.current)return s.createElement(s.Fragment,null,v.map(m=>s.createElement(Z,{key:z(m),isPresent:!0,initial:n?void 0:!1,presenceAffectsLayout:u,mode:i},m)));v=[...v];const l=h.current.map(z),E=c.map(z),S=l.length;for(let m=0;m<S;m++){const w=l[m];E.indexOf(w)===-1&&!p.has(w)&&p.set(w,void 0)}return i==="wait"&&p.size&&(v=[]),p.forEach((m,w)=>{if(E.indexOf(w)!==-1)return;const M=d.get(w);if(!M)return;const L=l.indexOf(w);let P=m;if(!P){const F=()=>{p.delete(w);const k=Array.from(d.keys()).filter(O=>!E.includes(O));if(k.forEach(O=>d.delete(O)),h.current=c.filter(O=>{const T=z(O);return T===w||k.includes(T)}),!p.size){if(f.current===!1)return;a(),r&&r()}};P=s.createElement(Z,{key:z(M),isPresent:!1,onExitComplete:F,custom:e,presenceAffectsLayout:u,mode:i},M),p.set(w,P)}v.splice(L,0,P)}),v=v.map(m=>{const w=m.key;return p.has(w)?m:s.createElement(Z,{key:z(m),isPresent:!0,presenceAffectsLayout:u,mode:i},m)}),s.createElement(s.Fragment,null,p.size?v:v.map(m=>s.cloneElement(m)))},jt=t=>{const{element:e,padding:n}=t;function r(o){return Object.prototype.hasOwnProperty.call(o,"current")}return{name:"arrow",options:t,fn(o){return r(e)?e.current!=null?ce({element:e.current,padding:n}).fn(o):{}:e?ce({element:e,padding:n}).fn(o):{}}}};var V=typeof document<"u"?s.useLayoutEffect:s.useEffect;function U(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,o;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!=e.length)return!1;for(r=n;r--!==0;)if(!U(t[r],e[r]))return!1;return!0}if(o=Object.keys(t),n=o.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!Object.prototype.hasOwnProperty.call(e,o[r]))return!1;for(r=n;r--!==0;){const u=o[r];if(!(u==="_owner"&&t.$$typeof)&&!U(t[u],e[u]))return!1}return!0}return t!==t&&e!==e}function le(t){const e=s.useRef(t);return V(()=>{e.current=t}),e}function qe(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:o,whileElementsMounted:u,open:i}=t,[a,f]=s.useState({x:null,y:null,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[c,v]=s.useState(r);U(c,r)||v(r);const p=s.useRef(null),h=s.useRef(null),d=s.useRef(a),g=le(u),l=le(o),[E,S]=s.useState(null),[m,w]=s.useState(null),M=s.useCallback(T=>{p.current!==T&&(p.current=T,S(T))},[]),L=s.useCallback(T=>{h.current!==T&&(h.current=T,w(T))},[]),P=s.useCallback(()=>{if(!p.current||!h.current)return;const T={placement:e,strategy:n,middleware:c};l.current&&(T.platform=l.current),ze(p.current,h.current,T).then(x=>{const I={...x,isPositioned:!0};F.current&&!U(d.current,I)&&(d.current=I,Ee.flushSync(()=>{f(I)}))})},[c,e,n,l]);V(()=>{i===!1&&d.current.isPositioned&&(d.current.isPositioned=!1,f(T=>({...T,isPositioned:!1})))},[i]);const F=s.useRef(!1);V(()=>(F.current=!0,()=>{F.current=!1}),[]),V(()=>{if(E&&m){if(g.current)return g.current(E,m,P);P()}},[E,m,P,g]);const k=s.useMemo(()=>({reference:p,floating:h,setReference:M,setFloating:L}),[M,L]),O=s.useMemo(()=>({reference:E,floating:m}),[E,m]);return s.useMemo(()=>({...a,update:P,refs:k,elements:O,reference:M,floating:L}),[a,P,k,O,M,L])}/*! * tabbable 6.2.0 * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE */var Ge=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"],re=Ge.join(","),we=typeof Element>"u",W=we?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,_=!we&&Element.prototype.getRootNode?function(t){var e;return t==null||(e=t.getRootNode)===null||e===void 0?void 0:e.call(t)}:function(t){return t==null?void 0:t.ownerDocument},q=function t(e,n){var r;n===void 0&&(n=!0);var o=e==null||(r=e.getAttribute)===null||r===void 0?void 0:r.call(e,"inert"),u=o===""||o==="true",i=u||n&&e&&t(e.parentNode);return i},Xe=function(e){var n,r=e==null||(n=e.getAttribute)===null||n===void 0?void 0:n.call(e,"contenteditable");return r===""||r==="true"},Ye=function(e,n,r){if(q(e))return[];var o=Array.prototype.slice.apply(e.querySelectorAll(re));return n&&W.call(e,re)&&o.unshift(e),o=o.filter(r),o},Ze=function t(e,n,r){for(var o=[],u=Array.from(e);u.length;){var i=u.shift();if(!q(i,!1))if(i.tagName==="SLOT"){var a=i.assignedElements(),f=a.length?a:i.children,c=t(f,!0,r);r.flatten?o.push.apply(o,c):o.push({scopeParent:i,candidates:c})}else{var v=W.call(i,re);v&&r.filter(i)&&(n||!e.includes(i))&&o.push(i);var p=i.shadowRoot||typeof r.getShadowRoot=="function"&&r.getShadowRoot(i),h=!q(p,!1)&&(!r.shadowRootFilter||r.shadowRootFilter(i));if(p&&h){var d=t(p===!0?i.children:p.children,!0,r);r.flatten?o.push.apply(o,d):o.push({scopeParent:i,candidates:d})}else u.unshift.apply(u,i.children)}}return o},Ce=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},xe=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||Xe(e))&&!Ce(e)?0:e.tabIndex},Je=function(e,n){var r=xe(e);return r<0&&n&&!Ce(e)?0:r},Qe=function(e,n){return e.tabIndex===n.tabIndex?e.documentOrder-n.documentOrder:e.tabIndex-n.tabIndex},Se=function(e){return e.tagName==="INPUT"},et=function(e){return Se(e)&&e.type==="hidden"},tt=function(e){var n=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(r){return r.tagName==="SUMMARY"});return n},nt=function(e,n){for(var r=0;r<e.length;r++)if(e[r].checked&&e[r].form===n)return e[r]},rt=function(e){if(!e.name)return!0;var n=e.form||_(e),r=function(a){return n.querySelectorAll('input[type="radio"][name="'+a+'"]')},o;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")o=r(window.CSS.escape(e.name));else try{o=r(e.name)}catch(i){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",i.message),!1}var u=nt(o,e.form);return!u||u===e},ot=function(e){return Se(e)&&e.type==="radio"},st=function(e){return ot(e)&&!rt(e)},ut=function(e){var n,r=e&&_(e),o=(n=r)===null||n===void 0?void 0:n.host,u=!1;if(r&&r!==e){var i,a,f;for(u=!!((i=o)!==null&&i!==void 0&&(a=i.ownerDocument)!==null&&a!==void 0&&a.contains(o)||e!=null&&(f=e.ownerDocument)!==null&&f!==void 0&&f.contains(e));!u&&o;){var c,v,p;r=_(o),o=(c=r)===null||c===void 0?void 0:c.host,u=!!((v=o)!==null&&v!==void 0&&(p=v.ownerDocument)!==null&&p!==void 0&&p.contains(o))}}return u},fe=function(e){var n=e.getBoundingClientRect(),r=n.width,o=n.height;return r===0&&o===0},it=function(e,n){var r=n.displayCheck,o=n.getShadowRoot;if(getComputedStyle(e).visibility==="hidden")return!0;var u=W.call(e,"details>summary:first-of-type"),i=u?e.parentElement:e;if(W.call(i,"details:not([open]) *"))return!0;if(!r||r==="full"||r==="legacy-full"){if(typeof o=="function"){for(var a=e;e;){var f=e.parentElement,c=_(e);if(f&&!f.shadowRoot&&o(f)===!0)return fe(e);e.assignedSlot?e=e.assignedSlot:!f&&c!==e.ownerDocument?e=c.host:e=f}e=a}if(ut(e))return!e.getClientRects().length;if(r!=="legacy-full")return!0}else if(r==="non-zero-area")return fe(e);return!1},at=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var n=e.parentElement;n;){if(n.tagName==="FIELDSET"&&n.disabled){for(var r=0;r<n.children.length;r++){var o=n.children.item(r);if(o.tagName==="LEGEND")return W.call(n,"fieldset[disabled] *")?!0:!o.contains(e)}return!0}n=n.parentElement}return!1},ct=function(e,n){return!(n.disabled||q(n)||et(n)||it(n,e)||tt(n)||at(n))},de=function(e,n){return!(st(n)||xe(n)<0||!ct(e,n))},lt=function(e){var n=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(n)||n>=0)},ft=function t(e){var n=[],r=[];return e.forEach(function(o,u){var i=!!o.scopeParent,a=i?o.scopeParent:o,f=Je(a,i),c=i?t(o.candidates):a;f===0?i?n.push.apply(n,c):n.push(a):r.push({documentOrder:u,tabIndex:f,item:o,isScope:i,content:c})}),r.sort(Qe).reduce(function(o,u){return u.isScope?o.push.apply(o,u.content):o.push(u.content),o},[]).concat(n)},Te=function(e,n){n=n||{};var r;return n.getShadowRoot?r=Ze([e],n.includeContainer,{filter:de.bind(null,n),flatten:!1,getShadowRoot:n.getShadowRoot,shadowRootFilter:lt}):r=Ye(e,n.includeContainer,de.bind(null,n)),ft(r)};function oe(){return oe=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},oe.apply(this,arguments)}var K=typeof document<"u"?s.useLayoutEffect:s.useEffect;let J=!1,dt=0;const me=()=>"floating-ui-"+dt++;function mt(){const[t,e]=s.useState(()=>J?me():void 0);return K(()=>{t==null&&e(me())},[]),s.useEffect(()=>{J||(J=!0)},[]),t}const pt=be["useId".toString()],se=pt||mt;function vt(){const t=new Map;return{emit(e,n){var r;(r=t.get(e))==null||r.forEach(o=>o(n))},on(e,n){t.set(e,[...t.get(e)||[],n])},off(e,n){var r;t.set(e,((r=t.get(e))==null?void 0:r.filter(o=>o!==n))||[])}}}const gt=s.createContext(null),ht=s.createContext(null),Ie=()=>{var t;return((t=s.useContext(gt))==null?void 0:t.id)||null},ue=()=>s.useContext(ht);function B(t){return(t==null?void 0:t.ownerDocument)||document}function bt(){const t=navigator.userAgentData;return t!=null&&t.platform?t.platform:navigator.platform}function yt(){const t=navigator.userAgentData;return t&&Array.isArray(t.brands)?t.brands.map(e=>{let{brand:n,version:r}=e;return n+"/"+r}).join(" "):navigator.userAgent}function X(t){return B(t).defaultView||window}function N(t){return t?t instanceof X(t).Element:!1}function Pe(t){return t?t instanceof X(t).HTMLElement:!1}function Et(t){if(typeof ShadowRoot>"u")return!1;const e=X(t).ShadowRoot;return t instanceof e||t instanceof ShadowRoot}function Rt(t){if(t.mozInputSource===0&&t.isTrusted)return!0;const e=/Android/i;return(e.test(bt())||e.test(yt()))&&t.pointerType?t.type==="click"&&t.buttons===1:t.detail===0&&!t.pointerType}function wt(t){return t.width===0&&t.height===0||t.width===1&&t.height===1&&t.pressure===0&&t.detail===0&&t.pointerType!=="mouse"||t.width<1&&t.height<1&&t.pressure===0&&t.detail===0}function Ct(){return/apple/i.test(navigator.vendor)}function Me(t,e){const n=["mouse","pen"];return e||n.push("",void 0),n.includes(t)}function G(t,e){if(!t||!e)return!1;const n=e.getRootNode&&e.getRootNode();if(t.contains(e))return!0;if(n&&Et(n)){let r=e;for(;r;){if(t===r)return!0;r=r.parentNode||r.host}}return!1}function pe(t){const e=s.useRef(t);return K(()=>{e.current=t}),e}const ve="data-floating-ui-safe-polygon";function Q(t,e,n){return n&&!Me(n)?0:typeof t=="number"?t:t==null?void 0:t[e]}const Ut=function(t,e){e===void 0&&(e={});const{open:n,onOpenChange:r,dataRef:o,events:u,elements:{domReference:i,floating:a},refs:f}=t,{enabled:c=!0,delay:v=0,handleClose:p=null,mouseOnly:h=!1,restMs:d=0,move:g=!0}=e,l=ue(),E=Ie(),S=pe(p),m=pe(v),w=s.useRef(),M=s.useRef(),L=s.useRef(),P=s.useRef(),F=s.useRef(!0),k=s.useRef(!1),O=s.useRef(()=>{}),T=s.useCallback(()=>{var b;const R=(b=o.current.openEvent)==null?void 0:b.type;return(R==null?void 0:R.includes("mouse"))&&R!=="mousedown"},[o]);s.useEffect(()=>{if(!c)return;function b(){clearTimeout(M.current),clearTimeout(P.current),F.current=!0}return u.on("dismiss",b),()=>{u.off("dismiss",b)}},[c,u]),s.useEffect(()=>{if(!c||!S.current||!n)return;function b(){T()&&r(!1)}const R=B(a).documentElement;return R.addEventListener("mouseleave",b),()=>{R.removeEventListener("mouseleave",b)}},[a,n,r,c,S,o,T]);const x=s.useCallback(function(b){b===void 0&&(b=!0);const R=Q(m.current,"close",w.current);R&&!L.current?(clearTimeout(M.current),M.current=setTimeout(()=>r(!1),R)):b&&(clearTimeout(M.current),r(!1))},[m,r]),I=s.useCallback(()=>{O.current(),L.current=void 0},[]),y=s.useCallback(()=>{if(k.current){const b=B(f.floating.current).body;b.style.pointerEvents="",b.removeAttribute(ve),k.current=!1}},[f]);return s.useEffect(()=>{if(!c)return;function b(){return o.current.openEvent?["click","mousedown"].includes(o.current.openEvent.type):!1}function R(C){if(clearTimeout(M.current),F.current=!1,h&&!Me(w.current)||d>0&&Q(m.current,"open")===0)return;o.current.openEvent=C;const $=Q(m.current,"open",w.current);$?M.current=setTimeout(()=>{r(!0)},$):r(!0)}function D(C){if(b())return;O.current();const $=B(a);if(clearTimeout(P.current),S.current){n||clearTimeout(M.current),L.current=S.current({...t,tree:l,x:C.clientX,y:C.clientY,onClose(){y(),I(),x()}});const ae=L.current;$.addEventListener("mousemove",ae),O.current=()=>{$.removeEventListener("mousemove",ae)};return}(w.current==="touch"?!G(a,C.relatedTarget):!0)&&x()}function A(C){b()||S.current==null||S.current({...t,tree:l,x:C.clientX,y:C.clientY,onClose(){y(),I(),x()}})(C)}if(N(i)){const C=i;return n&&C.addEventListener("mouseleave",A),a==null||a.addEventListener("mouseleave",A),g&&C.addEventListener("mousemove",R,{once:!0}),C.addEventListener("mouseenter",R),C.addEventListener("mouseleave",D),()=>{n&&C.removeEventListener("mouseleave",A),a==null||a.removeEventListener("mouseleave",A),g&&C.removeEventListener("mousemove",R),C.removeEventListener("mouseenter",R),C.removeEventListener("mouseleave",D)}}},[i,a,c,t,h,d,g,x,I,y,r,n,l,m,S,o]),K(()=>{var b;if(c&&n&&(b=S.current)!=null&&b.__options.blockPointerEvents&&T()){const A=B(a).body;if(A.setAttribute(ve,""),A.style.pointerEvents="none",k.current=!0,N(i)&&a){var R,D;const C=i,$=l==null||(R=l.nodesRef.current.find(ie=>ie.id===E))==null||(D=R.context)==null?void 0:D.elements.floating;return $&&($.style.pointerEvents=""),C.style.pointerEvents="auto",a.style.pointerEvents="auto",()=>{C.style.pointerEvents="",a.style.pointerEvents=""}}}},[c,n,E,a,i,l,S,o,T]),K(()=>{n||(w.current=void 0,I(),y())},[n,I,y]),s.useEffect(()=>()=>{I(),clearTimeout(M.current),clearTimeout(P.current),y()},[c,I,y]),s.useMemo(()=>{if(!c)return{};function b(R){w.current=R.pointerType}return{reference:{onPointerDown:b,onPointerEnter:b,onMouseMove(){n||d===0||(clearTimeout(P.current),P.current=setTimeout(()=>{F.current||r(!0)},d))}},floating:{onMouseEnter(){clearTimeout(M.current)},onMouseLeave(){u.emit("dismiss",{type:"mouseLeave",data:{returnFocus:!1}}),x(!1)}}}},[u,c,d,n,r,x])};function Oe(t){let e=t.activeElement;for(;((n=e)==null||(r=n.shadowRoot)==null?void 0:r.activeElement)!=null;){var n,r;e=e.shadowRoot.activeElement}return e}function ee(t,e){let n=t.filter(o=>{var u;return o.parentId===e&&((u=o.context)==null?void 0:u.open)}),r=n;for(;r.length;)r=t.filter(o=>{var u;return(u=r)==null?void 0:u.some(i=>{var a;return o.parentId===i.id&&((a=o.context)==null?void 0:a.open)})}),n=n.concat(r);return n}function xt(t){return"composedPath"in t?t.composedPath()[0]:t.target}const Le=()=>({getShadowRoot:!0,displayCheck:typeof ResizeObserver=="function"&&ResizeObserver.toString().includes("[native code]")?"full":"none"});function Ae(t,e){const n=Te(t,Le());e==="prev"&&n.reverse();const r=n.indexOf(Oe(B(t)));return n.slice(r+1)[0]}function St(){return Ae(document.body,"next")}function Tt(){return Ae(document.body,"prev")}function te(t,e){const n=e||t.currentTarget,r=t.relatedTarget;return!r||!G(n,r)}function It(t){Te(t,Le()).forEach(n=>{n.dataset.tabindex=n.getAttribute("tabindex")||"",n.setAttribute("tabindex","-1")})}function Pt(t){t.querySelectorAll("[data-tabindex]").forEach(n=>{const r=n.dataset.tabindex;delete n.dataset.tabindex,r?n.setAttribute("tabindex",r):n.removeAttribute("tabindex")})}const Fe={border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"fixed",whiteSpace:"nowrap",width:"1px",top:0,left:0};let Mt;function ge(t){t.key==="Tab"&&(t.target,clearTimeout(Mt))}const he=s.forwardRef(function(e,n){const[r,o]=s.useState();return K(()=>(Ct()&&o("button"),document.addEventListener("keydown",ge),()=>{document.removeEventListener("keydown",ge)}),[]),s.createElement("span",oe({},e,{ref:n,tabIndex:0,role:r,"aria-hidden":r?void 0:!0,"data-floating-ui-focus-guard":"",style:Fe}))}),ke=s.createContext(null),Ot=function(t){let{id:e,root:n}=t===void 0?{}:t;const[r,o]=s.useState(null),u=se(),i=Lt(),a=s.useMemo(()=>({id:e,root:n,portalContext:i,uniqueId:u}),[e,n,i,u]),f=s.useRef();return K(()=>()=>{r==null||r.remove()},[r,a]),K(()=>{if(f.current===a)return;f.current=a;const{id:c,root:v,portalContext:p,uniqueId:h}=a,d=c?document.getElementById(c):null,g="data-floating-ui-portal";if(d){const l=document.createElement("div");l.id=h,l.setAttribute(g,""),d.appendChild(l),o(l)}else{let l=(p==null?void 0:p.portalNode)||v||document.body,E=null;c&&(E=document.createElement("div"),E.id=c,l.appendChild(E));const S=document.createElement("div");S.id=h,S.setAttribute(g,""),l=E||l,l.appendChild(S),o(S)}},[a]),r},_t=t=>{let{children:e,id:n,root:r=null,preserveTabOrder:o=!0}=t;const u=Ot({id:n,root:r}),[i,a]=s.useState(null),f=s.useRef(null),c=s.useRef(null),v=s.useRef(null),p=s.useRef(null),h=!!i&&!i.modal&&i.open&&o&&!!(r||u);return s.useEffect(()=>{if(!u||!o||i!=null&&i.modal)return;function d(g){u&&te(g)&&(g.type==="focusin"?Pt:It)(u)}return u.addEventListener("focusin",d,!0),u.addEventListener("focusout",d,!0),()=>{u.removeEventListener("focusin",d,!0),u.removeEventListener("focusout",d,!0)}},[u,o,i==null?void 0:i.modal]),s.createElement(ke.Provider,{value:s.useMemo(()=>({preserveTabOrder:o,beforeOutsideRef:f,afterOutsideRef:c,beforeInsideRef:v,afterInsideRef:p,portalNode:u,setFocusManagerState:a}),[o,u])},h&&u&&s.createElement(he,{"data-type":"outside",ref:f,onFocus:d=>{if(te(d,u)){var g;(g=v.current)==null||g.focus()}else{const l=Tt()||(i==null?void 0:i.refs.domReference.current);l==null||l.focus()}}}),h&&u&&s.createElement("span",{"aria-owns":u.id,style:Fe}),u&&Ee.createPortal(e,u),h&&u&&s.createElement(he,{"data-type":"outside",ref:c,onFocus:d=>{if(te(d,u)){var g;(g=p.current)==null||g.focus()}else{const l=St()||(i==null?void 0:i.refs.domReference.current);l==null||l.focus(),i!=null&&i.closeOnFocusOut&&(i==null||i.onOpenChange(!1))}}}))},Lt=()=>s.useContext(ke),At=be["useInsertionEffect".toString()],Ft=At||(t=>t());function H(t){const e=s.useRef(()=>{});return Ft(()=>{e.current=t}),s.useCallback(function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return e.current==null?void 0:e.current(...r)},[])}function j(t,e){if(e==null)return!1;if("composedPath"in t)return t.composedPath().includes(e);const n=t;return n.target!=null&&e.contains(n.target)}const kt={pointerdown:"onPointerDown",mousedown:"onMouseDown",click:"onClick"},Dt={pointerdown:"onPointerDownCapture",mousedown:"onMouseDownCapture",click:"onClickCapture"},Nt=t=>{var e,n;return{escapeKeyBubbles:typeof t=="boolean"?t:(e=t==null?void 0:t.escapeKey)!=null?e:!1,outsidePressBubbles:typeof t=="boolean"?t:(n=t==null?void 0:t.outsidePress)!=null?n:!0}},qt=function(t,e){e===void 0&&(e={});const{open:n,onOpenChange:r,events:o,nodeId:u,elements:{reference:i,domReference:a,floating:f},dataRef:c}=t,{enabled:v=!0,escapeKey:p=!0,outsidePress:h=!0,outsidePressEvent:d="pointerdown",referencePress:g=!1,referencePressEvent:l="pointerdown",ancestorScroll:E=!1,bubbles:S}=e,m=ue(),w=Ie()!=null,M=H(typeof h=="function"?h:()=>!1),L=typeof h=="function"?M:h,P=s.useRef(!1),{escapeKeyBubbles:F,outsidePressBubbles:k}=Nt(S),O=H(x=>{if(!n||!v||!p||x.key!=="Escape")return;const I=m?ee(m.nodesRef.current,u):[];if(!F&&(x.stopPropagation(),I.length>0)){let y=!0;if(I.forEach(b=>{var R;if((R=b.context)!=null&&R.open&&!b.context.dataRef.current.__escapeKeyBubbles){y=!1;return}}),!y)return}o.emit("dismiss",{type:"escapeKey",data:{returnFocus:{preventScroll:!1}}}),r(!1)}),T=H(x=>{const I=P.current;if(P.current=!1,I||typeof L=="function"&&!L(x))return;const y=xt(x);if(Pe(y)&&f){const D=y.clientWidth>0&&y.scrollWidth>y.clientWidth,A=y.clientHeight>0&&y.scrollHeight>y.clientHeight;let C=A&&x.offsetX>y.clientWidth;if(A&&X(f).getComputedStyle(y).direction==="rtl"&&(C=x.offsetX<=y.offsetWidth-y.clientWidth),C||D&&x.offsetY>y.clientHeight)return}const b=m&&ee(m.nodesRef.current,u).some(D=>{var A;return j(x,(A=D.context)==null?void 0:A.elements.floating)});if(j(x,f)||j(x,a)||b)return;const R=m?ee(m.nodesRef.current,u):[];if(R.length>0){let D=!0;if(R.forEach(A=>{var C;if((C=A.context)!=null&&C.open&&!A.context.dataRef.current.__outsidePressBubbles){D=!1;return}}),!D)return}o.emit("dismiss",{type:"outsidePress",data:{returnFocus:w?{preventScroll:!0}:Rt(x)||wt(x)}}),r(!1)});return s.useEffect(()=>{if(!n||!v)return;c.current.__escapeKeyBubbles=F,c.current.__outsidePressBubbles=k;function x(){r(!1)}const I=B(f);p&&I.addEventListener("keydown",O),L&&I.addEventListener(d,T);let y=[];return E&&(N(a)&&(y=Y(a)),N(f)&&(y=y.concat(Y(f))),!N(i)&&i&&i.contextElement&&(y=y.concat(Y(i.contextElement)))),y=y.filter(b=>{var R;return b!==((R=I.defaultView)==null?void 0:R.visualViewport)}),y.forEach(b=>{b.addEventListener("scroll",x,{passive:!0})}),()=>{p&&I.removeEventListener("keydown",O),L&&I.removeEventListener(d,T),y.forEach(b=>{b.removeEventListener("scroll",x)})}},[c,f,a,i,p,L,d,n,r,E,v,F,k,O,T]),s.useEffect(()=>{P.current=!1},[L,d]),s.useMemo(()=>v?{reference:{onKeyDown:O,[kt[l]]:()=>{g&&(o.emit("dismiss",{type:"referencePress",data:{returnFocus:!1}}),r(!1))}},floating:{onKeyDown:O,[Dt[d]]:()=>{P.current=!0}}}:{},[v,o,g,d,l,r,O])},Gt=function(t,e){e===void 0&&(e={});const{open:n,onOpenChange:r,dataRef:o,events:u,refs:i,elements:{floating:a,domReference:f}}=t,{enabled:c=!0,keyboardOnly:v=!0}=e,p=s.useRef(""),h=s.useRef(!1),d=s.useRef();return s.useEffect(()=>{if(!c)return;const l=B(a).defaultView||window;function E(){!n&&Pe(f)&&f===Oe(B(f))&&(h.current=!0)}return l.addEventListener("blur",E),()=>{l.removeEventListener("blur",E)}},[a,f,n,c]),s.useEffect(()=>{if(!c)return;function g(l){(l.type==="referencePress"||l.type==="escapeKey")&&(h.current=!0)}return u.on("dismiss",g),()=>{u.off("dismiss",g)}},[u,c]),s.useEffect(()=>()=>{clearTimeout(d.current)},[]),s.useMemo(()=>c?{reference:{onPointerDown(g){let{pointerType:l}=g;p.current=l,h.current=!!(l&&v)},onMouseLeave(){h.current=!1},onFocus(g){var l;h.current||g.type==="focus"&&((l=o.current.openEvent)==null?void 0:l.type)==="mousedown"&&o.current.openEvent&&j(o.current.openEvent,f)||(o.current.openEvent=g.nativeEvent,r(!0))},onBlur(g){h.current=!1;const l=g.relatedTarget,E=N(l)&&l.hasAttribute("data-floating-ui-focus-guard")&&l.getAttribute("data-type")==="outside";d.current=setTimeout(()=>{G(i.floating.current,l)||G(f,l)||E||r(!1)})}}}:{},[c,v,f,i,o,r])},Xt=function(t,e){e===void 0&&(e={});const{open:n,floatingId:r}=t,{enabled:o=!0,role:u="dialog"}=e,i=se();return s.useMemo(()=>{const a={id:r,role:u};return o?u==="tooltip"?{reference:{"aria-describedby":n?r:void 0},floating:a}:{reference:{"aria-expanded":n?"true":"false","aria-haspopup":u==="alertdialog"?"dialog":u,"aria-controls":n?r:void 0,...u==="listbox"&&{role:"combobox"},...u==="menu"&&{id:i}},floating:{...a,...u==="menu"&&{"aria-labelledby":i}}}:{}},[o,u,n,r,i])};function Yt(t){t===void 0&&(t={});const{open:e=!1,onOpenChange:n,nodeId:r}=t,o=qe(t),u=ue(),i=s.useRef(null),a=s.useRef({}),f=s.useState(()=>vt())[0],c=se(),[v,p]=s.useState(null),h=s.useCallback(m=>{const w=N(m)?{getBoundingClientRect:()=>m.getBoundingClientRect(),contextElement:m}:m;o.refs.setReference(w)},[o.refs]),d=s.useCallback(m=>{(N(m)||m===null)&&(i.current=m,p(m)),(N(o.refs.reference.current)||o.refs.reference.current===null||m!==null&&!N(m))&&o.refs.setReference(m)},[o.refs]),g=s.useMemo(()=>({...o.refs,setReference:d,setPositionReference:h,domReference:i}),[o.refs,d,h]),l=s.useMemo(()=>({...o.elements,domReference:v}),[o.elements,v]),E=H(n),S=s.useMemo(()=>({...o,refs:g,elements:l,dataRef:a,nodeId:r,floatingId:c,events:f,open:e,onOpenChange:E}),[o,r,c,f,e,E,g,l]);return K(()=>{const m=u==null?void 0:u.nodesRef.current.find(w=>w.id===r);m&&(m.context=S)}),s.useMemo(()=>({...o,context:S,refs:g,elements:l,reference:d,positionReference:h}),[o,g,l,S,d,h])}function ne(t,e,n){const r=new Map;return{...n==="floating"&&{tabIndex:-1},...t,...e.map(o=>o?o[n]:null).concat(t).reduce((o,u)=>(u&&Object.entries(u).forEach(i=>{let[a,f]=i;if(a.indexOf("on")===0){if(r.has(a)||r.set(a,[]),typeof f=="function"){var c;(c=r.get(a))==null||c.push(f),o[a]=function(){for(var v,p=arguments.length,h=new Array(p),d=0;d<p;d++)h[d]=arguments[d];return(v=r.get(a))==null?void 0:v.map(g=>g(...h)).find(g=>g!==void 0)}}}else o[a]=f}),o),{})}}const Zt=function(t){t===void 0&&(t=[]);const e=t,n=s.useCallback(u=>ne(u,t,"reference"),e),r=s.useCallback(u=>ne(u,t,"floating"),e),o=s.useCallback(u=>ne(u,t,"item"),t.map(u=>u==null?void 0:u.item));return s.useMemo(()=>({getReferenceProps:n,getFloatingProps:r,getItemProps:o}),[n,r,o])};export{Ht as A,_t as F,Zt as a,Ut as b,Gt as c,Xt as d,qt as e,jt as f,Yt as u};