@m3e/core 1.0.0-rc.1 → 1.0.0-rc.3

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 (179) hide show
  1. package/README.md +1 -2
  2. package/dist/a11y.js +6 -18
  3. package/dist/a11y.js.map +1 -1
  4. package/dist/a11y.min.js +5 -5
  5. package/dist/a11y.min.js.map +1 -1
  6. package/dist/css-custom-data.json +20 -0
  7. package/dist/custom-elements.json +3605 -3375
  8. package/dist/html-custom-data.json +36 -6
  9. package/dist/index.js +417 -33
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.min.js +95 -84
  12. package/dist/index.min.js.map +1 -1
  13. package/dist/src/a11y/FocusTrapElement.d.ts +1 -1
  14. package/dist/src/a11y/FocusTrapElement.d.ts.map +1 -1
  15. package/dist/src/shared/controllers/PressedController.d.ts +2 -0
  16. package/dist/src/shared/controllers/PressedController.d.ts.map +1 -1
  17. package/dist/src/shared/mixins/AttachInternals.d.ts.map +1 -1
  18. package/dist/src/shared/mixins/Checked.d.ts.map +1 -1
  19. package/dist/src/shared/mixins/CheckedIndeterminate.d.ts.map +1 -1
  20. package/dist/src/shared/mixins/ConstraintValidation.d.ts.map +1 -1
  21. package/dist/src/shared/mixins/Dirty.d.ts.map +1 -1
  22. package/dist/src/shared/mixins/Disabled.d.ts.map +1 -1
  23. package/dist/src/shared/mixins/DisabledInteractive.d.ts.map +1 -1
  24. package/dist/src/shared/mixins/EventAttribute.d.ts.map +1 -1
  25. package/dist/src/shared/mixins/Focusable.d.ts.map +1 -1
  26. package/dist/src/shared/mixins/FormAssociated.d.ts.map +1 -1
  27. package/dist/src/shared/mixins/FormSubmitter.d.ts +4 -1
  28. package/dist/src/shared/mixins/FormSubmitter.d.ts.map +1 -1
  29. package/dist/src/shared/mixins/HtmlFor.d.ts.map +1 -1
  30. package/dist/src/shared/mixins/KeyboardClick.d.ts.map +1 -1
  31. package/dist/src/shared/mixins/Labelled.d.ts.map +1 -1
  32. package/dist/src/shared/mixins/LinkButton.d.ts +13 -3
  33. package/dist/src/shared/mixins/LinkButton.d.ts.map +1 -1
  34. package/dist/src/shared/mixins/ReadOnly.d.ts.map +1 -1
  35. package/dist/src/shared/mixins/Required.d.ts.map +1 -1
  36. package/dist/src/shared/mixins/RequiredConstraintValidation.d.ts.map +1 -1
  37. package/dist/src/shared/mixins/Role.d.ts.map +1 -1
  38. package/dist/src/shared/mixins/Selected.d.ts.map +1 -1
  39. package/dist/src/shared/mixins/Touched.d.ts.map +1 -1
  40. package/dist/src/shared/mixins/Vertical.d.ts.map +1 -1
  41. package/dist/src/shared/primitives/CollapsibleElement.d.ts +1 -1
  42. package/dist/src/shared/primitives/CollapsibleElement.d.ts.map +1 -1
  43. package/dist/src/shared/primitives/ElevationElement.d.ts +0 -1
  44. package/dist/src/shared/primitives/ElevationElement.d.ts.map +1 -1
  45. package/dist/src/shared/primitives/FocusRingElement.d.ts +0 -1
  46. package/dist/src/shared/primitives/FocusRingElement.d.ts.map +1 -1
  47. package/dist/src/shared/primitives/PseudoCheckboxElement.d.ts +0 -1
  48. package/dist/src/shared/primitives/PseudoCheckboxElement.d.ts.map +1 -1
  49. package/dist/src/shared/primitives/PseudoRadioElement.d.ts +0 -1
  50. package/dist/src/shared/primitives/PseudoRadioElement.d.ts.map +1 -1
  51. package/dist/src/shared/primitives/RippleElement.d.ts +0 -1
  52. package/dist/src/shared/primitives/RippleElement.d.ts.map +1 -1
  53. package/dist/src/shared/primitives/ScrollContainerElement.d.ts +1 -4
  54. package/dist/src/shared/primitives/ScrollContainerElement.d.ts.map +1 -1
  55. package/dist/src/shared/primitives/SlideElement.d.ts +1 -3
  56. package/dist/src/shared/primitives/SlideElement.d.ts.map +1 -1
  57. package/dist/src/shared/primitives/StateLayerElement.d.ts +0 -1
  58. package/dist/src/shared/primitives/StateLayerElement.d.ts.map +1 -1
  59. package/dist/src/shared/primitives/TextHighlightElement.d.ts +81 -0
  60. package/dist/src/shared/primitives/TextHighlightElement.d.ts.map +1 -0
  61. package/dist/src/shared/primitives/TextOverflowElement.d.ts +0 -1
  62. package/dist/src/shared/primitives/TextOverflowElement.d.ts.map +1 -1
  63. package/dist/src/shared/primitives/index.d.ts +1 -0
  64. package/dist/src/shared/primitives/index.d.ts.map +1 -1
  65. package/dist/src/shared/utils/scrollIntoViewIfNeeded.d.ts +2 -2
  66. package/dist/src/shared/utils/scrollIntoViewIfNeeded.d.ts.map +1 -1
  67. package/package.json +1 -1
  68. package/cem.config.mjs +0 -16
  69. package/demo/index.html +0 -58
  70. package/eslint.config.mjs +0 -21
  71. package/rollup.config.js +0 -132
  72. package/src/a11y/AriaDescriber.ts +0 -130
  73. package/src/a11y/FocusTrapElement.ts +0 -136
  74. package/src/a11y/InteractivityChecker.ts +0 -62
  75. package/src/a11y/LiveAnnouncer.ts +0 -143
  76. package/src/a11y/aria-reference.ts +0 -51
  77. package/src/a11y/index.ts +0 -8
  78. package/src/a11y/keycodes/KeyCode.ts +0 -128
  79. package/src/a11y/keycodes/ModifierKeys.ts +0 -5
  80. package/src/a11y/keycodes/getKeyCode.ts +0 -8
  81. package/src/a11y/keycodes/hasModifierKey.ts +0 -11
  82. package/src/a11y/keycodes/index.ts +0 -5
  83. package/src/a11y/keycodes/isModifierAllowed.ts +0 -12
  84. package/src/a11y/list-key/FocusKeyManager.ts +0 -25
  85. package/src/a11y/list-key/ListKeyManager.ts +0 -350
  86. package/src/a11y/list-key/ListManager.ts +0 -66
  87. package/src/a11y/list-key/RadioKeyManager.ts +0 -49
  88. package/src/a11y/list-key/RovingTabIndexManager.ts +0 -56
  89. package/src/a11y/list-key/SelectionManager.ts +0 -132
  90. package/src/a11y/list-key/Typeahead.ts +0 -131
  91. package/src/a11y/list-key/index.ts +0 -7
  92. package/src/a11y/visuallyHide.ts +0 -18
  93. package/src/anchoring/AnchorOptions.ts +0 -19
  94. package/src/anchoring/AnchorPosition.ts +0 -14
  95. package/src/anchoring/index.ts +0 -3
  96. package/src/anchoring/positionAnchor.ts +0 -53
  97. package/src/bidi/Directionality.ts +0 -85
  98. package/src/bidi/index.ts +0 -1
  99. package/src/index.ts +0 -1
  100. package/src/layout/Breakpoint.ts +0 -26
  101. package/src/layout/BreakpointObserver.ts +0 -44
  102. package/src/layout/index.ts +0 -2
  103. package/src/platform/Platform.ts +0 -67
  104. package/src/platform/index.ts +0 -1
  105. package/src/shared/controllers/FocusController.ts +0 -60
  106. package/src/shared/controllers/HoverController.ts +0 -140
  107. package/src/shared/controllers/IntersectionController.ts +0 -81
  108. package/src/shared/controllers/LongPressController.ts +0 -87
  109. package/src/shared/controllers/MonitorControllerBase.ts +0 -99
  110. package/src/shared/controllers/MutationController.ts +0 -89
  111. package/src/shared/controllers/PressedController.ts +0 -137
  112. package/src/shared/controllers/ResizeController.ts +0 -83
  113. package/src/shared/controllers/ScrollController.ts +0 -100
  114. package/src/shared/controllers/index.ts +0 -8
  115. package/src/shared/decorators/debounce.ts +0 -19
  116. package/src/shared/decorators/index.ts +0 -1
  117. package/src/shared/directives/index.ts +0 -1
  118. package/src/shared/directives/safeStyleMap.ts +0 -108
  119. package/src/shared/index.ts +0 -7
  120. package/src/shared/mixins/AttachInternals.ts +0 -48
  121. package/src/shared/mixins/Checked.ts +0 -50
  122. package/src/shared/mixins/CheckedIndeterminate.ts +0 -47
  123. package/src/shared/mixins/CheckedOrSelected.ts +0 -36
  124. package/src/shared/mixins/ConstraintValidation.ts +0 -213
  125. package/src/shared/mixins/Constructor.ts +0 -2
  126. package/src/shared/mixins/Dirty.ts +0 -71
  127. package/src/shared/mixins/Disabled.ts +0 -49
  128. package/src/shared/mixins/DisabledInteractive.ts +0 -78
  129. package/src/shared/mixins/EventAttribute.ts +0 -25
  130. package/src/shared/mixins/Focusable.ts +0 -52
  131. package/src/shared/mixins/FormAssociated.ts +0 -152
  132. package/src/shared/mixins/FormSubmitter.ts +0 -123
  133. package/src/shared/mixins/HtmlFor.ts +0 -89
  134. package/src/shared/mixins/KeyboardClick.ts +0 -46
  135. package/src/shared/mixins/Labelled.ts +0 -88
  136. package/src/shared/mixins/LinkButton.ts +0 -169
  137. package/src/shared/mixins/ReadOnly.ts +0 -48
  138. package/src/shared/mixins/Required.ts +0 -50
  139. package/src/shared/mixins/RequiredConstraintValidation.ts +0 -45
  140. package/src/shared/mixins/Role.ts +0 -134
  141. package/src/shared/mixins/Selected.ts +0 -50
  142. package/src/shared/mixins/Touched.ts +0 -71
  143. package/src/shared/mixins/Vertical.ts +0 -44
  144. package/src/shared/mixins/hasKeys.ts +0 -10
  145. package/src/shared/mixins/index.ts +0 -24
  146. package/src/shared/primitives/CollapsibleElement.ts +0 -227
  147. package/src/shared/primitives/ElevationElement.ts +0 -254
  148. package/src/shared/primitives/ElevationLevel.ts +0 -2
  149. package/src/shared/primitives/ElevationToken.ts +0 -18
  150. package/src/shared/primitives/FocusRingElement.ts +0 -199
  151. package/src/shared/primitives/FocusRingToken.ts +0 -24
  152. package/src/shared/primitives/PseudoCheckboxElement.ts +0 -116
  153. package/src/shared/primitives/PseudoRadioElement.ts +0 -83
  154. package/src/shared/primitives/RippleElement.ts +0 -289
  155. package/src/shared/primitives/RippleToken.ts +0 -15
  156. package/src/shared/primitives/ScrollContainerElement.ts +0 -151
  157. package/src/shared/primitives/ScrollDividers.ts +0 -2
  158. package/src/shared/primitives/SlideElement.ts +0 -128
  159. package/src/shared/primitives/StateLayerElement.ts +0 -191
  160. package/src/shared/primitives/StateLayerToken.ts +0 -16
  161. package/src/shared/primitives/TextOverflowElement.ts +0 -60
  162. package/src/shared/primitives/index.ts +0 -12
  163. package/src/shared/tokens/ColorToken.ts +0 -142
  164. package/src/shared/tokens/DensityToken.ts +0 -23
  165. package/src/shared/tokens/DesignToken.ts +0 -35
  166. package/src/shared/tokens/ElevationToken.ts +0 -115
  167. package/src/shared/tokens/MotionToken.ts +0 -107
  168. package/src/shared/tokens/ScrollbarToken.ts +0 -13
  169. package/src/shared/tokens/ShapeToken.ts +0 -138
  170. package/src/shared/tokens/StateToken.ts +0 -13
  171. package/src/shared/tokens/TypescaleToken.ts +0 -230
  172. package/src/shared/tokens/index.ts +0 -1
  173. package/src/shared/utils/getTextContent.ts +0 -31
  174. package/src/shared/utils/guid.ts +0 -11
  175. package/src/shared/utils/hasAssignedNodes.ts +0 -8
  176. package/src/shared/utils/index.ts +0 -5
  177. package/src/shared/utils/prefersReducedMotion.ts +0 -9
  178. package/src/shared/utils/scrollIntoViewIfNeeded.ts +0 -18
  179. package/tsconfig.json +0 -9
@@ -1,49 +0,0 @@
1
- import { LitElement } from "lit";
2
-
3
- import { CheckedOrSelectedMixin, isCheckedOrSelected } from "../../shared/mixins/CheckedOrSelected";
4
- import { DisabledMixin } from "../../shared/mixins/Disabled";
5
-
6
- import { RovingTabIndexManager } from "./RovingTabIndexManager";
7
-
8
- /**
9
- * Utility for managing keyboard events for selectable lists whose items behave like a radio.
10
- * @template T The type of managed item.
11
- */
12
- export class RadioKeyManager<
13
- T extends LitElement & DisabledMixin & CheckedOrSelectedMixin
14
- > extends RovingTabIndexManager<T> {
15
- /** @private */ #disabled = false;
16
-
17
- /** A value indicating whether managed items are disabled. */
18
- get disabled(): boolean {
19
- return this.#disabled;
20
- }
21
- set disabled(value: boolean) {
22
- this.#disabled = value;
23
- this.items.forEach((x) => (x.disabled = value));
24
- }
25
-
26
- /** @inheritdoc */
27
- override setItems(items: T[]): { added: readonly T[]; removed: readonly T[] } {
28
- if (this.disabled) {
29
- items.forEach((x) => (x.disabled = true));
30
- }
31
-
32
- const { added, removed } = super.setItems(items);
33
-
34
- if (added.length > 0 || removed.length > 0) {
35
- if (!this.activeItem) {
36
- this.updateActiveItem(added.find((x) => !this.skipPredicate(x)) ?? null);
37
- }
38
-
39
- if (this.activeItem && (this.activeItem.disabled || !isCheckedOrSelected(this.activeItem))) {
40
- const checked = added.find((x) => !this.skipPredicate(x) && isCheckedOrSelected(x));
41
- if (checked) {
42
- this.updateActiveItem(checked);
43
- }
44
- }
45
- }
46
-
47
- return { added, removed };
48
- }
49
- }
@@ -1,56 +0,0 @@
1
- import { FocusKeyManager } from "./FocusKeyManager";
2
-
3
- /**
4
- * Utility for managing keyboard events and a roving tab index for selectable lists whose items directly receive focus.
5
- * @template T The type of managed item.
6
- */
7
- export class RovingTabIndexManager<T extends HTMLElement> extends FocusKeyManager<T> {
8
- /** @private */ #disableRovingTabIndex = false;
9
-
10
- /** @inheritdoc */
11
- override updateActiveItem(item: T | null | undefined): void {
12
- super.updateActiveItem(item);
13
-
14
- if (!this.#disableRovingTabIndex) {
15
- item?.setAttribute("tabindex", "0");
16
- for (const other of this.items) {
17
- if (other !== item && other.hasAttribute("tabindex")) {
18
- other.setAttribute("tabindex", "-1");
19
- }
20
- }
21
- }
22
- }
23
-
24
- /** @inheritdoc */
25
- override setItems(items: T[]): { added: readonly T[]; removed: readonly T[] } {
26
- const result = super.setItems(items);
27
-
28
- if (!this.#disableRovingTabIndex) {
29
- for (const added of result.added) {
30
- if (added !== this.activeItem && !this.skipPredicate(added)) {
31
- added.setAttribute("tabindex", "-1");
32
- }
33
- }
34
- }
35
-
36
- return result;
37
- }
38
-
39
- /**
40
- * Configures whether roving tab index is disabled.
41
- * @param {boolean} [disabled=true] Whether the roving tab index is disabled.
42
- * @returns {RovingTabIndexManager<T>} The configured roving tab index manager.
43
- */
44
- disableRovingTabIndex(disabled: boolean = true): this {
45
- if (disabled !== this.#disableRovingTabIndex) {
46
- this.#disableRovingTabIndex = disabled;
47
- for (const item of this.items) {
48
- if (!this.skipPredicate(item)) {
49
- item?.setAttribute("tabindex", this.#disableRovingTabIndex || item === this.activeItem ? "0" : "-1");
50
- }
51
- }
52
- }
53
-
54
- return this;
55
- }
56
- }
@@ -1,132 +0,0 @@
1
- import { LitElement } from "lit";
2
-
3
- import { CheckedOrSelectedMixin, checkOrSelect, isCheckedOrSelected } from "../../shared/mixins/CheckedOrSelected";
4
- import { DisabledMixin } from "../../shared/mixins/Disabled";
5
-
6
- import { RadioKeyManager } from "./RadioKeyManager";
7
-
8
- /** A symbol through which to access an element's selection manager. */
9
- export const selectionManager = Symbol("selectionManager");
10
-
11
- /**
12
- * Utility for managing keyboard events for selectable lists where one or more items can be selected.
13
- * @template T The type of managed item.
14
- */
15
- export class SelectionManager<
16
- T extends LitElement & DisabledMixin & CheckedOrSelectedMixin
17
- > extends RadioKeyManager<T> {
18
- /** @private */ #onSelectedItemsChangeCallback?: () => void;
19
- /** @private */ #selectedItems = new Array<T>();
20
- /** @private */ #multi = false;
21
-
22
- /** A value indicating whether multiple items can be selected. */
23
- get multi(): boolean {
24
- return this.#multi;
25
- }
26
- set multi(value: boolean) {
27
- this.#multi = value;
28
- this.#enforceSingleSelect(true);
29
- }
30
-
31
- /** The selected items. */
32
- get selectedItems(): readonly T[] {
33
- return this.#selectedItems;
34
- }
35
-
36
- /**
37
- * Selects or deselects the item based on the item's checked or selected state.
38
- * @param {T} item The item whose selection state has changed.
39
- */
40
- notifySelectionChange(item: T): void {
41
- if (this.items.includes(item)) {
42
- if (isCheckedOrSelected(item)) {
43
- this.select(item);
44
- } else {
45
- this.deselect(item);
46
- }
47
- }
48
- }
49
-
50
- /**
51
- * Deselects the specified item.
52
- * @param {T} item The item to deselect.
53
- */
54
- deselect(item: T): void {
55
- if (this.items.includes(item)) {
56
- if (isCheckedOrSelected(item)) {
57
- checkOrSelect(item, false);
58
- }
59
-
60
- const index = this.#selectedItems.indexOf(item);
61
- if (index >= 0) {
62
- this.#selectedItems.splice(index, 1);
63
- this.#onSelectedItemsChangeCallback?.();
64
- }
65
- }
66
- }
67
-
68
- /**
69
- * Updates the selected item.
70
- * @param {T | null | undefined} item The selected item.
71
- * @param {boolean} [activate=true] A value indicating whether to activate the item.
72
- */
73
- select(item: T | null | undefined, activate: boolean = true): void {
74
- if (!item || this.items.includes(item)) {
75
- if (!this.multi) {
76
- for (const selected of this.#selectedItems) {
77
- if (selected !== item) {
78
- checkOrSelect(selected, false);
79
- }
80
- }
81
- this.#selectedItems.length = 0;
82
- }
83
-
84
- if (item) {
85
- this.#selectedItems.push(item);
86
- if (!isCheckedOrSelected(item)) {
87
- checkOrSelect(item, true);
88
- }
89
- }
90
-
91
- if (activate) {
92
- this.updateActiveItem(item);
93
- }
94
-
95
- this.#onSelectedItemsChangeCallback?.();
96
- }
97
- }
98
-
99
- /** @inheritdoc */
100
- override setItems(items: T[]): { added: readonly T[]; removed: readonly T[] } {
101
- const { added, removed } = super.setItems(items);
102
-
103
- this.#selectedItems = this.#selectedItems.filter((x) => !removed.includes(x));
104
- this.#selectedItems.push(...added.filter((x) => isCheckedOrSelected(x)));
105
- this.#enforceSingleSelect();
106
- this.#onSelectedItemsChangeCallback?.();
107
- return { added, removed };
108
- }
109
-
110
- /**
111
- * Configures the selection manager with a callback invoked when selected items change.
112
- * @param {() => void} callback The callback invoked when selected items change.
113
- * @returns {SelectionManager<T>} The configured selection manager.
114
- */
115
- onSelectedItemsChange(callback: () => void): this {
116
- this.#onSelectedItemsChangeCallback = callback;
117
- return this;
118
- }
119
-
120
- /** @private */
121
- #enforceSingleSelect(emit = false): void {
122
- if (!this.multi && this.#selectedItems.length > 1) {
123
- for (let i = 1; i < this.#selectedItems.length; i++) {
124
- checkOrSelect(this.#selectedItems[i], false);
125
- }
126
- this.#selectedItems.length = 1;
127
- if (emit) {
128
- this.#onSelectedItemsChangeCallback?.();
129
- }
130
- }
131
- }
132
- }
@@ -1,131 +0,0 @@
1
- /**
2
- * Adapted from Angular Material CDK KeyManager
3
- * Source: https://github.com/angular/components/blob/main/src/cdk/a11y/key-manager/typeahead.ts
4
- *
5
- * @license MIT
6
- * Copyright (c) 2025 Google LLC
7
- * See LICENSE file in the project root for full license text.
8
- */
9
-
10
- import { getKeyCode, KeyCode } from "../keycodes";
11
- import { hasKeys } from "../../shared/mixins/hasKeys";
12
-
13
- /** A symbol through which to access an element's textual content used for typeahead search. */
14
- export const typeaheadLabel = Symbol("typeaheadLabel");
15
-
16
- /** Defines functionality required for an item that supports searching using typeahead. */
17
- export interface TypeaheadItem {
18
- /** Returns the textual content to search. */
19
- [typeaheadLabel]?(): string;
20
- }
21
-
22
- /**
23
- * Determines whether a value is a `TypeaheadItem`.
24
- * @param {unknown} value The value to test.
25
- * @returns A value indicating whether `value` is an `TypeaheadItem`.
26
- */
27
- export function isTypeaheadItem(value: unknown): value is TypeaheadItem {
28
- return hasKeys<TypeaheadItem>(value, typeaheadLabel);
29
- }
30
-
31
- /** Encapsulates options used to select items based on typeahead.
32
- * @template T The type of `TypeaheadItem`.
33
- */
34
- export interface TypeaheadOptions<T extends TypeaheadItem = TypeaheadItem> {
35
- /** The interval, in milliseconds, before searching items. */
36
- debounceInterval?: number;
37
-
38
- /** Function used to determine whether an item should be skipped. */
39
- skipPredicate?: (item: T) => boolean;
40
-
41
- /** Function invoked when an item is selected. */
42
- callback: (item: T) => void;
43
- }
44
-
45
- /**
46
- * Implements typeahead functionality which selects items based on keyboard input.
47
- * @template T The type of `TypeaheadItem`.
48
- */
49
- export class Typeahead<T extends TypeaheadItem = TypeaheadItem> {
50
- /** @private */ #debounceInterval: number;
51
- /** @private */ #timeoutId = -1;
52
- /** @private */ #callback: (item: T) => void;
53
- /** @private */ #skipPredicate?: (item: T) => boolean;
54
-
55
- /** @private */ #pressedKeys = new Array<string>();
56
- /** @private */ #selectedIndex = -1;
57
- /** @private */ #items: readonly T[] = [];
58
-
59
- /**
60
- * Initializes a new instance of this class.
61
- * @param {TypeaheadOptions<T>} options Options that control typeahead behavior.
62
- */
63
- constructor(options: TypeaheadOptions<T>) {
64
- this.#debounceInterval = options.debounceInterval ?? 200;
65
- this.#callback = options.callback;
66
- this.#skipPredicate = options.skipPredicate;
67
- }
68
-
69
- /** A value indicating whether the user is currently typing. */
70
- get isTyping(): boolean {
71
- return this.#pressedKeys.length > 0;
72
- }
73
-
74
- /**
75
- * Sets the items to search.
76
- * @param {readonly T[]} items The items to search.
77
- */
78
- setItems(items: readonly T[]): void {
79
- this.#items = items;
80
- }
81
-
82
- /**
83
- * Sets the index of the selected item.
84
- * @param {number} index The index of the selected item.
85
- */
86
- setSelectedIndex(index: number): void {
87
- this.#selectedIndex = index;
88
- }
89
-
90
- /** Resets the stored sequence of typed characters. */
91
- reset(): void {
92
- this.#pressedKeys.length = 0;
93
- }
94
-
95
- /**
96
- * Sets the selected item depending on the key event passed in.
97
- * @param {KeyboardEvent} e The keyboard event to be used for determining which element should be active.
98
- */
99
- onKeyDown(e: KeyboardEvent): void {
100
- if (e.key && e.key.length === 1) {
101
- this.#appendKey(e.key);
102
- } else {
103
- const keycode = getKeyCode(e);
104
- if ((keycode >= KeyCode.A && keycode <= KeyCode.Z) || (keycode >= KeyCode.Zero && keycode <= KeyCode.Nine)) {
105
- this.#appendKey(String.fromCharCode(keycode));
106
- }
107
- }
108
- }
109
-
110
- /** @private */
111
- #appendKey(key: string): void {
112
- this.#pressedKeys.push(key.toLocaleUpperCase());
113
- clearTimeout(this.#timeoutId);
114
- this.#timeoutId = setTimeout(() => this.#searchItems(), this.#debounceInterval);
115
- }
116
-
117
- /** @private */
118
- #searchItems(): void {
119
- const term = this.#pressedKeys.join("");
120
- for (let i = 1; i < this.#items.length + 1; i++) {
121
- const index = (this.#selectedIndex + i) % this.#items.length;
122
- const item = this.#items[index];
123
- const label = item[typeaheadLabel]?.().toLocaleUpperCase().trim();
124
- if (!this.#skipPredicate?.(item) && label?.indexOf(term) === 0) {
125
- this.#callback(item);
126
- break;
127
- }
128
- }
129
- this.reset();
130
- }
131
- }
@@ -1,7 +0,0 @@
1
- export * from "./FocusKeyManager";
2
- export * from "./ListKeyManager";
3
- export * from "./ListManager";
4
- export * from "./RadioKeyManager";
5
- export * from "./RovingTabIndexManager";
6
- export * from "./SelectionManager";
7
- export * from "./Typeahead";
@@ -1,18 +0,0 @@
1
- /**
2
- * Visually hides an element.
3
- * @param {CSSStyleDeclaration} style The style of the element to visually hide.
4
- */
5
- export function visuallyHide(style: CSSStyleDeclaration): void {
6
- style.position = "absolute";
7
- style.appearance = "none";
8
- style.visibility = "hidden";
9
- style.border = "0";
10
- style.outline = "0";
11
- style.overflow = "hidden";
12
- style.left = "0";
13
- style.height = "1px";
14
- style.width = "1px";
15
- style.margin = "-1px";
16
- style.padding = "0";
17
- style.whiteSpace = "nowrap";
18
- }
@@ -1,19 +0,0 @@
1
- import { AnchorPosition } from "./AnchorPosition";
2
-
3
- /** Options used to anchor an element to another. */
4
- export interface AnchorOptions {
5
- /** The position of the element, relative to the anchor. */
6
- position: AnchorPosition;
7
-
8
- /** Whether to improve positioning for inline elements which can span multiple lines. */
9
- inline?: boolean;
10
-
11
- /** Whether the element can be shifted to keep it in view. */
12
- shift?: boolean;
13
-
14
- /** Whether the element can flip to keep it in view. */
15
- flip?: boolean | AnchorPosition[];
16
-
17
- /** The logical margin, in pixels, between element and its anchor. */
18
- offset?: number;
19
- }
@@ -1,14 +0,0 @@
1
- /** Specifies the possible positions in which to anchor an element to another. */
2
- export type AnchorPosition =
3
- | "top"
4
- | "right"
5
- | "bottom"
6
- | "left"
7
- | "top-start"
8
- | "top-end"
9
- | "right-start"
10
- | "right-end"
11
- | "bottom-start"
12
- | "bottom-end"
13
- | "left-start"
14
- | "left-end";
@@ -1,3 +0,0 @@
1
- export * from "./AnchorOptions";
2
- export * from "./AnchorPosition";
3
- export * from "./positionAnchor";
@@ -1,53 +0,0 @@
1
- import { autoUpdate, computePosition, flip, inline, Middleware, offset, platform, shift } from "@floating-ui/dom";
2
- import { offsetParent } from "composed-offset-position";
3
-
4
- import { AnchorOptions } from "./AnchorOptions";
5
- import { AnchorPosition } from "./AnchorPosition";
6
-
7
- /**
8
- * Positions an element relative to an anchor element.
9
- * @param {HTMLElement} target The element to position.
10
- * @param {HTMLElement} anchor The element in which to anchor `target`.
11
- * @param {AnchorOptions} options Options that control positioning relative to the anchor.
12
- * @param {((x: number, y: number, position: AnchorPosition) => void) | undefined} update Callback used to position `target`.
13
- * @returns {Promise<() => void>} Promise that resolves to a function used to stop updating target when the position of the anchor element changes.
14
- */
15
- export async function positionAnchor(
16
- target: HTMLElement,
17
- anchor: HTMLElement,
18
- options: AnchorOptions,
19
- update?: (x: number, y: number, position: AnchorPosition) => void
20
- ): Promise<() => void> {
21
- async function computeAnchorPosition() {
22
- const middleware = new Array<Middleware>();
23
-
24
- if (options?.inline) {
25
- middleware.push(inline());
26
- }
27
- if (options.flip) {
28
- middleware.push(options.flip === true ? flip() : flip({ fallbackPlacements: options.flip }));
29
- }
30
- if (options.shift) {
31
- middleware.push(shift());
32
- }
33
- if (options.offset && !isNaN(options.offset)) {
34
- middleware.push(offset(options.offset));
35
- }
36
-
37
- const result = await computePosition(anchor, target, {
38
- placement: options.position,
39
- middleware: middleware,
40
- platform: { ...platform, getOffsetParent: (x) => platform.getOffsetParent(x, offsetParent) },
41
- });
42
-
43
- if (!update) {
44
- target.style.left = `${result.x}px`;
45
- target.style.top = `${result.y}px`;
46
- } else {
47
- update(result.x, result.y, result.placement);
48
- }
49
- }
50
-
51
- await computeAnchorPosition();
52
- return autoUpdate(anchor, target, async () => await computeAnchorPosition());
53
- }
@@ -1,85 +0,0 @@
1
- /**
2
- * Adapted from Angular Material CDK Directionality
3
- * Source: https://github.com/angular/components/blob/main/src/cdk/bidi/directionality.ts
4
- *
5
- * @license MIT
6
- * Copyright (c) 2025 Google LLC
7
- * See LICENSE file in the project root for full license text.
8
- */
9
-
10
- import { isServer } from "lit";
11
-
12
- /** Taken from `goog.i18n.bidi.isRtlLanguage`. */
13
- const RTL_LOCALES =
14
- /^(ar|ckb|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Adlm|Arab|Hebr|Nkoo|Rohg|Thaa))(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)/i;
15
-
16
- /** Specifies the directionalities for a document. */
17
- export type Direction = "ltr" | "rtl";
18
-
19
- /** Utility used to determine the directionality of the current document. */
20
- export class M3eDirectionality {
21
- /** @private */ static #current: Direction = "ltr";
22
- /** @private */ static readonly #observers = Array<() => void>();
23
-
24
- static {
25
- if (!isServer) {
26
- this.#updateDirection();
27
-
28
- if (MutationObserver) {
29
- const init: MutationObserverInit = { attributeFilter: ["dir"] };
30
- const observer = new MutationObserver(() => this.#handleChange());
31
- if (document.body) {
32
- observer.observe(document.body, init);
33
- }
34
- if (document.documentElement) {
35
- observer.observe(document.documentElement, init);
36
- }
37
- }
38
-
39
- window.addEventListener("languagechange", () => this.#handleChange());
40
- }
41
- }
42
-
43
- /** The directionality of the current document. */
44
- static get current(): Direction {
45
- return this.#current;
46
- }
47
-
48
- /**
49
- * Observes changes to directionality.
50
- * @param {()=>void} callback Function invoked when directionality changes.
51
- * @returns {()=>void} A function used to unobserve changes.
52
- */
53
- static observe(callback: () => void): () => void {
54
- this.#observers.push(callback);
55
- return () => {
56
- this.#observers.splice(this.#observers.indexOf(callback), 1);
57
- };
58
- }
59
-
60
- /** @private */
61
- static #updateDirection() {
62
- const _dir = (document?.body?.dir || document?.documentElement?.dir)?.toLowerCase() || "auto";
63
- this.#current =
64
- _dir === "auto" && !isServer && navigator?.language
65
- ? RTL_LOCALES.test(navigator.language)
66
- ? "rtl"
67
- : "ltr"
68
- : _dir === "rtl"
69
- ? "rtl"
70
- : "ltr";
71
- }
72
-
73
- /** @private */
74
- static #handleChange(): void {
75
- this.#updateDirection();
76
- this.#observers.forEach((x) => x());
77
- }
78
- }
79
-
80
- declare global {
81
- /** Utility used to determine the directionality of the current document. */
82
- var M3eDirectionality: M3eDirectionality;
83
- }
84
-
85
- globalThis.M3eDirectionality = M3eDirectionality;
package/src/bidi/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./Directionality";
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./shared";
@@ -1,26 +0,0 @@
1
- /**
2
- * Adapted from Angular Material CDK Breakpoints
3
- * Source: https://github.com/angular/components/blob/main/src/cdk/layout/breakpoints.ts
4
- *
5
- * @license MIT
6
- * Copyright (c) 2025 Google LLC
7
- * See LICENSE file in the project root for full license text.
8
- */
9
-
10
- /** Specifies predefined breakpoints. */
11
- export enum Breakpoint {
12
- XSmall = "(max-width: 599.98px)",
13
- Small = "(min-width: 600px) and (max-width: 959.98px)",
14
- Medium = "(min-width: 960px) and (max-width: 1279.98px)",
15
- Large = "(min-width: 1280px) and (max-width: 1919.98px)",
16
- XLarge = "(min-width: 1920px)",
17
- Handset = "(max-width: 599.98px) and (orientation: portrait), (max-width: 959.98px) and (orientation: landscape)",
18
- Tablet = "(min-width: 600px) and (max-width: 839.98px) and (orientation: portrait), (min-width: 960px) and (max-width: 1279.98px) and (orientation: landscape)",
19
- Web = "(min-width: 840px) and (orientation: portrait), (min-width: 1280px) and (orientation: landscape)",
20
- HandsetPortrait = "(max-width: 599.98px) and (orientation: portrait)",
21
- TabletPortrait = "(min-width: 600px) and (max-width: 839.98px) and (orientation: portrait)",
22
- WebPortrait = "(min-width: 840px) and (orientation: portrait)",
23
- HandsetLandscape = "(max-width: 959.98px) and (orientation: landscape)",
24
- TabletLandscape = "(min-width: 960px) and (max-width: 1279.98px) and (orientation: landscape)",
25
- WebLandscape = "(min-width: 1280px) and (orientation: landscape)",
26
- }
@@ -1,44 +0,0 @@
1
- import { isServer } from "lit";
2
-
3
- import { Breakpoint } from "./Breakpoint";
4
-
5
- /** The callback function invoked when the viewport size changes. */
6
- export type BreakpointObserverCallback = (matches: Map<Breakpoint | string, boolean>) => void;
7
-
8
- /** Utility used to detect changes to viewport sizes. */
9
- export class M3eBreakpointObserver {
10
- /**
11
- * Observes changes to viewport sizes.
12
- * @param {Array<Breakpoint | string>} breakpoints The breakpoints to observe.
13
- * @param {BreakpointObserverCallback} callback The callback function invoked when the viewport size changes.
14
- * @returns {() => void} A function used to stop observing changes to viewport sizes.
15
- */
16
- static observe(breakpoints: Array<Breakpoint | string>, callback: BreakpointObserverCallback): () => void {
17
- if (isServer || breakpoints.length == 0) {
18
- return () => {};
19
- }
20
-
21
- const mediaQueries = breakpoints.map((x) => matchMedia(x));
22
- const changeHandler = () => {
23
- const map = new Map<Breakpoint | string, boolean>();
24
- breakpoints.forEach((x, i) => map.set(x, mediaQueries[i].matches));
25
- callback(map);
26
- };
27
-
28
- mediaQueries.forEach((x) => x.addEventListener("change", changeHandler));
29
-
30
- changeHandler();
31
-
32
- return () => {
33
- mediaQueries.forEach((x) => x.removeEventListener("change", changeHandler));
34
- mediaQueries.length = 0;
35
- };
36
- }
37
- }
38
-
39
- declare global {
40
- /** Utility used to detect changes to viewport sizes. */
41
- var M3eBreakpointObserver: M3eBreakpointObserver;
42
- }
43
-
44
- globalThis.M3eBreakpointObserver = M3eBreakpointObserver;
@@ -1,2 +0,0 @@
1
- export * from "./Breakpoint";
2
- export * from "./BreakpointObserver";