@elah/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.
Files changed (153) hide show
  1. package/dist/actions/index.d.ts +3 -0
  2. package/dist/actions/index.js +1 -0
  3. package/dist/actions/splitClipAtPlayhead.d.ts +8 -0
  4. package/dist/actions/splitClipAtPlayhead.js +34 -0
  5. package/dist/actions/types.d.ts +8 -0
  6. package/dist/actions/types.js +1 -0
  7. package/dist/assets/importFiles.d.ts +29 -0
  8. package/dist/assets/importFiles.js +351 -0
  9. package/dist/assets/index.d.ts +10 -0
  10. package/dist/assets/index.js +13 -0
  11. package/dist/assets/store.d.ts +13 -0
  12. package/dist/assets/store.js +20 -0
  13. package/dist/assets/types.d.ts +23 -0
  14. package/dist/assets/types.js +1 -0
  15. package/dist/debug/trace.d.ts +20 -0
  16. package/dist/debug/trace.js +98 -0
  17. package/dist/editor/TimelineEngine.d.ts +65 -0
  18. package/dist/editor/TimelineEngine.js +413 -0
  19. package/dist/editor-context.d.ts +10 -0
  20. package/dist/editor-context.js +10 -0
  21. package/dist/elements/audio.d.ts +13 -0
  22. package/dist/elements/audio.js +4 -0
  23. package/dist/elements/base.d.ts +40 -0
  24. package/dist/elements/base.js +39 -0
  25. package/dist/elements/image.d.ts +13 -0
  26. package/dist/elements/image.js +4 -0
  27. package/dist/elements/text.d.ts +12 -0
  28. package/dist/elements/text.js +8 -0
  29. package/dist/elements/video.d.ts +13 -0
  30. package/dist/elements/video.js +4 -0
  31. package/dist/export/ExportWorker.d.ts +1 -0
  32. package/dist/export/ExportWorker.js +371 -0
  33. package/dist/export/exportVideo.d.ts +3 -0
  34. package/dist/export/exportVideo.js +118 -0
  35. package/dist/export/index.d.ts +2 -0
  36. package/dist/export/index.js +1 -0
  37. package/dist/export/lazyExport.d.ts +4 -0
  38. package/dist/export/lazyExport.js +4 -0
  39. package/dist/export/types.d.ts +37 -0
  40. package/dist/export/types.js +1 -0
  41. package/dist/index.d.ts +48 -0
  42. package/dist/index.js +28 -0
  43. package/dist/media/audio/AudioPlaybackController.d.ts +26 -0
  44. package/dist/media/audio/AudioPlaybackController.js +125 -0
  45. package/dist/media/video/DecoderBackedVideoFrameProvider.d.ts +51 -0
  46. package/dist/media/video/DecoderBackedVideoFrameProvider.js +125 -0
  47. package/dist/media/video/FrameCache.d.ts +28 -0
  48. package/dist/media/video/FrameCache.js +88 -0
  49. package/dist/media/video/StreamingFrameProducer.d.ts +57 -0
  50. package/dist/media/video/StreamingFrameProducer.js +356 -0
  51. package/dist/media/video/VideoDecoderManager.d.ts +59 -0
  52. package/dist/media/video/VideoDecoderManager.js +342 -0
  53. package/dist/media/video/VideoFrameProvider.d.ts +101 -0
  54. package/dist/media/video/VideoFrameProvider.js +257 -0
  55. package/dist/media/video/demuxer/MediabunnyDemuxer.d.ts +23 -0
  56. package/dist/media/video/demuxer/MediabunnyDemuxer.js +88 -0
  57. package/dist/media/video/demuxer/createMediabunnyBackend.d.ts +32 -0
  58. package/dist/media/video/demuxer/createMediabunnyBackend.js +156 -0
  59. package/dist/media/video/index.d.ts +8 -0
  60. package/dist/media/video/index.js +5 -0
  61. package/dist/playback/PlaybackEngine.d.ts +50 -0
  62. package/dist/playback/PlaybackEngine.js +188 -0
  63. package/dist/renderer/gpu/GpuRenderer.d.ts +38 -0
  64. package/dist/renderer/gpu/GpuRenderer.js +208 -0
  65. package/dist/renderer/gpu/RenderGraph.d.ts +10 -0
  66. package/dist/renderer/gpu/RenderGraph.js +80 -0
  67. package/dist/renderer/gpu/ShaderProgram.d.ts +14 -0
  68. package/dist/renderer/gpu/ShaderProgram.js +76 -0
  69. package/dist/renderer/gpu/TexturePool.d.ts +25 -0
  70. package/dist/renderer/gpu/TexturePool.js +93 -0
  71. package/dist/renderer/gpu/VideoTexture.d.ts +13 -0
  72. package/dist/renderer/gpu/VideoTexture.js +54 -0
  73. package/dist/renderer/gpu/WebGLContext.d.ts +28 -0
  74. package/dist/renderer/gpu/WebGLContext.js +102 -0
  75. package/dist/renderer/gpu/debug/DebugGpuRenderer.d.ts +27 -0
  76. package/dist/renderer/gpu/debug/DebugGpuRenderer.js +108 -0
  77. package/dist/renderer/gpu/debug/DebugOverlay.d.ts +17 -0
  78. package/dist/renderer/gpu/debug/DebugOverlay.js +83 -0
  79. package/dist/renderer/gpu/debug/GpuDebugCounters.d.ts +38 -0
  80. package/dist/renderer/gpu/debug/GpuDebugCounters.js +72 -0
  81. package/dist/renderer/gpu/debug/GpuDebugGlobal.d.ts +16 -0
  82. package/dist/renderer/gpu/debug/GpuDebugGlobal.js +14 -0
  83. package/dist/renderer/gpu/debug/GpuRendererDebugPanel.d.ts +31 -0
  84. package/dist/renderer/gpu/debug/GpuRendererDebugPanel.js +128 -0
  85. package/dist/renderer/gpu/debug/RecordingGl.d.ts +88 -0
  86. package/dist/renderer/gpu/debug/RecordingGl.js +214 -0
  87. package/dist/renderer/gpu/debug/playground.d.ts +20 -0
  88. package/dist/renderer/gpu/debug/playground.js +64 -0
  89. package/dist/renderer/gpu/debug/scenarios.d.ts +7 -0
  90. package/dist/renderer/gpu/debug/scenarios.js +145 -0
  91. package/dist/renderer/gpu/debug/types.d.ts +16 -0
  92. package/dist/renderer/gpu/debug/types.js +1 -0
  93. package/dist/renderer/gpu/layers/FrameProbeLayer.d.ts +16 -0
  94. package/dist/renderer/gpu/layers/FrameProbeLayer.js +127 -0
  95. package/dist/renderer/gpu/layers/ImageLayer.d.ts +23 -0
  96. package/dist/renderer/gpu/layers/ImageLayer.js +124 -0
  97. package/dist/renderer/gpu/layers/TestLayer.d.ts +16 -0
  98. package/dist/renderer/gpu/layers/TestLayer.js +109 -0
  99. package/dist/renderer/gpu/layers/TextLayer.d.ts +19 -0
  100. package/dist/renderer/gpu/layers/TextLayer.js +166 -0
  101. package/dist/renderer/gpu/layers/VideoLayer.d.ts +38 -0
  102. package/dist/renderer/gpu/layers/VideoLayer.js +194 -0
  103. package/dist/renderer/gpu/layers/drawRect.d.ts +13 -0
  104. package/dist/renderer/gpu/layers/drawRect.js +55 -0
  105. package/dist/renderer/gpu/layers/objectFit.d.ts +7 -0
  106. package/dist/renderer/gpu/layers/objectFit.js +26 -0
  107. package/dist/renderer/gpu/layers/textLayout.d.ts +47 -0
  108. package/dist/renderer/gpu/layers/textLayout.js +82 -0
  109. package/dist/renderer/gpu/layers/types.d.ts +18 -0
  110. package/dist/renderer/gpu/layers/types.js +1 -0
  111. package/dist/renderer/gpu/shaders/quad.frag.d.ts +1 -0
  112. package/dist/renderer/gpu/shaders/quad.frag.js +14 -0
  113. package/dist/renderer/gpu/shaders/quad.vert.d.ts +1 -0
  114. package/dist/renderer/gpu/shaders/quad.vert.js +28 -0
  115. package/dist/renderer/gpu/types.d.ts +21 -0
  116. package/dist/renderer/gpu/types.js +1 -0
  117. package/dist/renderer/gpu/viewport.d.ts +7 -0
  118. package/dist/renderer/gpu/viewport.js +33 -0
  119. package/dist/renderer/types.d.ts +7 -0
  120. package/dist/renderer/types.js +1 -0
  121. package/dist/resolver/resolveTimeline.d.ts +3 -0
  122. package/dist/resolver/resolveTimeline.js +249 -0
  123. package/dist/resolver/scene.d.ts +54 -0
  124. package/dist/resolver/scene.js +1 -0
  125. package/dist/stores/playback.store.d.ts +50 -0
  126. package/dist/stores/playback.store.js +42 -0
  127. package/dist/stores/selection.store.d.ts +12 -0
  128. package/dist/stores/selection.store.js +19 -0
  129. package/dist/stores/tracks.store.d.ts +19 -0
  130. package/dist/stores/tracks.store.js +27 -0
  131. package/dist/stores/transitions.store.d.ts +9 -0
  132. package/dist/stores/transitions.store.js +7 -0
  133. package/dist/track/track.d.ts +8 -0
  134. package/dist/track/track.js +19 -0
  135. package/dist/types/index.d.ts +117 -0
  136. package/dist/types/index.js +1 -0
  137. package/dist/utils/frames.d.ts +20 -0
  138. package/dist/utils/frames.js +40 -0
  139. package/dist/utils/id.d.ts +1 -0
  140. package/dist/utils/id.js +3 -0
  141. package/dist/utils/snap.d.ts +5 -0
  142. package/dist/utils/snap.js +79 -0
  143. package/dist/visitor/add.d.ts +3 -0
  144. package/dist/visitor/add.js +16 -0
  145. package/dist/visitor/clone.d.ts +3 -0
  146. package/dist/visitor/clone.js +25 -0
  147. package/dist/visitor/remove.d.ts +5 -0
  148. package/dist/visitor/remove.js +29 -0
  149. package/dist/visitor/split.d.ts +3 -0
  150. package/dist/visitor/split.js +31 -0
  151. package/dist/visitor/update.d.ts +4 -0
  152. package/dist/visitor/update.js +31 -0
  153. package/package.json +31 -0
@@ -0,0 +1,249 @@
1
+ function applyEasing(t, easing = 'linear') {
2
+ const c = Math.max(0, Math.min(1, t));
3
+ if (easing === 'ease-in')
4
+ return c * c;
5
+ if (easing === 'ease-out')
6
+ return c * (2 - c);
7
+ return c;
8
+ }
9
+ function findClipById(clips, clipId) {
10
+ for (const [trackId, trackClips] of Object.entries(clips)) {
11
+ const clip = trackClips.find((c) => c.id === clipId);
12
+ if (clip)
13
+ return { clip, trackId };
14
+ }
15
+ return null;
16
+ }
17
+ export function resolveTimeline(frame, project) {
18
+ const scene = {
19
+ frame,
20
+ fps: project.fps,
21
+ stage: project.stage,
22
+ videos: [],
23
+ audios: [],
24
+ texts: [],
25
+ images: [],
26
+ transitions: [],
27
+ };
28
+ const hasSolo = { video: false, audio: false, text: false };
29
+ for (const t of project.tracks) {
30
+ if (t.solo) {
31
+ if (t.kind === 'video' || t.kind === 'audio' || t.kind === 'text') {
32
+ hasSolo[t.kind] = true;
33
+ }
34
+ }
35
+ }
36
+ const maxOrder = project.tracks.reduce((m, t) => Math.max(m, t.order), 0);
37
+ for (const track of project.tracks) {
38
+ if (track.disabled)
39
+ continue;
40
+ if (hasSolo[track.kind] && !track.solo)
41
+ continue;
42
+ const clips = project.clips[track.id];
43
+ if (!clips || clips.length === 0)
44
+ continue;
45
+ const zIndex = track.kind === 'text' ? 1000000 : (maxOrder - track.order) * 1000;
46
+ for (const clip of clips) {
47
+ if (clip.disabled)
48
+ continue;
49
+ if (frame < clip.startFrame)
50
+ continue;
51
+ if (frame >= clip.startFrame + clip.durationFrames)
52
+ continue;
53
+ const sourceFrame = frame - clip.startFrame + clip.sourceStartFrame;
54
+ const opacity = clip.opacity ?? 1;
55
+ const baseVolume = clip.volume ?? 1;
56
+ const volume = track.muted ? 0 : baseVolume;
57
+ if (clip.type === 'video' && clip.src) {
58
+ const active = {
59
+ type: 'video',
60
+ id: clip.id,
61
+ trackId: clip.trackId,
62
+ name: clip.name,
63
+ src: clip.src,
64
+ sourceFrame,
65
+ opacity,
66
+ volume,
67
+ zIndex,
68
+ ...(clip.transform ? { transform: clip.transform } : {}),
69
+ };
70
+ scene.videos.push(active);
71
+ }
72
+ else if (clip.type === 'audio' && clip.src) {
73
+ const active = {
74
+ type: 'audio',
75
+ id: clip.id,
76
+ trackId: clip.trackId,
77
+ name: clip.name,
78
+ src: clip.src,
79
+ sourceFrame,
80
+ opacity: 1,
81
+ volume,
82
+ zIndex,
83
+ ...(clip.transform ? { transform: clip.transform } : {}),
84
+ };
85
+ scene.audios.push(active);
86
+ }
87
+ else if (clip.type === 'text') {
88
+ let resolvedOpacity = opacity;
89
+ const anim = clip.textAnimation;
90
+ if (anim) {
91
+ const d = Math.max(1, anim.durationFrames);
92
+ const localFrame = frame - clip.startFrame;
93
+ if (anim.in === 'fade') {
94
+ resolvedOpacity = Math.min(resolvedOpacity, Math.min(1, localFrame / d));
95
+ }
96
+ if (anim.out === 'fade') {
97
+ resolvedOpacity = Math.min(resolvedOpacity, Math.min(1, (clip.durationFrames - localFrame) / d));
98
+ }
99
+ }
100
+ const active = {
101
+ type: 'text',
102
+ id: clip.id,
103
+ trackId: clip.trackId,
104
+ name: clip.name,
105
+ content: clip.content ?? '',
106
+ sourceFrame,
107
+ opacity: resolvedOpacity,
108
+ zIndex,
109
+ ...(clip.transform ? { transform: clip.transform } : {}),
110
+ ...(clip.fontSize !== undefined ? { fontSize: clip.fontSize } : {}),
111
+ ...(clip.color !== undefined ? { color: clip.color } : {}),
112
+ ...(clip.fontFamily !== undefined ? { fontFamily: clip.fontFamily } : {}),
113
+ ...(clip.fontWeight !== undefined ? { fontWeight: clip.fontWeight } : {}),
114
+ ...(clip.textAlign !== undefined ? { textAlign: clip.textAlign } : {}),
115
+ };
116
+ scene.texts.push(active);
117
+ }
118
+ else if (clip.type === 'image' && clip.src) {
119
+ const active = {
120
+ type: 'image',
121
+ id: clip.id,
122
+ trackId: clip.trackId,
123
+ name: clip.name,
124
+ src: clip.src,
125
+ sourceFrame,
126
+ opacity,
127
+ zIndex,
128
+ ...(clip.transform ? { transform: clip.transform } : {}),
129
+ };
130
+ scene.images.push(active);
131
+ }
132
+ }
133
+ }
134
+ for (const transition of project.transitions) {
135
+ if (frame < transition.startFrame)
136
+ continue;
137
+ if (frame >= transition.startFrame + transition.durationFrames)
138
+ continue;
139
+ const rawT = (frame - transition.startFrame) / Math.max(1, transition.durationFrames);
140
+ const t = applyEasing(rawT, transition.easing);
141
+ const fromResult = findClipById(project.clips, transition.fromClipId);
142
+ const toResult = findClipById(project.clips, transition.toClipId);
143
+ if (!fromResult || !toResult)
144
+ continue;
145
+ const { clip: fromClip } = fromResult;
146
+ const { clip: toClip } = toResult;
147
+ const fromZIndex = (maxOrder - (project.tracks.find((tr) => tr.id === transition.trackId)?.order ?? 0)) * 1000;
148
+ const toZIndex = fromZIndex + 1;
149
+ const fromSourceFrame = Math.min(Math.max(0, frame - fromClip.startFrame + fromClip.sourceStartFrame), fromClip.sourceDurationFrames - 1);
150
+ const toSourceFrame = Math.max(0, Math.min(frame - toClip.startFrame + toClip.sourceStartFrame, toClip.sourceDurationFrames - 1));
151
+ const fromOpacity = 0;
152
+ const toOpacity = 1;
153
+ const toTrackMuted = project.tracks.find((tr) => tr.id === toClip.trackId)?.muted ?? false;
154
+ if (fromClip.type === 'video' && fromClip.src) {
155
+ const existing = scene.videos.find((v) => v.id === fromClip.id);
156
+ if (existing) {
157
+ existing.opacity = fromOpacity;
158
+ existing.sourceFrame = fromSourceFrame;
159
+ }
160
+ else {
161
+ scene.videos.push({
162
+ type: 'video',
163
+ id: fromClip.id,
164
+ trackId: fromClip.trackId,
165
+ name: fromClip.name,
166
+ src: fromClip.src,
167
+ sourceFrame: fromSourceFrame,
168
+ opacity: fromOpacity,
169
+ volume: 0,
170
+ zIndex: fromZIndex,
171
+ ...(fromClip.transform ? { transform: fromClip.transform } : {}),
172
+ });
173
+ }
174
+ }
175
+ if (toClip.type === 'video' && toClip.src) {
176
+ const existing = scene.videos.find((v) => v.id === toClip.id);
177
+ if (existing) {
178
+ existing.opacity = toOpacity;
179
+ existing.sourceFrame = toSourceFrame;
180
+ }
181
+ else {
182
+ scene.videos.push({
183
+ type: 'video',
184
+ id: toClip.id,
185
+ trackId: toClip.trackId,
186
+ name: toClip.name,
187
+ src: toClip.src,
188
+ sourceFrame: toSourceFrame,
189
+ opacity: toOpacity,
190
+ volume: toTrackMuted ? 0 : (toClip.volume ?? 1),
191
+ zIndex: toZIndex,
192
+ ...(toClip.transform ? { transform: toClip.transform } : {}),
193
+ });
194
+ }
195
+ }
196
+ if (fromClip.type === 'image' && fromClip.src) {
197
+ const existing = scene.images.find((v) => v.id === fromClip.id);
198
+ if (existing) {
199
+ existing.opacity = fromOpacity;
200
+ }
201
+ else {
202
+ scene.images.push({
203
+ type: 'image',
204
+ id: fromClip.id,
205
+ trackId: fromClip.trackId,
206
+ name: fromClip.name,
207
+ src: fromClip.src,
208
+ sourceFrame: fromSourceFrame,
209
+ opacity: fromOpacity,
210
+ zIndex: fromZIndex,
211
+ ...(fromClip.transform ? { transform: fromClip.transform } : {}),
212
+ });
213
+ }
214
+ }
215
+ if (toClip.type === 'image' && toClip.src) {
216
+ const existing = scene.images.find((v) => v.id === toClip.id);
217
+ if (existing) {
218
+ existing.opacity = toOpacity;
219
+ }
220
+ else {
221
+ scene.images.push({
222
+ type: 'image',
223
+ id: toClip.id,
224
+ trackId: toClip.trackId,
225
+ name: toClip.name,
226
+ src: toClip.src,
227
+ sourceFrame: toSourceFrame,
228
+ opacity: toOpacity,
229
+ zIndex: toZIndex,
230
+ ...(toClip.transform ? { transform: toClip.transform } : {}),
231
+ });
232
+ }
233
+ }
234
+ scene.transitions.push({
235
+ id: transition.id,
236
+ kind: transition.kind,
237
+ t,
238
+ direction: transition.direction,
239
+ fromClipId: transition.fromClipId,
240
+ toClipId: transition.toClipId,
241
+ });
242
+ }
243
+ const byDepth = (a, b) => a.zIndex - b.zIndex;
244
+ scene.videos.sort(byDepth);
245
+ scene.audios.sort(byDepth);
246
+ scene.texts.sort(byDepth);
247
+ scene.images.sort(byDepth);
248
+ return scene;
249
+ }
@@ -0,0 +1,54 @@
1
+ import type { Transform, TransitionKind, TransitionDirection } from '../types';
2
+ export interface ActiveClipBase {
3
+ id: string;
4
+ trackId: string;
5
+ name: string;
6
+ sourceFrame: number;
7
+ opacity: number;
8
+ zIndex: number;
9
+ transform?: Transform;
10
+ }
11
+ export interface ActiveVideoClip extends ActiveClipBase {
12
+ type: 'video';
13
+ src: string;
14
+ volume: number;
15
+ }
16
+ export interface ActiveAudioClip extends ActiveClipBase {
17
+ type: 'audio';
18
+ src: string;
19
+ volume: number;
20
+ }
21
+ export interface ActiveTextClip extends ActiveClipBase {
22
+ type: 'text';
23
+ content: string;
24
+ fontSize?: number;
25
+ color?: string;
26
+ fontFamily?: string;
27
+ fontWeight?: 'normal' | 'bold';
28
+ textAlign?: 'left' | 'center' | 'right';
29
+ }
30
+ export interface ActiveImageClip extends ActiveClipBase {
31
+ type: 'image';
32
+ src: string;
33
+ }
34
+ export interface ActiveTransition {
35
+ id: string;
36
+ kind: TransitionKind;
37
+ t: number;
38
+ direction?: TransitionDirection;
39
+ fromClipId: string;
40
+ toClipId: string;
41
+ }
42
+ export interface Scene {
43
+ frame: number;
44
+ fps: number;
45
+ stage: {
46
+ width: number;
47
+ height: number;
48
+ };
49
+ videos: ActiveVideoClip[];
50
+ audios: ActiveAudioClip[];
51
+ texts: ActiveTextClip[];
52
+ images: ActiveImageClip[];
53
+ transitions: ActiveTransition[];
54
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ export interface PlaybackState {
2
+ currentFrame: number;
3
+ currentFrameEpoch: number;
4
+ isPlaying: boolean;
5
+ playbackRate: number;
6
+ loop: boolean;
7
+ volume: number;
8
+ muted: boolean;
9
+ zoom: number;
10
+ snapEnabled: boolean;
11
+ }
12
+ export interface PlaybackActions {
13
+ setCurrentFrame: (frame: number) => void;
14
+ play: () => void;
15
+ pause: () => void;
16
+ togglePlayPause: () => void;
17
+ setPlaybackRate: (rate: number) => void;
18
+ toggleLoop: () => void;
19
+ setVolume: (volume: number) => void;
20
+ toggleMute: () => void;
21
+ setZoom: (zoom: number) => void;
22
+ toggleSnap: () => void;
23
+ }
24
+ export declare const usePlaybackStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<PlaybackState & PlaybackActions>, "setState" | "persist"> & {
25
+ setState(partial: (PlaybackState & PlaybackActions) | Partial<PlaybackState & PlaybackActions> | ((state: PlaybackState & PlaybackActions) => (PlaybackState & PlaybackActions) | Partial<PlaybackState & PlaybackActions>), replace?: false | undefined): unknown;
26
+ setState(state: (PlaybackState & PlaybackActions) | ((state: PlaybackState & PlaybackActions) => PlaybackState & PlaybackActions), replace: true): unknown;
27
+ persist: {
28
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<PlaybackState & PlaybackActions, {
29
+ zoom: number;
30
+ volume: number;
31
+ muted: boolean;
32
+ playbackRate: number;
33
+ loop: boolean;
34
+ snapEnabled: boolean;
35
+ }, unknown>>) => void;
36
+ clearStorage: () => void;
37
+ rehydrate: () => Promise<void> | void;
38
+ hasHydrated: () => boolean;
39
+ onHydrate: (fn: (state: PlaybackState & PlaybackActions) => void) => () => void;
40
+ onFinishHydration: (fn: (state: PlaybackState & PlaybackActions) => void) => () => void;
41
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<PlaybackState & PlaybackActions, {
42
+ zoom: number;
43
+ volume: number;
44
+ muted: boolean;
45
+ playbackRate: number;
46
+ loop: boolean;
47
+ snapEnabled: boolean;
48
+ }, unknown>>;
49
+ };
50
+ }>;
@@ -0,0 +1,42 @@
1
+ import { create } from 'zustand';
2
+ import { persist } from 'zustand/middleware';
3
+ import { toFrame } from '../utils/frames';
4
+ export const usePlaybackStore = create()(persist((set) => ({
5
+ currentFrame: 0,
6
+ currentFrameEpoch: 0,
7
+ isPlaying: false,
8
+ playbackRate: 1,
9
+ loop: false,
10
+ volume: 1,
11
+ muted: false,
12
+ zoom: 4,
13
+ snapEnabled: true,
14
+ setCurrentFrame: (frame) => set((s) => {
15
+ const next = toFrame(frame);
16
+ return s.currentFrame === next
17
+ ? { currentFrameEpoch: s.currentFrameEpoch + 1 }
18
+ : {
19
+ currentFrame: next,
20
+ currentFrameEpoch: s.currentFrameEpoch + 1,
21
+ };
22
+ }),
23
+ play: () => set((s) => (s.isPlaying ? s : { isPlaying: true })),
24
+ pause: () => set((s) => (s.isPlaying ? { isPlaying: false } : s)),
25
+ togglePlayPause: () => set((s) => ({ isPlaying: !s.isPlaying })),
26
+ setPlaybackRate: (rate) => set({ playbackRate: rate }),
27
+ toggleLoop: () => set((s) => ({ loop: !s.loop })),
28
+ setVolume: (volume) => set({ volume: Math.max(0, Math.min(1, volume)) }),
29
+ toggleMute: () => set((s) => ({ muted: !s.muted })),
30
+ setZoom: (zoom) => set({ zoom: Math.max(0.02, Math.min(50, zoom)) }),
31
+ toggleSnap: () => set((s) => ({ snapEnabled: !s.snapEnabled })),
32
+ }), {
33
+ name: 'myeditor-playback',
34
+ partialize: (s) => ({
35
+ zoom: s.zoom,
36
+ volume: s.volume,
37
+ muted: s.muted,
38
+ playbackRate: s.playbackRate,
39
+ loop: s.loop,
40
+ snapEnabled: s.snapEnabled,
41
+ }),
42
+ }));
@@ -0,0 +1,12 @@
1
+ export interface SelectionState {
2
+ selectedClipIds: Set<string>;
3
+ activeTrackId: string | null;
4
+ }
5
+ export interface SelectionActions {
6
+ selectClip: (clipId: string) => void;
7
+ toggleClipSelection: (clipId: string) => void;
8
+ selectClips: (clipIds: string[]) => void;
9
+ clearSelection: () => void;
10
+ setActiveTrack: (trackId: string | null) => void;
11
+ }
12
+ export declare const useSelectionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SelectionState & SelectionActions>>;
@@ -0,0 +1,19 @@
1
+ import { create } from 'zustand';
2
+ export const useSelectionStore = create()((set) => ({
3
+ selectedClipIds: new Set(),
4
+ activeTrackId: null,
5
+ selectClip: (clipId) => set({ selectedClipIds: new Set([clipId]) }),
6
+ toggleClipSelection: (clipId) => set((s) => {
7
+ const next = new Set(s.selectedClipIds);
8
+ if (next.has(clipId)) {
9
+ next.delete(clipId);
10
+ }
11
+ else {
12
+ next.add(clipId);
13
+ }
14
+ return { selectedClipIds: next };
15
+ }),
16
+ selectClips: (clipIds) => set({ selectedClipIds: new Set(clipIds) }),
17
+ clearSelection: () => set({ selectedClipIds: new Set() }),
18
+ setActiveTrack: (trackId) => set({ activeTrackId: trackId }),
19
+ }));
@@ -0,0 +1,19 @@
1
+ import type { Clip, Project, Track } from '../types';
2
+ export interface TracksState {
3
+ tracks: Track[];
4
+ clips: Record<string, Clip[]>;
5
+ stage: {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ totalFrames: number;
10
+ canUndo: boolean;
11
+ canRedo: boolean;
12
+ }
13
+ export interface TracksActions {
14
+ sync: (project: Project, meta: {
15
+ canUndo: boolean;
16
+ canRedo: boolean;
17
+ }) => void;
18
+ }
19
+ export declare const useTracksStore: import("zustand").UseBoundStore<import("zustand").StoreApi<TracksState & TracksActions>>;
@@ -0,0 +1,27 @@
1
+ import { create } from 'zustand';
2
+ export const useTracksStore = create()((set) => ({
3
+ tracks: [],
4
+ clips: {},
5
+ stage: { width: 1080, height: 1920 },
6
+ totalFrames: 0,
7
+ canUndo: false,
8
+ canRedo: false,
9
+ sync: (project, meta) => {
10
+ let max = 0;
11
+ for (const trackClips of Object.values(project.clips)) {
12
+ for (const c of trackClips) {
13
+ const end = c.startFrame + c.durationFrames;
14
+ if (end > max)
15
+ max = end;
16
+ }
17
+ }
18
+ set({
19
+ tracks: project.tracks,
20
+ clips: project.clips,
21
+ stage: project.stage,
22
+ totalFrames: max,
23
+ canUndo: meta.canUndo,
24
+ canRedo: meta.canRedo,
25
+ });
26
+ },
27
+ }));
@@ -0,0 +1,9 @@
1
+ import type { Transition, Project } from '../types';
2
+ interface TransitionsState {
3
+ transitions: Transition[];
4
+ }
5
+ interface TransitionsActions {
6
+ sync: (project: Project) => void;
7
+ }
8
+ export declare const useTransitionsStore: import("zustand").UseBoundStore<import("zustand").StoreApi<TransitionsState & TransitionsActions>>;
9
+ export {};
@@ -0,0 +1,7 @@
1
+ import { create } from 'zustand';
2
+ export const useTransitionsStore = create()((set) => ({
3
+ transitions: [],
4
+ sync: (project) => {
5
+ set({ transitions: project.transitions });
6
+ },
7
+ }));
@@ -0,0 +1,8 @@
1
+ import type { Track, TrackKind } from '../types';
2
+ export interface CreateTrackOptions {
3
+ kind: TrackKind;
4
+ name?: string;
5
+ order?: number;
6
+ height?: number;
7
+ }
8
+ export declare function createTrack(options: CreateTrackOptions): Track;
@@ -0,0 +1,19 @@
1
+ import { generateId } from '../utils/id';
2
+ export function createTrack(options) {
3
+ return {
4
+ id: generateId(),
5
+ name: options.name ??
6
+ (options.kind === 'video'
7
+ ? 'Video'
8
+ : options.kind === 'audio'
9
+ ? 'Audio'
10
+ : 'Text'),
11
+ kind: options.kind,
12
+ order: options.order ?? 0,
13
+ height: options.height ?? 64,
14
+ locked: false,
15
+ disabled: false,
16
+ muted: false,
17
+ solo: false,
18
+ };
19
+ }
@@ -0,0 +1,117 @@
1
+ export type FrameCount = number;
2
+ export type TextAnimationKind = 'fade';
3
+ export interface TextAnimation {
4
+ in?: TextAnimationKind;
5
+ out?: TextAnimationKind;
6
+ durationFrames: number;
7
+ }
8
+ export interface Transform {
9
+ x: number;
10
+ y: number;
11
+ scale: number;
12
+ rotation: number;
13
+ anchor: {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ }
18
+ export type ClipType = 'video' | 'audio' | 'text' | 'image';
19
+ export type TrackKind = 'video' | 'audio' | 'text';
20
+ export interface Clip {
21
+ id: string;
22
+ trackId: string;
23
+ type: ClipType;
24
+ name: string;
25
+ startFrame: FrameCount;
26
+ durationFrames: FrameCount;
27
+ sourceStartFrame: FrameCount;
28
+ sourceDurationFrames: FrameCount;
29
+ src?: string;
30
+ assetId?: string;
31
+ content?: string;
32
+ fontSize?: number;
33
+ color?: string;
34
+ fontFamily?: string;
35
+ fontWeight?: 'normal' | 'bold';
36
+ textAlign?: 'left' | 'center' | 'right';
37
+ volume?: number;
38
+ opacity?: number;
39
+ locked?: boolean;
40
+ disabled?: boolean;
41
+ transform?: Transform;
42
+ textAnimation?: TextAnimation;
43
+ }
44
+ export interface Track {
45
+ id: string;
46
+ name: string;
47
+ kind: TrackKind;
48
+ order: number;
49
+ height: number;
50
+ locked: boolean;
51
+ disabled: boolean;
52
+ muted: boolean;
53
+ solo: boolean;
54
+ }
55
+ export interface Project {
56
+ id: string;
57
+ fps: number;
58
+ stage: {
59
+ width: number;
60
+ height: number;
61
+ };
62
+ tracks: Track[];
63
+ clips: Record<string, Clip[]>;
64
+ transitions: Transition[];
65
+ version: number;
66
+ }
67
+ export interface InitialTrackConfig {
68
+ kind: TrackKind;
69
+ name?: string;
70
+ }
71
+ export interface TimelineConfig {
72
+ fps: number;
73
+ stage?: {
74
+ width: number;
75
+ height: number;
76
+ };
77
+ defaultTrackHeight?: number;
78
+ maxHistorySize?: number;
79
+ initialTracks?: InitialTrackConfig[];
80
+ }
81
+ export type TransitionKind = 'fade' | 'slide' | 'wipe';
82
+ export type TransitionEasing = 'linear' | 'ease-in' | 'ease-out';
83
+ export type TransitionDirection = 'left' | 'right' | 'up' | 'down';
84
+ export interface Transition {
85
+ id: string;
86
+ kind: TransitionKind;
87
+ fromClipId: string;
88
+ toClipId: string;
89
+ trackId: string;
90
+ startFrame: FrameCount;
91
+ durationFrames: FrameCount;
92
+ direction?: TransitionDirection;
93
+ easing?: TransitionEasing;
94
+ }
95
+ export type EngineEvent = 'change' | 'track:added' | 'track:removed' | 'clip:added' | 'clip:removed' | 'clip:updated' | 'clip:split' | 'transition:added' | 'transition:removed' | 'history:change';
96
+ export type EngineEventPayload = {
97
+ change: Project;
98
+ 'track:added': Track;
99
+ 'track:removed': string;
100
+ 'clip:added': Clip;
101
+ 'clip:removed': {
102
+ clipId: string;
103
+ trackId: string;
104
+ };
105
+ 'clip:updated': Clip;
106
+ 'clip:split': {
107
+ leftId: string;
108
+ rightId: string;
109
+ trackId: string;
110
+ };
111
+ 'transition:added': Transition;
112
+ 'transition:removed': string;
113
+ 'history:change': {
114
+ canUndo: boolean;
115
+ canRedo: boolean;
116
+ };
117
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { Clip } from '../types';
2
+ export declare function toFrame(value: number): number;
3
+ export declare function secondsToFrames(seconds: number, fps: number): number;
4
+ export declare function framesToSeconds(frames: number, fps: number): number;
5
+ export declare function framesToTimecode(frames: number, fps: number): string;
6
+ export declare function getTotalFrames(clips: Record<string, Array<{
7
+ startFrame: number;
8
+ durationFrames: number;
9
+ }>>): number;
10
+ export declare function clipsOverlap(a: {
11
+ startFrame: number;
12
+ durationFrames: number;
13
+ }, b: {
14
+ startFrame: number;
15
+ durationFrames: number;
16
+ }): boolean;
17
+ export declare function findOverlaps(trackClips: Clip[], candidate: {
18
+ startFrame: number;
19
+ durationFrames: number;
20
+ }, excludeId?: string): Clip[];