# Motion components: the spec (v0) A motion component is a web element that draws itself at any moment of time. MOGA renders them into video, and the same component plays in any web page, in React, in Remotion or in HyperFrames, because it asks its host for nothing but time, props and a small `ctx`. This page is the contract between a component and a host. MOGA's stage (`runtime/runtime.ts`) is one host; `@moga/player` (`packages/player`) is the other, and the one to copy. Status: v0, December 2026. The names below are what MOGA ships today; a later version may rename the `x-m3e-*` and `x-moga-*` keywords to neutral ones and will keep reading these. ## 1. A component is a folder ``` / component.ts the element (or .tsx, .js, .jsx); default export: a class extending HTMLElement schema.json its props, as JSON Schema … any files of its own it imports (motion.ts, shapes.ts); nothing outside the folder ``` `` is a custom element name: lowercase, with a hyphen (`title-card`). A component builds from its own files only, so it can be copied anywhere whole. ## 2. It draws from time, props and ctx ```ts export default class TitleCard extends HTMLElement { renderAt(t: number, props: Props, ctx: Ctx) { … } } ``` - `t` is seconds since the element came on screen. The host calls `renderAt` for every frame it shows. - The same `t`, `props` and `ctx` always draw the same frame, in any order: draw from them alone. No timers, no `Date`, no `performance.now`, no `Math.random` (use `ctx.random(i)`), no network. - A component draws into its own DOM (children, a shadow root, a canvas). The host sets its box (`width` × `height` px); a component sized for 1080p scales with `ctx.height / 1080`. ## 3. ctx | Field | What it is | | ---------------------------- | ------------------------------------------------------------------------- | | `fps`, `frame` | The frame rate, and `t` as a frame number | | `width`, `height` | The element's box in px | | `duration` | Seconds it stays on screen (0: it holds), so an exit can land at its end | | `theme` | `light` or `dark` | | `seed`, `random(i)` | A number in [0, 1) for each `i`, the same on every frame and every render | | `ease(ease, s, dur?)` | Progress (0 → 1, past 1 where a spring swings) of a move `s` seconds in | | `tween(a, b, ease, s, dur?)` | A number or colour from `a` to `b` along `ease` | | `token(name)` | A token's value in the theme shown: `token('md.sys.color.primary')` | | `colors` | Every colour token, resolved | | `wait(promise)` | Holds the frame until a picture or font it loads settles | An `ease` is any ease a MOGA keyframe takes: a spring token (`'{md.sys.motion.spring.expressive.spatial.fast}'`), a spring by feel (`{ bounce: 0.2, dur: 0.5 }`), a cubic bezier (`{ bezier: [x1, y1, x2, y2], dur }`), a named curve (`{ curve: 'out(4)', dur: 0.8 }`) or `'linear'`. ## 4. Props `schema.json` lists each prop with `type` and `default`. A host gives `renderAt` every prop, defaults filled in, numbers as numbers, booleans as booleans, and a token reference (`'{md.sys.color.primary}'`) resolved to its value. - `"x-m3e-animatable": true` on a number: a host may keyframe it. - `"x-m3e-text": true` on a string: words a host translates. - `"x-moga-preview"`: how to frame it alone (its box, props and length), `"x-moga-label"` and `"x-moga-icon"`: its chip. ## 5. Look: tokens, never hard-coded colours Colours, corners and type come from tokens: `ctx.token(...)` in code, `var(--md-sys-color-primary)` in CSS (a token's path with dots as dashes). Motion comes from spring and curve tokens through `ctx.ease`. A **theme preset** is one set of those tokens (colours light and dark, shapes, type scale); a host draws with whichever preset it is given, so a component restyles with no change to its code. MOGA's default is M3 Expressive's classic-blue scheme (`packages/player/dist/theme.js`); a preset is a plain object `{ name, tokens: { "": { type, value, dark? } }, css? }`. The Hub serves a preset's tokens, and the tokens a bundle carries, for a project that wants the look without the components: `/t/m3-expressive.css` (CSS variables, light on `:root`, dark under `.dark`, `[data-theme="dark"]` or the system's dark mode), `/t/m3-expressive.tailwind.css` (the same, then Tailwind v4 names for them: `bg-primary`, `rounded-large`, `font-brand`), `/t/m3-expressive.json` (DTCG, a dark value under `$extensions.dark` as MOGA writes it), and `/r/theme.json` (a shadcn theme item: `npx shadcn add` writes its `cssVars`). A bundle's: `/t/.css` and so on, and its `/r/.json` carries them as `cssVars`. ## 6. Hosts A host does four things: defines the element under its tag, fills its props (section 4), sets its box and the preset's CSS variables, and calls `renderAt` with `ctx` for the time it wants. `@moga/player` is that in about 200 lines: ```ts import TitleCard from '@/components/moga/title-card'; // index.ts: defineMotion('title-card', Component, schema) import preset from '@/components/moga/theme.js'; const player = TitleCard.mount(element, { preset, duration: 5, props: { title: 'Make it move' }, }); player.play(); // a web page's clock player.seek(2.5); // a scrubber, a scroll position player.frame(n); // Remotion's useCurrentFrame(), HyperFrames' seek ``` `node scripts/player-check.ts` proves the player draws what MOGA renders: the motion pack's title card, ten frames light and dark, pixel for pixel. Each host has a few lines of glue beside the player, so the component follows that host's clock: | Host | Glue | How | | ----------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | A web page | none | `mount(...).play()`, or `seek(t)` from a scrubber; `fit: true` scales the box to the element's width | | React | `react.js` (`/r/player-react.json`) | ``; with no `time` or `frame` it plays | | Remotion | `remotion.js` (`/r/player-remotion.json`) | `` draws `useCurrentFrame()`, sized to the composition, and holds the render (`delayRender`) until `player.ready()` | | HyperFrames | `hyperframes.js` (in `/r/player.json`) | `follow(player, { start })`: draws the time of every `hf-seek` HyperFrames sends, and makes the capture wait for `player.ready()` | `player.ready()` settles when what the frame drawn waits on (its fonts, the pictures it passed to `ctx.wait`) has loaded; a renderer captures after it. A page with no build (a HyperFrames composition, a CodePen) imports from the Hub directly; the component's code comes built into one module, as MOGA builds it: ```html ``` ## 7. Getting one Every component listed on MOGA Hub is a shadcn registry item, free and with no account ([decision](decisions/hub.md#registry)): ``` npx shadcn@latest add https://hub.trymoga.app/r/moga/motion/title-card.json ``` It copies the component's source into `components/moga//` with an `index.ts` that defines it, and the player and default preset into `components/moga/`. A component written in JSX comes as MOGA builds it (MOGA's JSX makes real DOM elements, which a project's own JSX setting would not). `https://hub.trymoga.app/r/registry.json` lists them all. Without shadcn, `npx -y https://hub.trymoga.app/cli.tgz add moga/motion/title-card` does the same, and `search`, `show` and `tokens` find and read them. An agent reaches them through the Hub's MCP server (`claude mcp add --transport http moga https://hub.trymoga.app/mcp`) or `https://hub.trymoga.app/llms.txt` ([decision](decisions/hub.md#agents)).