@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/README.md +293 -34
- package/dist/index.d.ts +187 -4
- package/dist/index.js +1235 -518
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,10 @@ npm install @inertiaui/vanilla
|
|
|
26
26
|
- [Reorder](#reorder)
|
|
27
27
|
- [Positioning](#positioning)
|
|
28
28
|
- [Native Popovers](#native-popovers)
|
|
29
|
+
- [Tooltip Controllers](#tooltip-controllers)
|
|
30
|
+
- [Dialog Controllers](#dialog-controllers)
|
|
31
|
+
- [Inline styles](#inline-styles)
|
|
32
|
+
- [CSS Variable Inheritance](#css-variable-inheritance)
|
|
29
33
|
- [Accessibility](#accessibility)
|
|
30
34
|
- [Animation](#animation)
|
|
31
35
|
- [Dark Mode Detection](#dark-mode-detection)
|
|
@@ -151,7 +155,7 @@ Elements with `aria-hidden="true"` are excluded. (Elements with `disabled` are a
|
|
|
151
155
|
|
|
152
156
|
### focusFirstEnabledElement
|
|
153
157
|
|
|
154
|
-
Focuses the first non-disabled element in a list of candidates. Nullish values are ignored, and the function returns whether anything was focused.
|
|
158
|
+
Focuses the first non-disabled element in a list of candidates. Nullish values are ignored, and the function returns whether anything was focused. An optional second argument accepts native `FocusOptions`, including `{ preventScroll: true }`.
|
|
155
159
|
|
|
156
160
|
```typescript
|
|
157
161
|
import { focusFirstEnabledElement } from '@inertiaui/vanilla'
|
|
@@ -405,71 +409,199 @@ focusOut.cleanup()
|
|
|
405
409
|
|
|
406
410
|
## Reorder
|
|
407
411
|
|
|
408
|
-
Framework-neutral helpers for keyboard and pointer reordering.
|
|
409
|
-
|
|
410
412
|
### createReorderableList
|
|
411
413
|
|
|
412
|
-
|
|
414
|
+
`createReorderableList` manages item registration, preview order, keyboard moves, pointer drags, and cleanup. Bounds and auto-scroll are optional. Your application controls rendering, announcements, focus, and animation.
|
|
413
415
|
|
|
414
416
|
```typescript
|
|
415
417
|
import {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
418
|
+
animateFromSnapshot,
|
|
419
|
+
captureAnimationSnapshot,
|
|
420
|
+
createReorderableList,
|
|
421
|
+
REORDERABLE_LIST_HANDLE_ATTRIBUTE,
|
|
422
|
+
type AnimationSnapshot,
|
|
421
423
|
} from '@inertiaui/vanilla'
|
|
422
424
|
|
|
423
425
|
let items = ['Apple', 'Banana', 'Cherry']
|
|
424
426
|
let animationSnapshot: AnimationSnapshot | null = null
|
|
425
427
|
|
|
426
428
|
const controller = createReorderableList({
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
429
|
+
getItems: () => items,
|
|
430
|
+
setItems: (nextItems) => {
|
|
431
|
+
items = nextItems
|
|
432
|
+
render()
|
|
433
|
+
},
|
|
434
|
+
getBounds: () => listElement.getBoundingClientRect(),
|
|
435
|
+
autoScroll: true,
|
|
436
|
+
onChange: () => render(),
|
|
437
|
+
onBeforeReorder: (move, context) => {
|
|
438
|
+
if (!context.alreadyPreviewed) {
|
|
439
|
+
animationSnapshot = captureAnimationSnapshot(itemElements)
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
onReorder: (move) => {
|
|
443
|
+
animateFromSnapshot(animationSnapshot, itemElements)
|
|
444
|
+
animationSnapshot = null
|
|
445
|
+
announce(`Moved ${move.item}`)
|
|
446
|
+
},
|
|
445
447
|
})
|
|
446
448
|
|
|
447
449
|
controller.setListElement(listElement)
|
|
448
450
|
|
|
449
451
|
items.forEach((_, index) => {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
452
|
+
controller.setItemElement(index, itemElements[index])
|
|
453
|
+
handles[index].setAttribute(REORDERABLE_LIST_HANDLE_ATTRIBUTE, 'true')
|
|
454
|
+
handles[index].addEventListener('pointerdown', (event) => controller.pointerDown(index, event))
|
|
453
455
|
})
|
|
454
456
|
|
|
455
457
|
moveUpButton.addEventListener('click', () => controller.moveItem(index, 'up'))
|
|
456
458
|
```
|
|
457
459
|
|
|
458
|
-
|
|
460
|
+
`getPreviewOrder()` and `getPreviewItems()` return the preview order during a pointer drag. The reorder callbacks receive `context.alreadyPreviewed`, which indicates whether the controller already reported the committed target through `onChange`.
|
|
461
|
+
|
|
462
|
+
#### Pointer activation
|
|
463
|
+
|
|
464
|
+
By default, a press on a handle starts a drag immediately. The controller prevents the browser's default action, attempts pointer capture, and calls `onChange`.
|
|
465
|
+
|
|
466
|
+
`activationDistance` delays the drag until the pointer travels the specified distance in CSS pixels. Below that distance, the press retains native click, focus, and scroll behavior. A release before activation does not call `onChange`.
|
|
467
|
+
|
|
468
|
+
`suppressClickAfterDrag: true` blocks the next click after a drag ends. A new pointer press or key press clears the suppression before that interaction produces a click.
|
|
469
|
+
|
|
470
|
+
The following example combines delayed activation with click suppression:
|
|
471
|
+
|
|
472
|
+
```typescript
|
|
473
|
+
const controller = createReorderableList({
|
|
474
|
+
getItems: () => columns,
|
|
475
|
+
setItems: (nextColumns) => (columns = nextColumns),
|
|
476
|
+
activationDistance: 4,
|
|
477
|
+
suppressClickAfterDrag: true,
|
|
478
|
+
onChange: (state) => {
|
|
479
|
+
const pointer = controller.getPointer()
|
|
480
|
+
|
|
481
|
+
if (state.draggedIndex !== null && pointer) {
|
|
482
|
+
// Keep the dragged item under the pointer.
|
|
483
|
+
translate(state.draggedIndex, pointer.position.clientX - pointer.origin.clientX)
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
window.addEventListener('keydown', (event) => {
|
|
489
|
+
if (event.key === 'Escape') controller.cancel()
|
|
490
|
+
})
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### Pointer state and cancellation
|
|
494
|
+
|
|
495
|
+
`getPointer()` returns the press origin and the latest pointer position during an active drag. The method returns `null` before activation and while idle. The same object lasts for the drag, but each pointer move replaces its `position` property. A copy of the coordinates preserves an earlier position.
|
|
496
|
+
|
|
497
|
+
`cancel()` ends a pending press or an active drag without committing the move. Window focus loss also cancels the gesture. Cancellation of an active drag calls `onChange` with the idle state. The controller remains available for the next press.
|
|
498
|
+
|
|
499
|
+
`cleanup()` ends the gesture and removes listeners without calling `onChange`. A browser `pointercancel` ends the gesture without suppressing a later click. The canceled pointer does not generate a click.
|
|
500
|
+
|
|
501
|
+
#### Collision points
|
|
502
|
+
|
|
503
|
+
By default, the pointer position determines the insertion index. An item moves past a neighbor when the pointer crosses that neighbor's midpoint.
|
|
504
|
+
|
|
505
|
+
`getCollisionPoint(pointer, item)` supplies a different point for the insertion calculation. `item` contains the dragged item's bounds at drag start. The controller clamps the returned point to the bounding area of the measured items. A `null` result or nonfinite coordinates fall back to the pointer position.
|
|
506
|
+
|
|
507
|
+
The example uses the right edge when the item moves right and the left edge when the item moves left. A wide item can then pass a narrow neighbor before the pointer reaches that neighbor's midpoint:
|
|
508
|
+
|
|
509
|
+
```ts
|
|
510
|
+
const controller = createReorderableList({
|
|
511
|
+
getItems: () => columns,
|
|
512
|
+
setItems: (next) => (columns = next),
|
|
513
|
+
getCollisionPoint: ({ origin, position }, item) => {
|
|
514
|
+
const offset = position.clientX - origin.clientX
|
|
515
|
+
|
|
516
|
+
return { clientX: (offset > 0 ? item.right : item.left) + offset, clientY: position.clientY }
|
|
517
|
+
},
|
|
518
|
+
})
|
|
519
|
+
```
|
|
459
520
|
|
|
460
|
-
|
|
521
|
+
The last pointer move determines whether release commits the move. A pointer outside the reorder bounds cancels the drop, even if the collision point remains inside.
|
|
522
|
+
|
|
523
|
+
#### Writing direction
|
|
524
|
+
|
|
525
|
+
At drag start, the controller reads the list element's writing direction. Without a registered list element, the controller reads the first registered item's direction. Horizontal auto-scroll supports right-to-left containers, where the horizontal scroll position starts at zero and decreases as the content scrolls left.
|
|
526
|
+
|
|
527
|
+
#### Reorderable list options
|
|
461
528
|
|
|
462
529
|
| Option | Type | Default | Description |
|
|
463
530
|
|--------|------|---------|-------------|
|
|
464
531
|
| `getItems` | `() => readonly T[]` | Required | Current ordered items |
|
|
465
532
|
| `setItems` | `(items: T[]) => void` | `undefined` | Optional writer used by `moveItem` and pointer commits |
|
|
466
533
|
| `canReorder` | `() => boolean` | `true` | Guard before starting or committing a reorder |
|
|
467
|
-
| `getBounds` | `() => ReorderBounds \| null` | Registered list
|
|
534
|
+
| `getBounds` | `() => ReorderBounds \| null` | Registered list bounds | Optional outer active area |
|
|
468
535
|
| `autoScroll` | `boolean \| AutoScrollerOptions` | `false` | Edge auto-scroll while dragging |
|
|
536
|
+
| `activationDistance` | `number` | `0` | Pointer travel in CSS pixels before a press starts dragging |
|
|
537
|
+
| `suppressClickAfterDrag` | `boolean` | `false` | Whether the controller suppresses the click after a pointer drag |
|
|
538
|
+
| `getCollisionPoint` | `(pointer, item) => ReorderPoint \| null` | Pointer position | Point used to calculate the insertion index during a drag |
|
|
469
539
|
| `onChange` | `(state) => void` | `undefined` | Called when pointer drag state changes |
|
|
470
540
|
| `onBeforeReorder` | `(move, context) => void` | `undefined` | Called before writing items or firing `onReorder` |
|
|
471
541
|
| `onReorder` | `(move, context) => void` | `undefined` | Called after a valid keyboard or pointer reorder |
|
|
472
542
|
|
|
543
|
+
#### Reorderable list controller
|
|
544
|
+
|
|
545
|
+
| Method | Description |
|
|
546
|
+
|--------|-------------|
|
|
547
|
+
| `setListElement(element)` | Sets the element used for default bounds and writing direction |
|
|
548
|
+
| `setItemElement(index, element)` | Registers an item element by index, or unregisters it when `element` is `null` or `undefined` |
|
|
549
|
+
| `getItemElements()` | Returns registered item elements in index order |
|
|
550
|
+
| `getPreviewOrder()` | Returns item indices in preview order |
|
|
551
|
+
| `getPreviewItems()` | Returns items with their source and visual indices in preview order |
|
|
552
|
+
| `moveItem(index, direction)` | Commits an `'up'` or `'down'` keyboard reorder |
|
|
553
|
+
| `pointerDown(index, event)` | Starts a pending press or an active drag from a handle's `pointerdown` event |
|
|
554
|
+
| `getPointer()` | Returns the origin and the latest position of an active drag, or `null` |
|
|
555
|
+
| `cancel()` | Ends a pending press or an active drag without committing the move |
|
|
556
|
+
| `cleanup()` | Ends pointer work and removes listeners without calling `onChange` |
|
|
557
|
+
|
|
558
|
+
### getReorderOffsets
|
|
559
|
+
|
|
560
|
+
`getReorderOffsets(rects, order, options?)` returns each item's offset along the layout axis after a reorder. `rects` contains item bounds in source order. `order` contains source indices in the new order. The returned offsets use source order.
|
|
561
|
+
|
|
562
|
+
The following example applies vertical offsets to preview an order:
|
|
563
|
+
|
|
564
|
+
```ts
|
|
565
|
+
import { getReorderOffsets } from '@inertiaui/vanilla'
|
|
566
|
+
|
|
567
|
+
const rects = items.map((item) => item.getBoundingClientRect())
|
|
568
|
+
const offsets = getReorderOffsets(rects, [2, 0, 1])
|
|
569
|
+
|
|
570
|
+
items.forEach((item, index) => (item.style.transform = `translateY(${offsets[index]}px)`))
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
`getReorderOffsets` supports one row or one column with items of different sizes. It does not support layouts that wrap onto several rows. Each measured gap remains between the same layout positions after a reorder.
|
|
574
|
+
|
|
575
|
+
The `gap` option replaces the measured gaps in both the source and destination layouts. An explicit gap accounts for boxes displaced by sticky positioning. With `gap: 0`, the calculation places items edge to edge.
|
|
576
|
+
|
|
577
|
+
The function returns zero offsets when `order` is unchanged or is not a permutation of the source indices.
|
|
578
|
+
|
|
579
|
+
| Option | Type | Default | Description |
|
|
580
|
+
|--------|------|---------|-------------|
|
|
581
|
+
| `axis` | `'x' \| 'y'` | `'y'` | Axis the items are laid out along |
|
|
582
|
+
| `reverse` | `boolean` | `false` | The items run toward the start of the axis, as in a right-to-left row |
|
|
583
|
+
| `gap` | `number` | Measured | Space between neighboring items |
|
|
584
|
+
|
|
585
|
+
### getScrollableAncestors
|
|
586
|
+
|
|
587
|
+
`getScrollableAncestors(element, axis?)` returns scrollable ancestors, nearest first, followed by the element's window. The traversal follows assigned slots and crosses shadow roots through their hosts. `axis` defaults to `'both'`. A value of `'x'` or `'y'` restricts the ancestors to those that scroll along that axis. The window remains the last entry.
|
|
588
|
+
|
|
589
|
+
The following example caches horizontal scroll containers until the drag ends:
|
|
590
|
+
|
|
591
|
+
```ts
|
|
592
|
+
import { createReorderableList, getScrollableAncestors, type AutoScrollContainer } from '@inertiaui/vanilla'
|
|
593
|
+
|
|
594
|
+
let containers: AutoScrollContainer[] | null = null
|
|
595
|
+
|
|
596
|
+
const controller = createReorderableList({
|
|
597
|
+
getItems: () => columns,
|
|
598
|
+
autoScroll: { axis: 'x', getScrollContainers: () => (containers ??= getScrollableAncestors(row, 'x')) },
|
|
599
|
+
onChange: (state) => state.draggedIndex === null && (containers = null),
|
|
600
|
+
})
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
With auto-scroll enabled and no `getScrollContainers` callback, the controller discovers scrollable ancestors along both axes on each pointer move.
|
|
604
|
+
|
|
473
605
|
## Positioning
|
|
474
606
|
|
|
475
607
|
Utilities for positioning floating elements (dropdowns, tooltips, popovers) relative to a reference element. Uses [CSS Anchor Positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning) when supported, with an automatic JavaScript fallback.
|
|
@@ -511,6 +643,7 @@ The function applies positioning styles to the floating element automatically (`
|
|
|
511
643
|
| `offset` | `number` | `0` | Distance in pixels between reference and floating element |
|
|
512
644
|
| `flip` | `boolean` | `true` | Flip to opposite side when overflowing viewport |
|
|
513
645
|
| `autoSize` | `boolean` | `false` | Constrain the floating element to the available viewport space (sets `max-height` and `overflow-y: auto`) |
|
|
646
|
+
| `anchorPositioning` | `boolean` | `true` | Use CSS anchors when supported. Set to `false` to use numeric positioning. |
|
|
514
647
|
|
|
515
648
|
#### Placements
|
|
516
649
|
|
|
@@ -816,6 +949,90 @@ popover.addEventListener('focusout', (event) => {
|
|
|
816
949
|
| `startAutoUpdate()` | Starts `autoUpdateTopLayerPopover` |
|
|
817
950
|
| `cleanupPopover()` | Cleans focus-out and positioning listeners |
|
|
818
951
|
|
|
952
|
+
## Tooltip Controllers
|
|
953
|
+
|
|
954
|
+
`createTooltipController(options)` coordinates hover and focus intent, delayed opening, positioning, Escape dismissal, and cleanup. It never moves focus. It keeps a tooltip open while either pointer or keyboard focus remains in its trigger, and ignores completion of an obsolete closing transition.
|
|
955
|
+
|
|
956
|
+
The default `position` is `{ placement: 'top', offset: 6, anchorPositioning: false }`. Tooltips use numeric positioning unless `position.anchorPositioning` is `true` and the browser supports CSS anchors.
|
|
957
|
+
|
|
958
|
+
```ts
|
|
959
|
+
import { createTooltipController } from '@inertiaui/vanilla'
|
|
960
|
+
|
|
961
|
+
const tooltip = createTooltipController({
|
|
962
|
+
reference: () => triggerElement,
|
|
963
|
+
tooltip: () => tooltipElement,
|
|
964
|
+
enabled: () => Boolean(text),
|
|
965
|
+
delay: () => delay,
|
|
966
|
+
position: { placement: 'top', offset: 6 },
|
|
967
|
+
onOpenChange: (open) => setVisible(open),
|
|
968
|
+
})
|
|
969
|
+
```
|
|
970
|
+
|
|
971
|
+
Bind `onMouseEnter`, `onMouseLeave`, `onFocusIn`, and `onFocusOut` to the trigger. After rendering the tooltip, call `mount()`. Call `cleanup()` before removing its DOM or disposing its owner; call `hide()` to dismiss it. `isOpen` and `native` are readonly values, not framework reactive state. Bridge changes through `onOpenChange`.
|
|
972
|
+
|
|
973
|
+
Render native tooltips with `popover="manual"` and `role="tooltip"`, ideally within the trigger's DOM ancestry. For fallback tooltips, choose the portal destination yourself (inside any surrounding modal) and supply appropriate positioning/stacking styles. CSS width limits are preserved. Supply a stable tooltip ID and connect the trigger's `aria-describedby` while visible.
|
|
974
|
+
|
|
975
|
+
Optional `onMount({ reference, popover, native })` can return a cleanup callback. `transition(visible)` can return a promise; hiding waits for it. The consumer owns animation styles, cancellation, and reduced-motion policy. `cleanup()` cancels delayed opening and removes mounted behavior while preserving logical open state, so a framework can replay `mount()` safely.
|
|
976
|
+
|
|
977
|
+
## Dialog Controllers
|
|
978
|
+
|
|
979
|
+
`createDialogController(options)` adds native modal behavior, or a focus-trapped fallback when `showModal` is unavailable. It balances scroll locks, restores focus, and restricts fallback Escape handling to the top dialog. The fallback marks siblings along the dialog ancestry inert, preserving accessibility of the dialog itself.
|
|
980
|
+
|
|
981
|
+
```ts
|
|
982
|
+
import { createDialogController } from '@inertiaui/vanilla'
|
|
983
|
+
|
|
984
|
+
const dialog = createDialogController({
|
|
985
|
+
dialog: () => dialogElement,
|
|
986
|
+
panel: () => panelElement,
|
|
987
|
+
onOpenChange: (open) => setVisible(open),
|
|
988
|
+
onCancel: () => requestCancel(),
|
|
989
|
+
})
|
|
990
|
+
|
|
991
|
+
dialog.open()
|
|
992
|
+
// After rendering:
|
|
993
|
+
dialog.mount()
|
|
994
|
+
// Close and await any supplied transition:
|
|
995
|
+
await dialog.close()
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
Use `<dialog>` when `native` is true. Otherwise render a container with `role="dialog"`, `aria-modal="true"`, a backdrop, and appropriate styles. Supply accessible labels in either case. The controller calls `onCancel` for Escape; the consumer decides whether to close, so controlled components can honor their existing cancellation contract.
|
|
999
|
+
|
|
1000
|
+
`transition(visible)` and `onMount({ dialog, panel, native })` follow the same transition/cleanup contract as tooltips. Reopening during a closing transition keeps the dialog open. Call `cleanup()` before removing DOM or disposing the owner. It releases mounted behavior without changing logical `isOpen`, allowing framework effect replay. Call `close()` for an actual state change.
|
|
1001
|
+
|
|
1002
|
+
## Inline styles
|
|
1003
|
+
|
|
1004
|
+
`captureInlineStyles(element, properties)` records the inline values and `!important` priorities of the specified CSS properties. Property names use CSS syntax, such as `z-index`.
|
|
1005
|
+
|
|
1006
|
+
`restore()` restores all captured properties. `restore(properties)` restores only the captured properties in that list. Both methods leave other properties unchanged. If a captured property had no inline value, `restore` removes the property.
|
|
1007
|
+
|
|
1008
|
+
The following example restores `transform` before it restores the other captured properties:
|
|
1009
|
+
|
|
1010
|
+
```ts
|
|
1011
|
+
import { captureInlineStyles } from '@inertiaui/vanilla'
|
|
1012
|
+
|
|
1013
|
+
const styles = captureInlineStyles(row, ['transform', 'z-index'])
|
|
1014
|
+
row.style.zIndex = '10'
|
|
1015
|
+
row.style.transform = 'translateY(40px)'
|
|
1016
|
+
|
|
1017
|
+
styles.restore(['transform'])
|
|
1018
|
+
styles.restore()
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
## CSS Variable Inheritance
|
|
1022
|
+
|
|
1023
|
+
`inheritCssVariables(source, target, { filter, mediaQueries })` copies selected computed custom properties to a portal and returns a cleanup function. It watches ancestor class/style changes and the supplied media queries. Cleanup restores prior inline values and priorities when its own value is still present; consumer value overrides are preserved.
|
|
1024
|
+
|
|
1025
|
+
```ts
|
|
1026
|
+
import { inheritCssVariables } from '@inertiaui/vanilla'
|
|
1027
|
+
|
|
1028
|
+
const cleanup = inheritCssVariables(trigger, portal, {
|
|
1029
|
+
filter: (name) => name.startsWith('--my-component-'),
|
|
1030
|
+
mediaQueries: ['(prefers-color-scheme: dark)'],
|
|
1031
|
+
})
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
The helper is intentionally scoped to caller-selected variables. It does not observe stylesheet edits, arbitrary attribute selectors, or reparenting: remount it when the source ancestry changes. Native top-layer elements retain ordinary DOM inheritance and generally do not need this helper.
|
|
1035
|
+
|
|
819
1036
|
## Accessibility
|
|
820
1037
|
|
|
821
1038
|
Accessibility utilities for managing `aria-hidden` attributes with reference counting support.
|
|
@@ -1031,6 +1248,42 @@ if (!prefersReducedMotion() && supportsWebAnimations()) {
|
|
|
1031
1248
|
}
|
|
1032
1249
|
```
|
|
1033
1250
|
|
|
1251
|
+
### createLayoutAnimation
|
|
1252
|
+
|
|
1253
|
+
`createLayoutAnimation(options?)` schedules animations from a layout snapshot and tracks scheduled and active animations. The snapshot contains element bounds before a layout change. `getElements` returns the elements after the renderer applies that change.
|
|
1254
|
+
|
|
1255
|
+
The following example animates a reordered list and restores the moved row's `z-index` when the animations settle:
|
|
1256
|
+
|
|
1257
|
+
```typescript
|
|
1258
|
+
import { captureAnimationSnapshot, captureInlineStyles, createLayoutAnimation } from '@inertiaui/vanilla'
|
|
1259
|
+
|
|
1260
|
+
const layout = createLayoutAnimation({ duration: 160, easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'none' })
|
|
1261
|
+
|
|
1262
|
+
const snapshot = captureAnimationSnapshot(rows())
|
|
1263
|
+
const styles = captureInlineStyles(movedRow, ['z-index'])
|
|
1264
|
+
movedRow.style.zIndex = '10'
|
|
1265
|
+
renderItemsInNewOrder()
|
|
1266
|
+
|
|
1267
|
+
layout.animate(snapshot, rows, {
|
|
1268
|
+
onStart: () => movedRow.focus({ preventScroll: true }),
|
|
1269
|
+
onSettle: () => styles.restore(),
|
|
1270
|
+
})
|
|
1271
|
+
```
|
|
1272
|
+
|
|
1273
|
+
Animations start on the next animation frame by default. The `schedule` option replaces that scheduler. The callback receives a `run` function to call after the renderer updates the layout. `schedule` can return a function that cancels the scheduled call. For Vue, `schedule: (run) => void nextTick(run)` starts the animation after the next DOM update.
|
|
1274
|
+
|
|
1275
|
+
`onStart(animations)` runs immediately after the animations start. `onSettle()` runs asynchronously after all animations from that call finish or are canceled. Cancellation includes both `cancel()` and a later animation that replaces an animation on the same element.
|
|
1276
|
+
|
|
1277
|
+
When no elements animate, `onStart` receives an empty array and `onSettle` still runs asynchronously. For example, no elements animate when the user prefers reduced motion. If `cancel()` stops a scheduled call before it starts, neither callback runs. `cleanup()` prevents later callbacks.
|
|
1278
|
+
|
|
1279
|
+
| Method | Description |
|
|
1280
|
+
|--------|-------------|
|
|
1281
|
+
| `animate(snapshot, getElements, callbacks?)` | Schedules animations from the snapshot to the new layout |
|
|
1282
|
+
| `cancel()` | Cancels scheduled calls and active animations. Active animations still invoke `onSettle` |
|
|
1283
|
+
| `cleanup()` | Cancels all work, prevents callbacks, and ignores later `animate()` calls |
|
|
1284
|
+
|
|
1285
|
+
The options are those of [`animateFromSnapshot`](#captureanimationsnapshot-and-animatefromsnapshot), plus `schedule`.
|
|
1286
|
+
|
|
1034
1287
|
### cancelAnimations
|
|
1035
1288
|
|
|
1036
1289
|
Cancel any running animations on an element:
|
|
@@ -1156,7 +1409,9 @@ Create a timeout-based debouncer with an explicit millisecond delay. This is use
|
|
|
1156
1409
|
```typescript
|
|
1157
1410
|
import { createDebouncer } from '@inertiaui/vanilla'
|
|
1158
1411
|
|
|
1159
|
-
|
|
1412
|
+
// A number or a getter evaluated for each new schedule.
|
|
1413
|
+
let delay = 250
|
|
1414
|
+
const debouncer = createDebouncer(() => delay)
|
|
1160
1415
|
|
|
1161
1416
|
input.addEventListener('input', () => {
|
|
1162
1417
|
debouncer.schedule(() => {
|
|
@@ -1168,6 +1423,8 @@ input.addEventListener('input', () => {
|
|
|
1168
1423
|
debouncer.cancel()
|
|
1169
1424
|
```
|
|
1170
1425
|
|
|
1426
|
+
`pending` is readonly and true only while a callback is scheduled. Both cancellation and callback dispatch clear it.
|
|
1427
|
+
|
|
1171
1428
|
### detectFramerate
|
|
1172
1429
|
|
|
1173
1430
|
Detect the browser's current framerate. Returns a Promise that resolves with the detected FPS (capped to the 30–240 range). Falls back to 60 if `requestAnimationFrame` is unavailable or detection times out.
|
|
@@ -1673,6 +1930,8 @@ import type {
|
|
|
1673
1930
|
ReorderCommitContext,
|
|
1674
1931
|
ReorderDirection,
|
|
1675
1932
|
ReorderMove,
|
|
1933
|
+
ReorderPoint,
|
|
1934
|
+
ReorderPointer,
|
|
1676
1935
|
ReorderPreviewItem,
|
|
1677
1936
|
ReorderableListController,
|
|
1678
1937
|
ReorderableListOptions,
|