1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.isCustomElement = exports.isSlotElement = exports.isSelectElement = exports.isTextareaElement = exports.isScriptElement = exports.isStyleElement = exports.isIFrameElement = exports.isImageElement = exports.isVideoElement = exports.isCanvasElement = exports.isBodyElement = exports.isSVGElement = exports.isHTMLElement = exports.isInputElement = exports.isOLElement = exports.isLIElement = exports.isSVGElementNode = exports.isHTMLElementNode = exports.isElementNode = exports.isTextNode = exports.parseTree = void 0;
|
---|
4 | var element_container_1 = require("./element-container");
|
---|
5 | var text_container_1 = require("./text-container");
|
---|
6 | var image_element_container_1 = require("./replaced-elements/image-element-container");
|
---|
7 | var canvas_element_container_1 = require("./replaced-elements/canvas-element-container");
|
---|
8 | var svg_element_container_1 = require("./replaced-elements/svg-element-container");
|
---|
9 | var li_element_container_1 = require("./elements/li-element-container");
|
---|
10 | var ol_element_container_1 = require("./elements/ol-element-container");
|
---|
11 | var input_element_container_1 = require("./replaced-elements/input-element-container");
|
---|
12 | var select_element_container_1 = require("./elements/select-element-container");
|
---|
13 | var textarea_element_container_1 = require("./elements/textarea-element-container");
|
---|
14 | var iframe_element_container_1 = require("./replaced-elements/iframe-element-container");
|
---|
15 | var LIST_OWNERS = ['OL', 'UL', 'MENU'];
|
---|
16 | var parseNodeTree = function (context, node, parent, root) {
|
---|
17 | for (var childNode = node.firstChild, nextNode = void 0; childNode; childNode = nextNode) {
|
---|
18 | nextNode = childNode.nextSibling;
|
---|
19 | if (exports.isTextNode(childNode) && childNode.data.trim().length > 0) {
|
---|
20 | parent.textNodes.push(new text_container_1.TextContainer(context, childNode, parent.styles));
|
---|
21 | }
|
---|
22 | else if (exports.isElementNode(childNode)) {
|
---|
23 | if (exports.isSlotElement(childNode) && childNode.assignedNodes) {
|
---|
24 | childNode.assignedNodes().forEach(function (childNode) { return parseNodeTree(context, childNode, parent, root); });
|
---|
25 | }
|
---|
26 | else {
|
---|
27 | var container = createContainer(context, childNode);
|
---|
28 | if (container.styles.isVisible()) {
|
---|
29 | if (createsRealStackingContext(childNode, container, root)) {
|
---|
30 | container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */;
|
---|
31 | }
|
---|
32 | else if (createsStackingContext(container.styles)) {
|
---|
33 | container.flags |= 2 /* CREATES_STACKING_CONTEXT */;
|
---|
34 | }
|
---|
35 | if (LIST_OWNERS.indexOf(childNode.tagName) !== -1) {
|
---|
36 | container.flags |= 8 /* IS_LIST_OWNER */;
|
---|
37 | }
|
---|
38 | parent.elements.push(container);
|
---|
39 | childNode.slot;
|
---|
40 | if (childNode.shadowRoot) {
|
---|
41 | parseNodeTree(context, childNode.shadowRoot, container, root);
|
---|
42 | }
|
---|
43 | else if (!exports.isTextareaElement(childNode) &&
|
---|
44 | !exports.isSVGElement(childNode) &&
|
---|
45 | !exports.isSelectElement(childNode)) {
|
---|
46 | parseNodeTree(context, childNode, container, root);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 | };
|
---|
53 | var createContainer = function (context, element) {
|
---|
54 | if (exports.isImageElement(element)) {
|
---|
55 | return new image_element_container_1.ImageElementContainer(context, element);
|
---|
56 | }
|
---|
57 | if (exports.isCanvasElement(element)) {
|
---|
58 | return new canvas_element_container_1.CanvasElementContainer(context, element);
|
---|
59 | }
|
---|
60 | if (exports.isSVGElement(element)) {
|
---|
61 | return new svg_element_container_1.SVGElementContainer(context, element);
|
---|
62 | }
|
---|
63 | if (exports.isLIElement(element)) {
|
---|
64 | return new li_element_container_1.LIElementContainer(context, element);
|
---|
65 | }
|
---|
66 | if (exports.isOLElement(element)) {
|
---|
67 | return new ol_element_container_1.OLElementContainer(context, element);
|
---|
68 | }
|
---|
69 | if (exports.isInputElement(element)) {
|
---|
70 | return new input_element_container_1.InputElementContainer(context, element);
|
---|
71 | }
|
---|
72 | if (exports.isSelectElement(element)) {
|
---|
73 | return new select_element_container_1.SelectElementContainer(context, element);
|
---|
74 | }
|
---|
75 | if (exports.isTextareaElement(element)) {
|
---|
76 | return new textarea_element_container_1.TextareaElementContainer(context, element);
|
---|
77 | }
|
---|
78 | if (exports.isIFrameElement(element)) {
|
---|
79 | return new iframe_element_container_1.IFrameElementContainer(context, element);
|
---|
80 | }
|
---|
81 | return new element_container_1.ElementContainer(context, element);
|
---|
82 | };
|
---|
83 | var parseTree = function (context, element) {
|
---|
84 | var container = createContainer(context, element);
|
---|
85 | container.flags |= 4 /* CREATES_REAL_STACKING_CONTEXT */;
|
---|
86 | parseNodeTree(context, element, container, container);
|
---|
87 | return container;
|
---|
88 | };
|
---|
89 | exports.parseTree = parseTree;
|
---|
90 | var createsRealStackingContext = function (node, container, root) {
|
---|
91 | return (container.styles.isPositionedWithZIndex() ||
|
---|
92 | container.styles.opacity < 1 ||
|
---|
93 | container.styles.isTransformed() ||
|
---|
94 | (exports.isBodyElement(node) && root.styles.isTransparent()));
|
---|
95 | };
|
---|
96 | var createsStackingContext = function (styles) { return styles.isPositioned() || styles.isFloating(); };
|
---|
97 | var isTextNode = function (node) { return node.nodeType === Node.TEXT_NODE; };
|
---|
98 | exports.isTextNode = isTextNode;
|
---|
99 | var isElementNode = function (node) { return node.nodeType === Node.ELEMENT_NODE; };
|
---|
100 | exports.isElementNode = isElementNode;
|
---|
101 | var isHTMLElementNode = function (node) {
|
---|
102 | return exports.isElementNode(node) && typeof node.style !== 'undefined' && !exports.isSVGElementNode(node);
|
---|
103 | };
|
---|
104 | exports.isHTMLElementNode = isHTMLElementNode;
|
---|
105 | var isSVGElementNode = function (element) {
|
---|
106 | return typeof element.className === 'object';
|
---|
107 | };
|
---|
108 | exports.isSVGElementNode = isSVGElementNode;
|
---|
109 | var isLIElement = function (node) { return node.tagName === 'LI'; };
|
---|
110 | exports.isLIElement = isLIElement;
|
---|
111 | var isOLElement = function (node) { return node.tagName === 'OL'; };
|
---|
112 | exports.isOLElement = isOLElement;
|
---|
113 | var isInputElement = function (node) { return node.tagName === 'INPUT'; };
|
---|
114 | exports.isInputElement = isInputElement;
|
---|
115 | var isHTMLElement = function (node) { return node.tagName === 'HTML'; };
|
---|
116 | exports.isHTMLElement = isHTMLElement;
|
---|
117 | var isSVGElement = function (node) { return node.tagName === 'svg'; };
|
---|
118 | exports.isSVGElement = isSVGElement;
|
---|
119 | var isBodyElement = function (node) { return node.tagName === 'BODY'; };
|
---|
120 | exports.isBodyElement = isBodyElement;
|
---|
121 | var isCanvasElement = function (node) { return node.tagName === 'CANVAS'; };
|
---|
122 | exports.isCanvasElement = isCanvasElement;
|
---|
123 | var isVideoElement = function (node) { return node.tagName === 'VIDEO'; };
|
---|
124 | exports.isVideoElement = isVideoElement;
|
---|
125 | var isImageElement = function (node) { return node.tagName === 'IMG'; };
|
---|
126 | exports.isImageElement = isImageElement;
|
---|
127 | var isIFrameElement = function (node) { return node.tagName === 'IFRAME'; };
|
---|
128 | exports.isIFrameElement = isIFrameElement;
|
---|
129 | var isStyleElement = function (node) { return node.tagName === 'STYLE'; };
|
---|
130 | exports.isStyleElement = isStyleElement;
|
---|
131 | var isScriptElement = function (node) { return node.tagName === 'SCRIPT'; };
|
---|
132 | exports.isScriptElement = isScriptElement;
|
---|
133 | var isTextareaElement = function (node) { return node.tagName === 'TEXTAREA'; };
|
---|
134 | exports.isTextareaElement = isTextareaElement;
|
---|
135 | var isSelectElement = function (node) { return node.tagName === 'SELECT'; };
|
---|
136 | exports.isSelectElement = isSelectElement;
|
---|
137 | var isSlotElement = function (node) { return node.tagName === 'SLOT'; };
|
---|
138 | exports.isSlotElement = isSlotElement;
|
---|
139 | // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
---|
140 | var isCustomElement = function (node) { return node.tagName.indexOf('-') > 0; };
|
---|
141 | exports.isCustomElement = isCustomElement;
|
---|
142 | //# sourceMappingURL=node-parser.js.map |
---|