Docs
API Reference

Node

Node has no public import path. Obtain instances through ui.create(); ui.root is also a node. TElement depends on the renderer.

Properties

PropertyTypeDescription
idnumberIdentifier within the UI.
uiUI | nullOwning UI; null after destruction.
elementTElement | nullRenderer element; null after destruction.
parentNode<TElement> | nullParent node.
childrenNode<TElement>[]Child nodes.
pathnumber[]Child-index path from the root.
layoutNodeLayoutLast computed layout; read after ui.update().
text_contentstring | undefinedText set through text().
stylesPartial<Record<StyleName | (string & {}), ResolvedStyle>>Resolved styles.
ordernumberPainting order.
scrollTopnumberRead/write vertical scroll offset.
scrollLeftnumberRead/write horizontal scroll offset.
scrollHeight, scrollWidthnumberScrollable content dimensions.
clientHeight, clientWidthnumberVisible content dimensions.
scrollingbooleanScroll gesture state.
scroll_top, scroll_leftnumberBacking fields; use scrollTop and scrollLeft.

Methods

MethodReturnsDescription
add(child: Node, before_node: Node | null = null)voidInserts a detached child; null appends.
remove(child: Node)voidDestroys a direct child and its subtree.
detach()voidDetaches this subtree for reuse.
destroy()voidDestroys this subtree; the root destroys the UI.
style(name: StyleName | (string & {}), value: string)voidSets a style.
text(value: string)voidSets text; text nodes cannot have children.
isTextNode()booleanWhether text() has initialized this node.
hasTextContent()booleanWhether this node has non-empty text.
on<TName extends string>(type: TName, listener: (event: EventPayload<TName>) => void)voidAdds an event listener.
off<TName extends string>(type: TName, listener: (event: EventPayload<TName>) => void)voidRemoves an event listener.
destroyEvents()voidRemoves all listeners on this node.
focus(source_event: EventSource | null = null)voidFocuses this node.
blur(source_event: EventSource | null = null)voidClears focus if this node owns it.

Event names and payloads are listed in Events.

Adding and moving nodes

parent.add(child, before_node) requires:

  • A detached child from the same UI, other than ui.root.
  • A parent that is not a text node, the child itself, or one of the child's descendants.
  • A before_node that is already a direct child of the parent, or null to append.

Invalid insertions throw. Detach an attached node before moving or reordering it:

child.detach()
parent.add(child, before_node)
ui.update()

detach() preserves the subtree for reuse. remove() destroys a direct child and its subtree; it throws if the supplied node is not a direct child.

Reading layout

layout starts empty. Attach the node beneath ui.root and call ui.update() before reading its computed dimensions. Update again after changes that affect layout; scroll metrics such as scrollHeight and clientHeight are also refreshed by update().

node.style('width', '240px')
ui.update()
console.log(node.layout.width, node.layout.height)

The layout has this shape; NodeLayout is not a separately exported type:

type NodeLayout = Partial<{
  x: number
  y: number
  width: number
  height: number
  top: number
  left: number
  centerX: number
  centerY: number
  padding: { top: number; right: number; bottom: number; left: number }
  border: { top: number; right: number; bottom: number; left: number }
}>

On this page