Animotion Documentation
repository·main·Indexed 23 days ago
https://github.com/animotionjs/animotionA presentational framework for creating high-quality slides and code visualizations using Svelte, Reveal.js, and Tailwind CSS. It features a specialized Code component for animated code snippets with Magic Move transitions, supporting programmatic updates, insertions, removals, and line selections via a dedicated API.
What's inside Animotion
- Animotion is a presentational framework designed for creating beautiful slides and visualizing ideas using code. It leverages Svelte, Reveal.js, and Tailwind CSS to provide a powerful stack for code-driven presentations.
Install Animotion via CLI
mainThe fastest way to initialize a new Animotion project is by using the
npm createcommand. This will scaffold a new project using the latest version of the Animotion generator.npm create @animotion@latestInstall Animotion on Windows
mainIf the standard Animotion CLI command fails to execute on a Windows environment, use
npxto run the creation tool directly.npx @animotion/createInsert code at a specific line
mainUse the
insertmethod to add code at a specific position. The input string should follow the format:<lineNumber>:<indentLevel> <codeContent>.lineNumber: 1-indexed.indentLevel: Optional. Number of indentation levels (tabs or spaces based on existing code).
Example: To insert
const a = 1;at line 5 with 2 levels of indentation:codeRef.insert`5:2 const a = 1;`Remove lines by number or range
mainThe
removemethod allows you to delete lines from the current code block using various syntax patterns:- Single line:
`5` - Range:
`5-7` - Multiple lines:
`5,7,9` - Combinations:
`5,7-10`
Example:
// Removes lines 5 through 7 codeRef.remove`5-7`- Single line:
Manage global presentation state with setPresentation and getPresentation
mainAnimotion provides a mechanism to store and access the global
RevealApiinstance across your application. This is useful for controlling presentation state (like slides) from different components.- Use
setPresentation(reveal: RevealApi)to initialize the global state with aReveal.jsAPI instance. - Use
getPresentation()to retrieve a reactive object that exposes the currentslidesstate.
- Use
Animate code changes with the Code component API
mainThe
Codecomponent exports several methods to transform the currently displayed code with smooth animations. These methods typically use tagged template literals.Transformation Methods
update(strings, ...expressions): Replaces the current code with new code.append(strings, ...expressions): Appends new code to the end of the current code.insert(strings, ...expressions): Inserts code at a specific line. Format:`line:indent code`(e.g.,`5:2 const y = 2;`).remove(strings, ...expressions): Removes lines by number. Supports single lines (5), ranges (5-7), or lists (5,7,9).replace(from, to): Finds a specific code pattern and replaces it with new content.
Selection Methods
selectLines(strings, ...expressions): Highlights specific lines. Supports ranges like`1-5, 10`.selectLinesAdd(strings, ...expressions): Adds lines to the current selection without deselecting others.select(strings, ...expressions): Highlights tokens matching a pattern. Supports filtering by line or index:`pattern :index`or`line pattern`.selectAdd(strings, ...expressions): Adds matching tokens to the current selection.scrollToLine(strings, ...expressions): Smoothly scrolls the container to make a specific line visible.
Example: Updating and Selecting
<script> let codeRef; </script> <Code bind:this={codeRef} code="console.log('hello')" lang="ts" /> <button on:click={() => codeRef.update`console.log('world')`}> Update </button> <button on:click={() => codeRef.selectLines`1-1`}> Highlight Line 1 </button><Code bind:this={self} code={codes[0]} {lang} {theme} {options} {autoIndent} {...props} />Use the Code component for animated code snippets
mainThe
Codecomponent is used to display and format code snippets in slides with smooth transitions (Magic Move). It supports single code blocks or an array of code blocks that can be navigated like steps in a presentation.Props
code: The initial code string to display.codes: An array of code strings. If provided, the component renders a sequence of code blocks that can be navigated using theActioncomponent (which provides undo/redo functionality).lang: The language for syntax highlighting (e.g.,ts,python).theme: The Shiki theme to use (defaults topoimandres).options: Configuration for@shikijs/magic-move(e.g.,lineNumbers).autoIndent: Automatically removes common leading indentation (defaults totrue).class: Additional CSS classes for the container.
Import Animotion components
mainThe Animotion library provides a suite of Svelte components for building presentations, animations, and interactive code displays. You can import these components from the main component entrypoint to build your UI.
import { Action, Code, Embed, Notes, Presentation, Recorder, Slide, Slides, Transition } from './lib/components';Access presentation state with getPresentation
mainUsegetPresentationto retrieve the current presentation state from the Animotion store.Define component props with defineProps
mainUsedefinePropsto define the properties for your Animotion components. This is imported from the main entrypoint.