@pixerate/editor-react 0.95.0 → 0.96.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/README.md +2 -0
- package/dist/animation-editor/index.cjs +1240 -195
- package/dist/animation-editor/index.js +4 -2
- package/dist/canvas/index.cjs +1418 -373
- package/dist/canvas/index.js +4 -2
- package/dist/chunk-3I7FOSLF.js +988 -0
- package/dist/{chunk-OTGJEYHV.js → chunk-5LFQ2UQZ.js} +75 -68
- package/dist/{chunk-5R67YSSD.js → chunk-GLSOQNQR.js} +1 -1
- package/dist/{chunk-6YRSQW2V.js → chunk-IY6YOY5B.js} +1 -1
- package/dist/chunk-KIRIU53A.js +72 -0
- package/dist/color/ColorPicker.d.cts +30 -0
- package/dist/color/ColorPicker.d.ts +30 -0
- package/dist/color/DualColorPicker.d.cts +29 -0
- package/dist/color/DualColorPicker.d.ts +29 -0
- package/dist/color/index.cjs +1067 -0
- package/dist/color/index.d.cts +7 -0
- package/dist/color/index.d.ts +7 -0
- package/dist/color/index.js +14 -0
- package/dist/color/useColorScheme.d.cts +16 -0
- package/dist/color/useColorScheme.d.ts +16 -0
- package/dist/effects/index.cjs +1169 -124
- package/dist/effects/index.js +4 -2
- package/dist/gradient/FillPicker.d.cts +27 -0
- package/dist/gradient/FillPicker.d.ts +27 -0
- package/dist/gradient/GradientEditor.d.cts +21 -0
- package/dist/gradient/GradientEditor.d.ts +21 -0
- package/dist/gradient/index.cjs +1601 -0
- package/dist/gradient/index.d.cts +6 -0
- package/dist/gradient/index.d.ts +6 -0
- package/dist/gradient/index.js +617 -0
- package/dist/gradient/useGradientController.d.cts +10 -0
- package/dist/gradient/useGradientController.d.ts +10 -0
- package/dist/image-editor/index.cjs +1742 -697
- package/dist/image-editor/index.js +5 -3
- package/dist/index.cjs +2160 -1115
- package/dist/index.js +5 -3
- package/dist/paint-editor/index.cjs +1233 -188
- package/dist/paint-editor/index.js +4 -2
- package/dist/parameters/fields.d.cts +1 -1
- package/dist/parameters/fields.d.ts +1 -1
- package/dist/parameters/index.cjs +1218 -173
- package/dist/parameters/index.js +3 -1
- package/dist/vector/index.cjs +1219 -174
- package/dist/vector/index.js +4 -2
- package/dist/video-editor/index.cjs +1230 -185
- package/dist/video-editor/index.js +4 -2
- package/package.json +29 -3
|
@@ -0,0 +1,988 @@
|
|
|
1
|
+
// src/color/ColorPicker.tsx
|
|
2
|
+
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
contrastRatio,
|
|
5
|
+
formatHex,
|
|
6
|
+
inSrgbGamut,
|
|
7
|
+
parseColor,
|
|
8
|
+
pickerAlphaBackground,
|
|
9
|
+
pickerAreaBackground,
|
|
10
|
+
pickerKeyStep,
|
|
11
|
+
pickerStateFromAlpha,
|
|
12
|
+
pickerStateFromArea,
|
|
13
|
+
pickerStateFromColor,
|
|
14
|
+
pickerStateFromHue,
|
|
15
|
+
pickerStateToHex,
|
|
16
|
+
pushRecentColor,
|
|
17
|
+
PICKER_HUE_BACKGROUND
|
|
18
|
+
} from "@pixerate/editor/color";
|
|
19
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
20
|
+
var LOCAL_STORAGE_KEY = "pixerate:color:recent";
|
|
21
|
+
function readLocalRecents() {
|
|
22
|
+
try {
|
|
23
|
+
if (typeof localStorage === "undefined") return [];
|
|
24
|
+
const raw = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
25
|
+
if (!raw) return [];
|
|
26
|
+
const parsed = JSON.parse(raw);
|
|
27
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
28
|
+
} catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function writeLocalRecents(list) {
|
|
33
|
+
try {
|
|
34
|
+
if (typeof localStorage !== "undefined") {
|
|
35
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(list));
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var CHECKERBOARD_BG = "repeating-conic-gradient(var(--pixerate-checker-a, #d4d4d8) 0 25%, var(--pixerate-checker-b, #ffffff) 0 50%)";
|
|
41
|
+
var DEFAULT_PICKER_STATE = { h: 0, s: 1, v: 1, alpha: 1 };
|
|
42
|
+
var ColorPicker = ({
|
|
43
|
+
value,
|
|
44
|
+
onChange,
|
|
45
|
+
onGestureStart,
|
|
46
|
+
onGestureEnd,
|
|
47
|
+
alpha = false,
|
|
48
|
+
swatches,
|
|
49
|
+
recent: controlledRecent,
|
|
50
|
+
onRecentChange,
|
|
51
|
+
contrastAgainst,
|
|
52
|
+
disabled = false,
|
|
53
|
+
className,
|
|
54
|
+
id,
|
|
55
|
+
"aria-label": ariaLabel = "Color picker"
|
|
56
|
+
}) => {
|
|
57
|
+
const generatedId = useId();
|
|
58
|
+
const pickerId = id || generatedId;
|
|
59
|
+
const [pickerState, setPickerState] = useState(
|
|
60
|
+
() => pickerStateFromColor(value) ?? DEFAULT_PICKER_STATE
|
|
61
|
+
);
|
|
62
|
+
const stateRef = useRef(pickerState);
|
|
63
|
+
stateRef.current = pickerState;
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const next = pickerStateFromColor(value, stateRef.current);
|
|
66
|
+
if (next) {
|
|
67
|
+
setPickerState(next);
|
|
68
|
+
}
|
|
69
|
+
}, [value]);
|
|
70
|
+
const [internalRecent, setInternalRecent] = useState(
|
|
71
|
+
() => controlledRecent ? [] : readLocalRecents()
|
|
72
|
+
);
|
|
73
|
+
const activeRecent = controlledRecent ?? internalRecent;
|
|
74
|
+
const recordRecent = useCallback(
|
|
75
|
+
(color) => {
|
|
76
|
+
const updated = pushRecentColor(activeRecent, color, 12);
|
|
77
|
+
if (!controlledRecent) {
|
|
78
|
+
setInternalRecent(updated);
|
|
79
|
+
writeLocalRecents(updated);
|
|
80
|
+
}
|
|
81
|
+
onRecentChange?.(updated);
|
|
82
|
+
},
|
|
83
|
+
[activeRecent, controlledRecent, onRecentChange]
|
|
84
|
+
);
|
|
85
|
+
const [textDraft, setTextDraft] = useState(value);
|
|
86
|
+
const [isInvalid, setIsInvalid] = useState(false);
|
|
87
|
+
const [isClipped, setIsClipped] = useState(false);
|
|
88
|
+
const isTypingRef = useRef(false);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!isTypingRef.current) {
|
|
91
|
+
setTextDraft(value);
|
|
92
|
+
setIsInvalid(false);
|
|
93
|
+
const parsed = parseColor(value);
|
|
94
|
+
setIsClipped(Boolean(parsed && !inSrgbGamut(parsed)));
|
|
95
|
+
}
|
|
96
|
+
}, [value]);
|
|
97
|
+
const [hasEyeDropper, setHasEyeDropper] = useState(false);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
setHasEyeDropper(typeof window !== "undefined" && "EyeDropper" in window);
|
|
100
|
+
}, []);
|
|
101
|
+
const emitColorChange = useCallback(
|
|
102
|
+
(nextState) => {
|
|
103
|
+
setPickerState(nextState);
|
|
104
|
+
const hex = pickerStateToHex(nextState, alpha);
|
|
105
|
+
onChange(hex);
|
|
106
|
+
},
|
|
107
|
+
[alpha, onChange]
|
|
108
|
+
);
|
|
109
|
+
const latest = useRef({ emitColorChange, recordRecent, onGestureEnd, alpha });
|
|
110
|
+
latest.current = { emitColorChange, recordRecent, onGestureEnd, alpha };
|
|
111
|
+
const endDragRef = useRef(null);
|
|
112
|
+
useEffect(() => () => endDragRef.current?.(), []);
|
|
113
|
+
const startDrag = (e, next) => {
|
|
114
|
+
if (disabled) return;
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
endDragRef.current?.();
|
|
117
|
+
onGestureStart?.();
|
|
118
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
119
|
+
const update = (clientX, clientY) => {
|
|
120
|
+
const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
121
|
+
const y = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
|
|
122
|
+
latest.current.emitColorChange(next(stateRef.current, x, y));
|
|
123
|
+
};
|
|
124
|
+
update(e.clientX, e.clientY);
|
|
125
|
+
const onPointerMove = (ev) => update(ev.clientX, ev.clientY);
|
|
126
|
+
const end = () => {
|
|
127
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
128
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
129
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
130
|
+
endDragRef.current = null;
|
|
131
|
+
latest.current.onGestureEnd?.();
|
|
132
|
+
};
|
|
133
|
+
const onPointerUp = () => {
|
|
134
|
+
end();
|
|
135
|
+
latest.current.recordRecent(pickerStateToHex(stateRef.current, latest.current.alpha));
|
|
136
|
+
};
|
|
137
|
+
endDragRef.current = end;
|
|
138
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
139
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
140
|
+
window.addEventListener("pointercancel", onPointerUp);
|
|
141
|
+
};
|
|
142
|
+
const handleAreaPointerDown = (e) => startDrag(e, (state, x, y) => pickerStateFromArea(state, x, y));
|
|
143
|
+
const handleHuePointerDown = (e) => startDrag(e, (state, x) => pickerStateFromHue(state, x));
|
|
144
|
+
const handleAlphaPointerDown = (e) => startDrag(e, (state, x) => pickerStateFromAlpha(state, x));
|
|
145
|
+
const handleAreaKeyDown = (e) => {
|
|
146
|
+
if (disabled) return;
|
|
147
|
+
const next = pickerKeyStep(pickerState, "area", e.key, e.shiftKey);
|
|
148
|
+
if (next) {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
emitColorChange(next);
|
|
151
|
+
recordRecent(pickerStateToHex(next, alpha));
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const handleHueKeyDown = (e) => {
|
|
155
|
+
if (disabled) return;
|
|
156
|
+
const next = pickerKeyStep(pickerState, "hue", e.key, e.shiftKey);
|
|
157
|
+
if (next) {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
emitColorChange(next);
|
|
160
|
+
recordRecent(pickerStateToHex(next, alpha));
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const handleAlphaKeyDown = (e) => {
|
|
164
|
+
if (disabled) return;
|
|
165
|
+
const next = pickerKeyStep(pickerState, "alpha", e.key, e.shiftKey);
|
|
166
|
+
if (next) {
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
emitColorChange(next);
|
|
169
|
+
recordRecent(pickerStateToHex(next, alpha));
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const commitTextInput = (inputElement) => {
|
|
173
|
+
isTypingRef.current = false;
|
|
174
|
+
const parsed = parseColor(textDraft);
|
|
175
|
+
if (parsed) {
|
|
176
|
+
setIsInvalid(false);
|
|
177
|
+
setIsClipped(!inSrgbGamut(parsed));
|
|
178
|
+
const formatted = formatHex(parsed);
|
|
179
|
+
onChange(formatted);
|
|
180
|
+
recordRecent(formatted);
|
|
181
|
+
} else {
|
|
182
|
+
setIsInvalid(true);
|
|
183
|
+
setTextDraft(value);
|
|
184
|
+
if (inputElement) {
|
|
185
|
+
inputElement.value = value;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const handleTextKeyDown = (e) => {
|
|
190
|
+
if (e.key === "Enter") {
|
|
191
|
+
e.preventDefault();
|
|
192
|
+
commitTextInput(e.currentTarget);
|
|
193
|
+
} else if (e.key === "Escape") {
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
isTypingRef.current = false;
|
|
196
|
+
setIsInvalid(false);
|
|
197
|
+
setTextDraft(value);
|
|
198
|
+
e.currentTarget.value = value;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const handleEyeDropper = async () => {
|
|
202
|
+
if (disabled || !hasEyeDropper) return;
|
|
203
|
+
try {
|
|
204
|
+
const EyeDropperClass = window.EyeDropper;
|
|
205
|
+
const eyeDropper = new EyeDropperClass();
|
|
206
|
+
const res = await eyeDropper.open();
|
|
207
|
+
if (res?.sRGBHex) {
|
|
208
|
+
onChange(res.sRGBHex);
|
|
209
|
+
recordRecent(res.sRGBHex);
|
|
210
|
+
}
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const contrastResult = useMemo(() => {
|
|
215
|
+
if (!contrastAgainst) return null;
|
|
216
|
+
const fg = parseColor(value);
|
|
217
|
+
const bg = parseColor(contrastAgainst);
|
|
218
|
+
if (!fg || !bg) return null;
|
|
219
|
+
const ratio = contrastRatio(fg, bg);
|
|
220
|
+
const aa = ratio >= 4.5;
|
|
221
|
+
const aaa = ratio >= 7;
|
|
222
|
+
return { ratio, aa, aaa };
|
|
223
|
+
}, [value, contrastAgainst]);
|
|
224
|
+
const currentHex = pickerStateToHex(pickerState, alpha);
|
|
225
|
+
const liveDescription = `Selected color: ${value}${contrastResult ? `, contrast ${contrastResult.ratio.toFixed(1)}:1 against ${contrastAgainst}, ${contrastResult.aa ? "passes AA" : "fails AA"}` : ""}`;
|
|
226
|
+
return /* @__PURE__ */ jsxs(
|
|
227
|
+
"div",
|
|
228
|
+
{
|
|
229
|
+
id: pickerId,
|
|
230
|
+
role: "group",
|
|
231
|
+
"aria-label": ariaLabel,
|
|
232
|
+
className,
|
|
233
|
+
style: {
|
|
234
|
+
boxSizing: "border-box",
|
|
235
|
+
width: "var(--pixerate-color-picker-width, 240px)",
|
|
236
|
+
borderRadius: "var(--pixerate-color-picker-radius, 8px)",
|
|
237
|
+
background: "var(--pixerate-color-picker-bg, #1f2430)",
|
|
238
|
+
color: "var(--pixerate-color-picker-fg, #f0f2f5)",
|
|
239
|
+
padding: "12px",
|
|
240
|
+
display: "flex",
|
|
241
|
+
flexDirection: "column",
|
|
242
|
+
gap: "10px",
|
|
243
|
+
fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
244
|
+
fontSize: "12px",
|
|
245
|
+
userSelect: "none",
|
|
246
|
+
opacity: disabled ? 0.6 : 1,
|
|
247
|
+
pointerEvents: disabled ? "none" : "auto"
|
|
248
|
+
},
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ jsx(
|
|
251
|
+
"span",
|
|
252
|
+
{
|
|
253
|
+
role: "status",
|
|
254
|
+
"aria-live": "polite",
|
|
255
|
+
style: {
|
|
256
|
+
position: "absolute",
|
|
257
|
+
width: "1px",
|
|
258
|
+
height: "1px",
|
|
259
|
+
padding: 0,
|
|
260
|
+
margin: "-1px",
|
|
261
|
+
overflow: "hidden",
|
|
262
|
+
clip: "rect(0, 0, 0, 0)",
|
|
263
|
+
whiteSpace: "nowrap",
|
|
264
|
+
border: 0
|
|
265
|
+
},
|
|
266
|
+
children: liveDescription
|
|
267
|
+
}
|
|
268
|
+
),
|
|
269
|
+
/* @__PURE__ */ jsx(
|
|
270
|
+
"div",
|
|
271
|
+
{
|
|
272
|
+
role: "slider",
|
|
273
|
+
tabIndex: disabled ? -1 : 0,
|
|
274
|
+
"aria-label": "Saturation and brightness",
|
|
275
|
+
"aria-valuetext": `Saturation ${Math.round(pickerState.s * 100)}%, Brightness ${Math.round(
|
|
276
|
+
pickerState.v * 100
|
|
277
|
+
)}%`,
|
|
278
|
+
"aria-disabled": disabled,
|
|
279
|
+
onPointerDown: handleAreaPointerDown,
|
|
280
|
+
onKeyDown: handleAreaKeyDown,
|
|
281
|
+
style: {
|
|
282
|
+
position: "relative",
|
|
283
|
+
width: "100%",
|
|
284
|
+
height: "150px",
|
|
285
|
+
borderRadius: "6px",
|
|
286
|
+
background: pickerAreaBackground(pickerState),
|
|
287
|
+
cursor: disabled ? "default" : "crosshair",
|
|
288
|
+
touchAction: "none",
|
|
289
|
+
outline: "none"
|
|
290
|
+
},
|
|
291
|
+
children: /* @__PURE__ */ jsx(
|
|
292
|
+
"div",
|
|
293
|
+
{
|
|
294
|
+
style: {
|
|
295
|
+
position: "absolute",
|
|
296
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
297
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
298
|
+
borderRadius: "50%",
|
|
299
|
+
transform: "translate(-50%, -50%)",
|
|
300
|
+
left: `${pickerState.s * 100}%`,
|
|
301
|
+
top: `${(1 - pickerState.v) * 100}%`,
|
|
302
|
+
border: "2px solid #ffffff",
|
|
303
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
304
|
+
pointerEvents: "none",
|
|
305
|
+
backgroundColor: currentHex
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
/* @__PURE__ */ jsx(
|
|
312
|
+
"div",
|
|
313
|
+
{
|
|
314
|
+
role: "slider",
|
|
315
|
+
tabIndex: disabled ? -1 : 0,
|
|
316
|
+
"aria-label": "Hue",
|
|
317
|
+
"aria-valuenow": Math.round(pickerState.h),
|
|
318
|
+
"aria-valuemin": 0,
|
|
319
|
+
"aria-valuemax": 360,
|
|
320
|
+
"aria-valuetext": `${Math.round(pickerState.h)} degrees`,
|
|
321
|
+
"aria-disabled": disabled,
|
|
322
|
+
onPointerDown: handleHuePointerDown,
|
|
323
|
+
onKeyDown: handleHueKeyDown,
|
|
324
|
+
style: {
|
|
325
|
+
position: "relative",
|
|
326
|
+
width: "100%",
|
|
327
|
+
height: "12px",
|
|
328
|
+
borderRadius: "6px",
|
|
329
|
+
background: PICKER_HUE_BACKGROUND,
|
|
330
|
+
cursor: disabled ? "default" : "pointer",
|
|
331
|
+
touchAction: "none",
|
|
332
|
+
outline: "none"
|
|
333
|
+
},
|
|
334
|
+
children: /* @__PURE__ */ jsx(
|
|
335
|
+
"div",
|
|
336
|
+
{
|
|
337
|
+
style: {
|
|
338
|
+
position: "absolute",
|
|
339
|
+
top: "50%",
|
|
340
|
+
transform: "translate(-50%, -50%)",
|
|
341
|
+
left: `${pickerState.h / 360 * 100}%`,
|
|
342
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
343
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
344
|
+
borderRadius: "50%",
|
|
345
|
+
border: "2px solid #ffffff",
|
|
346
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
347
|
+
pointerEvents: "none",
|
|
348
|
+
backgroundColor: `hsl(${pickerState.h}, 100%, 50%)`
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
),
|
|
354
|
+
alpha && /* @__PURE__ */ jsxs(
|
|
355
|
+
"div",
|
|
356
|
+
{
|
|
357
|
+
role: "slider",
|
|
358
|
+
tabIndex: disabled ? -1 : 0,
|
|
359
|
+
"aria-label": "Alpha",
|
|
360
|
+
"aria-valuenow": Math.round(pickerState.alpha * 100),
|
|
361
|
+
"aria-valuemin": 0,
|
|
362
|
+
"aria-valuemax": 100,
|
|
363
|
+
"aria-valuetext": `${Math.round(pickerState.alpha * 100)}%`,
|
|
364
|
+
"aria-disabled": disabled,
|
|
365
|
+
onPointerDown: handleAlphaPointerDown,
|
|
366
|
+
onKeyDown: handleAlphaKeyDown,
|
|
367
|
+
style: {
|
|
368
|
+
position: "relative",
|
|
369
|
+
width: "100%",
|
|
370
|
+
height: "12px",
|
|
371
|
+
borderRadius: "6px",
|
|
372
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
373
|
+
backgroundSize: "8px 8px",
|
|
374
|
+
cursor: disabled ? "default" : "pointer",
|
|
375
|
+
touchAction: "none",
|
|
376
|
+
outline: "none",
|
|
377
|
+
overflow: "hidden"
|
|
378
|
+
},
|
|
379
|
+
children: [
|
|
380
|
+
/* @__PURE__ */ jsx(
|
|
381
|
+
"div",
|
|
382
|
+
{
|
|
383
|
+
style: {
|
|
384
|
+
position: "absolute",
|
|
385
|
+
inset: 0,
|
|
386
|
+
background: pickerAlphaBackground(pickerState)
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
),
|
|
390
|
+
/* @__PURE__ */ jsx(
|
|
391
|
+
"div",
|
|
392
|
+
{
|
|
393
|
+
style: {
|
|
394
|
+
position: "absolute",
|
|
395
|
+
top: "50%",
|
|
396
|
+
transform: "translate(-50%, -50%)",
|
|
397
|
+
left: `${pickerState.alpha * 100}%`,
|
|
398
|
+
width: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
399
|
+
height: "var(--pixerate-color-picker-thumb-size, 14px)",
|
|
400
|
+
borderRadius: "50%",
|
|
401
|
+
border: "2px solid #ffffff",
|
|
402
|
+
boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
|
|
403
|
+
pointerEvents: "none",
|
|
404
|
+
backgroundColor: currentHex
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
)
|
|
408
|
+
]
|
|
409
|
+
}
|
|
410
|
+
),
|
|
411
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "2px" }, children: [
|
|
412
|
+
/* @__PURE__ */ jsx(
|
|
413
|
+
"div",
|
|
414
|
+
{
|
|
415
|
+
style: {
|
|
416
|
+
position: "relative",
|
|
417
|
+
width: "28px",
|
|
418
|
+
height: "28px",
|
|
419
|
+
borderRadius: "4px",
|
|
420
|
+
backgroundImage: CHECKERBOARD_BG,
|
|
421
|
+
backgroundSize: "8px 8px",
|
|
422
|
+
overflow: "hidden",
|
|
423
|
+
flexShrink: 0,
|
|
424
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
425
|
+
},
|
|
426
|
+
children: /* @__PURE__ */ jsx(
|
|
427
|
+
"div",
|
|
428
|
+
{
|
|
429
|
+
style: {
|
|
430
|
+
width: "100%",
|
|
431
|
+
height: "100%",
|
|
432
|
+
backgroundColor: currentHex
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
)
|
|
436
|
+
}
|
|
437
|
+
),
|
|
438
|
+
/* @__PURE__ */ jsx(
|
|
439
|
+
"input",
|
|
440
|
+
{
|
|
441
|
+
type: "text",
|
|
442
|
+
value: textDraft,
|
|
443
|
+
disabled,
|
|
444
|
+
"aria-label": "Color hex or CSS string",
|
|
445
|
+
"aria-invalid": isInvalid ? "true" : void 0,
|
|
446
|
+
onChange: (e) => {
|
|
447
|
+
isTypingRef.current = true;
|
|
448
|
+
setTextDraft(e.target.value);
|
|
449
|
+
setIsInvalid(false);
|
|
450
|
+
},
|
|
451
|
+
onKeyDown: handleTextKeyDown,
|
|
452
|
+
onBlur: (e) => commitTextInput(e.currentTarget),
|
|
453
|
+
style: {
|
|
454
|
+
flex: 1,
|
|
455
|
+
minWidth: 0,
|
|
456
|
+
height: "28px",
|
|
457
|
+
padding: "0 8px",
|
|
458
|
+
fontSize: "12px",
|
|
459
|
+
fontFamily: "monospace",
|
|
460
|
+
borderRadius: "4px",
|
|
461
|
+
border: isInvalid ? "1px solid #ef4444" : "1px solid rgba(255,255,255,0.2)",
|
|
462
|
+
background: "rgba(0,0,0,0.2)",
|
|
463
|
+
color: "inherit",
|
|
464
|
+
outline: "none"
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
),
|
|
468
|
+
hasEyeDropper && /* @__PURE__ */ jsx(
|
|
469
|
+
"button",
|
|
470
|
+
{
|
|
471
|
+
type: "button",
|
|
472
|
+
disabled,
|
|
473
|
+
"aria-label": "Pick color from screen",
|
|
474
|
+
title: "Pick color from screen",
|
|
475
|
+
onClick: handleEyeDropper,
|
|
476
|
+
style: {
|
|
477
|
+
display: "inline-flex",
|
|
478
|
+
alignItems: "center",
|
|
479
|
+
justifyContent: "center",
|
|
480
|
+
width: "28px",
|
|
481
|
+
height: "28px",
|
|
482
|
+
borderRadius: "4px",
|
|
483
|
+
border: "1px solid rgba(255,255,255,0.2)",
|
|
484
|
+
background: "transparent",
|
|
485
|
+
color: "inherit",
|
|
486
|
+
cursor: disabled ? "default" : "pointer"
|
|
487
|
+
},
|
|
488
|
+
children: /* @__PURE__ */ jsxs(
|
|
489
|
+
"svg",
|
|
490
|
+
{
|
|
491
|
+
width: "14",
|
|
492
|
+
height: "14",
|
|
493
|
+
viewBox: "0 0 24 24",
|
|
494
|
+
fill: "none",
|
|
495
|
+
stroke: "currentColor",
|
|
496
|
+
strokeWidth: "2",
|
|
497
|
+
strokeLinecap: "round",
|
|
498
|
+
strokeLinejoin: "round",
|
|
499
|
+
children: [
|
|
500
|
+
/* @__PURE__ */ jsx("path", { d: "m19 11-8-8-8.5 8.5a2.12 2.12 0 0 0 0 3l2.5 2.5 1.5-1.5" }),
|
|
501
|
+
/* @__PURE__ */ jsx("path", { d: "m5 16-3 3 1 1 3-3" }),
|
|
502
|
+
/* @__PURE__ */ jsx("path", { d: "m14 6 4 4" })
|
|
503
|
+
]
|
|
504
|
+
}
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
)
|
|
508
|
+
] }),
|
|
509
|
+
isClipped && /* @__PURE__ */ jsx(
|
|
510
|
+
"div",
|
|
511
|
+
{
|
|
512
|
+
role: "note",
|
|
513
|
+
title: "This colour was outside standard sRGB and clipped.",
|
|
514
|
+
style: {
|
|
515
|
+
display: "inline-flex",
|
|
516
|
+
alignItems: "center",
|
|
517
|
+
gap: "4px",
|
|
518
|
+
fontSize: "10px",
|
|
519
|
+
color: "#f59e0b",
|
|
520
|
+
background: "rgba(245, 158, 11, 0.1)",
|
|
521
|
+
padding: "2px 6px",
|
|
522
|
+
borderRadius: "4px",
|
|
523
|
+
alignSelf: "flex-start"
|
|
524
|
+
},
|
|
525
|
+
children: /* @__PURE__ */ jsx("span", { children: "\u26A0 Clipped to sRGB" })
|
|
526
|
+
}
|
|
527
|
+
),
|
|
528
|
+
contrastResult && /* @__PURE__ */ jsxs(
|
|
529
|
+
"div",
|
|
530
|
+
{
|
|
531
|
+
style: {
|
|
532
|
+
display: "flex",
|
|
533
|
+
alignItems: "center",
|
|
534
|
+
justifyContent: "space-between",
|
|
535
|
+
fontSize: "11px",
|
|
536
|
+
padding: "4px 8px",
|
|
537
|
+
borderRadius: "4px",
|
|
538
|
+
background: "rgba(255,255,255,0.05)",
|
|
539
|
+
border: "1px solid rgba(255,255,255,0.1)"
|
|
540
|
+
},
|
|
541
|
+
children: [
|
|
542
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
543
|
+
"Contrast: ",
|
|
544
|
+
/* @__PURE__ */ jsxs("strong", { children: [
|
|
545
|
+
contrastResult.ratio.toFixed(2),
|
|
546
|
+
":1"
|
|
547
|
+
] })
|
|
548
|
+
] }),
|
|
549
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "6px" }, children: [
|
|
550
|
+
/* @__PURE__ */ jsxs(
|
|
551
|
+
"span",
|
|
552
|
+
{
|
|
553
|
+
style: {
|
|
554
|
+
color: contrastResult.aa ? "#10b981" : "#ef4444",
|
|
555
|
+
fontWeight: 600
|
|
556
|
+
},
|
|
557
|
+
children: [
|
|
558
|
+
"AA ",
|
|
559
|
+
contrastResult.aa ? "\u2713" : "\u2717"
|
|
560
|
+
]
|
|
561
|
+
}
|
|
562
|
+
),
|
|
563
|
+
/* @__PURE__ */ jsxs(
|
|
564
|
+
"span",
|
|
565
|
+
{
|
|
566
|
+
style: {
|
|
567
|
+
color: contrastResult.aaa ? "#10b981" : "#ef4444",
|
|
568
|
+
fontWeight: 600
|
|
569
|
+
},
|
|
570
|
+
children: [
|
|
571
|
+
"AAA ",
|
|
572
|
+
contrastResult.aaa ? "\u2713" : "\u2717"
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
)
|
|
576
|
+
] })
|
|
577
|
+
]
|
|
578
|
+
}
|
|
579
|
+
),
|
|
580
|
+
swatches && swatches.length > 0 && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
581
|
+
/* @__PURE__ */ jsx("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Palette" }),
|
|
582
|
+
/* @__PURE__ */ jsx("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: swatches.map((color, idx) => /* @__PURE__ */ jsx(
|
|
583
|
+
"button",
|
|
584
|
+
{
|
|
585
|
+
type: "button",
|
|
586
|
+
"data-testid": "color-picker-swatch",
|
|
587
|
+
title: color,
|
|
588
|
+
disabled,
|
|
589
|
+
"aria-label": `Color ${color}`,
|
|
590
|
+
onClick: () => {
|
|
591
|
+
onChange(color);
|
|
592
|
+
recordRecent(color);
|
|
593
|
+
},
|
|
594
|
+
style: {
|
|
595
|
+
width: "18px",
|
|
596
|
+
height: "18px",
|
|
597
|
+
borderRadius: "3px",
|
|
598
|
+
backgroundColor: color,
|
|
599
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
600
|
+
cursor: disabled ? "default" : "pointer",
|
|
601
|
+
padding: 0,
|
|
602
|
+
outline: "none"
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
`${color}-${idx}`
|
|
606
|
+
)) })
|
|
607
|
+
] }),
|
|
608
|
+
activeRecent.length > 0 && /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
|
|
609
|
+
/* @__PURE__ */ jsx("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Recent" }),
|
|
610
|
+
/* @__PURE__ */ jsx("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: activeRecent.map((color, idx) => /* @__PURE__ */ jsx(
|
|
611
|
+
"button",
|
|
612
|
+
{
|
|
613
|
+
type: "button",
|
|
614
|
+
"data-testid": "color-picker-recent",
|
|
615
|
+
disabled,
|
|
616
|
+
"aria-label": `Color ${color}`,
|
|
617
|
+
onClick: () => {
|
|
618
|
+
onChange(color);
|
|
619
|
+
recordRecent(color);
|
|
620
|
+
},
|
|
621
|
+
style: {
|
|
622
|
+
width: "18px",
|
|
623
|
+
height: "18px",
|
|
624
|
+
borderRadius: "3px",
|
|
625
|
+
backgroundColor: color,
|
|
626
|
+
border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
|
|
627
|
+
cursor: disabled ? "default" : "pointer",
|
|
628
|
+
padding: 0,
|
|
629
|
+
outline: "none"
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
`recent-${color}-${idx}`
|
|
633
|
+
)) })
|
|
634
|
+
] })
|
|
635
|
+
]
|
|
636
|
+
}
|
|
637
|
+
);
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// src/color/DualColorPicker.tsx
|
|
641
|
+
import { useState as useState2, useId as useId2 } from "react";
|
|
642
|
+
import {
|
|
643
|
+
normalizeDualColor,
|
|
644
|
+
setDualColorSide,
|
|
645
|
+
deriveDualColor,
|
|
646
|
+
checkDualColorContrast,
|
|
647
|
+
resolveColor,
|
|
648
|
+
DEFAULT_SCHEME_SURFACES
|
|
649
|
+
} from "@pixerate/editor/color";
|
|
650
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
651
|
+
function DualColorPicker({
|
|
652
|
+
value,
|
|
653
|
+
onChange,
|
|
654
|
+
onGestureStart,
|
|
655
|
+
onGestureEnd,
|
|
656
|
+
scheme: controlledScheme,
|
|
657
|
+
onSchemeChange,
|
|
658
|
+
surfaces = DEFAULT_SCHEME_SURFACES,
|
|
659
|
+
contrastAgainst,
|
|
660
|
+
alpha = false,
|
|
661
|
+
swatches,
|
|
662
|
+
disabled = false,
|
|
663
|
+
className = ""
|
|
664
|
+
}) {
|
|
665
|
+
const sameId = useId2();
|
|
666
|
+
const [internalScheme, setInternalScheme] = useState2("light");
|
|
667
|
+
const activeScheme = controlledScheme ?? internalScheme;
|
|
668
|
+
const handleSchemeSelect = (nextScheme) => {
|
|
669
|
+
if (onSchemeChange) {
|
|
670
|
+
onSchemeChange(nextScheme);
|
|
671
|
+
} else {
|
|
672
|
+
setInternalScheme(nextScheme);
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
const dual = normalizeDualColor(value) ?? { light: "#000000", dark: "#000000" };
|
|
676
|
+
const isSame = dual.light.toLowerCase() === dual.dark.toLowerCase();
|
|
677
|
+
const [sameInBoth, setSameInBoth] = useState2(isSame);
|
|
678
|
+
const handleSameToggle = (e) => {
|
|
679
|
+
const nextSame = e.target.checked;
|
|
680
|
+
setSameInBoth(nextSame);
|
|
681
|
+
if (nextSame) {
|
|
682
|
+
const activeVal = activeScheme === "dark" ? dual.dark : dual.light;
|
|
683
|
+
onChange({ light: activeVal, dark: activeVal });
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
const handleDerive = () => {
|
|
687
|
+
if (disabled) return;
|
|
688
|
+
onGestureStart?.();
|
|
689
|
+
const currentActive = activeScheme === "dark" ? dual.dark : dual.light;
|
|
690
|
+
const derived = deriveDualColor(currentActive, {
|
|
691
|
+
from: activeScheme,
|
|
692
|
+
// An unreadable surfaces prop falls back to the defaults rather than throwing.
|
|
693
|
+
surfaces: normalizeDualColor(surfaces) ?? DEFAULT_SCHEME_SURFACES
|
|
694
|
+
});
|
|
695
|
+
onChange(derived);
|
|
696
|
+
onGestureEnd?.();
|
|
697
|
+
};
|
|
698
|
+
const handleInnerChange = (hex) => {
|
|
699
|
+
if (sameInBoth) {
|
|
700
|
+
onChange({ light: hex, dark: hex });
|
|
701
|
+
} else {
|
|
702
|
+
const updated = setDualColorSide(dual, activeScheme, hex);
|
|
703
|
+
onChange(updated);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
const activeColor = activeScheme === "dark" ? dual.dark : dual.light;
|
|
707
|
+
const activeContrastTarget = contrastAgainst ? resolveColor(contrastAgainst, activeScheme) ?? void 0 : void 0;
|
|
708
|
+
const dualContrast = contrastAgainst && normalizeDualColor(contrastAgainst) ? checkDualColorContrast(dual, contrastAgainst) : null;
|
|
709
|
+
return /* @__PURE__ */ jsxs2(
|
|
710
|
+
"div",
|
|
711
|
+
{
|
|
712
|
+
className: `pixerate-dual-color-picker ${className}`,
|
|
713
|
+
style: {
|
|
714
|
+
display: "flex",
|
|
715
|
+
flexDirection: "column",
|
|
716
|
+
gap: "12px",
|
|
717
|
+
padding: "12px",
|
|
718
|
+
background: "#1a1d24",
|
|
719
|
+
color: "#e2e8f0",
|
|
720
|
+
borderRadius: "10px",
|
|
721
|
+
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
|
722
|
+
width: "260px",
|
|
723
|
+
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
724
|
+
fontSize: "13px",
|
|
725
|
+
boxSizing: "border-box"
|
|
726
|
+
},
|
|
727
|
+
children: [
|
|
728
|
+
/* @__PURE__ */ jsxs2(
|
|
729
|
+
"div",
|
|
730
|
+
{
|
|
731
|
+
role: "tablist",
|
|
732
|
+
"aria-label": "Color scheme mode",
|
|
733
|
+
style: {
|
|
734
|
+
display: "flex",
|
|
735
|
+
background: "#111318",
|
|
736
|
+
borderRadius: "6px",
|
|
737
|
+
padding: "2px",
|
|
738
|
+
gap: "2px"
|
|
739
|
+
},
|
|
740
|
+
children: [
|
|
741
|
+
/* @__PURE__ */ jsx2(
|
|
742
|
+
"button",
|
|
743
|
+
{
|
|
744
|
+
type: "button",
|
|
745
|
+
role: "tab",
|
|
746
|
+
"aria-selected": activeScheme === "light",
|
|
747
|
+
onClick: () => handleSchemeSelect("light"),
|
|
748
|
+
disabled,
|
|
749
|
+
style: {
|
|
750
|
+
flex: 1,
|
|
751
|
+
padding: "6px 8px",
|
|
752
|
+
border: "none",
|
|
753
|
+
borderRadius: "4px",
|
|
754
|
+
background: activeScheme === "light" ? "#2d3342" : "transparent",
|
|
755
|
+
color: activeScheme === "light" ? "#ffffff" : "#8c95a6",
|
|
756
|
+
fontWeight: activeScheme === "light" ? 600 : 400,
|
|
757
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
758
|
+
fontSize: "12px",
|
|
759
|
+
transition: "all 0.15s ease"
|
|
760
|
+
},
|
|
761
|
+
children: "Light"
|
|
762
|
+
}
|
|
763
|
+
),
|
|
764
|
+
/* @__PURE__ */ jsx2(
|
|
765
|
+
"button",
|
|
766
|
+
{
|
|
767
|
+
type: "button",
|
|
768
|
+
role: "tab",
|
|
769
|
+
"aria-selected": activeScheme === "dark",
|
|
770
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
771
|
+
disabled,
|
|
772
|
+
style: {
|
|
773
|
+
flex: 1,
|
|
774
|
+
padding: "6px 8px",
|
|
775
|
+
border: "none",
|
|
776
|
+
borderRadius: "4px",
|
|
777
|
+
background: activeScheme === "dark" ? "#2d3342" : "transparent",
|
|
778
|
+
color: activeScheme === "dark" ? "#ffffff" : "#8c95a6",
|
|
779
|
+
fontWeight: activeScheme === "dark" ? 600 : 400,
|
|
780
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
781
|
+
fontSize: "12px",
|
|
782
|
+
transition: "all 0.15s ease"
|
|
783
|
+
},
|
|
784
|
+
children: "Dark"
|
|
785
|
+
}
|
|
786
|
+
)
|
|
787
|
+
]
|
|
788
|
+
}
|
|
789
|
+
),
|
|
790
|
+
/* @__PURE__ */ jsxs2("div", { style: { display: "flex", gap: "8px" }, children: [
|
|
791
|
+
/* @__PURE__ */ jsxs2(
|
|
792
|
+
"button",
|
|
793
|
+
{
|
|
794
|
+
type: "button",
|
|
795
|
+
onClick: () => handleSchemeSelect("light"),
|
|
796
|
+
disabled,
|
|
797
|
+
title: "Edit light mode colour",
|
|
798
|
+
style: {
|
|
799
|
+
flex: 1,
|
|
800
|
+
display: "flex",
|
|
801
|
+
flexDirection: "column",
|
|
802
|
+
alignItems: "center",
|
|
803
|
+
gap: "6px",
|
|
804
|
+
padding: "8px",
|
|
805
|
+
background: surfaces.light,
|
|
806
|
+
color: "#000000",
|
|
807
|
+
border: activeScheme === "light" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
808
|
+
borderRadius: "6px",
|
|
809
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
810
|
+
outline: "none"
|
|
811
|
+
},
|
|
812
|
+
children: [
|
|
813
|
+
/* @__PURE__ */ jsx2(
|
|
814
|
+
"span",
|
|
815
|
+
{
|
|
816
|
+
style: {
|
|
817
|
+
width: "100%",
|
|
818
|
+
height: "24px",
|
|
819
|
+
borderRadius: "4px",
|
|
820
|
+
background: dual.light,
|
|
821
|
+
border: "1px solid rgba(0,0,0,0.15)"
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
),
|
|
825
|
+
/* @__PURE__ */ jsx2("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Light" })
|
|
826
|
+
]
|
|
827
|
+
}
|
|
828
|
+
),
|
|
829
|
+
/* @__PURE__ */ jsxs2(
|
|
830
|
+
"button",
|
|
831
|
+
{
|
|
832
|
+
type: "button",
|
|
833
|
+
onClick: () => handleSchemeSelect("dark"),
|
|
834
|
+
disabled,
|
|
835
|
+
title: "Edit dark mode colour",
|
|
836
|
+
style: {
|
|
837
|
+
flex: 1,
|
|
838
|
+
display: "flex",
|
|
839
|
+
flexDirection: "column",
|
|
840
|
+
alignItems: "center",
|
|
841
|
+
gap: "6px",
|
|
842
|
+
padding: "8px",
|
|
843
|
+
background: surfaces.dark,
|
|
844
|
+
color: "#ffffff",
|
|
845
|
+
border: activeScheme === "dark" ? "2px solid #3b82f6" : "1px solid #333842",
|
|
846
|
+
borderRadius: "6px",
|
|
847
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
848
|
+
outline: "none"
|
|
849
|
+
},
|
|
850
|
+
children: [
|
|
851
|
+
/* @__PURE__ */ jsx2(
|
|
852
|
+
"span",
|
|
853
|
+
{
|
|
854
|
+
style: {
|
|
855
|
+
width: "100%",
|
|
856
|
+
height: "24px",
|
|
857
|
+
borderRadius: "4px",
|
|
858
|
+
background: dual.dark,
|
|
859
|
+
border: "1px solid rgba(255,255,255,0.15)"
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
),
|
|
863
|
+
/* @__PURE__ */ jsx2("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Dark" })
|
|
864
|
+
]
|
|
865
|
+
}
|
|
866
|
+
)
|
|
867
|
+
] }),
|
|
868
|
+
/* @__PURE__ */ jsxs2(
|
|
869
|
+
"div",
|
|
870
|
+
{
|
|
871
|
+
style: {
|
|
872
|
+
display: "flex",
|
|
873
|
+
alignItems: "center",
|
|
874
|
+
justifyContent: "space-between",
|
|
875
|
+
gap: "8px",
|
|
876
|
+
padding: "2px 0"
|
|
877
|
+
},
|
|
878
|
+
children: [
|
|
879
|
+
/* @__PURE__ */ jsxs2(
|
|
880
|
+
"label",
|
|
881
|
+
{
|
|
882
|
+
htmlFor: sameId,
|
|
883
|
+
style: {
|
|
884
|
+
display: "flex",
|
|
885
|
+
alignItems: "center",
|
|
886
|
+
gap: "6px",
|
|
887
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
888
|
+
userSelect: "none",
|
|
889
|
+
fontSize: "12px",
|
|
890
|
+
color: "#c4cad4"
|
|
891
|
+
},
|
|
892
|
+
children: [
|
|
893
|
+
/* @__PURE__ */ jsx2(
|
|
894
|
+
"input",
|
|
895
|
+
{
|
|
896
|
+
id: sameId,
|
|
897
|
+
type: "checkbox",
|
|
898
|
+
checked: sameInBoth,
|
|
899
|
+
onChange: handleSameToggle,
|
|
900
|
+
disabled,
|
|
901
|
+
style: { cursor: disabled ? "not-allowed" : "pointer" }
|
|
902
|
+
}
|
|
903
|
+
),
|
|
904
|
+
/* @__PURE__ */ jsx2("span", { children: "Same in both" })
|
|
905
|
+
]
|
|
906
|
+
}
|
|
907
|
+
),
|
|
908
|
+
/* @__PURE__ */ jsx2(
|
|
909
|
+
"button",
|
|
910
|
+
{
|
|
911
|
+
type: "button",
|
|
912
|
+
onClick: handleDerive,
|
|
913
|
+
disabled,
|
|
914
|
+
style: {
|
|
915
|
+
padding: "4px 10px",
|
|
916
|
+
background: "#2d3342",
|
|
917
|
+
color: "#e2e8f0",
|
|
918
|
+
border: "1px solid #3b4252",
|
|
919
|
+
borderRadius: "4px",
|
|
920
|
+
fontSize: "11px",
|
|
921
|
+
fontWeight: 500,
|
|
922
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
|
923
|
+
},
|
|
924
|
+
children: "Derive"
|
|
925
|
+
}
|
|
926
|
+
)
|
|
927
|
+
]
|
|
928
|
+
}
|
|
929
|
+
),
|
|
930
|
+
dualContrast && /* @__PURE__ */ jsxs2(
|
|
931
|
+
"div",
|
|
932
|
+
{
|
|
933
|
+
"data-testid": "dual-contrast-summary",
|
|
934
|
+
style: {
|
|
935
|
+
display: "flex",
|
|
936
|
+
justifyContent: "space-between",
|
|
937
|
+
background: "#111318",
|
|
938
|
+
padding: "6px 8px",
|
|
939
|
+
borderRadius: "6px",
|
|
940
|
+
fontSize: "11px",
|
|
941
|
+
color: "#8c95a6"
|
|
942
|
+
},
|
|
943
|
+
children: [
|
|
944
|
+
/* @__PURE__ */ jsxs2("span", { children: [
|
|
945
|
+
"Light:",
|
|
946
|
+
" ",
|
|
947
|
+
/* @__PURE__ */ jsxs2("strong", { style: { color: dualContrast.light.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
948
|
+
dualContrast.light.ratio.toFixed(2),
|
|
949
|
+
" (",
|
|
950
|
+
dualContrast.light.level,
|
|
951
|
+
")"
|
|
952
|
+
] })
|
|
953
|
+
] }),
|
|
954
|
+
/* @__PURE__ */ jsxs2("span", { children: [
|
|
955
|
+
"Dark:",
|
|
956
|
+
" ",
|
|
957
|
+
/* @__PURE__ */ jsxs2("strong", { style: { color: dualContrast.dark.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
|
|
958
|
+
dualContrast.dark.ratio.toFixed(2),
|
|
959
|
+
" (",
|
|
960
|
+
dualContrast.dark.level,
|
|
961
|
+
")"
|
|
962
|
+
] })
|
|
963
|
+
] })
|
|
964
|
+
]
|
|
965
|
+
}
|
|
966
|
+
),
|
|
967
|
+
/* @__PURE__ */ jsx2(
|
|
968
|
+
ColorPicker,
|
|
969
|
+
{
|
|
970
|
+
value: activeColor,
|
|
971
|
+
onChange: handleInnerChange,
|
|
972
|
+
onGestureStart,
|
|
973
|
+
onGestureEnd,
|
|
974
|
+
contrastAgainst: activeContrastTarget,
|
|
975
|
+
alpha,
|
|
976
|
+
swatches,
|
|
977
|
+
disabled
|
|
978
|
+
}
|
|
979
|
+
)
|
|
980
|
+
]
|
|
981
|
+
}
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
export {
|
|
986
|
+
ColorPicker,
|
|
987
|
+
DualColorPicker
|
|
988
|
+
};
|