stnd.build

@stnd/dom

Circle 3 — Specialized Satellite & Plumbing · Active · Utility

Role: Low-level DOM query, focus-trap, portal, and event delegation micro-utilities used by @stnd/ui and @stnd/client.

When to use: Internal plumbing for focus management and keyboard trapping inside custom interactive components.

Quick Start (TL;DR)

import { trapFocus } from "@stnd/dom";

Lightweight DOM manipulation and extraction utilities.

ELI5

Once content is rendered to an HTML string (by @stnd/press, usually), these are the scissors: pull out all the images to lazy-load them, grab the headings to build a table of contents, split the content in two at the first occurrence of a given tag (partition). It works the same whether that HTML lives in a Cloudflare Worker or a browser tab — no Node-only APIs.

Use it:

import { extractHeadings } from "@stnd/dom";
const headings = extractHeadings(html, [1, 2]); // table of contents data

Overview

@stnd/dom provides a set of utilities for processing HTML strings and DOM elements. These are designed to be used both on the server (using linkedom) and in the browser.

Key Exports

Usage

import { extractHeadings } from "@stnd/dom";

const html = "<h1>Title</h1><p>Text</p><h2>Subtitle</h2>";
const headings = extractHeadings(html, [1, 2]);

// headings = [{ level: 1, text: "Title", id: "title" }, { level: 2, text: "Subtitle", id: "subtitle" }]

Features