vdom

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package vdom provides the Virtual DOM implementation for Vango.

The Virtual DOM (VDOM) provides an in-memory representation of the UI that can be efficiently diffed to produce minimal DOM updates. In Vango's server-driven architecture, the VDOM lives on the server and diffs produce binary patches sent to the client.

Core Types

VNode is the fundamental building block representing elements, text, fragments, components, and raw HTML. Props holds attributes and event handlers. Attr and EventHandler are used to build Props.

Element API

Elements are created using variadic factory functions:

Div(Class("card"), ID("main"),
    H1(Text("Title")),
    P(Text("Content")),
    OnClick(handler),
)

Diffing

The Diff function compares two VNode trees and returns a slice of Patch operations. Keyed reconciliation is used when children have Key attributes.

Hydration

AssignHIDs walks the tree and assigns hydration IDs to interactive elements (those with event handlers). These IDs link server VNodes to client DOM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignAllHIDs

func AssignAllHIDs(node *VNode, gen *HIDGenerator)

AssignAllHIDs assigns HIDs to ALL element nodes, not just interactive ones. This is useful for debugging or when all elements need to be addressable.

func AssignHIDs

func AssignHIDs(node *VNode, gen *HIDGenerator)

AssignHIDs walks the tree and assigns HIDs to interactive elements. An element is interactive if it has event handlers (props starting with "on"). Elements containing text children also get HIDs so text updates can target them.

func ClearHIDs

func ClearHIDs(node *VNode)

ClearHIDs removes all HIDs from the tree.

func CollectHIDs

func CollectHIDs(node *VNode) map[string]*VNode

CollectHIDs returns a map of HID to VNode for all nodes with HIDs.

func CopyHIDs

func CopyHIDs(src, dst *VNode) bool

CopyHIDs copies HIDs from the source tree to the destination tree. This is useful when diffing to preserve HIDs between renders. Returns true if all HIDs were successfully copied.

func CountInteractive

func CountInteractive(node *VNode) int

CountInteractive returns the number of interactive elements in the tree.

func EffectiveAttrs

func EffectiveAttrs(node *VNode) map[string]string

EffectiveAttrs returns the string attributes that should be present on the DOM for the given node.

This includes: - regular attributes (excluding internal props, event handlers, etc.) - derived attributes for event interception (`data-ve` + modifier attrs) - derived attributes for hooks (`data-hook` + `data-hook-config`) - derived attributes for optimistic updates (`data-optimistic`)

It intentionally omits `data-hid`, which is managed separately via node.HID.

It may return nil when there are no effective attributes.

func EffectiveAttrsWithPolicy

func EffectiveAttrsWithPolicy(node *VNode, policy URLPolicy) map[string]string

EffectiveAttrsWithPolicy returns EffectiveAttrs using the provided URL policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

It may return nil when there are no effective attributes.

func EnableDevWarnings

func EnableDevWarnings(enabled bool)

EnableDevWarnings controls whether vdom emits development warnings for potentially expensive or footgun-prone helpers.

This is intended to be toggled by the server/runtime when DevMode is enabled.

func IsIsland

func IsIsland(node *VNode) bool

IsIsland reports whether the node is an island boundary.

func IsIslandWithPolicy

func IsIslandWithPolicy(node *VNode, policy URLPolicy) bool

IsIslandWithPolicy reports whether the node is an island boundary using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func IsOpaque

func IsOpaque(node *VNode) bool

IsOpaque reports whether the node is an opaque boundary (island or wasm).

func IsOpaqueWithPolicy

func IsOpaqueWithPolicy(node *VNode, policy URLPolicy) bool

IsOpaqueWithPolicy reports whether the node is an opaque boundary using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func IsVoidElement

func IsVoidElement(tag string) bool

IsVoidElement returns true if the tag is a void element.

func IsWasm

func IsWasm(node *VNode) bool

IsWasm reports whether the node is a WASM boundary.

func IsWasmWithPolicy

func IsWasmWithPolicy(node *VNode, policy URLPolicy) bool

IsWasmWithPolicy reports whether the node is a WASM boundary using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func IslandID

func IslandID(node *VNode) (string, bool)

IslandID returns the island identifier if present.

func IslandIDWithPolicy

func IslandIDWithPolicy(node *VNode, policy URLPolicy) (string, bool)

IslandIDWithPolicy returns the island identifier if present using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func IslandModule

func IslandModule(node *VNode) (string, bool)

IslandModule returns the module path for an island, if present.

func IslandModuleWithPolicy

func IslandModuleWithPolicy(node *VNode, policy URLPolicy) (string, bool)

IslandModuleWithPolicy returns the module path for an island, if present, using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func IslandProps

func IslandProps(node *VNode) (string, bool)

IslandProps returns the JSON props string for an island, if present.

func IslandPropsWithPolicy

func IslandPropsWithPolicy(node *VNode, policy URLPolicy) (string, bool)

IslandPropsWithPolicy returns the JSON props string for an island, if present, using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func OpaqueKind

func OpaqueKind(node *VNode) string

OpaqueKind returns the opaque boundary kind for a node: "island", "wasm", or "".

func OpaqueKindWithPolicy

func OpaqueKindWithPolicy(node *VNode, policy URLPolicy) string

OpaqueKindWithPolicy returns the opaque boundary kind for a node using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func SanitizeAttrValue

func SanitizeAttrValue(key, raw string) (string, bool)

SanitizeAttrValue applies URL scheme filtering for URL-bearing attributes and enforces srcdoc policy. Non-URL attributes are returned unchanged. Returns ok=false when the attribute should be omitted.

func SanitizeAttrValueWithPolicy

func SanitizeAttrValueWithPolicy(policy URLPolicy, key, raw string) (string, bool)

SanitizeAttrValueWithPolicy applies URL scheme filtering for URL-bearing attributes and enforces srcdoc policy. Non-URL attributes are returned unchanged. Returns ok=false when the attribute should be omitted. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func ValidateRuntimeUnsafeBootstrap added in v0.2.0

func ValidateRuntimeUnsafeBootstrap(cfg bootstrap.Config, perms RuntimeUnsafePermissions) error

func WasmID

func WasmID(node *VNode) (string, bool)

WasmID returns the WASM component identifier if present.

func WasmIDWithPolicy

func WasmIDWithPolicy(node *VNode, policy URLPolicy) (string, bool)

WasmIDWithPolicy returns the WASM component identifier if present using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func WasmModule

func WasmModule(node *VNode) (string, bool)

WasmModule returns the module path for a WASM component, if present.

func WasmModuleWithPolicy

func WasmModuleWithPolicy(node *VNode, policy URLPolicy) (string, bool)

WasmModuleWithPolicy returns the module path for a WASM component, if present, using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

func WasmProps

func WasmProps(node *VNode) (string, bool)

WasmProps returns the JSON props string for a WASM component, if present.

func WasmPropsWithPolicy

func WasmPropsWithPolicy(node *VNode, policy URLPolicy) (string, bool)

WasmPropsWithPolicy returns the JSON props string for a WASM component, if present, using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

Types

type Attr

type Attr struct {
	Key   string
	Value any
}

Attr represents a single attribute.

func Accept

func Accept(types string) Attr

Accept sets the accept attribute.

func AccessKey

func AccessKey(key string) Attr

AccessKey sets the accesskey attribute.

func Action

func Action(url string) Attr

Action sets the action attribute.

func Allow

func Allow(value string) Attr

Allow sets the allow attribute.

func Allowfullscreen

func Allowfullscreen(allowfullscreen ...bool) Attr

Allowfullscreen sets the allowfullscreen attribute.

func Alt

func Alt(text string) Attr

Alt sets the alt attribute.

func AriaAtomic

func AriaAtomic(atomic bool) Attr

AriaAtomic sets the aria-atomic attribute.

func AriaBusy

func AriaBusy(busy bool) Attr

AriaBusy sets the aria-busy attribute.

func AriaControls

func AriaControls(id string) Attr

AriaControls sets the aria-controls attribute.

func AriaCurrent

func AriaCurrent(value string) Attr

AriaCurrent sets the aria-current attribute.

func AriaDescribedBy

func AriaDescribedBy(id string) Attr

AriaDescribedBy sets the aria-describedby attribute.

func AriaDisabled

func AriaDisabled(disabled bool) Attr

AriaDisabled sets the aria-disabled attribute.

func AriaExpanded

func AriaExpanded(expanded bool) Attr

AriaExpanded sets the aria-expanded attribute.

func AriaHasPopup

func AriaHasPopup(value string) Attr

AriaHasPopup sets the aria-haspopup attribute.

func AriaHidden

func AriaHidden(hidden bool) Attr

AriaHidden sets the aria-hidden attribute.

func AriaLabel

func AriaLabel(label string) Attr

AriaLabel sets the aria-label attribute.

func AriaLabelledBy

func AriaLabelledBy(id string) Attr

AriaLabelledBy sets the aria-labelledby attribute.

func AriaLive

func AriaLive(mode string) Attr

AriaLive sets the aria-live attribute.

func AriaModal

func AriaModal(modal bool) Attr

AriaModal sets the aria-modal attribute.

func AriaPressed

func AriaPressed(pressed string) Attr

AriaPressed sets the aria-pressed attribute.

func AriaSelected

func AriaSelected(selected bool) Attr

AriaSelected sets the aria-selected attribute.

func AriaValueMax

func AriaValueMax(value float64) Attr

AriaValueMax sets the aria-valuemax attribute.

func AriaValueMin

func AriaValueMin(value float64) Attr

AriaValueMin sets the aria-valuemin attribute.

func AriaValueNow

func AriaValueNow(value float64) Attr

AriaValueNow sets the aria-valuenow attribute.

func Async

func Async(async ...bool) Attr

Async sets the async attribute for script elements.

func AttrIf

func AttrIf(condition bool, a Attr) Attr

AttrIf adds any attribute conditionally.

func Autocomplete

func Autocomplete(value string) Attr

Autocomplete sets the autocomplete attribute.

func Autofocus

func Autofocus(autofocus ...bool) Attr

Autofocus sets the autofocus attribute.

func Autoplay

func Autoplay(autoplay ...bool) Attr

Autoplay sets the autoplay attribute.

func Capture

func Capture(mode string) Attr

Capture sets the capture attribute.

func Charset

func Charset(charset string) Attr

Charset sets the charset attribute.

func Checked

func Checked(checked ...bool) Attr

Checked sets the checked attribute.

func Class

func Class(classes ...string) Attr

Class sets the class attribute, joining multiple classes with spaces.

func ClassIf

func ClassIf(condition bool, class string) Attr

ClassIf adds a class conditionally.

func Classes

func Classes(classes ...any) Attr

Classes merges multiple class values. Accepts string, []string, and map[string]bool.

func Cols

func Cols(n int) Attr

Cols sets the cols attribute.

func Colspan

func Colspan(n int) Attr

Colspan sets the colspan attribute.

func Content

func Content(content string) Attr

Content sets the content attribute.

func ContentEditable

func ContentEditable(editable bool) Attr

ContentEditable sets the contenteditable attribute.

func Controls

func Controls(controls ...bool) Attr

Controls sets the controls attribute.

func Crossorigin

func Crossorigin(value string) Attr

Crossorigin sets the crossorigin attribute.

func D added in v0.2.0

func D(value string) Attr

D sets the SVG path d attribute.

func Data

func Data(key, value string) Attr

Data creates a data-* attribute. This is the primary way to add data attributes. Example: Data("id", "123") → data-id="123"

func DataAttr

func DataAttr(key, value string) Attr

DataAttr is an alias for Data(). Provided for backwards compatibility.

func Decoding

func Decoding(mode string) Attr

Decoding sets the decoding attribute.

func Defer_

func Defer_(deferAttr ...bool) Attr

Defer_ sets the defer attribute for script elements.

func Dir

func Dir(dir string) Attr

Dir sets the dir attribute.

func Disabled

func Disabled(disabled ...bool) Attr

Disabled sets/unsets the disabled boolean attribute. Disabled() and Disabled(true) set it; Disabled(false) omits/removes it.

func Download

func Download(filename ...string) Attr

Download sets the download attribute.

func Draggable

func Draggable() Attr

Draggable sets the draggable attribute.

func Enctype

func Enctype(enctype string) Attr

Enctype sets the enctype attribute.

func Enterkeyhint

func Enterkeyhint(hint string) Attr

Enterkeyhint sets the enterkeyhint attribute.

func Fill added in v0.2.0

func Fill(value string) Attr

Fill sets the SVG fill attribute.

func For

func For(id string) Attr

For sets the for attribute (for labels).

func FormAttr

func FormAttr(id string) Attr

FormAttr sets the form attribute (to associate with a form by id).

func Formaction

func Formaction(url string) Attr

Formaction sets the formaction attribute.

func HeadersAttr

func HeadersAttr(ids string) Attr

Headers sets the headers attribute.

func Height

func Height(h int) Attr

Height sets the height attribute.

func Hidden

func Hidden(hidden ...bool) Attr

Hidden sets the hidden attribute.

func Href

func Href(url string) Attr

Href sets the href attribute.

func Hreflang

func Hreflang(lang string) Attr

Hreflang sets the hreflang attribute.

func HttpEquiv

func HttpEquiv(value string) Attr

HttpEquiv sets the http-equiv attribute.

func ID

func ID(id string) Attr

ID sets the id attribute.

func Inputmode

func Inputmode(mode string) Attr

Inputmode sets the inputmode attribute.

func Integrity

func Integrity(value string) Attr

Integrity sets the integrity attribute for subresource integrity.

func Key

func Key(key any) Attr

Key creates a key attribute for reconciliation. The key is converted to a string using fmt.Sprintf.

func Lang

func Lang(lang string) Attr

Lang sets the lang attribute.

func List

func List(id string) Attr

List sets the list attribute (for input with datalist).

func Loading

func Loading(mode string) Attr

Loading sets the loading attribute.

func Loop

func Loop(loop ...bool) Attr

Loop sets the loop attribute.

func Max

func Max(value string) Attr

Max sets the max attribute.

func MaxLength

func MaxLength(n int) Attr

MaxLength sets the maxlength attribute.

func Method

func Method(method string) Attr

Method sets the method attribute.

func Min

func Min(value string) Attr

Min sets the min attribute.

func MinLength

func MinLength(n int) Attr

MinLength sets the minlength attribute.

func Multiple

func Multiple(multiple ...bool) Attr

Multiple sets the multiple attribute.

func MutedAttr

func MutedAttr(muted ...bool) Attr

Muted sets the muted attribute.

func Name

func Name(name string) Attr

Name sets the name attribute.

func Novalidate

func Novalidate(novalidate ...bool) Attr

Novalidate sets the novalidate attribute.

func Open

func Open(open ...bool) Attr

Open sets the open attribute (for details, dialog).

func Pattern

func Pattern(pattern string) Attr

Pattern sets the pattern attribute.

func Placeholder

func Placeholder(text string) Attr

Placeholder sets the placeholder attribute.

func Playsinline

func Playsinline(playsinline ...bool) Attr

Playsinline sets the playsinline attribute.

func Poster

func Poster(url string) Attr

Poster sets the poster attribute.

func Preload

func Preload(mode string) Attr

Preload sets the preload attribute.

func Readonly

func Readonly(readonly ...bool) Attr

Readonly sets the readonly attribute.

func Rel

func Rel(rel string) Attr

Rel sets the rel attribute.

func Required

func Required(required ...bool) Attr

Required sets the required attribute.

func Role

func Role(role string) Attr

Role sets the role attribute.

func Rows

func Rows(n int) Attr

Rows sets the rows attribute.

func Rowspan

func Rowspan(n int) Attr

Rowspan sets the rowspan attribute.

func Sandbox

func Sandbox(value string) Attr

Sandbox sets the sandbox attribute.

func Scope

func Scope(scope string) Attr

Scope sets the scope attribute.

func Selected

func Selected(selected ...bool) Attr

Selected sets the selected attribute.

func SizesAttr

func SizesAttr(sizes string) Attr

Sizes sets the sizes attribute.

func Spellcheck

func Spellcheck(check bool) Attr

Spellcheck sets the spellcheck attribute.

func Src

func Src(url string) Attr

Src sets the src attribute.

func Srcset

func Srcset(srcset string) Attr

Srcset sets the srcset attribute.

func Step

func Step(value string) Attr

Step sets the step attribute.

func Stroke added in v0.2.0

func Stroke(value string) Attr

Stroke sets the SVG stroke attribute.

func StrokeLinecap added in v0.2.0

func StrokeLinecap(value string) Attr

StrokeLinecap sets the SVG stroke-linecap attribute.

func StrokeLinejoin added in v0.2.0

func StrokeLinejoin(value string) Attr

StrokeLinejoin sets the SVG stroke-linejoin attribute.

func StrokeWidth added in v0.2.0

func StrokeWidth(value any) Attr

StrokeWidth sets the SVG stroke-width attribute.

func StyleAttr

func StyleAttr(style string) Attr

StyleAttr sets the style attribute (named to avoid conflict with Style element).

func TabIndex

func TabIndex(index int) Attr

TabIndex sets the tabindex attribute.

func Target

func Target(target string) Attr

Target sets the target attribute.

func TestID

func TestID(id string) Attr

TestID sets the data-testid attribute for testing hooks.

func TitleAttr

func TitleAttr(title string) Attr

TitleAttr sets the title attribute (named to avoid conflict with Title element).

func Type

func Type(t string) Attr

Type sets the type attribute.

func Value

func Value(value string) Attr

Value sets the value attribute.

func ViewBox added in v0.2.0

func ViewBox(value string) Attr

ViewBox sets the SVG viewBox attribute.

func Width

func Width(w int) Attr

Width sets the width attribute.

func Wrap

func Wrap(mode string) Attr

Wrap sets the wrap attribute.

func (Attr) IsEmpty

func (a Attr) IsEmpty() bool

IsEmpty returns true if this is an empty/nil attribute.

type Case

type Case[T comparable] struct {
	Value     T
	Node      *VNode
	IsDefault bool
}

Case represents a case in a Switch statement.

func Case_

func Case_[T comparable](value T, node *VNode) Case[T]

Case_ creates a case for Switch.

func Default

func Default[T comparable](node *VNode) Case[T]

Default creates a default case for Switch.

type ChildrenProvider

type ChildrenProvider interface {
	ChildrenNodes() []*VNode
}

ChildrenProvider exposes child VNodes to the VDOM layer. This is intended for framework integration only.

type Component

type Component interface {
	Render() *VNode
}

Component is anything that can render to a VNode.

func Func

func Func(render func() *VNode) Component

Func creates a component from a render function.

type EventHandler

type EventHandler struct {
	Event   string // "onclick", "oninput", etc.
	Handler any    // Function to call
}

EventHandler represents an event handler.

func OnAbort

func OnAbort(handler any) EventHandler

OnAbort handles abort events.

func OnAnimationCancel

func OnAnimationCancel(handler any) EventHandler

OnAnimationCancel handles animationcancel events.

func OnAnimationEnd

func OnAnimationEnd(handler any) EventHandler

OnAnimationEnd handles animationend events.

func OnAnimationIteration

func OnAnimationIteration(handler any) EventHandler

OnAnimationIteration handles animationiteration events.

func OnAnimationStart

func OnAnimationStart(handler any) EventHandler

OnAnimationStart handles animationstart events.

func OnBlur

func OnBlur(handler any) EventHandler

OnBlur handles blur events.

func OnCanPlay

func OnCanPlay(handler any) EventHandler

OnCanPlay handles canplay events (can begin playback).

func OnCanPlayThrough

func OnCanPlayThrough(handler any) EventHandler

OnCanPlayThrough handles canplaythrough events (can play without buffering).

func OnChange

func OnChange(handler any) EventHandler

OnChange handles change events (fired when value is committed).

func OnClick

func OnClick(handler any) EventHandler

OnClick handles click events.

func OnContextMenu

func OnContextMenu(handler any) EventHandler

OnContextMenu handles contextmenu (right-click) events.

func OnCopy

func OnCopy(handler any) EventHandler

OnCopy handles copy events.

func OnCut

func OnCut(handler any) EventHandler

OnCut handles cut events.

func OnDblClick

func OnDblClick(handler any) EventHandler

OnDblClick handles double-click events.

func OnDrag

func OnDrag(handler any) EventHandler

OnDrag handles drag events.

func OnDragEnd

func OnDragEnd(handler any) EventHandler

OnDragEnd handles dragend events.

func OnDragEnter

func OnDragEnter(handler any) EventHandler

OnDragEnter handles dragenter events.

func OnDragLeave

func OnDragLeave(handler any) EventHandler

OnDragLeave handles dragleave events.

func OnDragOver

func OnDragOver(handler any) EventHandler

OnDragOver handles dragover events.

func OnDragStart

func OnDragStart(handler any) EventHandler

OnDragStart handles dragstart events.

func OnDrop

func OnDrop(handler any) EventHandler

OnDrop handles drop events.

func OnDurationChange

func OnDurationChange(handler any) EventHandler

OnDurationChange handles durationchange events.

func OnEmptied

func OnEmptied(handler any) EventHandler

OnEmptied handles emptied events (media emptied).

func OnEnded

func OnEnded(handler any) EventHandler

OnEnded handles ended events (media playback finished).

func OnError

func OnError(handler any) EventHandler

OnError handles error events.

func OnFocus

func OnFocus(handler any) EventHandler

OnFocus handles focus events.

func OnFocusIn

func OnFocusIn(handler any) EventHandler

OnFocusIn handles focusin events (bubbles, unlike focus).

func OnFocusOut

func OnFocusOut(handler any) EventHandler

OnFocusOut handles focusout events (bubbles, unlike blur).

func OnInput

func OnInput(handler any) EventHandler

OnInput handles input events (fired when value changes).

func OnInvalid

func OnInvalid(handler any) EventHandler

OnInvalid handles invalid events (form validation).

func OnKeyDown

func OnKeyDown(handler any) EventHandler

OnKeyDown handles keydown events.

func OnKeyPress

func OnKeyPress(handler any) EventHandler

OnKeyPress handles keypress events (deprecated, but still supported).

func OnKeyUp

func OnKeyUp(handler any) EventHandler

OnKeyUp handles keyup events.

func OnLoad

func OnLoad(handler any) EventHandler

OnLoad handles load events.

func OnLoadStart

func OnLoadStart(handler any) EventHandler

OnLoadStart handles loadstart events (loading begins).

func OnLoadedData

func OnLoadedData(handler any) EventHandler

OnLoadedData handles loadeddata events (first frame loaded).

func OnLoadedMetadata

func OnLoadedMetadata(handler any) EventHandler

OnLoadedMetadata handles loadedmetadata events (metadata loaded).

func OnMouseDown

func OnMouseDown(handler any) EventHandler

OnMouseDown handles mousedown events.

func OnMouseEnter

func OnMouseEnter(handler any) EventHandler

OnMouseEnter handles mouseenter events.

func OnMouseLeave

func OnMouseLeave(handler any) EventHandler

OnMouseLeave handles mouseleave events.

func OnMouseMove

func OnMouseMove(handler any) EventHandler

OnMouseMove handles mousemove events.

func OnMouseOut

func OnMouseOut(handler any) EventHandler

OnMouseOut handles mouseout events.

func OnMouseOver

func OnMouseOver(handler any) EventHandler

OnMouseOver handles mouseover events.

func OnMouseUp

func OnMouseUp(handler any) EventHandler

OnMouseUp handles mouseup events.

func OnPaste

func OnPaste(handler any) EventHandler

OnPaste handles paste events.

func OnPause

func OnPause(handler any) EventHandler

OnPause handles pause events (media is paused).

func OnPlay

func OnPlay(handler any) EventHandler

OnPlay handles play events (media starts playing).

func OnPlaying

func OnPlaying(handler any) EventHandler

OnPlaying handles playing events (playback resumed after pausing/buffering).

func OnPointerCancel

func OnPointerCancel(handler any) EventHandler

OnPointerCancel handles pointercancel events.

func OnPointerDown

func OnPointerDown(handler any) EventHandler

OnPointerDown handles pointerdown events.

func OnPointerEnter

func OnPointerEnter(handler any) EventHandler

OnPointerEnter handles pointerenter events.

func OnPointerLeave

func OnPointerLeave(handler any) EventHandler

OnPointerLeave handles pointerleave events.

func OnPointerMove

func OnPointerMove(handler any) EventHandler

OnPointerMove handles pointermove events.

func OnPointerUp

func OnPointerUp(handler any) EventHandler

OnPointerUp handles pointerup events.

func OnProgress

func OnProgress(handler any) EventHandler

OnProgress handles progress events (loading progress).

func OnRateChange

func OnRateChange(handler any) EventHandler

OnRateChange handles ratechange events (playback rate changed).

func OnReset

func OnReset(handler any) EventHandler

OnReset handles form reset events.

func OnScroll

func OnScroll(handler any) EventHandler

OnScroll handles scroll events.

func OnScrollEnd

func OnScrollEnd(handler any) EventHandler

OnScrollEnd handles scrollend events.

func OnSeeked

func OnSeeked(handler any) EventHandler

OnSeeked handles seeked events (seek operation completed).

func OnSeeking

func OnSeeking(handler any) EventHandler

OnSeeking handles seeking events (seek operation started).

func OnSelect

func OnSelect(handler any) EventHandler

OnSelect handles select events (text selection).

func OnStalled

func OnStalled(handler any) EventHandler

OnStalled handles stalled events (fetching media data stalled).

func OnSubmit

func OnSubmit(handler any) EventHandler

OnSubmit handles form submit events.

func OnSuspend

func OnSuspend(handler any) EventHandler

OnSuspend handles suspend events (loading suspended).

func OnTimeUpdate

func OnTimeUpdate(handler any) EventHandler

OnTimeUpdate handles timeupdate events (playback position changed).

func OnToggle

func OnToggle(handler any) EventHandler

OnToggle handles toggle events (for details element).

func OnTouchCancel

func OnTouchCancel(handler any) EventHandler

OnTouchCancel handles touchcancel events.

func OnTouchEnd

func OnTouchEnd(handler any) EventHandler

OnTouchEnd handles touchend events.

func OnTouchMove

func OnTouchMove(handler any) EventHandler

OnTouchMove handles touchmove events.

func OnTouchStart

func OnTouchStart(handler any) EventHandler

OnTouchStart handles touchstart events.

func OnTransitionCancel

func OnTransitionCancel(handler any) EventHandler

OnTransitionCancel handles transitioncancel events.

func OnTransitionEnd

func OnTransitionEnd(handler any) EventHandler

OnTransitionEnd handles transitionend events.

func OnTransitionRun

func OnTransitionRun(handler any) EventHandler

OnTransitionRun handles transitionrun events.

func OnTransitionStart

func OnTransitionStart(handler any) EventHandler

OnTransitionStart handles transitionstart events.

func OnVolumeChange

func OnVolumeChange(handler any) EventHandler

OnVolumeChange handles volumechange events.

func OnWaiting

func OnWaiting(handler any) EventHandler

OnWaiting handles waiting events (playback stopped, waiting for data).

func OnWheel

func OnWheel(handler any) EventHandler

OnWheel handles wheel (scroll wheel) events.

type FuncComponent

type FuncComponent struct {
	// contains filtered or unexported fields
}

FuncComponent wraps a render function.

func (*FuncComponent) Render

func (f *FuncComponent) Render() *VNode

Render implements Component.

type HIDGenerator

type HIDGenerator struct {
	// contains filtered or unexported fields
}

HIDGenerator generates unique hydration IDs for interactive elements.

func NewHIDGenerator

func NewHIDGenerator() *HIDGenerator

NewHIDGenerator creates a new HIDGenerator.

func (*HIDGenerator) Current

func (g *HIDGenerator) Current() uint32

Current returns the current counter value without incrementing.

func (*HIDGenerator) Next

func (g *HIDGenerator) Next() string

Next returns the next hydration ID (e.g., "h1", "h2", ...).

func (*HIDGenerator) Reset

func (g *HIDGenerator) Reset()

Reset resets the counter to 0.

type Patch

type Patch struct {
	Op       PatchOp // Operation type
	HID      string  // Target element's hydration ID
	Key      string  // Attribute key (for SetAttr/RemoveAttr)
	Value    string  // New value
	Node     *VNode  // For InsertNode/ReplaceNode
	Index    int     // Insert position
	ParentID string  // Parent for InsertNode

	// Unaddressable marks a diff batch that cannot be represented safely as patches.
	// The server intercepts these batches and falls back to ResyncFull.
	Unaddressable bool
	Reason        string
}

Patch represents a single DOM operation to apply.

func Diff

func Diff(prev, next *VNode) []Patch

Diff compares two VNode trees and returns the patches needed to transform prev into next.

func DiffWithPolicy

func DiffWithPolicy(prev, next *VNode, policy URLPolicy) []Patch

DiffWithPolicy compares two VNode trees using the provided URL policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).

type PatchOp

type PatchOp uint8

PatchOp is the type of patch operation.

const (
	PatchSetText       PatchOp = 0x01 // Update text content
	PatchSetAttr       PatchOp = 0x02 // Set/update attribute
	PatchRemoveAttr    PatchOp = 0x03 // Remove attribute
	PatchInsertNode    PatchOp = 0x04 // Insert new node
	PatchRemoveNode    PatchOp = 0x05 // Remove node
	PatchMoveNode      PatchOp = 0x06 // Move node to new position
	PatchReplaceNode   PatchOp = 0x07 // Replace node entirely
	PatchSetValue      PatchOp = 0x08 // Set input value
	PatchSetChecked    PatchOp = 0x09 // Set checkbox checked
	PatchSetSelected   PatchOp = 0x0A // Set select option selected
	PatchFocus         PatchOp = 0x0B // Focus element
	PatchSetTextAt     PatchOp = 0x16 // Set text by parent/index
	PatchRemoveNodeAt  PatchOp = 0x17 // Remove node by parent/index
	PatchReplaceNodeAt PatchOp = 0x18 // Replace node by parent/index
)

func (PatchOp) String

func (op PatchOp) String() string

String returns the string representation of the PatchOp.

type PathProvider

type PathProvider interface {
	Path() string
}

PathProvider is the interface for context that provides current path. This is typically satisfied by server.Ctx.

type Props

type Props map[string]any

Props holds attributes and event handlers.

type RawHTMLSanitizeReport

type RawHTMLSanitizeReport struct {
	Modified      bool
	RemovedNodes  int
	RemovedAttrs  int
	RewrittenAttr int
	ParseError    bool
	UnsafeBypass  bool
}

RawHTMLSanitizeReport describes how raw HTML was transformed.

func SanitizeRawHTML

func SanitizeRawHTML(raw string) (string, RawHTMLSanitizeReport)

SanitizeRawHTML sanitizes raw HTML using the default URL policy.

func SanitizeRawHTMLWithPolicy

func SanitizeRawHTMLWithPolicy(policy URLPolicy, raw string) (string, RawHTMLSanitizeReport)

SanitizeRawHTMLWithPolicy sanitizes raw HTML using the provided URL policy.

Sanitization rules: - Drop all on* event handler attributes. - Sanitize URL-bearing attributes with the same policy used for normal attrs. - Drop blocked attributes (unsafe schemes, srcdoc when disallowed, etc.). - Drop high-risk executable/style tags (<script>, <style>, <base>, <meta>) unless raw unsafe mode is enabled. - Drop style attributes to avoid CSS injection through raw HTML sinks.

type RuntimeUnsafePermissions added in v0.2.0

type RuntimeUnsafePermissions struct {
	AllowUnsafeRawHTML         bool
	AllowInsecureModuleOrigins bool
}

type ScriptsOption

type ScriptsOption func(*scriptsOptions)

ScriptsOption is a functional option for VangoScripts.

func WithAllowInsecureModuleOrigins added in v0.0.2

func WithAllowInsecureModuleOrigins() ScriptsOption

WithAllowInsecureModuleOrigins allows cross-origin http: module imports on https: pages. SECURITY: This is a break-glass option for trusted local/dev environments only.

func WithAllowInsecureModuleOriginsAcknowledged added in v0.2.0

func WithAllowInsecureModuleOriginsAcknowledged(token string) ScriptsOption

WithAllowInsecureModuleOriginsAcknowledged allows insecure cross-origin http: module origins on https: pages with an explicit acknowledgement token.

func WithAllowSrcdoc

func WithAllowSrcdoc() ScriptsOption

WithAllowSrcdoc enables client-side srcdoc updates. Use this only when cfg.Security.URLPolicy.AllowSrcdoc is true.

func WithAllowUnsafeRawHTML

func WithAllowUnsafeRawHTML() ScriptsOption

WithAllowUnsafeRawHTML disables client-side raw HTML sanitization. SECURITY: Only use when all raw HTML input is fully trusted.

func WithAllowUnsafeRawHTMLAcknowledged added in v0.2.0

func WithAllowUnsafeRawHTMLAcknowledged(token string) ScriptsOption

WithAllowUnsafeRawHTMLAcknowledged disables client-side raw HTML sanitization with an explicit acknowledgement token.

func WithBootstrapConfig added in v0.0.3

func WithBootstrapConfig(cfg bootstrap.Config) ScriptsOption

WithBootstrapConfig injects canonical bootstrap JSON alongside the runtime script.

func WithCSRFToken

func WithCSRFToken(token string) ScriptsOption

WithCSRFToken injects a CSRF token for the thin client. The token is used for WebSocket handshake validation.

func WithDebug

func WithDebug() ScriptsOption

WithDebug enables debug mode for the thin client. Debug mode logs events, patches, and WebSocket messages to console.

func WithModuleOrigins

func WithModuleOrigins(origins ...string) ScriptsOption

WithModuleOrigins sets allowed origins for island/wasm module imports. Origins must be full origins (scheme + host + optional port).

func WithRuntimeUnsafePermissions added in v0.2.0

func WithRuntimeUnsafePermissions(perms RuntimeUnsafePermissions) ScriptsOption

WithRuntimeUnsafePermissions injects validated runtime unsafe permissions.

func WithScriptPath

func WithScriptPath(path string) ScriptsOption

WithScriptPath sets a custom path for the thin client script. Default is "/_vango/client.js".

func WithoutDefer

func WithoutDefer() ScriptsOption

WithoutDefer removes the defer attribute from the script tag. By default, scripts are loaded with defer for non-blocking loading.

type TrustedHTML

type TrustedHTML string

TrustedHTML marks HTML content that is intentionally allowed to bypass text escaping. Construct this type only from trusted/sanitized sources.

func SanitizeTrustedHTML

func SanitizeTrustedHTML(html string) TrustedHTML

SanitizeTrustedHTML sanitizes a raw HTML string using the default URL policy.

func SanitizeTrustedHTMLWithPolicy

func SanitizeTrustedHTMLWithPolicy(policy URLPolicy, html string) TrustedHTML

SanitizeTrustedHTMLWithPolicy sanitizes a raw HTML string using the provided URL policy.

func UnsafeTrustedHTML

func UnsafeTrustedHTML(html string) TrustedHTML

UnsafeTrustedHTML marks a string as trusted HTML without sanitization. Use this only for hardcoded/internal HTML that you fully trust.

type URLPolicy

type URLPolicy struct {
	AllowedHrefSchemes     map[string]struct{}
	AllowedResourceSchemes map[string]struct{}
	AllowedActionSchemes   map[string]struct{}
	AllowSrcdoc            bool
	// AllowUnsafeRawHTML disables sink sanitization for raw HTML content.
	// Default: false.
	AllowUnsafeRawHTML bool
}

URLPolicy defines allowed schemes for URL-bearing attributes. Empty scheme lists fall back to secure defaults.

func CloneURLPolicy

func CloneURLPolicy(policy URLPolicy) URLPolicy

CloneURLPolicy returns a deep copy of the policy (maps are cloned).

func DefaultURLPolicy

func DefaultURLPolicy() URLPolicy

DefaultURLPolicy returns the default URL scheme policy.

func NormalizeURLPolicy

func NormalizeURLPolicy(policy URLPolicy) URLPolicy

NormalizeURLPolicy fills in defaults and normalizes schemes.

func URLPolicyFromSchemes

func URLPolicyFromSchemes(hrefSchemes, resourceSchemes, actionSchemes []string, allowSrcdoc bool) URLPolicy

URLPolicyFromSchemes builds a URLPolicy from scheme lists. Empty slices fall back to the defaults.

type VKind

type VKind uint8

VKind is the node type discriminator.

const (
	KindElement   VKind = iota + 1 // <div>, <button>, etc.
	KindText                       // Plain text node
	KindFragment                   // Grouping without wrapper
	KindComponent                  // Nested component
	KindRaw                        // Raw HTML (sanitized at sinks unless unsafe mode is enabled)
)

func (VKind) String

func (k VKind) String() string

String returns the string representation of the VKind.

type VNode

type VNode struct {
	Kind     VKind     // Node type
	Tag      string    // Element tag name (e.g., "div")
	Props    Props     // Attributes and event handlers
	Children []*VNode  // Child nodes
	Key      string    // Reconciliation key
	Text     string    // For KindText and KindRaw
	Comp     Component // For KindComponent
	HID      string    // Hydration ID (assigned during render)
}

VNode is the virtual DOM node.

func A

func A(args ...any) *VNode

func Abbr

func Abbr(args ...any) *VNode

func Address

func Address(args ...any) *VNode

func Area

func Area(args ...any) *VNode

func Article

func Article(args ...any) *VNode

func Aside

func Aside(args ...any) *VNode

func Audio

func Audio(args ...any) *VNode

func B

func B(args ...any) *VNode

func Base

func Base(args ...any) *VNode

func Bdi

func Bdi(args ...any) *VNode

func Bdo

func Bdo(args ...any) *VNode

func Blockquote

func Blockquote(args ...any) *VNode

func Body

func Body(args ...any) *VNode

func Br

func Br(args ...any) *VNode

func Button

func Button(args ...any) *VNode

func Canvas

func Canvas(args ...any) *VNode

func Caption

func Caption(args ...any) *VNode

func Circle

func Circle(args ...any) *VNode

SVG child elements

func Cite

func Cite(args ...any) *VNode

func Code

func Code(args ...any) *VNode

func Col

func Col(args ...any) *VNode

func Colgroup

func Colgroup(args ...any) *VNode

func CustomElement

func CustomElement(tag string, args ...any) *VNode

CustomElement creates an element with a custom tag name.

func DangerouslySetInnerHTML

func DangerouslySetInnerHTML(html TrustedHTML) *VNode

DangerouslySetInnerHTML creates a raw HTML node.

SECURITY WARNING: This bypasses all HTML escaping and can cause XSS vulnerabilities if the content includes untrusted user input. Vango applies sink sanitization by default (SSR, patches, ResyncFull), but you must still treat this API as dangerous and feed it trusted/sanitized HTML. Default sink sanitization strips executable/style tags, style attrs, event handler attrs, unsafe URL attrs, and Vango runtime control attrs. Only use with content that is:

  • Hardcoded in your source code
  • Generated by a trusted sanitizer (e.g., bluemonday)
  • From a trusted internal service

NEVER pass user-provided strings directly to DangerouslySetInnerHTML().

Example:

DangerouslySetInnerHTML(SanitizeTrustedHTML("<strong>Bold</strong>"))

func DataElement

func DataElement(args ...any) *VNode

DataElement creates a <data> HTML element. Note: For data-* attributes, use Data(key, value) from attributes.go instead.

func Datalist

func Datalist(args ...any) *VNode

func Dd

func Dd(args ...any) *VNode

func Defs

func Defs(args ...any) *VNode

func Details

func Details(args ...any) *VNode

func Dfn

func Dfn(args ...any) *VNode

func Dialog

func Dialog(args ...any) *VNode

func Div

func Div(args ...any) *VNode

func Dl

func Dl(args ...any) *VNode

func Dt

func Dt(args ...any) *VNode

func Either

func Either(first, second *VNode) *VNode

Either returns first if it's not nil, otherwise second.

func Ellipse

func Ellipse(args ...any) *VNode

func Em

func Em(args ...any) *VNode

func Embed

func Embed(args ...any) *VNode

func Empty

func Empty() *VNode

Empty returns an empty fragment that renders nothing. Unlike Null which returns nil, Empty returns a valid VNode that simply has no children.

Example:

vdom.Empty()  // Renders nothing

func Fieldset

func Fieldset(args ...any) *VNode

func Figcaption

func Figcaption(args ...any) *VNode

func Figure

func Figure(args ...any) *VNode

func FindByHID

func FindByHID(node *VNode, hid string) *VNode

FindByHID finds a node by its HID in the tree.

func Footer(args ...any) *VNode

func Form

func Form(args ...any) *VNode

func Fragment

func Fragment(children ...any) *VNode

Fragment groups children without a wrapper element. It accepts ChildrenProvider implementations like vango.Slot. Any unsupported child type panics with a descriptive error.

func G

func G(args ...any) *VNode

func Group

func Group(children ...any) *VNode

Group is an alias for Fragment.

func H1

func H1(args ...any) *VNode

func H2

func H2(args ...any) *VNode

func H3

func H3(args ...any) *VNode

func H4

func H4(args ...any) *VNode

func H5

func H5(args ...any) *VNode

func H6

func H6(args ...any) *VNode
func Head(args ...any) *VNode
func Header(args ...any) *VNode

func Hgroup

func Hgroup(args ...any) *VNode

func Hide

func Hide(condition bool, node *VNode) *VNode

Hide returns the node if condition is false, otherwise Nothing. Alias for Unless for semantic clarity.

func Hr

func Hr(args ...any) *VNode

func Html

func Html(args ...any) *VNode

func I

func I(args ...any) *VNode

func If

func If(condition bool, node *VNode) *VNode

If returns the node if condition is true, nil otherwise.

func IfElse

func IfElse(condition bool, ifTrue, ifFalse *VNode) *VNode

IfElse returns the first node if condition is true, the second otherwise.

func IfLazy

func IfLazy(condition bool, fn func() *VNode) *VNode

IfLazy is an alias for When - use when you need lazy evaluation. See When for details on why this is needed for nullable pointer access.

func Iframe

func Iframe(args ...any) *VNode

func Img

func Img(args ...any) *VNode

func Input

func Input(args ...any) *VNode

func Kbd

func Kbd(args ...any) *VNode

func Label

func Label(args ...any) *VNode

func Legend

func Legend(args ...any) *VNode

func Li

func Li(args ...any) *VNode

func Line

func Line(args ...any) *VNode
func Link(path string, children ...any) *VNode

Link creates an anchor for client-side SPA navigation. When clicked, the thin client intercepts and sends a navigate event to the server instead of performing a full page reload.

Example: Link("/about", Text("About"))

func LinkEl

func LinkEl(args ...any) *VNode

func LinkPrefetch

func LinkPrefetch(path string, children ...any) *VNode

LinkPrefetch creates an SPA link that prefetches the target on hover. This provides faster navigation by loading the page before click.

Example: LinkPrefetch("/about", Text("About"))

func Main

func Main(args ...any) *VNode

func Map_

func Map_(args ...any) *VNode

func Mark

func Mark(args ...any) *VNode

func Math

func Math(args ...any) *VNode

func Maybe

func Maybe(node *VNode) *VNode

Maybe returns the node if it's not nil. This is a no-op but can make code more readable.

func Menu(args ...any) *VNode

func Meta

func Meta(args ...any) *VNode

func Meter

func Meter(args ...any) *VNode
func Nav(args ...any) *VNode
func NavLink(ctx PathProvider, path string, children ...any) *VNode

NavLink creates an SPA link with "active" class when path matches. The active class is applied server-side based on the current route. This is the recommended helper for navigation menus.

Example:

Nav(
    NavLink(ctx, "/", Text("Home")),
    NavLink(ctx, "/about", Text("About")),
)
func NavLinkPrefix(ctx PathProvider, path string, children ...any) *VNode

NavLinkPrefix is like NavLink but matches path prefixes. Use for nav items that should be active for all sub-routes.

Example:

NavLinkPrefix(ctx, "/admin", Text("Admin"))
// Active on /admin, /admin/users, /admin/settings, etc.

func Noscript

func Noscript(args ...any) *VNode

func Nothing

func Nothing() *VNode

Nothing is a legacy alias for Null. Prefer Null() for new code to match the spec naming.

func Null

func Null() *VNode

Null returns nil, representing explicit nothing in the component tree. Use this when you want to explicitly render nothing.

Example:

func MaybeShow() *vdom.VNode {
    if !shouldShow {
        return vdom.Null()
    }
    return Content()
}

func Object

func Object(args ...any) *VNode

func Ol

func Ol(args ...any) *VNode

func Optgroup

func Optgroup(args ...any) *VNode

func Option

func Option(args ...any) *VNode

func Output

func Output(args ...any) *VNode

func P

func P(args ...any) *VNode

func Param

func Param(args ...any) *VNode

func Path

func Path(args ...any) *VNode

func Picture

func Picture(args ...any) *VNode

func Polygon

func Polygon(args ...any) *VNode

func Polyline

func Polyline(args ...any) *VNode

func Pre

func Pre(args ...any) *VNode

func Progress

func Progress(args ...any) *VNode

func Q

func Q(args ...any) *VNode

func Range

func Range[T any](items []T, fn func(item T, index int) *VNode) []*VNode

Range maps a slice to VNodes.

func RangeKeyed

func RangeKeyed[T any](items []T, key func(item T) any, fn func(item T) *VNode) []*VNode

RangeKeyed maps a slice to VNodes and assigns a stable key for each item. The key value is formatted using fmt.Sprintf("%v", key).

func RangeMap

func RangeMap[K comparable, V any](m map[K]V, fn func(key K, value V) *VNode) []*VNode

RangeMap maps a map to VNodes. RangeMap iterates deterministically by sorting keys.

Key ordering rules:

  • bool: false < true
  • signed ints: numeric ascending
  • unsigned ints + uintptr: numeric ascending
  • string: lexicographic ascending
  • other comparable keys: deterministic ordering by (type, value token)

Float keys are rejected (panic) because they can be unordered (NaN).

func Raw

func Raw(html TrustedHTML) *VNode

Raw is a legacy alias for DangerouslySetInnerHTML. Prefer DangerouslySetInnerHTML for new code as it makes the security implications more explicit.

SECURITY WARNING: This bypasses all HTML escaping. See DangerouslySetInnerHTML.

func Rect

func Rect(args ...any) *VNode

func Repeat

func Repeat(n int, fn func(i int) *VNode) []*VNode

Repeat creates n nodes using the given function.

func Rp

func Rp(args ...any) *VNode

func Rt

func Rt(args ...any) *VNode

func Ruby

func Ruby(args ...any) *VNode

func S

func S(args ...any) *VNode

func Samp

func Samp(args ...any) *VNode

func Script

func Script(args ...any) *VNode

func Section

func Section(args ...any) *VNode

func Select

func Select(args ...any) *VNode

func Show

func Show(condition bool, node *VNode) *VNode

Show returns the node if condition is true, otherwise Nothing. Alias for If for semantic clarity.

func ShowWhen

func ShowWhen(condition bool, fn func() *VNode) *VNode

ShowWhen is an alias for When with a UI-focused name. Use when conditionally showing UI elements that depend on nullable data.

func Slot

func Slot(args ...any) *VNode

func Small

func Small(args ...any) *VNode

func Source

func Source(args ...any) *VNode

func Span

func Span(args ...any) *VNode

func Strong

func Strong(args ...any) *VNode

func Style

func Style(args ...any) *VNode

func Sub

func Sub(args ...any) *VNode

func Summary

func Summary(args ...any) *VNode

func Sup

func Sup(args ...any) *VNode

func Svg

func Svg(args ...any) *VNode

func Switch

func Switch[T comparable](value T, cases ...Case[T]) *VNode

Switch returns the node for the matching case value. If no case matches and there's a default, the default node is returned.

func Table

func Table(args ...any) *VNode

func Tbody

func Tbody(args ...any) *VNode

func Td

func Td(args ...any) *VNode

func Template

func Template(args ...any) *VNode

func Text

func Text(content string) *VNode

Text creates a text node.

func Textarea

func Textarea(args ...any) *VNode

func Textf

func Textf(format string, args ...any) *VNode

Textf creates a formatted text node.

func Tfoot

func Tfoot(args ...any) *VNode

func Th

func Th(args ...any) *VNode

func Thead

func Thead(args ...any) *VNode

func Time_

func Time_(args ...any) *VNode

func Title

func Title(args ...any) *VNode

func TitleEl

func TitleEl(args ...any) *VNode

TitleEl is an alias for Title. It exists to match the Vango v1 Developer Guide examples and avoid ambiguity with the TitleAttr helper.

func Tr

func Tr(args ...any) *VNode

func Track

func Track(args ...any) *VNode

func U

func U(args ...any) *VNode

func Ul

func Ul(args ...any) *VNode

func Unless

func Unless(condition bool, node *VNode) *VNode

Unless is the inverse of If. Returns the node if condition is false.

func Use

func Use(args ...any) *VNode

func VangoScripts

func VangoScripts(opts ...ScriptsOption) *VNode

VangoScripts returns the script tag(s) needed to load the Vango thin client. This should be placed in the <head> or at the end of <body> in your layout.

Options can customize behavior:

  • WithDebug() - enable console logging
  • WithScriptPath(path) - custom script location
  • WithCSRFToken(token) - inject CSRF token
  • WithoutDefer() - load script synchronously
  • WithAllowSrcdoc() - enable client-side srcdoc updates
  • WithAllowUnsafeRawHTML() - disable raw HTML sanitization (unsafe)
  • WithAllowInsecureModuleOrigins() - allow insecure http: cross-origin module imports on https: pages (unsafe)

Example usage in a layout:

func Layout(ctx vango.Ctx, children ...*vdom.VNode) *vdom.VNode {
    return vdom.Html(
        vdom.Head(
            vdom.Meta(vdom.Charset("utf-8")),
            vdom.VangoScripts(vdom.WithCSRFToken(ctx.Session().CSRFToken())),
        ),
        vdom.Body(children...),
    )
}

func Var

func Var(args ...any) *VNode

func Video

func Video(args ...any) *VNode

func Wbr

func Wbr(args ...any) *VNode

func When

func When(condition bool, fn func() *VNode) *VNode

When is like If but with lazy evaluation. The function is only called if condition is true, preventing nil pointer panics.

Use this instead of If when the node contains expressions that depend on the condition being true (e.g., dereferencing a pointer that might be nil).

Example - WRONG (panics when DueDate is nil):

If(card.DueDate != nil,
    Span(Text(card.DueDate.Format("Jan 2"))),  // Evaluated even when nil!
)

Example - CORRECT (safe with lazy evaluation):

When(card.DueDate != nil, func() *VNode {
    return Span(Text(card.DueDate.Format("Jan 2")))  // Only evaluated when not nil
})

func (*VNode) IsInteractive

func (v *VNode) IsInteractive() bool

IsInteractive returns true if this element has at least one event handler prop. Event handler detection is centralized in isEventHandler so interactive counting, diffing, and effective attribute generation stay consistent.

func (*VNode) SuppressesRawHTMLUsageWarning added in v0.0.3

func (v *VNode) SuppressesRawHTMLUsageWarning() bool

SuppressesRawHTMLUsageWarning reports whether this raw node was produced by internal framework code that should not trigger the generic "raw HTML API used" warning when sink sanitization makes no changes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL