package.lit-element.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scoped-elements Show documentation
Show all versions of scoped-elements Show documentation
Allows to auto define custom elements scoping them
The newest version!
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} LitElementConstructor
* @typedef {import('@open-wc/dedupe-mixin').Constructor} 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);