dom

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package dom provides a basic DOM manipulation wrapper using syscall/js.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClass

func AddClass(elemID, class string)

------------------------------------------------------------------------------------------------ AddClass adds a CSS class to the element looked up by ID.

func AddElementTo

func AddElementTo(target, elem Handle)

------------------------------------------------------------------------------------------------ AddElementTo appends a child element to a target element.

func AddEventListener

func AddEventListener(elem Handle, event string, cb js.Value)

------------------------------------------------------------------------------------------------ AddEventListener registers an event listener on the element.

func AddEventListenerByID

func AddEventListenerByID(id, event string, cb js.Value)

------------------------------------------------------------------------------------------------ AddEventListenerByID registers an event listener on the element matching the ID.

func AddNewStyleElement

func AddNewStyleElement(css string)

------------------------------------------------------------------------------------------------ AddNewStyleElement injects a style block with raw CSS rules into document head.

func AddToBody

func AddToBody(elem Handle)

------------------------------------------------------------------------------------------------ AddToBody appends a child element to the document body.

func Alert

func Alert(msg string)

------------------------------------------------------------------------------------------------ Alert triggers a browser modal dialog with the specified message.

func GetString

func GetString(elemID, key string) string

------------------------------------------------------------------------------------------------ GetString retrieves a string property from an element by ID.

func Hide

func Hide(id string)

------------------------------------------------------------------------------------------------ Hide sets display to "none" on the element matching the ID.

func Init

func Init()

------------------------------------------------------------------------------------------------ Init captures global JS references from the browser.

func Log

func Log(messages []string)

------------------------------------------------------------------------------------------------ Log logs a slice of strings to the browser developer console.

func RemoveAllChildElementsFrom

func RemoveAllChildElementsFrom(target Handle)

------------------------------------------------------------------------------------------------ RemoveAllChildElementsFrom removes all children from the target element.

func RemoveClass

func RemoveClass(elemID, class string)

------------------------------------------------------------------------------------------------ RemoveClass removes a CSS class from the element looked up by ID.

func SetFocus

func SetFocus(id string)

------------------------------------------------------------------------------------------------ SetFocus calls focus() on the element matching the ID.

func SetValue

func SetValue(elemID, key, value string)

------------------------------------------------------------------------------------------------ SetValue sets a string property on an element by ID.

func Show

func Show(id string)

------------------------------------------------------------------------------------------------ Show sets display to "block" on the element matching the ID.

func StartAnimationLoop

func StartAnimationLoop(cb js.Value) (stop func())

------------------------------------------------------------------------------------------------ StartAnimationLoop drives a 60 FPS animation cycle via requestAnimationFrame. It returns a stop function; calling it halts the loop and releases the JS closure.

Types

type Context2D

type Context2D struct {
	Ctx Handle
}

------------------------------------------------------------------------------------------------ Context2D wraps the canvas 2D rendering context.

func (Context2D) Arc

func (c Context2D) Arc(x, y, radius, startAngle, endAngle float64, ccw bool)

------------------------------------------------------------------------------------------------ Arc draws a circular arc on the rendering context.

func (Context2D) BeginPath

func (c Context2D) BeginPath()

------------------------------------------------------------------------------------------------ BeginPath begins a new path in the rendering context.

func (Context2D) Fill

func (c Context2D) Fill()

------------------------------------------------------------------------------------------------ Fill fills the current path with the current fill style.

func (Context2D) FillStyle

func (c Context2D) FillStyle(style string)

------------------------------------------------------------------------------------------------ FillStyle sets the fill style/color of the rendering context.

type Handle

type Handle js.Value

------------------------------------------------------------------------------------------------ Handle represents a reference to a live JS object in the browser.

var (
	Document Handle
	Body     Handle
	Head     Handle
)

------------------------------------------------------------------------------------------------ Global element references.

var Invalid Handle

------------------------------------------------------------------------------------------------ Invalid represents a null/invalid handle.

func CanvasCreate

func CanvasCreate(parent Handle, width, height int) Handle

------------------------------------------------------------------------------------------------ CanvasCreate creates a canvas element and appends it to parent.

func CanvasGetContext

func CanvasGetContext(canvas Handle) Handle

------------------------------------------------------------------------------------------------ CanvasGetContext retrieves the 2D rendering context of the canvas.

func CreateButton

func CreateButton(text string) Handle

------------------------------------------------------------------------------------------------ CreateButton creates a button element of type "button" with pre-set inner text.

func CreateDiv

func CreateDiv() Handle

------------------------------------------------------------------------------------------------ CreateDiv creates a new div element.

func CreateElement

func CreateElement(tag string) Handle

------------------------------------------------------------------------------------------------ CreateElement creates a new HTML element of the given tag name.

func CreateImg

func CreateImg(src string) Handle

------------------------------------------------------------------------------------------------ CreateImg creates an img element with pre-set src.

func CreateParagraph

func CreateParagraph() Handle

------------------------------------------------------------------------------------------------ CreateParagraph creates a new p element.

func CreateParagraphWithText

func CreateParagraphWithText(text string) Handle

------------------------------------------------------------------------------------------------ CreateParagraphWithText creates a new p element with pre-set inner text.

func GetElementByID

func GetElementByID(id string) Handle

------------------------------------------------------------------------------------------------ GetElementByID returns the element handle matching the specified ID.

func WrapElementWithNewDiv

func WrapElementWithNewDiv(element Handle, classes []string) Handle

------------------------------------------------------------------------------------------------ WrapElementWithNewDiv wraps an existing element in a new div with the given classes.

func (Handle) AddClassTo

func (h Handle) AddClassTo(class string)

------------------------------------------------------------------------------------------------ AddClassTo adds a CSS class to the element.

func (Handle) Get

func (h Handle) Get(key string) string

------------------------------------------------------------------------------------------------ Get gets a JS property on the handle as a string.

func (Handle) IsValid

func (h Handle) IsValid() bool

------------------------------------------------------------------------------------------------ IsValid checks if the handle is valid (truthy in the JS sense).

func (Handle) RemoveClassFrom

func (h Handle) RemoveClassFrom(class string)

------------------------------------------------------------------------------------------------ RemoveClassFrom removes a CSS class from the element.

func (Handle) ReplaceClasses

func (h Handle) ReplaceClasses(classes []string)

------------------------------------------------------------------------------------------------ ReplaceClasses replaces all classes on the element with the given list.

func (Handle) Set

func (h Handle) Set(key string, value any)

------------------------------------------------------------------------------------------------ Set sets a JS property on the handle to an arbitrary value.

func (Handle) SetInnerHTML

func (h Handle) SetInnerHTML(html string)

------------------------------------------------------------------------------------------------ SetInnerHTML sets the inner HTML of an element.

func (Handle) SetInnerText

func (h Handle) SetInnerText(text string)

------------------------------------------------------------------------------------------------ SetInnerText sets the inner text of an element.

Jump to

Keyboard shortcuts

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