1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.prevElementSibling = exports.nextElementSibling = exports.getName = exports.hasAttrib = exports.getAttributeValue = exports.getSiblings = exports.getParent = exports.getChildren = void 0;
|
4 | var domhandler_1 = require("domhandler");
|
5 | var emptyArray = [];
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function getChildren(elem) {
|
13 | var _a;
|
14 | return (_a = elem.children) !== null && _a !== void 0 ? _a : emptyArray;
|
15 | }
|
16 | exports.getChildren = getChildren;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function getParent(elem) {
|
24 | return elem.parent || null;
|
25 | }
|
26 | exports.getParent = getParent;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function getSiblings(elem) {
|
38 | var _a, _b;
|
39 | var parent = getParent(elem);
|
40 | if (parent != null)
|
41 | return getChildren(parent);
|
42 | var siblings = [elem];
|
43 | var prev = elem.prev, next = elem.next;
|
44 | while (prev != null) {
|
45 | siblings.unshift(prev);
|
46 | (_a = prev, prev = _a.prev);
|
47 | }
|
48 | while (next != null) {
|
49 | siblings.push(next);
|
50 | (_b = next, next = _b.next);
|
51 | }
|
52 | return siblings;
|
53 | }
|
54 | exports.getSiblings = getSiblings;
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function getAttributeValue(elem, name) {
|
63 | var _a;
|
64 | return (_a = elem.attribs) === null || _a === void 0 ? void 0 : _a[name];
|
65 | }
|
66 | exports.getAttributeValue = getAttributeValue;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | function hasAttrib(elem, name) {
|
75 | return (elem.attribs != null &&
|
76 | Object.prototype.hasOwnProperty.call(elem.attribs, name) &&
|
77 | elem.attribs[name] != null);
|
78 | }
|
79 | exports.hasAttrib = hasAttrib;
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | function getName(elem) {
|
87 | return elem.name;
|
88 | }
|
89 | exports.getName = getName;
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function nextElementSibling(elem) {
|
97 | var _a;
|
98 | var next = elem.next;
|
99 | while (next !== null && !(0, domhandler_1.isTag)(next))
|
100 | (_a = next, next = _a.next);
|
101 | return next;
|
102 | }
|
103 | exports.nextElementSibling = nextElementSibling;
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | function prevElementSibling(elem) {
|
111 | var _a;
|
112 | var prev = elem.prev;
|
113 | while (prev !== null && !(0, domhandler_1.isTag)(prev))
|
114 | (_a = prev, prev = _a.prev);
|
115 | return prev;
|
116 | }
|
117 | exports.prevElementSibling = prevElementSibling;
|