@moneko/core 2.0.0-beta.4 → 2.0.0-beta.40

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.
Files changed (91) hide show
  1. package/{lib/utils → build}/color-palette.d.ts +0 -0
  2. package/build/color-palette.js +1 -0
  3. package/build/common.js +1 -1
  4. package/build/envFlags.d.ts +1 -1
  5. package/build/envFlags.js +1 -1
  6. package/build/html-add-entry-attr.js +1 -1
  7. package/build/html-plugin-option.js +1 -1
  8. package/build/minify.d.ts +1 -1
  9. package/build/modifyVars.js +1 -1
  10. package/build/module-federation.js +1 -1
  11. package/build/module.config.js +1 -1
  12. package/build/process-env.d.ts +3 -1
  13. package/build/process-env.js +1 -1
  14. package/build/swcrc.js +1 -1
  15. package/build/tsloader.config.js +1 -1
  16. package/build/utils.d.ts +9 -6
  17. package/build/utils.js +1 -1
  18. package/{lib/utils/theme.d.ts → build/variables.d.ts} +9 -1
  19. package/build/variables.js +1 -0
  20. package/build/webpack.common.js +1 -1
  21. package/build/webpack.dev.js +1 -1
  22. package/build/yarn-argv.js +1 -1
  23. package/lib/components/app-router/index.d.ts +2 -2
  24. package/lib/components/app-router/index.js +1 -1
  25. package/lib/components/app-router/index.js.map +1 -1
  26. package/lib/components/fallback/index.js +1 -1
  27. package/lib/components/fallback/index.js.map +1 -1
  28. package/lib/components/fallback-comp/index.js +1 -1
  29. package/lib/components/fallback-comp/index.js.map +1 -1
  30. package/lib/components/layout-menu/index.js +1 -1
  31. package/lib/components/layout-menu/index.js.map +1 -1
  32. package/lib/hooks/navgate.js +1 -1
  33. package/lib/hooks/navgate.js.map +1 -1
  34. package/lib/index.d.ts +3 -9
  35. package/lib/index.js +1 -1
  36. package/lib/index.js.map +1 -1
  37. package/lib/packages/back-stage/app.d.ts +0 -2
  38. package/lib/packages/back-stage/app.js +1 -1
  39. package/lib/packages/back-stage/app.js.map +1 -1
  40. package/lib/packages/back-stage/index.d.ts +1 -1
  41. package/lib/packages/back-stage/index.js +1 -1
  42. package/lib/packages/back-stage/index.js.map +1 -1
  43. package/lib/packages/back-stage/layout/index.js +1 -1
  44. package/lib/packages/back-stage/layout/index.js.map +1 -1
  45. package/lib/packages/back-stage/models/app-program.d.ts +1 -1
  46. package/lib/packages/back-stage/models/app-program.js +1 -1
  47. package/lib/packages/back-stage/models/app-program.js.map +1 -1
  48. package/lib/packages/library/index.d.ts +1 -1
  49. package/lib/packages/library/index.js +1 -1
  50. package/lib/packages/library/index.js.map +1 -1
  51. package/lib/packages/mobile/index.d.ts +1 -1
  52. package/lib/packages/mobile/index.js +1 -1
  53. package/lib/packages/mobile/index.js.map +1 -1
  54. package/lib/packages/single-spa/index.d.ts +1 -1
  55. package/lib/packages/single-spa/index.js +1 -1
  56. package/lib/packages/single-spa/index.js.map +1 -1
  57. package/lib/packages/site/index.d.ts +1 -1
  58. package/lib/packages/site/index.js +1 -1
  59. package/lib/packages/site/index.js.map +1 -1
  60. package/lib/router/index.d.ts +13 -5
  61. package/lib/router/index.js +1 -1
  62. package/lib/router/index.js.map +1 -1
  63. package/lib/styles/animation.css +58 -0
  64. package/lib/styles/normalize.css +96 -21
  65. package/lib/styles/variables.css +40 -0
  66. package/lib/utils/index.d.ts +1 -2
  67. package/lib/utils/index.js +1 -1
  68. package/lib/utils/index.js.map +1 -1
  69. package/package.json +19 -23
  70. package/typings/global.d.ts +29 -11
  71. package/build/has-antd.d.ts +0 -3
  72. package/build/has-antd.js +0 -1
  73. package/lib/components/readme/index.d.ts +0 -3
  74. package/lib/components/readme/index.js +0 -2
  75. package/lib/components/readme/index.js.map +0 -1
  76. package/lib/components/readme/index.less +0 -4
  77. package/lib/packages/back-stage/antd.global.less +0 -67
  78. package/lib/styles/animation.less +0 -58
  79. package/lib/styles/ant.variables.global.less +0 -231
  80. package/lib/styles/eval/bezierEasing.less +0 -106
  81. package/lib/styles/eval/colorPalette.less +0 -73
  82. package/lib/styles/eval/tinyColor.less +0 -1181
  83. package/lib/styles/index.global.less +0 -136
  84. package/lib/styles/vars.less +0 -98
  85. package/lib/utils/color-palette.js +0 -2
  86. package/lib/utils/color-palette.js.map +0 -1
  87. package/lib/utils/lazy-import.d.ts +0 -34
  88. package/lib/utils/lazy-import.js +0 -2
  89. package/lib/utils/lazy-import.js.map +0 -1
  90. package/lib/utils/theme.js +0 -2
  91. package/lib/utils/theme.js.map +0 -1
@@ -1,1181 +0,0 @@
1
- .tinyColorMixin() {
2
- @functions: ~`(function() {
3
- // TinyColor v1.4.1
4
- // https://github.com/bgrins/TinyColor
5
- // 2016-07-07, Brian Grinstead, MIT License
6
- var trimLeft = /^\s+/,
7
- trimRight = /\s+$/,
8
- tinyCounter = 0,
9
- mathRound = Math.round,
10
- mathMin = Math.min,
11
- mathMax = Math.max,
12
- mathRandom = Math.random;
13
-
14
- function tinycolor (color, opts) {
15
-
16
- color = (color) ? color : '';
17
- opts = opts || { };
18
-
19
- // If input is already a tinycolor, return itself
20
- if (color instanceof tinycolor) {
21
- return color;
22
- }
23
- // If we are called as a function, call using new instead
24
- if (!(this instanceof tinycolor)) {
25
- return new tinycolor(color, opts);
26
- }
27
-
28
- var rgb = inputToRGB(color);
29
- this._originalInput = color,
30
- this._r = rgb.r,
31
- this._g = rgb.g,
32
- this._b = rgb.b,
33
- this._a = rgb.a,
34
- this._roundA = mathRound(100*this._a) / 100,
35
- this._format = opts.format || rgb.format;
36
- this._gradientType = opts.gradientType;
37
-
38
- // Don't let the range of [0,255] come back in [0,1].
39
- // Potentially lose a little bit of precision here, but will fix issues where
40
- // .5 gets interpreted as half of the total, instead of half of 1
41
- // If it was supposed to be 128, this was already taken care of by inputToRgb
42
- if (this._r < 1) { this._r = mathRound(this._r); }
43
- if (this._g < 1) { this._g = mathRound(this._g); }
44
- if (this._b < 1) { this._b = mathRound(this._b); }
45
-
46
- this._ok = rgb.ok;
47
- this._tc_id = tinyCounter++;
48
- }
49
-
50
- tinycolor.prototype = {
51
- isDark: function() {
52
- return this.getBrightness() < 128;
53
- },
54
- isLight: function() {
55
- return !this.isDark();
56
- },
57
- isValid: function() {
58
- return this._ok;
59
- },
60
- getOriginalInput: function() {
61
- return this._originalInput;
62
- },
63
- getFormat: function() {
64
- return this._format;
65
- },
66
- getAlpha: function() {
67
- return this._a;
68
- },
69
- getBrightness: function() {
70
- //http://www.w3.org/TR/AERT#color-contrast
71
- var rgb = this.toRgb();
72
- return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
73
- },
74
- getLuminance: function() {
75
- //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
76
- var rgb = this.toRgb();
77
- var RsRGB, GsRGB, BsRGB, R, G, B;
78
- RsRGB = rgb.r/255;
79
- GsRGB = rgb.g/255;
80
- BsRGB = rgb.b/255;
81
-
82
- if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
83
- if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
84
- if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
85
- return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
86
- },
87
- setAlpha: function(value) {
88
- this._a = boundAlpha(value);
89
- this._roundA = mathRound(100*this._a) / 100;
90
- return this;
91
- },
92
- toHsv: function() {
93
- var hsv = rgbToHsv(this._r, this._g, this._b);
94
- return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
95
- },
96
- toHsvString: function() {
97
- var hsv = rgbToHsv(this._r, this._g, this._b);
98
- var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
99
- return (this._a == 1) ?
100
- "hsv(" + h + ", " + s + "%, " + v + "%)" :
101
- "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
102
- },
103
- toHsl: function() {
104
- var hsl = rgbToHsl(this._r, this._g, this._b);
105
- return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
106
- },
107
- toHslString: function() {
108
- var hsl = rgbToHsl(this._r, this._g, this._b);
109
- var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
110
- return (this._a == 1) ?
111
- "hsl(" + h + ", " + s + "%, " + l + "%)" :
112
- "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
113
- },
114
- toHex: function(allow3Char) {
115
- return rgbToHex(this._r, this._g, this._b, allow3Char);
116
- },
117
- toHexString: function(allow3Char) {
118
- return '#' + this.toHex(allow3Char);
119
- },
120
- toHex8: function(allow4Char) {
121
- return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
122
- },
123
- toHex8String: function(allow4Char) {
124
- return '#' + this.toHex8(allow4Char);
125
- },
126
- toRgb: function() {
127
- return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
128
- },
129
- toRgbString: function() {
130
- return (this._a == 1) ?
131
- "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
132
- "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
133
- },
134
- toPercentageRgb: function() {
135
- return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
136
- },
137
- toPercentageRgbString: function() {
138
- return (this._a == 1) ?
139
- "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
140
- "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
141
- },
142
- toName: function() {
143
- if (this._a === 0) {
144
- return "transparent";
145
- }
146
-
147
- if (this._a < 1) {
148
- return false;
149
- }
150
-
151
- return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
152
- },
153
- toFilter: function(secondColor) {
154
- var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
155
- var secondHex8String = hex8String;
156
- var gradientType = this._gradientType ? "GradientType = 1, " : "";
157
-
158
- if (secondColor) {
159
- var s = tinycolor(secondColor);
160
- secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
161
- }
162
-
163
- return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
164
- },
165
- toString: function(format) {
166
- var formatSet = !!format;
167
- format = format || this._format;
168
-
169
- var formattedString = false;
170
- var hasAlpha = this._a < 1 && this._a >= 0;
171
- var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
172
-
173
- if (needsAlphaFormat) {
174
- // Special case for "transparent", all other non-alpha formats
175
- // will return rgba when there is transparency.
176
- if (format === "name" && this._a === 0) {
177
- return this.toName();
178
- }
179
- return this.toRgbString();
180
- }
181
- if (format === "rgb") {
182
- formattedString = this.toRgbString();
183
- }
184
- if (format === "prgb") {
185
- formattedString = this.toPercentageRgbString();
186
- }
187
- if (format === "hex" || format === "hex6") {
188
- formattedString = this.toHexString();
189
- }
190
- if (format === "hex3") {
191
- formattedString = this.toHexString(true);
192
- }
193
- if (format === "hex4") {
194
- formattedString = this.toHex8String(true);
195
- }
196
- if (format === "hex8") {
197
- formattedString = this.toHex8String();
198
- }
199
- if (format === "name") {
200
- formattedString = this.toName();
201
- }
202
- if (format === "hsl") {
203
- formattedString = this.toHslString();
204
- }
205
- if (format === "hsv") {
206
- formattedString = this.toHsvString();
207
- }
208
-
209
- return formattedString || this.toHexString();
210
- },
211
- clone: function() {
212
- return tinycolor(this.toString());
213
- },
214
-
215
- _applyModification: function(fn, args) {
216
- var color = fn.apply(null, [this].concat([].slice.call(args)));
217
- this._r = color._r;
218
- this._g = color._g;
219
- this._b = color._b;
220
- this.setAlpha(color._a);
221
- return this;
222
- },
223
- lighten: function() {
224
- return this._applyModification(lighten, arguments);
225
- },
226
- brighten: function() {
227
- return this._applyModification(brighten, arguments);
228
- },
229
- darken: function() {
230
- return this._applyModification(darken, arguments);
231
- },
232
- desaturate: function() {
233
- return this._applyModification(desaturate, arguments);
234
- },
235
- saturate: function() {
236
- return this._applyModification(saturate, arguments);
237
- },
238
- greyscale: function() {
239
- return this._applyModification(greyscale, arguments);
240
- },
241
- spin: function() {
242
- return this._applyModification(spin, arguments);
243
- },
244
-
245
- _applyCombination: function(fn, args) {
246
- return fn.apply(null, [this].concat([].slice.call(args)));
247
- },
248
- analogous: function() {
249
- return this._applyCombination(analogous, arguments);
250
- },
251
- complement: function() {
252
- return this._applyCombination(complement, arguments);
253
- },
254
- monochromatic: function() {
255
- return this._applyCombination(monochromatic, arguments);
256
- },
257
- splitcomplement: function() {
258
- return this._applyCombination(splitcomplement, arguments);
259
- },
260
- triad: function() {
261
- return this._applyCombination(triad, arguments);
262
- },
263
- tetrad: function() {
264
- return this._applyCombination(tetrad, arguments);
265
- }
266
- };
267
-
268
- // If input is an object, force 1 into "1.0" to handle ratios properly
269
- // String input requires "1.0" as input, so 1 will be treated as 1
270
- tinycolor.fromRatio = function(color, opts) {
271
- if (typeof color == "object") {
272
- var newColor = {};
273
- for (var i in color) {
274
- if (color.hasOwnProperty(i)) {
275
- if (i === "a") {
276
- newColor[i] = color[i];
277
- }
278
- else {
279
- newColor[i] = convertToPercentage(color[i]);
280
- }
281
- }
282
- }
283
- color = newColor;
284
- }
285
-
286
- return tinycolor(color, opts);
287
- };
288
-
289
- // Given a string or object, convert that input to RGB
290
- // Possible string inputs:
291
- //
292
- // "red"
293
- // "#f00" or "f00"
294
- // "#ff0000" or "ff0000"
295
- // "#ff000000" or "ff000000"
296
- // "rgb 255 0 0" or "rgb (255, 0, 0)"
297
- // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
298
- // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
299
- // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
300
- // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
301
- // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
302
- // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
303
- //
304
- function inputToRGB(color) {
305
-
306
- var rgb = { r: 0, g: 0, b: 0 };
307
- var a = 1;
308
- var s = null;
309
- var v = null;
310
- var l = null;
311
- var ok = false;
312
- var format = false;
313
-
314
- if (typeof color == "string") {
315
- color = stringInputToObject(color);
316
- }
317
-
318
- if (typeof color == "object") {
319
- if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
320
- rgb = rgbToRgb(color.r, color.g, color.b);
321
- ok = true;
322
- format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
323
- }
324
- else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
325
- s = convertToPercentage(color.s);
326
- v = convertToPercentage(color.v);
327
- rgb = hsvToRgb(color.h, s, v);
328
- ok = true;
329
- format = "hsv";
330
- }
331
- else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
332
- s = convertToPercentage(color.s);
333
- l = convertToPercentage(color.l);
334
- rgb = hslToRgb(color.h, s, l);
335
- ok = true;
336
- format = "hsl";
337
- }
338
-
339
- if (color.hasOwnProperty("a")) {
340
- a = color.a;
341
- }
342
- }
343
-
344
- a = boundAlpha(a);
345
-
346
- return {
347
- ok: ok,
348
- format: color.format || format,
349
- r: mathMin(255, mathMax(rgb.r, 0)),
350
- g: mathMin(255, mathMax(rgb.g, 0)),
351
- b: mathMin(255, mathMax(rgb.b, 0)),
352
- a: a
353
- };
354
- }
355
-
356
- // Conversion Functions
357
- // --------------------
358
-
359
- // rgbToHsl, rgbToHsv, hslToRgb, hsvToRgb modified from:
360
- // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
361
-
362
- // rgbToRgb
363
- // Handle bounds / percentage checking to conform to CSS color spec
364
- // <http://www.w3.org/TR/css3-color/>
365
- // *Assumes:* r, g, b in [0, 255] or [0, 1]
366
- // *Returns:* { r, g, b } in [0, 255]
367
- function rgbToRgb(r, g, b){
368
- return {
369
- r: bound01(r, 255) * 255,
370
- g: bound01(g, 255) * 255,
371
- b: bound01(b, 255) * 255
372
- };
373
- }
374
-
375
- // rgbToHsl
376
- // Converts an RGB color value to HSL.
377
- // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
378
- // *Returns:* { h, s, l } in [0,1]
379
- function rgbToHsl(r, g, b) {
380
-
381
- r = bound01(r, 255);
382
- g = bound01(g, 255);
383
- b = bound01(b, 255);
384
-
385
- var max = mathMax(r, g, b), min = mathMin(r, g, b);
386
- var h, s, l = (max + min) / 2;
387
-
388
- if(max == min) {
389
- h = s = 0; // achromatic
390
- }
391
- else {
392
- var d = max - min;
393
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
394
- switch(max) {
395
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
396
- case g: h = (b - r) / d + 2; break;
397
- case b: h = (r - g) / d + 4; break;
398
- }
399
-
400
- h /= 6;
401
- }
402
-
403
- return { h: h, s: s, l: l };
404
- }
405
-
406
- // hslToRgb
407
- // Converts an HSL color value to RGB.
408
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
409
- // *Returns:* { r, g, b } in the set [0, 255]
410
- function hslToRgb(h, s, l) {
411
- var r, g, b;
412
-
413
- h = bound01(h, 360);
414
- s = bound01(s, 100);
415
- l = bound01(l, 100);
416
-
417
- function hue2rgb(p, q, t) {
418
- if(t < 0) t += 1;
419
- if(t > 1) t -= 1;
420
- if(t < 1/6) return p + (q - p) * 6 * t;
421
- if(t < 1/2) return q;
422
- if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
423
- return p;
424
- }
425
-
426
- if(s === 0) {
427
- r = g = b = l; // achromatic
428
- }
429
- else {
430
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
431
- var p = 2 * l - q;
432
- r = hue2rgb(p, q, h + 1/3);
433
- g = hue2rgb(p, q, h);
434
- b = hue2rgb(p, q, h - 1/3);
435
- }
436
-
437
- return { r: r * 255, g: g * 255, b: b * 255 };
438
- }
439
-
440
- // rgbToHsv
441
- // Converts an RGB color value to HSV
442
- // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
443
- // *Returns:* { h, s, v } in [0,1]
444
- function rgbToHsv(r, g, b) {
445
-
446
- r = bound01(r, 255);
447
- g = bound01(g, 255);
448
- b = bound01(b, 255);
449
-
450
- var max = mathMax(r, g, b), min = mathMin(r, g, b);
451
- var h, s, v = max;
452
-
453
- var d = max - min;
454
- s = max === 0 ? 0 : d / max;
455
-
456
- if(max == min) {
457
- h = 0; // achromatic
458
- }
459
- else {
460
- switch(max) {
461
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
462
- case g: h = (b - r) / d + 2; break;
463
- case b: h = (r - g) / d + 4; break;
464
- }
465
- h /= 6;
466
- }
467
- return { h: h, s: s, v: v };
468
- }
469
-
470
- // hsvToRgb
471
- // Converts an HSV color value to RGB.
472
- // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
473
- // *Returns:* { r, g, b } in the set [0, 255]
474
- function hsvToRgb(h, s, v) {
475
-
476
- h = bound01(h, 360) * 6;
477
- s = bound01(s, 100);
478
- v = bound01(v, 100);
479
-
480
- var i = Math.floor(h),
481
- f = h - i,
482
- p = v * (1 - s),
483
- q = v * (1 - f * s),
484
- t = v * (1 - (1 - f) * s),
485
- mod = i % 6,
486
- r = [v, q, p, p, t, v][mod],
487
- g = [t, v, v, q, p, p][mod],
488
- b = [p, p, t, v, v, q][mod];
489
-
490
- return { r: r * 255, g: g * 255, b: b * 255 };
491
- }
492
-
493
- // rgbToHex
494
- // Converts an RGB color to hex
495
- // Assumes r, g, and b are contained in the set [0, 255]
496
- // Returns a 3 or 6 character hex
497
- function rgbToHex(r, g, b, allow3Char) {
498
-
499
- var hex = [
500
- pad2(mathRound(r).toString(16)),
501
- pad2(mathRound(g).toString(16)),
502
- pad2(mathRound(b).toString(16))
503
- ];
504
-
505
- // Return a 3 character hex if possible
506
- 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)) {
507
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
508
- }
509
-
510
- return hex.join("");
511
- }
512
-
513
- // rgbaToHex
514
- // Converts an RGBA color plus alpha transparency to hex
515
- // Assumes r, g, b are contained in the set [0, 255] and
516
- // a in [0, 1]. Returns a 4 or 8 character rgba hex
517
- function rgbaToHex(r, g, b, a, allow4Char) {
518
-
519
- var hex = [
520
- pad2(mathRound(r).toString(16)),
521
- pad2(mathRound(g).toString(16)),
522
- pad2(mathRound(b).toString(16)),
523
- pad2(convertDecimalToHex(a))
524
- ];
525
-
526
- // Return a 4 character hex if possible
527
- 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)) {
528
- return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
529
- }
530
-
531
- return hex.join("");
532
- }
533
-
534
- // rgbaToArgbHex
535
- // Converts an RGBA color to an ARGB Hex8 string
536
- // Rarely used, but required for "toFilter()"
537
- function rgbaToArgbHex(r, g, b, a) {
538
-
539
- var hex = [
540
- pad2(convertDecimalToHex(a)),
541
- pad2(mathRound(r).toString(16)),
542
- pad2(mathRound(g).toString(16)),
543
- pad2(mathRound(b).toString(16))
544
- ];
545
-
546
- return hex.join("");
547
- }
548
-
549
- // equals
550
- // Can be called with any tinycolor input
551
- tinycolor.equals = function (color1, color2) {
552
- if (!color1 || !color2) { return false; }
553
- return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
554
- };
555
-
556
- tinycolor.random = function() {
557
- return tinycolor.fromRatio({
558
- r: mathRandom(),
559
- g: mathRandom(),
560
- b: mathRandom()
561
- });
562
- };
563
-
564
- // Modification Functions
565
- // ----------------------
566
- // Thanks to less.js for some of the basics here
567
- // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
568
-
569
- function desaturate(color, amount) {
570
- amount = (amount === 0) ? 0 : (amount || 10);
571
- var hsl = tinycolor(color).toHsl();
572
- hsl.s -= amount / 100;
573
- hsl.s = clamp01(hsl.s);
574
- return tinycolor(hsl);
575
- }
576
-
577
- function saturate(color, amount) {
578
- amount = (amount === 0) ? 0 : (amount || 10);
579
- var hsl = tinycolor(color).toHsl();
580
- hsl.s += amount / 100;
581
- hsl.s = clamp01(hsl.s);
582
- return tinycolor(hsl);
583
- }
584
-
585
- function greyscale(color) {
586
- return tinycolor(color).desaturate(100);
587
- }
588
-
589
- function lighten (color, amount) {
590
- amount = (amount === 0) ? 0 : (amount || 10);
591
- var hsl = tinycolor(color).toHsl();
592
- hsl.l += amount / 100;
593
- hsl.l = clamp01(hsl.l);
594
- return tinycolor(hsl);
595
- }
596
-
597
- function brighten(color, amount) {
598
- amount = (amount === 0) ? 0 : (amount || 10);
599
- var rgb = tinycolor(color).toRgb();
600
- rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
601
- rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
602
- rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
603
- return tinycolor(rgb);
604
- }
605
-
606
- function darken (color, amount) {
607
- amount = (amount === 0) ? 0 : (amount || 10);
608
- var hsl = tinycolor(color).toHsl();
609
- hsl.l -= amount / 100;
610
- hsl.l = clamp01(hsl.l);
611
- return tinycolor(hsl);
612
- }
613
-
614
- // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
615
- // Values outside of this range will be wrapped into this range.
616
- function spin(color, amount) {
617
- var hsl = tinycolor(color).toHsl();
618
- var hue = (hsl.h + amount) % 360;
619
- hsl.h = hue < 0 ? 360 + hue : hue;
620
- return tinycolor(hsl);
621
- }
622
-
623
- // Combination Functions
624
- // ---------------------
625
- // Thanks to jQuery xColor for some of the ideas behind these
626
- // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
627
-
628
- function complement(color) {
629
- var hsl = tinycolor(color).toHsl();
630
- hsl.h = (hsl.h + 180) % 360;
631
- return tinycolor(hsl);
632
- }
633
-
634
- function triad(color) {
635
- var hsl = tinycolor(color).toHsl();
636
- var h = hsl.h;
637
- return [
638
- tinycolor(color),
639
- tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
640
- tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
641
- ];
642
- }
643
-
644
- function tetrad(color) {
645
- var hsl = tinycolor(color).toHsl();
646
- var h = hsl.h;
647
- return [
648
- tinycolor(color),
649
- tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
650
- tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
651
- tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
652
- ];
653
- }
654
-
655
- function splitcomplement(color) {
656
- var hsl = tinycolor(color).toHsl();
657
- var h = hsl.h;
658
- return [
659
- tinycolor(color),
660
- tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
661
- tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
662
- ];
663
- }
664
-
665
- function analogous(color, results, slices) {
666
- results = results || 6;
667
- slices = slices || 30;
668
-
669
- var hsl = tinycolor(color).toHsl();
670
- var part = 360 / slices;
671
- var ret = [tinycolor(color)];
672
-
673
- for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
674
- hsl.h = (hsl.h + part) % 360;
675
- ret.push(tinycolor(hsl));
676
- }
677
- return ret;
678
- }
679
-
680
- function monochromatic(color, results) {
681
- results = results || 6;
682
- var hsv = tinycolor(color).toHsv();
683
- var h = hsv.h, s = hsv.s, v = hsv.v;
684
- var ret = [];
685
- var modification = 1 / results;
686
-
687
- while (results--) {
688
- ret.push(tinycolor({ h: h, s: s, v: v}));
689
- v = (v + modification) % 1;
690
- }
691
-
692
- return ret;
693
- }
694
-
695
- // Utility Functions
696
- // ---------------------
697
-
698
- tinycolor.mix = function(color1, color2, amount) {
699
- amount = (amount === 0) ? 0 : (amount || 50);
700
-
701
- var rgb1 = tinycolor(color1).toRgb();
702
- var rgb2 = tinycolor(color2).toRgb();
703
-
704
- var p = amount / 100;
705
-
706
- var rgba = {
707
- r: ((rgb2.r - rgb1.r) * p) + rgb1.r,
708
- g: ((rgb2.g - rgb1.g) * p) + rgb1.g,
709
- b: ((rgb2.b - rgb1.b) * p) + rgb1.b,
710
- a: ((rgb2.a - rgb1.a) * p) + rgb1.a
711
- };
712
-
713
- return tinycolor(rgba);
714
- };
715
-
716
- // Readability Functions
717
- // ---------------------
718
- // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
719
-
720
- // contrast
721
- // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
722
- tinycolor.readability = function(color1, color2) {
723
- var c1 = tinycolor(color1);
724
- var c2 = tinycolor(color2);
725
- return (Math.max(c1.getLuminance(),c2.getLuminance())+0.05) / (Math.min(c1.getLuminance(),c2.getLuminance())+0.05);
726
- };
727
-
728
- // isReadable
729
- // Ensure that foreground and background color combinations meet WCAG2 guidelines.
730
- // The third argument is an optional Object.
731
- // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
732
- // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
733
- // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
734
-
735
- // *Example*
736
- // tinycolor.isReadable("#000", "#111") => false
737
- // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
738
- tinycolor.isReadable = function(color1, color2, wcag2) {
739
- var readability = tinycolor.readability(color1, color2);
740
- var wcag2Parms, out;
741
-
742
- out = false;
743
-
744
- wcag2Parms = validateWCAG2Parms(wcag2);
745
- switch (wcag2Parms.level + wcag2Parms.size) {
746
- case "AAsmall":
747
- case "AAAlarge":
748
- out = readability >= 4.5;
749
- break;
750
- case "AAlarge":
751
- out = readability >= 3;
752
- break;
753
- case "AAAsmall":
754
- out = readability >= 7;
755
- break;
756
- }
757
- return out;
758
-
759
- };
760
-
761
- // mostReadable
762
- // Given a base color and a list of possible foreground or background
763
- // colors for that base, returns the most readable color.
764
- // Optionally returns Black or White if the most readable color is unreadable.
765
- // *Example*
766
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
767
- // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
768
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
769
- // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
770
- tinycolor.mostReadable = function(baseColor, colorList, args) {
771
- var bestColor = null;
772
- var bestScore = 0;
773
- var readability;
774
- var includeFallbackColors, level, size ;
775
- args = args || {};
776
- includeFallbackColors = args.includeFallbackColors ;
777
- level = args.level;
778
- size = args.size;
779
-
780
- for (var i= 0; i < colorList.length ; i++) {
781
- readability = tinycolor.readability(baseColor, colorList[i]);
782
- if (readability > bestScore) {
783
- bestScore = readability;
784
- bestColor = tinycolor(colorList[i]);
785
- }
786
- }
787
-
788
- if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) {
789
- return bestColor;
790
- }
791
- else {
792
- args.includeFallbackColors=false;
793
- return tinycolor.mostReadable(baseColor,["#fff", "#000"],args);
794
- }
795
- };
796
-
797
- // Big List of Colors
798
- // ------------------
799
- // <http://www.w3.org/TR/css3-color/#svg-color>
800
- var names = tinycolor.names = {
801
- aliceblue: "f0f8ff",
802
- antiquewhite: "faebd7",
803
- aqua: "0ff",
804
- aquamarine: "7fffd4",
805
- azure: "f0ffff",
806
- beige: "f5f5dc",
807
- bisque: "ffe4c4",
808
- black: "000",
809
- blanchedalmond: "ffebcd",
810
- blue: "00f",
811
- blueviolet: "8a2be2",
812
- brown: "a52a2a",
813
- burlywood: "deb887",
814
- burntsienna: "ea7e5d",
815
- cadetblue: "5f9ea0",
816
- chartreuse: "7fff00",
817
- chocolate: "d2691e",
818
- coral: "ff7f50",
819
- cornflowerblue: "6495ed",
820
- cornsilk: "fff8dc",
821
- crimson: "dc143c",
822
- cyan: "0ff",
823
- darkblue: "00008b",
824
- darkcyan: "008b8b",
825
- darkgoldenrod: "b8860b",
826
- darkgray: "a9a9a9",
827
- darkgreen: "006400",
828
- darkgrey: "a9a9a9",
829
- darkkhaki: "bdb76b",
830
- darkmagenta: "8b008b",
831
- darkolivegreen: "556b2f",
832
- darkorange: "ff8c00",
833
- darkorchid: "9932cc",
834
- darkred: "8b0000",
835
- darksalmon: "e9967a",
836
- darkseagreen: "8fbc8f",
837
- darkslateblue: "483d8b",
838
- darkslategray: "2f4f4f",
839
- darkslategrey: "2f4f4f",
840
- darkturquoise: "00ced1",
841
- darkviolet: "9400d3",
842
- deeppink: "ff1493",
843
- deepskyblue: "00bfff",
844
- dimgray: "696969",
845
- dimgrey: "696969",
846
- dodgerblue: "1e90ff",
847
- firebrick: "b22222",
848
- floralwhite: "fffaf0",
849
- forestgreen: "228b22",
850
- fuchsia: "f0f",
851
- gainsboro: "dcdcdc",
852
- ghostwhite: "f8f8ff",
853
- gold: "ffd700",
854
- goldenrod: "daa520",
855
- gray: "808080",
856
- green: "008000",
857
- greenyellow: "adff2f",
858
- grey: "808080",
859
- honeydew: "f0fff0",
860
- hotpink: "ff69b4",
861
- indianred: "cd5c5c",
862
- indigo: "4b0082",
863
- ivory: "fffff0",
864
- khaki: "f0e68c",
865
- lavender: "e6e6fa",
866
- lavenderblush: "fff0f5",
867
- lawngreen: "7cfc00",
868
- lemonchiffon: "fffacd",
869
- lightblue: "add8e6",
870
- lightcoral: "f08080",
871
- lightcyan: "e0ffff",
872
- lightgoldenrodyellow: "fafad2",
873
- lightgray: "d3d3d3",
874
- lightgreen: "90ee90",
875
- lightgrey: "d3d3d3",
876
- lightpink: "ffb6c1",
877
- lightsalmon: "ffa07a",
878
- lightseagreen: "20b2aa",
879
- lightskyblue: "87cefa",
880
- lightslategray: "789",
881
- lightslategrey: "789",
882
- lightsteelblue: "b0c4de",
883
- lightyellow: "ffffe0",
884
- lime: "0f0",
885
- limegreen: "32cd32",
886
- linen: "faf0e6",
887
- magenta: "f0f",
888
- maroon: "800000",
889
- mediumaquamarine: "66cdaa",
890
- mediumblue: "0000cd",
891
- mediumorchid: "ba55d3",
892
- mediumpurple: "9370db",
893
- mediumseagreen: "3cb371",
894
- mediumslateblue: "7b68ee",
895
- mediumspringgreen: "00fa9a",
896
- mediumturquoise: "48d1cc",
897
- mediumvioletred: "c71585",
898
- midnightblue: "191970",
899
- mintcream: "f5fffa",
900
- mistyrose: "ffe4e1",
901
- moccasin: "ffe4b5",
902
- navajowhite: "ffdead",
903
- navy: "000080",
904
- oldlace: "fdf5e6",
905
- olive: "808000",
906
- olivedrab: "6b8e23",
907
- orange: "ffa500",
908
- orangered: "ff4500",
909
- orchid: "da70d6",
910
- palegoldenrod: "eee8aa",
911
- palegreen: "98fb98",
912
- paleturquoise: "afeeee",
913
- palevioletred: "db7093",
914
- papayawhip: "ffefd5",
915
- peachpuff: "ffdab9",
916
- peru: "cd853f",
917
- pink: "ffc0cb",
918
- plum: "dda0dd",
919
- powderblue: "b0e0e6",
920
- purple: "800080",
921
- rebeccapurple: "663399",
922
- red: "f00",
923
- rosybrown: "bc8f8f",
924
- royalblue: "4169e1",
925
- saddlebrown: "8b4513",
926
- salmon: "fa8072",
927
- sandybrown: "f4a460",
928
- seagreen: "2e8b57",
929
- seashell: "fff5ee",
930
- sienna: "a0522d",
931
- silver: "c0c0c0",
932
- skyblue: "87ceeb",
933
- slateblue: "6a5acd",
934
- slategray: "708090",
935
- slategrey: "708090",
936
- snow: "fffafa",
937
- springgreen: "00ff7f",
938
- steelblue: "4682b4",
939
- tan: "d2b48c",
940
- teal: "008080",
941
- thistle: "d8bfd8",
942
- tomato: "ff6347",
943
- turquoise: "40e0d0",
944
- violet: "ee82ee",
945
- wheat: "f5deb3",
946
- white: "fff",
947
- whitesmoke: "f5f5f5",
948
- yellow: "ff0",
949
- yellowgreen: "9acd32"
950
- };
951
-
952
- // Make it easy to access colors via hexNames[hex]
953
- var hexNames = tinycolor.hexNames = flip(names);
954
-
955
- // Utilities
956
- // ---------
957
-
958
- // { 'name1': 'val1' } becomes { 'val1': 'name1' }
959
- function flip(o) {
960
- var flipped = { };
961
- for (var i in o) {
962
- if (o.hasOwnProperty(i)) {
963
- flipped[o[i]] = i;
964
- }
965
- }
966
- return flipped;
967
- }
968
-
969
- // Return a valid alpha value [0,1] with all invalid values being set to 1
970
- function boundAlpha(a) {
971
- a = parseFloat(a);
972
-
973
- if (isNaN(a) || a < 0 || a > 1) {
974
- a = 1;
975
- }
976
-
977
- return a;
978
- }
979
-
980
- // Take input from [0, n] and return it as [0, 1]
981
- function bound01(n, max) {
982
- if (isOnePointZero(n)) { n = "100%"; }
983
-
984
- var processPercent = isPercentage(n);
985
- n = mathMin(max, mathMax(0, parseFloat(n)));
986
-
987
- // Automatically convert percentage into number
988
- if (processPercent) {
989
- n = parseInt(n * max, 10) / 100;
990
- }
991
-
992
- // Handle floating point rounding errors
993
- if ((Math.abs(n - max) < 0.000001)) {
994
- return 1;
995
- }
996
-
997
- // Convert into [0, 1] range if it isn't already
998
- return (n % max) / parseFloat(max);
999
- }
1000
-
1001
- // Force a number between 0 and 1
1002
- function clamp01(val) {
1003
- return mathMin(1, mathMax(0, val));
1004
- }
1005
-
1006
- // Parse a base-16 hex value into a base-10 integer
1007
- function parseIntFromHex(val) {
1008
- return parseInt(val, 16);
1009
- }
1010
-
1011
- // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
1012
- // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
1013
- function isOnePointZero(n) {
1014
- return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
1015
- }
1016
-
1017
- // Check to see if string passed in is a percentage
1018
- function isPercentage(n) {
1019
- return typeof n === "string" && n.indexOf('%') != -1;
1020
- }
1021
-
1022
- // Force a hex value to have 2 characters
1023
- function pad2(c) {
1024
- return c.length == 1 ? '0' + c : '' + c;
1025
- }
1026
-
1027
- // Replace a decimal with it's percentage value
1028
- function convertToPercentage(n) {
1029
- if (n <= 1) {
1030
- n = (n * 100) + "%";
1031
- }
1032
-
1033
- return n;
1034
- }
1035
-
1036
- // Converts a decimal to a hex value
1037
- function convertDecimalToHex(d) {
1038
- return Math.round(parseFloat(d) * 255).toString(16);
1039
- }
1040
- // Converts a hex value to a decimal
1041
- function convertHexToDecimal(h) {
1042
- return (parseIntFromHex(h) / 255);
1043
- }
1044
-
1045
- var matchers = (function() {
1046
-
1047
- // <http://www.w3.org/TR/css3-values/#integers>
1048
- var CSS_INTEGER = "[-\\+]?\\d+%?";
1049
-
1050
- // <http://www.w3.org/TR/css3-values/#number-value>
1051
- var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
1052
-
1053
- // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
1054
- var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
1055
-
1056
- // Actual matching.
1057
- // Parentheses and commas are optional, but not required.
1058
- // Whitespace can take the place of commas or opening paren
1059
- var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1060
- var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1061
-
1062
- return {
1063
- CSS_UNIT: new RegExp(CSS_UNIT),
1064
- rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
1065
- rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
1066
- hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
1067
- hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
1068
- hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
1069
- hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
1070
- hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1071
- hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1072
- hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1073
- hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1074
- };
1075
- })();
1076
-
1077
- // isValidCSSUnit
1078
- // Take in a single string / number and check to see if it looks like a CSS unit
1079
- // (see matchers above for definition).
1080
- function isValidCSSUnit(color) {
1081
- return !!matchers.CSS_UNIT.exec(color);
1082
- }
1083
-
1084
- // stringInputToObject
1085
- // Permissive string parsing. Take in a number of formats, and output an object
1086
- // based on detected format. Returns { r, g, b } or { h, s, l } or { h, s, v}
1087
- function stringInputToObject(color) {
1088
-
1089
- color = color.replace(trimLeft, '').replace(trimRight, '').toLowerCase();
1090
- var named = false;
1091
- if (names[color]) {
1092
- color = names[color];
1093
- named = true;
1094
- }
1095
- else if (color == 'transparent') {
1096
- return { r: 0, g: 0, b: 0, a: 0, format: "name" };
1097
- }
1098
-
1099
- // Try to match string input using regular expressions.
1100
- // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1101
- // Just return an object and let the conversion functions handle that.
1102
- // This way the result will be the same whether the tinycolor is initialized with string or object.
1103
- var match;
1104
- if ((match = matchers.rgb.exec(color))) {
1105
- return { r: match[1], g: match[2], b: match[3] };
1106
- }
1107
- if ((match = matchers.rgba.exec(color))) {
1108
- return { r: match[1], g: match[2], b: match[3], a: match[4] };
1109
- }
1110
- if ((match = matchers.hsl.exec(color))) {
1111
- return { h: match[1], s: match[2], l: match[3] };
1112
- }
1113
- if ((match = matchers.hsla.exec(color))) {
1114
- return { h: match[1], s: match[2], l: match[3], a: match[4] };
1115
- }
1116
- if ((match = matchers.hsv.exec(color))) {
1117
- return { h: match[1], s: match[2], v: match[3] };
1118
- }
1119
- if ((match = matchers.hsva.exec(color))) {
1120
- return { h: match[1], s: match[2], v: match[3], a: match[4] };
1121
- }
1122
- if ((match = matchers.hex8.exec(color))) {
1123
- return {
1124
- r: parseIntFromHex(match[1]),
1125
- g: parseIntFromHex(match[2]),
1126
- b: parseIntFromHex(match[3]),
1127
- a: convertHexToDecimal(match[4]),
1128
- format: named ? "name" : "hex8"
1129
- };
1130
- }
1131
- if ((match = matchers.hex6.exec(color))) {
1132
- return {
1133
- r: parseIntFromHex(match[1]),
1134
- g: parseIntFromHex(match[2]),
1135
- b: parseIntFromHex(match[3]),
1136
- format: named ? "name" : "hex"
1137
- };
1138
- }
1139
- if ((match = matchers.hex4.exec(color))) {
1140
- return {
1141
- r: parseIntFromHex(match[1] + '' + match[1]),
1142
- g: parseIntFromHex(match[2] + '' + match[2]),
1143
- b: parseIntFromHex(match[3] + '' + match[3]),
1144
- a: convertHexToDecimal(match[4] + '' + match[4]),
1145
- format: named ? "name" : "hex8"
1146
- };
1147
- }
1148
- if ((match = matchers.hex3.exec(color))) {
1149
- return {
1150
- r: parseIntFromHex(match[1] + '' + match[1]),
1151
- g: parseIntFromHex(match[2] + '' + match[2]),
1152
- b: parseIntFromHex(match[3] + '' + match[3]),
1153
- format: named ? "name" : "hex"
1154
- };
1155
- }
1156
-
1157
- return false;
1158
- }
1159
-
1160
- function validateWCAG2Parms(parms) {
1161
- // return valid WCAG2 parms for isReadable.
1162
- // If input parms are invalid, return {"level":"AA", "size":"small"}
1163
- var level, size;
1164
- parms = parms || {"level":"AA", "size":"small"};
1165
- level = (parms.level || "AA").toUpperCase();
1166
- size = (parms.size || "small").toLowerCase();
1167
- if (level !== "AA" && level !== "AAA") {
1168
- level = "AA";
1169
- }
1170
- if (size !== "small" && size !== "large") {
1171
- size = "small";
1172
- }
1173
- return {"level":level, "size":size};
1174
- }
1175
-
1176
- this.tinycolor = tinycolor;
1177
-
1178
- })()`;
1179
- }
1180
-
1181
- .tinyColorMixin();