@appica/ui-react 1.0.0 → 1.2.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 +72 -0
- package/README.md +47 -5
- package/agent-rules.md +41 -0
- package/appica.css +7 -0
- package/dist/components/accordion/accordion.d.ts +24 -0
- package/dist/components/accordion/accordion.d.ts.map +1 -1
- package/dist/components/accordion/accordion.js +2 -1
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/alert/alert.d.ts +30 -2
- package/dist/components/alert/alert.d.ts.map +1 -1
- package/dist/components/alert/alert.js +2 -1
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.d.ts +12 -2
- package/dist/components/alert-dialog/alert-dialog.d.ts.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.js +10 -5
- package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/components/autocomplete/autocomplete.d.ts +21 -1
- package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
- package/dist/components/autocomplete/autocomplete.js +3 -2
- package/dist/components/autocomplete/autocomplete.js.map +1 -1
- package/dist/components/avatar/avatar.d.ts +17 -1
- package/dist/components/avatar/avatar.d.ts.map +1 -1
- package/dist/components/avatar/avatar.js +2 -1
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts +2 -1
- package/dist/components/background-pattern/background-pattern-interactive.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-interactive.js +4 -2
- package/dist/components/background-pattern/background-pattern-interactive.js.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.d.ts +3 -2
- package/dist/components/background-pattern/background-pattern-shared.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern-shared.js +48 -16
- package/dist/components/background-pattern/background-pattern-shared.js.map +1 -1
- package/dist/components/background-pattern/background-pattern.d.ts +13 -5
- package/dist/components/background-pattern/background-pattern.d.ts.map +1 -1
- package/dist/components/background-pattern/background-pattern.js +13 -4
- package/dist/components/background-pattern/background-pattern.js.map +1 -1
- package/dist/components/background-pattern/index.js +1 -0
- package/dist/components/background-pattern/index.js.map +1 -1
- package/dist/components/badge/badge.d.ts +13 -3
- package/dist/components/badge/badge.d.ts.map +1 -1
- package/dist/components/badge/badge.js +2 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/border-beam/border-beam.d.ts +52 -0
- package/dist/components/border-beam/border-beam.d.ts.map +1 -0
- package/dist/components/border-beam/border-beam.js +68 -0
- package/dist/components/border-beam/border-beam.js.map +1 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts +8 -0
- package/dist/components/breadcrumb/breadcrumb.d.ts.map +1 -1
- package/dist/components/breadcrumb/breadcrumb.js +2 -1
- package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
- package/dist/components/button/button-variants.d.ts +2 -2
- package/dist/components/button/button-variants.js +2 -1
- package/dist/components/button/button-variants.js.map +1 -1
- package/dist/components/button/button.d.ts +11 -1
- package/dist/components/button/button.d.ts.map +1 -1
- package/dist/components/button/button.js +2 -1
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/button/index.js +1 -0
- package/dist/components/button/index.js.map +1 -1
- package/dist/components/button-group/button-group-context.js +1 -0
- package/dist/components/button-group/button-group-context.js.map +1 -1
- package/dist/components/button-group/button-group.d.ts +10 -0
- package/dist/components/button-group/button-group.d.ts.map +1 -1
- package/dist/components/button-group/button-group.js +2 -1
- package/dist/components/button-group/button-group.js.map +1 -1
- package/dist/components/calendar/calendar.d.ts +5 -0
- package/dist/components/calendar/calendar.d.ts.map +1 -1
- package/dist/components/calendar/calendar.js +2 -1
- package/dist/components/calendar/calendar.js.map +1 -1
- package/dist/components/card/card.d.ts +43 -0
- package/dist/components/card/card.d.ts.map +1 -0
- package/dist/components/card/card.js +104 -0
- package/dist/components/card/card.js.map +1 -0
- package/dist/components/carousel/carousel.d.ts +106 -6
- package/dist/components/carousel/carousel.d.ts.map +1 -1
- package/dist/components/carousel/carousel.js +180 -5
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +2 -1
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.d.ts +4 -0
- package/dist/components/checkbox-group/checkbox-group.d.ts.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.js +2 -1
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
- package/dist/components/chip/chip.d.ts +33 -1
- package/dist/components/chip/chip.d.ts.map +1 -1
- package/dist/components/chip/chip.js +2 -1
- package/dist/components/chip/chip.js.map +1 -1
- package/dist/components/collapsible/collapsible.js +2 -1
- package/dist/components/collapsible/collapsible.js.map +1 -1
- package/dist/components/color-area/color-area.d.ts +53 -0
- package/dist/components/color-area/color-area.d.ts.map +1 -0
- package/dist/components/color-area/color-area.js +246 -0
- package/dist/components/color-area/color-area.js.map +1 -0
- package/dist/components/color-picker/color-picker.d.ts +152 -0
- package/dist/components/color-picker/color-picker.d.ts.map +1 -0
- package/dist/components/color-picker/color-picker.js +328 -0
- package/dist/components/color-picker/color-picker.js.map +1 -0
- package/dist/components/color-slider/color-slider.d.ts +48 -0
- package/dist/components/color-slider/color-slider.d.ts.map +1 -0
- package/dist/components/color-slider/color-slider.js +217 -0
- package/dist/components/color-slider/color-slider.js.map +1 -0
- package/dist/components/color-swatch/color-swatch.d.ts +47 -0
- package/dist/components/color-swatch/color-swatch.d.ts.map +1 -0
- package/dist/components/color-swatch/color-swatch.js +67 -0
- package/dist/components/color-swatch/color-swatch.js.map +1 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.d.ts +62 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.d.ts.map +1 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.js +203 -0
- package/dist/components/color-swatch-picker/color-swatch-picker.js.map +1 -0
- package/dist/components/combobox/combobox.d.ts +25 -1
- package/dist/components/combobox/combobox.d.ts.map +1 -1
- package/dist/components/combobox/combobox.js +3 -2
- package/dist/components/combobox/combobox.js.map +1 -1
- package/dist/components/context-menu/context-menu.d.ts +7 -1
- package/dist/components/context-menu/context-menu.d.ts.map +1 -1
- package/dist/components/context-menu/context-menu.js +11 -5
- package/dist/components/context-menu/context-menu.js.map +1 -1
- package/dist/components/copy-button/copy-button.d.ts +18 -1
- package/dist/components/copy-button/copy-button.d.ts.map +1 -1
- package/dist/components/copy-button/copy-button.js +6 -5
- package/dist/components/copy-button/copy-button.js.map +1 -1
- package/dist/components/countdown/countdown.d.ts +14 -0
- package/dist/components/countdown/countdown.d.ts.map +1 -1
- package/dist/components/countdown/countdown.js +2 -1
- package/dist/components/countdown/countdown.js.map +1 -1
- package/dist/components/date-field/date-field.d.ts +35 -0
- package/dist/components/date-field/date-field.d.ts.map +1 -1
- package/dist/components/date-field/date-field.js +2 -1
- package/dist/components/date-field/date-field.js.map +1 -1
- package/dist/components/date-picker/date-picker.d.ts +94 -0
- package/dist/components/date-picker/date-picker.d.ts.map +1 -1
- package/dist/components/date-picker/date-picker.js +2 -1
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/dialog/dialog.d.ts +20 -2
- package/dist/components/dialog/dialog.d.ts.map +1 -1
- package/dist/components/dialog/dialog.js +9 -4
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/drawer/drawer.d.ts +22 -2
- package/dist/components/drawer/drawer.d.ts.map +1 -1
- package/dist/components/drawer/drawer.js +14 -7
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +7 -1
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu/dropdown-menu.js +11 -5
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -1
- package/dist/components/field/field.js +2 -1
- package/dist/components/field/field.js.map +1 -1
- package/dist/components/fieldset/fieldset.js +2 -1
- package/dist/components/fieldset/fieldset.js.map +1 -1
- package/dist/components/form/form.js +1 -0
- package/dist/components/form/form.js.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts +51 -1
- package/dist/components/gradient-glow/gradient-glow.d.ts.map +1 -1
- package/dist/components/gradient-glow/gradient-glow.js +5 -3
- package/dist/components/gradient-glow/gradient-glow.js.map +1 -1
- package/dist/components/input/index.js +1 -0
- package/dist/components/input/index.js.map +1 -1
- package/dist/components/input/input-variants.d.ts +1 -1
- package/dist/components/input/input-variants.js +2 -1
- package/dist/components/input/input-variants.js.map +1 -1
- package/dist/components/input/input.d.ts +21 -1
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/input/input.js +4 -3
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/kbd/kbd.d.ts +8 -0
- package/dist/components/kbd/kbd.d.ts.map +1 -1
- package/dist/components/kbd/kbd.js +2 -1
- package/dist/components/kbd/kbd.js.map +1 -1
- package/dist/components/loader/loader.d.ts +8 -0
- package/dist/components/loader/loader.d.ts.map +1 -1
- package/dist/components/loader/loader.js +2 -1
- package/dist/components/loader/loader.js.map +1 -1
- package/dist/components/menubar/menubar.d.ts +8 -0
- package/dist/components/menubar/menubar.d.ts.map +1 -1
- package/dist/components/menubar/menubar.js +2 -1
- package/dist/components/menubar/menubar.js.map +1 -1
- package/dist/components/meter/meter.d.ts +4 -0
- package/dist/components/meter/meter.d.ts.map +1 -1
- package/dist/components/meter/meter.js +2 -1
- package/dist/components/meter/meter.js.map +1 -1
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/index.js.map +1 -1
- package/dist/components/navigation/navigation-context.js +1 -0
- package/dist/components/navigation/navigation-context.js.map +1 -1
- package/dist/components/navigation/navigation-link-variants.d.ts +2 -2
- package/dist/components/navigation/navigation-link-variants.js +2 -1
- package/dist/components/navigation/navigation-link-variants.js.map +1 -1
- package/dist/components/navigation/navigation-link.d.ts +22 -0
- package/dist/components/navigation/navigation-link.d.ts.map +1 -1
- package/dist/components/navigation/navigation-link.js +2 -1
- package/dist/components/navigation/navigation-link.js.map +1 -1
- package/dist/components/navigation/navigation.d.ts +12 -0
- package/dist/components/navigation/navigation.d.ts.map +1 -1
- package/dist/components/navigation/navigation.js +2 -1
- package/dist/components/navigation/navigation.js.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.d.ts +33 -0
- package/dist/components/navigation-menu/navigation-menu.d.ts.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.js +2 -1
- package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
- package/dist/components/number-field/number-field.d.ts +14 -0
- package/dist/components/number-field/number-field.d.ts.map +1 -1
- package/dist/components/number-field/number-field.js +2 -1
- package/dist/components/number-field/number-field.js.map +1 -1
- package/dist/components/otp-field/otp-field.d.ts +9 -0
- package/dist/components/otp-field/otp-field.d.ts.map +1 -1
- package/dist/components/otp-field/otp-field.js +2 -1
- package/dist/components/otp-field/otp-field.js.map +1 -1
- package/dist/components/pagination/pagination.d.ts +16 -0
- package/dist/components/pagination/pagination.d.ts.map +1 -1
- package/dist/components/pagination/pagination.js +2 -1
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/popover/popover.d.ts +5 -1
- package/dist/components/popover/popover.d.ts.map +1 -1
- package/dist/components/popover/popover.js +3 -2
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/preview-card/preview-card.d.ts +5 -1
- package/dist/components/preview-card/preview-card.d.ts.map +1 -1
- package/dist/components/preview-card/preview-card.js +3 -2
- package/dist/components/preview-card/preview-card.js.map +1 -1
- package/dist/components/progress/progress.d.ts +17 -0
- package/dist/components/progress/progress.d.ts.map +1 -1
- package/dist/components/progress/progress.js +2 -1
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/radio/radio.js +2 -1
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radio-group/radio-group.d.ts +4 -0
- package/dist/components/radio-group/radio-group.d.ts.map +1 -1
- package/dist/components/radio-group/radio-group.js +2 -1
- package/dist/components/radio-group/radio-group.js.map +1 -1
- package/dist/components/rating/rating.d.ts +79 -0
- package/dist/components/rating/rating.d.ts.map +1 -0
- package/dist/components/rating/rating.js +302 -0
- package/dist/components/rating/rating.js.map +1 -0
- package/dist/components/scroll-area/scroll-area.d.ts +13 -0
- package/dist/components/scroll-area/scroll-area.d.ts.map +1 -1
- package/dist/components/scroll-area/scroll-area.js +2 -1
- package/dist/components/scroll-area/scroll-area.js.map +1 -1
- package/dist/components/select/select.d.ts +20 -1
- package/dist/components/select/select.d.ts.map +1 -1
- package/dist/components/select/select.js +3 -2
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/separator/separator.d.ts +4 -0
- package/dist/components/separator/separator.d.ts.map +1 -1
- package/dist/components/separator/separator.js +2 -1
- package/dist/components/separator/separator.js.map +1 -1
- package/dist/components/skeleton/skeleton.d.ts +4 -0
- package/dist/components/skeleton/skeleton.d.ts.map +1 -1
- package/dist/components/skeleton/skeleton.js +2 -1
- package/dist/components/skeleton/skeleton.js.map +1 -1
- package/dist/components/slider/slider.d.ts +5 -0
- package/dist/components/slider/slider.d.ts.map +1 -1
- package/dist/components/slider/slider.js +2 -1
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/sparkline/sparkline.d.ts +44 -0
- package/dist/components/sparkline/sparkline.d.ts.map +1 -1
- package/dist/components/sparkline/sparkline.js +2 -1
- package/dist/components/sparkline/sparkline.js.map +1 -1
- package/dist/components/spinner/spinner.d.ts +8 -0
- package/dist/components/spinner/spinner.d.ts.map +1 -1
- package/dist/components/spinner/spinner.js +2 -1
- package/dist/components/spinner/spinner.js.map +1 -1
- package/dist/components/switch/switch.d.ts +19 -15
- package/dist/components/switch/switch.d.ts.map +1 -1
- package/dist/components/switch/switch.js +2 -1
- package/dist/components/switch/switch.js.map +1 -1
- package/dist/components/table/table.d.ts +28 -0
- package/dist/components/table/table.d.ts.map +1 -1
- package/dist/components/table/table.js +2 -1
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.d.ts +32 -2
- package/dist/components/tabs/tabs.d.ts.map +1 -1
- package/dist/components/tabs/tabs.js +2 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/text-animate/text-animate.d.ts +31 -0
- package/dist/components/text-animate/text-animate.d.ts.map +1 -1
- package/dist/components/text-animate/text-animate.js +27 -9
- package/dist/components/text-animate/text-animate.js.map +1 -1
- package/dist/components/textarea/textarea.d.ts +15 -0
- package/dist/components/textarea/textarea.d.ts.map +1 -1
- package/dist/components/textarea/textarea.js +2 -1
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/thumbnail/thumbnail.d.ts +22 -2
- package/dist/components/thumbnail/thumbnail.d.ts.map +1 -1
- package/dist/components/thumbnail/thumbnail.js +2 -1
- package/dist/components/thumbnail/thumbnail.js.map +1 -1
- package/dist/components/time-field/time-field.d.ts +35 -0
- package/dist/components/time-field/time-field.d.ts.map +1 -1
- package/dist/components/time-field/time-field.js +2 -1
- package/dist/components/time-field/time-field.js.map +1 -1
- package/dist/components/toast/toast.d.ts +18 -0
- package/dist/components/toast/toast.d.ts.map +1 -1
- package/dist/components/toast/toast.js +2 -1
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toc/toc.d.ts +10 -0
- package/dist/components/toc/toc.d.ts.map +1 -1
- package/dist/components/toc/toc.js +2 -1
- package/dist/components/toc/toc.js.map +1 -1
- package/dist/components/toggle/toggle.js +1 -0
- package/dist/components/toggle/toggle.js.map +1 -1
- package/dist/components/toggle-group/toggle-group.js +2 -1
- package/dist/components/toggle-group/toggle-group.js.map +1 -1
- package/dist/components/toolbar/toolbar.js +2 -1
- package/dist/components/toolbar/toolbar.js.map +1 -1
- package/dist/components/tooltip/tooltip.d.ts +5 -1
- package/dist/components/tooltip/tooltip.d.ts.map +1 -1
- package/dist/components/tooltip/tooltip.js +3 -2
- package/dist/components/tooltip/tooltip.js.map +1 -1
- package/dist/hooks/use-direction.js +1 -0
- package/dist/hooks/use-direction.js.map +1 -1
- package/dist/hooks/use-dismissible.d.ts +4 -0
- package/dist/hooks/use-dismissible.d.ts.map +1 -1
- package/dist/hooks/use-dismissible.js +1 -0
- package/dist/hooks/use-dismissible.js.map +1 -1
- package/dist/hooks/use-local-storage.js +1 -0
- package/dist/hooks/use-local-storage.js.map +1 -1
- package/dist/hooks/use-media-query.js +1 -0
- package/dist/hooks/use-media-query.js.map +1 -1
- package/dist/hooks/use-reduced-motion.d.ts +1 -1
- package/dist/hooks/use-reduced-motion.js +1 -0
- package/dist/hooks/use-reduced-motion.js.map +1 -1
- package/dist/hooks/use-theme.d.ts +1 -1
- package/dist/hooks/use-theme.js +1 -0
- package/dist/hooks/use-theme.js.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/color-control.d.ts +75 -0
- package/dist/internal/color-control.d.ts.map +1 -0
- package/dist/internal/color-control.js +79 -0
- package/dist/internal/color-control.js.map +1 -0
- package/dist/internal/color-math.d.ts +9 -0
- package/dist/internal/color-math.d.ts.map +1 -0
- package/dist/internal/color-math.js +35 -0
- package/dist/internal/color-math.js.map +1 -0
- package/dist/internal/color-picker-context.d.ts +34 -0
- package/dist/internal/color-picker-context.d.ts.map +1 -0
- package/dist/internal/color-picker-context.js +42 -0
- package/dist/internal/color-picker-context.js.map +1 -0
- package/dist/{floating.d.ts → internal/floating.d.ts} +3 -3
- package/dist/internal/floating.d.ts.map +1 -0
- package/dist/{floating.js → internal/floating.js} +1 -0
- package/dist/internal/floating.js.map +1 -0
- package/dist/{modal.d.ts → internal/modal.d.ts} +2 -2
- package/dist/internal/modal.d.ts.map +1 -0
- package/dist/{modal.js → internal/modal.js} +1 -0
- package/dist/internal/modal.js.map +1 -0
- package/dist/{utils.d.ts → internal/utils.d.ts} +2 -2
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/{utils.js → internal/utils.js} +1 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/lib/color.d.ts +95 -0
- package/dist/lib/color.d.ts.map +1 -0
- package/dist/lib/color.js +329 -0
- package/dist/lib/color.js.map +1 -0
- package/dist/providers/direction-provider.d.ts +4 -4
- package/dist/providers/direction-provider.d.ts.map +1 -1
- package/dist/providers/direction-provider.js +1 -0
- package/dist/providers/direction-provider.js.map +1 -1
- package/dist/providers/reduced-motion-provider.d.ts +4 -8
- package/dist/providers/reduced-motion-provider.d.ts.map +1 -1
- package/dist/providers/reduced-motion-provider.js +1 -0
- package/dist/providers/reduced-motion-provider.js.map +1 -1
- package/dist/providers/theme-provider/index.js +1 -0
- package/dist/providers/theme-provider/index.js.map +1 -1
- package/dist/providers/theme-provider/theme-provider.d.ts +28 -12
- package/dist/providers/theme-provider/theme-provider.d.ts.map +1 -1
- package/dist/providers/theme-provider/theme-provider.js +1 -0
- package/dist/providers/theme-provider/theme-provider.js.map +1 -1
- package/dist/providers/theme-provider/theme-script.js +1 -0
- package/dist/providers/theme-provider/theme-script.js.map +1 -1
- package/package.json +91 -31
- package/src/components/accordion/accordion.tsx +25 -1
- package/src/components/alert/alert.tsx +30 -2
- package/src/components/alert-dialog/alert-dialog.test.tsx +34 -2
- package/src/components/alert-dialog/alert-dialog.tsx +21 -5
- package/src/components/autocomplete/autocomplete.test.tsx +1 -1
- package/src/components/autocomplete/autocomplete.tsx +22 -2
- package/src/components/avatar/avatar.test.tsx +2 -2
- package/src/components/avatar/avatar.tsx +17 -1
- package/src/components/background-pattern/background-pattern-interactive.tsx +4 -2
- package/src/components/background-pattern/background-pattern-shared.tsx +56 -19
- package/src/components/background-pattern/background-pattern.test.tsx +36 -1
- package/src/components/background-pattern/background-pattern.tsx +24 -9
- package/src/components/badge/badge.tsx +14 -2
- package/src/components/border-beam/border-beam.test.tsx +91 -0
- package/src/components/border-beam/border-beam.tsx +131 -0
- package/src/components/breadcrumb/breadcrumb.tsx +9 -1
- package/src/components/button/button-variants.ts +1 -1
- package/src/components/button/button.tsx +13 -2
- package/src/components/button-group/button-group.tsx +11 -1
- package/src/components/calendar/calendar.tsx +6 -1
- package/src/components/card/card.test.tsx +98 -0
- package/src/components/card/card.tsx +154 -0
- package/src/components/carousel/carousel.test.tsx +179 -0
- package/src/components/carousel/carousel.tsx +329 -6
- package/src/components/checkbox/checkbox.test.tsx +2 -2
- package/src/components/checkbox/checkbox.tsx +1 -1
- package/src/components/checkbox-group/checkbox-group.tsx +5 -1
- package/src/components/chip/chip.tsx +33 -1
- package/src/components/collapsible/collapsible.tsx +1 -1
- package/src/components/color-area/color-area.test.tsx +242 -0
- package/src/components/color-area/color-area.tsx +356 -0
- package/src/components/color-picker/color-picker.test.tsx +286 -0
- package/src/components/color-picker/color-picker.tsx +546 -0
- package/src/components/color-slider/color-slider.test.tsx +222 -0
- package/src/components/color-slider/color-slider.tsx +330 -0
- package/src/components/color-swatch/color-swatch.test.tsx +117 -0
- package/src/components/color-swatch/color-swatch.tsx +119 -0
- package/src/components/color-swatch-picker/color-swatch-picker.test.tsx +287 -0
- package/src/components/color-swatch-picker/color-swatch-picker.tsx +327 -0
- package/src/components/combobox/combobox.test.tsx +1 -1
- package/src/components/combobox/combobox.tsx +26 -2
- package/src/components/context-menu/context-menu.test.tsx +28 -0
- package/src/components/context-menu/context-menu.tsx +16 -5
- package/src/components/copy-button/copy-button.test.tsx +14 -1
- package/src/components/copy-button/copy-button.tsx +27 -6
- package/src/components/countdown/countdown.tsx +15 -1
- package/src/components/date-field/date-field.tsx +36 -1
- package/src/components/date-picker/date-picker.test.tsx +1 -1
- package/src/components/date-picker/date-picker.tsx +95 -1
- package/src/components/dialog/dialog.test.tsx +30 -1
- package/src/components/dialog/dialog.tsx +28 -6
- package/src/components/drawer/drawer.test.tsx +32 -1
- package/src/components/drawer/drawer.tsx +37 -7
- package/src/components/dropdown-menu/dropdown-menu.test.tsx +28 -0
- package/src/components/dropdown-menu/dropdown-menu.tsx +16 -5
- package/src/components/field/field.tsx +1 -1
- package/src/components/fieldset/fieldset.tsx +1 -1
- package/src/components/gradient-glow/gradient-glow.test.tsx +7 -1
- package/src/components/gradient-glow/gradient-glow.tsx +64 -11
- package/src/components/input/input-variants.ts +1 -1
- package/src/components/input/input.tsx +24 -4
- package/src/components/kbd/kbd.tsx +9 -1
- package/src/components/loader/loader.tsx +9 -1
- package/src/components/menubar/menubar.tsx +9 -1
- package/src/components/meter/meter.tsx +5 -1
- package/src/components/navigation/navigation-link-variants.ts +1 -1
- package/src/components/navigation/navigation-link.tsx +23 -1
- package/src/components/navigation/navigation.tsx +23 -3
- package/src/components/navigation-menu/navigation-menu.tsx +34 -1
- package/src/components/number-field/number-field.tsx +15 -1
- package/src/components/otp-field/otp-field.tsx +10 -1
- package/src/components/pagination/pagination.tsx +17 -1
- package/src/components/popover/popover.test.tsx +1 -1
- package/src/components/popover/popover.tsx +6 -2
- package/src/components/preview-card/preview-card.tsx +6 -2
- package/src/components/progress/progress.tsx +18 -1
- package/src/components/radio/radio.test.tsx +1 -1
- package/src/components/radio/radio.tsx +1 -1
- package/src/components/radio-group/radio-group.test.tsx +1 -1
- package/src/components/radio-group/radio-group.tsx +5 -1
- package/src/components/rating/rating.test.tsx +246 -0
- package/src/components/rating/rating.tsx +457 -0
- package/src/components/scroll-area/scroll-area.test.tsx +1 -1
- package/src/components/scroll-area/scroll-area.tsx +14 -1
- package/src/components/select/select.tsx +21 -2
- package/src/components/separator/separator.tsx +5 -1
- package/src/components/skeleton/skeleton.tsx +5 -1
- package/src/components/slider/slider.test.tsx +1 -1
- package/src/components/slider/slider.tsx +6 -1
- package/src/components/sparkline/sparkline.test.tsx +1 -1
- package/src/components/sparkline/sparkline.tsx +45 -1
- package/src/components/spinner/spinner.tsx +9 -1
- package/src/components/switch/switch.test.tsx +1 -1
- package/src/components/switch/switch.tsx +5 -1
- package/src/components/table/table.tsx +29 -1
- package/src/components/tabs/tabs.test.tsx +1 -1
- package/src/components/tabs/tabs.tsx +33 -2
- package/src/components/text-animate/text-animate.test.tsx +62 -0
- package/src/components/text-animate/text-animate.tsx +77 -9
- package/src/components/textarea/textarea.tsx +16 -1
- package/src/components/thumbnail/thumbnail.test.tsx +1 -1
- package/src/components/thumbnail/thumbnail.tsx +21 -1
- package/src/components/time-field/time-field.tsx +36 -1
- package/src/components/toast/toast.test.tsx +1 -1
- package/src/components/toast/toast.tsx +19 -1
- package/src/components/toc/toc.tsx +11 -1
- package/src/components/toggle/toggle.test.tsx +1 -1
- package/src/components/toggle-group/toggle-group.tsx +1 -1
- package/src/components/toolbar/toolbar.tsx +1 -1
- package/src/components/tooltip/tooltip.test.tsx +1 -1
- package/src/components/tooltip/tooltip.tsx +6 -2
- package/src/hooks/use-dismissible.ts +4 -0
- package/src/hooks/use-local-storage.ts +3 -3
- package/src/hooks/use-reduced-motion.ts +1 -1
- package/src/hooks/use-theme.ts +1 -1
- package/src/index.ts +11 -2
- package/src/internal/color-control.ts +178 -0
- package/src/internal/color-math.ts +44 -0
- package/src/internal/color-picker-context.ts +80 -0
- package/src/{floating.ts → internal/floating.ts} +3 -3
- package/src/{modal.ts → internal/modal.ts} +3 -3
- package/src/lib/color.test.ts +178 -0
- package/src/lib/color.ts +471 -0
- package/src/providers/direction-provider.tsx +4 -4
- package/src/providers/reduced-motion-provider.tsx +4 -8
- package/src/providers/theme-provider/theme-provider.tsx +28 -12
- package/src/providers/theme-provider/theme-script.tsx +2 -2
- package/src/test/setup.ts +1 -1
- package/styles.css +28 -4
- package/dist/floating.d.ts.map +0 -1
- package/dist/floating.js.map +0 -1
- package/dist/modal.d.ts.map +0 -1
- package/dist/modal.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
- /package/src/{floating.test.ts → internal/floating.test.ts} +0 -0
- /package/src/{modal.test.ts → internal/modal.test.ts} +0 -0
- /package/src/{utils.test.tsx → internal/utils.test.tsx} +0 -0
- /package/src/{utils.ts → internal/utils.ts} +0 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
type Color,
|
|
4
|
+
convertColor,
|
|
5
|
+
formatChannelValue,
|
|
6
|
+
formatColor,
|
|
7
|
+
getChannelRange,
|
|
8
|
+
getChannelValue,
|
|
9
|
+
getColorSpaceAxes,
|
|
10
|
+
parseColor,
|
|
11
|
+
safeParseColor,
|
|
12
|
+
withChannelValue,
|
|
13
|
+
} from './color'
|
|
14
|
+
|
|
15
|
+
const round = (color: Color, precision = 2) =>
|
|
16
|
+
Object.fromEntries(
|
|
17
|
+
Object.entries(color).map(([key, value]) => [
|
|
18
|
+
key,
|
|
19
|
+
typeof value === 'number' ? Number(value.toFixed(precision)) : value,
|
|
20
|
+
]),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
describe('parseColor', () => {
|
|
24
|
+
it('parses hex in every length', () => {
|
|
25
|
+
expect(parseColor('#f00')).toEqual({ space: 'rgb', red: 255, green: 0, blue: 0, alpha: 1 })
|
|
26
|
+
expect(parseColor('#ff0000')).toEqual({ space: 'rgb', red: 255, green: 0, blue: 0, alpha: 1 })
|
|
27
|
+
expect(parseColor('#ff000080').alpha).toBeCloseTo(0.502, 3)
|
|
28
|
+
expect(parseColor('#f008').alpha).toBeCloseTo(0.533, 3)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('parses comma and space separated function syntax alike', () => {
|
|
32
|
+
expect(parseColor('rgb(10, 20, 30)')).toEqual(parseColor('rgb(10 20 30)'))
|
|
33
|
+
expect(parseColor('rgba(10, 20, 30, 0.5)')).toEqual(parseColor('rgb(10 20 30 / 50%)'))
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('parses hsl, hsb and oklch', () => {
|
|
37
|
+
expect(parseColor('hsl(120, 50%, 40%)')).toEqual({
|
|
38
|
+
space: 'hsl',
|
|
39
|
+
hue: 120,
|
|
40
|
+
saturation: 50,
|
|
41
|
+
lightness: 40,
|
|
42
|
+
alpha: 1,
|
|
43
|
+
})
|
|
44
|
+
expect(parseColor('hsb(120, 50%, 40%)').space).toBe('hsb')
|
|
45
|
+
expect(parseColor('oklch(62.8% 0.26 29.2)')).toEqual({
|
|
46
|
+
space: 'oklch',
|
|
47
|
+
lightness: 62.8,
|
|
48
|
+
chroma: 0.26,
|
|
49
|
+
hue: 29.2,
|
|
50
|
+
alpha: 1,
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('normalizes hue outside 0-360', () => {
|
|
55
|
+
expect(getChannelValue(parseColor('hsl(-30, 50%, 40%)'), 'hue')).toBe(330)
|
|
56
|
+
expect(getChannelValue(parseColor('hsl(390, 50%, 40%)'), 'hue')).toBe(30)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('keeps a hue of exactly 360, which is in range rather than past it', () => {
|
|
60
|
+
// The channel's maximum has to survive a round trip, or a slider that reaches it
|
|
61
|
+
// snaps back to the opposite end the moment the value is written out and reread.
|
|
62
|
+
const wheel = parseColor('hsb(360, 100%, 100%)')
|
|
63
|
+
expect(getChannelValue(wheel, 'hue')).toBe(360)
|
|
64
|
+
expect(getChannelValue(parseColor(formatColor(wheel, 'hsba')), 'hue')).toBe(360)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('throws on nonsense, and safeParseColor returns undefined instead', () => {
|
|
68
|
+
expect(() => parseColor('not a color')).toThrow()
|
|
69
|
+
expect(() => parseColor('#fffff')).toThrow()
|
|
70
|
+
expect(safeParseColor('not a color')).toBeUndefined()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('convertColor', () => {
|
|
75
|
+
it('round-trips primaries through every space', () => {
|
|
76
|
+
for (const hex of ['#ff0000', '#00ff00', '#0000ff', '#123456', '#ffffff', '#000000']) {
|
|
77
|
+
const rgb = parseColor(hex)
|
|
78
|
+
for (const space of ['hsl', 'hsb', 'oklch'] as const) {
|
|
79
|
+
const back = convertColor(convertColor(rgb, space), 'rgb')
|
|
80
|
+
expect(formatColor(back, 'hex')).toBe(hex)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('matches known hsl and hsb values', () => {
|
|
86
|
+
expect(round(convertColor(parseColor('#ff0000'), 'hsl'))).toEqual({
|
|
87
|
+
space: 'hsl',
|
|
88
|
+
hue: 0,
|
|
89
|
+
saturation: 100,
|
|
90
|
+
lightness: 50,
|
|
91
|
+
alpha: 1,
|
|
92
|
+
})
|
|
93
|
+
expect(round(convertColor(parseColor('#808080'), 'hsb'))).toEqual({
|
|
94
|
+
space: 'hsb',
|
|
95
|
+
hue: 0,
|
|
96
|
+
saturation: 0,
|
|
97
|
+
brightness: 50.2,
|
|
98
|
+
alpha: 1,
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('places white and black at the ends of the oklch lightness axis', () => {
|
|
103
|
+
expect(getChannelValue(convertColor(parseColor('#ffffff'), 'oklch'), 'lightness')).toBeCloseTo(100, 1)
|
|
104
|
+
expect(getChannelValue(convertColor(parseColor('#000000'), 'oklch'), 'lightness')).toBeCloseTo(0, 1)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('pins hue to zero for grays, so round-trips stay stable', () => {
|
|
108
|
+
expect(getChannelValue(convertColor(parseColor('#808080'), 'oklch'), 'hue')).toBe(0)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('preserves alpha across spaces', () => {
|
|
112
|
+
expect(convertColor(parseColor('rgba(255, 0, 0, 0.4)'), 'oklch').alpha).toBe(0.4)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('formatColor', () => {
|
|
117
|
+
it('picks the shortest css form for the color own space', () => {
|
|
118
|
+
expect(formatColor(parseColor('rgb(1, 2, 3)'))).toBe('rgb(1, 2, 3)')
|
|
119
|
+
expect(formatColor(parseColor('rgba(1, 2, 3, 0.5)'))).toBe('rgba(1, 2, 3, 0.5)')
|
|
120
|
+
expect(formatColor(parseColor('hsl(120, 50%, 40%)'))).toBe('hsl(120, 50%, 40%)')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('borrows hsl syntax for hsb, which has no css form', () => {
|
|
124
|
+
expect(formatColor(parseColor('hsb(120, 100%, 100%)'))).toBe('hsl(120, 100%, 50%)')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('writes oklch with slash alpha', () => {
|
|
128
|
+
expect(formatColor(parseColor('oklch(62.8% 0.26 29.2 / 0.5)'))).toBe('oklch(62.8% 0.26 29.2 / 0.5)')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('converts into the requested format', () => {
|
|
132
|
+
expect(formatColor(parseColor('hsl(0, 100%, 50%)'), 'hex')).toBe('#ff0000')
|
|
133
|
+
expect(formatColor(parseColor('#ff000080'), 'hexa')).toBe('#ff000080')
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
describe('channels', () => {
|
|
138
|
+
it('clamps to the channel range on write', () => {
|
|
139
|
+
expect(getChannelValue(withChannelValue(parseColor('#000'), 'red', 999), 'red')).toBe(255)
|
|
140
|
+
expect(getChannelValue(withChannelValue(parseColor('hsl(0, 0%, 0%)'), 'saturation', -5), 'saturation')).toBe(0)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('rejects channels outside the color space', () => {
|
|
144
|
+
expect(() => getChannelValue(parseColor('#000'), 'hue')).toThrow()
|
|
145
|
+
expect(() => getChannelRange('rgb', 'chroma')).toThrow()
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('formats values with the unit of the channel', () => {
|
|
149
|
+
const color = parseColor('hsl(210, 40%, 60%)')
|
|
150
|
+
expect(formatChannelValue(color, 'hue')).toBe('210°')
|
|
151
|
+
expect(formatChannelValue(color, 'saturation')).toBe('40%')
|
|
152
|
+
expect(formatChannelValue(parseColor('rgb(10, 20, 30)'), 'red')).toBe('10')
|
|
153
|
+
expect(formatChannelValue(parseColor('oklch(50% 0.1 30)'), 'chroma')).toBe('0.100')
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('fills unspecified axes with the channels left free', () => {
|
|
157
|
+
expect(getColorSpaceAxes('hsb', { xChannel: 'saturation', yChannel: 'brightness' })).toEqual({
|
|
158
|
+
xChannel: 'saturation',
|
|
159
|
+
yChannel: 'brightness',
|
|
160
|
+
zChannel: 'hue',
|
|
161
|
+
})
|
|
162
|
+
expect(getColorSpaceAxes('hsb', { yChannel: 'brightness' })).toEqual({
|
|
163
|
+
xChannel: 'hue',
|
|
164
|
+
yChannel: 'brightness',
|
|
165
|
+
zChannel: 'saturation',
|
|
166
|
+
})
|
|
167
|
+
expect(getColorSpaceAxes('rgb')).toEqual({ xChannel: 'red', yChannel: 'green', zChannel: 'blue' })
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
describe('out-of-gamut oklch', () => {
|
|
172
|
+
it('converts the way a browser paints it, by clipping', () => {
|
|
173
|
+
// Chrome clips oklch() per channel rather than reducing chroma, so matching it
|
|
174
|
+
// keeps a picked color identical to the one the emitted string renders as.
|
|
175
|
+
const clipped = convertColor(parseColor('oklch(85% 0.25 30)'), 'rgb')
|
|
176
|
+
expect(formatColor(clipped, 'rgb')).toBe('rgb(255, 124, 98)')
|
|
177
|
+
})
|
|
178
|
+
})
|
package/src/lib/color.ts
ADDED
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
// Color model shared by the color components (ColorArea, ColorSlider, ColorSwatch,
|
|
2
|
+
// ColorSwatchPicker, ColorPicker). A Color is a plain, serializable object
|
|
3
|
+
// rather than a class instance, so it can cross the RSC boundary and survive
|
|
4
|
+
// `structuredClone` - a class would not.
|
|
5
|
+
//
|
|
6
|
+
// The matrix conversions live in ../color-math, which stays free of objects and of
|
|
7
|
+
// this module's clamping rules.
|
|
8
|
+
|
|
9
|
+
import { linearRgbToOklab, oklchToSrgb, srgbToLinear } from '../internal/color-math'
|
|
10
|
+
|
|
11
|
+
/** A color space a `Color` can be expressed in. */
|
|
12
|
+
export type ColorSpace = 'rgb' | 'hsl' | 'hsb' | 'oklch'
|
|
13
|
+
|
|
14
|
+
/** A single adjustable component of a color. */
|
|
15
|
+
export type ColorChannel =
|
|
16
|
+
'red' | 'green' | 'blue' | 'hue' | 'saturation' | 'lightness' | 'brightness' | 'chroma' | 'alpha'
|
|
17
|
+
|
|
18
|
+
/** A string form `formatColor` can produce and `parseColor` can read back. */
|
|
19
|
+
export type ColorFormat = 'hex' | 'hexa' | 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hsb' | 'hsba' | 'oklch' | 'oklcha'
|
|
20
|
+
|
|
21
|
+
/** sRGB color. Channels are 0-255, alpha is 0-1. */
|
|
22
|
+
export interface RgbColor {
|
|
23
|
+
space: 'rgb'
|
|
24
|
+
red: number
|
|
25
|
+
green: number
|
|
26
|
+
blue: number
|
|
27
|
+
alpha: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** HSL color. Hue is 0-360, saturation and lightness are 0-100, alpha is 0-1. */
|
|
31
|
+
export interface HslColor {
|
|
32
|
+
space: 'hsl'
|
|
33
|
+
hue: number
|
|
34
|
+
saturation: number
|
|
35
|
+
lightness: number
|
|
36
|
+
alpha: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** HSB (a.k.a. HSV) color. Hue is 0-360, saturation and brightness are 0-100, alpha is 0-1. */
|
|
40
|
+
export interface HsbColor {
|
|
41
|
+
space: 'hsb'
|
|
42
|
+
hue: number
|
|
43
|
+
saturation: number
|
|
44
|
+
brightness: number
|
|
45
|
+
alpha: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** OKLCh color. Lightness is 0-100, chroma is 0-0.4, hue is 0-360, alpha is 0-1. */
|
|
49
|
+
export interface OklchColor {
|
|
50
|
+
space: 'oklch'
|
|
51
|
+
lightness: number
|
|
52
|
+
chroma: number
|
|
53
|
+
hue: number
|
|
54
|
+
alpha: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A color value in one of the supported color spaces. */
|
|
58
|
+
export type Color = RgbColor | HslColor | HsbColor | OklchColor
|
|
59
|
+
|
|
60
|
+
/** The bounds and increments of a channel within a given color space. */
|
|
61
|
+
export interface ColorChannelRange {
|
|
62
|
+
/** Lowest value the channel accepts. */
|
|
63
|
+
minValue: number
|
|
64
|
+
/** Highest value the channel accepts. */
|
|
65
|
+
maxValue: number
|
|
66
|
+
/** Increment applied by an arrow key. */
|
|
67
|
+
step: number
|
|
68
|
+
/** Increment applied by Page Up, Page Down, or a shifted arrow key. */
|
|
69
|
+
pageSize: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The three channels of a color space, mapped onto the axes of a color area. */
|
|
73
|
+
export interface ColorAxes {
|
|
74
|
+
/** Channel driven by the horizontal axis. */
|
|
75
|
+
xChannel: ColorChannel
|
|
76
|
+
/** Channel driven by the vertical axis. */
|
|
77
|
+
yChannel: ColorChannel
|
|
78
|
+
/** Channel held constant, and so not represented by either axis. */
|
|
79
|
+
zChannel: ColorChannel
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const CHANNELS: Record<ColorSpace, [ColorChannel, ColorChannel, ColorChannel]> = {
|
|
83
|
+
rgb: ['red', 'green', 'blue'],
|
|
84
|
+
hsl: ['hue', 'saturation', 'lightness'],
|
|
85
|
+
hsb: ['hue', 'saturation', 'brightness'],
|
|
86
|
+
oklch: ['lightness', 'chroma', 'hue'],
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const RANGES: Record<ColorSpace, Partial<Record<ColorChannel, ColorChannelRange>>> = {
|
|
90
|
+
rgb: {
|
|
91
|
+
red: { minValue: 0, maxValue: 255, step: 1, pageSize: 17 },
|
|
92
|
+
green: { minValue: 0, maxValue: 255, step: 1, pageSize: 17 },
|
|
93
|
+
blue: { minValue: 0, maxValue: 255, step: 1, pageSize: 17 },
|
|
94
|
+
},
|
|
95
|
+
hsl: {
|
|
96
|
+
hue: { minValue: 0, maxValue: 360, step: 1, pageSize: 15 },
|
|
97
|
+
saturation: { minValue: 0, maxValue: 100, step: 1, pageSize: 10 },
|
|
98
|
+
lightness: { minValue: 0, maxValue: 100, step: 1, pageSize: 10 },
|
|
99
|
+
},
|
|
100
|
+
hsb: {
|
|
101
|
+
hue: { minValue: 0, maxValue: 360, step: 1, pageSize: 15 },
|
|
102
|
+
saturation: { minValue: 0, maxValue: 100, step: 1, pageSize: 10 },
|
|
103
|
+
brightness: { minValue: 0, maxValue: 100, step: 1, pageSize: 10 },
|
|
104
|
+
},
|
|
105
|
+
oklch: {
|
|
106
|
+
lightness: { minValue: 0, maxValue: 100, step: 1, pageSize: 10 },
|
|
107
|
+
chroma: { minValue: 0, maxValue: 0.4, step: 0.005, pageSize: 0.05 },
|
|
108
|
+
hue: { minValue: 0, maxValue: 360, step: 1, pageSize: 15 },
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const ALPHA_RANGE: ColorChannelRange = { minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1 }
|
|
113
|
+
|
|
114
|
+
/** Returns the three channels that define `space`, in canonical order. */
|
|
115
|
+
export function getColorChannels(space: ColorSpace): [ColorChannel, ColorChannel, ColorChannel] {
|
|
116
|
+
return CHANNELS[space]
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Returns the bounds and increments of `channel` within `space`. */
|
|
120
|
+
export function getChannelRange(space: ColorSpace, channel: ColorChannel): ColorChannelRange {
|
|
121
|
+
if (channel === 'alpha') return ALPHA_RANGE
|
|
122
|
+
const range = RANGES[space][channel]
|
|
123
|
+
if (!range) throw new Error(`Channel "${channel}" is not part of the ${space} color space`)
|
|
124
|
+
return range
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Reads a single channel off a color. Throws if the channel is not in the color's space. */
|
|
128
|
+
export function getChannelValue(color: Color, channel: ColorChannel): number {
|
|
129
|
+
const value = (color as unknown as Record<string, number>)[channel]
|
|
130
|
+
if (typeof value !== 'number') {
|
|
131
|
+
throw new Error(`Channel "${channel}" is not part of the ${color.space} color space`)
|
|
132
|
+
}
|
|
133
|
+
return value
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Returns a copy of `color` with `channel` clamped into range and set to `value`. */
|
|
137
|
+
export function withChannelValue(color: Color, channel: ColorChannel, value: number): Color {
|
|
138
|
+
const { minValue, maxValue } = getChannelRange(color.space, channel)
|
|
139
|
+
return { ...color, [channel]: clamp(value, minValue, maxValue) } as Color
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Resolves the x, y and z channels of a color area. Unspecified axes fall back to
|
|
144
|
+
* the first channels of `space` that are still free.
|
|
145
|
+
*/
|
|
146
|
+
export function getColorSpaceAxes(space: ColorSpace, axes: Partial<Omit<ColorAxes, 'zChannel'>> = {}): ColorAxes {
|
|
147
|
+
const channels = CHANNELS[space]
|
|
148
|
+
const xChannel = axes.xChannel ?? channels.find((c) => c !== axes.yChannel)!
|
|
149
|
+
const yChannel = axes.yChannel ?? channels.find((c) => c !== xChannel)!
|
|
150
|
+
const zChannel = channels.find((c) => c !== xChannel && c !== yChannel)!
|
|
151
|
+
return { xChannel, yChannel, zChannel }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function clamp(value: number, min: number, max: number) {
|
|
155
|
+
return Math.min(Math.max(value, min), max)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Guarded so an in-range hue comes back bit for bit - the modulo round trip adds
|
|
159
|
+
// float error that would surface in parsed values. 360 is inside the range too: it is
|
|
160
|
+
// the hue channel's documented maximum, so a slider that reaches it has to be able to
|
|
161
|
+
// write it out and read it back, even though it paints the same color as 0.
|
|
162
|
+
function mod360(hue: number) {
|
|
163
|
+
if (hue >= 0 && hue <= 360) return hue
|
|
164
|
+
return ((hue % 360) + 360) % 360
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function rgbToHsb(color: RgbColor): HsbColor {
|
|
168
|
+
const r = color.red / 255
|
|
169
|
+
const g = color.green / 255
|
|
170
|
+
const b = color.blue / 255
|
|
171
|
+
const max = Math.max(r, g, b)
|
|
172
|
+
const min = Math.min(r, g, b)
|
|
173
|
+
const delta = max - min
|
|
174
|
+
|
|
175
|
+
let hue = 0
|
|
176
|
+
if (delta !== 0) {
|
|
177
|
+
if (max === r) hue = ((g - b) / delta) % 6
|
|
178
|
+
else if (max === g) hue = (b - r) / delta + 2
|
|
179
|
+
else hue = (r - g) / delta + 4
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
space: 'hsb',
|
|
184
|
+
hue: mod360(hue * 60),
|
|
185
|
+
saturation: max === 0 ? 0 : (delta / max) * 100,
|
|
186
|
+
brightness: max * 100,
|
|
187
|
+
alpha: color.alpha,
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function hsbToRgb(color: HsbColor): RgbColor {
|
|
192
|
+
const s = color.saturation / 100
|
|
193
|
+
const v = color.brightness / 100
|
|
194
|
+
const c = v * s
|
|
195
|
+
const h = color.hue / 60
|
|
196
|
+
const x = c * (1 - Math.abs((h % 2) - 1))
|
|
197
|
+
const m = v - c
|
|
198
|
+
const [r, g, b] = sector(h, c, x)
|
|
199
|
+
return { space: 'rgb', red: (r + m) * 255, green: (g + m) * 255, blue: (b + m) * 255, alpha: color.alpha }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function rgbToHsl(color: RgbColor): HslColor {
|
|
203
|
+
const hsb = rgbToHsb(color)
|
|
204
|
+
const v = hsb.brightness / 100
|
|
205
|
+
const s = hsb.saturation / 100
|
|
206
|
+
const l = v * (1 - s / 2)
|
|
207
|
+
return {
|
|
208
|
+
space: 'hsl',
|
|
209
|
+
hue: hsb.hue,
|
|
210
|
+
saturation: l === 0 || l === 1 ? 0 : ((v - l) / Math.min(l, 1 - l)) * 100,
|
|
211
|
+
lightness: l * 100,
|
|
212
|
+
alpha: color.alpha,
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function hslToRgb(color: HslColor): RgbColor {
|
|
217
|
+
const s = color.saturation / 100
|
|
218
|
+
const l = color.lightness / 100
|
|
219
|
+
const c = (1 - Math.abs(2 * l - 1)) * s
|
|
220
|
+
const h = color.hue / 60
|
|
221
|
+
const x = c * (1 - Math.abs((h % 2) - 1))
|
|
222
|
+
const m = l - c / 2
|
|
223
|
+
const [r, g, b] = sector(h, c, x)
|
|
224
|
+
return { space: 'rgb', red: (r + m) * 255, green: (g + m) * 255, blue: (b + m) * 255, alpha: color.alpha }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function sector(h: number, c: number, x: number): [number, number, number] {
|
|
228
|
+
if (h < 1) return [c, x, 0]
|
|
229
|
+
if (h < 2) return [x, c, 0]
|
|
230
|
+
if (h < 3) return [0, c, x]
|
|
231
|
+
if (h < 4) return [0, x, c]
|
|
232
|
+
if (h < 5) return [x, 0, c]
|
|
233
|
+
return [c, 0, x]
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function rgbToOklch(color: RgbColor): OklchColor {
|
|
237
|
+
const [L, a, b] = linearRgbToOklab(
|
|
238
|
+
srgbToLinear(color.red / 255),
|
|
239
|
+
srgbToLinear(color.green / 255),
|
|
240
|
+
srgbToLinear(color.blue / 255),
|
|
241
|
+
)
|
|
242
|
+
const chroma = Math.sqrt(a * a + b * b)
|
|
243
|
+
return {
|
|
244
|
+
space: 'oklch',
|
|
245
|
+
lightness: L * 100,
|
|
246
|
+
chroma,
|
|
247
|
+
// Hue is meaningless at zero chroma and float noise there swings wildly, so pin
|
|
248
|
+
// it to keep round trips through gray stable.
|
|
249
|
+
hue: chroma < 1e-6 ? 0 : mod360((Math.atan2(b, a) * 180) / Math.PI),
|
|
250
|
+
alpha: color.alpha,
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function oklchToRgb(color: OklchColor): RgbColor {
|
|
255
|
+
const [r, g, b] = oklchToSrgb(color.lightness / 100, color.chroma, color.hue)
|
|
256
|
+
return {
|
|
257
|
+
space: 'rgb',
|
|
258
|
+
red: clamp(r, 0, 1) * 255,
|
|
259
|
+
green: clamp(g, 0, 1) * 255,
|
|
260
|
+
blue: clamp(b, 0, 1) * 255,
|
|
261
|
+
alpha: color.alpha,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function toRgb(color: Color): RgbColor {
|
|
266
|
+
switch (color.space) {
|
|
267
|
+
case 'rgb':
|
|
268
|
+
return color
|
|
269
|
+
case 'hsl':
|
|
270
|
+
return hslToRgb(color)
|
|
271
|
+
case 'hsb':
|
|
272
|
+
return hsbToRgb(color)
|
|
273
|
+
case 'oklch':
|
|
274
|
+
return oklchToRgb(color)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Converts `color` into `space`. Returns the same object when it is already there. */
|
|
279
|
+
export function convertColor<S extends ColorSpace>(color: Color, space: S): Extract<Color, { space: S }> {
|
|
280
|
+
if (color.space === space) return color as Extract<Color, { space: S }>
|
|
281
|
+
const rgb = toRgb(color)
|
|
282
|
+
switch (space) {
|
|
283
|
+
case 'rgb':
|
|
284
|
+
return rgb as Extract<Color, { space: S }>
|
|
285
|
+
case 'hsl':
|
|
286
|
+
return rgbToHsl(rgb) as Extract<Color, { space: S }>
|
|
287
|
+
case 'hsb':
|
|
288
|
+
return rgbToHsb(rgb) as Extract<Color, { space: S }>
|
|
289
|
+
default:
|
|
290
|
+
return rgbToOklch(rgb) as Extract<Color, { space: S }>
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const CHANNEL_NAMES: Record<ColorChannel, string> = {
|
|
295
|
+
red: 'Red',
|
|
296
|
+
green: 'Green',
|
|
297
|
+
blue: 'Blue',
|
|
298
|
+
hue: 'Hue',
|
|
299
|
+
saturation: 'Saturation',
|
|
300
|
+
lightness: 'Lightness',
|
|
301
|
+
brightness: 'Brightness',
|
|
302
|
+
chroma: 'Chroma',
|
|
303
|
+
alpha: 'Alpha',
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Returns the English display name of `channel`, for labels and value text. */
|
|
307
|
+
export function getChannelName(channel: ColorChannel): string {
|
|
308
|
+
return CHANNEL_NAMES[channel]
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Formats a channel value for display, with the unit the channel is measured in. */
|
|
312
|
+
export function formatChannelValue(color: Color, channel: ColorChannel): string {
|
|
313
|
+
const value = getChannelValue(color, channel)
|
|
314
|
+
if (channel === 'hue') return `${Math.round(value)}°`
|
|
315
|
+
if (channel === 'chroma') return value.toFixed(3)
|
|
316
|
+
if (channel === 'alpha') return `${Math.round(value * 100)}%`
|
|
317
|
+
if (color.space === 'rgb') return `${Math.round(value)}`
|
|
318
|
+
return `${Math.round(value)}%`
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const HEX_RE = /^#([0-9a-f]{3,8})$/i
|
|
322
|
+
const FUNC_RE = /^(rgba?|hsla?|hsba?|hsva?|oklch)\(([^)]*)\)$/i
|
|
323
|
+
|
|
324
|
+
function parseComponent(raw: string, scale: number, max: number): number {
|
|
325
|
+
const percent = raw.endsWith('%')
|
|
326
|
+
const value = Number.parseFloat(percent ? raw.slice(0, -1) : raw)
|
|
327
|
+
if (Number.isNaN(value)) throw new Error(`Invalid color component "${raw}"`)
|
|
328
|
+
return clamp(percent ? (value / 100) * scale : value, 0, max)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function parseAlpha(raw: string | undefined): number {
|
|
332
|
+
if (raw == null || raw === '' || raw === 'none') return 1
|
|
333
|
+
return parseComponent(raw, 1, 1)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Parses a CSS color string into a `Color`. Accepts hex (3, 4, 6 or 8 digits),
|
|
338
|
+
* `rgb()`, `hsl()`, `oklch()` in both comma and space separated forms, plus the
|
|
339
|
+
* non-CSS `hsb()` used by design tools. Throws on anything else.
|
|
340
|
+
*/
|
|
341
|
+
export function parseColor(value: string): Color {
|
|
342
|
+
const input = value.trim()
|
|
343
|
+
|
|
344
|
+
const hex = HEX_RE.exec(input)
|
|
345
|
+
if (hex) {
|
|
346
|
+
const digits = hex[1] ?? ''
|
|
347
|
+
if (digits.length !== 3 && digits.length !== 4 && digits.length !== 6 && digits.length !== 8) {
|
|
348
|
+
throw new Error(`Invalid hex color "${value}"`)
|
|
349
|
+
}
|
|
350
|
+
const expand = digits.length <= 4
|
|
351
|
+
const size = expand ? 1 : 2
|
|
352
|
+
const channel = (i: number) => {
|
|
353
|
+
const slice = digits.slice(i * size, i * size + size)
|
|
354
|
+
return Number.parseInt(expand ? slice + slice : slice, 16)
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
space: 'rgb',
|
|
358
|
+
red: channel(0),
|
|
359
|
+
green: channel(1),
|
|
360
|
+
blue: channel(2),
|
|
361
|
+
alpha: digits.length === 4 || digits.length === 8 ? channel(3) / 255 : 1,
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const func = FUNC_RE.exec(input)
|
|
366
|
+
if (func) {
|
|
367
|
+
const name = (func[1] ?? '').toLowerCase()
|
|
368
|
+
const parts = (func[2] ?? '')
|
|
369
|
+
.replace('/', ' ')
|
|
370
|
+
.split(/[\s,]+/)
|
|
371
|
+
.filter(Boolean)
|
|
372
|
+
const [first, second, third, fourth] = parts
|
|
373
|
+
if (first == null || second == null || third == null) throw new Error(`Invalid color "${value}"`)
|
|
374
|
+
const alpha = parseAlpha(fourth)
|
|
375
|
+
|
|
376
|
+
if (name === 'rgb' || name === 'rgba') {
|
|
377
|
+
return {
|
|
378
|
+
space: 'rgb',
|
|
379
|
+
red: parseComponent(first, 255, 255),
|
|
380
|
+
green: parseComponent(second, 255, 255),
|
|
381
|
+
blue: parseComponent(third, 255, 255),
|
|
382
|
+
alpha,
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (name === 'hsl' || name === 'hsla') {
|
|
386
|
+
return {
|
|
387
|
+
space: 'hsl',
|
|
388
|
+
hue: mod360(Number.parseFloat(first)),
|
|
389
|
+
saturation: parseComponent(second, 100, 100),
|
|
390
|
+
lightness: parseComponent(third, 100, 100),
|
|
391
|
+
alpha,
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (name === 'oklch') {
|
|
395
|
+
return {
|
|
396
|
+
space: 'oklch',
|
|
397
|
+
lightness: parseComponent(first, 100, 100),
|
|
398
|
+
chroma: parseComponent(second, 0.4, Number.POSITIVE_INFINITY),
|
|
399
|
+
hue: mod360(Number.parseFloat(third)),
|
|
400
|
+
alpha,
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
space: 'hsb',
|
|
405
|
+
hue: mod360(Number.parseFloat(first)),
|
|
406
|
+
saturation: parseComponent(second, 100, 100),
|
|
407
|
+
brightness: parseComponent(third, 100, 100),
|
|
408
|
+
alpha,
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
throw new Error(`Invalid color "${value}"`)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** Parses `value` into a `Color`, returning `undefined` instead of throwing on bad input. */
|
|
416
|
+
export function safeParseColor(value: string): Color | undefined {
|
|
417
|
+
try {
|
|
418
|
+
return parseColor(value)
|
|
419
|
+
} catch {
|
|
420
|
+
return undefined
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function round(value: number, precision = 0) {
|
|
425
|
+
const factor = 10 ** precision
|
|
426
|
+
return Math.round(value * factor) / factor
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function hexPair(value: number) {
|
|
430
|
+
return clamp(Math.round(value), 0, 255).toString(16).padStart(2, '0')
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Serializes `color` to a CSS string. `'css'` picks the shortest form the browser
|
|
435
|
+
* understands for the color's own space, which is what you want for a `background`.
|
|
436
|
+
*/
|
|
437
|
+
export function formatColor(color: Color, format: ColorFormat | 'css' = 'css'): string {
|
|
438
|
+
if (format === 'css') {
|
|
439
|
+
const space = color.space === 'hsb' ? 'hsl' : color.space
|
|
440
|
+
return formatColor(color, (color.alpha < 1 ? `${space}a` : space) as ColorFormat)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (format === 'hex' || format === 'hexa') {
|
|
444
|
+
const rgb = convertColor(color, 'rgb')
|
|
445
|
+
const base = `#${hexPair(rgb.red)}${hexPair(rgb.green)}${hexPair(rgb.blue)}`
|
|
446
|
+
return format === 'hexa' ? `${base}${hexPair(rgb.alpha * 255)}` : base
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const withAlpha = format.endsWith('a')
|
|
450
|
+
const alpha = round(color.alpha, 2)
|
|
451
|
+
|
|
452
|
+
if (format === 'rgb' || format === 'rgba') {
|
|
453
|
+
const { red, green, blue } = convertColor(color, 'rgb')
|
|
454
|
+
const channels = `${round(red)}, ${round(green)}, ${round(blue)}`
|
|
455
|
+
return withAlpha ? `rgba(${channels}, ${alpha})` : `rgb(${channels})`
|
|
456
|
+
}
|
|
457
|
+
if (format === 'hsl' || format === 'hsla') {
|
|
458
|
+
const { hue, saturation, lightness } = convertColor(color, 'hsl')
|
|
459
|
+
const channels = `${round(hue, 2)}, ${round(saturation, 2)}%, ${round(lightness, 2)}%`
|
|
460
|
+
return withAlpha ? `hsla(${channels}, ${alpha})` : `hsl(${channels})`
|
|
461
|
+
}
|
|
462
|
+
if (format === 'hsb' || format === 'hsba') {
|
|
463
|
+
const { hue, saturation, brightness } = convertColor(color, 'hsb')
|
|
464
|
+
const channels = `${round(hue, 2)}, ${round(saturation, 2)}%, ${round(brightness, 2)}%`
|
|
465
|
+
return withAlpha ? `hsba(${channels}, ${alpha})` : `hsb(${channels})`
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const { lightness, chroma, hue } = convertColor(color, 'oklch')
|
|
469
|
+
const channels = `${round(lightness, 2)}% ${round(chroma, 4)} ${round(hue, 2)}`
|
|
470
|
+
return withAlpha ? `oklch(${channels} / ${alpha})` : `oklch(${channels})`
|
|
471
|
+
}
|
|
@@ -4,11 +4,11 @@ import { DirectionProvider as BaseDirectionProvider } from '@base-ui/react/direc
|
|
|
4
4
|
export type Direction = 'ltr' | 'rtl'
|
|
5
5
|
|
|
6
6
|
export interface DirectionProviderProps {
|
|
7
|
+
/** The subtree that should read this direction */
|
|
7
8
|
children: ReactNode
|
|
8
9
|
/**
|
|
9
|
-
* Reading direction for components
|
|
10
|
-
*
|
|
11
|
-
* our `useDirection()` hook. Defaults to `ltr`.
|
|
10
|
+
* Reading direction for descendant components
|
|
11
|
+
* @default 'ltr'
|
|
12
12
|
*/
|
|
13
13
|
dir?: Direction
|
|
14
14
|
}
|
|
@@ -18,7 +18,7 @@ export interface DirectionProviderProps {
|
|
|
18
18
|
* UI's direction provider so consumers depend on `@appica/ui-react` rather than
|
|
19
19
|
* the underlying primitive.
|
|
20
20
|
*
|
|
21
|
-
* Optional
|
|
21
|
+
* Optional - components default to `ltr` with no provider, so reach for this
|
|
22
22
|
* only when supporting RTL.
|
|
23
23
|
*/
|
|
24
24
|
export function DirectionProvider({ children, dir = 'ltr' }: DirectionProviderProps) {
|