bs-widget 1.0.1

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 (3) hide show
  1. package/README.md +99 -0
  2. package/dist/bundle.js +1372 -0
  3. package/package.json +40 -0
package/dist/bundle.js ADDED
@@ -0,0 +1,1372 @@
1
+ var BSWidget = (function () {
2
+ 'use strict';
3
+
4
+ function ownKeys(object, enumerableOnly) {
5
+ var keys = Object.keys(object);
6
+ if (Object.getOwnPropertySymbols) {
7
+ var symbols = Object.getOwnPropertySymbols(object);
8
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
9
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
10
+ })), keys.push.apply(keys, symbols);
11
+ }
12
+ return keys;
13
+ }
14
+ function _objectSpread2(target) {
15
+ for (var i = 1; i < arguments.length; i++) {
16
+ var source = null != arguments[i] ? arguments[i] : {};
17
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
18
+ _defineProperty(target, key, source[key]);
19
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
20
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
21
+ });
22
+ }
23
+ return target;
24
+ }
25
+ function _defineProperty(obj, key, value) {
26
+ key = _toPropertyKey(key);
27
+ if (key in obj) {
28
+ Object.defineProperty(obj, key, {
29
+ value: value,
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ } else {
35
+ obj[key] = value;
36
+ }
37
+ return obj;
38
+ }
39
+ function _toPrimitive(input, hint) {
40
+ if (typeof input !== "object" || input === null) return input;
41
+ var prim = input[Symbol.toPrimitive];
42
+ if (prim !== undefined) {
43
+ var res = prim.call(input, hint || "default");
44
+ if (typeof res !== "object") return res;
45
+ throw new TypeError("@@toPrimitive must return a primitive value.");
46
+ }
47
+ return (hint === "string" ? String : Number)(input);
48
+ }
49
+ function _toPropertyKey(arg) {
50
+ var key = _toPrimitive(arg, "string");
51
+ return typeof key === "symbol" ? key : String(key);
52
+ }
53
+
54
+ // This file is autogenerated. It's used to publish ESM to npm.
55
+ function _typeof(obj) {
56
+ "@babel/helpers - typeof";
57
+
58
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
59
+ return typeof obj;
60
+ } : function (obj) {
61
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
62
+ }, _typeof(obj);
63
+ }
64
+
65
+ // https://github.com/bgrins/TinyColor
66
+ // Brian Grinstead, MIT License
67
+
68
+ var trimLeft = /^\s+/;
69
+ var trimRight = /\s+$/;
70
+ function tinycolor(color, opts) {
71
+ color = color ? color : "";
72
+ opts = opts || {};
73
+
74
+ // If input is already a tinycolor, return itself
75
+ if (color instanceof tinycolor) {
76
+ return color;
77
+ }
78
+ // If we are called as a function, call using new instead
79
+ if (!(this instanceof tinycolor)) {
80
+ return new tinycolor(color, opts);
81
+ }
82
+ var rgb = inputToRGB(color);
83
+ 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;
84
+ this._gradientType = opts.gradientType;
85
+
86
+ // Don't let the range of [0,255] come back in [0,1].
87
+ // Potentially lose a little bit of precision here, but will fix issues where
88
+ // .5 gets interpreted as half of the total, instead of half of 1
89
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
90
+ if (this._r < 1) this._r = Math.round(this._r);
91
+ if (this._g < 1) this._g = Math.round(this._g);
92
+ if (this._b < 1) this._b = Math.round(this._b);
93
+ this._ok = rgb.ok;
94
+ }
95
+ tinycolor.prototype = {
96
+ isDark: function isDark() {
97
+ return this.getBrightness() < 128;
98
+ },
99
+ isLight: function isLight() {
100
+ return !this.isDark();
101
+ },
102
+ isValid: function isValid() {
103
+ return this._ok;
104
+ },
105
+ getOriginalInput: function getOriginalInput() {
106
+ return this._originalInput;
107
+ },
108
+ getFormat: function getFormat() {
109
+ return this._format;
110
+ },
111
+ getAlpha: function getAlpha() {
112
+ return this._a;
113
+ },
114
+ getBrightness: function getBrightness() {
115
+ //http://www.w3.org/TR/AERT#color-contrast
116
+ var rgb = this.toRgb();
117
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
118
+ },
119
+ getLuminance: function getLuminance() {
120
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
121
+ var rgb = this.toRgb();
122
+ var RsRGB, GsRGB, BsRGB, R, G, B;
123
+ RsRGB = rgb.r / 255;
124
+ GsRGB = rgb.g / 255;
125
+ BsRGB = rgb.b / 255;
126
+ if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
127
+ if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
128
+ if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
129
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
130
+ },
131
+ setAlpha: function setAlpha(value) {
132
+ this._a = boundAlpha(value);
133
+ this._roundA = Math.round(100 * this._a) / 100;
134
+ return this;
135
+ },
136
+ toHsv: function toHsv() {
137
+ var hsv = rgbToHsv(this._r, this._g, this._b);
138
+ return {
139
+ h: hsv.h * 360,
140
+ s: hsv.s,
141
+ v: hsv.v,
142
+ a: this._a
143
+ };
144
+ },
145
+ toHsvString: function toHsvString() {
146
+ var hsv = rgbToHsv(this._r, this._g, this._b);
147
+ var h = Math.round(hsv.h * 360),
148
+ s = Math.round(hsv.s * 100),
149
+ v = Math.round(hsv.v * 100);
150
+ return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
151
+ },
152
+ toHsl: function toHsl() {
153
+ var hsl = rgbToHsl(this._r, this._g, this._b);
154
+ return {
155
+ h: hsl.h * 360,
156
+ s: hsl.s,
157
+ l: hsl.l,
158
+ a: this._a
159
+ };
160
+ },
161
+ toHslString: function toHslString() {
162
+ var hsl = rgbToHsl(this._r, this._g, this._b);
163
+ var h = Math.round(hsl.h * 360),
164
+ s = Math.round(hsl.s * 100),
165
+ l = Math.round(hsl.l * 100);
166
+ return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
167
+ },
168
+ toHex: function toHex(allow3Char) {
169
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
170
+ },
171
+ toHexString: function toHexString(allow3Char) {
172
+ return "#" + this.toHex(allow3Char);
173
+ },
174
+ toHex8: function toHex8(allow4Char) {
175
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
176
+ },
177
+ toHex8String: function toHex8String(allow4Char) {
178
+ return "#" + this.toHex8(allow4Char);
179
+ },
180
+ toRgb: function toRgb() {
181
+ return {
182
+ r: Math.round(this._r),
183
+ g: Math.round(this._g),
184
+ b: Math.round(this._b),
185
+ a: this._a
186
+ };
187
+ },
188
+ toRgbString: function toRgbString() {
189
+ 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 + ")";
190
+ },
191
+ toPercentageRgb: function toPercentageRgb() {
192
+ return {
193
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
194
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
195
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
196
+ a: this._a
197
+ };
198
+ },
199
+ toPercentageRgbString: function toPercentageRgbString() {
200
+ 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 + ")";
201
+ },
202
+ toName: function toName() {
203
+ if (this._a === 0) {
204
+ return "transparent";
205
+ }
206
+ if (this._a < 1) {
207
+ return false;
208
+ }
209
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
210
+ },
211
+ toFilter: function toFilter(secondColor) {
212
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
213
+ var secondHex8String = hex8String;
214
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
215
+ if (secondColor) {
216
+ var s = tinycolor(secondColor);
217
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
218
+ }
219
+ return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
220
+ },
221
+ toString: function toString(format) {
222
+ var formatSet = !!format;
223
+ format = format || this._format;
224
+ var formattedString = false;
225
+ var hasAlpha = this._a < 1 && this._a >= 0;
226
+ var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
227
+ if (needsAlphaFormat) {
228
+ // Special case for "transparent", all other non-alpha formats
229
+ // will return rgba when there is transparency.
230
+ if (format === "name" && this._a === 0) {
231
+ return this.toName();
232
+ }
233
+ return this.toRgbString();
234
+ }
235
+ if (format === "rgb") {
236
+ formattedString = this.toRgbString();
237
+ }
238
+ if (format === "prgb") {
239
+ formattedString = this.toPercentageRgbString();
240
+ }
241
+ if (format === "hex" || format === "hex6") {
242
+ formattedString = this.toHexString();
243
+ }
244
+ if (format === "hex3") {
245
+ formattedString = this.toHexString(true);
246
+ }
247
+ if (format === "hex4") {
248
+ formattedString = this.toHex8String(true);
249
+ }
250
+ if (format === "hex8") {
251
+ formattedString = this.toHex8String();
252
+ }
253
+ if (format === "name") {
254
+ formattedString = this.toName();
255
+ }
256
+ if (format === "hsl") {
257
+ formattedString = this.toHslString();
258
+ }
259
+ if (format === "hsv") {
260
+ formattedString = this.toHsvString();
261
+ }
262
+ return formattedString || this.toHexString();
263
+ },
264
+ clone: function clone() {
265
+ return tinycolor(this.toString());
266
+ },
267
+ _applyModification: function _applyModification(fn, args) {
268
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
269
+ this._r = color._r;
270
+ this._g = color._g;
271
+ this._b = color._b;
272
+ this.setAlpha(color._a);
273
+ return this;
274
+ },
275
+ lighten: function lighten() {
276
+ return this._applyModification(_lighten, arguments);
277
+ },
278
+ brighten: function brighten() {
279
+ return this._applyModification(_brighten, arguments);
280
+ },
281
+ darken: function darken() {
282
+ return this._applyModification(_darken, arguments);
283
+ },
284
+ desaturate: function desaturate() {
285
+ return this._applyModification(_desaturate, arguments);
286
+ },
287
+ saturate: function saturate() {
288
+ return this._applyModification(_saturate, arguments);
289
+ },
290
+ greyscale: function greyscale() {
291
+ return this._applyModification(_greyscale, arguments);
292
+ },
293
+ spin: function spin() {
294
+ return this._applyModification(_spin, arguments);
295
+ },
296
+ _applyCombination: function _applyCombination(fn, args) {
297
+ return fn.apply(null, [this].concat([].slice.call(args)));
298
+ },
299
+ analogous: function analogous() {
300
+ return this._applyCombination(_analogous, arguments);
301
+ },
302
+ complement: function complement() {
303
+ return this._applyCombination(_complement, arguments);
304
+ },
305
+ monochromatic: function monochromatic() {
306
+ return this._applyCombination(_monochromatic, arguments);
307
+ },
308
+ splitcomplement: function splitcomplement() {
309
+ return this._applyCombination(_splitcomplement, arguments);
310
+ },
311
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
312
+ // polyad: function (number) {
313
+ // return this._applyCombination(polyad, [number]);
314
+ // },
315
+ triad: function triad() {
316
+ return this._applyCombination(polyad, [3]);
317
+ },
318
+ tetrad: function tetrad() {
319
+ return this._applyCombination(polyad, [4]);
320
+ }
321
+ };
322
+
323
+ // If input is an object, force 1 into "1.0" to handle ratios properly
324
+ // String input requires "1.0" as input, so 1 will be treated as 1
325
+ tinycolor.fromRatio = function (color, opts) {
326
+ if (_typeof(color) == "object") {
327
+ var newColor = {};
328
+ for (var i in color) {
329
+ if (color.hasOwnProperty(i)) {
330
+ if (i === "a") {
331
+ newColor[i] = color[i];
332
+ } else {
333
+ newColor[i] = convertToPercentage(color[i]);
334
+ }
335
+ }
336
+ }
337
+ color = newColor;
338
+ }
339
+ return tinycolor(color, opts);
340
+ };
341
+
342
+ // Given a string or object, convert that input to RGB
343
+ // Possible string inputs:
344
+ //
345
+ // "red"
346
+ // "#f00" or "f00"
347
+ // "#ff0000" or "ff0000"
348
+ // "#ff000000" or "ff000000"
349
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
350
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
351
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
352
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
353
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
354
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
355
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
356
+ //
357
+ function inputToRGB(color) {
358
+ var rgb = {
359
+ r: 0,
360
+ g: 0,
361
+ b: 0
362
+ };
363
+ var a = 1;
364
+ var s = null;
365
+ var v = null;
366
+ var l = null;
367
+ var ok = false;
368
+ var format = false;
369
+ if (typeof color == "string") {
370
+ color = stringInputToObject(color);
371
+ }
372
+ if (_typeof(color) == "object") {
373
+ if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
374
+ rgb = rgbToRgb(color.r, color.g, color.b);
375
+ ok = true;
376
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
377
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
378
+ s = convertToPercentage(color.s);
379
+ v = convertToPercentage(color.v);
380
+ rgb = hsvToRgb(color.h, s, v);
381
+ ok = true;
382
+ format = "hsv";
383
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
384
+ s = convertToPercentage(color.s);
385
+ l = convertToPercentage(color.l);
386
+ rgb = hslToRgb(color.h, s, l);
387
+ ok = true;
388
+ format = "hsl";
389
+ }
390
+ if (color.hasOwnProperty("a")) {
391
+ a = color.a;
392
+ }
393
+ }
394
+ a = boundAlpha(a);
395
+ return {
396
+ ok: ok,
397
+ format: color.format || format,
398
+ r: Math.min(255, Math.max(rgb.r, 0)),
399
+ g: Math.min(255, Math.max(rgb.g, 0)),
400
+ b: Math.min(255, Math.max(rgb.b, 0)),
401
+ a: a
402
+ };
403
+ }
404
+
405
+ // Conversion Functions
406
+ // --------------------
407
+
408
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
409
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
410
+
411
+ // `rgbToRgb`
412
+ // Handle bounds / percentage checking to conform to CSS color spec
413
+ // <http://www.w3.org/TR/css3-color/>
414
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
415
+ // *Returns:* { r, g, b } in [0, 255]
416
+ function rgbToRgb(r, g, b) {
417
+ return {
418
+ r: bound01(r, 255) * 255,
419
+ g: bound01(g, 255) * 255,
420
+ b: bound01(b, 255) * 255
421
+ };
422
+ }
423
+
424
+ // `rgbToHsl`
425
+ // Converts an RGB color value to HSL.
426
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
427
+ // *Returns:* { h, s, l } in [0,1]
428
+ function rgbToHsl(r, g, b) {
429
+ r = bound01(r, 255);
430
+ g = bound01(g, 255);
431
+ b = bound01(b, 255);
432
+ var max = Math.max(r, g, b),
433
+ min = Math.min(r, g, b);
434
+ var h,
435
+ s,
436
+ l = (max + min) / 2;
437
+ if (max == min) {
438
+ h = s = 0; // achromatic
439
+ } else {
440
+ var d = max - min;
441
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
442
+ switch (max) {
443
+ case r:
444
+ h = (g - b) / d + (g < b ? 6 : 0);
445
+ break;
446
+ case g:
447
+ h = (b - r) / d + 2;
448
+ break;
449
+ case b:
450
+ h = (r - g) / d + 4;
451
+ break;
452
+ }
453
+ h /= 6;
454
+ }
455
+ return {
456
+ h: h,
457
+ s: s,
458
+ l: l
459
+ };
460
+ }
461
+
462
+ // `hslToRgb`
463
+ // Converts an HSL color value to RGB.
464
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
465
+ // *Returns:* { r, g, b } in the set [0, 255]
466
+ function hslToRgb(h, s, l) {
467
+ var r, g, b;
468
+ h = bound01(h, 360);
469
+ s = bound01(s, 100);
470
+ l = bound01(l, 100);
471
+ function hue2rgb(p, q, t) {
472
+ if (t < 0) t += 1;
473
+ if (t > 1) t -= 1;
474
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
475
+ if (t < 1 / 2) return q;
476
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
477
+ return p;
478
+ }
479
+ if (s === 0) {
480
+ r = g = b = l; // achromatic
481
+ } else {
482
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
483
+ var p = 2 * l - q;
484
+ r = hue2rgb(p, q, h + 1 / 3);
485
+ g = hue2rgb(p, q, h);
486
+ b = hue2rgb(p, q, h - 1 / 3);
487
+ }
488
+ return {
489
+ r: r * 255,
490
+ g: g * 255,
491
+ b: b * 255
492
+ };
493
+ }
494
+
495
+ // `rgbToHsv`
496
+ // Converts an RGB color value to HSV
497
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
498
+ // *Returns:* { h, s, v } in [0,1]
499
+ function rgbToHsv(r, g, b) {
500
+ r = bound01(r, 255);
501
+ g = bound01(g, 255);
502
+ b = bound01(b, 255);
503
+ var max = Math.max(r, g, b),
504
+ min = Math.min(r, g, b);
505
+ var h,
506
+ s,
507
+ v = max;
508
+ var d = max - min;
509
+ s = max === 0 ? 0 : d / max;
510
+ if (max == min) {
511
+ h = 0; // achromatic
512
+ } else {
513
+ switch (max) {
514
+ case r:
515
+ h = (g - b) / d + (g < b ? 6 : 0);
516
+ break;
517
+ case g:
518
+ h = (b - r) / d + 2;
519
+ break;
520
+ case b:
521
+ h = (r - g) / d + 4;
522
+ break;
523
+ }
524
+ h /= 6;
525
+ }
526
+ return {
527
+ h: h,
528
+ s: s,
529
+ v: v
530
+ };
531
+ }
532
+
533
+ // `hsvToRgb`
534
+ // Converts an HSV color value to RGB.
535
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
536
+ // *Returns:* { r, g, b } in the set [0, 255]
537
+ function hsvToRgb(h, s, v) {
538
+ h = bound01(h, 360) * 6;
539
+ s = bound01(s, 100);
540
+ v = bound01(v, 100);
541
+ var i = Math.floor(h),
542
+ f = h - i,
543
+ p = v * (1 - s),
544
+ q = v * (1 - f * s),
545
+ t = v * (1 - (1 - f) * s),
546
+ mod = i % 6,
547
+ r = [v, q, p, p, t, v][mod],
548
+ g = [t, v, v, q, p, p][mod],
549
+ b = [p, p, t, v, v, q][mod];
550
+ return {
551
+ r: r * 255,
552
+ g: g * 255,
553
+ b: b * 255
554
+ };
555
+ }
556
+
557
+ // `rgbToHex`
558
+ // Converts an RGB color to hex
559
+ // Assumes r, g, and b are contained in the set [0, 255]
560
+ // Returns a 3 or 6 character hex
561
+ function rgbToHex(r, g, b, allow3Char) {
562
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
563
+
564
+ // Return a 3 character hex if possible
565
+ 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)) {
566
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
567
+ }
568
+ return hex.join("");
569
+ }
570
+
571
+ // `rgbaToHex`
572
+ // Converts an RGBA color plus alpha transparency to hex
573
+ // Assumes r, g, b are contained in the set [0, 255] and
574
+ // a in [0, 1]. Returns a 4 or 8 character rgba hex
575
+ function rgbaToHex(r, g, b, a, allow4Char) {
576
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
577
+
578
+ // Return a 4 character hex if possible
579
+ 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)) {
580
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
581
+ }
582
+ return hex.join("");
583
+ }
584
+
585
+ // `rgbaToArgbHex`
586
+ // Converts an RGBA color to an ARGB Hex8 string
587
+ // Rarely used, but required for "toFilter()"
588
+ function rgbaToArgbHex(r, g, b, a) {
589
+ var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
590
+ return hex.join("");
591
+ }
592
+
593
+ // `equals`
594
+ // Can be called with any tinycolor input
595
+ tinycolor.equals = function (color1, color2) {
596
+ if (!color1 || !color2) return false;
597
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
598
+ };
599
+ tinycolor.random = function () {
600
+ return tinycolor.fromRatio({
601
+ r: Math.random(),
602
+ g: Math.random(),
603
+ b: Math.random()
604
+ });
605
+ };
606
+
607
+ // Modification Functions
608
+ // ----------------------
609
+ // Thanks to less.js for some of the basics here
610
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
611
+
612
+ function _desaturate(color, amount) {
613
+ amount = amount === 0 ? 0 : amount || 10;
614
+ var hsl = tinycolor(color).toHsl();
615
+ hsl.s -= amount / 100;
616
+ hsl.s = clamp01(hsl.s);
617
+ return tinycolor(hsl);
618
+ }
619
+ function _saturate(color, amount) {
620
+ amount = amount === 0 ? 0 : amount || 10;
621
+ var hsl = tinycolor(color).toHsl();
622
+ hsl.s += amount / 100;
623
+ hsl.s = clamp01(hsl.s);
624
+ return tinycolor(hsl);
625
+ }
626
+ function _greyscale(color) {
627
+ return tinycolor(color).desaturate(100);
628
+ }
629
+ function _lighten(color, amount) {
630
+ amount = amount === 0 ? 0 : amount || 10;
631
+ var hsl = tinycolor(color).toHsl();
632
+ hsl.l += amount / 100;
633
+ hsl.l = clamp01(hsl.l);
634
+ return tinycolor(hsl);
635
+ }
636
+ function _brighten(color, amount) {
637
+ amount = amount === 0 ? 0 : amount || 10;
638
+ var rgb = tinycolor(color).toRgb();
639
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
640
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
641
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
642
+ return tinycolor(rgb);
643
+ }
644
+ function _darken(color, amount) {
645
+ amount = amount === 0 ? 0 : amount || 10;
646
+ var hsl = tinycolor(color).toHsl();
647
+ hsl.l -= amount / 100;
648
+ hsl.l = clamp01(hsl.l);
649
+ return tinycolor(hsl);
650
+ }
651
+
652
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
653
+ // Values outside of this range will be wrapped into this range.
654
+ function _spin(color, amount) {
655
+ var hsl = tinycolor(color).toHsl();
656
+ var hue = (hsl.h + amount) % 360;
657
+ hsl.h = hue < 0 ? 360 + hue : hue;
658
+ return tinycolor(hsl);
659
+ }
660
+
661
+ // Combination Functions
662
+ // ---------------------
663
+ // Thanks to jQuery xColor for some of the ideas behind these
664
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
665
+
666
+ function _complement(color) {
667
+ var hsl = tinycolor(color).toHsl();
668
+ hsl.h = (hsl.h + 180) % 360;
669
+ return tinycolor(hsl);
670
+ }
671
+ function polyad(color, number) {
672
+ if (isNaN(number) || number <= 0) {
673
+ throw new Error("Argument to polyad must be a positive number");
674
+ }
675
+ var hsl = tinycolor(color).toHsl();
676
+ var result = [tinycolor(color)];
677
+ var step = 360 / number;
678
+ for (var i = 1; i < number; i++) {
679
+ result.push(tinycolor({
680
+ h: (hsl.h + i * step) % 360,
681
+ s: hsl.s,
682
+ l: hsl.l
683
+ }));
684
+ }
685
+ return result;
686
+ }
687
+ function _splitcomplement(color) {
688
+ var hsl = tinycolor(color).toHsl();
689
+ var h = hsl.h;
690
+ return [tinycolor(color), tinycolor({
691
+ h: (h + 72) % 360,
692
+ s: hsl.s,
693
+ l: hsl.l
694
+ }), tinycolor({
695
+ h: (h + 216) % 360,
696
+ s: hsl.s,
697
+ l: hsl.l
698
+ })];
699
+ }
700
+ function _analogous(color, results, slices) {
701
+ results = results || 6;
702
+ slices = slices || 30;
703
+ var hsl = tinycolor(color).toHsl();
704
+ var part = 360 / slices;
705
+ var ret = [tinycolor(color)];
706
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
707
+ hsl.h = (hsl.h + part) % 360;
708
+ ret.push(tinycolor(hsl));
709
+ }
710
+ return ret;
711
+ }
712
+ function _monochromatic(color, results) {
713
+ results = results || 6;
714
+ var hsv = tinycolor(color).toHsv();
715
+ var h = hsv.h,
716
+ s = hsv.s,
717
+ v = hsv.v;
718
+ var ret = [];
719
+ var modification = 1 / results;
720
+ while (results--) {
721
+ ret.push(tinycolor({
722
+ h: h,
723
+ s: s,
724
+ v: v
725
+ }));
726
+ v = (v + modification) % 1;
727
+ }
728
+ return ret;
729
+ }
730
+
731
+ // Utility Functions
732
+ // ---------------------
733
+
734
+ tinycolor.mix = function (color1, color2, amount) {
735
+ amount = amount === 0 ? 0 : amount || 50;
736
+ var rgb1 = tinycolor(color1).toRgb();
737
+ var rgb2 = tinycolor(color2).toRgb();
738
+ var p = amount / 100;
739
+ var rgba = {
740
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
741
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
742
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
743
+ a: (rgb2.a - rgb1.a) * p + rgb1.a
744
+ };
745
+ return tinycolor(rgba);
746
+ };
747
+
748
+ // Readability Functions
749
+ // ---------------------
750
+ // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
751
+
752
+ // `contrast`
753
+ // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
754
+ tinycolor.readability = function (color1, color2) {
755
+ var c1 = tinycolor(color1);
756
+ var c2 = tinycolor(color2);
757
+ return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
758
+ };
759
+
760
+ // `isReadable`
761
+ // Ensure that foreground and background color combinations meet WCAG2 guidelines.
762
+ // The third argument is an optional Object.
763
+ // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
764
+ // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
765
+ // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
766
+
767
+ // *Example*
768
+ // tinycolor.isReadable("#000", "#111") => false
769
+ // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
770
+ tinycolor.isReadable = function (color1, color2, wcag2) {
771
+ var readability = tinycolor.readability(color1, color2);
772
+ var wcag2Parms, out;
773
+ out = false;
774
+ wcag2Parms = validateWCAG2Parms(wcag2);
775
+ switch (wcag2Parms.level + wcag2Parms.size) {
776
+ case "AAsmall":
777
+ case "AAAlarge":
778
+ out = readability >= 4.5;
779
+ break;
780
+ case "AAlarge":
781
+ out = readability >= 3;
782
+ break;
783
+ case "AAAsmall":
784
+ out = readability >= 7;
785
+ break;
786
+ }
787
+ return out;
788
+ };
789
+
790
+ // `mostReadable`
791
+ // Given a base color and a list of possible foreground or background
792
+ // colors for that base, returns the most readable color.
793
+ // Optionally returns Black or White if the most readable color is unreadable.
794
+ // *Example*
795
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
796
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
797
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
798
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
799
+ tinycolor.mostReadable = function (baseColor, colorList, args) {
800
+ var bestColor = null;
801
+ var bestScore = 0;
802
+ var readability;
803
+ var includeFallbackColors, level, size;
804
+ args = args || {};
805
+ includeFallbackColors = args.includeFallbackColors;
806
+ level = args.level;
807
+ size = args.size;
808
+ for (var i = 0; i < colorList.length; i++) {
809
+ readability = tinycolor.readability(baseColor, colorList[i]);
810
+ if (readability > bestScore) {
811
+ bestScore = readability;
812
+ bestColor = tinycolor(colorList[i]);
813
+ }
814
+ }
815
+ if (tinycolor.isReadable(baseColor, bestColor, {
816
+ level: level,
817
+ size: size
818
+ }) || !includeFallbackColors) {
819
+ return bestColor;
820
+ } else {
821
+ args.includeFallbackColors = false;
822
+ return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
823
+ }
824
+ };
825
+
826
+ // Big List of Colors
827
+ // ------------------
828
+ // <https://www.w3.org/TR/css-color-4/#named-colors>
829
+ var names = tinycolor.names = {
830
+ aliceblue: "f0f8ff",
831
+ antiquewhite: "faebd7",
832
+ aqua: "0ff",
833
+ aquamarine: "7fffd4",
834
+ azure: "f0ffff",
835
+ beige: "f5f5dc",
836
+ bisque: "ffe4c4",
837
+ black: "000",
838
+ blanchedalmond: "ffebcd",
839
+ blue: "00f",
840
+ blueviolet: "8a2be2",
841
+ brown: "a52a2a",
842
+ burlywood: "deb887",
843
+ burntsienna: "ea7e5d",
844
+ cadetblue: "5f9ea0",
845
+ chartreuse: "7fff00",
846
+ chocolate: "d2691e",
847
+ coral: "ff7f50",
848
+ cornflowerblue: "6495ed",
849
+ cornsilk: "fff8dc",
850
+ crimson: "dc143c",
851
+ cyan: "0ff",
852
+ darkblue: "00008b",
853
+ darkcyan: "008b8b",
854
+ darkgoldenrod: "b8860b",
855
+ darkgray: "a9a9a9",
856
+ darkgreen: "006400",
857
+ darkgrey: "a9a9a9",
858
+ darkkhaki: "bdb76b",
859
+ darkmagenta: "8b008b",
860
+ darkolivegreen: "556b2f",
861
+ darkorange: "ff8c00",
862
+ darkorchid: "9932cc",
863
+ darkred: "8b0000",
864
+ darksalmon: "e9967a",
865
+ darkseagreen: "8fbc8f",
866
+ darkslateblue: "483d8b",
867
+ darkslategray: "2f4f4f",
868
+ darkslategrey: "2f4f4f",
869
+ darkturquoise: "00ced1",
870
+ darkviolet: "9400d3",
871
+ deeppink: "ff1493",
872
+ deepskyblue: "00bfff",
873
+ dimgray: "696969",
874
+ dimgrey: "696969",
875
+ dodgerblue: "1e90ff",
876
+ firebrick: "b22222",
877
+ floralwhite: "fffaf0",
878
+ forestgreen: "228b22",
879
+ fuchsia: "f0f",
880
+ gainsboro: "dcdcdc",
881
+ ghostwhite: "f8f8ff",
882
+ gold: "ffd700",
883
+ goldenrod: "daa520",
884
+ gray: "808080",
885
+ green: "008000",
886
+ greenyellow: "adff2f",
887
+ grey: "808080",
888
+ honeydew: "f0fff0",
889
+ hotpink: "ff69b4",
890
+ indianred: "cd5c5c",
891
+ indigo: "4b0082",
892
+ ivory: "fffff0",
893
+ khaki: "f0e68c",
894
+ lavender: "e6e6fa",
895
+ lavenderblush: "fff0f5",
896
+ lawngreen: "7cfc00",
897
+ lemonchiffon: "fffacd",
898
+ lightblue: "add8e6",
899
+ lightcoral: "f08080",
900
+ lightcyan: "e0ffff",
901
+ lightgoldenrodyellow: "fafad2",
902
+ lightgray: "d3d3d3",
903
+ lightgreen: "90ee90",
904
+ lightgrey: "d3d3d3",
905
+ lightpink: "ffb6c1",
906
+ lightsalmon: "ffa07a",
907
+ lightseagreen: "20b2aa",
908
+ lightskyblue: "87cefa",
909
+ lightslategray: "789",
910
+ lightslategrey: "789",
911
+ lightsteelblue: "b0c4de",
912
+ lightyellow: "ffffe0",
913
+ lime: "0f0",
914
+ limegreen: "32cd32",
915
+ linen: "faf0e6",
916
+ magenta: "f0f",
917
+ maroon: "800000",
918
+ mediumaquamarine: "66cdaa",
919
+ mediumblue: "0000cd",
920
+ mediumorchid: "ba55d3",
921
+ mediumpurple: "9370db",
922
+ mediumseagreen: "3cb371",
923
+ mediumslateblue: "7b68ee",
924
+ mediumspringgreen: "00fa9a",
925
+ mediumturquoise: "48d1cc",
926
+ mediumvioletred: "c71585",
927
+ midnightblue: "191970",
928
+ mintcream: "f5fffa",
929
+ mistyrose: "ffe4e1",
930
+ moccasin: "ffe4b5",
931
+ navajowhite: "ffdead",
932
+ navy: "000080",
933
+ oldlace: "fdf5e6",
934
+ olive: "808000",
935
+ olivedrab: "6b8e23",
936
+ orange: "ffa500",
937
+ orangered: "ff4500",
938
+ orchid: "da70d6",
939
+ palegoldenrod: "eee8aa",
940
+ palegreen: "98fb98",
941
+ paleturquoise: "afeeee",
942
+ palevioletred: "db7093",
943
+ papayawhip: "ffefd5",
944
+ peachpuff: "ffdab9",
945
+ peru: "cd853f",
946
+ pink: "ffc0cb",
947
+ plum: "dda0dd",
948
+ powderblue: "b0e0e6",
949
+ purple: "800080",
950
+ rebeccapurple: "663399",
951
+ red: "f00",
952
+ rosybrown: "bc8f8f",
953
+ royalblue: "4169e1",
954
+ saddlebrown: "8b4513",
955
+ salmon: "fa8072",
956
+ sandybrown: "f4a460",
957
+ seagreen: "2e8b57",
958
+ seashell: "fff5ee",
959
+ sienna: "a0522d",
960
+ silver: "c0c0c0",
961
+ skyblue: "87ceeb",
962
+ slateblue: "6a5acd",
963
+ slategray: "708090",
964
+ slategrey: "708090",
965
+ snow: "fffafa",
966
+ springgreen: "00ff7f",
967
+ steelblue: "4682b4",
968
+ tan: "d2b48c",
969
+ teal: "008080",
970
+ thistle: "d8bfd8",
971
+ tomato: "ff6347",
972
+ turquoise: "40e0d0",
973
+ violet: "ee82ee",
974
+ wheat: "f5deb3",
975
+ white: "fff",
976
+ whitesmoke: "f5f5f5",
977
+ yellow: "ff0",
978
+ yellowgreen: "9acd32"
979
+ };
980
+
981
+ // Make it easy to access colors via `hexNames[hex]`
982
+ var hexNames = tinycolor.hexNames = flip(names);
983
+
984
+ // Utilities
985
+ // ---------
986
+
987
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
988
+ function flip(o) {
989
+ var flipped = {};
990
+ for (var i in o) {
991
+ if (o.hasOwnProperty(i)) {
992
+ flipped[o[i]] = i;
993
+ }
994
+ }
995
+ return flipped;
996
+ }
997
+
998
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
999
+ function boundAlpha(a) {
1000
+ a = parseFloat(a);
1001
+ if (isNaN(a) || a < 0 || a > 1) {
1002
+ a = 1;
1003
+ }
1004
+ return a;
1005
+ }
1006
+
1007
+ // Take input from [0, n] and return it as [0, 1]
1008
+ function bound01(n, max) {
1009
+ if (isOnePointZero(n)) n = "100%";
1010
+ var processPercent = isPercentage(n);
1011
+ n = Math.min(max, Math.max(0, parseFloat(n)));
1012
+
1013
+ // Automatically convert percentage into number
1014
+ if (processPercent) {
1015
+ n = parseInt(n * max, 10) / 100;
1016
+ }
1017
+
1018
+ // Handle floating point rounding errors
1019
+ if (Math.abs(n - max) < 0.000001) {
1020
+ return 1;
1021
+ }
1022
+
1023
+ // Convert into [0, 1] range if it isn't already
1024
+ return n % max / parseFloat(max);
1025
+ }
1026
+
1027
+ // Force a number between 0 and 1
1028
+ function clamp01(val) {
1029
+ return Math.min(1, Math.max(0, val));
1030
+ }
1031
+
1032
+ // Parse a base-16 hex value into a base-10 integer
1033
+ function parseIntFromHex(val) {
1034
+ return parseInt(val, 16);
1035
+ }
1036
+
1037
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
1038
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
1039
+ function isOnePointZero(n) {
1040
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
1041
+ }
1042
+
1043
+ // Check to see if string passed in is a percentage
1044
+ function isPercentage(n) {
1045
+ return typeof n === "string" && n.indexOf("%") != -1;
1046
+ }
1047
+
1048
+ // Force a hex value to have 2 characters
1049
+ function pad2(c) {
1050
+ return c.length == 1 ? "0" + c : "" + c;
1051
+ }
1052
+
1053
+ // Replace a decimal with it's percentage value
1054
+ function convertToPercentage(n) {
1055
+ if (n <= 1) {
1056
+ n = n * 100 + "%";
1057
+ }
1058
+ return n;
1059
+ }
1060
+
1061
+ // Converts a decimal to a hex value
1062
+ function convertDecimalToHex(d) {
1063
+ return Math.round(parseFloat(d) * 255).toString(16);
1064
+ }
1065
+ // Converts a hex value to a decimal
1066
+ function convertHexToDecimal(h) {
1067
+ return parseIntFromHex(h) / 255;
1068
+ }
1069
+ var matchers = function () {
1070
+ // <http://www.w3.org/TR/css3-values/#integers>
1071
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
1072
+
1073
+ // <http://www.w3.org/TR/css3-values/#number-value>
1074
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
1075
+
1076
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
1077
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
1078
+
1079
+ // Actual matching.
1080
+ // Parentheses and commas are optional, but not required.
1081
+ // Whitespace can take the place of commas or opening paren
1082
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1083
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1084
+ return {
1085
+ CSS_UNIT: new RegExp(CSS_UNIT),
1086
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
1087
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
1088
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
1089
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
1090
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
1091
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
1092
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1093
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1094
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1095
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1096
+ };
1097
+ }();
1098
+
1099
+ // `isValidCSSUnit`
1100
+ // Take in a single string / number and check to see if it looks like a CSS unit
1101
+ // (see `matchers` above for definition).
1102
+ function isValidCSSUnit(color) {
1103
+ return !!matchers.CSS_UNIT.exec(color);
1104
+ }
1105
+
1106
+ // `stringInputToObject`
1107
+ // Permissive string parsing. Take in a number of formats, and output an object
1108
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
1109
+ function stringInputToObject(color) {
1110
+ color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
1111
+ var named = false;
1112
+ if (names[color]) {
1113
+ color = names[color];
1114
+ named = true;
1115
+ } else if (color == "transparent") {
1116
+ return {
1117
+ r: 0,
1118
+ g: 0,
1119
+ b: 0,
1120
+ a: 0,
1121
+ format: "name"
1122
+ };
1123
+ }
1124
+
1125
+ // Try to match string input using regular expressions.
1126
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1127
+ // Just return an object and let the conversion functions handle that.
1128
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
1129
+ var match;
1130
+ if (match = matchers.rgb.exec(color)) {
1131
+ return {
1132
+ r: match[1],
1133
+ g: match[2],
1134
+ b: match[3]
1135
+ };
1136
+ }
1137
+ if (match = matchers.rgba.exec(color)) {
1138
+ return {
1139
+ r: match[1],
1140
+ g: match[2],
1141
+ b: match[3],
1142
+ a: match[4]
1143
+ };
1144
+ }
1145
+ if (match = matchers.hsl.exec(color)) {
1146
+ return {
1147
+ h: match[1],
1148
+ s: match[2],
1149
+ l: match[3]
1150
+ };
1151
+ }
1152
+ if (match = matchers.hsla.exec(color)) {
1153
+ return {
1154
+ h: match[1],
1155
+ s: match[2],
1156
+ l: match[3],
1157
+ a: match[4]
1158
+ };
1159
+ }
1160
+ if (match = matchers.hsv.exec(color)) {
1161
+ return {
1162
+ h: match[1],
1163
+ s: match[2],
1164
+ v: match[3]
1165
+ };
1166
+ }
1167
+ if (match = matchers.hsva.exec(color)) {
1168
+ return {
1169
+ h: match[1],
1170
+ s: match[2],
1171
+ v: match[3],
1172
+ a: match[4]
1173
+ };
1174
+ }
1175
+ if (match = matchers.hex8.exec(color)) {
1176
+ return {
1177
+ r: parseIntFromHex(match[1]),
1178
+ g: parseIntFromHex(match[2]),
1179
+ b: parseIntFromHex(match[3]),
1180
+ a: convertHexToDecimal(match[4]),
1181
+ format: named ? "name" : "hex8"
1182
+ };
1183
+ }
1184
+ if (match = matchers.hex6.exec(color)) {
1185
+ return {
1186
+ r: parseIntFromHex(match[1]),
1187
+ g: parseIntFromHex(match[2]),
1188
+ b: parseIntFromHex(match[3]),
1189
+ format: named ? "name" : "hex"
1190
+ };
1191
+ }
1192
+ if (match = matchers.hex4.exec(color)) {
1193
+ return {
1194
+ r: parseIntFromHex(match[1] + "" + match[1]),
1195
+ g: parseIntFromHex(match[2] + "" + match[2]),
1196
+ b: parseIntFromHex(match[3] + "" + match[3]),
1197
+ a: convertHexToDecimal(match[4] + "" + match[4]),
1198
+ format: named ? "name" : "hex8"
1199
+ };
1200
+ }
1201
+ if (match = matchers.hex3.exec(color)) {
1202
+ return {
1203
+ r: parseIntFromHex(match[1] + "" + match[1]),
1204
+ g: parseIntFromHex(match[2] + "" + match[2]),
1205
+ b: parseIntFromHex(match[3] + "" + match[3]),
1206
+ format: named ? "name" : "hex"
1207
+ };
1208
+ }
1209
+ return false;
1210
+ }
1211
+ function validateWCAG2Parms(parms) {
1212
+ // return valid WCAG2 parms for isReadable.
1213
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
1214
+ var level, size;
1215
+ parms = parms || {
1216
+ level: "AA",
1217
+ size: "small"
1218
+ };
1219
+ level = (parms.level || "AA").toUpperCase();
1220
+ size = (parms.size || "small").toLowerCase();
1221
+ if (level !== "AA" && level !== "AAA") {
1222
+ level = "AA";
1223
+ }
1224
+ if (size !== "small" && size !== "large") {
1225
+ size = "small";
1226
+ }
1227
+ return {
1228
+ level: level,
1229
+ size: size
1230
+ };
1231
+ }
1232
+
1233
+ function BSWidget(options) {
1234
+ var _this = this;
1235
+ var cors = "https://beanstack-cors-anywhere.herokuapp.com/";
1236
+ var api = "https://beanstackedu.beanstack.com/api/v2/microsites_group_statistics/";
1237
+ var defaults = {
1238
+ microsite: 6,
1239
+ container: "#bs-widget",
1240
+ color: "#2323FA",
1241
+ styled: true
1242
+ };
1243
+ var heart = '<svg width="20" height="29" viewBox="0 0 20 29" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.10466 9.60099C-1.42936 13.4764 0.777223 19.0596 14.6388 28.4978C14.9823 28.7315 15.4783 28.6482 15.153 28.0563L15.0603 27.8838C14.1577 26.1622 13.1114 22.8931 15.6222 18.7861L15.8194 18.4598C19.007 13.1288 22.0554 5.13492 17.2642 1.50079C12.3347 -2.23819 6.60583 2.63878 6.46388 8.35695L6.3637 8.29836C5.80513 7.98761 3.03132 6.65437 1.10466 9.60099Z"/></svg>';
1244
+ var clock = '<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10 2.16667C5.3975 2.16667 1.66666 5.89751 1.66666 10.5C1.66666 15.1025 5.3975 18.8333 10 18.8333C14.6025 18.8333 18.3333 15.1025 18.3333 10.5C18.3333 5.89751 14.6025 2.16667 10 2.16667ZM12.155 13.8333L9.41083 11.0892C9.25416 10.9325 9.16666 10.7208 9.16666 10.5V6.33334C9.16666 5.87334 9.54 5.50001 10 5.50001C10.46 5.50001 10.8333 5.87334 10.8333 6.33334V10.155L13.3333 12.655C13.6583 12.98 13.6583 13.5083 13.3333 13.8333C13.0083 14.1583 12.48 14.1583 12.155 13.8333Z"/></svg>';
1245
+ var styles = "#bs-widget,.bs-widget-container{display:-webkit-box;display:-ms-flexbox;-webkit-box-orient:vertical;-webkit-box-direction:normal}#bs-widget,.bs-widget-container,.bs-widget-title-row{-webkit-box-direction:normal}#bs-widget{display:flex;-ms-flex-direction:column;flex-direction:column;width:100%;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:24px;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;font-family:Arial,sans-serif;font-style:normal;--bs-color:red;--bs-light:red;--bs-dark:red}.bs-widget-container{-webkit-box-sizing:border-box;box-sizing:border-box;display:flex;-ms-flex-direction:column;flex-direction:column;-webkit-box-align:start;-ms-flex-align:start;align-items:flex-start;padding:32px;gap:28px;position:relative;width:500px;background:#fff;border:2px solid #eaeaea;border-radius:16px}.bs-widget-title-row{width:100%;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-ms-flex-direction:row;flex-direction:row;-webkit-box-pack:justify;-ms-flex-pack:justify;justify-content:space-between;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:4px}.bs-widget-title-row .bs-widget-title-container{display:-webkit-box;display:-ms-flexbox;display:flex;gap:12px;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:start;-ms-flex-pack:start;justify-content:flex-start}.bs-widget-goal-row,.bs-widget-title-row .bs-widget-endson-container{display:-webkit-box;display:-ms-flexbox;-webkit-box-direction:normal}.bs-widget-title-row .bs-widget-endson-container .bs-widget-clock svg,.bs-widget-title-row .bs-widget-title-container .bs-widget-heart svg{fill:var(--bs-color)}.bs-widget-title-row .bs-widget-title-container .bs-widget-title{font-weight:700;font-size:20px;line-height:25px;color:var(--bs-color)}.bs-widget-title-row .bs-widget-endson-container{display:flex;-webkit-box-orient:horizontal;-ms-flex-direction:row;flex-direction:row;gap:8px;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end}.bs-widget-title-row .bs-widget-endson-container .bs-widget-endson{font-weight:700;font-size:15px;line-height:20px;text-align:right;color:#656565;position:relative;top:-1px}.bs-widget-goal-row{width:100%;display:flex;-webkit-box-orient:vertical;-ms-flex-direction:column;flex-direction:column;gap:12px}.bs-widget-goal-row .bs-widget-goal-text{color:#656565}.bs-widget-goal-row .bs-widget-goal-text strong{font-weight:700;font-size:30px;line-height:34px;color:var(--bs-color)}.bs-widget-goal-row .bs-widget-goal-text span{font-weight:700;font-size:16px}@media screen and (max-width:350px){.bs-widget-title-row .bs-widget-title-container .bs-widget-heart svg{width:12px;height:22px}.bs-widget-title-row .bs-widget-title-container .bs-widget-title{font-size:18px;line-height:22px}.bs-widget-title-row .bs-widget-endson-container .bs-widget-clock{display:none}.bs-widget-title-row .bs-widget-endson-container .bs-widget-endson{font-size:14px;line-height:18px}.bs-widget-goal-row .bs-widget-goal-text{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;gap:2px}.bs-widget-goal-row .bs-widget-goal-text strong{font-size:24px;line-height:30px}.bs-widget-goal-row .bs-widget-goal-text span{font-size:15px;line-height:18px}}.bs-widget-goal-row .bs-widget-goal{margin-top:4px}.bs-widget-goal-row .bs-widget-goal .bs-widget-goal-bar{height:8px;width:100%;background:var(--bs-light);border-radius:8px;position:relative}.bs-widget-goal-row .bs-widget-goal .bs-widget-goal-progress{background:var(--bs-color);border-radius:8px;height:100%;}.bs-widget-goal-row .bs-widget-goal .bs-widget-goal-indicator{width:8px;height:8px;background:#fff;border:4px solid var(--bs-color);-webkit-box-shadow:0 0 0 4px #fff;box-shadow:0 0 0 4px #fff;border-radius:100%;position:absolute;margin-left:-4px;left:0px;top:0;margin-top:-4px}.bs-widget-last-updated-row{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;width:100%;gap:8px}.bs-widget-last-updated-row .bs-widget-last-updated{font-weight:400;font-size:14px;line-height:18px;color:#707070}.bs-widget-last-updated-row a.bs-widget-visit{font-weight:400;font-size:14px;line-height:18px;text-align:center;-webkit-text-decoration-line:underline;text-decoration-line:underline;color:var(--bs-dark)}@media screen and (max-width:450px){.bs-widget-title-row{-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:start;-ms-flex-pack:start;justify-content:flex-start;-webkit-box-align:start;-ms-flex-align:start;align-items:flex-start}.bs-widget-last-updated-row{-webkit-box-align:start;-ms-flex-align:start;align-items:flex-start}.bs-widget-last-updated-row .bs-widget-last-updated,.bs-widget-last-updated-row a.bs-widget-visit{font-size:13px;line-height:16px}}";
1246
+ options = _objectSpread2(_objectSpread2({}, defaults), options);
1247
+ this.loadRequest = function () {
1248
+ var req = new XMLHttpRequest();
1249
+ req.onreadystatechange = function () {
1250
+ if (this.readyState === 4 && this.status === 200) {
1251
+ var data = JSON.parse(this.responseText);
1252
+ _this.init(data.statistic);
1253
+ } else if (this.readyState === 4 && this.status != 200) {
1254
+ _this.error(this.status);
1255
+ }
1256
+ };
1257
+ req.open("GET", cors + api + options.microsite);
1258
+ req.setRequestHeader("Content-Type", "application/json");
1259
+ req.setRequestHeader("Accept", "application/json");
1260
+ req.send();
1261
+ };
1262
+ this.init = function (data) {
1263
+ var endDate = new Date(data.end_date).toLocaleDateString("en-us", {
1264
+ year: "numeric",
1265
+ day: "numeric",
1266
+ month: "short"
1267
+ });
1268
+ var updatedDate = new Date(data.updated_at).toLocaleDateString("en-us", {
1269
+ hour: "2-digit",
1270
+ minute: "2-digit",
1271
+ month: "short",
1272
+ day: "numeric",
1273
+ year: "numeric"
1274
+ });
1275
+ var goalBarPercentage = data.total / data.goal >= 1 ? "100%" : Math.ceil(data.total / data.goal * 100).toString() + "%";
1276
+ var container = document.createElement("div");
1277
+ container.setAttribute("class", "bs-widget-container");
1278
+ container.style.setProperty("--bs-color", tinycolor(options.color).toHexString());
1279
+ container.style.setProperty("--bs-dark", tinycolor(options.color).darken().toHexString());
1280
+ container.style.setProperty("--bs-light", tinycolor(options.color).lighten(30).toHexString());
1281
+ var style = document.createElement("style");
1282
+ if (options.styled == true) {
1283
+ style.innerHTML = styles;
1284
+ }
1285
+ container.appendChild(style);
1286
+ var titleRow = document.createElement("div");
1287
+ titleRow.setAttribute("class", "bs-widget-title-row");
1288
+ container.appendChild(titleRow);
1289
+ var titleContainer = document.createElement("div");
1290
+ titleContainer.setAttribute("class", "bs-widget-title-container");
1291
+ titleRow.appendChild(titleContainer);
1292
+ var titleHeart = document.createElement("div");
1293
+ titleHeart.setAttribute("class", "bs-widget-heart");
1294
+ titleHeart.innerHTML = heart;
1295
+ titleContainer.appendChild(titleHeart);
1296
+ var titleText = document.createElement("div");
1297
+ titleText.setAttribute("class", "bs-widget-title");
1298
+ titleText.innerHTML = "Our Goal";
1299
+ titleContainer.appendChild(titleText);
1300
+ var endsContainer = document.createElement("div");
1301
+ endsContainer.setAttribute("class", "bs-widget-endson-container");
1302
+ titleRow.appendChild(endsContainer);
1303
+ var endsClock = document.createElement("div");
1304
+ endsClock.setAttribute("class", "bs-widget-clock");
1305
+ endsClock.innerHTML = clock;
1306
+ endsContainer.appendChild(endsClock);
1307
+ var endsText = document.createElement("div");
1308
+ endsText.setAttribute("class", "bs-widget-endson");
1309
+ endsText.innerHTML = "Ends on " + endDate;
1310
+ endsContainer.appendChild(endsText); // FORMAT DATE
1311
+
1312
+ var goalRow = document.createElement("div");
1313
+ goalRow.setAttribute("class", "bs-widget-goal-row");
1314
+ container.appendChild(goalRow);
1315
+ var goalText = document.createElement("div");
1316
+ goalText.setAttribute("class", "bs-widget-goal-text");
1317
+ goalRow.appendChild(goalText);
1318
+ var goalStrong = document.createElement("strong");
1319
+ goalStrong.innerHTML = data.total.toLocaleString("en-US"); // FORMAT
1320
+ goalText.appendChild(goalStrong);
1321
+ var goalSpan = document.createElement("span");
1322
+ goalSpan.innerHTML = " / " + data.goal.toLocaleString("en-US"); // FORMAT
1323
+ goalText.appendChild(goalSpan);
1324
+ var goalContainer = document.createElement("div");
1325
+ goalContainer.setAttribute("class", "bs-widget-goal");
1326
+ goalRow.appendChild(goalContainer);
1327
+ var goalBar = document.createElement("div");
1328
+ goalBar.setAttribute("class", "bs-widget-goal-bar");
1329
+ goalContainer.appendChild(goalBar);
1330
+ var goalProgress = document.createElement("div");
1331
+ goalProgress.setAttribute("class", "bs-widget-goal-progress");
1332
+ goalProgress.style.width = goalBarPercentage;
1333
+ goalBar.appendChild(goalProgress);
1334
+ var goalIndicator = document.createElement("div");
1335
+ goalIndicator.setAttribute("class", "bs-widget-goal-indicator");
1336
+ goalIndicator.style.left = goalBarPercentage;
1337
+ goalBar.appendChild(goalIndicator);
1338
+ var lastUpdatedRow = document.createElement("div");
1339
+ lastUpdatedRow.setAttribute("class", "bs-widget-last-updated-row");
1340
+ container.appendChild(lastUpdatedRow);
1341
+ var lastUpdated = document.createElement("div");
1342
+ lastUpdated.setAttribute("class", "bs-widget-last-updated");
1343
+ lastUpdated.innerHTML = "Last updated on " + updatedDate;
1344
+ lastUpdatedRow.appendChild(lastUpdated);
1345
+
1346
+ // const visitLink = document.createElement("a");
1347
+ // visitLink.setAttribute("class", "bs-widget-visit");
1348
+ // visitLink.setAttribute("href", "https://" + + "beanstack.com/");
1349
+ // visitLink.innerHTML = "Visit our Beanstack site";
1350
+ // lastUpdatedRow.appendChild(visitLink);
1351
+
1352
+ document.querySelector(options.container).appendChild(container);
1353
+ };
1354
+ this.error = function (error) {
1355
+ var container = document.createElement("div");
1356
+ container.setAttribute("class", "bs-widget-container");
1357
+ container.classList.add("error");
1358
+ container.innerHTML = error;
1359
+ container.style.setProperty("--bs-color", tinycolor(options.color).toHexString());
1360
+ container.style.setProperty("--bs-dark", tinycolor(options.color).darken().toHexString());
1361
+ container.style.setProperty("--bs-light", tinycolor(options.color).lighten(30).toHexString());
1362
+ var style = document.createElement("style");
1363
+ style.innerHTML = styles;
1364
+ container.appendChild(style);
1365
+ document.querySelector(options.container).appendChild(container);
1366
+ };
1367
+ this.loadRequest();
1368
+ }
1369
+
1370
+ return BSWidget;
1371
+
1372
+ })();