@sanity/color-input 3.1.2 → 4.0.0-canary.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/lib/index.d.mts +90 -0
- package/lib/index.d.ts +6 -6
- package/lib/index.esm.js +629 -1204
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +616 -1212
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1150 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +32 -36
- package/src/ColorInput.tsx +23 -18
- package/src/ColorList.tsx +8 -7
- package/src/ColorPicker.tsx +8 -7
- package/src/ColorPickerFields.tsx +15 -15
- package/src/index.ts +5 -4
- package/src/schemas/color.tsx +3 -3
package/lib/index.esm.js
CHANGED
|
@@ -1,261 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import styled from
|
|
10
|
-
import { isValidHex } from
|
|
11
|
-
const hslaColor = defineType({
|
|
12
|
-
title: "Hue Saturation Lightness",
|
|
13
|
-
name: "hslaColor",
|
|
14
|
-
type: "object",
|
|
15
|
-
fields: [{
|
|
16
|
-
name: "h",
|
|
17
|
-
type: "number",
|
|
18
|
-
title: "Hue"
|
|
19
|
-
}, {
|
|
20
|
-
name: "s",
|
|
21
|
-
type: "number",
|
|
22
|
-
title: "Saturation"
|
|
23
|
-
}, {
|
|
24
|
-
name: "l",
|
|
25
|
-
type: "number",
|
|
26
|
-
title: "Lightness"
|
|
27
|
-
}, {
|
|
28
|
-
name: "a",
|
|
29
|
-
type: "number",
|
|
30
|
-
title: "Alpha"
|
|
31
|
-
}]
|
|
32
|
-
});
|
|
33
|
-
const rgbaColor = defineType({
|
|
34
|
-
title: "Red Green Blue (rgb)",
|
|
35
|
-
name: "rgbaColor",
|
|
36
|
-
type: "object",
|
|
37
|
-
fields: [{
|
|
38
|
-
name: "r",
|
|
39
|
-
type: "number",
|
|
40
|
-
title: "Red"
|
|
41
|
-
}, {
|
|
42
|
-
name: "g",
|
|
43
|
-
type: "number",
|
|
44
|
-
title: "Green"
|
|
45
|
-
}, {
|
|
46
|
-
name: "b",
|
|
47
|
-
type: "number",
|
|
48
|
-
title: "Blue"
|
|
49
|
-
}, {
|
|
50
|
-
name: "a",
|
|
51
|
-
type: "number",
|
|
52
|
-
title: "Alpha"
|
|
53
|
-
}]
|
|
54
|
-
});
|
|
55
|
-
const ColorPickerFields = _ref => {
|
|
56
|
-
let {
|
|
57
|
-
onChange,
|
|
58
|
-
rgb,
|
|
59
|
-
hsl,
|
|
60
|
-
hex,
|
|
61
|
-
disableAlpha
|
|
62
|
-
} = _ref;
|
|
63
|
-
var _a;
|
|
64
|
-
const {
|
|
65
|
-
sanity
|
|
66
|
-
} = useTheme();
|
|
67
|
-
const inputStyles = useMemo(() => ({
|
|
68
|
-
input: {
|
|
69
|
-
width: "80%",
|
|
70
|
-
padding: "4px 10% 3px",
|
|
71
|
-
border: "none",
|
|
72
|
-
boxShadow: "inset 0 0 0 1px ".concat(sanity.color.input.default.enabled.border),
|
|
73
|
-
color: sanity.color.input.default.enabled.fg,
|
|
74
|
-
backgroundColor: sanity.color.input.default.enabled.bg,
|
|
75
|
-
fontSize: sanity.fonts.text.sizes[0].fontSize,
|
|
76
|
-
textAlign: "center"
|
|
77
|
-
},
|
|
78
|
-
label: {
|
|
79
|
-
display: "block",
|
|
80
|
-
textAlign: "center",
|
|
81
|
-
fontSize: sanity.fonts.label.sizes[0].fontSize,
|
|
82
|
-
color: sanity.color.base.fg,
|
|
83
|
-
paddingTop: "3px",
|
|
84
|
-
paddingBottom: "4px",
|
|
85
|
-
textTransform: "capitalize"
|
|
86
|
-
}
|
|
87
|
-
}), [sanity]);
|
|
88
|
-
const handleChange = useCallback(data => {
|
|
89
|
-
if ("hex" in data && data.hex && isValidHex(data.hex)) {
|
|
90
|
-
onChange({
|
|
91
|
-
hex: data.hex,
|
|
92
|
-
source: "hex"
|
|
93
|
-
});
|
|
94
|
-
} else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b)) {
|
|
95
|
-
onChange({
|
|
96
|
-
r: Number(data.r) || rgb.r,
|
|
97
|
-
g: Number(data.g) || rgb.g,
|
|
98
|
-
b: Number(data.b) || rgb.b,
|
|
99
|
-
a: rgb.a,
|
|
100
|
-
source: "rgb"
|
|
101
|
-
});
|
|
102
|
-
} else if (hsl && "a" in data && data.a) {
|
|
103
|
-
let alpha = Number(data.a);
|
|
104
|
-
if (alpha < 0) {
|
|
105
|
-
alpha = 0;
|
|
106
|
-
} else if (alpha > 100) {
|
|
107
|
-
alpha = 100;
|
|
108
|
-
}
|
|
109
|
-
alpha /= 100;
|
|
110
|
-
onChange({
|
|
111
|
-
h: hsl.h,
|
|
112
|
-
s: hsl.s,
|
|
113
|
-
l: hsl.l,
|
|
114
|
-
a: alpha,
|
|
115
|
-
source: "hsl"
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}, [onChange, hsl, rgb]);
|
|
119
|
-
return /* @__PURE__ */jsxs(Flex, {
|
|
120
|
-
children: [/* @__PURE__ */jsx(Box, {
|
|
121
|
-
flex: 2,
|
|
122
|
-
marginRight: 1,
|
|
123
|
-
children: /* @__PURE__ */jsx(EditableInput, {
|
|
124
|
-
style: inputStyles,
|
|
125
|
-
label: "hex",
|
|
126
|
-
value: hex == null ? void 0 : hex.replace("#", ""),
|
|
127
|
-
onChange: handleChange
|
|
128
|
-
})
|
|
129
|
-
}), /* @__PURE__ */jsx(Box, {
|
|
130
|
-
flex: 1,
|
|
131
|
-
marginRight: 1,
|
|
132
|
-
children: /* @__PURE__ */jsx(EditableInput, {
|
|
133
|
-
style: inputStyles,
|
|
134
|
-
label: "r",
|
|
135
|
-
value: rgb == null ? void 0 : rgb.r,
|
|
136
|
-
onChange: handleChange,
|
|
137
|
-
dragLabel: true,
|
|
138
|
-
dragMax: 255
|
|
139
|
-
})
|
|
140
|
-
}), /* @__PURE__ */jsx(Box, {
|
|
141
|
-
flex: 1,
|
|
142
|
-
marginRight: 1,
|
|
143
|
-
children: /* @__PURE__ */jsx(EditableInput, {
|
|
144
|
-
style: inputStyles,
|
|
145
|
-
label: "g",
|
|
146
|
-
value: rgb == null ? void 0 : rgb.g,
|
|
147
|
-
onChange: handleChange,
|
|
148
|
-
dragLabel: true,
|
|
149
|
-
dragMax: 255
|
|
150
|
-
})
|
|
151
|
-
}), /* @__PURE__ */jsx(Box, {
|
|
152
|
-
flex: 1,
|
|
153
|
-
marginRight: 1,
|
|
154
|
-
children: /* @__PURE__ */jsx(EditableInput, {
|
|
155
|
-
style: inputStyles,
|
|
156
|
-
label: "b",
|
|
157
|
-
value: rgb == null ? void 0 : rgb.b,
|
|
158
|
-
onChange: handleChange,
|
|
159
|
-
dragLabel: true,
|
|
160
|
-
dragMax: 255
|
|
161
|
-
})
|
|
162
|
-
}), !disableAlpha && /* @__PURE__ */jsx(Box, {
|
|
163
|
-
flex: 1,
|
|
164
|
-
children: /* @__PURE__ */jsx(EditableInput, {
|
|
165
|
-
style: inputStyles,
|
|
166
|
-
label: "a",
|
|
167
|
-
value: Math.round(((_a = rgb == null ? void 0 : rgb.a) != null ? _a : 1) * 100),
|
|
168
|
-
onChange: handleChange,
|
|
169
|
-
dragLabel: true,
|
|
170
|
-
dragMax: 100
|
|
171
|
-
})
|
|
172
|
-
})]
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
// This file is autogenerated. It's used to publish ESM to npm.
|
|
1
|
+
import { set, setIfMissing, unset, defineType, definePlugin } from "sanity";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { TrashIcon, AddIcon } from "@sanity/icons";
|
|
4
|
+
import { Flex, useTheme, Box, Card, Stack, Text, Inline, Button } from "@sanity/ui";
|
|
5
|
+
import debounce from "lodash/debounce.js";
|
|
6
|
+
import { memo, useMemo, useCallback, useRef, useState, useEffect } from "react";
|
|
7
|
+
import { CustomPicker } from "react-color";
|
|
8
|
+
import { EditableInput, Saturation, Hue, Alpha, Checkboard } from "react-color/lib/components/common";
|
|
9
|
+
import { styled } from "styled-components";
|
|
10
|
+
import { isValidHex } from "react-color/lib/helpers/color";
|
|
177
11
|
function _typeof(obj) {
|
|
178
12
|
"@babel/helpers - typeof";
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
13
|
+
return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) {
|
|
14
|
+
return typeof obj2;
|
|
15
|
+
} : function(obj2) {
|
|
16
|
+
return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
184
17
|
}, _typeof(obj);
|
|
185
18
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
opts = opts || {};
|
|
195
|
-
|
|
196
|
-
// If input is already a tinycolor, return itself
|
|
197
|
-
if (color instanceof tinycolor) {
|
|
198
|
-
return color;
|
|
199
|
-
}
|
|
200
|
-
// If we are called as a function, call using new instead
|
|
201
|
-
if (!(this instanceof tinycolor)) {
|
|
202
|
-
return new tinycolor(color, opts);
|
|
203
|
-
}
|
|
204
|
-
var rgb = inputToRGB(color);
|
|
205
|
-
this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
|
|
206
|
-
this._gradientType = opts.gradientType;
|
|
207
|
-
|
|
208
|
-
// Don't let the range of [0,255] come back in [0,1].
|
|
209
|
-
// Potentially lose a little bit of precision here, but will fix issues where
|
|
210
|
-
// .5 gets interpreted as half of the total, instead of half of 1
|
|
211
|
-
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
|
|
212
|
-
if (this._r < 1) this._r = Math.round(this._r);
|
|
213
|
-
if (this._g < 1) this._g = Math.round(this._g);
|
|
214
|
-
if (this._b < 1) this._b = Math.round(this._b);
|
|
215
|
-
this._ok = rgb.ok;
|
|
19
|
+
var trimLeft = /^\s+/, trimRight = /\s+$/;
|
|
20
|
+
function tinycolor(color2, opts) {
|
|
21
|
+
if (color2 = color2 || "", opts = opts || {}, color2 instanceof tinycolor)
|
|
22
|
+
return color2;
|
|
23
|
+
if (!(this instanceof tinycolor))
|
|
24
|
+
return new tinycolor(color2, opts);
|
|
25
|
+
var rgb = inputToRGB(color2);
|
|
26
|
+
this._originalInput = color2, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format, this._gradientType = opts.gradientType, this._r < 1 && (this._r = Math.round(this._r)), this._g < 1 && (this._g = Math.round(this._g)), this._b < 1 && (this._b = Math.round(this._b)), this._ok = rgb.ok;
|
|
216
27
|
}
|
|
217
28
|
tinycolor.prototype = {
|
|
218
|
-
isDark: function
|
|
29
|
+
isDark: function() {
|
|
219
30
|
return this.getBrightness() < 128;
|
|
220
31
|
},
|
|
221
|
-
isLight: function
|
|
32
|
+
isLight: function() {
|
|
222
33
|
return !this.isDark();
|
|
223
34
|
},
|
|
224
|
-
isValid: function
|
|
35
|
+
isValid: function() {
|
|
225
36
|
return this._ok;
|
|
226
37
|
},
|
|
227
|
-
getOriginalInput: function
|
|
38
|
+
getOriginalInput: function() {
|
|
228
39
|
return this._originalInput;
|
|
229
40
|
},
|
|
230
|
-
getFormat: function
|
|
41
|
+
getFormat: function() {
|
|
231
42
|
return this._format;
|
|
232
43
|
},
|
|
233
|
-
getAlpha: function
|
|
44
|
+
getAlpha: function() {
|
|
234
45
|
return this._a;
|
|
235
46
|
},
|
|
236
|
-
getBrightness: function
|
|
237
|
-
//http://www.w3.org/TR/AERT#color-contrast
|
|
47
|
+
getBrightness: function() {
|
|
238
48
|
var rgb = this.toRgb();
|
|
239
|
-
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) /
|
|
49
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
|
|
240
50
|
},
|
|
241
|
-
getLuminance: function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
245
|
-
RsRGB = rgb.r / 255;
|
|
246
|
-
GsRGB = rgb.g / 255;
|
|
247
|
-
BsRGB = rgb.b / 255;
|
|
248
|
-
if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
249
|
-
if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
250
|
-
if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
251
|
-
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
51
|
+
getLuminance: function() {
|
|
52
|
+
var rgb = this.toRgb(), RsRGB, GsRGB, BsRGB, R, G, B;
|
|
53
|
+
return RsRGB = rgb.r / 255, GsRGB = rgb.g / 255, BsRGB = rgb.b / 255, RsRGB <= 0.03928 ? R = RsRGB / 12.92 : R = Math.pow((RsRGB + 0.055) / 1.055, 2.4), GsRGB <= 0.03928 ? G = GsRGB / 12.92 : G = Math.pow((GsRGB + 0.055) / 1.055, 2.4), BsRGB <= 0.03928 ? B = BsRGB / 12.92 : B = Math.pow((BsRGB + 0.055) / 1.055, 2.4), 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
252
54
|
},
|
|
253
|
-
setAlpha: function
|
|
254
|
-
this._a = boundAlpha(value);
|
|
255
|
-
this._roundA = Math.round(100 * this._a) / 100;
|
|
256
|
-
return this;
|
|
55
|
+
setAlpha: function(value) {
|
|
56
|
+
return this._a = boundAlpha(value), this._roundA = Math.round(100 * this._a) / 100, this;
|
|
257
57
|
},
|
|
258
|
-
toHsv: function
|
|
58
|
+
toHsv: function() {
|
|
259
59
|
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
260
60
|
return {
|
|
261
61
|
h: hsv.h * 360,
|
|
@@ -264,14 +64,11 @@ tinycolor.prototype = {
|
|
|
264
64
|
a: this._a
|
|
265
65
|
};
|
|
266
66
|
},
|
|
267
|
-
toHsvString: function
|
|
268
|
-
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
269
|
-
var h = Math.round(hsv.h * 360),
|
|
270
|
-
s = Math.round(hsv.s * 100),
|
|
271
|
-
v = Math.round(hsv.v * 100);
|
|
67
|
+
toHsvString: function() {
|
|
68
|
+
var hsv = rgbToHsv(this._r, this._g, this._b), h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
|
272
69
|
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
273
70
|
},
|
|
274
|
-
toHsl: function
|
|
71
|
+
toHsl: function() {
|
|
275
72
|
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
276
73
|
return {
|
|
277
74
|
h: hsl.h * 360,
|
|
@@ -280,26 +77,23 @@ tinycolor.prototype = {
|
|
|
280
77
|
a: this._a
|
|
281
78
|
};
|
|
282
79
|
},
|
|
283
|
-
toHslString: function
|
|
284
|
-
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
285
|
-
var h = Math.round(hsl.h * 360),
|
|
286
|
-
s = Math.round(hsl.s * 100),
|
|
287
|
-
l = Math.round(hsl.l * 100);
|
|
80
|
+
toHslString: function() {
|
|
81
|
+
var hsl = rgbToHsl(this._r, this._g, this._b), h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
|
288
82
|
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
289
83
|
},
|
|
290
|
-
toHex: function
|
|
84
|
+
toHex: function(allow3Char) {
|
|
291
85
|
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
292
86
|
},
|
|
293
|
-
toHexString: function
|
|
87
|
+
toHexString: function(allow3Char) {
|
|
294
88
|
return "#" + this.toHex(allow3Char);
|
|
295
89
|
},
|
|
296
|
-
toHex8: function
|
|
90
|
+
toHex8: function(allow4Char) {
|
|
297
91
|
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
298
92
|
},
|
|
299
|
-
toHex8String: function
|
|
93
|
+
toHex8String: function(allow4Char) {
|
|
300
94
|
return "#" + this.toHex8(allow4Char);
|
|
301
95
|
},
|
|
302
|
-
toRgb: function
|
|
96
|
+
toRgb: function() {
|
|
303
97
|
return {
|
|
304
98
|
r: Math.round(this._r),
|
|
305
99
|
g: Math.round(this._g),
|
|
@@ -307,10 +101,10 @@ tinycolor.prototype = {
|
|
|
307
101
|
a: this._a
|
|
308
102
|
};
|
|
309
103
|
},
|
|
310
|
-
toRgbString: function
|
|
104
|
+
toRgbString: function() {
|
|
311
105
|
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
|
|
312
106
|
},
|
|
313
|
-
toPercentageRgb: function
|
|
107
|
+
toPercentageRgb: function() {
|
|
314
108
|
return {
|
|
315
109
|
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
316
110
|
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
@@ -318,223 +112,104 @@ tinycolor.prototype = {
|
|
|
318
112
|
a: this._a
|
|
319
113
|
};
|
|
320
114
|
},
|
|
321
|
-
toPercentageRgbString: function
|
|
115
|
+
toPercentageRgbString: function() {
|
|
322
116
|
return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
|
323
117
|
},
|
|
324
|
-
toName: function
|
|
325
|
-
|
|
326
|
-
return "transparent";
|
|
327
|
-
}
|
|
328
|
-
if (this._a < 1) {
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
118
|
+
toName: function() {
|
|
119
|
+
return this._a === 0 ? "transparent" : this._a < 1 ? !1 : hexNames[rgbToHex(this._r, this._g, this._b, !0)] || !1;
|
|
332
120
|
},
|
|
333
|
-
toFilter: function
|
|
334
|
-
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
335
|
-
var secondHex8String = hex8String;
|
|
336
|
-
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
121
|
+
toFilter: function(secondColor) {
|
|
122
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a), secondHex8String = hex8String, gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
337
123
|
if (secondColor) {
|
|
338
124
|
var s = tinycolor(secondColor);
|
|
339
125
|
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
340
126
|
}
|
|
341
127
|
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
342
128
|
},
|
|
343
|
-
toString: function
|
|
129
|
+
toString: function(format) {
|
|
344
130
|
var formatSet = !!format;
|
|
345
131
|
format = format || this._format;
|
|
346
|
-
var formattedString =
|
|
347
|
-
|
|
348
|
-
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
349
|
-
if (needsAlphaFormat) {
|
|
350
|
-
// Special case for "transparent", all other non-alpha formats
|
|
351
|
-
// will return rgba when there is transparency.
|
|
352
|
-
if (format === "name" && this._a === 0) {
|
|
353
|
-
return this.toName();
|
|
354
|
-
}
|
|
355
|
-
return this.toRgbString();
|
|
356
|
-
}
|
|
357
|
-
if (format === "rgb") {
|
|
358
|
-
formattedString = this.toRgbString();
|
|
359
|
-
}
|
|
360
|
-
if (format === "prgb") {
|
|
361
|
-
formattedString = this.toPercentageRgbString();
|
|
362
|
-
}
|
|
363
|
-
if (format === "hex" || format === "hex6") {
|
|
364
|
-
formattedString = this.toHexString();
|
|
365
|
-
}
|
|
366
|
-
if (format === "hex3") {
|
|
367
|
-
formattedString = this.toHexString(true);
|
|
368
|
-
}
|
|
369
|
-
if (format === "hex4") {
|
|
370
|
-
formattedString = this.toHex8String(true);
|
|
371
|
-
}
|
|
372
|
-
if (format === "hex8") {
|
|
373
|
-
formattedString = this.toHex8String();
|
|
374
|
-
}
|
|
375
|
-
if (format === "name") {
|
|
376
|
-
formattedString = this.toName();
|
|
377
|
-
}
|
|
378
|
-
if (format === "hsl") {
|
|
379
|
-
formattedString = this.toHslString();
|
|
380
|
-
}
|
|
381
|
-
if (format === "hsv") {
|
|
382
|
-
formattedString = this.toHsvString();
|
|
383
|
-
}
|
|
384
|
-
return formattedString || this.toHexString();
|
|
132
|
+
var formattedString = !1, hasAlpha = this._a < 1 && this._a >= 0, needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
133
|
+
return needsAlphaFormat ? format === "name" && this._a === 0 ? this.toName() : this.toRgbString() : (format === "rgb" && (formattedString = this.toRgbString()), format === "prgb" && (formattedString = this.toPercentageRgbString()), (format === "hex" || format === "hex6") && (formattedString = this.toHexString()), format === "hex3" && (formattedString = this.toHexString(!0)), format === "hex4" && (formattedString = this.toHex8String(!0)), format === "hex8" && (formattedString = this.toHex8String()), format === "name" && (formattedString = this.toName()), format === "hsl" && (formattedString = this.toHslString()), format === "hsv" && (formattedString = this.toHsvString()), formattedString || this.toHexString());
|
|
385
134
|
},
|
|
386
|
-
clone: function
|
|
135
|
+
clone: function() {
|
|
387
136
|
return tinycolor(this.toString());
|
|
388
137
|
},
|
|
389
|
-
_applyModification: function
|
|
390
|
-
var
|
|
391
|
-
this._r =
|
|
392
|
-
this._g = color._g;
|
|
393
|
-
this._b = color._b;
|
|
394
|
-
this.setAlpha(color._a);
|
|
395
|
-
return this;
|
|
138
|
+
_applyModification: function(fn, args) {
|
|
139
|
+
var color2 = fn.apply(null, [this].concat([].slice.call(args)));
|
|
140
|
+
return this._r = color2._r, this._g = color2._g, this._b = color2._b, this.setAlpha(color2._a), this;
|
|
396
141
|
},
|
|
397
|
-
lighten: function
|
|
142
|
+
lighten: function() {
|
|
398
143
|
return this._applyModification(_lighten, arguments);
|
|
399
144
|
},
|
|
400
|
-
brighten: function
|
|
145
|
+
brighten: function() {
|
|
401
146
|
return this._applyModification(_brighten, arguments);
|
|
402
147
|
},
|
|
403
|
-
darken: function
|
|
148
|
+
darken: function() {
|
|
404
149
|
return this._applyModification(_darken, arguments);
|
|
405
150
|
},
|
|
406
|
-
desaturate: function
|
|
151
|
+
desaturate: function() {
|
|
407
152
|
return this._applyModification(_desaturate, arguments);
|
|
408
153
|
},
|
|
409
|
-
saturate: function
|
|
154
|
+
saturate: function() {
|
|
410
155
|
return this._applyModification(_saturate, arguments);
|
|
411
156
|
},
|
|
412
|
-
greyscale: function
|
|
157
|
+
greyscale: function() {
|
|
413
158
|
return this._applyModification(_greyscale, arguments);
|
|
414
159
|
},
|
|
415
|
-
spin: function
|
|
160
|
+
spin: function() {
|
|
416
161
|
return this._applyModification(_spin, arguments);
|
|
417
162
|
},
|
|
418
|
-
_applyCombination: function
|
|
163
|
+
_applyCombination: function(fn, args) {
|
|
419
164
|
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
420
165
|
},
|
|
421
|
-
analogous: function
|
|
166
|
+
analogous: function() {
|
|
422
167
|
return this._applyCombination(_analogous, arguments);
|
|
423
168
|
},
|
|
424
|
-
complement: function
|
|
169
|
+
complement: function() {
|
|
425
170
|
return this._applyCombination(_complement, arguments);
|
|
426
171
|
},
|
|
427
|
-
monochromatic: function
|
|
172
|
+
monochromatic: function() {
|
|
428
173
|
return this._applyCombination(_monochromatic, arguments);
|
|
429
174
|
},
|
|
430
|
-
splitcomplement: function
|
|
175
|
+
splitcomplement: function() {
|
|
431
176
|
return this._applyCombination(_splitcomplement, arguments);
|
|
432
177
|
},
|
|
433
178
|
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
434
179
|
// polyad: function (number) {
|
|
435
180
|
// return this._applyCombination(polyad, [number]);
|
|
436
181
|
// },
|
|
437
|
-
triad: function
|
|
182
|
+
triad: function() {
|
|
438
183
|
return this._applyCombination(polyad, [3]);
|
|
439
184
|
},
|
|
440
|
-
tetrad: function
|
|
185
|
+
tetrad: function() {
|
|
441
186
|
return this._applyCombination(polyad, [4]);
|
|
442
187
|
}
|
|
443
188
|
};
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
// String input requires "1.0" as input, so 1 will be treated as 1
|
|
447
|
-
tinycolor.fromRatio = function (color, opts) {
|
|
448
|
-
if (_typeof(color) == "object") {
|
|
189
|
+
tinycolor.fromRatio = function(color2, opts) {
|
|
190
|
+
if (_typeof(color2) == "object") {
|
|
449
191
|
var newColor = {};
|
|
450
|
-
for (var i in
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
newColor[i] = color[i];
|
|
454
|
-
} else {
|
|
455
|
-
newColor[i] = convertToPercentage(color[i]);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
color = newColor;
|
|
192
|
+
for (var i in color2)
|
|
193
|
+
color2.hasOwnProperty(i) && (i === "a" ? newColor[i] = color2[i] : newColor[i] = convertToPercentage(color2[i]));
|
|
194
|
+
color2 = newColor;
|
|
460
195
|
}
|
|
461
|
-
return tinycolor(
|
|
196
|
+
return tinycolor(color2, opts);
|
|
462
197
|
};
|
|
463
|
-
|
|
464
|
-
// Given a string or object, convert that input to RGB
|
|
465
|
-
// Possible string inputs:
|
|
466
|
-
//
|
|
467
|
-
// "red"
|
|
468
|
-
// "#f00" or "f00"
|
|
469
|
-
// "#ff0000" or "ff0000"
|
|
470
|
-
// "#ff000000" or "ff000000"
|
|
471
|
-
// "rgb 255 0 0" or "rgb (255, 0, 0)"
|
|
472
|
-
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
|
|
473
|
-
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
|
|
474
|
-
// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
|
|
475
|
-
// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
|
|
476
|
-
// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
|
|
477
|
-
// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
|
|
478
|
-
//
|
|
479
|
-
function inputToRGB(color) {
|
|
198
|
+
function inputToRGB(color2) {
|
|
480
199
|
var rgb = {
|
|
481
200
|
r: 0,
|
|
482
201
|
g: 0,
|
|
483
202
|
b: 0
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
var l = null;
|
|
489
|
-
var ok = false;
|
|
490
|
-
var format = false;
|
|
491
|
-
if (typeof color == "string") {
|
|
492
|
-
color = stringInputToObject(color);
|
|
493
|
-
}
|
|
494
|
-
if (_typeof(color) == "object") {
|
|
495
|
-
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
496
|
-
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
497
|
-
ok = true;
|
|
498
|
-
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
499
|
-
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
500
|
-
s = convertToPercentage(color.s);
|
|
501
|
-
v = convertToPercentage(color.v);
|
|
502
|
-
rgb = hsvToRgb(color.h, s, v);
|
|
503
|
-
ok = true;
|
|
504
|
-
format = "hsv";
|
|
505
|
-
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
506
|
-
s = convertToPercentage(color.s);
|
|
507
|
-
l = convertToPercentage(color.l);
|
|
508
|
-
rgb = hslToRgb(color.h, s, l);
|
|
509
|
-
ok = true;
|
|
510
|
-
format = "hsl";
|
|
511
|
-
}
|
|
512
|
-
if (color.hasOwnProperty("a")) {
|
|
513
|
-
a = color.a;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
a = boundAlpha(a);
|
|
517
|
-
return {
|
|
518
|
-
ok: ok,
|
|
519
|
-
format: color.format || format,
|
|
203
|
+
}, a = 1, s = null, v = null, l = null, ok = !1, format = !1;
|
|
204
|
+
return typeof color2 == "string" && (color2 = stringInputToObject(color2)), _typeof(color2) == "object" && (isValidCSSUnit(color2.r) && isValidCSSUnit(color2.g) && isValidCSSUnit(color2.b) ? (rgb = rgbToRgb(color2.r, color2.g, color2.b), ok = !0, format = String(color2.r).substr(-1) === "%" ? "prgb" : "rgb") : isValidCSSUnit(color2.h) && isValidCSSUnit(color2.s) && isValidCSSUnit(color2.v) ? (s = convertToPercentage(color2.s), v = convertToPercentage(color2.v), rgb = hsvToRgb(color2.h, s, v), ok = !0, format = "hsv") : isValidCSSUnit(color2.h) && isValidCSSUnit(color2.s) && isValidCSSUnit(color2.l) && (s = convertToPercentage(color2.s), l = convertToPercentage(color2.l), rgb = hslToRgb(color2.h, s, l), ok = !0, format = "hsl"), color2.hasOwnProperty("a") && (a = color2.a)), a = boundAlpha(a), {
|
|
205
|
+
ok,
|
|
206
|
+
format: color2.format || format,
|
|
520
207
|
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
521
208
|
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
522
209
|
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
523
|
-
a
|
|
210
|
+
a
|
|
524
211
|
};
|
|
525
212
|
}
|
|
526
|
-
|
|
527
|
-
// Conversion Functions
|
|
528
|
-
// --------------------
|
|
529
|
-
|
|
530
|
-
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
|
|
531
|
-
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
|
|
532
|
-
|
|
533
|
-
// `rgbToRgb`
|
|
534
|
-
// Handle bounds / percentage checking to conform to CSS color spec
|
|
535
|
-
// <http://www.w3.org/TR/css3-color/>
|
|
536
|
-
// *Assumes:* r, g, b in [0, 255] or [0, 1]
|
|
537
|
-
// *Returns:* { r, g, b } in [0, 255]
|
|
538
213
|
function rgbToRgb(r, g, b) {
|
|
539
214
|
return {
|
|
540
215
|
r: bound01(r, 255) * 255,
|
|
@@ -542,26 +217,14 @@ function rgbToRgb(r, g, b) {
|
|
|
542
217
|
b: bound01(b, 255) * 255
|
|
543
218
|
};
|
|
544
219
|
}
|
|
545
|
-
|
|
546
|
-
// `rgbToHsl`
|
|
547
|
-
// Converts an RGB color value to HSL.
|
|
548
|
-
// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
|
|
549
|
-
// *Returns:* { h, s, l } in [0,1]
|
|
550
220
|
function rgbToHsl(r, g, b) {
|
|
551
|
-
r = bound01(r, 255);
|
|
552
|
-
g =
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
var h,
|
|
557
|
-
s,
|
|
558
|
-
l = (max + min) / 2;
|
|
559
|
-
if (max == min) {
|
|
560
|
-
h = s = 0; // achromatic
|
|
561
|
-
} else {
|
|
221
|
+
r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
|
|
222
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, l = (max + min) / 2;
|
|
223
|
+
if (max == min)
|
|
224
|
+
h = s = 0;
|
|
225
|
+
else {
|
|
562
226
|
var d = max - min;
|
|
563
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
|
|
564
|
-
switch (max) {
|
|
227
|
+
switch (s = l > 0.5 ? d / (2 - max - min) : d / (max + min), max) {
|
|
565
228
|
case r:
|
|
566
229
|
h = (g - b) / d + (g < b ? 6 : 0);
|
|
567
230
|
break;
|
|
@@ -575,37 +238,22 @@ function rgbToHsl(r, g, b) {
|
|
|
575
238
|
h /= 6;
|
|
576
239
|
}
|
|
577
240
|
return {
|
|
578
|
-
h
|
|
579
|
-
s
|
|
580
|
-
l
|
|
241
|
+
h,
|
|
242
|
+
s,
|
|
243
|
+
l
|
|
581
244
|
};
|
|
582
245
|
}
|
|
583
|
-
|
|
584
|
-
// `hslToRgb`
|
|
585
|
-
// Converts an HSL color value to RGB.
|
|
586
|
-
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
|
|
587
|
-
// *Returns:* { r, g, b } in the set [0, 255]
|
|
588
246
|
function hslToRgb(h, s, l) {
|
|
589
247
|
var r, g, b;
|
|
590
|
-
h = bound01(h, 360);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
function hue2rgb(p, q, t) {
|
|
594
|
-
if (t < 0) t += 1;
|
|
595
|
-
if (t > 1) t -= 1;
|
|
596
|
-
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
597
|
-
if (t < 1 / 2) return q;
|
|
598
|
-
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
599
|
-
return p;
|
|
248
|
+
h = bound01(h, 360), s = bound01(s, 100), l = bound01(l, 100);
|
|
249
|
+
function hue2rgb(p2, q2, t) {
|
|
250
|
+
return t < 0 && (t += 1), t > 1 && (t -= 1), t < 1 / 6 ? p2 + (q2 - p2) * 6 * t : t < 1 / 2 ? q2 : t < 2 / 3 ? p2 + (q2 - p2) * (2 / 3 - t) * 6 : p2;
|
|
600
251
|
}
|
|
601
|
-
if (s === 0)
|
|
602
|
-
r = g = b = l;
|
|
603
|
-
|
|
604
|
-
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
605
|
-
|
|
606
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
607
|
-
g = hue2rgb(p, q, h);
|
|
608
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
252
|
+
if (s === 0)
|
|
253
|
+
r = g = b = l;
|
|
254
|
+
else {
|
|
255
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q;
|
|
256
|
+
r = hue2rgb(p, q, h + 1 / 3), g = hue2rgb(p, q, h), b = hue2rgb(p, q, h - 1 / 3);
|
|
609
257
|
}
|
|
610
258
|
return {
|
|
611
259
|
r: r * 255,
|
|
@@ -613,25 +261,12 @@ function hslToRgb(h, s, l) {
|
|
|
613
261
|
b: b * 255
|
|
614
262
|
};
|
|
615
263
|
}
|
|
616
|
-
|
|
617
|
-
// `rgbToHsv`
|
|
618
|
-
// Converts an RGB color value to HSV
|
|
619
|
-
// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
|
|
620
|
-
// *Returns:* { h, s, v } in [0,1]
|
|
621
264
|
function rgbToHsv(r, g, b) {
|
|
622
|
-
r = bound01(r, 255);
|
|
623
|
-
g =
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
var h,
|
|
628
|
-
s,
|
|
629
|
-
v = max;
|
|
630
|
-
var d = max - min;
|
|
631
|
-
s = max === 0 ? 0 : d / max;
|
|
632
|
-
if (max == min) {
|
|
633
|
-
h = 0; // achromatic
|
|
634
|
-
} else {
|
|
265
|
+
r = bound01(r, 255), g = bound01(g, 255), b = bound01(b, 255);
|
|
266
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b), h, s, v = max, d = max - min;
|
|
267
|
+
if (s = max === 0 ? 0 : d / max, max == min)
|
|
268
|
+
h = 0;
|
|
269
|
+
else {
|
|
635
270
|
switch (max) {
|
|
636
271
|
case r:
|
|
637
272
|
h = (g - b) / d + (g < b ? 6 : 0);
|
|
@@ -646,170 +281,92 @@ function rgbToHsv(r, g, b) {
|
|
|
646
281
|
h /= 6;
|
|
647
282
|
}
|
|
648
283
|
return {
|
|
649
|
-
h
|
|
650
|
-
s
|
|
651
|
-
v
|
|
284
|
+
h,
|
|
285
|
+
s,
|
|
286
|
+
v
|
|
652
287
|
};
|
|
653
288
|
}
|
|
654
|
-
|
|
655
|
-
// `hsvToRgb`
|
|
656
|
-
// Converts an HSV color value to RGB.
|
|
657
|
-
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
|
|
658
|
-
// *Returns:* { r, g, b } in the set [0, 255]
|
|
659
289
|
function hsvToRgb(h, s, v) {
|
|
660
|
-
h = bound01(h, 360) * 6;
|
|
661
|
-
s =
|
|
662
|
-
v = bound01(v, 100);
|
|
663
|
-
var i = Math.floor(h),
|
|
664
|
-
f = h - i,
|
|
665
|
-
p = v * (1 - s),
|
|
666
|
-
q = v * (1 - f * s),
|
|
667
|
-
t = v * (1 - (1 - f) * s),
|
|
668
|
-
mod = i % 6,
|
|
669
|
-
r = [v, q, p, p, t, v][mod],
|
|
670
|
-
g = [t, v, v, q, p, p][mod],
|
|
671
|
-
b = [p, p, t, v, v, q][mod];
|
|
290
|
+
h = bound01(h, 360) * 6, s = bound01(s, 100), v = bound01(v, 100);
|
|
291
|
+
var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
|
|
672
292
|
return {
|
|
673
293
|
r: r * 255,
|
|
674
294
|
g: g * 255,
|
|
675
295
|
b: b * 255
|
|
676
296
|
};
|
|
677
297
|
}
|
|
678
|
-
|
|
679
|
-
// `rgbToHex`
|
|
680
|
-
// Converts an RGB color to hex
|
|
681
|
-
// Assumes r, g, and b are contained in the set [0, 255]
|
|
682
|
-
// Returns a 3 or 6 character hex
|
|
683
298
|
function rgbToHex(r, g, b, allow3Char) {
|
|
684
299
|
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
685
|
-
|
|
686
|
-
// Return a 3 character hex if possible
|
|
687
|
-
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
688
|
-
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
689
|
-
}
|
|
690
|
-
return hex.join("");
|
|
300
|
+
return allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) ? hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) : hex.join("");
|
|
691
301
|
}
|
|
692
|
-
|
|
693
|
-
// `rgbaToHex`
|
|
694
|
-
// Converts an RGBA color plus alpha transparency to hex
|
|
695
|
-
// Assumes r, g, b are contained in the set [0, 255] and
|
|
696
|
-
// a in [0, 1]. Returns a 4 or 8 character rgba hex
|
|
697
302
|
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
698
303
|
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
699
|
-
|
|
700
|
-
// Return a 4 character hex if possible
|
|
701
|
-
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
702
|
-
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
703
|
-
}
|
|
704
|
-
return hex.join("");
|
|
304
|
+
return allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1) ? hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0) : hex.join("");
|
|
705
305
|
}
|
|
706
|
-
|
|
707
|
-
// `rgbaToArgbHex`
|
|
708
|
-
// Converts an RGBA color to an ARGB Hex8 string
|
|
709
|
-
// Rarely used, but required for "toFilter()"
|
|
710
306
|
function rgbaToArgbHex(r, g, b, a) {
|
|
711
307
|
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
712
308
|
return hex.join("");
|
|
713
309
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
// Can be called with any tinycolor input
|
|
717
|
-
tinycolor.equals = function (color1, color2) {
|
|
718
|
-
if (!color1 || !color2) return false;
|
|
719
|
-
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
310
|
+
tinycolor.equals = function(color1, color2) {
|
|
311
|
+
return !color1 || !color2 ? !1 : tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
720
312
|
};
|
|
721
|
-
tinycolor.random = function
|
|
313
|
+
tinycolor.random = function() {
|
|
722
314
|
return tinycolor.fromRatio({
|
|
723
315
|
r: Math.random(),
|
|
724
316
|
g: Math.random(),
|
|
725
317
|
b: Math.random()
|
|
726
318
|
});
|
|
727
319
|
};
|
|
728
|
-
|
|
729
|
-
// Modification Functions
|
|
730
|
-
// ----------------------
|
|
731
|
-
// Thanks to less.js for some of the basics here
|
|
732
|
-
// <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
|
|
733
|
-
|
|
734
|
-
function _desaturate(color, amount) {
|
|
320
|
+
function _desaturate(color2, amount) {
|
|
735
321
|
amount = amount === 0 ? 0 : amount || 10;
|
|
736
|
-
var hsl = tinycolor(
|
|
737
|
-
hsl.s -= amount / 100;
|
|
738
|
-
hsl.s = clamp01(hsl.s);
|
|
739
|
-
return tinycolor(hsl);
|
|
322
|
+
var hsl = tinycolor(color2).toHsl();
|
|
323
|
+
return hsl.s -= amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
|
|
740
324
|
}
|
|
741
|
-
function _saturate(
|
|
325
|
+
function _saturate(color2, amount) {
|
|
742
326
|
amount = amount === 0 ? 0 : amount || 10;
|
|
743
|
-
var hsl = tinycolor(
|
|
744
|
-
hsl.s += amount / 100;
|
|
745
|
-
hsl.s = clamp01(hsl.s);
|
|
746
|
-
return tinycolor(hsl);
|
|
327
|
+
var hsl = tinycolor(color2).toHsl();
|
|
328
|
+
return hsl.s += amount / 100, hsl.s = clamp01(hsl.s), tinycolor(hsl);
|
|
747
329
|
}
|
|
748
|
-
function _greyscale(
|
|
749
|
-
return tinycolor(
|
|
330
|
+
function _greyscale(color2) {
|
|
331
|
+
return tinycolor(color2).desaturate(100);
|
|
750
332
|
}
|
|
751
|
-
function _lighten(
|
|
333
|
+
function _lighten(color2, amount) {
|
|
752
334
|
amount = amount === 0 ? 0 : amount || 10;
|
|
753
|
-
var hsl = tinycolor(
|
|
754
|
-
hsl.l += amount / 100;
|
|
755
|
-
hsl.l = clamp01(hsl.l);
|
|
756
|
-
return tinycolor(hsl);
|
|
335
|
+
var hsl = tinycolor(color2).toHsl();
|
|
336
|
+
return hsl.l += amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
|
|
757
337
|
}
|
|
758
|
-
function _brighten(
|
|
338
|
+
function _brighten(color2, amount) {
|
|
759
339
|
amount = amount === 0 ? 0 : amount || 10;
|
|
760
|
-
var rgb = tinycolor(
|
|
761
|
-
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
762
|
-
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
763
|
-
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
764
|
-
return tinycolor(rgb);
|
|
340
|
+
var rgb = tinycolor(color2).toRgb();
|
|
341
|
+
return rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100)))), rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100)))), rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100)))), tinycolor(rgb);
|
|
765
342
|
}
|
|
766
|
-
function _darken(
|
|
343
|
+
function _darken(color2, amount) {
|
|
767
344
|
amount = amount === 0 ? 0 : amount || 10;
|
|
768
|
-
var hsl = tinycolor(
|
|
769
|
-
hsl.l -= amount / 100;
|
|
770
|
-
hsl.l = clamp01(hsl.l);
|
|
771
|
-
return tinycolor(hsl);
|
|
345
|
+
var hsl = tinycolor(color2).toHsl();
|
|
346
|
+
return hsl.l -= amount / 100, hsl.l = clamp01(hsl.l), tinycolor(hsl);
|
|
772
347
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
function _spin(color, amount) {
|
|
777
|
-
var hsl = tinycolor(color).toHsl();
|
|
778
|
-
var hue = (hsl.h + amount) % 360;
|
|
779
|
-
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
780
|
-
return tinycolor(hsl);
|
|
348
|
+
function _spin(color2, amount) {
|
|
349
|
+
var hsl = tinycolor(color2).toHsl(), hue = (hsl.h + amount) % 360;
|
|
350
|
+
return hsl.h = hue < 0 ? 360 + hue : hue, tinycolor(hsl);
|
|
781
351
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
// Thanks to jQuery xColor for some of the ideas behind these
|
|
786
|
-
// <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
|
|
787
|
-
|
|
788
|
-
function _complement(color) {
|
|
789
|
-
var hsl = tinycolor(color).toHsl();
|
|
790
|
-
hsl.h = (hsl.h + 180) % 360;
|
|
791
|
-
return tinycolor(hsl);
|
|
352
|
+
function _complement(color2) {
|
|
353
|
+
var hsl = tinycolor(color2).toHsl();
|
|
354
|
+
return hsl.h = (hsl.h + 180) % 360, tinycolor(hsl);
|
|
792
355
|
}
|
|
793
|
-
function polyad(
|
|
794
|
-
if (isNaN(number) || number <= 0)
|
|
356
|
+
function polyad(color2, number) {
|
|
357
|
+
if (isNaN(number) || number <= 0)
|
|
795
358
|
throw new Error("Argument to polyad must be a positive number");
|
|
796
|
-
|
|
797
|
-
var hsl = tinycolor(color).toHsl();
|
|
798
|
-
var result = [tinycolor(color)];
|
|
799
|
-
var step = 360 / number;
|
|
800
|
-
for (var i = 1; i < number; i++) {
|
|
359
|
+
for (var hsl = tinycolor(color2).toHsl(), result = [tinycolor(color2)], step = 360 / number, i = 1; i < number; i++)
|
|
801
360
|
result.push(tinycolor({
|
|
802
361
|
h: (hsl.h + i * step) % 360,
|
|
803
362
|
s: hsl.s,
|
|
804
363
|
l: hsl.l
|
|
805
364
|
}));
|
|
806
|
-
}
|
|
807
365
|
return result;
|
|
808
366
|
}
|
|
809
|
-
function _splitcomplement(
|
|
810
|
-
var hsl = tinycolor(
|
|
811
|
-
|
|
812
|
-
return [tinycolor(color), tinycolor({
|
|
367
|
+
function _splitcomplement(color2) {
|
|
368
|
+
var hsl = tinycolor(color2).toHsl(), h = hsl.h;
|
|
369
|
+
return [tinycolor(color2), tinycolor({
|
|
813
370
|
h: (h + 72) % 360,
|
|
814
371
|
s: hsl.s,
|
|
815
372
|
l: hsl.l
|
|
@@ -819,46 +376,26 @@ function _splitcomplement(color) {
|
|
|
819
376
|
l: hsl.l
|
|
820
377
|
})];
|
|
821
378
|
}
|
|
822
|
-
function _analogous(
|
|
823
|
-
results = results || 6;
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
var ret = [tinycolor(color)];
|
|
828
|
-
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
|
|
829
|
-
hsl.h = (hsl.h + part) % 360;
|
|
830
|
-
ret.push(tinycolor(hsl));
|
|
831
|
-
}
|
|
379
|
+
function _analogous(color2, results, slices) {
|
|
380
|
+
results = results || 6, slices = slices || 30;
|
|
381
|
+
var hsl = tinycolor(color2).toHsl(), part = 360 / slices, ret = [tinycolor(color2)];
|
|
382
|
+
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; )
|
|
383
|
+
hsl.h = (hsl.h + part) % 360, ret.push(tinycolor(hsl));
|
|
832
384
|
return ret;
|
|
833
385
|
}
|
|
834
|
-
function _monochromatic(
|
|
386
|
+
function _monochromatic(color2, results) {
|
|
835
387
|
results = results || 6;
|
|
836
|
-
var hsv = tinycolor(
|
|
837
|
-
var h = hsv.h,
|
|
838
|
-
s = hsv.s,
|
|
839
|
-
v = hsv.v;
|
|
840
|
-
var ret = [];
|
|
841
|
-
var modification = 1 / results;
|
|
842
|
-
while (results--) {
|
|
388
|
+
for (var hsv = tinycolor(color2).toHsv(), h = hsv.h, s = hsv.s, v = hsv.v, ret = [], modification = 1 / results; results--; )
|
|
843
389
|
ret.push(tinycolor({
|
|
844
|
-
h
|
|
845
|
-
s
|
|
846
|
-
v
|
|
847
|
-
}));
|
|
848
|
-
v = (v + modification) % 1;
|
|
849
|
-
}
|
|
390
|
+
h,
|
|
391
|
+
s,
|
|
392
|
+
v
|
|
393
|
+
})), v = (v + modification) % 1;
|
|
850
394
|
return ret;
|
|
851
395
|
}
|
|
852
|
-
|
|
853
|
-
// Utility Functions
|
|
854
|
-
// ---------------------
|
|
855
|
-
|
|
856
|
-
tinycolor.mix = function (color1, color2, amount) {
|
|
396
|
+
tinycolor.mix = function(color1, color2, amount) {
|
|
857
397
|
amount = amount === 0 ? 0 : amount || 50;
|
|
858
|
-
var rgb1 = tinycolor(color1).toRgb()
|
|
859
|
-
var rgb2 = tinycolor(color2).toRgb();
|
|
860
|
-
var p = amount / 100;
|
|
861
|
-
var rgba = {
|
|
398
|
+
var rgb1 = tinycolor(color1).toRgb(), rgb2 = tinycolor(color2).toRgb(), p = amount / 100, rgba = {
|
|
862
399
|
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
863
400
|
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
864
401
|
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
@@ -866,35 +403,13 @@ tinycolor.mix = function (color1, color2, amount) {
|
|
|
866
403
|
};
|
|
867
404
|
return tinycolor(rgba);
|
|
868
405
|
};
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
// ---------------------
|
|
872
|
-
// <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
|
|
873
|
-
|
|
874
|
-
// `contrast`
|
|
875
|
-
// Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
|
|
876
|
-
tinycolor.readability = function (color1, color2) {
|
|
877
|
-
var c1 = tinycolor(color1);
|
|
878
|
-
var c2 = tinycolor(color2);
|
|
406
|
+
tinycolor.readability = function(color1, color2) {
|
|
407
|
+
var c1 = tinycolor(color1), c2 = tinycolor(color2);
|
|
879
408
|
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
880
409
|
};
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
// The third argument is an optional Object.
|
|
885
|
-
// the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
|
|
886
|
-
// the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
|
|
887
|
-
// If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
|
|
888
|
-
|
|
889
|
-
// *Example*
|
|
890
|
-
// tinycolor.isReadable("#000", "#111") => false
|
|
891
|
-
// tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
|
|
892
|
-
tinycolor.isReadable = function (color1, color2, wcag2) {
|
|
893
|
-
var readability = tinycolor.readability(color1, color2);
|
|
894
|
-
var wcag2Parms, out;
|
|
895
|
-
out = false;
|
|
896
|
-
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
897
|
-
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
410
|
+
tinycolor.isReadable = function(color1, color2, wcag2) {
|
|
411
|
+
var readability = tinycolor.readability(color1, color2), wcag2Parms, out;
|
|
412
|
+
switch (out = !1, wcag2Parms = validateWCAG2Parms(wcag2), wcag2Parms.level + wcag2Parms.size) {
|
|
898
413
|
case "AAsmall":
|
|
899
414
|
case "AAAlarge":
|
|
900
415
|
out = readability >= 4.5;
|
|
@@ -908,46 +423,16 @@ tinycolor.isReadable = function (color1, color2, wcag2) {
|
|
|
908
423
|
}
|
|
909
424
|
return out;
|
|
910
425
|
};
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
|
|
921
|
-
tinycolor.mostReadable = function (baseColor, colorList, args) {
|
|
922
|
-
var bestColor = null;
|
|
923
|
-
var bestScore = 0;
|
|
924
|
-
var readability;
|
|
925
|
-
var includeFallbackColors, level, size;
|
|
926
|
-
args = args || {};
|
|
927
|
-
includeFallbackColors = args.includeFallbackColors;
|
|
928
|
-
level = args.level;
|
|
929
|
-
size = args.size;
|
|
930
|
-
for (var i = 0; i < colorList.length; i++) {
|
|
931
|
-
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
932
|
-
if (readability > bestScore) {
|
|
933
|
-
bestScore = readability;
|
|
934
|
-
bestColor = tinycolor(colorList[i]);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
938
|
-
level: level,
|
|
939
|
-
size: size
|
|
940
|
-
}) || !includeFallbackColors) {
|
|
941
|
-
return bestColor;
|
|
942
|
-
} else {
|
|
943
|
-
args.includeFallbackColors = false;
|
|
944
|
-
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
945
|
-
}
|
|
426
|
+
tinycolor.mostReadable = function(baseColor, colorList, args) {
|
|
427
|
+
var bestColor = null, bestScore = 0, readability, includeFallbackColors, level, size;
|
|
428
|
+
args = args || {}, includeFallbackColors = args.includeFallbackColors, level = args.level, size = args.size;
|
|
429
|
+
for (var i = 0; i < colorList.length; i++)
|
|
430
|
+
readability = tinycolor.readability(baseColor, colorList[i]), readability > bestScore && (bestScore = readability, bestColor = tinycolor(colorList[i]));
|
|
431
|
+
return tinycolor.isReadable(baseColor, bestColor, {
|
|
432
|
+
level,
|
|
433
|
+
size
|
|
434
|
+
}) || !includeFallbackColors ? bestColor : (args.includeFallbackColors = !1, tinycolor.mostReadable(baseColor, ["#fff", "#000"], args));
|
|
946
435
|
};
|
|
947
|
-
|
|
948
|
-
// Big List of Colors
|
|
949
|
-
// ------------------
|
|
950
|
-
// <https://www.w3.org/TR/css-color-4/#named-colors>
|
|
951
436
|
var names = tinycolor.names = {
|
|
952
437
|
aliceblue: "f0f8ff",
|
|
953
438
|
antiquewhite: "faebd7",
|
|
@@ -1098,111 +583,47 @@ var names = tinycolor.names = {
|
|
|
1098
583
|
whitesmoke: "f5f5f5",
|
|
1099
584
|
yellow: "ff0",
|
|
1100
585
|
yellowgreen: "9acd32"
|
|
1101
|
-
};
|
|
1102
|
-
|
|
1103
|
-
// Make it easy to access colors via `hexNames[hex]`
|
|
1104
|
-
var hexNames = tinycolor.hexNames = flip(names);
|
|
1105
|
-
|
|
1106
|
-
// Utilities
|
|
1107
|
-
// ---------
|
|
1108
|
-
|
|
1109
|
-
// `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
|
|
586
|
+
}, hexNames = tinycolor.hexNames = flip(names);
|
|
1110
587
|
function flip(o) {
|
|
1111
588
|
var flipped = {};
|
|
1112
|
-
for (var i in o)
|
|
1113
|
-
|
|
1114
|
-
flipped[o[i]] = i;
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
589
|
+
for (var i in o)
|
|
590
|
+
o.hasOwnProperty(i) && (flipped[o[i]] = i);
|
|
1117
591
|
return flipped;
|
|
1118
592
|
}
|
|
1119
|
-
|
|
1120
|
-
// Return a valid alpha value [0,1] with all invalid values being set to 1
|
|
1121
593
|
function boundAlpha(a) {
|
|
1122
|
-
a = parseFloat(a);
|
|
1123
|
-
if (isNaN(a) || a < 0 || a > 1) {
|
|
1124
|
-
a = 1;
|
|
1125
|
-
}
|
|
1126
|
-
return a;
|
|
594
|
+
return a = parseFloat(a), (isNaN(a) || a < 0 || a > 1) && (a = 1), a;
|
|
1127
595
|
}
|
|
1128
|
-
|
|
1129
|
-
// Take input from [0, n] and return it as [0, 1]
|
|
1130
596
|
function bound01(n, max) {
|
|
1131
|
-
|
|
597
|
+
isOnePointZero(n) && (n = "100%");
|
|
1132
598
|
var processPercent = isPercentage(n);
|
|
1133
|
-
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
1134
|
-
|
|
1135
|
-
// Automatically convert percentage into number
|
|
1136
|
-
if (processPercent) {
|
|
1137
|
-
n = parseInt(n * max, 10) / 100;
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
// Handle floating point rounding errors
|
|
1141
|
-
if (Math.abs(n - max) < 0.000001) {
|
|
1142
|
-
return 1;
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
// Convert into [0, 1] range if it isn't already
|
|
1146
|
-
return n % max / parseFloat(max);
|
|
599
|
+
return n = Math.min(max, Math.max(0, parseFloat(n))), processPercent && (n = parseInt(n * max, 10) / 100), Math.abs(n - max) < 1e-6 ? 1 : n % max / parseFloat(max);
|
|
1147
600
|
}
|
|
1148
|
-
|
|
1149
|
-
// Force a number between 0 and 1
|
|
1150
601
|
function clamp01(val) {
|
|
1151
602
|
return Math.min(1, Math.max(0, val));
|
|
1152
603
|
}
|
|
1153
|
-
|
|
1154
|
-
// Parse a base-16 hex value into a base-10 integer
|
|
1155
604
|
function parseIntFromHex(val) {
|
|
1156
605
|
return parseInt(val, 16);
|
|
1157
606
|
}
|
|
1158
|
-
|
|
1159
|
-
// Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
|
|
1160
|
-
// <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
|
|
1161
607
|
function isOnePointZero(n) {
|
|
1162
608
|
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
1163
609
|
}
|
|
1164
|
-
|
|
1165
|
-
// Check to see if string passed in is a percentage
|
|
1166
610
|
function isPercentage(n) {
|
|
1167
|
-
return typeof n
|
|
611
|
+
return typeof n == "string" && n.indexOf("%") != -1;
|
|
1168
612
|
}
|
|
1169
|
-
|
|
1170
|
-
// Force a hex value to have 2 characters
|
|
1171
613
|
function pad2(c) {
|
|
1172
614
|
return c.length == 1 ? "0" + c : "" + c;
|
|
1173
615
|
}
|
|
1174
|
-
|
|
1175
|
-
// Replace a decimal with it's percentage value
|
|
1176
616
|
function convertToPercentage(n) {
|
|
1177
|
-
|
|
1178
|
-
n = n * 100 + "%";
|
|
1179
|
-
}
|
|
1180
|
-
return n;
|
|
617
|
+
return n <= 1 && (n = n * 100 + "%"), n;
|
|
1181
618
|
}
|
|
1182
|
-
|
|
1183
|
-
// Converts a decimal to a hex value
|
|
1184
619
|
function convertDecimalToHex(d) {
|
|
1185
620
|
return Math.round(parseFloat(d) * 255).toString(16);
|
|
1186
621
|
}
|
|
1187
|
-
// Converts a hex value to a decimal
|
|
1188
622
|
function convertHexToDecimal(h) {
|
|
1189
623
|
return parseIntFromHex(h) / 255;
|
|
1190
624
|
}
|
|
1191
|
-
var matchers = function
|
|
1192
|
-
|
|
1193
|
-
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
1194
|
-
|
|
1195
|
-
// <http://www.w3.org/TR/css3-values/#number-value>
|
|
1196
|
-
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
1197
|
-
|
|
1198
|
-
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
|
1199
|
-
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
1200
|
-
|
|
1201
|
-
// Actual matching.
|
|
1202
|
-
// Parentheses and commas are optional, but not required.
|
|
1203
|
-
// Whitespace can take the place of commas or opening paren
|
|
1204
|
-
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1205
|
-
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
625
|
+
var matchers = function() {
|
|
626
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?", CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?", CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")", PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?", PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1206
627
|
return {
|
|
1207
628
|
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
1208
629
|
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
@@ -1217,24 +638,15 @@ var matchers = function () {
|
|
|
1217
638
|
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
1218
639
|
};
|
|
1219
640
|
}();
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
// Take in a single string / number and check to see if it looks like a CSS unit
|
|
1223
|
-
// (see `matchers` above for definition).
|
|
1224
|
-
function isValidCSSUnit(color) {
|
|
1225
|
-
return !!matchers.CSS_UNIT.exec(color);
|
|
641
|
+
function isValidCSSUnit(color2) {
|
|
642
|
+
return !!matchers.CSS_UNIT.exec(color2);
|
|
1226
643
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
var named = false;
|
|
1234
|
-
if (names[color]) {
|
|
1235
|
-
color = names[color];
|
|
1236
|
-
named = true;
|
|
1237
|
-
} else if (color == "transparent") {
|
|
644
|
+
function stringInputToObject(color2) {
|
|
645
|
+
color2 = color2.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
646
|
+
var named = !1;
|
|
647
|
+
if (names[color2])
|
|
648
|
+
color2 = names[color2], named = !0;
|
|
649
|
+
else if (color2 == "transparent")
|
|
1238
650
|
return {
|
|
1239
651
|
r: 0,
|
|
1240
652
|
g: 0,
|
|
@@ -1242,421 +654,421 @@ function stringInputToObject(color) {
|
|
|
1242
654
|
a: 0,
|
|
1243
655
|
format: "name"
|
|
1244
656
|
};
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
// Try to match string input using regular expressions.
|
|
1248
|
-
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
|
|
1249
|
-
// Just return an object and let the conversion functions handle that.
|
|
1250
|
-
// This way the result will be the same whether the tinycolor is initialized with string or object.
|
|
1251
657
|
var match;
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
a: convertHexToDecimal(match[4]),
|
|
1303
|
-
format: named ? "name" : "hex8"
|
|
1304
|
-
};
|
|
1305
|
-
}
|
|
1306
|
-
if (match = matchers.hex6.exec(color)) {
|
|
1307
|
-
return {
|
|
1308
|
-
r: parseIntFromHex(match[1]),
|
|
1309
|
-
g: parseIntFromHex(match[2]),
|
|
1310
|
-
b: parseIntFromHex(match[3]),
|
|
1311
|
-
format: named ? "name" : "hex"
|
|
1312
|
-
};
|
|
1313
|
-
}
|
|
1314
|
-
if (match = matchers.hex4.exec(color)) {
|
|
1315
|
-
return {
|
|
1316
|
-
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1317
|
-
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1318
|
-
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1319
|
-
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
1320
|
-
format: named ? "name" : "hex8"
|
|
1321
|
-
};
|
|
1322
|
-
}
|
|
1323
|
-
if (match = matchers.hex3.exec(color)) {
|
|
1324
|
-
return {
|
|
1325
|
-
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1326
|
-
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1327
|
-
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1328
|
-
format: named ? "name" : "hex"
|
|
1329
|
-
};
|
|
1330
|
-
}
|
|
1331
|
-
return false;
|
|
658
|
+
return (match = matchers.rgb.exec(color2)) ? {
|
|
659
|
+
r: match[1],
|
|
660
|
+
g: match[2],
|
|
661
|
+
b: match[3]
|
|
662
|
+
} : (match = matchers.rgba.exec(color2)) ? {
|
|
663
|
+
r: match[1],
|
|
664
|
+
g: match[2],
|
|
665
|
+
b: match[3],
|
|
666
|
+
a: match[4]
|
|
667
|
+
} : (match = matchers.hsl.exec(color2)) ? {
|
|
668
|
+
h: match[1],
|
|
669
|
+
s: match[2],
|
|
670
|
+
l: match[3]
|
|
671
|
+
} : (match = matchers.hsla.exec(color2)) ? {
|
|
672
|
+
h: match[1],
|
|
673
|
+
s: match[2],
|
|
674
|
+
l: match[3],
|
|
675
|
+
a: match[4]
|
|
676
|
+
} : (match = matchers.hsv.exec(color2)) ? {
|
|
677
|
+
h: match[1],
|
|
678
|
+
s: match[2],
|
|
679
|
+
v: match[3]
|
|
680
|
+
} : (match = matchers.hsva.exec(color2)) ? {
|
|
681
|
+
h: match[1],
|
|
682
|
+
s: match[2],
|
|
683
|
+
v: match[3],
|
|
684
|
+
a: match[4]
|
|
685
|
+
} : (match = matchers.hex8.exec(color2)) ? {
|
|
686
|
+
r: parseIntFromHex(match[1]),
|
|
687
|
+
g: parseIntFromHex(match[2]),
|
|
688
|
+
b: parseIntFromHex(match[3]),
|
|
689
|
+
a: convertHexToDecimal(match[4]),
|
|
690
|
+
format: named ? "name" : "hex8"
|
|
691
|
+
} : (match = matchers.hex6.exec(color2)) ? {
|
|
692
|
+
r: parseIntFromHex(match[1]),
|
|
693
|
+
g: parseIntFromHex(match[2]),
|
|
694
|
+
b: parseIntFromHex(match[3]),
|
|
695
|
+
format: named ? "name" : "hex"
|
|
696
|
+
} : (match = matchers.hex4.exec(color2)) ? {
|
|
697
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
698
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
699
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
700
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
701
|
+
format: named ? "name" : "hex8"
|
|
702
|
+
} : (match = matchers.hex3.exec(color2)) ? {
|
|
703
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
704
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
705
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
706
|
+
format: named ? "name" : "hex"
|
|
707
|
+
} : !1;
|
|
1332
708
|
}
|
|
1333
709
|
function validateWCAG2Parms(parms) {
|
|
1334
|
-
// return valid WCAG2 parms for isReadable.
|
|
1335
|
-
// If input parms are invalid, return {"level":"AA", "size":"small"}
|
|
1336
710
|
var level, size;
|
|
1337
|
-
parms = parms || {
|
|
711
|
+
return parms = parms || {
|
|
1338
712
|
level: "AA",
|
|
1339
713
|
size: "small"
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
if (level !== "AA" && level !== "AAA") {
|
|
1344
|
-
level = "AA";
|
|
1345
|
-
}
|
|
1346
|
-
if (size !== "small" && size !== "large") {
|
|
1347
|
-
size = "small";
|
|
1348
|
-
}
|
|
1349
|
-
return {
|
|
1350
|
-
level: level,
|
|
1351
|
-
size: size
|
|
714
|
+
}, level = (parms.level || "AA").toUpperCase(), size = (parms.size || "small").toLowerCase(), level !== "AA" && level !== "AAA" && (level = "AA"), size !== "small" && size !== "large" && (size = "small"), {
|
|
715
|
+
level,
|
|
716
|
+
size
|
|
1352
717
|
};
|
|
1353
718
|
}
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
return /* @__PURE__ */jsx(ColorListWrap, {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
719
|
+
const ColorListWrap = styled(Flex)`
|
|
720
|
+
gap: 0.25em;
|
|
721
|
+
`, ColorBoxContainer = styled.div`
|
|
722
|
+
width: 2.1em;
|
|
723
|
+
height: 2.1em;
|
|
724
|
+
cursor: pointer;
|
|
725
|
+
position: relative;
|
|
726
|
+
overflow: hidden;
|
|
727
|
+
border-radius: 3px;
|
|
728
|
+
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAADFJREFUOE9jZGBgEGHAD97gk2YcNYBhmIQBgWSAP52AwoAQwJvQRg1gACckQoC2gQgAIF8IscwEtKYAAAAASUVORK5CYII=')
|
|
729
|
+
left center #fff;
|
|
730
|
+
`, ColorBox$1 = styled.div`
|
|
731
|
+
border-radius: inherit;
|
|
732
|
+
box-shadow: inset 0 0 0 1px var(--card-shadow-outline-color);
|
|
733
|
+
content: '';
|
|
734
|
+
position: absolute;
|
|
735
|
+
inset: 0;
|
|
736
|
+
z-index: 1;
|
|
737
|
+
`, validateColors = (colors) => colors.reduce((cls, c) => {
|
|
738
|
+
const color2 = c.hex ? tinycolor(c.hex) : tinycolor(c);
|
|
739
|
+
return color2.isValid() && cls.push({
|
|
740
|
+
color: c,
|
|
741
|
+
backgroundColor: color2.toRgbString()
|
|
742
|
+
}), cls;
|
|
743
|
+
}, []), ColorList = memo(function({ colors, onChange }) {
|
|
744
|
+
return colors ? /* @__PURE__ */ jsx(ColorListWrap, { wrap: "wrap", children: validateColors(colors).map(({ color: color2, backgroundColor }, idx) => /* @__PURE__ */ jsx(
|
|
745
|
+
ColorBoxContainer,
|
|
746
|
+
{
|
|
747
|
+
onClick: () => {
|
|
748
|
+
onChange(color2);
|
|
749
|
+
},
|
|
750
|
+
children: /* @__PURE__ */ jsx(ColorBox$1, { style: { background: backgroundColor } })
|
|
751
|
+
},
|
|
752
|
+
`${backgroundColor}-${idx}`
|
|
753
|
+
)) }) : null;
|
|
754
|
+
}), ColorPickerFields = ({
|
|
755
|
+
onChange,
|
|
756
|
+
rgb,
|
|
757
|
+
hsl,
|
|
758
|
+
hex,
|
|
759
|
+
disableAlpha
|
|
760
|
+
}) => {
|
|
761
|
+
const { sanity } = useTheme(), inputStyles = useMemo(
|
|
762
|
+
() => ({
|
|
763
|
+
input: {
|
|
764
|
+
width: "80%",
|
|
765
|
+
padding: "4px 10% 3px",
|
|
766
|
+
border: "none",
|
|
767
|
+
boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,
|
|
768
|
+
color: sanity.color.input.default.enabled.fg,
|
|
769
|
+
backgroundColor: sanity.color.input.default.enabled.bg,
|
|
770
|
+
fontSize: sanity.fonts.text.sizes[0].fontSize,
|
|
771
|
+
textAlign: "center"
|
|
772
|
+
},
|
|
773
|
+
label: {
|
|
774
|
+
display: "block",
|
|
775
|
+
textAlign: "center",
|
|
776
|
+
fontSize: sanity.fonts.label.sizes[0].fontSize,
|
|
777
|
+
color: sanity.color.base.fg,
|
|
778
|
+
paddingTop: "3px",
|
|
779
|
+
paddingBottom: "4px",
|
|
780
|
+
textTransform: "capitalize"
|
|
781
|
+
}
|
|
782
|
+
}),
|
|
783
|
+
[sanity]
|
|
784
|
+
), handleChange = useCallback(
|
|
785
|
+
(data) => {
|
|
786
|
+
if ("hex" in data && data.hex && isValidHex(data.hex))
|
|
787
|
+
onChange({
|
|
788
|
+
hex: data.hex,
|
|
789
|
+
source: "hex"
|
|
790
|
+
});
|
|
791
|
+
else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b))
|
|
792
|
+
onChange({
|
|
793
|
+
r: Number(data.r) || rgb.r,
|
|
794
|
+
g: Number(data.g) || rgb.g,
|
|
795
|
+
b: Number(data.b) || rgb.b,
|
|
796
|
+
a: rgb.a,
|
|
797
|
+
source: "rgb"
|
|
798
|
+
});
|
|
799
|
+
else if (hsl && "a" in data && data.a) {
|
|
800
|
+
let alpha = Number(data.a);
|
|
801
|
+
alpha < 0 ? alpha = 0 : alpha > 100 && (alpha = 100), alpha /= 100, onChange({
|
|
802
|
+
h: hsl.h,
|
|
803
|
+
s: hsl.s,
|
|
804
|
+
l: hsl.l,
|
|
805
|
+
a: alpha,
|
|
806
|
+
source: "hsl"
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
[onChange, hsl, rgb]
|
|
811
|
+
);
|
|
812
|
+
return /* @__PURE__ */ jsxs(Flex, { children: [
|
|
813
|
+
/* @__PURE__ */ jsx(Box, { flex: 2, marginRight: 1, children: /* @__PURE__ */ jsx(
|
|
814
|
+
EditableInput,
|
|
815
|
+
{
|
|
816
|
+
style: inputStyles,
|
|
817
|
+
label: "hex",
|
|
818
|
+
value: hex?.replace("#", ""),
|
|
819
|
+
onChange: handleChange
|
|
820
|
+
}
|
|
821
|
+
) }),
|
|
822
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
|
|
823
|
+
EditableInput,
|
|
824
|
+
{
|
|
825
|
+
style: inputStyles,
|
|
826
|
+
label: "r",
|
|
827
|
+
value: rgb?.r,
|
|
828
|
+
onChange: handleChange,
|
|
829
|
+
dragLabel: !0,
|
|
830
|
+
dragMax: 255
|
|
831
|
+
}
|
|
832
|
+
) }),
|
|
833
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
|
|
834
|
+
EditableInput,
|
|
835
|
+
{
|
|
836
|
+
style: inputStyles,
|
|
837
|
+
label: "g",
|
|
838
|
+
value: rgb?.g,
|
|
839
|
+
onChange: handleChange,
|
|
840
|
+
dragLabel: !0,
|
|
841
|
+
dragMax: 255
|
|
842
|
+
}
|
|
843
|
+
) }),
|
|
844
|
+
/* @__PURE__ */ jsx(Box, { flex: 1, marginRight: 1, children: /* @__PURE__ */ jsx(
|
|
845
|
+
EditableInput,
|
|
846
|
+
{
|
|
847
|
+
style: inputStyles,
|
|
848
|
+
label: "b",
|
|
849
|
+
value: rgb?.b,
|
|
850
|
+
onChange: handleChange,
|
|
851
|
+
dragLabel: !0,
|
|
852
|
+
dragMax: 255
|
|
853
|
+
}
|
|
854
|
+
) }),
|
|
855
|
+
!disableAlpha && /* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsx(
|
|
856
|
+
EditableInput,
|
|
857
|
+
{
|
|
858
|
+
style: inputStyles,
|
|
859
|
+
label: "a",
|
|
860
|
+
value: Math.round((rgb?.a ?? 1) * 100),
|
|
861
|
+
onChange: handleChange,
|
|
862
|
+
dragLabel: !0,
|
|
863
|
+
dragMax: 100
|
|
864
|
+
}
|
|
865
|
+
) })
|
|
866
|
+
] });
|
|
867
|
+
}, ColorBox = styled(Box)`
|
|
868
|
+
position: absolute;
|
|
869
|
+
top: 0;
|
|
870
|
+
left: 0;
|
|
871
|
+
width: 100%;
|
|
872
|
+
height: 100%;
|
|
873
|
+
`, ReadOnlyContainer = styled(Flex)`
|
|
874
|
+
margin-top: 6rem;
|
|
875
|
+
background-color: var(--card-bg-color);
|
|
876
|
+
position: relative;
|
|
877
|
+
width: 100%;
|
|
878
|
+
`, ColorPickerInner = (props) => {
|
|
1409
879
|
const {
|
|
1410
880
|
width,
|
|
1411
|
-
color: {
|
|
1412
|
-
rgb,
|
|
1413
|
-
hex,
|
|
1414
|
-
hsv,
|
|
1415
|
-
hsl
|
|
1416
|
-
},
|
|
881
|
+
color: { rgb, hex, hsv, hsl },
|
|
1417
882
|
onChange,
|
|
1418
883
|
onUnset,
|
|
1419
884
|
disableAlpha,
|
|
1420
885
|
colorList,
|
|
1421
886
|
readOnly
|
|
1422
887
|
} = props;
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
overflow: "hidden",
|
|
1464
|
-
style: {
|
|
1465
|
-
position: "relative",
|
|
1466
|
-
height: "10px",
|
|
1467
|
-
background: "#fff"
|
|
1468
|
-
},
|
|
1469
|
-
children: /* @__PURE__ */jsx(Alpha, {
|
|
1470
|
-
rgb,
|
|
1471
|
-
hsl,
|
|
1472
|
-
onChange
|
|
1473
|
-
})
|
|
1474
|
-
})]
|
|
1475
|
-
}), /* @__PURE__ */jsxs(Flex, {
|
|
1476
|
-
children: [/* @__PURE__ */jsxs(Card, {
|
|
1477
|
-
flex: 1,
|
|
1478
|
-
radius: 2,
|
|
1479
|
-
overflow: "hidden",
|
|
1480
|
-
style: {
|
|
1481
|
-
position: "relative",
|
|
1482
|
-
minWidth: "4em",
|
|
1483
|
-
background: "#fff"
|
|
1484
|
-
},
|
|
1485
|
-
children: [/* @__PURE__ */jsx(Checkboard, {}), /* @__PURE__ */jsx(ColorBox, {
|
|
1486
|
-
style: {
|
|
1487
|
-
backgroundColor: "rgba(".concat(rgb == null ? void 0 : rgb.r, ",").concat(rgb == null ? void 0 : rgb.g, ",").concat(rgb == null ? void 0 : rgb.b, ",").concat(rgb == null ? void 0 : rgb.a, ")")
|
|
888
|
+
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: [
|
|
889
|
+
!readOnly && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
890
|
+
/* @__PURE__ */ jsx(Card, { overflow: "hidden", style: { position: "relative", height: "5em" }, children: /* @__PURE__ */ jsx(Saturation, { onChange, hsl, hsv }) }),
|
|
891
|
+
/* @__PURE__ */ jsx(
|
|
892
|
+
Card,
|
|
893
|
+
{
|
|
894
|
+
shadow: 1,
|
|
895
|
+
radius: 3,
|
|
896
|
+
overflow: "hidden",
|
|
897
|
+
style: { position: "relative", height: "10px" },
|
|
898
|
+
children: /* @__PURE__ */ jsx(Hue, { hsl, onChange: !readOnly && onChange })
|
|
899
|
+
}
|
|
900
|
+
),
|
|
901
|
+
!disableAlpha && /* @__PURE__ */ jsx(
|
|
902
|
+
Card,
|
|
903
|
+
{
|
|
904
|
+
shadow: 1,
|
|
905
|
+
radius: 3,
|
|
906
|
+
overflow: "hidden",
|
|
907
|
+
style: { position: "relative", height: "10px", background: "#fff" },
|
|
908
|
+
children: /* @__PURE__ */ jsx(Alpha, { rgb, hsl, onChange })
|
|
909
|
+
}
|
|
910
|
+
)
|
|
911
|
+
] }),
|
|
912
|
+
/* @__PURE__ */ jsxs(Flex, { children: [
|
|
913
|
+
/* @__PURE__ */ jsxs(
|
|
914
|
+
Card,
|
|
915
|
+
{
|
|
916
|
+
flex: 1,
|
|
917
|
+
radius: 2,
|
|
918
|
+
overflow: "hidden",
|
|
919
|
+
style: { position: "relative", minWidth: "4em", background: "#fff" },
|
|
920
|
+
children: [
|
|
921
|
+
/* @__PURE__ */ jsx(Checkboard, {}),
|
|
922
|
+
/* @__PURE__ */ jsx(
|
|
923
|
+
ColorBox,
|
|
924
|
+
{
|
|
925
|
+
style: {
|
|
926
|
+
backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`
|
|
927
|
+
}
|
|
1488
928
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
children:
|
|
1498
|
-
size: 3,
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
}),
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
colors: colorList,
|
|
1543
|
-
onChange
|
|
1544
|
-
})]
|
|
1545
|
-
})
|
|
1546
|
-
})
|
|
1547
|
-
});
|
|
1548
|
-
};
|
|
1549
|
-
const ColorPicker = CustomPicker(ColorPickerInner);
|
|
1550
|
-
const DEFAULT_COLOR = {
|
|
929
|
+
),
|
|
930
|
+
readOnly && /* @__PURE__ */ jsx(
|
|
931
|
+
ReadOnlyContainer,
|
|
932
|
+
{
|
|
933
|
+
padding: 2,
|
|
934
|
+
paddingBottom: 1,
|
|
935
|
+
sizing: "border",
|
|
936
|
+
justify: "space-between",
|
|
937
|
+
children: /* @__PURE__ */ jsxs(Stack, { space: 3, marginTop: 1, children: [
|
|
938
|
+
/* @__PURE__ */ jsx(Text, { size: 3, weight: "bold", children: hex }),
|
|
939
|
+
/* @__PURE__ */ jsxs(Inline, { space: 3, children: [
|
|
940
|
+
/* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
941
|
+
/* @__PURE__ */ jsx("strong", { children: "RGB: " }),
|
|
942
|
+
rgb?.r,
|
|
943
|
+
" ",
|
|
944
|
+
rgb?.g,
|
|
945
|
+
" ",
|
|
946
|
+
rgb?.b
|
|
947
|
+
] }),
|
|
948
|
+
/* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
949
|
+
/* @__PURE__ */ jsx("strong", { children: "HSL: " }),
|
|
950
|
+
" ",
|
|
951
|
+
Math.round(hsl?.h ?? 0),
|
|
952
|
+
" ",
|
|
953
|
+
Math.round((hsl?.s ?? 0) * 100),
|
|
954
|
+
"% ",
|
|
955
|
+
Math.round((hsl?.l ?? 0) * 100),
|
|
956
|
+
"%"
|
|
957
|
+
] })
|
|
958
|
+
] })
|
|
959
|
+
] })
|
|
960
|
+
}
|
|
961
|
+
)
|
|
962
|
+
]
|
|
963
|
+
}
|
|
964
|
+
),
|
|
965
|
+
!readOnly && /* @__PURE__ */ jsxs(Flex, { align: "flex-start", marginLeft: 2, children: [
|
|
966
|
+
/* @__PURE__ */ jsx(Box, { style: { width: 200 }, children: /* @__PURE__ */ jsx(
|
|
967
|
+
ColorPickerFields,
|
|
968
|
+
{
|
|
969
|
+
rgb,
|
|
970
|
+
hsl,
|
|
971
|
+
hex,
|
|
972
|
+
onChange,
|
|
973
|
+
disableAlpha
|
|
974
|
+
}
|
|
975
|
+
) }),
|
|
976
|
+
/* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(Button, { onClick: onUnset, title: "Delete color", icon: TrashIcon, tone: "critical" }) })
|
|
977
|
+
] })
|
|
978
|
+
] }),
|
|
979
|
+
colorList && /* @__PURE__ */ jsx(ColorList, { colors: colorList, onChange })
|
|
980
|
+
] }) }) });
|
|
981
|
+
}, ColorPicker = CustomPicker(ColorPickerInner), DEFAULT_COLOR = {
|
|
1551
982
|
hex: "#24a3e3",
|
|
1552
|
-
hsl: {
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
l: 0.5156,
|
|
1556
|
-
a: 1
|
|
1557
|
-
},
|
|
1558
|
-
hsv: {
|
|
1559
|
-
h: 200,
|
|
1560
|
-
s: 0.8414,
|
|
1561
|
-
v: 0.8901,
|
|
1562
|
-
a: 1
|
|
1563
|
-
},
|
|
1564
|
-
rgb: {
|
|
1565
|
-
r: 46,
|
|
1566
|
-
g: 163,
|
|
1567
|
-
b: 227,
|
|
1568
|
-
a: 1
|
|
1569
|
-
},
|
|
983
|
+
hsl: { h: 200, s: 0.7732, l: 0.5156, a: 1 },
|
|
984
|
+
hsv: { h: 200, s: 0.8414, v: 0.8901, a: 1 },
|
|
985
|
+
rgb: { r: 46, g: 163, b: 227, a: 1 },
|
|
1570
986
|
source: "hex"
|
|
1571
987
|
};
|
|
1572
988
|
function ColorInput(props) {
|
|
1573
|
-
|
|
1574
|
-
const {
|
|
1575
|
-
onChange,
|
|
1576
|
-
readOnly
|
|
1577
|
-
} = props;
|
|
1578
|
-
const value = props.value;
|
|
1579
|
-
const type = props.schemaType;
|
|
1580
|
-
const focusRef = useRef(null);
|
|
1581
|
-
const [color, setColor] = useState(value);
|
|
989
|
+
const { onChange, readOnly } = props, value = props.value, type = props.schemaType, focusRef = useRef(null), [color2, setColor] = useState(value);
|
|
1582
990
|
useEffect(() => setColor(value), [value]);
|
|
1583
|
-
const emitSetColor = useCallback(
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
setColor(
|
|
1607
|
-
|
|
991
|
+
const emitSetColor = useCallback(
|
|
992
|
+
(nextColor) => {
|
|
993
|
+
const fieldPatches = type.fields.filter((field) => field.name in nextColor).map((field) => {
|
|
994
|
+
const nextFieldValue = nextColor[field.name], isObject = field.type.jsonType === "object";
|
|
995
|
+
return set(
|
|
996
|
+
isObject ? Object.assign({ _type: field.type.name }, nextFieldValue) : nextFieldValue,
|
|
997
|
+
[field.name]
|
|
998
|
+
);
|
|
999
|
+
});
|
|
1000
|
+
onChange([
|
|
1001
|
+
setIfMissing({ _type: type.name }),
|
|
1002
|
+
set(type.name, ["_type"]),
|
|
1003
|
+
set(nextColor.rgb?.a, ["alpha"]),
|
|
1004
|
+
...fieldPatches
|
|
1005
|
+
]);
|
|
1006
|
+
},
|
|
1007
|
+
[onChange, type]
|
|
1008
|
+
), debouncedColorChange = useMemo(() => debounce(emitSetColor, 100), [emitSetColor]), handleColorChange = useCallback(
|
|
1009
|
+
(nextColor) => {
|
|
1010
|
+
setColor(nextColor), debouncedColorChange(nextColor);
|
|
1011
|
+
},
|
|
1012
|
+
[debouncedColorChange, setColor]
|
|
1013
|
+
), handleCreateColor = useCallback(() => {
|
|
1014
|
+
setColor(DEFAULT_COLOR), emitSetColor(DEFAULT_COLOR);
|
|
1015
|
+
}, [emitSetColor]), handleUnset = useCallback(() => {
|
|
1016
|
+
setColor(void 0), onChange(unset());
|
|
1608
1017
|
}, [onChange]);
|
|
1609
|
-
return /* @__PURE__ */jsx(Fragment, {
|
|
1610
|
-
|
|
1611
|
-
|
|
1018
|
+
return /* @__PURE__ */ jsx(Fragment, { children: value && value.hex ? /* @__PURE__ */ jsx(
|
|
1019
|
+
ColorPicker,
|
|
1020
|
+
{
|
|
1021
|
+
color: color2,
|
|
1612
1022
|
onChange: handleColorChange,
|
|
1613
|
-
readOnly: readOnly || typeof type.readOnly
|
|
1614
|
-
disableAlpha: !!
|
|
1615
|
-
colorList:
|
|
1023
|
+
readOnly: readOnly || typeof type.readOnly == "boolean" && type.readOnly,
|
|
1024
|
+
disableAlpha: !!type.options?.disableAlpha,
|
|
1025
|
+
colorList: type.options?.colorList,
|
|
1616
1026
|
onUnset: handleUnset
|
|
1617
|
-
}
|
|
1027
|
+
}
|
|
1028
|
+
) : /* @__PURE__ */ jsx(
|
|
1029
|
+
Button,
|
|
1030
|
+
{
|
|
1618
1031
|
icon: AddIcon,
|
|
1619
1032
|
mode: "ghost",
|
|
1620
1033
|
text: "Create color",
|
|
1621
1034
|
ref: focusRef,
|
|
1622
|
-
disabled:
|
|
1035
|
+
disabled: !!readOnly,
|
|
1623
1036
|
onClick: handleCreateColor
|
|
1624
|
-
}
|
|
1625
|
-
});
|
|
1037
|
+
}
|
|
1038
|
+
) });
|
|
1626
1039
|
}
|
|
1627
|
-
const round =
|
|
1628
|
-
let val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
1629
|
-
return Math.round(val * 100);
|
|
1630
|
-
};
|
|
1631
|
-
const colorTypeName = "color";
|
|
1632
|
-
const color = defineType({
|
|
1040
|
+
const round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = defineType({
|
|
1633
1041
|
name: colorTypeName,
|
|
1634
1042
|
type: "object",
|
|
1635
1043
|
title: "Color",
|
|
1636
|
-
components: {
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1044
|
+
components: { input: ColorInput },
|
|
1045
|
+
fields: [
|
|
1046
|
+
{
|
|
1047
|
+
title: "Hex",
|
|
1048
|
+
name: "hex",
|
|
1049
|
+
type: "string"
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
title: "Alpha",
|
|
1053
|
+
name: "alpha",
|
|
1054
|
+
type: "number"
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
title: "Hue Saturation Lightness",
|
|
1058
|
+
name: "hsl",
|
|
1059
|
+
type: "hslaColor"
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
title: "Hue Saturation Value",
|
|
1063
|
+
name: "hsv",
|
|
1064
|
+
type: "hsvaColor"
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
title: "Red Green Blue (rgb)",
|
|
1068
|
+
name: "rgb",
|
|
1069
|
+
type: "rgbaColor"
|
|
1070
|
+
}
|
|
1071
|
+
],
|
|
1660
1072
|
preview: {
|
|
1661
1073
|
select: {
|
|
1662
1074
|
title: "hex",
|
|
@@ -1664,62 +1076,75 @@ const color = defineType({
|
|
|
1664
1076
|
hex: "hex",
|
|
1665
1077
|
hsl: "hsl"
|
|
1666
1078
|
},
|
|
1667
|
-
prepare(
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
} = _ref4;
|
|
1079
|
+
prepare({
|
|
1080
|
+
title,
|
|
1081
|
+
hex,
|
|
1082
|
+
hsl,
|
|
1083
|
+
alpha
|
|
1084
|
+
}) {
|
|
1674
1085
|
let subtitle = hex || "No color set";
|
|
1675
|
-
|
|
1676
|
-
subtitle = "H:".concat(round(hsl.h), " S:").concat(round(hsl.s), " L:").concat(round(hsl.l), " A:").concat(round(alpha));
|
|
1677
|
-
}
|
|
1678
|
-
return {
|
|
1086
|
+
return hsl && (subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`), {
|
|
1679
1087
|
title,
|
|
1680
1088
|
subtitle,
|
|
1681
|
-
media: () => /* @__PURE__ */jsx(
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1089
|
+
media: () => /* @__PURE__ */ jsx(
|
|
1090
|
+
"div",
|
|
1091
|
+
{
|
|
1092
|
+
style: {
|
|
1093
|
+
backgroundColor: hex ?? "#000",
|
|
1094
|
+
opacity: alpha ?? 1,
|
|
1095
|
+
position: "absolute",
|
|
1096
|
+
height: "100%",
|
|
1097
|
+
width: "100%",
|
|
1098
|
+
top: "0",
|
|
1099
|
+
left: "0"
|
|
1100
|
+
}
|
|
1690
1101
|
}
|
|
1691
|
-
|
|
1102
|
+
)
|
|
1692
1103
|
};
|
|
1693
1104
|
}
|
|
1694
1105
|
}
|
|
1695
|
-
})
|
|
1696
|
-
|
|
1106
|
+
}), hslaColor = defineType({
|
|
1107
|
+
title: "Hue Saturation Lightness",
|
|
1108
|
+
name: "hslaColor",
|
|
1109
|
+
type: "object",
|
|
1110
|
+
fields: [
|
|
1111
|
+
{ name: "h", type: "number", title: "Hue" },
|
|
1112
|
+
{ name: "s", type: "number", title: "Saturation" },
|
|
1113
|
+
{ name: "l", type: "number", title: "Lightness" },
|
|
1114
|
+
{ name: "a", type: "number", title: "Alpha" }
|
|
1115
|
+
]
|
|
1116
|
+
}), hsvaColor = defineType({
|
|
1697
1117
|
title: "Hue Saturation Value",
|
|
1698
1118
|
name: "hsvaColor",
|
|
1699
1119
|
type: "object",
|
|
1700
|
-
fields: [
|
|
1701
|
-
name: "h",
|
|
1702
|
-
type: "number",
|
|
1703
|
-
title: "
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
title: "
|
|
1712
|
-
|
|
1713
|
-
name: "
|
|
1714
|
-
type: "number",
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
});
|
|
1718
|
-
const colorInput = definePlugin({
|
|
1120
|
+
fields: [
|
|
1121
|
+
{ name: "h", type: "number", title: "Hue" },
|
|
1122
|
+
{ name: "s", type: "number", title: "Saturation" },
|
|
1123
|
+
{ name: "v", type: "number", title: "Value" },
|
|
1124
|
+
{ name: "a", type: "number", title: "Alpha" }
|
|
1125
|
+
]
|
|
1126
|
+
}), rgbaColor = defineType({
|
|
1127
|
+
title: "Red Green Blue (rgb)",
|
|
1128
|
+
name: "rgbaColor",
|
|
1129
|
+
type: "object",
|
|
1130
|
+
fields: [
|
|
1131
|
+
{ name: "r", type: "number", title: "Red" },
|
|
1132
|
+
{ name: "g", type: "number", title: "Green" },
|
|
1133
|
+
{ name: "b", type: "number", title: "Blue" },
|
|
1134
|
+
{ name: "a", type: "number", title: "Alpha" }
|
|
1135
|
+
]
|
|
1136
|
+
}), colorInput = definePlugin({
|
|
1719
1137
|
name: "@sanity/color-input",
|
|
1720
1138
|
schema: {
|
|
1721
1139
|
types: [hslaColor, hsvaColor, rgbaColor, color]
|
|
1722
1140
|
}
|
|
1723
1141
|
});
|
|
1724
|
-
export {
|
|
1142
|
+
export {
|
|
1143
|
+
ColorInput,
|
|
1144
|
+
color,
|
|
1145
|
+
colorInput,
|
|
1146
|
+
hslaColor,
|
|
1147
|
+
hsvaColor,
|
|
1148
|
+
rgbaColor
|
|
1149
|
+
};
|
|
1725
1150
|
//# sourceMappingURL=index.esm.js.map
|