Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

eachDeclarationBlock.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. const { isRoot, isAtRule, isRule } = require('./typeGuards');
  3. /** @typedef {import('postcss').Root} Root */
  4. /** @typedef {import('postcss').Root} Document */
  5. /** @typedef {import('postcss').Node} PostcssNode */
  6. /** @typedef {import('postcss').ContainerBase} PostcssContainerNode */
  7. /**
  8. * @param {PostcssNode} node
  9. * @returns {node is PostcssContainerNode}
  10. */
  11. function isContainerNode(node) {
  12. return isRule(node) || isAtRule(node) || isRoot(node);
  13. }
  14. /**
  15. * In order to accommodate nested blocks (postcss-nested),
  16. * we need to run a shallow loop (instead of eachDecl() or eachRule(),
  17. * which loop recursively) and allow each nested block to accumulate
  18. * its own list of properties -- so that a property in a nested rule
  19. * does not conflict with the same property in the parent rule
  20. * executes a provided function once for each declaration block.
  21. *
  22. * @param {Root | Document} root - root element of file.
  23. * @param {function} cb - Function to execute for each declaration block
  24. *
  25. * @returns {void}
  26. */
  27. module.exports = function (root, cb) {
  28. /**
  29. * @param {PostcssNode} statement
  30. *
  31. * @returns {void}
  32. */
  33. function each(statement) {
  34. if (!isContainerNode(statement)) return;
  35. if (statement.nodes && statement.nodes.length) {
  36. /** @type {PostcssNode[]} */
  37. const decls = [];
  38. statement.nodes.forEach((node) => {
  39. if (node.type === 'decl') {
  40. decls.push(node);
  41. }
  42. each(node);
  43. });
  44. if (decls.length) {
  45. cb(decls.forEach.bind(decls));
  46. }
  47. }
  48. }
  49. each(root);
  50. };