igniteui-webcomponents 7.3.0-beta.0 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/animations/player.d.ts +7 -2
- package/animations/player.js +1 -2
- package/animations/player.js.map +1 -1
- package/components/accordion/accordion.js +4 -16
- package/components/accordion/accordion.js.map +1 -1
- package/components/avatar/avatar.d.ts +0 -1
- package/components/avatar/avatar.js +5 -9
- package/components/avatar/avatar.js.map +1 -1
- package/components/badge/badge.d.ts +1 -3
- package/components/badge/badge.js +4 -8
- package/components/badge/badge.js.map +1 -1
- package/components/banner/banner.d.ts +6 -5
- package/components/banner/banner.js +19 -17
- package/components/banner/banner.js.map +1 -1
- package/components/button/button-base.d.ts +1 -1
- package/components/button/button-base.js.map +1 -1
- package/components/button-group/button-group.d.ts +0 -1
- package/components/button-group/button-group.js +12 -17
- package/components/button-group/button-group.js.map +1 -1
- package/components/calendar/base.d.ts +3 -13
- package/components/calendar/base.js +10 -31
- package/components/calendar/base.js.map +1 -1
- package/components/calendar/calendar.d.ts +2 -2
- package/components/calendar/months-view/months-view.d.ts +1 -1
- package/components/calendar/months-view/months-view.js.map +1 -1
- package/components/carousel/carousel-indicator.d.ts +1 -1
- package/components/carousel/carousel-indicator.js +13 -13
- package/components/carousel/carousel-indicator.js.map +1 -1
- package/components/carousel/carousel-slide.d.ts +0 -2
- package/components/carousel/carousel-slide.js +7 -9
- package/components/carousel/carousel-slide.js.map +1 -1
- package/components/carousel/carousel.d.ts +52 -35
- package/components/carousel/carousel.js +136 -122
- package/components/carousel/carousel.js.map +1 -1
- package/components/carousel/themes/carousel.base.css.js +1 -1
- package/components/carousel/themes/carousel.base.css.js.map +1 -1
- package/components/chat/chat-input.d.ts +1 -1
- package/components/chat/chat-input.js +21 -21
- package/components/chat/chat-input.js.map +1 -1
- package/components/chat/chat.d.ts +0 -2
- package/components/chat/chat.js +6 -12
- package/components/chat/chat.js.map +1 -1
- package/components/checkbox/checkbox-base.d.ts +1 -1
- package/components/checkbox/checkbox.d.ts +3 -5
- package/components/checkbox/checkbox.js +33 -44
- package/components/checkbox/checkbox.js.map +1 -1
- package/components/checkbox/switch.d.ts +1 -1
- package/components/checkbox/switch.js +23 -34
- package/components/checkbox/switch.js.map +1 -1
- package/components/chip/chip.d.ts +1 -14
- package/components/chip/chip.js +12 -33
- package/components/chip/chip.js.map +1 -1
- package/components/color-picker/color-picker.d.ts +261 -0
- package/components/color-picker/color-picker.js +620 -0
- package/components/color-picker/color-picker.js.map +1 -0
- package/components/color-picker/common.d.ts +37 -0
- package/components/color-picker/common.js +55 -0
- package/components/color-picker/common.js.map +1 -0
- package/components/color-picker/converters.d.ts +18 -0
- package/components/color-picker/converters.js +173 -0
- package/components/color-picker/converters.js.map +1 -0
- package/components/color-picker/model.d.ts +120 -0
- package/components/color-picker/model.js +174 -0
- package/components/color-picker/model.js.map +1 -0
- package/components/color-picker/picker-canvas.d.ts +95 -0
- package/components/color-picker/picker-canvas.js +154 -0
- package/components/color-picker/picker-canvas.js.map +1 -0
- package/components/color-picker/themes/color-picker.base.css.d.ts +1 -0
- package/components/color-picker/themes/color-picker.base.css.js +3 -0
- package/components/color-picker/themes/color-picker.base.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.bootstrap.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.bootstrap.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.bootstrap.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.fluent.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.fluent.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.fluent.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.indigo.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.indigo.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.indigo.css.js.map +1 -0
- package/components/color-picker/themes/dark/color-picker.material.css.d.ts +1 -0
- package/components/color-picker/themes/dark/color-picker.material.css.js +3 -0
- package/components/color-picker/themes/dark/color-picker.material.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.bootstrap.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.bootstrap.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.bootstrap.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.fluent.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.fluent.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.fluent.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.indigo.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.indigo.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.indigo.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.material.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.material.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.material.css.js.map +1 -0
- package/components/color-picker/themes/light/color-picker.shared.css.d.ts +1 -0
- package/components/color-picker/themes/light/color-picker.shared.css.js +3 -0
- package/components/color-picker/themes/light/color-picker.shared.css.js.map +1 -0
- package/components/color-picker/themes/picker-canvas.base.css.d.ts +1 -0
- package/components/color-picker/themes/picker-canvas.base.css.js +3 -0
- package/components/color-picker/themes/picker-canvas.base.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.bootstrap.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.bootstrap.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.bootstrap.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.common.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.common.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.common.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.fluent.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.fluent.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.fluent.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.indigo.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.indigo.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.indigo.css.js.map +1 -0
- package/components/color-picker/themes/shared/color-picker.material.css.d.ts +1 -0
- package/components/color-picker/themes/shared/color-picker.material.css.js +3 -0
- package/components/color-picker/themes/shared/color-picker.material.css.js.map +1 -0
- package/components/color-picker/themes/themes.d.ts +2 -0
- package/components/color-picker/themes/themes.js +50 -0
- package/components/color-picker/themes/themes.js.map +1 -0
- package/components/color-picker/validators.d.ts +3 -0
- package/components/color-picker/validators.js +5 -0
- package/components/color-picker/validators.js.map +1 -0
- package/components/combo/combo-item.d.ts +1 -3
- package/components/combo/combo-item.js +5 -12
- package/components/combo/combo-item.js.map +1 -1
- package/components/combo/combo.d.ts +7 -20
- package/components/combo/combo.js +59 -81
- package/components/combo/combo.js.map +1 -1
- package/components/date-picker/date-picker.base.d.ts +12 -9
- package/components/date-picker/date-picker.base.js +24 -31
- package/components/date-picker/date-picker.base.js.map +1 -1
- package/components/date-picker/date-picker.d.ts +1 -1
- package/components/date-picker/date-picker.js +3 -5
- package/components/date-picker/date-picker.js.map +1 -1
- package/components/date-range-picker/date-range-input.d.ts +2 -4
- package/components/date-range-picker/date-range-input.js +6 -37
- package/components/date-range-picker/date-range-input.js.map +1 -1
- package/components/date-range-picker/date-range-picker.d.ts +2 -5
- package/components/date-range-picker/date-range-picker.js +15 -28
- package/components/date-range-picker/date-range-picker.js.map +1 -1
- package/components/date-range-picker/predefined-ranges-area.d.ts +2 -2
- package/components/date-range-picker/predefined-ranges-area.js +4 -6
- package/components/date-range-picker/predefined-ranges-area.js.map +1 -1
- package/components/date-range-picker/validators.d.ts +1 -1
- package/components/date-range-picker/validators.js +5 -18
- package/components/date-range-picker/validators.js.map +1 -1
- package/components/date-time-input/date-part.d.ts +2 -1
- package/components/date-time-input/date-part.js +38 -75
- package/components/date-time-input/date-part.js.map +1 -1
- package/components/date-time-input/date-time-input.base.d.ts +31 -12
- package/components/date-time-input/date-time-input.base.js +43 -11
- package/components/date-time-input/date-time-input.base.js.map +1 -1
- package/components/date-time-input/date-time-input.d.ts +1 -3
- package/components/date-time-input/date-time-input.js +7 -40
- package/components/date-time-input/date-time-input.js.map +1 -1
- package/components/date-time-input/datetime-mask-parser.d.ts +8 -0
- package/components/date-time-input/datetime-mask-parser.js +8 -8
- package/components/date-time-input/datetime-mask-parser.js.map +1 -1
- package/components/date-time-input/validators.js +3 -14
- package/components/date-time-input/validators.js.map +1 -1
- package/components/dialog/dialog.d.ts +6 -7
- package/components/dialog/dialog.js +21 -26
- package/components/dialog/dialog.js.map +1 -1
- package/components/divider/divider.d.ts +1 -4
- package/components/divider/divider.js +8 -17
- package/components/divider/divider.js.map +1 -1
- package/components/dropdown/dropdown-group.js +1 -6
- package/components/dropdown/dropdown-group.js.map +1 -1
- package/components/expansion-panel/expansion-panel.d.ts +15 -5
- package/components/expansion-panel/expansion-panel.js +23 -34
- package/components/expansion-panel/expansion-panel.js.map +1 -1
- package/components/file-input/file-input.d.ts +2 -14
- package/components/file-input/file-input.js +5 -23
- package/components/file-input/file-input.js.map +1 -1
- package/components/highlight/highlight.d.ts +6 -8
- package/components/highlight/highlight.js +12 -20
- package/components/highlight/highlight.js.map +1 -1
- package/components/icon/icon-references.js +1 -0
- package/components/icon/icon-references.js.map +1 -1
- package/components/icon/icon.d.ts +1 -1
- package/components/icon/internal-icons-lib.js +3 -0
- package/components/icon/internal-icons-lib.js.map +1 -1
- package/components/icon/registry/types.d.ts +1 -1
- package/components/icon/registry/types.js.map +1 -1
- package/components/input/input.d.ts +9 -19
- package/components/input/input.js +30 -60
- package/components/input/input.js.map +1 -1
- package/components/input/themes/shared/input.material.css.js +1 -1
- package/components/input/themes/shared/input.material.css.js.map +1 -1
- package/components/mask-input/mask-input.d.ts +1 -1
- package/components/mask-input/mask-input.js +2 -4
- package/components/mask-input/mask-input.js.map +1 -1
- package/components/nav-drawer/nav-drawer.d.ts +7 -7
- package/components/nav-drawer/nav-drawer.js +12 -23
- package/components/nav-drawer/nav-drawer.js.map +1 -1
- package/components/progress/base.d.ts +4 -7
- package/components/progress/base.js +21 -45
- package/components/progress/base.js.map +1 -1
- package/components/qr-code/qr-code.d.ts +1 -1
- package/components/qr-code/qr-code.js +3 -2
- package/components/qr-code/qr-code.js.map +1 -1
- package/components/qr-code/types.d.ts +1 -1
- package/components/qr-code/types.js.map +1 -1
- package/components/radio/controller.d.ts +2 -30
- package/components/radio/controller.js +8 -94
- package/components/radio/controller.js.map +1 -1
- package/components/radio/radio.d.ts +5 -5
- package/components/radio/radio.js +48 -58
- package/components/radio/radio.js.map +1 -1
- package/components/radio-group/radio-group.d.ts +1 -2
- package/components/radio-group/radio-group.js +2 -9
- package/components/radio-group/radio-group.js.map +1 -1
- package/components/rating/rating.d.ts +24 -12
- package/components/rating/rating.js +79 -73
- package/components/rating/rating.js.map +1 -1
- package/components/resize-container/default-ghost.js +4 -3
- package/components/resize-container/default-ghost.js.map +1 -1
- package/components/resize-container/resize-container.d.ts +1 -1
- package/components/resize-container/resize-container.js +5 -3
- package/components/resize-container/resize-container.js.map +1 -1
- package/components/resize-container/resize-controller.js +4 -3
- package/components/resize-container/resize-controller.js.map +1 -1
- package/components/select/select-group.d.ts +2 -1
- package/components/select/select-group.js +7 -11
- package/components/select/select-group.js.map +1 -1
- package/components/select/select.d.ts +3 -4
- package/components/select/select.js +23 -28
- package/components/select/select.js.map +1 -1
- package/components/slider/range-slider.d.ts +3 -2
- package/components/slider/range-slider.js +22 -70
- package/components/slider/range-slider.js.map +1 -1
- package/components/slider/slider-base.d.ts +9 -6
- package/components/slider/slider-base.js +27 -28
- package/components/slider/slider-base.js.map +1 -1
- package/components/slider/slider.js +9 -5
- package/components/slider/slider.js.map +1 -1
- package/components/splitter/splitter.d.ts +1 -1
- package/components/splitter/splitter.js.map +1 -1
- package/components/stepper/step.d.ts +3 -0
- package/components/stepper/step.js +9 -5
- package/components/stepper/step.js.map +1 -1
- package/components/stepper/stepper.d.ts +0 -11
- package/components/stepper/stepper.js +21 -86
- package/components/stepper/stepper.js.map +1 -1
- package/components/tabs/tab.d.ts +1 -1
- package/components/tabs/tab.js +6 -5
- package/components/tabs/tab.js.map +1 -1
- package/components/tabs/tabs.d.ts +1 -5
- package/components/tabs/tabs.js +12 -34
- package/components/tabs/tabs.js.map +1 -1
- package/components/textarea/textarea.d.ts +6 -7
- package/components/textarea/textarea.js +3 -10
- package/components/textarea/textarea.js.map +1 -1
- package/components/theme-provider/theme-provider.d.ts +2 -4
- package/components/theme-provider/theme-provider.js +11 -21
- package/components/theme-provider/theme-provider.js.map +1 -1
- package/components/tile-manager/tile-manager.d.ts +10 -21
- package/components/tile-manager/tile-manager.js +43 -74
- package/components/tile-manager/tile-manager.js.map +1 -1
- package/components/tile-manager/tile.d.ts +10 -18
- package/components/tile-manager/tile.js +50 -67
- package/components/tile-manager/tile.js.map +1 -1
- package/components/tooltip/tooltip.d.ts +4 -7
- package/components/tooltip/tooltip.js +20 -28
- package/components/tooltip/tooltip.js.map +1 -1
- package/components/tree/tree.d.ts +1 -14
- package/components/tree/tree.js +5 -23
- package/components/tree/tree.js.map +1 -1
- package/components/tree/tree.navigation.d.ts +1 -1
- package/components/tree/tree.navigation.js.map +1 -1
- package/components/types.d.ts +2 -0
- package/components/types.js.map +1 -1
- package/components/validation-container/validation-container.d.ts +1 -2
- package/components/validation-container/validation-container.js.map +1 -1
- package/components/virtualization/engine.d.ts +40 -38
- package/components/virtualization/engine.js.map +1 -1
- package/components/virtualization/types.d.ts +6 -5
- package/components/virtualization/types.js.map +1 -1
- package/components/virtualization/virtualization.d.ts +94 -80
- package/components/virtualization/virtualization.js +10 -2
- package/components/virtualization/virtualization.js.map +1 -1
- package/custom-elements.json +31948 -26708
- package/igniteui-webcomponents.css-data.json +1 -1
- package/igniteui-webcomponents.html-data.json +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/internals/controllers/aria-projection.d.ts +6 -6
- package/internals/controllers/aria-projection.js.map +1 -1
- package/internals/controllers/context-provider.d.ts +48 -0
- package/internals/controllers/context-provider.js +29 -0
- package/internals/controllers/context-provider.js.map +1 -0
- package/internals/controllers/drag.js +6 -6
- package/internals/controllers/drag.js.map +1 -1
- package/internals/controllers/gestures.js +3 -0
- package/internals/controllers/gestures.js.map +1 -1
- package/internals/controllers/group.d.ts +64 -0
- package/internals/controllers/group.js +104 -0
- package/internals/controllers/group.js.map +1 -0
- package/internals/controllers/internals.d.ts +16 -3
- package/internals/controllers/internals.js +10 -3
- package/internals/controllers/internals.js.map +1 -1
- package/internals/controllers/key-bindings.d.ts +6 -0
- package/internals/controllers/key-bindings.js +3 -0
- package/internals/controllers/key-bindings.js.map +1 -1
- package/internals/controllers/roving-focus.d.ts +72 -0
- package/internals/controllers/roving-focus.js +61 -0
- package/internals/controllers/roving-focus.js.map +1 -0
- package/internals/controllers/slot.d.ts +8 -0
- package/internals/controllers/slot.js +4 -0
- package/internals/controllers/slot.js.map +1 -1
- package/internals/controllers/toggle.d.ts +96 -0
- package/internals/controllers/toggle.js +65 -0
- package/internals/controllers/toggle.js.map +1 -0
- package/internals/date/converters.js +2 -5
- package/internals/date/converters.js.map +1 -1
- package/internals/date/model.d.ts +4 -0
- package/internals/date/model.js +6 -0
- package/internals/date/model.js.map +1 -1
- package/internals/decorators/coerced-property.d.ts +47 -0
- package/internals/decorators/coerced-property.js +36 -0
- package/internals/decorators/coerced-property.js.map +1 -0
- package/internals/definitions/defineAllComponents.js +2 -0
- package/internals/definitions/defineAllComponents.js.map +1 -1
- package/internals/i18n/i18n-controller.d.ts +22 -3
- package/internals/i18n/i18n-controller.js +28 -6
- package/internals/i18n/i18n-controller.js.map +1 -1
- package/internals/mixins/alert.d.ts +1 -1
- package/internals/mixins/alert.js +5 -3
- package/internals/mixins/alert.js.map +1 -1
- package/internals/mixins/combo-box.d.ts +3 -12
- package/internals/mixins/combo-box.js +6 -32
- package/internals/mixins/combo-box.js.map +1 -1
- package/internals/mixins/forms/associated.js +18 -0
- package/internals/mixins/forms/associated.js.map +1 -1
- package/internals/mixins/forms/types.d.ts +20 -1
- package/internals/mixins/forms/types.js.map +1 -1
- package/internals/mixins/i18n.d.ts +31 -0
- package/internals/mixins/i18n.js +36 -0
- package/internals/mixins/i18n.js.map +1 -0
- package/internals/mixins/mask-behavior.d.ts +6 -5
- package/internals/mixins/mask-behavior.js +1 -2
- package/internals/mixins/mask-behavior.js.map +1 -1
- package/internals/mixins/option.js +4 -2
- package/internals/mixins/option.js.map +1 -1
- package/internals/templates/masked-input.d.ts +1 -1
- package/internals/templates/masked-input.js.map +1 -1
- package/internals/templates/slotted-icon.d.ts +32 -0
- package/internals/templates/slotted-icon.js +19 -0
- package/internals/templates/slotted-icon.js.map +1 -0
- package/internals/templates/toggle-shell.d.ts +46 -0
- package/internals/templates/toggle-shell.js +38 -0
- package/internals/templates/toggle-shell.js.map +1 -0
- package/internals/timing.d.ts +32 -0
- package/internals/timing.js +20 -0
- package/internals/timing.js.map +1 -0
- package/internals/utils/arrays.d.ts +2 -2
- package/internals/utils/arrays.js.map +1 -1
- package/internals/utils/dom.d.ts +22 -0
- package/internals/utils/dom.js +15 -1
- package/internals/utils/dom.js.map +1 -1
- package/internals/utils/math.d.ts +1 -1
- package/internals/utils/math.js.map +1 -1
- package/internals/utils/types.d.ts +1 -1
- package/internals/utils/types.js.map +1 -1
- package/internals/validators.d.ts +23 -0
- package/internals/validators.js +21 -0
- package/internals/validators.js.map +1 -1
- package/package.json +3 -1
- package/theming/theming-controller.d.ts +3 -3
- package/theming/theming-controller.js.map +1 -1
- package/web-types.json +2 -2
- package/internals/decorators/watch.d.ts +0 -5
- package/internals/decorators/watch.js +0 -19
- package/internals/decorators/watch.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function createTimer(callback, defaultDelay = 0) {
|
|
2
|
+
let handle;
|
|
3
|
+
return {
|
|
4
|
+
get active() {
|
|
5
|
+
return handle !== undefined;
|
|
6
|
+
},
|
|
7
|
+
start(delay = defaultDelay) {
|
|
8
|
+
clearTimeout(handle);
|
|
9
|
+
handle = setTimeout(() => {
|
|
10
|
+
handle = undefined;
|
|
11
|
+
callback();
|
|
12
|
+
}, delay);
|
|
13
|
+
},
|
|
14
|
+
stop() {
|
|
15
|
+
clearTimeout(handle);
|
|
16
|
+
handle = undefined;
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=timing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.js","sourceRoot":"","sources":["../../src/internals/timing.ts"],"names":[],"mappings":"AAgCA,MAAM,UAAU,WAAW,CAAC,QAAoB,EAAE,YAAY,GAAG,CAAC;IAChE,IAAI,MAAiD,CAAC;IAEtD,OAAO;QACL,IAAI,MAAM;YACR,OAAO,MAAM,KAAK,SAAS,CAAC;QAC9B,CAAC;QACD,KAAK,CAAC,KAAK,GAAG,YAAY;YACxB,YAAY,CAAC,MAAM,CAAC,CAAC;YACrB,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE;gBACvB,MAAM,GAAG,SAAS,CAAC;gBACnB,QAAQ,EAAE,CAAC;YACb,CAAC,EAAE,KAAK,CAAC,CAAC;QACZ,CAAC;QACD,IAAI;YACF,YAAY,CAAC,MAAM,CAAC,CAAC;YACrB,MAAM,GAAG,SAAS,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * A restartable timeout handle. See {@link createTimer}.\n */\nexport type Timer = {\n /** Whether the timer is currently armed. */\n readonly active: boolean;\n /**\n * (Re)arms the timer, canceling a previously armed run.\n *\n * When `delay` is omitted, the default delay of the timer is used.\n */\n start(delay?: number): void;\n /** Cancels the armed run, if any. */\n stop(): void;\n};\n\n/**\n * Creates a restartable timeout around `callback`.\n *\n * Every `start` supersedes the previous one, so the callback runs at most once,\n * `delay` milliseconds after the most recent `start` - the recurring\n * \"clear the stored handle, then set it again\" bookkeeping is kept in one place.\n *\n * @example\n * ```typescript\n * const timer = createTimer(() => this.hideTooltip(), 500);\n *\n * timer.start(); // arms the timer with the default delay\n * timer.start(1000); // supersedes the run above\n * timer.stop(); // cancels it altogether\n * ```\n */\nexport function createTimer(callback: () => void, defaultDelay = 0): Timer {\n let handle: ReturnType<typeof setTimeout> | undefined;\n\n return {\n get active(): boolean {\n return handle !== undefined;\n },\n start(delay = defaultDelay): void {\n clearTimeout(handle);\n handle = setTimeout(() => {\n handle = undefined;\n callback();\n }, delay);\n },\n stop(): void {\n clearTimeout(handle);\n handle = undefined;\n },\n };\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Returns the first element of the given array.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
* Assumes a non-empty array
|
|
5
|
+
* Assumes a non-empty array - for an empty one it returns `undefined`
|
|
6
6
|
* typed as `T`.
|
|
7
7
|
*/
|
|
8
8
|
export declare function firstOf<T>(arr: T[]): T;
|
|
@@ -10,7 +10,7 @@ export declare function firstOf<T>(arr: T[]): T;
|
|
|
10
10
|
* Returns the last element of the given array.
|
|
11
11
|
*
|
|
12
12
|
* @remarks
|
|
13
|
-
* Assumes a non-empty array
|
|
13
|
+
* Assumes a non-empty array - for an empty one it returns `undefined`
|
|
14
14
|
* typed as `T`.
|
|
15
15
|
*/
|
|
16
16
|
export declare function lastOf<T>(arr: T[]): T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrays.js","sourceRoot":"","sources":["../../../src/internals/utils/arrays.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,OAAO,CAAI,GAAQ;IACjC,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,CAAM,CAAC;AACxB,CAAC;AASD,MAAM,UAAU,MAAM,CAAI,GAAQ;IAChC,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAM,CAAC;AACzB,CAAC;AAYD,MAAM,SAAS,CAAC,CAAC,KAAK,CAAI,GAAQ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B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * Returns the first element of the given array.\n *\n * @remarks\n * Assumes a non-empty array - for an empty one it returns `undefined`\n * typed as `T`.\n */\nexport function firstOf<T>(arr: T[]) {\n return arr.at(0) as T;\n}\n\n/**\n * Returns the last element of the given array.\n *\n * @remarks\n * Assumes a non-empty array - for an empty one it returns `undefined`\n * typed as `T`.\n */\nexport function lastOf<T>(arr: T[]) {\n return arr.at(-1) as T;\n}\n\n/**\n * Splits an array into chunks of a specified size and returns a generator that yields each chunk.\n *\n * @example\n * ```typescript\n * [...chunk([1, 2, 3, 4, 5], 2)]; // [[1, 2], [3, 4], [5]]\n * ```\n *\n * @throws If the `size` parameter is not a safe integer greater than or equal to 1.\n */\nexport function* chunk<T>(arr: T[], size: number): Generator<T[]> {\n if (!Number.isSafeInteger(size) || size < 1) {\n throw new Error('size must be an integer >= 1');\n }\n\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size);\n }\n}\n\n/**\n * Returns whether a given collection is empty.\n */\nexport function isEmpty<T, U extends object>(\n x: ArrayLike<T> | Set<T> | Map<U, T>\n): boolean {\n return 'length' in x ? x.length < 1 : x.size < 1;\n}\n\n/**\n * Ensures the given value is wrapped in an array. If the value is already an array, it is returned as-is. If the value is undefined, an empty array is returned.\n *\n * @example\n * ```typescript\n * asArray(5); // [5]\n * asArray([1, 2, 3]); // [1, 2, 3]\n * asArray(undefined); // []\n * ```\n */\nexport function asArray<T>(value?: T | T[]): T[] {\n if (value == null) return [];\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Splits an array into two based on a predicate function, returning a tuple of [truthy, falsy] arrays.\n *\n * @example\n * ```typescript\n * const [evens, odds] = partition([1, 2, 3, 4], x => x % 2 === 0);\n * console.log(evens); // [2, 4]\n * console.log(odds); // [1, 3]\n * ```\n */\nexport function partition<T>(\n array: T[],\n isTruthy: (value: T) => boolean\n): [truthy: T[], falsy: T[]] {\n const truthy: T[] = [];\n const falsy: T[] = [];\n\n for (const item of array) {\n (isTruthy(item) ? truthy : falsy).push(item);\n }\n\n return [truthy, falsy];\n}\n"]}
|
package/internals/utils/dom.d.ts
CHANGED
|
@@ -58,6 +58,28 @@ export declare function getCenterPoint(element: Element): {
|
|
|
58
58
|
x: number;
|
|
59
59
|
y: number;
|
|
60
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Maps a pointer's `clientX` coordinate to a fraction in the [0, 1] range of the
|
|
63
|
+
* element's bounding box width, measured from the element's logical start edge -
|
|
64
|
+
* the left edge when `ltr` is true, the right one otherwise.
|
|
65
|
+
*
|
|
66
|
+
* Returns 0 for an element without layout.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Pointer 30px into a 120px wide element
|
|
71
|
+
* pointToFraction(element, event.clientX); // 0.25
|
|
72
|
+
* pointToFraction(element, event.clientX, false); // 0.75
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function pointToFraction(element: Element, clientX: number, ltr?: boolean): number;
|
|
76
|
+
/**
|
|
77
|
+
* Concatenates the text content of the given nodes into a single string,
|
|
78
|
+
* trimmed and with consecutive whitespace collapsed.
|
|
79
|
+
*
|
|
80
|
+
* Useful for deriving an accessible label from projected content.
|
|
81
|
+
*/
|
|
82
|
+
export declare function normalizedTextContent(nodes: Iterable<Node>): string;
|
|
61
83
|
/** Returns whether the given client coordinates lie within the bounding box of the element. */
|
|
62
84
|
export declare function isPointInsideElement(element: Element, x: number, y: number): boolean;
|
|
63
85
|
/** Returns the scale factor of a given element based on its bounding client rect and offset dimensions. */
|
package/internals/utils/dom.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isServer } from 'lit';
|
|
2
|
-
import { asNumber, numberInRangeInclusive } from './math.js';
|
|
2
|
+
import { asNumber, clamp, numberInRangeInclusive } from './math.js';
|
|
3
3
|
import { merge } from './objects.js';
|
|
4
4
|
import { isDefined } from './types.js';
|
|
5
5
|
export function isLTR(element) {
|
|
@@ -91,6 +91,20 @@ export function getCenterPoint(element) {
|
|
|
91
91
|
y: top + height * 0.5,
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
+
export function pointToFraction(element, clientX, ltr = true) {
|
|
95
|
+
const { left, right, width } = element.getBoundingClientRect();
|
|
96
|
+
if (width === 0) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
return clamp((ltr ? clientX - left : right - clientX) / width, 0, 1);
|
|
100
|
+
}
|
|
101
|
+
export function normalizedTextContent(nodes) {
|
|
102
|
+
let text = '';
|
|
103
|
+
for (const node of nodes) {
|
|
104
|
+
text += node.textContent ?? '';
|
|
105
|
+
}
|
|
106
|
+
return text.trim().replace(/\s+/gu, ' ');
|
|
107
|
+
}
|
|
94
108
|
export function isPointInsideElement(element, x, y) {
|
|
95
109
|
const { left, right, top, bottom } = element.getBoundingClientRect();
|
|
96
110
|
return (numberInRangeInclusive(x, left, right) &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../src/internals/utils/dom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,MAAM,UAAU,KAAK,CAAC,OAAoB;IACxC,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AACtC,CAAC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AQ,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAKD,MAAM,UAAU,kBAAkB,CAAC,SAAe;IAChD,KAAK,MAAM,QAAQ,IAAI,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3D,IAAI,QAAQ,YAAY,WAAW,IAAI,QAAQ,CAAC,eAAe,EAAE,EAAE,CAAC;YAClE,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { isServer } from 'lit';\nimport { asNumber, numberInRangeInclusive } from './math.js';\nimport { merge } from './objects.js';\nimport { isDefined } from './types.js';\n\n/**\n * Returns whether an element has a Left-to-Right directionality.\n */\nexport function isLTR(element: HTMLElement) {\n return element.matches(':dir(ltr)');\n}\n\nconst LENGTH_PROPERTY = '--igc-resolved-length';\n\nconst SUPPORTS_REGISTERED_PROPERTIES =\n !isServer && typeof CSS !== 'undefined' && 'registerProperty' in CSS;\n\nlet lengthPropertyUsable: boolean | undefined;\n\nfunction canResolveLengths(): boolean {\n if (lengthPropertyUsable === undefined) {\n lengthPropertyUsable = SUPPORTS_REGISTERED_PROPERTIES;\n\n if (lengthPropertyUsable) {\n try {\n CSS.registerProperty({\n name: LENGTH_PROPERTY,\n syntax: '<length>',\n inherits: false,\n initialValue: '0px',\n });\n } catch {\n // The descriptor is a constant, so the only realistic rejection is a\n // duplicate registration from another bundle instance - which leaves\n // the property just as usable.\n }\n }\n }\n\n return lengthPropertyUsable;\n}\n\n/**\n * Resolves a CSS length to pixels in the context of `element`.\n *\n * A registered custom property computes to an absolute length, which lets the\n * browser do the conversion for font, viewport and container relative units\n * instead of them being read as raw numbers. Percentages are not lengths -\n * resolve those against whatever basis applies to the property at hand.\n *\n * Returns 0 for percentages, for values that are not valid lengths, and where\n * the resolution is unavailable - during server-side rendering, or without\n * support for registered custom properties. Guessing from the raw token would\n * read `5rem` as 5 pixels, so callers get an obvious zero instead.\n *\n * @example\n * ```typescript\n * resolveCssLength(element, '5rem'); // 80\n * resolveCssLength(element, '2em'); // 2 x the element font size\n * ```\n */\nexport function resolveCssLength(element: HTMLElement, value: string): number {\n if (!canResolveLengths()) {\n return 0;\n }\n\n const { style } = element;\n const previous = style.getPropertyValue(LENGTH_PROPERTY);\n const priority = style.getPropertyPriority(LENGTH_PROPERTY);\n\n style.setProperty(LENGTH_PROPERTY, value);\n const resolved = getComputedStyle(element).getPropertyValue(LENGTH_PROPERTY);\n\n // Restore rather than remove - the caller may be using the property itself.\n if (previous) {\n style.setProperty(LENGTH_PROPERTY, previous, priority);\n } else {\n style.removeProperty(LENGTH_PROPERTY);\n }\n\n return asNumber(resolved);\n}\n\nexport type IterNodesOptions<T = Node> = {\n show?: keyof typeof NodeFilter;\n filter?: (node: T) => boolean;\n};\n\nfunction createNodeFilter<T extends Node>(predicate: (node: T) => boolean) {\n return {\n acceptNode: (node: T): number =>\n predicate(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP,\n };\n}\n\n/**\n * Iterates over the DOM subtree of `root` in document order, yielding the nodes\n * matching the passed {@link IterNodesOptions | options}.\n *\n * @example\n * ```typescript\n * for (const button of iterNodes<HTMLButtonElement>(root, { show: 'SHOW_ELEMENT', filter: isButton })) { ... }\n * ```\n */\nexport function* iterNodes<T extends Node>(\n root: Node,\n options?: IterNodesOptions<T>\n): Generator<T> {\n if (!isDefined(globalThis.document)) {\n return;\n }\n\n const whatToShow = options?.show\n ? NodeFilter[options.show]\n : NodeFilter.SHOW_ALL;\n\n const nodeFilter = options?.filter\n ? createNodeFilter(options.filter)\n : undefined;\n\n const treeWalker = document.createTreeWalker(root, whatToShow, nodeFilter);\n\n while (treeWalker.nextNode()) {\n yield treeWalker.currentNode as T;\n }\n}\n\n/**\n * Iterates over `node` and its ancestors, crossing shadow DOM boundaries.\n *\n * Shadow roots are traversed through their host, so only elements are yielded.\n *\n * @example\n * ```typescript\n * for (const ancestor of iterAncestors(element)) { ... }\n * ```\n */\nexport function* iterAncestors(node?: Node | null): Generator<Element> {\n let current: Node | null | undefined = node;\n\n while (current) {\n if (isElement(current)) {\n yield current;\n }\n\n current = current instanceof ShadowRoot ? current.host : current.parentNode;\n }\n}\n\n/** Returns the root node (document or shadow root) of the given element. */\nexport function getRoot(\n element: Element,\n options?: GetRootNodeOptions\n): Document | ShadowRoot {\n return element.getRootNode(options) as Document | ShadowRoot;\n}\n\n/** Returns the element with the given id in the root node of `root`, if any. */\nexport function getElementByIdFromRoot(root: HTMLElement, id: string) {\n return getRoot(root).getElementById(id);\n}\n\nexport function isElement(node: unknown): node is Element {\n return node instanceof Node && node.nodeType === Node.ELEMENT_NODE;\n}\n\nexport function isDocument(node: unknown): node is Document {\n return node instanceof Node && node.nodeType === Node.DOCUMENT_NODE;\n}\n\n/** Returns the center x/y coordinate of a given element. */\nexport function getCenterPoint(element: Element): { x: number; y: number } {\n const { left, top, width, height } = element.getBoundingClientRect();\n\n return {\n x: left + width * 0.5,\n y: top + height * 0.5,\n };\n}\n\n/** Returns whether the given client coordinates lie within the bounding box of the element. */\nexport function isPointInsideElement(\n element: Element,\n x: number,\n y: number\n): boolean {\n const { left, right, top, bottom } = element.getBoundingClientRect();\n return (\n numberInRangeInclusive(x, left, right) &&\n numberInRangeInclusive(y, top, bottom)\n );\n}\n\n/** Returns the scale factor of a given element based on its bounding client rect and offset dimensions. */\nexport function getScaleFactor(element: HTMLElement): { x: number; y: number } {\n const { offsetWidth, offsetHeight } = element;\n const { width, height } = element.getBoundingClientRect();\n return { x: offsetWidth / width || 1, y: offsetHeight / height || 1 };\n}\n\n/** Rounds a CSS pixel value to the closest device-pixel boundary to avoid blurry rendering. */\nexport function roundByDPR(value: number): number {\n const dpr = globalThis.devicePixelRatio || 1;\n return Math.round(value * dpr) / dpr;\n}\n\n/** Null-safe `Element.scrollIntoView` defaulting to the nearest block/inline position. */\nexport function scrollIntoView(\n element?: HTMLElement | null,\n config?: ScrollIntoViewOptions\n): void {\n if (!element) {\n return;\n }\n\n element.scrollIntoView(\n Object.assign(\n {\n behavior: 'auto',\n block: 'nearest',\n inline: 'nearest',\n },\n config\n )\n );\n}\n\n/** Applies the given CSS declarations to the inline style of the element. */\nexport function setStyles(\n element: HTMLElement,\n styles: Partial<CSSStyleDeclaration>\n): void {\n merge(element.style, styles);\n}\n\n/** Returns whether the given input has at least one selected file. */\nexport function hasFiles(input: { files: FileList | null }): boolean {\n return input.files != null && input.files.length > 0;\n}\n\n/**\n * Returns whether the given element is currently an open popover or not.\n * This is useful to determine if the popover is open without relying on the `open` property, which may not be in sync with the actual popover state if the opening/closing animations are still running.\n * Note: This function only works for elements that use the `:popover-open` pseudo-class to indicate\n */\nexport function isPopoverOpen(element?: Element): boolean {\n return element?.matches(':popover-open') ?? false;\n}\n\n/**\n * Returns whether the given element, or any of its ancestors across shadow DOM\n * boundaries, is positioned as `sticky`.\n */\nexport function hasStickyAncestor(element: Element): boolean {\n for (const ancestor of iterAncestors(element)) {\n if (getComputedStyle(ancestor).position === 'sticky') {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Returns the nearest visible ancestor of a given node, traversing through shadow DOM boundaries if necessary. If no visible ancestor is found, returns null.\n */\nexport function getVisibleAncestor(startNode: Node): HTMLElement | null {\n for (const ancestor of iterAncestors(startNode.parentNode)) {\n if (ancestor instanceof HTMLElement && ancestor.checkVisibility()) {\n return ancestor;\n }\n }\n\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../src/internals/utils/dom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,C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eInclusive } from './math.js';\nimport { merge } from './objects.js';\nimport { isDefined } from './types.js';\n\n/**\n * Returns whether an element has a Left-to-Right directionality.\n */\nexport function isLTR(element: HTMLElement) {\n return element.matches(':dir(ltr)');\n}\n\nconst LENGTH_PROPERTY = '--igc-resolved-length';\n\nconst SUPPORTS_REGISTERED_PROPERTIES =\n !isServer && typeof CSS !== 'undefined' && 'registerProperty' in CSS;\n\nlet lengthPropertyUsable: boolean | undefined;\n\nfunction canResolveLengths(): boolean {\n if (lengthPropertyUsable === undefined) {\n lengthPropertyUsable = SUPPORTS_REGISTERED_PROPERTIES;\n\n if (lengthPropertyUsable) {\n try {\n CSS.registerProperty({\n name: LENGTH_PROPERTY,\n syntax: '<length>',\n inherits: false,\n initialValue: '0px',\n });\n } catch {\n // The descriptor is a constant, so the only realistic rejection is a\n // duplicate registration from another bundle instance - which leaves\n // the property just as usable.\n }\n }\n }\n\n return lengthPropertyUsable;\n}\n\n/**\n * Resolves a CSS length to pixels in the context of `element`.\n *\n * A registered custom property computes to an absolute length, which lets the\n * browser do the conversion for font, viewport and container relative units\n * instead of them being read as raw numbers. Percentages are not lengths -\n * resolve those against whatever basis applies to the property at hand.\n *\n * Returns 0 for percentages, for values that are not valid lengths, and where\n * the resolution is unavailable - during server-side rendering, or without\n * support for registered custom properties. Guessing from the raw token would\n * read `5rem` as 5 pixels, so callers get an obvious zero instead.\n *\n * @example\n * ```typescript\n * resolveCssLength(element, '5rem'); // 80\n * resolveCssLength(element, '2em'); // 2 x the element font size\n * ```\n */\nexport function resolveCssLength(element: HTMLElement, value: string): number {\n if (!canResolveLengths()) {\n return 0;\n }\n\n const { style } = element;\n const previous = style.getPropertyValue(LENGTH_PROPERTY);\n const priority = style.getPropertyPriority(LENGTH_PROPERTY);\n\n style.setProperty(LENGTH_PROPERTY, value);\n const resolved = getComputedStyle(element).getPropertyValue(LENGTH_PROPERTY);\n\n // Restore rather than remove - the caller may be using the property itself.\n if (previous) {\n style.setProperty(LENGTH_PROPERTY, previous, priority);\n } else {\n style.removeProperty(LENGTH_PROPERTY);\n }\n\n return asNumber(resolved);\n}\n\nexport type IterNodesOptions<T = Node> = {\n show?: keyof typeof NodeFilter;\n filter?: (node: T) => boolean;\n};\n\nfunction createNodeFilter<T extends Node>(predicate: (node: T) => boolean) {\n return {\n acceptNode: (node: T): number =>\n predicate(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP,\n };\n}\n\n/**\n * Iterates over the DOM subtree of `root` in document order, yielding the nodes\n * matching the passed {@link IterNodesOptions | options}.\n *\n * @example\n * ```typescript\n * for (const button of iterNodes<HTMLButtonElement>(root, { show: 'SHOW_ELEMENT', filter: isButton })) { ... }\n * ```\n */\nexport function* iterNodes<T extends Node>(\n root: Node,\n options?: IterNodesOptions<T>\n): Generator<T> {\n if (!isDefined(globalThis.document)) {\n return;\n }\n\n const whatToShow = options?.show\n ? NodeFilter[options.show]\n : NodeFilter.SHOW_ALL;\n\n const nodeFilter = options?.filter\n ? createNodeFilter(options.filter)\n : undefined;\n\n const treeWalker = document.createTreeWalker(root, whatToShow, nodeFilter);\n\n while (treeWalker.nextNode()) {\n yield treeWalker.currentNode as T;\n }\n}\n\n/**\n * Iterates over `node` and its ancestors, crossing shadow DOM boundaries.\n *\n * Shadow roots are traversed through their host, so only elements are yielded.\n *\n * @example\n * ```typescript\n * for (const ancestor of iterAncestors(element)) { ... }\n * ```\n */\nexport function* iterAncestors(node?: Node | null): Generator<Element> {\n let current: Node | null | undefined = node;\n\n while (current) {\n if (isElement(current)) {\n yield current;\n }\n\n current = current instanceof ShadowRoot ? current.host : current.parentNode;\n }\n}\n\n/** Returns the root node (document or shadow root) of the given element. */\nexport function getRoot(\n element: Element,\n options?: GetRootNodeOptions\n): Document | ShadowRoot {\n return element.getRootNode(options) as Document | ShadowRoot;\n}\n\n/** Returns the element with the given id in the root node of `root`, if any. */\nexport function getElementByIdFromRoot(root: HTMLElement, id: string) {\n return getRoot(root).getElementById(id);\n}\n\nexport function isElement(node: unknown): node is Element {\n return node instanceof Node && node.nodeType === Node.ELEMENT_NODE;\n}\n\nexport function isDocument(node: unknown): node is Document {\n return node instanceof Node && node.nodeType === Node.DOCUMENT_NODE;\n}\n\n/** Returns the center x/y coordinate of a given element. */\nexport function getCenterPoint(element: Element): { x: number; y: number } {\n const { left, top, width, height } = element.getBoundingClientRect();\n\n return {\n x: left + width * 0.5,\n y: top + height * 0.5,\n };\n}\n\n/**\n * Maps a pointer's `clientX` coordinate to a fraction in the [0, 1] range of the\n * element's bounding box width, measured from the element's logical start edge -\n * the left edge when `ltr` is true, the right one otherwise.\n *\n * Returns 0 for an element without layout.\n *\n * @example\n * ```typescript\n * // Pointer 30px into a 120px wide element\n * pointToFraction(element, event.clientX); // 0.25\n * pointToFraction(element, event.clientX, false); // 0.75\n * ```\n */\nexport function pointToFraction(\n element: Element,\n clientX: number,\n ltr = true\n): number {\n const { left, right, width } = element.getBoundingClientRect();\n\n if (width === 0) {\n return 0;\n }\n\n return clamp((ltr ? clientX - left : right - clientX) / width, 0, 1);\n}\n\n/**\n * Concatenates the text content of the given nodes into a single string,\n * trimmed and with consecutive whitespace collapsed.\n *\n * Useful for deriving an accessible label from projected content.\n */\nexport function normalizedTextContent(nodes: Iterable<Node>): string {\n let text = '';\n\n for (const node of nodes) {\n text += node.textContent ?? '';\n }\n\n return text.trim().replace(/\\s+/gu, ' ');\n}\n\n/** Returns whether the given client coordinates lie within the bounding box of the element. */\nexport function isPointInsideElement(\n element: Element,\n x: number,\n y: number\n): boolean {\n const { left, right, top, bottom } = element.getBoundingClientRect();\n return (\n numberInRangeInclusive(x, left, right) &&\n numberInRangeInclusive(y, top, bottom)\n );\n}\n\n/** Returns the scale factor of a given element based on its bounding client rect and offset dimensions. */\nexport function getScaleFactor(element: HTMLElement): { x: number; y: number } {\n const { offsetWidth, offsetHeight } = element;\n const { width, height } = element.getBoundingClientRect();\n return { x: offsetWidth / width || 1, y: offsetHeight / height || 1 };\n}\n\n/** Rounds a CSS pixel value to the closest device-pixel boundary to avoid blurry rendering. */\nexport function roundByDPR(value: number): number {\n const dpr = globalThis.devicePixelRatio || 1;\n return Math.round(value * dpr) / dpr;\n}\n\n/** Null-safe `Element.scrollIntoView` defaulting to the nearest block/inline position. */\nexport function scrollIntoView(\n element?: HTMLElement | null,\n config?: ScrollIntoViewOptions\n): void {\n if (!element) {\n return;\n }\n\n element.scrollIntoView(\n Object.assign(\n {\n behavior: 'auto',\n block: 'nearest',\n inline: 'nearest',\n },\n config\n )\n );\n}\n\n/** Applies the given CSS declarations to the inline style of the element. */\nexport function setStyles(\n element: HTMLElement,\n styles: Partial<CSSStyleDeclaration>\n): void {\n merge(element.style, styles);\n}\n\n/** Returns whether the given input has at least one selected file. */\nexport function hasFiles(input: { files: FileList | null }): boolean {\n return input.files != null && input.files.length > 0;\n}\n\n/**\n * Returns whether the given element is currently an open popover or not.\n * This is useful to determine if the popover is open without relying on the `open` property, which may not be in sync with the actual popover state if the opening/closing animations are still running.\n * Note: This function only works for elements that use the `:popover-open` pseudo-class to indicate\n */\nexport function isPopoverOpen(element?: Element): boolean {\n return element?.matches(':popover-open') ?? false;\n}\n\n/**\n * Returns whether the given element, or any of its ancestors across shadow DOM\n * boundaries, is positioned as `sticky`.\n */\nexport function hasStickyAncestor(element: Element): boolean {\n for (const ancestor of iterAncestors(element)) {\n if (getComputedStyle(ancestor).position === 'sticky') {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Returns the nearest visible ancestor of a given node, traversing through shadow DOM boundaries if necessary. If no visible ancestor is found, returns null.\n */\nexport function getVisibleAncestor(startNode: Node): HTMLElement | null {\n for (const ancestor of iterAncestors(startNode.parentNode)) {\n if (ancestor instanceof HTMLElement && ancestor.checkVisibility()) {\n return ancestor;\n }\n }\n\n return null;\n}\n"]}
|
|
@@ -46,5 +46,5 @@ export declare function asNumber(value: unknown, fallback?: number): number;
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
export declare function wrap(min: number, max: number, value: number): number;
|
|
49
|
-
/** Euclidean modulo
|
|
49
|
+
/** Euclidean modulo - like `%` but the result always has the sign of the divisor. */
|
|
50
50
|
export declare function modulo(n: number, d: number): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.js","sourceRoot":"","sources":["../../../src/internals/utils/math.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;AAC9B,CAAC;AAGD,MAAM,UAAU,KAAK,CAAC,MAAc,EAAE,GAAW,EAAE,GAAW;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC;AAGD,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QACzD,OAAO,CAAC,CAAC;IACX,CAAC;IAGD,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IAErD,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC3D,CAAC;AAUD,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,SAAS,GAAG,CAAC;IACxD,MAAM,MAAM,GAAG,EAAE,IAAI,SAAS,CAAC;IAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AAC9C,CAAC;AAGD,MAAM,UAAU,sBAAsB,CACpC,KAAa,EACb,GAAW,EACX,GAAW;IAEX,OAAO,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC;AACtC,CAAC;AAkBD,MAAM,UAAU,QAAQ,CAAC,KAAc,EAAE,QAAQ,GAAG,CAAC;IACnD,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAe,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrD,CAAC;AAeD,MAAM,UAAU,IAAI,CAAC,GAAW,EAAE,GAAW,EAAE,KAAa;IAC1D,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAGD,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["/** Returns `part` as a percentage of `whole`. */\nexport function asPercent(part: number, whole: number): number {\n return (part / whole) * 100;\n}\n\n/** Clamps the given number between the min and max bounds (inclusive). */\nexport function clamp(number: number, min: number, max: number): number {\n return Math.max(min, Math.min(number, max));\n}\n\n/** Returns the number of decimal places of the given number. */\nexport function numberOfDecimals(number: number): number {\n if (!Number.isFinite(number) || Number.isInteger(number)) {\n return 0;\n }\n\n // Exponential notation, e.g. `1.5e-7` -> 1 mantissa decimal + 7 exponent places\n const [mantissa, exponent] = number.toString().split('e-');\n const decimals = mantissa.split('.')[1]?.length ?? 0;\n\n return exponent ? decimals + Number(exponent) : decimals;\n}\n\n/**\n * Rounds a number to the given order of magnitude (number of decimal places).\n *\n * @example\n * ```typescript\n * roundPrecise(3.14159, 2); // 3.14\n * ```\n */\nexport function roundPrecise(number: number, magnitude = 1): number {\n const factor = 10 ** magnitude;\n return Math.round(number * factor) / factor;\n}\n\n/** Returns whether the given value lies between the min and max bounds (inclusive). */\nexport function numberInRangeInclusive(\n value: number,\n min: number,\n max: number\n) {\n return value >= min && value <= max;\n}\n\n/**\n * Parse the passed `value` as a number or return the `fallback` if it can't be done.\n *\n * @example\n * ```typescript\n * asNumber('5'); // 5\n * asNumber('3.14'); // 3.14\n * asNumber('five'); // 0\n * asNumber('five', 5); // 5\n * asNumber(undefined, 10); // 10\n * asNumber(null, 10); // 10\n * asNumber(NaN, 10); // 10\n * asNumber(Infinity, 10); // 10\n * asNumber(-Infinity, 10); // 10\n * ```\n */\nexport function asNumber(value: unknown, fallback = 0): number {\n const parsed = Number.parseFloat(value as string);\n return Number.isFinite(parsed) ? parsed : fallback;\n}\n\n/**\n * Returns the value wrapped between the min and max bounds.\n *\n * If the value is greater than max, returns the min and vice-versa.\n * If the value is between the bounds, it is returned unchanged.\n *\n * @example\n * ```typescript\n * wrap(1, 4, 2); // 2\n * wrap(1, 4, 5); // 1\n * wrap(1, 4, -1); // 4\n * ```\n */\nexport function wrap(min: number, max: number, value: number) {\n if (value < min) {\n return max;\n }\n if (value > max) {\n return min;\n }\n\n return value;\n}\n\n/** Euclidean modulo
|
|
1
|
+
{"version":3,"file":"math.js","sourceRoot":"","sources":["../../../src/internals/utils/math.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,KAAa;IACnD,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;AAC9B,CAAC;AAGD,MAAM,UAAU,KAAK,CAAC,MAAc,EAAE,GAAW,EAAE,GAAW;IAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAA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,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QAChB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAGD,MAAM,UAAU,MAAM,CAAC,CAAS,EAAE,CAAS;IACzC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["/** Returns `part` as a percentage of `whole`. */\nexport function asPercent(part: number, whole: number): number {\n return (part / whole) * 100;\n}\n\n/** Clamps the given number between the min and max bounds (inclusive). */\nexport function clamp(number: number, min: number, max: number): number {\n return Math.max(min, Math.min(number, max));\n}\n\n/** Returns the number of decimal places of the given number. */\nexport function numberOfDecimals(number: number): number {\n if (!Number.isFinite(number) || Number.isInteger(number)) {\n return 0;\n }\n\n // Exponential notation, e.g. `1.5e-7` -> 1 mantissa decimal + 7 exponent places\n const [mantissa, exponent] = number.toString().split('e-');\n const decimals = mantissa.split('.')[1]?.length ?? 0;\n\n return exponent ? decimals + Number(exponent) : decimals;\n}\n\n/**\n * Rounds a number to the given order of magnitude (number of decimal places).\n *\n * @example\n * ```typescript\n * roundPrecise(3.14159, 2); // 3.14\n * ```\n */\nexport function roundPrecise(number: number, magnitude = 1): number {\n const factor = 10 ** magnitude;\n return Math.round(number * factor) / factor;\n}\n\n/** Returns whether the given value lies between the min and max bounds (inclusive). */\nexport function numberInRangeInclusive(\n value: number,\n min: number,\n max: number\n) {\n return value >= min && value <= max;\n}\n\n/**\n * Parse the passed `value` as a number or return the `fallback` if it can't be done.\n *\n * @example\n * ```typescript\n * asNumber('5'); // 5\n * asNumber('3.14'); // 3.14\n * asNumber('five'); // 0\n * asNumber('five', 5); // 5\n * asNumber(undefined, 10); // 10\n * asNumber(null, 10); // 10\n * asNumber(NaN, 10); // 10\n * asNumber(Infinity, 10); // 10\n * asNumber(-Infinity, 10); // 10\n * ```\n */\nexport function asNumber(value: unknown, fallback = 0): number {\n const parsed = Number.parseFloat(value as string);\n return Number.isFinite(parsed) ? parsed : fallback;\n}\n\n/**\n * Returns the value wrapped between the min and max bounds.\n *\n * If the value is greater than max, returns the min and vice-versa.\n * If the value is between the bounds, it is returned unchanged.\n *\n * @example\n * ```typescript\n * wrap(1, 4, 2); // 2\n * wrap(1, 4, 5); // 1\n * wrap(1, 4, -1); // 4\n * ```\n */\nexport function wrap(min: number, max: number, value: number) {\n if (value < min) {\n return max;\n }\n if (value > max) {\n return min;\n }\n\n return value;\n}\n\n/** Euclidean modulo - like `%` but the result always has the sign of the divisor. */\nexport function modulo(n: number, d: number) {\n return ((n % d) + d) % d;\n}\n"]}
|
|
@@ -3,7 +3,7 @@ export declare function isDefined<T = unknown>(value: T): value is T & ({} | nul
|
|
|
3
3
|
export declare function isFunction(value: unknown): value is CallableFunction;
|
|
4
4
|
export declare function isString(value: unknown): value is string;
|
|
5
5
|
export declare function isObject(value: unknown): value is object;
|
|
6
|
-
/** Returns whether the value is a plain object (POJO)
|
|
6
|
+
/** Returns whether the value is a plain object (POJO) - created via `{}`, `new Object()` or `Object.create(null)`. */
|
|
7
7
|
export declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
8
8
|
export declare function isRegExp(value: unknown): value is RegExp;
|
|
9
9
|
export declare function isEventListenerObject(x: unknown): x is EventListenerObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internals/utils/types.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,SAAS,CAAc,KAAQ;IAC7C,OAAO,KAAK,KAAK,SAAS,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACpD,CAAC;AAGD,MAAM,UAAU,aAAa,CAC3B,KAAc;IAEd,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAmC,CAAC;IAE7E,MAAM,kBAAkB,GACtB,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,MAAM,CAAC,SAAS;QAC1B,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAExC,OAAO,kBAAkB;QACvB,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB;QAC7D,CAAC,CAAC,KAAK,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,YAAY,MAAM,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,CAAU;IAC9C,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,aAAa,IAAI,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["/** Returns whether the value is not `undefined`. Note that `null` is considered defined. */\nexport function isDefined<T = unknown>(value: T) {\n return value !== undefined;\n}\n\nexport function isFunction(value: unknown): value is CallableFunction {\n return typeof value === 'function';\n}\n\nexport function isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\nexport function isObject(value: unknown): value is object {\n return value != null && typeof value === 'object';\n}\n\n/** Returns whether the value is a plain object (POJO)
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internals/utils/types.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,SAAS,CAAc,KAAQ;IAC7C,OAAO,KAAK,KAAK,SAAS,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACpD,CAAC;AAGD,MAAM,UAAU,aAAa,CAC3B,KAAc;IAEd,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAmC,CAAC;IAE7E,MAAM,kBAAkB,GACtB,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,MAAM,CAAC,SAAS;QAC1B,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAExC,OAAO,kBAAkB;QACvB,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB;QAC7D,CAAC,CAAC,KAAK,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,YAAY,MAAM,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,CAAU;IAC9C,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,aAAa,IAAI,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["/** Returns whether the value is not `undefined`. Note that `null` is considered defined. */\nexport function isDefined<T = unknown>(value: T) {\n return value !== undefined;\n}\n\nexport function isFunction(value: unknown): value is CallableFunction {\n return typeof value === 'function';\n}\n\nexport function isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\nexport function isObject(value: unknown): value is object {\n return value != null && typeof value === 'object';\n}\n\n/** Returns whether the value is a plain object (POJO) - created via `{}`, `new Object()` or `Object.create(null)`. */\nexport function isPlainObject(\n value: unknown\n): value is Record<PropertyKey, unknown> {\n if (!isObject(value)) {\n return false;\n }\n\n const proto = Object.getPrototypeOf(value) as typeof Object.prototype | null;\n\n const hasObjectPrototype =\n proto === null ||\n proto === Object.prototype ||\n Object.getPrototypeOf(proto) === null;\n\n return hasObjectPrototype\n ? Object.prototype.toString.call(value) === '[object Object]'\n : false;\n}\n\nexport function isRegExp(value: unknown): value is RegExp {\n return value instanceof RegExp;\n}\n\nexport function isEventListenerObject(x: unknown): x is EventListenerObject {\n return isObject(x) && 'handleEvent' in x;\n}\n\n/** Required utility type for specific props */\nexport type RequiredProps<T, K extends keyof T> = T & {\n [P in K]-?: T[P];\n};\n"]}
|
|
@@ -53,4 +53,27 @@ export declare const maxDateValidator: Validator<{
|
|
|
53
53
|
value?: Date | null;
|
|
54
54
|
max?: Date | null;
|
|
55
55
|
}>;
|
|
56
|
+
/** A host whose bound comparisons follow the parts present in its format. */
|
|
57
|
+
interface DatePartsHost {
|
|
58
|
+
hasDateParts(): boolean;
|
|
59
|
+
hasTimeParts(): boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a `rangeUnderflow` validator for hosts whose `min` comparison must
|
|
63
|
+
* respect the parts of the host's format - day granularity when the format has
|
|
64
|
+
* no time parts, time-of-day granularity when it has no date parts.
|
|
65
|
+
*
|
|
66
|
+
* `resolveValues` returns the dates checked against the bound; empty slots
|
|
67
|
+
* are skipped, so a partial range validates only its present ends.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createMinDateTimeValidator<T extends DatePartsHost & {
|
|
70
|
+
min?: Date | null;
|
|
71
|
+
}>(resolveValues: (host: T) => (Date | null | undefined)[]): Validator<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a `rangeOverflow` validator for hosts whose `max` comparison must
|
|
74
|
+
* respect the parts of the host's format. See {@link createMinDateTimeValidator}.
|
|
75
|
+
*/
|
|
76
|
+
export declare function createMaxDateTimeValidator<T extends DatePartsHost & {
|
|
77
|
+
max?: Date | null;
|
|
78
|
+
}>(resolveValues: (host: T) => (Date | null | undefined)[]): Validator<T>;
|
|
56
79
|
export {};
|
package/internals/validators.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ValidationResourceStringsEN } from 'igniteui-i18n-core';
|
|
2
|
+
import { isDateExceedingMax, isDateLessThanMin } from './date/compare.js';
|
|
2
3
|
import { CalendarDay } from './date/model.js';
|
|
3
4
|
import { asNumber, numberOfDecimals, roundPrecise } from './utils/math.js';
|
|
4
5
|
import { formatString } from './utils/strings.js';
|
|
@@ -77,4 +78,24 @@ export const maxDateValidator = {
|
|
|
77
78
|
message: ({ max }) => formatString(ValidationResourceStringsEN.max_validation_error, max),
|
|
78
79
|
isValid: ({ value, max }) => value && max ? CalendarDay.compare(value, max) <= 0 : true,
|
|
79
80
|
};
|
|
81
|
+
function isWithinBound(host, bound, values, exceeds) {
|
|
82
|
+
return bound
|
|
83
|
+
? values.every((date) => !date ||
|
|
84
|
+
!exceeds(date, bound, host.hasTimeParts(), host.hasDateParts()))
|
|
85
|
+
: true;
|
|
86
|
+
}
|
|
87
|
+
export function createMinDateTimeValidator(resolveValues) {
|
|
88
|
+
return {
|
|
89
|
+
key: 'rangeUnderflow',
|
|
90
|
+
message: ({ min }) => formatString(ValidationResourceStringsEN.min_validation_error, min),
|
|
91
|
+
isValid: (host) => isWithinBound(host, host.min, resolveValues(host), isDateLessThanMin),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function createMaxDateTimeValidator(resolveValues) {
|
|
95
|
+
return {
|
|
96
|
+
key: 'rangeOverflow',
|
|
97
|
+
message: ({ max }) => formatString(ValidationResourceStringsEN.max_validation_error, max),
|
|
98
|
+
isValid: (host) => isWithinBound(host, host.max, resolveValues(host), isDateExceedingMax),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
80
101
|
//# sourceMappingURL=validators.js.map
|
|
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ValidationResourceStringsEN } from 'igniteui-i18n-core';\nimport { CalendarDay } from './date/model.js';\nimport { asNumber, numberOfDecimals, roundPrecise } from './utils/math.js';\nimport { formatString } from './utils/strings.js';\nimport { isDefined } from './utils/types.js';\n\ntype ValidatorHandler<T> = (host: T) => boolean;\ntype ValidatorMessageFormat<T> = (host: T) => string;\n\n/** @hidden */\nexport interface Validator<T = any> {\n key: keyof ValidityStateFlags;\n message: string | ValidatorMessageFormat<T>;\n isValid: ValidatorHandler<T>;\n}\n\nconst emailRegex =\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;\n\nexport const requiredValidator: Validator<{\n required: boolean;\n value?: unknown;\n}> = {\n key: 'valueMissing',\n message: ValidationResourceStringsEN.required_validation_error!,\n isValid: ({ required, value }) => (required ? !!value : true),\n};\n\nexport const requiredBooleanValidator: Validator<{\n required: boolean;\n checked: boolean;\n}> = {\n key: 'valueMissing',\n message: ValidationResourceStringsEN.required_validation_error!,\n isValid: ({ required, checked }) => (required ? checked : true),\n};\n\nexport const minLengthValidator: Validator<{\n minLength?: number;\n value: string;\n}> = {\n key: 'tooShort',\n message: ({ minLength }) =>\n formatString(\n ValidationResourceStringsEN.min_length_validation_error!,\n minLength\n ),\n isValid: ({ minLength, value }) =>\n minLength && value ? value.length >= asNumber(minLength) : true,\n};\n\nexport const maxLengthValidator: Validator<{\n maxLength?: number;\n value: string;\n}> = {\n key: 'tooLong',\n message: ({ maxLength }) =>\n formatString(\n ValidationResourceStringsEN.max_length_validation_error!,\n maxLength\n ),\n isValid: ({ maxLength, value }) =>\n maxLength && value ? value.length <= asNumber(maxLength) : true,\n};\n\nexport const patternValidator: Validator<{ pattern?: string; value: string }> =\n {\n key: 'patternMismatch',\n message: ValidationResourceStringsEN.pattern_validation_error!,\n isValid: ({ pattern, value }) =>\n pattern && value ? new RegExp(pattern, 'u').test(value) : true,\n };\n\nexport const minValidator: Validator<{\n min?: number;\n value: number | string;\n}> = {\n key: 'rangeUnderflow',\n message: ({ min }) =>\n formatString(ValidationResourceStringsEN.min_validation_error!, min),\n isValid: ({ min, value }) =>\n isDefined(value) && value !== '' && isDefined(min)\n ? asNumber(value) >= asNumber(min)\n : true,\n};\n\nexport const maxValidator: Validator<{\n max?: number;\n value: number | string;\n}> = {\n key: 'rangeOverflow',\n message: ({ max }) =>\n formatString(ValidationResourceStringsEN.max_validation_error!, max),\n isValid: ({ max, value }) =>\n isDefined(value) && value !== '' && isDefined(max)\n ? asNumber(value) <= asNumber(max)\n : true,\n};\n\nexport const stepValidator: Validator<{\n min?: number;\n step?: number;\n value: number | string;\n}> = {\n key: 'stepMismatch',\n message: 'Value does not conform to step constraint',\n isValid: ({ min, step, value }) => {\n if (isDefined(value) && value !== '' && isDefined(step)) {\n const _value = asNumber(value) - asNumber(min);\n const _step = asNumber(step);\n const magnitude = numberOfDecimals(_step) + 1;\n const rem = roundPrecise(\n Math.abs(_value - _step * Math.round(_value / _step)),\n magnitude\n );\n\n return !rem;\n }\n return true;\n },\n};\n\nexport const emailValidator: Validator<{ value: string }> = {\n key: 'typeMismatch',\n message: ValidationResourceStringsEN.email_validation_error!,\n isValid: ({ value }) => (value ? emailRegex.test(value) : true),\n};\n\nexport const urlValidator: Validator<{ value: string }> = {\n key: 'typeMismatch',\n message: ValidationResourceStringsEN.url_validation_error!,\n isValid: ({ value }) => (value ? URL.canParse(value) : true),\n};\n\nexport const minDateValidator: Validator<{\n value?: Date | null;\n min?: Date | null;\n}> = {\n key: 'rangeUnderflow',\n message: ({ min }) =>\n formatString(ValidationResourceStringsEN.min_validation_error!, min),\n isValid: ({ value, min }) =>\n value && min ? CalendarDay.compare(value, min) >= 0 : true,\n};\n\nexport const maxDateValidator: Validator<{\n value?: Date | null;\n max?: Date | null;\n}> = {\n key: 'rangeOverflow',\n message: ({ max }) =>\n formatString(ValidationResourceStringsEN.max_validation_error!, max),\n isValid: ({ value, max }) =>\n value && max ? CalendarDay.compare(value, max) <= 0 : true,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/internals/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAY7C,MAAM,UAAU,GACd,sIAAsI,CAAC;AAEzI,MAAM,CAAC,MAAM,iBAAiB,GAGzB;IACH,GAAG,EAAE,cAAc;IACnB,OAAO,EAAE,2BAA2B,CAAC,yBAA0B;IAC/D,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;CAC9D,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAGhC;IACH,GAAG,EAAE,cAAc;IACnB,OAAO,EAAE,2BAA2B,CAAC,yBAA0B;IAC/D,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;CAChE,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAG1B;IACH,GAAG,EAAE,UAAU;IACf,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CACzB,YAAY,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ceedingMax, isDateLessThanMin } from './date/compare.js';\nimport { CalendarDay } from './date/model.js';\nimport { asNumber, numberOfDecimals, roundPrecise } from './utils/math.js';\nimport { formatString } from './utils/strings.js';\nimport { isDefined } from './utils/types.js';\n\ntype ValidatorHandler<T> = (host: T) => boolean;\ntype ValidatorMessageFormat<T> = (host: T) => string;\n\n/** @hidden */\nexport interface Validator<T = any> {\n key: keyof ValidityStateFlags;\n message: string | ValidatorMessageFormat<T>;\n isValid: ValidatorHandler<T>;\n}\n\nconst emailRegex =\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;\n\nexport const requiredValidator: Validator<{\n required: boolean;\n value?: unknown;\n}> = {\n key: 'valueMissing',\n message: ValidationResourceStringsEN.required_validation_error!,\n isValid: ({ required, value }) => (required ? !!value : true),\n};\n\nexport const requiredBooleanValidator: Validator<{\n required: boolean;\n checked: boolean;\n}> = {\n key: 'valueMissing',\n message: ValidationResourceStringsEN.required_validation_error!,\n isValid: ({ required, checked }) => (required ? checked : true),\n};\n\nexport const minLengthValidator: Validator<{\n minLength?: number;\n value: string;\n}> = {\n key: 'tooShort',\n message: ({ minLength }) =>\n formatString(\n ValidationResourceStringsEN.min_length_validation_error!,\n minLength\n ),\n isValid: ({ minLength, value }) =>\n minLength && value ? value.length >= asNumber(minLength) : true,\n};\n\nexport const maxLengthValidator: Validator<{\n maxLength?: number;\n value: string;\n}> = {\n key: 'tooLong',\n message: ({ maxLength }) =>\n formatString(\n ValidationResourceStringsEN.max_length_validation_error!,\n maxLength\n ),\n isValid: ({ maxLength, value }) =>\n maxLength && value ? value.length <= asNumber(maxLength) : true,\n};\n\nexport const patternValidator: Validator<{ pattern?: string; value: string }> =\n {\n key: 'patternMismatch',\n message: ValidationResourceStringsEN.pattern_validation_error!,\n isValid: ({ pattern, value }) =>\n pattern && value ? new RegExp(pattern, 'u').test(value) : true,\n };\n\nexport const minValidator: Validator<{\n min?: number;\n value: number | string;\n}> = {\n key: 'rangeUnderflow',\n message: ({ min }) =>\n formatString(ValidationResourceStringsEN.min_validation_error!, min),\n isValid: ({ min, value }) =>\n isDefined(value) && value !== '' && isDefined(min)\n ? asNumber(value) >= asNumber(min)\n : true,\n};\n\nexport const maxValidator: Validator<{\n max?: number;\n value: number | string;\n}> = {\n key: 'rangeOverflow',\n message: ({ max }) =>\n formatString(ValidationResourceStringsEN.max_validation_error!, max),\n isValid: ({ max, value }) =>\n isDefined(value) && value !== '' && isDefined(max)\n ? asNumber(value) <= asNumber(max)\n : true,\n};\n\nexport const stepValidator: Validator<{\n min?: number;\n step?: number;\n value: number | string;\n}> = {\n key: 'stepMismatch',\n message: 'Value does not conform to step constraint',\n isValid: ({ min, step, value }) => {\n if (isDefined(value) && value !== '' && isDefined(step)) {\n const _value = asNumber(value) - asNumber(min);\n const _step = asNumber(step);\n const magnitude = numberOfDecimals(_step) + 1;\n const rem = roundPrecise(\n Math.abs(_value - _step * Math.round(_value / _step)),\n magnitude\n );\n\n return !rem;\n }\n return true;\n },\n};\n\nexport const emailValidator: Validator<{ value: string }> = {\n key: 'typeMismatch',\n message: ValidationResourceStringsEN.email_validation_error!,\n isValid: ({ value }) => (value ? emailRegex.test(value) : true),\n};\n\nexport const urlValidator: Validator<{ value: string }> = {\n key: 'typeMismatch',\n message: ValidationResourceStringsEN.url_validation_error!,\n isValid: ({ value }) => (value ? URL.canParse(value) : true),\n};\n\nexport const minDateValidator: Validator<{\n value?: Date | null;\n min?: Date | null;\n}> = {\n key: 'rangeUnderflow',\n message: ({ min }) =>\n formatString(ValidationResourceStringsEN.min_validation_error!, min),\n isValid: ({ value, min }) =>\n value && min ? CalendarDay.compare(value, min) >= 0 : true,\n};\n\nexport const maxDateValidator: Validator<{\n value?: Date | null;\n max?: Date | null;\n}> = {\n key: 'rangeOverflow',\n message: ({ max }) =>\n formatString(ValidationResourceStringsEN.max_validation_error!, max),\n isValid: ({ value, max }) =>\n value && max ? CalendarDay.compare(value, max) <= 0 : true,\n};\n\n/** A host whose bound comparisons follow the parts present in its format. */\ninterface DatePartsHost {\n hasDateParts(): boolean;\n hasTimeParts(): boolean;\n}\n\n/** Compares a date against a bound at the granularity of the host's format. */\ntype DateBoundComparer = (\n date: Date,\n bound: Date,\n hasTimeParts: boolean,\n hasDateParts: boolean\n) => boolean;\n\n/** Whether no value of the host exceeds `bound`. An absent bound holds. */\nfunction isWithinBound<T extends DatePartsHost>(\n host: T,\n bound: Date | null | undefined,\n values: (Date | null | undefined)[],\n exceeds: DateBoundComparer\n): boolean {\n return bound\n ? values.every(\n (date) =>\n !date ||\n !exceeds(date, bound, host.hasTimeParts(), host.hasDateParts())\n )\n : true;\n}\n\n/**\n * Creates a `rangeUnderflow` validator for hosts whose `min` comparison must\n * respect the parts of the host's format - day granularity when the format has\n * no time parts, time-of-day granularity when it has no date parts.\n *\n * `resolveValues` returns the dates checked against the bound; empty slots\n * are skipped, so a partial range validates only its present ends.\n */\nexport function createMinDateTimeValidator<\n T extends DatePartsHost & { min?: Date | null },\n>(resolveValues: (host: T) => (Date | null | undefined)[]): Validator<T> {\n return {\n key: 'rangeUnderflow',\n message: ({ min }) =>\n formatString(ValidationResourceStringsEN.min_validation_error!, min),\n isValid: (host) =>\n isWithinBound(host, host.min, resolveValues(host), isDateLessThanMin),\n };\n}\n\n/**\n * Creates a `rangeOverflow` validator for hosts whose `max` comparison must\n * respect the parts of the host's format. See {@link createMinDateTimeValidator}.\n */\nexport function createMaxDateTimeValidator<\n T extends DatePartsHost & { max?: Date | null },\n>(resolveValues: (host: T) => (Date | null | undefined)[]): Validator<T> {\n return {\n key: 'rangeOverflow',\n message: ({ max }) =>\n formatString(ValidationResourceStringsEN.max_validation_error!, max),\n isValid: (host) =>\n isWithinBound(host, host.max, resolveValues(host), isDateExceedingMax),\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-webcomponents",
|
|
3
|
-
"version": "7.3.0
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.",
|
|
5
5
|
"author": "Infragistics",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,6 +51,8 @@
|
|
|
51
51
|
"chat",
|
|
52
52
|
"checkbox",
|
|
53
53
|
"chip",
|
|
54
|
+
"color picker",
|
|
55
|
+
"color input",
|
|
54
56
|
"combo",
|
|
55
57
|
"date input",
|
|
56
58
|
"date picker",
|
|
@@ -5,8 +5,8 @@ import type { Theme, Themes, ThemeVariant, ThemingControllerConfig } from './typ
|
|
|
5
5
|
*
|
|
6
6
|
* It resolves the active theme from one of two sources, in order of priority:
|
|
7
7
|
*
|
|
8
|
-
* 1. **Context**
|
|
9
|
-
* 2. **Global**
|
|
8
|
+
* 1. **Context** - provided by an ancestor `<igc-theme-provider>` element via the Lit context API.
|
|
9
|
+
* 2. **Global** - the application-wide theme set via `configureTheme()`.
|
|
10
10
|
*
|
|
11
11
|
* When a context provider is present, the controller subscribes to its updates
|
|
12
12
|
* and stops listening to global theme change events. When the host element is
|
|
@@ -17,7 +17,7 @@ import type { Theme, Themes, ThemeVariant, ThemingControllerConfig } from './typ
|
|
|
17
17
|
* every time the active theme or variant changes.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* Basic usage
|
|
20
|
+
* Basic usage - typically created via {@link addThemingController}:
|
|
21
21
|
* ```typescript
|
|
22
22
|
* import { addThemingController } from '#theming/theming-controller.js';
|
|
23
23
|
* import { all } from './themes/themes.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theming-controller.js","sourceRoot":"","sources":["../../src/theming/theming-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,c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ClB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAgC,CAAC;QACzD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,IAAI,GAAG,CAAA,EAAE,CAAC;QAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAA,EAAE,CAAC;QAEhE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,UAAW,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9E,CAAC;CAGF;AAkDD,MAAM,UAAU,oBAAoB,CAClC,IAA8C,EAC9C,MAAc,EACd,MAAgC;IAEhC,OAAO,IAAI,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { ContextConsumer } from '@lit/context';\nimport {\n adoptStyles,\n css,\n type LitElement,\n type ReactiveController,\n type ReactiveControllerHost,\n type ReactiveElement,\n} from 'lit';\n\nimport { getTheme } from './config.js';\nimport { themeContext } from './context.js';\nimport { _themeChangedEmitter, CHANGED_THEME_EVENT } from './theming-event.js';\nimport type {\n Theme,\n Themes,\n ThemeVariant,\n ThemingControllerConfig,\n} from './types.js';\n\ntype ThemeProviderSource = 'uninitialized' | 'context' | 'global';\n\n/**\n * A reactive controller that manages theme adoption for a Lit host element.\n *\n * It resolves the active theme from one of two sources, in order of priority:\n *\n * 1. **Context** — provided by an ancestor `<igc-theme-provider>` element via the Lit context API.\n * 2. **Global** — the application-wide theme set via `configureTheme()`.\n *\n * When a context provider is present, the controller subscribes to its updates\n * and stops listening to global theme change events. When the host element is\n * disconnected and reconnected outside a provider, it automatically falls back\n * to the global theme.\n *\n * Theme styles are applied directly to the host's shadow root via `adoptStyles`\n * every time the active theme or variant changes.\n *\n * @example\n * Basic usage — typically created via {@link addThemingController}:\n * ```typescript\n * import { addThemingController } from '#theming/theming-controller.js';\n * import { all } from './themes/themes.js';\n *\n * export default class IgcMyComponent extends LitElement {\n * constructor() {\n * super();\n * addThemingController(this, all);\n * }\n * }\n * ```\n *\n * @example\n * Accessing the current theme and variant at runtime:\n * ```typescript\n * export default class IgcMyComponent extends LitElement {\n * private readonly _themes = addThemingController(this, all);\n *\n * protected override render() {\n * // Conditionally render based on active theme\n * return this._themes.variant === 'dark'\n * ? html`<div class=\"dark-layout\"></div>`\n * : html`<div class=\"light-layout\"></div>`;\n * }\n * }\n * ```\n */\nclass ThemingController implements ReactiveController {\n //#region Internal state\n\n private readonly _host: ReactiveControllerHost & ReactiveElement;\n private readonly _themes: Themes;\n private readonly _options?: ThemingControllerConfig;\n private readonly _contextConsumer: ContextConsumer<\n typeof themeContext,\n ReactiveElement\n >;\n\n private _theme: Theme = 'bootstrap';\n private _variant: ThemeVariant = 'light';\n private _themeSource: ThemeProviderSource = 'uninitialized';\n\n //#endregion\n\n //#region Public properties\n\n /** Gets the current theme. */\n public get theme(): Theme {\n return this._theme;\n }\n\n /** Gets the current theme variant. */\n public get variant(): ThemeVariant {\n return this._variant;\n }\n\n //#endregion\n\n constructor(\n host: ReactiveControllerHost & ReactiveElement,\n themes: Themes,\n config?: ThemingControllerConfig\n ) {\n this._host = host;\n this._themes = themes;\n this._options = config;\n\n this._host.addController(this);\n\n this._contextConsumer = new ContextConsumer(this._host, {\n context: themeContext,\n callback: (value) => {\n if (value) {\n this._applyContextTheme(value);\n }\n },\n subscribe: true,\n });\n }\n\n //#region ReactiveController implementation\n\n /** @internal */\n public hostConnected(): void {\n // Apply the global theme initially. When the host's first update cycle begins, if a context provider is\n // present and has set its value, the callback will be invoked and override with the context value.\n this._applyGlobalTheme();\n }\n\n /** @internal */\n public hostDisconnected(): void {\n if (this._themeSource === 'global') {\n _themeChangedEmitter.removeEventListener(CHANGED_THEME_EVENT, this);\n }\n\n // Reset to initial state so that if the host reconnects in a different part of the tree,\n // it can properly re-resolve the theme source.\n this._themeSource = 'uninitialized';\n this._contextConsumer.value = undefined;\n }\n\n //#endregion\n\n //#region Event handling\n\n /** @internal */\n public handleEvent(): void {\n if (this._themeSource === 'global') {\n this._applyGlobalTheme();\n }\n }\n\n //#endregion\n\n //#region Internal methods\n\n private _applyContextTheme(contextValue: {\n theme: Theme;\n variant: ThemeVariant;\n }): void {\n // If we were using global theme, unsubscribe from global events\n if (this._themeSource === 'global') {\n _themeChangedEmitter.removeEventListener(CHANGED_THEME_EVENT, this);\n }\n\n this._themeSource = 'context';\n this._applyTheme(contextValue.theme, contextValue.variant);\n }\n\n private _applyGlobalTheme(): void {\n // Subscribe to global events only on first initialization\n if (this._themeSource === 'uninitialized') {\n _themeChangedEmitter.addEventListener(CHANGED_THEME_EVENT, this);\n }\n\n const { theme, themeVariant } = getTheme();\n\n this._themeSource = 'global';\n this._applyTheme(theme, themeVariant);\n }\n\n private _applyTheme(theme: Theme, variant: ThemeVariant): void {\n this._theme = theme;\n this._variant = variant;\n\n this._adoptStyles();\n this._options?.themeChange?.call(this._host, this._theme);\n this._host.requestUpdate();\n }\n\n private _adoptStyles(): void {\n const ctor = this._host.constructor as typeof LitElement;\n const shared = this._themes[this._variant].shared || css``;\n const theme = this._themes[this._variant][this._theme] || css``;\n\n adoptStyles(this._host.shadowRoot!, [...ctor.elementStyles, shared, theme]);\n }\n\n //#endregion\n}\n\n/**\n * Creates and attaches a {@link ThemingController} to the given host element.\n *\n * This is the preferred way to add theming support to a component. The controller\n * is registered with the host's reactive controller lifecycle and automatically\n * resolves the active theme from an ancestor `<igc-theme-provider>` context or\n * falls back to the application-wide theme set via `configureTheme()`.\n *\n * @param host - The Lit element that will host the controller.\n * @param themes - The theme styles map containing `light` and `dark` variant entries,\n * each keyed by theme name (`bootstrap`, `material`, `fluent`, `indigo`) and\n * an optional `shared` entry applied regardless of theme.\n * @param config - Optional configuration.\n * @param config.themeChange - Callback invoked on the host whenever the active theme changes.\n *\n * @returns The created {@link ThemingController} instance.\n *\n * @example\n * Minimal setup in a component constructor:\n * ```typescript\n * import { addThemingController } from '#theming/theming-controller.js';\n * import { all } from './themes/themes.js';\n *\n * export default class IgcMyComponent extends LitElement {\n * constructor() {\n * super();\n * addThemingController(this, all);\n * }\n * }\n * ```\n *\n * @example\n * With a `themeChange` callback and retained controller reference:\n * ```typescript\n * export default class IgcMyComponent extends LitElement {\n * private readonly _themingController = addThemingController(this, all, {\n * themeChange(theme) {\n * // Called on `this` (the host) whenever the theme switches\n * console.log(`Theme changed to: ${theme}`);\n * },\n * });\n *\n * protected override render() {\n * return html`<span>Current variant: ${this._themingController.variant}</span>`;\n * }\n * }\n * ```\n */\nexport function addThemingController(\n host: ReactiveControllerHost & ReactiveElement,\n themes: Themes,\n config?: ThemingControllerConfig\n): ThemingController {\n return new ThemingController(host, themes, config);\n}\n\nexport type { ThemingController };\n"]}
|
|
1
|
+
{"version":3,"file":"theming-controller.js","sourceRoot":"","sources":["../../src/theming/theming-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,GAAG,GAKJ,MAAM,KAAK,CAAC;AAEb,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAuD/E,MAAM,iBAAiB;IAoBrB,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAGD,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAID,YACE,IAA8C,EAC9C,MAAc,EACd,MAAgC;QAvB1B,WAAM,GAAU,WAAW,CAAC;QAC5B,aAAQ,GAAiB,OAAO,CAAC;QACjC,iBAAY,GAAwB,eAAe,CAAC;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IAAI,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { ContextConsumer } from '@lit/context';\nimport {\n adoptStyles,\n css,\n type LitElement,\n type ReactiveController,\n type ReactiveControllerHost,\n type ReactiveElement,\n} from 'lit';\n\nimport { getTheme } from './config.js';\nimport { themeContext } from './context.js';\nimport { _themeChangedEmitter, CHANGED_THEME_EVENT } from './theming-event.js';\nimport type {\n Theme,\n Themes,\n ThemeVariant,\n ThemingControllerConfig,\n} from './types.js';\n\ntype ThemeProviderSource = 'uninitialized' | 'context' | 'global';\n\n/**\n * A reactive controller that manages theme adoption for a Lit host element.\n *\n * It resolves the active theme from one of two sources, in order of priority:\n *\n * 1. **Context** - provided by an ancestor `<igc-theme-provider>` element via the Lit context API.\n * 2. **Global** - the application-wide theme set via `configureTheme()`.\n *\n * When a context provider is present, the controller subscribes to its updates\n * and stops listening to global theme change events. When the host element is\n * disconnected and reconnected outside a provider, it automatically falls back\n * to the global theme.\n *\n * Theme styles are applied directly to the host's shadow root via `adoptStyles`\n * every time the active theme or variant changes.\n *\n * @example\n * Basic usage - typically created via {@link addThemingController}:\n * ```typescript\n * import { addThemingController } from '#theming/theming-controller.js';\n * import { all } from './themes/themes.js';\n *\n * export default class IgcMyComponent extends LitElement {\n * constructor() {\n * super();\n * addThemingController(this, all);\n * }\n * }\n * ```\n *\n * @example\n * Accessing the current theme and variant at runtime:\n * ```typescript\n * export default class IgcMyComponent extends LitElement {\n * private readonly _themes = addThemingController(this, all);\n *\n * protected override render() {\n * // Conditionally render based on active theme\n * return this._themes.variant === 'dark'\n * ? html`<div class=\"dark-layout\"></div>`\n * : html`<div class=\"light-layout\"></div>`;\n * }\n * }\n * ```\n */\nclass ThemingController implements ReactiveController {\n //#region Internal state\n\n private readonly _host: ReactiveControllerHost & ReactiveElement;\n private readonly _themes: Themes;\n private readonly _options?: ThemingControllerConfig;\n private readonly _contextConsumer: ContextConsumer<\n typeof themeContext,\n ReactiveElement\n >;\n\n private _theme: Theme = 'bootstrap';\n private _variant: ThemeVariant = 'light';\n private _themeSource: ThemeProviderSource = 'uninitialized';\n\n //#endregion\n\n //#region Public properties\n\n /** Gets the current theme. */\n public get theme(): Theme {\n return this._theme;\n }\n\n /** Gets the current theme variant. */\n public get variant(): ThemeVariant {\n return this._variant;\n }\n\n //#endregion\n\n constructor(\n host: ReactiveControllerHost & ReactiveElement,\n themes: Themes,\n config?: ThemingControllerConfig\n ) {\n this._host = host;\n this._themes = themes;\n this._options = config;\n\n this._host.addController(this);\n\n this._contextConsumer = new ContextConsumer(this._host, {\n context: themeContext,\n callback: (value) => {\n if (value) {\n this._applyContextTheme(value);\n }\n },\n subscribe: true,\n });\n }\n\n //#region ReactiveController implementation\n\n /** @internal */\n public hostConnected(): void {\n // Apply the global theme initially. When the host's first update cycle begins, if a context provider is\n // present and has set its value, the callback will be invoked and override with the context value.\n this._applyGlobalTheme();\n }\n\n /** @internal */\n public hostDisconnected(): void {\n if (this._themeSource === 'global') {\n _themeChangedEmitter.removeEventListener(CHANGED_THEME_EVENT, this);\n }\n\n // Reset to initial state so that if the host reconnects in a different part of the tree,\n // it can properly re-resolve the theme source.\n this._themeSource = 'uninitialized';\n this._contextConsumer.value = undefined;\n }\n\n //#endregion\n\n //#region Event handling\n\n /** @internal */\n public handleEvent(): void {\n if (this._themeSource === 'global') {\n this._applyGlobalTheme();\n }\n }\n\n //#endregion\n\n //#region Internal methods\n\n private _applyContextTheme(contextValue: {\n theme: Theme;\n variant: ThemeVariant;\n }): void {\n // If we were using global theme, unsubscribe from global events\n if (this._themeSource === 'global') {\n _themeChangedEmitter.removeEventListener(CHANGED_THEME_EVENT, this);\n }\n\n this._themeSource = 'context';\n this._applyTheme(contextValue.theme, contextValue.variant);\n }\n\n private _applyGlobalTheme(): void {\n // Subscribe to global events only on first initialization\n if (this._themeSource === 'uninitialized') {\n _themeChangedEmitter.addEventListener(CHANGED_THEME_EVENT, this);\n }\n\n const { theme, themeVariant } = getTheme();\n\n this._themeSource = 'global';\n this._applyTheme(theme, themeVariant);\n }\n\n private _applyTheme(theme: Theme, variant: ThemeVariant): void {\n this._theme = theme;\n this._variant = variant;\n\n this._adoptStyles();\n this._options?.themeChange?.call(this._host, this._theme);\n this._host.requestUpdate();\n }\n\n private _adoptStyles(): void {\n const ctor = this._host.constructor as typeof LitElement;\n const shared = this._themes[this._variant].shared || css``;\n const theme = this._themes[this._variant][this._theme] || css``;\n\n adoptStyles(this._host.shadowRoot!, [...ctor.elementStyles, shared, theme]);\n }\n\n //#endregion\n}\n\n/**\n * Creates and attaches a {@link ThemingController} to the given host element.\n *\n * This is the preferred way to add theming support to a component. The controller\n * is registered with the host's reactive controller lifecycle and automatically\n * resolves the active theme from an ancestor `<igc-theme-provider>` context or\n * falls back to the application-wide theme set via `configureTheme()`.\n *\n * @param host - The Lit element that will host the controller.\n * @param themes - The theme styles map containing `light` and `dark` variant entries,\n * each keyed by theme name (`bootstrap`, `material`, `fluent`, `indigo`) and\n * an optional `shared` entry applied regardless of theme.\n * @param config - Optional configuration.\n * @param config.themeChange - Callback invoked on the host whenever the active theme changes.\n *\n * @returns The created {@link ThemingController} instance.\n *\n * @example\n * Minimal setup in a component constructor:\n * ```typescript\n * import { addThemingController } from '#theming/theming-controller.js';\n * import { all } from './themes/themes.js';\n *\n * export default class IgcMyComponent extends LitElement {\n * constructor() {\n * super();\n * addThemingController(this, all);\n * }\n * }\n * ```\n *\n * @example\n * With a `themeChange` callback and retained controller reference:\n * ```typescript\n * export default class IgcMyComponent extends LitElement {\n * private readonly _themingController = addThemingController(this, all, {\n * themeChange(theme) {\n * // Called on `this` (the host) whenever the theme switches\n * console.log(`Theme changed to: ${theme}`);\n * },\n * });\n *\n * protected override render() {\n * return html`<span>Current variant: ${this._themingController.variant}</span>`;\n * }\n * }\n * ```\n */\nexport function addThemingController(\n host: ReactiveControllerHost & ReactiveElement,\n themes: Themes,\n config?: ThemingControllerConfig\n): ThemingController {\n return new ThemingController(host, themes, config);\n}\n\nexport type { ThemingController };\n"]}
|