ui-visual-engine
v0.1.2
Published
JSON-driven, narration-synchronized animated lesson player for React (cinematic and scrolling modes).
Readme
ui-visual-engine
A JSON-driven animated lesson player for React. You send a lesson as JSON plus narration audio (files, links or in-memory blobs, whole or in chunks). It plays as a video-like lesson (cinematic) or a growing scrolling page (vertical), with the visuals synced to the voice.
Install
# from the public npm registry
npm i ui-visual-engine
# or from a packed file / folder
npm i ./ui-visual-engine-0.1.2.tgzPeer dependencies: react and react-dom >=18.2 and <20.
Use
import { useMemo } from 'react';
import { VisualPlayer } from 'ui-visual-engine';
import 'ui-visual-engine/style.css';
export function Lesson() {
const source = useMemo(() => ({ url: '/lessons/my-lesson/lesson.json' }), []);
return (
<div style={{ height: '100vh' }}>
<VisualPlayer source={source} />
</div>
);
}- The player fills its parent, so give the parent a height.
- Memoize
source: a new object reloads the lesson.
Responsive by design (0.1.1)
The player sizes itself from its parent element, never the window. Give the parent a size; everything inside follows it, live, even while a lesson is playing.
<div style={{ width: '100%', height: '70dvh' }}> {/* any size: page, card, sidebar, modal */}
<VisualPlayer source={source} options={{ presentation: { mode: 'auto' } }} />
</div>mode: 'auto'picks cinematic for roomy landscape boxes and the scrolling page for small, narrow or short boxes, and switches live when the box changes (with hysteresis, and playback keeps going). A learner's own choice with the mode button wins.- Text, controls, overlays and icons scale with the player (
--vle-u, container units); no fixed pixel sizes or viewport units are used inside the player. - Diagrams measure their own box and pick the first readable arrangement: the authored layout, its portrait layout, then automatic snaking grids. Sideways panning is a last resort.
- List-item highlights light the item's text (no full-width boxes);
release: trueturns each off after its sentence. - Floating buttons never cover content: "Enlarge" sits under drawings on reading pages, and the "Follow narration" pill gives way to the control-bar button when there is no side gutter.
Sources
{ url: 'https://cdn.example.com/lessons/x/lesson.json' } // link
{ lesson: jsonObject } // direct JSON
{ json: jsonText } // JSON string
{ file: fileOrBlob } // local file
{ lesson, assets: { 'audio/s1-1.mp3': ttsBlob } } // in-memory voice/images
{ lesson, streaming: true } // more scenes follow (engine.appendScenes)Options you'll usually set:
<VisualPlayer
source={source}
options={{ allowedOrigins: ['https://cdn.example.com'], presentation: { mode: 'vertical' }, dev: true }}
onEngine={(engine) => { /* engine.appendScenes(...), engine.finishStream(), engine.play() … */ }}
/>Voice in chunks (no timing maths)
"narration": { "chunks": [
{ "id": "c1", "src": "audio/s1-1.mp3", "text": "First sentence." },
{ "id": "c2", "src": "audio/s1-2.mp3", "text": "Second sentence." }
] }The player measures each file, plays the chunks in order, and syncs animations
("at": { "cue": "c2" }) and captions to them.
Documentation (included in this package)
docs/SETUP_GUIDE.md: setup, the full API, the content pipeline (LLM → JSON → TTS → player), streaming, deployment, troubleshooting.docs/LESSON_AUTHORING_GUIDE.md: the lesson JSON format, effects, layouts, quality rules, and the LLM generation prompt.docs/VISUAL_ENGINE.md: architecture and extension points (custom renderers, effects, themes, layouts, presentation modes).
Notes
- ESM-only package. The packed artifact is checked with React 18.3.1, TypeScript and Vite. Next.js, webpack and React 19 compatibility have not yet been verified.
- Use it in a browser component only. With Next.js, add
'use client'. - GSAP is distributed under GSAP's own no-charge license.
Build and verify (from the repository root)
npm run test:package # build, pack, check strict consumer types and Vite build
npm run pack:package # build automatically and create the .tgzPacking and publishing from this repository automatically builds the package first.
The package is configured for public npm access. Build, check and pack commands do not publish it.
To release version 0.1.2, run npm publish from this package directory after verification.
