1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | require('./unsupportedIterableToArray-68db1d3b.js');
|
6 | var _commonjsHelpers = require('./_commonjsHelpers-72d386ba.js');
|
7 | var toConsumableArray = require('./toConsumableArray-d8a4a2c3.js');
|
8 | var getPrototypeOf = require('./getPrototypeOf-2a661a20.js');
|
9 |
|
10 | function _isNativeFunction(fn) {
|
11 | return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
12 | }
|
13 |
|
14 | var isNativeFunction = _isNativeFunction;
|
15 |
|
16 | function _isNativeReflectConstruct() {
|
17 | if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
18 | if (Reflect.construct.sham) return false;
|
19 | if (typeof Proxy === "function") return true;
|
20 |
|
21 | try {
|
22 | Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
23 | return true;
|
24 | } catch (e) {
|
25 | return false;
|
26 | }
|
27 | }
|
28 |
|
29 | var isNativeReflectConstruct = _isNativeReflectConstruct;
|
30 |
|
31 | var construct = _commonjsHelpers.createCommonjsModule(function (module) {
|
32 | function _construct(Parent, args, Class) {
|
33 | if (isNativeReflectConstruct()) {
|
34 | module.exports = _construct = Reflect.construct;
|
35 | } else {
|
36 | module.exports = _construct = function _construct(Parent, args, Class) {
|
37 | var a = [null];
|
38 | a.push.apply(a, args);
|
39 | var Constructor = Function.bind.apply(Parent, a);
|
40 | var instance = new Constructor();
|
41 | if (Class) getPrototypeOf.setPrototypeOf(instance, Class.prototype);
|
42 | return instance;
|
43 | };
|
44 | }
|
45 |
|
46 | return _construct.apply(null, arguments);
|
47 | }
|
48 |
|
49 | module.exports = _construct;
|
50 | });
|
51 |
|
52 | var wrapNativeSuper = _commonjsHelpers.createCommonjsModule(function (module) {
|
53 | function _wrapNativeSuper(Class) {
|
54 | var _cache = typeof Map === "function" ? new Map() : undefined;
|
55 |
|
56 | module.exports = _wrapNativeSuper = function _wrapNativeSuper(Class) {
|
57 | if (Class === null || !isNativeFunction(Class)) return Class;
|
58 |
|
59 | if (typeof Class !== "function") {
|
60 | throw new TypeError("Super expression must either be null or a function");
|
61 | }
|
62 |
|
63 | if (typeof _cache !== "undefined") {
|
64 | if (_cache.has(Class)) return _cache.get(Class);
|
65 |
|
66 | _cache.set(Class, Wrapper);
|
67 | }
|
68 |
|
69 | function Wrapper() {
|
70 | return construct(Class, arguments, getPrototypeOf._getPrototypeOf(this).constructor);
|
71 | }
|
72 |
|
73 | Wrapper.prototype = Object.create(Class.prototype, {
|
74 | constructor: {
|
75 | value: Wrapper,
|
76 | enumerable: false,
|
77 | writable: true,
|
78 | configurable: true
|
79 | }
|
80 | });
|
81 | return getPrototypeOf.setPrototypeOf(Wrapper, Class);
|
82 | };
|
83 |
|
84 | return _wrapNativeSuper(Class);
|
85 | }
|
86 |
|
87 | module.exports = _wrapNativeSuper;
|
88 | });
|
89 |
|
90 | function _createSuper(Derived) { return function () { var Super = getPrototypeOf._getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$1()) { var NewTarget = getPrototypeOf._getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return getPrototypeOf._possibleConstructorReturn(this, result); }; }
|
91 |
|
92 | function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
93 |
|
94 | var RGB_HEX_RE = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
95 |
|
96 | function rgbFromRgbInt(rgbInt) {
|
97 | return {
|
98 | r: Math.floor(rgbInt / Math.pow(256, 2)),
|
99 | g: Math.floor(rgbInt / 256 % 256),
|
100 | b: Math.floor(rgbInt % 256)
|
101 | };
|
102 | }
|
103 |
|
104 | function normalizeHexColor(value) {
|
105 | var matches = value ? String(value).match(RGB_HEX_RE) : null;
|
106 |
|
107 | if (matches === null) {
|
108 | throw new Error("color(): the value must be a valid CSS hexadecimal color. Received: ".concat(value));
|
109 | }
|
110 |
|
111 | var hexColor = matches[1].toUpperCase();
|
112 |
|
113 | if (hexColor.length === 3) {
|
114 | return toConsumableArray._toConsumableArray(hexColor).map(function (c) {
|
115 | return c + c;
|
116 | }).join('');
|
117 | }
|
118 |
|
119 | return hexColor;
|
120 | }
|
121 |
|
122 | var Color = function (_String) {
|
123 | getPrototypeOf._inherits(Color, _String);
|
124 |
|
125 | var _super = _createSuper(Color);
|
126 |
|
127 | function Color(value) {
|
128 | var _this;
|
129 |
|
130 | getPrototypeOf._classCallCheck(this, Color);
|
131 |
|
132 | _this = _super.call(this, value);
|
133 | var hexColor = normalizeHexColor(value);
|
134 |
|
135 | var _rgbFromRgbInt = rgbFromRgbInt(parseInt(hexColor, 16)),
|
136 | r = _rgbFromRgbInt.r,
|
137 | g = _rgbFromRgbInt.g,
|
138 | b = _rgbFromRgbInt.b;
|
139 |
|
140 | _this.r = r;
|
141 | _this.g = g;
|
142 | _this.b = b;
|
143 | _this.hexColor = hexColor;
|
144 | return _this;
|
145 | }
|
146 |
|
147 | getPrototypeOf._createClass(Color, [{
|
148 | key: "toString",
|
149 | value: function toString() {
|
150 | return this.toCssRgb();
|
151 | }
|
152 | }, {
|
153 | key: "valueOf",
|
154 | value: function valueOf() {
|
155 | return this.toCssRgb();
|
156 | }
|
157 | }, {
|
158 | key: "toArray",
|
159 | value: function toArray() {
|
160 | return [this.r, this.g, this.b];
|
161 | }
|
162 | }, {
|
163 | key: "toObject",
|
164 | value: function toObject() {
|
165 | var r = this.r,
|
166 | g = this.g,
|
167 | b = this.b;
|
168 | return {
|
169 | r: r,
|
170 | g: g,
|
171 | b: b
|
172 | };
|
173 | }
|
174 | }, {
|
175 | key: "alpha",
|
176 | value: function alpha(_alpha) {
|
177 | return this.toCssRgb({
|
178 | alpha: _alpha
|
179 | });
|
180 | }
|
181 | }, {
|
182 | key: "toCssRgb",
|
183 | value: function toCssRgb() {
|
184 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
185 | _ref$alpha = _ref.alpha,
|
186 | alpha = _ref$alpha === void 0 ? 1 : _ref$alpha;
|
187 |
|
188 | if (alpha === 1) {
|
189 | return "#".concat(this.hexColor);
|
190 | }
|
191 |
|
192 | alpha = Math.max(0, Math.min(1, alpha));
|
193 | return "rgba(".concat(this.r, ", ").concat(this.g, ", ").concat(this.b, ", ").concat(alpha, ")");
|
194 | }
|
195 | }]);
|
196 |
|
197 | return Color;
|
198 | }( wrapNativeSuper(String));
|
199 |
|
200 | function color(value) {
|
201 | return new Color(value);
|
202 | }
|
203 |
|
204 | exports.default = color;
|
205 |
|