New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thisway/utils

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thisway/utils - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0-beta.0

lib/bounding.d.ts

4

index.d.ts

@@ -12,1 +12,5 @@ export * from './lib/animation-frame-throttle';

export * from './lib/transform';
export * from './lib/bounding';
export * from './lib/function';
export * from './lib/scroll';
export * from './lib/hierarchy';

@@ -1,8 +0,9 @@

import { derived as E } from "svelte/store";
function T(e) {
let t = !1;
import { derived as ht } from "svelte/store";
import { checkElementType as mt, getScrollingElement as dt } from "@thisway/utils";
function Ft(t) {
let e = !1;
return () => {
t || (t = !0, requestAnimationFrame(() => {
e || (e = !0, requestAnimationFrame(() => {
requestAnimationFrame(() => {
e(), t = !1;
t(), e = !1;
});

@@ -12,53 +13,55 @@ }));

}
function g(e) {
return Number.isFinite(e) ? `${e}px` : "";
function Et(t) {
return Number.isFinite(t) ? `${t}px` : "";
}
function b(e) {
return e && Number.isFinite(e) ? e : 0;
function kt(t) {
return t && Number.isFinite(t) ? t : 0;
}
const { hasOwn: I } = Object;
function h(e, t) {
for (const n in t) {
if (!I(t, n))
const { hasOwn: gt } = Object;
function Yt(t, e) {
for (const n in e) {
if (!gt(e, n))
continue;
const r = t[n], i = e[n];
e[n] = i === "" ? r : i ?? r;
const r = e[n], o = t[n];
t[n] = o === "" ? r : o ?? r;
}
return e;
return t;
}
const O = (e) => {
let t, n;
return (r) => (r === t && n || (t = r, n = e(t)), n);
const Dt = (t) => {
let e, n;
return (r) => (r === e && n || (e = r, n = t(e)), n);
};
function F(e, t, n) {
return E(e, (r) => (r == null ? void 0 : r[t]) ?? n);
function At(t, e, n) {
return ht(t, (r) => (r == null ? void 0 : r[e]) ?? n);
}
const x = (e, t, n) => e < t ? t : e > n ? n : e, p = (e, t) => {
const n = new ResizeObserver(t);
return n.observe(e), () => n.disconnect();
}, y = {
const Ct = (t, e, n) => t < e ? e : t > n ? n : t, Lt = (t, e) => {
const n = new ResizeObserver(e);
return n.observe(t), () => n.disconnect();
}, Xt = {
width: 0,
height: 0
}, Y = (e) => Number.isFinite(e), A = (e, t) => e instanceof Node ? !0 : t ? e instanceof t.Node : !1, R = (e) => e.nodeType === Node.ELEMENT_NODE;
function _(e) {
return ["INPUT", "TEXTAREA"].includes(e.tagName) || ["text", "vertical-text"].includes(getComputedStyle(e).cursor);
}, _t = (t) => Number.isFinite(t), Pt = (t, e) => t instanceof Node ? !0 : e ? t instanceof e.Node : !1, St = (t) => t.nodeType === Node.ELEMENT_NODE;
function Vt(t) {
return ["INPUT", "TEXTAREA"].includes(t.tagName) || ["text", "vertical-text"].includes(getComputedStyle(t).cursor);
}
function v(e, t) {
return e.tagName === t.toUpperCase();
function bt(t) {
return (e) => e.tagName === t.toUpperCase();
}
function P(e) {
return e.scrollingElement || e.documentElement;
function pt() {
}
function S(e) {
let t = Number.POSITIVE_INFINITY, n = Number.POSITIVE_INFINITY, r = Number.NEGATIVE_INFINITY, i = Number.NEGATIVE_INFINITY;
for (const a of e) {
const { x: m, y: f, right: N, bottom: l } = a.getBoundingClientRect();
m < t && (t = m), f < n && (n = f), N > r && (r = N), l > i && (i = l);
function ft(t) {
return t.scrollingElement || t.documentElement;
}
function $t(t) {
let e = Number.POSITIVE_INFINITY, n = Number.POSITIVE_INFINITY, r = Number.NEGATIVE_INFINITY, o = Number.NEGATIVE_INFINITY;
for (const m of t) {
const { x: d, y: g, right: N, bottom: b } = m.getBoundingClientRect();
d < e && (e = d), g < n && (n = g), N > r && (r = N), b > o && (o = b);
}
const o = t, u = n, c = r - t, s = i - n;
return new DOMRectReadOnly(o, u, c, s);
const i = e, c = n, l = r - e, p = o - n;
return new DOMRectReadOnly(i, c, l, p);
}
function V(e) {
function Nt(t) {
try {
return e == null ? void 0 : e.frameElement;
return t == null ? void 0 : t.frameElement;
} catch {

@@ -68,45 +71,292 @@ return;

}
const X = [1, 0, 0, 1, 0, 0];
function z(e) {
const [t, n, r, i] = e;
return [t, n, r, i, 0, 0];
function ot(t) {
const e = ft(t.ownerDocument), n = t.ownerDocument.defaultView;
let r = t === e ? Nt(n) : t.parentElement;
if (!r) {
const o = t.getRootNode();
o !== t.ownerDocument && (r = o.host);
}
return r;
}
function M(e, t, n) {
return n[0] * e + n[2] * t + n[4];
function C(t, e, n) {
if (!t)
return pt;
const r = {
passive: !0,
capture: !0
};
return t.addEventListener(e, n, r), () => {
t.removeEventListener(e, n, r);
};
}
function C(e, t, n) {
return n[1] * e + n[3] * t + n[5];
const qt = [1, 0, 0, 1, 0, 0];
function wt(t) {
const [e, n, r, o] = t;
return [e, n, r, o, 0, 0];
}
function q(e, t, n) {
const [r, i, o, u, c, s] = n;
return (u * e - o * t + o * s - u * c) / (r * u - i * o);
function it(t, e, n) {
return n[0] * t + n[2] * e + n[4];
}
function B(e, t, n) {
const [r, i, o, u, c, s] = n;
return (r * t - i * e + i * c - r * s) / (r * u - o * i);
function ct(t, e, n) {
return n[1] * t + n[3] * e + n[5];
}
function zt(t, e, n) {
const [r, o, i, c, l, p] = n;
return (c * t - i * e + i * p - c * l) / (r * c - o * i);
}
function Gt(t, e, n) {
const [r, o, i, c, l, p] = n;
return (r * e - o * t + o * l - r * p) / (r * c - i * o);
}
function yt(t) {
for (const e of t)
try {
e();
} catch (n) {
console.error(n);
}
}
function Ut(t, e, n) {
const r = new ResizeObserver(n), o = [];
for (const i of t)
r.observe(i);
for (const i of e) {
const c = i.contentWindow;
o.push(C(c, "resize", n), C(c, "scroll", n));
}
return o.push(C(window, "resize", n), C(window, "scroll", n)), () => {
yt(o);
};
}
function Zt(t, e) {
let { x: n, y: r, width: o, height: i } = t;
n = it(n, r, e), r = ct(n, r, e);
const c = wt(e);
return o = it(o, 0, c), i = ct(0, i, c), new DOMRectReadOnly(n, r, o, i);
}
function L(t, e, n, r, o, i, c, l) {
return i < t && c > e || i > t && c < e ? 0 : i <= t && l <= n || c >= e && l >= n ? i - t - r : c > e && l < n || i < t && l > n ? c - e + o : 0;
}
function Tt(t, e) {
const n = typeof e == "function" ? e : (i) => i !== e, r = [];
let o = ot(t);
for (; o && n(o); )
r.push(o), o = ot(o);
return r;
}
function It(t) {
return (e) => {
const n = ft(e.ownerDocument);
return e === n ? !0 : e === e.ownerDocument.body && G(e) && !G(n) ? !1 : !!G(e, t);
};
}
function st(t, e) {
return e && t === "hidden" ? !1 : t !== "visible" && t !== "clip";
}
const Rt = mt("iframe");
function G(t, e) {
if (Rt(t))
return !1;
if (t.clientHeight < t.scrollHeight || t.clientWidth < t.scrollWidth) {
const n = getComputedStyle(t, null);
return st(n.overflowY, e) || st(n.overflowX, e);
}
return !1;
}
function Ot(t, e) {
for (let n = e.length - 1; n >= 0; n--) {
const r = e[n], o = r.getBoundingClientRect(), i = o.width / r.offsetWidth, c = o.height / r.offsetHeight;
t = new DOMRectReadOnly(
t.x * i + o.x,
t.y * c + o.y,
t.width * i,
t.height * c
);
}
return t;
}
const { parseInt: X, parseFloat: _ } = Number;
function xt(t) {
const e = window.getComputedStyle(t);
return {
top: _(e.scrollMarginTop) || 0,
right: _(e.scrollMarginRight) || 0,
bottom: _(e.scrollMarginBottom) || 0,
left: _(e.scrollMarginLeft) || 0
};
}
function Wt(t, e, n, r) {
var Q, j, tt, et;
if (t.length === 0)
return [];
const o = t[0].ownerDocument.defaultView;
if (!o)
return [];
const { scrollX: i, scrollY: c, innerWidth: l, innerHeight: p, visualViewport: m } = o, d = (m == null ? void 0 : m.width) ?? l, g = (m == null ? void 0 : m.height) ?? p, N = Ot(n.getBoundingClientRect(), e), b = N.top - (((Q = r.offset) == null ? void 0 : Q.top) ?? 0), R = N.bottom + (((j = r.offset) == null ? void 0 : j.bottom) ?? 0), w = N.left - (((tt = r.offset) == null ? void 0 : tt.left) ?? 0), O = N.right + (((et = r.offset) == null ? void 0 : et.right) ?? 0), y = R - b, T = O - w, { scrollMode: ut, block: I, inline: x } = r, { top: U, right: Z, bottom: J, left: K } = xt(n);
let a = I === "start" || I === "nearest" ? b - U : I === "end" ? R + J : b + y / 2 - U + J, h = x === "center" ? w + T / 2 - K + Z : x === "end" ? O + Z : w - K;
const P = [];
for (let S = 0; S < t.length; S++) {
const s = t[S], { height: W, width: M, top: B, right: V, bottom: $, left: H } = s.getBoundingClientRect();
if (ut === "if-needed" && b >= 0 && w >= 0 && R <= g && O <= d && b >= B && R <= $ && w >= H && O <= V)
return P;
const v = getComputedStyle(s), F = X(v.borderLeftWidth, 10), E = X(v.borderTopWidth, 10), k = X(v.borderRightWidth, 10), Y = X(v.borderBottomWidth, 10);
let f = 0, u = 0;
const D = "offsetWidth" in s ? s.offsetWidth - s.clientWidth - F - k : 0, A = "offsetHeight" in s ? s.offsetHeight - s.clientHeight - E - Y : 0, q = "offsetWidth" in s ? s.offsetWidth === 0 ? 0 : M / s.offsetWidth : 0, z = "offsetHeight" in s ? s.offsetHeight === 0 ? 0 : W / s.offsetHeight : 0;
if (dt(s.ownerDocument) === s) {
switch (I) {
case "start": {
f = a;
break;
}
case "end": {
f = a - g;
break;
}
case "nearest": {
f = L(
c,
c + g,
g,
E,
Y,
c + a,
c + a + y,
y
);
break;
}
default:
f = a - g / 2;
}
switch (x) {
case "start": {
u = h;
break;
}
case "center": {
u = h - d / 2;
break;
}
case "end": {
u = h - d;
break;
}
default:
u = L(
i,
i + d,
d,
F,
k,
i + h,
i + h + T,
T
);
}
f = Math.max(0, f + c), u = Math.max(0, u + i);
} else {
switch (I) {
case "start": {
f = a - B - E;
break;
}
case "end": {
f = a - $ + Y + A;
break;
}
case "nearest": {
f = L(
B,
$,
W,
E,
Y + A,
a,
a + y,
y
);
break;
}
default:
f = a - (B + W / 2) + A / 2;
}
switch (x) {
case "start": {
u = h - H - F;
break;
}
case "center": {
u = h - (H + M / 2) + D / 2;
break;
}
case "end": {
u = h - V + k + D;
break;
}
default:
u = L(
H,
V,
M,
F,
k + D,
h,
h + T,
T
);
}
const { scrollLeft: nt, scrollTop: rt, scrollHeight: lt, scrollWidth: at } = s;
f = z === 0 ? 0 : Math.max(0, Math.min(rt + f / z, lt - W / z + A)), u = q === 0 ? 0 : Math.max(0, Math.min(nt + u / q, at - M / q + D)), a += rt - f, h += nt - u;
}
P.push({
el: s,
top: f,
left: u
});
}
return P;
}
function Mt(t, e, n) {
const r = Tt(t, n), o = r.filter(It(e)), i = r.filter(bt("iframe"));
return [o, i];
}
function Jt(t, e) {
const { skipOverflowHiddenElements: n, boundary: r } = e, [o, i] = Mt(t, n, r);
return Wt(o, i, t, e);
}
export {
y as EMPTY_SIZE,
X as NOOP_TRANSFORM,
T as animationFrameThrottle,
v as checkElementType,
x as clamp,
h as defaults,
z as deltaTransform,
b as finite,
S as getElementsBounding,
V as getFrameElement,
P as getScrollingElement,
R as isElement,
A as isNode,
_ as isTextInputElement,
Y as isValidNumber,
O as memoize,
F as pick$,
p as resizeObserver,
q as reverseX,
B as reverseY,
g as toPx,
M as transformX,
C as transformY
Xt as EMPTY_SIZE,
qt as NOOP_TRANSFORM,
Ft as animationFrameThrottle,
Tt as buildHierarchy,
Mt as buildScrollHierarchy,
bt as checkElementType,
Ct as clamp,
Wt as computeFrameScrollActions,
Jt as computeScrollIntoView,
Yt as defaults,
wt as deltaTransform,
kt as finite,
$t as getElementsBounding,
Nt as getFrameElement,
ot as getParentElement,
ft as getScrollingElement,
St as isElement,
Pt as isNode,
It as isScrollableElement,
Vt as isTextInputElement,
_t as isValidNumber,
C as listenWindow,
Dt as memoize,
Ut as observeElementBounding,
At as pick$,
Lt as resizeObserver,
zt as reverseX,
Gt as reverseY,
yt as runAll,
Et as toPx,
Zt as transformDOMRect,
Ot as transformNestedBounding,
it as transformX,
ct as transformY
};
export declare function getScrollingElement(document: Document): Element;
export declare function getElementsBounding(elements: readonly Element[]): DOMRectReadOnly;
export declare function getFrameElement(window: Window | null | undefined): Element | null | undefined;
export declare function getParentElement(element: Element): Element | null | undefined;
export declare function listenWindow<K extends keyof WindowEventMap>(target: Window | undefined | null, key: K, callback: (event: WindowEventMap[K]) => void): () => void;

4

lib/is.d.ts

@@ -13,3 +13,3 @@ export declare const isValidNumber: (value: number | null | undefined) => value is number;

export declare const isElement: (value: Node) => value is Element;
export declare function isTextInputElement(el: Element): boolean;
export declare function checkElementType<K extends keyof HTMLElementTagNameMap>(node: Element, key: K): node is HTMLElementTagNameMap[K];
export declare function isTextInputElement(element: Element): boolean;
export declare function checkElementType<K extends keyof HTMLElementTagNameMap>(key: K): (node: Element) => node is HTMLElementTagNameMap[K];
{
"name": "@thisway/utils",
"version": "0.4.2",
"version": "0.5.0-beta.0",
"type": "module",

@@ -5,0 +5,0 @@ "dependencies": {},

Sorry, the diff of this file is not supported yet

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