@inertiaui/vanilla 1.1.0 → 1.2.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/dist/index.d.ts CHANGED
@@ -19,8 +19,27 @@ export declare interface AnimateOptions {
19
19
  fill?: FillMode;
20
20
  }
21
21
 
22
+ export declare type AutoScrollAxis = 'x' | 'y' | 'both';
23
+
24
+ export declare type AutoScrollContainer = Element | Window;
25
+
26
+ export declare interface AutoScrollerOptions {
27
+ /** Edge size in CSS pixels that starts scrolling. Defaults to 48. */
28
+ edgeThreshold?: number;
29
+ /** Maximum scroll speed in CSS pixels per second. Defaults to 720. */
30
+ maxSpeed?: number;
31
+ /** Limit scrolling to one axis. Defaults to both axes. */
32
+ axis?: AutoScrollAxis;
33
+ /** Override scroll containers. Defaults to scrollable ancestors plus window. */
34
+ getScrollContainers?: (element: Element | null) => AutoScrollContainer[];
35
+ /** Called once per animation frame after one or more containers scrolled. */
36
+ onScroll?: () => void;
37
+ }
38
+
22
39
  export declare function autoUpdate(reference: HTMLElement, floating: HTMLElement, update: () => void): CleanupFunction;
23
40
 
41
+ export declare function autoUpdateTopLayerPopover(reference: HTMLElement, floating: HTMLElement, update: () => void): CleanupFunction;
42
+
24
43
  /**
25
44
  * Port of Laravel's `blank` function.
26
45
  * Returns true if the value is "empty" — null, undefined, empty string, empty array/object, etc.
@@ -34,12 +53,36 @@ export declare function cancelAnimations(element: HTMLElement): void;
34
53
 
35
54
  export declare type CleanupFunction = () => void;
36
55
 
56
+ /**
57
+ * Supported output formats for {@link formatColor}.
58
+ */
59
+ export declare type ColorFormat = 'hex' | 'rgb' | 'hsl';
60
+
37
61
  export declare function computePosition(reference: HTMLElement, floating: HTMLElement, options?: PositionOptions_2): PositionResult;
38
62
 
63
+ /**
64
+ * Create a {@link Debouncer} with a fixed delay.
65
+ *
66
+ * @param delay - Milliseconds to wait after the latest `schedule()` call.
67
+ */
68
+ export declare function createDebouncer(delay: number): Debouncer;
69
+
70
+ export declare function createFocusOutDismiss(options: FocusOutDismissOptions): FocusOutDismissController;
71
+
39
72
  export declare function createFocusTrap(container: HTMLElement, options?: FocusTrapOptions): CleanupFunction;
40
73
 
41
74
  export declare function createMenuNavigation(container: HTMLElement, options?: MenuNavigationOptions): CleanupFunction;
42
75
 
76
+ export declare function createNativePopoverDisclosure(options: NativePopoverDisclosureOptions): NativePopoverDisclosureController;
77
+
78
+ /**
79
+ * Framework-neutral list reorder controller. It combines item registration,
80
+ * live pointer preview ordering, keyboard moves, pointer commits, bounds, and
81
+ * cleanup while leaving rendering, announcements, and animation policy to the
82
+ * consuming package.
83
+ */
84
+ export declare function createReorderableList<T>(options: ReorderableListOptions<T>): ReorderableListController<T>;
85
+
43
86
  export declare type DarkModeStrategy = 'auto' | 'class' | 'selector' | 'media' | (() => boolean);
44
87
 
45
88
  /**
@@ -50,6 +93,17 @@ export declare type DarkModeStrategy = 'auto' | 'class' | 'selector' | 'media' |
50
93
  */
51
94
  export declare function debounce<T extends (...args: unknown[]) => void>(fn: T): (...args: Parameters<T>) => void;
52
95
 
96
+ /**
97
+ * A timeout-based debounced scheduler. Each `schedule()` cancels any pending
98
+ * call and queues a fresh one `delay` milliseconds out.
99
+ */
100
+ export declare interface Debouncer {
101
+ /** Queue `fn` to run after `delay` ms, cancelling any pending call. */
102
+ schedule(fn: () => void): void;
103
+ /** Cancel a pending call, if any. */
104
+ cancel(): void;
105
+ }
106
+
53
107
  /**
54
108
  * Detect the browser's current framerate.
55
109
  * Returns a Promise that resolves with the detected FPS (capped to 30–240 range).
@@ -69,6 +123,8 @@ export declare const easings: {
69
123
  readonly inOut: "cubic-bezier(0.4, 0, 0.2, 1)";
70
124
  };
71
125
 
126
+ declare type ElementGetter<T extends HTMLElement = HTMLElement> = () => T | null;
127
+
72
128
  export declare interface EscapeKeyOptions {
73
129
  preventDefault?: boolean;
74
130
  stopPropagation?: boolean;
@@ -78,12 +134,55 @@ export declare function except<T extends Record<string, unknown>>(target: T, key
78
134
 
79
135
  export declare function except(target: string[], keys: string[], ignoreCase?: boolean): string[];
80
136
 
137
+ export declare function focusFirstEnabledElement(elements: Array<HTMLElement | null | undefined>): boolean;
138
+
139
+ export declare interface FocusOutDismissController {
140
+ markOpen: () => void;
141
+ cancel: () => void;
142
+ schedule: (event: FocusEvent) => void;
143
+ cleanup: CleanupFunction;
144
+ }
145
+
146
+ export declare interface FocusOutDismissOptions {
147
+ container: () => HTMLElement | null;
148
+ onDismiss: () => void;
149
+ delay?: number;
150
+ shouldIgnore?: () => boolean;
151
+ }
152
+
81
153
  export declare interface FocusTrapOptions {
82
154
  initialFocus?: boolean;
83
155
  initialFocusElement?: HTMLElement | null;
84
156
  returnFocus?: boolean;
85
157
  }
86
158
 
159
+ /**
160
+ * Format an alpha value as a compact decimal string (e.g. `0.5`, `1`),
161
+ * dropping trailing zeros.
162
+ */
163
+ export declare function formatAlpha(number: number): string;
164
+
165
+ /**
166
+ * Format a {@link ParsedColor} as a `hex`, `rgb`, or `hsl` string.
167
+ *
168
+ * By default the alpha channel is only included when the color is partially
169
+ * transparent (`alpha < 1`); override with {@link FormatColorOptions.includeAlpha}.
170
+ * Returned values are stable and normalized (hex is lowercase); callers may
171
+ * uppercase for display.
172
+ */
173
+ export declare function formatColor(color: ParsedColor, format?: ColorFormat, options?: FormatColorOptions): string;
174
+
175
+ /**
176
+ * Options for {@link formatColor}.
177
+ */
178
+ export declare interface FormatColorOptions {
179
+ /**
180
+ * Whether to include the alpha channel in the output.
181
+ * Defaults to `true` when the color's alpha is below 1, `false` otherwise.
182
+ */
183
+ includeAlpha?: boolean;
184
+ }
185
+
87
186
  export declare function generateId(prefix?: string): string;
88
187
 
89
188
  /**
@@ -92,6 +191,12 @@ export declare function generateId(prefix?: string): string;
92
191
  */
93
192
  export declare function hexToHsl(hex: string): HslColor;
94
193
 
194
+ /**
195
+ * Convert a hex color string to RGB channels.
196
+ * Accepts any input understood by {@link parseHexColor}; falls back to black on invalid input.
197
+ */
198
+ export declare function hexToRgb(hex: string): RgbColor;
199
+
95
200
  export declare interface HslColor {
96
201
  h: number;
97
202
  s: number;
@@ -114,10 +219,25 @@ export declare function isStandardDomEvent(eventName: string): boolean;
114
219
 
115
220
  export declare function kebabCase(string: string): string;
116
221
 
222
+ export declare interface ListboxNavigationOptions<T> {
223
+ items: readonly T[];
224
+ currentIndex: number;
225
+ key: string;
226
+ isItemDisabled?: (item: T, index: number) => boolean;
227
+ fallbackIndex?: number;
228
+ }
229
+
230
+ export declare interface ListboxNavigationResult {
231
+ handled: boolean;
232
+ index: number;
233
+ }
234
+
117
235
  export declare function lockScroll(): CleanupFunction;
118
236
 
119
237
  export declare function markAriaHidden(elementOrSelector: Element | string): CleanupFunction;
120
238
 
239
+ export declare function markInert(elementOrSelector: HTMLElement | string): CleanupFunction;
240
+
121
241
  export declare interface MenuNavigationOptions {
122
242
  itemSelector?: string;
123
243
  orientation?: 'vertical' | 'horizontal';
@@ -126,6 +246,57 @@ export declare interface MenuNavigationOptions {
126
246
  onActivate?: (item: HTMLElement) => void;
127
247
  }
128
248
 
249
+ export declare interface NativePopoverCloseOptions {
250
+ onClose?: () => void;
251
+ hide?: boolean;
252
+ }
253
+
254
+ export declare interface NativePopoverDisclosureController {
255
+ readonly isOpen: boolean;
256
+ openPopover: (options?: NativePopoverOpenOptions) => void;
257
+ closePopover: (options?: NativePopoverCloseOptions) => boolean;
258
+ togglePopover: (open: () => void, close: () => void) => void;
259
+ showPopover: () => void;
260
+ hidePopover: () => void;
261
+ handlePopoverToggle: (event: Event, options?: NativePopoverToggleOptions) => boolean;
262
+ handleFocusOut: (event: FocusEvent) => void;
263
+ updatePosition: () => void;
264
+ startAutoUpdate: () => void;
265
+ cleanupPopover: CleanupFunction;
266
+ }
267
+
268
+ export declare interface NativePopoverDisclosureOptions {
269
+ reference: ElementGetter;
270
+ popover: ElementGetter;
271
+ position: TopLayerPopoverPositionOptions;
272
+ enabled?: () => boolean;
273
+ focusOut?: FocusOutDismissOptions;
274
+ onOpenChange?: (isOpen: boolean) => void;
275
+ }
276
+
277
+ export declare interface NativePopoverOpenOptions {
278
+ onBeforeOpen?: () => void;
279
+ }
280
+
281
+ export declare interface NativePopoverToggleOptions {
282
+ onClose?: () => void;
283
+ }
284
+
285
+ /**
286
+ * Clamp an alpha value to the range 0-1. Non-finite input falls back to 1.
287
+ */
288
+ export declare function normalizeAlpha(number: number): number;
289
+
290
+ /**
291
+ * Normalize a hue to an integer in the range 0-359, wrapping negatives and overflow.
292
+ */
293
+ export declare function normalizeHue(number: number): number;
294
+
295
+ /**
296
+ * Clamp and round a percentage value to an integer in the range 0-100.
297
+ */
298
+ export declare function normalizePercent(number: number): number;
299
+
129
300
  export declare function onceChildrenRendered(element: Element, callback: () => void): void;
130
301
 
131
302
  export declare function onClickOutside(elements: HTMLElement | HTMLElement[], callback: (event: PointerEvent) => void): CleanupFunction;
@@ -142,6 +313,71 @@ export declare function only(target: string[], keys: string[], ignoreCase?: bool
142
313
  */
143
314
  export declare function onRtlChange(callback: (rtl: boolean) => void): CleanupFunction;
144
315
 
316
+ /**
317
+ * Parse an alpha channel from a raw string as found in rgba()/hsla() notation.
318
+ *
319
+ * - `undefined` or empty means "no alpha specified" and returns 1
320
+ * - Percentages (`50%`) must be within 0-100
321
+ * - Decimals must be within 0-1
322
+ * - Returns `null` for out-of-range or non-numeric input
323
+ */
324
+ export declare function parseAlphaChannel(rawAlpha: string | undefined): number | null;
325
+
326
+ /**
327
+ * Parse any supported color string (hex, rgb/rgba, hsl/hsla) into a {@link ParsedColor}.
328
+ * Returns `null` for empty or unrecognized input.
329
+ */
330
+ export declare function parseColorString(input: string | null | undefined): ParsedColor | null;
331
+
332
+ /**
333
+ * A fully normalized color model.
334
+ *
335
+ * - `hex` is lowercase, 6-digit, with a leading '#'
336
+ * - `h` is 0-359, `s`/`l` are 0-100
337
+ * - `alpha` is 0-1
338
+ */
339
+ export declare interface ParsedColor {
340
+ hex: string;
341
+ h: number;
342
+ s: number;
343
+ l: number;
344
+ alpha: number;
345
+ }
346
+
347
+ /**
348
+ * Build a {@link ParsedColor} from a 6-digit hex string and optional alpha (0-1).
349
+ */
350
+ export declare function parsedFromHex(hex: string, alphaValue?: number): ParsedColor;
351
+
352
+ /**
353
+ * Parse a hex color string into a {@link ParsedColor}.
354
+ *
355
+ * Accepts 3, 4, 6, or 8 digit hex, with or without a leading '#'.
356
+ * 4/8 digit forms carry an alpha channel. Returns `null` on invalid input.
357
+ */
358
+ export declare function parseHexColor(input: string): ParsedColor | null;
359
+
360
+ /**
361
+ * Parse an `hsl()`/`hsla()` color string into a {@link ParsedColor}.
362
+ * Saturation and lightness must be percentages within 0-100. Returns `null` on invalid input.
363
+ */
364
+ export declare function parseHslColor(input: string): ParsedColor | null;
365
+
366
+ /**
367
+ * Parse a single RGB channel from a raw string.
368
+ *
369
+ * - Percentages (`50%`) map 0-100 onto 0-255
370
+ * - Numbers must be within 0-255
371
+ * - Returns `null` for out-of-range or non-numeric input
372
+ */
373
+ export declare function parseRgbChannel(rawChannel: string): number | null;
374
+
375
+ /**
376
+ * Parse an `rgb()`/`rgba()` color string into a {@link ParsedColor}.
377
+ * Channels may be numeric (0-255) or percentages. Returns `null` on invalid input.
378
+ */
379
+ export declare function parseRgbColor(input: string): ParsedColor | null;
380
+
145
381
  export declare type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end';
146
382
 
147
383
  declare interface PositionOptions_2 {
@@ -163,6 +399,8 @@ export declare interface PositionResult {
163
399
  placement: Placement;
164
400
  }
165
401
 
402
+ export declare function positionTopLayerPopover(reference: HTMLElement, floating: HTMLElement, options?: TopLayerPopoverPositionOptions): PositionResult;
403
+
166
404
  /**
167
405
  * Detect whether the user prefers dark mode.
168
406
  *
@@ -178,8 +416,121 @@ export declare function rejectNullValues<T>(target: T[]): Exclude<T, null>[];
178
416
 
179
417
  export declare function rejectNullValues<T extends Record<string, unknown>>(target: T): Partial<T>;
180
418
 
419
+ /**
420
+ * Attribute a caller places on a drag handle element so the pointer controller
421
+ * can verify that a pointer interaction started on an actual reorder handle.
422
+ */
423
+ export declare const REORDERABLE_LIST_HANDLE_ATTRIBUTE = "data-reorderable-list-handle";
424
+
425
+ export declare interface ReorderableListController<T> {
426
+ /** Register the outer list element used for default bounds and auto-scroll ancestry. */
427
+ setListElement: (element: HTMLElement | null | undefined) => void;
428
+ /** Register or unregister an item element by source index. */
429
+ setItemElement: (index: number, element: HTMLElement | null | undefined) => void;
430
+ /** Current registered item elements ordered by index. */
431
+ getItemElements: () => HTMLElement[];
432
+ /** Source indices in the order they should render for the live pointer preview. */
433
+ getPreviewOrder: () => number[];
434
+ /** Current items plus source and visual indices for the live pointer preview. */
435
+ getPreviewItems: () => ReorderPreviewItem<T>[];
436
+ /** Commit an up/down keyboard reorder. */
437
+ moveItem: (index: number, direction: ReorderDirection) => ReorderMove<T> | null;
438
+ /** Begin a pointer reorder from a registered handle event. */
439
+ pointerDown: (index: number, event: PointerEvent) => void;
440
+ /** Cancel active pointer work and remove global listeners. Idempotent. */
441
+ cleanup: CleanupFunction;
442
+ }
443
+
444
+ export declare interface ReorderableListOptions<T> {
445
+ /** Return the current ordered items. */
446
+ getItems: () => readonly T[];
447
+ /** Optional writer used by `moveItem` and pointer commits. */
448
+ setItems?: (items: T[]) => void;
449
+ /** Optional guard; reordering is skipped when it returns false. Defaults to true. */
450
+ canReorder?: () => boolean;
451
+ /** Optional outer collision bounds. Defaults to the registered list element rect. */
452
+ getBounds?: () => ReorderBounds | null;
453
+ /** Optional edge auto-scroll while pointer-dragging. Disabled by default. */
454
+ autoScroll?: boolean | AutoScrollerOptions;
455
+ /** Called whenever pointer drag state changes. */
456
+ onChange?: (state: ReorderableListState) => void;
457
+ /** Called immediately before items are written or `onReorder` fires. */
458
+ onBeforeReorder?: (move: ReorderMove<T>, context: ReorderCommitContext) => void;
459
+ /** Called after a valid keyboard or pointer reorder. */
460
+ onReorder?: (move: ReorderMove<T>, context: ReorderCommitContext) => void;
461
+ }
462
+
463
+ export declare type ReorderableListState = {
464
+ draggedIndex: number | null;
465
+ insertionIndex: number | null;
466
+ targetIndex: number | null;
467
+ };
468
+
469
+ export declare type ReorderBounds = {
470
+ left: number;
471
+ top: number;
472
+ right: number;
473
+ bottom: number;
474
+ };
475
+
476
+ export declare type ReorderCommitContext = {
477
+ /**
478
+ * True when a pointer reorder already animated to the committed target
479
+ * while dragging. Consumers can use this to avoid replaying the same
480
+ * reorder animation on release.
481
+ */
482
+ alreadyPreviewed: boolean;
483
+ };
484
+
485
+ export declare type ReorderDirection = 'up' | 'down';
486
+
487
+ export declare type ReorderMove<T> = {
488
+ item: T;
489
+ fromIndex: number;
490
+ toIndex: number;
491
+ source: ReorderSource;
492
+ };
493
+
494
+ export declare type ReorderPreviewItem<T> = {
495
+ item: T;
496
+ /** Index in the source item array. */
497
+ index: number;
498
+ /** Index where the item is currently previewed visually. */
499
+ visualIndex: number;
500
+ };
501
+
502
+ export declare type ReorderSource = 'keyboard' | 'pointer';
503
+
504
+ export declare function resolveListboxNavigation<T>(options: ListboxNavigationOptions<T>): ListboxNavigationResult;
505
+
506
+ /**
507
+ * An RGB color with 0-255 integer channels.
508
+ */
509
+ export declare interface RgbColor {
510
+ r: number;
511
+ g: number;
512
+ b: number;
513
+ }
514
+
515
+ /**
516
+ * Convert RGB channels to a lowercase 6-digit hex string with a leading '#'.
517
+ * Channels are clamped to 0-255.
518
+ */
519
+ export declare function rgbToHex(r: number, g: number, b: number): string;
520
+
181
521
  export declare function sameUrlPath(url1: string | URL | undefined | null, url2: string | URL | undefined | null): boolean;
182
522
 
183
523
  export declare function supportsAnchorPositioning(): boolean;
184
524
 
525
+ export declare function supportsTopLayerAnchorPositioning(): boolean;
526
+
527
+ export declare interface TopLayerPopoverPositionOptions {
528
+ placement?: Placement;
529
+ offset?: number;
530
+ flip?: boolean;
531
+ matchReferenceWidth?: boolean;
532
+ viewportMargin?: number;
533
+ anchorPositioning?: boolean;
534
+ }
535
+
185
536
  export { }