Skip to main content

Class: SafeArea

Defined in: src/core/SafeArea.ts:101

The rectangle visible in every target aspect, with helpers to position mobjects against it. The safe area is centered at the origin.

Constructors​

Constructor​

new SafeArea(frames): SafeArea

Defined in: src/core/SafeArea.ts:113

Build a safe area from explicit frames (all centered at the origin).

Parameters​

frames​

readonly AspectFrameSize[]

One or more target frames. Must not be empty.

Returns​

SafeArea

Properties​

frames​

readonly frames: readonly AspectFrameSize[]

Defined in: src/core/SafeArea.ts:107

The per-aspect frames this safe area was built from.


height​

readonly height: number

Defined in: src/core/SafeArea.ts:105

Safe-area height in world units.


width​

readonly width: number

Defined in: src/core/SafeArea.ts:103

Safe-area width in world units.

Accessors​

halfHeight​

Get Signature​

get halfHeight(): number

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

Half the safe-area height.

Returns​

number


halfWidth​

Get Signature​

get halfWidth(): number

Defined in: src/core/SafeArea.ts:148

Half the safe-area width.

Returns​

number

Methods​

anchorPoint()​

anchorPoint(anchor, buffer): Vector3Tuple

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

A point on the safe area for the given anchor, inset by buffer. The center anchor returns the origin; edges inset on one axis, corners on both.

Parameters​

anchor​

SafeAreaAnchor

The anchor position.

buffer​

number = 0

Inset from the edge in world units. Defaults to 0.

Returns​

Vector3Tuple

The anchor point [x, y, 0].


contains()​

contains(mob, buffer): boolean

Defined in: src/core/SafeArea.ts:218

Whether a mobject's bounding box fits entirely inside the safe area, optionally inset by buffer.

Parameters​

mob​

Mobject

The mobject to test.

buffer​

number = 0

Inset from the edge in world units. Defaults to 0.

Returns​

boolean

True if the mobject is fully inside.


place()​

place<T>(mob, anchor, buffer): T

Defined in: src/core/SafeArea.ts:191

Position a mobject against the safe area so it stays inside every target aspect. The matching edge or corner of the mobject's bounding box aligns to the safe-area edge, inset by buffer; center moves the mobject to the origin.

Type Parameters​

T​

T extends Mobject

Parameters​

mob​

T

The mobject to position.

anchor​

SafeAreaAnchor = 'center'

The anchor position. Defaults to center.

buffer​

number = 0

Inset from the edge in world units. Defaults to 0.

Returns​

T

The mobject, for chaining.


fromAspectRatios()​

static fromAspectRatios(aspectRatios, options): SafeArea

Defined in: src/core/SafeArea.ts:132

Build a safe area from target aspect ratios (width / height).

Each aspect becomes a frame of the shared reference height, so the frame width is referenceHeight * aspect. This matches the camera's fill mode used by Scene.setFrameAspect.

Parameters​

aspectRatios​

readonly number[]

Target aspect ratios, e.g. [16/9, 9/16, 1/1].

options​

SafeAreaOptions = {}

Reference height (defaults to DEFAULT_FRAME_HEIGHT).

Returns​

SafeArea

A new SafeArea.

Throws​

If aspectRatios is empty.