@m3e/core 1.0.0-rc.1 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/a11y.js +6 -18
- package/dist/a11y.js.map +1 -1
- package/dist/a11y.min.js +5 -5
- package/dist/a11y.min.js.map +1 -1
- package/dist/custom-elements.json +3449 -3429
- package/dist/html-custom-data.json +14 -6
- package/dist/index.js +198 -29
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +87 -87
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
- package/cem.config.mjs +0 -16
- package/demo/index.html +0 -58
- package/dist/src/a11y/AriaDescriber.d.ts +0 -31
- package/dist/src/a11y/AriaDescriber.d.ts.map +0 -1
- package/dist/src/a11y/FocusTrapElement.d.ts +0 -25
- package/dist/src/a11y/FocusTrapElement.d.ts.map +0 -1
- package/dist/src/a11y/InteractivityChecker.d.ts +0 -22
- package/dist/src/a11y/InteractivityChecker.d.ts.map +0 -1
- package/dist/src/a11y/LiveAnnouncer.d.ts +0 -56
- package/dist/src/a11y/LiveAnnouncer.d.ts.map +0 -1
- package/dist/src/a11y/aria-reference.d.ts +0 -30
- package/dist/src/a11y/aria-reference.d.ts.map +0 -1
- package/dist/src/a11y/index.d.ts +0 -8
- package/dist/src/a11y/index.d.ts.map +0 -1
- package/dist/src/a11y/keycodes/KeyCode.d.ts +0 -118
- package/dist/src/a11y/keycodes/KeyCode.d.ts.map +0 -1
- package/dist/src/a11y/keycodes/ModifierKeys.d.ts +0 -5
- package/dist/src/a11y/keycodes/ModifierKeys.d.ts.map +0 -1
- package/dist/src/a11y/keycodes/getKeyCode.d.ts +0 -7
- package/dist/src/a11y/keycodes/getKeyCode.d.ts.map +0 -1
- package/dist/src/a11y/keycodes/hasModifierKey.d.ts +0 -9
- package/dist/src/a11y/keycodes/hasModifierKey.d.ts.map +0 -1
- package/dist/src/a11y/keycodes/index.d.ts +0 -6
- package/dist/src/a11y/keycodes/index.d.ts.map +0 -1
- package/dist/src/a11y/keycodes/isModifierAllowed.d.ts +0 -9
- package/dist/src/a11y/keycodes/isModifierAllowed.d.ts.map +0 -1
- package/dist/src/a11y/list-key/FocusKeyManager.d.ts +0 -17
- package/dist/src/a11y/list-key/FocusKeyManager.d.ts.map +0 -1
- package/dist/src/a11y/list-key/ListKeyManager.d.ts +0 -114
- package/dist/src/a11y/list-key/ListKeyManager.d.ts.map +0 -1
- package/dist/src/a11y/list-key/ListManager.d.ts +0 -37
- package/dist/src/a11y/list-key/ListManager.d.ts.map +0 -1
- package/dist/src/a11y/list-key/RadioKeyManager.d.ts +0 -20
- package/dist/src/a11y/list-key/RadioKeyManager.d.ts.map +0 -1
- package/dist/src/a11y/list-key/RovingTabIndexManager.d.ts +0 -22
- package/dist/src/a11y/list-key/RovingTabIndexManager.d.ts.map +0 -1
- package/dist/src/a11y/list-key/SelectionManager.d.ts +0 -46
- package/dist/src/a11y/list-key/SelectionManager.d.ts.map +0 -1
- package/dist/src/a11y/list-key/Typeahead.d.ts +0 -64
- package/dist/src/a11y/list-key/Typeahead.d.ts.map +0 -1
- package/dist/src/a11y/list-key/index.d.ts +0 -8
- package/dist/src/a11y/list-key/index.d.ts.map +0 -1
- package/dist/src/a11y/visuallyHide.d.ts +0 -6
- package/dist/src/a11y/visuallyHide.d.ts.map +0 -1
- package/dist/src/anchoring/AnchorOptions.d.ts +0 -15
- package/dist/src/anchoring/AnchorOptions.d.ts.map +0 -1
- package/dist/src/anchoring/AnchorPosition.d.ts +0 -3
- package/dist/src/anchoring/AnchorPosition.d.ts.map +0 -1
- package/dist/src/anchoring/index.d.ts +0 -4
- package/dist/src/anchoring/index.d.ts.map +0 -1
- package/dist/src/anchoring/positionAnchor.d.ts +0 -12
- package/dist/src/anchoring/positionAnchor.d.ts.map +0 -1
- package/dist/src/bidi/Directionality.d.ts +0 -27
- package/dist/src/bidi/Directionality.d.ts.map +0 -1
- package/dist/src/bidi/index.d.ts +0 -2
- package/dist/src/bidi/index.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/layout/Breakpoint.d.ts +0 -26
- package/dist/src/layout/Breakpoint.d.ts.map +0 -1
- package/dist/src/layout/BreakpointObserver.d.ts +0 -18
- package/dist/src/layout/BreakpointObserver.d.ts.map +0 -1
- package/dist/src/layout/index.d.ts +0 -3
- package/dist/src/layout/index.d.ts.map +0 -1
- package/dist/src/platform/Platform.d.ts +0 -34
- package/dist/src/platform/Platform.d.ts.map +0 -1
- package/dist/src/platform/index.d.ts +0 -2
- package/dist/src/platform/index.d.ts.map +0 -1
- package/dist/src/shared/controllers/FocusController.d.ts +0 -30
- package/dist/src/shared/controllers/FocusController.d.ts.map +0 -1
- package/dist/src/shared/controllers/HoverController.d.ts +0 -40
- package/dist/src/shared/controllers/HoverController.d.ts.map +0 -1
- package/dist/src/shared/controllers/IntersectionController.d.ts +0 -40
- package/dist/src/shared/controllers/IntersectionController.d.ts.map +0 -1
- package/dist/src/shared/controllers/LongPressController.d.ts +0 -32
- package/dist/src/shared/controllers/LongPressController.d.ts.map +0 -1
- package/dist/src/shared/controllers/MonitorControllerBase.d.ts +0 -62
- package/dist/src/shared/controllers/MonitorControllerBase.d.ts.map +0 -1
- package/dist/src/shared/controllers/MutationController.d.ts +0 -37
- package/dist/src/shared/controllers/MutationController.d.ts.map +0 -1
- package/dist/src/shared/controllers/PressedController.d.ts +0 -45
- package/dist/src/shared/controllers/PressedController.d.ts.map +0 -1
- package/dist/src/shared/controllers/ResizeController.d.ts +0 -40
- package/dist/src/shared/controllers/ResizeController.d.ts.map +0 -1
- package/dist/src/shared/controllers/ScrollController.d.ts +0 -34
- package/dist/src/shared/controllers/ScrollController.d.ts.map +0 -1
- package/dist/src/shared/controllers/index.d.ts +0 -9
- package/dist/src/shared/controllers/index.d.ts.map +0 -1
- package/dist/src/shared/decorators/debounce.d.ts +0 -7
- package/dist/src/shared/decorators/debounce.d.ts.map +0 -1
- package/dist/src/shared/decorators/index.d.ts +0 -2
- package/dist/src/shared/decorators/index.d.ts.map +0 -1
- package/dist/src/shared/directives/index.d.ts +0 -2
- package/dist/src/shared/directives/index.d.ts.map +0 -1
- package/dist/src/shared/directives/safeStyleMap.d.ts +0 -44
- package/dist/src/shared/directives/safeStyleMap.d.ts.map +0 -1
- package/dist/src/shared/index.d.ts +0 -8
- package/dist/src/shared/index.d.ts.map +0 -1
- package/dist/src/shared/mixins/AttachInternals.d.ts +0 -24
- package/dist/src/shared/mixins/AttachInternals.d.ts.map +0 -1
- package/dist/src/shared/mixins/Checked.d.ts +0 -24
- package/dist/src/shared/mixins/Checked.d.ts.map +0 -1
- package/dist/src/shared/mixins/CheckedIndeterminate.d.ts +0 -25
- package/dist/src/shared/mixins/CheckedIndeterminate.d.ts.map +0 -1
- package/dist/src/shared/mixins/CheckedOrSelected.d.ts +0 -23
- package/dist/src/shared/mixins/CheckedOrSelected.d.ts.map +0 -1
- package/dist/src/shared/mixins/ConstraintValidation.d.ts +0 -48
- package/dist/src/shared/mixins/ConstraintValidation.d.ts.map +0 -1
- package/dist/src/shared/mixins/Constructor.d.ts +0 -3
- package/dist/src/shared/mixins/Constructor.d.ts.map +0 -1
- package/dist/src/shared/mixins/Dirty.d.ts +0 -27
- package/dist/src/shared/mixins/Dirty.d.ts.map +0 -1
- package/dist/src/shared/mixins/Disabled.d.ts +0 -25
- package/dist/src/shared/mixins/Disabled.d.ts.map +0 -1
- package/dist/src/shared/mixins/DisabledInteractive.d.ts +0 -25
- package/dist/src/shared/mixins/DisabledInteractive.d.ts.map +0 -1
- package/dist/src/shared/mixins/EventAttribute.d.ts +0 -11
- package/dist/src/shared/mixins/EventAttribute.d.ts.map +0 -1
- package/dist/src/shared/mixins/Focusable.d.ts +0 -11
- package/dist/src/shared/mixins/Focusable.d.ts.map +0 -1
- package/dist/src/shared/mixins/FormAssociated.d.ts +0 -34
- package/dist/src/shared/mixins/FormAssociated.d.ts.map +0 -1
- package/dist/src/shared/mixins/FormSubmitter.d.ts +0 -31
- package/dist/src/shared/mixins/FormSubmitter.d.ts.map +0 -1
- package/dist/src/shared/mixins/HtmlFor.d.ts +0 -30
- package/dist/src/shared/mixins/HtmlFor.d.ts.map +0 -1
- package/dist/src/shared/mixins/KeyboardClick.d.ts +0 -11
- package/dist/src/shared/mixins/KeyboardClick.d.ts.map +0 -1
- package/dist/src/shared/mixins/Labelled.d.ts +0 -22
- package/dist/src/shared/mixins/Labelled.d.ts.map +0 -1
- package/dist/src/shared/mixins/LinkButton.d.ts +0 -36
- package/dist/src/shared/mixins/LinkButton.d.ts.map +0 -1
- package/dist/src/shared/mixins/ReadOnly.d.ts +0 -25
- package/dist/src/shared/mixins/ReadOnly.d.ts.map +0 -1
- package/dist/src/shared/mixins/Required.d.ts +0 -26
- package/dist/src/shared/mixins/Required.d.ts.map +0 -1
- package/dist/src/shared/mixins/RequiredConstraintValidation.d.ts +0 -21
- package/dist/src/shared/mixins/RequiredConstraintValidation.d.ts.map +0 -1
- package/dist/src/shared/mixins/Role.d.ts +0 -13
- package/dist/src/shared/mixins/Role.d.ts.map +0 -1
- package/dist/src/shared/mixins/Selected.d.ts +0 -24
- package/dist/src/shared/mixins/Selected.d.ts.map +0 -1
- package/dist/src/shared/mixins/Touched.d.ts +0 -27
- package/dist/src/shared/mixins/Touched.d.ts.map +0 -1
- package/dist/src/shared/mixins/Vertical.d.ts +0 -24
- package/dist/src/shared/mixins/Vertical.d.ts.map +0 -1
- package/dist/src/shared/mixins/hasKeys.d.ts +0 -9
- package/dist/src/shared/mixins/hasKeys.d.ts.map +0 -1
- package/dist/src/shared/mixins/index.d.ts +0 -25
- package/dist/src/shared/mixins/index.d.ts.map +0 -1
- package/dist/src/shared/primitives/CollapsibleElement.d.ts +0 -58
- package/dist/src/shared/primitives/CollapsibleElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/ElevationElement.d.ts +0 -88
- package/dist/src/shared/primitives/ElevationElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/ElevationLevel.d.ts +0 -3
- package/dist/src/shared/primitives/ElevationLevel.d.ts.map +0 -1
- package/dist/src/shared/primitives/ElevationToken.d.ts +0 -15
- package/dist/src/shared/primitives/ElevationToken.d.ts.map +0 -1
- package/dist/src/shared/primitives/FocusRingElement.d.ts +0 -78
- package/dist/src/shared/primitives/FocusRingElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/FocusRingToken.d.ts +0 -17
- package/dist/src/shared/primitives/FocusRingToken.d.ts.map +0 -1
- package/dist/src/shared/primitives/PseudoCheckboxElement.d.ts +0 -50
- package/dist/src/shared/primitives/PseudoCheckboxElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/PseudoRadioElement.d.ts +0 -41
- package/dist/src/shared/primitives/PseudoRadioElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/RippleElement.d.ts +0 -110
- package/dist/src/shared/primitives/RippleElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/RippleToken.d.ts +0 -12
- package/dist/src/shared/primitives/RippleToken.d.ts.map +0 -1
- package/dist/src/shared/primitives/ScrollContainerElement.d.ts +0 -64
- package/dist/src/shared/primitives/ScrollContainerElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/ScrollDividers.d.ts +0 -3
- package/dist/src/shared/primitives/ScrollDividers.d.ts.map +0 -1
- package/dist/src/shared/primitives/SlideElement.d.ts +0 -48
- package/dist/src/shared/primitives/SlideElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/StateLayerElement.d.ts +0 -77
- package/dist/src/shared/primitives/StateLayerElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/StateLayerToken.d.ts +0 -13
- package/dist/src/shared/primitives/StateLayerToken.d.ts.map +0 -1
- package/dist/src/shared/primitives/TextOverflowElement.d.ts +0 -39
- package/dist/src/shared/primitives/TextOverflowElement.d.ts.map +0 -1
- package/dist/src/shared/primitives/index.d.ts +0 -13
- package/dist/src/shared/primitives/index.d.ts.map +0 -1
- package/dist/src/shared/tokens/ColorToken.d.ts +0 -96
- package/dist/src/shared/tokens/ColorToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/DensityToken.d.ts +0 -15
- package/dist/src/shared/tokens/DensityToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/DesignToken.d.ts +0 -366
- package/dist/src/shared/tokens/DesignToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/ElevationToken.d.ts +0 -16
- package/dist/src/shared/tokens/ElevationToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/MotionToken.d.ts +0 -69
- package/dist/src/shared/tokens/MotionToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/ScrollbarToken.d.ts +0 -10
- package/dist/src/shared/tokens/ScrollbarToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/ShapeToken.d.ts +0 -79
- package/dist/src/shared/tokens/ShapeToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/StateToken.d.ts +0 -10
- package/dist/src/shared/tokens/StateToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/TypescaleToken.d.ts +0 -220
- package/dist/src/shared/tokens/TypescaleToken.d.ts.map +0 -1
- package/dist/src/shared/tokens/index.d.ts +0 -2
- package/dist/src/shared/tokens/index.d.ts.map +0 -1
- package/dist/src/shared/utils/getTextContent.d.ts +0 -8
- package/dist/src/shared/utils/getTextContent.d.ts.map +0 -1
- package/dist/src/shared/utils/guid.d.ts +0 -6
- package/dist/src/shared/utils/guid.d.ts.map +0 -1
- package/dist/src/shared/utils/hasAssignedNodes.d.ts +0 -7
- package/dist/src/shared/utils/hasAssignedNodes.d.ts.map +0 -1
- package/dist/src/shared/utils/index.d.ts +0 -6
- package/dist/src/shared/utils/index.d.ts.map +0 -1
- package/dist/src/shared/utils/prefersReducedMotion.d.ts +0 -6
- package/dist/src/shared/utils/prefersReducedMotion.d.ts.map +0 -1
- package/dist/src/shared/utils/scrollIntoViewIfNeeded.d.ts +0 -8
- package/dist/src/shared/utils/scrollIntoViewIfNeeded.d.ts.map +0 -1
- package/eslint.config.mjs +0 -21
- package/rollup.config.js +0 -132
- package/src/a11y/AriaDescriber.ts +0 -130
- package/src/a11y/FocusTrapElement.ts +0 -136
- package/src/a11y/InteractivityChecker.ts +0 -62
- package/src/a11y/LiveAnnouncer.ts +0 -143
- package/src/a11y/aria-reference.ts +0 -51
- package/src/a11y/index.ts +0 -8
- package/src/a11y/keycodes/KeyCode.ts +0 -128
- package/src/a11y/keycodes/ModifierKeys.ts +0 -5
- package/src/a11y/keycodes/getKeyCode.ts +0 -8
- package/src/a11y/keycodes/hasModifierKey.ts +0 -11
- package/src/a11y/keycodes/index.ts +0 -5
- package/src/a11y/keycodes/isModifierAllowed.ts +0 -12
- package/src/a11y/list-key/FocusKeyManager.ts +0 -25
- package/src/a11y/list-key/ListKeyManager.ts +0 -350
- package/src/a11y/list-key/ListManager.ts +0 -66
- package/src/a11y/list-key/RadioKeyManager.ts +0 -49
- package/src/a11y/list-key/RovingTabIndexManager.ts +0 -56
- package/src/a11y/list-key/SelectionManager.ts +0 -132
- package/src/a11y/list-key/Typeahead.ts +0 -131
- package/src/a11y/list-key/index.ts +0 -7
- package/src/a11y/visuallyHide.ts +0 -18
- package/src/anchoring/AnchorOptions.ts +0 -19
- package/src/anchoring/AnchorPosition.ts +0 -14
- package/src/anchoring/index.ts +0 -3
- package/src/anchoring/positionAnchor.ts +0 -53
- package/src/bidi/Directionality.ts +0 -85
- package/src/bidi/index.ts +0 -1
- package/src/index.ts +0 -1
- package/src/layout/Breakpoint.ts +0 -26
- package/src/layout/BreakpointObserver.ts +0 -44
- package/src/layout/index.ts +0 -2
- package/src/platform/Platform.ts +0 -67
- package/src/platform/index.ts +0 -1
- package/src/shared/controllers/FocusController.ts +0 -60
- package/src/shared/controllers/HoverController.ts +0 -140
- package/src/shared/controllers/IntersectionController.ts +0 -81
- package/src/shared/controllers/LongPressController.ts +0 -87
- package/src/shared/controllers/MonitorControllerBase.ts +0 -99
- package/src/shared/controllers/MutationController.ts +0 -89
- package/src/shared/controllers/PressedController.ts +0 -137
- package/src/shared/controllers/ResizeController.ts +0 -83
- package/src/shared/controllers/ScrollController.ts +0 -100
- package/src/shared/controllers/index.ts +0 -8
- package/src/shared/decorators/debounce.ts +0 -19
- package/src/shared/decorators/index.ts +0 -1
- package/src/shared/directives/index.ts +0 -1
- package/src/shared/directives/safeStyleMap.ts +0 -108
- package/src/shared/index.ts +0 -7
- package/src/shared/mixins/AttachInternals.ts +0 -48
- package/src/shared/mixins/Checked.ts +0 -50
- package/src/shared/mixins/CheckedIndeterminate.ts +0 -47
- package/src/shared/mixins/CheckedOrSelected.ts +0 -36
- package/src/shared/mixins/ConstraintValidation.ts +0 -213
- package/src/shared/mixins/Constructor.ts +0 -2
- package/src/shared/mixins/Dirty.ts +0 -71
- package/src/shared/mixins/Disabled.ts +0 -49
- package/src/shared/mixins/DisabledInteractive.ts +0 -78
- package/src/shared/mixins/EventAttribute.ts +0 -25
- package/src/shared/mixins/Focusable.ts +0 -52
- package/src/shared/mixins/FormAssociated.ts +0 -152
- package/src/shared/mixins/FormSubmitter.ts +0 -123
- package/src/shared/mixins/HtmlFor.ts +0 -89
- package/src/shared/mixins/KeyboardClick.ts +0 -46
- package/src/shared/mixins/Labelled.ts +0 -88
- package/src/shared/mixins/LinkButton.ts +0 -169
- package/src/shared/mixins/ReadOnly.ts +0 -48
- package/src/shared/mixins/Required.ts +0 -50
- package/src/shared/mixins/RequiredConstraintValidation.ts +0 -45
- package/src/shared/mixins/Role.ts +0 -134
- package/src/shared/mixins/Selected.ts +0 -50
- package/src/shared/mixins/Touched.ts +0 -71
- package/src/shared/mixins/Vertical.ts +0 -44
- package/src/shared/mixins/hasKeys.ts +0 -10
- package/src/shared/mixins/index.ts +0 -24
- package/src/shared/primitives/CollapsibleElement.ts +0 -227
- package/src/shared/primitives/ElevationElement.ts +0 -254
- package/src/shared/primitives/ElevationLevel.ts +0 -2
- package/src/shared/primitives/ElevationToken.ts +0 -18
- package/src/shared/primitives/FocusRingElement.ts +0 -199
- package/src/shared/primitives/FocusRingToken.ts +0 -24
- package/src/shared/primitives/PseudoCheckboxElement.ts +0 -116
- package/src/shared/primitives/PseudoRadioElement.ts +0 -83
- package/src/shared/primitives/RippleElement.ts +0 -289
- package/src/shared/primitives/RippleToken.ts +0 -15
- package/src/shared/primitives/ScrollContainerElement.ts +0 -151
- package/src/shared/primitives/ScrollDividers.ts +0 -2
- package/src/shared/primitives/SlideElement.ts +0 -128
- package/src/shared/primitives/StateLayerElement.ts +0 -191
- package/src/shared/primitives/StateLayerToken.ts +0 -16
- package/src/shared/primitives/TextOverflowElement.ts +0 -60
- package/src/shared/primitives/index.ts +0 -12
- package/src/shared/tokens/ColorToken.ts +0 -142
- package/src/shared/tokens/DensityToken.ts +0 -23
- package/src/shared/tokens/DesignToken.ts +0 -35
- package/src/shared/tokens/ElevationToken.ts +0 -115
- package/src/shared/tokens/MotionToken.ts +0 -107
- package/src/shared/tokens/ScrollbarToken.ts +0 -13
- package/src/shared/tokens/ShapeToken.ts +0 -138
- package/src/shared/tokens/StateToken.ts +0 -13
- package/src/shared/tokens/TypescaleToken.ts +0 -230
- package/src/shared/tokens/index.ts +0 -1
- package/src/shared/utils/getTextContent.ts +0 -31
- package/src/shared/utils/guid.ts +0 -11
- package/src/shared/utils/hasAssignedNodes.ts +0 -8
- package/src/shared/utils/index.ts +0 -5
- package/src/shared/utils/prefersReducedMotion.ts +0 -9
- package/src/shared/utils/scrollIntoViewIfNeeded.ts +0 -18
- package/tsconfig.json +0 -9
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ReactiveControllerHost } from "lit";
|
|
2
|
-
|
|
3
|
-
import { MonitorControllerBase, MonitorControllerOptions } from "./MonitorControllerBase";
|
|
4
|
-
|
|
5
|
-
/** The callback function invoked when the focused state of an element changes. */
|
|
6
|
-
export type FocusControllerCallback = (focused: boolean, focusVisible: boolean, target: HTMLElement) => void;
|
|
7
|
-
|
|
8
|
-
/** Encapsulates options used to configure a `FocusController`. */
|
|
9
|
-
export interface FocusControllerOptions extends MonitorControllerOptions {
|
|
10
|
-
/** The callback invoked when the focused state of an element changes. */
|
|
11
|
-
callback: FocusControllerCallback;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** A `ReactiveController` used to monitor the focused state of one or more elements. */
|
|
15
|
-
export class FocusController extends MonitorControllerBase {
|
|
16
|
-
/** @private */ readonly #callback: FocusControllerCallback;
|
|
17
|
-
/** @private */ readonly #focusInHandler = (e: Event) => this.#handleFocusIn(e);
|
|
18
|
-
/** @private */ readonly #focusOutHandler = (e: Event) => this.#handleFocusOut(e);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Initializes a new instance of this class.
|
|
22
|
-
* @param {ReactiveControllerHost & HTMLElement} host The host element to which this controller will be added.
|
|
23
|
-
* @param {FocusControllerOptions} options Options used to configure this controller.
|
|
24
|
-
*/
|
|
25
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: FocusControllerOptions) {
|
|
26
|
-
super(host, options);
|
|
27
|
-
this.#callback = options.callback;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Starts observing the specified element.
|
|
32
|
-
* @param {HTMLElement} target The element to start observing.
|
|
33
|
-
*/
|
|
34
|
-
protected override _observe(target: HTMLElement): void {
|
|
35
|
-
target.addEventListener("keydown", this.#focusInHandler);
|
|
36
|
-
target.addEventListener("focusin", this.#focusInHandler);
|
|
37
|
-
target.addEventListener("focusout", this.#focusOutHandler);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Stops observing the specified element.
|
|
42
|
-
* @param {HTMLElement} target The element to stop observing.
|
|
43
|
-
*/
|
|
44
|
-
protected override _unobserve(target: HTMLElement): void {
|
|
45
|
-
target.removeEventListener("keydown", this.#focusInHandler);
|
|
46
|
-
target.removeEventListener("focusin", this.#focusInHandler);
|
|
47
|
-
target.removeEventListener("focusout", this.#focusOutHandler);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** @private */
|
|
51
|
-
#handleFocusIn(e: Event): void {
|
|
52
|
-
const target = e.target as HTMLElement;
|
|
53
|
-
this.#callback(true, target.matches(":focus-visible") || matchMedia("(forced-colors: active)").matches, target);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** @private */
|
|
57
|
-
#handleFocusOut(e: Event): void {
|
|
58
|
-
this.#callback(false, false, e.target as HTMLElement);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { ReactiveControllerHost } from "lit";
|
|
2
|
-
|
|
3
|
-
import { MonitorControllerBase, MonitorControllerOptions } from "./MonitorControllerBase";
|
|
4
|
-
|
|
5
|
-
/** The callback function invoked when the hover state of an element changes. */
|
|
6
|
-
export type HoverControllerCallback = (hovering: boolean, target: HTMLElement) => void;
|
|
7
|
-
|
|
8
|
-
/** Encapsulates options used to configure a `HoverController`. */
|
|
9
|
-
export interface HoverControllerOptions extends MonitorControllerOptions {
|
|
10
|
-
/** The callback invoked when the hover state of an element changes. */
|
|
11
|
-
callback: HoverControllerCallback;
|
|
12
|
-
|
|
13
|
-
/** The delay, in milliseconds, before reporting hover start. */
|
|
14
|
-
startDelay?: number;
|
|
15
|
-
|
|
16
|
-
/** The delay, in milliseconds, before reporting hover end. */
|
|
17
|
-
endDelay?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** A `ReactiveController` used to monitor the hover state of one or more elements. */
|
|
21
|
-
export class HoverController extends MonitorControllerBase {
|
|
22
|
-
/** @private */ readonly #callback: HoverControllerCallback;
|
|
23
|
-
/** @private */ readonly #startDelays = new Map<HTMLElement, number>();
|
|
24
|
-
/** @private */ readonly #endDelays = new Map<HTMLElement, number>();
|
|
25
|
-
/** @private */ readonly #pointerInHandler = (e: Event) => this.#handlePointerEnter(e);
|
|
26
|
-
/** @private */ readonly #pointerLeaveHandler = (e: Event) => this.#handlePointerLeave(e);
|
|
27
|
-
|
|
28
|
-
/** The delay, in milliseconds, before reporting hover start. */
|
|
29
|
-
startDelay: number;
|
|
30
|
-
|
|
31
|
-
/** The delay, in milliseconds, before reporting hover end. */
|
|
32
|
-
endDelay: number;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Initializes a new instance of this class.
|
|
36
|
-
* @param {ReactiveControllerHost & HTMLElement} host The host element to which this controller will be added.
|
|
37
|
-
* @param {HoverControllerOptions} options Options used to configure this controller.
|
|
38
|
-
*/
|
|
39
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: HoverControllerOptions) {
|
|
40
|
-
super(host, options);
|
|
41
|
-
this.#callback = options.callback;
|
|
42
|
-
this.startDelay = options.startDelay ?? 0;
|
|
43
|
-
this.endDelay = options.endDelay ?? 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Clears any hover delays for all targets. */
|
|
47
|
-
clearDelays(): void {
|
|
48
|
-
for (const target of this.targets) {
|
|
49
|
-
this.#clearDelays(target);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Starts observing the specified element.
|
|
55
|
-
* @param {HTMLElement} target The element to start observing.
|
|
56
|
-
*/
|
|
57
|
-
protected override _observe(target: HTMLElement): void {
|
|
58
|
-
target.addEventListener("pointerenter", this.#pointerInHandler);
|
|
59
|
-
target.addEventListener("pointerleave", this.#pointerLeaveHandler);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Stops observing the specified element.
|
|
64
|
-
* @param {HTMLElement} target The element to stop observing.
|
|
65
|
-
*/
|
|
66
|
-
protected override _unobserve(target: HTMLElement): void {
|
|
67
|
-
target.removeEventListener("pointerenter", this.#pointerInHandler);
|
|
68
|
-
target.removeEventListener("pointerleave", this.#pointerLeaveHandler);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** @private */
|
|
72
|
-
#clearDelays(target: HTMLElement): void {
|
|
73
|
-
this.#clearStartDelay(target);
|
|
74
|
-
this.#clearEndDelay(target);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** @private */
|
|
78
|
-
#clearStartDelay(target: HTMLElement): boolean {
|
|
79
|
-
if (this.#startDelays.has(target)) {
|
|
80
|
-
clearTimeout(this.#startDelays.get(target));
|
|
81
|
-
return this.#startDelays.delete(target);
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** @private */
|
|
87
|
-
#clearEndDelay(target: HTMLElement): boolean {
|
|
88
|
-
if (this.#endDelays.has(target)) {
|
|
89
|
-
clearTimeout(this.#endDelays.get(target));
|
|
90
|
-
return this.#endDelays.delete(target);
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** @private */
|
|
96
|
-
#handlePointerEnter(e: Event): void {
|
|
97
|
-
const target = e.target as HTMLElement;
|
|
98
|
-
|
|
99
|
-
// If there is a pending end delay, cancel it.
|
|
100
|
-
this.#clearEndDelay(target);
|
|
101
|
-
|
|
102
|
-
// Otherwise, if there is a pending start delay, cancel it and start a new one.
|
|
103
|
-
if (this.startDelay > 0) {
|
|
104
|
-
this.#clearStartDelay(target);
|
|
105
|
-
this.#startDelays.set(
|
|
106
|
-
target,
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
this.#startDelays.delete(target);
|
|
109
|
-
this.#callback(true, target);
|
|
110
|
-
}, this.startDelay)
|
|
111
|
-
);
|
|
112
|
-
} else {
|
|
113
|
-
// Otherwise, report the start.
|
|
114
|
-
this.#callback(true, target);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** @private */
|
|
119
|
-
#handlePointerLeave(e: Event): void {
|
|
120
|
-
const target = e.target as HTMLElement;
|
|
121
|
-
|
|
122
|
-
// If there is a pending start delay, cancel it and do not report the end.
|
|
123
|
-
if (this.#clearStartDelay(target)) return;
|
|
124
|
-
|
|
125
|
-
// Otherwise, if there is a pending end delay, cancel it and start a new one.
|
|
126
|
-
if (this.endDelay > 0) {
|
|
127
|
-
this.#clearEndDelay(target);
|
|
128
|
-
this.#endDelays.set(
|
|
129
|
-
target,
|
|
130
|
-
setTimeout(() => {
|
|
131
|
-
this.#endDelays.delete(target);
|
|
132
|
-
this.#callback(false, target);
|
|
133
|
-
}, this.endDelay)
|
|
134
|
-
);
|
|
135
|
-
} else {
|
|
136
|
-
// Otherwise, report the end.
|
|
137
|
-
this.#callback(false, target);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { isServer, ReactiveControllerHost } from "lit";
|
|
2
|
-
|
|
3
|
-
import { MonitorControllerBase, MonitorControllerOptions } from "./MonitorControllerBase";
|
|
4
|
-
|
|
5
|
-
/** The callback function for a `IntersectionController`. */
|
|
6
|
-
export type IntersectionControllerCallback = (...args: Parameters<IntersectionObserverCallback>) => void;
|
|
7
|
-
|
|
8
|
-
/** Encapsulates options used to configure a `IntersectionController`. */
|
|
9
|
-
export interface IntersectionControllerOptions extends MonitorControllerOptions {
|
|
10
|
-
/** The callback used to process detected changes. */
|
|
11
|
-
callback: IntersectionControllerCallback;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* By default, the `callback` is invoked without changes when a
|
|
15
|
-
* target is observed in order to help maintain initial state. Use
|
|
16
|
-
* `skipInitial` to skip this step.
|
|
17
|
-
*/
|
|
18
|
-
skipInitial?: boolean;
|
|
19
|
-
|
|
20
|
-
/** The configuration object for the underlying `IntersectionObserver`. */
|
|
21
|
-
init?: IntersectionObserverInit;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** A `ReactiveController` used to monitor changes in the intersection of a target element with an ancestor element. */
|
|
25
|
-
export class IntersectionController extends MonitorControllerBase {
|
|
26
|
-
/** @private */ #host: ReactiveControllerHost;
|
|
27
|
-
/** @private */ #callback: IntersectionControllerCallback;
|
|
28
|
-
/** @private */ #skipInitial = false;
|
|
29
|
-
/** @private */ #observer?: IntersectionObserver;
|
|
30
|
-
/** @private */ #unobservedUpdate = true;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Initializes a new instance of the `IntersectionController` class.
|
|
34
|
-
* @param {ReactiveControllerHost & HTMLElement} host The host element to which this controller will be added.
|
|
35
|
-
* @param {IntersectionControllerOptions} options Options used to configure this controller.
|
|
36
|
-
*/
|
|
37
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: IntersectionControllerOptions) {
|
|
38
|
-
super(host, options);
|
|
39
|
-
|
|
40
|
-
this.#host = host;
|
|
41
|
-
this.#callback = options.callback;
|
|
42
|
-
this.#skipInitial = options.skipInitial ?? false;
|
|
43
|
-
|
|
44
|
-
if (isServer) return;
|
|
45
|
-
if (!window.IntersectionObserver) {
|
|
46
|
-
console.warn("IntersectionController error: the browser does not support IntersectionObserver.");
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.#observer = new IntersectionObserver((entries, observer) => {
|
|
51
|
-
this.#callback(entries, observer);
|
|
52
|
-
this.#host.requestUpdate();
|
|
53
|
-
}, options.init);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** @inheritdoc */
|
|
57
|
-
override async hostUpdated(): Promise<void> {
|
|
58
|
-
if (this.#observer && !this.#skipInitial && this.#unobservedUpdate) {
|
|
59
|
-
this.#callback([], this.#observer);
|
|
60
|
-
}
|
|
61
|
-
this.#unobservedUpdate = false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Starts observing the specified element.
|
|
66
|
-
* @param {HTMLElement} target The element to start observing.
|
|
67
|
-
*/
|
|
68
|
-
protected override _observe(target: HTMLElement): void {
|
|
69
|
-
this.#observer?.observe(target);
|
|
70
|
-
this.#unobservedUpdate = true;
|
|
71
|
-
this.#host.requestUpdate();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Stops observing the specified element.
|
|
76
|
-
* @param {HTMLElement} target The element to stop observing.
|
|
77
|
-
*/
|
|
78
|
-
protected override _unobserve(target: HTMLElement): void {
|
|
79
|
-
this.#observer?.unobserve(target);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { ReactiveControllerHost } from "lit";
|
|
2
|
-
|
|
3
|
-
import { MonitorControllerBase, MonitorControllerOptions } from "./MonitorControllerBase";
|
|
4
|
-
|
|
5
|
-
/** The callback function invoked when a long press gesture is detected. */
|
|
6
|
-
export type LongPressControllerCallback = (pressed: boolean, target: HTMLElement) => void;
|
|
7
|
-
|
|
8
|
-
/** Encapsulates options used to configure a `LongPressController`. */
|
|
9
|
-
export interface LongPressControllerOptions extends MonitorControllerOptions {
|
|
10
|
-
/** The callback invoked when the pressed state of an element changes. */
|
|
11
|
-
callback: LongPressControllerCallback;
|
|
12
|
-
|
|
13
|
-
/** The amount of time, in milliseconds, a touch gesture must be held. */
|
|
14
|
-
threshold?: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** A `ReactiveController` used to detect a long press gesture. */
|
|
18
|
-
export class LongPressController extends MonitorControllerBase {
|
|
19
|
-
/** @private */ readonly #callback: LongPressControllerCallback;
|
|
20
|
-
/** @private */ readonly #threshold: number;
|
|
21
|
-
/** @private */ readonly #pressedTargets = new Set<HTMLElement>();
|
|
22
|
-
/** @private */ readonly #pressedTimeouts = new Map<HTMLElement, number>();
|
|
23
|
-
|
|
24
|
-
/** @private */ readonly #touchStartHandler = (e: TouchEvent) => this.#handleTouchStart(e);
|
|
25
|
-
/** @private */ readonly #touchEndOrCancelHandler = (e: TouchEvent) => this.#handleTouchEndOrCancel(e);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Initializes a new instance of this class.
|
|
29
|
-
* @param {ReactiveControllerHost & HTMLElement} host The host element to which this controller will be added.
|
|
30
|
-
* @param {LongPressControllerOptions} options Options used to configure this controller.
|
|
31
|
-
*/
|
|
32
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: LongPressControllerOptions) {
|
|
33
|
-
super(host, options);
|
|
34
|
-
this.#callback = options.callback;
|
|
35
|
-
this.#threshold = options.threshold ?? 500;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Starts observing the specified element.
|
|
40
|
-
* @param {HTMLElement} target The element to start observing.
|
|
41
|
-
*/
|
|
42
|
-
protected override _observe(target: HTMLElement): void {
|
|
43
|
-
target.addEventListener("touchstart", this.#touchStartHandler);
|
|
44
|
-
target.addEventListener("touchend", this.#touchEndOrCancelHandler);
|
|
45
|
-
target.addEventListener("touchcancel", this.#touchEndOrCancelHandler);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Stops observing the specified element.
|
|
50
|
-
* @param {HTMLElement} target The element to stop observing.
|
|
51
|
-
*/
|
|
52
|
-
protected override _unobserve(target: HTMLElement): void {
|
|
53
|
-
target.removeEventListener("touchstart", this.#touchStartHandler);
|
|
54
|
-
target.removeEventListener("touchend", this.#touchEndOrCancelHandler);
|
|
55
|
-
target.removeEventListener("touchcancel", this.#touchEndOrCancelHandler);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @private */
|
|
59
|
-
#handleTouchStart(e: TouchEvent): void {
|
|
60
|
-
if (e.currentTarget instanceof HTMLElement && this.isObserving(e.currentTarget)) {
|
|
61
|
-
const target = e.currentTarget;
|
|
62
|
-
this.#pressedTimeouts.set(
|
|
63
|
-
target,
|
|
64
|
-
setTimeout(() => {
|
|
65
|
-
this.#pressedTargets.add(target);
|
|
66
|
-
this.#pressedTimeouts.delete(target);
|
|
67
|
-
this.#callback(true, target);
|
|
68
|
-
}, this.#threshold)
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** @private */
|
|
74
|
-
#handleTouchEndOrCancel(e: TouchEvent): void {
|
|
75
|
-
if (e.currentTarget instanceof HTMLElement && this.isObserving(e.currentTarget)) {
|
|
76
|
-
const target = e.currentTarget;
|
|
77
|
-
if (this.#pressedTargets.has(target)) {
|
|
78
|
-
this.#callback(false, target);
|
|
79
|
-
this.#pressedTargets.delete(target);
|
|
80
|
-
}
|
|
81
|
-
if (this.#pressedTimeouts.has(target)) {
|
|
82
|
-
clearTimeout(this.#pressedTimeouts.get(target));
|
|
83
|
-
this.#pressedTimeouts.delete(target);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
2
|
-
|
|
3
|
-
/** Encapsulates options used to monitor the state of one or more elements. */
|
|
4
|
-
export interface MonitorControllerOptions {
|
|
5
|
-
/**
|
|
6
|
-
* The element to observe. In addition to configuring the target here,
|
|
7
|
-
* the `observe` method can be called to observe additional targets. When
|
|
8
|
-
* not specified, the target defaults to the `host`. If set to `null`, no
|
|
9
|
-
* target is automatically observed. Only the configured target will be
|
|
10
|
-
* re-observed if the host connects again after unobserving via disconnection.
|
|
11
|
-
*/
|
|
12
|
-
target?: HTMLElement | null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A base implementation for a `ReactiveController` used to monitor the state of one
|
|
17
|
-
* or more elements. This class must be inherited.
|
|
18
|
-
*/
|
|
19
|
-
export abstract class MonitorControllerBase implements ReactiveController {
|
|
20
|
-
/** @private */ readonly #host: ReactiveControllerHost & HTMLElement;
|
|
21
|
-
/** @private */ readonly #target?: HTMLElement | null;
|
|
22
|
-
/** @private */ readonly #targets = new Set<HTMLElement>();
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Initializes the `MonitorControllerBase` base class values when called by a derived class.
|
|
26
|
-
* @param {ReactiveControllerHost & HTMLElement} host The host element to which this controller will be added.
|
|
27
|
-
* @param {MonitorControllerOptions} options Options used to configure this controller.
|
|
28
|
-
*/
|
|
29
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: MonitorControllerOptions) {
|
|
30
|
-
this.#host = host;
|
|
31
|
-
this.#target = options.target;
|
|
32
|
-
this.#host.addController(this);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** The targets being observed. */
|
|
36
|
-
get targets(): Iterable<HTMLElement> {
|
|
37
|
-
return this.#targets.values();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** @inheritdoc */
|
|
41
|
-
hostConnected(): void {
|
|
42
|
-
// Target defaults to host unless explicitly null.
|
|
43
|
-
if (this.#target !== null) {
|
|
44
|
-
this.observe(this.#target ?? this.#host);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** @inheritdoc */
|
|
49
|
-
hostDisconnected(): void {
|
|
50
|
-
this.#targets.forEach((x) => this.unobserve(x));
|
|
51
|
-
this.#targets.clear();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** @inheritdoc */
|
|
55
|
-
hostUpdate?(): void;
|
|
56
|
-
|
|
57
|
-
/** @inheritdoc */
|
|
58
|
-
hostUpdated?(): void;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Starts observing the specified element.
|
|
62
|
-
* @param {HTMLElement} target The element to start observing.
|
|
63
|
-
*/
|
|
64
|
-
observe(target: HTMLElement): void {
|
|
65
|
-
if (this.#targets.has(target)) return;
|
|
66
|
-
this.#targets.add(target);
|
|
67
|
-
this._observe(target);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Determines whether the specified element is being observed.
|
|
72
|
-
* @param {HTMLElement} target The element to test.
|
|
73
|
-
* @returns {boolean} Whether `target` is being observed.
|
|
74
|
-
*/
|
|
75
|
-
isObserving(target: HTMLElement): boolean {
|
|
76
|
-
return this.#targets.has(target);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Stops observing the specified element.
|
|
81
|
-
* @param {HTMLElement} target The element to stop observing.
|
|
82
|
-
*/
|
|
83
|
-
unobserve(target: HTMLElement): void {
|
|
84
|
-
if (!this.#targets.delete(target)) return;
|
|
85
|
-
this._unobserve(target);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* When implemented by a derived class, starts observing the specified element.
|
|
90
|
-
* @param {HTMLElement} target The element to start observing.
|
|
91
|
-
*/
|
|
92
|
-
protected abstract _observe(target: HTMLElement): void;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* When implemented by a derived class, stops observing the specified element.
|
|
96
|
-
* @param {HTMLElement} target The element to stop observing.
|
|
97
|
-
*/
|
|
98
|
-
protected abstract _unobserve(target: HTMLElement): void;
|
|
99
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { isServer, ReactiveControllerHost } from "lit";
|
|
2
|
-
|
|
3
|
-
import { MonitorControllerBase, MonitorControllerOptions } from "./MonitorControllerBase";
|
|
4
|
-
|
|
5
|
-
/** Encapsulates options used to configure a `MutationController`. */
|
|
6
|
-
export interface MutationControllerOptions extends MonitorControllerOptions {
|
|
7
|
-
/** The callback used to process detected changes. */
|
|
8
|
-
callback: MutationCallback;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* By default, the `callback` is invoked without changes when a
|
|
12
|
-
* target is observed in order to help maintain initial state. Use
|
|
13
|
-
* `skipInitial` to skip this step.
|
|
14
|
-
*/
|
|
15
|
-
skipInitial?: boolean;
|
|
16
|
-
|
|
17
|
-
/** The configuration object for the underlying `MutationObserver`. */
|
|
18
|
-
config?: MutationObserverInit;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A `ReactiveController` that integrates a `MutationObserver` with an element's reactive update lifecycle
|
|
23
|
-
* to detect arbitrary changes to DOM, including nodes being added or removed and attributes changing.
|
|
24
|
-
*/
|
|
25
|
-
export class MutationController extends MonitorControllerBase {
|
|
26
|
-
/** @private */ #host: ReactiveControllerHost;
|
|
27
|
-
/** @private */ #callback: MutationCallback;
|
|
28
|
-
/** @private */ #skipInitial = false;
|
|
29
|
-
/** @private */ #config?: MutationObserverInit;
|
|
30
|
-
/** @private */ #observer?: MutationObserver;
|
|
31
|
-
/** @private */ #unobservedUpdate = true;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Initializes a new instance of the `MutationController` class.
|
|
35
|
-
* @param {ReactiveControllerHost & HTMLElement} host The host element to which this controller will be added.
|
|
36
|
-
* @param {MutationControllerOptions} options Options used to configure this controller.
|
|
37
|
-
*/
|
|
38
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: MutationControllerOptions) {
|
|
39
|
-
super(host, options);
|
|
40
|
-
|
|
41
|
-
this.#host = host;
|
|
42
|
-
this.#callback = options.callback;
|
|
43
|
-
this.#skipInitial = options.skipInitial ?? false;
|
|
44
|
-
this.#config = options.config;
|
|
45
|
-
|
|
46
|
-
if (isServer) return;
|
|
47
|
-
if (!window.MutationObserver) {
|
|
48
|
-
console.warn("MutationController error: the browser does not support MutationObserver.");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.#observer = new MutationObserver((records, observer) => {
|
|
53
|
-
this.#callback(records, observer);
|
|
54
|
-
this.#host.requestUpdate();
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @inheritdoc */
|
|
59
|
-
override async hostUpdated(): Promise<void> {
|
|
60
|
-
if (this.#observer && !this.#skipInitial && this.#unobservedUpdate) {
|
|
61
|
-
const records = this.#observer.takeRecords();
|
|
62
|
-
if (records.length > 0) {
|
|
63
|
-
this.#callback(records, this.#observer);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.#unobservedUpdate = false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** @inheritdoc */
|
|
70
|
-
override hostDisconnected(): void {
|
|
71
|
-
super.hostDisconnected();
|
|
72
|
-
this.#observer?.disconnect();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** @inheritdoc */
|
|
76
|
-
protected override _observe(target: HTMLElement): void {
|
|
77
|
-
this.#observer?.observe(target, this.#config);
|
|
78
|
-
this.#unobservedUpdate = true;
|
|
79
|
-
this.#host.requestUpdate();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** @inheritdoc */
|
|
83
|
-
protected override _unobserve(): void {
|
|
84
|
-
this.#observer?.disconnect();
|
|
85
|
-
for (const target of this.targets) {
|
|
86
|
-
this.#observer?.observe(target, this.#config);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { ReactiveControllerHost } from "lit";
|
|
2
|
-
|
|
3
|
-
import { MonitorControllerBase, MonitorControllerOptions } from "./MonitorControllerBase";
|
|
4
|
-
|
|
5
|
-
/** The callback function invoked when the pressed state of an element changes. */
|
|
6
|
-
export type PressedControllerCallback = (
|
|
7
|
-
pressed: boolean,
|
|
8
|
-
point: { x: number; y: number },
|
|
9
|
-
target: HTMLElement
|
|
10
|
-
) => void;
|
|
11
|
-
|
|
12
|
-
/** Encapsulates options used to configure a `PressedController`. */
|
|
13
|
-
export interface PressedControllerOptions extends MonitorControllerOptions {
|
|
14
|
-
/** The callback invoked when the pressed state of an element changes. */
|
|
15
|
-
callback: PressedControllerCallback;
|
|
16
|
-
|
|
17
|
-
/** Whether events are captured. */
|
|
18
|
-
capture?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A function used to determine whether a given keyboard key toggles the pressed state.
|
|
22
|
-
* @param key The `KeyboardEvent.key` to test.
|
|
23
|
-
* @returns Whether `key` toggles the pressed state.
|
|
24
|
-
*/
|
|
25
|
-
isPressedKey?: (key: string) => boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** A `ReactiveController` used to monitor the pressed state of one or more elements. */
|
|
29
|
-
export class PressedController extends MonitorControllerBase {
|
|
30
|
-
/** @private */ readonly #capture?: boolean;
|
|
31
|
-
/** @private */ readonly #callback: PressedControllerCallback;
|
|
32
|
-
/** @private */ readonly #isPressedKey?: (key: string) => boolean;
|
|
33
|
-
/** @private */ readonly #pressedTargets = new Set<HTMLElement>();
|
|
34
|
-
|
|
35
|
-
/** @private */ readonly #pointerDownHandler = (e: PointerEvent) => this.#handlePointerDown(e);
|
|
36
|
-
/** @private */ readonly #pointerUpHandler = (e: PointerEvent) => this.#handlePointerUp(e);
|
|
37
|
-
/** @private */ readonly #keyDownHandler = (e: KeyboardEvent) => this.#handleKeyDown(e);
|
|
38
|
-
/** @private */ readonly #keyUpHandler = (e: KeyboardEvent) => this.#handleKeyUp(e);
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Initializes a new instance of this class.
|
|
42
|
-
* @param {ReactiveControllerHost & HTMLElement} host The host element to which this controller will be added.
|
|
43
|
-
* @param {PressedControllerOptions} options Options used to configure this controller.
|
|
44
|
-
*/
|
|
45
|
-
constructor(host: ReactiveControllerHost & HTMLElement, options: PressedControllerOptions) {
|
|
46
|
-
super(host, options);
|
|
47
|
-
|
|
48
|
-
this.#capture = options.capture;
|
|
49
|
-
this.#callback = options.callback;
|
|
50
|
-
this.#isPressedKey = options.isPressedKey;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** @inheritdoc */
|
|
54
|
-
override hostConnected(): void {
|
|
55
|
-
document.addEventListener("pointerup", this.#pointerUpHandler, { capture: this.#capture });
|
|
56
|
-
super.hostConnected();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** @inheritdoc */
|
|
60
|
-
override hostDisconnected(): void {
|
|
61
|
-
document.removeEventListener("pointerup", this.#pointerUpHandler, { capture: this.#capture });
|
|
62
|
-
super.hostDisconnected();
|
|
63
|
-
this.#pressedTargets.clear();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Starts observing the specified element.
|
|
68
|
-
* @param {HTMLElement} target The element to start observing.
|
|
69
|
-
*/
|
|
70
|
-
protected override _observe(target: HTMLElement): void {
|
|
71
|
-
target.addEventListener("pointerdown", this.#pointerDownHandler, { capture: this.#capture });
|
|
72
|
-
if (this.#isPressedKey) {
|
|
73
|
-
target.addEventListener("keydown", this.#keyDownHandler, { capture: this.#capture });
|
|
74
|
-
target.addEventListener("keyup", this.#keyUpHandler, { capture: this.#capture });
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Stops observing the specified element.
|
|
80
|
-
* @param {HTMLElement} target The element to stop observing.
|
|
81
|
-
*/
|
|
82
|
-
protected override _unobserve(target: HTMLElement): void {
|
|
83
|
-
target.removeEventListener("pointerdown", this.#pointerDownHandler, { capture: this.#capture });
|
|
84
|
-
|
|
85
|
-
if (this.#isPressedKey) {
|
|
86
|
-
target.removeEventListener("keydown", this.#keyDownHandler, { capture: this.#capture });
|
|
87
|
-
target.removeEventListener("keyup", this.#keyUpHandler, { capture: this.#capture });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** @private */
|
|
92
|
-
#handlePointerDown(e: PointerEvent): void {
|
|
93
|
-
if (e.pointerType === "mouse" && e.button > 1) return;
|
|
94
|
-
|
|
95
|
-
for (const target of e.composedPath()) {
|
|
96
|
-
if (target instanceof HTMLElement && this.isObserving(target)) {
|
|
97
|
-
this.#pressedTargets.add(target);
|
|
98
|
-
this.#callback(true, { x: e.x, y: e.y }, target);
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** @private */
|
|
105
|
-
#handlePointerUp(e: PointerEvent): void {
|
|
106
|
-
if (e.pointerType === "mouse" && e.button > 1) return;
|
|
107
|
-
|
|
108
|
-
this.#pressedTargets.forEach((x) => this.#callback(false, { x: e.x, y: e.y }, x));
|
|
109
|
-
this.#pressedTargets.clear();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** @private */
|
|
113
|
-
#handleKeyDown(e: KeyboardEvent): void {
|
|
114
|
-
const target = e.target as HTMLElement;
|
|
115
|
-
|
|
116
|
-
if (!this.#pressedTargets.has(target) && this.#isPressedKey?.(e.key)) {
|
|
117
|
-
if (e.key === " ") {
|
|
118
|
-
e.preventDefault();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
this.#pressedTargets.add(target);
|
|
122
|
-
const bounds = target.getBoundingClientRect();
|
|
123
|
-
this.#callback(true, { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 }, target);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** @private */
|
|
128
|
-
#handleKeyUp(e: KeyboardEvent): void {
|
|
129
|
-
const target = e.target as HTMLElement;
|
|
130
|
-
|
|
131
|
-
if (this.#pressedTargets.has(target) && this.#isPressedKey?.(e.key)) {
|
|
132
|
-
this.#pressedTargets.delete(target);
|
|
133
|
-
const bounds = target.getBoundingClientRect();
|
|
134
|
-
this.#callback(false, { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 }, target);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|