(win, elementConnectedCallback)
| 91 | * @return {typeof AmpElement} The custom element class. |
| 92 | */ |
| 93 | export function createCustomElementClass(win, elementConnectedCallback) { |
| 94 | const BaseCustomElement = /** @type {typeof HTMLElement} */ ( |
| 95 | createBaseCustomElementClass(win, elementConnectedCallback) |
| 96 | ); |
| 97 | // It's necessary to create a subclass, because the same "base" class cannot |
| 98 | // be registered to multiple custom elements. |
| 99 | class CustomAmpElement extends BaseCustomElement { |
| 100 | /** |
| 101 | * adoptedCallback is only called when using a Native implementation of Custom Elements V1. |
| 102 | * Our polyfill does not call this method. |
| 103 | */ |
| 104 | adoptedCallback() { |
| 105 | // Work around an issue with Firefox changing the prototype of our |
| 106 | // already constructed element to the new document's HTMLElement. |
| 107 | if (Object.getPrototypeOf(this) !== customAmpElementProto) { |
| 108 | Object.setPrototypeOf(this, customAmpElementProto); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | const customAmpElementProto = CustomAmpElement.prototype; |
| 113 | return /** @type {typeof AmpElement} */ (CustomAmpElement); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Creates a base custom element class. |
no test coverage detected