color-interfaces
Advanced tools
Comparing version
import { Color as Color_ } from './ColorInterface'; | ||
import RGBInterface from './RGBInterface'; | ||
import RGBAInterface from './RGBAInterface'; | ||
import HSLInterface from './HSLInterface'; | ||
@@ -27,2 +28,3 @@ import HSVInterface from './HSVInterface'; | ||
private _rgb; | ||
private _rgba; | ||
private _hsl; | ||
@@ -34,2 +36,3 @@ private _hsv; | ||
get rgb(): RGBInterface; | ||
get rgba(): RGBAInterface; | ||
get hsl(): HSLInterface; | ||
@@ -61,2 +64,3 @@ get hsv(): HSVInterface; | ||
copy(): Color; | ||
mixWithColor(color: Color, percent: number): this; | ||
private updateHslFromRgb; | ||
@@ -63,0 +67,0 @@ private updateRgbFromHsl; |
export interface Color { | ||
rgb: RGBInterface; | ||
rgba: RGBAInterface; | ||
hsl: HSLInterface; | ||
@@ -29,2 +30,3 @@ hsv: HSVInterface; | ||
copy: () => Color; | ||
mixWithColor(color: Color, percent: number): Color; | ||
} | ||
@@ -36,5 +38,14 @@ export interface RGBInterface { | ||
get: () => RGB; | ||
set: (rgb: RGB) => void; | ||
set: (rgb: RGB) => RGBInterface; | ||
toCss: () => string; | ||
} | ||
export interface RGBAInterface { | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
get: () => RGBA; | ||
set: (rgba: RGBA) => RGBAInterface; | ||
toCss: () => string; | ||
} | ||
export interface HSLInterface { | ||
@@ -45,3 +56,3 @@ h: number; | ||
get: () => HSL; | ||
set: (hsv: HSL) => void; | ||
set: (hsv: HSL) => HSLInterface; | ||
toCss: () => string; | ||
@@ -54,3 +65,3 @@ } | ||
get: () => HSV; | ||
set: (hsv: HSV) => void; | ||
set: (hsv: HSV) => HSVInterface; | ||
toCss: () => string; | ||
@@ -60,3 +71,3 @@ } | ||
get: () => HEX; | ||
set: (hex: HEX) => void; | ||
set: (hex: HEX) => HexInterface; | ||
toCss: () => string; | ||
@@ -63,0 +74,0 @@ } |
@@ -1,6 +0,6 @@ | ||
import { Color, HexInterface as HexInterface_, HEX } from './ColorInterface'; | ||
import { Color, HexInterface as HexInterface_, HEX } from "./ColorInterface"; | ||
declare class HexInterface implements HexInterface_ { | ||
private color; | ||
constructor(color: Color); | ||
set(hex: HEX): void; | ||
set(hex: HEX): this; | ||
get(): string; | ||
@@ -7,0 +7,0 @@ toCss(): string; |
@@ -1,2 +0,2 @@ | ||
import { Color, HSLInterface as HSLInterface_, HSL } from './ColorInterface'; | ||
import { Color, HSLInterface as HSLInterface_, HSL } from "./ColorInterface"; | ||
declare class HSLInterface implements HSLInterface_ { | ||
@@ -12,5 +12,5 @@ private color; | ||
get(): HSL; | ||
set(hsl: HSL): void; | ||
set(hsl: HSL): this; | ||
toCss(): string; | ||
} | ||
export default HSLInterface; |
@@ -1,2 +0,2 @@ | ||
import { Color, HSVInterface as HSVInterface_, HSV } from './ColorInterface'; | ||
import { Color, HSVInterface as HSVInterface_, HSV } from "./ColorInterface"; | ||
declare class HSVInterface implements HSVInterface_ { | ||
@@ -12,5 +12,5 @@ private color; | ||
get(): HSV; | ||
set(hsv: HSV): void; | ||
set(hsv: HSV): this; | ||
toCss(): string; | ||
} | ||
export default HSVInterface; |
import Color from './Color'; | ||
export default Color; | ||
export { default as RGBInterface } from './RGBInterface'; | ||
export { default as RGBAInterface } from './RGBAInterface'; | ||
export { default as HSLInterface } from './HSLInterface'; | ||
@@ -8,1 +9,2 @@ export { default as HSVInterface } from './HSVInterface'; | ||
export { RGB, RGBA, HSL, HSLA, HSV, HSVA, HEX } from './ColorInterface'; | ||
export { ColorType } from './consts'; |
207
dist/main.js
@@ -85,3 +85,3 @@ module.exports = | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 6); | ||
/******/ return __webpack_require__(__webpack_require__.s = 8); | ||
/******/ }) | ||
@@ -121,2 +121,15 @@ /************************************************************************/ | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __read = (this && this.__read) || function (o, n) { | ||
@@ -138,8 +151,40 @@ var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var RGBInterface = /** @class */ (function () { | ||
function RGBInterface(color) { | ||
var BaseRGBInterface_1 = __importDefault(__webpack_require__(2)); | ||
var RGBInterface = /** @class */ (function (_super) { | ||
__extends(RGBInterface, _super); | ||
function RGBInterface() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
RGBInterface.prototype.get = function () { | ||
return [this.r, this.g, this.b]; | ||
}; | ||
RGBInterface.prototype.set = function (rgb) { | ||
var _a; | ||
_a = __read(rgb, 3), this.r = _a[0], this.g = _a[1], this.b = _a[2]; | ||
return this; | ||
}; | ||
RGBInterface.prototype.toCss = function () { | ||
return "rgb(" + this.r + ", " + this.g + ", " + this.b + ")"; | ||
}; | ||
return RGBInterface; | ||
}(BaseRGBInterface_1.default)); | ||
exports.default = RGBInterface; | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var BaseRGBInterface = /** @class */ (function () { | ||
function BaseRGBInterface(color) { | ||
this.color = color; | ||
} | ||
Object.defineProperty(RGBInterface.prototype, "r", { | ||
Object.defineProperty(BaseRGBInterface.prototype, "r", { | ||
get: function () { | ||
@@ -154,3 +199,3 @@ return this.color.getRed(); | ||
}); | ||
Object.defineProperty(RGBInterface.prototype, "g", { | ||
Object.defineProperty(BaseRGBInterface.prototype, "g", { | ||
get: function () { | ||
@@ -165,3 +210,3 @@ return this.color.getGreen(); | ||
}); | ||
Object.defineProperty(RGBInterface.prototype, "b", { | ||
Object.defineProperty(BaseRGBInterface.prototype, "b", { | ||
get: function () { | ||
@@ -176,19 +221,80 @@ return this.color.getBlue(); | ||
}); | ||
RGBInterface.prototype.get = function () { | ||
return [this.r, this.g, this.b]; | ||
return BaseRGBInterface; | ||
}()); | ||
exports.default = BaseRGBInterface; | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
RGBInterface.prototype.set = function (rgb) { | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var BaseRGBInterface_1 = __importDefault(__webpack_require__(2)); | ||
var RGBAInterface = /** @class */ (function (_super) { | ||
__extends(RGBAInterface, _super); | ||
function RGBAInterface() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
Object.defineProperty(RGBAInterface.prototype, "a", { | ||
get: function () { | ||
return this.color.alpha; | ||
}, | ||
set: function (alpha) { | ||
this.color.alpha = alpha; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
RGBAInterface.prototype.get = function () { | ||
return [this.r, this.g, this.b, this.a]; | ||
}; | ||
RGBAInterface.prototype.set = function (rgba) { | ||
var _a; | ||
_a = __read(rgb, 3), this.r = _a[0], this.g = _a[1], this.b = _a[2]; | ||
_a = __read(rgba, 4), this.r = _a[0], this.g = _a[1], this.b = _a[2], this.a = _a[3]; | ||
return this; | ||
}; | ||
RGBInterface.prototype.toCss = function () { | ||
return "rgb(" + this.r + ", " + this.g + ", " + this.b + ")"; | ||
RGBAInterface.prototype.toCss = function () { | ||
return "rgba(" + this.r + ", " + this.g + ", " + this.b + ", " + this.a.toFixed(2) + ")"; | ||
}; | ||
return RGBInterface; | ||
}()); | ||
exports.default = RGBInterface; | ||
return RGBAInterface; | ||
}(BaseRGBInterface_1.default)); | ||
exports.default = RGBAInterface; | ||
/***/ }), | ||
/* 2 */ | ||
/* 4 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -215,3 +321,3 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils_1 = __webpack_require__(3); | ||
var utils_1 = __webpack_require__(5); | ||
var HSLInterface = /** @class */ (function () { | ||
@@ -257,2 +363,3 @@ function HSLInterface(color) { | ||
_a = __read(hsl, 3), this.h = _a[0], this.s = _a[1], this.l = _a[2]; | ||
return this; | ||
}; | ||
@@ -270,3 +377,3 @@ HSLInterface.prototype.toCss = function () { | ||
/***/ }), | ||
/* 3 */ | ||
/* 5 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -282,7 +389,9 @@ | ||
}; | ||
exports.mixRgbColors = function (rgb1, rgb2, m) { return [ | ||
rgb1[0] + m * (rgb2[0] - rgb1[0]), | ||
rgb1[1] + m * (rgb2[1] - rgb1[1]), | ||
rgb1[2] + m * (rgb2[2] - rgb1[2]), | ||
]; }; | ||
exports.mixRgbColors = function (rgb1, rgb2, m) { | ||
return [ | ||
rgb1[0] + m * (rgb2[0] - rgb1[0]), | ||
rgb1[1] + m * (rgb2[1] - rgb1[1]), | ||
rgb1[2] + m * (rgb2[2] - rgb1[2]), | ||
]; | ||
}; | ||
exports.toPercent = function (value) { | ||
@@ -329,3 +438,3 @@ return Math.round(value * 100) + "%"; | ||
/***/ }), | ||
/* 4 */ | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -392,2 +501,3 @@ | ||
_a = __read(hsv, 3), this.h = _a[0], this.s = _a[1], this.v = _a[2]; | ||
return this; | ||
}; | ||
@@ -403,3 +513,3 @@ HSVInterface.prototype.toCss = function () { | ||
/***/ }), | ||
/* 5 */ | ||
/* 7 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -417,3 +527,3 @@ | ||
if (!(consts_1.RE_HEX_3.test(hex) || consts_1.RE_HEX_6.test(hex))) { | ||
throw Error('Not valid hex color'); | ||
throw Error("Not valid hex color"); | ||
} | ||
@@ -425,2 +535,3 @@ if (consts_1.RE_HEX_3.test(hex)) { | ||
this.color.rgb.set([temp >> 16, (temp >> 8) & 0xff, temp & 0xff]); | ||
return this; | ||
}; | ||
@@ -430,3 +541,3 @@ HexInterface.prototype.get = function () { | ||
var hex = ((rgb.r << 16) | (rgb.g << 8) | rgb.b).toString(16); | ||
return "" + '0'.repeat(6 - hex.length) + hex; | ||
return "" + "0".repeat(6 - hex.length) + hex; | ||
}; | ||
@@ -446,3 +557,3 @@ HexInterface.prototype.toCss = function () { | ||
/***/ }), | ||
/* 6 */ | ||
/* 8 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -456,16 +567,20 @@ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Color_1 = __importDefault(__webpack_require__(7)); | ||
var Color_1 = __importDefault(__webpack_require__(9)); | ||
exports.default = Color_1.default; | ||
var RGBInterface_1 = __webpack_require__(1); | ||
Object.defineProperty(exports, "RGBInterface", { enumerable: true, get: function () { return RGBInterface_1.default; } }); | ||
var HSLInterface_1 = __webpack_require__(2); | ||
var RGBAInterface_1 = __webpack_require__(3); | ||
Object.defineProperty(exports, "RGBAInterface", { enumerable: true, get: function () { return RGBAInterface_1.default; } }); | ||
var HSLInterface_1 = __webpack_require__(4); | ||
Object.defineProperty(exports, "HSLInterface", { enumerable: true, get: function () { return HSLInterface_1.default; } }); | ||
var HSVInterface_1 = __webpack_require__(4); | ||
var HSVInterface_1 = __webpack_require__(6); | ||
Object.defineProperty(exports, "HSVInterface", { enumerable: true, get: function () { return HSVInterface_1.default; } }); | ||
var HexInterface_1 = __webpack_require__(5); | ||
var HexInterface_1 = __webpack_require__(7); | ||
Object.defineProperty(exports, "HexInterface", { enumerable: true, get: function () { return HexInterface_1.default; } }); | ||
var consts_1 = __webpack_require__(0); | ||
Object.defineProperty(exports, "ColorType", { enumerable: true, get: function () { return consts_1.ColorType; } }); | ||
/***/ }), | ||
/* 7 */ | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
@@ -496,7 +611,8 @@ | ||
var RGBInterface_1 = __importDefault(__webpack_require__(1)); | ||
var HSLInterface_1 = __importDefault(__webpack_require__(2)); | ||
var HSVInterface_1 = __importDefault(__webpack_require__(4)); | ||
var HexInterface_1 = __importDefault(__webpack_require__(5)); | ||
var RGBAInterface_1 = __importDefault(__webpack_require__(3)); | ||
var HSLInterface_1 = __importDefault(__webpack_require__(4)); | ||
var HSVInterface_1 = __importDefault(__webpack_require__(6)); | ||
var HexInterface_1 = __importDefault(__webpack_require__(7)); | ||
var consts_1 = __webpack_require__(0); | ||
var utils_1 = __webpack_require__(3); | ||
var utils_1 = __webpack_require__(5); | ||
/** | ||
@@ -523,2 +639,3 @@ * @constructor | ||
this._rgb = null; | ||
this._rgba = null; | ||
this._hsl = null; | ||
@@ -565,2 +682,12 @@ this._hsv = null; | ||
}); | ||
Object.defineProperty(Color.prototype, "rgba", { | ||
get: function () { | ||
if (this._rgba === null) { | ||
this._rgba = new RGBAInterface_1.default(this); | ||
} | ||
return this._rgba; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Color.prototype, "hsl", { | ||
@@ -598,3 +725,3 @@ get: function () { | ||
get: function () { | ||
return Math.round(utils_1.clamp(this._alpha, 0, 1)); | ||
return utils_1.clamp(this._alpha, 0, 1); | ||
}, | ||
@@ -699,2 +826,6 @@ set: function (alpha) { | ||
}; | ||
Color.prototype.mixWithColor = function (color, percent) { | ||
this.rgb.set(utils_1.mixRgbColors(this.rgb.get(), color.rgb.get(), percent)); | ||
return this; | ||
}; | ||
Color.prototype.updateHslFromRgb = function () { | ||
@@ -701,0 +832,0 @@ var red = this.red / 255; |
@@ -1,1 +0,1 @@ | ||
module.exports=function(t){var e={};function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(o,n,function(e){return t[e]}.bind(null,n));return o},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=6)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.RE_HEX_3=e.RE_HEX_6=e.GREY=e.WHITE=e.BLACK=e.DEFAULT_COLOR=e.ColorType=void 0,function(t){t[t.KEYWORD=1]="KEYWORD",t[t.HEX=2]="HEX",t[t.RGB=3]="RGB",t[t.RGBA=4]="RGBA",t[t.HSL=5]="HSL",t[t.HSLA=6]="HSLA",t[t.HSV=7]="HSV"}(e.ColorType||(e.ColorType={})),e.DEFAULT_COLOR="black",e.BLACK=[0,0,0],e.WHITE=[255,255,255],e.GREY=[127.5,127.5,127.5],e.RE_HEX_6=new RegExp("^[0-9a-fA-F]{6}$"),e.RE_HEX_3=new RegExp("^[0-9a-fA-F]{3}$")},function(t,e,r){"use strict";var o=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,n,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)u.push(o.value)}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return u};Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t){this.color=t}return Object.defineProperty(t.prototype,"r",{get:function(){return this.color.getRed()},set:function(t){this.color.setRed(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"g",{get:function(){return this.color.getGreen()},set:function(t){this.color.setGreen(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"b",{get:function(){return this.color.getBlue()},set:function(t){this.color.setBlue(t)},enumerable:!1,configurable:!0}),t.prototype.get=function(){return[this.r,this.g,this.b]},t.prototype.set=function(t){var e;e=o(t,3),this.r=e[0],this.g=e[1],this.b=e[2]},t.prototype.toCss=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"},t}();e.default=n},function(t,e,r){"use strict";var o=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,n,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)u.push(o.value)}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return u};Object.defineProperty(e,"__esModule",{value:!0});var n=r(3),i=function(){function t(t){this.color=t}return Object.defineProperty(t.prototype,"h",{get:function(){return this.color.getHue()},set:function(t){this.color.setHue(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"s",{get:function(){return this.color.getSaturation()},set:function(t){this.color.setSaturation(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"l",{get:function(){return this.color.getLightness()},set:function(t){this.color.setLightness(t)},enumerable:!1,configurable:!0}),t.prototype.get=function(){return[this.h,this.s,this.l]},t.prototype.set=function(t){var e;e=o(t,3),this.h=e[0],this.s=e[1],this.l=e[2]},t.prototype.toCss=function(){var t=n.toPercent(this.s),e=n.toPercent(this.l);return"hsl("+this.h+", "+t+", "+e+")"},t}();e.default=i},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getTestSpan=e.parseInt10=e.hueToRgb=e.toPercent=e.mixRgbColors=e.clamp=void 0;var o=r(0);e.clamp=function(t,e,r){return Math.min(Math.max(t,e),r)},e.mixRgbColors=function(t,e,r){return[t[0]+r*(e[0]-t[0]),t[1]+r*(e[1]-t[1]),t[2]+r*(e[2]-t[2])]},e.toPercent=function(t){return Math.round(100*t)+"%"},e.hueToRgb=function(t){var e=(t%=360)%60;switch(t-=e,e=Math.round(4.25*e),t){case 0:return[255,e,0];case 60:return[255-e,255,0];case 120:return[0,255,e];case 180:return[0,255-e,255];case 240:return[e,0,255];case 300:return[255,0,255-e]}return[0,0,0]},e.parseInt10=function(t){return Number.parseInt(t,10)},e.getTestSpan=function(){var t=n;return t&&t.parentNode||((t=n=document.createElement("span")).style.display="none",document.body.appendChild(t)),t.style.setProperty("color",o.DEFAULT_COLOR,"important"),t};var n=null},function(t,e,r){"use strict";var o=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,n,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)u.push(o.value)}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return u};Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t){this.color=t}return Object.defineProperty(t.prototype,"h",{get:function(){return this.color.getHue()},set:function(t){this.color.setHue(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"s",{get:function(){return this.color.getSaturationV()},set:function(t){this.color.setSaturationV(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"v",{get:function(){return this.color.getValue()},set:function(t){this.color.setValue(t)},enumerable:!1,configurable:!0}),t.prototype.get=function(){return[this.h,this.s,this.v]},t.prototype.set=function(t){var e;e=o(t,3),this.h=e[0],this.s=e[1],this.v=e[2]},t.prototype.toCss=function(){return this.color.hsl.toCss()},t}();e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var o=r(0),n=function(){function t(t){this.color=t}return t.prototype.set=function(t){if(!o.RE_HEX_3.test(t)&&!o.RE_HEX_6.test(t))throw Error("Not valid hex color");o.RE_HEX_3.test(t)&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]);var e=Number.parseInt(t,16);this.color.rgb.set([e>>16,e>>8&255,255&e])},t.prototype.get=function(){var t=this.color.rgb,e=(t.r<<16|t.g<<8|t.b).toString(16);return""+"0".repeat(6-e.length)+e},t.prototype.toCss=function(){var t=this.get();return t[0]===t[1]&&t[2]===t[3]&&t[4]===t[5]&&(t=""+t[0]+t[2]+t[4]),"#"+t},t}();e.default=n},function(t,e,r){"use strict";var o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var n=o(r(7));e.default=n.default;var i=r(1);Object.defineProperty(e,"RGBInterface",{enumerable:!0,get:function(){return i.default}});var u=r(2);Object.defineProperty(e,"HSLInterface",{enumerable:!0,get:function(){return u.default}});var s=r(4);Object.defineProperty(e,"HSVInterface",{enumerable:!0,get:function(){return s.default}});var a=r(5);Object.defineProperty(e,"HexInterface",{enumerable:!0,get:function(){return a.default}})},function(t,e,r){"use strict";var o=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,n,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)u.push(o.value)}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return u},n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(r(1)),u=n(r(2)),s=n(r(4)),a=n(r(5)),l=r(0),c=r(3),h=function(){function t(t,e){if(this._alpha=1,this.red=0,this.green=0,this.blue=0,this.hue=0,this.saturation=0,this.lightness=0,this.saturationV=0,this.value=0,this._rgb=null,this._hsl=null,this._hsv=null,this._hex=null,"string"==typeof t&&this.parseCSSColor(t),Array.isArray(t))switch(e){case void 0:case l.ColorType.RGB:this.rgb.set(t);break;case l.ColorType.HSL:this.hsl.set(t);break;case l.ColorType.HSV:this.hsv.set(t)}}return t.prototype.parseCSSColor=function(t){var e=c.getTestSpan();e.style.setProperty("color",t,"important");var r=window.getComputedStyle(e).color.split(/rgba?\(|,s*|\)$/).filter(Boolean);4===r.length&&(this.alpha=parseFloat(r.pop())),this.rgb.set(r.map(c.parseInt10))},Object.defineProperty(t.prototype,"rgb",{get:function(){return null===this._rgb&&(this._rgb=new i.default(this)),this._rgb},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hsl",{get:function(){return this._hsl||(this._hsl=new u.default(this)),this._hsl},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hsv",{get:function(){return this._hsv||(this._hsv=new s.default(this)),this._hsv},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return this._hex||(this._hex=new a.default(this)),this._hex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"alpha",{get:function(){return Math.round(c.clamp(this._alpha,0,1))},set:function(t){this._alpha=t},enumerable:!1,configurable:!0}),t.prototype.setRed=function(t){this.red=c.clamp(t,0,255),this.updateHslFromRgb(),this.updateHsvFromHsl()},t.prototype.getRed=function(){return Math.round(c.clamp(this.red,0,255))},t.prototype.setGreen=function(t){this.green=c.clamp(t,0,255),this.updateHslFromRgb(),this.updateHsvFromHsl()},t.prototype.getGreen=function(){return Math.round(c.clamp(this.green,0,255))},t.prototype.setBlue=function(t){this.blue=c.clamp(t,0,255),this.updateHslFromRgb(),this.updateHsvFromHsl()},t.prototype.getBlue=function(){return Math.round(c.clamp(this.blue,0,255))},t.prototype.setHue=function(t){this.hue=c.clamp(t,0,360),this.updateRgbFromHsl()},t.prototype.getHue=function(){return Math.round(c.clamp(this.hue,0,360))},t.prototype.setSaturation=function(t){this.saturation=c.clamp(t,0,1),this.updateRgbFromHsl(),this.updateHsvFromHsl()},t.prototype.getSaturation=function(){return c.clamp(this.saturation,0,1)},t.prototype.setSaturationV=function(t){this.saturationV=c.clamp(t,0,1),this.updateHslFromHsv(),this.updateRgbFromHsl()},t.prototype.getSaturationV=function(){return c.clamp(this.saturationV,0,1)},t.prototype.setLightness=function(t){this.lightness=c.clamp(t,0,1),this.updateRgbFromHsl(),this.updateHsvFromHsl()},t.prototype.getLightness=function(){return c.clamp(this.lightness,0,1)},t.prototype.setValue=function(t){this.value=c.clamp(t,0,1),this.updateHslFromHsv(),this.updateRgbFromHsl()},t.prototype.getValue=function(){return c.clamp(this.value,0,1)},t.prototype.getGreyValue=function(){return.2126*this.red+.7152*this.green+.0722*this.blue},t.prototype.invert=function(){return this.setHue((this.hue+180)%360),this},t.prototype.getLuminance=function(){var t=this.rgb.get().map((function(t){var e=t/255;return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*t[0]+.7152*t[1]+.0722*t[2]},t.prototype.getContrastRatio=function(t){var e=this.getLuminance(),r=t.getLuminance();return e>r?(e+.05)/(r+.05):(r+.05)/(e+.05)},t.prototype.copy=function(){var e=new t;return e.setRed(this.red),e.setGreen(this.green),e.setBlue(this.blue),e.alpha=this.alpha,e},t.prototype.updateHslFromRgb=function(){var t=this.red/255,e=this.green/255,r=this.blue/255,o=Math.max(t,e,r),n=Math.min(t,e,r),i=o+n,u=o-n;if(this.hue=0,this.saturation=0,this.lightness=i/2,0!==u){this.saturation=u/(1-Math.abs(i-1));var s=60/u;switch(o){case t:this.hue=(360+(e-r)*s)%360;break;case e:this.hue=120+(r-t)*s;break;case r:this.hue=240+(t-e)*s}}},t.prototype.updateRgbFromHsl=function(){var t,e=c.hueToRgb(this.hue),r=c.mixRgbColors(e,l.GREY,1-this.saturation),n=this.lightness<=.5?l.BLACK:l.WHITE,i=1-Math.abs(2*this.lightness-1);t=o(c.mixRgbColors(n,r,i),3),this.red=t[0],this.green=t[1],this.blue=t[2]},t.prototype.updateHsvFromHsl=function(){var t=this.lightness,e=(2*t+this.saturation*(1-Math.abs(2*t-1)))/2;this.saturationV=2*(e-t)/e||0,this.value=e},t.prototype.updateHslFromHsv=function(){var t=this.value,e=this.saturationV,r=.5*t*(2-e);this.saturation=e*t/(1-Math.abs(2*r-1))||0,this.lightness=r},t}();e.default=h}]); | ||
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=8)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.RE_HEX_3=e.RE_HEX_6=e.GREY=e.WHITE=e.BLACK=e.DEFAULT_COLOR=e.ColorType=void 0,function(t){t[t.KEYWORD=1]="KEYWORD",t[t.HEX=2]="HEX",t[t.RGB=3]="RGB",t[t.RGBA=4]="RGBA",t[t.HSL=5]="HSL",t[t.HSLA=6]="HSLA",t[t.HSV=7]="HSV"}(e.ColorType||(e.ColorType={})),e.DEFAULT_COLOR="black",e.BLACK=[0,0,0],e.WHITE=[255,255,255],e.GREY=[127.5,127.5,127.5],e.RE_HEX_6=new RegExp("^[0-9a-fA-F]{6}$"),e.RE_HEX_3=new RegExp("^[0-9a-fA-F]{3}$")},function(t,e,r){"use strict";var n,o=this&&this.__extends||(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var s=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.get=function(){return[this.r,this.g,this.b]},e.prototype.set=function(t){var e;return e=i(t,3),this.r=e[0],this.g=e[1],this.b=e[2],this},e.prototype.toCss=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"},e}(u(r(2)).default);e.default=s},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t){this.color=t}return Object.defineProperty(t.prototype,"r",{get:function(){return this.color.getRed()},set:function(t){this.color.setRed(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"g",{get:function(){return this.color.getGreen()},set:function(t){this.color.setGreen(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"b",{get:function(){return this.color.getBlue()},set:function(t){this.color.setBlue(t)},enumerable:!1,configurable:!0}),t}();e.default=n},function(t,e,r){"use strict";var n,o=this&&this.__extends||(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var s=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),Object.defineProperty(e.prototype,"a",{get:function(){return this.color.alpha},set:function(t){this.color.alpha=t},enumerable:!1,configurable:!0}),e.prototype.get=function(){return[this.r,this.g,this.b,this.a]},e.prototype.set=function(t){var e;return e=i(t,4),this.r=e[0],this.g=e[1],this.b=e[2],this.a=e[3],this},e.prototype.toCss=function(){return"rgba("+this.r+", "+this.g+", "+this.b+", "+this.a.toFixed(2)+")"},e}(u(r(2)).default);e.default=s},function(t,e,r){"use strict";var n=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u};Object.defineProperty(e,"__esModule",{value:!0});var o=r(5),i=function(){function t(t){this.color=t}return Object.defineProperty(t.prototype,"h",{get:function(){return this.color.getHue()},set:function(t){this.color.setHue(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"s",{get:function(){return this.color.getSaturation()},set:function(t){this.color.setSaturation(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"l",{get:function(){return this.color.getLightness()},set:function(t){this.color.setLightness(t)},enumerable:!1,configurable:!0}),t.prototype.get=function(){return[this.h,this.s,this.l]},t.prototype.set=function(t){var e;return e=n(t,3),this.h=e[0],this.s=e[1],this.l=e[2],this},t.prototype.toCss=function(){var t=o.toPercent(this.s),e=o.toPercent(this.l);return"hsl("+this.h+", "+t+", "+e+")"},t}();e.default=i},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getTestSpan=e.parseInt10=e.hueToRgb=e.toPercent=e.mixRgbColors=e.clamp=void 0;var n=r(0);e.clamp=function(t,e,r){return Math.min(Math.max(t,e),r)},e.mixRgbColors=function(t,e,r){return[t[0]+r*(e[0]-t[0]),t[1]+r*(e[1]-t[1]),t[2]+r*(e[2]-t[2])]},e.toPercent=function(t){return Math.round(100*t)+"%"},e.hueToRgb=function(t){var e=(t%=360)%60;switch(t-=e,e=Math.round(4.25*e),t){case 0:return[255,e,0];case 60:return[255-e,255,0];case 120:return[0,255,e];case 180:return[0,255-e,255];case 240:return[e,0,255];case 300:return[255,0,255-e]}return[0,0,0]},e.parseInt10=function(t){return Number.parseInt(t,10)},e.getTestSpan=function(){var t=o;return t&&t.parentNode||((t=o=document.createElement("span")).style.display="none",document.body.appendChild(t)),t.style.setProperty("color",n.DEFAULT_COLOR,"important"),t};var o=null},function(t,e,r){"use strict";var n=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u};Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t){this.color=t}return Object.defineProperty(t.prototype,"h",{get:function(){return this.color.getHue()},set:function(t){this.color.setHue(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"s",{get:function(){return this.color.getSaturationV()},set:function(t){this.color.setSaturationV(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"v",{get:function(){return this.color.getValue()},set:function(t){this.color.setValue(t)},enumerable:!1,configurable:!0}),t.prototype.get=function(){return[this.h,this.s,this.v]},t.prototype.set=function(t){var e;return e=n(t,3),this.h=e[0],this.s=e[1],this.v=e[2],this},t.prototype.toCss=function(){return this.color.hsl.toCss()},t}();e.default=o},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(0),o=function(){function t(t){this.color=t}return t.prototype.set=function(t){if(!n.RE_HEX_3.test(t)&&!n.RE_HEX_6.test(t))throw Error("Not valid hex color");n.RE_HEX_3.test(t)&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]);var e=Number.parseInt(t,16);return this.color.rgb.set([e>>16,e>>8&255,255&e]),this},t.prototype.get=function(){var t=this.color.rgb,e=(t.r<<16|t.g<<8|t.b).toString(16);return""+"0".repeat(6-e.length)+e},t.prototype.toCss=function(){var t=this.get();return t[0]===t[1]&&t[2]===t[3]&&t[4]===t[5]&&(t=""+t[0]+t[2]+t[4]),"#"+t},t}();e.default=o},function(t,e,r){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=n(r(9));e.default=o.default;var i=r(1);Object.defineProperty(e,"RGBInterface",{enumerable:!0,get:function(){return i.default}});var u=r(3);Object.defineProperty(e,"RGBAInterface",{enumerable:!0,get:function(){return u.default}});var s=r(4);Object.defineProperty(e,"HSLInterface",{enumerable:!0,get:function(){return s.default}});var a=r(6);Object.defineProperty(e,"HSVInterface",{enumerable:!0,get:function(){return a.default}});var l=r(7);Object.defineProperty(e,"HexInterface",{enumerable:!0,get:function(){return l.default}});var c=r(0);Object.defineProperty(e,"ColorType",{enumerable:!0,get:function(){return c.ColorType}})},function(t,e,r){"use strict";var n=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var i=o(r(1)),u=o(r(3)),s=o(r(4)),a=o(r(6)),l=o(r(7)),c=r(0),h=r(5),p=function(){function t(t,e){if(this._alpha=1,this.red=0,this.green=0,this.blue=0,this.hue=0,this.saturation=0,this.lightness=0,this.saturationV=0,this.value=0,this._rgb=null,this._rgba=null,this._hsl=null,this._hsv=null,this._hex=null,"string"==typeof t&&this.parseCSSColor(t),Array.isArray(t))switch(e){case void 0:case c.ColorType.RGB:this.rgb.set(t);break;case c.ColorType.HSL:this.hsl.set(t);break;case c.ColorType.HSV:this.hsv.set(t)}}return t.prototype.parseCSSColor=function(t){var e=h.getTestSpan();e.style.setProperty("color",t,"important");var r=window.getComputedStyle(e).color.split(/rgba?\(|,s*|\)$/).filter(Boolean);4===r.length&&(this.alpha=parseFloat(r.pop())),this.rgb.set(r.map(h.parseInt10))},Object.defineProperty(t.prototype,"rgb",{get:function(){return null===this._rgb&&(this._rgb=new i.default(this)),this._rgb},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"rgba",{get:function(){return null===this._rgba&&(this._rgba=new u.default(this)),this._rgba},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hsl",{get:function(){return this._hsl||(this._hsl=new s.default(this)),this._hsl},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hsv",{get:function(){return this._hsv||(this._hsv=new a.default(this)),this._hsv},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return this._hex||(this._hex=new l.default(this)),this._hex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"alpha",{get:function(){return h.clamp(this._alpha,0,1)},set:function(t){this._alpha=t},enumerable:!1,configurable:!0}),t.prototype.setRed=function(t){this.red=h.clamp(t,0,255),this.updateHslFromRgb(),this.updateHsvFromHsl()},t.prototype.getRed=function(){return Math.round(h.clamp(this.red,0,255))},t.prototype.setGreen=function(t){this.green=h.clamp(t,0,255),this.updateHslFromRgb(),this.updateHsvFromHsl()},t.prototype.getGreen=function(){return Math.round(h.clamp(this.green,0,255))},t.prototype.setBlue=function(t){this.blue=h.clamp(t,0,255),this.updateHslFromRgb(),this.updateHsvFromHsl()},t.prototype.getBlue=function(){return Math.round(h.clamp(this.blue,0,255))},t.prototype.setHue=function(t){this.hue=h.clamp(t,0,360),this.updateRgbFromHsl()},t.prototype.getHue=function(){return Math.round(h.clamp(this.hue,0,360))},t.prototype.setSaturation=function(t){this.saturation=h.clamp(t,0,1),this.updateRgbFromHsl(),this.updateHsvFromHsl()},t.prototype.getSaturation=function(){return h.clamp(this.saturation,0,1)},t.prototype.setSaturationV=function(t){this.saturationV=h.clamp(t,0,1),this.updateHslFromHsv(),this.updateRgbFromHsl()},t.prototype.getSaturationV=function(){return h.clamp(this.saturationV,0,1)},t.prototype.setLightness=function(t){this.lightness=h.clamp(t,0,1),this.updateRgbFromHsl(),this.updateHsvFromHsl()},t.prototype.getLightness=function(){return h.clamp(this.lightness,0,1)},t.prototype.setValue=function(t){this.value=h.clamp(t,0,1),this.updateHslFromHsv(),this.updateRgbFromHsl()},t.prototype.getValue=function(){return h.clamp(this.value,0,1)},t.prototype.getGreyValue=function(){return.2126*this.red+.7152*this.green+.0722*this.blue},t.prototype.invert=function(){return this.setHue((this.hue+180)%360),this},t.prototype.getLuminance=function(){var t=this.rgb.get().map((function(t){var e=t/255;return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*t[0]+.7152*t[1]+.0722*t[2]},t.prototype.getContrastRatio=function(t){var e=this.getLuminance(),r=t.getLuminance();return e>r?(e+.05)/(r+.05):(r+.05)/(e+.05)},t.prototype.copy=function(){var e=new t;return e.setRed(this.red),e.setGreen(this.green),e.setBlue(this.blue),e.alpha=this.alpha,e},t.prototype.mixWithColor=function(t,e){return this.rgb.set(h.mixRgbColors(this.rgb.get(),t.rgb.get(),e)),this},t.prototype.updateHslFromRgb=function(){var t=this.red/255,e=this.green/255,r=this.blue/255,n=Math.max(t,e,r),o=Math.min(t,e,r),i=n+o,u=n-o;if(this.hue=0,this.saturation=0,this.lightness=i/2,0!==u){this.saturation=u/(1-Math.abs(i-1));var s=60/u;switch(n){case t:this.hue=(360+(e-r)*s)%360;break;case e:this.hue=120+(r-t)*s;break;case r:this.hue=240+(t-e)*s}}},t.prototype.updateRgbFromHsl=function(){var t,e=h.hueToRgb(this.hue),r=h.mixRgbColors(e,c.GREY,1-this.saturation),o=this.lightness<=.5?c.BLACK:c.WHITE,i=1-Math.abs(2*this.lightness-1);t=n(h.mixRgbColors(o,r,i),3),this.red=t[0],this.green=t[1],this.blue=t[2]},t.prototype.updateHsvFromHsl=function(){var t=this.lightness,e=(2*t+this.saturation*(1-Math.abs(2*t-1)))/2;this.saturationV=2*(e-t)/e||0,this.value=e},t.prototype.updateHslFromHsv=function(){var t=this.value,e=this.saturationV,r=.5*t*(2-e);this.saturation=e*t/(1-Math.abs(2*r-1))||0,this.lightness=r},t}();e.default=p}]); |
@@ -1,15 +0,8 @@ | ||
import { Color, RGBInterface as RGBInterface_, RGB } from './ColorInterface'; | ||
declare class RGBInterface implements RGBInterface_ { | ||
private color; | ||
constructor(color: Color); | ||
set r(r: number); | ||
get r(): number; | ||
set g(g: number); | ||
get g(): number; | ||
set b(b: number); | ||
get b(): number; | ||
import { RGBInterface as RGBInterface_, RGB } from './ColorInterface'; | ||
import BaseRGBInterface from './BaseRGBInterface'; | ||
declare class RGBInterface extends BaseRGBInterface implements RGBInterface_ { | ||
get(): RGB; | ||
set(rgb: RGB): void; | ||
set(rgb: RGB): this; | ||
toCss(): string; | ||
} | ||
export default RGBInterface; |
import { RGB } from './ColorInterface'; | ||
export declare const clamp: (val: number, min: number, max: number) => number; | ||
export declare const mixRgbColors: (rgb1: RGB, rgb2: RGB, m: number) => number[]; | ||
export declare const mixRgbColors: (rgb1: RGB, rgb2: RGB, m: number) => RGB; | ||
export declare const toPercent: (value: number) => string; | ||
@@ -5,0 +5,0 @@ export declare const hueToRgb: (hue: number) => number[]; |
import Color from './dist/index'; | ||
export default Color; | ||
export { default as RGBInterface } from './dist/RGBInterface'; | ||
export { default as RGBAInterface } from './dist/RGBAInterface'; | ||
export { default as HSLInterface } from './dist/HSLInterface'; | ||
export { default as HSVInterface } from './dist/HSVInterface'; | ||
export { default as HexInterface } from './dist/HexInterface'; | ||
export { RGB, RGBA, HSL, HSLA, HSV, HSVA, HEX } from './ColorInterface'; | ||
export { RGB, RGBA, HSL, HSLA, HSV, HSVA, HEX } from './dist/ColorInterface'; | ||
export { ColorType } from './dist/consts'; |
{ | ||
"name": "color-interfaces", | ||
"version": "0.0.9", | ||
"version": "0.0.11", | ||
"description": "interfaces for color spaces", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/chriskr/color-interfaces", |
@@ -26,2 +26,3 @@ # color-interfaces | ||
rgb: RGBInterface; | ||
rgba: RGBAInterface; | ||
hsl: HSLInterface; | ||
@@ -52,2 +53,4 @@ hsv: HSVInterface; | ||
parseCSSColor(input: string): void; | ||
copy: () => Color; | ||
mixWithColor(color: Color, percent: number): Color; | ||
} | ||
@@ -60,6 +63,16 @@ | ||
get: () => RGB; | ||
set: (rgb: RGB) => void; | ||
set: (rgb: RGB) => RGBInterface; | ||
toCss: () => string; | ||
} | ||
export interface RGBAInterface { | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
get: () => RGBA; | ||
set: (rgba: RGBA) => RGBAInterface; | ||
toCss: () => string; | ||
} | ||
export interface HSLInterface { | ||
@@ -70,3 +83,3 @@ h: number; | ||
get: () => HSL; | ||
set: (hsv: HSL) => void; | ||
set: (hsv: HSL) => HSLInterface; | ||
toCss: () => string; | ||
@@ -80,3 +93,3 @@ } | ||
get: () => HSV; | ||
set: (hsv: HSV) => void; | ||
set: (hsv: HSV) => HSVInterface; | ||
toCss: () => string; | ||
@@ -87,3 +100,3 @@ } | ||
get: () => HEX; | ||
set: (hex: HEX) => void; | ||
set: (hex: HEX) => HexInterface; | ||
toCss: () => string; | ||
@@ -99,2 +112,3 @@ } | ||
export type HEX = string; | ||
``` |
import { Color as Color_, RGB, HSV, HSL } from './ColorInterface'; | ||
import RGBInterface from './RGBInterface'; | ||
import RGBAInterface from './RGBAInterface'; | ||
import HSLInterface from './HSLInterface'; | ||
@@ -36,2 +37,3 @@ import HSVInterface from './HSVInterface'; | ||
private _rgb: RGBInterface | null = null; | ||
private _rgba: RGBAInterface | null = null; | ||
private _hsl: HSLInterface | null = null; | ||
@@ -79,2 +81,9 @@ private _hsv: HSVInterface | null = null; | ||
get rgba(): RGBAInterface { | ||
if (this._rgba === null) { | ||
this._rgba = new RGBAInterface(this); | ||
} | ||
return this._rgba; | ||
} | ||
get hsl(): HSLInterface { | ||
@@ -106,3 +115,3 @@ if (!this._hsl) { | ||
get alpha() { | ||
return Math.round(clamp(this._alpha, 0, 1)); | ||
return clamp(this._alpha, 0, 1); | ||
} | ||
@@ -223,2 +232,7 @@ | ||
mixWithColor(color: Color, percent: number) { | ||
this.rgb.set(mixRgbColors(this.rgb.get(), color.rgb.get(), percent)); | ||
return this; | ||
} | ||
private updateHslFromRgb() { | ||
@@ -225,0 +239,0 @@ const red = this.red / 255; |
export interface Color { | ||
rgb: RGBInterface; | ||
rgba: RGBAInterface; | ||
hsl: HSLInterface; | ||
@@ -29,2 +30,3 @@ hsv: HSVInterface; | ||
copy: () => Color; | ||
mixWithColor(color: Color, percent: number): Color; | ||
} | ||
@@ -37,6 +39,16 @@ | ||
get: () => RGB; | ||
set: (rgb: RGB) => void; | ||
set: (rgb: RGB) => RGBInterface; | ||
toCss: () => string; | ||
} | ||
export interface RGBAInterface { | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
get: () => RGBA; | ||
set: (rgba: RGBA) => RGBAInterface; | ||
toCss: () => string; | ||
} | ||
export interface HSLInterface { | ||
@@ -47,3 +59,3 @@ h: number; | ||
get: () => HSL; | ||
set: (hsv: HSL) => void; | ||
set: (hsv: HSL) => HSLInterface; | ||
toCss: () => string; | ||
@@ -57,3 +69,3 @@ } | ||
get: () => HSV; | ||
set: (hsv: HSV) => void; | ||
set: (hsv: HSV) => HSVInterface; | ||
toCss: () => string; | ||
@@ -64,3 +76,3 @@ } | ||
get: () => HEX; | ||
set: (hex: HEX) => void; | ||
set: (hex: HEX) => HexInterface; | ||
toCss: () => string; | ||
@@ -67,0 +79,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { Color, HexInterface as HexInterface_, HEX } from './ColorInterface'; | ||
import { RE_HEX_3, RE_HEX_6 } from './consts'; | ||
import { Color, HexInterface as HexInterface_, HEX } from "./ColorInterface"; | ||
import { RE_HEX_3, RE_HEX_6 } from "./consts"; | ||
@@ -12,3 +12,3 @@ class HexInterface implements HexInterface_ { | ||
if (!(RE_HEX_3.test(hex) || RE_HEX_6.test(hex))) { | ||
throw Error('Not valid hex color'); | ||
throw Error("Not valid hex color"); | ||
} | ||
@@ -20,2 +20,3 @@ if (RE_HEX_3.test(hex)) { | ||
this.color.rgb.set([temp >> 16, (temp >> 8) & 0xff, temp & 0xff]); | ||
return this; | ||
} | ||
@@ -26,3 +27,3 @@ | ||
const hex = ((rgb.r << 16) | (rgb.g << 8) | rgb.b).toString(16); | ||
return `${'0'.repeat(6 - hex.length)}${hex}`; | ||
return `${"0".repeat(6 - hex.length)}${hex}`; | ||
} | ||
@@ -29,0 +30,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { Color, HSLInterface as HSLInterface_, HSL } from './ColorInterface'; | ||
import { toPercent } from './utils'; | ||
import { Color, HSLInterface as HSLInterface_, HSL } from "./ColorInterface"; | ||
import { toPercent } from "./utils"; | ||
@@ -40,2 +40,3 @@ class HSLInterface implements HSLInterface_ { | ||
[this.h, this.s, this.l] = hsl; | ||
return this; | ||
} | ||
@@ -42,0 +43,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Color, HSVInterface as HSVInterface_, HSV } from './ColorInterface'; | ||
import { Color, HSVInterface as HSVInterface_, HSV } from "./ColorInterface"; | ||
@@ -39,2 +39,3 @@ class HSVInterface implements HSVInterface_ { | ||
[this.h, this.s, this.v] = hsv; | ||
return this; | ||
} | ||
@@ -41,0 +42,0 @@ |
import Color from './Color'; | ||
export default Color; | ||
export { default as RGBInterface } from './RGBInterface'; | ||
export { default as RGBAInterface } from './RGBAInterface'; | ||
export { default as HSLInterface } from './HSLInterface'; | ||
@@ -8,1 +9,2 @@ export { default as HSVInterface } from './HSVInterface'; | ||
export { RGB, RGBA, HSL, HSLA, HSV, HSVA, HEX } from './ColorInterface'; | ||
export { ColorType } from './consts'; |
import { Color, RGBInterface as RGBInterface_, RGB } from './ColorInterface'; | ||
import BaseRGBInterface from './BaseRGBInterface'; | ||
class RGBInterface implements RGBInterface_ { | ||
private color: Color; | ||
constructor(color: Color) { | ||
this.color = color; | ||
} | ||
set r(r) { | ||
this.color.setRed(r); | ||
} | ||
get r() { | ||
return this.color.getRed(); | ||
} | ||
set g(g) { | ||
this.color.setGreen(g); | ||
} | ||
get g() { | ||
return this.color.getGreen(); | ||
} | ||
set b(b) { | ||
this.color.setBlue(b); | ||
} | ||
get b() { | ||
return this.color.getBlue(); | ||
} | ||
class RGBInterface extends BaseRGBInterface implements RGBInterface_ { | ||
get() { | ||
@@ -40,2 +11,3 @@ return [this.r, this.g, this.b] as RGB; | ||
[this.r, this.g, this.b] = rgb; | ||
return this; | ||
} | ||
@@ -42,0 +14,0 @@ |
@@ -8,7 +8,8 @@ import { RGB } from './ColorInterface'; | ||
export const mixRgbColors = (rgb1: RGB, rgb2: RGB, m: number) => [ | ||
rgb1[0] + m * (rgb2[0] - rgb1[0]), | ||
rgb1[1] + m * (rgb2[1] - rgb1[1]), | ||
rgb1[2] + m * (rgb2[2] - rgb1[2]), | ||
]; | ||
export const mixRgbColors = (rgb1: RGB, rgb2: RGB, m: number) => | ||
[ | ||
rgb1[0] + m * (rgb2[0] - rgb1[0]), | ||
rgb1[1] + m * (rgb2[1] - rgb1[1]), | ||
rgb1[2] + m * (rgb2[2] - rgb1[2]), | ||
] as RGB; | ||
@@ -15,0 +16,0 @@ export const toPercent = (value: number) => { |
85228
12.26%32
14.29%1670
14.62%108
14.89%