@shgysk8zer0/polyfills 0.4.4 → 0.4.5

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.
package/element.js CHANGED
@@ -1,10 +1,32 @@
1
1
  import { aria } from './aom.js';
2
- import { polyfillGetterSetter, polyfillMethod } from './utils.js';
2
+ import { polyfillGetterSetter, polyfillMethod, overwriteMethod } from './utils.js';
3
3
  import { setHTMLUnsafe } from './methods/dom.js';
4
4
  import './sanitizer.js';
5
5
 
6
6
  polyfillMethod(Element.prototype, 'setHTMLUnsafe', setHTMLUnsafe);
7
7
 
8
+ if ('CustomElementRegistry' in globalThis && ! (CustomElementRegistry.prototype.getName instanceof Function)) {
9
+ const registry = new Map();
10
+
11
+ overwriteMethod(CustomElementRegistry.prototype, 'define', original => {
12
+ return (tag, proto, opts) => {
13
+ original.call(customElements, tag,proto, opts);
14
+ registry.set(proto, typeof opts.extends === 'string' ? opts.extends : tag);
15
+ };
16
+ });
17
+
18
+ polyfillMethod(CustomElementRegistry.prototype, 'getName', proto => {
19
+ if (typeof proto === 'function') {
20
+ return registry.get(proto) ?? null;
21
+ } else if (typeof proto === 'object' && proto !== null) {
22
+ // Unnecessary, but just to be sure the same errors are thrown.
23
+ throw new TypeError('CustomElementRegistry.getName: Argument 1 is not callable.');
24
+ } else {
25
+ throw new TypeError('CustomElementRegistry.getName: Argument 1 is not an object.');
26
+ }
27
+ });
28
+ }
29
+
8
30
  function handlePopover({ currentTarget }) {
9
31
  switch(currentTarget.popoverTargetAction) {
10
32
  case 'show':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shgysk8zer0/polyfills",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A collection of JavaScript polyfills",