-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathcreator.js
More file actions
31 lines (29 loc) · 821 Bytes
/
creator.js
File metadata and controls
31 lines (29 loc) · 821 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
// @ts-check
/**
* @param {Document} document
* @returns
*/
var creator = (document = /** @type {Document} */(globalThis.document)) => {
let tpl = document.createElement('template'), range;
/**
* @param {string} content
* @param {boolean} [xml=false]
* @returns {DocumentFragment}
*/
return (content, xml = false) => {
if (xml) {
if (!range) {
range = document.createRange();
range.selectNodeContents(
document.createElementNS('http://www.w3.org/2000/svg', 'svg')
);
}
return range.createContextualFragment(content);
}
tpl.innerHTML = content;
const fragment = tpl.content;
tpl = /** @type {HTMLTemplateElement} */(tpl.cloneNode(false));
return fragment;
};
};
export { creator as default };