index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = parseMedia;
  6. var _Container = require('./nodes/Container');
  7. var _Container2 = _interopRequireDefault(_Container);
  8. var _parsers = require('./parsers');
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * Parses a media query list into an array of nodes. A typical node signature:
  12. * {string} node.type -- one of: 'media-query', 'media-type', 'keyword',
  13. * 'media-feature-expression', 'media-feature', 'colon', 'value'
  14. * {string} node.value -- the contents of a particular element, trimmed
  15. * e.g.: `screen`, `max-width`, `1024px`
  16. * {string} node.after -- whitespaces that follow the element
  17. * {string} node.before -- whitespaces that precede the element
  18. * {string} node.sourceIndex -- the index of the element in a source media
  19. * query list, 0-based
  20. * {object} node.parent -- a link to the parent node (a container)
  21. *
  22. * Some nodes (media queries, media feature expressions) contain other nodes.
  23. * They additionally have:
  24. * {array} node.nodes -- an array of nodes of the type described here
  25. * {funciton} node.each -- traverses direct children of the node, calling
  26. * a callback for each one
  27. * {funciton} node.walk -- traverses ALL descendants of the node, calling
  28. * a callback for each one
  29. */
  30. function parseMedia(value) {
  31. return new _Container2.default({
  32. nodes: (0, _parsers.parseMediaList)(value),
  33. type: 'media-query-list',
  34. value: value.trim()
  35. });
  36. }