drone-path 0.0.0 → 0.8.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.
- package/CHANGELOG.md +179 -0
- package/LICENSE +21 -0
- package/README.md +83 -6
- package/THIRD-PARTY-NOTICES.md +77 -0
- package/app/main.mjs +496 -0
- package/app/preload.cjs +31 -0
- package/app/update-policy.d.mts +6 -0
- package/app/update-policy.mjs +6 -0
- package/app/update.d.mts +10 -0
- package/app/update.mjs +54 -0
- package/bin/drone-path.mjs +5 -0
- package/dist/appassets.js +44 -0
- package/dist/apppaths.js +28 -0
- package/dist/appsession.js +128 -0
- package/dist/appstate.js +109 -0
- package/dist/assets.js +67 -0
- package/dist/cammeta.js +292 -0
- package/dist/changeset-gate.js +46 -0
- package/dist/cli.js +156 -0
- package/dist/config.js +469 -0
- package/dist/configfile.js +81 -0
- package/dist/decimate.js +94 -0
- package/dist/errors.js +4 -0
- package/dist/exportjob.js +106 -0
- package/dist/ff.js +121 -0
- package/dist/fftools.js +65 -0
- package/dist/geo.js +70 -0
- package/dist/inputs.js +59 -0
- package/dist/manual/anchors.js +23 -0
- package/dist/manual/build.js +78 -0
- package/dist/manual/cliref.js +36 -0
- package/dist/manual/links.js +76 -0
- package/dist/manual/markdown.js +101 -0
- package/dist/manual/model.js +4 -0
- package/dist/manual/module.js +8 -0
- package/dist/manual/nav.js +13 -0
- package/dist/manual/reference.js +26 -0
- package/dist/page.js +108 -0
- package/dist/paths.js +28 -0
- package/dist/plan.js +119 -0
- package/dist/png.js +52 -0
- package/dist/proto.js +102 -0
- package/dist/range.js +58 -0
- package/dist/render.js +408 -0
- package/dist/renderer/boot.js +7 -0
- package/dist/renderer/dom.js +132 -0
- package/dist/renderer/framemath.js +34 -0
- package/dist/renderer/leaflet.js +5 -0
- package/dist/renderer/scene.js +358 -0
- package/dist/renderer/theme.js +34 -0
- package/dist/renderer/tilesources.js +34 -0
- package/dist/renderer/trail.js +53 -0
- package/dist/restyle.js +24 -0
- package/dist/run.js +446 -0
- package/dist/serve.js +70 -0
- package/dist/srt.js +76 -0
- package/dist/summary.js +22 -0
- package/dist/telemetry-math.js +302 -0
- package/dist/telemetry.js +38 -0
- package/dist/tilecache.js +26 -0
- package/dist/tiles.js +241 -0
- package/dist/tracing.js +208 -0
- package/dist/version.js +3 -0
- package/package.json +93 -7
package/dist/cli.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { Command, Option } from 'commander';
|
|
3
|
+
import { ERROR_PREFIX, errorMessage } from './errors.js';
|
|
4
|
+
import { VERSION } from './version.js';
|
|
5
|
+
import { CONFIG_FILE_OPTION, CONFIG_OPTIONS, cliDefaultOf } from './config.js';
|
|
6
|
+
import { resolveConfig } from './configfile.js';
|
|
7
|
+
import { collectRecordings } from './inputs.js';
|
|
8
|
+
import { requireTools } from './ff.js';
|
|
9
|
+
import { resolveFfTools } from './fftools.js';
|
|
10
|
+
import { runBatch } from './run.js';
|
|
11
|
+
import { createTracing } from './tracing.js';
|
|
12
|
+
export function buildProgram() {
|
|
13
|
+
const program = new Command();
|
|
14
|
+
program
|
|
15
|
+
.name('drone-path')
|
|
16
|
+
.description('Render flight-path map overlay videos from DJI drone recordings (telemetry ' +
|
|
17
|
+
'from the .SRT sidecar or the embedded CAM-meta stream) at exactly the source ' +
|
|
18
|
+
'frame rate and frame count.')
|
|
19
|
+
.version(VERSION)
|
|
20
|
+
.argument('<inputs...>', 'video files and/or folders (folders are scanned for *.mp4)');
|
|
21
|
+
for (const row of CONFIG_OPTIONS) {
|
|
22
|
+
const option = new Option(row.cli.flags, row.cli.help);
|
|
23
|
+
if (row.cli.choices)
|
|
24
|
+
option.choices([...row.cli.choices]);
|
|
25
|
+
// An empty CLI default means "not set"; commander would print a noisy
|
|
26
|
+
// (default: "") for it, and the override layer reads only given flags.
|
|
27
|
+
const defaultValue = cliDefaultOf(row.key);
|
|
28
|
+
if (defaultValue !== '')
|
|
29
|
+
option.default(defaultValue);
|
|
30
|
+
program.addOption(option);
|
|
31
|
+
}
|
|
32
|
+
program.option(CONFIG_FILE_OPTION.flags, CONFIG_FILE_OPTION.help);
|
|
33
|
+
return program;
|
|
34
|
+
}
|
|
35
|
+
// Commander's built-in defaults must never leak into the override layer:
|
|
36
|
+
// resolveConfig would then let "CLI" always win over the config file and
|
|
37
|
+
// silently break the documented "CLI flags > config file > defaults"
|
|
38
|
+
// precedence.
|
|
39
|
+
function givenOnCommandLine(program, name) {
|
|
40
|
+
return program.getOptionValueSource(name) === 'cli';
|
|
41
|
+
}
|
|
42
|
+
// The documented long flag of an option's spelling ("--quiet" for
|
|
43
|
+
// "-q, --quiet"), so error contexts never name a short alias.
|
|
44
|
+
export function longFlagOf(flags) {
|
|
45
|
+
const tokens = flags.split(/[ ,|]+/);
|
|
46
|
+
return tokens.find((token) => token.startsWith('--')) ?? tokens[0];
|
|
47
|
+
}
|
|
48
|
+
// Collect only the flags the user actually set, each through its table
|
|
49
|
+
// normalizer, so a config-file value can still win over a CLI default.
|
|
50
|
+
function collectOverrides(program) {
|
|
51
|
+
const opts = program.opts();
|
|
52
|
+
const cli = {};
|
|
53
|
+
for (const row of CONFIG_OPTIONS) {
|
|
54
|
+
if (!givenOnCommandLine(program, row.key))
|
|
55
|
+
continue;
|
|
56
|
+
const flag = longFlagOf(row.cli.flags);
|
|
57
|
+
const raw = row.cli.parse ? row.cli.parse(opts[row.key]) : opts[row.key];
|
|
58
|
+
Object.assign(cli, row.normalize(raw, flag));
|
|
59
|
+
}
|
|
60
|
+
return cli;
|
|
61
|
+
}
|
|
62
|
+
export function parseCliArgs(argv) {
|
|
63
|
+
const program = buildProgram();
|
|
64
|
+
program.exitOverride();
|
|
65
|
+
program.parse(argv, { from: 'user' });
|
|
66
|
+
const opts = program.opts();
|
|
67
|
+
return {
|
|
68
|
+
inputs: [...program.args],
|
|
69
|
+
cli: collectOverrides(program),
|
|
70
|
+
configPath: typeof opts.config === 'string' ? opts.config : null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function isCommanderExit(e) {
|
|
74
|
+
return (typeof e === 'object' &&
|
|
75
|
+
e !== null &&
|
|
76
|
+
'code' in e &&
|
|
77
|
+
typeof (e).code === 'string' &&
|
|
78
|
+
e.code.startsWith('commander.'));
|
|
79
|
+
}
|
|
80
|
+
// --help / --version already printed and count as success.
|
|
81
|
+
function commanderExitCode(e) {
|
|
82
|
+
return e.code === 'commander.helpDisplayed' || e.code === 'commander.version'
|
|
83
|
+
? 0
|
|
84
|
+
: e.exitCode;
|
|
85
|
+
}
|
|
86
|
+
function resolveInvocation(argv) {
|
|
87
|
+
const parsed = parseCliArgs(argv.slice(2));
|
|
88
|
+
const { config, configPath } = resolveConfig({
|
|
89
|
+
cli: parsed.cli,
|
|
90
|
+
configPath: parsed.configPath,
|
|
91
|
+
});
|
|
92
|
+
return { inputs: parsed.inputs, config, configPath };
|
|
93
|
+
}
|
|
94
|
+
function createLogger(config) {
|
|
95
|
+
return (msg) => {
|
|
96
|
+
if (!config.quiet)
|
|
97
|
+
process.stderr.write(`[drone-path] ${msg}\n`);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// The pipeline stage: tools, inputs, output folder, batch, summary, and the
|
|
101
|
+
// batch's effect on the exit code.
|
|
102
|
+
async function runPipeline(invocation, tracing, log) {
|
|
103
|
+
const { inputs, config, configPath } = invocation;
|
|
104
|
+
const tools = resolveFfTools(config);
|
|
105
|
+
await requireTools(tools);
|
|
106
|
+
const videos = collectRecordings(inputs, { recurse: config.recurse });
|
|
107
|
+
if (config.outDir)
|
|
108
|
+
fs.mkdirSync(config.outDir, { recursive: true });
|
|
109
|
+
log(`${videos.length} recording(s) -> ${config.outDir ?? 'beside the sources'}` +
|
|
110
|
+
(configPath ? ` (config: ${configPath})` : ''));
|
|
111
|
+
const emit = (summary) => {
|
|
112
|
+
if (config.json) {
|
|
113
|
+
// Flush synchronously: the summary must survive any later I/O hiccups.
|
|
114
|
+
fs.writeSync(1, `${JSON.stringify(summary)}\n`);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const result = await runBatch(videos, config, log, emit, {
|
|
118
|
+
trace: { tracer: tracing.tracer },
|
|
119
|
+
tools,
|
|
120
|
+
});
|
|
121
|
+
log(`done: ${result.ok} ok, ${result.skipped} skipped, ${result.failed} failed`);
|
|
122
|
+
if (result.failed > 0)
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
}
|
|
125
|
+
async function withTracingShutdown(tracing, log, body) {
|
|
126
|
+
try {
|
|
127
|
+
await body();
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
try {
|
|
131
|
+
await tracing.shutdown();
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
// A shutdown hiccup must not replace the error that is unwinding.
|
|
135
|
+
log(`warning: tracing shutdown failed: ${errorMessage(e)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export async function main(argv = process.argv) {
|
|
140
|
+
try {
|
|
141
|
+
const invocation = resolveInvocation(argv);
|
|
142
|
+
const log = createLogger(invocation.config);
|
|
143
|
+
const tracing = await createTracing();
|
|
144
|
+
if (tracing.enabled)
|
|
145
|
+
log(`tracing: enabled (OTLP/HTTP protobuf)`);
|
|
146
|
+
await withTracingShutdown(tracing, log, () => runPipeline(invocation, tracing, log));
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
if (isCommanderExit(e)) {
|
|
150
|
+
process.exitCode = commanderExitCode(e);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
process.stderr.write(`${ERROR_PREFIX}${errorMessage(e)}\n`);
|
|
154
|
+
process.exitCode = 1;
|
|
155
|
+
}
|
|
156
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
// The option vocabulary: the option types (Style, View, Capture, Codec,
|
|
2
|
+
// Quality, Preset, HudSpec), their defaults and the parsing/normalizing rules.
|
|
3
|
+
// Feature modules import them from here, and this module stays free of I/O so
|
|
4
|
+
// the app UI can share the vocabulary in its browser bundle. File discovery
|
|
5
|
+
// and the precedence of the config layers live in src/configfile.ts.
|
|
6
|
+
export const CONFIG_FILE_NAME = '.dronepath.json';
|
|
7
|
+
// The config-file selection flag: vocabulary outside the config keys,
|
|
8
|
+
// shared by the CLI and the generated reference so they cannot drift.
|
|
9
|
+
export const CONFIG_FILE_OPTION = {
|
|
10
|
+
flags: '--config <path>',
|
|
11
|
+
help: 'config file (default: .dronepath.json discovered upward from the working directory)',
|
|
12
|
+
};
|
|
13
|
+
export const STYLE_VALUES = ['satellite', 'topo'];
|
|
14
|
+
export const VIEW_VALUES = ['follow', 'overview'];
|
|
15
|
+
const CAPTURE_VALUES = ['jpeg', 'png'];
|
|
16
|
+
export const CODEC_VALUES = ['h264', 'h265'];
|
|
17
|
+
export const QUALITY_VALUES = ['near-lossless', 'high', 'medium', 'low'];
|
|
18
|
+
export const PRESET_VALUES = ['medium', 'veryfast'];
|
|
19
|
+
export function parseHud(list) {
|
|
20
|
+
const hud = { heading: false, alt: false, speed: false };
|
|
21
|
+
if (!list || list.toLowerCase() === 'none')
|
|
22
|
+
return hud;
|
|
23
|
+
for (const part of list
|
|
24
|
+
.split(',')
|
|
25
|
+
.map((s) => s.trim().toLowerCase())
|
|
26
|
+
.filter(Boolean)) {
|
|
27
|
+
if (part === 'heading' || part === 'arrow')
|
|
28
|
+
hud.heading = true;
|
|
29
|
+
else if (part === 'alt' || part === 'altitude')
|
|
30
|
+
hud.alt = true;
|
|
31
|
+
else if (part === 'speed')
|
|
32
|
+
hud.speed = true;
|
|
33
|
+
else
|
|
34
|
+
throw new Error(`unknown --hud component: ${part} (use heading,alt,speed or none)`);
|
|
35
|
+
}
|
|
36
|
+
return hud;
|
|
37
|
+
}
|
|
38
|
+
// The "alt hides when unavailable" rule, one home for the pipeline and the UI.
|
|
39
|
+
export function resolveHudSpec(hud, hasAlt) {
|
|
40
|
+
return hud.alt && !hasAlt ? { ...hud, alt: false } : hud;
|
|
41
|
+
}
|
|
42
|
+
// What "unavailable" means for the rule above: no altitude sample at all in
|
|
43
|
+
// the telemetry.
|
|
44
|
+
export function hasAltitude(alt) {
|
|
45
|
+
return alt.some((a) => a !== null);
|
|
46
|
+
}
|
|
47
|
+
// The CLI-string form of a HUD spec ("none" when no chip is on), the inverse
|
|
48
|
+
// of parseHud.
|
|
49
|
+
export function formatHud(hud) {
|
|
50
|
+
const parts = [];
|
|
51
|
+
if (hud.heading)
|
|
52
|
+
parts.push('heading');
|
|
53
|
+
if (hud.alt)
|
|
54
|
+
parts.push('alt');
|
|
55
|
+
if (hud.speed)
|
|
56
|
+
parts.push('speed');
|
|
57
|
+
return parts.length ? parts.join(',') : 'none';
|
|
58
|
+
}
|
|
59
|
+
// Typed layers (config files, export requests) carry exact JSON types, so a
|
|
60
|
+
// mistyped value must fail instead of being silently converted.
|
|
61
|
+
export function asNumber(value, name) {
|
|
62
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
63
|
+
throw new Error(`invalid number for ${name}: ${String(value)}`);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
// Commander hands every option value as a string; numeric flags are converted
|
|
68
|
+
// at the CLI boundary only. Anything that is not a plain decimal literal
|
|
69
|
+
// passes through so asNumber rejects it naming the offending input verbatim.
|
|
70
|
+
const CLI_NUMBER_RX = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
|
|
71
|
+
function cliNumber(raw) {
|
|
72
|
+
if (typeof raw !== 'string' || !CLI_NUMBER_RX.test(raw.trim()))
|
|
73
|
+
return raw;
|
|
74
|
+
return Number(raw);
|
|
75
|
+
}
|
|
76
|
+
function asString(value, name) {
|
|
77
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
78
|
+
throw new Error(`invalid value for ${name}: ${String(value)}`);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
function asBool(value, name) {
|
|
83
|
+
if (typeof value !== 'boolean') {
|
|
84
|
+
throw new Error(`invalid value for ${name}: ${String(value)}`);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
function asEnum(value, name, allowed) {
|
|
89
|
+
if (typeof value !== 'string' || !allowed.includes(value)) {
|
|
90
|
+
throw new Error(`invalid value for ${name}: ${String(value)} (use ${allowed.join(' | ')})`);
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
function asNullableString(value, name) {
|
|
95
|
+
if (value === null || value === '')
|
|
96
|
+
return null;
|
|
97
|
+
return asString(value, name);
|
|
98
|
+
}
|
|
99
|
+
export const CONFIG_OPTIONS = [
|
|
100
|
+
{
|
|
101
|
+
key: 'outDir',
|
|
102
|
+
cli: { flags: '--out-dir <dir>', help: 'output folder' },
|
|
103
|
+
default: 'out',
|
|
104
|
+
normalize: (v, name) => ({ outDir: asNullableString(v, name) }),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
key: 'outSuffix',
|
|
108
|
+
cli: { flags: '--out-suffix <suffix>', help: 'output name = <basename><suffix>.mp4' },
|
|
109
|
+
default: '_map',
|
|
110
|
+
normalize: (v, name) => ({ outSuffix: asString(v, name) }),
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
key: 'width',
|
|
114
|
+
cli: { flags: '--width <px>', help: 'canvas width in pixels (rounded down to even)', parse: cliNumber },
|
|
115
|
+
default: 768,
|
|
116
|
+
normalize: (v, name) => ({ width: asNumber(v, name) }),
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
key: 'height',
|
|
120
|
+
cli: { flags: '--height <px>', help: 'canvas height in pixels (rounded down to even)', parse: cliNumber },
|
|
121
|
+
default: 768,
|
|
122
|
+
normalize: (v, name) => ({ height: asNumber(v, name) }),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
key: 'style',
|
|
126
|
+
cli: { flags: '--style <name>', help: 'map look', choices: STYLE_VALUES },
|
|
127
|
+
default: 'satellite',
|
|
128
|
+
normalize: (v, name) => ({ style: asEnum(v, name, STYLE_VALUES) }),
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
key: 'view',
|
|
132
|
+
cli: {
|
|
133
|
+
flags: '--view <mode>',
|
|
134
|
+
help: 'follow: drone stays centered and the map slides under it; overview: static whole-track map',
|
|
135
|
+
choices: VIEW_VALUES,
|
|
136
|
+
},
|
|
137
|
+
default: 'follow',
|
|
138
|
+
normalize: (v, name) => ({ view: asEnum(v, name, VIEW_VALUES) }),
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
key: 'zoom',
|
|
142
|
+
cli: { flags: '--zoom <n>', help: 'fixed view zoom level (0 = auto-fit to the track)', parse: cliNumber },
|
|
143
|
+
default: 0,
|
|
144
|
+
normalize: (v, name) => ({ zoom: asNumber(v, name) }),
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
key: 'zoomOut',
|
|
148
|
+
cli: { flags: '--zoom-out <n>', help: 'auto-fit only: pull back n zoom levels', parse: cliNumber },
|
|
149
|
+
default: 1,
|
|
150
|
+
normalize: (v, name) => ({ zoomOut: asNumber(v, name) }),
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
key: 'introSec',
|
|
154
|
+
cli: { flags: '--intro-sec <s>', help: 'intro: zoom in from one level out over s seconds', parse: cliNumber },
|
|
155
|
+
default: 2,
|
|
156
|
+
normalize: (v, name) => ({ introSec: asNumber(v, name) }),
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
key: 'outroSec',
|
|
160
|
+
cli: { flags: '--outro-sec <s>', help: 'outro: zoom back out over s seconds', parse: cliNumber },
|
|
161
|
+
default: 2,
|
|
162
|
+
normalize: (v, name) => ({ outroSec: asNumber(v, name) }),
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
key: 'hud',
|
|
166
|
+
cli: {
|
|
167
|
+
flags: '--hud <list>',
|
|
168
|
+
help: 'comma list of heading,alt,speed - or none (alt hides when unavailable)',
|
|
169
|
+
},
|
|
170
|
+
default: { heading: true, alt: false, speed: false },
|
|
171
|
+
normalize: (v, name) => ({ hud: parseHud(asString(v, name)) }),
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
key: 'workers',
|
|
175
|
+
cli: { flags: '--workers <n>', help: 'parallel browser pages', parse: cliNumber },
|
|
176
|
+
default: 4,
|
|
177
|
+
normalize: (v, name) => ({ workers: asNumber(v, name) }),
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
key: 'capture',
|
|
181
|
+
cli: { flags: '--capture <mode>', help: 'frame capture mode (canvas is parked)', choices: CAPTURE_VALUES },
|
|
182
|
+
default: 'jpeg',
|
|
183
|
+
normalize: (v, name) => ({ capture: asEnum(v, name, CAPTURE_VALUES) }),
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
key: 'codec',
|
|
187
|
+
cli: { flags: '--codec <name>', help: 'video codec (mp4 container)', choices: CODEC_VALUES },
|
|
188
|
+
default: 'h264',
|
|
189
|
+
normalize: (v, name) => ({ codec: asEnum(v, name, CODEC_VALUES) }),
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
key: 'quality',
|
|
193
|
+
cli: { flags: '--quality <level>', help: 'encoding quality', choices: QUALITY_VALUES },
|
|
194
|
+
default: 'high',
|
|
195
|
+
normalize: (v, name) => ({ quality: asEnum(v, name, QUALITY_VALUES) }),
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: 'preset',
|
|
199
|
+
cli: { flags: '--preset <name>', help: 'encoding speed', choices: PRESET_VALUES },
|
|
200
|
+
default: 'medium',
|
|
201
|
+
normalize: (v, name) => ({ preset: asEnum(v, name, PRESET_VALUES) }),
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
key: 'tileCache',
|
|
205
|
+
cli: { flags: '--tile-cache <dir>', help: 'tile cache directory (default: per-user cache dir)' },
|
|
206
|
+
default: '',
|
|
207
|
+
normalize: (v, name) => ({ tileCache: asString(v, name) }),
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
key: 'browser',
|
|
211
|
+
cli: { flags: '--browser <path>', help: 'Chromium/Chrome/Edge executable (default: system Chrome/Edge)' },
|
|
212
|
+
default: null,
|
|
213
|
+
normalize: (v, name) => ({ browser: asNullableString(v, name) }),
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
key: 'ffmpeg',
|
|
217
|
+
cli: { flags: '--ffmpeg <path>', help: 'ffmpeg executable (default: embedded binary, then PATH)' },
|
|
218
|
+
default: null,
|
|
219
|
+
normalize: (v, name) => ({ ffmpeg: asNullableString(v, name) }),
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
key: 'ffprobe',
|
|
223
|
+
cli: { flags: '--ffprobe <path>', help: 'ffprobe executable (default: embedded binary, then PATH)' },
|
|
224
|
+
default: null,
|
|
225
|
+
normalize: (v, name) => ({ ffprobe: asNullableString(v, name) }),
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
key: 'skipExisting',
|
|
229
|
+
cli: {
|
|
230
|
+
flags: '--skip-existing',
|
|
231
|
+
help: 'skip recordings whose output already exists and matches the source',
|
|
232
|
+
},
|
|
233
|
+
default: false,
|
|
234
|
+
normalize: (v, name) => ({ skipExisting: asBool(v, name) }),
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
key: 'recurse',
|
|
238
|
+
cli: { flags: '--recurse', help: 'scan input folders recursively' },
|
|
239
|
+
default: false,
|
|
240
|
+
normalize: (v, name) => ({ recurse: asBool(v, name) }),
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
key: 'json',
|
|
244
|
+
cli: { flags: '--json', help: 'print one NDJSON summary line per recording on stdout' },
|
|
245
|
+
default: false,
|
|
246
|
+
normalize: (v, name) => ({ json: asBool(v, name) }),
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
key: 'quiet',
|
|
250
|
+
cli: { flags: '-q, --quiet', help: 'suppress progress output' },
|
|
251
|
+
default: false,
|
|
252
|
+
normalize: (v, name) => ({ quiet: asBool(v, name) }),
|
|
253
|
+
},
|
|
254
|
+
];
|
|
255
|
+
// The CLI spells a default the way commander expects it. The config-native
|
|
256
|
+
// default stays in the table's `default` column so DEFAULT_CONFIG is a straight
|
|
257
|
+
// copy. Three kinds differ from their config form: a boolean default stays a
|
|
258
|
+
// boolean (commander's presence flags), a null default becomes the empty string
|
|
259
|
+
// ("not set") - "null" would read as a literal path - and the HUD spec becomes
|
|
260
|
+
// its comma string.
|
|
261
|
+
export function cliDefaultOf(key) {
|
|
262
|
+
const row = CONFIG_OPTIONS.find((r) => r.key === key);
|
|
263
|
+
if (!row)
|
|
264
|
+
throw new Error(`unknown config key ${String(key)}`);
|
|
265
|
+
const value = row.default;
|
|
266
|
+
if (typeof value === 'boolean')
|
|
267
|
+
return value;
|
|
268
|
+
if (value === null || value === undefined)
|
|
269
|
+
return '';
|
|
270
|
+
return key === 'hud' ? formatHud(value) : String(value);
|
|
271
|
+
}
|
|
272
|
+
// Frozen so no resolved config can corrupt the shared defaults; merges copy
|
|
273
|
+
// the hud spec so every resolved config owns its own mutable copy.
|
|
274
|
+
export const DEFAULT_CONFIG = Object.freeze(Object.fromEntries(CONFIG_OPTIONS.map((row) => [row.key, row.default])));
|
|
275
|
+
Object.freeze(DEFAULT_CONFIG.hud);
|
|
276
|
+
// Keyed lookup built from the option table; a key's normalizer is found by its
|
|
277
|
+
// name, and an unknown key is a usage error naming the origin.
|
|
278
|
+
const OVERRIDE_NORMALIZERS = Object.fromEntries(CONFIG_OPTIONS.map((row) => [row.key, row.normalize]));
|
|
279
|
+
export function normalizeOverrides(raw, origin) {
|
|
280
|
+
const out = {};
|
|
281
|
+
for (const key of Object.keys(raw)) {
|
|
282
|
+
const normalize = Object.hasOwn(OVERRIDE_NORMALIZERS, key)
|
|
283
|
+
? OVERRIDE_NORMALIZERS[key]
|
|
284
|
+
: null;
|
|
285
|
+
if (!normalize)
|
|
286
|
+
throw new Error(`unknown config key ${key} in ${origin}`);
|
|
287
|
+
const value = raw[key];
|
|
288
|
+
if (value === undefined || value === null)
|
|
289
|
+
continue;
|
|
290
|
+
Object.assign(out, normalize(value, `${origin}: ${key}`));
|
|
291
|
+
}
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
export function effectiveZoomOut(config) {
|
|
295
|
+
return config.zoom > 0 ? 0 : config.zoomOut;
|
|
296
|
+
}
|
|
297
|
+
export function settingsPatchOf(config) {
|
|
298
|
+
return {
|
|
299
|
+
style: config.style,
|
|
300
|
+
view: config.view,
|
|
301
|
+
zoom: config.zoom,
|
|
302
|
+
zoomOut: config.zoomOut,
|
|
303
|
+
hud: config.hud,
|
|
304
|
+
introSec: config.introSec,
|
|
305
|
+
outroSec: config.outroSec,
|
|
306
|
+
codec: config.codec,
|
|
307
|
+
quality: config.quality,
|
|
308
|
+
preset: config.preset,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// The persisted keys in the vocabulary's table order: the persisted state's
|
|
312
|
+
// shape and its serialization order in one home.
|
|
313
|
+
export const SETTINGS_KEYS = [
|
|
314
|
+
'style',
|
|
315
|
+
'view',
|
|
316
|
+
'zoom',
|
|
317
|
+
'zoomOut',
|
|
318
|
+
'hud',
|
|
319
|
+
'introSec',
|
|
320
|
+
'outroSec',
|
|
321
|
+
'codec',
|
|
322
|
+
'quality',
|
|
323
|
+
'preset',
|
|
324
|
+
];
|
|
325
|
+
// The settings-values boundary (the settings save IPC, the persisted state
|
|
326
|
+
// file): the keys arrive complete and vocabulary-valid, so no layer
|
|
327
|
+
// downstream can hold a value the pipeline would reject. The HUD spec travels
|
|
328
|
+
// as its object form over IPC and as its CLI string in JSON files; both run
|
|
329
|
+
// through the vocabulary's own normalizers.
|
|
330
|
+
export function parseSettingsPatch(raw, origin) {
|
|
331
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
332
|
+
throw new Error(`invalid settings in ${origin}`);
|
|
333
|
+
}
|
|
334
|
+
const flat = { ...raw };
|
|
335
|
+
// A known config key outside the persisted set (a machine-owned value) must
|
|
336
|
+
// never ride along; the vocabulary's normalizers only reject unknown keys.
|
|
337
|
+
for (const key of Object.keys(flat)) {
|
|
338
|
+
if (!SETTINGS_KEYS.includes(key)) {
|
|
339
|
+
throw new Error(`unknown settings key ${key} in ${origin}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (flat.hud !== undefined && flat.hud !== null && typeof flat.hud !== 'string') {
|
|
343
|
+
flat.hud = formatHud(parseHudObject(flat.hud, `${origin}: hud`));
|
|
344
|
+
}
|
|
345
|
+
const patch = normalizeOverrides(flat, origin);
|
|
346
|
+
for (const key of SETTINGS_KEYS) {
|
|
347
|
+
if (patch[key] === undefined) {
|
|
348
|
+
throw new Error(`missing settings key ${key} in ${origin}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const settings = patch;
|
|
352
|
+
validateRenderConfig({ ...DEFAULT_CONFIG, ...settings, hud: { ...settings.hud } });
|
|
353
|
+
return settings;
|
|
354
|
+
}
|
|
355
|
+
// The smallest canvas the renderer and the app's dimension fields accept, in
|
|
356
|
+
// one home so the CLI, the pipeline and the export modal cannot disagree.
|
|
357
|
+
export const MIN_DIMENSION = 64;
|
|
358
|
+
// The negated comparisons are NaN-safe: they also reject NaN sneak-ins.
|
|
359
|
+
export function validateDimensions(width, height) {
|
|
360
|
+
if (!(width >= MIN_DIMENSION) || !(height >= MIN_DIMENSION)) {
|
|
361
|
+
throw new Error(`width and height must be at least ${MIN_DIMENSION}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// The documented "rounded down to even" rule (keeping the MIN_DIMENSION
|
|
365
|
+
// floor), in one home: every config producer applies it so a RenderConfig
|
|
366
|
+
// always holds the effective canvas the renderer gets.
|
|
367
|
+
export function normalizeDimensions(width, height) {
|
|
368
|
+
return {
|
|
369
|
+
width: Math.max(MIN_DIMENSION, 2 * Math.floor(width / 2)),
|
|
370
|
+
height: Math.max(MIN_DIMENSION, 2 * Math.floor(height / 2)),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
export function validateRenderConfig(config) {
|
|
374
|
+
validateDimensions(config.width, config.height);
|
|
375
|
+
if (!Number.isInteger(config.workers) || config.workers < 1) {
|
|
376
|
+
throw new Error('workers must be a positive integer');
|
|
377
|
+
}
|
|
378
|
+
if (!(config.zoom >= 0))
|
|
379
|
+
throw new Error('zoom must be >= 0 (0 = auto-fit)');
|
|
380
|
+
if (!(config.zoomOut >= 0))
|
|
381
|
+
throw new Error('zoom-out must be >= 0');
|
|
382
|
+
if (!(config.introSec >= 0) || !(config.outroSec >= 0)) {
|
|
383
|
+
throw new Error('intro-sec and outro-sec must be >= 0');
|
|
384
|
+
}
|
|
385
|
+
if (!config.outSuffix)
|
|
386
|
+
throw new Error('out-suffix must not be empty');
|
|
387
|
+
}
|
|
388
|
+
// One rule for a usable frame range, shared by the request parser and the
|
|
389
|
+
// pipeline's range guard so they cannot drift.
|
|
390
|
+
export function assertValidFrameRange(range, name = 'frame range') {
|
|
391
|
+
if (!Number.isInteger(range.start) || !Number.isInteger(range.end)) {
|
|
392
|
+
throw new Error(`invalid ${name}: start and end must be integer frame indices`);
|
|
393
|
+
}
|
|
394
|
+
if (range.start < 0 || range.start >= range.end) {
|
|
395
|
+
throw new Error(`invalid ${name}: expected 0 <= start < end, got ${range.start}-${range.end}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
export function parseFrameRange(raw, name = 'frame range') {
|
|
399
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
400
|
+
throw new Error(`invalid ${name}`);
|
|
401
|
+
}
|
|
402
|
+
const r = raw;
|
|
403
|
+
for (const key of Object.keys(r)) {
|
|
404
|
+
if (key !== 'start' && key !== 'end') {
|
|
405
|
+
throw new Error(`unknown ${name} key ${key}`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const start = asNumber(r.start, `${name}: start`);
|
|
409
|
+
const end = asNumber(r.end, `${name}: end`);
|
|
410
|
+
assertValidFrameRange({ start, end }, name);
|
|
411
|
+
return { start, end };
|
|
412
|
+
}
|
|
413
|
+
function parseHudObject(value, name) {
|
|
414
|
+
if (typeof value !== 'object' || value === null) {
|
|
415
|
+
throw new Error(`invalid value for ${name}`);
|
|
416
|
+
}
|
|
417
|
+
const h = value;
|
|
418
|
+
for (const key of Object.keys(h)) {
|
|
419
|
+
if (key !== 'heading' && key !== 'alt' && key !== 'speed') {
|
|
420
|
+
throw new Error(`unknown key ${key} in ${name}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
heading: asBool(h.heading, `${name}: heading`),
|
|
425
|
+
alt: asBool(h.alt, `${name}: alt`),
|
|
426
|
+
speed: asBool(h.speed, `${name}: speed`),
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
// Machine-owned settings the renderer never chooses: the main process's
|
|
430
|
+
// resolved values stay authoritative, so a snapshot cannot redirect the tile
|
|
431
|
+
// cache, the browser, the worker count or the CLI-only switches.
|
|
432
|
+
const MAIN_OWNED_KEYS = [
|
|
433
|
+
'outDir', 'outSuffix', 'tileCache', 'browser', 'ffmpeg', 'ffprobe', 'workers', 'capture',
|
|
434
|
+
'skipExisting', 'recurse', 'json', 'quiet',
|
|
435
|
+
];
|
|
436
|
+
// The renderer sends the look and the export dimensions; everything else comes
|
|
437
|
+
// from the main process. The HUD spec travels in its CLI string form so the
|
|
438
|
+
// vocabulary's own normalizers stay the single validation home.
|
|
439
|
+
function parseRequestConfig(raw, base) {
|
|
440
|
+
if (typeof raw !== 'object' || raw === null) {
|
|
441
|
+
throw new Error('invalid export request: config');
|
|
442
|
+
}
|
|
443
|
+
const flat = { ...raw };
|
|
444
|
+
for (const key of MAIN_OWNED_KEYS)
|
|
445
|
+
delete flat[key];
|
|
446
|
+
if (flat.hud !== undefined && flat.hud !== null) {
|
|
447
|
+
flat.hud = formatHud(parseHudObject(flat.hud, 'export request: config: hud'));
|
|
448
|
+
}
|
|
449
|
+
const config = { ...base, ...normalizeOverrides(flat, 'export request: config') };
|
|
450
|
+
validateRenderConfig(config);
|
|
451
|
+
return { ...config, ...normalizeDimensions(config.width, config.height) };
|
|
452
|
+
}
|
|
453
|
+
export function parseExportRequest(raw, base) {
|
|
454
|
+
if (typeof raw !== 'object' || raw === null) {
|
|
455
|
+
throw new Error('invalid export request');
|
|
456
|
+
}
|
|
457
|
+
const r = raw;
|
|
458
|
+
for (const key of Object.keys(r)) {
|
|
459
|
+
if (key !== 'outPath' && key !== 'config' && key !== 'range') {
|
|
460
|
+
throw new Error(`unknown export request key ${key}`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const outPath = asString(r.outPath, 'export request: outPath');
|
|
464
|
+
if (!outPath.toLowerCase().endsWith('.mp4')) {
|
|
465
|
+
throw new Error(`export request: outPath must be an .mp4 file: ${outPath}`);
|
|
466
|
+
}
|
|
467
|
+
const range = r.range === undefined || r.range === null ? null : parseFrameRange(r.range);
|
|
468
|
+
return { outPath, config: parseRequestConfig(r.config, base), range };
|
|
469
|
+
}
|