@multitrack/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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Jack Hsu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # @multitrack/core
2
+
3
+ A scroll-driven animation engine with a multi-track timeline architecture, inspired by video editing software. Pure TypeScript, zero dependencies.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @multitrack/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Timeline, ScrollDriver } from "@multitrack/core";
15
+
16
+ const timeline = new Timeline({
17
+ config: [
18
+ { name: "intro", duration: 3, track: "main", easing: "linear" },
19
+ { name: "feature", duration: 5, track: "main" },
20
+ { name: "outro", duration: 3, track: "main", easing: "linear" },
21
+
22
+ // Independent text track — overlaps freely with main
23
+ { name: "buffer", duration: 4, track: "text" },
24
+ { name: "caption", duration: 3, track: "text" },
25
+ ],
26
+ });
27
+
28
+ // Connect to scroll position
29
+ const driver = new ScrollDriver(timeline, {
30
+ container: document.querySelector("#scroll-container"),
31
+ });
32
+
33
+ // React to step changes
34
+ timeline.on("step:enter", ({ name }) => console.log("entered", name));
35
+ timeline.on("step:exit", ({ name }) => console.log("exited", name));
36
+
37
+ // Read opacity values at any scroll progress
38
+ const opacities = timeline.getOpacities();
39
+ // { intro: 0.8, feature: 0, outro: 0, buffer: 1, caption: 0 }
40
+ ```
41
+
42
+ ## API
43
+
44
+ ### `Timeline`
45
+
46
+ The core engine. Resolves step configs into absolute positions and calculates opacity values at any scroll progress.
47
+
48
+ ```typescript
49
+ const timeline = new Timeline({ config, breakpoints?, devtools? });
50
+
51
+ timeline.setProgress(0.5); // Set playhead position (0–1)
52
+ timeline.getOpacities(); // Get all step opacities
53
+ timeline.getCurrentSteps(); // Get currently active steps
54
+ timeline.on("step:enter", handler); // Listen to events
55
+ timeline.use(middleware); // Add middleware
56
+ timeline.scope(() => { ... }); // Scoped subscriptions
57
+ timeline.dispose(); // Clean up
58
+ ```
59
+
60
+ ### `ScrollDriver`
61
+
62
+ Connects a `Timeline` to a scrollable DOM element, translating scroll position into timeline progress.
63
+
64
+ ### Easings
65
+
66
+ Built-in presets: `snap` (default — binary 0/1), `linear`, `easeIn`, `easeOut`, `easeInOut`. Or pass a custom function.
67
+
68
+ ```typescript
69
+ { name: "fade", duration: 3, track: "main", easing: "linear" }
70
+ { name: "custom", duration: 4, track: "main", easing: (t) => t * t }
71
+ ```
72
+
73
+ ### Middleware
74
+
75
+ Intercept `step:enter` and `step:exit` events:
76
+
77
+ ```typescript
78
+ timeline.use((event, next) => {
79
+ analytics.track(event.type, event.payload.name);
80
+ next();
81
+ });
82
+ ```
83
+
84
+ ### Responsive tracks
85
+
86
+ Include or exclude steps based on named breakpoints tied to CSS media queries:
87
+
88
+ ```typescript
89
+ const timeline = new Timeline({
90
+ config: [
91
+ { name: "mobile-hero", duration: 5, track: "main", when: "mobile" },
92
+ { name: "desktop-hero", duration: 8, track: "main", when: "desktop" },
93
+ ],
94
+ breakpoints: {
95
+ mobile: "(max-width: 767px)",
96
+ desktop: "(min-width: 768px)",
97
+ },
98
+ });
99
+ ```
100
+
101
+ ## React bindings
102
+
103
+ See [`@multitrack/react`](https://github.com/jakhsu/multitrack/tree/main/packages/react) for React hooks and components.
104
+
105
+ ## License
106
+
107
+ MIT