node-parser.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var element_container_1 = require("./element-container");
  4. var text_container_1 = require("./text-container");
  5. var image_element_container_1 = require("./replaced-elements/image-element-container");
  6. var canvas_element_container_1 = require("./replaced-elements/canvas-element-container");
  7. var svg_element_container_1 = require("./replaced-elements/svg-element-container");
  8. var li_element_container_1 = require("./elements/li-element-container");
  9. var ol_element_container_1 = require("./elements/ol-element-container");
  10. var input_element_container_1 = require("./replaced-elements/input-element-container");
  11. var select_element_container_1 = require("./elements/select-element-container");
  12. var textarea_element_container_1 = require("./elements/textarea-element-container");
  13. var iframe_element_container_1 = require("./replaced-elements/iframe-element-container");
  14. var LIST_OWNERS = ['OL', 'UL', 'MENU'];
  15. var parseNodeTree = function (node, parent, root) {
  16. for (var childNode = node.firstChild, nextNode = void 0; childNode; childNode = nextNode) {
  17. nextNode = childNode.nextSibling;
  18. if (exports.isTextNode(childNode) && childNode.data.trim().length > 0) {
  19. parent.textNodes.push(new text_container_1.TextContainer(childNode, parent.styles));
  20. }
  21. else if (exports.isElementNode(childNode)) {
  22. var container = createContainer(childNode);
  23. if (container.styles.isVisible()) {
  24. if (createsRealStackingContext(childNode, container, root)) {
  25. container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */;
  26. }
  27. else if (createsStackingContext(container.styles)) {
  28. container.flags |= 2 /* CREATES_STACKING_CONTEXT */;
  29. }
  30. if (LIST_OWNERS.indexOf(childNode.tagName) !== -1) {
  31. container.flags |= 8 /* IS_LIST_OWNER */;
  32. }
  33. parent.elements.push(container);
  34. if (!exports.isTextareaElement(childNode) && !exports.isSVGElement(childNode) && !exports.isSelectElement(childNode)) {
  35. parseNodeTree(childNode, container, root);
  36. }
  37. }
  38. }
  39. }
  40. };
  41. var createContainer = function (element) {
  42. if (exports.isImageElement(element)) {
  43. return new image_element_container_1.ImageElementContainer(element);
  44. }
  45. if (exports.isCanvasElement(element)) {
  46. return new canvas_element_container_1.CanvasElementContainer(element);
  47. }
  48. if (exports.isSVGElement(element)) {
  49. return new svg_element_container_1.SVGElementContainer(element);
  50. }
  51. if (exports.isLIElement(element)) {
  52. return new li_element_container_1.LIElementContainer(element);
  53. }
  54. if (exports.isOLElement(element)) {
  55. return new ol_element_container_1.OLElementContainer(element);
  56. }
  57. if (exports.isInputElement(element)) {
  58. return new input_element_container_1.InputElementContainer(element);
  59. }
  60. if (exports.isSelectElement(element)) {
  61. return new select_element_container_1.SelectElementContainer(element);
  62. }
  63. if (exports.isTextareaElement(element)) {
  64. return new textarea_element_container_1.TextareaElementContainer(element);
  65. }
  66. if (exports.isIFrameElement(element)) {
  67. return new iframe_element_container_1.IFrameElementContainer(element);
  68. }
  69. return new element_container_1.ElementContainer(element);
  70. };
  71. exports.parseTree = function (element) {
  72. var container = createContainer(element);
  73. container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */;
  74. parseNodeTree(element, container, container);
  75. return container;
  76. };
  77. var createsRealStackingContext = function (node, container, root) {
  78. return (container.styles.isPositionedWithZIndex() ||
  79. container.styles.opacity < 1 ||
  80. container.styles.isTransformed() ||
  81. (exports.isBodyElement(node) && root.styles.isTransparent()));
  82. };
  83. var createsStackingContext = function (styles) { return styles.isPositioned() || styles.isFloating(); };
  84. exports.isTextNode = function (node) { return node.nodeType === Node.TEXT_NODE; };
  85. exports.isElementNode = function (node) { return node.nodeType === Node.ELEMENT_NODE; };
  86. exports.isHTMLElementNode = function (node) {
  87. return typeof node.style !== 'undefined';
  88. };
  89. exports.isLIElement = function (node) { return node.tagName === 'LI'; };
  90. exports.isOLElement = function (node) { return node.tagName === 'OL'; };
  91. exports.isInputElement = function (node) { return node.tagName === 'INPUT'; };
  92. exports.isHTMLElement = function (node) { return node.tagName === 'HTML'; };
  93. exports.isSVGElement = function (node) { return node.tagName === 'svg'; };
  94. exports.isBodyElement = function (node) { return node.tagName === 'BODY'; };
  95. exports.isCanvasElement = function (node) { return node.tagName === 'CANVAS'; };
  96. exports.isImageElement = function (node) { return node.tagName === 'IMG'; };
  97. exports.isIFrameElement = function (node) { return node.tagName === 'IFRAME'; };
  98. exports.isStyleElement = function (node) { return node.tagName === 'STYLE'; };
  99. exports.isScriptElement = function (node) { return node.tagName === 'SCRIPT'; };
  100. exports.isTextareaElement = function (node) { return node.tagName === 'TEXTAREA'; };
  101. exports.isSelectElement = function (node) { return node.tagName === 'SELECT'; };
  102. //# sourceMappingURL=node-parser.js.map