@sanity/color-input 6.0.10 → 6.0.12
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/ColorInput.js +967 -0
- package/dist/ColorInput.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +143 -132
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/dist/_chunks-es/ColorInput.js +0 -790
- package/dist/_chunks-es/ColorInput.js.map +0 -1
|
@@ -1,790 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { c } from "react/compiler-runtime";
|
|
3
|
-
import { AddIcon } from "@sanity/icons/Add";
|
|
4
|
-
import { TrashIcon } from "@sanity/icons/Trash";
|
|
5
|
-
import { Flex, useTheme, Box, Button, Stack, Text, Inline, Card } from "@sanity/ui";
|
|
6
|
-
import { Component, PureComponent, useOptimistic, useRef, startTransition } from "react";
|
|
7
|
-
import { unset, set, setIfMissing } from "sanity";
|
|
8
|
-
import { styled } from "styled-components";
|
|
9
|
-
import tinycolor from "tinycolor2";
|
|
10
|
-
import throttle from "lodash-es/throttle";
|
|
11
|
-
const ColorListWrap = /* @__PURE__ */ styled(Flex).withConfig({
|
|
12
|
-
displayName: "ColorListWrap",
|
|
13
|
-
componentId: "sc-nrr1l2-0"
|
|
14
|
-
})(["gap:0.25em;"]), ColorBoxContainer = /* @__PURE__ */ styled.div.withConfig({
|
|
15
|
-
displayName: "ColorBoxContainer",
|
|
16
|
-
componentId: "sc-nrr1l2-1"
|
|
17
|
-
})(["width:2.1em;height:2.1em;cursor:pointer;position:relative;overflow:hidden;border-radius:3px;background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=') left center #fff;"]), ColorBox$1 = /* @__PURE__ */ styled.div.withConfig({
|
|
18
|
-
displayName: "ColorBox",
|
|
19
|
-
componentId: "sc-nrr1l2-2"
|
|
20
|
-
})(["border-radius:inherit;box-shadow:inset 0 0 0 1px var(--card-shadow-outline-color);content:'';position:absolute;inset:0;z-index:1;"]), validateColors = (colors) => {
|
|
21
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22
|
-
return colors.reduce((cls, c2) => {
|
|
23
|
-
const color = c2.hex ? tinycolor(c2.hex) : tinycolor(c2);
|
|
24
|
-
if (color.isValid()) {
|
|
25
|
-
const backgroundColor = color.toRgbString(), key = JSON.stringify({
|
|
26
|
-
color: c2,
|
|
27
|
-
backgroundColor
|
|
28
|
-
});
|
|
29
|
-
seen.has(key) || (seen.add(key), cls.push({
|
|
30
|
-
key,
|
|
31
|
-
color: c2,
|
|
32
|
-
backgroundColor
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
return cls;
|
|
36
|
-
}, []);
|
|
37
|
-
};
|
|
38
|
-
function ColorList(t0) {
|
|
39
|
-
const $ = c(7), {
|
|
40
|
-
colors,
|
|
41
|
-
onChange
|
|
42
|
-
} = t0;
|
|
43
|
-
if (!colors)
|
|
44
|
-
return null;
|
|
45
|
-
let t1;
|
|
46
|
-
if ($[0] !== colors || $[1] !== onChange) {
|
|
47
|
-
let t22;
|
|
48
|
-
$[3] !== onChange ? (t22 = (t3) => {
|
|
49
|
-
const {
|
|
50
|
-
key,
|
|
51
|
-
color,
|
|
52
|
-
backgroundColor
|
|
53
|
-
} = t3;
|
|
54
|
-
return /* @__PURE__ */ jsx(ColorBoxContainer, { onClick: () => {
|
|
55
|
-
onChange(color);
|
|
56
|
-
}, children: /* @__PURE__ */ jsx(ColorBox$1, { style: {
|
|
57
|
-
background: backgroundColor
|
|
58
|
-
} }) }, key);
|
|
59
|
-
}, $[3] = onChange, $[4] = t22) : t22 = $[4], t1 = validateColors(colors).map(t22), $[0] = colors, $[1] = onChange, $[2] = t1;
|
|
60
|
-
} else
|
|
61
|
-
t1 = $[2];
|
|
62
|
-
let t2;
|
|
63
|
-
return $[5] !== t1 ? (t2 = /* @__PURE__ */ jsx(ColorListWrap, { wrap: "wrap", children: t1 }), $[5] = t1, $[6] = t2) : t2 = $[6], t2;
|
|
64
|
-
}
|
|
65
|
-
const checkboardCache = {};
|
|
66
|
-
function render(c1, c2, size, serverCanvas) {
|
|
67
|
-
if (typeof document > "u" && !serverCanvas)
|
|
68
|
-
return null;
|
|
69
|
-
const canvas = serverCanvas ? new serverCanvas() : document.createElement("canvas");
|
|
70
|
-
canvas.width = size * 2, canvas.height = size * 2;
|
|
71
|
-
const ctx = canvas.getContext("2d");
|
|
72
|
-
return ctx ? (ctx.fillStyle = c1, ctx.fillRect(0, 0, canvas.width, canvas.height), ctx.fillStyle = c2, ctx.fillRect(0, 0, size, size), ctx.translate(size, size), ctx.fillRect(0, 0, size, size), canvas.toDataURL()) : null;
|
|
73
|
-
}
|
|
74
|
-
function get(c1, c2, size, serverCanvas) {
|
|
75
|
-
const key = `${c1}-${c2}-${size}${serverCanvas ? "-server" : ""}`, cached = checkboardCache[key];
|
|
76
|
-
if (cached)
|
|
77
|
-
return cached;
|
|
78
|
-
const checkboard = render(c1, c2, size, serverCanvas);
|
|
79
|
-
return checkboardCache[key] = checkboard, checkboard;
|
|
80
|
-
}
|
|
81
|
-
const EMPTY_RENDERERS = {};
|
|
82
|
-
function Checkboard(t0) {
|
|
83
|
-
const $ = c(9), {
|
|
84
|
-
white: t1,
|
|
85
|
-
grey: t2,
|
|
86
|
-
size: t3,
|
|
87
|
-
renderers: t4,
|
|
88
|
-
borderRadius,
|
|
89
|
-
boxShadow
|
|
90
|
-
} = t0, white = t1 === void 0 ? "transparent" : t1, grey = t2 === void 0 ? "rgba(0,0,0,.08)" : t2, size = t3 === void 0 ? 8 : t3, renderers = t4 === void 0 ? EMPTY_RENDERERS : t4;
|
|
91
|
-
let t5;
|
|
92
|
-
$[0] !== grey || $[1] !== renderers.canvas || $[2] !== size || $[3] !== white ? (t5 = get(white, grey, size, renderers.canvas), $[0] = grey, $[1] = renderers.canvas, $[2] = size, $[3] = white, $[4] = t5) : t5 = $[4];
|
|
93
|
-
const background = t5, t6 = background ? `url(${background}) center left` : void 0;
|
|
94
|
-
let t7;
|
|
95
|
-
return $[5] !== borderRadius || $[6] !== boxShadow || $[7] !== t6 ? (t7 = /* @__PURE__ */ jsx("div", { style: {
|
|
96
|
-
borderRadius,
|
|
97
|
-
boxShadow,
|
|
98
|
-
position: "absolute",
|
|
99
|
-
inset: 0,
|
|
100
|
-
background: t6
|
|
101
|
-
} }), $[5] = borderRadius, $[6] = boxShadow, $[7] = t6, $[8] = t7) : t7 = $[8], t7;
|
|
102
|
-
}
|
|
103
|
-
function calculateChange$2(e, hsl, direction, initialA, container) {
|
|
104
|
-
const containerWidth = container.clientWidth, containerHeight = container.clientHeight, x = "touches" in e ? e.touches[0]?.pageX ?? 0 : e.pageX, y = "touches" in e ? e.touches[0]?.pageY ?? 0 : e.pageY, left = x - (container.getBoundingClientRect().left + window.scrollX), top = y - (container.getBoundingClientRect().top + window.scrollY);
|
|
105
|
-
if (direction === "vertical") {
|
|
106
|
-
let a2;
|
|
107
|
-
return top < 0 ? a2 = 0 : top > containerHeight ? a2 = 1 : a2 = Math.round(top * 100 / containerHeight) / 100, hsl.a !== a2 ? {
|
|
108
|
-
h: hsl.h,
|
|
109
|
-
s: hsl.s,
|
|
110
|
-
l: hsl.l,
|
|
111
|
-
a: a2,
|
|
112
|
-
source: "rgb"
|
|
113
|
-
} : null;
|
|
114
|
-
}
|
|
115
|
-
let a;
|
|
116
|
-
return left < 0 ? a = 0 : left > containerWidth ? a = 1 : a = Math.round(left * 100 / containerWidth) / 100, initialA !== a ? {
|
|
117
|
-
h: hsl.h,
|
|
118
|
-
s: hsl.s,
|
|
119
|
-
l: hsl.l,
|
|
120
|
-
a,
|
|
121
|
-
source: "rgb"
|
|
122
|
-
} : null;
|
|
123
|
-
}
|
|
124
|
-
class Alpha extends Component {
|
|
125
|
-
container = null;
|
|
126
|
-
componentWillUnmount() {
|
|
127
|
-
this.unbindEventListeners();
|
|
128
|
-
}
|
|
129
|
-
setContainerRef = (node) => {
|
|
130
|
-
this.container = node;
|
|
131
|
-
};
|
|
132
|
-
handleChange = (event) => {
|
|
133
|
-
if (!this.container)
|
|
134
|
-
return;
|
|
135
|
-
const change = calculateChange$2(event, this.props.hsl, this.props.direction, this.props.a, this.container);
|
|
136
|
-
change && typeof this.props.onChange == "function" && this.props.onChange(change);
|
|
137
|
-
};
|
|
138
|
-
handleMouseDown = (event) => {
|
|
139
|
-
this.handleChange(event.nativeEvent), window.addEventListener("mousemove", this.handleChange), window.addEventListener("mouseup", this.handleMouseUp);
|
|
140
|
-
};
|
|
141
|
-
handleMouseUp = () => {
|
|
142
|
-
this.unbindEventListeners();
|
|
143
|
-
};
|
|
144
|
-
unbindEventListeners = () => {
|
|
145
|
-
window.removeEventListener("mousemove", this.handleChange), window.removeEventListener("mouseup", this.handleMouseUp);
|
|
146
|
-
};
|
|
147
|
-
render() {
|
|
148
|
-
const {
|
|
149
|
-
rgb,
|
|
150
|
-
direction,
|
|
151
|
-
radius,
|
|
152
|
-
shadow,
|
|
153
|
-
renderers
|
|
154
|
-
} = this.props, alphaValue = rgb.a ?? 1, gradient = direction === "vertical" ? `linear-gradient(to bottom, rgba(${rgb.r},${rgb.g},${rgb.b}, 0) 0%, rgba(${rgb.r},${rgb.g},${rgb.b}, 1) 100%)` : `linear-gradient(to right, rgba(${rgb.r},${rgb.g},${rgb.b}, 0) 0%, rgba(${rgb.r},${rgb.g},${rgb.b}, 1) 100%)`, pointerStyle = direction === "vertical" ? {
|
|
155
|
-
position: "absolute",
|
|
156
|
-
left: 0,
|
|
157
|
-
top: `${alphaValue * 100}%`
|
|
158
|
-
} : {
|
|
159
|
-
position: "absolute",
|
|
160
|
-
left: `${alphaValue * 100}%`
|
|
161
|
-
};
|
|
162
|
-
return /* @__PURE__ */ jsxs("div", { style: {
|
|
163
|
-
position: "absolute",
|
|
164
|
-
inset: 0,
|
|
165
|
-
borderRadius: radius
|
|
166
|
-
}, children: [
|
|
167
|
-
/* @__PURE__ */ jsx("div", { style: {
|
|
168
|
-
position: "absolute",
|
|
169
|
-
inset: 0,
|
|
170
|
-
overflow: "hidden",
|
|
171
|
-
borderRadius: radius
|
|
172
|
-
}, children: /* @__PURE__ */ jsx(Checkboard, { renderers }) }),
|
|
173
|
-
/* @__PURE__ */ jsx("div", { style: {
|
|
174
|
-
position: "absolute",
|
|
175
|
-
inset: 0,
|
|
176
|
-
background: gradient,
|
|
177
|
-
boxShadow: shadow,
|
|
178
|
-
borderRadius: radius
|
|
179
|
-
} }),
|
|
180
|
-
/* @__PURE__ */ jsx("div", { style: {
|
|
181
|
-
position: "relative",
|
|
182
|
-
height: "100%",
|
|
183
|
-
margin: "0 3px"
|
|
184
|
-
}, ref: this.setContainerRef, onMouseDown: this.handleMouseDown, onTouchMove: this.handleChange, onTouchStart: this.handleChange, children: /* @__PURE__ */ jsx("div", { style: pointerStyle, children: /* @__PURE__ */ jsx("div", { style: {
|
|
185
|
-
width: "4px",
|
|
186
|
-
borderRadius: "1px",
|
|
187
|
-
height: "8px",
|
|
188
|
-
boxShadow: "0 0 2px rgba(0, 0, 0, .6)",
|
|
189
|
-
background: "#fff",
|
|
190
|
-
marginTop: "1px",
|
|
191
|
-
transform: "translateX(-2px)"
|
|
192
|
-
} }) }) })
|
|
193
|
-
] });
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const VALIDATION_KEYS = /* @__PURE__ */ new Set(["r", "g", "b", "a", "h", "s", "l", "v"]), PERCENT_PATTERN = /^\d+%$/;
|
|
197
|
-
function simpleCheckForValidColor(data) {
|
|
198
|
-
if (typeof data == "string")
|
|
199
|
-
return data;
|
|
200
|
-
let checked = 0, passed = 0;
|
|
201
|
-
for (const [key, value] of Object.entries(data))
|
|
202
|
-
!VALIDATION_KEYS.has(key) || !value || (checked += 1, Number.isNaN(Number(value)) || (passed += 1), (key === "s" || key === "l") && PERCENT_PATTERN.test(String(value)) && (passed += 1));
|
|
203
|
-
return checked === passed ? data : !1;
|
|
204
|
-
}
|
|
205
|
-
function toState(data, oldHue) {
|
|
206
|
-
const instance = typeof data == "string" ? tinycolor(data) : "hex" in data ? tinycolor(data.hex) : tinycolor(data), hsl = instance.toHsl(), hsv = instance.toHsv(), rgb = instance.toRgb(), hex = instance.toHex();
|
|
207
|
-
hsl.s === 0 && (hsl.h = oldHue ?? 0, hsv.h = oldHue ?? 0);
|
|
208
|
-
const transparent = hex === "000000" && rgb.a === 0, incomingHue = typeof data == "string" ? void 0 : "h" in data ? data.h : void 0, source = typeof data == "string" ? void 0 : data.source;
|
|
209
|
-
return {
|
|
210
|
-
hsl,
|
|
211
|
-
hex: transparent ? "transparent" : `#${hex}`,
|
|
212
|
-
rgb,
|
|
213
|
-
hsv,
|
|
214
|
-
oldHue: incomingHue || oldHue || hsl.h,
|
|
215
|
-
source: source ?? ""
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
function isValidHex(hex) {
|
|
219
|
-
if (hex === "transparent")
|
|
220
|
-
return !0;
|
|
221
|
-
const lh = hex.charAt(0) === "#" ? 1 : 0;
|
|
222
|
-
return hex.length !== 4 + lh && hex.length < 7 + lh && tinycolor(hex).isValid();
|
|
223
|
-
}
|
|
224
|
-
const DEFAULT_COLOR$1 = {
|
|
225
|
-
h: 250,
|
|
226
|
-
s: 0.5,
|
|
227
|
-
l: 0.2,
|
|
228
|
-
a: 1
|
|
229
|
-
};
|
|
230
|
-
function CustomPicker(Picker) {
|
|
231
|
-
class ColorPicker2 extends PureComponent {
|
|
232
|
-
static getDerivedStateFromProps(nextProps, state) {
|
|
233
|
-
return {
|
|
234
|
-
...toState(nextProps.color ?? DEFAULT_COLOR$1, state.oldHue)
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
constructor(props) {
|
|
238
|
-
super(props), this.state = {
|
|
239
|
-
...toState(props.color ?? DEFAULT_COLOR$1, 0)
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
handleChange = (data) => {
|
|
243
|
-
if (!simpleCheckForValidColor(data))
|
|
244
|
-
return;
|
|
245
|
-
const incomingHue = typeof data == "string" ? void 0 : "h" in data ? data.h : void 0, colors = toState(data, incomingHue || this.state.oldHue);
|
|
246
|
-
this.setState(colors), this.props.onChange?.(colors);
|
|
247
|
-
};
|
|
248
|
-
render() {
|
|
249
|
-
const injected = {
|
|
250
|
-
hsl: this.state.hsl,
|
|
251
|
-
hsv: this.state.hsv,
|
|
252
|
-
rgb: this.state.rgb,
|
|
253
|
-
hex: this.state.hex,
|
|
254
|
-
oldHue: this.state.oldHue,
|
|
255
|
-
source: this.state.source,
|
|
256
|
-
onChange: this.handleChange
|
|
257
|
-
}, pickerProps = {
|
|
258
|
-
...this.props,
|
|
259
|
-
...injected
|
|
260
|
-
};
|
|
261
|
-
return /* @__PURE__ */ jsx(Picker, { ...pickerProps });
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return ColorPicker2;
|
|
265
|
-
}
|
|
266
|
-
const DEFAULT_ARROW_OFFSET = 1, getNumberValue = (value) => Number(String(value).replace(/%/g, ""));
|
|
267
|
-
let idCounter = 1;
|
|
268
|
-
class EditableInput extends Component {
|
|
269
|
-
input = null;
|
|
270
|
-
constructor(props) {
|
|
271
|
-
super(props);
|
|
272
|
-
const initialValue = String(props.value ?? "").toUpperCase();
|
|
273
|
-
this.state = {
|
|
274
|
-
value: initialValue,
|
|
275
|
-
blurValue: initialValue
|
|
276
|
-
}, this.inputId = `rc-editable-input-${idCounter++}`;
|
|
277
|
-
}
|
|
278
|
-
componentDidUpdate(prevProps, prevState) {
|
|
279
|
-
if (this.props.value !== this.state.value && (prevProps.value !== this.props.value || prevState.value !== this.state.value)) {
|
|
280
|
-
const nextValue = String(this.props.value ?? "").toUpperCase(), isFocused = this.input === document.activeElement;
|
|
281
|
-
this.setState(isFocused ? {
|
|
282
|
-
blurValue: nextValue
|
|
283
|
-
} : {
|
|
284
|
-
value: nextValue,
|
|
285
|
-
blurValue: this.state.blurValue ? "" : nextValue
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
componentWillUnmount() {
|
|
290
|
-
this.unbindEventListeners();
|
|
291
|
-
}
|
|
292
|
-
setInputRef = (input) => {
|
|
293
|
-
this.input = input;
|
|
294
|
-
};
|
|
295
|
-
getValueObjectWithLabel = (value) => ({
|
|
296
|
-
[this.props.label]: String(value)
|
|
297
|
-
});
|
|
298
|
-
getArrowOffset = () => this.props.arrowOffset ?? DEFAULT_ARROW_OFFSET;
|
|
299
|
-
setUpdatedValue = (value, event) => {
|
|
300
|
-
this.props.onChange?.(this.getValueObjectWithLabel(value), event), this.setState({
|
|
301
|
-
value: String(value)
|
|
302
|
-
});
|
|
303
|
-
};
|
|
304
|
-
handleBlur = () => {
|
|
305
|
-
this.state.blurValue && this.setState({
|
|
306
|
-
value: this.state.blurValue,
|
|
307
|
-
blurValue: ""
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
handleChange = (event) => {
|
|
311
|
-
this.setUpdatedValue(event.target.value, event);
|
|
312
|
-
};
|
|
313
|
-
handleKeyDown = (event) => {
|
|
314
|
-
const value = getNumberValue(event.currentTarget.value), isUp = event.key === "ArrowUp", isDown = event.key === "ArrowDown";
|
|
315
|
-
if (!Number.isNaN(value) && (isUp || isDown)) {
|
|
316
|
-
const offset = this.getArrowOffset(), updatedValue = isUp ? value + offset : value - offset;
|
|
317
|
-
this.setUpdatedValue(updatedValue, event);
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
handleDrag = (event) => {
|
|
321
|
-
if (!this.props.dragLabel)
|
|
322
|
-
return;
|
|
323
|
-
const {
|
|
324
|
-
dragMax,
|
|
325
|
-
value
|
|
326
|
-
} = this.props, numericValue = typeof value == "number" ? value : Number(value), newValue = Math.round(numericValue + event.movementX);
|
|
327
|
-
dragMax !== void 0 && newValue >= 0 && newValue <= dragMax && this.props.onChange?.(this.getValueObjectWithLabel(newValue), event);
|
|
328
|
-
};
|
|
329
|
-
handleMouseDown = (event) => {
|
|
330
|
-
this.props.dragLabel && (event.preventDefault(), this.handleDrag(event.nativeEvent), window.addEventListener("mousemove", this.handleDrag), window.addEventListener("mouseup", this.handleMouseUp));
|
|
331
|
-
};
|
|
332
|
-
handleMouseUp = () => {
|
|
333
|
-
this.unbindEventListeners();
|
|
334
|
-
};
|
|
335
|
-
unbindEventListeners = () => {
|
|
336
|
-
window.removeEventListener("mousemove", this.handleDrag), window.removeEventListener("mouseup", this.handleMouseUp);
|
|
337
|
-
};
|
|
338
|
-
render() {
|
|
339
|
-
const style = this.props.style ?? {}, wrapStyle = {
|
|
340
|
-
position: "relative",
|
|
341
|
-
...style.wrap
|
|
342
|
-
}, inputStyle = {
|
|
343
|
-
...style.input
|
|
344
|
-
}, labelStyle = {
|
|
345
|
-
...style.label,
|
|
346
|
-
...this.props.dragLabel ? {
|
|
347
|
-
cursor: "ew-resize"
|
|
348
|
-
} : null
|
|
349
|
-
};
|
|
350
|
-
return /* @__PURE__ */ jsxs("div", { style: wrapStyle, children: [
|
|
351
|
-
/* @__PURE__ */ jsx("input", { id: this.inputId, style: inputStyle, ref: this.setInputRef, value: this.state.value, onKeyDown: this.handleKeyDown, onChange: this.handleChange, onBlur: this.handleBlur, placeholder: this.props.placeholder, spellCheck: "false" }),
|
|
352
|
-
this.props.label && !this.props.hideLabel ? (
|
|
353
|
-
// oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- the label is a drag affordance using pointer coordinates; the input also supports arrow-key stepping
|
|
354
|
-
/* @__PURE__ */ jsx("label", { htmlFor: this.inputId, style: labelStyle, onMouseDown: this.handleMouseDown, children: this.props.label })
|
|
355
|
-
) : null
|
|
356
|
-
] });
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
function calculateChange$1(e, direction, hsl, container) {
|
|
360
|
-
const containerWidth = container.clientWidth, containerHeight = container.clientHeight, x = "touches" in e ? e.touches[0]?.pageX ?? 0 : e.pageX, y = "touches" in e ? e.touches[0]?.pageY ?? 0 : e.pageY, left = x - (container.getBoundingClientRect().left + window.scrollX), top = y - (container.getBoundingClientRect().top + window.scrollY);
|
|
361
|
-
if (direction === "vertical") {
|
|
362
|
-
let h2;
|
|
363
|
-
return top < 0 ? h2 = 359 : top > containerHeight ? h2 = 0 : h2 = 360 * (-(top * 100 / containerHeight) + 100) / 100, hsl.h !== h2 ? {
|
|
364
|
-
h: h2,
|
|
365
|
-
s: hsl.s,
|
|
366
|
-
l: hsl.l,
|
|
367
|
-
a: hsl.a ?? 1,
|
|
368
|
-
source: "hsl"
|
|
369
|
-
} : null;
|
|
370
|
-
}
|
|
371
|
-
let h;
|
|
372
|
-
return left < 0 ? h = 0 : left > containerWidth ? h = 359 : h = 360 * (left * 100 / containerWidth) / 100, hsl.h !== h ? {
|
|
373
|
-
h,
|
|
374
|
-
s: hsl.s,
|
|
375
|
-
l: hsl.l,
|
|
376
|
-
a: hsl.a ?? 1,
|
|
377
|
-
source: "hsl"
|
|
378
|
-
} : null;
|
|
379
|
-
}
|
|
380
|
-
const HueGradient = /* @__PURE__ */ styled.div.withConfig({
|
|
381
|
-
displayName: "HueGradient",
|
|
382
|
-
componentId: "sc-9dykdk-0"
|
|
383
|
-
})(["background:", ";"], ({
|
|
384
|
-
$direction
|
|
385
|
-
}) => $direction === "vertical" ? "linear-gradient(to top, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)" : "linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%)");
|
|
386
|
-
class Hue extends Component {
|
|
387
|
-
container = null;
|
|
388
|
-
componentWillUnmount() {
|
|
389
|
-
this.unbindEventListeners();
|
|
390
|
-
}
|
|
391
|
-
setContainerRef = (node) => {
|
|
392
|
-
this.container = node;
|
|
393
|
-
};
|
|
394
|
-
handleChange = (event) => {
|
|
395
|
-
if (!this.container)
|
|
396
|
-
return;
|
|
397
|
-
const change = calculateChange$1(event, this.props.direction, this.props.hsl, this.container);
|
|
398
|
-
change && typeof this.props.onChange == "function" && this.props.onChange(change);
|
|
399
|
-
};
|
|
400
|
-
handleMouseDown = (event) => {
|
|
401
|
-
this.handleChange(event.nativeEvent), window.addEventListener("mousemove", this.handleChange), window.addEventListener("mouseup", this.handleMouseUp);
|
|
402
|
-
};
|
|
403
|
-
handleMouseUp = () => {
|
|
404
|
-
this.unbindEventListeners();
|
|
405
|
-
};
|
|
406
|
-
unbindEventListeners = () => {
|
|
407
|
-
window.removeEventListener("mousemove", this.handleChange), window.removeEventListener("mouseup", this.handleMouseUp);
|
|
408
|
-
};
|
|
409
|
-
render() {
|
|
410
|
-
const {
|
|
411
|
-
hsl,
|
|
412
|
-
direction = "horizontal",
|
|
413
|
-
radius,
|
|
414
|
-
shadow
|
|
415
|
-
} = this.props, pointerStyle = direction === "vertical" ? {
|
|
416
|
-
position: "absolute",
|
|
417
|
-
left: "0px",
|
|
418
|
-
top: `${-(hsl.h * 100 / 360) + 100}%`
|
|
419
|
-
} : {
|
|
420
|
-
position: "absolute",
|
|
421
|
-
left: `${hsl.h * 100 / 360}%`
|
|
422
|
-
};
|
|
423
|
-
return /* @__PURE__ */ jsx("div", { style: {
|
|
424
|
-
position: "absolute",
|
|
425
|
-
inset: 0,
|
|
426
|
-
borderRadius: radius,
|
|
427
|
-
boxShadow: shadow
|
|
428
|
-
}, children: /* @__PURE__ */ jsx(HueGradient, { $direction: direction, style: {
|
|
429
|
-
padding: "0 2px",
|
|
430
|
-
position: "relative",
|
|
431
|
-
height: "100%",
|
|
432
|
-
borderRadius: radius
|
|
433
|
-
}, ref: this.setContainerRef, onMouseDown: this.handleMouseDown, onTouchMove: this.handleChange, onTouchStart: this.handleChange, children: /* @__PURE__ */ jsx("div", { style: pointerStyle, children: /* @__PURE__ */ jsx("div", { style: {
|
|
434
|
-
marginTop: "1px",
|
|
435
|
-
width: "4px",
|
|
436
|
-
borderRadius: "1px",
|
|
437
|
-
height: "8px",
|
|
438
|
-
boxShadow: "0 0 2px rgba(0, 0, 0, .6)",
|
|
439
|
-
background: "#fff",
|
|
440
|
-
transform: "translateX(-2px)"
|
|
441
|
-
} }) }) }) });
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
function calculateChange(e, hsl, container) {
|
|
445
|
-
const {
|
|
446
|
-
width: containerWidth,
|
|
447
|
-
height: containerHeight
|
|
448
|
-
} = container.getBoundingClientRect(), x = "touches" in e ? e.touches[0]?.pageX ?? 0 : e.pageX, y = "touches" in e ? e.touches[0]?.pageY ?? 0 : e.pageY;
|
|
449
|
-
let left = x - (container.getBoundingClientRect().left + window.scrollX), top = y - (container.getBoundingClientRect().top + window.scrollY);
|
|
450
|
-
left < 0 ? left = 0 : left > containerWidth && (left = containerWidth), top < 0 ? top = 0 : top > containerHeight && (top = containerHeight);
|
|
451
|
-
const saturation = left / containerWidth, bright = 1 - top / containerHeight;
|
|
452
|
-
return {
|
|
453
|
-
h: hsl.h,
|
|
454
|
-
s: saturation,
|
|
455
|
-
v: bright,
|
|
456
|
-
a: hsl.a ?? 1,
|
|
457
|
-
source: "hsv"
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
const SaturationWhite = /* @__PURE__ */ styled.div.withConfig({
|
|
461
|
-
displayName: "SaturationWhite",
|
|
462
|
-
componentId: "sc-21ffrq-0"
|
|
463
|
-
})(["background:linear-gradient(to right,#fff,rgba(255,255,255,0));"]), SaturationBlack = /* @__PURE__ */ styled.div.withConfig({
|
|
464
|
-
displayName: "SaturationBlack",
|
|
465
|
-
componentId: "sc-21ffrq-1"
|
|
466
|
-
})(["background:linear-gradient(to top,#000,rgba(0,0,0,0));"]);
|
|
467
|
-
class Saturation extends Component {
|
|
468
|
-
container = null;
|
|
469
|
-
throttle = throttle((handler, data) => {
|
|
470
|
-
handler(data);
|
|
471
|
-
}, 50);
|
|
472
|
-
componentWillUnmount() {
|
|
473
|
-
this.throttle.cancel(), this.unbindEventListeners();
|
|
474
|
-
}
|
|
475
|
-
setContainerRef = (node) => {
|
|
476
|
-
this.container = node;
|
|
477
|
-
};
|
|
478
|
-
getContainerRenderWindow() {
|
|
479
|
-
const {
|
|
480
|
-
container
|
|
481
|
-
} = this;
|
|
482
|
-
let renderWindow = window;
|
|
483
|
-
for (; !renderWindow.document.contains(container) && renderWindow.parent !== renderWindow; )
|
|
484
|
-
renderWindow = renderWindow.parent;
|
|
485
|
-
return renderWindow;
|
|
486
|
-
}
|
|
487
|
-
handleChange = (event) => {
|
|
488
|
-
!this.container || typeof this.props.onChange != "function" || this.throttle(this.props.onChange, calculateChange(event, this.props.hsl, this.container));
|
|
489
|
-
};
|
|
490
|
-
handleMouseDown = (event) => {
|
|
491
|
-
this.handleChange(event.nativeEvent);
|
|
492
|
-
const renderWindow = this.getContainerRenderWindow();
|
|
493
|
-
renderWindow.addEventListener("mousemove", this.handleChange), renderWindow.addEventListener("mouseup", this.handleMouseUp);
|
|
494
|
-
};
|
|
495
|
-
handleMouseUp = () => {
|
|
496
|
-
this.unbindEventListeners();
|
|
497
|
-
};
|
|
498
|
-
unbindEventListeners = () => {
|
|
499
|
-
const renderWindow = this.getContainerRenderWindow();
|
|
500
|
-
renderWindow.removeEventListener("mousemove", this.handleChange), renderWindow.removeEventListener("mouseup", this.handleMouseUp);
|
|
501
|
-
};
|
|
502
|
-
render() {
|
|
503
|
-
const {
|
|
504
|
-
hsl,
|
|
505
|
-
hsv,
|
|
506
|
-
radius,
|
|
507
|
-
shadow
|
|
508
|
-
} = this.props, pointerStyle = {
|
|
509
|
-
position: "absolute",
|
|
510
|
-
top: `${-(hsv.v * 100) + 100}%`,
|
|
511
|
-
left: `${hsv.s * 100}%`,
|
|
512
|
-
cursor: "default"
|
|
513
|
-
};
|
|
514
|
-
return (
|
|
515
|
-
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- the picker surface is dragged via pointer coordinates, which have no keyboard equivalent
|
|
516
|
-
/* @__PURE__ */ jsx("div", { style: {
|
|
517
|
-
position: "absolute",
|
|
518
|
-
inset: 0,
|
|
519
|
-
background: `hsl(${hsl.h},100%, 50%)`,
|
|
520
|
-
borderRadius: radius
|
|
521
|
-
}, ref: this.setContainerRef, onMouseDown: this.handleMouseDown, onTouchMove: this.handleChange, onTouchStart: this.handleChange, children: /* @__PURE__ */ jsxs(SaturationWhite, { style: {
|
|
522
|
-
position: "absolute",
|
|
523
|
-
inset: 0,
|
|
524
|
-
borderRadius: radius
|
|
525
|
-
}, children: [
|
|
526
|
-
/* @__PURE__ */ jsx(SaturationBlack, { style: {
|
|
527
|
-
position: "absolute",
|
|
528
|
-
inset: 0,
|
|
529
|
-
boxShadow: shadow,
|
|
530
|
-
borderRadius: radius
|
|
531
|
-
} }),
|
|
532
|
-
/* @__PURE__ */ jsx("div", { style: pointerStyle, children: /* @__PURE__ */ jsx("div", { style: {
|
|
533
|
-
width: "4px",
|
|
534
|
-
height: "4px",
|
|
535
|
-
boxShadow: "0 0 0 1.5px #fff, inset 0 0 1px 1px rgba(0,0,0,.3), 0 0 1px 2px rgba(0,0,0,.4)",
|
|
536
|
-
borderRadius: "50%",
|
|
537
|
-
cursor: "pointer",
|
|
538
|
-
transform: "translate(-2px, -2px)"
|
|
539
|
-
} }) })
|
|
540
|
-
] }) })
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
const ColorPickerFields = (t0) => {
|
|
545
|
-
const $ = c(44), {
|
|
546
|
-
onChange,
|
|
547
|
-
rgb,
|
|
548
|
-
hsl,
|
|
549
|
-
hex,
|
|
550
|
-
disableAlpha
|
|
551
|
-
} = t0, {
|
|
552
|
-
sanity
|
|
553
|
-
} = useTheme(), t1 = `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`, t2 = sanity.fonts.text.sizes[0]?.fontSize;
|
|
554
|
-
let t3;
|
|
555
|
-
$[0] !== sanity.color.input.default.enabled.bg || $[1] !== sanity.color.input.default.enabled.fg || $[2] !== t1 || $[3] !== t2 ? (t3 = {
|
|
556
|
-
width: "80%",
|
|
557
|
-
padding: "4px 10% 3px",
|
|
558
|
-
border: "none",
|
|
559
|
-
boxShadow: t1,
|
|
560
|
-
color: sanity.color.input.default.enabled.fg,
|
|
561
|
-
backgroundColor: sanity.color.input.default.enabled.bg,
|
|
562
|
-
fontSize: t2,
|
|
563
|
-
textAlign: "center"
|
|
564
|
-
}, $[0] = sanity.color.input.default.enabled.bg, $[1] = sanity.color.input.default.enabled.fg, $[2] = t1, $[3] = t2, $[4] = t3) : t3 = $[4];
|
|
565
|
-
const t4 = sanity.fonts.label.sizes[0]?.fontSize;
|
|
566
|
-
let t5;
|
|
567
|
-
$[5] !== sanity.color.base.fg || $[6] !== t4 ? (t5 = {
|
|
568
|
-
display: "block",
|
|
569
|
-
textAlign: "center",
|
|
570
|
-
fontSize: t4,
|
|
571
|
-
color: sanity.color.base.fg,
|
|
572
|
-
paddingTop: "3px",
|
|
573
|
-
paddingBottom: "4px",
|
|
574
|
-
textTransform: "capitalize"
|
|
575
|
-
}, $[5] = sanity.color.base.fg, $[6] = t4, $[7] = t5) : t5 = $[7];
|
|
576
|
-
let t6;
|
|
577
|
-
$[8] !== t3 || $[9] !== t5 ? (t6 = {
|
|
578
|
-
input: t3,
|
|
579
|
-
label: t5
|
|
580
|
-
}, $[8] = t3, $[9] = t5, $[10] = t6) : t6 = $[10];
|
|
581
|
-
const inputStyles = t6;
|
|
582
|
-
let t7;
|
|
583
|
-
$[11] !== hsl || $[12] !== onChange || $[13] !== rgb ? (t7 = (data) => {
|
|
584
|
-
if ("hex" in data && data.hex && isValidHex(data.hex))
|
|
585
|
-
onChange({
|
|
586
|
-
hex: data.hex,
|
|
587
|
-
source: "hex"
|
|
588
|
-
});
|
|
589
|
-
else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b))
|
|
590
|
-
onChange({
|
|
591
|
-
r: Number(data.r) || rgb.r,
|
|
592
|
-
g: Number(data.g) || rgb.g,
|
|
593
|
-
b: Number(data.b) || rgb.b,
|
|
594
|
-
a: rgb.a,
|
|
595
|
-
source: "rgb"
|
|
596
|
-
});
|
|
597
|
-
else if (hsl && "a" in data && data.a) {
|
|
598
|
-
let alpha = Number(data.a);
|
|
599
|
-
alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha = alpha / 100, onChange({
|
|
600
|
-
h: hsl.h,
|
|
601
|
-
s: hsl.s,
|
|
602
|
-
l: hsl.l,
|
|
603
|
-
a: alpha,
|
|
604
|
-
source: "hsl"
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
}, $[11] = hsl, $[12] = onChange, $[13] = rgb, $[14] = t7) : t7 = $[14];
|
|
608
|
-
const handleChange = t7;
|
|
609
|
-
let t8;
|
|
610
|
-
$[15] !== hex ? (t8 = hex?.replace("#", ""), $[15] = hex, $[16] = t8) : t8 = $[16];
|
|
611
|
-
let t9;
|
|
612
|
-
$[17] !== handleChange || $[18] !== inputStyles || $[19] !== t8 ? (t9 = /* @__PURE__ */ jsx(Box, { flex: 2, marginRight: 1, children: /* @__PURE__ */ jsx(EditableInput, { style: inputStyles, label: "hex", value: t8, onChange: handleChange }) }), $[17] = handleChange, $[18] = inputStyles, $[19] = t8, $[20] = t9) : t9 = $[20];
|
|
613
|
-
const t10 = rgb?.r;
|
|
614
|
-
let t11;
|
|
615
|
-
$[21] !== handleChange || $[22] !== inputStyles || $[23] !== t10 ? (t11 = /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(EditableInput, { style: inputStyles, label: "r", value: t10, onChange: handleChange, dragLabel: !0, dragMax: 255 }) }), $[21] = handleChange, $[22] = inputStyles, $[23] = t10, $[24] = t11) : t11 = $[24];
|
|
616
|
-
const t12 = rgb?.g;
|
|
617
|
-
let t13;
|
|
618
|
-
$[25] !== handleChange || $[26] !== inputStyles || $[27] !== t12 ? (t13 = /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(EditableInput, { style: inputStyles, label: "g", value: t12, onChange: handleChange, dragLabel: !0, dragMax: 255 }) }), $[25] = handleChange, $[26] = inputStyles, $[27] = t12, $[28] = t13) : t13 = $[28];
|
|
619
|
-
const t14 = rgb?.b;
|
|
620
|
-
let t15;
|
|
621
|
-
$[29] !== handleChange || $[30] !== inputStyles || $[31] !== t14 ? (t15 = /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(EditableInput, { style: inputStyles, label: "b", value: t14, onChange: handleChange, dragLabel: !0, dragMax: 255 }) }), $[29] = handleChange, $[30] = inputStyles, $[31] = t14, $[32] = t15) : t15 = $[32];
|
|
622
|
-
let t16;
|
|
623
|
-
$[33] !== disableAlpha || $[34] !== handleChange || $[35] !== inputStyles || $[36] !== rgb?.a ? (t16 = !disableAlpha && /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(EditableInput, { style: inputStyles, label: "a", value: Math.round((rgb?.a ?? 1) * 100), onChange: handleChange, dragLabel: !0, dragMax: 100 }) }), $[33] = disableAlpha, $[34] = handleChange, $[35] = inputStyles, $[36] = rgb?.a, $[37] = t16) : t16 = $[37];
|
|
624
|
-
let t17;
|
|
625
|
-
return $[38] !== t11 || $[39] !== t13 || $[40] !== t15 || $[41] !== t16 || $[42] !== t9 ? (t17 = /* @__PURE__ */ jsxs(Flex, { children: [
|
|
626
|
-
t9,
|
|
627
|
-
t11,
|
|
628
|
-
t13,
|
|
629
|
-
t15,
|
|
630
|
-
t16
|
|
631
|
-
] }), $[38] = t11, $[39] = t13, $[40] = t15, $[41] = t16, $[42] = t9, $[43] = t17) : t17 = $[43], t17;
|
|
632
|
-
}, ColorBox = /* @__PURE__ */ styled(Box).withConfig({
|
|
633
|
-
displayName: "ColorBox",
|
|
634
|
-
componentId: "sc-13q7kbw-0"
|
|
635
|
-
})(["position:absolute;top:0;left:0;width:100%;height:100%;"]), ReadOnlyContainer = /* @__PURE__ */ styled(Flex).withConfig({
|
|
636
|
-
displayName: "ReadOnlyContainer",
|
|
637
|
-
componentId: "sc-13q7kbw-1"
|
|
638
|
-
})(["margin-top:6rem;background-color:var(--card-bg-color);position:relative;width:100%;"]), ColorPickerInner = (props) => {
|
|
639
|
-
const $ = c(46), {
|
|
640
|
-
width,
|
|
641
|
-
color: t0,
|
|
642
|
-
onChange,
|
|
643
|
-
onUnset,
|
|
644
|
-
disableAlpha,
|
|
645
|
-
colorList,
|
|
646
|
-
readOnly
|
|
647
|
-
} = props, {
|
|
648
|
-
rgb,
|
|
649
|
-
hex,
|
|
650
|
-
hsv,
|
|
651
|
-
hsl
|
|
652
|
-
} = t0;
|
|
653
|
-
if (!hsl || !hsv)
|
|
654
|
-
return null;
|
|
655
|
-
let t1;
|
|
656
|
-
$[0] !== width ? (t1 = {
|
|
657
|
-
width
|
|
658
|
-
}, $[0] = width, $[1] = t1) : t1 = $[1];
|
|
659
|
-
let t2;
|
|
660
|
-
$[2] !== disableAlpha || $[3] !== hsl || $[4] !== hsv || $[5] !== onChange || $[6] !== readOnly || $[7] !== rgb ? (t2 = !readOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
661
|
-
/* @__PURE__ */ jsx(Card, { overflow: "hidden", style: {
|
|
662
|
-
position: "relative",
|
|
663
|
-
height: "5em"
|
|
664
|
-
}, children: /* @__PURE__ */ jsx(Saturation, { onChange, hsl, hsv }) }),
|
|
665
|
-
/* @__PURE__ */ jsx(Card, { shadow: 1, radius: 3, overflow: "hidden", style: {
|
|
666
|
-
position: "relative",
|
|
667
|
-
height: "10px"
|
|
668
|
-
}, children: /* @__PURE__ */ jsx(Hue, { hsl, onChange: !readOnly && onChange }) }),
|
|
669
|
-
!disableAlpha && /* @__PURE__ */ jsx(Card, { shadow: 1, radius: 3, overflow: "hidden", style: {
|
|
670
|
-
position: "relative",
|
|
671
|
-
height: "10px",
|
|
672
|
-
background: "#fff"
|
|
673
|
-
}, children: /* @__PURE__ */ jsx(Alpha, { rgb, hsl, onChange }) })
|
|
674
|
-
] }), $[2] = disableAlpha, $[3] = hsl, $[4] = hsv, $[5] = onChange, $[6] = readOnly, $[7] = rgb, $[8] = t2) : t2 = $[8];
|
|
675
|
-
let t3, t4;
|
|
676
|
-
$[9] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = {
|
|
677
|
-
position: "relative",
|
|
678
|
-
minWidth: "4em",
|
|
679
|
-
background: "#fff"
|
|
680
|
-
}, t4 = /* @__PURE__ */ jsx(Checkboard, { size: 8, white: "transparent", grey: "rgba(0,0,0,.08)" }), $[9] = t3, $[10] = t4) : (t3 = $[9], t4 = $[10]);
|
|
681
|
-
const t5 = `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`;
|
|
682
|
-
let t6;
|
|
683
|
-
$[11] !== t5 ? (t6 = /* @__PURE__ */ jsx(ColorBox, { style: {
|
|
684
|
-
backgroundColor: t5
|
|
685
|
-
} }), $[11] = t5, $[12] = t6) : t6 = $[12];
|
|
686
|
-
let t7;
|
|
687
|
-
$[13] !== hex || $[14] !== hsl?.h || $[15] !== hsl?.l || $[16] !== hsl?.s || $[17] !== readOnly || $[18] !== rgb?.b || $[19] !== rgb?.g || $[20] !== rgb?.r ? (t7 = readOnly && /* @__PURE__ */ jsx(ReadOnlyContainer, { padding: 2, paddingBottom: 1, sizing: "border", justify: "space-between", children: /* @__PURE__ */ jsxs(Stack, { gap: 3, marginTop: 1, children: [
|
|
688
|
-
/* @__PURE__ */ jsx(Text, { size: 3, weight: "bold", children: hex }),
|
|
689
|
-
/* @__PURE__ */ jsxs(Inline, { gap: 3, children: [
|
|
690
|
-
/* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
691
|
-
/* @__PURE__ */ jsx("strong", { children: "RGB: " }),
|
|
692
|
-
rgb?.r,
|
|
693
|
-
" ",
|
|
694
|
-
rgb?.g,
|
|
695
|
-
" ",
|
|
696
|
-
rgb?.b
|
|
697
|
-
] }),
|
|
698
|
-
/* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
699
|
-
/* @__PURE__ */ jsx("strong", { children: "HSL: " }),
|
|
700
|
-
" ",
|
|
701
|
-
Math.round(hsl?.h ?? 0),
|
|
702
|
-
" ",
|
|
703
|
-
Math.round((hsl?.s ?? 0) * 100),
|
|
704
|
-
"% ",
|
|
705
|
-
Math.round((hsl?.l ?? 0) * 100),
|
|
706
|
-
"%"
|
|
707
|
-
] })
|
|
708
|
-
] })
|
|
709
|
-
] }) }), $[13] = hex, $[14] = hsl?.h, $[15] = hsl?.l, $[16] = hsl?.s, $[17] = readOnly, $[18] = rgb?.b, $[19] = rgb?.g, $[20] = rgb?.r, $[21] = t7) : t7 = $[21];
|
|
710
|
-
let t8;
|
|
711
|
-
$[22] !== t6 || $[23] !== t7 ? (t8 = /* @__PURE__ */ jsxs(Card, { flex: 1, radius: 2, overflow: "hidden", style: t3, children: [
|
|
712
|
-
t4,
|
|
713
|
-
t6,
|
|
714
|
-
t7
|
|
715
|
-
] }), $[22] = t6, $[23] = t7, $[24] = t8) : t8 = $[24];
|
|
716
|
-
let t9;
|
|
717
|
-
$[25] !== disableAlpha || $[26] !== hex || $[27] !== hsl || $[28] !== onChange || $[29] !== onUnset || $[30] !== readOnly || $[31] !== rgb ? (t9 = !readOnly && /* @__PURE__ */ jsxs(Flex, { align: "flex-start", marginLeft: 2, children: [
|
|
718
|
-
/* @__PURE__ */ jsx(Box, { style: {
|
|
719
|
-
width: 200
|
|
720
|
-
}, children: /* @__PURE__ */ jsx(ColorPickerFields, { rgb, hsl, hex, onChange, disableAlpha }) }),
|
|
721
|
-
/* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Button, { onClick: onUnset, title: "Delete color", icon: TrashIcon, tone: "critical" }) })
|
|
722
|
-
] }), $[25] = disableAlpha, $[26] = hex, $[27] = hsl, $[28] = onChange, $[29] = onUnset, $[30] = readOnly, $[31] = rgb, $[32] = t9) : t9 = $[32];
|
|
723
|
-
let t10;
|
|
724
|
-
$[33] !== t8 || $[34] !== t9 ? (t10 = /* @__PURE__ */ jsxs(Flex, { children: [
|
|
725
|
-
t8,
|
|
726
|
-
t9
|
|
727
|
-
] }), $[33] = t8, $[34] = t9, $[35] = t10) : t10 = $[35];
|
|
728
|
-
let t11;
|
|
729
|
-
$[36] !== colorList || $[37] !== onChange ? (t11 = colorList && /* @__PURE__ */ jsx(ColorList, { colors: colorList, onChange }), $[36] = colorList, $[37] = onChange, $[38] = t11) : t11 = $[38];
|
|
730
|
-
let t12;
|
|
731
|
-
$[39] !== t10 || $[40] !== t11 || $[41] !== t2 ? (t12 = /* @__PURE__ */ jsx(Card, { padding: 1, border: !0, radius: 1, children: /* @__PURE__ */ jsxs(Stack, { gap: 2, children: [
|
|
732
|
-
t2,
|
|
733
|
-
t10,
|
|
734
|
-
t11
|
|
735
|
-
] }) }), $[39] = t10, $[40] = t11, $[41] = t2, $[42] = t12) : t12 = $[42];
|
|
736
|
-
let t13;
|
|
737
|
-
return $[43] !== t1 || $[44] !== t12 ? (t13 = /* @__PURE__ */ jsx("div", { style: t1, children: t12 }), $[43] = t1, $[44] = t12, $[45] = t13) : t13 = $[45], t13;
|
|
738
|
-
}, ColorPicker = CustomPicker(ColorPickerInner), DEFAULT_COLOR = {
|
|
739
|
-
hex: "#24a3e3",
|
|
740
|
-
hsl: {
|
|
741
|
-
h: 200,
|
|
742
|
-
s: 0.7732,
|
|
743
|
-
l: 0.5156,
|
|
744
|
-
a: 1
|
|
745
|
-
},
|
|
746
|
-
hsv: {
|
|
747
|
-
h: 200,
|
|
748
|
-
s: 0.8414,
|
|
749
|
-
v: 0.8901,
|
|
750
|
-
a: 1
|
|
751
|
-
},
|
|
752
|
-
rgb: {
|
|
753
|
-
r: 46,
|
|
754
|
-
g: 163,
|
|
755
|
-
b: 227,
|
|
756
|
-
a: 1
|
|
757
|
-
},
|
|
758
|
-
source: "hex"
|
|
759
|
-
};
|
|
760
|
-
function ColorInput(props) {
|
|
761
|
-
const $ = c(10), {
|
|
762
|
-
onChange,
|
|
763
|
-
readOnly
|
|
764
|
-
} = props, _value = props.value, [value, setColorOptimistic] = useOptimistic(_value), type = props.schemaType, focusRef = useRef(null);
|
|
765
|
-
let t0;
|
|
766
|
-
$[0] !== onChange || $[1] !== type ? (t0 = function(nextColor) {
|
|
767
|
-
const fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field_0) => {
|
|
768
|
-
const nextFieldValue = nextColor[field_0.name], isObject = field_0.type.jsonType === "object";
|
|
769
|
-
return set(isObject ? Object.assign({
|
|
770
|
-
_type: field_0.type.name
|
|
771
|
-
}, nextFieldValue) : nextFieldValue, [field_0.name]);
|
|
772
|
-
});
|
|
773
|
-
onChange([setIfMissing({
|
|
774
|
-
_type: type.name
|
|
775
|
-
}), set(type.name, ["_type"]), set(nextColor.rgb?.a, ["alpha"]), ...fieldPatches]);
|
|
776
|
-
}, $[0] = onChange, $[1] = type, $[2] = t0) : t0 = $[2];
|
|
777
|
-
const handleChange = t0;
|
|
778
|
-
let t1;
|
|
779
|
-
return $[3] !== handleChange || $[4] !== onChange || $[5] !== readOnly || $[6] !== setColorOptimistic || $[7] !== type || $[8] !== value ? (t1 = /* @__PURE__ */ jsx(Fragment, { children: value && value.hex ? /* @__PURE__ */ jsx(ColorPicker, { color: value, onChange: (nextColor_0) => startTransition(() => {
|
|
780
|
-
setColorOptimistic(nextColor_0), handleChange(nextColor_0);
|
|
781
|
-
}), readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly, disableAlpha: !!type.options?.disableAlpha, colorList: type.options?.colorList, onUnset: () => startTransition(() => {
|
|
782
|
-
setColorOptimistic(void 0), onChange(unset());
|
|
783
|
-
}) }) : /* @__PURE__ */ jsx(Button, { icon: AddIcon, mode: "ghost", text: "Create color", ref: focusRef, disabled: !!readOnly, onClick: () => startTransition(() => {
|
|
784
|
-
setColorOptimistic(DEFAULT_COLOR), handleChange(DEFAULT_COLOR);
|
|
785
|
-
}) }) }), $[3] = handleChange, $[4] = onChange, $[5] = readOnly, $[6] = setColorOptimistic, $[7] = type, $[8] = value, $[9] = t1) : t1 = $[9], t1;
|
|
786
|
-
}
|
|
787
|
-
export {
|
|
788
|
-
ColorInput as default
|
|
789
|
-
};
|
|
790
|
-
//# sourceMappingURL=ColorInput.js.map
|