@react-hive/honey-utils 3.12.0 → 3.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -9
- package/dist/README.md +65 -9
- package/dist/a11y/focus/get-focusable-html-elements.d.ts +12 -0
- package/dist/a11y/focus/index.d.ts +3 -0
- package/dist/a11y/focus/is-html-element-focusable.d.ts +21 -0
- package/dist/a11y/focus/move-focus-within-container.d.ts +52 -0
- package/dist/a11y/index.d.ts +1 -0
- package/dist/dom/dom.d.ts +42 -0
- package/dist/dom/file/download-file.d.ts +35 -0
- package/dist/dom/file/index.d.ts +1 -0
- package/dist/dom/index.d.ts +4 -0
- package/dist/dom/layout/center-element-in-container.d.ts +30 -0
- package/dist/dom/layout/index.d.ts +2 -0
- package/dist/dom/layout/overflow.d.ts +38 -0
- package/dist/dom/transform/index.d.ts +1 -0
- package/dist/dom/transform/parse-2d-matrix.d.ts +25 -0
- package/dist/env/index.d.ts +1 -0
- package/dist/env/storage/index.d.ts +1 -0
- package/dist/env/storage/local-storage.d.ts +40 -0
- package/dist/geometry/index.d.ts +1 -0
- package/dist/geometry/layout/calculate-center-offset.d.ts +39 -0
- package/dist/geometry/layout/index.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.dev.cjs +719 -295
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/intersection/get-dom-rect-intersection-ratio.d.ts +12 -0
- package/dist/intersection/index.d.ts +2 -0
- package/dist/intersection/resolve-axis-delta.d.ts +58 -0
- package/package.json +1 -1
- package/dist/dom.d.ts +0 -343
package/dist/dom.d.ts
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import type { Nullable } from './types';
|
|
2
|
-
export declare const FOCUSABLE_HTML_TAGS: string[];
|
|
3
|
-
interface HTMLElementTransformationValues {
|
|
4
|
-
translateX: number;
|
|
5
|
-
translateY: number;
|
|
6
|
-
scaleX: number;
|
|
7
|
-
scaleY: number;
|
|
8
|
-
skewX: number;
|
|
9
|
-
skewY: number;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Extracts transformation values (translate, scale, skew) from the 2D transformation matrix of a given HTML element.
|
|
13
|
-
*
|
|
14
|
-
* Only works with 2D transforms (i.e., `matrix(a, b, c, d, e, f)`).
|
|
15
|
-
*
|
|
16
|
-
* @param element - The element with a CSS transform applied.
|
|
17
|
-
* @returns An object with parsed transformation values.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const values = parse2DMatrix(myElement);
|
|
22
|
-
* console.log(values.translateX);
|
|
23
|
-
* console.log(values.scaleX);
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare const parse2DMatrix: (element: HTMLElement) => HTMLElementTransformationValues;
|
|
27
|
-
/**
|
|
28
|
-
* Creates a clone of a Blob object.
|
|
29
|
-
*
|
|
30
|
-
* @param blob - The Blob object to clone.
|
|
31
|
-
*
|
|
32
|
-
* @returns A new Blob with the same content and type as the original.
|
|
33
|
-
*/
|
|
34
|
-
export declare const cloneBlob: (blob: Blob) => Blob;
|
|
35
|
-
/**
|
|
36
|
-
* Calculates the intersection ratio between two DOM rectangles.
|
|
37
|
-
*
|
|
38
|
-
* The ratio represents the proportion of the `targetRect` that is covered by `sourceRect`.
|
|
39
|
-
* A value of `1` means `sourceRect` completely covers `targetRect`, and `0` means no overlap.
|
|
40
|
-
*
|
|
41
|
-
* @param sourceRect - The rectangle used to measure overlap against the target.
|
|
42
|
-
* @param targetRect - The rectangle whose covered area is measured.
|
|
43
|
-
*
|
|
44
|
-
* @returns A number between `0` and `1` representing the intersection ratio.
|
|
45
|
-
*/
|
|
46
|
-
export declare const getDOMRectIntersectionRatio: (sourceRect: DOMRect, targetRect: DOMRect) => number;
|
|
47
|
-
/**
|
|
48
|
-
* Returns the bounding DOMRect of an element based on offset and client dimensions.
|
|
49
|
-
*
|
|
50
|
-
* This utility is useful when you need a stable, layout-based rect
|
|
51
|
-
* without triggering a reflow via `getBoundingClientRect()`.
|
|
52
|
-
*
|
|
53
|
-
* @param element - The target HTML element.
|
|
54
|
-
* @returns A `DOMRect` representing the element’s offset position and size.
|
|
55
|
-
*/
|
|
56
|
-
export declare const getElementOffsetRect: (element: HTMLElement) => DOMRect;
|
|
57
|
-
/**
|
|
58
|
-
* Determines whether the given HTMLElement is an HTMLAnchorElement.
|
|
59
|
-
*
|
|
60
|
-
* Acts as a type guard so that TypeScript narrows `element` to
|
|
61
|
-
* `HTMLAnchorElement` when the function returns `true`.
|
|
62
|
-
*
|
|
63
|
-
* An element qualifies as an anchor by having a tag name of `"A"`.
|
|
64
|
-
*
|
|
65
|
-
* @param element - The element to test.
|
|
66
|
-
*
|
|
67
|
-
* @returns Whether the element is an anchor element.
|
|
68
|
-
*/
|
|
69
|
-
export declare const isAnchorHtmlElement: (element: HTMLElement) => element is HTMLAnchorElement;
|
|
70
|
-
/**
|
|
71
|
-
* Checks whether an element is explicitly marked as contenteditable.
|
|
72
|
-
*
|
|
73
|
-
* Browsers treat elements with `contenteditable="true"` as focusable,
|
|
74
|
-
* even if they are not normally keyboard-focusable.
|
|
75
|
-
*
|
|
76
|
-
* @param element - The element to inspect.
|
|
77
|
-
*
|
|
78
|
-
* @returns True if `contenteditable="true"` is set.
|
|
79
|
-
*/
|
|
80
|
-
export declare const isContentEditableHtmlElement: (element: HTMLElement) => boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Determines whether an HTMLElement is focusable under standard browser rules.
|
|
83
|
-
*
|
|
84
|
-
* The function checks a combination of factors:
|
|
85
|
-
* - The element must be rendered (not `display: none` or `visibility: hidden`).
|
|
86
|
-
* - Disabled form controls are never focusable.
|
|
87
|
-
* - Elements with `tabindex="-1"` are intentionally removed from the focus order.
|
|
88
|
-
* - Certain native HTML elements are inherently focusable (e.g. inputs, buttons, anchors with `href`).
|
|
89
|
-
* - Elements with `contenteditable="true"` are treated as focusable.
|
|
90
|
-
* - Any element with a valid `tabindex` (not null) is considered focusable.
|
|
91
|
-
*
|
|
92
|
-
* This logic approximates how browsers and the accessibility tree
|
|
93
|
-
* determine real-world focusability—not just tabindex presence.
|
|
94
|
-
*
|
|
95
|
-
* @param element - The element to test. `null` or `undefined` will return `false`.
|
|
96
|
-
*
|
|
97
|
-
* @returns Whether the element is focusable.
|
|
98
|
-
*/
|
|
99
|
-
export declare const isHtmlElementFocusable: (element: Nullable<HTMLElement>) => boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Collects all focusable descendant elements within a container.
|
|
102
|
-
*
|
|
103
|
-
* The function queries *all* elements under the container and filters them
|
|
104
|
-
* using `isHtmlElementFocusable`, producing a reliable list of elements
|
|
105
|
-
* that can receive keyboard focus in real-world browser conditions.
|
|
106
|
-
*
|
|
107
|
-
* @param container - The root container whose focusable children will be found.
|
|
108
|
-
*
|
|
109
|
-
* @returns An array of focusable HTMLElements in DOM order.
|
|
110
|
-
*/
|
|
111
|
-
export declare const getFocusableHtmlElements: (container: HTMLElement) => HTMLElement[];
|
|
112
|
-
export type FocusMoveDirection = 'next' | 'previous';
|
|
113
|
-
export interface MoveFocusWithinContainerOptions {
|
|
114
|
-
/**
|
|
115
|
-
* Whether focus navigation should wrap around when reaching
|
|
116
|
-
* the beginning or end of the focusable elements list.
|
|
117
|
-
*
|
|
118
|
-
* When enabled, moving past the last element focuses the first,
|
|
119
|
-
* and moving before the first focuses the last.
|
|
120
|
-
*
|
|
121
|
-
* @default true
|
|
122
|
-
*/
|
|
123
|
-
wrap?: boolean;
|
|
124
|
-
/**
|
|
125
|
-
* Custom resolver for determining the next focus index.
|
|
126
|
-
*
|
|
127
|
-
* When provided, this function overrides the default navigation logic
|
|
128
|
-
* and receives full control over how the focus moves.
|
|
129
|
-
*
|
|
130
|
-
* @param currentIndex - Index of the currently focused element.
|
|
131
|
-
* @param direction - Direction in which focus is moving.
|
|
132
|
-
* @param elements - Ordered list of focusable elements within the container.
|
|
133
|
-
*
|
|
134
|
-
* @returns The index of the element to focus next, or `null` to prevent focus movement.
|
|
135
|
-
*/
|
|
136
|
-
getNextIndex?: (currentIndex: number, direction: FocusMoveDirection, elements: HTMLElement[]) => Nullable<number>;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Moves focus to the next or previous focusable element within a container.
|
|
140
|
-
*
|
|
141
|
-
* This utility is commonly used to implement accessible keyboard navigation patterns such as:
|
|
142
|
-
* - roving tabindex
|
|
143
|
-
* - custom dropdowns
|
|
144
|
-
* - tablists
|
|
145
|
-
* - menus
|
|
146
|
-
* - horizontal or vertical navigation groups
|
|
147
|
-
*
|
|
148
|
-
* Focus movement is scoped to a container and operates on the list of
|
|
149
|
-
* focusable descendants returned by `getFocusableHtmlElements`.
|
|
150
|
-
*
|
|
151
|
-
* @param direction - Direction in which focus should move (`'next'` or `'previous'`).
|
|
152
|
-
* @param container - Optional container that defines the focus scope.
|
|
153
|
-
* If omitted, the parent element of the currently focused element is used.
|
|
154
|
-
* @param options - Optional configuration controlling wrapping behavior and custom index resolution.
|
|
155
|
-
*
|
|
156
|
-
* @remarks
|
|
157
|
-
* - This function reads from and mutates the document's focus state.
|
|
158
|
-
* - If no active element exists, no container can be resolved,
|
|
159
|
-
* or the active element is not part of the focusable set, no action is taken.
|
|
160
|
-
* - When `getNextIndex` is provided, it fully overrides the default wrapping and directional logic.
|
|
161
|
-
*/
|
|
162
|
-
export declare const moveFocusWithinContainer: (direction: FocusMoveDirection, container?: Nullable<HTMLElement>, { wrap, getNextIndex }?: MoveFocusWithinContainerOptions) => void;
|
|
163
|
-
/**
|
|
164
|
-
* Checks whether an element has horizontal overflow.
|
|
165
|
-
*
|
|
166
|
-
* @param element - The element to check.
|
|
167
|
-
*
|
|
168
|
-
* @returns `true` if the content overflows horizontally.
|
|
169
|
-
*/
|
|
170
|
-
export declare const hasXOverflow: (element: HTMLElement) => boolean;
|
|
171
|
-
/**
|
|
172
|
-
* Calculates the horizontal overflow width of an element.
|
|
173
|
-
*
|
|
174
|
-
* The overflow width represents how much wider the content is compared
|
|
175
|
-
* to the visible container area.
|
|
176
|
-
*
|
|
177
|
-
* @param element - The scrollable container element.
|
|
178
|
-
*
|
|
179
|
-
* @returns The overflow width in pixels. Returns `0` when the content does not overflow horizontally.
|
|
180
|
-
*/
|
|
181
|
-
export declare const getXOverflowWidth: (element: HTMLElement) => number;
|
|
182
|
-
/**
|
|
183
|
-
* Checks whether an element has vertical overflow.
|
|
184
|
-
*
|
|
185
|
-
* @param element - The element to check.
|
|
186
|
-
*
|
|
187
|
-
* @returns `true` if the content overflows vertically.
|
|
188
|
-
*/
|
|
189
|
-
export declare const hasYOverflow: (element: HTMLElement) => boolean;
|
|
190
|
-
/**
|
|
191
|
-
* Calculates the vertical overflow height of an element.
|
|
192
|
-
*
|
|
193
|
-
* The overflow height represents how much taller the content is compared
|
|
194
|
-
* to the visible container area.
|
|
195
|
-
*
|
|
196
|
-
* @param element - The scrollable container element.
|
|
197
|
-
*
|
|
198
|
-
* @returns The overflow height in pixels. Returns `0` when the content does not overflow vertically.
|
|
199
|
-
*/
|
|
200
|
-
export declare const getYOverflowHeight: (element: HTMLElement) => number;
|
|
201
|
-
export interface CalculateCenterOffsetOptions {
|
|
202
|
-
/**
|
|
203
|
-
* Total overflow size for the axis.
|
|
204
|
-
*
|
|
205
|
-
* Represents how much larger the content is compared to the visible
|
|
206
|
-
* container size (e.g. scroll width minus client width).
|
|
207
|
-
*/
|
|
208
|
-
overflowSize: number;
|
|
209
|
-
/**
|
|
210
|
-
* Visible size of the container along the axis.
|
|
211
|
-
*
|
|
212
|
-
* Typically, `clientWidth` for the X axis or `clientHeight` for the Y axis.
|
|
213
|
-
*/
|
|
214
|
-
containerSize: number;
|
|
215
|
-
/**
|
|
216
|
-
* Offset of the target element from the start of the container along the axis.
|
|
217
|
-
*
|
|
218
|
-
* Typically, `offsetLeft` (X axis) or `offsetTop` (Y axis).
|
|
219
|
-
*/
|
|
220
|
-
elementOffset: number;
|
|
221
|
-
/**
|
|
222
|
-
* Size of the target element along the axis.
|
|
223
|
-
*
|
|
224
|
-
* Typically, `clientWidth` (X axis) or `clientHeight` (Y axis).
|
|
225
|
-
*/
|
|
226
|
-
elementSize: number;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Calculates the offset required to center an element within a container along a single axis.
|
|
230
|
-
*
|
|
231
|
-
* The returned value is clamped so that the resulting translation does not
|
|
232
|
-
* exceed the container's scrollable bounds.
|
|
233
|
-
*
|
|
234
|
-
* This function performs pure math only and does not access the DOM.
|
|
235
|
-
*
|
|
236
|
-
* @returns A negative offset value suitable for use in a CSS `translate`
|
|
237
|
-
* transform, or `0` when no overflow exists on the axis.
|
|
238
|
-
*/
|
|
239
|
-
export declare const calculateCenterOffset: ({ overflowSize, containerSize, elementOffset, elementSize, }: CalculateCenterOffsetOptions) => number;
|
|
240
|
-
type Axis = 'x' | 'y' | 'both';
|
|
241
|
-
export interface CenterElementInContainerOptions {
|
|
242
|
-
/**
|
|
243
|
-
* Axis (or axes) along which centering is applied.
|
|
244
|
-
*
|
|
245
|
-
* @default 'both'
|
|
246
|
-
*/
|
|
247
|
-
axis?: Axis;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Translates a container so that a target element is visually centered within its visible bounds.
|
|
251
|
-
*
|
|
252
|
-
* Centering is achieved by applying a CSS `transform: translate(...)` to the
|
|
253
|
-
* container element rather than using native scrolling.
|
|
254
|
-
*
|
|
255
|
-
* ### Behavior
|
|
256
|
-
* - Centering is calculated independently for each enabled axis.
|
|
257
|
-
* - Translation is applied only when the container content overflows on that axis.
|
|
258
|
-
* - When no overflow exists, the container remains untransformed for that axis.
|
|
259
|
-
*
|
|
260
|
-
* ### Notes
|
|
261
|
-
* - This function performs immediate DOM reads and writes.
|
|
262
|
-
* - The resulting transform is clamped to valid scrollable bounds.
|
|
263
|
-
*
|
|
264
|
-
* @param containerElement - The container whose content is translated.
|
|
265
|
-
* @param elementToCenter - The descendant element to align to the container’s center.
|
|
266
|
-
* @param options - Optional configuration controlling which axis or axes are centered.
|
|
267
|
-
*/
|
|
268
|
-
export declare const centerElementInContainer: (containerElement: HTMLElement, elementToCenter: HTMLElement, { axis }?: CenterElementInContainerOptions) => void;
|
|
269
|
-
/**
|
|
270
|
-
* Determines whether the browser environment allows safe read access to
|
|
271
|
-
* `localStorage`. Some platforms (e.g., Safari Private Mode, sandboxed iframes)
|
|
272
|
-
* expose `localStorage` but still throw when accessed.
|
|
273
|
-
*
|
|
274
|
-
* This function **only tests read access**, making it safe even when write
|
|
275
|
-
* operations would fail due to `QuotaExceededError` or storage restrictions.
|
|
276
|
-
*
|
|
277
|
-
* @returns `true` if `localStorage` exists and calling `getItem()` does not
|
|
278
|
-
* throw; otherwise `false`.
|
|
279
|
-
*/
|
|
280
|
-
export declare const isLocalStorageReadable: () => boolean;
|
|
281
|
-
interface LocalStorageCapabilities {
|
|
282
|
-
readable: boolean;
|
|
283
|
-
writable: boolean;
|
|
284
|
-
}
|
|
285
|
-
interface LocalStorageCapabilities {
|
|
286
|
-
readable: boolean;
|
|
287
|
-
writable: boolean;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Determines whether the browser's `localStorage` supports safe read and write operations.
|
|
291
|
-
* This function performs two independent checks:
|
|
292
|
-
*
|
|
293
|
-
* **1. Readability**
|
|
294
|
-
* - Verified by calling `localStorage.getItem()` inside a `try` block.
|
|
295
|
-
* - Fails in environments where storage access throws immediately (e.g., disabled storage,
|
|
296
|
-
* sandboxed iframes, strict privacy modes, SSR).
|
|
297
|
-
*
|
|
298
|
-
* **2. Writeability**
|
|
299
|
-
* - Verified by attempting to `setItem()` and then `removeItem()` using a temporary key.
|
|
300
|
-
* - Can fail due to:
|
|
301
|
-
* - `QuotaExceededError` when storage is full.
|
|
302
|
-
* - Disabled write access (e.g., Safari Private Mode).
|
|
303
|
-
* - Security-restricted contexts (third-party frames, hardened privacy settings)
|
|
304
|
-
*
|
|
305
|
-
* @returns An object describing the detected `localStorage` capabilities.
|
|
306
|
-
*/
|
|
307
|
-
export declare const getLocalStorageCapabilities: () => LocalStorageCapabilities;
|
|
308
|
-
export type Downloadable = Blob | MediaSource | string;
|
|
309
|
-
export interface DownloadFileOptions {
|
|
310
|
-
/**
|
|
311
|
-
* Suggested filename for the downloaded file.
|
|
312
|
-
*
|
|
313
|
-
* When provided, the browser will attempt to save the file using this name.
|
|
314
|
-
* If omitted and the source is a URL string, the browser may infer the name
|
|
315
|
-
* from the URL.
|
|
316
|
-
*/
|
|
317
|
-
fileName?: string;
|
|
318
|
-
/**
|
|
319
|
-
* Target browsing context for the download link.
|
|
320
|
-
*/
|
|
321
|
-
target?: '_self' | '_blank';
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Initiates a file download in a browser environment.
|
|
325
|
-
*
|
|
326
|
-
* This utility supports downloading from:
|
|
327
|
-
* - a URL string
|
|
328
|
-
* - a `Blob`
|
|
329
|
-
* - a `MediaSource`
|
|
330
|
-
*
|
|
331
|
-
* For non-string inputs, an object URL is created temporarily and
|
|
332
|
-
* automatically revoked after the download is triggered.
|
|
333
|
-
*
|
|
334
|
-
* @remarks
|
|
335
|
-
* - This function performs direct DOM manipulation and must be executed in a browser environment.
|
|
336
|
-
* - In non-DOM contexts (e.g. SSR), the function exits without side effects.
|
|
337
|
-
* - Object URLs are revoked asynchronously to avoid Safari-related issues.
|
|
338
|
-
*
|
|
339
|
-
* @param file - The file source to download (URL string or binary object).
|
|
340
|
-
* @param options - Optional configuration controlling filename and link target.
|
|
341
|
-
*/
|
|
342
|
-
export declare const downloadFile: (file: Downloadable, { fileName, target }?: DownloadFileOptions) => void;
|
|
343
|
-
export {};
|