You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.1 KiB

2 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "nesting", {
  6. enumerable: true,
  7. get: ()=>nesting
  8. });
  9. const _postcss = /*#__PURE__*/ _interopRequireDefault(require("postcss"));
  10. const _postcssNested = /*#__PURE__*/ _interopRequireDefault(require("postcss-nested"));
  11. function _interopRequireDefault(obj) {
  12. return obj && obj.__esModule ? obj : {
  13. default: obj
  14. };
  15. }
  16. function nesting(opts = _postcssNested.default) {
  17. return (root, result)=>{
  18. root.walkAtRules("screen", (rule)=>{
  19. rule.name = "media";
  20. rule.params = `screen(${rule.params})`;
  21. });
  22. root.walkAtRules("apply", (rule)=>{
  23. rule.before(_postcss.default.decl({
  24. prop: "__apply",
  25. value: rule.params,
  26. source: rule.source
  27. }));
  28. rule.remove();
  29. });
  30. let plugin = (()=>{
  31. var ref;
  32. if (typeof opts === "function" || typeof opts === "object" && (opts === null || opts === void 0 ? void 0 : (ref = opts.hasOwnProperty) === null || ref === void 0 ? void 0 : ref.call(opts, "postcssPlugin"))) {
  33. return opts;
  34. }
  35. if (typeof opts === "string") {
  36. return require(opts);
  37. }
  38. if (Object.keys(opts).length <= 0) {
  39. return _postcssNested.default;
  40. }
  41. throw new Error("tailwindcss/nesting should be loaded with a nesting plugin.");
  42. })();
  43. (0, _postcss.default)([
  44. plugin
  45. ]).process(root, result.opts).sync();
  46. root.walkDecls("__apply", (decl)=>{
  47. decl.before(_postcss.default.atRule({
  48. name: "apply",
  49. params: decl.value,
  50. source: decl.source
  51. }));
  52. decl.remove();
  53. });
  54. /**
  55. * Use a private PostCSS API to remove the "clean" flag from the entire AST.
  56. * This is done because running process() on the AST will set the "clean"
  57. * flag on all nodes, which we don't want.
  58. *
  59. * This causes downstream plugins using the visitor API to be skipped.
  60. *
  61. * This is guarded because the PostCSS API is not public
  62. * and may change in future versions of PostCSS.
  63. *
  64. * See https://github.com/postcss/postcss/issues/1712 for more details
  65. *
  66. * @param {import('postcss').Node} node
  67. */ function markDirty(node) {
  68. if (!("markDirty" in node)) {
  69. return;
  70. }
  71. // Traverse the tree down to the leaf nodes
  72. if (node.nodes) {
  73. node.nodes.forEach((n)=>markDirty(n));
  74. }
  75. // If it's a leaf node mark it as dirty
  76. // We do this here because marking a node as dirty
  77. // will walk up the tree and mark all parents as dirty
  78. // resulting in a lot of unnecessary work if we did this
  79. // for every single node
  80. if (!node.nodes) {
  81. node.markDirty();
  82. }
  83. }
  84. markDirty(root);
  85. return root;
  86. };
  87. }