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