lambda.html
Version:
Lambda.html is a TypeScript-based HTML builder framework that leverages functional programming principles to provide a declarative, composable, and extensible approach for building dynamic web interfaces. Designed for robustness and maintainability, it in
160 lines (159 loc) • 5.97 kB
TypeScript
import { HTMX } from "./htmx.js";
export type Thunk<T> = () => T;
export type View = Tag | string | View[];
export declare class Tag {
el: string;
child: View;
id?: string;
class?: string;
style?: string;
attributes: Record<string, string>;
htmx?: HTMX;
toggles?: string[];
constructor(element: string, child?: View);
setId(id?: string): Tag;
setClass(c?: string): Tag;
addClass(c: string): Tag;
setStyle(style?: string): Tag;
addAttribute(key: string, value: string): Tag;
setHtmx(htmx?: HTMX): Tag;
setToggles(toggles?: string[]): Tag;
}
export declare function Empty(): View;
export declare function El(el: string, child?: View): Tag;
export declare function Div(child?: View): Tag;
export declare function Main(child?: View): Tag;
export declare function Header(child?: View): Tag;
export declare function Footer(child?: View): Tag;
export declare function Section(child?: View): Tag;
export declare function Article(child?: View): Tag;
export declare function P(child?: View): Tag;
export declare class InputTag extends Tag {
type?: string;
placeholder?: string;
name?: string;
value?: string;
accept?: string;
min?: number;
max?: number;
setType(type?: string): InputTag;
setPlaceholder(placeholder?: string): InputTag;
setName(name?: string): InputTag;
setValue(value?: string): InputTag;
setAccept(accept?: string): InputTag;
setMin(min?: number): InputTag;
setMax(max?: number): InputTag;
}
export declare function Input(child?: View): InputTag;
export declare class TextareaTag extends Tag {
placeholder?: string;
name?: string;
rows?: number;
cols?: number;
setPlaceholder(placeholder?: string): TextareaTag;
setName(name?: string): TextareaTag;
setRows(rows?: number): TextareaTag;
setCols(cols?: number): TextareaTag;
}
export declare function Textarea(child?: View): TextareaTag;
export declare class ButtonTag extends Tag {
type?: string;
setType(type?: string): ButtonTag;
}
export declare function Button(child?: View): ButtonTag;
export declare class LabelTag extends Tag {
for?: string;
setFor(forId?: string): LabelTag;
}
export declare function Label(child?: View): LabelTag;
export declare class AnchorTag extends Tag {
href?: string;
target?: string;
setHref(href?: string): AnchorTag;
setTarget(target?: string): AnchorTag;
}
export declare function A(child?: View): AnchorTag;
export declare class FormTag extends Tag {
action?: string;
method?: string;
setAction(action?: string): FormTag;
setMethod(method?: string): FormTag;
}
export declare function Form(child?: View): FormTag;
export declare class ImgTag extends Tag {
src?: string;
alt?: string;
width?: string;
height?: string;
setSrc(src?: string): ImgTag;
setAlt(alt?: string): ImgTag;
setWidth(width?: string): ImgTag;
setHeight(height?: string): ImgTag;
}
export declare function Img(child?: View): ImgTag;
interface Option {
value: string;
text: string;
selected: boolean;
}
export declare class SelectTag extends Tag {
name?: string;
options?: Option[];
setName(name?: string): SelectTag;
setOptions(options?: Option[]): SelectTag;
}
export declare function Select(child?: View): SelectTag;
export declare class OptionTag extends Tag {
value?: string;
selected: boolean;
setValue(value: string): this;
setSelected(selected?: boolean): this;
}
export declare function Option(child?: View): OptionTag;
export declare class VideoTag extends Tag {
width?: number;
height?: number;
controls?: boolean;
src?: string;
setWidth(width: number): VideoTag;
setHeight(height: number): VideoTag;
setControls(enabled?: boolean): VideoTag;
setSrc(src: string): VideoTag;
}
export declare function Video(child?: View): VideoTag;
export declare function HTML(child?: View): Tag;
export declare function Head(child?: View): Tag;
export declare function Body(child?: View): Tag;
export declare function Template(): Tag;
export declare function Script(js: string): Tag;
export declare function H1(child?: View): Tag;
export declare function H2(child?: View): Tag;
export declare function H3(child?: View): Tag;
export declare function H4(child?: View): Tag;
export declare function Span(child?: View): Tag;
export declare function Ul(child?: View): Tag;
export declare function Ol(child?: View): Tag;
export declare function Li(child?: View): Tag;
export declare function Table(child?: View): Tag;
export declare function Thead(child?: View): Tag;
export declare function Tbody(child?: View): Tag;
export declare function Tr(child?: View): Tag;
export declare function Th(child?: View): Tag;
export declare function Td(child?: View): Tag;
export declare function Hr(child?: View): Tag;
export type OverlayPosition = 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'left' | 'right' | 'center';
export declare function Overlay(content: View, overlay: View, position?: OverlayPosition): Tag;
export declare function IfThenElse(condition: boolean, thenBranch: Thunk<View>, elseBranch: Thunk<View>): View;
export declare function IfThen(condition: boolean, then: Thunk<View>): View;
type Case = {
condition: boolean;
component: Thunk<View>;
};
export declare function SwitchCase(cases: Case[], defaultView?: Thunk<View>): View;
export declare function ForEach<T>(views: Iterable<T>, renderItem: (item: T) => View): View;
export declare function ForEach1<T>(views: Iterable<T>, renderItem: (item: T, index: number) => View): View;
export declare function ForEach2(high: number, renderItem: (index: number) => View): View;
export declare function ForEach3(low: number, high: number, renderItem: (index: number) => View): View;
export declare function Repeat(times: number, content: Thunk<View>): View;
export declare function render(view: View): string;
export {};