@anoki/fse-ui
Version:
FSE UI components library
405 lines (404 loc) • 11.1 kB
JavaScript
import { computePosition as st, offset as rt, shift as ct, flip as lt, size as ft, hide as ut, arrow as ht, limitShift as at } from "./index.es802.js";
import { createCoords as y, round as z, max as E, min as N, rectToClientRect as J, floor as D } from "./index.es803.js";
import { isElement as v, getDocumentElement as b, getOverflowAncestors as $, getComputedStyle as R, isHTMLElement as T, getWindow as O, isTopLayer as V, getParentNode as S, isLastTraversableNode as A, isTableElement as dt, isContainingBlock as Q, getContainingBlock as gt, getNodeName as _, isOverflowElement as q, getNodeScroll as H, getFrameElement as U, isWebKit as Y } from "./index.es804.js";
function Z(t) {
const e = R(t);
let i = parseFloat(e.width) || 0, o = parseFloat(e.height) || 0;
const n = T(t), r = n ? t.offsetWidth : i, s = n ? t.offsetHeight : o, c = z(i) !== r || z(o) !== s;
return c && (i = r, o = s), {
width: i,
height: o,
$: c
};
}
function X(t) {
return v(t) ? t : t.contextElement;
}
function F(t) {
const e = X(t);
if (!T(e))
return y(1);
const i = e.getBoundingClientRect(), {
width: o,
height: n,
$: r
} = Z(e);
let s = (r ? z(i.width) : i.width) / o, c = (r ? z(i.height) : i.height) / n;
return (!s || !Number.isFinite(s)) && (s = 1), (!c || !Number.isFinite(c)) && (c = 1), {
x: s,
y: c
};
}
const pt = /* @__PURE__ */ y(0);
function tt(t) {
const e = O(t);
return !Y() || !e.visualViewport ? pt : {
x: e.visualViewport.offsetLeft,
y: e.visualViewport.offsetTop
};
}
function mt(t, e, i) {
return e === void 0 && (e = !1), !i || e && i !== O(t) ? !1 : e;
}
function L(t, e, i, o) {
e === void 0 && (e = !1), i === void 0 && (i = !1);
const n = t.getBoundingClientRect(), r = X(t);
let s = y(1);
e && (o ? v(o) && (s = F(o)) : s = F(t));
const c = mt(r, i, o) ? tt(r) : y(0);
let l = (n.left + c.x) / s.x, f = (n.top + c.y) / s.y, u = n.width / s.x, a = n.height / s.y;
if (r) {
const d = O(r), h = o && v(o) ? O(o) : o;
let m = d, p = U(m);
for (; p && o && h !== m; ) {
const w = F(p), g = p.getBoundingClientRect(), x = R(p), C = g.left + (p.clientLeft + parseFloat(x.paddingLeft)) * w.x, W = g.top + (p.clientTop + parseFloat(x.paddingTop)) * w.y;
l *= w.x, f *= w.y, u *= w.x, a *= w.y, l += C, f += W, m = O(p), p = U(m);
}
}
return J({
width: u,
height: a,
x: l,
y: f
});
}
function I(t, e) {
const i = H(t).scrollLeft;
return e ? e.left + i : L(b(t)).left + i;
}
function et(t, e) {
const i = t.getBoundingClientRect(), o = i.left + e.scrollLeft - I(t, i), n = i.top + e.scrollTop;
return {
x: o,
y: n
};
}
function wt(t) {
let {
elements: e,
rect: i,
offsetParent: o,
strategy: n
} = t;
const r = n === "fixed", s = b(o), c = e ? V(e.floating) : !1;
if (o === s || c && r)
return i;
let l = {
scrollLeft: 0,
scrollTop: 0
}, f = y(1);
const u = y(0), a = T(o);
if ((a || !a && !r) && ((_(o) !== "body" || q(s)) && (l = H(o)), a)) {
const h = L(o);
f = F(o), u.x = h.x + o.clientLeft, u.y = h.y + o.clientTop;
}
const d = s && !a && !r ? et(s, l) : y(0);
return {
width: i.width * f.x,
height: i.height * f.y,
x: i.x * f.x - l.scrollLeft * f.x + u.x + d.x,
y: i.y * f.y - l.scrollTop * f.y + u.y + d.y
};
}
function yt(t) {
return Array.from(t.getClientRects());
}
function xt(t) {
const e = b(t), i = H(t), o = t.ownerDocument.body, n = E(e.scrollWidth, e.clientWidth, o.scrollWidth, o.clientWidth), r = E(e.scrollHeight, e.clientHeight, o.scrollHeight, o.clientHeight);
let s = -i.scrollLeft + I(t);
const c = -i.scrollTop;
return R(o).direction === "rtl" && (s += E(e.clientWidth, o.clientWidth) - n), {
width: n,
height: r,
x: s,
y: c
};
}
const K = 25;
function vt(t, e) {
const i = O(t), o = b(t), n = i.visualViewport;
let r = o.clientWidth, s = o.clientHeight, c = 0, l = 0;
if (n) {
r = n.width, s = n.height;
const u = Y();
(!u || u && e === "fixed") && (c = n.offsetLeft, l = n.offsetTop);
}
const f = I(o);
if (f <= 0) {
const u = o.ownerDocument, a = u.body, d = getComputedStyle(a), h = u.compatMode === "CSS1Compat" && parseFloat(d.marginLeft) + parseFloat(d.marginRight) || 0, m = Math.abs(o.clientWidth - a.clientWidth - h);
m <= K && (r -= m);
} else f <= K && (r += f);
return {
width: r,
height: s,
x: c,
y: l
};
}
function Rt(t, e) {
const i = L(t, !0, e === "fixed"), o = i.top + t.clientTop, n = i.left + t.clientLeft, r = T(t) ? F(t) : y(1), s = t.clientWidth * r.x, c = t.clientHeight * r.y, l = n * r.x, f = o * r.y;
return {
width: s,
height: c,
x: l,
y: f
};
}
function j(t, e, i) {
let o;
if (e === "viewport")
o = vt(t, i);
else if (e === "document")
o = xt(b(t));
else if (v(e))
o = Rt(e, i);
else {
const n = tt(t);
o = {
x: e.x - n.x,
y: e.y - n.y,
width: e.width,
height: e.height
};
}
return J(o);
}
function it(t, e) {
const i = S(t);
return i === e || !v(i) || A(i) ? !1 : R(i).position === "fixed" || it(i, e);
}
function bt(t, e) {
const i = e.get(t);
if (i)
return i;
let o = $(t, [], !1).filter((c) => v(c) && _(c) !== "body"), n = null;
const r = R(t).position === "fixed";
let s = r ? S(t) : t;
for (; v(s) && !A(s); ) {
const c = R(s), l = Q(s);
!l && c.position === "fixed" && (n = null), (r ? !l && !n : !l && c.position === "static" && !!n && (n.position === "absolute" || n.position === "fixed") || q(s) && !l && it(t, s)) ? o = o.filter((u) => u !== s) : n = c, s = S(s);
}
return e.set(t, o), o;
}
function Ct(t) {
let {
element: e,
boundary: i,
rootBoundary: o,
strategy: n
} = t;
const s = [...i === "clippingAncestors" ? V(e) ? [] : bt(e, this._c) : [].concat(i), o], c = j(e, s[0], n);
let l = c.top, f = c.right, u = c.bottom, a = c.left;
for (let d = 1; d < s.length; d++) {
const h = j(e, s[d], n);
l = E(h.top, l), f = N(h.right, f), u = N(h.bottom, u), a = E(h.left, a);
}
return {
width: f - a,
height: u - l,
x: a,
y: l
};
}
function Ot(t) {
const {
width: e,
height: i
} = Z(t);
return {
width: e,
height: i
};
}
function Lt(t, e, i) {
const o = T(e), n = b(e), r = i === "fixed", s = L(t, !0, r, e);
let c = {
scrollLeft: 0,
scrollTop: 0
};
const l = y(0);
function f() {
l.x = I(n);
}
if (o || !o && !r)
if ((_(e) !== "body" || q(n)) && (c = H(e)), o) {
const h = L(e, !0, r, e);
l.x = h.x + e.clientLeft, l.y = h.y + e.clientTop;
} else n && f();
r && !o && n && f();
const u = n && !o && !r ? et(n, c) : y(0), a = s.left + c.scrollLeft - l.x - u.x, d = s.top + c.scrollTop - l.y - u.y;
return {
x: a,
y: d,
width: s.width,
height: s.height
};
}
function M(t) {
return R(t).position === "static";
}
function G(t, e) {
if (!T(t) || R(t).position === "fixed")
return null;
if (e)
return e(t);
let i = t.offsetParent;
return b(t) === i && (i = i.ownerDocument.body), i;
}
function ot(t, e) {
const i = O(t);
if (V(t))
return i;
if (!T(t)) {
let n = S(t);
for (; n && !A(n); ) {
if (v(n) && !M(n))
return n;
n = S(n);
}
return i;
}
let o = G(t, e);
for (; o && dt(o) && M(o); )
o = G(o, e);
return o && A(o) && M(o) && !Q(o) ? i : o || gt(t) || i;
}
const Tt = async function(t) {
const e = this.getOffsetParent || ot, i = this.getDimensions, o = await i(t.floating);
return {
reference: Lt(t.reference, await e(t.floating), t.strategy),
floating: {
x: 0,
y: 0,
width: o.width,
height: o.height
}
};
};
function Et(t) {
return R(t).direction === "rtl";
}
const Ft = {
convertOffsetParentRelativeRectToViewportRelativeRect: wt,
getDocumentElement: b,
getClippingRect: Ct,
getOffsetParent: ot,
getElementRects: Tt,
getClientRects: yt,
getDimensions: Ot,
getScale: F,
isElement: v,
isRTL: Et
};
function nt(t, e) {
return t.x === e.x && t.y === e.y && t.width === e.width && t.height === e.height;
}
function St(t, e) {
let i = null, o;
const n = b(t);
function r() {
var c;
clearTimeout(o), (c = i) == null || c.disconnect(), i = null;
}
function s(c, l) {
c === void 0 && (c = !1), l === void 0 && (l = 1), r();
const f = t.getBoundingClientRect(), {
left: u,
top: a,
width: d,
height: h
} = f;
if (c || e(), !d || !h)
return;
const m = D(a), p = D(n.clientWidth - (u + d)), w = D(n.clientHeight - (a + h)), g = D(u), C = {
rootMargin: -m + "px " + -p + "px " + -w + "px " + -g + "px",
threshold: E(0, N(1, l)) || 1
};
let W = !0;
function k(P) {
const B = P[0].intersectionRatio;
if (B !== l) {
if (!W)
return s();
B ? s(!1, B) : o = setTimeout(() => {
s(!1, 1e-7);
}, 1e3);
}
B === 1 && !nt(f, t.getBoundingClientRect()) && s(), W = !1;
}
try {
i = new IntersectionObserver(k, {
...C,
// Handle <iframe>s
root: n.ownerDocument
});
} catch {
i = new IntersectionObserver(k, C);
}
i.observe(t);
}
return s(!0), r;
}
function zt(t, e, i, o) {
o === void 0 && (o = {});
const {
ancestorScroll: n = !0,
ancestorResize: r = !0,
elementResize: s = typeof ResizeObserver == "function",
layoutShift: c = typeof IntersectionObserver == "function",
animationFrame: l = !1
} = o, f = X(t), u = n || r ? [...f ? $(f) : [], ...e ? $(e) : []] : [];
u.forEach((g) => {
n && g.addEventListener("scroll", i, {
passive: !0
}), r && g.addEventListener("resize", i);
});
const a = f && c ? St(f, i) : null;
let d = -1, h = null;
s && (h = new ResizeObserver((g) => {
let [x] = g;
x && x.target === f && h && e && (h.unobserve(e), cancelAnimationFrame(d), d = requestAnimationFrame(() => {
var C;
(C = h) == null || C.observe(e);
})), i();
}), f && !l && h.observe(f), e && h.observe(e));
let m, p = l ? L(t) : null;
l && w();
function w() {
const g = L(t);
p && !nt(p, g) && i(), p = g, m = requestAnimationFrame(w);
}
return i(), () => {
var g;
u.forEach((x) => {
n && x.removeEventListener("scroll", i), r && x.removeEventListener("resize", i);
}), a == null || a(), (g = h) == null || g.disconnect(), h = null, l && cancelAnimationFrame(m);
};
}
const At = rt, Ht = ct, It = lt, Mt = ft, Nt = ut, $t = ht, Vt = at, _t = (t, e, i) => {
const o = /* @__PURE__ */ new Map(), n = {
platform: Ft,
...i
}, r = {
...n.platform,
_c: o
};
return st(t, e, {
...n,
platform: r
});
};
export {
$t as arrow,
zt as autoUpdate,
_t as computePosition,
It as flip,
$ as getOverflowAncestors,
Nt as hide,
Vt as limitShift,
At as offset,
Ft as platform,
Ht as shift,
Mt as size
};
//# sourceMappingURL=index.es729.js.map