generated from shgysk8zer0/npm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyfill.js
107 lines (96 loc) · 2.35 KB
/
polyfill.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import './sanitizer.js';
import { setHTML as html, parseHTML as parse } from '@aegisjsproject/sanitizer/sanitize.js';
if (! (Promise.withResolvers instanceof Function)) {
Promise.withResolvers = function withResolvers() {
const def = {};
def.promise = new Promise((resolve, reject) => {
def.resolve = resolve;
def.reject = reject;
});
return def;
};
}
/**
* This is needed for working with sanitizer configs & attrs
*/
if (! (URL.canParse instanceof Function)) {
URL.canParse = function canParse(url, base) {
try {
new URL(url, base);
return true;
} catch {
return false;
}
};
}
if (! (URL.parse instanceof Function)) {
URL.parse = function parse(url, base) {
try {
return new URL(url, base);
} catch {
return null;
}
};
}
if (! (Object.groupBy instanceof Function)) {
Object.groupBy = function groupBy(arr, callback) {
const obj = {};
for (const item of arr) {
const key = callback(item);
if (! (key in obj)) {
obj[key] = [item];
} else {
obj[key].push(item);
}
}
return obj;
};
}
if (! (Element.prototype.setHTML instanceof Function)) {
Element.prototype.setHTML = function setHTML(content, {
elements,
attributes,
comments,
dataAttributes,
sanitizer,
...rest
} = {}) {
/**
* @todo Remove legacy support for v1.0.0
*/
if (typeof sanitizer === 'object' && sanitizer !== null) {
html(this, content, sanitizer.getConfiguration instanceof Function
? sanitizer.getConfiguration()
: sanitizer);
} else {
html(this, content, { elements, attributes, comments, dataAttributes, ...rest });
}
};
DocumentFragment.prototype.setHTML = function setHTML(...args) {
Element.prototype.setHTML.apply(this, args);
};
HTMLTemplateElement.prototype.setHTML = function setHTML(html, config) {
this.content.setHTML(html, config);
};
}
if (! (Document.parseHTML instanceof Function)) {
Document.parseHTML = function parseHTML(content, {
elements,
attributes,
comments,
dataAttributes,
sanitizer,
...rest
} = {}) {
/**
* @todo Remove legacy support for v1.0.0
*/
if (typeof sanitizer === 'object' && sanitizer !== null) {
return Document.parseHTML(content, sanitizer.getConfiguration instanceof Function
? sanitizer.getConfiguration()
: sanitizer);
} else {
return parse(content, { elements, attributes, comments, dataAttributes, ...rest });
}
};
}