@plexui/vue 0.9.0 → 0.11.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 +6 -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/ButtonGroup/ButtonGroup.js +7 -0
- package/dist/es/components/ButtonGroup/ButtonGroup.js.map +1 -1
- package/dist/es/components/ButtonGroup/index.js.map +1 -1
- package/dist/es/components/Checkbox/Checkbox.js +5 -6
- package/dist/es/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/es/components/ColorPicker/ColorPicker.js +476 -0
- package/dist/es/components/ColorPicker/ColorPicker.js.map +1 -0
- package/dist/es/components/ColorPicker/ColorWell.js +186 -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 +223 -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 +58 -0
- package/dist/es/components/ContextMenu/shared.js.map +1 -0
- package/dist/es/components/DatePicker/DatePicker.js +19 -3
- package/dist/es/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js +1 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +245 -25
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/dialogSteps.js +85 -0
- package/dist/es/components/Dialog/dialogSteps.js.map +1 -0
- package/dist/es/components/Dialog/dialogViewport.js +74 -0
- package/dist/es/components/Dialog/dialogViewport.js.map +1 -0
- package/dist/es/components/Dialog/index.js +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +2 -1
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/Field/Field.js +11 -3
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/FieldGroup/FieldGroup.js +12 -1
- package/dist/es/components/FieldGroup/FieldGroup.js.map +1 -1
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +2 -2
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js.map +1 -1
- package/dist/es/components/Icon/index.js +1 -0
- package/dist/es/components/Icon/index.js.map +1 -1
- package/dist/es/components/Icon/svg/Eyedropper.js +10 -0
- package/dist/es/components/Icon/svg/Eyedropper.js.map +1 -0
- package/dist/es/components/IndexBar/IndexBar.js +215 -0
- package/dist/es/components/IndexBar/IndexBar.js.map +1 -0
- package/dist/es/components/IndexBar/index.js +2 -0
- package/dist/es/components/IndexBar/index.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 -2
- package/dist/es/components/Input/Input.js.map +1 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js +149 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +206 -33
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/Menu/index.js +1 -1
- package/dist/es/components/Menu/index.js.map +1 -1
- package/dist/es/components/Page/Page.js +43 -11
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/PageControl/PageControl.js +210 -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/PhoneLayout/PhoneLayout.js +50 -0
- package/dist/es/components/PhoneLayout/PhoneLayout.js.map +1 -0
- package/dist/es/components/PhoneLayout/index.js +2 -0
- package/dist/es/components/PhoneLayout/index.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +5 -1
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Popover/deferredPointerDownOutside.js +59 -4
- package/dist/es/components/Popover/deferredPointerDownOutside.js.map +1 -1
- package/dist/es/components/Select/Select.js +18 -11
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/SelectControl/SelectControl.js +1 -0
- package/dist/es/components/SelectControl/SelectControl.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +21 -6
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +44 -9
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/Stepper/Stepper.js +195 -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/SwipeActions/SwipeActions.js +374 -0
- package/dist/es/components/SwipeActions/SwipeActions.js.map +1 -0
- package/dist/es/components/SwipeActions/index.js +2 -0
- package/dist/es/components/SwipeActions/index.js.map +1 -0
- package/dist/es/components/Switch/Switch.js +3 -1
- package/dist/es/components/Switch/Switch.js.map +1 -1
- package/dist/es/components/TabBar/TabBar.js +205 -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 +10 -2
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/TagInput/TagInput.js +3 -46
- package/dist/es/components/TagInput/TagInput.js.map +1 -1
- package/dist/es/components/Textarea/Textarea.js +2 -0
- package/dist/es/components/Textarea/Textarea.js.map +1 -1
- package/dist/es/components/Tip/Tip.js +276 -0
- package/dist/es/components/Tip/Tip.js.map +1 -0
- package/dist/es/components/Tip/index.js +2 -0
- package/dist/es/components/Tip/index.js.map +1 -0
- package/dist/es/components/Toast/ToastRenderer.js +30 -13
- package/dist/es/components/Toast/ToastRenderer.js.map +1 -1
- package/dist/es/components/Toast/Toaster.js +17 -6
- package/dist/es/components/Toast/Toaster.js.map +1 -1
- package/dist/es/components/Toast/toastLifecycle.js +113 -1
- package/dist/es/components/Toast/toastLifecycle.js.map +1 -1
- package/dist/es/components/Toolbar/Toolbar.js +37 -6
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/es/components/Toolbar/index.js.map +1 -1
- package/dist/es/components/Tooltip/slot.js +3 -3
- package/dist/es/components/Tooltip/slot.js.map +1 -1
- package/dist/es/composables/useEscCloseStack.js +8 -4
- package/dist/es/composables/useEscCloseStack.js.map +1 -1
- package/dist/es/lib/fieldRow.js +15 -2
- package/dist/es/lib/fieldRow.js.map +1 -1
- package/dist/es/lib/floatingBoundary.js +3 -1
- package/dist/es/lib/floatingBoundary.js.map +1 -1
- package/dist/es/lib/helpers.js +21 -0
- package/dist/es/lib/helpers.js.map +1 -1
- package/dist/es/lib/menuSubmenuPlacement.js +51 -6
- package/dist/es/lib/menuSubmenuPlacement.js.map +1 -1
- package/dist/es/lib/menuTriggerCover.js +70 -0
- package/dist/es/lib/menuTriggerCover.js.map +1 -0
- package/dist/es/lib/phoneLayout.js +16 -0
- package/dist/es/lib/phoneLayout.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/toastRegion.js +6 -0
- package/dist/es/lib/toastRegion.js.map +1 -0
- package/dist/types/components/ButtonGroup/ButtonGroup.d.ts +13 -0
- package/dist/types/components/ButtonGroup/index.d.ts +1 -1
- package/dist/types/components/ColorPicker/ColorPicker.d.ts +244 -0
- package/dist/types/components/ColorPicker/ColorWell.d.ts +334 -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 +128 -0
- package/dist/types/components/ContextMenu/index.d.ts +1 -0
- package/dist/types/components/ContextMenu/shared.d.ts +51 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +24 -4
- package/dist/types/components/DateRangePicker/DateRangePicker.d.ts +4 -4
- package/dist/types/components/Dialog/Dialog.d.ts +100 -4
- package/dist/types/components/Dialog/dialogSteps.d.ts +10 -0
- package/dist/types/components/Dialog/dialogViewport.d.ts +1 -0
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/Field/Field.d.ts +21 -2
- package/dist/types/components/FieldGroup/FieldGroup.d.ts +18 -1
- package/dist/types/components/Icon/index.d.ts +1 -0
- package/dist/types/components/Icon/svg/Eyedropper.d.ts +3 -0
- package/dist/types/components/IndexBar/IndexBar.d.ts +112 -0
- package/dist/types/components/IndexBar/index.d.ts +1 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +2 -2
- package/dist/types/components/Menu/Menu.d.ts +153 -40
- package/dist/types/components/Menu/index.d.ts +1 -1
- package/dist/types/components/Page/Page.d.ts +13 -5
- package/dist/types/components/PageControl/PageControl.d.ts +216 -0
- package/dist/types/components/PageControl/index.d.ts +1 -0
- package/dist/types/components/PhoneLayout/PhoneLayout.d.ts +21 -0
- package/dist/types/components/PhoneLayout/index.d.ts +1 -0
- package/dist/types/components/Popover/deferredPointerDownOutside.d.ts +1 -1
- package/dist/types/components/Select/Select.d.ts +6 -6
- package/dist/types/components/Stepper/Stepper.d.ts +338 -0
- package/dist/types/components/Stepper/index.d.ts +1 -0
- package/dist/types/components/SwipeActions/SwipeActions.d.ts +135 -0
- package/dist/types/components/SwipeActions/index.d.ts +1 -0
- package/dist/types/components/TabBar/TabBar.d.ts +405 -0
- package/dist/types/components/TabBar/index.d.ts +1 -0
- package/dist/types/components/Tip/Tip.d.ts +146 -0
- package/dist/types/components/Tip/index.d.ts +1 -0
- package/dist/types/components/Toast/toastLifecycle.d.ts +34 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +26 -9
- package/dist/types/components/Toolbar/index.d.ts +1 -1
- package/dist/types/components/Tooltip/CopyTooltip.d.ts +1 -1
- package/dist/types/composables/useEscCloseStack.d.ts +2 -2
- package/dist/types/lib/fieldRow.d.ts +5 -0
- package/dist/types/lib/helpers.d.ts +6 -0
- package/dist/types/lib/menuSubmenuPlacement.d.ts +14 -1
- package/dist/types/lib/menuTriggerCover.d.ts +23 -0
- package/dist/types/lib/phoneLayout.d.ts +11 -0
- package/dist/types/lib/scrollEdges.d.ts +16 -0
- package/dist/types/lib/toastRegion.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { computed, defineComponent, h, onMounted, ref, useId } from "vue";
|
|
2
|
+
import s from "@plexui/styles/components/ColorPicker/ColorPicker.module.css";
|
|
3
|
+
import { useBreakpoint } from "../../composables/useBreakpoints.js";
|
|
4
|
+
import { Button, NavigationButton } from "../Button/index.js";
|
|
5
|
+
import { Dialog, DialogBody, DialogClose, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "../Dialog/index.js";
|
|
6
|
+
import { Eyedropper, X } from "../Icon/index.js";
|
|
7
|
+
import { Popover, PopoverContent, PopoverTrigger } from "../Popover/index.js";
|
|
8
|
+
import { Toolbar, ToolbarLeading, ToolbarTitle, ToolbarTrailing } from "../Toolbar/index.js";
|
|
9
|
+
import { ColorPicker } from "./ColorPicker.js";
|
|
10
|
+
import { alphaPercent, cssColor, eyeDropper, formatColor, hexDigits, parseColor } from "./shared.js";
|
|
11
|
+
// Vue port of packages/ui/src/components/ColorPicker/ColorWell.tsx: the same well, and the same picker in a Popover
|
|
12
|
+
// from the well or, on a phone, a sheet with the eyedropper, the title and Close. React's `value` + `onChange`
|
|
13
|
+
// become `value` + `update:value` (`v-model:value`) and `change`; the picker's `mode` and `swatches` events pass
|
|
14
|
+
// through as `update:mode` / `modeChange` and `update:swatches` / `swatchesChange`.
|
|
15
|
+
const ColorWellComponent = defineComponent({
|
|
16
|
+
name: "ColorWell",
|
|
17
|
+
inheritAttrs: false,
|
|
18
|
+
props: {
|
|
19
|
+
/** The `id` of the well. */
|
|
20
|
+
id: String,
|
|
21
|
+
/** The controlled color, `#rrggbb` or `#rrggbbaa`; `null` shows the rainbow well with no color. Bind with `v-model:value`. */
|
|
22
|
+
value: { type: String, default: undefined },
|
|
23
|
+
/** The color when it is initially rendered. Use when you do not need to control the color. @default null */
|
|
24
|
+
defaultValue: { type: String, default: null },
|
|
25
|
+
/** The title of the picker. @default "Colors" */
|
|
26
|
+
title: { type: String, default: "Colors" },
|
|
27
|
+
/** Shows the eyedropper in the picker where the browser can pick a color from the screen (EyeDropper API). @default true */
|
|
28
|
+
supportsEyedropper: { type: Boolean, default: true },
|
|
29
|
+
/** The kit's Picker Button sizes: `sm` 28px, `lg` 36px. @default "sm" */
|
|
30
|
+
size: { type: String, default: "sm" },
|
|
31
|
+
/** When `true`, prevents the user from opening the picker. */
|
|
32
|
+
disabled: { type: Boolean, default: false },
|
|
33
|
+
/** The name of the well. Submits its color with the owning form. */
|
|
34
|
+
name: String,
|
|
35
|
+
/** Accessible name of the well. @default "Color" */
|
|
36
|
+
ariaLabel: String,
|
|
37
|
+
/** The `id` of the visible label of the well. */
|
|
38
|
+
ariaLabelledby: String,
|
|
39
|
+
/** Shows the Opacity slider in the picker. @default true */
|
|
40
|
+
supportsAlpha: { type: Boolean, default: true },
|
|
41
|
+
/** The controlled way to choose a color. Bind with `v-model:mode`. */
|
|
42
|
+
mode: { type: String, default: undefined },
|
|
43
|
+
/** The way to choose a color when the picker opens. @default "grid" */
|
|
44
|
+
defaultMode: { type: String, default: undefined },
|
|
45
|
+
/** The controlled saved colors. Bind with `v-model:swatches`. */
|
|
46
|
+
swatches: { type: Array, default: undefined },
|
|
47
|
+
/** The saved colors when the picker opens. @default [] */
|
|
48
|
+
defaultSwatches: { type: Array, default: undefined },
|
|
49
|
+
},
|
|
50
|
+
emits: {
|
|
51
|
+
/** The picker chose a color */
|
|
52
|
+
"update:value": (value) => typeof value === "string",
|
|
53
|
+
/** The picker chose a color (React `onChange`) */
|
|
54
|
+
"change": (value) => typeof value === "string",
|
|
55
|
+
/** Another of Grid, Spectrum and Sliders was chosen */
|
|
56
|
+
"update:mode": (mode) => typeof mode === "string",
|
|
57
|
+
/** Another way was chosen (React `onModeChange`) */
|
|
58
|
+
"modeChange": (mode) => typeof mode === "string",
|
|
59
|
+
/** Add saved the current color or Delete removed one */
|
|
60
|
+
"update:swatches": (swatches) => Array.isArray(swatches),
|
|
61
|
+
/** The saved colors changed (React `onSwatchesChange`) */
|
|
62
|
+
"swatchesChange": (swatches) => Array.isArray(swatches),
|
|
63
|
+
},
|
|
64
|
+
setup(props, { attrs, emit }) {
|
|
65
|
+
const wide = useBreakpoint("md");
|
|
66
|
+
const valueId = `${useId()}-value`;
|
|
67
|
+
const open = ref(false);
|
|
68
|
+
const internalValue = ref(props.defaultValue);
|
|
69
|
+
const value = computed(() => (props.value === undefined ? internalValue.value : props.value));
|
|
70
|
+
const color = computed(() => parseColor(value.value));
|
|
71
|
+
// The EyeDropper API exists only in a browser, so the button appears after mounting.
|
|
72
|
+
const canPick = ref(false);
|
|
73
|
+
onMounted(() => {
|
|
74
|
+
canPick.value = eyeDropper() !== null;
|
|
75
|
+
});
|
|
76
|
+
let picking = false;
|
|
77
|
+
const choose = (next) => {
|
|
78
|
+
if (props.value === undefined)
|
|
79
|
+
internalValue.value = next;
|
|
80
|
+
emit("update:value", next);
|
|
81
|
+
emit("change", next);
|
|
82
|
+
};
|
|
83
|
+
const pick = async () => {
|
|
84
|
+
const EyeDropper = eyeDropper();
|
|
85
|
+
if (!EyeDropper || picking)
|
|
86
|
+
return;
|
|
87
|
+
picking = true;
|
|
88
|
+
try {
|
|
89
|
+
const picked = parseColor((await new EyeDropper().open()).sRGBHex);
|
|
90
|
+
if (picked)
|
|
91
|
+
choose(formatColor({ ...picked, a: color.value?.a ?? 1 }));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Escape, or a click the browser did not hand to the page, cancels the pick.
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
picking = false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const setOpen = (next) => {
|
|
101
|
+
open.value = next;
|
|
102
|
+
};
|
|
103
|
+
return () => {
|
|
104
|
+
const current = color.value;
|
|
105
|
+
const well = h("button", {
|
|
106
|
+
...attrs,
|
|
107
|
+
"id": props.id,
|
|
108
|
+
"type": "button",
|
|
109
|
+
"class": [s.Well, attrs.class],
|
|
110
|
+
"data-size": props.size,
|
|
111
|
+
"data-selected": current ? "" : undefined,
|
|
112
|
+
"disabled": props.disabled,
|
|
113
|
+
"aria-label": props.ariaLabelledby ? undefined : (props.ariaLabel ?? "Color"),
|
|
114
|
+
"aria-labelledby": props.ariaLabelledby,
|
|
115
|
+
"aria-describedby": current ? valueId : undefined,
|
|
116
|
+
"style": current ? { "--color-well-color": cssColor(current) } : undefined,
|
|
117
|
+
}, current
|
|
118
|
+
? [
|
|
119
|
+
h("span", { class: s.WellColor }),
|
|
120
|
+
// The color, read as the well's description.
|
|
121
|
+
h("span", { id: valueId, hidden: true }, `#${hexDigits(current)}${current.a < 1 ? `, ${alphaPercent(current.a)}% opacity` : ""}`),
|
|
122
|
+
]
|
|
123
|
+
: []);
|
|
124
|
+
const picker = () => h(ColorPicker, {
|
|
125
|
+
"supportsAlpha": props.supportsAlpha,
|
|
126
|
+
"mode": props.mode,
|
|
127
|
+
...(props.defaultMode !== undefined ? { defaultMode: props.defaultMode } : {}),
|
|
128
|
+
"swatches": props.swatches,
|
|
129
|
+
"defaultSwatches": props.defaultSwatches,
|
|
130
|
+
"value": formatColor(current ?? { r: 0, g: 0, b: 0, a: 1 }),
|
|
131
|
+
"ariaLabel": props.title,
|
|
132
|
+
"onChange": choose,
|
|
133
|
+
"onUpdate:mode": (mode) => emit("update:mode", mode),
|
|
134
|
+
"onModeChange": (mode) => emit("modeChange", mode),
|
|
135
|
+
"onUpdate:swatches": (swatches) => emit("update:swatches", swatches),
|
|
136
|
+
"onSwatchesChange": (swatches) => emit("swatchesChange", swatches),
|
|
137
|
+
});
|
|
138
|
+
const eyedropperButton = (glass) => props.supportsEyedropper && canPick.value
|
|
139
|
+
? h(Button, {
|
|
140
|
+
"color": "secondary",
|
|
141
|
+
"variant": glass ? "soft" : "ghost",
|
|
142
|
+
"mobileMaterial": glass ? "glass" : undefined,
|
|
143
|
+
"size": glass ? "lg" : "sm",
|
|
144
|
+
"uniform": true,
|
|
145
|
+
"pill": true,
|
|
146
|
+
"aria-label": "Eyedropper",
|
|
147
|
+
"onClick": () => void pick(),
|
|
148
|
+
}, () => h(Eyedropper))
|
|
149
|
+
: null;
|
|
150
|
+
const hidden = props.name !== undefined ? h("input", { type: "hidden", name: props.name, value: value.value ?? "", disabled: props.disabled }) : null;
|
|
151
|
+
const presentation = wide.value
|
|
152
|
+
? h(Popover, { "open": open.value, "onUpdate:open": setOpen }, () => [
|
|
153
|
+
h(PopoverTrigger, null, () => well),
|
|
154
|
+
h(PopoverContent, { class: s.Popover, width: "auto", side: "bottom", align: "center" }, () => [
|
|
155
|
+
h("div", { class: s.PopoverHeader }, [
|
|
156
|
+
h("div", { class: s.PopoverLeading }, [eyedropperButton(false)]),
|
|
157
|
+
h("span", { class: s.PopoverTitle }, props.title),
|
|
158
|
+
h("div", { class: s.PopoverTrailing }, [
|
|
159
|
+
h(Button, { "color": "secondary", "variant": "ghost", "size": "sm", "uniform": true, "pill": true, "aria-label": "Close", "onClick": () => setOpen(false) }, () => h(X)),
|
|
160
|
+
]),
|
|
161
|
+
]),
|
|
162
|
+
picker(),
|
|
163
|
+
]),
|
|
164
|
+
])
|
|
165
|
+
: h(Dialog, { "open": open.value, "onUpdate:open": setOpen }, () => [
|
|
166
|
+
h(DialogTrigger, null, () => well),
|
|
167
|
+
h(DialogContent, { mobileVariant: "sheet", showClose: false, class: s.Sheet }, () => [
|
|
168
|
+
h(Toolbar, { background: "solid" }, () => [
|
|
169
|
+
h(ToolbarLeading, null, () => eyedropperButton(true)),
|
|
170
|
+
h(ToolbarTitle, null, () => props.title),
|
|
171
|
+
h(ToolbarTrailing, null, () => h(DialogClose, null, () => h(NavigationButton, { action: "close" }))),
|
|
172
|
+
]),
|
|
173
|
+
h(DialogHeader, null, () => h(DialogTitle, null, () => props.title)),
|
|
174
|
+
h(DialogBody, { class: s.SheetBody }, () => picker()),
|
|
175
|
+
]),
|
|
176
|
+
]);
|
|
177
|
+
return [hidden, presentation];
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
/**
|
|
182
|
+
* A color well, as `UIColorWell`: the kit's Picker Button (5739:34128), a rainbow ring around the chosen color. It
|
|
183
|
+
* opens the color picker, in a Popover from the well, and on a phone in a sheet, as the system picker.
|
|
184
|
+
*/
|
|
185
|
+
export const ColorWell = ColorWellComponent;
|
|
186
|
+
//# sourceMappingURL=ColorWell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorWell.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/ColorWell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAiB,MAAM,KAAK,CAAA;AACxF,OAAO,CAAC,MAAM,8DAA8D,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC7H,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,E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,CAAC,CAAC,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;4BACrD,CAAC,CAAC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;4BACxC,CAAC,CAAC,eAAe,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;yBACrG,CAAC;wBACF,CAAC,CAAC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;wBACpE,CAAC,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;qBACtD,CAAC;iBACH,CAAC,CAAA;YAEN,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;QAC/B,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAIF;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAkB,CAAA","sourcesContent":["import { computed, defineComponent, h, onMounted, ref, useId, type PropType } from \"vue\"\nimport s from \"@plexui/styles/components/ColorPicker/ColorPicker.module.css\"\nimport { useBreakpoint } from \"../../composables/useBreakpoints.js\"\nimport { Button, NavigationButton } from \"../Button/index.js\"\nimport { Dialog, DialogBody, DialogClose, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from \"../Dialog/index.js\"\nimport { Eyedropper, X } from \"../Icon/index.js\"\nimport { Popover, PopoverContent, PopoverTrigger } from \"../Popover/index.js\"\nimport { Toolbar, ToolbarLeading, ToolbarTitle, ToolbarTrailing } from \"../Toolbar/index.js\"\nimport { ColorPicker } from \"./ColorPicker.js\"\nimport { alphaPercent, cssColor, eyeDropper, formatColor, hexDigits, parseColor, type ColorPickerMode } from \"./shared.js\"\n\n// Vue port of packages/ui/src/components/ColorPicker/ColorWell.tsx: the same well, and the same picker in a Popover\n// from the well or, on a phone, a sheet with the eyedropper, the title and Close. React's `value` + `onChange`\n// become `value` + `update:value` (`v-model:value`) and `change`; the picker's `mode` and `swatches` events pass\n// through as `update:mode` / `modeChange` and `update:swatches` / `swatchesChange`.\n\nconst ColorWellComponent = defineComponent({\n name: \"ColorWell\",\n inheritAttrs: false,\n props: {\n /** The `id` of the well. */\n id: String,\n /** The controlled color, `#rrggbb` or `#rrggbbaa`; `null` shows the rainbow well with no color. Bind with `v-model:value`. */\n value: { type: String as PropType<string | null>, default: undefined },\n /** The color when it is initially rendered. Use when you do not need to control the color. @default null */\n defaultValue: { type: String as PropType<string | null>, default: null },\n /** The title of the picker. @default \"Colors\" */\n title: { type: String, default: \"Colors\" },\n /** Shows the eyedropper in the picker where the browser can pick a color from the screen (EyeDropper API). @default true */\n supportsEyedropper: { type: Boolean, default: true },\n /** The kit's Picker Button sizes: `sm` 28px, `lg` 36px. @default \"sm\" */\n size: { type: String as PropType<\"sm\" | \"lg\">, default: \"sm\" },\n /** When `true`, prevents the user from opening the picker. */\n disabled: { type: Boolean, default: false },\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 ariaLabel: String,\n /** The `id` of the visible label of the well. */\n ariaLabelledby: String,\n /** Shows the Opacity slider in the picker. @default true */\n supportsAlpha: { type: Boolean, default: true },\n /** The controlled way to choose a color. Bind with `v-model:mode`. */\n mode: { type: String as PropType<ColorPickerMode>, default: undefined },\n /** The way to choose a color when the picker opens. @default \"grid\" */\n defaultMode: { type: String as PropType<ColorPickerMode>, default: undefined },\n /** The controlled saved colors. Bind with `v-model:swatches`. */\n swatches: { type: Array as PropType<string[]>, default: undefined },\n /** The saved colors when the picker opens. @default [] */\n defaultSwatches: { type: Array as PropType<string[]>, default: undefined },\n },\n emits: {\n /** The picker chose a color */\n \"update:value\": (value: string) => typeof value === \"string\",\n /** The picker chose a color (React `onChange`) */\n \"change\": (value: string) => typeof value === \"string\",\n /** Another of Grid, Spectrum and Sliders was chosen */\n \"update:mode\": (mode: ColorPickerMode) => typeof mode === \"string\",\n /** Another way was chosen (React `onModeChange`) */\n \"modeChange\": (mode: ColorPickerMode) => typeof mode === \"string\",\n /** Add saved the current color or Delete removed one */\n \"update:swatches\": (swatches: string[]) => Array.isArray(swatches),\n /** The saved colors changed (React `onSwatchesChange`) */\n \"swatchesChange\": (swatches: string[]) => Array.isArray(swatches),\n },\n setup(props, { attrs, emit }) {\n const wide = useBreakpoint(\"md\")\n const valueId = `${useId()}-value`\n const open = ref(false)\n const internalValue = ref<string | null>(props.defaultValue)\n const value = computed(() => (props.value === undefined ? internalValue.value : props.value))\n const color = computed(() => parseColor(value.value))\n // The EyeDropper API exists only in a browser, so the button appears after mounting.\n const canPick = ref(false)\n onMounted(() => {\n canPick.value = eyeDropper() !== null\n })\n let picking = false\n\n const choose = (next: string) => {\n if (props.value === undefined) internalValue.value = next\n emit(\"update:value\", next)\n emit(\"change\", next)\n }\n\n const pick = async () => {\n const EyeDropper = eyeDropper()\n if (!EyeDropper || picking) return\n picking = true\n try {\n const picked = parseColor((await new EyeDropper().open()).sRGBHex)\n if (picked) choose(formatColor({ ...picked, a: color.value?.a ?? 1 }))\n } catch {\n // Escape, or a click the browser did not hand to the page, cancels the pick.\n } finally {\n picking = false\n }\n }\n\n const setOpen = (next: boolean) => {\n open.value = next\n }\n\n return () => {\n const current = color.value\n const well = h(\n \"button\",\n {\n ...attrs,\n \"id\": props.id,\n \"type\": \"button\",\n \"class\": [s.Well, attrs.class],\n \"data-size\": props.size,\n \"data-selected\": current ? \"\" : undefined,\n \"disabled\": props.disabled,\n \"aria-label\": props.ariaLabelledby ? undefined : (props.ariaLabel ?? \"Color\"),\n \"aria-labelledby\": props.ariaLabelledby,\n \"aria-describedby\": current ? valueId : undefined,\n \"style\": current ? { \"--color-well-color\": cssColor(current) } : undefined,\n },\n current\n ? [\n h(\"span\", { class: s.WellColor }),\n // The color, read as the well's description.\n h(\"span\", { id: valueId, hidden: true }, `#${hexDigits(current)}${current.a < 1 ? `, ${alphaPercent(current.a)}% opacity` : \"\"}`),\n ]\n : [],\n )\n\n const picker = () =>\n h(ColorPicker, {\n \"supportsAlpha\": props.supportsAlpha,\n \"mode\": props.mode,\n ...(props.defaultMode !== undefined ? { defaultMode: props.defaultMode } : {}),\n \"swatches\": props.swatches,\n \"defaultSwatches\": props.defaultSwatches,\n \"value\": formatColor(current ?? { r: 0, g: 0, b: 0, a: 1 }),\n \"ariaLabel\": props.title,\n \"onChange\": choose,\n \"onUpdate:mode\": (mode: ColorPickerMode) => emit(\"update:mode\", mode),\n \"onModeChange\": (mode: ColorPickerMode) => emit(\"modeChange\", mode),\n \"onUpdate:swatches\": (swatches: string[]) => emit(\"update:swatches\", swatches),\n \"onSwatchesChange\": (swatches: string[]) => emit(\"swatchesChange\", swatches),\n })\n\n const eyedropperButton = (glass: boolean) =>\n props.supportsEyedropper && canPick.value\n ? h(\n Button,\n {\n \"color\": \"secondary\",\n \"variant\": glass ? \"soft\" : \"ghost\",\n \"mobileMaterial\": glass ? \"glass\" : undefined,\n \"size\": glass ? \"lg\" : \"sm\",\n \"uniform\": true,\n \"pill\": true,\n \"aria-label\": \"Eyedropper\",\n \"onClick\": () => void pick(),\n },\n () => h(Eyedropper),\n )\n : null\n\n const hidden = props.name !== undefined ? h(\"input\", { type: \"hidden\", name: props.name, value: value.value ?? \"\", disabled: props.disabled }) : null\n\n const presentation = wide.value\n ? h(Popover, { \"open\": open.value, \"onUpdate:open\": setOpen }, () => [\n h(PopoverTrigger, null, () => well),\n h(PopoverContent, { class: s.Popover, width: \"auto\", side: \"bottom\", align: \"center\" }, () => [\n h(\"div\", { class: s.PopoverHeader }, [\n h(\"div\", { class: s.PopoverLeading }, [eyedropperButton(false)]),\n h(\"span\", { class: s.PopoverTitle }, props.title),\n h(\"div\", { class: s.PopoverTrailing }, [\n h(\n Button,\n { \"color\": \"secondary\", \"variant\": \"ghost\", \"size\": \"sm\", \"uniform\": true, \"pill\": true, \"aria-label\": \"Close\", \"onClick\": () => setOpen(false) },\n () => h(X),\n ),\n ]),\n ]),\n picker(),\n ]),\n ])\n : h(Dialog, { \"open\": open.value, \"onUpdate:open\": setOpen }, () => [\n h(DialogTrigger, null, () => well),\n h(DialogContent, { mobileVariant: \"sheet\", showClose: false, class: s.Sheet }, () => [\n h(Toolbar, { background: \"solid\" }, () => [\n h(ToolbarLeading, null, () => eyedropperButton(true)),\n h(ToolbarTitle, null, () => props.title),\n h(ToolbarTrailing, null, () => h(DialogClose, null, () => h(NavigationButton, { action: \"close\" }))),\n ]),\n h(DialogHeader, null, () => h(DialogTitle, null, () => props.title)),\n h(DialogBody, { class: s.SheetBody }, () => picker()),\n ]),\n ])\n\n return [hidden, presentation]\n }\n },\n})\n\nexport type ColorWellProps = InstanceType<typeof ColorWellComponent>[\"$props\"]\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 const ColorWell = ColorWellComponent\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,SAAS,EAAuB,MAAM,gBAAgB,CAAA","sourcesContent":["export { ColorPicker, type ColorPickerProps } from \"./ColorPicker.js\"\nexport { ColorWell, type ColorWellProps } from \"./ColorWell.js\"\nexport type { ColorPickerMode } from \"./shared.js\"\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":"AAOA,MAAM,CAAC,MAAM,kBAAkB,GA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AAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;IAC5D,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC7E,CAAC;AAKD,MAAM,UAAU,UAAU;IACxB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAA;IAC9C,OAAQ,MAA0D,CAAC,UAAU,IAAI,IAAI,CAAA;AACvF,CAAC","sourcesContent":["// Shared with packages/ui/src/components/ColorPicker/shared.ts: keep the two copies the same.\n/** 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"]}
|