runtime

package
v1.6.0-beta.7 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const WireVersion byte = 1

WireVersion is the codec's frame-format version. It is written as byte 0 of every top-level frame by NewEncoder and validated by NewDecoder. Bumping it is an intentional, irreversible wire break: a decoder built for one version rejects frames carrying any other. Nested encodes (_encode_X, _encode_sliceX) receive an already-opened *Encoder and therefore never re-emit this byte — only the frame's opening carries it.

Variables

View Source
var HTMX htmxAPI

HTMX is the host no-op singleton (see the js&&wasm HTMX for behavior).

Functions

func AddClass

func AddClass(id, className string)

func AddEventListener

func AddEventListener(el JSValue, event string, fn func())

func AddEventListenerWithEvent

func AddEventListenerWithEvent(el JSValue, event string, fn func(JSValue))

func AppendChild

func AppendChild(parent, child JSValue)

func BeginBatch

func BeginBatch()

BeginBatch is a no-op in non-WASM builds.

func BroadcastTopicEncoded

func BroadcastTopicEncoded(keyName, encoded string)

func BroadcastTopicEncodedField

func BroadcastTopicEncodedField(keyName, fieldName, encoded string)

func BroadcastTopicOnline

func BroadcastTopicOnline(keyName, encoded string)

func CaptureScope

func CaptureScope() string

CaptureScope returns the scope active at the call site. Capture it before spawning a goroutine or scheduling async work whose body touches scoped DOM helpers, then re-establish it with RunInScope when that work runs — a goroutine does not inherit the carrier across a suspension point.

Keep any blocking call (a fetch, a channel receive) OUTSIDE RunInScope and wrap only the scoped, non-blocking work — mirroring how PingUntilOnline keeps time.Sleep outside RunInScope:

scope := CaptureScope()
go func() {
    body, _ := Fetch(url)                       // blocks — outside RunInScope
    RunInScope(scope, func() { SetText("out", body) })  // scoped, non-blocking
}()

func ClickElement

func ClickElement(el JSValue)

func ConsoleLog

func ConsoleLog(args ...any)

func CookieDelete

func CookieDelete(key string)

func CookieGet

func CookieGet(key string) string

func CookieSet

func CookieSet(key, value string, opts ...CookieOptions)

func CopyBytesToGo

func CopyBytesToGo(dst []byte, src JSValue) int

func CopyBytesToJS

func CopyBytesToJS(dst JSValue, src []byte) int

func CreateTopic

func CreateTopic[T any](zero T, cfg TopicConfig) func() interface{}

CreateTopic declares a topic. The CLI AST scanner detects this call and generates the concrete typed accessor. At runtime this returns a no-op.

func CreateWasmBoolFunc

func CreateWasmBoolFunc(name string, fn func(bool))

func CreateWasmFunc

func CreateWasmFunc(name string, fn func())

func CreateWasmStringFunc

func CreateWasmStringFunc(name string, fn func(string))

func DurableKey

func DurableKey() string

DurableKey is empty on the host build (no DOM to read data-gothic-durable-key from), so DurableObserve treats every placement as non-durable server-side.

func DurableObserve

func DurableObserve[T any](field string, obs *Observable[T], encode func(T) string, decode func(string) T)

DurableObserve is a no-op server-side: obs behaves as a plain observable and no durable wiring is emitted into the SSR render.

func EndBatch

func EndBatch()

EndBatch is a no-op in non-WASM builds.

func ExecJS

func ExecJS(script string)

func FetchAsync added in v1.4.0

func FetchAsync(url string, cfg FetchConfig, done func(Response, error))

func FetchChan added in v1.4.0

func FetchChan(url string, cfg ...FetchConfig) <-chan FetchResult

FetchChan returns a buffered channel already carrying one zero FetchResult so a host consumer that receives from it gets a zero value instead of blocking forever — matching the zero-value discipline of the other server-side stubs.

func GetFileBytes

func GetFileBytes(id string) []byte

func GetValue

func GetValue(id string) string

func GoBack

func GoBack()

func GothicHaltChan

func GothicHaltChan() <-chan struct{}

GothicHaltChan returns a nil channel on the host build; the real implementation (js && wasm) returns the keep-alive sentinel that main() selects on. A nil channel blocks forever, matching the original select{} keep-alive semantics for any host-side compile of the generated main().

func GothicRegisterSchema

func GothicRegisterSchema(key, schemaID, descriptor string)

GothicRegisterSchema is a no-op on the host build. The real implementation (js && wasm) deposits the type's compact schema descriptor on window.__gothicSchemas under its content-hash id — the schema seam, reserved for a future generic interpreter and interpreted by nothing in v3.0.

func GothicRegisterScope

func GothicRegisterScope(body func())

GothicRegisterScope is a no-op on the host build; the real implementation (js && wasm) registers the mount scope and publishes a per-instance __gothic_register_scope callback for multiplexed pages. Running body directly would execute WASM-only runtime calls server-side, so the host stub — like the generated main() itself, which is //go:build js && wasm — simply does nothing.

func GothicRegisterWithCore

func GothicRegisterWithCore(scopeID, schemaID, schema string)

GothicRegisterWithCore is a no-op on the host build. The real implementation (js && wasm) performs the component→core registration RPC against the full-Go static core over the document control-plane bus. Like GothicRegisterSchema it is emitted by generated code only, never hand-written in a ClientSideState block, so it has no user-facing stub-parity obligation.

func HexDecode

func HexDecode(s string) []byte

func HexEncode

func HexEncode(src []byte) string

func ListenTopicCoreOnline

func ListenTopicCoreOnline(key string, fn func())

func ListenTopicEvent

func ListenTopicEvent(keyName string, fn func(string))

func ListenTopicEventField

func ListenTopicEventField(keyName, fieldName string, fn func([]byte))

func ListenTopicOnline

func ListenTopicOnline(keyName string, fn func(string))

func ListenTopicPing

func ListenTopicPing(keyName string, fn func())

func ListenTopicSetReq

func ListenTopicSetReq(keyName string, fn func(string))

func ListenTopicSetReqField

func ListenTopicSetReqField(keyName, fieldName string, fn func(string))

func LocalStorageGet

func LocalStorageGet(key string) string

func LocalStorageRemove

func LocalStorageRemove(key string)

func LocalStorageSet

func LocalStorageSet(key, value string)
func Navigate(url string)

func OnUnmount

func OnUnmount(fn func()) func()

OnUnmount is a no-op on the host build; the real implementation (js && wasm) appends the callback to the __gothic_registry[<scope>].__onUnmounts array so the bootstrap's per-scope teardown can invoke every registered callback. It returns a deregister func (a no-op here) so host builds match the WASM signature that drops a callback once it becomes dead weight.

func PingTopicManager

func PingTopicManager(keyName string)

func PingUntilOnline

func PingUntilOnline(keyName string, isOnline func() bool)

func PushState

func PushState(url, title string)

func RegisterTopicWithCore

func RegisterTopicWithCore(key string, fields []string)

Topic ↔ full-Go core control-plane. No-ops on the host build; the real implementations (js && wasm, topic.go) perform the register handshake and listen for the per-key online ack. Emitted by generated WASM code only, never hand-written in a ClientSideState block, so no user-facing stub-parity list.

func Reload

func Reload()

func RemoveClass

func RemoveClass(id, className string)

func RemoveElement

func RemoveElement(el JSValue)

func RequestTopicSet

func RequestTopicSet(keyName, encoded string)

func RequestTopicSetField

func RequestTopicSetField(keyName, fieldName, encoded string)

func RequestTopicSetFieldBytes

func RequestTopicSetFieldBytes(keyName, fieldName string, b []byte)

func RunInScope

func RunInScope(id string, fn func())

RunInScope runs fn with the given scope active, restoring the previous scope afterwards. Pair it with CaptureScope to carry a scope into a goroutine or deferred callback. Nesting is supported.

func SessionStorageGet

func SessionStorageGet(key string) string

func SessionStorageRemove

func SessionStorageRemove(key string)

func SessionStorageSet

func SessionStorageSet(key, value string)

func SetAttr

func SetAttr(id, attr, value string)

func SetHTML

func SetHTML(id, html string)

func SetStyle

func SetStyle(id, property, value string)

func SetText

func SetText(id, value string)

func SetValue

func SetValue(id, value string)

func ToggleClass

func ToggleClass(id, className string)

func TriggerDownload

func TriggerDownload(filename string, data []byte, mimeType string)

func UpdateTopicOnlineStore

func UpdateTopicOnlineStore(keyName string, encoded []byte)

func WriteClipboard

func WriteClipboard(text string)

Types

type AjaxOpts added in v1.4.0

type AjaxOpts struct {
	Target string
	Source string
	Swap   SwapStrategy
	Values map[string]string
}

AjaxOpts is the optional context for HTMX.Ajax (see js&&wasm for field meaning).

type Compression

type Compression int

Compression is the compression algorithm used for a topic's WASM payload.

const (
	GZIP   Compression = iota // default
	BROTLI Compression = iota
)

type CookieOptions

type CookieOptions struct {
	MaxAge   int
	Path     string
	SameSite string
	Secure   bool
}

type Decoder

type Decoder struct {
	Buf []byte
	Pos int
	Err error
}

Decoder reads a little-endian binary stream. Err accumulates the first decode error — check it once at the end rather than per call.

func NewDecoder

func NewDecoder(buf []byte) *Decoder

NewDecoder opens a frame produced by NewEncoder. It validates the WireVersion header byte at position 0 and positions Pos immediately after it, so the first typed read returns the frame's first field. On an empty buffer or a version mismatch it sets Err (leaving Pos at 0) and never panics — need() short- circuits all subsequent reads. Use this at every site that decodes a complete wire frame; per-field capture helpers that walk an already-opened Decoder keep using the raw &Decoder{} form.

func (*Decoder) Bool

func (d *Decoder) Bool() bool

func (*Decoder) Bytes

func (d *Decoder) Bytes() []byte

func (*Decoder) F32

func (d *Decoder) F32() float32

func (*Decoder) F64

func (d *Decoder) F64() float64

func (*Decoder) I32

func (d *Decoder) I32() int32

func (*Decoder) I64

func (d *Decoder) I64() int64

func (*Decoder) String

func (d *Decoder) String() string

func (*Decoder) U8

func (d *Decoder) U8() uint8

func (*Decoder) U16

func (d *Decoder) U16() uint16

func (*Decoder) U32

func (d *Decoder) U32() uint32

func (*Decoder) U64

func (d *Decoder) U64() uint64

type Encoder

type Encoder struct{ Buf []byte }

Encoder writes a little-endian binary stream into Buf. Preallocate with NewEncoder to avoid repeated append growth.

func NewEncoder

func NewEncoder(cap int) *Encoder

NewEncoder opens a new frame: it returns an *Encoder whose buffer already contains the single WireVersion header byte at position 0. Every subsequent write appends after it. Because nested encoders reuse this same *Encoder, the version byte appears exactly once per frame — at the frame boundary.

func (*Encoder) Bool

func (e *Encoder) Bool(v bool)

func (*Encoder) Bytes

func (e *Encoder) Bytes(v []byte)

func (*Encoder) F32

func (e *Encoder) F32(v float32)

func (*Encoder) F64

func (e *Encoder) F64(v float64)

func (*Encoder) I32

func (e *Encoder) I32(v int32)

func (*Encoder) I64

func (e *Encoder) I64(v int64)

func (*Encoder) String

func (e *Encoder) String(v string)

func (*Encoder) U8

func (e *Encoder) U8(v uint8)

func (*Encoder) U16

func (e *Encoder) U16(v uint16)

func (*Encoder) U32

func (e *Encoder) U32(v uint32)

func (*Encoder) U64

func (e *Encoder) U64(v uint64)

type Event added in v1.4.0

type Event = JSValue

Event is the browser Event passed to On/OnGlobal handlers (host: JSValue stub).

type FetchConfig

type FetchConfig struct {
	Method    string
	Headers   map[string]string
	Body      string
	BodyBytes []byte
	Query     map[string]string
}

type FetchResult added in v1.4.0

type FetchResult struct {
	Response Response
	Err      error
}

type HtmxEvent added in v1.4.0

type HtmxEvent string

HtmxEvent is a string-backed htmx event name (full htmx 2.0.3 catalog).

const (
	EvtAbort                     HtmxEvent = "htmx:abort"
	EvtAfterOnLoad               HtmxEvent = "htmx:afterOnLoad"
	EvtAfterProcessNode          HtmxEvent = "htmx:afterProcessNode"
	EvtAfterRequest              HtmxEvent = "htmx:afterRequest"
	EvtAfterSettle               HtmxEvent = "htmx:afterSettle"
	EvtAfterSwap                 HtmxEvent = "htmx:afterSwap"
	EvtBadResponseURL            HtmxEvent = "htmx:badResponseUrl"
	EvtBeforeCleanupElement      HtmxEvent = "htmx:beforeCleanupElement"
	EvtBeforeHistorySave         HtmxEvent = "htmx:beforeHistorySave"
	EvtBeforeHistoryUpdate       HtmxEvent = "htmx:beforeHistoryUpdate"
	EvtBeforeOnLoad              HtmxEvent = "htmx:beforeOnLoad"
	EvtBeforeProcessNode         HtmxEvent = "htmx:beforeProcessNode"
	EvtBeforeRequest             HtmxEvent = "htmx:beforeRequest"
	EvtBeforeSend                HtmxEvent = "htmx:beforeSend"
	EvtBeforeSwap                HtmxEvent = "htmx:beforeSwap"
	EvtBeforeTransition          HtmxEvent = "htmx:beforeTransition"
	EvtConfigRequest             HtmxEvent = "htmx:configRequest"
	EvtConfirm                   HtmxEvent = "htmx:confirm"
	EvtError                     HtmxEvent = "htmx:error"
	EvtEvalDisallowedError       HtmxEvent = "htmx:evalDisallowedError"
	EvtEventFilterError          HtmxEvent = "htmx:eventFilter:error"
	EvtHistoryCacheError         HtmxEvent = "htmx:historyCacheError"
	EvtHistoryCacheMiss          HtmxEvent = "htmx:historyCacheMiss"
	EvtHistoryCacheMissLoad      HtmxEvent = "htmx:historyCacheMissLoad"
	EvtHistoryCacheMissLoadError HtmxEvent = "htmx:historyCacheMissLoadError"
	EvtHistoryItemCreated        HtmxEvent = "htmx:historyItemCreated"
	EvtHistoryRestore            HtmxEvent = "htmx:historyRestore"
	EvtInvalidPath               HtmxEvent = "htmx:invalidPath"
	EvtLoad                      HtmxEvent = "htmx:load"
	EvtOnLoadError               HtmxEvent = "htmx:onLoadError"
	EvtOobAfterSwap              HtmxEvent = "htmx:oobAfterSwap"
	EvtOobBeforeSwap             HtmxEvent = "htmx:oobBeforeSwap"
	EvtOobErrorNoTarget          HtmxEvent = "htmx:oobErrorNoTarget"
	EvtPrompt                    HtmxEvent = "htmx:prompt"
	EvtPushedIntoHistory         HtmxEvent = "htmx:pushedIntoHistory"
	EvtReplacedInHistory         HtmxEvent = "htmx:replacedInHistory"
	EvtResponseError             HtmxEvent = "htmx:responseError"
	EvtRestored                  HtmxEvent = "htmx:restored"
	EvtSendAbort                 HtmxEvent = "htmx:sendAbort"
	EvtSendError                 HtmxEvent = "htmx:sendError"
	EvtSwapError                 HtmxEvent = "htmx:swapError"
	EvtSyntaxError               HtmxEvent = "htmx:syntax:error"
	EvtTargetError               HtmxEvent = "htmx:targetError"
	EvtTimeout                   HtmxEvent = "htmx:timeout"
	EvtTrigger                   HtmxEvent = "htmx:trigger"
	EvtValidateURL               HtmxEvent = "htmx:validateUrl"
	EvtValidationValidate        HtmxEvent = "htmx:validation:validate"
	EvtValidationFailed          HtmxEvent = "htmx:validation:failed"
	EvtValidationHalted          HtmxEvent = "htmx:validation:halted"
	EvtXHRAbort                  HtmxEvent = "htmx:xhr:abort"
	EvtXHRLoadstart              HtmxEvent = "htmx:xhr:loadstart"
	EvtXHRLoadend                HtmxEvent = "htmx:xhr:loadend"
	EvtXHRProgress               HtmxEvent = "htmx:xhr:progress"
)

type JSValue

type JSValue struct{}

func CreateElement

func CreateElement(tag string) JSValue

func CreateWasmFuncWithReturn

func CreateWasmFuncWithReturn(name string, fn func(this JSValue, args []JSValue) any) JSValue

func Document

func Document() JSValue

func GetElementById

func GetElementById(id string) JSValue

func JS

func JS() JSValue

func QuerySelector

func QuerySelector(sel string) JSValue

func QuerySelectorAll

func QuerySelectorAll(sel string) JSValue

func Window

func Window() JSValue

func (JSValue) Bool

func (v JSValue) Bool() bool

func (JSValue) Call

func (v JSValue) Call(method string, args ...any) JSValue

func (JSValue) Float

func (v JSValue) Float() float64

func (JSValue) Get

func (v JSValue) Get(key string) JSValue

func (JSValue) Index

func (v JSValue) Index(i int) JSValue

func (JSValue) Int

func (v JSValue) Int() int

func (JSValue) IsNull

func (v JSValue) IsNull() bool

func (JSValue) IsUndefined

func (v JSValue) IsUndefined() bool

func (JSValue) Length

func (v JSValue) Length() int

func (JSValue) New

func (v JSValue) New(args ...any) JSValue

func (JSValue) Set

func (v JSValue) Set(key string, val any)

func (JSValue) SetIndex

func (v JSValue) SetIndex(i int, val any)

func (JSValue) String

func (v JSValue) String() string

func (JSValue) Truthy

func (v JSValue) Truthy() bool

type Observable

type Observable[T any] struct {
	// contains filtered or unexported fields
}

func CreateObservable

func CreateObservable[T any](initial T) *Observable[T]

func (*Observable[T]) Get

func (s *Observable[T]) Get() T

func (*Observable[T]) Set

func (s *Observable[T]) Set(v T)

type ObservableField

type ObservableField[T any] struct {
	// contains filtered or unexported fields
}

ObservableField stub — no-op broadcast and tracking for server-side compilation.

func NewObservableField

func NewObservableField[T any](initial T) *ObservableField[T]

func (*ObservableField[T]) ApplyExternal

func (f *ObservableField[T]) ApplyExternal(v T)

func (*ObservableField[T]) Get

func (f *ObservableField[T]) Get() T

func (*ObservableField[T]) Peek

func (f *ObservableField[T]) Peek() T

func (*ObservableField[T]) Set

func (f *ObservableField[T]) Set(v T)

func (*ObservableField[T]) SetBroadcast

func (f *ObservableField[T]) SetBroadcast(fn func())

type Response added in v1.4.0

type Response struct {
	Status  int
	Headers map[string]string
	Body    []byte
}

func Fetch

func Fetch(url string, config ...FetchConfig) (Response, error)

func (Response) Bytes added in v1.4.0

func (r Response) Bytes() []byte

func (Response) MapAny added in v1.4.0

func (r Response) MapAny() (map[string]any, error)

MapAny is a server-side no-op mirror of the WASM runtime method (Response has no body server-side). Returns nil, nil — the real JSON parse happens only in the browser build (dom.go). It is a METHOD, so parity_surface_test.go's top-level-func check does not cover it; it must be mirrored here by hand.

func (Response) OK added in v1.4.0

func (r Response) OK() bool

func (Response) Text added in v1.4.0

func (r Response) Text() string

type SharedTopicObservable

type SharedTopicObservable[T any] struct {
	// contains filtered or unexported fields
}

func (*SharedTopicObservable[T]) Get

func (s *SharedTopicObservable[T]) Get() T

func (*SharedTopicObservable[T]) Set

func (s *SharedTopicObservable[T]) Set(v T)

type Subscription

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

func Observe

func Observe(fn func(), deps ...any) *Subscription

func ObserveWithCleanup

func ObserveWithCleanup(fn func() func(), deps ...any) *Subscription

func (*Subscription) Stop

func (e *Subscription) Stop()

type SwapStrategy added in v1.4.0

type SwapStrategy string

SwapStrategy is a string-backed htmx swap style (see js&&wasm for the vocabulary).

const (
	InnerHTML   SwapStrategy = "innerHTML"
	OuterHTML   SwapStrategy = "outerHTML"
	BeforeBegin SwapStrategy = "beforebegin"
	AfterBegin  SwapStrategy = "afterbegin"
	BeforeEnd   SwapStrategy = "beforeend"
	AfterEnd    SwapStrategy = "afterend"
	Delete      SwapStrategy = "delete"
	None        SwapStrategy = "none"
)

type TopicConfig

type TopicConfig struct {
	Name             string
	Compression      Compression  // GZIP (default) or BROTLI
	Compiler         WasmCompiler // GothicTinyGo (default), LocalTinyGo, or Golang
	SubscriberFnName string       // overrides generated accessor func name (default: <StructName>Topic)
}

TopicConfig holds per-topic configuration.

type TopicKey

type TopicKey[T any] struct {
	Name string
	// contains filtered or unexported fields
}

TopicKey is a typed topic identifier that carries its own codec.

func AutoKey

func AutoKey[T any](name string) TopicKey[T]

AutoKey is rewritten to BinaryKey by the CLI before TinyGo compiles. This stub exists so server-side code compiles without error.

func BinaryKey

func BinaryKey[T any](name string, encode func(T, *Encoder), decode func(*Decoder) T) TopicKey[T]

func BoolKey

func BoolKey(name string) TopicKey[bool]

func ByteKey

func ByteKey(name string) TopicKey[byte]

ByteKey is UintKey for byte (= uint8).

func CustomKey

func CustomKey[T any](name string, encode func(T) string, decode func(string) T) TopicKey[T]

func Float32Key

func Float32Key(name string) TopicKey[float32]

func Float64Key

func Float64Key(name string) TopicKey[float64]

func Int8Key

func Int8Key(name string) TopicKey[int8]

func Int16Key

func Int16Key(name string) TopicKey[int16]

func Int32Key

func Int32Key(name string) TopicKey[int32]

func Int64Key

func Int64Key(name string) TopicKey[int64]

func IntKey

func IntKey(name string) TopicKey[int]

func RuneKey

func RuneKey(name string) TopicKey[rune]

RuneKey is IntKey for rune (= int32).

func StringKey

func StringKey(name string) TopicKey[string]

func Uint8Key

func Uint8Key(name string) TopicKey[uint8]

func Uint16Key

func Uint16Key(name string) TopicKey[uint16]

func Uint32Key

func Uint32Key(name string) TopicKey[uint32]

func Uint64Key

func Uint64Key(name string) TopicKey[uint64]

func UintKey

func UintKey(name string) TopicKey[uint]

type WasmCompiler

type WasmCompiler int

WasmCompiler selects the WASM build toolchain for a topic.

const (
	GothicTinyGo WasmCompiler = iota // default: embedded TinyGo binary
	LocalTinyGo                      // system tinygo binary in PATH
	Golang                           // GOOS=js GOARCH=wasm standard Go compiler
)

Jump to

Keyboard shortcuts

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