_errors.js 11 KB

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