This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
basichtml.js
61 lines (60 loc) · 2.21 KB
/
basichtml.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const utils = require('./src/utils');
const CustomElementRegistry = require('./src/CustomElementRegistry');
const Document = require('./src/Document');
const EventTarget = require('./src/EventTarget');
const HTMLElement = require('./src/HTMLElement');
const HTMLUnknownElement = require('./src/HTMLUnknownElement');
const CustomEvent = require('./src/CustomEvent');
const Image = require('./src/ImageFactory');
const NodeFilter = require('./src/NodeFilter');
const TreeWalker = require('./src/TreeWalker');
module.exports = {
Attr: require('./src/Attr'),
CharacterData: require('./src/CharacterData'),
Comment: require('./src/Comment'),
CustomElementRegistry: CustomElementRegistry,
CustomEvent: CustomEvent,
Document: Document,
DocumentFragment: require('./src/DocumentFragment'),
DocumentType: require('./src/DocumentType'),
DOMStringMap: require('./src/DOMStringMap'),
DOMTokenList: require('./src/DOMTokenList'),
Element: require('./src/Element'),
Event: require('./src/Event'),
EventTarget: EventTarget,
HTMLElement: HTMLElement,
HTMLUnknownElement: HTMLUnknownElement,
HTMLHtmlElement: require('./src/HTMLHtmlElement'),
HTMLTemplateElement: require('./src/HTMLTemplateElement'),
Image: Image,
Node: require('./src/Node'),
Text: require('./src/Text'),
NodeFilter: NodeFilter,
TreeWalker: TreeWalker,
init: (options) => {
if (!options) options = {};
const window = options.window ||
(typeof self === 'undefined' ? global : self);
window.customElements = options.customElements ||
new CustomElementRegistry();
window.document = new Document(window.customElements);
window.window = window;
window.HTMLElement = HTMLElement;
window.HTMLUnknownElement = HTMLUnknownElement;
window.CustomEvent = CustomEvent;
window.Image = function (...args) {
return Image(window.document, ...args);
};
EventTarget.init(window);
if (options.selector) {
const $ = options.selector.$;
const selector = options.selector.module ?
options.selector.module(window) :
require(options.selector.name);
utils.querySelectorAll = function querySelectorAll(css) {
return $(selector, this, css);
};
}
return window;
}
};