@slidevideo/cli 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.
- package/CHANGELOG.md +33 -0
- package/IMPRESSUM.md +13 -0
- package/LICENSE-TERMS.md +58 -0
- package/README.md +25 -0
- package/addons/slidevideo/geometry.ts +127 -0
- package/addons/slidevideo/global-top.vue +232 -0
- package/addons/slidevideo/package.json +1 -0
- package/addons/slidevideo/playback-entries.ts +14 -0
- package/addons/slidevideo/preview.ts +157 -0
- package/dist/adapters/browser-runtime.d.ts +37 -0
- package/dist/adapters/browser-runtime.js +1 -0
- package/dist/adapters/edge.d.ts +7 -0
- package/dist/adapters/edge.js +46 -0
- package/dist/adapters/elevenlabs.d.ts +7 -0
- package/dist/adapters/elevenlabs.js +58 -0
- package/dist/adapters/powerpoint-preview.d.ts +2 -0
- package/dist/adapters/powerpoint-preview.js +18 -0
- package/dist/adapters/powerpoint.d.ts +21 -0
- package/dist/adapters/powerpoint.js +434 -0
- package/dist/adapters/registry.d.ts +4 -0
- package/dist/adapters/registry.js +13 -0
- package/dist/adapters/slidev-inputs.d.ts +1 -0
- package/dist/adapters/slidev-inputs.js +86 -0
- package/dist/adapters/slidev-inspection.d.ts +3 -0
- package/dist/adapters/slidev-inspection.js +79 -0
- package/dist/adapters/slidev-server.d.ts +1 -0
- package/dist/adapters/slidev-server.js +48 -0
- package/dist/adapters/slidev.d.ts +30 -0
- package/dist/adapters/slidev.js +251 -0
- package/dist/annotation-paint.d.ts +19 -0
- package/dist/annotation-paint.js +13 -0
- package/dist/annotations.d.ts +27 -0
- package/dist/annotations.js +115 -0
- package/dist/assembly.d.ts +48 -0
- package/dist/assembly.js +138 -0
- package/dist/calibration.d.ts +24 -0
- package/dist/calibration.js +346 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +180 -0
- package/dist/compositor.d.ts +18 -0
- package/dist/compositor.js +155 -0
- package/dist/contracts.d.ts +358 -0
- package/dist/contracts.js +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +15 -0
- package/dist/executables.d.ts +23 -0
- package/dist/executables.js +165 -0
- package/dist/installation.d.ts +6 -0
- package/dist/installation.js +32 -0
- package/dist/license-key.d.ts +12 -0
- package/dist/license-key.js +55 -0
- package/dist/license-status.d.ts +16 -0
- package/dist/license-status.js +12 -0
- package/dist/media.d.ts +12 -0
- package/dist/media.js +57 -0
- package/dist/overlay-assets.d.ts +2 -0
- package/dist/overlay-assets.js +58 -0
- package/dist/pipeline.d.ts +50 -0
- package/dist/pipeline.js +257 -0
- package/dist/preview/contracts.d.ts +34 -0
- package/dist/preview/contracts.js +1 -0
- package/dist/preview/player.d.ts +1 -0
- package/dist/preview/player.js +129 -0
- package/dist/preview/server.d.ts +1 -0
- package/dist/preview/server.js +112 -0
- package/dist/preview/view.d.ts +1 -0
- package/dist/preview/view.js +36 -0
- package/dist/revoked-keys.json +1 -0
- package/dist/run.d.ts +12 -0
- package/dist/run.js +109 -0
- package/dist/setup-install.d.ts +7 -0
- package/dist/setup-install.js +98 -0
- package/dist/setup-license.d.ts +2 -0
- package/dist/setup-license.js +63 -0
- package/dist/setup.d.ts +34 -0
- package/dist/setup.js +218 -0
- package/dist/speech.d.ts +6 -0
- package/dist/speech.js +125 -0
- package/dist/storyboard.d.ts +6 -0
- package/dist/storyboard.js +86 -0
- package/dist/timing.d.ts +6 -0
- package/dist/timing.js +162 -0
- package/package.json +134 -0
- package/schemas/annotation-geometry.v1.json +130 -0
- package/schemas/revoked-keys.schema.json +11 -0
- package/schemas/run-manifest.v1.json +96 -0
- package/schemas/schedule.v1.json +108 -0
- package/schemas/schedule.v2.json +496 -0
- package/schemas/speech.v1.json +173 -0
- package/schemas/storyboard.v1.json +461 -0
- package/schemas/storyboard.v2.json +802 -0
- package/schemas/timing-evidence.v1.json +129 -0
- package/skills/slidevideo/SKILL.md +56 -0
- package/skills/slidevideo/references/production.md +76 -0
- package/skills/slidevideo/references/storyboard.md +272 -0
- package/tools/edge-tts/edge-tts.py +19 -0
- package/tools/edge-tts/requirements.lock +34 -0
- package/tools/powerpoint/Native.cs +277 -0
- package/tools/powerpoint/powerpoint.ps1 +714 -0
- package/tools/powerpoint/preview.ps1 +100 -0
- package/tools/powerpoint/requirements.json +11 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
export type ProgressReporter = (operation: string) => void;
|
|
2
|
+
export type Voice = {
|
|
3
|
+
provider: string;
|
|
4
|
+
voice: string;
|
|
5
|
+
options?: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export type Narration = {
|
|
8
|
+
id: string;
|
|
9
|
+
text: string;
|
|
10
|
+
voice?: Voice;
|
|
11
|
+
};
|
|
12
|
+
export type VisualAction = {
|
|
13
|
+
type: 'slide';
|
|
14
|
+
target: string;
|
|
15
|
+
duration_ms: number;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'reveal';
|
|
18
|
+
click: number;
|
|
19
|
+
duration_ms: number;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'play';
|
|
22
|
+
media: string;
|
|
23
|
+
audio: 'source' | 'muted';
|
|
24
|
+
volume: number;
|
|
25
|
+
trim_start_ms?: number;
|
|
26
|
+
trim_end_ms?: number;
|
|
27
|
+
rate?: number;
|
|
28
|
+
};
|
|
29
|
+
export type Action = (VisualAction | {
|
|
30
|
+
type: 'speak';
|
|
31
|
+
segment: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'hold';
|
|
34
|
+
duration_ms: number;
|
|
35
|
+
}) & {
|
|
36
|
+
id: string;
|
|
37
|
+
};
|
|
38
|
+
export type PhraseCue = {
|
|
39
|
+
segment: string;
|
|
40
|
+
phrase: string;
|
|
41
|
+
occurrence?: number;
|
|
42
|
+
boundary: 'start' | 'end';
|
|
43
|
+
offset_ms: number;
|
|
44
|
+
};
|
|
45
|
+
export type Cue = {
|
|
46
|
+
id: string;
|
|
47
|
+
at: PhraseCue;
|
|
48
|
+
action: VisualAction;
|
|
49
|
+
};
|
|
50
|
+
export type Rectangle = {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
};
|
|
56
|
+
export type AnnotationTarget = ({
|
|
57
|
+
type: 'region';
|
|
58
|
+
units: 'normalized';
|
|
59
|
+
} & Rectangle) | {
|
|
60
|
+
type: 'element';
|
|
61
|
+
selector: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'shape';
|
|
64
|
+
id: number;
|
|
65
|
+
};
|
|
66
|
+
export type Annotation = {
|
|
67
|
+
id: string;
|
|
68
|
+
scene: string;
|
|
69
|
+
target: AnnotationTarget;
|
|
70
|
+
effect: 'highlight';
|
|
71
|
+
appearance: {
|
|
72
|
+
color: string;
|
|
73
|
+
opacity: number;
|
|
74
|
+
blend?: 'source-over' | 'darken';
|
|
75
|
+
padding: {
|
|
76
|
+
units: 'normalized';
|
|
77
|
+
x: number;
|
|
78
|
+
y: number;
|
|
79
|
+
};
|
|
80
|
+
bottom_border?: {
|
|
81
|
+
color: string;
|
|
82
|
+
opacity: number;
|
|
83
|
+
units: 'normalized';
|
|
84
|
+
height: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
at: PhraseCue;
|
|
88
|
+
duration_ms: number;
|
|
89
|
+
};
|
|
90
|
+
export type ResolvedAnnotation = Annotation & {
|
|
91
|
+
start_ms: number;
|
|
92
|
+
end_ms: number;
|
|
93
|
+
slide: string;
|
|
94
|
+
visit: string;
|
|
95
|
+
click: number;
|
|
96
|
+
cue_span: {
|
|
97
|
+
segment: string;
|
|
98
|
+
start: number;
|
|
99
|
+
end: number;
|
|
100
|
+
form: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
export type AnnotationGeometry = {
|
|
104
|
+
id: string;
|
|
105
|
+
scene: string;
|
|
106
|
+
slide: string;
|
|
107
|
+
visit: string;
|
|
108
|
+
click: number;
|
|
109
|
+
start_ms: number;
|
|
110
|
+
end_ms: number;
|
|
111
|
+
observed_start_ms: number;
|
|
112
|
+
observed_end_ms: number;
|
|
113
|
+
viewport: {
|
|
114
|
+
width: number;
|
|
115
|
+
height: number;
|
|
116
|
+
};
|
|
117
|
+
content: Rectangle;
|
|
118
|
+
bounds: Rectangle;
|
|
119
|
+
samples: number;
|
|
120
|
+
};
|
|
121
|
+
export type ImageOverlay = {
|
|
122
|
+
id: string;
|
|
123
|
+
src: string;
|
|
124
|
+
box: Rectangle;
|
|
125
|
+
opacity: number;
|
|
126
|
+
scene?: string;
|
|
127
|
+
hide_in_scenes?: string[];
|
|
128
|
+
visible?: {
|
|
129
|
+
start: number | PhraseCue;
|
|
130
|
+
end: number | PhraseCue;
|
|
131
|
+
fade_in_ms?: number;
|
|
132
|
+
fade_out_ms?: number;
|
|
133
|
+
}[];
|
|
134
|
+
};
|
|
135
|
+
export type OverlayInterval = {
|
|
136
|
+
start_ms: number;
|
|
137
|
+
end_ms: number;
|
|
138
|
+
fade_in_ms: number;
|
|
139
|
+
fade_out_ms: number;
|
|
140
|
+
};
|
|
141
|
+
export type ResolvedOverlay = Pick<ImageOverlay, 'id' | 'src' | 'box' | 'opacity'> & {
|
|
142
|
+
visible: OverlayInterval[];
|
|
143
|
+
hidden: {
|
|
144
|
+
start_ms: number;
|
|
145
|
+
end_ms: number;
|
|
146
|
+
}[];
|
|
147
|
+
};
|
|
148
|
+
export type Storyboard = {
|
|
149
|
+
version: 1 | 2;
|
|
150
|
+
deck: string;
|
|
151
|
+
voice?: Voice;
|
|
152
|
+
output: {
|
|
153
|
+
width: number;
|
|
154
|
+
height: number;
|
|
155
|
+
fps: number;
|
|
156
|
+
};
|
|
157
|
+
media: {
|
|
158
|
+
id: string;
|
|
159
|
+
src: string;
|
|
160
|
+
}[];
|
|
161
|
+
narration: Narration[];
|
|
162
|
+
scenes: {
|
|
163
|
+
id: string;
|
|
164
|
+
slide: string;
|
|
165
|
+
duration_ms?: number;
|
|
166
|
+
actions: Action[];
|
|
167
|
+
}[];
|
|
168
|
+
cues: Cue[];
|
|
169
|
+
annotations?: Annotation[];
|
|
170
|
+
overlays?: ImageOverlay[];
|
|
171
|
+
};
|
|
172
|
+
export type Alignment = {
|
|
173
|
+
form: 'original' | 'normalized';
|
|
174
|
+
granularity: 'character' | 'word' | 'phrase';
|
|
175
|
+
text: string;
|
|
176
|
+
units: {
|
|
177
|
+
text: string;
|
|
178
|
+
start: number;
|
|
179
|
+
end: number;
|
|
180
|
+
start_ms: number;
|
|
181
|
+
end_ms: number;
|
|
182
|
+
}[];
|
|
183
|
+
};
|
|
184
|
+
export type SpeechAsset = {
|
|
185
|
+
id: string;
|
|
186
|
+
key: string;
|
|
187
|
+
audio: string;
|
|
188
|
+
sha256: string;
|
|
189
|
+
format: string;
|
|
190
|
+
duration_ms: number;
|
|
191
|
+
transcript: {
|
|
192
|
+
original: string;
|
|
193
|
+
normalized: string;
|
|
194
|
+
};
|
|
195
|
+
alignment: Alignment | null;
|
|
196
|
+
provenance: {
|
|
197
|
+
adapter: string;
|
|
198
|
+
version: string;
|
|
199
|
+
provider: string;
|
|
200
|
+
voice: string;
|
|
201
|
+
options: Record<string, unknown>;
|
|
202
|
+
generated_at: string;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
export type SpeechManifest = {
|
|
206
|
+
version: 1;
|
|
207
|
+
assets: SpeechAsset[];
|
|
208
|
+
};
|
|
209
|
+
export type ScheduledAction = {
|
|
210
|
+
id: string;
|
|
211
|
+
scene: string;
|
|
212
|
+
start_ms: number;
|
|
213
|
+
end_ms: number;
|
|
214
|
+
action: Action | ({
|
|
215
|
+
id: string;
|
|
216
|
+
} & VisualAction);
|
|
217
|
+
cue_span?: {
|
|
218
|
+
segment: string;
|
|
219
|
+
start: number;
|
|
220
|
+
end: number;
|
|
221
|
+
form: string;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
export type Schedule = {
|
|
225
|
+
version: 1 | 2;
|
|
226
|
+
duration_ms: number;
|
|
227
|
+
actions: ScheduledAction[];
|
|
228
|
+
media: {
|
|
229
|
+
id: string;
|
|
230
|
+
src: string;
|
|
231
|
+
duration_ms: number;
|
|
232
|
+
has_audio: boolean;
|
|
233
|
+
}[];
|
|
234
|
+
annotations?: ResolvedAnnotation[];
|
|
235
|
+
overlays?: ResolvedOverlay[];
|
|
236
|
+
};
|
|
237
|
+
export type ObservedEvent = {
|
|
238
|
+
id: string;
|
|
239
|
+
type: string;
|
|
240
|
+
scheduled_ms: number;
|
|
241
|
+
observed_ms: number;
|
|
242
|
+
media_ms?: number;
|
|
243
|
+
error?: string;
|
|
244
|
+
};
|
|
245
|
+
export type MediaProperties = {
|
|
246
|
+
width: number;
|
|
247
|
+
height: number;
|
|
248
|
+
duration_ms: number;
|
|
249
|
+
fps: number;
|
|
250
|
+
has_audio: boolean;
|
|
251
|
+
};
|
|
252
|
+
export type CaptureMapping = {
|
|
253
|
+
offset_ms: number;
|
|
254
|
+
rate: number;
|
|
255
|
+
trim_start_ms: number;
|
|
256
|
+
trim_end_ms: number;
|
|
257
|
+
offset_min_ms?: number;
|
|
258
|
+
offset_max_ms?: number;
|
|
259
|
+
};
|
|
260
|
+
export type TimingEvidence = {
|
|
261
|
+
version: 1;
|
|
262
|
+
status: 'accepted' | 'failed' | 'not_evaluated';
|
|
263
|
+
target_ms: number;
|
|
264
|
+
uncertainty_ms: number;
|
|
265
|
+
mapping: CaptureMapping;
|
|
266
|
+
checks: {
|
|
267
|
+
id: string;
|
|
268
|
+
expected_ms: number;
|
|
269
|
+
observed_ms: number;
|
|
270
|
+
error_ms: number;
|
|
271
|
+
evidence: string;
|
|
272
|
+
frame_index?: number;
|
|
273
|
+
capture_ms?: number;
|
|
274
|
+
uncertainty_ms?: number;
|
|
275
|
+
bracket_start_ms?: number;
|
|
276
|
+
bracket_end_ms?: number;
|
|
277
|
+
}[];
|
|
278
|
+
coverage: string[];
|
|
279
|
+
gaps: string[];
|
|
280
|
+
};
|
|
281
|
+
export type CaptureOrigin = {
|
|
282
|
+
method: 'opening_markers' | 'decoded_markers';
|
|
283
|
+
uncertainty_ms: number;
|
|
284
|
+
mapping: CaptureMapping;
|
|
285
|
+
};
|
|
286
|
+
export type ProductionOptions = {
|
|
287
|
+
verify_timing: boolean;
|
|
288
|
+
};
|
|
289
|
+
export type VisualArtifact = {
|
|
290
|
+
version: 1;
|
|
291
|
+
file: string;
|
|
292
|
+
properties: MediaProperties;
|
|
293
|
+
events: ObservedEvent[];
|
|
294
|
+
origin?: CaptureOrigin;
|
|
295
|
+
timing: TimingEvidence;
|
|
296
|
+
annotation_geometry?: AnnotationGeometry[];
|
|
297
|
+
provenance: {
|
|
298
|
+
adapter: string;
|
|
299
|
+
version: string;
|
|
300
|
+
dependencies?: Record<string, string>;
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
export interface TtsAdapter {
|
|
304
|
+
id: string;
|
|
305
|
+
version: string;
|
|
306
|
+
validate(voice: Voice): void;
|
|
307
|
+
synthesize(segment: Narration, voice: Voice, destination: string): Promise<Omit<SpeechAsset, 'key'>>;
|
|
308
|
+
}
|
|
309
|
+
export type PresentationInspection = {
|
|
310
|
+
slides: {
|
|
311
|
+
id: string;
|
|
312
|
+
index: number;
|
|
313
|
+
clicks: number;
|
|
314
|
+
clicks_known?: boolean;
|
|
315
|
+
}[];
|
|
316
|
+
media_ids: string[];
|
|
317
|
+
files: string[];
|
|
318
|
+
capabilities: string[];
|
|
319
|
+
annotation_targets?: {
|
|
320
|
+
slide: string;
|
|
321
|
+
targets: {
|
|
322
|
+
identity: string;
|
|
323
|
+
description: string;
|
|
324
|
+
}[];
|
|
325
|
+
}[];
|
|
326
|
+
};
|
|
327
|
+
export interface PresentationAdapter {
|
|
328
|
+
id: string;
|
|
329
|
+
version: string;
|
|
330
|
+
inspect(deck: string): Promise<PresentationInspection>;
|
|
331
|
+
inspectTargets?(storyboard: Storyboard): Promise<PresentationInspection['annotation_targets']>;
|
|
332
|
+
validate(storyboard: Storyboard, inspection: PresentationInspection, schedule?: Schedule): void;
|
|
333
|
+
startPreview?(storyboard: Storyboard, schedule: Schedule, directory: string, parentOrigin: string): Promise<import('./preview/contracts.js').PreviewSession>;
|
|
334
|
+
prepare(storyboard: Storyboard, schedule: Schedule, directory: string, options?: ProductionOptions): Promise<void>;
|
|
335
|
+
execute(progress?: ProgressReporter): Promise<VisualArtifact>;
|
|
336
|
+
cleanup(): Promise<void>;
|
|
337
|
+
}
|
|
338
|
+
export type Stage = 'validate' | 'tts' | 'resolve' | 'record' | 'assemble';
|
|
339
|
+
export type RunManifest = {
|
|
340
|
+
version: 1;
|
|
341
|
+
run_id: string;
|
|
342
|
+
created_at: string;
|
|
343
|
+
storyboard: string;
|
|
344
|
+
input_hash: string;
|
|
345
|
+
inputs: Record<string, string>;
|
|
346
|
+
versions: Record<string, string>;
|
|
347
|
+
stages: Partial<Record<Stage, {
|
|
348
|
+
status: 'running' | 'completed' | 'failed';
|
|
349
|
+
artifacts: Record<string, string>;
|
|
350
|
+
error?: {
|
|
351
|
+
code: string;
|
|
352
|
+
message: string;
|
|
353
|
+
};
|
|
354
|
+
}>>;
|
|
355
|
+
verify_timing?: boolean;
|
|
356
|
+
assembly_licensed?: boolean;
|
|
357
|
+
output?: string;
|
|
358
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class ProductionError extends Error {
|
|
2
|
+
code: string;
|
|
3
|
+
exitCode: number;
|
|
4
|
+
context: Record<string, unknown>;
|
|
5
|
+
constructor(code: string, message: string, exitCode?: number, context?: Record<string, unknown>);
|
|
6
|
+
}
|
|
7
|
+
export declare function requireCondition(condition: unknown, code: string, message: string, exitCode?: number, context?: Record<string, unknown>): asserts condition;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class ProductionError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
exitCode;
|
|
4
|
+
context;
|
|
5
|
+
constructor(code, message, exitCode = 2, context = {}) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.exitCode = exitCode;
|
|
9
|
+
this.context = context;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function requireCondition(condition, code, message, exitCode = 2, context = {}) {
|
|
13
|
+
if (!condition)
|
|
14
|
+
throw new ProductionError(code, message, exitCode, context);
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const toolNames: readonly ["browser", "python", "ffmpeg", "ffprobe"];
|
|
2
|
+
type Tool = typeof toolNames[number];
|
|
3
|
+
export type ToolPaths = Partial<Record<Tool, string>>;
|
|
4
|
+
type Candidate = {
|
|
5
|
+
path: string;
|
|
6
|
+
source: 'override' | 'environment' | 'config' | 'discovery';
|
|
7
|
+
};
|
|
8
|
+
type Browser = {
|
|
9
|
+
path: string;
|
|
10
|
+
name: 'Chromium' | 'Google Chrome' | 'Microsoft Edge' | 'Custom browser';
|
|
11
|
+
};
|
|
12
|
+
export declare function withExecutables<T>(overrides: ToolPaths, run: () => T): T;
|
|
13
|
+
export declare function configuredLicense(): boolean;
|
|
14
|
+
export declare function saveExecutablePaths(paths: ToolPaths): Promise<void>;
|
|
15
|
+
export declare function saveLicenseKey(key: string | null): Promise<void>;
|
|
16
|
+
export declare function isExecutable(path: string): boolean;
|
|
17
|
+
export declare function findOnPath(command: string, extraDirectories?: string[]): string | undefined;
|
|
18
|
+
export declare function browserCandidates(): Browser[];
|
|
19
|
+
export declare function browserName(path: string): Browser['name'];
|
|
20
|
+
export declare function toolCandidate(tool: Tool): Candidate | undefined;
|
|
21
|
+
export declare function discoverExecutable(tool: Tool): string | undefined;
|
|
22
|
+
export declare function executable(tool: Tool): string;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { accessSync, constants, readFileSync, statSync } from 'node:fs';
|
|
4
|
+
import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
6
|
+
import { chromium } from 'playwright';
|
|
7
|
+
import { ProductionError, requireCondition } from './errors.js';
|
|
8
|
+
import { edgePython, managedBrowserDirectory, userConfigFile } from './installation.js';
|
|
9
|
+
import { licenseStatus, revocationMessage } from './license-status.js';
|
|
10
|
+
export const toolNames = ['browser', 'python', 'ffmpeg', 'ffprobe'];
|
|
11
|
+
const windows = process.platform === 'win32';
|
|
12
|
+
const environmentPaths = { browser: 'SLIDEVIDEO_CHROMIUM', python: 'SLIDEVIDEO_PYTHON' };
|
|
13
|
+
const executableScope = new AsyncLocalStorage();
|
|
14
|
+
function readConfig() {
|
|
15
|
+
const file = userConfigFile();
|
|
16
|
+
try {
|
|
17
|
+
const configuration = JSON.parse(readFileSync(file, 'utf8'));
|
|
18
|
+
if (configuration?.version !== 1 ||
|
|
19
|
+
(configuration.licensed !== undefined && typeof configuration.licensed !== 'boolean')) {
|
|
20
|
+
throw new Error('Expected version 1 and an optional boolean licensed field');
|
|
21
|
+
}
|
|
22
|
+
const paths = configuration.paths;
|
|
23
|
+
if (paths !== undefined && (!paths || typeof paths !== 'object' || Array.isArray(paths) ||
|
|
24
|
+
Object.entries(paths).some(([tool, path]) => !toolNames.some(name => name === tool) || typeof path !== 'string' || !isAbsolute(path)))) {
|
|
25
|
+
throw new Error('Expected absolute executable paths');
|
|
26
|
+
}
|
|
27
|
+
return configuration;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code === 'ENOENT')
|
|
31
|
+
return { version: 1 };
|
|
32
|
+
throw new ProductionError('TOOL_CONFIG', `Cannot read ${file}: ${error instanceof SyntaxError ? 'invalid JSON' : error.message}`, 3);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function withExecutables(overrides, run) {
|
|
36
|
+
return executableScope.run({ overrides, configuration: readConfig() }, run);
|
|
37
|
+
}
|
|
38
|
+
export function configuredLicense() {
|
|
39
|
+
const { status } = licenseStatus((executableScope.getStore()?.configuration ?? readConfig()).license_key);
|
|
40
|
+
if (status === 'revoked')
|
|
41
|
+
console.error(revocationMessage);
|
|
42
|
+
return status === 'active';
|
|
43
|
+
}
|
|
44
|
+
export function saveExecutablePaths(paths) {
|
|
45
|
+
return updateConfig(configuration => { configuration.paths = { ...configuration.paths, ...paths }; });
|
|
46
|
+
}
|
|
47
|
+
export function saveLicenseKey(key) {
|
|
48
|
+
return updateConfig(configuration => {
|
|
49
|
+
delete configuration.licensed;
|
|
50
|
+
if (key === null)
|
|
51
|
+
delete configuration.license_key;
|
|
52
|
+
else
|
|
53
|
+
configuration.license_key = key;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function updateConfig(update) {
|
|
57
|
+
const file = userConfigFile();
|
|
58
|
+
const lock = `${file}.lock`;
|
|
59
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
60
|
+
try {
|
|
61
|
+
await mkdir(lock, { mode: 0o700 });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error.code !== 'EEXIST')
|
|
65
|
+
throw error;
|
|
66
|
+
throw new ProductionError('TOOL_CONFIG', `Another setup owns ${lock}. If it was interrupted, remove the empty lock directory and retry.`, 3);
|
|
67
|
+
}
|
|
68
|
+
const temporary = join(lock, randomUUID());
|
|
69
|
+
try {
|
|
70
|
+
const configuration = readConfig();
|
|
71
|
+
update(configuration);
|
|
72
|
+
await writeFile(temporary, JSON.stringify(configuration, null, 2) + '\n', { mode: 0o600 });
|
|
73
|
+
await rename(temporary, file);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await rm(lock, { recursive: true, force: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function isExecutable(path) {
|
|
80
|
+
try {
|
|
81
|
+
accessSync(path, windows ? constants.F_OK : constants.X_OK);
|
|
82
|
+
return statSync(path).isFile();
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function findOnPath(command, extraDirectories = []) {
|
|
89
|
+
const directories = [...(process.env.PATH ?? '').split(delimiter), ...extraDirectories].filter(isAbsolute);
|
|
90
|
+
const filename = windows && !command.toLowerCase().endsWith('.exe') ? `${command}.exe` : command;
|
|
91
|
+
return directories.map(directory => join(directory, filename)).find(isExecutable);
|
|
92
|
+
}
|
|
93
|
+
export function browserCandidates() {
|
|
94
|
+
const found = new Map();
|
|
95
|
+
const record = (name, paths) => {
|
|
96
|
+
for (const path of paths)
|
|
97
|
+
if (path && isExecutable(path))
|
|
98
|
+
found.set(windows ? path.toLowerCase() : path, { name, path });
|
|
99
|
+
};
|
|
100
|
+
const windowsRoots = [process.env.LOCALAPPDATA, process.env.ProgramFiles, process.env['ProgramFiles(x86)']].filter((path) => !!path);
|
|
101
|
+
const locations = (...parts) => windowsRoots.map(root => join(root, ...parts));
|
|
102
|
+
record('Chromium', [
|
|
103
|
+
...(windows ? locations('Chromium', 'Application', 'chrome.exe') : ['/usr/lib/chromium/chromium']),
|
|
104
|
+
findOnPath('chromium'), findOnPath('chromium-browser'),
|
|
105
|
+
...(windows ? [] : ['/snap/bin/chromium']),
|
|
106
|
+
chromium.executablePath(),
|
|
107
|
+
]);
|
|
108
|
+
record('Google Chrome', [
|
|
109
|
+
findOnPath('google-chrome'), findOnPath('google-chrome-stable'),
|
|
110
|
+
...(windows ? [findOnPath('chrome'), ...locations('Google', 'Chrome', 'Application', 'chrome.exe')] : ['/opt/google/chrome/chrome']),
|
|
111
|
+
]);
|
|
112
|
+
record('Microsoft Edge', [
|
|
113
|
+
findOnPath('microsoft-edge'), findOnPath('microsoft-edge-stable'),
|
|
114
|
+
...(windows ? [findOnPath('msedge'), ...locations('Microsoft', 'Edge', 'Application', 'msedge.exe')] : ['/opt/microsoft/msedge/msedge']),
|
|
115
|
+
]);
|
|
116
|
+
return [...found.values()];
|
|
117
|
+
}
|
|
118
|
+
export function browserName(path) {
|
|
119
|
+
const managed = relative(managedBrowserDirectory(), path);
|
|
120
|
+
if (/^chromium-\d+[\\/]/.test(managed))
|
|
121
|
+
return 'Chromium';
|
|
122
|
+
const name = basename(path).toLowerCase();
|
|
123
|
+
return browserCandidates().find(browser => browser.path === path)?.name
|
|
124
|
+
?? (name.includes('edge') ? 'Microsoft Edge' : name.includes('chromium') ? 'Chromium'
|
|
125
|
+
: /(?:^|-)chrome(?:-stable)?(?:\.exe)?$/.test(name) ? 'Google Chrome' : 'Custom browser');
|
|
126
|
+
}
|
|
127
|
+
export function toolCandidate(tool) {
|
|
128
|
+
const context = executableScope.getStore();
|
|
129
|
+
const override = context?.overrides[tool];
|
|
130
|
+
if (override !== undefined) {
|
|
131
|
+
requireCondition(override.trim(), 'OPTION', `--${tool} requires an executable path`);
|
|
132
|
+
return { path: resolve(override), source: 'override' };
|
|
133
|
+
}
|
|
134
|
+
const variable = tool === 'browser' || tool === 'python' ? environmentPaths[tool] : undefined;
|
|
135
|
+
if (variable && process.env[variable]) {
|
|
136
|
+
const path = process.env[variable];
|
|
137
|
+
return { path: !/[\\/]/.test(path) && findOnPath(path) || resolve(path), source: 'environment' };
|
|
138
|
+
}
|
|
139
|
+
const saved = (context?.configuration ?? readConfig()).paths?.[tool];
|
|
140
|
+
if (saved)
|
|
141
|
+
return { path: saved, source: 'config' };
|
|
142
|
+
const path = discoverExecutable(tool);
|
|
143
|
+
return path ? { path, source: 'discovery' } : undefined;
|
|
144
|
+
}
|
|
145
|
+
export function discoverExecutable(tool) {
|
|
146
|
+
let path;
|
|
147
|
+
if (tool === 'browser')
|
|
148
|
+
path = browserCandidates().find(browser => browser.name === 'Chromium')?.path;
|
|
149
|
+
else if (tool === 'python') {
|
|
150
|
+
const managed = edgePython();
|
|
151
|
+
path = isExecutable(managed) ? managed : windows ? findOnPath('py') ?? findOnPath('python') : findOnPath('python3') ?? findOnPath('python');
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const wingetLinks = windows && process.env.LOCALAPPDATA ? [join(process.env.LOCALAPPDATA, 'Microsoft', 'WinGet', 'Links')] : [];
|
|
155
|
+
path = findOnPath(tool, wingetLinks);
|
|
156
|
+
}
|
|
157
|
+
return path;
|
|
158
|
+
}
|
|
159
|
+
export function executable(tool) {
|
|
160
|
+
const candidate = toolCandidate(tool);
|
|
161
|
+
if (candidate && isExecutable(candidate.path))
|
|
162
|
+
return candidate.path;
|
|
163
|
+
const code = tool === 'browser' ? 'BROWSER_DEPENDENCY' : 'DEPENDENCY';
|
|
164
|
+
throw new ProductionError(code, `${tool} executable is unavailable${candidate ? ` at ${candidate.path}` : ''}. Run slidevideo setup or pass --${tool} <path>.`, 3);
|
|
165
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function packagePath(...parts: string[]): string;
|
|
2
|
+
export declare function userDataDirectory(): string;
|
|
3
|
+
export declare function userConfigFile(): string;
|
|
4
|
+
export declare function managedBrowserDirectory(): string;
|
|
5
|
+
export declare function environmentPython(directory: string): string;
|
|
6
|
+
export declare function edgePython(): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { isAbsolute, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
const packageRoot = fileURLToPath(new URL('../', import.meta.url));
|
|
6
|
+
export function packagePath(...parts) {
|
|
7
|
+
return join(packageRoot, ...parts);
|
|
8
|
+
}
|
|
9
|
+
export function userDataDirectory() {
|
|
10
|
+
if (process.platform === 'win32') {
|
|
11
|
+
return join(process.env.LOCALAPPDATA || join(homedir(), 'AppData', 'Local'), 'SlideVideo');
|
|
12
|
+
}
|
|
13
|
+
const dataHome = process.env.XDG_DATA_HOME;
|
|
14
|
+
return join(dataHome && isAbsolute(dataHome) ? dataHome : join(homedir(), '.local', 'share'), 'slidevideo');
|
|
15
|
+
}
|
|
16
|
+
export function userConfigFile() {
|
|
17
|
+
if (process.platform === 'win32')
|
|
18
|
+
return join(userDataDirectory(), 'config.json');
|
|
19
|
+
const configHome = process.env.XDG_CONFIG_HOME;
|
|
20
|
+
return join(configHome && isAbsolute(configHome) ? configHome : join(homedir(), '.config'), 'slidevideo', 'config.json');
|
|
21
|
+
}
|
|
22
|
+
export function managedBrowserDirectory() {
|
|
23
|
+
return join(userDataDirectory(), 'browsers');
|
|
24
|
+
}
|
|
25
|
+
export function environmentPython(directory) {
|
|
26
|
+
return process.platform === 'win32' ? join(directory, 'Scripts', 'python.exe') : join(directory, 'bin', 'python');
|
|
27
|
+
}
|
|
28
|
+
export function edgePython() {
|
|
29
|
+
const managed = environmentPython(join(userDataDirectory(), 'edge-tts'));
|
|
30
|
+
const checkout = environmentPython(packagePath('.venv'));
|
|
31
|
+
return existsSync(managed) || !existsSync(checkout) ? managed : checkout;
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function isLicenseEmail(email: unknown): email is string;
|
|
2
|
+
export declare function encodeLicenseKey(email: string, date: string): string;
|
|
3
|
+
export declare function decodeLicenseKey(key: unknown): {
|
|
4
|
+
email: string;
|
|
5
|
+
date: string;
|
|
6
|
+
} | undefined;
|
|
7
|
+
export declare function inspectLicenseKey(input: unknown): {
|
|
8
|
+
key: string;
|
|
9
|
+
digest: string;
|
|
10
|
+
email: string;
|
|
11
|
+
date: string;
|
|
12
|
+
} | undefined;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
const prefix = 'SV1';
|
|
3
|
+
export function isLicenseEmail(email) {
|
|
4
|
+
if (typeof email !== 'string' || email.length > 254 || /[^\x21-\x7e]/.test(email))
|
|
5
|
+
return false;
|
|
6
|
+
const [local, domain, extra] = email.split('@');
|
|
7
|
+
return extra === undefined && !!domain && local.length <= 64 &&
|
|
8
|
+
/^[a-z\d!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z\d!#$%&'*+/=?^_`{|}~-]+)*$/i.test(local) &&
|
|
9
|
+
domain.split('.').every(label => /^[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?$/i.test(label));
|
|
10
|
+
}
|
|
11
|
+
function isLicenseDate(date) {
|
|
12
|
+
if (typeof date !== 'string' || date.length !== 10 || !/^\d{4}-\d{2}-\d{2}$/.test(date))
|
|
13
|
+
return false;
|
|
14
|
+
const parsed = new Date(`${date}T00:00:00.000Z`);
|
|
15
|
+
return Number.isFinite(parsed.getTime()) && parsed.toISOString().slice(0, 10) === date;
|
|
16
|
+
}
|
|
17
|
+
function checksum(payload) {
|
|
18
|
+
return createHash('sha256').update(`${prefix}.${payload}`).digest('hex').slice(0, 12);
|
|
19
|
+
}
|
|
20
|
+
function encodePayload(email, date, nonce) {
|
|
21
|
+
return Buffer.from(JSON.stringify([email, date, nonce])).toString('base64url');
|
|
22
|
+
}
|
|
23
|
+
export function encodeLicenseKey(email, date) {
|
|
24
|
+
if (!isLicenseEmail(email) || !isLicenseDate(date))
|
|
25
|
+
throw new Error('Invalid license email or UTC date.');
|
|
26
|
+
const payload = encodePayload(email, date, randomBytes(12).toString('base64url'));
|
|
27
|
+
return `${prefix}.${payload}.${checksum(payload)}`;
|
|
28
|
+
}
|
|
29
|
+
export function decodeLicenseKey(key) {
|
|
30
|
+
if (typeof key !== 'string' || key.length > 512)
|
|
31
|
+
return;
|
|
32
|
+
const match = /^SV1\.([A-Za-z0-9_-]+)\.([a-f0-9]{12})$/.exec(key);
|
|
33
|
+
if (!match || match[0] !== key || checksum(match[1]) !== match[2])
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
const fields = JSON.parse(Buffer.from(match[1], 'base64url').toString('utf8'));
|
|
37
|
+
if (!Array.isArray(fields) || fields.length !== 3)
|
|
38
|
+
return;
|
|
39
|
+
const [email, date, nonce] = fields;
|
|
40
|
+
if (isLicenseEmail(email) && isLicenseDate(date) && typeof nonce === 'string' && nonce.length === 16 &&
|
|
41
|
+
/^[A-Za-z0-9_-]+$/.test(nonce) && encodePayload(email, date, nonce) === match[1])
|
|
42
|
+
return { email, date };
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function inspectLicenseKey(input) {
|
|
49
|
+
if (typeof input !== 'string')
|
|
50
|
+
return;
|
|
51
|
+
const key = input.trim();
|
|
52
|
+
const license = decodeLicenseKey(key);
|
|
53
|
+
if (license)
|
|
54
|
+
return { ...license, key, digest: createHash('sha256').update(key, 'utf8').digest('hex') };
|
|
55
|
+
}
|