@funstack/ui 0.1.0-alpha.10 → 0.1.0-alpha.12
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/dist/accordion/accordion-context.mjs.map +1 -1
- package/dist/accordion/accordion-item.d.mts +3 -4
- package/dist/accordion/accordion-item.d.mts.map +1 -1
- package/dist/accordion/accordion-item.mjs +10 -4
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-panel.d.mts +3 -4
- package/dist/accordion/accordion-panel.d.mts.map +1 -1
- package/dist/accordion/accordion-panel.mjs +2 -1
- package/dist/accordion/accordion-panel.mjs.map +1 -1
- package/dist/accordion/accordion-root.d.mts +3 -3
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +8 -19
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts +3 -4
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +5 -3
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/button/button.d.mts +4 -2
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +3 -2
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.d.mts +4 -5
- package/dist/checkbox/checkbox.d.mts.map +1 -1
- package/dist/checkbox/checkbox.mjs +16 -59
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-context.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-item.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +21 -27
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-label.mjs +1 -6
- package/dist/checkbox-group/checkbox-group-label.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.d.mts +3 -4
- package/dist/checkbox-group/checkbox-group-parent.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +12 -10
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +74 -101
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +5 -6
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-group.d.mts.map +1 -1
- package/dist/combobox/combobox-group.mjs +2 -1
- package/dist/combobox/combobox-group.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +14 -7
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts.map +1 -1
- package/dist/combobox/combobox-list.mjs +6 -10
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +2 -1
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs +9 -25
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +11 -10
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +37 -109
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +6 -25
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/index.d.mts +2 -2
- package/dist/combobox/index.mjs +3 -3
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +56 -0
- package/dist/combobox/use-combobox-form.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +62 -0
- package/dist/combobox/use-option-registry.mjs.map +1 -0
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +29 -62
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +5 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +3 -4
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +37 -98
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +30 -118
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +13 -16
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/field/field-control.mjs +6 -13
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts.map +1 -1
- package/dist/field/field-description.mjs +1 -2
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts.map +1 -1
- package/dist/field/field-error.mjs +1 -2
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +3 -11
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +21 -41
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.mjs +1 -1
- package/dist/field/use-server-error-visibility.mjs +44 -0
- package/dist/field/use-server-error-visibility.mjs.map +1 -0
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +6 -7
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +1 -1
- package/dist/form/form-submit.mjs +4 -10
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/internal/anchor-position.mjs +1 -59
- package/dist/internal/anchor-position.mjs.map +1 -1
- package/dist/internal/announce.mjs.map +1 -1
- package/dist/internal/arrow-keys.mjs +21 -0
- package/dist/internal/arrow-keys.mjs.map +1 -0
- package/dist/internal/decimal.mjs +7 -1
- package/dist/internal/decimal.mjs.map +1 -1
- package/dist/internal/dom-order.mjs +17 -0
- package/dist/internal/dom-order.mjs.map +1 -0
- package/dist/internal/field-context.d.mts.map +1 -1
- package/dist/internal/field-context.mjs +11 -1
- package/dist/internal/field-context.mjs.map +1 -1
- package/dist/internal/focus-first-invalid.mjs +1 -1
- package/dist/internal/focus-first-invalid.mjs.map +1 -1
- package/dist/internal/group-member.mjs +37 -0
- package/dist/internal/group-member.mjs.map +1 -0
- package/dist/internal/overlay-popup.mjs +103 -0
- package/dist/internal/overlay-popup.mjs.map +1 -0
- package/dist/internal/popover-open.mjs +18 -0
- package/dist/internal/popover-open.mjs.map +1 -0
- package/dist/internal/render-element.d.mts +2 -0
- package/dist/internal/render-element.mjs +20 -2
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/shipped-styles.mjs +14 -0
- package/dist/internal/shipped-styles.mjs.map +1 -0
- package/dist/internal/sync-presence.mjs +5 -1
- package/dist/internal/sync-presence.mjs.map +1 -1
- package/dist/internal/toolbar-context.mjs.map +1 -1
- package/dist/internal/tooltip-warm.mjs +1 -1
- package/dist/internal/tooltip-warm.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +1 -1
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/types.d.mts +8 -6
- package/dist/internal/types.d.mts.map +1 -1
- package/dist/internal/use-action-trigger.mjs +5 -23
- package/dist/internal/use-action-trigger.mjs.map +1 -1
- package/dist/internal/use-checkable-input.mjs +79 -0
- package/dist/internal/use-checkable-input.mjs.map +1 -0
- package/dist/internal/use-controllable-action.mjs +16 -24
- package/dist/internal/use-controllable-action.mjs.map +1 -1
- package/dist/internal/use-dev-warning.mjs +8 -4
- package/dist/internal/use-dev-warning.mjs.map +1 -1
- package/dist/internal/use-element-check.mjs +39 -0
- package/dist/internal/use-element-check.mjs.map +1 -0
- package/dist/internal/use-exit-animation.mjs +1 -1
- package/dist/internal/use-exit-animation.mjs.map +1 -1
- package/dist/internal/use-field-control.mjs +28 -12
- package/dist/internal/use-field-control.mjs.map +1 -1
- package/dist/internal/use-fieldset-group.mjs +46 -0
- package/dist/internal/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/use-form-reset.mjs +1 -5
- package/dist/internal/use-form-reset.mjs.map +1 -1
- package/dist/internal/use-item-order.mjs +42 -0
- package/dist/internal/use-item-order.mjs.map +1 -0
- package/dist/internal/use-latest.mjs +4 -8
- package/dist/internal/use-latest.mjs.map +1 -1
- package/dist/internal/use-merged-refs.mjs +19 -0
- package/dist/internal/use-merged-refs.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +84 -0
- package/dist/internal/use-name-warning.mjs.map +1 -0
- package/dist/internal/use-native-checked.mjs +4 -6
- package/dist/internal/use-native-checked.mjs.map +1 -1
- package/dist/internal/use-native-focusgroup.mjs +19 -0
- package/dist/internal/use-native-focusgroup.mjs.map +1 -0
- package/dist/internal/use-native-group-reconciliation.mjs.map +1 -1
- package/dist/internal/use-overlay-close.mjs +63 -0
- package/dist/internal/use-overlay-close.mjs.map +1 -0
- package/dist/internal/{use-popover-root.mjs → use-overlay-root.mjs} +28 -39
- package/dist/internal/use-overlay-root.mjs.map +1 -0
- package/dist/internal/use-popover-popup.mjs +32 -78
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.d.mts +15 -0
- package/dist/internal/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/use-popover-trigger.mjs +13 -17
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/use-register-count.mjs +24 -0
- package/dist/internal/use-register-count.mjs.map +1 -0
- package/dist/internal/use-render.d.mts +2 -0
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-resolved-placement.mjs +38 -22
- package/dist/internal/use-resolved-placement.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs +5 -18
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/internal/use-superseded-rejection.mjs +47 -0
- package/dist/internal/use-superseded-rejection.mjs.map +1 -0
- package/dist/internal/validity.mjs +1 -13
- package/dist/internal/validity.mjs.map +1 -1
- package/dist/internal/value-set.mjs +41 -0
- package/dist/internal/value-set.mjs.map +1 -0
- package/dist/menu/index.d.mts +1 -1
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context-trigger.d.mts +2 -7
- package/dist/menu/menu-context-trigger.d.mts.map +1 -1
- package/dist/menu/menu-context-trigger.mjs +10 -187
- package/dist/menu/menu-context-trigger.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-dom.mjs +1 -2
- package/dist/menu/menu-dom.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +167 -0
- package/dist/menu/menu-gestures.mjs.map +1 -0
- package/dist/menu/menu-group.d.mts.map +1 -1
- package/dist/menu/menu-group.mjs +2 -1
- package/dist/menu/menu-group.mjs.map +1 -1
- package/dist/menu/menu-hover.mjs +0 -1
- package/dist/menu/menu-hover.mjs.map +1 -1
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +101 -0
- package/dist/menu/menu-outside.mjs.map +1 -0
- package/dist/menu/menu-point.mjs +85 -0
- package/dist/menu/menu-point.mjs.map +1 -0
- package/dist/menu/menu-popup.d.mts +6 -7
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +37 -248
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.d.mts +10 -0
- package/dist/menu/menu-root.d.mts.map +1 -1
- package/dist/menu/menu-root.mjs +10 -8
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +6 -6
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +4 -9
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +8 -6
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/menu/use-menu-item.mjs +14 -16
- package/dist/menu/use-menu-item.mjs.map +1 -1
- package/dist/menu/use-menu-keyboard.mjs +88 -0
- package/dist/menu/use-menu-keyboard.mjs.map +1 -0
- package/dist/meter/meter-root.mjs +1 -1
- package/dist/number-field/index.d.mts +2 -1
- package/dist/number-field/index.d.mts.map +1 -1
- package/dist/number-field/index.mjs +2 -2
- package/dist/number-field/index.mjs.map +1 -1
- package/dist/number-field/number-field-arithmetic.mjs +30 -11
- package/dist/number-field/number-field-arithmetic.mjs.map +1 -1
- package/dist/number-field/number-field-context.d.mts +6 -1
- package/dist/number-field/number-field-context.d.mts.map +1 -0
- package/dist/number-field/number-field-context.mjs.map +1 -1
- package/dist/number-field/number-field-decrement.d.mts +1 -1
- package/dist/number-field/number-field-decrement.mjs +1 -1
- package/dist/number-field/number-field-decrement.mjs.map +1 -1
- package/dist/number-field/number-field-increment.d.mts +2 -22
- package/dist/number-field/number-field-increment.d.mts.map +1 -1
- package/dist/number-field/number-field-increment.mjs +2 -53
- package/dist/number-field/number-field-increment.mjs.map +1 -1
- package/dist/number-field/number-field-input.d.mts.map +1 -1
- package/dist/number-field/number-field-input.mjs +18 -22
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-label.d.mts.map +1 -1
- package/dist/number-field/number-field-label.mjs +3 -9
- package/dist/number-field/number-field-label.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts +2 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +81 -91
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/number-field/use-number-field-dev-warnings.mjs +28 -0
- package/dist/number-field/use-number-field-dev-warnings.mjs.map +1 -0
- package/dist/number-field/use-step-button.d.mts +24 -0
- package/dist/number-field/use-step-button.d.mts.map +1 -0
- package/dist/number-field/use-step-button.mjs +57 -3
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +28 -67
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +9 -6
- package/dist/popover/popover-popup.d.mts.map +1 -1
- package/dist/popover/popover-popup.mjs +13 -36
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +4 -3
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +4 -8
- package/dist/popover/popover-trigger.d.mts.map +1 -1
- package/dist/popover/popover-trigger.mjs +2 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/progress/progress-root.mjs +1 -1
- package/dist/radio-group/radio-group-context.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.d.mts +3 -4
- package/dist/radio-group/radio-group-item.d.mts.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +20 -25
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-label.mjs +1 -6
- package/dist/radio-group/radio-group-label.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +21 -40
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-dom.mjs +9 -18
- package/dist/select/select-dom.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-root.mjs +3 -2
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/slider/slider-arithmetic.mjs +74 -13
- package/dist/slider/slider-arithmetic.mjs.map +1 -1
- package/dist/slider/slider-context.mjs.map +1 -1
- package/dist/slider/slider-label.d.mts.map +1 -1
- package/dist/slider/slider-label.mjs +3 -9
- package/dist/slider/slider-label.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts +2 -2
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +36 -116
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/slider-thumb.d.mts.map +1 -1
- package/dist/slider/slider-thumb.mjs +8 -6
- package/dist/slider/slider-thumb.mjs.map +1 -1
- package/dist/slider/slider-value.d.mts.map +1 -1
- package/dist/slider/slider-value.mjs +2 -1
- package/dist/slider/slider-value.mjs.map +1 -1
- package/dist/slider/use-slider-dev-warnings.mjs +29 -0
- package/dist/slider/use-slider-dev-warnings.mjs.map +1 -0
- package/dist/slider/use-thumb-registry.mjs +51 -0
- package/dist/slider/use-thumb-registry.mjs.map +1 -0
- package/dist/switch/switch.d.mts +4 -5
- package/dist/switch/switch.d.mts.map +1 -1
- package/dist/switch/switch.mjs +15 -55
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-context.d.mts +2 -3
- package/dist/tabs/tabs-context.d.mts.map +1 -1
- package/dist/tabs/tabs-context.mjs.map +1 -1
- package/dist/tabs/tabs-list.d.mts.map +1 -1
- package/dist/tabs/tabs-list.mjs +9 -22
- package/dist/tabs/tabs-list.mjs.map +1 -1
- package/dist/tabs/tabs-panel.d.mts +3 -4
- package/dist/tabs/tabs-panel.d.mts.map +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts +4 -3
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +2 -1
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/tabs/tabs-tab.d.mts +3 -4
- package/dist/tabs/tabs-tab.d.mts.map +1 -1
- package/dist/tabs/tabs-tab.mjs.map +1 -1
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +2 -8
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-context.mjs.map +1 -1
- package/dist/toast/toast-hotkey.mjs +27 -0
- package/dist/toast/toast-hotkey.mjs.map +1 -0
- package/dist/toast/toast-queue.mjs +137 -0
- package/dist/toast/toast-queue.mjs.map +1 -0
- package/dist/toast/toast-timers.mjs +65 -0
- package/dist/toast/toast-timers.mjs.map +1 -0
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +30 -235
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/toast.mjs +1 -1
- package/dist/toast/toast.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +52 -0
- package/dist/toast/use-modal-portal-host.mjs.map +1 -0
- package/dist/toggle/toggle.d.mts +3 -4
- package/dist/toggle/toggle.d.mts.map +1 -1
- package/dist/toggle/toggle.mjs +7 -10
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-context.d.mts +2 -1
- package/dist/toggle-group/toggle-group-context.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-context.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-item.d.mts +5 -3
- package/dist/toggle-group/toggle-group-item.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-item.mjs +5 -7
- package/dist/toggle-group/toggle-group-item.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +29 -64
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/toolbar/toolbar-root.d.mts +2 -2
- package/dist/toolbar/toolbar-root.d.mts.map +1 -1
- package/dist/toolbar/toolbar-root.mjs +3 -4
- package/dist/toolbar/toolbar-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.d.mts.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +6 -15
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +2 -2
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.d.mts +2 -1
- package/dist/tooltip/tooltip-trigger.d.mts.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +3 -2
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/tooltip/use-tooltip-interaction.mjs +4 -3
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/accordion/accordion-context.d.mts +0 -5
- package/dist/accordion/accordion-context.d.mts.map +0 -1
- package/dist/internal/use-popover-root.mjs.map +0 -1
- /package/dist/internal/{use-popover-root.d.mts → use-overlay-root.d.mts} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EPSILON, gridDecimals, roundTo } from "../internal/decimal.mjs";
|
|
2
|
+
import { clamp, percentage } from "../internal/range-value.mjs";
|
|
2
3
|
//#region src/slider/slider-arithmetic.ts
|
|
3
|
-
/** Tolerance for grid computations on binary floating point (`0.3 / 0.1` is `2.9999999999999996`). */
|
|
4
|
-
const EPSILON = 1e-9;
|
|
5
4
|
/**
|
|
6
5
|
* The value a native range with these bounds would hold for `value`: snapped to
|
|
7
6
|
* `min + n × step` (ties toward +∞, the HTML step-mismatch rule), clamped to `[min, max]`, and,
|
|
@@ -10,7 +9,7 @@ const EPSILON = 1e-9;
|
|
|
10
9
|
* platform's maximum is `min`.
|
|
11
10
|
*/
|
|
12
11
|
function snap(value, min, max, step) {
|
|
13
|
-
const decimals =
|
|
12
|
+
const decimals = gridDecimals(step, min);
|
|
14
13
|
if (!Number.isFinite(value)) return min;
|
|
15
14
|
if (!(max > min)) return roundTo(min, decimals);
|
|
16
15
|
const lastIndex = Math.floor((max - min) / step + EPSILON);
|
|
@@ -31,7 +30,7 @@ function isOnGrid(value, min, max, step) {
|
|
|
31
30
|
}
|
|
32
31
|
/** The native `min` / `max` of thumb `index`: the slider's bounds, narrowed by its neighbours. */
|
|
33
32
|
function thumbBounds(values, index, min, max, gap) {
|
|
34
|
-
const decimals =
|
|
33
|
+
const decimals = gridDecimals(gap, min);
|
|
35
34
|
const before = values[index - 1];
|
|
36
35
|
const after = values[index + 1];
|
|
37
36
|
return {
|
|
@@ -47,7 +46,7 @@ function thumbBounds(values, index, min, max, gap) {
|
|
|
47
46
|
function clampToNeighbours(values, index, next, min, max, step, gap) {
|
|
48
47
|
const { lower, upper } = thumbBounds(values, index, min, max, gap);
|
|
49
48
|
const current = values[index] ?? next;
|
|
50
|
-
if (lower > upper +
|
|
49
|
+
if (lower > upper + 1e-9) return current;
|
|
51
50
|
return Math.min(Math.max(snap(next, min, max, step), lower), upper);
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
@@ -64,9 +63,7 @@ function sanitize(values, reference, min, max, step, gap) {
|
|
|
64
63
|
}
|
|
65
64
|
/** Position of `value` in `[min, max]`, in percent, clamped to `0`–`100`. */
|
|
66
65
|
function percent(value, min, max) {
|
|
67
|
-
|
|
68
|
-
const fraction = (value - min) / (max - min);
|
|
69
|
-
return Math.min(100, Math.max(0, fraction * 100));
|
|
66
|
+
return clamp(percentage(value, min, max), 0, 100);
|
|
70
67
|
}
|
|
71
68
|
/**
|
|
72
69
|
* The thumb a track press at `target` moves: the nearest by value. On a tie (two thumbs at one
|
|
@@ -78,10 +75,10 @@ function nearestThumb(values, target) {
|
|
|
78
75
|
let bestDistance = Number.POSITIVE_INFINITY;
|
|
79
76
|
values.forEach((value, index) => {
|
|
80
77
|
const distance = Math.abs(value - target);
|
|
81
|
-
if (distance < bestDistance -
|
|
78
|
+
if (distance < bestDistance - 1e-9) {
|
|
82
79
|
best = index;
|
|
83
80
|
bestDistance = distance;
|
|
84
|
-
} else if (Math.abs(distance - bestDistance) <=
|
|
81
|
+
} else if (Math.abs(distance - bestDistance) <= 1e-9 && target > value) best = index;
|
|
85
82
|
});
|
|
86
83
|
return best;
|
|
87
84
|
}
|
|
@@ -95,10 +92,74 @@ function equalValues(a, b) {
|
|
|
95
92
|
if (a.length !== b.length) return false;
|
|
96
93
|
return a.every((value, index) => {
|
|
97
94
|
const other = b[index];
|
|
98
|
-
return value === other || Math.abs(value - other) <
|
|
95
|
+
return value === other || Math.abs(value - other) < 1e-9 * Math.max(1, Math.abs(value));
|
|
99
96
|
});
|
|
100
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* The value under a pointer at `(clientX, clientY)` on a track occupying `rect` (design 4.1):
|
|
100
|
+
* left to right (right to left with `rtl`), or bottom to top when vertical, clamped to the track
|
|
101
|
+
* and mapped linearly onto `[min, max]`. Not snapped. An empty track maps to `min` (`max` in RTL).
|
|
102
|
+
*/
|
|
103
|
+
function pointerValue(rect, clientX, clientY, orientation, rtl, min, max) {
|
|
104
|
+
let fraction;
|
|
105
|
+
if (orientation === "vertical") fraction = rect.height > 0 ? (rect.bottom - clientY) / rect.height : 0;
|
|
106
|
+
else {
|
|
107
|
+
fraction = rect.width > 0 ? (clientX - rect.left) / rect.width : 0;
|
|
108
|
+
if (rtl) fraction = 1 - fraction;
|
|
109
|
+
}
|
|
110
|
+
fraction = Math.min(1, Math.max(0, fraction));
|
|
111
|
+
return min + fraction * (max - min);
|
|
112
|
+
}
|
|
113
|
+
/** The run of thumbs sharing thumb `index`'s value, or `null` when it shares it with none. */
|
|
114
|
+
function tiedRange(values, index) {
|
|
115
|
+
const at = values[index];
|
|
116
|
+
if (at === void 0) return null;
|
|
117
|
+
let first = index;
|
|
118
|
+
let last = index;
|
|
119
|
+
while (first > 0 && equalValues([values[first - 1]], [at])) first -= 1;
|
|
120
|
+
while (last < values.length - 1 && equalValues([values[last + 1]], [at])) last += 1;
|
|
121
|
+
return first !== last ? {
|
|
122
|
+
first,
|
|
123
|
+
last,
|
|
124
|
+
at
|
|
125
|
+
} : null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Which of the stacked thumbs a pointer at `raw` moves: the one that can go toward it (the last
|
|
129
|
+
* above the shared value, the first below). `null` exactly on the value (or with no tie).
|
|
130
|
+
*/
|
|
131
|
+
function resolveTie(tied, raw) {
|
|
132
|
+
if (tied === null) return null;
|
|
133
|
+
if (raw > tied.at) return tied.last;
|
|
134
|
+
if (raw < tied.at) return tied.first;
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The Root's geometry custom properties (design 3.1): `--slider-start` (the first thumb with
|
|
139
|
+
* several, else `0%`), `--slider-end` (the last thumb) and `--slider-value-<i>`, in percent.
|
|
140
|
+
*/
|
|
141
|
+
function sliderGeometry(shown, min, max) {
|
|
142
|
+
const count = shown.length;
|
|
143
|
+
const percents = shown.map((v) => percent(v, min, max));
|
|
144
|
+
const geometry = {
|
|
145
|
+
"--slider-start": count > 1 ? `${percents[0] ?? 0}%` : "0%",
|
|
146
|
+
"--slider-end": `${percents[count - 1] ?? 0}%`
|
|
147
|
+
};
|
|
148
|
+
percents.forEach((p, index) => {
|
|
149
|
+
geometry[`--slider-value-${index}`] = `${p}%`;
|
|
150
|
+
});
|
|
151
|
+
return geometry;
|
|
152
|
+
}
|
|
153
|
+
/** A Slider value as an array, one entry per thumb. */
|
|
154
|
+
function toArray(value) {
|
|
155
|
+
return typeof value === "number" ? [value] : value;
|
|
156
|
+
}
|
|
157
|
+
/** The shape of a Slider value (fixed at mount, design 3.1). */
|
|
158
|
+
function shapeOf(value) {
|
|
159
|
+
if (value === void 0) return void 0;
|
|
160
|
+
return typeof value === "number" ? "number" : "array";
|
|
161
|
+
}
|
|
101
162
|
//#endregion
|
|
102
|
-
export { clampToNeighbours,
|
|
163
|
+
export { clampToNeighbours, equalValues, isMaxReachable, isOnGrid, nearestThumb, percent, platformDefault, pointerValue, resolveTie, sanitize, shapeOf, sliderGeometry, snap, thumbBounds, tiedRange, toArray };
|
|
103
164
|
|
|
104
165
|
//# sourceMappingURL=slider-arithmetic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider-arithmetic.mjs","names":[],"sources":["../../src/slider/slider-arithmetic.ts"],"sourcesContent":["// Pure value arithmetic of the Slider (design/components/slider.md 5). No directive: no React,\n// no client-only API. The library computes exactly what the platform's range sanitisation would,\n// so the number it renders is the number the DOM holds and `FormData` posts.\n\nimport { decimalsOf, roundTo } from \"../internal/decimal.js\";\n\nexport { decimalsOf };\n\n/** Tolerance for grid computations on binary floating point (`0.3 / 0.1` is `2.9999999999999996`). */\nconst EPSILON = 1e-9;\n\n/**\n * The value a native range with these bounds would hold for `value`: snapped to\n * `min + n × step` (ties toward +∞, the HTML step-mismatch rule), clamped to `[min, max]`, and,\n * when the snapped value exceeds `max`, the last grid point below `max` (so `min 0, max 5,\n * step 2` caps at `4`). Rounded to the decimal places of `step` and `min`. With `max < min` the\n * platform's maximum is `min`.\n */\nexport function snap(value: number, min: number, max: number, step: number): number {\n const decimals = Math.max(decimalsOf(step), decimalsOf(min));\n if (!Number.isFinite(value)) return min;\n if (!(max > min)) return roundTo(min, decimals);\n const lastIndex = Math.floor((max - min) / step + EPSILON);\n let index = Math.floor((value - min) / step + 0.5 + EPSILON);\n if (index > lastIndex) index = lastIndex;\n if (index < 0) index = 0;\n return roundTo(min + index * step, decimals);\n}\n\n/** Whether `max` is reachable: `max - min` is a whole number of steps. */\nexport function isMaxReachable(min: number, max: number, step: number): boolean {\n if (!(max > min)) return true;\n const steps = (max - min) / step;\n return Math.abs(steps - Math.round(steps)) < EPSILON * Math.max(1, steps);\n}\n\n/** Whether `value` is a value a native range with these bounds can hold unchanged. */\nexport function isOnGrid(value: number, min: number, max: number, step: number): boolean {\n return Math.abs(snap(value, min, max, step) - value) < EPSILON * Math.max(1, Math.abs(value));\n}\n\n/** The native `min` / `max` of thumb `index`: the slider's bounds, narrowed by its neighbours. */\nexport function thumbBounds(\n values: readonly number[],\n index: number,\n min: number,\n max: number,\n gap: number,\n): { readonly lower: number; readonly upper: number } {\n const decimals = Math.max(decimalsOf(gap), decimalsOf(min));\n const before = values[index - 1];\n const after = values[index + 1];\n const lower = before === undefined ? min : roundTo(before + gap, decimals);\n const upper = after === undefined ? max : roundTo(after - gap, decimals);\n return { lower, upper };\n}\n\n/**\n * `next` for thumb `index`, snapped to the slider's grid and clamped between its neighbours\n * (`values[i - 1] + gap`, `values[i + 1] - gap`; on the grid, because every thumb shares `step`\n * and `min`). With no room between the neighbours the thumb keeps its value.\n */\nexport function clampToNeighbours(\n values: readonly number[],\n index: number,\n next: number,\n min: number,\n max: number,\n step: number,\n gap: number,\n): number {\n const { lower, upper } = thumbBounds(values, index, min, max, gap);\n const current = values[index] ?? next;\n if (lower > upper + EPSILON) return current;\n return Math.min(Math.max(snap(next, min, max, step), lower), upper);\n}\n\n/**\n * The value a native input with these attributes would hold for `value` (each thumb's bounds come\n * from `reference`, the values it is rendered against). Used to compare a DOM read with the shown\n * value: jsdom does not sanitise a range's value, browsers do, and a consumer's off-grid value is\n * rendered as given and sanitised by the DOM.\n */\nexport function sanitize(\n values: readonly number[],\n reference: readonly number[],\n min: number,\n max: number,\n step: number,\n gap: number,\n): readonly number[] {\n return values.map((value, index) => {\n const { lower, upper } = thumbBounds(reference, index, min, max, gap);\n // The native step base is the input's own `min` attribute (the neighbour-adjusted bound).\n return snap(value, lower, Math.max(lower, upper), step);\n });\n}\n\n/** Position of `value` in `[min, max]`, in percent, clamped to `0`–`100`. */\nexport function percent(value: number, min: number, max: number): number {\n if (!(max > min)) return 0;\n const fraction = (value - min) / (max - min);\n return Math.min(100, Math.max(0, fraction * 100));\n}\n\n/**\n * The thumb a track press at `target` moves: the nearest by value. On a tie (two thumbs at one\n * value, or equidistant thumbs) the thumb that can move toward the pointer: the later one when\n * the pointer is above it, else the earlier one.\n */\nexport function nearestThumb(values: readonly number[], target: number): number {\n let best = 0;\n let bestDistance = Number.POSITIVE_INFINITY;\n values.forEach((value, index) => {\n const distance = Math.abs(value - target);\n if (distance < bestDistance - EPSILON) {\n best = index;\n bestDistance = distance;\n } else if (Math.abs(distance - bestDistance) <= EPSILON && target > value) {\n best = index;\n }\n });\n return best;\n}\n\n/** The platform's default value: the midpoint, snapped to the grid; `min` when `max < min`. */\nexport function platformDefault(min: number, max: number, step: number): number {\n if (!(max > min)) return min;\n return snap(min + (max - min) / 2, min, max, step);\n}\n\n/** Element-wise equality of two value arrays (within floating-point tolerance). */\nexport function equalValues(a: readonly number[], b: readonly number[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((value, index) => {\n const other = b[index] as number;\n return value === other || Math.abs(value - other) < EPSILON * Math.max(1, Math.abs(value));\n });\n}\n"],"mappings":";;;AASA,MAAM,UAAU;;;;;;;;AAShB,SAAgB,KAAK,OAAe,KAAa,KAAa,MAAsB;CAClF,MAAM,WAAW,KAAK,IAAI,WAAW,IAAI,GAAG,WAAW,GAAG,CAAC;CAC3D,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO;CACpC,IAAI,EAAE,MAAM,MAAM,OAAO,QAAQ,KAAK,QAAQ;CAC9C,MAAM,YAAY,KAAK,OAAO,MAAM,OAAO,OAAO,OAAO;CACzD,IAAI,QAAQ,KAAK,OAAO,QAAQ,OAAO,OAAO,KAAM,OAAO;CAC3D,IAAI,QAAQ,WAAW,QAAQ;CAC/B,IAAI,QAAQ,GAAG,QAAQ;CACvB,OAAO,QAAQ,MAAM,QAAQ,MAAM,QAAQ;AAC7C;;AAGA,SAAgB,eAAe,KAAa,KAAa,MAAuB;CAC9E,IAAI,EAAE,MAAM,MAAM,OAAO;CACzB,MAAM,SAAS,MAAM,OAAO;CAC5B,OAAO,KAAK,IAAI,QAAQ,KAAK,MAAM,KAAK,CAAC,IAAI,UAAU,KAAK,IAAI,GAAG,KAAK;AAC1E;;AAGA,SAAgB,SAAS,OAAe,KAAa,KAAa,MAAuB;CACvF,OAAO,KAAK,IAAI,KAAK,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,IAAI,UAAU,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,CAAC;AAC9F;;AAGA,SAAgB,YACd,QACA,OACA,KACA,KACA,KACoD;CACpD,MAAM,WAAW,KAAK,IAAI,WAAW,GAAG,GAAG,WAAW,GAAG,CAAC;CAC1D,MAAM,SAAS,OAAO,QAAQ;CAC9B,MAAM,QAAQ,OAAO,QAAQ;CAG7B,OAAO;EAAE,OAFK,WAAW,KAAA,IAAY,MAAM,QAAQ,SAAS,KAAK,QAAQ;EAEzD,OADF,UAAU,KAAA,IAAY,MAAM,QAAQ,QAAQ,KAAK,QAAQ;CACjD;AACxB;;;;;;AAOA,SAAgB,kBACd,QACA,OACA,MACA,KACA,KACA,MACA,KACQ;CACR,MAAM,EAAE,OAAO,UAAU,YAAY,QAAQ,OAAO,KAAK,KAAK,GAAG;CACjE,MAAM,UAAU,OAAO,UAAU;CACjC,IAAI,QAAQ,QAAQ,SAAS,OAAO;CACpC,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK,MAAM,KAAK,KAAK,IAAI,GAAG,KAAK,GAAG,KAAK;AACpE;;;;;;;AAQA,SAAgB,SACd,QACA,WACA,KACA,KACA,MACA,KACmB;CACnB,OAAO,OAAO,KAAK,OAAO,UAAU;EAClC,MAAM,EAAE,OAAO,UAAU,YAAY,WAAW,OAAO,KAAK,KAAK,GAAG;EAEpE,OAAO,KAAK,OAAO,OAAO,KAAK,IAAI,OAAO,KAAK,GAAG,IAAI;CACxD,CAAC;AACH;;AAGA,SAAgB,QAAQ,OAAe,KAAa,KAAqB;CACvE,IAAI,EAAE,MAAM,MAAM,OAAO;CACzB,MAAM,YAAY,QAAQ,QAAQ,MAAM;CACxC,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,WAAW,GAAG,CAAC;AAClD;;;;;;AAOA,SAAgB,aAAa,QAA2B,QAAwB;CAC9E,IAAI,OAAO;CACX,IAAI,eAAe,OAAO;CAC1B,OAAO,SAAS,OAAO,UAAU;EAC/B,MAAM,WAAW,KAAK,IAAI,QAAQ,MAAM;EACxC,IAAI,WAAW,eAAe,SAAS;GACrC,OAAO;GACP,eAAe;EACjB,OAAO,IAAI,KAAK,IAAI,WAAW,YAAY,KAAK,WAAW,SAAS,OAClE,OAAO;CAEX,CAAC;CACD,OAAO;AACT;;AAGA,SAAgB,gBAAgB,KAAa,KAAa,MAAsB;CAC9E,IAAI,EAAE,MAAM,MAAM,OAAO;CACzB,OAAO,KAAK,OAAO,MAAM,OAAO,GAAG,KAAK,KAAK,IAAI;AACnD;;AAGA,SAAgB,YAAY,GAAsB,GAA+B;CAC/E,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OAAO,OAAO,UAAU;EAC/B,MAAM,QAAQ,EAAE;EAChB,OAAO,UAAU,SAAS,KAAK,IAAI,QAAQ,KAAK,IAAI,UAAU,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,CAAC;CAC3F,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"slider-arithmetic.mjs","names":[],"sources":["../../src/slider/slider-arithmetic.ts"],"sourcesContent":["// Pure value arithmetic of the Slider (design/components/slider.md 5). No directive: no React,\n// no client-only API. The library computes exactly what the platform's range sanitisation would,\n// so the number it renders is the number the DOM holds and `FormData` posts.\n\nimport { EPSILON, gridDecimals, roundTo } from \"../internal/decimal.js\";\nimport { clamp, percentage } from \"../internal/range-value.js\";\nimport type { Orientation } from \"../internal/types.js\";\n\n/**\n * The value a native range with these bounds would hold for `value`: snapped to\n * `min + n × step` (ties toward +∞, the HTML step-mismatch rule), clamped to `[min, max]`, and,\n * when the snapped value exceeds `max`, the last grid point below `max` (so `min 0, max 5,\n * step 2` caps at `4`). Rounded to the decimal places of `step` and `min`. With `max < min` the\n * platform's maximum is `min`.\n */\nexport function snap(value: number, min: number, max: number, step: number): number {\n const decimals = gridDecimals(step, min);\n if (!Number.isFinite(value)) return min;\n if (!(max > min)) return roundTo(min, decimals);\n const lastIndex = Math.floor((max - min) / step + EPSILON);\n let index = Math.floor((value - min) / step + 0.5 + EPSILON);\n if (index > lastIndex) index = lastIndex;\n if (index < 0) index = 0;\n return roundTo(min + index * step, decimals);\n}\n\n/** Whether `max` is reachable: `max - min` is a whole number of steps. */\nexport function isMaxReachable(min: number, max: number, step: number): boolean {\n if (!(max > min)) return true;\n const steps = (max - min) / step;\n return Math.abs(steps - Math.round(steps)) < EPSILON * Math.max(1, steps);\n}\n\n/** Whether `value` is a value a native range with these bounds can hold unchanged. */\nexport function isOnGrid(value: number, min: number, max: number, step: number): boolean {\n return Math.abs(snap(value, min, max, step) - value) < EPSILON * Math.max(1, Math.abs(value));\n}\n\n/** The native `min` / `max` of thumb `index`: the slider's bounds, narrowed by its neighbours. */\nexport function thumbBounds(\n values: readonly number[],\n index: number,\n min: number,\n max: number,\n gap: number,\n): { readonly lower: number; readonly upper: number } {\n const decimals = gridDecimals(gap, min);\n const before = values[index - 1];\n const after = values[index + 1];\n const lower = before === undefined ? min : roundTo(before + gap, decimals);\n const upper = after === undefined ? max : roundTo(after - gap, decimals);\n return { lower, upper };\n}\n\n/**\n * `next` for thumb `index`, snapped to the slider's grid and clamped between its neighbours\n * (`values[i - 1] + gap`, `values[i + 1] - gap`; on the grid, because every thumb shares `step`\n * and `min`). With no room between the neighbours the thumb keeps its value.\n */\nexport function clampToNeighbours(\n values: readonly number[],\n index: number,\n next: number,\n min: number,\n max: number,\n step: number,\n gap: number,\n): number {\n const { lower, upper } = thumbBounds(values, index, min, max, gap);\n const current = values[index] ?? next;\n if (lower > upper + EPSILON) return current;\n return Math.min(Math.max(snap(next, min, max, step), lower), upper);\n}\n\n/**\n * The value a native input with these attributes would hold for `value` (each thumb's bounds come\n * from `reference`, the values it is rendered against). Used to compare a DOM read with the shown\n * value: jsdom does not sanitise a range's value, browsers do, and a consumer's off-grid value is\n * rendered as given and sanitised by the DOM.\n */\nexport function sanitize(\n values: readonly number[],\n reference: readonly number[],\n min: number,\n max: number,\n step: number,\n gap: number,\n): readonly number[] {\n return values.map((value, index) => {\n const { lower, upper } = thumbBounds(reference, index, min, max, gap);\n // The native step base is the input's own `min` attribute (the neighbour-adjusted bound).\n return snap(value, lower, Math.max(lower, upper), step);\n });\n}\n\n/** Position of `value` in `[min, max]`, in percent, clamped to `0`–`100`. */\nexport function percent(value: number, min: number, max: number): number {\n return clamp(percentage(value, min, max), 0, 100);\n}\n\n/**\n * The thumb a track press at `target` moves: the nearest by value. On a tie (two thumbs at one\n * value, or equidistant thumbs) the thumb that can move toward the pointer: the later one when\n * the pointer is above it, else the earlier one.\n */\nexport function nearestThumb(values: readonly number[], target: number): number {\n let best = 0;\n let bestDistance = Number.POSITIVE_INFINITY;\n values.forEach((value, index) => {\n const distance = Math.abs(value - target);\n if (distance < bestDistance - EPSILON) {\n best = index;\n bestDistance = distance;\n } else if (Math.abs(distance - bestDistance) <= EPSILON && target > value) {\n best = index;\n }\n });\n return best;\n}\n\n/** The platform's default value: the midpoint, snapped to the grid; `min` when `max < min`. */\nexport function platformDefault(min: number, max: number, step: number): number {\n if (!(max > min)) return min;\n return snap(min + (max - min) / 2, min, max, step);\n}\n\n/** Element-wise equality of two value arrays (within floating-point tolerance). */\nexport function equalValues(a: readonly number[], b: readonly number[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((value, index) => {\n const other = b[index] as number;\n return value === other || Math.abs(value - other) < EPSILON * Math.max(1, Math.abs(value));\n });\n}\n\n/** The part of `DOMRect` a pointer position is mapped through. */\nexport interface TrackRect {\n readonly left: number;\n readonly bottom: number;\n readonly width: number;\n readonly height: number;\n}\n\n/**\n * The value under a pointer at `(clientX, clientY)` on a track occupying `rect` (design 4.1):\n * left to right (right to left with `rtl`), or bottom to top when vertical, clamped to the track\n * and mapped linearly onto `[min, max]`. Not snapped. An empty track maps to `min` (`max` in RTL).\n */\nexport function pointerValue(\n rect: TrackRect,\n clientX: number,\n clientY: number,\n orientation: Orientation,\n rtl: boolean,\n min: number,\n max: number,\n): number {\n let fraction: number;\n if (orientation === \"vertical\") {\n fraction = rect.height > 0 ? (rect.bottom - clientY) / rect.height : 0;\n } else {\n fraction = rect.width > 0 ? (clientX - rect.left) / rect.width : 0;\n if (rtl) fraction = 1 - fraction;\n }\n fraction = Math.min(1, Math.max(0, fraction));\n return min + fraction * (max - min);\n}\n\n/** Stacked thumbs: the thumbs `first`..`last` all hold the value `at`. */\nexport interface TiedThumbs {\n readonly first: number;\n readonly last: number;\n readonly at: number;\n}\n\n/** The run of thumbs sharing thumb `index`'s value, or `null` when it shares it with none. */\nexport function tiedRange(values: readonly number[], index: number): TiedThumbs | null {\n const at = values[index];\n if (at === undefined) return null;\n let first = index;\n let last = index;\n while (first > 0 && equalValues([values[first - 1] as number], [at])) first -= 1;\n while (last < values.length - 1 && equalValues([values[last + 1] as number], [at])) last += 1;\n return first !== last ? { first, last, at } : null;\n}\n\n/**\n * Which of the stacked thumbs a pointer at `raw` moves: the one that can go toward it (the last\n * above the shared value, the first below). `null` exactly on the value (or with no tie).\n */\nexport function resolveTie(tied: TiedThumbs | null, raw: number): number | null {\n if (tied === null) return null;\n if (raw > tied.at) return tied.last;\n if (raw < tied.at) return tied.first;\n return null;\n}\n\n/**\n * The Root's geometry custom properties (design 3.1): `--slider-start` (the first thumb with\n * several, else `0%`), `--slider-end` (the last thumb) and `--slider-value-<i>`, in percent.\n */\nexport function sliderGeometry(\n shown: readonly number[],\n min: number,\n max: number,\n): Record<string, string> {\n const count = shown.length;\n const percents = shown.map((v) => percent(v, min, max));\n const geometry: Record<string, string> = {\n \"--slider-start\": count > 1 ? `${percents[0] ?? 0}%` : \"0%\",\n \"--slider-end\": `${percents[count - 1] ?? 0}%`,\n };\n percents.forEach((p, index) => {\n geometry[`--slider-value-${index}`] = `${p}%`;\n });\n return geometry;\n}\n\n/** A Slider value as an array, one entry per thumb. */\nexport function toArray(value: number | readonly number[]): readonly number[] {\n return typeof value === \"number\" ? [value] : value;\n}\n\n/** The shape of a Slider value (fixed at mount, design 3.1). */\nexport function shapeOf(\n value: number | readonly number[] | undefined,\n): \"number\" | \"array\" | undefined {\n if (value === undefined) return undefined;\n return typeof value === \"number\" ? \"number\" : \"array\";\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider-context.mjs","names":[],"sources":["../../src/slider/slider-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefCallback, RefObject } from \"react\";\nimport type { SliderOrientation, SliderRootState, SliderValue } from \"./slider-root.js\";\n\n/** What the Root routes from an enclosing `Field.Root` to its Thumbs (design 9.4.1). */\nexport interface SliderFieldWiring {\n /** One thumb only: Thumb `index` 0 merges it into its input ref (registers the input). */\n readonly inputRef: RefCallback<HTMLElement> | undefined;\n /** One thumb only: token-merged into Thumb 0's input `aria-describedby`. */\n readonly describedBy: string | undefined;\n /** On every Thumb's input (ARIA 1.2: never on the group element). */\n readonly invalid: \"true\" | \"false\" | undefined;\n /** On every Thumb's styled element. */\n readonly dataInvalid: \"\" | undefined;\n /** The Field's own `name`, for the Thumb's \"name differs from the Field's\" warning. */\n readonly name: string | undefined;\n}\n\nexport interface SliderContextValue {\n /** The Root's state, for `Slider.Label` and `Slider.Value`. */\n readonly state: SliderRootState<SliderValue>;\n /** The values the thumbs show (design 2.2): `live` while held, else optimistic. */\n readonly shown: readonly number[];\n
|
|
1
|
+
{"version":3,"file":"slider-context.mjs","names":[],"sources":["../../src/slider/slider-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefCallback, RefObject } from \"react\";\nimport type { SliderOrientation, SliderRootState, SliderValue } from \"./slider-root.js\";\n\n/** What the Root routes from an enclosing `Field.Root` to its Thumbs (design 9.4.1). */\nexport interface SliderFieldWiring {\n /** One thumb only: Thumb `index` 0 merges it into its input ref (registers the input). */\n readonly inputRef: RefCallback<HTMLElement> | undefined;\n /** One thumb only: token-merged into Thumb 0's input `aria-describedby`. */\n readonly describedBy: string | undefined;\n /** On every Thumb's input (ARIA 1.2: never on the group element). */\n readonly invalid: \"true\" | \"false\" | undefined;\n /** On every Thumb's styled element. */\n readonly dataInvalid: \"\" | undefined;\n /** The Field's own `name`, for the Thumb's \"name differs from the Field's\" warning. */\n readonly name: string | undefined;\n}\n\nexport interface SliderContextValue {\n /** The Root's state, for `Slider.Label` and `Slider.Value`. */\n readonly state: SliderRootState<SliderValue>;\n /** The values the thumbs show (design 2.2): `live` while held, else optimistic. */\n readonly shown: readonly number[];\n readonly min: number;\n readonly max: number;\n readonly step: number;\n /** `minStepsBetweenThumbs × step`. */\n readonly gap: number;\n readonly orientation: SliderOrientation;\n readonly disabled: boolean;\n /** A step or commit dispatched through this Slider is in flight. */\n readonly pending: boolean;\n /** The thumb a pointer is captured on, or `null`. */\n readonly draggingThumb: number | null;\n /** The thumb the latest step or commit moved, or `null` (platform dispatches). */\n readonly pendingThumb: number | null;\n readonly name: string | undefined;\n readonly form: string | undefined;\n readonly getAriaValueText: ((value: number, index: number) => string) | undefined;\n readonly labelId: string;\n readonly thumbId: (index: number) => string;\n /** The Track's element: the geometry reference for pointer math. */\n readonly trackRef: RefObject<HTMLElement | null>;\n\n /** The native `input` of thumb `index` (React `onChange`): one step. */\n readonly inputStep: (index: number, value: number, event: Event) => void;\n /** The native `change` of thumb `index`: the key press's commit. */\n readonly inputCommit: (index: number, event: Event) => void;\n /** `keydown` on thumb `index`: ArrowLeft / ArrowRight normalisation of a vertical slider. */\n readonly inputKeyDown: (index: number, event: KeyboardEvent) => void;\n /** `pointerdown` on a Thumb (`index`) or on the Track (`null`: the nearest thumb). */\n readonly beginGesture: (index: number | null, event: PointerEvent, element: HTMLElement) => void;\n /** Called by each Thumb from a layout effect; returns the unregistration. */\n readonly registerThumb: (index: number, input: HTMLInputElement) => () => void;\n /** Called by each Label from a layout effect; returns the unregistration. */\n readonly registerLabel: () => () => void;\n /** The enclosing Field's wiring (design 9.4), `null` outside a `Field.Root`. */\n readonly field: SliderFieldWiring | null;\n /** Late-mounting Thumbs report here (useNativeGroupReconciliation). */\n readonly onItemMounted: () => void;\n}\n\nexport const SliderContext = createContext<SliderContextValue | null>(null);\n\nexport function useSliderContext(part: string): SliderContextValue {\n const context = use(SliderContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Slider.Root.`);\n }\n return context;\n}\n"],"mappings":";;;AA+DA,MAAa,gBAAgB,cAAyC,IAAI;AAE1E,SAAgB,iBAAiB,MAAkC;CACjE,MAAM,UAAU,IAAI,aAAa;CACjC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,wCAAwC;CAElE,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider-label.d.mts","names":[],"sources":["../../src/slider/slider-label.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"slider-label.d.mts","names":[],"sources":["../../src/slider/slider-label.tsx"],"mappings":";;;;;iBAYiB,iBAAiB,UAAU,cAAc,qBAAqB,KAC7E;EAGA,YAAY,+BAA+B,gBAAgB;EAC3D,QAAQ,WAAW,2BAA2B,gBAAgB;EAC9D,WAAW,WAAW,WAAW,gBAAgB;;EAEjD,SAAS,WAAW,gCAAgC,gBAAgB;;;;;;;wBAQtD,YAAY,UAAU,cAAc,eAClD,WACA,OACA,UACA,WACG,QACF,iBAAiB,KAAE;yBANN"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
+
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
3
4
|
import { useSliderContext } from "./slider-context.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { useLayoutEffect } from "react";
|
|
5
6
|
//#region src/slider/slider-label.tsx
|
|
6
7
|
const isDev = process.env.NODE_ENV !== "production";
|
|
7
8
|
/**
|
|
@@ -14,14 +15,7 @@ function SliderLabel({ className, style, children, render, ...rest }) {
|
|
|
14
15
|
const { registerLabel } = ctx;
|
|
15
16
|
useLayoutEffect(registerLabel, [registerLabel]);
|
|
16
17
|
const single = ctx.shown.length === 1;
|
|
17
|
-
const
|
|
18
|
-
const libraryRef = useCallback((element) => {
|
|
19
|
-
if (isDev && single && !warnedElement.current && element.tagName !== "LABEL") {
|
|
20
|
-
warnedElement.current = true;
|
|
21
|
-
console.error(`Slider.Label: expected a <label> element but got <${element.tagName.toLowerCase()}>. With one thumb the Label names the input through \`for\`, which only a <label> has.`);
|
|
22
|
-
}
|
|
23
|
-
return () => {};
|
|
24
|
-
}, [single]);
|
|
18
|
+
const libraryRef = useElementCheck(isDev && ((element) => single && element.tagName !== "LABEL" ? `Slider.Label: expected a <label> element but got <${element.tagName.toLowerCase()}>. With one thumb the Label names the input through \`for\`, which only a <label> has.` : null), [single]);
|
|
25
19
|
return useRender({
|
|
26
20
|
defaultElement: "label",
|
|
27
21
|
render,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider-label.mjs","names":[],"sources":["../../src/slider/slider-label.tsx"],"sourcesContent":["\"use client\";\nimport {
|
|
1
|
+
{"version":3,"file":"slider-label.mjs","names":[],"sources":["../../src/slider/slider-label.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useSliderContext } from \"./slider-context.js\";\nimport type { SliderRootState, SliderValue } from \"./slider-root.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `T` defaults to `SliderValue`; pass it to narrow the state (`<Slider.Label<number>>`). */\nexport interface SliderLabelProps<T extends SliderValue = SliderValue> extends Omit<\n ComponentPropsWithRef<\"label\">,\n \"htmlFor\" | \"id\" | \"className\" | \"style\" | \"children\"\n> {\n className?: StateValue<string | undefined, SliderRootState<T>>;\n style?: StateValue<CSSProperties | undefined, SliderRootState<T>>;\n children?: StateValue<ReactNode, SliderRootState<T>>;\n /** Must stay a `<label>` when the slider has one thumb (the `for` association). */\n render?: RenderProp<ComponentPropsWithRef<\"label\">, SliderRootState<T>>;\n}\n\n/**\n * The visible name of the slider: `<label for>` naming the only thumb's input, or, with several\n * thumbs, the element whose `id` the Root's `aria-labelledby` (`role=\"group\"`) points at, emitted\n * only while a Label is mounted. Owned keys: `id`, `htmlFor`.\n */\nexport function SliderLabel<T extends SliderValue = SliderValue>({\n className,\n style,\n children,\n render,\n ...rest\n}: SliderLabelProps<T>) {\n const ctx = useSliderContext(\"Slider.Label\");\n const { registerLabel } = ctx;\n useLayoutEffect(registerLabel, [registerLabel]);\n\n const single = ctx.shown.length === 1;\n const libraryRef = useElementCheck(\n isDev &&\n ((element) =>\n single && element.tagName !== \"LABEL\"\n ? `Slider.Label: expected a <label> element but got <${element.tagName.toLowerCase()}>. ` +\n `With one thumb the Label names the input through \\`for\\`, which only a <label> has.`\n : null),\n [single],\n );\n\n return useRender<ComponentPropsWithRef<\"label\">, SliderRootState<T>>({\n defaultElement: \"label\",\n render,\n state: ctx.state as SliderRootState<T>,\n className,\n style,\n children,\n props: rest,\n ref: libraryRef,\n libraryProps: {\n id: ctx.labelId,\n htmlFor: single ? ctx.thumbId(0) : undefined,\n },\n });\n}\n\nSliderLabel.displayName = \"SliderLabel\";\n"],"mappings":";;;;;;AASA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;AAmBvC,SAAgB,YAAiD,EAC/D,WACA,OACA,UACA,QACA,GAAG,QACmB;CACtB,MAAM,MAAM,iBAAiB,cAAc;CAC3C,MAAM,EAAE,kBAAkB;CAC1B,gBAAgB,eAAe,CAAC,aAAa,CAAC;CAE9C,MAAM,SAAS,IAAI,MAAM,WAAW;CACpC,MAAM,aAAa,gBACjB,WACI,YACA,UAAU,QAAQ,YAAY,UAC1B,qDAAqD,QAAQ,QAAQ,YAAY,EAAE,0FAEnF,OACR,CAAC,MAAM,CACT;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA;EACA,OAAO;EACP,KAAK;EACL,cAAc;GACZ,IAAI,IAAI;GACR,SAAS,SAAS,IAAI,QAAQ,CAAC,IAAI,KAAA;EACrC;CACF,CAAC;AACH;AAEA,YAAY,cAAc"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ActionDetails, ChangeAction, ChangeReason, RenderProp, StateValue } from "../internal/types.mjs";
|
|
1
|
+
import { ActionDetails, ChangeAction, ChangeReason, Orientation, RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
2
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
3
3
|
//#region src/slider/slider-root.d.ts
|
|
4
4
|
/** One number (one thumb) or one number per thumb, in ascending order. */
|
|
5
5
|
export type SliderValue = number | readonly number[];
|
|
6
|
-
export type SliderOrientation =
|
|
6
|
+
export type SliderOrientation = Orientation;
|
|
7
7
|
/** Details passed as the second argument of `Slider.Root`'s `valueChangeAction` (each step). */
|
|
8
8
|
export interface SliderValueChangeDetails extends ActionDetails {
|
|
9
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider-root.d.mts","names":[],"sources":["../../src/slider/slider-root.tsx"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"slider-root.d.mts","names":[],"sources":["../../src/slider/slider-root.tsx"],"mappings":";;;;YA4CY;YAEA,oBAAoB;;iBAGf,iCAAiC;;;;;;;;;;WAUvC,QAAQ;;WAER;;;iBAIM,iCAAiC;;;;;;;WAOvC,QAAQ;;WAER;;iBAGM,gBAAgB,UAAU;;;;;;WAMhC,OAAO;;WAEP;;WAEA;;WAEA;WACA,aAAa;WACb;WACA;WACA;WACA;;iBAGM,gBAAgB,UAAU,8BAA8B,KACvE;;EAcA,QAAQ;;;;;EAKR,eAAe;;;;;;;;;;EAUf,oBAAoB,aAAa,GAAG;;;;;;;EAOpC,oBAAoB,aAAa,GAAG;;EAEpC;;;;;EAKA;;EAEA;;EAEA;;EAEA,cAAc;;;;;EAKd,oBAAoB,eAAe;;;;;EAKnC;;EAEA;;EAEA;EACA,YAAY,+BAA+B,gBAAgB;EAC3D,QAAQ,WAAW,2BAA2B,gBAAgB;EAC9D,WAAW,WAAW,WAAW,gBAAgB;EACjD,SAAS,WAAW,8BAA8B,gBAAgB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createActionDetails } from "../internal/action-details.mjs";
|
|
3
3
|
import { dataAttr } from "../internal/data-attr.mjs";
|
|
4
|
+
import { useSupersededRejection } from "../internal/use-superseded-rejection.mjs";
|
|
4
5
|
import { useActionTrigger } from "../internal/use-action-trigger.mjs";
|
|
5
6
|
import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
6
7
|
import { mergeTokenLists } from "../internal/merge-props.mjs";
|
|
@@ -9,24 +10,19 @@ import { useRender } from "../internal/use-render.mjs";
|
|
|
9
10
|
import { transitionTypes } from "../internal/transition-types.mjs";
|
|
10
11
|
import { useLatest } from "../internal/use-latest.mjs";
|
|
11
12
|
import { useControllableAction } from "../internal/use-controllable-action.mjs";
|
|
12
|
-
import {
|
|
13
|
-
import { useFieldControl, useFieldValueChange, useMergedRef } from "../internal/use-field-control.mjs";
|
|
13
|
+
import { useFieldControl, useFieldValueChange } from "../internal/use-field-control.mjs";
|
|
14
14
|
import { useNativeGroupReconciliation } from "../internal/use-native-group-reconciliation.mjs";
|
|
15
15
|
import { SliderContext } from "./slider-context.mjs";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { useRegisterCount } from "../internal/use-register-count.mjs";
|
|
17
|
+
import { clampToNeighbours, equalValues, nearestThumb, platformDefault, pointerValue, resolveTie, sanitize, shapeOf, sliderGeometry, tiedRange, toArray } from "./slider-arithmetic.mjs";
|
|
18
|
+
import { useSliderDevWarnings } from "./use-slider-dev-warnings.mjs";
|
|
19
|
+
import { useThumbRegistry } from "./use-thumb-registry.mjs";
|
|
20
|
+
import { addTransitionType, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
18
21
|
import { jsx } from "react/jsx-runtime";
|
|
19
22
|
//#region src/slider/slider-root.tsx
|
|
20
23
|
const isDev = process.env.NODE_ENV !== "production";
|
|
21
24
|
const STEP_TYPES = transitionTypes("slider", "change");
|
|
22
25
|
const COMMIT_TYPES = transitionTypes("slider", "commit");
|
|
23
|
-
function toArray(value) {
|
|
24
|
-
return typeof value === "number" ? [value] : value;
|
|
25
|
-
}
|
|
26
|
-
function shapeOf(value) {
|
|
27
|
-
if (value === void 0) return void 0;
|
|
28
|
-
return typeof value === "number" ? "number" : "array";
|
|
29
|
-
}
|
|
30
26
|
function replaceAt(values, index, value) {
|
|
31
27
|
return values.map((v, i) => i === index ? value : v);
|
|
32
28
|
}
|
|
@@ -81,6 +77,7 @@ function SliderRootImpl(props) {
|
|
|
81
77
|
const activeGesture = useRef(null);
|
|
82
78
|
const commitSeq = useRef(0);
|
|
83
79
|
const trackRef = useRef(null);
|
|
80
|
+
const captureSuperseded = useSupersededRejection();
|
|
84
81
|
const runCommit = async (next, details) => {
|
|
85
82
|
const seq = ++commitSeq.current;
|
|
86
83
|
try {
|
|
@@ -102,11 +99,15 @@ function SliderRootImpl(props) {
|
|
|
102
99
|
warn: {
|
|
103
100
|
component: "Slider.Root",
|
|
104
101
|
prop: "value"
|
|
105
|
-
}
|
|
102
|
+
},
|
|
103
|
+
captureSuperseded
|
|
106
104
|
});
|
|
107
105
|
const { optimistic, committed, dispatch } = commitState;
|
|
108
106
|
const committedRef = useLatest(committed);
|
|
109
|
-
const { pending: stepPending, run: runStep } = useActionTrigger({
|
|
107
|
+
const { pending: stepPending, run: runStep } = useActionTrigger({
|
|
108
|
+
ignoreWhilePending: false,
|
|
109
|
+
captureSuperseded
|
|
110
|
+
});
|
|
110
111
|
const optimisticValues = useMemo(() => toArray(optimistic), [optimistic]);
|
|
111
112
|
const shown = (gestureThumb !== null || stepHeld || stepPending || commitState.pending) && live !== null ? live : optimisticValues;
|
|
112
113
|
const pending = stepPending || commitState.pending;
|
|
@@ -117,13 +118,13 @@ function SliderRootImpl(props) {
|
|
|
117
118
|
disabled: disabledProp,
|
|
118
119
|
component: "Slider.Root"
|
|
119
120
|
});
|
|
120
|
-
const fieldName =
|
|
121
|
+
const fieldName = field.fieldName;
|
|
121
122
|
const name = field.name;
|
|
122
123
|
const disabled = field.disabled;
|
|
123
124
|
const fieldId = field.id;
|
|
124
125
|
const thumbId = useCallback((index) => index === 0 && fieldId !== void 0 ? fieldId : `${id}-thumb-${index}`, [id, fieldId]);
|
|
125
|
-
const rootRef =
|
|
126
|
-
useDevWarning(field.inField && field.required, "Slider.Root: a range is never empty, so `required` on the enclosing Field.Root has no effect on the slider.");
|
|
126
|
+
const rootRef = thumbCount > 1 ? field.ref : void 0;
|
|
127
|
+
useDevWarning(field.inField && field.required, isDev && "Slider.Root: a range is never empty, so `required` on the enclosing Field.Root has no effect on the slider.");
|
|
127
128
|
/**
|
|
128
129
|
* The reason of the latest change the user or the platform made, consumed by the Field
|
|
129
130
|
* notification below: `"activate"` dismisses a shown server error, a rollback does not.
|
|
@@ -201,50 +202,8 @@ function SliderRootImpl(props) {
|
|
|
201
202
|
thumb
|
|
202
203
|
}));
|
|
203
204
|
}, [dispatch, latest]);
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
const warnedForm = useRef(false);
|
|
207
|
-
const registerThumb = useCallback((index, input) => {
|
|
208
|
-
const existing = registry.get(index);
|
|
209
|
-
if (isDev && existing !== void 0 && existing !== input && !warnedDuplicate.current) {
|
|
210
|
-
warnedDuplicate.current = true;
|
|
211
|
-
console.error(`Slider.Thumb: two Thumbs have \`index={${index}}\`. Each value needs exactly one Thumb; give every Thumb a distinct index.`);
|
|
212
|
-
}
|
|
213
|
-
if (isDev && !warnedForm.current) {
|
|
214
|
-
for (const other of registry.values()) if (other !== input && other.form !== input.form) {
|
|
215
|
-
warnedForm.current = true;
|
|
216
|
-
console.error("Slider.Thumb: the thumbs of one Slider belong to different forms (a Thumb's `form` prop). A form reset is followed through the first thumb's form only; keep every thumb in one form.");
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
registry.set(index, input);
|
|
221
|
-
return () => {
|
|
222
|
-
if (registry.get(index) === input) registry.delete(index);
|
|
223
|
-
};
|
|
224
|
-
}, [registry]);
|
|
225
|
-
/** The first registered input: the form-associated element the reset subscription follows. */
|
|
226
|
-
const formElement = useMemo(() => ({
|
|
227
|
-
get current() {
|
|
228
|
-
let first = null;
|
|
229
|
-
let firstIndex = Number.POSITIVE_INFINITY;
|
|
230
|
-
for (const [index, input] of registry) if (index < firstIndex) {
|
|
231
|
-
firstIndex = index;
|
|
232
|
-
first = input;
|
|
233
|
-
}
|
|
234
|
-
return first;
|
|
235
|
-
},
|
|
236
|
-
set current(_ignored) {}
|
|
237
|
-
}), [registry]);
|
|
238
|
-
const [labelCount, setLabelCount] = useState(0);
|
|
239
|
-
const labelCountRef = useRef(0);
|
|
240
|
-
const registerLabel = useCallback(() => {
|
|
241
|
-
labelCountRef.current += 1;
|
|
242
|
-
setLabelCount((count) => count + 1);
|
|
243
|
-
return () => {
|
|
244
|
-
labelCountRef.current -= 1;
|
|
245
|
-
setLabelCount((count) => count - 1);
|
|
246
|
-
};
|
|
247
|
-
}, []);
|
|
205
|
+
const { registry, registerThumb, formElement } = useThumbRegistry();
|
|
206
|
+
const { count: labelCount, register: registerLabel, countRef: labelCountRef } = useRegisterCount();
|
|
248
207
|
const [mountValue] = useState(value);
|
|
249
208
|
const resetTarget = () => value !== void 0 ? toArray(mountValue ?? value) : toArray(defaultValue ?? platformDefault(min, max, step));
|
|
250
209
|
const readCurrent = () => shownRef.current.map((v, index) => {
|
|
@@ -335,14 +294,7 @@ function SliderRootImpl(props) {
|
|
|
335
294
|
const valueAt = (clientX, clientY) => {
|
|
336
295
|
const { min: lo, max: hi, orientation: axis } = latest.current;
|
|
337
296
|
const rect = (trackRef.current ?? track).getBoundingClientRect();
|
|
338
|
-
|
|
339
|
-
if (axis === "vertical") fraction = rect.height > 0 ? (rect.bottom - clientY) / rect.height : 0;
|
|
340
|
-
else {
|
|
341
|
-
fraction = rect.width > 0 ? (clientX - rect.left) / rect.width : 0;
|
|
342
|
-
if (rtl) fraction = 1 - fraction;
|
|
343
|
-
}
|
|
344
|
-
fraction = Math.min(1, Math.max(0, fraction));
|
|
345
|
-
return lo + fraction * (hi - lo);
|
|
297
|
+
return pointerValue(rect, clientX, clientY, axis, rtl, lo, hi);
|
|
346
298
|
};
|
|
347
299
|
const moveTo = (thumb, raw, cause) => {
|
|
348
300
|
const { min: lo, max: hi, step: inc, gap: g } = latest.current;
|
|
@@ -352,29 +304,9 @@ function SliderRootImpl(props) {
|
|
|
352
304
|
};
|
|
353
305
|
const start = valueAt(event.clientX, event.clientY);
|
|
354
306
|
const startValues = shownRef.current;
|
|
355
|
-
|
|
356
|
-
if (index !== null) {
|
|
357
|
-
const at = startValues[index];
|
|
358
|
-
if (at !== void 0) {
|
|
359
|
-
let first = index;
|
|
360
|
-
let last = index;
|
|
361
|
-
while (first > 0 && equalValues([startValues[first - 1]], [at])) first -= 1;
|
|
362
|
-
while (last < startValues.length - 1 && equalValues([startValues[last + 1]], [at])) last += 1;
|
|
363
|
-
if (first !== last) tied = {
|
|
364
|
-
first,
|
|
365
|
-
last,
|
|
366
|
-
at
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const resolveTie = (raw) => {
|
|
371
|
-
if (tied === null) return null;
|
|
372
|
-
if (raw > tied.at) return tied.last;
|
|
373
|
-
if (raw < tied.at) return tied.first;
|
|
374
|
-
return null;
|
|
375
|
-
};
|
|
307
|
+
const tied = index === null ? null : tiedRange(startValues, index);
|
|
376
308
|
/** The thumb the gesture moves; `null` while a press on stacked thumbs is undecided. */
|
|
377
|
-
let decided = index === null ? nearestThumb(startValues, start) : tied ? resolveTie(start) : index;
|
|
309
|
+
let decided = index === null ? nearestThumb(startValues, start) : tied ? resolveTie(tied, start) : index;
|
|
378
310
|
/** The thumb shown as dragging and focused meanwhile. */
|
|
379
311
|
let thumb = decided ?? index ?? 0;
|
|
380
312
|
const pointerId = event.pointerId;
|
|
@@ -383,7 +315,7 @@ function SliderRootImpl(props) {
|
|
|
383
315
|
} catch {}
|
|
384
316
|
const decide = (raw) => {
|
|
385
317
|
if (decided !== null) return true;
|
|
386
|
-
decided = resolveTie(raw);
|
|
318
|
+
decided = resolveTie(tied, raw);
|
|
387
319
|
if (decided === null) return false;
|
|
388
320
|
if (decided !== thumb) {
|
|
389
321
|
thumb = decided;
|
|
@@ -439,30 +371,20 @@ function SliderRootImpl(props) {
|
|
|
439
371
|
activeGesture.current?.detach();
|
|
440
372
|
activeGesture.current = null;
|
|
441
373
|
}, []);
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
if (!isDev || warnedGroupName.current || !unnamedGroup || labelCountRef.current > 0) return;
|
|
454
|
-
warnedGroupName.current = true;
|
|
455
|
-
console.error("Slider.Root: a slider with several thumbs is a `group` and needs a name: render a Slider.Label, or pass `aria-label` / `aria-labelledby` to the Root.");
|
|
456
|
-
}, [unnamedGroup]);
|
|
457
|
-
const count = shown.length;
|
|
458
|
-
const percents = shown.map((v) => percent(v, min, max));
|
|
459
|
-
const geometry = {
|
|
460
|
-
"--slider-start": count > 1 ? `${percents[0] ?? 0}%` : "0%",
|
|
461
|
-
"--slider-end": `${percents[count - 1] ?? 0}%`
|
|
462
|
-
};
|
|
463
|
-
percents.forEach((p, index) => {
|
|
464
|
-
geometry[`--slider-value-${index}`] = `${p}%`;
|
|
374
|
+
useSliderDevWarnings({
|
|
375
|
+
stepProp,
|
|
376
|
+
stepValid,
|
|
377
|
+
min,
|
|
378
|
+
max,
|
|
379
|
+
step,
|
|
380
|
+
value,
|
|
381
|
+
defaultValue,
|
|
382
|
+
shape,
|
|
383
|
+
unnamedGroup: shown.length > 1 && !inField && rest["aria-label"] === void 0 && rest["aria-labelledby"] === void 0,
|
|
384
|
+
labelCountRef
|
|
465
385
|
});
|
|
386
|
+
const count = shown.length;
|
|
387
|
+
const geometry = sliderGeometry(shown, min, max);
|
|
466
388
|
const shownValue = fromArray(shown);
|
|
467
389
|
const dragging = gestureThumb !== null;
|
|
468
390
|
const state = useMemo(() => ({
|
|
@@ -489,7 +411,6 @@ function SliderRootImpl(props) {
|
|
|
489
411
|
const context = useMemo(() => ({
|
|
490
412
|
state,
|
|
491
413
|
shown,
|
|
492
|
-
shownValue,
|
|
493
414
|
min,
|
|
494
415
|
max,
|
|
495
416
|
step,
|
|
@@ -516,7 +437,6 @@ function SliderRootImpl(props) {
|
|
|
516
437
|
}), [
|
|
517
438
|
state,
|
|
518
439
|
shown,
|
|
519
|
-
shownValue,
|
|
520
440
|
min,
|
|
521
441
|
max,
|
|
522
442
|
step,
|