-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathutils.js
More file actions
35 lines (29 loc) · 835 Bytes
/
Copy pathutils.js
File metadata and controls
35 lines (29 loc) · 835 Bytes
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
const {isArray, prototype} = Array;
const {indexOf} = prototype;
export {isArray, indexOf};
const {
createDocumentFragment,
createElement,
createElementNS,
createTextNode,
createTreeWalker,
importNode
} = new Proxy({}, {
get: (_, method) => document[method].bind(document)
});
export {createTextNode, createTreeWalker, importNode};
const createHTML = html => {
const template = createElement('template');
template.innerHTML = html;
return template.content;
};
let xml;
const createSVG = svg => {
if (!xml) xml = createElementNS('http://www.w3.org/2000/svg', 'svg');
xml.innerHTML = svg;
const content = createDocumentFragment();
content.append(...xml.childNodes);
return content;
};
export const createContent = (text, svg) => svg ?
createSVG(text) : createHTML(text);