dom

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 17 Imported by: 3

Documentation

Overview

Package dom provides the fundamental DOM implementation for Gost-DOM.

The DOM includes a Node implementation, and it's fundamental special types, such as Element, Document, Text, etc; as well as events througn the [EventTarget] type.

Specific implementation of HTML element types, including the HTMLDocument, is in the html package.

Index

Constants

This section is empty.

Variables

View Source
var ErrDOM = DOMError{}

Deprecated: Use ErrDom

View Source
var ErrDom = DOMError{}
View Source
var ErrInvalidCharacter = DOMError{Code: invalid_character_err}

ErrInvalidCharacter is the DOMException returned when adding a token containing whitespace to a DOMTokenList. This corresponds to InvalidCharacterError in JavaScript.

View Source
var ErrSyntax = DOMError{Message: "SyntaxError", Code: syntax_err}

ErrSyntax is the DOMException returned when adding an empty string to a DOMTokenList. This corresponds to a SyntaxError in JavaScript

Functions

func IsDOMError deprecated

func IsDOMError(err error) bool

Deprecated: Prefer using Errors.Is(err, ErrDom)

func IsInvalidCharacterError deprecated

func IsInvalidCharacterError(err error) bool

Deprecated: Will be removed - use errors.Is(err, ErrInvalidCharacter)

func IsNotImplementedError deprecated

func IsNotImplementedError(err error) bool

Deprecated: Will be removed

func IsSyntaxError deprecated

func IsSyntaxError(err error) bool

Deprecated: Will be removed

func ParseDocument added in v0.11.0

func ParseDocument(document Document, reader io.Reader) error

ParseDocument parses an HTML or XML document.

Types

type Attr

type Attr interface {
	Node
	LocalName() string
	Name() string
	NamespaceURI() string
	OwnerElement() Element
	Prefix() string
	Value() string
	SetValue(val string)
	// contains filtered or unexported methods
}

Attr is the interface corresponding to the Attr DOM node

type Attributes deprecated

type Attributes []Attr

Deprecated: This will be removed

func (Attributes) Length

func (attrs Attributes) Length() int

type ChangeEvent added in v0.5.1

type ChangeEvent struct {
	// The original target of the change.
	Target          Node
	Attr            Attr
	Type            ChangeEventType
	AddedNodes      NodeList
	RemovedNodes    NodeList
	OldValue        string
	PreviousSibling Node
	NextSibling     Node
}

type ChangeEventType added in v0.6.0

type ChangeEventType string
const (
	ChangeEventChildList  ChangeEventType = "childList"
	ChangeEventAttributes ChangeEventType = "attributes"
	ChangeEventCData      ChangeEventType = "characterData"
)

type CharacterData

type CharacterData interface {
	Node
	ChildNode
	Data() string
	SetData(string)
	Length() int
}

CharacterData is a "base type" for Text, Comment, and [CDataSection], and ProcessingInstruction.

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

type ChildNode added in v0.8.0

type ChildNode interface {
	Remove()
}

type Closer added in v0.5.1

type Closer interface {
	Close()
}

type Comment

type Comment interface {
	CharacterData
}

func NewComment

func NewComment(text string, ownerDocument Document) Comment

type ContentContainer added in v0.11.0

type ContentContainer interface {
	ReplaceChildren(...Node) error
}

type DOMError

type DOMError struct {
	Message string
	Code    domErrorCode
}

DOMError corresponds to DOMException in JavaScript

func (DOMError) Error added in v0.11.0

func (e DOMError) Error() string

func (DOMError) Is added in v0.11.0

func (e DOMError) Is(target error) bool

type DOMTokenList

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

func NewClassList

func NewClassList(element Element) DOMTokenList

func NewDOMTokenList added in v0.2.0

func NewDOMTokenList(attribute string, element Element) DOMTokenList

func (DOMTokenList) Add

func (l DOMTokenList) Add(tokens ...string) error

func (DOMTokenList) All

func (l DOMTokenList) All() iter.Seq[string]

func (DOMTokenList) Contains

func (l DOMTokenList) Contains(token string) bool

func (DOMTokenList) Item

func (l DOMTokenList) Item(index int) (string, bool)

func (DOMTokenList) Length

func (l DOMTokenList) Length() int

func (DOMTokenList) Remove

func (l DOMTokenList) Remove(token ...string) error

Remove implements DOMTokenList.Remove

see also: https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove

func (DOMTokenList) Replace

func (l DOMTokenList) Replace(oldToken string, newToken string) (bool, error)

func (DOMTokenList) SetValue

func (l DOMTokenList) SetValue(val string)

func (DOMTokenList) Toggle

func (l DOMTokenList) Toggle(token string) (bool, error)

func (DOMTokenList) Value

func (l DOMTokenList) Value() string

type Document

type Document interface {
	RootNode
	ElementOrDocument
	ActiveElement() Element
	Body() Element
	SetBody(Element) error
	Head() Element
	CreateDocumentFragment() DocumentFragment
	CreateAttribute(string) Attr
	CreateAttributeNS(string, string) Attr
	CreateTextNode(data string) Text
	CreateComment(data string) Comment
	CreateDocumentType(name string) DocumentType
	CreateElementNS(string, string) Element
	CreateElement(string) Element
	CreateProcessingInstruction(string, string) ProcessingInstruction
	DocumentElement() Element
	ImportNode(Node, bool) Node
}

func NewDocument

func NewDocument(parentEventTarget event.EventTarget) Document

type DocumentEvent

type DocumentEvent = string
const (
	DocumentEventDOMContentLoaded DocumentEvent = "DOMContentLoaded"
	DocumentEventLoad             DocumentEvent = "load"
)

type DocumentFragment

type DocumentFragment interface {
	RootNode
}

func NewDocumentFragment

func NewDocumentFragment(ownerDocument Document) DocumentFragment

func ParseFragment added in v0.11.0

func ParseFragment(doc Document, r io.Reader) (DocumentFragment, error)

ParseFragment parses an HTML or XML DocumentFragment.

type DocumentType

type DocumentType interface {
	Node
	ChildNode
	Name() string
}

func NewDocumentType

func NewDocumentType(name string, ownerDocument Document) DocumentType

type Element

type Element interface {
	ElementContainer
	ChildNode
	NonDocumentTypeChildNode
	ElementOrDocument
	ClassList() DOMTokenList
	Closest(string) (Element, error)
	HasAttribute(name string) bool
	GetAttribute(name string) (string, bool)
	SetAttribute(name string, value string)
	RemoveAttribute(name string)
	GetAttributeNode(string) Attr
	SetAttributeNode(Attr) (Attr, error)
	RemoveAttributeNode(Attr) (Attr, error)
	Attributes() NamedNodeMap
	InsertAdjacentElement(position string, element Element) (Element, error)
	InsertAdjacentHTML(position string, text string) error
	InsertAdjacentText(position string, text string) error
	OuterHTML() string
	SetOuterHTML(string) error
	InnerHTML() string
	SetInnerHTML(string) error
	TagName() string
	// Deprecated: Use NamespaceURI
	Namespace() string
	NamespaceURI() string
	LocalName() string
	Matches(string) (bool, error)
	ID() string
	SetID(string)
	// contains filtered or unexported methods
}

An Element in the document. Can be either an [HTMLElement] or an [XMLElement]

func NewElement

func NewElement(tagName string, ownerDocument Document) Element

type ElementContainer

type ElementContainer interface {
	Node
	ElementParent
}

ElementContainer defines common functionality in Document, DocumentFragment, and Element. While they all have Node as the direct base class in the DOM spec; they share a common set of functions operating on elements

type ElementOrDocument added in v0.11.0

type ElementOrDocument interface {
	GetElementsByTagName(name string) HTMLCollection
	GetElementsByTagNameNS(ns, name string) HTMLCollection
}

ElementOrDocument doesn't correspond to an interface in the web IDL specs. It contains common operations between dom Elements and documents.

type ElementParent added in v0.8.0

type ElementParent = ParentNode

ElementParent is a type alias for ParentNode that allows it to be embedded in other interfaces and types, without conflicting with the ParentNode method on Node

type GetRootNodeOptions

type GetRootNodeOptions bool

type HTMLCollection added in v0.2.0

type HTMLCollection interface {
	All() []Element
	Length() int
	Item(int) Element
	NamedItem(string) Element
}

type NamedNodeMap

type NamedNodeMap interface {
	entity.Components
	All() iter.Seq[Attr]
	Length() int
	Item(index int) Attr
}

type Node

type Node interface {
	// Deprecated: This will be removed
	entity.ObjectIder
	entity.Components
	event.EventTarget
	Logger() log.Logger
	AppendChild(node Node) (Node, error)
	GetRootNode(options ...GetRootNodeOptions) Node
	ChildNodes() NodeList
	CloneNode(deep bool) Node
	IsConnected() bool
	// IsSameNode shouldn't be used and may be removed in a future version.
	IsSameNode(Node) bool
	Contains(node Node) bool
	InsertBefore(newNode Node, referenceNode Node) (Node, error)
	NodeName() string
	NodeType() NodeType
	NodeValue() (string, bool)
	SetNodeValue(string)
	OwnerDocument() Document
	ParentNode() Node
	ParentElement() Element
	RemoveChild(node Node) (Node, error)
	ReplaceChild(node, child Node) (Node, error)
	NextSibling() Node
	PreviousSibling() Node
	FirstChild() Node
	LastChild() Node
	TextContent() string
	SetTextContent(value string)
	Connected()
	IsEqualNode(Node) bool
	// SetSelf must be called when creating instances of structs embedding a Node.
	//
	// If this is not called, the specialised type, which is itself a Node, will
	// not be returned from functions that should have returned it, e.g., through
	// ChildNodes. Only the embedded Node will be returned, and any specialised
	// behaviour, including HTML output, will not work.
	//
	// This function is a workaround to solve a fundamental problem. The DOM
	// specifies a model that is fundamentally object-oriented, with sub-classes
	// overriding behaviour in super-classes. This is not a behaviour that Go has.
	SetSelf(node Node)

	Observe(observer) Closer
	// contains filtered or unexported methods
}

type NodeList

type NodeList interface {
	entity.Components
	Length() int

	// Item returns the node with the specified zero-based index. If the index
	// is out of range, the function returns nil.
	Item(index int) Node

	// Deprecated: Will converted into a iter.Seq return type
	All() []Node
}

NodeList corresponds to the NodeList IDL interface.

see also: https://developer.mozilla.org/en-US/docs/Web/API/NodeList

type NodeType

type NodeType int
const (
	NodeTypeElement               NodeType = 1
	NodeTypeAttribute             NodeType = 2
	NodeTypeText                  NodeType = 3
	NodeTypeCDataSection          NodeType = 4
	NodeTypeProcessingInstruction NodeType = 7
	NodeTypeComment               NodeType = 8
	NodeTypeDocument              NodeType = 9
	NodeTypeDocumentType          NodeType = 10
	NodeTypeDocumentFragment      NodeType = 11
)

func (NodeType) String

func (t NodeType) String() string

String returns name of the node type. For invalid values, a string representation of the integer value is returned.

type NonDocumentTypeChildNode added in v0.6.0

type NonDocumentTypeChildNode interface {
	PreviousElementSibling() Element
	NextElementSibling() Element
}

type NonElementParentNode added in v0.11.0

type NonElementParentNode interface {
	GetElementById(string) Element
}

type NotImplementedError deprecated

type NotImplementedError error

Deprecated: Unused, will be removed

type ParentNode added in v0.2.0

type ParentNode interface {
	Children() HTMLCollection
	FirstElementChild() Element
	LastElementChild() Element
	ChildElementCount() int
	/*
	   Note that the IDL operation accepts either string or node values. This interface
	   requires an explicit a [Node]. Use [Document.CreateText] to convert a string to
	   a Node.

	   See also: https://developer.mozilla.org/en-US/docs/Web/API/Element
	*/
	Prepend(...Node) error
	/*
	   Note that the IDL operation accepts either string or node values. This interface
	   requires an explicit a [Node]. Use [Document.CreateText] to convert a string to
	   a Node.

	   See also: https://developer.mozilla.org/en-US/docs/Web/API/Element
	*/
	Append(...Node) error
	/*
	   Note that the IDL operation accepts either string or node values. This interface
	   requires an explicit a [Node]. Use [Document.CreateText] to convert a string to
	   a Node.

	   See also: https://developer.mozilla.org/en-US/docs/Web/API/Element
	*/
	ReplaceChildren(...Node) error
	QuerySelector(string) (Element, error)
	QuerySelectorAll(string) (NodeList, error)
}

type ProcessingInstruction deprecated added in v0.10.3

type ProcessingInstruction interface {
	CharacterData
}

ProcessingInstruction represents an XML processing instruction.

Deprecated: This only exists to support Web Platform Tests. It may be removed.

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

func NewProcessingInstruction deprecated added in v0.10.3

func NewProcessingInstruction(target, data string, ownerDocument Document) ProcessingInstruction

NewProcessingInstruction creates a new ProcessingInstruction.

Deprecated: This only exists to support Web Platform Tests

type RootNode

type RootNode interface {
	ElementContainer
	NonElementParentNode
}

RootNode implements defines common behaviour between Document and DocumentFragment. While they both have Node as the direct base class in the DOM spec; they share a common set of functions operating on elements.

type ShadowRoot

type ShadowRoot interface {
	DocumentFragment
}

type Text

type Text interface {
	CharacterData
}

func NewText

func NewText(text string, ownerDocument Document) Text

Directories

Path Synopsis
Package event contains core browser event behavior
Package event contains core browser event behavior

Jump to

Keyboard shortcuts

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