glasslikeui 1.9.1 → 1.10.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 +887 -26
- package/dist/actions/adaptiveTone.d.ts +50 -0
- package/dist/actions/adaptiveTone.js +569 -0
- package/dist/actions/alertLogic.d.ts +67 -0
- package/dist/actions/alertLogic.js +123 -0
- package/dist/actions/anchorPlacement.d.ts +92 -0
- package/dist/actions/anchorPlacement.js +137 -0
- package/dist/actions/dragSnap.d.ts +1 -1
- package/dist/actions/dragSnapMath.d.ts +70 -0
- package/dist/actions/dragSnapMath.js +115 -0
- package/dist/actions/glassToneLogic.d.ts +182 -0
- package/dist/actions/glassToneLogic.js +513 -0
- package/dist/actions/heightTransition.d.ts +32 -0
- package/dist/actions/heightTransition.js +64 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +1 -0
- package/dist/actions/inertSiblings.js +20 -4
- package/dist/actions/menuLogic.d.ts +40 -0
- package/dist/actions/menuLogic.js +68 -0
- package/dist/actions/modalDialog.d.ts +19 -0
- package/dist/actions/modalDialog.js +48 -0
- package/dist/actions/popoverLogic.d.ts +25 -0
- package/dist/actions/popoverLogic.js +48 -0
- package/dist/actions/rovingIndex.d.ts +30 -0
- package/dist/actions/rovingIndex.js +49 -0
- package/dist/actions/scrollRunTracker.d.ts +36 -0
- package/dist/actions/scrollRunTracker.js +77 -0
- package/dist/actions/scrollUnder.d.ts +21 -0
- package/dist/actions/scrollUnder.js +29 -0
- package/dist/actions/segmentedLogic.d.ts +38 -0
- package/dist/actions/segmentedLogic.js +59 -0
- package/dist/actions/sheetLogic.d.ts +25 -7
- package/dist/actions/sheetLogic.js +43 -10
- package/dist/actions/sliderLogic.d.ts +29 -0
- package/dist/actions/sliderLogic.js +53 -0
- package/dist/actions/swipeActions.d.ts +46 -2
- package/dist/actions/swipeActions.js +267 -46
- package/dist/actions/tabBarMinimize.d.ts +31 -0
- package/dist/actions/tabBarMinimize.js +38 -0
- package/dist/actions/tabViewLogic.d.ts +47 -0
- package/dist/actions/tabViewLogic.js +71 -0
- package/dist/actions/toggleKnobLogic.d.ts +57 -0
- package/dist/actions/toggleKnobLogic.js +66 -0
- package/dist/actions/toolbarFocus.d.ts +44 -0
- package/dist/actions/toolbarFocus.js +228 -0
- package/dist/actions/topLayer.d.ts +12 -0
- package/dist/actions/topLayer.js +18 -0
- package/dist/components/dialog/ActionSheet.svelte +457 -0
- package/dist/components/dialog/ActionSheet.svelte.d.ts +25 -0
- package/dist/components/dialog/Alert.svelte +337 -0
- package/dist/components/dialog/Alert.svelte.d.ts +28 -0
- package/dist/components/dialog/index.d.ts +6 -0
- package/dist/components/dialog/index.js +6 -0
- package/dist/components/glass/Glass.svelte +49 -17
- package/dist/components/glass/Glass.svelte.d.ts +8 -0
- package/dist/components/glass/GlassSection.svelte +9 -1
- package/dist/components/glass/LensFilters.svelte +4 -2
- package/dist/components/glass/Popover.svelte +379 -0
- package/dist/components/glass/Popover.svelte.d.ts +30 -0
- package/dist/components/glass/Sheet.svelte +450 -105
- package/dist/components/glass/Sheet.svelte.d.ts +55 -7
- package/dist/components/glass/index.d.ts +3 -0
- package/dist/components/glass/index.js +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +4 -0
- package/dist/components/interactive/Badge.svelte +97 -6
- package/dist/components/interactive/Badge.svelte.d.ts +13 -2
- package/dist/components/interactive/Button.svelte +159 -20
- package/dist/components/interactive/Button.svelte.d.ts +14 -1
- package/dist/components/interactive/IconButton.svelte +214 -4
- package/dist/components/interactive/IconButton.svelte.d.ts +2 -1
- package/dist/components/interactive/ProgressView.svelte +306 -0
- package/dist/components/interactive/ProgressView.svelte.d.ts +25 -0
- package/dist/components/interactive/Segment.d.ts +14 -0
- package/dist/components/interactive/Segment.js +1 -0
- package/dist/components/interactive/SegmentedControl.svelte +399 -0
- package/dist/components/interactive/SegmentedControl.svelte.d.ts +17 -0
- package/dist/components/interactive/Slider.svelte +299 -0
- package/dist/components/interactive/Slider.svelte.d.ts +23 -0
- package/dist/components/interactive/TabView.svelte +573 -41
- package/dist/components/interactive/TabView.svelte.d.ts +25 -0
- package/dist/components/interactive/Toggle.svelte +287 -16
- package/dist/components/interactive/Toggle.svelte.d.ts +12 -0
- package/dist/components/interactive/index.d.ts +4 -0
- package/dist/components/interactive/index.js +3 -0
- package/dist/components/list/List.svelte +41 -17
- package/dist/components/list/List.svelte.d.ts +1 -0
- package/dist/components/list/ListRow.svelte +208 -47
- package/dist/components/list/ListRow.svelte.d.ts +16 -1
- package/dist/components/menu/Menu.svelte +51 -27
- package/dist/components/menu/Menu.svelte.d.ts +5 -0
- package/dist/components/menu/MenuItem.svelte +82 -25
- package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
- package/dist/components/menu/MenuSection.svelte +95 -0
- package/dist/components/menu/MenuSection.svelte.d.ts +18 -0
- package/dist/components/menu/MenuSubmenu.svelte +196 -0
- package/dist/components/menu/MenuSubmenu.svelte.d.ts +11 -0
- package/dist/components/menu/index.d.ts +4 -1
- package/dist/components/menu/index.js +3 -1
- package/dist/components/navigation/NavigationBar.svelte +97 -15
- package/dist/components/navigation/NavigationBar.svelte.d.ts +6 -0
- package/dist/components/toolbar/Toolbar.svelte +43 -0
- package/dist/components/toolbar/Toolbar.svelte.d.ts +13 -0
- package/dist/components/toolbar/ToolbarItemGroup.svelte +45 -0
- package/dist/components/toolbar/ToolbarItemGroup.svelte.d.ts +14 -0
- package/dist/components/toolbar/ToolbarSpacer.svelte +36 -0
- package/dist/components/toolbar/ToolbarSpacer.svelte.d.ts +12 -0
- package/dist/components/toolbar/index.d.ts +7 -0
- package/dist/components/toolbar/index.js +7 -0
- package/dist/components/typography/Text.svelte +9 -1
- package/dist/constants/alertAction.d.ts +19 -0
- package/dist/constants/alertAction.js +1 -0
- package/dist/constants/badge.d.ts +32 -0
- package/dist/constants/badge.js +47 -0
- package/dist/constants/buttons.d.ts +45 -0
- package/dist/constants/buttons.js +52 -0
- package/dist/constants/colors.d.ts +9 -4
- package/dist/constants/colors.js +9 -4
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.js +3 -0
- package/dist/constants/progress.d.ts +56 -0
- package/dist/constants/progress.js +75 -0
- package/dist/constants/variants.d.ts +6 -2
- package/dist/constants/variants.js +2 -2
- package/dist/styles/glasslikeui.css +128 -1
- package/dist/styles/lens.css +21 -19
- package/dist/styles/squircle.css +17 -7
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decisions behind the Toggle switch and its draggable knob, as plain
|
|
3
|
+
* functions, so mutation testing reaches them (Stryker cannot instrument
|
|
4
|
+
* .svelte files). Internal.
|
|
5
|
+
*/
|
|
6
|
+
/** The look of the switch: the iOS 26 glass switch, or the switch before it. */
|
|
7
|
+
export type ToggleAppearance = 'glass' | 'classic';
|
|
8
|
+
/** The look of the knob while pressed: a clear glass lens, or the solid knob. */
|
|
9
|
+
export type ToggleKnob = 'solid' | 'glass';
|
|
10
|
+
/** The size of a switch, in px. Toggle.svelte draws the same numbers in CSS. */
|
|
11
|
+
export interface ToggleMetrics {
|
|
12
|
+
trackWidth: number;
|
|
13
|
+
trackHeight: number;
|
|
14
|
+
knobWidth: number;
|
|
15
|
+
knobHeight: number;
|
|
16
|
+
/** The gap between the knob and the edge of the track. */
|
|
17
|
+
inset: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The sizes of each appearance. Glass is the iOS 26 UISwitch, measured in the
|
|
21
|
+
* iOS 26.5 simulator: a 63 by 28 track and a 37 by 24 capsule knob. Classic is
|
|
22
|
+
* the 51 by 31 switch with a round 27px knob that came before it.
|
|
23
|
+
*/
|
|
24
|
+
export declare const TOGGLE_METRICS: Readonly<Record<ToggleAppearance, Readonly<ToggleMetrics>>>;
|
|
25
|
+
/** How far the pointer moves before a press becomes a drag, in px. A shorter move is a tap. */
|
|
26
|
+
export declare const TOGGLE_DRAG_SLOP = 4;
|
|
27
|
+
/** The appearance to draw: `classic` only when asked for by name, glass otherwise. */
|
|
28
|
+
export declare function toggleAppearance(value: unknown): ToggleAppearance;
|
|
29
|
+
/**
|
|
30
|
+
* The knob to draw. One asked for by name wins. Otherwise the glass switch
|
|
31
|
+
* gets the glass knob, as on iOS 26, and the classic switch keeps its solid one.
|
|
32
|
+
*/
|
|
33
|
+
export declare function toggleKnob(value: unknown, appearance: ToggleAppearance): ToggleKnob;
|
|
34
|
+
/** How far the knob travels from off to on, in px: the track less the knob and its insets. */
|
|
35
|
+
export declare function knobTravel(appearance: ToggleAppearance): number;
|
|
36
|
+
/**
|
|
37
|
+
* A sideways pointer move `dx` in px, measured toward the on end. On is at
|
|
38
|
+
* the right left to right and at the left right to left.
|
|
39
|
+
*/
|
|
40
|
+
export declare function towardOn(dx: number, rtl: boolean): number;
|
|
41
|
+
/** Whether a pointer that moved `dx` px since it went down is dragging the knob. */
|
|
42
|
+
export declare function isKnobDrag(dx: number): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Where the knob sits, in px from the off end, while the pointer has moved
|
|
45
|
+
* `dx` px toward on from where it went down on a switch that was `startedOn`.
|
|
46
|
+
* It never leaves the `travel` px of track.
|
|
47
|
+
*/
|
|
48
|
+
export declare function knobOffset(startedOn: boolean, dx: number, travel: number): number;
|
|
49
|
+
/** Whether the switch is on when the knob is let go at `offset`: past the middle of its `travel`. */
|
|
50
|
+
export declare function isOnAtRelease(offset: number, travel: number): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Whether a pointer event comes from the pointer that pressed the knob. A
|
|
53
|
+
* second finger moving or lifting mid-drag must not move or let go of the knob.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isPressPointer(pressPointerId: number, event: {
|
|
56
|
+
pointerId: number;
|
|
57
|
+
}): boolean;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decisions behind the Toggle switch and its draggable knob, as plain
|
|
3
|
+
* functions, so mutation testing reaches them (Stryker cannot instrument
|
|
4
|
+
* .svelte files). Internal.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The sizes of each appearance. Glass is the iOS 26 UISwitch, measured in the
|
|
8
|
+
* iOS 26.5 simulator: a 63 by 28 track and a 37 by 24 capsule knob. Classic is
|
|
9
|
+
* the 51 by 31 switch with a round 27px knob that came before it.
|
|
10
|
+
*/
|
|
11
|
+
export var TOGGLE_METRICS = {
|
|
12
|
+
glass: { trackWidth: 63, trackHeight: 28, knobWidth: 37, knobHeight: 24, inset: 2 },
|
|
13
|
+
classic: { trackWidth: 51, trackHeight: 31, knobWidth: 27, knobHeight: 27, inset: 2 }
|
|
14
|
+
};
|
|
15
|
+
/** How far the pointer moves before a press becomes a drag, in px. A shorter move is a tap. */
|
|
16
|
+
export var TOGGLE_DRAG_SLOP = 4;
|
|
17
|
+
/** The appearance to draw: `classic` only when asked for by name, glass otherwise. */
|
|
18
|
+
export function toggleAppearance(value) {
|
|
19
|
+
return value === 'classic' ? 'classic' : 'glass';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The knob to draw. One asked for by name wins. Otherwise the glass switch
|
|
23
|
+
* gets the glass knob, as on iOS 26, and the classic switch keeps its solid one.
|
|
24
|
+
*/
|
|
25
|
+
export function toggleKnob(value, appearance) {
|
|
26
|
+
if (value === 'solid' || value === 'glass')
|
|
27
|
+
return value;
|
|
28
|
+
return appearance === 'classic' ? 'solid' : 'glass';
|
|
29
|
+
}
|
|
30
|
+
/** How far the knob travels from off to on, in px: the track less the knob and its insets. */
|
|
31
|
+
export function knobTravel(appearance) {
|
|
32
|
+
var m = TOGGLE_METRICS[appearance];
|
|
33
|
+
return m.trackWidth - m.knobWidth - 2 * m.inset;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A sideways pointer move `dx` in px, measured toward the on end. On is at
|
|
37
|
+
* the right left to right and at the left right to left.
|
|
38
|
+
*/
|
|
39
|
+
export function towardOn(dx, rtl) {
|
|
40
|
+
return rtl ? -dx : dx;
|
|
41
|
+
}
|
|
42
|
+
/** Whether a pointer that moved `dx` px since it went down is dragging the knob. */
|
|
43
|
+
export function isKnobDrag(dx) {
|
|
44
|
+
return Math.abs(dx) > TOGGLE_DRAG_SLOP;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Where the knob sits, in px from the off end, while the pointer has moved
|
|
48
|
+
* `dx` px toward on from where it went down on a switch that was `startedOn`.
|
|
49
|
+
* It never leaves the `travel` px of track.
|
|
50
|
+
*/
|
|
51
|
+
export function knobOffset(startedOn, dx, travel) {
|
|
52
|
+
var start = startedOn ? travel : 0;
|
|
53
|
+
var offset = start + (Number.isFinite(dx) ? dx : 0);
|
|
54
|
+
return Math.min(travel, Math.max(0, offset));
|
|
55
|
+
}
|
|
56
|
+
/** Whether the switch is on when the knob is let go at `offset`: past the middle of its `travel`. */
|
|
57
|
+
export function isOnAtRelease(offset, travel) {
|
|
58
|
+
return offset > travel / 2;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether a pointer event comes from the pointer that pressed the knob. A
|
|
62
|
+
* second finger moving or lifting mid-drag must not move or let go of the knob.
|
|
63
|
+
*/
|
|
64
|
+
export function isPressPointer(pressPointerId, event) {
|
|
65
|
+
return event.pointerId === pressPointerId;
|
|
66
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Roving focus for a WAI-ARIA toolbar: the toolbar is one tab stop, and the
|
|
3
|
+
* arrow keys, Home and End move between its controls. The controls are
|
|
4
|
+
* whatever focusable elements the page puts inside, so they are found in the
|
|
5
|
+
* DOM, and found again whenever the content changes. Internal.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Whether `element` can take focus at all: not disabled (on its own or by a
|
|
9
|
+
* disabled fieldset), not inside a `hidden` or `inert` subtree, and not hidden
|
|
10
|
+
* by CSS. An `aria-disabled` control stays reachable, as the WAI-ARIA toolbar
|
|
11
|
+
* pattern recommends.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isFocusable(element: Element): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether `element` is a control the arrow keys move to. Fields that need the
|
|
16
|
+
* arrow keys themselves (see ownsArrowKeys) are left out: they keep a tab stop
|
|
17
|
+
* of their own, so Tab and Shift+Tab can always leave them and reach the rest.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isToolbarItem(element: Element): boolean;
|
|
20
|
+
/** The controls inside `toolbar` that the arrow keys move between, in document order. */
|
|
21
|
+
export declare function toolbarItems(toolbar: Element): HTMLElement[];
|
|
22
|
+
/**
|
|
23
|
+
* Whether `element` needs the arrow keys, Home and End for itself: a text
|
|
24
|
+
* field, a slider, a select or editable text. The toolbar leaves those keys to
|
|
25
|
+
* it, as the WAI-ARIA toolbar pattern asks.
|
|
26
|
+
*/
|
|
27
|
+
export declare function ownsArrowKeys(element: Element): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether a DOM change can change the toolbar's controls: nodes added or
|
|
30
|
+
* removed, or an attribute changed on a control or on something holding one.
|
|
31
|
+
* A managed element counts too, as the change may be what took it out of the
|
|
32
|
+
* controls, such as a link losing its `href`. A style change on a part with no
|
|
33
|
+
* control in it, such as a knob being dragged, is skipped.
|
|
34
|
+
*/
|
|
35
|
+
export declare function touchesControls(record: Pick<MutationRecord, 'type' | 'target'>): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Makes `toolbar` a single tab stop with arrow key movement between its
|
|
38
|
+
* controls. Text fields, sliders and selects in it keep their own tab stop. `orientation` picks the arrow keys: Left and Right (swapped under
|
|
39
|
+
* `dir="rtl"`) or Up and Down. Movement wraps at the ends, Home and End jump to
|
|
40
|
+
* them. Returns a teardown that removes the listeners. The tab indexes stay, so a
|
|
41
|
+
* teardown followed by a new setup, as on an orientation change, never leaves
|
|
42
|
+
* the toolbar with no tab stop.
|
|
43
|
+
*/
|
|
44
|
+
export declare function toolbarFocus(toolbar: HTMLElement, orientation: 'horizontal' | 'vertical'): () => void;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Roving focus for a WAI-ARIA toolbar: the toolbar is one tab stop, and the
|
|
3
|
+
* arrow keys, Home and End move between its controls. The controls are
|
|
4
|
+
* whatever focusable elements the page puts inside, so they are found in the
|
|
5
|
+
* DOM, and found again whenever the content changes. Internal.
|
|
6
|
+
*/
|
|
7
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
8
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
9
|
+
if (ar || !(i in from)) {
|
|
10
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
11
|
+
ar[i] = from[i];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
15
|
+
};
|
|
16
|
+
import { isInRightToLeft, rovingTarget } from './rovingIndex';
|
|
17
|
+
/**
|
|
18
|
+
* The elements that can be toolbar controls, before disabled, hidden and
|
|
19
|
+
* field-like ones are dropped. Selects and text areas are always fields, so
|
|
20
|
+
* they are not listed.
|
|
21
|
+
*/
|
|
22
|
+
var ITEM_SELECTOR = [
|
|
23
|
+
'button',
|
|
24
|
+
'a[href]',
|
|
25
|
+
'input:not([type="hidden"])',
|
|
26
|
+
'[role="button"]',
|
|
27
|
+
'[role="link"]',
|
|
28
|
+
'[role="checkbox"]',
|
|
29
|
+
'[role="switch"]'
|
|
30
|
+
].join(', ');
|
|
31
|
+
/** Marks a control whose tab index the toolbar set. */
|
|
32
|
+
var MANAGED = 'data-toolbar-roving';
|
|
33
|
+
/** Input types whose arrow keys do not move a caret or change a value. */
|
|
34
|
+
var KEYLESS_INPUT_TYPES = new Set(['button', 'checkbox', 'radio', 'submit', 'reset', 'image', 'color', 'file']);
|
|
35
|
+
/**
|
|
36
|
+
* Whether `element` can take focus at all: not disabled (on its own or by a
|
|
37
|
+
* disabled fieldset), not inside a `hidden` or `inert` subtree, and not hidden
|
|
38
|
+
* by CSS. An `aria-disabled` control stays reachable, as the WAI-ARIA toolbar
|
|
39
|
+
* pattern recommends.
|
|
40
|
+
*/
|
|
41
|
+
export function isFocusable(element) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
if (element.matches(':disabled'))
|
|
44
|
+
return false;
|
|
45
|
+
if (element.closest('[hidden], [inert]') !== null)
|
|
46
|
+
return false;
|
|
47
|
+
// checkVisibility covers display: none and visibility: hidden on the element
|
|
48
|
+
// or an ancestor. Engines without it (jsdom) count the element as shown.
|
|
49
|
+
var shown = (_b = (_a = element).checkVisibility) === null || _b === void 0 ? void 0 : _b.call(_a, { checkVisibilityCSS: true });
|
|
50
|
+
return shown !== false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether `element` is a control the arrow keys move to. Fields that need the
|
|
54
|
+
* arrow keys themselves (see ownsArrowKeys) are left out: they keep a tab stop
|
|
55
|
+
* of their own, so Tab and Shift+Tab can always leave them and reach the rest.
|
|
56
|
+
*/
|
|
57
|
+
export function isToolbarItem(element) {
|
|
58
|
+
return isFocusable(element) && !ownsArrowKeys(element);
|
|
59
|
+
}
|
|
60
|
+
/** The controls inside `toolbar` that the arrow keys move between, in document order. */
|
|
61
|
+
export function toolbarItems(toolbar) {
|
|
62
|
+
return Array.from(toolbar.querySelectorAll(ITEM_SELECTOR)).filter(isToolbarItem);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether `element` needs the arrow keys, Home and End for itself: a text
|
|
66
|
+
* field, a slider, a select or editable text. The toolbar leaves those keys to
|
|
67
|
+
* it, as the WAI-ARIA toolbar pattern asks.
|
|
68
|
+
*/
|
|
69
|
+
export function ownsArrowKeys(element) {
|
|
70
|
+
var tag = element.tagName;
|
|
71
|
+
if (tag === 'TEXTAREA' || tag === 'SELECT')
|
|
72
|
+
return true;
|
|
73
|
+
if (tag === 'INPUT')
|
|
74
|
+
return !KEYLESS_INPUT_TYPES.has(element.type);
|
|
75
|
+
return element.isContentEditable === true;
|
|
76
|
+
}
|
|
77
|
+
/** Controls, and elements the toolbar manages that may have just stopped being controls. */
|
|
78
|
+
var WATCHED = "".concat(ITEM_SELECTOR, ", [").concat(MANAGED, "]");
|
|
79
|
+
/**
|
|
80
|
+
* Whether a DOM change can change the toolbar's controls: nodes added or
|
|
81
|
+
* removed, or an attribute changed on a control or on something holding one.
|
|
82
|
+
* A managed element counts too, as the change may be what took it out of the
|
|
83
|
+
* controls, such as a link losing its `href`. A style change on a part with no
|
|
84
|
+
* control in it, such as a knob being dragged, is skipped.
|
|
85
|
+
*/
|
|
86
|
+
export function touchesControls(record) {
|
|
87
|
+
if (record.type === 'childList')
|
|
88
|
+
return true;
|
|
89
|
+
var target = record.target;
|
|
90
|
+
return target.matches(WATCHED) || target.querySelector(WATCHED) !== null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Makes `toolbar` a single tab stop with arrow key movement between its
|
|
94
|
+
* controls. Text fields, sliders and selects in it keep their own tab stop. `orientation` picks the arrow keys: Left and Right (swapped under
|
|
95
|
+
* `dir="rtl"`) or Up and Down. Movement wraps at the ends, Home and End jump to
|
|
96
|
+
* them. Returns a teardown that removes the listeners. The tab indexes stay, so a
|
|
97
|
+
* teardown followed by a new setup, as on an orientation change, never leaves
|
|
98
|
+
* the toolbar with no tab stop.
|
|
99
|
+
*/
|
|
100
|
+
export function toolbarFocus(toolbar, orientation) {
|
|
101
|
+
var active = null;
|
|
102
|
+
// The controls as of the last sync, to find the one nearest a removed control.
|
|
103
|
+
var lastItems = [];
|
|
104
|
+
// Whether focus is in the toolbar, so that focus can follow when the focused
|
|
105
|
+
// control is removed or disabled.
|
|
106
|
+
var focusInside = false;
|
|
107
|
+
// A control that lost focus to nothing, until it is known whether the user
|
|
108
|
+
// left or the control is going away.
|
|
109
|
+
var leaving = null;
|
|
110
|
+
/** Decides a pending focusout: the user left if the control is still there and focusable. */
|
|
111
|
+
function settleLeave() {
|
|
112
|
+
if (leaving === null)
|
|
113
|
+
return;
|
|
114
|
+
if (leaving.isConnected && isFocusable(leaving))
|
|
115
|
+
focusInside = false;
|
|
116
|
+
leaving = null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The control to move to when `gone` leaves. A new control in its place
|
|
120
|
+
* comes first, as when a Play button is swapped for a Pause button. Then the
|
|
121
|
+
* next old control that is still there, the nearest one before it, and last
|
|
122
|
+
* the first control.
|
|
123
|
+
*/
|
|
124
|
+
function nearest(gone, items) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
// gone is always in lastItems, or null before there were any controls.
|
|
127
|
+
var at = lastItems.indexOf(gone);
|
|
128
|
+
var inPlace = items[at];
|
|
129
|
+
if (inPlace !== undefined && !lastItems.includes(inPlace))
|
|
130
|
+
return inPlace;
|
|
131
|
+
var order = __spreadArray(__spreadArray([], lastItems.slice(at + 1), true), lastItems.slice(0, at).reverse(), true);
|
|
132
|
+
return (_b = (_a = order.find(function (item) { return items.includes(item); })) !== null && _a !== void 0 ? _a : items[0]) !== null && _b !== void 0 ? _b : null;
|
|
133
|
+
}
|
|
134
|
+
function sync() {
|
|
135
|
+
var items = toolbarItems(toolbar);
|
|
136
|
+
var previous = active;
|
|
137
|
+
var lost = !items.includes(previous);
|
|
138
|
+
var focusLost = lost &&
|
|
139
|
+
focusInside &&
|
|
140
|
+
(document.activeElement === previous || document.activeElement === document.body);
|
|
141
|
+
// Keep the tab stop where it was while that control is still there.
|
|
142
|
+
active = lost ? nearest(previous, items) : previous;
|
|
143
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
144
|
+
var item = items_1[_i];
|
|
145
|
+
item.tabIndex = item === active ? 0 : -1;
|
|
146
|
+
item.setAttribute(MANAGED, '');
|
|
147
|
+
}
|
|
148
|
+
// An element that is no longer a control gives up its tab index: a field
|
|
149
|
+
// gets its own tab stop back, and a link that lost its href, a hidden
|
|
150
|
+
// input or a disabled control are no tab stop at all.
|
|
151
|
+
for (var _a = 0, _b = toolbar.querySelectorAll("[".concat(MANAGED, "]")); _a < _b.length; _a++) {
|
|
152
|
+
var element = _b[_a];
|
|
153
|
+
if (items.includes(element))
|
|
154
|
+
continue;
|
|
155
|
+
element.removeAttribute('tabindex');
|
|
156
|
+
element.removeAttribute(MANAGED);
|
|
157
|
+
}
|
|
158
|
+
lastItems = items;
|
|
159
|
+
if (focusLost)
|
|
160
|
+
active === null || active === void 0 ? void 0 : active.focus();
|
|
161
|
+
}
|
|
162
|
+
function onFocusIn(event) {
|
|
163
|
+
focusInside = true;
|
|
164
|
+
leaving = null;
|
|
165
|
+
var item = toolbarItems(toolbar).find(function (candidate) { return candidate === event.target; });
|
|
166
|
+
if (item === undefined)
|
|
167
|
+
return;
|
|
168
|
+
active = item;
|
|
169
|
+
sync();
|
|
170
|
+
}
|
|
171
|
+
function onFocusOut(event) {
|
|
172
|
+
var next = event.relatedTarget;
|
|
173
|
+
if (next !== null) {
|
|
174
|
+
if (!toolbar.contains(next))
|
|
175
|
+
focusInside = false;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
// Focus going nowhere from a control that is still there is the user
|
|
179
|
+
// leaving. From one being removed or disabled it is not, and sync brings
|
|
180
|
+
// focus back. Chromium sends this focusout while the control is still
|
|
181
|
+
// connected, just before removing it, so the decision waits a microtask.
|
|
182
|
+
// A sync before then still sees focus as inside, which is right for a
|
|
183
|
+
// control being removed and harmless for one that stays.
|
|
184
|
+
leaving = event.target;
|
|
185
|
+
queueMicrotask(settleLeave);
|
|
186
|
+
}
|
|
187
|
+
function onKeyDown(event) {
|
|
188
|
+
if (event.defaultPrevented)
|
|
189
|
+
return;
|
|
190
|
+
var target = event.target;
|
|
191
|
+
var items = toolbarItems(toolbar);
|
|
192
|
+
var current = items.indexOf(target);
|
|
193
|
+
if (current === -1)
|
|
194
|
+
return;
|
|
195
|
+
var next = rovingTarget(event.key, current, items.length, {
|
|
196
|
+
orientation: orientation,
|
|
197
|
+
isRightToLeft: isInRightToLeft(toolbar),
|
|
198
|
+
wraps: true,
|
|
199
|
+
jumpsToEnds: true
|
|
200
|
+
});
|
|
201
|
+
if (next === null)
|
|
202
|
+
return;
|
|
203
|
+
event.preventDefault();
|
|
204
|
+
active = items[next];
|
|
205
|
+
sync();
|
|
206
|
+
active.focus();
|
|
207
|
+
}
|
|
208
|
+
sync();
|
|
209
|
+
toolbar.addEventListener('focusin', onFocusIn);
|
|
210
|
+
toolbar.addEventListener('focusout', onFocusOut);
|
|
211
|
+
toolbar.addEventListener('keydown', onKeyDown);
|
|
212
|
+
var observer = typeof MutationObserver === 'undefined' ? null : new MutationObserver(function (records) {
|
|
213
|
+
if (records.some(touchesControls))
|
|
214
|
+
sync();
|
|
215
|
+
});
|
|
216
|
+
observer === null || observer === void 0 ? void 0 : observer.observe(toolbar, {
|
|
217
|
+
childList: true,
|
|
218
|
+
subtree: true,
|
|
219
|
+
attributes: true,
|
|
220
|
+
attributeFilter: ['disabled', 'inert', 'hidden', 'href', 'type', 'style', 'class']
|
|
221
|
+
});
|
|
222
|
+
return function () {
|
|
223
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
224
|
+
toolbar.removeEventListener('focusin', onFocusIn);
|
|
225
|
+
toolbar.removeEventListener('focusout', onFocusOut);
|
|
226
|
+
toolbar.removeEventListener('keydown', onKeyDown);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Puts an overlay in the browser's top layer, shared by every surface that
|
|
3
|
+
* floats over the page (Popover, Alert, ActionSheet). In the top layer no
|
|
4
|
+
* ancestor's overflow, transform or backdrop-filter clips the overlay, and the
|
|
5
|
+
* one shown last sits above the others, whatever their z-index. Internal.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Shows the element in the top layer as a manual popover, where the browser
|
|
9
|
+
* supports the `popover` attribute. Returns whether it did. Elsewhere the
|
|
10
|
+
* element keeps its own position and z-index.
|
|
11
|
+
*/
|
|
12
|
+
export declare function showInTopLayer(element: HTMLElement): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Puts an overlay in the browser's top layer, shared by every surface that
|
|
3
|
+
* floats over the page (Popover, Alert, ActionSheet). In the top layer no
|
|
4
|
+
* ancestor's overflow, transform or backdrop-filter clips the overlay, and the
|
|
5
|
+
* one shown last sits above the others, whatever their z-index. Internal.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Shows the element in the top layer as a manual popover, where the browser
|
|
9
|
+
* supports the `popover` attribute. Returns whether it did. Elsewhere the
|
|
10
|
+
* element keeps its own position and z-index.
|
|
11
|
+
*/
|
|
12
|
+
export function showInTopLayer(element) {
|
|
13
|
+
if (typeof element.showPopover !== 'function')
|
|
14
|
+
return false;
|
|
15
|
+
element.setAttribute('popover', 'manual');
|
|
16
|
+
element.showPopover();
|
|
17
|
+
return true;
|
|
18
|
+
}
|