Skip to content

Documentation / @ripl/terminal / TerminalContext

Class: TerminalContext ​

Defined in: terminal/src/context.ts:175

Terminal rendering context that rasterizes Ripl elements into character-based output via a TerminalOutput adapter.

Affine transforms, clipping and hit testing are all honored. A character grid still cannot honor the whole canvas contract, so the following constraints apply:

  • Text metrics are approximate: every glyph occupies exactly one terminal cell, so measureText reports one cell of width per character regardless of font, and the font state (family, size, weight) has no visual effect.
  • Rotated text runs along the grid: a glyph fills a whole cell and cannot itself be rotated, so a rotated run advances along whichever of eight compass directions the transform is nearest. A quarter-turn axis title reads down the side of a chart; it is not drawn sideways.
  • Stroke width approximates a non-uniform scale: a round pen is genuinely elliptical under one, so lineWidth maps through the geometric mean of the transform's scale factors.
  • Fills use the even-odd rule only: the scanline rasterizer ignores a nonzero fill rule (see TerminalContext.applyFill). Hit testing honors both.
  • Stroke joins and caps are always round: lineWidth is honored by stamping a round brush along the path, so lineCap, lineJoin and miterLimit have no effect. lineDash/lineDashOffset are honored, with arc length approximated by plotted-pixel count.
  • Gradients and patterns resolve to one color: a cell cannot interpolate, so a multi-color paint paints as its first non-transparent color.
  • No shadows, filters, or compositing: shadow*, filter and globalCompositeOperation are ignored. globalCompositeOperation: 'destination-out' warns, because canvas erases where the terminal draws — the output is inverted rather than merely degraded.
  • Text on a path is drawn straight: ContextText.pathData/startOffset are ignored and the run is laid out from its anchor along a straight line.
  • No images: drawImage is inherited as a no-op.

Extends ​

Constructors ​

Constructor ​

new TerminalContext(output, options?): TerminalContext

Defined in: terminal/src/context.ts:207

Parameters ​

ParameterType
outputTerminalOutput
options?TerminalContextOptions

Returns ​

TerminalContext

Overrides ​

Context.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
currentStateprotectedBaseStateundefined--Context.currentStatecore/src/context/context.ts:104
elementreadonlyElementundefinedThe underlying DOM element the context renders into.-Context.elementcore/src/context/context.ts:111
heightpublicnumberundefinedCurrent height of the rendering surface, in logical pixels — CSS pixels, unaffected by the device pixel ratio.-Context.heightcore/src/context/context.ts:124
hitTestHonorsTransformpublicbooleanfalseA hit point arrives in logical space while a path's recorded commands are in the element's own local space, and no transform is in force by the time a hit test runs — so the point has to be mapped back through the element's world transform, as it is on canvas.Context.hitTestHonorsTransform-terminal/src/context.ts:200
metareadonlyTMetaundefinedArbitrary metadata attached to the context.-Context.metacore/src/context/context.ts:113
parent?publicEventBus<ContextEventMap>undefinedThe parent event bus that emitted events bubble up to, if any.-Context.parentcore/src/core/event-bus.ts:107
renderDepthprotectednumber0--Context.renderDepthcore/src/context/context.ts:105
renderedElementspublicRenderElement[]undefinedElements rendered during the current pass, used for hit testing.-Context.renderedElementscore/src/context/context.ts:132
renderElement?publicRenderElementundefinedThe element currently being rendered, if any.-Context.renderElementcore/src/context/context.ts:130
saveDepthprotectednumber0--Context.saveDepthcore/src/context/context.ts:106
scaleXpublicScale<number, number>undefinedScale mapping logical x coordinates onto this backend's surface x coordinates. Drives drawing, not a conversion seam for callers — use Context.toSurfacePoint.-Context.scaleXcore/src/context/context.ts:126
scaleYpublicScale<number, number>undefinedScale mapping logical y coordinates onto this backend's surface y coordinates. Drives drawing, not a conversion seam for callers — use Context.toSurfacePoint.-Context.scaleYcore/src/context/context.ts:128
statesprotectedBaseState[]undefined--Context.statescore/src/context/context.ts:103
typereadonlystringundefinedThe context type identifier (e.g. canvas, svg).-Context.typecore/src/context/context.ts:109
widthpublicnumberundefinedCurrent width of the rendering surface, in logical pixels — CSS pixels, unaffected by the device pixel ratio.-Context.widthcore/src/context/context.ts:122
defaultKeyreadonlytypeof defaultKeyundefinedThe key under which resources are retained when no explicit key is provided.-Context.defaultKeycore/src/core/disposer.ts:11

Accessors ​

$events ​

Get Signature ​

get $events(): keyof ContextEventMap[]

Defined in: core/src/context/context.ts:135

The event types a context can emit. See EventBus.$events.

Returns ​

keyof ContextEventMap[]

Inherited from ​

Context.$events


currentRenderElement ​

Get Signature ​

get currentRenderElement(): RenderElement | undefined

Defined in: core/src/context/context.ts:153

The element currently being rendered; setting a non-abstract element also records it in Context.renderedElements.

Returns ​

RenderElement | undefined

Set Signature ​

set currentRenderElement(element): void

Defined in: core/src/context/context.ts:157

Parameters ​
ParameterType
elementRenderElement | undefined
Returns ​

void

Inherited from ​

Context.currentRenderElement


direction ​

Get Signature ​

get direction(): Direction

Defined in: core/src/context/context.ts:184

Directionality used when rendering text.

Returns ​

Direction

Set Signature ​

set direction(value): void

Defined in: core/src/context/context.ts:188

Directionality used when rendering text.

Parameters ​
ParameterType
valueDirection
Returns ​

void

Directionality used when rendering text.

Inherited from ​

Context.direction


fill ​

Get Signature ​

get fill(): string

Defined in: core/src/context/context.ts:166

Fill style (CSS color, gradient, or pattern) used to paint filled regions.

Returns ​

string

Set Signature ​

set fill(value): void

Defined in: core/src/context/context.ts:170

Fill style (CSS color, gradient, or pattern) used to paint filled regions.

Parameters ​
ParameterType
valuestring
Returns ​

void

Fill style (CSS color, gradient, or pattern) used to paint filled regions.

Inherited from ​

Context.fill


filter ​

Get Signature ​

get filter(): string

Defined in: core/src/context/context.ts:175

CSS filter string applied to subsequent drawing operations (e.g. blur(4px)).

Returns ​

string

Set Signature ​

set filter(value): void

Defined in: core/src/context/context.ts:179

CSS filter string applied to subsequent drawing operations (e.g. blur(4px)).

Parameters ​
ParameterType
valuestring
Returns ​

void

CSS filter string applied to subsequent drawing operations (e.g. blur(4px)).

Inherited from ​

Context.filter


font ​

Get Signature ​

get font(): string

Defined in: core/src/context/context.ts:193

CSS font shorthand used when rendering text.

Returns ​

string

Set Signature ​

set font(value): void

Defined in: core/src/context/context.ts:197

CSS font shorthand used when rendering text.

Parameters ​
ParameterType
valuestring
Returns ​

void

CSS font shorthand used when rendering text.

Inherited from ​

Context.font


fontKerning ​

Get Signature ​

get fontKerning(): FontKerning

Defined in: core/src/context/context.ts:202

Whether font kerning is applied when rendering text.

Returns ​

FontKerning

Set Signature ​

set fontKerning(value): void

Defined in: core/src/context/context.ts:206

Whether font kerning is applied when rendering text.

Parameters ​
ParameterType
valueFontKerning
Returns ​

void

Whether font kerning is applied when rendering text.

Inherited from ​

Context.fontKerning


globalCompositeOperation ​

Get Signature ​

get globalCompositeOperation(): unknown

Defined in: core/src/context/context.ts:220

Compositing operation controlling how new drawing is blended with existing content.

Returns ​

unknown

Set Signature ​

set globalCompositeOperation(value): void

Defined in: core/src/context/context.ts:224

Compositing operation controlling how new drawing is blended with existing content.

Parameters ​
ParameterType
valueunknown
Returns ​

void

Compositing operation controlling how new drawing is blended with existing content.

Inherited from ​

Context.globalCompositeOperation


lineCap ​

Get Signature ​

get lineCap(): LineCap

Defined in: core/src/context/context.ts:229

Cap style drawn at the endpoints of stroked lines.

Returns ​

LineCap

Set Signature ​

set lineCap(value): void

Defined in: core/src/context/context.ts:233

Cap style drawn at the endpoints of stroked lines.

Parameters ​
ParameterType
valueLineCap
Returns ​

void

Cap style drawn at the endpoints of stroked lines.

Inherited from ​

Context.lineCap


lineDash ​

Get Signature ​

get lineDash(): number[]

Defined in: core/src/context/context.ts:238

Dash pattern as alternating stroke and gap lengths; empty for a solid line.

Returns ​

number[]

Set Signature ​

set lineDash(value): void

Defined in: core/src/context/context.ts:242

Dash pattern as alternating stroke and gap lengths; empty for a solid line.

Parameters ​
ParameterType
valuenumber[]
Returns ​

void

Dash pattern as alternating stroke and gap lengths; empty for a solid line.

Inherited from ​

Context.lineDash


lineDashOffset ​

Get Signature ​

get lineDashOffset(): number

Defined in: core/src/context/context.ts:247

Distance into the line dash pattern at which dashing begins.

Returns ​

number

Set Signature ​

set lineDashOffset(value): void

Defined in: core/src/context/context.ts:251

Distance into the line dash pattern at which dashing begins.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Distance into the line dash pattern at which dashing begins.

Inherited from ​

Context.lineDashOffset


lineJoin ​

Get Signature ​

get lineJoin(): LineJoin

Defined in: core/src/context/context.ts:256

Join style drawn where two stroked segments meet.

Returns ​

LineJoin

Set Signature ​

set lineJoin(value): void

Defined in: core/src/context/context.ts:260

Join style drawn where two stroked segments meet.

Parameters ​
ParameterType
valueLineJoin
Returns ​

void

Join style drawn where two stroked segments meet.

Inherited from ​

Context.lineJoin


lineWidth ​

Get Signature ​

get lineWidth(): number

Defined in: core/src/context/context.ts:265

Width, in pixels, of stroked lines.

Returns ​

number

Set Signature ​

set lineWidth(value): void

Defined in: core/src/context/context.ts:269

Width, in pixels, of stroked lines.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Width, in pixels, of stroked lines.

Inherited from ​

Context.lineWidth


miterLimit ​

Get Signature ​

get miterLimit(): number

Defined in: core/src/context/context.ts:274

Miter length limit ratio applied to miter line joins.

Returns ​

number

Set Signature ​

set miterLimit(value): void

Defined in: core/src/context/context.ts:278

Miter length limit ratio applied to miter line joins.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Miter length limit ratio applied to miter line joins.

Inherited from ​

Context.miterLimit


opacity ​

Get Signature ​

get opacity(): number

Defined in: core/src/context/context.ts:211

Global alpha applied to everything drawn, from 0 to 1. Assignment replaces the current alpha; element and group opacity instead composite multiplicatively through CONTEXT_OPERATIONS.

Returns ​

number

Set Signature ​

set opacity(value): void

Defined in: core/src/context/context.ts:215

Global alpha applied to everything drawn, from 0 to 1.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Global alpha applied to everything drawn, from 0 to 1.

Inherited from ​

Context.opacity


rotation ​

Get Signature ​

get rotation(): Rotation

Defined in: core/src/context/context.ts:391

Rotation applied to the element's transform, as radians or a deg/rad string.

Returns ​

Rotation

Set Signature ​

set rotation(value): void

Defined in: core/src/context/context.ts:395

Rotation applied to the element's transform, as radians or a deg/rad string.

Parameters ​
ParameterType
valueRotation
Returns ​

void

Rotation applied to the element's transform, as radians or a deg/rad string.

Inherited from ​

Context.rotation


shadowBlur ​

Get Signature ​

get shadowBlur(): number

Defined in: core/src/context/context.ts:283

Gaussian blur radius applied to drawn shadows.

Returns ​

number

Set Signature ​

set shadowBlur(value): void

Defined in: core/src/context/context.ts:287

Gaussian blur radius applied to drawn shadows.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Gaussian blur radius applied to drawn shadows.

Inherited from ​

Context.shadowBlur


shadowColor ​

Get Signature ​

get shadowColor(): string

Defined in: core/src/context/context.ts:292

Color of drawn shadows.

Returns ​

string

Set Signature ​

set shadowColor(value): void

Defined in: core/src/context/context.ts:296

Color of drawn shadows.

Parameters ​
ParameterType
valuestring
Returns ​

void

Color of drawn shadows.

Inherited from ​

Context.shadowColor


shadowOffsetX ​

Get Signature ​

get shadowOffsetX(): number

Defined in: core/src/context/context.ts:301

Horizontal offset, in pixels, of drawn shadows.

Returns ​

number

Set Signature ​

set shadowOffsetX(value): void

Defined in: core/src/context/context.ts:305

Horizontal offset, in pixels, of drawn shadows.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Horizontal offset, in pixels, of drawn shadows.

Inherited from ​

Context.shadowOffsetX


shadowOffsetY ​

Get Signature ​

get shadowOffsetY(): number

Defined in: core/src/context/context.ts:310

Vertical offset, in pixels, of drawn shadows.

Returns ​

number

Set Signature ​

set shadowOffsetY(value): void

Defined in: core/src/context/context.ts:314

Vertical offset, in pixels, of drawn shadows.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Vertical offset, in pixels, of drawn shadows.

Inherited from ​

Context.shadowOffsetY


stroke ​

Get Signature ​

get stroke(): string

Defined in: core/src/context/context.ts:319

Stroke style (CSS color, gradient, or pattern) used to paint outlines.

Returns ​

string

Set Signature ​

set stroke(value): void

Defined in: core/src/context/context.ts:323

Stroke style (CSS color, gradient, or pattern) used to paint outlines.

Parameters ​
ParameterType
valuestring
Returns ​

void

Stroke style (CSS color, gradient, or pattern) used to paint outlines.

Inherited from ​

Context.stroke


supportsPathCaching ​

Get Signature ​

get supportsPathCaching(): boolean

Defined in: terminal/src/context.ts:203

Terminal paths are inert command recorders, so a cached path stays valid across frames.

Returns ​

boolean

Overrides ​

Context.supportsPathCaching


textAlign ​

Get Signature ​

get textAlign(): TextAlignment

Defined in: core/src/context/context.ts:328

Horizontal alignment of text relative to the drawing position.

Returns ​

TextAlignment

Set Signature ​

set textAlign(value): void

Defined in: core/src/context/context.ts:332

Horizontal alignment of text relative to the drawing position.

Parameters ​
ParameterType
valueTextAlignment
Returns ​

void

Horizontal alignment of text relative to the drawing position.

Inherited from ​

Context.textAlign


textBaseline ​

Get Signature ​

get textBaseline(): TextBaseline

Defined in: core/src/context/context.ts:337

Vertical baseline used when positioning text.

Returns ​

TextBaseline

Set Signature ​

set textBaseline(value): void

Defined in: core/src/context/context.ts:341

Vertical baseline used when positioning text.

Parameters ​
ParameterType
valueTextBaseline
Returns ​

void

Vertical baseline used when positioning text.

Inherited from ​

Context.textBaseline


transformOriginX ​

Get Signature ​

get transformOriginX(): TransformOrigin

Defined in: core/src/context/context.ts:400

Horizontal origin about which rotation and scaling are applied.

Returns ​

TransformOrigin

Set Signature ​

set transformOriginX(value): void

Defined in: core/src/context/context.ts:404

Horizontal origin about which rotation and scaling are applied.

Parameters ​
ParameterType
valueTransformOrigin
Returns ​

void

Horizontal origin about which rotation and scaling are applied.

Inherited from ​

Context.transformOriginX


transformOriginY ​

Get Signature ​

get transformOriginY(): TransformOrigin

Defined in: core/src/context/context.ts:409

Vertical origin about which rotation and scaling are applied.

Returns ​

TransformOrigin

Set Signature ​

set transformOriginY(value): void

Defined in: core/src/context/context.ts:413

Vertical origin about which rotation and scaling are applied.

Parameters ​
ParameterType
valueTransformOrigin
Returns ​

void

Vertical origin about which rotation and scaling are applied.

Inherited from ​

Context.transformOriginY


transformScaleX ​

Get Signature ​

get transformScaleX(): number

Defined in: core/src/context/context.ts:373

Horizontal scale factor applied to the element's transform.

Returns ​

number

Set Signature ​

set transformScaleX(value): void

Defined in: core/src/context/context.ts:377

Horizontal scale factor applied to the element's transform.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Horizontal scale factor applied to the element's transform.

Inherited from ​

Context.transformScaleX


transformScaleY ​

Get Signature ​

get transformScaleY(): number

Defined in: core/src/context/context.ts:382

Vertical scale factor applied to the element's transform.

Returns ​

number

Set Signature ​

set transformScaleY(value): void

Defined in: core/src/context/context.ts:386

Vertical scale factor applied to the element's transform.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Vertical scale factor applied to the element's transform.

Inherited from ​

Context.transformScaleY


translateX ​

Get Signature ​

get translateX(): number

Defined in: core/src/context/context.ts:355

Horizontal translation, in pixels, applied to the element's transform.

Returns ​

number

Set Signature ​

set translateX(value): void

Defined in: core/src/context/context.ts:359

Horizontal translation, in pixels, applied to the element's transform.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Horizontal translation, in pixels, applied to the element's transform.

Inherited from ​

Context.translateX


translateY ​

Get Signature ​

get translateY(): number

Defined in: core/src/context/context.ts:364

Vertical translation, in pixels, applied to the element's transform.

Returns ​

number

Set Signature ​

set translateY(value): void

Defined in: core/src/context/context.ts:368

Vertical translation, in pixels, applied to the element's transform.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Vertical translation, in pixels, applied to the element's transform.

Inherited from ​

Context.translateY


zIndex ​

Get Signature ​

get zIndex(): number

Defined in: core/src/context/context.ts:346

Stacking order used to sort elements during rendering; higher values draw on top.

Returns ​

number

Set Signature ​

set zIndex(value): void

Defined in: core/src/context/context.ts:350

Stacking order used to sort elements during rendering; higher values draw on top.

Parameters ​
ParameterType
valuenumber
Returns ​

void

Stacking order used to sort elements during rendering; higher values draw on top.

Inherited from ​

Context.zIndex

Methods ​

applyClip() ​

applyClip(path, fillRule?): void

Defined in: terminal/src/context.ts:485

Confines subsequent drawing to the given path, intersected with any clip already in force.

Parameters ​

ParameterTypeDescription
pathContextPathThe clip geometry.
fillRule?FillRuleAccepted for signature compatibility; the scanline rasterizer implements only the even-odd rule.

Returns ​

void

Overrides ​

Context.applyClip


applyFill() ​

applyFill(element, fillRule?): void

Defined in: terminal/src/context.ts:440

Rasterizes and fills the given path or text element using the current fill color, composited with the current opacity. A paint that resolves to nothing (none, transparent, or zero effective alpha) draws nothing at all.

Parameters ​

ParameterType
elementContextElement
fillRule?FillRule

Returns ​

void

Overrides ​

Context.applyFill


applyGroupPaint() ​

protected applyGroupPaint(group): void

Defined in: core/src/context/context.ts:603

Applies a group's own inherited paint (fill, stroke, opacity, font, line, shadow, text) to the context so descendants pick it up from the copied state. Transforms are applied separately, so they are skipped here.

Two boundary semantics are fixed here and every backend must honour them:

  • Opacity composites multiplicatively. CONTEXT_OPERATIONS multiplies rather than assigns, so nested groups compound and a leaf's own alpha stacks under its ancestors' instead of replacing it.
  • A group's gradient or pattern resolves against the group's own box. The group is the Context.currentRenderElement for the duration of the boundary, so a paint that bakes geometry at set time (canvas) and one that resolves it per leaf (SVG) agree on the same reference box: group.getBoundingBox(true), never a sibling's and never the surface.

Parameters ​

ParameterType
groupElement

Returns ​

void

Inherited from ​

Context.applyGroupPaint


applyStroke() ​

applyStroke(element): void

Defined in: terminal/src/context.ts:461

Rasterizes and strokes the given path or text element's outline using the current stroke color, composited with the current opacity. Stroked text is drawn as its glyphs in the stroke color, since a character cell has no outline to trace.

Parameters ​

ParameterType
elementContextElement

Returns ​

void

Overrides ​

Context.applyStroke


batch() ​

batch<TResult>(body): TResult

Defined in: core/src/context/context.ts:534

Clears the rendering surface and brackets the callback in markRenderStart/markRenderEnd, returning the callback's result. On exit the state stack is unwound to the depth captured on entry, giving the scene root the same guarantee Context.popGroup gives a group: a root-level clip: true shape deliberately skips its own restore() so the clip persists to later siblings, and with no enclosing group to absorb it that save would otherwise leak one state per frame, unbounded.

The surface is only cleared at render depth 0: a pass entered while an outer one is open continues it (matching Context.markRenderStart) rather than wiping what it drew.

Type Parameters ​

Type ParameterDefault type
TResultvoid

Parameters ​

ParameterType
body() => TResult

Returns ​

TResult

Inherited from ​

Context.batch


clear() ​

clear(): void

Defined in: terminal/src/context.ts:331

Homes the cursor and clears the rasterizer grid.

Returns ​

void

Overrides ​

Context.clear


createPath() ​

createPath(id?): TerminalPath

Defined in: terminal/src/context.ts:424

Creates a TerminalPath that records drawing commands for later rasterization.

Parameters ​

ParameterType
id?string

Returns ​

TerminalPath

Overrides ​

Context.createPath


createText() ​

createText(options): ContextText

Defined in: terminal/src/context.ts:429

Creates a text element from the given options.

Parameters ​

ParameterType
optionsTextOptions

Returns ​

ContextText

Overrides ​

Context.createText


destroy() ​

destroy(): void

Defined in: terminal/src/context.ts:580

Restores the terminal's SGR and cursor state before tearing the context down.

Returns ​

void

Overrides ​

Context.destroy


dispose() ​

protected dispose(key?): void

Defined in: core/src/core/disposer.ts:25

Disposes all resources under the given key, or all resources if no key is provided.

Parameters ​

ParameterType
key?PropertyKey

Returns ​

void

Inherited from ​

Context.dispose


drawImage() ​

drawImage(image, x, y, width?, height?): void

Defined in: core/src/context/context.ts:748

Draws an image onto the rendering surface at the given position and optional size.

Parameters ​

ParameterType
imageCanvasImageSource
xnumber
ynumber
width?number
height?number

Returns ​

void

Inherited from ​

Context.drawImage


emit() ​

Call Signature ​

emit<TEvent>(event): TEvent

Defined in: core/src/core/event-bus.ts:185

Emits an event, invoking all matching handlers and bubbling to the parent if applicable. Handlers for the event's own type run first, then EVENT_WILDCARD subscriptions.

Type Parameters ​
Type ParameterDefault type
TEvent extends Event<undefined>Event<undefined>
Parameters ​
ParameterType
eventTEvent
Returns ​

TEvent

Inherited from ​

Context.emit

Call Signature ​

emit<TEvent>(type, data): Event<ContextEventMap[TEvent]>

Defined in: core/src/core/event-bus.ts:186

Emits an event, invoking all matching handlers and bubbling to the parent if applicable. Handlers for the event's own type run first, then EVENT_WILDCARD subscriptions.

Type Parameters ​
Type Parameter
TEvent extends keyof ContextEventMap
Parameters ​
ParameterType
typeTEvent
dataContextEventMap[TEvent]
Returns ​

Event<ContextEventMap[TEvent]>

Inherited from ​

Context.emit


export() ​

export(): ContextExport

Defined in: terminal/src/context.ts:557

Captures the current grid as a plain-text string, an openable URL, and RGBA image data. The URL is minted once and reused, so release() has a single object URL to revoke.

Returns ​

ContextExport

Overrides ​

Context.export


getDefaultState() ​

protected getDefaultState(): BaseState

Defined in: core/src/context/context.ts:446

Returns ​

BaseState

Inherited from ​

Context.getDefaultState


has() ​

has(type): boolean

Defined in: core/src/core/event-bus.ts:123

Returns whether there are any listeners registered for the given event type. Wildcard subscriptions (EVENT_WILDCARD) are not listeners for any concrete type, so a bus observed only through the wildcard still reports false here.

Parameters ​

ParameterType
typekeyof ContextEventMap

Returns ​

boolean

Inherited from ​

Context.has


hitTest() ​

protected hitTest(events, x, y): RenderElement[]

Defined in: core/src/context/context.ts:808

Tests which rendered elements intersect the given point for the given event types, returning them topmost-first — the exact reverse of the order they were painted in.

The point is in logical space — the space pointer event payloads report — so a handler passes the coordinates it was given straight through.

Paint order is the sole key. Context.renderedElements already records the resolved stacking order (groups paint as contiguous stacking contexts), whereas RenderElement.zIndex is additive across the parent chain and so says nothing about two descendants of different groups; sorting by it discarded correct information.

Parameters ​

ParameterType
eventsstring[]
xnumber
ynumber

Returns ​

RenderElement[]

Inherited from ​

Context.hitTest


invalidateTrackedElements() ​

invalidateTrackedElements(event?): void

Defined in: core/src/context/context.ts:496

Clears the cached list of tracked elements for interaction, forcing a rebuild on the next hit test.

Parameters ​

ParameterType
event?string

Returns ​

void

Inherited from ​

Context.invalidateTrackedElements


isPointInPath() ​

isPointInPath(path, x, y, fillRule?): boolean

Defined in: terminal/src/context.ts:507

Tests whether a logical-space point falls inside the given path.

Parameters ​

ParameterTypeDescription
pathContextPathThe path to test against.
xnumberX coordinate in logical space.
ynumberY coordinate in logical space.
fillRule?FillRuleThe fill rule to apply. Defaults to nonzero, as canvas does.

Returns ​

boolean

true when the point is inside the path.

Overrides ​

Context.isPointInPath


isPointInStroke() ​

isPointInStroke(path, x, y): boolean

Defined in: terminal/src/context.ts:523

Tests whether a logical-space point falls on the given path's stroke.

Parameters ​

ParameterTypeDescription
pathContextPathThe path to test against.
xnumberX coordinate in logical space.
ynumberY coordinate in logical space.

Returns ​

boolean

true when the point is on the stroke.

Overrides ​

Context.isPointInStroke


layer() ​

layer<TResult>(body): TResult

Defined in: core/src/context/context.ts:472

Executes a callback within a save/restore pair, returning the callback's result.

Type Parameters ​

Type ParameterDefault type
TResultvoid

Parameters ​

ParameterType
body() => TResult

Returns ​

TResult

Inherited from ​

Context.layer


markRenderEnd() ​

markRenderEnd(): void

Defined in: terminal/src/context.ts:415

Ends the render pass and, at the outermost depth, flushes the rasterized output to the terminal.

Returns ​

void

Overrides ​

Context.markRenderEnd


markRenderStart() ​

markRenderStart(): void

Defined in: core/src/context/context.ts:510

Signals the start of a render pass; resets the rendered-elements list at depth 0.

Returns ​

void

Inherited from ​

Context.markRenderStart


measureText() ​

measureText(text): TextMetrics

Defined in: terminal/src/context.ts:532

Measures text in logical units, sizing each glyph to one character cell.

Parameters ​

ParameterType
textstring

Returns ​

TextMetrics

Overrides ​

Context.measureText


off() ​

off<TEvent>(type, handler): void

Defined in: core/src/core/event-bus.ts:144

Removes a previously registered handler for the given event type.

Type Parameters ​

Type Parameter
TEvent extends keyof ContextEventMap

Parameters ​

ParameterType
typeTEvent
handlerEventHandler<ContextEventMap[TEvent]>

Returns ​

void

Inherited from ​

Context.off


on() ​

on<TEvent>(type, handler, options?): Disposable

Defined in: core/src/core/event-bus.ts:131

Subscribes a handler to the given event type and returns a disposable for cleanup. Pass EVENT_WILDCARD to receive every event emitted on the bus regardless of type.

Type Parameters ​

Type Parameter
TEvent extends keyof ContextEventMap

Parameters ​

ParameterType
typeTEvent
handlerEventHandler<ContextEventMap[TEvent]>
options?EventSubscriptionOptions

Returns ​

Disposable

Inherited from ​

Context.on


once() ​

once<TEvent>(type, handler, options?): Disposable

Defined in: core/src/core/event-bus.ts:159

Subscribes a handler that is automatically removed after it fires once.

Type Parameters ​

Type Parameter
TEvent extends keyof ContextEventMap

Parameters ​

ParameterType
typeTEvent
handlerEventHandler<ContextEventMap[TEvent]>
options?EventSubscriptionOptions

Returns ​

Disposable

Inherited from ​

Context.once


popGroup() ​

popGroup(): void

Defined in: core/src/context/context.ts:620

Closes the most recently opened group boundary, unwinding the state stack back to the depth captured at Context.pushGroup and restoring the render element that was current before it. This absorbs any dangling save() left by a group-scoped clip (which deliberately skips its own restore so the clip persists to later siblings), confining the clip to the group rather than leaking it to the scene.

Returns ​

void

Inherited from ​

Context.popGroup


pushGroup() ​

pushGroup(group): void

Defined in: core/src/context/context.ts:573

Opens a group boundary: saves the current drawing state and applies the group's own transform and inherited paint (see applyGroupPaint for the opacity and gradient-bounds semantics every backend must honour), so that descendant elements render within the group's coordinate system, inherit its paint through the copied state (the render-tree cascade), and composite under its opacity. Any group-scoped clip is confined to the group. Every Context.pushGroup must be balanced by a matching Context.popGroup. Backends that render hierarchy structurally (such as SVG) override this to nest descendants under a group node.

Parameters ​

ParameterTypeDescription
groupElementThe group element whose boundary is being entered.

Returns ​

void

Inherited from ​

Context.pushGroup


requestRender() ​

requestRender(): void

Defined in: core/src/context/context.ts:505

Requests that the bound scene repaint on the next frame, for context-level changes (e.g. a 3D camera move) that mutate no element and so would otherwise be skipped by the renderer's dirty check.

Returns ​

void

Inherited from ​

Context.requestRender


rescale() ​

protected rescale(width, height): void

Defined in: terminal/src/context.ts:294

Installs the letterbox mapping and reports the new size. The base implementation resets scaleX/scaleY to identity and then emits resize, which a bound scene handles by repainting synchronously — so the mapping has to be complete before the emit, or that repaint places points with the old scales and extents with the new one.

Parameters ​

ParameterType
widthnumber
heightnumber

Returns ​

void

Overrides ​

Context.rescale


reset() ​

reset(): void

Defined in: terminal/src/context.ts:356

Resets the drawing state, the saved-state stack, the transform, the clip region, and the character grid.

Returns ​

void

Overrides ​

Context.reset


restore() ​

restore(): void

Defined in: terminal/src/context.ts:344

Restores the drawing state, the transform, and the clip region saved most recently.

Returns ​

void

Overrides ​

Context.restore


retain() ​

protected retain(value, key?): void

Defined in: core/src/core/disposer.ts:14

Registers a disposable resource under an optional key for later cleanup.

Parameters ​

ParameterTypeDefault value
valueDisposableundefined
keyPropertyKeyDisposer.defaultKey

Returns ​

void

Inherited from ​

Context.retain


rotate() ​

rotate(angle): void

Defined in: terminal/src/context.ts:368

Applies a rotation transformation, in radians.

Parameters ​

ParameterType
anglenumber

Returns ​

void

Overrides ​

Context.rotate


save() ​

save(): void

Defined in: terminal/src/context.ts:337

Pushes the drawing state, the current transform, and the clip region onto the saved-state stack.

Returns ​

void

Overrides ​

Context.save


scale() ​

scale(x, y): void

Defined in: terminal/src/context.ts:373

Applies a scale transformation with the given horizontal and vertical factors.

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

void

Overrides ​

Context.scale


setTransform() ​

setTransform(a, b, c, d, e, f): void

Defined in: terminal/src/context.ts:396

Replaces the current transformation matrix.

The matrix is in logical space, and this backend keeps its letterbox outside the transform, so the identity restores the context's own baseline with nothing to recompose underneath.

Parameters ​

ParameterTypeDescription
anumberHorizontal scaling.
bnumberVertical skewing.
cnumberHorizontal skewing.
dnumberVertical scaling.
enumberHorizontal translation, in logical units.
fnumberVertical translation, in logical units.

Returns ​

void

Overrides ​

Context.setTransform


toLogicalPoint() ​

toLogicalPoint(x, y): [number, number]

Defined in: terminal/src/context.ts:314

Maps a point from the braille raster grid back into the logical space elements are authored in, undoing the letterbox mapping TerminalContext.rescale installs.

The base implementation reads only the slope of scaleX/scaleY and so would drop the centring offset, placing a hit test on the non-limiting axis by the letterbox margin.

Parameters ​

ParameterTypeDescription
xnumberX coordinate in raster space.
ynumberY coordinate in raster space.

Returns ​

[number, number]

The [x, y] pair in logical space.

Overrides ​

Context.toLogicalPoint


toSurfacePoint() ​

toSurfacePoint(x, y): [number, number]

Defined in: terminal/src/context.ts:326

Maps a point from logical space into the braille raster grid, matching what scaleX/scaleY do when drawing. The inverse of TerminalContext.toLogicalPoint.

Parameters ​

ParameterTypeDescription
xnumberX coordinate in logical space.
ynumberY coordinate in logical space.

Returns ​

[number, number]

The [x, y] pair in raster space.

Overrides ​

Context.toSurfacePoint


transform() ​

transform(a, b, c, d, e, f): void

Defined in: terminal/src/context.ts:410

Multiplies the current transformation matrix by the given one.

Parameters ​

ParameterTypeDescription
anumberHorizontal scaling.
bnumberVertical skewing.
cnumberHorizontal skewing.
dnumberVertical scaling.
enumberHorizontal translation, in logical units.
fnumberVertical translation, in logical units.

Returns ​

void

Overrides ​

Context.transform


translate() ​

translate(x, y): void

Defined in: terminal/src/context.ts:378

Applies a translation transformation, in logical units.

Parameters ​

ParameterType
xnumber
ynumber

Returns ​

void

Overrides ​

Context.translate