Skip to content

Visualize Your Ideas With Code

refactor: introduce improved names (#425)

Jacob4a2188d33958
diff --git a/packages/2d/src/components/CodeBlock.ts b/packages/2d/src/components/CodeBlock.ts
index d9ce3386..1134f829 100644
--- a/packages/2d/src/components/CodeBlock.ts
+++ b/packages/2d/src/components/CodeBlock.ts
@@ -126,7 +126,7 @@ export class CodeBlock extends Shape {
@initial(0.32)
@signal()
- public declare readonly selectionOpacity: SimpleSignal<number, this>;
+ public declare readonly unselectedOpacity: SimpleSignal<number, this>;
private codeProgress = createSignal<number | null>(null);
private selectionProgress = createSignal<number | null>(null);
@@ -353,11 +353,11 @@ export class CodeBlock extends Shape {
const w = context.measureText('X').width;
const size = this.computedSize();
const progress = this.codeProgress();
- const selectionOpacity = this.selectionOpacity();
+ const unselectedOpacity = this.unselectedOpacity();
const globalAlpha = context.globalAlpha;
const getSelectionAlpha = (x: number, y: number) =>
- map(selectionOpacity, 1, this.selectionStrength(x, y));
+ map(unselectedOpacity, 1, this.selectionStrength(x, y));
const drawToken = (
code: string,
diff --git a/packages/2d/src/components/Icon.ts b/packages/2d/src/components/Icon.ts
index 892133fb..de3b036a 100644
--- a/packages/2d/src/components/Icon.ts
+++ b/packages/2d/src/components/Icon.ts
@@ -1,10 +1,10 @@
-import {Image, ImageProps} from '../components/Image';
+import {Img, ImgProps} from './Img';
import {colorSignal, computed, initial, signal} from '../decorators';
import {SignalValue, SimpleSignal} from '@motion-canvas/core/lib/signals';
import {useLogger} from '@motion-canvas/core/lib/utils';
import {ColorSignal, PossibleColor} from '@motion-canvas/core/lib/types';
-export interface IconProps extends ImageProps {
+export interface IconProps extends ImgProps {
/**
* {@inheritDoc Icon.icon}
*/
@@ -20,7 +20,7 @@ export interface IconProps extends ImageProps {
* An Icon Component that provides an easy access to over 150k icons.
* See https://icones.js.org/collection/all for all available Icons.
*/
-export class Icon extends Image {
+export class Icon extends Img {
/**
* The identifier of the icon.
*
@@ -79,7 +79,7 @@ export class Icon extends Image {
*/
protected setSrc() {
useLogger().warn(
- "The Icon Component does not accept setting the `src`. If you need access to `src`, use '<Image/>` instead.",
+ "The Icon Component does not accept setting the `src`. If you need access to `src`, use '<Img/>` instead.",
);
}
}
diff --git a/packages/2d/src/components/Image.ts b/packages/2d/src/components/Img.ts
similarity index 92%
rename from packages/2d/src/components/Image.ts
rename to packages/2d/src/components/Img.ts
index 5de7b9f2..1b34a5b1 100644
--- a/packages/2d/src/components/Image.ts
+++ b/packages/2d/src/components/Img.ts
@@ -2,7 +2,7 @@ import {computed, initial, signal} from '../decorators';
import {
Color,
PossibleVector2,
- Rect as RectType,
+ BBox,
SerializedVector2,
Vector2,
} from '@motion-canvas/core/lib/types';
@@ -16,13 +16,13 @@ import {
} from '@motion-canvas/core/lib/signals';
import {viaProxy} from '@motion-canvas/core/lib/utils';
-export interface ImageProps extends RectProps {
+export interface ImgProps extends RectProps {
src?: SignalValue<string>;
alpha?: SignalValue<number>;
smoothing?: SignalValue<boolean>;
}
-export class Image extends Rect {
+export class Img extends Rect {
private static pool: Record<string, HTMLImageElement> = {};
@signal()
@@ -36,7 +36,7 @@ export class Image extends Rect {
@signal()
public declare readonly smoothing: SimpleSignal<boolean, this>;
- public constructor(props: ImageProps) {
+ public constructor(props: ImgProps) {
super(props);
}
@@ -56,8 +56,8 @@ export class Image extends Rect {
@computed()
protected image(): HTMLImageElement {
const src = viaProxy(this.src());
- if (Image.pool[src]) {
- return Image.pool[src];
+ if (Img.pool[src]) {
+ return Img.pool[src];
}
const image = document.createElement('img');
@@ -71,7 +71,7 @@ export class Image extends Rect {
}),
);
}
- Image.pool[src] = image;
+ Img.pool[src] = image;
return image;
}
@@ -107,13 +107,13 @@ export class Image extends Rect {
}
const alpha = this.alpha();
if (alpha > 0) {
- const rect = RectType.fromSizeCentered(this.computedSize());
+ const box = BBox.fromSizeCentered(this.computedSize());
context.save();
if (alpha < 1) {
context.globalAlpha *= alpha;
}
context.imageSmoothingEnabled = this.smoothing();
- drawImage(context, this.image(), rect);
+ drawImage(context, this.image(), box);
context.restore();
}
this.drawChildren(context);
diff --git a/packages/2d/src/components/Latex.ts b/packages/2d/src/components/Latex.ts
index 42c30cb5..bf1feb19 100644
--- a/packages/2d/src/components/Latex.ts
+++ b/packages/2d/src/components/Latex.ts
@@ -5,7 +5,7 @@ import {AllPackages} from 'mathjax-full/js/input/tex/AllPackages';
import {liteAdaptor} from 'mathjax-full/js/adaptors/liteAdaptor';
import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html';
import {initial, signal} from '../decorators';
-import {Image, ImageProps} from './Image';
+import {Img, ImgProps} from './Img';
import {
DependencyContext,
SignalValue,
@@ -22,12 +22,12 @@ const jaxDocument = mathjax.document('', {
OutputJax: new SVG({fontCache: 'local'}),
});
-export interface LatexProps extends ImageProps {
+export interface LatexProps extends ImgProps {
tex?: SignalValue<string>;
renderProps?: SignalValue<OptionList>;
}
-export class Latex extends Image {
+export class Latex extends Img {
private static svgContentsPool: Record<string, string> = {};
private readonly imageElement = document.createElement('img');
diff --git a/packages/2d/src/components/Layout.ts b/packages/2d/src/components/Layout.ts
index 8b34d80f..8666d553 100644
--- a/packages/2d/src/components/Layout.ts
+++ b/packages/2d/src/components/Layout.ts
@@ -13,7 +13,7 @@ import {
originToOffset,
PossibleSpacing,
PossibleVector2,
- Rect,
+ BBox,
SerializedVector2,
SpacingSignal,
Vector2,
@@ -530,25 +530,25 @@ export class Layout extends Node {
return matrix;
}
- protected getComputedLayout(): Rect {
- return new Rect(this.element.getBoundingClientRect());
+ protected getComputedLayout(): BBox {
+ return new BBox(this.element.getBoundingClientRect());
}
@computed()
public computedPosition(): Vector2 {
this.requestLayoutUpdate();
- const rect = this.getComputedLayout();
+ const box = this.getComputedLayout();
const position = new Vector2(
- rect.x + (rect.width / 2) * this.offset.x(),
- rect.y + (rect.height / 2) * this.offset.y(),
+ box.x + (box.width / 2) * this.offset.x(),
+ box.y + (box.height / 2) * this.offset.y(),
);
const parent = this.parentTransform();
if (parent) {
const parentRect = parent.getComputedLayout();
- position.x -= parentRect.x + (parentRect.width - rect.width) / 2;
- position.y -= parentRect.y + (parentRect.height - rect.height) / 2;
+ position.x -= parentRect.x + (parentRect.width - box.width) / 2;
+ position.y -= parentRect.y + (parentRect.height - box.height) / 2;
}
return position;
@@ -627,8 +627,8 @@ export class Layout extends Node {
this.applyFont();
}
- protected override getCacheRect(): Rect {
- return Rect.fromSizeCentered(this.computedSize());
+ protected override getCacheBBox(): BBox {
+ return BBox.fromSizeCentered(this.computedSize());
}
protected override draw(context: CanvasRenderingContext2D) {
@@ -653,12 +653,12 @@ export class Layout extends Node {
) {
const size = this.computedSize();
const offset = size.mul(this.offset()).scale(0.5).transformAsPoint(matrix);
- const rect = Rect.fromSizeCentered(size);
- const layout = rect.transformCorners(matrix);
- const padding = rect
+ const box = BBox.fromSizeCentered(size);
+ const layout = box.transformCorners(matrix);
+ const padding = box
.addSpacing(this.padding().scale(-1))
.transformCorners(matrix);
- const margin = rect.addSpacing(this.margin()).transformCorners(matrix);
+ const margin = box.addSpacing(this.margin()).transformCorners(matrix);
context.beginPath();
drawLine(context, margin);
@@ -826,7 +826,7 @@ export class Layout extends Node {
public override hit(position: Vector2): Node | null {
const local = position.transformAsPoint(this.localToParent().inverse());
- if (this.cacheRect().includes(local)) {
+ if (this.cacheBBox().includes(local)) {
return super.hit(position) ?? this;
}
diff --git a/packages/2d/src/components/Line.ts b/packages/2d/src/components/Line.ts
index 7d8fa970..afd6e84f 100644
--- a/packages/2d/src/components/Line.ts
+++ b/packages/2d/src/components/Line.ts
@@ -9,7 +9,7 @@ import {
} from '@motion-canvas/core/lib/signals';
import {
PossibleVector2,
- Rect,
+ BBox,
SerializedVector2,
Vector2,
} from '@motion-canvas/core/lib/types';
@@ -85,7 +85,7 @@ export class Line extends Shape {
>;
protected override desiredSize(): SerializedVector2<DesiredLength> {
- return this.childrenRect().size;
+ return this.childrenBBox().size;
}
public constructor(props: LineProps) {
@@ -100,7 +100,7 @@ export class Line extends Shape {
}
@computed()
- protected childrenRect() {
+ protected childrenBBox() {
const custom = this.points();
const points = custom
? custom.map(
@@ -110,7 +110,7 @@ export class Line extends Shape {
.filter(child => !(child instanceof Layout) || child.isLayoutRoot())
.map(child => child.position());
- return Rect.fromPoints(...points);
+ return BBox.fromPoints(...points);
}
@computed()
@@ -224,21 +224,21 @@ export class Line extends Shape {
context.lineDashOffset -= arcLength / 2;
}
- protected override getComputedLayout(): Rect {
- const rect = super.getComputedLayout();
- rect.position = rect.position.sub(this.childrenRect().center);
- return rect;
+ protected override getComputedLayout(): BBox {
+ const box = super.getComputedLayout();
+ box.position = box.position.sub(this.childrenBBox().center);
+ return box;
}
protected override getPath(): Path2D {
return this.curveDrawingInfo().path;
}
- protected override getCacheRect(): Rect {
- const rect = this.childrenRect();
+ protected override getCacheBBox(): BBox {
+ const box = this.childrenBBox();
const arrowSize = this.arrowSize();
const lineWidth = this.lineWidth();
- return rect.expand(Math.max(0, arrowSize, lineWidth / 2));
+ return box.expand(Math.max(0, arrowSize, lineWidth / 2));
}
protected override drawShape(context: CanvasRenderingContext2D) {
@@ -283,7 +283,7 @@ export class Line extends Shape {
context: CanvasRenderingContext2D,
matrix: DOMMatrix,
) {
- const rect = this.childrenRect().transformCorners(matrix);
+ const box = this.childrenBBox().transformCorners(matrix);
const size = this.computedSize();
const offset = size.mul(this.offset()).scale(0.5).transformAsPoint(matrix);
@@ -320,7 +320,7 @@ export class Line extends Shape {
context.stroke();
context.beginPath();
- drawLine(context, rect);
+ drawLine(context, box);
context.closePath();
context.stroke();
}
diff --git a/packages/2d/src/components/Node.ts b/packages/2d/src/components/Node.ts
index 40996bde..dee3891f 100644
--- a/packages/2d/src/components/Node.ts
+++ b/packages/2d/src/components/Node.ts
@@ -12,7 +12,7 @@ import {
} from '../decorators';
import {
Vector2,
- Rect,
+ BBox,
transformScalar,
PossibleColor,
transformAngle,
@@ -593,7 +593,7 @@ export class Node implements Promisable<Node> {
* </Layout>
* );
*
- * node.insert(<Text />, 1);
+ * node.insert(<Txt />, 1);
* ```
*
* Result:
@@ -1009,7 +1009,7 @@ export class Node implements Promisable<Node> {
@computed()
protected cachedCanvas() {
const context = this.cacheCanvas();
- const cache = this.cacheRect();
+ const cache = this.cacheBBox();
context.canvas.width = cache.width;
context.canvas.height = cache.height;
context.resetTransform();
@@ -1020,22 +1020,22 @@ export class Node implements Promisable<Node> {
}
/**
- * Get a rectangle encapsulating the contents rendered by this node.
+ * Get a bounding box for the contents rendered by this node.
*
* @remarks
- * The returned rectangle should be in local space.
+ * The returned bounding box should be in local space.
*/
- protected getCacheRect(): Rect {
- return new Rect();
+ protected getCacheBBox(): BBox {
+ return new BBox();
}
/**
- * Get a rectangle encapsulating the contents rendered by this node as well
+ * Get a bounding box for the contents rendered by this node as well
* as its children.
*/
@computed()
- public cacheRect(): Rect {
- const cache = this.getCacheRect();
+ public cacheBBox(): BBox {
+ const cache = this.getCacheBBox();
const children = this.children();
if (children.length === 0) {
return cache.pixelPerfect;
@@ -1043,30 +1043,30 @@ export class Node implements Promisable<Node> {
const points: Vector2[] = cache.corners;
for (const child of children) {
- const childCache = child.fullCacheRect();
+ const childCache = child.fullCacheBBox();
const childMatrix = child.localToParent();
points.push(
...childCache.corners.map(r => r.transformAsPoint(childMatrix)),
);
}
- return Rect.fromPoints(...points).pixelPerfect;
+ return BBox.fromPoints(...points).pixelPerfect;
}
/**
- * Get a rectangle encapsulating the contents rendered by this node (including
+ * Get a bounding box for the contents rendered by this node (including
* effects applied after caching).
*
* @remarks
- * The returned rectangle should be in local space.
+ * The returned bounding box should be in local space.
*/
@computed()
- protected fullCacheRect(): Rect {
+ protected fullCacheBBox(): BBox {
const matrix = this.compositeToLocal();
const shadowOffset = this.shadowOffset().transform(matrix);
const shadowBlur = transformScalar(this.shadowBlur(), matrix);
- const result = this.cacheRect().expand(
+ const result = this.cacheBBox().expand(
this.filters.blur() * 2 + shadowBlur,
);
@@ -1132,7 +1132,7 @@ export class Node implements Promisable<Node> {
this.transformContext(context);
if (this.requiresCache()) {
- const cacheRect = this.cacheRect();
+ const cacheRect = this.cacheBBox();
if (cacheRect.width !== 0 && cacheRect.height !== 0) {
this.setupDrawFromCache(context);
const cacheContext = this.cachedCanvas();
@@ -1189,12 +1189,12 @@ export class Node implements Promisable<Node> {
* @param matrix - A local-to-screen matrix.
*/
public drawOverlay(context: CanvasRenderingContext2D, matrix: DOMMatrix) {
- const rect = this.cacheRect().transformCorners(matrix);
- const cache = this.getCacheRect().transformCorners(matrix);
+ const box = this.cacheBBox().transformCorners(matrix);
+ const cache = this.getCacheBBox().transformCorners(matrix);
context.strokeStyle = 'white';
context.lineWidth = 1;
context.beginPath();
- drawLine(context, rect);
+ drawLine(context, box);
context.closePath();
context.stroke();
diff --git a/packages/2d/src/components/Rect.ts b/packages/2d/src/components/Rect.ts
index e2cd884e..6c2a36f2 100644
--- a/packages/2d/src/components/Rect.ts
+++ b/packages/2d/src/components/Rect.ts
@@ -1,6 +1,6 @@
import {
PossibleSpacing,
- Rect as RectType,
+ BBox,
SpacingSignal,
} from '@motion-canvas/core/lib/types';
import {Shape, ShapeProps} from './Shape';
@@ -81,14 +81,14 @@ export class Rect extends Shape {
const radius = this.radius();
const smoothCorners = this.smoothCorners();
const cornerSharpness = this.cornerSharpness();
- const rect = RectType.fromSizeCentered(this.size());
- drawRoundRect(path, rect, radius, smoothCorners, cornerSharpness);
+ const box = BBox.fromSizeCentered(this.size());
+ drawRoundRect(path, box, radius, smoothCorners, cornerSharpness);
return path;
}
- protected override getCacheRect(): RectType {
- return super.getCacheRect().expand(this.rippleSize());
+ protected override getCacheBBox(): BBox {
+ return super.getCacheBBox().expand(this.rippleSize());
}
protected override getRipplePath(): Path2D {
@@ -97,8 +97,8 @@ export class Rect extends Shape {
const radius = this.radius().addScalar(rippleSize);
const smoothCorners = this.smoothCorners();
const cornerSharpness = this.cornerSharpness();
- const rect = RectType.fromSizeCentered(this.size()).expand(rippleSize);
- drawRoundRect(path, rect, radius, smoothCorners, cornerSharpness);
+ const box = BBox.fromSizeCentered(this.size()).expand(rippleSize);
+ drawRoundRect(path, box, radius, smoothCorners, cornerSharpness);
return path;
}
diff --git a/packages/2d/src/components/Shape.ts b/packages/2d/src/components/Shape.ts
index cb1df395..8feedd92 100644
--- a/packages/2d/src/components/Shape.ts
+++ b/packages/2d/src/components/Shape.ts
@@ -1,6 +1,6 @@
import {PossibleCanvasStyle} from '../partials';
import {computed, initial, signal} from '../decorators';
-import {Rect} from '@motion-canvas/core/lib/types';
+import {BBox} from '@motion-canvas/core/lib/types';
import {Layout, LayoutProps} from './Layout';
import {threadable} from '@motion-canvas/core/lib/decorators';
import {easeOutExpo, linear, map} from '@motion-canvas/core/lib/tweening';
@@ -110,8 +110,8 @@ export abstract class Shape extends Layout {
context.restore();
}
- protected override getCacheRect(): Rect {
- return super.getCacheRect().expand(this.lineWidth() / 2);
+ protected override getCacheBBox(): BBox {
+ return super.getCacheBBox().expand(this.lineWidth() / 2);
}
@computed()
diff --git a/packages/2d/src/components/Text.ts b/packages/2d/src/components/Txt.ts
similarity index 81%
rename from packages/2d/src/components/Text.ts
rename to packages/2d/src/components/Txt.ts
index c83a7741..8bfe229f 100644
--- a/packages/2d/src/components/Text.ts
+++ b/packages/2d/src/components/Txt.ts
@@ -2,16 +2,16 @@ import {computed, initial, interpolation, signal} from '../decorators';
import {useLogger} from '@motion-canvas/core/lib/utils';
import {textLerp} from '@motion-canvas/core/lib/tweening';
import {Shape, ShapeProps} from './Shape';
-import {Rect} from '@motion-canvas/core/lib/types';
+import {BBox} from '@motion-canvas/core/lib/types';
import {SignalValue, SimpleSignal} from '@motion-canvas/core/lib/signals';
import {View2D} from './View2D';
-export interface TextProps extends ShapeProps {
+export interface TxtProps extends ShapeProps {
children?: string;
text?: SignalValue<string>;
}
-export class Text extends Shape {
+export class Txt extends Shape {
protected static segmenter;
protected static formatter: HTMLDivElement;
@@ -33,7 +33,7 @@ export class Text extends Shape {
@signal()
public declare readonly text: SimpleSignal<string, this>;
- public constructor({children, ...rest}: TextProps) {
+ public constructor({children, ...rest}: TxtProps) {
super(rest);
if (children) {
this.text(children);
@@ -50,7 +50,7 @@ export class Text extends Shape {
const {width, height} = this.size();
const range = document.createRange();
let line = '';
- const lineRect = new Rect();
+ const lineRect = new BBox();
for (const childNode of this.element.childNodes) {
if (!childNode.textContent) {
continue;
@@ -81,20 +81,20 @@ export class Text extends Shape {
protected drawText(
context: CanvasRenderingContext2D,
text: string,
- rect: Rect,
+ box: BBox,
) {
- const y = rect.y + rect.height / 2;
+ const y = box.y + box.height / 2;
context.save();
context.textBaseline = 'middle';
if (this.lineWidth() <= 0) {
- context.fillText(text, rect.x, y);
+ context.fillText(text, box.x, y);
} else if (this.strokeFirst()) {
- context.strokeText(text, rect.x, y);
- context.fillText(text, rect.x, y);
+ context.strokeText(text, box.x, y);
+ context.fillText(text, box.x, y);
} else {
- context.fillText(text, rect.x, y);
- context.strokeText(text, rect.x, y);
+ context.fillText(text, box.x, y);
+ context.strokeText(text, box.x, y);
}
context.restore();
@@ -102,8 +102,8 @@ export class Text extends Shape {
@computed()
protected formattedText() {
- Text.formatter.innerText = this.text();
- return Text.formatter.innerText;
+ Txt.formatter.innerText = this.text();
+ return Txt.formatter.innerText;
}
protected override updateLayout() {
@@ -113,9 +113,9 @@ export class Text extends Shape {
const wrap =
this.styles.whiteSpace !== 'nowrap' && this.styles.whiteSpace !== 'pre';
- if (wrap && Text.segmenter) {
+ if (wrap && Txt.segmenter) {
this.element.innerText = '';
- for (const word of Text.segmenter.segment(this.formattedText())) {
+ for (const word of Txt.segmenter.segment(this.formattedText())) {
this.element.appendChild(document.createTextNode(word.segment));
}
} else if (this.styles.whiteSpace === 'pre') {
@@ -127,7 +127,7 @@ export class Text extends Shape {
this.element.innerText = this.formattedText();
}
- if (wrap && !Text.segmenter) {
+ if (wrap && !Txt.segmenter) {
useLogger().warn({
message: 'Wrapping is not supported',
inspect: this.key,
diff --git a/packages/2d/src/components/Video.ts b/packages/2d/src/components/Video.ts
index a7dc4202..31994c21 100644
--- a/packages/2d/src/components/Video.ts
+++ b/packages/2d/src/components/Video.ts
@@ -1,7 +1,4 @@
-import {
- Rect as RectType,
- SerializedVector2,
-} from '@motion-canvas/core/lib/types';
+import {BBox, SerializedVector2} from '@motion-canvas/core/lib/types';
import {drawImage} from '../utils';
import {computed, initial, signal} from '../decorators';
import {useThread} from '@motion-canvas/core/lib/utils';
@@ -166,13 +163,13 @@ export class Video extends Rect {
? this.fastSeekedVideo()
: this.seekedVideo();
- const rect = RectType.fromSizeCentered(this.computedSize());
+ const box = BBox.fromSizeCentered(this.computedSize());
context.save();
if (alpha < 1) {
context.globalAlpha *= alpha;
}
context.imageSmoothingEnabled = this.smoothing();
- drawImage(context, video, rect);
+ drawImage(context, video, box);
context.restore();
}
diff --git a/packages/2d/src/components/index.ts b/packages/2d/src/components/index.ts
index d13f38d0..0130fd82 100644
--- a/packages/2d/src/components/index.ts
+++ b/packages/2d/src/components/index.ts
@@ -1,6 +1,6 @@
export * from './Circle';
export * from './Icon';
-export * from './Image';
+export * from './Img';
export * from './Grid';
export * from './Latex';
export * from './Layout';
@@ -8,7 +8,7 @@ export * from './Line';
export * from './Node';
export * from './Rect';
export * from './Shape';
-export * from './Text';
+export * from './Txt';
export * from './types';
export * from './Video';
export * from './View2D';
diff --git a/packages/2d/src/utils/CanvasUtils.ts b/packages/2d/src/utils/CanvasUtils.ts
index 2f994856..a8d3f2cb 100644
--- a/packages/2d/src/utils/CanvasUtils.ts
+++ b/packages/2d/src/utils/CanvasUtils.ts
@@ -1,5 +1,5 @@
import {CanvasStyle, Gradient, Pattern, PossibleCanvasStyle} from '../partials';
-import {Color, Rect, Spacing, Vector2} from '@motion-canvas/core/lib/types';
+import {Color, BBox, Spacing, Vector2} from '@motion-canvas/core/lib/types';
export function canvasStyleParser(style: PossibleCanvasStyle) {
if (style === null) {
@@ -37,7 +37,7 @@ export function resolveCanvasStyle(
export function drawRoundRect(
context: CanvasRenderingContext2D | Path2D,
- rect: Rect,
+ rect: BBox,
radius: Spacing,
smoothCorners: boolean,
cornerSharpness: number,
@@ -133,7 +133,7 @@ function adjustRectRadius(
radius: number,
horizontal: number,
vertical: number,
- rect: Rect,
+ rect: BBox,
): number {
const width =
radius + horizontal > rect.width
@@ -149,35 +149,35 @@ function adjustRectRadius(
export function drawRect(
context: CanvasRenderingContext2D | Path2D,
- rect: Rect,
+ rect: BBox,
) {
context.rect(rect.x, rect.y, rect.width, rect.height);
}
-export function fillRect(context: CanvasRenderingContext2D, rect: Rect) {
+export function fillRect(context: CanvasRenderingContext2D, rect: BBox) {
context.fillRect(rect.x, rect.y, rect.width, rect.height);
}
-export function strokeRect(context: CanvasRenderingContext2D, rect: Rect) {
+export function strokeRect(context: CanvasRenderingContext2D, rect: BBox) {
context.strokeRect(rect.x, rect.y, rect.width, rect.height);
}
export function drawImage(
context: CanvasRenderingContext2D,
image: CanvasImageSource,
- destination: Rect,
+ destination: BBox,
): void;
export function drawImage(
context: CanvasRenderingContext2D,
image: CanvasImageSource,
- source: Rect,
- destination: Rect,
+ source: BBox,
+ destination: BBox,
): void;
export function drawImage(
context: CanvasRenderingContext2D,
image: CanvasImageSource,
- first: Rect,
- second?: Rect,
+ first: BBox,
+ second?: BBox,
): void {
if (second) {
context.drawImage(
diff --git a/packages/core/src/scenes/GeneratorScene.ts b/packages/core/src/scenes/GeneratorScene.ts
index fbe4e4ef..746ef960 100644
--- a/packages/core/src/scenes/GeneratorScene.ts
+++ b/packages/core/src/scenes/GeneratorScene.ts
@@ -20,7 +20,7 @@ import {
} from './Scene';
import {LifecycleEvents} from './LifecycleEvents';
import {Threadable} from './Threadable';
-import {Rect, Vector2} from '../types';
+import {BBox, Vector2} from '../types';
import {SceneState} from './SceneState';
import {Random} from './Random';
import {DependencyContext} from '../signals';
@@ -146,8 +146,8 @@ export abstract class GeneratorScene<T>
iterations++;
await Promise.all(promises.map(handle => handle.promise));
context.save();
- const rect = Rect.fromSizeCentered(this.getSize());
- context.clearRect(rect.x, rect.y, rect.width, rect.height);
+ const box = BBox.fromSizeCentered(this.getSize());
+ context.clearRect(box.x, box.y, box.width, box.height);
this.draw(context);
context.restore();
diff --git a/packages/core/src/transitions/zoomInTransition.ts b/packages/core/src/transitions/zoomInTransition.ts
index cb5f847a..6b0c49fe 100644
--- a/packages/core/src/transitions/zoomInTransition.ts
+++ b/packages/core/src/transitions/zoomInTransition.ts
@@ -1,4 +1,4 @@
-import {Rect, Vector2} from '../types';
+import {BBox, Vector2} from '../types';
import {useScene} from '../utils';
import {useTransition} from './useTransition';
import {clampRemap, easeInOutCubic, linear} from '../tweening';
@@ -12,7 +12,7 @@ import {ThreadGenerator} from '../threading';
* @param area - The area on which to zoom in.
* @param duration - The duration of the transition.
*/
-export function* zoomInTransition(area: Rect, duration = 0.6): ThreadGenerator {
+export function* zoomInTransition(area: BBox, duration = 0.6): ThreadGenerator {
const scale = useScene().getSize().div(area.size);
const currentPosition = Vector2.createSignal(area.position);
diff --git a/packages/core/src/transitions/zoomOutTransition.ts b/packages/core/src/transitions/zoomOutTransition.ts
index 450ee38b..b2c2d07d 100644
--- a/packages/core/src/transitions/zoomOutTransition.ts
+++ b/packages/core/src/transitions/zoomOutTransition.ts
@@ -1,4 +1,4 @@
-import {Rect, Vector2} from '../types';
+import {BBox, Vector2} from '../types';
import {useScene} from '../utils';
import {useTransition} from './useTransition';
import {clampRemap, easeInOutCubic, linear} from '../tweening';
@@ -13,7 +13,7 @@ import {ThreadGenerator} from '../threading';
* @param duration - The duration of the transition.
*/
export function* zoomOutTransition(
- area: Rect,
+ area: BBox,
duration = 0.6,
): ThreadGenerator {
const scale = useScene().getSize().div(area.size);
diff --git a/packages/core/src/types/Rect.test.ts b/packages/core/src/types/BBox.test.ts
similarity index 51%
rename from packages/core/src/types/Rect.test.ts
rename to packages/core/src/types/BBox.test.ts
index 5dfad595..cce88cb9 100644
--- a/packages/core/src/types/Rect.test.ts
+++ b/packages/core/src/types/BBox.test.ts
@@ -1,14 +1,14 @@
import {describe, expect, test} from 'vitest';
-import {Rect, Vector2} from '../types';
+import {BBox, Vector2} from '../types';
import {createSignal} from '../signals';
-describe('Rect', () => {
+describe('BBox', () => {
test('Correctly parses values', () => {
- const fromUndefined = new Rect();
- const fromProperties = new Rect(10, 20, 200, 100);
- const fromArray = new Rect([10, 20, 200, 100]);
- const fromVectors = new Rect(new Vector2(10, 20), new Vector2(200, 100));
- const fromObject = new Rect({x: 10, y: 20, width: 200, height: 100});
+ const fromUndefined = new BBox();
+ const fromProperties = new BBox(10, 20, 200, 100);
+ const fromArray = new BBox([10, 20, 200, 100]);
+ const fromVectors = new BBox(new Vector2(10, 20), new Vector2(200, 100));
+ const fromObject = new BBox({x: 10, y: 20, width: 200, height: 100});
expect(fromUndefined).toMatchObject({
x: 0,
@@ -42,11 +42,11 @@ describe('Rect', () => {
});
});
- test('Interpolates between rectangles', () => {
- const a = new Rect(10, 20, 200, 100);
- const b = new Rect(20, 40, 400, 200);
+ test('Interpolates between bounding boxes', () => {
+ const a = new BBox(10, 20, 200, 100);
+ const b = new BBox(20, 40, 400, 200);
- const result = Rect.lerp(a, b, 0.5);
+ const result = BBox.lerp(a, b, 0.5);
expect(result).toMatchObject({
x: 15,
@@ -58,16 +58,16 @@ describe('Rect', () => {
test('Creates a compound signal', () => {
const width = createSignal(200);
- const rect = Rect.createSignal(() => [10, 20, width(), 100]);
+ const box = BBox.createSignal(() => [10, 20, width(), 100]);
- expect(rect()).toMatchObject({x: 10, y: 20, width: 200, height: 100});
- expect(rect.x()).toBe(10);
- expect(rect.y()).toBe(20);
- expect(rect.width()).toBe(200);
- expect(rect.height()).toBe(100);
+ expect(box()).toMatchObject({x: 10, y: 20, width: 200, height: 100});
+ expect(box.x()).toBe(10);
+ expect(box.y()).toBe(20);
+ expect(box.width()).toBe(200);
+ expect(box.height()).toBe(100);
width(400);
- expect(rect()).toMatchObject({x: 10, y: 20, width: 400, height: 100});
- expect(rect.width()).toBe(400);
+ expect(box()).toMatchObject({x: 10, y: 20, width: 400, height: 100});
+ expect(box.width()).toBe(400);
});
});
diff --git a/packages/core/src/types/Rect.ts b/packages/core/src/types/BBox.ts
similarity index 79%
rename from packages/core/src/types/Rect.ts
rename to packages/core/src/types/BBox.ts
index a48c7df8..5db6f8fe 100644
--- a/packages/core/src/types/Rect.ts
+++ b/packages/core/src/types/BBox.ts
@@ -4,27 +4,27 @@ import {Type} from './Type';
import {Spacing} from './Spacing';
import {CompoundSignal, CompoundSignalContext, SignalValue} from '../signals';
-export type SerializedRect = {
+export type SerializedBBox = {
x: number;
y: number;
width: number;
height: number;
};
-export type PossibleRect =
- | SerializedRect
+export type PossibleBBox =
+ | SerializedBBox
| [number, number, number, number]
| Vector2
| undefined;
export type RectSignal<T> = CompoundSignal<
- PossibleRect,
- Rect,
+ PossibleBBox,
+ BBox,
'x' | 'y' | 'width' | 'height',
T
>;
-export class Rect implements Type {
+export class BBox implements Type {
public static readonly symbol = Symbol.for('@motion-canvas/core/types/Rect');
public x = 0;
@@ -33,22 +33,22 @@ export class Rect implements Type {
public height = 0;
public static createSignal(
- initial?: SignalValue<PossibleRect>,
- interpolation: InterpolationFunction<Rect> = Rect.lerp,
+ initial?: SignalValue<PossibleBBox>,
+ interpolation: InterpolationFunction<BBox> = BBox.lerp,
): RectSignal<void> {
return new CompoundSignalContext(
['x', 'y', 'width', 'height'],
- (value: PossibleRect) => new Rect(value),
+ (value: PossibleBBox) => new BBox(value),
initial,
interpolation,
).toSignal();
}
public static lerp(
- from: Rect,
- to: Rect,
- value: number | Vector2 | Rect,
- ): Rect {
+ from: BBox,
+ to: BBox,
+ value: number | Vector2 | BBox,
+ ): BBox {
let valueX;
let valueY;
let valueWidth;
@@ -65,7 +65,7 @@ export class Rect implements Type {
valueHeight = value.height;
}
- return new Rect(
+ return new BBox(
map(from.x, to.x, valueX),
map(from.y, to.y, valueY),
map(from.width, to.width, valueWidth),
@@ -74,8 +74,8 @@ export class Rect implements Type {
}
public static arcLerp(
- from: Rect,
- to: Rect,
+ from: BBox,
+ to: BBox,
value: number,
reverse = false,
ratio?: number,
@@ -83,14 +83,14 @@ export class Rect implements Type {
ratio ??=
(from.position.sub(to.position).ctg + from.size.sub(to.size).ctg) / 2;
- return Rect.lerp(from, to, arcLerp(value, reverse, ratio));
+ return BBox.lerp(from, to, arcLerp(value, reverse, ratio));
}
- public static fromSizeCentered(size: Vector2): Rect {
- return new Rect(-size.width / 2, -size.height / 2, size.width, size.height);
+ public static fromSizeCentered(size: Vector2): BBox {
+ return new BBox(-size.width / 2, -size.height / 2, size.width, size.height);
}
- public static fromPoints(...points: Vector2[]): Rect {
+ public static fromPoints(...points: Vector2[]): BBox {
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
@@ -111,37 +111,37 @@ export class Rect implements Type {
}
}
- return new Rect(minX, minY, maxX - minX, maxY - minY);
+ return new BBox(minX, minY, maxX - minX, maxY - minY);
}
- public static fromRects(...rects: Rect[]): Rect {
+ public static fromBBoxes(...boxes: BBox[]): BBox {
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
let maxY = -Infinity;
- for (const r of rects) {
- const right = r.x + r.width;
+ for (const box of boxes) {
+ const right = box.x + box.width;
if (right > maxX) {
maxX = right;
}
- if (r.x < minX) {
- minX = r.x;
+ if (box.x < minX) {
+ minX = box.x;
}
- const bottom = r.y + r.height;
+ const bottom = box.y + box.height;
if (bottom > maxY) {
maxY = bottom;
}
- if (r.y < minY) {
- minY = r.y;
+ if (box.y < minY) {
+ minY = box.y;
}
}
- return new Rect(minX, minY, maxX - minX, maxY - minY);
+ return new BBox(minX, minY, maxX - minX, maxY - minY);
}
- public lerp(to: Rect, value: number | Vector2 | Rect) {
- return Rect.lerp(this, to, value);
+ public lerp(to: BBox, value: number | Vector2 | BBox) {
+ return BBox.lerp(this, to, value);
}
public get position() {
@@ -216,7 +216,7 @@ export class Rect implements Type {
}
public get pixelPerfect() {
- return new Rect(
+ return new BBox(
Math.floor(this.x),
Math.floor(this.y),
Math.ceil(this.width + 1),
@@ -225,11 +225,11 @@ export class Rect implements Type {
}
public constructor();
- public constructor(from: PossibleRect);
+ public constructor(from: PossibleBBox);
public constructor(position: Vector2, size: Vector2);
public constructor(x: number, y?: number, width?: number, height?: number);
public constructor(
- one?: PossibleRect | number,
+ one?: PossibleBBox | number,
two: Vector2 | number = 0,
three = 0,
four = 0,
@@ -272,8 +272,8 @@ export class Rect implements Type {
this.height = one.height;
}
- public transform(matrix: DOMMatrix): Rect {
- return new Rect(
+ public transform(matrix: DOMMatrix): BBox {
+ return new BBox(
this.position.transformAsPoint(matrix),
this.size.transform(matrix),
);
@@ -284,7 +284,7 @@ export class Rect implements Type {
}
public expand(amount: number) {
- return new Rect(
+ return new BBox(
this.x - amount,
this.y - amount,
this.width + amount * 2,
@@ -293,7 +293,7 @@ export class Rect implements Type {
}
public addSpacing(spacing: Spacing) {
- const result = new Rect(this);
+ const result = new BBox(this);
result.left -= spacing.left;
result.top -= spacing.top;
result.right += spacing.right;
@@ -312,10 +312,10 @@ export class Rect implements Type {
}
public toSymbol(): symbol {
- return Rect.symbol;
+ return BBox.symbol;
}
- public serialize(): SerializedRect {
+ public serialize(): SerializedBBox {
return {x: this.x, y: this.y, width: this.width, height: this.height};
}
}
diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts
index 14df7058..0c51ed90 100644
--- a/packages/core/src/types/index.ts
+++ b/packages/core/src/types/index.ts
@@ -9,7 +9,7 @@ export * from './Color';
export * from './Matrix';
export * from './Matrix2D';
export * from './Origin';
-export * from './Rect';
+export * from './BBox';
export * from './Spacing';
export * from './Type';
export * from './Vector';
diff --git a/packages/core/src/utils/debug.test.ts b/packages/core/src/utils/debug.test.ts
index 673fea71..4b6a3847 100644
--- a/packages/core/src/utils/debug.test.ts
+++ b/packages/core/src/utils/debug.test.ts
@@ -1,6 +1,6 @@
import {describe, test, beforeEach, expect, vi} from 'vitest';
import {useLogger, debug, startScene} from '../utils';
-import {Rect, Vector2} from '../types';
+import {BBox, Vector2} from '../types';
import {Logger, LogLevel} from '../app';
import {Scene} from '../scenes';
@@ -17,11 +17,11 @@ describe('debug()', () => {
['NaN', NaN, {message: 'NaN'}],
['Vector2', Vector2.one, {message: '{"x":1,"y":1}', object: Vector2.one}],
[
- 'Rect',
- new Rect([10, 20, 30, 40]),
+ 'BBox',
+ new BBox([10, 20, 30, 40]),
{
message: '{"x":10,"y":20,"width":30,"height":40}',
- object: new Rect([10, 20, 30, 40]),
+ object: new BBox([10, 20, 30, 40]),
},
],
[
diff --git a/packages/docs/docs/advanced/custom-font.mdx b/packages/docs/docs/advanced/custom-font.mdx
index aa4cb934..c4f9dcf4 100644
--- a/packages/docs/docs/advanced/custom-font.mdx
+++ b/packages/docs/docs/advanced/custom-font.mdx
@@ -43,7 +43,7 @@ export default makeProject({
Now you can reference the fonts in the `fontFamily` property in this project.
```tsx
-<Text fontFamily={'Fira Code'}>Fira Code</Text>
+<Txt fontFamily={'Fira Code'}>Fira Code</Txt>
```
## Loading fonts from local
@@ -74,7 +74,7 @@ from the css.
```tsx
<Layout direction={'column'} alignItems={'center'} layout>
- <Text fontFamily={'Fira Code'}>Fira Code</Text>
- <Text fontFamily={'Cascadia Code'}>Cascadia Code</Text>
+ <Txt fontFamily={'Fira Code'}>Fira Code</Txt>
+ <Txt fontFamily={'Cascadia Code'}>Cascadia Code</Txt>
</Layout>
```
diff --git a/packages/docs/docs/getting-started/hierarchy.mdx b/packages/docs/docs/getting-started/hierarchy.mdx
index 19c7bab1..440c878b 100644
--- a/packages/docs/docs/getting-started/hierarchy.mdx
+++ b/packages/docs/docs/getting-started/hierarchy.mdx
@@ -25,7 +25,7 @@ view.add(
<Circle />
<Layout>
<Rect />
- <Text>Hi</Text>
+ <Txt>Hi</Txt>
</Layout>
</>,
);
@@ -68,7 +68,7 @@ view.add(
<Circle />
<Layout>
<Rect />
- <Text>Hi</Text>
+ <Txt>Hi</Txt>
</Layout>
</>,
);
diff --git a/packages/docs/docs/getting-started/layouts.mdx b/packages/docs/docs/getting-started/layouts.mdx
index 8d7e6dff..646b5c4b 100644
--- a/packages/docs/docs/getting-started/layouts.mdx
+++ b/packages/docs/docs/getting-started/layouts.mdx
@@ -14,7 +14,7 @@ Layouts allow you to arrange your nodes using [Flexbox][flexbox]. Any node
extending the [`Layout`](/api/2d/components/Layout) node can become a part of
the layout. This includes, but is not limited to:
[`Rect`](/api/2d/components/Rect), [`Circle`](/api/2d/components/Circle), and
-[`Image`](/api/2d/components/Image).
+[`Img`](/api/2d/components/Img).
## Layout root
diff --git a/packages/docs/docs/getting-started/media.mdx b/packages/docs/docs/getting-started/media.mdx
index 7d77345c..e7c3103a 100644
--- a/packages/docs/docs/getting-started/media.mdx
+++ b/packages/docs/docs/getting-started/media.mdx
@@ -75,23 +75,23 @@ animation, we need to import the image:
import examplePng from '../../images/example.png';
```
-Then we can use Motion Canvas [`Image`](/api/2d/components/Image) component to
+Then we can use Motion Canvas [`Img`](/api/2d/components/Img) component to
display the image:
```tsx
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
-import {Image} from '@motion-canvas/2d/lib/components';
+import {Img} from '@motion-canvas/2d/lib/components';
import examplePng from '../../images/example.png';
export default makeScene2D(function* (view) {
- view.add(<Image src={examplePng} />);
+ view.add(<Img src={examplePng} />);
});
```
Images can also be animated like every other component in Motion Canvas. For
this, we need to create a [`Reference`](/docs/references) and pass that to the
-[`Image`](/api/2d/components/Image):
+[`Img`](/api/2d/components/Img):
```tsx
// ...
@@ -99,9 +99,9 @@ import {createRef} from '@motion-canvas/core/lib/utils';
import {all} from '@motion-canvas/core/lib/flow';
export default makeScene2D(function* (view) {
- const imageRef = createRef<Image>();
+ const imageRef = createRef<Img>();
- view.add(<Image ref={imageRef} src={examplePng} scale={2} />);
+ view.add(<Img ref={imageRef} src={examplePng} scale={2} />);
yield* all(
imageRef().scale(2.5, 1.5).to(2, 1.5),
diff --git a/packages/docs/docs/getting-started/references.mdx b/packages/docs/docs/getting-started/references.mdx
index edaf26c2..79b99f37 100644
--- a/packages/docs/docs/getting-started/references.mdx
+++ b/packages/docs/docs/getting-started/references.mdx
@@ -185,14 +185,14 @@ function Label({
refs,
children,
}: {
- refs: {rect: Rect; text: Text};
+ refs: {rect: Rect; text: Txt};
children: string;
}) {
return (
// highlight-next-line
<Rect ref={makeRef(refs, 'rect')}>
// highlight-next-line
- <Text ref={makeRef(refs, 'text')}>{children}</Text>
+ <Txt ref={makeRef(refs, 'text')}>{children}</Txt>
</Rect>
);
}
@@ -222,12 +222,12 @@ function Label({
children,
}: {
// highlight-next-line
- refs: {rect: Rect; text: Text};
+ refs: {rect: Rect; text: Txt};
children: string;
}) {
return (
<Rect ref={makeRef(refs, 'rect')}>
- <Text ref={makeRef(refs, 'text')}>{children}</Text>
+ <Txt ref={makeRef(refs, 'text')}>{children}</Txt>
</Rect>
);
}
@@ -251,12 +251,12 @@ function Label({
children,
}: {
// highlight-next-line
- refs: {rect: Rect; text: Text};
+ refs: {rect: Rect; text: Txt};
children: string;
}) {
return (
<Rect ref={makeRef(refs, 'rect')}>
- <Text ref={makeRef(refs, 'text')}>{children}</Text>
+ <Txt ref={makeRef(refs, 'text')}>{children}</Txt>
</Rect>
);
}
diff --git a/packages/docs/docs/getting-started/signals.mdx b/packages/docs/docs/getting-started/signals.mdx
index 86f4e449..3637dd67 100644
--- a/packages/docs/docs/getting-started/signals.mdx
+++ b/packages/docs/docs/getting-started/signals.mdx
@@ -142,15 +142,15 @@ yield * signal(DEFAULT, 2);
Resetting to the default value is especially useful with node properties. In the
example below, we set the [`lineHeight`](/api/2d/components/Layout#lineHeight)
-of the [`Text`](/api/2d/components/Text) node to `150%`. This will override its
+of the [`Txt`](/api/2d/components/Txt) node to `150%`. This will override its
default value, which would be simply inherited from its parent:
```tsx
-const text = createRef<Text>();
+const text = createRef<Txt>();
view.add(
- <Text lineHeight={'150%'} ref={text}>
+ <Txt lineHeight={'150%'} ref={text}>
Hello world!
- </Text>,
+ </Txt>,
);
```
diff --git a/packages/examples/src/scenes/media-image.tsx b/packages/examples/src/scenes/media-image.tsx
index 14b42698..1606d2d5 100644
--- a/packages/examples/src/scenes/media-image.tsx
+++ b/packages/examples/src/scenes/media-image.tsx
@@ -1,14 +1,14 @@
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
-import {Image} from '@motion-canvas/2d/lib/components';
+import {Img} from '@motion-canvas/2d/lib/components';
import {createRef} from '@motion-canvas/core/lib/utils';
import {all} from '@motion-canvas/core/lib/flow';
import logoSvg from '@motion-canvas/examples/assets/logo.svg';
export default makeScene2D(function* (view) {
- const imageRef = createRef<Image>();
+ const imageRef = createRef<Img>();
- yield view.add(<Image ref={imageRef} src={logoSvg} scale={2} />);
+ yield view.add(<Img ref={imageRef} src={logoSvg} scale={2} />);
yield* all(
imageRef().scale(2.5, 1.5).to(2, 1.5),
diff --git a/packages/examples/src/scenes/node-signal.tsx b/packages/examples/src/scenes/node-signal.tsx
index 4ebb1f47..d93e3539 100644
--- a/packages/examples/src/scenes/node-signal.tsx
+++ b/packages/examples/src/scenes/node-signal.tsx
@@ -1,5 +1,5 @@
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
-import {Circle, Text, Line} from '@motion-canvas/2d/lib/components';
+import {Circle, Txt, Line} from '@motion-canvas/2d/lib/components';
import {createSignal} from '@motion-canvas/core/lib/signals';
import {Vector2} from '@motion-canvas/core/lib/types';
import {waitFor} from '@motion-canvas/core/lib/flow';
@@ -41,7 +41,7 @@ export default makeScene2D(function* (view) {
lineWidth={8}
stroke={'#242424'}
/>
- <Text
+ <Txt
// highlight-start
text={() => `r = ${radius().toFixed(2)}`}
x={() => (radius() * scale) / 2}
@@ -49,7 +49,7 @@ export default makeScene2D(function* (view) {
fill={'#242424'}
{...textStyle}
/>
- <Text
+ <Txt
// highlight-start
text={() => `A = ${area().toFixed(2)}`}
y={() => radius() * scale}
diff --git a/packages/examples/src/scenes/transitions-first.tsx b/packages/examples/src/scenes/transitions-first.tsx
index 49569fc3..0493585f 100644
--- a/packages/examples/src/scenes/transitions-first.tsx
+++ b/packages/examples/src/scenes/transitions-first.tsx
@@ -1,4 +1,4 @@
-import {Rect, Text} from '@motion-canvas/2d/lib/components';
+import {Rect, Txt} from '@motion-canvas/2d/lib/components';
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
import {waitFor} from '@motion-canvas/core/lib/flow';
@@ -12,14 +12,14 @@ export default makeScene2D(function* (view) {
alignItems={'center'}
justifyContent={'center'}
>
- <Text
+ <Txt
fontSize={160}
fontWeight={700}
fill={'#fff'}
fontFamily={'"JetBrains Mono", monospace'}
>
FIRST SCENE
- </Text>
+ </Txt>
</Rect>,
);
diff --git a/packages/examples/src/scenes/transitions-second.tsx b/packages/examples/src/scenes/transitions-second.tsx
index 6150b2f4..c7caf766 100644
--- a/packages/examples/src/scenes/transitions-second.tsx
+++ b/packages/examples/src/scenes/transitions-second.tsx
@@ -1,4 +1,4 @@
-import {Rect, Text} from '@motion-canvas/2d/lib/components';
+import {Rect, Txt} from '@motion-canvas/2d/lib/components';
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
import {all, waitFor} from '@motion-canvas/core/lib/flow';
import {slideTransition} from '@motion-canvas/core/lib/transitions';
@@ -7,7 +7,7 @@ import {Direction} from '@motion-canvas/core/lib/types';
export default makeScene2D(function* (view) {
const rect = createRef<Rect>();
- const text = createRef<Text>();
+ const text = createRef<Txt>();
view.add(
<Rect
@@ -19,7 +19,7 @@ export default makeScene2D(function* (view) {
alignItems={'center'}
justifyContent={'center'}
>
- <Text
+ <Txt
ref={text}
fontSize={160}
fontWeight={700}
@@ -27,7 +27,7 @@ export default makeScene2D(function* (view) {
fontFamily={'"JetBrains Mono", monospace'}
>
SECOND SCENE
- </Text>
+ </Txt>
</Rect>,
);
diff --git a/packages/examples/src/scenes/tweening-visualiser.tsx b/packages/examples/src/scenes/tweening-visualiser.tsx
index ea3a46d9..4cc84e69 100644
--- a/packages/examples/src/scenes/tweening-visualiser.tsx
+++ b/packages/examples/src/scenes/tweening-visualiser.tsx
@@ -5,7 +5,7 @@ import {
Line,
Node,
Layout,
- Text,
+ Txt,
} from '@motion-canvas/2d/lib/components';
import {makeScene2D} from '@motion-canvas/2d/lib/scenes';
import {all, waitFor} from '@motion-canvas/core/lib/flow';
@@ -52,19 +52,19 @@ export default makeScene2D(function* (view) {
{/* Tracker */}
<Layout y={() => value() * -500 + 650}>
- <Text
+ <Txt
fill={'#DDD'}
text={() => value().toFixed(2).toString()}
fontWeight={300}
fontSize={30}
x={-55}
y={3}
- ></Text>
+ ></Txt>
<Circle size={30} fill={'#DDD'}></Circle>
</Layout>
{/* Label */}
- <Text
+ <Txt
y={400}
x={-160}
fontWeight={400}
@@ -73,7 +73,7 @@ export default makeScene2D(function* (view) {
fontFamily={'Candara'}
fill={'#DDD'}
text={'VALUE'}
- ></Text>
+ ></Txt>
</Node>
{/* Horizontal */}
@@ -94,17 +94,17 @@ export default makeScene2D(function* (view) {
{/* Tracker */}
<Layout y={800} x={() => time() * 500 + 150}>
<Circle size={30} fill={'#DDD'}></Circle>
- <Text
+ <Txt
fill={'#DDD'}
text={() => (time() * TIME).toFixed(2).toString()}
fontWeight={300}
fontSize={30}
y={50}
- ></Text>
+ ></Txt>
</Layout>
{/* Label */}
- <Text
+ <Txt
y={900}
x={400}
fontWeight={400}
@@ -113,7 +113,7 @@ export default makeScene2D(function* (view) {
fontFamily={'Candara'}
fill={'#DDD'}
text={'TIME'}
- ></Text>
+ ></Txt>
</Node>
</Node>,
);