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.6 to 0.1.7

2

dist/index.d.ts

@@ -6,3 +6,2 @@ export * from "./attrs";

export * from "./fire-event";
export * from "./focus-event";
export * from "./focusable";

@@ -17,3 +16,2 @@ export * from "./form";

export * from "./listener";
export * from "./live-region";
export * from "./mutation-observer";

@@ -20,0 +18,0 @@ export * from "./next-tick";

118

dist/index.js

@@ -49,4 +49,4 @@ "use strict";

copyVisualStyles: () => copyVisualStyles,
createLiveRegion: () => createLiveRegion,
dataAttr: () => dataAttr,
defineDomHelpers: () => defineDomHelpers,
disableTextSelection: () => disableTextSelection,

@@ -100,2 +100,3 @@ dispatchInputCheckedEvent: () => dispatchInputCheckedEvent,

isDisabled: () => isDisabled,
isDocument: () => isDocument,
isDom: () => isDom,

@@ -156,3 +157,2 @@ isElementEditable: () => isElementEditable,

trackVisualViewport: () => trackVisualViewport,
validateBlur: () => validateBlur,
visuallyHiddenStyle: () => visuallyHiddenStyle,

@@ -249,2 +249,5 @@ waitFor: () => waitFor,

// src/query.ts
function isDocument(el) {
return el.nodeType === Node.DOCUMENT_NODE;
}
function isShadowRoot(el) {

@@ -266,2 +269,4 @@ return (el == null ? void 0 : el.toString()) === "[object ShadowRoot]";

return el.document;
if (isDocument(el))
return el;
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;

@@ -320,2 +325,18 @@ }

}
function defineDomHelpers(helpers) {
const dom = {
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 = dom.getDoc(ctx).defaultView) != null ? _a : window;
},
getActiveElement: (ctx) => dom.getDoc(ctx).activeElement,
getById: (ctx, id) => dom.getRootNode(ctx).getElementById(id)
};
return __spreadValues(__spreadValues({}, dom), helpers);
}
function contains(parent, child) {

@@ -336,3 +357,4 @@ if (!parent)

try {
return el instanceof getWindow(el).HTMLInputElement && el.selectionStart != null || /(textarea|select)/.test(el.localName) || el.isContentEditable;
const win = getWindow(el);
return el instanceof win.HTMLInputElement && el.selectionStart != null || /(textarea|select)/.test(el.localName) || el.isContentEditable;
} catch (e) {

@@ -416,10 +438,2 @@ return false;

// src/focus-event.ts
function validateBlur(event, opts) {
var _a;
const exclude = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
const relatedTarget = (_a = event.relatedTarget) != null ? _a : opts.fallback;
return exclude.every((el) => !(el == null ? void 0 : el.contains(relatedTarget)));
}
// src/focusable.ts

@@ -509,9 +523,3 @@ function hasNegativeTabIndex(element) {

const win = node.ownerDocument.defaultView || window;
const obs = new win.MutationObserver((changes) => {
for (const change of changes) {
if (change.type === "childList") {
fn(change);
}
}
});
const obs = new win.MutationObserver(fn);
obs.observe(node, { childList: true, subtree: true });

@@ -605,2 +613,4 @@ return () => obs.disconnect();

var _a;
if (!el)
return;
const win = getWindow(el);

@@ -616,2 +626,4 @@ if (!(el instanceof win.HTMLInputElement))

var _a;
if (!el)
return;
const win = getWindow(el);

@@ -754,55 +766,2 @@ if (!(el instanceof win.HTMLInputElement))

// src/visually-hidden.ts
var visuallyHiddenStyle = {
border: "0",
clip: "rect(0 0 0 0)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: "0",
position: "absolute",
width: "1px",
whiteSpace: "nowrap",
wordWrap: "normal"
};
function setVisuallyHidden(el) {
Object.assign(el.style, visuallyHiddenStyle);
}
// src/live-region.ts
var LIVE_REGION_ID = "__live-region__";
function createLiveRegion(opts = {}) {
var _a;
const { level = "polite", document: doc = document, root, delay: _delay = 0 } = opts;
const win = (_a = doc.defaultView) != null ? _a : window;
const parent = root != null ? root : doc.body;
function announce(message, delay) {
const oldRegion = doc.getElementById(LIVE_REGION_ID);
oldRegion == null ? void 0 : oldRegion.remove();
delay = delay != null ? delay : _delay;
const region = doc.createElement("span");
region.id = LIVE_REGION_ID;
region.dataset.liveAnnouncer = "true";
const role = level !== "assertive" ? "status" : "alert";
region.setAttribute("aria-live", level);
region.setAttribute("role", role);
setVisuallyHidden(region);
parent.appendChild(region);
win.setTimeout(() => {
region.textContent = message;
}, delay);
}
function destroy() {
const oldRegion = doc.getElementById(LIVE_REGION_ID);
oldRegion == null ? void 0 : oldRegion.remove();
}
return {
announce,
destroy,
toJSON() {
return LIVE_REGION_ID;
}
};
}
// src/next-tick.ts

@@ -1182,2 +1141,19 @@ function nextTick(fn) {

// src/visually-hidden.ts
var visuallyHiddenStyle = {
border: "0",
clip: "rect(0 0 0 0)",
height: "1px",
margin: "-1px",
overflow: "hidden",
padding: "0",
position: "absolute",
width: "1px",
whiteSpace: "nowrap",
wordWrap: "normal"
};
function setVisuallyHidden(el) {
Object.assign(el.style, visuallyHiddenStyle);
}
// src/wait.ts

@@ -1184,0 +1160,0 @@ function waitFor(predicate) {

@@ -5,4 +5,4 @@ declare type DescriptorOptions = {

};
export declare function dispatchInputValueEvent(el: HTMLElement, value: string | number): void;
export declare function dispatchInputCheckedEvent(el: HTMLElement, checked: boolean): void;
export declare function dispatchInputValueEvent(el: HTMLElement | null, value: string | number): void;
export declare function dispatchInputCheckedEvent(el: HTMLElement | null, checked: boolean): void;
export declare function trackInputPropertyMutation(el: HTMLInputElement | null, options: DescriptorOptions & {

@@ -9,0 +9,0 @@ fn?: (value: string) => void;

declare type Callback = (v: MutationRecord) => void;
export declare function observeAttributes(node: Element | null, attributes: string | string[], fn: Callback): () => void;
export declare function observeChildren(node: Element | null, fn: Callback): () => void;
export declare function observeChildren(node: Element | null, fn: (v: MutationRecord[]) => void): () => void;
export {};

@@ -0,1 +1,2 @@

export declare function isDocument(el: any): el is Document;
export declare function isShadowRoot(el: any): el is ShadowRoot;

@@ -5,3 +6,3 @@ export declare function isWindow(value: any): value is Window;

export declare const isWithinShadowRoot: (node: HTMLElement) => boolean;
export declare function getDocument(el: Element | Window | null): Document;
export declare function getDocument(el: Element | Window | Node | Document | null): Document;
export declare function getRootNode(el: Node): Document | ShadowRoot;

@@ -16,2 +17,12 @@ export declare function getWindow(el: HTMLElement): Window & typeof globalThis;

export declare function getParent(el: HTMLElement): HTMLElement;
declare type Ctx = {
getRootNode?: () => Document | ShadowRoot | Node;
};
export declare function defineDomHelpers<T>(helpers: T): {
getRootNode: (ctx: Ctx) => Document | ShadowRoot;
getDoc: (ctx: Ctx) => Document;
getWin: (ctx: Ctx) => Window & typeof globalThis;
getActiveElement: (ctx: Ctx) => HTMLElement;
getById: <T_1 = HTMLElement>(ctx: Ctx, id: string) => T_1;
} & T;
export declare function contains(parent: HTMLElement | EventTarget | null | undefined, child: HTMLElement | EventTarget | null): boolean;

@@ -22,1 +33,2 @@ export declare function isHTMLElement(v: any): v is HTMLElement;

export declare function isVisible(el: Element): boolean;
export {};
{
"name": "@zag-js/dom-utils",
"version": "0.1.6",
"version": "0.1.7",
"description": "",

@@ -28,3 +28,3 @@ "keywords": [

"dependencies": {
"@zag-js/types": "0.2.1",
"@zag-js/types": "0.2.2",
"@zag-js/utils": "0.1.2"

@@ -31,0 +31,0 @@ },

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