@zag-js/dom-utils
Advanced tools
Comparing version 0.0.0-dev-20220413175519 to 0.0.0-dev-20220415160434
@@ -0,4 +1,6 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -18,2 +20,3 @@ var __pow = Math.pow; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
@@ -105,3 +108,7 @@ | ||
// src/computed-style.ts | ||
var styleCache = /* @__PURE__ */ new WeakMap(); | ||
function getStyleCache() { | ||
; | ||
globalThis.__styleCache__ = globalThis.__styleCache__ || /* @__PURE__ */ new WeakMap(); | ||
return globalThis.__styleCache__; | ||
} | ||
function getComputedStyle2(el) { | ||
@@ -111,7 +118,8 @@ var _a; | ||
return {}; | ||
let style = styleCache.get(el); | ||
const cache = getStyleCache(); | ||
let style = cache.get(el); | ||
if (!style) { | ||
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
style = win.getComputedStyle(el); | ||
styleCache.set(el, style); | ||
cache.set(el, style); | ||
} | ||
@@ -184,3 +192,3 @@ return style; | ||
// ../core/src/functions.ts | ||
// ../core/dist/index.mjs | ||
var cast = (v) => v; | ||
@@ -190,4 +198,2 @@ var noop = () => { | ||
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v); | ||
// ../core/src/guard.ts | ||
var platform = (v) => isDom() && v.test(navigator.platform); | ||
@@ -205,4 +211,12 @@ var isDom = () => !!(typeof window !== "undefined"); | ||
// src/event-bus.ts | ||
var listenerElements = /* @__PURE__ */ new Map(); | ||
var listenerCache = /* @__PURE__ */ new Map(); | ||
function getListenerElements() { | ||
; | ||
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map(); | ||
return globalThis.__listenerElements__; | ||
} | ||
function getListenerCache() { | ||
; | ||
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map(); | ||
return globalThis.__listenerCache__; | ||
} | ||
function globalEventBus(node, type, handler, options) { | ||
@@ -213,2 +227,4 @@ var _a; | ||
const hash = JSON.stringify({ type, options }); | ||
const listenerElements = getListenerElements(); | ||
const listenerCache = getListenerCache(); | ||
const group = listenerElements.get(node); | ||
@@ -392,111 +408,5 @@ if (!listenerElements.has(node)) { | ||
// ../../../node_modules/compute-scroll-into-view/dist/index.module.js | ||
function t2(t3) { | ||
return typeof t3 == "object" && t3 != null && t3.nodeType === 1; | ||
} | ||
function e(t3, e2) { | ||
return (!e2 || t3 !== "hidden") && t3 !== "visible" && t3 !== "clip"; | ||
} | ||
function n(t3, n2) { | ||
if (t3.clientHeight < t3.scrollHeight || t3.clientWidth < t3.scrollWidth) { | ||
var r2 = getComputedStyle(t3, null); | ||
return e(r2.overflowY, n2) || e(r2.overflowX, n2) || function(t4) { | ||
var e2 = function(t5) { | ||
if (!t5.ownerDocument || !t5.ownerDocument.defaultView) | ||
return null; | ||
try { | ||
return t5.ownerDocument.defaultView.frameElement; | ||
} catch (t6) { | ||
return null; | ||
} | ||
}(t4); | ||
return !!e2 && (e2.clientHeight < t4.scrollHeight || e2.clientWidth < t4.scrollWidth); | ||
}(t3); | ||
} | ||
return false; | ||
} | ||
function r(t3, e2, n2, r2, i, o, l, d) { | ||
return o < t3 && l > e2 || o > t3 && l < e2 ? 0 : o <= t3 && d <= n2 || l >= e2 && d >= n2 ? o - t3 - r2 : l > e2 && d < n2 || o < t3 && d > n2 ? l - e2 + i : 0; | ||
} | ||
function index_module_default(e2, i) { | ||
var o = window, l = i.scrollMode, d = i.block, u = i.inline, h = i.boundary, a = i.skipOverflowHiddenElements, c = typeof h == "function" ? h : function(t3) { | ||
return t3 !== h; | ||
}; | ||
if (!t2(e2)) | ||
throw new TypeError("Invalid target"); | ||
for (var f = document.scrollingElement || document.documentElement, s = [], p = e2; t2(p) && c(p); ) { | ||
if ((p = p.parentElement) === f) { | ||
s.push(p); | ||
break; | ||
} | ||
p != null && p === document.body && n(p) && !n(document.documentElement) || p != null && n(p, a) && s.push(p); | ||
} | ||
for (var m = o.visualViewport ? o.visualViewport.width : innerWidth, g = o.visualViewport ? o.visualViewport.height : innerHeight, w = window.scrollX || pageXOffset, v = window.scrollY || pageYOffset, W = e2.getBoundingClientRect(), b = W.height, H = W.width, y = W.top, E = W.right, M = W.bottom, V = W.left, x = d === "start" || d === "nearest" ? y : d === "end" ? M : y + b / 2, I = u === "center" ? V + H / 2 : u === "end" ? E : V, C = [], T = 0; T < s.length; T++) { | ||
var k = s[T], B = k.getBoundingClientRect(), D = B.height, O = B.width, R = B.top, X = B.right, Y = B.bottom, L = B.left; | ||
if (l === "if-needed" && y >= 0 && V >= 0 && M <= g && E <= m && y >= R && M <= Y && V >= L && E <= X) | ||
return C; | ||
var S = getComputedStyle(k), j = parseInt(S.borderLeftWidth, 10), q = parseInt(S.borderTopWidth, 10), z = parseInt(S.borderRightWidth, 10), A = parseInt(S.borderBottomWidth, 10), F = 0, G = 0, J = "offsetWidth" in k ? k.offsetWidth - k.clientWidth - j - z : 0, K = "offsetHeight" in k ? k.offsetHeight - k.clientHeight - q - A : 0; | ||
if (f === k) | ||
F = d === "start" ? x : d === "end" ? x - g : d === "nearest" ? r(v, v + g, g, q, A, v + x, v + x + b, b) : x - g / 2, G = u === "start" ? I : u === "center" ? I - m / 2 : u === "end" ? I - m : r(w, w + m, m, j, z, w + I, w + I + H, H), F = Math.max(0, F + v), G = Math.max(0, G + w); | ||
else { | ||
F = d === "start" ? x - R - q : d === "end" ? x - Y + A + K : d === "nearest" ? r(R, Y, D, q, A + K, x, x + b, b) : x - (R + D / 2) + K / 2, G = u === "start" ? I - L - j : u === "center" ? I - (L + O / 2) + J / 2 : u === "end" ? I - X + z + J : r(L, X, O, j, z + J, I, I + H, H); | ||
var N = k.scrollLeft, P = k.scrollTop; | ||
x += P - (F = Math.max(0, Math.min(P + F, k.scrollHeight - D + K))), I += N - (G = Math.max(0, Math.min(N + G, k.scrollWidth - O + J))); | ||
} | ||
C.push({ el: k, top: F, left: G }); | ||
} | ||
return C; | ||
} | ||
// src/body-scroll-lock.ts | ||
var import_scroll_into_view_if_needed = __toESM(require("scroll-into-view-if-needed")); | ||
// node_modules/scroll-into-view-if-needed/es/index.js | ||
function isOptionsObject(options) { | ||
return options === Object(options) && Object.keys(options).length !== 0; | ||
} | ||
function defaultBehavior(actions, behavior) { | ||
if (behavior === void 0) { | ||
behavior = "auto"; | ||
} | ||
var canSmoothScroll = "scrollBehavior" in document.body.style; | ||
actions.forEach(function(_ref) { | ||
var el = _ref.el, top = _ref.top, left = _ref.left; | ||
if (el.scroll && canSmoothScroll) { | ||
el.scroll({ | ||
top, | ||
left, | ||
behavior | ||
}); | ||
} else { | ||
el.scrollTop = top; | ||
el.scrollLeft = left; | ||
} | ||
}); | ||
} | ||
function getOptions(options) { | ||
if (options === false) { | ||
return { | ||
block: "end", | ||
inline: "nearest" | ||
}; | ||
} | ||
if (isOptionsObject(options)) { | ||
return options; | ||
} | ||
return { | ||
block: "start", | ||
inline: "nearest" | ||
}; | ||
} | ||
function scrollIntoView(target, options) { | ||
var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target); | ||
if (isOptionsObject(options) && typeof options.behavior === "function") { | ||
return options.behavior(isTargetAttached ? index_module_default(target, options) : []); | ||
} | ||
if (!isTargetAttached) { | ||
return; | ||
} | ||
var computeOptions = getOptions(options); | ||
return defaultBehavior(index_module_default(target, computeOptions), computeOptions.behavior); | ||
} | ||
var es_default = scrollIntoView; | ||
// src/query.ts | ||
@@ -599,28 +509,28 @@ function getOwnerDocument(el) { | ||
let lastY = 0; | ||
let onTouchStart = (e2) => { | ||
scrollable = getScrollParent(e2.target); | ||
let onTouchStart = (e) => { | ||
scrollable = getScrollParent(e.target); | ||
if (scrollable === docEl && scrollable === doc.body) { | ||
return; | ||
} | ||
lastY = e2.changedTouches[0].pageY; | ||
lastY = e.changedTouches[0].pageY; | ||
}; | ||
let onTouchMove = (e2) => { | ||
if (e2.touches.length === 2 && allowPinchZoom) | ||
let onTouchMove = (e) => { | ||
if (e.touches.length === 2 && allowPinchZoom) | ||
return; | ||
if (!scrollable || scrollable === docEl || scrollable === doc.body) { | ||
e2.preventDefault(); | ||
e.preventDefault(); | ||
return; | ||
} | ||
let y = e2.changedTouches[0].pageY; | ||
let y = e.changedTouches[0].pageY; | ||
let scrollTop = scrollable.scrollTop; | ||
let bottom = scrollable.scrollHeight - scrollable.clientHeight; | ||
if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) { | ||
e2.preventDefault(); | ||
e.preventDefault(); | ||
} | ||
lastY = y; | ||
}; | ||
let onTouchEnd = (e2) => { | ||
let target = e2.target; | ||
let onTouchEnd = (e) => { | ||
let target = e.target; | ||
if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) { | ||
e2.preventDefault(); | ||
e.preventDefault(); | ||
target.style.transform = "translateY(-2000px)"; | ||
@@ -633,4 +543,4 @@ target.focus(); | ||
}; | ||
let onFocus = (e2) => { | ||
let target = e2.target; | ||
let onFocus = (e) => { | ||
let target = e.target; | ||
if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) { | ||
@@ -644,7 +554,7 @@ target.style.transform = "translateY(-2000px)"; | ||
win.requestAnimationFrame(function() { | ||
es_default(target, { scrollMode: "if-needed" }); | ||
(0, import_scroll_into_view_if_needed.default)(target, { scrollMode: "if-needed" }); | ||
}); | ||
} else { | ||
const onResize = () => { | ||
es_default(target, { scrollMode: "if-needed" }); | ||
(0, import_scroll_into_view_if_needed.default)(target, { scrollMode: "if-needed" }); | ||
}; | ||
@@ -1094,4 +1004,9 @@ addDomEvent(viewport, "resize", onResize, { once: true }); | ||
// src/rect-observer.ts | ||
var observedElements = /* @__PURE__ */ new Map(); | ||
function getObservedElements() { | ||
; | ||
globalThis.__rectObserverMap__ = globalThis.__rectObserverMap__ || /* @__PURE__ */ new Map(); | ||
return globalThis.__rectObserverMap__; | ||
} | ||
function observeElementRect(el, fn) { | ||
const observedElements = getObservedElements(); | ||
const data = observedElements.get(el); | ||
@@ -1125,2 +1040,3 @@ if (!data) { | ||
function runLoop() { | ||
const observedElements = getObservedElements(); | ||
const changedRectsData = []; | ||
@@ -1127,0 +1043,0 @@ observedElements.forEach((data, element) => { |
{ | ||
"name": "@zag-js/dom-utils", | ||
"version": "0.0.0-dev-20220413175519", | ||
"version": "0.0.0-dev-20220415160434", | ||
"description": "", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
"@types/react": "^18.0.0", | ||
"@zag-js/utils": "^0.0.0-dev-20220413175519", | ||
"@zag-js/utils": "^0.0.0-dev-20220415160434", | ||
"scroll-into-view-if-needed": "^2.2.29" | ||
@@ -32,0 +32,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
234289
2350