1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/esm/extends'), require('@babel/runtime/helpers/esm/assertThisInitialized'), require('@babel/runtime/helpers/esm/inheritsLoose'), require('@babel/runtime/helpers/esm/wrapNativeSuper'), require('@babel/runtime/helpers/esm/taggedTemplateLiteralLoose')) :
|
3 | typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/esm/extends', '@babel/runtime/helpers/esm/assertThisInitialized', '@babel/runtime/helpers/esm/inheritsLoose', '@babel/runtime/helpers/esm/wrapNativeSuper', '@babel/runtime/helpers/esm/taggedTemplateLiteralLoose'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.polished = {}, global.extends, global.assertThisInitialized, global.inheritsLoose, global.wrapNativeSuper, global.taggedTemplateLiteralLoose));
|
5 | }(this, (function (exports, _extends, _assertThisInitialized, _inheritsLoose, _wrapNativeSuper, _taggedTemplateLiteralLoose) { 'use strict';
|
6 |
|
7 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
8 |
|
9 | var _extends__default = _interopDefaultLegacy(_extends);
|
10 | var _assertThisInitialized__default = _interopDefaultLegacy(_assertThisInitialized);
|
11 | var _inheritsLoose__default = _interopDefaultLegacy(_inheritsLoose);
|
12 | var _wrapNativeSuper__default = _interopDefaultLegacy(_wrapNativeSuper);
|
13 | var _taggedTemplateLiteralLoose__default = _interopDefaultLegacy(_taggedTemplateLiteralLoose);
|
14 |
|
15 | function last() {
|
16 | var _ref;
|
17 |
|
18 | return _ref = arguments.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref];
|
19 | }
|
20 |
|
21 | function negation(a) {
|
22 | return -a;
|
23 | }
|
24 |
|
25 | function addition(a, b) {
|
26 | return a + b;
|
27 | }
|
28 |
|
29 | function subtraction(a, b) {
|
30 | return a - b;
|
31 | }
|
32 |
|
33 | function multiplication(a, b) {
|
34 | return a * b;
|
35 | }
|
36 |
|
37 | function division(a, b) {
|
38 | return a / b;
|
39 | }
|
40 |
|
41 | function max() {
|
42 | return Math.max.apply(Math, arguments);
|
43 | }
|
44 |
|
45 | function min() {
|
46 | return Math.min.apply(Math, arguments);
|
47 | }
|
48 |
|
49 | function comma() {
|
50 | return Array.of.apply(Array, arguments);
|
51 | }
|
52 |
|
53 | var defaultSymbols = {
|
54 | symbols: {
|
55 | '*': {
|
56 | infix: {
|
57 | symbol: '*',
|
58 | f: multiplication,
|
59 | notation: 'infix',
|
60 | precedence: 4,
|
61 | rightToLeft: 0,
|
62 | argCount: 2
|
63 | },
|
64 | symbol: '*',
|
65 | regSymbol: '\\*'
|
66 | },
|
67 | '/': {
|
68 | infix: {
|
69 | symbol: '/',
|
70 | f: division,
|
71 | notation: 'infix',
|
72 | precedence: 4,
|
73 | rightToLeft: 0,
|
74 | argCount: 2
|
75 | },
|
76 | symbol: '/',
|
77 | regSymbol: '/'
|
78 | },
|
79 | '+': {
|
80 | infix: {
|
81 | symbol: '+',
|
82 | f: addition,
|
83 | notation: 'infix',
|
84 | precedence: 2,
|
85 | rightToLeft: 0,
|
86 | argCount: 2
|
87 | },
|
88 | prefix: {
|
89 | symbol: '+',
|
90 | f: last,
|
91 | notation: 'prefix',
|
92 | precedence: 3,
|
93 | rightToLeft: 0,
|
94 | argCount: 1
|
95 | },
|
96 | symbol: '+',
|
97 | regSymbol: '\\+'
|
98 | },
|
99 | '-': {
|
100 | infix: {
|
101 | symbol: '-',
|
102 | f: subtraction,
|
103 | notation: 'infix',
|
104 | precedence: 2,
|
105 | rightToLeft: 0,
|
106 | argCount: 2
|
107 | },
|
108 | prefix: {
|
109 | symbol: '-',
|
110 | f: negation,
|
111 | notation: 'prefix',
|
112 | precedence: 3,
|
113 | rightToLeft: 0,
|
114 | argCount: 1
|
115 | },
|
116 | symbol: '-',
|
117 | regSymbol: '-'
|
118 | },
|
119 | ',': {
|
120 | infix: {
|
121 | symbol: ',',
|
122 | f: comma,
|
123 | notation: 'infix',
|
124 | precedence: 1,
|
125 | rightToLeft: 0,
|
126 | argCount: 2
|
127 | },
|
128 | symbol: ',',
|
129 | regSymbol: ','
|
130 | },
|
131 | '(': {
|
132 | prefix: {
|
133 | symbol: '(',
|
134 | f: last,
|
135 | notation: 'prefix',
|
136 | precedence: 0,
|
137 | rightToLeft: 0,
|
138 | argCount: 1
|
139 | },
|
140 | symbol: '(',
|
141 | regSymbol: '\\('
|
142 | },
|
143 | ')': {
|
144 | postfix: {
|
145 | symbol: ')',
|
146 | f: undefined,
|
147 | notation: 'postfix',
|
148 | precedence: 0,
|
149 | rightToLeft: 0,
|
150 | argCount: 1
|
151 | },
|
152 | symbol: ')',
|
153 | regSymbol: '\\)'
|
154 | },
|
155 | min: {
|
156 | func: {
|
157 | symbol: 'min',
|
158 | f: min,
|
159 | notation: 'func',
|
160 | precedence: 0,
|
161 | rightToLeft: 0,
|
162 | argCount: 1
|
163 | },
|
164 | symbol: 'min',
|
165 | regSymbol: 'min\\b'
|
166 | },
|
167 | max: {
|
168 | func: {
|
169 | symbol: 'max',
|
170 | f: max,
|
171 | notation: 'func',
|
172 | precedence: 0,
|
173 | rightToLeft: 0,
|
174 | argCount: 1
|
175 | },
|
176 | symbol: 'max',
|
177 | regSymbol: 'max\\b'
|
178 | }
|
179 | }
|
180 | };
|
181 |
|
182 |
|
183 |
|
184 | |
185 |
|
186 |
|
187 |
|
188 | var ERRORS = {
|
189 | "1": "Passed invalid arguments to hsl, please pass multiple numbers e.g. hsl(360, 0.75, 0.4) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75 }).\n\n",
|
190 | "2": "Passed invalid arguments to hsla, please pass multiple numbers e.g. hsla(360, 0.75, 0.4, 0.7) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75, alpha: 0.7 }).\n\n",
|
191 | "3": "Passed an incorrect argument to a color function, please pass a string representation of a color.\n\n",
|
192 | "4": "Couldn't generate valid rgb string from %s, it returned %s.\n\n",
|
193 | "5": "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.\n\n",
|
194 | "6": "Passed invalid arguments to rgb, please pass multiple numbers e.g. rgb(255, 205, 100) or an object e.g. rgb({ red: 255, green: 205, blue: 100 }).\n\n",
|
195 | "7": "Passed invalid arguments to rgba, please pass multiple numbers e.g. rgb(255, 205, 100, 0.75) or an object e.g. rgb({ red: 255, green: 205, blue: 100, alpha: 0.75 }).\n\n",
|
196 | "8": "Passed invalid argument to toColorString, please pass a RgbColor, RgbaColor, HslColor or HslaColor object.\n\n",
|
197 | "9": "Please provide a number of steps to the modularScale helper.\n\n",
|
198 | "10": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
|
199 | "11": "Invalid value passed as base to modularScale, expected number or em string but got \"%s\"\n\n",
|
200 | "12": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got \"%s\" instead.\n\n",
|
201 | "13": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got \"%s\" instead.\n\n",
|
202 | "14": "Passed invalid pixel value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
|
203 | "15": "Passed invalid base value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
|
204 | "16": "You must provide a template to this method.\n\n",
|
205 | "17": "You passed an unsupported selector state to this method.\n\n",
|
206 | "18": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
|
207 | "19": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
|
208 | "20": "expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
|
209 | "21": "expects the objects in the first argument array to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
|
210 | "22": "expects the first argument object to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
|
211 | "23": "fontFace expects a name of a font-family.\n\n",
|
212 | "24": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
|
213 | "25": "fontFace expects localFonts to be an array.\n\n",
|
214 | "26": "fontFace expects fileFormats to be an array.\n\n",
|
215 | "27": "radialGradient requries at least 2 color-stops to properly render.\n\n",
|
216 | "28": "Please supply a filename to retinaImage() as the first argument.\n\n",
|
217 | "29": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
|
218 | "30": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
|
219 | "31": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation\n\n",
|
220 | "32": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s')\n\n",
|
221 | "33": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation\n\n",
|
222 | "34": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
|
223 | "35": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
|
224 | "36": "Property must be a string value.\n\n",
|
225 | "37": "Syntax Error at %s.\n\n",
|
226 | "38": "Formula contains a function that needs parentheses at %s.\n\n",
|
227 | "39": "Formula is missing closing parenthesis at %s.\n\n",
|
228 | "40": "Formula has too many closing parentheses at %s.\n\n",
|
229 | "41": "All values in a formula must have the same unit or be unitless.\n\n",
|
230 | "42": "Please provide a number of steps to the modularScale helper.\n\n",
|
231 | "43": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
|
232 | "44": "Invalid value passed as base to modularScale, expected number or em/rem string but got %s.\n\n",
|
233 | "45": "Passed invalid argument to hslToColorString, please pass a HslColor or HslaColor object.\n\n",
|
234 | "46": "Passed invalid argument to rgbToColorString, please pass a RgbColor or RgbaColor object.\n\n",
|
235 | "47": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
|
236 | "48": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
|
237 | "49": "Expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
|
238 | "50": "Expects the objects in the first argument array to have the properties prop, fromSize, and toSize.\n\n",
|
239 | "51": "Expects the first argument object to have the properties prop, fromSize, and toSize.\n\n",
|
240 | "52": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
|
241 | "53": "fontFace expects localFonts to be an array.\n\n",
|
242 | "54": "fontFace expects fileFormats to be an array.\n\n",
|
243 | "55": "fontFace expects a name of a font-family.\n\n",
|
244 | "56": "linearGradient requries at least 2 color-stops to properly render.\n\n",
|
245 | "57": "radialGradient requries at least 2 color-stops to properly render.\n\n",
|
246 | "58": "Please supply a filename to retinaImage() as the first argument.\n\n",
|
247 | "59": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
|
248 | "60": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
|
249 | "61": "Property must be a string value.\n\n",
|
250 | "62": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
|
251 | "63": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
|
252 | "64": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation.\n\n",
|
253 | "65": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s').\n\n",
|
254 | "66": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation.\n\n",
|
255 | "67": "You must provide a template to this method.\n\n",
|
256 | "68": "You passed an unsupported selector state to this method.\n\n",
|
257 | "69": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got %s instead.\n\n",
|
258 | "70": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got %s instead.\n\n",
|
259 | "71": "Passed invalid pixel value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
|
260 | "72": "Passed invalid base value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
|
261 | "73": "Please provide a valid CSS variable.\n\n",
|
262 | "74": "CSS variable not found and no default was provided.\n\n",
|
263 | "75": "important requires a valid style object, got a %s instead.\n\n",
|
264 | "76": "fromSize and toSize must be provided as stringified numbers with the same units as minScreen and maxScreen.\n\n",
|
265 | "77": "remToPx expects a value in \"rem\" but you provided it in \"%s\".\n\n",
|
266 | "78": "base must be set in \"px\" or \"%\" but you set it in \"%s\".\n"
|
267 | };
|
268 | |
269 |
|
270 |
|
271 |
|
272 |
|
273 | function format() {
|
274 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
275 | args[_key] = arguments[_key];
|
276 | }
|
277 |
|
278 | var a = args[0];
|
279 | var b = [];
|
280 | var c;
|
281 |
|
282 | for (c = 1; c < args.length; c += 1) {
|
283 | b.push(args[c]);
|
284 | }
|
285 |
|
286 | b.forEach(function (d) {
|
287 | a = a.replace(/%[a-z]/, d);
|
288 | });
|
289 | return a;
|
290 | }
|
291 | |
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 | var PolishedError = function (_Error) {
|
299 | _inheritsLoose__default['default'](PolishedError, _Error);
|
300 |
|
301 | function PolishedError(code) {
|
302 | var _this;
|
303 |
|
304 | {
|
305 | for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
306 | args[_key2 - 1] = arguments[_key2];
|
307 | }
|
308 |
|
309 | _this = _Error.call(this, format.apply(void 0, [ERRORS[code]].concat(args))) || this;
|
310 | }
|
311 |
|
312 | return _assertThisInitialized__default['default'](_this);
|
313 | }
|
314 |
|
315 | return PolishedError;
|
316 | }( _wrapNativeSuper__default['default'](Error));
|
317 |
|
318 | var unitRegExp = /((?!\w)a|na|hc|mc|dg|me[r]?|xe|ni(?![a-zA-Z])|mm|cp|tp|xp|q(?!s)|hv|xamv|nimv|wv|sm|s(?!\D|$)|ged|darg?|nrut)/g;
|
319 |
|
320 | function mergeSymbolMaps(additionalSymbols) {
|
321 | var symbolMap = {};
|
322 | symbolMap.symbols = additionalSymbols ? _extends__default['default']({}, defaultSymbols.symbols, additionalSymbols.symbols) : _extends__default['default']({}, defaultSymbols.symbols);
|
323 | return symbolMap;
|
324 | }
|
325 |
|
326 | function exec(operators, values) {
|
327 | var _ref;
|
328 |
|
329 | var op = operators.pop();
|
330 | values.push(op.f.apply(op, (_ref = []).concat.apply(_ref, values.splice(-op.argCount))));
|
331 | return op.precedence;
|
332 | }
|
333 |
|
334 | function calculate(expression, additionalSymbols) {
|
335 | var symbolMap = mergeSymbolMaps(additionalSymbols);
|
336 | var match;
|
337 | var operators = [symbolMap.symbols['('].prefix];
|
338 | var values = [];
|
339 | var pattern = new RegExp(
|
340 | "\\d+(?:\\.\\d+)?|" +
|
341 | Object.keys(symbolMap.symbols).map(function (key) {
|
342 | return symbolMap.symbols[key];
|
343 | })
|
344 |
|
345 | .sort(function (a, b) {
|
346 | return b.symbol.length - a.symbol.length;
|
347 | })
|
348 | .map(function (val) {
|
349 | return val.regSymbol;
|
350 | }).join('|') + "|(\\S)", 'g');
|
351 | pattern.lastIndex = 0;
|
352 |
|
353 | var afterValue = false;
|
354 |
|
355 | do {
|
356 | match = pattern.exec(expression);
|
357 |
|
358 | var _ref2 = match || [')', undefined],
|
359 | token = _ref2[0],
|
360 | bad = _ref2[1];
|
361 |
|
362 | var notNumber = symbolMap.symbols[token];
|
363 | var notNewValue = notNumber && !notNumber.prefix && !notNumber.func;
|
364 | var notAfterValue = !notNumber || !notNumber.postfix && !notNumber.infix;
|
365 |
|
366 | if (bad || (afterValue ? notAfterValue : notNewValue)) {
|
367 | throw new PolishedError(37, match ? match.index : expression.length, expression);
|
368 | }
|
369 |
|
370 | if (afterValue) {
|
371 |
|
372 | var curr = notNumber.postfix || notNumber.infix;
|
373 |
|
374 | do {
|
375 | var prev = operators[operators.length - 1];
|
376 | if ((curr.precedence - prev.precedence || prev.rightToLeft) > 0) break;
|
377 | } while (exec(operators, values));
|
378 |
|
379 |
|
380 | afterValue = curr.notation === 'postfix';
|
381 |
|
382 | if (curr.symbol !== ')') {
|
383 | operators.push(curr);
|
384 |
|
385 | if (afterValue) exec(operators, values);
|
386 | }
|
387 | } else if (notNumber) {
|
388 |
|
389 | operators.push(notNumber.prefix || notNumber.func);
|
390 |
|
391 | if (notNumber.func) {
|
392 |
|
393 | match = pattern.exec(expression);
|
394 |
|
395 | if (!match || match[0] !== '(') {
|
396 | throw new PolishedError(38, match ? match.index : expression.length, expression);
|
397 | }
|
398 | }
|
399 | } else {
|
400 |
|
401 | values.push(+token);
|
402 | afterValue = true;
|
403 | }
|
404 | } while (match && operators.length);
|
405 |
|
406 | if (operators.length) {
|
407 | throw new PolishedError(39, match ? match.index : expression.length, expression);
|
408 | } else if (match) {
|
409 | throw new PolishedError(40, match ? match.index : expression.length, expression);
|
410 | } else {
|
411 | return values.pop();
|
412 | }
|
413 | }
|
414 |
|
415 | function reverseString(str) {
|
416 | return str.split('').reverse().join('');
|
417 | }
|
418 | |
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 | function math(formula, additionalSymbols) {
|
450 | var reversedFormula = reverseString(formula);
|
451 | var formulaMatch = reversedFormula.match(unitRegExp);
|
452 |
|
453 | if (formulaMatch && !formulaMatch.every(function (unit) {
|
454 | return unit === formulaMatch[0];
|
455 | })) {
|
456 | throw new PolishedError(41);
|
457 | }
|
458 |
|
459 | var cleanFormula = reverseString(reversedFormula.replace(unitRegExp, ''));
|
460 | return "" + calculate(cleanFormula, additionalSymbols) + (formulaMatch ? reverseString(formulaMatch[0]) : '');
|
461 | }
|
462 |
|
463 | var cssVariableRegex = /--[\S]*/g;
|
464 | |
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 | function cssVar(cssVariable, defaultValue) {
|
486 | if (!cssVariable || !cssVariable.match(cssVariableRegex)) {
|
487 | throw new PolishedError(73);
|
488 | }
|
489 |
|
490 | var variableValue;
|
491 |
|
492 |
|
493 |
|
494 |
|
495 | if (typeof document !== 'undefined' && document.documentElement !== null) {
|
496 | variableValue = getComputedStyle(document.documentElement).getPropertyValue(cssVariable);
|
497 | }
|
498 |
|
499 |
|
500 |
|
501 | if (variableValue) {
|
502 | return variableValue.trim();
|
503 | } else if (defaultValue) {
|
504 | return defaultValue;
|
505 | }
|
506 |
|
507 | throw new PolishedError(74);
|
508 | }
|
509 |
|
510 |
|
511 | function capitalizeString(string) {
|
512 | return string.charAt(0).toUpperCase() + string.slice(1);
|
513 | }
|
514 |
|
515 | var positionMap = ['Top', 'Right', 'Bottom', 'Left'];
|
516 |
|
517 | function generateProperty(property, position) {
|
518 | if (!property) return position.toLowerCase();
|
519 | var splitProperty = property.split('-');
|
520 |
|
521 | if (splitProperty.length > 1) {
|
522 | splitProperty.splice(1, 0, position);
|
523 | return splitProperty.reduce(function (acc, val) {
|
524 | return "" + acc + capitalizeString(val);
|
525 | });
|
526 | }
|
527 |
|
528 | var joinedProperty = property.replace(/([a-z])([A-Z])/g, "$1" + position + "$2");
|
529 | return property === joinedProperty ? "" + property + position : joinedProperty;
|
530 | }
|
531 |
|
532 | function generateStyles(property, valuesWithDefaults) {
|
533 | var styles = {};
|
534 |
|
535 | for (var i = 0; i < valuesWithDefaults.length; i += 1) {
|
536 | if (valuesWithDefaults[i] || valuesWithDefaults[i] === 0) {
|
537 | styles[generateProperty(property, positionMap[i])] = valuesWithDefaults[i];
|
538 | }
|
539 | }
|
540 |
|
541 | return styles;
|
542 | }
|
543 | |
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 | function directionalProperty(property) {
|
568 | for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
569 | values[_key - 1] = arguments[_key];
|
570 | }
|
571 |
|
572 |
|
573 | var firstValue = values[0],
|
574 | _values$ = values[1],
|
575 | secondValue = _values$ === void 0 ? firstValue : _values$,
|
576 | _values$2 = values[2],
|
577 | thirdValue = _values$2 === void 0 ? firstValue : _values$2,
|
578 | _values$3 = values[3],
|
579 | fourthValue = _values$3 === void 0 ? secondValue : _values$3;
|
580 | var valuesWithDefaults = [firstValue, secondValue, thirdValue, fourthValue];
|
581 | return generateStyles(property, valuesWithDefaults);
|
582 | }
|
583 |
|
584 | |
585 |
|
586 |
|
587 |
|
588 | function endsWith(string, suffix) {
|
589 | return string.substr(-suffix.length) === suffix;
|
590 | }
|
591 |
|
592 | var cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
|
593 | |
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 | function stripUnit(value) {
|
615 | if (typeof value !== 'string') return value;
|
616 | var matchedValue = value.match(cssRegex);
|
617 | return matchedValue ? parseFloat(value) : value;
|
618 | }
|
619 |
|
620 | |
621 |
|
622 |
|
623 |
|
624 |
|
625 | var pxtoFactory = function pxtoFactory(to) {
|
626 | return function (pxval, base) {
|
627 | if (base === void 0) {
|
628 | base = '16px';
|
629 | }
|
630 |
|
631 | var newPxval = pxval;
|
632 | var newBase = base;
|
633 |
|
634 | if (typeof pxval === 'string') {
|
635 | if (!endsWith(pxval, 'px')) {
|
636 | throw new PolishedError(69, to, pxval);
|
637 | }
|
638 |
|
639 | newPxval = stripUnit(pxval);
|
640 | }
|
641 |
|
642 | if (typeof base === 'string') {
|
643 | if (!endsWith(base, 'px')) {
|
644 | throw new PolishedError(70, to, base);
|
645 | }
|
646 |
|
647 | newBase = stripUnit(base);
|
648 | }
|
649 |
|
650 | if (typeof newPxval === 'string') {
|
651 | throw new PolishedError(71, pxval, to);
|
652 | }
|
653 |
|
654 | if (typeof newBase === 'string') {
|
655 | throw new PolishedError(72, base, to);
|
656 | }
|
657 |
|
658 | return "" + newPxval / newBase + to;
|
659 | };
|
660 | };
|
661 |
|
662 | |
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 | var em = pxtoFactory('em');
|
687 |
|
688 | var cssRegex$1 = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/;
|
689 | |
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 | function getValueAndUnit(value) {
|
714 | if (typeof value !== 'string') return [value, ''];
|
715 | var matchedValue = value.match(cssRegex$1);
|
716 | if (matchedValue) return [parseFloat(value), matchedValue[2]];
|
717 | return [value, undefined];
|
718 | }
|
719 |
|
720 | |
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 | function important(styleBlock, rules) {
|
746 | if (typeof styleBlock !== 'object' || styleBlock === null) {
|
747 | throw new PolishedError(75, typeof styleBlock);
|
748 | }
|
749 |
|
750 | var newStyleBlock = {};
|
751 | Object.keys(styleBlock).forEach(function (key) {
|
752 | if (typeof styleBlock[key] === 'object' && styleBlock[key] !== null) {
|
753 | newStyleBlock[key] = important(styleBlock[key], rules);
|
754 | } else if (!rules || rules && (rules === key || rules.indexOf(key) >= 0)) {
|
755 | newStyleBlock[key] = styleBlock[key] + " !important";
|
756 | } else {
|
757 | newStyleBlock[key] = styleBlock[key];
|
758 | }
|
759 | });
|
760 | return newStyleBlock;
|
761 | }
|
762 |
|
763 | var ratioNames = {
|
764 | minorSecond: 1.067,
|
765 | majorSecond: 1.125,
|
766 | minorThird: 1.2,
|
767 | majorThird: 1.25,
|
768 | perfectFourth: 1.333,
|
769 | augFourth: 1.414,
|
770 | perfectFifth: 1.5,
|
771 | minorSixth: 1.6,
|
772 | goldenSection: 1.618,
|
773 | majorSixth: 1.667,
|
774 | minorSeventh: 1.778,
|
775 | majorSeventh: 1.875,
|
776 | octave: 2,
|
777 | majorTenth: 2.5,
|
778 | majorEleventh: 2.667,
|
779 | majorTwelfth: 3,
|
780 | doubleOctave: 4
|
781 | };
|
782 |
|
783 | function getRatio(ratioName) {
|
784 | return ratioNames[ratioName];
|
785 | }
|
786 | |
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 | function modularScale(steps, base, ratio) {
|
810 | if (base === void 0) {
|
811 | base = '1em';
|
812 | }
|
813 |
|
814 | if (ratio === void 0) {
|
815 | ratio = 1.333;
|
816 | }
|
817 |
|
818 | if (typeof steps !== 'number') {
|
819 | throw new PolishedError(42);
|
820 | }
|
821 |
|
822 | if (typeof ratio === 'string' && !ratioNames[ratio]) {
|
823 | throw new PolishedError(43);
|
824 | }
|
825 |
|
826 | var _ref = typeof base === 'string' ? getValueAndUnit(base) : [base, ''],
|
827 | realBase = _ref[0],
|
828 | unit = _ref[1];
|
829 |
|
830 | var realRatio = typeof ratio === 'string' ? getRatio(ratio) : ratio;
|
831 |
|
832 | if (typeof realBase === 'string') {
|
833 | throw new PolishedError(44, base);
|
834 | }
|
835 |
|
836 | return "" + realBase * Math.pow(realRatio, steps) + (unit || '');
|
837 | }
|
838 |
|
839 | |
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 | var rem = pxtoFactory('rem');
|
864 |
|
865 | var defaultFontSize = 16;
|
866 |
|
867 | function convertBase(base) {
|
868 | var deconstructedValue = getValueAndUnit(base);
|
869 |
|
870 | if (deconstructedValue[1] === 'px') {
|
871 | return parseFloat(base);
|
872 | }
|
873 |
|
874 | if (deconstructedValue[1] === '%') {
|
875 | return parseFloat(base) / 100 * defaultFontSize;
|
876 | }
|
877 |
|
878 | throw new PolishedError(78, deconstructedValue[1]);
|
879 | }
|
880 |
|
881 | function getBaseFromDoc() {
|
882 |
|
883 |
|
884 |
|
885 | if (typeof document !== 'undefined' && document.documentElement !== null) {
|
886 | var rootFontSize = getComputedStyle(document.documentElement).fontSize;
|
887 | return rootFontSize ? convertBase(rootFontSize) : defaultFontSize;
|
888 | }
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 | return defaultFontSize;
|
895 | }
|
896 | |
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 | function remToPx(value, base) {
|
921 | var deconstructedValue = getValueAndUnit(value);
|
922 |
|
923 | if (deconstructedValue[1] !== 'rem' && deconstructedValue[1] !== '') {
|
924 | throw new PolishedError(77, deconstructedValue[1]);
|
925 | }
|
926 |
|
927 | var newBase = base ? convertBase(base) : getBaseFromDoc();
|
928 | return deconstructedValue[0] * newBase + "px";
|
929 | }
|
930 |
|
931 | var functionsMap = {
|
932 | back: 'cubic-bezier(0.600, -0.280, 0.735, 0.045)',
|
933 | circ: 'cubic-bezier(0.600, 0.040, 0.980, 0.335)',
|
934 | cubic: 'cubic-bezier(0.550, 0.055, 0.675, 0.190)',
|
935 | expo: 'cubic-bezier(0.950, 0.050, 0.795, 0.035)',
|
936 | quad: 'cubic-bezier(0.550, 0.085, 0.680, 0.530)',
|
937 | quart: 'cubic-bezier(0.895, 0.030, 0.685, 0.220)',
|
938 | quint: 'cubic-bezier(0.755, 0.050, 0.855, 0.060)',
|
939 | sine: 'cubic-bezier(0.470, 0.000, 0.745, 0.715)'
|
940 | };
|
941 | |
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 | function easeIn(functionName) {
|
963 | return functionsMap[functionName.toLowerCase().trim()];
|
964 | }
|
965 |
|
966 | var functionsMap$1 = {
|
967 | back: 'cubic-bezier(0.680, -0.550, 0.265, 1.550)',
|
968 | circ: 'cubic-bezier(0.785, 0.135, 0.150, 0.860)',
|
969 | cubic: 'cubic-bezier(0.645, 0.045, 0.355, 1.000)',
|
970 | expo: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)',
|
971 | quad: 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
|
972 | quart: 'cubic-bezier(0.770, 0.000, 0.175, 1.000)',
|
973 | quint: 'cubic-bezier(0.860, 0.000, 0.070, 1.000)',
|
974 | sine: 'cubic-bezier(0.445, 0.050, 0.550, 0.950)'
|
975 | };
|
976 | |
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 | function easeInOut(functionName) {
|
998 | return functionsMap$1[functionName.toLowerCase().trim()];
|
999 | }
|
1000 |
|
1001 | var functionsMap$2 = {
|
1002 | back: 'cubic-bezier(0.175, 0.885, 0.320, 1.275)',
|
1003 | cubic: 'cubic-bezier(0.215, 0.610, 0.355, 1.000)',
|
1004 | circ: 'cubic-bezier(0.075, 0.820, 0.165, 1.000)',
|
1005 | expo: 'cubic-bezier(0.190, 1.000, 0.220, 1.000)',
|
1006 | quad: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
|
1007 | quart: 'cubic-bezier(0.165, 0.840, 0.440, 1.000)',
|
1008 | quint: 'cubic-bezier(0.230, 1.000, 0.320, 1.000)',
|
1009 | sine: 'cubic-bezier(0.390, 0.575, 0.565, 1.000)'
|
1010 | };
|
1011 | |
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 | function easeOut(functionName) {
|
1033 | return functionsMap$2[functionName.toLowerCase().trim()];
|
1034 | }
|
1035 |
|
1036 | |
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 | function between(fromSize, toSize, minScreen, maxScreen) {
|
1061 | if (minScreen === void 0) {
|
1062 | minScreen = '320px';
|
1063 | }
|
1064 |
|
1065 | if (maxScreen === void 0) {
|
1066 | maxScreen = '1200px';
|
1067 | }
|
1068 |
|
1069 | var _getValueAndUnit = getValueAndUnit(fromSize),
|
1070 | unitlessFromSize = _getValueAndUnit[0],
|
1071 | fromSizeUnit = _getValueAndUnit[1];
|
1072 |
|
1073 | var _getValueAndUnit2 = getValueAndUnit(toSize),
|
1074 | unitlessToSize = _getValueAndUnit2[0],
|
1075 | toSizeUnit = _getValueAndUnit2[1];
|
1076 |
|
1077 | var _getValueAndUnit3 = getValueAndUnit(minScreen),
|
1078 | unitlessMinScreen = _getValueAndUnit3[0],
|
1079 | minScreenUnit = _getValueAndUnit3[1];
|
1080 |
|
1081 | var _getValueAndUnit4 = getValueAndUnit(maxScreen),
|
1082 | unitlessMaxScreen = _getValueAndUnit4[0],
|
1083 | maxScreenUnit = _getValueAndUnit4[1];
|
1084 |
|
1085 | if (typeof unitlessMinScreen !== 'number' || typeof unitlessMaxScreen !== 'number' || !minScreenUnit || !maxScreenUnit || minScreenUnit !== maxScreenUnit) {
|
1086 | throw new PolishedError(47);
|
1087 | }
|
1088 |
|
1089 | if (typeof unitlessFromSize !== 'number' || typeof unitlessToSize !== 'number' || fromSizeUnit !== toSizeUnit) {
|
1090 | throw new PolishedError(48);
|
1091 | }
|
1092 |
|
1093 | if (fromSizeUnit !== minScreenUnit || toSizeUnit !== maxScreenUnit) {
|
1094 | throw new PolishedError(76);
|
1095 | }
|
1096 |
|
1097 | var slope = (unitlessFromSize - unitlessToSize) / (unitlessMinScreen - unitlessMaxScreen);
|
1098 | var base = unitlessToSize - slope * unitlessMaxScreen;
|
1099 | return "calc(" + base.toFixed(2) + (fromSizeUnit || '') + " + " + (100 * slope).toFixed(2) + "vw)";
|
1100 | }
|
1101 |
|
1102 | |
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 | function clearFix(parent) {
|
1125 | var _ref;
|
1126 |
|
1127 | if (parent === void 0) {
|
1128 | parent = '&';
|
1129 | }
|
1130 |
|
1131 | var pseudoSelector = parent + "::after";
|
1132 | return _ref = {}, _ref[pseudoSelector] = {
|
1133 | clear: 'both',
|
1134 | content: '""',
|
1135 | display: 'table'
|
1136 | }, _ref;
|
1137 | }
|
1138 |
|
1139 | |
1140 |
|
1141 |
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 | function cover(offset) {
|
1164 | if (offset === void 0) {
|
1165 | offset = 0;
|
1166 | }
|
1167 |
|
1168 | return {
|
1169 | position: 'absolute',
|
1170 | top: offset,
|
1171 | right: offset,
|
1172 | bottom: offset,
|
1173 | left: offset
|
1174 | };
|
1175 | }
|
1176 |
|
1177 | |
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 | function ellipsis(width, lines) {
|
1203 | if (lines === void 0) {
|
1204 | lines = 1;
|
1205 | }
|
1206 |
|
1207 | var styles = {
|
1208 | display: 'inline-block',
|
1209 | maxWidth: width || '100%',
|
1210 | overflow: 'hidden',
|
1211 | textOverflow: 'ellipsis',
|
1212 | whiteSpace: 'nowrap',
|
1213 | wordWrap: 'normal'
|
1214 | };
|
1215 | return lines > 1 ? _extends__default['default']({}, styles, {
|
1216 | WebkitBoxOrient: 'vertical',
|
1217 | WebkitLineClamp: lines,
|
1218 | display: '-webkit-box',
|
1219 | whiteSpace: 'normal'
|
1220 | }) : styles;
|
1221 | }
|
1222 |
|
1223 | function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
|
1224 |
|
1225 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
1226 |
|
1227 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
1228 |
|
1229 | |
1230 |
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 | function fluidRange(cssProp, minScreen, maxScreen) {
|
1272 | if (minScreen === void 0) {
|
1273 | minScreen = '320px';
|
1274 | }
|
1275 |
|
1276 | if (maxScreen === void 0) {
|
1277 | maxScreen = '1200px';
|
1278 | }
|
1279 |
|
1280 | if (!Array.isArray(cssProp) && typeof cssProp !== 'object' || cssProp === null) {
|
1281 | throw new PolishedError(49);
|
1282 | }
|
1283 |
|
1284 | if (Array.isArray(cssProp)) {
|
1285 | var mediaQueries = {};
|
1286 | var fallbacks = {};
|
1287 |
|
1288 | for (var _iterator = _createForOfIteratorHelperLoose(cssProp), _step; !(_step = _iterator()).done;) {
|
1289 | var _extends2, _extends3;
|
1290 |
|
1291 | var obj = _step.value;
|
1292 |
|
1293 | if (!obj.prop || !obj.fromSize || !obj.toSize) {
|
1294 | throw new PolishedError(50);
|
1295 | }
|
1296 |
|
1297 | fallbacks[obj.prop] = obj.fromSize;
|
1298 | mediaQueries["@media (min-width: " + minScreen + ")"] = _extends__default['default']({}, mediaQueries["@media (min-width: " + minScreen + ")"], (_extends2 = {}, _extends2[obj.prop] = between(obj.fromSize, obj.toSize, minScreen, maxScreen), _extends2));
|
1299 | mediaQueries["@media (min-width: " + maxScreen + ")"] = _extends__default['default']({}, mediaQueries["@media (min-width: " + maxScreen + ")"], (_extends3 = {}, _extends3[obj.prop] = obj.toSize, _extends3));
|
1300 | }
|
1301 |
|
1302 | return _extends__default['default']({}, fallbacks, mediaQueries);
|
1303 | } else {
|
1304 | var _ref, _ref2, _ref3;
|
1305 |
|
1306 | if (!cssProp.prop || !cssProp.fromSize || !cssProp.toSize) {
|
1307 | throw new PolishedError(51);
|
1308 | }
|
1309 |
|
1310 | return _ref3 = {}, _ref3[cssProp.prop] = cssProp.fromSize, _ref3["@media (min-width: " + minScreen + ")"] = (_ref = {}, _ref[cssProp.prop] = between(cssProp.fromSize, cssProp.toSize, minScreen, maxScreen), _ref), _ref3["@media (min-width: " + maxScreen + ")"] = (_ref2 = {}, _ref2[cssProp.prop] = cssProp.toSize, _ref2), _ref3;
|
1311 | }
|
1312 | }
|
1313 |
|
1314 | var dataURIRegex = /^\s*data:([a-z]+\/[a-z-]+(;[a-z-]+=[a-z-]+)?)?(;charset=[a-z0-9-]+)?(;base64)?,[a-z0-9!$&',()*+,;=\-._~:@/?%\s]*\s*$/i;
|
1315 | var formatHintMap = {
|
1316 | woff: 'woff',
|
1317 | woff2: 'woff2',
|
1318 | ttf: 'truetype',
|
1319 | otf: 'opentype',
|
1320 | eot: 'embedded-opentype',
|
1321 | svg: 'svg',
|
1322 | svgz: 'svg'
|
1323 | };
|
1324 |
|
1325 | function generateFormatHint(format, formatHint) {
|
1326 | if (!formatHint) return '';
|
1327 | return " format(\"" + formatHintMap[format] + "\")";
|
1328 | }
|
1329 |
|
1330 | function isDataURI(fontFilePath) {
|
1331 | return !!fontFilePath.match(dataURIRegex);
|
1332 | }
|
1333 |
|
1334 | function generateFileReferences(fontFilePath, fileFormats, formatHint) {
|
1335 | if (isDataURI(fontFilePath)) {
|
1336 | return "url(\"" + fontFilePath + "\")" + generateFormatHint(fileFormats[0], formatHint);
|
1337 | }
|
1338 |
|
1339 | var fileFontReferences = fileFormats.map(function (format) {
|
1340 | return "url(\"" + fontFilePath + "." + format + "\")" + generateFormatHint(format, formatHint);
|
1341 | });
|
1342 | return fileFontReferences.join(', ');
|
1343 | }
|
1344 |
|
1345 | function generateLocalReferences(localFonts) {
|
1346 | var localFontReferences = localFonts.map(function (font) {
|
1347 | return "local(\"" + font + "\")";
|
1348 | });
|
1349 | return localFontReferences.join(', ');
|
1350 | }
|
1351 |
|
1352 | function generateSources(fontFilePath, localFonts, fileFormats, formatHint) {
|
1353 | var fontReferences = [];
|
1354 | if (localFonts) fontReferences.push(generateLocalReferences(localFonts));
|
1355 |
|
1356 | if (fontFilePath) {
|
1357 | fontReferences.push(generateFileReferences(fontFilePath, fileFormats, formatHint));
|
1358 | }
|
1359 |
|
1360 | return fontReferences.join(', ');
|
1361 | }
|
1362 | |
1363 |
|
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 | function fontFace(_ref) {
|
1392 | var fontFamily = _ref.fontFamily,
|
1393 | fontFilePath = _ref.fontFilePath,
|
1394 | fontStretch = _ref.fontStretch,
|
1395 | fontStyle = _ref.fontStyle,
|
1396 | fontVariant = _ref.fontVariant,
|
1397 | fontWeight = _ref.fontWeight,
|
1398 | _ref$fileFormats = _ref.fileFormats,
|
1399 | fileFormats = _ref$fileFormats === void 0 ? ['eot', 'woff2', 'woff', 'ttf', 'svg'] : _ref$fileFormats,
|
1400 | _ref$formatHint = _ref.formatHint,
|
1401 | formatHint = _ref$formatHint === void 0 ? false : _ref$formatHint,
|
1402 | _ref$localFonts = _ref.localFonts,
|
1403 | localFonts = _ref$localFonts === void 0 ? [fontFamily] : _ref$localFonts,
|
1404 | unicodeRange = _ref.unicodeRange,
|
1405 | fontDisplay = _ref.fontDisplay,
|
1406 | fontVariationSettings = _ref.fontVariationSettings,
|
1407 | fontFeatureSettings = _ref.fontFeatureSettings;
|
1408 |
|
1409 | if (!fontFamily) throw new PolishedError(55);
|
1410 |
|
1411 | if (!fontFilePath && !localFonts) {
|
1412 | throw new PolishedError(52);
|
1413 | }
|
1414 |
|
1415 | if (localFonts && !Array.isArray(localFonts)) {
|
1416 | throw new PolishedError(53);
|
1417 | }
|
1418 |
|
1419 | if (!Array.isArray(fileFormats)) {
|
1420 | throw new PolishedError(54);
|
1421 | }
|
1422 |
|
1423 | var fontFaceDeclaration = {
|
1424 | '@font-face': {
|
1425 | fontFamily: fontFamily,
|
1426 | src: generateSources(fontFilePath, localFonts, fileFormats, formatHint),
|
1427 | unicodeRange: unicodeRange,
|
1428 | fontStretch: fontStretch,
|
1429 | fontStyle: fontStyle,
|
1430 | fontVariant: fontVariant,
|
1431 | fontWeight: fontWeight,
|
1432 | fontDisplay: fontDisplay,
|
1433 | fontVariationSettings: fontVariationSettings,
|
1434 | fontFeatureSettings: fontFeatureSettings
|
1435 | }
|
1436 | };
|
1437 |
|
1438 | return JSON.parse(JSON.stringify(fontFaceDeclaration));
|
1439 | }
|
1440 |
|
1441 | |
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 | function hideText() {
|
1467 | return {
|
1468 | textIndent: '101%',
|
1469 | overflow: 'hidden',
|
1470 | whiteSpace: 'nowrap'
|
1471 | };
|
1472 | }
|
1473 |
|
1474 | |
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 |
|
1503 | function hideVisually() {
|
1504 | return {
|
1505 | border: '0',
|
1506 | clip: 'rect(0 0 0 0)',
|
1507 | height: '1px',
|
1508 | margin: '-1px',
|
1509 | overflow: 'hidden',
|
1510 | padding: '0',
|
1511 | position: 'absolute',
|
1512 | whiteSpace: 'nowrap',
|
1513 | width: '1px'
|
1514 | };
|
1515 | }
|
1516 |
|
1517 | |
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 | function hiDPI(ratio) {
|
1546 | if (ratio === void 0) {
|
1547 | ratio = 1.3;
|
1548 | }
|
1549 |
|
1550 | return "\n @media only screen and (-webkit-min-device-pixel-ratio: " + ratio + "),\n only screen and (min--moz-device-pixel-ratio: " + ratio + "),\n only screen and (-o-min-device-pixel-ratio: " + ratio + "/1),\n only screen and (min-resolution: " + Math.round(ratio * 96) + "dpi),\n only screen and (min-resolution: " + ratio + "dppx)\n ";
|
1551 | }
|
1552 |
|
1553 | function constructGradientValue(literals) {
|
1554 | var template = '';
|
1555 |
|
1556 | for (var _len = arguments.length, substitutions = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
1557 | substitutions[_key - 1] = arguments[_key];
|
1558 | }
|
1559 |
|
1560 | for (var i = 0; i < literals.length; i += 1) {
|
1561 | template += literals[i];
|
1562 |
|
1563 | if (i === substitutions.length - 1 && substitutions[i]) {
|
1564 | var definedValues = substitutions.filter(function (substitute) {
|
1565 | return !!substitute;
|
1566 | });
|
1567 |
|
1568 | if (definedValues.length > 1) {
|
1569 | template = template.slice(0, -1);
|
1570 | template += ", " + substitutions[i];
|
1571 | } else if (definedValues.length === 1) {
|
1572 | template += "" + substitutions[i];
|
1573 | }
|
1574 | } else if (substitutions[i]) {
|
1575 | template += substitutions[i] + " ";
|
1576 | }
|
1577 | }
|
1578 |
|
1579 | return template.trim();
|
1580 | }
|
1581 |
|
1582 | var _templateObject;
|
1583 |
|
1584 | |
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 | function linearGradient(_ref) {
|
1614 | var colorStops = _ref.colorStops,
|
1615 | fallback = _ref.fallback,
|
1616 | _ref$toDirection = _ref.toDirection,
|
1617 | toDirection = _ref$toDirection === void 0 ? '' : _ref$toDirection;
|
1618 |
|
1619 | if (!colorStops || colorStops.length < 2) {
|
1620 | throw new PolishedError(56);
|
1621 | }
|
1622 |
|
1623 | return {
|
1624 | backgroundColor: fallback || colorStops[0].replace(/,\s+/g, ',').split(' ')[0].replace(/,(?=\S)/g, ', '),
|
1625 | backgroundImage: constructGradientValue(_templateObject || (_templateObject = _taggedTemplateLiteralLoose__default['default'](["linear-gradient(", "", ")"])), toDirection, colorStops.join(', ').replace(/,(?=\S)/g, ', '))
|
1626 | };
|
1627 | }
|
1628 |
|
1629 | |
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 | function normalize() {
|
1649 | var _ref;
|
1650 |
|
1651 | return [(_ref = {
|
1652 | html: {
|
1653 | lineHeight: '1.15',
|
1654 | textSizeAdjust: '100%'
|
1655 | },
|
1656 | body: {
|
1657 | margin: '0'
|
1658 | },
|
1659 | main: {
|
1660 | display: 'block'
|
1661 | },
|
1662 | h1: {
|
1663 | fontSize: '2em',
|
1664 | margin: '0.67em 0'
|
1665 | },
|
1666 | hr: {
|
1667 | boxSizing: 'content-box',
|
1668 | height: '0',
|
1669 | overflow: 'visible'
|
1670 | },
|
1671 | pre: {
|
1672 | fontFamily: 'monospace, monospace',
|
1673 | fontSize: '1em'
|
1674 | },
|
1675 | a: {
|
1676 | backgroundColor: 'transparent'
|
1677 | },
|
1678 | 'abbr[title]': {
|
1679 | borderBottom: 'none',
|
1680 | textDecoration: 'underline'
|
1681 | }
|
1682 | }, _ref["b,\n strong"] = {
|
1683 | fontWeight: 'bolder'
|
1684 | }, _ref["code,\n kbd,\n samp"] = {
|
1685 | fontFamily: 'monospace, monospace',
|
1686 | fontSize: '1em'
|
1687 | }, _ref.small = {
|
1688 | fontSize: '80%'
|
1689 | }, _ref["sub,\n sup"] = {
|
1690 | fontSize: '75%',
|
1691 | lineHeight: '0',
|
1692 | position: 'relative',
|
1693 | verticalAlign: 'baseline'
|
1694 | }, _ref.sub = {
|
1695 | bottom: '-0.25em'
|
1696 | }, _ref.sup = {
|
1697 | top: '-0.5em'
|
1698 | }, _ref.img = {
|
1699 | borderStyle: 'none'
|
1700 | }, _ref["button,\n input,\n optgroup,\n select,\n textarea"] = {
|
1701 | fontFamily: 'inherit',
|
1702 | fontSize: '100%',
|
1703 | lineHeight: '1.15',
|
1704 | margin: '0'
|
1705 | }, _ref["button,\n input"] = {
|
1706 | overflow: 'visible'
|
1707 | }, _ref["button,\n select"] = {
|
1708 | textTransform: 'none'
|
1709 | }, _ref["button,\n html [type=\"button\"],\n [type=\"reset\"],\n [type=\"submit\"]"] = {
|
1710 | WebkitAppearance: 'button'
|
1711 | }, _ref["button::-moz-focus-inner,\n [type=\"button\"]::-moz-focus-inner,\n [type=\"reset\"]::-moz-focus-inner,\n [type=\"submit\"]::-moz-focus-inner"] = {
|
1712 | borderStyle: 'none',
|
1713 | padding: '0'
|
1714 | }, _ref["button:-moz-focusring,\n [type=\"button\"]:-moz-focusring,\n [type=\"reset\"]:-moz-focusring,\n [type=\"submit\"]:-moz-focusring"] = {
|
1715 | outline: '1px dotted ButtonText'
|
1716 | }, _ref.fieldset = {
|
1717 | padding: '0.35em 0.625em 0.75em'
|
1718 | }, _ref.legend = {
|
1719 | boxSizing: 'border-box',
|
1720 | color: 'inherit',
|
1721 | display: 'table',
|
1722 | maxWidth: '100%',
|
1723 | padding: '0',
|
1724 | whiteSpace: 'normal'
|
1725 | }, _ref.progress = {
|
1726 | verticalAlign: 'baseline'
|
1727 | }, _ref.textarea = {
|
1728 | overflow: 'auto'
|
1729 | }, _ref["[type=\"checkbox\"],\n [type=\"radio\"]"] = {
|
1730 | boxSizing: 'border-box',
|
1731 | padding: '0'
|
1732 | }, _ref["[type=\"number\"]::-webkit-inner-spin-button,\n [type=\"number\"]::-webkit-outer-spin-button"] = {
|
1733 | height: 'auto'
|
1734 | }, _ref['[type="search"]'] = {
|
1735 | WebkitAppearance: 'textfield',
|
1736 | outlineOffset: '-2px'
|
1737 | }, _ref['[type="search"]::-webkit-search-decoration'] = {
|
1738 | WebkitAppearance: 'none'
|
1739 | }, _ref['::-webkit-file-upload-button'] = {
|
1740 | WebkitAppearance: 'button',
|
1741 | font: 'inherit'
|
1742 | }, _ref.details = {
|
1743 | display: 'block'
|
1744 | }, _ref.summary = {
|
1745 | display: 'list-item'
|
1746 | }, _ref.template = {
|
1747 | display: 'none'
|
1748 | }, _ref['[hidden]'] = {
|
1749 | display: 'none'
|
1750 | }, _ref), {
|
1751 | 'abbr[title]': {
|
1752 | textDecoration: 'underline dotted'
|
1753 | }
|
1754 | }];
|
1755 | }
|
1756 |
|
1757 | var _templateObject$1;
|
1758 |
|
1759 | |
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 | function radialGradient(_ref) {
|
1791 | var colorStops = _ref.colorStops,
|
1792 | _ref$extent = _ref.extent,
|
1793 | extent = _ref$extent === void 0 ? '' : _ref$extent,
|
1794 | fallback = _ref.fallback,
|
1795 | _ref$position = _ref.position,
|
1796 | position = _ref$position === void 0 ? '' : _ref$position,
|
1797 | _ref$shape = _ref.shape,
|
1798 | shape = _ref$shape === void 0 ? '' : _ref$shape;
|
1799 |
|
1800 | if (!colorStops || colorStops.length < 2) {
|
1801 | throw new PolishedError(57);
|
1802 | }
|
1803 |
|
1804 | return {
|
1805 | backgroundColor: fallback || colorStops[0].split(' ')[0],
|
1806 | backgroundImage: constructGradientValue(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteralLoose__default['default'](["radial-gradient(", "", "", "", ")"])), position, shape, extent, colorStops.join(', '))
|
1807 | };
|
1808 | }
|
1809 |
|
1810 | |
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 | function retinaImage(filename, backgroundSize, extension, retinaFilename, retinaSuffix) {
|
1839 | var _ref;
|
1840 |
|
1841 | if (extension === void 0) {
|
1842 | extension = 'png';
|
1843 | }
|
1844 |
|
1845 | if (retinaSuffix === void 0) {
|
1846 | retinaSuffix = '_2x';
|
1847 | }
|
1848 |
|
1849 | if (!filename) {
|
1850 | throw new PolishedError(58);
|
1851 | }
|
1852 |
|
1853 |
|
1854 | var ext = extension.replace(/^\./, '');
|
1855 | var rFilename = retinaFilename ? retinaFilename + "." + ext : "" + filename + retinaSuffix + "." + ext;
|
1856 | return _ref = {
|
1857 | backgroundImage: "url(" + filename + "." + ext + ")"
|
1858 | }, _ref[hiDPI()] = _extends__default['default']({
|
1859 | backgroundImage: "url(" + rFilename + ")"
|
1860 | }, backgroundSize ? {
|
1861 | backgroundSize: backgroundSize
|
1862 | } : {}), _ref;
|
1863 | }
|
1864 |
|
1865 |
|
1866 | var functionsMap$3 = {
|
1867 | easeInBack: 'cubic-bezier(0.600, -0.280, 0.735, 0.045)',
|
1868 | easeInCirc: 'cubic-bezier(0.600, 0.040, 0.980, 0.335)',
|
1869 | easeInCubic: 'cubic-bezier(0.550, 0.055, 0.675, 0.190)',
|
1870 | easeInExpo: 'cubic-bezier(0.950, 0.050, 0.795, 0.035)',
|
1871 | easeInQuad: 'cubic-bezier(0.550, 0.085, 0.680, 0.530)',
|
1872 | easeInQuart: 'cubic-bezier(0.895, 0.030, 0.685, 0.220)',
|
1873 | easeInQuint: 'cubic-bezier(0.755, 0.050, 0.855, 0.060)',
|
1874 | easeInSine: 'cubic-bezier(0.470, 0.000, 0.745, 0.715)',
|
1875 | easeOutBack: 'cubic-bezier(0.175, 0.885, 0.320, 1.275)',
|
1876 | easeOutCubic: 'cubic-bezier(0.215, 0.610, 0.355, 1.000)',
|
1877 | easeOutCirc: 'cubic-bezier(0.075, 0.820, 0.165, 1.000)',
|
1878 | easeOutExpo: 'cubic-bezier(0.190, 1.000, 0.220, 1.000)',
|
1879 | easeOutQuad: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)',
|
1880 | easeOutQuart: 'cubic-bezier(0.165, 0.840, 0.440, 1.000)',
|
1881 | easeOutQuint: 'cubic-bezier(0.230, 1.000, 0.320, 1.000)',
|
1882 | easeOutSine: 'cubic-bezier(0.390, 0.575, 0.565, 1.000)',
|
1883 | easeInOutBack: 'cubic-bezier(0.680, -0.550, 0.265, 1.550)',
|
1884 | easeInOutCirc: 'cubic-bezier(0.785, 0.135, 0.150, 0.860)',
|
1885 | easeInOutCubic: 'cubic-bezier(0.645, 0.045, 0.355, 1.000)',
|
1886 | easeInOutExpo: 'cubic-bezier(1.000, 0.000, 0.000, 1.000)',
|
1887 | easeInOutQuad: 'cubic-bezier(0.455, 0.030, 0.515, 0.955)',
|
1888 | easeInOutQuart: 'cubic-bezier(0.770, 0.000, 0.175, 1.000)',
|
1889 | easeInOutQuint: 'cubic-bezier(0.860, 0.000, 0.070, 1.000)',
|
1890 | easeInOutSine: 'cubic-bezier(0.445, 0.050, 0.550, 0.950)'
|
1891 | };
|
1892 |
|
1893 |
|
1894 | function getTimingFunction(functionName) {
|
1895 | return functionsMap$3[functionName];
|
1896 | }
|
1897 | |
1898 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 |
|
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 | function timingFunctions(timingFunction) {
|
1922 | return getTimingFunction(timingFunction);
|
1923 | }
|
1924 |
|
1925 | var getBorderWidth = function getBorderWidth(pointingDirection, height, width) {
|
1926 | var fullWidth = "" + width[0] + (width[1] || '');
|
1927 | var halfWidth = "" + width[0] / 2 + (width[1] || '');
|
1928 | var fullHeight = "" + height[0] + (height[1] || '');
|
1929 | var halfHeight = "" + height[0] / 2 + (height[1] || '');
|
1930 |
|
1931 | switch (pointingDirection) {
|
1932 | case 'top':
|
1933 | return "0 " + halfWidth + " " + fullHeight + " " + halfWidth;
|
1934 |
|
1935 | case 'topLeft':
|
1936 | return fullWidth + " " + fullHeight + " 0 0";
|
1937 |
|
1938 | case 'left':
|
1939 | return halfHeight + " " + fullWidth + " " + halfHeight + " 0";
|
1940 |
|
1941 | case 'bottomLeft':
|
1942 | return fullWidth + " 0 0 " + fullHeight;
|
1943 |
|
1944 | case 'bottom':
|
1945 | return fullHeight + " " + halfWidth + " 0 " + halfWidth;
|
1946 |
|
1947 | case 'bottomRight':
|
1948 | return "0 0 " + fullWidth + " " + fullHeight;
|
1949 |
|
1950 | case 'right':
|
1951 | return halfHeight + " 0 " + halfHeight + " " + fullWidth;
|
1952 |
|
1953 | case 'topRight':
|
1954 | default:
|
1955 | return "0 " + fullWidth + " " + fullHeight + " 0";
|
1956 | }
|
1957 | };
|
1958 |
|
1959 | var getBorderColor = function getBorderColor(pointingDirection, foregroundColor) {
|
1960 | switch (pointingDirection) {
|
1961 | case 'top':
|
1962 | case 'bottomRight':
|
1963 | return {
|
1964 | borderBottomColor: foregroundColor
|
1965 | };
|
1966 |
|
1967 | case 'right':
|
1968 | case 'bottomLeft':
|
1969 | return {
|
1970 | borderLeftColor: foregroundColor
|
1971 | };
|
1972 |
|
1973 | case 'bottom':
|
1974 | case 'topLeft':
|
1975 | return {
|
1976 | borderTopColor: foregroundColor
|
1977 | };
|
1978 |
|
1979 | case 'left':
|
1980 | case 'topRight':
|
1981 | return {
|
1982 | borderRightColor: foregroundColor
|
1983 | };
|
1984 |
|
1985 | default:
|
1986 | throw new PolishedError(59);
|
1987 | }
|
1988 | };
|
1989 | |
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 |
|
2014 |
|
2015 |
|
2016 |
|
2017 | function triangle(_ref) {
|
2018 | var pointingDirection = _ref.pointingDirection,
|
2019 | height = _ref.height,
|
2020 | width = _ref.width,
|
2021 | foregroundColor = _ref.foregroundColor,
|
2022 | _ref$backgroundColor = _ref.backgroundColor,
|
2023 | backgroundColor = _ref$backgroundColor === void 0 ? 'transparent' : _ref$backgroundColor;
|
2024 | var widthAndUnit = getValueAndUnit(width);
|
2025 | var heightAndUnit = getValueAndUnit(height);
|
2026 |
|
2027 | if (isNaN(heightAndUnit[0]) || isNaN(widthAndUnit[0])) {
|
2028 | throw new PolishedError(60);
|
2029 | }
|
2030 |
|
2031 | return _extends__default['default']({
|
2032 | width: '0',
|
2033 | height: '0',
|
2034 | borderColor: backgroundColor
|
2035 | }, getBorderColor(pointingDirection, foregroundColor), {
|
2036 | borderStyle: 'solid',
|
2037 | borderWidth: getBorderWidth(pointingDirection, heightAndUnit, widthAndUnit)
|
2038 | });
|
2039 | }
|
2040 |
|
2041 | |
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 |
|
2056 |
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 |
|
2062 |
|
2063 | function wordWrap(wrap) {
|
2064 | if (wrap === void 0) {
|
2065 | wrap = 'break-word';
|
2066 | }
|
2067 |
|
2068 | var wordBreak = wrap === 'break-word' ? 'break-all' : wrap;
|
2069 | return {
|
2070 | overflowWrap: wrap,
|
2071 | wordWrap: wrap,
|
2072 | wordBreak: wordBreak
|
2073 | };
|
2074 | }
|
2075 |
|
2076 | function colorToInt(color) {
|
2077 | return Math.round(color * 255);
|
2078 | }
|
2079 |
|
2080 | function convertToInt(red, green, blue) {
|
2081 | return colorToInt(red) + "," + colorToInt(green) + "," + colorToInt(blue);
|
2082 | }
|
2083 |
|
2084 | function hslToRgb(hue, saturation, lightness, convert) {
|
2085 | if (convert === void 0) {
|
2086 | convert = convertToInt;
|
2087 | }
|
2088 |
|
2089 | if (saturation === 0) {
|
2090 |
|
2091 | return convert(lightness, lightness, lightness);
|
2092 | }
|
2093 |
|
2094 |
|
2095 | var huePrime = (hue % 360 + 360) % 360 / 60;
|
2096 | var chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
2097 | var secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1));
|
2098 | var red = 0;
|
2099 | var green = 0;
|
2100 | var blue = 0;
|
2101 |
|
2102 | if (huePrime >= 0 && huePrime < 1) {
|
2103 | red = chroma;
|
2104 | green = secondComponent;
|
2105 | } else if (huePrime >= 1 && huePrime < 2) {
|
2106 | red = secondComponent;
|
2107 | green = chroma;
|
2108 | } else if (huePrime >= 2 && huePrime < 3) {
|
2109 | green = chroma;
|
2110 | blue = secondComponent;
|
2111 | } else if (huePrime >= 3 && huePrime < 4) {
|
2112 | green = secondComponent;
|
2113 | blue = chroma;
|
2114 | } else if (huePrime >= 4 && huePrime < 5) {
|
2115 | red = secondComponent;
|
2116 | blue = chroma;
|
2117 | } else if (huePrime >= 5 && huePrime < 6) {
|
2118 | red = chroma;
|
2119 | blue = secondComponent;
|
2120 | }
|
2121 |
|
2122 | var lightnessModification = lightness - chroma / 2;
|
2123 | var finalRed = red + lightnessModification;
|
2124 | var finalGreen = green + lightnessModification;
|
2125 | var finalBlue = blue + lightnessModification;
|
2126 | return convert(finalRed, finalGreen, finalBlue);
|
2127 | }
|
2128 |
|
2129 | var namedColorMap = {
|
2130 | aliceblue: 'f0f8ff',
|
2131 | antiquewhite: 'faebd7',
|
2132 | aqua: '00ffff',
|
2133 | aquamarine: '7fffd4',
|
2134 | azure: 'f0ffff',
|
2135 | beige: 'f5f5dc',
|
2136 | bisque: 'ffe4c4',
|
2137 | black: '000',
|
2138 | blanchedalmond: 'ffebcd',
|
2139 | blue: '0000ff',
|
2140 | blueviolet: '8a2be2',
|
2141 | brown: 'a52a2a',
|
2142 | burlywood: 'deb887',
|
2143 | cadetblue: '5f9ea0',
|
2144 | chartreuse: '7fff00',
|
2145 | chocolate: 'd2691e',
|
2146 | coral: 'ff7f50',
|
2147 | cornflowerblue: '6495ed',
|
2148 | cornsilk: 'fff8dc',
|
2149 | crimson: 'dc143c',
|
2150 | cyan: '00ffff',
|
2151 | darkblue: '00008b',
|
2152 | darkcyan: '008b8b',
|
2153 | darkgoldenrod: 'b8860b',
|
2154 | darkgray: 'a9a9a9',
|
2155 | darkgreen: '006400',
|
2156 | darkgrey: 'a9a9a9',
|
2157 | darkkhaki: 'bdb76b',
|
2158 | darkmagenta: '8b008b',
|
2159 | darkolivegreen: '556b2f',
|
2160 | darkorange: 'ff8c00',
|
2161 | darkorchid: '9932cc',
|
2162 | darkred: '8b0000',
|
2163 | darksalmon: 'e9967a',
|
2164 | darkseagreen: '8fbc8f',
|
2165 | darkslateblue: '483d8b',
|
2166 | darkslategray: '2f4f4f',
|
2167 | darkslategrey: '2f4f4f',
|
2168 | darkturquoise: '00ced1',
|
2169 | darkviolet: '9400d3',
|
2170 | deeppink: 'ff1493',
|
2171 | deepskyblue: '00bfff',
|
2172 | dimgray: '696969',
|
2173 | dimgrey: '696969',
|
2174 | dodgerblue: '1e90ff',
|
2175 | firebrick: 'b22222',
|
2176 | floralwhite: 'fffaf0',
|
2177 | forestgreen: '228b22',
|
2178 | fuchsia: 'ff00ff',
|
2179 | gainsboro: 'dcdcdc',
|
2180 | ghostwhite: 'f8f8ff',
|
2181 | gold: 'ffd700',
|
2182 | goldenrod: 'daa520',
|
2183 | gray: '808080',
|
2184 | green: '008000',
|
2185 | greenyellow: 'adff2f',
|
2186 | grey: '808080',
|
2187 | honeydew: 'f0fff0',
|
2188 | hotpink: 'ff69b4',
|
2189 | indianred: 'cd5c5c',
|
2190 | indigo: '4b0082',
|
2191 | ivory: 'fffff0',
|
2192 | khaki: 'f0e68c',
|
2193 | lavender: 'e6e6fa',
|
2194 | lavenderblush: 'fff0f5',
|
2195 | lawngreen: '7cfc00',
|
2196 | lemonchiffon: 'fffacd',
|
2197 | lightblue: 'add8e6',
|
2198 | lightcoral: 'f08080',
|
2199 | lightcyan: 'e0ffff',
|
2200 | lightgoldenrodyellow: 'fafad2',
|
2201 | lightgray: 'd3d3d3',
|
2202 | lightgreen: '90ee90',
|
2203 | lightgrey: 'd3d3d3',
|
2204 | lightpink: 'ffb6c1',
|
2205 | lightsalmon: 'ffa07a',
|
2206 | lightseagreen: '20b2aa',
|
2207 | lightskyblue: '87cefa',
|
2208 | lightslategray: '789',
|
2209 | lightslategrey: '789',
|
2210 | lightsteelblue: 'b0c4de',
|
2211 | lightyellow: 'ffffe0',
|
2212 | lime: '0f0',
|
2213 | limegreen: '32cd32',
|
2214 | linen: 'faf0e6',
|
2215 | magenta: 'f0f',
|
2216 | maroon: '800000',
|
2217 | mediumaquamarine: '66cdaa',
|
2218 | mediumblue: '0000cd',
|
2219 | mediumorchid: 'ba55d3',
|
2220 | mediumpurple: '9370db',
|
2221 | mediumseagreen: '3cb371',
|
2222 | mediumslateblue: '7b68ee',
|
2223 | mediumspringgreen: '00fa9a',
|
2224 | mediumturquoise: '48d1cc',
|
2225 | mediumvioletred: 'c71585',
|
2226 | midnightblue: '191970',
|
2227 | mintcream: 'f5fffa',
|
2228 | mistyrose: 'ffe4e1',
|
2229 | moccasin: 'ffe4b5',
|
2230 | navajowhite: 'ffdead',
|
2231 | navy: '000080',
|
2232 | oldlace: 'fdf5e6',
|
2233 | olive: '808000',
|
2234 | olivedrab: '6b8e23',
|
2235 | orange: 'ffa500',
|
2236 | orangered: 'ff4500',
|
2237 | orchid: 'da70d6',
|
2238 | palegoldenrod: 'eee8aa',
|
2239 | palegreen: '98fb98',
|
2240 | paleturquoise: 'afeeee',
|
2241 | palevioletred: 'db7093',
|
2242 | papayawhip: 'ffefd5',
|
2243 | peachpuff: 'ffdab9',
|
2244 | peru: 'cd853f',
|
2245 | pink: 'ffc0cb',
|
2246 | plum: 'dda0dd',
|
2247 | powderblue: 'b0e0e6',
|
2248 | purple: '800080',
|
2249 | rebeccapurple: '639',
|
2250 | red: 'f00',
|
2251 | rosybrown: 'bc8f8f',
|
2252 | royalblue: '4169e1',
|
2253 | saddlebrown: '8b4513',
|
2254 | salmon: 'fa8072',
|
2255 | sandybrown: 'f4a460',
|
2256 | seagreen: '2e8b57',
|
2257 | seashell: 'fff5ee',
|
2258 | sienna: 'a0522d',
|
2259 | silver: 'c0c0c0',
|
2260 | skyblue: '87ceeb',
|
2261 | slateblue: '6a5acd',
|
2262 | slategray: '708090',
|
2263 | slategrey: '708090',
|
2264 | snow: 'fffafa',
|
2265 | springgreen: '00ff7f',
|
2266 | steelblue: '4682b4',
|
2267 | tan: 'd2b48c',
|
2268 | teal: '008080',
|
2269 | thistle: 'd8bfd8',
|
2270 | tomato: 'ff6347',
|
2271 | turquoise: '40e0d0',
|
2272 | violet: 'ee82ee',
|
2273 | wheat: 'f5deb3',
|
2274 | white: 'fff',
|
2275 | whitesmoke: 'f5f5f5',
|
2276 | yellow: 'ff0',
|
2277 | yellowgreen: '9acd32'
|
2278 | };
|
2279 | |
2280 |
|
2281 |
|
2282 |
|
2283 |
|
2284 | function nameToHex(color) {
|
2285 | if (typeof color !== 'string') return color;
|
2286 | var normalizedColorName = color.toLowerCase();
|
2287 | return namedColorMap[normalizedColorName] ? "#" + namedColorMap[normalizedColorName] : color;
|
2288 | }
|
2289 |
|
2290 | var hexRegex = /^#[a-fA-F0-9]{6}$/;
|
2291 | var hexRgbaRegex = /^#[a-fA-F0-9]{8}$/;
|
2292 | var reducedHexRegex = /^#[a-fA-F0-9]{3}$/;
|
2293 | var reducedRgbaHexRegex = /^#[a-fA-F0-9]{4}$/;
|
2294 | var rgbRegex = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i;
|
2295 | var rgbaRegex = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([-+]?[0-9]*[.]?[0-9]+)\s*\)$/i;
|
2296 | var hslRegex = /^hsl\(\s*(\d{0,3}[.]?[0-9]+)\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i;
|
2297 | var hslaRegex = /^hsla\(\s*(\d{0,3}[.]?[0-9]+)\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*,\s*(\d{1,3}[.]?[0-9]?)%\s*,\s*([-+]?[0-9]*[.]?[0-9]+)\s*\)$/i;
|
2298 | |
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 | function parseToRgb(color) {
|
2311 | if (typeof color !== 'string') {
|
2312 | throw new PolishedError(3);
|
2313 | }
|
2314 |
|
2315 | var normalizedColor = nameToHex(color);
|
2316 |
|
2317 | if (normalizedColor.match(hexRegex)) {
|
2318 | return {
|
2319 | red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16),
|
2320 | green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16),
|
2321 | blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16)
|
2322 | };
|
2323 | }
|
2324 |
|
2325 | if (normalizedColor.match(hexRgbaRegex)) {
|
2326 | var alpha = parseFloat((parseInt("" + normalizedColor[7] + normalizedColor[8], 16) / 255).toFixed(2));
|
2327 | return {
|
2328 | red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16),
|
2329 | green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16),
|
2330 | blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16),
|
2331 | alpha: alpha
|
2332 | };
|
2333 | }
|
2334 |
|
2335 | if (normalizedColor.match(reducedHexRegex)) {
|
2336 | return {
|
2337 | red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16),
|
2338 | green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16),
|
2339 | blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16)
|
2340 | };
|
2341 | }
|
2342 |
|
2343 | if (normalizedColor.match(reducedRgbaHexRegex)) {
|
2344 | var _alpha = parseFloat((parseInt("" + normalizedColor[4] + normalizedColor[4], 16) / 255).toFixed(2));
|
2345 |
|
2346 | return {
|
2347 | red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16),
|
2348 | green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16),
|
2349 | blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16),
|
2350 | alpha: _alpha
|
2351 | };
|
2352 | }
|
2353 |
|
2354 | var rgbMatched = rgbRegex.exec(normalizedColor);
|
2355 |
|
2356 | if (rgbMatched) {
|
2357 | return {
|
2358 | red: parseInt("" + rgbMatched[1], 10),
|
2359 | green: parseInt("" + rgbMatched[2], 10),
|
2360 | blue: parseInt("" + rgbMatched[3], 10)
|
2361 | };
|
2362 | }
|
2363 |
|
2364 | var rgbaMatched = rgbaRegex.exec(normalizedColor);
|
2365 |
|
2366 | if (rgbaMatched) {
|
2367 | return {
|
2368 | red: parseInt("" + rgbaMatched[1], 10),
|
2369 | green: parseInt("" + rgbaMatched[2], 10),
|
2370 | blue: parseInt("" + rgbaMatched[3], 10),
|
2371 | alpha: parseFloat("" + rgbaMatched[4])
|
2372 | };
|
2373 | }
|
2374 |
|
2375 | var hslMatched = hslRegex.exec(normalizedColor);
|
2376 |
|
2377 | if (hslMatched) {
|
2378 | var hue = parseInt("" + hslMatched[1], 10);
|
2379 | var saturation = parseInt("" + hslMatched[2], 10) / 100;
|
2380 | var lightness = parseInt("" + hslMatched[3], 10) / 100;
|
2381 | var rgbColorString = "rgb(" + hslToRgb(hue, saturation, lightness) + ")";
|
2382 | var hslRgbMatched = rgbRegex.exec(rgbColorString);
|
2383 |
|
2384 | if (!hslRgbMatched) {
|
2385 | throw new PolishedError(4, normalizedColor, rgbColorString);
|
2386 | }
|
2387 |
|
2388 | return {
|
2389 | red: parseInt("" + hslRgbMatched[1], 10),
|
2390 | green: parseInt("" + hslRgbMatched[2], 10),
|
2391 | blue: parseInt("" + hslRgbMatched[3], 10)
|
2392 | };
|
2393 | }
|
2394 |
|
2395 | var hslaMatched = hslaRegex.exec(normalizedColor);
|
2396 |
|
2397 | if (hslaMatched) {
|
2398 | var _hue = parseInt("" + hslaMatched[1], 10);
|
2399 |
|
2400 | var _saturation = parseInt("" + hslaMatched[2], 10) / 100;
|
2401 |
|
2402 | var _lightness = parseInt("" + hslaMatched[3], 10) / 100;
|
2403 |
|
2404 | var _rgbColorString = "rgb(" + hslToRgb(_hue, _saturation, _lightness) + ")";
|
2405 |
|
2406 | var _hslRgbMatched = rgbRegex.exec(_rgbColorString);
|
2407 |
|
2408 | if (!_hslRgbMatched) {
|
2409 | throw new PolishedError(4, normalizedColor, _rgbColorString);
|
2410 | }
|
2411 |
|
2412 | return {
|
2413 | red: parseInt("" + _hslRgbMatched[1], 10),
|
2414 | green: parseInt("" + _hslRgbMatched[2], 10),
|
2415 | blue: parseInt("" + _hslRgbMatched[3], 10),
|
2416 | alpha: parseFloat("" + hslaMatched[4])
|
2417 | };
|
2418 | }
|
2419 |
|
2420 | throw new PolishedError(5);
|
2421 | }
|
2422 |
|
2423 | function rgbToHsl(color) {
|
2424 |
|
2425 | var red = color.red / 255;
|
2426 | var green = color.green / 255;
|
2427 | var blue = color.blue / 255;
|
2428 | var max = Math.max(red, green, blue);
|
2429 | var min = Math.min(red, green, blue);
|
2430 | var lightness = (max + min) / 2;
|
2431 |
|
2432 | if (max === min) {
|
2433 |
|
2434 | if (color.alpha !== undefined) {
|
2435 | return {
|
2436 | hue: 0,
|
2437 | saturation: 0,
|
2438 | lightness: lightness,
|
2439 | alpha: color.alpha
|
2440 | };
|
2441 | } else {
|
2442 | return {
|
2443 | hue: 0,
|
2444 | saturation: 0,
|
2445 | lightness: lightness
|
2446 | };
|
2447 | }
|
2448 | }
|
2449 |
|
2450 | var hue;
|
2451 | var delta = max - min;
|
2452 | var saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min);
|
2453 |
|
2454 | switch (max) {
|
2455 | case red:
|
2456 | hue = (green - blue) / delta + (green < blue ? 6 : 0);
|
2457 | break;
|
2458 |
|
2459 | case green:
|
2460 | hue = (blue - red) / delta + 2;
|
2461 | break;
|
2462 |
|
2463 | default:
|
2464 |
|
2465 | hue = (red - green) / delta + 4;
|
2466 | break;
|
2467 | }
|
2468 |
|
2469 | hue *= 60;
|
2470 |
|
2471 | if (color.alpha !== undefined) {
|
2472 | return {
|
2473 | hue: hue,
|
2474 | saturation: saturation,
|
2475 | lightness: lightness,
|
2476 | alpha: color.alpha
|
2477 | };
|
2478 | }
|
2479 |
|
2480 | return {
|
2481 | hue: hue,
|
2482 | saturation: saturation,
|
2483 | lightness: lightness
|
2484 | };
|
2485 | }
|
2486 |
|
2487 | |
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 | function parseToHsl(color) {
|
2499 |
|
2500 |
|
2501 | return rgbToHsl(parseToRgb(color));
|
2502 | }
|
2503 |
|
2504 | |
2505 |
|
2506 |
|
2507 |
|
2508 | var reduceHexValue = function reduceHexValue(value) {
|
2509 | if (value.length === 7 && value[1] === value[2] && value[3] === value[4] && value[5] === value[6]) {
|
2510 | return "#" + value[1] + value[3] + value[5];
|
2511 | }
|
2512 |
|
2513 | return value;
|
2514 | };
|
2515 |
|
2516 | function numberToHex(value) {
|
2517 | var hex = value.toString(16);
|
2518 | return hex.length === 1 ? "0" + hex : hex;
|
2519 | }
|
2520 |
|
2521 | function colorToHex(color) {
|
2522 | return numberToHex(Math.round(color * 255));
|
2523 | }
|
2524 |
|
2525 | function convertToHex(red, green, blue) {
|
2526 | return reduceHexValue("#" + colorToHex(red) + colorToHex(green) + colorToHex(blue));
|
2527 | }
|
2528 |
|
2529 | function hslToHex(hue, saturation, lightness) {
|
2530 | return hslToRgb(hue, saturation, lightness, convertToHex);
|
2531 | }
|
2532 |
|
2533 | |
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 | function hsl(value, saturation, lightness) {
|
2557 | if (typeof value === 'number' && typeof saturation === 'number' && typeof lightness === 'number') {
|
2558 | return hslToHex(value, saturation, lightness);
|
2559 | } else if (typeof value === 'object' && saturation === undefined && lightness === undefined) {
|
2560 | return hslToHex(value.hue, value.saturation, value.lightness);
|
2561 | }
|
2562 |
|
2563 | throw new PolishedError(1);
|
2564 | }
|
2565 |
|
2566 | |
2567 |
|
2568 |
|
2569 |
|
2570 |
|
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 | function hsla(value, saturation, lightness, alpha) {
|
2593 | if (typeof value === 'number' && typeof saturation === 'number' && typeof lightness === 'number' && typeof alpha === 'number') {
|
2594 | return alpha >= 1 ? hslToHex(value, saturation, lightness) : "rgba(" + hslToRgb(value, saturation, lightness) + "," + alpha + ")";
|
2595 | } else if (typeof value === 'object' && saturation === undefined && lightness === undefined && alpha === undefined) {
|
2596 | return value.alpha >= 1 ? hslToHex(value.hue, value.saturation, value.lightness) : "rgba(" + hslToRgb(value.hue, value.saturation, value.lightness) + "," + value.alpha + ")";
|
2597 | }
|
2598 |
|
2599 | throw new PolishedError(2);
|
2600 | }
|
2601 |
|
2602 | |
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 |
|
2611 |
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 |
|
2623 |
|
2624 |
|
2625 | function rgb(value, green, blue) {
|
2626 | if (typeof value === 'number' && typeof green === 'number' && typeof blue === 'number') {
|
2627 | return reduceHexValue("#" + numberToHex(value) + numberToHex(green) + numberToHex(blue));
|
2628 | } else if (typeof value === 'object' && green === undefined && blue === undefined) {
|
2629 | return reduceHexValue("#" + numberToHex(value.red) + numberToHex(value.green) + numberToHex(value.blue));
|
2630 | }
|
2631 |
|
2632 | throw new PolishedError(6);
|
2633 | }
|
2634 |
|
2635 | |
2636 |
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 | function rgba(firstValue, secondValue, thirdValue, fourthValue) {
|
2670 | if (typeof firstValue === 'string' && typeof secondValue === 'number') {
|
2671 | var rgbValue = parseToRgb(firstValue);
|
2672 | return "rgba(" + rgbValue.red + "," + rgbValue.green + "," + rgbValue.blue + "," + secondValue + ")";
|
2673 | } else if (typeof firstValue === 'number' && typeof secondValue === 'number' && typeof thirdValue === 'number' && typeof fourthValue === 'number') {
|
2674 | return fourthValue >= 1 ? rgb(firstValue, secondValue, thirdValue) : "rgba(" + firstValue + "," + secondValue + "," + thirdValue + "," + fourthValue + ")";
|
2675 | } else if (typeof firstValue === 'object' && secondValue === undefined && thirdValue === undefined && fourthValue === undefined) {
|
2676 | return firstValue.alpha >= 1 ? rgb(firstValue.red, firstValue.green, firstValue.blue) : "rgba(" + firstValue.red + "," + firstValue.green + "," + firstValue.blue + "," + firstValue.alpha + ")";
|
2677 | }
|
2678 |
|
2679 | throw new PolishedError(7);
|
2680 | }
|
2681 |
|
2682 | var isRgb = function isRgb(color) {
|
2683 | return typeof color.red === 'number' && typeof color.green === 'number' && typeof color.blue === 'number' && (typeof color.alpha !== 'number' || typeof color.alpha === 'undefined');
|
2684 | };
|
2685 |
|
2686 | var isRgba = function isRgba(color) {
|
2687 | return typeof color.red === 'number' && typeof color.green === 'number' && typeof color.blue === 'number' && typeof color.alpha === 'number';
|
2688 | };
|
2689 |
|
2690 | var isHsl = function isHsl(color) {
|
2691 | return typeof color.hue === 'number' && typeof color.saturation === 'number' && typeof color.lightness === 'number' && (typeof color.alpha !== 'number' || typeof color.alpha === 'undefined');
|
2692 | };
|
2693 |
|
2694 | var isHsla = function isHsla(color) {
|
2695 | return typeof color.hue === 'number' && typeof color.saturation === 'number' && typeof color.lightness === 'number' && typeof color.alpha === 'number';
|
2696 | };
|
2697 | |
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 | function toColorString(color) {
|
2730 | if (typeof color !== 'object') throw new PolishedError(8);
|
2731 | if (isRgba(color)) return rgba(color);
|
2732 | if (isRgb(color)) return rgb(color);
|
2733 | if (isHsla(color)) return hsla(color);
|
2734 | if (isHsl(color)) return hsl(color);
|
2735 | throw new PolishedError(8);
|
2736 | }
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 |
|
2742 | function curried(f, length, acc) {
|
2743 | return function fn() {
|
2744 |
|
2745 | var combined = acc.concat(Array.prototype.slice.call(arguments));
|
2746 | return combined.length >= length ? f.apply(this, combined) : curried(f, length, combined);
|
2747 | };
|
2748 | }
|
2749 |
|
2750 |
|
2751 | function curry(f) {
|
2752 |
|
2753 | return curried(f, f.length, []);
|
2754 | }
|
2755 |
|
2756 | |
2757 |
|
2758 |
|
2759 |
|
2760 |
|
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 | function adjustHue(degree, color) {
|
2782 | if (color === 'transparent') return color;
|
2783 | var hslColor = parseToHsl(color);
|
2784 | return toColorString(_extends__default['default']({}, hslColor, {
|
2785 | hue: hslColor.hue + parseFloat(degree)
|
2786 | }));
|
2787 | }
|
2788 |
|
2789 |
|
2790 | var curriedAdjustHue = curry
|
2791 |
|
2792 | (adjustHue);
|
2793 |
|
2794 | |
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 | function complement(color) {
|
2818 | if (color === 'transparent') return color;
|
2819 | var hslColor = parseToHsl(color);
|
2820 | return toColorString(_extends__default['default']({}, hslColor, {
|
2821 | hue: (hslColor.hue + 180) % 360
|
2822 | }));
|
2823 | }
|
2824 |
|
2825 | function guard(lowerBoundary, upperBoundary, value) {
|
2826 | return Math.max(lowerBoundary, Math.min(upperBoundary, value));
|
2827 | }
|
2828 |
|
2829 | |
2830 |
|
2831 |
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 |
|
2837 |
|
2838 |
|
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 | function darken(amount, color) {
|
2854 | if (color === 'transparent') return color;
|
2855 | var hslColor = parseToHsl(color);
|
2856 | return toColorString(_extends__default['default']({}, hslColor, {
|
2857 | lightness: guard(0, 1, hslColor.lightness - parseFloat(amount))
|
2858 | }));
|
2859 | }
|
2860 |
|
2861 |
|
2862 | var curriedDarken = curry
|
2863 |
|
2864 | (darken);
|
2865 |
|
2866 | |
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 |
|
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 |
|
2885 |
|
2886 |
|
2887 |
|
2888 |
|
2889 |
|
2890 |
|
2891 | function desaturate(amount, color) {
|
2892 | if (color === 'transparent') return color;
|
2893 | var hslColor = parseToHsl(color);
|
2894 | return toColorString(_extends__default['default']({}, hslColor, {
|
2895 | saturation: guard(0, 1, hslColor.saturation - parseFloat(amount))
|
2896 | }));
|
2897 | }
|
2898 |
|
2899 |
|
2900 | var curriedDesaturate = curry
|
2901 |
|
2902 | (desaturate);
|
2903 |
|
2904 | |
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 | function getLuminance(color) {
|
2932 | if (color === 'transparent') return 0;
|
2933 | var rgbColor = parseToRgb(color);
|
2934 |
|
2935 | var _Object$keys$map = Object.keys(rgbColor).map(function (key) {
|
2936 | var channel = rgbColor[key] / 255;
|
2937 | return channel <= 0.03928 ? channel / 12.92 : Math.pow((channel + 0.055) / 1.055, 2.4);
|
2938 | }),
|
2939 | r = _Object$keys$map[0],
|
2940 | g = _Object$keys$map[1],
|
2941 | b = _Object$keys$map[2];
|
2942 |
|
2943 | return parseFloat((0.2126 * r + 0.7152 * g + 0.0722 * b).toFixed(3));
|
2944 | }
|
2945 |
|
2946 | |
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 | function getContrast(color1, color2) {
|
2955 | var luminance1 = getLuminance(color1);
|
2956 | var luminance2 = getLuminance(color2);
|
2957 | return parseFloat((luminance1 > luminance2 ? (luminance1 + 0.05) / (luminance2 + 0.05) : (luminance2 + 0.05) / (luminance1 + 0.05)).toFixed(2));
|
2958 | }
|
2959 |
|
2960 | |
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 | function grayscale(color) {
|
2984 | if (color === 'transparent') return color;
|
2985 | return toColorString(_extends__default['default']({}, parseToHsl(color), {
|
2986 | saturation: 0
|
2987 | }));
|
2988 | }
|
2989 |
|
2990 | |
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 |
|
2996 |
|
2997 |
|
2998 |
|
2999 |
|
3000 |
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 | function hslToColorString(color) {
|
3015 | if (typeof color === 'object' && typeof color.hue === 'number' && typeof color.saturation === 'number' && typeof color.lightness === 'number') {
|
3016 | if (color.alpha && typeof color.alpha === 'number') {
|
3017 | return hsla({
|
3018 | hue: color.hue,
|
3019 | saturation: color.saturation,
|
3020 | lightness: color.lightness,
|
3021 | alpha: color.alpha
|
3022 | });
|
3023 | }
|
3024 |
|
3025 | return hsl({
|
3026 | hue: color.hue,
|
3027 | saturation: color.saturation,
|
3028 | lightness: color.lightness
|
3029 | });
|
3030 | }
|
3031 |
|
3032 | throw new PolishedError(45);
|
3033 | }
|
3034 |
|
3035 | |
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 |
|
3052 |
|
3053 |
|
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 | function invert(color) {
|
3060 | if (color === 'transparent') return color;
|
3061 |
|
3062 | var value = parseToRgb(color);
|
3063 | return toColorString(_extends__default['default']({}, value, {
|
3064 | red: 255 - value.red,
|
3065 | green: 255 - value.green,
|
3066 | blue: 255 - value.blue
|
3067 | }));
|
3068 | }
|
3069 |
|
3070 | |
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 |
|
3084 |
|
3085 |
|
3086 |
|
3087 |
|
3088 |
|
3089 |
|
3090 |
|
3091 |
|
3092 |
|
3093 |
|
3094 | function lighten(amount, color) {
|
3095 | if (color === 'transparent') return color;
|
3096 | var hslColor = parseToHsl(color);
|
3097 | return toColorString(_extends__default['default']({}, hslColor, {
|
3098 | lightness: guard(0, 1, hslColor.lightness + parseFloat(amount))
|
3099 | }));
|
3100 | }
|
3101 |
|
3102 |
|
3103 | var curriedLighten = curry
|
3104 |
|
3105 | (lighten);
|
3106 |
|
3107 | |
3108 |
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 | function meetsContrastGuidelines(color1, color2) {
|
3115 | var contrastRatio = getContrast(color1, color2);
|
3116 | return {
|
3117 | AA: contrastRatio >= 4.5,
|
3118 | AALarge: contrastRatio >= 3,
|
3119 | AAA: contrastRatio >= 7,
|
3120 | AAALarge: contrastRatio >= 4.5
|
3121 | };
|
3122 | }
|
3123 |
|
3124 | |
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 |
|
3151 | function mix(weight, color, otherColor) {
|
3152 | if (color === 'transparent') return otherColor;
|
3153 | if (otherColor === 'transparent') return color;
|
3154 | if (weight === 0) return otherColor;
|
3155 | var parsedColor1 = parseToRgb(color);
|
3156 |
|
3157 | var color1 = _extends__default['default']({}, parsedColor1, {
|
3158 | alpha: typeof parsedColor1.alpha === 'number' ? parsedColor1.alpha : 1
|
3159 | });
|
3160 |
|
3161 | var parsedColor2 = parseToRgb(otherColor);
|
3162 |
|
3163 | var color2 = _extends__default['default']({}, parsedColor2, {
|
3164 | alpha: typeof parsedColor2.alpha === 'number' ? parsedColor2.alpha : 1
|
3165 | });
|
3166 |
|
3167 |
|
3168 |
|
3169 | var alphaDelta = color1.alpha - color2.alpha;
|
3170 | var x = parseFloat(weight) * 2 - 1;
|
3171 | var y = x * alphaDelta === -1 ? x : x + alphaDelta;
|
3172 | var z = 1 + x * alphaDelta;
|
3173 | var weight1 = (y / z + 1) / 2.0;
|
3174 | var weight2 = 1 - weight1;
|
3175 | var mixedColor = {
|
3176 | red: Math.floor(color1.red * weight1 + color2.red * weight2),
|
3177 | green: Math.floor(color1.green * weight1 + color2.green * weight2),
|
3178 | blue: Math.floor(color1.blue * weight1 + color2.blue * weight2),
|
3179 | alpha: color1.alpha * (parseFloat(weight) / 1.0) + color2.alpha * (1 - parseFloat(weight) / 1.0)
|
3180 | };
|
3181 | return rgba(mixedColor);
|
3182 | }
|
3183 |
|
3184 |
|
3185 | var curriedMix = curry
|
3186 |
|
3187 | (mix);
|
3188 |
|
3189 | |
3190 |
|
3191 |
|
3192 |
|
3193 |
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 | function opacify(amount, color) {
|
3218 | if (color === 'transparent') return color;
|
3219 | var parsedColor = parseToRgb(color);
|
3220 | var alpha = typeof parsedColor.alpha === 'number' ? parsedColor.alpha : 1;
|
3221 |
|
3222 | var colorWithAlpha = _extends__default['default']({}, parsedColor, {
|
3223 | alpha: guard(0, 1, (alpha * 100 + parseFloat(amount) * 100) / 100)
|
3224 | });
|
3225 |
|
3226 | return rgba(colorWithAlpha);
|
3227 | }
|
3228 |
|
3229 |
|
3230 | var curriedOpacify = curry
|
3231 |
|
3232 | (opacify);
|
3233 |
|
3234 | var defaultReturnIfLightColor = '#000';
|
3235 | var defaultReturnIfDarkColor = '#fff';
|
3236 | |
3237 |
|
3238 |
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 |
|
3260 |
|
3261 |
|
3262 |
|
3263 |
|
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 | function readableColor(color, returnIfLightColor, returnIfDarkColor, strict) {
|
3273 | if (returnIfLightColor === void 0) {
|
3274 | returnIfLightColor = defaultReturnIfLightColor;
|
3275 | }
|
3276 |
|
3277 | if (returnIfDarkColor === void 0) {
|
3278 | returnIfDarkColor = defaultReturnIfDarkColor;
|
3279 | }
|
3280 |
|
3281 | if (strict === void 0) {
|
3282 | strict = true;
|
3283 | }
|
3284 |
|
3285 | var isColorLight = getLuminance(color) > 0.179;
|
3286 | var preferredReturnColor = isColorLight ? returnIfLightColor : returnIfDarkColor;
|
3287 |
|
3288 | if (!strict || getContrast(color, preferredReturnColor) >= 4.5) {
|
3289 | return preferredReturnColor;
|
3290 | }
|
3291 |
|
3292 | return isColorLight ? defaultReturnIfLightColor : defaultReturnIfDarkColor;
|
3293 | }
|
3294 |
|
3295 | |
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 | function rgbToColorString(color) {
|
3320 | if (typeof color === 'object' && typeof color.red === 'number' && typeof color.green === 'number' && typeof color.blue === 'number') {
|
3321 | if (typeof color.alpha === 'number') {
|
3322 | return rgba({
|
3323 | red: color.red,
|
3324 | green: color.green,
|
3325 | blue: color.blue,
|
3326 | alpha: color.alpha
|
3327 | });
|
3328 | }
|
3329 |
|
3330 | return rgb({
|
3331 | red: color.red,
|
3332 | green: color.green,
|
3333 | blue: color.blue
|
3334 | });
|
3335 | }
|
3336 |
|
3337 | throw new PolishedError(46);
|
3338 | }
|
3339 |
|
3340 | |
3341 |
|
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 |
|
3355 |
|
3356 |
|
3357 |
|
3358 |
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 |
|
3366 | function saturate(amount, color) {
|
3367 | if (color === 'transparent') return color;
|
3368 | var hslColor = parseToHsl(color);
|
3369 | return toColorString(_extends__default['default']({}, hslColor, {
|
3370 | saturation: guard(0, 1, hslColor.saturation + parseFloat(amount))
|
3371 | }));
|
3372 | }
|
3373 |
|
3374 |
|
3375 | var curriedSaturate = curry
|
3376 |
|
3377 | (saturate);
|
3378 |
|
3379 | |
3380 |
|
3381 |
|
3382 |
|
3383 |
|
3384 |
|
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
|
3398 |
|
3399 |
|
3400 |
|
3401 |
|
3402 |
|
3403 | function setHue(hue, color) {
|
3404 | if (color === 'transparent') return color;
|
3405 | return toColorString(_extends__default['default']({}, parseToHsl(color), {
|
3406 | hue: parseFloat(hue)
|
3407 | }));
|
3408 | }
|
3409 |
|
3410 |
|
3411 | var curriedSetHue = curry
|
3412 |
|
3413 | (setHue);
|
3414 |
|
3415 | |
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 | function setLightness(lightness, color) {
|
3440 | if (color === 'transparent') return color;
|
3441 | return toColorString(_extends__default['default']({}, parseToHsl(color), {
|
3442 | lightness: parseFloat(lightness)
|
3443 | }));
|
3444 | }
|
3445 |
|
3446 |
|
3447 | var curriedSetLightness = curry
|
3448 |
|
3449 | (setLightness);
|
3450 |
|
3451 | |
3452 |
|
3453 |
|
3454 |
|
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 | function setSaturation(saturation, color) {
|
3476 | if (color === 'transparent') return color;
|
3477 | return toColorString(_extends__default['default']({}, parseToHsl(color), {
|
3478 | saturation: parseFloat(saturation)
|
3479 | }));
|
3480 | }
|
3481 |
|
3482 |
|
3483 | var curriedSetSaturation = curry
|
3484 |
|
3485 | (setSaturation);
|
3486 |
|
3487 | |
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 | function shade(percentage, color) {
|
3511 | if (color === 'transparent') return color;
|
3512 | return curriedMix(parseFloat(percentage), 'rgb(0, 0, 0)', color);
|
3513 | }
|
3514 |
|
3515 |
|
3516 | var curriedShade = curry
|
3517 |
|
3518 | (shade);
|
3519 |
|
3520 | |
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 | function tint(percentage, color) {
|
3544 | if (color === 'transparent') return color;
|
3545 | return curriedMix(parseFloat(percentage), 'rgb(255, 255, 255)', color);
|
3546 | }
|
3547 |
|
3548 |
|
3549 | var curriedTint = curry
|
3550 |
|
3551 | (tint);
|
3552 |
|
3553 | |
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 |
|
3563 |
|
3564 |
|
3565 |
|
3566 |
|
3567 |
|
3568 |
|
3569 |
|
3570 |
|
3571 |
|
3572 |
|
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 | function transparentize(amount, color) {
|
3582 | if (color === 'transparent') return color;
|
3583 | var parsedColor = parseToRgb(color);
|
3584 | var alpha = typeof parsedColor.alpha === 'number' ? parsedColor.alpha : 1;
|
3585 |
|
3586 | var colorWithAlpha = _extends__default['default']({}, parsedColor, {
|
3587 | alpha: guard(0, 1, +(alpha * 100 - parseFloat(amount) * 100).toFixed(2) / 100)
|
3588 | });
|
3589 |
|
3590 | return rgba(colorWithAlpha);
|
3591 | }
|
3592 |
|
3593 |
|
3594 | var curriedTransparentize = curry
|
3595 |
|
3596 | (transparentize);
|
3597 |
|
3598 | |
3599 |
|
3600 |
|
3601 |
|
3602 |
|
3603 |
|
3604 |
|
3605 |
|
3606 |
|
3607 |
|
3608 |
|
3609 |
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 |
|
3616 |
|
3617 |
|
3618 |
|
3619 |
|
3620 |
|
3621 |
|
3622 |
|
3623 |
|
3624 |
|
3625 |
|
3626 |
|
3627 |
|
3628 |
|
3629 |
|
3630 |
|
3631 |
|
3632 |
|
3633 |
|
3634 | function animation() {
|
3635 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
3636 | args[_key] = arguments[_key];
|
3637 | }
|
3638 |
|
3639 |
|
3640 | var multiMode = Array.isArray(args[0]);
|
3641 |
|
3642 | if (!multiMode && args.length > 8) {
|
3643 | throw new PolishedError(64);
|
3644 | }
|
3645 |
|
3646 | var code = args.map(function (arg) {
|
3647 | if (multiMode && !Array.isArray(arg) || !multiMode && Array.isArray(arg)) {
|
3648 | throw new PolishedError(65);
|
3649 | }
|
3650 |
|
3651 | if (Array.isArray(arg) && arg.length > 8) {
|
3652 | throw new PolishedError(66);
|
3653 | }
|
3654 |
|
3655 | return Array.isArray(arg) ? arg.join(' ') : arg;
|
3656 | }).join(', ');
|
3657 | return {
|
3658 | animation: code
|
3659 | };
|
3660 | }
|
3661 |
|
3662 | |
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 |
|
3677 |
|
3678 |
|
3679 |
|
3680 |
|
3681 | function backgroundImages() {
|
3682 | for (var _len = arguments.length, properties = new Array(_len), _key = 0; _key < _len; _key++) {
|
3683 | properties[_key] = arguments[_key];
|
3684 | }
|
3685 |
|
3686 | return {
|
3687 | backgroundImage: properties.join(', ')
|
3688 | };
|
3689 | }
|
3690 |
|
3691 | |
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 |
|
3699 |
|
3700 |
|
3701 |
|
3702 |
|
3703 |
|
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 | function backgrounds() {
|
3711 | for (var _len = arguments.length, properties = new Array(_len), _key = 0; _key < _len; _key++) {
|
3712 | properties[_key] = arguments[_key];
|
3713 | }
|
3714 |
|
3715 | return {
|
3716 | background: properties.join(', ')
|
3717 | };
|
3718 | }
|
3719 |
|
3720 | var sideMap = ['top', 'right', 'bottom', 'left'];
|
3721 | |
3722 |
|
3723 |
|
3724 |
|
3725 |
|
3726 |
|
3727 |
|
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 |
|
3737 |
|
3738 |
|
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 |
|
3762 | function border(sideKeyword) {
|
3763 | for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
3764 | values[_key - 1] = arguments[_key];
|
3765 | }
|
3766 |
|
3767 | if (typeof sideKeyword === 'string' && sideMap.indexOf(sideKeyword) >= 0) {
|
3768 | var _ref;
|
3769 |
|
3770 | return _ref = {}, _ref["border" + capitalizeString(sideKeyword) + "Width"] = values[0], _ref["border" + capitalizeString(sideKeyword) + "Style"] = values[1], _ref["border" + capitalizeString(sideKeyword) + "Color"] = values[2], _ref;
|
3771 | } else {
|
3772 | values.unshift(sideKeyword);
|
3773 | return {
|
3774 | borderWidth: values[0],
|
3775 | borderStyle: values[1],
|
3776 | borderColor: values[2]
|
3777 | };
|
3778 | }
|
3779 | }
|
3780 |
|
3781 | |
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 | function borderColor() {
|
3804 | for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
3805 | values[_key] = arguments[_key];
|
3806 | }
|
3807 |
|
3808 | return directionalProperty.apply(void 0, ['borderColor'].concat(values));
|
3809 | }
|
3810 |
|
3811 | |
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 |
|
3825 |
|
3826 |
|
3827 |
|
3828 |
|
3829 |
|
3830 |
|
3831 | function borderRadius(side, radius) {
|
3832 | var uppercaseSide = capitalizeString(side);
|
3833 |
|
3834 | if (!radius && radius !== 0) {
|
3835 | throw new PolishedError(62);
|
3836 | }
|
3837 |
|
3838 | if (uppercaseSide === 'Top' || uppercaseSide === 'Bottom') {
|
3839 | var _ref;
|
3840 |
|
3841 | return _ref = {}, _ref["border" + uppercaseSide + "RightRadius"] = radius, _ref["border" + uppercaseSide + "LeftRadius"] = radius, _ref;
|
3842 | }
|
3843 |
|
3844 | if (uppercaseSide === 'Left' || uppercaseSide === 'Right') {
|
3845 | var _ref2;
|
3846 |
|
3847 | return _ref2 = {}, _ref2["borderTop" + uppercaseSide + "Radius"] = radius, _ref2["borderBottom" + uppercaseSide + "Radius"] = radius, _ref2;
|
3848 | }
|
3849 |
|
3850 | throw new PolishedError(63);
|
3851 | }
|
3852 |
|
3853 | |
3854 |
|
3855 |
|
3856 |
|
3857 |
|
3858 |
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 |
|
3871 |
|
3872 |
|
3873 |
|
3874 |
|
3875 | function borderStyle() {
|
3876 | for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
3877 | values[_key] = arguments[_key];
|
3878 | }
|
3879 |
|
3880 | return directionalProperty.apply(void 0, ['borderStyle'].concat(values));
|
3881 | }
|
3882 |
|
3883 | |
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
|
3901 |
|
3902 |
|
3903 |
|
3904 |
|
3905 | function borderWidth() {
|
3906 | for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
3907 | values[_key] = arguments[_key];
|
3908 | }
|
3909 |
|
3910 | return directionalProperty.apply(void 0, ['borderWidth'].concat(values));
|
3911 | }
|
3912 |
|
3913 | function generateSelectors(template, state) {
|
3914 | var stateSuffix = state ? ":" + state : '';
|
3915 | return template(stateSuffix);
|
3916 | }
|
3917 | |
3918 |
|
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 | function statefulSelectors(states, template, stateMap) {
|
3924 | if (!template) throw new PolishedError(67);
|
3925 | if (states.length === 0) return generateSelectors(template, null);
|
3926 | var selectors = [];
|
3927 |
|
3928 | for (var i = 0; i < states.length; i += 1) {
|
3929 | if (stateMap && stateMap.indexOf(states[i]) < 0) {
|
3930 | throw new PolishedError(68);
|
3931 | }
|
3932 |
|
3933 | selectors.push(generateSelectors(template, states[i]));
|
3934 | }
|
3935 |
|
3936 | selectors = selectors.join(',');
|
3937 | return selectors;
|
3938 | }
|
3939 |
|
3940 | var stateMap = [undefined, null, 'active', 'focus', 'hover'];
|
3941 |
|
3942 | function template(state) {
|
3943 | return "button" + state + ",\n input[type=\"button\"]" + state + ",\n input[type=\"reset\"]" + state + ",\n input[type=\"submit\"]" + state;
|
3944 | }
|
3945 | |
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 |
|
3951 |
|
3952 |
|
3953 |
|
3954 |
|
3955 |
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 |
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 | function buttons() {
|
3974 | for (var _len = arguments.length, states = new Array(_len), _key = 0; _key < _len; _key++) {
|
3975 | states[_key] = arguments[_key];
|
3976 | }
|
3977 |
|
3978 | return statefulSelectors(states, template, stateMap);
|
3979 | }
|
3980 |
|
3981 | |
3982 |
|
3983 |
|
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 |
|
4003 | function margin() {
|
4004 | for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
4005 | values[_key] = arguments[_key];
|
4006 | }
|
4007 |
|
4008 | return directionalProperty.apply(void 0, ['margin'].concat(values));
|
4009 | }
|
4010 |
|
4011 | |
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 |
|
4024 |
|
4025 |
|
4026 |
|
4027 |
|
4028 |
|
4029 |
|
4030 |
|
4031 |
|
4032 |
|
4033 | function padding() {
|
4034 | for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
4035 | values[_key] = arguments[_key];
|
4036 | }
|
4037 |
|
4038 | return directionalProperty.apply(void 0, ['padding'].concat(values));
|
4039 | }
|
4040 |
|
4041 | var positionMap$1 = ['absolute', 'fixed', 'relative', 'static', 'sticky'];
|
4042 | |
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 |
|
4050 |
|
4051 |
|
4052 |
|
4053 |
|
4054 |
|
4055 |
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 |
|
4067 |
|
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 |
|
4075 |
|
4076 |
|
4077 |
|
4078 |
|
4079 |
|
4080 |
|
4081 |
|
4082 |
|
4083 |
|
4084 |
|
4085 | function position(firstValue) {
|
4086 | for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
4087 | values[_key - 1] = arguments[_key];
|
4088 | }
|
4089 |
|
4090 | if (positionMap$1.indexOf(firstValue) >= 0 && firstValue) {
|
4091 | return _extends__default['default']({}, directionalProperty.apply(void 0, [''].concat(values)), {
|
4092 | position: firstValue
|
4093 | });
|
4094 | } else {
|
4095 | return directionalProperty.apply(void 0, ['', firstValue].concat(values));
|
4096 | }
|
4097 | }
|
4098 |
|
4099 | |
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 |
|
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 |
|
4112 |
|
4113 |
|
4114 |
|
4115 |
|
4116 |
|
4117 |
|
4118 |
|
4119 | function size(height, width) {
|
4120 | if (width === void 0) {
|
4121 | width = height;
|
4122 | }
|
4123 |
|
4124 | return {
|
4125 | height: height,
|
4126 | width: width
|
4127 | };
|
4128 | }
|
4129 |
|
4130 | var stateMap$1 = [undefined, null, 'active', 'focus', 'hover'];
|
4131 |
|
4132 | function template$1(state) {
|
4133 | return "input[type=\"color\"]" + state + ",\n input[type=\"date\"]" + state + ",\n input[type=\"datetime\"]" + state + ",\n input[type=\"datetime-local\"]" + state + ",\n input[type=\"email\"]" + state + ",\n input[type=\"month\"]" + state + ",\n input[type=\"number\"]" + state + ",\n input[type=\"password\"]" + state + ",\n input[type=\"search\"]" + state + ",\n input[type=\"tel\"]" + state + ",\n input[type=\"text\"]" + state + ",\n input[type=\"time\"]" + state + ",\n input[type=\"url\"]" + state + ",\n input[type=\"week\"]" + state + ",\n input:not([type])" + state + ",\n textarea" + state;
|
4134 | }
|
4135 | |
4136 |
|
4137 |
|
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 |
|
4143 |
|
4144 |
|
4145 |
|
4146 |
|
4147 |
|
4148 |
|
4149 |
|
4150 |
|
4151 |
|
4152 |
|
4153 |
|
4154 |
|
4155 |
|
4156 |
|
4157 |
|
4158 |
|
4159 |
|
4160 |
|
4161 |
|
4162 |
|
4163 |
|
4164 |
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 | function textInputs() {
|
4176 | for (var _len = arguments.length, states = new Array(_len), _key = 0; _key < _len; _key++) {
|
4177 | states[_key] = arguments[_key];
|
4178 | }
|
4179 |
|
4180 | return statefulSelectors(states, template$1, stateMap$1);
|
4181 | }
|
4182 |
|
4183 | |
4184 |
|
4185 |
|
4186 |
|
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 |
|
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 | function transitions() {
|
4207 | for (var _len = arguments.length, properties = new Array(_len), _key = 0; _key < _len; _key++) {
|
4208 | properties[_key] = arguments[_key];
|
4209 | }
|
4210 |
|
4211 | if (Array.isArray(properties[0]) && properties.length === 2) {
|
4212 | var value = properties[1];
|
4213 |
|
4214 | if (typeof value !== 'string') {
|
4215 | throw new PolishedError(61);
|
4216 | }
|
4217 |
|
4218 | var transitionsString = properties[0].map(function (property) {
|
4219 | return property + " " + value;
|
4220 | }).join(', ');
|
4221 | return {
|
4222 | transition: transitionsString
|
4223 | };
|
4224 | } else {
|
4225 | return {
|
4226 | transition: properties.join(', ')
|
4227 | };
|
4228 | }
|
4229 | }
|
4230 |
|
4231 | exports.adjustHue = curriedAdjustHue;
|
4232 | exports.animation = animation;
|
4233 | exports.backgroundImages = backgroundImages;
|
4234 | exports.backgrounds = backgrounds;
|
4235 | exports.between = between;
|
4236 | exports.border = border;
|
4237 | exports.borderColor = borderColor;
|
4238 | exports.borderRadius = borderRadius;
|
4239 | exports.borderStyle = borderStyle;
|
4240 | exports.borderWidth = borderWidth;
|
4241 | exports.buttons = buttons;
|
4242 | exports.clearFix = clearFix;
|
4243 | exports.complement = complement;
|
4244 | exports.cover = cover;
|
4245 | exports.cssVar = cssVar;
|
4246 | exports.darken = curriedDarken;
|
4247 | exports.desaturate = curriedDesaturate;
|
4248 | exports.directionalProperty = directionalProperty;
|
4249 | exports.easeIn = easeIn;
|
4250 | exports.easeInOut = easeInOut;
|
4251 | exports.easeOut = easeOut;
|
4252 | exports.ellipsis = ellipsis;
|
4253 | exports.em = em;
|
4254 | exports.fluidRange = fluidRange;
|
4255 | exports.fontFace = fontFace;
|
4256 | exports.getContrast = getContrast;
|
4257 | exports.getLuminance = getLuminance;
|
4258 | exports.getValueAndUnit = getValueAndUnit;
|
4259 | exports.grayscale = grayscale;
|
4260 | exports.hiDPI = hiDPI;
|
4261 | exports.hideText = hideText;
|
4262 | exports.hideVisually = hideVisually;
|
4263 | exports.hsl = hsl;
|
4264 | exports.hslToColorString = hslToColorString;
|
4265 | exports.hsla = hsla;
|
4266 | exports.important = important;
|
4267 | exports.invert = invert;
|
4268 | exports.lighten = curriedLighten;
|
4269 | exports.linearGradient = linearGradient;
|
4270 | exports.margin = margin;
|
4271 | exports.math = math;
|
4272 | exports.meetsContrastGuidelines = meetsContrastGuidelines;
|
4273 | exports.mix = curriedMix;
|
4274 | exports.modularScale = modularScale;
|
4275 | exports.normalize = normalize;
|
4276 | exports.opacify = curriedOpacify;
|
4277 | exports.padding = padding;
|
4278 | exports.parseToHsl = parseToHsl;
|
4279 | exports.parseToRgb = parseToRgb;
|
4280 | exports.position = position;
|
4281 | exports.radialGradient = radialGradient;
|
4282 | exports.readableColor = readableColor;
|
4283 | exports.rem = rem;
|
4284 | exports.remToPx = remToPx;
|
4285 | exports.retinaImage = retinaImage;
|
4286 | exports.rgb = rgb;
|
4287 | exports.rgbToColorString = rgbToColorString;
|
4288 | exports.rgba = rgba;
|
4289 | exports.saturate = curriedSaturate;
|
4290 | exports.setHue = curriedSetHue;
|
4291 | exports.setLightness = curriedSetLightness;
|
4292 | exports.setSaturation = curriedSetSaturation;
|
4293 | exports.shade = curriedShade;
|
4294 | exports.size = size;
|
4295 | exports.stripUnit = stripUnit;
|
4296 | exports.textInputs = textInputs;
|
4297 | exports.timingFunctions = timingFunctions;
|
4298 | exports.tint = curriedTint;
|
4299 | exports.toColorString = toColorString;
|
4300 | exports.transitions = transitions;
|
4301 | exports.transparentize = curriedTransparentize;
|
4302 | exports.triangle = triangle;
|
4303 | exports.wordWrap = wordWrap;
|
4304 |
|
4305 | Object.defineProperty(exports, '__esModule', { value: true });
|
4306 |
|
4307 | })));
|