html

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package html works on top of the DOM to implement specific HTML elements.

The fundamental structure is implemented in package dom.

Index

Constants

View Source
const HistoryEventPopState = "popstate"

Variables

Functions

func NewDOMParser

func NewDOMParser() domParser

func ParseFragment added in v0.3.0

func ParseFragment(
	ownerDocument dom.Document,
	reader io.Reader,
) (dom.DocumentFragment, error)

Types

type BaseRules

type BaseRules struct{}

func (BaseRules) AppendChild

func (r BaseRules) AppendChild(parent dom.Node, child dom.Node) dom.Node

func (BaseRules) Connected

func (r BaseRules) Connected(n dom.Element)

type Clock added in v0.3.0

type Clock interface {
	RunAll() error
	Advance(time.Duration) error
}

type DOMStringList added in v0.2.0

type DOMStringList interface {
	Length() int
	Item(int) (string, bool)
	Contains(string) bool
}

type DOMStringMap added in v0.5.0

type DOMStringMap struct{ Element dom.Element }

DOMStringMap provides access to data-* attributes of an HTML or SVG element. In JavaScript, it is a dictionary-like object wrapping content with a "data-" prefix, converting kebab-case to camel-case, and stripping the prefix.

See also: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset

func (DOMStringMap) Delete added in v0.5.0

func (m DOMStringMap) Delete(key string)

func (DOMStringMap) Get added in v0.5.0

func (m DOMStringMap) Get(key string) (val string, exists bool)

func (DOMStringMap) Set added in v0.5.0

func (m DOMStringMap) Set(key string, val string)

type ElementSteps

type ElementSteps interface {
	AppendChild(parent dom.Node, child dom.Node) dom.Node
	Connected(n dom.Element)
}

type FormData

type FormData struct {
	Entries []FormDataEntry
}

func NewFormData

func NewFormData() *FormData

func NewFormDataForm

func NewFormDataForm(form HTMLFormElement) *FormData

func (*FormData) AddElement

func (d *FormData) AddElement(e dom.Element)

func (*FormData) Append

func (d *FormData) Append(name string, value FormDataValue)

func (*FormData) Delete

func (d *FormData) Delete(name string)

func (*FormData) Get

func (d *FormData) Get(name string) FormDataValue

func (*FormData) GetAll

func (d *FormData) GetAll(name string) []FormDataValue

func (*FormData) GetReader

func (d *FormData) GetReader() io.Reader

func (*FormData) Has

func (d *FormData) Has(name string) bool

func (*FormData) Keys

func (d *FormData) Keys() []string

func (*FormData) QueryString

func (d *FormData) QueryString() string

QueryString returns the formdata as a &-separated URL encoded key-value pair.

func (*FormData) Set

func (d *FormData) Set(name string, value FormDataValue)

func (*FormData) Values

func (d *FormData) Values() []FormDataValue

type FormDataEntry

type FormDataEntry struct {
	Name  string
	Value FormDataValue
}

type FormDataEventInit added in v0.4.0

type FormDataEventInit struct {
	FormData *FormData
}

type FormDataValue

type FormDataValue string // TODO Blob/file

func NewFormDataValueString

func NewFormDataValueString(value string) FormDataValue

type FormEvent

type FormEvent string
const (
	FormEventFormData FormEvent = "formdata"
	FormEventSubmit   FormEvent = "submit"
	FormEventReset    FormEvent = "reset"
)

type FormSubmitEvent

type FormSubmitEvent interface {
	event.Event
	Submitter() dom.Element
}

type GetReader

type GetReader interface {
	GetReader() io.Reader
}

type HTMLAnchorElement

type HTMLAnchorElement interface {
	HTMLElement
	HTMLHyperlinkElementUtils
	Target() string
	SetTarget(string)
	Download() string
	SetDownload(string)
	Ping() string
	SetPing(string)
	Rel() string
	SetRel(string)
	RelList() dom.DOMTokenList
	Hreflang() string
	SetHreflang(string)
	Type() string
	SetType(string)
	Text() string
	SetText(string)
	ReferrerPolicy() string
	SetReferrerPolicy(string)
}

func NewHTMLAnchorElement

func NewHTMLAnchorElement(ownerDoc HTMLDocument) HTMLAnchorElement

type HTMLButtonElement

type HTMLButtonElement interface {
	HTMLElement
	Type() string
	SetType(val string)
}

func NewHTMLButtonElement

func NewHTMLButtonElement(ownerDocument HTMLDocument) HTMLButtonElement

type HTMLDocument

type HTMLDocument interface {
	dom.Document
	// contains filtered or unexported methods
}

func NewHTMLDocument

func NewHTMLDocument(window Window) HTMLDocument

NewHTMLDocument creates an HTML document for an about:blank page.

The resulting document has an outer HTML similar to this, but there are no guarantees about the actual content.

<html><head></head><body><h1>Gost-DOM</h1></body></html>

type HTMLElement

type HTMLElement interface {
	dom.Element
	Renderer
	ChildrenRenderer
	HTMLOrSVGElement
	Click()
	// contains filtered or unexported methods
}

func NewHTMLElement

func NewHTMLElement(tagName string, ownerDocument HTMLDocument) HTMLElement

func NewHTMLScriptElement

func NewHTMLScriptElement(ownerDocument HTMLDocument) HTMLElement

type HTMLFormElement

type HTMLFormElement interface {
	HTMLElement
	Action() string
	SetAction(val string)
	Method() string
	SetMethod(value string)
	Elements() dom.NodeList
	Submit() error
	RequestSubmit(submitter dom.Element) error
}

func NewHtmlFormElement

func NewHtmlFormElement(ownerDocument HTMLDocument) HTMLFormElement

type HTMLHyperlinkElementUtils added in v0.2.0

type HTMLHyperlinkElementUtils interface {
	fmt.Stringer
	Href() string
	SetHref(string)
	Origin() string
	Protocol() string
	SetProtocol(string)
	Username() string
	SetUsername(string)
	Password() string
	SetPassword(string)
	Host() string
	SetHost(string)
	Hostname() string
	SetHostname(string)
	Port() string
	SetPort(string)
	Pathname() string
	SetPathname(string)
	Search() string
	SetSearch(string)
	Hash() string
	SetHash(string)
}

type HTMLInputElement

type HTMLInputElement interface {
	HTMLElement
	Type() string
	SetType(value string)
	Name() string
	CheckValidity() bool
}

func NewHTMLInputElement

func NewHTMLInputElement(ownerDocument HTMLDocument) HTMLInputElement

type HTMLOrSVGElement added in v0.5.0

type HTMLOrSVGElement interface {
	Dataset() DOMStringMap
	Nonce() string
	SetNonce(string)
	Autofocus() bool
	SetAutofocus(bool)
	TabIndex() int
	SetTabIndex(int)
	Focus()
	Blur()
}

type HTMLScriptElement added in v0.1.1

type HTMLScriptElement = HTMLElement

type HTMLTemplateElement

type HTMLTemplateElement interface {
	HTMLElement
	Content() dom.DocumentFragment
}

func NewHTMLTemplateElement

func NewHTMLTemplateElement(ownerDocument HTMLDocument) HTMLTemplateElement

type History

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

History implements the History API

Note: Currently, state is represented by string, but may change to a different type representing a JSON object.

func (*History) Back

func (h *History) Back() error

Back calls Go(-1).

See also: https://developer.mozilla.org/en-US/docs/Web/API/History/back

func (*History) Forward

func (h *History) Forward() error

Forward calls Go(1).

See also: https://developer.mozilla.org/en-US/docs/Web/API/History/forward

func (*History) Go

func (h *History) Go(relative int) error

Go moves back or forward through the history, possibly reloading the page if necessary. A negative value goes back in history; a positive value moves forward if possible. A value of 0 will trigger a reload.

See also: https://developer.mozilla.org/en-US/docs/Web/API/History/go

func (History) Length

func (h History) Length() int

Length returns the number of entries in the history. When navigating back, the length doesn't change, as they last viewed page is still in history.

Navigating to a new location truncates future history later than the current page.

func (*History) PushState

func (h *History) PushState(state HistoryState, href string) error

ReplaceState will update the current Location and push this as a new history entry without making a new request.

The function corresponds to replaceState on the History API with the following notes. If href is empty, the URL will not be updated; as if the argument was not specified in the JS API.

func (*History) ReplaceState

func (h *History) ReplaceState(state HistoryState, href string) error

ReplaceState will update the current Location and history entry without making a new request.

The function corresponds to replaceState on the History API with the following notes. If href is empty, the URL will not be updated; as if the argument was not specified in the JS API.

func (History) State

func (h History) State() HistoryState

State returns the state for the current page.

type HistoryState

type HistoryState string
const EMPTY_STATE HistoryState = ""

type Location added in v0.2.0

type Location interface {
	fmt.Stringer
	Href() string
	SetHref(string)
	Origin() string
	Protocol() string
	SetProtocol(string)
	Host() string
	SetHost(string)
	Hostname() string
	SetHostname(string)
	Port() string
	SetPort(string)
	Pathname() string
	SetPathname(string)
	Search() string
	SetSearch(string)
	Hash() string
	SetHash(string)
	AncestorOrigins() DOMStringList
	Assign(string) error
	Replace(string) error
	Reload() error
}

type PopStateEventInit added in v0.4.0

type PopStateEventInit struct {
	State HistoryState
}

The PopStateEvent is emitted after navigating to the same document, and will contain possible state passed to History.ReplaceState or History.PushState.

See also: https://developer.mozilla.org/en-US/docs/Web/API/PopStateEvent

type Predicate

type Predicate[T any] func(T) bool

type ScriptContext

type ScriptContext interface {
	// Run a script, and convert the result to a Go type. Only use this if you
	// need the return value, otherwise call Run.
	//
	// If the evaluated JS value cannot be converted to a Go value, an error is
	// returned.
	Eval(script string) (any, error)
	// Run a script. This is should be used instead of eval when the return value
	// is not needed, as eval could generate an error if the value cannot be
	// converted to a go-type.
	Run(script string) error
	Clock() Clock
	Close()
}

type ScriptHost

type ScriptHost interface {
	NewContext(window Window) ScriptContext
	Close()
}

type SetActiveElementer added in v0.5.0

type SetActiveElementer interface {
	SetActiveElement(e dom.Element)
}

type SubmitEventInit added in v0.4.0

type SubmitEventInit struct {
	Submitter dom.Element
}

type TemplateElementRules

type TemplateElementRules struct{ BaseRules }

func (TemplateElementRules) AppendChild

func (TemplateElementRules) AppendChild(parent dom.Node, child dom.Node) dom.Node

type Window

type Window interface {
	event.EventTarget
	entity.ObjectIder
	Document() dom.Document
	Close()
	Clock() Clock
	Navigate(string) error // TODO: Remove, perhaps? for testing
	LoadHTML(string) error // TODO: Remove, for testing
	Eval(string) (any, error)
	Run(string) error
	ScriptContext() ScriptContext
	Location() Location
	History() *History
	HTTPClient() http.Client
	ParseFragment(ownerDocument dom.Document, reader io.Reader) (dom.DocumentFragment, error)
	// contains filtered or unexported methods
}

func NewWindow

func NewWindow(windowOptions ...WindowOption) Window

func NewWindowReader

func NewWindowReader(reader io.Reader, windowOptions ...WindowOption) (Window, error)

NewWindowReader will create a new window and load parse the HTML from the reader. If there is an error reading from the stream, or parsing the DOM, an error is returned.

If this function returns without an error, the DOM will have been parsed and the DOMContentLoaded event has been dispached on the dom.Document

func OpenWindowFromLocation

func OpenWindowFromLocation(location string, windowOptions ...WindowOption) (Window, error)

type WindowOption

type WindowOption interface {
	Apply(options *WindowOptions)
}

type WindowOptionFunc

type WindowOptionFunc func(*WindowOptions)

func WindowOptionHost added in v0.3.0

func WindowOptionHost(host ScriptHost) WindowOptionFunc

func WindowOptionLocation

func WindowOptionLocation(location string) WindowOptionFunc

func (WindowOptionFunc) Apply

func (f WindowOptionFunc) Apply(options *WindowOptions)

type WindowOptions

type WindowOptions struct {
	ScriptHost
	HttpClient   http.Client
	BaseLocation string
}

func (WindowOptions) Apply

func (o WindowOptions) Apply(options *WindowOptions)

Jump to

Keyboard shortcuts

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