@shgysk8zer0/polyfills 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
package/element.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { aria } from './aom.js';
2
- import { overwriteMethod, polyfillGetterSetter } from './utils.js';
3
- import { SanitizerConfig as defaultConfig } from './assets/SanitizerConfigW3C.js';
4
- import { setHTML as safeSetHTML, convertToSanitizerConfig } from './assets/sanitizerUtils.js';
2
+ import { polyfillGetterSetter } from './utils.js';
3
+ import './sanitizer.js';
5
4
 
6
5
  function handlePopover({ currentTarget }) {
7
6
  switch(currentTarget.popoverTargetAction) {
@@ -243,23 +242,6 @@ if (! (HTMLImageElement.prototype.decode instanceof Function)) {
243
242
  };
244
243
  }
245
244
 
246
- if (! (Element.prototype.setHTML instanceof Function)) {
247
- Element.prototype.setHTML = function setHTML(input, opts = defaultConfig) {
248
- safeSetHTML(this, input, opts);
249
- };
250
- } else {
251
- overwriteMethod(Element.prototype, 'setHTML', function(orig) {
252
- return function setHTML(input, opts = {}) {
253
- if (! (opts.sanitizer instanceof Sanitizer)) {
254
- const sanitizer = new Sanitizer(convertToSanitizerConfig(opts));
255
- orig.call(this, input, { sanitizer });
256
- } else {
257
- orig.call(this, input, opts);
258
- }
259
- };
260
- });
261
- }
262
-
263
245
  if (! HTMLTemplateElement.prototype.hasOwnProperty('shadowRootMode')) {
264
246
  Object.defineProperty(HTMLTemplateElement.prototype, 'shadowRootMode', {
265
247
  get: function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/polyfills",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A collection of JavaScript polyfills",
@@ -38,6 +38,7 @@
38
38
  "fix:js": "eslint . --fix",
39
39
  "lint:js": "eslint .",
40
40
  "lint:html": "htmlhint \"**/*.html\"",
41
+ "build": "npm run build:js",
41
42
  "build:js": "rollup -c rollup.config.js",
42
43
  "create:lock": "npm i --package-lock-only --ignore-scripts --no-audit --no-fund",
43
44
  "version:bump": "npm run version:bump:patch",
@@ -70,8 +71,12 @@
70
71
  },
71
72
  "homepage": "https://github.com/shgysk8zer0/polyfills#readme",
72
73
  "devDependencies": {
74
+ "@rollup/plugin-node-resolve": "^15.2.3",
73
75
  "@shgysk8zer0/js-utils": "^1.0.1",
74
76
  "htmlhint": "^1.1.4",
75
77
  "http-server": "^14.1.1"
78
+ },
79
+ "dependencies": {
80
+ "@aegisjsproject/sanitizer": "^0.0.2"
76
81
  }
77
82
  }
package/rollup.config.js CHANGED
@@ -1,8 +1,11 @@
1
1
  /* eslint-env node */
2
2
  import { getConfig } from '@shgysk8zer0/js-utils/rollup';
3
+ import nodeResolve from '@rollup/plugin-node-resolve';
4
+
3
5
 
4
6
  export default getConfig('./all.js', {
5
7
  sourcemap: true,
6
8
  minify: true,
7
9
  format: 'iife',
10
+ plugins: [nodeResolve()],
8
11
  });
package/sanitizer.js ADDED
@@ -0,0 +1 @@
1
+ import '@aegisjsproject/sanitizer/sanitizer.js';
@@ -1,61 +0,0 @@
1
- /**
2
- * @copyright 2022-2023 Chris Zuber <admin@kernvalley.us>
3
- */
4
- import { nativeSupport, getSantizerUtils, sanitize, trustPolicies } from './sanitizerUtils.js';
5
- import { SanitizerConfig as defaultConfig } from './SanitizerConfigW3C.js';
6
-
7
- const protectedData = new WeakMap();
8
-
9
- /**
10
- * Need to create a policy for the Sanitizer API since
11
- * `trustedTypes.defaultPolicy.createHTML` will most likely use `new Sanitizer().sanitize()`
12
- * which would create infinite recursion.
13
- * @type {TrustedTypePolicy}
14
- */
15
-
16
-
17
- /**
18
- * @SEE https://wicg.github.io/sanitizer-api/
19
- * @SEE https://developer.mozilla.org/en-US/docs/Web/API/Sanitizer/Sanitizer
20
- * @TODO: Figure out how to handle `allowElements`, `allowAttributes`, and how each
21
- * works with their `block*` and/or `drop*` counterparts.
22
- * @TODO: Handle `svg:*` and `mathml:*`
23
- *
24
- * @NOTE: The spec is still under development and is likely to change.
25
- * @NOTE: This is a very imperfect implementation and may not perform very well,
26
- * as it may involve a lot of querying & modifying.
27
- */
28
- export class Sanitizer {
29
- constructor({
30
- allowElements, allowAttributes, blockElements, dropAttributes,
31
- dropElements, allowComments = defaultConfig.allowComments,
32
- allowCustomElements = defaultConfig.allowCustomElements,
33
- allowUnknownMarkup = defaultConfig.allowUnknownMarkup,
34
- } = Sanitizer.getDefaultConfiguration()) {
35
- protectedData.set(this, {
36
- allowElements, allowComments, allowAttributes, allowCustomElements,
37
- blockElements, dropAttributes, dropElements, allowUnknownMarkup,
38
- });
39
- }
40
-
41
- getConfiguration() {
42
- return protectedData.get(this);
43
- }
44
-
45
- sanitize(input) {
46
- return sanitize(input, this.getConfiguration());
47
- }
48
-
49
- sanitizeFor(tag, content) {
50
- const el = document.createElement(tag);
51
- el.setHTML(content, this.getConfiguration());
52
- return el;
53
- }
54
-
55
- static getDefaultConfiguration() {
56
- return defaultConfig;
57
- }
58
- }
59
-
60
- const { setHTML, polyfill } = getSantizerUtils(Sanitizer, defaultConfig);
61
- export { nativeSupport, setHTML, polyfill, trustPolicies };
@@ -1,348 +0,0 @@
1
- /**
2
- * @copyright 2023 Chris Zuber <admin@kernvalley.us>
3
- */
4
- import { allowComments, blockElements, dropElements, allowUnknownMarkup } from './SanitizerConfigBase.js';
5
- import { events } from './attributes.js';
6
- export const allowAttributes = {
7
- 'abbr': ['*'],
8
- // 'accept': ['*'],
9
- // 'accept-charset': ['*'],
10
- 'accesskey': ['*'],
11
- 'action': ['form'],
12
- // 'align': ['*'],
13
- // 'alink': ['*'],
14
- 'allow': ['iframe'],
15
- 'allowfullscreen': ['iframe'],
16
- 'alt': ['img'],
17
- // 'anchor': ['*'],
18
- // 'archive': ['*'],
19
- 'as': ['link'],
20
- 'async': ['script'],
21
- 'autocapitalize': ['form', 'input', 'textarea'],
22
- 'autocomplete': ['input', 'select', 'textarea'],
23
- 'autocorrect': ['form', 'input', 'textarea'],
24
- 'autofocus': ['*'],
25
- 'autopictureinpicture': ['video'],
26
- 'autoplay': ['audio', 'video'],
27
- // 'axis': ['*'],
28
- // 'background': ['*'],
29
- // 'behavior': ['*'],
30
- // 'bgcolor': ['*'],
31
- 'border': ['*'],
32
- // 'bordercolor': ['*'],
33
- // 'capture': ['*'],
34
- 'cellpadding': ['*'],
35
- 'cellspacing': ['*'],
36
- // 'challenge': ['*'],
37
- // 'char': ['*'],
38
- // 'charoff': ['*'],
39
- // 'charset': ['*'],
40
- 'checked': ['input'],
41
- 'cite': ['blockquote'],
42
- 'class': ['*'],
43
- // 'classid': ['*'],
44
- // 'clear': ['*'],
45
- // 'code': ['*'],
46
- // 'codebase': ['*'],
47
- // 'codetype': ['*'],
48
- // 'color': ['*'],
49
- 'cols': ['*'],
50
- 'colspan': ['*'],
51
- // 'compact': ['*'],
52
- 'content': ['meta'],
53
- 'contenteditable': ['*'],
54
- 'controls': ['audio', 'video'],
55
- // 'controlslist': ['*'],
56
- // 'conversiondestination': ['*'],
57
- // 'coords': ['*'],
58
- 'crossorigin': ['script', 'link', 'img', 'audio', 'video'],
59
- 'csp': ['iframe'],
60
- 'data': ['*'],
61
- 'datetime': ['time'],
62
- // 'declare': ['*'],
63
- 'decoding': ['img'],
64
- 'default': ['input'],
65
- 'defer': ['script'],
66
- 'dir': ['*'],
67
- // 'direction': ['*'],
68
- 'dirname': ['*'],
69
- 'disabled': ['button', 'input', 'fieldset'],
70
- 'disablepictureinpicture': ['*'],
71
- 'disableremoteplayback': ['*'],
72
- 'download': ['a'],
73
- 'draggable': ['*'],
74
- // 'elementtiming': ['*'],
75
- 'enctype': ['form'],
76
- // 'end': ['*'],
77
- 'enterkeyhint': ['input', 'button'],
78
- // 'event': ['*'],
79
- // 'exportparts': ['*'],
80
- // 'face': ['*'],
81
- 'for': ['label', 'output'],
82
- // 'form': ['*'],
83
- // 'formaction': ['*'],
84
- // 'formenctype': ['*'],
85
- // 'formmethod': ['*'],
86
- // 'formnovalidate': ['*'],
87
- // 'formtarget': ['*'],
88
- // 'frame': ['*'],
89
- 'frameborder': ['iframe'],
90
- // 'headers': ['*'],
91
- 'height': ['img', 'iframe', 'video'],
92
- 'hidden': ['*'],
93
- // 'high': ['*'],
94
- 'href': ['a', 'link'],
95
- 'hreflang': ['*'],
96
- // 'hreftranslate': ['*'],
97
- // 'hspace': ['*'],
98
- // 'http-equiv': ['*'],
99
- 'id': ['*'],
100
- // 'imagesizes': ['*'],
101
- // 'imagesrcset': ['*'],
102
- 'importance': ['*'],
103
- // 'impressiondata': ['*'],
104
- // 'impressionexpiry': ['*'],
105
- 'incremental': ['*'],
106
- 'inert': ['*'],
107
- 'inputmode': ['*'],
108
- 'integrity': ['link', 'script'],
109
- 'invisible': ['*'],
110
- 'is': ['*'],
111
- // 'ismap': ['*'],
112
- // 'keytype': ['*'],
113
- // 'kind': ['*'],
114
- 'label': ['*'],
115
- 'lang': ['*'],
116
- 'language': ['*'],
117
- // 'latencyhint': ['*'],
118
- // 'leftmargin': ['*'],
119
- 'link': ['*'],
120
- 'list': ['input', 'textarea'],
121
- 'loading': ['img', 'iframe'],
122
- // 'longdesc': ['*'],
123
- // 'loop': ['*'],
124
- // 'low': ['*'],
125
- // 'lowsrc': ['*'],
126
- // 'manifest': ['*'],
127
- // 'marginheight': ['*'],
128
- // 'marginwidth': ['*'],
129
- 'max': ['input'],
130
- 'maxlength': ['input', 'textarea'],
131
- // 'mayscript': ['*'],
132
- 'media': ['link'],
133
- 'method': ['form'],
134
- 'min': ['input'],
135
- 'minlength': ['input', 'textarea'],
136
- 'multiple': ['input', 'select'],
137
- 'muted': ['audio', 'video'],
138
- 'name': ['*'],
139
- // 'nohref': ['*'],
140
- 'nomodule': ['script'],
141
- 'nonce': ['script', 'link'],
142
- 'noresize': ['*'],
143
- // 'noshade': ['*'],
144
- 'novalidate': ['*'],
145
- 'nowrap': ['*'],
146
- 'object': ['*'],
147
- 'open': ['details', 'dialog'],
148
- // 'optimum': ['*'],
149
- 'part': ['*'],
150
- 'pattern': ['input', 'teaxarea'],
151
- // 'ping': ['*'],
152
- 'placeholder': ['input', 'textarea'],
153
- 'playsinline': ['*'],
154
- // 'policy': ['*'],
155
- 'poster': ['video'],
156
- 'preload': ['*'],
157
- // 'pseudo': ['*'],
158
- 'readonly': ['input', 'textarea', 'select'],
159
- 'referrerpolicy': ['script', 'link', 'img', 'video', 'source', 'iframe'],
160
- 'rel': ['a', 'link'],
161
- // 'reportingorigin': ['*'],
162
- 'required': ['input', 'textarea', 'select'],
163
- // 'resources': ['*'],
164
- 'rev': ['*'],
165
- 'reversed': ['*'],
166
- 'role': ['*'],
167
- 'rows': ['*'],
168
- 'rowspan': ['*'],
169
- 'rules': ['*'],
170
- 'sandbox': ['iframe'],
171
- // 'scheme': ['*'],
172
- // 'scope': ['*'],
173
- // 'scopes': ['*'],
174
- // 'scrollamount': ['*'],
175
- // 'scrolldelay': ['*'],
176
- 'scrolling': ['iframe'],
177
- // 'select': ['*'],
178
- 'selected': ['option'],
179
- 'shadowroot': ['template'],
180
- // 'shadowrootdelegatesfocus': ['*'],
181
- // 'shape': ['*'],
182
- 'size': ['*'],
183
- 'sizes': ['img'],
184
- 'slot': ['*'],
185
- 'span': ['*'],
186
- 'spellcheck': ['*'],
187
- 'src': ['img', 'script', 'source', 'audio', 'video'],
188
- // 'srcdoc': ['iframe'],
189
- 'srclang': ['*'],
190
- 'srcset': ['img'],
191
- // 'standby': ['*'],
192
- // 'start': ['*'],
193
- 'step': ['input'],
194
- // 'style': ['*'],
195
- // 'summary': ['*'],
196
- 'tabindex': ['*'],
197
- 'target': ['a', 'form'],
198
- 'text': ['*'],
199
- 'title': ['*'],
200
- // 'topmargin': ['*'],
201
- // 'translate': ['*'],
202
- // 'truespeed': ['*'],
203
- // 'trusttoken': ['*'],
204
- 'type': ['script', 'input'],
205
- // 'usemap': ['*'],
206
- // 'valign': ['*'],
207
- 'value': ['input'],
208
- // 'valuetype': ['*'],
209
- // 'version': ['*'],
210
- // 'virtualkeyboardpolicy': ['*'],
211
- // 'vlink': ['*'],
212
- // 'vspace': ['*'],
213
- 'webkitdirectory': ['*'],
214
- 'width': ['img', 'iframe', 'video'],
215
- 'wrap': ['*'],
216
- };
217
-
218
- export const allowCustomElements = true;
219
-
220
- export const allowElements = [
221
- 'a',
222
- 'abbr',
223
- 'acronym',
224
- 'address',
225
- 'area',
226
- 'article',
227
- 'aside',
228
- 'audio',
229
- 'b',
230
- 'bdi',
231
- 'bdo',
232
- 'big',
233
- 'blockquote',
234
- 'body',
235
- 'br',
236
- 'button',
237
- 'canvas',
238
- 'caption',
239
- 'center',
240
- 'cite',
241
- 'code',
242
- 'col',
243
- 'colgroup',
244
- 'datalist',
245
- 'dd',
246
- 'del',
247
- 'details',
248
- 'dialog',
249
- 'dfn',
250
- 'dir',
251
- 'div',
252
- 'dl',
253
- 'dt',
254
- 'em',
255
- 'fieldset',
256
- 'figcaption',
257
- 'figure',
258
- 'font',
259
- 'footer',
260
- 'form',
261
- 'h1',
262
- 'h2',
263
- 'h3',
264
- 'h4',
265
- 'h5',
266
- 'h6',
267
- 'head',
268
- 'header',
269
- 'hgroup',
270
- 'hr',
271
- 'html',
272
- 'i',
273
- 'img',
274
- 'input',
275
- 'ins',
276
- 'kbd',
277
- 'keygen',
278
- 'label',
279
- 'legend',
280
- 'li',
281
- 'link',
282
- 'listing',
283
- 'map',
284
- 'mark',
285
- 'menu',
286
- 'meta',
287
- 'meter',
288
- 'nav',
289
- 'nobr',
290
- 'ol',
291
- 'optgroup',
292
- 'option',
293
- 'output',
294
- 'p',
295
- 'picture',
296
- 'pre',
297
- 'progress',
298
- 'q',
299
- 'rb',
300
- 'rp',
301
- 'rt',
302
- 'rtc',
303
- 'ruby',
304
- 's',
305
- 'samp',
306
- 'section',
307
- 'select',
308
- 'slot',
309
- 'small',
310
- 'source',
311
- 'span',
312
- 'strike',
313
- 'strong',
314
- 'sub',
315
- 'summary',
316
- 'sup',
317
- 'svg',
318
- 'style',
319
- 'table',
320
- 'template',
321
- 'tbody',
322
- 'td',
323
- 'textarea',
324
- 'tfoot',
325
- 'th',
326
- 'thead',
327
- 'time',
328
- 'tr',
329
- 'track',
330
- 'tt',
331
- 'u',
332
- 'ul',
333
- 'var',
334
- 'video',
335
- 'wbr'
336
- ];
337
-
338
- export const dropAttributes = {
339
- 'style': ['*'],
340
- ...Object.fromEntries(events.map(ev => [ev, ['*']])),
341
- };
342
-
343
- export const SanitizerConfig = {
344
- allowAttributes, allowComments, allowElements, allowCustomElements,
345
- blockElements, dropAttributes, dropElements,
346
- };
347
-
348
- export { allowComments, blockElements, dropElements, allowUnknownMarkup };
@@ -1,18 +0,0 @@
1
- /**
2
- * @copyright 2023 Chris Zuber <admin@kernvalley.us>
3
- */
4
- import { events } from './attributes.js';
5
-
6
- export const allowAttributes = undefined;
7
- export const allowComments = false;
8
- export const allowCustomElements = false;
9
- export const allowElements = undefined;
10
- export const blockElements = ['frame'];
11
- export const dropAttributes = Object.fromEntries(events.map(event => [event, ['*']]));
12
- export const dropElements = ['script', 'link', 'title', 'noscript', 'head', 'body', 'object', 'embed', 'param', 'iframe','base'];
13
- export const allowUnknownMarkup = false;
14
-
15
- export const SanitizerConfig = {
16
- allowAttributes, allowComments, allowElements, allowCustomElements,
17
- blockElements, dropAttributes, dropElements, allowUnknownMarkup,
18
- };