Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/dom-event

Package Overview
Dependencies
Maintainers
1
Versions
681
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 0.0.0-dev-20230601120732 to 0.0.0-dev-20230605130234

5

dist/add-dom-event.d.ts

@@ -5,4 +5,3 @@ interface EventMap extends DocumentEventMap, WindowEventMap, HTMLElementEventMap {

type Target = (() => Node) | Node;
declare const addDomEvent: <K extends keyof EventMap>(target: Target, eventName: K, handler: (event: EventMap[K]) => void, options?: boolean | AddEventListenerOptions) => () => void;
export { addDomEvent };
export declare const addDomEvent: <K extends keyof EventMap>(target: Target, eventName: K, handler: (event: EventMap[K]) => void, options?: boolean | AddEventListenerOptions) => () => void;
export {};

35

dist/add-dom-event.js

@@ -1,27 +0,6 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/add-dom-event.ts
var add_dom_event_exports = {};
__export(add_dom_event_exports, {
addDomEvent: () => addDomEvent
});
module.exports = __toCommonJS(add_dom_event_exports);
var addDomEvent = (target, eventName, handler, options) => {
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const addDomEvent = (target, eventName, handler, options) => {
const node = typeof target === "function" ? target() : target;

@@ -33,5 +12,3 @@ node?.addEventListener(eventName, handler, options);

};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addDomEvent
});
exports.addDomEvent = addDomEvent;

@@ -1,10 +0,8 @@

declare function isKeyboardClick(e: Pick<MouseEvent, "detail" | "clientX" | "clientY">): boolean;
declare function isPrintableKey(e: Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey">): boolean;
declare function isVirtualPointerEvent(e: PointerEvent): boolean;
declare function isVirtualClick(e: MouseEvent | PointerEvent): boolean;
declare const isLeftClick: (e: Pick<MouseEvent, "button">) => boolean;
declare const isContextMenuEvent: (e: Pick<MouseEvent, "button" | "ctrlKey" | "metaKey">) => boolean;
declare const isModifiedEvent: (e: Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "altKey">) => boolean;
declare const isCtrlKey: (e: Pick<KeyboardEvent, "ctrlKey" | "metaKey">) => boolean;
export { isContextMenuEvent, isCtrlKey, isKeyboardClick, isLeftClick, isModifiedEvent, isPrintableKey, isVirtualClick, isVirtualPointerEvent };
export declare function isKeyboardClick(e: Pick<MouseEvent, "detail" | "clientX" | "clientY">): boolean;
export declare function isPrintableKey(e: Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey">): boolean;
export declare function isVirtualPointerEvent(e: PointerEvent): boolean;
export declare function isVirtualClick(e: MouseEvent | PointerEvent): boolean;
export declare const isLeftClick: (e: Pick<MouseEvent, "button">) => boolean;
export declare const isContextMenuEvent: (e: Pick<MouseEvent, "button" | "ctrlKey" | "metaKey">) => boolean;
export declare const isModifiedEvent: (e: Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "altKey">) => boolean;
export declare const isCtrlKey: (e: Pick<KeyboardEvent, "ctrlKey" | "metaKey">) => boolean;

@@ -1,33 +0,5 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/assertion.ts
var assertion_exports = {};
__export(assertion_exports, {
isContextMenuEvent: () => isContextMenuEvent,
isCtrlKey: () => isCtrlKey,
isKeyboardClick: () => isKeyboardClick,
isLeftClick: () => isLeftClick,
isModifiedEvent: () => isModifiedEvent,
isPrintableKey: () => isPrintableKey,
isVirtualClick: () => isVirtualClick,
isVirtualPointerEvent: () => isVirtualPointerEvent
});
module.exports = __toCommonJS(assertion_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
function isKeyboardClick(e) {

@@ -47,19 +19,17 @@ return e.detail === 0 || e.clientX === 0 && e.clientY === 0;

}
var isLeftClick = (e) => e.button === 0;
var isContextMenuEvent = (e) => {
const isLeftClick = (e) => e.button === 0;
const isContextMenuEvent = (e) => {
return e.button === 2 || isCtrlKey(e) && e.button === 0;
};
var isModifiedEvent = (e) => e.ctrlKey || e.altKey || e.metaKey;
var isMac = () => /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
var isCtrlKey = (e) => isMac() ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
isContextMenuEvent,
isCtrlKey,
isKeyboardClick,
isLeftClick,
isModifiedEvent,
isPrintableKey,
isVirtualClick,
isVirtualPointerEvent
});
const isModifiedEvent = (e) => e.ctrlKey || e.altKey || e.metaKey;
const isMac = () => /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
const isCtrlKey = (e) => isMac() ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey;
exports.isContextMenuEvent = isContextMenuEvent;
exports.isCtrlKey = isCtrlKey;
exports.isKeyboardClick = isKeyboardClick;
exports.isLeftClick = isLeftClick;
exports.isModifiedEvent = isModifiedEvent;
exports.isPrintableKey = isPrintableKey;
exports.isVirtualClick = isVirtualClick;
exports.isVirtualPointerEvent = isVirtualPointerEvent;

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

declare function fireCustomEvent(el: HTMLElement | null, type: string, init?: CustomEventInit): boolean | undefined;
declare function fireBlurEvent(el: HTMLElement, init?: FocusEventInit): boolean;
export { fireBlurEvent, fireCustomEvent };
export declare function fireCustomEvent(el: HTMLElement | null, type: string, init?: CustomEventInit): boolean | undefined;
export declare function fireBlurEvent(el: HTMLElement, init?: FocusEventInit): boolean;

@@ -1,27 +0,5 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/fire-event.ts
var fire_event_exports = {};
__export(fire_event_exports, {
fireBlurEvent: () => fireBlurEvent,
fireCustomEvent: () => fireCustomEvent
});
module.exports = __toCommonJS(fire_event_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
function fireCustomEvent(el, type, init) {

@@ -42,6 +20,4 @@ if (!el)

}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fireBlurEvent,
fireCustomEvent
});
exports.fireBlurEvent = fireBlurEvent;
exports.fireCustomEvent = fireCustomEvent;

@@ -1,9 +0,5 @@

import { EventKeyOptions } from './types.js';
import '@zag-js/types';
import type { EventKeyOptions } from "./types";
/**
* Determine the event key based on text direction.
*/
declare function getEventKey(event: Pick<KeyboardEvent, "key">, options?: EventKeyOptions): string;
export { getEventKey };
export declare function getEventKey(event: Pick<KeyboardEvent, "key">, options?: EventKeyOptions): string;

@@ -1,27 +0,6 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/get-event-key.ts
var get_event_key_exports = {};
__export(get_event_key_exports, {
getEventKey: () => getEventKey
});
module.exports = __toCommonJS(get_event_key_exports);
var keyMap = {
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const keyMap = {
Up: "ArrowUp",

@@ -35,3 +14,3 @@ Down: "ArrowDown",

};
var rtlKeyMap = {
const rtlKeyMap = {
ArrowLeft: "ArrowRight",

@@ -50,5 +29,3 @@ ArrowRight: "ArrowLeft"

}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getEventKey
});
exports.getEventKey = getEventKey;
type PointType = "page" | "client";
type AnyPointerEvent = MouseEvent | TouchEvent | PointerEvent;
declare function getEventPoint(event: AnyPointerEvent, type?: PointType): {
export declare function getEventPoint(event: AnyPointerEvent, type?: PointType): {
x: number;
y: number;
};
export { getEventPoint };
export {};

@@ -1,26 +0,5 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/get-event-point.ts
var get_event_point_exports = {};
__export(get_event_point_exports, {
getEventPoint: () => getEventPoint
});
module.exports = __toCommonJS(get_event_point_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
function pointFromTouch(e, type = "client") {

@@ -33,9 +12,7 @@ const point = e.touches[0] || e.changedTouches[0];

}
var isTouchEvent = (event) => "touches" in event && event.touches.length > 0;
const isTouchEvent = (event) => "touches" in event && event.touches.length > 0;
function getEventPoint(event, type = "client") {
return isTouchEvent(event) ? pointFromTouch(event, type) : pointFromMouse(event, type);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getEventPoint
});
exports.getEventPoint = getEventPoint;
/**
* Determine the step factor for keyboard events
*/
declare function getEventStep(event: Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "key" | "shiftKey">): 1 | 0.1 | 10;
export { getEventStep };
export declare function getEventStep(event: Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "key" | "shiftKey">): 1 | 0.1 | 10;

@@ -1,28 +0,7 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/get-event-step.ts
var get_event_step_exports = {};
__export(get_event_step_exports, {
getEventStep: () => getEventStep
});
module.exports = __toCommonJS(get_event_step_exports);
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
const ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
function getEventStep(event) {

@@ -37,5 +16,3 @@ if (event.ctrlKey || event.metaKey) {

}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getEventStep
});
exports.getEventStep = getEventStep;

@@ -1,6 +0,4 @@

import { JSX } from '@zag-js/types';
import type { JSX } from "@zag-js/types";
type NativeEvent<E> = JSX.ChangeEvent<any> extends E ? InputEvent : E extends JSX.SyntheticEvent<any, infer T> ? T : never;
declare function getNativeEvent<E>(event: E): NativeEvent<E>;
export { getNativeEvent };
export declare function getNativeEvent<E>(event: E): NativeEvent<E>;
export {};

@@ -1,32 +0,9 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/get-native-event.ts
var get_native_event_exports = {};
__export(get_native_event_exports, {
getNativeEvent: () => getNativeEvent
});
module.exports = __toCommonJS(get_native_event_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
function getNativeEvent(event) {
return event.nativeEvent ?? event;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getNativeEvent
});
exports.getNativeEvent = getNativeEvent;

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

type Point = {
export type Point = {
x: number;

@@ -13,3 +13,3 @@ y: number;

};
declare function getRelativePoint(point: Point, element: HTMLElement): {
export declare function getRelativePoint(point: Point, element: HTMLElement): {
offset: {

@@ -25,3 +25,2 @@ x: number;

};
export { Point, getRelativePoint };
export {};

@@ -1,26 +0,5 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/get-point-value.ts
var get_point_value_exports = {};
__export(get_point_value_exports, {
getRelativePoint: () => getRelativePoint
});
module.exports = __toCommonJS(get_point_value_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
function clamp(value) {

@@ -44,5 +23,3 @@ return Math.max(0, Math.min(1, value));

}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getRelativePoint
});
exports.getRelativePoint = getRelativePoint;

@@ -1,13 +0,12 @@

export { addDomEvent } from './add-dom-event.js';
export { isContextMenuEvent, isCtrlKey, isKeyboardClick, isLeftClick, isModifiedEvent, isPrintableKey, isVirtualClick, isVirtualPointerEvent } from './assertion.js';
export { fireBlurEvent, fireCustomEvent } from './fire-event.js';
export { getEventKey } from './get-event-key.js';
export { getEventPoint } from './get-event-point.js';
export { getEventStep } from './get-event-step.js';
export { getNativeEvent } from './get-native-event.js';
export { Point, getRelativePoint } from './get-point-value.js';
export { requestPointerLock } from './request-pointer-lock.js';
export { trackPointerMove } from './track-pointer-move.js';
export { trackVisualViewport } from './track-visual-viewport.js';
export { EventKeyMap } from './types.js';
import '@zag-js/types';
export * from "./add-dom-event";
export * from "./assertion";
export * from "./fire-event";
export * from "./get-event-key";
export * from "./get-event-point";
export * from "./get-event-step";
export * from "./get-native-event";
export * from "./get-point-value";
export * from "./request-pointer-lock";
export * from "./track-pointer-move";
export * from "./track-visual-viewport";
export type { EventKeyMap } from "./types";

@@ -1,264 +0,37 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/index.ts
var src_exports = {};
__export(src_exports, {
addDomEvent: () => addDomEvent,
fireBlurEvent: () => fireBlurEvent,
fireCustomEvent: () => fireCustomEvent,
getEventKey: () => getEventKey,
getEventPoint: () => getEventPoint,
getEventStep: () => getEventStep,
getNativeEvent: () => getNativeEvent,
getRelativePoint: () => getRelativePoint,
isContextMenuEvent: () => isContextMenuEvent,
isCtrlKey: () => isCtrlKey,
isKeyboardClick: () => isKeyboardClick,
isLeftClick: () => isLeftClick,
isModifiedEvent: () => isModifiedEvent,
isPrintableKey: () => isPrintableKey,
isVirtualClick: () => isVirtualClick,
isVirtualPointerEvent: () => isVirtualPointerEvent,
requestPointerLock: () => requestPointerLock,
trackPointerMove: () => trackPointerMove,
trackVisualViewport: () => trackVisualViewport
});
module.exports = __toCommonJS(src_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
// src/add-dom-event.ts
var addDomEvent = (target, eventName, handler, options) => {
const node = typeof target === "function" ? target() : target;
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
};
const addDomEvent = require('./add-dom-event.js');
const assertion = require('./assertion.js');
const fireEvent = require('./fire-event.js');
const getEventKey = require('./get-event-key.js');
const getEventPoint = require('./get-event-point.js');
const getEventStep = require('./get-event-step.js');
const getNativeEvent = require('./get-native-event.js');
const getPointValue = require('./get-point-value.js');
const requestPointerLock = require('./request-pointer-lock.js');
const trackPointerMove = require('./track-pointer-move.js');
const trackVisualViewport = require('./track-visual-viewport.js');
// src/assertion.ts
function isKeyboardClick(e) {
return e.detail === 0 || e.clientX === 0 && e.clientY === 0;
}
function isPrintableKey(e) {
return e.key.length === 1 && !e.ctrlKey && !e.metaKey;
}
function isVirtualPointerEvent(e) {
return e.width === 0 && e.height === 0 || e.width === 1 && e.height === 1 && e.pressure === 0 && e.detail === 0 && e.pointerType === "mouse";
}
function isVirtualClick(e) {
if (e.mozInputSource === 0 && e.isTrusted)
return true;
return e.detail === 0 && !e.pointerType;
}
var isLeftClick = (e) => e.button === 0;
var isContextMenuEvent = (e) => {
return e.button === 2 || isCtrlKey(e) && e.button === 0;
};
var isModifiedEvent = (e) => e.ctrlKey || e.altKey || e.metaKey;
var isMac = () => /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
var isCtrlKey = (e) => isMac() ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey;
// src/fire-event.ts
function fireCustomEvent(el, type, init) {
if (!el)
return;
const win = el.ownerDocument.defaultView || window;
const event = new win.CustomEvent(type, init);
return el.dispatchEvent(event);
}
function fireBlurEvent(el, init) {
const win = el.ownerDocument.defaultView || window;
const event = new win.FocusEvent("blur", init);
const allowed = el.dispatchEvent(event);
const bubbleInit = { ...init, bubbles: true };
el.dispatchEvent(new win.FocusEvent("focusout", bubbleInit));
return allowed;
}
// src/get-event-key.ts
var keyMap = {
Up: "ArrowUp",
Down: "ArrowDown",
Esc: "Escape",
" ": "Space",
",": "Comma",
Left: "ArrowLeft",
Right: "ArrowRight"
};
var rtlKeyMap = {
ArrowLeft: "ArrowRight",
ArrowRight: "ArrowLeft"
};
function getEventKey(event, options = {}) {
const { dir = "ltr", orientation = "horizontal" } = options;
let { key } = event;
key = keyMap[key] ?? key;
const isRtl = dir === "rtl" && orientation === "horizontal";
if (isRtl && key in rtlKeyMap) {
key = rtlKeyMap[key];
}
return key;
}
// src/get-event-point.ts
function pointFromTouch(e, type = "client") {
const point = e.touches[0] || e.changedTouches[0];
return { x: point[`${type}X`], y: point[`${type}Y`] };
}
function pointFromMouse(point, type = "client") {
return { x: point[`${type}X`], y: point[`${type}Y`] };
}
var isTouchEvent = (event) => "touches" in event && event.touches.length > 0;
function getEventPoint(event, type = "client") {
return isTouchEvent(event) ? pointFromTouch(event, type) : pointFromMouse(event, type);
}
// src/get-event-step.ts
var PAGE_KEYS = /* @__PURE__ */ new Set(["PageUp", "PageDown"]);
var ARROW_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
function getEventStep(event) {
if (event.ctrlKey || event.metaKey) {
return 0.1;
} else {
const isPageKey = PAGE_KEYS.has(event.key);
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.has(event.key);
return isSkipKey ? 10 : 1;
}
}
// src/get-native-event.ts
function getNativeEvent(event) {
return event.nativeEvent ?? event;
}
// src/get-point-value.ts
function clamp(value) {
return Math.max(0, Math.min(1, value));
}
function getRelativePoint(point, element) {
const { left, top, width, height } = element.getBoundingClientRect();
const offset = { x: point.x - left, y: point.y - top };
const percent = { x: clamp(offset.x / width), y: clamp(offset.y / height) };
function getPercentValue(options = {}) {
const { dir = "ltr", orientation = "horizontal", inverted } = options;
const invertX = typeof inverted === "object" ? inverted.x : inverted;
const invertY = typeof inverted === "object" ? inverted.y : inverted;
if (orientation === "horizontal") {
return dir === "rtl" || invertX ? 1 - percent.x : percent.x;
}
return invertY ? 1 - percent.y : percent.y;
}
return { offset, percent, getPercentValue };
}
// src/request-pointer-lock.ts
function requestPointerLock(doc, fn) {
const body = doc.body;
const supported = "pointerLockElement" in doc || "mozPointerLockElement" in doc;
const isLocked = () => !!doc.pointerLockElement;
function onPointerChange() {
fn?.(isLocked());
}
function onPointerError(event) {
if (isLocked())
fn?.(false);
console.error("PointerLock error occured:", event);
doc.exitPointerLock();
}
if (!supported)
return;
try {
body.requestPointerLock();
} catch {
}
const cleanup = [
addDomEvent(doc, "pointerlockchange", onPointerChange, false),
addDomEvent(doc, "pointerlockerror", onPointerError, false)
];
return () => {
cleanup.forEach((cleanup2) => cleanup2());
doc.exitPointerLock();
};
}
// src/track-pointer-move.ts
var import_text_selection = require("@zag-js/text-selection");
function trackPointerMove(doc, handlers) {
const { onPointerMove, onPointerUp } = handlers;
const handleMove = (event) => {
const point = getEventPoint(event);
const distance = Math.sqrt(point.x ** 2 + point.y ** 2);
const moveBuffer = event.pointerType === "touch" ? 10 : 5;
if (distance < moveBuffer)
return;
if (event.pointerType === "mouse" && event.button === 0) {
onPointerUp();
return;
}
onPointerMove({ point, event });
};
const cleanups = [
addDomEvent(doc, "pointermove", handleMove, false),
addDomEvent(doc, "pointerup", onPointerUp, false),
addDomEvent(doc, "pointercancel", onPointerUp, false),
addDomEvent(doc, "contextmenu", onPointerUp, false),
(0, import_text_selection.disableTextSelection)({ doc })
];
return () => {
cleanups.forEach((cleanup) => cleanup());
};
}
// src/track-visual-viewport.ts
function trackVisualViewport(doc, fn) {
const win = doc?.defaultView || window;
const onResize = () => {
fn?.(getViewportSize(win));
};
onResize();
return addDomEvent(win.visualViewport ?? win, "resize", onResize);
}
function getViewportSize(win) {
return {
width: win.visualViewport?.width || win.innerWidth,
height: win.visualViewport?.height || win.innerHeight
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addDomEvent,
fireBlurEvent,
fireCustomEvent,
getEventKey,
getEventPoint,
getEventStep,
getNativeEvent,
getRelativePoint,
isContextMenuEvent,
isCtrlKey,
isKeyboardClick,
isLeftClick,
isModifiedEvent,
isPrintableKey,
isVirtualClick,
isVirtualPointerEvent,
requestPointerLock,
trackPointerMove,
trackVisualViewport
});
exports.addDomEvent = addDomEvent.addDomEvent;
exports.isContextMenuEvent = assertion.isContextMenuEvent;
exports.isCtrlKey = assertion.isCtrlKey;
exports.isKeyboardClick = assertion.isKeyboardClick;
exports.isLeftClick = assertion.isLeftClick;
exports.isModifiedEvent = assertion.isModifiedEvent;
exports.isPrintableKey = assertion.isPrintableKey;
exports.isVirtualClick = assertion.isVirtualClick;
exports.isVirtualPointerEvent = assertion.isVirtualPointerEvent;
exports.fireBlurEvent = fireEvent.fireBlurEvent;
exports.fireCustomEvent = fireEvent.fireCustomEvent;
exports.getEventKey = getEventKey.getEventKey;
exports.getEventPoint = getEventPoint.getEventPoint;
exports.getEventStep = getEventStep.getEventStep;
exports.getNativeEvent = getNativeEvent.getNativeEvent;
exports.getRelativePoint = getPointValue.getRelativePoint;
exports.requestPointerLock = requestPointerLock.requestPointerLock;
exports.trackPointerMove = trackPointerMove.trackPointerMove;
exports.trackVisualViewport = trackVisualViewport.trackVisualViewport;

@@ -1,3 +0,1 @@

declare function requestPointerLock(doc: Document, fn?: (locked: boolean) => void): (() => void) | undefined;
export { requestPointerLock };
export declare function requestPointerLock(doc: Document, fn?: (locked: boolean) => void): (() => void) | undefined;

@@ -1,37 +0,7 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/request-pointer-lock.ts
var request_pointer_lock_exports = {};
__export(request_pointer_lock_exports, {
requestPointerLock: () => requestPointerLock
});
module.exports = __toCommonJS(request_pointer_lock_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
// src/add-dom-event.ts
var addDomEvent = (target, eventName, handler, options) => {
const node = typeof target === "function" ? target() : target;
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
};
const addDomEvent = require('./add-dom-event.js');
// src/request-pointer-lock.ts
function requestPointerLock(doc, fn) {

@@ -57,4 +27,4 @@ const body = doc.body;

const cleanup = [
addDomEvent(doc, "pointerlockchange", onPointerChange, false),
addDomEvent(doc, "pointerlockerror", onPointerError, false)
addDomEvent.addDomEvent(doc, "pointerlockchange", onPointerChange, false),
addDomEvent.addDomEvent(doc, "pointerlockerror", onPointerError, false)
];

@@ -66,5 +36,3 @@ return () => {

}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
requestPointerLock
});
exports.requestPointerLock = requestPointerLock;

@@ -12,4 +12,3 @@ type Point = {

};
declare function trackPointerMove(doc: Document, handlers: PointerMoveHandlers): () => void;
export { trackPointerMove };
export declare function trackPointerMove(doc: Document, handlers: PointerMoveHandlers): () => void;
export {};

@@ -1,55 +0,13 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/track-pointer-move.ts
var track_pointer_move_exports = {};
__export(track_pointer_move_exports, {
trackPointerMove: () => trackPointerMove
});
module.exports = __toCommonJS(track_pointer_move_exports);
var import_text_selection = require("@zag-js/text-selection");
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
// src/add-dom-event.ts
var addDomEvent = (target, eventName, handler, options) => {
const node = typeof target === "function" ? target() : target;
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
};
const textSelection = require('@zag-js/text-selection');
const addDomEvent = require('./add-dom-event.js');
const getEventPoint = require('./get-event-point.js');
// src/get-event-point.ts
function pointFromTouch(e, type = "client") {
const point = e.touches[0] || e.changedTouches[0];
return { x: point[`${type}X`], y: point[`${type}Y`] };
}
function pointFromMouse(point, type = "client") {
return { x: point[`${type}X`], y: point[`${type}Y`] };
}
var isTouchEvent = (event) => "touches" in event && event.touches.length > 0;
function getEventPoint(event, type = "client") {
return isTouchEvent(event) ? pointFromTouch(event, type) : pointFromMouse(event, type);
}
// src/track-pointer-move.ts
function trackPointerMove(doc, handlers) {
const { onPointerMove, onPointerUp } = handlers;
const handleMove = (event) => {
const point = getEventPoint(event);
const point = getEventPoint.getEventPoint(event);
const distance = Math.sqrt(point.x ** 2 + point.y ** 2);

@@ -66,7 +24,7 @@ const moveBuffer = event.pointerType === "touch" ? 10 : 5;

const cleanups = [
addDomEvent(doc, "pointermove", handleMove, false),
addDomEvent(doc, "pointerup", onPointerUp, false),
addDomEvent(doc, "pointercancel", onPointerUp, false),
addDomEvent(doc, "contextmenu", onPointerUp, false),
(0, import_text_selection.disableTextSelection)({ doc })
addDomEvent.addDomEvent(doc, "pointermove", handleMove, false),
addDomEvent.addDomEvent(doc, "pointerup", onPointerUp, false),
addDomEvent.addDomEvent(doc, "pointercancel", onPointerUp, false),
addDomEvent.addDomEvent(doc, "contextmenu", onPointerUp, false),
textSelection.disableTextSelection({ doc })
];

@@ -77,5 +35,3 @@ return () => {

}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
trackPointerMove
});
exports.trackPointerMove = trackPointerMove;

@@ -5,4 +5,3 @@ type ViewportSize = {

};
declare function trackVisualViewport(doc: Document, fn: (data: ViewportSize) => void): () => void;
export { trackVisualViewport };
export declare function trackVisualViewport(doc: Document, fn: (data: ViewportSize) => void): () => void;
export {};

@@ -1,37 +0,7 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
'use strict';
// src/track-visual-viewport.ts
var track_visual_viewport_exports = {};
__export(track_visual_viewport_exports, {
trackVisualViewport: () => trackVisualViewport
});
module.exports = __toCommonJS(track_visual_viewport_exports);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
// src/add-dom-event.ts
var addDomEvent = (target, eventName, handler, options) => {
const node = typeof target === "function" ? target() : target;
node?.addEventListener(eventName, handler, options);
return () => {
node?.removeEventListener(eventName, handler, options);
};
};
const addDomEvent = require('./add-dom-event.js');
// src/track-visual-viewport.ts
function trackVisualViewport(doc, fn) {

@@ -43,3 +13,3 @@ const win = doc?.defaultView || window;

onResize();
return addDomEvent(win.visualViewport ?? win, "resize", onResize);
return addDomEvent.addDomEvent(win.visualViewport ?? win, "resize", onResize);
}

@@ -52,5 +22,3 @@ function getViewportSize(win) {

}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
trackVisualViewport
});
exports.trackVisualViewport = trackVisualViewport;

@@ -1,12 +0,9 @@

import { JSX } from '@zag-js/types';
type EventKey = "ArrowDown" | "ArrowUp" | "ArrowLeft" | "ArrowRight" | "Space" | "Enter" | "Comma" | "Escape" | "Backspace" | "Delete" | "Home" | "End" | "Tab" | "PageUp" | "PageDown" | (string & {});
type EventKeyMap = {
import type { JSX } from "@zag-js/types";
export type EventKey = "ArrowDown" | "ArrowUp" | "ArrowLeft" | "ArrowRight" | "Space" | "Enter" | "Comma" | "Escape" | "Backspace" | "Delete" | "Home" | "End" | "Tab" | "PageUp" | "PageDown" | (string & {});
export type EventKeyMap = {
[key in EventKey]?: (event: JSX.KeyboardEvent) => void;
};
type EventKeyOptions = {
export type EventKeyOptions = {
dir?: "ltr" | "rtl";
orientation?: "horizontal" | "vertical";
};
export { EventKey, EventKeyMap, EventKeyOptions };
{
"name": "@zag-js/dom-event",
"version": "0.0.0-dev-20230601120732",
"version": "0.0.0-dev-20230605130234",
"description": "",

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

"dependencies": {
"@zag-js/types": "0.0.0-dev-20230601120732",
"@zag-js/text-selection": "0.0.0-dev-20230601120732"
"@zag-js/types": "0.0.0-dev-20230605130234",
"@zag-js/text-selection": "0.0.0-dev-20230605130234"
},

@@ -46,11 +46,6 @@ "devDependencies": {

"scripts": {
"build-fast": "tsup src",
"start": "pnpm build --watch",
"build": "tsup src --dts",
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
"build": "vite build -c ../../../vite.config.ts",
"lint": "eslint src --ext .ts,.tsx",
"test-ci": "pnpm test --ci --runInBand",
"test-watch": "pnpm test --watch -u",
"typecheck": "tsc --noEmit"
}
}

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

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