api.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. /*
  3. MIT License http://www.opensource.org/licenses/mit-license.php
  4. Author Tobias Koppers @sokra
  5. */
  6. // css base code, injected by the css-loader
  7. // eslint-disable-next-line func-names
  8. module.exports = function (useSourceMap) {
  9. var list = []; // return the list of modules as css string
  10. list.toString = function toString() {
  11. return this.map(function (item) {
  12. var content = cssWithMappingToString(item, useSourceMap);
  13. if (item[2]) {
  14. return "@media ".concat(item[2], " {").concat(content, "}");
  15. }
  16. return content;
  17. }).join('');
  18. }; // import a list of modules into the list
  19. // eslint-disable-next-line func-names
  20. list.i = function (modules, mediaQuery, dedupe) {
  21. if (typeof modules === 'string') {
  22. // eslint-disable-next-line no-param-reassign
  23. modules = [[null, modules, '']];
  24. }
  25. var alreadyImportedModules = {};
  26. if (dedupe) {
  27. for (var i = 0; i < this.length; i++) {
  28. // eslint-disable-next-line prefer-destructuring
  29. var id = this[i][0];
  30. if (id != null) {
  31. alreadyImportedModules[id] = true;
  32. }
  33. }
  34. }
  35. for (var _i = 0; _i < modules.length; _i++) {
  36. var item = [].concat(modules[_i]);
  37. if (dedupe && alreadyImportedModules[item[0]]) {
  38. // eslint-disable-next-line no-continue
  39. continue;
  40. }
  41. if (mediaQuery) {
  42. if (!item[2]) {
  43. item[2] = mediaQuery;
  44. } else {
  45. item[2] = "".concat(mediaQuery, " and ").concat(item[2]);
  46. }
  47. }
  48. list.push(item);
  49. }
  50. };
  51. return list;
  52. };
  53. function cssWithMappingToString(item, useSourceMap) {
  54. var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring
  55. var cssMapping = item[3];
  56. if (!cssMapping) {
  57. return content;
  58. }
  59. if (useSourceMap && typeof btoa === 'function') {
  60. var sourceMapping = toComment(cssMapping);
  61. var sourceURLs = cssMapping.sources.map(function (source) {
  62. return "/*# sourceURL=".concat(cssMapping.sourceRoot || '').concat(source, " */");
  63. });
  64. return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
  65. }
  66. return [content].join('\n');
  67. } // Adapted from convert-source-map (MIT)
  68. function toComment(sourceMap) {
  69. // eslint-disable-next-line no-undef
  70. var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
  71. var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
  72. return "/*# ".concat(data, " */");
  73. }