dom

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 16 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

This section is empty.

Functions

func IsDOMError

func IsDOMError(err error) bool

func IsInvalidCharacterError

func IsInvalidCharacterError(err error) bool

func IsNotImplementedError

func IsNotImplementedError(err error) bool

func IsSyntaxError

func IsSyntaxError(err error) bool

func NewPointerEvent added in v0.4.0

func NewPointerEvent(type_ string, init PointerEventInit) *event.Event

func NewUIEvent added in v0.4.0

func NewUIEvent(type_ string) *event.Event

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

type Attributes []Attr

TODO: In the DOM, this is a `NamedNodeMap`. Is that useful in Go?

func (Attributes) Length

func (attrs Attributes) Length() int

type CharacterData

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

type Comment

type Comment interface {
	CharacterData
}

func NewComment

func NewComment(text string, ownerDocument Document) Comment

type DOMError

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

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

func (DOMTokenList) Length

func (l DOMTokenList) Length() int

func (DOMTokenList) Remove

func (l DOMTokenList) Remove(token string)

func (DOMTokenList) Replace

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

func (DOMTokenList) SetValue

func (l DOMTokenList) SetValue(val string)

func (DOMTokenList) Toggle

func (l DOMTokenList) Toggle(token string) bool

func (DOMTokenList) Value

func (l DOMTokenList) Value() string

type Document

type Document interface {
	RootNode
	Body() Element
	Head() Element
	CreateDocumentFragment() DocumentFragment
	CreateAttribute(string) Attr
	CreateText(data string) Text
	CreateComment(data string) Comment
	CreateDocumentType(name string) DocumentType
	CreateElementNS(string, string) Element
	CreateElement(string) Element
	DocumentElement() Element
	// contains filtered or unexported methods
}

func NewDocument

func NewDocument(window DocumentParentWindow) 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

type DocumentParentWindow deprecated

type DocumentParentWindow interface {
	event.EventTarget
	ParseFragment(ownerDocument Document, reader io.Reader) (DocumentFragment, error)
}

Deprecated: This interface is part of an implementation details, and it was an oversight that it wasn't placed in an internal package. This will be removed from the public API in a future version

type DocumentType

type DocumentType interface {
	Node
	Name() string
}

func NewDocumentType

func NewDocumentType(name string, ownerDocument Document) DocumentType

type Element

type Element interface {
	ElementContainer
	ElementEvents
	ClassList() DOMTokenList
	HasAttribute(name string) bool
	GetAttribute(name string) (string, bool)
	SetAttribute(name string, value string)
	GetAttributeNode(string) Attr
	SetAttributeNode(Attr) (Attr, error)
	RemoveAttributeNode(Attr) (Attr, error)
	Attributes() NamedNodeMap
	InsertAdjacentHTML(position string, text string) error
	OuterHTML() string
	InnerHTML() string
	TagName() string
	Matches(string) (bool, error)
	// 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
	ParentNode
}

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 ElementEvents deprecated added in v0.4.0

type ElementEvents interface {
	// Deprecated: auxclick is not a method defined on Element in the DOM
	Auxclick() bool
	// Deprecated: click is not a method defined on Element in the DOM
	Click() bool
	// Deprecated: contextmenu is not a method defined on Element in the DOM
	Contextmenu() bool
}

Deprecated: ElementEvents expose methods that are not part of the Element specification

type GetRootNodeOptions

type GetRootNodeOptions bool

type HTMLCollection added in v0.2.0

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

type MouseEventInit added in v0.4.0

type MouseEventInit struct {
	UIEventInit
	ScreenX int
	ScreenY int
}

type NamedNodeMap

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

type Node

type Node interface {
	entity.Entity
	event.EventTarget
	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
	OwnerDocument() Document
	Parent() Node
	ParentElement() Element
	RemoveChild(node Node) (Node, error)
	NextSibling() Node
	PreviousSibling() Node
	FirstChild() Node
	TextContent() string
	SetTextContent(value string)
	Connected()
	// 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)
	// contains filtered or unexported methods
}

type NodeList

type NodeList interface {
	entity.Entity
	Length() int
	Item(index int) Node
	All() []Node
	// contains filtered or unexported methods
}

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 NotImplementedError

type NotImplementedError error

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(nodes ...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(nodes ...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(nodes ...Node) error
	QuerySelector(string) (Element, error)
	QuerySelectorAll(string) (NodeList, error)
}

type PointerEventInit added in v0.4.0

type PointerEventInit struct {
	MouseEventInit
	PointerId int
}

type RootNode

type RootNode interface {
	ElementContainer
	GetElementById(string) Element
}

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

type UIEvent added in v0.4.0

type UIEvent = *event.Event

type UIEventInit added in v0.4.0

type UIEventInit struct {
	event.EventInit
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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