UNPKG

11.6 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
6function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
7function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
8function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
9function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
10function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
11function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
13// based on https://github.com/styled-components/styled-components/blob/fcf6f3804c57a14dd7984dfab7bc06ee2edca044/src/utils/error.js
14/**
15 * Parse errors.md and turn it into a simple hash of code: message
16 * @private
17 */
18var ERRORS = {
19 "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",
20 "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",
21 "3": "Passed an incorrect argument to a color function, please pass a string representation of a color.\n\n",
22 "4": "Couldn't generate valid rgb string from %s, it returned %s.\n\n",
23 "5": "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.\n\n",
24 "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",
25 "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",
26 "8": "Passed invalid argument to toColorString, please pass a RgbColor, RgbaColor, HslColor or HslaColor object.\n\n",
27 "9": "Please provide a number of steps to the modularScale helper.\n\n",
28 "10": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
29 "11": "Invalid value passed as base to modularScale, expected number or em string but got \"%s\"\n\n",
30 "12": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got \"%s\" instead.\n\n",
31 "13": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got \"%s\" instead.\n\n",
32 "14": "Passed invalid pixel value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
33 "15": "Passed invalid base value (\"%s\") to %s(), please pass a value like \"12px\" or 12.\n\n",
34 "16": "You must provide a template to this method.\n\n",
35 "17": "You passed an unsupported selector state to this method.\n\n",
36 "18": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
37 "19": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
38 "20": "expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
39 "21": "expects the objects in the first argument array to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
40 "22": "expects the first argument object to have the properties `prop`, `fromSize`, and `toSize`.\n\n",
41 "23": "fontFace expects a name of a font-family.\n\n",
42 "24": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
43 "25": "fontFace expects localFonts to be an array.\n\n",
44 "26": "fontFace expects fileFormats to be an array.\n\n",
45 "27": "radialGradient requries at least 2 color-stops to properly render.\n\n",
46 "28": "Please supply a filename to retinaImage() as the first argument.\n\n",
47 "29": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
48 "30": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
49 "31": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation\n\n",
50 "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",
51 "33": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation\n\n",
52 "34": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
53 "35": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
54 "36": "Property must be a string value.\n\n",
55 "37": "Syntax Error at %s.\n\n",
56 "38": "Formula contains a function that needs parentheses at %s.\n\n",
57 "39": "Formula is missing closing parenthesis at %s.\n\n",
58 "40": "Formula has too many closing parentheses at %s.\n\n",
59 "41": "All values in a formula must have the same unit or be unitless.\n\n",
60 "42": "Please provide a number of steps to the modularScale helper.\n\n",
61 "43": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",
62 "44": "Invalid value passed as base to modularScale, expected number or em/rem string but got %s.\n\n",
63 "45": "Passed invalid argument to hslToColorString, please pass a HslColor or HslaColor object.\n\n",
64 "46": "Passed invalid argument to rgbToColorString, please pass a RgbColor or RgbaColor object.\n\n",
65 "47": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",
66 "48": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n",
67 "49": "Expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",
68 "50": "Expects the objects in the first argument array to have the properties prop, fromSize, and toSize.\n\n",
69 "51": "Expects the first argument object to have the properties prop, fromSize, and toSize.\n\n",
70 "52": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",
71 "53": "fontFace expects localFonts to be an array.\n\n",
72 "54": "fontFace expects fileFormats to be an array.\n\n",
73 "55": "fontFace expects a name of a font-family.\n\n",
74 "56": "linearGradient requries at least 2 color-stops to properly render.\n\n",
75 "57": "radialGradient requries at least 2 color-stops to properly render.\n\n",
76 "58": "Please supply a filename to retinaImage() as the first argument.\n\n",
77 "59": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",
78 "60": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",
79 "61": "Property must be a string value.\n\n",
80 "62": "borderRadius expects a radius value as a string or number as the second argument.\n\n",
81 "63": "borderRadius expects one of \"top\", \"bottom\", \"left\" or \"right\" as the first argument.\n\n",
82 "64": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation.\n\n",
83 "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",
84 "66": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation.\n\n",
85 "67": "You must provide a template to this method.\n\n",
86 "68": "You passed an unsupported selector state to this method.\n\n",
87 "69": "Expected a string ending in \"px\" or a number passed as the first argument to %s(), got %s instead.\n\n",
88 "70": "Expected a string ending in \"px\" or a number passed as the second argument to %s(), got %s instead.\n\n",
89 "71": "Passed invalid pixel value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
90 "72": "Passed invalid base value %s to %s(), please pass a value like \"12px\" or 12.\n\n",
91 "73": "Please provide a valid CSS variable.\n\n",
92 "74": "CSS variable not found and no default was provided.\n\n",
93 "75": "important requires a valid style object, got a %s instead.\n\n",
94 "76": "fromSize and toSize must be provided as stringified numbers with the same units as minScreen and maxScreen.\n\n",
95 "77": "remToPx expects a value in \"rem\" but you provided it in \"%s\".\n\n",
96 "78": "base must be set in \"px\" or \"%\" but you set it in \"%s\".\n"
97};
98
99/**
100 * super basic version of sprintf
101 * @private
102 */
103function format() {
104 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
105 args[_key] = arguments[_key];
106 }
107 var a = args[0];
108 var b = [];
109 var c;
110 for (c = 1; c < args.length; c += 1) {
111 b.push(args[c]);
112 }
113 b.forEach(function (d) {
114 a = a.replace(/%[a-z]/, d);
115 });
116 return a;
117}
118
119/**
120 * Create an error file out of errors.md for development and a simple web link to the full errors
121 * in production mode.
122 * @private
123 */
124var PolishedError = exports["default"] = /*#__PURE__*/function (_Error) {
125 _inheritsLoose(PolishedError, _Error);
126 function PolishedError(code) {
127 var _this;
128 if (process.env.NODE_ENV === 'production') {
129 _this = _Error.call(this, "An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#" + code + " for more information.") || this;
130 } else {
131 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
132 args[_key2 - 1] = arguments[_key2];
133 }
134 _this = _Error.call(this, format.apply(void 0, [ERRORS[code]].concat(args))) || this;
135 }
136 return _assertThisInitialized(_this);
137 }
138 return PolishedError;
139}( /*#__PURE__*/_wrapNativeSuper(Error));
140module.exports = exports.default;
\No newline at end of file