@data-slot/navigation-menu 0.2.68 → 0.2.70

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/README.md CHANGED
@@ -172,6 +172,9 @@ Their `data-side` / `data-align` are mirrored output values and are not used as
172
172
  reused. Otherwise, a `navigation-menu-viewport-positioner` wrapper is generated and positioned
173
173
  at the navigation root so submenu layers are not clipped by local stacking contexts.
174
174
 
175
+ Runtime positioner placement styles are reset on close, so restored authored positioners do not
176
+ leave stale geometry that can affect document overflow.
177
+
175
178
  The active `navigation-menu-content` panel is mounted inside `navigation-menu-viewport` while open
176
179
  and restored to its original markup location when inactive/closed.
177
180
 
@@ -224,12 +227,18 @@ and restored to its original markup location when inactive/closed.
224
227
  }
225
228
  ```
226
229
 
230
+ `data-instant` is automatically removed shortly after initial open. Use it only to skip first-frame
231
+ transitions.
232
+
227
233
  ### Motion Animations
228
234
 
229
235
  Content panels receive `data-motion` attributes for directional enter/exit animations.
230
236
  Both content and viewport also receive `data-starting-style` / `data-ending-style` markers from
231
237
  presence lifecycle hooks, so you can style smooth fade/scale transitions before unmount.
232
238
 
239
+ For exit animations, avoid CSS that force-hides content immediately by `data-state`
240
+ (for example `display: none` on non-active panels), because that bypasses the presence lifecycle.
241
+
233
242
  ```css
234
243
  /* Entering from right */
235
244
  [data-slot="navigation-menu-content"][data-motion="from-right"] {
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=[`start`,`center`,`end`],n=[`top`,`right`,`bottom`,`left`],r=(e,t)=>t===`start`?{x:e.left,y:e.top}:t===`end`?{x:e.right,y:e.bottom}:{x:e.left+e.width/2,y:e.top+e.height/2},i=(e,t,n)=>{let i=r(n,t);return e===`top`?{x:i.x,y:n.top}:e===`bottom`?{x:i.x,y:n.bottom}:e===`left`?{x:n.left,y:i.y}:{x:n.right,y:i.y}};function a(r,a={}){let o=a.delayOpen??(0,e.getDataNumber)(r,`delayOpen`)??200,s=a.delayClose??(0,e.getDataNumber)(r,`delayClose`)??150,c=a.openOnFocus??(0,e.getDataBool)(r,`openOnFocus`)??!0,l=a.side??(0,e.getDataEnum)(r,`side`,n)??`bottom`,u=a.align??(0,e.getDataEnum)(r,`align`,t)??`start`,d=a.sideOffset??(0,e.getDataNumber)(r,`sideOffset`)??0,f=a.alignOffset??(0,e.getDataNumber)(r,`alignOffset`)??0,p=a.safeTriangle??(0,e.getDataBool)(r,`safeTriangle`)??!1,m=a.debugSafeTriangle??(0,e.getDataBool)(r,`debugSafeTriangle`)??!1,ee=p||m,h=a.onValueChange,g=e=>e.replace(/[^a-z0-9\-_:.]/gi,`-`),_=(e,t)=>{`inert`in e&&(e.inert=t)},v=(0,e.getPart)(r,`navigation-menu-list`),te=(0,e.getParts)(r,`navigation-menu-item`),y=(0,e.getPart)(r,`navigation-menu-viewport`),b=(0,e.getPart)(r,`navigation-menu-indicator`),x=(e,t)=>{let n=e.parentElement;for(;n&&n!==r;){if(n.getAttribute(`data-slot`)===t)return n;n=n.parentElement}return null};if(!v||te.length===0)throw Error(`NavigationMenu requires navigation-menu-list and at least one navigation-menu-item`);let S=null,C=null,w=-1,T=null,E=null,D=null,O=!1,k=!1,A=!1,j=!1,M=null,N=null,ne=0,re=0,P=[],F=new Map,I=new Map,L=y?x(y,`navigation-menu-viewport-positioner`):null,R=y?x(y,`navigation-menu-positioner`):null,z=L??R,ie=z?x(z,`navigation-menu-portal`):null,B=y?(0,e.createPortalLifecycle)({content:y,root:r,enabled:!0,wrapperSlot:z?void 0:`navigation-menu-viewport-positioner`,container:z??void 0,mountTarget:z?ie??z:void 0}):null,V=y?(0,e.createPresenceLifecycle)({element:y,onExitComplete:()=>{j||(B?.restore(),y.hidden=!0,y.style.pointerEvents=`none`)}}):null,H=e=>{if(!y)return;let t=I.get(e)??{originalParent:null,originalNextSibling:null,mountedInViewport:!1};t.mountedInViewport||(t.originalParent=e.parentNode,t.originalNextSibling=e.nextSibling,t.mountedInViewport=!0,I.set(e,t)),e.parentNode!==y&&y.appendChild(e)},U=e=>{let t=I.get(e);if(!t||!t.mountedInViewport)return;let n=t.originalParent,r=t.originalNextSibling;n&&n.isConnected?r&&r.parentNode===n?n.insertBefore(e,r):n.appendChild(e):e.remove(),t.mountedInViewport=!1,t.originalParent=null,t.originalNextSibling=null},ae=()=>{if(!y||!B)return;let e=B.container,t=r.ownerDocument.defaultView??window,n=r.getBoundingClientRect(),i=n.top+t.scrollY+re,a=n.left+t.scrollX+ne;e.style.position=`absolute`,e.style.top=`${i}px`,e.style.left=`${a}px`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`top,left`,e.style.pointerEvents=`none`},W=null,oe=e=>{W?.disconnect(),W=null,!(!y||!e)&&(W=new ResizeObserver(()=>{let t=se(e.item,e.content);Oe(e.content,e.trigger,t)}),W.observe(e.content))};P.push(()=>W?.disconnect()),P.push(()=>{F.forEach(e=>e.cleanup()),F.clear(),I.forEach((e,t)=>{U(t),t.hidden=!0,t.style.pointerEvents=`none`}),I.clear(),V?.cleanup(),B?.cleanup()});let G=new Map,se=(r,i)=>({side:a.side??(0,e.getDataEnum)(i,`side`,n)??(0,e.getDataEnum)(r,`side`,n)??l,align:a.align??(0,e.getDataEnum)(i,`align`,t)??(0,e.getDataEnum)(r,`align`,t)??u,sideOffset:a.sideOffset??(0,e.getDataNumber)(i,`sideOffset`)??(0,e.getDataNumber)(r,`sideOffset`)??d,alignOffset:a.alignOffset??(0,e.getDataNumber)(i,`alignOffset`)??(0,e.getDataNumber)(r,`alignOffset`)??f}),ce=0;te.forEach(t=>{let n=t.dataset.value;if(!n)return;let r=(0,e.getPart)(t,`navigation-menu-trigger`),i=(0,e.getPart)(t,`navigation-menu-content`);if(r&&i){G.set(n,{item:t,trigger:r,content:i,index:ce++}),F.set(i,(0,e.createPresenceLifecycle)({element:i,onExitComplete:()=>{j||(U(i),i.hidden=!0,i.style.pointerEvents=`none`)}}));let a=g(n),o=(0,e.ensureId)(r,`nav-menu-trigger-${a}`),s=(0,e.ensureId)(i,`nav-menu-content-${a}`);r.setAttribute(`aria-haspopup`,`true`),r.setAttribute(`aria-controls`,s),i.setAttribute(`aria-labelledby`,o)}});let K=Array.from(G.values()).map(e=>e.trigger),le=new Map;for(let[e,t]of G)le.set(t.trigger,e);let ue=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),q=()=>{T&&=(clearTimeout(T),null),E&&=(clearTimeout(E),null)},de=()=>{N!==null&&(cancelAnimationFrame(N),N=null)},J=null,fe=()=>{if(!y)return null;let e=B?.container;return e instanceof HTMLElement?e:y.parentElement instanceof HTMLElement?y.parentElement:y},pe=()=>{let t=fe();return J||(J=document.createElement(`div`),J.setAttribute(`data-slot`,`navigation-menu-bridge`),J.style.cssText=`position: absolute; pointer-events: auto; z-index: 0; display: none;`,P.push((0,e.on)(J,`pointerenter`,()=>{q()}),(0,e.on)(J,`pointerleave`,t=>{if(O||S===null)return;let n=t.relatedTarget;Z(n)||n&&(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))),t&&J.parentElement!==t&&t.insertBefore(J,t.firstChild),J},Y=()=>{J&&(J.style.height=`0`,J.style.width=`0`,J.style.top=`0px`,J.style.left=`0px`,J.style.right=`0px`,J.style.bottom=`auto`,J.style.transform=`none`,J.style.clipPath=`none`,J.style.display=`none`)},me=()=>{if(!m)return null;let e=r.ownerDocument.body;return e?(M||(M=r.ownerDocument.createElement(`div`),M.setAttribute(`data-slot`,`navigation-menu-safe-triangle`),M.style.cssText=[`position: fixed`,`pointer-events: none`,`display: none`,`z-index: 2147483647`,`background: rgba(255, 0, 0, 0.18)`,`border: 1px solid rgba(255, 0, 0, 0.45)`].join(`; `)),M.parentElement!==e&&e.appendChild(M),M):null},he=()=>{M&&(M.style.width=`0`,M.style.height=`0`,M.style.clipPath=`none`,M.style.display=`none`)},X=()=>{m||he()},ge=e=>{let t=me();if(!t)return;let n=e.apex.x,r=e.apex.y,i=e.edgeA.x,a=e.edgeA.y,o=e.edgeB.x,s=e.edgeB.y,c=Math.min(n,i,o),l=Math.min(r,a,s),u=Math.max(n,i,o),d=Math.max(r,a,s),f=Math.max(1,u-c),p=Math.max(1,d-l),m=(e,t)=>`${(e-c)/f*100}% ${(t-l)/p*100}%`;t.style.display=`block`,t.style.left=`${c}px`,t.style.top=`${l}px`,t.style.width=`${f}px`,t.style.height=`${p}px`,t.style.clipPath=`polygon(${m(n,r)}, ${m(i,a)}, ${m(o,s)})`},_e=(e,t,n)=>(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y),ve=(e,t,n,r)=>{let i=_e(e,t,n),a=_e(e,n,r),o=_e(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},ye=(e,t,n)=>{let r=.5;if(n.top>=t.bottom-r)return[{x:n.left,y:n.top},{x:n.right,y:n.top}];if(n.bottom<=t.top+r)return[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}];if(n.left>=t.right-r)return[{x:n.left,y:n.top},{x:n.left,y:n.bottom}];if(n.right<=t.left+r)return[{x:n.right,y:n.top},{x:n.right,y:n.bottom}];let i=[[{x:n.left,y:n.top},{x:n.right,y:n.top}],[{x:n.right,y:n.top},{x:n.right,y:n.bottom}],[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}],[{x:n.left,y:n.top},{x:n.left,y:n.bottom}]],a=([t,n])=>t.y===n.y?Math.abs(e.y-t.y):Math.abs(e.x-t.x),o=i[0],s=a(o);for(let e=1;e<i.length;e++){let t=i[e],n=a(t);n<s&&(o=t,s=n)}return o},be=()=>S?G.get(S)??null:null,xe=(e,t,n)=>{if(n.width<=0||n.height<=0)return null;let r={x:e.left+e.width/2,y:e.top+e.height*.62},[i,a]=ye(r,t,n);if(i.x===a.x){let e=Math.min(i.y,a.y),t=Math.max(i.y,a.y),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:i.x,y:e+r},a={x:a.x,y:t-r}}else{let e=Math.min(i.x,a.x),t=Math.max(i.x,a.x),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:e+r,y:i.y},a={x:t-r,y:a.y}}return{apex:r,edgeA:i,edgeB:a}},Se=()=>{if(!ee||!y||S===null)return null;let e=be();if(!e)return null;let t=r.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),i=y.getBoundingClientRect(),a=e.content.getBoundingClientRect();return xe(n,t,i.width>0&&i.height>0?i:a)},Ce=e=>{let t=Se();return t?ve({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},we=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),Te=e=>{if(e.length<=1)return e.slice();let t=e=>`${e.x.toFixed(3)}:${e.y.toFixed(3)}`,n=new Map;for(let r of e)n.set(t(r),r);let r=Array.from(n.values()).sort((e,t)=>e.x===t.x?e.y-t.y:e.x-t.x);if(r.length<=2)return r;let i=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),a=[];for(let e of r){for(;a.length>=2&&i(a[a.length-2],a[a.length-1],e)<=0;)a.pop();a.push(e)}let o=[];for(let e=r.length-1;e>=0;e--){let t=r[e];for(;o.length>=2&&i(o[o.length-2],o[o.length-1],t)<=0;)o.pop();o.push(t)}return a.pop(),o.pop(),a.concat(o)},Ee=e=>{if(e.length<3){Y();return}let t=Te(e);if(t.length<3){Y();return}let n=Math.min(...t.map(e=>e.x)),r=Math.min(...t.map(e=>e.y)),i=Math.max(...t.map(e=>e.x)),a=Math.max(...t.map(e=>e.y)),o=Math.max(1,i-n),s=Math.max(1,a-r),c=e=>`${(e.x-n)/o*100}% ${(e.y-r)/s*100}%`,l=pe();l.style.display=`block`,l.style.transform=`none`,l.style.bottom=`auto`,l.style.right=`auto`,l.style.left=`${n}px`,l.style.top=`${r}px`,l.style.width=`${o}px`,l.style.height=`${s}px`,l.style.clipPath=`polygon(${t.map(c).join(`, `)})`},De=()=>{if(!m)return;let e=Se();if(!e){he();return}ge(e)},Z=e=>{if(!e)return!1;if(be()?.content.contains(e)||y?.contains(e)||J?.contains(e))return!0;let t=B?.container;return!!(t instanceof HTMLElement&&t.contains(e))};P.push(X),P.push(de),P.push(Y),P.push(()=>{he(),M?.parentElement&&M.parentElement.removeChild(M),M=null});let Oe=(t,a,o)=>{y&&requestAnimationFrame(()=>{let s=t.firstElementChild,c=t.lastElementChild,l=s?getComputedStyle(s):null,u=c?getComputedStyle(c):null,d=l&&parseFloat(l.marginTop)||0,f=u&&parseFloat(u.marginBottom)||0,p=(...e)=>{let t=0;for(let n of e)Number.isFinite(n)&&(t=Math.max(t,n));return t},m=t.getBoundingClientRect(),h=p(m.width,t.scrollWidth,t.offsetWidth,t.clientWidth),g=p(m.height,t.scrollHeight,t.offsetHeight,t.clientHeight)+d+f,_={top:m.top,left:m.left,width:h,height:g,right:m.left+h,bottom:m.top+g},v=getComputedStyle(y),te=parseFloat(v.marginTop)||0;y.style.setProperty(`--viewport-width`,`${h}px`),y.style.setProperty(`--viewport-height`,`${g}px`);let b=r.getBoundingClientRect(),x=a.getBoundingClientRect(),S=(0,e.computeFloatingPosition)({anchorRect:x,contentRect:_,side:o.side,align:o.align,sideOffset:o.sideOffset,alignOffset:o.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:n}),C=S.x-b.left,w=S.y-b.top;ne=C,re=w;let T=i(S.side,S.align,x),E=T.x-(b.left+C),D=T.y-(b.top+w),O=T.x-b.left,k=T.y-b.top,A=`${E}px ${D}px`,j=`${O}px ${k}px`;y.style.top=`0px`,y.style.left=`0px`,y.style.willChange=`transform,width,height`,y.style.setProperty(`--transform-origin`,A),t.style.top=`0px`,t.style.left=`0px`,t.style.setProperty(`--transform-origin`,A),y.setAttribute(`data-side`,S.side),y.setAttribute(`data-align`,S.align),t.setAttribute(`data-side`,S.side),t.setAttribute(`data-align`,S.align);let M=B?.container;M&&M!==y&&(M.setAttribute(`data-side`,S.side),M.setAttribute(`data-align`,S.align),M.style.setProperty(`--transform-origin`,j)),ae();let N=y.getBoundingClientRect(),P=[],F=Math.max(0,N.top-b.bottom),I=Math.max(0,b.top-N.bottom),L=Math.max(0,N.left-b.right),R=Math.max(0,b.left-N.right),z=Math.max(0,d+te),ie=Math.max(F,I,z),V=Math.max(L,R),H=ee?xe(x,b,N):null,U=(e,t,n,r)=>{n<=0||r<=0||P.push({x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r})};if(ie>=V&&ie>0){let e=Math.max(F,I,z),t=C,n=I>F&&I>=z?w+g:w-e,r=h;if(H){let e=Math.min(H.edgeA.x,H.edgeB.x)-b.left,n=Math.max(H.edgeA.x,H.edgeB.x)-b.left;t=e-8,r=n-e+16}U(t,n,r,e)}else if(V>0){let e=Math.max(L,R),t=w,n=R>L?C+h:C-e,r=g;if(H){let e=Math.min(H.edgeA.y,H.edgeB.y)-b.top,n=Math.max(H.edgeA.y,H.edgeB.y)-b.top;t=e-8,r=n-e+16}U(n,t,e,r)}if(H){let e=we(H.apex,b),t=we(H.edgeA,b),n=we(H.edgeB,b);P.push(e,t,n)}Ee(P),De()})},ke=e=>w===-1||e>w?`right`:`left`,Q=e=>{if(!b)return;if(D=e,!e){de(),b.removeAttribute(`data-instant`),b.setAttribute(`data-state`,`hidden`);return}b.getAttribute(`data-state`)!==`visible`&&(de(),b.setAttribute(`data-instant`,``),N=requestAnimationFrame(()=>{N=requestAnimationFrame(()=>{b.removeAttribute(`data-instant`),N=null})}));let t=v.getBoundingClientRect(),n=e.getBoundingClientRect();b.style.setProperty(`--indicator-left`,`${n.left-t.left}px`),b.style.setProperty(`--indicator-width`,`${n.width}px`),b.style.setProperty(`--indicator-top`,`${n.top-t.top}px`);let r=(y&&parseFloat(getComputedStyle(y).marginTop)||0)<1?1:0;b.style.setProperty(`--indicator-height`,`${n.height-r}px`),b.setAttribute(`data-state`,`visible`)},$=(t,n=!1)=>{if(X(),t===S){q();return}if(t!==null&&t===C){q();return}q(),C=t===null?null:t;let i=()=>{let n=S,i=t?G.get(t):null,a=n!==null&&t!==null&&n!==t,o=a&&i?ke(i.index):null,s=document.activeElement;if(t===null&&s&&(0,e.containsWithPortals)(r,s)){let e=n?G.get(n)?.trigger:null;e&&e.focus()}if(G.forEach(({trigger:r,content:i,item:a},s)=>{let c=s===t,l=s===n;if((0,e.setAria)(r,`expanded`,c),r.setAttribute(`data-state`,c?`open`:`closed`),c||l&&t===null?r.tabIndex=0:r.tabIndex=-1,a.setAttribute(`data-state`,c?`open`:`closed`),!c){let e=F.get(i);if(i.setAttribute(`data-state`,`inactive`),i.setAttribute(`aria-hidden`,`true`),_(i,!0),i.style.pointerEvents=`none`,l&&o){let e=o===`right`?`to-left`:`to-right`;i.setAttribute(`data-motion`,e)}else l&&i.removeAttribute(`data-motion`);l?e?.exit():e?.isExiting||(i.removeAttribute(`data-motion`),U(i),i.hidden=!0)}}),i){if(B?.mount(),y&&(y.hidden=!1),n===null&&V?.enter(),H(i.content),F.get(i.content)?.enter(),o){let e=o===`right`?`from-right`:`from-left`;i.content.setAttribute(`data-motion`,e)}else i.content.removeAttribute(`data-motion`);i.content.setAttribute(`data-state`,`active`),i.content.removeAttribute(`aria-hidden`),_(i.content,!1),i.content.hidden=!1,i.content.style.pointerEvents=`auto`,w=i.index;let e=se(i.item,i.content);Oe(i.content,i.trigger,e),oe(i),Q(i.trigger)}else Y(),X(),V?.exit(),oe(null);let c=t!==null;if(r.setAttribute(`data-state`,c?`open`:`closed`),o?r.setAttribute(`data-motion`,o===`right`?`from-right`:`from-left`):r.removeAttribute(`data-motion`),y){y.setAttribute(`data-state`,c?`open`:`closed`),y.style.pointerEvents=c?`auto`:`none`;let e=B?.container;c&&!a?(y.setAttribute(`data-instant`,``),e?.setAttribute(`data-instant`,``)):a&&(y.removeAttribute(`data-instant`),e?.removeAttribute(`data-instant`)),o&&y.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)}S=t,C=null,t===null&&Q(null),De(),(0,e.emit)(r,`navigation-menu:change`,{value:t}),h?.(t)};n?i():t!==null&&S===null?T=setTimeout(i,o):t!==null&&S!==null?i():E=setTimeout(i,s)};r.setAttribute(`data-state`,`closed`),y&&(y.setAttribute(`data-state`,`closed`),y.hidden=!0,y.style.pointerEvents=`none`),b&&b.setAttribute(`data-state`,`hidden`),G.forEach(({trigger:t,content:n,item:r})=>{t.tagName===`BUTTON`&&!t.hasAttribute(`type`)&&(t.type=`button`),(0,e.setAria)(t,`expanded`,!1),t.setAttribute(`data-state`,`closed`),t.tabIndex=t===K[0]?0:-1,r.setAttribute(`data-state`,`closed`),n.setAttribute(`data-state`,`inactive`),n.setAttribute(`aria-hidden`,`true`),n.tabIndex=-1,_(n,!0),n.hidden=!0,n.style.pointerEvents=`none`}),G.forEach(({item:t,trigger:n},i)=>{P.push((0,e.on)(n,`pointerenter`,e=>{if(!O){if(S!==i&&Ce(e))return;Q(n)}})),P.push((0,e.on)(t,`pointerenter`,e=>{if(!O){if(S!==i&&Ce(e))return;$(i)}})),P.push((0,e.on)(t,`pointerleave`,t=>{if(C===i&&S===null&&(q(),C=null),S===i&&!O){let n=t.relatedTarget;if(Z(n))return;(!n||!(0,e.containsWithPortals)(r,n))&&($(null),Q(null))}})),P.push((0,e.on)(n,`focus`,()=>{k||(c&&$(i,!0),Q(n))})),P.push((0,e.on)(n,`pointerdown`,()=>{k=!0})),P.push((0,e.on)(n,`click`,()=>{q(),S===i&&O?(O=!1,$(null,!0),Q(null)):S===i&&!O?(O=!0,Q(n)):(O=!0,$(i,!0),Q(n)),k=!1}))}),P.push((0,e.on)(r,`pointerenter`,()=>{A=!0}),(0,e.on)(r,`pointerleave`,e=>{let t=e.relatedTarget;if(!Z(t)&&(A=!1,!O)){if(Ce(e)){q();return}$(null),Q(null)}}),(0,e.on)(r,`pointerdown`,()=>{X(),q()})),y&&P.push((0,e.on)(y,`pointerenter`,()=>{X(),q()}),(0,e.on)(y,`transitionend`,e=>{if(e.target!==y)return;let t=S?G.get(S):null;if(t){let e=se(t.item,t.content);Oe(t.content,t.trigger,e)}})),G.forEach(({content:t})=>{P.push((0,e.on)(t,`pointerenter`,()=>{X(),q()}),(0,e.on)(t,`pointerleave`,t=>{if(O)return;let n=t.relatedTarget;Z(n)||(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))}),P.push((0,e.on)(v,`keydown`,e=>{let t=e.target,n=K.indexOf(t);if(n===-1)return;let r=le.get(t)??null,i=n;switch(e.key){case`ArrowLeft`:i=n-1,i<0&&(i=K.length-1);break;case`ArrowRight`:i=n+1,i>=K.length&&(i=0);break;case`ArrowDown`:e.preventDefault(),r&&(O=!0,$(r,!0),requestAnimationFrame(()=>{let e=G.get(r);if(!e)return;let t=ue(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=K.length-1;break;case`Escape`:O=!1,$(null,!0),Q(null);return;default:return}e.preventDefault();let a=K[i];a&&(K.forEach(e=>e.tabIndex=e===a?0:-1),a.focus(),Q(a))})),G.forEach(({content:t,trigger:n})=>{P.push((0,e.on)(t,`keydown`,e=>{let r=e.target,i=ue(t),a=i.indexOf(r);if(a!==-1)switch(e.key){case`ArrowDown`:case`ArrowRight`:{e.preventDefault();let t=a+1;t<i.length&&i[t]?.focus();break}case`ArrowUp`:case`ArrowLeft`:e.preventDefault(),a===0?n.focus():i[a-1]?.focus();break;case`Escape`:e.preventDefault(),O=!1,$(null,!0),Q(null),n.focus();break}}))});let Ae=()=>(0,e.containsWithPortals)(r,document.activeElement)||A||O,je=()=>{X(),O=!1,$(null,!0),Q(null),De()};return P.push((0,e.on)(document,`pointerup`,()=>{k=!1},{capture:!0}),(0,e.on)(document,`pointercancel`,()=>{k=!1},{capture:!0})),P.push((0,e.on)(document,`focusin`,t=>{S!==null&&((0,e.containsWithPortals)(r,t.target)||je())})),P.push((0,e.createDismissLayer)({root:r,isOpen:()=>S!==null&&Ae(),onDismiss:je,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:t=>!!t&&(0,e.containsWithPortals)(r,t)})),P.push((0,e.on)(window,`resize`,()=>{S&&requestAnimationFrame(()=>ae()),D&&requestAnimationFrame(()=>Q(D))}),(0,e.on)(v,`scroll`,()=>{D&&requestAnimationFrame(()=>Q(D))})),P.push((0,e.on)(r,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)je();else if(G.has(t.value)){O=!0,$(t.value,!0);let e=G.get(t.value);e&&Q(e.trigger)}}})),{get value(){return S},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{j=!0,q(),P.forEach(e=>e()),P.length=0}}}const o=new WeakSet;function s(t=document){let n=[];for(let r of(0,e.getRoots)(t,`navigation-menu`))o.has(r)||(o.add(r),n.push(a(r)));return n}exports.create=s,exports.createNavigationMenu=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=[`start`,`center`,`end`],n=[`top`,`right`,`bottom`,`left`],r=(e,t)=>t===`start`?{x:e.left,y:e.top}:t===`end`?{x:e.right,y:e.bottom}:{x:e.left+e.width/2,y:e.top+e.height/2},i=(e,t,n)=>{let i=r(n,t);return e===`top`?{x:i.x,y:n.top}:e===`bottom`?{x:i.x,y:n.bottom}:e===`left`?{x:n.left,y:i.y}:{x:n.right,y:i.y}};function a(r,a={}){let o=a.delayOpen??(0,e.getDataNumber)(r,`delayOpen`)??200,s=a.delayClose??(0,e.getDataNumber)(r,`delayClose`)??150,c=a.openOnFocus??(0,e.getDataBool)(r,`openOnFocus`)??!0,l=a.side??(0,e.getDataEnum)(r,`side`,n)??`bottom`,u=a.align??(0,e.getDataEnum)(r,`align`,t)??`start`,ee=a.sideOffset??(0,e.getDataNumber)(r,`sideOffset`)??0,te=a.alignOffset??(0,e.getDataNumber)(r,`alignOffset`)??0,d=a.safeTriangle??(0,e.getDataBool)(r,`safeTriangle`)??!1,f=a.debugSafeTriangle??(0,e.getDataBool)(r,`debugSafeTriangle`)??!1,ne=d||f,p=a.onValueChange,m=e=>e.replace(/[^a-z0-9\-_:.]/gi,`-`),h=(e,t)=>{`inert`in e&&(e.inert=t)},g=(0,e.getPart)(r,`navigation-menu-list`),re=(0,e.getParts)(r,`navigation-menu-item`),_=(0,e.getPart)(r,`navigation-menu-viewport`),v=(0,e.getPart)(r,`navigation-menu-indicator`),y=(e,t)=>{let n=e.parentElement;for(;n&&n!==r;){if(n.getAttribute(`data-slot`)===t)return n;n=n.parentElement}return null};if(!g||re.length===0)throw Error(`NavigationMenu requires navigation-menu-list and at least one navigation-menu-item`);let b=null,x=null,S=-1,C=null,w=null,T=null,E=!1,D=!1,O=!1,k=!1,A=null,j=null,M=null,N=0,P=0,F=[],I=new Map,L=new Map,R=_?y(_,`navigation-menu-viewport-positioner`):null,z=_?y(_,`navigation-menu-positioner`):null,B=R??z,ie=B?y(B,`navigation-menu-portal`):null,V=_?(0,e.createPortalLifecycle)({content:_,root:r,enabled:!0,wrapperSlot:B?void 0:`navigation-menu-viewport-positioner`,container:B??void 0,mountTarget:B?ie??B:void 0}):null,H=()=>{let e=V?.container;e instanceof HTMLElement&&(e.style.position=``,e.style.top=``,e.style.left=``,e.style.width=``,e.style.height=``,e.style.margin=``,e.style.willChange=``,e.style.pointerEvents=``,e.style.transform=``,e.style.removeProperty(`--transform-origin`),e.removeAttribute(`data-instant`))},U=()=>{M!==null&&(cancelAnimationFrame(M),M=null)},W=()=>{_?.removeAttribute(`data-instant`);let e=V?.container;e instanceof HTMLElement&&e.removeAttribute(`data-instant`)},ae=()=>{_&&(U(),M=requestAnimationFrame(()=>{M=requestAnimationFrame(()=>{W(),M=null})}))},oe=_?(0,e.createPresenceLifecycle)({element:_,onExitComplete:()=>{k||(U(),W(),H(),N=0,P=0,V?.restore(),_.hidden=!0,_.style.pointerEvents=`none`)}}):null,se=e=>{if(!_)return;let t=L.get(e)??{originalParent:null,originalNextSibling:null,mountedInViewport:!1};t.mountedInViewport||(t.originalParent=e.parentNode,t.originalNextSibling=e.nextSibling,t.mountedInViewport=!0,L.set(e,t)),e.parentNode!==_&&_.appendChild(e)},ce=e=>{let t=L.get(e);if(!t||!t.mountedInViewport)return;let n=t.originalParent,r=t.originalNextSibling;n&&n.isConnected?r&&r.parentNode===n?n.insertBefore(e,r):n.appendChild(e):e.remove(),t.mountedInViewport=!1,t.originalParent=null,t.originalNextSibling=null},le=()=>{if(!_||!V)return;let e=V.container,t=r.ownerDocument.defaultView??window,n=r.getBoundingClientRect(),i=n.top+t.scrollY+P,a=n.left+t.scrollX+N;e.style.position=`absolute`,e.style.top=`${i}px`,e.style.left=`${a}px`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`top,left`,e.style.pointerEvents=`none`},G=null,ue=e=>{G?.disconnect(),G=null,!(!_||!e)&&(G=new ResizeObserver(()=>{let t=de(e.item,e.content);Ne(e.content,e.trigger,t)}),G.observe(e.content))};F.push(()=>G?.disconnect()),F.push(()=>{U(),W(),I.forEach(e=>e.cleanup()),I.clear(),L.forEach((e,t)=>{ce(t),t.hidden=!0,t.style.pointerEvents=`none`}),L.clear(),H(),N=0,P=0,oe?.cleanup(),V?.cleanup()});let K=new Map,de=(r,i)=>({side:a.side??(0,e.getDataEnum)(i,`side`,n)??(0,e.getDataEnum)(r,`side`,n)??l,align:a.align??(0,e.getDataEnum)(i,`align`,t)??(0,e.getDataEnum)(r,`align`,t)??u,sideOffset:a.sideOffset??(0,e.getDataNumber)(i,`sideOffset`)??(0,e.getDataNumber)(r,`sideOffset`)??ee,alignOffset:a.alignOffset??(0,e.getDataNumber)(i,`alignOffset`)??(0,e.getDataNumber)(r,`alignOffset`)??te}),fe=0;re.forEach(t=>{let n=t.dataset.value;if(!n)return;let r=(0,e.getPart)(t,`navigation-menu-trigger`),i=(0,e.getPart)(t,`navigation-menu-content`);if(r&&i){K.set(n,{item:t,trigger:r,content:i,index:fe++}),I.set(i,(0,e.createPresenceLifecycle)({element:i,onExitComplete:()=>{k||(ce(i),i.hidden=!0,i.style.pointerEvents=`none`)}}));let a=m(n),o=(0,e.ensureId)(r,`nav-menu-trigger-${a}`),s=(0,e.ensureId)(i,`nav-menu-content-${a}`);r.setAttribute(`aria-haspopup`,`true`),r.setAttribute(`aria-controls`,s),i.setAttribute(`aria-labelledby`,o)}});let q=Array.from(K.values()).map(e=>e.trigger),pe=new Map;for(let[e,t]of K)pe.set(t.trigger,e);let me=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),J=()=>{C&&=(clearTimeout(C),null),w&&=(clearTimeout(w),null)},he=()=>{j!==null&&(cancelAnimationFrame(j),j=null)},Y=null,ge=()=>{if(!_)return null;let e=V?.container;return e instanceof HTMLElement?e:_.parentElement instanceof HTMLElement?_.parentElement:_},_e=()=>{let t=ge();return Y||(Y=document.createElement(`div`),Y.setAttribute(`data-slot`,`navigation-menu-bridge`),Y.style.cssText=`position: absolute; pointer-events: auto; z-index: 0; display: none;`,F.push((0,e.on)(Y,`pointerenter`,()=>{J()}),(0,e.on)(Y,`pointerleave`,t=>{if(E||b===null)return;let n=t.relatedTarget;Me(n)||n&&(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))),t&&Y.parentElement!==t&&t.insertBefore(Y,t.firstChild),Y},X=()=>{Y&&(Y.style.height=`0`,Y.style.width=`0`,Y.style.top=`0px`,Y.style.left=`0px`,Y.style.right=`0px`,Y.style.bottom=`auto`,Y.style.transform=`none`,Y.style.clipPath=`none`,Y.style.display=`none`)},ve=()=>{if(!f)return null;let e=r.ownerDocument.body;return e?(A||(A=r.ownerDocument.createElement(`div`),A.setAttribute(`data-slot`,`navigation-menu-safe-triangle`),A.style.cssText=[`position: fixed`,`pointer-events: none`,`display: none`,`z-index: 2147483647`,`background: rgba(255, 0, 0, 0.18)`,`border: 1px solid rgba(255, 0, 0, 0.45)`].join(`; `)),A.parentElement!==e&&e.appendChild(A),A):null},ye=()=>{A&&(A.style.width=`0`,A.style.height=`0`,A.style.clipPath=`none`,A.style.display=`none`)},Z=()=>{f||ye()},be=e=>{let t=ve();if(!t)return;let n=e.apex.x,r=e.apex.y,i=e.edgeA.x,a=e.edgeA.y,o=e.edgeB.x,s=e.edgeB.y,c=Math.min(n,i,o),l=Math.min(r,a,s),u=Math.max(n,i,o),ee=Math.max(r,a,s),te=Math.max(1,u-c),d=Math.max(1,ee-l),f=(e,t)=>`${(e-c)/te*100}% ${(t-l)/d*100}%`;t.style.display=`block`,t.style.left=`${c}px`,t.style.top=`${l}px`,t.style.width=`${te}px`,t.style.height=`${d}px`,t.style.clipPath=`polygon(${f(n,r)}, ${f(i,a)}, ${f(o,s)})`},xe=(e,t,n)=>(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y),Se=(e,t,n,r)=>{let i=xe(e,t,n),a=xe(e,n,r),o=xe(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},Ce=(e,t,n)=>{let r=.5;if(n.top>=t.bottom-r)return[{x:n.left,y:n.top},{x:n.right,y:n.top}];if(n.bottom<=t.top+r)return[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}];if(n.left>=t.right-r)return[{x:n.left,y:n.top},{x:n.left,y:n.bottom}];if(n.right<=t.left+r)return[{x:n.right,y:n.top},{x:n.right,y:n.bottom}];let i=[[{x:n.left,y:n.top},{x:n.right,y:n.top}],[{x:n.right,y:n.top},{x:n.right,y:n.bottom}],[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}],[{x:n.left,y:n.top},{x:n.left,y:n.bottom}]],a=([t,n])=>t.y===n.y?Math.abs(e.y-t.y):Math.abs(e.x-t.x),o=i[0],s=a(o);for(let e=1;e<i.length;e++){let t=i[e],n=a(t);n<s&&(o=t,s=n)}return o},we=()=>b?K.get(b)??null:null,Te=(e,t,n)=>{if(n.width<=0||n.height<=0)return null;let r={x:e.left+e.width/2,y:e.top+e.height*.62},[i,a]=Ce(r,t,n);if(i.x===a.x){let e=Math.min(i.y,a.y),t=Math.max(i.y,a.y),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:i.x,y:e+r},a={x:a.x,y:t-r}}else{let e=Math.min(i.x,a.x),t=Math.max(i.x,a.x),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:e+r,y:i.y},a={x:t-r,y:a.y}}return{apex:r,edgeA:i,edgeB:a}},Ee=()=>{if(!ne||!_||b===null)return null;let e=we();if(!e)return null;let t=r.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),i=_.getBoundingClientRect(),a=e.content.getBoundingClientRect();return Te(n,t,i.width>0&&i.height>0?i:a)},De=e=>{let t=Ee();return t?Se({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},Oe=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),ke=e=>{if(e.length<=1)return e.slice();let t=e=>`${e.x.toFixed(3)}:${e.y.toFixed(3)}`,n=new Map;for(let r of e)n.set(t(r),r);let r=Array.from(n.values()).sort((e,t)=>e.x===t.x?e.y-t.y:e.x-t.x);if(r.length<=2)return r;let i=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),a=[];for(let e of r){for(;a.length>=2&&i(a[a.length-2],a[a.length-1],e)<=0;)a.pop();a.push(e)}let o=[];for(let e=r.length-1;e>=0;e--){let t=r[e];for(;o.length>=2&&i(o[o.length-2],o[o.length-1],t)<=0;)o.pop();o.push(t)}return a.pop(),o.pop(),a.concat(o)},Ae=e=>{if(e.length<3){X();return}let t=ke(e);if(t.length<3){X();return}let n=Math.min(...t.map(e=>e.x)),r=Math.min(...t.map(e=>e.y)),i=Math.max(...t.map(e=>e.x)),a=Math.max(...t.map(e=>e.y)),o=Math.max(1,i-n),s=Math.max(1,a-r),c=e=>`${(e.x-n)/o*100}% ${(e.y-r)/s*100}%`,l=_e();l.style.display=`block`,l.style.transform=`none`,l.style.bottom=`auto`,l.style.right=`auto`,l.style.left=`${n}px`,l.style.top=`${r}px`,l.style.width=`${o}px`,l.style.height=`${s}px`,l.style.clipPath=`polygon(${t.map(c).join(`, `)})`},je=()=>{if(!f)return;let e=Ee();if(!e){ye();return}be(e)},Me=e=>{if(!e)return!1;if(we()?.content.contains(e)||_?.contains(e)||Y?.contains(e))return!0;let t=V?.container;return!!(t instanceof HTMLElement&&t.contains(e))};F.push(Z),F.push(he),F.push(X),F.push(()=>{ye(),A?.parentElement&&A.parentElement.removeChild(A),A=null});let Ne=(t,a,o)=>{_&&requestAnimationFrame(()=>{let s=t.firstElementChild,c=t.lastElementChild,l=s?getComputedStyle(s):null,u=c?getComputedStyle(c):null,ee=l&&parseFloat(l.marginTop)||0,te=u&&parseFloat(u.marginBottom)||0,d=(...e)=>{let t=0;for(let n of e)Number.isFinite(n)&&(t=Math.max(t,n));return t},f=t.getBoundingClientRect(),p=d(f.width,t.scrollWidth,t.offsetWidth,t.clientWidth),m=d(f.height,t.scrollHeight,t.offsetHeight,t.clientHeight)+ee+te,h={top:f.top,left:f.left,width:p,height:m,right:f.left+p,bottom:f.top+m},g=getComputedStyle(_),re=parseFloat(g.marginTop)||0;_.style.setProperty(`--viewport-width`,`${p}px`),_.style.setProperty(`--viewport-height`,`${m}px`);let v=r.getBoundingClientRect(),y=a.getBoundingClientRect(),b=(0,e.computeFloatingPosition)({anchorRect:y,contentRect:h,side:o.side,align:o.align,sideOffset:o.sideOffset,alignOffset:o.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:n}),x=b.x-v.left,S=b.y-v.top;N=x,P=S;let C=i(b.side,b.align,y),w=C.x-(v.left+x),T=C.y-(v.top+S),E=C.x-v.left,D=C.y-v.top,O=`${w}px ${T}px`,k=`${E}px ${D}px`;_.style.top=`0px`,_.style.left=`0px`,_.style.willChange=`transform,width,height`,_.style.setProperty(`--transform-origin`,O),t.style.top=`0px`,t.style.left=`0px`,t.style.setProperty(`--transform-origin`,O),_.setAttribute(`data-side`,b.side),_.setAttribute(`data-align`,b.align),t.setAttribute(`data-side`,b.side),t.setAttribute(`data-align`,b.align);let A=V?.container;A&&A!==_&&(A.setAttribute(`data-side`,b.side),A.setAttribute(`data-align`,b.align),A.style.setProperty(`--transform-origin`,k)),le();let j=_.getBoundingClientRect(),M=[],F=Math.max(0,j.top-v.bottom),I=Math.max(0,v.top-j.bottom),L=Math.max(0,j.left-v.right),R=Math.max(0,v.left-j.right),z=Math.max(0,ee+re),B=Math.max(F,I,z),ie=Math.max(L,R),H=ne?Te(y,v,j):null,U=(e,t,n,r)=>{n<=0||r<=0||M.push({x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r})};if(B>=ie&&B>0){let e=Math.max(F,I,z),t=x,n=I>F&&I>=z?S+m:S-e,r=p;if(H){let e=Math.min(H.edgeA.x,H.edgeB.x)-v.left,n=Math.max(H.edgeA.x,H.edgeB.x)-v.left;t=e-8,r=n-e+16}U(t,n,r,e)}else if(ie>0){let e=Math.max(L,R),t=S,n=R>L?x+p:x-e,r=m;if(H){let e=Math.min(H.edgeA.y,H.edgeB.y)-v.top,n=Math.max(H.edgeA.y,H.edgeB.y)-v.top;t=e-8,r=n-e+16}U(n,t,e,r)}if(H){let e=Oe(H.apex,v),t=Oe(H.edgeA,v),n=Oe(H.edgeB,v);M.push(e,t,n)}Ae(M),je()})},Pe=e=>S===-1||e>S?`right`:`left`,Q=e=>{if(!v)return;if(T=e,!e){he(),v.removeAttribute(`data-instant`),v.setAttribute(`data-state`,`hidden`);return}v.getAttribute(`data-state`)!==`visible`&&(he(),v.setAttribute(`data-instant`,``),j=requestAnimationFrame(()=>{j=requestAnimationFrame(()=>{v.removeAttribute(`data-instant`),j=null})}));let t=g.getBoundingClientRect(),n=e.getBoundingClientRect();v.style.setProperty(`--indicator-left`,`${n.left-t.left}px`),v.style.setProperty(`--indicator-width`,`${n.width}px`),v.style.setProperty(`--indicator-top`,`${n.top-t.top}px`);let r=(_&&parseFloat(getComputedStyle(_).marginTop)||0)<1?1:0;v.style.setProperty(`--indicator-height`,`${n.height-r}px`),v.setAttribute(`data-state`,`visible`)},$=(t,n=!1)=>{if(Z(),t===b){J();return}if(t!==null&&t===x){J();return}J(),x=t===null?null:t;let i=()=>{let n=b,i=t?K.get(t):null,a=n!==null&&t!==null&&n!==t,o=a&&i?Pe(i.index):null,s=document.activeElement;if(t===null&&s&&(0,e.containsWithPortals)(r,s)){let e=n?K.get(n)?.trigger:null;e&&e.focus()}if(K.forEach(({trigger:r,content:i,item:a},s)=>{let c=s===t,l=s===n;if((0,e.setAria)(r,`expanded`,c),r.setAttribute(`data-state`,c?`open`:`closed`),c||l&&t===null?r.tabIndex=0:r.tabIndex=-1,a.setAttribute(`data-state`,c?`open`:`closed`),!c){let e=I.get(i);if(i.setAttribute(`data-state`,`inactive`),i.setAttribute(`aria-hidden`,`true`),h(i,!0),i.style.pointerEvents=`none`,l&&o){let e=o===`right`?`to-left`:`to-right`;i.setAttribute(`data-motion`,e)}else l&&i.removeAttribute(`data-motion`);l?e?.exit():e?.isExiting||(i.removeAttribute(`data-motion`),ce(i),i.hidden=!0)}}),i){if(V?.mount(),_&&(_.hidden=!1),n===null&&oe?.enter(),se(i.content),I.get(i.content)?.enter(),o){let e=o===`right`?`from-right`:`from-left`;i.content.setAttribute(`data-motion`,e)}else i.content.removeAttribute(`data-motion`);i.content.setAttribute(`data-state`,`active`),i.content.removeAttribute(`aria-hidden`),h(i.content,!1),i.content.hidden=!1,i.content.style.pointerEvents=`auto`,S=i.index;let e=de(i.item,i.content);Ne(i.content,i.trigger,e),ue(i),Q(i.trigger)}else X(),Z(),oe?.exit(),ue(null);let c=t!==null;if(r.setAttribute(`data-state`,c?`open`:`closed`),o?r.setAttribute(`data-motion`,o===`right`?`from-right`:`from-left`):r.removeAttribute(`data-motion`),_){_.setAttribute(`data-state`,c?`open`:`closed`),_.style.pointerEvents=c?`auto`:`none`;let e=V?.container;c&&!a?(_.setAttribute(`data-instant`,``),e?.setAttribute(`data-instant`,``),ae()):a?(U(),W()):c||(U(),W()),o&&_.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)}b=t,x=null,t===null&&Q(null),je(),(0,e.emit)(r,`navigation-menu:change`,{value:t}),p?.(t)};n?i():t!==null&&b===null?C=setTimeout(i,o):t!==null&&b!==null?i():w=setTimeout(i,s)};r.setAttribute(`data-state`,`closed`),_&&(_.setAttribute(`data-state`,`closed`),_.hidden=!0,_.style.pointerEvents=`none`),v&&v.setAttribute(`data-state`,`hidden`),K.forEach(({trigger:t,content:n,item:r})=>{t.tagName===`BUTTON`&&!t.hasAttribute(`type`)&&(t.type=`button`),(0,e.setAria)(t,`expanded`,!1),t.setAttribute(`data-state`,`closed`),t.tabIndex=t===q[0]?0:-1,r.setAttribute(`data-state`,`closed`),n.setAttribute(`data-state`,`inactive`),n.setAttribute(`aria-hidden`,`true`),n.tabIndex=-1,h(n,!0),n.hidden=!0,n.style.pointerEvents=`none`}),K.forEach(({item:t,trigger:n},i)=>{F.push((0,e.on)(n,`pointerenter`,e=>{if(!E){if(b!==i&&De(e))return;Q(n)}})),F.push((0,e.on)(t,`pointerenter`,e=>{if(!E){if(b!==i&&De(e))return;$(i)}})),F.push((0,e.on)(t,`pointerleave`,t=>{if(x===i&&b===null&&(J(),x=null),b===i&&!E){let n=t.relatedTarget;if(Me(n))return;(!n||!(0,e.containsWithPortals)(r,n))&&($(null),Q(null))}})),F.push((0,e.on)(n,`focus`,()=>{D||(c&&$(i,!0),Q(n))})),F.push((0,e.on)(n,`pointerdown`,()=>{D=!0})),F.push((0,e.on)(n,`click`,()=>{J(),b===i&&E?(E=!1,$(null,!0),Q(null)):b===i&&!E?(E=!0,Q(n)):(E=!0,$(i,!0),Q(n)),D=!1}))}),F.push((0,e.on)(r,`pointerenter`,()=>{O=!0}),(0,e.on)(r,`pointerleave`,e=>{let t=e.relatedTarget;if(!Me(t)&&(O=!1,!E)){if(De(e)){J();return}$(null),Q(null)}}),(0,e.on)(r,`pointerdown`,()=>{Z(),J()})),_&&F.push((0,e.on)(_,`pointerenter`,()=>{Z(),J()}),(0,e.on)(_,`transitionend`,e=>{if(e.target!==_)return;let t=b?K.get(b):null;if(t){let e=de(t.item,t.content);Ne(t.content,t.trigger,e)}})),K.forEach(({content:t})=>{F.push((0,e.on)(t,`pointerenter`,()=>{Z(),J()}),(0,e.on)(t,`pointerleave`,t=>{if(E)return;let n=t.relatedTarget;Me(n)||(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))}),F.push((0,e.on)(g,`keydown`,e=>{let t=e.target,n=q.indexOf(t);if(n===-1)return;let r=pe.get(t)??null,i=n;switch(e.key){case`ArrowLeft`:i=n-1,i<0&&(i=q.length-1);break;case`ArrowRight`:i=n+1,i>=q.length&&(i=0);break;case`ArrowDown`:e.preventDefault(),r&&(E=!0,$(r,!0),requestAnimationFrame(()=>{let e=K.get(r);if(!e)return;let t=me(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=q.length-1;break;case`Escape`:E=!1,$(null,!0),Q(null);return;default:return}e.preventDefault();let a=q[i];a&&(q.forEach(e=>e.tabIndex=e===a?0:-1),a.focus(),Q(a))})),K.forEach(({content:t,trigger:n})=>{F.push((0,e.on)(t,`keydown`,e=>{let r=e.target,i=me(t),a=i.indexOf(r);if(a!==-1)switch(e.key){case`ArrowDown`:case`ArrowRight`:{e.preventDefault();let t=a+1;t<i.length&&i[t]?.focus();break}case`ArrowUp`:case`ArrowLeft`:e.preventDefault(),a===0?n.focus():i[a-1]?.focus();break;case`Escape`:e.preventDefault(),E=!1,$(null,!0),Q(null),n.focus();break}}))});let Fe=()=>(0,e.containsWithPortals)(r,document.activeElement)||O||E,Ie=()=>{Z(),E=!1,$(null,!0),Q(null),je()};return F.push((0,e.on)(document,`pointerup`,()=>{D=!1},{capture:!0}),(0,e.on)(document,`pointercancel`,()=>{D=!1},{capture:!0})),F.push((0,e.on)(document,`focusin`,t=>{b!==null&&((0,e.containsWithPortals)(r,t.target)||Ie())})),F.push((0,e.createDismissLayer)({root:r,isOpen:()=>b!==null&&Fe(),onDismiss:Ie,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:t=>!!t&&(0,e.containsWithPortals)(r,t)})),F.push((0,e.on)(window,`resize`,()=>{b&&requestAnimationFrame(()=>le()),T&&requestAnimationFrame(()=>Q(T))}),(0,e.on)(g,`scroll`,()=>{T&&requestAnimationFrame(()=>Q(T))})),F.push((0,e.on)(r,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)Ie();else if(K.has(t.value)){E=!0,$(t.value,!0);let e=K.get(t.value);e&&Q(e.trigger)}}})),{get value(){return b},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{k=!0,J(),F.forEach(e=>e()),F.length=0}}}const o=new WeakSet;function s(t=document){let n=[];for(let r of(0,e.getRoots)(t,`navigation-menu`))o.has(r)||(o.add(r),n.push(a(r)));return n}exports.create=s,exports.createNavigationMenu=a;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{computeFloatingPosition as e,containsWithPortals as t,createDismissLayer as n,createPortalLifecycle as r,createPresenceLifecycle as i,emit as a,ensureId as o,getDataBool as s,getDataEnum as c,getDataNumber as l,getPart as u,getParts as d,getRoots as f,on as p,setAria as m}from"@data-slot/core";const ee=[`start`,`center`,`end`],h=[`top`,`right`,`bottom`,`left`],g=(e,t)=>t===`start`?{x:e.left,y:e.top}:t===`end`?{x:e.right,y:e.bottom}:{x:e.left+e.width/2,y:e.top+e.height/2},te=(e,t,n)=>{let r=g(n,t);return e===`top`?{x:r.x,y:n.top}:e===`bottom`?{x:r.x,y:n.bottom}:e===`left`?{x:n.left,y:r.y}:{x:n.right,y:r.y}};function ne(f,g={}){let ne=g.delayOpen??l(f,`delayOpen`)??200,_=g.delayClose??l(f,`delayClose`)??150,v=g.openOnFocus??s(f,`openOnFocus`)??!0,y=g.side??c(f,`side`,h)??`bottom`,b=g.align??c(f,`align`,ee)??`start`,x=g.sideOffset??l(f,`sideOffset`)??0,S=g.alignOffset??l(f,`alignOffset`)??0,re=g.safeTriangle??s(f,`safeTriangle`)??!1,C=g.debugSafeTriangle??s(f,`debugSafeTriangle`)??!1,ie=re||C,ae=g.onValueChange,oe=e=>e.replace(/[^a-z0-9\-_:.]/gi,`-`),w=(e,t)=>{`inert`in e&&(e.inert=t)},T=u(f,`navigation-menu-list`),E=d(f,`navigation-menu-item`),D=u(f,`navigation-menu-viewport`),O=u(f,`navigation-menu-indicator`),k=(e,t)=>{let n=e.parentElement;for(;n&&n!==f;){if(n.getAttribute(`data-slot`)===t)return n;n=n.parentElement}return null};if(!T||E.length===0)throw Error(`NavigationMenu requires navigation-menu-list and at least one navigation-menu-item`);let A=null,j=null,M=-1,N=null,P=null,F=null,I=!1,L=!1,R=!1,se=!1,z=null,B=null,ce=0,le=0,V=[],H=new Map,U=new Map,ue=D?k(D,`navigation-menu-viewport-positioner`):null,de=D?k(D,`navigation-menu-positioner`):null,W=ue??de,fe=W?k(W,`navigation-menu-portal`):null,G=D?r({content:D,root:f,enabled:!0,wrapperSlot:W?void 0:`navigation-menu-viewport-positioner`,container:W??void 0,mountTarget:W?fe??W:void 0}):null,pe=D?i({element:D,onExitComplete:()=>{se||(G?.restore(),D.hidden=!0,D.style.pointerEvents=`none`)}}):null,me=e=>{if(!D)return;let t=U.get(e)??{originalParent:null,originalNextSibling:null,mountedInViewport:!1};t.mountedInViewport||(t.originalParent=e.parentNode,t.originalNextSibling=e.nextSibling,t.mountedInViewport=!0,U.set(e,t)),e.parentNode!==D&&D.appendChild(e)},he=e=>{let t=U.get(e);if(!t||!t.mountedInViewport)return;let n=t.originalParent,r=t.originalNextSibling;n&&n.isConnected?r&&r.parentNode===n?n.insertBefore(e,r):n.appendChild(e):e.remove(),t.mountedInViewport=!1,t.originalParent=null,t.originalNextSibling=null},ge=()=>{if(!D||!G)return;let e=G.container,t=f.ownerDocument.defaultView??window,n=f.getBoundingClientRect(),r=n.top+t.scrollY+le,i=n.left+t.scrollX+ce;e.style.position=`absolute`,e.style.top=`${r}px`,e.style.left=`${i}px`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`top,left`,e.style.pointerEvents=`none`},K=null,_e=e=>{K?.disconnect(),K=null,!(!D||!e)&&(K=new ResizeObserver(()=>{let t=ve(e.item,e.content);Ve(e.content,e.trigger,t)}),K.observe(e.content))};V.push(()=>K?.disconnect()),V.push(()=>{H.forEach(e=>e.cleanup()),H.clear(),U.forEach((e,t)=>{he(t),t.hidden=!0,t.style.pointerEvents=`none`}),U.clear(),pe?.cleanup(),G?.cleanup()});let q=new Map,ve=(e,t)=>({side:g.side??c(t,`side`,h)??c(e,`side`,h)??y,align:g.align??c(t,`align`,ee)??c(e,`align`,ee)??b,sideOffset:g.sideOffset??l(t,`sideOffset`)??l(e,`sideOffset`)??x,alignOffset:g.alignOffset??l(t,`alignOffset`)??l(e,`alignOffset`)??S}),ye=0;E.forEach(e=>{let t=e.dataset.value;if(!t)return;let n=u(e,`navigation-menu-trigger`),r=u(e,`navigation-menu-content`);if(n&&r){q.set(t,{item:e,trigger:n,content:r,index:ye++}),H.set(r,i({element:r,onExitComplete:()=>{se||(he(r),r.hidden=!0,r.style.pointerEvents=`none`)}}));let a=oe(t),s=o(n,`nav-menu-trigger-${a}`),c=o(r,`nav-menu-content-${a}`);n.setAttribute(`aria-haspopup`,`true`),n.setAttribute(`aria-controls`,c),r.setAttribute(`aria-labelledby`,s)}});let J=Array.from(q.values()).map(e=>e.trigger),be=new Map;for(let[e,t]of q)be.set(t.trigger,e);let xe=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),Y=()=>{N&&=(clearTimeout(N),null),P&&=(clearTimeout(P),null)},Se=()=>{B!==null&&(cancelAnimationFrame(B),B=null)},X=null,Ce=()=>{if(!D)return null;let e=G?.container;return e instanceof HTMLElement?e:D.parentElement instanceof HTMLElement?D.parentElement:D},we=()=>{let e=Ce();return X||(X=document.createElement(`div`),X.setAttribute(`data-slot`,`navigation-menu-bridge`),X.style.cssText=`position: absolute; pointer-events: auto; z-index: 0; display: none;`,V.push(p(X,`pointerenter`,()=>{Y()}),p(X,`pointerleave`,e=>{if(I||A===null)return;let n=e.relatedTarget;Be(n)||n&&t(f,n)||($(null),Q(null))}))),e&&X.parentElement!==e&&e.insertBefore(X,e.firstChild),X},Te=()=>{X&&(X.style.height=`0`,X.style.width=`0`,X.style.top=`0px`,X.style.left=`0px`,X.style.right=`0px`,X.style.bottom=`auto`,X.style.transform=`none`,X.style.clipPath=`none`,X.style.display=`none`)},Ee=()=>{if(!C)return null;let e=f.ownerDocument.body;return e?(z||(z=f.ownerDocument.createElement(`div`),z.setAttribute(`data-slot`,`navigation-menu-safe-triangle`),z.style.cssText=[`position: fixed`,`pointer-events: none`,`display: none`,`z-index: 2147483647`,`background: rgba(255, 0, 0, 0.18)`,`border: 1px solid rgba(255, 0, 0, 0.45)`].join(`; `)),z.parentElement!==e&&e.appendChild(z),z):null},De=()=>{z&&(z.style.width=`0`,z.style.height=`0`,z.style.clipPath=`none`,z.style.display=`none`)},Z=()=>{C||De()},Oe=e=>{let t=Ee();if(!t)return;let n=e.apex.x,r=e.apex.y,i=e.edgeA.x,a=e.edgeA.y,o=e.edgeB.x,s=e.edgeB.y,c=Math.min(n,i,o),l=Math.min(r,a,s),u=Math.max(n,i,o),d=Math.max(r,a,s),f=Math.max(1,u-c),p=Math.max(1,d-l),m=(e,t)=>`${(e-c)/f*100}% ${(t-l)/p*100}%`;t.style.display=`block`,t.style.left=`${c}px`,t.style.top=`${l}px`,t.style.width=`${f}px`,t.style.height=`${p}px`,t.style.clipPath=`polygon(${m(n,r)}, ${m(i,a)}, ${m(o,s)})`},ke=(e,t,n)=>(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y),Ae=(e,t,n,r)=>{let i=ke(e,t,n),a=ke(e,n,r),o=ke(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},je=(e,t,n)=>{let r=.5;if(n.top>=t.bottom-r)return[{x:n.left,y:n.top},{x:n.right,y:n.top}];if(n.bottom<=t.top+r)return[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}];if(n.left>=t.right-r)return[{x:n.left,y:n.top},{x:n.left,y:n.bottom}];if(n.right<=t.left+r)return[{x:n.right,y:n.top},{x:n.right,y:n.bottom}];let i=[[{x:n.left,y:n.top},{x:n.right,y:n.top}],[{x:n.right,y:n.top},{x:n.right,y:n.bottom}],[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}],[{x:n.left,y:n.top},{x:n.left,y:n.bottom}]],a=([t,n])=>t.y===n.y?Math.abs(e.y-t.y):Math.abs(e.x-t.x),o=i[0],s=a(o);for(let e=1;e<i.length;e++){let t=i[e],n=a(t);n<s&&(o=t,s=n)}return o},Me=()=>A?q.get(A)??null:null,Ne=(e,t,n)=>{if(n.width<=0||n.height<=0)return null;let r={x:e.left+e.width/2,y:e.top+e.height*.62},[i,a]=je(r,t,n);if(i.x===a.x){let e=Math.min(i.y,a.y),t=Math.max(i.y,a.y),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:i.x,y:e+r},a={x:a.x,y:t-r}}else{let e=Math.min(i.x,a.x),t=Math.max(i.x,a.x),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:e+r,y:i.y},a={x:t-r,y:a.y}}return{apex:r,edgeA:i,edgeB:a}},Pe=()=>{if(!ie||!D||A===null)return null;let e=Me();if(!e)return null;let t=f.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),r=D.getBoundingClientRect(),i=e.content.getBoundingClientRect();return Ne(n,t,r.width>0&&r.height>0?r:i)},Fe=e=>{let t=Pe();return t?Ae({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},Ie=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),Le=e=>{if(e.length<=1)return e.slice();let t=e=>`${e.x.toFixed(3)}:${e.y.toFixed(3)}`,n=new Map;for(let r of e)n.set(t(r),r);let r=Array.from(n.values()).sort((e,t)=>e.x===t.x?e.y-t.y:e.x-t.x);if(r.length<=2)return r;let i=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),a=[];for(let e of r){for(;a.length>=2&&i(a[a.length-2],a[a.length-1],e)<=0;)a.pop();a.push(e)}let o=[];for(let e=r.length-1;e>=0;e--){let t=r[e];for(;o.length>=2&&i(o[o.length-2],o[o.length-1],t)<=0;)o.pop();o.push(t)}return a.pop(),o.pop(),a.concat(o)},Re=e=>{if(e.length<3){Te();return}let t=Le(e);if(t.length<3){Te();return}let n=Math.min(...t.map(e=>e.x)),r=Math.min(...t.map(e=>e.y)),i=Math.max(...t.map(e=>e.x)),a=Math.max(...t.map(e=>e.y)),o=Math.max(1,i-n),s=Math.max(1,a-r),c=e=>`${(e.x-n)/o*100}% ${(e.y-r)/s*100}%`,l=we();l.style.display=`block`,l.style.transform=`none`,l.style.bottom=`auto`,l.style.right=`auto`,l.style.left=`${n}px`,l.style.top=`${r}px`,l.style.width=`${o}px`,l.style.height=`${s}px`,l.style.clipPath=`polygon(${t.map(c).join(`, `)})`},ze=()=>{if(!C)return;let e=Pe();if(!e){De();return}Oe(e)},Be=e=>{if(!e)return!1;if(Me()?.content.contains(e)||D?.contains(e)||X?.contains(e))return!0;let t=G?.container;return!!(t instanceof HTMLElement&&t.contains(e))};V.push(Z),V.push(Se),V.push(Te),V.push(()=>{De(),z?.parentElement&&z.parentElement.removeChild(z),z=null});let Ve=(t,n,r)=>{D&&requestAnimationFrame(()=>{let i=t.firstElementChild,a=t.lastElementChild,o=i?getComputedStyle(i):null,s=a?getComputedStyle(a):null,c=o&&parseFloat(o.marginTop)||0,l=s&&parseFloat(s.marginBottom)||0,u=(...e)=>{let t=0;for(let n of e)Number.isFinite(n)&&(t=Math.max(t,n));return t},d=t.getBoundingClientRect(),p=u(d.width,t.scrollWidth,t.offsetWidth,t.clientWidth),m=u(d.height,t.scrollHeight,t.offsetHeight,t.clientHeight)+c+l,ee={top:d.top,left:d.left,width:p,height:m,right:d.left+p,bottom:d.top+m},g=getComputedStyle(D),ne=parseFloat(g.marginTop)||0;D.style.setProperty(`--viewport-width`,`${p}px`),D.style.setProperty(`--viewport-height`,`${m}px`);let _=f.getBoundingClientRect(),v=n.getBoundingClientRect(),y=e({anchorRect:v,contentRect:ee,side:r.side,align:r.align,sideOffset:r.sideOffset,alignOffset:r.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:h}),b=y.x-_.left,x=y.y-_.top;ce=b,le=x;let S=te(y.side,y.align,v),re=S.x-(_.left+b),C=S.y-(_.top+x),ae=S.x-_.left,oe=S.y-_.top,w=`${re}px ${C}px`,T=`${ae}px ${oe}px`;D.style.top=`0px`,D.style.left=`0px`,D.style.willChange=`transform,width,height`,D.style.setProperty(`--transform-origin`,w),t.style.top=`0px`,t.style.left=`0px`,t.style.setProperty(`--transform-origin`,w),D.setAttribute(`data-side`,y.side),D.setAttribute(`data-align`,y.align),t.setAttribute(`data-side`,y.side),t.setAttribute(`data-align`,y.align);let E=G?.container;E&&E!==D&&(E.setAttribute(`data-side`,y.side),E.setAttribute(`data-align`,y.align),E.style.setProperty(`--transform-origin`,T)),ge();let O=D.getBoundingClientRect(),k=[],A=Math.max(0,O.top-_.bottom),j=Math.max(0,_.top-O.bottom),M=Math.max(0,O.left-_.right),N=Math.max(0,_.left-O.right),P=Math.max(0,c+ne),F=Math.max(A,j,P),I=Math.max(M,N),L=ie?Ne(v,_,O):null,R=(e,t,n,r)=>{n<=0||r<=0||k.push({x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r})};if(F>=I&&F>0){let e=Math.max(A,j,P),t=b,n=j>A&&j>=P?x+m:x-e,r=p;if(L){let e=Math.min(L.edgeA.x,L.edgeB.x)-_.left,n=Math.max(L.edgeA.x,L.edgeB.x)-_.left;t=e-8,r=n-e+16}R(t,n,r,e)}else if(I>0){let e=Math.max(M,N),t=x,n=N>M?b+p:b-e,r=m;if(L){let e=Math.min(L.edgeA.y,L.edgeB.y)-_.top,n=Math.max(L.edgeA.y,L.edgeB.y)-_.top;t=e-8,r=n-e+16}R(n,t,e,r)}if(L){let e=Ie(L.apex,_),t=Ie(L.edgeA,_),n=Ie(L.edgeB,_);k.push(e,t,n)}Re(k),ze()})},He=e=>M===-1||e>M?`right`:`left`,Q=e=>{if(!O)return;if(F=e,!e){Se(),O.removeAttribute(`data-instant`),O.setAttribute(`data-state`,`hidden`);return}O.getAttribute(`data-state`)!==`visible`&&(Se(),O.setAttribute(`data-instant`,``),B=requestAnimationFrame(()=>{B=requestAnimationFrame(()=>{O.removeAttribute(`data-instant`),B=null})}));let t=T.getBoundingClientRect(),n=e.getBoundingClientRect();O.style.setProperty(`--indicator-left`,`${n.left-t.left}px`),O.style.setProperty(`--indicator-width`,`${n.width}px`),O.style.setProperty(`--indicator-top`,`${n.top-t.top}px`);let r=(D&&parseFloat(getComputedStyle(D).marginTop)||0)<1?1:0;O.style.setProperty(`--indicator-height`,`${n.height-r}px`),O.setAttribute(`data-state`,`visible`)},$=(e,n=!1)=>{if(Z(),e===A){Y();return}if(e!==null&&e===j){Y();return}Y(),j=e===null?null:e;let r=()=>{let n=A,r=e?q.get(e):null,i=n!==null&&e!==null&&n!==e,o=i&&r?He(r.index):null,s=document.activeElement;if(e===null&&s&&t(f,s)){let e=n?q.get(n)?.trigger:null;e&&e.focus()}if(q.forEach(({trigger:t,content:r,item:i},a)=>{let s=a===e,c=a===n;if(m(t,`expanded`,s),t.setAttribute(`data-state`,s?`open`:`closed`),s||c&&e===null?t.tabIndex=0:t.tabIndex=-1,i.setAttribute(`data-state`,s?`open`:`closed`),!s){let e=H.get(r);if(r.setAttribute(`data-state`,`inactive`),r.setAttribute(`aria-hidden`,`true`),w(r,!0),r.style.pointerEvents=`none`,c&&o){let e=o===`right`?`to-left`:`to-right`;r.setAttribute(`data-motion`,e)}else c&&r.removeAttribute(`data-motion`);c?e?.exit():e?.isExiting||(r.removeAttribute(`data-motion`),he(r),r.hidden=!0)}}),r){if(G?.mount(),D&&(D.hidden=!1),n===null&&pe?.enter(),me(r.content),H.get(r.content)?.enter(),o){let e=o===`right`?`from-right`:`from-left`;r.content.setAttribute(`data-motion`,e)}else r.content.removeAttribute(`data-motion`);r.content.setAttribute(`data-state`,`active`),r.content.removeAttribute(`aria-hidden`),w(r.content,!1),r.content.hidden=!1,r.content.style.pointerEvents=`auto`,M=r.index;let e=ve(r.item,r.content);Ve(r.content,r.trigger,e),_e(r),Q(r.trigger)}else Te(),Z(),pe?.exit(),_e(null);let c=e!==null;if(f.setAttribute(`data-state`,c?`open`:`closed`),o?f.setAttribute(`data-motion`,o===`right`?`from-right`:`from-left`):f.removeAttribute(`data-motion`),D){D.setAttribute(`data-state`,c?`open`:`closed`),D.style.pointerEvents=c?`auto`:`none`;let e=G?.container;c&&!i?(D.setAttribute(`data-instant`,``),e?.setAttribute(`data-instant`,``)):i&&(D.removeAttribute(`data-instant`),e?.removeAttribute(`data-instant`)),o&&D.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)}A=e,j=null,e===null&&Q(null),ze(),a(f,`navigation-menu:change`,{value:e}),ae?.(e)};n?r():e!==null&&A===null?N=setTimeout(r,ne):e!==null&&A!==null?r():P=setTimeout(r,_)};f.setAttribute(`data-state`,`closed`),D&&(D.setAttribute(`data-state`,`closed`),D.hidden=!0,D.style.pointerEvents=`none`),O&&O.setAttribute(`data-state`,`hidden`),q.forEach(({trigger:e,content:t,item:n})=>{e.tagName===`BUTTON`&&!e.hasAttribute(`type`)&&(e.type=`button`),m(e,`expanded`,!1),e.setAttribute(`data-state`,`closed`),e.tabIndex=e===J[0]?0:-1,n.setAttribute(`data-state`,`closed`),t.setAttribute(`data-state`,`inactive`),t.setAttribute(`aria-hidden`,`true`),t.tabIndex=-1,w(t,!0),t.hidden=!0,t.style.pointerEvents=`none`}),q.forEach(({item:e,trigger:n},r)=>{V.push(p(n,`pointerenter`,e=>{if(!I){if(A!==r&&Fe(e))return;Q(n)}})),V.push(p(e,`pointerenter`,e=>{if(!I){if(A!==r&&Fe(e))return;$(r)}})),V.push(p(e,`pointerleave`,e=>{if(j===r&&A===null&&(Y(),j=null),A===r&&!I){let n=e.relatedTarget;if(Be(n))return;(!n||!t(f,n))&&($(null),Q(null))}})),V.push(p(n,`focus`,()=>{L||(v&&$(r,!0),Q(n))})),V.push(p(n,`pointerdown`,()=>{L=!0})),V.push(p(n,`click`,()=>{Y(),A===r&&I?(I=!1,$(null,!0),Q(null)):A===r&&!I?(I=!0,Q(n)):(I=!0,$(r,!0),Q(n)),L=!1}))}),V.push(p(f,`pointerenter`,()=>{R=!0}),p(f,`pointerleave`,e=>{let t=e.relatedTarget;if(!Be(t)&&(R=!1,!I)){if(Fe(e)){Y();return}$(null),Q(null)}}),p(f,`pointerdown`,()=>{Z(),Y()})),D&&V.push(p(D,`pointerenter`,()=>{Z(),Y()}),p(D,`transitionend`,e=>{if(e.target!==D)return;let t=A?q.get(A):null;if(t){let e=ve(t.item,t.content);Ve(t.content,t.trigger,e)}})),q.forEach(({content:e})=>{V.push(p(e,`pointerenter`,()=>{Z(),Y()}),p(e,`pointerleave`,e=>{if(I)return;let n=e.relatedTarget;Be(n)||t(f,n)||($(null),Q(null))}))}),V.push(p(T,`keydown`,e=>{let t=e.target,n=J.indexOf(t);if(n===-1)return;let r=be.get(t)??null,i=n;switch(e.key){case`ArrowLeft`:i=n-1,i<0&&(i=J.length-1);break;case`ArrowRight`:i=n+1,i>=J.length&&(i=0);break;case`ArrowDown`:e.preventDefault(),r&&(I=!0,$(r,!0),requestAnimationFrame(()=>{let e=q.get(r);if(!e)return;let t=xe(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=J.length-1;break;case`Escape`:I=!1,$(null,!0),Q(null);return;default:return}e.preventDefault();let a=J[i];a&&(J.forEach(e=>e.tabIndex=e===a?0:-1),a.focus(),Q(a))})),q.forEach(({content:e,trigger:t})=>{V.push(p(e,`keydown`,n=>{let r=n.target,i=xe(e),a=i.indexOf(r);if(a!==-1)switch(n.key){case`ArrowDown`:case`ArrowRight`:{n.preventDefault();let e=a+1;e<i.length&&i[e]?.focus();break}case`ArrowUp`:case`ArrowLeft`:n.preventDefault(),a===0?t.focus():i[a-1]?.focus();break;case`Escape`:n.preventDefault(),I=!1,$(null,!0),Q(null),t.focus();break}}))});let Ue=()=>t(f,document.activeElement)||R||I,We=()=>{Z(),I=!1,$(null,!0),Q(null),ze()};return V.push(p(document,`pointerup`,()=>{L=!1},{capture:!0}),p(document,`pointercancel`,()=>{L=!1},{capture:!0})),V.push(p(document,`focusin`,e=>{A!==null&&(t(f,e.target)||We())})),V.push(n({root:f,isOpen:()=>A!==null&&Ue(),onDismiss:We,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:e=>!!e&&t(f,e)})),V.push(p(window,`resize`,()=>{A&&requestAnimationFrame(()=>ge()),F&&requestAnimationFrame(()=>Q(F))}),p(T,`scroll`,()=>{F&&requestAnimationFrame(()=>Q(F))})),V.push(p(f,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)We();else if(q.has(t.value)){I=!0,$(t.value,!0);let e=q.get(t.value);e&&Q(e.trigger)}}})),{get value(){return A},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{se=!0,Y(),V.forEach(e=>e()),V.length=0}}}const _=new WeakSet;function v(e=document){let t=[];for(let n of f(e,`navigation-menu`))_.has(n)||(_.add(n),t.push(ne(n)));return t}export{v as create,ne as createNavigationMenu};
1
+ import{computeFloatingPosition as e,containsWithPortals as t,createDismissLayer as n,createPortalLifecycle as r,createPresenceLifecycle as i,emit as a,ensureId as o,getDataBool as s,getDataEnum as c,getDataNumber as l,getPart as u,getParts as d,getRoots as f,on as p,setAria as m}from"@data-slot/core";const ee=[`start`,`center`,`end`],te=[`top`,`right`,`bottom`,`left`],h=(e,t)=>t===`start`?{x:e.left,y:e.top}:t===`end`?{x:e.right,y:e.bottom}:{x:e.left+e.width/2,y:e.top+e.height/2},ne=(e,t,n)=>{let r=h(n,t);return e===`top`?{x:r.x,y:n.top}:e===`bottom`?{x:r.x,y:n.bottom}:e===`left`?{x:n.left,y:r.y}:{x:n.right,y:r.y}};function re(f,h={}){let re=h.delayOpen??l(f,`delayOpen`)??200,g=h.delayClose??l(f,`delayClose`)??150,_=h.openOnFocus??s(f,`openOnFocus`)??!0,v=h.side??c(f,`side`,te)??`bottom`,y=h.align??c(f,`align`,ee)??`start`,b=h.sideOffset??l(f,`sideOffset`)??0,ie=h.alignOffset??l(f,`alignOffset`)??0,ae=h.safeTriangle??s(f,`safeTriangle`)??!1,x=h.debugSafeTriangle??s(f,`debugSafeTriangle`)??!1,oe=ae||x,se=h.onValueChange,ce=e=>e.replace(/[^a-z0-9\-_:.]/gi,`-`),S=(e,t)=>{`inert`in e&&(e.inert=t)},le=u(f,`navigation-menu-list`),C=d(f,`navigation-menu-item`),w=u(f,`navigation-menu-viewport`),T=u(f,`navigation-menu-indicator`),E=(e,t)=>{let n=e.parentElement;for(;n&&n!==f;){if(n.getAttribute(`data-slot`)===t)return n;n=n.parentElement}return null};if(!le||C.length===0)throw Error(`NavigationMenu requires navigation-menu-list and at least one navigation-menu-item`);let D=null,O=null,k=-1,A=null,j=null,M=null,N=!1,P=!1,F=!1,ue=!1,I=null,L=null,R=null,de=0,fe=0,z=[],B=new Map,V=new Map,pe=w?E(w,`navigation-menu-viewport-positioner`):null,me=w?E(w,`navigation-menu-positioner`):null,H=pe??me,he=H?E(H,`navigation-menu-portal`):null,U=w?r({content:w,root:f,enabled:!0,wrapperSlot:H?void 0:`navigation-menu-viewport-positioner`,container:H??void 0,mountTarget:H?he??H:void 0}):null,ge=()=>{let e=U?.container;e instanceof HTMLElement&&(e.style.position=``,e.style.top=``,e.style.left=``,e.style.width=``,e.style.height=``,e.style.margin=``,e.style.willChange=``,e.style.pointerEvents=``,e.style.transform=``,e.style.removeProperty(`--transform-origin`),e.removeAttribute(`data-instant`))},W=()=>{R!==null&&(cancelAnimationFrame(R),R=null)},G=()=>{w?.removeAttribute(`data-instant`);let e=U?.container;e instanceof HTMLElement&&e.removeAttribute(`data-instant`)},_e=()=>{w&&(W(),R=requestAnimationFrame(()=>{R=requestAnimationFrame(()=>{G(),R=null})}))},ve=w?i({element:w,onExitComplete:()=>{ue||(W(),G(),ge(),de=0,fe=0,U?.restore(),w.hidden=!0,w.style.pointerEvents=`none`)}}):null,ye=e=>{if(!w)return;let t=V.get(e)??{originalParent:null,originalNextSibling:null,mountedInViewport:!1};t.mountedInViewport||(t.originalParent=e.parentNode,t.originalNextSibling=e.nextSibling,t.mountedInViewport=!0,V.set(e,t)),e.parentNode!==w&&w.appendChild(e)},be=e=>{let t=V.get(e);if(!t||!t.mountedInViewport)return;let n=t.originalParent,r=t.originalNextSibling;n&&n.isConnected?r&&r.parentNode===n?n.insertBefore(e,r):n.appendChild(e):e.remove(),t.mountedInViewport=!1,t.originalParent=null,t.originalNextSibling=null},xe=()=>{if(!w||!U)return;let e=U.container,t=f.ownerDocument.defaultView??window,n=f.getBoundingClientRect(),r=n.top+t.scrollY+fe,i=n.left+t.scrollX+de;e.style.position=`absolute`,e.style.top=`${r}px`,e.style.left=`${i}px`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`top,left`,e.style.pointerEvents=`none`},K=null,Se=e=>{K?.disconnect(),K=null,!(!w||!e)&&(K=new ResizeObserver(()=>{let t=Ce(e.item,e.content);Ke(e.content,e.trigger,t)}),K.observe(e.content))};z.push(()=>K?.disconnect()),z.push(()=>{W(),G(),B.forEach(e=>e.cleanup()),B.clear(),V.forEach((e,t)=>{be(t),t.hidden=!0,t.style.pointerEvents=`none`}),V.clear(),ge(),de=0,fe=0,ve?.cleanup(),U?.cleanup()});let q=new Map,Ce=(e,t)=>({side:h.side??c(t,`side`,te)??c(e,`side`,te)??v,align:h.align??c(t,`align`,ee)??c(e,`align`,ee)??y,sideOffset:h.sideOffset??l(t,`sideOffset`)??l(e,`sideOffset`)??b,alignOffset:h.alignOffset??l(t,`alignOffset`)??l(e,`alignOffset`)??ie}),we=0;C.forEach(e=>{let t=e.dataset.value;if(!t)return;let n=u(e,`navigation-menu-trigger`),r=u(e,`navigation-menu-content`);if(n&&r){q.set(t,{item:e,trigger:n,content:r,index:we++}),B.set(r,i({element:r,onExitComplete:()=>{ue||(be(r),r.hidden=!0,r.style.pointerEvents=`none`)}}));let a=ce(t),s=o(n,`nav-menu-trigger-${a}`),c=o(r,`nav-menu-content-${a}`);n.setAttribute(`aria-haspopup`,`true`),n.setAttribute(`aria-controls`,c),r.setAttribute(`aria-labelledby`,s)}});let J=Array.from(q.values()).map(e=>e.trigger),Te=new Map;for(let[e,t]of q)Te.set(t.trigger,e);let Ee=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),Y=()=>{A&&=(clearTimeout(A),null),j&&=(clearTimeout(j),null)},De=()=>{L!==null&&(cancelAnimationFrame(L),L=null)},X=null,Oe=()=>{if(!w)return null;let e=U?.container;return e instanceof HTMLElement?e:w.parentElement instanceof HTMLElement?w.parentElement:w},ke=()=>{let e=Oe();return X||(X=document.createElement(`div`),X.setAttribute(`data-slot`,`navigation-menu-bridge`),X.style.cssText=`position: absolute; pointer-events: auto; z-index: 0; display: none;`,z.push(p(X,`pointerenter`,()=>{Y()}),p(X,`pointerleave`,e=>{if(N||D===null)return;let n=e.relatedTarget;Ge(n)||n&&t(f,n)||($(null),Q(null))}))),e&&X.parentElement!==e&&e.insertBefore(X,e.firstChild),X},Ae=()=>{X&&(X.style.height=`0`,X.style.width=`0`,X.style.top=`0px`,X.style.left=`0px`,X.style.right=`0px`,X.style.bottom=`auto`,X.style.transform=`none`,X.style.clipPath=`none`,X.style.display=`none`)},je=()=>{if(!x)return null;let e=f.ownerDocument.body;return e?(I||(I=f.ownerDocument.createElement(`div`),I.setAttribute(`data-slot`,`navigation-menu-safe-triangle`),I.style.cssText=[`position: fixed`,`pointer-events: none`,`display: none`,`z-index: 2147483647`,`background: rgba(255, 0, 0, 0.18)`,`border: 1px solid rgba(255, 0, 0, 0.45)`].join(`; `)),I.parentElement!==e&&e.appendChild(I),I):null},Me=()=>{I&&(I.style.width=`0`,I.style.height=`0`,I.style.clipPath=`none`,I.style.display=`none`)},Z=()=>{x||Me()},Ne=e=>{let t=je();if(!t)return;let n=e.apex.x,r=e.apex.y,i=e.edgeA.x,a=e.edgeA.y,o=e.edgeB.x,s=e.edgeB.y,c=Math.min(n,i,o),l=Math.min(r,a,s),u=Math.max(n,i,o),d=Math.max(r,a,s),f=Math.max(1,u-c),p=Math.max(1,d-l),m=(e,t)=>`${(e-c)/f*100}% ${(t-l)/p*100}%`;t.style.display=`block`,t.style.left=`${c}px`,t.style.top=`${l}px`,t.style.width=`${f}px`,t.style.height=`${p}px`,t.style.clipPath=`polygon(${m(n,r)}, ${m(i,a)}, ${m(o,s)})`},Pe=(e,t,n)=>(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y),Fe=(e,t,n,r)=>{let i=Pe(e,t,n),a=Pe(e,n,r),o=Pe(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},Ie=(e,t,n)=>{let r=.5;if(n.top>=t.bottom-r)return[{x:n.left,y:n.top},{x:n.right,y:n.top}];if(n.bottom<=t.top+r)return[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}];if(n.left>=t.right-r)return[{x:n.left,y:n.top},{x:n.left,y:n.bottom}];if(n.right<=t.left+r)return[{x:n.right,y:n.top},{x:n.right,y:n.bottom}];let i=[[{x:n.left,y:n.top},{x:n.right,y:n.top}],[{x:n.right,y:n.top},{x:n.right,y:n.bottom}],[{x:n.left,y:n.bottom},{x:n.right,y:n.bottom}],[{x:n.left,y:n.top},{x:n.left,y:n.bottom}]],a=([t,n])=>t.y===n.y?Math.abs(e.y-t.y):Math.abs(e.x-t.x),o=i[0],s=a(o);for(let e=1;e<i.length;e++){let t=i[e],n=a(t);n<s&&(o=t,s=n)}return o},Le=()=>D?q.get(D)??null:null,Re=(e,t,n)=>{if(n.width<=0||n.height<=0)return null;let r={x:e.left+e.width/2,y:e.top+e.height*.62},[i,a]=Ie(r,t,n);if(i.x===a.x){let e=Math.min(i.y,a.y),t=Math.max(i.y,a.y),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:i.x,y:e+r},a={x:a.x,y:t-r}}else{let e=Math.min(i.x,a.x),t=Math.max(i.x,a.x),n=t-e,r=n<=28?0:Math.min(10,(n-28)/2);i={x:e+r,y:i.y},a={x:t-r,y:a.y}}return{apex:r,edgeA:i,edgeB:a}},ze=()=>{if(!oe||!w||D===null)return null;let e=Le();if(!e)return null;let t=f.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),r=w.getBoundingClientRect(),i=e.content.getBoundingClientRect();return Re(n,t,r.width>0&&r.height>0?r:i)},Be=e=>{let t=ze();return t?Fe({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},Ve=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),He=e=>{if(e.length<=1)return e.slice();let t=e=>`${e.x.toFixed(3)}:${e.y.toFixed(3)}`,n=new Map;for(let r of e)n.set(t(r),r);let r=Array.from(n.values()).sort((e,t)=>e.x===t.x?e.y-t.y:e.x-t.x);if(r.length<=2)return r;let i=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),a=[];for(let e of r){for(;a.length>=2&&i(a[a.length-2],a[a.length-1],e)<=0;)a.pop();a.push(e)}let o=[];for(let e=r.length-1;e>=0;e--){let t=r[e];for(;o.length>=2&&i(o[o.length-2],o[o.length-1],t)<=0;)o.pop();o.push(t)}return a.pop(),o.pop(),a.concat(o)},Ue=e=>{if(e.length<3){Ae();return}let t=He(e);if(t.length<3){Ae();return}let n=Math.min(...t.map(e=>e.x)),r=Math.min(...t.map(e=>e.y)),i=Math.max(...t.map(e=>e.x)),a=Math.max(...t.map(e=>e.y)),o=Math.max(1,i-n),s=Math.max(1,a-r),c=e=>`${(e.x-n)/o*100}% ${(e.y-r)/s*100}%`,l=ke();l.style.display=`block`,l.style.transform=`none`,l.style.bottom=`auto`,l.style.right=`auto`,l.style.left=`${n}px`,l.style.top=`${r}px`,l.style.width=`${o}px`,l.style.height=`${s}px`,l.style.clipPath=`polygon(${t.map(c).join(`, `)})`},We=()=>{if(!x)return;let e=ze();if(!e){Me();return}Ne(e)},Ge=e=>{if(!e)return!1;if(Le()?.content.contains(e)||w?.contains(e)||X?.contains(e))return!0;let t=U?.container;return!!(t instanceof HTMLElement&&t.contains(e))};z.push(Z),z.push(De),z.push(Ae),z.push(()=>{Me(),I?.parentElement&&I.parentElement.removeChild(I),I=null});let Ke=(t,n,r)=>{w&&requestAnimationFrame(()=>{let i=t.firstElementChild,a=t.lastElementChild,o=i?getComputedStyle(i):null,s=a?getComputedStyle(a):null,c=o&&parseFloat(o.marginTop)||0,l=s&&parseFloat(s.marginBottom)||0,u=(...e)=>{let t=0;for(let n of e)Number.isFinite(n)&&(t=Math.max(t,n));return t},d=t.getBoundingClientRect(),p=u(d.width,t.scrollWidth,t.offsetWidth,t.clientWidth),m=u(d.height,t.scrollHeight,t.offsetHeight,t.clientHeight)+c+l,ee={top:d.top,left:d.left,width:p,height:m,right:d.left+p,bottom:d.top+m},h=getComputedStyle(w),re=parseFloat(h.marginTop)||0;w.style.setProperty(`--viewport-width`,`${p}px`),w.style.setProperty(`--viewport-height`,`${m}px`);let g=f.getBoundingClientRect(),_=n.getBoundingClientRect(),v=e({anchorRect:_,contentRect:ee,side:r.side,align:r.align,sideOffset:r.sideOffset,alignOffset:r.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:te}),y=v.x-g.left,b=v.y-g.top;de=y,fe=b;let ie=ne(v.side,v.align,_),ae=ie.x-(g.left+y),x=ie.y-(g.top+b),se=ie.x-g.left,ce=ie.y-g.top,S=`${ae}px ${x}px`,le=`${se}px ${ce}px`;w.style.top=`0px`,w.style.left=`0px`,w.style.willChange=`transform,width,height`,w.style.setProperty(`--transform-origin`,S),t.style.top=`0px`,t.style.left=`0px`,t.style.setProperty(`--transform-origin`,S),w.setAttribute(`data-side`,v.side),w.setAttribute(`data-align`,v.align),t.setAttribute(`data-side`,v.side),t.setAttribute(`data-align`,v.align);let C=U?.container;C&&C!==w&&(C.setAttribute(`data-side`,v.side),C.setAttribute(`data-align`,v.align),C.style.setProperty(`--transform-origin`,le)),xe();let T=w.getBoundingClientRect(),E=[],D=Math.max(0,T.top-g.bottom),O=Math.max(0,g.top-T.bottom),k=Math.max(0,T.left-g.right),A=Math.max(0,g.left-T.right),j=Math.max(0,c+re),M=Math.max(D,O,j),N=Math.max(k,A),P=oe?Re(_,g,T):null,F=(e,t,n,r)=>{n<=0||r<=0||E.push({x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r})};if(M>=N&&M>0){let e=Math.max(D,O,j),t=y,n=O>D&&O>=j?b+m:b-e,r=p;if(P){let e=Math.min(P.edgeA.x,P.edgeB.x)-g.left,n=Math.max(P.edgeA.x,P.edgeB.x)-g.left;t=e-8,r=n-e+16}F(t,n,r,e)}else if(N>0){let e=Math.max(k,A),t=b,n=A>k?y+p:y-e,r=m;if(P){let e=Math.min(P.edgeA.y,P.edgeB.y)-g.top,n=Math.max(P.edgeA.y,P.edgeB.y)-g.top;t=e-8,r=n-e+16}F(n,t,e,r)}if(P){let e=Ve(P.apex,g),t=Ve(P.edgeA,g),n=Ve(P.edgeB,g);E.push(e,t,n)}Ue(E),We()})},qe=e=>k===-1||e>k?`right`:`left`,Q=e=>{if(!T)return;if(M=e,!e){De(),T.removeAttribute(`data-instant`),T.setAttribute(`data-state`,`hidden`);return}T.getAttribute(`data-state`)!==`visible`&&(De(),T.setAttribute(`data-instant`,``),L=requestAnimationFrame(()=>{L=requestAnimationFrame(()=>{T.removeAttribute(`data-instant`),L=null})}));let t=le.getBoundingClientRect(),n=e.getBoundingClientRect();T.style.setProperty(`--indicator-left`,`${n.left-t.left}px`),T.style.setProperty(`--indicator-width`,`${n.width}px`),T.style.setProperty(`--indicator-top`,`${n.top-t.top}px`);let r=(w&&parseFloat(getComputedStyle(w).marginTop)||0)<1?1:0;T.style.setProperty(`--indicator-height`,`${n.height-r}px`),T.setAttribute(`data-state`,`visible`)},$=(e,n=!1)=>{if(Z(),e===D){Y();return}if(e!==null&&e===O){Y();return}Y(),O=e===null?null:e;let r=()=>{let n=D,r=e?q.get(e):null,i=n!==null&&e!==null&&n!==e,o=i&&r?qe(r.index):null,s=document.activeElement;if(e===null&&s&&t(f,s)){let e=n?q.get(n)?.trigger:null;e&&e.focus()}if(q.forEach(({trigger:t,content:r,item:i},a)=>{let s=a===e,c=a===n;if(m(t,`expanded`,s),t.setAttribute(`data-state`,s?`open`:`closed`),s||c&&e===null?t.tabIndex=0:t.tabIndex=-1,i.setAttribute(`data-state`,s?`open`:`closed`),!s){let e=B.get(r);if(r.setAttribute(`data-state`,`inactive`),r.setAttribute(`aria-hidden`,`true`),S(r,!0),r.style.pointerEvents=`none`,c&&o){let e=o===`right`?`to-left`:`to-right`;r.setAttribute(`data-motion`,e)}else c&&r.removeAttribute(`data-motion`);c?e?.exit():e?.isExiting||(r.removeAttribute(`data-motion`),be(r),r.hidden=!0)}}),r){if(U?.mount(),w&&(w.hidden=!1),n===null&&ve?.enter(),ye(r.content),B.get(r.content)?.enter(),o){let e=o===`right`?`from-right`:`from-left`;r.content.setAttribute(`data-motion`,e)}else r.content.removeAttribute(`data-motion`);r.content.setAttribute(`data-state`,`active`),r.content.removeAttribute(`aria-hidden`),S(r.content,!1),r.content.hidden=!1,r.content.style.pointerEvents=`auto`,k=r.index;let e=Ce(r.item,r.content);Ke(r.content,r.trigger,e),Se(r),Q(r.trigger)}else Ae(),Z(),ve?.exit(),Se(null);let c=e!==null;if(f.setAttribute(`data-state`,c?`open`:`closed`),o?f.setAttribute(`data-motion`,o===`right`?`from-right`:`from-left`):f.removeAttribute(`data-motion`),w){w.setAttribute(`data-state`,c?`open`:`closed`),w.style.pointerEvents=c?`auto`:`none`;let e=U?.container;c&&!i?(w.setAttribute(`data-instant`,``),e?.setAttribute(`data-instant`,``),_e()):i?(W(),G()):c||(W(),G()),o&&w.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)}D=e,O=null,e===null&&Q(null),We(),a(f,`navigation-menu:change`,{value:e}),se?.(e)};n?r():e!==null&&D===null?A=setTimeout(r,re):e!==null&&D!==null?r():j=setTimeout(r,g)};f.setAttribute(`data-state`,`closed`),w&&(w.setAttribute(`data-state`,`closed`),w.hidden=!0,w.style.pointerEvents=`none`),T&&T.setAttribute(`data-state`,`hidden`),q.forEach(({trigger:e,content:t,item:n})=>{e.tagName===`BUTTON`&&!e.hasAttribute(`type`)&&(e.type=`button`),m(e,`expanded`,!1),e.setAttribute(`data-state`,`closed`),e.tabIndex=e===J[0]?0:-1,n.setAttribute(`data-state`,`closed`),t.setAttribute(`data-state`,`inactive`),t.setAttribute(`aria-hidden`,`true`),t.tabIndex=-1,S(t,!0),t.hidden=!0,t.style.pointerEvents=`none`}),q.forEach(({item:e,trigger:n},r)=>{z.push(p(n,`pointerenter`,e=>{if(!N){if(D!==r&&Be(e))return;Q(n)}})),z.push(p(e,`pointerenter`,e=>{if(!N){if(D!==r&&Be(e))return;$(r)}})),z.push(p(e,`pointerleave`,e=>{if(O===r&&D===null&&(Y(),O=null),D===r&&!N){let n=e.relatedTarget;if(Ge(n))return;(!n||!t(f,n))&&($(null),Q(null))}})),z.push(p(n,`focus`,()=>{P||(_&&$(r,!0),Q(n))})),z.push(p(n,`pointerdown`,()=>{P=!0})),z.push(p(n,`click`,()=>{Y(),D===r&&N?(N=!1,$(null,!0),Q(null)):D===r&&!N?(N=!0,Q(n)):(N=!0,$(r,!0),Q(n)),P=!1}))}),z.push(p(f,`pointerenter`,()=>{F=!0}),p(f,`pointerleave`,e=>{let t=e.relatedTarget;if(!Ge(t)&&(F=!1,!N)){if(Be(e)){Y();return}$(null),Q(null)}}),p(f,`pointerdown`,()=>{Z(),Y()})),w&&z.push(p(w,`pointerenter`,()=>{Z(),Y()}),p(w,`transitionend`,e=>{if(e.target!==w)return;let t=D?q.get(D):null;if(t){let e=Ce(t.item,t.content);Ke(t.content,t.trigger,e)}})),q.forEach(({content:e})=>{z.push(p(e,`pointerenter`,()=>{Z(),Y()}),p(e,`pointerleave`,e=>{if(N)return;let n=e.relatedTarget;Ge(n)||t(f,n)||($(null),Q(null))}))}),z.push(p(le,`keydown`,e=>{let t=e.target,n=J.indexOf(t);if(n===-1)return;let r=Te.get(t)??null,i=n;switch(e.key){case`ArrowLeft`:i=n-1,i<0&&(i=J.length-1);break;case`ArrowRight`:i=n+1,i>=J.length&&(i=0);break;case`ArrowDown`:e.preventDefault(),r&&(N=!0,$(r,!0),requestAnimationFrame(()=>{let e=q.get(r);if(!e)return;let t=Ee(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=J.length-1;break;case`Escape`:N=!1,$(null,!0),Q(null);return;default:return}e.preventDefault();let a=J[i];a&&(J.forEach(e=>e.tabIndex=e===a?0:-1),a.focus(),Q(a))})),q.forEach(({content:e,trigger:t})=>{z.push(p(e,`keydown`,n=>{let r=n.target,i=Ee(e),a=i.indexOf(r);if(a!==-1)switch(n.key){case`ArrowDown`:case`ArrowRight`:{n.preventDefault();let e=a+1;e<i.length&&i[e]?.focus();break}case`ArrowUp`:case`ArrowLeft`:n.preventDefault(),a===0?t.focus():i[a-1]?.focus();break;case`Escape`:n.preventDefault(),N=!1,$(null,!0),Q(null),t.focus();break}}))});let Je=()=>t(f,document.activeElement)||F||N,Ye=()=>{Z(),N=!1,$(null,!0),Q(null),We()};return z.push(p(document,`pointerup`,()=>{P=!1},{capture:!0}),p(document,`pointercancel`,()=>{P=!1},{capture:!0})),z.push(p(document,`focusin`,e=>{D!==null&&(t(f,e.target)||Ye())})),z.push(n({root:f,isOpen:()=>D!==null&&Je(),onDismiss:Ye,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:e=>!!e&&t(f,e)})),z.push(p(window,`resize`,()=>{D&&requestAnimationFrame(()=>xe()),M&&requestAnimationFrame(()=>Q(M))}),p(le,`scroll`,()=>{M&&requestAnimationFrame(()=>Q(M))})),z.push(p(f,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)Ye();else if(q.has(t.value)){N=!0,$(t.value,!0);let e=q.get(t.value);e&&Q(e.trigger)}}})),{get value(){return D},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{ue=!0,Y(),z.forEach(e=>e()),z.length=0}}}const g=new WeakSet;function _(e=document){let t=[];for(let n of f(e,`navigation-menu`))g.has(n)||(g.add(n),t.push(re(n)));return t}export{_ as create,re as createNavigationMenu};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/navigation-menu",
3
- "version": "0.2.68",
3
+ "version": "0.2.70",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -39,6 +39,6 @@
39
39
  ],
40
40
  "license": "MIT",
41
41
  "dependencies": {
42
- "@data-slot/core": "0.2.68"
42
+ "@data-slot/core": "0.2.70"
43
43
  }
44
44
  }