Skip to content

Visualize Your Ideas With Code

feat(ui): scene graph icons (#914)

Jacobe92ddef34860
diff --git a/packages/2d/src/editor/icons/CircleIcon.tsx b/packages/2d/src/editor/icons/CircleIcon.tsx
new file mode 100644
index 00000000..c1ab544a
--- /dev/null
+++ b/packages/2d/src/editor/icons/CircleIcon.tsx
@@ -0,0 +1,7 @@
+export function CircleIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M10,5C12.76,5 15,7.24 15,10C15,12.76 12.76,15 10,15C7.24,15 5,12.76 5,10C5,7.24 7.24,5 10,5ZM10,7C8.344,7 7,8.344 7,10C7,11.656 8.344,13 10,13C11.656,13 13,11.656 13,10C13,8.344 11.656,7 10,7Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/CodeBlockIcon.tsx b/packages/2d/src/editor/icons/CodeBlockIcon.tsx
new file mode 100644
index 00000000..1748c5c5
--- /dev/null
+++ b/packages/2d/src/editor/icons/CodeBlockIcon.tsx
@@ -0,0 +1,8 @@
+export function CodeBlockIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M5,9L5,6.999C5,6.469 5.211,5.96 5.585,5.586C5.96,5.211 6.469,5 6.999,5L9,5L9,7L6.999,7L7,9L7,11L7,13L8.985,13L9,15L7,15C5.895,15 5,14.105 5,13L5,11L4,11L4,9L5,9Z" />
+ <path d="M15,11L15,13.001C15,13.531 14.789,14.04 14.415,14.414C14.04,14.789 13.531,15 13.001,15L11,15L11,13L13,13L13,11L13,9L13,7L11.015,7L11,5L13,5C14.105,5 15,5.895 15,7L15,9L16,9L16,11L15,11Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/CurveIcon.tsx b/packages/2d/src/editor/icons/CurveIcon.tsx
new file mode 100644
index 00000000..fd8916ec
--- /dev/null
+++ b/packages/2d/src/editor/icons/CurveIcon.tsx
@@ -0,0 +1,7 @@
+export function CurveIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M12.19,6.47L13.595,5.047C15.519,6.947 15.187,8.932 14.229,9.951C13.675,10.541 12.879,10.861 12.016,10.767C11.261,10.685 10.426,10.278 9.708,9.348C9.292,8.809 8.878,8.441 8.471,8.249C8.217,8.13 7.979,8.084 7.77,8.154C7.565,8.222 7.409,8.394 7.287,8.621C7.097,8.975 7.001,9.444 7,10.003C6.996,11.584 7.848,12.746 8.91,12.946C9.535,13.064 10.185,12.783 10.687,12.082L12.313,13.247C11,15.079 9.118,15.344 7.581,14.591C6.161,13.896 4.994,12.246 5,9.997C5.005,7.945 5.963,6.649 7.136,6.257C8.281,5.874 9.866,6.278 11.292,8.126C11.81,8.799 12.421,8.954 12.772,8.581C13.196,8.13 13.042,7.312 12.19,6.47Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/GridIcon.tsx b/packages/2d/src/editor/icons/GridIcon.tsx
new file mode 100644
index 00000000..bbacf5db
--- /dev/null
+++ b/packages/2d/src/editor/icons/GridIcon.tsx
@@ -0,0 +1,7 @@
+export function GridIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M6,8L4,8L4,6L6,6L6,4L8,4L8,6L12,6L12,4L14,4L14,6L16,6L16,8L14,8L14,12L16,12L16,14L14,14L14,16L12,16L12,14L8,14L8,16L6,16L6,14L4,14L4,12L6,12L6,8ZM8,12L12,12L12,8L8,8L8,12Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/IconMap.ts b/packages/2d/src/editor/icons/IconMap.ts
new file mode 100644
index 00000000..400fd707
--- /dev/null
+++ b/packages/2d/src/editor/icons/IconMap.ts
@@ -0,0 +1,35 @@
+/* eslint-disable @typescript-eslint/naming-convention */
+
+import {FunctionComponent} from 'preact';
+import {CircleIcon} from './CircleIcon';
+import {CodeBlockIcon} from './CodeBlockIcon';
+import {CurveIcon} from './CurveIcon';
+import {GridIcon} from './GridIcon';
+import {ImgIcon} from './ImgIcon';
+import {LayoutIcon} from './LayoutIcon';
+import {LineIcon} from './LineIcon';
+import {NodeIcon} from './NodeIcon';
+import {RayIcon} from './RayIcon';
+import {RectIcon} from './RectIcon';
+import {ShapeIcon} from './ShapeIcon';
+import {TxtIcon} from './TxtIcon';
+import {VideoIcon} from './VideoIcon';
+import {View2DIcon} from './View2DIcon';
+
+export const IconMap: Record<string, FunctionComponent> = {
+ Circle: CircleIcon,
+ CodeBlock: CodeBlockIcon,
+ Curve: CurveIcon,
+ Grid: GridIcon,
+ Img: ImgIcon,
+ Layout: LayoutIcon,
+ Line: LineIcon,
+ Node: NodeIcon,
+ Ray: RayIcon,
+ Rect: RectIcon,
+ Shape: ShapeIcon,
+ Txt: TxtIcon,
+ TxtLeaf: TxtIcon,
+ Video: VideoIcon,
+ View2D: View2DIcon,
+};
diff --git a/packages/2d/src/editor/icons/ImgIcon.tsx b/packages/2d/src/editor/icons/ImgIcon.tsx
new file mode 100644
index 00000000..6c75b9d7
--- /dev/null
+++ b/packages/2d/src/editor/icons/ImgIcon.tsx
@@ -0,0 +1,8 @@
+export function ImgIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M5,15L15,15L15,10L13,8L8,13L5,10L5,15Z" />
+ <circle cx="8" cy="7" r="2" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/LayoutIcon.tsx b/packages/2d/src/editor/icons/LayoutIcon.tsx
new file mode 100644
index 00000000..79504671
--- /dev/null
+++ b/packages/2d/src/editor/icons/LayoutIcon.tsx
@@ -0,0 +1,9 @@
+export function LayoutIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M14,5C14.552,5 15,5.448 15,6C15,7.916 15,12.084 15,14C15,14.552 14.552,15 14,15C12.815,15 11,15 11,15L11,5L14,5Z" />
+ <path d="M9,5L9,9L5,9L5,6C5,5.448 5.448,5 6,5L9,5Z" />
+ <path d="M9,11L9,15L6,15C5.448,15 5,14.552 5,14L5,11L9,11Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/LineIcon.tsx b/packages/2d/src/editor/icons/LineIcon.tsx
new file mode 100644
index 00000000..fe3f94f0
--- /dev/null
+++ b/packages/2d/src/editor/icons/LineIcon.tsx
@@ -0,0 +1,7 @@
+export function LineIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M9.906,4.589L11.411,5.906L8.529,9.2L13.859,8.439C14.273,8.379 14.68,8.584 14.879,8.952C15.078,9.319 15.028,9.772 14.753,10.087L10.094,15.411L8.589,14.094L11.471,10.8L6.141,11.561C5.727,11.621 5.32,11.416 5.121,11.048C4.922,10.681 4.972,10.228 5.247,9.913L9.906,4.589Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/NodeIcon.tsx b/packages/2d/src/editor/icons/NodeIcon.tsx
new file mode 100644
index 00000000..7d71b0c9
--- /dev/null
+++ b/packages/2d/src/editor/icons/NodeIcon.tsx
@@ -0,0 +1,7 @@
+export function NodeIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M7,9L5,9L5,7L7,7L7,5L9,5L9,7L12,7L12,5L15,8L12,11L12,9L9,9L9,12L11,12L8,15L5,12L7,12L7,9Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/RayIcon.tsx b/packages/2d/src/editor/icons/RayIcon.tsx
new file mode 100644
index 00000000..3075cc6f
--- /dev/null
+++ b/packages/2d/src/editor/icons/RayIcon.tsx
@@ -0,0 +1,7 @@
+export function RayIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M12,9.414L6.707,14.707L5.293,13.293L10.586,8L8,8L8,6L13,6C13.552,6 14,6.448 14,7L14,12L12,12L12,9.414Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/RectIcon.tsx b/packages/2d/src/editor/icons/RectIcon.tsx
new file mode 100644
index 00000000..2a601eb4
--- /dev/null
+++ b/packages/2d/src/editor/icons/RectIcon.tsx
@@ -0,0 +1,7 @@
+export function RectIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M15,6L15,14C15,14.552 14.552,15 14,15L6,15C5.448,15 5,14.552 5,14L5,6C5,5.448 5.448,5 6,5L14,5C14.552,5 15,5.448 15,6ZM13,7L7,7L7,13L13,13L13,7Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/ShapeIcon.tsx b/packages/2d/src/editor/icons/ShapeIcon.tsx
new file mode 100644
index 00000000..f89435cb
--- /dev/null
+++ b/packages/2d/src/editor/icons/ShapeIcon.tsx
@@ -0,0 +1,7 @@
+export function ShapeIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M11.746,10.93C12.637,12.664 11.973,14.504 10.611,15.244C9.692,15.743 8.385,15.804 6.94,14.829C5.555,13.893 4.689,12.16 4.544,10.388C4.395,8.572 5,6.752 6.399,5.701C8.069,4.445 10.793,4.271 12.765,4.921C14.324,5.436 15.374,6.473 15.495,7.691C15.651,9.262 14.613,10.061 13.26,10.5C12.847,10.634 12.41,10.735 12.02,10.841C11.936,10.864 11.838,10.897 11.746,10.93ZM7.601,7.299C6.737,7.949 6.445,9.103 6.537,10.224C6.633,11.389 7.149,12.556 8.06,13.171C8.696,13.601 9.251,13.706 9.656,13.486C10.207,13.187 10.315,12.395 9.886,11.701C9.48,11.044 9.513,10.523 9.68,10.122C9.835,9.75 10.164,9.417 10.678,9.187C11.243,8.935 12.157,8.8 12.908,8.503C13.216,8.381 13.542,8.264 13.505,7.888C13.485,7.691 13.359,7.53 13.197,7.384C12.928,7.143 12.558,6.959 12.138,6.821C10.736,6.358 8.789,6.406 7.601,7.299Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/TxtIcon.tsx b/packages/2d/src/editor/icons/TxtIcon.tsx
new file mode 100644
index 00000000..f1985536
--- /dev/null
+++ b/packages/2d/src/editor/icons/TxtIcon.tsx
@@ -0,0 +1,8 @@
+export function TxtIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M9,13L9,6L11,6L11,13L12,13L12,15L8,15L8,13L9,13Z" />
+ <path d="M7,8L5,8L5,6C5,5.448 5.448,5 6,5L14,5C14.552,5 15,5.448 15,6L15,8L13,8L13,7L7,7L7,8Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/VideoIcon.tsx b/packages/2d/src/editor/icons/VideoIcon.tsx
new file mode 100644
index 00000000..16a9ed6f
--- /dev/null
+++ b/packages/2d/src/editor/icons/VideoIcon.tsx
@@ -0,0 +1,7 @@
+export function VideoIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M14,10.866L7.25,14.763C6.941,14.942 6.559,14.942 6.25,14.763C5.941,14.585 5.75,14.254 5.75,13.897L5.75,6.103C5.75,5.746 5.941,5.415 6.25,5.237C6.559,5.058 6.941,5.058 7.25,5.237L14,9.134C14.309,9.313 14.5,9.643 14.5,10C14.5,10.357 14.309,10.687 14,10.866ZM11.5,10L7.75,7.835L7.75,12.165L11.5,10Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/icons/View2DIcon.tsx b/packages/2d/src/editor/icons/View2DIcon.tsx
new file mode 100644
index 00000000..1c52e169
--- /dev/null
+++ b/packages/2d/src/editor/icons/View2DIcon.tsx
@@ -0,0 +1,10 @@
+export function View2DIcon() {
+ return (
+ <svg viewBox="0 0 20 20" fill="currentColor">
+ <path d="M9,5L9,7L7,7L7,9L5,9L5,6C5,5.448 5.448,5 6,5L9,5Z" />
+ <path d="M5,11L7,11L7,13L9,13L9,15L6,15C5.448,15 5,14.552 5,14L5,11Z" />
+ <path d="M11,15L11,13L13,13L13,11L15,11L15,14C15,14.552 14.552,15 14,15L11,15Z" />
+ <path d="M15,9L13,9L13,7L11,7L11,5L14,5C14.552,5 15,5.448 15,6L15,9Z" />
+ </svg>
+ );
+}
diff --git a/packages/2d/src/editor/tree/NodeElement.tsx b/packages/2d/src/editor/tree/NodeElement.tsx
index 4eb49364..98293293 100644
--- a/packages/2d/src/editor/tree/NodeElement.tsx
+++ b/packages/2d/src/editor/tree/NodeElement.tsx
@@ -1,7 +1,8 @@
-import {Node} from '@motion-canvas/2d';
+import {NODE_NAME, Node} from '@motion-canvas/2d';
import {useComputed, useSignal, useSignalEffect} from '@preact/signals';
import {useRef} from 'preact/hooks';
import {usePluginState} from '../Provider';
+import {IconMap} from '../icons/IconMap';
import {TreeElement} from './TreeElement';
interface NodeElementProps {
@@ -46,11 +47,14 @@ export function NodeElement({node, depth = 0}: NodeElementProps) {
}
});
+ const Icon = IconMap[node[NODE_NAME]] ?? IconMap.Node;
+
return (
<TreeElement
forwardRef={ref}
open={open}
depth={depth}
+ icon={<Icon />}
label={node.key}
selected={selectedKey.value === node.key}
onClick={event => {
diff --git a/packages/2d/src/editor/tree/TreeElement.tsx b/packages/2d/src/editor/tree/TreeElement.tsx
index b61bacc4..80fd29bb 100644
--- a/packages/2d/src/editor/tree/TreeElement.tsx
+++ b/packages/2d/src/editor/tree/TreeElement.tsx
@@ -1,6 +1,6 @@
import {Collapse, Toggle} from '@motion-canvas/ui';
import {Signal} from '@preact/signals';
-import clsx from 'clsx';
+import {clsx} from 'clsx';
import {ComponentChildren, JSX} from 'preact';
import {Ref} from 'preact/hooks';
import styles from './index.module.scss';
@@ -8,7 +8,8 @@ import styles from './index.module.scss';
const DEPTH_VAR = '--depth';
interface TreeElementProps
- extends Omit<JSX.HTMLAttributes<HTMLDivElement>, 'label'> {
+ extends Omit<JSX.HTMLAttributes<HTMLDivElement>, 'label' | 'icon'> {
+ icon?: ComponentChildren;
label: ComponentChildren;
children?: ComponentChildren;
selected?: boolean;
@@ -23,6 +24,7 @@ export function TreeElement({
selected,
depth = 0,
open,
+ icon,
forwardRef,
...props
}: TreeElementProps) {
@@ -57,7 +59,7 @@ export function TreeElement({
}}
/>
)}
- <div className={styles.icon} />
+ {icon}
{label}
</div>
{hasChildren && (
diff --git a/packages/2d/src/editor/tree/TreeRoot.tsx b/packages/2d/src/editor/tree/TreeRoot.tsx
index 0892a286..ef01bf6e 100644
--- a/packages/2d/src/editor/tree/TreeRoot.tsx
+++ b/packages/2d/src/editor/tree/TreeRoot.tsx
@@ -1,4 +1,4 @@
-import clsx from 'clsx';
+import {clsx} from 'clsx';
import {JSX} from 'preact';
import styles from './index.module.scss';
diff --git a/packages/2d/src/editor/tree/index.module.scss b/packages/2d/src/editor/tree/index.module.scss
index d8b323ca..a41cea56 100644
--- a/packages/2d/src/editor/tree/index.module.scss
+++ b/packages/2d/src/editor/tree/index.module.scss
@@ -4,15 +4,6 @@
border-top: 2px solid var(--background-color);
}
-.icon {
- width: 20px;
- height: 20px;
- align-self: center;
- background-color: var(--background-color);
- border-radius: var(--radius);
- margin-right: 8px;
-}
-
.label {
--depth: 0;
@@ -35,4 +26,13 @@
&.parent {
padding-left: calc(var(--depth) * 22px);
}
+
+ > svg {
+ width: 20px;
+ height: 20px;
+ align-self: center;
+ background-color: var(--background-color);
+ border-radius: var(--radius);
+ margin-right: 8px;
+ }
}
diff --git a/packages/2d/src/lib/components/Circle.ts b/packages/2d/src/lib/components/Circle.ts
index 9abe66d4..036037db 100644
--- a/packages/2d/src/lib/components/Circle.ts
+++ b/packages/2d/src/lib/components/Circle.ts
@@ -6,7 +6,7 @@ import {
SimpleSignal,
} from '@motion-canvas/core';
import {CurveProfile, getCircleProfile} from '../curves';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {DesiredLength} from '../partials';
import {Curve, CurveProps} from './Curve';
@@ -126,6 +126,7 @@ export interface CircleProps extends CurveProps {
* });
* ```
*/
+@nodeName('Circle')
export class Circle extends Curve {
/**
* The starting angle in degrees for the circle sector.
diff --git a/packages/2d/src/lib/components/CodeBlock.ts b/packages/2d/src/lib/components/CodeBlock.ts
index 55a3ad1d..11e6af4b 100644
--- a/packages/2d/src/lib/components/CodeBlock.ts
+++ b/packages/2d/src/lib/components/CodeBlock.ts
@@ -27,7 +27,7 @@ import {
parse,
ready,
} from 'code-fns';
-import {computed, initial, parser, signal} from '../decorators';
+import {computed, initial, nodeName, parser, signal} from '../decorators';
import {DesiredLength} from '../partials';
import {Shape, ShapeProps} from './Shape';
@@ -47,6 +47,7 @@ export interface CodeModification {
to: Code;
}
+@nodeName('CodeBlock')
export class CodeBlock extends Shape {
private static initialized = createComputedAsync(
() => ready().then(() => true),
diff --git a/packages/2d/src/lib/components/Curve.ts b/packages/2d/src/lib/components/Curve.ts
index 6972e836..a134f306 100644
--- a/packages/2d/src/lib/components/Curve.ts
+++ b/packages/2d/src/lib/components/Curve.ts
@@ -10,7 +10,7 @@ import {CurveDrawingInfo} from '../curves/CurveDrawingInfo';
import {CurvePoint} from '../curves/CurvePoint';
import {CurveProfile} from '../curves/CurveProfile';
import {getPointAtDistance} from '../curves/getPointAtDistance';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {DesiredLength} from '../partials';
import {lineTo, moveTo, resolveCanvasStyle} from '../utils';
import {Shape, ShapeProps} from './Shape';
@@ -50,6 +50,7 @@ export interface CurveProps extends ShapeProps {
arrowSize?: SignalValue<number>;
}
+@nodeName('Curve')
export abstract class Curve extends Shape {
/**
* Whether the curve should be closed.
diff --git a/packages/2d/src/lib/components/Grid.ts b/packages/2d/src/lib/components/Grid.ts
index 580bdf32..bcc8c7db 100644
--- a/packages/2d/src/lib/components/Grid.ts
+++ b/packages/2d/src/lib/components/Grid.ts
@@ -5,7 +5,7 @@ import {
Vector2Signal,
map,
} from '@motion-canvas/core';
-import {initial, signal, vector2Signal} from '../decorators';
+import {initial, nodeName, signal, vector2Signal} from '../decorators';
import {Shape, ShapeProps} from './Shape';
export interface GridProps extends ShapeProps {
@@ -52,6 +52,7 @@ export interface GridProps extends ShapeProps {
* });
* ```
*/
+@nodeName('Grid')
export class Grid extends Shape {
/**
* The spacing between the grid lines.
diff --git a/packages/2d/src/lib/components/Img.ts b/packages/2d/src/lib/components/Img.ts
index f4c530a1..01e5e16f 100644
--- a/packages/2d/src/lib/components/Img.ts
+++ b/packages/2d/src/lib/components/Img.ts
@@ -11,7 +11,7 @@ import {
useLogger,
viaProxy,
} from '@motion-canvas/core';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {DesiredLength} from '../partials';
import {drawImage} from '../utils';
import {Rect, RectProps} from './Rect';
@@ -65,6 +65,7 @@ export interface ImgProps extends RectProps {
* });
* ```
*/
+@nodeName('Img')
export class Img extends Rect {
private static pool: Record<string, HTMLImageElement> = {};
diff --git a/packages/2d/src/lib/components/Layout.ts b/packages/2d/src/lib/components/Layout.ts
index fe114cfe..7677f4c8 100644
--- a/packages/2d/src/lib/components/Layout.ts
+++ b/packages/2d/src/lib/components/Layout.ts
@@ -28,6 +28,7 @@ import {
getPropertyMeta,
initial,
interpolation,
+ nodeName,
signal,
Vector2LengthSignal,
vector2Signal,
@@ -186,6 +187,7 @@ export interface LayoutProps extends NodeProps {
clip?: SignalValue<boolean>;
}
+@nodeName('Layout')
export class Layout extends Node {
@initial(null)
@interpolation(boolLerp)
diff --git a/packages/2d/src/lib/components/Line.ts b/packages/2d/src/lib/components/Line.ts
index c4e1f4fb..e2e3787a 100644
--- a/packages/2d/src/lib/components/Line.ts
+++ b/packages/2d/src/lib/components/Line.ts
@@ -18,7 +18,7 @@ import {
polygonLength,
polygonPointsLerp,
} from '../curves/createCurveProfileLerp';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {arc, drawLine, drawPivot, lineTo, moveTo} from '../utils';
import lineWithoutPoints from './__logs__/line-without-points.md';
import {Curve, CurveProps} from './Curve';
@@ -140,6 +140,7 @@ export interface LineProps extends CurveProps {
* });
* ```
*/
+@nodeName('Line')
export class Line extends Curve {
/**
* Rotate the points to minimize the overall distance traveled when tweening.
diff --git a/packages/2d/src/lib/components/Node.ts b/packages/2d/src/lib/components/Node.ts
index 436abae1..d37841c5 100644
--- a/packages/2d/src/lib/components/Node.ts
+++ b/packages/2d/src/lib/components/Node.ts
@@ -27,6 +27,7 @@ import {
useLogger,
} from '@motion-canvas/core';
import {
+ NODE_NAME,
cloneable,
colorSignal,
computed,
@@ -34,6 +35,7 @@ import {
initial,
initializeSignals,
inspectable,
+ nodeName,
parser,
signal,
vector2Signal,
@@ -81,7 +83,12 @@ export interface NodeProps {
compositeOperation?: SignalValue<GlobalCompositeOperation>;
}
+@nodeName('Node')
export class Node implements Promisable<Node> {
+ /**
+ * @internal
+ */
+ public declare readonly [NODE_NAME]: string;
public declare isClass: boolean;
/**
diff --git a/packages/2d/src/lib/components/Ray.ts b/packages/2d/src/lib/components/Ray.ts
index 1c9e0f23..47085060 100644
--- a/packages/2d/src/lib/components/Ray.ts
+++ b/packages/2d/src/lib/components/Ray.ts
@@ -5,7 +5,7 @@ import {
Vector2Signal,
} from '@motion-canvas/core';
import {CurveProfile, LineSegment} from '../curves';
-import {vector2Signal} from '../decorators';
+import {nodeName, vector2Signal} from '../decorators';
import {arc, drawLine, drawPivot} from '../utils';
import {Curve, CurveProps} from './Curve';
@@ -53,6 +53,7 @@ export interface RayProps extends CurveProps {
* });
* ```
*/
+@nodeName('Ray')
export class Ray extends Curve {
/**
* The starting point of the ray.
diff --git a/packages/2d/src/lib/components/Rect.ts b/packages/2d/src/lib/components/Rect.ts
index 3d067e55..06eb824d 100644
--- a/packages/2d/src/lib/components/Rect.ts
+++ b/packages/2d/src/lib/components/Rect.ts
@@ -7,7 +7,7 @@ import {
SpacingSignal,
} from '@motion-canvas/core';
import {getRectProfile} from '../curves/getRectProfile';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {spacingSignal} from '../decorators/spacingSignal';
import {DesiredLength} from '../partials';
import {drawRoundRect} from '../utils';
@@ -30,6 +30,7 @@ export interface RectProps extends CurveProps {
cornerSharpness?: SignalValue<number>;
}
+@nodeName('Rect')
export class Rect extends Curve {
/**
* Rounds the corners of this rectangle.
diff --git a/packages/2d/src/lib/components/Shape.ts b/packages/2d/src/lib/components/Shape.ts
index 15c6ca15..e3afe89a 100644
--- a/packages/2d/src/lib/components/Shape.ts
+++ b/packages/2d/src/lib/components/Shape.ts
@@ -8,7 +8,7 @@ import {
map,
threadable,
} from '@motion-canvas/core';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {
CanvasStyleSignal,
canvasStyleSignal,
@@ -29,6 +29,7 @@ export interface ShapeProps extends LayoutProps {
antialiased?: SignalValue<boolean>;
}
+@nodeName('Shape')
export abstract class Shape extends Layout {
@canvasStyleSignal()
public declare readonly fill: CanvasStyleSignal<this>;
diff --git a/packages/2d/src/lib/components/Txt.ts b/packages/2d/src/lib/components/Txt.ts
index e3d9cf3b..9d524dea 100644
--- a/packages/2d/src/lib/components/Txt.ts
+++ b/packages/2d/src/lib/components/Txt.ts
@@ -9,7 +9,7 @@ import {
capitalize,
threadable,
} from '@motion-canvas/core';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {is} from '../utils';
import {Node} from './Node';
import {Shape, ShapeProps} from './Shape';
@@ -24,6 +24,7 @@ export interface TxtProps extends ShapeProps {
text?: SignalValue<string>;
}
+@nodeName('Txt')
export class Txt extends Shape {
/**
* Create a bold text node.
diff --git a/packages/2d/src/lib/components/TxtLeaf.ts b/packages/2d/src/lib/components/TxtLeaf.ts
index 773b4b10..f5c8c887 100644
--- a/packages/2d/src/lib/components/TxtLeaf.ts
+++ b/packages/2d/src/lib/components/TxtLeaf.ts
@@ -6,7 +6,13 @@ import {
lazy,
textLerp,
} from '@motion-canvas/core';
-import {computed, initial, interpolation, signal} from '../decorators';
+import {
+ computed,
+ initial,
+ interpolation,
+ nodeName,
+ signal,
+} from '../decorators';
import {Shape, ShapeProps} from './Shape';
import {Txt} from './Txt';
import {View2D} from './View2D';
@@ -16,6 +22,7 @@ export interface TxtLeafProps extends ShapeProps {
text?: SignalValue<string>;
}
+@nodeName('TxtLeaf')
export class TxtLeaf extends Shape {
@lazy(() => {
const formatter = document.createElement('span');
diff --git a/packages/2d/src/lib/components/Video.ts b/packages/2d/src/lib/components/Video.ts
index 1e74a540..32536d84 100644
--- a/packages/2d/src/lib/components/Video.ts
+++ b/packages/2d/src/lib/components/Video.ts
@@ -10,7 +10,7 @@ import {
useLogger,
useThread,
} from '@motion-canvas/core';
-import {computed, initial, signal} from '../decorators';
+import {computed, initial, nodeName, signal} from '../decorators';
import {DesiredLength} from '../partials';
import {drawImage} from '../utils';
import {Rect, RectProps} from './Rect';
@@ -44,6 +44,7 @@ export interface VideoProps extends RectProps {
play?: boolean;
}
+@nodeName('Video')
export class Video extends Rect {
private static readonly pool: Record<string, HTMLVideoElement> = {};
diff --git a/packages/2d/src/lib/components/View2D.ts b/packages/2d/src/lib/components/View2D.ts
index 785385cf..7372a3fb 100644
--- a/packages/2d/src/lib/components/View2D.ts
+++ b/packages/2d/src/lib/components/View2D.ts
@@ -1,5 +1,6 @@
import {PlaybackState, SimpleSignal, lazy} from '@motion-canvas/core';
import {initial, signal} from '../decorators';
+import {nodeName} from '../decorators/nodeName';
import {useScene2D} from '../scenes/useScene2D';
import type {Node} from './Node';
import {Rect, RectProps} from './Rect';
@@ -8,6 +9,7 @@ export interface View2DProps extends RectProps {
assetHash: string;
}
+@nodeName('View2D')
export class View2D extends Rect {
@lazy(() => {
const frameID = 'motion-canvas-2d-frame';
diff --git a/packages/2d/src/lib/decorators/index.ts b/packages/2d/src/lib/decorators/index.ts
index 5477151a..54e7c99d 100644
--- a/packages/2d/src/lib/decorators/index.ts
+++ b/packages/2d/src/lib/decorators/index.ts
@@ -5,5 +5,6 @@ export * from './computed';
export * from './defaultStyle';
export * from './filtersSignal';
export * from './initializers';
+export * from './nodeName';
export * from './signal';
export * from './vector2Signal';
diff --git a/packages/2d/src/lib/decorators/nodeName.ts b/packages/2d/src/lib/decorators/nodeName.ts
new file mode 100644
index 00000000..69c99135
--- /dev/null
+++ b/packages/2d/src/lib/decorators/nodeName.ts
@@ -0,0 +1,13 @@
+/**
+ * @internal
+ */
+export const NODE_NAME = Symbol.for('@motion-canvas/2d/nodeName');
+
+/**
+ * @internal
+ */
+export function nodeName(name: string) {
+ return function (target: any) {
+ target.prototype[NODE_NAME] = name;
+ };
+}