Documentation
¶
Overview ¶
Package html works on top of dom to implement specific HTML elements
Index ¶
- Constants
- Variables
- func NewDOMParser() domParser
- type BaseRules
- type ElementSteps
- type FormData
- func (d *FormData) AddElement(e dom.Element)
- func (d *FormData) Append(name string, value FormDataValue)
- func (d *FormData) Delete(name string)
- func (d *FormData) Get(name string) FormDataValue
- func (d *FormData) GetAll(name string) []FormDataValue
- func (d *FormData) GetReader() io.Reader
- func (d *FormData) Has(name string) bool
- func (d *FormData) Keys() []string
- func (d *FormData) QueryString() string
- func (d *FormData) Set(name string, value FormDataValue)
- func (d *FormData) Values() []FormDataValue
- type FormDataEntry
- type FormDataEvent
- type FormDataValue
- type FormEvent
- type FormSubmitEvent
- type GetReader
- type HTMLAnchorElement
- type HTMLButtonElement
- type HTMLDocument
- type HTMLElement
- type HTMLFormElement
- type HTMLInputElement
- type HTMLTemplateElement
- type History
- func (h *History) Back() error
- func (h *History) Forward() error
- func (h *History) Go(relative int) error
- func (h History) Length() int
- func (h *History) PushState(state HistoryState, href string) error
- func (h *History) ReplaceState(state HistoryState, href string) error
- func (h History) State() HistoryState
- type HistoryState
- type PopStateEvent
- type Predicate
- type ScriptContext
- type ScriptElementRules
- type ScriptHost
- type TemplateElementRules
- type Window
- type WindowOption
- type WindowOptionFunc
- type WindowOptions
Constants ¶
const HistoryEventPopState = "popstate"
Variables ¶
var ElementMap = map[atom.Atom]ElementSteps{ atom.Template: TemplateElementRules{}, }
Functions ¶
func NewDOMParser ¶
func NewDOMParser() domParser
Types ¶
type ElementSteps ¶
type FormData ¶
type FormData struct {
Entries []FormDataEntry
}
func NewFormData ¶
func NewFormData() *FormData
func NewFormDataForm ¶
func NewFormDataForm(form HTMLFormElement) *FormData
func (*FormData) AddElement ¶
func (*FormData) Append ¶
func (d *FormData) Append(name string, value FormDataValue)
func (*FormData) Get ¶
func (d *FormData) Get(name string) FormDataValue
func (*FormData) GetAll ¶
func (d *FormData) GetAll(name string) []FormDataValue
func (*FormData) QueryString ¶
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 FormDataValue ¶
type FormDataValue string // TODO Blob/file
func NewFormDataValueString ¶
func NewFormDataValueString(value string) FormDataValue
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 ¶
Back calls Go(-1).
See also: https://developer.mozilla.org/en-US/docs/Web/API/History/back
func (*History) Forward ¶
Forward calls Go(1).
See also: https://developer.mozilla.org/en-US/docs/Web/API/History/forward
func (*History) Go ¶
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 ¶
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) 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 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 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 }
type ScriptHost ¶
type ScriptHost interface {
NewContext(window Window) ScriptContext
Close()
}
type TemplateElementRules ¶
type TemplateElementRules struct{ BaseRules }
func (TemplateElementRules) AppendChild ¶
type Window ¶
type Window interface {
EventTarget
entity.Entity
Document() Document
Close()
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)