jaci-ui 0.9.4 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +11 -1
- package/dist/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/components/accordion/accordion.cjs.map +1 -1
- package/dist/components/accordion/accordion.js.map +1 -1
- package/dist/components/alert/alert.cjs.map +1 -1
- package/dist/components/alert/alert.js.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.cjs.map +1 -1
- package/dist/components/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/components/aspect-ratio/aspect-ratio.cjs.map +1 -1
- package/dist/components/avatar/avatar.cjs.map +1 -1
- package/dist/components/avatar/avatar.js.map +1 -1
- package/dist/components/breadcrumbs/breadcrumbs.cjs.map +1 -1
- package/dist/components/button/button.cjs +1 -0
- package/dist/components/button/button.cjs.map +1 -1
- package/dist/components/button/button.d.cts +2 -1
- package/dist/components/button/button.d.ts +2 -1
- package/dist/components/button/button.js +1 -0
- package/dist/components/button/button.js.map +1 -1
- package/dist/components/button-group/button-group.cjs.map +1 -1
- package/dist/components/calendar/calendar.cjs +4 -6
- package/dist/components/calendar/calendar.cjs.map +1 -1
- package/dist/components/calendar/calendar.js +4 -6
- package/dist/components/calendar/calendar.js.map +1 -1
- package/dist/components/card/card.cjs.map +1 -1
- package/dist/components/carousel/carousel.cjs.map +1 -1
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.cjs +7 -3
- package/dist/components/checkbox-group/checkbox-group.cjs.map +1 -1
- package/dist/components/checkbox-group/checkbox-group.js +7 -3
- package/dist/components/checkbox-group/checkbox-group.js.map +1 -1
- package/dist/components/code/code.cjs.map +1 -1
- package/dist/components/code/code.js.map +1 -1
- package/dist/components/collapsible/collapsible.cjs.map +1 -1
- package/dist/components/collapsible/collapsible.js.map +1 -1
- package/dist/components/color-picker/color-picker.cjs.map +1 -1
- package/dist/components/color-picker/color-picker.js.map +1 -1
- package/dist/components/color-picker/color-utils.cjs +5 -3
- package/dist/components/color-picker/color-utils.cjs.map +1 -1
- package/dist/components/color-picker/color-utils.js +5 -3
- package/dist/components/color-picker/color-utils.js.map +1 -1
- package/dist/components/color-swatch/color-swatch.cjs.map +1 -1
- package/dist/components/combobox/combobox.cjs +2 -1
- package/dist/components/combobox/combobox.cjs.map +1 -1
- package/dist/components/combobox/combobox.js +2 -1
- package/dist/components/combobox/combobox.js.map +1 -1
- package/dist/components/command/command.cjs.map +1 -1
- package/dist/components/command/command.js.map +1 -1
- package/dist/components/context-menu/context-menu.cjs.map +1 -1
- package/dist/components/context-menu/context-menu.d.cts +2 -2
- package/dist/components/context-menu/context-menu.d.ts +2 -2
- package/dist/components/controls/checkbox.cjs.map +1 -1
- package/dist/components/controls/checkbox.js.map +1 -1
- package/dist/components/controls/input.cjs.map +1 -1
- package/dist/components/controls/input.js.map +1 -1
- package/dist/components/controls/radio.cjs.map +1 -1
- package/dist/components/controls/switch.cjs.map +1 -1
- package/dist/components/controls/switch.js.map +1 -1
- package/dist/components/controls/textarea.cjs.map +1 -1
- package/dist/components/controls/textarea.js.map +1 -1
- package/dist/components/copyable/copyable.cjs.map +1 -1
- package/dist/components/copyable/copyable.js.map +1 -1
- package/dist/components/data-toolbar/data-toolbar.cjs.map +1 -1
- package/dist/components/data-toolbar/data-toolbar.js.map +1 -1
- package/dist/components/data-view/data-view.cjs.map +1 -1
- package/dist/components/date-picker/date-picker.cjs +4 -7
- package/dist/components/date-picker/date-picker.cjs.map +1 -1
- package/dist/components/date-picker/date-picker.js +4 -7
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/date-range-picker/date-range-picker.cjs +4 -6
- package/dist/components/date-range-picker/date-range-picker.cjs.map +1 -1
- package/dist/components/date-range-picker/date-range-picker.js +4 -6
- package/dist/components/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/components/dialog/dialog.cjs.map +1 -1
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/download-trigger/download-trigger.cjs.map +1 -1
- package/dist/components/drawer/drawer.cjs.map +1 -1
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/empty-state/empty-state.cjs.map +1 -1
- package/dist/components/feedback/badge.cjs.map +1 -1
- package/dist/components/field/field.cjs.map +1 -1
- package/dist/components/field/field.js.map +1 -1
- package/dist/components/fieldset/fieldset.cjs.map +1 -1
- package/dist/components/figure/figure.cjs.map +1 -1
- package/dist/components/figure/figure.js.map +1 -1
- package/dist/components/form/form.cjs.map +1 -1
- package/dist/components/form/form.js.map +1 -1
- package/dist/components/icon-button/icon-button.cjs.map +1 -1
- package/dist/components/icon-button/icon-button.js.map +1 -1
- package/dist/components/image/image.cjs.map +1 -1
- package/dist/components/image/image.js.map +1 -1
- package/dist/components/input-group/input-group.cjs.map +1 -1
- package/dist/components/kbd/kbd.cjs.map +1 -1
- package/dist/components/layout/index.cjs.map +1 -1
- package/dist/components/list/list.cjs.map +1 -1
- package/dist/components/menu/menu.cjs.map +1 -1
- package/dist/components/menu/menu.d.cts +2 -2
- package/dist/components/menu/menu.d.ts +2 -2
- package/dist/components/menubar/menubar.cjs.map +1 -1
- package/dist/components/menubar/menubar.d.cts +2 -2
- package/dist/components/menubar/menubar.d.ts +2 -2
- package/dist/components/menubar/menubar.js.map +1 -1
- package/dist/components/meter/meter.cjs.map +1 -1
- package/dist/components/meter/meter.js.map +1 -1
- package/dist/components/navigation/navigation.cjs.map +1 -1
- package/dist/components/navigation/navigation.js.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.cjs.map +1 -1
- package/dist/components/navigation-menu/navigation-menu.js.map +1 -1
- package/dist/components/number-field/number-field.cjs +2 -1
- package/dist/components/number-field/number-field.cjs.map +1 -1
- package/dist/components/number-field/number-field.js +2 -1
- package/dist/components/number-field/number-field.js.map +1 -1
- package/dist/components/option-selector/option-selector.cjs.map +1 -1
- package/dist/components/option-selector/option-selector.js.map +1 -1
- package/dist/components/pagination/pagination.cjs.map +1 -1
- package/dist/components/pagination/pagination.js.map +1 -1
- package/dist/components/pin-input/pin-input.cjs.map +1 -1
- package/dist/components/pin-input/pin-input.js.map +1 -1
- package/dist/components/popover/popover.cjs.map +1 -1
- package/dist/components/popover/popover.js.map +1 -1
- package/dist/components/progress/progress.cjs.map +1 -1
- package/dist/components/progress/progress.js.map +1 -1
- package/dist/components/qr-code/qr-code.cjs.map +1 -1
- package/dist/components/qr-code/qr-code.js.map +1 -1
- package/dist/components/quote/quote.cjs.map +1 -1
- package/dist/components/quote/quote.js.map +1 -1
- package/dist/components/radio-group/radio-group.cjs +7 -3
- package/dist/components/radio-group/radio-group.cjs.map +1 -1
- package/dist/components/radio-group/radio-group.js +7 -3
- package/dist/components/radio-group/radio-group.js.map +1 -1
- package/dist/components/range-slider/range-slider.cjs.map +1 -1
- package/dist/components/range-slider/range-slider.js.map +1 -1
- package/dist/components/scroll-area/scroll-area.cjs.map +1 -1
- package/dist/components/select/select.cjs.map +1 -1
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/sidebar/sidebar.cjs.map +1 -1
- package/dist/components/sidebar/sidebar.js.map +1 -1
- package/dist/components/skeleton/skeleton.cjs.map +1 -1
- package/dist/components/slider/slider.cjs.map +1 -1
- package/dist/components/slider/slider.js.map +1 -1
- package/dist/components/spacer/spacer.cjs.map +1 -1
- package/dist/components/stat/stat.cjs.map +1 -1
- package/dist/components/stat/stat.js.map +1 -1
- package/dist/components/stepper/stepper.cjs +2 -1
- package/dist/components/stepper/stepper.cjs.map +1 -1
- package/dist/components/stepper/stepper.js +2 -1
- package/dist/components/stepper/stepper.js.map +1 -1
- package/dist/components/table/table.cjs.map +1 -1
- package/dist/components/table/table.js.map +1 -1
- package/dist/components/tabs/tabs.cjs.map +1 -1
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/tags-input/tags-input.cjs +10 -9
- package/dist/components/tags-input/tags-input.cjs.map +1 -1
- package/dist/components/tags-input/tags-input.js +10 -9
- package/dist/components/tags-input/tags-input.js.map +1 -1
- package/dist/components/toast/toast.cjs.map +1 -1
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/toggle/toggle.cjs.map +1 -1
- package/dist/components/toggle-group/toggle-group.cjs.map +1 -1
- package/dist/components/toolbar/toolbar.cjs.map +1 -1
- package/dist/components/tooltip/tooltip.cjs.map +1 -1
- package/dist/components/tree-view/tree-view.cjs.map +1 -1
- package/dist/components/tree-view/tree-view.js.map +1 -1
- package/dist/components/typography/heading.cjs.map +1 -1
- package/dist/components/typography/link.cjs.map +1 -1
- package/dist/components/typography/paragraph.cjs.map +1 -1
- package/dist/components/typography/text.cjs.map +1 -1
- package/dist/components/upload/upload.cjs +2 -2
- package/dist/components/upload/upload.cjs.map +1 -1
- package/dist/components/upload/upload.js +2 -2
- package/dist/components/upload/upload.js.map +1 -1
- package/dist/components/visually-hidden/visually-hidden.cjs.map +1 -1
- package/dist/panda-preset.cjs.map +1 -1
- package/dist/styles/theme.cjs +18 -18
- package/dist/styles/theme.cjs.map +1 -1
- package/dist/styles/theme.js +18 -18
- package/dist/styles/theme.js.map +1 -1
- package/dist/styles.css +12 -21
- package/dist/theme/theme-provider.cjs.map +1 -1
- package/dist/theme/theme-provider.js.map +1 -1
- package/dist/theme/theme-scope.cjs.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox-group.cjs","names":["
|
|
1
|
+
{"version":3,"file":"checkbox-group.cjs","names":["checkboxGroup","cx","Field","BaseCheckboxGroup","forwardRef","BaseField","withRecipeClassName","BaseCheckbox"],"sources":["../../../src/components/checkbox-group/checkbox-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { Checkbox as BaseCheckbox } from \"@base-ui/react/checkbox\";\nimport { CheckboxGroup as BaseCheckboxGroup } from \"@base-ui/react/checkbox-group\";\nimport { Field as BaseField } from \"@base-ui/react/field\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport type { CheckboxGroup as BaseCheckboxGroupType } from \"@base-ui/react/checkbox-group\";\nimport type { CheckboxRoot as BaseCheckboxRoot } from \"@base-ui/react/checkbox\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { checkboxGroup } from \"../../styled-system/recipes\";\nimport { withRecipeClassName } from \"../base-ui\";\nimport { Field } from \"../field\";\n\nexport interface CheckboxGroupRootProps\n extends Omit<BaseCheckboxGroupType.Props, \"children\" | \"className\" | \"onValueChange\"> {\n /** Marks the group invalid when an external validator owns its state. */\n invalid?: boolean;\n /** Direct error content rendered through the surrounding Field context. */\n errors?: ReactNode | ReactNode[];\n children?: ReactNode;\n className?: string;\n name?: string;\n onValueChange?: (value: string[]) => void;\n}\n\nexport function CheckboxGroupRoot({\n children,\n className,\n errors,\n invalid,\n name,\n onValueChange,\n ...props\n}: CheckboxGroupRootProps) {\n const styles = checkboxGroup();\n const fieldProps = {\n className: cx(styles.root, className),\n ...(errors === undefined ? {} : { errors }),\n ...(invalid === undefined ? {} : { invalid }),\n ...(name === undefined ? {} : { name }),\n };\n\n return (\n <Field {...fieldProps}>\n <BaseCheckboxGroup {...props} onValueChange={(value) => onValueChange?.(value)}>\n {children}\n </BaseCheckboxGroup>\n </Field>\n );\n}\n\nexport type CheckboxGroupLabelProps = ComponentPropsWithoutRef<typeof BaseField.Label>;\n\nexport const CheckboxGroupLabel = forwardRef<HTMLElement, CheckboxGroupLabelProps>(\n function CheckboxGroupLabel({ className, ...props }, ref) {\n return (\n <BaseField.Label\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().label, className)}\n data-slot=\"checkbox-group-label\"\n />\n );\n },\n);\n\nexport type CheckboxGroupOptionProps = ComponentPropsWithoutRef<\"label\">;\n\nexport const CheckboxGroupOption = forwardRef<HTMLLabelElement, CheckboxGroupOptionProps>(\n function CheckboxGroupOption({ children, className, htmlFor, ...props }, ref) {\n return (\n <label\n {...props}\n ref={ref}\n className={cx(checkboxGroup().option, className)}\n data-slot=\"checkbox-group-option\"\n htmlFor={htmlFor}\n >\n {children}\n </label>\n );\n },\n);\n\nexport type CheckboxGroupOptionsProps = ComponentPropsWithoutRef<\"div\">;\n\nexport const CheckboxGroupOptions = forwardRef<HTMLDivElement, CheckboxGroupOptionsProps>(\n function CheckboxGroupOptions({ className, ...props }, ref) {\n return (\n <div\n {...props}\n ref={ref}\n className={cx(checkboxGroup().options, className)}\n data-slot=\"checkbox-group-options\"\n />\n );\n },\n);\n\nexport type CheckboxGroupItemProps = BaseCheckboxRoot.Props;\n\nexport const CheckboxGroupItem = forwardRef<HTMLElement, CheckboxGroupItemProps>(\n function CheckboxGroupItem({ className, ...props }, ref) {\n return (\n <BaseCheckbox.Root\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().checkbox, className)}\n data-slot=\"checkbox-group-item\"\n />\n );\n },\n);\n\nexport type CheckboxGroupIndicatorProps = ComponentPropsWithoutRef<typeof BaseCheckbox.Indicator>;\n\nexport const CheckboxGroupIndicator = forwardRef<HTMLSpanElement, CheckboxGroupIndicatorProps>(\n function CheckboxGroupIndicator({ children, className, ...props }, ref) {\n return (\n <BaseCheckbox.Indicator\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().indicator, className)}\n data-slot=\"checkbox-group-indicator\"\n >\n {children ?? \"✓\"}\n </BaseCheckbox.Indicator>\n );\n },\n);\n\nexport const CheckboxGroup = {\n Root: CheckboxGroupRoot,\n Label: CheckboxGroupLabel,\n Options: CheckboxGroupOptions,\n Option: CheckboxGroupOption,\n Item: CheckboxGroupItem,\n Indicator: CheckboxGroupIndicator,\n};\n"],"mappings":";;;;;;;;;;;AA2BA,SAAgB,kBAAkB,EAChC,UACA,WACA,QACA,SACA,MACA,eACA,GAAG,SACsB;CACzB,MAAM,SAASA,uBAAAA,cAAc;CAC7B,MAAM,aAAa;EACjB,WAAWC,WAAAA,GAAG,OAAO,MAAM,SAAS;EACpC,GAAI,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,O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S,KAAK;CACvD,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACG,wBAAAA,SAAa,MAAd;EACE,GAAI;EACC;EACL,WAAWD,gBAAAA,oBAAoBN,uBAAAA,cAAc,CAAC,CAAC,UAAU,SAAS;EAClE,aAAU;CACX,CAAA;AAEL,CACF;AAIA,MAAa,0BAAA,GAAyBI,MAAAA,WAAAA,CACpC,SAAS,uBAAuB,EAAE,UAAU,WAAW,GAAG,SAAS,KAAK;CACtE,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACG,wBAAAA,SAAa,WAAd;EACE,GAAI;EACC;EACL,WAAWD,gBAAAA,oBAAoBN,uBAAAA,cAAc,CAAC,CAAC,WAAW,SAAS;EACnE,aAAU;EAET,UAAA,YAAY;CACS,CAAA;AAE5B,CACF;AAEA,MAAa,gBAAgB;CAC3B,MAAM;CACN,OAAO;CACP,SAAS;CACT,QAAQ;CACR,MAAM;CACN,WAAW;AACb"}
|
|
@@ -10,11 +10,15 @@ import { CheckboxGroup } from "@base-ui/react/checkbox-group";
|
|
|
10
10
|
import { Field } from "@base-ui/react/field";
|
|
11
11
|
//#region src/components/checkbox-group/checkbox-group.tsx
|
|
12
12
|
function CheckboxGroupRoot({ children, className, errors, invalid, name, onValueChange, ...props }) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const styles = checkboxGroup();
|
|
14
|
+
const fieldProps = {
|
|
15
|
+
className: cx(styles.root, className),
|
|
15
16
|
...errors === void 0 ? {} : { errors },
|
|
16
17
|
...invalid === void 0 ? {} : { invalid },
|
|
17
|
-
...name === void 0 ? {} : { name }
|
|
18
|
+
...name === void 0 ? {} : { name }
|
|
19
|
+
};
|
|
20
|
+
return /* @__PURE__ */ jsx(Field$1, {
|
|
21
|
+
...fieldProps,
|
|
18
22
|
children: /* @__PURE__ */ jsx(CheckboxGroup, {
|
|
19
23
|
...props,
|
|
20
24
|
onValueChange: (value) => onValueChange?.(value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkbox-group.js","names":["Field","BaseCheckboxGroup","BaseField","BaseCheckbox","CheckboxGroup"],"sources":["../../../src/components/checkbox-group/checkbox-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { Checkbox as BaseCheckbox } from \"@base-ui/react/checkbox\";\nimport { CheckboxGroup as BaseCheckboxGroup } from \"@base-ui/react/checkbox-group\";\nimport { Field as BaseField } from \"@base-ui/react/field\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport type { CheckboxGroup as BaseCheckboxGroupType } from \"@base-ui/react/checkbox-group\";\nimport type { CheckboxRoot as BaseCheckboxRoot } from \"@base-ui/react/checkbox\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { checkboxGroup } from \"../../styled-system/recipes\";\nimport { withRecipeClassName } from \"../base-ui\";\nimport { Field } from \"../field\";\n\nexport interface CheckboxGroupRootProps\n extends Omit<BaseCheckboxGroupType.Props, \"children\" | \"className\" | \"onValueChange\"> {\n /** Marks the group invalid when an external validator owns its state. */\n invalid?: boolean;\n /** Direct error content rendered through the surrounding Field context. */\n errors?: ReactNode | ReactNode[];\n children?: ReactNode;\n className?: string;\n name?: string;\n onValueChange?: (value: string[]) => void;\n}\n\nexport function CheckboxGroupRoot({\n children,\n className,\n errors,\n invalid,\n name,\n onValueChange,\n ...props\n}: CheckboxGroupRootProps) {\n const styles = checkboxGroup();\n const fieldProps = {\n className: cx(styles.root, className),\n ...(errors === undefined ? {} : { errors }),\n ...(invalid === undefined ? {} : { invalid }),\n ...(name === undefined ? {} : { name }),\n };\n\n return (\n <Field {...fieldProps}>\n <BaseCheckboxGroup {...props} onValueChange={(value) => onValueChange?.(value)}>\n {children}\n </BaseCheckboxGroup>\n </Field>\n );\n}\n\nexport type CheckboxGroupLabelProps = ComponentPropsWithoutRef<typeof BaseField.Label>;\n\nexport const CheckboxGroupLabel = forwardRef<HTMLElement, CheckboxGroupLabelProps>(\n function CheckboxGroupLabel({ className, ...props }, ref) {\n return (\n <BaseField.Label\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().label, className)}\n data-slot=\"checkbox-group-label\"\n />\n );\n },\n);\n\nexport type CheckboxGroupOptionProps = ComponentPropsWithoutRef<\"label\">;\n\nexport const CheckboxGroupOption = forwardRef<HTMLLabelElement, CheckboxGroupOptionProps>(\n function CheckboxGroupOption({ children, className, htmlFor, ...props }, ref) {\n return (\n <label\n {...props}\n ref={ref}\n className={cx(checkboxGroup().option, className)}\n data-slot=\"checkbox-group-option\"\n htmlFor={htmlFor}\n >\n {children}\n </label>\n );\n },\n);\n\nexport type CheckboxGroupOptionsProps = ComponentPropsWithoutRef<\"div\">;\n\nexport const CheckboxGroupOptions = forwardRef<HTMLDivElement, CheckboxGroupOptionsProps>(\n function CheckboxGroupOptions({ className, ...props }, ref) {\n return (\n <div\n {...props}\n ref={ref}\n className={cx(checkboxGroup().options, className)}\n data-slot=\"checkbox-group-options\"\n />\n );\n },\n);\n\nexport type CheckboxGroupItemProps = BaseCheckboxRoot.Props;\n\nexport const CheckboxGroupItem = forwardRef<HTMLElement, CheckboxGroupItemProps>(\n function CheckboxGroupItem({ className, ...props }, ref) {\n return (\n <BaseCheckbox.Root\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().checkbox, className)}\n data-slot=\"checkbox-group-item\"\n />\n );\n },\n);\n\nexport type CheckboxGroupIndicatorProps = ComponentPropsWithoutRef<typeof BaseCheckbox.Indicator>;\n\nexport const CheckboxGroupIndicator = forwardRef<HTMLSpanElement, CheckboxGroupIndicatorProps>(\n function CheckboxGroupIndicator({ children, className, ...props }, ref) {\n return (\n <BaseCheckbox.Indicator\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().indicator, className)}\n data-slot=\"checkbox-group-indicator\"\n >\n {children ?? \"✓\"}\n </BaseCheckbox.Indicator>\n );\n },\n);\n\nexport const CheckboxGroup = {\n Root: CheckboxGroupRoot,\n Label: CheckboxGroupLabel,\n Options: CheckboxGroupOptions,\n Option: CheckboxGroupOption,\n Item: CheckboxGroupItem,\n Indicator: CheckboxGroupIndicator,\n};\n"],"mappings":";;;;;;;;;;;AA2BA,SAAgB,kBAAkB,EAChC,UACA,WACA,QACA,SACA,MACA,eACA,GAAG,SACsB;
|
|
1
|
+
{"version":3,"file":"checkbox-group.js","names":["Field","BaseCheckboxGroup","BaseField","BaseCheckbox","CheckboxGroup"],"sources":["../../../src/components/checkbox-group/checkbox-group.tsx"],"sourcesContent":["\"use client\";\n\nimport { Checkbox as BaseCheckbox } from \"@base-ui/react/checkbox\";\nimport { CheckboxGroup as BaseCheckboxGroup } from \"@base-ui/react/checkbox-group\";\nimport { Field as BaseField } from \"@base-ui/react/field\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport type { CheckboxGroup as BaseCheckboxGroupType } from \"@base-ui/react/checkbox-group\";\nimport type { CheckboxRoot as BaseCheckboxRoot } from \"@base-ui/react/checkbox\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { checkboxGroup } from \"../../styled-system/recipes\";\nimport { withRecipeClassName } from \"../base-ui\";\nimport { Field } from \"../field\";\n\nexport interface CheckboxGroupRootProps\n extends Omit<BaseCheckboxGroupType.Props, \"children\" | \"className\" | \"onValueChange\"> {\n /** Marks the group invalid when an external validator owns its state. */\n invalid?: boolean;\n /** Direct error content rendered through the surrounding Field context. */\n errors?: ReactNode | ReactNode[];\n children?: ReactNode;\n className?: string;\n name?: string;\n onValueChange?: (value: string[]) => void;\n}\n\nexport function CheckboxGroupRoot({\n children,\n className,\n errors,\n invalid,\n name,\n onValueChange,\n ...props\n}: CheckboxGroupRootProps) {\n const styles = checkboxGroup();\n const fieldProps = {\n className: cx(styles.root, className),\n ...(errors === undefined ? {} : { errors }),\n ...(invalid === undefined ? {} : { invalid }),\n ...(name === undefined ? {} : { name }),\n };\n\n return (\n <Field {...fieldProps}>\n <BaseCheckboxGroup {...props} onValueChange={(value) => onValueChange?.(value)}>\n {children}\n </BaseCheckboxGroup>\n </Field>\n );\n}\n\nexport type CheckboxGroupLabelProps = ComponentPropsWithoutRef<typeof BaseField.Label>;\n\nexport const CheckboxGroupLabel = forwardRef<HTMLElement, CheckboxGroupLabelProps>(\n function CheckboxGroupLabel({ className, ...props }, ref) {\n return (\n <BaseField.Label\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().label, className)}\n data-slot=\"checkbox-group-label\"\n />\n );\n },\n);\n\nexport type CheckboxGroupOptionProps = ComponentPropsWithoutRef<\"label\">;\n\nexport const CheckboxGroupOption = forwardRef<HTMLLabelElement, CheckboxGroupOptionProps>(\n function CheckboxGroupOption({ children, className, htmlFor, ...props }, ref) {\n return (\n <label\n {...props}\n ref={ref}\n className={cx(checkboxGroup().option, className)}\n data-slot=\"checkbox-group-option\"\n htmlFor={htmlFor}\n >\n {children}\n </label>\n );\n },\n);\n\nexport type CheckboxGroupOptionsProps = ComponentPropsWithoutRef<\"div\">;\n\nexport const CheckboxGroupOptions = forwardRef<HTMLDivElement, CheckboxGroupOptionsProps>(\n function CheckboxGroupOptions({ className, ...props }, ref) {\n return (\n <div\n {...props}\n ref={ref}\n className={cx(checkboxGroup().options, className)}\n data-slot=\"checkbox-group-options\"\n />\n );\n },\n);\n\nexport type CheckboxGroupItemProps = BaseCheckboxRoot.Props;\n\nexport const CheckboxGroupItem = forwardRef<HTMLElement, CheckboxGroupItemProps>(\n function CheckboxGroupItem({ className, ...props }, ref) {\n return (\n <BaseCheckbox.Root\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().checkbox, className)}\n data-slot=\"checkbox-group-item\"\n />\n );\n },\n);\n\nexport type CheckboxGroupIndicatorProps = ComponentPropsWithoutRef<typeof BaseCheckbox.Indicator>;\n\nexport const CheckboxGroupIndicator = forwardRef<HTMLSpanElement, CheckboxGroupIndicatorProps>(\n function CheckboxGroupIndicator({ children, className, ...props }, ref) {\n return (\n <BaseCheckbox.Indicator\n {...props}\n ref={ref}\n className={withRecipeClassName(checkboxGroup().indicator, className)}\n data-slot=\"checkbox-group-indicator\"\n >\n {children ?? \"✓\"}\n </BaseCheckbox.Indicator>\n );\n },\n);\n\nexport const CheckboxGroup = {\n Root: CheckboxGroupRoot,\n Label: CheckboxGroupLabel,\n Options: CheckboxGroupOptions,\n Option: CheckboxGroupOption,\n Item: CheckboxGroupItem,\n Indicator: CheckboxGroupIndicator,\n};\n"],"mappings":";;;;;;;;;;;AA2BA,SAAgB,kBAAkB,EAChC,UACA,WACA,QACA,SACA,MACA,eACA,GAAG,SACsB;CACzB,MAAM,SAAS,cAAc;CAC7B,MAAM,aAAa;EACjB,WAAW,GAAG,OAAO,MAAM,SAAS;EACpC,GAAI,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,OAAO;EACzC,GAAI,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ;EAC3C,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;CACvC;CAEA,OACE,oBAACA,SAAD;EAAO,GAAI;EACT,UAAA,oBAACC,eAAD;GAAmB,GAAI;GAAO,gBAAgB,UAAU,gBAAgB,KAAK;GAC1E;EACgB,CAAA;CACd,CAAA;AAEX;AAIA,MAAa,qBAAqB,WAChC,SAAS,mBAAmB,EAAE,WAAW,GAAG,SAAS,KAAK;CACxD,OACE,oBAACC,MAAU,OAAX;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,cAAc,CAAC,CAAC,OAAO,SAAS;EAC/D,aAAU;CACX,CAAA;AAEL,CACF;AAIA,MAAa,sBAAsB,WACjC,SAAS,oBAAoB,EAAE,UAAU,WAAW,SAAS,GAAG,SAAS,KAAK;CAC5E,OACE,oBAAC,SAAD;EACE,GAAI;EACC;EACL,WAAW,GAAG,cAAc,CAAC,CAAC,QAAQ,SAAS;EAC/C,aAAU;EACD;EAER;CACI,CAAA;AAEX,CACF;AAIA,MAAa,uBAAuB,WAClC,SAAS,qBAAqB,EAAE,WAAW,GAAG,SAAS,KAAK;CAC1D,OACE,oBAAC,OAAD;EACE,GAAI;EACC;EACL,WAAW,GAAG,cAAc,CAAC,CAAC,SAAS,SAAS;EAChD,aAAU;CACX,CAAA;AAEL,CACF;AAIA,MAAa,oBAAoB,WAC/B,SAAS,kBAAkB,EAAE,WAAW,GAAG,SAAS,KAAK;CACvD,OACE,oBAACC,SAAa,MAAd;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,cAAc,CAAC,CAAC,UAAU,SAAS;EAClE,aAAU;CACX,CAAA;AAEL,CACF;AAIA,MAAa,yBAAyB,WACpC,SAAS,uBAAuB,EAAE,UAAU,WAAW,GAAG,SAAS,KAAK;CACtE,OACE,oBAACA,SAAa,WAAd;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,cAAc,CAAC,CAAC,WAAW,SAAS;EACnE,aAAU;EAET,UAAA,YAAY;CACS,CAAA;AAE5B,CACF;AAEA,MAAaC,kBAAgB;CAC3B,MAAM;CACN,OAAO;CACP,SAAS;CACT,QAAQ;CACR,MAAM;CACN,WAAW;AACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.cjs","names":["Children","cx","code"],"sources":["../../../src/components/code/code.tsx"],"sourcesContent":["import { Children, forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { code } from \"../../styled-system/recipes\";\n\nexport type CodeVariant = \"inline\" | \"block\";\n\nexport interface CodeProps extends Omit<ComponentPropsWithoutRef<\"code\">, \"children\"> {\n children?: ReactNode;\n variant?: CodeVariant;\n language?: string;\n wrap?: boolean;\n truncate?: boolean;\n lineNumbers?: boolean;\n}\n\nfunction getTextLines(children: ReactNode) {\n const nodes = Children.toArray(children);\n if (!nodes.every((node) => typeof node === \"string\" || typeof node === \"number\")) return null;\n return nodes.map(String).join(\"\").split(\"\\n\");\n}\n\nfunction getLineKeys(lines: readonly string[]) {\n const occurrences = new Map<string, number>();\n return lines.map((line) => {\n const occurrence = occurrences.get(line) ?? 0;\n occurrences.set(line, occurrence + 1);\n return `line-${line}-${occurrence}`;\n });\n}\n\nexport const Code = forwardRef<HTMLElement, CodeProps>(function Code(\n {\n children,\n className,\n language,\n lineNumbers = false,\n truncate = false,\n variant = \"inline\",\n wrap = false,\n ...props\n },\n ref,\n) {\n const lines = variant === \"block\" && lineNumbers ? getTextLines(children) : null;\n const lineKeys = lines ? getLineKeys(lines) : null;\n const classNames = cx(code({ lineNumbers: Boolean(lines), truncate, variant, wrap }), className);\n\n if (variant === \"block\") {\n return (\n <pre\n {...props}\n ref={ref as React.Ref<HTMLPreElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-line-numbers={lines ? \"true\" : undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {lines ? (\n <span aria-hidden=\"true\" data-slot=\"code-gutter\">\n {lines.map((_, index) => (\n <span data-slot=\"code-line-number\" key={lineKeys?.[index]}>\n {index + 1}\n </span>\n ))}\n </span>\n ) : null}\n <code data-slot=\"code-content\">\n {lines\n ? lines.map((line, index) => (\n <span data-slot=\"code-line\" key={lineKeys?.[index]}>\n {line}\n {index < lines.length - 1 ? \"\\n\" : null}\n </span>\n ))\n : children}\n </code>\n </pre>\n );\n }\n\n return (\n <code\n {...props}\n ref={ref as React.Ref<HTMLElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {children}\n </code>\n );\n});\n"],"mappings":";;;;;AAiBA,SAAS,aAAa,UAAqB;CACzC,MAAM,QAAQA,MAAAA,SAAS,QAAQ,QAAQ;CACvC,IAAI,CAAC,MAAM,OAAO,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS,QAAQ,GAAG,OAAO;CACzF,OAAO,MAAM,IAAI,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,IAAI;AAC9C;AAEA,SAAS,YAAY,OAA0B;CAC7C,MAAM,8BAAc,IAAI,IAAoB;CAC5C,OAAO,MAAM,KAAK,SAAS;EACzB,MAAM,aAAa,YAAY,IAAI,IAAI,KAAK;EAC5C,YAAY,IAAI,MAAM,aAAa,CAAC;EACpC,OAAO,QAAQ,KAAK,GAAG;CACzB,CAAC;AACH;AAEA,MAAa,QAAA,
|
|
1
|
+
{"version":3,"file":"code.cjs","names":["Children","forwardRef","cx","code"],"sources":["../../../src/components/code/code.tsx"],"sourcesContent":["import { Children, forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { code } from \"../../styled-system/recipes\";\n\nexport type CodeVariant = \"inline\" | \"block\";\n\nexport interface CodeProps extends Omit<ComponentPropsWithoutRef<\"code\">, \"children\"> {\n children?: ReactNode;\n variant?: CodeVariant;\n language?: string;\n wrap?: boolean;\n truncate?: boolean;\n lineNumbers?: boolean;\n}\n\nfunction getTextLines(children: ReactNode) {\n const nodes = Children.toArray(children);\n if (!nodes.every((node) => typeof node === \"string\" || typeof node === \"number\")) return null;\n return nodes.map(String).join(\"\").split(\"\\n\");\n}\n\nfunction getLineKeys(lines: readonly string[]) {\n const occurrences = new Map<string, number>();\n return lines.map((line) => {\n const occurrence = occurrences.get(line) ?? 0;\n occurrences.set(line, occurrence + 1);\n return `line-${line}-${occurrence}`;\n });\n}\n\nexport const Code = forwardRef<HTMLElement, CodeProps>(function Code(\n {\n children,\n className,\n language,\n lineNumbers = false,\n truncate = false,\n variant = \"inline\",\n wrap = false,\n ...props\n },\n ref,\n) {\n const lines = variant === \"block\" && lineNumbers ? getTextLines(children) : null;\n const lineKeys = lines ? getLineKeys(lines) : null;\n const classNames = cx(code({ lineNumbers: Boolean(lines), truncate, variant, wrap }), className);\n\n if (variant === \"block\") {\n return (\n <pre\n {...props}\n ref={ref as React.Ref<HTMLPreElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-line-numbers={lines ? \"true\" : undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {lines ? (\n <span aria-hidden=\"true\" data-slot=\"code-gutter\">\n {lines.map((_, index) => (\n <span data-slot=\"code-line-number\" key={lineKeys?.[index]}>\n {index + 1}\n </span>\n ))}\n </span>\n ) : null}\n <code data-slot=\"code-content\">\n {lines\n ? lines.map((line, index) => (\n <span data-slot=\"code-line\" key={lineKeys?.[index]}>\n {line}\n {index < lines.length - 1 ? \"\\n\" : null}\n </span>\n ))\n : children}\n </code>\n </pre>\n );\n }\n\n return (\n <code\n {...props}\n ref={ref as React.Ref<HTMLElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {children}\n </code>\n );\n});\n"],"mappings":";;;;;AAiBA,SAAS,aAAa,UAAqB;CACzC,MAAM,QAAQA,MAAAA,SAAS,QAAQ,QAAQ;CACvC,IAAI,CAAC,MAAM,OAAO,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS,QAAQ,GAAG,OAAO;CACzF,OAAO,MAAM,IAAI,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,IAAI;AAC9C;AAEA,SAAS,YAAY,OAA0B;CAC7C,MAAM,8BAAc,IAAI,IAAoB;CAC5C,OAAO,MAAM,KAAK,SAAS;EACzB,MAAM,aAAa,YAAY,IAAI,IAAI,KAAK;EAC5C,YAAY,IAAI,MAAM,aAAa,CAAC;EACpC,OAAO,QAAQ,KAAK,GAAG;CACzB,CAAC;AACH;AAEA,MAAa,QAAA,GAAOC,MAAAA,WAAAA,CAAmC,SAAS,KAC9D,EACE,UACA,WACA,UACA,cAAc,OACd,WAAW,OACX,UAAU,UACV,OAAO,OACP,GAAG,SAEL,KACA;CACA,MAAM,QAAQ,YAAY,WAAW,cAAc,aAAa,QAAQ,IAAI;CAC5E,MAAM,WAAW,QAAQ,YAAY,KAAK,IAAI;CAC9C,MAAM,aAAaC,WAAAA,GAAGC,aAAAA,KAAK;EAAE,aAAa,QAAQ,KAAK;EAAG;EAAU;EAAS;CAAK,CAAC,GAAG,SAAS;CAE/F,IAAI,YAAY,SACd,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EACE,GAAI;EACC;EACL,WAAW;EACX,uBAAoB;EACpB,iBAAe,YAAY,KAAA;EAC3B,qBAAmB,QAAQ,SAAS,KAAA;EACpC,aAAU;EACV,gBAAc;EARhB,UAAA,CAUG,QACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,eAAY;GAAO,aAAU;GAChC,UAAA,MAAM,KAAK,GAAG,UACb,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IAAM,aAAU;IACb,UAAA,QAAQ;GACL,GAFkC,WAAW,MAE7C,CACP;EACG,CAAA,IACJ,MACJ,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,aAAU;GACb,UAAA,QACG,MAAM,KAAK,MAAM,UACf,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;IAAM,aAAU;IAAhB,UAAA,CACG,MACA,QAAQ,MAAM,SAAS,IAAI,OAAO,IAC/B;GAH2B,GAAA,WAAW,MAGtC,CACP,IACD;EACA,CAAA,CACH;;CAIT,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,GAAI;EACC;EACL,WAAW;EACX,uBAAoB;EACpB,iBAAe,YAAY,KAAA;EAC3B,aAAU;EACV,gBAAc;EAEb;CACG,CAAA;AAEV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.js","names":[],"sources":["../../../src/components/code/code.tsx"],"sourcesContent":["import { Children, forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { code } from \"../../styled-system/recipes\";\n\nexport type CodeVariant = \"inline\" | \"block\";\n\nexport interface CodeProps extends Omit<ComponentPropsWithoutRef<\"code\">, \"children\"> {\n children?: ReactNode;\n variant?: CodeVariant;\n language?: string;\n wrap?: boolean;\n truncate?: boolean;\n lineNumbers?: boolean;\n}\n\nfunction getTextLines(children: ReactNode) {\n const nodes = Children.toArray(children);\n if (!nodes.every((node) => typeof node === \"string\" || typeof node === \"number\")) return null;\n return nodes.map(String).join(\"\").split(\"\\n\");\n}\n\nfunction getLineKeys(lines: readonly string[]) {\n const occurrences = new Map<string, number>();\n return lines.map((line) => {\n const occurrence = occurrences.get(line) ?? 0;\n occurrences.set(line, occurrence + 1);\n return `line-${line}-${occurrence}`;\n });\n}\n\nexport const Code = forwardRef<HTMLElement, CodeProps>(function Code(\n {\n children,\n className,\n language,\n lineNumbers = false,\n truncate = false,\n variant = \"inline\",\n wrap = false,\n ...props\n },\n ref,\n) {\n const lines = variant === \"block\" && lineNumbers ? getTextLines(children) : null;\n const lineKeys = lines ? getLineKeys(lines) : null;\n const classNames = cx(code({ lineNumbers: Boolean(lines), truncate, variant, wrap }), className);\n\n if (variant === \"block\") {\n return (\n <pre\n {...props}\n ref={ref as React.Ref<HTMLPreElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-line-numbers={lines ? \"true\" : undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {lines ? (\n <span aria-hidden=\"true\" data-slot=\"code-gutter\">\n {lines.map((_, index) => (\n <span data-slot=\"code-line-number\" key={lineKeys?.[index]}>\n {index + 1}\n </span>\n ))}\n </span>\n ) : null}\n <code data-slot=\"code-content\">\n {lines\n ? lines.map((line, index) => (\n <span data-slot=\"code-line\" key={lineKeys?.[index]}>\n {line}\n {index < lines.length - 1 ? \"\\n\" : null}\n </span>\n ))\n : children}\n </code>\n </pre>\n );\n }\n\n return (\n <code\n {...props}\n ref={ref as React.Ref<HTMLElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {children}\n </code>\n );\n});\n"],"mappings":";;;;;AAiBA,SAAS,aAAa,UAAqB;CACzC,MAAM,QAAQ,SAAS,QAAQ,QAAQ;CACvC,IAAI,CAAC,MAAM,OAAO,SAAS,OAAO,SAAS,YAAY,OAAO,SAAS,QAAQ,GAAG,OAAO;CACzF,OAAO,MAAM,IAAI,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,IAAI;AAC9C;AAEA,SAAS,YAAY,OAA0B;CAC7C,MAAM,8BAAc,IAAI,IAAoB;CAC5C,OAAO,MAAM,KAAK,SAAS;EACzB,MAAM,aAAa,YAAY,IAAI,IAAI,KAAK;EAC5C,YAAY,IAAI,MAAM,aAAa,CAAC;EACpC,OAAO,QAAQ,KAAK,GAAG;CACzB,CAAC;AACH;AAEA,MAAa,OAAO,WAAmC,SAAS,KAC9D,EACE,UACA,WACA,UACA,cAAc,OACd,WAAW,OACX,UAAU,UACV,OAAO,OACP,GAAG,SAEL,KACA;CACA,MAAM,QAAQ,YAAY,WAAW,cAAc,aAAa,QAAQ,IAAI;CAC5E,MAAM,WAAW,QAAQ,YAAY,KAAK,IAAI;CAC9C,MAAM,aAAa,GAAG,KAAK;EAAE,aAAa,QAAQ,KAAK;EAAG;EAAU;EAAS;CAAK,CAAC,GAAG,SAAS;CAE/F,IAAI,YAAY,SACd,OACE,qBAAC,OAAD;EACE,GAAI;EACC;EACL,WAAW;EACX,uBAAoB;EACpB,iBAAe,YAAY,KAAA;EAC3B,qBAAmB,QAAQ,SAAS,KAAA;EACpC,aAAU;EACV,gBAAc;
|
|
1
|
+
{"version":3,"file":"code.js","names":[],"sources":["../../../src/components/code/code.tsx"],"sourcesContent":["import { Children, forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { code } from \"../../styled-system/recipes\";\n\nexport type CodeVariant = \"inline\" | \"block\";\n\nexport interface CodeProps extends Omit<ComponentPropsWithoutRef<\"code\">, \"children\"> {\n children?: ReactNode;\n variant?: CodeVariant;\n language?: string;\n wrap?: boolean;\n truncate?: boolean;\n lineNumbers?: boolean;\n}\n\nfunction getTextLines(children: ReactNode) {\n const nodes = Children.toArray(children);\n if (!nodes.every((node) => typeof node === \"string\" || typeof node === \"number\")) return null;\n return nodes.map(String).join(\"\").split(\"\\n\");\n}\n\nfunction getLineKeys(lines: readonly string[]) {\n const occurrences = new Map<string, number>();\n return lines.map((line) => {\n const occurrence = occurrences.get(line) ?? 0;\n occurrences.set(line, occurrence + 1);\n return `line-${line}-${occurrence}`;\n });\n}\n\nexport const Code = forwardRef<HTMLElement, CodeProps>(function Code(\n {\n children,\n className,\n language,\n lineNumbers = false,\n truncate = false,\n variant = \"inline\",\n wrap = false,\n ...props\n },\n ref,\n) {\n const lines = variant === \"block\" && lineNumbers ? getTextLines(children) : null;\n const lineKeys = lines ? getLineKeys(lines) : null;\n const classNames = cx(code({ lineNumbers: Boolean(lines), truncate, variant, wrap }), className);\n\n if (variant === \"block\") {\n return (\n <pre\n {...props}\n ref={ref as React.Ref<HTMLPreElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-line-numbers={lines ? \"true\" : undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {lines ? (\n <span aria-hidden=\"true\" data-slot=\"code-gutter\">\n {lines.map((_, index) => (\n <span data-slot=\"code-line-number\" key={lineKeys?.[index]}>\n {index + 1}\n </span>\n ))}\n </span>\n ) : null}\n <code data-slot=\"code-content\">\n {lines\n ? lines.map((line, index) => (\n <span data-slot=\"code-line\" key={lineKeys?.[index]}>\n {line}\n {index < lines.length - 1 ? \"\\n\" : null}\n </span>\n ))\n : children}\n </code>\n </pre>\n );\n }\n\n return (\n <code\n {...props}\n ref={ref as React.Ref<HTMLElement>}\n className={classNames}\n data-jaci-component=\"code\"\n data-language={language || undefined}\n data-slot=\"code\"\n data-variant={variant}\n >\n {children}\n </code>\n );\n});\n"],"mappings":";;;;;AAiBA,SAAS,aAAa,UAAqB;CACzC,MAAM,QAAQ,SAAS,QAAQ,QAAQ;CACvC,IAAI,CAAC,MAAM,OAAO,SAAS,OAAO,SAA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BAAC,QAAD;EACE,GAAI;EACC;EACL,WAAW;EACX,uBAAoB;EACpB,iBAAe,YAAY,KAAA;EAC3B,aAAU;EACV,gBAAc;EAEb;CACG,CAAA;AAEV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collapsible.cjs","names":["BaseCollapsible","withRecipeClassName","collapsible","cx"],"sources":["../../../src/components/collapsible/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport { Collapsible as BaseCollapsible } from \"@base-ui/react/collapsible\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef } from \"react\";\n\nimport { withRecipeClassName } from \"../base-ui\";\nimport { cx } from \"../../styled-system/css\";\nimport { collapsible } from \"../../styled-system/recipes\";\n\nexport type CollapsibleRootProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Root>;\n\nexport const CollapsibleRoot = forwardRef<HTMLDivElement, CollapsibleRootProps>(\n function CollapsibleRoot({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Root\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().root, className)}\n data-jaci-component=\"collapsible\"\n data-slot=\"collapsible\"\n />\n );\n },\n);\n\nexport interface CollapsibleTriggerProps\n extends ComponentPropsWithoutRef<typeof BaseCollapsible.Trigger> {\n showIndicator?: boolean;\n}\n\nexport const CollapsibleTrigger = forwardRef<HTMLButtonElement, CollapsibleTriggerProps>(\n function CollapsibleTrigger({ children, className, showIndicator = true, ...props }, ref) {\n const styles = collapsible();\n\n return (\n <BaseCollapsible.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(styles.trigger, className)}\n data-slot=\"collapsible-trigger\"\n >\n {showIndicator ? <CollapsibleIndicator /> : null}\n {children}\n </BaseCollapsible.Trigger>\n );\n },\n);\n\nexport type CollapsiblePanelProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Panel>;\n\nexport const CollapsiblePanel = forwardRef<HTMLDivElement, CollapsiblePanelProps>(\n function CollapsiblePanel({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Panel\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().panel, className)}\n data-slot=\"collapsible-panel\"\n />\n );\n },\n);\n\nexport type CollapsibleIndicatorProps = ComponentPropsWithoutRef<\"span\">;\n\nexport const CollapsibleIndicator = forwardRef<HTMLSpanElement, CollapsibleIndicatorProps>(\n function CollapsibleIndicator({ children = \"›\", className, ...props }, ref) {\n return (\n <span\n {...props}\n aria-hidden=\"true\"\n ref={ref}\n className={cx(collapsible().indicator, className)}\n data-slot=\"collapsible-indicator\"\n >\n {children}\n </span>\n );\n },\n);\n\nexport const Collapsible = {\n Root: CollapsibleRoot,\n Trigger: CollapsibleTrigger,\n Panel: CollapsiblePanel,\n Indicator: CollapsibleIndicator,\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,mBAAA,
|
|
1
|
+
{"version":3,"file":"collapsible.cjs","names":["forwardRef","BaseCollapsible","withRecipeClassName","collapsible","cx"],"sources":["../../../src/components/collapsible/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport { Collapsible as BaseCollapsible } from \"@base-ui/react/collapsible\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef } from \"react\";\n\nimport { withRecipeClassName } from \"../base-ui\";\nimport { cx } from \"../../styled-system/css\";\nimport { collapsible } from \"../../styled-system/recipes\";\n\nexport type CollapsibleRootProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Root>;\n\nexport const CollapsibleRoot = forwardRef<HTMLDivElement, CollapsibleRootProps>(\n function CollapsibleRoot({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Root\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().root, className)}\n data-jaci-component=\"collapsible\"\n data-slot=\"collapsible\"\n />\n );\n },\n);\n\nexport interface CollapsibleTriggerProps\n extends ComponentPropsWithoutRef<typeof BaseCollapsible.Trigger> {\n showIndicator?: boolean;\n}\n\nexport const CollapsibleTrigger = forwardRef<HTMLButtonElement, CollapsibleTriggerProps>(\n function CollapsibleTrigger({ children, className, showIndicator = true, ...props }, ref) {\n const styles = collapsible();\n\n return (\n <BaseCollapsible.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(styles.trigger, className)}\n data-slot=\"collapsible-trigger\"\n >\n {showIndicator ? <CollapsibleIndicator /> : null}\n {children}\n </BaseCollapsible.Trigger>\n );\n },\n);\n\nexport type CollapsiblePanelProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Panel>;\n\nexport const CollapsiblePanel = forwardRef<HTMLDivElement, CollapsiblePanelProps>(\n function CollapsiblePanel({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Panel\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().panel, className)}\n data-slot=\"collapsible-panel\"\n />\n );\n },\n);\n\nexport type CollapsibleIndicatorProps = ComponentPropsWithoutRef<\"span\">;\n\nexport const CollapsibleIndicator = forwardRef<HTMLSpanElement, CollapsibleIndicatorProps>(\n function CollapsibleIndicator({ children = \"›\", className, ...props }, ref) {\n return (\n <span\n {...props}\n aria-hidden=\"true\"\n ref={ref}\n className={cx(collapsible().indicator, className)}\n data-slot=\"collapsible-indicator\"\n >\n {children}\n </span>\n );\n },\n);\n\nexport const Collapsible = {\n Root: CollapsibleRoot,\n Trigger: CollapsibleTrigger,\n Panel: CollapsiblePanel,\n Indicator: CollapsibleIndicator,\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,mBAAA,GAAkBA,MAAAA,WAAAA,CAC7B,SAAS,gBAAgB,EAAE,WAAW,GAAG,SAAS,KAAK;CACrD,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,2BAAAA,YAAgB,MAAjB;EACE,GAAI;EACC;EACL,WAAWC,gBAAAA,oBAAoBC,oBAAAA,YAAY,CAAC,CAAC,MAAM,SAAS;EAC5D,uBAAoB;EACpB,aAAU;CACX,CAAA;AAEL,CACF;AAOA,MAAa,sBAAA,GAAqBH,MAAAA,WAAAA,CAChC,SAAS,mBAAmB,EAAE,UAAU,WAAW,gBAAgB,MAAM,GAAG,SAAS,KAAK;CACxF,MAAM,SAASG,oBAAAA,YAAY;CAE3B,OACE,iBAAA,GAAA,kBAAA,KAAA,CAACF,2BAAAA,YAAgB,SAAjB;EACE,GAAI;EACC;EACL,WAAWC,gBAAAA,oBAAoB,OAAO,SAAS,SAAS;EACxD,aAAU;EAJZ,UAAA,CAMG,gBAAgB,iBAAA,GAAA,kBAAA,IAAA,CAAC,sBAAD,CAAuB,CAAA,IAAI,MAC3C,QACsB;;AAE7B,CACF;AAIA,MAAa,oBAAA,GAAmBF,MAAAA,WAAAA,CAC9B,SAAS,iBAAiB,EAAE,WAAW,GAAG,SAAS,KAAK;CACtD,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,2BAAAA,YAAgB,OAAjB;EACE,GAAI;EACC;EACL,WAAWC,gBAAAA,oBAAoBC,oBAAAA,YAAY,CAAC,CAAC,OAAO,SAAS;EAC7D,aAAU;CACX,CAAA;AAEL,CACF;AAIA,MAAa,wBAAA,GAAuBH,MAAAA,WAAAA,CAClC,SAAS,qBAAqB,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS,KAAK;CAC1E,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;EACE,GAAI;EACJ,eAAY;EACP;EACL,WAAWI,WAAAA,GAAGD,oBAAAA,YAAY,CAAC,CAAC,WAAW,SAAS;EAChD,aAAU;EAET;CACG,CAAA;AAEV,CACF;AAEA,MAAa,cAAc;CACzB,MAAM;CACN,SAAS;CACT,OAAO;CACP,WAAW;AACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collapsible.js","names":["BaseCollapsible","Collapsible"],"sources":["../../../src/components/collapsible/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport { Collapsible as BaseCollapsible } from \"@base-ui/react/collapsible\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef } from \"react\";\n\nimport { withRecipeClassName } from \"../base-ui\";\nimport { cx } from \"../../styled-system/css\";\nimport { collapsible } from \"../../styled-system/recipes\";\n\nexport type CollapsibleRootProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Root>;\n\nexport const CollapsibleRoot = forwardRef<HTMLDivElement, CollapsibleRootProps>(\n function CollapsibleRoot({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Root\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().root, className)}\n data-jaci-component=\"collapsible\"\n data-slot=\"collapsible\"\n />\n );\n },\n);\n\nexport interface CollapsibleTriggerProps\n extends ComponentPropsWithoutRef<typeof BaseCollapsible.Trigger> {\n showIndicator?: boolean;\n}\n\nexport const CollapsibleTrigger = forwardRef<HTMLButtonElement, CollapsibleTriggerProps>(\n function CollapsibleTrigger({ children, className, showIndicator = true, ...props }, ref) {\n const styles = collapsible();\n\n return (\n <BaseCollapsible.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(styles.trigger, className)}\n data-slot=\"collapsible-trigger\"\n >\n {showIndicator ? <CollapsibleIndicator /> : null}\n {children}\n </BaseCollapsible.Trigger>\n );\n },\n);\n\nexport type CollapsiblePanelProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Panel>;\n\nexport const CollapsiblePanel = forwardRef<HTMLDivElement, CollapsiblePanelProps>(\n function CollapsiblePanel({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Panel\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().panel, className)}\n data-slot=\"collapsible-panel\"\n />\n );\n },\n);\n\nexport type CollapsibleIndicatorProps = ComponentPropsWithoutRef<\"span\">;\n\nexport const CollapsibleIndicator = forwardRef<HTMLSpanElement, CollapsibleIndicatorProps>(\n function CollapsibleIndicator({ children = \"›\", className, ...props }, ref) {\n return (\n <span\n {...props}\n aria-hidden=\"true\"\n ref={ref}\n className={cx(collapsible().indicator, className)}\n data-slot=\"collapsible-indicator\"\n >\n {children}\n </span>\n );\n },\n);\n\nexport const Collapsible = {\n Root: CollapsibleRoot,\n Trigger: CollapsibleTrigger,\n Panel: CollapsiblePanel,\n Indicator: CollapsibleIndicator,\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,kBAAkB,WAC7B,SAAS,gBAAgB,EAAE,WAAW,GAAG,SAAS,KAAK;CACrD,OACE,oBAACA,YAAgB,MAAjB;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,YAAY,CAAC,CAAC,MAAM,SAAS;EAC5D,uBAAoB;EACpB,aAAU;CACX,CAAA;AAEL,CACF;AAOA,MAAa,qBAAqB,WAChC,SAAS,mBAAmB,EAAE,UAAU,WAAW,gBAAgB,MAAM,GAAG,SAAS,KAAK;CACxF,MAAM,SAAS,YAAY;CAE3B,OACE,qBAACA,YAAgB,SAAjB;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,OAAO,SAAS,SAAS;EACxD,aAAU;
|
|
1
|
+
{"version":3,"file":"collapsible.js","names":["BaseCollapsible","Collapsible"],"sources":["../../../src/components/collapsible/collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport { Collapsible as BaseCollapsible } from \"@base-ui/react/collapsible\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef } from \"react\";\n\nimport { withRecipeClassName } from \"../base-ui\";\nimport { cx } from \"../../styled-system/css\";\nimport { collapsible } from \"../../styled-system/recipes\";\n\nexport type CollapsibleRootProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Root>;\n\nexport const CollapsibleRoot = forwardRef<HTMLDivElement, CollapsibleRootProps>(\n function CollapsibleRoot({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Root\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().root, className)}\n data-jaci-component=\"collapsible\"\n data-slot=\"collapsible\"\n />\n );\n },\n);\n\nexport interface CollapsibleTriggerProps\n extends ComponentPropsWithoutRef<typeof BaseCollapsible.Trigger> {\n showIndicator?: boolean;\n}\n\nexport const CollapsibleTrigger = forwardRef<HTMLButtonElement, CollapsibleTriggerProps>(\n function CollapsibleTrigger({ children, className, showIndicator = true, ...props }, ref) {\n const styles = collapsible();\n\n return (\n <BaseCollapsible.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(styles.trigger, className)}\n data-slot=\"collapsible-trigger\"\n >\n {showIndicator ? <CollapsibleIndicator /> : null}\n {children}\n </BaseCollapsible.Trigger>\n );\n },\n);\n\nexport type CollapsiblePanelProps = ComponentPropsWithoutRef<typeof BaseCollapsible.Panel>;\n\nexport const CollapsiblePanel = forwardRef<HTMLDivElement, CollapsiblePanelProps>(\n function CollapsiblePanel({ className, ...props }, ref) {\n return (\n <BaseCollapsible.Panel\n {...props}\n ref={ref}\n className={withRecipeClassName(collapsible().panel, className)}\n data-slot=\"collapsible-panel\"\n />\n );\n },\n);\n\nexport type CollapsibleIndicatorProps = ComponentPropsWithoutRef<\"span\">;\n\nexport const CollapsibleIndicator = forwardRef<HTMLSpanElement, CollapsibleIndicatorProps>(\n function CollapsibleIndicator({ children = \"›\", className, ...props }, ref) {\n return (\n <span\n {...props}\n aria-hidden=\"true\"\n ref={ref}\n className={cx(collapsible().indicator, className)}\n data-slot=\"collapsible-indicator\"\n >\n {children}\n </span>\n );\n },\n);\n\nexport const Collapsible = {\n Root: CollapsibleRoot,\n Trigger: CollapsibleTrigger,\n Panel: CollapsiblePanel,\n Indicator: CollapsibleIndicator,\n};\n"],"mappings":";;;;;;;;AAYA,MAAa,kBAAkB,WAC7B,SAAS,gBAAgB,EAAE,WAAW,GAAG,SAAS,KAAK;CACrD,OACE,oBAACA,YAAgB,MAAjB;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,YAAY,CAAC,CAAC,MAAM,SAAS;EAC5D,uBAAoB;EACpB,aAAU;CACX,CAAA;AAEL,CACF;AAOA,MAAa,qBAAqB,WAChC,SAAS,mBAAmB,EAAE,UAAU,WAAW,gBAAgB,MAAM,GAAG,SAAS,KAAK;CACxF,MAAM,SAAS,YAAY;CAE3B,OACE,qBAACA,YAAgB,SAAjB;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,OAAO,SAAS,SAAS;EACxD,aAAU;EAJZ,UAAA,CAMG,gBAAgB,oBAAC,sBAAD,CAAuB,CAAA,IAAI,MAC3C,QACsB;;AAE7B,CACF;AAIA,MAAa,mBAAmB,WAC9B,SAAS,iBAAiB,EAAE,WAAW,GAAG,SAAS,KAAK;CACtD,OACE,oBAACA,YAAgB,OAAjB;EACE,GAAI;EACC;EACL,WAAW,oBAAoB,YAAY,CAAC,CAAC,OAAO,SAAS;EAC7D,aAAU;CACX,CAAA;AAEL,CACF;AAIA,MAAa,uBAAuB,WAClC,SAAS,qBAAqB,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS,KAAK;CAC1E,OACE,oBAAC,QAAD;EACE,GAAI;EACJ,eAAY;EACP;EACL,WAAW,GAAG,YAAY,CAAC,CAAC,WAAW,SAAS;EAChD,aAAU;EAET;CACG,CAAA;AAEV,CACF;AAEA,MAAaC,gBAAc;CACzB,MAAM;CACN,SAAS;CACT,OAAO;CACP,WAAW;AACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-picker.cjs","names":["defaultColor","parseColor","formatColor","BasePopover","cx","colorPicker","withRecipeClassName","useThemePortalProps"],"sources":["../../../src/components/color-picker/color-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport { Popover as BasePopover } from \"@base-ui/react/popover\";\nimport { createContext, forwardRef, useContext, useEffect, useId, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, CSSProperties, PointerEvent, ReactNode } from \"react\";\nimport type { PopoverRoot as BasePopoverRoot } from \"@base-ui/react/popover\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { colorPicker } from \"../../styled-system/recipes\";\nimport { withRecipeClassName } from \"../base-ui\";\nimport { useThemePortalProps } from \"../../theme/theme-scope\";\nimport { defaultColor, formatColor, parseColor } from \"./color-utils\";\nimport type { ColorFormat, ColorModel } from \"./color-utils\";\n\nexport type { ColorFormat, ColorModel } from \"./color-utils\";\nexport { defaultColor, formatColor, parseColor } from \"./color-utils\";\n\ninterface ColorPickerContextValue {\n color: ColorModel;\n disabled: boolean;\n format: ColorFormat;\n inputId: string;\n setColor: (color: ColorModel) => void;\n showAlpha: boolean;\n swatches: string[];\n value: string;\n}\n\nconst ColorPickerContext = createContext<ColorPickerContextValue | null>(null);\n\nfunction useColorPicker() {\n const context = useContext(ColorPickerContext);\n if (!context) throw new Error(\"ColorPicker parts must be rendered inside ColorPicker.Root.\");\n return context;\n}\n\nexport interface ColorPickerRootProps extends Omit<BasePopoverRoot.Props, \"children\"> {\n children?: ReactNode;\n defaultValue?: string;\n disabled?: boolean;\n format?: ColorFormat;\n id?: string;\n name?: string;\n onValueChange?: (value: string) => void;\n showAlpha?: boolean;\n swatches?: string[];\n value?: string;\n}\n\nexport function ColorPickerRoot({\n children,\n defaultValue = \"#000000\",\n disabled = false,\n format = \"hex\",\n id,\n name,\n onValueChange,\n showAlpha = false,\n swatches = [],\n value: controlledValue,\n ...popoverProps\n}: ColorPickerRootProps) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const [uncontrolledColor, setUncontrolledColor] = useState<ColorModel>(() =>\n defaultColor(defaultValue),\n );\n const parsedControlled = parseColor(controlledValue);\n const color = parsedControlled ?? uncontrolledColor;\n const formattedValue = formatColor(color, format, showAlpha);\n const setColor = (nextColor: ColorModel) => {\n setUncontrolledColor(nextColor);\n onValueChange?.(formatColor(nextColor, format, showAlpha));\n };\n\n return (\n <ColorPickerContext.Provider\n value={{\n color,\n disabled,\n format,\n inputId,\n setColor,\n showAlpha,\n swatches,\n value: formattedValue,\n }}\n >\n <BasePopover.Root {...popoverProps}>\n {children}\n {name ? (\n <input\n aria-hidden=\"true\"\n id={`${inputId}-value`}\n name={name}\n type=\"hidden\"\n value={formattedValue}\n />\n ) : null}\n </BasePopover.Root>\n </ColorPickerContext.Provider>\n );\n}\n\nexport interface ColorPickerLabelProps extends ComponentPropsWithoutRef<\"label\"> {}\nexport const ColorPickerLabel = forwardRef<HTMLLabelElement, ColorPickerLabelProps>(\n function ColorPickerLabel({ children, className, htmlFor, ...props }, ref) {\n const { inputId } = useColorPicker();\n return (\n <label\n {...props}\n ref={ref}\n className={cx(colorPicker().label, className)}\n data-slot=\"color-picker-label\"\n htmlFor={htmlFor ?? inputId}\n >\n {children}\n </label>\n );\n },\n);\n\nexport type ColorPickerControlProps = ComponentPropsWithoutRef<\"div\">;\nexport const ColorPickerControl = forwardRef<HTMLDivElement, ColorPickerControlProps>(\n function ColorPickerControl({ className, ...props }, ref) {\n return (\n <div\n {...props}\n ref={ref}\n className={cx(colorPicker().control, className)}\n data-slot=\"color-picker-control\"\n />\n );\n },\n);\n\nexport type ColorPickerTriggerProps = ComponentPropsWithoutRef<typeof BasePopover.Trigger>;\nexport const ColorPickerTrigger = forwardRef<HTMLButtonElement, ColorPickerTriggerProps>(\n function ColorPickerTrigger({ className, disabled, ...props }, ref) {\n const context = useColorPicker();\n return (\n <BasePopover.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().trigger, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-trigger\"\n disabled={disabled ?? context.disabled}\n id={props.id ?? context.inputId}\n />\n );\n },\n);\n\nexport type ColorPickerPreviewProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerPreview = forwardRef<HTMLSpanElement, ColorPickerPreviewProps>(\n function ColorPickerPreview({ className, style, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? value}\n className={cx(colorPicker().preview, className)}\n data-slot=\"color-picker-preview\"\n role=\"img\"\n style={{ backgroundColor: value, ...style }}\n />\n );\n },\n);\n\nexport type ColorPickerValueProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerValue = forwardRef<HTMLSpanElement, ColorPickerValueProps>(\n function ColorPickerValue({ className, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n className={cx(colorPicker().value, className)}\n data-slot=\"color-picker-value\"\n >\n {props.children ?? value}\n </span>\n );\n },\n);\n\nexport function ColorPickerPortal(props: ComponentPropsWithoutRef<typeof BasePopover.Portal>) {\n return <BasePopover.Portal {...useThemePortalProps(props)} />;\n}\nexport type ColorPickerPositionerProps = ComponentPropsWithoutRef<typeof BasePopover.Positioner>;\nexport const ColorPickerPositioner = forwardRef<HTMLDivElement, ColorPickerPositionerProps>(\n function ColorPickerPositioner({ className, ...props }, ref) {\n return (\n <BasePopover.Positioner\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().positioner, className)}\n data-slot=\"color-picker-positioner\"\n />\n );\n },\n);\n\nexport type ColorPickerPopupProps = ComponentPropsWithoutRef<typeof BasePopover.Popup>;\nexport const ColorPickerPopup = forwardRef<HTMLDivElement, ColorPickerPopupProps>(\n function ColorPickerPopup({ className, ...props }, ref) {\n return (\n <BasePopover.Popup\n {...props}\n aria-label={props[\"aria-label\"] ?? \"Color picker\"}\n ref={ref}\n className={withRecipeClassName(colorPicker().popup, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-popup\"\n />\n );\n },\n);\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(max, Math.max(min, value));\n}\n\nfunction formatPalettePercentage(value: number) {\n return `${Number(value.toFixed(2))}%`;\n}\n\nfunction hslToPalettePosition(color: ColorModel) {\n const lightness = clamp(color.lightness / 100, 0, 1);\n const saturation = clamp(color.saturation / 100, 0, 1);\n const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;\n const value = lightness + chroma / 2;\n\n return {\n lightness: (1 - value) * 100,\n saturation: value === 0 ? 0 : (chroma / value) * 100,\n };\n}\n\nfunction palettePositionToHsl(\n saturation: number,\n lightness: number,\n color: ColorModel,\n): ColorModel {\n const hsvSaturation = clamp(saturation / 100, 0, 1);\n const value = 1 - clamp(lightness / 100, 0, 1);\n const hslLightness = value * (1 - hsvSaturation / 2);\n const hslSaturation =\n hslLightness === 0 || hslLightness === 1\n ? 0\n : ((value - hslLightness) / Math.min(hslLightness, 1 - hslLightness)) * 100;\n\n return {\n ...color,\n lightness: hslLightness * 100,\n saturation: clamp(hslSaturation, 0, 100),\n };\n}\n\nfunction updateFromPoint(\n event: PointerEvent<HTMLDivElement>,\n setColor: (color: ColorModel) => void,\n color: ColorModel,\n) {\n const rect = event.currentTarget.getBoundingClientRect();\n const saturation = Math.round(clamp((event.clientX - rect.left) / rect.width, 0, 1) * 100);\n const lightness = Math.round(clamp((event.clientY - rect.top) / rect.height, 0, 1) * 100);\n setColor(palettePositionToHsl(saturation, lightness, color));\n}\n\nexport type ColorPickerPaletteProps = Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\">;\nexport const ColorPickerPalette = forwardRef<HTMLDivElement, ColorPickerPaletteProps>(\n function ColorPickerPalette(\n {\n children,\n className,\n onKeyDown,\n onPointerCancel,\n onPointerDown,\n onPointerMove,\n onPointerUp,\n style,\n ...props\n },\n ref,\n ) {\n const { color, disabled, setColor, value } = useColorPicker();\n const [isDragging, setIsDragging] = useState(false);\n const background = `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${color.hue} 100% 50%))`;\n const palettePosition = hslToPalettePosition(color);\n const paletteStyle = {\n \"--jaci-color-palette-lightness\": formatPalettePercentage(palettePosition.lightness),\n \"--jaci-color-palette-saturation\": formatPalettePercentage(palettePosition.saturation),\n background,\n ...style,\n } as CSSProperties;\n\n const releasePointer = (event: PointerEvent<HTMLDivElement>) => {\n if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n setIsDragging(false);\n };\n\n return (\n <div\n {...props}\n ref={ref}\n aria-disabled={disabled || undefined}\n aria-label={props[\"aria-label\"] ?? \"Color saturation and lightness\"}\n aria-valuemax={100}\n aria-valuemin={0}\n aria-valuenow={Math.round(palettePosition.saturation)}\n aria-valuetext={value}\n className={cx(colorPicker().palette, className)}\n data-disabled={disabled || undefined}\n data-dragging={isDragging || undefined}\n data-slot=\"color-picker-palette\"\n onKeyDown={(event) => {\n const step = event.shiftKey ? 10 : 1;\n if (\n event.key === \"ArrowLeft\" ||\n event.key === \"ArrowRight\" ||\n event.key === \"ArrowUp\" ||\n event.key === \"ArrowDown\"\n ) {\n event.preventDefault();\n const saturation =\n event.key === \"ArrowLeft\"\n ? Math.max(0, palettePosition.saturation - step)\n : event.key === \"ArrowRight\"\n ? Math.min(100, palettePosition.saturation + step)\n : palettePosition.saturation;\n const lightness =\n event.key === \"ArrowDown\"\n ? Math.min(100, palettePosition.lightness + step)\n : event.key === \"ArrowUp\"\n ? Math.max(0, palettePosition.lightness - step)\n : palettePosition.lightness;\n setColor(palettePositionToHsl(saturation, lightness, color));\n }\n onKeyDown?.(event);\n }}\n onPointerDown={(event) => {\n if (!disabled) {\n updateFromPoint(event, setColor, color);\n setIsDragging(true);\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Pointer capture is not available in every test environment.\n }\n }\n onPointerDown?.(event);\n }}\n onPointerMove={(event) => {\n if (!disabled && isDragging) updateFromPoint(event, setColor, color);\n onPointerMove?.(event);\n }}\n onPointerUp={(event) => {\n releasePointer(event);\n onPointerUp?.(event);\n }}\n onPointerCancel={(event) => {\n releasePointer(event);\n onPointerCancel?.(event);\n }}\n role=\"slider\"\n style={paletteStyle}\n tabIndex={props.tabIndex ?? (disabled ? -1 : 0)}\n >\n <span\n aria-hidden=\"true\"\n className={colorPicker().paletteIndicator}\n data-slot=\"color-picker-palette-indicator\"\n />\n {children}\n </div>\n );\n },\n);\n\nexport type ColorPickerHueProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerHue = forwardRef<HTMLInputElement, ColorPickerHueProps>(\n function ColorPickerHue({ className, onInput, ...props }, ref) {\n const { color, setColor } = useColorPicker();\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Hue\"}\n className={cx(colorPicker().hue, className)}\n data-slot=\"color-picker-hue\"\n max={360}\n min={0}\n onInput={(event) => {\n setColor({ ...color, hue: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={1}\n type=\"range\"\n value={color.hue}\n />\n );\n },\n);\n\nexport type ColorPickerAlphaProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerAlpha = forwardRef<HTMLInputElement, ColorPickerAlphaProps>(\n function ColorPickerAlpha({ className, onInput, style, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n if (!showAlpha) return null;\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Opacity\"}\n className={cx(colorPicker().alpha, className)}\n data-slot=\"color-picker-alpha\"\n max={1}\n min={0}\n onInput={(event) => {\n setColor({ ...color, alpha: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={0.01}\n style={{\n ...style,\n background: `linear-gradient(to right, transparent, ${formatColor({ ...color, alpha: 1 }, \"rgb\")})`,\n }}\n type=\"range\"\n value={color.alpha}\n />\n );\n },\n);\n\nexport type ColorPickerSwatchesProps = ComponentPropsWithoutRef<\"fieldset\">;\nexport const ColorPickerSwatches = forwardRef<HTMLFieldSetElement, ColorPickerSwatchesProps>(\n function ColorPickerSwatches({ children, className, ...props }, ref) {\n const { swatches } = useColorPicker();\n return (\n <fieldset\n {...props}\n ref={ref}\n className={cx(colorPicker().swatches, className)}\n data-slot=\"color-picker-swatches\"\n >\n {children ?? swatches.map((color) => <ColorPickerSwatch color={color} key={color} />)}\n </fieldset>\n );\n },\n);\n\nexport interface ColorPickerSwatchProps extends ComponentPropsWithoutRef<\"button\"> {\n color: string;\n}\nexport const ColorPickerSwatch = forwardRef<HTMLButtonElement, ColorPickerSwatchProps>(\n function ColorPickerSwatch({ children, className, color, style, ...props }, ref) {\n const context = useColorPicker();\n const parsed = parseColor(color);\n const selected =\n parsed && formatColor(parsed, context.format, context.showAlpha) === context.value;\n return (\n <button\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? color}\n aria-pressed={selected || undefined}\n className={cx(colorPicker().swatch, className)}\n data-selected={selected || undefined}\n data-slot=\"color-picker-swatch\"\n onClick={(event) => {\n if (parsed) context.setColor(parsed);\n props.onClick?.(event);\n }}\n style={{ backgroundColor: color, ...style }}\n type=\"button\"\n >\n {children}\n </button>\n );\n },\n);\n\nexport type ColorPickerInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerInput = forwardRef<HTMLInputElement, ColorPickerInputProps>(\n function ColorPickerInput({ className, onBlur, onKeyDown, ...props }, ref) {\n const { format, setColor, showAlpha, value } = useColorPicker();\n const [draft, setDraft] = useState(value);\n const [invalid, setInvalid] = useState(false);\n useEffect(() => setDraft(value), [value]);\n const commit = () => {\n const parsed = parseColor(draft);\n if (!parsed) {\n setInvalid(true);\n setDraft(value);\n return;\n }\n setInvalid(false);\n setColor(parsed);\n setDraft(formatColor(parsed, format, showAlpha));\n };\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Color value\"}\n aria-invalid={invalid || undefined}\n className={cx(colorPicker().input, className)}\n data-slot=\"color-picker-input\"\n onBlur={(event) => {\n commit();\n onBlur?.(event);\n }}\n onChange={(event) => {\n setDraft(event.currentTarget.value);\n setInvalid(false);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n commit();\n }\n onKeyDown?.(event);\n }}\n type=\"text\"\n value={draft}\n />\n );\n },\n);\n\nexport type ColorPickerNativeInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerNativeInput = forwardRef<HTMLInputElement, ColorPickerNativeInputProps>(\n function ColorPickerNativeInput({ className, onInput, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n const value = formatColor({ ...color, alpha: 1 }, \"hex\");\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Choose a color\"}\n className={cx(colorPicker().nativeInput, className)}\n data-slot=\"color-picker-native-input\"\n onInput={(event) => {\n const parsed = parseColor(event.currentTarget.value);\n if (parsed) setColor({ ...parsed, alpha: showAlpha ? color.alpha : 1 });\n onInput?.(event);\n }}\n type=\"color\"\n value={value.slice(0, 7)}\n />\n );\n },\n);\n\nexport const ColorPicker = {\n Root: ColorPickerRoot,\n Label: ColorPickerLabel,\n Control: ColorPickerControl,\n Trigger: ColorPickerTrigger,\n Preview: ColorPickerPreview,\n Value: ColorPickerValue,\n Portal: ColorPickerPortal,\n Positioner: ColorPickerPositioner,\n Popup: ColorPickerPopup,\n Palette: ColorPickerPalette,\n Hue: ColorPickerHue,\n Alpha: ColorPickerAlpha,\n Swatches: ColorPickerSwatches,\n Swatch: ColorPickerSwatch,\n Input: ColorPickerInput,\n NativeInput: ColorPickerNativeInput,\n createHandle: BasePopover.createHandle,\n};\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,sBAAA,GAAA,MAAA,cAAA,CAAmE,IAAI;AAE7E,SAAS,iBAAiB;CACxB,MAAM,WAAA,GAAA,MAAA,WAAA,CAAqB,kBAAkB;CAC7C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,6DAA6D;CAC3F,OAAO;AACT;AAeA,SAAgB,gBAAgB,EAC9B,UACA,eAAe,WACf,WAAW,OACX,SAAS,OACT,IACA,MACA,eACA,YAAY,OACZ,WAAW,CAAC,GACZ,OAAO,iBACP,GAAG,gBACoB;CACvB,MAAM,eAAA,GAAA,MAAA,MAAA,CAAoB;CAC1B,MAAM,UAAU,MAAM;CACtB,MAAM,CAAC,mBAAmB,yBAAA,GAAA,MAAA,SAAA,OACxBA,oBAAAA,aAAa,YAAY,CAC3B;CAEA,MAAM,QADmBC,oBAAAA,WAAW,eACP,KAAK;CAClC,MAAM,iBAAiBC,oBAAAA,YAAY,OAAO,QAAQ,SAAS;CA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AAEA,MAAa,cAAc;CACzB,MAAM;CACN,OAAO;CACP,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO;CACP,QAAQ;CACR,YAAY;CACZ,OAAO;CACP,SAAS;CACT,KAAK;CACL,OAAO;CACP,UAAU;CACV,QAAQ;CACR,OAAO;CACP,aAAa;CACb,cAAcE,uBAAAA,QAAY;AAC5B"}
|
|
1
|
+
{"version":3,"file":"color-picker.cjs","names":["createContext","useContext","useId","useState","defaultColor","parseColor","formatColor","BasePopover","forwardRef","cx","colorPicker","withRecipeClassName","useThemePortalProps"],"sources":["../../../src/components/color-picker/color-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport { Popover as BasePopover } from \"@base-ui/react/popover\";\nimport { createContext, forwardRef, useContext, useEffect, useId, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, CSSProperties, PointerEvent, ReactNode } from \"react\";\nimport type { PopoverRoot as BasePopoverRoot } from \"@base-ui/react/popover\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { colorPicker } from \"../../styled-system/recipes\";\nimport { withRecipeClassName } from \"../base-ui\";\nimport { useThemePortalProps } from \"../../theme/theme-scope\";\nimport { defaultColor, formatColor, parseColor } from \"./color-utils\";\nimport type { ColorFormat, ColorModel } from \"./color-utils\";\n\nexport type { ColorFormat, ColorModel } from \"./color-utils\";\nexport { defaultColor, formatColor, parseColor } from \"./color-utils\";\n\ninterface ColorPickerContextValue {\n color: ColorModel;\n disabled: boolean;\n format: ColorFormat;\n inputId: string;\n setColor: (color: ColorModel) => void;\n showAlpha: boolean;\n swatches: string[];\n value: string;\n}\n\nconst ColorPickerContext = createContext<ColorPickerContextValue | null>(null);\n\nfunction useColorPicker() {\n const context = useContext(ColorPickerContext);\n if (!context) throw new Error(\"ColorPicker parts must be rendered inside ColorPicker.Root.\");\n return context;\n}\n\nexport interface ColorPickerRootProps extends Omit<BasePopoverRoot.Props, \"children\"> {\n children?: ReactNode;\n defaultValue?: string;\n disabled?: boolean;\n format?: ColorFormat;\n id?: string;\n name?: string;\n onValueChange?: (value: string) => void;\n showAlpha?: boolean;\n swatches?: string[];\n value?: string;\n}\n\nexport function ColorPickerRoot({\n children,\n defaultValue = \"#000000\",\n disabled = false,\n format = \"hex\",\n id,\n name,\n onValueChange,\n showAlpha = false,\n swatches = [],\n value: controlledValue,\n ...popoverProps\n}: ColorPickerRootProps) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const [uncontrolledColor, setUncontrolledColor] = useState<ColorModel>(() =>\n defaultColor(defaultValue),\n );\n const parsedControlled = parseColor(controlledValue);\n const color = parsedControlled ?? uncontrolledColor;\n const formattedValue = formatColor(color, format, showAlpha);\n const setColor = (nextColor: ColorModel) => {\n setUncontrolledColor(nextColor);\n onValueChange?.(formatColor(nextColor, format, showAlpha));\n };\n\n return (\n <ColorPickerContext.Provider\n value={{\n color,\n disabled,\n format,\n inputId,\n setColor,\n showAlpha,\n swatches,\n value: formattedValue,\n }}\n >\n <BasePopover.Root {...popoverProps}>\n {children}\n {name ? (\n <input\n aria-hidden=\"true\"\n id={`${inputId}-value`}\n name={name}\n type=\"hidden\"\n value={formattedValue}\n />\n ) : null}\n </BasePopover.Root>\n </ColorPickerContext.Provider>\n );\n}\n\nexport interface ColorPickerLabelProps extends ComponentPropsWithoutRef<\"label\"> {}\nexport const ColorPickerLabel = forwardRef<HTMLLabelElement, ColorPickerLabelProps>(\n function ColorPickerLabel({ children, className, htmlFor, ...props }, ref) {\n const { inputId } = useColorPicker();\n return (\n <label\n {...props}\n ref={ref}\n className={cx(colorPicker().label, className)}\n data-slot=\"color-picker-label\"\n htmlFor={htmlFor ?? inputId}\n >\n {children}\n </label>\n );\n },\n);\n\nexport type ColorPickerControlProps = ComponentPropsWithoutRef<\"div\">;\nexport const ColorPickerControl = forwardRef<HTMLDivElement, ColorPickerControlProps>(\n function ColorPickerControl({ className, ...props }, ref) {\n return (\n <div\n {...props}\n ref={ref}\n className={cx(colorPicker().control, className)}\n data-slot=\"color-picker-control\"\n />\n );\n },\n);\n\nexport type ColorPickerTriggerProps = ComponentPropsWithoutRef<typeof BasePopover.Trigger>;\nexport const ColorPickerTrigger = forwardRef<HTMLButtonElement, ColorPickerTriggerProps>(\n function ColorPickerTrigger({ className, disabled, ...props }, ref) {\n const context = useColorPicker();\n return (\n <BasePopover.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().trigger, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-trigger\"\n disabled={disabled ?? context.disabled}\n id={props.id ?? context.inputId}\n />\n );\n },\n);\n\nexport type ColorPickerPreviewProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerPreview = forwardRef<HTMLSpanElement, ColorPickerPreviewProps>(\n function ColorPickerPreview({ className, style, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? value}\n className={cx(colorPicker().preview, className)}\n data-slot=\"color-picker-preview\"\n role=\"img\"\n style={{ backgroundColor: value, ...style }}\n />\n );\n },\n);\n\nexport type ColorPickerValueProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerValue = forwardRef<HTMLSpanElement, ColorPickerValueProps>(\n function ColorPickerValue({ className, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n className={cx(colorPicker().value, className)}\n data-slot=\"color-picker-value\"\n >\n {props.children ?? value}\n </span>\n );\n },\n);\n\nexport function ColorPickerPortal(props: ComponentPropsWithoutRef<typeof BasePopover.Portal>) {\n return <BasePopover.Portal {...useThemePortalProps(props)} />;\n}\nexport type ColorPickerPositionerProps = ComponentPropsWithoutRef<typeof BasePopover.Positioner>;\nexport const ColorPickerPositioner = forwardRef<HTMLDivElement, ColorPickerPositionerProps>(\n function ColorPickerPositioner({ className, ...props }, ref) {\n return (\n <BasePopover.Positioner\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().positioner, className)}\n data-slot=\"color-picker-positioner\"\n />\n );\n },\n);\n\nexport type ColorPickerPopupProps = ComponentPropsWithoutRef<typeof BasePopover.Popup>;\nexport const ColorPickerPopup = forwardRef<HTMLDivElement, ColorPickerPopupProps>(\n function ColorPickerPopup({ className, ...props }, ref) {\n return (\n <BasePopover.Popup\n {...props}\n aria-label={props[\"aria-label\"] ?? \"Color picker\"}\n ref={ref}\n className={withRecipeClassName(colorPicker().popup, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-popup\"\n />\n );\n },\n);\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(max, Math.max(min, value));\n}\n\nfunction formatPalettePercentage(value: number) {\n return `${Number(value.toFixed(2))}%`;\n}\n\nfunction hslToPalettePosition(color: ColorModel) {\n const lightness = clamp(color.lightness / 100, 0, 1);\n const saturation = clamp(color.saturation / 100, 0, 1);\n const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;\n const value = lightness + chroma / 2;\n\n return {\n lightness: (1 - value) * 100,\n saturation: value === 0 ? 0 : (chroma / value) * 100,\n };\n}\n\nfunction palettePositionToHsl(\n saturation: number,\n lightness: number,\n color: ColorModel,\n): ColorModel {\n const hsvSaturation = clamp(saturation / 100, 0, 1);\n const value = 1 - clamp(lightness / 100, 0, 1);\n const hslLightness = value * (1 - hsvSaturation / 2);\n const hslSaturation =\n hslLightness === 0 || hslLightness === 1\n ? 0\n : ((value - hslLightness) / Math.min(hslLightness, 1 - hslLightness)) * 100;\n\n return {\n ...color,\n lightness: hslLightness * 100,\n saturation: clamp(hslSaturation, 0, 100),\n };\n}\n\nfunction updateFromPoint(\n event: PointerEvent<HTMLDivElement>,\n setColor: (color: ColorModel) => void,\n color: ColorModel,\n) {\n const rect = event.currentTarget.getBoundingClientRect();\n const saturation = Math.round(clamp((event.clientX - rect.left) / rect.width, 0, 1) * 100);\n const lightness = Math.round(clamp((event.clientY - rect.top) / rect.height, 0, 1) * 100);\n setColor(palettePositionToHsl(saturation, lightness, color));\n}\n\nexport type ColorPickerPaletteProps = Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\">;\nexport const ColorPickerPalette = forwardRef<HTMLDivElement, ColorPickerPaletteProps>(\n function ColorPickerPalette(\n {\n children,\n className,\n onKeyDown,\n onPointerCancel,\n onPointerDown,\n onPointerMove,\n onPointerUp,\n style,\n ...props\n },\n ref,\n ) {\n const { color, disabled, setColor, value } = useColorPicker();\n const [isDragging, setIsDragging] = useState(false);\n const background = `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${color.hue} 100% 50%))`;\n const palettePosition = hslToPalettePosition(color);\n const paletteStyle = {\n \"--jaci-color-palette-lightness\": formatPalettePercentage(palettePosition.lightness),\n \"--jaci-color-palette-saturation\": formatPalettePercentage(palettePosition.saturation),\n background,\n ...style,\n } as CSSProperties;\n\n const releasePointer = (event: PointerEvent<HTMLDivElement>) => {\n if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n setIsDragging(false);\n };\n\n return (\n <div\n {...props}\n ref={ref}\n aria-disabled={disabled || undefined}\n aria-label={props[\"aria-label\"] ?? \"Color saturation and lightness\"}\n aria-valuemax={100}\n aria-valuemin={0}\n aria-valuenow={Math.round(palettePosition.saturation)}\n aria-valuetext={value}\n className={cx(colorPicker().palette, className)}\n data-disabled={disabled || undefined}\n data-dragging={isDragging || undefined}\n data-slot=\"color-picker-palette\"\n onKeyDown={(event) => {\n const step = event.shiftKey ? 10 : 1;\n if (\n event.key === \"ArrowLeft\" ||\n event.key === \"ArrowRight\" ||\n event.key === \"ArrowUp\" ||\n event.key === \"ArrowDown\"\n ) {\n event.preventDefault();\n const saturation =\n event.key === \"ArrowLeft\"\n ? Math.max(0, palettePosition.saturation - step)\n : event.key === \"ArrowRight\"\n ? Math.min(100, palettePosition.saturation + step)\n : palettePosition.saturation;\n const lightness =\n event.key === \"ArrowDown\"\n ? Math.min(100, palettePosition.lightness + step)\n : event.key === \"ArrowUp\"\n ? Math.max(0, palettePosition.lightness - step)\n : palettePosition.lightness;\n setColor(palettePositionToHsl(saturation, lightness, color));\n }\n onKeyDown?.(event);\n }}\n onPointerDown={(event) => {\n if (!disabled) {\n updateFromPoint(event, setColor, color);\n setIsDragging(true);\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Pointer capture is not available in every test environment.\n }\n }\n onPointerDown?.(event);\n }}\n onPointerMove={(event) => {\n if (!disabled && isDragging) updateFromPoint(event, setColor, color);\n onPointerMove?.(event);\n }}\n onPointerUp={(event) => {\n releasePointer(event);\n onPointerUp?.(event);\n }}\n onPointerCancel={(event) => {\n releasePointer(event);\n onPointerCancel?.(event);\n }}\n role=\"slider\"\n style={paletteStyle}\n tabIndex={props.tabIndex ?? (disabled ? -1 : 0)}\n >\n <span\n aria-hidden=\"true\"\n className={colorPicker().paletteIndicator}\n data-slot=\"color-picker-palette-indicator\"\n />\n {children}\n </div>\n );\n },\n);\n\nexport type ColorPickerHueProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerHue = forwardRef<HTMLInputElement, ColorPickerHueProps>(\n function ColorPickerHue({ className, onInput, ...props }, ref) {\n const { color, setColor } = useColorPicker();\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Hue\"}\n className={cx(colorPicker().hue, className)}\n data-slot=\"color-picker-hue\"\n max={360}\n min={0}\n onInput={(event) => {\n setColor({ ...color, hue: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={1}\n type=\"range\"\n value={color.hue}\n />\n );\n },\n);\n\nexport type ColorPickerAlphaProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerAlpha = forwardRef<HTMLInputElement, ColorPickerAlphaProps>(\n function ColorPickerAlpha({ className, onInput, style, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n if (!showAlpha) return null;\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Opacity\"}\n className={cx(colorPicker().alpha, className)}\n data-slot=\"color-picker-alpha\"\n max={1}\n min={0}\n onInput={(event) => {\n setColor({ ...color, alpha: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={0.01}\n style={{\n ...style,\n background: `linear-gradient(to right, transparent, ${formatColor({ ...color, alpha: 1 }, \"rgb\")})`,\n }}\n type=\"range\"\n value={color.alpha}\n />\n );\n },\n);\n\nexport type ColorPickerSwatchesProps = ComponentPropsWithoutRef<\"fieldset\">;\nexport const ColorPickerSwatches = forwardRef<HTMLFieldSetElement, ColorPickerSwatchesProps>(\n function ColorPickerSwatches({ children, className, ...props }, ref) {\n const { swatches } = useColorPicker();\n return (\n <fieldset\n {...props}\n ref={ref}\n className={cx(colorPicker().swatches, className)}\n data-slot=\"color-picker-swatches\"\n >\n {children ?? swatches.map((color) => <ColorPickerSwatch color={color} key={color} />)}\n </fieldset>\n );\n },\n);\n\nexport interface ColorPickerSwatchProps extends ComponentPropsWithoutRef<\"button\"> {\n color: string;\n}\nexport const ColorPickerSwatch = forwardRef<HTMLButtonElement, ColorPickerSwatchProps>(\n function ColorPickerSwatch({ children, className, color, style, ...props }, ref) {\n const context = useColorPicker();\n const parsed = parseColor(color);\n const selected =\n parsed && formatColor(parsed, context.format, context.showAlpha) === context.value;\n return (\n <button\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? color}\n aria-pressed={selected || undefined}\n className={cx(colorPicker().swatch, className)}\n data-selected={selected || undefined}\n data-slot=\"color-picker-swatch\"\n onClick={(event) => {\n if (parsed) context.setColor(parsed);\n props.onClick?.(event);\n }}\n style={{ backgroundColor: color, ...style }}\n type=\"button\"\n >\n {children}\n </button>\n );\n },\n);\n\nexport type ColorPickerInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerInput = forwardRef<HTMLInputElement, ColorPickerInputProps>(\n function ColorPickerInput({ className, onBlur, onKeyDown, ...props }, ref) {\n const { format, setColor, showAlpha, value } = useColorPicker();\n const [draft, setDraft] = useState(value);\n const [invalid, setInvalid] = useState(false);\n useEffect(() => setDraft(value), [value]);\n const commit = () => {\n const parsed = parseColor(draft);\n if (!parsed) {\n setInvalid(true);\n setDraft(value);\n return;\n }\n setInvalid(false);\n setColor(parsed);\n setDraft(formatColor(parsed, format, showAlpha));\n };\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Color value\"}\n aria-invalid={invalid || undefined}\n className={cx(colorPicker().input, className)}\n data-slot=\"color-picker-input\"\n onBlur={(event) => {\n commit();\n onBlur?.(event);\n }}\n onChange={(event) => {\n setDraft(event.currentTarget.value);\n setInvalid(false);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n commit();\n }\n onKeyDown?.(event);\n }}\n type=\"text\"\n value={draft}\n />\n );\n },\n);\n\nexport type ColorPickerNativeInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerNativeInput = forwardRef<HTMLInputElement, ColorPickerNativeInputProps>(\n function ColorPickerNativeInput({ className, onInput, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n const value = formatColor({ ...color, alpha: 1 }, \"hex\");\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Choose a color\"}\n className={cx(colorPicker().nativeInput, className)}\n data-slot=\"color-picker-native-input\"\n onInput={(event) => {\n const parsed = parseColor(event.currentTarget.value);\n if (parsed) setColor({ ...parsed, alpha: showAlpha ? color.alpha : 1 });\n onInput?.(event);\n }}\n type=\"color\"\n value={value.slice(0, 7)}\n />\n );\n },\n);\n\nexport const ColorPicker = {\n Root: ColorPickerRoot,\n Label: ColorPickerLabel,\n Control: ColorPickerControl,\n Trigger: ColorPickerTrigger,\n Preview: ColorPickerPreview,\n Value: ColorPickerValue,\n Portal: ColorPickerPortal,\n Positioner: ColorPickerPositioner,\n Popup: ColorPickerPopup,\n Palette: ColorPickerPalette,\n Hue: ColorPickerHue,\n Alpha: ColorPickerAlpha,\n Swatches: ColorPickerSwatches,\n Swatch: ColorPickerSwatch,\n Input: ColorPickerInput,\n NativeInput: ColorPickerNativeInput,\n createHandle: BasePopover.createHandle,\n};\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,sBAAA,GAAqBA,MAAAA,cAAAA,CAA8C,IAAI;AAE7E,SAAS,iBAAiB;CACxB,MAAM,WAAA,GAAUC,MAAAA,WAAAA,CAAW,kBAAkB;CAC7C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,6DAA6D;CAC3F,OAAO;AACT;AAeA,SAAgB,gBAAgB,EAC9B,UACA,eAAe,WACf,WAAW,OACX,SAAS,OACT,IACA,MACA,eACA,YAAY,OACZ,WAAW,CAAC,GACZ,OAAO,iBACP,GAAG,gBACoB;CACvB,MAAM,eAAA,GAAcC,MAAAA,MAAAA,CAAM;CAC1B,MAAM,UAAU,MAAM;CACtB,MAAM,CAAC,mBAAmB,yBAAA,GAAwBC,MAAAA,SAAAA,OAChDC,oBAAAA,aAAa,YAAY,CAC3B;CAEA,MAAM,QADmBC,oBAAAA,WAAW,eACP,KAAK;CAClC,MAAM,iBAAiBC,oBAAAA,YAAY,OAAO,QAAQ,SAAS;CAC3D,MAAM,YAAY,cAA0B;EAC1C,qBAAqB,SAAS;EAC9B,gBAAgBA,oBAAAA,YAAY,WAAW,QAAQ,SAAS,CAAC;CAC3D;CAEA,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,mBAAmB,UAApB;EACE,OAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;EACT;EAEA,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,uBAAAA,QAAY,MAAb;GAAkB,GAAI;GAAtB,UAAA,CACG,UACA,OACC,iBAAA,GAAA,kBAAA,IAAA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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-picker.js","names":["BasePopover"],"sources":["../../../src/components/color-picker/color-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport { Popover as BasePopover } from \"@base-ui/react/popover\";\nimport { createContext, forwardRef, useContext, useEffect, useId, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, CSSProperties, PointerEvent, ReactNode } from \"react\";\nimport type { PopoverRoot as BasePopoverRoot } from \"@base-ui/react/popover\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { colorPicker } from \"../../styled-system/recipes\";\nimport { withRecipeClassName } from \"../base-ui\";\nimport { useThemePortalProps } from \"../../theme/theme-scope\";\nimport { defaultColor, formatColor, parseColor } from \"./color-utils\";\nimport type { ColorFormat, ColorModel } from \"./color-utils\";\n\nexport type { ColorFormat, ColorModel } from \"./color-utils\";\nexport { defaultColor, formatColor, parseColor } from \"./color-utils\";\n\ninterface ColorPickerContextValue {\n color: ColorModel;\n disabled: boolean;\n format: ColorFormat;\n inputId: string;\n setColor: (color: ColorModel) => void;\n showAlpha: boolean;\n swatches: string[];\n value: string;\n}\n\nconst ColorPickerContext = createContext<ColorPickerContextValue | null>(null);\n\nfunction useColorPicker() {\n const context = useContext(ColorPickerContext);\n if (!context) throw new Error(\"ColorPicker parts must be rendered inside ColorPicker.Root.\");\n return context;\n}\n\nexport interface ColorPickerRootProps extends Omit<BasePopoverRoot.Props, \"children\"> {\n children?: ReactNode;\n defaultValue?: string;\n disabled?: boolean;\n format?: ColorFormat;\n id?: string;\n name?: string;\n onValueChange?: (value: string) => void;\n showAlpha?: boolean;\n swatches?: string[];\n value?: string;\n}\n\nexport function ColorPickerRoot({\n children,\n defaultValue = \"#000000\",\n disabled = false,\n format = \"hex\",\n id,\n name,\n onValueChange,\n showAlpha = false,\n swatches = [],\n value: controlledValue,\n ...popoverProps\n}: ColorPickerRootProps) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const [uncontrolledColor, setUncontrolledColor] = useState<ColorModel>(() =>\n defaultColor(defaultValue),\n );\n const parsedControlled = parseColor(controlledValue);\n const color = parsedControlled ?? uncontrolledColor;\n const formattedValue = formatColor(color, format, showAlpha);\n const setColor = (nextColor: ColorModel) => {\n setUncontrolledColor(nextColor);\n onValueChange?.(formatColor(nextColor, format, showAlpha));\n };\n\n return (\n <ColorPickerContext.Provider\n value={{\n color,\n disabled,\n format,\n inputId,\n setColor,\n showAlpha,\n swatches,\n value: formattedValue,\n }}\n >\n <BasePopover.Root {...popoverProps}>\n {children}\n {name ? (\n <input\n aria-hidden=\"true\"\n id={`${inputId}-value`}\n name={name}\n type=\"hidden\"\n value={formattedValue}\n />\n ) : null}\n </BasePopover.Root>\n </ColorPickerContext.Provider>\n );\n}\n\nexport interface ColorPickerLabelProps extends ComponentPropsWithoutRef<\"label\"> {}\nexport const ColorPickerLabel = forwardRef<HTMLLabelElement, ColorPickerLabelProps>(\n function ColorPickerLabel({ children, className, htmlFor, ...props }, ref) {\n const { inputId } = useColorPicker();\n return (\n <label\n {...props}\n ref={ref}\n className={cx(colorPicker().label, className)}\n data-slot=\"color-picker-label\"\n htmlFor={htmlFor ?? inputId}\n >\n {children}\n </label>\n );\n },\n);\n\nexport type ColorPickerControlProps = ComponentPropsWithoutRef<\"div\">;\nexport const ColorPickerControl = forwardRef<HTMLDivElement, ColorPickerControlProps>(\n function ColorPickerControl({ className, ...props }, ref) {\n return (\n <div\n {...props}\n ref={ref}\n className={cx(colorPicker().control, className)}\n data-slot=\"color-picker-control\"\n />\n );\n },\n);\n\nexport type ColorPickerTriggerProps = ComponentPropsWithoutRef<typeof BasePopover.Trigger>;\nexport const ColorPickerTrigger = forwardRef<HTMLButtonElement, ColorPickerTriggerProps>(\n function ColorPickerTrigger({ className, disabled, ...props }, ref) {\n const context = useColorPicker();\n return (\n <BasePopover.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().trigger, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-trigger\"\n disabled={disabled ?? context.disabled}\n id={props.id ?? context.inputId}\n />\n );\n },\n);\n\nexport type ColorPickerPreviewProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerPreview = forwardRef<HTMLSpanElement, ColorPickerPreviewProps>(\n function ColorPickerPreview({ className, style, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? value}\n className={cx(colorPicker().preview, className)}\n data-slot=\"color-picker-preview\"\n role=\"img\"\n style={{ backgroundColor: value, ...style }}\n />\n );\n },\n);\n\nexport type ColorPickerValueProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerValue = forwardRef<HTMLSpanElement, ColorPickerValueProps>(\n function ColorPickerValue({ className, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n className={cx(colorPicker().value, className)}\n data-slot=\"color-picker-value\"\n >\n {props.children ?? value}\n </span>\n );\n },\n);\n\nexport function ColorPickerPortal(props: ComponentPropsWithoutRef<typeof BasePopover.Portal>) {\n return <BasePopover.Portal {...useThemePortalProps(props)} />;\n}\nexport type ColorPickerPositionerProps = ComponentPropsWithoutRef<typeof BasePopover.Positioner>;\nexport const ColorPickerPositioner = forwardRef<HTMLDivElement, ColorPickerPositionerProps>(\n function ColorPickerPositioner({ className, ...props }, ref) {\n return (\n <BasePopover.Positioner\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().positioner, className)}\n data-slot=\"color-picker-positioner\"\n />\n );\n },\n);\n\nexport type ColorPickerPopupProps = ComponentPropsWithoutRef<typeof BasePopover.Popup>;\nexport const ColorPickerPopup = forwardRef<HTMLDivElement, ColorPickerPopupProps>(\n function ColorPickerPopup({ className, ...props }, ref) {\n return (\n <BasePopover.Popup\n {...props}\n aria-label={props[\"aria-label\"] ?? \"Color picker\"}\n ref={ref}\n className={withRecipeClassName(colorPicker().popup, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-popup\"\n />\n );\n },\n);\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(max, Math.max(min, value));\n}\n\nfunction formatPalettePercentage(value: number) {\n return `${Number(value.toFixed(2))}%`;\n}\n\nfunction hslToPalettePosition(color: ColorModel) {\n const lightness = clamp(color.lightness / 100, 0, 1);\n const saturation = clamp(color.saturation / 100, 0, 1);\n const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;\n const value = lightness + chroma / 2;\n\n return {\n lightness: (1 - value) * 100,\n saturation: value === 0 ? 0 : (chroma / value) * 100,\n };\n}\n\nfunction palettePositionToHsl(\n saturation: number,\n lightness: number,\n color: ColorModel,\n): ColorModel {\n const hsvSaturation = clamp(saturation / 100, 0, 1);\n const value = 1 - clamp(lightness / 100, 0, 1);\n const hslLightness = value * (1 - hsvSaturation / 2);\n const hslSaturation =\n hslLightness === 0 || hslLightness === 1\n ? 0\n : ((value - hslLightness) / Math.min(hslLightness, 1 - hslLightness)) * 100;\n\n return {\n ...color,\n lightness: hslLightness * 100,\n saturation: clamp(hslSaturation, 0, 100),\n };\n}\n\nfunction updateFromPoint(\n event: PointerEvent<HTMLDivElement>,\n setColor: (color: ColorModel) => void,\n color: ColorModel,\n) {\n const rect = event.currentTarget.getBoundingClientRect();\n const saturation = Math.round(clamp((event.clientX - rect.left) / rect.width, 0, 1) * 100);\n const lightness = Math.round(clamp((event.clientY - rect.top) / rect.height, 0, 1) * 100);\n setColor(palettePositionToHsl(saturation, lightness, color));\n}\n\nexport type ColorPickerPaletteProps = Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\">;\nexport const ColorPickerPalette = forwardRef<HTMLDivElement, ColorPickerPaletteProps>(\n function ColorPickerPalette(\n {\n children,\n className,\n onKeyDown,\n onPointerCancel,\n onPointerDown,\n onPointerMove,\n onPointerUp,\n style,\n ...props\n },\n ref,\n ) {\n const { color, disabled, setColor, value } = useColorPicker();\n const [isDragging, setIsDragging] = useState(false);\n const background = `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${color.hue} 100% 50%))`;\n const palettePosition = hslToPalettePosition(color);\n const paletteStyle = {\n \"--jaci-color-palette-lightness\": formatPalettePercentage(palettePosition.lightness),\n \"--jaci-color-palette-saturation\": formatPalettePercentage(palettePosition.saturation),\n background,\n ...style,\n } as CSSProperties;\n\n const releasePointer = (event: PointerEvent<HTMLDivElement>) => {\n if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n setIsDragging(false);\n };\n\n return (\n <div\n {...props}\n ref={ref}\n aria-disabled={disabled || undefined}\n aria-label={props[\"aria-label\"] ?? \"Color saturation and lightness\"}\n aria-valuemax={100}\n aria-valuemin={0}\n aria-valuenow={Math.round(palettePosition.saturation)}\n aria-valuetext={value}\n className={cx(colorPicker().palette, className)}\n data-disabled={disabled || undefined}\n data-dragging={isDragging || undefined}\n data-slot=\"color-picker-palette\"\n onKeyDown={(event) => {\n const step = event.shiftKey ? 10 : 1;\n if (\n event.key === \"ArrowLeft\" ||\n event.key === \"ArrowRight\" ||\n event.key === \"ArrowUp\" ||\n event.key === \"ArrowDown\"\n ) {\n event.preventDefault();\n const saturation =\n event.key === \"ArrowLeft\"\n ? Math.max(0, palettePosition.saturation - step)\n : event.key === \"ArrowRight\"\n ? Math.min(100, palettePosition.saturation + step)\n : palettePosition.saturation;\n const lightness =\n event.key === \"ArrowDown\"\n ? Math.min(100, palettePosition.lightness + step)\n : event.key === \"ArrowUp\"\n ? Math.max(0, palettePosition.lightness - step)\n : palettePosition.lightness;\n setColor(palettePositionToHsl(saturation, lightness, color));\n }\n onKeyDown?.(event);\n }}\n onPointerDown={(event) => {\n if (!disabled) {\n updateFromPoint(event, setColor, color);\n setIsDragging(true);\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Pointer capture is not available in every test environment.\n }\n }\n onPointerDown?.(event);\n }}\n onPointerMove={(event) => {\n if (!disabled && isDragging) updateFromPoint(event, setColor, color);\n onPointerMove?.(event);\n }}\n onPointerUp={(event) => {\n releasePointer(event);\n onPointerUp?.(event);\n }}\n onPointerCancel={(event) => {\n releasePointer(event);\n onPointerCancel?.(event);\n }}\n role=\"slider\"\n style={paletteStyle}\n tabIndex={props.tabIndex ?? (disabled ? -1 : 0)}\n >\n <span\n aria-hidden=\"true\"\n className={colorPicker().paletteIndicator}\n data-slot=\"color-picker-palette-indicator\"\n />\n {children}\n </div>\n );\n },\n);\n\nexport type ColorPickerHueProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerHue = forwardRef<HTMLInputElement, ColorPickerHueProps>(\n function ColorPickerHue({ className, onInput, ...props }, ref) {\n const { color, setColor } = useColorPicker();\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Hue\"}\n className={cx(colorPicker().hue, className)}\n data-slot=\"color-picker-hue\"\n max={360}\n min={0}\n onInput={(event) => {\n setColor({ ...color, hue: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={1}\n type=\"range\"\n value={color.hue}\n />\n );\n },\n);\n\nexport type ColorPickerAlphaProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerAlpha = forwardRef<HTMLInputElement, ColorPickerAlphaProps>(\n function ColorPickerAlpha({ className, onInput, style, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n if (!showAlpha) return null;\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Opacity\"}\n className={cx(colorPicker().alpha, className)}\n data-slot=\"color-picker-alpha\"\n max={1}\n min={0}\n onInput={(event) => {\n setColor({ ...color, alpha: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={0.01}\n style={{\n ...style,\n background: `linear-gradient(to right, transparent, ${formatColor({ ...color, alpha: 1 }, \"rgb\")})`,\n }}\n type=\"range\"\n value={color.alpha}\n />\n );\n },\n);\n\nexport type ColorPickerSwatchesProps = ComponentPropsWithoutRef<\"fieldset\">;\nexport const ColorPickerSwatches = forwardRef<HTMLFieldSetElement, ColorPickerSwatchesProps>(\n function ColorPickerSwatches({ children, className, ...props }, ref) {\n const { swatches } = useColorPicker();\n return (\n <fieldset\n {...props}\n ref={ref}\n className={cx(colorPicker().swatches, className)}\n data-slot=\"color-picker-swatches\"\n >\n {children ?? swatches.map((color) => <ColorPickerSwatch color={color} key={color} />)}\n </fieldset>\n );\n },\n);\n\nexport interface ColorPickerSwatchProps extends ComponentPropsWithoutRef<\"button\"> {\n color: string;\n}\nexport const ColorPickerSwatch = forwardRef<HTMLButtonElement, ColorPickerSwatchProps>(\n function ColorPickerSwatch({ children, className, color, style, ...props }, ref) {\n const context = useColorPicker();\n const parsed = parseColor(color);\n const selected =\n parsed && formatColor(parsed, context.format, context.showAlpha) === context.value;\n return (\n <button\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? color}\n aria-pressed={selected || undefined}\n className={cx(colorPicker().swatch, className)}\n data-selected={selected || undefined}\n data-slot=\"color-picker-swatch\"\n onClick={(event) => {\n if (parsed) context.setColor(parsed);\n props.onClick?.(event);\n }}\n style={{ backgroundColor: color, ...style }}\n type=\"button\"\n >\n {children}\n </button>\n );\n },\n);\n\nexport type ColorPickerInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerInput = forwardRef<HTMLInputElement, ColorPickerInputProps>(\n function ColorPickerInput({ className, onBlur, onKeyDown, ...props }, ref) {\n const { format, setColor, showAlpha, value } = useColorPicker();\n const [draft, setDraft] = useState(value);\n const [invalid, setInvalid] = useState(false);\n useEffect(() => setDraft(value), [value]);\n const commit = () => {\n const parsed = parseColor(draft);\n if (!parsed) {\n setInvalid(true);\n setDraft(value);\n return;\n }\n setInvalid(false);\n setColor(parsed);\n setDraft(formatColor(parsed, format, showAlpha));\n };\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Color value\"}\n aria-invalid={invalid || undefined}\n className={cx(colorPicker().input, className)}\n data-slot=\"color-picker-input\"\n onBlur={(event) => {\n commit();\n onBlur?.(event);\n }}\n onChange={(event) => {\n setDraft(event.currentTarget.value);\n setInvalid(false);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n commit();\n }\n onKeyDown?.(event);\n }}\n type=\"text\"\n value={draft}\n />\n );\n },\n);\n\nexport type ColorPickerNativeInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerNativeInput = forwardRef<HTMLInputElement, ColorPickerNativeInputProps>(\n function ColorPickerNativeInput({ className, onInput, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n const value = formatColor({ ...color, alpha: 1 }, \"hex\");\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Choose a color\"}\n className={cx(colorPicker().nativeInput, className)}\n data-slot=\"color-picker-native-input\"\n onInput={(event) => {\n const parsed = parseColor(event.currentTarget.value);\n if (parsed) setColor({ ...parsed, alpha: showAlpha ? color.alpha : 1 });\n onInput?.(event);\n }}\n type=\"color\"\n value={value.slice(0, 7)}\n />\n );\n },\n);\n\nexport const ColorPicker = {\n Root: ColorPickerRoot,\n Label: ColorPickerLabel,\n Control: ColorPickerControl,\n Trigger: ColorPickerTrigger,\n Preview: ColorPickerPreview,\n Value: ColorPickerValue,\n Portal: ColorPickerPortal,\n Positioner: ColorPickerPositioner,\n Popup: ColorPickerPopup,\n Palette: ColorPickerPalette,\n Hue: ColorPickerHue,\n Alpha: ColorPickerAlpha,\n Swatches: ColorPickerSwatches,\n Swatch: ColorPickerSwatch,\n Input: ColorPickerInput,\n NativeInput: ColorPickerNativeInput,\n createHandle: BasePopover.createHandle,\n};\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,q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AAS,uBAAuB,EAAE,WAAW,SAAS,GAAG,SAAS,KAAK;CACrE,MAAM,EAAE,OAAO,UAAU,cAAc,eAAe;CACtD,MAAM,QAAQ,YAAY;EAAE,GAAG;EAAO,OAAO;CAAE,GAAG,KAAK;CACvD,OACE,oBAAC,SAAD;EACE,GAAI;EACC;EACL,cAAY,MAAM,iBAAiB;EACnC,WAAW,GAAG,YAAY,CAAC,CAAC,aAAa,SAAS;EAClD,aAAU;EACV,UAAU,UAAU;GAClB,MAAM,SAAS,WAAW,MAAM,cAAc,KAAK;GACnD,IAAI,QAAQ,SAAS;IAAE,GAAG;IAAQ,OAAO,YAAY,MAAM,QAAQ;GAAE,CAAC;GACtE,UAAU,KAAK;EACjB;EACA,MAAK;EACL,OAAO,MAAM,MAAM,GAAG,CAAC;CACxB,CAAA;AAEL,CACF;AAEA,MAAa,cAAc;CACzB,MAAM;CACN,OAAO;CACP,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO;CACP,QAAQ;CACR,YAAY;CACZ,OAAO;CACP,SAAS;CACT,KAAK;CACL,OAAO;CACP,UAAU;CACV,QAAQ;CACR,OAAO;CACP,aAAa;CACb,cAAcA,QAAY;AAC5B"}
|
|
1
|
+
{"version":3,"file":"color-picker.js","names":["BasePopover"],"sources":["../../../src/components/color-picker/color-picker.tsx"],"sourcesContent":["\"use client\";\n\nimport { Popover as BasePopover } from \"@base-ui/react/popover\";\nimport { createContext, forwardRef, useContext, useEffect, useId, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, CSSProperties, PointerEvent, ReactNode } from \"react\";\nimport type { PopoverRoot as BasePopoverRoot } from \"@base-ui/react/popover\";\n\nimport { cx } from \"../../styled-system/css\";\nimport { colorPicker } from \"../../styled-system/recipes\";\nimport { withRecipeClassName } from \"../base-ui\";\nimport { useThemePortalProps } from \"../../theme/theme-scope\";\nimport { defaultColor, formatColor, parseColor } from \"./color-utils\";\nimport type { ColorFormat, ColorModel } from \"./color-utils\";\n\nexport type { ColorFormat, ColorModel } from \"./color-utils\";\nexport { defaultColor, formatColor, parseColor } from \"./color-utils\";\n\ninterface ColorPickerContextValue {\n color: ColorModel;\n disabled: boolean;\n format: ColorFormat;\n inputId: string;\n setColor: (color: ColorModel) => void;\n showAlpha: boolean;\n swatches: string[];\n value: string;\n}\n\nconst ColorPickerContext = createContext<ColorPickerContextValue | null>(null);\n\nfunction useColorPicker() {\n const context = useContext(ColorPickerContext);\n if (!context) throw new Error(\"ColorPicker parts must be rendered inside ColorPicker.Root.\");\n return context;\n}\n\nexport interface ColorPickerRootProps extends Omit<BasePopoverRoot.Props, \"children\"> {\n children?: ReactNode;\n defaultValue?: string;\n disabled?: boolean;\n format?: ColorFormat;\n id?: string;\n name?: string;\n onValueChange?: (value: string) => void;\n showAlpha?: boolean;\n swatches?: string[];\n value?: string;\n}\n\nexport function ColorPickerRoot({\n children,\n defaultValue = \"#000000\",\n disabled = false,\n format = \"hex\",\n id,\n name,\n onValueChange,\n showAlpha = false,\n swatches = [],\n value: controlledValue,\n ...popoverProps\n}: ColorPickerRootProps) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const [uncontrolledColor, setUncontrolledColor] = useState<ColorModel>(() =>\n defaultColor(defaultValue),\n );\n const parsedControlled = parseColor(controlledValue);\n const color = parsedControlled ?? uncontrolledColor;\n const formattedValue = formatColor(color, format, showAlpha);\n const setColor = (nextColor: ColorModel) => {\n setUncontrolledColor(nextColor);\n onValueChange?.(formatColor(nextColor, format, showAlpha));\n };\n\n return (\n <ColorPickerContext.Provider\n value={{\n color,\n disabled,\n format,\n inputId,\n setColor,\n showAlpha,\n swatches,\n value: formattedValue,\n }}\n >\n <BasePopover.Root {...popoverProps}>\n {children}\n {name ? (\n <input\n aria-hidden=\"true\"\n id={`${inputId}-value`}\n name={name}\n type=\"hidden\"\n value={formattedValue}\n />\n ) : null}\n </BasePopover.Root>\n </ColorPickerContext.Provider>\n );\n}\n\nexport interface ColorPickerLabelProps extends ComponentPropsWithoutRef<\"label\"> {}\nexport const ColorPickerLabel = forwardRef<HTMLLabelElement, ColorPickerLabelProps>(\n function ColorPickerLabel({ children, className, htmlFor, ...props }, ref) {\n const { inputId } = useColorPicker();\n return (\n <label\n {...props}\n ref={ref}\n className={cx(colorPicker().label, className)}\n data-slot=\"color-picker-label\"\n htmlFor={htmlFor ?? inputId}\n >\n {children}\n </label>\n );\n },\n);\n\nexport type ColorPickerControlProps = ComponentPropsWithoutRef<\"div\">;\nexport const ColorPickerControl = forwardRef<HTMLDivElement, ColorPickerControlProps>(\n function ColorPickerControl({ className, ...props }, ref) {\n return (\n <div\n {...props}\n ref={ref}\n className={cx(colorPicker().control, className)}\n data-slot=\"color-picker-control\"\n />\n );\n },\n);\n\nexport type ColorPickerTriggerProps = ComponentPropsWithoutRef<typeof BasePopover.Trigger>;\nexport const ColorPickerTrigger = forwardRef<HTMLButtonElement, ColorPickerTriggerProps>(\n function ColorPickerTrigger({ className, disabled, ...props }, ref) {\n const context = useColorPicker();\n return (\n <BasePopover.Trigger\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().trigger, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-trigger\"\n disabled={disabled ?? context.disabled}\n id={props.id ?? context.inputId}\n />\n );\n },\n);\n\nexport type ColorPickerPreviewProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerPreview = forwardRef<HTMLSpanElement, ColorPickerPreviewProps>(\n function ColorPickerPreview({ className, style, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? value}\n className={cx(colorPicker().preview, className)}\n data-slot=\"color-picker-preview\"\n role=\"img\"\n style={{ backgroundColor: value, ...style }}\n />\n );\n },\n);\n\nexport type ColorPickerValueProps = ComponentPropsWithoutRef<\"span\">;\nexport const ColorPickerValue = forwardRef<HTMLSpanElement, ColorPickerValueProps>(\n function ColorPickerValue({ className, ...props }, ref) {\n const { value } = useColorPicker();\n return (\n <span\n {...props}\n ref={ref}\n className={cx(colorPicker().value, className)}\n data-slot=\"color-picker-value\"\n >\n {props.children ?? value}\n </span>\n );\n },\n);\n\nexport function ColorPickerPortal(props: ComponentPropsWithoutRef<typeof BasePopover.Portal>) {\n return <BasePopover.Portal {...useThemePortalProps(props)} />;\n}\nexport type ColorPickerPositionerProps = ComponentPropsWithoutRef<typeof BasePopover.Positioner>;\nexport const ColorPickerPositioner = forwardRef<HTMLDivElement, ColorPickerPositionerProps>(\n function ColorPickerPositioner({ className, ...props }, ref) {\n return (\n <BasePopover.Positioner\n {...props}\n ref={ref}\n className={withRecipeClassName(colorPicker().positioner, className)}\n data-slot=\"color-picker-positioner\"\n />\n );\n },\n);\n\nexport type ColorPickerPopupProps = ComponentPropsWithoutRef<typeof BasePopover.Popup>;\nexport const ColorPickerPopup = forwardRef<HTMLDivElement, ColorPickerPopupProps>(\n function ColorPickerPopup({ className, ...props }, ref) {\n return (\n <BasePopover.Popup\n {...props}\n aria-label={props[\"aria-label\"] ?? \"Color picker\"}\n ref={ref}\n className={withRecipeClassName(colorPicker().popup, className)}\n data-jaci-component=\"color-picker\"\n data-slot=\"color-picker-popup\"\n />\n );\n },\n);\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(max, Math.max(min, value));\n}\n\nfunction formatPalettePercentage(value: number) {\n return `${Number(value.toFixed(2))}%`;\n}\n\nfunction hslToPalettePosition(color: ColorModel) {\n const lightness = clamp(color.lightness / 100, 0, 1);\n const saturation = clamp(color.saturation / 100, 0, 1);\n const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;\n const value = lightness + chroma / 2;\n\n return {\n lightness: (1 - value) * 100,\n saturation: value === 0 ? 0 : (chroma / value) * 100,\n };\n}\n\nfunction palettePositionToHsl(\n saturation: number,\n lightness: number,\n color: ColorModel,\n): ColorModel {\n const hsvSaturation = clamp(saturation / 100, 0, 1);\n const value = 1 - clamp(lightness / 100, 0, 1);\n const hslLightness = value * (1 - hsvSaturation / 2);\n const hslSaturation =\n hslLightness === 0 || hslLightness === 1\n ? 0\n : ((value - hslLightness) / Math.min(hslLightness, 1 - hslLightness)) * 100;\n\n return {\n ...color,\n lightness: hslLightness * 100,\n saturation: clamp(hslSaturation, 0, 100),\n };\n}\n\nfunction updateFromPoint(\n event: PointerEvent<HTMLDivElement>,\n setColor: (color: ColorModel) => void,\n color: ColorModel,\n) {\n const rect = event.currentTarget.getBoundingClientRect();\n const saturation = Math.round(clamp((event.clientX - rect.left) / rect.width, 0, 1) * 100);\n const lightness = Math.round(clamp((event.clientY - rect.top) / rect.height, 0, 1) * 100);\n setColor(palettePositionToHsl(saturation, lightness, color));\n}\n\nexport type ColorPickerPaletteProps = Omit<ComponentPropsWithoutRef<\"div\">, \"onChange\">;\nexport const ColorPickerPalette = forwardRef<HTMLDivElement, ColorPickerPaletteProps>(\n function ColorPickerPalette(\n {\n children,\n className,\n onKeyDown,\n onPointerCancel,\n onPointerDown,\n onPointerMove,\n onPointerUp,\n style,\n ...props\n },\n ref,\n ) {\n const { color, disabled, setColor, value } = useColorPicker();\n const [isDragging, setIsDragging] = useState(false);\n const background = `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, hsl(${color.hue} 100% 50%))`;\n const palettePosition = hslToPalettePosition(color);\n const paletteStyle = {\n \"--jaci-color-palette-lightness\": formatPalettePercentage(palettePosition.lightness),\n \"--jaci-color-palette-saturation\": formatPalettePercentage(palettePosition.saturation),\n background,\n ...style,\n } as CSSProperties;\n\n const releasePointer = (event: PointerEvent<HTMLDivElement>) => {\n if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n setIsDragging(false);\n };\n\n return (\n <div\n {...props}\n ref={ref}\n aria-disabled={disabled || undefined}\n aria-label={props[\"aria-label\"] ?? \"Color saturation and lightness\"}\n aria-valuemax={100}\n aria-valuemin={0}\n aria-valuenow={Math.round(palettePosition.saturation)}\n aria-valuetext={value}\n className={cx(colorPicker().palette, className)}\n data-disabled={disabled || undefined}\n data-dragging={isDragging || undefined}\n data-slot=\"color-picker-palette\"\n onKeyDown={(event) => {\n const step = event.shiftKey ? 10 : 1;\n if (\n event.key === \"ArrowLeft\" ||\n event.key === \"ArrowRight\" ||\n event.key === \"ArrowUp\" ||\n event.key === \"ArrowDown\"\n ) {\n event.preventDefault();\n const saturation =\n event.key === \"ArrowLeft\"\n ? Math.max(0, palettePosition.saturation - step)\n : event.key === \"ArrowRight\"\n ? Math.min(100, palettePosition.saturation + step)\n : palettePosition.saturation;\n const lightness =\n event.key === \"ArrowDown\"\n ? Math.min(100, palettePosition.lightness + step)\n : event.key === \"ArrowUp\"\n ? Math.max(0, palettePosition.lightness - step)\n : palettePosition.lightness;\n setColor(palettePositionToHsl(saturation, lightness, color));\n }\n onKeyDown?.(event);\n }}\n onPointerDown={(event) => {\n if (!disabled) {\n updateFromPoint(event, setColor, color);\n setIsDragging(true);\n try {\n event.currentTarget.setPointerCapture(event.pointerId);\n } catch {\n // Pointer capture is not available in every test environment.\n }\n }\n onPointerDown?.(event);\n }}\n onPointerMove={(event) => {\n if (!disabled && isDragging) updateFromPoint(event, setColor, color);\n onPointerMove?.(event);\n }}\n onPointerUp={(event) => {\n releasePointer(event);\n onPointerUp?.(event);\n }}\n onPointerCancel={(event) => {\n releasePointer(event);\n onPointerCancel?.(event);\n }}\n role=\"slider\"\n style={paletteStyle}\n tabIndex={props.tabIndex ?? (disabled ? -1 : 0)}\n >\n <span\n aria-hidden=\"true\"\n className={colorPicker().paletteIndicator}\n data-slot=\"color-picker-palette-indicator\"\n />\n {children}\n </div>\n );\n },\n);\n\nexport type ColorPickerHueProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerHue = forwardRef<HTMLInputElement, ColorPickerHueProps>(\n function ColorPickerHue({ className, onInput, ...props }, ref) {\n const { color, setColor } = useColorPicker();\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Hue\"}\n className={cx(colorPicker().hue, className)}\n data-slot=\"color-picker-hue\"\n max={360}\n min={0}\n onInput={(event) => {\n setColor({ ...color, hue: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={1}\n type=\"range\"\n value={color.hue}\n />\n );\n },\n);\n\nexport type ColorPickerAlphaProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"max\" | \"min\" | \"onChange\" | \"step\" | \"type\" | \"value\"\n>;\nexport const ColorPickerAlpha = forwardRef<HTMLInputElement, ColorPickerAlphaProps>(\n function ColorPickerAlpha({ className, onInput, style, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n if (!showAlpha) return null;\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Opacity\"}\n className={cx(colorPicker().alpha, className)}\n data-slot=\"color-picker-alpha\"\n max={1}\n min={0}\n onInput={(event) => {\n setColor({ ...color, alpha: Number(event.currentTarget.value) });\n onInput?.(event);\n }}\n step={0.01}\n style={{\n ...style,\n background: `linear-gradient(to right, transparent, ${formatColor({ ...color, alpha: 1 }, \"rgb\")})`,\n }}\n type=\"range\"\n value={color.alpha}\n />\n );\n },\n);\n\nexport type ColorPickerSwatchesProps = ComponentPropsWithoutRef<\"fieldset\">;\nexport const ColorPickerSwatches = forwardRef<HTMLFieldSetElement, ColorPickerSwatchesProps>(\n function ColorPickerSwatches({ children, className, ...props }, ref) {\n const { swatches } = useColorPicker();\n return (\n <fieldset\n {...props}\n ref={ref}\n className={cx(colorPicker().swatches, className)}\n data-slot=\"color-picker-swatches\"\n >\n {children ?? swatches.map((color) => <ColorPickerSwatch color={color} key={color} />)}\n </fieldset>\n );\n },\n);\n\nexport interface ColorPickerSwatchProps extends ComponentPropsWithoutRef<\"button\"> {\n color: string;\n}\nexport const ColorPickerSwatch = forwardRef<HTMLButtonElement, ColorPickerSwatchProps>(\n function ColorPickerSwatch({ children, className, color, style, ...props }, ref) {\n const context = useColorPicker();\n const parsed = parseColor(color);\n const selected =\n parsed && formatColor(parsed, context.format, context.showAlpha) === context.value;\n return (\n <button\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? color}\n aria-pressed={selected || undefined}\n className={cx(colorPicker().swatch, className)}\n data-selected={selected || undefined}\n data-slot=\"color-picker-swatch\"\n onClick={(event) => {\n if (parsed) context.setColor(parsed);\n props.onClick?.(event);\n }}\n style={{ backgroundColor: color, ...style }}\n type=\"button\"\n >\n {children}\n </button>\n );\n },\n);\n\nexport type ColorPickerInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerInput = forwardRef<HTMLInputElement, ColorPickerInputProps>(\n function ColorPickerInput({ className, onBlur, onKeyDown, ...props }, ref) {\n const { format, setColor, showAlpha, value } = useColorPicker();\n const [draft, setDraft] = useState(value);\n const [invalid, setInvalid] = useState(false);\n useEffect(() => setDraft(value), [value]);\n const commit = () => {\n const parsed = parseColor(draft);\n if (!parsed) {\n setInvalid(true);\n setDraft(value);\n return;\n }\n setInvalid(false);\n setColor(parsed);\n setDraft(formatColor(parsed, format, showAlpha));\n };\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Color value\"}\n aria-invalid={invalid || undefined}\n className={cx(colorPicker().input, className)}\n data-slot=\"color-picker-input\"\n onBlur={(event) => {\n commit();\n onBlur?.(event);\n }}\n onChange={(event) => {\n setDraft(event.currentTarget.value);\n setInvalid(false);\n }}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n commit();\n }\n onKeyDown?.(event);\n }}\n type=\"text\"\n value={draft}\n />\n );\n },\n);\n\nexport type ColorPickerNativeInputProps = Omit<\n ComponentPropsWithoutRef<\"input\">,\n \"onChange\" | \"type\" | \"value\"\n>;\nexport const ColorPickerNativeInput = forwardRef<HTMLInputElement, ColorPickerNativeInputProps>(\n function ColorPickerNativeInput({ className, onInput, ...props }, ref) {\n const { color, setColor, showAlpha } = useColorPicker();\n const value = formatColor({ ...color, alpha: 1 }, \"hex\");\n return (\n <input\n {...props}\n ref={ref}\n aria-label={props[\"aria-label\"] ?? \"Choose a color\"}\n className={cx(colorPicker().nativeInput, className)}\n data-slot=\"color-picker-native-input\"\n onInput={(event) => {\n const parsed = parseColor(event.currentTarget.value);\n if (parsed) setColor({ ...parsed, alpha: showAlpha ? color.alpha : 1 });\n onInput?.(event);\n }}\n type=\"color\"\n value={value.slice(0, 7)}\n />\n );\n },\n);\n\nexport const ColorPicker = {\n Root: ColorPickerRoot,\n Label: ColorPickerLabel,\n Control: ColorPickerControl,\n Trigger: ColorPickerTrigger,\n Preview: ColorPickerPreview,\n Value: ColorPickerValue,\n Portal: ColorPickerPortal,\n Positioner: ColorPickerPositioner,\n Popup: ColorPickerPopup,\n Palette: ColorPickerPalette,\n Hue: ColorPickerHue,\n Alpha: ColorPickerAlpha,\n Swatches: ColorPickerSwatches,\n Swatch: ColorPickerSwatch,\n Input: ColorPickerInput,\n NativeInput: ColorPickerNativeInput,\n createHandle: BasePopover.createHandle,\n};\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,qBAAqB,cAA8C,IAAI;AAE7E,SAAS,iBAAiB;CACxB,MAAM,UAAU,WAAW,kBAAkB;CAC7C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,6DAA6D;CAC3F,OAAO;AACT;AAeA,SAAgB,gBAAgB,EAC9B,UACA,eAAe,WACf,WAAW,OACX,SAAS,OACT,IACA,MACA,eACA,YAAY,OACZ,WAAW,CAAC,GACZ,OAAO,iBACP,GAAG,gBACoB;CACvB,MAAM,cAAc,MAAM;CAC1B,MAAM,UAAU,MAAM;CACtB,MAAM,CAAC,mBAAmB,wBAAwB,eAChD,aAAa,YAAY,CAC3B;CAEA,MAAM,QADmB,WAAW,eACP,KAAK;CAClC,MAAM,iBAAiB,YAAY,OAAO,QAAQ,SAAS;CAC3D,MAAM,YAAY,cAA0B;EAC1C,qBAAqB,SAA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G,CAAC;CACxB,CAAA;AAEL,CACF;AAEA,MAAa,cAAc;CACzB,MAAM;CACN,OAAO;CACP,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO;CACP,QAAQ;CACR,YAAY;CACZ,OAAO;CACP,SAAS;CACT,KAAK;CACL,OAAO;CACP,UAAU;CACV,QAAQ;CACR,OAAO;CACP,aAAa;CACb,cAAcA,QAAY;AAC5B"}
|
|
@@ -76,9 +76,11 @@ function rgbToHsl(red, green, blue, alpha = 1) {
|
|
|
76
76
|
let hue = 0;
|
|
77
77
|
const lightness = (max + min) / 2;
|
|
78
78
|
const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
|
|
79
|
-
if (delta !== 0)
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if (delta !== 0) {
|
|
80
|
+
if (max === r) hue = 60 * ((g - b) / delta % 6);
|
|
81
|
+
else if (max === g) hue = 60 * ((b - r) / delta + 2);
|
|
82
|
+
else hue = 60 * ((r - g) / delta + 4);
|
|
83
|
+
}
|
|
82
84
|
return {
|
|
83
85
|
alpha: clamp(alpha, 0, 1),
|
|
84
86
|
hue: (hue + 360) % 360,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-utils.cjs","names":[],"sources":["../../../src/components/color-picker/color-utils.ts"],"sourcesContent":["export type ColorFormat = \"hex\" | \"rgb\" | \"hsl\";\n\nexport interface ColorModel {\n alpha: number;\n hue: number;\n lightness: number;\n saturation: number;\n}\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nfunction parseNumber(value: string, min: number, max: number) {\n const parsed = Number.parseFloat(value);\n return Number.isFinite(parsed) ? clamp(parsed, min, max) : null;\n}\n\nfunction parseAlpha(value: string | undefined) {\n if (value === undefined) return 1;\n if (value.trim().endsWith(\"%\")) {\n return parseNumber(value, 0, 100) === null\n ? null\n : (parseNumber(value, 0, 100) as number) / 100;\n }\n return parseNumber(value, 0, 1);\n}\n\nfunction parseHex(value: string): ColorModel | null {\n const hex = value.slice(1);\n if (![3, 4, 6, 8].includes(hex.length) || !/^[\\da-f]+$/i.test(hex)) return null;\n const expanded =\n hex.length <= 4\n ? hex\n .split(\"\")\n .map((part) => `${part}${part}`)\n .join(\"\")\n : hex;\n const red = Number.parseInt(expanded.slice(0, 2), 16) / 255;\n const green = Number.parseInt(expanded.slice(2, 4), 16) / 255;\n const blue = Number.parseInt(expanded.slice(4, 6), 16) / 255;\n const alpha = expanded.length === 8 ? Number.parseInt(expanded.slice(6, 8), 16) / 255 : 1;\n return rgbToHsl(red * 255, green * 255, blue * 255, alpha);\n}\n\nfunction parseRgb(value: string): ColorModel | null {\n const match = value.match(\n /^rgba?\\(\\s*([^,\\s]+)[,\\s]+([^,\\s]+)[,\\s]+([^,\\s]+)(?:\\s*[,/]\\s*([^\\s]+))?\\s*\\)$/i,\n );\n if (!match) return null;\n\n const redValue = match[1];\n const greenValue = match[2];\n const blueValue = match[3];\n if (!redValue || !greenValue || !blueValue) return null;\n const channels = [redValue, greenValue, blueValue].map((channel) => {\n if (channel.endsWith(\"%\")) {\n const percentage = parseNumber(channel, 0, 100);\n return percentage === null ? null : (percentage / 100) * 255;\n }\n return parseNumber(channel, 0, 255);\n });\n const alpha = parseAlpha(match[4]);\n if (channels.some((channel) => channel === null) || alpha === null) return null;\n return rgbToHsl(channels[0] as number, channels[1] as number, channels[2] as number, alpha);\n}\n\nfunction parseHsl(value: string): ColorModel | null {\n const match = value.match(\n /^hsla?\\(\\s*([^,\\s]+)(?:deg)?[,\\s]+([^,\\s]+)[,\\s]+([^,\\s]+)(?:\\s*[,/]\\s*([^\\s]+))?\\s*\\)$/i,\n );\n if (!match) return null;\n const hueValue = match[1];\n const saturationValue = match[2];\n const lightnessValue = match[3];\n if (!hueValue || !saturationValue || !lightnessValue) return null;\n const hue = parseNumber(hueValue.replace(/deg$/i, \"\"), -360, 360);\n const saturation = parseNumber(saturationValue, 0, 100);\n const lightness = parseNumber(lightnessValue, 0, 100);\n const alpha = parseAlpha(match[4]);\n if (hue === null || saturation === null || lightness === null || alpha === null) return null;\n if (!saturationValue.endsWith(\"%\") || !lightnessValue.endsWith(\"%\")) return null;\n return { alpha, hue: (hue + 360) % 360, lightness, saturation };\n}\n\nfunction rgbToHsl(red: number, green: number, blue: number, alpha = 1): ColorModel {\n const r = red / 255;\n const g = green / 255;\n const b = blue / 255;\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const delta = max - min;\n let hue = 0;\n const lightness = (max + min) / 2;\n const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));\n\n if (delta !== 0) {\n if (max === r) hue = 60 * (((g - b) / delta) % 6);\n else if (max === g) hue = 60 * ((b - r) / delta + 2);\n else hue = 60 * ((r - g) / delta + 4);\n }\n\n return {\n alpha: clamp(alpha, 0, 1),\n hue: (hue + 360) % 360,\n lightness: lightness * 100,\n saturation: saturation * 100,\n };\n}\n\nfunction hslToRgb({ hue, lightness, saturation }: ColorModel) {\n const h = hue / 360;\n const s = saturation / 100;\n const l = lightness / 100;\n const chroma = (1 - Math.abs(2 * l - 1)) * s;\n const segment = h * 6;\n const x = chroma * (1 - Math.abs((segment % 2) - 1));\n const [r, g, b] =\n segment < 1\n ? [chroma, x, 0]\n : segment < 2\n ? [x, chroma, 0]\n : segment < 3\n ? [0, chroma, x]\n : segment < 4\n ? [0, x, chroma]\n : segment < 5\n ? [x, 0, chroma]\n : [chroma, 0, x];\n const match = l - chroma / 2;\n return {\n blue: Math.round((b + match) * 255),\n green: Math.round((g + match) * 255),\n red: Math.round((r + match) * 255),\n };\n}\n\nexport function parseColor(value: string | undefined): ColorModel | null {\n if (!value) return null;\n const normalized = value.trim();\n if (normalized.startsWith(\"#\")) return parseHex(normalized);\n if (/^rgba?/i.test(normalized)) return parseRgb(normalized);\n if (/^hsla?/i.test(normalized)) return parseHsl(normalized);\n return null;\n}\n\nfunction formatAlpha(alpha: number) {\n return Number(alpha.toFixed(3)).toString();\n}\n\nexport function formatColor(color: ColorModel, format: ColorFormat, showAlpha = false) {\n const rgb = hslToRgb(color);\n if (format === \"hex\") {\n const base = [rgb.red, rgb.green, rgb.blue]\n .map((channel) => channel.toString(16).padStart(2, \"0\"))\n .join(\"\");\n return `#${base}${\n showAlpha\n ? Math.round(color.alpha * 255)\n .toString(16)\n .padStart(2, \"0\")\n : \"\"\n }`;\n }\n if (format === \"rgb\") {\n return showAlpha\n ? `rgba(${rgb.red}, ${rgb.green}, ${rgb.blue}, ${formatAlpha(color.alpha)})`\n : `rgb(${rgb.red}, ${rgb.green}, ${rgb.blue})`;\n }\n return showAlpha\n ? `hsla(${Math.round(color.hue)}, ${Math.round(color.saturation)}%, ${Math.round(color.lightness)}%, ${formatAlpha(color.alpha)})`\n : `hsl(${Math.round(color.hue)}, ${Math.round(color.saturation)}%, ${Math.round(color.lightness)}%)`;\n}\n\nexport function defaultColor(value?: string) {\n return parseColor(value) ?? { alpha: 1, hue: 0, lightness: 0, saturation: 0 };\n}\n"],"mappings":";AASA,MAAM,SAAS,OAAe,KAAa,QAAgB,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;AAE7F,SAAS,YAAY,OAAe,KAAa,KAAa;CAC5D,MAAM,SAAS,OAAO,WAAW,KAAK;CACtC,OAAO,OAAO,SAAS,MAAM,IAAI,MAAM,QAAQ,KAAK,GAAG,IAAI;AAC7D;AAEA,SAAS,WAAW,OAA2B;CAC7C,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,GAC3B,OAAO,YAAY,OAAO,GAAG,GAAG,MAAM,OAClC,OACC,YAAY,OAAO,GAAG,GAAG,IAAe;CAE/C,OAAO,YAAY,OAAO,GAAG,CAAC;AAChC;AAEA,SAAS,SAAS,OAAkC;CAClD,MAAM,MAAM,MAAM,MAAM,CAAC;CACzB,IAAI,CAAC;EAAC;EAAG;EAAG;EAAG;CAAC,CAAC,CAAC,SAAS,IAAI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AK,IAAI;EAAO,IAAI;CAAI,CAAC,CACxC,KAAK,YAAY,QAAQ,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CACvD,KAAK,EACM,IACZ,YACI,KAAK,MAAM,MAAM,QAAQ,GAAG,CAAC,CAC1B,SAAS,EAAE,CAAC,CACZ,SAAS,GAAG,GAAG,IAClB;CAGR,IAAI,WAAW,OACb,OAAO,YACH,QAAQ,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,KAAK,IAAI,YAAY,MAAM,KAAK,EAAE,KACxE,OAAO,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,KAAK;CAEhD,OAAO,YACH,QAAQ,KAAK,MAAM,MAAM,GAAG,EAAE,IAAI,KAAK,MAAM,MAAM,UAAU,EAAE,KAAK,KAAK,MAAM,MAAM,SAAS,EAAE,KAAK,YAAY,MAAM,KAAK,EAAE,KAC9H,OAAO,KAAK,MAAM,MAAM,GAAG,EAAE,IAAI,KAAK,MAAM,MAAM,UAAU,EAAE,KAAK,KAAK,MAAM,MAAM,SAAS,EAAE;AACrG;AAEA,SAAgB,aAAa,OAAgB;CAC3C,OAAO,WAAW,KAAK,KAAK;EAAE,OAAO;EAAG,KAAK;EAAG,WAAW;EAAG,YAAY;CAAE;AAC9E"}
|
|
1
|
+
{"version":3,"file":"color-utils.cjs","names":[],"sources":["../../../src/components/color-picker/color-utils.ts"],"sourcesContent":["export type ColorFormat = \"hex\" | \"rgb\" | \"hsl\";\n\nexport interface ColorModel {\n alpha: number;\n hue: number;\n lightness: number;\n saturation: number;\n}\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nfunction parseNumber(value: string, min: number, max: number) {\n const parsed = Number.parseFloat(value);\n return Number.isFinite(parsed) ? clamp(parsed, min, max) : null;\n}\n\nfunction parseAlpha(value: string | undefined) {\n if (value === undefined) return 1;\n if (value.trim().endsWith(\"%\")) {\n return parseNumber(value, 0, 100) === null\n ? null\n : (parseNumber(value, 0, 100) as number) / 100;\n }\n return parseNumber(value, 0, 1);\n}\n\nfunction parseHex(value: string): ColorModel | null {\n const hex = value.slice(1);\n if (![3, 4, 6, 8].includes(hex.length) || !/^[\\da-f]+$/i.test(hex)) return null;\n const expanded =\n hex.length <= 4\n ? hex\n .split(\"\")\n .map((part) => `${part}${part}`)\n .join(\"\")\n : hex;\n const red = Number.parseInt(expanded.slice(0, 2), 16) / 255;\n const green = Number.parseInt(expanded.slice(2, 4), 16) / 255;\n const blue = Number.parseInt(expanded.slice(4, 6), 16) / 255;\n const alpha = expanded.length === 8 ? Number.parseInt(expanded.slice(6, 8), 16) / 255 : 1;\n return rgbToHsl(red * 255, green * 255, blue * 255, alpha);\n}\n\nfunction parseRgb(value: string): ColorModel | null {\n const match = value.match(\n /^rgba?\\(\\s*([^,\\s]+)[,\\s]+([^,\\s]+)[,\\s]+([^,\\s]+)(?:\\s*[,/]\\s*([^\\s]+))?\\s*\\)$/i,\n );\n if (!match) return null;\n\n const redValue = match[1];\n const greenValue = match[2];\n const blueValue = match[3];\n if (!redValue || !greenValue || !blueValue) return null;\n const channels = [redValue, greenValue, blueValue].map((channel) => {\n if (channel.endsWith(\"%\")) {\n const percentage = parseNumber(channel, 0, 100);\n return percentage === null ? null : (percentage / 100) * 255;\n }\n return parseNumber(channel, 0, 255);\n });\n const alpha = parseAlpha(match[4]);\n if (channels.some((channel) => channel === null) || alpha === null) return null;\n return rgbToHsl(channels[0] as number, channels[1] as number, channels[2] as number, alpha);\n}\n\nfunction parseHsl(value: string): ColorModel | null {\n const match = value.match(\n /^hsla?\\(\\s*([^,\\s]+)(?:deg)?[,\\s]+([^,\\s]+)[,\\s]+([^,\\s]+)(?:\\s*[,/]\\s*([^\\s]+))?\\s*\\)$/i,\n );\n if (!match) return null;\n const hueValue = match[1];\n const saturationValue = match[2];\n const lightnessValue = match[3];\n if (!hueValue || !saturationValue || !lightnessValue) return null;\n const hue = parseNumber(hueValue.replace(/deg$/i, \"\"), -360, 360);\n const saturation = parseNumber(saturationValue, 0, 100);\n const lightness = parseNumber(lightnessValue, 0, 100);\n const alpha = parseAlpha(match[4]);\n if (hue === null || saturation === null || lightness === null || alpha === null) return null;\n if (!saturationValue.endsWith(\"%\") || !lightnessValue.endsWith(\"%\")) return null;\n return { alpha, hue: (hue + 360) % 360, lightness, saturation };\n}\n\nfunction rgbToHsl(red: number, green: number, blue: number, alpha = 1): ColorModel {\n const r = red / 255;\n const g = green / 255;\n const b = blue / 255;\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const delta = max - min;\n let hue = 0;\n const lightness = (max + min) / 2;\n const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));\n\n if (delta !== 0) {\n if (max === r) hue = 60 * (((g - b) / delta) % 6);\n else if (max === g) hue = 60 * ((b - r) / delta + 2);\n else hue = 60 * ((r - g) / delta + 4);\n }\n\n return {\n alpha: clamp(alpha, 0, 1),\n hue: (hue + 360) % 360,\n lightness: lightness * 100,\n saturation: saturation * 100,\n };\n}\n\nfunction hslToRgb({ hue, lightness, saturation }: ColorModel) {\n const h = hue / 360;\n const s = saturation / 100;\n const l = lightness / 100;\n const chroma = (1 - Math.abs(2 * l - 1)) * s;\n const segment = h * 6;\n const x = chroma * (1 - Math.abs((segment % 2) - 1));\n const [r, g, b] =\n segment < 1\n ? [chroma, x, 0]\n : segment < 2\n ? [x, chroma, 0]\n : segment < 3\n ? [0, chroma, x]\n : segment < 4\n ? [0, x, chroma]\n : segment < 5\n ? [x, 0, chroma]\n : [chroma, 0, x];\n const match = l - chroma / 2;\n return {\n blue: Math.round((b + match) * 255),\n green: Math.round((g + match) * 255),\n red: Math.round((r + match) * 255),\n };\n}\n\nexport function parseColor(value: string | undefined): ColorModel | null {\n if (!value) return null;\n const normalized = value.trim();\n if (normalized.startsWith(\"#\")) return parseHex(normalized);\n if (/^rgba?/i.test(normalized)) return parseRgb(normalized);\n if (/^hsla?/i.test(normalized)) return parseHsl(normalized);\n return null;\n}\n\nfunction formatAlpha(alpha: number) {\n return Number(alpha.toFixed(3)).toString();\n}\n\nexport function formatColor(color: ColorModel, format: ColorFormat, showAlpha = false) {\n const rgb = hslToRgb(color);\n if (format === \"hex\") {\n const base = [rgb.red, rgb.green, rgb.blue]\n .map((channel) => channel.toString(16).padStart(2, \"0\"))\n .join(\"\");\n return `#${base}${\n showAlpha\n ? Math.round(color.alpha * 255)\n .toString(16)\n .padStart(2, \"0\")\n : \"\"\n }`;\n }\n if (format === \"rgb\") {\n return showAlpha\n ? `rgba(${rgb.red}, ${rgb.green}, ${rgb.blue}, ${formatAlpha(color.alpha)})`\n : `rgb(${rgb.red}, ${rgb.green}, ${rgb.blue})`;\n }\n return showAlpha\n ? `hsla(${Math.round(color.hue)}, ${Math.round(color.saturation)}%, ${Math.round(color.lightness)}%, ${formatAlpha(color.alpha)})`\n : `hsl(${Math.round(color.hue)}, ${Math.round(color.saturation)}%, ${Math.round(color.lightness)}%)`;\n}\n\nexport function defaultColor(value?: string) {\n return parseColor(value) ?? { alpha: 1, hue: 0, lightness: 0, saturation: 0 };\n}\n"],"mappings":";AASA,MAAM,SAAS,OAAe,KAAa,QAAgB,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,CAAC;AAE7F,SAAS,YAAY,OAAe,KAAa,KAAa;CAC5D,MAAM,SAAS,OAAO,WAAW,KAAK;CACtC,OAAO,OAAO,SAAS,MAAM,IAAI,MAAM,QAAQ,KAAK,GAAG,IAAI;AAC7D;AAEA,SAAS,WAAW,OAA2B;CAC7C,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,GAC3B,OAAO,YAAY,OAAO,GAAG,GAAG,MAAM,OAClC,OACC,YAAY,OAAO,GAAG,GAAG,IAAe;CAE/C,OAAO,YAAY,OAAO,GAAG,CAAC;AAChC;AAEA,SAAS,SAAS,OAAkC;CAClD,MAAM,MAAM,MAAM,MAAM,CAAC;C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rF,MAAM,MAAM,SAAS,KAAK;CAC1B,IAAI,WAAW,OAIb,OAAO,IAHM;EAAC,IAAI;EAAK,IAAI;EAAO,IAAI;CAAI,CAAC,CACxC,KAAK,YAAY,QAAQ,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CACvD,KAAK,EACM,IACZ,YACI,KAAK,MAAM,MAAM,QAAQ,GAAG,CAAC,CAC1B,SAAS,EAAE,CAAC,CACZ,SAAS,GAAG,GAAG,IAClB;CAGR,IAAI,WAAW,OACb,OAAO,YACH,QAAQ,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,KAAK,IAAI,YAAY,MAAM,KAAK,EAAE,KACxE,OAAO,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,KAAK;CAEhD,OAAO,YACH,QAAQ,KAAK,MAAM,MAAM,GAAG,EAAE,IAAI,KAAK,MAAM,MAAM,UAAU,EAAE,KAAK,KAAK,MAAM,MAAM,SAAS,EAAE,KAAK,YAAY,MAAM,KAAK,EAAE,KAC9H,OAAO,KAAK,MAAM,MAAM,GAAG,EAAE,IAAI,KAAK,MAAM,MAAM,UAAU,EAAE,KAAK,KAAK,MAAM,MAAM,SAAS,EAAE;AACrG;AAEA,SAAgB,aAAa,OAAgB;CAC3C,OAAO,WAAW,KAAK,KAAK;EAAE,OAAO;EAAG,KAAK;EAAG,WAAW;EAAG,YAAY;CAAE;AAC9E"}
|
|
@@ -76,9 +76,11 @@ function rgbToHsl(red, green, blue, alpha = 1) {
|
|
|
76
76
|
let hue = 0;
|
|
77
77
|
const lightness = (max + min) / 2;
|
|
78
78
|
const saturation = delta === 0 ? 0 : delta / (1 - Math.abs(2 * lightness - 1));
|
|
79
|
-
if (delta !== 0)
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if (delta !== 0) {
|
|
80
|
+
if (max === r) hue = 60 * ((g - b) / delta % 6);
|
|
81
|
+
else if (max === g) hue = 60 * ((b - r) / delta + 2);
|
|
82
|
+
else hue = 60 * ((r - g) / delta + 4);
|
|
83
|
+
}
|
|
82
84
|
return {
|
|
83
85
|
alpha: clamp(alpha, 0, 1),
|
|
84
86
|
hue: (hue + 360) % 360,
|