drone-path-engine 1.0.0-rc1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -198,6 +198,7 @@ export declare function normalizeDimensions(width: number, height: number): {
198
198
  };
199
199
  export declare function isValidRenderConfig(config: RenderConfig): boolean;
200
200
  export declare function validateRenderConfig(config: RenderConfig): void;
201
+ export declare function finalizeRenderConfig(config: RenderConfig): RenderConfig;
201
202
  export interface ExportRequest {
202
203
  outPath: string;
203
204
  config: RenderConfig;
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { parseFrameRange } from 'drone-path-core/frame-range';
3
- import { numberValue, parseValue, strictShape } from 'drone-path-core/validation';
3
+ import { asRecord, isRecord, numberValue, parseValue, strictShape } from 'drone-path-core/validation';
4
4
  export const MAP_STYLE_VALUES = ['satellite', 'topo'];
5
5
  const VIEW_MODE_VALUES = ['follow', 'overview'];
6
6
  const CAPTURE_FORMAT_VALUES = ['jpeg', 'png'];
@@ -68,7 +68,7 @@ function nullableStringValue(name) {
68
68
  }
69
69
  // The legacy key loops ran Object.keys on any object, arrays included;
70
70
  // spreading keeps exactly those keys visible to the strict shapes below.
71
- const keyedObjectInput = (value) => typeof value === 'object' && value !== null ? { ...value } : value;
71
+ const keyedObjectInput = (value) => isRecord(value) ? { ...value } : value;
72
72
  // The whitespace tolerance matches the legacy trim-before-match so the error
73
73
  // can echo the raw untrimmed input.
74
74
  const TRAIL_COLOR_RX = /^\s*#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})\s*$/i;
@@ -422,14 +422,7 @@ export function appearanceOf(config) {
422
422
  }
423
423
  export function settingsPatchOf(config) {
424
424
  return {
425
- style: config.style,
426
- view: config.view,
427
- zoom: config.zoom,
428
- zoomOut: config.zoomOut,
429
- hud: config.hud,
430
- introSec: config.introSec,
431
- outroSec: config.outroSec,
432
- trailColor: config.trailColor,
425
+ ...appearanceOf(config),
433
426
  codec: config.codec,
434
427
  quality: config.quality,
435
428
  preset: config.preset,
@@ -459,7 +452,7 @@ export function parseSettingsPatch(raw, origin) {
459
452
  // The pick-request flavor of look settings: its error wording is the legacy
460
453
  // IPC wording, deliberately distinct from validateRenderConfig's CLI wording.
461
454
  export function parseAppearanceSettings(raw) {
462
- const look = typeof raw === 'object' && raw !== null ? raw : {};
455
+ const look = asRecord(raw);
463
456
  const { style, view, hud } = look;
464
457
  const mapStyle = parseValue(z.enum(MAP_STYLE_VALUES, {
465
458
  error: (issue) => `unknown map style: ${String(issue.input)}`,
@@ -476,7 +469,7 @@ export function parseAppearanceSettings(raw) {
476
469
  requireNonNegative(introSec, 'intro must be 0 or more');
477
470
  requireNonNegative(outroSec, 'outro must be 0 or more');
478
471
  const trailColor = asTrailColor(look.trailColor ?? null, 'trail color');
479
- const chips = typeof hud === 'object' && hud !== null ? hud : {};
472
+ const chips = asRecord(hud);
480
473
  return {
481
474
  style: mapStyle,
482
475
  view: viewMode,
@@ -538,6 +531,10 @@ export function validateRenderConfig(config) {
538
531
  if (!config.outSuffix)
539
532
  throw new Error('out-suffix must not be empty');
540
533
  }
534
+ export function finalizeRenderConfig(config) {
535
+ validateRenderConfig(config);
536
+ return { ...config, ...normalizeDimensions(config.width, config.height) };
537
+ }
541
538
  const MAIN_OWNED_KEYS = [
542
539
  // TELEMETRY_JSON_ALIAS.inputKey stays stripped as a legacy spelling of
543
540
  // trackOut, so neither spelling can leak into an export request's config.
@@ -545,7 +542,7 @@ const MAIN_OWNED_KEYS = [
545
542
  'skipExisting', 'recurse', 'trackOut', TELEMETRY_JSON_ALIAS.inputKey, 'json', 'quiet',
546
543
  ];
547
544
  function parseRequestConfig(raw, base) {
548
- if (typeof raw !== 'object' || raw === null) {
545
+ if (!isRecord(raw)) {
549
546
  throw new Error('invalid export request: config');
550
547
  }
551
548
  const flat = { ...raw };
@@ -557,8 +554,7 @@ function parseRequestConfig(raw, base) {
557
554
  : parseValue(hudSpecSchema('export request: config: hud'), hud);
558
555
  const config = { ...base, ...normalizeOverrides(rest, 'export request: config') };
559
556
  const merged = hudSpec === undefined ? config : { ...config, hud: hudSpec };
560
- validateRenderConfig(merged);
561
- return { ...merged, ...normalizeDimensions(merged.width, merged.height) };
557
+ return finalizeRenderConfig(merged);
562
558
  }
563
559
  const EXPORT_REQUEST_SCHEMA = z.preprocess(keyedObjectInput, strictShape({
564
560
  outPath: z.unknown().optional(),
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { userDataDir } from './paths.js';
4
- import { CONFIG_FILE_NAME, DEFAULT_CONFIG, assertOneTrackOutSpelling, normalizeDimensions, normalizeOverrides, trackOutSpellingOf, validateRenderConfig, } from './config.js';
4
+ import { CONFIG_FILE_NAME, DEFAULT_CONFIG, assertOneTrackOutSpelling, finalizeRenderConfig, normalizeOverrides, trackOutSpellingOf, } from './config.js';
5
5
  import { errorMessage } from 'drone-path-core/errors';
6
6
  export function defaultTileCache() {
7
7
  const override = process.env['DRONEPATH_TILE_CACHE'];
@@ -77,10 +77,6 @@ export function resolveConfig(opts) {
77
77
  { origin: 'the command line', spelling: opts.cliTrackOutSpelling ?? null },
78
78
  ]);
79
79
  const merged = mergeConfigLayers(fileLayer.overrides, opts.cli ?? {});
80
- validateRenderConfig(merged);
81
- const normalized = {
82
- ...merged,
83
- ...normalizeDimensions(merged.width, merged.height),
84
- };
80
+ const normalized = finalizeRenderConfig(merged);
85
81
  return { config: resolveConfigPaths(normalized, cwd), configPath };
86
82
  }
@@ -1,11 +1,2 @@
1
- export interface DecimatedTrack {
2
- lat: number[];
3
- lon: number[];
4
- frame: number[];
5
- }
6
- interface DecimateOptions {
7
- epsilonPx?: number;
8
- maxPoints?: number;
9
- }
10
- export declare function decimateTrack(lat: readonly number[], lon: readonly number[], zoom: number, options?: DecimateOptions): DecimatedTrack;
11
- export {};
1
+ export { decimateTrack } from 'drone-path-core/decimate';
2
+ export type { DecimatedTrack } from 'drone-path-core/decimate';
package/dist/decimate.js CHANGED
@@ -1,84 +1 @@
1
- import { project } from 'drone-path-core/geo';
2
- const DEFAULT_EPSILON_PX = 1;
3
- const DEFAULT_MAX_POINTS = 3000;
4
- export function decimateTrack(lat, lon, zoom, options = {}) {
5
- const epsilonPx = options.epsilonPx ?? DEFAULT_EPSILON_PX;
6
- const maxPoints = options.maxPoints ?? DEFAULT_MAX_POINTS;
7
- if (!(epsilonPx >= 0))
8
- throw new Error('epsilon must be >= 0');
9
- if (!Number.isInteger(maxPoints) || maxPoints < 2) {
10
- throw new Error('maxPoints must be an integer >= 2');
11
- }
12
- if (lat.length !== lon.length) {
13
- throw new Error('lat and lon must have the same length');
14
- }
15
- const n = lat.length;
16
- if (n === 0)
17
- return { lat: [], lon: [], frame: [] };
18
- if (n === 1)
19
- return { lat: [lat[0]], lon: [lon[0]], frame: [0] };
20
- const px = new Array(n);
21
- for (let i = 0; i < n; i++)
22
- px[i] = project(lon[i], lat[i], zoom);
23
- let keep = douglasPeucker(px, epsilonPx);
24
- if (keep.length > maxPoints) {
25
- let hi = epsilonPx > 0 ? epsilonPx * 2 : 1;
26
- let hiKeep = douglasPeucker(px, hi);
27
- while (hiKeep.length > maxPoints) {
28
- hi *= 2;
29
- hiKeep = douglasPeucker(px, hi);
30
- }
31
- keep = hiKeep;
32
- }
33
- const track = { lat: [], lon: [], frame: [] };
34
- for (const i of keep) {
35
- track.lat.push(lat[i]);
36
- track.lon.push(lon[i]);
37
- track.frame.push(i);
38
- }
39
- return track;
40
- }
41
- function douglasPeucker(px, epsilon) {
42
- const n = px.length;
43
- const keep = new Uint8Array(n);
44
- keep[0] = 1;
45
- keep[n - 1] = 1;
46
- const stack = [0, n - 1];
47
- while (stack.length > 0) {
48
- const end = stack.pop();
49
- const start = stack.pop();
50
- if (end - start < 2)
51
- continue;
52
- const a = px[start];
53
- const b = px[end];
54
- const mid = (start + end) / 2;
55
- let maxDist = -1;
56
- let maxIdx = -1;
57
- for (let i = start + 1; i < end; i++) {
58
- const d = distanceToSegment(px[i], a, b);
59
- if (d > maxDist ||
60
- (d === maxDist && Math.abs(i - mid) < Math.abs(maxIdx - mid))) {
61
- maxDist = d;
62
- maxIdx = i;
63
- }
64
- }
65
- if (maxDist > epsilon) {
66
- keep[maxIdx] = 1;
67
- stack.push(start, maxIdx, maxIdx, end);
68
- }
69
- }
70
- const indices = [];
71
- for (let i = 0; i < n; i++)
72
- if (keep[i])
73
- indices.push(i);
74
- return indices;
75
- }
76
- function distanceToSegment(p, a, b) {
77
- const dx = b.x - a.x;
78
- const dy = b.y - a.y;
79
- const lenSq = dx * dx + dy * dy;
80
- if (lenSq === 0)
81
- return Math.sqrt((p.x - a.x) ** 2 + (p.y - a.y) ** 2);
82
- const t = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / lenSq));
83
- return Math.sqrt((p.x - (a.x + t * dx)) ** 2 + (p.y - (a.y + t * dy)) ** 2);
84
- }
1
+ export { decimateTrack } from 'drone-path-core/decimate';
package/dist/pipeline.js CHANGED
@@ -150,6 +150,7 @@ async function telemetryStage(env, probe) {
150
150
  frames: probe.frames,
151
151
  fpsValue: probe.fps.value,
152
152
  durationSec: probe.durationSec,
153
+ camMeta: probe.camMeta,
153
154
  tools,
154
155
  });
155
156
  const tel = loaded.telemetry;
@@ -198,16 +199,8 @@ async function tileWarmStage(deps, config, overview, log, signal) {
198
199
  }
199
200
  return tileStats;
200
201
  }
201
- export async function prepareSession(videoPath, config, log, options = {}) {
202
- const env = {
203
- videoPath,
204
- config,
205
- log,
206
- deps: resolveDeps(options.deps, config.tileCache),
207
- tools: options.tools ?? resolveFfmpegTools(config),
208
- report: createPrepareReporter(options.onProgress),
209
- };
210
- const { width, height } = config;
202
+ async function prepareWithEnv(env) {
203
+ const { width, height } = env.config;
211
204
  const { probe, introOutro } = await probeStage(env);
212
205
  const { tel, frameValues, trackValues, protoFile, gimbalDevice, hud } = await telemetryStage(env, probe);
213
206
  const overview = await viewPlanStage(env, tel);
@@ -227,6 +220,16 @@ export async function prepareSession(videoPath, config, log, options = {}) {
227
220
  frames,
228
221
  };
229
222
  }
223
+ export async function prepareSession(videoPath, config, log, options = {}) {
224
+ return prepareWithEnv({
225
+ videoPath,
226
+ config,
227
+ log,
228
+ deps: resolveDeps(options.deps, config.tileCache),
229
+ tools: options.tools ?? resolveFfmpegTools(config),
230
+ report: createPrepareReporter(options.onProgress),
231
+ });
232
+ }
230
233
  export function recordingPageOpts(prep, config) {
231
234
  return planPageOpts({
232
235
  bbox: prep.tel.bbox,
@@ -348,10 +351,13 @@ export async function processRecording(videoPath, config, log, outPath = outputP
348
351
  const tools = options.tools ?? resolveFfmpegTools(config);
349
352
  if (options.signal?.aborted)
350
353
  throw new Error(ERR_RENDER_CANCELED);
351
- const prep = await prepareSession(videoPath, config, log, {
352
- ...options,
354
+ const prep = await prepareWithEnv({
355
+ videoPath,
356
+ config,
357
+ log,
353
358
  deps,
354
359
  tools,
360
+ report: createPrepareReporter(options.onProgress),
355
361
  });
356
362
  if (options.signal?.aborted)
357
363
  throw new Error(ERR_RENDER_CANCELED);
package/dist/plan.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { MIN_DIMENSION } from './config.js';
1
2
  import { project } from 'drone-path-core/geo';
2
3
  import { TILE_SOURCES } from './renderer/tilesources.js';
3
4
  const MIN_ZOOM = 2;
@@ -53,8 +54,8 @@ function tilesCovering(centerPx, trackSpanPx, zoom, width, height, follow, maxNa
53
54
  export function computeOverview({ bbox, width, height, maxZoom = 19, zoomOut = 0, follow = false, maxNativeZoom = null, zoomOverride = 0, }) {
54
55
  const padX = Math.round(width * 0.08);
55
56
  const padY = Math.round(height * 0.08);
56
- const availW = Math.max(64, width - 2 * padX);
57
- const availH = Math.max(64, height - 2 * padY);
57
+ const availW = Math.max(MIN_DIMENSION, width - 2 * padX);
58
+ const availH = Math.max(MIN_DIMENSION, height - 2 * padY);
58
59
  let zoom;
59
60
  if (zoomOverride > 0) {
60
61
  zoom = Math.max(MIN_ZOOM, Math.min(maxZoom, Math.round(zoomOverride)));
@@ -6,14 +6,14 @@ import { createTrailController } from './trail.js';
6
6
  function hudEq(a, b) {
7
7
  return (a.heading === b.heading && a.alt === b.alt && a.speed === b.speed);
8
8
  }
9
+ /** A missing value renders exactly like a disabled chip: the dimmed "--". */
10
+ function isMissing(value) {
11
+ return value === null || value === undefined;
12
+ }
9
13
  function setChipText(chip, value, format) {
10
14
  if (!chip)
11
15
  return;
12
- chip.textContent = value === null || value === undefined ? '--' : format(value);
13
- }
14
- /** A missing value renders exactly like a disabled chip: the dimmed "--". */
15
- function isPlaceholder(value) {
16
- return value === null || value === undefined;
16
+ chip.textContent = isMissing(value) ? '--' : format(value);
17
17
  }
18
18
  let scopeCount = 0;
19
19
  class SceneState {
@@ -305,7 +305,7 @@ class SceneState {
305
305
  setHeading(chip, deg) {
306
306
  if (!chip)
307
307
  return;
308
- const missing = deg === null || deg === undefined;
308
+ const missing = isMissing(deg);
309
309
  const arrow = chip.querySelector('.chip-arrow');
310
310
  const num = chip.querySelector('.num');
311
311
  if (arrow) {
@@ -321,7 +321,7 @@ class SceneState {
321
321
  return;
322
322
  setChipText(chip.querySelector('.num'), value, format);
323
323
  if (this.externalHud)
324
- chip.classList.toggle('map-readout-off', isPlaceholder(value));
324
+ chip.classList.toggle('map-readout-off', isMissing(value));
325
325
  }
326
326
  setFrame(i) {
327
327
  this.curIdx = i;
@@ -346,18 +346,17 @@ class SceneState {
346
346
  update(next) {
347
347
  const prev = this.data;
348
348
  this.data = next;
349
- if (next.lat !== prev.lat || next.lon !== prev.lon) {
349
+ const styleChanged = next.style !== prev.style;
350
+ const sizeChanged = next.width !== prev.width || next.height !== prev.height;
351
+ const trackChanged = next.lat !== prev.lat || next.lon !== prev.lon;
352
+ if (trackChanged) {
350
353
  this.latlngs = this.latlngsOf(next);
351
354
  this.bb = this.L.latLngBounds(this.latlngs);
352
355
  }
353
- const chromeChanged = next.style !== prev.style ||
354
- next.trailColor !== prev.trailColor ||
355
- next.width !== prev.width ||
356
- next.height !== prev.height ||
357
- next.attribution !== prev.attribution;
358
- if (chromeChanged)
356
+ const lookChanged = styleChanged || next.trailColor !== prev.trailColor || sizeChanged;
357
+ if (lookChanged || next.attribution !== prev.attribution)
359
358
  this.applyChrome();
360
- if (next.style !== prev.style) {
359
+ if (styleChanged) {
361
360
  // Zoom constraints are per tile layer (topo is native to z17), so a style switch swaps the layer instead of only its URL.
362
361
  this.tiles.remove();
363
362
  this.tiles = this.makeTileLayer(next.tileUrl, next.style);
@@ -366,16 +365,10 @@ class SceneState {
366
365
  else if (next.tileUrl !== prev.tileUrl) {
367
366
  this.tiles.setUrl(next.tileUrl);
368
367
  }
369
- const decorInvalidated = next.style !== prev.style ||
370
- next.trailColor !== prev.trailColor ||
371
- next.trailLat !== prev.trailLat ||
368
+ const trailChanged = next.trailLat !== prev.trailLat ||
372
369
  next.trailLon !== prev.trailLon ||
373
- next.trailFrame !== prev.trailFrame ||
374
- next.lat !== prev.lat ||
375
- next.lon !== prev.lon ||
376
- next.width !== prev.width ||
377
- next.height !== prev.height;
378
- if (decorInvalidated)
370
+ next.trailFrame !== prev.trailFrame;
371
+ if (lookChanged || trailChanged || trackChanged)
379
372
  this.rebuildDecor();
380
373
  if (!hudEq(prev.hud, next.hud) ||
381
374
  next.hudPills !== prev.hudPills ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drone-path-engine",
3
- "version": "1.0.0-rc1",
3
+ "version": "1.0.0",
4
4
  "description": "Plan and render flight-path map overlays from drone telemetry.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@types/leaflet": "~1.9.22",
33
- "drone-path-core": "~1.0.0-rc1",
33
+ "drone-path-core": "~1.0.0",
34
34
  "leaflet": "~1.9.4",
35
35
  "p-queue": "~10.0.0",
36
36
  "playwright-core": "~1.65.0",