@multitrack/svelte 0.1.0 → 0.1.1

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/package.json +10 -8
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,167 @@
1
+ # @multitrack/svelte
2
+
3
+ Svelte 5 bindings for [`@multitrack/core`](https://github.com/jakhsu/multitrack/tree/main/packages/core) — a scroll-driven animation engine with a multi-track timeline architecture.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @multitrack/core @multitrack/svelte
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```svelte
14
+ <!-- App.svelte -->
15
+ <script lang="ts">
16
+ import { MultitrackProvider, ScrollContainer, FixedStage, Show } from "@multitrack/svelte";
17
+ import type { StepConfig } from "@multitrack/core";
18
+ import IntroSection from "./IntroSection.svelte";
19
+ import FeatureSection from "./FeatureSection.svelte";
20
+
21
+ const config: StepConfig[] = [
22
+ { name: "intro", duration: 3, track: "main", easing: "linear" },
23
+ { name: "feature", duration: 5, track: "main" },
24
+ { name: "outro", duration: 3, track: "main", easing: "linear" },
25
+ ];
26
+ </script>
27
+
28
+ <MultitrackProvider {config}>
29
+ <ScrollContainer>
30
+ <FixedStage>
31
+ <Show when="intro">
32
+ <IntroSection />
33
+ </Show>
34
+ <Show when="feature">
35
+ <FeatureSection />
36
+ </Show>
37
+ </FixedStage>
38
+ </ScrollContainer>
39
+ </MultitrackProvider>
40
+ ```
41
+
42
+ ```svelte
43
+ <!-- IntroSection.svelte -->
44
+ <script lang="ts">
45
+ import { useStep } from "@multitrack/svelte";
46
+
47
+ const step = useStep("intro");
48
+ </script>
49
+
50
+ <div style:opacity={step.opacity} style:transform="translateY({(1 - step.opacity) * 40}px)">
51
+ <h1>Welcome</h1>
52
+ </div>
53
+ ```
54
+
55
+ ## API
56
+
57
+ ### `<MultitrackProvider>`
58
+
59
+ Wraps your app and creates the timeline instance. All composables and components must be used within this provider.
60
+
61
+ ```svelte
62
+ <MultitrackProvider {config} {breakpoints} devtools>
63
+ {@render children()}
64
+ </MultitrackProvider>
65
+ ```
66
+
67
+ ### Composables
68
+
69
+ #### `useStep(name)`
70
+
71
+ Returns a reactive object with `opacity` and `isActive` getters for a single step.
72
+
73
+ #### `useOpacities()`
74
+
75
+ Returns a reactive object with a `current` getter containing an `Opacities` record (`{ [stepName]: number }`) for all steps.
76
+
77
+ #### `useScrollProgress()`
78
+
79
+ Returns a reactive object with `scrollPercentage`, `currentStep`, and `totalSteps` getters.
80
+
81
+ #### `useTimeline()`
82
+
83
+ Returns the underlying `Timeline` instance for advanced use cases.
84
+
85
+ ### Components
86
+
87
+ #### `<ScrollContainer>`
88
+
89
+ The scrollable container that drives the timeline. Renders a `<div>` with the correct scroll height.
90
+
91
+ #### `<FixedStage>`
92
+
93
+ A fixed-position overlay inside `ScrollContainer` for content that stays in the viewport while scrolling.
94
+
95
+ #### `<Show when="stepName">`
96
+
97
+ Conditionally renders children when the named step is active (opacity > 0).
98
+
99
+ ### DevTools
100
+
101
+ Enable the Chrome DevTools integration by passing the `devtools` prop to the provider:
102
+
103
+ ```svelte
104
+ <MultitrackProvider {config} devtools>
105
+ {@render children()}
106
+ </MultitrackProvider>
107
+ ```
108
+
109
+ This exposes timeline state to the [@multitrack/devtools](https://github.com/jakhsu/multitrack/tree/main/packages/devtools) Chrome extension, giving you a live timeline inspector with playhead visualization, active step opacities, and an event log.
110
+
111
+ ## Full example with `useStep()`
112
+
113
+ For fine-grained control over individual steps, use the `useStep()` composable to get reactive `opacity` and `isActive` values and drive animations directly:
114
+
115
+ ```svelte
116
+ <!-- App.svelte -->
117
+ <script lang="ts">
118
+ import { MultitrackProvider, ScrollContainer, FixedStage, Show } from "@multitrack/svelte";
119
+ import type { StepConfig } from "@multitrack/core";
120
+ import IntroSection from "./IntroSection.svelte";
121
+ import FeatureSection from "./FeatureSection.svelte";
122
+ import Caption from "./Caption.svelte";
123
+
124
+ const config: StepConfig[] = [
125
+ { name: "intro", duration: 3, track: "main", easing: "linear" },
126
+ { name: "feature", duration: 5, track: "main" },
127
+ { name: "outro", duration: 3, track: "main", easing: "linear" },
128
+
129
+ // Independent text track — overlaps freely with main
130
+ { name: "buffer", duration: 4, track: "text" },
131
+ { name: "caption", duration: 3, track: "text" },
132
+ ];
133
+ </script>
134
+
135
+ <MultitrackProvider {config} devtools>
136
+ <ScrollContainer>
137
+ <FixedStage>
138
+ <Show when="intro">
139
+ <IntroSection />
140
+ </Show>
141
+ <Show when="feature">
142
+ <FeatureSection />
143
+ </Show>
144
+ <Show when="caption">
145
+ <Caption text="Tracks are independent." />
146
+ </Show>
147
+ </FixedStage>
148
+ </ScrollContainer>
149
+ </MultitrackProvider>
150
+ ```
151
+
152
+ ```svelte
153
+ <!-- IntroSection.svelte -->
154
+ <script lang="ts">
155
+ import { useStep } from "@multitrack/svelte";
156
+
157
+ const step = useStep("intro");
158
+ </script>
159
+
160
+ <div style:opacity={step.opacity} style:transform="translateY({(1 - step.opacity) * 40}px)">
161
+ <h1>Welcome</h1>
162
+ </div>
163
+ ```
164
+
165
+ ## License
166
+
167
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multitrack/svelte",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Svelte 5 bindings for @multitrack/core",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -12,16 +12,14 @@
12
12
  "default": "./dist/index.js"
13
13
  }
14
14
  },
15
- "files": ["dist"],
16
- "scripts": {
17
- "build": "svelte-package -i src -o dist",
18
- "dev": "svelte-package -i src -o dist --watch"
19
- },
15
+ "files": [
16
+ "dist"
17
+ ],
20
18
  "peerDependencies": {
21
19
  "svelte": ">=5.0.0"
22
20
  },
23
21
  "dependencies": {
24
- "@multitrack/core": "workspace:^"
22
+ "@multitrack/core": "^0.1.1"
25
23
  },
26
24
  "devDependencies": {
27
25
  "@sveltejs/package": "^2.0.0",
@@ -54,5 +52,9 @@
54
52
  },
55
53
  "engines": {
56
54
  "node": ">=20"
55
+ },
56
+ "scripts": {
57
+ "build": "svelte-package -i src -o dist",
58
+ "dev": "svelte-package -i src -o dist --watch"
57
59
  }
58
- }
60
+ }