document.js 724 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. const { Document: PostCssDocument } = require("postcss");
  3. class Document extends PostCssDocument {
  4. toString(stringifier) {
  5. return super.toString(
  6. stringifier || {
  7. stringify: require("../stringify"),
  8. }
  9. );
  10. }
  11. each(callback) {
  12. const result = this.nodes.map((node) => node.each(callback));
  13. return result.every((result) => result !== false) && result.pop();
  14. }
  15. append(...args) {
  16. this.last.append.apply(this.last, args);
  17. return this;
  18. }
  19. prepend(...args) {
  20. this.first.prepend.apply(this.first, args);
  21. return this;
  22. }
  23. insertBefore(exist, add) {
  24. exist.prepend(add);
  25. return this;
  26. }
  27. insertAfter(exist, add) {
  28. exist.append(add);
  29. return this;
  30. }
  31. }
  32. module.exports = Document;