Documentation
ΒΆ
Index ΒΆ
- func Append(parentID string, component Component) error
- func GetDocumentAttr(attr string) string
- func GetHash() string
- func LocalStorageAvailable() bool
- func LocalStorageClear() error
- func LocalStorageDel(key string) error
- func LocalStorageGet(key string) (string, error)
- func LocalStorageSet(key, value string) error
- func Log(v ...any)
- func OnHashChange(handler func(hash string))
- func Render(parentID string, component Component) error
- func SetDocumentAttr(attr, value string)
- func SetHash(hash string)
- func SetLog(log func(v ...any))
- func Update(component Component)
- type CSSProvider
- type Component
- type DOM
- type Element
- func A(href string, children ...any) *Element
- func Article(children ...any) *Element
- func Aside(children ...any) *Element
- func Br() *Element
- func Button(children ...any) *Element
- func Canvas(children ...any) *Element
- func Code(children ...any) *Element
- func Details(children ...any) *Element
- func Dialog(children ...any) *Element
- func Div(children ...any) *Element
- func Em(children ...any) *Element
- func Fieldset(children ...any) *Element
- func Figcaption(children ...any) *Element
- func Figure(children ...any) *Element
- func Footer(children ...any) *Element
- func H1(children ...any) *Element
- func H2(children ...any) *Element
- func H3(children ...any) *Element
- func H4(children ...any) *Element
- func H5(children ...any) *Element
- func H6(children ...any) *Element
- func Header(children ...any) *Element
- func Hr() *Element
- func Img(src, alt string) *Element
- func Input(typ string) *Element
- func Label(children ...any) *Element
- func Legend(children ...any) *Element
- func Li(children ...any) *Element
- func Main(children ...any) *Element
- func Mark(children ...any) *Element
- func Nav(children ...any) *Element
- func Ol(children ...any) *Element
- func Option(value, text string) *Element
- func P(children ...any) *Element
- func Pre(children ...any) *Element
- func Script(children ...any) *Element
- func Section(children ...any) *Element
- func SelectedOption(value, text string) *Element
- func Small(children ...any) *Element
- func Span(children ...any) *Element
- func Strong(children ...any) *Element
- func Style(children ...any) *Element
- func Summary(children ...any) *Element
- func Svg(children ...any) *Element
- func Table(children ...any) *Element
- func Tbody(children ...any) *Element
- func Td(children ...any) *Element
- func Tfoot(children ...any) *Element
- func Th(children ...any) *Element
- func Thead(children ...any) *Element
- func Tr(children ...any) *Element
- func Ul(children ...any) *Element
- func Use(children ...any) *Element
- func (b *Element) Add(children ...any) *Element
- func (b *Element) Attr(key, val string) *Element
- func (b *Element) Children() []Component
- func (b *Element) Class(class ...string) *Element
- func (b *Element) For(other *Element) *Element
- func (b *Element) GetID() string
- func (b *Element) ID(id string) *Element
- func (b *Element) On(t string, h func(Event)) *Element
- func (b *Element) Render(parentID string) error
- func (b *Element) RenderHTML() string
- func (b *Element) SetID(id string)
- func (b *Element) Text(text string) *Element
- func (b *Element) Update()
- type Event
- type IconSvgProvider
- type JSProvider
- type Mountable
- type Reference
- type Unmountable
- type Updatable
- type ViewRenderer
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func Append ΒΆ added in v0.2.0
Append injects a component AFTER the last child of the parent element.
func GetDocumentAttr ΒΆ added in v0.9.0
GetDocumentAttr reads an attribute from document.documentElement. Returns "" if the attribute is absent.
func LocalStorageAvailable ΒΆ added in v0.9.0
func LocalStorageAvailable() bool
LocalStorageAvailable reports whether localStorage is accessible in the current browser context. Returns false when blocked by iframe sandbox, privacy settings, or private mode. Used internally by all LocalStorage* functions and available as a public check.
func LocalStorageClear ΒΆ added in v0.9.0
func LocalStorageClear() error
LocalStorageClear removes all keys. Returns error if storage unavailable.
func LocalStorageDel ΒΆ added in v0.9.0
LocalStorageDel removes a key. Returns error if storage unavailable.
func LocalStorageGet ΒΆ added in v0.9.0
LocalStorageGet retrieves a value from window.localStorage. Returns ("", nil) β key absent, storage is functional. Returns ("", error) β storage unavailable.
func LocalStorageSet ΒΆ added in v0.9.0
LocalStorageSet writes a key-value pair. Returns error if: storage unavailable, value > lsMaxValue, or budget exceeded.
func OnHashChange ΒΆ added in v0.0.11
func OnHashChange(handler func(hash string))
OnHashChange registers a hash change listener.
func SetDocumentAttr ΒΆ added in v0.9.0
func SetDocumentAttr(attr, value string)
SetDocumentAttr sets an attribute on document.documentElement (<html>). value=="" removes the attribute β consistent with GetDocumentAttr returning "" for absent attributes.
Types ΒΆ
type CSSProvider ΒΆ added in v0.5.6
type CSSProvider interface {
RenderCSS() string
}
CSSProvider is an optional capability: components that provide raw CSS for SSR asset collection (collected by tinywasm/site during static build).
type Component ΒΆ
type Component interface {
GetID() string
SetID(id string)
RenderHTML() string
Children() []Component
}
Component is the minimal interface for components. All components must implement this for both SSR (backend) and WASM (frontend).
NOTE: If your struct embeds Element, embed it as a VALUE, not a pointer:
type MyComponent struct {
Element // β
Correct β never nil
// NOT: *Element // β Wrong β nil pointer causes panic in renderToHTML
}
This is because renderToHTML calls GetID() on every Component child before checking ViewRenderer.
type DOM ΒΆ
type DOM interface {
// Render injecta un componente en un elemento padre.
// 1. Llama a componente.Render() (si es ViewRenderer) o componente.RenderHTML()
// 2. Establece el contenido del elemento padre (buscado por parentID)
// 3. Llama a componente.OnMount() para enlazar eventos
Render(parentID string, component Component) error
// Append injecta un componente DESPUΓS del ΓΊltimo hijo del elemento padre.
// Γtil para listas dinΓ‘micas.
Append(parentID string, component Component) error
// OnHashChange registra un listener para cambios en el hash de la URL.
OnHashChange(handler func(hash string))
// GetHash devuelve el hash actual de la URL (ej. "#help").
GetHash() string
// SetHash actualiza el hash de la URL.
SetHash(hash string)
// Update re-renderiza el componente en su posiciΓ³n actual en el DOM.
Update(component Component)
// Get retrieves an element by ID.
Get(id string) (Reference, bool)
// Log provides logging functionality using the log function passed to New.
Log(v ...any)
}
DOM is the main entry point for interacting with the browser. It is designed to be injected into your components.
type Element ΒΆ
type Element struct {
// contains filtered or unexported fields
}
Element represents a DOM element in the fluent Element API.
func Figcaption ΒΆ added in v0.4.2
func SelectedOption ΒΆ added in v0.4.2
func (*Element) Add ΒΆ added in v0.2.3
Add adds one or more children to the element. Children can be *Element, Node, Component, or string.
func (*Element) Children ΒΆ added in v0.2.3
Children returns the component's children (components only).
func (*Element) For ΒΆ added in v0.8.0
For sets the for= attribute pointing to other's ID, auto-generating other's ID if it has none. Use for label/input pairing and aria-* references.
func (*Element) Render ΒΆ added in v0.2.3
Render renders the element to the parent. This is a terminal operation.
func (*Element) RenderHTML ΒΆ added in v0.2.3
RenderHTML renders the element to HTML string.
type Event ΒΆ
type Event interface {
// PreventDefault prevents the default action of the event.
PreventDefault()
// StopPropagation stops the event from bubbling up the DOM tree.
StopPropagation()
// TargetValue returns the value of the event's target element.
// Useful for input, textarea, and select elements.
TargetValue() string
// TargetID returns the ID of the event's target element.
TargetID() string
// TargetChecked returns the checked status of the event's target element.
// Useful for checkbox and radio input elements.
TargetChecked() bool
}
Event represents a DOM event.
type IconSvgProvider ΒΆ added in v0.5.6
IconSvgProvider is an optional capability: components that expose SVG icons for the global sprite sheet injected during SSR build.
type JSProvider ΒΆ added in v0.5.6
type JSProvider interface {
RenderJS() string
}
JSProvider is an optional capability: components that provide raw JS for SSR asset collection.
type Mountable ΒΆ
type Mountable interface {
OnMount()
}
Mountable is an optional interface for components that need initialization logic.
type Reference ΒΆ added in v0.2.3
type Reference interface {
// GetAttr retrieves an attribute value.
GetAttr(key string) string
// Value returns the current value of an input/textarea/select.
Value() string
// Checked returns the current checked state of a checkbox or radio button.
Checked() bool
// On registers a generic event handler (e.g., "click", "change", "input", "keydown").
On(eventType string, handler func(event Event))
// Focus sets focus to the element.
Focus()
}
Reference represents a reference to a DOM node. It provides methods for reading and interaction.
type Unmountable ΒΆ added in v0.2.0
type Unmountable interface {
OnUnmount()
}
Unmountable is an optional interface for components that need cleanup logic.
type Updatable ΒΆ added in v0.2.0
type Updatable interface {
OnUpdate()
}
Updatable is an optional interface for components that need update logic.
type ViewRenderer ΒΆ added in v0.2.0
type ViewRenderer interface {
Render() *Element
}
ViewRenderer returns a Node tree for declarative UI.