Skip to content

Log ​

A monospace log display container that supports incremental appending and "stick-to-bottom" auto-scrolling, suitable for consoles / build output scenarios.

Basic Usage ​

Basic log stream

Provide data via the lines property (or the lines attribute as a JSON string); when appending, only the new lines are rendered incrementally — existing nodes are not rebuilt.

Line Numbers ​

Show line numbers

Appending and Auto-Scroll ​

Appending log stream (stick-to-bottom auto-scroll)

Appends a log line every 1.2s; auto-scroll happens only when pinned to the bottom, and scrolling up to read history does not interrupt it.

Disabling Auto-Scroll ​

auto-scroll=false

With auto-scroll="false", appended content does not auto-scroll to the bottom.

Empty State ​

Empty log

An empty lines shows the empty-state placeholder; the copy follows the locale (overridable via empty-text).

Custom empty text

empty-text overrides the default empty-state copy (default: "No logs").

Loading History on Scroll-Up ​

require-more pagination

Scrolling to the top fires oas-require-more (detail { from: 'top' }); after a simulated delay, 10 older lines are prepended (key-aligned reconcile — existing rows are not rebuilt), line numbers re-flow and the reading position is preserved.

Line Highlight ​

Keyword / regex highlight

The highlight JSON array: strings are literal keywords, pattern entries are regexes (escape backslashes as JSON, e.g. \\d); matches are wrapped in a mark span (token semantic background) and all text goes through textContent to prevent injection.

Search Filter ​

Keyword search filter

A non-empty keyword shows only matching lines (case-insensitive), with matched fragments wrapped in a mark highlight (same visual system as the highlight channel); line numbers still show the original indices. The component fires oas-search (detail { keyword, matched, total }) so the host can display a match count. Clearing the input restores all lines; the host's lines data is never modified.

Level Colors ​

levels semantic colors

The levels JSON array aligns with lines by index: info / success / warning / error map to token semantic colors (dark-theme aware), with aliases like warn / fatal; unknown levels are not colored.

ANSI Coloring ​

ANSI escape sequence coloring

With ansi set, each line is parsed for ANSI SGR escape sequences: 16 / 256 / truecolor foreground and background colors plus bold / dim / italic / underline / inverse; escape codes are stripped from the displayed text. The ANSI foreground takes precedence over the levels semantic line color, and keyword / highlight marks still apply (inheriting the ANSI foreground). The palette uses light-dark() so dark mode switches to readable colors automatically.

Scope and boundaries:

  • Foreground / background: 16 colors 30-37 / 90-97 (bright) / 40-47 / 100-107, rendered via the built-in light-dark() palette (CSS classes, one readable set per theme, overridable per color with the --ansi-* CSS variables set on the oas-log element); 38;5;n / 48;5;n (256 colors) and 38;2;r;g;b / 48;2;r;g;b (truecolor) are rendered as inline styles, with foreground colors auto-corrected for perceptual contrast in each theme and colored backgrounds picking the best foreground (16-color backgrounds guarantee at least one of black / white passes; arbitrary truecolor backgrounds can only be optimized, extreme mid-tones may need an explicit host foreground).
  • Styles: 1 bold, 2 dim, 3 italic, 4 underline, 7 inverse; 0 resets everything, 22 / 23 / 24 / 27 turn each style off (39 / 49 clear the foreground / background back to inherited colors).
  • Precedence: a segment with an ANSI foreground color wins (overriding the levels semantic line color); segments without an ANSI foreground keep the levels / host text color. keyword / highlight marks are wrapped inside the ANSI segment and inherit its foreground, so highlighting never loses the color.
  • Safety & performance: sequences are parsed into plain-text segments rendered with classes / inline styles — innerHTML is never used, so hostile text (<script>, quotes, &) is displayed literally; non-SGR CSI / OSC / multi-byte ESC sequences and C0 control characters are stripped as well (tabs are preserved) and never leak into the DOM. Unknown / invalid parameters are ignored without affecting the rest of the line. Parsing only runs when a line's content or a channel changes; appends perform zero rebuilds while channels stay unchanged.
  • Boundaries: keyword filtering matches the visible text (escape sequences are stripped first when ansi is on), so color codes cannot hide a match; SGR state resets per line (colors do not carry across lines), so multi-line colored output should include escapes on each line. The 16-color palette is tuned against the page background --oas-color-bg; on elevated backgrounds or with dim, override the --ansi-* variables if stricter contrast is needed. No terminal emulation (input, cursor, OSC 8 hyperlinks).

Loading and scrollTo ​

loading + scrollTo()

Fetch againBack to topBack to bottom

The loading attribute shows an overlay and syncs aria-busy; the scrollTo('top' | 'bottom' | px) method lets external buttons jump around.

Font Size ​

Font size follows the outer context (inherited) by default; override with the CSS variable --oas-log-font (e.g. 18px).

Events and Methods ​

  • oas-require-more: fired when scrolling into the top/bottom threshold zone (detail { from: 'top' | 'bottom' }). Edge-triggered — no repeated firing while staying in the zone, reset after leaving; thresholds controlled by offset-top / offset-bottom (px).
  • oas-search: search filter report (detail { keyword, matched, total }) — fired when the keyword or the data changes (deduped for identical state); matched is the current number of matching lines and total the total lines; the filter window is the currently loaded lines (compatible with paginated loading).
  • scrollTo('top' | 'bottom' | number): scrolls the viewport to top / bottom / a pixel offset, for external "back to bottom" buttons.
  • loading: overlay mask on the viewport, syncs aria-busy; copy follows the locale (loading.loading).
  • levels / highlight / keyword: per-line level semantic colors / keyword·regex highlight / search filter channels (JSON attributes, see demos above). A non-empty keyword shows only matching lines (case-insensitive) and highlights matched fragments with a mark span; filtering never modifies the host's lines, line numbers and levels stay aligned to the original indices, and clearing restores everything.
  • ansi: ANSI SGR escape sequence coloring switch (off by default), supporting 16 / 256 / truecolor foreground and background colors plus common styles — see the "ANSI Coloring" section.

When history lines are prepended, the reconcile aligns rows by content key: existing row nodes are reused, line numbers re-flow, and the viewport reading position is compensated automatically.

API ​

oas-log ​

Attributes ​

AttributeDescriptionTypeDefault
ansiParse and render ANSI SGR escape sequences per line (boolean, off by default): 16-color foreground/background (30-37/90-97/40-47/100-107, light-dark() palette), 256 colors (38;5;n/48;5;n) and truecolor (38;2;r;g;b/48;2;r;g;b, inline style), plus bold/dim/italic/underline/inverse and reset; non-SGR CSI/OSC/multi-byte ESC sequences and C0 control characters are stripped to prevent leakage (tabs preserved); the ANSI foreground overrides the per-line levels semantic color, keyword/highlight marks still apply (inheriting the ANSI foreground)boolean—
auto-scrollAuto-scroll to bottom on append (only when stuck to the bottom)stringtrue
empty-textEmpty state text (overrides the locale default)——
highlightLine highlight rules (JSON array): string = literal keyword; { text } / { pattern, flags } = regex; matches are wrapped with a mark background (warning token)string—
keywordSearch filter keyword: when non-empty, only matching lines are shown (case-insensitive) and matched fragments get a mark highlight (same visual system as highlight); line numbers / levels stay aligned to the original indices, clearing restores all lines without modifying the host's linesstring—
levelsLine levels (JSON array, index-aligned with lines): info/success/warning/error (aliases like warn/fatal normalized), mapped to semantic color tokensstring—
line-numberShow the left line number columnboolean—
linesLog lines JSON string (attribute channel)string[][]
loadingLoading state (viewport overlay + spinner + aria-busy)boolean—
offset-bottomDistance from the bottom that counts as reaching it (px, fires oas-require-more with from=bottom, default 0)——
offset-topDistance from the top that counts as reaching it (px, fires oas-require-more with from=top, default 0)——

Methods ​

MethodSignatureDescription
scrollToscrollTo(target?: (ScrollToOptions & { position?: 'top' | 'bottom' }) | 'top' | 'bottom' | number): voidScroll the viewport: 'top' goes to the top, 'bottom' to the bottom, and a number is the pixel scrollTop

Events ​

EventDescription
oas-require-moreFired once when scrolling enters the top/bottom threshold edge (not repeatedly while staying, re-arms after leaving), detail: { from: "top" | "bottom" }; for loading history/new entries
oas-searchSearch filter report: fired when the keyword or the data changes (deduped for identical state), detail: { keyword, matched, total } (matched = matching line count, total = total lines; the filter window is the currently loaded lines)

CSS Variables ​

CSS VariableDefault
--oas-log-fontinherit
--oas-log-loading-maskcolor-mix(in srgb, var(--oas-color-bg) 65%, transparent)
--oas-log-mark-bgcolor-mix(in srgb, var(--oas-color-warning) 18%, transparent)
--oas-log-mark-colorvar(--oas-color-warning-text)

Parts: ::part(viewport) scroll viewport, ::part(log) log content, ::part(row) a single row, ::part(line-number) line number, ::part(line) line text, ::part(empty) empty state.

Released under the MIT OR Apache-2.0 License.