@data-slot/navigation-menu 0.2.62 → 0.2.64
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
|
@@ -76,6 +76,7 @@ const menu = createNavigationMenu(element, {
|
|
|
76
76
|
| `align` | `"start" \| "center" \| "end"` | `"start"` | Viewport alignment on cross-axis |
|
|
77
77
|
| `sideOffset` | `number` | `0` | Distance from trigger to viewport (px) |
|
|
78
78
|
| `alignOffset` | `number` | `0` | Cross-axis alignment offset (px) |
|
|
79
|
+
| `safeTriangle` | `boolean` | `false` | Enable hover safe-triangle switching guard |
|
|
79
80
|
| `onValueChange` | `(value: string \| null) => void` | `undefined` | Callback when active item changes |
|
|
80
81
|
| `debugSafeTriangle` | `boolean` | `false` | Show red hover safe-triangle debug overlay |
|
|
81
82
|
|
|
@@ -92,6 +93,7 @@ Options can also be set via data attributes on the root element. JS options take
|
|
|
92
93
|
| `data-align` | string | `"start"` | Viewport alignment: `"start"`, `"center"`, or `"end"` |
|
|
93
94
|
| `data-side-offset` | number | `0` | Distance from trigger to viewport (px) |
|
|
94
95
|
| `data-align-offset` | number | `0` | Cross-axis alignment offset (px) |
|
|
96
|
+
| `data-safe-triangle` | boolean | `false` | Enable hover safe-triangle switching guard |
|
|
95
97
|
| `data-debug-safe-triangle` | boolean | `false` | Show red hover safe-triangle debug overlay |
|
|
96
98
|
|
|
97
99
|
Boolean attributes: present or `"true"` = true, `"false"` = false, absent = default.
|
|
@@ -18,6 +18,8 @@ interface NavigationMenuOptions {
|
|
|
18
18
|
sideOffset?: number;
|
|
19
19
|
/** Offset along alignment axis (px) */
|
|
20
20
|
alignOffset?: number;
|
|
21
|
+
/** Enable hover safe-triangle behavior (opt-in) */
|
|
22
|
+
safeTriangle?: boolean;
|
|
21
23
|
/** Callback when active item changes */
|
|
22
24
|
onValueChange?: (value: string | null) => void;
|
|
23
25
|
/** Debug hover safe-triangle polygon */
|
|
@@ -18,6 +18,8 @@ interface NavigationMenuOptions {
|
|
|
18
18
|
sideOffset?: number;
|
|
19
19
|
/** Offset along alignment axis (px) */
|
|
20
20
|
alignOffset?: number;
|
|
21
|
+
/** Enable hover safe-triangle behavior (opt-in) */
|
|
22
|
+
safeTriangle?: boolean;
|
|
21
23
|
/** Callback when active item changes */
|
|
22
24
|
onValueChange?: (value: string | null) => void;
|
|
23
25
|
/** Debug hover safe-triangle polygon */
|
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`];function r(r,i={}){let a=i.delayOpen??(0,e.getDataNumber)(r,`delayOpen`)??200,o=i.delayClose??(0,e.getDataNumber)(r,`delayClose`)??150,s=i.openOnFocus??(0,e.getDataBool)(r,`openOnFocus`)??!0,c=i.side??(0,e.getDataEnum)(r,`side`,n)??`bottom`,l=i.align??(0,e.getDataEnum)(r,`align`,t)??`start`,u=i.sideOffset??(0,e.getDataNumber)(r,`sideOffset`)??0,d=i.alignOffset??(0,e.getDataNumber)(r,`alignOffset`)??0,f=i.debugSafeTriangle??(0,e.getDataBool)(r,`debugSafeTriangle`)??!1,p=i.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`),ee=(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||ee.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=[],M=new Map,N=new Map,P=_?y(_,`navigation-menu-viewport-positioner`):null,F=_?y(_,`navigation-menu-positioner`):null,I=P??F,te=I?y(I,`navigation-menu-portal`):null,L=_?(0,e.createPortalLifecycle)({content:_,root:r,enabled:!0,wrapperSlot:I?void 0:`navigation-menu-viewport-positioner`,container:I??void 0,mountTarget:I?te??I:void 0}):null,R=_?(0,e.createPresenceLifecycle)({element:_,onExitComplete:()=>{k||(L?.restore(),_.hidden=!0,_.style.pointerEvents=`none`)}}):null,ne=e=>{if(!_)return;let t=N.get(e)??{originalParent:null,originalNextSibling:null,mountedInViewport:!1};t.mountedInViewport||(t.originalParent=e.parentNode,t.originalNextSibling=e.nextSibling,t.mountedInViewport=!0,N.set(e,t)),e.parentNode!==_&&_.appendChild(e)},z=e=>{let t=N.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},re=()=>{if(!_||!L)return;let e=L.container,t=r.ownerDocument.defaultView??window,n=r.getBoundingClientRect();e.style.position=`absolute`,e.style.top=`0px`,e.style.left=`0px`,e.style.transform=`translate3d(${n.left+t.scrollX}px, ${n.top+t.scrollY}px, 0)`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`transform`,e.style.pointerEvents=`none`},B=null,ie=e=>{B?.disconnect(),B=null,!(!_||!e)&&(B=new ResizeObserver(()=>{let t=H(e.item,e.content);xe(e.content,e.trigger,t)}),B.observe(e.content))};j.push(()=>B?.disconnect()),j.push(()=>{M.forEach(e=>e.cleanup()),M.clear(),N.forEach((e,t)=>{z(t),t.hidden=!0,t.style.pointerEvents=`none`}),N.clear(),R?.cleanup(),L?.cleanup()});let V=new Map,H=(r,a)=>({side:i.side??(0,e.getDataEnum)(a,`side`,n)??(0,e.getDataEnum)(r,`side`,n)??c,align:i.align??(0,e.getDataEnum)(a,`align`,t)??(0,e.getDataEnum)(r,`align`,t)??l,sideOffset:i.sideOffset??(0,e.getDataNumber)(a,`sideOffset`)??(0,e.getDataNumber)(r,`sideOffset`)??u,alignOffset:i.alignOffset??(0,e.getDataNumber)(a,`alignOffset`)??(0,e.getDataNumber)(r,`alignOffset`)??d}),ae=0;ee.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){V.set(n,{item:t,trigger:r,content:i,index:ae++}),M.set(i,(0,e.createPresenceLifecycle)({element:i,onExitComplete:()=>{k||(z(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 U=Array.from(V.values()).map(e=>e.trigger),oe=new Map;for(let[e,t]of V)oe.set(t.trigger,e);let se=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),W=()=>{C&&=(clearTimeout(C),null),w&&=(clearTimeout(w),null)},G=null,ce=()=>{if(!_)return null;let e=L?.container;return e instanceof HTMLElement?e:_.parentElement instanceof HTMLElement?_.parentElement:_},le=()=>{let t=ce();return G||(G=document.createElement(`div`),G.setAttribute(`data-slot`,`navigation-menu-bridge`),G.style.cssText=`position: absolute; pointer-events: auto; z-index: 0; display: none;`,j.push((0,e.on)(G,`pointerenter`,()=>{W()}),(0,e.on)(G,`pointerleave`,t=>{if(E||b===null)return;let n=t.relatedTarget;Z(n)||n&&(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))),t&&G.parentElement!==t&&t.insertBefore(G,t.firstChild),G},K=()=>{G&&(G.style.height=`0`,G.style.width=`0`,G.style.top=`0px`,G.style.left=`0px`,G.style.right=`0px`,G.style.bottom=`auto`,G.style.transform=`none`,G.style.clipPath=`none`,G.style.display=`none`)},ue=()=>{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},q=()=>{A&&(A.style.width=`0`,A.style.height=`0`,A.style.clipPath=`none`,A.style.display=`none`)},J=()=>{f||q()},de=e=>{let t=ue();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)})`},Y=(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=Y(e,t,n),a=Y(e,n,r),o=Y(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},pe=(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=()=>b?V.get(b)??null:null,he=(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]=pe(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}},ge=()=>{if(!_||b===null)return null;let e=me();if(!e)return null;let t=r.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),i=_.getBoundingClientRect(),a=e.content.getBoundingClientRect();return he(n,t,i.width>0&&i.height>0?i:a)},X=e=>{let t=ge();return t?fe({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},_e=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),ve=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)},ye=e=>{if(e.length<3){K();return}let t=ve(e);if(t.length<3){K();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=le();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(`, `)})`},be=()=>{if(!f)return;let e=ge();if(!e){q();return}de(e)},Z=e=>{if(!e)return!1;if(me()?.content.contains(e)||_?.contains(e)||G?.contains(e))return!0;let t=L?.container;return!!(t instanceof HTMLElement&&t.contains(e))};j.push(J),j.push(K),j.push(()=>{q(),A?.parentElement&&A.parentElement.removeChild(A),A=null});let xe=(t,i,a)=>{_&&requestAnimationFrame(()=>{let o=t.firstElementChild,s=t.lastElementChild,c=o?getComputedStyle(o):null,l=s?getComputedStyle(s):null,u=c&&parseFloat(c.marginTop)||0,d=l&&parseFloat(l.marginBottom)||0,f=(...e)=>{let t=0;for(let n of e)Number.isFinite(n)&&(t=Math.max(t,n));return t},p=t.getBoundingClientRect(),m=f(p.width,t.scrollWidth,t.offsetWidth,t.clientWidth),h=f(p.height,t.scrollHeight,t.offsetHeight,t.clientHeight)+u+d,g={top:p.top,left:p.left,width:m,height:h,right:p.left+m,bottom:p.top+h},ee=getComputedStyle(_),v=parseFloat(ee.marginTop)||0;_.style.setProperty(`--viewport-width`,`${m}px`),_.style.setProperty(`--viewport-height`,`${h}px`);let y=r.getBoundingClientRect(),b=i.getBoundingClientRect(),x=(0,e.computeFloatingPosition)({anchorRect:b,contentRect:g,side:a.side,align:a.align,sideOffset:a.sideOffset,alignOffset:a.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:n}),S=x.x-y.left,C=x.y-y.top;_.style.top=`0px`,_.style.left=`0px`,_.style.transform=`translate3d(${S}px, ${C}px, 0)`,_.style.willChange=`transform,width,height`,t.style.top=`0px`,t.style.left=`0px`,_.setAttribute(`data-side`,x.side),_.setAttribute(`data-align`,x.align),t.setAttribute(`data-side`,x.side),t.setAttribute(`data-align`,x.align);let w=L?.container;w&&w!==_&&(w.setAttribute(`data-side`,x.side),w.setAttribute(`data-align`,x.align)),re();let T=_.getBoundingClientRect(),E=[],D=Math.max(0,T.top-y.bottom),O=Math.max(0,y.top-T.bottom),k=Math.max(0,T.left-y.right),A=Math.max(0,y.left-T.right),j=Math.max(0,u+v),M=Math.max(D,O,j),N=Math.max(k,A),P=he(b,y,T),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=S,n=O>D&&O>=j?C+h:C-e,r=m;if(P){let e=Math.min(P.edgeA.x,P.edgeB.x)-y.left,n=Math.max(P.edgeA.x,P.edgeB.x)-y.left;t=e-8,r=n-e+16}F(t,n,r,e)}else if(N>0){let e=Math.max(k,A),t=C,n=A>k?S+m:S-e,r=h;if(P){let e=Math.min(P.edgeA.y,P.edgeB.y)-y.top,n=Math.max(P.edgeA.y,P.edgeB.y)-y.top;t=e-8,r=n-e+16}F(n,t,e,r)}if(P){let e=_e(P.apex,y),t=_e(P.edgeA,y),n=_e(P.edgeB,y);E.push(e,t,n)}ye(E),be()})},Se=e=>S===-1||e>S?`right`:`left`,Q=e=>{if(!v)return;if(T=e,!e){v.setAttribute(`data-state`,`hidden`);return}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(J(),t===b){W();return}if(t!==null&&t===x){W();return}W(),x=t===null?null:t;let i=()=>{let n=b,i=t?V.get(t):null,a=n!==null&&t!==null&&n!==t,o=a&&i?Se(i.index):null,s=document.activeElement;if(t===null&&s&&(0,e.containsWithPortals)(r,s)){let e=n?V.get(n)?.trigger:null;e&&e.focus()}if(V.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=M.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`),z(i),i.hidden=!0)}}),i){if(L?.mount(),_&&(_.hidden=!1),n===null&&R?.enter(),ne(i.content),M.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=H(i.item,i.content);xe(i.content,i.trigger,e),ie(i),Q(i.trigger)}else K(),J(),R?.exit(),ie(null);let c=t!==null;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`,c&&!a?_.setAttribute(`data-instant`,``):a&&_.removeAttribute(`data-instant`),o&&_.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)),b=t,x=null,t===null&&Q(null),be(),(0,e.emit)(r,`navigation-menu:change`,{value:t}),p?.(t)};n?i():t!==null&&b===null?C=setTimeout(i,a):t!==null&&b!==null?i():w=setTimeout(i,o)};r.setAttribute(`data-state`,`closed`),_&&(_.setAttribute(`data-state`,`closed`),_.hidden=!0,_.style.pointerEvents=`none`),v&&v.setAttribute(`data-state`,`hidden`),V.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===U[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`}),V.forEach(({item:t,trigger:n},i)=>{j.push((0,e.on)(n,`pointerenter`,e=>{if(!E){if(b!==i&&X(e))return;Q(n)}})),j.push((0,e.on)(t,`pointerenter`,e=>{if(!E){if(b!==i&&X(e))return;$(i)}})),j.push((0,e.on)(t,`pointerleave`,t=>{if(x===i&&b===null&&(W(),x=null),b===i&&!E){let n=t.relatedTarget;if(Z(n))return;(!n||!(0,e.containsWithPortals)(r,n))&&($(null),Q(null))}})),j.push((0,e.on)(n,`focus`,()=>{D||(s&&$(i,!0),Q(n))})),j.push((0,e.on)(n,`pointerdown`,()=>{D=!0})),j.push((0,e.on)(n,`click`,()=>{W(),b===i&&E?(E=!1,$(null,!0),Q(null)):b===i&&!E?(E=!0,Q(n)):(E=!0,$(i,!0),Q(n)),D=!1}))}),j.push((0,e.on)(r,`pointerenter`,()=>{O=!0}),(0,e.on)(r,`pointerleave`,e=>{let t=e.relatedTarget;if(!Z(t)&&(O=!1,!E)){if(X(e)){W();return}$(null),Q(null)}}),(0,e.on)(r,`pointerdown`,()=>{J(),W()})),_&&j.push((0,e.on)(_,`pointerenter`,()=>{J(),W()}),(0,e.on)(_,`transitionend`,e=>{if(e.target!==_)return;let t=b?V.get(b):null;if(t){let e=H(t.item,t.content);xe(t.content,t.trigger,e)}})),V.forEach(({content:t})=>{j.push((0,e.on)(t,`pointerenter`,()=>{J(),W()}),(0,e.on)(t,`pointerleave`,t=>{if(E)return;let n=t.relatedTarget;Z(n)||(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))}),j.push((0,e.on)(g,`keydown`,e=>{let t=e.target,n=U.indexOf(t);if(n===-1)return;let r=oe.get(t)??null,i=n;switch(e.key){case`ArrowLeft`:i=n-1,i<0&&(i=U.length-1);break;case`ArrowRight`:i=n+1,i>=U.length&&(i=0);break;case`ArrowDown`:e.preventDefault(),r&&(E=!0,$(r,!0),requestAnimationFrame(()=>{let e=V.get(r);if(!e)return;let t=se(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=U.length-1;break;case`Escape`:E=!1,$(null,!0),Q(null);return;default:return}e.preventDefault();let a=U[i];a&&(U.forEach(e=>e.tabIndex=e===a?0:-1),a.focus(),Q(a))})),V.forEach(({content:t,trigger:n})=>{j.push((0,e.on)(t,`keydown`,e=>{let r=e.target,i=se(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 Ce=()=>(0,e.containsWithPortals)(r,document.activeElement)||O||E,we=()=>{J(),E=!1,$(null,!0),Q(null),be()};return j.push((0,e.on)(document,`pointerup`,()=>{D=!1},{capture:!0}),(0,e.on)(document,`pointercancel`,()=>{D=!1},{capture:!0})),j.push((0,e.on)(document,`focusin`,t=>{b!==null&&((0,e.containsWithPortals)(r,t.target)||we())})),j.push((0,e.createDismissLayer)({root:r,isOpen:()=>b!==null&&Ce(),onDismiss:we,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:t=>!!t&&(0,e.containsWithPortals)(r,t)})),j.push((0,e.on)(window,`resize`,()=>{b&&requestAnimationFrame(()=>re()),T&&requestAnimationFrame(()=>Q(T))}),(0,e.on)(g,`scroll`,()=>{T&&requestAnimationFrame(()=>Q(T))})),j.push((0,e.on)(r,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)we();else if(V.has(t.value)){E=!0,$(t.value,!0);let e=V.get(t.value);e&&Q(e.trigger)}}})),{get value(){return b},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{k=!0,W(),j.forEach(e=>e()),j.length=0}}}const i=new WeakSet;function a(t=document){let n=[];for(let a of(0,e.getRoots)(t,`navigation-menu`))i.has(a)||(i.add(a),n.push(r(a)));return n}exports.create=a,exports.createNavigationMenu=r;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=[`start`,`center`,`end`],n=[`top`,`right`,`bottom`,`left`];function r(r,i={}){let a=i.delayOpen??(0,e.getDataNumber)(r,`delayOpen`)??200,o=i.delayClose??(0,e.getDataNumber)(r,`delayClose`)??150,s=i.openOnFocus??(0,e.getDataBool)(r,`openOnFocus`)??!0,c=i.side??(0,e.getDataEnum)(r,`side`,n)??`bottom`,l=i.align??(0,e.getDataEnum)(r,`align`,t)??`start`,u=i.sideOffset??(0,e.getDataNumber)(r,`sideOffset`)??0,d=i.alignOffset??(0,e.getDataNumber)(r,`alignOffset`)??0,f=i.safeTriangle??(0,e.getDataBool)(r,`safeTriangle`)??!1,p=i.debugSafeTriangle??(0,e.getDataBool)(r,`debugSafeTriangle`)??!1,m=f||p,h=i.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`),y=(0,e.getParts)(r,`navigation-menu-item`),b=(0,e.getPart)(r,`navigation-menu-viewport`),x=(0,e.getPart)(r,`navigation-menu-indicator`),S=(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||y.length===0)throw Error(`NavigationMenu requires navigation-menu-list and at least one navigation-menu-item`);let C=null,w=null,T=-1,E=null,D=null,O=null,k=!1,A=!1,j=!1,M=!1,N=null,P=null,F=[],I=new Map,L=new Map,ee=b?S(b,`navigation-menu-viewport-positioner`):null,te=b?S(b,`navigation-menu-positioner`):null,R=ee??te,ne=R?S(R,`navigation-menu-portal`):null,z=b?(0,e.createPortalLifecycle)({content:b,root:r,enabled:!0,wrapperSlot:R?void 0:`navigation-menu-viewport-positioner`,container:R??void 0,mountTarget:R?ne??R:void 0}):null,B=b?(0,e.createPresenceLifecycle)({element:b,onExitComplete:()=>{M||(z?.restore(),b.hidden=!0,b.style.pointerEvents=`none`)}}):null,re=e=>{if(!b)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!==b&&b.appendChild(e)},ie=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},ae=()=>{if(!b||!z)return;let e=z.container,t=r.ownerDocument.defaultView??window,n=r.getBoundingClientRect();e.style.position=`absolute`,e.style.top=`0px`,e.style.left=`0px`,e.style.transform=`translate3d(${n.left+t.scrollX}px, ${n.top+t.scrollY}px, 0)`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`transform`,e.style.pointerEvents=`none`},V=null,oe=e=>{V?.disconnect(),V=null,!(!b||!e)&&(V=new ResizeObserver(()=>{let t=U(e.item,e.content);Te(e.content,e.trigger,t)}),V.observe(e.content))};F.push(()=>V?.disconnect()),F.push(()=>{I.forEach(e=>e.cleanup()),I.clear(),L.forEach((e,t)=>{ie(t),t.hidden=!0,t.style.pointerEvents=`none`}),L.clear(),B?.cleanup(),z?.cleanup()});let H=new Map,U=(r,a)=>({side:i.side??(0,e.getDataEnum)(a,`side`,n)??(0,e.getDataEnum)(r,`side`,n)??c,align:i.align??(0,e.getDataEnum)(a,`align`,t)??(0,e.getDataEnum)(r,`align`,t)??l,sideOffset:i.sideOffset??(0,e.getDataNumber)(a,`sideOffset`)??(0,e.getDataNumber)(r,`sideOffset`)??u,alignOffset:i.alignOffset??(0,e.getDataNumber)(a,`alignOffset`)??(0,e.getDataNumber)(r,`alignOffset`)??d}),se=0;y.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){H.set(n,{item:t,trigger:r,content:i,index:se++}),I.set(i,(0,e.createPresenceLifecycle)({element:i,onExitComplete:()=>{M||(ie(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 W=Array.from(H.values()).map(e=>e.trigger),ce=new Map;for(let[e,t]of H)ce.set(t.trigger,e);let le=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),G=()=>{E&&=(clearTimeout(E),null),D&&=(clearTimeout(D),null)},K=()=>{P!==null&&(cancelAnimationFrame(P),P=null)},q=null,ue=()=>{if(!b)return null;let e=z?.container;return e instanceof HTMLElement?e:b.parentElement instanceof HTMLElement?b.parentElement:b},de=()=>{let t=ue();return q||(q=document.createElement(`div`),q.setAttribute(`data-slot`,`navigation-menu-bridge`),q.style.cssText=`position: absolute; pointer-events: auto; z-index: 0; display: none;`,F.push((0,e.on)(q,`pointerenter`,()=>{G()}),(0,e.on)(q,`pointerleave`,t=>{if(k||C===null)return;let n=t.relatedTarget;Z(n)||n&&(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))),t&&q.parentElement!==t&&t.insertBefore(q,t.firstChild),q},J=()=>{q&&(q.style.height=`0`,q.style.width=`0`,q.style.top=`0px`,q.style.left=`0px`,q.style.right=`0px`,q.style.bottom=`auto`,q.style.transform=`none`,q.style.clipPath=`none`,q.style.display=`none`)},fe=()=>{if(!p)return null;let e=r.ownerDocument.body;return e?(N||(N=r.ownerDocument.createElement(`div`),N.setAttribute(`data-slot`,`navigation-menu-safe-triangle`),N.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(`; `)),N.parentElement!==e&&e.appendChild(N),N):null},Y=()=>{N&&(N.style.width=`0`,N.style.height=`0`,N.style.clipPath=`none`,N.style.display=`none`)},X=()=>{p||Y()},pe=e=>{let t=fe();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)})`},me=(e,t,n)=>(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y),he=(e,t,n,r)=>{let i=me(e,t,n),a=me(e,n,r),o=me(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},ge=(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},_e=()=>C?H.get(C)??null:null,ve=(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]=ge(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}},ye=()=>{if(!m||!b||C===null)return null;let e=_e();if(!e)return null;let t=r.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),i=b.getBoundingClientRect(),a=e.content.getBoundingClientRect();return ve(n,t,i.width>0&&i.height>0?i:a)},be=e=>{let t=ye();return t?he({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},xe=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),Se=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)},Ce=e=>{if(e.length<3){J();return}let t=Se(e);if(t.length<3){J();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=de();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(!p)return;let e=ye();if(!e){Y();return}pe(e)},Z=e=>{if(!e)return!1;if(_e()?.content.contains(e)||b?.contains(e)||q?.contains(e))return!0;let t=z?.container;return!!(t instanceof HTMLElement&&t.contains(e))};F.push(X),F.push(K),F.push(J),F.push(()=>{Y(),N?.parentElement&&N.parentElement.removeChild(N),N=null});let Te=(t,i,a)=>{b&&requestAnimationFrame(()=>{let o=t.firstElementChild,s=t.lastElementChild,c=o?getComputedStyle(o):null,l=s?getComputedStyle(s):null,u=c&&parseFloat(c.marginTop)||0,d=l&&parseFloat(l.marginBottom)||0,f=(...e)=>{let t=0;for(let n of e)Number.isFinite(n)&&(t=Math.max(t,n));return t},p=t.getBoundingClientRect(),h=f(p.width,t.scrollWidth,t.offsetWidth,t.clientWidth),g=f(p.height,t.scrollHeight,t.offsetHeight,t.clientHeight)+u+d,_={top:p.top,left:p.left,width:h,height:g,right:p.left+h,bottom:p.top+g},v=getComputedStyle(b),y=parseFloat(v.marginTop)||0;b.style.setProperty(`--viewport-width`,`${h}px`),b.style.setProperty(`--viewport-height`,`${g}px`);let x=r.getBoundingClientRect(),S=i.getBoundingClientRect(),C=(0,e.computeFloatingPosition)({anchorRect:S,contentRect:_,side:a.side,align:a.align,sideOffset:a.sideOffset,alignOffset:a.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:n}),w=C.x-x.left,T=C.y-x.top;b.style.top=`0px`,b.style.left=`0px`,b.style.transform=`translate3d(${w}px, ${T}px, 0)`,b.style.willChange=`transform,width,height`,t.style.top=`0px`,t.style.left=`0px`,b.setAttribute(`data-side`,C.side),b.setAttribute(`data-align`,C.align),t.setAttribute(`data-side`,C.side),t.setAttribute(`data-align`,C.align);let E=z?.container;E&&E!==b&&(E.setAttribute(`data-side`,C.side),E.setAttribute(`data-align`,C.align)),ae();let D=b.getBoundingClientRect(),O=[],k=Math.max(0,D.top-x.bottom),A=Math.max(0,x.top-D.bottom),j=Math.max(0,D.left-x.right),M=Math.max(0,x.left-D.right),N=Math.max(0,u+y),P=Math.max(k,A,N),F=Math.max(j,M),I=m?ve(S,x,D):null,L=(e,t,n,r)=>{n<=0||r<=0||O.push({x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r})};if(P>=F&&P>0){let e=Math.max(k,A,N),t=w,n=A>k&&A>=N?T+g:T-e,r=h;if(I){let e=Math.min(I.edgeA.x,I.edgeB.x)-x.left,n=Math.max(I.edgeA.x,I.edgeB.x)-x.left;t=e-8,r=n-e+16}L(t,n,r,e)}else if(F>0){let e=Math.max(j,M),t=T,n=M>j?w+h:w-e,r=g;if(I){let e=Math.min(I.edgeA.y,I.edgeB.y)-x.top,n=Math.max(I.edgeA.y,I.edgeB.y)-x.top;t=e-8,r=n-e+16}L(n,t,e,r)}if(I){let e=xe(I.apex,x),t=xe(I.edgeA,x),n=xe(I.edgeB,x);O.push(e,t,n)}Ce(O),we()})},Ee=e=>T===-1||e>T?`right`:`left`,Q=e=>{if(!x)return;if(O=e,!e){K(),x.removeAttribute(`data-instant`),x.setAttribute(`data-state`,`hidden`);return}x.getAttribute(`data-state`)!==`visible`&&(K(),x.setAttribute(`data-instant`,``),P=requestAnimationFrame(()=>{P=requestAnimationFrame(()=>{x.removeAttribute(`data-instant`),P=null})}));let t=v.getBoundingClientRect(),n=e.getBoundingClientRect();x.style.setProperty(`--indicator-left`,`${n.left-t.left}px`),x.style.setProperty(`--indicator-width`,`${n.width}px`),x.style.setProperty(`--indicator-top`,`${n.top-t.top}px`);let r=(b&&parseFloat(getComputedStyle(b).marginTop)||0)<1?1:0;x.style.setProperty(`--indicator-height`,`${n.height-r}px`),x.setAttribute(`data-state`,`visible`)},$=(t,n=!1)=>{if(X(),t===C){G();return}if(t!==null&&t===w){G();return}G(),w=t===null?null:t;let i=()=>{let n=C,i=t?H.get(t):null,a=n!==null&&t!==null&&n!==t,o=a&&i?Ee(i.index):null,s=document.activeElement;if(t===null&&s&&(0,e.containsWithPortals)(r,s)){let e=n?H.get(n)?.trigger:null;e&&e.focus()}if(H.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`),_(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`),ie(i),i.hidden=!0)}}),i){if(z?.mount(),b&&(b.hidden=!1),n===null&&B?.enter(),re(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`),_(i.content,!1),i.content.hidden=!1,i.content.style.pointerEvents=`auto`,T=i.index;let e=U(i.item,i.content);Te(i.content,i.trigger,e),oe(i),Q(i.trigger)}else J(),X(),B?.exit(),oe(null);let c=t!==null;r.setAttribute(`data-state`,c?`open`:`closed`),o?r.setAttribute(`data-motion`,o===`right`?`from-right`:`from-left`):r.removeAttribute(`data-motion`),b&&(b.setAttribute(`data-state`,c?`open`:`closed`),b.style.pointerEvents=c?`auto`:`none`,c&&!a?b.setAttribute(`data-instant`,``):a&&b.removeAttribute(`data-instant`),o&&b.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)),C=t,w=null,t===null&&Q(null),we(),(0,e.emit)(r,`navigation-menu:change`,{value:t}),h?.(t)};n?i():t!==null&&C===null?E=setTimeout(i,a):t!==null&&C!==null?i():D=setTimeout(i,o)};r.setAttribute(`data-state`,`closed`),b&&(b.setAttribute(`data-state`,`closed`),b.hidden=!0,b.style.pointerEvents=`none`),x&&x.setAttribute(`data-state`,`hidden`),H.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===W[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`}),H.forEach(({item:t,trigger:n},i)=>{F.push((0,e.on)(n,`pointerenter`,e=>{if(!k){if(C!==i&&be(e))return;Q(n)}})),F.push((0,e.on)(t,`pointerenter`,e=>{if(!k){if(C!==i&&be(e))return;$(i)}})),F.push((0,e.on)(t,`pointerleave`,t=>{if(w===i&&C===null&&(G(),w=null),C===i&&!k){let n=t.relatedTarget;if(Z(n))return;(!n||!(0,e.containsWithPortals)(r,n))&&($(null),Q(null))}})),F.push((0,e.on)(n,`focus`,()=>{A||(s&&$(i,!0),Q(n))})),F.push((0,e.on)(n,`pointerdown`,()=>{A=!0})),F.push((0,e.on)(n,`click`,()=>{G(),C===i&&k?(k=!1,$(null,!0),Q(null)):C===i&&!k?(k=!0,Q(n)):(k=!0,$(i,!0),Q(n)),A=!1}))}),F.push((0,e.on)(r,`pointerenter`,()=>{j=!0}),(0,e.on)(r,`pointerleave`,e=>{let t=e.relatedTarget;if(!Z(t)&&(j=!1,!k)){if(be(e)){G();return}$(null),Q(null)}}),(0,e.on)(r,`pointerdown`,()=>{X(),G()})),b&&F.push((0,e.on)(b,`pointerenter`,()=>{X(),G()}),(0,e.on)(b,`transitionend`,e=>{if(e.target!==b)return;let t=C?H.get(C):null;if(t){let e=U(t.item,t.content);Te(t.content,t.trigger,e)}})),H.forEach(({content:t})=>{F.push((0,e.on)(t,`pointerenter`,()=>{X(),G()}),(0,e.on)(t,`pointerleave`,t=>{if(k)return;let n=t.relatedTarget;Z(n)||(0,e.containsWithPortals)(r,n)||($(null),Q(null))}))}),F.push((0,e.on)(v,`keydown`,e=>{let t=e.target,n=W.indexOf(t);if(n===-1)return;let r=ce.get(t)??null,i=n;switch(e.key){case`ArrowLeft`:i=n-1,i<0&&(i=W.length-1);break;case`ArrowRight`:i=n+1,i>=W.length&&(i=0);break;case`ArrowDown`:e.preventDefault(),r&&(k=!0,$(r,!0),requestAnimationFrame(()=>{let e=H.get(r);if(!e)return;let t=le(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=W.length-1;break;case`Escape`:k=!1,$(null,!0),Q(null);return;default:return}e.preventDefault();let a=W[i];a&&(W.forEach(e=>e.tabIndex=e===a?0:-1),a.focus(),Q(a))})),H.forEach(({content:t,trigger:n})=>{F.push((0,e.on)(t,`keydown`,e=>{let r=e.target,i=le(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(),k=!1,$(null,!0),Q(null),n.focus();break}}))});let De=()=>(0,e.containsWithPortals)(r,document.activeElement)||j||k,Oe=()=>{X(),k=!1,$(null,!0),Q(null),we()};return F.push((0,e.on)(document,`pointerup`,()=>{A=!1},{capture:!0}),(0,e.on)(document,`pointercancel`,()=>{A=!1},{capture:!0})),F.push((0,e.on)(document,`focusin`,t=>{C!==null&&((0,e.containsWithPortals)(r,t.target)||Oe())})),F.push((0,e.createDismissLayer)({root:r,isOpen:()=>C!==null&&De(),onDismiss:Oe,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:t=>!!t&&(0,e.containsWithPortals)(r,t)})),F.push((0,e.on)(window,`resize`,()=>{C&&requestAnimationFrame(()=>ae()),O&&requestAnimationFrame(()=>Q(O))}),(0,e.on)(v,`scroll`,()=>{O&&requestAnimationFrame(()=>Q(O))})),F.push((0,e.on)(r,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)Oe();else if(H.has(t.value)){k=!0,$(t.value,!0);let e=H.get(t.value);e&&Q(e.trigger)}}})),{get value(){return C},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{M=!0,G(),F.forEach(e=>e()),F.length=0}}}const i=new WeakSet;function a(t=document){let n=[];for(let a of(0,e.getRoots)(t,`navigation-menu`))i.has(a)||(i.add(a),n.push(r(a)));return n}exports.create=a,exports.createNavigationMenu=r;
|
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 h=[`start`,`center`,`end`],g=[`top`,`right`,`bottom`,`left`];function _(f,_={}){let v=_.delayOpen??l(f,`delayOpen`)??200,y=_.delayClose??l(f,`delayClose`)??150,ee=_.openOnFocus??s(f,`openOnFocus`)??!0,b=_.side??c(f,`side`,g)??`bottom`,x=_.align??c(f,`align`,h)??`start`,S=_.sideOffset??l(f,`sideOffset`)??0,C=_.alignOffset??l(f,`alignOffset`)??0,w=_.debugSafeTriangle??s(f,`debugSafeTriangle`)??!1,te=_.onValueChange,T=e=>e.replace(/[^a-z0-9\-_:.]/gi,`-`),E=(e,t)=>{`inert`in e&&(e.inert=t)},D=u(f,`navigation-menu-list`),O=d(f,`navigation-menu-item`),k=u(f,`navigation-menu-viewport`),A=u(f,`navigation-menu-indicator`),j=(e,t)=>{let n=e.parentElement;for(;n&&n!==f;){if(n.getAttribute(`data-slot`)===t)return n;n=n.parentElement}return null};if(!D||O.length===0)throw Error(`NavigationMenu requires navigation-menu-list and at least one navigation-menu-item`);let M=null,N=null,P=-1,ne=null,re=null,F=null,I=!1,L=!1,ie=!1,ae=!1,R=null,z=[],B=new Map,V=new Map,oe=k?j(k,`navigation-menu-viewport-positioner`):null,se=k?j(k,`navigation-menu-positioner`):null,H=oe??se,ce=H?j(H,`navigation-menu-portal`):null,U=k?r({content:k,root:f,enabled:!0,wrapperSlot:H?void 0:`navigation-menu-viewport-positioner`,container:H??void 0,mountTarget:H?ce??H:void 0}):null,le=k?i({element:k,onExitComplete:()=>{ae||(U?.restore(),k.hidden=!0,k.style.pointerEvents=`none`)}}):null,ue=e=>{if(!k)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!==k&&k.appendChild(e)},de=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},fe=()=>{if(!k||!U)return;let e=U.container,t=f.ownerDocument.defaultView??window,n=f.getBoundingClientRect();e.style.position=`absolute`,e.style.top=`0px`,e.style.left=`0px`,e.style.transform=`translate3d(${n.left+t.scrollX}px, ${n.top+t.scrollY}px, 0)`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`transform`,e.style.pointerEvents=`none`},W=null,pe=e=>{W?.disconnect(),W=null,!(!k||!e)&&(W=new ResizeObserver(()=>{let t=me(e.item,e.content);Pe(e.content,e.trigger,t)}),W.observe(e.content))};z.push(()=>W?.disconnect()),z.push(()=>{B.forEach(e=>e.cleanup()),B.clear(),V.forEach((e,t)=>{de(t),t.hidden=!0,t.style.pointerEvents=`none`}),V.clear(),le?.cleanup(),U?.cleanup()});let G=new Map,me=(e,t)=>({side:_.side??c(t,`side`,g)??c(e,`side`,g)??b,align:_.align??c(t,`align`,h)??c(e,`align`,h)??x,sideOffset:_.sideOffset??l(t,`sideOffset`)??l(e,`sideOffset`)??S,alignOffset:_.alignOffset??l(t,`alignOffset`)??l(e,`alignOffset`)??C}),he=0;O.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){G.set(t,{item:e,trigger:n,content:r,index:he++}),B.set(r,i({element:r,onExitComplete:()=>{ae||(de(r),r.hidden=!0,r.style.pointerEvents=`none`)}}));let a=T(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 K=Array.from(G.values()).map(e=>e.trigger),ge=new Map;for(let[e,t]of G)ge.set(t.trigger,e);let _e=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),q=()=>{ne&&=(clearTimeout(ne),null),re&&=(clearTimeout(re),null)},J=null,ve=()=>{if(!k)return null;let e=U?.container;return e instanceof HTMLElement?e:k.parentElement instanceof HTMLElement?k.parentElement:k},ye=()=>{let e=ve();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;`,z.push(p(J,`pointerenter`,()=>{q()}),p(J,`pointerleave`,e=>{if(I||M===null)return;let n=e.relatedTarget;Z(n)||n&&t(f,n)||($(null),Q(null))}))),e&&J.parentElement!==e&&e.insertBefore(J,e.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`)},be=()=>{if(!w)return null;let e=f.ownerDocument.body;return e?(R||(R=f.ownerDocument.createElement(`div`),R.setAttribute(`data-slot`,`navigation-menu-safe-triangle`),R.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(`; `)),R.parentElement!==e&&e.appendChild(R),R):null},xe=()=>{R&&(R.style.width=`0`,R.style.height=`0`,R.style.clipPath=`none`,R.style.display=`none`)},X=()=>{w||xe()},Se=e=>{let t=be();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)})`},Ce=(e,t,n)=>(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y),we=(e,t,n,r)=>{let i=Ce(e,t,n),a=Ce(e,n,r),o=Ce(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},Te=(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},Ee=()=>M?G.get(M)??null:null,De=(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]=Te(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}},Oe=()=>{if(!k||M===null)return null;let e=Ee();if(!e)return null;let t=f.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),r=k.getBoundingClientRect(),i=e.content.getBoundingClientRect();return De(n,t,r.width>0&&r.height>0?r:i)},ke=e=>{let t=Oe();return t?we({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},Ae=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),je=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)},Me=e=>{if(e.length<3){Y();return}let t=je(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=ye();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(`, `)})`},Ne=()=>{if(!w)return;let e=Oe();if(!e){xe();return}Se(e)},Z=e=>{if(!e)return!1;if(Ee()?.content.contains(e)||k?.contains(e)||J?.contains(e))return!0;let t=U?.container;return!!(t instanceof HTMLElement&&t.contains(e))};z.push(X),z.push(Y),z.push(()=>{xe(),R?.parentElement&&R.parentElement.removeChild(R),R=null});let Pe=(t,n,r)=>{k&&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,h={top:d.top,left:d.left,width:p,height:m,right:d.left+p,bottom:d.top+m},_=getComputedStyle(k),v=parseFloat(_.marginTop)||0;k.style.setProperty(`--viewport-width`,`${p}px`),k.style.setProperty(`--viewport-height`,`${m}px`);let y=f.getBoundingClientRect(),ee=n.getBoundingClientRect(),b=e({anchorRect:ee,contentRect:h,side:r.side,align:r.align,sideOffset:r.sideOffset,alignOffset:r.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:g}),x=b.x-y.left,S=b.y-y.top;k.style.top=`0px`,k.style.left=`0px`,k.style.transform=`translate3d(${x}px, ${S}px, 0)`,k.style.willChange=`transform,width,height`,t.style.top=`0px`,t.style.left=`0px`,k.setAttribute(`data-side`,b.side),k.setAttribute(`data-align`,b.align),t.setAttribute(`data-side`,b.side),t.setAttribute(`data-align`,b.align);let C=U?.container;C&&C!==k&&(C.setAttribute(`data-side`,b.side),C.setAttribute(`data-align`,b.align)),fe();let w=k.getBoundingClientRect(),te=[],T=Math.max(0,w.top-y.bottom),E=Math.max(0,y.top-w.bottom),D=Math.max(0,w.left-y.right),O=Math.max(0,y.left-w.right),A=Math.max(0,c+v),j=Math.max(T,E,A),M=Math.max(D,O),N=De(ee,y,w),P=(e,t,n,r)=>{n<=0||r<=0||te.push({x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r})};if(j>=M&&j>0){let e=Math.max(T,E,A),t=x,n=E>T&&E>=A?S+m:S-e,r=p;if(N){let e=Math.min(N.edgeA.x,N.edgeB.x)-y.left,n=Math.max(N.edgeA.x,N.edgeB.x)-y.left;t=e-8,r=n-e+16}P(t,n,r,e)}else if(M>0){let e=Math.max(D,O),t=S,n=O>D?x+p:x-e,r=m;if(N){let e=Math.min(N.edgeA.y,N.edgeB.y)-y.top,n=Math.max(N.edgeA.y,N.edgeB.y)-y.top;t=e-8,r=n-e+16}P(n,t,e,r)}if(N){let e=Ae(N.apex,y),t=Ae(N.edgeA,y),n=Ae(N.edgeB,y);te.push(e,t,n)}Me(te),Ne()})},Fe=e=>P===-1||e>P?`right`:`left`,Q=e=>{if(!A)return;if(F=e,!e){A.setAttribute(`data-state`,`hidden`);return}let t=D.getBoundingClientRect(),n=e.getBoundingClientRect();A.style.setProperty(`--indicator-left`,`${n.left-t.left}px`),A.style.setProperty(`--indicator-width`,`${n.width}px`),A.style.setProperty(`--indicator-top`,`${n.top-t.top}px`);let r=(k&&parseFloat(getComputedStyle(k).marginTop)||0)<1?1:0;A.style.setProperty(`--indicator-height`,`${n.height-r}px`),A.setAttribute(`data-state`,`visible`)},$=(e,n=!1)=>{if(X(),e===M){q();return}if(e!==null&&e===N){q();return}q(),N=e===null?null:e;let r=()=>{let n=M,r=e?G.get(e):null,i=n!==null&&e!==null&&n!==e,o=i&&r?Fe(r.index):null,s=document.activeElement;if(e===null&&s&&t(f,s)){let e=n?G.get(n)?.trigger:null;e&&e.focus()}if(G.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`),E(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`),de(r),r.hidden=!0)}}),r){if(U?.mount(),k&&(k.hidden=!1),n===null&&le?.enter(),ue(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`),E(r.content,!1),r.content.hidden=!1,r.content.style.pointerEvents=`auto`,P=r.index;let e=me(r.item,r.content);Pe(r.content,r.trigger,e),pe(r),Q(r.trigger)}else Y(),X(),le?.exit(),pe(null);let c=e!==null;f.setAttribute(`data-state`,c?`open`:`closed`),o?f.setAttribute(`data-motion`,o===`right`?`from-right`:`from-left`):f.removeAttribute(`data-motion`),k&&(k.setAttribute(`data-state`,c?`open`:`closed`),k.style.pointerEvents=c?`auto`:`none`,c&&!i?k.setAttribute(`data-instant`,``):i&&k.removeAttribute(`data-instant`),o&&k.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)),M=e,N=null,e===null&&Q(null),Ne(),a(f,`navigation-menu:change`,{value:e}),te?.(e)};n?r():e!==null&&M===null?ne=setTimeout(r,v):e!==null&&M!==null?r():re=setTimeout(r,y)};f.setAttribute(`data-state`,`closed`),k&&(k.setAttribute(`data-state`,`closed`),k.hidden=!0,k.style.pointerEvents=`none`),A&&A.setAttribute(`data-state`,`hidden`),G.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===K[0]?0:-1,n.setAttribute(`data-state`,`closed`),t.setAttribute(`data-state`,`inactive`),t.setAttribute(`aria-hidden`,`true`),t.tabIndex=-1,E(t,!0),t.hidden=!0,t.style.pointerEvents=`none`}),G.forEach(({item:e,trigger:n},r)=>{z.push(p(n,`pointerenter`,e=>{if(!I){if(M!==r&&ke(e))return;Q(n)}})),z.push(p(e,`pointerenter`,e=>{if(!I){if(M!==r&&ke(e))return;$(r)}})),z.push(p(e,`pointerleave`,e=>{if(N===r&&M===null&&(q(),N=null),M===r&&!I){let n=e.relatedTarget;if(Z(n))return;(!n||!t(f,n))&&($(null),Q(null))}})),z.push(p(n,`focus`,()=>{L||(ee&&$(r,!0),Q(n))})),z.push(p(n,`pointerdown`,()=>{L=!0})),z.push(p(n,`click`,()=>{q(),M===r&&I?(I=!1,$(null,!0),Q(null)):M===r&&!I?(I=!0,Q(n)):(I=!0,$(r,!0),Q(n)),L=!1}))}),z.push(p(f,`pointerenter`,()=>{ie=!0}),p(f,`pointerleave`,e=>{let t=e.relatedTarget;if(!Z(t)&&(ie=!1,!I)){if(ke(e)){q();return}$(null),Q(null)}}),p(f,`pointerdown`,()=>{X(),q()})),k&&z.push(p(k,`pointerenter`,()=>{X(),q()}),p(k,`transitionend`,e=>{if(e.target!==k)return;let t=M?G.get(M):null;if(t){let e=me(t.item,t.content);Pe(t.content,t.trigger,e)}})),G.forEach(({content:e})=>{z.push(p(e,`pointerenter`,()=>{X(),q()}),p(e,`pointerleave`,e=>{if(I)return;let n=e.relatedTarget;Z(n)||t(f,n)||($(null),Q(null))}))}),z.push(p(D,`keydown`,e=>{let t=e.target,n=K.indexOf(t);if(n===-1)return;let r=ge.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&&(I=!0,$(r,!0),requestAnimationFrame(()=>{let e=G.get(r);if(!e)return;let t=_e(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=K.length-1;break;case`Escape`:I=!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:e,trigger:t})=>{z.push(p(e,`keydown`,n=>{let r=n.target,i=_e(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 Ie=()=>t(f,document.activeElement)||ie||I,Le=()=>{X(),I=!1,$(null,!0),Q(null),Ne()};return z.push(p(document,`pointerup`,()=>{L=!1},{capture:!0}),p(document,`pointercancel`,()=>{L=!1},{capture:!0})),z.push(p(document,`focusin`,e=>{M!==null&&(t(f,e.target)||Le())})),z.push(n({root:f,isOpen:()=>M!==null&&Ie(),onDismiss:Le,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:e=>!!e&&t(f,e)})),z.push(p(window,`resize`,()=>{M&&requestAnimationFrame(()=>fe()),F&&requestAnimationFrame(()=>Q(F))}),p(D,`scroll`,()=>{F&&requestAnimationFrame(()=>Q(F))})),z.push(p(f,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)Le();else if(G.has(t.value)){I=!0,$(t.value,!0);let e=G.get(t.value);e&&Q(e.trigger)}}})),{get value(){return M},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{ae=!0,q(),z.forEach(e=>e()),z.length=0}}}const v=new WeakSet;function y(e=document){let t=[];for(let n of f(e,`navigation-menu`))v.has(n)||(v.add(n),t.push(_(n)));return t}export{y as create,_ 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 h=[`start`,`center`,`end`],g=[`top`,`right`,`bottom`,`left`];function _(f,_={}){let v=_.delayOpen??l(f,`delayOpen`)??200,y=_.delayClose??l(f,`delayClose`)??150,ee=_.openOnFocus??s(f,`openOnFocus`)??!0,b=_.side??c(f,`side`,g)??`bottom`,x=_.align??c(f,`align`,h)??`start`,S=_.sideOffset??l(f,`sideOffset`)??0,C=_.alignOffset??l(f,`alignOffset`)??0,w=_.safeTriangle??s(f,`safeTriangle`)??!1,T=_.debugSafeTriangle??s(f,`debugSafeTriangle`)??!1,te=w||T,ne=_.onValueChange,E=e=>e.replace(/[^a-z0-9\-_:.]/gi,`-`),D=(e,t)=>{`inert`in e&&(e.inert=t)},O=u(f,`navigation-menu-list`),k=d(f,`navigation-menu-item`),A=u(f,`navigation-menu-viewport`),j=u(f,`navigation-menu-indicator`),M=(e,t)=>{let n=e.parentElement;for(;n&&n!==f;){if(n.getAttribute(`data-slot`)===t)return n;n=n.parentElement}return null};if(!O||k.length===0)throw Error(`NavigationMenu requires navigation-menu-list and at least one navigation-menu-item`);let N=null,P=null,re=-1,ie=null,ae=null,F=null,I=!1,L=!1,oe=!1,se=!1,R=null,z=null,B=[],V=new Map,H=new Map,ce=A?M(A,`navigation-menu-viewport-positioner`):null,le=A?M(A,`navigation-menu-positioner`):null,U=ce??le,ue=U?M(U,`navigation-menu-portal`):null,W=A?r({content:A,root:f,enabled:!0,wrapperSlot:U?void 0:`navigation-menu-viewport-positioner`,container:U??void 0,mountTarget:U?ue??U:void 0}):null,de=A?i({element:A,onExitComplete:()=>{se||(W?.restore(),A.hidden=!0,A.style.pointerEvents=`none`)}}):null,fe=e=>{if(!A)return;let t=H.get(e)??{originalParent:null,originalNextSibling:null,mountedInViewport:!1};t.mountedInViewport||(t.originalParent=e.parentNode,t.originalNextSibling=e.nextSibling,t.mountedInViewport=!0,H.set(e,t)),e.parentNode!==A&&A.appendChild(e)},pe=e=>{let t=H.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},me=()=>{if(!A||!W)return;let e=W.container,t=f.ownerDocument.defaultView??window,n=f.getBoundingClientRect();e.style.position=`absolute`,e.style.top=`0px`,e.style.left=`0px`,e.style.transform=`translate3d(${n.left+t.scrollX}px, ${n.top+t.scrollY}px, 0)`,e.style.width=`${n.width}px`,e.style.height=`${n.height}px`,e.style.margin=`0`,e.style.willChange=`transform`,e.style.pointerEvents=`none`},G=null,he=e=>{G?.disconnect(),G=null,!(!A||!e)&&(G=new ResizeObserver(()=>{let t=ge(e.item,e.content);Re(e.content,e.trigger,t)}),G.observe(e.content))};B.push(()=>G?.disconnect()),B.push(()=>{V.forEach(e=>e.cleanup()),V.clear(),H.forEach((e,t)=>{pe(t),t.hidden=!0,t.style.pointerEvents=`none`}),H.clear(),de?.cleanup(),W?.cleanup()});let K=new Map,ge=(e,t)=>({side:_.side??c(t,`side`,g)??c(e,`side`,g)??b,align:_.align??c(t,`align`,h)??c(e,`align`,h)??x,sideOffset:_.sideOffset??l(t,`sideOffset`)??l(e,`sideOffset`)??S,alignOffset:_.alignOffset??l(t,`alignOffset`)??l(e,`alignOffset`)??C}),_e=0;k.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){K.set(t,{item:e,trigger:n,content:r,index:_e++}),V.set(r,i({element:r,onExitComplete:()=>{se||(pe(r),r.hidden=!0,r.style.pointerEvents=`none`)}}));let a=E(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 q=Array.from(K.values()).map(e=>e.trigger),ve=new Map;for(let[e,t]of K)ve.set(t.trigger,e);let ye=e=>Array.from(e.querySelectorAll(`a, button, input, select, textarea, [tabindex]:not([tabindex="-1"])`)).filter(e=>!e.hidden&&!e.closest(`[hidden]`)),J=()=>{ie&&=(clearTimeout(ie),null),ae&&=(clearTimeout(ae),null)},be=()=>{z!==null&&(cancelAnimationFrame(z),z=null)},Y=null,xe=()=>{if(!A)return null;let e=W?.container;return e instanceof HTMLElement?e:A.parentElement instanceof HTMLElement?A.parentElement:A},Se=()=>{let e=xe();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;`,B.push(p(Y,`pointerenter`,()=>{J()}),p(Y,`pointerleave`,e=>{if(I||N===null)return;let n=e.relatedTarget;Le(n)||n&&t(f,n)||($(null),Q(null))}))),e&&Y.parentElement!==e&&e.insertBefore(Y,e.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`)},Ce=()=>{if(!T)return null;let e=f.ownerDocument.body;return e?(R||(R=f.ownerDocument.createElement(`div`),R.setAttribute(`data-slot`,`navigation-menu-safe-triangle`),R.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(`; `)),R.parentElement!==e&&e.appendChild(R),R):null},we=()=>{R&&(R.style.width=`0`,R.style.height=`0`,R.style.clipPath=`none`,R.style.display=`none`)},Z=()=>{T||we()},Te=e=>{let t=Ce();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)})`},Ee=(e,t,n)=>(e.x-n.x)*(t.y-n.y)-(t.x-n.x)*(e.y-n.y),De=(e,t,n,r)=>{let i=Ee(e,t,n),a=Ee(e,n,r),o=Ee(e,r,t);return!((i<0||a<0||o<0)&&(i>0||a>0||o>0))},Oe=(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},ke=()=>N?K.get(N)??null:null,Ae=(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]=Oe(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}},je=()=>{if(!te||!A||N===null)return null;let e=ke();if(!e)return null;let t=f.getBoundingClientRect(),n=e.trigger.getBoundingClientRect(),r=A.getBoundingClientRect(),i=e.content.getBoundingClientRect();return Ae(n,t,r.width>0&&r.height>0?r:i)},Me=e=>{let t=je();return t?De({x:e.clientX,y:e.clientY},t.apex,t.edgeA,t.edgeB):!1},Ne=(e,t)=>({x:e.x-t.left,y:e.y-t.top}),Pe=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)},Fe=e=>{if(e.length<3){X();return}let t=Pe(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=Se();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(`, `)})`},Ie=()=>{if(!T)return;let e=je();if(!e){we();return}Te(e)},Le=e=>{if(!e)return!1;if(ke()?.content.contains(e)||A?.contains(e)||Y?.contains(e))return!0;let t=W?.container;return!!(t instanceof HTMLElement&&t.contains(e))};B.push(Z),B.push(be),B.push(X),B.push(()=>{we(),R?.parentElement&&R.parentElement.removeChild(R),R=null});let Re=(t,n,r)=>{A&&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,h={top:d.top,left:d.left,width:p,height:m,right:d.left+p,bottom:d.top+m},_=getComputedStyle(A),v=parseFloat(_.marginTop)||0;A.style.setProperty(`--viewport-width`,`${p}px`),A.style.setProperty(`--viewport-height`,`${m}px`);let y=f.getBoundingClientRect(),ee=n.getBoundingClientRect(),b=e({anchorRect:ee,contentRect:h,side:r.side,align:r.align,sideOffset:r.sideOffset,alignOffset:r.alignOffset,avoidCollisions:!1,collisionPadding:0,allowedSides:g}),x=b.x-y.left,S=b.y-y.top;A.style.top=`0px`,A.style.left=`0px`,A.style.transform=`translate3d(${x}px, ${S}px, 0)`,A.style.willChange=`transform,width,height`,t.style.top=`0px`,t.style.left=`0px`,A.setAttribute(`data-side`,b.side),A.setAttribute(`data-align`,b.align),t.setAttribute(`data-side`,b.side),t.setAttribute(`data-align`,b.align);let C=W?.container;C&&C!==A&&(C.setAttribute(`data-side`,b.side),C.setAttribute(`data-align`,b.align)),me();let w=A.getBoundingClientRect(),T=[],ne=Math.max(0,w.top-y.bottom),E=Math.max(0,y.top-w.bottom),D=Math.max(0,w.left-y.right),O=Math.max(0,y.left-w.right),k=Math.max(0,c+v),j=Math.max(ne,E,k),M=Math.max(D,O),N=te?Ae(ee,y,w):null,P=(e,t,n,r)=>{n<=0||r<=0||T.push({x:e,y:t},{x:e+n,y:t},{x:e+n,y:t+r},{x:e,y:t+r})};if(j>=M&&j>0){let e=Math.max(ne,E,k),t=x,n=E>ne&&E>=k?S+m:S-e,r=p;if(N){let e=Math.min(N.edgeA.x,N.edgeB.x)-y.left,n=Math.max(N.edgeA.x,N.edgeB.x)-y.left;t=e-8,r=n-e+16}P(t,n,r,e)}else if(M>0){let e=Math.max(D,O),t=S,n=O>D?x+p:x-e,r=m;if(N){let e=Math.min(N.edgeA.y,N.edgeB.y)-y.top,n=Math.max(N.edgeA.y,N.edgeB.y)-y.top;t=e-8,r=n-e+16}P(n,t,e,r)}if(N){let e=Ne(N.apex,y),t=Ne(N.edgeA,y),n=Ne(N.edgeB,y);T.push(e,t,n)}Fe(T),Ie()})},ze=e=>re===-1||e>re?`right`:`left`,Q=e=>{if(!j)return;if(F=e,!e){be(),j.removeAttribute(`data-instant`),j.setAttribute(`data-state`,`hidden`);return}j.getAttribute(`data-state`)!==`visible`&&(be(),j.setAttribute(`data-instant`,``),z=requestAnimationFrame(()=>{z=requestAnimationFrame(()=>{j.removeAttribute(`data-instant`),z=null})}));let t=O.getBoundingClientRect(),n=e.getBoundingClientRect();j.style.setProperty(`--indicator-left`,`${n.left-t.left}px`),j.style.setProperty(`--indicator-width`,`${n.width}px`),j.style.setProperty(`--indicator-top`,`${n.top-t.top}px`);let r=(A&&parseFloat(getComputedStyle(A).marginTop)||0)<1?1:0;j.style.setProperty(`--indicator-height`,`${n.height-r}px`),j.setAttribute(`data-state`,`visible`)},$=(e,n=!1)=>{if(Z(),e===N){J();return}if(e!==null&&e===P){J();return}J(),P=e===null?null:e;let r=()=>{let n=N,r=e?K.get(e):null,i=n!==null&&e!==null&&n!==e,o=i&&r?ze(r.index):null,s=document.activeElement;if(e===null&&s&&t(f,s)){let e=n?K.get(n)?.trigger:null;e&&e.focus()}if(K.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=V.get(r);if(r.setAttribute(`data-state`,`inactive`),r.setAttribute(`aria-hidden`,`true`),D(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`),pe(r),r.hidden=!0)}}),r){if(W?.mount(),A&&(A.hidden=!1),n===null&&de?.enter(),fe(r.content),V.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`),D(r.content,!1),r.content.hidden=!1,r.content.style.pointerEvents=`auto`,re=r.index;let e=ge(r.item,r.content);Re(r.content,r.trigger,e),he(r),Q(r.trigger)}else X(),Z(),de?.exit(),he(null);let c=e!==null;f.setAttribute(`data-state`,c?`open`:`closed`),o?f.setAttribute(`data-motion`,o===`right`?`from-right`:`from-left`):f.removeAttribute(`data-motion`),A&&(A.setAttribute(`data-state`,c?`open`:`closed`),A.style.pointerEvents=c?`auto`:`none`,c&&!i?A.setAttribute(`data-instant`,``):i&&A.removeAttribute(`data-instant`),o&&A.style.setProperty(`--motion-direction`,o===`right`?`1`:`-1`)),N=e,P=null,e===null&&Q(null),Ie(),a(f,`navigation-menu:change`,{value:e}),ne?.(e)};n?r():e!==null&&N===null?ie=setTimeout(r,v):e!==null&&N!==null?r():ae=setTimeout(r,y)};f.setAttribute(`data-state`,`closed`),A&&(A.setAttribute(`data-state`,`closed`),A.hidden=!0,A.style.pointerEvents=`none`),j&&j.setAttribute(`data-state`,`hidden`),K.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===q[0]?0:-1,n.setAttribute(`data-state`,`closed`),t.setAttribute(`data-state`,`inactive`),t.setAttribute(`aria-hidden`,`true`),t.tabIndex=-1,D(t,!0),t.hidden=!0,t.style.pointerEvents=`none`}),K.forEach(({item:e,trigger:n},r)=>{B.push(p(n,`pointerenter`,e=>{if(!I){if(N!==r&&Me(e))return;Q(n)}})),B.push(p(e,`pointerenter`,e=>{if(!I){if(N!==r&&Me(e))return;$(r)}})),B.push(p(e,`pointerleave`,e=>{if(P===r&&N===null&&(J(),P=null),N===r&&!I){let n=e.relatedTarget;if(Le(n))return;(!n||!t(f,n))&&($(null),Q(null))}})),B.push(p(n,`focus`,()=>{L||(ee&&$(r,!0),Q(n))})),B.push(p(n,`pointerdown`,()=>{L=!0})),B.push(p(n,`click`,()=>{J(),N===r&&I?(I=!1,$(null,!0),Q(null)):N===r&&!I?(I=!0,Q(n)):(I=!0,$(r,!0),Q(n)),L=!1}))}),B.push(p(f,`pointerenter`,()=>{oe=!0}),p(f,`pointerleave`,e=>{let t=e.relatedTarget;if(!Le(t)&&(oe=!1,!I)){if(Me(e)){J();return}$(null),Q(null)}}),p(f,`pointerdown`,()=>{Z(),J()})),A&&B.push(p(A,`pointerenter`,()=>{Z(),J()}),p(A,`transitionend`,e=>{if(e.target!==A)return;let t=N?K.get(N):null;if(t){let e=ge(t.item,t.content);Re(t.content,t.trigger,e)}})),K.forEach(({content:e})=>{B.push(p(e,`pointerenter`,()=>{Z(),J()}),p(e,`pointerleave`,e=>{if(I)return;let n=e.relatedTarget;Le(n)||t(f,n)||($(null),Q(null))}))}),B.push(p(O,`keydown`,e=>{let t=e.target,n=q.indexOf(t);if(n===-1)return;let r=ve.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&&(I=!0,$(r,!0),requestAnimationFrame(()=>{let e=K.get(r);if(!e)return;let t=ye(e.content)[0];t?t.focus():e.content.focus()}));return;case`Home`:i=0;break;case`End`:i=q.length-1;break;case`Escape`:I=!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:e,trigger:t})=>{B.push(p(e,`keydown`,n=>{let r=n.target,i=ye(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 Be=()=>t(f,document.activeElement)||oe||I,Ve=()=>{Z(),I=!1,$(null,!0),Q(null),Ie()};return B.push(p(document,`pointerup`,()=>{L=!1},{capture:!0}),p(document,`pointercancel`,()=>{L=!1},{capture:!0})),B.push(p(document,`focusin`,e=>{N!==null&&(t(f,e.target)||Ve())})),B.push(n({root:f,isOpen:()=>N!==null&&Be(),onDismiss:Ve,closeOnClickOutside:!0,closeOnEscape:!0,preventEscapeDefault:!1,isInside:e=>!!e&&t(f,e)})),B.push(p(window,`resize`,()=>{N&&requestAnimationFrame(()=>me()),F&&requestAnimationFrame(()=>Q(F))}),p(O,`scroll`,()=>{F&&requestAnimationFrame(()=>Q(F))})),B.push(p(f,`navigation-menu:set`,e=>{let t=e.detail;if(t?.value!==void 0){if(t.value===null)Ve();else if(K.has(t.value)){I=!0,$(t.value,!0);let e=K.get(t.value);e&&Q(e.trigger)}}})),{get value(){return N},open:e=>$(e,!0),close:()=>$(null,!0),destroy:()=>{se=!0,J(),B.forEach(e=>e()),B.length=0}}}const v=new WeakSet;function y(e=document){let t=[];for(let n of f(e,`navigation-menu`))v.has(n)||(v.add(n),t.push(_(n)));return t}export{y as create,_ as createNavigationMenu};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-slot/navigation-menu",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.64",
|
|
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.
|
|
42
|
+
"@data-slot/core": "0.2.64"
|
|
43
43
|
}
|
|
44
44
|
}
|