@nild/components 0.0.5 → 0.0.6

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.
@@ -0,0 +1 @@
1
+ import{evaluate as H,getSideAxis as B,getSide as W,clamp as q,getOppositePlacement as Z,getExpandedPlacements as _,getOppositeAxisPlacements as $,getAlignmentSides as J,getPaddingObject as K,getAlignmentAxis as N,getAlignment as z,rectToClientRect as G,getOppositeAxis as M,getAxisLength as Q,min as U}from"./floating-ui.utils.js";function X(l,i,m){let{reference:n,floating:c}=l;const t=B(i),r=N(i),s=Q(r),p=W(i),d=t==="y",g=n.x+n.width/2-c.width/2,a=n.y+n.height/2-c.height/2,f=n[s]/2-c[s]/2;let e;switch(p){case"top":e={x:g,y:n.y-c.height};break;case"bottom":e={x:g,y:n.y+n.height};break;case"right":e={x:n.x+n.width,y:a};break;case"left":e={x:n.x-c.width,y:a};break;default:e={x:n.x,y:n.y}}switch(z(i)){case"start":e[r]-=f*(m&&d?-1:1);break;case"end":e[r]+=f*(m&&d?-1:1);break}return e}const ee=async(l,i,m)=>{const{placement:n="bottom",strategy:c="absolute",middleware:t=[],platform:r}=m,s=t.filter(Boolean),p=await(r.isRTL==null?void 0:r.isRTL(i));let d=await r.getElementRects({reference:l,floating:i,strategy:c}),{x:g,y:a}=X(d,n,p),f=n,e={},o=0;for(let y=0;y<s.length;y++){const{name:u,fn:h}=s[y],{x,y:w,data:R,reset:A}=await h({x:g,y:a,initialPlacement:n,placement:f,strategy:c,middlewareData:e,rects:d,platform:r,elements:{reference:l,floating:i}});g=x??g,a=w??a,e={...e,[u]:{...e[u],...R}},A&&o<=50&&(o++,typeof A=="object"&&(A.placement&&(f=A.placement),A.rects&&(d=A.rects===!0?await r.getElementRects({reference:l,floating:i,strategy:c}):A.rects),{x:g,y:a}=X(d,f,p)),y=-1)}return{x:g,y:a,placement:f,strategy:c,middlewareData:e}};async function I(l,i){var m;i===void 0&&(i={});const{x:n,y:c,platform:t,rects:r,elements:s,strategy:p}=l,{boundary:d="clippingAncestors",rootBoundary:g="viewport",elementContext:a="floating",altBoundary:f=!1,padding:e=0}=H(i,l),o=K(e),y=s[f?a==="floating"?"reference":"floating":a],u=G(await t.getClippingRect({element:(m=await(t.isElement==null?void 0:t.isElement(y)))==null||m?y:y.contextElement||await(t.getDocumentElement==null?void 0:t.getDocumentElement(s.floating)),boundary:d,rootBoundary:g,strategy:p})),h=a==="floating"?{x:n,y:c,width:r.floating.width,height:r.floating.height}:r.reference,x=await(t.getOffsetParent==null?void 0:t.getOffsetParent(s.floating)),w=await(t.isElement==null?void 0:t.isElement(x))?await(t.getScale==null?void 0:t.getScale(x))||{x:1,y:1}:{x:1,y:1},R=G(t.convertOffsetParentRelativeRectToViewportRelativeRect?await t.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:h,offsetParent:x,strategy:p}):h);return{top:(u.top-R.top+o.top)/w.y,bottom:(R.bottom-u.bottom+o.bottom)/w.y,left:(u.left-R.left+o.left)/w.x,right:(R.right-u.right+o.right)/w.x}}const te=l=>({name:"arrow",options:l,async fn(i){const{x:m,y:n,placement:c,rects:t,platform:r,elements:s,middlewareData:p}=i,{element:d,padding:g=0}=H(l,i)||{};if(d==null)return{};const a=K(g),f={x:m,y:n},e=N(c),o=Q(e),y=await r.getDimensions(d),u=e==="y",h=u?"top":"left",x=u?"bottom":"right",w=u?"clientHeight":"clientWidth",R=t.reference[o]+t.reference[e]-f[e]-t.floating[o],A=f[e]-t.reference[e],C=await(r.getOffsetParent==null?void 0:r.getOffsetParent(d));let T=C?C[w]:0;(!T||!await(r.isElement==null?void 0:r.isElement(C)))&&(T=s.floating[w]||t.floating[o]);const F=R/2-A/2,D=T/2-y[o]/2-1,P=U(a[h],D),V=U(a[x],D),S=P,j=T-y[o]-V,v=T/2-y[o]/2+F,L=q(S,v,j),k=!p.arrow&&z(c)!=null&&v!==L&&t.reference[o]/2-(v<S?P:V)-y[o]/2<0,b=k?v<S?v-S:v-j:0;return{[e]:f[e]+b,data:{[e]:L,centerOffset:v-L-b,...k&&{alignmentOffset:b}},reset:k}}}),ne=function(l){return l===void 0&&(l={}),{name:"flip",options:l,async fn(i){var m,n;const{placement:c,middlewareData:t,rects:r,initialPlacement:s,platform:p,elements:d}=i,{mainAxis:g=!0,crossAxis:a=!0,fallbackPlacements:f,fallbackStrategy:e="bestFit",fallbackAxisSideDirection:o="none",flipAlignment:y=!0,...u}=H(l,i);if((m=t.arrow)!=null&&m.alignmentOffset)return{};const h=W(c),x=B(s),w=W(s)===s,R=await(p.isRTL==null?void 0:p.isRTL(d.floating)),A=f||(w||!y?[Z(s)]:_(s)),C=o!=="none";!f&&C&&A.push(...$(s,y,o,R));const T=[s,...A],F=await I(i,u),D=[];let P=((n=t.flip)==null?void 0:n.overflows)||[];if(g&&D.push(F[h]),a){const v=J(c,r,R);D.push(F[v[0]],F[v[1]])}if(P=[...P,{placement:c,overflows:D}],!D.every(v=>v<=0)){var V,S;const v=(((V=t.flip)==null?void 0:V.index)||0)+1,L=T[v];if(L&&(!(a==="alignment"&&x!==B(L))||P.every(b=>b.overflows[0]>0&&B(b.placement)===x)))return{data:{index:v,overflows:P},reset:{placement:L}};let k=(S=P.filter(b=>b.overflows[0]<=0).sort((b,O)=>b.overflows[1]-O.overflows[1])[0])==null?void 0:S.placement;if(!k)switch(e){case"bestFit":{var j;const b=(j=P.filter(O=>{if(C){const E=B(O.placement);return E===x||E==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(E=>E>0).reduce((E,Y)=>E+Y,0)]).sort((O,E)=>O[1]-E[1])[0])==null?void 0:j[0];b&&(k=b);break}case"initialPlacement":k=s;break}if(c!==k)return{reset:{placement:k}}}return{}}}};async function ae(l,i){const{placement:m,platform:n,elements:c}=l,t=await(n.isRTL==null?void 0:n.isRTL(c.floating)),r=W(m),s=z(m),p=B(m)==="y",d=["left","top"].includes(r)?-1:1,g=t&&p?-1:1,a=H(i,l);let{mainAxis:f,crossAxis:e,alignmentAxis:o}=typeof a=="number"?{mainAxis:a,crossAxis:0,alignmentAxis:null}:{mainAxis:a.mainAxis||0,crossAxis:a.crossAxis||0,alignmentAxis:a.alignmentAxis};return s&&typeof o=="number"&&(e=s==="end"?o*-1:o),p?{x:e*g,y:f*d}:{x:f*d,y:e*g}}const ie=function(l){return l===void 0&&(l=0),{name:"offset",options:l,async fn(i){var m,n;const{x:c,y:t,placement:r,middlewareData:s}=i,p=await ae(i,l);return r===((m=s.offset)==null?void 0:m.placement)&&(n=s.arrow)!=null&&n.alignmentOffset?{}:{x:c+p.x,y:t+p.y,data:{...p,placement:r}}}}},le=function(l){return l===void 0&&(l={}),{name:"shift",options:l,async fn(i){const{x:m,y:n,placement:c}=i,{mainAxis:t=!0,crossAxis:r=!1,limiter:s={fn:u=>{let{x:h,y:x}=u;return{x:h,y:x}}},...p}=H(l,i),d={x:m,y:n},g=await I(i,p),a=B(W(c)),f=M(a);let e=d[f],o=d[a];if(t){const u=f==="y"?"top":"left",h=f==="y"?"bottom":"right",x=e+g[u],w=e-g[h];e=q(x,e,w)}if(r){const u=a==="y"?"top":"left",h=a==="y"?"bottom":"right",x=o+g[u],w=o-g[h];o=q(x,o,w)}const y=s.fn({...i,[f]:e,[a]:o});return{...y,data:{x:y.x-m,y:y.y-n,enabled:{[f]:t,[a]:r}}}}}};export{te as arrow,ee as computePosition,I as detectOverflow,ne as flip,ie as offset,G as rectToClientRect,le as shift};
@@ -0,0 +1 @@
1
+ import{offset as it,shift as rt,flip as st,arrow as lt,computePosition as ct}from"./floating-ui.core.js";import{createCoords as x,round as A,max as W,min as S,rectToClientRect as $,floor as D}from"./floating-ui.utils.js";import{isElement as v,getDocumentElement as b,getOverflowAncestors as N,getComputedStyle as L,isHTMLElement as R,getWindow as C,isTopLayer as V,getParentNode as O,isLastTraversableNode as P,isTableElement as ft,isContainingBlock as K,getContainingBlock as at,getNodeName as I,isOverflowElement as M,getNodeScroll as z,getFrameElement as j,isWebKit as G}from"./floating-ui.utils.dom.js";function J(t){const e=L(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=R(t),s=i?t.offsetWidth:n,r=i?t.offsetHeight:o,l=A(n)!==s||A(o)!==r;return l&&(n=s,o=r),{width:n,height:o,$:l}}function k(t){return v(t)?t:t.contextElement}function F(t){const e=k(t);if(!R(e))return x(1);const n=e.getBoundingClientRect(),{width:o,height:i,$:s}=J(e);let r=(s?A(n.width):n.width)/o,l=(s?A(n.height):n.height)/i;return(!r||!Number.isFinite(r))&&(r=1),(!l||!Number.isFinite(l))&&(l=1),{x:r,y:l}}const ut=x(0);function Q(t){const e=C(t);return!G()||!e.visualViewport?ut:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ht(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==C(t)?!1:e}function E(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);const i=t.getBoundingClientRect(),s=k(t);let r=x(1);e&&(o?v(o)&&(r=F(o)):r=F(t));const l=ht(s,n,o)?Q(s):x(0);let c=(i.left+l.x)/r.x,f=(i.top+l.y)/r.y,a=i.width/r.x,d=i.height/r.y;if(s){const p=C(s),u=o&&v(o)?C(o):o;let w=p,g=j(w);for(;g&&o&&u!==w;){const m=F(g),h=g.getBoundingClientRect(),y=L(g),T=h.left+(g.clientLeft+parseFloat(y.paddingLeft))*m.x,B=h.top+(g.clientTop+parseFloat(y.paddingTop))*m.y;c*=m.x,f*=m.y,a*=m.x,d*=m.y,c+=T,f+=B,w=C(g),g=j(w)}}return $({width:a,height:d,x:c,y:f})}function q(t,e){const n=z(t).scrollLeft;return e?e.left+n:E(b(t)).left+n}function U(t,e,n){n===void 0&&(n=!1);const o=t.getBoundingClientRect(),i=o.left+e.scrollLeft-(n?0:q(t,o)),s=o.top+e.scrollTop;return{x:i,y:s}}function dt(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t;const s=i==="fixed",r=b(o),l=e?V(e.floating):!1;if(o===r||l&&s)return n;let c={scrollLeft:0,scrollTop:0},f=x(1);const a=x(0),d=R(o);if((d||!d&&!s)&&((I(o)!=="body"||M(r))&&(c=z(o)),R(o))){const u=E(o);f=F(o),a.x=u.x+o.clientLeft,a.y=u.y+o.clientTop}const p=r&&!d&&!s?U(r,c,!0):x(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-c.scrollLeft*f.x+a.x+p.x,y:n.y*f.y-c.scrollTop*f.y+a.y+p.y}}function gt(t){return Array.from(t.getClientRects())}function pt(t){const e=b(t),n=z(t),o=t.ownerDocument.body,i=W(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=W(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let r=-n.scrollLeft+q(t);const l=-n.scrollTop;return L(o).direction==="rtl"&&(r+=W(e.clientWidth,o.clientWidth)-i),{width:i,height:s,x:r,y:l}}function mt(t,e){const n=C(t),o=b(t),i=n.visualViewport;let s=o.clientWidth,r=o.clientHeight,l=0,c=0;if(i){s=i.width,r=i.height;const f=G();(!f||f&&e==="fixed")&&(l=i.offsetLeft,c=i.offsetTop)}return{width:s,height:r,x:l,y:c}}function yt(t,e){const n=E(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,s=R(t)?F(t):x(1),r=t.clientWidth*s.x,l=t.clientHeight*s.y,c=i*s.x,f=o*s.y;return{width:r,height:l,x:c,y:f}}function X(t,e,n){let o;if(e==="viewport")o=mt(t,n);else if(e==="document")o=pt(b(t));else if(v(e))o=yt(e,n);else{const i=Q(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return $(o)}function Y(t,e){const n=O(t);return n===e||!v(n)||P(n)?!1:L(n).position==="fixed"||Y(n,e)}function xt(t,e){const n=e.get(t);if(n)return n;let o=N(t,[],!1).filter(l=>v(l)&&I(l)!=="body"),i=null;const s=L(t).position==="fixed";let r=s?O(t):t;for(;v(r)&&!P(r);){const l=L(r),c=K(r);!c&&l.position==="fixed"&&(i=null),(s?!c&&!i:!c&&l.position==="static"&&i&&["absolute","fixed"].includes(i.position)||M(r)&&!c&&Y(t,r))?o=o.filter(f=>f!==r):i=l,r=O(r)}return e.set(t,o),o}function wt(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t;const s=[...n==="clippingAncestors"?V(e)?[]:xt(e,this._c):[].concat(n),o],r=s[0],l=s.reduce((c,f)=>{const a=X(e,f,i);return c.top=W(a.top,c.top),c.right=S(a.right,c.right),c.bottom=S(a.bottom,c.bottom),c.left=W(a.left,c.left),c},X(e,r,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function vt(t){const{width:e,height:n}=J(t);return{width:e,height:n}}function bt(t,e,n){const o=R(e),i=b(e),s=n==="fixed",r=E(t,!0,s,e);let l={scrollLeft:0,scrollTop:0};const c=x(0);function f(){c.x=q(i)}if(o||!o&&!s)if((I(e)!=="body"||M(i))&&(l=z(e)),o){const u=E(e,!0,s,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else i&&f();s&&!o&&i&&f();const a=i&&!o&&!s?U(i,l):x(0),d=r.left+l.scrollLeft-c.x-a.x,p=r.top+l.scrollTop-c.y-a.y;return{x:d,y:p,width:r.width,height:r.height}}function _(t){return L(t).position==="static"}function Z(t,e){if(!R(t)||L(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return b(t)===n&&(n=n.ownerDocument.body),n}function tt(t,e){const n=C(t);if(V(t))return n;if(!R(t)){let i=O(t);for(;i&&!P(i);){if(v(i)&&!_(i))return i;i=O(i)}return n}let o=Z(t,e);for(;o&&ft(o)&&_(o);)o=Z(o,e);return o&&P(o)&&_(o)&&!K(o)?n:o||at(t)||n}const Lt=async function(t){const e=this.getOffsetParent||tt,n=this.getDimensions,o=await n(t.floating);return{reference:bt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Rt(t){return L(t).direction==="rtl"}const et={convertOffsetParentRelativeRectToViewportRelativeRect:dt,getDocumentElement:b,getClippingRect:wt,getOffsetParent:tt,getElementRects:Lt,getClientRects:gt,getDimensions:vt,getScale:F,isElement:v,isRTL:Rt};function nt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Tt(t,e){let n=null,o;const i=b(t);function s(){var l;clearTimeout(o),(l=n)==null||l.disconnect(),n=null}function r(l,c){l===void 0&&(l=!1),c===void 0&&(c=1),s();const f=t.getBoundingClientRect(),{left:a,top:d,width:p,height:u}=f;if(l||e(),!p||!u)return;const w=D(d),g=D(i.clientWidth-(a+p)),m=D(i.clientHeight-(d+u)),h=D(a),y={rootMargin:-w+"px "+-g+"px "+-m+"px "+-h+"px",threshold:W(0,S(1,c))||1};let T=!0;function B(ot){const H=ot[0].intersectionRatio;if(H!==c){if(!T)return r();H?r(!1,H):o=setTimeout(()=>{r(!1,1e-7)},1e3)}H===1&&!nt(f,t.getBoundingClientRect())&&r(),T=!1}try{n=new IntersectionObserver(B,{...y,root:i.ownerDocument})}catch{n=new IntersectionObserver(B,y)}n.observe(t)}return r(!0),s}function Ct(t,e,n,o){o===void 0&&(o={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:r=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:c=!1}=o,f=k(t),a=i||s?[...f?N(f):[],...N(e)]:[];a.forEach(h=>{i&&h.addEventListener("scroll",n,{passive:!0}),s&&h.addEventListener("resize",n)});const d=f&&l?Tt(f,n):null;let p=-1,u=null;r&&(u=new ResizeObserver(h=>{let[y]=h;y&&y.target===f&&u&&(u.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var T;(T=u)==null||T.observe(e)})),n()}),f&&!c&&u.observe(f),u.observe(e));let w,g=c?E(t):null;c&&m();function m(){const h=E(t);g&&!nt(g,h)&&n(),g=h,w=requestAnimationFrame(m)}return n(),()=>{var h;a.forEach(y=>{i&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),d?.(),(h=u)==null||h.disconnect(),u=null,c&&cancelAnimationFrame(w)}}const Et=it,Wt=rt,Ft=st,Ot=lt,Bt=(t,e,n)=>{const o=new Map,i={platform:et,...n},s={...i.platform,_c:o};return ct(t,e,{...i,platform:s})};export{Ot as arrow,Ct as autoUpdate,Bt as computePosition,Ft as flip,N as getOverflowAncestors,Et as offset,et as platform,Wt as shift};
@@ -1 +1 @@
1
- import{jsx as O}from"react/jsx-runtime";import{computePosition as F,offset as G,shift as H,flip as J,arrow as K,autoUpdate as M}from"../../node_modules/.pnpm/@floating-ui_dom@1.7.1/node_modules/@floating-ui/dom/dist/floating-ui.dom.js";import{useControllableState as N,useStableCallback as x,useIsomorphicLayoutEffect as P}from"@nild/hooks";import{getDPR as Q,roundByDPR as u}from"@nild/shared/utils";import{useRef as b,useState as f,useMemo as W,Children as X,isValidElement as g,cloneElement as j}from"react";import"../../portal/Arrow.js";import k from"../../portal/Portal.js";import Y from"../../transition/Transition.js";import h from"../../trigger/Trigger.js";const Z=(I,{placement:m="bottom",strategy:w="absolute",offset:C=12,open:L,defaultOpen:E=!1}={})=>{const t=b(null),a=b(null),c=b(null),[n,R]=f(E),[r,S]=N(L,E),[s,T]=f({x:0,y:0}),[l,U]=f({x:0,y:0}),[o,V]=f(m.split("-")[0]),$=W(()=>{const e=o==="top"||o==="bottom";return{[o==="left"?"right":"left"]:e?l.x:l.x-s.x,[o==="top"?"bottom":"top"]:e?l.y-s.y:l.y}},[o,l,s]),q={top:"down",bottom:"up",left:"right",right:"left"}[o];let y,d,i;X.forEach(I,e=>{g(e)&&e.type!==h&&e.type!==k&&(y=e),g(e)&&e.type===h&&(d=e),g(e)&&e.type===k&&(i=e)});const z=x(e=>{if(d)return j(d,{...e,ref:t});if(y)return O(h,{...e,ref:t,children:y})}),A=x(e=>{if(i)return O(Y,{visible:r,children:n&&j(i,{...i.props,...e,style:{transform:`translate(${s.x}px, ${s.y}px)`,...Q()>=1.5&&{willChange:"transform"}},ref:a,arrow:{ref:c,style:$,orientation:q}})})}),v=x(()=>{!t.current||!a.current||F(t.current,a.current,{placement:m,strategy:w,middleware:[G(C),H(),J(),c.current&&K({element:c.current})]}).then(({x:e,y:D,placement:B,middlewareData:{arrow:p}})=>{T({x:u(e),y:u(D)}),V(B.split("-")[0]),U({x:u(p?.x??e),y:u(p?.y??D)})})});return P(()=>{r&&!n?R(!0):r&&n&&v()},[r,n]),P(()=>{if(!(!t.current||!a.current||!r))return M(t.current,a.current,v)},[m,w,C,r]),[r,{setOpen:S,renderTrigger:z,renderPortal:A}]};export{Z as default};
1
+ import{jsx as O}from"react/jsx-runtime";import{computePosition as F,offset as G,shift as H,flip as J,arrow as K,autoUpdate as M}from"../../_lib/floating-ui.dom.js";import{useControllableState as N,useStableCallback as x,useIsomorphicLayoutEffect as P}from"@nild/hooks";import{getDPR as Q,roundByDPR as u}from"@nild/shared/utils";import{useRef as b,useState as f,useMemo as W,Children as X,isValidElement as g,cloneElement as j}from"react";import"../../portal/Arrow.js";import k from"../../portal/Portal.js";import Y from"../../transition/Transition.js";import h from"../../trigger/Trigger.js";const Z=(I,{placement:m="bottom",strategy:w="absolute",offset:C=12,open:L,defaultOpen:E=!1}={})=>{const t=b(null),a=b(null),c=b(null),[n,R]=f(E),[r,S]=N(L,E),[s,T]=f({x:0,y:0}),[l,U]=f({x:0,y:0}),[o,V]=f(m.split("-")[0]),$=W(()=>{const e=o==="top"||o==="bottom";return{[o==="left"?"right":"left"]:e?l.x:l.x-s.x,[o==="top"?"bottom":"top"]:e?l.y-s.y:l.y}},[o,l,s]),q={top:"down",bottom:"up",left:"right",right:"left"}[o];let y,d,i;X.forEach(I,e=>{g(e)&&e.type!==h&&e.type!==k&&(y=e),g(e)&&e.type===h&&(d=e),g(e)&&e.type===k&&(i=e)});const z=x(e=>{if(d)return j(d,{...e,ref:t});if(y)return O(h,{...e,ref:t,children:y})}),A=x(e=>{if(i)return O(Y,{visible:r,children:n&&j(i,{...i.props,...e,style:{transform:`translate(${s.x}px, ${s.y}px)`,...Q()>=1.5&&{willChange:"transform"}},ref:a,arrow:{ref:c,style:$,orientation:q}})})}),v=x(()=>{!t.current||!a.current||F(t.current,a.current,{placement:m,strategy:w,middleware:[G(C),H(),J(),c.current&&K({element:c.current})]}).then(({x:e,y:D,placement:B,middlewareData:{arrow:p}})=>{T({x:u(e),y:u(D)}),V(B.split("-")[0]),U({x:u(p?.x??e),y:u(p?.y??D)})})});return P(()=>{r&&!n?R(!0):r&&n&&v()},[r,n]),P(()=>{if(!(!t.current||!a.current||!r))return M(t.current,a.current,v)},[m,w,C,r]),[r,{setOpen:S,renderTrigger:z,renderPortal:A}]};export{Z as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nild/components",
3
3
  "private": false,
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
7
7
  "exports": {
@@ -31,8 +31,8 @@
31
31
  "peerDependencies": {
32
32
  "react": ">=18.2.0",
33
33
  "react-dom": ">=18.2.0",
34
- "@nild/shared": "0.0.4",
35
- "@nild/hooks": "0.0.5"
34
+ "@nild/shared": "0.0.5",
35
+ "@nild/hooks": "0.0.6"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "vite build --mode PROD",
@@ -1 +0,0 @@
1
- import{evaluate as H,getSideAxis as B,getSide as W,clamp as q,getOppositePlacement as Z,getExpandedPlacements as _,getOppositeAxisPlacements as $,getAlignmentSides as J,getPaddingObject as K,getAlignmentAxis as N,getAlignment as z,rectToClientRect as G,getOppositeAxis as M,getAxisLength as Q,min as U}from"../../../../../@floating-ui_utils@0.2.9/node_modules/@floating-ui/utils/dist/floating-ui.utils.js";function X(l,i,m){let{reference:n,floating:c}=l;const t=B(i),r=N(i),s=Q(r),p=W(i),d=t==="y",g=n.x+n.width/2-c.width/2,a=n.y+n.height/2-c.height/2,f=n[s]/2-c[s]/2;let e;switch(p){case"top":e={x:g,y:n.y-c.height};break;case"bottom":e={x:g,y:n.y+n.height};break;case"right":e={x:n.x+n.width,y:a};break;case"left":e={x:n.x-c.width,y:a};break;default:e={x:n.x,y:n.y}}switch(z(i)){case"start":e[r]-=f*(m&&d?-1:1);break;case"end":e[r]+=f*(m&&d?-1:1);break}return e}const ee=async(l,i,m)=>{const{placement:n="bottom",strategy:c="absolute",middleware:t=[],platform:r}=m,s=t.filter(Boolean),p=await(r.isRTL==null?void 0:r.isRTL(i));let d=await r.getElementRects({reference:l,floating:i,strategy:c}),{x:g,y:a}=X(d,n,p),f=n,e={},o=0;for(let y=0;y<s.length;y++){const{name:u,fn:h}=s[y],{x,y:w,data:R,reset:A}=await h({x:g,y:a,initialPlacement:n,placement:f,strategy:c,middlewareData:e,rects:d,platform:r,elements:{reference:l,floating:i}});g=x??g,a=w??a,e={...e,[u]:{...e[u],...R}},A&&o<=50&&(o++,typeof A=="object"&&(A.placement&&(f=A.placement),A.rects&&(d=A.rects===!0?await r.getElementRects({reference:l,floating:i,strategy:c}):A.rects),{x:g,y:a}=X(d,f,p)),y=-1)}return{x:g,y:a,placement:f,strategy:c,middlewareData:e}};async function I(l,i){var m;i===void 0&&(i={});const{x:n,y:c,platform:t,rects:r,elements:s,strategy:p}=l,{boundary:d="clippingAncestors",rootBoundary:g="viewport",elementContext:a="floating",altBoundary:f=!1,padding:e=0}=H(i,l),o=K(e),y=s[f?a==="floating"?"reference":"floating":a],u=G(await t.getClippingRect({element:(m=await(t.isElement==null?void 0:t.isElement(y)))==null||m?y:y.contextElement||await(t.getDocumentElement==null?void 0:t.getDocumentElement(s.floating)),boundary:d,rootBoundary:g,strategy:p})),h=a==="floating"?{x:n,y:c,width:r.floating.width,height:r.floating.height}:r.reference,x=await(t.getOffsetParent==null?void 0:t.getOffsetParent(s.floating)),w=await(t.isElement==null?void 0:t.isElement(x))?await(t.getScale==null?void 0:t.getScale(x))||{x:1,y:1}:{x:1,y:1},R=G(t.convertOffsetParentRelativeRectToViewportRelativeRect?await t.convertOffsetParentRelativeRectToViewportRelativeRect({elements:s,rect:h,offsetParent:x,strategy:p}):h);return{top:(u.top-R.top+o.top)/w.y,bottom:(R.bottom-u.bottom+o.bottom)/w.y,left:(u.left-R.left+o.left)/w.x,right:(R.right-u.right+o.right)/w.x}}const te=l=>({name:"arrow",options:l,async fn(i){const{x:m,y:n,placement:c,rects:t,platform:r,elements:s,middlewareData:p}=i,{element:d,padding:g=0}=H(l,i)||{};if(d==null)return{};const a=K(g),f={x:m,y:n},e=N(c),o=Q(e),y=await r.getDimensions(d),u=e==="y",h=u?"top":"left",x=u?"bottom":"right",w=u?"clientHeight":"clientWidth",R=t.reference[o]+t.reference[e]-f[e]-t.floating[o],A=f[e]-t.reference[e],C=await(r.getOffsetParent==null?void 0:r.getOffsetParent(d));let T=C?C[w]:0;(!T||!await(r.isElement==null?void 0:r.isElement(C)))&&(T=s.floating[w]||t.floating[o]);const F=R/2-A/2,D=T/2-y[o]/2-1,P=U(a[h],D),V=U(a[x],D),S=P,j=T-y[o]-V,v=T/2-y[o]/2+F,L=q(S,v,j),k=!p.arrow&&z(c)!=null&&v!==L&&t.reference[o]/2-(v<S?P:V)-y[o]/2<0,b=k?v<S?v-S:v-j:0;return{[e]:f[e]+b,data:{[e]:L,centerOffset:v-L-b,...k&&{alignmentOffset:b}},reset:k}}}),ne=function(l){return l===void 0&&(l={}),{name:"flip",options:l,async fn(i){var m,n;const{placement:c,middlewareData:t,rects:r,initialPlacement:s,platform:p,elements:d}=i,{mainAxis:g=!0,crossAxis:a=!0,fallbackPlacements:f,fallbackStrategy:e="bestFit",fallbackAxisSideDirection:o="none",flipAlignment:y=!0,...u}=H(l,i);if((m=t.arrow)!=null&&m.alignmentOffset)return{};const h=W(c),x=B(s),w=W(s)===s,R=await(p.isRTL==null?void 0:p.isRTL(d.floating)),A=f||(w||!y?[Z(s)]:_(s)),C=o!=="none";!f&&C&&A.push(...$(s,y,o,R));const T=[s,...A],F=await I(i,u),D=[];let P=((n=t.flip)==null?void 0:n.overflows)||[];if(g&&D.push(F[h]),a){const v=J(c,r,R);D.push(F[v[0]],F[v[1]])}if(P=[...P,{placement:c,overflows:D}],!D.every(v=>v<=0)){var V,S;const v=(((V=t.flip)==null?void 0:V.index)||0)+1,L=T[v];if(L&&(!(a==="alignment"&&x!==B(L))||P.every(b=>b.overflows[0]>0&&B(b.placement)===x)))return{data:{index:v,overflows:P},reset:{placement:L}};let k=(S=P.filter(b=>b.overflows[0]<=0).sort((b,O)=>b.overflows[1]-O.overflows[1])[0])==null?void 0:S.placement;if(!k)switch(e){case"bestFit":{var j;const b=(j=P.filter(O=>{if(C){const E=B(O.placement);return E===x||E==="y"}return!0}).map(O=>[O.placement,O.overflows.filter(E=>E>0).reduce((E,Y)=>E+Y,0)]).sort((O,E)=>O[1]-E[1])[0])==null?void 0:j[0];b&&(k=b);break}case"initialPlacement":k=s;break}if(c!==k)return{reset:{placement:k}}}return{}}}};async function ae(l,i){const{placement:m,platform:n,elements:c}=l,t=await(n.isRTL==null?void 0:n.isRTL(c.floating)),r=W(m),s=z(m),p=B(m)==="y",d=["left","top"].includes(r)?-1:1,g=t&&p?-1:1,a=H(i,l);let{mainAxis:f,crossAxis:e,alignmentAxis:o}=typeof a=="number"?{mainAxis:a,crossAxis:0,alignmentAxis:null}:{mainAxis:a.mainAxis||0,crossAxis:a.crossAxis||0,alignmentAxis:a.alignmentAxis};return s&&typeof o=="number"&&(e=s==="end"?o*-1:o),p?{x:e*g,y:f*d}:{x:f*d,y:e*g}}const ie=function(l){return l===void 0&&(l=0),{name:"offset",options:l,async fn(i){var m,n;const{x:c,y:t,placement:r,middlewareData:s}=i,p=await ae(i,l);return r===((m=s.offset)==null?void 0:m.placement)&&(n=s.arrow)!=null&&n.alignmentOffset?{}:{x:c+p.x,y:t+p.y,data:{...p,placement:r}}}}},le=function(l){return l===void 0&&(l={}),{name:"shift",options:l,async fn(i){const{x:m,y:n,placement:c}=i,{mainAxis:t=!0,crossAxis:r=!1,limiter:s={fn:u=>{let{x:h,y:x}=u;return{x:h,y:x}}},...p}=H(l,i),d={x:m,y:n},g=await I(i,p),a=B(W(c)),f=M(a);let e=d[f],o=d[a];if(t){const u=f==="y"?"top":"left",h=f==="y"?"bottom":"right",x=e+g[u],w=e-g[h];e=q(x,e,w)}if(r){const u=a==="y"?"top":"left",h=a==="y"?"bottom":"right",x=o+g[u],w=o-g[h];o=q(x,o,w)}const y=s.fn({...i,[f]:e,[a]:o});return{...y,data:{x:y.x-m,y:y.y-n,enabled:{[f]:t,[a]:r}}}}}};export{te as arrow,ee as computePosition,I as detectOverflow,ne as flip,ie as offset,G as rectToClientRect,le as shift};
@@ -1 +0,0 @@
1
- import{offset as it,shift as rt,flip as st,arrow as lt,computePosition as ct}from"../../../../../@floating-ui_core@1.7.1/node_modules/@floating-ui/core/dist/floating-ui.core.js";import{createCoords as x,round as A,max as W,min as S,rectToClientRect as $,floor as D}from"../../../../../@floating-ui_utils@0.2.9/node_modules/@floating-ui/utils/dist/floating-ui.utils.js";import{isElement as v,getDocumentElement as b,getOverflowAncestors as N,getComputedStyle as L,isHTMLElement as R,getWindow as C,isTopLayer as V,getParentNode as O,isLastTraversableNode as P,isTableElement as ft,isContainingBlock as K,getContainingBlock as at,getNodeName as I,isOverflowElement as M,getNodeScroll as z,getFrameElement as j,isWebKit as G}from"../../../../../@floating-ui_utils@0.2.9/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js";function J(t){const e=L(t);let n=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=R(t),s=i?t.offsetWidth:n,r=i?t.offsetHeight:o,l=A(n)!==s||A(o)!==r;return l&&(n=s,o=r),{width:n,height:o,$:l}}function k(t){return v(t)?t:t.contextElement}function F(t){const e=k(t);if(!R(e))return x(1);const n=e.getBoundingClientRect(),{width:o,height:i,$:s}=J(e);let r=(s?A(n.width):n.width)/o,l=(s?A(n.height):n.height)/i;return(!r||!Number.isFinite(r))&&(r=1),(!l||!Number.isFinite(l))&&(l=1),{x:r,y:l}}const ut=x(0);function Q(t){const e=C(t);return!G()||!e.visualViewport?ut:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ht(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==C(t)?!1:e}function E(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);const i=t.getBoundingClientRect(),s=k(t);let r=x(1);e&&(o?v(o)&&(r=F(o)):r=F(t));const l=ht(s,n,o)?Q(s):x(0);let c=(i.left+l.x)/r.x,f=(i.top+l.y)/r.y,a=i.width/r.x,d=i.height/r.y;if(s){const p=C(s),u=o&&v(o)?C(o):o;let w=p,g=j(w);for(;g&&o&&u!==w;){const m=F(g),h=g.getBoundingClientRect(),y=L(g),T=h.left+(g.clientLeft+parseFloat(y.paddingLeft))*m.x,B=h.top+(g.clientTop+parseFloat(y.paddingTop))*m.y;c*=m.x,f*=m.y,a*=m.x,d*=m.y,c+=T,f+=B,w=C(g),g=j(w)}}return $({width:a,height:d,x:c,y:f})}function q(t,e){const n=z(t).scrollLeft;return e?e.left+n:E(b(t)).left+n}function U(t,e,n){n===void 0&&(n=!1);const o=t.getBoundingClientRect(),i=o.left+e.scrollLeft-(n?0:q(t,o)),s=o.top+e.scrollTop;return{x:i,y:s}}function dt(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t;const s=i==="fixed",r=b(o),l=e?V(e.floating):!1;if(o===r||l&&s)return n;let c={scrollLeft:0,scrollTop:0},f=x(1);const a=x(0),d=R(o);if((d||!d&&!s)&&((I(o)!=="body"||M(r))&&(c=z(o)),R(o))){const u=E(o);f=F(o),a.x=u.x+o.clientLeft,a.y=u.y+o.clientTop}const p=r&&!d&&!s?U(r,c,!0):x(0);return{width:n.width*f.x,height:n.height*f.y,x:n.x*f.x-c.scrollLeft*f.x+a.x+p.x,y:n.y*f.y-c.scrollTop*f.y+a.y+p.y}}function gt(t){return Array.from(t.getClientRects())}function pt(t){const e=b(t),n=z(t),o=t.ownerDocument.body,i=W(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=W(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let r=-n.scrollLeft+q(t);const l=-n.scrollTop;return L(o).direction==="rtl"&&(r+=W(e.clientWidth,o.clientWidth)-i),{width:i,height:s,x:r,y:l}}function mt(t,e){const n=C(t),o=b(t),i=n.visualViewport;let s=o.clientWidth,r=o.clientHeight,l=0,c=0;if(i){s=i.width,r=i.height;const f=G();(!f||f&&e==="fixed")&&(l=i.offsetLeft,c=i.offsetTop)}return{width:s,height:r,x:l,y:c}}function yt(t,e){const n=E(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,s=R(t)?F(t):x(1),r=t.clientWidth*s.x,l=t.clientHeight*s.y,c=i*s.x,f=o*s.y;return{width:r,height:l,x:c,y:f}}function X(t,e,n){let o;if(e==="viewport")o=mt(t,n);else if(e==="document")o=pt(b(t));else if(v(e))o=yt(e,n);else{const i=Q(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return $(o)}function Y(t,e){const n=O(t);return n===e||!v(n)||P(n)?!1:L(n).position==="fixed"||Y(n,e)}function xt(t,e){const n=e.get(t);if(n)return n;let o=N(t,[],!1).filter(l=>v(l)&&I(l)!=="body"),i=null;const s=L(t).position==="fixed";let r=s?O(t):t;for(;v(r)&&!P(r);){const l=L(r),c=K(r);!c&&l.position==="fixed"&&(i=null),(s?!c&&!i:!c&&l.position==="static"&&i&&["absolute","fixed"].includes(i.position)||M(r)&&!c&&Y(t,r))?o=o.filter(f=>f!==r):i=l,r=O(r)}return e.set(t,o),o}function wt(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t;const s=[...n==="clippingAncestors"?V(e)?[]:xt(e,this._c):[].concat(n),o],r=s[0],l=s.reduce((c,f)=>{const a=X(e,f,i);return c.top=W(a.top,c.top),c.right=S(a.right,c.right),c.bottom=S(a.bottom,c.bottom),c.left=W(a.left,c.left),c},X(e,r,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function vt(t){const{width:e,height:n}=J(t);return{width:e,height:n}}function bt(t,e,n){const o=R(e),i=b(e),s=n==="fixed",r=E(t,!0,s,e);let l={scrollLeft:0,scrollTop:0};const c=x(0);function f(){c.x=q(i)}if(o||!o&&!s)if((I(e)!=="body"||M(i))&&(l=z(e)),o){const u=E(e,!0,s,e);c.x=u.x+e.clientLeft,c.y=u.y+e.clientTop}else i&&f();s&&!o&&i&&f();const a=i&&!o&&!s?U(i,l):x(0),d=r.left+l.scrollLeft-c.x-a.x,p=r.top+l.scrollTop-c.y-a.y;return{x:d,y:p,width:r.width,height:r.height}}function _(t){return L(t).position==="static"}function Z(t,e){if(!R(t)||L(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return b(t)===n&&(n=n.ownerDocument.body),n}function tt(t,e){const n=C(t);if(V(t))return n;if(!R(t)){let i=O(t);for(;i&&!P(i);){if(v(i)&&!_(i))return i;i=O(i)}return n}let o=Z(t,e);for(;o&&ft(o)&&_(o);)o=Z(o,e);return o&&P(o)&&_(o)&&!K(o)?n:o||at(t)||n}const Lt=async function(t){const e=this.getOffsetParent||tt,n=this.getDimensions,o=await n(t.floating);return{reference:bt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Rt(t){return L(t).direction==="rtl"}const et={convertOffsetParentRelativeRectToViewportRelativeRect:dt,getDocumentElement:b,getClippingRect:wt,getOffsetParent:tt,getElementRects:Lt,getClientRects:gt,getDimensions:vt,getScale:F,isElement:v,isRTL:Rt};function nt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Tt(t,e){let n=null,o;const i=b(t);function s(){var l;clearTimeout(o),(l=n)==null||l.disconnect(),n=null}function r(l,c){l===void 0&&(l=!1),c===void 0&&(c=1),s();const f=t.getBoundingClientRect(),{left:a,top:d,width:p,height:u}=f;if(l||e(),!p||!u)return;const w=D(d),g=D(i.clientWidth-(a+p)),m=D(i.clientHeight-(d+u)),h=D(a),y={rootMargin:-w+"px "+-g+"px "+-m+"px "+-h+"px",threshold:W(0,S(1,c))||1};let T=!0;function B(ot){const H=ot[0].intersectionRatio;if(H!==c){if(!T)return r();H?r(!1,H):o=setTimeout(()=>{r(!1,1e-7)},1e3)}H===1&&!nt(f,t.getBoundingClientRect())&&r(),T=!1}try{n=new IntersectionObserver(B,{...y,root:i.ownerDocument})}catch{n=new IntersectionObserver(B,y)}n.observe(t)}return r(!0),s}function Ct(t,e,n,o){o===void 0&&(o={});const{ancestorScroll:i=!0,ancestorResize:s=!0,elementResize:r=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:c=!1}=o,f=k(t),a=i||s?[...f?N(f):[],...N(e)]:[];a.forEach(h=>{i&&h.addEventListener("scroll",n,{passive:!0}),s&&h.addEventListener("resize",n)});const d=f&&l?Tt(f,n):null;let p=-1,u=null;r&&(u=new ResizeObserver(h=>{let[y]=h;y&&y.target===f&&u&&(u.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var T;(T=u)==null||T.observe(e)})),n()}),f&&!c&&u.observe(f),u.observe(e));let w,g=c?E(t):null;c&&m();function m(){const h=E(t);g&&!nt(g,h)&&n(),g=h,w=requestAnimationFrame(m)}return n(),()=>{var h;a.forEach(y=>{i&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),d?.(),(h=u)==null||h.disconnect(),u=null,c&&cancelAnimationFrame(w)}}const Et=it,Wt=rt,Ft=st,Ot=lt,Bt=(t,e,n)=>{const o=new Map,i={platform:et,...n},s={...i.platform,_c:o};return ct(t,e,{...i,platform:s})};export{Ot as arrow,Ct as autoUpdate,Bt as computePosition,Ft as flip,N as getOverflowAncestors,Et as offset,et as platform,Wt as shift};