Socket
Socket
Sign inDemoInstall

@floating-ui/core

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@floating-ui/core - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

56

dist/floating-ui.core.esm.js

@@ -672,26 +672,32 @@ function getBasePlacement(placement) {

}
const offset = value => ({
name: 'offset',
fn(middlewareArguments) {
const {
x,
y,
placement,
rects
} = middlewareArguments;
const diffCoords = convertValueToCoords({
placement,
rects,
value
});
return {
x: x + diffCoords.x,
y: y + diffCoords.y,
data: diffCoords
};
const offset = function (value) {
if (value === void 0) {
value = 0;
}
});
return {
name: 'offset',
fn(middlewareArguments) {
const {
x,
y,
placement,
rects
} = middlewareArguments;
const diffCoords = convertValueToCoords({
placement,
rects,
value
});
return {
x: x + diffCoords.x,
y: y + diffCoords.y,
data: diffCoords
};
}
};
};
function getCrossAxis(axis) {

@@ -792,11 +798,7 @@ return axis === 'x' ? 'y' : 'x';

placement
}) : {
mainAxis: offset,
crossAxis: 0
};
}) : offset;
const computedOffset = typeof rawOffset === 'number' ? {
mainAxis: rawOffset,
crossAxis: 0
} : // @ts-ignore - we want this to occur
{
} : {
mainAxis: 0,

@@ -803,0 +805,0 @@ crossAxis: 0,

@@ -1,1 +0,1 @@

function t(t){return t.split("-")[0]}function e(t){return t.split("-")[1]}function n(e){return["top","bottom"].includes(t(e))?"x":"y"}function r(t){return"y"===t?"height":"width"}function o(o){let{reference:i,floating:a,placement:l}=o;const s=i.x+i.width/2-a.width/2,c=i.y+i.height/2-a.height/2;let f;switch(t(l)){case"top":f={x:s,y:i.y-a.height};break;case"bottom":f={x:s,y:i.y+i.height};break;case"right":f={x:i.x+i.width,y:c};break;case"left":f={x:i.x-a.width,y:c};break;default:f={x:i.x,y:i.y}}const m=n(l),u=r(m);switch(e(l)){case"start":f[m]=f[m]-(i[u]/2-a[u]/2);break;case"end":f[m]=f[m]+(i[u]/2-a[u]/2)}return f}const i=async(t,e,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=n;let s=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:c,y:f}=o({...s,placement:r}),m=r,u={};for(let n=0;n<a.length;n++){0===n&&({x:c,y:f}=o({...s,placement:m}));const{name:p,fn:d}=a[n],{x:y,y:g,data:x,reset:h}=await d({x:c,y:f,initialPlacement:r,placement:m,strategy:i,middlewareData:u,rects:s,platform:l,elements:{reference:t,floating:e}});c=null!=y?y:c,f=null!=g?g:f,u={...u,[p]:null!=x?x:{}},h&&("object"==typeof h&&h.placement&&(m=h.placement),s=await l.getElementRects({reference:t,floating:e,strategy:i}),n=-1)}return{x:c,y:f,placement:m,strategy:i,middlewareData:u}};function a(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}function l(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}async function s(t,e){void 0===e&&(e={});const{x:n,y:r,platform:o,rects:i,elements:s,strategy:c}=t,{boundary:f="clippingParents",rootBoundary:m="viewport",elementContext:u="floating",altBoundary:p=!1,padding:d=0}=e,y=a(d),g=s[p?"floating"===u?"reference":"floating":u],x=await o.getClippingClientRect({element:await o.isElement(g)?g:g.contextElement||await o.getDocumentElement({element:s.floating}),boundary:f,rootBoundary:m}),h=l(await o.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===u?{...i.floating,x:n,y:r}:i.reference,offsetParent:await o.getOffsetParent({element:s.floating}),strategy:c}));return{top:x.top-h.top+y.top,bottom:h.bottom-x.bottom+y.bottom,left:x.left-h.left+y.left,right:h.right-x.right+y.right}}function c(t,e,n){return Math.max(t,Math.min(e,n))}const f=e=>({name:"arrow",async fn(o){const{element:i,padding:l=0}=null!=e?e:{},{x:s,y:f,placement:m,rects:u,platform:p}=o;if(null==i)return{};const d=a(l),y={x:s,y:f},g=n(t(m)),x=r(g),h=await p.getDimensions({element:i}),w="y"===g?"top":"left",v="y"===g?"bottom":"right",b=u.reference[x]+u.reference[g]-y[g]-u.floating[x],A=y[g]-u.reference[g],k=await p.getOffsetParent({element:i}),P=k?"y"===g?k.clientHeight||0:k.clientWidth||0:0,D=b/2-A/2,R=d[w],O=P-h[x]-d[v],E=P/2-h[x]/2+D,B=c(R,E,O);return{data:{[g]:B,centerOffset:E-B}}}}),m={left:"right",right:"left",bottom:"top",top:"bottom"};function u(t){return t.replace(/left|right|bottom|top/g,(t=>m[t]))}function p(t,o){const i="start"===e(t),a=n(t),l=r(a);let s="x"===a?i?"right":"left":i?"bottom":"top";return o.reference[l]>o.floating[l]&&(s=u(s)),{main:s,cross:u(s)}}const d={start:"end",end:"start"};function y(t){return t.replace(/start|end/g,(t=>d[t]))}const g=["top","right","bottom","left"],x=g.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]);const h=function(n){return void 0===n&&(n={}),{name:"autoPlacement",async fn(r){var o,i,a,l,c,f;const{x:m,y:u,rects:d,middlewareData:g,placement:h}=r,{alignment:w=null,crossAxis:v=!1,allowedPlacements:b=x,autoAlignment:A=!0,...k}=n;if(null!=(o=g.autoPlacement)&&o.skip)return{};const P=function(n,r,o){return o.filter((o=>n?e(o)===n||!!r&&y(o)!==o:t(o)===o))}(w,A,b),D=await s(r,k),R=null!=(i=null==(a=g.autoPlacement)?void 0:a.index)?i:0,O=P[R],{main:E,cross:B}=p(O,d);if(h!==O)return{x:m,y:u,reset:{placement:P[0]}};const C=[D[t(O)],D[E],D[B]],H=[...null!=(l=null==(c=g.autoPlacement)?void 0:c.overflows)?l:[],{placement:O,overflows:C}],z=P[R+1];if(z)return{data:{index:R+1,overflows:H},reset:{placement:z}};const F=H.slice().sort(v||A&&e(h)?(t,e)=>t.overflows.reduce(((t,e)=>t+e),0)-e.overflows.reduce(((t,e)=>t+e),0):(t,e)=>t.overflows[0]-e.overflows[0]),M=null==(f=F.find((t=>{let{overflows:e}=t;return e.every((t=>t<=0))})))?void 0:f.placement;return{data:{skip:!0},reset:{placement:null!=M?M:F[0].placement}}}}};const w=function(e){return void 0===e&&(e={}),{name:"flip",async fn(n){var r,o;const{placement:i,middlewareData:a,rects:l,initialPlacement:c}=n;if(null!=(r=a.flip)&&r.skip)return{};const{mainAxis:f=!0,crossAxis:m=!0,fallbackPlacements:d,fallbackStrategy:g="bestFit",flipAlignment:x=!0,...h}=e,w=t(i),v=d||(w===c||!x?[u(c)]:function(t){const e=u(t);return[y(t),e,y(e)]}(c)),b=[c,...v],A=await s(n,h),k=[];let P=(null==(o=a.flip)?void 0:o.overflows)||[];if(f&&k.push(A[w]),m){const{main:t,cross:e}=p(i,l);k.push(A[t],A[e])}if(P=[...P,{placement:i,overflows:k}],!k.every((t=>t<=0))){var D,R;const t=(null!=(D=null==(R=a.flip)?void 0:R.index)?D:0)+1,e=b[t];if(e)return{data:{index:t,overflows:P},reset:{placement:e}};let n="bottom";switch(g){case"bestFit":{var O;const t=null==(O=P.slice().sort(((t,e)=>t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)-e.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)))[0])?void 0:O.placement;t&&(n=t);break}case"initialPlacement":n=c}return{data:{skip:!0},reset:{placement:n}}}return{}}}};function v(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function b(t){return g.some((e=>t[e]>=0))}const A=()=>({name:"hide",async fn(t){const e=await s(t,{elementContext:"reference"}),n=await s(t,{altBoundary:!0}),r=v(e,t.rects.reference),o=v(n,t.rects.floating);return{data:{referenceHidden:b(r),referenceHiddenOffsets:r,escaped:b(o),escapedOffsets:o}}}});const k=e=>({name:"offset",fn(r){const{x:o,y:i,placement:a,rects:l}=r,s=function(e){let{placement:r,rects:o,value:i}=e;const a=t(r),l=["left","top"].includes(a)?-1:1,s="function"==typeof i?i({...o,placement:r}):i,{mainAxis:c,crossAxis:f}="number"==typeof s?{mainAxis:s,crossAxis:0}:{mainAxis:0,crossAxis:0,...s};return"x"===n(a)?{x:f,y:c*l}:{x:c*l,y:f}}({placement:a,rects:l,value:e});return{x:o+s.x,y:i+s.y,data:s}}});function P(t){return"x"===t?"y":"x"}const D=function(e){return void 0===e&&(e={}),{name:"shift",async fn(r){const{x:o,y:i,placement:a}=r,{mainAxis:l=!0,crossAxis:f=!1,limiter:m=(t=>{let{x:e,y:n}=t;return{x:e,y:n}}),...u}=e,p={x:o,y:i},d=await s(r,u),y=n(t(a)),g=P(y);let x=p[y],h=p[g];if(l){const t="y"===y?"bottom":"right";x=c(x+d["y"===y?"top":"left"],x,x-d[t])}if(f){const t="y"===g?"bottom":"right";h=c(h+d["y"===g?"top":"left"],h,h-d[t])}return m({...r,[y]:x,[g]:h})}}},R=function(e){return void 0===e&&(e={}),r=>{const{x:o,y:i,placement:a,rects:l,middlewareData:s}=r,{offset:c=0,mainAxis:f=!0,crossAxis:m=!0}=e,u={x:o,y:i},p=n(t(a)),d=P(p);let y=u[p],g=u[d];const x="function"==typeof c?c({...l,placement:a}):{mainAxis:c,crossAxis:0},h="number"==typeof x?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(f){const t="y"===p?"height":"width",e=l.reference[p]-l.floating[t]+h.mainAxis,n=l.reference[p]+l.reference[t]-h.mainAxis;y<e?y=e:y>n&&(y=n)}if(m){var w,v,b,A;const t="y"===p?"width":"height",e=l.reference[d]-l.floating[t]-(null!=(w=null==(v=s.offset)?void 0:v[p])?w:0)+h.crossAxis,n=l.reference[d]+l.reference[t]+(null!=(b=null==(A=s.offset)?void 0:A[p])?b:0)+h.crossAxis;g<e?g=e:g>n&&(g=n)}return{[p]:y,[d]:g}}},O=function(n){return void 0===n&&(n={}),{name:"size",async fn(r){var o;const{placement:i,rects:a,middlewareData:l}=r,{apply:c,...f}=n,m=await s(r,f),u=t(i),p="end"===e(i);let d,y;"top"===u||"bottom"===u?(d=u,y=p?"left":"right"):(y=u,d=p?"top":"bottom");const g={height:a.floating.height-m[d],width:a.floating.width-m[y]};return null!=(o=l.size)&&o.skip?{}:(null==c||c(g),{data:{skip:!0},reset:!0})}}};export{f as arrow,h as autoPlacement,i as computePosition,s as detectOverflow,w as flip,A as hide,R as limitShift,k as offset,l as rectToClientRect,D as shift,O as size};
function t(t){return t.split("-")[0]}function e(t){return t.split("-")[1]}function n(e){return["top","bottom"].includes(t(e))?"x":"y"}function r(t){return"y"===t?"height":"width"}function o(o){let{reference:i,floating:a,placement:l}=o;const c=i.x+i.width/2-a.width/2,s=i.y+i.height/2-a.height/2;let f;switch(t(l)){case"top":f={x:c,y:i.y-a.height};break;case"bottom":f={x:c,y:i.y+i.height};break;case"right":f={x:i.x+i.width,y:s};break;case"left":f={x:i.x-a.width,y:s};break;default:f={x:i.x,y:i.y}}const u=n(l),m=r(u);switch(e(l)){case"start":f[u]=f[u]-(i[m]/2-a[m]/2);break;case"end":f[u]=f[u]+(i[m]/2-a[m]/2)}return f}const i=async(t,e,n)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=n;let c=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:s,y:f}=o({...c,placement:r}),u=r,m={};for(let n=0;n<a.length;n++){0===n&&({x:s,y:f}=o({...c,placement:u}));const{name:p,fn:d}=a[n],{x:y,y:g,data:x,reset:h}=await d({x:s,y:f,initialPlacement:r,placement:u,strategy:i,middlewareData:m,rects:c,platform:l,elements:{reference:t,floating:e}});s=null!=y?y:s,f=null!=g?g:f,m={...m,[p]:null!=x?x:{}},h&&("object"==typeof h&&h.placement&&(u=h.placement),c=await l.getElementRects({reference:t,floating:e,strategy:i}),n=-1)}return{x:s,y:f,placement:u,strategy:i,middlewareData:m}};function a(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}function l(t){return{...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}async function c(t,e){void 0===e&&(e={});const{x:n,y:r,platform:o,rects:i,elements:c,strategy:s}=t,{boundary:f="clippingParents",rootBoundary:u="viewport",elementContext:m="floating",altBoundary:p=!1,padding:d=0}=e,y=a(d),g=c[p?"floating"===m?"reference":"floating":m],x=await o.getClippingClientRect({element:await o.isElement(g)?g:g.contextElement||await o.getDocumentElement({element:c.floating}),boundary:f,rootBoundary:u}),h=l(await o.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===m?{...i.floating,x:n,y:r}:i.reference,offsetParent:await o.getOffsetParent({element:c.floating}),strategy:s}));return{top:x.top-h.top+y.top,bottom:h.bottom-x.bottom+y.bottom,left:x.left-h.left+y.left,right:h.right-x.right+y.right}}function s(t,e,n){return Math.max(t,Math.min(e,n))}const f=e=>({name:"arrow",async fn(o){const{element:i,padding:l=0}=null!=e?e:{},{x:c,y:f,placement:u,rects:m,platform:p}=o;if(null==i)return{};const d=a(l),y={x:c,y:f},g=n(t(u)),x=r(g),h=await p.getDimensions({element:i}),w="y"===g?"top":"left",v="y"===g?"bottom":"right",b=m.reference[x]+m.reference[g]-y[g]-m.floating[x],A=y[g]-m.reference[g],k=await p.getOffsetParent({element:i}),P=k?"y"===g?k.clientHeight||0:k.clientWidth||0:0,D=b/2-A/2,R=d[w],O=P-h[x]-d[v],E=P/2-h[x]/2+D,B=s(R,E,O);return{data:{[g]:B,centerOffset:E-B}}}}),u={left:"right",right:"left",bottom:"top",top:"bottom"};function m(t){return t.replace(/left|right|bottom|top/g,(t=>u[t]))}function p(t,o){const i="start"===e(t),a=n(t),l=r(a);let c="x"===a?i?"right":"left":i?"bottom":"top";return o.reference[l]>o.floating[l]&&(c=m(c)),{main:c,cross:m(c)}}const d={start:"end",end:"start"};function y(t){return t.replace(/start|end/g,(t=>d[t]))}const g=["top","right","bottom","left"],x=g.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]);const h=function(n){return void 0===n&&(n={}),{name:"autoPlacement",async fn(r){var o,i,a,l,s,f;const{x:u,y:m,rects:d,middlewareData:g,placement:h}=r,{alignment:w=null,crossAxis:v=!1,allowedPlacements:b=x,autoAlignment:A=!0,...k}=n;if(null!=(o=g.autoPlacement)&&o.skip)return{};const P=function(n,r,o){return o.filter((o=>n?e(o)===n||!!r&&y(o)!==o:t(o)===o))}(w,A,b),D=await c(r,k),R=null!=(i=null==(a=g.autoPlacement)?void 0:a.index)?i:0,O=P[R],{main:E,cross:B}=p(O,d);if(h!==O)return{x:u,y:m,reset:{placement:P[0]}};const C=[D[t(O)],D[E],D[B]],H=[...null!=(l=null==(s=g.autoPlacement)?void 0:s.overflows)?l:[],{placement:O,overflows:C}],z=P[R+1];if(z)return{data:{index:R+1,overflows:H},reset:{placement:z}};const F=H.slice().sort(v||A&&e(h)?(t,e)=>t.overflows.reduce(((t,e)=>t+e),0)-e.overflows.reduce(((t,e)=>t+e),0):(t,e)=>t.overflows[0]-e.overflows[0]),M=null==(f=F.find((t=>{let{overflows:e}=t;return e.every((t=>t<=0))})))?void 0:f.placement;return{data:{skip:!0},reset:{placement:null!=M?M:F[0].placement}}}}};const w=function(e){return void 0===e&&(e={}),{name:"flip",async fn(n){var r,o;const{placement:i,middlewareData:a,rects:l,initialPlacement:s}=n;if(null!=(r=a.flip)&&r.skip)return{};const{mainAxis:f=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:g="bestFit",flipAlignment:x=!0,...h}=e,w=t(i),v=d||(w===s||!x?[m(s)]:function(t){const e=m(t);return[y(t),e,y(e)]}(s)),b=[s,...v],A=await c(n,h),k=[];let P=(null==(o=a.flip)?void 0:o.overflows)||[];if(f&&k.push(A[w]),u){const{main:t,cross:e}=p(i,l);k.push(A[t],A[e])}if(P=[...P,{placement:i,overflows:k}],!k.every((t=>t<=0))){var D,R;const t=(null!=(D=null==(R=a.flip)?void 0:R.index)?D:0)+1,e=b[t];if(e)return{data:{index:t,overflows:P},reset:{placement:e}};let n="bottom";switch(g){case"bestFit":{var O;const t=null==(O=P.slice().sort(((t,e)=>t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)-e.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)))[0])?void 0:O.placement;t&&(n=t);break}case"initialPlacement":n=s}return{data:{skip:!0},reset:{placement:n}}}return{}}}};function v(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function b(t){return g.some((e=>t[e]>=0))}const A=()=>({name:"hide",async fn(t){const e=await c(t,{elementContext:"reference"}),n=await c(t,{altBoundary:!0}),r=v(e,t.rects.reference),o=v(n,t.rects.floating);return{data:{referenceHidden:b(r),referenceHiddenOffsets:r,escaped:b(o),escapedOffsets:o}}}});const k=function(e){return void 0===e&&(e=0),{name:"offset",fn(r){const{x:o,y:i,placement:a,rects:l}=r,c=function(e){let{placement:r,rects:o,value:i}=e;const a=t(r),l=["left","top"].includes(a)?-1:1,c="function"==typeof i?i({...o,placement:r}):i,{mainAxis:s,crossAxis:f}="number"==typeof c?{mainAxis:c,crossAxis:0}:{mainAxis:0,crossAxis:0,...c};return"x"===n(a)?{x:f,y:s*l}:{x:s*l,y:f}}({placement:a,rects:l,value:e});return{x:o+c.x,y:i+c.y,data:c}}}};function P(t){return"x"===t?"y":"x"}const D=function(e){return void 0===e&&(e={}),{name:"shift",async fn(r){const{x:o,y:i,placement:a}=r,{mainAxis:l=!0,crossAxis:f=!1,limiter:u=(t=>{let{x:e,y:n}=t;return{x:e,y:n}}),...m}=e,p={x:o,y:i},d=await c(r,m),y=n(t(a)),g=P(y);let x=p[y],h=p[g];if(l){const t="y"===y?"bottom":"right";x=s(x+d["y"===y?"top":"left"],x,x-d[t])}if(f){const t="y"===g?"bottom":"right";h=s(h+d["y"===g?"top":"left"],h,h-d[t])}return u({...r,[y]:x,[g]:h})}}},R=function(e){return void 0===e&&(e={}),r=>{const{x:o,y:i,placement:a,rects:l,middlewareData:c}=r,{offset:s=0,mainAxis:f=!0,crossAxis:u=!0}=e,m={x:o,y:i},p=n(t(a)),d=P(p);let y=m[p],g=m[d];const x="function"==typeof s?s({...l,placement:a}):s,h="number"==typeof x?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(f){const t="y"===p?"height":"width",e=l.reference[p]-l.floating[t]+h.mainAxis,n=l.reference[p]+l.reference[t]-h.mainAxis;y<e?y=e:y>n&&(y=n)}if(u){var w,v,b,A;const t="y"===p?"width":"height",e=l.reference[d]-l.floating[t]-(null!=(w=null==(v=c.offset)?void 0:v[p])?w:0)+h.crossAxis,n=l.reference[d]+l.reference[t]+(null!=(b=null==(A=c.offset)?void 0:A[p])?b:0)+h.crossAxis;g<e?g=e:g>n&&(g=n)}return{[p]:y,[d]:g}}},O=function(n){return void 0===n&&(n={}),{name:"size",async fn(r){var o;const{placement:i,rects:a,middlewareData:l}=r,{apply:s,...f}=n,u=await c(r,f),m=t(i),p="end"===e(i);let d,y;"top"===m||"bottom"===m?(d=m,y=p?"left":"right"):(y=m,d=p?"top":"bottom");const g={height:a.floating.height-u[d],width:a.floating.width-u[y]};return null!=(o=l.size)&&o.skip?{}:(null==s||s(g),{data:{skip:!0},reset:!0})}}};export{f as arrow,h as autoPlacement,i as computePosition,c as detectOverflow,w as flip,A as hide,R as limitShift,k as offset,l as rectToClientRect,D as shift,O as size};

@@ -678,26 +678,32 @@ (function (global, factory) {

}
const offset = value => ({
name: 'offset',
fn(middlewareArguments) {
const {
x,
y,
placement,
rects
} = middlewareArguments;
const diffCoords = convertValueToCoords({
placement,
rects,
value
});
return {
x: x + diffCoords.x,
y: y + diffCoords.y,
data: diffCoords
};
const offset = function (value) {
if (value === void 0) {
value = 0;
}
});
return {
name: 'offset',
fn(middlewareArguments) {
const {
x,
y,
placement,
rects
} = middlewareArguments;
const diffCoords = convertValueToCoords({
placement,
rects,
value
});
return {
x: x + diffCoords.x,
y: y + diffCoords.y,
data: diffCoords
};
}
};
};
function getCrossAxis(axis) {

@@ -798,11 +804,7 @@ return axis === 'x' ? 'y' : 'x';

placement
}) : {
mainAxis: offset,
crossAxis: 0
};
}) : offset;
const computedOffset = typeof rawOffset === 'number' ? {
mainAxis: rawOffset,
crossAxis: 0
} : // @ts-ignore - we want this to occur
{
} : {
mainAxis: 0,

@@ -809,0 +811,0 @@ crossAxis: 0,

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FloatingUICore={})}(this,(function(e){"use strict";function t(e){return e.split("-")[0]}function n(e){return e.split("-")[1]}function r(e){return["top","bottom"].includes(t(e))?"x":"y"}function o(e){return"y"===e?"height":"width"}function i(e){let{reference:i,floating:a,placement:l}=e;const s=i.x+i.width/2-a.width/2,c=i.y+i.height/2-a.height/2;let f;switch(t(l)){case"top":f={x:s,y:i.y-a.height};break;case"bottom":f={x:s,y:i.y+i.height};break;case"right":f={x:i.x+i.width,y:c};break;case"left":f={x:i.x-a.width,y:c};break;default:f={x:i.x,y:i.y}}const u=r(l),m=o(u);switch(n(l)){case"start":f[u]=f[u]-(i[m]/2-a[m]/2);break;case"end":f[u]=f[u]+(i[m]/2-a[m]/2)}return f}function a(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}function l(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}async function s(e,t){void 0===t&&(t={});const{x:n,y:r,platform:o,rects:i,elements:s,strategy:c}=e,{boundary:f="clippingParents",rootBoundary:u="viewport",elementContext:m="floating",altBoundary:d=!1,padding:p=0}=t,y=a(p),g=s[d?"floating"===m?"reference":"floating":m],h=await o.getClippingClientRect({element:await o.isElement(g)?g:g.contextElement||await o.getDocumentElement({element:s.floating}),boundary:f,rootBoundary:u}),x=l(await o.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===m?{...i.floating,x:n,y:r}:i.reference,offsetParent:await o.getOffsetParent({element:s.floating}),strategy:c}));return{top:h.top-x.top+y.top,bottom:x.bottom-h.bottom+y.bottom,left:h.left-x.left+y.left,right:x.right-h.right+y.right}}function c(e,t,n){return Math.max(e,Math.min(t,n))}const f={left:"right",right:"left",bottom:"top",top:"bottom"};function u(e){return e.replace(/left|right|bottom|top/g,(e=>f[e]))}function m(e,t){const i="start"===n(e),a=r(e),l=o(a);let s="x"===a?i?"right":"left":i?"bottom":"top";return t.reference[l]>t.floating[l]&&(s=u(s)),{main:s,cross:u(s)}}const d={start:"end",end:"start"};function p(e){return e.replace(/start|end/g,(e=>d[e]))}const y=["top","right","bottom","left"],g=y.reduce(((e,t)=>e.concat(t,t+"-start",t+"-end")),[]);function h(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function x(e){return y.some((t=>e[t]>=0))}function w(e){return"x"===e?"y":"x"}e.arrow=e=>({name:"arrow",async fn(n){const{element:i,padding:l=0}=null!=e?e:{},{x:s,y:f,placement:u,rects:m,platform:d}=n;if(null==i)return{};const p=a(l),y={x:s,y:f},g=r(t(u)),h=o(g),x=await d.getDimensions({element:i}),w="y"===g?"top":"left",b="y"===g?"bottom":"right",v=m.reference[h]+m.reference[g]-y[g]-m.floating[h],A=y[g]-m.reference[g],P=await d.getOffsetParent({element:i}),k=P?"y"===g?P.clientHeight||0:P.clientWidth||0:0,D=v/2-A/2,O=p[w],R=k-x[h]-p[b],C=k/2-x[h]/2+D,E=c(O,C,R);return{data:{[g]:E,centerOffset:C-E}}}}),e.autoPlacement=function(e){return void 0===e&&(e={}),{name:"autoPlacement",async fn(r){var o,i,a,l,c,f;const{x:u,y:d,rects:y,middlewareData:h,placement:x}=r,{alignment:w=null,crossAxis:b=!1,allowedPlacements:v=g,autoAlignment:A=!0,...P}=e;if(null!=(o=h.autoPlacement)&&o.skip)return{};const k=function(e,r,o){return o.filter((o=>e?n(o)===e||!!r&&p(o)!==o:t(o)===o))}(w,A,v),D=await s(r,P),O=null!=(i=null==(a=h.autoPlacement)?void 0:a.index)?i:0,R=k[O],{main:C,cross:E}=m(R,y);if(x!==R)return{x:u,y:d,reset:{placement:k[0]}};const B=[D[t(R)],D[C],D[E]],T=[...null!=(l=null==(c=h.autoPlacement)?void 0:c.overflows)?l:[],{placement:R,overflows:B}],j=k[O+1];if(j)return{data:{index:O+1,overflows:T},reset:{placement:j}};const z=T.slice().sort(b||A&&n(x)?(e,t)=>e.overflows.reduce(((e,t)=>e+t),0)-t.overflows.reduce(((e,t)=>e+t),0):(e,t)=>e.overflows[0]-t.overflows[0]),F=null==(f=z.find((e=>{let{overflows:t}=e;return t.every((e=>e<=0))})))?void 0:f.placement;return{data:{skip:!0},reset:{placement:null!=F?F:z[0].placement}}}}},e.computePosition=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:a=[],platform:l}=n;let s=await l.getElementRects({reference:e,floating:t,strategy:o}),{x:c,y:f}=i({...s,placement:r}),u=r,m={};for(let n=0;n<a.length;n++){0===n&&({x:c,y:f}=i({...s,placement:u}));const{name:d,fn:p}=a[n],{x:y,y:g,data:h,reset:x}=await p({x:c,y:f,initialPlacement:r,placement:u,strategy:o,middlewareData:m,rects:s,platform:l,elements:{reference:e,floating:t}});c=null!=y?y:c,f=null!=g?g:f,m={...m,[d]:null!=h?h:{}},x&&("object"==typeof x&&x.placement&&(u=x.placement),s=await l.getElementRects({reference:e,floating:t,strategy:o}),n=-1)}return{x:c,y:f,placement:u,strategy:o,middlewareData:m}},e.detectOverflow=s,e.flip=function(e){return void 0===e&&(e={}),{name:"flip",async fn(n){var r,o;const{placement:i,middlewareData:a,rects:l,initialPlacement:c}=n;if(null!=(r=a.flip)&&r.skip)return{};const{mainAxis:f=!0,crossAxis:d=!0,fallbackPlacements:y,fallbackStrategy:g="bestFit",flipAlignment:h=!0,...x}=e,w=t(i),b=y||(w===c||!h?[u(c)]:function(e){const t=u(e);return[p(e),t,p(t)]}(c)),v=[c,...b],A=await s(n,x),P=[];let k=(null==(o=a.flip)?void 0:o.overflows)||[];if(f&&P.push(A[w]),d){const{main:e,cross:t}=m(i,l);P.push(A[e],A[t])}if(k=[...k,{placement:i,overflows:P}],!P.every((e=>e<=0))){var D,O;const e=(null!=(D=null==(O=a.flip)?void 0:O.index)?D:0)+1,t=v[e];if(t)return{data:{index:e,overflows:k},reset:{placement:t}};let n="bottom";switch(g){case"bestFit":{var R;const e=null==(R=k.slice().sort(((e,t)=>e.overflows.filter((e=>e>0)).reduce(((e,t)=>e+t),0)-t.overflows.filter((e=>e>0)).reduce(((e,t)=>e+t),0)))[0])?void 0:R.placement;e&&(n=e);break}case"initialPlacement":n=c}return{data:{skip:!0},reset:{placement:n}}}return{}}}},e.hide=()=>({name:"hide",async fn(e){const t=await s(e,{elementContext:"reference"}),n=await s(e,{altBoundary:!0}),r=h(t,e.rects.reference),o=h(n,e.rects.floating);return{data:{referenceHidden:x(r),referenceHiddenOffsets:r,escaped:x(o),escapedOffsets:o}}}}),e.limitShift=function(e){return void 0===e&&(e={}),n=>{const{x:o,y:i,placement:a,rects:l,middlewareData:s}=n,{offset:c=0,mainAxis:f=!0,crossAxis:u=!0}=e,m={x:o,y:i},d=r(t(a)),p=w(d);let y=m[d],g=m[p];const h="function"==typeof c?c({...l,placement:a}):{mainAxis:c,crossAxis:0},x="number"==typeof h?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(f){const e="y"===d?"height":"width",t=l.reference[d]-l.floating[e]+x.mainAxis,n=l.reference[d]+l.reference[e]-x.mainAxis;y<t?y=t:y>n&&(y=n)}if(u){var b,v,A,P;const e="y"===d?"width":"height",t=l.reference[p]-l.floating[e]-(null!=(b=null==(v=s.offset)?void 0:v[d])?b:0)+x.crossAxis,n=l.reference[p]+l.reference[e]+(null!=(A=null==(P=s.offset)?void 0:P[d])?A:0)+x.crossAxis;g<t?g=t:g>n&&(g=n)}return{[d]:y,[p]:g}}},e.offset=e=>({name:"offset",fn(n){const{x:o,y:i,placement:a,rects:l}=n,s=function(e){let{placement:n,rects:o,value:i}=e;const a=t(n),l=["left","top"].includes(a)?-1:1,s="function"==typeof i?i({...o,placement:n}):i,{mainAxis:c,crossAxis:f}="number"==typeof s?{mainAxis:s,crossAxis:0}:{mainAxis:0,crossAxis:0,...s};return"x"===r(a)?{x:f,y:c*l}:{x:c*l,y:f}}({placement:a,rects:l,value:e});return{x:o+s.x,y:i+s.y,data:s}}}),e.rectToClientRect=l,e.shift=function(e){return void 0===e&&(e={}),{name:"shift",async fn(n){const{x:o,y:i,placement:a}=n,{mainAxis:l=!0,crossAxis:f=!1,limiter:u=(e=>{let{x:t,y:n}=e;return{x:t,y:n}}),...m}=e,d={x:o,y:i},p=await s(n,m),y=r(t(a)),g=w(y);let h=d[y],x=d[g];if(l){const e="y"===y?"bottom":"right";h=c(h+p["y"===y?"top":"left"],h,h-p[e])}if(f){const e="y"===g?"bottom":"right";x=c(x+p["y"===g?"top":"left"],x,x-p[e])}return u({...n,[y]:h,[g]:x})}}},e.size=function(e){return void 0===e&&(e={}),{name:"size",async fn(r){var o;const{placement:i,rects:a,middlewareData:l}=r,{apply:c,...f}=e,u=await s(r,f),m=t(i),d="end"===n(i);let p,y;"top"===m||"bottom"===m?(p=m,y=d?"left":"right"):(y=m,p=d?"top":"bottom");const g={height:a.floating.height-u[p],width:a.floating.width-u[y]};return null!=(o=l.size)&&o.skip?{}:(null==c||c(g),{data:{skip:!0},reset:!0})}}},Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FloatingUICore={})}(this,(function(e){"use strict";function t(e){return e.split("-")[0]}function n(e){return e.split("-")[1]}function r(e){return["top","bottom"].includes(t(e))?"x":"y"}function o(e){return"y"===e?"height":"width"}function i(e){let{reference:i,floating:a,placement:l}=e;const s=i.x+i.width/2-a.width/2,c=i.y+i.height/2-a.height/2;let f;switch(t(l)){case"top":f={x:s,y:i.y-a.height};break;case"bottom":f={x:s,y:i.y+i.height};break;case"right":f={x:i.x+i.width,y:c};break;case"left":f={x:i.x-a.width,y:c};break;default:f={x:i.x,y:i.y}}const u=r(l),m=o(u);switch(n(l)){case"start":f[u]=f[u]-(i[m]/2-a[m]/2);break;case"end":f[u]=f[u]+(i[m]/2-a[m]/2)}return f}function a(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}function l(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}async function s(e,t){void 0===t&&(t={});const{x:n,y:r,platform:o,rects:i,elements:s,strategy:c}=e,{boundary:f="clippingParents",rootBoundary:u="viewport",elementContext:m="floating",altBoundary:d=!1,padding:p=0}=t,y=a(p),g=s[d?"floating"===m?"reference":"floating":m],h=await o.getClippingClientRect({element:await o.isElement(g)?g:g.contextElement||await o.getDocumentElement({element:s.floating}),boundary:f,rootBoundary:u}),x=l(await o.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===m?{...i.floating,x:n,y:r}:i.reference,offsetParent:await o.getOffsetParent({element:s.floating}),strategy:c}));return{top:h.top-x.top+y.top,bottom:x.bottom-h.bottom+y.bottom,left:h.left-x.left+y.left,right:x.right-h.right+y.right}}function c(e,t,n){return Math.max(e,Math.min(t,n))}const f={left:"right",right:"left",bottom:"top",top:"bottom"};function u(e){return e.replace(/left|right|bottom|top/g,(e=>f[e]))}function m(e,t){const i="start"===n(e),a=r(e),l=o(a);let s="x"===a?i?"right":"left":i?"bottom":"top";return t.reference[l]>t.floating[l]&&(s=u(s)),{main:s,cross:u(s)}}const d={start:"end",end:"start"};function p(e){return e.replace(/start|end/g,(e=>d[e]))}const y=["top","right","bottom","left"],g=y.reduce(((e,t)=>e.concat(t,t+"-start",t+"-end")),[]);function h(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function x(e){return y.some((t=>e[t]>=0))}function w(e){return"x"===e?"y":"x"}e.arrow=e=>({name:"arrow",async fn(n){const{element:i,padding:l=0}=null!=e?e:{},{x:s,y:f,placement:u,rects:m,platform:d}=n;if(null==i)return{};const p=a(l),y={x:s,y:f},g=r(t(u)),h=o(g),x=await d.getDimensions({element:i}),w="y"===g?"top":"left",b="y"===g?"bottom":"right",v=m.reference[h]+m.reference[g]-y[g]-m.floating[h],A=y[g]-m.reference[g],P=await d.getOffsetParent({element:i}),k=P?"y"===g?P.clientHeight||0:P.clientWidth||0:0,D=v/2-A/2,O=p[w],R=k-x[h]-p[b],C=k/2-x[h]/2+D,E=c(O,C,R);return{data:{[g]:E,centerOffset:C-E}}}}),e.autoPlacement=function(e){return void 0===e&&(e={}),{name:"autoPlacement",async fn(r){var o,i,a,l,c,f;const{x:u,y:d,rects:y,middlewareData:h,placement:x}=r,{alignment:w=null,crossAxis:b=!1,allowedPlacements:v=g,autoAlignment:A=!0,...P}=e;if(null!=(o=h.autoPlacement)&&o.skip)return{};const k=function(e,r,o){return o.filter((o=>e?n(o)===e||!!r&&p(o)!==o:t(o)===o))}(w,A,v),D=await s(r,P),O=null!=(i=null==(a=h.autoPlacement)?void 0:a.index)?i:0,R=k[O],{main:C,cross:E}=m(R,y);if(x!==R)return{x:u,y:d,reset:{placement:k[0]}};const B=[D[t(R)],D[C],D[E]],T=[...null!=(l=null==(c=h.autoPlacement)?void 0:c.overflows)?l:[],{placement:R,overflows:B}],j=k[O+1];if(j)return{data:{index:O+1,overflows:T},reset:{placement:j}};const z=T.slice().sort(b||A&&n(x)?(e,t)=>e.overflows.reduce(((e,t)=>e+t),0)-t.overflows.reduce(((e,t)=>e+t),0):(e,t)=>e.overflows[0]-t.overflows[0]),F=null==(f=z.find((e=>{let{overflows:t}=e;return t.every((e=>e<=0))})))?void 0:f.placement;return{data:{skip:!0},reset:{placement:null!=F?F:z[0].placement}}}}},e.computePosition=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:a=[],platform:l}=n;let s=await l.getElementRects({reference:e,floating:t,strategy:o}),{x:c,y:f}=i({...s,placement:r}),u=r,m={};for(let n=0;n<a.length;n++){0===n&&({x:c,y:f}=i({...s,placement:u}));const{name:d,fn:p}=a[n],{x:y,y:g,data:h,reset:x}=await p({x:c,y:f,initialPlacement:r,placement:u,strategy:o,middlewareData:m,rects:s,platform:l,elements:{reference:e,floating:t}});c=null!=y?y:c,f=null!=g?g:f,m={...m,[d]:null!=h?h:{}},x&&("object"==typeof x&&x.placement&&(u=x.placement),s=await l.getElementRects({reference:e,floating:t,strategy:o}),n=-1)}return{x:c,y:f,placement:u,strategy:o,middlewareData:m}},e.detectOverflow=s,e.flip=function(e){return void 0===e&&(e={}),{name:"flip",async fn(n){var r,o;const{placement:i,middlewareData:a,rects:l,initialPlacement:c}=n;if(null!=(r=a.flip)&&r.skip)return{};const{mainAxis:f=!0,crossAxis:d=!0,fallbackPlacements:y,fallbackStrategy:g="bestFit",flipAlignment:h=!0,...x}=e,w=t(i),b=y||(w===c||!h?[u(c)]:function(e){const t=u(e);return[p(e),t,p(t)]}(c)),v=[c,...b],A=await s(n,x),P=[];let k=(null==(o=a.flip)?void 0:o.overflows)||[];if(f&&P.push(A[w]),d){const{main:e,cross:t}=m(i,l);P.push(A[e],A[t])}if(k=[...k,{placement:i,overflows:P}],!P.every((e=>e<=0))){var D,O;const e=(null!=(D=null==(O=a.flip)?void 0:O.index)?D:0)+1,t=v[e];if(t)return{data:{index:e,overflows:k},reset:{placement:t}};let n="bottom";switch(g){case"bestFit":{var R;const e=null==(R=k.slice().sort(((e,t)=>e.overflows.filter((e=>e>0)).reduce(((e,t)=>e+t),0)-t.overflows.filter((e=>e>0)).reduce(((e,t)=>e+t),0)))[0])?void 0:R.placement;e&&(n=e);break}case"initialPlacement":n=c}return{data:{skip:!0},reset:{placement:n}}}return{}}}},e.hide=()=>({name:"hide",async fn(e){const t=await s(e,{elementContext:"reference"}),n=await s(e,{altBoundary:!0}),r=h(t,e.rects.reference),o=h(n,e.rects.floating);return{data:{referenceHidden:x(r),referenceHiddenOffsets:r,escaped:x(o),escapedOffsets:o}}}}),e.limitShift=function(e){return void 0===e&&(e={}),n=>{const{x:o,y:i,placement:a,rects:l,middlewareData:s}=n,{offset:c=0,mainAxis:f=!0,crossAxis:u=!0}=e,m={x:o,y:i},d=r(t(a)),p=w(d);let y=m[d],g=m[p];const h="function"==typeof c?c({...l,placement:a}):c,x="number"==typeof h?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(f){const e="y"===d?"height":"width",t=l.reference[d]-l.floating[e]+x.mainAxis,n=l.reference[d]+l.reference[e]-x.mainAxis;y<t?y=t:y>n&&(y=n)}if(u){var b,v,A,P;const e="y"===d?"width":"height",t=l.reference[p]-l.floating[e]-(null!=(b=null==(v=s.offset)?void 0:v[d])?b:0)+x.crossAxis,n=l.reference[p]+l.reference[e]+(null!=(A=null==(P=s.offset)?void 0:P[d])?A:0)+x.crossAxis;g<t?g=t:g>n&&(g=n)}return{[d]:y,[p]:g}}},e.offset=function(e){return void 0===e&&(e=0),{name:"offset",fn(n){const{x:o,y:i,placement:a,rects:l}=n,s=function(e){let{placement:n,rects:o,value:i}=e;const a=t(n),l=["left","top"].includes(a)?-1:1,s="function"==typeof i?i({...o,placement:n}):i,{mainAxis:c,crossAxis:f}="number"==typeof s?{mainAxis:s,crossAxis:0}:{mainAxis:0,crossAxis:0,...s};return"x"===r(a)?{x:f,y:c*l}:{x:c*l,y:f}}({placement:a,rects:l,value:e});return{x:o+s.x,y:i+s.y,data:s}}}},e.rectToClientRect=l,e.shift=function(e){return void 0===e&&(e={}),{name:"shift",async fn(n){const{x:o,y:i,placement:a}=n,{mainAxis:l=!0,crossAxis:f=!1,limiter:u=(e=>{let{x:t,y:n}=e;return{x:t,y:n}}),...m}=e,d={x:o,y:i},p=await s(n,m),y=r(t(a)),g=w(y);let h=d[y],x=d[g];if(l){const e="y"===y?"bottom":"right";h=c(h+p["y"===y?"top":"left"],h,h-p[e])}if(f){const e="y"===g?"bottom":"right";x=c(x+p["y"===g?"top":"left"],x,x-p[e])}return u({...n,[y]:h,[g]:x})}}},e.size=function(e){return void 0===e&&(e={}),{name:"size",async fn(r){var o;const{placement:i,rects:a,middlewareData:l}=r,{apply:c,...f}=e,u=await s(r,f),m=t(i),d="end"===n(i);let p,y;"top"===m||"bottom"===m?(p=m,y=d?"left":"right"):(y=m,p=d?"top":"bottom");const g={height:a.floating.height-u[p],width:a.floating.width-u[y]};return null!=(o=l.size)&&o.skip?{}:(null==c||c(g),{data:{skip:!0},reset:!0})}}},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@floating-ui/core",
"version": "0.1.4",
"version": "0.1.5",
"description": "Positioning library for floating elements: tooltips, popovers, dropdowns, and more",

@@ -8,2 +8,7 @@ "main": "dist/floating-ui.core.js",

"unpkg": "dist/floating-ui.core.min.js",
"type": "module",
"exports": {
"import": "./dist/floating-ui.core.esm.js",
"require": "./dist/floating-ui.core.js"
},
"sideEffects": false,

@@ -10,0 +15,0 @@ "files": [

@@ -20,3 +20,3 @@ import type { Placement, Rect, Coords, Middleware } from '../types';

}): Coords;
export declare const offset: (value: Offset) => Middleware;
export declare const offset: (value?: Offset) => Middleware;
export {};

@@ -13,3 +13,9 @@ import type { Middleware, Rect, Placement, MiddlewareArguments, Coords } from '../types';

reference: Rect;
}) => number) | number;
}) => number | {
mainAxis?: number;
crossAxis?: number;
}) | number | {
mainAxis?: number;
crossAxis?: number;
};
export declare type LimitShiftOptions = {

@@ -16,0 +22,0 @@ offset: LimitShiftOffset;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc