@inertiaui/vanilla 1.4.0 → 1.6.0

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
@@ -70,6 +70,13 @@ export declare function cancelAnimations(element: HTMLElement): void;
70
70
  */
71
71
  export declare function captureAnimationSnapshot(elements: Iterable<HTMLElement | null | undefined>): AnimationSnapshot | null;
72
72
 
73
+ /**
74
+ * Remember an element's inline values for some CSS properties, with their
75
+ * priorities, so temporary changes can be undone without touching other inline
76
+ * styles. Name properties as in CSS, such as `z-index`.
77
+ */
78
+ export declare function captureInlineStyles(element: HTMLElement, properties: readonly string[]): InlineStyleSnapshot;
79
+
73
80
  export declare type CleanupFunction = () => void;
74
81
 
75
82
  /**
@@ -80,16 +87,25 @@ export declare type ColorFormat = 'hex' | 'rgb' | 'hsl';
80
87
  export declare function computePosition(reference: HTMLElement, floating: HTMLElement, options?: PositionOptions_2): PositionResult;
81
88
 
82
89
  /**
83
- * Create a {@link Debouncer} with a fixed delay.
90
+ * Create a {@link Debouncer} with a fixed delay or a getter read on each schedule.
84
91
  *
85
92
  * @param delay - Milliseconds to wait after the latest `schedule()` call.
86
93
  */
87
- export declare function createDebouncer(delay: number): Debouncer;
94
+ export declare function createDebouncer(delay: number | (() => number)): Debouncer;
95
+
96
+ /** Controls modal behavior while the consumer owns rendering and transitions. */
97
+ export declare function createDialogController(options: DialogControllerOptions): DialogController;
88
98
 
89
99
  export declare function createFocusOutDismiss(options: FocusOutDismissOptions): FocusOutDismissController;
90
100
 
91
101
  export declare function createFocusTrap(container: HTMLElement, options?: FocusTrapOptions): CleanupFunction;
92
102
 
103
+ /**
104
+ * Animate layout changes a renderer makes after a snapshot, keeping track of
105
+ * scheduled and running moves so they can be interrupted.
106
+ */
107
+ export declare function createLayoutAnimation(options?: LayoutAnimationOptions): LayoutAnimationController;
108
+
93
109
  export declare function createMenuNavigation(container: HTMLElement, options?: MenuNavigationOptions): CleanupFunction;
94
110
 
95
111
  export declare function createNativePopoverDisclosure(options: NativePopoverDisclosureOptions): NativePopoverDisclosureController;
@@ -105,6 +121,14 @@ export declare function createPopoverController(options: PopoverControllerOption
105
121
  */
106
122
  export declare function createReorderableList<T>(options: ReorderableListOptions<T>): ReorderableListController<T>;
107
123
 
124
+ /** Coordinates hover and focus intent without moving focus into the tooltip. */
125
+ export declare function createTooltipController(options: TooltipControllerOptions): TooltipController;
126
+
127
+ export declare interface CssVariableInheritanceOptions {
128
+ filter: (name: string) => boolean;
129
+ mediaQueries?: readonly string[];
130
+ }
131
+
108
132
  export declare type DarkModeStrategy = 'auto' | 'class' | 'selector' | 'media' | (() => boolean);
109
133
 
110
134
  /**
@@ -120,6 +144,8 @@ export declare function debounce<T extends (...args: unknown[]) => void>(fn: T):
120
144
  * call and queues a fresh one `delay` milliseconds out.
121
145
  */
122
146
  export declare interface Debouncer {
147
+ /** Whether a scheduled callback is waiting to run. */
148
+ readonly pending: boolean;
123
149
  /** Queue `fn` to run after `delay` ms, cancelling any pending call. */
124
150
  schedule(fn: () => void): void;
125
151
  /** Cancel a pending call, if any. */
@@ -133,6 +159,30 @@ export declare interface Debouncer {
133
159
  */
134
160
  export declare function detectFramerate(): Promise<number>;
135
161
 
162
+ export declare interface DialogController {
163
+ readonly native: boolean;
164
+ readonly isOpen: boolean;
165
+ open: () => void;
166
+ close: () => Promise<void>;
167
+ mount: () => void;
168
+ cleanup: CleanupFunction;
169
+ }
170
+
171
+ export declare interface DialogControllerOptions {
172
+ dialog: () => HTMLElement | null;
173
+ panel: () => HTMLElement | null;
174
+ onOpenChange?: (open: boolean) => void;
175
+ onCancel?: () => void;
176
+ onMount?: (context: DialogMountContext) => CleanupFunction | void;
177
+ transition?: (visible: boolean) => void | Promise<unknown>;
178
+ }
179
+
180
+ export declare interface DialogMountContext {
181
+ dialog: HTMLElement;
182
+ panel: HTMLElement;
183
+ native: boolean;
184
+ }
185
+
136
186
  export declare type EasingName = keyof typeof easings;
137
187
 
138
188
  /**
@@ -156,7 +206,7 @@ export declare function except<T extends Record<string, unknown>>(target: T, key
156
206
 
157
207
  export declare function except(target: string[], keys: string[], ignoreCase?: boolean): string[];
158
208
 
159
- export declare function focusFirstEnabledElement(elements: Array<HTMLElement | null | undefined>): boolean;
209
+ export declare function focusFirstEnabledElement(elements: Array<HTMLElement | null | undefined>, options?: FocusOptions): boolean;
160
210
 
161
211
  export declare interface FocusOutDismissController {
162
212
  markOpen: () => void;
@@ -207,6 +257,24 @@ export declare interface FormatColorOptions {
207
257
 
208
258
  export declare function generateId(prefix?: string): string;
209
259
 
260
+ /**
261
+ * Return how far each item moves along the axis when the items are laid out in
262
+ * `order`, a permutation of their indices. The offsets describe the movement
263
+ * between the items packed in their current order and packed in `order`, so items
264
+ * of different sizes line up and an unchanged order returns zero offsets. Each gap
265
+ * between neighboring slots stays in place, or is `gap` in both layouts when
266
+ * given. An order that is not a permutation of the items leaves every item where
267
+ * it is.
268
+ */
269
+ export declare function getReorderOffsets(rects: readonly ReorderBounds[], order: readonly number[], options?: ReorderOffsetsOptions): number[];
270
+
271
+ /**
272
+ * Ancestors of `element` that can scroll, nearest first, followed by its window.
273
+ * Pass an axis to keep only the ancestors that scroll along it. Shadow roots are
274
+ * crossed through their hosts.
275
+ */
276
+ export declare function getScrollableAncestors(element: Element | null, axis?: AutoScrollAxis): AutoScrollContainer[];
277
+
210
278
  /**
211
279
  * Convert a hex color string to HSL values.
212
280
  * Accepts with or without leading '#'.
@@ -232,6 +300,14 @@ export declare interface HslColor {
232
300
  */
233
301
  export declare function hslToHex(h: number, s: number, l: number): string;
234
302
 
303
+ /** Copy selected computed custom properties and restore owned inline values on cleanup. */
304
+ export declare function inheritCssVariables(source: HTMLElement, target: HTMLElement, options: CssVariableInheritanceOptions): () => void;
305
+
306
+ export declare interface InlineStyleSnapshot {
307
+ /** Put back the captured inline values and priorities, of every captured property or only of the given ones. */
308
+ restore: (properties?: readonly string[]) => void;
309
+ }
310
+
235
311
  /**
236
312
  * Check whether the document is currently in RTL direction.
237
313
  */
@@ -241,6 +317,34 @@ export declare function isStandardDomEvent(eventName: string): boolean;
241
317
 
242
318
  export declare function kebabCase(string: string): string;
243
319
 
320
+ export declare interface LayoutAnimationCallbacks {
321
+ /** Called with the started animations, in the same task that starts them. */
322
+ onStart?: (animations: Animation[]) => void;
323
+ /**
324
+ * Called once every animation of the run has finished or been canceled, by a
325
+ * later run taking over its elements or by `cancel()`. Use it to undo styles
326
+ * the move needed. Still runs, shortly after `onStart`, when nothing animates.
327
+ */
328
+ onSettle?: () => void;
329
+ }
330
+
331
+ export declare interface LayoutAnimationController {
332
+ /** Animate the elements from `snapshot` to their layout once the renderer has updated. */
333
+ animate: (snapshot: AnimationSnapshot | null, getElements: () => Iterable<HTMLElement | null | undefined>, callbacks?: LayoutAnimationCallbacks) => void;
334
+ /** Drop runs that have not started and cancel running animations, which still settle. */
335
+ cancel: () => void;
336
+ /** Stop everything without calling back, and ignore later runs. Idempotent. */
337
+ cleanup: CleanupFunction;
338
+ }
339
+
340
+ export declare interface LayoutAnimationOptions extends AnimateFromSnapshotOptions {
341
+ /**
342
+ * Run the callback once the renderer has applied the new layout, and return a
343
+ * function that cancels it. Defaults to the next animation frame.
344
+ */
345
+ schedule?: (run: () => void) => (() => void) | void;
346
+ }
347
+
244
348
  export declare interface ListboxNavigationOptions<T> {
245
349
  items: readonly T[];
246
350
  currentIndex: number;
@@ -443,6 +547,8 @@ declare interface PositionOptions_2 {
443
547
  * applied via its `anchor` prop, so long menus scroll instead of overflowing.
444
548
  */
445
549
  autoSize?: boolean;
550
+ /** Use CSS anchors when supported. Set false to use numeric positioning. */
551
+ anchorPositioning?: boolean;
446
552
  }
447
553
  export { PositionOptions_2 as PositionOptions }
448
554
 
@@ -492,7 +598,18 @@ export declare interface ReorderableListController<T> {
492
598
  moveItem: (index: number, direction: ReorderDirection) => ReorderMove<T> | null;
493
599
  /** Begin a pointer reorder from a registered handle event. */
494
600
  pointerDown: (index: number, event: PointerEvent) => void;
495
- /** Cancel active pointer work and remove global listeners. Idempotent. */
601
+ /**
602
+ * Pointer positions of the active drag, or null while idle and before a press
603
+ * starts dragging. The object lives for the whole gesture and its `position`
604
+ * is replaced as the pointer moves, so copy the values you need to keep.
605
+ */
606
+ getPointer: () => ReorderPointer | null;
607
+ /**
608
+ * End a pending press or active pointer drag without committing it. An active
609
+ * drag notifies `onChange` with the idle state. The controller stays usable.
610
+ */
611
+ cancel: () => void;
612
+ /** Cancel active pointer work and remove global listeners without notifying `onChange`. Idempotent. */
496
613
  cleanup: CleanupFunction;
497
614
  }
498
615
 
@@ -507,6 +624,23 @@ export declare interface ReorderableListOptions<T> {
507
624
  getBounds?: () => ReorderBounds | null;
508
625
  /** Optional edge auto-scroll while pointer-dragging. Disabled by default. */
509
626
  autoScroll?: boolean | AutoScrollerOptions;
627
+ /**
628
+ * Pointer travel in CSS pixels before a press starts dragging. Until then the
629
+ * press keeps its native click, focus, and scrolling. Defaults to 0, which
630
+ * starts dragging on press.
631
+ */
632
+ activationDistance?: number;
633
+ /** Ignore the click that follows a pointer drag, so releasing over a control does not activate it. Defaults to false. */
634
+ suppressClickAfterDrag?: boolean;
635
+ /**
636
+ * Point that picks the drop slot while pointer-dragging, given the pointer and
637
+ * the dragged item's box as measured when the drag started. Returning the
638
+ * item's leading edge lets items of different sizes swap once the dragged
639
+ * item covers half of a neighbor. The point is clamped to the items' extent,
640
+ * and returning null uses the pointer, which is also the default. Whether a
641
+ * release drops or cancels always follows the pointer itself.
642
+ */
643
+ getCollisionPoint?: (pointer: ReorderPointer, item: ReorderBounds) => ReorderPoint | null;
510
644
  /** Called whenever pointer drag state changes. */
511
645
  onChange?: (state: ReorderableListState) => void;
512
646
  /** Called immediately before items are written or `onReorder` fires. */
@@ -546,6 +680,32 @@ export declare type ReorderMove<T> = {
546
680
  source: ReorderSource;
547
681
  };
548
682
 
683
+ export declare interface ReorderOffsetsOptions {
684
+ /** Axis the items are laid out along. Defaults to `'y'`. */
685
+ axis?: 'x' | 'y';
686
+ /** The items run toward the start of the axis, as in a right-to-left row. Defaults to false. */
687
+ reverse?: boolean;
688
+ /**
689
+ * Space between neighboring items, used for both orders. Defaults to the gap
690
+ * each slot has now, which suits lists whose items are measured where they lie
691
+ * in the flow. Pass 0 for items that touch, such as table cells, when some boxes
692
+ * are measured elsewhere, for instance stuck in place by sticky positioning.
693
+ */
694
+ gap?: number;
695
+ }
696
+
697
+ export declare type ReorderPoint = {
698
+ clientX: number;
699
+ clientY: number;
700
+ };
701
+
702
+ export declare type ReorderPointer = {
703
+ /** Where the press started. */
704
+ readonly origin: ReorderPoint;
705
+ /** The latest pointer position. */
706
+ readonly position: ReorderPoint;
707
+ };
708
+
549
709
  export declare type ReorderPreviewItem<T> = {
550
710
  item: T;
551
711
  /** Index in the source item array. */
@@ -581,6 +741,29 @@ export declare function supportsTopLayerAnchorPositioning(): boolean;
581
741
 
582
742
  export declare function supportsWebAnimations(): boolean;
583
743
 
744
+ export declare interface TooltipController {
745
+ readonly native: boolean;
746
+ readonly isOpen: boolean;
747
+ mount: () => void;
748
+ cleanup: CleanupFunction;
749
+ hide: () => Promise<void>;
750
+ onMouseEnter: () => void;
751
+ onMouseLeave: () => void;
752
+ onFocusIn: () => void;
753
+ onFocusOut: (event: FocusEvent) => void;
754
+ }
755
+
756
+ export declare interface TooltipControllerOptions {
757
+ reference: () => HTMLElement | null;
758
+ tooltip: () => HTMLElement | null;
759
+ enabled?: () => boolean;
760
+ delay?: number | (() => number);
761
+ position?: PositionOptions_2;
762
+ onOpenChange?: (open: boolean) => void;
763
+ onMount?: (context: PopoverMountContext) => CleanupFunction | void;
764
+ transition?: (visible: boolean) => void | Promise<unknown>;
765
+ }
766
+
584
767
  export declare interface TopLayerPopoverPositionOptions {
585
768
  placement?: Placement;
586
769
  offset?: number;