@zag-js/dom-query
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { JSX, MaybeFn, Nullable } from '@zag-js/types'; | ||
import { JSX, MaybeFn, Nullable, MaybeElement as MaybeElement$2 } from '@zag-js/types'; | ||
@@ -266,2 +266,24 @@ declare function isCaretAtStart(input: HTMLInputElement | HTMLTextAreaElement | null): boolean; | ||
interface ElementRect { | ||
left: number; | ||
top: number; | ||
width: number; | ||
height: number; | ||
} | ||
interface RectEntryDetails { | ||
rects: ElementRect[]; | ||
entries: ResizeObserverEntry[]; | ||
} | ||
interface ElementRectOptions extends ResizeObserverOptions { | ||
/** | ||
* The callback to call when the element's rect changes. | ||
*/ | ||
onEntry: (details: RectEntryDetails) => void; | ||
/** | ||
* The function to call to get the element's rect. | ||
*/ | ||
measure: (el: HTMLElement) => ElementRect; | ||
} | ||
declare function trackElementRect(elements: MaybeElement$2[], options: ElementRectOptions): () => void; | ||
interface ScopeContext { | ||
@@ -363,2 +385,2 @@ getRootNode?: (() => Document | ShadowRoot | Node) | undefined; | ||
export { type CheckedEventOptions, type DataUrlOptions, type DataUrlType, type DisableTextSelectionOptions, type InitialFocusOptions, type InputValueEventOptions, type ItemToId, MAX_Z_INDEX, type ObserveAttributeOptions, type ObserveChildrenOptions, type OverflowAncestor, type PercentValueOptions, type PointerMoveDetails, type PointerMoveHandlers, type PressDetails, type ProxyTabFocusOptions, type ScopeContext, type ScrollOptions, type ScrollPosition, type SearchableItem, type TrackFormControlOptions, type TrackPressOptions, type TypeaheadOptions, type TypeaheadState, type ViewportSize, addDomEvent, ariaAttr, clickIfLink, contains, createScope, dataAttr, defaultItemToId, disableTextSelection, dispatchInputCheckedEvent, dispatchInputValueEvent, getActiveElement, getBeforeInputValue, getByText, getByTypeahead, getComputedStyle, getDataUrl, getDocument, getDocumentElement, getEventKey, getEventPoint, getEventStep, getEventTarget, getFirstFocusable, getFirstTabbable, getFocusables, getInitialFocus, getLastTabbable, getNativeEvent, getNearestOverflowAncestor, getNextTabbable, getNodeName, getOverflowAncestors, getParentNode, getPlatform, getRelativePoint, getScrollPosition, getTabIndex, getTabbableEdges, getTabbables, getUserAgent, getWindow, indexOfId, isAnchorElement, isAndroid, isApple, isCaretAtStart, isChrome, isComposingEvent, isContextMenuEvent, isCtrlOrMetaKey, isDocument, isDom, isDownloadingEvent, isEditableElement, isElementVisible, isFirefox, isFocusable, isHTMLElement, isIPad, isIPhone, isInView, isInputElement, isIos, isKeyboardClick, isLeftClick, isMac, isModifierKey, isNode, isOpeningInNewTab, isOverflowElement, isPrintableKey, isRootElement, isSafari, isSelfTarget, isShadowRoot, isTabbable, isTouchDevice, isTouchEvent, isValidTabEvent, isVirtualClick, isVirtualPointerEvent, isVisualViewport, isWebKit, isWindow, itemById, nextById, nextTick, observeAttributes, observeChildren, prevById, proxyTabFocus, query, queryAll, queueBeforeEvent, raf, requestPointerLock, restoreTextSelection, scrollIntoView, setAttribute, setCaretToEnd, setElementChecked, setElementValue, setProperty, setStyle, setStyleProperty, setVisuallyHidden, trackFormControl, trackPointerMove, trackPress, trackVisualViewport, visuallyHiddenStyle, waitForElement, waitForElements }; | ||
export { type CheckedEventOptions, type DataUrlOptions, type DataUrlType, type DisableTextSelectionOptions, type ElementRect, type ElementRectOptions, type InitialFocusOptions, type InputValueEventOptions, type ItemToId, MAX_Z_INDEX, type ObserveAttributeOptions, type ObserveChildrenOptions, type OverflowAncestor, type PercentValueOptions, type PointerMoveDetails, type PointerMoveHandlers, type PressDetails, type ProxyTabFocusOptions, type RectEntryDetails, type ScopeContext, type ScrollOptions, type ScrollPosition, type SearchableItem, type TrackFormControlOptions, type TrackPressOptions, type TypeaheadOptions, type TypeaheadState, type ViewportSize, addDomEvent, ariaAttr, clickIfLink, contains, createScope, dataAttr, defaultItemToId, disableTextSelection, dispatchInputCheckedEvent, dispatchInputValueEvent, getActiveElement, getBeforeInputValue, getByText, getByTypeahead, getComputedStyle, getDataUrl, getDocument, getDocumentElement, getEventKey, getEventPoint, getEventStep, getEventTarget, getFirstFocusable, getFirstTabbable, getFocusables, getInitialFocus, getLastTabbable, getNativeEvent, getNearestOverflowAncestor, getNextTabbable, getNodeName, getOverflowAncestors, getParentNode, getPlatform, getRelativePoint, getScrollPosition, getTabIndex, getTabbableEdges, getTabbables, getUserAgent, getWindow, indexOfId, isAnchorElement, isAndroid, isApple, isCaretAtStart, isChrome, isComposingEvent, isContextMenuEvent, isCtrlOrMetaKey, isDocument, isDom, isDownloadingEvent, isEditableElement, isElementVisible, isFirefox, isFocusable, isHTMLElement, isIPad, isIPhone, isInView, isInputElement, isIos, isKeyboardClick, isLeftClick, isMac, isModifierKey, isNode, isOpeningInNewTab, isOverflowElement, isPrintableKey, isRootElement, isSafari, isSelfTarget, isShadowRoot, isTabbable, isTouchDevice, isTouchEvent, isValidTabEvent, isVirtualClick, isVirtualPointerEvent, isVisualViewport, isWebKit, isWindow, itemById, nextById, nextTick, observeAttributes, observeChildren, prevById, proxyTabFocus, query, queryAll, queueBeforeEvent, raf, requestPointerLock, restoreTextSelection, scrollIntoView, setAttribute, setCaretToEnd, setElementChecked, setElementValue, setProperty, setStyle, setStyleProperty, setVisuallyHidden, trackElementRect, trackFormControl, trackPointerMove, trackPress, trackVisualViewport, visuallyHiddenStyle, waitForElement, waitForElements }; |
@@ -922,2 +922,17 @@ 'use strict'; | ||
// src/resize-observer.ts | ||
function trackElementRect(elements, options) { | ||
const { onEntry, measure, box = "border-box" } = options; | ||
const elems = (Array.isArray(elements) ? elements : [elements]).filter(isHTMLElement); | ||
const win = getWindow(elems[0]); | ||
const trigger = (entries) => { | ||
const rects = elems.map((el) => measure(el)); | ||
onEntry({ rects, entries }); | ||
}; | ||
trigger([]); | ||
const obs = new win.ResizeObserver(trigger); | ||
elems.forEach((el) => obs.observe(el, { box })); | ||
return () => obs.disconnect(); | ||
} | ||
// src/scope.ts | ||
@@ -1216,2 +1231,3 @@ function createScope(methods) { | ||
exports.setVisuallyHidden = setVisuallyHidden; | ||
exports.trackElementRect = trackElementRect; | ||
exports.trackFormControl = trackFormControl; | ||
@@ -1218,0 +1234,0 @@ exports.trackPointerMove = trackPointerMove; |
{ | ||
"name": "@zag-js/dom-query", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"description": "The dom helper library for zag.js machines", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@zag-js/types": "1.8.1" | ||
"@zag-js/types": "1.8.2" | ||
}, | ||
@@ -34,0 +34,0 @@ "module": "dist/index.mjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
123230
2.12%2668
1.91%+ Added
- Removed
Updated