UNPKG

@anoki/fse-ui

Version:

FSE UI components library

3 lines (2 loc) 3.95 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index.cjs729.js"),L=require("react"),H=require("react-dom");function U(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const o=U(L),I=U(H);var J=typeof document<"u",K=function(){},R=J?L.useLayoutEffect:K;function P(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(typeof e=="function"&&e.toString()===n.toString())return!0;let t,r,u;if(e&&n&&typeof e=="object"){if(Array.isArray(e)){if(t=e.length,t!==n.length)return!1;for(r=t;r--!==0;)if(!P(e[r],n[r]))return!1;return!0}if(u=Object.keys(e),t=u.length,t!==Object.keys(n).length)return!1;for(r=t;r--!==0;)if(!{}.hasOwnProperty.call(n,u[r]))return!1;for(r=t;r--!==0;){const g=u[r];if(!(g==="_owner"&&e.$$typeof)&&!P(e[g],n[g]))return!1}return!0}return e!==e&&n!==n}function $(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function z(e,n){const t=$(e);return Math.round(n*t)/t}function D(e){const n=o.useRef(e);return R(()=>{n.current=e}),n}function Q(e){e===void 0&&(e={});const{placement:n="bottom",strategy:t="absolute",middleware:r=[],platform:u,elements:{reference:g,floating:A}={},transform:j=!0,whileElementsMounted:k,open:S}=e,[i,E]=o.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[M,T]=o.useState(r);P(M,r)||T(r);const[B,N]=o.useState(null),[V,W]=o.useState(null),b=o.useCallback(f=>{f!==m.current&&(m.current=f,N(f))},[]),v=o.useCallback(f=>{f!==d.current&&(d.current=f,W(f))},[]),c=g||B,l=A||V,m=o.useRef(null),d=o.useRef(null),w=o.useRef(i),G=k!=null,O=D(k),_=D(u),C=D(S),y=o.useCallback(()=>{if(!m.current||!d.current)return;const f={placement:n,strategy:t,middleware:M};_.current&&(f.platform=_.current),s.computePosition(m.current,d.current,f).then(h=>{const p={...h,isPositioned:C.current!==!1};x.current&&!P(w.current,p)&&(w.current=p,I.flushSync(()=>{E(p)}))})},[M,n,t,_,C]);R(()=>{S===!1&&w.current.isPositioned&&(w.current.isPositioned=!1,E(f=>({...f,isPositioned:!1})))},[S]);const x=o.useRef(!1);R(()=>(x.current=!0,()=>{x.current=!1}),[]),R(()=>{if(c&&(m.current=c),l&&(d.current=l),c&&l){if(O.current)return O.current(c,l,y);y()}},[c,l,y,O,G]);const F=o.useMemo(()=>({reference:m,floating:d,setReference:b,setFloating:v}),[b,v]),a=o.useMemo(()=>({reference:c,floating:l}),[c,l]),q=o.useMemo(()=>{const f={position:t,left:0,top:0};if(!a.floating)return f;const h=z(a.floating,i.x),p=z(a.floating,i.y);return j?{...f,transform:"translate("+h+"px, "+p+"px)",...$(a.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:h,top:p}},[t,j,a.floating,i.x,i.y]);return o.useMemo(()=>({...i,update:y,refs:F,elements:a,floatingStyles:q}),[i,y,F,a,q])}const X=e=>{function n(t){return{}.hasOwnProperty.call(t,"current")}return{name:"arrow",options:e,fn(t){const{element:r,padding:u}=typeof e=="function"?e(t):e;return r&&n(r)?r.current!=null?s.arrow({element:r.current,padding:u}).fn(t):{}:r?s.arrow({element:r,padding:u}).fn(t):{}}}},Y=(e,n)=>{const t=s.offset(e);return{name:t.name,fn:t.fn,options:[e,n]}},Z=(e,n)=>{const t=s.shift(e);return{name:t.name,fn:t.fn,options:[e,n]}},ee=(e,n)=>({fn:s.limitShift(e).fn,options:[e,n]}),te=(e,n)=>{const t=s.flip(e);return{name:t.name,fn:t.fn,options:[e,n]}},ne=(e,n)=>{const t=s.size(e);return{name:t.name,fn:t.fn,options:[e,n]}},re=(e,n)=>{const t=s.hide(e);return{name:t.name,fn:t.fn,options:[e,n]}},oe=(e,n)=>{const t=X(e);return{name:t.name,fn:t.fn,options:[e,n]}};exports.autoUpdate=s.autoUpdate;exports.computePosition=s.computePosition;exports.platform=s.platform;exports.arrow=oe;exports.flip=te;exports.hide=re;exports.limitShift=ee;exports.offset=Y;exports.shift=Z;exports.size=ne;exports.useFloating=Q; //# sourceMappingURL=index.cjs727.js.map