@zag-js/dom-utils
Advanced tools
Comparing version 0.0.0-dev-20230201173935 to 0.0.0-dev-20230201181615
@@ -34,3 +34,2 @@ "use strict"; | ||
function getComputedStyle(el) { | ||
var _a; | ||
if (!el) | ||
@@ -41,3 +40,3 @@ return {}; | ||
if (!style) { | ||
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
const win = el?.ownerDocument.defaultView ?? window; | ||
style = win.getComputedStyle(el); | ||
@@ -44,0 +43,0 @@ cache.set(el, style); |
@@ -50,5 +50,4 @@ "use strict"; | ||
function getPlatform() { | ||
var _a; | ||
const agent = navigator.userAgentData; | ||
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform; | ||
return agent?.platform ?? navigator.platform; | ||
} | ||
@@ -66,3 +65,3 @@ var pt = (v) => isDom() && v.test(getPlatform()); | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
@@ -86,4 +85,3 @@ | ||
function getNativeEvent(e) { | ||
var _a; | ||
return (_a = e.nativeEvent) != null ? _a : e; | ||
return e.nativeEvent ?? e; | ||
} | ||
@@ -90,0 +88,0 @@ function isSelfEvent(event) { |
@@ -32,4 +32,3 @@ "use strict"; | ||
function getWindow(el) { | ||
var _a; | ||
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
return el?.ownerDocument.defaultView ?? window; | ||
} | ||
@@ -36,0 +35,0 @@ |
@@ -39,3 +39,3 @@ "use strict"; | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
@@ -42,0 +42,0 @@ function isVisible(el) { |
@@ -32,3 +32,2 @@ "use strict"; | ||
function getComputedStyle(el) { | ||
var _a; | ||
if (!el) | ||
@@ -39,3 +38,3 @@ return {}; | ||
if (!style) { | ||
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
const win = el?.ownerDocument.defaultView ?? window; | ||
style = win.getComputedStyle(el); | ||
@@ -42,0 +41,0 @@ cache.set(el, style); |
@@ -43,4 +43,3 @@ "use strict"; | ||
function getEventPoint(event, type = "page") { | ||
var _a, _b; | ||
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event; | ||
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event; | ||
return { x: point[`${type}X`], y: point[`${type}Y`] }; | ||
@@ -47,0 +46,0 @@ } |
@@ -165,3 +165,2 @@ "use strict"; | ||
function getComputedStyle(el) { | ||
var _a; | ||
if (!el) | ||
@@ -172,3 +171,3 @@ return {}; | ||
if (!style) { | ||
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
const win = el?.ownerDocument.defaultView ?? window; | ||
style = win.getComputedStyle(el); | ||
@@ -192,3 +191,3 @@ cache.set(el, style); | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
@@ -198,3 +197,3 @@ var cast = (v) => v; | ||
fns.forEach(function(fn) { | ||
fn == null ? void 0 : fn(...a); | ||
fn?.(...a); | ||
}); | ||
@@ -211,5 +210,4 @@ }; | ||
function getPlatform() { | ||
var _a; | ||
const agent = navigator.userAgentData; | ||
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform; | ||
return agent?.platform ?? navigator.platform; | ||
} | ||
@@ -232,6 +230,6 @@ var pt = (v) => isDom() && v.test(getPlatform()); | ||
function isShadowRoot(el) { | ||
return (el == null ? void 0 : el.toString()) === "[object ShadowRoot]"; | ||
return el?.toString() === "[object ShadowRoot]"; | ||
} | ||
function isWindow(value) { | ||
return (value == null ? void 0 : value.toString()) === "[object Window]"; | ||
return value?.toString() === "[object Window]"; | ||
} | ||
@@ -245,3 +243,2 @@ function isFrame(element) { | ||
function getDocument(el) { | ||
var _a; | ||
if (isWindow(el)) | ||
@@ -251,3 +248,3 @@ return el.document; | ||
return el; | ||
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document; | ||
return el?.ownerDocument ?? document; | ||
} | ||
@@ -258,4 +255,3 @@ function getRootNode(el) { | ||
function getWindow(el) { | ||
var _a; | ||
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
return el?.ownerDocument.defaultView ?? window; | ||
} | ||
@@ -266,4 +262,3 @@ function getDocumentElement(el) { | ||
function getNodeName(node) { | ||
var _a; | ||
return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : ""; | ||
return isWindow(node) ? "" : node?.localName ?? ""; | ||
} | ||
@@ -279,4 +274,3 @@ function getEventWindow(event) { | ||
function getEventTarget(event) { | ||
var _a, _b; | ||
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target; | ||
return event.composedPath?.()[0] ?? event.target; | ||
} | ||
@@ -310,11 +304,5 @@ function getActiveElement(el) { | ||
const dom = { | ||
getRootNode: (ctx) => { | ||
var _a, _b; | ||
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document; | ||
}, | ||
getRootNode: (ctx) => ctx.getRootNode?.() ?? document, | ||
getDoc: (ctx) => getDocument(dom.getRootNode(ctx)), | ||
getWin: (ctx) => { | ||
var _a; | ||
return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window; | ||
}, | ||
getWin: (ctx) => dom.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom.getDoc(ctx).activeElement, | ||
@@ -334,6 +322,6 @@ getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id) | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
var isDisabled = (el) => { | ||
return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true; | ||
return el?.getAttribute("disabled") != null || !!el?.getAttribute("aria-disabled") === true; | ||
}; | ||
@@ -373,4 +361,3 @@ function isElementEditable(el) { | ||
function getNativeEvent(e) { | ||
var _a; | ||
return (_a = e.nativeEvent) != null ? _a : e; | ||
return e.nativeEvent ?? e; | ||
} | ||
@@ -516,4 +503,3 @@ function isSelfEvent(event) { | ||
function getEventPoint(event, type = "page") { | ||
var _a, _b; | ||
const point = isTouchEvent(event) ? (_b = (_a = event.touches[0]) != null ? _a : event.changedTouches[0]) != null ? _b : fallback : event; | ||
const point = isTouchEvent(event) ? event.touches[0] ?? event.changedTouches[0] ?? fallback : event; | ||
return { x: point[`${type}X`], y: point[`${type}Y`] }; | ||
@@ -561,6 +547,5 @@ } | ||
function getEventKey(event, options = {}) { | ||
var _a; | ||
const { dir = "ltr", orientation = "horizontal" } = options; | ||
let { key } = event; | ||
key = (_a = sameKeyMap[key]) != null ? _a : key; | ||
key = sameKeyMap[key] ?? key; | ||
const isRtl = dir === "rtl" && orientation === "horizontal"; | ||
@@ -598,10 +583,9 @@ if (isRtl && key in rtlKeyMap) { | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
} | ||
function addPointerEvent(target, event, listener, options) { | ||
var _a; | ||
const type = (_a = getEventName(event)) != null ? _a : event; | ||
const type = getEventName(event) ?? event; | ||
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options); | ||
@@ -617,4 +601,3 @@ } | ||
return (event) => { | ||
var _a; | ||
const win = (_a = event.view) != null ? _a : window; | ||
const win = event.view ?? window; | ||
const isMouseEvent2 = event instanceof win.MouseEvent; | ||
@@ -711,4 +694,4 @@ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0; | ||
return () => { | ||
cleanup == null ? void 0 : cleanup(); | ||
dispose == null ? void 0 : dispose(); | ||
cleanup?.(); | ||
dispose?.(); | ||
}; | ||
@@ -725,7 +708,6 @@ } | ||
function queryAll(root, selector) { | ||
var _a; | ||
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []); | ||
return Array.from(root?.querySelectorAll(selector) ?? []); | ||
} | ||
function query(root, selector) { | ||
return root == null ? void 0 : root.querySelector(selector); | ||
return root?.querySelector(selector); | ||
} | ||
@@ -751,6 +733,3 @@ function itemById(v, id) { | ||
} | ||
var getValueText = (item) => { | ||
var _a, _b; | ||
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : ""; | ||
}; | ||
var getValueText = (item) => item.dataset.valuetext ?? item.textContent ?? ""; | ||
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase()); | ||
@@ -778,3 +757,3 @@ var wrap = (v, idx) => { | ||
function disableTextSelection({ target, doc } = {}) { | ||
const _document = doc != null ? doc : document; | ||
const _document = doc ?? document; | ||
if (isIos()) { | ||
@@ -793,3 +772,3 @@ if (state === "default") { | ||
function restoreTextSelection({ target, doc } = {}) { | ||
const _document = doc != null ? doc : document; | ||
const _document = doc ?? document; | ||
if (isIos()) { | ||
@@ -814,3 +793,3 @@ if (state !== "disabled") | ||
if (target.style.userSelect === "none") { | ||
target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : ""; | ||
target.style.userSelect = targetOldUserSelect ?? ""; | ||
} | ||
@@ -827,4 +806,3 @@ if (target.getAttribute("style") === "") { | ||
function trackPointerDown(doc, onPointerDown) { | ||
var _a; | ||
const win = (_a = doc.defaultView) != null ? _a : window; | ||
const win = doc.defaultView ?? window; | ||
const fn = (event) => { | ||
@@ -877,9 +855,9 @@ if (event.target instanceof win.HTMLElement) { | ||
if (locked) | ||
onPointerLock == null ? void 0 : onPointerLock(); | ||
onPointerLock?.(); | ||
else | ||
onPointerUnlock == null ? void 0 : onPointerUnlock(); | ||
onPointerUnlock?.(); | ||
} | ||
function onPointerError(event) { | ||
if (locked) | ||
onPointerUnlock == null ? void 0 : onPointerUnlock(); | ||
onPointerUnlock?.(); | ||
console.error("PointerLock error occured:", event); | ||
@@ -1063,14 +1041,12 @@ exit(); | ||
function trackVisualViewport(options) { | ||
var _a; | ||
const { document: doc, resolve } = options; | ||
const win = (doc == null ? void 0 : doc.defaultView) || window; | ||
resolve == null ? void 0 : resolve(getViewportSize(win)); | ||
const onResize = () => resolve == null ? void 0 : resolve(getViewportSize(win)); | ||
return addDomEvent((_a = win.visualViewport) != null ? _a : win, "resize", onResize); | ||
const win = doc?.defaultView || window; | ||
resolve?.(getViewportSize(win)); | ||
const onResize = () => resolve?.(getViewportSize(win)); | ||
return addDomEvent(win.visualViewport ?? win, "resize", onResize); | ||
} | ||
function getViewportSize(win) { | ||
var _a, _b; | ||
return { | ||
width: ((_a = win.visualViewport) == null ? void 0 : _a.width) || win.innerWidth, | ||
height: ((_b = win.visualViewport) == null ? void 0 : _b.height) || win.innerHeight | ||
width: win.visualViewport?.width || win.innerWidth, | ||
height: win.visualViewport?.height || win.innerHeight | ||
}; | ||
@@ -1077,0 +1053,0 @@ } |
@@ -41,6 +41,5 @@ "use strict"; | ||
function getEventKey(event, options = {}) { | ||
var _a; | ||
const { dir = "ltr", orientation = "horizontal" } = options; | ||
let { key } = event; | ||
key = (_a = sameKeyMap[key]) != null ? _a : key; | ||
key = sameKeyMap[key] ?? key; | ||
const isRtl = dir === "rtl" && orientation === "horizontal"; | ||
@@ -47,0 +46,0 @@ if (isRtl && key in rtlKeyMap) { |
@@ -34,3 +34,3 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
@@ -66,10 +66,9 @@ | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
} | ||
function addPointerEvent(target, event, listener, options) { | ||
var _a; | ||
const type = (_a = getEventName(event)) != null ? _a : event; | ||
const type = getEventName(event) ?? event; | ||
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options); | ||
@@ -85,4 +84,3 @@ } | ||
return (event) => { | ||
var _a; | ||
const win = (_a = event.view) != null ? _a : window; | ||
const win = event.view ?? window; | ||
const isMouseEvent = event instanceof win.MouseEvent; | ||
@@ -89,0 +87,0 @@ const isPrimary = !isMouseEvent || isMouseEvent && event.button === 0; |
@@ -60,4 +60,4 @@ "use strict"; | ||
return () => { | ||
cleanup == null ? void 0 : cleanup(); | ||
dispose == null ? void 0 : dispose(); | ||
cleanup?.(); | ||
dispose?.(); | ||
}; | ||
@@ -64,0 +64,0 @@ } |
@@ -34,7 +34,6 @@ "use strict"; | ||
function queryAll(root, selector) { | ||
var _a; | ||
return Array.from((_a = root == null ? void 0 : root.querySelectorAll(selector)) != null ? _a : []); | ||
return Array.from(root?.querySelectorAll(selector) ?? []); | ||
} | ||
function query(root, selector) { | ||
return root == null ? void 0 : root.querySelector(selector); | ||
return root?.querySelector(selector); | ||
} | ||
@@ -60,6 +59,3 @@ function itemById(v, id) { | ||
} | ||
var getValueText = (item) => { | ||
var _a, _b; | ||
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : ""; | ||
}; | ||
var getValueText = (item) => item.dataset.valuetext ?? item.textContent ?? ""; | ||
var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase()); | ||
@@ -66,0 +62,0 @@ var wrap = (v, idx) => { |
@@ -36,5 +36,4 @@ "use strict"; | ||
function getPlatform() { | ||
var _a; | ||
const agent = navigator.userAgentData; | ||
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform; | ||
return agent?.platform ?? navigator.platform; | ||
} | ||
@@ -41,0 +40,0 @@ var pt = (v) => isDom() && v.test(getPlatform()); |
@@ -31,7 +31,7 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
var callAll = (...fns) => (...a) => { | ||
fns.forEach(function(fn) { | ||
fn == null ? void 0 : fn(...a); | ||
fn?.(...a); | ||
}); | ||
@@ -48,5 +48,4 @@ }; | ||
function getPlatform() { | ||
var _a; | ||
const agent = navigator.userAgentData; | ||
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform; | ||
return agent?.platform ?? navigator.platform; | ||
} | ||
@@ -81,10 +80,9 @@ var pt = (v) => isDom() && v.test(getPlatform()); | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
} | ||
function addPointerEvent(target, event, listener, options) { | ||
var _a; | ||
const type = (_a = getEventName(event)) != null ? _a : event; | ||
const type = getEventName(event) ?? event; | ||
return addDomEvent(target, type, wrapHandler(listener, event === "pointerdown"), options); | ||
@@ -100,4 +98,3 @@ } | ||
return (event) => { | ||
var _a; | ||
const win = (_a = event.view) != null ? _a : window; | ||
const win = event.view ?? window; | ||
const isMouseEvent2 = event instanceof win.MouseEvent; | ||
@@ -155,3 +152,3 @@ const isPrimary = !isMouseEvent2 || isMouseEvent2 && event.button === 0; | ||
function disableTextSelection({ target, doc } = {}) { | ||
const _document = doc != null ? doc : document; | ||
const _document = doc ?? document; | ||
if (isIos()) { | ||
@@ -170,3 +167,3 @@ if (state === "default") { | ||
function restoreTextSelection({ target, doc } = {}) { | ||
const _document = doc != null ? doc : document; | ||
const _document = doc ?? document; | ||
if (isIos()) { | ||
@@ -191,3 +188,3 @@ if (state !== "disabled") | ||
if (target.style.userSelect === "none") { | ||
target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : ""; | ||
target.style.userSelect = targetOldUserSelect ?? ""; | ||
} | ||
@@ -204,4 +201,3 @@ if (target.getAttribute("style") === "") { | ||
function trackPointerDown(doc, onPointerDown) { | ||
var _a; | ||
const win = (_a = doc.defaultView) != null ? _a : window; | ||
const win = doc.defaultView ?? window; | ||
const fn = (event) => { | ||
@@ -208,0 +204,0 @@ if (event.target instanceof win.HTMLElement) { |
@@ -32,7 +32,7 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
var callAll = (...fns) => (...a) => { | ||
fns.forEach(function(fn) { | ||
fn == null ? void 0 : fn(...a); | ||
fn?.(...a); | ||
}); | ||
@@ -48,5 +48,5 @@ }; | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
@@ -72,9 +72,9 @@ } | ||
if (locked) | ||
onPointerLock == null ? void 0 : onPointerLock(); | ||
onPointerLock?.(); | ||
else | ||
onPointerUnlock == null ? void 0 : onPointerUnlock(); | ||
onPointerUnlock?.(); | ||
} | ||
function onPointerError(event) { | ||
if (locked) | ||
onPointerUnlock == null ? void 0 : onPointerUnlock(); | ||
onPointerUnlock?.(); | ||
console.error("PointerLock error occured:", event); | ||
@@ -81,0 +81,0 @@ exit(); |
@@ -50,6 +50,6 @@ "use strict"; | ||
function isShadowRoot(el) { | ||
return (el == null ? void 0 : el.toString()) === "[object ShadowRoot]"; | ||
return el?.toString() === "[object ShadowRoot]"; | ||
} | ||
function isWindow(value) { | ||
return (value == null ? void 0 : value.toString()) === "[object Window]"; | ||
return value?.toString() === "[object Window]"; | ||
} | ||
@@ -63,3 +63,2 @@ function isFrame(element) { | ||
function getDocument(el) { | ||
var _a; | ||
if (isWindow(el)) | ||
@@ -69,3 +68,3 @@ return el.document; | ||
return el; | ||
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document; | ||
return el?.ownerDocument ?? document; | ||
} | ||
@@ -76,4 +75,3 @@ function getRootNode(el) { | ||
function getWindow(el) { | ||
var _a; | ||
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
return el?.ownerDocument.defaultView ?? window; | ||
} | ||
@@ -84,4 +82,3 @@ function getDocumentElement(el) { | ||
function getNodeName(node) { | ||
var _a; | ||
return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : ""; | ||
return isWindow(node) ? "" : node?.localName ?? ""; | ||
} | ||
@@ -97,4 +94,3 @@ function getEventWindow(event) { | ||
function getEventTarget(event) { | ||
var _a, _b; | ||
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target; | ||
return event.composedPath?.()[0] ?? event.target; | ||
} | ||
@@ -128,11 +124,5 @@ function getActiveElement(el) { | ||
const dom = { | ||
getRootNode: (ctx) => { | ||
var _a, _b; | ||
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document; | ||
}, | ||
getRootNode: (ctx) => ctx.getRootNode?.() ?? document, | ||
getDoc: (ctx) => getDocument(dom.getRootNode(ctx)), | ||
getWin: (ctx) => { | ||
var _a; | ||
return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window; | ||
}, | ||
getWin: (ctx) => dom.getDoc(ctx).defaultView ?? window, | ||
getActiveElement: (ctx) => dom.getDoc(ctx).activeElement, | ||
@@ -152,6 +142,6 @@ getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id) | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
var isDisabled = (el) => { | ||
return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true; | ||
return el?.getAttribute("disabled") != null || !!el?.getAttribute("aria-disabled") === true; | ||
}; | ||
@@ -158,0 +148,0 @@ function isElementEditable(el) { |
@@ -37,3 +37,2 @@ "use strict"; | ||
function getComputedStyle(el) { | ||
var _a; | ||
if (!el) | ||
@@ -44,3 +43,3 @@ return {}; | ||
if (!style) { | ||
const win = (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
const win = el?.ownerDocument.defaultView ?? window; | ||
style = win.getComputedStyle(el); | ||
@@ -57,6 +56,5 @@ cache.set(el, style); | ||
function isWindow(value) { | ||
return (value == null ? void 0 : value.toString()) === "[object Window]"; | ||
return value?.toString() === "[object Window]"; | ||
} | ||
function getDocument(el) { | ||
var _a; | ||
if (isWindow(el)) | ||
@@ -66,11 +64,9 @@ return el.document; | ||
return el; | ||
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document; | ||
return el?.ownerDocument ?? document; | ||
} | ||
function getWindow(el) { | ||
var _a; | ||
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window; | ||
return el?.ownerDocument.defaultView ?? window; | ||
} | ||
function getNodeName(node) { | ||
var _a; | ||
return isWindow(node) ? "" : (_a = node == null ? void 0 : node.localName) != null ? _a : ""; | ||
return isWindow(node) ? "" : node?.localName ?? ""; | ||
} | ||
@@ -84,3 +80,3 @@ function getParent(el) { | ||
function isHTMLElement(v) { | ||
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string"; | ||
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string"; | ||
} | ||
@@ -87,0 +83,0 @@ |
@@ -46,5 +46,4 @@ "use strict"; | ||
function getPlatform() { | ||
var _a; | ||
const agent = navigator.userAgentData; | ||
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform; | ||
return agent?.platform ?? navigator.platform; | ||
} | ||
@@ -62,3 +61,3 @@ var pt = (v) => isDom() && v.test(getPlatform()); | ||
function disableTextSelection({ target, doc } = {}) { | ||
const _document = doc != null ? doc : document; | ||
const _document = doc ?? document; | ||
if (isIos()) { | ||
@@ -77,3 +76,3 @@ if (state === "default") { | ||
function restoreTextSelection({ target, doc } = {}) { | ||
const _document = doc != null ? doc : document; | ||
const _document = doc ?? document; | ||
if (isIos()) { | ||
@@ -98,3 +97,3 @@ if (state !== "disabled") | ||
if (target.style.userSelect === "none") { | ||
target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : ""; | ||
target.style.userSelect = targetOldUserSelect ?? ""; | ||
} | ||
@@ -101,0 +100,0 @@ if (target.getAttribute("style") === "") { |
@@ -35,6 +35,3 @@ "use strict"; | ||
} | ||
var getValueText = (item) => { | ||
var _a, _b; | ||
return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : ""; | ||
}; | ||
var getValueText = (item) => item.dataset.valuetext ?? item.textContent ?? ""; | ||
var match = (valueText, query) => valueText.toLowerCase().startsWith(query.toLowerCase()); | ||
@@ -41,0 +38,0 @@ var wrap = (v, idx) => { |
@@ -30,3 +30,3 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
@@ -42,5 +42,5 @@ var cast = (v) => v; | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
@@ -47,0 +47,0 @@ } |
@@ -30,3 +30,3 @@ "use strict"; | ||
const res = typeof v === "function" ? v(...a) : v; | ||
return res != null ? res : void 0; | ||
return res ?? void 0; | ||
}; | ||
@@ -41,5 +41,5 @@ | ||
const node = isRef(target) ? target.current : runIfFn(target); | ||
node == null ? void 0 : node.addEventListener(eventName, handler, options); | ||
node?.addEventListener(eventName, handler, options); | ||
return () => { | ||
node == null ? void 0 : node.removeEventListener(eventName, handler, options); | ||
node?.removeEventListener(eventName, handler, options); | ||
}; | ||
@@ -50,14 +50,12 @@ } | ||
function trackVisualViewport(options) { | ||
var _a; | ||
const { document: doc, resolve } = options; | ||
const win = (doc == null ? void 0 : doc.defaultView) || window; | ||
resolve == null ? void 0 : resolve(getViewportSize(win)); | ||
const onResize = () => resolve == null ? void 0 : resolve(getViewportSize(win)); | ||
return addDomEvent((_a = win.visualViewport) != null ? _a : win, "resize", onResize); | ||
const win = doc?.defaultView || window; | ||
resolve?.(getViewportSize(win)); | ||
const onResize = () => resolve?.(getViewportSize(win)); | ||
return addDomEvent(win.visualViewport ?? win, "resize", onResize); | ||
} | ||
function getViewportSize(win) { | ||
var _a, _b; | ||
return { | ||
width: ((_a = win.visualViewport) == null ? void 0 : _a.width) || win.innerWidth, | ||
height: ((_b = win.visualViewport) == null ? void 0 : _b.height) || win.innerHeight | ||
width: win.visualViewport?.width || win.innerWidth, | ||
height: win.visualViewport?.height || win.innerHeight | ||
}; | ||
@@ -64,0 +62,0 @@ } |
{ | ||
"name": "@zag-js/dom-utils", | ||
"version": "0.0.0-dev-20230201173935", | ||
"version": "0.0.0-dev-20230201181615", | ||
"description": "", | ||
@@ -25,7 +25,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/types": "0.0.0-dev-20230201173935" | ||
"@zag-js/types": "0.0.0-dev-20230201181615" | ||
}, | ||
"devDependencies": { | ||
"clean-package": "2.2.0", | ||
"@zag-js/utils": "0.3.2" | ||
"@zag-js/utils": "0.0.0-dev-20230201181615" | ||
}, | ||
@@ -32,0 +32,0 @@ "clean-package": "../../../clean-package.config.json", |
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
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
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
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
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
178727
5594
+ Added@zag-js/types@0.0.0-dev-20230201181615(transitive)
- Removed@zag-js/types@0.0.0-dev-20230201173935(transitive)