drone-path 0.8.1 → 0.10.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 (60) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +18 -25
  3. package/THIRD-PARTY-NOTICES.md +14 -7
  4. package/app/ipc.mjs +178 -0
  5. package/app/main.mjs +10 -150
  6. package/app/preload.cjs +3 -0
  7. package/dist/appassets.js +2 -11
  8. package/dist/apppaths.js +2 -10
  9. package/dist/appsession.js +59 -59
  10. package/dist/appstate.js +22 -38
  11. package/dist/assets.js +0 -7
  12. package/dist/buildinfo.js +71 -0
  13. package/dist/cammeta.js +127 -89
  14. package/dist/changeset-gate.js +0 -7
  15. package/dist/cli.js +3 -36
  16. package/dist/config.js +216 -167
  17. package/dist/configfile.js +0 -8
  18. package/dist/decimate.js +2 -12
  19. package/dist/exportjob.js +3 -19
  20. package/dist/ff.js +2 -27
  21. package/dist/fftools.js +0 -10
  22. package/dist/frametime.js +32 -0
  23. package/dist/geo.js +3 -13
  24. package/dist/inputs.js +0 -4
  25. package/dist/manual/anchors.js +1 -7
  26. package/dist/manual/build.js +0 -6
  27. package/dist/manual/cliref.js +0 -6
  28. package/dist/manual/links.js +0 -17
  29. package/dist/manual/markdown.js +2 -10
  30. package/dist/manual/model.js +0 -3
  31. package/dist/manual/module.js +0 -3
  32. package/dist/manual/nav.js +0 -2
  33. package/dist/manual/reference.js +1 -4
  34. package/dist/page.js +3 -26
  35. package/dist/paths.js +0 -12
  36. package/dist/plan.js +1 -18
  37. package/dist/png.js +1 -21
  38. package/dist/proto.js +4 -4
  39. package/dist/range.js +0 -8
  40. package/dist/render.js +38 -165
  41. package/dist/renderer/dom.js +0 -6
  42. package/dist/renderer/framemath.js +0 -4
  43. package/dist/renderer/scene.js +10 -34
  44. package/dist/renderer/theme.js +58 -10
  45. package/dist/renderer/tilesources.js +0 -10
  46. package/dist/renderer/trail.js +1 -12
  47. package/dist/restyle.js +1 -9
  48. package/dist/run.js +79 -143
  49. package/dist/serve.js +0 -13
  50. package/dist/srt.js +30 -8
  51. package/dist/summary.js +0 -3
  52. package/dist/telemetry-json-schema.js +23 -0
  53. package/dist/telemetry-json.js +113 -0
  54. package/dist/telemetry-math.js +11 -46
  55. package/dist/telemetry.js +58 -11
  56. package/dist/tilecache.js +0 -5
  57. package/dist/tiles.js +31 -117
  58. package/package.json +15 -13
  59. package/dist/renderer/leaflet.js +0 -5
  60. package/dist/tracing.js +0 -208
@@ -1,76 +1,61 @@
1
- // Session vocabulary and state machine for the desktop app, free of Electron
2
- // APIs: pick -> validate -> prepare -> hold one prepared recording.
3
1
  import fs from 'node:fs';
4
2
  import path from 'node:path';
3
+ import { z } from 'zod';
5
4
  import { TILE_BASE, mediaUrlFor } from './apppaths.js';
6
- import { STYLE_VALUES, VIEW_VALUES, asNumber } from './config.js';
5
+ import { parseFrameRange, parseLookSettings, parseValue, resolveRange, strictShape, } from './config.js';
7
6
  import { errorMessage } from './errors.js';
7
+ import { timeAt } from './frametime.js';
8
8
  import { isRecordingName } from './inputs.js';
9
9
  import { buildSceneData } from './page.js';
10
- import { prepareSession, recordingPageOpts } from './run.js';
11
- /** Frame-exact duration from the reported frames and rate, not the container's. */
10
+ import { prepareSession, recordingPageOpts, telemetryExportInput, } from './run.js';
11
+ import { writeTelemetryDocument } from './telemetry-json.js';
12
12
  export function frameExactDuration(probe) {
13
- return probe.frames / probe.fps.value;
13
+ return timeAt(probe.frames, probe.fps.value);
14
14
  }
15
- // The IPC boundary's vocabulary check: whatever the renderer sends, the
16
- // preparation only ever plans from a valid look.
17
15
  export function parsePickRequest(raw) {
18
16
  const input = typeof raw === 'object' && raw !== null ? raw : {};
19
- const look = typeof input.settings === 'object' && input.settings !== null
20
- ? input.settings
21
- : {};
22
- const { style, view, hud } = look;
23
- if (typeof style !== 'string' || !STYLE_VALUES.includes(style)) {
24
- throw new Error(`unknown map style: ${String(style)}`);
25
- }
26
- if (typeof view !== 'string' || !VIEW_VALUES.includes(view)) {
27
- throw new Error(`unknown view: ${String(view)}`);
17
+ return { settings: parseLookSettings(input.settings) };
18
+ }
19
+ const TELEMETRY_SAVE_SHAPE = {
20
+ outPath: z.unknown().optional(),
21
+ range: z.unknown().optional(),
22
+ };
23
+ export function parseTelemetrySaveRequest(raw) {
24
+ const request = parseValue(strictShape(TELEMETRY_SAVE_SHAPE, {
25
+ invalid: 'invalid telemetry save request',
26
+ unknownKey: (key) => `unknown telemetry save request key ${key}`,
27
+ }), raw);
28
+ const outPath = parseValue(z
29
+ .string({ error: () => 'invalid telemetry save request: outPath' })
30
+ .min(1, { error: () => 'invalid telemetry save request: outPath' }), request.outPath);
31
+ if (!outPath.toLowerCase().endsWith('.json')) {
32
+ throw new Error(`invalid telemetry save request: outPath must be a .json file: ${outPath}`);
28
33
  }
29
- const zoom = asNumber(look.zoom, 'zoom');
30
- const zoomOut = asNumber(look.zoomOut, 'zoom-out');
31
- if (!(zoom >= 0))
32
- throw new Error('zoom must be >= 0 (0 = auto-fit)');
33
- if (!(zoomOut >= 0))
34
- throw new Error('zoom-out must be >= 0');
35
- const introSec = asNumber(look.introSec, 'intro');
36
- const outroSec = asNumber(look.outroSec, 'outro');
37
- if (!(introSec >= 0))
38
- throw new Error('intro must be 0 or more');
39
- if (!(outroSec >= 0))
40
- throw new Error('outro must be 0 or more');
41
- const chips = typeof hud === 'object' && hud !== null ? hud : {};
42
- return {
43
- settings: {
44
- style: style,
45
- view: view,
46
- zoom,
47
- zoomOut,
48
- hud: { heading: !!chips.heading, alt: !!chips.alt, speed: !!chips.speed },
49
- introSec,
50
- outroSec,
51
- },
52
- };
34
+ const range = request.range === undefined || request.range === null
35
+ ? null
36
+ : parseFrameRange(request.range);
37
+ return { outPath, range };
53
38
  }
54
- // The shared pipeline preparation plus the scene data the UI drives: probe,
55
- // telemetry and the view plan — no tile wait, so the footage shows right away
56
- // and the map fetches its tiles on demand.
57
39
  export const prepareUiSession = async (videoPath, config, log, onProgress, deps) => {
58
40
  const prep = await prepareSession(videoPath, config, log, {
59
41
  onProgress,
60
42
  deps,
61
43
  });
62
44
  return {
63
- scene: buildSceneData(recordingPageOpts(prep, config), TILE_BASE),
64
- video: {
65
- src: mediaUrlFor(videoPath),
66
- fps: prep.probe.fps.value,
67
- frames: prep.probe.frames,
68
- width: prep.probe.width,
69
- height: prep.probe.height,
45
+ session: {
46
+ scene: buildSceneData(recordingPageOpts(prep, config), TILE_BASE),
47
+ video: {
48
+ src: mediaUrlFor(videoPath),
49
+ fps: prep.probe.fps.value,
50
+ frames: prep.probe.frames,
51
+ width: prep.probe.width,
52
+ height: prep.probe.height,
53
+ },
54
+ tileBase: TILE_BASE,
55
+ bbox: prep.tel.bbox,
56
+ durationSec: frameExactDuration(prep.probe),
70
57
  },
71
- tileBase: TILE_BASE,
72
- bbox: prep.tel.bbox,
73
- durationSec: frameExactDuration(prep.probe),
58
+ telemetry: telemetryExportInput(prep),
74
59
  };
75
60
  };
76
61
  function isReadableVideo(filePath) {
@@ -83,13 +68,25 @@ function isReadableVideo(filePath) {
83
68
  return false;
84
69
  }
85
70
  }
71
+ function segmentTelemetryInput(input, range) {
72
+ const segment = resolveRange(range, input.frameCount);
73
+ if (!segment)
74
+ return input;
75
+ return {
76
+ ...input,
77
+ frameCount: segment.end - segment.start + 1,
78
+ frames: input.frames.slice(segment.start, segment.end + 1),
79
+ headingDeg: input.headingDeg.slice(segment.start, segment.end + 1),
80
+ frameStart: segment.start,
81
+ };
82
+ }
86
83
  export function createAppSession(options) {
87
84
  const { config, pickFile } = options;
88
85
  const prepare = options.prepare ?? prepareUiSession;
89
86
  const log = options.log ?? (() => { });
90
87
  const onPreparing = options.onPreparing ?? (() => { });
91
88
  const onPrepareProgress = options.onPrepareProgress ?? (() => { });
92
- let session = null;
89
+ let prepared = null;
93
90
  let videoPath = null;
94
91
  let picking = false;
95
92
  return {
@@ -107,9 +104,7 @@ export function createAppSession(options) {
107
104
  return { ok: false, error: `not a readable .mp4 file: ${resolved}` };
108
105
  }
109
106
  onPreparing(resolved);
110
- // The renderer's current look prepares the recording, so the prepared
111
- // scene matches what the player shows.
112
- session = await prepare(resolved, { ...config, ...request.settings }, log, onPrepareProgress);
107
+ prepared = await prepare(resolved, { ...config, ...request.settings }, log, onPrepareProgress);
113
108
  videoPath = resolved;
114
109
  log(`loaded: ${resolved}`);
115
110
  return { ok: true };
@@ -122,7 +117,12 @@ export function createAppSession(options) {
122
117
  picking = false;
123
118
  }
124
119
  },
125
- getSession: () => session,
120
+ getSession: () => prepared?.session ?? null,
126
121
  videoPath: () => videoPath,
122
+ saveTelemetryJson(file, range) {
123
+ if (!prepared)
124
+ throw new Error('no recording loaded');
125
+ writeTelemetryDocument(file, segmentTelemetryInput(prepared.telemetry, range));
126
+ },
127
127
  };
128
128
  }
package/dist/appstate.js CHANGED
@@ -1,18 +1,11 @@
1
- // The desktop app's per-user state: the settings panel's last look in
2
- // option-vocabulary values and the folder the last recording was opened from.
3
- // Parsing and merging stay pure; the file I/O below them is the thin shell the
4
- // app seeds from and flushes to.
5
1
  import fs from 'node:fs';
6
2
  import path from 'node:path';
7
- import { DEFAULT_CONFIG, SETTINGS_KEYS, formatHud, parseSettingsPatch } from './config.js';
3
+ import { z } from 'zod';
4
+ import { DEFAULT_CONFIG, SETTINGS_KEYS, formatHud, parseSettingsPatch, parseValue, strictShape, } from './config.js';
8
5
  export const APP_STATE_VERSION = 1;
9
6
  export function emptyAppState() {
10
7
  return { settings: null, lastOpenDir: null };
11
8
  }
12
- // Older settings objects read tolerantly: a key their writer did not know
13
- // starts at its documented default, so an upgrade keeps the look the user
14
- // chose. A present-but-mistyped value (null included) stays the parser's
15
- // business and fails the state.
16
9
  function fillMissingSettings(raw) {
17
10
  if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
18
11
  return raw;
@@ -23,33 +16,29 @@ function fillMissingSettings(raw) {
23
16
  }
24
17
  return filled;
25
18
  }
26
- // The state falls back as a whole: a file whose shape this build cannot read
27
- // is outdated or corrupt, and keeping parts of it would restore a look the
28
- // user never chose.
19
+ const APP_STATE_SHAPE = {
20
+ version: z.unknown().optional(),
21
+ settings: z.unknown().optional(),
22
+ lastOpenDir: z.unknown().optional(),
23
+ };
24
+ const LAST_OPEN_DIR = z
25
+ .optional(z.nullable(z.string({
26
+ error: (issue) => `invalid app state: lastOpenDir: ${String(issue.input)}`,
27
+ })))
28
+ .transform((value) => value ?? null);
29
29
  export function parseAppState(raw) {
30
- if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
31
- throw new Error('invalid app state');
32
- }
33
- const r = raw;
34
- for (const key of Object.keys(r)) {
35
- if (key !== 'version' && key !== 'settings' && key !== 'lastOpenDir') {
36
- throw new Error(`unknown app state key ${key}`);
37
- }
38
- }
39
- if (r.version !== APP_STATE_VERSION) {
40
- throw new Error(`unsupported app state version: ${String(r.version)}`);
41
- }
42
- const settings = r.settings === undefined || r.settings === null
30
+ const state = parseValue(strictShape(APP_STATE_SHAPE, {
31
+ invalid: 'invalid app state',
32
+ unknownKey: (key) => `unknown app state key ${key}`,
33
+ }), raw);
34
+ parseValue(z.literal(APP_STATE_VERSION, {
35
+ error: (issue) => `unsupported app state version: ${String(issue.input)}`,
36
+ }), state.version);
37
+ const settings = state.settings === undefined || state.settings === null
43
38
  ? null
44
- : parseSettingsPatch(fillMissingSettings(r.settings), 'app state');
45
- if (r.lastOpenDir !== undefined && r.lastOpenDir !== null && typeof r.lastOpenDir !== 'string') {
46
- throw new Error(`invalid app state: lastOpenDir: ${String(r.lastOpenDir)}`);
47
- }
48
- const lastOpenDir = typeof r.lastOpenDir === 'string' ? r.lastOpenDir : null;
49
- return { settings, lastOpenDir };
39
+ : parseSettingsPatch(fillMissingSettings(state.settings), 'app state');
40
+ return { settings, lastOpenDir: parseValue(LAST_OPEN_DIR, state.lastOpenDir) };
50
41
  }
51
- // The file's option values use the config-file spelling (the HUD spec as its
52
- // CLI string), so a state file reads like .dronepath.json.
53
42
  export function serializeAppState(state) {
54
43
  const out = { version: APP_STATE_VERSION };
55
44
  if (state.settings) {
@@ -64,23 +53,18 @@ export function serializeAppState(state) {
64
53
  out.lastOpenDir = state.lastOpenDir;
65
54
  return `${JSON.stringify(out, null, 2)}\n`;
66
55
  }
67
- // The persisted look seeds the panel and the export base; machine-owned values
68
- // always stay whatever the config layers resolved.
69
56
  export function applyAppState(config, state) {
70
57
  if (!state.settings)
71
58
  return config;
72
59
  return {
73
60
  ...config,
74
61
  ...state.settings,
75
- // hud is an object; the winner is copied so no two configs share it.
76
62
  hud: { ...state.settings.hud },
77
63
  };
78
64
  }
79
65
  export function rememberOpenedFile(state, filePath) {
80
66
  return { ...state, lastOpenDir: path.dirname(filePath) };
81
67
  }
82
- // A missing or unusable state file is a fresh install: never a failure the
83
- // launch would die on.
84
68
  export function readAppState(file) {
85
69
  let text;
86
70
  try {
package/dist/assets.js CHANGED
@@ -1,7 +1,3 @@
1
- // Pure URL-to-file routing shared by the render server and the app bundle:
2
- // maps a request pathname to the resource that backs it. The route guards
3
- // and the tile acceptance policy live here so they stay unit-testable; the
4
- // servers only perform the I/O.
5
1
  import path from 'node:path';
6
2
  import { parseTilePathname, tilePaths } from './tilecache.js';
7
3
  export const MIME = {
@@ -32,9 +28,6 @@ export function resolveTileRoute(pathname, tileCache, policy) {
32
28
  placeholderPath: paths.placeholder,
33
29
  };
34
30
  }
35
- // Serves /leaflet/*, /tiles/* and /renderer/*: the whitelist guards decide
36
- // what may be served, and every /tiles/ URL is claimed (missing tiles are the
37
- // caller's 404).
38
31
  export function resolveAsset(url, routes) {
39
32
  if (url.startsWith('/leaflet/')) {
40
33
  const rel = url.slice('/leaflet/'.length);
@@ -0,0 +1,71 @@
1
+ import { execFile } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { promisify } from 'node:util';
6
+ import { VERSION } from './version.js';
7
+ const execFileAsync = promisify(execFile);
8
+ export function defaultBuildinfoPaths(root) {
9
+ return {
10
+ moduleFile: path.join(root, 'ui', 'lib', 'buildinfo', 'generated', 'buildinfo.ts'),
11
+ };
12
+ }
13
+ export function resolveBuildGit(version, probe) {
14
+ const commit = probe?.headCommit?.trim() ?? '';
15
+ if (probe === null || commit === '')
16
+ return null;
17
+ // Only the matching v<version> tag marks a formal release; any other state
18
+ // keeps the commit hash visible.
19
+ return { tagged: probe.tagsAtHead.includes(`v${version}`), commit: commit.slice(0, 8) };
20
+ }
21
+ export function buildinfoModuleSource(version, git) {
22
+ return ('// Generated by src/buildinfo.ts at build time. Do not edit.\n' +
23
+ "import type { BuildGit } from '../../buildversion.js';\n" +
24
+ '\n' +
25
+ `export const BUILD_VERSION = ${JSON.stringify(version)};\n` +
26
+ `export const BUILD_GIT: BuildGit | null = ${JSON.stringify(git)};\n`);
27
+ }
28
+ export function buildBuildinfo(paths, version, probe) {
29
+ const git = resolveBuildGit(version, probe);
30
+ fs.mkdirSync(path.dirname(paths.moduleFile), { recursive: true });
31
+ fs.writeFileSync(paths.moduleFile, buildinfoModuleSource(version, git));
32
+ return git;
33
+ }
34
+ async function tryGit(args) {
35
+ try {
36
+ const { stdout } = await execFileAsync('git', [...args]);
37
+ return stdout;
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ }
43
+ export async function probeGit() {
44
+ const head = await tryGit(['rev-parse', 'HEAD']);
45
+ if (head === null)
46
+ return null;
47
+ // A missing tag list only means HEAD is untagged, not that git is gone.
48
+ const tags = await tryGit(['tag', '--points-at', 'HEAD']);
49
+ return {
50
+ headCommit: head.trim(),
51
+ tagsAtHead: (tags ?? '')
52
+ .split('\n')
53
+ .map((tag) => tag.trim())
54
+ .filter((tag) => tag !== ''),
55
+ };
56
+ }
57
+ async function main() {
58
+ try {
59
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
60
+ const git = buildBuildinfo(defaultBuildinfoPaths(root), VERSION, await probeGit());
61
+ const detail = git === null ? 'no git' : git.tagged ? 'tagged' : `commit ${git.commit}`;
62
+ process.stderr.write(`[drone-path] buildinfo: ${VERSION} (${detail})\n`);
63
+ }
64
+ catch (e) {
65
+ process.stderr.write(`[drone-path] ERROR: ${e.message}\n`);
66
+ process.exitCode = 1;
67
+ }
68
+ }
69
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
70
+ void main();
71
+ }