@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,134 +0,0 @@
1
- import { LitElement } from "lit";
2
-
3
- import { Constructor } from "./Constructor";
4
-
5
- /** Specifies valid values for the ARIA `role` attribute. */
6
- export type ARIARole =
7
- | "alert"
8
- | "alertdialog"
9
- | "button"
10
- | "checkbox"
11
- | "dialog"
12
- | "gridcell"
13
- | "link"
14
- | "log"
15
- | "marquee"
16
- | "menuitem"
17
- | "menuitemcheckbox"
18
- | "menuitemradio"
19
- | "option"
20
- | "progressbar"
21
- | "radio"
22
- | "scrollbar"
23
- | "searchbox"
24
- | "slider"
25
- | "spinbutton"
26
- | "status"
27
- | "switch"
28
- | "tab"
29
- | "tabpanel"
30
- | "textbox"
31
- | "timer"
32
- | "tooltip"
33
- | "treeitem"
34
- | "combobox"
35
- | "grid"
36
- | "listbox"
37
- | "menu"
38
- | "menubar"
39
- | "radiogroup"
40
- | "tablist"
41
- | "tree"
42
- | "treegrid"
43
- | "application"
44
- | "article"
45
- | "cell"
46
- | "columnheader"
47
- | "definition"
48
- | "directory"
49
- | "document"
50
- | "feed"
51
- | "figure"
52
- | "group"
53
- | "heading"
54
- | "img"
55
- | "list"
56
- | "listitem"
57
- | "math"
58
- | "none"
59
- | "note"
60
- | "presentation"
61
- | "region"
62
- | "row"
63
- | "rowgroup"
64
- | "rowheader"
65
- | "separator"
66
- | "table"
67
- | "term"
68
- | "text"
69
- | "toolbar"
70
- | "banner"
71
- | "complementary"
72
- | "contentinfo"
73
- | "form"
74
- | "main"
75
- | "navigation"
76
- | "region"
77
- | "search"
78
- | "doc-abstract"
79
- | "doc-acknowledgments"
80
- | "doc-afterword"
81
- | "doc-appendix"
82
- | "doc-backlink"
83
- | "doc-biblioentry"
84
- | "doc-bibliography"
85
- | "doc-biblioref"
86
- | "doc-chapter"
87
- | "doc-colophon"
88
- | "doc-conclusion"
89
- | "doc-cover"
90
- | "doc-credit"
91
- | "doc-credits"
92
- | "doc-dedication"
93
- | "doc-endnote"
94
- | "doc-endnotes"
95
- | "doc-epigraph"
96
- | "doc-epilogue"
97
- | "doc-errata"
98
- | "doc-example"
99
- | "doc-footnote"
100
- | "doc-foreword"
101
- | "doc-glossary"
102
- | "doc-glossref"
103
- | "doc-index"
104
- | "doc-introduction"
105
- | "doc-noteref"
106
- | "doc-notice"
107
- | "doc-pagebreak"
108
- | "doc-pagelist"
109
- | "doc-part"
110
- | "doc-preface"
111
- | "doc-prologue"
112
- | "doc-pullquote"
113
- | "doc-qna"
114
- | "doc-subtitle"
115
- | "doc-tip"
116
- | "doc-toc";
117
-
118
- /**
119
- * Mixin to augment an element with an ARIA role.
120
- * @template T The type of the base class.
121
- * @param {T} base The base class.
122
- * @param {ARIARole} role The ARIA role.
123
- * @returns {Constructor & T} A constructor that implements focusable behavior.
124
- */
125
- export function Role<T extends Constructor<LitElement>>(base: T, role: ARIARole): Constructor & T {
126
- abstract class _RoleMixin extends base {
127
- override connectedCallback(): void {
128
- this.role = this.role || role;
129
- super.connectedCallback();
130
- }
131
- }
132
-
133
- return _RoleMixin;
134
- }
@@ -1,50 +0,0 @@
1
- import { LitElement, PropertyValues } from "lit";
2
- import { property } from "lit/decorators.js";
3
-
4
- import { Constructor } from "./Constructor";
5
- import { hasKeys } from "./hasKeys";
6
-
7
- /** Defines functionality for an element which supports a selected state. */
8
- export interface SelectedMixin {
9
- /**
10
- * Whether the element is selected.
11
- * @default false
12
- */
13
- selected: boolean;
14
- }
15
-
16
- /**
17
- * Determines whether a value is a `SelectedMixin`.
18
- * @param {unknown} value The value to test.
19
- * @returns Whether `value` is a `SelectedMixin`.
20
- */
21
- export function isSelectedMixin(value: unknown): value is SelectedMixin {
22
- return hasKeys<SelectedMixin>(value, "selected");
23
- }
24
-
25
- /**
26
- * Mixin to augment an element with behavior that supports a selected state.
27
- * @template T The type of the base class.
28
- * @param {T} base The base class.
29
- * @returns {Constructor<SelectedMixin> & T} A constructor that implements `SelectedMixin`.
30
- */
31
- export function Selected<T extends Constructor<LitElement>>(base: T): Constructor<SelectedMixin> & T {
32
- abstract class _SelectedMixin extends base implements SelectedMixin {
33
- @property({ type: Boolean, reflect: true }) selected = false;
34
-
35
- protected override update(changedProperties: PropertyValues<this>): void {
36
- super.update(changedProperties);
37
-
38
- if (changedProperties.has("selected")) {
39
- if (this.role === "button") {
40
- this.ariaPressed = `${this.selected}`;
41
- this.ariaSelected = null;
42
- } else if (this.role && this.role !== "none" && this.role !== "presentation") {
43
- this.ariaSelected = `${this.selected}`;
44
- this.ariaPressed = null;
45
- }
46
- }
47
- }
48
- }
49
- return _SelectedMixin;
50
- }
@@ -1,71 +0,0 @@
1
- import { LitElement } from "lit";
2
-
3
- import { Constructor } from "./Constructor";
4
- import { hasKeys } from "./hasKeys";
5
-
6
- /** Defines functionality for an element that can be marked as touched. */
7
- export interface TouchedMixin {
8
- /** Whether the user has interacted when the element. */
9
- readonly touched: boolean;
10
-
11
- /** Whether the user has not interacted when the element. */
12
- readonly untouched: boolean;
13
-
14
- /** Marks the element as touched. */
15
- markAsTouched(): void;
16
-
17
- /** Marks the element as untouched. */
18
- markAsUntouched(): void;
19
- }
20
-
21
- /**
22
- * Determines whether a value is a `TouchedMixin`.
23
- * @param {unknown} value The value to test.
24
- * @returns A value indicating whether `value` is a `TouchedMixin`.
25
- */
26
- export function isTouchedMixin(value: unknown): value is TouchedMixin {
27
- return hasKeys<TouchedMixin>(value, "touched", "untouched", "markAsTouched", "markAsUntouched");
28
- }
29
-
30
- const _eventHandler = Symbol("_eventHandler");
31
-
32
- /**
33
- * Mixin to augment an element with functionality used to mark it as touched.
34
- * @template T The type of the base class.
35
- * @param {T} base The base class.
36
- * @returns {Constructor<TouchedMixin> & T} A constructor that implements `TouchedMixin`.
37
- */
38
- export function Touched<T extends Constructor<LitElement>>(base: T): Constructor<TouchedMixin> & T {
39
- abstract class _Touched extends base implements TouchedMixin {
40
- private [_eventHandler] = () => this.markAsTouched();
41
-
42
- get touched(): boolean {
43
- return this.classList.contains("-touched");
44
- }
45
-
46
- get untouched(): boolean {
47
- return !this.touched;
48
- }
49
-
50
- override connectedCallback(): void {
51
- this.markAsUntouched();
52
- super.connectedCallback();
53
- this.addEventListener("focusout", this[_eventHandler]);
54
- }
55
-
56
- override disconnectedCallback(): void {
57
- super.disconnectedCallback();
58
- this.removeEventListener("focusout", this[_eventHandler]);
59
- }
60
-
61
- markAsTouched(): void {
62
- this.classList.toggle("-touched", true);
63
- }
64
-
65
- markAsUntouched(): void {
66
- this.classList.toggle("-touched", false);
67
- }
68
- }
69
-
70
- return _Touched;
71
- }
@@ -1,44 +0,0 @@
1
- import { LitElement, PropertyValues } from "lit";
2
- import { property } from "lit/decorators.js";
3
-
4
- import { Constructor } from "./Constructor";
5
- import { hasKeys } from "./hasKeys";
6
-
7
- /** Defines functionality for an element which supports a vertical orientation. */
8
- export interface VerticalMixin {
9
- /**
10
- * Whether the element is oriented vertically.
11
- * @default false
12
- */
13
- vertical: boolean;
14
- }
15
-
16
- /**
17
- * Determines whether a value is a `VerticalMixin`.
18
- * @param {unknown} value The value to test.
19
- * @returns A value indicating whether `value` is a `VerticalMixin`.
20
- */
21
- export function isVerticalMixin(value: unknown): value is VerticalMixin {
22
- return hasKeys<VerticalMixin>(value, "vertical");
23
- }
24
-
25
- /**
26
- * Mixin to augment an element with behavior that supports a vertical orientation.
27
- * @template T The type of the base class.
28
- * @param {T} base The base class.
29
- * @returns {Constructor<VerticalMixin> & T} A constructor that implements `VerticalMixin`.
30
- */
31
- export function Vertical<T extends Constructor<LitElement>>(base: T): Constructor<VerticalMixin> & T {
32
- abstract class _VerticalMixin extends base implements VerticalMixin {
33
- @property({ type: Boolean, reflect: true }) vertical = false;
34
-
35
- protected override update(changedProperties: PropertyValues<this>): void {
36
- super.update(changedProperties);
37
-
38
- if (changedProperties.has("vertical")) {
39
- this.ariaOrientation = this.vertical ? "vertical" : "horizontal";
40
- }
41
- }
42
- }
43
- return _VerticalMixin;
44
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Determines whether an object has keys for a given type.
3
- * @template T The type to test.
4
- * @param {unknown} value The value to test.
5
- * @param {...keys: Array<keyof T>} keys The keys of `T` to test.
6
- * @returns {boolean} Whether `value` has all `keys`.
7
- */
8
- export function hasKeys<T extends object>(value: unknown, ...keys: Array<keyof T>): boolean {
9
- return typeof value === "object" && value !== null && keys.every((x) => x in value);
10
- }
@@ -1,24 +0,0 @@
1
- export * from "./AttachInternals";
2
- export * from "./Checked";
3
- export * from "./CheckedIndeterminate";
4
- export * from "./CheckedOrSelected";
5
- export * from "./ConstraintValidation";
6
- export * from "./Dirty";
7
- export * from "./Disabled";
8
- export * from "./DisabledInteractive";
9
- export * from "./EventAttribute";
10
- export * from "./Focusable";
11
- export * from "./FormAssociated";
12
- export * from "./FormSubmitter";
13
- export * from "./hasKeys";
14
- export * from "./HtmlFor";
15
- export * from "./KeyboardClick";
16
- export * from "./Labelled";
17
- export * from "./LinkButton";
18
- export * from "./ReadOnly";
19
- export * from "./Required";
20
- export * from "./RequiredConstraintValidation";
21
- export * from "./Role";
22
- export * from "./Selected";
23
- export * from "./Touched";
24
- export * from "./Vertical";
@@ -1,227 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
2
-
3
- import { css, CSSResultGroup, html, LitElement, PropertyValues, unsafeCSS } from "lit";
4
- import { customElement, property } from "lit/decorators.js";
5
-
6
- import { EventAttribute, Role } from "../mixins";
7
- import { DesignToken } from "../tokens";
8
- import { prefersReducedMotion } from "../utils";
9
-
10
- /**
11
- * A container used to expand and collapse content.
12
- *
13
- * @example
14
- * ```html
15
- * <m3e-collapsible>
16
- * <!-- Collapsible content -->
17
- * </m3e-collapsible>
18
- * ```
19
- *
20
- * @tag m3e-collapsible
21
- *
22
- * @slot - Renders the collapsible content.
23
- *
24
- * @attr open - Whether content is visible.
25
- *
26
- * @fires opening - Emitted when the collapsible begins to open.
27
- * @fires opened - Emitted when the collapsible has opened.
28
- * @fires closing - Emitted when the collapsible begins to close.
29
- * @fires closed - Emitted when the collapsible has closed.
30
- *
31
- * @cssprop --m3e-collapsible-animation-duration - The duration of the expand / collapse animation.
32
- */
33
- @customElement("m3e-collapsible")
34
- export class M3eCollapsibleElement extends EventAttribute(
35
- Role(LitElement, "none"),
36
- "opening",
37
- "opened",
38
- "closing",
39
- "closed"
40
- ) {
41
- /** The styles of the element. */
42
- static override styles: CSSResultGroup = css`
43
- :host {
44
- display: block;
45
- height: 0px;
46
- overflow: hidden;
47
- transition: ${unsafeCSS(`visibility var(--m3e-collapsible-animation-duration, ${DesignToken.motion.duration.medium1})
48
- ${DesignToken.motion.easing.standard},
49
- height var(--m3e-collapsible-animation-duration, ${DesignToken.motion.duration.medium1})
50
- ${DesignToken.motion.easing.standard},
51
- padding-top var(--m3e-collapsible-animation-duration, ${DesignToken.motion.duration.medium1})
52
- ${DesignToken.motion.easing.standard},
53
- padding-bottom var(--m3e-collapsible-animation-duration, ${DesignToken.motion.duration.medium1})
54
- ${DesignToken.motion.easing.standard}`)};
55
- }
56
- :host(:not(.-closing):not([open])) {
57
- visibility: hidden;
58
- }
59
- :host([open]) {
60
- visibility: visible;
61
- }
62
- :host(:not([open])) {
63
- min-height: unset !important;
64
- padding-top: 0px !important;
65
- padding-bottom: 0px !important;
66
- }
67
- :host(.-no-animate) {
68
- transition-duration: 0ms;
69
- }
70
- ::slotted(*) {
71
- --m3e-collapsible-animation-duration: initial;
72
- }
73
- @media (prefers-reduced-motion) {
74
- :host {
75
- transition: none;
76
- }
77
- }
78
- `;
79
-
80
- /** @private */ #slotChanged = false;
81
- /** @private */ #hasOpened = false;
82
-
83
- /**
84
- * Whether content is visible.
85
- * @default false
86
- */
87
- @property({ type: Boolean, reflect: true }) open = false;
88
-
89
- /** @inheritdoc */
90
- protected override update(changedProperties: PropertyValues): void {
91
- super.update(changedProperties);
92
-
93
- this.classList.toggle("-no-animate", true);
94
-
95
- if (!this.#slotChanged) {
96
- if (this.open) {
97
- this.#hasOpened = true;
98
- this.#autoSize();
99
- }
100
- this.#slotChanged = true;
101
- return;
102
- }
103
-
104
- this.toggleAttribute("inert", !this.open);
105
-
106
- if (this.open) {
107
- this.#hasOpened = true;
108
- this.classList.toggle("-closing", false);
109
- this.classList.toggle("-opening", true);
110
- this.dispatchEvent(new Event("opening"));
111
-
112
- this.#clearSize();
113
- this.classList.toggle("-no-animate", false);
114
- this.#actualSize();
115
-
116
- if (prefersReducedMotion()) {
117
- this.classList.toggle("-opening", false);
118
- this.dispatchEvent(new Event("opened"));
119
- } else {
120
- this.addEventListener(
121
- "transitionend",
122
- () => {
123
- if (this.open) {
124
- this.#autoSize();
125
- this.classList.toggle("-opening", false);
126
- this.dispatchEvent(new Event("opened"));
127
- }
128
- },
129
- { once: true }
130
- );
131
- }
132
- } else {
133
- this.classList.toggle("-opening", false);
134
- this.classList.toggle("-closing", true);
135
- this.dispatchEvent(new Event("closing"));
136
-
137
- this.#actualSize();
138
- if (this.#hasOpened) {
139
- this.classList.toggle("-no-animate", false);
140
- }
141
-
142
- if (prefersReducedMotion()) {
143
- this.#clearSize();
144
- this.classList.toggle("-closing", false);
145
- this.dispatchEvent(new Event("closed"));
146
- } else {
147
- requestAnimationFrame(() => {
148
- this.#clearSize();
149
- this.addEventListener(
150
- "transitionend",
151
- () => {
152
- if (!this.open) {
153
- this.classList.toggle("-closing", false);
154
- this.dispatchEvent(new Event("closed"));
155
- }
156
- },
157
- { once: true }
158
- );
159
- });
160
- }
161
- }
162
- }
163
-
164
- /** @inheritdoc */
165
- protected override render(): unknown {
166
- return html`<slot @slotchange="${this.#handleSlotChange}"></slot>`;
167
- }
168
-
169
- /** @private */
170
- #handleSlotChange() {
171
- this.#slotChanged = true;
172
- }
173
-
174
- /** @private */
175
- #autoSize(): void {
176
- this.style.height = "auto";
177
- }
178
-
179
- /** @private */
180
- #clearSize(): void {
181
- this.style.height = "";
182
- }
183
-
184
- /** @private */
185
- #actualSize(): void {
186
- this.style.height = `${this.scrollHeight}px`;
187
- }
188
- }
189
-
190
- interface M3eCollapsibleElementEventMap extends HTMLElementEventMap {
191
- opening: Event;
192
- opened: Event;
193
- closing: Event;
194
- closed: Event;
195
- }
196
-
197
- export interface M3eCollapsibleElement {
198
- addEventListener<K extends keyof M3eCollapsibleElementEventMap>(
199
- type: K,
200
- listener: (this: M3eCollapsibleElement, ev: M3eCollapsibleElementEventMap[K]) => void,
201
- options?: boolean | AddEventListenerOptions
202
- ): void;
203
-
204
- addEventListener(
205
- type: string,
206
- listener: EventListenerOrEventListenerObject,
207
- options?: boolean | AddEventListenerOptions
208
- ): void;
209
-
210
- removeEventListener<K extends keyof M3eCollapsibleElementEventMap>(
211
- type: K,
212
- listener: (this: M3eCollapsibleElement, ev: M3eCollapsibleElementEventMap[K]) => void,
213
- options?: boolean | EventListenerOptions
214
- ): void;
215
-
216
- removeEventListener(
217
- type: string,
218
- listener: EventListenerOrEventListenerObject,
219
- options?: boolean | EventListenerOptions
220
- ): void;
221
- }
222
-
223
- declare global {
224
- interface HTMLElementTagNameMap {
225
- "m3e-collapsible": M3eCollapsibleElement;
226
- }
227
- }