Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: added switch, radio
dev_wandry1df37ca6bc47
diff --git a/components/docs/examples/index.tsx b/components/docs/examples/index.tsxindex 74f4105b..461a8733 100644--- a/components/docs/examples/index.tsx+++ b/components/docs/examples/index.tsx@@ -13,6 +13,8 @@ import {CheckboxExampleScene,checkboxExampleCode,} from "./checkbox-example";+import { RadioExampleScene, radioExampleCode } from "./radio-example";+import { SwitchExampleScene, switchExampleCode } from "./switch-example";export interface ExampleEntry {Component: ComponentType;@@ -58,4 +60,20 @@ export const examples: Record<string, ExampleEntry> = {width: W,height: H,},+ "radio-example": {+ Component: RadioExampleScene,+ code: radioExampleCode,+ durationInFrames: 100,+ fps: FPS,+ width: W,+ height: H,+ },+ "switch-example": {+ Component: SwitchExampleScene,+ code: switchExampleCode,+ durationInFrames: 100,+ fps: FPS,+ width: W,+ height: H,+ },};diff --git a/components/docs/examples/radio-example.tsx b/components/docs/examples/radio-example.tsxnew file mode 100644index 00000000..59c2e3a5--- /dev/null+++ b/components/docs/examples/radio-example.tsx@@ -0,0 +1,24 @@+"use client";++import { Radio } from "@/registry/remocn-ui/radio";+import { useRadioTransition } from "@/registry/remocn-ui/radio/use-radio-transition";++export const RadioExampleScene = () => {+ const style = useRadioTransition([+ { at: 18, state: "checked", duration: 14 },+ { at: 78, state: "unchecked", duration: 12 },+ ]);+ return <Radio label="Subscribe to updates" style={style} />;+};++export const radioExampleCode = `import { Radio } from "@/components/remocn/radio";+import { useRadioTransition } from "@/components/remocn/use-radio-transition";++export const Scene = () => {+ const style = useRadioTransition([+ { at: 18, state: "checked", duration: 14 },+ { at: 78, state: "unchecked", duration: 12 },+ ]);++ return <Radio label="Subscribe to updates" style={style} />;+};`;diff --git a/components/docs/examples/switch-example.tsx b/components/docs/examples/switch-example.tsxnew file mode 100644index 00000000..dc01f70a--- /dev/null+++ b/components/docs/examples/switch-example.tsx@@ -0,0 +1,24 @@+"use client";++import { Switch } from "@/registry/remocn-ui/switch";+import { useSwitchTransition } from "@/registry/remocn-ui/switch/use-switch-transition";++export const SwitchExampleScene = () => {+ const style = useSwitchTransition([+ { at: 18, state: "checked", duration: 14 },+ { at: 78, state: "unchecked", duration: 12 },+ ]);+ return <Switch label="Enable notifications" style={style} />;+};++export const switchExampleCode = `import { Switch } from "@/components/remocn/switch";+import { useSwitchTransition } from "@/components/remocn/use-switch-transition";++export const Scene = () => {+ const style = useSwitchTransition([+ { at: 18, state: "checked", duration: 14 },+ { at: 78, state: "unchecked", duration: 12 },+ ]);++ return <Switch label="Enable notifications" style={style} />;+};`;diff --git a/content/docs/ui/components/meta.json b/content/docs/ui/components/meta.jsonindex 0ee20f66..edd423aa 100644--- a/content/docs/ui/components/meta.json+++ b/content/docs/ui/components/meta.json@@ -1,5 +1,5 @@{"title": "Components","collapsible": false,- "pages": ["accordion", "alert-dialog", "button", "checkbox", "spinner"]+ "pages": ["accordion", "alert-dialog", "button", "checkbox", "radio", "spinner", "switch"]}diff --git a/content/docs/ui/components/radio.mdx b/content/docs/ui/components/radio.mdxnew file mode 100644index 00000000..d5bec3f7--- /dev/null+++ b/content/docs/ui/components/radio.mdx@@ -0,0 +1,136 @@+---+title: Radio+description: A radio whose checked/unchecked state is a pure function of the timeline+---++<ComponentPreview name="radio" />++A state atom whose appearance (checked, unchecked) is a pure function of the `state` prop. Pass a state directly or drive it from the Remotion timeline via `useCurrentState`. The component reads no frame — only the state value you give it.++## Installation++<InstallBlock name="radio" />++<Note>+Installing `radio` automatically installs the shared `remocn-ui` core (`lib/remocn-ui/`) via `registryDependencies`. You do not need to install it separately.+</Note>++## States++`RadioState` is:++```ts+type RadioState =+ | "unchecked" // empty ring, border = theme.border, no dot+ | "checked" // ring border = primary, inner dot fills with primary, scales + fades in+```++`checked` sets the ring border to `primary`, fills the inner dot with `primary`, and animates it in via opacity and scale. `unchecked` renders an empty ring with the theme border color and a hidden dot.++## Snap usage++Pass `state` directly — the component snaps instantly to that visual. Useful for static previews or when you drive state from your own logic:++```tsx+import { Radio } from "@/components/remocn/radio";++export const Scene = () => <Radio state="checked" />;+```++To drive state from the timeline, use `useCurrentState`:++```tsx+import { useCurrentState } from "@/lib/remocn-ui";+import { Radio } from "@/components/remocn/radio";++export const Scene = () => {+ const state = useCurrentState(+ [+ { at: 18, state: "checked" },+ { at: 78, state: "unchecked" },+ ],+ "unchecked",+ );++ return <Radio label="Subscribe to updates" state={state} />;+};+```++Each `at` is a **Sequence-local authored frame**. State persists between steps: `checked` at frame 18 keeps the ring checked until `unchecked` fires at frame 78. See [Concepts](/docs/ui/concepts) for the full `useCurrentState` API.++## Smooth transitions++State changes via `state` snap with no cross-fade. For animated transitions, use `useRadioTransition` from the copied `use-radio-transition.ts` file. It reads the frame, interpolates between state presets, and returns a resolved `RadioStyle` — pass it to the `style` prop:++```tsx+import { Radio } from "@/components/remocn/radio";+import { useRadioTransition } from "@/components/remocn/use-radio-transition";++export const Scene = () => {+ const style = useRadioTransition([+ { at: 18, state: "checked", duration: 14 },+ { at: 78, state: "unchecked", duration: 12 },+ ]);+ return <Radio label="Subscribe to updates" style={style} />;+};+```++The `duration` field on each step overrides the file's `DEFAULT_DURATION` for that specific transition. To globally tune timing and easing, edit `use-radio-transition.ts` directly in your project — that file is yours (shadcn "own your code" philosophy).++`style` takes precedence over `state` when both are provided.++## Full lifecycle++A complete unchecked → checked → unchecked run using the smooth transition path. Copy the code to drop it into your own composition.++<LiveExample name="radio-example" />++## Props++<PropsTable+ rows={[+ {+ name: "state",+ type: "\"unchecked\" | \"checked\"",+ default: "\"unchecked\"",+ description: "Current visual state (snap path). State changes snap — no automatic cross-fade.",+ },+ {+ name: "style",+ type: "RadioStyle",+ description: "Resolved animated visual (smooth path). Pass an interpolated RadioStyle from useRadioTransition. Takes precedence over state when provided.",+ },+ {+ name: "label",+ type: "string",+ description: "Optional text label rendered next to the ring. Omit for a bare radio.",+ },+ {+ name: "size",+ type: "\"sm\" | \"default\" | \"lg\"",+ default: "\"default\"",+ description: "Ring and label size preset.",+ },+ {+ name: "theme",+ type: "Partial<RemocnTheme>",+ description: "Per-component theme override. Merges with the active RemocnUIProvider theme and the mode defaults. Must be concrete oklch/hex/rgb values — not CSS custom properties.",+ },+ {+ name: "primary",+ type: "string",+ description: "Convenience override for the primary theme token — merged into theme.",+ },+ {+ name: "mode",+ type: "\"light\" | \"dark\"",+ default: "\"light\"",+ description: "Sets the base palette. Overrides the mode on RemocnUIProvider when both are present.",+ },+ {+ name: "className",+ type: "string",+ description: "Optional className passed to the radio element.",+ },+ ]}+/>diff --git a/content/docs/ui/components/switch.mdx b/content/docs/ui/components/switch.mdxnew file mode 100644index 00000000..67a335ad--- /dev/null+++ b/content/docs/ui/components/switch.mdx@@ -0,0 +1,136 @@+---+title: Switch+description: A switch whose checked/unchecked state is a pure function of the timeline+---++<ComponentPreview name="switch" />++A state atom whose appearance (checked, unchecked) is a pure function of the `state` prop. Pass a state directly or drive it from the Remotion timeline via `useCurrentState`. The component reads no frame — only the state value you give it.++## Installation++<InstallBlock name="switch" />++<Note>+Installing `switch` automatically installs the shared `remocn-ui` core (`lib/remocn-ui/`) via `registryDependencies`. You do not need to install it separately.+</Note>++## States++`SwitchState` is:++```ts+type SwitchState =+ | "unchecked" // track = theme.input, thumb at left+ | "checked" // track fills primary, thumb slides to the right+```++`checked` fills the track with `primary` and slides the thumb to the right edge. `unchecked` renders an inactive track with the theme input color and positions the thumb at the left.++## Snap usage++Pass `state` directly — the component snaps instantly to that visual. Useful for static previews or when you drive state from your own logic:++```tsx+import { Switch } from "@/components/remocn/switch";++export const Scene = () => <Switch state="checked" />;+```++To drive state from the timeline, use `useCurrentState`:++```tsx+import { useCurrentState } from "@/lib/remocn-ui";+import { Switch } from "@/components/remocn/switch";++export const Scene = () => {+ const state = useCurrentState(+ [+ { at: 18, state: "checked" },+ { at: 78, state: "unchecked" },+ ],+ "unchecked",+ );++ return <Switch label="Enable notifications" state={state} />;+};+```++Each `at` is a **Sequence-local authored frame**. State persists between steps: `checked` at frame 18 keeps the switch on until `unchecked` fires at frame 78. See [Concepts](/docs/ui/concepts) for the full `useCurrentState` API.++## Smooth transitions++State changes via `state` snap with no cross-fade. For animated transitions, use `useSwitchTransition` from the copied `use-switch-transition.ts` file. It reads the frame, interpolates between state presets, and returns a resolved `SwitchStyle` — pass it to the `style` prop:++```tsx+import { Switch } from "@/components/remocn/switch";+import { useSwitchTransition } from "@/components/remocn/use-switch-transition";++export const Scene = () => {+ const style = useSwitchTransition([+ { at: 18, state: "checked", duration: 14 },+ { at: 78, state: "unchecked", duration: 12 },+ ]);+ return <Switch label="Enable notifications" style={style} />;+};+```++The `duration` field on each step overrides the file's `DEFAULT_DURATION` for that specific transition. To globally tune timing and easing, edit `use-switch-transition.ts` directly in your project — that file is yours (shadcn "own your code" philosophy).++`style` takes precedence over `state` when both are provided.++## Full lifecycle++A complete unchecked → checked → unchecked run using the smooth transition path. Copy the code to drop it into your own composition.++<LiveExample name="switch-example" />++## Props++<PropsTable+ rows={[+ {+ name: "state",+ type: "\"unchecked\" | \"checked\"",+ default: "\"unchecked\"",+ description: "Current visual state (snap path). State changes snap — no automatic cross-fade.",+ },+ {+ name: "style",+ type: "SwitchStyle",+ description: "Resolved animated visual (smooth path). Pass an interpolated SwitchStyle from useSwitchTransition. Takes precedence over state when provided.",+ },+ {+ name: "label",+ type: "string",+ description: "Optional text label rendered next to the track. Omit for a bare switch.",+ },+ {+ name: "size",+ type: "\"sm\" | \"default\" | \"lg\"",+ default: "\"default\"",+ description: "Track and label size preset.",+ },+ {+ name: "theme",+ type: "Partial<RemocnTheme>",+ description: "Per-component theme override. Merges with the active RemocnUIProvider theme and the mode defaults. Must be concrete oklch/hex/rgb values — not CSS custom properties.",+ },+ {+ name: "primary",+ type: "string",+ description: "Convenience override for the primary theme token — merged into theme.",+ },+ {+ name: "mode",+ type: "\"light\" | \"dark\"",+ default: "\"light\"",+ description: "Sets the base palette. Overrides the mode on RemocnUIProvider when both are present.",+ },+ {+ name: "className",+ type: "string",+ description: "Optional className passed to the switch element.",+ },+ ]}+/>diff --git a/registry/__index__.tsx b/registry/__index__.tsxindex 42be79fd..3b699632 100644--- a/registry/__index__.tsx+++ b/registry/__index__.tsx@@ -113,8 +113,12 @@ import { Button } from "@/registry/remocn-ui/button";import { buttonConfig } from "@/registry/remocn-ui/button/config";import { Checkbox } from "@/registry/remocn-ui/checkbox";import { checkboxConfig } from "@/registry/remocn-ui/checkbox/config";+import { Radio } from "@/registry/remocn-ui/radio";+import { radioConfig } from "@/registry/remocn-ui/radio/config";import { Spinner } from "@/registry/remocn-ui/spinner";import { spinnerConfig } from "@/registry/remocn-ui/spinner/config";+import { Switch } from "@/registry/remocn-ui/switch";+import { switchConfig } from "@/registry/remocn-ui/switch/config";import { ZoomThroughTransition } from "@/registry/remocn/zoom-through-transition";import { zoomThroughTransitionConfig } from "@/registry/remocn/zoom-through-transition/config";@@ -292,6 +296,8 @@ const registry: Record<string, RegistryEntry> = {"accordion": { Component: Accordion, config: accordionConfig },"alert-dialog": { Component: AlertDialog, config: alertDialogConfig },"checkbox": { Component: Checkbox, config: checkboxConfig },+ "radio": { Component: Radio, config: radioConfig },+ "switch": { Component: Switch, config: switchConfig },"spinner": { Component: Spinner, config: spinnerConfig },};diff --git a/registry/remocn-ui/radio/__tests__/README.md b/registry/remocn-ui/radio/__tests__/README.mdnew file mode 100644index 00000000..d5fd7190--- /dev/null+++ b/registry/remocn-ui/radio/__tests__/README.md@@ -0,0 +1,118 @@+# `radio` — verification tests++Pure / deterministic verification for the `radio` component+(`registry/remocn-ui/radio/`). The RENDER path needs Remotion's+`useCurrentFrame()` and cannot run headless, so the render is NOT exercised+here. This suite covers the pieces that ARE pure: `RadioState` union+membership, `radioConfig.controls.state` wiring, `radioConfig.snippet`+codegen, `radioStyle` presets, and `tweenRadioStyle` interpolation.++## Animation model — pure snap + opt-in smooth path++Radio ships two complementary paths:++**Snap path** (`state?: RadioState` prop):+`Radio` is a frame-free pure renderer. The `state` prop drives all visuals.+Each state maps to a complete resting visual via the exported pure function+`radioStyle(state, ctx) => RadioStyle`. State changes snap instantly — no+tweening inside the component.++**Smooth path** (`style?: RadioStyle` prop):+Callers opt in to smooth transitions by passing a pre-interpolated `RadioStyle`+to the `style` prop. The caller — typically `useRadioTransition` — reads+`useCurrentFrame()` and calls `useStateTransition` from `core/timeline.ts` to+compute `{ from, to, progress }`, then blends the two presets via+`tweenRadioStyle(from, to, t)`. The `Radio` component itself remains+frame-free; it simply renders whatever `RadioStyle` it receives.++This design keeps `Radio` pure-testable (no Remotion render context needed)+while still supporting smooth check/uncheck transitions for production use.++## How to run++The repo uses **Bun**, which has a built-in test runner — runs TypeScript+natively, no test-framework dep.++```bash+bun install+bun test registry/remocn-ui/radio/__tests__+```++`radio.test.ts` imports `bun:test` (not `vitest`/`jest`), so no test script+or framework dep is added to `package.json`.++## What is covered++- **`RadioState` union** — asserts the two states `["unchecked","checked"]`+ are the complete set (via the real `controls.state.options` list from+ `config.ts`).+- **`radioConfig.controls.state`** — the customizer control wiring. Asserts a+ `select` control exists with exactly those two options, default `"checked"`+ (so the preview shows the filled dot), and that every option is a member of+ the `RadioState` union.+- **`radioConfig.snippet`** — REAL pure string builder (high value).+ Asserts: emits `state="<state>"` as a bare JSX prop for every option; NEVER+ emits `steps` or `action`; includes `import { Radio }` from+ `@/components/remocn/radio`; omits default-equal props (`label=""`,+ `size=default`, `mode=light`, `primary=#171717`); EMITS non-default+ `label`/`size`/`mode`/`primary`; structural round-trip (starts with import,+ contains `<Radio`, ends `/>`).+- **`radioStyle` presets** — exported pure `(state, ctx) => RadioStyle` map.+ A `RadioStyleContext` is built from `radioStyleContext(defaultLightTheme)`+ — the same call the component makes internally. Asserts per-state numeric+ invariants (dotOpacity, dotScale) and that `ringBorderColor` is always a+ non-empty string. Also asserts the key invariant: unchecked has dotOpacity 0;+ checked has dotOpacity 1.+- **`tweenRadioStyle`** — exported pure `(a, b, t) => RadioStyle`. Asserts:+ at t=0 all numeric fields equal `a`; at t=1 all equal `b`; at t=0.5 each+ numeric field is the exact midpoint (dotOpacity 0→1 gives 0.5, dotScale+ 0.4→1 gives 0.7). `ringBorderColor` at all t is a non-empty string (the+ oklch mix value is not hardcoded).++**Radio render** is a pure `(style | state) => visual` observable only via+Remotion render, not unit-tested here.++**`useRadioTransition`** reads `useCurrentFrame()` via `useStateTransition`+inside the hook — that is correct and expected. It is not a render component;+the smooth-path design isolates all frame-reading to the hook, keeping+`Radio` pure.++## Import strategy++`radio.test.ts` imports via **relative paths** and the+**`@/lib/remocn-ui` tsconfig alias**:++- `../index` — relative, for `RadioState`, `radioStyle`, `radioStyleContext`+- `../use-radio-transition` — relative, for `tweenRadioStyle`+- `../config` — relative, for `radioConfig`+- `@/lib/remocn-ui` — alias (resolves to `registry/remocn-ui/core/index.ts`),+ for `defaultLightTheme`++Importing `index.tsx` and `use-radio-transition.ts` pulls the `remotion`+module (and React), but neither `radioStyle`, `radioStyleContext`, nor+`tweenRadioStyle` call `useCurrentFrame()` at import time or at call time —+they are pure value functions. `bun test` resolves tsconfig `paths`, so the+alias works without additional config.++## Determinism grep checklist (run manually; must print NOTHING)++Radio is frame-free. The component must contain **none** of the following:++```bash+grep -nE "useCurrentFrame|useState|useEffect|onClick|onChange|addEventListener|Date\.now|Math\.random" \+ registry/remocn-ui/radio/index.tsx+```++Expected: no output. Any match is a determinism violation.++`use-radio-transition.ts` is the CALLER hook that intentionally reads+`useCurrentFrame()` (via `useStateTransition`). It is not a render component;+the smooth-path design isolates all frame-reading to the hook, keeping+`Radio` pure.++Tier-wide sweep:++```bash+grep -nE "useState|useEffect|onClick|onChange|addEventListener|Date\.now|Math\.random" \+ registry/remocn-ui/radio/index.tsx registry/remocn-ui/core/*.ts+```diff --git a/registry/remocn-ui/radio/__tests__/radio.test.ts b/registry/remocn-ui/radio/__tests__/radio.test.tsnew file mode 100644index 00000000..3b763379--- /dev/null+++ b/registry/remocn-ui/radio/__tests__/radio.test.ts@@ -0,0 +1,349 @@+/**+ * Verification tests for the PURE / DETERMINISTIC parts of `radio`.+ *+ * Scope:+ * - registry/remocn-ui/radio/index.tsx — RadioState union membership,+ * radioStyleContext, radioStyle presets+ * - registry/remocn-ui/radio/use-radio-transition.ts — tweenRadioStyle+ * - registry/remocn-ui/radio/config.ts — radioConfig.controls.state+ * wiring + radioConfig.snippet output (the state → JSX codegen)+ *+ * The render path (index.tsx) is a PURE-STATE model: `(state) => visual`.+ * State changes snap (no tweening inside the component). The smooth-path hook+ * `useRadioTransition` reads `useCurrentFrame()` via `useStateTransition`+ * internally; it cannot run outside a Remotion render tree. So Radio render+ * is NOT exercised here. The pure-testable surface is the customizer wiring,+ * snippet codegen, style presets, and tween interpolation (below).+ *+ * Runner: Bun's built-in test runner (TypeScript-native, no framework dep).+ * bun test registry/remocn-ui/radio/__tests__+ *+ * --------------------------------------------------------------------------+ * IMPORT STRATEGY+ * --------------------------------------------------------------------------+ * `config.ts` imports `RadioState` from `@/registry/remocn-ui/radio`+ * and the pieces under test never CALL a Remotion runtime API at import time —+ * `radioConfig` is a plain object; `.snippet` is a pure string builder;+ * `radioStyle` and `tweenRadioStyle` are pure value functions.+ * We import via RELATIVE paths (matching the existing test suite pattern),+ * annotating each import with the source it corresponds to.+ * --------------------------------------------------------------------------+ */++import { describe, expect, it } from "bun:test";+import {+ type RadioState,+ radioStyle,+ radioStyleContext,+} from "../index";+import { tweenRadioStyle } from "../use-radio-transition";+import { radioConfig } from "../config";+import { defaultLightTheme } from "@/lib/remocn-ui";++// ===========================================================================+// Shared fixtures+// ===========================================================================++/**+ * The RadioState union, enumerated as a runtime list for membership checks.+ * Must stay in sync with `export type RadioState` in index.tsx.+ */+const VALID_STATES: readonly RadioState[] = ["unchecked", "checked"];++/** Minimal shape mirroring the customizer's value bag passed to snippet(). */+type SnippetValues = {+ state?: string;+ label?: string;+ size?: string;+ mode?: string;+ primary?: string;+};++const snippet = (values: SnippetValues): string =>+ radioConfig.snippet(values as Record<string, unknown>);++// ===========================================================================+// 1. RadioState union membership+// ===========================================================================++describe("RadioState union", () => {+ it("contains exactly the two documented states", () => {+ // We can't enumerate a TS type at runtime, but we can assert the REAL+ // controls.state options match and that all known states are members.+ const control = radioConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ expect(control.options).toEqual(["unchecked", "checked"]);+ });++ it("every VALID_STATES entry is assignable (no typos in the fixture)", () => {+ // Belt-and-suspenders: the fixture array must have exactly 2 entries and+ // match the options list from the real config.+ const control = radioConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ expect(VALID_STATES).toHaveLength(2);+ for (const s of VALID_STATES) {+ expect(control.options).toContain(s);+ }+ });+});++// ===========================================================================+// 2. radioConfig.controls.state — customizer control wiring+// ===========================================================================++describe("radioConfig.controls.state", () => {+ it("is a select control", () => {+ expect(radioConfig.controls.state.type).toBe("select");+ });++ it("has exactly the two RadioState options in order", () => {+ const control = radioConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ expect(control.options).toEqual(["unchecked", "checked"]);+ });++ it("defaults to 'checked' so the preview shows the filled dot", () => {+ const control = radioConfig.controls.state;+ expect(control.default).toBe("checked");+ });++ it("every option is a member of the RadioState union", () => {+ const control = radioConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ for (const option of control.options) {+ expect(VALID_STATES).toContain(option as RadioState);+ }+ });+});++// ===========================================================================+// 3. radioConfig.snippet — pure string builder+// State model: snippet emits `state="<state>"` as a bare JSX prop.+// It NEVER emits `steps` or `action`.+// ===========================================================================++describe("radioConfig.snippet: state prop emission", () => {+ it("emits state=\"unchecked\" for the unchecked option", () => {+ expect(snippet({ state: "unchecked" })).toContain('state="unchecked"');+ });++ it("emits state=\"checked\" for the checked option", () => {+ expect(snippet({ state: "checked" })).toContain('state="checked"');+ });++ it("emits the correct state for every control option", () => {+ const control = radioConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ for (const state of control.options) {+ const out = snippet({ state });+ expect(out).toContain(`state="${state}"`);+ }+ });+});++describe("radioConfig.snippet: NEVER emits steps or action", () => {+ it("never emits `steps` in any state", () => {+ for (const state of VALID_STATES) {+ expect(snippet({ state })).not.toContain("steps");+ }+ });++ it("never emits `action` in any state", () => {+ for (const state of VALID_STATES) {+ expect(snippet({ state })).not.toContain("action");+ }+ });+});++describe("radioConfig.snippet: import line", () => {+ it("includes `import { Radio }` from the correct path", () => {+ const out = snippet({ state: "checked" });+ expect(out).toContain('import { Radio }');+ expect(out).toContain('from "@/components/remocn/radio"');+ });+});++describe("radioConfig.snippet: default props are omitted", () => {+ // Defaults: label="", size=default, mode=light, primary=#171717+ const allDefaults = snippet({+ state: "checked",+ label: "",+ size: "default",+ mode: "light",+ primary: "#171717",+ });++ it("omits label when it equals the default (empty string)", () => {+ expect(allDefaults).not.toContain("label=");+ });++ it("omits size when it equals the default 'default'", () => {+ expect(allDefaults).not.toContain("size=");+ });++ it("omits mode when it equals the default 'light'", () => {+ expect(allDefaults).not.toContain("mode=");+ });++ it("omits primary when it equals the default '#171717'", () => {+ expect(allDefaults).not.toContain("primary=");+ });+});++describe("radioConfig.snippet: non-default props are emitted", () => {+ it("emits a non-default label", () => {+ expect(snippet({ state: "checked", label: "Option A" })).toContain('label="Option A"');+ });++ it("emits a non-default size", () => {+ expect(snippet({ state: "checked", size: "lg" })).toContain('size="lg"');+ });++ it("emits a non-default mode", () => {+ expect(snippet({ state: "checked", mode: "dark" })).toContain('mode="dark"');+ });++ it("emits a non-default primary color", () => {+ expect(snippet({ state: "checked", primary: "#6366f1" })).toContain('primary="#6366f1"');+ });+});++describe("radioConfig.snippet: structural round-trip", () => {+ const out = snippet({ state: "checked" });++ it("starts with the import line", () => {+ expect(out.startsWith('import { Radio }')).toBe(true);+ });++ it("contains a <Radio JSX opening", () => {+ expect(out).toContain("<Radio");+ });++ it("ends with a self-closing />", () => {+ expect(out.trimEnd().endsWith("/>")).toBe(true);+ });+});++// ===========================================================================+// 4. radioStyle presets — pure (state, ctx) => RadioStyle+// radioStyleContext and radioStyle are now exported and frame-free.+// Build one ctx from the default light theme, then assert the+// numeric/opacity invariants for both states.+// ringBorderColor is derived from the theme — asserted non-empty only+// (exact value is an implementation detail of the theme).+// ===========================================================================++const ctx = radioStyleContext(defaultLightTheme);++describe("radioStyle: unchecked state", () => {+ const s = radioStyle("unchecked", ctx);++ it("dotOpacity is 0 (dot hidden)", () => {+ expect(s.dotOpacity).toBe(0);+ });++ it("dotScale is 0.4 (pre-pop position, slight shrink)", () => {+ expect(s.dotScale).toBeCloseTo(0.4, 10);+ });++ it("ringBorderColor is a non-empty string", () => {+ expect(typeof s.ringBorderColor).toBe("string");+ expect(s.ringBorderColor.length).toBeGreaterThan(0);+ });+});++describe("radioStyle: checked state", () => {+ const s = radioStyle("checked", ctx);++ it("dotOpacity is 1 (dot fully visible)", () => {+ expect(s.dotOpacity).toBe(1);+ });++ it("dotScale is 1 (full size, post-pop)", () => {+ expect(s.dotScale).toBe(1);+ });++ it("ringBorderColor is a non-empty string", () => {+ expect(typeof s.ringBorderColor).toBe("string");+ expect(s.ringBorderColor.length).toBeGreaterThan(0);+ });+});++describe("radioStyle: invariants — unchecked hides dot, checked shows dot", () => {+ it("unchecked has dotOpacity 0 (dot invisible)", () => {+ const s = radioStyle("unchecked", ctx);+ expect(s.dotOpacity).toBe(0);+ });++ it("checked has dotOpacity 1 (dot fully visible)", () => {+ const s = radioStyle("checked", ctx);+ expect(s.dotOpacity).toBe(1);+ });+});++// ===========================================================================+// 5. tweenRadioStyle — pure linear interpolation between two RadioStyles.+// Numbers lerp linearly; colors via oklch mix → non-empty string at all t.+// Concrete expectations: unchecked→checked for midpoint math.+// unchecked: dotOpacity=0, dotScale=0.4+// checked: dotOpacity=1, dotScale=1+// ===========================================================================++describe("tweenRadioStyle: t=0 returns values equal to `a`", () => {+ const a = radioStyle("unchecked", ctx);+ const b = radioStyle("checked", ctx);+ const r = tweenRadioStyle(a, b, 0);++ it("dotOpacity equals a.dotOpacity at t=0", () => {+ expect(r.dotOpacity).toBeCloseTo(a.dotOpacity, 10);+ });++ it("dotScale equals a.dotScale at t=0", () => {+ expect(r.dotScale).toBeCloseTo(a.dotScale, 10);+ });++ it("ringBorderColor is a non-empty string at t=0", () => {+ expect(typeof r.ringBorderColor).toBe("string");+ expect(r.ringBorderColor.length).toBeGreaterThan(0);+ });+});++describe("tweenRadioStyle: t=1 returns values equal to `b`", () => {+ const a = radioStyle("unchecked", ctx);+ const b = radioStyle("checked", ctx);+ const r = tweenRadioStyle(a, b, 1);++ it("dotOpacity equals b.dotOpacity at t=1", () => {+ expect(r.dotOpacity).toBeCloseTo(b.dotOpacity, 10);+ });++ it("dotScale equals b.dotScale at t=1", () => {+ expect(r.dotScale).toBeCloseTo(b.dotScale, 10);+ });++ it("ringBorderColor is a non-empty string at t=1", () => {+ expect(typeof r.ringBorderColor).toBe("string");+ expect(r.ringBorderColor.length).toBeGreaterThan(0);+ });+});++describe("tweenRadioStyle: t=0.5 midpoint numeric lerp (unchecked → checked)", () => {+ // unchecked: dotOpacity=0, dotScale=0.4+ // checked: dotOpacity=1, dotScale=1+ const a = radioStyle("unchecked", ctx);+ const b = radioStyle("checked", ctx);+ const r = tweenRadioStyle(a, b, 0.5);++ it("dotOpacity midpoint: 0 → 1 gives 0.5", () => {+ expect(r.dotOpacity).toBeCloseTo(0.5, 10);+ });++ it("dotScale midpoint: 0.4 → 1 gives 0.7", () => {+ expect(r.dotScale).toBeCloseTo(0.7, 10);+ });++ it("ringBorderColor is a non-empty string at t=0.5", () => {+ expect(typeof r.ringBorderColor).toBe("string");+ expect(r.ringBorderColor.length).toBeGreaterThan(0);+ });+});diff --git a/registry/remocn-ui/radio/config.ts b/registry/remocn-ui/radio/config.tsnew file mode 100644index 00000000..342dd7ae--- /dev/null+++ b/registry/remocn-ui/radio/config.ts@@ -0,0 +1,57 @@+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";+import type { RadioState } from "@/registry/remocn-ui/radio";++export const radioConfig: ComponentConfig = {+ componentName: "Radio",+ importPath: "@/components/remocn/radio",+ controls: {+ label: { type: "text", default: "", label: "Label" },+ size: {+ type: "select",+ default: "default",+ options: ["sm", "default", "lg"],+ label: "Size",+ },+ state: {+ type: "select",+ // Default to `checked` so the preview shows the filled dot.+ default: "checked",+ options: ["unchecked", "checked"],+ label: "State",+ },+ mode: {+ type: "select",+ default: "light",+ options: ["light", "dark"],+ label: "Mode",+ },+ primary: { type: "color", default: "#171717", label: "Primary" },+ },+ durationInFrames: 120,+ fps: FPS,+ compositionWidth: W,+ compositionHeight: H,+ snippet: (values) => {+ const state = (values.state as RadioState) ?? "checked";+ const label = values.label as string | undefined;+ const size = values.size as string | undefined;+ const mode = values.mode as string | undefined;+ const primary = values.primary as string | undefined;++ const props: string[] = [` state="${state}"`];+ if (label !== undefined && label !== "")+ props.push(` label="${label}"`);+ if (size !== undefined && size !== "default")+ props.push(` size="${size}"`);+ if (mode !== undefined && mode !== "light")+ props.push(` mode="${mode}"`);+ if (primary !== undefined && primary !== "#171717")+ props.push(` primary="${primary}"`);++ return `import { Radio } from "@/components/remocn/radio";++<Radio+${props.join("\n")}+/>`;+ },+};diff --git a/registry/remocn-ui/radio/index.tsx b/registry/remocn-ui/radio/index.tsxnew file mode 100644index 00000000..10c7bd4e--- /dev/null+++ b/registry/remocn-ui/radio/index.tsx@@ -0,0 +1,177 @@+"use client";++import { type RemocnTheme, useRemocnTheme } from "@/lib/remocn-ui";++export type RadioState = "unchecked" | "checked";++type RadioSize = "sm" | "default" | "lg";++export interface RadioProps {+ /** Current visual state (snap path). State changes snap (no enter-tweens). */+ state?: RadioState;+ /**+ * Resolved animated visual (smooth path). When provided, takes precedence over+ * `state` — feed it an interpolated `RadioStyle` from `useRadioTransition`.+ */+ style?: RadioStyle;+ /** Optional text label rendered next to the circle. */+ label?: string;+ size?: RadioSize;+ theme?: Partial<RemocnTheme>;+ /** Convenience override for the `primary` theme token — merged into `theme`. */+ primary?: string;+ mode?: "light" | "dark";+ className?: string;+}++const SIZE_STYLES: Record<+ RadioSize,+ { box: number; fontSize: number; gap: number }+> = {+ sm: { box: 16, fontSize: 13, gap: 8 },+ default: { box: 20, fontSize: 15, gap: 10 },+ lg: { box: 24, fontSize: 17, gap: 12 },+};++// ===========================================================================+// Radio visual — the COMPLETE animated look for a moment in time. A `state`+// is a named preset of this visual (`radioStyle`); the smooth path feeds an+// interpolated `RadioStyle` straight through. The component is a pure+// renderer of whichever `RadioStyle` it receives.+// ===========================================================================++export interface RadioStyle {+ /** Animated outer-ring border color. */+ ringBorderColor: string;+ /** Inner dot opacity 0→1. */+ dotOpacity: number;+ /** Inner dot scale 0.4→1 (a slight pop on check). */+ dotScale: number;+}++/** Concrete colors for the active theme, resolved once per render. */+export interface RadioStyleContext {+ uncheckedBorder: string;+ checkedBorder: string;+ /** Static dot fill color (never animated). */+ dotColor: string;+}++/**+ * Derive the concrete colors for a theme. Pure — call it once and reuse the+ * result for every `radioStyle(state, ctx)` preset.+ */+export function radioStyleContext(theme: RemocnTheme): RadioStyleContext {+ return {+ uncheckedBorder: theme.border,+ checkedBorder: theme.primary,+ dotColor: theme.primary,+ };+}++/**+ * The COMPLETE resting visual for a state — a pure `(state, ctx) => RadioStyle`+ * map. To change how a state looks, edit one entry.+ */+export function radioStyle(+ state: RadioState,+ ctx: RadioStyleContext,+): RadioStyle {+ switch (state) {+ case "checked":+ return {+ ringBorderColor: ctx.checkedBorder,+ dotOpacity: 1,+ dotScale: 1,+ };+ default:+ return {+ ringBorderColor: ctx.uncheckedBorder,+ dotOpacity: 0,+ dotScale: 0.4,+ };+ }+}++export function Radio({+ state = "unchecked",+ style,+ label,+ size = "default",+ theme: themeOverride,+ primary,+ mode,+ className,+}: RadioProps) {+ const theme = useRemocnTheme(+ { ...themeOverride, ...(primary ? { primary } : {}) },+ mode,+ );++ const sizeStyle = SIZE_STYLES[size];+ const ctx = radioStyleContext(theme);+ const v = style ?? radioStyle(state, ctx);+ const boxSize = sizeStyle.box;++ return (+ <div+ style={{+ position: "absolute",+ inset: 0,+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ background: theme.background,+ fontFamily:+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",+ }}+ >+ <span+ className={className}+ style={{+ display: "inline-flex",+ alignItems: "center",+ gap: sizeStyle.gap,+ }}+ >+ {/* The ring — animated border; the inner dot appears inside it. */}+ <span+ style={{+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ width: boxSize,+ height: boxSize,+ borderRadius: "50%",+ border: `1px solid ${v.ringBorderColor}`,+ background: theme.background,+ }}+ >+ {/* Inner dot — scales + fades in on check. */}+ <span+ style={{+ width: Math.round(boxSize * 0.45),+ height: Math.round(boxSize * 0.45),+ borderRadius: "50%",+ background: ctx.dotColor,+ opacity: v.dotOpacity,+ transform: `scale(${v.dotScale})`,+ }}+ />+ </span>+ {label !== undefined && (+ <span+ style={{+ fontSize: sizeStyle.fontSize,+ fontWeight: 500,+ letterSpacing: "-0.01em",+ color: theme.foreground,+ }}+ >+ {label}+ </span>+ )}+ </span>+ </div>+ );+}diff --git a/registry/remocn-ui/radio/use-radio-transition.ts b/registry/remocn-ui/radio/use-radio-transition.tsnew file mode 100644index 00000000..b3f6a429--- /dev/null+++ b/registry/remocn-ui/radio/use-radio-transition.ts@@ -0,0 +1,72 @@+"use client";++import {+ easings,+ mixOklch,+ type RemocnTheme,+ type Step,+ useRemocnTheme,+ useStateTransition,+} from "@/lib/remocn-ui";+import {+ radioStyle,+ radioStyleContext,+ type RadioState,+ type RadioStyle,+} from "@/components/remocn/radio";+// ^ install path; resolves in-repo via the @/components/remocn/* tsconfig alias.++/** Default transition length (frames) when a step omits `duration`. Tune to taste. */+export const DEFAULT_DURATION = 10;++/** Blend two radio visuals: numbers lerp, colors via oklch mix. */+export function tweenRadioStyle(+ a: RadioStyle,+ b: RadioStyle,+ t: number,+): RadioStyle {+ return {+ ringBorderColor: mixOklch(a.ringBorderColor, b.ringBorderColor, t),+ dotOpacity: a.dotOpacity + (b.dotOpacity - a.dotOpacity) * t,+ dotScale: a.dotScale + (b.dotScale - a.dotScale) * t,+ };+}++export interface RadioTransitionOptions {+ theme?: Partial<RemocnTheme>;+ mode?: "light" | "dark";+ primary?: string;+ speed?: number;+ defaultDuration?: number;+}++/**+ * Timeline → resolved (eased, tweened) RadioStyle. The CALLER invokes this;+ * it reads the frame, the `<Radio>` component does not. Feed the result to+ * `<Radio style={...} />` for smooth check/uncheck transitions.+ */+export function useRadioTransition(+ steps: Step<RadioState>[],+ opts: RadioTransitionOptions = {},+): RadioStyle {+ const {+ theme: themeOverride,+ mode,+ primary,+ speed = 1,+ defaultDuration = DEFAULT_DURATION,+ } = opts;+ const theme = useRemocnTheme(+ { ...themeOverride, ...(primary ? { primary } : {}) },+ mode,+ );+ const ctx = radioStyleContext(theme);+ const { from, to, progress } = useStateTransition(+ steps,+ "unchecked",+ speed,+ defaultDuration,+ );+ const t = easings.out(progress);+ return tweenRadioStyle(radioStyle(from, ctx), radioStyle(to, ctx), t);+}diff --git a/registry/remocn-ui/registry.json b/registry/remocn-ui/registry.jsonindex 2b96ad07..313019d8 100644--- a/registry/remocn-ui/registry.json+++ b/registry/remocn-ui/registry.json@@ -136,6 +136,46 @@"target": "components/remocn/use-checkbox-transition.ts"}]+ },+ {+ "name": "radio",+ "type": "registry:component",+ "title": "UI Radio",+ "description": "A radio whose checked/unchecked state is a pure function of the timeline; the ring border and inner dot pop are keyframed presets.",+ "dependencies": ["remotion"],+ "registryDependencies": ["remocn-ui"],+ "files": [+ {+ "path": "radio/index.tsx",+ "type": "registry:component",+ "target": "components/remocn/radio.tsx"+ },+ {+ "path": "radio/use-radio-transition.ts",+ "type": "registry:component",+ "target": "components/remocn/use-radio-transition.ts"+ }+ ]+ },+ {+ "name": "switch",+ "type": "registry:component",+ "title": "UI Switch",+ "description": "A switch whose checked/unchecked state is a pure function of the timeline; the track fill and sliding thumb are keyframed presets.",+ "dependencies": ["remotion"],+ "registryDependencies": ["remocn-ui"],+ "files": [+ {+ "path": "switch/index.tsx",+ "type": "registry:component",+ "target": "components/remocn/switch.tsx"+ },+ {+ "path": "switch/use-switch-transition.ts",+ "type": "registry:component",+ "target": "components/remocn/use-switch-transition.ts"+ }+ ]}]}diff --git a/registry/remocn-ui/switch/__tests__/README.md b/registry/remocn-ui/switch/__tests__/README.mdnew file mode 100644index 00000000..55c21857--- /dev/null+++ b/registry/remocn-ui/switch/__tests__/README.md@@ -0,0 +1,118 @@+# `switch` — verification tests++Pure / deterministic verification for the `switch` component+(`registry/remocn-ui/switch/`). The RENDER path needs Remotion's+`useCurrentFrame()` and cannot run headless, so the render is NOT exercised+here. This suite covers the pieces that ARE pure: `SwitchState` union+membership, `switchConfig.controls.state` wiring, `switchConfig.snippet`+codegen, `switchStyle` presets, and `tweenSwitchStyle` interpolation.++## Animation model — pure snap + opt-in smooth path++Switch ships two complementary paths:++**Snap path** (`state?: SwitchState` prop):+`Switch` is a frame-free pure renderer. The `state` prop drives all visuals.+Each state maps to a complete resting visual via the exported pure function+`switchStyle(state, ctx) => SwitchStyle`. State changes snap instantly — no+tweening inside the component.++**Smooth path** (`style?: SwitchStyle` prop):+Callers opt in to smooth transitions by passing a pre-interpolated `SwitchStyle`+to the `style` prop. The caller — typically `useSwitchTransition` — reads+`useCurrentFrame()` and calls `useStateTransition` from `core/timeline.ts` to+compute `{ from, to, progress }`, then blends the two presets via+`tweenSwitchStyle(from, to, t)`. The `Switch` component itself remains+frame-free; it simply renders whatever `SwitchStyle` it receives.++This design keeps `Switch` pure-testable (no Remotion render context needed)+while still supporting smooth toggle transitions for production use.++## How to run++The repo uses **Bun**, which has a built-in test runner — runs TypeScript+natively, no test-framework dep.++```bash+bun install+bun test registry/remocn-ui/switch/__tests__+```++`switch.test.ts` imports `bun:test` (not `vitest`/`jest`), so no test script+or framework dep is added to `package.json`.++## What is covered++- **`SwitchState` union** — asserts the two states `["unchecked","checked"]`+ are the complete set (via the real `controls.state.options` list from+ `config.ts`).+- **`switchConfig.controls.state`** — the customizer control wiring. Asserts a+ `select` control exists with exactly those two options, default `"checked"`+ (so the preview shows the filled track and slid thumb), and that every option+ is a member of the `SwitchState` union.+- **`switchConfig.snippet`** — REAL pure string builder (high value).+ Asserts: emits `state="<state>"` as a bare JSX prop for every option; NEVER+ emits `steps` or `action`; includes `import { Switch }` from+ `@/components/remocn/switch`; omits default-equal props (`label=""`,+ `size=default`, `mode=light`, `primary=#171717`); EMITS non-default+ `label`/`size`/`mode`/`primary`; structural round-trip (starts with import,+ contains `<Switch`, ends `/>`).+- **`switchStyle` presets** — exported pure `(state, ctx) => SwitchStyle` map.+ A `SwitchStyleContext` is built from `switchStyleContext(defaultLightTheme)`+ — the same call the component makes internally. Asserts per-state numeric+ invariants (thumbOffset) and that `trackBackground` is always a non-empty+ string. Also asserts the key invariant: unchecked has thumbOffset 0 (thumb+ at left); checked has thumbOffset 1 (thumb at right).+- **`tweenSwitchStyle`** — exported pure `(a, b, t) => SwitchStyle`. Asserts:+ at t=0 all numeric fields equal `a`; at t=1 all equal `b`; at t=0.5 the+ numeric field is the exact midpoint (thumbOffset 0→1 gives 0.5).+ `trackBackground` at all t is a non-empty string (the oklch mix value is not+ hardcoded).++**Switch render** is a pure `(style | state) => visual` observable only via+Remotion render, not unit-tested here.++**`useSwitchTransition`** reads `useCurrentFrame()` via `useStateTransition`+inside the hook — that is correct and expected. It is not a render component;+the smooth-path design isolates all frame-reading to the hook, keeping+`Switch` pure.++## Import strategy++`switch.test.ts` imports via **relative paths** and the+**`@/lib/remocn-ui` tsconfig alias**:++- `../index` — relative, for `SwitchState`, `switchStyle`, `switchStyleContext`+- `../use-switch-transition` — relative, for `tweenSwitchStyle`+- `../config` — relative, for `switchConfig`+- `@/lib/remocn-ui` — alias (resolves to `registry/remocn-ui/core/index.ts`),+ for `defaultLightTheme`++Importing `index.tsx` and `use-switch-transition.ts` pulls the `remotion`+module (and React), but neither `switchStyle`, `switchStyleContext`, nor+`tweenSwitchStyle` call `useCurrentFrame()` at import time or at call time —+they are pure value functions. `bun test` resolves tsconfig `paths`, so the+alias works without additional config.++## Determinism grep checklist (run manually; must print NOTHING)++Switch is frame-free. The component must contain **none** of the following:++```bash+grep -nE "useCurrentFrame|useState|useEffect|onClick|onChange|addEventListener|Date\.now|Math\.random" \+ registry/remocn-ui/switch/index.tsx+```++Expected: no output. Any match is a determinism violation.++`use-switch-transition.ts` is the CALLER hook that intentionally reads+`useCurrentFrame()` (via `useStateTransition`). It is not a render component;+the smooth-path design isolates all frame-reading to the hook, keeping+`Switch` pure.++Tier-wide sweep:++```bash+grep -nE "useState|useEffect|onClick|onChange|addEventListener|Date\.now|Math\.random" \+ registry/remocn-ui/switch/index.tsx registry/remocn-ui/core/*.ts+```diff --git a/registry/remocn-ui/switch/__tests__/switch.test.ts b/registry/remocn-ui/switch/__tests__/switch.test.tsnew file mode 100644index 00000000..abaee23a--- /dev/null+++ b/registry/remocn-ui/switch/__tests__/switch.test.ts@@ -0,0 +1,329 @@+/**+ * Verification tests for the PURE / DETERMINISTIC parts of `switch`.+ *+ * Scope:+ * - registry/remocn-ui/switch/index.tsx — SwitchState union membership,+ * switchStyleContext, switchStyle presets+ * - registry/remocn-ui/switch/use-switch-transition.ts — tweenSwitchStyle+ * - registry/remocn-ui/switch/config.ts — switchConfig.controls.state+ * wiring + switchConfig.snippet output (the state → JSX codegen)+ *+ * The render path (index.tsx) is a PURE-STATE model: `(state) => visual`.+ * State changes snap (no tweening inside the component). The smooth-path hook+ * `useSwitchTransition` reads `useCurrentFrame()` via `useStateTransition`+ * internally; it cannot run outside a Remotion render tree. So Switch render+ * is NOT exercised here. The pure-testable surface is the customizer wiring,+ * snippet codegen, style presets, and tween interpolation (below).+ *+ * Runner: Bun's built-in test runner (TypeScript-native, no framework dep).+ * bun test registry/remocn-ui/switch/__tests__+ *+ * --------------------------------------------------------------------------+ * IMPORT STRATEGY+ * --------------------------------------------------------------------------+ * `config.ts` imports `SwitchState` from `@/registry/remocn-ui/switch`+ * and the pieces under test never CALL a Remotion runtime API at import time —+ * `switchConfig` is a plain object; `.snippet` is a pure string builder;+ * `switchStyle` and `tweenSwitchStyle` are pure value functions.+ * We import via RELATIVE paths (matching the existing test suite pattern),+ * annotating each import with the source it corresponds to.+ * --------------------------------------------------------------------------+ */++import { describe, expect, it } from "bun:test";+import {+ type SwitchState,+ switchStyle,+ switchStyleContext,+} from "../index";+import { tweenSwitchStyle } from "../use-switch-transition";+import { switchConfig } from "../config";+import { defaultLightTheme } from "@/lib/remocn-ui";++// ===========================================================================+// Shared fixtures+// ===========================================================================++/**+ * The SwitchState union, enumerated as a runtime list for membership checks.+ * Must stay in sync with `export type SwitchState` in index.tsx.+ */+const VALID_STATES: readonly SwitchState[] = ["unchecked", "checked"];++/** Minimal shape mirroring the customizer's value bag passed to snippet(). */+type SnippetValues = {+ state?: string;+ label?: string;+ size?: string;+ mode?: string;+ primary?: string;+};++const snippet = (values: SnippetValues): string =>+ switchConfig.snippet(values as Record<string, unknown>);++// ===========================================================================+// 1. SwitchState union membership+// ===========================================================================++describe("SwitchState union", () => {+ it("contains exactly the two documented states", () => {+ // We can't enumerate a TS type at runtime, but we can assert the REAL+ // controls.state options match and that all known states are members.+ const control = switchConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ expect(control.options).toEqual(["unchecked", "checked"]);+ });++ it("every VALID_STATES entry is assignable (no typos in the fixture)", () => {+ // Belt-and-suspenders: the fixture array must have exactly 2 entries and+ // match the options list from the real config.+ const control = switchConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ expect(VALID_STATES).toHaveLength(2);+ for (const s of VALID_STATES) {+ expect(control.options).toContain(s);+ }+ });+});++// ===========================================================================+// 2. switchConfig.controls.state — customizer control wiring+// ===========================================================================++describe("switchConfig.controls.state", () => {+ it("is a select control", () => {+ expect(switchConfig.controls.state.type).toBe("select");+ });++ it("has exactly the two SwitchState options in order", () => {+ const control = switchConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ expect(control.options).toEqual(["unchecked", "checked"]);+ });++ it("defaults to 'checked' so the preview shows the filled track and slid thumb", () => {+ const control = switchConfig.controls.state;+ expect(control.default).toBe("checked");+ });++ it("every option is a member of the SwitchState union", () => {+ const control = switchConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ for (const option of control.options) {+ expect(VALID_STATES).toContain(option as SwitchState);+ }+ });+});++// ===========================================================================+// 3. switchConfig.snippet — pure string builder+// State model: snippet emits `state="<state>"` as a bare JSX prop.+// It NEVER emits `steps` or `action`.+// ===========================================================================++describe("switchConfig.snippet: state prop emission", () => {+ it("emits state=\"unchecked\" for the unchecked option", () => {+ expect(snippet({ state: "unchecked" })).toContain('state="unchecked"');+ });++ it("emits state=\"checked\" for the checked option", () => {+ expect(snippet({ state: "checked" })).toContain('state="checked"');+ });++ it("emits the correct state for every control option", () => {+ const control = switchConfig.controls.state;+ if (control.type !== "select") throw new Error("state control must be a select");+ for (const state of control.options) {+ const out = snippet({ state });+ expect(out).toContain(`state="${state}"`);+ }+ });+});++describe("switchConfig.snippet: NEVER emits steps or action", () => {+ it("never emits `steps` in any state", () => {+ for (const state of VALID_STATES) {+ expect(snippet({ state })).not.toContain("steps");+ }+ });++ it("never emits `action` in any state", () => {+ for (const state of VALID_STATES) {+ expect(snippet({ state })).not.toContain("action");+ }+ });+});++describe("switchConfig.snippet: import line", () => {+ it("includes `import { Switch }` from the correct path", () => {+ const out = snippet({ state: "checked" });+ expect(out).toContain('import { Switch }');+ expect(out).toContain('from "@/components/remocn/switch"');+ });+});++describe("switchConfig.snippet: default props are omitted", () => {+ // Defaults: label="", size=default, mode=light, primary=#171717+ const allDefaults = snippet({+ state: "checked",+ label: "",+ size: "default",+ mode: "light",+ primary: "#171717",+ });++ it("omits label when it equals the default (empty string)", () => {+ expect(allDefaults).not.toContain("label=");+ });++ it("omits size when it equals the default 'default'", () => {+ expect(allDefaults).not.toContain("size=");+ });++ it("omits mode when it equals the default 'light'", () => {+ expect(allDefaults).not.toContain("mode=");+ });++ it("omits primary when it equals the default '#171717'", () => {+ expect(allDefaults).not.toContain("primary=");+ });+});++describe("switchConfig.snippet: non-default props are emitted", () => {+ it("emits a non-default label", () => {+ expect(snippet({ state: "checked", label: "Enable notifications" })).toContain('label="Enable notifications"');+ });++ it("emits a non-default size", () => {+ expect(snippet({ state: "checked", size: "lg" })).toContain('size="lg"');+ });++ it("emits a non-default mode", () => {+ expect(snippet({ state: "checked", mode: "dark" })).toContain('mode="dark"');+ });++ it("emits a non-default primary color", () => {+ expect(snippet({ state: "checked", primary: "#6366f1" })).toContain('primary="#6366f1"');+ });+});++describe("switchConfig.snippet: structural round-trip", () => {+ const out = snippet({ state: "checked" });++ it("starts with the import line", () => {+ expect(out.startsWith('import { Switch }')).toBe(true);+ });++ it("contains a <Switch JSX opening", () => {+ expect(out).toContain("<Switch");+ });++ it("ends with a self-closing />", () => {+ expect(out.trimEnd().endsWith("/>")).toBe(true);+ });+});++// ===========================================================================+// 4. switchStyle presets — pure (state, ctx) => SwitchStyle+// switchStyleContext and switchStyle are now exported and frame-free.+// Build one ctx from the default light theme, then assert the+// numeric invariants for both states.+// trackBackground is derived from the theme — asserted non-empty only+// (exact value is an implementation detail of the theme).+// ===========================================================================++const ctx = switchStyleContext(defaultLightTheme);++describe("switchStyle: unchecked state", () => {+ const s = switchStyle("unchecked", ctx);++ it("thumbOffset is 0 (thumb at left / unchecked position)", () => {+ expect(s.thumbOffset).toBe(0);+ });++ it("trackBackground is a non-empty string", () => {+ expect(typeof s.trackBackground).toBe("string");+ expect(s.trackBackground.length).toBeGreaterThan(0);+ });+});++describe("switchStyle: checked state", () => {+ const s = switchStyle("checked", ctx);++ it("thumbOffset is 1 (thumb at right / checked position)", () => {+ expect(s.thumbOffset).toBe(1);+ });++ it("trackBackground is a non-empty string", () => {+ expect(typeof s.trackBackground).toBe("string");+ expect(s.trackBackground.length).toBeGreaterThan(0);+ });+});++describe("switchStyle: invariants — unchecked thumb at left, checked thumb at right", () => {+ it("unchecked has thumbOffset 0 (thumb at left)", () => {+ const s = switchStyle("unchecked", ctx);+ expect(s.thumbOffset).toBe(0);+ });++ it("checked has thumbOffset 1 (thumb at right)", () => {+ const s = switchStyle("checked", ctx);+ expect(s.thumbOffset).toBe(1);+ });+});++// ===========================================================================+// 5. tweenSwitchStyle — pure linear interpolation between two SwitchStyles.+// Numbers lerp linearly; colors via oklch mix → non-empty string at all t.+// Concrete expectations: unchecked→checked for midpoint math.+// unchecked: thumbOffset=0+// checked: thumbOffset=1+// ===========================================================================++describe("tweenSwitchStyle: t=0 returns values equal to `a`", () => {+ const a = switchStyle("unchecked", ctx);+ const b = switchStyle("checked", ctx);+ const r = tweenSwitchStyle(a, b, 0);++ it("thumbOffset equals a.thumbOffset at t=0", () => {+ expect(r.thumbOffset).toBeCloseTo(a.thumbOffset, 10);+ });++ it("trackBackground is a non-empty string at t=0", () => {+ expect(typeof r.trackBackground).toBe("string");+ expect(r.trackBackground.length).toBeGreaterThan(0);+ });+});++describe("tweenSwitchStyle: t=1 returns values equal to `b`", () => {+ const a = switchStyle("unchecked", ctx);+ const b = switchStyle("checked", ctx);+ const r = tweenSwitchStyle(a, b, 1);++ it("thumbOffset equals b.thumbOffset at t=1", () => {+ expect(r.thumbOffset).toBeCloseTo(b.thumbOffset, 10);+ });++ it("trackBackground is a non-empty string at t=1", () => {+ expect(typeof r.trackBackground).toBe("string");+ expect(r.trackBackground.length).toBeGreaterThan(0);+ });+});++describe("tweenSwitchStyle: t=0.5 midpoint numeric lerp (unchecked → checked)", () => {+ // unchecked: thumbOffset=0+ // checked: thumbOffset=1+ const a = switchStyle("unchecked", ctx);+ const b = switchStyle("checked", ctx);+ const r = tweenSwitchStyle(a, b, 0.5);++ it("thumbOffset midpoint: 0 → 1 gives 0.5", () => {+ expect(r.thumbOffset).toBeCloseTo(0.5, 10);+ });++ it("trackBackground is a non-empty string at t=0.5", () => {+ expect(typeof r.trackBackground).toBe("string");+ expect(r.trackBackground.length).toBeGreaterThan(0);+ });+});diff --git a/registry/remocn-ui/switch/config.ts b/registry/remocn-ui/switch/config.tsnew file mode 100644index 00000000..fbf022bc--- /dev/null+++ b/registry/remocn-ui/switch/config.ts@@ -0,0 +1,57 @@+import { type ComponentConfig, FPS, H, W } from "@/lib/customizer-config";+import type { SwitchState } from "@/registry/remocn-ui/switch";++export const switchConfig: ComponentConfig = {+ componentName: "Switch",+ importPath: "@/components/remocn/switch",+ controls: {+ label: { type: "text", default: "", label: "Label" },+ size: {+ type: "select",+ default: "default",+ options: ["sm", "default", "lg"],+ label: "Size",+ },+ state: {+ type: "select",+ // Default to `checked` so the preview shows the filled track + slid thumb.+ default: "checked",+ options: ["unchecked", "checked"],+ label: "State",+ },+ mode: {+ type: "select",+ default: "light",+ options: ["light", "dark"],+ label: "Mode",+ },+ primary: { type: "color", default: "#171717", label: "Primary" },+ },+ durationInFrames: 120,+ fps: FPS,+ compositionWidth: W,+ compositionHeight: H,+ snippet: (values) => {+ const state = (values.state as SwitchState) ?? "checked";+ const label = values.label as string | undefined;+ const size = values.size as string | undefined;+ const mode = values.mode as string | undefined;+ const primary = values.primary as string | undefined;++ const props: string[] = [` state="${state}"`];+ if (label !== undefined && label !== "")+ props.push(` label="${label}"`);+ if (size !== undefined && size !== "default")+ props.push(` size="${size}"`);+ if (mode !== undefined && mode !== "light")+ props.push(` mode="${mode}"`);+ if (primary !== undefined && primary !== "#171717")+ props.push(` primary="${primary}"`);++ return `import { Switch } from "@/components/remocn/switch";++<Switch+${props.join("\n")}+/>`;+ },+};diff --git a/registry/remocn-ui/switch/index.tsx b/registry/remocn-ui/switch/index.tsxnew file mode 100644index 00000000..aec7916e--- /dev/null+++ b/registry/remocn-ui/switch/index.tsx@@ -0,0 +1,178 @@+"use client";++import { type RemocnTheme, useRemocnTheme } from "@/lib/remocn-ui";++export type SwitchState = "unchecked" | "checked";++type SwitchSize = "sm" | "default" | "lg";++export interface SwitchProps {+ /** Current visual state (snap path). State changes snap (no enter-tweens). */+ state?: SwitchState;+ /**+ * Resolved animated visual (smooth path). When provided, takes precedence over+ * `state` — feed it an interpolated `SwitchStyle` from `useSwitchTransition`.+ */+ style?: SwitchStyle;+ /** Optional text label rendered next to the track. */+ label?: string;+ size?: SwitchSize;+ theme?: Partial<RemocnTheme>;+ /** Convenience override for the `primary` theme token — merged into `theme`. */+ primary?: string;+ mode?: "light" | "dark";+ className?: string;+}++const SIZE_STYLES: Record<+ SwitchSize,+ { trackW: number; trackH: number; thumb: number; pad: number; fontSize: number; gap: number }+> = {+ sm: { trackW: 36, trackH: 20, thumb: 16, pad: 2, fontSize: 13, gap: 8 },+ default: { trackW: 44, trackH: 24, thumb: 20, pad: 2, fontSize: 15, gap: 10 },+ lg: { trackW: 52, trackH: 28, thumb: 24, pad: 2, fontSize: 17, gap: 12 },+};++// ===========================================================================+// Switch visual — the COMPLETE animated look for a moment in time. A `state`+// is a named preset of this visual (`switchStyle`); the smooth path feeds an+// interpolated `SwitchStyle` straight through. The component is a pure+// renderer of whichever `SwitchStyle` it receives.+// ===========================================================================++export interface SwitchStyle {+ /** Animated track fill color (a concrete color, never "transparent"). */+ trackBackground: string;+ /**+ * Thumb position fraction 0→1: fraction of `travel` the thumb has slid.+ * 0 = unchecked (left), 1 = checked (right).+ */+ thumbOffset: number;+}++/** Concrete colors for the active theme, resolved once per render. */+export interface SwitchStyleContext {+ uncheckedTrack: string;+ checkedTrack: string;+ /** Static thumb fill color (never animated). */+ thumbColor: string;+}++/**+ * Derive the concrete colors for a theme. Pure — call it once and reuse the+ * result for every `switchStyle(state, ctx)` preset.+ */+export function switchStyleContext(theme: RemocnTheme): SwitchStyleContext {+ return {+ uncheckedTrack: theme.input,+ checkedTrack: theme.primary,+ thumbColor: theme.background,+ };+}++/**+ * The COMPLETE resting visual for a state — a pure `(state, ctx) => SwitchStyle`+ * map. To change how a state looks, edit one entry.+ */+export function switchStyle(+ state: SwitchState,+ ctx: SwitchStyleContext,+): SwitchStyle {+ switch (state) {+ case "checked":+ return {+ trackBackground: ctx.checkedTrack,+ thumbOffset: 1,+ };+ default:+ return {+ trackBackground: ctx.uncheckedTrack,+ thumbOffset: 0,+ };+ }+}++export function Switch({+ state = "unchecked",+ style,+ label,+ size = "default",+ theme: themeOverride,+ primary,+ mode,+ className,+}: SwitchProps) {+ const theme = useRemocnTheme(+ { ...themeOverride, ...(primary ? { primary } : {}) },+ mode,+ );++ const sizeStyle = SIZE_STYLES[size];+ const ctx = switchStyleContext(theme);+ const v = style ?? switchStyle(state, ctx);++ const travel = sizeStyle.trackW - sizeStyle.thumb - sizeStyle.pad * 2;++ return (+ <div+ style={{+ position: "absolute",+ inset: 0,+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ background: theme.background,+ fontFamily:+ "var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif",+ }}+ >+ <span+ className={className}+ style={{+ display: "inline-flex",+ alignItems: "center",+ gap: sizeStyle.gap,+ }}+ >+ {/* The track — animated fill; the thumb slides inside it. */}+ <span+ style={{+ position: "relative",+ display: "flex",+ alignItems: "center",+ width: sizeStyle.trackW,+ height: sizeStyle.trackH,+ borderRadius: sizeStyle.trackH / 2,+ background: v.trackBackground,+ }}+ >+ {/* The thumb — translates horizontally by thumbOffset * travel. */}+ <span+ style={{+ position: "absolute",+ left: sizeStyle.pad,+ width: sizeStyle.thumb,+ height: sizeStyle.thumb,+ borderRadius: "50%",+ background: ctx.thumbColor,+ boxShadow: "0 1px 2px rgba(0,0,0,0.15)",+ transform: `translateX(${v.thumbOffset * travel}px)`,+ }}+ />+ </span>+ {label !== undefined && (+ <span+ style={{+ fontSize: sizeStyle.fontSize,+ fontWeight: 500,+ letterSpacing: "-0.01em",+ color: theme.foreground,+ }}+ >+ {label}+ </span>+ )}+ </span>+ </div>+ );+}diff --git a/registry/remocn-ui/switch/use-switch-transition.ts b/registry/remocn-ui/switch/use-switch-transition.tsnew file mode 100644index 00000000..054f344c--- /dev/null+++ b/registry/remocn-ui/switch/use-switch-transition.ts@@ -0,0 +1,71 @@+"use client";++import {+ easings,+ mixOklch,+ type RemocnTheme,+ type Step,+ useRemocnTheme,+ useStateTransition,+} from "@/lib/remocn-ui";+import {+ switchStyle,+ switchStyleContext,+ type SwitchState,+ type SwitchStyle,+} from "@/components/remocn/switch";+// ^ install path; resolves in-repo via the @/components/remocn/* tsconfig alias.++/** Default transition length (frames) when a step omits `duration`. Tune to taste. */+export const DEFAULT_DURATION = 10;++/** Blend two switch visuals: numbers lerp, colors via oklch mix. */+export function tweenSwitchStyle(+ a: SwitchStyle,+ b: SwitchStyle,+ t: number,+): SwitchStyle {+ return {+ trackBackground: mixOklch(a.trackBackground, b.trackBackground, t),+ thumbOffset: a.thumbOffset + (b.thumbOffset - a.thumbOffset) * t,+ };+}++export interface SwitchTransitionOptions {+ theme?: Partial<RemocnTheme>;+ mode?: "light" | "dark";+ primary?: string;+ speed?: number;+ defaultDuration?: number;+}++/**+ * Timeline → resolved (eased, tweened) SwitchStyle. The CALLER invokes this;+ * it reads the frame, the `<Switch>` component does not. Feed the result to+ * `<Switch style={...} />` for smooth toggle transitions.+ */+export function useSwitchTransition(+ steps: Step<SwitchState>[],+ opts: SwitchTransitionOptions = {},+): SwitchStyle {+ const {+ theme: themeOverride,+ mode,+ primary,+ speed = 1,+ defaultDuration = DEFAULT_DURATION,+ } = opts;+ const theme = useRemocnTheme(+ { ...themeOverride, ...(primary ? { primary } : {}) },+ mode,+ );+ const ctx = switchStyleContext(theme);+ const { from, to, progress } = useStateTransition(+ steps,+ "unchecked",+ speed,+ defaultDuration,+ );+ const t = easings.out(progress);+ return tweenSwitchStyle(switchStyle(from, ctx), switchStyle(to, ctx), t);+}