-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMain.js
executable file
·74 lines (56 loc) · 1.85 KB
/
Main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
import jsdom from "jsdom";
const enviroment = (new jsdom.JSDOM('', { runScripts: "outside-only" }));
global.window = enviroment.window;
global.document = enviroment.window.document;
global.SVGElement = enviroment.window.SVGElement;
global.CustomEvent = enviroment.window.CustomEvent;
export function unsafeCreateEnviroment() {
//removes event listeners and child nodes
document.body = document.body.cloneNode(false);
document.body.innerHTML = '<div id=mount-point></div>';
}
export function clickEvent() {
return new window.Event('click', { bubbles: true });
}
export function inputEvent() {
return new window.Event('input', { bubbles: true });
}
export function keydownEvent() {
return new window.KeyboardEvent('keydown', { key: 'q', bubbles: true });
}
export function enterPressedEvent() {
return new window.KeyboardEvent('keypress', { key: 'Enter', bubbles: true });
}
export function errorEvent() {
return new window.Event('error', { bubbles: true });
}
export function offlineEvent() {
return new window.Event('offline', { bubbles: true });
}
export function getCssText(node) {
return node.style.cssText;
}
export function getAllAttributes(node) {
let attributes = [];
for (let i = 0; i < node.attributes.length; i++)
attributes.push(node.attributes[i].name + ':' + node.attributes[i].value);
return attributes.join(' ');
}
export function getAllProperties(node) {
return function (list) {
let properties = [];
for (let p of list)
if (node[p])
properties.push(node[p] + '');
return properties;
};
}
export function innerHtml_(node, html) {
node.innerHTML = html;
}
export function createSvg() {
return document.createElementNS('http://www.w3.org/1999/xhtml', 'svg');
}
export function createDiv() {
return document.createElement('div');
}