@inertiaui/vanilla 1.5.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 +221 -32
- package/dist/index.d.ts +121 -1
- package/dist/index.js +912 -462
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ npm install @inertiaui/vanilla
|
|
|
28
28
|
- [Native Popovers](#native-popovers)
|
|
29
29
|
- [Tooltip Controllers](#tooltip-controllers)
|
|
30
30
|
- [Dialog Controllers](#dialog-controllers)
|
|
31
|
+
- [Inline styles](#inline-styles)
|
|
31
32
|
- [CSS Variable Inheritance](#css-variable-inheritance)
|
|
32
33
|
- [Accessibility](#accessibility)
|
|
33
34
|
- [Animation](#animation)
|
|
@@ -408,71 +409,199 @@ focusOut.cleanup()
|
|
|
408
409
|
|
|
409
410
|
## Reorder
|
|
410
411
|
|
|
411
|
-
Framework-neutral helpers for keyboard and pointer reordering.
|
|
412
|
-
|
|
413
412
|
### createReorderableList
|
|
414
413
|
|
|
415
|
-
|
|
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.
|
|
416
415
|
|
|
417
416
|
```typescript
|
|
418
417
|
import {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
418
|
+
animateFromSnapshot,
|
|
419
|
+
captureAnimationSnapshot,
|
|
420
|
+
createReorderableList,
|
|
421
|
+
REORDERABLE_LIST_HANDLE_ATTRIBUTE,
|
|
422
|
+
type AnimationSnapshot,
|
|
424
423
|
} from '@inertiaui/vanilla'
|
|
425
424
|
|
|
426
425
|
let items = ['Apple', 'Banana', 'Cherry']
|
|
427
426
|
let animationSnapshot: AnimationSnapshot | null = null
|
|
428
427
|
|
|
429
428
|
const controller = createReorderableList({
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
+
},
|
|
448
447
|
})
|
|
449
448
|
|
|
450
449
|
controller.setListElement(listElement)
|
|
451
450
|
|
|
452
451
|
items.forEach((_, index) => {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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))
|
|
456
455
|
})
|
|
457
456
|
|
|
458
457
|
moveUpButton.addEventListener('click', () => controller.moveItem(index, 'up'))
|
|
459
458
|
```
|
|
460
459
|
|
|
461
|
-
|
|
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
|
+
```
|
|
520
|
+
|
|
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
|
|
462
524
|
|
|
463
|
-
|
|
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
|
|
464
528
|
|
|
465
529
|
| Option | Type | Default | Description |
|
|
466
530
|
|--------|------|---------|-------------|
|
|
467
531
|
| `getItems` | `() => readonly T[]` | Required | Current ordered items |
|
|
468
532
|
| `setItems` | `(items: T[]) => void` | `undefined` | Optional writer used by `moveItem` and pointer commits |
|
|
469
533
|
| `canReorder` | `() => boolean` | `true` | Guard before starting or committing a reorder |
|
|
470
|
-
| `getBounds` | `() => ReorderBounds \| null` | Registered list
|
|
534
|
+
| `getBounds` | `() => ReorderBounds \| null` | Registered list bounds | Optional outer active area |
|
|
471
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 |
|
|
472
539
|
| `onChange` | `(state) => void` | `undefined` | Called when pointer drag state changes |
|
|
473
540
|
| `onBeforeReorder` | `(move, context) => void` | `undefined` | Called before writing items or firing `onReorder` |
|
|
474
541
|
| `onReorder` | `(move, context) => void` | `undefined` | Called after a valid keyboard or pointer reorder |
|
|
475
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
|
+
|
|
476
605
|
## Positioning
|
|
477
606
|
|
|
478
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.
|
|
@@ -514,6 +643,7 @@ The function applies positioning styles to the floating element automatically (`
|
|
|
514
643
|
| `offset` | `number` | `0` | Distance in pixels between reference and floating element |
|
|
515
644
|
| `flip` | `boolean` | `true` | Flip to opposite side when overflowing viewport |
|
|
516
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. |
|
|
517
647
|
|
|
518
648
|
#### Placements
|
|
519
649
|
|
|
@@ -823,6 +953,8 @@ popover.addEventListener('focusout', (event) => {
|
|
|
823
953
|
|
|
824
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.
|
|
825
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
|
+
|
|
826
958
|
```ts
|
|
827
959
|
import { createTooltipController } from '@inertiaui/vanilla'
|
|
828
960
|
|
|
@@ -867,6 +999,25 @@ Use `<dialog>` when `native` is true. Otherwise render a container with `role="d
|
|
|
867
999
|
|
|
868
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.
|
|
869
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
|
+
|
|
870
1021
|
## CSS Variable Inheritance
|
|
871
1022
|
|
|
872
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.
|
|
@@ -1097,6 +1248,42 @@ if (!prefersReducedMotion() && supportsWebAnimations()) {
|
|
|
1097
1248
|
}
|
|
1098
1249
|
```
|
|
1099
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
|
+
|
|
1100
1287
|
### cancelAnimations
|
|
1101
1288
|
|
|
1102
1289
|
Cancel any running animations on an element:
|
|
@@ -1743,6 +1930,8 @@ import type {
|
|
|
1743
1930
|
ReorderCommitContext,
|
|
1744
1931
|
ReorderDirection,
|
|
1745
1932
|
ReorderMove,
|
|
1933
|
+
ReorderPoint,
|
|
1934
|
+
ReorderPointer,
|
|
1746
1935
|
ReorderPreviewItem,
|
|
1747
1936
|
ReorderableListController,
|
|
1748
1937
|
ReorderableListOptions,
|
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
|
/**
|
|
@@ -93,6 +100,12 @@ export declare function createFocusOutDismiss(options: FocusOutDismissOptions):
|
|
|
93
100
|
|
|
94
101
|
export declare function createFocusTrap(container: HTMLElement, options?: FocusTrapOptions): CleanupFunction;
|
|
95
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
|
+
|
|
96
109
|
export declare function createMenuNavigation(container: HTMLElement, options?: MenuNavigationOptions): CleanupFunction;
|
|
97
110
|
|
|
98
111
|
export declare function createNativePopoverDisclosure(options: NativePopoverDisclosureOptions): NativePopoverDisclosureController;
|
|
@@ -244,6 +257,24 @@ export declare interface FormatColorOptions {
|
|
|
244
257
|
|
|
245
258
|
export declare function generateId(prefix?: string): string;
|
|
246
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
|
+
|
|
247
278
|
/**
|
|
248
279
|
* Convert a hex color string to HSL values.
|
|
249
280
|
* Accepts with or without leading '#'.
|
|
@@ -272,6 +303,11 @@ export declare function hslToHex(h: number, s: number, l: number): string;
|
|
|
272
303
|
/** Copy selected computed custom properties and restore owned inline values on cleanup. */
|
|
273
304
|
export declare function inheritCssVariables(source: HTMLElement, target: HTMLElement, options: CssVariableInheritanceOptions): () => void;
|
|
274
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
|
+
|
|
275
311
|
/**
|
|
276
312
|
* Check whether the document is currently in RTL direction.
|
|
277
313
|
*/
|
|
@@ -281,6 +317,34 @@ export declare function isStandardDomEvent(eventName: string): boolean;
|
|
|
281
317
|
|
|
282
318
|
export declare function kebabCase(string: string): string;
|
|
283
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
|
+
|
|
284
348
|
export declare interface ListboxNavigationOptions<T> {
|
|
285
349
|
items: readonly T[];
|
|
286
350
|
currentIndex: number;
|
|
@@ -483,6 +547,8 @@ declare interface PositionOptions_2 {
|
|
|
483
547
|
* applied via its `anchor` prop, so long menus scroll instead of overflowing.
|
|
484
548
|
*/
|
|
485
549
|
autoSize?: boolean;
|
|
550
|
+
/** Use CSS anchors when supported. Set false to use numeric positioning. */
|
|
551
|
+
anchorPositioning?: boolean;
|
|
486
552
|
}
|
|
487
553
|
export { PositionOptions_2 as PositionOptions }
|
|
488
554
|
|
|
@@ -532,7 +598,18 @@ export declare interface ReorderableListController<T> {
|
|
|
532
598
|
moveItem: (index: number, direction: ReorderDirection) => ReorderMove<T> | null;
|
|
533
599
|
/** Begin a pointer reorder from a registered handle event. */
|
|
534
600
|
pointerDown: (index: number, event: PointerEvent) => void;
|
|
535
|
-
/**
|
|
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. */
|
|
536
613
|
cleanup: CleanupFunction;
|
|
537
614
|
}
|
|
538
615
|
|
|
@@ -547,6 +624,23 @@ export declare interface ReorderableListOptions<T> {
|
|
|
547
624
|
getBounds?: () => ReorderBounds | null;
|
|
548
625
|
/** Optional edge auto-scroll while pointer-dragging. Disabled by default. */
|
|
549
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;
|
|
550
644
|
/** Called whenever pointer drag state changes. */
|
|
551
645
|
onChange?: (state: ReorderableListState) => void;
|
|
552
646
|
/** Called immediately before items are written or `onReorder` fires. */
|
|
@@ -586,6 +680,32 @@ export declare type ReorderMove<T> = {
|
|
|
586
680
|
source: ReorderSource;
|
|
587
681
|
};
|
|
588
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
|
+
|
|
589
709
|
export declare type ReorderPreviewItem<T> = {
|
|
590
710
|
item: T;
|
|
591
711
|
/** Index in the source item array. */
|