node

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arena

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

Arena allocates stable nodes in blocks. A producer can discard the arena after building its tree, or reuse it once all published nodes are retired. Reset invalidates all previous node pointers.

func (*Arena) Clone

func (a *Arena) Clone(source *Node) *Node

Clone copies a subtree into this arena, sharing immutable attributes.

func (*Arena) CloneCompact

func (a *Arena) CloneCompact(source *Node) *Node

CloneCompact copies the live subtree into a new string backing store. Identical strings share storage, and the result can outlive the input tree.

func (*Arena) New

func (a *Arena) New(kind NodeType, data string) *Node

func (*Arena) Reset

func (a *Arena) Reset()

type Attribute

type Attribute struct{ Name, Value string }

Attribute is an authored name/value pair. Names retain their exact spelling; the HTML parser applies ASCII folding and foreign-content adjustments.

type AttributeSet

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

AttributeSet stores a compact collection of attributes. Empty sets need only a nil pointer. Small elements use a compact sorted list; larger sets use a map without duplicating names in a second index.

func (*AttributeSet) Attr

func (a *AttributeSet) Attr(name string) (string, bool)

func (*AttributeSet) AttrCount

func (a *AttributeSet) AttrCount() int

func (*AttributeSet) AttrValue

func (a *AttributeSet) AttrValue(name string) string

AttrValue returns an attribute's value, or an empty string if absent.

func (*AttributeSet) Attributes

func (a *AttributeSet) Attributes() iter.Seq2[string, string]

Attributes visits attributes without allocating. Order is unspecified. Removing or updating the currently yielded attribute is allowed; other mutations during iteration are not supported. Pairs are values, never writable storage views.

func (*AttributeSet) RemoveAttr

func (a *AttributeSet) RemoveAttr(name string) bool

RemoveAttr removes an attribute, returning whether it was present.

func (*AttributeSet) SetAttr

func (a *AttributeSet) SetAttr(name, value string) bool

SetAttr changes an attribute, returning whether its value changed.

func (*AttributeSet) SetAttributes

func (a *AttributeSet) SetAttributes(attributes ...Attribute)

SetAttributes replaces all attributes with an owned copy and reuses capacity. Duplicate names keep their first value, matching HTML tokenization.

func (*AttributeSet) SortedAttributes

func (a *AttributeSet) SortedAttributes() iter.Seq2[string, string]

SortedAttributes visits attributes in name order. Small lists need no extra storage. Large maps allocate a sorted name buffer for deterministic output. Do not change attributes during iteration.

type Namespace

type Namespace uint8
const (
	HTML Namespace = iota
	MathML
	SVG
)

type Node

type Node struct {
	AttributeSet
	Parent    *Node
	Data      string
	Children  []*Node
	Order     uint32
	States    StateSet[uint16]
	Type      NodeType
	Namespace Namespace
}

Node is the ordered logical node shared by native UI content producers. Its address stays stable while attached, detached, or moved to another parent.

func NewDocument

func NewDocument() *Node

func NewElement

func NewElement(tag string, attrs ...Attribute) *Node

func NewText

func NewText(text string) *Node

func (*Node) AdoptChildren

func (dst *Node) AdoptChildren(src *Node)

AdoptChildren moves all of src's children to dst in their existing order.

func (*Node) AppendChild

func (n *Node) AppendChild(child *Node)

func (*Node) ClearChildren

func (n *Node) ClearChildren()

ClearChildren detaches all direct children while retaining list capacity.

func (*Node) CopyAttributes

func (n *Node) CopyAttributes(source *Node)

CopyAttributes copies into independently writable storage.

func (*Node) EqualAttributes

func (n *Node) EqualAttributes(other *Node) bool

EqualAttributes compares authored attributes without exposing their storage.

func (*Node) InsertBefore

func (n *Node) InsertBefore(child, before *Node)

InsertBefore inserts a detached child before a sibling. A nil sibling appends.

func (*Node) KeepChildren

func (n *Node) KeepChildren(keep func(*Node) bool)

KeepChildren removes children rejected by keep, preserving relative order.

func (*Node) LastChild

func (n *Node) LastChild() *Node

func (*Node) PreviousSibling

func (n *Node) PreviousSibling() *Node

func (*Node) RemoveChild

func (n *Node) RemoveChild(child *Node) bool

RemoveChild detaches a child and reports whether it belonged to n.

func (*Node) ShareAttributes

func (n *Node) ShareAttributes(source *Node)

ShareAttributes shares source's storage without copying it. Subsequent edits to either node detach its attributes. A nil source clears the attributes. Sharing does not extend the lifetime of parser-owned names or values. Independent destinations may share a read-only source concurrently.

func (*Node) String

func (n *Node) String() string

func (*Node) Within

func (n *Node) Within(root *Node) bool

Within reports whether n is root or a descendant of root.

type NodeType

type NodeType int8
const (
	DocumentNode NodeType = iota
	ElementNode
	TextNode
)

type StateSet

type StateSet[T ~uint16] struct {
	// contains filtered or unexported fields
}

StateSet stores explicitly resolved boolean states in two compact bitsets. A valid bit distinguishes a live false value from an uninitialized state.

func (*StateSet[T]) Clear

func (s *StateSet[T]) Clear(flag T)

func (StateSet[T]) Get

func (s StateSet[T]) Get(flag T) (bool, bool)

func (*StateSet[T]) Set

func (s *StateSet[T]) Set(flag T, value bool)

Jump to

Keyboard shortcuts

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