@plexui/ui 0.28.1 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/Alert/Alert.js +2 -2
- package/dist/es/components/Alert/Alert.js.map +1 -1
- package/dist/es/components/Avatar/Avatar.js +3 -1
- package/dist/es/components/Avatar/Avatar.js.map +1 -1
- package/dist/es/components/Badge/index.js +1 -1
- package/dist/es/components/Badge/index.js.map +1 -1
- package/dist/es/components/Button/Button.js +4 -3
- package/dist/es/components/Button/Button.js.map +1 -1
- package/dist/es/components/Button/NavigationButton.js +10 -0
- package/dist/es/components/Button/NavigationButton.js.map +1 -0
- package/dist/es/components/Button/NavigationGlyph.js +19 -0
- package/dist/es/components/Button/NavigationGlyph.js.map +1 -0
- package/dist/es/components/Button/index.js +1 -0
- package/dist/es/components/Button/index.js.map +1 -1
- package/dist/es/components/Checkbox/Checkbox.js +2 -1
- package/dist/es/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/es/components/ColorPicker/ColorPicker.js +227 -0
- package/dist/es/components/ColorPicker/ColorPicker.js.map +1 -0
- package/dist/es/components/ColorPicker/ColorWell.js +58 -0
- package/dist/es/components/ColorPicker/ColorWell.js.map +1 -0
- package/dist/es/components/ColorPicker/index.js +3 -0
- package/dist/es/components/ColorPicker/index.js.map +1 -0
- package/dist/es/components/ColorPicker/shared.js +132 -0
- package/dist/es/components/ColorPicker/shared.js.map +1 -0
- package/dist/es/components/ContextMenu/ContextMenu.js +164 -0
- package/dist/es/components/ContextMenu/ContextMenu.js.map +1 -0
- package/dist/es/components/ContextMenu/index.js +2 -0
- package/dist/es/components/ContextMenu/index.js.map +1 -0
- package/dist/es/components/ContextMenu/shared.js +56 -0
- package/dist/es/components/ContextMenu/shared.js.map +1 -0
- package/dist/es/components/DateInput/DateInput.js +4 -2
- package/dist/es/components/DateInput/DateInput.js.map +1 -1
- package/dist/es/components/DatePicker/Calendar.js +89 -55
- package/dist/es/components/DatePicker/Calendar.js.map +1 -1
- package/dist/es/components/DatePicker/CalendarNavigationIcon.js +13 -0
- package/dist/es/components/DatePicker/CalendarNavigationIcon.js.map +1 -0
- package/dist/es/components/DatePicker/DatePicker.js +9 -2
- package/dist/es/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/es/components/DatePicker/useCalendarGutter.js +8 -0
- package/dist/es/components/DatePicker/useCalendarGutter.js.map +1 -0
- package/dist/es/components/DateRangePicker/Calendar.js +66 -49
- package/dist/es/components/DateRangePicker/Calendar.js.map +1 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js +6 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/es/components/DateRangePicker/Trigger.js +1 -1
- package/dist/es/components/DateRangePicker/Trigger.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +136 -20
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +77 -24
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/Field/Field.js +51 -4
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/FieldGroup/FieldGroup.js +4 -2
- package/dist/es/components/FieldGroup/FieldGroup.js.map +1 -1
- package/dist/es/components/FileUpload/FileUpload.js +43 -3
- package/dist/es/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +18 -16
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js.map +1 -1
- package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js +11 -6
- package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js.map +1 -1
- package/dist/es/components/Icon/index.js +2 -0
- package/dist/es/components/Icon/index.js.map +1 -1
- package/dist/es/components/Icon/svg/Disclosure.js +5 -0
- package/dist/es/components/Icon/svg/Disclosure.js.map +1 -0
- package/dist/es/components/Icon/svg/Eyedropper.js +6 -0
- package/dist/es/components/Icon/svg/Eyedropper.js.map +1 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +1 -1
- package/dist/es/components/Indicator/LoadingIndicator.js.map +1 -1
- package/dist/es/components/Input/Input.js +3 -3
- package/dist/es/components/Input/Input.js.map +1 -1
- package/dist/es/components/InputGroup/InputGroup.js +3 -1
- package/dist/es/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js +95 -93
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +306 -34
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/OTPInput/OTPInput.js +4 -1
- package/dist/es/components/OTPInput/OTPInput.js.map +1 -1
- package/dist/es/components/Page/Page.js +147 -19
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/Page/index.js.map +1 -1
- package/dist/es/components/PageControl/PageControl.js +146 -0
- package/dist/es/components/PageControl/PageControl.js.map +1 -0
- package/dist/es/components/PageControl/index.js +2 -0
- package/dist/es/components/PageControl/index.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +75 -33
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Popover/deferredOutsidePress.js +90 -0
- package/dist/es/components/Popover/deferredOutsidePress.js.map +1 -0
- package/dist/es/components/Popover/usePopoverContext.js.map +1 -1
- package/dist/es/components/RadioGroup/RadioGroup.js +1 -1
- package/dist/es/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/es/components/Select/Select.js +98 -32
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/SelectControl/SelectControl.js +48 -29
- package/dist/es/components/SelectControl/SelectControl.js.map +1 -1
- package/dist/es/components/SelectControl/index.js +1 -1
- package/dist/es/components/SelectControl/index.js.map +1 -1
- package/dist/es/components/ShimmerText/ShimmerText.js +17 -7
- package/dist/es/components/ShimmerText/ShimmerText.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +21 -8
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +61 -15
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/Sortable/Sortable.js +16 -6
- package/dist/es/components/Sortable/Sortable.js.map +1 -1
- package/dist/es/components/Stepper/Stepper.js +114 -0
- package/dist/es/components/Stepper/Stepper.js.map +1 -0
- package/dist/es/components/Stepper/index.js +2 -0
- package/dist/es/components/Stepper/index.js.map +1 -0
- package/dist/es/components/Switch/Switch.js +2 -2
- package/dist/es/components/Switch/Switch.js.map +1 -1
- package/dist/es/components/TabBar/TabBar.js +128 -0
- package/dist/es/components/TabBar/TabBar.js.map +1 -0
- package/dist/es/components/TabBar/index.js +2 -0
- package/dist/es/components/TabBar/index.js.map +1 -0
- package/dist/es/components/Tabs/Tabs.js +27 -11
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/TagInput/TagInput.js +40 -4
- package/dist/es/components/TagInput/TagInput.js.map +1 -1
- package/dist/es/components/Textarea/Textarea.js +7 -1
- package/dist/es/components/Textarea/Textarea.js.map +1 -1
- package/dist/es/components/Toast/ToastRenderer.js +86 -0
- package/dist/es/components/Toast/ToastRenderer.js.map +1 -0
- package/dist/es/components/Toast/Toaster.js +31 -16
- package/dist/es/components/Toast/Toaster.js.map +1 -1
- package/dist/es/components/Toast/toastLifecycle.js +283 -0
- package/dist/es/components/Toast/toastLifecycle.js.map +1 -0
- package/dist/es/components/Toolbar/Toolbar.js +92 -0
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -0
- package/dist/es/components/Toolbar/index.js +2 -0
- package/dist/es/components/Toolbar/index.js.map +1 -0
- package/dist/es/components/Tooltip/CopyTooltip.js +37 -11
- package/dist/es/components/Tooltip/CopyTooltip.js.map +1 -1
- package/dist/es/components/Tooltip/Tooltip.js +61 -9
- package/dist/es/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/es/hooks/useFloatingBoundary.js +35 -0
- package/dist/es/hooks/useFloatingBoundary.js.map +1 -0
- package/dist/es/hooks/usePhoneSubmenu.js +22 -0
- package/dist/es/hooks/usePhoneSubmenu.js.map +1 -0
- package/dist/es/lib/copyToClipboard.js +16 -7
- package/dist/es/lib/copyToClipboard.js.map +1 -1
- package/dist/es/lib/fieldRow.js +7 -1
- package/dist/es/lib/fieldRow.js.map +1 -1
- package/dist/es/lib/floatingBoundary.js +90 -0
- package/dist/es/lib/floatingBoundary.js.map +1 -0
- package/dist/es/lib/focusRestore.js +56 -0
- package/dist/es/lib/focusRestore.js.map +1 -0
- package/dist/es/lib/helpers.js +0 -18
- package/dist/es/lib/helpers.js.map +1 -1
- package/dist/es/lib/inputMode.js +9 -0
- package/dist/es/lib/inputMode.js.map +1 -0
- package/dist/es/lib/menuInitialFocus.js +100 -0
- package/dist/es/lib/menuInitialFocus.js.map +1 -0
- package/dist/es/lib/menuSubmenuPlacement.js +264 -0
- package/dist/es/lib/menuSubmenuPlacement.js.map +1 -0
- package/dist/es/lib/menuTriggerCover.js +70 -0
- package/dist/es/lib/menuTriggerCover.js.map +1 -0
- package/dist/es/lib/observeTextareaWidth.js +49 -0
- package/dist/es/lib/observeTextareaWidth.js.map +1 -0
- package/dist/es/lib/scrollEdges.js +34 -0
- package/dist/es/lib/scrollEdges.js.map +1 -0
- package/dist/es/lib/selectPress.js +34 -0
- package/dist/es/lib/selectPress.js.map +1 -0
- package/dist/es/lib/sortable.js +74 -20
- package/dist/es/lib/sortable.js.map +1 -1
- package/dist/es/styles/mobile-materials.css +1 -0
- package/dist/es/styles/mobile-surfaces.css +1 -0
- package/dist/types/components/Button/Button.d.ts +2 -0
- package/dist/types/components/Button/NavigationButton.d.ts +8 -0
- package/dist/types/components/Button/NavigationGlyph.d.ts +7 -0
- package/dist/types/components/Button/index.d.ts +1 -0
- package/dist/types/components/ColorPicker/ColorPicker.d.ts +34 -0
- package/dist/types/components/ColorPicker/ColorWell.d.ts +32 -0
- package/dist/types/components/ColorPicker/index.d.ts +3 -0
- package/dist/types/components/ColorPicker/shared.d.ts +69 -0
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +78 -0
- package/dist/types/components/ContextMenu/index.d.ts +1 -0
- package/dist/types/components/ContextMenu/shared.d.ts +50 -0
- package/dist/types/components/DatePicker/CalendarNavigationIcon.d.ts +5 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +7 -1
- package/dist/types/components/DatePicker/useCalendarGutter.d.ts +1 -0
- package/dist/types/components/DateRangePicker/DateRangePicker.d.ts +2 -0
- package/dist/types/components/Dialog/Dialog.d.ts +17 -6
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/Field/Field.d.ts +12 -2
- package/dist/types/components/FieldGroup/FieldGroup.d.ts +11 -2
- package/dist/types/components/Icon/index.d.ts +2 -0
- package/dist/types/components/Icon/svg/Disclosure.d.ts +6 -0
- package/dist/types/components/Icon/svg/Eyedropper.d.ts +6 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +1 -1
- package/dist/types/components/Menu/Menu.d.ts +74 -9
- package/dist/types/components/Page/Page.d.ts +24 -9
- package/dist/types/components/Page/index.d.ts +1 -1
- package/dist/types/components/PageControl/PageControl.d.ts +52 -0
- package/dist/types/components/PageControl/index.d.ts +1 -0
- package/dist/types/components/Popover/Popover.d.ts +11 -6
- package/dist/types/components/Popover/deferredOutsidePress.d.ts +14 -0
- package/dist/types/components/Popover/usePopoverContext.d.ts +1 -0
- package/dist/types/components/Select/Select.d.ts +3 -3
- package/dist/types/components/SelectControl/SelectControl.d.ts +2 -2
- package/dist/types/components/SelectControl/index.d.ts +1 -1
- package/dist/types/components/Sortable/Sortable.d.ts +1 -1
- package/dist/types/components/Stepper/Stepper.d.ts +56 -0
- package/dist/types/components/Stepper/index.d.ts +1 -0
- package/dist/types/components/Switch/Switch.d.ts +3 -1
- package/dist/types/components/TabBar/TabBar.d.ts +74 -0
- package/dist/types/components/TabBar/index.d.ts +1 -0
- package/dist/types/components/Toast/ToastRenderer.d.ts +3 -0
- package/dist/types/components/Toast/Toaster.d.ts +4 -2
- package/dist/types/components/Toast/toastLifecycle.d.ts +90 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +93 -0
- package/dist/types/components/Toolbar/index.d.ts +1 -0
- package/dist/types/components/Tooltip/Tooltip.d.ts +2 -2
- package/dist/types/hooks/useFloatingBoundary.d.ts +24 -0
- package/dist/types/hooks/usePhoneSubmenu.d.ts +3 -0
- package/dist/types/lib/fieldRow.d.ts +6 -0
- package/dist/types/lib/floatingBoundary.d.ts +9 -0
- package/dist/types/lib/focusRestore.d.ts +5 -0
- package/dist/types/lib/helpers.d.ts +1 -5
- package/dist/types/lib/inputMode.d.ts +7 -0
- package/dist/types/lib/menuInitialFocus.d.ts +9 -0
- package/dist/types/lib/menuSubmenuPlacement.d.ts +57 -0
- package/dist/types/lib/menuTriggerCover.d.ts +23 -0
- package/dist/types/lib/observeTextareaWidth.d.ts +2 -0
- package/dist/types/lib/scrollEdges.d.ts +16 -0
- package/dist/types/lib/selectPress.d.ts +23 -0
- package/dist/types/lib/sortable.d.ts +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { Slider as RadixSlider } from "radix-ui";
|
|
5
|
+
import { useId, useRef, useState, } from "react";
|
|
6
|
+
import s from "@plexui/styles/components/ColorPicker/ColorPicker.module.css";
|
|
7
|
+
import { useLatestValue } from "../../hooks/useLatestValue.js";
|
|
8
|
+
import { prefersReducedMotion } from "../../lib/helpers.js";
|
|
9
|
+
import { ContextMenu } from "../ContextMenu/index.js";
|
|
10
|
+
import { Plus, RemoveTrash } from "../Icon/index.js";
|
|
11
|
+
import { PageControl } from "../PageControl/index.js";
|
|
12
|
+
import { SegmentedControl } from "../SegmentedControl/index.js";
|
|
13
|
+
import { alphaPercent, channelTrack, COLOR_PICKER_CHANNELS, COLOR_PICKER_GRID_COLUMNS, COLOR_PICKER_MODES, COLOR_PICKER_SWATCHES_PER_PAGE, cssColor, formatColor, gridColor, gridIndex, gridMove, hexDigits, listMove, opacityTrack, parseColor, parseNumber, sameRgb, spectrumColor, spectrumPoint, swatchPageCount, } from "./shared.js";
|
|
14
|
+
const BLACK = { r: 0, g: 0, b: 0, a: 1 };
|
|
15
|
+
const GRID_CELLS = COLOR_PICKER_GRID_COLUMNS * 10;
|
|
16
|
+
const NAVIGATION_KEYS = ["ArrowRight", "ArrowLeft", "ArrowDown", "ArrowUp", "Home", "End"];
|
|
17
|
+
/** A slider on a colored track, after the kit's Opacity slider (515:47434): a 36px ring on a 40px capsule. */
|
|
18
|
+
function ColorSlider({ labelId, value, max, track, valueText, onChange }) {
|
|
19
|
+
return (_jsx("div", { className: s.Track, style: { "--color-picker-track": track }, children: _jsxs(RadixSlider.Root, { className: s.SliderRoot, min: 0, max: max, step: 1, value: [value], onValueChange: ([next]) => onChange(next), children: [_jsx(RadixSlider.Track, { className: s.SliderTrack }), _jsx(RadixSlider.Thumb, { className: s.Knob, "aria-labelledby": labelId, "aria-valuetext": valueText })] }) }));
|
|
20
|
+
}
|
|
21
|
+
/** The value beside a slider, after the kit's Percentage field (515:47438); typing a value and Enter or leaving it applies it. */
|
|
22
|
+
function ColorField({ value, label, labelledBy, inputMode, wide = false, onCommit }) {
|
|
23
|
+
const [draft, setDraft] = useState(null);
|
|
24
|
+
const commit = () => {
|
|
25
|
+
if (draft !== null)
|
|
26
|
+
onCommit(draft);
|
|
27
|
+
setDraft(null);
|
|
28
|
+
};
|
|
29
|
+
return (_jsx("input", { className: s.Field, "data-wide": wide ? "" : undefined, type: "text", inputMode: inputMode, autoComplete: "off", spellCheck: false, "aria-label": label, "aria-labelledby": labelledBy, value: draft ?? value, onFocus: (event) => {
|
|
30
|
+
setDraft(value);
|
|
31
|
+
event.currentTarget.select();
|
|
32
|
+
}, onChange: (event) => setDraft(event.currentTarget.value), onBlur: commit, onKeyDown: (event) => {
|
|
33
|
+
if (event.key !== "Enter")
|
|
34
|
+
return;
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
commit();
|
|
37
|
+
} }));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The system color picker of iOS 26 (kit Color Picker - iPhone 0:5275): Grid, Spectrum and Sliders, the Opacity
|
|
41
|
+
* slider, and the saved colors with Add. Show it inside a Popover or a Sheet, or use `ColorWell`, which does.
|
|
42
|
+
*/
|
|
43
|
+
export function ColorPicker({ id, value: valueProp, defaultValue, onChange, supportsAlpha = true, mode: modeProp, defaultMode = "grid", onModeChange, swatches: swatchesProp, defaultSwatches, onSwatchesChange, "aria-label": ariaLabel = "Colors", className, }) {
|
|
44
|
+
const uid = useId();
|
|
45
|
+
const [internalValue, setInternalValue] = useState(() => defaultValue ?? "#000000");
|
|
46
|
+
const value = valueProp ?? internalValue;
|
|
47
|
+
const color = parseColor(value) ?? BLACK;
|
|
48
|
+
const colorRef = useLatestValue(color);
|
|
49
|
+
const options = useLatestValue({ controlled: valueProp !== undefined, supportsAlpha, onChange });
|
|
50
|
+
const [internalMode, setInternalMode] = useState(defaultMode);
|
|
51
|
+
const mode = modeProp ?? internalMode;
|
|
52
|
+
const [internalSwatches, setInternalSwatches] = useState(() => defaultSwatches ?? []);
|
|
53
|
+
const swatches = swatchesProp ?? internalSwatches;
|
|
54
|
+
const commit = (next) => {
|
|
55
|
+
const formatted = formatColor(options.current.supportsAlpha ? next : { ...next, a: 1 });
|
|
56
|
+
// Only a color other than the one shown is reported; an owner that keeps its color hears every new choice.
|
|
57
|
+
if (formatted === formatColor(colorRef.current))
|
|
58
|
+
return;
|
|
59
|
+
// A controlled color changes only when the owner passes it back, as in Vue.
|
|
60
|
+
if (!options.current.controlled)
|
|
61
|
+
setInternalValue(formatted);
|
|
62
|
+
options.current.onChange?.(formatted);
|
|
63
|
+
};
|
|
64
|
+
const changeMode = (next) => {
|
|
65
|
+
if (modeProp === undefined)
|
|
66
|
+
setInternalMode(next);
|
|
67
|
+
onModeChange?.(next);
|
|
68
|
+
};
|
|
69
|
+
const changeSwatches = (next) => {
|
|
70
|
+
if (swatchesProp === undefined)
|
|
71
|
+
setInternalSwatches(next);
|
|
72
|
+
onSwatchesChange?.(next);
|
|
73
|
+
};
|
|
74
|
+
return (_jsxs("div", { id: id, role: "group", "aria-label": ariaLabel, className: clsx(s.ColorPicker, className), "data-mode": mode, children: [_jsx(SegmentedControl, { "aria-label": "Mode", value: mode, onChange: changeMode, block: true, className: s.Modes, children: COLOR_PICKER_MODES.map((option) => (_jsx(SegmentedControl.Option, { value: option.value, children: option.label }, option.value))) }), _jsxs("div", { className: s.Body, children: [mode === "grid" && _jsx(ColorGrid, { color: color, onSelect: commit }), mode === "spectrum" && _jsx(ColorSpectrum, { color: color, onSelect: commit }), mode === "sliders" && _jsx(ColorSliders, { uid: uid, color: color, onSelect: commit })] }), supportsAlpha && (_jsxs("div", { className: s.Opacity, children: [_jsx("span", { id: `${uid}-opacity`, className: s.Label, children: "Opacity" }), _jsxs("div", { className: s.Row, children: [_jsx(ColorSlider, { labelId: `${uid}-opacity`, value: alphaPercent(color.a), max: 100, track: opacityTrack(color), valueText: `${alphaPercent(color.a)}%`, onChange: (percent) => commit({ ...colorRef.current, a: percent / 100 }) }), _jsx(ColorField, { value: `${alphaPercent(color.a)}%`, labelledBy: `${uid}-opacity`, inputMode: "numeric", onCommit: (text) => {
|
|
75
|
+
const percent = parseNumber(text, 0, 100);
|
|
76
|
+
if (percent !== null)
|
|
77
|
+
commit({ ...colorRef.current, a: percent / 100 });
|
|
78
|
+
} })] })] })), _jsx(ColorSwatches, { color: color, swatches: swatches, onSelect: commit, onChange: changeSwatches })] }));
|
|
79
|
+
}
|
|
80
|
+
/** The kit's Color Grid: twelve hues across, grays then nine shades down; the selected cell has a 3px white ring. */
|
|
81
|
+
function ColorGrid({ color, onSelect }) {
|
|
82
|
+
const selected = gridIndex(color);
|
|
83
|
+
const focusable = selected === -1 ? 0 : selected;
|
|
84
|
+
const onKeyDown = (event) => {
|
|
85
|
+
const from = Number(event.target.dataset.index);
|
|
86
|
+
if (!Number.isInteger(from) || !NAVIGATION_KEYS.includes(event.key))
|
|
87
|
+
return;
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
const next = gridMove(from, event.key);
|
|
90
|
+
if (next === from)
|
|
91
|
+
return;
|
|
92
|
+
const cell = event.currentTarget.querySelector(`[data-index="${next}"]`);
|
|
93
|
+
cell?.focus();
|
|
94
|
+
onSelect({ ...(parseColor(gridColor(next)) ?? BLACK), a: color.a });
|
|
95
|
+
};
|
|
96
|
+
return (_jsx("div", { role: "radiogroup", "aria-label": "Grid", className: s.Grid, onKeyDown: onKeyDown, children: Array.from({ length: GRID_CELLS }, (_, index) => {
|
|
97
|
+
const hex = gridColor(index);
|
|
98
|
+
return (_jsx("button", { type: "button", role: "radio", "aria-checked": index === selected, "aria-label": hex.toUpperCase(), tabIndex: index === focusable ? 0 : -1, "data-index": index, className: s.Cell, style: { backgroundColor: hex }, onClick: () => onSelect({ ...(parseColor(hex) ?? BLACK), a: color.a }) }, hex));
|
|
99
|
+
}) }));
|
|
100
|
+
}
|
|
101
|
+
const SPECTRUM_STEP = 0.01;
|
|
102
|
+
/**
|
|
103
|
+
* The spectrum: hue from top to bottom, white to the full hue to black across. Up and Down change the hue, Left
|
|
104
|
+
* and Right the lightness, by 1% (10% with Shift or Page Up and Page Down).
|
|
105
|
+
*/
|
|
106
|
+
function ColorSpectrum({ color, onSelect }) {
|
|
107
|
+
const [held, setHeld] = useState(() => ({ point: spectrumPoint(color), digits: hexDigits(color) }));
|
|
108
|
+
// The point the picker last chose stays while the color is the one it chose: a hex color loses the exact point,
|
|
109
|
+
// and a gray or white has no hue of its own.
|
|
110
|
+
const point = held.digits === hexDigits(color) ? held.point : spectrumPoint(color, held.point);
|
|
111
|
+
const choose = (next) => {
|
|
112
|
+
const clamped = { x: Math.min(1, Math.max(0, next.x)), y: Math.min(1, Math.max(0, next.y)) };
|
|
113
|
+
const chosen = spectrumColor(clamped, color.a);
|
|
114
|
+
setHeld({ point: clamped, digits: hexDigits(chosen) });
|
|
115
|
+
onSelect(chosen);
|
|
116
|
+
};
|
|
117
|
+
const fromPointer = (event) => {
|
|
118
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
119
|
+
if (box.width === 0 || box.height === 0)
|
|
120
|
+
return;
|
|
121
|
+
choose({ x: (event.clientX - box.left) / box.width, y: (event.clientY - box.top) / box.height });
|
|
122
|
+
};
|
|
123
|
+
const onKeyDown = (event) => {
|
|
124
|
+
const step = event.shiftKey ? SPECTRUM_STEP * 10 : SPECTRUM_STEP;
|
|
125
|
+
const moves = {
|
|
126
|
+
ArrowLeft: { x: point.x - step, y: point.y },
|
|
127
|
+
ArrowRight: { x: point.x + step, y: point.y },
|
|
128
|
+
ArrowUp: { x: point.x, y: point.y - step },
|
|
129
|
+
ArrowDown: { x: point.x, y: point.y + step },
|
|
130
|
+
PageUp: { x: point.x, y: point.y - SPECTRUM_STEP * 10 },
|
|
131
|
+
PageDown: { x: point.x, y: point.y + SPECTRUM_STEP * 10 },
|
|
132
|
+
};
|
|
133
|
+
const next = moves[event.key];
|
|
134
|
+
if (!next)
|
|
135
|
+
return;
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
choose(next);
|
|
138
|
+
};
|
|
139
|
+
const hue = Math.round(point.y * 360);
|
|
140
|
+
return (_jsx("div", { role: "slider", tabIndex: 0, "aria-label": "Spectrum", "aria-valuemin": 0, "aria-valuemax": 360, "aria-valuenow": hue, "aria-valuetext": `#${hexDigits(color)}, hue ${hue}°, lightness ${Math.round((1 - point.x) * 100)}%`, className: s.Spectrum, onPointerDown: (event) => {
|
|
141
|
+
if (event.button !== 0)
|
|
142
|
+
return;
|
|
143
|
+
event.currentTarget.setPointerCapture?.(event.pointerId);
|
|
144
|
+
event.currentTarget.focus({ preventScroll: true });
|
|
145
|
+
fromPointer(event);
|
|
146
|
+
}, onPointerMove: (event) => {
|
|
147
|
+
if (event.currentTarget.hasPointerCapture?.(event.pointerId))
|
|
148
|
+
fromPointer(event);
|
|
149
|
+
}, onKeyDown: onKeyDown, children: _jsx("span", { className: s.Loupe, style: { left: `${point.x * 100}%`, top: `${point.y * 100}%`, backgroundColor: cssColor(color, 1) } }) }));
|
|
150
|
+
}
|
|
151
|
+
/** Red, Green and Blue, each a slider and a field from 0 to 255, then the Hex field. */
|
|
152
|
+
function ColorSliders({ uid, color, onSelect }) {
|
|
153
|
+
return (_jsxs("div", { className: s.Sliders, children: [COLOR_PICKER_CHANNELS.map(({ channel, label }) => {
|
|
154
|
+
const labelId = `${uid}-${channel}`;
|
|
155
|
+
return (_jsxs("div", { className: s.Channel, children: [_jsx("span", { id: labelId, className: s.Label, children: label }), _jsxs("div", { className: s.Row, children: [_jsx(ColorSlider, { labelId: labelId, value: color[channel], max: 255, track: channelTrack(color, channel), valueText: String(color[channel]), onChange: (next) => onSelect({ ...color, [channel]: next }) }), _jsx(ColorField, { value: String(color[channel]), labelledBy: labelId, inputMode: "numeric", onCommit: (text) => {
|
|
156
|
+
const next = parseNumber(text, 0, 255);
|
|
157
|
+
if (next !== null)
|
|
158
|
+
onSelect({ ...color, [channel]: next });
|
|
159
|
+
} })] })] }, channel));
|
|
160
|
+
}), _jsxs("div", { className: s.Hex, children: [_jsx("span", { id: `${uid}-hex`, className: s.Label, children: "Hex Color #" }), _jsx(ColorField, { value: hexDigits(color), labelledBy: `${uid}-hex`, inputMode: "text", wide: true, onCommit: (text) => {
|
|
161
|
+
const next = parseColor(text);
|
|
162
|
+
if (next)
|
|
163
|
+
onSelect({ ...next, a: color.a });
|
|
164
|
+
} })] })] }));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The current color, and the saved colors in pages of two rows of five with Add after the last (kit Swatches
|
|
168
|
+
* 515:46585). A saved color is a radio; Delete or Backspace, or Delete in its context menu, removes it.
|
|
169
|
+
*/
|
|
170
|
+
function ColorSwatches({ color, swatches, onSelect, onChange }) {
|
|
171
|
+
const pagesRef = useRef(null);
|
|
172
|
+
const [page, setPage] = useState(0);
|
|
173
|
+
const saved = swatches.map((hex) => parseColor(hex) ?? BLACK);
|
|
174
|
+
const current = formatColor(color);
|
|
175
|
+
const checked = saved.findIndex((swatch) => sameRgb(swatch, color) && alphaPercent(swatch.a) === alphaPercent(color.a));
|
|
176
|
+
const focusable = checked === -1 ? 0 : checked;
|
|
177
|
+
const pageCount = swatchPageCount(swatches.length);
|
|
178
|
+
const reveal = (element) => element?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
179
|
+
const remove = (index, pages) => {
|
|
180
|
+
onChange(swatches.filter((_, i) => i !== index));
|
|
181
|
+
// Focus stays in the list: on the color that takes the place, the one before at the end, or Add.
|
|
182
|
+
const target = Math.min(index, swatches.length - 2);
|
|
183
|
+
requestAnimationFrame(() => {
|
|
184
|
+
const next = target >= 0 ? pages?.querySelector(`[data-swatch="${target}"]`) : pages?.querySelector("[data-add]");
|
|
185
|
+
next?.focus();
|
|
186
|
+
reveal(next);
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const onKeyDown = (event) => {
|
|
190
|
+
const from = Number(event.target.dataset.swatch);
|
|
191
|
+
if (!Number.isInteger(from))
|
|
192
|
+
return;
|
|
193
|
+
if (event.key === "Delete" || event.key === "Backspace") {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
remove(from, event.currentTarget);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!NAVIGATION_KEYS.includes(event.key))
|
|
199
|
+
return;
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
const next = listMove(from, swatches.length, event.key);
|
|
202
|
+
if (next === from)
|
|
203
|
+
return;
|
|
204
|
+
const element = event.currentTarget.querySelector(`[data-swatch="${next}"]`);
|
|
205
|
+
element?.focus();
|
|
206
|
+
reveal(element);
|
|
207
|
+
onSelect(saved[next]);
|
|
208
|
+
};
|
|
209
|
+
const items = [...swatches.map((hex, index) => ({ hex, index })), null];
|
|
210
|
+
const pages = Array.from({ length: pageCount }, (_, p) => items.slice(p * COLOR_PICKER_SWATCHES_PER_PAGE, (p + 1) * COLOR_PICKER_SWATCHES_PER_PAGE));
|
|
211
|
+
return (_jsxs("div", { className: s.Swatches, children: [_jsx("div", { role: "img", "aria-label": `Selected color #${hexDigits(color)}${color.a < 1 ? `, ${alphaPercent(color.a)}% opacity` : ""}`, className: s.Current, children: _jsx("span", { className: s.CurrentFill, style: { backgroundColor: cssColor(color) } }) }), _jsxs("div", { className: s.Saved, children: [_jsx("div", { ref: pagesRef, role: "radiogroup", "aria-label": "Saved colors", className: s.Pages, onKeyDown: onKeyDown, onScroll: (event) => {
|
|
212
|
+
const { scrollLeft, clientWidth } = event.currentTarget;
|
|
213
|
+
if (clientWidth > 0)
|
|
214
|
+
setPage(Math.round(scrollLeft / clientWidth));
|
|
215
|
+
}, children: pages.map((pageItems, p) => (_jsx("div", { className: s.Page, children: pageItems.map((item) => item === null ? (_jsx("button", { type: "button", "data-add": "", className: s.Add, "aria-label": "Add color", onClick: (event) => {
|
|
216
|
+
onChange([...swatches, current]);
|
|
217
|
+
const add = event.currentTarget;
|
|
218
|
+
requestAnimationFrame(() => reveal(add));
|
|
219
|
+
}, children: _jsx(Plus, {}) }, "add")) : (_jsxs(ContextMenu, { children: [_jsx(ContextMenu.Trigger, { children: _jsx("button", { type: "button", role: "radio", "aria-checked": item.index === checked, "aria-label": `#${hexDigits(saved[item.index])}${saved[item.index].a < 1 ? `, ${alphaPercent(saved[item.index].a)}% opacity` : ""}`, tabIndex: item.index === focusable ? 0 : -1, "data-swatch": item.index, className: s.Swatch, onClick: () => onSelect(saved[item.index]), children: _jsx("span", { className: s.SwatchFill, style: { backgroundColor: cssColor(saved[item.index]) } }) }) }), _jsx(ContextMenu.Content, { children: _jsxs(ContextMenu.Item, { danger: true, onSelect: () => remove(item.index, pagesRef.current), children: [_jsx(RemoveTrash, { width: 20, height: 20 }), " Delete"] }) })] }, `${item.index}-${item.hex}`))) }, p))) }), _jsx("div", { className: s.PageControlRow, children: pageCount > 1 && (_jsx(PageControl, { count: pageCount, value: Math.min(page, pageCount - 1), "aria-label": "Saved color pages", onChange: (index) => {
|
|
220
|
+
const pagesElement = pagesRef.current;
|
|
221
|
+
if (!pagesElement)
|
|
222
|
+
return;
|
|
223
|
+
setPage(index);
|
|
224
|
+
pagesElement.scrollTo?.({ left: index * pagesElement.clientWidth, behavior: prefersReducedMotion() ? "auto" : "smooth" });
|
|
225
|
+
} })) })] })] }));
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=ColorPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorPicker.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/ColorPicker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,EACL,KAAK,EACL,MAAM,EACN,QAAQ,GAIT,MAAM,OAAO,CAAA;AACd,OAAO,CAAC,MAAM,8DAA8D,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,EACzB,kBAAkB,EAClB,8BAA8B,EAC9B,QAAQ,EACR,WAAW,EACX,SAAS,EACT,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,YAAY,EACZ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AQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAI,GACnF,GACW,EACtB,KAAC,WAAW,CAAC,OAAO,cAClB,MAAC,WAAW,CAAC,IAAI,IAAC,MAAM,QAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,aAC3E,KAAC,WAAW,IAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,GAAI,eACrB,GACC,KAnBN,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,CAoB/B,CACf,CAAC,IAtCM,CAAC,CAuCL,CACP,CAAC,GACE,EAEN,cAAK,SAAS,EAAE,CAAC,CAAC,cAAc,YAC7B,SAAS,GAAG,CAAC,IAAI,CAChB,KAAC,WAAW,IACV,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,GAAG,CAAC,CAAC,gBACzB,mBAAmB,EAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;gCAClB,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAA;gCACrC,IAAI,CAAC,YAAY;oCAAE,OAAM;gCACzB,OAAO,CAAC,KAAK,CAAC,CAAA;gCACd,YAAY,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,YAAY,CAAC,WAAW,EAAE,QAAQ,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;4BAC3H,CAAC,GACD,CACH,GACG,IACF,IACF,CACP,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { Slider as RadixSlider } from \"radix-ui\"\nimport {\n useId,\n useRef,\n useState,\n type CSSProperties,\n type KeyboardEvent,\n type PointerEvent,\n} from \"react\"\nimport s from \"@plexui/styles/components/ColorPicker/ColorPicker.module.css\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { prefersReducedMotion } from \"../../lib/helpers\"\nimport { ContextMenu } from \"../ContextMenu\"\nimport { Plus, RemoveTrash } from \"../Icon\"\nimport { PageControl } from \"../PageControl\"\nimport { SegmentedControl } from \"../SegmentedControl\"\nimport {\n alphaPercent,\n channelTrack,\n COLOR_PICKER_CHANNELS,\n COLOR_PICKER_GRID_COLUMNS,\n COLOR_PICKER_MODES,\n COLOR_PICKER_SWATCHES_PER_PAGE,\n cssColor,\n formatColor,\n gridColor,\n gridIndex,\n gridMove,\n hexDigits,\n listMove,\n opacityTrack,\n parseColor,\n parseNumber,\n sameRgb,\n spectrumColor,\n spectrumPoint,\n swatchPageCount,\n type ColorPickerMode,\n type Rgba,\n type SpectrumPoint,\n} from \"./shared\"\n\nconst BLACK: Rgba = { r: 0, g: 0, b: 0, a: 1 }\nconst GRID_CELLS = COLOR_PICKER_GRID_COLUMNS * 10\nconst NAVIGATION_KEYS = [\"ArrowRight\", \"ArrowLeft\", \"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"]\n\nexport type ColorPickerProps = {\n /** The `id` of the picker. */\n id?: string\n /** The controlled color, `#rrggbb` or `#rrggbbaa`. Use with `onChange`. */\n value?: string\n /** The color when it is initially rendered. Use when you do not need to control the color. @default \"#000000\" */\n defaultValue?: string\n /** Called with the next color: `#rrggbb`, or `#rrggbbaa` when it is not opaque. */\n onChange?: (value: string) => void\n /** Shows the Opacity slider, as `supportsAlpha` of the system picker. @default true */\n supportsAlpha?: boolean\n /** The controlled way to choose a color. Use with `onModeChange`. */\n mode?: ColorPickerMode\n /** The way to choose a color when the picker is initially rendered. @default \"grid\" */\n defaultMode?: ColorPickerMode\n /** Called when another of Grid, Spectrum and Sliders is chosen. */\n onModeChange?: (mode: ColorPickerMode) => void\n /** The controlled saved colors. Use with `onSwatchesChange`. */\n swatches?: string[]\n /** The saved colors when the picker is initially rendered. @default [] */\n defaultSwatches?: string[]\n /** Called with the saved colors after Add saves the current color or Delete removes one. */\n onSwatchesChange?: (swatches: string[]) => void\n /** Accessible name of the picker. @default \"Colors\" */\n \"aria-label\"?: string\n /** CSS classes applied to the picker */\n className?: string\n}\n\ntype ColorSliderProps = {\n labelId: string\n value: number\n max: number\n track: string\n valueText: string\n onChange: (value: number) => void\n}\n\n/** A slider on a colored track, after the kit's Opacity slider (515:47434): a 36px ring on a 40px capsule. */\nfunction ColorSlider({ labelId, value, max, track, valueText, onChange }: ColorSliderProps) {\n return (\n <div className={s.Track} style={{ \"--color-picker-track\": track } as CSSProperties}>\n <RadixSlider.Root className={s.SliderRoot} min={0} max={max} step={1} value={[value]} onValueChange={([next]) => onChange(next)}>\n <RadixSlider.Track className={s.SliderTrack} />\n <RadixSlider.Thumb className={s.Knob} aria-labelledby={labelId} aria-valuetext={valueText} />\n </RadixSlider.Root>\n </div>\n )\n}\n\ntype ColorFieldProps = {\n value: string\n label?: string\n labelledBy?: string\n inputMode: \"numeric\" | \"text\"\n wide?: boolean\n onCommit: (text: string) => void\n}\n\n/** The value beside a slider, after the kit's Percentage field (515:47438); typing a value and Enter or leaving it applies it. */\nfunction ColorField({ value, label, labelledBy, inputMode, wide = false, onCommit }: ColorFieldProps) {\n const [draft, setDraft] = useState<string | null>(null)\n const commit = () => {\n if (draft !== null) onCommit(draft)\n setDraft(null)\n }\n return (\n <input\n className={s.Field}\n data-wide={wide ? \"\" : undefined}\n type=\"text\"\n inputMode={inputMode}\n autoComplete=\"off\"\n spellCheck={false}\n aria-label={label}\n aria-labelledby={labelledBy}\n value={draft ?? value}\n onFocus={(event) => {\n setDraft(value)\n event.currentTarget.select()\n }}\n onChange={(event) => setDraft(event.currentTarget.value)}\n onBlur={commit}\n onKeyDown={(event) => {\n if (event.key !== \"Enter\") return\n event.preventDefault()\n commit()\n }}\n />\n )\n}\n\n/**\n * The system color picker of iOS 26 (kit Color Picker - iPhone 0:5275): Grid, Spectrum and Sliders, the Opacity\n * slider, and the saved colors with Add. Show it inside a Popover or a Sheet, or use `ColorWell`, which does.\n */\nexport function ColorPicker({\n id,\n value: valueProp,\n defaultValue,\n onChange,\n supportsAlpha = true,\n mode: modeProp,\n defaultMode = \"grid\",\n onModeChange,\n swatches: swatchesProp,\n defaultSwatches,\n onSwatchesChange,\n \"aria-label\": ariaLabel = \"Colors\",\n className,\n}: ColorPickerProps) {\n const uid = useId()\n const [internalValue, setInternalValue] = useState(() => defaultValue ?? \"#000000\")\n const value = valueProp ?? internalValue\n const color = parseColor(value) ?? BLACK\n const colorRef = useLatestValue(color)\n const options = useLatestValue({ controlled: valueProp !== undefined, supportsAlpha, onChange })\n\n const [internalMode, setInternalMode] = useState<ColorPickerMode>(defaultMode)\n const mode = modeProp ?? internalMode\n\n const [internalSwatches, setInternalSwatches] = useState(() => defaultSwatches ?? [])\n const swatches = swatchesProp ?? internalSwatches\n\n const commit = (next: Rgba) => {\n const formatted = formatColor(options.current.supportsAlpha ? next : { ...next, a: 1 })\n // Only a color other than the one shown is reported; an owner that keeps its color hears every new choice.\n if (formatted === formatColor(colorRef.current)) return\n // A controlled color changes only when the owner passes it back, as in Vue.\n if (!options.current.controlled) setInternalValue(formatted)\n options.current.onChange?.(formatted)\n }\n\n const changeMode = (next: ColorPickerMode) => {\n if (modeProp === undefined) setInternalMode(next)\n onModeChange?.(next)\n }\n\n const changeSwatches = (next: string[]) => {\n if (swatchesProp === undefined) setInternalSwatches(next)\n onSwatchesChange?.(next)\n }\n\n return (\n <div id={id} role=\"group\" aria-label={ariaLabel} className={clsx(s.ColorPicker, className)} data-mode={mode}>\n <SegmentedControl<ColorPickerMode> aria-label=\"Mode\" value={mode} onChange={changeMode} block className={s.Modes}>\n {COLOR_PICKER_MODES.map((option) => (\n <SegmentedControl.Option key={option.value} value={option.value}>{option.label}</SegmentedControl.Option>\n ))}\n </SegmentedControl>\n <div className={s.Body}>\n {mode === \"grid\" && <ColorGrid color={color} onSelect={commit} />}\n {mode === \"spectrum\" && <ColorSpectrum color={color} onSelect={commit} />}\n {mode === \"sliders\" && <ColorSliders uid={uid} color={color} onSelect={commit} />}\n </div>\n {supportsAlpha && (\n <div className={s.Opacity}>\n <span id={`${uid}-opacity`} className={s.Label}>Opacity</span>\n <div className={s.Row}>\n <ColorSlider\n labelId={`${uid}-opacity`}\n value={alphaPercent(color.a)}\n max={100}\n track={opacityTrack(color)}\n valueText={`${alphaPercent(color.a)}%`}\n onChange={(percent) => commit({ ...colorRef.current, a: percent / 100 })}\n />\n <ColorField\n value={`${alphaPercent(color.a)}%`}\n labelledBy={`${uid}-opacity`}\n inputMode=\"numeric\"\n onCommit={(text) => {\n const percent = parseNumber(text, 0, 100)\n if (percent !== null) commit({ ...colorRef.current, a: percent / 100 })\n }}\n />\n </div>\n </div>\n )}\n <ColorSwatches color={color} swatches={swatches} onSelect={commit} onChange={changeSwatches} />\n </div>\n )\n}\n\ntype PartProps = { color: Rgba; onSelect: (color: Rgba) => void }\n\n/** The kit's Color Grid: twelve hues across, grays then nine shades down; the selected cell has a 3px white ring. */\nfunction ColorGrid({ color, onSelect }: PartProps) {\n const selected = gridIndex(color)\n const focusable = selected === -1 ? 0 : selected\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const from = Number((event.target as HTMLElement).dataset.index)\n if (!Number.isInteger(from) || !NAVIGATION_KEYS.includes(event.key)) return\n event.preventDefault()\n const next = gridMove(from, event.key)\n if (next === from) return\n const cell = event.currentTarget.querySelector<HTMLElement>(`[data-index=\"${next}\"]`)\n cell?.focus()\n onSelect({ ...(parseColor(gridColor(next)) ?? BLACK), a: color.a })\n }\n\n return (\n <div role=\"radiogroup\" aria-label=\"Grid\" className={s.Grid} onKeyDown={onKeyDown}>\n {Array.from({ length: GRID_CELLS }, (_, index) => {\n const hex = gridColor(index)\n return (\n <button\n key={hex}\n type=\"button\"\n role=\"radio\"\n aria-checked={index === selected}\n aria-label={hex.toUpperCase()}\n tabIndex={index === focusable ? 0 : -1}\n data-index={index}\n className={s.Cell}\n style={{ backgroundColor: hex }}\n onClick={() => onSelect({ ...(parseColor(hex) ?? BLACK), a: color.a })}\n />\n )\n })}\n </div>\n )\n}\n\nconst SPECTRUM_STEP = 0.01\n\n/**\n * The spectrum: hue from top to bottom, white to the full hue to black across. Up and Down change the hue, Left\n * and Right the lightness, by 1% (10% with Shift or Page Up and Page Down).\n */\nfunction ColorSpectrum({ color, onSelect }: PartProps) {\n const [held, setHeld] = useState<{ point: SpectrumPoint; digits: string }>(() => ({ point: spectrumPoint(color), digits: hexDigits(color) }))\n // The point the picker last chose stays while the color is the one it chose: a hex color loses the exact point,\n // and a gray or white has no hue of its own.\n const point = held.digits === hexDigits(color) ? held.point : spectrumPoint(color, held.point)\n\n const choose = (next: SpectrumPoint) => {\n const clamped = { x: Math.min(1, Math.max(0, next.x)), y: Math.min(1, Math.max(0, next.y)) }\n const chosen = spectrumColor(clamped, color.a)\n setHeld({ point: clamped, digits: hexDigits(chosen) })\n onSelect(chosen)\n }\n\n const fromPointer = (event: PointerEvent<HTMLDivElement>) => {\n const box = event.currentTarget.getBoundingClientRect()\n if (box.width === 0 || box.height === 0) return\n choose({ x: (event.clientX - box.left) / box.width, y: (event.clientY - box.top) / box.height })\n }\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const step = event.shiftKey ? SPECTRUM_STEP * 10 : SPECTRUM_STEP\n const moves: Record<string, SpectrumPoint> = {\n ArrowLeft: { x: point.x - step, y: point.y },\n ArrowRight: { x: point.x + step, y: point.y },\n ArrowUp: { x: point.x, y: point.y - step },\n ArrowDown: { x: point.x, y: point.y + step },\n PageUp: { x: point.x, y: point.y - SPECTRUM_STEP * 10 },\n PageDown: { x: point.x, y: point.y + SPECTRUM_STEP * 10 },\n }\n const next = moves[event.key]\n if (!next) return\n event.preventDefault()\n choose(next)\n }\n\n const hue = Math.round(point.y * 360)\n return (\n <div\n role=\"slider\"\n tabIndex={0}\n aria-label=\"Spectrum\"\n aria-valuemin={0}\n aria-valuemax={360}\n aria-valuenow={hue}\n aria-valuetext={`#${hexDigits(color)}, hue ${hue}°, lightness ${Math.round((1 - point.x) * 100)}%`}\n className={s.Spectrum}\n onPointerDown={(event) => {\n if (event.button !== 0) return\n event.currentTarget.setPointerCapture?.(event.pointerId)\n event.currentTarget.focus({ preventScroll: true })\n fromPointer(event)\n }}\n onPointerMove={(event) => {\n if (event.currentTarget.hasPointerCapture?.(event.pointerId)) fromPointer(event)\n }}\n onKeyDown={onKeyDown}\n >\n <span\n className={s.Loupe}\n style={{ left: `${point.x * 100}%`, top: `${point.y * 100}%`, backgroundColor: cssColor(color, 1) }}\n />\n </div>\n )\n}\n\n/** Red, Green and Blue, each a slider and a field from 0 to 255, then the Hex field. */\nfunction ColorSliders({ uid, color, onSelect }: PartProps & { uid: string }) {\n return (\n <div className={s.Sliders}>\n {COLOR_PICKER_CHANNELS.map(({ channel, label }) => {\n const labelId = `${uid}-${channel}`\n return (\n <div key={channel} className={s.Channel}>\n <span id={labelId} className={s.Label}>{label}</span>\n <div className={s.Row}>\n <ColorSlider\n labelId={labelId}\n value={color[channel]}\n max={255}\n track={channelTrack(color, channel)}\n valueText={String(color[channel])}\n onChange={(next) => onSelect({ ...color, [channel]: next })}\n />\n <ColorField\n value={String(color[channel])}\n labelledBy={labelId}\n inputMode=\"numeric\"\n onCommit={(text) => {\n const next = parseNumber(text, 0, 255)\n if (next !== null) onSelect({ ...color, [channel]: next })\n }}\n />\n </div>\n </div>\n )\n })}\n <div className={s.Hex}>\n <span id={`${uid}-hex`} className={s.Label}>Hex Color #</span>\n <ColorField\n value={hexDigits(color)}\n labelledBy={`${uid}-hex`}\n inputMode=\"text\"\n wide\n onCommit={(text) => {\n const next = parseColor(text)\n if (next) onSelect({ ...next, a: color.a })\n }}\n />\n </div>\n </div>\n )\n}\n\ntype ColorSwatchesProps = PartProps & { swatches: string[]; onChange: (swatches: string[]) => void }\n\n/**\n * The current color, and the saved colors in pages of two rows of five with Add after the last (kit Swatches\n * 515:46585). A saved color is a radio; Delete or Backspace, or Delete in its context menu, removes it.\n */\nfunction ColorSwatches({ color, swatches, onSelect, onChange }: ColorSwatchesProps) {\n const pagesRef = useRef<HTMLDivElement>(null)\n const [page, setPage] = useState(0)\n const saved = swatches.map((hex) => parseColor(hex) ?? BLACK)\n const current = formatColor(color)\n const checked = saved.findIndex((swatch) => sameRgb(swatch, color) && alphaPercent(swatch.a) === alphaPercent(color.a))\n const focusable = checked === -1 ? 0 : checked\n const pageCount = swatchPageCount(swatches.length)\n\n const reveal = (element: HTMLElement | null | undefined) => element?.scrollIntoView?.({ block: \"nearest\", inline: \"nearest\" })\n\n const remove = (index: number, pages: HTMLElement | null) => {\n onChange(swatches.filter((_, i) => i !== index))\n // Focus stays in the list: on the color that takes the place, the one before at the end, or Add.\n const target = Math.min(index, swatches.length - 2)\n requestAnimationFrame(() => {\n const next = target >= 0 ? pages?.querySelector<HTMLElement>(`[data-swatch=\"${target}\"]`) : pages?.querySelector<HTMLElement>(\"[data-add]\")\n next?.focus()\n reveal(next)\n })\n }\n\n const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n const from = Number((event.target as HTMLElement).dataset.swatch)\n if (!Number.isInteger(from)) return\n if (event.key === \"Delete\" || event.key === \"Backspace\") {\n event.preventDefault()\n remove(from, event.currentTarget)\n return\n }\n if (!NAVIGATION_KEYS.includes(event.key)) return\n event.preventDefault()\n const next = listMove(from, swatches.length, event.key)\n if (next === from) return\n const element = event.currentTarget.querySelector<HTMLElement>(`[data-swatch=\"${next}\"]`)\n element?.focus()\n reveal(element)\n onSelect(saved[next])\n }\n\n const items = [...swatches.map((hex, index) => ({ hex, index })), null]\n const pages = Array.from({ length: pageCount }, (_, p) => items.slice(p * COLOR_PICKER_SWATCHES_PER_PAGE, (p + 1) * COLOR_PICKER_SWATCHES_PER_PAGE))\n\n return (\n <div className={s.Swatches}>\n <div role=\"img\" aria-label={`Selected color #${hexDigits(color)}${color.a < 1 ? `, ${alphaPercent(color.a)}% opacity` : \"\"}`} className={s.Current}>\n <span className={s.CurrentFill} style={{ backgroundColor: cssColor(color) }} />\n </div>\n <div className={s.Saved}>\n <div\n ref={pagesRef}\n role=\"radiogroup\"\n aria-label=\"Saved colors\"\n className={s.Pages}\n onKeyDown={onKeyDown}\n onScroll={(event) => {\n const { scrollLeft, clientWidth } = event.currentTarget\n if (clientWidth > 0) setPage(Math.round(scrollLeft / clientWidth))\n }}\n >\n {pages.map((pageItems, p) => (\n <div key={p} className={s.Page}>\n {pageItems.map((item) => item === null ? (\n <button\n key=\"add\"\n type=\"button\"\n data-add=\"\"\n className={s.Add}\n aria-label=\"Add color\"\n onClick={(event) => {\n onChange([...swatches, current])\n const add = event.currentTarget\n requestAnimationFrame(() => reveal(add))\n }}\n >\n <Plus />\n </button>\n ) : (\n <ContextMenu key={`${item.index}-${item.hex}`}>\n <ContextMenu.Trigger>\n <button\n type=\"button\"\n role=\"radio\"\n aria-checked={item.index === checked}\n aria-label={`#${hexDigits(saved[item.index])}${saved[item.index].a < 1 ? `, ${alphaPercent(saved[item.index].a)}% opacity` : \"\"}`}\n tabIndex={item.index === focusable ? 0 : -1}\n data-swatch={item.index}\n className={s.Swatch}\n onClick={() => onSelect(saved[item.index])}\n >\n <span className={s.SwatchFill} style={{ backgroundColor: cssColor(saved[item.index]) }} />\n </button>\n </ContextMenu.Trigger>\n <ContextMenu.Content>\n <ContextMenu.Item danger onSelect={() => remove(item.index, pagesRef.current)}>\n <RemoveTrash width={20} height={20} /> Delete\n </ContextMenu.Item>\n </ContextMenu.Content>\n </ContextMenu>\n ))}\n </div>\n ))}\n </div>\n {/* The row of the page control keeps its height with one page, so the picker does not change size. */}\n <div className={s.PageControlRow}>\n {pageCount > 1 && (\n <PageControl\n count={pageCount}\n value={Math.min(page, pageCount - 1)}\n aria-label=\"Saved color pages\"\n onChange={(index) => {\n const pagesElement = pagesRef.current\n if (!pagesElement) return\n setPage(index)\n pagesElement.scrollTo?.({ left: index * pagesElement.clientWidth, behavior: prefersReducedMotion() ? \"auto\" : \"smooth\" })\n }}\n />\n )}\n </div>\n </div>\n </div>\n )\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import s from "@plexui/styles/components/ColorPicker/ColorPicker.module.css";
|
|
6
|
+
import { useBreakpoint } from "../../hooks/useBreakpoints.js";
|
|
7
|
+
import { useLatestValue } from "../../hooks/useLatestValue.js";
|
|
8
|
+
import { Button, NavigationButton } from "../Button/index.js";
|
|
9
|
+
import { Dialog } from "../Dialog/index.js";
|
|
10
|
+
import { Eyedropper, X } from "../Icon/index.js";
|
|
11
|
+
import { Popover } from "../Popover/index.js";
|
|
12
|
+
import { Toolbar } from "../Toolbar/index.js";
|
|
13
|
+
import { ColorPicker } from "./ColorPicker.js";
|
|
14
|
+
import { alphaPercent, cssColor, eyeDropper, formatColor, hexDigits, parseColor } from "./shared.js";
|
|
15
|
+
/**
|
|
16
|
+
* A color well, as `UIColorWell`: the kit's Picker Button (5739:34128), a rainbow ring around the chosen color. It
|
|
17
|
+
* opens the color picker, in a Popover from the well, and on a phone in a sheet, as the system picker.
|
|
18
|
+
*/
|
|
19
|
+
export function ColorWell({ id, value: valueProp, defaultValue = null, onChange, title = "Colors", supportsEyedropper = true, size = "sm", disabled = false, name, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, className, ...pickerProps }) {
|
|
20
|
+
const wide = useBreakpoint("md");
|
|
21
|
+
const valueId = `${useId()}-value`;
|
|
22
|
+
const [open, setOpen] = useState(false);
|
|
23
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
24
|
+
const value = valueProp === undefined ? internalValue : valueProp;
|
|
25
|
+
const color = parseColor(value);
|
|
26
|
+
const options = useLatestValue({ controlled: valueProp !== undefined, onChange });
|
|
27
|
+
// The EyeDropper API exists only in a browser, so the button appears after hydration.
|
|
28
|
+
const [canPick, setCanPick] = useState(false);
|
|
29
|
+
useEffect(() => setCanPick(eyeDropper() !== null), []);
|
|
30
|
+
const picking = useRef(false);
|
|
31
|
+
const choose = (next) => {
|
|
32
|
+
if (!options.current.controlled)
|
|
33
|
+
setInternalValue(next);
|
|
34
|
+
options.current.onChange?.(next);
|
|
35
|
+
};
|
|
36
|
+
const pick = async () => {
|
|
37
|
+
const EyeDropper = eyeDropper();
|
|
38
|
+
if (!EyeDropper || picking.current)
|
|
39
|
+
return;
|
|
40
|
+
picking.current = true;
|
|
41
|
+
try {
|
|
42
|
+
const picked = parseColor((await new EyeDropper().open()).sRGBHex);
|
|
43
|
+
if (picked)
|
|
44
|
+
choose(formatColor({ ...picked, a: color?.a ?? 1 }));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Escape, or a click the browser did not hand to the page, cancels the pick.
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
picking.current = false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const well = (_jsxs("button", { id: id, type: "button", className: clsx(s.Well, className), "data-size": size, "data-selected": color ? "" : undefined, disabled: disabled, "aria-label": ariaLabelledBy ? undefined : ariaLabel ?? "Color", "aria-labelledby": ariaLabelledBy, "aria-describedby": color ? valueId : undefined, style: color ? { "--color-well-color": cssColor(color) } : undefined, children: [color && _jsx("span", { className: s.WellColor }), color && _jsx("span", { id: valueId, hidden: true, children: `#${hexDigits(color)}${color.a < 1 ? `, ${alphaPercent(color.a)}% opacity` : ""}` })] }));
|
|
54
|
+
const picker = (_jsx(ColorPicker, { ...pickerProps, value: formatColor(color ?? { r: 0, g: 0, b: 0, a: 1 }), onChange: choose, "aria-label": title }));
|
|
55
|
+
const eyedropperButton = (glass) => supportsEyedropper && canPick && (_jsx(Button, { color: "secondary", variant: glass ? "soft" : "ghost", mobileMaterial: glass ? "glass" : undefined, size: glass ? "lg" : "sm", uniform: true, pill: true, "aria-label": "Eyedropper", onClick: () => void pick(), children: _jsx(Eyedropper, {}) }));
|
|
56
|
+
return (_jsxs(_Fragment, { children: [name !== undefined && _jsx("input", { type: "hidden", name: name, value: value ?? "", disabled: disabled }), wide ? (_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(Popover.Trigger, { children: well }), _jsxs(Popover.Content, { className: s.Popover, width: "auto", side: "bottom", align: "center", children: [_jsxs("div", { className: s.PopoverHeader, children: [_jsx("div", { className: s.PopoverLeading, children: eyedropperButton(false) }), _jsx("span", { className: s.PopoverTitle, children: title }), _jsx("div", { className: s.PopoverTrailing, children: _jsx(Button, { color: "secondary", variant: "ghost", size: "sm", uniform: true, pill: true, "aria-label": "Close", onClick: () => setOpen(false), children: _jsx(X, {}) }) })] }), picker] })] })) : (_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(Dialog.Trigger, { children: well }), _jsxs(Dialog.Content, { mobileVariant: "sheet", showClose: false, className: s.Sheet, children: [_jsxs(Toolbar, { background: "solid", children: [_jsx(Toolbar.Leading, { children: eyedropperButton(true) }), _jsx(Toolbar.Title, { children: title }), _jsx(Toolbar.Trailing, { children: _jsx(Dialog.Close, { children: _jsx(NavigationButton, { action: "close" }) }) })] }), _jsx(Dialog.Header, { children: _jsx(Dialog.Title, { children: title }) }), _jsx(Dialog.Body, { className: s.SheetBody, children: picker })] })] }))] }));
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ColorWell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorWell.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/ColorWell.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAsC,MAAM,OAAO,CAAA;AAC9F,OAAO,CAAC,MAAM,8DAA8D,C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CAAC,CAAC,CAAC,CACF,MAAC,MAAM,IAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,aACvC,KAAC,MAAM,CAAC,OAAO,cAAE,IAAI,GAAkB,EACvC,MAAC,MAAM,CAAC,OAAO,IAAC,aAAa,EAAC,OAAO,EAAC,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,KAAK,aACxE,MAAC,OAAO,IAAC,UAAU,EAAC,OAAO,aACzB,KAAC,OAAO,CAAC,OAAO,cAAE,gBAAgB,CAAC,IAAI,CAAC,GAAmB,EAC3D,KAAC,OAAO,CAAC,KAAK,cAAE,KAAK,GAAiB,EACtC,KAAC,OAAO,CAAC,QAAQ,cACf,KAAC,MAAM,CAAC,KAAK,cACX,KAAC,gBAAgB,IAAC,MAAM,EAAC,OAAO,GAAG,GACtB,GACE,IACX,EACV,KAAC,MAAM,CAAC,MAAM,cACZ,KAAC,MAAM,CAAC,KAAK,cAAE,KAAK,GAAgB,GACtB,EAChB,KAAC,MAAM,CAAC,IAAI,IAAC,SAAS,EAAE,CAAC,CAAC,SAAS,YAAG,MAAM,GAAe,IAC5C,IACV,CACV,IACA,CACJ,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { useEffect, useId, useRef, useState, type CSSProperties, type ReactNode } from \"react\"\nimport s from \"@plexui/styles/components/ColorPicker/ColorPicker.module.css\"\nimport { useBreakpoint } from \"../../hooks/useBreakpoints\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { Button, NavigationButton } from \"../Button\"\nimport { Dialog } from \"../Dialog\"\nimport { Eyedropper, X } from \"../Icon\"\nimport { Popover } from \"../Popover\"\nimport { Toolbar } from \"../Toolbar\"\nimport { ColorPicker, type ColorPickerProps } from \"./ColorPicker\"\nimport { alphaPercent, cssColor, eyeDropper, formatColor, hexDigits, parseColor } from \"./shared\"\n\nexport type ColorWellProps = Omit<ColorPickerProps, \"value\" | \"defaultValue\" | \"onChange\" | \"aria-label\" | \"className\" | \"id\"> & {\n /** The `id` of the well. */\n id?: string\n /** The controlled color, `#rrggbb` or `#rrggbbaa`; `null` shows the rainbow well with no color. Use with `onChange`. */\n value?: string | null\n /** The color when it is initially rendered. Use when you do not need to control the color. @default null */\n defaultValue?: string | null\n /** Called with the color the picker chose. */\n onChange?: (value: string) => void\n /** The title of the picker. @default \"Colors\" */\n title?: string\n /** Shows the eyedropper in the picker where the browser can pick a color from the screen (EyeDropper API). @default true */\n supportsEyedropper?: boolean\n /** The kit's Picker Button sizes: `sm` 28px, `lg` 36px. @default \"sm\" */\n size?: \"sm\" | \"lg\"\n /** When `true`, prevents the user from opening the picker. */\n disabled?: boolean\n /** The name of the well. Submits its color with the owning form. */\n name?: string\n /** Accessible name of the well. @default \"Color\" */\n \"aria-label\"?: string\n /** The `id` of the visible label of the well. */\n \"aria-labelledby\"?: string\n /** CSS classes applied to the well */\n className?: string\n}\n\n/**\n * A color well, as `UIColorWell`: the kit's Picker Button (5739:34128), a rainbow ring around the chosen color. It\n * opens the color picker, in a Popover from the well, and on a phone in a sheet, as the system picker.\n */\nexport function ColorWell({\n id,\n value: valueProp,\n defaultValue = null,\n onChange,\n title = \"Colors\",\n supportsEyedropper = true,\n size = \"sm\",\n disabled = false,\n name,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n className,\n ...pickerProps\n}: ColorWellProps) {\n const wide = useBreakpoint(\"md\")\n const valueId = `${useId()}-value`\n const [open, setOpen] = useState(false)\n const [internalValue, setInternalValue] = useState<string | null>(defaultValue)\n const value = valueProp === undefined ? internalValue : valueProp\n const color = parseColor(value)\n const options = useLatestValue({ controlled: valueProp !== undefined, onChange })\n // The EyeDropper API exists only in a browser, so the button appears after hydration.\n const [canPick, setCanPick] = useState(false)\n useEffect(() => setCanPick(eyeDropper() !== null), [])\n const picking = useRef(false)\n\n const choose = (next: string) => {\n if (!options.current.controlled) setInternalValue(next)\n options.current.onChange?.(next)\n }\n\n const pick = async () => {\n const EyeDropper = eyeDropper()\n if (!EyeDropper || picking.current) return\n picking.current = true\n try {\n const picked = parseColor((await new EyeDropper().open()).sRGBHex)\n if (picked) choose(formatColor({ ...picked, a: color?.a ?? 1 }))\n } catch {\n // Escape, or a click the browser did not hand to the page, cancels the pick.\n } finally {\n picking.current = false\n }\n }\n\n const well = (\n <button\n id={id}\n type=\"button\"\n className={clsx(s.Well, className)}\n data-size={size}\n data-selected={color ? \"\" : undefined}\n disabled={disabled}\n aria-label={ariaLabelledBy ? undefined : ariaLabel ?? \"Color\"}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={color ? valueId : undefined}\n style={color ? { \"--color-well-color\": cssColor(color) } as CSSProperties : undefined}\n >\n {color && <span className={s.WellColor} />}\n {/* The color, read as the well's description. */}\n {color && <span id={valueId} hidden>{`#${hexDigits(color)}${color.a < 1 ? `, ${alphaPercent(color.a)}% opacity` : \"\"}`}</span>}\n </button>\n )\n\n const picker = (\n <ColorPicker {...pickerProps} value={formatColor(color ?? { r: 0, g: 0, b: 0, a: 1 })} onChange={choose} aria-label={title} />\n )\n const eyedropperButton = (glass: boolean): ReactNode => supportsEyedropper && canPick && (\n <Button\n color=\"secondary\"\n variant={glass ? \"soft\" : \"ghost\"}\n mobileMaterial={glass ? \"glass\" : undefined}\n size={glass ? \"lg\" : \"sm\"}\n uniform\n pill\n aria-label=\"Eyedropper\"\n onClick={() => void pick()}\n >\n <Eyedropper />\n </Button>\n )\n\n return (\n <>\n {name !== undefined && <input type=\"hidden\" name={name} value={value ?? \"\"} disabled={disabled} />}\n {wide ? (\n <Popover open={open} onOpenChange={setOpen}>\n <Popover.Trigger>{well}</Popover.Trigger>\n <Popover.Content className={s.Popover} width=\"auto\" side=\"bottom\" align=\"center\">\n <div className={s.PopoverHeader}>\n <div className={s.PopoverLeading}>{eyedropperButton(false)}</div>\n <span className={s.PopoverTitle}>{title}</span>\n <div className={s.PopoverTrailing}>\n <Button color=\"secondary\" variant=\"ghost\" size=\"sm\" uniform pill aria-label=\"Close\" onClick={() => setOpen(false)}>\n <X />\n </Button>\n </div>\n </div>\n {picker}\n </Popover.Content>\n </Popover>\n ) : (\n <Dialog open={open} onOpenChange={setOpen}>\n <Dialog.Trigger>{well}</Dialog.Trigger>\n <Dialog.Content mobileVariant=\"sheet\" showClose={false} className={s.Sheet}>\n <Toolbar background=\"solid\">\n <Toolbar.Leading>{eyedropperButton(true)}</Toolbar.Leading>\n <Toolbar.Title>{title}</Toolbar.Title>\n <Toolbar.Trailing>\n <Dialog.Close>\n <NavigationButton action=\"close\" />\n </Dialog.Close>\n </Toolbar.Trailing>\n </Toolbar>\n <Dialog.Header>\n <Dialog.Title>{title}</Dialog.Title>\n </Dialog.Header>\n <Dialog.Body className={s.SheetBody}>{picker}</Dialog.Body>\n </Dialog.Content>\n </Dialog>\n )}\n </>\n )\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,SAAS,EAAuB,MAAM,aAAa,CAAA","sourcesContent":["export { ColorPicker, type ColorPickerProps } from \"./ColorPicker\"\nexport { ColorWell, type ColorWellProps } from \"./ColorWell\"\nexport type { ColorPickerMode } from \"./shared\"\n"]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export const COLOR_PICKER_MODES = [
|
|
2
|
+
{ value: "grid", label: "Grid" },
|
|
3
|
+
{ value: "spectrum", label: "Spectrum" },
|
|
4
|
+
{ value: "sliders", label: "Sliders" },
|
|
5
|
+
];
|
|
6
|
+
/** The kit's Color Grid (515:48178): a row of grays, then nine rows from dark to light, twelve hues across. */
|
|
7
|
+
export const COLOR_PICKER_GRID = [
|
|
8
|
+
["#fefffe", "#ebebeb", "#d6d6d6", "#c2c2c2", "#adadad", "#999999", "#858585", "#707070", "#5c5c5c", "#474747", "#333333", "#000000"],
|
|
9
|
+
["#00374a", "#011d57", "#11053b", "#2e063d", "#3c071b", "#5c0701", "#5a1c00", "#583300", "#563d00", "#666100", "#4f5504", "#263e0f"],
|
|
10
|
+
["#004d65", "#012f7b", "#1a0a52", "#450d59", "#551029", "#831100", "#7b2900", "#7a4a00", "#785800", "#8d8602", "#6f760a", "#38571a"],
|
|
11
|
+
["#016e8f", "#0042a9", "#2c0977", "#61187c", "#791a3d", "#b51a00", "#ad3e00", "#a96800", "#a67b01", "#c4bc00", "#9ba50e", "#4e7a27"],
|
|
12
|
+
["#008cb4", "#0056d6", "#371a94", "#7a219e", "#99244f", "#e22400", "#da5100", "#d38301", "#d19d01", "#f5ec00", "#c3d117", "#669d34"],
|
|
13
|
+
["#00a1d8", "#0061fd", "#4d22b2", "#982abc", "#b92d5d", "#ff4015", "#ff6a00", "#ffab01", "#fcc700", "#fefb41", "#d9ec37", "#76bb40"],
|
|
14
|
+
["#01c7fc", "#3a87fd", "#5e30eb", "#be38f3", "#e63b7a", "#fe6250", "#fe8648", "#feb43f", "#fecb3e", "#fff76b", "#e4ef65", "#96d35f"],
|
|
15
|
+
["#52d6fc", "#74a7ff", "#864ffd", "#d357fe", "#ee719e", "#ff8c82", "#fea57d", "#fec777", "#fed977", "#fff994", "#eaf28f", "#b1dd8b"],
|
|
16
|
+
["#93e3fc", "#a7c6ff", "#b18cfe", "#e292fe", "#f4a4c0", "#ffb5af", "#ffc5ab", "#fed9a8", "#fde4a8", "#fffbb9", "#f1f7b7", "#cde8b5"],
|
|
17
|
+
["#cbf0ff", "#d2e2fe", "#d8c9fe", "#efcafe", "#f9d3e0", "#ffdad8", "#ffe2d6", "#feecd4", "#fef1d5", "#fdfbdd", "#f6fadb", "#deeed4"],
|
|
18
|
+
];
|
|
19
|
+
export const COLOR_PICKER_GRID_COLUMNS = 12;
|
|
20
|
+
const GRID = COLOR_PICKER_GRID.flat();
|
|
21
|
+
/** Saved colors fill pages of two rows of five, with the Add button after the last one (kit Swatches 515:52724). */
|
|
22
|
+
export const COLOR_PICKER_SWATCHES_PER_PAGE = 10;
|
|
23
|
+
export const COLOR_PICKER_SWATCHES_PER_ROW = 5;
|
|
24
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
25
|
+
const byte = (value) => clamp(Math.round(value), 0, 255);
|
|
26
|
+
/** Reads `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, in either case; anything else is `null`. */
|
|
27
|
+
export function parseColor(input) {
|
|
28
|
+
const match = /^#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec((input ?? "").trim());
|
|
29
|
+
if (!match)
|
|
30
|
+
return null;
|
|
31
|
+
let hex = match[1];
|
|
32
|
+
if (hex.length <= 4)
|
|
33
|
+
hex = [...hex].map((digit) => digit + digit).join("");
|
|
34
|
+
const channel = (index) => Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
35
|
+
return { r: channel(0), g: channel(1), b: channel(2), a: hex.length === 8 ? channel(3) / 255 : 1 };
|
|
36
|
+
}
|
|
37
|
+
const two = (value) => byte(value).toString(16).padStart(2, "0");
|
|
38
|
+
/** `#rrggbb`, or `#rrggbbaa` when the color is not opaque. */
|
|
39
|
+
export function formatColor({ r, g, b, a }) {
|
|
40
|
+
const opaque = Math.round(clamp(a, 0, 1) * 255) === 255;
|
|
41
|
+
return `#${two(r)}${two(g)}${two(b)}${opaque ? "" : two(clamp(a, 0, 1) * 255)}`;
|
|
42
|
+
}
|
|
43
|
+
/** The six digits the Hex field shows, as the system picker does: upper case, no `#`. */
|
|
44
|
+
export const hexDigits = ({ r, g, b }) => `${two(r)}${two(g)}${two(b)}`.toUpperCase();
|
|
45
|
+
/** A CSS color for a fill. */
|
|
46
|
+
export const cssColor = ({ r, g, b, a }, alpha = a) => `rgb(${byte(r)} ${byte(g)} ${byte(b)} / ${Math.round(clamp(alpha, 0, 1) * 1000) / 10}%)`;
|
|
47
|
+
export const sameRgb = (one, other) => byte(one.r) === byte(other.r) && byte(one.g) === byte(other.g) && byte(one.b) === byte(other.b);
|
|
48
|
+
/** Whole percent of opacity, as the Opacity field shows it. */
|
|
49
|
+
export const alphaPercent = (a) => Math.round(clamp(a, 0, 1) * 100);
|
|
50
|
+
/** The grid cell of a color, or -1 when the grid has no such color. */
|
|
51
|
+
export const gridIndex = (color) => GRID.findIndex((hex) => {
|
|
52
|
+
const cell = parseColor(hex);
|
|
53
|
+
return cell !== null && sameRgb(cell, color);
|
|
54
|
+
});
|
|
55
|
+
export const gridColor = (index) => GRID[index];
|
|
56
|
+
/** The cell an arrow key, Home or End moves to from `index`, or `index` itself at an edge. */
|
|
57
|
+
export function gridMove(index, key) {
|
|
58
|
+
const columns = COLOR_PICKER_GRID_COLUMNS;
|
|
59
|
+
const column = index % columns;
|
|
60
|
+
const next = {
|
|
61
|
+
ArrowRight: column < columns - 1 ? index + 1 : index,
|
|
62
|
+
ArrowLeft: column > 0 ? index - 1 : index,
|
|
63
|
+
ArrowDown: index + columns < GRID.length ? index + columns : index,
|
|
64
|
+
ArrowUp: index - columns >= 0 ? index - columns : index,
|
|
65
|
+
Home: index - column,
|
|
66
|
+
End: index - column + columns - 1,
|
|
67
|
+
};
|
|
68
|
+
return next[key] ?? index;
|
|
69
|
+
}
|
|
70
|
+
/** The item a key moves to in a list of `count` items (saved colors), or `index` itself. */
|
|
71
|
+
export function listMove(index, count, key) {
|
|
72
|
+
const next = {
|
|
73
|
+
ArrowRight: Math.min(count - 1, index + 1),
|
|
74
|
+
ArrowDown: Math.min(count - 1, index + 1),
|
|
75
|
+
ArrowLeft: Math.max(0, index - 1),
|
|
76
|
+
ArrowUp: Math.max(0, index - 1),
|
|
77
|
+
Home: 0,
|
|
78
|
+
End: count - 1,
|
|
79
|
+
};
|
|
80
|
+
return next[key] ?? index;
|
|
81
|
+
}
|
|
82
|
+
/** Pages of saved colors: the colors and the Add button after them, ten to a page. */
|
|
83
|
+
export const swatchPageCount = (count) => Math.max(1, Math.ceil((count + 1) / COLOR_PICKER_SWATCHES_PER_PAGE));
|
|
84
|
+
function rgbToHsl({ r, g, b }) {
|
|
85
|
+
const [red, green, blue] = [r / 255, g / 255, b / 255];
|
|
86
|
+
const max = Math.max(red, green, blue);
|
|
87
|
+
const min = Math.min(red, green, blue);
|
|
88
|
+
const lightness = (max + min) / 2;
|
|
89
|
+
const delta = max - min;
|
|
90
|
+
if (delta === 0)
|
|
91
|
+
return { h: null, s: 0, l: lightness };
|
|
92
|
+
const saturation = delta / (1 - Math.abs(2 * lightness - 1));
|
|
93
|
+
const sector = max === red ? ((green - blue) / delta + 6) % 6 : max === green ? (blue - red) / delta + 2 : (red - green) / delta + 4;
|
|
94
|
+
return { h: sector * 60, s: saturation, l: lightness };
|
|
95
|
+
}
|
|
96
|
+
function hslToRgb(hue, saturation, lightness) {
|
|
97
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
98
|
+
const sector = (((hue % 360) + 360) % 360) / 60;
|
|
99
|
+
const second = chroma * (1 - Math.abs((sector % 2) - 1));
|
|
100
|
+
const [red, green, blue] = sector < 1 ? [chroma, second, 0] : sector < 2 ? [second, chroma, 0] : sector < 3 ? [0, chroma, second]
|
|
101
|
+
: sector < 4 ? [0, second, chroma] : sector < 5 ? [second, 0, chroma] : [chroma, 0, second];
|
|
102
|
+
const match = lightness - chroma / 2;
|
|
103
|
+
return { r: byte((red + match) * 255), g: byte((green + match) * 255), b: byte((blue + match) * 255) };
|
|
104
|
+
}
|
|
105
|
+
export function spectrumColor({ x, y }, alpha) {
|
|
106
|
+
return { ...hslToRgb(clamp(y, 0, 1) * 360, 1, 1 - clamp(x, 0, 1)), a: alpha };
|
|
107
|
+
}
|
|
108
|
+
/** Where a color sits on the spectrum; a gray keeps the hue of `previous`, as it has none. */
|
|
109
|
+
export function spectrumPoint(color, previous) {
|
|
110
|
+
const { h, l } = rgbToHsl(color);
|
|
111
|
+
return { x: 1 - l, y: h === null ? previous?.y ?? 0 : h / 360 };
|
|
112
|
+
}
|
|
113
|
+
/** The track of the Opacity slider: the color from clear to opaque over the kit's 12% to 88% (515:47434). */
|
|
114
|
+
export const opacityTrack = (color) => `linear-gradient(to right, ${cssColor(color, 0)} 12%, ${cssColor(color, 1)} 88%)`;
|
|
115
|
+
export const COLOR_PICKER_CHANNELS = [
|
|
116
|
+
{ channel: "r", label: "Red" },
|
|
117
|
+
{ channel: "g", label: "Green" },
|
|
118
|
+
{ channel: "b", label: "Blue" },
|
|
119
|
+
];
|
|
120
|
+
/** The track of a channel slider: the color with that channel from 0 to 255. */
|
|
121
|
+
export const channelTrack = (color, channel) => `linear-gradient(to right, ${cssColor({ ...color, [channel]: 0 }, 1)}, ${cssColor({ ...color, [channel]: 255 }, 1)})`;
|
|
122
|
+
/** A number typed in a field, kept within `min` and `max`; text with no number is `null`. */
|
|
123
|
+
export function parseNumber(text, min, max) {
|
|
124
|
+
const number = Number.parseFloat(text.replace(/[%\s]/g, ""));
|
|
125
|
+
return Number.isFinite(number) ? clamp(Math.round(number), min, max) : null;
|
|
126
|
+
}
|
|
127
|
+
export function eyeDropper() {
|
|
128
|
+
if (typeof window === "undefined")
|
|
129
|
+
return null;
|
|
130
|
+
return window.EyeDropper ?? null;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/shared.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,kBAAkB,GAAyD;IACtF,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAChC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;IACxC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;CACvC,CAAA;AAED,+GAA+G;AAC/G,MAAM,CAAC,MAAM,iBAAiB,GAAmC;IAC/D,CAAC,SAAS,EAAE,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xB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAA;IAC9C,OAAQ,MAA0D,CAAC,UAAU,IAAI,IAAI,CAAA;AACvF,CAAC","sourcesContent":["/** A color as the picker holds it: channels 0 to 255 and an alpha from 0 to 1. */\nexport type Rgba = { r: number; g: number; b: number; a: number }\n\n/** The three ways to choose a color, as the segments of the system picker. */\nexport type ColorPickerMode = \"grid\" | \"spectrum\" | \"sliders\"\n\nexport const COLOR_PICKER_MODES: readonly { value: ColorPickerMode; label: string }[] = [\n { value: \"grid\", label: \"Grid\" },\n { value: \"spectrum\", label: \"Spectrum\" },\n { value: \"sliders\", label: \"Sliders\" },\n]\n\n/** The kit's Color Grid (515:48178): a row of grays, then nine rows from dark to light, twelve hues across. */\nexport const COLOR_PICKER_GRID: readonly (readonly string[])[] = [\n [\"#fefffe\", \"#ebebeb\", \"#d6d6d6\", \"#c2c2c2\", \"#adadad\", \"#999999\", \"#858585\", \"#707070\", \"#5c5c5c\", \"#474747\", \"#333333\", \"#000000\"],\n [\"#00374a\", \"#011d57\", \"#11053b\", \"#2e063d\", \"#3c071b\", \"#5c0701\", \"#5a1c00\", \"#583300\", \"#563d00\", \"#666100\", \"#4f5504\", \"#263e0f\"],\n [\"#004d65\", \"#012f7b\", \"#1a0a52\", \"#450d59\", \"#551029\", \"#831100\", \"#7b2900\", \"#7a4a00\", \"#785800\", \"#8d8602\", \"#6f760a\", \"#38571a\"],\n [\"#016e8f\", \"#0042a9\", \"#2c0977\", \"#61187c\", \"#791a3d\", \"#b51a00\", \"#ad3e00\", \"#a96800\", \"#a67b01\", \"#c4bc00\", \"#9ba50e\", \"#4e7a27\"],\n [\"#008cb4\", \"#0056d6\", \"#371a94\", \"#7a219e\", \"#99244f\", \"#e22400\", \"#da5100\", \"#d38301\", \"#d19d01\", \"#f5ec00\", \"#c3d117\", \"#669d34\"],\n [\"#00a1d8\", \"#0061fd\", \"#4d22b2\", \"#982abc\", \"#b92d5d\", \"#ff4015\", \"#ff6a00\", \"#ffab01\", \"#fcc700\", \"#fefb41\", \"#d9ec37\", \"#76bb40\"],\n [\"#01c7fc\", \"#3a87fd\", \"#5e30eb\", \"#be38f3\", \"#e63b7a\", \"#fe6250\", \"#fe8648\", \"#feb43f\", \"#fecb3e\", \"#fff76b\", \"#e4ef65\", \"#96d35f\"],\n [\"#52d6fc\", \"#74a7ff\", \"#864ffd\", \"#d357fe\", \"#ee719e\", \"#ff8c82\", \"#fea57d\", \"#fec777\", \"#fed977\", \"#fff994\", \"#eaf28f\", \"#b1dd8b\"],\n [\"#93e3fc\", \"#a7c6ff\", \"#b18cfe\", \"#e292fe\", \"#f4a4c0\", \"#ffb5af\", \"#ffc5ab\", \"#fed9a8\", \"#fde4a8\", \"#fffbb9\", \"#f1f7b7\", \"#cde8b5\"],\n [\"#cbf0ff\", \"#d2e2fe\", \"#d8c9fe\", \"#efcafe\", \"#f9d3e0\", \"#ffdad8\", \"#ffe2d6\", \"#feecd4\", \"#fef1d5\", \"#fdfbdd\", \"#f6fadb\", \"#deeed4\"],\n]\n\nexport const COLOR_PICKER_GRID_COLUMNS = 12\nconst GRID = COLOR_PICKER_GRID.flat()\n\n/** Saved colors fill pages of two rows of five, with the Add button after the last one (kit Swatches 515:52724). */\nexport const COLOR_PICKER_SWATCHES_PER_PAGE = 10\nexport const COLOR_PICKER_SWATCHES_PER_ROW = 5\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value))\nconst byte = (value: number) => clamp(Math.round(value), 0, 255)\n\n/** Reads `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, in either case; anything else is `null`. */\nexport function parseColor(input: string | null | undefined): Rgba | null {\n const match = /^#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec((input ?? \"\").trim())\n if (!match) return null\n let hex = match[1]\n if (hex.length <= 4) hex = [...hex].map((digit) => digit + digit).join(\"\")\n const channel = (index: number) => Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16)\n return { r: channel(0), g: channel(1), b: channel(2), a: hex.length === 8 ? channel(3) / 255 : 1 }\n}\n\nconst two = (value: number) => byte(value).toString(16).padStart(2, \"0\")\n\n/** `#rrggbb`, or `#rrggbbaa` when the color is not opaque. */\nexport function formatColor({ r, g, b, a }: Rgba): string {\n const opaque = Math.round(clamp(a, 0, 1) * 255) === 255\n return `#${two(r)}${two(g)}${two(b)}${opaque ? \"\" : two(clamp(a, 0, 1) * 255)}`\n}\n\n/** The six digits the Hex field shows, as the system picker does: upper case, no `#`. */\nexport const hexDigits = ({ r, g, b }: Rgba) => `${two(r)}${two(g)}${two(b)}`.toUpperCase()\n\n/** A CSS color for a fill. */\nexport const cssColor = ({ r, g, b, a }: Rgba, alpha = a) => `rgb(${byte(r)} ${byte(g)} ${byte(b)} / ${Math.round(clamp(alpha, 0, 1) * 1000) / 10}%)`\n\nexport const sameRgb = (one: Rgba, other: Rgba) => byte(one.r) === byte(other.r) && byte(one.g) === byte(other.g) && byte(one.b) === byte(other.b)\n\n/** Whole percent of opacity, as the Opacity field shows it. */\nexport const alphaPercent = (a: number) => Math.round(clamp(a, 0, 1) * 100)\n\n/** The grid cell of a color, or -1 when the grid has no such color. */\nexport const gridIndex = (color: Rgba) => GRID.findIndex((hex) => {\n const cell = parseColor(hex)\n return cell !== null && sameRgb(cell, color)\n})\n\nexport const gridColor = (index: number) => GRID[index]\n\n/** The cell an arrow key, Home or End moves to from `index`, or `index` itself at an edge. */\nexport function gridMove(index: number, key: string): number {\n const columns = COLOR_PICKER_GRID_COLUMNS\n const column = index % columns\n const next: Record<string, number> = {\n ArrowRight: column < columns - 1 ? index + 1 : index,\n ArrowLeft: column > 0 ? index - 1 : index,\n ArrowDown: index + columns < GRID.length ? index + columns : index,\n ArrowUp: index - columns >= 0 ? index - columns : index,\n Home: index - column,\n End: index - column + columns - 1,\n }\n return next[key] ?? index\n}\n\n/** The item a key moves to in a list of `count` items (saved colors), or `index` itself. */\nexport function listMove(index: number, count: number, key: string): number {\n const next: Record<string, number> = {\n ArrowRight: Math.min(count - 1, index + 1),\n ArrowDown: Math.min(count - 1, index + 1),\n ArrowLeft: Math.max(0, index - 1),\n ArrowUp: Math.max(0, index - 1),\n Home: 0,\n End: count - 1,\n }\n return next[key] ?? index\n}\n\n/** Pages of saved colors: the colors and the Add button after them, ten to a page. */\nexport const swatchPageCount = (count: number) => Math.max(1, Math.ceil((count + 1) / COLOR_PICKER_SWATCHES_PER_PAGE))\n\nfunction rgbToHsl({ r, g, b }: Rgba) {\n const [red, green, blue] = [r / 255, g / 255, b / 255]\n const max = Math.max(red, green, blue)\n const min = Math.min(red, green, blue)\n const lightness = (max + min) / 2\n const delta = max - min\n if (delta === 0) return { h: null, s: 0, l: lightness }\n const saturation = delta / (1 - Math.abs(2 * lightness - 1))\n const sector = max === red ? ((green - blue) / delta + 6) % 6 : max === green ? (blue - red) / delta + 2 : (red - green) / delta + 4\n return { h: sector * 60, s: saturation, l: lightness }\n}\n\nfunction hslToRgb(hue: number, saturation: number, lightness: number) {\n const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation\n const sector = (((hue % 360) + 360) % 360) / 60\n const second = chroma * (1 - Math.abs((sector % 2) - 1))\n const [red, green, blue] =\n sector < 1 ? [chroma, second, 0] : sector < 2 ? [second, chroma, 0] : sector < 3 ? [0, chroma, second]\n : sector < 4 ? [0, second, chroma] : sector < 5 ? [second, 0, chroma] : [chroma, 0, second]\n const match = lightness - chroma / 2\n return { r: byte((red + match) * 255), g: byte((green + match) * 255), b: byte((blue + match) * 255) }\n}\n\n/**\n * A point of the spectrum: hue from top to bottom, and from white at the leading edge through the full hue at the\n * middle to black at the trailing edge, as the system picker draws it (UIColorPickerViewController overview image).\n */\nexport type SpectrumPoint = { x: number; y: number }\n\nexport function spectrumColor({ x, y }: SpectrumPoint, alpha: number): Rgba {\n return { ...hslToRgb(clamp(y, 0, 1) * 360, 1, 1 - clamp(x, 0, 1)), a: alpha }\n}\n\n/** Where a color sits on the spectrum; a gray keeps the hue of `previous`, as it has none. */\nexport function spectrumPoint(color: Rgba, previous?: SpectrumPoint): SpectrumPoint {\n const { h, l } = rgbToHsl(color)\n return { x: 1 - l, y: h === null ? previous?.y ?? 0 : h / 360 }\n}\n\n/** The track of the Opacity slider: the color from clear to opaque over the kit's 12% to 88% (515:47434). */\nexport const opacityTrack = (color: Rgba) => `linear-gradient(to right, ${cssColor(color, 0)} 12%, ${cssColor(color, 1)} 88%)`\n\nexport type ColorChannel = \"r\" | \"g\" | \"b\"\n\nexport const COLOR_PICKER_CHANNELS: readonly { channel: ColorChannel; label: string }[] = [\n { channel: \"r\", label: \"Red\" },\n { channel: \"g\", label: \"Green\" },\n { channel: \"b\", label: \"Blue\" },\n]\n\n/** The track of a channel slider: the color with that channel from 0 to 255. */\nexport const channelTrack = (color: Rgba, channel: ColorChannel) =>\n `linear-gradient(to right, ${cssColor({ ...color, [channel]: 0 }, 1)}, ${cssColor({ ...color, [channel]: 255 }, 1)})`\n\n/** A number typed in a field, kept within `min` and `max`; text with no number is `null`. */\nexport function parseNumber(text: string, min: number, max: number): number | null {\n const number = Number.parseFloat(text.replace(/[%\\s]/g, \"\"))\n return Number.isFinite(number) ? clamp(Math.round(number), min, max) : null\n}\n\n/** The EyeDropper API (Chromium), when the browser has it. */\ntype EyeDropperConstructor = new () => { open: () => Promise<{ sRGBHex: string }> }\n\nexport function eyeDropper(): EyeDropperConstructor | null {\n if (typeof window === \"undefined\") return null\n return (window as Window & { EyeDropper?: EyeDropperConstructor }).EyeDropper ?? null\n}\n"]}
|