Documentation
¶
Overview ¶
Package dom defines Growse's browser-owned document model.
Index ¶
- type Document
- func (d *Document) AppendChild(parent, child *Node) error
- func (d *Document) ApplySnapshot(snapshot DocumentSnapshot) error
- func (d *Document) CreateElement(tagName string, attributes map[string]string) *Node
- func (d *Document) CreateText(text string) *Node
- func (d *Document) DetachChild(parent, child *Node) bool
- func (d *Document) ElementCount() int
- func (d *Document) GetElementByID(id string) (*Node, bool)
- func (d *Document) GetElementsByClassName(value string) []*Node
- func (d *Document) GetElementsByTagName(value string) []*Node
- func (d *Document) InsertChild(parent, child *Node, index int) error
- func (d *Document) IsConnected(node *Node) bool
- func (d *Document) NodeByID(id NodeID) (*Node, bool)
- func (d *Document) NodeCount() int
- func (d *Document) OwnedNodeCount() int
- func (d *Document) QuerySelector(value string) (*Node, bool)
- func (d *Document) QuerySelectorAll(value string) []*Node
- func (d *Document) ReadyState() string
- func (d *Document) Remove(id NodeID) ([]NodeID, bool)
- func (d *Document) RemoveAttribute(id NodeID, name string) bool
- func (d *Document) ReplaceChildren(parent *Node, children []*Node) bool
- func (d *Document) SetAttribute(id NodeID, name, value string) bool
- func (d *Document) SetReadyState(state string) bool
- func (d *Document) SetTextContent(id NodeID, value string) bool
- func (d *Document) Snapshot() DocumentSnapshot
- func (d *Document) Title() string
- type DocumentSnapshot
- type Node
- type NodeID
- type NodeSnapshot
- type NodeType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
Root *Node
// contains filtered or unexported fields
}
Document owns a DOM tree and its node indexes.
func NewDocument ¶
func NewDocument() *Document
NewDocument creates an empty document with a document root node.
func NewDocumentFromSnapshot ¶ added in v0.14.0
func NewDocumentFromSnapshot(snapshot DocumentSnapshot) (*Document, error)
NewDocumentFromSnapshot validates snapshot and constructs an independent document with the same stable Node IDs.
func (*Document) AppendChild ¶
AppendChild attaches child beneath parent.
func (*Document) ApplySnapshot ¶ added in v0.14.0
func (d *Document) ApplySnapshot(snapshot DocumentSnapshot) error
ApplySnapshot updates a live document in place. Existing nodes with matching IDs and types are reused so runtime-side Element handles remain valid.
func (*Document) CreateElement ¶
CreateElement creates an unattached element owned by the document.
func (*Document) CreateText ¶
CreateText creates an unattached text node owned by the document.
func (*Document) DetachChild ¶ added in v0.14.0
DetachChild removes a direct child without destroying its subtree identity.
func (*Document) ElementCount ¶
ElementCount returns the number of element nodes.
func (*Document) GetElementByID ¶
GetElementByID returns the first element with the given id attribute.
func (*Document) GetElementsByClassName ¶ added in v0.14.0
GetElementsByClassName returns connected elements containing every class token.
func (*Document) GetElementsByTagName ¶ added in v0.14.0
GetElementsByTagName returns connected elements with the requested tag or all for "*".
func (*Document) InsertChild ¶ added in v0.14.0
InsertChild attaches or moves child beneath parent at index.
func (*Document) IsConnected ¶
IsConnected はノードがDocumentのルートツリーに接続されているかを返す。
func (*Document) OwnedNodeCount ¶ added in v0.14.0
OwnedNodeCount includes detached nodes retained by live Runtime handles.
func (*Document) QuerySelector ¶
QuerySelector は対応する単純セレクターに最初に一致する要素を返す。
func (*Document) QuerySelectorAll ¶ added in v0.14.0
QuerySelectorAll returns all connected elements matching a supported selector.
func (*Document) ReadyState ¶ added in v0.14.0
ReadyState reports the document loading lifecycle exposed to scripts.
func (*Document) RemoveAttribute ¶ added in v0.8.0
RemoveAttribute removes an element attribute and reports whether it existed.
func (*Document) ReplaceChildren ¶ added in v0.14.0
ReplaceChildren atomically moves children beneath parent and detaches the old list.
func (*Document) SetAttribute ¶
SetAttribute は要素の属性を設定し、値が変化した場合にtrueを返す。
func (*Document) SetReadyState ¶ added in v0.14.0
SetReadyState advances the document loading lifecycle.
func (*Document) SetTextContent ¶
SetTextContent は指定したノードの子を1つのテキストノードへ置き換える。
func (*Document) Snapshot ¶ added in v0.14.0
func (d *Document) Snapshot() DocumentSnapshot
Snapshot returns a detached, serializable copy of the current document.
type DocumentSnapshot ¶ added in v0.14.0
type DocumentSnapshot struct {
Root NodeSnapshot `json:"root"`
NextID NodeID `json:"nextId"`
ReadyState string `json:"readyState,omitempty"`
}
DocumentSnapshot is the pointer-free representation exchanged with an isolated runtime worker. Node IDs remain stable across snapshots.
type Node ¶
type Node struct {
ID NodeID
Type NodeType
TagName string
Text string
Attributes map[string]string
// ControlValue and ControlChecked hold browser-owned live form state. The
// corresponding HTML attributes remain the reset defaults.
ControlValue string
ControlValueDirty bool
ControlChecked bool
ControlCheckedDirty bool
Parent *Node
Children []*Node
// contains filtered or unexported fields
}
Node is one item in a Growse DOM tree.
func (*Node) TextContent ¶
TextContent returns the concatenated text of the node and its descendants.
type NodeSnapshot ¶ added in v0.14.0
type NodeSnapshot struct {
ID NodeID `json:"id"`
Type NodeType `json:"type"`
TagName string `json:"tagName,omitempty"`
Text string `json:"text,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
ControlValue string `json:"controlValue,omitempty"`
ControlValueDirty bool `json:"controlValueDirty,omitempty"`
ControlChecked bool `json:"controlChecked,omitempty"`
ControlCheckedDirty bool `json:"controlCheckedDirty,omitempty"`
Children []NodeSnapshot `json:"children,omitempty"`
}
NodeSnapshot contains only browser-visible DOM state. Parent and document pointers are reconstructed by ApplySnapshot.