import { IEventEmitter, IEventListenerSubscription } from '@breadstone/mosaik-elements'; import { LitElement, type PropertyDeclaration } from 'lit'; import { CSSResultGroup } from '../../../Dom/Css'; import type { IPropertyChangedEventDetail } from '../../events'; import { FlowDirection } from '../../Types/FlowDirection'; import type { IConnectedCallback } from './Interfaces/IConnectedCallback'; import type { IDisconnectedCallback } from './Interfaces/IDisconnectedCallback'; export type UnpackCustomEvent = T extends CustomEvent ? U : unknown; /** * Custom Element - The foundational base class for all Mosaik web components. * * @description * CustomElement extends LitElement and provides the core infrastructure for all Mosaik components. * It establishes fundamental patterns including lifecycle management, event handling, style adoption, * internationalization (i18n) support, and template part querying. This abstract class serves as the * root of the component hierarchy and provides essential features like custom style injection via * shadow DOM, automatic event subscription cleanup, property change tracking, and bidirectional text * support. All Mosaik components inherit from this base class either directly or through specialized * intermediate base classes. * * @name CustomElement * @category Abstract Elements * * @slot style - Custom styles injection slot for shadow DOM styling escape hatch * * @fires connected {ConnectedEvent} - Emitted when the element is connected to the DOM * @fires disconnected {DisconnectedEvent} - Emitted when the element is disconnected from the DOM * @fires changed {PropertyChangedEvent} - Emitted when any attribute changes before update * * @example * Extending CustomElement to create a new component: * ```typescript * export class MyElement extends CustomElement { * constructor() { * super(); * } * protected override render() { * return html`
My Component
`; * } * } * ``` * * @example * Injecting custom styles via the style slot: * ```html * * *

Custom Title

*
* ``` * * @example * Using lifecycle events: * ```typescript * element.connected.on(() => { * console.log('Element connected to DOM'); * }); * element.changed.on(({ propertyName, oldValue, newValue }) => { * console.log(`Property ${propertyName} changed from ${oldValue} to ${newValue}`); * }); * ``` * * @example * Querying template parts: * ```typescript * protected override onApplyTemplate(): void { * const header = this.getTemplatePart('header'); * const items = this.getTemplateParts('item'); * } * ``` * * @abstract * @public */ export declare class CustomElement extends LitElement implements IConnectedCallback, IDisconnectedCallback { /** * The slot name used for custom styles injection. * Users can inject custom styles via ``. * * @public * @readonly */ static get CUSTOM_STYLES_SLOT(): string; private readonly _connected; private readonly _disconnected; private readonly _changed; private readonly _subscriptions; private _dir; private _lang; /** * Constructs a new instance of the `CustomElement` class. * * @public */ constructor(); /** * Gets or sets the `dir` property. * * @public * @override * @attr dir */ get dir(): FlowDirection; set dir(value: FlowDirection); /** * Gets or sets the `lang` property. * * @public * @override * @attr lang */ get lang(): string; set lang(value: string); /** * Called when the element is connected to the DOM. * Provides reference to `IEventEmitter` as event argument. * * @public * @hidden * @eventProperty * @readonly */ get connected(): IEventEmitter; /** * Called when the element is disconnected from the DOM. * Provides reference to `IEventEmitter` as event argument. * * @public * @hidden * @eventProperty * @readonly */ get disconnected(): IEventEmitter; /** * Called when the element will be updated. * Provides reference to `IEventEmitter` as event argument. * * @public * @hidden * @eventProperty * @readonly */ get changed(): IEventEmitter; /** * @public * @override * @hidden */ connectedCallback(): void; /** * @public * @override * @hidden */ disconnectedCallback(): void; /** * @public * @override * @hidden */ attributeChangedCallback(name: string, old: string | null, value: string | null): void; /** * Adopts the specified styles. * * @public * @hidden * @param styles - The styles to adopt. */ adoptStyle(styles: CSSResultGroup): void; /** * Adds an event listener. * The listener will be removed when the element is disconnected from the DOM. * * @public * @hidden */ on(event: TEvent, listener: (this: HTMLElement, event: HTMLElementEventMap[TEvent]) => unknown, options?: boolean | AddEventListenerOptions): IEventListenerSubscription; /** * Removes an event listener. * * @public * @hidden */ off(subscription: IEventListenerSubscription): void; /** * @hidden */ off(event: TEvent, listener: (this: HTMLElement, event: HTMLElementEventMap[TEvent]) => unknown): void; /** * Emits a custom event with more convenient defaults. * * @public * @hidden */ emit>(event: TEvent, eventInitDict?: CustomEventInit): boolean; /** * @hidden */ emit>(type: keyof HTMLElementEventMap, eventInitDict?: CustomEventInit): boolean; /** * @public * @override * @hidden */ requestUpdate(name?: keyof this, oldValue?: unknown, options?: PropertyDeclaration): void; /** * @protected * @override */ protected firstUpdated(changedProperties: Map): void; /** * @protected * @override */ protected update(changedProperties: Map): void; /** * @protected * @override */ protected willUpdate(changedProperties: Map): void; /** * A method that will be called when the element template is applied. * In this method are the element children available. * * @protected * @virtual */ protected onApplyTemplate(): void; /** * Adopts custom styles from the light DOM into the shadow DOM. * * This method enables the "styling escape hatch" pattern, allowing developers * to inject custom styles into a component's shadow DOM via a slotted style element: * * @example * ```html * * *

Custom Title

*
* ``` * * @remarks * - Only `