@zag-js/dom-utils
Advanced tools
Comparing version 0.0.0-dev-20221018140542 to 0.0.0-dev-20221031080845
@@ -163,2 +163,3 @@ "use strict"; | ||
function getComputedStyle(el) { | ||
var _a; | ||
if (!el) | ||
@@ -169,3 +170,3 @@ return {}; | ||
if (!style) { | ||
const win = (el == null ? void 0 : el.ownerDocument.defaultView) ?? window; | ||
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
style = win.getComputedStyle(el); | ||
@@ -189,3 +190,3 @@ cache.set(el, style); | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res ?? void 0; | ||
return res != null ? res : void 0; | ||
}; | ||
@@ -205,4 +206,5 @@ var cast = (v) => v; | ||
function getPlatform() { | ||
var _a; | ||
const agent = navigator.userAgentData; | ||
return (agent == null ? void 0 : agent.platform) ?? navigator.platform; | ||
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform; | ||
} | ||
@@ -237,2 +239,3 @@ var pt = (v) => isDom() && v.test(getPlatform()); | ||
function getDocument(el) { | ||
var _a; | ||
if (isWindow(el)) | ||
@@ -242,3 +245,3 @@ return el.document; | ||
return el; | ||
return (el == null ? void 0 : el.ownerDocument) ?? document; | ||
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document; | ||
} | ||
@@ -249,3 +252,4 @@ function getRootNode(el) { | ||
function getWindow(el) { | ||
return (el == null ? void 0 : el.ownerDocument.defaultView) ?? window; | ||
var _a; | ||
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
} | ||
@@ -256,3 +260,4 @@ function getDocumentElement(el) { | ||
function getNodeName(node) { | ||
return isWindow(node) ? "" : (node == null ? void 0 : node.localName) ?? ""; | ||
var _a; | ||
return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : ""; | ||
} | ||
@@ -268,4 +273,4 @@ function getEventWindow(event) { | ||
function getEventTarget(event) { | ||
var _a; | ||
return ((_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) ?? event.target; | ||
var _a, _b; | ||
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target; | ||
} | ||
@@ -300,7 +305,10 @@ function getActiveElement(el) { | ||
getRootNode: (ctx) => { | ||
var _a, _b; | ||
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document; | ||
}, | ||
getDoc: (ctx) => getDocument(dom.getRootNode(ctx)), | ||
getWin: (ctx) => { | ||
var _a; | ||
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document; | ||
return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window; | ||
}, | ||
getDoc: (ctx) => getDocument(dom.getRootNode(ctx)), | ||
getWin: (ctx) => dom.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom.getDoc(ctx).activeElement, | ||
@@ -311,3 +319,3 @@ getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id), | ||
return function emit(evt, detail, options) { | ||
const { bubbles = true, cancelable, composed = true } = options ?? {}; | ||
const { bubbles = true, cancelable, composed = true } = options != null ? options : {}; | ||
const eventName = `zag:${evt}`; | ||
@@ -376,3 +384,4 @@ const init = { bubbles, cancelable, composed, detail }; | ||
function getNativeEvent(e) { | ||
return e.nativeEvent ?? e; | ||
var _a; | ||
return (_a = e.nativeEvent) != null ? _a : e; | ||
} | ||
@@ -518,3 +527,4 @@ function isSelfEvent(event) { | ||
function getEventPoint(event, type = "page") { | ||
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event; | ||
var _a, _b; | ||
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event; | ||
return { x: point[`${type}X`], y: point[`${type}Y`] }; | ||
@@ -546,5 +556,6 @@ } | ||
function getEventKey(event, options = {}) { | ||
var _a; | ||
const { dir = "ltr", orientation = "horizontal" } = options; | ||
let { key } = event; | ||
key = sameKeyMap[key] ?? key; | ||
key = (_a = sameKeyMap[key]) != null ? _a : key; | ||
const isRtl = dir === "rtl" && orientation === "horizontal"; | ||
@@ -588,3 +599,4 @@ if (isRtl && key in rtlKeyMap) { | ||
function addPointerEvent(target, event, listener, options) { | ||
const type = getEventName(event) ?? event; | ||
var _a; | ||
const type = (_a = getEventName(event)) != null ? _a : event; | ||
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options); | ||
@@ -600,3 +612,4 @@ } | ||
return (event) => { | ||
const win = event.view ?? window; | ||
var _a; | ||
const win = (_a = event.view) != null ? _a : window; | ||
const isMouseEvent2 = event instanceof win.MouseEvent; | ||
@@ -706,3 +719,4 @@ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0; | ||
function queryAll(root, selector) { | ||
return Array.from((root == null ? void 0 : root.querySelectorAll(selector)) ?? []); | ||
var _a; | ||
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []); | ||
} | ||
@@ -731,3 +745,6 @@ function query(root, selector) { | ||
} | ||
var getValueText = (item) => item.dataset.valuetext ?? item.textContent ?? ""; | ||
var getValueText = (item) => { | ||
var _a, _b; | ||
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : ""; | ||
}; | ||
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase()); | ||
@@ -755,3 +772,3 @@ var wrap = (v, idx) => { | ||
function disableTextSelection({ target, doc } = {}) { | ||
const _document = doc ?? document; | ||
const _document = doc != null ? doc : document; | ||
if (isIos()) { | ||
@@ -770,3 +787,3 @@ if (state === "default") { | ||
function restoreTextSelection({ target, doc } = {}) { | ||
const _document = doc ?? document; | ||
const _document = doc != null ? doc : document; | ||
if (isIos()) { | ||
@@ -791,3 +808,3 @@ if (state !== "disabled") | ||
if (target.style.userSelect === "none") { | ||
target.style.userSelect = targetOldUserSelect ?? ""; | ||
target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : ""; | ||
} | ||
@@ -804,3 +821,4 @@ if (target.getAttribute("style") === "") { | ||
function trackPointerDown(doc, onPointerDown) { | ||
const win = doc.defaultView ?? window; | ||
var _a; | ||
const win = (_a = doc.defaultView) != null ? _a : window; | ||
const fn = (event) => { | ||
@@ -1031,2 +1049,3 @@ if (event.target instanceof win.HTMLElement) { | ||
function trackVisualViewport(options) { | ||
var _a; | ||
const { document: doc, resolve } = options; | ||
@@ -1036,3 +1055,3 @@ const win = (doc == null ? void 0 : doc.defaultView) || window; | ||
const onResize = () => resolve == null ? void 0 : resolve(getViewportSize(win)); | ||
return addDomEvent(win.visualViewport ?? win, "resize", onResize); | ||
return addDomEvent((_a = win.visualViewport) != null ? _a : win, "resize", onResize); | ||
} | ||
@@ -1039,0 +1058,0 @@ function getViewportSize(win) { |
{ | ||
"name": "@zag-js/dom-utils", | ||
"version": "0.0.0-dev-20221018140542", | ||
"version": "0.0.0-dev-20221031080845", | ||
"description": "", | ||
@@ -28,6 +28,6 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@zag-js/types": "0.2.7" | ||
"@zag-js/types": "0.0.0-dev-20221031080845" | ||
}, | ||
"devDependencies": { | ||
"@zag-js/utils": "0.1.6" | ||
"@zag-js/utils": "0.0.0-dev-20221031080845" | ||
}, | ||
@@ -34,0 +34,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
85741
2472
+ Added@zag-js/types@0.0.0-dev-20221031080845(transitive)
+ Addedcsstype@3.1.1(transitive)
- Removed@zag-js/types@0.2.7(transitive)
- Removedcsstype@3.1.0(transitive)