highlight_manager.ts view source
import {HighlightManager} from '@fuzdev/fuz_code/highlight_manager.js'; Manages CSS Custom Highlight API ranges for a single element's text node.
Tracks ranges per element and only removes its own ranges when clearing,
cooperating with other managers that share the global CSS.highlights registry.
Experimental — limited browser support. Use Code.svelte for production block code; this powers the experimental CodeHighlight and CodeTextarea.
examples
const manager = new HighlightManager();
manager.highlight_from_lexed(element, syntax_styler_global.lex(text, 'ts'));element_ranges
This manager's ranges, keyed by prefixed highlight name (e.g. token_keyword).
A single range object may be shared across several names (a token type plus
its aliases), since one range can belong to multiple Highlight sets.
type Map<string, AbstractRange[]>
constructor
type new (): HighlightManager
highlight_from_lexed
Highlights element's text node from a lexed event stream. Ranges come
straight from event offsets — no position reconstruction. Clears this
manager's previous ranges first.
A missing text node is a no-op. Offsets past the text node's length are clamped (a DOM/source mismatch is the caller's concern, not a throw here).
type (element: Element, lexed: LexedSyntax): void
element
Elementlexed
voidclear_element_ranges
Clears only this manager's ranges from the shared highlights. Defensive: a highlight may already be gone (e.g. another manager removed the last range, or HMR reset the registry), which is a valid state, not an error.
type (): void
voiddestroy
type (): void
void