@remote-dom/polyfill 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/build/cjs/Attr.cjs +0 -54
- package/build/cjs/CharacterData.cjs +0 -29
- package/build/cjs/ChildNode.cjs +0 -45
- package/build/cjs/Comment.cjs +0 -11
- package/build/cjs/CustomElementRegistry.cjs +0 -35
- package/build/cjs/CustomEvent.cjs +0 -28
- package/build/cjs/Document.cjs +0 -94
- package/build/cjs/DocumentFragment.cjs +0 -12
- package/build/cjs/Element.cjs +0 -81
- package/build/cjs/Event.cjs +0 -113
- package/build/cjs/EventTarget.cjs +0 -101
- package/build/cjs/HTMLElement.cjs +0 -7
- package/build/cjs/HTMLTemplateElement.cjs +0 -26
- package/build/cjs/MutationObserver.cjs +0 -7
- package/build/cjs/NamedNodeMap.cjs +0 -115
- package/build/cjs/Node.cjs +0 -102
- package/build/cjs/NodeList.cjs +0 -9
- package/build/cjs/ParentNode.cjs +0 -130
- package/build/cjs/SVGElement.cjs +0 -19
- package/build/cjs/Text.cjs +0 -11
- package/build/cjs/Window.cjs +0 -69
- package/build/cjs/constants.cjs +0 -57
- package/build/cjs/hooks.cjs +0 -5
- package/build/cjs/index.cjs +0 -10
- package/build/cjs/selectors.cjs +0 -203
- package/build/cjs/serialization.cjs +0 -96
- package/build/cjs/shared.cjs +0 -63
package/build/cjs/Window.cjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Document = require('./Document.cjs');
|
|
4
|
-
var Event = require('./Event.cjs');
|
|
5
|
-
var EventTarget = require('./EventTarget.cjs');
|
|
6
|
-
var CustomEvent = require('./CustomEvent.cjs');
|
|
7
|
-
var Node = require('./Node.cjs');
|
|
8
|
-
var ParentNode = require('./ParentNode.cjs');
|
|
9
|
-
var ChildNode = require('./ChildNode.cjs');
|
|
10
|
-
var Element = require('./Element.cjs');
|
|
11
|
-
var HTMLElement = require('./HTMLElement.cjs');
|
|
12
|
-
var SVGElement = require('./SVGElement.cjs');
|
|
13
|
-
var CharacterData = require('./CharacterData.cjs');
|
|
14
|
-
var Text = require('./Text.cjs');
|
|
15
|
-
var Comment = require('./Comment.cjs');
|
|
16
|
-
var DocumentFragment = require('./DocumentFragment.cjs');
|
|
17
|
-
var HTMLTemplateElement = require('./HTMLTemplateElement.cjs');
|
|
18
|
-
var CustomElementRegistry = require('./CustomElementRegistry.cjs');
|
|
19
|
-
var MutationObserver = require('./MutationObserver.cjs');
|
|
20
|
-
|
|
21
|
-
class Window extends EventTarget.EventTarget {
|
|
22
|
-
name = '';
|
|
23
|
-
parent = this;
|
|
24
|
-
self = this;
|
|
25
|
-
top = this;
|
|
26
|
-
document = new Document.Document(this);
|
|
27
|
-
customElements = new CustomElementRegistry.CustomElementRegistryImplementation();
|
|
28
|
-
location = globalThis.location;
|
|
29
|
-
navigator = globalThis.navigator;
|
|
30
|
-
Event = Event.Event;
|
|
31
|
-
Node = Node.Node;
|
|
32
|
-
ParentNode = ParentNode.ParentNode;
|
|
33
|
-
ChildNode = ChildNode.ChildNode;
|
|
34
|
-
EventTarget = EventTarget.EventTarget;
|
|
35
|
-
CustomEvent = CustomEvent.CustomEvent;
|
|
36
|
-
DocumentFragment = DocumentFragment.DocumentFragment;
|
|
37
|
-
Document = Document.Document;
|
|
38
|
-
CharacterData = CharacterData.CharacterData;
|
|
39
|
-
Comment = Comment.Comment;
|
|
40
|
-
Text = Text.Text;
|
|
41
|
-
Element = Element.Element;
|
|
42
|
-
HTMLElement = HTMLElement.HTMLElement;
|
|
43
|
-
SVGElement = SVGElement.SVGElement;
|
|
44
|
-
HTMLTemplateElement = HTMLTemplateElement.HTMLTemplateElement;
|
|
45
|
-
MutationObserver = MutationObserver.MutationObserver;
|
|
46
|
-
}
|
|
47
|
-
function installWindowAsGlobal(window) {
|
|
48
|
-
const properties = Object.getOwnPropertyDescriptors(window);
|
|
49
|
-
delete properties.self;
|
|
50
|
-
Object.defineProperties(globalThis, {
|
|
51
|
-
...properties,
|
|
52
|
-
window: {
|
|
53
|
-
value: window
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
if (typeof self === 'undefined') {
|
|
57
|
-
Object.defineProperty(globalThis, 'self', {
|
|
58
|
-
value: window
|
|
59
|
-
});
|
|
60
|
-
} else {
|
|
61
|
-
// There can already be a `self`, like when polyfilling the DOM
|
|
62
|
-
// in a Web Worker. In those cases, just mirror all the `Window`
|
|
63
|
-
// properties onto `self`, rather than wholly redefining it.
|
|
64
|
-
Object.defineProperties(self, properties);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
exports.Window = Window;
|
|
69
|
-
exports.installWindowAsGlobal = installWindowAsGlobal;
|
package/build/cjs/constants.cjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const NAME = Symbol('name');
|
|
4
|
-
const VALUE = Symbol('value');
|
|
5
|
-
const NS = Symbol('ns');
|
|
6
|
-
const OWNER_ELEMENT = Symbol('owner');
|
|
7
|
-
const OWNER_DOCUMENT = Symbol('owner_document');
|
|
8
|
-
const ATTRIBUTES = Symbol('attributes');
|
|
9
|
-
const PREV = Symbol('prev');
|
|
10
|
-
const NEXT = Symbol('next');
|
|
11
|
-
const CHILD = Symbol('child');
|
|
12
|
-
const PARENT = Symbol('parent');
|
|
13
|
-
const DATA = Symbol('data');
|
|
14
|
-
const LISTENERS = Symbol('listeners');
|
|
15
|
-
const IS_TRUSTED = Symbol('isTrusted');
|
|
16
|
-
const CONTENT = Symbol('content');
|
|
17
|
-
const SLOT = Symbol('slot');
|
|
18
|
-
|
|
19
|
-
// @TODO remove explicit values
|
|
20
|
-
let NodeType = /*#__PURE__*/function (NodeType) {
|
|
21
|
-
NodeType[NodeType["NODE"] = 0] = "NODE";
|
|
22
|
-
NodeType[NodeType["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
|
|
23
|
-
NodeType[NodeType["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
|
|
24
|
-
NodeType[NodeType["TEXT_NODE"] = 3] = "TEXT_NODE";
|
|
25
|
-
NodeType[NodeType["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
|
|
26
|
-
NodeType[NodeType["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
|
|
27
|
-
NodeType[NodeType["ENTITY_NODE"] = 6] = "ENTITY_NODE";
|
|
28
|
-
NodeType[NodeType["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
|
|
29
|
-
NodeType[NodeType["COMMENT_NODE"] = 8] = "COMMENT_NODE";
|
|
30
|
-
NodeType[NodeType["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
|
|
31
|
-
NodeType[NodeType["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
|
|
32
|
-
NodeType[NodeType["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
|
|
33
|
-
return NodeType;
|
|
34
|
-
}({});
|
|
35
|
-
let NamespaceURI = /*#__PURE__*/function (NamespaceURI) {
|
|
36
|
-
NamespaceURI["XHTML"] = "http://www.w3.org/1999/xhtml";
|
|
37
|
-
NamespaceURI["SVG"] = "http://www.w3.org/2000/svg";
|
|
38
|
-
return NamespaceURI;
|
|
39
|
-
}({});
|
|
40
|
-
|
|
41
|
-
exports.ATTRIBUTES = ATTRIBUTES;
|
|
42
|
-
exports.CHILD = CHILD;
|
|
43
|
-
exports.CONTENT = CONTENT;
|
|
44
|
-
exports.DATA = DATA;
|
|
45
|
-
exports.IS_TRUSTED = IS_TRUSTED;
|
|
46
|
-
exports.LISTENERS = LISTENERS;
|
|
47
|
-
exports.NAME = NAME;
|
|
48
|
-
exports.NEXT = NEXT;
|
|
49
|
-
exports.NS = NS;
|
|
50
|
-
exports.NamespaceURI = NamespaceURI;
|
|
51
|
-
exports.NodeType = NodeType;
|
|
52
|
-
exports.OWNER_DOCUMENT = OWNER_DOCUMENT;
|
|
53
|
-
exports.OWNER_ELEMENT = OWNER_ELEMENT;
|
|
54
|
-
exports.PARENT = PARENT;
|
|
55
|
-
exports.PREV = PREV;
|
|
56
|
-
exports.SLOT = SLOT;
|
|
57
|
-
exports.VALUE = VALUE;
|
package/build/cjs/hooks.cjs
DELETED
package/build/cjs/index.cjs
DELETED
package/build/cjs/selectors.cjs
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var constants = require('./constants.cjs');
|
|
4
|
-
var shared = require('./shared.cjs');
|
|
5
|
-
|
|
6
|
-
var Combinator = /*#__PURE__*/function (Combinator) {
|
|
7
|
-
Combinator[Combinator["Descendant"] = 0] = "Descendant";
|
|
8
|
-
Combinator[Combinator["Child"] = 1] = "Child";
|
|
9
|
-
Combinator[Combinator["Sibling"] = 2] = "Sibling";
|
|
10
|
-
Combinator[Combinator["Adjacent"] = 3] = "Adjacent";
|
|
11
|
-
Combinator[Combinator["Inner"] = 4] = "Inner";
|
|
12
|
-
return Combinator;
|
|
13
|
-
}(Combinator || {});
|
|
14
|
-
var MatcherType = /*#__PURE__*/function (MatcherType) {
|
|
15
|
-
MatcherType[MatcherType["Unknown"] = 0] = "Unknown";
|
|
16
|
-
MatcherType[MatcherType["Id"] = 1] = "Id";
|
|
17
|
-
MatcherType[MatcherType["Class"] = 2] = "Class";
|
|
18
|
-
MatcherType[MatcherType["Attribute"] = 3] = "Attribute";
|
|
19
|
-
MatcherType[MatcherType["Pseudo"] = 4] = "Pseudo";
|
|
20
|
-
MatcherType[MatcherType["Function"] = 5] = "Function";
|
|
21
|
-
return MatcherType;
|
|
22
|
-
}(MatcherType || {});
|
|
23
|
-
function querySelector(within, selector) {
|
|
24
|
-
const parts = parseSelector(selector);
|
|
25
|
-
let result = null;
|
|
26
|
-
const child = within[constants.CHILD];
|
|
27
|
-
if (child && parts[0].matchers.length) {
|
|
28
|
-
walkNodesForSelector(child, parts, node => {
|
|
29
|
-
result = node;
|
|
30
|
-
return false;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
function querySelectorAll(within, selector) {
|
|
36
|
-
const parts = parseSelector(selector);
|
|
37
|
-
const results = [];
|
|
38
|
-
const child = within[constants.CHILD];
|
|
39
|
-
if (child && parts[0].matchers.length) {
|
|
40
|
-
walkNodesForSelector(child, parts, node => {
|
|
41
|
-
results.push(node);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return results;
|
|
45
|
-
}
|
|
46
|
-
function parseSelector(selector) {
|
|
47
|
-
let part = {
|
|
48
|
-
combinator: Combinator.Inner,
|
|
49
|
-
matchers: []
|
|
50
|
-
};
|
|
51
|
-
const parts = [part];
|
|
52
|
-
const tokenizer = /\s*?([>\s+~]?)\s*?(?:(?:\[\s*([^\]=]+)(?:=(['"])(.*?)\3)?\s*\])|([#.])([^\s#.[>:]+)|:(\w+)(?:\((.*?)\))?)/gi;
|
|
53
|
-
let token;
|
|
54
|
-
while (token = tokenizer.exec(selector)) {
|
|
55
|
-
// [1]: ancestor/parent/sibling/adjacent
|
|
56
|
-
// [2]: attribute name
|
|
57
|
-
// [4]: attribute value
|
|
58
|
-
// [5]: id/class sigil
|
|
59
|
-
// [6]: id/class name
|
|
60
|
-
// [7]: :pseudo/:function() name
|
|
61
|
-
// [8]: :function(argument) value
|
|
62
|
-
if (token[1]) {
|
|
63
|
-
// Update the combinator on the (now parent) Part:
|
|
64
|
-
if (token[1] === '>') part.combinator = Combinator.Child;else if (token[1] === '+') part.combinator = Combinator.Adjacent;else if (token[1] === '~') part.combinator = Combinator.Sibling;else part.combinator = Combinator.Descendant;
|
|
65
|
-
// Add a new Part for the next selector parts:
|
|
66
|
-
part = {
|
|
67
|
-
combinator: Combinator.Inner,
|
|
68
|
-
matchers: []
|
|
69
|
-
};
|
|
70
|
-
parts.push(part);
|
|
71
|
-
}
|
|
72
|
-
let type = MatcherType.Unknown;
|
|
73
|
-
if (token[2]) {
|
|
74
|
-
type = MatcherType.Attribute;
|
|
75
|
-
} else if (token[5]) {
|
|
76
|
-
type = token[5] === '#' ? MatcherType.Id : MatcherType.Class;
|
|
77
|
-
} else if (token[7]) {
|
|
78
|
-
type = token[8] == null ? MatcherType.Pseudo : MatcherType.Function;
|
|
79
|
-
}
|
|
80
|
-
part.matchers.push({
|
|
81
|
-
type,
|
|
82
|
-
name: token[2] || token[6] || token[7],
|
|
83
|
-
value: token[4] ?? token[6] ?? token[8]
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return parts;
|
|
87
|
-
}
|
|
88
|
-
function matchesSelector(element, selector) {
|
|
89
|
-
const parsed = parseSelector(selector);
|
|
90
|
-
let part;
|
|
91
|
-
while (part = parsed.pop()) {
|
|
92
|
-
if (!matchesSelectorPart(element, part)) return false;
|
|
93
|
-
}
|
|
94
|
-
// let part = parsed.pop();
|
|
95
|
-
// if (!part || !matchesSelectorPart(element, part)) {
|
|
96
|
-
// return false;
|
|
97
|
-
// }
|
|
98
|
-
// while ((part = parsed.pop())) {
|
|
99
|
-
// if (!matchesSelectorPart(element, part)) return false;
|
|
100
|
-
// }
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
function walkNodesForSelector(node, parts, callback) {
|
|
104
|
-
if (shared.isElementNode(node)) {
|
|
105
|
-
if (matchesSelectorRecursive(node, parts)) {
|
|
106
|
-
if (callback(node) === false) return false;
|
|
107
|
-
}
|
|
108
|
-
const child = node[constants.CHILD];
|
|
109
|
-
if (child && walkNodesForSelector(child, parts, callback) === false) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const next = node[constants.NEXT];
|
|
114
|
-
if (next && walkNodesForSelector(next, parts, callback) === false) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
function matchesSelectorRecursive(element, parts) {
|
|
120
|
-
const {
|
|
121
|
-
combinator,
|
|
122
|
-
matchers
|
|
123
|
-
} = parts[parts.length - 1];
|
|
124
|
-
if (combinator === Combinator.Inner) {
|
|
125
|
-
if (!matchesSelectorMatcher(element, matchers)) return false;
|
|
126
|
-
const pp = parts.slice(0, -1);
|
|
127
|
-
return pp.length === 0 || matchesSelectorRecursive(element, pp);
|
|
128
|
-
}
|
|
129
|
-
const link = combinator === Combinator.Child || combinator === Combinator.Descendant ? constants.PARENT : constants.PREV;
|
|
130
|
-
let ref = element[link];
|
|
131
|
-
if (!ref || !matchesSelectorMatcher(ref, matchers)) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
if (combinator === Combinator.Descendant || combinator === Combinator.Sibling) {
|
|
135
|
-
while (ref = ref[link]) {
|
|
136
|
-
if (matchesSelectorMatcher(ref, matchers)) {
|
|
137
|
-
const pp = parts.slice(0, -1);
|
|
138
|
-
if (pp.length === 0) return true;
|
|
139
|
-
if (matchesSelectorRecursive(element, pp)) return true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
function matchesSelectorPart(element, {
|
|
146
|
-
combinator,
|
|
147
|
-
matchers
|
|
148
|
-
}) {
|
|
149
|
-
if (combinator === Combinator.Inner) {
|
|
150
|
-
return matchesSelectorMatcher(element, matchers);
|
|
151
|
-
}
|
|
152
|
-
const link = combinator === Combinator.Child || combinator === Combinator.Descendant ? constants.PARENT : constants.PREV;
|
|
153
|
-
let ref = element[link];
|
|
154
|
-
if (!ref || !matchesSelectorMatcher(ref, matchers)) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
if (combinator === Combinator.Descendant || combinator === Combinator.Sibling) {
|
|
158
|
-
while (ref = ref[link]) {
|
|
159
|
-
if (matchesSelectorMatcher(ref, matchers)) return true;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
function matchesSelectorMatcher(element, matcher) {
|
|
165
|
-
if (!element) return false;
|
|
166
|
-
if (Array.isArray(matcher)) {
|
|
167
|
-
for (const single of matcher) {
|
|
168
|
-
if (matchesSelectorMatcher(element, single) === false) return false;
|
|
169
|
-
}
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
const {
|
|
173
|
-
type,
|
|
174
|
-
name,
|
|
175
|
-
value
|
|
176
|
-
} = matcher;
|
|
177
|
-
switch (type) {
|
|
178
|
-
// case 'id': case 'class': return element.getAttribute(matcher.type) === matcher.name;
|
|
179
|
-
case MatcherType.Id:
|
|
180
|
-
return element.getAttribute('id') === name;
|
|
181
|
-
case MatcherType.Class:
|
|
182
|
-
return element.getAttribute('class') === name;
|
|
183
|
-
case MatcherType.Attribute:
|
|
184
|
-
return value == null ? element.hasAttribute(name) : element.getAttribute(name) === value;
|
|
185
|
-
case MatcherType.Pseudo:
|
|
186
|
-
switch (name) {
|
|
187
|
-
default:
|
|
188
|
-
throw Error(`Pseudo :${name} not implemented`);
|
|
189
|
-
}
|
|
190
|
-
case MatcherType.Function:
|
|
191
|
-
switch (name) {
|
|
192
|
-
case 'has':
|
|
193
|
-
return matchesSelector(element, value || '');
|
|
194
|
-
default:
|
|
195
|
-
throw Error(`Function :${name}(${value}) not implemented`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
exports.parseSelector = parseSelector;
|
|
202
|
-
exports.querySelector = querySelector;
|
|
203
|
-
exports.querySelectorAll = querySelectorAll;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var constants = require('./constants.cjs');
|
|
4
|
-
|
|
5
|
-
// const voidElements = {
|
|
6
|
-
// img: true,
|
|
7
|
-
// image: true,
|
|
8
|
-
// };
|
|
9
|
-
// const elementTokenizer =
|
|
10
|
-
// /(?:<([a-z][a-z0-9-:]*)( [^<>'"\n=\s]+=(['"])[^>'"\n]*\3)*\s*(\/?)\s*>|<\/([a-z][a-z0-9-:]*)>|([^&<>]+))/gi;
|
|
11
|
-
// const attributeTokenizer = / ([^<>'"\n=\s]+)=(['"])([^>'"\n]*)\2/g;
|
|
12
|
-
const elementTokenizer = /(?:<([a-z][a-z0-9-:]*)((?:\s[^<>'"=\n\s]+(?:=(['"])[^\n]*?\3|=[^>'"\n\s]*|))*)\s*(\/?)\s*>|<\/([a-z][a-z0-9-:]*)>|<!--(.*?)-->|([^&<>]+))/gi;
|
|
13
|
-
const attributeTokenizer = /\s([^<>'"=\n\s]+)(?:=(['"])([^\n]*?)\2|=([^>'"\n\s]*)|)/g;
|
|
14
|
-
function parseHtml(html, contextNode) {
|
|
15
|
-
const document = contextNode.ownerDocument;
|
|
16
|
-
const root = document.createDocumentFragment();
|
|
17
|
-
const stack = [root];
|
|
18
|
-
let parent = root;
|
|
19
|
-
let token;
|
|
20
|
-
elementTokenizer.lastIndex = 0;
|
|
21
|
-
while (token = elementTokenizer.exec(html)) {
|
|
22
|
-
const tag = token[1];
|
|
23
|
-
if (tag) {
|
|
24
|
-
const node = document.createElement(tag);
|
|
25
|
-
const attrs = token[2];
|
|
26
|
-
attributeTokenizer.lastIndex = 0;
|
|
27
|
-
let t;
|
|
28
|
-
while (t = attributeTokenizer.exec(attrs)) {
|
|
29
|
-
node.setAttribute(t[1], t[3] || t[4] || '');
|
|
30
|
-
}
|
|
31
|
-
parent.append(node);
|
|
32
|
-
// if (voidElements[tag] === true) continue;
|
|
33
|
-
stack.push(parent);
|
|
34
|
-
parent = node;
|
|
35
|
-
} else if (token[5]) {
|
|
36
|
-
parent = stack.pop() || root;
|
|
37
|
-
} else if (token[6]) {
|
|
38
|
-
parent.append(document.createComment(token[6]));
|
|
39
|
-
} else {
|
|
40
|
-
parent.append(token[7]);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return root;
|
|
44
|
-
}
|
|
45
|
-
function serializeChildren(parentNode) {
|
|
46
|
-
let out = '';
|
|
47
|
-
let child = parentNode[constants.CHILD];
|
|
48
|
-
while (child) {
|
|
49
|
-
out += serializeNode(child);
|
|
50
|
-
child = child[constants.NEXT];
|
|
51
|
-
}
|
|
52
|
-
return out;
|
|
53
|
-
}
|
|
54
|
-
function serializeNode(node) {
|
|
55
|
-
switch (node.nodeType) {
|
|
56
|
-
case constants.NodeType.ELEMENT_NODE:
|
|
57
|
-
{
|
|
58
|
-
const el = node;
|
|
59
|
-
let out = `<${el[constants.NAME]}`;
|
|
60
|
-
let attr = el[constants.ATTRIBUTES]?.[constants.CHILD];
|
|
61
|
-
while (attr) {
|
|
62
|
-
out += ` ${attr[constants.NAME]}`;
|
|
63
|
-
let value = attr[constants.VALUE];
|
|
64
|
-
if (value !== '') {
|
|
65
|
-
value = String(value).replace(/&/g, '&').replace(/"/g, '"');
|
|
66
|
-
out += `="${value}"`;
|
|
67
|
-
}
|
|
68
|
-
attr = attr[constants.NEXT];
|
|
69
|
-
}
|
|
70
|
-
out += '>';
|
|
71
|
-
out += serializeChildren(el);
|
|
72
|
-
// let child = el[CHILD];
|
|
73
|
-
// while (child) {
|
|
74
|
-
// out += serialize(child);
|
|
75
|
-
// child = child[NEXT];
|
|
76
|
-
// }
|
|
77
|
-
out += `</${el[constants.NAME]}>`;
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
case constants.NodeType.TEXT_NODE:
|
|
81
|
-
{
|
|
82
|
-
const text = node;
|
|
83
|
-
return text[constants.DATA].replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
84
|
-
}
|
|
85
|
-
case constants.NodeType.COMMENT_NODE:
|
|
86
|
-
{
|
|
87
|
-
const text = node;
|
|
88
|
-
return `<!--${text[constants.DATA]}-->`;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return '';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
exports.parseHtml = parseHtml;
|
|
95
|
-
exports.serializeChildren = serializeChildren;
|
|
96
|
-
exports.serializeNode = serializeNode;
|
package/build/cjs/shared.cjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var constants = require('./constants.cjs');
|
|
4
|
-
|
|
5
|
-
function isCharacterData(node) {
|
|
6
|
-
return constants.DATA in node;
|
|
7
|
-
}
|
|
8
|
-
function isTextNode(node) {
|
|
9
|
-
return node.nodeType === constants.NodeType.TEXT_NODE;
|
|
10
|
-
}
|
|
11
|
-
function isCommentNode(node) {
|
|
12
|
-
return node.nodeType === constants.NodeType.COMMENT_NODE;
|
|
13
|
-
}
|
|
14
|
-
function isElementNode(node) {
|
|
15
|
-
return node.nodeType === constants.NodeType.ELEMENT_NODE;
|
|
16
|
-
}
|
|
17
|
-
function isDocumentFragmentNode(node) {
|
|
18
|
-
return node.nodeType === constants.NodeType.DOCUMENT_FRAGMENT_NODE;
|
|
19
|
-
}
|
|
20
|
-
function isParentNode(node) {
|
|
21
|
-
return 'appendChild' in node;
|
|
22
|
-
}
|
|
23
|
-
function cloneNode(node, deep, document = node.ownerDocument) {
|
|
24
|
-
if (isTextNode(node)) {
|
|
25
|
-
return document.createTextNode(node.data);
|
|
26
|
-
} else if (isCommentNode(node)) {
|
|
27
|
-
return document.createComment(node.data);
|
|
28
|
-
} else if (isElementNode(node)) {
|
|
29
|
-
const cloned = document.createElement(node.localName);
|
|
30
|
-
if (node[constants.ATTRIBUTES]) {
|
|
31
|
-
for (let i = 0; i < node[constants.ATTRIBUTES].length; i++) {
|
|
32
|
-
const attribute = node[constants.ATTRIBUTES].item(i);
|
|
33
|
-
cloned.setAttributeNS(attribute.namespaceURI, attribute.name, attribute.value);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (deep) {
|
|
37
|
-
for (const child of node.childNodes) {
|
|
38
|
-
cloned.appendChild(cloneNode(child, true, document));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return cloned;
|
|
42
|
-
} else if (isDocumentFragmentNode(node)) {
|
|
43
|
-
const fragment = document.createDocumentFragment();
|
|
44
|
-
if (deep) {
|
|
45
|
-
for (const child of node.childNodes) {
|
|
46
|
-
fragment.appendChild(cloneNode(child, true, document));
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return fragment;
|
|
50
|
-
} else {
|
|
51
|
-
const cloned = new node.constructor();
|
|
52
|
-
cloned[constants.OWNER_DOCUMENT] = document;
|
|
53
|
-
return cloned;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
exports.cloneNode = cloneNode;
|
|
58
|
-
exports.isCharacterData = isCharacterData;
|
|
59
|
-
exports.isCommentNode = isCommentNode;
|
|
60
|
-
exports.isDocumentFragmentNode = isDocumentFragmentNode;
|
|
61
|
-
exports.isElementNode = isElementNode;
|
|
62
|
-
exports.isParentNode = isParentNode;
|
|
63
|
-
exports.isTextNode = isTextNode;
|