Socket
Socket
Sign inDemoInstall

@zag-js/dom-utils

Package Overview
Dependencies
Maintainers
1
Versions
227
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/dom-utils - npm Package Compare versions

Comparing version 0.1.13 to 0.2.0

2

dist/index.d.ts

@@ -209,2 +209,4 @@ import { JSX } from '@zag-js/types';

getById: <T_1 = HTMLElement>(ctx: Ctx, id: string) => T_1 | null;
createEmitter: (ctx: Ctx, target: HTMLElement) => (evt: string, detail: Record<string, any>, options?: EventInit) => void;
createListener: (target: HTMLElement) => <T_2 = any>(evt: string, handler: (e: CustomEvent<T_2>) => void) => () => void;
} & T;

@@ -211,0 +213,0 @@ declare function contains(parent: HTMLElement | EventTarget | null | undefined, child: HTMLElement | EventTarget | null): boolean;

85

dist/index.js

@@ -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,9 +305,30 @@ 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,
getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id)
getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id),
createEmitter: (ctx, target) => {
const win = dom.getWin(ctx);
return function emit(evt, detail, options) {
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
const eventName = `zag:${evt}`;
const init = { bubbles, cancelable, composed, detail };
const event = new win.CustomEvent(eventName, init);
target.dispatchEvent(event);
};
},
createListener: (target) => {
return function listen(evt, handler) {
const eventName = `zag:${evt}`;
const listener = (e) => handler(e);
target.addEventListener(eventName, listener);
return () => target.removeEventListener(eventName, listener);
};
}
};

@@ -357,3 +383,4 @@ return {

function getNativeEvent(e) {
return e.nativeEvent ?? e;
var _a;
return (_a = e.nativeEvent) != null ? _a : e;
}

@@ -499,3 +526,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`] };

@@ -527,5 +555,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";

@@ -569,3 +598,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);

@@ -581,3 +611,4 @@ }

return (event) => {
const win = event.view ?? window;
var _a;
const win = (_a = event.view) != null ? _a : window;
const isMouseEvent2 = event instanceof win.MouseEvent;

@@ -687,3 +718,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 : []);
}

@@ -712,3 +744,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());

@@ -736,3 +771,3 @@ var wrap = (v, idx) => {

function disableTextSelection({ target, doc } = {}) {
const _document = doc ?? document;
const _document = doc != null ? doc : document;
if (isIos()) {

@@ -751,3 +786,3 @@ if (state === "default") {

function restoreTextSelection({ target, doc } = {}) {
const _document = doc ?? document;
const _document = doc != null ? doc : document;
if (isIos()) {

@@ -772,3 +807,3 @@ if (state !== "disabled")

if (target.style.userSelect === "none") {
target.style.userSelect = targetOldUserSelect ?? "";
target.style.userSelect = targetOldUserSelect != null ? targetOldUserSelect : "";
}

@@ -785,3 +820,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) => {

@@ -1012,2 +1048,3 @@ if (event.target instanceof win.HTMLElement) {

function trackVisualViewport(options) {
var _a;
const { document: doc, resolve } = options;

@@ -1017,3 +1054,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);
}

@@ -1020,0 +1057,0 @@ function getViewportSize(win) {

{
"name": "@zag-js/dom-utils",
"version": "0.1.13",
"version": "0.2.0",
"description": "",

@@ -28,6 +28,6 @@ "main": "dist/index.js",

"dependencies": {
"@zag-js/types": "0.2.7"
"@zag-js/types": "0.3.0"
},
"devDependencies": {
"@zag-js/utils": "0.1.6"
"@zag-js/utils": "0.2.0"
},

@@ -34,0 +34,0 @@ "scripts": {

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