api.js 2.3 KB

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