html

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package html works on top of dom to implement specific HTML elements

Index

Constants

View Source
const HistoryEventPopState = "popstate"

Variables

Functions

func NewDOMParser

func NewDOMParser() domParser

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(w Window, n dom.Element)

type ElementSteps

type ElementSteps interface {
	AppendChild(parent dom.Node, child dom.Node) dom.Node
	Connected(w Window, 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 FormDataEvent

type FormDataEvent interface {
	dom.Event
	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 {
	dom.Event
	Submitter() dom.Element
}

type GetReader

type GetReader interface {
	GetReader() io.Reader
}

type HTMLAnchorElement

type HTMLAnchorElement interface {
	HTMLElement
	Target() string
	SetTarget(string)
	Download() string
	SetDownload(string)
	Ping() string
	SetPing(string)
	Rel() string
	SetRel(string)
	RelList() string
	Hreflang() string
	SetHreflang(string)
	Type() string
	SetType(string)
	Text() string
	SetText(string)
	ReferrerPolicy() string
	SetReferrerPolicy(string)
	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)
}

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 {
	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, so do not depend on this value.

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

type HTMLElement

type HTMLElement interface {
	Element
	Renderer
	ChildrenRenderer
	// 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 HTMLInputElement

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

func NewHTMLInputElement

func NewHTMLInputElement(ownerDocument HTMLDocument) HTMLInputElement

type HTMLTemplateElement

type HTMLTemplateElement interface {
	HTMLElement
	Content() 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

func (*History) ReplaceState

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

ReplaceState the current [Window.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

type HistoryState

type HistoryState string
const EMPTY_STATE HistoryState = ""

type PopStateEvent

type PopStateEvent interface {
	dom.Event
	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
	Close()
}

type ScriptElementRules

type ScriptElementRules struct{ BaseRules }

func (ScriptElementRules) Connected

func (r ScriptElementRules) Connected(win Window, node dom.Element)

type ScriptHost

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

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 {
	EventTarget
	entity.Entity
	Document() Document
	Close()
	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 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 [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 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