chroma-panel 0.1.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/LICENSE +44 -0
- package/README.md +119 -0
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/a11y/contrast.cjs +107 -0
- package/dist/a11y/contrast.d.cts +34 -0
- package/dist/a11y/contrast.d.ts +34 -0
- package/dist/a11y/contrast.js +101 -0
- package/dist/color/convert.cjs +162 -0
- package/dist/color/convert.d.cts +16 -0
- package/dist/color/convert.d.ts +16 -0
- package/dist/color/convert.js +153 -0
- package/dist/color/parse.cjs +153 -0
- package/dist/color/parse.d.cts +7 -0
- package/dist/color/parse.d.ts +7 -0
- package/dist/color/parse.js +151 -0
- package/dist/color/serialize.cjs +79 -0
- package/dist/color/serialize.d.cts +11 -0
- package/dist/color/serialize.d.ts +11 -0
- package/dist/color/serialize.js +73 -0
- package/dist/color/sticky.cjs +20 -0
- package/dist/color/sticky.d.cts +6 -0
- package/dist/color/sticky.d.ts +6 -0
- package/dist/color/sticky.js +19 -0
- package/dist/color/types.d.cts +43 -0
- package/dist/color/types.d.ts +43 -0
- package/dist/components/ChromaPanel.cjs +254 -0
- package/dist/components/ChromaPanel.d.cts +47 -0
- package/dist/components/ChromaPanel.d.ts +47 -0
- package/dist/components/ChromaPanel.js +251 -0
- package/dist/components/ColorInput.cjs +128 -0
- package/dist/components/ColorInput.d.cts +19 -0
- package/dist/components/ColorInput.d.ts +19 -0
- package/dist/components/ColorInput.js +127 -0
- package/dist/components/ModeToolbar.cjs +33 -0
- package/dist/components/ModeToolbar.d.cts +10 -0
- package/dist/components/ModeToolbar.d.ts +10 -0
- package/dist/components/ModeToolbar.js +32 -0
- package/dist/components/PanelFooter.cjs +82 -0
- package/dist/components/PanelFooter.d.cts +5 -0
- package/dist/components/PanelFooter.d.ts +5 -0
- package/dist/components/PanelFooter.js +80 -0
- package/dist/components/Popover.cjs +154 -0
- package/dist/components/Popover.d.cts +13 -0
- package/dist/components/Popover.d.ts +13 -0
- package/dist/components/Popover.js +153 -0
- package/dist/contrast.cjs +10 -0
- package/dist/contrast.d.cts +2 -0
- package/dist/contrast.d.ts +2 -0
- package/dist/contrast.js +2 -0
- package/dist/core/context.cjs +30 -0
- package/dist/core/context.d.cts +43 -0
- package/dist/core/context.d.ts +43 -0
- package/dist/core/context.js +26 -0
- package/dist/core/dev.cjs +11 -0
- package/dist/core/dev.js +11 -0
- package/dist/core/store.cjs +43 -0
- package/dist/core/store.d.cts +17 -0
- package/dist/core/store.d.ts +17 -0
- package/dist/core/store.js +44 -0
- package/dist/core/styleInjector.cjs +38 -0
- package/dist/core/styleInjector.d.cts +4 -0
- package/dist/core/styleInjector.d.ts +4 -0
- package/dist/core/styleInjector.js +38 -0
- package/dist/core/useColorStore.cjs +43 -0
- package/dist/core/useColorStore.d.cts +6 -0
- package/dist/core/useColorStore.d.ts +6 -0
- package/dist/core/useColorStore.js +41 -0
- package/dist/core/useFormControl.cjs +87 -0
- package/dist/core/useFormControl.js +82 -0
- package/dist/core/useMediaQuery.cjs +48 -0
- package/dist/core/useMediaQuery.js +46 -0
- package/dist/core/usePointerDrag.cjs +177 -0
- package/dist/core/usePointerDrag.d.cts +35 -0
- package/dist/core/usePointerDrag.d.ts +35 -0
- package/dist/core/usePointerDrag.js +175 -0
- package/dist/core/useScrollFade.cjs +44 -0
- package/dist/core/useScrollFade.js +43 -0
- package/dist/core.cjs +33 -0
- package/dist/core.d.cts +7 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.js +6 -0
- package/dist/data/defaults.cjs +123 -0
- package/dist/data/defaults.d.cts +6 -0
- package/dist/data/defaults.d.ts +6 -0
- package/dist/data/defaults.js +122 -0
- package/dist/data/namedColors.cjs +11 -0
- package/dist/data/namedColors.d.cts +3 -0
- package/dist/data/namedColors.d.ts +3 -0
- package/dist/data/namedColors.js +12 -0
- package/dist/image/extract.cjs +98 -0
- package/dist/image/extract.d.cts +16 -0
- package/dist/image/extract.d.ts +16 -0
- package/dist/image/extract.js +99 -0
- package/dist/image/mmcq.cjs +182 -0
- package/dist/image/mmcq.d.cts +8 -0
- package/dist/image/mmcq.d.ts +8 -0
- package/dist/image/mmcq.js +183 -0
- package/dist/image-worker.js +202 -0
- package/dist/image.cjs +12 -0
- package/dist/image.d.cts +4 -0
- package/dist/image.d.ts +4 -0
- package/dist/image.js +9 -0
- package/dist/index.cjs +119 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +44 -0
- package/dist/modes/gradients.cjs +48 -0
- package/dist/modes/gradients.js +43 -0
- package/dist/modes/image/index.cjs +193 -0
- package/dist/modes/image/index.d.cts +10 -0
- package/dist/modes/image/index.d.ts +10 -0
- package/dist/modes/image/index.js +191 -0
- package/dist/modes/palettes/index.cjs +76 -0
- package/dist/modes/palettes/index.d.cts +6 -0
- package/dist/modes/palettes/index.d.ts +6 -0
- package/dist/modes/palettes/index.js +74 -0
- package/dist/modes/pencils/index.cjs +36 -0
- package/dist/modes/pencils/index.d.cts +6 -0
- package/dist/modes/pencils/index.d.ts +6 -0
- package/dist/modes/pencils/index.js +34 -0
- package/dist/modes/registry.cjs +26 -0
- package/dist/modes/registry.d.cts +13 -0
- package/dist/modes/registry.d.ts +13 -0
- package/dist/modes/registry.js +25 -0
- package/dist/modes/sliders/index.cjs +300 -0
- package/dist/modes/sliders/index.d.cts +6 -0
- package/dist/modes/sliders/index.d.ts +6 -0
- package/dist/modes/sliders/index.js +298 -0
- package/dist/modes/wheel/index.cjs +62 -0
- package/dist/modes/wheel/index.d.cts +6 -0
- package/dist/modes/wheel/index.d.ts +6 -0
- package/dist/modes/wheel/index.js +60 -0
- package/dist/named-colors.cjs +3 -0
- package/dist/named-colors.d.cts +2 -0
- package/dist/named-colors.d.ts +2 -0
- package/dist/named-colors.js +2 -0
- package/dist/palettes.cjs +8 -0
- package/dist/palettes.d.cts +2 -0
- package/dist/palettes.d.ts +2 -0
- package/dist/palettes.js +7 -0
- package/dist/panel.cjs +80 -0
- package/dist/panel.d.cts +27 -0
- package/dist/panel.d.ts +27 -0
- package/dist/panel.js +27 -0
- package/dist/pencils.cjs +8 -0
- package/dist/pencils.d.cts +2 -0
- package/dist/pencils.d.ts +2 -0
- package/dist/pencils.js +7 -0
- package/dist/primitives/AxisInput.cjs +26 -0
- package/dist/primitives/AxisInput.js +25 -0
- package/dist/primitives/ChannelSlider.cjs +94 -0
- package/dist/primitives/ChannelSlider.d.cts +18 -0
- package/dist/primitives/ChannelSlider.d.ts +18 -0
- package/dist/primitives/ChannelSlider.js +93 -0
- package/dist/primitives/ColorArea.cjs +85 -0
- package/dist/primitives/ColorArea.d.cts +8 -0
- package/dist/primitives/ColorArea.d.ts +8 -0
- package/dist/primitives/ColorArea.js +84 -0
- package/dist/primitives/ColorDisc.cjs +95 -0
- package/dist/primitives/ColorDisc.d.cts +8 -0
- package/dist/primitives/ColorDisc.d.ts +8 -0
- package/dist/primitives/ColorDisc.js +94 -0
- package/dist/primitives/ColorField.cjs +68 -0
- package/dist/primitives/ColorField.d.cts +9 -0
- package/dist/primitives/ColorField.d.ts +9 -0
- package/dist/primitives/ColorField.js +67 -0
- package/dist/primitives/NumberField.cjs +65 -0
- package/dist/primitives/NumberField.d.cts +14 -0
- package/dist/primitives/NumberField.d.ts +14 -0
- package/dist/primitives/NumberField.js +64 -0
- package/dist/primitives/SegmentedControl.cjs +66 -0
- package/dist/primitives/SegmentedControl.d.cts +21 -0
- package/dist/primitives/SegmentedControl.d.ts +21 -0
- package/dist/primitives/SegmentedControl.js +65 -0
- package/dist/primitives/Swatch.cjs +22 -0
- package/dist/primitives/Swatch.d.cts +13 -0
- package/dist/primitives/Swatch.d.ts +13 -0
- package/dist/primitives/Swatch.js +21 -0
- package/dist/primitives/SwatchGrid.cjs +63 -0
- package/dist/primitives/SwatchGrid.d.cts +17 -0
- package/dist/primitives/SwatchGrid.d.ts +17 -0
- package/dist/primitives/SwatchGrid.js +62 -0
- package/dist/primitives/icons.cjs +149 -0
- package/dist/primitives/icons.d.cts +9 -0
- package/dist/primitives/icons.d.ts +9 -0
- package/dist/primitives/icons.js +141 -0
- package/dist/primitives/useEyedropper.cjs +30 -0
- package/dist/primitives/useEyedropper.d.cts +7 -0
- package/dist/primitives/useEyedropper.d.ts +7 -0
- package/dist/primitives/useEyedropper.js +29 -0
- package/dist/sliders.cjs +8 -0
- package/dist/sliders.d.cts +2 -0
- package/dist/sliders.d.ts +2 -0
- package/dist/sliders.js +7 -0
- package/dist/style.css +2 -0
- package/dist/styles/css.cjs +4 -0
- package/dist/styles/css.js +5 -0
- package/dist/wheel.cjs +8 -0
- package/dist/wheel.d.cts +2 -0
- package/dist/wheel.d.ts +2 -0
- package/dist/wheel.js +7 -0
- package/package.json +222 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
//#region src/modes/registry.d.ts
|
|
3
|
+
export type ModeId = "wheel" | "sliders" | "palettes" | "image" | "pencils";
|
|
4
|
+
export interface PickerMode {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
icon: React.ComponentType;
|
|
8
|
+
Panel: React.ComponentType;
|
|
9
|
+
}
|
|
10
|
+
export declare function registerMode(mode: PickerMode): void;
|
|
11
|
+
export declare function getMode(id: string): PickerMode | undefined;
|
|
12
|
+
export declare function resolveModes(requested: (string | PickerMode)[]): PickerMode[];
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
//#region src/modes/registry.d.ts
|
|
3
|
+
export type ModeId = "wheel" | "sliders" | "palettes" | "image" | "pencils";
|
|
4
|
+
export interface PickerMode {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
icon: React.ComponentType;
|
|
8
|
+
Panel: React.ComponentType;
|
|
9
|
+
}
|
|
10
|
+
export declare function registerMode(mode: PickerMode): void;
|
|
11
|
+
export declare function getMode(id: string): PickerMode | undefined;
|
|
12
|
+
export declare function resolveModes(requested: (string | PickerMode)[]): PickerMode[];
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { warnOnce } from "../core/dev.js";
|
|
2
|
+
//#region src/modes/registry.ts
|
|
3
|
+
const registry = /* @__PURE__ */ new Map();
|
|
4
|
+
function registerMode(mode) {
|
|
5
|
+
registry.set(mode.id, mode);
|
|
6
|
+
}
|
|
7
|
+
function getMode(id) {
|
|
8
|
+
return registry.get(id);
|
|
9
|
+
}
|
|
10
|
+
function resolveModes(requested) {
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const entry of requested) {
|
|
13
|
+
if (typeof entry !== "string") {
|
|
14
|
+
out.push(entry);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const found = registry.get(entry);
|
|
18
|
+
if (found !== void 0) out.push(found);
|
|
19
|
+
else warnOnce(`unknown mode "${entry}". Known modes: ${Array.from(registry.keys()).join(", ")}.`);
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { getMode, registerMode, resolveModes };
|
|
25
|
+
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_context = require("../../core/context.cjs");
|
|
4
|
+
const require_convert = require("../../color/convert.cjs");
|
|
5
|
+
const require_ChannelSlider = require("../../primitives/ChannelSlider.cjs");
|
|
6
|
+
const require_ColorField = require("../../primitives/ColorField.cjs");
|
|
7
|
+
const require_icons = require("../../primitives/icons.cjs");
|
|
8
|
+
const require_gradients = require("../gradients.cjs");
|
|
9
|
+
const require_sticky = require("../../color/sticky.cjs");
|
|
10
|
+
const require_NumberField = require("../../primitives/NumberField.cjs");
|
|
11
|
+
const require_SegmentedControl = require("../../primitives/SegmentedControl.cjs");
|
|
12
|
+
let react = require("react");
|
|
13
|
+
react = require_runtime.__toESM(react, 1);
|
|
14
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
15
|
+
//#region src/modes/sliders/index.tsx
|
|
16
|
+
const MODELS = [
|
|
17
|
+
{
|
|
18
|
+
id: "rgb",
|
|
19
|
+
label: "RGB",
|
|
20
|
+
content: "RGB"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "hsl",
|
|
24
|
+
label: "HSL",
|
|
25
|
+
content: "HSL"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "hsb",
|
|
29
|
+
label: "HSB",
|
|
30
|
+
content: "HSB"
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
function writeRgb(key) {
|
|
34
|
+
return (value, current) => {
|
|
35
|
+
const rgba = require_convert.hsvaToRgba(current);
|
|
36
|
+
return require_sticky.ingest(require_convert.rgbaToHsva({
|
|
37
|
+
...rgba,
|
|
38
|
+
[key]: value
|
|
39
|
+
}), current);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function readRgb(key) {
|
|
43
|
+
return (c) => Math.round(require_convert.hsvaToRgba(c)[key]);
|
|
44
|
+
}
|
|
45
|
+
function SlidersPanel() {
|
|
46
|
+
const { options } = require_context.usePanel();
|
|
47
|
+
const [model, setModel] = react.useState("rgb");
|
|
48
|
+
const alpha = options.showAlpha ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
49
|
+
label: "Opacity",
|
|
50
|
+
shortLabel: "A",
|
|
51
|
+
min: 0,
|
|
52
|
+
max: 100,
|
|
53
|
+
read: (c) => c.a * 100,
|
|
54
|
+
write: (v, c) => ({
|
|
55
|
+
...c,
|
|
56
|
+
a: v / 100
|
|
57
|
+
}),
|
|
58
|
+
gradient: require_gradients.alphaTrack,
|
|
59
|
+
channel: "alpha",
|
|
60
|
+
formatValue: (v) => `${Math.round(v)} percent`
|
|
61
|
+
}) : null;
|
|
62
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
63
|
+
className: "cp-panel",
|
|
64
|
+
children: [
|
|
65
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SegmentedControl.SegmentedControl, {
|
|
66
|
+
size: "sm",
|
|
67
|
+
ariaLabel: "Colour model",
|
|
68
|
+
items: MODELS,
|
|
69
|
+
value: model,
|
|
70
|
+
onChange: (id) => setModel(id)
|
|
71
|
+
}),
|
|
72
|
+
model === "rgb" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
73
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
74
|
+
label: "Red",
|
|
75
|
+
shortLabel: "R",
|
|
76
|
+
min: 0,
|
|
77
|
+
max: 255,
|
|
78
|
+
read: readRgb("r"),
|
|
79
|
+
write: writeRgb("r"),
|
|
80
|
+
gradient: require_gradients.redTrack,
|
|
81
|
+
channel: "red"
|
|
82
|
+
}),
|
|
83
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
84
|
+
label: "Green",
|
|
85
|
+
shortLabel: "G",
|
|
86
|
+
min: 0,
|
|
87
|
+
max: 255,
|
|
88
|
+
read: readRgb("g"),
|
|
89
|
+
write: writeRgb("g"),
|
|
90
|
+
gradient: require_gradients.greenTrack,
|
|
91
|
+
channel: "green"
|
|
92
|
+
}),
|
|
93
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
94
|
+
label: "Blue",
|
|
95
|
+
shortLabel: "B",
|
|
96
|
+
min: 0,
|
|
97
|
+
max: 255,
|
|
98
|
+
read: readRgb("b"),
|
|
99
|
+
write: writeRgb("b"),
|
|
100
|
+
gradient: require_gradients.blueTrack,
|
|
101
|
+
channel: "blue"
|
|
102
|
+
}),
|
|
103
|
+
alpha,
|
|
104
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
105
|
+
className: "cp-fields",
|
|
106
|
+
children: [
|
|
107
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
108
|
+
label: "R",
|
|
109
|
+
min: 0,
|
|
110
|
+
max: 255,
|
|
111
|
+
read: readRgb("r"),
|
|
112
|
+
write: writeRgb("r")
|
|
113
|
+
}),
|
|
114
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
115
|
+
label: "G",
|
|
116
|
+
min: 0,
|
|
117
|
+
max: 255,
|
|
118
|
+
read: readRgb("g"),
|
|
119
|
+
write: writeRgb("g")
|
|
120
|
+
}),
|
|
121
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
122
|
+
label: "B",
|
|
123
|
+
min: 0,
|
|
124
|
+
max: 255,
|
|
125
|
+
read: readRgb("b"),
|
|
126
|
+
write: writeRgb("b")
|
|
127
|
+
})
|
|
128
|
+
]
|
|
129
|
+
})
|
|
130
|
+
] }),
|
|
131
|
+
model === "hsl" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
132
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
133
|
+
label: "Hue",
|
|
134
|
+
shortLabel: "H",
|
|
135
|
+
min: 0,
|
|
136
|
+
max: 360,
|
|
137
|
+
read: (c) => Math.round(c.h),
|
|
138
|
+
write: (h, c) => ({
|
|
139
|
+
...c,
|
|
140
|
+
h
|
|
141
|
+
}),
|
|
142
|
+
channel: "hue",
|
|
143
|
+
formatValue: (v) => `${Math.round(v)} degrees`
|
|
144
|
+
}),
|
|
145
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
146
|
+
label: "Saturation",
|
|
147
|
+
shortLabel: "S",
|
|
148
|
+
min: 0,
|
|
149
|
+
max: 100,
|
|
150
|
+
read: (c) => Math.round(require_convert.hsvaToHsla(c).s),
|
|
151
|
+
write: (s, c) => require_sticky.ingest(require_convert.hslaToHsva({
|
|
152
|
+
...require_convert.hsvaToHsla(c),
|
|
153
|
+
s
|
|
154
|
+
}), c),
|
|
155
|
+
gradient: require_gradients.saturationTrack,
|
|
156
|
+
channel: "saturation"
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
159
|
+
label: "Lightness",
|
|
160
|
+
shortLabel: "L",
|
|
161
|
+
min: 0,
|
|
162
|
+
max: 100,
|
|
163
|
+
read: (c) => Math.round(require_convert.hsvaToHsla(c).l),
|
|
164
|
+
write: (l, c) => require_sticky.ingest(require_convert.hslaToHsva({
|
|
165
|
+
...require_convert.hsvaToHsla(c),
|
|
166
|
+
l
|
|
167
|
+
}), c),
|
|
168
|
+
gradient: require_gradients.lightnessTrack,
|
|
169
|
+
channel: "lightness"
|
|
170
|
+
}),
|
|
171
|
+
alpha,
|
|
172
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
173
|
+
className: "cp-fields",
|
|
174
|
+
children: [
|
|
175
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
176
|
+
label: "H",
|
|
177
|
+
min: 0,
|
|
178
|
+
max: 360,
|
|
179
|
+
read: (c) => Math.round(c.h),
|
|
180
|
+
write: (h, c) => ({
|
|
181
|
+
...c,
|
|
182
|
+
h
|
|
183
|
+
})
|
|
184
|
+
}),
|
|
185
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
186
|
+
label: "S",
|
|
187
|
+
min: 0,
|
|
188
|
+
max: 100,
|
|
189
|
+
read: (c) => Math.round(require_convert.hsvaToHsla(c).s),
|
|
190
|
+
write: (s, c) => require_sticky.ingest(require_convert.hslaToHsva({
|
|
191
|
+
...require_convert.hsvaToHsla(c),
|
|
192
|
+
s
|
|
193
|
+
}), c)
|
|
194
|
+
}),
|
|
195
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
196
|
+
label: "L",
|
|
197
|
+
min: 0,
|
|
198
|
+
max: 100,
|
|
199
|
+
read: (c) => Math.round(require_convert.hsvaToHsla(c).l),
|
|
200
|
+
write: (l, c) => require_sticky.ingest(require_convert.hslaToHsva({
|
|
201
|
+
...require_convert.hsvaToHsla(c),
|
|
202
|
+
l
|
|
203
|
+
}), c)
|
|
204
|
+
})
|
|
205
|
+
]
|
|
206
|
+
})
|
|
207
|
+
] }),
|
|
208
|
+
model === "hsb" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
209
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
210
|
+
label: "Hue",
|
|
211
|
+
shortLabel: "H",
|
|
212
|
+
min: 0,
|
|
213
|
+
max: 360,
|
|
214
|
+
read: (c) => Math.round(c.h),
|
|
215
|
+
write: (h, c) => ({
|
|
216
|
+
...c,
|
|
217
|
+
h
|
|
218
|
+
}),
|
|
219
|
+
channel: "hue",
|
|
220
|
+
formatValue: (v) => `${Math.round(v)} degrees`
|
|
221
|
+
}),
|
|
222
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
223
|
+
label: "Saturation",
|
|
224
|
+
shortLabel: "S",
|
|
225
|
+
min: 0,
|
|
226
|
+
max: 100,
|
|
227
|
+
read: (c) => Math.round(c.s),
|
|
228
|
+
write: (s, c) => ({
|
|
229
|
+
...c,
|
|
230
|
+
s
|
|
231
|
+
}),
|
|
232
|
+
gradient: require_gradients.saturationTrack,
|
|
233
|
+
channel: "saturation"
|
|
234
|
+
}),
|
|
235
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ChannelSlider.ChannelSlider, {
|
|
236
|
+
label: "Brightness",
|
|
237
|
+
shortLabel: "B",
|
|
238
|
+
min: 0,
|
|
239
|
+
max: 100,
|
|
240
|
+
read: (c) => Math.round(c.v),
|
|
241
|
+
write: (v, c) => ({
|
|
242
|
+
...c,
|
|
243
|
+
v
|
|
244
|
+
}),
|
|
245
|
+
gradient: require_gradients.brightnessTrack,
|
|
246
|
+
channel: "brightness"
|
|
247
|
+
}),
|
|
248
|
+
alpha,
|
|
249
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
250
|
+
className: "cp-fields",
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
253
|
+
label: "H",
|
|
254
|
+
min: 0,
|
|
255
|
+
max: 360,
|
|
256
|
+
read: (c) => Math.round(c.h),
|
|
257
|
+
write: (h, c) => ({
|
|
258
|
+
...c,
|
|
259
|
+
h
|
|
260
|
+
})
|
|
261
|
+
}),
|
|
262
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
263
|
+
label: "S",
|
|
264
|
+
min: 0,
|
|
265
|
+
max: 100,
|
|
266
|
+
read: (c) => Math.round(c.s),
|
|
267
|
+
write: (s, c) => ({
|
|
268
|
+
...c,
|
|
269
|
+
s
|
|
270
|
+
})
|
|
271
|
+
}),
|
|
272
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_NumberField.NumberField, {
|
|
273
|
+
label: "B",
|
|
274
|
+
min: 0,
|
|
275
|
+
max: 100,
|
|
276
|
+
read: (c) => Math.round(c.v),
|
|
277
|
+
write: (v, c) => ({
|
|
278
|
+
...c,
|
|
279
|
+
v
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
]
|
|
283
|
+
})
|
|
284
|
+
] }),
|
|
285
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
286
|
+
className: "cp-fields",
|
|
287
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_ColorField.ColorField, { withAlpha: options.showAlpha })
|
|
288
|
+
})
|
|
289
|
+
]
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
const slidersMode = {
|
|
293
|
+
id: "sliders",
|
|
294
|
+
label: "Sliders",
|
|
295
|
+
icon: require_icons.SlidersIcon,
|
|
296
|
+
Panel: SlidersPanel
|
|
297
|
+
};
|
|
298
|
+
//#endregion
|
|
299
|
+
exports.SlidersPanel = SlidersPanel;
|
|
300
|
+
exports.slidersMode = slidersMode;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { usePanel } from "../../core/context.js";
|
|
3
|
+
import { hslaToHsva, hsvaToHsla, hsvaToRgba, rgbaToHsva } from "../../color/convert.js";
|
|
4
|
+
import { ChannelSlider } from "../../primitives/ChannelSlider.js";
|
|
5
|
+
import { ColorField } from "../../primitives/ColorField.js";
|
|
6
|
+
import { SlidersIcon } from "../../primitives/icons.js";
|
|
7
|
+
import { alphaTrack, blueTrack, brightnessTrack, greenTrack, lightnessTrack, redTrack, saturationTrack } from "../gradients.js";
|
|
8
|
+
import { ingest } from "../../color/sticky.js";
|
|
9
|
+
import { NumberField } from "../../primitives/NumberField.js";
|
|
10
|
+
import { SegmentedControl } from "../../primitives/SegmentedControl.js";
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
//#region src/modes/sliders/index.tsx
|
|
14
|
+
const MODELS = [
|
|
15
|
+
{
|
|
16
|
+
id: "rgb",
|
|
17
|
+
label: "RGB",
|
|
18
|
+
content: "RGB"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "hsl",
|
|
22
|
+
label: "HSL",
|
|
23
|
+
content: "HSL"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "hsb",
|
|
27
|
+
label: "HSB",
|
|
28
|
+
content: "HSB"
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
function writeRgb(key) {
|
|
32
|
+
return (value, current) => {
|
|
33
|
+
const rgba = hsvaToRgba(current);
|
|
34
|
+
return ingest(rgbaToHsva({
|
|
35
|
+
...rgba,
|
|
36
|
+
[key]: value
|
|
37
|
+
}), current);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function readRgb(key) {
|
|
41
|
+
return (c) => Math.round(hsvaToRgba(c)[key]);
|
|
42
|
+
}
|
|
43
|
+
function SlidersPanel() {
|
|
44
|
+
const { options } = usePanel();
|
|
45
|
+
const [model, setModel] = React.useState("rgb");
|
|
46
|
+
const alpha = options.showAlpha ? /* @__PURE__ */ jsx(ChannelSlider, {
|
|
47
|
+
label: "Opacity",
|
|
48
|
+
shortLabel: "A",
|
|
49
|
+
min: 0,
|
|
50
|
+
max: 100,
|
|
51
|
+
read: (c) => c.a * 100,
|
|
52
|
+
write: (v, c) => ({
|
|
53
|
+
...c,
|
|
54
|
+
a: v / 100
|
|
55
|
+
}),
|
|
56
|
+
gradient: alphaTrack,
|
|
57
|
+
channel: "alpha",
|
|
58
|
+
formatValue: (v) => `${Math.round(v)} percent`
|
|
59
|
+
}) : null;
|
|
60
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
61
|
+
className: "cp-panel",
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
64
|
+
size: "sm",
|
|
65
|
+
ariaLabel: "Colour model",
|
|
66
|
+
items: MODELS,
|
|
67
|
+
value: model,
|
|
68
|
+
onChange: (id) => setModel(id)
|
|
69
|
+
}),
|
|
70
|
+
model === "rgb" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
71
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
72
|
+
label: "Red",
|
|
73
|
+
shortLabel: "R",
|
|
74
|
+
min: 0,
|
|
75
|
+
max: 255,
|
|
76
|
+
read: readRgb("r"),
|
|
77
|
+
write: writeRgb("r"),
|
|
78
|
+
gradient: redTrack,
|
|
79
|
+
channel: "red"
|
|
80
|
+
}),
|
|
81
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
82
|
+
label: "Green",
|
|
83
|
+
shortLabel: "G",
|
|
84
|
+
min: 0,
|
|
85
|
+
max: 255,
|
|
86
|
+
read: readRgb("g"),
|
|
87
|
+
write: writeRgb("g"),
|
|
88
|
+
gradient: greenTrack,
|
|
89
|
+
channel: "green"
|
|
90
|
+
}),
|
|
91
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
92
|
+
label: "Blue",
|
|
93
|
+
shortLabel: "B",
|
|
94
|
+
min: 0,
|
|
95
|
+
max: 255,
|
|
96
|
+
read: readRgb("b"),
|
|
97
|
+
write: writeRgb("b"),
|
|
98
|
+
gradient: blueTrack,
|
|
99
|
+
channel: "blue"
|
|
100
|
+
}),
|
|
101
|
+
alpha,
|
|
102
|
+
/* @__PURE__ */ jsxs("div", {
|
|
103
|
+
className: "cp-fields",
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
106
|
+
label: "R",
|
|
107
|
+
min: 0,
|
|
108
|
+
max: 255,
|
|
109
|
+
read: readRgb("r"),
|
|
110
|
+
write: writeRgb("r")
|
|
111
|
+
}),
|
|
112
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
113
|
+
label: "G",
|
|
114
|
+
min: 0,
|
|
115
|
+
max: 255,
|
|
116
|
+
read: readRgb("g"),
|
|
117
|
+
write: writeRgb("g")
|
|
118
|
+
}),
|
|
119
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
120
|
+
label: "B",
|
|
121
|
+
min: 0,
|
|
122
|
+
max: 255,
|
|
123
|
+
read: readRgb("b"),
|
|
124
|
+
write: writeRgb("b")
|
|
125
|
+
})
|
|
126
|
+
]
|
|
127
|
+
})
|
|
128
|
+
] }),
|
|
129
|
+
model === "hsl" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
130
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
131
|
+
label: "Hue",
|
|
132
|
+
shortLabel: "H",
|
|
133
|
+
min: 0,
|
|
134
|
+
max: 360,
|
|
135
|
+
read: (c) => Math.round(c.h),
|
|
136
|
+
write: (h, c) => ({
|
|
137
|
+
...c,
|
|
138
|
+
h
|
|
139
|
+
}),
|
|
140
|
+
channel: "hue",
|
|
141
|
+
formatValue: (v) => `${Math.round(v)} degrees`
|
|
142
|
+
}),
|
|
143
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
144
|
+
label: "Saturation",
|
|
145
|
+
shortLabel: "S",
|
|
146
|
+
min: 0,
|
|
147
|
+
max: 100,
|
|
148
|
+
read: (c) => Math.round(hsvaToHsla(c).s),
|
|
149
|
+
write: (s, c) => ingest(hslaToHsva({
|
|
150
|
+
...hsvaToHsla(c),
|
|
151
|
+
s
|
|
152
|
+
}), c),
|
|
153
|
+
gradient: saturationTrack,
|
|
154
|
+
channel: "saturation"
|
|
155
|
+
}),
|
|
156
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
157
|
+
label: "Lightness",
|
|
158
|
+
shortLabel: "L",
|
|
159
|
+
min: 0,
|
|
160
|
+
max: 100,
|
|
161
|
+
read: (c) => Math.round(hsvaToHsla(c).l),
|
|
162
|
+
write: (l, c) => ingest(hslaToHsva({
|
|
163
|
+
...hsvaToHsla(c),
|
|
164
|
+
l
|
|
165
|
+
}), c),
|
|
166
|
+
gradient: lightnessTrack,
|
|
167
|
+
channel: "lightness"
|
|
168
|
+
}),
|
|
169
|
+
alpha,
|
|
170
|
+
/* @__PURE__ */ jsxs("div", {
|
|
171
|
+
className: "cp-fields",
|
|
172
|
+
children: [
|
|
173
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
174
|
+
label: "H",
|
|
175
|
+
min: 0,
|
|
176
|
+
max: 360,
|
|
177
|
+
read: (c) => Math.round(c.h),
|
|
178
|
+
write: (h, c) => ({
|
|
179
|
+
...c,
|
|
180
|
+
h
|
|
181
|
+
})
|
|
182
|
+
}),
|
|
183
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
184
|
+
label: "S",
|
|
185
|
+
min: 0,
|
|
186
|
+
max: 100,
|
|
187
|
+
read: (c) => Math.round(hsvaToHsla(c).s),
|
|
188
|
+
write: (s, c) => ingest(hslaToHsva({
|
|
189
|
+
...hsvaToHsla(c),
|
|
190
|
+
s
|
|
191
|
+
}), c)
|
|
192
|
+
}),
|
|
193
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
194
|
+
label: "L",
|
|
195
|
+
min: 0,
|
|
196
|
+
max: 100,
|
|
197
|
+
read: (c) => Math.round(hsvaToHsla(c).l),
|
|
198
|
+
write: (l, c) => ingest(hslaToHsva({
|
|
199
|
+
...hsvaToHsla(c),
|
|
200
|
+
l
|
|
201
|
+
}), c)
|
|
202
|
+
})
|
|
203
|
+
]
|
|
204
|
+
})
|
|
205
|
+
] }),
|
|
206
|
+
model === "hsb" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
207
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
208
|
+
label: "Hue",
|
|
209
|
+
shortLabel: "H",
|
|
210
|
+
min: 0,
|
|
211
|
+
max: 360,
|
|
212
|
+
read: (c) => Math.round(c.h),
|
|
213
|
+
write: (h, c) => ({
|
|
214
|
+
...c,
|
|
215
|
+
h
|
|
216
|
+
}),
|
|
217
|
+
channel: "hue",
|
|
218
|
+
formatValue: (v) => `${Math.round(v)} degrees`
|
|
219
|
+
}),
|
|
220
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
221
|
+
label: "Saturation",
|
|
222
|
+
shortLabel: "S",
|
|
223
|
+
min: 0,
|
|
224
|
+
max: 100,
|
|
225
|
+
read: (c) => Math.round(c.s),
|
|
226
|
+
write: (s, c) => ({
|
|
227
|
+
...c,
|
|
228
|
+
s
|
|
229
|
+
}),
|
|
230
|
+
gradient: saturationTrack,
|
|
231
|
+
channel: "saturation"
|
|
232
|
+
}),
|
|
233
|
+
/* @__PURE__ */ jsx(ChannelSlider, {
|
|
234
|
+
label: "Brightness",
|
|
235
|
+
shortLabel: "B",
|
|
236
|
+
min: 0,
|
|
237
|
+
max: 100,
|
|
238
|
+
read: (c) => Math.round(c.v),
|
|
239
|
+
write: (v, c) => ({
|
|
240
|
+
...c,
|
|
241
|
+
v
|
|
242
|
+
}),
|
|
243
|
+
gradient: brightnessTrack,
|
|
244
|
+
channel: "brightness"
|
|
245
|
+
}),
|
|
246
|
+
alpha,
|
|
247
|
+
/* @__PURE__ */ jsxs("div", {
|
|
248
|
+
className: "cp-fields",
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
251
|
+
label: "H",
|
|
252
|
+
min: 0,
|
|
253
|
+
max: 360,
|
|
254
|
+
read: (c) => Math.round(c.h),
|
|
255
|
+
write: (h, c) => ({
|
|
256
|
+
...c,
|
|
257
|
+
h
|
|
258
|
+
})
|
|
259
|
+
}),
|
|
260
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
261
|
+
label: "S",
|
|
262
|
+
min: 0,
|
|
263
|
+
max: 100,
|
|
264
|
+
read: (c) => Math.round(c.s),
|
|
265
|
+
write: (s, c) => ({
|
|
266
|
+
...c,
|
|
267
|
+
s
|
|
268
|
+
})
|
|
269
|
+
}),
|
|
270
|
+
/* @__PURE__ */ jsx(NumberField, {
|
|
271
|
+
label: "B",
|
|
272
|
+
min: 0,
|
|
273
|
+
max: 100,
|
|
274
|
+
read: (c) => Math.round(c.v),
|
|
275
|
+
write: (v, c) => ({
|
|
276
|
+
...c,
|
|
277
|
+
v
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
]
|
|
281
|
+
})
|
|
282
|
+
] }),
|
|
283
|
+
/* @__PURE__ */ jsx("div", {
|
|
284
|
+
className: "cp-fields",
|
|
285
|
+
children: /* @__PURE__ */ jsx(ColorField, { withAlpha: options.showAlpha })
|
|
286
|
+
})
|
|
287
|
+
]
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
const slidersMode = {
|
|
291
|
+
id: "sliders",
|
|
292
|
+
label: "Sliders",
|
|
293
|
+
icon: SlidersIcon,
|
|
294
|
+
Panel: SlidersPanel
|
|
295
|
+
};
|
|
296
|
+
//#endregion
|
|
297
|
+
export { SlidersPanel, slidersMode };
|
|
298
|
+
|