@sanity/color-input 4.0.5 → 4.0.7

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.
@@ -0,0 +1,344 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { memo, useMemo, useCallback, useRef, useState, useEffect, startTransition, useDeferredValue } from "react";
3
+ import { CustomPicker } from "react-color";
4
+ import { EditableInput, Saturation, Hue, Alpha, Checkboard } from "react-color/lib/components/common";
5
+ import { set, setIfMissing, unset } from "sanity";
6
+ import { styled } from "styled-components";
7
+ import { useEffectEvent } from "use-effect-event";
8
+ import { AddIcon, TrashIcon } from "@sanity/icons";
9
+ import { Flex, useTheme, Box, Button, Card, Stack, Text, Inline } from "@sanity/ui";
10
+ import tinycolor from "tinycolor2";
11
+ import { isValidHex } from "react-color/lib/helpers/color";
12
+ const ColorListWrap = styled(Flex)`
13
+ gap: 0.25em;
14
+ `, ColorBoxContainer = styled.div`
15
+ width: 2.1em;
16
+ height: 2.1em;
17
+ cursor: pointer;
18
+ position: relative;
19
+ overflow: hidden;
20
+ border-radius: 3px;
21
+ background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')
22
+ left center #fff;
23
+ `, ColorBox$1 = styled.div`
24
+ border-radius: inherit;
25
+ box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);
26
+ content: '';
27
+ position: absolute;
28
+ inset: 0;
29
+ z-index: 1;
30
+ `, validateColors = (colors) => colors.reduce((cls, c) => {
31
+ const color = c.hex ? tinycolor(c.hex) : tinycolor(c);
32
+ return color.isValid() && cls.push({
33
+ color: c,
34
+ backgroundColor: color.toRgbString()
35
+ }), cls;
36
+ }, []), ColorList = memo(function({ colors, onChange }) {
37
+ return colors ? /* @__PURE__ */ jsx(ColorListWrap, { wrap: "wrap", children: validateColors(colors).map(({ color, backgroundColor }, idx) => /* @__PURE__ */ jsx(
38
+ ColorBoxContainer,
39
+ {
40
+ onClick: () => {
41
+ onChange(color);
42
+ },
43
+ children: /* @__PURE__ */ jsx(ColorBox$1, { style: { background: backgroundColor } })
44
+ },
45
+ `${backgroundColor}-${idx}`
46
+ )) }) : null;
47
+ }), ColorPickerFields = ({
48
+ onChange,
49
+ rgb,
50
+ hsl,
51
+ hex,
52
+ disableAlpha
53
+ }) => {
54
+ const { sanity } = useTheme(), inputStyles = useMemo(
55
+ () => ({
56
+ input: {
57
+ width: "80%",
58
+ padding: "4px 10% 3px",
59
+ border: "none",
60
+ boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,
61
+ color: sanity.color.input.default.enabled.fg,
62
+ backgroundColor: sanity.color.input.default.enabled.bg,
63
+ fontSize: sanity.fonts.text.sizes[0]?.fontSize,
64
+ textAlign: "center"
65
+ },
66
+ label: {
67
+ display: "block",
68
+ textAlign: "center",
69
+ fontSize: sanity.fonts.label.sizes[0]?.fontSize,
70
+ color: sanity.color.base.fg,
71
+ paddingTop: "3px",
72
+ paddingBottom: "4px",
73
+ textTransform: "capitalize"
74
+ }
75
+ }),
76
+ [sanity]
77
+ ), handleChange = useCallback(
78
+ (data) => {
79
+ if ("hex" in data && data.hex && isValidHex(data.hex))
80
+ onChange({
81
+ hex: data.hex,
82
+ source: "hex"
83
+ });
84
+ else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b))
85
+ onChange({
86
+ r: Number(data.r) || rgb.r,
87
+ g: Number(data.g) || rgb.g,
88
+ b: Number(data.b) || rgb.b,
89
+ a: rgb.a,
90
+ source: "rgb"
91
+ });
92
+ else if (hsl && "a" in data && data.a) {
93
+ let alpha = Number(data.a);
94
+ alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha /= 100, onChange({
95
+ h: hsl.h,
96
+ s: hsl.s,
97
+ l: hsl.l,
98
+ a: alpha,
99
+ source: "hsl"
100
+ });
101
+ }
102
+ },
103
+ [onChange, hsl, rgb]
104
+ );
105
+ return /* @__PURE__ */ jsxs(Flex, { children: [
106
+ /* @__PURE__ */ jsx(Box, { flex: 2, marginRight: 1, children: /* @__PURE__ */ jsx(
107
+ EditableInput,
108
+ {
109
+ style: inputStyles,
110
+ label: "hex",
111
+ value: hex?.replace("#", ""),
112
+ onChange: handleChange
113
+ }
114
+ ) }),
115
+ /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
116
+ EditableInput,
117
+ {
118
+ style: inputStyles,
119
+ label: "r",
120
+ value: rgb?.r,
121
+ onChange: handleChange,
122
+ dragLabel: !0,
123
+ dragMax: 255
124
+ }
125
+ ) }),
126
+ /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
127
+ EditableInput,
128
+ {
129
+ style: inputStyles,
130
+ label: "g",
131
+ value: rgb?.g,
132
+ onChange: handleChange,
133
+ dragLabel: !0,
134
+ dragMax: 255
135
+ }
136
+ ) }),
137
+ /* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
138
+ EditableInput,
139
+ {
140
+ style: inputStyles,
141
+ label: "b",
142
+ value: rgb?.b,
143
+ onChange: handleChange,
144
+ dragLabel: !0,
145
+ dragMax: 255
146
+ }
147
+ ) }),
148
+ !disableAlpha && /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(
149
+ EditableInput,
150
+ {
151
+ style: inputStyles,
152
+ label: "a",
153
+ value: Math.round((rgb?.a ?? 1) * 100),
154
+ onChange: handleChange,
155
+ dragLabel: !0,
156
+ dragMax: 100
157
+ }
158
+ ) })
159
+ ] });
160
+ }, ColorBox = styled(Box)`
161
+ position: absolute;
162
+ top: 0;
163
+ left: 0;
164
+ width: 100%;
165
+ height: 100%;
166
+ `, ReadOnlyContainer = styled(Flex)`
167
+ margin-top: 6rem;
168
+ background-color: var(--card-bg-color);
169
+ position: relative;
170
+ width: 100%;
171
+ `, ColorPickerInner = (props) => {
172
+ const {
173
+ width,
174
+ color: { rgb, hex, hsv, hsl },
175
+ onChange,
176
+ onUnset,
177
+ disableAlpha,
178
+ colorList,
179
+ readOnly
180
+ } = props;
181
+ return !hsl || !hsv ? null : /* @__PURE__ */ jsx("div", { style: { width }, children: /* @__PURE__ */ jsx(Card, { padding: 1, border: !0, radius: 1, children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
182
+ !readOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
183
+ /* @__PURE__ */ jsx(Card, { overflow: "hidden", style: { position: "relative", height: "5em" }, children: /* @__PURE__ */ jsx(Saturation, { onChange, hsl, hsv }) }),
184
+ /* @__PURE__ */ jsx(
185
+ Card,
186
+ {
187
+ shadow: 1,
188
+ radius: 3,
189
+ overflow: "hidden",
190
+ style: { position: "relative", height: "10px" },
191
+ children: /* @__PURE__ */ jsx(Hue, { hsl, onChange: !readOnly && onChange })
192
+ }
193
+ ),
194
+ !disableAlpha && /* @__PURE__ */ jsx(
195
+ Card,
196
+ {
197
+ shadow: 1,
198
+ radius: 3,
199
+ overflow: "hidden",
200
+ style: { position: "relative", height: "10px", background: "#fff" },
201
+ children: /* @__PURE__ */ jsx(Alpha, { rgb, hsl, onChange })
202
+ }
203
+ )
204
+ ] }),
205
+ /* @__PURE__ */ jsxs(Flex, { children: [
206
+ /* @__PURE__ */ jsxs(
207
+ Card,
208
+ {
209
+ flex: 1,
210
+ radius: 2,
211
+ overflow: "hidden",
212
+ style: { position: "relative", minWidth: "4em", background: "#fff" },
213
+ children: [
214
+ /* @__PURE__ */ jsx(
215
+ Checkboard,
216
+ {
217
+ size: 8,
218
+ white: "transparent",
219
+ grey: "rgba(0,0,0,.08)",
220
+ renderers: {}
221
+ }
222
+ ),
223
+ /* @__PURE__ */ jsx(
224
+ ColorBox,
225
+ {
226
+ style: {
227
+ backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`
228
+ }
229
+ }
230
+ ),
231
+ readOnly && /* @__PURE__ */ jsx(
232
+ ReadOnlyContainer,
233
+ {
234
+ padding: 2,
235
+ paddingBottom: 1,
236
+ sizing: "border",
237
+ justify: "space-between",
238
+ children: /* @__PURE__ */ jsxs(Stack, { space: 3, marginTop: 1, children: [
239
+ /* @__PURE__ */ jsx(Text, { size: 3, weight: "bold", children: hex }),
240
+ /* @__PURE__ */ jsxs(Inline, { space: 3, children: [
241
+ /* @__PURE__ */ jsxs(Text, { size: 1, children: [
242
+ /* @__PURE__ */ jsx("strong", { children: "RGB: " }),
243
+ rgb?.r,
244
+ " ",
245
+ rgb?.g,
246
+ " ",
247
+ rgb?.b
248
+ ] }),
249
+ /* @__PURE__ */ jsxs(Text, { size: 1, children: [
250
+ /* @__PURE__ */ jsx("strong", { children: "HSL: " }),
251
+ " ",
252
+ Math.round(hsl?.h ?? 0),
253
+ " ",
254
+ Math.round((hsl?.s ?? 0) * 100),
255
+ "% ",
256
+ Math.round((hsl?.l ?? 0) * 100),
257
+ "%"
258
+ ] })
259
+ ] })
260
+ ] })
261
+ }
262
+ )
263
+ ]
264
+ }
265
+ ),
266
+ !readOnly && /* @__PURE__ */ jsxs(Flex, { align: "flex-start", marginLeft: 2, children: [
267
+ /* @__PURE__ */ jsx(Box, { style: { width: 200 }, children: /* @__PURE__ */ jsx(
268
+ ColorPickerFields,
269
+ {
270
+ rgb,
271
+ hsl,
272
+ hex,
273
+ onChange,
274
+ disableAlpha
275
+ }
276
+ ) }),
277
+ /* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Button, { onClick: onUnset, title: "Delete color", icon: TrashIcon, tone: "critical" }) })
278
+ ] })
279
+ ] }),
280
+ colorList && /* @__PURE__ */ jsx(ColorList, { colors: colorList, onChange })
281
+ ] }) }) });
282
+ }, ColorPicker = CustomPicker(ColorPickerInner), DEFAULT_COLOR = {
283
+ hex: "#24a3e3",
284
+ hsl: { h: 200, s: 0.7732, l: 0.5156, a: 1 },
285
+ hsv: { h: 200, s: 0.8414, v: 0.8901, a: 1 },
286
+ rgb: { r: 46, g: 163, b: 227, a: 1 },
287
+ source: "hex"
288
+ };
289
+ function ColorInput(props) {
290
+ const { onChange, readOnly } = props, value = props.value, type = props.schemaType, focusRef = useRef(null), [color, setColor] = useState(value);
291
+ useEffect(() => startTransition(() => setColor(value)), [value]);
292
+ const [emitColor, setEmitColor] = useState(void 0), debouncedColor = useDeferredValue(emitColor), handleChange = useEffectEvent((nextColor) => {
293
+ const fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field) => {
294
+ const nextFieldValue = nextColor[field.name], isObject = field.type.jsonType === "object";
295
+ return set(
296
+ isObject ? Object.assign({ _type: field.type.name }, nextFieldValue) : nextFieldValue,
297
+ [field.name]
298
+ );
299
+ });
300
+ onChange([
301
+ setIfMissing({ _type: type.name }),
302
+ set(type.name, ["_type"]),
303
+ set(nextColor.rgb?.a, ["alpha"]),
304
+ ...fieldPatches
305
+ ]);
306
+ });
307
+ useEffect(() => {
308
+ if (!debouncedColor) return;
309
+ const raf = requestAnimationFrame(() => handleChange(debouncedColor));
310
+ return () => cancelAnimationFrame(raf);
311
+ }, [debouncedColor]);
312
+ const handleCreateColor = useCallback(() => {
313
+ setColor(DEFAULT_COLOR), setEmitColor(DEFAULT_COLOR);
314
+ }, []), handleColorChange = useCallback((nextColor) => {
315
+ setColor(nextColor), setEmitColor(nextColor);
316
+ }, []), handleUnset = useCallback(() => {
317
+ setColor(void 0), onChange(unset());
318
+ }, [onChange]);
319
+ return /* @__PURE__ */ jsx(Fragment, { children: value && value.hex ? /* @__PURE__ */ jsx(
320
+ ColorPicker,
321
+ {
322
+ color,
323
+ onChange: handleColorChange,
324
+ readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly,
325
+ disableAlpha: !!type.options?.disableAlpha,
326
+ colorList: type.options?.colorList,
327
+ onUnset: handleUnset
328
+ }
329
+ ) : /* @__PURE__ */ jsx(
330
+ Button,
331
+ {
332
+ icon: AddIcon,
333
+ mode: "ghost",
334
+ text: "Create color",
335
+ ref: focusRef,
336
+ disabled: !!readOnly,
337
+ onClick: handleCreateColor
338
+ }
339
+ ) });
340
+ }
341
+ export {
342
+ ColorInput as default
343
+ };
344
+ //# sourceMappingURL=ColorInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColorInput.js","sources":["../../src/ColorList.tsx","../../src/ColorPickerFields.tsx","../../src/ColorInput.tsx"],"sourcesContent":["import type {Color, ColorChangeHandler} from 'react-color'\n\nimport {memo} from 'react'\nimport {styled} from 'styled-components'\nimport tinycolor from 'tinycolor2'\n\nimport {Flex} from '@sanity/ui'\n\nconst ColorListWrap = styled(Flex)`\n gap: 0.25em;\n`\n\nconst ColorBoxContainer = styled.div`\n width: 2.1em;\n height: 2.1em;\n cursor: pointer;\n position: relative;\n overflow: hidden;\n border-radius: 3px;\n background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')\n left center #fff;\n`\n\nconst ColorBox = styled.div`\n border-radius: inherit;\n box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);\n content: '';\n position: absolute;\n inset: 0;\n z-index: 1;\n`\n\ninterface ValidatedColor {\n color: Color\n backgroundColor: string\n}\n\ninterface ColorListProps {\n colors?: Array<Color>\n onChange: ColorChangeHandler<Color>\n}\n\nconst validateColors = (colors: Array<Color>) =>\n colors.reduce((cls: Array<ValidatedColor>, c) => {\n // @ts-expect-error fix types later\n const color = c.hex ? tinycolor(c.hex) : tinycolor(c)\n if (color.isValid()) {\n cls.push({\n color: c,\n backgroundColor: color.toRgbString(),\n })\n }\n return cls\n }, [])\n\nexport const ColorList = memo(function ColorList({colors, onChange}: ColorListProps) {\n if (!colors) return null\n return (\n <ColorListWrap wrap=\"wrap\">\n {validateColors(colors).map(({color, backgroundColor}, idx) => (\n <ColorBoxContainer\n key={`${backgroundColor}-${idx}`}\n onClick={() => {\n onChange(color)\n }}\n >\n <ColorBox style={{background: backgroundColor}} />\n </ColorBoxContainer>\n ))}\n </ColorListWrap>\n )\n})\n","import type {Color, ColorChangeHandler, HSLColor, RGBColor} from 'react-color'\nimport type {EditableInputStyles} from 'react-color/lib/components/common/EditableInput'\n\nimport {useCallback, useMemo} from 'react'\nimport {EditableInput} from 'react-color/lib/components/common'\n// @ts-expect-error missing export\nimport {isValidHex} from 'react-color/lib/helpers/color'\n\nimport {Box, Flex, useTheme} from '@sanity/ui'\n\ninterface ColorPickerFieldsProps {\n rgb?: RGBColor\n hsl?: HSLColor\n hex?: string\n disableAlpha: boolean\n onChange: ColorChangeHandler<Color>\n}\n\nexport const ColorPickerFields = ({\n onChange,\n rgb,\n hsl,\n hex,\n disableAlpha,\n}: ColorPickerFieldsProps) => {\n const {sanity} = useTheme()\n\n const inputStyles: EditableInputStyles = useMemo(\n () => ({\n input: {\n width: '80%',\n padding: '4px 10% 3px',\n border: 'none',\n boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,\n color: sanity.color.input.default.enabled.fg,\n backgroundColor: sanity.color.input.default.enabled.bg,\n fontSize: sanity.fonts.text.sizes[0]?.fontSize,\n textAlign: 'center',\n },\n label: {\n display: 'block',\n textAlign: 'center',\n fontSize: sanity.fonts.label.sizes[0]?.fontSize,\n color: sanity.color.base.fg,\n paddingTop: '3px',\n paddingBottom: '4px',\n textTransform: 'capitalize',\n },\n }),\n [sanity],\n )\n\n const handleChange: ColorChangeHandler<Record<string, string>> = useCallback(\n (data) => {\n if ('hex' in data && data['hex'] && isValidHex(data['hex'])) {\n onChange({\n hex: data['hex'],\n source: 'hex',\n })\n } else if (\n rgb &&\n (('r' in data && data['r']) || ('g' in data && data['g']) || ('b' in data && data['b']))\n ) {\n onChange({\n r: Number(data['r']) || rgb.r,\n g: Number(data['g']) || rgb.g,\n b: Number(data['b']) || rgb.b,\n a: rgb.a,\n source: 'rgb',\n })\n } else if (hsl && 'a' in data && data['a']) {\n let alpha = Number(data['a'])\n if (alpha < 0) {\n alpha = 0\n } else if (alpha > 100) {\n alpha = 100\n }\n alpha /= 100\n\n onChange({\n h: hsl.h,\n s: hsl.s,\n l: hsl.l,\n a: alpha,\n source: 'hsl',\n })\n }\n },\n [onChange, hsl, rgb],\n )\n\n return (\n <Flex>\n <Box flex={2} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"hex\"\n value={hex?.replace('#', '')}\n onChange={handleChange}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"r\"\n value={rgb?.r}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"g\"\n value={rgb?.g}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"b\"\n value={rgb?.b}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n {!disableAlpha && (\n <Box flex={1}>\n <EditableInput\n style={inputStyles}\n label=\"a\"\n value={Math.round((rgb?.a ?? 1) * 100)}\n onChange={handleChange}\n dragLabel\n dragMax={100}\n />\n </Box>\n )}\n </Flex>\n )\n}\n","import type {CustomPickerInjectedProps} from 'react-color/lib/components/common/ColorWrap'\n\nimport {startTransition, useCallback, useDeferredValue, useEffect, useRef, useState} from 'react'\nimport {type Color, CustomPicker} from 'react-color'\nimport {Alpha, Checkboard, Hue, Saturation} from 'react-color/lib/components/common'\nimport {type ObjectInputProps, set, setIfMissing, unset} from 'sanity'\nimport {styled} from 'styled-components'\nimport {useEffectEvent} from 'use-effect-event'\n\nimport {AddIcon} from '@sanity/icons'\nimport {TrashIcon} from '@sanity/icons'\nimport {Box, Button, Card, Flex, Inline, Stack, Text} from '@sanity/ui'\n\nimport type {ColorSchemaType, ColorValue} from './types'\n\nimport {ColorList} from './ColorList'\nimport {ColorPickerFields} from './ColorPickerFields'\n\nconst ColorBox = styled(Box)`\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n`\n\nconst ReadOnlyContainer = styled(Flex)`\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n`\n\ninterface ColorPickerProps extends CustomPickerInjectedProps<Color> {\n width?: string\n disableAlpha: boolean\n colorList?: Array<Color> | undefined\n readOnly?: boolean\n onUnset: () => void\n color: ColorValue\n}\n\nconst ColorPickerInner = (props: ColorPickerProps) => {\n const {\n width,\n color: {rgb, hex, hsv, hsl},\n onChange,\n onUnset,\n disableAlpha,\n colorList,\n readOnly,\n } = props\n\n if (!hsl || !hsv) {\n return null\n }\n\n return (\n <div style={{width}}>\n <Card padding={1} border radius={1}>\n <Stack space={2}>\n {!readOnly && (\n <>\n <Card overflow=\"hidden\" style={{position: 'relative', height: '5em'}}>\n <Saturation onChange={onChange} hsl={hsl} hsv={hsv} />\n </Card>\n\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Hue hsl={hsl} onChange={!readOnly && onChange} />\n </Card>\n\n {!disableAlpha && (\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px', background: '#fff'}}\n >\n <Alpha rgb={rgb} hsl={hsl} onChange={onChange} />\n </Card>\n )}\n </>\n )}\n <Flex>\n <Card\n flex={1}\n radius={2}\n overflow=\"hidden\"\n style={{position: 'relative', minWidth: '4em', background: '#fff'}}\n >\n <Checkboard\n size={8}\n white=\"transparent\"\n grey=\"rgba(0,0,0,.08)\"\n renderers={{} as {canvas: unknown}}\n />\n <ColorBox\n style={{\n backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`,\n }}\n />\n\n {readOnly && (\n <ReadOnlyContainer\n padding={2}\n paddingBottom={1}\n sizing=\"border\"\n justify=\"space-between\"\n >\n <Stack space={3} marginTop={1}>\n <Text size={3} weight=\"bold\">\n {hex}\n </Text>\n\n <Inline space={3}>\n <Text size={1}>\n <strong>RGB: </strong>\n {rgb?.r} {rgb?.g} {rgb?.b}\n </Text>\n <Text size={1}>\n <strong>HSL: </strong> {Math.round(hsl?.h ?? 0)}{' '}\n {Math.round((hsl?.s ?? 0) * 100)}% {Math.round((hsl?.l ?? 0) * 100)}%\n </Text>\n </Inline>\n </Stack>\n </ReadOnlyContainer>\n )}\n </Card>\n\n {!readOnly && (\n <Flex align=\"flex-start\" marginLeft={2}>\n <Box style={{width: 200}}>\n <ColorPickerFields\n rgb={rgb}\n hsl={hsl}\n hex={hex}\n onChange={onChange}\n disableAlpha={disableAlpha}\n />\n </Box>\n <Box marginLeft={2}>\n <Button onClick={onUnset} title=\"Delete color\" icon={TrashIcon} tone=\"critical\" />\n </Box>\n </Flex>\n )}\n </Flex>\n {colorList && <ColorList colors={colorList} onChange={onChange} />}\n </Stack>\n </Card>\n </div>\n )\n}\n\nconst ColorPicker = CustomPicker(ColorPickerInner)\n\nconst DEFAULT_COLOR: ColorValue & {source: string} = {\n hex: '#24a3e3',\n hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},\n hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},\n rgb: {r: 46, g: 163, b: 227, a: 1},\n source: 'hex',\n}\n\nexport default function ColorInput(props: ObjectInputProps) {\n const {onChange, readOnly} = props\n const value = props.value as ColorValue | undefined\n const type = props.schemaType as ColorSchemaType\n const focusRef = useRef<HTMLButtonElement>(null)\n\n // use local state so we can have instant ui updates while debouncing patch emits\n const [color, setColor] = useState(value)\n // Marking the `setColor` in a transition allows React to interrupt render should the user start dragging the input before React is finished rendering\n useEffect(() => startTransition(() => setColor(value)), [value])\n\n // The color picker emits onChange events continuously while the user is sliding the\n // hue/saturation/alpha selectors. This debounces the event to avoid excessive patches\n // and massively improve render performance and avoid jank\n const [emitColor, setEmitColor] = useState<typeof value>(undefined)\n const debouncedColor = useDeferredValue(emitColor)\n const handleChange = useEffectEvent((nextColor: ColorValue) => {\n const fieldPatches = type.fields\n .filter((field) => field.name in nextColor)\n .map((field) => {\n const nextFieldValue = nextColor[field.name as keyof ColorValue]\n const isObject = field.type.jsonType === 'object'\n return set(\n isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,\n [field.name],\n )\n })\n\n onChange([\n setIfMissing({_type: type.name}),\n set(type.name, ['_type']),\n set(nextColor.rgb?.a, ['alpha']),\n ...fieldPatches,\n ])\n })\n useEffect(() => {\n if (!debouncedColor) return undefined\n const raf = requestAnimationFrame(() => handleChange(debouncedColor))\n return () => cancelAnimationFrame(raf)\n }, [debouncedColor])\n\n const handleCreateColor = useCallback(() => {\n setColor(DEFAULT_COLOR)\n setEmitColor(DEFAULT_COLOR)\n }, [])\n\n const handleColorChange = useCallback((nextColor: ColorValue) => {\n setColor(nextColor)\n setEmitColor(nextColor)\n }, [])\n\n const handleUnset = useCallback(() => {\n setColor(undefined)\n onChange(unset())\n }, [onChange])\n\n return (\n <>\n {value && value.hex ? (\n <ColorPicker\n color={color!}\n onChange={handleColorChange}\n readOnly={readOnly || (typeof type.readOnly === 'boolean' && type.readOnly)}\n disableAlpha={!!type.options?.disableAlpha}\n colorList={type.options?.colorList}\n onUnset={handleUnset}\n />\n ) : (\n <Button\n icon={AddIcon}\n mode=\"ghost\"\n text=\"Create color\"\n ref={focusRef}\n disabled={Boolean(readOnly)}\n onClick={handleCreateColor}\n />\n )}\n </>\n )\n}\n"],"names":["ColorBox"],"mappings":";;;;;;;;;;;AAQA,MAAM,gBAAgB,OAAO,IAAI;AAAA;AAAA,GAI3B,oBAAoB,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAW3BA,aAAW,OAAO;AAA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@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
3
  var sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), react = require("react");
4
4
  const ColorInput = react.lazy(() => Promise.resolve().then(function() {
5
- return require("./_chunks-cjs/ColorInput.js");
5
+ return require("./_chunks-cjs/ColorInput.cjs");
6
6
  })), round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = sanity.defineType({
7
7
  name: colorTypeName,
8
8
  type: "object",
@@ -111,4 +111,4 @@ exports.colorInput = colorInput;
111
111
  exports.hslaColor = hslaColor;
112
112
  exports.hsvaColor = hsvaColor;
113
113
  exports.rgbaColor = rgbaColor;
114
- //# sourceMappingURL=index.js.map
114
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/LazyColorInput.tsx","../src/schemas/color.tsx","../src/schemas/hslaColor.ts","../src/schemas/hsvaColor.ts","../src/schemas/rgbaColor.ts","../src/index.ts"],"sourcesContent":["import {lazy} from 'react'\n\nexport const ColorInput = lazy(() => import('./ColorInput'))\n","import {defineType, type ObjectDefinition} from 'sanity'\n\nimport {ColorInput} from '../LazyColorInput'\nimport {type ColorOptions} from '../types'\n\nconst round = (val: number = 1) => Math.round(val * 100)\n\nconst colorTypeName = 'color' as const\n\n/**\n * @public\n */\nexport interface ColorDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {\n type: typeof colorTypeName\n options?: ColorOptions\n}\n\ndeclare module 'sanity' {\n // makes type: 'color' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n color: ColorDefinition\n }\n}\n\nexport const color = defineType({\n name: colorTypeName,\n type: 'object',\n title: 'Color',\n components: {input: ColorInput},\n fields: [\n {\n title: 'Hex',\n name: 'hex',\n type: 'string',\n },\n {\n title: 'Alpha',\n name: 'alpha',\n type: 'number',\n },\n {\n title: 'Hue Saturation Lightness',\n name: 'hsl',\n type: 'hslaColor',\n },\n {\n title: 'Hue Saturation Value',\n name: 'hsv',\n type: 'hsvaColor',\n },\n {\n title: 'Red Green Blue (rgb)',\n name: 'rgb',\n type: 'rgbaColor',\n },\n ],\n preview: {\n select: {\n title: 'hex',\n alpha: 'alpha',\n hex: 'hex',\n hsl: 'hsl',\n },\n prepare({\n title,\n hex,\n hsl,\n alpha,\n }: {\n title: string\n alpha?: number\n hex?: string\n hsl?: {h: number; s: number; l: number}\n }) {\n let subtitle = hex || 'No color set'\n if (hsl) {\n subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`\n }\n return {\n title: title,\n subtitle: subtitle,\n media: () => (\n <div\n style={{\n backgroundColor: hex ?? '#000',\n opacity: alpha ?? 1,\n position: 'absolute',\n height: '100%',\n width: '100%',\n top: '0',\n left: '0',\n }}\n />\n ),\n }\n },\n },\n})\n","import {defineType} from 'sanity'\n\nexport const hslaColor = defineType({\n title: 'Hue Saturation Lightness',\n name: 'hslaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'l', type: 'number', title: 'Lightness'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {defineType} from 'sanity'\n\nexport const hsvaColor = defineType({\n title: 'Hue Saturation Value',\n name: 'hsvaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'v', type: 'number', title: 'Value'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {defineType} from 'sanity'\n\nexport const rgbaColor = defineType({\n title: 'Red Green Blue (rgb)',\n name: 'rgbaColor',\n type: 'object',\n fields: [\n {name: 'r', type: 'number', title: 'Red'},\n {name: 'g', type: 'number', title: 'Green'},\n {name: 'b', type: 'number', title: 'Blue'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {definePlugin} from 'sanity'\n\nimport {color, type ColorDefinition} from './schemas/color'\nimport {hslaColor} from './schemas/hslaColor'\nimport {hsvaColor} from './schemas/hsvaColor'\nimport {rgbaColor} from './schemas/rgbaColor'\n\nexport const colorInput = definePlugin({\n name: '@sanity/color-input',\n schema: {\n types: [hslaColor, hsvaColor, rgbaColor, color],\n },\n})\n\nexport {color, hslaColor, hsvaColor, rgbaColor}\nexport {ColorInput} from './LazyColorInput'\nexport type {ColorDefinition}\nexport type {ColorInputProps, ColorOptions, ColorSchemaType, ColorValue} from './types'\n"],"names":["lazy","defineType","jsx","definePlugin"],"mappings":";;;AAEO,MAAM,aAAaA,MAAAA,KAAK,MAAM,QAAA,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAO,8BAAc;AAAA,CAAA,CAAC,GCGrD,QAAQ,CAAC,MAAc,MAAM,KAAK,MAAM,MAAM,GAAG,GAEjD,gBAAgB,SAiBT,QAAQC,OAAAA,WAAW;AAAA,EAC9B,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,YAAY,EAAC,OAAO,WAAA;AAAA,EACpB,QAAQ;AAAA,IACN;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,IAER;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,IAER;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,IAER;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,IAER;AAAA,MACE,OAAO;AAAA,MACP,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAAA,EACR;AAAA,EAEF,SAAS;AAAA,IACP,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,OAAO;AAAA,MACP,KAAK;AAAA,MACL,KAAK;AAAA,IAAA;AAAA,IAEP,QAAQ;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;A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M;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,IACN,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,MAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,QAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,OAAA;AAAA,IACnC,EAAC,MAAM,KAAK,MAAM,UAAU,OAAO,QAAA;AAAA,EAAO;AAE9C,CAAC,GCLY,aAAaE,OAAAA,aAAa;AAAA,EACrC,MAAM;AAAA,EACN,QAAQ;AAAA,IACN,OAAO,CAAC,WAAW,WAAW,WAAW,KAAK;AAAA,EAAA;AAElD,CAAC;;;;;;;"}
@@ -0,0 +1,64 @@
1
+ import * as sanity8 from "sanity";
2
+ import { ObjectDefinition, ObjectInputProps, ObjectOptions, ObjectSchemaType } from "sanity";
3
+ import { Color, HSLColor, HSVColor, RGBColor } from "react-color";
4
+ import * as react2 from "react";
5
+ interface ColorValue {
6
+ hex: string;
7
+ hsl: HSLColor;
8
+ hsv: HSVColor;
9
+ rgb: RGBColor;
10
+ }
11
+ interface ColorOptions extends Omit<ObjectOptions, 'columns'> {
12
+ disableAlpha?: boolean;
13
+ colorList?: Array<Color>;
14
+ }
15
+ type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {
16
+ options?: ColorOptions;
17
+ };
18
+ type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>;
19
+ declare const colorTypeName: "color";
20
+ /**
21
+ * @public
22
+ */
23
+ interface ColorDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {
24
+ type: typeof colorTypeName;
25
+ options?: ColorOptions;
26
+ }
27
+ declare module 'sanity' {
28
+ interface IntrinsicDefinitions {
29
+ color: ColorDefinition;
30
+ }
31
+ }
32
+ declare const color: {
33
+ type: "object";
34
+ name: "color";
35
+ } & Omit<ObjectDefinition, "preview"> & {
36
+ preview?: sanity8.PreviewConfig<{
37
+ title: string;
38
+ alpha: string;
39
+ hex: string;
40
+ hsl: string;
41
+ }, Record<"alpha" | "hex" | "hsl" | "title", any>>;
42
+ };
43
+ declare const hslaColor: {
44
+ type: "object";
45
+ name: "hslaColor";
46
+ } & Omit<sanity8.ObjectDefinition, "preview"> & {
47
+ preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
48
+ };
49
+ declare const hsvaColor: {
50
+ type: "object";
51
+ name: "hsvaColor";
52
+ } & Omit<sanity8.ObjectDefinition, "preview"> & {
53
+ preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
54
+ };
55
+ declare const rgbaColor: {
56
+ type: "object";
57
+ name: "rgbaColor";
58
+ } & Omit<sanity8.ObjectDefinition, "preview"> & {
59
+ preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
60
+ };
61
+ declare function ColorInput$1(props: ObjectInputProps): react2.JSX.Element;
62
+ declare const ColorInput: react2.LazyExoticComponent<typeof ColorInput$1>;
63
+ declare const colorInput: sanity8.Plugin<void>;
64
+ export { type ColorDefinition, ColorInput, type ColorInputProps, type ColorOptions, type ColorSchemaType, type ColorValue, color, colorInput, hslaColor, hsvaColor, rgbaColor };
@@ -0,0 +1,64 @@
1
+ import * as sanity8 from "sanity";
2
+ import { ObjectDefinition, ObjectInputProps, ObjectOptions, ObjectSchemaType } from "sanity";
3
+ import { Color, HSLColor, HSVColor, RGBColor } from "react-color";
4
+ import * as react2 from "react";
5
+ interface ColorValue {
6
+ hex: string;
7
+ hsl: HSLColor;
8
+ hsv: HSVColor;
9
+ rgb: RGBColor;
10
+ }
11
+ interface ColorOptions extends Omit<ObjectOptions, 'columns'> {
12
+ disableAlpha?: boolean;
13
+ colorList?: Array<Color>;
14
+ }
15
+ type ColorSchemaType = Omit<ObjectSchemaType, 'options'> & {
16
+ options?: ColorOptions;
17
+ };
18
+ type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>;
19
+ declare const colorTypeName: "color";
20
+ /**
21
+ * @public
22
+ */
23
+ interface ColorDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {
24
+ type: typeof colorTypeName;
25
+ options?: ColorOptions;
26
+ }
27
+ declare module 'sanity' {
28
+ interface IntrinsicDefinitions {
29
+ color: ColorDefinition;
30
+ }
31
+ }
32
+ declare const color: {
33
+ type: "object";
34
+ name: "color";
35
+ } & Omit<ObjectDefinition, "preview"> & {
36
+ preview?: sanity8.PreviewConfig<{
37
+ title: string;
38
+ alpha: string;
39
+ hex: string;
40
+ hsl: string;
41
+ }, Record<"alpha" | "hex" | "hsl" | "title", any>>;
42
+ };
43
+ declare const hslaColor: {
44
+ type: "object";
45
+ name: "hslaColor";
46
+ } & Omit<sanity8.ObjectDefinition, "preview"> & {
47
+ preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
48
+ };
49
+ declare const hsvaColor: {
50
+ type: "object";
51
+ name: "hsvaColor";
52
+ } & Omit<sanity8.ObjectDefinition, "preview"> & {
53
+ preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
54
+ };
55
+ declare const rgbaColor: {
56
+ type: "object";
57
+ name: "rgbaColor";
58
+ } & Omit<sanity8.ObjectDefinition, "preview"> & {
59
+ preview?: sanity8.PreviewConfig<Record<string, string>, Record<never, any>>;
60
+ };
61
+ declare function ColorInput$1(props: ObjectInputProps): react2.JSX.Element;
62
+ declare const ColorInput: react2.LazyExoticComponent<typeof ColorInput$1>;
63
+ declare const colorInput: sanity8.Plugin<void>;
64
+ export { type ColorDefinition, ColorInput, type ColorInputProps, type ColorOptions, type ColorSchemaType, type ColorValue, color, colorInput, hslaColor, hsvaColor, rgbaColor };
@@ -1,7 +1,7 @@
1
1
  import { defineType, definePlugin } from "sanity";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { lazy } from "react";
4
- const ColorInput = lazy(() => import("./_chunks-es/ColorInput.mjs")), round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = defineType({
4
+ const ColorInput = lazy(() => import("./_chunks-es/ColorInput.js")), round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = defineType({
5
5
  name: colorTypeName,
6
6
  type: "object",
7
7
  title: "Color",
@@ -111,4 +111,4 @@ export {
111
111
  hsvaColor,
112
112
  rgbaColor
113
113
  };
114
- //# sourceMappingURL=index.mjs.map
114
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/LazyColorInput.tsx","../src/schemas/color.tsx","../src/schemas/hslaColor.ts","../src/schemas/hsvaColor.ts","../src/schemas/rgbaColor.ts","../src/index.ts"],"sourcesContent":["import {lazy} from 'react'\n\nexport const ColorInput = lazy(() => import('./ColorInput'))\n","import {defineType, type ObjectDefinition} from 'sanity'\n\nimport {ColorInput} from '../LazyColorInput'\nimport {type ColorOptions} from '../types'\n\nconst round = (val: number = 1) => Math.round(val * 100)\n\nconst colorTypeName = 'color' as const\n\n/**\n * @public\n */\nexport interface ColorDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options'> {\n type: typeof colorTypeName\n options?: ColorOptions\n}\n\ndeclare module 'sanity' {\n // makes type: 'color' narrow correctly when using defineType/defineField/defineArrayMember\n export interface IntrinsicDefinitions {\n color: ColorDefinition\n }\n}\n\nexport const color = defineType({\n name: colorTypeName,\n type: 'object',\n title: 'Color',\n components: {input: ColorInput},\n fields: [\n {\n title: 'Hex',\n name: 'hex',\n type: 'string',\n },\n {\n title: 'Alpha',\n name: 'alpha',\n type: 'number',\n },\n {\n title: 'Hue Saturation Lightness',\n name: 'hsl',\n type: 'hslaColor',\n },\n {\n title: 'Hue Saturation Value',\n name: 'hsv',\n type: 'hsvaColor',\n },\n {\n title: 'Red Green Blue (rgb)',\n name: 'rgb',\n type: 'rgbaColor',\n },\n ],\n preview: {\n select: {\n title: 'hex',\n alpha: 'alpha',\n hex: 'hex',\n hsl: 'hsl',\n },\n prepare({\n title,\n hex,\n hsl,\n alpha,\n }: {\n title: string\n alpha?: number\n hex?: string\n hsl?: {h: number; s: number; l: number}\n }) {\n let subtitle = hex || 'No color set'\n if (hsl) {\n subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`\n }\n return {\n title: title,\n subtitle: subtitle,\n media: () => (\n <div\n style={{\n backgroundColor: hex ?? '#000',\n opacity: alpha ?? 1,\n position: 'absolute',\n height: '100%',\n width: '100%',\n top: '0',\n left: '0',\n }}\n />\n ),\n }\n },\n },\n})\n","import {defineType} from 'sanity'\n\nexport const hslaColor = defineType({\n title: 'Hue Saturation Lightness',\n name: 'hslaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'l', type: 'number', title: 'Lightness'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {defineType} from 'sanity'\n\nexport const hsvaColor = defineType({\n title: 'Hue Saturation Value',\n name: 'hsvaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'v', type: 'number', title: 'Value'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {defineType} from 'sanity'\n\nexport const rgbaColor = defineType({\n title: 'Red Green Blue (rgb)',\n name: 'rgbaColor',\n type: 'object',\n fields: [\n {name: 'r', type: 'number', title: 'Red'},\n {name: 'g', type: 'number', title: 'Green'},\n {name: 'b', type: 'number', title: 'Blue'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n})\n","import {definePlugin} from 'sanity'\n\nimport {color, type ColorDefinition} from './schemas/color'\nimport {hslaColor} from './schemas/hslaColor'\nimport {hsvaColor} from './schemas/hsvaColor'\nimport {rgbaColor} from './schemas/rgbaColor'\n\nexport const colorInput = definePlugin({\n name: '@sanity/color-input',\n schema: {\n types: [hslaColor, hsvaColor, rgbaColor, color],\n },\n})\n\nexport {color, hslaColor, hsvaColor, rgbaColor}\nexport {ColorInput} from './LazyColorInput'\nexport type {ColorDefinition}\nexport type {ColorInputProps, Color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