@razorpay/blade 10.12.1 → 10.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/index.development.web.js +5 -5
- package/build/components/index.development.web.js.map +1 -1
- package/build/components/index.native.js +2 -2
- package/build/components/index.native.js.map +1 -1
- package/build/components/index.production.web.js +5 -5
- package/build/components/index.production.web.js.map +1 -1
- package/build/css/bankingThemeDarkDesktop.css +1 -1
- package/build/css/bankingThemeDarkMobile.css +1 -1
- package/build/css/bankingThemeLightDesktop.css +1 -1
- package/build/css/bankingThemeLightMobile.css +1 -1
- package/build/css/paymentThemeDarkDesktop.css +1 -1
- package/build/css/paymentThemeDarkMobile.css +1 -1
- package/build/css/paymentThemeLightDesktop.css +1 -1
- package/build/css/paymentThemeLightMobile.css +1 -1
- package/build/tokens/index.d.ts +18 -1
- package/build/tokens/index.development.web.js +2292 -1325
- package/build/tokens/index.development.web.js.map +1 -1
- package/build/tokens/index.native.d.ts +18 -1
- package/build/tokens/index.native.js +1498 -898
- package/build/tokens/index.native.js.map +1 -1
- package/build/tokens/index.production.web.js +1517 -91
- package/build/tokens/index.production.web.js.map +1 -1
- package/package.json +4 -2
|
@@ -324,8 +324,8 @@ var fontFamily = {
|
|
|
324
324
|
code: 'monospace'
|
|
325
325
|
};
|
|
326
326
|
|
|
327
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
328
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
327
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
328
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
329
329
|
|
|
330
330
|
/**
|
|
331
331
|
* For font size and line-heights we can’t say from xl to 2xl the value will necessary increase.
|
|
@@ -341,7 +341,7 @@ var fontWeight = {
|
|
|
341
341
|
var typography = {
|
|
342
342
|
onDesktop: {
|
|
343
343
|
fonts: {
|
|
344
|
-
family: _objectSpread({}, fontFamily),
|
|
344
|
+
family: _objectSpread$1({}, fontFamily),
|
|
345
345
|
size: {
|
|
346
346
|
10: 9,
|
|
347
347
|
25: 10,
|
|
@@ -362,7 +362,7 @@ var typography = {
|
|
|
362
362
|
1300: 64,
|
|
363
363
|
1600: 88
|
|
364
364
|
},
|
|
365
|
-
weight: _objectSpread({}, fontWeight)
|
|
365
|
+
weight: _objectSpread$1({}, fontWeight)
|
|
366
366
|
},
|
|
367
367
|
lineHeights: {
|
|
368
368
|
0: 0,
|
|
@@ -387,7 +387,7 @@ var typography = {
|
|
|
387
387
|
|
|
388
388
|
onMobile: {
|
|
389
389
|
fonts: {
|
|
390
|
-
family: _objectSpread({}, fontFamily),
|
|
390
|
+
family: _objectSpread$1({}, fontFamily),
|
|
391
391
|
size: {
|
|
392
392
|
10: 9,
|
|
393
393
|
25: 10,
|
|
@@ -408,7 +408,7 @@ var typography = {
|
|
|
408
408
|
1300: 56,
|
|
409
409
|
1600: 64
|
|
410
410
|
},
|
|
411
|
-
weight: _objectSpread({}, fontWeight)
|
|
411
|
+
weight: _objectSpread$1({}, fontWeight)
|
|
412
412
|
},
|
|
413
413
|
lineHeights: {
|
|
414
414
|
0: 0,
|
|
@@ -5570,7 +5570,7 @@ var _hashDelete = hashDelete$1;
|
|
|
5570
5570
|
var nativeCreate$2 = _nativeCreate;
|
|
5571
5571
|
|
|
5572
5572
|
/** Used to stand-in for `undefined` hash values. */
|
|
5573
|
-
var HASH_UNDEFINED$
|
|
5573
|
+
var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
|
|
5574
5574
|
|
|
5575
5575
|
/** Used for built-in method references. */
|
|
5576
5576
|
var objectProto$a = Object.prototype;
|
|
@@ -5591,7 +5591,7 @@ function hashGet$1(key) {
|
|
|
5591
5591
|
var data = this.__data__;
|
|
5592
5592
|
if (nativeCreate$2) {
|
|
5593
5593
|
var result = data[key];
|
|
5594
|
-
return result === HASH_UNDEFINED$
|
|
5594
|
+
return result === HASH_UNDEFINED$1 ? undefined : result;
|
|
5595
5595
|
}
|
|
5596
5596
|
return hasOwnProperty$8.call(data, key) ? data[key] : undefined;
|
|
5597
5597
|
}
|
|
@@ -5625,7 +5625,7 @@ var _hashHas = hashHas$1;
|
|
|
5625
5625
|
var nativeCreate = _nativeCreate;
|
|
5626
5626
|
|
|
5627
5627
|
/** Used to stand-in for `undefined` hash values. */
|
|
5628
|
-
var HASH_UNDEFINED
|
|
5628
|
+
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|
5629
5629
|
|
|
5630
5630
|
/**
|
|
5631
5631
|
* Sets the hash `key` to `value`.
|
|
@@ -5640,7 +5640,7 @@ var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
|
|
|
5640
5640
|
function hashSet$1(key, value) {
|
|
5641
5641
|
var data = this.__data__;
|
|
5642
5642
|
this.size += this.has(key) ? 0 : 1;
|
|
5643
|
-
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED
|
|
5643
|
+
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
|
|
5644
5644
|
return this;
|
|
5645
5645
|
}
|
|
5646
5646
|
|
|
@@ -5826,7 +5826,7 @@ var mapCacheClear = _mapCacheClear,
|
|
|
5826
5826
|
* @constructor
|
|
5827
5827
|
* @param {Array} [entries] The key-value pairs to cache.
|
|
5828
5828
|
*/
|
|
5829
|
-
function MapCache$
|
|
5829
|
+
function MapCache$1(entries) {
|
|
5830
5830
|
var index = -1,
|
|
5831
5831
|
length = entries == null ? 0 : entries.length;
|
|
5832
5832
|
|
|
@@ -5838,17 +5838,17 @@ function MapCache$2(entries) {
|
|
|
5838
5838
|
}
|
|
5839
5839
|
|
|
5840
5840
|
// Add methods to `MapCache`.
|
|
5841
|
-
MapCache$
|
|
5842
|
-
MapCache$
|
|
5843
|
-
MapCache$
|
|
5844
|
-
MapCache$
|
|
5845
|
-
MapCache$
|
|
5841
|
+
MapCache$1.prototype.clear = mapCacheClear;
|
|
5842
|
+
MapCache$1.prototype['delete'] = mapCacheDelete;
|
|
5843
|
+
MapCache$1.prototype.get = mapCacheGet;
|
|
5844
|
+
MapCache$1.prototype.has = mapCacheHas;
|
|
5845
|
+
MapCache$1.prototype.set = mapCacheSet;
|
|
5846
5846
|
|
|
5847
|
-
var _MapCache = MapCache$
|
|
5847
|
+
var _MapCache = MapCache$1;
|
|
5848
5848
|
|
|
5849
5849
|
var ListCache$1 = _ListCache,
|
|
5850
5850
|
Map$1 = _Map,
|
|
5851
|
-
MapCache
|
|
5851
|
+
MapCache = _MapCache;
|
|
5852
5852
|
|
|
5853
5853
|
/** Used as the size to enable large array optimizations. */
|
|
5854
5854
|
var LARGE_ARRAY_SIZE = 200;
|
|
@@ -5872,7 +5872,7 @@ function stackSet$1(key, value) {
|
|
|
5872
5872
|
this.size = ++data.size;
|
|
5873
5873
|
return this;
|
|
5874
5874
|
}
|
|
5875
|
-
data = this.__data__ = new MapCache
|
|
5875
|
+
data = this.__data__ = new MapCache(pairs);
|
|
5876
5876
|
}
|
|
5877
5877
|
data.set(key, value);
|
|
5878
5878
|
this.size = data.size;
|
|
@@ -7251,8 +7251,8 @@ var _cloneRegExp = cloneRegExp$1;
|
|
|
7251
7251
|
var Symbol$1 = _Symbol;
|
|
7252
7252
|
|
|
7253
7253
|
/** Used to convert symbols to primitives and strings. */
|
|
7254
|
-
var symbolProto
|
|
7255
|
-
symbolValueOf = symbolProto
|
|
7254
|
+
var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
|
|
7255
|
+
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
|
|
7256
7256
|
|
|
7257
7257
|
/**
|
|
7258
7258
|
* Creates a clone of the `symbol` object.
|
|
@@ -7705,75 +7705,6 @@ var cloneDeep_1 = cloneDeep;
|
|
|
7705
7705
|
|
|
7706
7706
|
var cloneDeep$1 = /*@__PURE__*/getDefaultExportFromCjs(cloneDeep_1);
|
|
7707
7707
|
|
|
7708
|
-
/** Used to stand-in for `undefined` hash values. */
|
|
7709
|
-
|
|
7710
|
-
var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
|
7711
|
-
|
|
7712
|
-
/**
|
|
7713
|
-
* Adds `value` to the array cache.
|
|
7714
|
-
*
|
|
7715
|
-
* @private
|
|
7716
|
-
* @name add
|
|
7717
|
-
* @memberOf SetCache
|
|
7718
|
-
* @alias push
|
|
7719
|
-
* @param {*} value The value to cache.
|
|
7720
|
-
* @returns {Object} Returns the cache instance.
|
|
7721
|
-
*/
|
|
7722
|
-
function setCacheAdd$1(value) {
|
|
7723
|
-
this.__data__.set(value, HASH_UNDEFINED);
|
|
7724
|
-
return this;
|
|
7725
|
-
}
|
|
7726
|
-
|
|
7727
|
-
var _setCacheAdd = setCacheAdd$1;
|
|
7728
|
-
|
|
7729
|
-
/**
|
|
7730
|
-
* Checks if `value` is in the array cache.
|
|
7731
|
-
*
|
|
7732
|
-
* @private
|
|
7733
|
-
* @name has
|
|
7734
|
-
* @memberOf SetCache
|
|
7735
|
-
* @param {*} value The value to search for.
|
|
7736
|
-
* @returns {number} Returns `true` if `value` is found, else `false`.
|
|
7737
|
-
*/
|
|
7738
|
-
|
|
7739
|
-
function setCacheHas$1(value) {
|
|
7740
|
-
return this.__data__.has(value);
|
|
7741
|
-
}
|
|
7742
|
-
|
|
7743
|
-
var _setCacheHas = setCacheHas$1;
|
|
7744
|
-
|
|
7745
|
-
var MapCache = _MapCache,
|
|
7746
|
-
setCacheAdd = _setCacheAdd,
|
|
7747
|
-
setCacheHas = _setCacheHas;
|
|
7748
|
-
|
|
7749
|
-
/**
|
|
7750
|
-
*
|
|
7751
|
-
* Creates an array cache object to store unique values.
|
|
7752
|
-
*
|
|
7753
|
-
* @private
|
|
7754
|
-
* @constructor
|
|
7755
|
-
* @param {Array} [values] The values to cache.
|
|
7756
|
-
*/
|
|
7757
|
-
function SetCache(values) {
|
|
7758
|
-
var index = -1,
|
|
7759
|
-
length = values == null ? 0 : values.length;
|
|
7760
|
-
|
|
7761
|
-
this.__data__ = new MapCache;
|
|
7762
|
-
while (++index < length) {
|
|
7763
|
-
this.add(values[index]);
|
|
7764
|
-
}
|
|
7765
|
-
}
|
|
7766
|
-
|
|
7767
|
-
// Add methods to `SetCache`.
|
|
7768
|
-
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
|
7769
|
-
SetCache.prototype.has = setCacheHas;
|
|
7770
|
-
|
|
7771
|
-
var Symbol = _Symbol;
|
|
7772
|
-
|
|
7773
|
-
/** Used to convert symbols to primitives and strings. */
|
|
7774
|
-
var symbolProto = Symbol ? Symbol.prototype : undefined;
|
|
7775
|
-
symbolProto ? symbolProto.valueOf : undefined;
|
|
7776
|
-
|
|
7777
7708
|
var baseAssignValue = _baseAssignValue,
|
|
7778
7709
|
eq$1 = eq_1;
|
|
7779
7710
|
|
|
@@ -8448,6 +8379,8 @@ var merge_1 = merge;
|
|
|
8448
8379
|
var merge$1 = /*@__PURE__*/getDefaultExportFromCjs(merge_1);
|
|
8449
8380
|
|
|
8450
8381
|
/**
|
|
8382
|
+
* @deprecated Use `createTheme` from `@razorpay/blade/tokens` instead
|
|
8383
|
+
*
|
|
8451
8384
|
* @description
|
|
8452
8385
|
*
|
|
8453
8386
|
* `overrideTheme` merges the `baseThemeTokens` and `overrides` and returns a new ThemeTokens object,
|
|
@@ -8481,5 +8414,1498 @@ var overrideTheme = function overrideTheme(_ref) {
|
|
|
8481
8414
|
return merge$1(cloneDeep$1(baseThemeTokens), overrides);
|
|
8482
8415
|
};
|
|
8483
8416
|
|
|
8484
|
-
|
|
8417
|
+
// This file is autogenerated. It's used to publish ESM to npm.
|
|
8418
|
+
function _typeof(obj) {
|
|
8419
|
+
"@babel/helpers - typeof";
|
|
8420
|
+
|
|
8421
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
8422
|
+
return typeof obj;
|
|
8423
|
+
} : function (obj) {
|
|
8424
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
8425
|
+
}, _typeof(obj);
|
|
8426
|
+
}
|
|
8427
|
+
|
|
8428
|
+
// https://github.com/bgrins/TinyColor
|
|
8429
|
+
// Brian Grinstead, MIT License
|
|
8430
|
+
|
|
8431
|
+
var trimLeft = /^\s+/;
|
|
8432
|
+
var trimRight = /\s+$/;
|
|
8433
|
+
function tinycolor(color, opts) {
|
|
8434
|
+
color = color ? color : "";
|
|
8435
|
+
opts = opts || {};
|
|
8436
|
+
|
|
8437
|
+
// If input is already a tinycolor, return itself
|
|
8438
|
+
if (color instanceof tinycolor) {
|
|
8439
|
+
return color;
|
|
8440
|
+
}
|
|
8441
|
+
// If we are called as a function, call using new instead
|
|
8442
|
+
if (!(this instanceof tinycolor)) {
|
|
8443
|
+
return new tinycolor(color, opts);
|
|
8444
|
+
}
|
|
8445
|
+
var rgb = inputToRGB(color);
|
|
8446
|
+
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;
|
|
8447
|
+
this._gradientType = opts.gradientType;
|
|
8448
|
+
|
|
8449
|
+
// Don't let the range of [0,255] come back in [0,1].
|
|
8450
|
+
// Potentially lose a little bit of precision here, but will fix issues where
|
|
8451
|
+
// .5 gets interpreted as half of the total, instead of half of 1
|
|
8452
|
+
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
|
|
8453
|
+
if (this._r < 1) this._r = Math.round(this._r);
|
|
8454
|
+
if (this._g < 1) this._g = Math.round(this._g);
|
|
8455
|
+
if (this._b < 1) this._b = Math.round(this._b);
|
|
8456
|
+
this._ok = rgb.ok;
|
|
8457
|
+
}
|
|
8458
|
+
tinycolor.prototype = {
|
|
8459
|
+
isDark: function isDark() {
|
|
8460
|
+
return this.getBrightness() < 128;
|
|
8461
|
+
},
|
|
8462
|
+
isLight: function isLight() {
|
|
8463
|
+
return !this.isDark();
|
|
8464
|
+
},
|
|
8465
|
+
isValid: function isValid() {
|
|
8466
|
+
return this._ok;
|
|
8467
|
+
},
|
|
8468
|
+
getOriginalInput: function getOriginalInput() {
|
|
8469
|
+
return this._originalInput;
|
|
8470
|
+
},
|
|
8471
|
+
getFormat: function getFormat() {
|
|
8472
|
+
return this._format;
|
|
8473
|
+
},
|
|
8474
|
+
getAlpha: function getAlpha() {
|
|
8475
|
+
return this._a;
|
|
8476
|
+
},
|
|
8477
|
+
getBrightness: function getBrightness() {
|
|
8478
|
+
//http://www.w3.org/TR/AERT#color-contrast
|
|
8479
|
+
var rgb = this.toRgb();
|
|
8480
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
|
|
8481
|
+
},
|
|
8482
|
+
getLuminance: function getLuminance() {
|
|
8483
|
+
//http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
|
|
8484
|
+
var rgb = this.toRgb();
|
|
8485
|
+
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
8486
|
+
RsRGB = rgb.r / 255;
|
|
8487
|
+
GsRGB = rgb.g / 255;
|
|
8488
|
+
BsRGB = rgb.b / 255;
|
|
8489
|
+
if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
8490
|
+
if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
8491
|
+
if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
8492
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
8493
|
+
},
|
|
8494
|
+
setAlpha: function setAlpha(value) {
|
|
8495
|
+
this._a = boundAlpha(value);
|
|
8496
|
+
this._roundA = Math.round(100 * this._a) / 100;
|
|
8497
|
+
return this;
|
|
8498
|
+
},
|
|
8499
|
+
toHsv: function toHsv() {
|
|
8500
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
8501
|
+
return {
|
|
8502
|
+
h: hsv.h * 360,
|
|
8503
|
+
s: hsv.s,
|
|
8504
|
+
v: hsv.v,
|
|
8505
|
+
a: this._a
|
|
8506
|
+
};
|
|
8507
|
+
},
|
|
8508
|
+
toHsvString: function toHsvString() {
|
|
8509
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
8510
|
+
var h = Math.round(hsv.h * 360),
|
|
8511
|
+
s = Math.round(hsv.s * 100),
|
|
8512
|
+
v = Math.round(hsv.v * 100);
|
|
8513
|
+
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
8514
|
+
},
|
|
8515
|
+
toHsl: function toHsl() {
|
|
8516
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
8517
|
+
return {
|
|
8518
|
+
h: hsl.h * 360,
|
|
8519
|
+
s: hsl.s,
|
|
8520
|
+
l: hsl.l,
|
|
8521
|
+
a: this._a
|
|
8522
|
+
};
|
|
8523
|
+
},
|
|
8524
|
+
toHslString: function toHslString() {
|
|
8525
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
8526
|
+
var h = Math.round(hsl.h * 360),
|
|
8527
|
+
s = Math.round(hsl.s * 100),
|
|
8528
|
+
l = Math.round(hsl.l * 100);
|
|
8529
|
+
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
8530
|
+
},
|
|
8531
|
+
toHex: function toHex(allow3Char) {
|
|
8532
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
8533
|
+
},
|
|
8534
|
+
toHexString: function toHexString(allow3Char) {
|
|
8535
|
+
return "#" + this.toHex(allow3Char);
|
|
8536
|
+
},
|
|
8537
|
+
toHex8: function toHex8(allow4Char) {
|
|
8538
|
+
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
8539
|
+
},
|
|
8540
|
+
toHex8String: function toHex8String(allow4Char) {
|
|
8541
|
+
return "#" + this.toHex8(allow4Char);
|
|
8542
|
+
},
|
|
8543
|
+
toRgb: function toRgb() {
|
|
8544
|
+
return {
|
|
8545
|
+
r: Math.round(this._r),
|
|
8546
|
+
g: Math.round(this._g),
|
|
8547
|
+
b: Math.round(this._b),
|
|
8548
|
+
a: this._a
|
|
8549
|
+
};
|
|
8550
|
+
},
|
|
8551
|
+
toRgbString: function toRgbString() {
|
|
8552
|
+
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 + ")";
|
|
8553
|
+
},
|
|
8554
|
+
toPercentageRgb: function toPercentageRgb() {
|
|
8555
|
+
return {
|
|
8556
|
+
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
8557
|
+
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
8558
|
+
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
8559
|
+
a: this._a
|
|
8560
|
+
};
|
|
8561
|
+
},
|
|
8562
|
+
toPercentageRgbString: function toPercentageRgbString() {
|
|
8563
|
+
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 + ")";
|
|
8564
|
+
},
|
|
8565
|
+
toName: function toName() {
|
|
8566
|
+
if (this._a === 0) {
|
|
8567
|
+
return "transparent";
|
|
8568
|
+
}
|
|
8569
|
+
if (this._a < 1) {
|
|
8570
|
+
return false;
|
|
8571
|
+
}
|
|
8572
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
8573
|
+
},
|
|
8574
|
+
toFilter: function toFilter(secondColor) {
|
|
8575
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
8576
|
+
var secondHex8String = hex8String;
|
|
8577
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
8578
|
+
if (secondColor) {
|
|
8579
|
+
var s = tinycolor(secondColor);
|
|
8580
|
+
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
8581
|
+
}
|
|
8582
|
+
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
8583
|
+
},
|
|
8584
|
+
toString: function toString(format) {
|
|
8585
|
+
var formatSet = !!format;
|
|
8586
|
+
format = format || this._format;
|
|
8587
|
+
var formattedString = false;
|
|
8588
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
8589
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
8590
|
+
if (needsAlphaFormat) {
|
|
8591
|
+
// Special case for "transparent", all other non-alpha formats
|
|
8592
|
+
// will return rgba when there is transparency.
|
|
8593
|
+
if (format === "name" && this._a === 0) {
|
|
8594
|
+
return this.toName();
|
|
8595
|
+
}
|
|
8596
|
+
return this.toRgbString();
|
|
8597
|
+
}
|
|
8598
|
+
if (format === "rgb") {
|
|
8599
|
+
formattedString = this.toRgbString();
|
|
8600
|
+
}
|
|
8601
|
+
if (format === "prgb") {
|
|
8602
|
+
formattedString = this.toPercentageRgbString();
|
|
8603
|
+
}
|
|
8604
|
+
if (format === "hex" || format === "hex6") {
|
|
8605
|
+
formattedString = this.toHexString();
|
|
8606
|
+
}
|
|
8607
|
+
if (format === "hex3") {
|
|
8608
|
+
formattedString = this.toHexString(true);
|
|
8609
|
+
}
|
|
8610
|
+
if (format === "hex4") {
|
|
8611
|
+
formattedString = this.toHex8String(true);
|
|
8612
|
+
}
|
|
8613
|
+
if (format === "hex8") {
|
|
8614
|
+
formattedString = this.toHex8String();
|
|
8615
|
+
}
|
|
8616
|
+
if (format === "name") {
|
|
8617
|
+
formattedString = this.toName();
|
|
8618
|
+
}
|
|
8619
|
+
if (format === "hsl") {
|
|
8620
|
+
formattedString = this.toHslString();
|
|
8621
|
+
}
|
|
8622
|
+
if (format === "hsv") {
|
|
8623
|
+
formattedString = this.toHsvString();
|
|
8624
|
+
}
|
|
8625
|
+
return formattedString || this.toHexString();
|
|
8626
|
+
},
|
|
8627
|
+
clone: function clone() {
|
|
8628
|
+
return tinycolor(this.toString());
|
|
8629
|
+
},
|
|
8630
|
+
_applyModification: function _applyModification(fn, args) {
|
|
8631
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
8632
|
+
this._r = color._r;
|
|
8633
|
+
this._g = color._g;
|
|
8634
|
+
this._b = color._b;
|
|
8635
|
+
this.setAlpha(color._a);
|
|
8636
|
+
return this;
|
|
8637
|
+
},
|
|
8638
|
+
lighten: function lighten() {
|
|
8639
|
+
return this._applyModification(_lighten, arguments);
|
|
8640
|
+
},
|
|
8641
|
+
brighten: function brighten() {
|
|
8642
|
+
return this._applyModification(_brighten, arguments);
|
|
8643
|
+
},
|
|
8644
|
+
darken: function darken() {
|
|
8645
|
+
return this._applyModification(_darken, arguments);
|
|
8646
|
+
},
|
|
8647
|
+
desaturate: function desaturate() {
|
|
8648
|
+
return this._applyModification(_desaturate, arguments);
|
|
8649
|
+
},
|
|
8650
|
+
saturate: function saturate() {
|
|
8651
|
+
return this._applyModification(_saturate, arguments);
|
|
8652
|
+
},
|
|
8653
|
+
greyscale: function greyscale() {
|
|
8654
|
+
return this._applyModification(_greyscale, arguments);
|
|
8655
|
+
},
|
|
8656
|
+
spin: function spin() {
|
|
8657
|
+
return this._applyModification(_spin, arguments);
|
|
8658
|
+
},
|
|
8659
|
+
_applyCombination: function _applyCombination(fn, args) {
|
|
8660
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
8661
|
+
},
|
|
8662
|
+
analogous: function analogous() {
|
|
8663
|
+
return this._applyCombination(_analogous, arguments);
|
|
8664
|
+
},
|
|
8665
|
+
complement: function complement() {
|
|
8666
|
+
return this._applyCombination(_complement, arguments);
|
|
8667
|
+
},
|
|
8668
|
+
monochromatic: function monochromatic() {
|
|
8669
|
+
return this._applyCombination(_monochromatic, arguments);
|
|
8670
|
+
},
|
|
8671
|
+
splitcomplement: function splitcomplement() {
|
|
8672
|
+
return this._applyCombination(_splitcomplement, arguments);
|
|
8673
|
+
},
|
|
8674
|
+
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
8675
|
+
// polyad: function (number) {
|
|
8676
|
+
// return this._applyCombination(polyad, [number]);
|
|
8677
|
+
// },
|
|
8678
|
+
triad: function triad() {
|
|
8679
|
+
return this._applyCombination(polyad, [3]);
|
|
8680
|
+
},
|
|
8681
|
+
tetrad: function tetrad() {
|
|
8682
|
+
return this._applyCombination(polyad, [4]);
|
|
8683
|
+
}
|
|
8684
|
+
};
|
|
8685
|
+
|
|
8686
|
+
// If input is an object, force 1 into "1.0" to handle ratios properly
|
|
8687
|
+
// String input requires "1.0" as input, so 1 will be treated as 1
|
|
8688
|
+
tinycolor.fromRatio = function (color, opts) {
|
|
8689
|
+
if (_typeof(color) == "object") {
|
|
8690
|
+
var newColor = {};
|
|
8691
|
+
for (var i in color) {
|
|
8692
|
+
if (color.hasOwnProperty(i)) {
|
|
8693
|
+
if (i === "a") {
|
|
8694
|
+
newColor[i] = color[i];
|
|
8695
|
+
} else {
|
|
8696
|
+
newColor[i] = convertToPercentage(color[i]);
|
|
8697
|
+
}
|
|
8698
|
+
}
|
|
8699
|
+
}
|
|
8700
|
+
color = newColor;
|
|
8701
|
+
}
|
|
8702
|
+
return tinycolor(color, opts);
|
|
8703
|
+
};
|
|
8704
|
+
|
|
8705
|
+
// Given a string or object, convert that input to RGB
|
|
8706
|
+
// Possible string inputs:
|
|
8707
|
+
//
|
|
8708
|
+
// "red"
|
|
8709
|
+
// "#f00" or "f00"
|
|
8710
|
+
// "#ff0000" or "ff0000"
|
|
8711
|
+
// "#ff000000" or "ff000000"
|
|
8712
|
+
// "rgb 255 0 0" or "rgb (255, 0, 0)"
|
|
8713
|
+
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
|
|
8714
|
+
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
|
|
8715
|
+
// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
|
|
8716
|
+
// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
|
|
8717
|
+
// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
|
|
8718
|
+
// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
|
|
8719
|
+
//
|
|
8720
|
+
function inputToRGB(color) {
|
|
8721
|
+
var rgb = {
|
|
8722
|
+
r: 0,
|
|
8723
|
+
g: 0,
|
|
8724
|
+
b: 0
|
|
8725
|
+
};
|
|
8726
|
+
var a = 1;
|
|
8727
|
+
var s = null;
|
|
8728
|
+
var v = null;
|
|
8729
|
+
var l = null;
|
|
8730
|
+
var ok = false;
|
|
8731
|
+
var format = false;
|
|
8732
|
+
if (typeof color == "string") {
|
|
8733
|
+
color = stringInputToObject(color);
|
|
8734
|
+
}
|
|
8735
|
+
if (_typeof(color) == "object") {
|
|
8736
|
+
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
8737
|
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
8738
|
+
ok = true;
|
|
8739
|
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
8740
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
8741
|
+
s = convertToPercentage(color.s);
|
|
8742
|
+
v = convertToPercentage(color.v);
|
|
8743
|
+
rgb = hsvToRgb(color.h, s, v);
|
|
8744
|
+
ok = true;
|
|
8745
|
+
format = "hsv";
|
|
8746
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
8747
|
+
s = convertToPercentage(color.s);
|
|
8748
|
+
l = convertToPercentage(color.l);
|
|
8749
|
+
rgb = hslToRgb(color.h, s, l);
|
|
8750
|
+
ok = true;
|
|
8751
|
+
format = "hsl";
|
|
8752
|
+
}
|
|
8753
|
+
if (color.hasOwnProperty("a")) {
|
|
8754
|
+
a = color.a;
|
|
8755
|
+
}
|
|
8756
|
+
}
|
|
8757
|
+
a = boundAlpha(a);
|
|
8758
|
+
return {
|
|
8759
|
+
ok: ok,
|
|
8760
|
+
format: color.format || format,
|
|
8761
|
+
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
8762
|
+
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
8763
|
+
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
8764
|
+
a: a
|
|
8765
|
+
};
|
|
8766
|
+
}
|
|
8767
|
+
|
|
8768
|
+
// Conversion Functions
|
|
8769
|
+
// --------------------
|
|
8770
|
+
|
|
8771
|
+
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
|
|
8772
|
+
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
|
|
8773
|
+
|
|
8774
|
+
// `rgbToRgb`
|
|
8775
|
+
// Handle bounds / percentage checking to conform to CSS color spec
|
|
8776
|
+
// <http://www.w3.org/TR/css3-color/>
|
|
8777
|
+
// *Assumes:* r, g, b in [0, 255] or [0, 1]
|
|
8778
|
+
// *Returns:* { r, g, b } in [0, 255]
|
|
8779
|
+
function rgbToRgb(r, g, b) {
|
|
8780
|
+
return {
|
|
8781
|
+
r: bound01(r, 255) * 255,
|
|
8782
|
+
g: bound01(g, 255) * 255,
|
|
8783
|
+
b: bound01(b, 255) * 255
|
|
8784
|
+
};
|
|
8785
|
+
}
|
|
8786
|
+
|
|
8787
|
+
// `rgbToHsl`
|
|
8788
|
+
// Converts an RGB color value to HSL.
|
|
8789
|
+
// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
|
|
8790
|
+
// *Returns:* { h, s, l } in [0,1]
|
|
8791
|
+
function rgbToHsl(r, g, b) {
|
|
8792
|
+
r = bound01(r, 255);
|
|
8793
|
+
g = bound01(g, 255);
|
|
8794
|
+
b = bound01(b, 255);
|
|
8795
|
+
var max = Math.max(r, g, b),
|
|
8796
|
+
min = Math.min(r, g, b);
|
|
8797
|
+
var h,
|
|
8798
|
+
s,
|
|
8799
|
+
l = (max + min) / 2;
|
|
8800
|
+
if (max == min) {
|
|
8801
|
+
h = s = 0; // achromatic
|
|
8802
|
+
} else {
|
|
8803
|
+
var d = max - min;
|
|
8804
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
8805
|
+
switch (max) {
|
|
8806
|
+
case r:
|
|
8807
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
8808
|
+
break;
|
|
8809
|
+
case g:
|
|
8810
|
+
h = (b - r) / d + 2;
|
|
8811
|
+
break;
|
|
8812
|
+
case b:
|
|
8813
|
+
h = (r - g) / d + 4;
|
|
8814
|
+
break;
|
|
8815
|
+
}
|
|
8816
|
+
h /= 6;
|
|
8817
|
+
}
|
|
8818
|
+
return {
|
|
8819
|
+
h: h,
|
|
8820
|
+
s: s,
|
|
8821
|
+
l: l
|
|
8822
|
+
};
|
|
8823
|
+
}
|
|
8824
|
+
|
|
8825
|
+
// `hslToRgb`
|
|
8826
|
+
// Converts an HSL color value to RGB.
|
|
8827
|
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
|
|
8828
|
+
// *Returns:* { r, g, b } in the set [0, 255]
|
|
8829
|
+
function hslToRgb(h, s, l) {
|
|
8830
|
+
var r, g, b;
|
|
8831
|
+
h = bound01(h, 360);
|
|
8832
|
+
s = bound01(s, 100);
|
|
8833
|
+
l = bound01(l, 100);
|
|
8834
|
+
function hue2rgb(p, q, t) {
|
|
8835
|
+
if (t < 0) t += 1;
|
|
8836
|
+
if (t > 1) t -= 1;
|
|
8837
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
8838
|
+
if (t < 1 / 2) return q;
|
|
8839
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
8840
|
+
return p;
|
|
8841
|
+
}
|
|
8842
|
+
if (s === 0) {
|
|
8843
|
+
r = g = b = l; // achromatic
|
|
8844
|
+
} else {
|
|
8845
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
8846
|
+
var p = 2 * l - q;
|
|
8847
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
8848
|
+
g = hue2rgb(p, q, h);
|
|
8849
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
8850
|
+
}
|
|
8851
|
+
return {
|
|
8852
|
+
r: r * 255,
|
|
8853
|
+
g: g * 255,
|
|
8854
|
+
b: b * 255
|
|
8855
|
+
};
|
|
8856
|
+
}
|
|
8857
|
+
|
|
8858
|
+
// `rgbToHsv`
|
|
8859
|
+
// Converts an RGB color value to HSV
|
|
8860
|
+
// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
|
|
8861
|
+
// *Returns:* { h, s, v } in [0,1]
|
|
8862
|
+
function rgbToHsv(r, g, b) {
|
|
8863
|
+
r = bound01(r, 255);
|
|
8864
|
+
g = bound01(g, 255);
|
|
8865
|
+
b = bound01(b, 255);
|
|
8866
|
+
var max = Math.max(r, g, b),
|
|
8867
|
+
min = Math.min(r, g, b);
|
|
8868
|
+
var h,
|
|
8869
|
+
s,
|
|
8870
|
+
v = max;
|
|
8871
|
+
var d = max - min;
|
|
8872
|
+
s = max === 0 ? 0 : d / max;
|
|
8873
|
+
if (max == min) {
|
|
8874
|
+
h = 0; // achromatic
|
|
8875
|
+
} else {
|
|
8876
|
+
switch (max) {
|
|
8877
|
+
case r:
|
|
8878
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
8879
|
+
break;
|
|
8880
|
+
case g:
|
|
8881
|
+
h = (b - r) / d + 2;
|
|
8882
|
+
break;
|
|
8883
|
+
case b:
|
|
8884
|
+
h = (r - g) / d + 4;
|
|
8885
|
+
break;
|
|
8886
|
+
}
|
|
8887
|
+
h /= 6;
|
|
8888
|
+
}
|
|
8889
|
+
return {
|
|
8890
|
+
h: h,
|
|
8891
|
+
s: s,
|
|
8892
|
+
v: v
|
|
8893
|
+
};
|
|
8894
|
+
}
|
|
8895
|
+
|
|
8896
|
+
// `hsvToRgb`
|
|
8897
|
+
// Converts an HSV color value to RGB.
|
|
8898
|
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
|
|
8899
|
+
// *Returns:* { r, g, b } in the set [0, 255]
|
|
8900
|
+
function hsvToRgb(h, s, v) {
|
|
8901
|
+
h = bound01(h, 360) * 6;
|
|
8902
|
+
s = bound01(s, 100);
|
|
8903
|
+
v = bound01(v, 100);
|
|
8904
|
+
var i = Math.floor(h),
|
|
8905
|
+
f = h - i,
|
|
8906
|
+
p = v * (1 - s),
|
|
8907
|
+
q = v * (1 - f * s),
|
|
8908
|
+
t = v * (1 - (1 - f) * s),
|
|
8909
|
+
mod = i % 6,
|
|
8910
|
+
r = [v, q, p, p, t, v][mod],
|
|
8911
|
+
g = [t, v, v, q, p, p][mod],
|
|
8912
|
+
b = [p, p, t, v, v, q][mod];
|
|
8913
|
+
return {
|
|
8914
|
+
r: r * 255,
|
|
8915
|
+
g: g * 255,
|
|
8916
|
+
b: b * 255
|
|
8917
|
+
};
|
|
8918
|
+
}
|
|
8919
|
+
|
|
8920
|
+
// `rgbToHex`
|
|
8921
|
+
// Converts an RGB color to hex
|
|
8922
|
+
// Assumes r, g, and b are contained in the set [0, 255]
|
|
8923
|
+
// Returns a 3 or 6 character hex
|
|
8924
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
8925
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
8926
|
+
|
|
8927
|
+
// Return a 3 character hex if possible
|
|
8928
|
+
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)) {
|
|
8929
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
8930
|
+
}
|
|
8931
|
+
return hex.join("");
|
|
8932
|
+
}
|
|
8933
|
+
|
|
8934
|
+
// `rgbaToHex`
|
|
8935
|
+
// Converts an RGBA color plus alpha transparency to hex
|
|
8936
|
+
// Assumes r, g, b are contained in the set [0, 255] and
|
|
8937
|
+
// a in [0, 1]. Returns a 4 or 8 character rgba hex
|
|
8938
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
8939
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
8940
|
+
|
|
8941
|
+
// Return a 4 character hex if possible
|
|
8942
|
+
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)) {
|
|
8943
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
8944
|
+
}
|
|
8945
|
+
return hex.join("");
|
|
8946
|
+
}
|
|
8947
|
+
|
|
8948
|
+
// `rgbaToArgbHex`
|
|
8949
|
+
// Converts an RGBA color to an ARGB Hex8 string
|
|
8950
|
+
// Rarely used, but required for "toFilter()"
|
|
8951
|
+
function rgbaToArgbHex(r, g, b, a) {
|
|
8952
|
+
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
8953
|
+
return hex.join("");
|
|
8954
|
+
}
|
|
8955
|
+
|
|
8956
|
+
// `equals`
|
|
8957
|
+
// Can be called with any tinycolor input
|
|
8958
|
+
tinycolor.equals = function (color1, color2) {
|
|
8959
|
+
if (!color1 || !color2) return false;
|
|
8960
|
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
8961
|
+
};
|
|
8962
|
+
tinycolor.random = function () {
|
|
8963
|
+
return tinycolor.fromRatio({
|
|
8964
|
+
r: Math.random(),
|
|
8965
|
+
g: Math.random(),
|
|
8966
|
+
b: Math.random()
|
|
8967
|
+
});
|
|
8968
|
+
};
|
|
8969
|
+
|
|
8970
|
+
// Modification Functions
|
|
8971
|
+
// ----------------------
|
|
8972
|
+
// Thanks to less.js for some of the basics here
|
|
8973
|
+
// <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
|
|
8974
|
+
|
|
8975
|
+
function _desaturate(color, amount) {
|
|
8976
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
8977
|
+
var hsl = tinycolor(color).toHsl();
|
|
8978
|
+
hsl.s -= amount / 100;
|
|
8979
|
+
hsl.s = clamp01(hsl.s);
|
|
8980
|
+
return tinycolor(hsl);
|
|
8981
|
+
}
|
|
8982
|
+
function _saturate(color, amount) {
|
|
8983
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
8984
|
+
var hsl = tinycolor(color).toHsl();
|
|
8985
|
+
hsl.s += amount / 100;
|
|
8986
|
+
hsl.s = clamp01(hsl.s);
|
|
8987
|
+
return tinycolor(hsl);
|
|
8988
|
+
}
|
|
8989
|
+
function _greyscale(color) {
|
|
8990
|
+
return tinycolor(color).desaturate(100);
|
|
8991
|
+
}
|
|
8992
|
+
function _lighten(color, amount) {
|
|
8993
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
8994
|
+
var hsl = tinycolor(color).toHsl();
|
|
8995
|
+
hsl.l += amount / 100;
|
|
8996
|
+
hsl.l = clamp01(hsl.l);
|
|
8997
|
+
return tinycolor(hsl);
|
|
8998
|
+
}
|
|
8999
|
+
function _brighten(color, amount) {
|
|
9000
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
9001
|
+
var rgb = tinycolor(color).toRgb();
|
|
9002
|
+
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
9003
|
+
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
9004
|
+
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
9005
|
+
return tinycolor(rgb);
|
|
9006
|
+
}
|
|
9007
|
+
function _darken(color, amount) {
|
|
9008
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
9009
|
+
var hsl = tinycolor(color).toHsl();
|
|
9010
|
+
hsl.l -= amount / 100;
|
|
9011
|
+
hsl.l = clamp01(hsl.l);
|
|
9012
|
+
return tinycolor(hsl);
|
|
9013
|
+
}
|
|
9014
|
+
|
|
9015
|
+
// Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
|
|
9016
|
+
// Values outside of this range will be wrapped into this range.
|
|
9017
|
+
function _spin(color, amount) {
|
|
9018
|
+
var hsl = tinycolor(color).toHsl();
|
|
9019
|
+
var hue = (hsl.h + amount) % 360;
|
|
9020
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
9021
|
+
return tinycolor(hsl);
|
|
9022
|
+
}
|
|
9023
|
+
|
|
9024
|
+
// Combination Functions
|
|
9025
|
+
// ---------------------
|
|
9026
|
+
// Thanks to jQuery xColor for some of the ideas behind these
|
|
9027
|
+
// <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
|
|
9028
|
+
|
|
9029
|
+
function _complement(color) {
|
|
9030
|
+
var hsl = tinycolor(color).toHsl();
|
|
9031
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
9032
|
+
return tinycolor(hsl);
|
|
9033
|
+
}
|
|
9034
|
+
function polyad(color, number) {
|
|
9035
|
+
if (isNaN(number) || number <= 0) {
|
|
9036
|
+
throw new Error("Argument to polyad must be a positive number");
|
|
9037
|
+
}
|
|
9038
|
+
var hsl = tinycolor(color).toHsl();
|
|
9039
|
+
var result = [tinycolor(color)];
|
|
9040
|
+
var step = 360 / number;
|
|
9041
|
+
for (var i = 1; i < number; i++) {
|
|
9042
|
+
result.push(tinycolor({
|
|
9043
|
+
h: (hsl.h + i * step) % 360,
|
|
9044
|
+
s: hsl.s,
|
|
9045
|
+
l: hsl.l
|
|
9046
|
+
}));
|
|
9047
|
+
}
|
|
9048
|
+
return result;
|
|
9049
|
+
}
|
|
9050
|
+
function _splitcomplement(color) {
|
|
9051
|
+
var hsl = tinycolor(color).toHsl();
|
|
9052
|
+
var h = hsl.h;
|
|
9053
|
+
return [tinycolor(color), tinycolor({
|
|
9054
|
+
h: (h + 72) % 360,
|
|
9055
|
+
s: hsl.s,
|
|
9056
|
+
l: hsl.l
|
|
9057
|
+
}), tinycolor({
|
|
9058
|
+
h: (h + 216) % 360,
|
|
9059
|
+
s: hsl.s,
|
|
9060
|
+
l: hsl.l
|
|
9061
|
+
})];
|
|
9062
|
+
}
|
|
9063
|
+
function _analogous(color, results, slices) {
|
|
9064
|
+
results = results || 6;
|
|
9065
|
+
slices = slices || 30;
|
|
9066
|
+
var hsl = tinycolor(color).toHsl();
|
|
9067
|
+
var part = 360 / slices;
|
|
9068
|
+
var ret = [tinycolor(color)];
|
|
9069
|
+
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
|
|
9070
|
+
hsl.h = (hsl.h + part) % 360;
|
|
9071
|
+
ret.push(tinycolor(hsl));
|
|
9072
|
+
}
|
|
9073
|
+
return ret;
|
|
9074
|
+
}
|
|
9075
|
+
function _monochromatic(color, results) {
|
|
9076
|
+
results = results || 6;
|
|
9077
|
+
var hsv = tinycolor(color).toHsv();
|
|
9078
|
+
var h = hsv.h,
|
|
9079
|
+
s = hsv.s,
|
|
9080
|
+
v = hsv.v;
|
|
9081
|
+
var ret = [];
|
|
9082
|
+
var modification = 1 / results;
|
|
9083
|
+
while (results--) {
|
|
9084
|
+
ret.push(tinycolor({
|
|
9085
|
+
h: h,
|
|
9086
|
+
s: s,
|
|
9087
|
+
v: v
|
|
9088
|
+
}));
|
|
9089
|
+
v = (v + modification) % 1;
|
|
9090
|
+
}
|
|
9091
|
+
return ret;
|
|
9092
|
+
}
|
|
9093
|
+
|
|
9094
|
+
// Utility Functions
|
|
9095
|
+
// ---------------------
|
|
9096
|
+
|
|
9097
|
+
tinycolor.mix = function (color1, color2, amount) {
|
|
9098
|
+
amount = amount === 0 ? 0 : amount || 50;
|
|
9099
|
+
var rgb1 = tinycolor(color1).toRgb();
|
|
9100
|
+
var rgb2 = tinycolor(color2).toRgb();
|
|
9101
|
+
var p = amount / 100;
|
|
9102
|
+
var rgba = {
|
|
9103
|
+
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
9104
|
+
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
9105
|
+
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
9106
|
+
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
9107
|
+
};
|
|
9108
|
+
return tinycolor(rgba);
|
|
9109
|
+
};
|
|
9110
|
+
|
|
9111
|
+
// Readability Functions
|
|
9112
|
+
// ---------------------
|
|
9113
|
+
// <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
|
|
9114
|
+
|
|
9115
|
+
// `contrast`
|
|
9116
|
+
// Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
|
|
9117
|
+
tinycolor.readability = function (color1, color2) {
|
|
9118
|
+
var c1 = tinycolor(color1);
|
|
9119
|
+
var c2 = tinycolor(color2);
|
|
9120
|
+
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
9121
|
+
};
|
|
9122
|
+
|
|
9123
|
+
// `isReadable`
|
|
9124
|
+
// Ensure that foreground and background color combinations meet WCAG2 guidelines.
|
|
9125
|
+
// The third argument is an optional Object.
|
|
9126
|
+
// the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
|
|
9127
|
+
// the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
|
|
9128
|
+
// If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
|
|
9129
|
+
|
|
9130
|
+
// *Example*
|
|
9131
|
+
// tinycolor.isReadable("#000", "#111") => false
|
|
9132
|
+
// tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
|
|
9133
|
+
tinycolor.isReadable = function (color1, color2, wcag2) {
|
|
9134
|
+
var readability = tinycolor.readability(color1, color2);
|
|
9135
|
+
var wcag2Parms, out;
|
|
9136
|
+
out = false;
|
|
9137
|
+
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
9138
|
+
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
9139
|
+
case "AAsmall":
|
|
9140
|
+
case "AAAlarge":
|
|
9141
|
+
out = readability >= 4.5;
|
|
9142
|
+
break;
|
|
9143
|
+
case "AAlarge":
|
|
9144
|
+
out = readability >= 3;
|
|
9145
|
+
break;
|
|
9146
|
+
case "AAAsmall":
|
|
9147
|
+
out = readability >= 7;
|
|
9148
|
+
break;
|
|
9149
|
+
}
|
|
9150
|
+
return out;
|
|
9151
|
+
};
|
|
9152
|
+
|
|
9153
|
+
// `mostReadable`
|
|
9154
|
+
// Given a base color and a list of possible foreground or background
|
|
9155
|
+
// colors for that base, returns the most readable color.
|
|
9156
|
+
// Optionally returns Black or White if the most readable color is unreadable.
|
|
9157
|
+
// *Example*
|
|
9158
|
+
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
|
|
9159
|
+
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
|
|
9160
|
+
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
|
|
9161
|
+
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
|
|
9162
|
+
tinycolor.mostReadable = function (baseColor, colorList, args) {
|
|
9163
|
+
var bestColor = null;
|
|
9164
|
+
var bestScore = 0;
|
|
9165
|
+
var readability;
|
|
9166
|
+
var includeFallbackColors, level, size;
|
|
9167
|
+
args = args || {};
|
|
9168
|
+
includeFallbackColors = args.includeFallbackColors;
|
|
9169
|
+
level = args.level;
|
|
9170
|
+
size = args.size;
|
|
9171
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
9172
|
+
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
9173
|
+
if (readability > bestScore) {
|
|
9174
|
+
bestScore = readability;
|
|
9175
|
+
bestColor = tinycolor(colorList[i]);
|
|
9176
|
+
}
|
|
9177
|
+
}
|
|
9178
|
+
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
9179
|
+
level: level,
|
|
9180
|
+
size: size
|
|
9181
|
+
}) || !includeFallbackColors) {
|
|
9182
|
+
return bestColor;
|
|
9183
|
+
} else {
|
|
9184
|
+
args.includeFallbackColors = false;
|
|
9185
|
+
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
9186
|
+
}
|
|
9187
|
+
};
|
|
9188
|
+
|
|
9189
|
+
// Big List of Colors
|
|
9190
|
+
// ------------------
|
|
9191
|
+
// <https://www.w3.org/TR/css-color-4/#named-colors>
|
|
9192
|
+
var names = tinycolor.names = {
|
|
9193
|
+
aliceblue: "f0f8ff",
|
|
9194
|
+
antiquewhite: "faebd7",
|
|
9195
|
+
aqua: "0ff",
|
|
9196
|
+
aquamarine: "7fffd4",
|
|
9197
|
+
azure: "f0ffff",
|
|
9198
|
+
beige: "f5f5dc",
|
|
9199
|
+
bisque: "ffe4c4",
|
|
9200
|
+
black: "000",
|
|
9201
|
+
blanchedalmond: "ffebcd",
|
|
9202
|
+
blue: "00f",
|
|
9203
|
+
blueviolet: "8a2be2",
|
|
9204
|
+
brown: "a52a2a",
|
|
9205
|
+
burlywood: "deb887",
|
|
9206
|
+
burntsienna: "ea7e5d",
|
|
9207
|
+
cadetblue: "5f9ea0",
|
|
9208
|
+
chartreuse: "7fff00",
|
|
9209
|
+
chocolate: "d2691e",
|
|
9210
|
+
coral: "ff7f50",
|
|
9211
|
+
cornflowerblue: "6495ed",
|
|
9212
|
+
cornsilk: "fff8dc",
|
|
9213
|
+
crimson: "dc143c",
|
|
9214
|
+
cyan: "0ff",
|
|
9215
|
+
darkblue: "00008b",
|
|
9216
|
+
darkcyan: "008b8b",
|
|
9217
|
+
darkgoldenrod: "b8860b",
|
|
9218
|
+
darkgray: "a9a9a9",
|
|
9219
|
+
darkgreen: "006400",
|
|
9220
|
+
darkgrey: "a9a9a9",
|
|
9221
|
+
darkkhaki: "bdb76b",
|
|
9222
|
+
darkmagenta: "8b008b",
|
|
9223
|
+
darkolivegreen: "556b2f",
|
|
9224
|
+
darkorange: "ff8c00",
|
|
9225
|
+
darkorchid: "9932cc",
|
|
9226
|
+
darkred: "8b0000",
|
|
9227
|
+
darksalmon: "e9967a",
|
|
9228
|
+
darkseagreen: "8fbc8f",
|
|
9229
|
+
darkslateblue: "483d8b",
|
|
9230
|
+
darkslategray: "2f4f4f",
|
|
9231
|
+
darkslategrey: "2f4f4f",
|
|
9232
|
+
darkturquoise: "00ced1",
|
|
9233
|
+
darkviolet: "9400d3",
|
|
9234
|
+
deeppink: "ff1493",
|
|
9235
|
+
deepskyblue: "00bfff",
|
|
9236
|
+
dimgray: "696969",
|
|
9237
|
+
dimgrey: "696969",
|
|
9238
|
+
dodgerblue: "1e90ff",
|
|
9239
|
+
firebrick: "b22222",
|
|
9240
|
+
floralwhite: "fffaf0",
|
|
9241
|
+
forestgreen: "228b22",
|
|
9242
|
+
fuchsia: "f0f",
|
|
9243
|
+
gainsboro: "dcdcdc",
|
|
9244
|
+
ghostwhite: "f8f8ff",
|
|
9245
|
+
gold: "ffd700",
|
|
9246
|
+
goldenrod: "daa520",
|
|
9247
|
+
gray: "808080",
|
|
9248
|
+
green: "008000",
|
|
9249
|
+
greenyellow: "adff2f",
|
|
9250
|
+
grey: "808080",
|
|
9251
|
+
honeydew: "f0fff0",
|
|
9252
|
+
hotpink: "ff69b4",
|
|
9253
|
+
indianred: "cd5c5c",
|
|
9254
|
+
indigo: "4b0082",
|
|
9255
|
+
ivory: "fffff0",
|
|
9256
|
+
khaki: "f0e68c",
|
|
9257
|
+
lavender: "e6e6fa",
|
|
9258
|
+
lavenderblush: "fff0f5",
|
|
9259
|
+
lawngreen: "7cfc00",
|
|
9260
|
+
lemonchiffon: "fffacd",
|
|
9261
|
+
lightblue: "add8e6",
|
|
9262
|
+
lightcoral: "f08080",
|
|
9263
|
+
lightcyan: "e0ffff",
|
|
9264
|
+
lightgoldenrodyellow: "fafad2",
|
|
9265
|
+
lightgray: "d3d3d3",
|
|
9266
|
+
lightgreen: "90ee90",
|
|
9267
|
+
lightgrey: "d3d3d3",
|
|
9268
|
+
lightpink: "ffb6c1",
|
|
9269
|
+
lightsalmon: "ffa07a",
|
|
9270
|
+
lightseagreen: "20b2aa",
|
|
9271
|
+
lightskyblue: "87cefa",
|
|
9272
|
+
lightslategray: "789",
|
|
9273
|
+
lightslategrey: "789",
|
|
9274
|
+
lightsteelblue: "b0c4de",
|
|
9275
|
+
lightyellow: "ffffe0",
|
|
9276
|
+
lime: "0f0",
|
|
9277
|
+
limegreen: "32cd32",
|
|
9278
|
+
linen: "faf0e6",
|
|
9279
|
+
magenta: "f0f",
|
|
9280
|
+
maroon: "800000",
|
|
9281
|
+
mediumaquamarine: "66cdaa",
|
|
9282
|
+
mediumblue: "0000cd",
|
|
9283
|
+
mediumorchid: "ba55d3",
|
|
9284
|
+
mediumpurple: "9370db",
|
|
9285
|
+
mediumseagreen: "3cb371",
|
|
9286
|
+
mediumslateblue: "7b68ee",
|
|
9287
|
+
mediumspringgreen: "00fa9a",
|
|
9288
|
+
mediumturquoise: "48d1cc",
|
|
9289
|
+
mediumvioletred: "c71585",
|
|
9290
|
+
midnightblue: "191970",
|
|
9291
|
+
mintcream: "f5fffa",
|
|
9292
|
+
mistyrose: "ffe4e1",
|
|
9293
|
+
moccasin: "ffe4b5",
|
|
9294
|
+
navajowhite: "ffdead",
|
|
9295
|
+
navy: "000080",
|
|
9296
|
+
oldlace: "fdf5e6",
|
|
9297
|
+
olive: "808000",
|
|
9298
|
+
olivedrab: "6b8e23",
|
|
9299
|
+
orange: "ffa500",
|
|
9300
|
+
orangered: "ff4500",
|
|
9301
|
+
orchid: "da70d6",
|
|
9302
|
+
palegoldenrod: "eee8aa",
|
|
9303
|
+
palegreen: "98fb98",
|
|
9304
|
+
paleturquoise: "afeeee",
|
|
9305
|
+
palevioletred: "db7093",
|
|
9306
|
+
papayawhip: "ffefd5",
|
|
9307
|
+
peachpuff: "ffdab9",
|
|
9308
|
+
peru: "cd853f",
|
|
9309
|
+
pink: "ffc0cb",
|
|
9310
|
+
plum: "dda0dd",
|
|
9311
|
+
powderblue: "b0e0e6",
|
|
9312
|
+
purple: "800080",
|
|
9313
|
+
rebeccapurple: "663399",
|
|
9314
|
+
red: "f00",
|
|
9315
|
+
rosybrown: "bc8f8f",
|
|
9316
|
+
royalblue: "4169e1",
|
|
9317
|
+
saddlebrown: "8b4513",
|
|
9318
|
+
salmon: "fa8072",
|
|
9319
|
+
sandybrown: "f4a460",
|
|
9320
|
+
seagreen: "2e8b57",
|
|
9321
|
+
seashell: "fff5ee",
|
|
9322
|
+
sienna: "a0522d",
|
|
9323
|
+
silver: "c0c0c0",
|
|
9324
|
+
skyblue: "87ceeb",
|
|
9325
|
+
slateblue: "6a5acd",
|
|
9326
|
+
slategray: "708090",
|
|
9327
|
+
slategrey: "708090",
|
|
9328
|
+
snow: "fffafa",
|
|
9329
|
+
springgreen: "00ff7f",
|
|
9330
|
+
steelblue: "4682b4",
|
|
9331
|
+
tan: "d2b48c",
|
|
9332
|
+
teal: "008080",
|
|
9333
|
+
thistle: "d8bfd8",
|
|
9334
|
+
tomato: "ff6347",
|
|
9335
|
+
turquoise: "40e0d0",
|
|
9336
|
+
violet: "ee82ee",
|
|
9337
|
+
wheat: "f5deb3",
|
|
9338
|
+
white: "fff",
|
|
9339
|
+
whitesmoke: "f5f5f5",
|
|
9340
|
+
yellow: "ff0",
|
|
9341
|
+
yellowgreen: "9acd32"
|
|
9342
|
+
};
|
|
9343
|
+
|
|
9344
|
+
// Make it easy to access colors via `hexNames[hex]`
|
|
9345
|
+
var hexNames = tinycolor.hexNames = flip(names);
|
|
9346
|
+
|
|
9347
|
+
// Utilities
|
|
9348
|
+
// ---------
|
|
9349
|
+
|
|
9350
|
+
// `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
|
|
9351
|
+
function flip(o) {
|
|
9352
|
+
var flipped = {};
|
|
9353
|
+
for (var i in o) {
|
|
9354
|
+
if (o.hasOwnProperty(i)) {
|
|
9355
|
+
flipped[o[i]] = i;
|
|
9356
|
+
}
|
|
9357
|
+
}
|
|
9358
|
+
return flipped;
|
|
9359
|
+
}
|
|
9360
|
+
|
|
9361
|
+
// Return a valid alpha value [0,1] with all invalid values being set to 1
|
|
9362
|
+
function boundAlpha(a) {
|
|
9363
|
+
a = parseFloat(a);
|
|
9364
|
+
if (isNaN(a) || a < 0 || a > 1) {
|
|
9365
|
+
a = 1;
|
|
9366
|
+
}
|
|
9367
|
+
return a;
|
|
9368
|
+
}
|
|
9369
|
+
|
|
9370
|
+
// Take input from [0, n] and return it as [0, 1]
|
|
9371
|
+
function bound01(n, max) {
|
|
9372
|
+
if (isOnePointZero(n)) n = "100%";
|
|
9373
|
+
var processPercent = isPercentage(n);
|
|
9374
|
+
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
9375
|
+
|
|
9376
|
+
// Automatically convert percentage into number
|
|
9377
|
+
if (processPercent) {
|
|
9378
|
+
n = parseInt(n * max, 10) / 100;
|
|
9379
|
+
}
|
|
9380
|
+
|
|
9381
|
+
// Handle floating point rounding errors
|
|
9382
|
+
if (Math.abs(n - max) < 0.000001) {
|
|
9383
|
+
return 1;
|
|
9384
|
+
}
|
|
9385
|
+
|
|
9386
|
+
// Convert into [0, 1] range if it isn't already
|
|
9387
|
+
return n % max / parseFloat(max);
|
|
9388
|
+
}
|
|
9389
|
+
|
|
9390
|
+
// Force a number between 0 and 1
|
|
9391
|
+
function clamp01(val) {
|
|
9392
|
+
return Math.min(1, Math.max(0, val));
|
|
9393
|
+
}
|
|
9394
|
+
|
|
9395
|
+
// Parse a base-16 hex value into a base-10 integer
|
|
9396
|
+
function parseIntFromHex(val) {
|
|
9397
|
+
return parseInt(val, 16);
|
|
9398
|
+
}
|
|
9399
|
+
|
|
9400
|
+
// Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
|
|
9401
|
+
// <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
|
|
9402
|
+
function isOnePointZero(n) {
|
|
9403
|
+
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
9404
|
+
}
|
|
9405
|
+
|
|
9406
|
+
// Check to see if string passed in is a percentage
|
|
9407
|
+
function isPercentage(n) {
|
|
9408
|
+
return typeof n === "string" && n.indexOf("%") != -1;
|
|
9409
|
+
}
|
|
9410
|
+
|
|
9411
|
+
// Force a hex value to have 2 characters
|
|
9412
|
+
function pad2(c) {
|
|
9413
|
+
return c.length == 1 ? "0" + c : "" + c;
|
|
9414
|
+
}
|
|
9415
|
+
|
|
9416
|
+
// Replace a decimal with it's percentage value
|
|
9417
|
+
function convertToPercentage(n) {
|
|
9418
|
+
if (n <= 1) {
|
|
9419
|
+
n = n * 100 + "%";
|
|
9420
|
+
}
|
|
9421
|
+
return n;
|
|
9422
|
+
}
|
|
9423
|
+
|
|
9424
|
+
// Converts a decimal to a hex value
|
|
9425
|
+
function convertDecimalToHex(d) {
|
|
9426
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
9427
|
+
}
|
|
9428
|
+
// Converts a hex value to a decimal
|
|
9429
|
+
function convertHexToDecimal(h) {
|
|
9430
|
+
return parseIntFromHex(h) / 255;
|
|
9431
|
+
}
|
|
9432
|
+
var matchers = function () {
|
|
9433
|
+
// <http://www.w3.org/TR/css3-values/#integers>
|
|
9434
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
9435
|
+
|
|
9436
|
+
// <http://www.w3.org/TR/css3-values/#number-value>
|
|
9437
|
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
9438
|
+
|
|
9439
|
+
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
|
9440
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
9441
|
+
|
|
9442
|
+
// Actual matching.
|
|
9443
|
+
// Parentheses and commas are optional, but not required.
|
|
9444
|
+
// Whitespace can take the place of commas or opening paren
|
|
9445
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
9446
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
9447
|
+
return {
|
|
9448
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
9449
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
9450
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
9451
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
9452
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
9453
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
9454
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
9455
|
+
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
9456
|
+
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
9457
|
+
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
9458
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
9459
|
+
};
|
|
9460
|
+
}();
|
|
9461
|
+
|
|
9462
|
+
// `isValidCSSUnit`
|
|
9463
|
+
// Take in a single string / number and check to see if it looks like a CSS unit
|
|
9464
|
+
// (see `matchers` above for definition).
|
|
9465
|
+
function isValidCSSUnit(color) {
|
|
9466
|
+
return !!matchers.CSS_UNIT.exec(color);
|
|
9467
|
+
}
|
|
9468
|
+
|
|
9469
|
+
// `stringInputToObject`
|
|
9470
|
+
// Permissive string parsing. Take in a number of formats, and output an object
|
|
9471
|
+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
|
|
9472
|
+
function stringInputToObject(color) {
|
|
9473
|
+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
9474
|
+
var named = false;
|
|
9475
|
+
if (names[color]) {
|
|
9476
|
+
color = names[color];
|
|
9477
|
+
named = true;
|
|
9478
|
+
} else if (color == "transparent") {
|
|
9479
|
+
return {
|
|
9480
|
+
r: 0,
|
|
9481
|
+
g: 0,
|
|
9482
|
+
b: 0,
|
|
9483
|
+
a: 0,
|
|
9484
|
+
format: "name"
|
|
9485
|
+
};
|
|
9486
|
+
}
|
|
9487
|
+
|
|
9488
|
+
// Try to match string input using regular expressions.
|
|
9489
|
+
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
|
|
9490
|
+
// Just return an object and let the conversion functions handle that.
|
|
9491
|
+
// This way the result will be the same whether the tinycolor is initialized with string or object.
|
|
9492
|
+
var match;
|
|
9493
|
+
if (match = matchers.rgb.exec(color)) {
|
|
9494
|
+
return {
|
|
9495
|
+
r: match[1],
|
|
9496
|
+
g: match[2],
|
|
9497
|
+
b: match[3]
|
|
9498
|
+
};
|
|
9499
|
+
}
|
|
9500
|
+
if (match = matchers.rgba.exec(color)) {
|
|
9501
|
+
return {
|
|
9502
|
+
r: match[1],
|
|
9503
|
+
g: match[2],
|
|
9504
|
+
b: match[3],
|
|
9505
|
+
a: match[4]
|
|
9506
|
+
};
|
|
9507
|
+
}
|
|
9508
|
+
if (match = matchers.hsl.exec(color)) {
|
|
9509
|
+
return {
|
|
9510
|
+
h: match[1],
|
|
9511
|
+
s: match[2],
|
|
9512
|
+
l: match[3]
|
|
9513
|
+
};
|
|
9514
|
+
}
|
|
9515
|
+
if (match = matchers.hsla.exec(color)) {
|
|
9516
|
+
return {
|
|
9517
|
+
h: match[1],
|
|
9518
|
+
s: match[2],
|
|
9519
|
+
l: match[3],
|
|
9520
|
+
a: match[4]
|
|
9521
|
+
};
|
|
9522
|
+
}
|
|
9523
|
+
if (match = matchers.hsv.exec(color)) {
|
|
9524
|
+
return {
|
|
9525
|
+
h: match[1],
|
|
9526
|
+
s: match[2],
|
|
9527
|
+
v: match[3]
|
|
9528
|
+
};
|
|
9529
|
+
}
|
|
9530
|
+
if (match = matchers.hsva.exec(color)) {
|
|
9531
|
+
return {
|
|
9532
|
+
h: match[1],
|
|
9533
|
+
s: match[2],
|
|
9534
|
+
v: match[3],
|
|
9535
|
+
a: match[4]
|
|
9536
|
+
};
|
|
9537
|
+
}
|
|
9538
|
+
if (match = matchers.hex8.exec(color)) {
|
|
9539
|
+
return {
|
|
9540
|
+
r: parseIntFromHex(match[1]),
|
|
9541
|
+
g: parseIntFromHex(match[2]),
|
|
9542
|
+
b: parseIntFromHex(match[3]),
|
|
9543
|
+
a: convertHexToDecimal(match[4]),
|
|
9544
|
+
format: named ? "name" : "hex8"
|
|
9545
|
+
};
|
|
9546
|
+
}
|
|
9547
|
+
if (match = matchers.hex6.exec(color)) {
|
|
9548
|
+
return {
|
|
9549
|
+
r: parseIntFromHex(match[1]),
|
|
9550
|
+
g: parseIntFromHex(match[2]),
|
|
9551
|
+
b: parseIntFromHex(match[3]),
|
|
9552
|
+
format: named ? "name" : "hex"
|
|
9553
|
+
};
|
|
9554
|
+
}
|
|
9555
|
+
if (match = matchers.hex4.exec(color)) {
|
|
9556
|
+
return {
|
|
9557
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
9558
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
9559
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
9560
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
9561
|
+
format: named ? "name" : "hex8"
|
|
9562
|
+
};
|
|
9563
|
+
}
|
|
9564
|
+
if (match = matchers.hex3.exec(color)) {
|
|
9565
|
+
return {
|
|
9566
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
9567
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
9568
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
9569
|
+
format: named ? "name" : "hex"
|
|
9570
|
+
};
|
|
9571
|
+
}
|
|
9572
|
+
return false;
|
|
9573
|
+
}
|
|
9574
|
+
function validateWCAG2Parms(parms) {
|
|
9575
|
+
// return valid WCAG2 parms for isReadable.
|
|
9576
|
+
// If input parms are invalid, return {"level":"AA", "size":"small"}
|
|
9577
|
+
var level, size;
|
|
9578
|
+
parms = parms || {
|
|
9579
|
+
level: "AA",
|
|
9580
|
+
size: "small"
|
|
9581
|
+
};
|
|
9582
|
+
level = (parms.level || "AA").toUpperCase();
|
|
9583
|
+
size = (parms.size || "small").toLowerCase();
|
|
9584
|
+
if (level !== "AA" && level !== "AAA") {
|
|
9585
|
+
level = "AA";
|
|
9586
|
+
}
|
|
9587
|
+
if (size !== "small" && size !== "large") {
|
|
9588
|
+
size = "small";
|
|
9589
|
+
}
|
|
9590
|
+
return {
|
|
9591
|
+
level: level,
|
|
9592
|
+
size: size
|
|
9593
|
+
};
|
|
9594
|
+
}
|
|
9595
|
+
|
|
9596
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9597
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9598
|
+
// WCAG2ContrastOptions are the options used to determine if a color is readable
|
|
9599
|
+
var WCAG2ContrastOptions = {
|
|
9600
|
+
level: 'AAA',
|
|
9601
|
+
size: 'large'
|
|
9602
|
+
};
|
|
9603
|
+
|
|
9604
|
+
/**
|
|
9605
|
+
* getColorWithOpacity
|
|
9606
|
+
* @param color - The color to add opacity to
|
|
9607
|
+
* @param opacity - The opacity to add to the color
|
|
9608
|
+
* @returns The color with the opacity added
|
|
9609
|
+
* @example
|
|
9610
|
+
* getColorWithOpacity('#fff', 0.5) // returns 'hsla(0, 0%, 100%, 0.5)'
|
|
9611
|
+
*
|
|
9612
|
+
**/
|
|
9613
|
+
var getColorWithOpacity = function getColorWithOpacity(color, opacity) {
|
|
9614
|
+
return tinycolor(color).setAlpha(opacity).toHslString();
|
|
9615
|
+
};
|
|
9616
|
+
|
|
9617
|
+
/**
|
|
9618
|
+
*
|
|
9619
|
+
* @description
|
|
9620
|
+
* Generates a chromatic color palette based on the base color passed in.
|
|
9621
|
+
* The base color is used to generate a palette of 11 colors, 5 shades lighter and 5 shades darker than the base color.
|
|
9622
|
+
* @param baseColorInput - The base color to generate the chromatic color palette from in hex, rgb, or hsl format
|
|
9623
|
+
* @returns Array of chromatic color palette
|
|
9624
|
+
*/
|
|
9625
|
+
var generateChromaticBrandColors = function generateChromaticBrandColors(baseColorInput) {
|
|
9626
|
+
var baseColor = tinycolor(baseColorInput);
|
|
9627
|
+
var baseColorHslString = baseColor.toHslString();
|
|
9628
|
+
var palette = [baseColorHslString]; // Include the original color
|
|
9629
|
+
var brightness = tinycolor(baseColor).getBrightness();
|
|
9630
|
+
// Determine how much to lighten or darken the colors depending on the brightness of the base color
|
|
9631
|
+
var lightnessFactor = brightness > 150 ? 3 : 6;
|
|
9632
|
+
var darknessFactor = brightness < 50 ? 3 : 5;
|
|
9633
|
+
var currentColor = baseColor;
|
|
9634
|
+
|
|
9635
|
+
// Generate shades lighter
|
|
9636
|
+
for (var lightShadeIndex = 0; lightShadeIndex < 6; lightShadeIndex++) {
|
|
9637
|
+
currentColor = currentColor.brighten(lightnessFactor);
|
|
9638
|
+
palette.push(currentColor.toHslString());
|
|
9639
|
+
}
|
|
9640
|
+
currentColor = tinycolor(baseColorHslString); // Reset to the base color
|
|
9641
|
+
|
|
9642
|
+
// Generate shades darker
|
|
9643
|
+
for (var darkShadeIndex = 0; darkShadeIndex < 4; darkShadeIndex++) {
|
|
9644
|
+
currentColor = currentColor.darken(darknessFactor);
|
|
9645
|
+
palette.unshift(currentColor.toHslString()); // Add shades at the beginning of the palette
|
|
9646
|
+
}
|
|
9647
|
+
|
|
9648
|
+
var colorPalette = palette.reverse();
|
|
9649
|
+
var brandPrimaryColor = colorPalette[6];
|
|
9650
|
+
var brandColors = {
|
|
9651
|
+
'50': colorPalette[0],
|
|
9652
|
+
'100': colorPalette[1],
|
|
9653
|
+
'200': colorPalette[2],
|
|
9654
|
+
'300': colorPalette[3],
|
|
9655
|
+
'400': colorPalette[4],
|
|
9656
|
+
'500': colorPalette[5],
|
|
9657
|
+
'600': brandPrimaryColor,
|
|
9658
|
+
'700': colorPalette[7],
|
|
9659
|
+
'800': colorPalette[8],
|
|
9660
|
+
'900': colorPalette[9],
|
|
9661
|
+
'950': colorPalette[10],
|
|
9662
|
+
a00: getColorWithOpacity(brandPrimaryColor, opacity[0]),
|
|
9663
|
+
a50: getColorWithOpacity(brandPrimaryColor, opacity[1]),
|
|
9664
|
+
a100: getColorWithOpacity(brandPrimaryColor, opacity[2]),
|
|
9665
|
+
a200: getColorWithOpacity(brandPrimaryColor, opacity[3])
|
|
9666
|
+
};
|
|
9667
|
+
return brandColors;
|
|
9668
|
+
};
|
|
9669
|
+
|
|
9670
|
+
/**
|
|
9671
|
+
*
|
|
9672
|
+
* @param brandColors - The brand colors to use to override the light theme
|
|
9673
|
+
* @description Returns overrides for the light theme with the brand colors passed in
|
|
9674
|
+
* @returns Overrides for the light theme with the custom brand colors
|
|
9675
|
+
*/
|
|
9676
|
+
var getOnLightOverrides = function getOnLightOverrides(brandColors) {
|
|
9677
|
+
// Select the most readable color to use as the foreground color on top of brand color
|
|
9678
|
+
// For example: On Primary Button where the background color is brand color, the text color should be either dark or light depending on which is more readable on top of that brand color
|
|
9679
|
+
var foregroundOnBrandColorLight = tinycolor.mostReadable(brandColors[800], [colors$2.neutral.blueGrayLight[1300], colors$2.neutral.blueGrayLight[0]], WCAG2ContrastOptions).toHslString();
|
|
9680
|
+
|
|
9681
|
+
// Select the most readable color to use as the foreground color on top of surface color
|
|
9682
|
+
// For example: On Secondary Button where the background color is surface color, the text color should be either the brand color or dark color depending on which is more readable on top of that surface color
|
|
9683
|
+
var foregroundOnSurfaceLight = tinycolor.isReadable(colors$2.neutral.blueGrayLight[50], brandColors[600], WCAG2ContrastOptions) ? brandColors[600] : colors$2.neutral.blueGrayLight[1100];
|
|
9684
|
+
|
|
9685
|
+
// Overrides for the light theme with the brand colors passed in
|
|
9686
|
+
var lightThemeOverrides = {
|
|
9687
|
+
colors: {
|
|
9688
|
+
onLight: {
|
|
9689
|
+
brand: {
|
|
9690
|
+
primary: {
|
|
9691
|
+
300: brandColors.a50,
|
|
9692
|
+
400: brandColors.a100,
|
|
9693
|
+
500: brandColors[600],
|
|
9694
|
+
600: brandColors[700],
|
|
9695
|
+
700: brandColors[800],
|
|
9696
|
+
800: brandColors[950]
|
|
9697
|
+
},
|
|
9698
|
+
gray: {
|
|
9699
|
+
200: {
|
|
9700
|
+
lowContrast: foregroundOnBrandColorLight
|
|
9701
|
+
}
|
|
9702
|
+
}
|
|
9703
|
+
},
|
|
9704
|
+
action: {
|
|
9705
|
+
background: {
|
|
9706
|
+
primary: {
|
|
9707
|
+
"default": brandColors[600],
|
|
9708
|
+
hover: brandColors[700],
|
|
9709
|
+
focus: brandColors[800],
|
|
9710
|
+
active: brandColors[900]
|
|
9711
|
+
},
|
|
9712
|
+
secondary: {
|
|
9713
|
+
"default": brandColors.a00,
|
|
9714
|
+
hover: brandColors.a50,
|
|
9715
|
+
focus: brandColors.a100,
|
|
9716
|
+
active: brandColors.a200
|
|
9717
|
+
},
|
|
9718
|
+
tertiary: {
|
|
9719
|
+
"default": colors$2.neutral.blueGrayLight[0],
|
|
9720
|
+
hover: colors$2.neutral.blueGrayLight[50],
|
|
9721
|
+
focus: colors$2.neutral.blueGrayLight[100],
|
|
9722
|
+
active: colors$2.neutral.blueGrayLight[200]
|
|
9723
|
+
}
|
|
9724
|
+
},
|
|
9725
|
+
border: {
|
|
9726
|
+
primary: {
|
|
9727
|
+
"default": brandColors[600],
|
|
9728
|
+
hover: brandColors[700],
|
|
9729
|
+
focus: brandColors[800],
|
|
9730
|
+
active: brandColors[900]
|
|
9731
|
+
},
|
|
9732
|
+
secondary: {
|
|
9733
|
+
"default": brandColors[600],
|
|
9734
|
+
hover: brandColors[600],
|
|
9735
|
+
focus: brandColors[600],
|
|
9736
|
+
active: brandColors[600]
|
|
9737
|
+
},
|
|
9738
|
+
tertiary: {
|
|
9739
|
+
"default": colors$2.neutral.blueGrayLight[300],
|
|
9740
|
+
hover: colors$2.neutral.blueGrayLight[300],
|
|
9741
|
+
focus: colors$2.neutral.blueGrayLight[300],
|
|
9742
|
+
active: colors$2.neutral.blueGrayLight[300]
|
|
9743
|
+
}
|
|
9744
|
+
},
|
|
9745
|
+
text: {
|
|
9746
|
+
primary: {
|
|
9747
|
+
"default": foregroundOnBrandColorLight,
|
|
9748
|
+
hover: foregroundOnBrandColorLight,
|
|
9749
|
+
focus: foregroundOnBrandColorLight,
|
|
9750
|
+
active: foregroundOnBrandColorLight
|
|
9751
|
+
},
|
|
9752
|
+
secondary: {
|
|
9753
|
+
"default": foregroundOnSurfaceLight,
|
|
9754
|
+
hover: foregroundOnSurfaceLight,
|
|
9755
|
+
focus: foregroundOnSurfaceLight,
|
|
9756
|
+
active: foregroundOnSurfaceLight
|
|
9757
|
+
}
|
|
9758
|
+
},
|
|
9759
|
+
icon: {
|
|
9760
|
+
primary: {
|
|
9761
|
+
"default": foregroundOnBrandColorLight,
|
|
9762
|
+
hover: foregroundOnBrandColorLight,
|
|
9763
|
+
focus: foregroundOnBrandColorLight,
|
|
9764
|
+
active: foregroundOnBrandColorLight
|
|
9765
|
+
},
|
|
9766
|
+
secondary: {
|
|
9767
|
+
"default": foregroundOnSurfaceLight,
|
|
9768
|
+
hover: foregroundOnSurfaceLight,
|
|
9769
|
+
focus: foregroundOnSurfaceLight,
|
|
9770
|
+
active: foregroundOnSurfaceLight
|
|
9771
|
+
}
|
|
9772
|
+
}
|
|
9773
|
+
}
|
|
9774
|
+
}
|
|
9775
|
+
}
|
|
9776
|
+
};
|
|
9777
|
+
return lightThemeOverrides;
|
|
9778
|
+
};
|
|
9779
|
+
|
|
9780
|
+
/**
|
|
9781
|
+
*
|
|
9782
|
+
* @param brandColors - The brand colors to use to override the dark theme
|
|
9783
|
+
* @description Returns overrides for the dark theme with the brand colors passed in
|
|
9784
|
+
* @returns Overrides for the dark theme with the custom brand colors
|
|
9785
|
+
*/
|
|
9786
|
+
var getOnDarkOverrides = function getOnDarkOverrides(brandColors) {
|
|
9787
|
+
// Select the most readable color to use as the foreground color on top of brand color
|
|
9788
|
+
// For example: On Primary Button where the background color is brand color, the text color should be either dark or light depending on which is more readable on top of that brand color
|
|
9789
|
+
var foregroundOnBrandColorDark = tinycolor.mostReadable(brandColors[800], [colors$2.neutral.blueGrayDark[800], colors$2.neutral.blueGrayDark[0]], WCAG2ContrastOptions).toHslString();
|
|
9790
|
+
|
|
9791
|
+
// Select the most readable color to use as the foreground color on top of surface color
|
|
9792
|
+
// For example: On Secondary Button where the background color is surface color, the text color should be either the brand color or light color depending on which is more readable on top of that surface color
|
|
9793
|
+
var foregroundOnSurfaceDark = tinycolor.isReadable(colors$2.neutral.blueGrayDark[1100], brandColors[400], WCAG2ContrastOptions) ? brandColors[400] : colors$2.neutral.blueGrayDark[0];
|
|
9794
|
+
|
|
9795
|
+
// Overrides for the dark theme with the brand colors passed in
|
|
9796
|
+
var darkThemeOverrides = {
|
|
9797
|
+
colors: {
|
|
9798
|
+
onDark: {
|
|
9799
|
+
brand: {
|
|
9800
|
+
primary: {
|
|
9801
|
+
300: brandColors.a100,
|
|
9802
|
+
400: brandColors.a200,
|
|
9803
|
+
500: brandColors[400],
|
|
9804
|
+
600: brandColors[500],
|
|
9805
|
+
700: brandColors[600],
|
|
9806
|
+
800: brandColors[900]
|
|
9807
|
+
},
|
|
9808
|
+
gray: {
|
|
9809
|
+
200: {
|
|
9810
|
+
lowContrast: foregroundOnBrandColorDark
|
|
9811
|
+
}
|
|
9812
|
+
}
|
|
9813
|
+
},
|
|
9814
|
+
action: {
|
|
9815
|
+
background: {
|
|
9816
|
+
primary: {
|
|
9817
|
+
"default": brandColors[500],
|
|
9818
|
+
hover: brandColors[600],
|
|
9819
|
+
focus: brandColors[700],
|
|
9820
|
+
active: brandColors[800]
|
|
9821
|
+
},
|
|
9822
|
+
secondary: {
|
|
9823
|
+
"default": brandColors.a00,
|
|
9824
|
+
hover: brandColors.a50,
|
|
9825
|
+
focus: brandColors.a100,
|
|
9826
|
+
active: brandColors.a200
|
|
9827
|
+
}
|
|
9828
|
+
},
|
|
9829
|
+
border: {
|
|
9830
|
+
primary: {
|
|
9831
|
+
"default": brandColors[500],
|
|
9832
|
+
hover: brandColors[600],
|
|
9833
|
+
focus: brandColors[700],
|
|
9834
|
+
active: brandColors[800]
|
|
9835
|
+
},
|
|
9836
|
+
secondary: {
|
|
9837
|
+
"default": brandColors[400],
|
|
9838
|
+
hover: brandColors[400],
|
|
9839
|
+
focus: brandColors[400],
|
|
9840
|
+
active: brandColors[400]
|
|
9841
|
+
}
|
|
9842
|
+
},
|
|
9843
|
+
text: {
|
|
9844
|
+
primary: {
|
|
9845
|
+
"default": foregroundOnBrandColorDark,
|
|
9846
|
+
hover: foregroundOnBrandColorDark,
|
|
9847
|
+
focus: foregroundOnBrandColorDark,
|
|
9848
|
+
active: foregroundOnBrandColorDark
|
|
9849
|
+
},
|
|
9850
|
+
secondary: {
|
|
9851
|
+
"default": foregroundOnSurfaceDark,
|
|
9852
|
+
hover: foregroundOnSurfaceDark,
|
|
9853
|
+
focus: foregroundOnSurfaceDark,
|
|
9854
|
+
active: foregroundOnSurfaceDark
|
|
9855
|
+
}
|
|
9856
|
+
},
|
|
9857
|
+
icon: {
|
|
9858
|
+
primary: {
|
|
9859
|
+
"default": foregroundOnBrandColorDark,
|
|
9860
|
+
hover: foregroundOnBrandColorDark,
|
|
9861
|
+
focus: foregroundOnBrandColorDark,
|
|
9862
|
+
active: foregroundOnBrandColorDark
|
|
9863
|
+
},
|
|
9864
|
+
secondary: {
|
|
9865
|
+
"default": foregroundOnSurfaceDark,
|
|
9866
|
+
hover: foregroundOnSurfaceDark,
|
|
9867
|
+
focus: foregroundOnSurfaceDark,
|
|
9868
|
+
active: foregroundOnSurfaceDark
|
|
9869
|
+
}
|
|
9870
|
+
}
|
|
9871
|
+
}
|
|
9872
|
+
}
|
|
9873
|
+
}
|
|
9874
|
+
};
|
|
9875
|
+
return darkThemeOverrides;
|
|
9876
|
+
};
|
|
9877
|
+
|
|
9878
|
+
/**
|
|
9879
|
+
* @param {Object} themeConfig - The brand color and overrides to apply to the theme
|
|
9880
|
+
* @param {string} themeConfig.brandColor - The brand color to use to generate the theme. Can be in hex, rgb, or hsl format.
|
|
9881
|
+
* @description
|
|
9882
|
+
* Creates a Blade Theme based on the custom brand color
|
|
9883
|
+
* @returns The Theme Tokens with the custom brand colors
|
|
9884
|
+
* @example
|
|
9885
|
+
* const theme = createTheme({ brandColor: '#19BEA2'})
|
|
9886
|
+
**/
|
|
9887
|
+
var createTheme = function createTheme(_ref) {
|
|
9888
|
+
var _brandedLightTheme$co, _brandedDarkTheme$col;
|
|
9889
|
+
var brandColor = _ref.brandColor;
|
|
9890
|
+
var chromaticBrandColors = generateChromaticBrandColors(brandColor);
|
|
9891
|
+
// Get onLight overrides
|
|
9892
|
+
var brandedLightTheme = getOnLightOverrides(chromaticBrandColors);
|
|
9893
|
+
// Get onDark overrides
|
|
9894
|
+
var brandedDarkTheme = getOnDarkOverrides(chromaticBrandColors);
|
|
9895
|
+
|
|
9896
|
+
// Override the payment theme with the brand colors
|
|
9897
|
+
var brandedThemeTokens = overrideTheme({
|
|
9898
|
+
baseThemeTokens: paymentTheme,
|
|
9899
|
+
overrides: {
|
|
9900
|
+
name: "custom-".concat(tinycolor(brandColor).toHex()),
|
|
9901
|
+
colors: {
|
|
9902
|
+
onLight: _objectSpread({}, brandedLightTheme === null || brandedLightTheme === void 0 ? void 0 : (_brandedLightTheme$co = brandedLightTheme.colors) === null || _brandedLightTheme$co === void 0 ? void 0 : _brandedLightTheme$co.onLight),
|
|
9903
|
+
onDark: _objectSpread({}, brandedDarkTheme === null || brandedDarkTheme === void 0 ? void 0 : (_brandedDarkTheme$col = brandedDarkTheme.colors) === null || _brandedDarkTheme$col === void 0 ? void 0 : _brandedDarkTheme$col.onDark)
|
|
9904
|
+
}
|
|
9905
|
+
}
|
|
9906
|
+
});
|
|
9907
|
+
return brandedThemeTokens;
|
|
9908
|
+
};
|
|
9909
|
+
|
|
9910
|
+
export { bankingTheme, border, breakpoints, colors$2 as colors, createTheme, elevation, motion, opacity, overrideTheme, paymentTheme, size, spacing, typography };
|
|
8485
9911
|
//# sourceMappingURL=index.production.web.js.map
|