UNPKG

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