UNPKG

rvx

Version:

A signal based rendering library

94 lines (86 loc) 3.31 kB
/*! MIT License Copyright (c) 2025 Max J. Polster Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import { Signal } from './rvx.js'; import { Content } from './rvx.js'; type StartTrigger = "on-connect" | "manual"; type DisposeTrigger = "on-disconnect" | "manual"; interface RvxElementOptions { /** * Shadow root options to use or false to attach content to the element directly. * * By default and when `true`, an open shadow root is attached immediately. */ shadow?: boolean | ShadowRootInit; /** * When to render this element's content. * * + `on-connect` - Default. Render when this element is connected. * + `manual` - Render only when `.start()` is called. */ start?: StartTrigger; /** * When to dispose this element's content. * * + `on-disconnect` - Default. Dispose when this element is disconnected or when `.dispose()` is called. * + `manual` - Dispose only when `.dispose()` is called. */ dispose?: DisposeTrigger; } declare const moduleEnv: typeof globalThis; declare abstract class RvxElement extends moduleEnv.HTMLElement { #private; static observedAttributes?: string[]; constructor(options?: RvxElementOptions); /** * Called to render the content of this element. * * @returns The content to attach to this element or the shadow root if it exists. */ abstract render(): Content; /** * Get a signal that reflects an attribute value. * * + `null` represents a missing attribute. * + This signal is only updated if the name is part of the static `observedAttributes` array. * + Updating the signal value will also update or remove the attribute. * + This signal will be kept alive until neither this element nor the signal is referenced anymore. * * @param name The attribute name. * @returns The signal. */ reflect(name: string): Signal<string | null>; /** * Manually initialize this element. * * This has no effect if the element is already initialized. */ start(): void; /** * Manually dispose this element. * * This will leave rendered content as is. */ dispose(): void; connectedCallback(): void; disconnectedCallback(): void; attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void; } export { RvxElement }; export type { DisposeTrigger, RvxElementOptions, StartTrigger };