@shotstack/shotstack-studio 1.0.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 (45) hide show
  1. package/LICENSE +164 -0
  2. package/dist/core/animations/curve-interpolator.d.ts +6 -0
  3. package/dist/core/animations/effect-preset-builder.d.ts +18 -0
  4. package/dist/core/animations/keyframe-builder.d.ts +12 -0
  5. package/dist/core/animations/transition-preset-builder.d.ts +20 -0
  6. package/dist/core/entities/audio-player.d.ts +17 -0
  7. package/dist/core/entities/edit.d.ts +46 -0
  8. package/dist/core/entities/entity.d.ts +5 -0
  9. package/dist/core/entities/html-player.d.ts +17 -0
  10. package/dist/core/entities/image-player.d.ts +15 -0
  11. package/dist/core/entities/inspector.d.ts +18 -0
  12. package/dist/core/entities/luma-player.d.ts +18 -0
  13. package/dist/core/entities/player.d.ts +73 -0
  14. package/dist/core/entities/shape-player.d.ts +15 -0
  15. package/dist/core/entities/text-player.d.ts +18 -0
  16. package/dist/core/entities/video-player.d.ts +22 -0
  17. package/dist/core/events/asset-load-tracker.d.ts +16 -0
  18. package/dist/core/events/event-emitter.d.ts +10 -0
  19. package/dist/core/export/video-exporter.d.ts +17 -0
  20. package/dist/core/inputs/controls.d.ts +11 -0
  21. package/dist/core/inputs/pointer.d.ts +4 -0
  22. package/dist/core/layouts/geometry.d.ts +8 -0
  23. package/dist/core/layouts/position-builder.d.ts +8 -0
  24. package/dist/core/loaders/asset-loader.d.ts +9 -0
  25. package/dist/core/loaders/audio-load-parser.d.ts +11 -0
  26. package/dist/core/loaders/font-load-parser.d.ts +13 -0
  27. package/dist/core/schemas/asset.d.ts +648 -0
  28. package/dist/core/schemas/audio-asset.d.ts +82 -0
  29. package/dist/core/schemas/clip.d.ts +1185 -0
  30. package/dist/core/schemas/edit.d.ts +4061 -0
  31. package/dist/core/schemas/html-asset.d.ts +27 -0
  32. package/dist/core/schemas/image-asset.d.ts +57 -0
  33. package/dist/core/schemas/keyframe.d.ts +26 -0
  34. package/dist/core/schemas/luma-asset.d.ts +13 -0
  35. package/dist/core/schemas/shape-asset.d.ts +199 -0
  36. package/dist/core/schemas/text-asset.d.ts +155 -0
  37. package/dist/core/schemas/track.d.ts +1491 -0
  38. package/dist/core/schemas/video-asset.d.ts +126 -0
  39. package/dist/core/shotstack-canvas.d.ts +24 -0
  40. package/dist/index.d.ts +4 -0
  41. package/dist/main.d.ts +1 -0
  42. package/dist/shotstack-studio.es.js +5546 -0
  43. package/dist/shotstack-studio.umd.js +183 -0
  44. package/package.json +56 -0
  45. package/readme.md +298 -0
package/readme.md ADDED
@@ -0,0 +1,298 @@
1
+ # Shotstack Studio
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@shotstack/shotstack-studio.svg)](https://www.npmjs.com/package/@shotstack/shotstack-studio)
4
+ [![License](https://img.shields.io/badge/license-PolyForm_Shield-blue.svg)](https://polyformproject.org/licenses/shield/1.0.0/)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue.svg)](https://www.typescriptlang.org/)
6
+
7
+ A JavaScript library for creating and editing videos in the browser.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @shotstack/shotstack-studio
13
+ ```
14
+
15
+ ```bash
16
+ yarn add @shotstack/shotstack-studio
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```typescript
22
+ import { Edit, Canvas, Controls } from "@shotstack/shotstack-studio";
23
+ import myTemplateJson from "hello.json"
24
+
25
+ // 1. Retrieve an edit from a template
26
+ const templateUrl = 'https://shotstack-assets.s3.amazonaws.com/templates/hello-world/hello.json'
27
+ const response = await fetch(templateUrl);
28
+ const template = await response.json();
29
+
30
+ // 2. Initialize the edit with dimensions and background color
31
+ const edit = new Edit(template.output.size, template.timeline.background);
32
+ await edit.load();
33
+
34
+ // 3. Create a canvas to display the edit
35
+ const canvas = new Canvas(template.output.size, edit);
36
+ await canvas.load(); // Renders to [data-shotstack-studio] element
37
+
38
+ // 4. Load the template
39
+ await edit.loadEdit(myTemplateJson);
40
+
41
+ // 5. Add keyboard controls
42
+ const controls = new Controls(edit);
43
+ await controls.load();
44
+ ```
45
+
46
+ Your HTML should include a container with the `data-shotstack-studio` attribute:
47
+
48
+ ```html
49
+ <div data-shotstack-studio class="canvas-container"></div>
50
+ ```
51
+
52
+ ## Features
53
+
54
+ - Create video compositions with multiple tracks and clips
55
+ - Use in conjunction with the Shotstack Edit API to render video
56
+ - Export to video using browser-based FFmpeg
57
+
58
+ ## Main Components
59
+
60
+ ### Edit
61
+
62
+ The Edit class represents a video project with its timeline, clips, and properties.
63
+
64
+ ```typescript
65
+ // Create an edit with dimensions and background
66
+ const edit = new Edit({ width: 1280, height: 720 }, "#000000");
67
+ await edit.load();
68
+
69
+ // Load from template
70
+ await edit.loadEdit(templateJson);
71
+
72
+ // Playback controls
73
+ edit.play();
74
+ edit.pause();
75
+ edit.seek(2000); // Seek to 2 seconds (in milliseconds)
76
+ edit.stop(); // Stop and return to beginning
77
+
78
+ // Editing functions
79
+ edit.addClip(0, {
80
+ asset: {
81
+ type: "image",
82
+ src: "https://example.com/image.jpg"
83
+ },
84
+ start: 0,
85
+ length: 5
86
+ });
87
+
88
+ edit.addTrack(1, { clips: [] });
89
+ edit.deleteClip(0, 0);
90
+ edit.deleteTrack(1);
91
+
92
+ // Get edit information
93
+ const clip = edit.getClip(0, 0);
94
+ const track = edit.getTrack(0);
95
+ const editJson = edit.getEdit();
96
+ const duration = edit.totalDuration; // in milliseconds
97
+ ```
98
+
99
+ ### Canvas
100
+
101
+ The Canvas class provides the visual rendering of the edit.
102
+
103
+ ```typescript
104
+ // Create and load the canvas
105
+ const canvas = new Canvas(edit.size, edit);
106
+ await canvas.load();
107
+
108
+ // Zoom and positioning
109
+ canvas.centerEdit();
110
+ canvas.zoomToFit();
111
+ canvas.setZoom(1.5); // 1.0 is 100%, 0.5 is 50%, etc.
112
+ ```
113
+
114
+ ### Controls
115
+
116
+ The Controls class adds keyboard controls for playback.
117
+
118
+ ```typescript
119
+ const controls = new Controls(edit);
120
+ await controls.load();
121
+
122
+ // Available keyboard controls:
123
+ // Space - Play/Pause
124
+ // J - Stop
125
+ // K - Pause
126
+ // L - Play
127
+ // Left Arrow - Seek backward
128
+ // Right Arrow - Seek forward
129
+ // Shift + Arrow - Seek larger amount
130
+ // Comma - Step backward one frame
131
+ // Period - Step forward one frame
132
+ ```
133
+
134
+ ### VideoExporter
135
+
136
+ The VideoExporter class exports the edit to a video file.
137
+
138
+ ```typescript
139
+ const exporter = new VideoExporter(edit, canvas);
140
+ await exporter.export("my-video.mp4", 25); // filename, fps
141
+ ```
142
+
143
+ ## Template Format
144
+
145
+ Templates use a JSON format with the following structure:
146
+
147
+ ```typescript
148
+ {
149
+ timeline: {
150
+ background: "#000000",
151
+ fonts: [
152
+ { src: "https://example.com/font.ttf" }
153
+ ],
154
+ tracks: [
155
+ {
156
+ clips: [
157
+ {
158
+ asset: {
159
+ type: "image", // image, video, text, shape, audio
160
+ src: "https://example.com/image.jpg",
161
+ // Other asset properties depend on type
162
+ },
163
+ start: 0, // Start time in seconds
164
+ length: 5, // Duration in seconds
165
+ transition: { // Optional transitions
166
+ in: "fade",
167
+ out: "fade"
168
+ },
169
+ position: "center", // Positioning
170
+ scale: 1, // Scale factor
171
+ offset: {
172
+ x: 0.1, // X-axis offset relative to position
173
+ y: 0 // Y-axis offset relative to position
174
+ }
175
+ }
176
+ ]
177
+ }
178
+ ]
179
+ },
180
+ output: {
181
+ format: "mp4",
182
+ size: {
183
+ width: 1280,
184
+ height: 720
185
+ }
186
+ }
187
+ }
188
+ ```
189
+
190
+ ## License
191
+
192
+ PolyForm Shield License 1.0.0
193
+
194
+ ## API Reference
195
+
196
+ ### Edit
197
+
198
+ The `Edit` class represents a video editing project with its timeline, clips, and properties.
199
+
200
+ ```typescript
201
+ import { Edit } from "@shotstack/shotstack-studio";
202
+ import { EditSchema } from "@shotstack/shotstack-studio";
203
+ ```
204
+
205
+ #### Constructor
206
+
207
+ ```typescript
208
+ constructor(size: Size, backgroundColor: string = "#ffffff")
209
+ ```
210
+
211
+ Creates a new Edit instance with the specified dimensions and background color.
212
+
213
+ #### Properties
214
+
215
+ - `assetLoader` - Asset loader instance for managing media assets
216
+ - `events` - Event emitter for handling events
217
+ - `playbackTime` - Current playback position in milliseconds
218
+ - `totalDuration` - Total duration of the edit in milliseconds
219
+
220
+ #### Methods
221
+
222
+ - `async load()` - Initialize and prepare the edit for rendering
223
+ - `async loadEdit(edit: EditType)` - Load an edit from a JSON template
224
+ - `play()` - Start playback
225
+ - `pause()` - Pause playback
226
+ - `seek(target: number)` - Seek to a specific time in milliseconds
227
+ - `stop()` - Stop playback and return to beginning
228
+ - `addClip(trackIdx: number, clip: ClipType)` - Add a clip to a specific track
229
+ - `deleteClip(trackIdx: number, clipIdx: number)` - Delete a clip
230
+ - `getClip(trackIdx: number, clipIdx: number)` - Get a clip by track and index
231
+ - `addTrack(trackIdx: number, track: TrackType)` - Add a new track
232
+ - `getTrack(trackIdx: number)` - Get a track by index
233
+ - `deleteTrack(trackIdx: number)` - Delete a track
234
+ - `getEdit()` - Get the full edit configuration as a JSON object
235
+
236
+ ### Canvas
237
+
238
+ The `Canvas` class provides the visual rendering of the edit.
239
+
240
+ ```typescript
241
+ import { Canvas } from "@shotstack/shotstack-studio";
242
+ import type { Size } from "@shotstack/shotstack-studio";
243
+ ```
244
+
245
+ #### Constructor
246
+
247
+ ```typescript
248
+ constructor(size: Size, edit: Edit)
249
+ ```
250
+
251
+ Creates a new canvas with specified dimensions for rendering the edit.
252
+
253
+ #### Methods
254
+
255
+ - `async load()` - Initialize the canvas and add it to the DOM
256
+ - `centerEdit()` - Center the edit in the canvas
257
+ - `zoomToFit()` - Zoom to fit the entire edit
258
+ - `setZoom(zoom: number)` - Set zoom level
259
+
260
+ ### Controls
261
+
262
+ The `Controls` class adds keyboard controls for playback.
263
+
264
+ ```typescript
265
+ import { Controls } from "@shotstack/shotstack-studio";
266
+ ```
267
+
268
+ #### Constructor
269
+
270
+ ```typescript
271
+ constructor(edit: Edit)
272
+ ```
273
+
274
+ Creates a new controls instance for the provided Edit.
275
+
276
+ #### Methods
277
+
278
+ - `async load()` - Set up event listeners for keyboard controls
279
+
280
+ ### VideoExporter
281
+
282
+ The `VideoExporter` class handles exporting the edit to mp4.
283
+
284
+ ```typescript
285
+ import { VideoExporter } from "@shotstack/shotstack-studio";
286
+ ```
287
+
288
+ #### Constructor
289
+
290
+ ```typescript
291
+ constructor(edit: Edit, canvas: Canvas)
292
+ ```
293
+
294
+ Creates a new exporter for the provided Edit and Canvas.
295
+
296
+ #### Methods
297
+
298
+ - `async export(filename: string = "shotstack-export.mp4", fps: number = 25)` - Export the edit to a video file