@video-editor/protocol 0.0.1-beta.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @video-editor/shared
2
+
3
+ video editor libs common type
@@ -0,0 +1,423 @@
1
+ import { ComputedRef } from '@vue/reactivity';
2
+ import { DeepReadonly } from '@vue/reactivity';
3
+ import { file } from 'opfs-tools';
4
+ import { IAudioSegment } from '@video-editor/shared';
5
+ import { IEffectSegment } from '@video-editor/shared';
6
+ import { IFillMode } from '@video-editor/shared';
7
+ import { IFilterSegment } from '@video-editor/shared';
8
+ import { IFramesSegmentUnion } from '@video-editor/shared';
9
+ import { IImageSegment } from '@video-editor/shared';
10
+ import { ISamples } from './fetch';
11
+ import { ITextSegment } from '@video-editor/shared';
12
+ import { ITrackType } from '@video-editor/shared';
13
+ import { ITransition } from '@video-editor/shared';
14
+ import { IVideoProtocol } from '@video-editor/shared';
15
+ import { MP4File } from '@webav/mp4box.js';
16
+ import { MP4Info } from '@webav/mp4box.js';
17
+ import { MP4Sample } from '@webav/mp4box.js';
18
+ import { Ref } from '@vue/reactivity';
19
+ import { SegmentUnion } from '@video-editor/shared';
20
+ import { TrackTypeMapSegment } from '@video-editor/shared';
21
+ import { TrackUnion } from '@video-editor/shared';
22
+
23
+ export declare function createResourceManager(opts?: {
24
+ dir?: string;
25
+ }): {
26
+ add: (url: string) => Promise<void>;
27
+ get: (url: string) => Promise<void | HTMLImageElement | ISamples[]>;
28
+ remove: (url: string) => Promise<void>;
29
+ clear: () => Promise<void>;
30
+ };
31
+
32
+ export declare function createValidator(): {
33
+ verify: (o: object) => IVideoProtocol;
34
+ verifyBasic: (o: object) => Omit<IVideoProtocol, "tracks"> & {
35
+ tracks: object[];
36
+ };
37
+ verifyFramesSegment: (o: object) => IFramesSegmentUnion;
38
+ verifyTextSegment: (o: object) => ITextSegment;
39
+ verifyPhotoSegment: (o: object) => IImageSegment;
40
+ verifyAudioSegment: (o: object) => IAudioSegment;
41
+ verifyEffectSegment: (o: object) => IEffectSegment;
42
+ verifyFilterSegment: (o: object) => IFilterSegment;
43
+ verifyTrack: (o: object) => Omit<IVideoProtocol["tracks"][number], "children"> & {
44
+ children: object[];
45
+ };
46
+ verifySegment: (o: object & {
47
+ segmentType: ITrackType;
48
+ }) => IFramesSegmentUnion | IAudioSegment | IEffectSegment | IFilterSegment | IImageSegment | ITextSegment;
49
+ };
50
+
51
+ export declare function createVideoProtocolManager(protocol: IVideoProtocol): {
52
+ videoBasicInfo: {
53
+ version: `${number}.${number}.${number}`;
54
+ width: number;
55
+ height: number;
56
+ fps: number;
57
+ };
58
+ curTime: Ref<number, number>;
59
+ setSelectedSegment: (id?: SegmentUnion["id"]) => void;
60
+ selectedSegment: ComputedRef<DeepReadonly<SegmentUnion | undefined>>;
61
+ trackMap: ComputedRef< {
62
+ frames: readonly {
63
+ readonly trackId: string;
64
+ readonly trackType: "frames";
65
+ readonly children: readonly ({
66
+ readonly type: "video";
67
+ readonly fromTime?: number | undefined;
68
+ readonly volume?: number | undefined;
69
+ readonly playRate?: number | undefined;
70
+ readonly url: string;
71
+ readonly transform?: {
72
+ readonly position: readonly [number, number, number];
73
+ readonly rotation: readonly [number, number, number];
74
+ readonly scale: readonly [number, number, number];
75
+ } | undefined;
76
+ readonly opacity?: number | undefined;
77
+ readonly fillMode?: IFillMode | undefined;
78
+ readonly animation?: {
79
+ readonly id: string;
80
+ readonly name: string;
81
+ readonly duration: number;
82
+ readonly type: "in" | "out" | "combo";
83
+ readonly url?: string | undefined;
84
+ } | undefined;
85
+ readonly transitionIn?: {
86
+ readonly id: string;
87
+ readonly name: string;
88
+ readonly duration: number;
89
+ } | undefined;
90
+ readonly transitionOut?: {
91
+ readonly id: string;
92
+ readonly name: string;
93
+ readonly duration: number;
94
+ } | undefined;
95
+ readonly palette?: {
96
+ readonly temperature: number;
97
+ readonly hue: number;
98
+ readonly saturation: number;
99
+ readonly brightness: number;
100
+ readonly contrast: number;
101
+ readonly shine: number;
102
+ readonly highlight: number;
103
+ readonly shadow: number;
104
+ readonly sharpness: number;
105
+ readonly vignette: number;
106
+ readonly fade: number;
107
+ readonly grain: number;
108
+ } | undefined;
109
+ readonly background?: `rgba(${number},${number},${number},${number})` | undefined;
110
+ readonly id: string;
111
+ readonly startTime: number;
112
+ readonly endTime: number;
113
+ readonly segmentType: "frames";
114
+ } | {
115
+ readonly type: "image";
116
+ readonly format: "img" | "gif";
117
+ readonly url: string;
118
+ readonly transform?: {
119
+ readonly position: readonly [number, number, number];
120
+ readonly rotation: readonly [number, number, number];
121
+ readonly scale: readonly [number, number, number];
122
+ } | undefined;
123
+ readonly opacity?: number | undefined;
124
+ readonly fillMode?: IFillMode | undefined;
125
+ readonly animation?: {
126
+ readonly id: string;
127
+ readonly name: string;
128
+ readonly duration: number;
129
+ readonly type: "in" | "out" | "combo";
130
+ readonly url?: string | undefined;
131
+ } | undefined;
132
+ readonly transitionIn?: {
133
+ readonly id: string;
134
+ readonly name: string;
135
+ readonly duration: number;
136
+ } | undefined;
137
+ readonly transitionOut?: {
138
+ readonly id: string;
139
+ readonly name: string;
140
+ readonly duration: number;
141
+ } | undefined;
142
+ readonly palette?: {
143
+ readonly temperature: number;
144
+ readonly hue: number;
145
+ readonly saturation: number;
146
+ readonly brightness: number;
147
+ readonly contrast: number;
148
+ readonly shine: number;
149
+ readonly highlight: number;
150
+ readonly shadow: number;
151
+ readonly sharpness: number;
152
+ readonly vignette: number;
153
+ readonly fade: number;
154
+ readonly grain: number;
155
+ } | undefined;
156
+ readonly background?: `rgba(${number},${number},${number},${number})` | undefined;
157
+ readonly id: string;
158
+ readonly startTime: number;
159
+ readonly endTime: number;
160
+ readonly segmentType: "frames";
161
+ } | {
162
+ readonly type: "3D";
163
+ readonly url: string;
164
+ readonly transform?: {
165
+ readonly position: readonly [number, number, number];
166
+ readonly rotation: readonly [number, number, number];
167
+ readonly scale: readonly [number, number, number];
168
+ } | undefined;
169
+ readonly opacity?: number | undefined;
170
+ readonly fillMode?: IFillMode | undefined;
171
+ readonly animation?: {
172
+ readonly id: string;
173
+ readonly name: string;
174
+ readonly duration: number;
175
+ readonly type: "in" | "out" | "combo";
176
+ readonly url?: string | undefined;
177
+ } | undefined;
178
+ readonly transitionIn?: {
179
+ readonly id: string;
180
+ readonly name: string;
181
+ readonly duration: number;
182
+ } | undefined;
183
+ readonly transitionOut?: {
184
+ readonly id: string;
185
+ readonly name: string;
186
+ readonly duration: number;
187
+ } | undefined;
188
+ readonly palette?: {
189
+ readonly temperature: number;
190
+ readonly hue: number;
191
+ readonly saturation: number;
192
+ readonly brightness: number;
193
+ readonly contrast: number;
194
+ readonly shine: number;
195
+ readonly highlight: number;
196
+ readonly shadow: number;
197
+ readonly sharpness: number;
198
+ readonly vignette: number;
199
+ readonly fade: number;
200
+ readonly grain: number;
201
+ } | undefined;
202
+ readonly background?: `rgba(${number},${number},${number},${number})` | undefined;
203
+ readonly id: string;
204
+ readonly startTime: number;
205
+ readonly endTime: number;
206
+ readonly segmentType: "frames";
207
+ })[];
208
+ readonly isMain?: boolean | undefined;
209
+ }[];
210
+ text: readonly {
211
+ readonly trackId: string;
212
+ readonly trackType: "text";
213
+ readonly children: readonly {
214
+ readonly segmentType: "text";
215
+ readonly texts: readonly {
216
+ readonly content: string;
217
+ readonly align?: "left" | "center" | "right" | "justify" | undefined;
218
+ readonly dropShadow?: {
219
+ readonly color?: string | undefined;
220
+ readonly opacity?: number | undefined;
221
+ readonly blur?: number | undefined;
222
+ readonly distance?: number | undefined;
223
+ readonly angle?: number | undefined;
224
+ } | undefined;
225
+ readonly fontFamily?: string | readonly string[] | undefined;
226
+ readonly fontSize?: number | undefined;
227
+ readonly fontWeight?: "normal" | "bold" | "bolder" | "lighter" | "100" | "200" | "300" | "400" | "500" | "600" | "700" | "800" | "900" | undefined;
228
+ readonly fontStyle?: "normal" | "italic" | "oblique" | undefined;
229
+ readonly underline?: boolean | undefined;
230
+ readonly fill?: string | undefined;
231
+ readonly letterSpacing?: number | undefined;
232
+ readonly leading?: number | undefined;
233
+ readonly stroke?: {
234
+ readonly color?: string | undefined;
235
+ readonly width?: number | undefined;
236
+ readonly opacity?: number | undefined;
237
+ } | undefined;
238
+ readonly background?: {
239
+ readonly color?: string | undefined;
240
+ readonly opacity?: number | undefined;
241
+ } | undefined;
242
+ }[];
243
+ readonly transform?: {
244
+ readonly position: readonly [number, number, number];
245
+ readonly rotation: readonly [number, number, number];
246
+ readonly scale: readonly [number, number, number];
247
+ } | undefined;
248
+ readonly opacity?: number | undefined;
249
+ readonly animation?: {
250
+ readonly id: string;
251
+ readonly name: string;
252
+ readonly duration: number;
253
+ readonly type: "in" | "out" | "combo";
254
+ readonly url?: string | undefined;
255
+ } | undefined;
256
+ readonly id: string;
257
+ readonly startTime: number;
258
+ readonly endTime: number;
259
+ readonly url?: string | undefined;
260
+ }[];
261
+ }[];
262
+ image: readonly {
263
+ readonly trackId: string;
264
+ readonly trackType: "image";
265
+ readonly children: readonly {
266
+ readonly segmentType: "image";
267
+ readonly format: "img" | "gif";
268
+ readonly url: string;
269
+ readonly fillMode?: IFillMode | undefined;
270
+ readonly animation?: {
271
+ readonly id: string;
272
+ readonly name: string;
273
+ readonly duration: number;
274
+ readonly type: "in" | "out" | "combo";
275
+ readonly url?: string | undefined;
276
+ } | undefined;
277
+ readonly transform?: {
278
+ readonly position: readonly [number, number, number];
279
+ readonly rotation: readonly [number, number, number];
280
+ readonly scale: readonly [number, number, number];
281
+ } | undefined;
282
+ readonly palette?: {
283
+ readonly temperature: number;
284
+ readonly hue: number;
285
+ readonly saturation: number;
286
+ readonly brightness: number;
287
+ readonly contrast: number;
288
+ readonly shine: number;
289
+ readonly highlight: number;
290
+ readonly shadow: number;
291
+ readonly sharpness: number;
292
+ readonly vignette: number;
293
+ readonly fade: number;
294
+ readonly grain: number;
295
+ } | undefined;
296
+ readonly id: string;
297
+ readonly startTime: number;
298
+ readonly endTime: number;
299
+ }[];
300
+ }[];
301
+ audio: readonly {
302
+ readonly trackId: string;
303
+ readonly trackType: "audio";
304
+ readonly children: readonly {
305
+ readonly segmentType: "audio";
306
+ readonly url: string;
307
+ readonly fromTime?: number | undefined;
308
+ readonly volume?: number | undefined;
309
+ readonly fadeInDuration?: number | undefined;
310
+ readonly fadeOutDuration?: number | undefined;
311
+ readonly playRate?: number | undefined;
312
+ readonly id: string;
313
+ readonly startTime: number;
314
+ readonly endTime: number;
315
+ }[];
316
+ }[];
317
+ effect: readonly {
318
+ readonly trackId: string;
319
+ readonly trackType: "effect";
320
+ readonly children: readonly {
321
+ readonly segmentType: "effect";
322
+ readonly effectId: string;
323
+ readonly name: string;
324
+ readonly id: string;
325
+ readonly startTime: number;
326
+ readonly endTime: number;
327
+ readonly url?: string | undefined;
328
+ }[];
329
+ }[];
330
+ filter: readonly {
331
+ readonly trackId: string;
332
+ readonly trackType: "filter";
333
+ readonly children: readonly {
334
+ readonly segmentType: "filter";
335
+ readonly filterId: string;
336
+ readonly name: string;
337
+ readonly intensity?: number | undefined;
338
+ readonly id: string;
339
+ readonly startTime: number;
340
+ readonly endTime: number;
341
+ readonly url?: string | undefined;
342
+ }[];
343
+ }[];
344
+ }>;
345
+ segmentMap: ComputedRef<Record<string, DeepReadonly<SegmentUnion | undefined>>>;
346
+ getSegment: <T extends ITrackType>(id: SegmentUnion["id"], type?: T) => DeepReadonly<TrackTypeMapSegment[T]> | undefined;
347
+ addSegment: (segment: PartialByKeys<TrackTypeMapSegment[ITrackType], "id">) => string;
348
+ removeSegment: (id: SegmentUnion["id"]) => boolean;
349
+ updateSegment: <T extends ITrackType>(updater: (segment: TrackTypeMapSegment[T]) => void, id?: string, type?: T) => void;
350
+ exportProtocol: () => IVideoProtocol;
351
+ addTransition: (transition: ITransition, addTime?: number) => boolean;
352
+ removeTransition: (segmentId: string) => boolean;
353
+ updateTransition: (segmentId: string, updater: (transition: ITransition) => void) => boolean;
354
+ undo: () => void;
355
+ redo: () => void;
356
+ redoCount: ComputedRef<number>;
357
+ undoCount: ComputedRef<number>;
358
+ };
359
+
360
+ export declare const DUPLICATE_SEGMENT_ID = "duplicate segment id";
361
+
362
+ export declare const DUPLICATE_TRACK_ID = "duplicate track id";
363
+
364
+ export declare function fileTo(type: IResType): typeof fileToImage | typeof fileToMP4 | (() => Promise<void>) | (() => Promise<void>) | (() => Promise<void>);
365
+
366
+ declare function fileToImage(file: OPFSToolFile): Promise<HTMLImageElement | undefined>;
367
+
368
+ declare function fileToMP4(file: OPFSToolFile): Promise<ISamples_2[]>;
369
+
370
+ export declare function fileToMP4Samples(input: string | OPFSToolFile, cbs: {
371
+ onReady?: (data: {
372
+ info: MP4Info;
373
+ mp4BoxFile: MP4File;
374
+ }) => void;
375
+ onSamples?: (data: ISamples_2) => void;
376
+ onDone?: () => void;
377
+ onError?: (err: Error) => void;
378
+ }): Promise<{
379
+ stop: () => void;
380
+ }>;
381
+
382
+ export declare function getResourceType(url: string): Promise<{
383
+ type: IResType;
384
+ totalSize: number;
385
+ }>;
386
+
387
+ declare type IResType = keyof IResTypeMap;
388
+
389
+ declare interface IResTypeMap {
390
+ image: HTMLImageElement;
391
+ video: ISamples_2[];
392
+ audio: 'audio';
393
+ font: 'font';
394
+ model: 'model';
395
+ }
396
+
397
+ declare interface ISamples_2 {
398
+ id: number;
399
+ type: 'video' | 'audio';
400
+ samples: MP4Sample[];
401
+ }
402
+
403
+ export { ITrackType }
404
+
405
+ export { IVideoProtocol }
406
+
407
+ declare type OPFSToolFile = ReturnType<typeof file>;
408
+
409
+ export declare const parse: parseFn;
410
+
411
+ declare type parseFn = (videoProtocolStr: string) => object;
412
+
413
+ declare type PartialByKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
414
+
415
+ export { SegmentUnion }
416
+
417
+ export { TrackTypeMapSegment }
418
+
419
+ export { TrackUnion }
420
+
421
+ export declare function vFetch(url: string, init?: RequestInit): Promise<Response>;
422
+
423
+ export { }