api.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use strict";
  2. /*
  3. MIT License http://www.opensource.org/licenses/mit-license.php
  4. Author Tobias Koppers @sokra
  5. */
  6. module.exports = function (cssWithMappingToString) {
  7. var list = [];
  8. // return the list of modules as css string
  9. list.toString = function toString() {
  10. return this.map(function (item) {
  11. var content = "";
  12. var needLayer = typeof item[5] !== "undefined";
  13. if (item[4]) {
  14. content += "@supports (".concat(item[4], ") {");
  15. }
  16. if (item[2]) {
  17. content += "@media ".concat(item[2], " {");
  18. }
  19. if (needLayer) {
  20. content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {");
  21. }
  22. content += cssWithMappingToString(item);
  23. if (needLayer) {
  24. content += "}";
  25. }
  26. if (item[2]) {
  27. content += "}";
  28. }
  29. if (item[4]) {
  30. content += "}";
  31. }
  32. return content;
  33. }).join("");
  34. };
  35. // import a list of modules into the list
  36. list.i = function i(modules, media, dedupe, supports, layer) {
  37. if (typeof modules === "string") {
  38. modules = [[null, modules, undefined]];
  39. }
  40. var alreadyImportedModules = {};
  41. if (dedupe) {
  42. for (var k = 0; k < this.length; k++) {
  43. var id = this[k][0];
  44. if (id != null) {
  45. alreadyImportedModules[id] = true;
  46. }
  47. }
  48. }
  49. for (var _k = 0; _k < modules.length; _k++) {
  50. var item = [].concat(modules[_k]);
  51. if (dedupe && alreadyImportedModules[item[0]]) {
  52. continue;
  53. }
  54. if (typeof layer !== "undefined") {
  55. if (typeof item[5] === "undefined") {
  56. item[5] = layer;
  57. } else {
  58. item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}");
  59. item[5] = layer;
  60. }
  61. }
  62. if (media) {
  63. if (!item[2]) {
  64. item[2] = media;
  65. } else {
  66. item[1] = "@media ".concat(item[2], " {").concat(item[1], "}");
  67. item[2] = media;
  68. }
  69. }
  70. if (supports) {
  71. if (!item[4]) {
  72. item[4] = "".concat(supports);
  73. } else {
  74. item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}");
  75. item[4] = supports;
  76. }
  77. }
  78. list.push(item);
  79. }
  80. };
  81. return list;
  82. };