rvx
Version:
A signal based rendering library
197 lines (186 loc) • 6.52 kB
TypeScript
/*!
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 { Component } from './rvx.js';
/**
* Check if rvx dom is used in the current context.
*/
declare function isRvxDom(): boolean;
declare const WINDOW_MARKER: unique symbol;
declare const NODE_LENGTH: unique symbol;
declare const NODE_APPEND_HTML_TO: unique symbol;
declare class NodeList {
#private;
constructor(node: Node);
get length(): number;
forEach(cb: (node: Node, index: number, list: NodeList) => void, thisArg?: unknown): void;
[Symbol.iterator](): Iterator<Node>;
values(): Iterator<Node>;
}
declare function htmlEscapeAppendTo(html: string, data: string): string;
declare class NoopEvent {
}
declare class NoopEventTarget {
addEventListener(): void;
removeEventListener(): void;
dispatchEvent(): void;
}
declare class Document extends NoopEventTarget {
get body(): Element | null;
get activeElement(): Element | null;
createTextNode(data: string): Text;
createComment(data: string): NoopComment;
createDocumentFragment(): DocumentFragment;
createElementNS(namespaceURI: string, tagName: string): Element;
createElement(tagName: string): Element;
}
declare class Node extends NoopEventTarget {
#private;
get parentNode(): Node | null;
get firstChild(): Node | null;
get lastChild(): Node | null;
get previousSibling(): Node | null;
get nextSibling(): Node | null;
get childNodes(): NodeList;
[NODE_LENGTH](): number;
[NODE_APPEND_HTML_TO](html: string): string;
contains(node: Node | null): boolean;
hasChildNodes(): boolean;
removeChild(node: Node): Node;
appendChild(node: Node): Node;
insertBefore(node: Node, ref: Node): Node;
replaceChild(node: Node, ref: Node): Node;
remove(): void;
append(...nodes: (Node | string)[]): void;
replaceChildren(...nodes: (Node | string)[]): void;
get textContent(): string;
get outerHTML(): string;
}
interface Node {
nodeType: number;
nodeName: string;
}
declare class DocumentFragment extends Node {
}
declare class NoopComment extends Node {
#private;
constructor(data: string);
get textContent(): string;
set textContent(data: string);
[NODE_APPEND_HTML_TO](html: string): string;
}
declare class Text extends Node {
#private;
constructor(data: string);
get textContent(): string;
set textContent(data: string);
[NODE_APPEND_HTML_TO](html: string): string;
}
declare const XMLNS_HTML = 0;
declare const XMLNS_SVG = 1;
declare const XMLNS_MATHML = 2;
type XMLNS = typeof XMLNS_HTML | typeof XMLNS_SVG | typeof XMLNS_MATHML;
declare function resolveNamespaceURI(uri: string): XMLNS;
declare function isVoidTag(xmlns: XMLNS, name: string): boolean;
declare const ATTR_CHANGED: unique symbol;
interface Attribute {
name: string;
value: string;
stale: boolean;
}
declare class ElementClassList {
#private;
constructor(attrs: Attribute[]);
get length(): number;
get value(): string;
[ATTR_CHANGED](attr: Attribute | null): void;
add(...tokens: string[]): void;
contains(token: string): boolean;
remove(...tokens: string[]): void;
replace(oldToken: string, newToken: string): boolean;
toggle(token: string, force?: boolean): boolean;
values(): IterableIterator<string>;
[Symbol.iterator](): IterableIterator<string>;
}
declare class ElementStyles {
#private;
constructor(attrs: Attribute[]);
get cssText(): string;
[ATTR_CHANGED](attr: Attribute | null): void;
setProperty(name: string, value: string, priority?: "" | "important"): void;
removeProperty(name: string): string;
getPropertyValue(name: string): string;
}
declare class Element extends Node {
#private;
constructor(namespaceURI: string, tagName: string);
get tagName(): string;
get nodeName(): string;
get namespaceURI(): string;
get innerHTML(): string;
set innerHTML(html: string);
get classList(): ElementClassList;
get style(): ElementStyles;
focus(): void;
blur(): void;
setAttribute(name: string, value: string): void;
removeAttribute(name: string): void;
toggleAttribute(name: string, force?: boolean): void;
getAttribute(name: string): string | null;
hasAttribute(name: string): boolean;
[NODE_APPEND_HTML_TO](html: string): string;
}
declare class RawHTML extends Node {
#private;
constructor(html: string);
[NODE_APPEND_HTML_TO](html: string): string;
}
declare class Window extends NoopEventTarget {
window: this;
document: Document;
}
interface Window {
[WINDOW_MARKER]: boolean;
Comment: typeof NoopComment;
CustomEvent: typeof NoopEvent;
Document: typeof Document;
DocumentFragment: typeof DocumentFragment;
Element: typeof Element;
Event: typeof NoopEvent;
Node: typeof Node;
Text: typeof Text;
}
/**
* A global default rvxdom window instance.
*/
declare const WINDOW: Window;
/**
* Render a component to HTML using rvx dom.
*/
declare function renderToString(component: Component): string;
declare function renderToString<P>(component: Component<P>, props: P): string;
/**
* Render a component to HTML using rvx dom.
*
* This injects a new {@link AsyncContext} to wait for rendering to complete.
*/
declare function renderToStringAsync(component: Component): Promise<string>;
declare function renderToStringAsync<P>(component: Component<P>, props: P): Promise<string>;
export { Document, DocumentFragment, Element, ElementClassList, ElementStyles, Node, NodeList, NoopComment, NoopEvent, NoopEventTarget, RawHTML, Text, WINDOW, Window, XMLNS_HTML, XMLNS_MATHML, XMLNS_SVG, htmlEscapeAppendTo, isRvxDom, isVoidTag, renderToString, renderToStringAsync, resolveNamespaceURI };
export type { XMLNS };