-
-
Notifications
You must be signed in to change notification settings - Fork 418
/
lit-element.js
40 lines (33 loc) · 1.47 KB
/
lit-element.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
import { dedupeMixin } from '@open-wc/dedupe-mixin';
import { adoptStyles } from 'lit';
import { ScopedElementsMixin as BaseScopedElementsMixin } from './html-element.js';
/**
* @typedef {import('./types.js').ScopedElementsHost} ScopedElementsHost
* @typedef {import('./types.js').ScopedElementsMap} ScopedElementsMap
* @typedef {import('lit').CSSResultOrNative} CSSResultOrNative
* @typedef {import('lit').LitElement} LitElement
* @typedef {typeof import('lit').LitElement} TypeofLitElement
* @typedef {import('@open-wc/dedupe-mixin').Constructor<LitElement>} LitElementConstructor
* @typedef {import('@open-wc/dedupe-mixin').Constructor<ScopedElementsHost>} ScopedElementsHostConstructor
*/
/**
* @template {LitElementConstructor} T
* @param {T} superclass
* @return {T & ScopedElementsHostConstructor}
*/
const ScopedElementsMixinImplementation = superclass =>
/** @type {ScopedElementsHost} */
class ScopedElementsHost extends BaseScopedElementsMixin(superclass) {
createRenderRoot() {
const { shadowRootOptions, elementStyles } = /** @type {TypeofLitElement} */ (
this.constructor
);
const shadowRoot = this.attachShadow(shadowRootOptions);
// @ts-ignore
this.renderOptions.creationScope = shadowRoot;
adoptStyles(shadowRoot, elementStyles);
this.renderOptions.renderBefore ??= shadowRoot.firstChild;
return shadowRoot;
}
};
export const ScopedElementsMixin = dedupeMixin(ScopedElementsMixinImplementation);