glasslikeui 1.9.0 → 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.
Files changed (128) hide show
  1. package/README.md +892 -24
  2. package/dist/actions/adaptiveTone.d.ts +50 -0
  3. package/dist/actions/adaptiveTone.js +569 -0
  4. package/dist/actions/alertLogic.d.ts +67 -0
  5. package/dist/actions/alertLogic.js +123 -0
  6. package/dist/actions/anchorPlacement.d.ts +92 -0
  7. package/dist/actions/anchorPlacement.js +137 -0
  8. package/dist/actions/dragSnap.d.ts +1 -1
  9. package/dist/actions/dragSnapMath.d.ts +70 -0
  10. package/dist/actions/dragSnapMath.js +115 -0
  11. package/dist/actions/glassToneLogic.d.ts +182 -0
  12. package/dist/actions/glassToneLogic.js +513 -0
  13. package/dist/actions/heightTransition.d.ts +32 -0
  14. package/dist/actions/heightTransition.js +64 -0
  15. package/dist/actions/index.d.ts +1 -0
  16. package/dist/actions/index.js +1 -0
  17. package/dist/actions/inertSiblings.js +20 -4
  18. package/dist/actions/menuLogic.d.ts +40 -0
  19. package/dist/actions/menuLogic.js +68 -0
  20. package/dist/actions/modalDialog.d.ts +19 -0
  21. package/dist/actions/modalDialog.js +48 -0
  22. package/dist/actions/popoverLogic.d.ts +25 -0
  23. package/dist/actions/popoverLogic.js +48 -0
  24. package/dist/actions/rovingIndex.d.ts +30 -0
  25. package/dist/actions/rovingIndex.js +49 -0
  26. package/dist/actions/scrollRunTracker.d.ts +36 -0
  27. package/dist/actions/scrollRunTracker.js +77 -0
  28. package/dist/actions/scrollUnder.d.ts +21 -0
  29. package/dist/actions/scrollUnder.js +29 -0
  30. package/dist/actions/segmentedLogic.d.ts +38 -0
  31. package/dist/actions/segmentedLogic.js +59 -0
  32. package/dist/actions/sheetLogic.d.ts +43 -0
  33. package/dist/actions/sheetLogic.js +71 -0
  34. package/dist/actions/sliderLogic.d.ts +29 -0
  35. package/dist/actions/sliderLogic.js +53 -0
  36. package/dist/actions/swipeActions.d.ts +46 -2
  37. package/dist/actions/swipeActions.js +267 -46
  38. package/dist/actions/tabBarMinimize.d.ts +31 -0
  39. package/dist/actions/tabBarMinimize.js +38 -0
  40. package/dist/actions/tabViewLogic.d.ts +47 -0
  41. package/dist/actions/tabViewLogic.js +71 -0
  42. package/dist/actions/toggleKnobLogic.d.ts +57 -0
  43. package/dist/actions/toggleKnobLogic.js +66 -0
  44. package/dist/actions/toolbarFocus.d.ts +44 -0
  45. package/dist/actions/toolbarFocus.js +228 -0
  46. package/dist/actions/topLayer.d.ts +12 -0
  47. package/dist/actions/topLayer.js +18 -0
  48. package/dist/components/dialog/ActionSheet.svelte +457 -0
  49. package/dist/components/dialog/ActionSheet.svelte.d.ts +25 -0
  50. package/dist/components/dialog/Alert.svelte +337 -0
  51. package/dist/components/dialog/Alert.svelte.d.ts +28 -0
  52. package/dist/components/dialog/index.d.ts +6 -0
  53. package/dist/components/dialog/index.js +6 -0
  54. package/dist/components/glass/Glass.svelte +49 -17
  55. package/dist/components/glass/Glass.svelte.d.ts +8 -0
  56. package/dist/components/glass/GlassSection.svelte +9 -1
  57. package/dist/components/glass/LensFilters.svelte +4 -2
  58. package/dist/components/glass/Popover.svelte +379 -0
  59. package/dist/components/glass/Popover.svelte.d.ts +30 -0
  60. package/dist/components/glass/Sheet.svelte +470 -103
  61. package/dist/components/glass/Sheet.svelte.d.ts +55 -7
  62. package/dist/components/glass/index.d.ts +3 -0
  63. package/dist/components/glass/index.js +1 -0
  64. package/dist/components/index.d.ts +2 -0
  65. package/dist/components/index.js +4 -0
  66. package/dist/components/interactive/Badge.svelte +97 -6
  67. package/dist/components/interactive/Badge.svelte.d.ts +13 -2
  68. package/dist/components/interactive/Button.svelte +162 -20
  69. package/dist/components/interactive/Button.svelte.d.ts +14 -1
  70. package/dist/components/interactive/IconButton.svelte +214 -4
  71. package/dist/components/interactive/IconButton.svelte.d.ts +2 -1
  72. package/dist/components/interactive/ProgressView.svelte +306 -0
  73. package/dist/components/interactive/ProgressView.svelte.d.ts +25 -0
  74. package/dist/components/interactive/Segment.d.ts +14 -0
  75. package/dist/components/interactive/Segment.js +1 -0
  76. package/dist/components/interactive/SegmentedControl.svelte +399 -0
  77. package/dist/components/interactive/SegmentedControl.svelte.d.ts +17 -0
  78. package/dist/components/interactive/Slider.svelte +299 -0
  79. package/dist/components/interactive/Slider.svelte.d.ts +23 -0
  80. package/dist/components/interactive/TabView.svelte +573 -41
  81. package/dist/components/interactive/TabView.svelte.d.ts +25 -0
  82. package/dist/components/interactive/Toggle.svelte +287 -16
  83. package/dist/components/interactive/Toggle.svelte.d.ts +12 -0
  84. package/dist/components/interactive/index.d.ts +4 -0
  85. package/dist/components/interactive/index.js +3 -0
  86. package/dist/components/list/List.svelte +41 -17
  87. package/dist/components/list/List.svelte.d.ts +1 -0
  88. package/dist/components/list/ListRow.svelte +208 -47
  89. package/dist/components/list/ListRow.svelte.d.ts +16 -1
  90. package/dist/components/menu/Menu.svelte +51 -27
  91. package/dist/components/menu/Menu.svelte.d.ts +5 -0
  92. package/dist/components/menu/MenuItem.svelte +82 -25
  93. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  94. package/dist/components/menu/MenuSection.svelte +95 -0
  95. package/dist/components/menu/MenuSection.svelte.d.ts +18 -0
  96. package/dist/components/menu/MenuSubmenu.svelte +196 -0
  97. package/dist/components/menu/MenuSubmenu.svelte.d.ts +11 -0
  98. package/dist/components/menu/index.d.ts +4 -1
  99. package/dist/components/menu/index.js +3 -1
  100. package/dist/components/navigation/NavigationBar.svelte +97 -15
  101. package/dist/components/navigation/NavigationBar.svelte.d.ts +6 -0
  102. package/dist/components/toolbar/Toolbar.svelte +43 -0
  103. package/dist/components/toolbar/Toolbar.svelte.d.ts +13 -0
  104. package/dist/components/toolbar/ToolbarItemGroup.svelte +45 -0
  105. package/dist/components/toolbar/ToolbarItemGroup.svelte.d.ts +14 -0
  106. package/dist/components/toolbar/ToolbarSpacer.svelte +36 -0
  107. package/dist/components/toolbar/ToolbarSpacer.svelte.d.ts +12 -0
  108. package/dist/components/toolbar/index.d.ts +7 -0
  109. package/dist/components/toolbar/index.js +7 -0
  110. package/dist/components/typography/Text.svelte +9 -1
  111. package/dist/constants/alertAction.d.ts +19 -0
  112. package/dist/constants/alertAction.js +1 -0
  113. package/dist/constants/badge.d.ts +32 -0
  114. package/dist/constants/badge.js +47 -0
  115. package/dist/constants/buttons.d.ts +45 -0
  116. package/dist/constants/buttons.js +52 -0
  117. package/dist/constants/colors.d.ts +9 -4
  118. package/dist/constants/colors.js +9 -4
  119. package/dist/constants/index.d.ts +3 -0
  120. package/dist/constants/index.js +3 -0
  121. package/dist/constants/progress.d.ts +56 -0
  122. package/dist/constants/progress.js +75 -0
  123. package/dist/constants/variants.d.ts +6 -2
  124. package/dist/constants/variants.js +2 -2
  125. package/dist/styles/glasslikeui.css +135 -1
  126. package/dist/styles/lens.css +21 -19
  127. package/dist/styles/squircle.css +17 -7
  128. package/package.json +1 -1
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Animates elements from the heights they had before a state change to the
3
+ * heights they have after it. CSS cannot transition a height that changes
4
+ * because a child leaves the flow (a TabView label hidden with position
5
+ * absolute when the bar minimises), so the change is played in script with
6
+ * the timing of `--transition-spring`. Internal.
7
+ */
8
+ /** The duration of `--transition-spring`. */
9
+ export declare const HEIGHT_TRANSITION_MS = 400;
10
+ /** The easing of `--transition-spring`. */
11
+ export declare const HEIGHT_TRANSITION_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
12
+ /**
13
+ * True when a change from one height to another should be animated: the
14
+ * element is shown both before and after (taller than the 1px of a visually
15
+ * hidden element, compared unrounded), and the height changed by at least
16
+ * half a pixel.
17
+ */
18
+ export declare function shouldAnimateHeight(from: number, to: number): boolean;
19
+ /**
20
+ * An element's border box height, fractional (offsetHeight rounds to whole
21
+ * pixels, and Firefox and WebKit lay tabs out at heights such as 61.5px, so a
22
+ * rounded start would jump half a pixel).
23
+ */
24
+ export declare function heightOf(el: HTMLElement): number;
25
+ /** Each element's border box height, read before the change. */
26
+ export declare function captureHeights(elements: Iterable<HTMLElement>): Map<HTMLElement, number>;
27
+ /**
28
+ * Plays each captured element from its old height to its current one, and
29
+ * returns the animations. Nothing plays under reduced motion, for an element
30
+ * no longer in the document, or where the browser has no Web Animations.
31
+ */
32
+ export declare function playHeightTransition(before: Map<HTMLElement, number>, reducedMotion: boolean): Animation[];
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Animates elements from the heights they had before a state change to the
3
+ * heights they have after it. CSS cannot transition a height that changes
4
+ * because a child leaves the flow (a TabView label hidden with position
5
+ * absolute when the bar minimises), so the change is played in script with
6
+ * the timing of `--transition-spring`. Internal.
7
+ */
8
+ /** The duration of `--transition-spring`. */
9
+ export var HEIGHT_TRANSITION_MS = 400;
10
+ /** The easing of `--transition-spring`. */
11
+ export var HEIGHT_TRANSITION_EASING = 'cubic-bezier(0.32, 0.72, 0, 1)';
12
+ /**
13
+ * True when a change from one height to another should be animated: the
14
+ * element is shown both before and after (taller than the 1px of a visually
15
+ * hidden element, compared unrounded), and the height changed by at least
16
+ * half a pixel.
17
+ */
18
+ export function shouldAnimateHeight(from, to) {
19
+ return from > 1 && to > 1 && Math.abs(to - from) >= 0.5;
20
+ }
21
+ /**
22
+ * An element's border box height, fractional (offsetHeight rounds to whole
23
+ * pixels, and Firefox and WebKit lay tabs out at heights such as 61.5px, so a
24
+ * rounded start would jump half a pixel).
25
+ */
26
+ export function heightOf(el) {
27
+ return el.getBoundingClientRect().height;
28
+ }
29
+ /** Each element's border box height, read before the change. */
30
+ export function captureHeights(elements) {
31
+ var heights = new Map();
32
+ for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
33
+ var el = elements_1[_i];
34
+ heights.set(el, heightOf(el));
35
+ }
36
+ return heights;
37
+ }
38
+ /**
39
+ * Plays each captured element from its old height to its current one, and
40
+ * returns the animations. Nothing plays under reduced motion, for an element
41
+ * no longer in the document, or where the browser has no Web Animations.
42
+ */
43
+ export function playHeightTransition(before, reducedMotion) {
44
+ if (reducedMotion)
45
+ return [];
46
+ var played = [];
47
+ for (var _i = 0, before_1 = before; _i < before_1.length; _i++) {
48
+ var _a = before_1[_i], el = _a[0], from = _a[1];
49
+ if (!el.isConnected || typeof el.animate !== 'function')
50
+ continue;
51
+ var to = heightOf(el);
52
+ if (!shouldAnimateHeight(from, to))
53
+ continue;
54
+ played.push(el.animate([{ height: "".concat(from, "px") }, { height: "".concat(to, "px") }], {
55
+ duration: HEIGHT_TRANSITION_MS,
56
+ easing: HEIGHT_TRANSITION_EASING,
57
+ // WebKit starts an animation in the next frame, before which it has
58
+ // no effect: without a backwards fill that frame paints the new
59
+ // height, and the animation then snaps back to the old one.
60
+ fill: 'backwards'
61
+ }));
62
+ }
63
+ return played;
64
+ }
@@ -8,3 +8,4 @@ export * from './swipeActions';
8
8
  export * from './refreshable';
9
9
  export * from './inertSiblings';
10
10
  export * from './focusTrap';
11
+ export * from './adaptiveTone';
@@ -8,3 +8,4 @@ export * from './swipeActions';
8
8
  export * from './refreshable';
9
9
  export * from './inertSiblings';
10
10
  export * from './focusTrap';
11
+ export * from './adaptiveTone';
@@ -6,18 +6,30 @@
6
6
  * `body`, are made inert. Ancestors are never touched: a surface mounted inside
7
7
  * page content keeps that content, and so itself, interactive.
8
8
  */
9
+ /**
10
+ * How many open surfaces hold each element inert. Two modals can be open at
11
+ * once and close in either order: an element stays inert until the last
12
+ * surface that made it inert lets go. An element counted here was made inert
13
+ * by this module, so it is not mistaken for a host-set one.
14
+ */
15
+ var holds = new WeakMap();
9
16
  /** Sets `inert` on the siblings of the surface and returns a function that undoes exactly that. */
10
17
  export function inertSiblings(surface) {
18
+ var _a;
11
19
  var body = surface.ownerDocument.body;
12
20
  var added = [];
13
21
  // Walk up, inerting the siblings at each level. Stop once the node is the body.
14
22
  for (var node = surface; node !== body && node.parentElement; node = node.parentElement) {
15
23
  var parent = node.parentElement;
16
- for (var _i = 0, _a = parent.children; _i < _a.length; _i++) {
17
- var sibling = _a[_i];
24
+ for (var _i = 0, _b = parent.children; _i < _b.length; _i++) {
25
+ var sibling = _b[_i];
26
+ if (sibling === node)
27
+ continue;
28
+ var count = (_a = holds.get(sibling)) !== null && _a !== void 0 ? _a : 0;
18
29
  // A host-set inert is the host's: leave it, and leave it in place on restore.
19
- if (sibling === node || sibling.hasAttribute('inert'))
30
+ if (count === 0 && sibling.hasAttribute('inert'))
20
31
  continue;
32
+ holds.set(sibling, count + 1);
21
33
  sibling.setAttribute('inert', '');
22
34
  added.push(sibling);
23
35
  }
@@ -29,7 +41,11 @@ export function inertSiblings(surface) {
29
41
  restored = true;
30
42
  for (var _i = 0, added_1 = added; _i < added_1.length; _i++) {
31
43
  var element = added_1[_i];
32
- element.removeAttribute('inert');
44
+ // A count of 0 reads the same as no entry, so it can stay in the map.
45
+ var left = holds.get(element) - 1;
46
+ holds.set(element, left);
47
+ if (left === 0)
48
+ element.removeAttribute('inert');
33
49
  }
34
50
  };
35
51
  }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The keyboard and activation decisions Menu makes, as plain functions, so
3
+ * mutation testing reaches them (Stryker cannot instrument .svelte files). The
4
+ * menu follows the WAI-ARIA menu pattern. Internal.
5
+ */
6
+ /** Matches every item of a menu: plain items and checkable ones. */
7
+ export declare const MENU_ITEM_SELECTOR = "[role=\"menuitem\"], [role=\"menuitemcheckbox\"]";
8
+ /**
9
+ * The index of the item a key press moves focus to, or `null` when the key is
10
+ * not one the menu moves on. ArrowDown and ArrowUp step through the items and
11
+ * wrap at either end. From no focused item (`index` -1) ArrowDown goes to the
12
+ * first and ArrowUp to the last. Home and End go to the first and last item.
13
+ */
14
+ export declare function menuKeyTarget(key: string, index: number, count: number): number | null;
15
+ /** The attributes of an item that decide what activating it does. */
16
+ export interface MenuItemState {
17
+ /** The item's `aria-disabled`. */
18
+ disabled: string | null;
19
+ /** The item's `aria-haspopup`, set on an item that opens a submenu. */
20
+ haspopup: string | null;
21
+ }
22
+ /**
23
+ * Whether activating an item closes the menu. An item that runs an action
24
+ * closes it, as on iOS. A disabled item does nothing, and an item that opens a
25
+ * submenu keeps the menu open so the submenu can show.
26
+ */
27
+ export declare function activationCloses(item: MenuItemState): boolean;
28
+ /** Reads the MenuItemState of an element. */
29
+ export declare function menuItemState(element: Element): MenuItemState;
30
+ /**
31
+ * Which key opens and which closes a submenu, by text direction. The open key
32
+ * points into the submenu, the close key back out, as the arrow suggests.
33
+ */
34
+ export declare function submenuKeyAction(key: string, rtl?: boolean): 'open' | 'close' | null;
35
+ /** The sizes a menu section lays its items out in, as UIMenu's preferred element size does. */
36
+ export type MenuSectionSize = 'small' | 'medium' | 'large';
37
+ /** Every MenuSectionSize. */
38
+ export declare const MENU_SECTION_SIZES: readonly MenuSectionSize[];
39
+ /** The size in use: the given one when it is known, else `large`, the list layout. */
40
+ export declare function menuSectionSize(size: string | undefined): MenuSectionSize;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The keyboard and activation decisions Menu makes, as plain functions, so
3
+ * mutation testing reaches them (Stryker cannot instrument .svelte files). The
4
+ * menu follows the WAI-ARIA menu pattern. Internal.
5
+ */
6
+ /** Matches every item of a menu: plain items and checkable ones. */
7
+ export var MENU_ITEM_SELECTOR = '[role="menuitem"], [role="menuitemcheckbox"]';
8
+ /**
9
+ * The index of the item a key press moves focus to, or `null` when the key is
10
+ * not one the menu moves on. ArrowDown and ArrowUp step through the items and
11
+ * wrap at either end. From no focused item (`index` -1) ArrowDown goes to the
12
+ * first and ArrowUp to the last. Home and End go to the first and last item.
13
+ */
14
+ export function menuKeyTarget(key, index, count) {
15
+ if (count <= 0)
16
+ return null;
17
+ switch (key) {
18
+ case 'ArrowDown':
19
+ return (index + 1) % count;
20
+ case 'ArrowUp':
21
+ return index <= 0 ? count - 1 : index - 1;
22
+ case 'Home':
23
+ return 0;
24
+ case 'End':
25
+ return count - 1;
26
+ default:
27
+ return null;
28
+ }
29
+ }
30
+ /**
31
+ * Whether activating an item closes the menu. An item that runs an action
32
+ * closes it, as on iOS. A disabled item does nothing, and an item that opens a
33
+ * submenu keeps the menu open so the submenu can show.
34
+ */
35
+ export function activationCloses(item) {
36
+ if (item.disabled === 'true')
37
+ return false;
38
+ return item.haspopup === null || item.haspopup === 'false';
39
+ }
40
+ /** Reads the MenuItemState of an element. */
41
+ export function menuItemState(element) {
42
+ return {
43
+ disabled: element.getAttribute('aria-disabled'),
44
+ haspopup: element.getAttribute('aria-haspopup')
45
+ };
46
+ }
47
+ /**
48
+ * Which key opens and which closes a submenu, by text direction. The open key
49
+ * points into the submenu, the close key back out, as the arrow suggests.
50
+ */
51
+ export function submenuKeyAction(key, rtl) {
52
+ if (rtl === void 0) { rtl = false; }
53
+ var into = rtl ? 'ArrowLeft' : 'ArrowRight';
54
+ var out = rtl ? 'ArrowRight' : 'ArrowLeft';
55
+ if (key === into)
56
+ return 'open';
57
+ if (key === out || key === 'Escape')
58
+ return 'close';
59
+ return null;
60
+ }
61
+ /** Every MenuSectionSize. */
62
+ export var MENU_SECTION_SIZES = ['small', 'medium', 'large'];
63
+ /** The size in use: the given one when it is known, else `large`, the list layout. */
64
+ export function menuSectionSize(size) {
65
+ return MENU_SECTION_SIZES.includes(size)
66
+ ? size
67
+ : 'large';
68
+ }
@@ -0,0 +1,19 @@
1
+ /** What a modal dialog needs from the component that shows it. */
2
+ export interface ModalDialogOptions {
3
+ /** The element to focus first, or null to focus the dialog itself. */
4
+ initialFocus: () => HTMLElement | null;
5
+ /** Runs when Escape is pressed inside the dialog. */
6
+ onEscape: () => void;
7
+ /**
8
+ * The overlay around the dialog (its backdrop), shown in the top layer where
9
+ * the browser supports it, so the dialog opened last is drawn above a
10
+ * Popover or another dialog and no ancestor clips it.
11
+ */
12
+ layer?: HTMLElement | null | undefined;
13
+ }
14
+ /**
15
+ * Starts the modal behaviour on a dialog element and returns the function that
16
+ * ends it. Ending it twice is safe. The opener is recorded before the page goes
17
+ * inert, and focused again only once the page is interactive again.
18
+ */
19
+ export declare function openModalDialog(dialog: HTMLElement, options: ModalDialogOptions): () => void;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The focus and keyboard handling an alert dialog needs while it is on screen,
3
+ * shared by Alert and ActionSheet. It follows the WAI-ARIA dialog pattern:
4
+ * focus moves in, Tab stays inside, the page behind is inert, Escape asks to
5
+ * cancel, and focus goes back to the opener on close. Internal.
6
+ */
7
+ import { inertSiblings } from './inertSiblings';
8
+ import { trapTab } from './focusTrap';
9
+ import { showInTopLayer } from './topLayer';
10
+ /**
11
+ * Starts the modal behaviour on a dialog element and returns the function that
12
+ * ends it. Ending it twice is safe. The opener is recorded before the page goes
13
+ * inert, and focused again only once the page is interactive again.
14
+ */
15
+ export function openModalDialog(dialog, options) {
16
+ var doc = dialog.ownerDocument;
17
+ var opener = doc.activeElement;
18
+ if (options.layer)
19
+ showInTopLayer(options.layer);
20
+ var releaseInert = inertSiblings(dialog);
21
+ var target = options.initialFocus();
22
+ // Leave focus alone if something inside (an autofocus field) already has it.
23
+ if (!dialog.contains(doc.activeElement))
24
+ (target !== null && target !== void 0 ? target : dialog).focus({ preventScroll: true });
25
+ function onKeydown(event) {
26
+ if (event.key === 'Escape') {
27
+ event.preventDefault();
28
+ // A nested dialog handles its own Escape first.
29
+ event.stopPropagation();
30
+ options.onEscape();
31
+ }
32
+ else {
33
+ trapTab(event, dialog);
34
+ }
35
+ }
36
+ dialog.addEventListener('keydown', onKeydown);
37
+ var ended = false;
38
+ return function () {
39
+ if (ended)
40
+ return;
41
+ ended = true;
42
+ dialog.removeEventListener('keydown', onKeydown);
43
+ releaseInert();
44
+ if (opener instanceof HTMLElement && opener.isConnected && opener !== doc.body) {
45
+ opener.focus({ preventScroll: true });
46
+ }
47
+ };
48
+ }
@@ -0,0 +1,25 @@
1
+ /** How a popover shows: anchored to its source, or as a sheet from the bottom edge. */
2
+ export type PopoverPresentation = 'popover' | 'sheet';
3
+ /** What a popover becomes on a compact width, as SwiftUI's presentationCompactAdaptation sets. */
4
+ export type PopoverCompactAdaptation = 'sheet' | 'popover';
5
+ /**
6
+ * How the popover shows at this viewport width. On a compact width it becomes
7
+ * a sheet, as on iPhone, unless `adaptation` asks to keep the popover.
8
+ */
9
+ export declare function popoverPresentation(viewportWidth: number, adaptation?: PopoverCompactAdaptation): PopoverPresentation;
10
+ /**
11
+ * What a key press does while the popover is open: Escape closes it, and Tab
12
+ * is kept inside the sheet, which is modal. An anchored popover is not modal,
13
+ * so Tab moves on as usual, and Escape closes it only when focus is in the
14
+ * panel or on its source (`focusWithin`): Escape elsewhere on the page belongs
15
+ * to whatever has focus there. A closed popover ignores every key, and so
16
+ * does an open one when something inside it, such as a menu or a nested
17
+ * popover, has already handled the key (`handled`, the event's
18
+ * defaultPrevented).
19
+ */
20
+ export declare function popoverKeyAction(key: string, open: boolean, presentation: PopoverPresentation, handled?: boolean, focusWithin?: boolean): 'close' | 'trap' | null;
21
+ /**
22
+ * Whether a press outside closes the popover: a press on neither the panel nor
23
+ * its source. A press on the source is left to the source, which toggles it.
24
+ */
25
+ export declare function isOutsidePress(target: Node | null, panel: Element | null | undefined, source: Element | null | undefined): boolean;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The decisions Popover makes, as plain functions, so mutation testing reaches
3
+ * them (Stryker cannot instrument .svelte files). Internal.
4
+ */
5
+ import { isCompactWidth } from './anchorPlacement';
6
+ /**
7
+ * How the popover shows at this viewport width. On a compact width it becomes
8
+ * a sheet, as on iPhone, unless `adaptation` asks to keep the popover.
9
+ */
10
+ export function popoverPresentation(viewportWidth, adaptation) {
11
+ if (adaptation === void 0) { adaptation = 'sheet'; }
12
+ return adaptation === 'sheet' && isCompactWidth(viewportWidth) ? 'sheet' : 'popover';
13
+ }
14
+ /**
15
+ * What a key press does while the popover is open: Escape closes it, and Tab
16
+ * is kept inside the sheet, which is modal. An anchored popover is not modal,
17
+ * so Tab moves on as usual, and Escape closes it only when focus is in the
18
+ * panel or on its source (`focusWithin`): Escape elsewhere on the page belongs
19
+ * to whatever has focus there. A closed popover ignores every key, and so
20
+ * does an open one when something inside it, such as a menu or a nested
21
+ * popover, has already handled the key (`handled`, the event's
22
+ * defaultPrevented).
23
+ */
24
+ export function popoverKeyAction(key, open, presentation, handled, focusWithin) {
25
+ if (handled === void 0) { handled = false; }
26
+ if (focusWithin === void 0) { focusWithin = true; }
27
+ if (!open || handled)
28
+ return null;
29
+ var modal = presentation === 'sheet';
30
+ if (key === 'Escape')
31
+ return modal || focusWithin ? 'close' : null;
32
+ if (key === 'Tab' && modal)
33
+ return 'trap';
34
+ return null;
35
+ }
36
+ /**
37
+ * Whether a press outside closes the popover: a press on neither the panel nor
38
+ * its source. A press on the source is left to the source, which toggles it.
39
+ */
40
+ export function isOutsidePress(target, panel, source) {
41
+ if (!target)
42
+ return false;
43
+ if (panel === null || panel === void 0 ? void 0 : panel.contains(target))
44
+ return false;
45
+ if (source === null || source === void 0 ? void 0 : source.contains(target))
46
+ return false;
47
+ return true;
48
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Arrow key movement inside a composite widget with one tab stop, such as a
3
+ * radio group or a toolbar (WAI-ARIA APG roving tabindex). The component
4
+ * passes in the key and where focus is, and moves focus to the index this
5
+ * returns. Internal.
6
+ */
7
+ /** Which arrow keys move between items. 'both' takes all four. */
8
+ export type RovingOrientation = 'horizontal' | 'vertical' | 'both';
9
+ /** How a widget moves its focus between items. */
10
+ export interface RovingOptions {
11
+ /** The arrow keys the widget answers to. */
12
+ orientation: RovingOrientation;
13
+ /** Whether the layout runs right to left, which swaps Left and Right. */
14
+ isRightToLeft: boolean;
15
+ /** Whether moving past the last item lands on the first, and back. */
16
+ wraps: boolean;
17
+ /** Whether Home and End jump to the first and last item. */
18
+ jumpsToEnds: boolean;
19
+ }
20
+ /**
21
+ * The index focus moves to when `key` is pressed on the item at `current`, of
22
+ * `count` items. Null when the key does nothing here, so the component leaves
23
+ * the event alone. A `current` outside the items counts as before the first.
24
+ */
25
+ export declare function rovingTarget(key: string, current: number, count: number, options: RovingOptions): number | null;
26
+ /**
27
+ * Whether `element` lays out right to left. Read from the computed style, so a
28
+ * `dir` attribute, `dir="auto"` and a CSS `direction` all count.
29
+ */
30
+ export declare function isInRightToLeft(element: Element): boolean;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Arrow key movement inside a composite widget with one tab stop, such as a
3
+ * radio group or a toolbar (WAI-ARIA APG roving tabindex). The component
4
+ * passes in the key and where focus is, and moves focus to the index this
5
+ * returns. Internal.
6
+ */
7
+ /** The step an arrow key takes, before right to left is applied. */
8
+ var STEPS = {
9
+ ArrowLeft: { step: -1, axis: 'horizontal' },
10
+ ArrowRight: { step: 1, axis: 'horizontal' },
11
+ ArrowUp: { step: -1, axis: 'vertical' },
12
+ ArrowDown: { step: 1, axis: 'vertical' }
13
+ };
14
+ /**
15
+ * The index focus moves to when `key` is pressed on the item at `current`, of
16
+ * `count` items. Null when the key does nothing here, so the component leaves
17
+ * the event alone. A `current` outside the items counts as before the first.
18
+ */
19
+ export function rovingTarget(key, current, count, options) {
20
+ if (count < 1)
21
+ return null;
22
+ var last = count - 1;
23
+ if (options.jumpsToEnds && key === 'Home')
24
+ return 0;
25
+ if (options.jumpsToEnds && key === 'End')
26
+ return last;
27
+ var arrow = STEPS[key];
28
+ if (!arrow)
29
+ return null;
30
+ if (options.orientation !== 'both' && options.orientation !== arrow.axis)
31
+ return null;
32
+ var flipped = arrow.axis === 'horizontal' && options.isRightToLeft;
33
+ var step = flipped ? -arrow.step : arrow.step;
34
+ if (current < 0 || current > last)
35
+ return step > 0 ? 0 : last;
36
+ var next = current + step;
37
+ if (next < 0)
38
+ return options.wraps ? last : 0;
39
+ if (next > last)
40
+ return options.wraps ? 0 : last;
41
+ return next;
42
+ }
43
+ /**
44
+ * Whether `element` lays out right to left. Read from the computed style, so a
45
+ * `dir` attribute, `dir="auto"` and a CSS `direction` all count.
46
+ */
47
+ export function isInRightToLeft(element) {
48
+ return getComputedStyle(element).direction === 'rtl';
49
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The scroll runs a minimising tab bar keeps, one per scroll source, so one
3
+ * source's position is never measured against another's. Kept out of the
4
+ * component so mutation testing reaches it. Internal.
5
+ */
6
+ import { type TabBarMinimizeBehavior } from './tabBarMinimize';
7
+ /**
8
+ * Scrolls that never move the bar: text areas, and anything inside a dialog
9
+ * or popover drawn over the page, such as a Sheet, Alert or Popover. On iOS
10
+ * those scroll on their own and leave the tab bar as it was.
11
+ */
12
+ export declare const IGNORED_SCROLL_SOURCES = "textarea, dialog, [role=\"dialog\"], [role=\"alertdialog\"], [aria-modal=\"true\"]";
13
+ /** True when a scroll in this element should not move the tab bar (see IGNORED_SCROLL_SOURCES). */
14
+ export declare function isIgnoredScrollSource(element: Element): boolean;
15
+ /**
16
+ * Scroll runs by source. An element source that has left the document is
17
+ * dropped on the next scroll, so content that came and went (a sheet's body,
18
+ * a popover list) is not kept alive.
19
+ */
20
+ export declare class ScrollRunTracker {
21
+ private readonly runs;
22
+ /** How many sources are tracked. */
23
+ get size(): number;
24
+ /** Forgets every source. */
25
+ clear(): void;
26
+ /** Starts a source's run at a position. */
27
+ start(source: EventTarget, y: number): void;
28
+ /**
29
+ * Records that a source scrolled to `y` and returns whether the bar is
30
+ * minimised after it. A source seen for the first time starts its run there.
31
+ */
32
+ step(behavior: TabBarMinimizeBehavior, minimized: boolean, source: EventTarget, y: number): boolean;
33
+ /** Starts every run again where it stands, so a whole new run is needed to change the bar. */
34
+ restart(): void;
35
+ private prune;
36
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The scroll runs a minimising tab bar keeps, one per scroll source, so one
3
+ * source's position is never measured against another's. Kept out of the
4
+ * component so mutation testing reaches it. Internal.
5
+ */
6
+ import { minimizeStep, scrollRunAt } from './tabBarMinimize';
7
+ /**
8
+ * Scrolls that never move the bar: text areas, and anything inside a dialog
9
+ * or popover drawn over the page, such as a Sheet, Alert or Popover. On iOS
10
+ * those scroll on their own and leave the tab bar as it was.
11
+ */
12
+ export var IGNORED_SCROLL_SOURCES = 'textarea, dialog, [role="dialog"], [role="alertdialog"], [aria-modal="true"]';
13
+ /** True when a scroll in this element should not move the tab bar (see IGNORED_SCROLL_SOURCES). */
14
+ export function isIgnoredScrollSource(element) {
15
+ if (element.closest(IGNORED_SCROLL_SOURCES))
16
+ return true;
17
+ try {
18
+ return element.closest(':popover-open') !== null;
19
+ }
20
+ catch (_a) {
21
+ // An engine without the :popover-open selector has no open popovers.
22
+ return false;
23
+ }
24
+ }
25
+ /**
26
+ * Scroll runs by source. An element source that has left the document is
27
+ * dropped on the next scroll, so content that came and went (a sheet's body,
28
+ * a popover list) is not kept alive.
29
+ */
30
+ var ScrollRunTracker = /** @class */ (function () {
31
+ function ScrollRunTracker() {
32
+ this.runs = new Map();
33
+ }
34
+ Object.defineProperty(ScrollRunTracker.prototype, "size", {
35
+ /** How many sources are tracked. */
36
+ get: function () {
37
+ return this.runs.size;
38
+ },
39
+ enumerable: false,
40
+ configurable: true
41
+ });
42
+ /** Forgets every source. */
43
+ ScrollRunTracker.prototype.clear = function () {
44
+ this.runs.clear();
45
+ };
46
+ /** Starts a source's run at a position. */
47
+ ScrollRunTracker.prototype.start = function (source, y) {
48
+ this.runs.set(source, scrollRunAt(y));
49
+ };
50
+ /**
51
+ * Records that a source scrolled to `y` and returns whether the bar is
52
+ * minimised after it. A source seen for the first time starts its run there.
53
+ */
54
+ ScrollRunTracker.prototype.step = function (behavior, minimized, source, y) {
55
+ var _a;
56
+ this.prune();
57
+ var step = minimizeStep(behavior, minimized, (_a = this.runs.get(source)) !== null && _a !== void 0 ? _a : scrollRunAt(y), y);
58
+ this.runs.set(source, step.run);
59
+ return step.minimized;
60
+ };
61
+ /** Starts every run again where it stands, so a whole new run is needed to change the bar. */
62
+ ScrollRunTracker.prototype.restart = function () {
63
+ for (var _i = 0, _a = this.runs; _i < _a.length; _i++) {
64
+ var _b = _a[_i], source = _b[0], run = _b[1];
65
+ this.runs.set(source, scrollRunAt(run.last));
66
+ }
67
+ };
68
+ ScrollRunTracker.prototype.prune = function () {
69
+ for (var _i = 0, _a = this.runs.keys(); _i < _a.length; _i++) {
70
+ var source = _a[_i];
71
+ if (source instanceof Node && !source.isConnected)
72
+ this.runs.delete(source);
73
+ }
74
+ };
75
+ return ScrollRunTracker;
76
+ }());
77
+ export { ScrollRunTracker };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Whether page content has scrolled under top chrome, such as the
3
+ * NavigationBar, which shows its scroll edge effect only then. Internal: not
4
+ * exported from the package.
5
+ */
6
+ /** The part of `window` the watcher reads: a scroll position and its events. */
7
+ export interface ScrollUnderTarget {
8
+ readonly scrollY: number;
9
+ addEventListener(type: 'scroll', listener: () => void, options: AddEventListenerOptions): void;
10
+ removeEventListener(type: 'scroll', listener: () => void): void;
11
+ }
12
+ /**
13
+ * True once the page has moved down from its top. A negative position (the
14
+ * rubber band past the top in Safari) and a missing one count as the top.
15
+ */
16
+ export declare function isScrolledUnder(scrollY: number): boolean;
17
+ /**
18
+ * Calls `onChange` with the current answer, then again each time it changes as
19
+ * `target` scrolls. Returns a function that stops listening.
20
+ */
21
+ export declare function watchScrollUnder(target: ScrollUnderTarget, onChange: (under: boolean) => void): () => void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Whether page content has scrolled under top chrome, such as the
3
+ * NavigationBar, which shows its scroll edge effect only then. Internal: not
4
+ * exported from the package.
5
+ */
6
+ /**
7
+ * True once the page has moved down from its top. A negative position (the
8
+ * rubber band past the top in Safari) and a missing one count as the top.
9
+ */
10
+ export function isScrolledUnder(scrollY) {
11
+ return scrollY > 0;
12
+ }
13
+ /**
14
+ * Calls `onChange` with the current answer, then again each time it changes as
15
+ * `target` scrolls. Returns a function that stops listening.
16
+ */
17
+ export function watchScrollUnder(target, onChange) {
18
+ var under = isScrolledUnder(target.scrollY);
19
+ onChange(under);
20
+ var onScroll = function () {
21
+ var next = isScrolledUnder(target.scrollY);
22
+ if (next === under)
23
+ return;
24
+ under = next;
25
+ onChange(next);
26
+ };
27
+ target.addEventListener('scroll', onScroll, { passive: true });
28
+ return function () { return target.removeEventListener('scroll', onScroll); };
29
+ }