@tryghost/color-utils 0.1.11 → 0.1.14
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/es/color-utils.js +21 -13
- package/es/color-utils.js.map +1 -1
- package/package.json +5 -5
- package/umd/color-utils.min.js +1 -1
- package/umd/color-utils.min.js.map +1 -1
package/es/color-utils.js
CHANGED
|
@@ -198,12 +198,13 @@ var colorString = createCommonjsModule(function (module) {
|
|
|
198
198
|
/* MIT license */
|
|
199
199
|
|
|
200
200
|
|
|
201
|
+
var hasOwnProperty = Object.hasOwnProperty;
|
|
201
202
|
|
|
202
203
|
var reverseNames = {};
|
|
203
204
|
|
|
204
205
|
// create a list of reverse color names
|
|
205
206
|
for (var name in colorName$1) {
|
|
206
|
-
if (colorName$1
|
|
207
|
+
if (hasOwnProperty.call(colorName$1, name)) {
|
|
207
208
|
reverseNames[colorName$1[name]] = name;
|
|
208
209
|
}
|
|
209
210
|
}
|
|
@@ -246,9 +247,9 @@ cs.get.rgb = function (string) {
|
|
|
246
247
|
|
|
247
248
|
var abbr = /^#([a-f0-9]{3,4})$/i;
|
|
248
249
|
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
|
249
|
-
var rgba = /^rgba?\(\s*([+-]?\d+)\s
|
|
250
|
-
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s
|
|
251
|
-
var keyword =
|
|
250
|
+
var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
251
|
+
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
252
|
+
var keyword = /^(\w+)$/;
|
|
252
253
|
|
|
253
254
|
var rgb = [0, 0, 0, 1];
|
|
254
255
|
var match;
|
|
@@ -285,7 +286,11 @@ cs.get.rgb = function (string) {
|
|
|
285
286
|
}
|
|
286
287
|
|
|
287
288
|
if (match[4]) {
|
|
288
|
-
|
|
289
|
+
if (match[5]) {
|
|
290
|
+
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
291
|
+
} else {
|
|
292
|
+
rgb[3] = parseFloat(match[4]);
|
|
293
|
+
}
|
|
289
294
|
}
|
|
290
295
|
} else if (match = string.match(per)) {
|
|
291
296
|
for (i = 0; i < 3; i++) {
|
|
@@ -293,19 +298,22 @@ cs.get.rgb = function (string) {
|
|
|
293
298
|
}
|
|
294
299
|
|
|
295
300
|
if (match[4]) {
|
|
296
|
-
|
|
301
|
+
if (match[5]) {
|
|
302
|
+
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
303
|
+
} else {
|
|
304
|
+
rgb[3] = parseFloat(match[4]);
|
|
305
|
+
}
|
|
297
306
|
}
|
|
298
307
|
} else if (match = string.match(keyword)) {
|
|
299
308
|
if (match[1] === 'transparent') {
|
|
300
309
|
return [0, 0, 0, 0];
|
|
301
310
|
}
|
|
302
311
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (!rgb) {
|
|
312
|
+
if (!hasOwnProperty.call(colorName$1, match[1])) {
|
|
306
313
|
return null;
|
|
307
314
|
}
|
|
308
315
|
|
|
316
|
+
rgb = colorName$1[match[1]];
|
|
309
317
|
rgb[3] = 1;
|
|
310
318
|
|
|
311
319
|
return rgb;
|
|
@@ -326,12 +334,12 @@ cs.get.hsl = function (string) {
|
|
|
326
334
|
return null;
|
|
327
335
|
}
|
|
328
336
|
|
|
329
|
-
var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?[\d
|
|
337
|
+
var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
330
338
|
var match = string.match(hsl);
|
|
331
339
|
|
|
332
340
|
if (match) {
|
|
333
341
|
var alpha = parseFloat(match[4]);
|
|
334
|
-
var h = (parseFloat(match[1]) + 360) % 360;
|
|
342
|
+
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
|
335
343
|
var s = clamp(parseFloat(match[2]), 0, 100);
|
|
336
344
|
var l = clamp(parseFloat(match[3]), 0, 100);
|
|
337
345
|
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
@@ -347,7 +355,7 @@ cs.get.hwb = function (string) {
|
|
|
347
355
|
return null;
|
|
348
356
|
}
|
|
349
357
|
|
|
350
|
-
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d
|
|
358
|
+
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
351
359
|
var match = string.match(hwb);
|
|
352
360
|
|
|
353
361
|
if (match) {
|
|
@@ -426,7 +434,7 @@ function clamp(num, min, max) {
|
|
|
426
434
|
}
|
|
427
435
|
|
|
428
436
|
function hexDouble(num) {
|
|
429
|
-
var str = num.toString(16).toUpperCase();
|
|
437
|
+
var str = Math.round(num).toString(16).toUpperCase();
|
|
430
438
|
return (str.length < 2) ? '0' + str : str;
|
|
431
439
|
}
|
|
432
440
|
});
|