Documentation / @ripl/3d / CanvasContext3D
Class: CanvasContext3D ​
Defined in: 3d/src/core/context.ts:646
Canvas 2D–backed 3D rendering context with face buffer and painter's algorithm sorting.
Extends ​
Canvas2DState&Context3D<this>
Constructors ​
Constructor ​
new CanvasContext3D(
target,options?):CanvasContext3D
Defined in: 3d/src/core/context.ts:652
Parameters ​
| Parameter | Type |
|---|---|
target | string | HTMLElement |
options? | Context3DOptions |
Returns ​
CanvasContext3D
Overrides ​
canvas2DStateMixin(Context3D).constructor
Properties ​
| Property | Modifier | Type | Default value | Description | Inherited from | Defined in |
|---|---|---|---|---|---|---|
cameraPosition | public | Vector3 | undefined | The camera's world-space position, as last set by setCamera. | canvas2DStateMixin(Context3D).cameraPosition | 3d/src/core/context.ts:185 |
context | protected | CanvasRenderingContext2D | undefined | - | - | 3d/src/core/context.ts:648 |
currentState | protected | BaseState | undefined | - | canvas2DStateMixin(Context3D).currentState | core/src/context/context.ts:104 |
direction | public | Direction | undefined | The current text direction. | canvas2DStateMixin(Context3D).direction | canvas/src/mixins.ts:55 |
element | readonly | HTMLCanvasElement | undefined | The underlying DOM element the context renders into. | canvas2DStateMixin(Context3D).element | core/src/context/context.ts:111 |
faceBuffer | public | ProjectedFace3D[] | [] | Faces accumulated since the last flush, sorted back-to-front and drained when they are drawn (painter's algorithm). A backend that never draws them — the base class, or a GPU context — leaves this empty by clearing it at the start of each pass. | canvas2DStateMixin(Context3D).faceBuffer | 3d/src/core/context.ts:191 |
far | protected | number | undefined | - | canvas2DStateMixin(Context3D).far | 3d/src/core/context.ts:195 |
fill | public | string | undefined | The current fill style: a color or CSS gradient string. Assigning an empty value is ignored, because native canvas rejects it and the paint already in force stays in use. | canvas2DStateMixin(Context3D).fill | canvas/src/mixins.ts:51 |
filter | public | string | undefined | The current filter applied to drawing operations. | canvas2DStateMixin(Context3D).filter | canvas/src/mixins.ts:53 |
font | public | string | undefined | The current font used for text rendering. | canvas2DStateMixin(Context3D).font | canvas/src/mixins.ts:57 |
fontKerning | public | FontKerning | undefined | The current font kerning mode. | canvas2DStateMixin(Context3D).fontKerning | canvas/src/mixins.ts:59 |
fov | protected | number | undefined | - | canvas2DStateMixin(Context3D).fov | 3d/src/core/context.ts:193 |
globalCompositeOperation | public | unknown | undefined | The current compositing operation used when drawing. | canvas2DStateMixin(Context3D).globalCompositeOperation | canvas/src/mixins.ts:63 |
height | public | number | undefined | Current height of the rendering surface, in logical pixels — CSS pixels, unaffected by the device pixel ratio. | canvas2DStateMixin(Context3D).height | core/src/context/context.ts:124 |
hitTestHonorsTransform | public | boolean | false | Whether this context's hit testing natively accounts for element and ancestor group transforms (as SVG does, via the DOM). When false (e.g. canvas), callers map the hit point into the element's local space before testing. See Element.getWorldTransform. | canvas2DStateMixin(Context3D).hitTestHonorsTransform | core/src/context/context.ts:120 |
lights | readonly | LightList | undefined | The lights illuminating the scene. | canvas2DStateMixin(Context3D).lights | 3d/src/core/context.ts:183 |
lineCap | public | LineCap | undefined | The current line cap style for stroke endpoints. | canvas2DStateMixin(Context3D).lineCap | canvas/src/mixins.ts:65 |
lineDash | public | number[] | undefined | The current line dash pattern. | canvas2DStateMixin(Context3D).lineDash | canvas/src/mixins.ts:67 |
lineDashOffset | public | number | undefined | The current offset into the line dash pattern. | canvas2DStateMixin(Context3D).lineDashOffset | canvas/src/mixins.ts:69 |
lineJoin | public | LineJoin | undefined | The current line join style for stroke corners. | canvas2DStateMixin(Context3D).lineJoin | canvas/src/mixins.ts:71 |
lineWidth | public | number | undefined | The current stroke width, in pixels. | canvas2DStateMixin(Context3D).lineWidth | canvas/src/mixins.ts:73 |
meta | readonly | Context3DMeta | undefined | Arbitrary metadata attached to the context. | canvas2DStateMixin(Context3D).meta | core/src/context/context.ts:113 |
miterLimit | public | number | undefined | The current miter limit for stroke joins. | canvas2DStateMixin(Context3D).miterLimit | canvas/src/mixins.ts:75 |
near | protected | number | undefined | - | canvas2DStateMixin(Context3D).near | 3d/src/core/context.ts:194 |
opacity | public | number | undefined | The current global opacity applied to drawing operations. | canvas2DStateMixin(Context3D).opacity | canvas/src/mixins.ts:61 |
parent? | public | EventBus<ContextEventMap> | undefined | The parent event bus that emitted events bubble up to, if any. | canvas2DStateMixin(Context3D).parent | core/src/core/event-bus.ts:107 |
projectionMatrix | public | Matrix4 | undefined | The projection matrix transforming view space into clip space. | canvas2DStateMixin(Context3D).projectionMatrix | 3d/src/core/context.ts:179 |
renderDepth | protected | number | 0 | - | canvas2DStateMixin(Context3D).renderDepth | core/src/context/context.ts:105 |
renderedElements | public | RenderElement[] | undefined | Elements rendered during the current pass, used for hit testing. | canvas2DStateMixin(Context3D).renderedElements | core/src/context/context.ts:132 |
renderElement? | public | RenderElement | undefined | The element currently being rendered, if any. | canvas2DStateMixin(Context3D).renderElement | core/src/context/context.ts:130 |
root | readonly | HTMLElement | undefined | The host DOM element that the context's rendering surface is mounted into. | canvas2DStateMixin(Context3D).root | dom/src/context.ts:48 |
saveDepth | protected | number | 0 | - | canvas2DStateMixin(Context3D).saveDepth | core/src/context/context.ts:106 |
scaleX | public | Scale<number, number> | undefined | Scale mapping logical x coordinates onto this backend's surface x coordinates. Drives drawing, not a conversion seam for callers — use Context.toSurfacePoint. | canvas2DStateMixin(Context3D).scaleX | core/src/context/context.ts:126 |
scaleY | public | Scale<number, number> | undefined | Scale mapping logical y coordinates onto this backend's surface y coordinates. Drives drawing, not a conversion seam for callers — use Context.toSurfacePoint. | canvas2DStateMixin(Context3D).scaleY | core/src/context/context.ts:128 |
shadowBlur | public | number | undefined | The current shadow blur radius. | canvas2DStateMixin(Context3D).shadowBlur | canvas/src/mixins.ts:77 |
shadowColor | public | string | undefined | The current shadow color. | canvas2DStateMixin(Context3D).shadowColor | canvas/src/mixins.ts:79 |
shadowOffsetX | public | number | undefined | The current horizontal shadow offset. | canvas2DStateMixin(Context3D).shadowOffsetX | canvas/src/mixins.ts:81 |
shadowOffsetY | public | number | undefined | The current vertical shadow offset. | canvas2DStateMixin(Context3D).shadowOffsetY | canvas/src/mixins.ts:83 |
states | protected | BaseState[] | undefined | - | canvas2DStateMixin(Context3D).states | core/src/context/context.ts:103 |
stroke | public | string | undefined | The current stroke style: a color or CSS gradient string. Assigning an empty value is ignored, because native canvas rejects it and the paint already in force stays in use. | canvas2DStateMixin(Context3D).stroke | canvas/src/mixins.ts:85 |
textAlign | public | TextAlignment | undefined | The current horizontal text alignment. | canvas2DStateMixin(Context3D).textAlign | canvas/src/mixins.ts:87 |
textBaseline | public | TextBaseline | undefined | The current vertical text baseline. | canvas2DStateMixin(Context3D).textBaseline | canvas/src/mixins.ts:89 |
type | readonly | string | undefined | The context type identifier (e.g. canvas, svg). | canvas2DStateMixin(Context3D).type | core/src/context/context.ts:109 |
viewMatrix | public | Matrix4 | undefined | The view matrix transforming world space into camera (view) space. | canvas2DStateMixin(Context3D).viewMatrix | 3d/src/core/context.ts:177 |
viewProjectionMatrix | public | Matrix4 | undefined | The combined view-projection matrix, transforming world space directly into clip space. | canvas2DStateMixin(Context3D).viewProjectionMatrix | 3d/src/core/context.ts:181 |
width | public | number | undefined | Current width of the rendering surface, in logical pixels — CSS pixels, unaffected by the device pixel ratio. | canvas2DStateMixin(Context3D).width | core/src/context/context.ts:122 |
defaultKey | readonly | typeof defaultKey | undefined | The key under which resources are retained when no explicit key is provided. | canvas2DStateMixin(Context3D).defaultKey | core/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 ​
canvas2DStateMixin(Context3D).$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 ​
| Parameter | Type |
|---|---|
element | RenderElement | undefined |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).currentRenderElement
fog ​
Get Signature ​
get fog():
Fog|null
Defined in: 3d/src/core/context.ts:212
Atmospheric haze blending distant geometry towards a colour, or null for none.
Both backends resolve it identically. Assign a new object to change it — mutating the existing one in place will not repaint.
Returns ​
Fog | null
Set Signature ​
set fog(
value):void
Defined in: 3d/src/core/context.ts:216
Parameters ​
| Parameter | Type |
|---|---|
value | Fog | null |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).fog
lightDirection ​
Get Signature ​
get lightDirection():
Vector3
Defined in: 3d/src/core/context.ts:244
The direction of the default rig's directional light.
A convenience over reaching into lights for the single-light case. Replacing the rig through Context3DOptions.lights, or removing that light, leaves this inert — set the light's own direction instead.
Returns ​
Set Signature ​
set lightDirection(
value):void
Defined in: 3d/src/core/context.ts:248
Parameters ​
| Parameter | Type |
|---|---|
value | Vector3 |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).lightDirection
lightMode ​
Get Signature ​
get lightMode():
LightMode
Defined in: 3d/src/core/context.ts:261
Whether the default rig's directional light is fixed in world space or follows the camera.
Inert once the default rig is replaced, exactly as lightDirection is.
Returns ​
Set Signature ​
set lightMode(
value):void
Defined in: 3d/src/core/context.ts:265
Parameters ​
| Parameter | Type |
|---|---|
value | LightMode |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).lightMode
projectionMode ​
Get Signature ​
get projectionMode():
"perspective"|"orthographic"
Defined in: 3d/src/core/context.ts:228
The projection currently in effect, which a resize preserves.
Returns ​
"perspective" | "orthographic"
Inherited from ​
canvas2DStateMixin(Context3D).projectionMode
renderStrategy ​
Get Signature ​
get renderStrategy():
RenderStrategy
Defined in: 3d/src/core/context.ts:233
The active rendering strategy (cpu or gpu) for this context.
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).renderStrategy
resolvedFog ​
Get Signature ​
get resolvedFog():
ResolvedFog|null
Defined in: 3d/src/core/context.ts:223
The resolved fog both backends shade against, or null when there is none.
Returns ​
ResolvedFog | null
Inherited from ​
canvas2DStateMixin(Context3D).resolvedFog
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 ​
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 ​
| Parameter | Type |
|---|---|
value | Rotation |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).rotation
supportsPathCaching ​
Get Signature ​
get supportsPathCaching():
boolean
Defined in: 3d/src/core/context.ts:668
Whether traced paths may be reused across frames; the 2D elements this context hosts trace side-effect-free paths.
Returns ​
boolean
Overrides ​
canvas2DStateMixin(Context3D).supportsPathCaching
transformOriginX ​
Get Signature ​
get transformOriginX():
TransformOrigin
Defined in: core/src/context/context.ts:400
Horizontal origin about which rotation and scaling are applied.
Returns ​
Set Signature ​
set transformOriginX(
value):void
Defined in: core/src/context/context.ts:404
Horizontal origin about which rotation and scaling are applied.
Parameters ​
| Parameter | Type |
|---|---|
value | TransformOrigin |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
Set Signature ​
set transformOriginY(
value):void
Defined in: core/src/context/context.ts:413
Vertical origin about which rotation and scaling are applied.
Parameters ​
| Parameter | Type |
|---|---|
value | TransformOrigin |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
value | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
value | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
value | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
value | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
value | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).zIndex
Methods ​
applyClip() ​
applyClip(
path,fillRule?):void
Defined in: 3d/src/core/context.ts:922
Clips subsequent drawing, flushing any buffered 3D faces first so the clip cannot reach back over them.
Parameters ​
| Parameter | Type |
|---|---|
path | CanvasPath |
fillRule? | FillRule |
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).applyClip
applyFill() ​
applyFill(
element,fillRule?):void
Defined in: 3d/src/core/context.ts:901
Fills a path or text, flushing any buffered 3D faces first so paint order follows scene order.
Parameters ​
| Parameter | Type |
|---|---|
element | ContextText | CanvasPath |
fillRule? | FillRule |
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).applyFill
applyGroupPaint() ​
protectedapplyGroupPaint(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 ​
| Parameter | Type |
|---|---|
group | Element |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).applyGroupPaint
applyStroke() ​
applyStroke(
element):void
Defined in: 3d/src/core/context.ts:908
Strokes a path or text, flushing any buffered 3D faces first so paint order follows scene order.
Parameters ​
| Parameter | Type |
|---|---|
element | ContextText | CanvasPath |
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).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 Parameter | Default type |
|---|---|
TResult | void |
Parameters ​
| Parameter | Type |
|---|---|
body | () => TResult |
Returns ​
TResult
Inherited from ​
canvas2DStateMixin(Context3D).batch
captureFaceState() ​
captureFaceState(
transform):ProjectedFaceState3D
Defined in: 3d/src/core/context.ts:585
Snapshots the drawing state a face must be painted with.
The CPU painter buffers faces and flushes them at the end of the frame, by which point every element restore() and popGroup() has already unwound the state the face was projected under. Capturing it here is what lets CanvasContext3D re-apply it at draw time.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
transform | Matrix | null | The element's composed 2D world transform, or null for the identity. |
Returns ​
The resolved drawing state to store on each of the element's faces.
Inherited from ​
canvas2DStateMixin(Context3D).captureFaceState
clear() ​
clear():
void
Defined in: canvas/src/mixins.ts:95
Clears the entire canvas surface.
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).clear
createPath() ​
Call Signature ​
createPath(
id?):CanvasPath
Defined in: canvas/src/mixins.ts:127
Creates a new CanvasPath, optionally reusing an id for diffing efficiency.
Parameters ​
| Parameter | Type |
|---|---|
id? | string |
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).createPath
Call Signature ​
createPath(
id?):ContextPath
Defined in: core/src/context/context.ts:738
Creates a new path element, optionally reusing an id for SVG diffing efficiency.
Parameters ​
| Parameter | Type |
|---|---|
id? | string |
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).createPath
createText() ​
createText(
options):ContextText
Defined in: core/src/context/context.ts:743
Creates a new text element from the given options.
Parameters ​
| Parameter | Type |
|---|---|
options | TextOptions |
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).createText
destroy() ​
destroy():
void
Defined in: 3d/src/core/context.ts:944
Destroys the context, releasing the texture patterns and tile canvases cached against it.
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).destroy
disableInteraction() ​
disableInteraction():
void
Defined in: dom/src/context.ts:388
Disables DOM interaction events, unwinding any hover with a final mouseleave per element.
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).disableInteraction
dispose() ​
protecteddispose(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 ​
| Parameter | Type |
|---|---|
key? | PropertyKey |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).dispose
drawImage() ​
drawImage(
image,x,y,width?,height?):void
Defined in: 3d/src/core/context.ts:915
Draws an image, flushing any buffered 3D faces first so paint order follows scene order.
Parameters ​
| Parameter | Type |
|---|---|
image | CanvasImageSource |
x | number |
y | number |
width? | number |
height? | number |
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).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 Parameter | Default type |
|---|---|
TEvent extends Event<undefined> | Event<undefined> |
Parameters ​
| Parameter | Type |
|---|---|
event | TEvent |
Returns ​
TEvent
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
type | TEvent |
data | ContextEventMap[TEvent] |
Returns ​
Event<ContextEventMap[TEvent]>
Inherited from ​
canvas2DStateMixin(Context3D).emit
enableInteraction() ​
enableInteraction():
void
Defined in: dom/src/context.ts:344
Enables DOM interaction events (mouse enter, leave, move, down, up, click, drag) with element hit testing.
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).enableInteraction
export() ​
export():
ContextExport
Defined in: 3d/src/core/context.ts:627
Exports the rendered canvas. Shared by CPU and GPU 3D contexts; call after a frame has rendered (GPU present textures are transient, so createCanvasExport snapshots immediately).
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).export
flushFaces() ​
flushFaces():
void
Defined in: 3d/src/core/context.ts:721
Sorts the buffered faces back-to-front and paints them, then empties the buffer.
Called at the end of the frame and again whenever something else is about to paint — a 2D element, an image, or a clip — so that 3D geometry composites in scene order rather than always landing on top. Faces depth-sort against each other within a flush, not across flushes.
Returns ​
void
getDefaultState() ​
protectedgetDefaultState():BaseState
Defined in: core/src/context/context.ts:446
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).getDefaultState
getLightDirectionForRender() ​
getLightDirectionForRender():
Vector3
Defined in: 3d/src/core/context.ts:414
Returns the effective light direction for the current render, accounting for the light mode.
Both consumers dot this against a world-space normal, so 'world' is the identity and 'camera' reads lightDirection as camera-relative and carries it into world space through the inverse of the view rotation.
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).getLightDirectionForRender
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 ​
| Parameter | Type |
|---|---|
type | keyof ContextEventMap |
Returns ​
boolean
Inherited from ​
canvas2DStateMixin(Context3D).has
hitTest() ​
protectedhitTest(events,x,y):RenderElement[]
Defined in: 3d/src/core/context.ts:480
Tests which rendered elements the pointer is over, ranking 3D shapes by how near their geometry is rather than by paint order.
The base class ranks by paint order, which for 2D is exactly right — the last thing painted is the thing on top. A 3D scene does not paint in element order: CanvasContext3D.flushFaces buffers the faces of every shape and depth-sorts them globally, so what you see is ordered by depth while what the base class hits is ordered by the position an element happened to take in the render stream. For an assembly of interleaved parts those two orders routinely disagree.
2D elements keep their paint order and their positions in the list, so a 2D element painted over a 3D one still wins: it flushed the face buffer, and paint order genuinely does decide there.
Parameters ​
| Parameter | Type |
|---|---|
events | string[] |
x | number |
y | number |
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).hitTest
init() ​
protectedinit():void
Defined in: dom/src/context.ts:85
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).init
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 ​
| Parameter | Type |
|---|---|
event? | string |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).invalidateTrackedElements
isPointInPath() ​
isPointInPath(
path,x,y,fillRule?):boolean
Defined in: canvas/src/mixins.ts:137
Tests whether a point lies inside the filled region of a path.
Parameters ​
| Parameter | Type |
|---|---|
path | ContextPath |
x | number |
y | number |
fillRule? | FillRule |
Returns ​
boolean
Inherited from ​
canvas2DStateMixin(Context3D).isPointInPath
isPointInStroke() ​
isPointInStroke(
path,x,y):boolean
Defined in: canvas/src/mixins.ts:139
Tests whether a point lies on the stroked outline of a path.
Parameters ​
| Parameter | Type |
|---|---|
path | ContextPath |
x | number |
y | number |
Returns ​
boolean
Inherited from ​
canvas2DStateMixin(Context3D).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 Parameter | Default type |
|---|---|
TResult | void |
Parameters ​
| Parameter | Type |
|---|---|
body | () => TResult |
Returns ​
TResult
Inherited from ​
canvas2DStateMixin(Context3D).layer
markRenderEnd() ​
markRenderEnd():
void
Defined in: 3d/src/core/context.ts:704
Ends the render pass and, at the outermost depth, flushes any faces still buffered.
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).markRenderEnd
markRenderStart() ​
markRenderStart():
void
Defined in: 3d/src/core/context.ts:695
Begins a render pass, resetting the frame's face buffer and clip tracking at the outermost depth.
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).markRenderStart
measureText() ​
measureText(
text,font?):TextMetrics
Defined in: canvas/src/mixins.ts:125
Measures text dimensions using the canvas context's current font, text alignment, and baseline, or an optional font override.
Parameters ​
| Parameter | Type |
|---|---|
text | string |
font? | string |
Returns ​
TextMetrics
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<ContextEventMap[TEvent]> |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<ContextEventMap[TEvent]> |
options? | EventSubscriptionOptions |
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).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 ​
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<ContextEventMap[TEvent]> |
options? | EventSubscriptionOptions |
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).once
popGroup() ​
popGroup():
void
Defined in: 3d/src/core/context.ts:934
Closes a group boundary, flushing any faces buffered under a clip installed within it. popGroup unwinds that clip, so a group-scoped clip would otherwise be gone by the time the faces were painted while an identical root-level clip still masked them.
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).popGroup
project() ​
project(
point):ProjectedPoint
Defined in: 3d/src/core/context.ts:571
Projects a 3D world-space point to 2D logical coordinates — CSS pixels relative to the context's top-left — plus a depth for z-ordering.
Parameters ​
| Parameter | Type |
|---|---|
point | Vector3 |
Returns ​
Inherited from ​
canvas2DStateMixin(Context3D).project
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 ​
| Parameter | Type | Description |
|---|---|---|
group | Element | The group element whose boundary is being entered. |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).pushGroup
raycast() ​
raycast(
x,y):Ray|null
Defined in: 3d/src/core/context.ts:429
Builds the world-space ray through a point on the surface.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
x | number | Screen-space x, in logical CSS pixels relative to the context's top-left. |
y | number | Screen-space y. |
Returns ​
Ray | null
The ray, or null when the view-projection matrix is singular.
Inherited from ​
canvas2DStateMixin(Context3D).raycast
raycastAll() ​
raycastAll(
root,x,y,options?):Intersection3D[]
Defined in: 3d/src/core/context.ts:446
Casts a ray through a point on the surface and returns every 3D shape it meets.
Reports the full intersection — point, face, normal and texture coordinate — where hitTest answers only which elements the pointer is over. It also ignores pointerEvents and whether a shape has any handlers, so it sees the whole scene.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
root | Element | The element to search, typically the scene. |
x | number | Screen-space x, in logical CSS pixels relative to the context's top-left. |
y | number | Screen-space y. |
options? | Raycast3DOptions | Whether to accept back-facing hits. |
Returns ​
The intersections, nearest first.
Inherited from ​
canvas2DStateMixin(Context3D).raycastAll
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 ​
canvas2DStateMixin(Context3D).requestRender
rescale() ​
protectedrescale(width,height):void
Defined in: 3d/src/core/context.ts:673
Parameters ​
| Parameter | Type |
|---|---|
width | number |
height | number |
Returns ​
void
Overrides ​
canvas2DStateMixin(Context3D).rescale
reset() ​
reset():
void
Defined in: canvas/src/mixins.ts:97
Resets the context to its default state, dropping the saved-state stack and re-installing the device-pixel-ratio transform the surface is drawn through.
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).reset
resolveLights() ​
resolveLights():
ResolvedLight[]
Defined in: 3d/src/core/context.ts:518
Resolves the scene's lights into the flat numeric form both backends shade against.
Cached until a light changes or the camera moves, because the CPU painter asks for it once per shape and camera-space lights depend on the view matrix.
Returns ​
The enabled lights, capped at MAX_LIGHTS.
Inherited from ​
canvas2DStateMixin(Context3D).resolveLights
restore() ​
restore():
void
Defined in: canvas/src/mixins.ts:93
Restores the most recently saved drawing state from the stack; a no-op when the stack is empty.
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).restore
retain() ​
protectedretain(value,key?):void
Defined in: core/src/core/disposer.ts:14
Registers a disposable resource under an optional key for later cleanup.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
value | Disposable | undefined |
key | PropertyKey | Disposer.defaultKey |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).retain
rotate() ​
rotate(
angle):void
Defined in: canvas/src/mixins.ts:99
Applies a rotation transformation, in radians.
Parameters ​
| Parameter | Type |
|---|---|
angle | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).rotate
save() ​
save():
void
Defined in: canvas/src/mixins.ts:91
Saves the current drawing state, including the resolved Canvas2DState.fill and Canvas2DState.stroke strings, onto the state stack.
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).save
scale() ​
scale(
x,y):void
Defined in: canvas/src/mixins.ts:101
Applies a scale transformation.
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).scale
setCamera() ​
setCamera(
eye,target,up):void
Defined in: 3d/src/core/context.ts:367
Sets the view matrix from an eye position, look-at target, and up direction.
Parameters ​
| Parameter | Type |
|---|---|
eye | Vector3 |
target | Vector3 |
up | Vector3 |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).setCamera
setOrthographic() ​
setOrthographic(
left,right,bottom,top,near,far):void
Defined in: 3d/src/core/context.ts:393
Sets an orthographic projection with explicit frustum bounds.
The bounds are retained and replayed verbatim whenever the projection is rebuilt, so a resize keeps the projection orthographic. It does not re-fit the frustum to the new aspect ratio — the caller owns that, and Camera recomputes it on its next flush.
Parameters ​
| Parameter | Type |
|---|---|
left | number |
right | number |
bottom | number |
top | number |
near | number |
far | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).setOrthographic
setPerspective() ​
setPerspective(
fov,near,far):void
Defined in: 3d/src/core/context.ts:377
Updates the perspective projection with the given field of view, near, and far planes, replacing any orthographic projection.
Parameters ​
| Parameter | Type |
|---|---|
fov | number |
near | number |
far | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).setPerspective
setTransform() ​
setTransform(
a,b,c,d,e,f):void
Defined in: canvas/src/mixins.ts:113
Replaces the current transformation matrix with [a, b, c, d, e, f].
Parameters ​
| Parameter | Type | Description |
|---|---|---|
a | number | Horizontal scaling. |
b | number | Vertical skewing. |
c | number | Horizontal skewing. |
d | number | Vertical scaling. |
e | number | Horizontal translation. |
f | number | Vertical translation. |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).setTransform
submitMesh() ​
submitMesh(
submission):void
Defined in: 3d/src/core/context.ts:619
Submits a mesh for rendering this frame. Noop in the base class; overridden by GPU-backed contexts.
Parameters ​
| Parameter | Type |
|---|---|
submission | MeshSubmission |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).submitMesh
toLogicalPoint() ​
toLogicalPoint(
x,y): [number,number]
Defined in: core/src/context/context.ts:697
Maps a point from surface space — this backend's own drawing coordinates, as produced by Context.scaleX and Context.scaleY — into the logical space elements are authored in and every public coordinate is expressed in.
Backends disagree on what surface space is: canvas maps logical coordinates onto device pixels while SVG leaves them identity, so a backend has to invert what this context actually does rather than assume the device pixel ratio.
This is a seam for backend implementors, not for consumers — nothing crossing the public API is in surface space, so a caller holding a pointer coordinate already has a logical one.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
x | number | X coordinate in surface space. |
y | number | Y coordinate in surface space. |
Returns ​
[number, number]
The [x, y] pair in logical space.
Inherited from ​
canvas2DStateMixin(Context3D).toLogicalPoint
toSurfacePoint() ​
toSurfacePoint(
x,y): [number,number]
Defined in: core/src/context/context.ts:710
Maps a point from the logical space elements are authored in into this backend's own drawing coordinates. The inverse of Context.toLogicalPoint, and likewise a seam for backend implementors rather than consumers.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
x | number | X coordinate in logical space. |
y | number | Y coordinate in logical space. |
Returns ​
[number, number]
The [x, y] pair in surface space.
Inherited from ​
canvas2DStateMixin(Context3D).toSurfacePoint
transform() ​
transform(
a,b,c,d,e,f):void
Defined in: canvas/src/mixins.ts:123
Multiplies the current transformation matrix by [a, b, c, d, e, f].
Parameters ​
| Parameter | Type | Description |
|---|---|---|
a | number | Horizontal scaling. |
b | number | Vertical skewing. |
c | number | Horizontal skewing. |
d | number | Vertical scaling. |
e | number | Horizontal translation. |
f | number | Vertical translation. |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).transform
translate() ​
translate(
x,y):void
Defined in: canvas/src/mixins.ts:103
Applies a translation transformation.
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).translate
updateProjectionMatrix() ​
protectedupdateProjectionMatrix():void
Defined in: 3d/src/core/context.ts:346
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).updateProjectionMatrix
updateViewProjectionMatrix() ​
protectedupdateViewProjectionMatrix():void
Defined in: 3d/src/core/context.ts:342
Returns ​
void
Inherited from ​
canvas2DStateMixin(Context3D).updateViewProjectionMatrix