dom

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 13 Imported by: 0 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

Overview

Package dom implements Kite's public DOM interfaces. It manages the logical tree, document adoption, connection callbacks, and element identity. Public traversal excludes the private subtrees used to implement built-in controls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdoptOuterTree

func AdoptOuterTree(n dom.Node)

AdoptOuterTree runs an adoption walk over the subtree rooted at n. This is typically called by the engine during initial mount.

func DefaultScroller

func DefaultScroller(host dom.Element) event.Scrollable

DefaultScroller returns a new Scrollable implementation for the given host.

func IsOverlay

func IsOverlay(el dom.Element) bool

IsOverlay reports whether el is currently registered in its owner document's top layer.

func IsUANode

func IsUANode(n dom.Node) bool

IsUANode reports whether n is part of a UA shadow subtree. The check is O(1) because AttachUARoot stamps every node in the subtree with an inUASubtree flag at construction time.

func LayoutChildren

func LayoutChildren(n dom.Node) iter.Seq[dom.Node]

LayoutChildren returns an iterator that yields the engine-visible children of n. For nodes that hold a UA shadow subtree (via AttachUARoot), the iterator yields the public child list followed by the children of the UA root.

LayoutChildren is the authoritative walker for the engine's Sync, Style, Layout, and Paint phases. It must never be exposed to author code; public author-facing traversal (ChildNodes, FirstChild, LastChild, Children) must remain UA-invisible.

Zero-allocation fast path: when n has no UA subtree the iterator degrades to a plain ChildNodes() walk with no additional overhead beyond the public iterator.

func Outer

func Outer(n dom.Node) dom.Node

Outer returns the self wrapper for el when one has been adopted; otherwise it returns el unchanged. This is useful when code needs the user-visible wrapper rather than the raw inner *Element.

func UARoot

func UARoot(el dom.Element) dom.Node

UARoot returns the UA shadow subtree root attached to el, or nil if el does not have one. This is an engine-internal accessor used by the Sync phase. It must not be called from author code.

Types

type BaseNode

type BaseNode struct {
	internalevent.Target
	// contains filtered or unexported fields
}

func (*BaseNode) AppendChild

func (b *BaseNode) AppendChild(child dom.Node) dom.Node

func (*BaseNode) ChildNeedsSync

func (b *BaseNode) ChildNeedsSync() bool

func (*BaseNode) ChildNodes

func (b *BaseNode) ChildNodes() iter.Seq[dom.Node]

func (*BaseNode) ClearStyleFlags

func (b *BaseNode) ClearStyleFlags()

func (*BaseNode) ClearSyncFlags

func (b *BaseNode) ClearSyncFlags()

func (*BaseNode) CloneNode

func (b *BaseNode) CloneNode(deep bool) dom.Node

func (*BaseNode) Contains

func (b *BaseNode) Contains(descendant dom.Node) bool

func (*BaseNode) EventTarget

func (b *BaseNode) EventTarget() event.EventTarget

func (*BaseNode) FirstChild

func (b *BaseNode) FirstChild() dom.Node

func (*BaseNode) HasChildNodes

func (b *BaseNode) HasChildNodes() bool

func (*BaseNode) HasDirtyStyleChild

func (b *BaseNode) HasDirtyStyleChild() bool

func (*BaseNode) InsertBefore

func (b *BaseNode) InsertBefore(newChild, ref dom.Node) dom.Node

func (*BaseNode) IsConnected

func (b *BaseNode) IsConnected() bool

func (*BaseNode) Kind

func (b *BaseNode) Kind() dom.Kind

func (*BaseNode) LastChild

func (b *BaseNode) LastChild() dom.Node

func (*BaseNode) MarkNeedsScrollSync

func (b *BaseNode) MarkNeedsScrollSync()

func (*BaseNode) MarkNeedsSync

func (b *BaseNode) MarkNeedsSync()

func (*BaseNode) MarkStyleChildDirty

func (b *BaseNode) MarkStyleChildDirty()

func (*BaseNode) NeedsScrollSync

func (b *BaseNode) NeedsScrollSync() bool

func (*BaseNode) NeedsSync

func (b *BaseNode) NeedsSync() bool

func (*BaseNode) NextSibling

func (b *BaseNode) NextSibling() dom.Node

func (*BaseNode) NodeName

func (b *BaseNode) NodeName() string

func (*BaseNode) OwnerDocument

func (b *BaseNode) OwnerDocument() dom.Document

func (*BaseNode) Parent

func (b *BaseNode) Parent() dom.Node

func (*BaseNode) ParentElement

func (b *BaseNode) ParentElement() dom.Element

func (*BaseNode) PreviousSibling

func (b *BaseNode) PreviousSibling() dom.Node

func (*BaseNode) RemoveChild

func (b *BaseNode) RemoveChild(child dom.Node) dom.Node

func (*BaseNode) ReplaceChild

func (b *BaseNode) ReplaceChild(newChild, oldChild dom.Node) dom.Node

func (*BaseNode) TextContent

func (b *BaseNode) TextContent() string

func (*BaseNode) Unwrap

func (b *BaseNode) Unwrap() dom.Node

type DirtyElement

type DirtyElement interface {
	DirtyNode
	dom.Element

	MarkStyleDirty()
	IsDirtyStyle() bool
	ClearDirtyStyle()

	IsHovered() bool
	SetHovered(bool)
	IsActive() bool
	SetActive(bool)

	RawStyle() style.Style
	DefaultStyle() style.Style
	IntrinsicStyle() style.Style
}

DirtyElement defines the internal interface for tracking element-specific style properties and flags.

func AsDirtyElement

func AsDirtyElement(n dom.Node) DirtyElement

AsDirtyElement returns the internal DirtyElement interface for the given element.

type DirtyNode

type DirtyNode interface {
	dom.Node

	MarkNeedsSync()
	NeedsSync() bool
	ChildNeedsSync() bool
	ClearSyncFlags()

	MarkNeedsScrollSync()
	NeedsScrollSync() bool

	HasDirtyStyleChild() bool
	MarkStyleChildDirty()
	ClearStyleFlags()
}

DirtyNode defines the internal interface for tracking structural and style-propagation dirty state on any logical node.

func AsDirty

func AsDirty(n dom.Node) DirtyNode

AsDirty returns the internal DirtyNode interface for the given node.

type Document

type Document struct {
	BaseNode
	// contains filtered or unexported fields
}

Document is the concrete, exported implementation of Document.

func NewDocument

func NewDocument() *Document

NewDocument creates and returns a new, empty Document. The document itself is always connected.

func (*Document) ActiveScope

func (d *Document) ActiveScope() *dom.FocusScope

func (*Document) Body

func (d *Document) Body() dom.Element

func (*Document) CreateElement

func (d *Document) CreateElement(tag string, self dom.Node) dom.Element

CreateElement returns a new, detached Element with the given tag name owned by this document.

func (*Document) CreateRange

func (d *Document) CreateRange() dom.Range

func (*Document) CreateTextNode

func (d *Document) CreateTextNode(data string, self dom.Node) dom.TextNode

CreateTextNode returns a new, detached TextNode with the given data owned by this document.

func (*Document) CurrentFocus

func (d *Document) CurrentFocus() dom.Element

func (*Document) DefaultView

func (d *Document) DefaultView() dom.View

func (*Document) FindAnchor

func (d *Document) FindAnchor(name string) dom.Element

FindAnchor returns the Element registered under name in the anchor registry, or nil.

func (*Document) FindNodeAtByteOffset

func (d *Document) FindNodeAtByteOffset(root dom.Node, targetOffset int) (dom.Node, int)

func (*Document) Focus

func (d *Document) Focus(el dom.Element)

func (*Document) GetElementByID

func (d *Document) GetElementByID(id string) dom.Element

GetElementByID returns the Element whose ID equals id, or nil.

func (*Document) HideOverlay

func (d *Document) HideOverlay(el dom.Element)

func (*Document) InvalidatePreorderCache

func (d *Document) InvalidatePreorderCache()

func (*Document) InvalidateTextNodeCache

func (d *Document) InvalidateTextNodeCache()

func (*Document) IsFocused

func (d *Document) IsFocused(el dom.Element) bool

func (*Document) MoveCaret

func (d *Document) MoveCaret(dir dom.Direction) bool

func (*Document) Mutating

func (d *Document) Mutating() bool

func (*Document) NavigateFocus

func (d *Document) NavigateFocus(dir dom.Direction) bool

func (*Document) NextFocus

func (d *Document) NextFocus() bool

func (*Document) NumOverlays

func (d *Document) NumOverlays() int

func (*Document) Overlays

func (d *Document) Overlays() iter.Seq[dom.Element]

func (*Document) PopScope

func (d *Document) PopScope()

func (*Document) PreorderOrders

func (d *Document) PreorderOrders() map[any]render.NodeOrder

func (*Document) PreorderValid

func (d *Document) PreorderValid() bool

func (*Document) PreviousFocus

func (d *Document) PreviousFocus() bool

func (*Document) PushScope

func (d *Document) PushScope(scope *dom.FocusScope)

func (*Document) QuerySelector

func (d *Document) QuerySelector(selector string) dom.Element

func (*Document) RegisterAnchor

func (d *Document) RegisterAnchor(name string, el dom.Element)

RegisterAnchor adds el to the anchor registry under name.

func (*Document) Selection

func (d *Document) Selection() dom.Selection

func (*Document) SetDefaultView

func (d *Document) SetDefaultView(v dom.View)

func (*Document) SetFocusHandle

func (d *Document) SetFocusHandle(handle dom.FocusHandle)

func (*Document) SetTerminal

func (d *Document) SetTerminal(t terminal.Terminal)

SetTerminal attaches the host environment to the document.

func (*Document) ShowOverlay

func (d *Document) ShowOverlay(el dom.Element, zIndex int)

func (*Document) Terminal

func (d *Document) Terminal() terminal.Terminal

Terminal returns the host environment, or nil if none is attached.

func (*Document) UnregisterAnchor

func (d *Document) UnregisterAnchor(name string)

UnregisterAnchor removes the entry for name from the anchor registry.

type Element

type Element struct {
	BaseNode
	// contains filtered or unexported fields
}

Element is the concrete, exported implementation of Element.

func NewElement

func NewElement(doc dom.Document, tag string, self dom.Node) *Element

NewElement allocates an element with the given tag name and owner document. If self is nil, the element's self pointer defaults to itself.

func (*Element) AttachUARoot

func (e *Element) AttachUARoot(root dom.Node)

AttachUARoot attaches root as the closed UA shadow subtree for this host. See dom.Element.AttachUARoot for the full contract.

func (*Element) Attribute

func (e *Element) Attribute(name string) (string, bool)

func (*Element) Blur

func (e *Element) Blur()

func (*Element) Children

func (e *Element) Children() iter.Seq[dom.Node]

Children is a helper that returns only Element children. Deprecated: use ChildNodes() and filter by kind.

func (*Element) Class

func (e *Element) Class() string

Class returns the element's classification.

func (*Element) ClearDirtyStyle

func (e *Element) ClearDirtyStyle()

func (*Element) ClearStyleFlags

func (e *Element) ClearStyleFlags()

func (*Element) DefaultStyle

func (e *Element) DefaultStyle() style.Style

func (*Element) EachAttribute

func (e *Element) EachAttribute(fn func(name, value string) bool)

func (*Element) Focus

func (e *Element) Focus()

func (*Element) GetBoundingClientRect

func (e *Element) GetBoundingClientRect() (geom.Rect, bool)

func (*Element) HasAttribute

func (e *Element) HasAttribute(name string) bool

func (*Element) ID

func (e *Element) ID() string

ID returns the element's identifier.

func (*Element) IntrinsicStyle

func (e *Element) IntrinsicStyle() style.Style

IntrinsicStyle returns the UA-mandated sparse style for this element. It delegates to the user-visible wrapper (outer) if it's a specialized implementation.

func (*Element) IsActive

func (e *Element) IsActive() bool

func (*Element) IsDirtyStyle

func (e *Element) IsDirtyStyle() bool

func (*Element) IsFocusable

func (e *Element) IsFocusable() bool

func (*Element) IsHovered

func (e *Element) IsHovered() bool

func (*Element) MarkStyleDirty

func (e *Element) MarkStyleDirty()

func (*Element) ProvidesCursor

func (e *Element) ProvidesCursor() bool

func (*Element) QuerySelector

func (e *Element) QuerySelector(selector string) dom.Element

func (*Element) RawStyle

func (e *Element) RawStyle() style.Style

func (*Element) RemoveAttribute

func (e *Element) RemoveAttribute(name string)

func (*Element) ReplaceWith

func (e *Element) ReplaceWith(nodes ...dom.Node) dom.Element

ReplaceWith replaces this element with the given nodes.

func (*Element) Scroll

func (e *Element) Scroll() (x, y int)

func (*Element) ScrollBy

func (e *Element) ScrollBy(dx, dy int)

func (*Element) ScrollCursorIntoView

func (e *Element) ScrollCursorIntoView()

func (*Element) ScrollTo

func (e *Element) ScrollTo(x, y int)

func (*Element) SetActive

func (e *Element) SetActive(v bool)

func (*Element) SetAttribute

func (e *Element) SetAttribute(name, value string)

func (*Element) SetClass

func (e *Element) SetClass(class string)

SetClass sets the element's classification.

func (*Element) SetHovered

func (e *Element) SetHovered(v bool)

func (*Element) SetID

func (e *Element) SetID(id string)

SetID sets the element's identifier. Registry maintenance when the node is disconnected only the stored id field is updated; the identity registry is touched only when the node is connected.

func (*Element) SetTabIndex

func (e *Element) SetTabIndex(index int)

func (*Element) TabIndex

func (e *Element) TabIndex() int

func (*Element) TagName

func (e *Element) TagName() string

TagName returns the tag name.

func (*Element) UARoot

func (e *Element) UARoot() dom.Node

UARoot returns the closed UA shadow subtree root, or nil.

type OverlayRecord

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

type Range

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

func (*Range) Collapse

func (r *Range) Collapse(toStart bool)

func (*Range) EndContainer

func (r *Range) EndContainer() dom.Node

func (*Range) EndOffset

func (r *Range) EndOffset() int

func (*Range) IsCollapsed

func (r *Range) IsCollapsed() bool

func (*Range) SetEnd

func (r *Range) SetEnd(node dom.Node, offset int)

func (*Range) SetStart

func (r *Range) SetStart(node dom.Node, offset int)

func (*Range) StartContainer

func (r *Range) StartContainer() dom.Node

func (*Range) StartOffset

func (r *Range) StartOffset() int

func (*Range) String

func (r *Range) String() string

type ScrollState

type ScrollState struct {
	X, Y int
}

type Selection

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

func (*Selection) AddRange

func (s *Selection) AddRange(r dom.Range)

func (*Selection) GetRangeAt

func (s *Selection) GetRangeAt(index int) dom.Range

func (*Selection) NewRange

func (s *Selection) NewRange() *Range

func (*Selection) RangeCount

func (s *Selection) RangeCount() int

func (*Selection) RemoveAllRanges

func (s *Selection) RemoveAllRanges()

func (*Selection) String

func (s *Selection) String() string

type TextNode

type TextNode struct {
	BaseNode
	// contains filtered or unexported fields
}

TextNode is the concrete, exported implementation of TextNode.

func NewTextNode

func NewTextNode(doc dom.Document, data string, self dom.Node) *TextNode

NewTextNode allocates a TextNode with the given data and owner document. If self is nil, the node's identity is itself.

func (*TextNode) Data

func (t *TextNode) Data() string

Data returns the current text content.

func (*TextNode) SetData

func (t *TextNode) SetData(data string)

SetData replaces the text content and notifies the parent's render object.

type TextNodeRecord

type TextNodeRecord struct {
	Node      dom.TextNode
	StartByte int
	EndByte   int
}

Jump to

Keyboard shortcuts

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