UNPKG

abi.js

Version:

[![typescript-icon]][typescript-link] [![license-icon]][license-link] [![status-icon]][status-link] [![ci-icon]][ci-link] [![twitter-icon]][twitter-link]

94 lines (93 loc) 3.83 kB
export type DocType = 'html' | 'xhtml' | 'xml'; export type DocVersion<T extends DocType> = T extends 'html' ? 5 | 4.01 | 4.0 | 3.2 | 2.0 | 1.0 : 1.0 | 1.1; export type DocMode<T extends DocType> = T extends 'html' | 'xhtml' ? 'strict' | 'frameset' | 'transitional' : never; export type Locale = string; export type Attrs = Record<string, string>; export type Props = Record<string, any>; export type EltName = string; export type Translations = Record<Locale, string>; export declare class Doc<T extends DocType = 'html'> { readonly root: Node; readonly type: T; readonly charset: string; readonly version: DocVersion<T>; readonly mode: DocMode<T>; constructor(root: Node, type?: T, charset?: string, version?: DocVersion<typeof type>, mode?: DocMode<typeof type>); render(locale?: Locale): string; } export declare abstract class Node { abstract render(locale?: Locale): string; } export declare abstract class Tag extends Node { readonly name: string; protected nodes: Node[]; constructor(name: string, ...nodes: Node[]); addNodes(nodes: Node[]): this; addNode(node: Node): this; getNodes(): Node[]; getTexts(): Text[]; getElements(): Element[]; abstract open(): string; abstract close(): string; get slot(): Slot; get is_empty(): boolean; render(locale?: Locale): string; renderSlot(locale?: Locale): string; } export declare class Component extends Tag { readonly props: Props; constructor(name: string, props: Props, ...nodes: Node[]); open(): string; close(): string; renderProps(): string; } export declare class Element extends Tag { readonly attrs: Attrs; static readonly ORPHAN: string[]; static readonly INLINE: string[]; constructor(name: EltName, attrs?: Attrs, ...nodes: Node[]); renderAttrs(): string; open(): string; close(): string; get is_orphan(): boolean; get is_paired(): boolean; get is_inline(): boolean; get is_block(): boolean; get is_custom(): boolean; } export declare class Slot extends Node { readonly nodes: Node[]; constructor(nodes: Node[]); get is_empty(): boolean; render(locale?: string | undefined): string; } export declare class Text extends Node { value: string; static locale: Locale; static dictionnary: Record<string, Translations>; constructor(value: string, translations?: Translations); static setTranslations(value: string, translations: Translations): void; static setTranslation(value: string, locale: Locale, translation: string): void; static getTranslation(value: string, locale: Locale): string | undefined; static getTranslations(value: string): Translations; static translate(value: string): Translate; translateTo(locale: Locale): string; render(locale?: Locale): string; } export declare class Translate { protected translations: Translations; constructor(translations: Translations); static from(translations: Translations): Translate; to(locale: Locale): string | undefined; } export declare class Template { protected content: string | TemplateStringsArray; constructor(content: string | TemplateStringsArray); render(locale?: Locale): string; } export declare function doc<T extends DocType = 'html'>(root: Node, type?: T, charset?: string, version?: DocVersion<typeof type>, mode?: DocMode<typeof type>): Doc<T>; export declare function text(value: string, translations?: Translations): Text; export declare function component(name: string, props?: Props, ...nodes: Node[]): Component; export declare function element(name: EltName, attrs?: Attrs, ...nodes: Node[]): Element; export declare function template(content: string | TemplateStringsArray): Template; export declare function render(node: Node, locale?: Locale): string;