UNPKG

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