@hyperframes/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -0
- package/dist/adapters/gsap.d.ts +14 -0
- package/dist/adapters/gsap.d.ts.map +1 -0
- package/dist/adapters/gsap.js +25 -0
- package/dist/adapters/gsap.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/types.d.ts +15 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/compiler/htmlBundler.d.ts +16 -0
- package/dist/compiler/htmlBundler.d.ts.map +1 -0
- package/dist/compiler/htmlBundler.js +448 -0
- package/dist/compiler/htmlBundler.js.map +1 -0
- package/dist/compiler/htmlCompiler.d.ts +18 -0
- package/dist/compiler/htmlCompiler.d.ts.map +1 -0
- package/dist/compiler/htmlCompiler.js +65 -0
- package/dist/compiler/htmlCompiler.js.map +1 -0
- package/dist/compiler/index.d.ts +5 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +9 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/staticGuard.d.ts +8 -0
- package/dist/compiler/staticGuard.d.ts.map +1 -0
- package/dist/compiler/staticGuard.js +26 -0
- package/dist/compiler/staticGuard.js.map +1 -0
- package/dist/compiler/timingCompiler.d.ts +72 -0
- package/dist/compiler/timingCompiler.d.ts.map +1 -0
- package/dist/compiler/timingCompiler.js +191 -0
- package/dist/compiler/timingCompiler.js.map +1 -0
- package/dist/core.types.d.ts +314 -0
- package/dist/core.types.d.ts.map +1 -0
- package/dist/core.types.js +52 -0
- package/dist/core.types.js.map +1 -0
- package/dist/generators/hyperframes.d.ts +21 -0
- package/dist/generators/hyperframes.d.ts.map +1 -0
- package/dist/generators/hyperframes.js +572 -0
- package/dist/generators/hyperframes.js.map +1 -0
- package/dist/hyperframe.manifest.json +22 -0
- package/dist/hyperframe.runtime.iife.js +13 -0
- package/dist/hyperframe.runtime.mjs +13 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/inline-scripts/hyperframe.d.ts +13 -0
- package/dist/inline-scripts/hyperframe.d.ts.map +1 -0
- package/dist/inline-scripts/hyperframe.js +15 -0
- package/dist/inline-scripts/hyperframe.js.map +1 -0
- package/dist/inline-scripts/hyperframesRuntime.engine.d.ts +7 -0
- package/dist/inline-scripts/hyperframesRuntime.engine.d.ts.map +1 -0
- package/dist/inline-scripts/hyperframesRuntime.engine.js +31 -0
- package/dist/inline-scripts/hyperframesRuntime.engine.js.map +1 -0
- package/dist/inline-scripts/parityContract.d.ts +5 -0
- package/dist/inline-scripts/parityContract.d.ts.map +1 -0
- package/dist/inline-scripts/parityContract.js +43 -0
- package/dist/inline-scripts/parityContract.js.map +1 -0
- package/dist/inline-scripts/pickerApi.d.ts +32 -0
- package/dist/inline-scripts/pickerApi.d.ts.map +1 -0
- package/dist/inline-scripts/pickerApi.js +2 -0
- package/dist/inline-scripts/pickerApi.js.map +1 -0
- package/dist/inline-scripts/runtimeContract.d.ts +14 -0
- package/dist/inline-scripts/runtimeContract.d.ts.map +1 -0
- package/dist/inline-scripts/runtimeContract.js +21 -0
- package/dist/inline-scripts/runtimeContract.js.map +1 -0
- package/dist/lint/hyperframeLinter.d.ts +3 -0
- package/dist/lint/hyperframeLinter.d.ts.map +1 -0
- package/dist/lint/hyperframeLinter.js +621 -0
- package/dist/lint/hyperframeLinter.js.map +1 -0
- package/dist/lint/index.d.ts +3 -0
- package/dist/lint/index.d.ts.map +1 -0
- package/dist/lint/index.js +2 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/lint/types.d.ts +21 -0
- package/dist/lint/types.d.ts.map +1 -0
- package/dist/lint/types.js +2 -0
- package/dist/lint/types.js.map +1 -0
- package/dist/parsers/gsapParser.d.ts +50 -0
- package/dist/parsers/gsapParser.d.ts.map +1 -0
- package/dist/parsers/gsapParser.js +411 -0
- package/dist/parsers/gsapParser.js.map +1 -0
- package/dist/parsers/htmlParser.d.ts +29 -0
- package/dist/parsers/htmlParser.d.ts.map +1 -0
- package/dist/parsers/htmlParser.js +726 -0
- package/dist/parsers/htmlParser.js.map +1 -0
- package/dist/templates/base.d.ts +4 -0
- package/dist/templates/base.d.ts.map +1 -0
- package/dist/templates/base.js +20 -0
- package/dist/templates/base.js.map +1 -0
- package/dist/templates/constants.d.ts +7 -0
- package/dist/templates/constants.d.ts.map +1 -0
- package/dist/templates/constants.js +8 -0
- package/dist/templates/constants.js.map +1 -0
- package/docs/common-mistakes.md +73 -0
- package/docs/core.md +532 -0
- package/docs/core_notes.md +61 -0
- package/docs/quickstart-template.html +180 -0
- package/docs/versions/changelog.md +5 -0
- package/docs/versions/v0.1/core.md +326 -0
- package/package.json +83 -0
package/docs/core.md
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
# HyperFrames Schema
|
|
2
|
+
|
|
3
|
+
Reference for generating and editing HyperFrames HTML compositions. This is your source of truth for how to author compositions.
|
|
4
|
+
|
|
5
|
+
**New to HyperFrames?** Start with the [quickstart template](./quickstart-template.html) — a copy-paste composition with inline comments explaining every required piece. See [common mistakes](./common-mistakes.md) for pitfalls that break compositions.
|
|
6
|
+
|
|
7
|
+
For Frame adapters and deterministic frame rendering direction, see [`../../FRAME.md`](../../FRAME.md) and [`../adapters/README.md`](../adapters/README.md).
|
|
8
|
+
|
|
9
|
+
Producer-canonical parity note:
|
|
10
|
+
|
|
11
|
+
- Producer render behavior is the source of truth for deterministic parity.
|
|
12
|
+
- Preview should emulate producer seek semantics (`renderSeek`, frame quantization, readiness gates) in parity mode.
|
|
13
|
+
- Non-parity smooth playback can exist, but parity mode is the correctness baseline.
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
HyperFrames uses HTML as the source of truth for describing a video:
|
|
18
|
+
|
|
19
|
+
- **HTML clips** = video, image, audio, composition
|
|
20
|
+
- **Data attributes** = timing, metadata, styling
|
|
21
|
+
- **CSS** = positioning and appearance
|
|
22
|
+
- **GSAP timeline** = animations and playback sync
|
|
23
|
+
|
|
24
|
+
### Framework-Managed Behavior
|
|
25
|
+
|
|
26
|
+
The framework reads data attributes and automatically manages:
|
|
27
|
+
|
|
28
|
+
- **Primitive clip timeline entries** — the framework reads `data-start`, `data-duration`, and `data-track-index` from primitive clips and adds them to the composition's GSAP timeline. You do not manually add primitive clips to the timeline in scripts.
|
|
29
|
+
- **Media playback** (play, pause, seek) for `<video>` and `<audio>`
|
|
30
|
+
- **Clip lifecycle** — clips are **mounted** (made visible on screen) and **unmounted** (removed from screen) based on `data-start` and `data-duration`
|
|
31
|
+
- **Timeline synchronization** (keeping media in sync with the GSAP master timeline)
|
|
32
|
+
- **Media loading** — the framework waits for all media elements to load before resolving timing and starting playback
|
|
33
|
+
|
|
34
|
+
Mounting and unmounting controls **presence**, not appearance. A clip that is mounted is on screen; a clip that is unmounted is not. Transitions (fade in, slide in, etc.) are separate — they are animated in scripts and happen _after_ a clip is mounted or _before_ it is unmounted.
|
|
35
|
+
|
|
36
|
+
The framework does **not** handle transitions, effects, or visual animation — those are driven by GSAP in JavaScript.
|
|
37
|
+
|
|
38
|
+
Do not manually call `video.play()`, `video.pause()`, set `audio.currentTime`, or mount/unmount clips in scripts. The framework owns media playback and clip lifecycle. Animating visual properties like `opacity` or `transform` for transitions is fine — that's what scripts are for.
|
|
39
|
+
|
|
40
|
+
## Viewport
|
|
41
|
+
|
|
42
|
+
Every composition must include `data-width` and `data-height` so scripts and CSS can reference concrete pixel dimensions for layout. Common sizes:
|
|
43
|
+
|
|
44
|
+
- **Landscape**: `data-width="1920" data-height="1080"`
|
|
45
|
+
- **Portrait**: `data-width="1080" data-height="1920"`
|
|
46
|
+
|
|
47
|
+
e.g.,
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<div id="main" data-composition-id="my-video" data-start="0" data-width="1920" data-height="1080">
|
|
51
|
+
<!-- clips -->
|
|
52
|
+
</div>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Every composition's container is full-screen within the viewport by default. The framework applies full-screen sizing to composition containers automatically.
|
|
56
|
+
|
|
57
|
+
To position or size individual clips (e.g., picture-in-picture, overlay placement), use standard CSS on the element.
|
|
58
|
+
|
|
59
|
+
## Compositions
|
|
60
|
+
|
|
61
|
+
A composition is the fundamental grouping unit in HyperFrames. Every clip — video, image, audio — must live inside a composition. The `index.html` file is itself a composition (the top-level one), and it can contain nested compositions within it. Any composition can be imported into another composition as a sub-composition — there is no special "root" type.
|
|
62
|
+
|
|
63
|
+
A composition carries the same core attributes as any other clip (`id`, `data-start`, `data-track-index`), so it can be placed and timed on a timeline just like a video or image. A composition's length is determined by its GSAP timeline — there is no `data-duration` on compositions. This means compositions can be nested: a composition clip inside another composition behaves like a self-contained video within the parent timeline.
|
|
64
|
+
|
|
65
|
+
### Composition File Structure
|
|
66
|
+
|
|
67
|
+
**Each composition should be defined in its own HTML file.** This keeps compositions modular, reusable, and maintainable. The file contains the complete composition: HTML structure, inline styles, and script.
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
project/
|
|
71
|
+
├── index.html # Root composition
|
|
72
|
+
├── compositions/
|
|
73
|
+
│ ├── intro-anim.html # Intro animation composition
|
|
74
|
+
│ ├── caption-overlay.html # Caption composition
|
|
75
|
+
│ └── outro-title.html # Outro composition
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Composition file format** (`compositions/intro-anim.html`):
|
|
79
|
+
|
|
80
|
+
```html
|
|
81
|
+
<!-- Define the composition as a template that can be loaded -->
|
|
82
|
+
<template id="intro-anim-template">
|
|
83
|
+
<div data-composition-id="intro-anim" data-width="1920" data-height="1080">
|
|
84
|
+
<div class="title">Welcome!</div>
|
|
85
|
+
<div class="subtitle">Let's get started</div>
|
|
86
|
+
|
|
87
|
+
<style>
|
|
88
|
+
[data-composition-id="intro-anim"] .title {
|
|
89
|
+
font-size: 72px;
|
|
90
|
+
color: white;
|
|
91
|
+
text-align: center;
|
|
92
|
+
}
|
|
93
|
+
[data-composition-id="intro-anim"] .subtitle {
|
|
94
|
+
font-size: 36px;
|
|
95
|
+
color: #ccc;
|
|
96
|
+
text-align: center;
|
|
97
|
+
}
|
|
98
|
+
</style>
|
|
99
|
+
|
|
100
|
+
<script>
|
|
101
|
+
const tl = gsap.timeline({ paused: true });
|
|
102
|
+
tl.from(".title", { opacity: 0, y: -50, duration: 1 });
|
|
103
|
+
tl.from(".subtitle", { opacity: 0, y: 50, duration: 1 }, 0.5);
|
|
104
|
+
window.__timelines["intro-anim"] = tl;
|
|
105
|
+
</script>
|
|
106
|
+
</div>
|
|
107
|
+
</template>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Loading Compositions
|
|
111
|
+
|
|
112
|
+
Use the `data-composition-src` attribute to load a composition from an external HTML file. The framework will automatically fetch the template and instantiate it:
|
|
113
|
+
|
|
114
|
+
```html
|
|
115
|
+
<div id="comp-1" data-composition-id="my-video" data-start="0" data-width="1920" data-height="1080">
|
|
116
|
+
<!-- Primitive clips -->
|
|
117
|
+
<video id="el-1" data-start="0" data-duration="10" data-track-index="0" src="..."></video>
|
|
118
|
+
<video id="el-2" data-start="el-1" data-duration="8" data-track-index="0" src="..."></video>
|
|
119
|
+
<img id="el-3" data-start="5" data-duration="4" data-track-index="1" src="..." />
|
|
120
|
+
<audio id="el-4" data-start="0" data-duration="30" data-track-index="2" src="..." />
|
|
121
|
+
|
|
122
|
+
<!-- Load composition from external file -->
|
|
123
|
+
<div
|
|
124
|
+
id="el-5"
|
|
125
|
+
data-composition-id="intro-anim"
|
|
126
|
+
data-composition-src="compositions/intro-anim.html"
|
|
127
|
+
data-start="0"
|
|
128
|
+
data-track-index="3"
|
|
129
|
+
></div>
|
|
130
|
+
|
|
131
|
+
<!-- Another loaded composition -->
|
|
132
|
+
<div
|
|
133
|
+
id="el-6"
|
|
134
|
+
data-composition-id="captions"
|
|
135
|
+
data-composition-src="compositions/caption-overlay.html"
|
|
136
|
+
data-start="0"
|
|
137
|
+
data-track-index="4"
|
|
138
|
+
></div>
|
|
139
|
+
</div>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The framework will:
|
|
143
|
+
|
|
144
|
+
1. Fetch the HTML file specified in `data-composition-src`
|
|
145
|
+
2. Extract the `<template>` content
|
|
146
|
+
3. Clone and mount it into the composition element
|
|
147
|
+
4. Execute any `<script>` tags within the template
|
|
148
|
+
5. Register the timeline in `window.__timelines`
|
|
149
|
+
|
|
150
|
+
### Best Practices for Composition Files
|
|
151
|
+
|
|
152
|
+
**Use separate HTML files when:**
|
|
153
|
+
|
|
154
|
+
- The composition is reusable across multiple projects or scenes
|
|
155
|
+
- The composition has complex logic, styling, or structure (>20 lines)
|
|
156
|
+
- You want to keep the main `index.html` clean and focused on orchestration
|
|
157
|
+
- The composition represents a distinct functional unit (captions, titles, animations)
|
|
158
|
+
|
|
159
|
+
**Use inline compositions when:**
|
|
160
|
+
|
|
161
|
+
- The composition is truly one-off and project-specific
|
|
162
|
+
- The composition is very simple (<10 lines total)
|
|
163
|
+
- You're prototyping and iterating quickly
|
|
164
|
+
|
|
165
|
+
**File naming conventions:**
|
|
166
|
+
|
|
167
|
+
- Use kebab-case: `intro-anim.html`, `caption-overlay.html`, `emoji-burst.html`
|
|
168
|
+
- Name files descriptively based on their purpose or visual function
|
|
169
|
+
- Group related compositions in subdirectories if you have many: `compositions/titles/`, `compositions/overlays/`
|
|
170
|
+
|
|
171
|
+
## Clip Types
|
|
172
|
+
|
|
173
|
+
A clip is any discrete block on the timeline. We represent clips as HTML elements and apply data-attributes to describe them.
|
|
174
|
+
|
|
175
|
+
- `<video>` — Video clips, B-roll, A-roll
|
|
176
|
+
- `<img>` — Static images, overlays
|
|
177
|
+
- `<audio>` — Music, sound effects
|
|
178
|
+
- `<div data-composition-id="...">` — Nested compositions (animations, grouped sequences)
|
|
179
|
+
|
|
180
|
+
## HTML Attributes
|
|
181
|
+
|
|
182
|
+
### All Clips
|
|
183
|
+
|
|
184
|
+
- `id` — Unique identifier (e.g., "el-1")
|
|
185
|
+
- `data-start` — Start time in seconds, or a clip `id` reference. See [Relative Timing](#relative-timing).
|
|
186
|
+
- `data-duration` — Duration in seconds. Required for `<img>` clips. Optional for `<video>` and `<audio>` (defaults to the source media's full duration). Not used on compositions.
|
|
187
|
+
- `data-track-index` — Timeline track number. Tracks serve two purposes: they determine visual layering (higher tracks render in front) and they group clips into rows on the timeline. Clips on the same track **cannot overlap in time**.
|
|
188
|
+
|
|
189
|
+
### Media Clips (video, audio)
|
|
190
|
+
|
|
191
|
+
- `data-media-start` — (optional) Playback begins at this time in the source file, in seconds. Defaults to `0`.
|
|
192
|
+
|
|
193
|
+
### Composition Clips
|
|
194
|
+
|
|
195
|
+
- `data-composition-id` — Unique composition ID
|
|
196
|
+
- `data-composition-src` — (optional) Path to external HTML file containing the composition template. The framework will fetch, instantiate, and mount the template automatically.
|
|
197
|
+
|
|
198
|
+
> Compositions do **not** use `data-duration`. Their duration is determined by their GSAP timeline.
|
|
199
|
+
|
|
200
|
+
## Relative Timing
|
|
201
|
+
|
|
202
|
+
Instead of calculating absolute start times, a clip can reference another clip's `id` in its `data-start` attribute. This means "start when that clip ends." The referenced clip must be in the same composition and must have a known duration (either an explicit `data-duration` or an inferred duration from the source media).
|
|
203
|
+
|
|
204
|
+
### Basic Sequential Clips
|
|
205
|
+
|
|
206
|
+
```html
|
|
207
|
+
<video id="intro" data-start="0" data-duration="10" data-track-index="0" src="..."></video>
|
|
208
|
+
<video id="main" data-start="intro" data-duration="20" data-track-index="0" src="..."></video>
|
|
209
|
+
<video id="outro" data-start="main" data-duration="5" data-track-index="0" src="..."></video>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`main` resolves to second 10, `outro` resolves to second 30. If `intro`'s duration changes to 15, `main` and `outro` shift automatically.
|
|
213
|
+
|
|
214
|
+
### Offsets (gaps and overlaps)
|
|
215
|
+
|
|
216
|
+
Add `+ N` or `- N` after the ID to offset from the end of the referenced clip:
|
|
217
|
+
|
|
218
|
+
```html
|
|
219
|
+
<!-- intro ends at 10. "intro + 2" = 10 + 2 = starts at second 12 (2s gap) -->
|
|
220
|
+
<video id="scene-a" data-start="intro + 2" data-duration="20" data-track-index="0" src="..."></video>
|
|
221
|
+
|
|
222
|
+
<!-- intro ends at 10. "intro - 0.5" = 10 - 0.5 = starts at second 9.5 (0.5s overlap for crossfade) -->
|
|
223
|
+
<!-- Different track because clips on the same track cannot overlap -->
|
|
224
|
+
<video id="scene-b" data-start="intro - 0.5" data-duration="20" data-track-index="1" src="..."></video>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Rules
|
|
228
|
+
|
|
229
|
+
- **Same composition only** — references resolve within the clip's parent composition
|
|
230
|
+
- **No circular references** — A cannot start after B if B starts after A
|
|
231
|
+
- **Referenced clip must have a known duration** — the system needs a known end time to resolve the reference (either explicit `data-duration` or inferred from source media)
|
|
232
|
+
- **Parsing** — if the value is a valid number, it is absolute seconds; otherwise it is parsed as `<id>`, `<id> + <number>`, or `<id> - <number>`
|
|
233
|
+
|
|
234
|
+
## Video Clips
|
|
235
|
+
|
|
236
|
+
Full-screen or positioned video clips. Videos sync their playback to the timeline position.
|
|
237
|
+
|
|
238
|
+
```html
|
|
239
|
+
<video
|
|
240
|
+
id="el-1"
|
|
241
|
+
data-start="0"
|
|
242
|
+
data-duration="15"
|
|
243
|
+
data-track-index="0"
|
|
244
|
+
src="./assets/video.mp4"
|
|
245
|
+
></video>
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
- `data-media-start` — Playback begins at this time in the source video file (seconds). Default: `0`.
|
|
249
|
+
- `data-duration` — (optional) How long the clip occupies on the timeline, in seconds. Playback runs from `data-media-start` for up to `data-duration` seconds. If the source media runs out before `data-duration` elapses, playback naturally stops (the clip remains mounted showing the last frame). If omitted, defaults to the remaining duration of the source file from `data-media-start`.
|
|
250
|
+
|
|
251
|
+
## Image Clips
|
|
252
|
+
|
|
253
|
+
Static images that appear for a duration.
|
|
254
|
+
|
|
255
|
+
```html
|
|
256
|
+
<img
|
|
257
|
+
id="el-2"
|
|
258
|
+
data-start="5"
|
|
259
|
+
data-duration="4"
|
|
260
|
+
data-track-index="1"
|
|
261
|
+
src="./assets/video.mp4"
|
|
262
|
+
/>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Audio Clips
|
|
266
|
+
|
|
267
|
+
Background music or sound effects. Audio clips are invisible.
|
|
268
|
+
|
|
269
|
+
```html
|
|
270
|
+
<audio
|
|
271
|
+
id="el-4"
|
|
272
|
+
data-start="0"
|
|
273
|
+
data-duration="30"
|
|
274
|
+
data-track-index="2"
|
|
275
|
+
src="./assets/music.mp3"
|
|
276
|
+
></audio>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
- `data-media-start` — Playback begins at this time in the source audio file (seconds). Default: `0`.
|
|
280
|
+
- `data-duration` — (optional) How long the clip occupies on the timeline, in seconds. Playback runs from `data-media-start` for up to `data-duration` seconds. If the source media runs out before `data-duration` elapses, playback naturally stops (the clip remains mounted but silent). If omitted, defaults to the remaining duration of the source file from `data-media-start`.
|
|
281
|
+
|
|
282
|
+
## Two Layers: Primitives and Scripts
|
|
283
|
+
|
|
284
|
+
Every composition — master or sub — has the same two layers:
|
|
285
|
+
|
|
286
|
+
- **HTML** — primitive clips (`video`, `img`, `audio`, nested `div[data-composition-id]`). This is the declarative structure: what plays, when, and on which track.
|
|
287
|
+
- **Script** — effects, transitions, dynamic DOM, canvas, SVG — creative animation and visuals via GSAP. Scripts do **not** control media playback or clip visibility; the framework handles those via data attributes.
|
|
288
|
+
|
|
289
|
+
Both layers are available to every composition. The schema defines the primitives and the timeline contract; scripts handle visual creativity on top of that.
|
|
290
|
+
|
|
291
|
+
> **Warning:** Never use scripts to play/pause/seek media elements or to show/hide clips based on timing. The framework does this automatically from `data-start`, `data-duration`, and `data-media-start`. Scripts that duplicate this behavior will conflict with the framework.
|
|
292
|
+
|
|
293
|
+
### Script Isolation
|
|
294
|
+
|
|
295
|
+
Each composition's script is scoped to that composition. When a composition is loaded from an external HTML file via `data-composition-src`, its inline `<script>` and `<style>` tags are automatically included and scoped to that composition.
|
|
296
|
+
|
|
297
|
+
**Preferred approach** — Composition in separate HTML file:
|
|
298
|
+
|
|
299
|
+
```html
|
|
300
|
+
<!-- In index.html -->
|
|
301
|
+
<div
|
|
302
|
+
id="el-5"
|
|
303
|
+
data-composition-id="intro-anim"
|
|
304
|
+
data-composition-src="compositions/intro-anim.html"
|
|
305
|
+
data-start="0"
|
|
306
|
+
data-track-index="2"
|
|
307
|
+
></div>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Alternative approach** — External JS file:
|
|
311
|
+
|
|
312
|
+
```html
|
|
313
|
+
<!-- In index.html -->
|
|
314
|
+
<div
|
|
315
|
+
id="el-5"
|
|
316
|
+
data-composition-id="intro-anim"
|
|
317
|
+
data-start="0"
|
|
318
|
+
data-track-index="2"
|
|
319
|
+
data-width="1920"
|
|
320
|
+
data-height="1080"
|
|
321
|
+
>
|
|
322
|
+
<script src="intro-anim.js"></script>
|
|
323
|
+
</div>
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
The separate HTML file approach is preferred because it keeps all composition code (structure, style, script) in one self-contained, reusable file.
|
|
327
|
+
|
|
328
|
+
The only required file is `index.html`. Every composition must have at least a script to create and register its GSAP timeline.
|
|
329
|
+
|
|
330
|
+
### Top-Level Composition
|
|
331
|
+
|
|
332
|
+
The top-level composition is the `index.html` entry point. It acts as the conductor — sequencing clips and placing sub-composition timelines into an overall master timeline. It can technically do anything in its script, but its primary purpose is high-level orchestration. Any composition can serve as a top-level composition or be nested into another — there is no structural difference.
|
|
333
|
+
|
|
334
|
+
```html
|
|
335
|
+
<div id="comp-1" data-composition-id="my-video" data-start="0" data-width="1920" data-height="1080">
|
|
336
|
+
<!-- Primitive clips -->
|
|
337
|
+
<video id="el-1" data-start="0" data-duration="10" data-track-index="0" src="..."></video>
|
|
338
|
+
<video id="el-2" data-start="el-1" data-duration="8" data-track-index="0" src="..."></video>
|
|
339
|
+
<img id="el-3" data-start="5" data-duration="4" data-track-index="1" src="..." />
|
|
340
|
+
<audio id="el-4" data-start="0" data-duration="30" data-track-index="2" src="..." />
|
|
341
|
+
|
|
342
|
+
<!-- Load sub-compositions from external files -->
|
|
343
|
+
<div
|
|
344
|
+
id="el-5"
|
|
345
|
+
data-composition-id="intro-anim"
|
|
346
|
+
data-composition-src="compositions/intro-anim.html"
|
|
347
|
+
data-start="0"
|
|
348
|
+
data-track-index="3"
|
|
349
|
+
></div>
|
|
350
|
+
|
|
351
|
+
<div
|
|
352
|
+
id="el-6"
|
|
353
|
+
data-composition-id="captions"
|
|
354
|
+
data-composition-src="compositions/caption-overlay.html"
|
|
355
|
+
data-start="0"
|
|
356
|
+
data-track-index="4"
|
|
357
|
+
></div>
|
|
358
|
+
|
|
359
|
+
<script>
|
|
360
|
+
// Just register the timeline - framework auto-nests sub-compositions
|
|
361
|
+
const tl = gsap.timeline({ paused: true });
|
|
362
|
+
window.__timelines["my-video"] = tl;
|
|
363
|
+
</script>
|
|
364
|
+
</div>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Sub-Compositions
|
|
368
|
+
|
|
369
|
+
Sub-compositions are a spectrum. One might simply group a few primitive clips. Another might be a fully custom program with its own HTML, CSS, and JavaScript — creating, animating, and destroying DOM however it sees fit. There are no categories or constraints on what a sub-composition does internally. The only rule: it must be driven by a GSAP timeline and export it. If children use `position: absolute`, always set explicit `left`/`top`/`bottom`/`right` — the composition root is a positioned container, so omitting coordinates produces unpredictable placement.
|
|
370
|
+
|
|
371
|
+
## Wrapping Dynamic Content in Compositions
|
|
372
|
+
|
|
373
|
+
**Critical Rule: All visual content must live inside a composition with data attributes to appear in the timeline.**
|
|
374
|
+
|
|
375
|
+
When you have dynamic or script-animated content (captions, emojis, overlays, text animations), wrap them in a composition element with `data-start`, `data-duration` (or let the timeline determine duration), and `data-track-index`. The children inside can be freely created and animated via JavaScript—they don't need individual data attributes.
|
|
376
|
+
|
|
377
|
+
### Wrong: Dynamic content outside a composition
|
|
378
|
+
|
|
379
|
+
```html
|
|
380
|
+
<!-- BAD: captions-container is not a composition - won't appear in timeline -->
|
|
381
|
+
<div id="ui-layer">
|
|
382
|
+
<div id="captions-container">
|
|
383
|
+
<!-- Dynamically created caption groups via JS -->
|
|
384
|
+
</div>
|
|
385
|
+
<div class="emoji" id="emoji-1">🤩</div>
|
|
386
|
+
</div>
|
|
387
|
+
|
|
388
|
+
<script>
|
|
389
|
+
// These animations work visually but elements don't appear in timeline
|
|
390
|
+
tl.to(".caption-group", { opacity: 1 }, 0.5);
|
|
391
|
+
tl.to("#emoji-1", { scale: 1.2 }, 2);
|
|
392
|
+
</script>
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Correct: Dynamic content wrapped in compositions
|
|
396
|
+
|
|
397
|
+
**Preferred approach** — Load from external HTML files:
|
|
398
|
+
|
|
399
|
+
```html
|
|
400
|
+
<!-- GOOD: Each logical group is a composition loaded from its own file -->
|
|
401
|
+
<div
|
|
402
|
+
id="captions-comp"
|
|
403
|
+
data-composition-id="captions"
|
|
404
|
+
data-composition-src="compositions/captions.html"
|
|
405
|
+
data-start="0"
|
|
406
|
+
data-track-index="5"
|
|
407
|
+
></div>
|
|
408
|
+
|
|
409
|
+
<div
|
|
410
|
+
id="emojis-comp"
|
|
411
|
+
data-composition-id="emojis"
|
|
412
|
+
data-composition-src="compositions/emojis.html"
|
|
413
|
+
data-start="0"
|
|
414
|
+
data-track-index="6"
|
|
415
|
+
></div>
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
**Alternative approach** — Inline composition (useful for one-off custom compositions):
|
|
419
|
+
|
|
420
|
+
```html
|
|
421
|
+
<div
|
|
422
|
+
id="captions-comp"
|
|
423
|
+
data-composition-id="captions"
|
|
424
|
+
data-start="0"
|
|
425
|
+
data-track-index="5"
|
|
426
|
+
data-width="1080"
|
|
427
|
+
data-height="1920"
|
|
428
|
+
>
|
|
429
|
+
<!-- Children created/animated by script - no data attributes needed -->
|
|
430
|
+
<div id="captions-container"></div>
|
|
431
|
+
<script>
|
|
432
|
+
const captionTL = gsap.timeline({ paused: true });
|
|
433
|
+
// Dynamically create and animate caption groups...
|
|
434
|
+
window.__timelines["captions"] = captionTL;
|
|
435
|
+
</script>
|
|
436
|
+
</div>
|
|
437
|
+
|
|
438
|
+
<div
|
|
439
|
+
id="emojis-comp"
|
|
440
|
+
data-composition-id="emojis"
|
|
441
|
+
data-start="0"
|
|
442
|
+
data-track-index="6"
|
|
443
|
+
data-width="1080"
|
|
444
|
+
data-height="1920"
|
|
445
|
+
>
|
|
446
|
+
<div class="emoji" id="emoji-1">🤩</div>
|
|
447
|
+
<div class="emoji" id="emoji-2">🏔️</div>
|
|
448
|
+
<script>
|
|
449
|
+
const emojiTL = gsap.timeline({ paused: true });
|
|
450
|
+
emojiTL.to("#emoji-1", { opacity: 1, scale: 1.2 }, 2);
|
|
451
|
+
emojiTL.to("#emoji-2", { opacity: 1, scale: 1.2 }, 4);
|
|
452
|
+
window.__timelines["emojis"] = emojiTL;
|
|
453
|
+
</script>
|
|
454
|
+
</div>
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### When to create separate compositions
|
|
458
|
+
|
|
459
|
+
- **Captions**: One composition for all captions, script manages word groups
|
|
460
|
+
- **Emojis/Stickers**: One composition for the emoji layer
|
|
461
|
+
- **Hooks/Titles**: One composition per distinct title sequence
|
|
462
|
+
- **Overlays**: Group related overlays into compositions by purpose
|
|
463
|
+
|
|
464
|
+
The composition appears in the timeline with its start time and duration (determined by its GSAP timeline). Everything inside is managed by the script but inherits the composition's timeline position.
|
|
465
|
+
|
|
466
|
+
### Caption discoverability contract
|
|
467
|
+
|
|
468
|
+
To make caption previews deterministic and easy to isolate in downstream UIs (timeline, mini-player, editor overlays), caption compositions should expose a stable root selector.
|
|
469
|
+
|
|
470
|
+
Use these attributes on the caption root node:
|
|
471
|
+
|
|
472
|
+
- `data-timeline-role="captions"` (required)
|
|
473
|
+
- `data-caption-root="true"` (recommended)
|
|
474
|
+
|
|
475
|
+
Example:
|
|
476
|
+
|
|
477
|
+
```html
|
|
478
|
+
<div
|
|
479
|
+
id="captions-comp"
|
|
480
|
+
data-composition-id="captions"
|
|
481
|
+
data-start="0"
|
|
482
|
+
data-track-index="5"
|
|
483
|
+
data-width="1080"
|
|
484
|
+
data-height="1920"
|
|
485
|
+
data-timeline-role="captions"
|
|
486
|
+
data-caption-root="true"
|
|
487
|
+
>
|
|
488
|
+
<div id="caption-container"></div>
|
|
489
|
+
<script>
|
|
490
|
+
const captionTL = gsap.timeline({ paused: true });
|
|
491
|
+
window.__timelines["captions"] = captionTL;
|
|
492
|
+
</script>
|
|
493
|
+
</div>
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
## Timeline Contract
|
|
497
|
+
|
|
498
|
+
The framework initializes `window.__timelines = {}` before any scripts run. Every composition **must** have a script that creates a GSAP timeline and registers it:
|
|
499
|
+
|
|
500
|
+
```js
|
|
501
|
+
const tl = gsap.timeline({ paused: true });
|
|
502
|
+
// ... add tweens, nested timelines, etc.
|
|
503
|
+
window.__timelines["<data-composition-id>"] = tl;
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### Rules
|
|
507
|
+
|
|
508
|
+
- **Every composition needs a script** — at minimum, to create and register its timeline. A composition without a script has no timeline and cannot participate in the hierarchy.
|
|
509
|
+
- **All timelines start paused** — create timelines with `{ paused: true }`. The top-level timeline is controlled externally by the frontend player or renderer.
|
|
510
|
+
- **Framework auto-nests sub-timelines** — you do **not** need to manually add sub-composition timelines to the master timeline. The framework automatically nests any timeline registered in `window.__timelines` into its parent based on the composition's `data-start` attribute.
|
|
511
|
+
- **Duration comes from the timeline** — a composition's duration is `tl.duration()`. The timeline is the sole source of truth; there is no `data-duration` on compositions.
|
|
512
|
+
- **Timelines must be finite** — every timeline must have a finite duration. Infinite or indefinite timelines are not supported.
|
|
513
|
+
|
|
514
|
+
### What NOT to do
|
|
515
|
+
|
|
516
|
+
```js
|
|
517
|
+
// UNNECESSARY - the framework does this automatically
|
|
518
|
+
if (window.__timelines["captions"]) {
|
|
519
|
+
masterTL.add(window.__timelines["captions"], 0);
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
Just register your timeline in `window.__timelines` and the framework handles the rest.
|
|
524
|
+
|
|
525
|
+
## Output Checklist
|
|
526
|
+
|
|
527
|
+
- [ ] Every composition has `data-width` and `data-height` attributes
|
|
528
|
+
- [ ] Each reusable composition is in its own HTML file (in `compositions/` directory)
|
|
529
|
+
- [ ] Compositions loaded via `data-composition-src` attribute
|
|
530
|
+
- [ ] Each composition file uses `<template>` tag to wrap its content
|
|
531
|
+
- [ ] `window.__timelines` given all compositions' timelines
|
|
532
|
+
- [ ] Complex/dynamic animations are handled by scripts in compositions
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Core Notes
|
|
2
|
+
|
|
3
|
+
Extended design rationale and context for decisions in `core.md`. This file is for humans reviewing the design — it is not consumed by the LLM agent.
|
|
4
|
+
|
|
5
|
+
## Interactive Compositions
|
|
6
|
+
|
|
7
|
+
### Why `data-start="interactive"`
|
|
8
|
+
|
|
9
|
+
We considered three alternatives:
|
|
10
|
+
|
|
11
|
+
1. **`data-interactive` boolean attribute** — Keeps `data-start` clean, but then `data-start` must either be omitted (breaking the convention that every clip has `data-start`) or present but meaningless. Two attributes to express what one value handles.
|
|
12
|
+
|
|
13
|
+
2. **Event-driven `data-start="on:click:#element"`** — More expressive and extensible to other events (`on:hover`, `on:end:#video`), but complex to parse, harder for an LLM to author correctly, and the trigger/target relationship is declared on the target which reads backwards.
|
|
14
|
+
|
|
15
|
+
3. **`data-start="interactive"` (chosen)** — Reuses the existing `data-start` attribute with a new keyword value. Reads naturally: "when does this start?" → "interactively." One attribute, no ambiguity, easy to parse (`=== "interactive"` check).
|
|
16
|
+
|
|
17
|
+
The tradeoff is that `data-start` is now overloaded (was purely numeric/reference, now has a keyword). We accepted this because the parsing is trivial and the readability gain is significant.
|
|
18
|
+
|
|
19
|
+
### Why `window.__navigate()` instead of `data-goto`
|
|
20
|
+
|
|
21
|
+
Navigation is behavior, not structure. The framework's philosophy separates these: HTML declares structure and timing, scripts handle behavior.
|
|
22
|
+
|
|
23
|
+
A `data-goto="composition-id"` attribute on trigger elements would be declarative and concise, but limits what authors can do. With a runtime API, scripts can:
|
|
24
|
+
|
|
25
|
+
- Add conditional logic (`if (score > 50) navigate('win') else navigate('lose')`)
|
|
26
|
+
- Animate a transition before navigating
|
|
27
|
+
- Add delays or timeouts
|
|
28
|
+
- Chain multiple actions on a single click
|
|
29
|
+
- Use any DOM event, not just clicks
|
|
30
|
+
|
|
31
|
+
The trigger element is just normal HTML with a normal `addEventListener`. The LLM only needs to know `window.__navigate(id)` — plain JS.
|
|
32
|
+
|
|
33
|
+
### Navigation Behavior: Replace
|
|
34
|
+
|
|
35
|
+
When `__navigate()` is called:
|
|
36
|
+
|
|
37
|
+
1. The currently active composition's timeline pauses
|
|
38
|
+
2. The current composition hides (visibility/display)
|
|
39
|
+
3. The target interactive composition shows
|
|
40
|
+
4. The target's timeline seeks to 0 and plays
|
|
41
|
+
|
|
42
|
+
We chose Replace (parent hides entirely) over Overlay (target plays on top) or Pause-and-branch (parent pauses, resumes when target ends) because it's the simplest mental model and matches how most interactive video works (YouTube branching, Netflix Bandersnatch).
|
|
43
|
+
|
|
44
|
+
### Ownership Model
|
|
45
|
+
|
|
46
|
+
Interactive compositions are children of the composition that branches to them in the DOM tree. The parent composition is the "root" of its branching experience — it owns its branches.
|
|
47
|
+
|
|
48
|
+
However, `window.__navigate()` resolves composition IDs globally across the full tree, not scoped to the current parent. This means:
|
|
49
|
+
|
|
50
|
+
- A deeply nested interactive composition can navigate to any other interactive composition by ID
|
|
51
|
+
- A shared "game over" or "credits" composition can be reached from anywhere
|
|
52
|
+
- Circular navigation is possible (A → B → A) — the framework does not prevent loops
|
|
53
|
+
|
|
54
|
+
### Future Extensions
|
|
55
|
+
|
|
56
|
+
These are not implemented but the design accommodates them without breaking changes:
|
|
57
|
+
|
|
58
|
+
- **Overlay mode**: `window.__navigate(id, { mode: 'overlay' })` — target plays on top, parent pauses or continues
|
|
59
|
+
- **History / back**: `window.__navigate('$back')` to return to the previous composition, `window.__navigateHistory` to read the stack
|
|
60
|
+
- **Auto-advance / timeout**: Scripts can implement this today with `setTimeout(() => window.__navigate('default'), 10000)`. A declarative shorthand could be added later.
|
|
61
|
+
- **Pause-and-branch**: `window.__navigate(id, { mode: 'branch' })` — parent pauses, resumes when target ends
|