react-stately 3.46.0 → 3.47.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/dist/exports/Color.cjs.map +1 -1
- package/dist/exports/Color.js.map +1 -1
- package/dist/exports/Color.mjs.map +1 -1
- package/dist/exports/index.cjs.map +1 -1
- package/dist/exports/index.js.map +1 -1
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/private/autocomplete/useAutocompleteState.cjs.map +1 -1
- package/dist/exports/private/autocomplete/useAutocompleteState.js.map +1 -1
- package/dist/exports/private/autocomplete/useAutocompleteState.mjs.map +1 -1
- package/dist/exports/private/collections/getChildNodes.cjs.map +1 -1
- package/dist/exports/private/collections/getChildNodes.js.map +1 -1
- package/dist/exports/private/collections/getChildNodes.mjs.map +1 -1
- package/dist/exports/private/flags/flags.cjs.map +1 -1
- package/dist/exports/private/flags/flags.js.map +1 -1
- package/dist/exports/private/flags/flags.mjs.map +1 -1
- package/dist/exports/private/form/useFormValidationState.cjs.map +1 -1
- package/dist/exports/private/form/useFormValidationState.js.map +1 -1
- package/dist/exports/private/form/useFormValidationState.mjs.map +1 -1
- package/dist/exports/private/grid/GridCollection.cjs.map +1 -1
- package/dist/exports/private/grid/GridCollection.js.map +1 -1
- package/dist/exports/private/grid/GridCollection.mjs.map +1 -1
- package/dist/exports/private/steplist/useStepListState.cjs.map +1 -1
- package/dist/exports/private/steplist/useStepListState.js.map +1 -1
- package/dist/exports/private/steplist/useStepListState.mjs.map +1 -1
- package/dist/exports/private/table/TableCollection.cjs.map +1 -1
- package/dist/exports/private/table/TableCollection.js.map +1 -1
- package/dist/exports/private/table/TableCollection.mjs.map +1 -1
- package/dist/exports/private/table/useTreeGridState.cjs.map +1 -1
- package/dist/exports/private/table/useTreeGridState.js.map +1 -1
- package/dist/exports/private/table/useTreeGridState.mjs.map +1 -1
- package/dist/exports/useAsyncList.cjs.map +1 -1
- package/dist/exports/useAsyncList.js.map +1 -1
- package/dist/exports/useAsyncList.mjs.map +1 -1
- package/dist/exports/useCalendarState.cjs.map +1 -1
- package/dist/exports/useCalendarState.js.map +1 -1
- package/dist/exports/useCalendarState.mjs.map +1 -1
- package/dist/exports/useColorAreaState.cjs.map +1 -1
- package/dist/exports/useColorAreaState.js.map +1 -1
- package/dist/exports/useColorAreaState.mjs.map +1 -1
- package/dist/exports/useColorFieldState.cjs.map +1 -1
- package/dist/exports/useColorFieldState.js.map +1 -1
- package/dist/exports/useColorFieldState.mjs.map +1 -1
- package/dist/exports/useColorPickerState.cjs.map +1 -1
- package/dist/exports/useColorPickerState.js.map +1 -1
- package/dist/exports/useColorPickerState.mjs.map +1 -1
- package/dist/exports/useColorSliderState.cjs.map +1 -1
- package/dist/exports/useColorSliderState.js.map +1 -1
- package/dist/exports/useColorSliderState.mjs.map +1 -1
- package/dist/exports/useColorWheelState.cjs.map +1 -1
- package/dist/exports/useColorWheelState.js.map +1 -1
- package/dist/exports/useColorWheelState.mjs.map +1 -1
- package/dist/exports/useComboBoxState.cjs +1 -1
- package/dist/exports/useComboBoxState.cjs.map +1 -1
- package/dist/exports/useComboBoxState.js +1 -1
- package/dist/exports/useComboBoxState.js.map +1 -1
- package/dist/exports/useComboBoxState.mjs +1 -1
- package/dist/exports/useComboBoxState.mjs.map +1 -1
- package/dist/exports/useDateFieldState.cjs.map +1 -1
- package/dist/exports/useDateFieldState.js.map +1 -1
- package/dist/exports/useDateFieldState.mjs.map +1 -1
- package/dist/exports/useDatePickerState.cjs.map +1 -1
- package/dist/exports/useDatePickerState.js.map +1 -1
- package/dist/exports/useDatePickerState.mjs.map +1 -1
- package/dist/exports/useDateRangePickerState.cjs.map +1 -1
- package/dist/exports/useDateRangePickerState.js.map +1 -1
- package/dist/exports/useDateRangePickerState.mjs.map +1 -1
- package/dist/exports/useDisclosureGroupState.cjs.map +1 -1
- package/dist/exports/useDisclosureGroupState.js.map +1 -1
- package/dist/exports/useDisclosureGroupState.mjs.map +1 -1
- package/dist/exports/useDraggableCollectionState.cjs.map +1 -1
- package/dist/exports/useDraggableCollectionState.js.map +1 -1
- package/dist/exports/useDraggableCollectionState.mjs.map +1 -1
- package/dist/exports/useDroppableCollectionState.cjs.map +1 -1
- package/dist/exports/useDroppableCollectionState.js.map +1 -1
- package/dist/exports/useDroppableCollectionState.mjs.map +1 -1
- package/dist/exports/useMenuTriggerState.cjs.map +1 -1
- package/dist/exports/useMenuTriggerState.js.map +1 -1
- package/dist/exports/useMenuTriggerState.mjs.map +1 -1
- package/dist/exports/useMultipleSelectionState.cjs.map +1 -1
- package/dist/exports/useMultipleSelectionState.js.map +1 -1
- package/dist/exports/useMultipleSelectionState.mjs.map +1 -1
- package/dist/exports/useOverlayTriggerState.cjs.map +1 -1
- package/dist/exports/useOverlayTriggerState.js.map +1 -1
- package/dist/exports/useOverlayTriggerState.mjs.map +1 -1
- package/dist/exports/useRangeCalendarState.cjs.map +1 -1
- package/dist/exports/useRangeCalendarState.js.map +1 -1
- package/dist/exports/useRangeCalendarState.mjs.map +1 -1
- package/dist/exports/useSelectState.cjs.map +1 -1
- package/dist/exports/useSelectState.js.map +1 -1
- package/dist/exports/useSelectState.mjs.map +1 -1
- package/dist/exports/useSingleSelectListState.cjs.map +1 -1
- package/dist/exports/useSingleSelectListState.js.map +1 -1
- package/dist/exports/useSingleSelectListState.mjs.map +1 -1
- package/dist/exports/useTableState.cjs.map +1 -1
- package/dist/exports/useTableState.js.map +1 -1
- package/dist/exports/useTableState.mjs.map +1 -1
- package/dist/exports/useTimeFieldState.cjs.map +1 -1
- package/dist/exports/useTimeFieldState.js.map +1 -1
- package/dist/exports/useTimeFieldState.mjs.map +1 -1
- package/dist/exports/useToastState.cjs.map +1 -1
- package/dist/exports/useToastState.js.map +1 -1
- package/dist/exports/useToastState.mjs.map +1 -1
- package/dist/private/autocomplete/useAutocompleteState.cjs.map +1 -1
- package/dist/private/autocomplete/useAutocompleteState.js.map +1 -1
- package/dist/private/autocomplete/useAutocompleteState.mjs.map +1 -1
- package/dist/private/calendar/useCalendarState.cjs +82 -30
- package/dist/private/calendar/useCalendarState.cjs.map +1 -1
- package/dist/private/calendar/useCalendarState.js +85 -32
- package/dist/private/calendar/useCalendarState.js.map +1 -1
- package/dist/private/calendar/useCalendarState.mjs +84 -32
- package/dist/private/calendar/useCalendarState.mjs.map +1 -1
- package/dist/private/calendar/useRangeCalendarState.cjs +53 -40
- package/dist/private/calendar/useRangeCalendarState.cjs.map +1 -1
- package/dist/private/calendar/useRangeCalendarState.js +55 -43
- package/dist/private/calendar/useRangeCalendarState.js.map +1 -1
- package/dist/private/calendar/useRangeCalendarState.mjs +55 -42
- package/dist/private/calendar/useRangeCalendarState.mjs.map +1 -1
- package/dist/private/calendar/utils.cjs +6 -1
- package/dist/private/calendar/utils.cjs.map +1 -1
- package/dist/private/calendar/utils.js +6 -2
- package/dist/private/calendar/utils.js.map +1 -1
- package/dist/private/calendar/utils.mjs +6 -2
- package/dist/private/calendar/utils.mjs.map +1 -1
- package/dist/private/checkbox/useCheckboxGroupState.cjs.map +1 -1
- package/dist/private/checkbox/useCheckboxGroupState.js.map +1 -1
- package/dist/private/checkbox/useCheckboxGroupState.mjs.map +1 -1
- package/dist/private/collections/CollectionBuilder.cjs.map +1 -1
- package/dist/private/collections/CollectionBuilder.js.map +1 -1
- package/dist/private/collections/CollectionBuilder.mjs.map +1 -1
- package/dist/private/collections/Item.cjs +1 -0
- package/dist/private/collections/Item.cjs.map +1 -1
- package/dist/private/collections/Item.js +1 -0
- package/dist/private/collections/Item.js.map +1 -1
- package/dist/private/collections/Item.mjs +1 -0
- package/dist/private/collections/Item.mjs.map +1 -1
- package/dist/private/collections/Section.cjs +1 -0
- package/dist/private/collections/Section.cjs.map +1 -1
- package/dist/private/collections/Section.js +1 -0
- package/dist/private/collections/Section.js.map +1 -1
- package/dist/private/collections/Section.mjs +1 -0
- package/dist/private/collections/Section.mjs.map +1 -1
- package/dist/private/collections/getChildNodes.cjs.map +1 -1
- package/dist/private/collections/getChildNodes.js.map +1 -1
- package/dist/private/collections/getChildNodes.mjs.map +1 -1
- package/dist/private/collections/useCollection.cjs.map +1 -1
- package/dist/private/collections/useCollection.js.map +1 -1
- package/dist/private/collections/useCollection.mjs.map +1 -1
- package/dist/private/color/Color.cjs +15 -9
- package/dist/private/color/Color.cjs.map +1 -1
- package/dist/private/color/Color.js +15 -9
- package/dist/private/color/Color.js.map +1 -1
- package/dist/private/color/Color.mjs +15 -9
- package/dist/private/color/Color.mjs.map +1 -1
- package/dist/private/color/useColorAreaState.cjs.map +1 -1
- package/dist/private/color/useColorAreaState.js.map +1 -1
- package/dist/private/color/useColorAreaState.mjs.map +1 -1
- package/dist/private/color/useColorChannelFieldState.cjs.map +1 -1
- package/dist/private/color/useColorChannelFieldState.js.map +1 -1
- package/dist/private/color/useColorChannelFieldState.mjs.map +1 -1
- package/dist/private/color/useColorFieldState.cjs.map +1 -1
- package/dist/private/color/useColorFieldState.js.map +1 -1
- package/dist/private/color/useColorFieldState.mjs.map +1 -1
- package/dist/private/color/useColorPickerState.cjs.map +1 -1
- package/dist/private/color/useColorPickerState.js.map +1 -1
- package/dist/private/color/useColorPickerState.mjs.map +1 -1
- package/dist/private/color/useColorSliderState.cjs +5 -3
- package/dist/private/color/useColorSliderState.cjs.map +1 -1
- package/dist/private/color/useColorSliderState.js +5 -3
- package/dist/private/color/useColorSliderState.js.map +1 -1
- package/dist/private/color/useColorSliderState.mjs +5 -3
- package/dist/private/color/useColorSliderState.mjs.map +1 -1
- package/dist/private/color/useColorWheelState.cjs.map +1 -1
- package/dist/private/color/useColorWheelState.js.map +1 -1
- package/dist/private/color/useColorWheelState.mjs.map +1 -1
- package/dist/private/combobox/useComboBoxState.cjs +8 -2
- package/dist/private/combobox/useComboBoxState.cjs.map +1 -1
- package/dist/private/combobox/useComboBoxState.js +8 -2
- package/dist/private/combobox/useComboBoxState.js.map +1 -1
- package/dist/private/combobox/useComboBoxState.mjs +8 -2
- package/dist/private/combobox/useComboBoxState.mjs.map +1 -1
- package/dist/private/data/useAsyncList.cjs.map +1 -1
- package/dist/private/data/useAsyncList.js.map +1 -1
- package/dist/private/data/useAsyncList.mjs.map +1 -1
- package/dist/private/data/useListData.cjs.map +1 -1
- package/dist/private/data/useListData.js.map +1 -1
- package/dist/private/data/useListData.mjs.map +1 -1
- package/dist/private/data/useTreeData.cjs.map +1 -1
- package/dist/private/data/useTreeData.js.map +1 -1
- package/dist/private/data/useTreeData.mjs.map +1 -1
- package/dist/private/datepicker/IncompleteDate.cjs +8 -2
- package/dist/private/datepicker/IncompleteDate.cjs.map +1 -1
- package/dist/private/datepicker/IncompleteDate.js +8 -2
- package/dist/private/datepicker/IncompleteDate.js.map +1 -1
- package/dist/private/datepicker/IncompleteDate.mjs +8 -2
- package/dist/private/datepicker/IncompleteDate.mjs.map +1 -1
- package/dist/private/datepicker/placeholders.cjs +5 -0
- package/dist/private/datepicker/placeholders.cjs.map +1 -1
- package/dist/private/datepicker/placeholders.js +5 -0
- package/dist/private/datepicker/placeholders.js.map +1 -1
- package/dist/private/datepicker/placeholders.mjs +5 -0
- package/dist/private/datepicker/placeholders.mjs.map +1 -1
- package/dist/private/datepicker/useDateFieldState.cjs.map +1 -1
- package/dist/private/datepicker/useDateFieldState.js.map +1 -1
- package/dist/private/datepicker/useDateFieldState.mjs.map +1 -1
- package/dist/private/datepicker/useDatePickerState.cjs.map +1 -1
- package/dist/private/datepicker/useDatePickerState.js.map +1 -1
- package/dist/private/datepicker/useDatePickerState.mjs.map +1 -1
- package/dist/private/datepicker/useDateRangePickerState.cjs +1 -1
- package/dist/private/datepicker/useDateRangePickerState.cjs.map +1 -1
- package/dist/private/datepicker/useDateRangePickerState.js +1 -1
- package/dist/private/datepicker/useDateRangePickerState.js.map +1 -1
- package/dist/private/datepicker/useDateRangePickerState.mjs +1 -1
- package/dist/private/datepicker/useDateRangePickerState.mjs.map +1 -1
- package/dist/private/datepicker/useTimeFieldState.cjs.map +1 -1
- package/dist/private/datepicker/useTimeFieldState.js.map +1 -1
- package/dist/private/datepicker/useTimeFieldState.mjs.map +1 -1
- package/dist/private/datepicker/utils.cjs +2 -2
- package/dist/private/datepicker/utils.cjs.map +1 -1
- package/dist/private/datepicker/utils.js +2 -2
- package/dist/private/datepicker/utils.js.map +1 -1
- package/dist/private/datepicker/utils.mjs +2 -2
- package/dist/private/datepicker/utils.mjs.map +1 -1
- package/dist/private/disclosure/useDisclosureGroupState.cjs.map +1 -1
- package/dist/private/disclosure/useDisclosureGroupState.js.map +1 -1
- package/dist/private/disclosure/useDisclosureGroupState.mjs.map +1 -1
- package/dist/private/disclosure/useDisclosureState.cjs.map +1 -1
- package/dist/private/disclosure/useDisclosureState.js.map +1 -1
- package/dist/private/disclosure/useDisclosureState.mjs.map +1 -1
- package/dist/private/dnd/useDraggableCollectionState.cjs.map +1 -1
- package/dist/private/dnd/useDraggableCollectionState.js.map +1 -1
- package/dist/private/dnd/useDraggableCollectionState.mjs.map +1 -1
- package/dist/private/dnd/useDroppableCollectionState.cjs.map +1 -1
- package/dist/private/dnd/useDroppableCollectionState.js.map +1 -1
- package/dist/private/dnd/useDroppableCollectionState.mjs.map +1 -1
- package/dist/private/form/useFormValidationState.cjs.map +1 -1
- package/dist/private/form/useFormValidationState.js.map +1 -1
- package/dist/private/form/useFormValidationState.mjs.map +1 -1
- package/dist/private/grid/GridCollection.cjs.map +1 -1
- package/dist/private/grid/GridCollection.js.map +1 -1
- package/dist/private/grid/GridCollection.mjs.map +1 -1
- package/dist/private/grid/useGridState.cjs.map +1 -1
- package/dist/private/grid/useGridState.js.map +1 -1
- package/dist/private/grid/useGridState.mjs.map +1 -1
- package/dist/private/layout/GridLayout.cjs +8 -3
- package/dist/private/layout/GridLayout.cjs.map +1 -1
- package/dist/private/layout/GridLayout.js +8 -3
- package/dist/private/layout/GridLayout.js.map +1 -1
- package/dist/private/layout/GridLayout.mjs +8 -3
- package/dist/private/layout/GridLayout.mjs.map +1 -1
- package/dist/private/layout/ListLayout.cjs +1 -1
- package/dist/private/layout/ListLayout.cjs.map +1 -1
- package/dist/private/layout/ListLayout.js +2 -1
- package/dist/private/layout/ListLayout.js.map +1 -1
- package/dist/private/layout/ListLayout.mjs +1 -1
- package/dist/private/layout/ListLayout.mjs.map +1 -1
- package/dist/private/layout/TableLayout.cjs +60 -35
- package/dist/private/layout/TableLayout.cjs.map +1 -1
- package/dist/private/layout/TableLayout.js +65 -38
- package/dist/private/layout/TableLayout.js.map +1 -1
- package/dist/private/layout/TableLayout.mjs +61 -36
- package/dist/private/layout/TableLayout.mjs.map +1 -1
- package/dist/private/layout/WaterfallLayout.cjs.map +1 -1
- package/dist/private/layout/WaterfallLayout.js.map +1 -1
- package/dist/private/layout/WaterfallLayout.mjs.map +1 -1
- package/dist/private/list/ListCollection.cjs.map +1 -1
- package/dist/private/list/ListCollection.js.map +1 -1
- package/dist/private/list/ListCollection.mjs.map +1 -1
- package/dist/private/list/useListState.cjs.map +1 -1
- package/dist/private/list/useListState.js.map +1 -1
- package/dist/private/list/useListState.mjs.map +1 -1
- package/dist/private/list/useSingleSelectListState.cjs.map +1 -1
- package/dist/private/list/useSingleSelectListState.js.map +1 -1
- package/dist/private/list/useSingleSelectListState.mjs.map +1 -1
- package/dist/private/menu/useMenuTriggerState.cjs.map +1 -1
- package/dist/private/menu/useMenuTriggerState.js.map +1 -1
- package/dist/private/menu/useMenuTriggerState.mjs.map +1 -1
- package/dist/private/menu/useSubmenuTriggerState.cjs.map +1 -1
- package/dist/private/menu/useSubmenuTriggerState.js.map +1 -1
- package/dist/private/menu/useSubmenuTriggerState.mjs.map +1 -1
- package/dist/private/numberfield/useNumberFieldState.cjs +13 -1
- package/dist/private/numberfield/useNumberFieldState.cjs.map +1 -1
- package/dist/private/numberfield/useNumberFieldState.js +13 -1
- package/dist/private/numberfield/useNumberFieldState.js.map +1 -1
- package/dist/private/numberfield/useNumberFieldState.mjs +13 -1
- package/dist/private/numberfield/useNumberFieldState.mjs.map +1 -1
- package/dist/private/overlays/useOverlayTriggerState.cjs.map +1 -1
- package/dist/private/overlays/useOverlayTriggerState.js.map +1 -1
- package/dist/private/overlays/useOverlayTriggerState.mjs.map +1 -1
- package/dist/private/radio/useRadioGroupState.cjs.map +1 -1
- package/dist/private/radio/useRadioGroupState.js.map +1 -1
- package/dist/private/radio/useRadioGroupState.mjs.map +1 -1
- package/dist/private/searchfield/useSearchFieldState.cjs.map +1 -1
- package/dist/private/searchfield/useSearchFieldState.js.map +1 -1
- package/dist/private/searchfield/useSearchFieldState.mjs.map +1 -1
- package/dist/private/select/useSelectState.cjs.map +1 -1
- package/dist/private/select/useSelectState.js.map +1 -1
- package/dist/private/select/useSelectState.mjs.map +1 -1
- package/dist/private/selection/SelectionManager.cjs +2 -1
- package/dist/private/selection/SelectionManager.cjs.map +1 -1
- package/dist/private/selection/SelectionManager.js +3 -2
- package/dist/private/selection/SelectionManager.js.map +1 -1
- package/dist/private/selection/SelectionManager.mjs +2 -1
- package/dist/private/selection/SelectionManager.mjs.map +1 -1
- package/dist/private/selection/useMultipleSelectionState.cjs.map +1 -1
- package/dist/private/selection/useMultipleSelectionState.js.map +1 -1
- package/dist/private/selection/useMultipleSelectionState.mjs.map +1 -1
- package/dist/private/slider/useSliderState.cjs +22 -2
- package/dist/private/slider/useSliderState.cjs.map +1 -1
- package/dist/private/slider/useSliderState.js +22 -2
- package/dist/private/slider/useSliderState.js.map +1 -1
- package/dist/private/slider/useSliderState.mjs +22 -2
- package/dist/private/slider/useSliderState.mjs.map +1 -1
- package/dist/private/steplist/useStepListState.cjs.map +1 -1
- package/dist/private/steplist/useStepListState.js.map +1 -1
- package/dist/private/steplist/useStepListState.mjs.map +1 -1
- package/dist/private/table/Cell.cjs +2 -1
- package/dist/private/table/Cell.cjs.map +1 -1
- package/dist/private/table/Cell.js +2 -1
- package/dist/private/table/Cell.js.map +1 -1
- package/dist/private/table/Cell.mjs +2 -1
- package/dist/private/table/Cell.mjs.map +1 -1
- package/dist/private/table/Column.cjs +1 -0
- package/dist/private/table/Column.cjs.map +1 -1
- package/dist/private/table/Column.js +1 -0
- package/dist/private/table/Column.js.map +1 -1
- package/dist/private/table/Column.mjs +1 -0
- package/dist/private/table/Column.mjs.map +1 -1
- package/dist/private/table/Row.cjs +2 -1
- package/dist/private/table/Row.cjs.map +1 -1
- package/dist/private/table/Row.js +2 -1
- package/dist/private/table/Row.js.map +1 -1
- package/dist/private/table/Row.mjs +2 -1
- package/dist/private/table/Row.mjs.map +1 -1
- package/dist/private/table/TableBody.cjs +4 -2
- package/dist/private/table/TableBody.cjs.map +1 -1
- package/dist/private/table/TableBody.js +4 -2
- package/dist/private/table/TableBody.js.map +1 -1
- package/dist/private/table/TableBody.mjs +4 -2
- package/dist/private/table/TableBody.mjs.map +1 -1
- package/dist/private/table/TableCollection.cjs +1 -1
- package/dist/private/table/TableCollection.cjs.map +1 -1
- package/dist/private/table/TableCollection.js +1 -1
- package/dist/private/table/TableCollection.js.map +1 -1
- package/dist/private/table/TableCollection.mjs +1 -1
- package/dist/private/table/TableCollection.mjs.map +1 -1
- package/dist/private/table/TableColumnLayout.cjs +4 -1
- package/dist/private/table/TableColumnLayout.cjs.map +1 -1
- package/dist/private/table/TableColumnLayout.js +4 -1
- package/dist/private/table/TableColumnLayout.js.map +1 -1
- package/dist/private/table/TableColumnLayout.mjs +4 -1
- package/dist/private/table/TableColumnLayout.mjs.map +1 -1
- package/dist/private/table/TableHeader.cjs +4 -2
- package/dist/private/table/TableHeader.cjs.map +1 -1
- package/dist/private/table/TableHeader.js +4 -2
- package/dist/private/table/TableHeader.js.map +1 -1
- package/dist/private/table/TableHeader.mjs +4 -2
- package/dist/private/table/TableHeader.mjs.map +1 -1
- package/dist/private/table/TableUtils.cjs +1 -1
- package/dist/private/table/TableUtils.cjs.map +1 -1
- package/dist/private/table/TableUtils.js +1 -1
- package/dist/private/table/TableUtils.js.map +1 -1
- package/dist/private/table/TableUtils.mjs +1 -1
- package/dist/private/table/TableUtils.mjs.map +1 -1
- package/dist/private/table/useTableColumnResizeState.cjs.map +1 -1
- package/dist/private/table/useTableColumnResizeState.js.map +1 -1
- package/dist/private/table/useTableColumnResizeState.mjs.map +1 -1
- package/dist/private/table/useTableState.cjs +2 -1
- package/dist/private/table/useTableState.cjs.map +1 -1
- package/dist/private/table/useTableState.js +2 -1
- package/dist/private/table/useTableState.js.map +1 -1
- package/dist/private/table/useTableState.mjs +2 -1
- package/dist/private/table/useTableState.mjs.map +1 -1
- package/dist/private/table/useTreeGridState.cjs +2 -1
- package/dist/private/table/useTreeGridState.cjs.map +1 -1
- package/dist/private/table/useTreeGridState.js +2 -1
- package/dist/private/table/useTreeGridState.js.map +1 -1
- package/dist/private/table/useTreeGridState.mjs +2 -1
- package/dist/private/table/useTreeGridState.mjs.map +1 -1
- package/dist/private/tabs/useTabListState.cjs.map +1 -1
- package/dist/private/tabs/useTabListState.js.map +1 -1
- package/dist/private/tabs/useTabListState.mjs.map +1 -1
- package/dist/private/toast/useToastState.cjs.map +1 -1
- package/dist/private/toast/useToastState.js.map +1 -1
- package/dist/private/toast/useToastState.mjs.map +1 -1
- package/dist/private/toggle/useToggleGroupState.cjs.map +1 -1
- package/dist/private/toggle/useToggleGroupState.js.map +1 -1
- package/dist/private/toggle/useToggleGroupState.mjs.map +1 -1
- package/dist/private/toggle/useToggleState.cjs.map +1 -1
- package/dist/private/toggle/useToggleState.js.map +1 -1
- package/dist/private/toggle/useToggleState.mjs.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.cjs.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.js.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.mjs.map +1 -1
- package/dist/private/tree/TreeCollection.cjs.map +1 -1
- package/dist/private/tree/TreeCollection.js.map +1 -1
- package/dist/private/tree/TreeCollection.mjs.map +1 -1
- package/dist/private/tree/useTreeState.cjs.map +1 -1
- package/dist/private/tree/useTreeState.js.map +1 -1
- package/dist/private/tree/useTreeState.mjs.map +1 -1
- package/dist/private/utils/number.cjs +2 -1
- package/dist/private/utils/number.cjs.map +1 -1
- package/dist/private/utils/number.js +2 -1
- package/dist/private/utils/number.js.map +1 -1
- package/dist/private/utils/number.mjs +2 -1
- package/dist/private/utils/number.mjs.map +1 -1
- package/dist/private/utils/useControlledState.cjs.map +1 -1
- package/dist/private/utils/useControlledState.js.map +1 -1
- package/dist/private/utils/useControlledState.mjs.map +1 -1
- package/dist/private/virtualizer/Layout.cjs.map +1 -1
- package/dist/private/virtualizer/Layout.js.map +1 -1
- package/dist/private/virtualizer/Layout.mjs.map +1 -1
- package/dist/private/virtualizer/LayoutInfo.cjs +4 -2
- package/dist/private/virtualizer/LayoutInfo.cjs.map +1 -1
- package/dist/private/virtualizer/LayoutInfo.js +4 -2
- package/dist/private/virtualizer/LayoutInfo.js.map +1 -1
- package/dist/private/virtualizer/LayoutInfo.mjs +4 -2
- package/dist/private/virtualizer/LayoutInfo.mjs.map +1 -1
- package/dist/private/virtualizer/Rect.cjs +4 -0
- package/dist/private/virtualizer/Rect.cjs.map +1 -1
- package/dist/private/virtualizer/Rect.js +4 -0
- package/dist/private/virtualizer/Rect.js.map +1 -1
- package/dist/private/virtualizer/Rect.mjs +4 -0
- package/dist/private/virtualizer/Rect.mjs.map +1 -1
- package/dist/private/virtualizer/ReusableView.cjs.map +1 -1
- package/dist/private/virtualizer/ReusableView.js.map +1 -1
- package/dist/private/virtualizer/ReusableView.mjs.map +1 -1
- package/dist/private/virtualizer/Size.cjs.map +1 -1
- package/dist/private/virtualizer/Size.js.map +1 -1
- package/dist/private/virtualizer/Size.mjs.map +1 -1
- package/dist/private/virtualizer/Virtualizer.cjs +4 -4
- package/dist/private/virtualizer/Virtualizer.cjs.map +1 -1
- package/dist/private/virtualizer/Virtualizer.js +4 -4
- package/dist/private/virtualizer/Virtualizer.js.map +1 -1
- package/dist/private/virtualizer/Virtualizer.mjs +4 -4
- package/dist/private/virtualizer/Virtualizer.mjs.map +1 -1
- package/dist/private/virtualizer/useVirtualizerState.cjs.map +1 -1
- package/dist/private/virtualizer/useVirtualizerState.js.map +1 -1
- package/dist/private/virtualizer/useVirtualizerState.mjs.map +1 -1
- package/dist/types/exports/useCalendarState.d.ts +1 -1
- package/dist/types/src/autocomplete/useAutocompleteState.d.ts +4 -1
- package/dist/types/src/calendar/types.d.ts +50 -14
- package/dist/types/src/calendar/useCalendarState.d.ts +20 -6
- package/dist/types/src/calendar/useRangeCalendarState.d.ts +14 -5
- package/dist/types/src/calendar/utils.d.ts +1 -0
- package/dist/types/src/checkbox/useCheckboxGroupState.d.ts +1 -0
- package/dist/types/src/collections/useCollection.d.ts +1 -1
- package/dist/types/src/color/useColorAreaState.d.ts +21 -8
- package/dist/types/src/color/useColorFieldState.d.ts +2 -3
- package/dist/types/src/color/useColorSliderState.d.ts +4 -1
- package/dist/types/src/color/useColorWheelState.d.ts +5 -1
- package/dist/types/src/combobox/useComboBoxState.d.ts +19 -6
- package/dist/types/src/data/useAsyncList.d.ts +2 -2
- package/dist/types/src/data/useListData.d.ts +13 -1
- package/dist/types/src/data/useTreeData.d.ts +11 -0
- package/dist/types/src/datepicker/IncompleteDate.d.ts +11 -5
- package/dist/types/src/datepicker/types.d.ts +37 -11
- package/dist/types/src/datepicker/useDateFieldState.d.ts +13 -4
- package/dist/types/src/datepicker/useDatePickerState.d.ts +10 -4
- package/dist/types/src/datepicker/useDateRangePickerState.d.ts +12 -3
- package/dist/types/src/dnd/useDraggableCollectionState.d.ts +4 -1
- package/dist/types/src/form/useFormValidationState.d.ts +4 -1
- package/dist/types/src/grid/GridCollection.d.ts +2 -1
- package/dist/types/src/grid/useGridState.d.ts +7 -3
- package/dist/types/src/layout/GridLayout.d.ts +18 -2
- package/dist/types/src/layout/ListLayout.d.ts +34 -12
- package/dist/types/src/layout/TableLayout.d.ts +11 -4
- package/dist/types/src/layout/WaterfallLayout.d.ts +9 -2
- package/dist/types/src/list/useListState.d.ts +2 -2
- package/dist/types/src/menu/useMenuTriggerState.d.ts +3 -1
- package/dist/types/src/menu/useSubmenuTriggerState.d.ts +2 -2
- package/dist/types/src/numberfield/useNumberFieldState.d.ts +15 -11
- package/dist/types/src/radio/useRadioGroupState.d.ts +4 -1
- package/dist/types/src/select/useSelectState.d.ts +13 -2
- package/dist/types/src/selection/types.d.ts +4 -1
- package/dist/types/src/selection/useMultipleSelectionState.d.ts +2 -0
- package/dist/types/src/slider/useSliderState.d.ts +22 -2
- package/dist/types/src/table/Column.d.ts +4 -1
- package/dist/types/src/table/Row.d.ts +5 -3
- package/dist/types/src/table/TableBody.d.ts +3 -2
- package/dist/types/src/table/TableCollection.d.ts +4 -1
- package/dist/types/src/table/TableColumnLayout.d.ts +4 -1
- package/dist/types/src/table/TableHeader.d.ts +7 -3
- package/dist/types/src/table/TableUtils.d.ts +19 -16
- package/dist/types/src/table/useTableColumnResizeState.d.ts +5 -3
- package/dist/types/src/table/useTableState.d.ts +15 -6
- package/dist/types/src/table/useTreeGridState.d.ts +3 -2
- package/dist/types/src/toggle/useToggleGroupState.d.ts +1 -0
- package/dist/types/src/toggle/useToggleState.d.ts +2 -1
- package/dist/types/src/tooltip/useTooltipTriggerState.d.ts +8 -2
- package/dist/types/src/tree/useTreeState.d.ts +1 -1
- package/dist/types/src/utils/number.d.ts +2 -1
- package/dist/types/src/virtualizer/Layout.d.ts +5 -2
- package/dist/types/src/virtualizer/LayoutInfo.d.ts +10 -3
- package/dist/types/src/virtualizer/Rect.d.ts +4 -0
- package/dist/types/src/virtualizer/Virtualizer.d.ts +5 -4
- package/package.json +8 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AASD,IAAI,mCAAa,IAAI,CAAA,GAAA,gCAAwB,EAAE,CAAA,GAAA,+CAAW;AAGnD,SAAS,yCAAW,KAAa;IACtC,IAAI,MAAM,+BAAS,KAAK,CAAC,UAAU,+BAAS,KAAK,CAAC,UAAU,+BAAS,KAAK,CAAC;IAC3E,IAAI,KACF,OAAO;IAGT,MAAM,IAAI,MAAM,0BAA0B;AA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QAAqB;QAAoB;KAC1C;IAED,IAAI,CAAC,GAAG,GAAG,EAAE,GAAG,qCAAe,UAAU,GAAG,GAAG;IAC/C,OAAO,qCAAe,YAAY,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;AAC1E;AAEA,SAAS,qCAAe,CAAW,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IAClE,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG;IACrC,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG;IACrC,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG;IACrC,OAAO;QAAC;QAAG;QAAG;KAAE;AAClB","sources":["packages/react-stately/src/color/Color.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, toFixedNumber} from '../utils/number';\nimport {ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorSpace, Color as IColor} from './types';\n// @ts-ignore\nimport intlMessages from '../../intl/color/*.json';\nimport {LocalizedStringDictionary, LocalizedStringFormatter} from '@internationalized/string';\nimport {NumberFormatter} from '@internationalized/number';\n\nlet dictionary = new LocalizedStringDictionary(intlMessages);\n\n/** Parses a color from a string value. Throws an error if the string could not be parsed. */\nexport function parseColor(value: string): IColor {\n let res = RGBColor.parse(value) || HSBColor.parse(value) || HSLColor.parse(value);\n if (res) {\n return res;\n }\n\n throw new Error('Invalid color value: ' + value);\n}\n\nexport function normalizeColor(v: string | IColor): IColor {\n if (typeof v === 'string') {\n return parseColor(v);\n } else {\n return v;\n }\n}\n\n/** Returns a list of color channels for a given color space. */\nexport function getColorChannels(colorSpace: ColorSpace): [ColorChannel, ColorChannel, ColorChannel] {\n switch (colorSpace) {\n case 'rgb':\n return RGBColor.colorChannels;\n case 'hsl':\n return HSLColor.colorChannels;\n case 'hsb':\n return HSBColor.colorChannels;\n }\n}\n\n/**\n * Returns the hue value normalized to the range of 0 to 360.\n */\nexport function normalizeHue(hue: number): number {\n if (hue === 360) {\n return hue;\n }\n\n return ((hue % 360) + 360) % 360;\n}\n\n// Lightness threshold between orange and brown.\nconst ORANGE_LIGHTNESS_THRESHOLD = 0.68;\n// Lightness threshold between pure yellow and \"yellow green\".\nconst YELLOW_GREEN_LIGHTNESS_THRESHOLD = 0.85;\n// The maximum lightness considered to be \"dark\".\nconst MAX_DARK_LIGHTNESS = 0.55;\n// The chroma threshold between gray and color.\nconst GRAY_THRESHOLD = 0.001;\nconst OKLCH_HUES: [number, string][] = [\n [0, 'pink'],\n [15, 'red'],\n [48, 'orange'],\n [94, 'yellow'],\n [135, 'green'],\n [175, 'cyan'],\n [264, 'blue'],\n [284, 'purple'],\n [320, 'magenta'],\n [349, 'pink']\n];\n\nabstract class Color implements IColor {\n abstract toFormat(format: ColorFormat): IColor;\n abstract toString(format: ColorFormat | 'css'): string;\n abstract clone(): IColor;\n abstract getChannelRange(channel: ColorChannel): ColorChannelRange;\n abstract getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;\n abstract formatChannelValue(channel: ColorChannel, locale: string): string;\n\n toHexInt(): number {\n return this.toFormat('rgb').toHexInt();\n }\n\n getChannelValue(channel: ColorChannel): number {\n if (channel in this) {\n return this[channel];\n }\n\n throw new Error('Unsupported color channel: ' + channel);\n }\n\n withChannelValue(channel: ColorChannel, value: number): IColor {\n if (channel in this) {\n let x = this.clone();\n x[channel] = value;\n return x;\n }\n\n throw new Error('Unsupported color channel: ' + channel);\n }\n\n getChannelName(channel: ColorChannel, locale: string) {\n let strings = LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;\n return strings.getStringForLocale(channel, locale);\n }\n\n abstract getColorSpace(): ColorSpace;\n\n getColorSpaceAxes(xyChannels: {xChannel?: ColorChannel, yChannel?: ColorChannel}): ColorAxes {\n let {xChannel, yChannel} = xyChannels;\n let xCh = xChannel || this.getColorChannels().find(c => c !== yChannel)!;\n let yCh = yChannel || this.getColorChannels().find(c => c !== xCh)!;\n let zCh = this.getColorChannels().find(c => c !== xCh && c !== yCh)!;\n\n return {xChannel: xCh, yChannel: yCh, zChannel: zCh};\n }\n\n abstract getColorChannels(): [ColorChannel, ColorChannel, ColorChannel]\n\n getColorName(locale: string): string {\n // Convert to oklch color space, which has perceptually uniform lightness across all hues.\n let [l, c, h] = toOKLCH(this);\n\n let strings = LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;\n if (l > 0.999) {\n return strings.getStringForLocale('white', locale);\n }\n\n if (l < 0.001) {\n return strings.getStringForLocale('black', locale);\n }\n\n let hue: string;\n [hue, l] = this.getOklchHue(l, c, h, locale);\n\n let lightness = '';\n let chroma = '';\n if (c <= 0.1 && c >= GRAY_THRESHOLD) {\n if (l >= 0.7) {\n chroma = 'pale';\n } else {\n chroma = 'grayish';\n }\n } else if (c >= 0.15) {\n chroma = 'vibrant';\n }\n\n if (l < 0.3) {\n lightness = 'very dark';\n } else if (l < MAX_DARK_LIGHTNESS) {\n lightness = 'dark';\n } else if (l < 0.7) {\n // none\n } else if (l < 0.85) {\n lightness = 'light';\n } else {\n lightness = 'very light';\n }\n\n if (chroma) {\n chroma = strings.getStringForLocale(chroma, locale);\n }\n\n if (lightness) {\n lightness = strings.getStringForLocale(lightness, locale);\n }\n\n let alpha = this.getChannelValue('alpha');\n let formatter = new LocalizedStringFormatter(locale, strings);\n if (alpha < 1) {\n let percentTransparent = new NumberFormatter(locale, {style: 'percent'}).format(1 - alpha);\n return formatter.format('transparentColorName', {\n lightness,\n chroma,\n hue,\n percentTransparent\n }).replace(/\\s+/g, ' ').trim();\n } else {\n return formatter.format('colorName', {\n lightness,\n chroma,\n hue\n }).replace(/\\s+/g, ' ').trim();\n }\n }\n\n private getOklchHue(l: number, c: number, h: number, locale: string): [string, number] {\n let strings = LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;\n if (c < GRAY_THRESHOLD) {\n return [strings.getStringForLocale('gray', locale), l];\n }\n\n for (let i = 0; i < OKLCH_HUES.length; i++) {\n let [hue, hueName] = OKLCH_HUES[i];\n let [nextHue, nextHueName] = OKLCH_HUES[i + 1] || [360, 'pink'];\n if (h >= hue && h < nextHue) {\n // Split orange hue into brown/orange depending on lightness.\n if (hueName === 'orange') {\n if (l < ORANGE_LIGHTNESS_THRESHOLD) {\n hueName = 'brown';\n } else {\n // Adjust lightness.\n l = (l - ORANGE_LIGHTNESS_THRESHOLD) + MAX_DARK_LIGHTNESS;\n }\n }\n\n // If the hue is at least halfway to the next hue, add the next hue name as well.\n if (h > hue + (nextHue - hue) / 2 && hueName !== nextHueName) {\n hueName = `${hueName} ${nextHueName}`;\n } else if (hueName === 'yellow' && l < YELLOW_GREEN_LIGHTNESS_THRESHOLD) {\n // Yellow shifts toward green at lower lightnesses.\n hueName = 'yellow green';\n }\n\n let name = strings.getStringForLocale(hueName, locale).toLocaleLowerCase(locale);\n return [name, l];\n }\n }\n\n throw new Error('Unexpected hue');\n }\n\n getHueName(locale: string): string {\n let [l, c, h] = toOKLCH(this);\n let [name] = this.getOklchHue(l, c, h, locale);\n return name;\n }\n}\n\nclass RGBColor extends Color {\n constructor(private red: number, private green: number, private blue: number, private alpha: number) {\n super();\n }\n\n static parse(value: string) {\n let colors: Array<number | undefined> = [];\n // matching #rgb, #rgba, #rrggbb, #rrggbbaa\n if (/^#[\\da-f]+$/i.test(value) && [4, 5, 7, 9].includes(value.length)) {\n const values = (value.length < 6 ? value.replace(/[^#]/gi, '$&$&') : value).slice(1).split('');\n while (values.length > 0) {\n colors.push(parseInt(values.splice(0, 2).join(''), 16));\n }\n colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined;\n }\n\n // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)\n const match = value.match(/^rgba?\\((.*)\\)$/);\n if (match?.[1]) {\n colors = match[1].split(',').map(value => Number(value.trim()));\n colors = colors.map((num, i) => {\n return clamp(num ?? 0, 0, i < 3 ? 255 : 1);\n });\n }\n if (colors[0] === undefined || colors[1] === undefined || colors[2] === undefined) {\n return undefined;\n }\n\n return colors.length < 3 ? undefined : new RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1);\n }\n\n toString(format: ColorFormat | 'css' = 'css') {\n switch (format) {\n case 'hex':\n return '#' + (this.red.toString(16).padStart(2, '0') + this.green.toString(16).padStart(2, '0') + this.blue.toString(16).padStart(2, '0')).toUpperCase();\n case 'hexa':\n return '#' + (this.red.toString(16).padStart(2, '0') + this.green.toString(16).padStart(2, '0') + this.blue.toString(16).padStart(2, '0') + Math.round(this.alpha * 255).toString(16).padStart(2, '0')).toUpperCase();\n case 'rgb':\n return `rgb(${this.red}, ${this.green}, ${this.blue})`;\n case 'css':\n case 'rgba':\n return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;\n default:\n return this.toFormat(format).toString(format);\n }\n }\n\n toFormat(format: ColorFormat): IColor {\n switch (format) {\n case 'hex':\n case 'hexa':\n case 'rgb':\n case 'rgba':\n return this;\n case 'hsb':\n case 'hsba':\n return this.toHSB();\n case 'hsl':\n case 'hsla':\n return this.toHSL();\n default:\n throw new Error('Unsupported color conversion: rgb -> ' + format);\n }\n }\n\n toHexInt(): number {\n return this.red << 16 | this.green << 8 | this.blue;\n }\n\n /**\n * Converts an RGB color value to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n * @returns An HSBColor object.\n */\n private toHSB(): IColor {\n const red = this.red / 255;\n const green = this.green / 255;\n const blue = this.blue / 255;\n const min = Math.min(red, green, blue);\n const brightness = Math.max(red, green, blue);\n const chroma = brightness - min;\n const saturation = brightness === 0 ? 0 : chroma / brightness;\n let hue = 0; // achromatic\n\n if (chroma !== 0) {\n switch (brightness) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0);\n break;\n case green:\n hue = (blue - red) / chroma + 2;\n break;\n case blue:\n hue = (red - green) / chroma + 4;\n break;\n }\n\n hue /= 6;\n }\n\n return new HSBColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n this.alpha\n );\n }\n\n /**\n * Converts an RGB color value to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n * @returns An HSLColor object.\n */\n private toHSL(): IColor {\n const red = this.red / 255;\n const green = this.green / 255;\n const blue = this.blue / 255;\n const min = Math.min(red, green, blue);\n const max = Math.max(red, green, blue);\n const lightness = (max + min) / 2;\n const chroma = max - min;\n let hue: number;\n let saturation: number;\n\n if (chroma === 0) {\n hue = saturation = 0; // achromatic\n } else {\n saturation = chroma / (lightness < .5 ? max + min : 2 - max - min);\n\n switch (max) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0);\n break;\n case green:\n hue = (blue - red) / chroma + 2;\n break;\n case blue:\n default:\n hue = (red - green) / chroma + 4;\n break;\n }\n\n hue /= 6;\n }\n\n return new HSLColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n this.alpha);\n }\n\n clone(): IColor {\n return new RGBColor(this.red, this.green, this.blue, this.alpha);\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case 'red':\n case 'green':\n case 'blue':\n return {minValue: 0x0, maxValue: 0xFF, step: 0x1, pageSize: 0x11};\n case 'alpha':\n return {minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {\n switch (channel) {\n case 'red':\n case 'green':\n case 'blue':\n return {style: 'decimal'};\n case 'alpha':\n return {style: 'percent'};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n formatChannelValue(channel: ColorChannel, locale: string) {\n let options = this.getChannelFormatOptions(channel);\n let value = this.getChannelValue(channel);\n return new NumberFormatter(locale, options).format(value);\n }\n\n getColorSpace(): ColorSpace {\n return 'rgb';\n }\n\n static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ['red', 'green', 'blue'];\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return RGBColor.colorChannels;\n }\n}\n\n// X = <negative/positive number with/without decimal places>\n// before/after a comma, 0 or more whitespaces are allowed\n// - hsb(X, X%, X%)\n// - hsba(X, X%, X%, X)\nconst HSB_REGEX = /hsb\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsba\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/;\n\nclass HSBColor extends Color {\n constructor(private hue: number, private saturation: number, private brightness: number, private alpha: number) {\n super();\n }\n\n static parse(value: string): HSBColor | void {\n let m: RegExpMatchArray | null;\n if ((m = value.match(HSB_REGEX))) {\n const [h, s, b, a] = (m[1] ?? m[2]).split(',').map(n => Number(n.trim().replace('%', '')));\n return new HSBColor(normalizeHue(h), clamp(s, 0, 100), clamp(b, 0, 100), clamp(a ?? 1, 0, 1));\n }\n }\n\n toString(format: ColorFormat | 'css' = 'css') {\n switch (format) {\n case 'css':\n return this.toHSL().toString('css');\n case 'hex':\n return this.toRGB().toString('hex');\n case 'hexa':\n return this.toRGB().toString('hexa');\n case 'hsb':\n return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`;\n case 'hsba':\n return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;\n default:\n return this.toFormat(format).toString(format);\n }\n }\n\n toFormat(format: ColorFormat): IColor {\n switch (format) {\n case 'hsb':\n case 'hsba':\n return this;\n case 'hsl':\n case 'hsla':\n return this.toHSL();\n case 'rgb':\n case 'rgba':\n return this.toRGB();\n default:\n throw new Error('Unsupported color conversion: hsb -> ' + format);\n }\n }\n\n /**\n * Converts a HSB color to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.\n * @returns An HSLColor object.\n */\n private toHSL(): IColor {\n let saturation = this.saturation / 100;\n let brightness = this.brightness / 100;\n let lightness = brightness * (1 - saturation / 2);\n saturation = lightness === 0 || lightness === 1 ? 0 : (brightness - lightness) / Math.min(lightness, 1 - lightness);\n\n return new HSLColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n this.alpha\n );\n }\n\n /**\n * Converts a HSV color value to RGB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.\n * @returns An RGBColor object.\n */\n private toRGB(): IColor {\n let hue = this.hue;\n let saturation = this.saturation / 100;\n let brightness = this.brightness / 100;\n let fn = (n: number, k = (n + hue / 60) % 6) => brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);\n return new RGBColor(\n Math.round(fn(5) * 255),\n Math.round(fn(3) * 255),\n Math.round(fn(1) * 255),\n this.alpha\n );\n }\n\n clone(): IColor {\n return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha);\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case 'hue':\n return {minValue: 0, maxValue: 360, step: 1, pageSize: 15};\n case 'saturation':\n case 'brightness':\n return {minValue: 0, maxValue: 100, step: 1, pageSize: 10};\n case 'alpha':\n return {minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {\n switch (channel) {\n case 'hue':\n return {style: 'unit', unit: 'degree', unitDisplay: 'narrow'};\n case 'saturation':\n case 'brightness':\n case 'alpha':\n return {style: 'percent'};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n formatChannelValue(channel: ColorChannel, locale: string) {\n let options = this.getChannelFormatOptions(channel);\n let value = this.getChannelValue(channel);\n if (channel === 'saturation' || channel === 'brightness') {\n value /= 100;\n }\n return new NumberFormatter(locale, options).format(value);\n }\n\n getColorSpace(): ColorSpace {\n return 'hsb';\n }\n\n static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ['hue', 'saturation', 'brightness'];\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSBColor.colorChannels;\n }\n}\n\n// X = <negative/positive number with/without decimal places>\n// before/after a comma, 0 or more whitespaces are allowed\n// - hsl(X, X%, X%)\n// - hsla(X, X%, X%, X)\nconst HSL_REGEX = /hsl\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsla\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/;\n\nclass HSLColor extends Color {\n constructor(private hue: number, private saturation: number, private lightness: number, private alpha: number) {\n super();\n }\n\n static parse(value: string): HSLColor | void {\n let m: RegExpMatchArray | null;\n if ((m = value.match(HSL_REGEX))) {\n const [h, s, l, a] = (m[1] ?? m[2]).split(',').map(n => Number(n.trim().replace('%', '')));\n return new HSLColor(normalizeHue(h), clamp(s, 0, 100), clamp(l, 0, 100), clamp(a ?? 1, 0, 1));\n }\n }\n\n toString(format: ColorFormat | 'css' = 'css') {\n switch (format) {\n case 'hex':\n return this.toRGB().toString('hex');\n case 'hexa':\n return this.toRGB().toString('hexa');\n case 'hsl':\n return `hsl(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%)`;\n case 'css':\n case 'hsla':\n return `hsla(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%, ${this.alpha})`;\n default:\n return this.toFormat(format).toString(format);\n }\n }\n toFormat(format: ColorFormat): IColor {\n switch (format) {\n case 'hsl':\n case 'hsla':\n return this;\n case 'hsb':\n case 'hsba':\n return this.toHSB();\n case 'rgb':\n case 'rgba':\n return this.toRGB();\n default:\n throw new Error('Unsupported color conversion: hsl -> ' + format);\n }\n }\n\n /**\n * Converts a HSL color to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.\n * @returns An HSBColor object.\n */\n private toHSB(): IColor {\n let saturation = this.saturation / 100;\n let lightness = this.lightness / 100;\n let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);\n saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);\n return new HSBColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n this.alpha\n );\n }\n\n /**\n * Converts a HSL color to RGB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.\n * @returns An RGBColor object.\n */\n private toRGB(): IColor {\n let hue = this.hue;\n let saturation = this.saturation / 100;\n let lightness = this.lightness / 100;\n let a = saturation * Math.min(lightness, 1 - lightness);\n let fn = (n: number, k = (n + hue / 30) % 12) => lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n return new RGBColor(\n Math.round(fn(0) * 255),\n Math.round(fn(8) * 255),\n Math.round(fn(4) * 255),\n this.alpha\n );\n }\n\n clone(): IColor {\n return new HSLColor(this.hue, this.saturation, this.lightness, this.alpha);\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case 'hue':\n return {minValue: 0, maxValue: 360, step: 1, pageSize: 15};\n case 'saturation':\n case 'lightness':\n return {minValue: 0, maxValue: 100, step: 1, pageSize: 10};\n case 'alpha':\n return {minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {\n switch (channel) {\n case 'hue':\n return {style: 'unit', unit: 'degree', unitDisplay: 'narrow'};\n case 'saturation':\n case 'lightness':\n case 'alpha':\n return {style: 'percent'};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n formatChannelValue(channel: ColorChannel, locale: string) {\n let options = this.getChannelFormatOptions(channel);\n let value = this.getChannelValue(channel);\n if (channel === 'saturation' || channel === 'lightness') {\n value /= 100;\n }\n return new NumberFormatter(locale, options).format(value);\n }\n\n getColorSpace(): ColorSpace {\n return 'hsl';\n }\n\n static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ['hue', 'saturation', 'lightness'];\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSLColor.colorChannels;\n }\n}\n\n// https://www.w3.org/TR/css-color-4/#color-conversion-code\nfunction toOKLCH(color: Color) {\n let rgb = color.toFormat('rgb');\n let red = rgb.getChannelValue('red') / 255;\n let green = rgb.getChannelValue('green') / 255;\n let blue = rgb.getChannelValue('blue') / 255;\n [red, green, blue] = lin_sRGB(red, green, blue);\n let [x, y, z] = lin_sRGB_to_XYZ(red, green, blue);\n let [l, a, b] = XYZ_to_OKLab(x, y, z);\n return OKLab_to_OKLCH(l, a, b);\n}\n\nfunction OKLab_to_OKLCH(l: number, a: number, b: number): [number, number, number] {\n var hue = Math.atan2(b, a) * 180 / Math.PI;\n return [\n l,\n Math.sqrt(a ** 2 + b ** 2), // Chroma\n hue >= 0 ? hue : hue + 360 // Hue, in degrees [0 to 360)\n ];\n}\n\nfunction lin_sRGB(r: number, g: number, b: number): [number, number, number] {\n // convert an array of sRGB values\n // where in-gamut values are in the range [0 - 1]\n // to linear light (un-companded) form.\n // https://en.wikipedia.org/wiki/SRGB\n // Extended transfer function:\n // for negative values, linear portion is extended on reflection of axis,\n // then reflected power function is used.\n return [lin_sRGB_component(r), lin_sRGB_component(g), lin_sRGB_component(b)];\n}\n\nfunction lin_sRGB_component(val: number) {\n let sign = val < 0 ? -1 : 1;\n let abs = Math.abs(val);\n\n if (abs <= 0.04045) {\n return val / 12.92;\n }\n\n return sign * (Math.pow((abs + 0.055) / 1.055, 2.4));\n}\n\nfunction lin_sRGB_to_XYZ(r: number, g: number, b: number) {\n // convert an array of linear-light sRGB values to CIE XYZ\n // using sRGB's own white, D65 (no chromatic adaptation)\n const M = [\n 506752 / 1228815, 87881 / 245763, 12673 / 70218,\n 87098 / 409605, 175762 / 245763, 12673 / 175545,\n 7918 / 409605, 87881 / 737289, 1001167 / 1053270\n ];\n return multiplyMatrix(M, r, g, b);\n}\n\nfunction XYZ_to_OKLab(x: number, y: number, z: number) {\n // Given XYZ relative to D65, convert to OKLab\n const XYZtoLMS = [\n 0.8190224379967030, 0.3619062600528904, -0.1288737815209879,\n 0.0329836539323885, 0.9292868615863434, 0.0361446663506424,\n 0.0481771893596242, 0.2642395317527308, 0.6335478284694309\n ];\n const LMStoOKLab = [\n 0.2104542683093140, 0.7936177747023054, -0.0040720430116193,\n 1.9779985324311684, -2.4285922420485799, 0.4505937096174110,\n 0.0259040424655478, 0.7827717124575296, -0.8086757549230774\n ];\n\n let [a, b, c] = multiplyMatrix(XYZtoLMS, x, y, z);\n return multiplyMatrix(LMStoOKLab, Math.cbrt(a), Math.cbrt(b), Math.cbrt(c));\n}\n\nfunction multiplyMatrix(m: number[], x: number, y: number, z: number): [number, number, number] {\n let a = m[0] * x + m[1] * y + m[2] * z;\n let b = m[3] * x + m[4] * y + m[5] * z;\n let c = m[6] * x + m[7] * y + m[8] * z;\n return [a, b, c];\n}\n"],"names":[],"version":3,"file":"Color.mjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAgBD,IAAI,mCAAa,IAAI,CAAA,GAAA,gCAAwB,EAAE,CAAA,GAAA,+CAAW;AAGnD,SAAS,yCAAW,KAAa;IACtC,IAAI,MAAM,+BAAS,KAAK,CAAC,UAAU,+BAAS,KAAK,CAAC,UAAU,+BAAS,KAAK,CAAC;IAC3E,IAAI,KACF,OAAO;IAGT,MAAM,IAAI,MAAM,0BAA0B;AAC5C;AAEO,SAAS,0CAAe,CAAkB;IAC/C,IAAI,OAAO,MAAM,UACf,OAAO,yCAAW;SAElB,OAAO;AAEX;AAGO,SAAS,0CACd,UAAsB;IAEtB,OAAQ;QACN,KAAK;YACH,OAAO,+BAAS,aAAa;QAC/B,KAAK;YACH,OAAO,+BAAS,aAAa;QAC/B,KAAK;YACH,OAAO,+BAAS,aAAa;IACjC;AACF;AAKO,SAAS,0CAAa,GAAW;IACtC,IAAI,QAAQ,KACV,OAAO;IAGT,OAAO,AAAC,CAAA,AAAC,MAAM,MAAO,GAAE,IAAK;AAC/B;AAEA,gDAAgD;AAChD,MAAM,mDAA6B;AACnC,8DAA8D;AAC9D,MAAM,yDAAmC;AACzC,iDAAiD;AACjD,MAAM,2CAAqB;AAC3B,+CAA+C;AAC/C,MAAM,uCAAiB;AACvB,MAAM,mCAAiC;IACrC;QAAC;QAAG;KAAO;IACX;QAAC;QAAI;KAAM;IACX;QAAC;QAAI;KAAS;IACd;QAAC;QAAI;KAAS;IACd;QAAC;QAAK;KAAQ;IACd;QAAC;QAAK;KAAO;IACb;QAAC;QAAK;KAAO;IACb;QAAC;QAAK;KA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CAAgB,CAAS,EAAE,CAAS,EAAE,CAAS;IACtD,0DAA0D;IAC1D,wDAAwD;IACxD,MAAM,IAAI;QACR,SAAS;QACT,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,QAAQ;QACR,OAAO;QACP,QAAQ;QACR,UAAU;KACX;IACD,OAAO,qCAAe,GAAG,GAAG,GAAG;AACjC;AAEA,SAAS,mCAAa,CAAS,EAAE,CAAS,EAAE,CAAS;IACnD,8CAA8C;IAC9C,MAAM,WAAW;QACf;QAAmB;QAAoB;QAAqB;QAC5D;QAAoB;QAAoB;QAAoB;QAC5D;KACD;IACD,MAAM,aAAa;QACjB;QAAmB;QAAoB;QAAqB;QAC5D;QAAqB;QAAmB;QAAoB;QAC5D;KACD;IAED,IAAI,CAAC,GAAG,GAAG,EAAE,GAAG,qCAAe,UAAU,GAAG,GAAG;IAC/C,OAAO,qCAAe,YAAY,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;AAC1E;AAEA,SAAS,qCAAe,CAAW,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IAClE,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG;IACrC,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG;IACrC,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG;IACrC,OAAO;QAAC;QAAG;QAAG;KAAE;AAClB","sources":["packages/react-stately/src/color/Color.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, toFixedNumber} from '../utils/number';\nimport {\n ColorAxes,\n ColorChannel,\n ColorChannelRange,\n ColorFormat,\n ColorSpace,\n Color as IColor\n} from './types';\n// @ts-ignore\nimport intlMessages from '../../intl/color/*.json';\nimport {LocalizedStringDictionary, LocalizedStringFormatter} from '@internationalized/string';\nimport {NumberFormatter} from '@internationalized/number';\n\nlet dictionary = new LocalizedStringDictionary(intlMessages);\n\n/** Parses a color from a string value. Throws an error if the string could not be parsed. */\nexport function parseColor(value: string): IColor {\n let res = RGBColor.parse(value) || HSBColor.parse(value) || HSLColor.parse(value);\n if (res) {\n return res;\n }\n\n throw new Error('Invalid color value: ' + value);\n}\n\nexport function normalizeColor(v: string | IColor): IColor {\n if (typeof v === 'string') {\n return parseColor(v);\n } else {\n return v;\n }\n}\n\n/** Returns a list of color channels for a given color space. */\nexport function getColorChannels(\n colorSpace: ColorSpace\n): [ColorChannel, ColorChannel, ColorChannel] {\n switch (colorSpace) {\n case 'rgb':\n return RGBColor.colorChannels;\n case 'hsl':\n return HSLColor.colorChannels;\n case 'hsb':\n return HSBColor.colorChannels;\n }\n}\n\n/**\n * Returns the hue value normalized to the range of 0 to 360.\n */\nexport function normalizeHue(hue: number): number {\n if (hue === 360) {\n return hue;\n }\n\n return ((hue % 360) + 360) % 360;\n}\n\n// Lightness threshold between orange and brown.\nconst ORANGE_LIGHTNESS_THRESHOLD = 0.68;\n// Lightness threshold between pure yellow and \"yellow green\".\nconst YELLOW_GREEN_LIGHTNESS_THRESHOLD = 0.85;\n// The maximum lightness considered to be \"dark\".\nconst MAX_DARK_LIGHTNESS = 0.55;\n// The chroma threshold between gray and color.\nconst GRAY_THRESHOLD = 0.001;\nconst OKLCH_HUES: [number, string][] = [\n [0, 'pink'],\n [15, 'red'],\n [48, 'orange'],\n [94, 'yellow'],\n [135, 'green'],\n [175, 'cyan'],\n [264, 'blue'],\n [284, 'purple'],\n [320, 'magenta'],\n [349, 'pink']\n];\n\nabstract class Color implements IColor {\n abstract toFormat(format: ColorFormat): IColor;\n abstract toString(format: ColorFormat | 'css'): string;\n abstract clone(): IColor;\n abstract getChannelRange(channel: ColorChannel): ColorChannelRange;\n abstract getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;\n abstract formatChannelValue(channel: ColorChannel, locale: string): string;\n\n toHexInt(): number {\n return this.toFormat('rgb').toHexInt();\n }\n\n getChannelValue(channel: ColorChannel): number {\n if (channel in this) {\n return this[channel];\n }\n\n throw new Error('Unsupported color channel: ' + channel);\n }\n\n withChannelValue(channel: ColorChannel, value: number): IColor {\n if (channel in this) {\n let x = this.clone();\n x[channel] = value;\n return x;\n }\n\n throw new Error('Unsupported color channel: ' + channel);\n }\n\n getChannelName(channel: ColorChannel, locale: string) {\n let strings =\n LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;\n return strings.getStringForLocale(channel, locale);\n }\n\n abstract getColorSpace(): ColorSpace;\n\n getColorSpaceAxes(xyChannels: {xChannel?: ColorChannel; yChannel?: ColorChannel}): ColorAxes {\n let {xChannel, yChannel} = xyChannels;\n let xCh = xChannel || this.getColorChannels().find(c => c !== yChannel)!;\n let yCh = yChannel || this.getColorChannels().find(c => c !== xCh)!;\n let zCh = this.getColorChannels().find(c => c !== xCh && c !== yCh)!;\n\n return {xChannel: xCh, yChannel: yCh, zChannel: zCh};\n }\n\n abstract getColorChannels(): [ColorChannel, ColorChannel, ColorChannel];\n\n getColorName(locale: string): string {\n // Convert to oklch color space, which has perceptually uniform lightness across all hues.\n let [l, c, h] = toOKLCH(this);\n\n let strings =\n LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;\n if (l > 0.999) {\n return strings.getStringForLocale('white', locale);\n }\n\n if (l < 0.001) {\n return strings.getStringForLocale('black', locale);\n }\n\n let hue: string;\n [hue, l] = this.getOklchHue(l, c, h, locale);\n\n let lightness = '';\n let chroma = '';\n if (c <= 0.1 && c >= GRAY_THRESHOLD) {\n if (l >= 0.7) {\n chroma = 'pale';\n } else {\n chroma = 'grayish';\n }\n } else if (c >= 0.15) {\n chroma = 'vibrant';\n }\n\n if (l < 0.3) {\n lightness = 'very dark';\n } else if (l < MAX_DARK_LIGHTNESS) {\n lightness = 'dark';\n } else if (l < 0.7) {\n // none\n } else if (l < 0.85) {\n lightness = 'light';\n } else {\n lightness = 'very light';\n }\n\n if (chroma) {\n chroma = strings.getStringForLocale(chroma, locale);\n }\n\n if (lightness) {\n lightness = strings.getStringForLocale(lightness, locale);\n }\n\n let alpha = this.getChannelValue('alpha');\n let formatter = new LocalizedStringFormatter(locale, strings);\n if (alpha < 1) {\n let percentTransparent = new NumberFormatter(locale, {style: 'percent'}).format(1 - alpha);\n return formatter\n .format('transparentColorName', {\n lightness,\n chroma,\n hue,\n percentTransparent\n })\n .replace(/\\s+/g, ' ')\n .trim();\n } else {\n return formatter\n .format('colorName', {\n lightness,\n chroma,\n hue\n })\n .replace(/\\s+/g, ' ')\n .trim();\n }\n }\n\n private getOklchHue(l: number, c: number, h: number, locale: string): [string, number] {\n let strings =\n LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/color') || dictionary;\n if (c < GRAY_THRESHOLD) {\n return [strings.getStringForLocale('gray', locale), l];\n }\n\n for (let i = 0; i < OKLCH_HUES.length; i++) {\n let [hue, hueName] = OKLCH_HUES[i];\n let [nextHue, nextHueName] = OKLCH_HUES[i + 1] || [360, 'pink'];\n if (h >= hue && h < nextHue) {\n // Split orange hue into brown/orange depending on lightness.\n if (hueName === 'orange') {\n if (l < ORANGE_LIGHTNESS_THRESHOLD) {\n hueName = 'brown';\n } else {\n // Adjust lightness.\n l = l - ORANGE_LIGHTNESS_THRESHOLD + MAX_DARK_LIGHTNESS;\n }\n }\n\n // If the hue is at least halfway to the next hue, add the next hue name as well.\n if (h > hue + (nextHue - hue) / 2 && hueName !== nextHueName) {\n hueName = `${hueName} ${nextHueName}`;\n } else if (hueName === 'yellow' && l < YELLOW_GREEN_LIGHTNESS_THRESHOLD) {\n // Yellow shifts toward green at lower lightnesses.\n hueName = 'yellow green';\n }\n\n let name = strings.getStringForLocale(hueName, locale).toLocaleLowerCase(locale);\n return [name, l];\n }\n }\n\n throw new Error('Unexpected hue');\n }\n\n getHueName(locale: string): string {\n let [l, c, h] = toOKLCH(this);\n let [name] = this.getOklchHue(l, c, h, locale);\n return name;\n }\n}\n\nclass RGBColor extends Color {\n constructor(\n private red: number,\n private green: number,\n private blue: number,\n private alpha: number\n ) {\n super();\n }\n\n static parse(value: string) {\n let colors: Array<number | undefined> = [];\n // matching #rgb, #rgba, #rrggbb, #rrggbbaa\n if (/^#[\\da-f]+$/i.test(value) && [4, 5, 7, 9].includes(value.length)) {\n const values = (value.length < 6 ? value.replace(/[^#]/gi, '$&$&') : value)\n .slice(1)\n .split('');\n while (values.length > 0) {\n colors.push(parseInt(values.splice(0, 2).join(''), 16));\n }\n colors[3] = colors[3] !== undefined ? colors[3] / 255 : undefined;\n }\n\n // matching rgb(rrr, ggg, bbb), rgba(rrr, ggg, bbb, 0.a)\n const match = value.match(/^rgba?\\((.*)\\)$/);\n if (match?.[1]) {\n colors = match[1].split(',').map(value => Number(value.trim()));\n colors = colors.map((num, i) => {\n return clamp(num ?? 0, 0, i < 3 ? 255 : 1);\n });\n }\n if (colors[0] === undefined || colors[1] === undefined || colors[2] === undefined) {\n return undefined;\n }\n\n return colors.length < 3\n ? undefined\n : new RGBColor(colors[0], colors[1], colors[2], colors[3] ?? 1);\n }\n\n toString(format: ColorFormat | 'css' = 'css') {\n switch (format) {\n case 'hex':\n return (\n '#' +\n (\n this.red.toString(16).padStart(2, '0') +\n this.green.toString(16).padStart(2, '0') +\n this.blue.toString(16).padStart(2, '0')\n ).toUpperCase()\n );\n case 'hexa':\n return (\n '#' +\n (\n this.red.toString(16).padStart(2, '0') +\n this.green.toString(16).padStart(2, '0') +\n this.blue.toString(16).padStart(2, '0') +\n Math.round(this.alpha * 255)\n .toString(16)\n .padStart(2, '0')\n ).toUpperCase()\n );\n case 'rgb':\n return `rgb(${this.red}, ${this.green}, ${this.blue})`;\n case 'css':\n case 'rgba':\n return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;\n default:\n return this.toFormat(format).toString(format);\n }\n }\n\n toFormat(format: ColorFormat): IColor {\n switch (format) {\n case 'hex':\n case 'hexa':\n case 'rgb':\n case 'rgba':\n return this;\n case 'hsb':\n case 'hsba':\n return this.toHSB();\n case 'hsl':\n case 'hsla':\n return this.toHSL();\n default:\n throw new Error('Unsupported color conversion: rgb -> ' + format);\n }\n }\n\n toHexInt(): number {\n return (this.red << 16) | (this.green << 8) | this.blue;\n }\n\n /**\n * Converts an RGB color value to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n *\n * @returns An HSBColor object.\n */\n private toHSB(): IColor {\n const red = this.red / 255;\n const green = this.green / 255;\n const blue = this.blue / 255;\n const min = Math.min(red, green, blue);\n const brightness = Math.max(red, green, blue);\n const chroma = brightness - min;\n const saturation = brightness === 0 ? 0 : chroma / brightness;\n let hue = 0; // achromatic\n\n if (chroma !== 0) {\n switch (brightness) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0);\n break;\n case green:\n hue = (blue - red) / chroma + 2;\n break;\n case blue:\n hue = (red - green) / chroma + 4;\n break;\n }\n\n hue /= 6;\n }\n\n return new HSBColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n this.alpha\n );\n }\n\n /**\n * Converts an RGB color value to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#From_RGB.\n *\n * @returns An HSLColor object.\n */\n private toHSL(): IColor {\n const red = this.red / 255;\n const green = this.green / 255;\n const blue = this.blue / 255;\n const min = Math.min(red, green, blue);\n const max = Math.max(red, green, blue);\n const lightness = (max + min) / 2;\n const chroma = max - min;\n let hue: number;\n let saturation: number;\n\n if (chroma === 0) {\n hue = saturation = 0; // achromatic\n } else {\n saturation = chroma / (lightness < 0.5 ? max + min : 2 - max - min);\n\n switch (max) {\n case red:\n hue = (green - blue) / chroma + (green < blue ? 6 : 0);\n break;\n case green:\n hue = (blue - red) / chroma + 2;\n break;\n case blue:\n default:\n hue = (red - green) / chroma + 4;\n break;\n }\n\n hue /= 6;\n }\n\n return new HSLColor(\n toFixedNumber(hue * 360, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n this.alpha\n );\n }\n\n clone(): IColor {\n return new RGBColor(this.red, this.green, this.blue, this.alpha);\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case 'red':\n case 'green':\n case 'blue':\n return {minValue: 0x0, maxValue: 0xff, step: 0x1, pageSize: 0x11};\n case 'alpha':\n return {minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {\n switch (channel) {\n case 'red':\n case 'green':\n case 'blue':\n return {style: 'decimal'};\n case 'alpha':\n return {style: 'percent'};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n formatChannelValue(channel: ColorChannel, locale: string) {\n let options = this.getChannelFormatOptions(channel);\n let value = this.getChannelValue(channel);\n return new NumberFormatter(locale, options).format(value);\n }\n\n getColorSpace(): ColorSpace {\n return 'rgb';\n }\n\n static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = ['red', 'green', 'blue'];\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return RGBColor.colorChannels;\n }\n}\n\n// X = <negative/positive number with/without decimal places>\n// before/after a comma, 0 or more whitespaces are allowed\n// - hsb(X, X%, X%)\n// - hsba(X, X%, X%, X)\nconst HSB_REGEX =\n /hsb\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsba\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/;\n\nclass HSBColor extends Color {\n constructor(\n private hue: number,\n private saturation: number,\n private brightness: number,\n private alpha: number\n ) {\n super();\n }\n\n static parse(value: string): HSBColor | void {\n let m: RegExpMatchArray | null;\n if ((m = value.match(HSB_REGEX))) {\n const [h, s, b, a] = (m[1] ?? m[2]).split(',').map(n => Number(n.trim().replace('%', '')));\n return new HSBColor(normalizeHue(h), clamp(s, 0, 100), clamp(b, 0, 100), clamp(a ?? 1, 0, 1));\n }\n }\n\n toString(format: ColorFormat | 'css' = 'css') {\n switch (format) {\n case 'css':\n return this.toHSL().toString('css');\n case 'hex':\n return this.toRGB().toString('hex');\n case 'hexa':\n return this.toRGB().toString('hexa');\n case 'hsb':\n return `hsb(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%)`;\n case 'hsba':\n return `hsba(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.brightness, 2)}%, ${this.alpha})`;\n default:\n return this.toFormat(format).toString(format);\n }\n }\n\n toFormat(format: ColorFormat): IColor {\n switch (format) {\n case 'hsb':\n case 'hsba':\n return this;\n case 'hsl':\n case 'hsla':\n return this.toHSL();\n case 'rgb':\n case 'rgba':\n return this.toRGB();\n default:\n throw new Error('Unsupported color conversion: hsb -> ' + format);\n }\n }\n\n /**\n * Converts a HSB color to HSL.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_HSL.\n *\n * @returns An HSLColor object.\n */\n private toHSL(): IColor {\n let saturation = this.saturation / 100;\n let brightness = this.brightness / 100;\n let lightness = brightness * (1 - saturation / 2);\n saturation =\n lightness === 0 || lightness === 1\n ? 0\n : (brightness - lightness) / Math.min(lightness, 1 - lightness);\n\n return new HSLColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(lightness * 100, 2),\n this.alpha\n );\n }\n\n /**\n * Converts a HSV color value to RGB. Conversion formula adapted from\n * https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB_alternative.\n *\n * @returns An RGBColor object.\n */\n private toRGB(): IColor {\n let hue = this.hue;\n let saturation = this.saturation / 100;\n let brightness = this.brightness / 100;\n let fn = (n: number, k = (n + hue / 60) % 6) =>\n brightness - saturation * brightness * Math.max(Math.min(k, 4 - k, 1), 0);\n return new RGBColor(\n Math.round(fn(5) * 255),\n Math.round(fn(3) * 255),\n Math.round(fn(1) * 255),\n this.alpha\n );\n }\n\n clone(): IColor {\n return new HSBColor(this.hue, this.saturation, this.brightness, this.alpha);\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case 'hue':\n return {minValue: 0, maxValue: 360, step: 1, pageSize: 15};\n case 'saturation':\n case 'brightness':\n return {minValue: 0, maxValue: 100, step: 1, pageSize: 10};\n case 'alpha':\n return {minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {\n switch (channel) {\n case 'hue':\n return {style: 'unit', unit: 'degree', unitDisplay: 'narrow'};\n case 'saturation':\n case 'brightness':\n case 'alpha':\n return {style: 'percent'};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n formatChannelValue(channel: ColorChannel, locale: string) {\n let options = this.getChannelFormatOptions(channel);\n let value = this.getChannelValue(channel);\n if (channel === 'saturation' || channel === 'brightness') {\n value /= 100;\n }\n return new NumberFormatter(locale, options).format(value);\n }\n\n getColorSpace(): ColorSpace {\n return 'hsb';\n }\n\n static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\n 'hue',\n 'saturation',\n 'brightness'\n ];\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSBColor.colorChannels;\n }\n}\n\n// X = <negative/positive number with/without decimal places>\n// before/after a comma, 0 or more whitespaces are allowed\n// - hsl(X, X%, X%)\n// - hsla(X, X%, X%, X)\nconst HSL_REGEX =\n /hsl\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%)\\)|hsla\\(([-+]?\\d+(?:.\\d+)?\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d+(?:.\\d+)?%\\s*,\\s*[-+]?\\d(.\\d+)?)\\)/;\n\nclass HSLColor extends Color {\n constructor(\n private hue: number,\n private saturation: number,\n private lightness: number,\n private alpha: number\n ) {\n super();\n }\n\n static parse(value: string): HSLColor | void {\n let m: RegExpMatchArray | null;\n if ((m = value.match(HSL_REGEX))) {\n const [h, s, l, a] = (m[1] ?? m[2]).split(',').map(n => Number(n.trim().replace('%', '')));\n return new HSLColor(normalizeHue(h), clamp(s, 0, 100), clamp(l, 0, 100), clamp(a ?? 1, 0, 1));\n }\n }\n\n toString(format: ColorFormat | 'css' = 'css') {\n switch (format) {\n case 'hex':\n return this.toRGB().toString('hex');\n case 'hexa':\n return this.toRGB().toString('hexa');\n case 'hsl':\n return `hsl(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%)`;\n case 'css':\n case 'hsla':\n return `hsla(${this.hue}, ${toFixedNumber(this.saturation, 2)}%, ${toFixedNumber(this.lightness, 2)}%, ${this.alpha})`;\n default:\n return this.toFormat(format).toString(format);\n }\n }\n toFormat(format: ColorFormat): IColor {\n switch (format) {\n case 'hsl':\n case 'hsla':\n return this;\n case 'hsb':\n case 'hsba':\n return this.toHSB();\n case 'rgb':\n case 'rgba':\n return this.toRGB();\n default:\n throw new Error('Unsupported color conversion: hsl -> ' + format);\n }\n }\n\n /**\n * Converts a HSL color to HSB.\n * Conversion formula adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_HSV.\n *\n * @returns An HSBColor object.\n */\n private toHSB(): IColor {\n let saturation = this.saturation / 100;\n let lightness = this.lightness / 100;\n let brightness = lightness + saturation * Math.min(lightness, 1 - lightness);\n saturation = brightness === 0 ? 0 : 2 * (1 - lightness / brightness);\n return new HSBColor(\n toFixedNumber(this.hue, 2),\n toFixedNumber(saturation * 100, 2),\n toFixedNumber(brightness * 100, 2),\n this.alpha\n );\n }\n\n /**\n * Converts a HSL color to RGB. Conversion formula adapted from\n * https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative.\n *\n * @returns An RGBColor object.\n */\n private toRGB(): IColor {\n let hue = this.hue;\n let saturation = this.saturation / 100;\n let lightness = this.lightness / 100;\n let a = saturation * Math.min(lightness, 1 - lightness);\n let fn = (n: number, k = (n + hue / 30) % 12) =>\n lightness - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n return new RGBColor(\n Math.round(fn(0) * 255),\n Math.round(fn(8) * 255),\n Math.round(fn(4) * 255),\n this.alpha\n );\n }\n\n clone(): IColor {\n return new HSLColor(this.hue, this.saturation, this.lightness, this.alpha);\n }\n\n getChannelRange(channel: ColorChannel): ColorChannelRange {\n switch (channel) {\n case 'hue':\n return {minValue: 0, maxValue: 360, step: 1, pageSize: 15};\n case 'saturation':\n case 'lightness':\n return {minValue: 0, maxValue: 100, step: 1, pageSize: 10};\n case 'alpha':\n return {minValue: 0, maxValue: 1, step: 0.01, pageSize: 0.1};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions {\n switch (channel) {\n case 'hue':\n return {style: 'unit', unit: 'degree', unitDisplay: 'narrow'};\n case 'saturation':\n case 'lightness':\n case 'alpha':\n return {style: 'percent'};\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n }\n\n formatChannelValue(channel: ColorChannel, locale: string) {\n let options = this.getChannelFormatOptions(channel);\n let value = this.getChannelValue(channel);\n if (channel === 'saturation' || channel === 'lightness') {\n value /= 100;\n }\n return new NumberFormatter(locale, options).format(value);\n }\n\n getColorSpace(): ColorSpace {\n return 'hsl';\n }\n\n static colorChannels: [ColorChannel, ColorChannel, ColorChannel] = [\n 'hue',\n 'saturation',\n 'lightness'\n ];\n getColorChannels(): [ColorChannel, ColorChannel, ColorChannel] {\n return HSLColor.colorChannels;\n }\n}\n\n// https://www.w3.org/TR/css-color-4/#color-conversion-code\nfunction toOKLCH(color: Color) {\n let rgb = color.toFormat('rgb');\n let red = rgb.getChannelValue('red') / 255;\n let green = rgb.getChannelValue('green') / 255;\n let blue = rgb.getChannelValue('blue') / 255;\n [red, green, blue] = lin_sRGB(red, green, blue);\n let [x, y, z] = lin_sRGB_to_XYZ(red, green, blue);\n let [l, a, b] = XYZ_to_OKLab(x, y, z);\n return OKLab_to_OKLCH(l, a, b);\n}\n\nfunction OKLab_to_OKLCH(l: number, a: number, b: number): [number, number, number] {\n var hue = (Math.atan2(b, a) * 180) / Math.PI;\n return [\n l,\n Math.sqrt(a ** 2 + b ** 2), // Chroma\n hue >= 0 ? hue : hue + 360 // Hue, in degrees [0 to 360)\n ];\n}\n\nfunction lin_sRGB(r: number, g: number, b: number): [number, number, number] {\n // convert an array of sRGB values\n // where in-gamut values are in the range [0 - 1]\n // to linear light (un-companded) form.\n // https://en.wikipedia.org/wiki/SRGB\n // Extended transfer function:\n // for negative values, linear portion is extended on reflection of axis,\n // then reflected power function is used.\n return [lin_sRGB_component(r), lin_sRGB_component(g), lin_sRGB_component(b)];\n}\n\nfunction lin_sRGB_component(val: number) {\n let sign = val < 0 ? -1 : 1;\n let abs = Math.abs(val);\n\n if (abs <= 0.04045) {\n return val / 12.92;\n }\n\n return sign * Math.pow((abs + 0.055) / 1.055, 2.4);\n}\n\nfunction lin_sRGB_to_XYZ(r: number, g: number, b: number) {\n // convert an array of linear-light sRGB values to CIE XYZ\n // using sRGB's own white, D65 (no chromatic adaptation)\n const M = [\n 506752 / 1228815,\n 87881 / 245763,\n 12673 / 70218,\n 87098 / 409605,\n 175762 / 245763,\n 12673 / 175545,\n 7918 / 409605,\n 87881 / 737289,\n 1001167 / 1053270\n ];\n return multiplyMatrix(M, r, g, b);\n}\n\nfunction XYZ_to_OKLab(x: number, y: number, z: number) {\n // Given XYZ relative to D65, convert to OKLab\n const XYZtoLMS = [\n 0.819022437996703, 0.3619062600528904, -0.1288737815209879, 0.0329836539323885,\n 0.9292868615863434, 0.0361446663506424, 0.0481771893596242, 0.2642395317527308,\n 0.6335478284694309\n ];\n const LMStoOKLab = [\n 0.210454268309314, 0.7936177747023054, -0.0040720430116193, 1.9779985324311684,\n -2.4285922420485799, 0.450593709617411, 0.0259040424655478, 0.7827717124575296,\n -0.8086757549230774\n ];\n\n let [a, b, c] = multiplyMatrix(XYZtoLMS, x, y, z);\n return multiplyMatrix(LMStoOKLab, Math.cbrt(a), Math.cbrt(b), Math.cbrt(c));\n}\n\nfunction multiplyMatrix(m: number[], x: number, y: number, z: number): [number, number, number] {\n let a = m[0] * x + m[1] * y + m[2] * z;\n let b = m[3] * x + m[4] * y + m[5] * z;\n let c = m[6] * x + m[7] * y + m[8] * z;\n return [a, b, c];\n}\n"],"names":[],"version":3,"file":"Color.mjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiFD,MAAM,sCAAgB,CAAA,GAAA,oCAAS,EAAE;AAK1B,SAAS,0CAAkB,KAAqB;IACrD,IAAI,SACF,KAAK,gBACL,YAAY,cACZ,UAAU,YACV,QAAQ,YACR,QAAQ,YACR,QAAQ,eACR,WAAW,EACZ,GAAG;IAEJ,IAAI,CAAC,SAAS,CAAC,cACb,eAAe;IAEjB,IAAI,OACF,QAAQ,CAAA,GAAA,w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AA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACjH;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,aAAY,UAAU;YACpB,IAAI,cAAc,cAAc,OAAO;YACvC,cAAc,OAAO,GAAG;YAExB,IAAI,eAAe,CAAC,cAAc,aAChC,YAAY,SAAS,OAAO;YAG9B,YAAY;QACd;oBACA;QACA;YACE,OAAO,MAAM,gBAAgB,CAAC,SAAS;QACzC;IACF;AACF","sources":["packages/react-stately/src/color/useColorAreaState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {Color, ColorChannel, ColorSpace} from './types';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useRef, useState} from 'react';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorAreaProps extends Omit<ValueBase<string | Color>, 'onChange'> {\n /**\n * The color space that the color area operates in. The `xChannel` and `yChannel` must be in this color space.\n * If not provided, this defaults to the color space of the `color` or `defaultColor` value.\n */\n colorSpace?: ColorSpace,\n /** Color channel for the horizontal axis. */\n xChannel?: ColorChannel,\n /** Color channel for the vertical axis. */\n yChannel?: ColorChannel,\n /** Whether the ColorArea is disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the value changes, as the user drags. */\n onChange?: (value: Color) => void,\n /** Handler that is called when the user stops dragging. */\n onChangeEnd?: (value: Color) => void\n}\n\nexport interface ColorAreaState {\n /** The current color value displayed by the color area. */\n readonly value: Color,\n /** The default value of the color area. */\n readonly defaultValue: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n\n /** The current value of the horizontal axis channel displayed by the color area. */\n xValue: number,\n /** Sets the value for the horizontal axis channel displayed by the color area, and triggers `onChange`. */\n setXValue(value: number): void,\n\n /** The current value of the vertical axis channel displayed by the color area. */\n yValue: number,\n /** Sets the value for the vertical axis channel displayed by the color area, and triggers `onChange`. */\n setYValue(value: number): void,\n\n /** Sets the x and y channels of the current color value based on a percentage of the width and height of the color area, and triggers `onChange`. */\n setColorFromPoint(x: number, y: number): void,\n /** Returns the coordinates of the thumb relative to the upper left corner of the color area as a percentage. */\n getThumbPosition(): {x: number, y: number},\n\n /** Increments the value of the horizontal axis channel by the channel step or page amount. */\n incrementX(stepSize?: number): void,\n /** Decrements the value of the horizontal axis channel by the channel step or page amount. */\n decrementX(stepSize?: number): void,\n\n /** Increments the value of the vertical axis channel by the channel step or page amount. */\n incrementY(stepSize?: number): void,\n /** Decrements the value of the vertical axis channel by the channel step or page amount. */\n decrementY(stepSize?: number): void,\n\n /** Whether the color area is currently being dragged. */\n readonly isDragging: boolean,\n /** Sets whether the color area is being dragged. */\n setDragging(value: boolean): void,\n\n /** Returns the xChannel, yChannel and zChannel names based on the color value. */\n channels: {xChannel: ColorChannel, yChannel: ColorChannel, zChannel: ColorChannel},\n /** The step value of the xChannel, used when incrementing and decrementing. */\n xChannelStep: number,\n /** The step value of the yChannel, used when incrementing and decrementing. */\n yChannelStep: number,\n /** The page step value of the xChannel, used when incrementing and decrementing. */\n xChannelPageStep: number,\n /** The page step value of the yChannel, used when incrementing and decrementing. */\n yChannelPageStep: number,\n\n /** Returns the color that should be displayed in the color area thumb instead of `value`. */\n getDisplayColor(): Color\n}\n\nconst DEFAULT_COLOR = parseColor('#ffffff');\n/**\n * Provides state management for a color area component.\n * Color area allows users to adjust two channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.\n */\nexport function useColorAreaState(props: ColorAreaProps): ColorAreaState {\n let {\n value,\n defaultValue,\n colorSpace,\n xChannel,\n yChannel,\n onChange,\n onChangeEnd\n } = props;\n\n if (!value && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [colorValue, setColorState] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);\n let [initialValue] = useState(colorValue);\n let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);\n let valueRef = useRef(color);\n let setColor = (color: Color) => {\n valueRef.current = color;\n setColorState(color);\n };\n\n let channels = useMemo(() =>\n color.getColorSpaceAxes({xChannel, yChannel}),\n [color, xChannel, yChannel]\n );\n\n let xChannelRange = color.getChannelRange(channels.xChannel);\n let yChannelRange = color.getChannelRange(channels.yChannel);\n let {minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX} = xChannelRange;\n let {minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY} = yChannelRange;\n\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let xValue = color.getChannelValue(channels.xChannel);\n let yValue = color.getChannelValue(channels.yChannel);\n let setXValue = (v: number) => {\n if (v === xValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.xChannel, v);\n setColor(newColor);\n };\n let setYValue = (v: number) => {\n if (v === yValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.yChannel, v);\n setColor(newColor);\n };\n\n return {\n channels,\n xChannelStep: stepX,\n yChannelStep: stepY,\n xChannelPageStep: pageSizeX,\n yChannelPageStep: pageSizeY,\n value: color,\n defaultValue: value !== undefined ? initialValue : defaultValue as Color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n xValue,\n setXValue,\n yValue,\n setYValue,\n setColorFromPoint(x: number, y: number) {\n let newXValue = minValueX + clamp(x, 0, 1) * (maxValueX - minValueX);\n let newYValue = minValueY + (1 - clamp(y, 0, 1)) * (maxValueY - minValueY);\n let newColor: Color | undefined;\n if (newXValue !== xValue) {\n // Round new value to multiple of step, clamp value between min and max\n newXValue = snapValueToStep(newXValue, minValueX, maxValueX, stepX);\n newColor = color.withChannelValue(channels.xChannel, newXValue);\n }\n if (newYValue !== yValue) {\n // Round new value to multiple of step, clamp value between min and max\n newYValue = snapValueToStep(newYValue, minValueY, maxValueY, stepY);\n newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);\n }\n if (newColor) {\n setColor(newColor);\n }\n },\n getThumbPosition() {\n let x = (xValue - minValueX) / (maxValueX - minValueX);\n let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);\n return {x, y};\n },\n incrementX(stepSize = 1) {\n setXValue(xValue + stepSize > maxValueX ? maxValueX : snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX));\n },\n incrementY(stepSize = 1) {\n setYValue(yValue + stepSize > maxValueY ? maxValueY : snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY));\n },\n decrementX(stepSize = 1) {\n setXValue(snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));\n },\n decrementY(stepSize = 1) {\n setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return color.withChannelValue('alpha', 1);\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorAreaState.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAU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,IAAI,AAAC,CAAA,SAAS,SAAQ,IAAM,CAAA,YAAY,SAAQ;YACxD,OAAO;mBAAC;mBAAG;YAAC;QACd;QACA,YAAW,WAAW,CAAC;YACrB,UACE,SAAS,WAAW,YAChB,YACA,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QAEjE;QACA,YAAW,WAAW,CAAC;YACrB,UACE,SAAS,WAAW,YAChB,YACA,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QAEjE;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,aAAY,UAAU;YACpB,IAAI,cAAc,cAAc,OAAO;YACvC,cAAc,OAAO,GAAG;YAExB,IAAI,eAAe,CAAC,cAAc,aAChC,YAAY,SAAS,OAAO;YAG9B,YAAY;QACd;oBACA;QACA;YACE,OAAO,MAAM,gBAAgB,CAAC,SAAS;QACzC;IACF;AACF","sources":["packages/react-stately/src/color/useColorAreaState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {Color, ColorChannel, ColorSpace} from './types';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useRef, useState} from 'react';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorAreaProps extends Omit<ValueBase<string | Color>, 'onChange'> {\n /**\n * The color space that the color area operates in. The `xChannel` and `yChannel` must be in this\n * color space. If not provided, this defaults to the color space of the `color` or `defaultColor`\n * value.\n */\n colorSpace?: ColorSpace;\n /** Color channel for the horizontal axis. */\n xChannel?: ColorChannel;\n /** Color channel for the vertical axis. */\n yChannel?: ColorChannel;\n /** Whether the ColorArea is disabled. */\n isDisabled?: boolean;\n /** Handler that is called when the value changes, as the user drags. */\n onChange?: (value: Color) => void;\n /** Handler that is called when the user stops dragging. */\n onChangeEnd?: (value: Color) => void;\n}\n\nexport interface ColorAreaState {\n /** The current color value displayed by the color area. */\n readonly value: Color;\n /** The default value of the color area. */\n readonly defaultValue: Color;\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void;\n\n /** The current value of the horizontal axis channel displayed by the color area. */\n xValue: number;\n /**\n * Sets the value for the horizontal axis channel displayed by the color area, and triggers\n * `onChange`.\n */\n setXValue(value: number): void;\n\n /** The current value of the vertical axis channel displayed by the color area. */\n yValue: number;\n /**\n * Sets the value for the vertical axis channel displayed by the color area, and triggers\n * `onChange`.\n */\n setYValue(value: number): void;\n\n /**\n * Sets the x and y channels of the current color value based on a percentage of the width and\n * height of the color area, and triggers `onChange`.\n */\n setColorFromPoint(x: number, y: number): void;\n /**\n * Returns the coordinates of the thumb relative to the upper left corner of the color area as a\n * percentage.\n */\n getThumbPosition(): {x: number; y: number};\n\n /** Increments the value of the horizontal axis channel by the channel step or page amount. */\n incrementX(stepSize?: number): void;\n /** Decrements the value of the horizontal axis channel by the channel step or page amount. */\n decrementX(stepSize?: number): void;\n\n /** Increments the value of the vertical axis channel by the channel step or page amount. */\n incrementY(stepSize?: number): void;\n /** Decrements the value of the vertical axis channel by the channel step or page amount. */\n decrementY(stepSize?: number): void;\n\n /** Whether the color area is currently being dragged. */\n readonly isDragging: boolean;\n /** Sets whether the color area is being dragged. */\n setDragging(value: boolean): void;\n\n /** Returns the xChannel, yChannel and zChannel names based on the color value. */\n channels: {xChannel: ColorChannel; yChannel: ColorChannel; zChannel: ColorChannel};\n /** The step value of the xChannel, used when incrementing and decrementing. */\n xChannelStep: number;\n /** The step value of the yChannel, used when incrementing and decrementing. */\n yChannelStep: number;\n /** The page step value of the xChannel, used when incrementing and decrementing. */\n xChannelPageStep: number;\n /** The page step value of the yChannel, used when incrementing and decrementing. */\n yChannelPageStep: number;\n\n /** Returns the color that should be displayed in the color area thumb instead of `value`. */\n getDisplayColor(): Color;\n}\n\nconst DEFAULT_COLOR = parseColor('#ffffff');\n/**\n * Provides state management for a color area component. Color area allows users to adjust two\n * channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.\n */\nexport function useColorAreaState(props: ColorAreaProps): ColorAreaState {\n let {value, defaultValue, colorSpace, xChannel, yChannel, onChange, onChangeEnd} = props;\n\n if (!value && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [colorValue, setColorState] = useControlledState<Color>(\n value as Color,\n defaultValue as Color,\n onChange\n );\n let [initialValue] = useState(colorValue);\n let color = useMemo(\n () => (colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue),\n [colorValue, colorSpace]\n );\n let valueRef = useRef(color);\n let setColor = (color: Color) => {\n valueRef.current = color;\n setColorState(color);\n };\n\n let channels = useMemo(\n () => color.getColorSpaceAxes({xChannel, yChannel}),\n [color, xChannel, yChannel]\n );\n\n let xChannelRange = color.getChannelRange(channels.xChannel);\n let yChannelRange = color.getChannelRange(channels.yChannel);\n let {minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX} = xChannelRange;\n let {minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY} = yChannelRange;\n\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let xValue = color.getChannelValue(channels.xChannel);\n let yValue = color.getChannelValue(channels.yChannel);\n let setXValue = (v: number) => {\n if (v === xValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.xChannel, v);\n setColor(newColor);\n };\n let setYValue = (v: number) => {\n if (v === yValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.yChannel, v);\n setColor(newColor);\n };\n\n return {\n channels,\n xChannelStep: stepX,\n yChannelStep: stepY,\n xChannelPageStep: pageSizeX,\n yChannelPageStep: pageSizeY,\n value: color,\n defaultValue: value !== undefined ? initialValue : (defaultValue as Color),\n setValue(value) {\n setColor(normalizeColor(value));\n },\n xValue,\n setXValue,\n yValue,\n setYValue,\n setColorFromPoint(x: number, y: number) {\n let newXValue = minValueX + clamp(x, 0, 1) * (maxValueX - minValueX);\n let newYValue = minValueY + (1 - clamp(y, 0, 1)) * (maxValueY - minValueY);\n let newColor: Color | undefined;\n if (newXValue !== xValue) {\n // Round new value to multiple of step, clamp value between min and max\n newXValue = snapValueToStep(newXValue, minValueX, maxValueX, stepX);\n newColor = color.withChannelValue(channels.xChannel, newXValue);\n }\n if (newYValue !== yValue) {\n // Round new value to multiple of step, clamp value between min and max\n newYValue = snapValueToStep(newYValue, minValueY, maxValueY, stepY);\n newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);\n }\n if (newColor) {\n setColor(newColor);\n }\n },\n getThumbPosition() {\n let x = (xValue - minValueX) / (maxValueX - minValueX);\n let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);\n return {x, y};\n },\n incrementX(stepSize = 1) {\n setXValue(\n xValue + stepSize > maxValueX\n ? maxValueX\n : snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX)\n );\n },\n incrementY(stepSize = 1) {\n setYValue(\n yValue + stepSize > maxValueY\n ? maxValueY\n : snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY)\n );\n },\n decrementX(stepSize = 1) {\n setXValue(snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));\n },\n decrementY(stepSize = 1) {\n setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return color.withChannelValue('alpha', 1);\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorAreaState.cjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiFD,MAAM,sCAAgB,CAAA,GAAA,wCAAS,EAAE;AAK1B,SAAS,0CAAkB,KAAqB;IACrD,IAAI,SACF,KAAK,gBACL,YAAY,cACZ,UAAU,YACV,QAAQ,YACR,QAAQ,YACR,QAAQ,eACR,WAAW,EACZ,GAAG;IAEJ,IAAI,CAAC,SAAS,CAAC,cACb,eAAe;IAEjB,IAAI,OACF,QAAQ,CAAA,GAAA,yCAAa,EAAE;IAEzB,IAAI,cACF,eAAe,CAAA,GAAA,yCAAa,EAAE;IAGhC,+HAA+H;IAC/H,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,yCAAiB,EAAS,OAAgB,cAAuB;IACnG,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,QAAQ,CAAA,GAAA,cAAM,EAAE,IAAM,cAAc,aAAa,WAAW,QAAQ,CAAC,cAAc,YAAY;QAAC;QAAY;KAAW;IAC3H,IAAI,WAAW,CAAA,GAAA,aAAK,EAAE;IACtB,IAAI,WAAW,CAAC;QACd,SAAS,OAAO,GAAG;QACnB,cAAc;IAChB;IAEA,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IACrB,MAAM,iBAAiB,CAAC;sBAAC;sBAAU;QAAQ,IAC3C;QAAC;QAAO;QAAU;KAAS;IAG7B,IAAI,gBAAgB,MAAM,eAAe,CAAC,SAAS,QAAQ;IAC3D,IAAI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,gBAAgB,CAAC,SAAS,QAAQ,EAAE;YACvD;YACA,IAAI,cAAc,QAAQ;gBACxB,uEAAuE;gBACvE,YAAY,CAAA,GAAA,yCAAc,EAAE,WAAW,WAAW,WAAW;gBAC7D,WAAW,AAAC,CAAA,YAAY,KAAI,EAAG,gBAAgB,CAAC,SAAS,QAAQ,EAAE;YACrE;YACA,IAAI,UACF,SAAS;QAEb;QACA;YACE,IAAI,IAAI,AAAC,CAAA,SAAS,SAAQ,IAAM,CAAA,YAAY,SAAQ;YACpD,IAAI,IAAI,IAAI,AAAC,CAAA,SAAS,SAAQ,IAAM,CAAA,YAAY,SAAQ;YACxD,OAAO;mBAAC;mBAAG;YAAC;QACd;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,SAAS,WAAW,YAAY,YAAY,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACjH;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,SAAS,WAAW,YAAY,YAAY,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACjH;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,aAAY,UAAU;YACpB,IAAI,cAAc,cAAc,OAAO;YACvC,cAAc,OAAO,GAAG;YAExB,IAAI,eAAe,CAAC,cAAc,aAChC,YAAY,SAAS,OAAO;YAG9B,YAAY;QACd;oBACA;QACA;YACE,OAAO,MAAM,gBAAgB,CAAC,SAAS;QACzC;IACF;AACF","sources":["packages/react-stately/src/color/useColorAreaState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {Color, ColorChannel, ColorSpace} from './types';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useRef, useState} from 'react';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorAreaProps extends Omit<ValueBase<string | Color>, 'onChange'> {\n /**\n * The color space that the color area operates in. The `xChannel` and `yChannel` must be in this color space.\n * If not provided, this defaults to the color space of the `color` or `defaultColor` value.\n */\n colorSpace?: ColorSpace,\n /** Color channel for the horizontal axis. */\n xChannel?: ColorChannel,\n /** Color channel for the vertical axis. */\n yChannel?: ColorChannel,\n /** Whether the ColorArea is disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the value changes, as the user drags. */\n onChange?: (value: Color) => void,\n /** Handler that is called when the user stops dragging. */\n onChangeEnd?: (value: Color) => void\n}\n\nexport interface ColorAreaState {\n /** The current color value displayed by the color area. */\n readonly value: Color,\n /** The default value of the color area. */\n readonly defaultValue: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n\n /** The current value of the horizontal axis channel displayed by the color area. */\n xValue: number,\n /** Sets the value for the horizontal axis channel displayed by the color area, and triggers `onChange`. */\n setXValue(value: number): void,\n\n /** The current value of the vertical axis channel displayed by the color area. */\n yValue: number,\n /** Sets the value for the vertical axis channel displayed by the color area, and triggers `onChange`. */\n setYValue(value: number): void,\n\n /** Sets the x and y channels of the current color value based on a percentage of the width and height of the color area, and triggers `onChange`. */\n setColorFromPoint(x: number, y: number): void,\n /** Returns the coordinates of the thumb relative to the upper left corner of the color area as a percentage. */\n getThumbPosition(): {x: number, y: number},\n\n /** Increments the value of the horizontal axis channel by the channel step or page amount. */\n incrementX(stepSize?: number): void,\n /** Decrements the value of the horizontal axis channel by the channel step or page amount. */\n decrementX(stepSize?: number): void,\n\n /** Increments the value of the vertical axis channel by the channel step or page amount. */\n incrementY(stepSize?: number): void,\n /** Decrements the value of the vertical axis channel by the channel step or page amount. */\n decrementY(stepSize?: number): void,\n\n /** Whether the color area is currently being dragged. */\n readonly isDragging: boolean,\n /** Sets whether the color area is being dragged. */\n setDragging(value: boolean): void,\n\n /** Returns the xChannel, yChannel and zChannel names based on the color value. */\n channels: {xChannel: ColorChannel, yChannel: ColorChannel, zChannel: ColorChannel},\n /** The step value of the xChannel, used when incrementing and decrementing. */\n xChannelStep: number,\n /** The step value of the yChannel, used when incrementing and decrementing. */\n yChannelStep: number,\n /** The page step value of the xChannel, used when incrementing and decrementing. */\n xChannelPageStep: number,\n /** The page step value of the yChannel, used when incrementing and decrementing. */\n yChannelPageStep: number,\n\n /** Returns the color that should be displayed in the color area thumb instead of `value`. */\n getDisplayColor(): Color\n}\n\nconst DEFAULT_COLOR = parseColor('#ffffff');\n/**\n * Provides state management for a color area component.\n * Color area allows users to adjust two channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.\n */\nexport function useColorAreaState(props: ColorAreaProps): ColorAreaState {\n let {\n value,\n defaultValue,\n colorSpace,\n xChannel,\n yChannel,\n onChange,\n onChangeEnd\n } = props;\n\n if (!value && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [colorValue, setColorState] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);\n let [initialValue] = useState(colorValue);\n let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);\n let valueRef = useRef(color);\n let setColor = (color: Color) => {\n valueRef.current = color;\n setColorState(color);\n };\n\n let channels = useMemo(() =>\n color.getColorSpaceAxes({xChannel, yChannel}),\n [color, xChannel, yChannel]\n );\n\n let xChannelRange = color.getChannelRange(channels.xChannel);\n let yChannelRange = color.getChannelRange(channels.yChannel);\n let {minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX} = xChannelRange;\n let {minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY} = yChannelRange;\n\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let xValue = color.getChannelValue(channels.xChannel);\n let yValue = color.getChannelValue(channels.yChannel);\n let setXValue = (v: number) => {\n if (v === xValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.xChannel, v);\n setColor(newColor);\n };\n let setYValue = (v: number) => {\n if (v === yValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.yChannel, v);\n setColor(newColor);\n };\n\n return {\n channels,\n xChannelStep: stepX,\n yChannelStep: stepY,\n xChannelPageStep: pageSizeX,\n yChannelPageStep: pageSizeY,\n value: color,\n defaultValue: value !== undefined ? initialValue : defaultValue as Color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n xValue,\n setXValue,\n yValue,\n setYValue,\n setColorFromPoint(x: number, y: number) {\n let newXValue = minValueX + clamp(x, 0, 1) * (maxValueX - minValueX);\n let newYValue = minValueY + (1 - clamp(y, 0, 1)) * (maxValueY - minValueY);\n let newColor: Color | undefined;\n if (newXValue !== xValue) {\n // Round new value to multiple of step, clamp value between min and max\n newXValue = snapValueToStep(newXValue, minValueX, maxValueX, stepX);\n newColor = color.withChannelValue(channels.xChannel, newXValue);\n }\n if (newYValue !== yValue) {\n // Round new value to multiple of step, clamp value between min and max\n newYValue = snapValueToStep(newYValue, minValueY, maxValueY, stepY);\n newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);\n }\n if (newColor) {\n setColor(newColor);\n }\n },\n getThumbPosition() {\n let x = (xValue - minValueX) / (maxValueX - minValueX);\n let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);\n return {x, y};\n },\n incrementX(stepSize = 1) {\n setXValue(xValue + stepSize > maxValueX ? maxValueX : snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX));\n },\n incrementY(stepSize = 1) {\n setYValue(yValue + stepSize > maxValueY ? maxValueY : snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY));\n },\n decrementX(stepSize = 1) {\n setXValue(snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));\n },\n decrementY(stepSize = 1) {\n setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return color.withChannelValue('alpha', 1);\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorAreaState.js.map"}
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA8FD,MAAM,sCAAgB,CAAA,GAAA,wCAAS,EAAE;AAK1B,SAAS,0CAAkB,KAAqB;IACrD,IAAI,SAAC,KAAK,gBAAE,YAAY,cAAE,UAAU,YAAE,QAAQ,YAAE,QAAQ,YAAE,QAAQ,eAAE,WAAW,EAAC,GAAG;IAEnF,IAAI,CAAC,SAAS,CAAC,cACb,eAAe;IAEjB,IAAI,OACF,QAAQ,CAAA,GAAA,yCAAa,EAAE;IAEzB,IAAI,cACF,eAAe,CAAA,GAAA,yCAAa,EAAE;IAGhC,+HAA+H;IAC/H,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,yCAAiB,EACjD,OACA,cACA;IAEF,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,QAAQ,CAAA,GAAA,cAAM,EAChB,IAAO,cAAc,aAAa,WAAW,QAAQ,CAAC,cAAc,YACpE;QAAC;QAAY;KAAW;IAE1B,IAAI,WAAW,CAAA,GAAA,aAAK,EAA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QACd;oBACA;QACA;YACE,OAAO,MAAM,gBAAgB,CAAC,SAAS;QACzC;IACF;AACF","sources":["packages/react-stately/src/color/useColorAreaState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {Color, ColorChannel, ColorSpace} from './types';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useRef, useState} from 'react';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorAreaProps extends Omit<ValueBase<string | Color>, 'onChange'> {\n /**\n * The color space that the color area operates in. The `xChannel` and `yChannel` must be in this\n * color space. If not provided, this defaults to the color space of the `color` or `defaultColor`\n * value.\n */\n colorSpace?: ColorSpace;\n /** Color channel for the horizontal axis. */\n xChannel?: ColorChannel;\n /** Color channel for the vertical axis. */\n yChannel?: ColorChannel;\n /** Whether the ColorArea is disabled. */\n isDisabled?: boolean;\n /** Handler that is called when the value changes, as the user drags. */\n onChange?: (value: Color) => void;\n /** Handler that is called when the user stops dragging. */\n onChangeEnd?: (value: Color) => void;\n}\n\nexport interface ColorAreaState {\n /** The current color value displayed by the color area. */\n readonly value: Color;\n /** The default value of the color area. */\n readonly defaultValue: Color;\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void;\n\n /** The current value of the horizontal axis channel displayed by the color area. */\n xValue: number;\n /**\n * Sets the value for the horizontal axis channel displayed by the color area, and triggers\n * `onChange`.\n */\n setXValue(value: number): void;\n\n /** The current value of the vertical axis channel displayed by the color area. */\n yValue: number;\n /**\n * Sets the value for the vertical axis channel displayed by the color area, and triggers\n * `onChange`.\n */\n setYValue(value: number): void;\n\n /**\n * Sets the x and y channels of the current color value based on a percentage of the width and\n * height of the color area, and triggers `onChange`.\n */\n setColorFromPoint(x: number, y: number): void;\n /**\n * Returns the coordinates of the thumb relative to the upper left corner of the color area as a\n * percentage.\n */\n getThumbPosition(): {x: number; y: number};\n\n /** Increments the value of the horizontal axis channel by the channel step or page amount. */\n incrementX(stepSize?: number): void;\n /** Decrements the value of the horizontal axis channel by the channel step or page amount. */\n decrementX(stepSize?: number): void;\n\n /** Increments the value of the vertical axis channel by the channel step or page amount. */\n incrementY(stepSize?: number): void;\n /** Decrements the value of the vertical axis channel by the channel step or page amount. */\n decrementY(stepSize?: number): void;\n\n /** Whether the color area is currently being dragged. */\n readonly isDragging: boolean;\n /** Sets whether the color area is being dragged. */\n setDragging(value: boolean): void;\n\n /** Returns the xChannel, yChannel and zChannel names based on the color value. */\n channels: {xChannel: ColorChannel; yChannel: ColorChannel; zChannel: ColorChannel};\n /** The step value of the xChannel, used when incrementing and decrementing. */\n xChannelStep: number;\n /** The step value of the yChannel, used when incrementing and decrementing. */\n yChannelStep: number;\n /** The page step value of the xChannel, used when incrementing and decrementing. */\n xChannelPageStep: number;\n /** The page step value of the yChannel, used when incrementing and decrementing. */\n yChannelPageStep: number;\n\n /** Returns the color that should be displayed in the color area thumb instead of `value`. */\n getDisplayColor(): Color;\n}\n\nconst DEFAULT_COLOR = parseColor('#ffffff');\n/**\n * Provides state management for a color area component. Color area allows users to adjust two\n * channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.\n */\nexport function useColorAreaState(props: ColorAreaProps): ColorAreaState {\n let {value, defaultValue, colorSpace, xChannel, yChannel, onChange, onChangeEnd} = props;\n\n if (!value && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [colorValue, setColorState] = useControlledState<Color>(\n value as Color,\n defaultValue as Color,\n onChange\n );\n let [initialValue] = useState(colorValue);\n let color = useMemo(\n () => (colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue),\n [colorValue, colorSpace]\n );\n let valueRef = useRef(color);\n let setColor = (color: Color) => {\n valueRef.current = color;\n setColorState(color);\n };\n\n let channels = useMemo(\n () => color.getColorSpaceAxes({xChannel, yChannel}),\n [color, xChannel, yChannel]\n );\n\n let xChannelRange = color.getChannelRange(channels.xChannel);\n let yChannelRange = color.getChannelRange(channels.yChannel);\n let {minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX} = xChannelRange;\n let {minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY} = yChannelRange;\n\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let xValue = color.getChannelValue(channels.xChannel);\n let yValue = color.getChannelValue(channels.yChannel);\n let setXValue = (v: number) => {\n if (v === xValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.xChannel, v);\n setColor(newColor);\n };\n let setYValue = (v: number) => {\n if (v === yValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.yChannel, v);\n setColor(newColor);\n };\n\n return {\n channels,\n xChannelStep: stepX,\n yChannelStep: stepY,\n xChannelPageStep: pageSizeX,\n yChannelPageStep: pageSizeY,\n value: color,\n defaultValue: value !== undefined ? initialValue : (defaultValue as Color),\n setValue(value) {\n setColor(normalizeColor(value));\n },\n xValue,\n setXValue,\n yValue,\n setYValue,\n setColorFromPoint(x: number, y: number) {\n let newXValue = minValueX + clamp(x, 0, 1) * (maxValueX - minValueX);\n let newYValue = minValueY + (1 - clamp(y, 0, 1)) * (maxValueY - minValueY);\n let newColor: Color | undefined;\n if (newXValue !== xValue) {\n // Round new value to multiple of step, clamp value between min and max\n newXValue = snapValueToStep(newXValue, minValueX, maxValueX, stepX);\n newColor = color.withChannelValue(channels.xChannel, newXValue);\n }\n if (newYValue !== yValue) {\n // Round new value to multiple of step, clamp value between min and max\n newYValue = snapValueToStep(newYValue, minValueY, maxValueY, stepY);\n newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);\n }\n if (newColor) {\n setColor(newColor);\n }\n },\n getThumbPosition() {\n let x = (xValue - minValueX) / (maxValueX - minValueX);\n let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);\n return {x, y};\n },\n incrementX(stepSize = 1) {\n setXValue(\n xValue + stepSize > maxValueX\n ? maxValueX\n : snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX)\n );\n },\n incrementY(stepSize = 1) {\n setYValue(\n yValue + stepSize > maxValueY\n ? maxValueY\n : snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY)\n );\n },\n decrementX(stepSize = 1) {\n setXValue(snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));\n },\n decrementY(stepSize = 1) {\n setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return color.withChannelValue('alpha', 1);\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorAreaState.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiFD,MAAM,sCAAgB,CAAA,GAAA,wCAAS,EAAE;AAK1B,SAAS,0CAAkB,KAAqB;IACrD,IAAI,SACF,KAAK,gBACL,YAAY,cACZ,UAAU,YACV,QAAQ,YACR,QAAQ,YACR,QAAQ,eACR,WAAW,EACZ,GAAG;IAEJ,IAAI,CAAC,SAAS,CAAC,cACb,eAAe;IAEjB,IAAI,OACF,QAAQ,CAAA,GAAA,yCAAa,EAAE;IAEzB,IAAI,c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,WAAW,WAAW;QACjH;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,aAAY,UAAU;YACpB,IAAI,cAAc,cAAc,OAAO;YACvC,cAAc,OAAO,GAAG;YAExB,IAAI,eAAe,CAAC,cAAc,aAChC,YAAY,SAAS,OAAO;YAG9B,YAAY;QACd;oBACA;QACA;YACE,OAAO,MAAM,gBAAgB,CAAC,SAAS;QACzC;IACF;AACF","sources":["packages/react-stately/src/color/useColorAreaState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {Color, ColorChannel, ColorSpace} from './types';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useRef, useState} from 'react';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorAreaProps extends Omit<ValueBase<string | Color>, 'onChange'> {\n /**\n * The color space that the color area operates in. The `xChannel` and `yChannel` must be in this color space.\n * If not provided, this defaults to the color space of the `color` or `defaultColor` value.\n */\n colorSpace?: ColorSpace,\n /** Color channel for the horizontal axis. */\n xChannel?: ColorChannel,\n /** Color channel for the vertical axis. */\n yChannel?: ColorChannel,\n /** Whether the ColorArea is disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the value changes, as the user drags. */\n onChange?: (value: Color) => void,\n /** Handler that is called when the user stops dragging. */\n onChangeEnd?: (value: Color) => void\n}\n\nexport interface ColorAreaState {\n /** The current color value displayed by the color area. */\n readonly value: Color,\n /** The default value of the color area. */\n readonly defaultValue: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n\n /** The current value of the horizontal axis channel displayed by the color area. */\n xValue: number,\n /** Sets the value for the horizontal axis channel displayed by the color area, and triggers `onChange`. */\n setXValue(value: number): void,\n\n /** The current value of the vertical axis channel displayed by the color area. */\n yValue: number,\n /** Sets the value for the vertical axis channel displayed by the color area, and triggers `onChange`. */\n setYValue(value: number): void,\n\n /** Sets the x and y channels of the current color value based on a percentage of the width and height of the color area, and triggers `onChange`. */\n setColorFromPoint(x: number, y: number): void,\n /** Returns the coordinates of the thumb relative to the upper left corner of the color area as a percentage. */\n getThumbPosition(): {x: number, y: number},\n\n /** Increments the value of the horizontal axis channel by the channel step or page amount. */\n incrementX(stepSize?: number): void,\n /** Decrements the value of the horizontal axis channel by the channel step or page amount. */\n decrementX(stepSize?: number): void,\n\n /** Increments the value of the vertical axis channel by the channel step or page amount. */\n incrementY(stepSize?: number): void,\n /** Decrements the value of the vertical axis channel by the channel step or page amount. */\n decrementY(stepSize?: number): void,\n\n /** Whether the color area is currently being dragged. */\n readonly isDragging: boolean,\n /** Sets whether the color area is being dragged. */\n setDragging(value: boolean): void,\n\n /** Returns the xChannel, yChannel and zChannel names based on the color value. */\n channels: {xChannel: ColorChannel, yChannel: ColorChannel, zChannel: ColorChannel},\n /** The step value of the xChannel, used when incrementing and decrementing. */\n xChannelStep: number,\n /** The step value of the yChannel, used when incrementing and decrementing. */\n yChannelStep: number,\n /** The page step value of the xChannel, used when incrementing and decrementing. */\n xChannelPageStep: number,\n /** The page step value of the yChannel, used when incrementing and decrementing. */\n yChannelPageStep: number,\n\n /** Returns the color that should be displayed in the color area thumb instead of `value`. */\n getDisplayColor(): Color\n}\n\nconst DEFAULT_COLOR = parseColor('#ffffff');\n/**\n * Provides state management for a color area component.\n * Color area allows users to adjust two channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.\n */\nexport function useColorAreaState(props: ColorAreaProps): ColorAreaState {\n let {\n value,\n defaultValue,\n colorSpace,\n xChannel,\n yChannel,\n onChange,\n onChangeEnd\n } = props;\n\n if (!value && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [colorValue, setColorState] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);\n let [initialValue] = useState(colorValue);\n let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);\n let valueRef = useRef(color);\n let setColor = (color: Color) => {\n valueRef.current = color;\n setColorState(color);\n };\n\n let channels = useMemo(() =>\n color.getColorSpaceAxes({xChannel, yChannel}),\n [color, xChannel, yChannel]\n );\n\n let xChannelRange = color.getChannelRange(channels.xChannel);\n let yChannelRange = color.getChannelRange(channels.yChannel);\n let {minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX} = xChannelRange;\n let {minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY} = yChannelRange;\n\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let xValue = color.getChannelValue(channels.xChannel);\n let yValue = color.getChannelValue(channels.yChannel);\n let setXValue = (v: number) => {\n if (v === xValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.xChannel, v);\n setColor(newColor);\n };\n let setYValue = (v: number) => {\n if (v === yValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.yChannel, v);\n setColor(newColor);\n };\n\n return {\n channels,\n xChannelStep: stepX,\n yChannelStep: stepY,\n xChannelPageStep: pageSizeX,\n yChannelPageStep: pageSizeY,\n value: color,\n defaultValue: value !== undefined ? initialValue : defaultValue as Color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n xValue,\n setXValue,\n yValue,\n setYValue,\n setColorFromPoint(x: number, y: number) {\n let newXValue = minValueX + clamp(x, 0, 1) * (maxValueX - minValueX);\n let newYValue = minValueY + (1 - clamp(y, 0, 1)) * (maxValueY - minValueY);\n let newColor: Color | undefined;\n if (newXValue !== xValue) {\n // Round new value to multiple of step, clamp value between min and max\n newXValue = snapValueToStep(newXValue, minValueX, maxValueX, stepX);\n newColor = color.withChannelValue(channels.xChannel, newXValue);\n }\n if (newYValue !== yValue) {\n // Round new value to multiple of step, clamp value between min and max\n newYValue = snapValueToStep(newYValue, minValueY, maxValueY, stepY);\n newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);\n }\n if (newColor) {\n setColor(newColor);\n }\n },\n getThumbPosition() {\n let x = (xValue - minValueX) / (maxValueX - minValueX);\n let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);\n return {x, y};\n },\n incrementX(stepSize = 1) {\n setXValue(xValue + stepSize > maxValueX ? maxValueX : snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX));\n },\n incrementY(stepSize = 1) {\n setYValue(yValue + stepSize > maxValueY ? maxValueY : snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY));\n },\n decrementX(stepSize = 1) {\n setXValue(snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));\n },\n decrementY(stepSize = 1) {\n setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return color.withChannelValue('alpha', 1);\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorAreaState.mjs.map"}
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA8FD,MAAM,sCAAgB,CAAA,GAAA,w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Y,SAAQ;YACxD,OAAO;mBAAC;mBAAG;YAAC;QACd;QACA,YAAW,WAAW,CAAC;YACrB,UACE,SAAS,WAAW,YAChB,YACA,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QAEjE;QACA,YAAW,WAAW,CAAC;YACrB,UACE,SAAS,WAAW,YAChB,YACA,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QAEjE;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,YAAW,WAAW,CAAC;YACrB,UAAU,CAAA,GAAA,yCAAc,EAAE,SAAS,UAAU,WAAW,WAAW;QACrE;QACA,aAAY,UAAU;YACpB,IAAI,cAAc,cAAc,OAAO;YACvC,cAAc,OAAO,GAAG;YAExB,IAAI,eAAe,CAAC,cAAc,aAChC,YAAY,SAAS,OAAO;YAG9B,YAAY;QACd;oBACA;QACA;YACE,OAAO,MAAM,gBAAgB,CAAC,SAAS;QACzC;IACF;AACF","sources":["packages/react-stately/src/color/useColorAreaState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '../utils/number';\n\nimport {Color, ColorChannel, ColorSpace} from './types';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useRef, useState} from 'react';\nimport {ValueBase} from '@react-types/shared';\n\nexport interface ColorAreaProps extends Omit<ValueBase<string | Color>, 'onChange'> {\n /**\n * The color space that the color area operates in. The `xChannel` and `yChannel` must be in this\n * color space. If not provided, this defaults to the color space of the `color` or `defaultColor`\n * value.\n */\n colorSpace?: ColorSpace;\n /** Color channel for the horizontal axis. */\n xChannel?: ColorChannel;\n /** Color channel for the vertical axis. */\n yChannel?: ColorChannel;\n /** Whether the ColorArea is disabled. */\n isDisabled?: boolean;\n /** Handler that is called when the value changes, as the user drags. */\n onChange?: (value: Color) => void;\n /** Handler that is called when the user stops dragging. */\n onChangeEnd?: (value: Color) => void;\n}\n\nexport interface ColorAreaState {\n /** The current color value displayed by the color area. */\n readonly value: Color;\n /** The default value of the color area. */\n readonly defaultValue: Color;\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void;\n\n /** The current value of the horizontal axis channel displayed by the color area. */\n xValue: number;\n /**\n * Sets the value for the horizontal axis channel displayed by the color area, and triggers\n * `onChange`.\n */\n setXValue(value: number): void;\n\n /** The current value of the vertical axis channel displayed by the color area. */\n yValue: number;\n /**\n * Sets the value for the vertical axis channel displayed by the color area, and triggers\n * `onChange`.\n */\n setYValue(value: number): void;\n\n /**\n * Sets the x and y channels of the current color value based on a percentage of the width and\n * height of the color area, and triggers `onChange`.\n */\n setColorFromPoint(x: number, y: number): void;\n /**\n * Returns the coordinates of the thumb relative to the upper left corner of the color area as a\n * percentage.\n */\n getThumbPosition(): {x: number; y: number};\n\n /** Increments the value of the horizontal axis channel by the channel step or page amount. */\n incrementX(stepSize?: number): void;\n /** Decrements the value of the horizontal axis channel by the channel step or page amount. */\n decrementX(stepSize?: number): void;\n\n /** Increments the value of the vertical axis channel by the channel step or page amount. */\n incrementY(stepSize?: number): void;\n /** Decrements the value of the vertical axis channel by the channel step or page amount. */\n decrementY(stepSize?: number): void;\n\n /** Whether the color area is currently being dragged. */\n readonly isDragging: boolean;\n /** Sets whether the color area is being dragged. */\n setDragging(value: boolean): void;\n\n /** Returns the xChannel, yChannel and zChannel names based on the color value. */\n channels: {xChannel: ColorChannel; yChannel: ColorChannel; zChannel: ColorChannel};\n /** The step value of the xChannel, used when incrementing and decrementing. */\n xChannelStep: number;\n /** The step value of the yChannel, used when incrementing and decrementing. */\n yChannelStep: number;\n /** The page step value of the xChannel, used when incrementing and decrementing. */\n xChannelPageStep: number;\n /** The page step value of the yChannel, used when incrementing and decrementing. */\n yChannelPageStep: number;\n\n /** Returns the color that should be displayed in the color area thumb instead of `value`. */\n getDisplayColor(): Color;\n}\n\nconst DEFAULT_COLOR = parseColor('#ffffff');\n/**\n * Provides state management for a color area component. Color area allows users to adjust two\n * channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.\n */\nexport function useColorAreaState(props: ColorAreaProps): ColorAreaState {\n let {value, defaultValue, colorSpace, xChannel, yChannel, onChange, onChangeEnd} = props;\n\n if (!value && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [colorValue, setColorState] = useControlledState<Color>(\n value as Color,\n defaultValue as Color,\n onChange\n );\n let [initialValue] = useState(colorValue);\n let color = useMemo(\n () => (colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue),\n [colorValue, colorSpace]\n );\n let valueRef = useRef(color);\n let setColor = (color: Color) => {\n valueRef.current = color;\n setColorState(color);\n };\n\n let channels = useMemo(\n () => color.getColorSpaceAxes({xChannel, yChannel}),\n [color, xChannel, yChannel]\n );\n\n let xChannelRange = color.getChannelRange(channels.xChannel);\n let yChannelRange = color.getChannelRange(channels.yChannel);\n let {minValue: minValueX, maxValue: maxValueX, step: stepX, pageSize: pageSizeX} = xChannelRange;\n let {minValue: minValueY, maxValue: maxValueY, step: stepY, pageSize: pageSizeY} = yChannelRange;\n\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let xValue = color.getChannelValue(channels.xChannel);\n let yValue = color.getChannelValue(channels.yChannel);\n let setXValue = (v: number) => {\n if (v === xValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.xChannel, v);\n setColor(newColor);\n };\n let setYValue = (v: number) => {\n if (v === yValue) {\n return;\n }\n let newColor = color.withChannelValue(channels.yChannel, v);\n setColor(newColor);\n };\n\n return {\n channels,\n xChannelStep: stepX,\n yChannelStep: stepY,\n xChannelPageStep: pageSizeX,\n yChannelPageStep: pageSizeY,\n value: color,\n defaultValue: value !== undefined ? initialValue : (defaultValue as Color),\n setValue(value) {\n setColor(normalizeColor(value));\n },\n xValue,\n setXValue,\n yValue,\n setYValue,\n setColorFromPoint(x: number, y: number) {\n let newXValue = minValueX + clamp(x, 0, 1) * (maxValueX - minValueX);\n let newYValue = minValueY + (1 - clamp(y, 0, 1)) * (maxValueY - minValueY);\n let newColor: Color | undefined;\n if (newXValue !== xValue) {\n // Round new value to multiple of step, clamp value between min and max\n newXValue = snapValueToStep(newXValue, minValueX, maxValueX, stepX);\n newColor = color.withChannelValue(channels.xChannel, newXValue);\n }\n if (newYValue !== yValue) {\n // Round new value to multiple of step, clamp value between min and max\n newYValue = snapValueToStep(newYValue, minValueY, maxValueY, stepY);\n newColor = (newColor || color).withChannelValue(channels.yChannel, newYValue);\n }\n if (newColor) {\n setColor(newColor);\n }\n },\n getThumbPosition() {\n let x = (xValue - minValueX) / (maxValueX - minValueX);\n let y = 1 - (yValue - minValueY) / (maxValueY - minValueY);\n return {x, y};\n },\n incrementX(stepSize = 1) {\n setXValue(\n xValue + stepSize > maxValueX\n ? maxValueX\n : snapValueToStep(xValue + stepSize, minValueX, maxValueX, stepX)\n );\n },\n incrementY(stepSize = 1) {\n setYValue(\n yValue + stepSize > maxValueY\n ? maxValueY\n : snapValueToStep(yValue + stepSize, minValueY, maxValueY, stepY)\n );\n },\n decrementX(stepSize = 1) {\n setXValue(snapValueToStep(xValue - stepSize, minValueX, maxValueX, stepX));\n },\n decrementY(stepSize = 1) {\n setYValue(snapValueToStep(yValue - stepSize, minValueY, maxValueY, stepY));\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return color.withChannelValue('alpha', 1);\n }\n };\n}\n"],"names":[],"version":3,"file":"useColorAreaState.mjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;AA6BO,SAAS,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;AA6BO,SAAS,0CACd,KAAoC;IAEpC,IAAI,WAAC,OAAO,cAAE,UAAU,UAAE,MAAM,EAAC,GAAG;IACpC,IAAI,eAAe,CAAA,GAAA,kCAAO,EAAE,MAAM,KAAK;IACvC,IAAI,sBAAsB,CAAA,GAAA,kCAAO,EAAE,MAAM,YAAY;IACrD,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,4CAAiB,EAC5C,cACA,uBAAuB,MACvB,MAAM,QAAQ;IAEhB,IAAI,QAAQ,sCAAgB,YAAY;IACxC,IAAI,CAAC,kBAAkB,GAAG,CAAA,GAAA,qBAAO,EAAE;IACnC,IAAI,oBAAoB,uBAAuB;IAC/C,IAAI,eAAe,sCAAgB,mBAAmB;IACtD,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,gBAAgB,CAAA,GAAA,oBAAM,EAAE,IAAM,MAAM,uBAAuB,CAAC,UAAU;QAAC;QAAO;KAAQ;IAC1F,IAAI,aAAa,cAAc,KAAK,KAAK,aAAa,MAAM,QAAQ,KAAK,MAAM,MAAM;IAErF,IAAI,mBAAmB,CAAA,GAAA,6CAAkB,EAAE;gBACzC;QACA,OAAO,eAAe,OAAO,MAAM,QAAQ;QAC3C,cACE,sBAAsB,OAAO,MAAM,aAAa,eAAe,CAAC,WAAW;QAC7E,UAAU,CAAA;YACR,IAAI,CAAC,OAAO,KAAK,CAAC,IAChB,SAAS,MAAM,gBAAgB,CAAC,SAAS,IAAI;iBAE7C,SAAS;QAEb;QACA,UAAU,MAAM,QAAQ,GAAG;QAC3B,UAAU,MAAM,QAAQ,GAAG;QAC3B,MAAM,MAAM,IAAI,GAAG;uBACnB;IACF;IAEA,OAAO;QACL,GAAG,gBAAgB;QACnB,YAAY;2BACZ;QACA,eAAe;IACjB;AACF;AAEA,SAAS,sCAAgB,UAAwB,EAAE,UAAyC;IAC1F,IAAI,QAAQ,CAAA,GAAA,kCAAO,EAAE;IACrB,OAAO,CAAA,GAAA,oBAAM,EAAE;QACb,IAAI,oBAAoB,cAAc;QACtC,OAAO,cAAc,oBACjB,kBAAkB,QAAQ,CAAC,cAC3B;IACN,GAAG;QAAC;QAAO;QAAY;KAAW;AACpC","sources":["packages/react-stately/src/color/useColorChannelFieldState.ts"],"sourcesContent":["import {Color, ColorChannel, ColorSpace} from './types';\nimport {ColorFieldProps} from './useColorFieldState';\nimport {NumberFieldState, useNumberFieldState} from '../numberfield/useNumberFieldState';\nimport {useColor} from './useColor';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorChannelFieldProps extends ColorFieldProps {\n colorSpace?: ColorSpace;\n channel: ColorChannel;\n}\n\nexport interface ColorChannelFieldStateOptions extends ColorChannelFieldProps {\n locale: string;\n}\n\nexport interface ColorChannelFieldState extends NumberFieldState {\n /** The current value of the field. */\n colorValue: Color;\n /** The default value of the field. */\n defaultColorValue: Color | null;\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void;\n}\n\n/**\n * Provides state management for a color channel field, allowing users to edit the\n * value of an individual color channel.\n */\nexport function useColorChannelFieldState(\n props: ColorChannelFieldStateOptions\n): ColorChannelFieldState {\n let {channel, colorSpace, locale} = props;\n let initialValue = useColor(props.value);\n let initialDefaultValue = useColor(props.defaultValue);\n let [colorValue, setColor] = useControlledState(\n initialValue,\n initialDefaultValue ?? null,\n props.onChange\n );\n let color = useConvertColor(colorValue, colorSpace);\n let [initialColorValue] = useState(colorValue);\n let defaultColorValue = initialDefaultValue ?? initialColorValue;\n let defaultColor = useConvertColor(defaultColorValue, colorSpace);\n let value = color.getChannelValue(channel);\n let range = color.getChannelRange(channel);\n let formatOptions = useMemo(() => color.getChannelFormatOptions(channel), [color, channel]);\n let multiplier = formatOptions.style === 'percent' && range.maxValue === 100 ? 100 : 1;\n\n let numberFieldState = useNumberFieldState({\n locale,\n value: colorValue === null ? NaN : value / multiplier,\n defaultValue:\n defaultColorValue === null ? NaN : defaultColor.getChannelValue(channel) / multiplier,\n onChange: v => {\n if (!Number.isNaN(v)) {\n setColor(color.withChannelValue(channel, v * multiplier));\n } else {\n setColor(null);\n }\n },\n minValue: range.minValue / multiplier,\n maxValue: range.maxValue / multiplier,\n step: range.step / multiplier,\n formatOptions\n });\n\n return {\n ...numberFieldState,\n colorValue: color,\n defaultColorValue,\n setColorValue: setColor\n };\n}\n\nfunction useConvertColor(colorValue: Color | null, colorSpace: ColorSpace | null | undefined) {\n let black = useColor('#000')!;\n return useMemo(() => {\n let nonNullColorValue = colorValue || black;\n return colorSpace && nonNullColorValue\n ? nonNullColorValue.toFormat(colorSpace)\n : nonNullColorValue;\n }, [black, colorValue, colorSpace]);\n}\n"],"names":[],"version":3,"file":"useColorChannelFieldState.cjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AA6BO,SAAS,
|
|
1
|
+
{"mappings":";;;;;;;;;AA6BO,SAAS,0CACd,KAAoC;IAEpC,IAAI,WAAC,OAAO,cAAE,UAAU,UAAE,MAAM,EAAC,GAAG;IACpC,IAAI,eAAe,CAAA,GAAA,yCAAO,EAAE,MAAM,KAAK;IACvC,IAAI,sBAAsB,CAAA,GAAA,yCAAO,EAAE,MAAM,YAAY;IACrD,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,yCAAiB,EAC5C,cACA,gCAAA,iCAAA,sBAAuB,MACvB,MAAM,QAAQ;IAEhB,IAAI,QAAQ,sCAAgB,YAAY;IACxC,IAAI,CAAC,kBAAkB,GAAG,CAAA,GAAA,eAAO,EAAE;IACnC,IAAI,oBAAoB,gCAAA,iCAAA,sBAAuB;IAC/C,IAAI,eAAe,sCAAgB,mBAAmB;IACtD,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,gBAAgB,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,uBAAuB,CAAC,UAAU;QAAC;QAAO;KAAQ;IAC1F,IAAI,aAAa,cAAc,KAAK,KAAK,aAAa,MAAM,QAAQ,KAAK,MAAM,MAAM;IAErF,IAAI,mBAAmB,CAAA,GAAA,yCAAkB,EAAE;gBACzC;QACA,OAAO,eAAe,OAAO,MAAM,QAAQ;QAC3C,cACE,sBAAsB,OAAO,MAAM,aAAa,eAAe,CAAC,WAAW;QAC7E,UAAU,CAAA;YACR,IAAI,CAAC,OAAO,KAAK,CAAC,IAChB,SAAS,MAAM,gBAAgB,CAAC,SAAS,IAAI;iBAE7C,SAAS;QAEb;QACA,UAAU,MAAM,QAAQ,GAAG;QAC3B,UAAU,MAAM,QAAQ,GAAG;QAC3B,MAAM,MAAM,IAAI,GAAG;uBACnB;IACF;IAEA,OAAO;QACL,GAAG,gBAAgB;QACnB,YAAY;2BACZ;QACA,eAAe;IACjB;AACF;AAEA,SAAS,sCAAgB,UAAwB,EAAE,UAAyC;IAC1F,IAAI,QAAQ,CAAA,GAAA,yCAAO,EAAE;IACrB,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,IAAI,oBAAoB,cAAc;QACtC,OAAO,cAAc,oBACjB,kBAAkB,QAAQ,CAAC,cAC3B;IACN,GAAG;QAAC;QAAO;QAAY;KAAW;AACpC","sources":["packages/react-stately/src/color/useColorChannelFieldState.ts"],"sourcesContent":["import {Color, ColorChannel, ColorSpace} from './types';\nimport {ColorFieldProps} from './useColorFieldState';\nimport {NumberFieldState, useNumberFieldState} from '../numberfield/useNumberFieldState';\nimport {useColor} from './useColor';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorChannelFieldProps extends ColorFieldProps {\n colorSpace?: ColorSpace;\n channel: ColorChannel;\n}\n\nexport interface ColorChannelFieldStateOptions extends ColorChannelFieldProps {\n locale: string;\n}\n\nexport interface ColorChannelFieldState extends NumberFieldState {\n /** The current value of the field. */\n colorValue: Color;\n /** The default value of the field. */\n defaultColorValue: Color | null;\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void;\n}\n\n/**\n * Provides state management for a color channel field, allowing users to edit the\n * value of an individual color channel.\n */\nexport function useColorChannelFieldState(\n props: ColorChannelFieldStateOptions\n): ColorChannelFieldState {\n let {channel, colorSpace, locale} = props;\n let initialValue = useColor(props.value);\n let initialDefaultValue = useColor(props.defaultValue);\n let [colorValue, setColor] = useControlledState(\n initialValue,\n initialDefaultValue ?? null,\n props.onChange\n );\n let color = useConvertColor(colorValue, colorSpace);\n let [initialColorValue] = useState(colorValue);\n let defaultColorValue = initialDefaultValue ?? initialColorValue;\n let defaultColor = useConvertColor(defaultColorValue, colorSpace);\n let value = color.getChannelValue(channel);\n let range = color.getChannelRange(channel);\n let formatOptions = useMemo(() => color.getChannelFormatOptions(channel), [color, channel]);\n let multiplier = formatOptions.style === 'percent' && range.maxValue === 100 ? 100 : 1;\n\n let numberFieldState = useNumberFieldState({\n locale,\n value: colorValue === null ? NaN : value / multiplier,\n defaultValue:\n defaultColorValue === null ? NaN : defaultColor.getChannelValue(channel) / multiplier,\n onChange: v => {\n if (!Number.isNaN(v)) {\n setColor(color.withChannelValue(channel, v * multiplier));\n } else {\n setColor(null);\n }\n },\n minValue: range.minValue / multiplier,\n maxValue: range.maxValue / multiplier,\n step: range.step / multiplier,\n formatOptions\n });\n\n return {\n ...numberFieldState,\n colorValue: color,\n defaultColorValue,\n setColorValue: setColor\n };\n}\n\nfunction useConvertColor(colorValue: Color | null, colorSpace: ColorSpace | null | undefined) {\n let black = useColor('#000')!;\n return useMemo(() => {\n let nonNullColorValue = colorValue || black;\n return colorSpace && nonNullColorValue\n ? nonNullColorValue.toFormat(colorSpace)\n : nonNullColorValue;\n }, [black, colorValue, colorSpace]);\n}\n"],"names":[],"version":3,"file":"useColorChannelFieldState.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AA6BO,SAAS,
|
|
1
|
+
{"mappings":";;;;;;;;;AA6BO,SAAS,0CACd,KAAoC;IAEpC,IAAI,WAAC,OAAO,cAAE,UAAU,UAAE,MAAM,EAAC,GAAG;IACpC,IAAI,eAAe,CAAA,GAAA,yCAAO,EAAE,MAAM,KAAK;IACvC,IAAI,sBAAsB,CAAA,GAAA,yCAAO,EAAE,MAAM,YAAY;IACrD,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,yCAAiB,EAC5C,cACA,uBAAuB,MACvB,MAAM,QAAQ;IAEhB,IAAI,QAAQ,sCAAgB,YAAY;IACxC,IAAI,CAAC,kBAAkB,GAAG,CAAA,GAAA,eAAO,EAAE;IACnC,IAAI,oBAAoB,uBAAuB;IAC/C,IAAI,eAAe,sCAAgB,mBAAmB;IACtD,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,QAAQ,MAAM,eAAe,CAAC;IAClC,IAAI,gBAAgB,CAAA,GAAA,cAAM,EAAE,IAAM,MAAM,uBAAuB,CAAC,UAAU;QAAC;QAAO;KAAQ;IAC1F,IAAI,aAAa,cAAc,KAAK,KAAK,aAAa,MAAM,QAAQ,KAAK,MAAM,MAAM;IAErF,IAAI,mBAAmB,CAAA,GAAA,yCAAkB,EAAE;gBACzC;QACA,OAAO,eAAe,OAAO,MAAM,QAAQ;QAC3C,cACE,sBAAsB,OAAO,MAAM,aAAa,eAAe,CAAC,WAAW;QAC7E,UAAU,CAAA;YACR,IAAI,CAAC,OAAO,KAAK,CAAC,IAChB,SAAS,MAAM,gBAAgB,CAAC,SAAS,IAAI;iBAE7C,SAAS;QAEb;QACA,UAAU,MAAM,QAAQ,GAAG;QAC3B,UAAU,MAAM,QAAQ,GAAG;QAC3B,MAAM,MAAM,IAAI,GAAG;uBACnB;IACF;IAEA,OAAO;QACL,GAAG,gBAAgB;QACnB,YAAY;2BACZ;QACA,eAAe;IACjB;AACF;AAEA,SAAS,sCAAgB,UAAwB,EAAE,UAAyC;IAC1F,IAAI,QAAQ,CAAA,GAAA,yCAAO,EAAE;IACrB,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,IAAI,oBAAoB,cAAc;QACtC,OAAO,cAAc,oBACjB,kBAAkB,QAAQ,CAAC,cAC3B;IACN,GAAG;QAAC;QAAO;QAAY;KAAW;AACpC","sources":["packages/react-stately/src/color/useColorChannelFieldState.ts"],"sourcesContent":["import {Color, ColorChannel, ColorSpace} from './types';\nimport {ColorFieldProps} from './useColorFieldState';\nimport {NumberFieldState, useNumberFieldState} from '../numberfield/useNumberFieldState';\nimport {useColor} from './useColor';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorChannelFieldProps extends ColorFieldProps {\n colorSpace?: ColorSpace;\n channel: ColorChannel;\n}\n\nexport interface ColorChannelFieldStateOptions extends ColorChannelFieldProps {\n locale: string;\n}\n\nexport interface ColorChannelFieldState extends NumberFieldState {\n /** The current value of the field. */\n colorValue: Color;\n /** The default value of the field. */\n defaultColorValue: Color | null;\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void;\n}\n\n/**\n * Provides state management for a color channel field, allowing users to edit the\n * value of an individual color channel.\n */\nexport function useColorChannelFieldState(\n props: ColorChannelFieldStateOptions\n): ColorChannelFieldState {\n let {channel, colorSpace, locale} = props;\n let initialValue = useColor(props.value);\n let initialDefaultValue = useColor(props.defaultValue);\n let [colorValue, setColor] = useControlledState(\n initialValue,\n initialDefaultValue ?? null,\n props.onChange\n );\n let color = useConvertColor(colorValue, colorSpace);\n let [initialColorValue] = useState(colorValue);\n let defaultColorValue = initialDefaultValue ?? initialColorValue;\n let defaultColor = useConvertColor(defaultColorValue, colorSpace);\n let value = color.getChannelValue(channel);\n let range = color.getChannelRange(channel);\n let formatOptions = useMemo(() => color.getChannelFormatOptions(channel), [color, channel]);\n let multiplier = formatOptions.style === 'percent' && range.maxValue === 100 ? 100 : 1;\n\n let numberFieldState = useNumberFieldState({\n locale,\n value: colorValue === null ? NaN : value / multiplier,\n defaultValue:\n defaultColorValue === null ? NaN : defaultColor.getChannelValue(channel) / multiplier,\n onChange: v => {\n if (!Number.isNaN(v)) {\n setColor(color.withChannelValue(channel, v * multiplier));\n } else {\n setColor(null);\n }\n },\n minValue: range.minValue / multiplier,\n maxValue: range.maxValue / multiplier,\n step: range.step / multiplier,\n formatOptions\n });\n\n return {\n ...numberFieldState,\n colorValue: color,\n defaultColorValue,\n setColorValue: setColor\n };\n}\n\nfunction useConvertColor(colorValue: Color | null, colorSpace: ColorSpace | null | undefined) {\n let black = useColor('#000')!;\n return useMemo(() => {\n let nonNullColorValue = colorValue || black;\n return colorSpace && nonNullColorValue\n ? nonNullColorValue.toFormat(colorSpace)\n : nonNullColorValue;\n }, [black, colorValue, colorSpace]);\n}\n"],"names":[],"version":3,"file":"useColorChannelFieldState.mjs.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqDD,MAAM,kCAAY,CAAA,GAAA,oCAAS,EAAE;AAC7B,MAAM,kCAAY,CAAA,GAAA,oCAAS,EAAE;AAC7B,MAAM,sCAAgB,gCAAU,QAAQ;AACxC,MAAM,sCAAgB,gCAAU,QAAQ;AAMjC,SAAS,0CACd,KAAsB;IAEtB,IAAI,SACF,KAAK,gBACL,YAAY,YACZ,QAAQ,EACT,GAAG;IACJ,IAAI,QAAC,IAAI,EAAC,GAAG,gCAAU,eAAe,CAAC;IAEvC,IAAI,sBAAsB,CAAA,GAAA,kCAAO,EAAE;IACnC,IAAI,C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AAW,QAAQ,CAAC;QAEtC,cAAc;QACd,WAAW,gBAAgB;IAC7B;IAEA,IAAI,YAAY;QACd,IAAI,WAAW,oCAAc,aAAa;QAC1C,2EAA2E;QAC3E,yCAAyC;QACzC,+FAA+F;QAC/F,6GAA6G;QAC7G,IAAI,aAAa,YACf,cAAc,SAAS,QAAQ,CAAC;QAElC,oBAAoB;QACpB,WAAW,gBAAgB;IAC7B;IACA,IAAI,YAAY;QACd,IAAI,WAAW,oCAAc,aAAa,CAAC;QAC3C,2EAA2E;QAC3E,yCAAyC;QACzC,+FAA+F;QAC/F,6GAA6G;QAC7G,IAAI,aAAa,YACf,cAAc,SAAS,QAAQ,CAAC;QAElC,oBAAoB;QACpB,WAAW,gBAAgB;IAC7B;IACA,IAAI,iBAAiB,IAAM,oBAAoB;IAC/C,IAAI,iBAAiB,IAAM,oBAAoB;IAE/C,IAAI,WAAW,CAAC,QAAkB,UAAU,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,uBAAuB,CAAC,EAAE;IAE1F,OAAO;QACL,GAAG,UAAU;kBACb;oBACA;QACA,mBAAmB,uBAAuB;uBAC1C;oBACA;uBACA;gBACA;mBACA;wBACA;mBACA;wBACA;IACF;AACF;AAEA,SAAS,oCAAc,KAAY,EAAE,IAAY;IAC/C,IAAI,WAAW,QAAQ,QAAQ;IAC/B,IAAI,WAAW,SAAS,QAAQ;IAEhC,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,WAAW,MAAM,sCAAgB;IAClE,IAAI,aAAa,UAAU;QACzB,IAAI,iBAAiB,CAAC,CAAC,EAAE,SAAS,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,KAAK,WAAW,IAAI;QAC/E,WAAW,CAAA,GAAA,oCAAS,EAAE;IACxB;IACA,OAAO;AACT","sources":["packages/react-stately/src/color/useColorFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Color} from './types';\nimport {FocusableProps, HelpTextProps, InputBase, LabelableProps, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorFieldProps extends Omit<ValueBase<string | Color | null>, 'onChange'>, InputBase, Validation<Color | null>, FocusableProps, TextInputBase, LabelableProps, HelpTextProps {\n /** Handler that is called when the value changes. */\n onChange?: (color: Color | null) => void\n}\n\nexport interface ColorFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n readonly inputValue: string,\n /**\n * The currently parsed color value, or null if the field is empty.\n * Updated based on the `inputValue` as the user types.\n */\n readonly colorValue: Color | null,\n /** The default value of the color field. */\n readonly defaultColorValue: Color | null,\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void,\n /** Sets the current text value of the input. */\n setInputValue(value: string): void,\n /**\n * Updates the input value based on the currently parsed color value.\n * Typically this is called when the field is blurred.\n */\n commit(): void,\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void,\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void,\n /** Sets the current value to the maximum color value, and fires `onChange`. */\n incrementToMax(): void,\n /** Sets the current value to the minimum color value, and fires `onChange`. */\n decrementToMin(): void,\n /**\n * Validates a user input string.\n * Values can be partially entered, and may be valid even if they cannot currently be parsed to a color.\n * Can be used to implement validation as a user types.\n */\n validate(value: string): boolean\n}\n\nconst MIN_COLOR = parseColor('#000000');\nconst MAX_COLOR = parseColor('#FFFFFF');\nconst MIN_COLOR_INT = MIN_COLOR.toHexInt();\nconst MAX_COLOR_INT = MAX_COLOR.toHexInt();\n\n/**\n * Provides state management for a color field component. Color fields allow\n * users to enter and adjust a hex color value.\n */\nexport function useColorFieldState(\n props: ColorFieldProps\n): ColorFieldState {\n let {\n value,\n defaultValue,\n onChange\n } = props;\n let {step} = MIN_COLOR.getChannelRange('red');\n\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color | null>(useColor(value), initialDefaultValue!, onChange);\n let [initialValue] = useState(colorValue);\n let [inputValue, setInputValue] = useState(() => (value || defaultValue) && colorValue ? colorValue.toString('hex') : '');\n\n let validation = useFormValidationState({\n ...props,\n value: colorValue\n });\n\n let safelySetColorValue = (newColor: Color | null) => {\n if (!colorValue || !newColor) {\n setColorValue(newColor);\n return;\n }\n if (newColor.toHexInt() !== colorValue.toHexInt()) {\n setColorValue(newColor);\n return;\n }\n };\n\n let [prevValue, setPrevValue] = useState(colorValue);\n if (prevValue !== colorValue) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n setPrevValue(colorValue);\n }\n\n let parsedValue = useMemo(() => {\n let color;\n try {\n color = parseColor(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);\n } catch {\n color = null;\n }\n return color;\n }, [inputValue]);\n\n let commit = () => {\n // Set to empty state if input value is empty\n if (!inputValue.length) {\n safelySetColorValue(null);\n if (value === undefined || colorValue === null) {\n setInputValue('');\n } else {\n setInputValue(colorValue.toString('hex'));\n }\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (parsedValue == null) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n return;\n }\n\n safelySetColorValue(parsedValue);\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n let newColorValue = '';\n if (colorValue) {\n newColorValue = colorValue.toString('hex');\n }\n setInputValue(newColorValue);\n validation.commitValidation();\n };\n\n let increment = () => {\n let newValue = addColorValue(parsedValue, step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let decrement = () => {\n let newValue = addColorValue(parsedValue, -step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let incrementToMax = () => safelySetColorValue(MAX_COLOR);\n let decrementToMin = () => safelySetColorValue(MIN_COLOR);\n\n let validate = (value: string) => value === '' || !!value.match(/^#?[0-9a-f]{0,6}$/i)?.[0];\n\n return {\n ...validation,\n validate,\n colorValue,\n defaultColorValue: initialDefaultValue ?? initialValue,\n setColorValue,\n inputValue,\n setInputValue,\n commit,\n increment,\n incrementToMax,\n decrement,\n decrementToMin\n };\n}\n\nfunction addColorValue(color: Color, step: number) {\n let newColor = color ? color : MIN_COLOR;\n let colorInt = newColor.toHexInt();\n\n let clampInt = Math.min(Math.max(colorInt + step, MIN_COLOR_INT), MAX_COLOR_INT);\n if (clampInt !== colorInt) {\n let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;\n newColor = parseColor(newColorString);\n }\n return newColor;\n}\n"],"names":[],"version":3,"file":"useColorFieldState.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAoED,MAAM,kCAAY,CAAA,GAAA,oCAAS,EAAE;AAC7B,MAAM,kCAAY,CAAA,GAAA,oCAAS,EAAE;AAC7B,MAAM,sCAAgB,gCAAU,QAAQ;AACxC,MAAM,sCAAgB,gCAAU,QA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CAAC,GAAG,KAAK,WAAW,IAAI;QAC/E,WAAW,CAAA,GAAA,oCAAS,EAAE;IACxB;IACA,OAAO;AACT","sources":["packages/react-stately/src/color/useColorFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Color} from './types';\nimport {\n FocusableProps,\n HelpTextProps,\n InputBase,\n LabelableProps,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorFieldProps\n extends\n Omit<ValueBase<string | Color | null>, 'onChange'>,\n InputBase,\n Validation<Color | null>,\n FocusableProps,\n TextInputBase,\n LabelableProps,\n HelpTextProps {\n /** Handler that is called when the value changes. */\n onChange?: (color: Color | null) => void;\n}\n\nexport interface ColorFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n readonly inputValue: string;\n /**\n * The currently parsed color value, or null if the field is empty.\n * Updated based on the `inputValue` as the user types.\n */\n readonly colorValue: Color | null;\n /** The default value of the color field. */\n readonly defaultColorValue: Color | null;\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void;\n /** Sets the current text value of the input. */\n setInputValue(value: string): void;\n /**\n * Updates the input value based on the currently parsed color value.\n * Typically this is called when the field is blurred.\n */\n commit(): void;\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void;\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void;\n /** Sets the current value to the maximum color value, and fires `onChange`. */\n incrementToMax(): void;\n /** Sets the current value to the minimum color value, and fires `onChange`. */\n decrementToMin(): void;\n /**\n * Validates a user input string. Values can be partially entered, and may be valid even if they\n * cannot currently be parsed to a color. Can be used to implement validation as a user types.\n */\n validate(value: string): boolean;\n}\n\nconst MIN_COLOR = parseColor('#000000');\nconst MAX_COLOR = parseColor('#FFFFFF');\nconst MIN_COLOR_INT = MIN_COLOR.toHexInt();\nconst MAX_COLOR_INT = MAX_COLOR.toHexInt();\n\n/**\n * Provides state management for a color field component. Color fields allow\n * users to enter and adjust a hex color value.\n */\nexport function useColorFieldState(props: ColorFieldProps): ColorFieldState {\n let {value, defaultValue, onChange} = props;\n let {step} = MIN_COLOR.getChannelRange('red');\n\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color | null>(\n useColor(value),\n initialDefaultValue!,\n onChange\n );\n let [initialValue] = useState(colorValue);\n let [inputValue, setInputValue] = useState(() =>\n (value || defaultValue) && colorValue ? colorValue.toString('hex') : ''\n );\n\n let validation = useFormValidationState({\n ...props,\n value: colorValue\n });\n\n let safelySetColorValue = (newColor: Color | null) => {\n if (!colorValue || !newColor) {\n setColorValue(newColor);\n return;\n }\n if (newColor.toHexInt() !== colorValue.toHexInt()) {\n setColorValue(newColor);\n return;\n }\n };\n\n let [prevValue, setPrevValue] = useState(colorValue);\n if (prevValue !== colorValue) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n setPrevValue(colorValue);\n }\n\n let parsedValue = useMemo(() => {\n let color;\n try {\n color = parseColor(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);\n } catch {\n color = null;\n }\n return color;\n }, [inputValue]);\n\n let commit = () => {\n // Set to empty state if input value is empty\n if (!inputValue.length) {\n safelySetColorValue(null);\n if (value === undefined || colorValue === null) {\n setInputValue('');\n } else {\n setInputValue(colorValue.toString('hex'));\n }\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (parsedValue == null) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n return;\n }\n\n safelySetColorValue(parsedValue);\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n let newColorValue = '';\n if (colorValue) {\n newColorValue = colorValue.toString('hex');\n }\n setInputValue(newColorValue);\n validation.commitValidation();\n };\n\n let increment = () => {\n let newValue = addColorValue(parsedValue, step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let decrement = () => {\n let newValue = addColorValue(parsedValue, -step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let incrementToMax = () => safelySetColorValue(MAX_COLOR);\n let decrementToMin = () => safelySetColorValue(MIN_COLOR);\n\n let validate = (value: string) => value === '' || !!value.match(/^#?[0-9a-f]{0,6}$/i)?.[0];\n\n return {\n ...validation,\n validate,\n colorValue,\n defaultColorValue: initialDefaultValue ?? initialValue,\n setColorValue,\n inputValue,\n setInputValue,\n commit,\n increment,\n incrementToMax,\n decrement,\n decrementToMin\n };\n}\n\nfunction addColorValue(color: Color, step: number) {\n let newColor = color ? color : MIN_COLOR;\n let colorInt = newColor.toHexInt();\n\n let clampInt = Math.min(Math.max(colorInt + step, MIN_COLOR_INT), MAX_COLOR_INT);\n if (clampInt !== colorInt) {\n let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;\n newColor = parseColor(newColorString);\n }\n return newColor;\n}\n"],"names":[],"version":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BACA;mBACA;wBACA;IACF;AACF;AAEA,SAAS,oCAAc,KAAY,EAAE,IAAY;IAC/C,IAAI,WAAW,QAAQ,QAAQ;IAC/B,IAAI,WAAW,SAAS,QAAQ;IAEhC,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,WAAW,MAAM,sCAAgB;IAClE,IAAI,aAAa,UAAU;QACzB,IAAI,iBAAiB,CAAC,CAAC,EAAE,SAAS,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,KAAK,WAAW,IAAI;QAC/E,WAAW,CAAA,GAAA,wCAAS,EAAE;IACxB;IACA,OAAO;AACT","sources":["packages/react-stately/src/color/useColorFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Color} from './types';\nimport {FocusableProps, HelpTextProps, InputBase, LabelableProps, TextInputBase, Validation, ValueBase} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorFieldProps extends Omit<ValueBase<string | Color | null>, 'onChange'>, InputBase, Validation<Color | null>, FocusableProps, TextInputBase, LabelableProps, HelpTextProps {\n /** Handler that is called when the value changes. */\n onChange?: (color: Color | null) => void\n}\n\nexport interface ColorFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n readonly inputValue: string,\n /**\n * The currently parsed color value, or null if the field is empty.\n * Updated based on the `inputValue` as the user types.\n */\n readonly colorValue: Color | null,\n /** The default value of the color field. */\n readonly defaultColorValue: Color | null,\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void,\n /** Sets the current text value of the input. */\n setInputValue(value: string): void,\n /**\n * Updates the input value based on the currently parsed color value.\n * Typically this is called when the field is blurred.\n */\n commit(): void,\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void,\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void,\n /** Sets the current value to the maximum color value, and fires `onChange`. */\n incrementToMax(): void,\n /** Sets the current value to the minimum color value, and fires `onChange`. */\n decrementToMin(): void,\n /**\n * Validates a user input string.\n * Values can be partially entered, and may be valid even if they cannot currently be parsed to a color.\n * Can be used to implement validation as a user types.\n */\n validate(value: string): boolean\n}\n\nconst MIN_COLOR = parseColor('#000000');\nconst MAX_COLOR = parseColor('#FFFFFF');\nconst MIN_COLOR_INT = MIN_COLOR.toHexInt();\nconst MAX_COLOR_INT = MAX_COLOR.toHexInt();\n\n/**\n * Provides state management for a color field component. Color fields allow\n * users to enter and adjust a hex color value.\n */\nexport function useColorFieldState(\n props: ColorFieldProps\n): ColorFieldState {\n let {\n value,\n defaultValue,\n onChange\n } = props;\n let {step} = MIN_COLOR.getChannelRange('red');\n\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color | null>(useColor(value), initialDefaultValue!, onChange);\n let [initialValue] = useState(colorValue);\n let [inputValue, setInputValue] = useState(() => (value || defaultValue) && colorValue ? colorValue.toString('hex') : '');\n\n let validation = useFormValidationState({\n ...props,\n value: colorValue\n });\n\n let safelySetColorValue = (newColor: Color | null) => {\n if (!colorValue || !newColor) {\n setColorValue(newColor);\n return;\n }\n if (newColor.toHexInt() !== colorValue.toHexInt()) {\n setColorValue(newColor);\n return;\n }\n };\n\n let [prevValue, setPrevValue] = useState(colorValue);\n if (prevValue !== colorValue) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n setPrevValue(colorValue);\n }\n\n let parsedValue = useMemo(() => {\n let color;\n try {\n color = parseColor(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);\n } catch {\n color = null;\n }\n return color;\n }, [inputValue]);\n\n let commit = () => {\n // Set to empty state if input value is empty\n if (!inputValue.length) {\n safelySetColorValue(null);\n if (value === undefined || colorValue === null) {\n setInputValue('');\n } else {\n setInputValue(colorValue.toString('hex'));\n }\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (parsedValue == null) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n return;\n }\n\n safelySetColorValue(parsedValue);\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n let newColorValue = '';\n if (colorValue) {\n newColorValue = colorValue.toString('hex');\n }\n setInputValue(newColorValue);\n validation.commitValidation();\n };\n\n let increment = () => {\n let newValue = addColorValue(parsedValue, step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let decrement = () => {\n let newValue = addColorValue(parsedValue, -step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let incrementToMax = () => safelySetColorValue(MAX_COLOR);\n let decrementToMin = () => safelySetColorValue(MIN_COLOR);\n\n let validate = (value: string) => value === '' || !!value.match(/^#?[0-9a-f]{0,6}$/i)?.[0];\n\n return {\n ...validation,\n validate,\n colorValue,\n defaultColorValue: initialDefaultValue ?? initialValue,\n setColorValue,\n inputValue,\n setInputValue,\n commit,\n increment,\n incrementToMax,\n decrement,\n decrementToMin\n };\n}\n\nfunction addColorValue(color: Color, step: number) {\n let newColor = color ? color : MIN_COLOR;\n let colorInt = newColor.toHexInt();\n\n let clampInt = Math.min(Math.max(colorInt + step, MIN_COLOR_INT), MAX_COLOR_INT);\n if (clampInt !== colorInt) {\n let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;\n newColor = parseColor(newColorString);\n }\n return newColor;\n}\n"],"names":[],"version":3,"file":"useColorFieldState.js.map"}
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAoED,MAAM,kCAAY,CAAA,GAAA,wCAAS,EAAE;AAC7B,MAAM,kCAAY,CAAA,GAAA,wCAAS,EAAE;AAC7B,MAAM,sCAAgB,gCAAU,QAAQ;AACxC,MAAM,sCAAgB,gCAAU,QAAQ;AAMjC,SAAS,0CAAmB,KAAsB;IACvD,IAAI,SAAC,KAAK,gBAAE,YAAY,YAAE,QAAQ,EAAC,GAAG;IACtC,IAAI,QAAC,IAAI,EAAC,GAAG,gCAAU,eAAe,CAAC;IAEvC,IAAI,sBAAsB,CAAA,GAAA,yCAAO,EAAE;IACnC,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,yCAAiB,EACjD,CAAA,GAAA,yCAAO,EAAE,QACT,qBACA;IAEF,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,eAAO,EAAE,IACzC,AAAC,CAAA,SAAS,YAAW,KAAM,aAAa,WAAW,QAAQ,CAAC,SAAS;IAGvE,IAAI,aAAa,CAAA,GAAA,yCAAqB,EAAE;QACtC,GAAG,KAAK;QACR,OAAO;IACT;IAEA,IAAI,sBAAsB,CAAC;QACzB,IAAI,CAAC,cAAc,CAAC,UAAU;YAC5B,cAAc;YACd;QACF;QACA,IAAI,SAAS,QAAQ,OAAO,WAAW,QAAQ,IAAI;YACjD,cAAc;YACd;QACF;IACF;IAEA,IAAI,CAA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E/C,IAAI,WAAW,CAAC;YAAoC;eAAlB,UAAU,MAAM,CAAC,GAAC,eAAA,MAAM,KAAK,CAAC,mCAAZ,mCAAA,YAAmC,CAAC,EAAE;;IAE1F,OAAO;QACL,GAAG,UAAU;kBACb;oBACA;QACA,mBAAmB,gCAAA,iCAAA,sBAAuB;uBAC1C;oBACA;uBACA;gBACA;mBACA;wBACA;mBACA;wBACA;IACF;AACF;AAEA,SAAS,oCAAc,KAAY,EAAE,IAAY;IAC/C,IAAI,WAAW,QAAQ,QAAQ;IAC/B,IAAI,WAAW,SAAS,QAAQ;IAEhC,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,WAAW,MAAM,sCAAgB;IAClE,IAAI,aAAa,UAAU;QACzB,IAAI,iBAAiB,CAAC,CAAC,EAAE,SAAS,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,KAAK,WAAW,IAAI;QAC/E,WAAW,CAAA,GAAA,wCAAS,EAAE;IACxB;IACA,OAAO;AACT","sources":["packages/react-stately/src/color/useColorFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Color} from './types';\nimport {\n FocusableProps,\n HelpTextProps,\n InputBase,\n LabelableProps,\n TextInputBase,\n Validation,\n ValueBase\n} from '@react-types/shared';\nimport {FormValidationState, useFormValidationState} from '../form/useFormValidationState';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorFieldProps\n extends\n Omit<ValueBase<string | Color | null>, 'onChange'>,\n InputBase,\n Validation<Color | null>,\n FocusableProps,\n TextInputBase,\n LabelableProps,\n HelpTextProps {\n /** Handler that is called when the value changes. */\n onChange?: (color: Color | null) => void;\n}\n\nexport interface ColorFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n readonly inputValue: string;\n /**\n * The currently parsed color value, or null if the field is empty.\n * Updated based on the `inputValue` as the user types.\n */\n readonly colorValue: Color | null;\n /** The default value of the color field. */\n readonly defaultColorValue: Color | null;\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void;\n /** Sets the current text value of the input. */\n setInputValue(value: string): void;\n /**\n * Updates the input value based on the currently parsed color value.\n * Typically this is called when the field is blurred.\n */\n commit(): void;\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void;\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void;\n /** Sets the current value to the maximum color value, and fires `onChange`. */\n incrementToMax(): void;\n /** Sets the current value to the minimum color value, and fires `onChange`. */\n decrementToMin(): void;\n /**\n * Validates a user input string. Values can be partially entered, and may be valid even if they\n * cannot currently be parsed to a color. Can be used to implement validation as a user types.\n */\n validate(value: string): boolean;\n}\n\nconst MIN_COLOR = parseColor('#000000');\nconst MAX_COLOR = parseColor('#FFFFFF');\nconst MIN_COLOR_INT = MIN_COLOR.toHexInt();\nconst MAX_COLOR_INT = MAX_COLOR.toHexInt();\n\n/**\n * Provides state management for a color field component. Color fields allow\n * users to enter and adjust a hex color value.\n */\nexport function useColorFieldState(props: ColorFieldProps): ColorFieldState {\n let {value, defaultValue, onChange} = props;\n let {step} = MIN_COLOR.getChannelRange('red');\n\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color | null>(\n useColor(value),\n initialDefaultValue!,\n onChange\n );\n let [initialValue] = useState(colorValue);\n let [inputValue, setInputValue] = useState(() =>\n (value || defaultValue) && colorValue ? colorValue.toString('hex') : ''\n );\n\n let validation = useFormValidationState({\n ...props,\n value: colorValue\n });\n\n let safelySetColorValue = (newColor: Color | null) => {\n if (!colorValue || !newColor) {\n setColorValue(newColor);\n return;\n }\n if (newColor.toHexInt() !== colorValue.toHexInt()) {\n setColorValue(newColor);\n return;\n }\n };\n\n let [prevValue, setPrevValue] = useState(colorValue);\n if (prevValue !== colorValue) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n setPrevValue(colorValue);\n }\n\n let parsedValue = useMemo(() => {\n let color;\n try {\n color = parseColor(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);\n } catch {\n color = null;\n }\n return color;\n }, [inputValue]);\n\n let commit = () => {\n // Set to empty state if input value is empty\n if (!inputValue.length) {\n safelySetColorValue(null);\n if (value === undefined || colorValue === null) {\n setInputValue('');\n } else {\n setInputValue(colorValue.toString('hex'));\n }\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (parsedValue == null) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n return;\n }\n\n safelySetColorValue(parsedValue);\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n let newColorValue = '';\n if (colorValue) {\n newColorValue = colorValue.toString('hex');\n }\n setInputValue(newColorValue);\n validation.commitValidation();\n };\n\n let increment = () => {\n let newValue = addColorValue(parsedValue, step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let decrement = () => {\n let newValue = addColorValue(parsedValue, -step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let incrementToMax = () => safelySetColorValue(MAX_COLOR);\n let decrementToMin = () => safelySetColorValue(MIN_COLOR);\n\n let validate = (value: string) => value === '' || !!value.match(/^#?[0-9a-f]{0,6}$/i)?.[0];\n\n return {\n ...validation,\n validate,\n colorValue,\n defaultColorValue: initialDefaultValue ?? initialValue,\n setColorValue,\n inputValue,\n setInputValue,\n commit,\n increment,\n incrementToMax,\n decrement,\n decrementToMin\n };\n}\n\nfunction addColorValue(color: Color, step: number) {\n let newColor = color ? color : MIN_COLOR;\n let colorInt = newColor.toHexInt();\n\n let clampInt = Math.min(Math.max(colorInt + step, MIN_COLOR_INT), MAX_COLOR_INT);\n if (clampInt !== colorInt) {\n let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;\n newColor = parseColor(newColorString);\n }\n return newColor;\n}\n"],"names":[],"version":3,"file":"useColorFieldState.js.map"}
|