@digipair/skill-web-jsoneditor 0.114.2 → 0.114.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +10 -85512
- package/dist/index.esm.js +5 -5
- package/package.json +5 -2
- package/dist/vanilla-picker.cjs.js +0 -1041
|
@@ -1,1041 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/*!
|
|
4
|
-
* vanilla-picker v2.12.3
|
|
5
|
-
* https://vanilla-picker.js.org
|
|
6
|
-
*
|
|
7
|
-
* Copyright 2017-2024 Andreas Borgen (https://github.com/Sphinxxxx), Adam Brooks (https://github.com/dissimulate)
|
|
8
|
-
* Released under the ISC license.
|
|
9
|
-
*/ function _instanceof(left, right) {
|
|
10
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
11
|
-
return !!right[Symbol.hasInstance](left);
|
|
12
|
-
} else {
|
|
13
|
-
return left instanceof right;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
var classCallCheck = function classCallCheck(instance, Constructor) {
|
|
17
|
-
if (!_instanceof(instance, Constructor)) {
|
|
18
|
-
throw new TypeError("Cannot call a class as a function");
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var createClass = function() {
|
|
22
|
-
function defineProperties(target, props) {
|
|
23
|
-
for(var i = 0; i < props.length; i++){
|
|
24
|
-
var descriptor = props[i];
|
|
25
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
26
|
-
descriptor.configurable = true;
|
|
27
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
28
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return function(Constructor, protoProps, staticProps) {
|
|
32
|
-
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
33
|
-
if (staticProps) defineProperties(Constructor, staticProps);
|
|
34
|
-
return Constructor;
|
|
35
|
-
};
|
|
36
|
-
}();
|
|
37
|
-
var slicedToArray = function() {
|
|
38
|
-
function sliceIterator(arr, i) {
|
|
39
|
-
var _arr = [];
|
|
40
|
-
var _n = true;
|
|
41
|
-
var _d = false;
|
|
42
|
-
var _e = undefined;
|
|
43
|
-
try {
|
|
44
|
-
for(var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true){
|
|
45
|
-
_arr.push(_s.value);
|
|
46
|
-
if (i && _arr.length === i) break;
|
|
47
|
-
}
|
|
48
|
-
} catch (err) {
|
|
49
|
-
_d = true;
|
|
50
|
-
_e = err;
|
|
51
|
-
} finally{
|
|
52
|
-
try {
|
|
53
|
-
if (!_n && _i["return"]) _i["return"]();
|
|
54
|
-
} finally{
|
|
55
|
-
if (_d) throw _e;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return _arr;
|
|
59
|
-
}
|
|
60
|
-
return function(arr, i) {
|
|
61
|
-
if (Array.isArray(arr)) {
|
|
62
|
-
return arr;
|
|
63
|
-
} else if (Symbol.iterator in Object(arr)) {
|
|
64
|
-
return sliceIterator(arr, i);
|
|
65
|
-
} else {
|
|
66
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}();
|
|
70
|
-
String.prototype.startsWith = String.prototype.startsWith || function(needle) {
|
|
71
|
-
return this.indexOf(needle) === 0;
|
|
72
|
-
};
|
|
73
|
-
String.prototype.padStart = String.prototype.padStart || function(len, pad) {
|
|
74
|
-
var str = this;
|
|
75
|
-
while(str.length < len){
|
|
76
|
-
str = pad + str;
|
|
77
|
-
}
|
|
78
|
-
return str;
|
|
79
|
-
};
|
|
80
|
-
var colorNames = {
|
|
81
|
-
cb: '0f8ff',
|
|
82
|
-
tqw: 'aebd7',
|
|
83
|
-
q: '-ffff',
|
|
84
|
-
qmrn: '7fffd4',
|
|
85
|
-
zr: '0ffff',
|
|
86
|
-
bg: '5f5dc',
|
|
87
|
-
bsq: 'e4c4',
|
|
88
|
-
bck: '---',
|
|
89
|
-
nch: 'ebcd',
|
|
90
|
-
b: '--ff',
|
|
91
|
-
bvt: '8a2be2',
|
|
92
|
-
brwn: 'a52a2a',
|
|
93
|
-
brw: 'deb887',
|
|
94
|
-
ctb: '5f9ea0',
|
|
95
|
-
hrt: '7fff-',
|
|
96
|
-
chcT: 'd2691e',
|
|
97
|
-
cr: '7f50',
|
|
98
|
-
rnw: '6495ed',
|
|
99
|
-
crns: '8dc',
|
|
100
|
-
crms: 'dc143c',
|
|
101
|
-
cn: '-ffff',
|
|
102
|
-
Db: '--8b',
|
|
103
|
-
Dcn: '-8b8b',
|
|
104
|
-
Dgnr: 'b8860b',
|
|
105
|
-
Dgr: 'a9a9a9',
|
|
106
|
-
Dgrn: '-64-',
|
|
107
|
-
Dkhk: 'bdb76b',
|
|
108
|
-
Dmgn: '8b-8b',
|
|
109
|
-
Dvgr: '556b2f',
|
|
110
|
-
Drng: '8c-',
|
|
111
|
-
Drch: '9932cc',
|
|
112
|
-
Dr: '8b--',
|
|
113
|
-
Dsmn: 'e9967a',
|
|
114
|
-
Dsgr: '8fbc8f',
|
|
115
|
-
DsTb: '483d8b',
|
|
116
|
-
DsTg: '2f4f4f',
|
|
117
|
-
Dtrq: '-ced1',
|
|
118
|
-
Dvt: '94-d3',
|
|
119
|
-
ppnk: '1493',
|
|
120
|
-
pskb: '-bfff',
|
|
121
|
-
mgr: '696969',
|
|
122
|
-
grb: '1e90ff',
|
|
123
|
-
rbrc: 'b22222',
|
|
124
|
-
rwht: 'af0',
|
|
125
|
-
stg: '228b22',
|
|
126
|
-
chs: '-ff',
|
|
127
|
-
gnsb: 'dcdcdc',
|
|
128
|
-
st: '8f8ff',
|
|
129
|
-
g: 'd7-',
|
|
130
|
-
gnr: 'daa520',
|
|
131
|
-
gr: '808080',
|
|
132
|
-
grn: '-8-0',
|
|
133
|
-
grnw: 'adff2f',
|
|
134
|
-
hnw: '0fff0',
|
|
135
|
-
htpn: '69b4',
|
|
136
|
-
nnr: 'cd5c5c',
|
|
137
|
-
ng: '4b-82',
|
|
138
|
-
vr: '0',
|
|
139
|
-
khk: '0e68c',
|
|
140
|
-
vnr: 'e6e6fa',
|
|
141
|
-
nrb: '0f5',
|
|
142
|
-
wngr: '7cfc-',
|
|
143
|
-
mnch: 'acd',
|
|
144
|
-
Lb: 'add8e6',
|
|
145
|
-
Lcr: '08080',
|
|
146
|
-
Lcn: 'e0ffff',
|
|
147
|
-
Lgnr: 'afad2',
|
|
148
|
-
Lgr: 'd3d3d3',
|
|
149
|
-
Lgrn: '90ee90',
|
|
150
|
-
Lpnk: 'b6c1',
|
|
151
|
-
Lsmn: 'a07a',
|
|
152
|
-
Lsgr: '20b2aa',
|
|
153
|
-
Lskb: '87cefa',
|
|
154
|
-
LsTg: '778899',
|
|
155
|
-
Lstb: 'b0c4de',
|
|
156
|
-
Lw: 'e0',
|
|
157
|
-
m: '-ff-',
|
|
158
|
-
mgrn: '32cd32',
|
|
159
|
-
nn: 'af0e6',
|
|
160
|
-
mgnt: '-ff',
|
|
161
|
-
mrn: '8--0',
|
|
162
|
-
mqm: '66cdaa',
|
|
163
|
-
mmb: '--cd',
|
|
164
|
-
mmrc: 'ba55d3',
|
|
165
|
-
mmpr: '9370db',
|
|
166
|
-
msg: '3cb371',
|
|
167
|
-
mmsT: '7b68ee',
|
|
168
|
-
'': '-fa9a',
|
|
169
|
-
mtr: '48d1cc',
|
|
170
|
-
mmvt: 'c71585',
|
|
171
|
-
mnLb: '191970',
|
|
172
|
-
ntc: '5fffa',
|
|
173
|
-
mstr: 'e4e1',
|
|
174
|
-
mccs: 'e4b5',
|
|
175
|
-
vjw: 'dead',
|
|
176
|
-
nv: '--80',
|
|
177
|
-
c: 'df5e6',
|
|
178
|
-
v: '808-0',
|
|
179
|
-
vrb: '6b8e23',
|
|
180
|
-
rng: 'a5-',
|
|
181
|
-
rngr: '45-',
|
|
182
|
-
rch: 'da70d6',
|
|
183
|
-
pgnr: 'eee8aa',
|
|
184
|
-
pgrn: '98fb98',
|
|
185
|
-
ptrq: 'afeeee',
|
|
186
|
-
pvtr: 'db7093',
|
|
187
|
-
ppwh: 'efd5',
|
|
188
|
-
pchp: 'dab9',
|
|
189
|
-
pr: 'cd853f',
|
|
190
|
-
pnk: 'c0cb',
|
|
191
|
-
pm: 'dda0dd',
|
|
192
|
-
pwrb: 'b0e0e6',
|
|
193
|
-
prp: '8-080',
|
|
194
|
-
cc: '663399',
|
|
195
|
-
r: '--',
|
|
196
|
-
sbr: 'bc8f8f',
|
|
197
|
-
rb: '4169e1',
|
|
198
|
-
sbrw: '8b4513',
|
|
199
|
-
smn: 'a8072',
|
|
200
|
-
nbr: '4a460',
|
|
201
|
-
sgrn: '2e8b57',
|
|
202
|
-
ssh: '5ee',
|
|
203
|
-
snn: 'a0522d',
|
|
204
|
-
svr: 'c0c0c0',
|
|
205
|
-
skb: '87ceeb',
|
|
206
|
-
sTb: '6a5acd',
|
|
207
|
-
sTgr: '708090',
|
|
208
|
-
snw: 'afa',
|
|
209
|
-
n: '-ff7f',
|
|
210
|
-
stb: '4682b4',
|
|
211
|
-
tn: 'd2b48c',
|
|
212
|
-
t: '-8080',
|
|
213
|
-
thst: 'd8bfd8',
|
|
214
|
-
tmT: '6347',
|
|
215
|
-
trqs: '40e0d0',
|
|
216
|
-
vt: 'ee82ee',
|
|
217
|
-
whT: '5deb3',
|
|
218
|
-
wht: '',
|
|
219
|
-
hts: '5f5f5',
|
|
220
|
-
w: '-',
|
|
221
|
-
wgrn: '9acd32'
|
|
222
|
-
};
|
|
223
|
-
function printNum(num) {
|
|
224
|
-
var decs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
225
|
-
var str = decs > 0 ? num.toFixed(decs).replace(/0+$/, '').replace(/\.$/, '') : num.toString();
|
|
226
|
-
return str || '0';
|
|
227
|
-
}
|
|
228
|
-
var Color = function() {
|
|
229
|
-
function Color(r, g, b, a) {
|
|
230
|
-
classCallCheck(this, Color);
|
|
231
|
-
var that = this;
|
|
232
|
-
function parseString(input) {
|
|
233
|
-
if (input.startsWith('hsl')) {
|
|
234
|
-
var _input$match$map = input.match(/([\-\d\.e]+)/g).map(Number), _input$match$map2 = slicedToArray(_input$match$map, 4), h = _input$match$map2[0], s = _input$match$map2[1], l = _input$match$map2[2], _a = _input$match$map2[3];
|
|
235
|
-
if (_a === undefined) {
|
|
236
|
-
_a = 1;
|
|
237
|
-
}
|
|
238
|
-
h /= 360;
|
|
239
|
-
s /= 100;
|
|
240
|
-
l /= 100;
|
|
241
|
-
that.hsla = [
|
|
242
|
-
h,
|
|
243
|
-
s,
|
|
244
|
-
l,
|
|
245
|
-
_a
|
|
246
|
-
];
|
|
247
|
-
} else if (input.startsWith('rgb')) {
|
|
248
|
-
var _input$match$map3 = input.match(/([\-\d\.e]+)/g).map(Number), _input$match$map4 = slicedToArray(_input$match$map3, 4), _r = _input$match$map4[0], _g = _input$match$map4[1], _b = _input$match$map4[2], _a2 = _input$match$map4[3];
|
|
249
|
-
if (_a2 === undefined) {
|
|
250
|
-
_a2 = 1;
|
|
251
|
-
}
|
|
252
|
-
that.rgba = [
|
|
253
|
-
_r,
|
|
254
|
-
_g,
|
|
255
|
-
_b,
|
|
256
|
-
_a2
|
|
257
|
-
];
|
|
258
|
-
} else {
|
|
259
|
-
if (input.startsWith('#')) {
|
|
260
|
-
that.rgba = Color.hexToRgb(input);
|
|
261
|
-
} else {
|
|
262
|
-
that.rgba = Color.nameToRgb(input) || Color.hexToRgb(input);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
if (r === undefined) ;
|
|
267
|
-
else if (Array.isArray(r)) {
|
|
268
|
-
this.rgba = r;
|
|
269
|
-
} else if (b === undefined) {
|
|
270
|
-
var color = r && '' + r;
|
|
271
|
-
if (color) {
|
|
272
|
-
parseString(color.toLowerCase());
|
|
273
|
-
}
|
|
274
|
-
} else {
|
|
275
|
-
this.rgba = [
|
|
276
|
-
r,
|
|
277
|
-
g,
|
|
278
|
-
b,
|
|
279
|
-
a === undefined ? 1 : a
|
|
280
|
-
];
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
createClass(Color, [
|
|
284
|
-
{
|
|
285
|
-
key: 'printRGB',
|
|
286
|
-
value: function printRGB(alpha) {
|
|
287
|
-
var rgb = alpha ? this.rgba : this.rgba.slice(0, 3), vals = rgb.map(function(x, i) {
|
|
288
|
-
return printNum(x, i === 3 ? 3 : 0);
|
|
289
|
-
});
|
|
290
|
-
return alpha ? 'rgba(' + vals + ')' : 'rgb(' + vals + ')';
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
key: 'printHSL',
|
|
295
|
-
value: function printHSL(alpha) {
|
|
296
|
-
var mults = [
|
|
297
|
-
360,
|
|
298
|
-
100,
|
|
299
|
-
100,
|
|
300
|
-
1
|
|
301
|
-
], suff = [
|
|
302
|
-
'',
|
|
303
|
-
'%',
|
|
304
|
-
'%',
|
|
305
|
-
''
|
|
306
|
-
];
|
|
307
|
-
var hsl = alpha ? this.hsla : this.hsla.slice(0, 3), vals = hsl.map(function(x, i) {
|
|
308
|
-
return printNum(x * mults[i], i === 3 ? 3 : 1) + suff[i];
|
|
309
|
-
});
|
|
310
|
-
return alpha ? 'hsla(' + vals + ')' : 'hsl(' + vals + ')';
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
key: 'printHex',
|
|
315
|
-
value: function printHex(alpha) {
|
|
316
|
-
var hex = this.hex;
|
|
317
|
-
return alpha ? hex : hex.substring(0, 7);
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
key: 'rgba',
|
|
322
|
-
get: function get() {
|
|
323
|
-
if (this._rgba) {
|
|
324
|
-
return this._rgba;
|
|
325
|
-
}
|
|
326
|
-
if (!this._hsla) {
|
|
327
|
-
throw new Error('No color is set');
|
|
328
|
-
}
|
|
329
|
-
return this._rgba = Color.hslToRgb(this._hsla);
|
|
330
|
-
},
|
|
331
|
-
set: function set(rgb) {
|
|
332
|
-
if (rgb.length === 3) {
|
|
333
|
-
rgb[3] = 1;
|
|
334
|
-
}
|
|
335
|
-
this._rgba = rgb;
|
|
336
|
-
this._hsla = null;
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
key: 'rgbString',
|
|
341
|
-
get: function get() {
|
|
342
|
-
return this.printRGB();
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
key: 'rgbaString',
|
|
347
|
-
get: function get() {
|
|
348
|
-
return this.printRGB(true);
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
key: 'hsla',
|
|
353
|
-
get: function get() {
|
|
354
|
-
if (this._hsla) {
|
|
355
|
-
return this._hsla;
|
|
356
|
-
}
|
|
357
|
-
if (!this._rgba) {
|
|
358
|
-
throw new Error('No color is set');
|
|
359
|
-
}
|
|
360
|
-
return this._hsla = Color.rgbToHsl(this._rgba);
|
|
361
|
-
},
|
|
362
|
-
set: function set(hsl) {
|
|
363
|
-
if (hsl.length === 3) {
|
|
364
|
-
hsl[3] = 1;
|
|
365
|
-
}
|
|
366
|
-
this._hsla = hsl;
|
|
367
|
-
this._rgba = null;
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
key: 'hslString',
|
|
372
|
-
get: function get() {
|
|
373
|
-
return this.printHSL();
|
|
374
|
-
}
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
key: 'hslaString',
|
|
378
|
-
get: function get() {
|
|
379
|
-
return this.printHSL(true);
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
key: 'hex',
|
|
384
|
-
get: function get() {
|
|
385
|
-
var rgb = this.rgba, hex = rgb.map(function(x, i) {
|
|
386
|
-
return i < 3 ? x.toString(16) : Math.round(x * 255).toString(16);
|
|
387
|
-
});
|
|
388
|
-
return '#' + hex.map(function(x) {
|
|
389
|
-
return x.padStart(2, '0');
|
|
390
|
-
}).join('');
|
|
391
|
-
},
|
|
392
|
-
set: function set(hex) {
|
|
393
|
-
this.rgba = Color.hexToRgb(hex);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
], [
|
|
397
|
-
{
|
|
398
|
-
key: 'hexToRgb',
|
|
399
|
-
value: function hexToRgb(input) {
|
|
400
|
-
var hex = (input.startsWith('#') ? input.slice(1) : input).replace(/^(\w{3})$/, '$1F').replace(/^(\w)(\w)(\w)(\w)$/, '$1$1$2$2$3$3$4$4').replace(/^(\w{6})$/, '$1FF');
|
|
401
|
-
if (!hex.match(/^([0-9a-fA-F]{8})$/)) {
|
|
402
|
-
throw new Error('Unknown hex color; ' + input);
|
|
403
|
-
}
|
|
404
|
-
var rgba = hex.match(/^(\w\w)(\w\w)(\w\w)(\w\w)$/).slice(1).map(function(x) {
|
|
405
|
-
return parseInt(x, 16);
|
|
406
|
-
});
|
|
407
|
-
rgba[3] = rgba[3] / 255;
|
|
408
|
-
return rgba;
|
|
409
|
-
}
|
|
410
|
-
},
|
|
411
|
-
{
|
|
412
|
-
key: 'nameToRgb',
|
|
413
|
-
value: function nameToRgb(input) {
|
|
414
|
-
var hash = input.toLowerCase().replace('at', 'T').replace(/[aeiouyldf]/g, '').replace('ght', 'L').replace('rk', 'D').slice(-5, 4), hex = colorNames[hash];
|
|
415
|
-
return hex === undefined ? hex : Color.hexToRgb(hex.replace(/\-/g, '00').padStart(6, 'f'));
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
key: 'rgbToHsl',
|
|
420
|
-
value: function rgbToHsl(_ref) {
|
|
421
|
-
var _ref2 = slicedToArray(_ref, 4), r = _ref2[0], g = _ref2[1], b = _ref2[2], a = _ref2[3];
|
|
422
|
-
r /= 255;
|
|
423
|
-
g /= 255;
|
|
424
|
-
b /= 255;
|
|
425
|
-
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
426
|
-
var h = void 0, s = void 0, l = (max + min) / 2;
|
|
427
|
-
if (max === min) {
|
|
428
|
-
h = s = 0;
|
|
429
|
-
} else {
|
|
430
|
-
var d = max - min;
|
|
431
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
432
|
-
switch(max){
|
|
433
|
-
case r:
|
|
434
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
435
|
-
break;
|
|
436
|
-
case g:
|
|
437
|
-
h = (b - r) / d + 2;
|
|
438
|
-
break;
|
|
439
|
-
case b:
|
|
440
|
-
h = (r - g) / d + 4;
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
h /= 6;
|
|
444
|
-
}
|
|
445
|
-
return [
|
|
446
|
-
h,
|
|
447
|
-
s,
|
|
448
|
-
l,
|
|
449
|
-
a
|
|
450
|
-
];
|
|
451
|
-
}
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
key: 'hslToRgb',
|
|
455
|
-
value: function hslToRgb(_ref3) {
|
|
456
|
-
var _ref4 = slicedToArray(_ref3, 4), h = _ref4[0], s = _ref4[1], l = _ref4[2], a = _ref4[3];
|
|
457
|
-
var r = void 0, g = void 0, b = void 0;
|
|
458
|
-
if (s === 0) {
|
|
459
|
-
r = g = b = l;
|
|
460
|
-
} else {
|
|
461
|
-
var hue2rgb = function hue2rgb(p, q, t) {
|
|
462
|
-
if (t < 0) t += 1;
|
|
463
|
-
if (t > 1) t -= 1;
|
|
464
|
-
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
465
|
-
if (t < 1 / 2) return q;
|
|
466
|
-
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
467
|
-
return p;
|
|
468
|
-
};
|
|
469
|
-
var q = l < 0.5 ? l * (1 + s) : l + s - l * s, p = 2 * l - q;
|
|
470
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
471
|
-
g = hue2rgb(p, q, h);
|
|
472
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
473
|
-
}
|
|
474
|
-
var rgba = [
|
|
475
|
-
r * 255,
|
|
476
|
-
g * 255,
|
|
477
|
-
b * 255
|
|
478
|
-
].map(Math.round);
|
|
479
|
-
rgba[3] = a;
|
|
480
|
-
return rgba;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
]);
|
|
484
|
-
return Color;
|
|
485
|
-
}();
|
|
486
|
-
var EventBucket = function() {
|
|
487
|
-
function EventBucket() {
|
|
488
|
-
classCallCheck(this, EventBucket);
|
|
489
|
-
this._events = [];
|
|
490
|
-
}
|
|
491
|
-
createClass(EventBucket, [
|
|
492
|
-
{
|
|
493
|
-
key: 'add',
|
|
494
|
-
value: function add(target, type, handler) {
|
|
495
|
-
target.addEventListener(type, handler, false);
|
|
496
|
-
this._events.push({
|
|
497
|
-
target: target,
|
|
498
|
-
type: type,
|
|
499
|
-
handler: handler
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
},
|
|
503
|
-
{
|
|
504
|
-
key: 'remove',
|
|
505
|
-
value: function remove(target, type, handler) {
|
|
506
|
-
this._events = this._events.filter(function(e) {
|
|
507
|
-
var isMatch = true;
|
|
508
|
-
if (target && target !== e.target) {
|
|
509
|
-
isMatch = false;
|
|
510
|
-
}
|
|
511
|
-
if (type && type !== e.type) {
|
|
512
|
-
isMatch = false;
|
|
513
|
-
}
|
|
514
|
-
if (handler && handler !== e.handler) {
|
|
515
|
-
isMatch = false;
|
|
516
|
-
}
|
|
517
|
-
if (isMatch) {
|
|
518
|
-
EventBucket._doRemove(e.target, e.type, e.handler);
|
|
519
|
-
}
|
|
520
|
-
return !isMatch;
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
},
|
|
524
|
-
{
|
|
525
|
-
key: 'destroy',
|
|
526
|
-
value: function destroy() {
|
|
527
|
-
this._events.forEach(function(e) {
|
|
528
|
-
return EventBucket._doRemove(e.target, e.type, e.handler);
|
|
529
|
-
});
|
|
530
|
-
this._events = [];
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
], [
|
|
534
|
-
{
|
|
535
|
-
key: '_doRemove',
|
|
536
|
-
value: function _doRemove(target, type, handler) {
|
|
537
|
-
target.removeEventListener(type, handler, false);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
]);
|
|
541
|
-
return EventBucket;
|
|
542
|
-
}();
|
|
543
|
-
function parseHTML(htmlString) {
|
|
544
|
-
var div = document.createElement('div');
|
|
545
|
-
div.innerHTML = htmlString;
|
|
546
|
-
return div.firstElementChild;
|
|
547
|
-
}
|
|
548
|
-
function dragTrack(eventBucket, area, callback) {
|
|
549
|
-
var dragging = false;
|
|
550
|
-
function clamp(val, min, max) {
|
|
551
|
-
return Math.max(min, Math.min(val, max));
|
|
552
|
-
}
|
|
553
|
-
function onMove(e, info, starting) {
|
|
554
|
-
if (starting) {
|
|
555
|
-
dragging = true;
|
|
556
|
-
}
|
|
557
|
-
if (!dragging) {
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
e.preventDefault();
|
|
561
|
-
var bounds = area.getBoundingClientRect(), w = bounds.width, h = bounds.height, x = info.clientX, y = info.clientY;
|
|
562
|
-
var relX = clamp(x - bounds.left, 0, w), relY = clamp(y - bounds.top, 0, h);
|
|
563
|
-
callback(relX / w, relY / h);
|
|
564
|
-
}
|
|
565
|
-
function onMouse(e, starting) {
|
|
566
|
-
var button = e.buttons === undefined ? e.which : e.buttons;
|
|
567
|
-
if (button === 1) {
|
|
568
|
-
onMove(e, e, starting);
|
|
569
|
-
} else {
|
|
570
|
-
dragging = false;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
function onTouch(e, starting) {
|
|
574
|
-
if (e.touches.length === 1) {
|
|
575
|
-
onMove(e, e.touches[0], starting);
|
|
576
|
-
} else {
|
|
577
|
-
dragging = false;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
eventBucket.add(area, 'mousedown', function(e) {
|
|
581
|
-
onMouse(e, true);
|
|
582
|
-
});
|
|
583
|
-
eventBucket.add(area, 'touchstart', function(e) {
|
|
584
|
-
onTouch(e, true);
|
|
585
|
-
});
|
|
586
|
-
eventBucket.add(window, 'mousemove', onMouse);
|
|
587
|
-
eventBucket.add(area, 'touchmove', onTouch);
|
|
588
|
-
eventBucket.add(window, 'mouseup', function(e) {
|
|
589
|
-
dragging = false;
|
|
590
|
-
});
|
|
591
|
-
eventBucket.add(area, 'touchend', function(e) {
|
|
592
|
-
dragging = false;
|
|
593
|
-
});
|
|
594
|
-
eventBucket.add(area, 'touchcancel', function(e) {
|
|
595
|
-
dragging = false;
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
var BG_TRANSP = 'linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%) 0 0 / 2em 2em,\n linear-gradient(45deg, lightgrey 25%, white 25%, white 75%, lightgrey 75%) 1em 1em / 2em 2em';
|
|
599
|
-
var HUES = 360;
|
|
600
|
-
var EVENT_KEY = 'keydown', EVENT_CLICK_OUTSIDE = 'mousedown', EVENT_TAB_MOVE = 'focusin';
|
|
601
|
-
function $(selector, context) {
|
|
602
|
-
return (context || document).querySelector(selector);
|
|
603
|
-
}
|
|
604
|
-
function stopEvent(e) {
|
|
605
|
-
e.preventDefault();
|
|
606
|
-
e.stopPropagation();
|
|
607
|
-
}
|
|
608
|
-
function onKey(bucket, target, keys, handler, stop) {
|
|
609
|
-
bucket.add(target, EVENT_KEY, function(e) {
|
|
610
|
-
if (keys.indexOf(e.key) >= 0) {
|
|
611
|
-
handler(e);
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
var Picker = function() {
|
|
616
|
-
function Picker(options) {
|
|
617
|
-
classCallCheck(this, Picker);
|
|
618
|
-
this.settings = {
|
|
619
|
-
popup: 'right',
|
|
620
|
-
layout: 'default',
|
|
621
|
-
alpha: true,
|
|
622
|
-
editor: true,
|
|
623
|
-
editorFormat: 'hex',
|
|
624
|
-
cancelButton: false,
|
|
625
|
-
defaultColor: '#0cf'
|
|
626
|
-
};
|
|
627
|
-
this._events = new EventBucket();
|
|
628
|
-
this.onChange = null;
|
|
629
|
-
this.onDone = null;
|
|
630
|
-
this.onOpen = null;
|
|
631
|
-
this.onClose = null;
|
|
632
|
-
this.setOptions(options);
|
|
633
|
-
}
|
|
634
|
-
createClass(Picker, [
|
|
635
|
-
{
|
|
636
|
-
key: 'setOptions',
|
|
637
|
-
value: function setOptions(options) {
|
|
638
|
-
var _this = this;
|
|
639
|
-
if (!options) {
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
var settings = this.settings;
|
|
643
|
-
function transfer(source, target, skipKeys) {
|
|
644
|
-
for(var key in source){
|
|
645
|
-
target[key] = source[key];
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
if (_instanceof(options, HTMLElement)) {
|
|
649
|
-
settings.parent = options;
|
|
650
|
-
} else {
|
|
651
|
-
if (settings.parent && options.parent && settings.parent !== options.parent) {
|
|
652
|
-
this._events.remove(settings.parent);
|
|
653
|
-
this._popupInited = false;
|
|
654
|
-
}
|
|
655
|
-
transfer(options, settings);
|
|
656
|
-
if (options.onChange) {
|
|
657
|
-
this.onChange = options.onChange;
|
|
658
|
-
}
|
|
659
|
-
if (options.onDone) {
|
|
660
|
-
this.onDone = options.onDone;
|
|
661
|
-
}
|
|
662
|
-
if (options.onOpen) {
|
|
663
|
-
this.onOpen = options.onOpen;
|
|
664
|
-
}
|
|
665
|
-
if (options.onClose) {
|
|
666
|
-
this.onClose = options.onClose;
|
|
667
|
-
}
|
|
668
|
-
var col = options.color || options.colour;
|
|
669
|
-
if (col) {
|
|
670
|
-
this._setColor(col);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
var parent = settings.parent;
|
|
674
|
-
if (parent && settings.popup && !this._popupInited) {
|
|
675
|
-
var openProxy = function openProxy(e) {
|
|
676
|
-
return _this.openHandler(e);
|
|
677
|
-
};
|
|
678
|
-
this._events.add(parent, 'click', openProxy);
|
|
679
|
-
onKey(this._events, parent, [
|
|
680
|
-
' ',
|
|
681
|
-
'Spacebar',
|
|
682
|
-
'Enter'
|
|
683
|
-
], openProxy);
|
|
684
|
-
this._popupInited = true;
|
|
685
|
-
} else if (options.parent && !settings.popup) {
|
|
686
|
-
this.show();
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
},
|
|
690
|
-
{
|
|
691
|
-
key: 'openHandler',
|
|
692
|
-
value: function openHandler(e) {
|
|
693
|
-
if (this.show()) {
|
|
694
|
-
e && e.preventDefault();
|
|
695
|
-
this.settings.parent.style.pointerEvents = 'none';
|
|
696
|
-
var toFocus = e && e.type === EVENT_KEY ? this._domEdit : this.domElement;
|
|
697
|
-
setTimeout(function() {
|
|
698
|
-
return toFocus.focus();
|
|
699
|
-
}, 100);
|
|
700
|
-
if (this.onOpen) {
|
|
701
|
-
this.onOpen(this.colour);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
},
|
|
706
|
-
{
|
|
707
|
-
key: 'closeHandler',
|
|
708
|
-
value: function closeHandler(e) {
|
|
709
|
-
var event = e && e.type;
|
|
710
|
-
var doHide = false;
|
|
711
|
-
if (!e) {
|
|
712
|
-
doHide = true;
|
|
713
|
-
} else if (event === EVENT_CLICK_OUTSIDE || event === EVENT_TAB_MOVE) {
|
|
714
|
-
var knownTime = (this.__containedEvent || 0) + 100;
|
|
715
|
-
if (e.timeStamp > knownTime) {
|
|
716
|
-
doHide = true;
|
|
717
|
-
}
|
|
718
|
-
} else {
|
|
719
|
-
stopEvent(e);
|
|
720
|
-
doHide = true;
|
|
721
|
-
}
|
|
722
|
-
if (doHide && this.hide()) {
|
|
723
|
-
this.settings.parent.style.pointerEvents = '';
|
|
724
|
-
if (event !== EVENT_CLICK_OUTSIDE) {
|
|
725
|
-
this.settings.parent.focus();
|
|
726
|
-
}
|
|
727
|
-
if (this.onClose) {
|
|
728
|
-
this.onClose(this.colour);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
},
|
|
733
|
-
{
|
|
734
|
-
key: 'movePopup',
|
|
735
|
-
value: function movePopup(options, open) {
|
|
736
|
-
this.closeHandler();
|
|
737
|
-
this.setOptions(options);
|
|
738
|
-
if (open) {
|
|
739
|
-
this.openHandler();
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
},
|
|
743
|
-
{
|
|
744
|
-
key: 'setColor',
|
|
745
|
-
value: function setColor(color, silent) {
|
|
746
|
-
this._setColor(color, {
|
|
747
|
-
silent: silent
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
},
|
|
751
|
-
{
|
|
752
|
-
key: '_setColor',
|
|
753
|
-
value: function _setColor(color, flags) {
|
|
754
|
-
if (typeof color === 'string') {
|
|
755
|
-
color = color.trim();
|
|
756
|
-
}
|
|
757
|
-
if (!color) {
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
flags = flags || {};
|
|
761
|
-
var c = void 0;
|
|
762
|
-
try {
|
|
763
|
-
c = new Color(color);
|
|
764
|
-
} catch (ex) {
|
|
765
|
-
if (flags.failSilently) {
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
throw ex;
|
|
769
|
-
}
|
|
770
|
-
if (!this.settings.alpha) {
|
|
771
|
-
var hsla = c.hsla;
|
|
772
|
-
hsla[3] = 1;
|
|
773
|
-
c.hsla = hsla;
|
|
774
|
-
}
|
|
775
|
-
this.colour = this.color = c;
|
|
776
|
-
this._setHSLA(null, null, null, null, flags);
|
|
777
|
-
}
|
|
778
|
-
},
|
|
779
|
-
{
|
|
780
|
-
key: 'setColour',
|
|
781
|
-
value: function setColour(colour, silent) {
|
|
782
|
-
this.setColor(colour, silent);
|
|
783
|
-
}
|
|
784
|
-
},
|
|
785
|
-
{
|
|
786
|
-
key: 'show',
|
|
787
|
-
value: function show() {
|
|
788
|
-
var parent = this.settings.parent;
|
|
789
|
-
if (!parent) {
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
if (this.domElement) {
|
|
793
|
-
var toggled = this._toggleDOM(true);
|
|
794
|
-
this._setPosition();
|
|
795
|
-
return toggled;
|
|
796
|
-
}
|
|
797
|
-
var html = this.settings.template || '<div class="picker_wrapper" tabindex="-1"><div class="picker_arrow"></div><div class="picker_hue picker_slider"><div class="picker_selector"></div></div><div class="picker_sl"><div class="picker_selector"></div></div><div class="picker_alpha picker_slider"><div class="picker_selector"></div></div><div class="picker_editor"><input aria-label="Type a color name or hex value"/></div><div class="picker_sample"></div><div class="picker_done"><button>Ok</button></div><div class="picker_cancel"><button>Cancel</button></div></div>';
|
|
798
|
-
var wrapper = parseHTML(html);
|
|
799
|
-
this.domElement = wrapper;
|
|
800
|
-
this._domH = $('.picker_hue', wrapper);
|
|
801
|
-
this._domSL = $('.picker_sl', wrapper);
|
|
802
|
-
this._domA = $('.picker_alpha', wrapper);
|
|
803
|
-
this._domEdit = $('.picker_editor input', wrapper);
|
|
804
|
-
this._domSample = $('.picker_sample', wrapper);
|
|
805
|
-
this._domOkay = $('.picker_done button', wrapper);
|
|
806
|
-
this._domCancel = $('.picker_cancel button', wrapper);
|
|
807
|
-
wrapper.classList.add('layout_' + this.settings.layout);
|
|
808
|
-
if (!this.settings.alpha) {
|
|
809
|
-
wrapper.classList.add('no_alpha');
|
|
810
|
-
}
|
|
811
|
-
if (!this.settings.editor) {
|
|
812
|
-
wrapper.classList.add('no_editor');
|
|
813
|
-
}
|
|
814
|
-
if (!this.settings.cancelButton) {
|
|
815
|
-
wrapper.classList.add('no_cancel');
|
|
816
|
-
}
|
|
817
|
-
this._ifPopup(function() {
|
|
818
|
-
return wrapper.classList.add('popup');
|
|
819
|
-
});
|
|
820
|
-
this._setPosition();
|
|
821
|
-
if (this.colour) {
|
|
822
|
-
this._updateUI();
|
|
823
|
-
} else {
|
|
824
|
-
this._setColor(this.settings.defaultColor);
|
|
825
|
-
}
|
|
826
|
-
this._bindEvents();
|
|
827
|
-
return true;
|
|
828
|
-
}
|
|
829
|
-
},
|
|
830
|
-
{
|
|
831
|
-
key: 'hide',
|
|
832
|
-
value: function hide() {
|
|
833
|
-
return this._toggleDOM(false);
|
|
834
|
-
}
|
|
835
|
-
},
|
|
836
|
-
{
|
|
837
|
-
key: 'destroy',
|
|
838
|
-
value: function destroy() {
|
|
839
|
-
this._events.destroy();
|
|
840
|
-
if (this.domElement) {
|
|
841
|
-
this.settings.parent.removeChild(this.domElement);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
},
|
|
845
|
-
{
|
|
846
|
-
key: '_bindEvents',
|
|
847
|
-
value: function _bindEvents() {
|
|
848
|
-
var _this2 = this;
|
|
849
|
-
var that = this, dom = this.domElement, events = this._events;
|
|
850
|
-
function addEvent(target, type, handler) {
|
|
851
|
-
events.add(target, type, handler);
|
|
852
|
-
}
|
|
853
|
-
addEvent(dom, 'click', function(e) {
|
|
854
|
-
return e.preventDefault();
|
|
855
|
-
});
|
|
856
|
-
dragTrack(events, this._domH, function(x, y) {
|
|
857
|
-
return that._setHSLA(x);
|
|
858
|
-
});
|
|
859
|
-
dragTrack(events, this._domSL, function(x, y) {
|
|
860
|
-
return that._setHSLA(null, x, 1 - y);
|
|
861
|
-
});
|
|
862
|
-
if (this.settings.alpha) {
|
|
863
|
-
dragTrack(events, this._domA, function(x, y) {
|
|
864
|
-
return that._setHSLA(null, null, null, 1 - y);
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
var editInput = this._domEdit;
|
|
868
|
-
{
|
|
869
|
-
addEvent(editInput, 'input', function(e) {
|
|
870
|
-
that._setColor(this.value, {
|
|
871
|
-
fromEditor: true,
|
|
872
|
-
failSilently: true
|
|
873
|
-
});
|
|
874
|
-
});
|
|
875
|
-
addEvent(editInput, 'focus', function(e) {
|
|
876
|
-
var input = this;
|
|
877
|
-
if (input.selectionStart === input.selectionEnd) {
|
|
878
|
-
input.select();
|
|
879
|
-
}
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
this._ifPopup(function() {
|
|
883
|
-
var popupCloseProxy = function popupCloseProxy(e) {
|
|
884
|
-
return _this2.closeHandler(e);
|
|
885
|
-
};
|
|
886
|
-
addEvent(window, EVENT_CLICK_OUTSIDE, popupCloseProxy);
|
|
887
|
-
addEvent(window, EVENT_TAB_MOVE, popupCloseProxy);
|
|
888
|
-
onKey(events, dom, [
|
|
889
|
-
'Esc',
|
|
890
|
-
'Escape'
|
|
891
|
-
], popupCloseProxy);
|
|
892
|
-
var timeKeeper = function timeKeeper(e) {
|
|
893
|
-
_this2.__containedEvent = e.timeStamp;
|
|
894
|
-
};
|
|
895
|
-
addEvent(dom, EVENT_CLICK_OUTSIDE, timeKeeper);
|
|
896
|
-
addEvent(dom, EVENT_TAB_MOVE, timeKeeper);
|
|
897
|
-
addEvent(_this2._domCancel, 'click', popupCloseProxy);
|
|
898
|
-
});
|
|
899
|
-
var onDoneProxy = function onDoneProxy(e) {
|
|
900
|
-
_this2._ifPopup(function() {
|
|
901
|
-
return _this2.closeHandler(e);
|
|
902
|
-
});
|
|
903
|
-
if (_this2.onDone) {
|
|
904
|
-
_this2.onDone(_this2.colour);
|
|
905
|
-
}
|
|
906
|
-
};
|
|
907
|
-
addEvent(this._domOkay, 'click', onDoneProxy);
|
|
908
|
-
onKey(events, dom, [
|
|
909
|
-
'Enter'
|
|
910
|
-
], onDoneProxy);
|
|
911
|
-
}
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
key: '_setPosition',
|
|
915
|
-
value: function _setPosition() {
|
|
916
|
-
var parent = this.settings.parent, elm = this.domElement;
|
|
917
|
-
if (parent !== elm.parentNode) {
|
|
918
|
-
parent.appendChild(elm);
|
|
919
|
-
}
|
|
920
|
-
this._ifPopup(function(popup) {
|
|
921
|
-
if (getComputedStyle(parent).position === 'static') {
|
|
922
|
-
parent.style.position = 'relative';
|
|
923
|
-
}
|
|
924
|
-
var cssClass = popup === true ? 'popup_right' : 'popup_' + popup;
|
|
925
|
-
[
|
|
926
|
-
'popup_top',
|
|
927
|
-
'popup_bottom',
|
|
928
|
-
'popup_left',
|
|
929
|
-
'popup_right'
|
|
930
|
-
].forEach(function(c) {
|
|
931
|
-
if (c === cssClass) {
|
|
932
|
-
elm.classList.add(c);
|
|
933
|
-
} else {
|
|
934
|
-
elm.classList.remove(c);
|
|
935
|
-
}
|
|
936
|
-
});
|
|
937
|
-
elm.classList.add(cssClass);
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
},
|
|
941
|
-
{
|
|
942
|
-
key: '_setHSLA',
|
|
943
|
-
value: function _setHSLA(h, s, l, a, flags) {
|
|
944
|
-
flags = flags || {};
|
|
945
|
-
var col = this.colour, hsla = col.hsla;
|
|
946
|
-
[
|
|
947
|
-
h,
|
|
948
|
-
s,
|
|
949
|
-
l,
|
|
950
|
-
a
|
|
951
|
-
].forEach(function(x, i) {
|
|
952
|
-
if (x || x === 0) {
|
|
953
|
-
hsla[i] = x;
|
|
954
|
-
}
|
|
955
|
-
});
|
|
956
|
-
col.hsla = hsla;
|
|
957
|
-
this._updateUI(flags);
|
|
958
|
-
if (this.onChange && !flags.silent) {
|
|
959
|
-
this.onChange(col);
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
},
|
|
963
|
-
{
|
|
964
|
-
key: '_updateUI',
|
|
965
|
-
value: function _updateUI(flags) {
|
|
966
|
-
if (!this.domElement) {
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
flags = flags || {};
|
|
970
|
-
var col = this.colour, hsl = col.hsla, cssHue = 'hsl(' + hsl[0] * HUES + ', 100%, 50%)', cssHSL = col.hslString, cssHSLA = col.hslaString;
|
|
971
|
-
var uiH = this._domH, uiSL = this._domSL, uiA = this._domA, thumbH = $('.picker_selector', uiH), thumbSL = $('.picker_selector', uiSL), thumbA = $('.picker_selector', uiA);
|
|
972
|
-
function posX(parent, child, relX) {
|
|
973
|
-
child.style.left = relX * 100 + '%';
|
|
974
|
-
}
|
|
975
|
-
function posY(parent, child, relY) {
|
|
976
|
-
child.style.top = relY * 100 + '%';
|
|
977
|
-
}
|
|
978
|
-
posX(uiH, thumbH, hsl[0]);
|
|
979
|
-
this._domSL.style.backgroundColor = this._domH.style.color = cssHue;
|
|
980
|
-
posX(uiSL, thumbSL, hsl[1]);
|
|
981
|
-
posY(uiSL, thumbSL, 1 - hsl[2]);
|
|
982
|
-
uiSL.style.color = cssHSL;
|
|
983
|
-
posY(uiA, thumbA, 1 - hsl[3]);
|
|
984
|
-
var opaque = cssHSL, transp = opaque.replace('hsl', 'hsla').replace(')', ', 0)'), bg = 'linear-gradient(' + [
|
|
985
|
-
opaque,
|
|
986
|
-
transp
|
|
987
|
-
] + ')';
|
|
988
|
-
this._domA.style.background = bg + ', ' + BG_TRANSP;
|
|
989
|
-
if (!flags.fromEditor) {
|
|
990
|
-
var format = this.settings.editorFormat, alpha = this.settings.alpha;
|
|
991
|
-
var value = void 0;
|
|
992
|
-
switch(format){
|
|
993
|
-
case 'rgb':
|
|
994
|
-
value = col.printRGB(alpha);
|
|
995
|
-
break;
|
|
996
|
-
case 'hsl':
|
|
997
|
-
value = col.printHSL(alpha);
|
|
998
|
-
break;
|
|
999
|
-
default:
|
|
1000
|
-
value = col.printHex(alpha);
|
|
1001
|
-
}
|
|
1002
|
-
this._domEdit.value = value;
|
|
1003
|
-
}
|
|
1004
|
-
this._domSample.style.color = cssHSLA;
|
|
1005
|
-
}
|
|
1006
|
-
},
|
|
1007
|
-
{
|
|
1008
|
-
key: '_ifPopup',
|
|
1009
|
-
value: function _ifPopup(actionIf, actionElse) {
|
|
1010
|
-
if (this.settings.parent && this.settings.popup) {
|
|
1011
|
-
actionIf && actionIf(this.settings.popup);
|
|
1012
|
-
} else {
|
|
1013
|
-
actionElse && actionElse();
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
},
|
|
1017
|
-
{
|
|
1018
|
-
key: '_toggleDOM',
|
|
1019
|
-
value: function _toggleDOM(toVisible) {
|
|
1020
|
-
var dom = this.domElement;
|
|
1021
|
-
if (!dom) {
|
|
1022
|
-
return false;
|
|
1023
|
-
}
|
|
1024
|
-
var displayStyle = toVisible ? '' : 'none', toggle = dom.style.display !== displayStyle;
|
|
1025
|
-
if (toggle) {
|
|
1026
|
-
dom.style.display = displayStyle;
|
|
1027
|
-
}
|
|
1028
|
-
return toggle;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
]);
|
|
1032
|
-
return Picker;
|
|
1033
|
-
}();
|
|
1034
|
-
{
|
|
1035
|
-
var style = document.createElement('style');
|
|
1036
|
-
style.textContent = '.picker_wrapper.no_alpha .picker_alpha{display:none}.picker_wrapper.no_editor .picker_editor{position:absolute;z-index:-1;opacity:0}.picker_wrapper.no_cancel .picker_cancel{display:none}.layout_default.picker_wrapper{display:flex;flex-flow:row wrap;justify-content:space-between;align-items:stretch;font-size:10px;width:25em;padding:.5em}.layout_default.picker_wrapper input,.layout_default.picker_wrapper button{font-size:1rem}.layout_default.picker_wrapper>*{margin:.5em}.layout_default.picker_wrapper::before{content:"";display:block;width:100%;height:0;order:1}.layout_default .picker_slider,.layout_default .picker_selector{padding:1em}.layout_default .picker_hue{width:100%}.layout_default .picker_sl{flex:1 1 auto}.layout_default .picker_sl::before{content:"";display:block;padding-bottom:100%}.layout_default .picker_editor{order:1;width:6.5rem}.layout_default .picker_editor input{width:100%;height:100%}.layout_default .picker_sample{order:1;flex:1 1 auto}.layout_default .picker_done,.layout_default .picker_cancel{order:1}.picker_wrapper{box-sizing:border-box;background:#f2f2f2;box-shadow:0 0 0 1px silver;cursor:default;font-family:sans-serif;color:#444;pointer-events:auto}.picker_wrapper:focus{outline:none}.picker_wrapper button,.picker_wrapper input{box-sizing:border-box;border:none;box-shadow:0 0 0 1px silver;outline:none}.picker_wrapper button:focus,.picker_wrapper button:active,.picker_wrapper input:focus,.picker_wrapper input:active{box-shadow:0 0 2px 1px #1e90ff}.picker_wrapper button{padding:.4em .6em;cursor:pointer;background-color:#f5f5f5;background-image:linear-gradient(0deg, gainsboro, transparent)}.picker_wrapper button:active{background-image:linear-gradient(0deg, transparent, gainsboro)}.picker_wrapper button:hover{background-color:#fff}.picker_selector{position:absolute;z-index:1;display:block;-webkit-transform:translate(-50%, -50%);transform:translate(-50%, -50%);border:2px solid #fff;border-radius:100%;box-shadow:0 0 3px 1px #67b9ff;background:currentColor;cursor:pointer}.picker_slider .picker_selector{border-radius:2px}.picker_hue{position:relative;background-image:linear-gradient(90deg, red, yellow, lime, cyan, blue, magenta, red);box-shadow:0 0 0 1px silver}.picker_sl{position:relative;box-shadow:0 0 0 1px silver;background-image:linear-gradient(180deg, white, rgba(255, 255, 255, 0) 50%),linear-gradient(0deg, black, rgba(0, 0, 0, 0) 50%),linear-gradient(90deg, #808080, rgba(128, 128, 128, 0))}.picker_alpha,.picker_sample{position:relative;background:linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%) 0 0/2em 2em,linear-gradient(45deg, lightgrey 25%, white 25%, white 75%, lightgrey 75%) 1em 1em/2em 2em;box-shadow:0 0 0 1px silver}.picker_alpha .picker_selector,.picker_sample .picker_selector{background:none}.picker_editor input{font-family:monospace;padding:.2em .4em}.picker_sample::before{content:"";position:absolute;display:block;width:100%;height:100%;background:currentColor}.picker_arrow{position:absolute;z-index:-1}.picker_wrapper.popup{position:absolute;z-index:2;margin:1.5em}.picker_wrapper.popup,.picker_wrapper.popup .picker_arrow::before,.picker_wrapper.popup .picker_arrow::after{background:#f2f2f2;box-shadow:0 0 10px 1px rgba(0,0,0,.4)}.picker_wrapper.popup .picker_arrow{width:3em;height:3em;margin:0}.picker_wrapper.popup .picker_arrow::before,.picker_wrapper.popup .picker_arrow::after{content:"";display:block;position:absolute;top:0;left:0;z-index:-99}.picker_wrapper.popup .picker_arrow::before{width:100%;height:100%;-webkit-transform:skew(45deg);transform:skew(45deg);-webkit-transform-origin:0 100%;transform-origin:0 100%}.picker_wrapper.popup .picker_arrow::after{width:150%;height:150%;box-shadow:none}.popup.popup_top{bottom:100%;left:0}.popup.popup_top .picker_arrow{bottom:0;left:0;-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.popup.popup_bottom{top:100%;left:0}.popup.popup_bottom .picker_arrow{top:0;left:0;-webkit-transform:rotate(90deg) scale(1, -1);transform:rotate(90deg) scale(1, -1)}.popup.popup_left{top:0;right:100%}.popup.popup_left .picker_arrow{top:0;right:0;-webkit-transform:scale(-1, 1);transform:scale(-1, 1)}.popup.popup_right{top:0;left:100%}.popup.popup_right .picker_arrow{top:0;left:0}';
|
|
1037
|
-
document.documentElement.firstElementChild.appendChild(style);
|
|
1038
|
-
Picker.StyleElement = style;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
exports.default = Picker;
|