drone-path-engine 1.2.0 → 2.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/README.md +3 -1
- package/dist/config.d.ts +11 -12
- package/dist/config.js +14 -35
- package/dist/paths.d.ts +1 -2
- package/dist/paths.js +1 -7
- package/dist/pipeline.d.ts +1 -5
- package/dist/pipeline.js +21 -44
- package/dist/plan.d.ts +0 -9
- package/dist/plan.js +0 -12
- package/dist/render-cancellation.d.ts +1 -0
- package/dist/render-cancellation.js +4 -0
- package/dist/render-page.d.ts +1 -8
- package/dist/render-page.js +3 -8
- package/dist/render.d.ts +0 -1
- package/dist/render.js +9 -12
- package/dist/renderer/framemath.d.ts +0 -1
- package/dist/renderer/framemath.js +0 -11
- package/dist/renderer/scene.d.ts +0 -2
- package/dist/renderer/scene.js +56 -25
- package/dist/renderer/theme.d.ts +1 -0
- package/dist/renderer/theme.js +1 -1
- package/dist/renderer/trail.d.ts +2 -0
- package/dist/renderer/trail.js +41 -11
- package/dist/restyle.js +0 -1
- package/dist/tiles.js +29 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -15,7 +15,9 @@ import { DEFAULT_CONFIG } from 'drone-path-engine/config';
|
|
|
15
15
|
import { runBatch } from 'drone-path-engine/pipeline';
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Each module ships TypeScript declarations.
|
|
18
|
+
Each module ships TypeScript declarations. If you construct a `RenderConfig`,
|
|
19
|
+
remove the retired `introSec` and `outroSec` fields. Renders use the selected
|
|
20
|
+
camera mode for the entire recording.
|
|
19
21
|
|
|
20
22
|
Install `@types/node` for your Node.js major version. In TypeScript 6, list
|
|
21
23
|
`node` in `compilerOptions.types` to load the Node declarations.
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FfmpegToolOverrides } from 'drone-path-core/ffmpeg-tools';
|
|
2
|
-
import type { FrameRange } from 'drone-path-core/frame-range';
|
|
3
2
|
export declare const MAP_STYLE_VALUES: readonly ["satellite", "topo"];
|
|
4
3
|
export type MapStyle = (typeof MAP_STYLE_VALUES)[number];
|
|
5
4
|
declare const VIEW_MODE_VALUES: readonly ["follow", "overview"];
|
|
@@ -26,8 +25,6 @@ export interface RenderConfig extends FfmpegToolOverrides {
|
|
|
26
25
|
view: ViewMode;
|
|
27
26
|
zoom: number;
|
|
28
27
|
zoomOut: number;
|
|
29
|
-
introSec: number;
|
|
30
|
-
outroSec: number;
|
|
31
28
|
trailColor: string | null;
|
|
32
29
|
hud: HudLayout;
|
|
33
30
|
workers: number;
|
|
@@ -95,12 +92,6 @@ export declare const OVERRIDE_NORMALIZERS: {
|
|
|
95
92
|
zoomOut: (v: unknown, name: string) => {
|
|
96
93
|
zoomOut: number;
|
|
97
94
|
};
|
|
98
|
-
introSec: (v: unknown, name: string) => {
|
|
99
|
-
introSec: number;
|
|
100
|
-
};
|
|
101
|
-
outroSec: (v: unknown, name: string) => {
|
|
102
|
-
outroSec: number;
|
|
103
|
-
};
|
|
104
95
|
trailColor: (v: unknown, name: string) => {
|
|
105
96
|
trailColor: string | null;
|
|
106
97
|
};
|
|
@@ -176,11 +167,20 @@ export declare function assertOneTrackOutSpelling(entries: readonly {
|
|
|
176
167
|
}[]): void;
|
|
177
168
|
export declare function cliDefaultOf(key: keyof RenderConfig): string | boolean;
|
|
178
169
|
export declare const DEFAULT_CONFIG: RenderConfig;
|
|
170
|
+
export declare const RETIRED_ZOOM_OPTIONS: readonly [{
|
|
171
|
+
readonly key: "introSec";
|
|
172
|
+
readonly flags: "--intro-sec <s>";
|
|
173
|
+
}, {
|
|
174
|
+
readonly key: "outroSec";
|
|
175
|
+
readonly flags: "--outro-sec <s>";
|
|
176
|
+
}];
|
|
177
|
+
export declare const RETIRED_ZOOM_HELP = "Deprecated and ignored. Remove this option from your settings.";
|
|
178
|
+
export declare function retiredZoomWarning(option: string): string;
|
|
179
179
|
export declare function normalizeOverrides(raw: Record<string, unknown>, origin: string, onDeprecated?: (message: string) => void): ConfigOverrides;
|
|
180
180
|
export declare function effectiveZoomOut(config: Pick<RenderConfig, 'zoom' | 'zoomOut'>): number;
|
|
181
|
-
declare const LOOK_SETTINGS_KEYS: readonly ["style", "view", "zoom", "zoomOut", "hud", "
|
|
181
|
+
declare const LOOK_SETTINGS_KEYS: readonly ["style", "view", "zoom", "zoomOut", "hud", "trailColor"];
|
|
182
182
|
declare const ENCODE_SETTINGS_KEYS: readonly ["codec", "quality", "preset"];
|
|
183
|
-
export declare const SETTINGS_KEYS: readonly ["style", "view", "zoom", "zoomOut", "hud", "
|
|
183
|
+
export declare const SETTINGS_KEYS: readonly ["style", "view", "zoom", "zoomOut", "hud", "trailColor", "codec", "quality", "preset"];
|
|
184
184
|
export type AppearanceSettings = Pick<RenderConfig, (typeof LOOK_SETTINGS_KEYS)[number]>;
|
|
185
185
|
export type EncodeSettings = Pick<RenderConfig, (typeof ENCODE_SETTINGS_KEYS)[number]>;
|
|
186
186
|
export type SettingsPatch = Pick<RenderConfig, (typeof SETTINGS_KEYS)[number]>;
|
|
@@ -202,7 +202,6 @@ export declare function finalizeRenderConfig(config: RenderConfig): RenderConfig
|
|
|
202
202
|
export interface ExportRequest {
|
|
203
203
|
outPath: string;
|
|
204
204
|
config: RenderConfig;
|
|
205
|
-
range: FrameRange | null;
|
|
206
205
|
}
|
|
207
206
|
export declare function parseExportRequest(raw: unknown, base: RenderConfig): ExportRequest;
|
|
208
207
|
export {};
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { parseFrameRange } from 'drone-path-core/frame-range';
|
|
3
2
|
import { asRecord, isRecord, numberValue, parseValue, strictShape } from 'drone-path-core/validation';
|
|
4
3
|
export const MAP_STYLE_VALUES = ['satellite', 'topo'];
|
|
5
4
|
const VIEW_MODE_VALUES = ['follow', 'overview'];
|
|
@@ -113,8 +112,6 @@ export const OVERRIDE_NORMALIZERS = {
|
|
|
113
112
|
view: (v, name) => ({ view: parseValue(enumValue(name, VIEW_MODE_VALUES), v) }),
|
|
114
113
|
zoom: (v, name) => ({ zoom: parseValue(numberValue(name), v) }),
|
|
115
114
|
zoomOut: (v, name) => ({ zoomOut: parseValue(numberValue(name), v) }),
|
|
116
|
-
introSec: (v, name) => ({ introSec: parseValue(numberValue(name), v) }),
|
|
117
|
-
outroSec: (v, name) => ({ outroSec: parseValue(numberValue(name), v) }),
|
|
118
115
|
trailColor: (v, name) => ({ trailColor: asTrailColor(v, name) }),
|
|
119
116
|
hud: (v, name) => ({ hud: parseHud(parseValue(stringValue(name), v)) }),
|
|
120
117
|
workers: (v, name) => ({ workers: parseValue(numberValue(name), v) }),
|
|
@@ -185,18 +182,6 @@ export const CONFIG_OPTIONS = [
|
|
|
185
182
|
default: 1,
|
|
186
183
|
normalize: OVERRIDE_NORMALIZERS.zoomOut,
|
|
187
184
|
},
|
|
188
|
-
{
|
|
189
|
-
key: 'introSec',
|
|
190
|
-
cli: { flags: '--intro-sec <s>', help: 'intro: zoom in from one level out over s seconds', parse: cliNumber },
|
|
191
|
-
default: 2,
|
|
192
|
-
normalize: OVERRIDE_NORMALIZERS.introSec,
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
key: 'outroSec',
|
|
196
|
-
cli: { flags: '--outro-sec <s>', help: 'outro: zoom back out over s seconds', parse: cliNumber },
|
|
197
|
-
default: 2,
|
|
198
|
-
normalize: OVERRIDE_NORMALIZERS.outroSec,
|
|
199
|
-
},
|
|
200
185
|
{
|
|
201
186
|
key: 'trailColor',
|
|
202
187
|
cli: {
|
|
@@ -361,11 +346,20 @@ export function cliDefaultOf(key) {
|
|
|
361
346
|
}
|
|
362
347
|
export const DEFAULT_CONFIG = Object.freeze(Object.fromEntries(CONFIG_OPTIONS.map((row) => [row.key, row.default])));
|
|
363
348
|
Object.freeze(DEFAULT_CONFIG.hud);
|
|
349
|
+
export const RETIRED_ZOOM_OPTIONS = [
|
|
350
|
+
{ key: 'introSec', flags: '--intro-sec <s>' },
|
|
351
|
+
{ key: 'outroSec', flags: '--outro-sec <s>' },
|
|
352
|
+
];
|
|
353
|
+
export const RETIRED_ZOOM_HELP = 'Deprecated and ignored. Remove this option from your settings.';
|
|
354
|
+
export function retiredZoomWarning(option) {
|
|
355
|
+
return `deprecated option ${option} is ignored: automatic opening and closing zoom has been removed`;
|
|
356
|
+
}
|
|
364
357
|
const OVERRIDE_SHAPE = {
|
|
365
358
|
...Object.fromEntries(CONFIG_OPTIONS.map((row) => [row.key, z.unknown().optional()])),
|
|
366
359
|
// The deprecated alias is accepted as an input spelling only; it never
|
|
367
360
|
// becomes its own config key.
|
|
368
361
|
[TELEMETRY_JSON_ALIAS.inputKey]: z.unknown().optional(),
|
|
362
|
+
...Object.fromEntries(RETIRED_ZOOM_OPTIONS.map(({ key }) => [key, z.unknown().optional()])),
|
|
369
363
|
};
|
|
370
364
|
export function normalizeOverrides(raw, origin, onDeprecated) {
|
|
371
365
|
parseValue(strictShape(OVERRIDE_SHAPE, {
|
|
@@ -376,6 +370,10 @@ export function normalizeOverrides(raw, origin, onDeprecated) {
|
|
|
376
370
|
for (const key of Object.keys(raw)) {
|
|
377
371
|
if (key === TELEMETRY_JSON_ALIAS.inputKey)
|
|
378
372
|
continue;
|
|
373
|
+
if (RETIRED_ZOOM_OPTIONS.some((option) => option.key === key)) {
|
|
374
|
+
onDeprecated?.(retiredZoomWarning(key));
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
379
377
|
const normalize = OVERRIDE_NORMALIZERS[key];
|
|
380
378
|
const value = raw[key];
|
|
381
379
|
if (value === undefined)
|
|
@@ -400,8 +398,6 @@ const LOOK_SETTINGS_KEYS = [
|
|
|
400
398
|
'zoom',
|
|
401
399
|
'zoomOut',
|
|
402
400
|
'hud',
|
|
403
|
-
'introSec',
|
|
404
|
-
'outroSec',
|
|
405
401
|
'trailColor',
|
|
406
402
|
];
|
|
407
403
|
const ENCODE_SETTINGS_KEYS = ['codec', 'quality', 'preset'];
|
|
@@ -415,8 +411,6 @@ export function appearanceOf(config) {
|
|
|
415
411
|
zoom: config.zoom,
|
|
416
412
|
zoomOut: config.zoomOut,
|
|
417
413
|
hud: { ...config.hud },
|
|
418
|
-
introSec: config.introSec,
|
|
419
|
-
outroSec: config.outroSec,
|
|
420
414
|
trailColor: config.trailColor,
|
|
421
415
|
};
|
|
422
416
|
}
|
|
@@ -464,10 +458,6 @@ export function parseAppearanceSettings(raw) {
|
|
|
464
458
|
const zoomOut = parseValue(numberValue('zoom-out'), look.zoomOut);
|
|
465
459
|
requireNonNegative(zoom, 'zoom must be >= 0 (0 = auto-fit)');
|
|
466
460
|
requireNonNegative(zoomOut, 'zoom-out must be >= 0');
|
|
467
|
-
const introSec = parseValue(numberValue('intro'), look.introSec);
|
|
468
|
-
const outroSec = parseValue(numberValue('outro'), look.outroSec);
|
|
469
|
-
requireNonNegative(introSec, 'intro must be 0 or more');
|
|
470
|
-
requireNonNegative(outroSec, 'outro must be 0 or more');
|
|
471
461
|
const trailColor = asTrailColor(look.trailColor ?? null, 'trail color');
|
|
472
462
|
const chips = asRecord(hud);
|
|
473
463
|
return {
|
|
@@ -476,8 +466,6 @@ export function parseAppearanceSettings(raw) {
|
|
|
476
466
|
zoom,
|
|
477
467
|
zoomOut,
|
|
478
468
|
hud: { heading: !!chips.heading, alt: !!chips.alt, speed: !!chips.speed },
|
|
479
|
-
introSec,
|
|
480
|
-
outroSec,
|
|
481
469
|
trailColor,
|
|
482
470
|
};
|
|
483
471
|
}
|
|
@@ -514,8 +502,6 @@ export function isValidRenderConfig(config) {
|
|
|
514
502
|
isValidWorkerCount(config.workers) &&
|
|
515
503
|
isNonNegative(config.zoom) &&
|
|
516
504
|
isNonNegative(config.zoomOut) &&
|
|
517
|
-
isNonNegative(config.introSec) &&
|
|
518
|
-
isNonNegative(config.outroSec) &&
|
|
519
505
|
config.outSuffix !== '');
|
|
520
506
|
}
|
|
521
507
|
export function validateRenderConfig(config) {
|
|
@@ -525,9 +511,6 @@ export function validateRenderConfig(config) {
|
|
|
525
511
|
}
|
|
526
512
|
requireNonNegative(config.zoom, 'zoom must be >= 0 (0 = auto-fit)');
|
|
527
513
|
requireNonNegative(config.zoomOut, 'zoom-out must be >= 0');
|
|
528
|
-
if (!isNonNegative(config.introSec) || !isNonNegative(config.outroSec)) {
|
|
529
|
-
throw new Error('intro-sec and outro-sec must be >= 0');
|
|
530
|
-
}
|
|
531
514
|
if (!config.outSuffix)
|
|
532
515
|
throw new Error('out-suffix must not be empty');
|
|
533
516
|
}
|
|
@@ -559,7 +542,6 @@ function parseRequestConfig(raw, base) {
|
|
|
559
542
|
const EXPORT_REQUEST_SCHEMA = z.preprocess(keyedObjectInput, strictShape({
|
|
560
543
|
outPath: z.unknown().optional(),
|
|
561
544
|
config: z.unknown().optional(),
|
|
562
|
-
range: z.unknown().optional(),
|
|
563
545
|
}, {
|
|
564
546
|
invalid: 'invalid export request',
|
|
565
547
|
unknownKey: (key) => `unknown export request key ${key}`,
|
|
@@ -570,8 +552,5 @@ export function parseExportRequest(raw, base) {
|
|
|
570
552
|
if (!outPath.toLowerCase().endsWith('.mp4')) {
|
|
571
553
|
throw new Error(`export request: outPath must be an .mp4 file: ${outPath}`);
|
|
572
554
|
}
|
|
573
|
-
|
|
574
|
-
? null
|
|
575
|
-
: parseFrameRange(request.range);
|
|
576
|
-
return { outPath, config: parseRequestConfig(request.config, base), range };
|
|
555
|
+
return { outPath, config: parseRequestConfig(request.config, base) };
|
|
577
556
|
}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare function samePath(a: string, b: string, platform?: NodeJS.Platform): boolean;
|
|
1
|
+
export { pathKey, samePath } from 'drone-path-core/paths';
|
|
3
2
|
export declare function uniquePath(dir: string, stem: string, ext: string, isTaken: (candidate: string) => boolean): string;
|
|
4
3
|
export declare function userDataDir(): string;
|
package/dist/paths.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
export
|
|
4
|
-
const resolved = platform === 'win32' ? path.win32.resolve(p) : path.posix.resolve(p);
|
|
5
|
-
return platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
6
|
-
}
|
|
7
|
-
export function samePath(a, b, platform = process.platform) {
|
|
8
|
-
return pathKey(a, platform) === pathKey(b, platform);
|
|
9
|
-
}
|
|
3
|
+
export { pathKey, samePath } from 'drone-path-core/paths';
|
|
10
4
|
export function uniquePath(dir, stem, ext, isTaken) {
|
|
11
5
|
for (let n = 1;; n++) {
|
|
12
6
|
const name = n === 1 ? `${stem}${ext}` : `${stem}-${n}${ext}`;
|
package/dist/pipeline.d.ts
CHANGED
|
@@ -10,12 +10,11 @@ import type { TelemetryDocumentInput, TelemetryFrameInput } from 'drone-path-cor
|
|
|
10
10
|
import type { TrackRecord, TrackStream } from 'drone-path-core/track';
|
|
11
11
|
import { prefetchTiles } from './tiles.js';
|
|
12
12
|
import { INITIAL_PREPARE_PROGRESS } from './plan.js';
|
|
13
|
-
import type {
|
|
13
|
+
import type { OverviewPlan, PrepareProgress, PrepareStage } from './plan.js';
|
|
14
14
|
import type { RenderPageOpts } from './render-page.js';
|
|
15
15
|
import { renderVideo } from './render.js';
|
|
16
16
|
import type { CaptureProgress } from './render.js';
|
|
17
17
|
import type { HudLayout, RenderConfig } from './config.js';
|
|
18
|
-
import type { FrameRange } from 'drone-path-core/frame-range';
|
|
19
18
|
import type { TelemetrySummary } from 'drone-path-core/telemetry-summary';
|
|
20
19
|
import type { LogFn } from './logging.js';
|
|
21
20
|
export { INITIAL_PREPARE_PROGRESS };
|
|
@@ -31,7 +30,6 @@ export interface RecordingSummary extends Partial<Pick<TelemetrySummary, 'source
|
|
|
31
30
|
hud?: HudLayout;
|
|
32
31
|
frames?: number;
|
|
33
32
|
fps?: string;
|
|
34
|
-
frameRange?: FrameRange;
|
|
35
33
|
bbox?: Bbox;
|
|
36
34
|
zoomFixed?: boolean;
|
|
37
35
|
tilesDownloaded?: number;
|
|
@@ -63,7 +61,6 @@ export interface PipelineDeps {
|
|
|
63
61
|
interface PipelineOptions {
|
|
64
62
|
deps?: Partial<PipelineDeps>;
|
|
65
63
|
tools?: FfmpegToolPaths;
|
|
66
|
-
range?: FrameRange;
|
|
67
64
|
signal?: AbortSignal;
|
|
68
65
|
onProgress?: PrepareProgressFn;
|
|
69
66
|
onCapture?: (progress: CaptureProgress) => void;
|
|
@@ -78,7 +75,6 @@ interface PreparedRecording {
|
|
|
78
75
|
protoFile: string | null;
|
|
79
76
|
gimbalDevice: GimbalDeviceConstants | null;
|
|
80
77
|
hud: HudLayout;
|
|
81
|
-
introOutro: IntroOutroFrames;
|
|
82
78
|
overview: OverviewPlan;
|
|
83
79
|
frames: FrameChannels;
|
|
84
80
|
}
|
package/dist/pipeline.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { ERR_OUTPUT_VERIFICATION,
|
|
3
|
+
import { ERR_OUTPUT_VERIFICATION, codedError, errorMessage } from 'drone-path-core/errors';
|
|
4
|
+
import { renderCanceledError } from './render-cancellation.js';
|
|
4
5
|
import { probeVideo } from 'drone-path-core/ffmpeg';
|
|
5
6
|
import { outputMatchesSource, verifyOutput } from './ffmpeg-output.js';
|
|
6
7
|
import { resolveFfmpegTools } from 'drone-path-core/ffmpeg-tools';
|
|
@@ -9,11 +10,10 @@ import { pathKey, uniquePath } from './paths.js';
|
|
|
9
10
|
import { loadTelemetry } from 'drone-path-core/telemetry';
|
|
10
11
|
import { writeTrackFile } from 'drone-path-core/track-write';
|
|
11
12
|
import { prefetchTiles } from './tiles.js';
|
|
12
|
-
import { INITIAL_PREPARE_PROGRESS, PREPARE_STAGE_ORDER,
|
|
13
|
+
import { INITIAL_PREPARE_PROGRESS, PREPARE_STAGE_ORDER, planView, } from './plan.js';
|
|
13
14
|
import { buildPageHtml, planPageOpts } from './render-page.js';
|
|
14
15
|
import { renderVideo } from './render.js';
|
|
15
16
|
import { effectiveZoomOut, hasAltitude, resolveHudLayout } from './config.js';
|
|
16
|
-
import { resolveFrameRange } from 'drone-path-core/frame-range';
|
|
17
17
|
import { fixCountLabel, noLockCountLabel, telemetrySummary, trackDistanceLabel, } from 'drone-path-core/telemetry-summary';
|
|
18
18
|
export { INITIAL_PREPARE_PROGRESS };
|
|
19
19
|
export function outputPathFor(videoPath, config) {
|
|
@@ -130,18 +130,11 @@ function createPrepareReporter(onProgress = () => { }) {
|
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
async function probeStage(env) {
|
|
133
|
-
const { videoPath,
|
|
133
|
+
const { videoPath, log, deps, tools, report } = env;
|
|
134
134
|
report('probe');
|
|
135
135
|
const probe = await deps.probeVideo(tools, videoPath, log);
|
|
136
136
|
log(`source: ${path.basename(videoPath)} ${probe.width}x${probe.height} @ ${probe.fps.str} fps, ${probe.frames} frames`);
|
|
137
|
-
|
|
138
|
-
fps: probe.fps.value,
|
|
139
|
-
frames: probe.frames,
|
|
140
|
-
});
|
|
141
|
-
if (introOutro.clamped) {
|
|
142
|
-
log(`intro/outro shortened to ${introOutro.introN}/${introOutro.outroN} frames for this clip`);
|
|
143
|
-
}
|
|
144
|
-
return { probe, introOutro };
|
|
137
|
+
return probe;
|
|
145
138
|
}
|
|
146
139
|
async function telemetryStage(env, probe) {
|
|
147
140
|
const { videoPath, config, log, deps, tools, report } = env;
|
|
@@ -175,12 +168,9 @@ async function viewPlanStage(env, tel) {
|
|
|
175
168
|
log(describeView(config, overview, config.style));
|
|
176
169
|
return overview;
|
|
177
170
|
}
|
|
178
|
-
function canceledError(cause) {
|
|
179
|
-
return codedError(ERR_RENDER_CANCELED, { code: 'RENDER_CANCELED', cause });
|
|
180
|
-
}
|
|
181
171
|
async function tileWarmStage(deps, config, overview, log, signal) {
|
|
182
172
|
if (signal?.aborted)
|
|
183
|
-
throw
|
|
173
|
+
throw renderCanceledError();
|
|
184
174
|
let tileStats;
|
|
185
175
|
try {
|
|
186
176
|
tileStats = await deps.prefetchTiles({
|
|
@@ -192,11 +182,11 @@ async function tileWarmStage(deps, config, overview, log, signal) {
|
|
|
192
182
|
}
|
|
193
183
|
catch (err) {
|
|
194
184
|
if (signal?.aborted)
|
|
195
|
-
throw
|
|
185
|
+
throw renderCanceledError(err);
|
|
196
186
|
throw err;
|
|
197
187
|
}
|
|
198
188
|
if (signal?.aborted)
|
|
199
|
-
throw
|
|
189
|
+
throw renderCanceledError();
|
|
200
190
|
if (tileStats.downloaded) {
|
|
201
191
|
log(`tiles: ${tileStats.downloaded} downloaded, ${tileStats.failed} placeholders`);
|
|
202
192
|
}
|
|
@@ -204,7 +194,7 @@ async function tileWarmStage(deps, config, overview, log, signal) {
|
|
|
204
194
|
}
|
|
205
195
|
async function prepareWithEnv(env) {
|
|
206
196
|
const { width, height } = env.config;
|
|
207
|
-
const
|
|
197
|
+
const probe = await probeStage(env);
|
|
208
198
|
const { tel, frameValues, trackValues, protoFile, gimbalDevice, hud } = await telemetryStage(env, probe);
|
|
209
199
|
const overview = await viewPlanStage(env, tel);
|
|
210
200
|
const frames = frameChannelsOf(tel);
|
|
@@ -218,7 +208,6 @@ async function prepareWithEnv(env) {
|
|
|
218
208
|
protoFile,
|
|
219
209
|
gimbalDevice,
|
|
220
210
|
hud,
|
|
221
|
-
introOutro,
|
|
222
211
|
overview,
|
|
223
212
|
frames,
|
|
224
213
|
};
|
|
@@ -239,17 +228,15 @@ export function recordingPageOpts(prep, config) {
|
|
|
239
228
|
width: prep.width,
|
|
240
229
|
height: prep.height,
|
|
241
230
|
config,
|
|
242
|
-
source: { fps: prep.probe.fps.value, frames: prep.probe.frames },
|
|
243
231
|
frames: prep.frames,
|
|
244
232
|
planned: {
|
|
245
233
|
overview: prep.overview,
|
|
246
|
-
introOutro: prep.introOutro,
|
|
247
234
|
hud: prep.hud,
|
|
248
235
|
},
|
|
249
236
|
});
|
|
250
237
|
}
|
|
251
238
|
function buildOkSummary(ctx, elapsedSec) {
|
|
252
|
-
const { config, probe, tel, hud,
|
|
239
|
+
const { config, probe, tel, hud, overview, tileStats } = ctx;
|
|
253
240
|
const telemetry = telemetrySummary(tel);
|
|
254
241
|
return {
|
|
255
242
|
video: ctx.videoPath,
|
|
@@ -259,8 +246,8 @@ function buildOkSummary(ctx, elapsedSec) {
|
|
|
259
246
|
height: ctx.height,
|
|
260
247
|
style: config.style,
|
|
261
248
|
view: config.view,
|
|
262
|
-
introFrames:
|
|
263
|
-
outroFrames:
|
|
249
|
+
introFrames: 0,
|
|
250
|
+
outroFrames: 0,
|
|
264
251
|
hud,
|
|
265
252
|
// Field by field, not a spread: a TelemetrySummary rename must land here visibly, not silently drop a --json key.
|
|
266
253
|
source: telemetry.source,
|
|
@@ -269,9 +256,8 @@ function buildOkSummary(ctx, elapsedSec) {
|
|
|
269
256
|
fixes: telemetry.fixCount,
|
|
270
257
|
noLock: telemetry.noLock,
|
|
271
258
|
trackDistanceM: telemetry.trackDistanceM,
|
|
272
|
-
frames:
|
|
259
|
+
frames: probe.frames,
|
|
273
260
|
fps: probe.fps.str,
|
|
274
|
-
frameRange: ctx.frameRange ?? undefined,
|
|
275
261
|
bbox: tel.bbox,
|
|
276
262
|
zoom: overview.zoom,
|
|
277
263
|
zoomFixed: config.zoom > 0,
|
|
@@ -283,22 +269,20 @@ function buildOkSummary(ctx, elapsedSec) {
|
|
|
283
269
|
}
|
|
284
270
|
async function verifyRenderedOutput(env) {
|
|
285
271
|
const { ctx, deps, tools } = env;
|
|
286
|
-
const verify = await deps.verifyOutput(tools, ctx.outPath, ctx.
|
|
272
|
+
const verify = await deps.verifyOutput(tools, ctx.outPath, ctx.probe.frames, ctx.probe.fps.value);
|
|
287
273
|
if (!verify.ok) {
|
|
288
274
|
throw codedError(`${ERR_OUTPUT_VERIFICATION}got ${verify.frames} frames @ ${verify.fps ?? 'unknown'}, ` +
|
|
289
|
-
`expected ${ctx.
|
|
275
|
+
`expected ${ctx.probe.frames} @ ${ctx.probe.fps.str}`, {
|
|
290
276
|
code: 'OUTPUT_VERIFICATION',
|
|
291
277
|
params: {
|
|
292
278
|
frames: verify.frames,
|
|
293
279
|
fps: verify.fps ?? 'unknown',
|
|
294
|
-
expectedFrames: ctx.
|
|
280
|
+
expectedFrames: ctx.probe.frames,
|
|
295
281
|
expectedFps: ctx.probe.fps.str,
|
|
296
282
|
},
|
|
297
283
|
});
|
|
298
284
|
}
|
|
299
|
-
ctx.log(
|
|
300
|
-
? 'verified: frame count and frame rate are 1:1 within the exported range'
|
|
301
|
-
: 'verified: frame count and frame rate match the source');
|
|
285
|
+
ctx.log('verified: frame count and frame rate match the source');
|
|
302
286
|
}
|
|
303
287
|
async function renderToOutput(env) {
|
|
304
288
|
const { ctx, deps, tools, options } = env;
|
|
@@ -316,8 +300,7 @@ async function renderToOutput(env) {
|
|
|
316
300
|
tools,
|
|
317
301
|
width: ctx.width,
|
|
318
302
|
height: ctx.height,
|
|
319
|
-
frames: ctx.
|
|
320
|
-
frameStart: ctx.frameRange?.start ?? 0,
|
|
303
|
+
frames: ctx.probe.frames,
|
|
321
304
|
fpsStr: ctx.probe.fps.str,
|
|
322
305
|
workers: ctx.config.workers,
|
|
323
306
|
outPath: ctx.outPath,
|
|
@@ -351,9 +334,7 @@ export function trackExportStream(prep) {
|
|
|
351
334
|
};
|
|
352
335
|
}
|
|
353
336
|
function writeTrackExport(file, prep, log) {
|
|
354
|
-
|
|
355
|
-
// limits the render, never this export.
|
|
356
|
-
writeTrackFile(file, { document: telemetryExportInput(prep), track: trackExportStream(prep) }, null);
|
|
337
|
+
writeTrackFile(file, { document: telemetryExportInput(prep), track: trackExportStream(prep) });
|
|
357
338
|
log(`track: wrote ${file}`);
|
|
358
339
|
}
|
|
359
340
|
export async function processRecording(videoPath, config, log, outPath = outputPathFor(videoPath, config), options = {}) {
|
|
@@ -361,7 +342,7 @@ export async function processRecording(videoPath, config, log, outPath = outputP
|
|
|
361
342
|
const deps = resolveDeps(options.deps, config.tileCache);
|
|
362
343
|
const tools = options.tools ?? resolveFfmpegTools(config);
|
|
363
344
|
if (options.signal?.aborted)
|
|
364
|
-
throw
|
|
345
|
+
throw renderCanceledError();
|
|
365
346
|
const prep = await prepareWithEnv({
|
|
366
347
|
videoPath,
|
|
367
348
|
config,
|
|
@@ -371,21 +352,17 @@ export async function processRecording(videoPath, config, log, outPath = outputP
|
|
|
371
352
|
report: createPrepareReporter(options.onProgress),
|
|
372
353
|
});
|
|
373
354
|
if (options.signal?.aborted)
|
|
374
|
-
throw
|
|
355
|
+
throw renderCanceledError();
|
|
375
356
|
if (config.trackOut) {
|
|
376
357
|
writeTrackExport(config.trackOut, prep, log);
|
|
377
358
|
}
|
|
378
359
|
const tileStats = await tileWarmStage(deps, config, prep.overview, log, options.signal);
|
|
379
|
-
const range = resolveFrameRange(options.range, prep.probe.frames);
|
|
380
|
-
const outFrames = range ? range.end - range.start + 1 : prep.probe.frames;
|
|
381
360
|
const ctx = {
|
|
382
361
|
...prep,
|
|
383
362
|
videoPath,
|
|
384
363
|
outPath,
|
|
385
364
|
config,
|
|
386
365
|
log,
|
|
387
|
-
outFrames,
|
|
388
|
-
frameRange: range,
|
|
389
366
|
tileStats,
|
|
390
367
|
};
|
|
391
368
|
await renderToOutput({ ctx, deps, tools, options });
|
package/dist/plan.d.ts
CHANGED
|
@@ -26,16 +26,7 @@ export declare function zoomLimits(style: MapStyle): {
|
|
|
26
26
|
max: number;
|
|
27
27
|
};
|
|
28
28
|
export declare function computeOverview({ bbox, width, height, maxZoom, zoomOut, follow, maxNativeZoom, zoomOverride, }: OverviewPlanOptions): OverviewPlan;
|
|
29
|
-
export interface IntroOutroFrames {
|
|
30
|
-
introN: number;
|
|
31
|
-
outroN: number;
|
|
32
|
-
clamped: boolean;
|
|
33
|
-
}
|
|
34
29
|
export declare function planView(bbox: Bbox, width: number, height: number, config: Pick<RenderConfig, 'style' | 'view' | 'zoom' | 'zoomOut'>): OverviewPlan;
|
|
35
|
-
export declare function planIntroOutroFrames(config: Pick<RenderConfig, 'introSec' | 'outroSec'>, source: {
|
|
36
|
-
fps: number;
|
|
37
|
-
frames: number;
|
|
38
|
-
}): IntroOutroFrames;
|
|
39
30
|
export declare const PREPARE_STAGE_ORDER: readonly ["probe", "telemetry", "plan"];
|
|
40
31
|
export type PrepareStage = (typeof PREPARE_STAGE_ORDER)[number];
|
|
41
32
|
export interface PrepareProgress {
|
package/dist/plan.js
CHANGED
|
@@ -93,18 +93,6 @@ export function planView(bbox, width, height, config) {
|
|
|
93
93
|
follow: config.view === 'follow',
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
-
export function planIntroOutroFrames(config, source) {
|
|
97
|
-
let introN = Math.max(0, Math.round(config.introSec * source.fps));
|
|
98
|
-
let outroN = Math.max(0, Math.round(config.outroSec * source.fps));
|
|
99
|
-
const budget = Math.max(2, Math.floor(source.frames / 2));
|
|
100
|
-
const clamped = introN + outroN > budget;
|
|
101
|
-
if (clamped) {
|
|
102
|
-
const scale = budget / (introN + outroN);
|
|
103
|
-
introN = Math.floor(introN * scale);
|
|
104
|
-
outroN = Math.floor(outroN * scale);
|
|
105
|
-
}
|
|
106
|
-
return { introN, outroN, clamped };
|
|
107
|
-
}
|
|
108
96
|
export const PREPARE_STAGE_ORDER = ['probe', 'telemetry', 'plan'];
|
|
109
97
|
export const INITIAL_PREPARE_PROGRESS = {
|
|
110
98
|
stage: PREPARE_STAGE_ORDER[0],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderCanceledError(cause?: unknown): Error;
|
package/dist/render-page.d.ts
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
import type { AppearanceSettings, HudLayout, RenderConfig } from './config.js';
|
|
2
2
|
import type { DecimatedTrack } from './decimate.js';
|
|
3
3
|
import type { Bbox, LatLon } from 'drone-path-core/geo';
|
|
4
|
-
import type {
|
|
4
|
+
import type { OverviewPlan } from './plan.js';
|
|
5
5
|
import type { SceneData } from './renderer/scene.js';
|
|
6
6
|
import type { FrameChannels } from 'drone-path-core/telemetry-math';
|
|
7
7
|
export interface RenderPageOpts extends FrameChannels, Pick<RenderConfig, 'width' | 'height'>, Pick<AppearanceSettings, 'style' | 'view' | 'zoom' | 'trailColor' | 'hud'> {
|
|
8
8
|
center: LatLon;
|
|
9
9
|
attribution: string;
|
|
10
10
|
decimated: DecimatedTrack;
|
|
11
|
-
introN?: number;
|
|
12
|
-
outroN?: number;
|
|
13
11
|
}
|
|
14
12
|
export declare function planPageOpts(opts: {
|
|
15
13
|
bbox: Bbox;
|
|
16
14
|
width: number;
|
|
17
15
|
height: number;
|
|
18
16
|
config: AppearanceSettings;
|
|
19
|
-
source: {
|
|
20
|
-
fps: number;
|
|
21
|
-
frames: number;
|
|
22
|
-
};
|
|
23
17
|
frames: FrameChannels;
|
|
24
18
|
planned?: {
|
|
25
19
|
overview: OverviewPlan;
|
|
26
|
-
introOutro: IntroOutroFrames;
|
|
27
20
|
hud: HudLayout;
|
|
28
21
|
};
|
|
29
22
|
previous?: {
|
package/dist/render-page.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { hasAltitude, resolveHudLayout } from './config.js';
|
|
2
2
|
import { decimateTrack } from './decimate.js';
|
|
3
3
|
import { unproject } from 'drone-path-core/geo';
|
|
4
|
-
import {
|
|
4
|
+
import { planView } from './plan.js';
|
|
5
5
|
import { TILE_SOURCES } from './renderer/tilesources.js';
|
|
6
6
|
export function planPageOpts(opts) {
|
|
7
|
-
const { bbox, width, height, config,
|
|
7
|
+
const { bbox, width, height, config, frames, planned, previous } = opts;
|
|
8
8
|
const overview = planned?.overview ?? planView(bbox, width, height, config);
|
|
9
|
-
const introOutro = planned?.introOutro ?? planIntroOutroFrames(config, source);
|
|
10
9
|
const hud = planned?.hud ?? resolveHudLayout(config.hud, hasAltitude(frames.alt));
|
|
11
10
|
const decimated = previous && previous.zoom === overview.zoom
|
|
12
11
|
? previous.decimated
|
|
@@ -20,8 +19,6 @@ export function planPageOpts(opts) {
|
|
|
20
19
|
center: unproject(overview.centerPx.x, overview.centerPx.y, overview.zoom),
|
|
21
20
|
zoom: overview.zoom,
|
|
22
21
|
attribution: TILE_SOURCES[config.style].attribution,
|
|
23
|
-
introN: introOutro.introN,
|
|
24
|
-
outroN: introOutro.outroN,
|
|
25
22
|
lat: frames.lat,
|
|
26
23
|
lon: frames.lon,
|
|
27
24
|
alt: frames.alt,
|
|
@@ -32,7 +29,7 @@ export function planPageOpts(opts) {
|
|
|
32
29
|
};
|
|
33
30
|
}
|
|
34
31
|
export function buildSceneData(opts, tileBase) {
|
|
35
|
-
const { width, height, style, trailColor, view, center, zoom, attribution, lat, lon, alt, speed, headingDeg, hud, decimated,
|
|
32
|
+
const { width, height, style, trailColor, view, center, zoom, attribution, lat, lon, alt, speed, headingDeg, hud, decimated, } = opts;
|
|
36
33
|
return {
|
|
37
34
|
style,
|
|
38
35
|
trailColor,
|
|
@@ -43,8 +40,6 @@ export function buildSceneData(opts, tileBase) {
|
|
|
43
40
|
zoom,
|
|
44
41
|
center: { lat: center.lat, lon: center.lon },
|
|
45
42
|
attribution,
|
|
46
|
-
introN,
|
|
47
|
-
outroN,
|
|
48
43
|
lat, lon, alt, speed, headingDeg,
|
|
49
44
|
hud,
|
|
50
45
|
trailLat: decimated.lat,
|
package/dist/render.d.ts
CHANGED
|
@@ -37,7 +37,6 @@ export interface CaptureProgress {
|
|
|
37
37
|
export interface RenderJobOptions extends Pick<RenderConfig, 'style' | 'tileCache' | 'width' | 'height' | 'workers' | 'capture' | 'codec' | 'quality' | 'preset'> {
|
|
38
38
|
html: string;
|
|
39
39
|
frames: number;
|
|
40
|
-
frameStart?: number;
|
|
41
40
|
fpsStr: string;
|
|
42
41
|
outPath: string;
|
|
43
42
|
log?: LogFn;
|
package/dist/render.js
CHANGED
|
@@ -2,8 +2,9 @@ import http from 'node:http';
|
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { once } from 'node:events';
|
|
4
4
|
import { MIME } from './assets.js';
|
|
5
|
-
import { ERR_RENDER_CANCELED,
|
|
5
|
+
import { ERR_RENDER_CANCELED, errorMessage } from 'drone-path-core/errors';
|
|
6
6
|
import { RENDERER_DIR, serveAsset } from './serve.js';
|
|
7
|
+
import { renderCanceledError } from './render-cancellation.js';
|
|
7
8
|
const PAGE_LOAD_TIMEOUT_MS = 60000;
|
|
8
9
|
const SCREENSHOT_TIMEOUT_MS = 60000;
|
|
9
10
|
function startServer({ html, style, tileCache, log, }) {
|
|
@@ -253,7 +254,7 @@ function screenshotOptions(capture) {
|
|
|
253
254
|
}
|
|
254
255
|
async function captureFrame(run, loop, page, idx) {
|
|
255
256
|
const evalStart = Date.now();
|
|
256
|
-
await page.evaluate((frame) => globalThis.__setFrame(frame),
|
|
257
|
+
await page.evaluate((frame) => globalThis.__setFrame(frame), idx);
|
|
257
258
|
run.timing.evalMs += Date.now() - evalStart;
|
|
258
259
|
const captureStart = Date.now();
|
|
259
260
|
const buf = await page.screenshot(screenshotOptions(run.capture));
|
|
@@ -267,9 +268,6 @@ async function captureFrame(run, loop, page, idx) {
|
|
|
267
268
|
run.onCapture?.({ done, total: run.frames });
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
|
-
function canceledError(cause) {
|
|
271
|
-
return codedError(ERR_RENDER_CANCELED, { code: 'RENDER_CANCELED', cause });
|
|
272
|
-
}
|
|
273
271
|
async function workerLoop(run, loop, workerId) {
|
|
274
272
|
const page = await run.active.newPage({
|
|
275
273
|
viewport: { width: run.width, height: run.height },
|
|
@@ -282,7 +280,7 @@ async function workerLoop(run, loop, workerId) {
|
|
|
282
280
|
if (loop.failed)
|
|
283
281
|
return;
|
|
284
282
|
if (run.signal?.aborted)
|
|
285
|
-
throw
|
|
283
|
+
throw renderCanceledError();
|
|
286
284
|
const idx = loop.cursor++;
|
|
287
285
|
if (idx >= run.frames)
|
|
288
286
|
break;
|
|
@@ -329,13 +327,13 @@ async function captureAndEncode(active, env) {
|
|
|
329
327
|
const stream = new OrderedFrameStream(encoder, workerCount);
|
|
330
328
|
const abortEncode = () => {
|
|
331
329
|
encoder.kill();
|
|
332
|
-
stream.abort(
|
|
330
|
+
stream.abort(renderCanceledError());
|
|
333
331
|
};
|
|
334
332
|
signal?.addEventListener('abort', abortEncode, { once: true });
|
|
335
333
|
try {
|
|
336
334
|
await runWorkers({ ...ctx, active, url, stream, timing }, workerCount);
|
|
337
335
|
if (signal?.aborted)
|
|
338
|
-
throw
|
|
336
|
+
throw renderCanceledError();
|
|
339
337
|
await finishEncode(encoder, stream, log, outPath);
|
|
340
338
|
}
|
|
341
339
|
catch (e) {
|
|
@@ -344,7 +342,7 @@ async function captureAndEncode(active, env) {
|
|
|
344
342
|
if (signal?.aborted) {
|
|
345
343
|
throw e instanceof Error && e.message === ERR_RENDER_CANCELED
|
|
346
344
|
? e
|
|
347
|
-
:
|
|
345
|
+
: renderCanceledError(e);
|
|
348
346
|
}
|
|
349
347
|
throw e;
|
|
350
348
|
}
|
|
@@ -363,13 +361,12 @@ function reportProfile(env) {
|
|
|
363
361
|
return { profile };
|
|
364
362
|
}
|
|
365
363
|
export async function renderVideo(opts) {
|
|
366
|
-
const { html, style, tileCache, width, height, frames, fpsStr, workers, outPath, log = () => { }, browserPath = null, tools, capture = 'jpeg', codec = 'h264', quality = 'high', preset = 'medium',
|
|
364
|
+
const { html, style, tileCache, width, height, frames, fpsStr, workers, outPath, log = () => { }, browserPath = null, tools, capture = 'jpeg', codec = 'h264', quality = 'high', preset = 'medium', signal, onCapture, } = opts;
|
|
367
365
|
const workerCount = Math.max(1, Math.min(workers, frames));
|
|
368
366
|
const ctx = {
|
|
369
367
|
width,
|
|
370
368
|
height,
|
|
371
369
|
frames,
|
|
372
|
-
frameStart,
|
|
373
370
|
fpsStr,
|
|
374
371
|
outPath,
|
|
375
372
|
capture,
|
|
@@ -382,7 +379,7 @@ export async function renderVideo(opts) {
|
|
|
382
379
|
tools,
|
|
383
380
|
};
|
|
384
381
|
if (signal?.aborted)
|
|
385
|
-
throw
|
|
382
|
+
throw renderCanceledError();
|
|
386
383
|
const timing = { evalMs: 0, captureMs: 0, emitMs: 0 };
|
|
387
384
|
const { server, url } = await startServer({ html, style, tileCache, log });
|
|
388
385
|
const env = { ctx, url, timing, workerCount };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare function computeScale(width: number, height: number): number;
|
|
2
2
|
export declare function smoothstep(t: number): number;
|
|
3
|
-
export declare function introOutroScale(i: number, introN: number, outroN: number, totalN: number): number;
|
|
4
3
|
export declare function metersPerPixel(lat: number, zoom: number): number;
|
|
5
4
|
export declare function scaleBarMeters(mPerPx: number, maxPx: number): number;
|
|
@@ -5,17 +5,6 @@ export function smoothstep(t) {
|
|
|
5
5
|
const clamped = Math.max(0, Math.min(1, t));
|
|
6
6
|
return clamped * clamped * (3 - 2 * clamped);
|
|
7
7
|
}
|
|
8
|
-
export function introOutroScale(i, introN, outroN, totalN) {
|
|
9
|
-
let kIn = 1;
|
|
10
|
-
let kOut = 1;
|
|
11
|
-
if (introN > 0 && i < introN) {
|
|
12
|
-
kIn = Math.pow(2, -(1 - smoothstep(i / introN)));
|
|
13
|
-
}
|
|
14
|
-
if (outroN > 0 && i > totalN - 1 - outroN) {
|
|
15
|
-
kOut = Math.pow(2, -(1 - smoothstep((totalN - 1 - i) / outroN)));
|
|
16
|
-
}
|
|
17
|
-
return Math.min(kIn, kOut);
|
|
18
|
-
}
|
|
19
8
|
export function metersPerPixel(lat, zoom) {
|
|
20
9
|
return (156543.033928 * Math.cos((lat * Math.PI) / 180)) / Math.pow(2, zoom);
|
|
21
10
|
}
|
package/dist/renderer/scene.d.ts
CHANGED
|
@@ -14,8 +14,6 @@ export interface SceneData extends FrameChannels {
|
|
|
14
14
|
zoom: number;
|
|
15
15
|
center: LatLon;
|
|
16
16
|
attribution: string;
|
|
17
|
-
introN: number;
|
|
18
|
-
outroN: number;
|
|
19
17
|
hud: HudLayout;
|
|
20
18
|
/** Whether this viewer draws the in-frame HUD pills; a caller that overlays
|
|
21
19
|
its own toggles (the Map appearance preview) sets this to false. */
|
package/dist/renderer/scene.js
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import { TILE_SOURCES } from './tilesources.js';
|
|
2
2
|
import { droneMarkerMarkup, el, hudMarkup, mapMarkup, quietAttributionLinks, sceneCss, stripReadoutMarkup } from './dom.js';
|
|
3
|
-
import { computeScale,
|
|
3
|
+
import { computeScale, metersPerPixel, scaleBarMeters } from './framemath.js';
|
|
4
4
|
import { themeFor } from './theme.js';
|
|
5
5
|
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
|
+
function trailLayerFor(L, line) {
|
|
10
|
+
return {
|
|
11
|
+
setLatLngs(points) {
|
|
12
|
+
line.setLatLngs(points);
|
|
13
|
+
},
|
|
14
|
+
// Mutating the live array and calling redraw() is Leaflet's documented
|
|
15
|
+
// way to skip reconverting the whole prefix; bounds are extended as
|
|
16
|
+
// addLatLng does so a line that started empty still projects.
|
|
17
|
+
spliceTail(drop, points) {
|
|
18
|
+
const latlngs = line.getLatLngs();
|
|
19
|
+
latlngs.length -= drop;
|
|
20
|
+
const bounds = line.getBounds();
|
|
21
|
+
for (const [lat, lon] of points) {
|
|
22
|
+
const ll = L.latLng(lat, lon);
|
|
23
|
+
latlngs.push(ll);
|
|
24
|
+
bounds.extend(ll);
|
|
25
|
+
}
|
|
26
|
+
line.redraw();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
9
30
|
/** A missing value renders exactly like a disabled chip: the dimmed "--". */
|
|
10
31
|
function isMissing(value) {
|
|
11
32
|
return value === null || value === undefined;
|
|
@@ -53,10 +74,13 @@ class SceneState {
|
|
|
53
74
|
this.styleEl = document.createElement('style');
|
|
54
75
|
document.head.appendChild(this.styleEl);
|
|
55
76
|
// One definedness rule for both: a caller either supplies the external
|
|
56
|
-
// strip host or gets the in-frame export HUD
|
|
77
|
+
// strip host or gets the in-frame export HUD (unless hudPills is false),
|
|
78
|
+
// never a mix of the two.
|
|
57
79
|
const externalHud = hudHost !== undefined;
|
|
58
|
-
|
|
59
|
-
|
|
80
|
+
const suppressHud = externalHud || firstData.hudPills === false;
|
|
81
|
+
host.innerHTML = mapMarkup(suppressHud ? null : firstData.hud, firstData.attribution);
|
|
82
|
+
this.frameEl = el(host, '#map-frame');
|
|
83
|
+
this.hudRoot = hudHost ?? host.querySelector('#hud');
|
|
60
84
|
this.externalHud = externalHud;
|
|
61
85
|
this.attrEl = el(host, '#attr');
|
|
62
86
|
this.applyChrome();
|
|
@@ -80,7 +104,6 @@ class SceneState {
|
|
|
80
104
|
this.tiles.addTo(this.map);
|
|
81
105
|
this.latlngs = this.latlngsOf(firstData);
|
|
82
106
|
this.bb = L.latLngBounds(this.latlngs);
|
|
83
|
-
this.frameEl = el(host, '#map-frame');
|
|
84
107
|
this.scalelineEl = el(host, '#scaleline');
|
|
85
108
|
this.scaletextEl = el(host, '#scaletext');
|
|
86
109
|
// Leaflet only creates marker DOM once the map has a view: layoutMap() must precede buildDecor() so the arrow/wrap elements exist.
|
|
@@ -104,7 +127,7 @@ class SceneState {
|
|
|
104
127
|
makeTileLayer(tileUrl, style) {
|
|
105
128
|
return this.L.tileLayer(tileUrl, {
|
|
106
129
|
maxZoom: TILE_SOURCES[style].maxZoom,
|
|
107
|
-
maxNativeZoom: TILE_SOURCES[style].maxNativeZoom
|
|
130
|
+
maxNativeZoom: TILE_SOURCES[style].maxNativeZoom,
|
|
108
131
|
});
|
|
109
132
|
}
|
|
110
133
|
latlngsOf(data) {
|
|
@@ -244,9 +267,8 @@ class SceneState {
|
|
|
244
267
|
lat: this.data.trailLat,
|
|
245
268
|
lon: this.data.trailLon,
|
|
246
269
|
frame: this.data.trailFrame,
|
|
247
|
-
}, { lat: this.data.lat, lon: this.data.lon }, trailLayers),
|
|
270
|
+
}, { lat: this.data.lat, lon: this.data.lon }, trailLayers.map((line) => trailLayerFor(this.L, line))),
|
|
248
271
|
arrowEl: this.host.querySelector('#drone-arrow'),
|
|
249
|
-
wrapEl: this.host.querySelector('.drone-wrap'),
|
|
250
272
|
};
|
|
251
273
|
if (!this.data.hud.heading && decor.arrowEl)
|
|
252
274
|
decor.arrowEl.style.display = 'none';
|
|
@@ -261,19 +283,32 @@ class SceneState {
|
|
|
261
283
|
// Scoped to the chip container so an external strip and a second scene
|
|
262
284
|
// (the export preview) can never cross-write. A scene whose caller
|
|
263
285
|
// overlays its own pills draws none of its own (#283).
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
286
|
+
if (this.externalHud) {
|
|
287
|
+
if (this.hudRoot) {
|
|
288
|
+
this.hudRoot.innerHTML = stripReadoutMarkup(this.data.hud, this.data.stripLabels);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else if (this.data.hudPills === false) {
|
|
292
|
+
this.hudRoot?.remove();
|
|
293
|
+
this.hudRoot = null;
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
if (!this.hudRoot) {
|
|
297
|
+
const hud = document.createElement('div');
|
|
298
|
+
hud.id = 'hud';
|
|
299
|
+
this.frameEl.insertBefore(hud, this.attrEl);
|
|
300
|
+
this.hudRoot = hud;
|
|
301
|
+
}
|
|
302
|
+
this.hudRoot.innerHTML = hudMarkup(this.data.hud);
|
|
303
|
+
}
|
|
304
|
+
this.headingChip = this.hudRoot?.querySelector('#chip-heading') ?? null;
|
|
305
|
+
this.altChip = this.hudRoot?.querySelector('#chip-alt') ?? null;
|
|
306
|
+
this.speedChip = this.hudRoot?.querySelector('#chip-speed') ?? null;
|
|
272
307
|
if (this.decor.arrowEl) {
|
|
273
308
|
this.decor.arrowEl.style.display = this.data.hud.heading ? '' : 'none';
|
|
274
309
|
}
|
|
275
310
|
}
|
|
276
|
-
updateTransform(i
|
|
311
|
+
updateTransform(i) {
|
|
277
312
|
const { data, layout, decor, mapEl } = this;
|
|
278
313
|
let dx = 0;
|
|
279
314
|
let dy = 0;
|
|
@@ -283,12 +318,9 @@ class SceneState {
|
|
|
283
318
|
dy = p.y - layout.c0.y;
|
|
284
319
|
}
|
|
285
320
|
mapEl.style.transform =
|
|
286
|
-
'translate(' + (layout.vw / 2 - layout.bigW / 2 -
|
|
287
|
-
(layout.vh / 2 - layout.bigH / 2 -
|
|
288
|
-
|
|
289
|
-
decor.wrapEl.style.transform = k === 1 ? '' : 'scale(' + 1 / k + ')';
|
|
290
|
-
}
|
|
291
|
-
this.scalelineEl.style.width = Math.round((layout.bestM / layout.mPerPx) * k) + 'px';
|
|
321
|
+
'translate(' + (layout.vw / 2 - layout.bigW / 2 - dx) + 'px,' +
|
|
322
|
+
(layout.vh / 2 - layout.bigH / 2 - dy) + 'px)';
|
|
323
|
+
this.scalelineEl.style.width = Math.round(layout.bestM / layout.mPerPx) + 'px';
|
|
292
324
|
if (data.hud.heading && decor.arrowEl) {
|
|
293
325
|
decor.arrowEl.style.transform = 'rotate(' + data.headingDeg[i] + 'deg)';
|
|
294
326
|
}
|
|
@@ -327,8 +359,7 @@ class SceneState {
|
|
|
327
359
|
this.curIdx = i;
|
|
328
360
|
this.decor.trailCtl.setFrame(i);
|
|
329
361
|
this.decor.drone.setLatLng(this.latlngs[i]);
|
|
330
|
-
|
|
331
|
-
this.updateTransform(i, k);
|
|
362
|
+
this.updateTransform(i);
|
|
332
363
|
this.updateHud(i);
|
|
333
364
|
// Canvas painting is deferred to requestAnimationFrame
|
|
334
365
|
return new Promise((resolve) => {
|
package/dist/renderer/theme.d.ts
CHANGED
package/dist/renderer/theme.js
CHANGED
package/dist/renderer/trail.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { LatLngTuple } from 'leaflet';
|
|
2
2
|
export interface TrailLayer {
|
|
3
3
|
setLatLngs(points: LatLngTuple[]): void;
|
|
4
|
+
/** Drops the last `drop` points, appends `points`, and redraws once. */
|
|
5
|
+
spliceTail(drop: number, points: LatLngTuple[]): void;
|
|
4
6
|
}
|
|
5
7
|
export interface TrailController {
|
|
6
8
|
setFrame(i: number): void;
|
package/dist/renderer/trail.js
CHANGED
|
@@ -16,27 +16,57 @@ export function lastIndexAtOrBefore(trailFrame, i) {
|
|
|
16
16
|
}
|
|
17
17
|
export function createTrailController(trail, frames, layers) {
|
|
18
18
|
let lastFrame = null;
|
|
19
|
+
// Last kept trail index on screen; null until the first full draw.
|
|
20
|
+
let drawnEnd = null;
|
|
21
|
+
let drawnTip = false;
|
|
19
22
|
let drawn = false;
|
|
23
|
+
const keptPoints = (from, to) => {
|
|
24
|
+
const points = [];
|
|
25
|
+
for (let j = from; j <= to; j++)
|
|
26
|
+
points.push([trail.lat[j], trail.lon[j]]);
|
|
27
|
+
return points;
|
|
28
|
+
};
|
|
29
|
+
const drawFull = (end, tip) => {
|
|
30
|
+
const points = keptPoints(0, end);
|
|
31
|
+
if (tip !== null)
|
|
32
|
+
points.push(tip);
|
|
33
|
+
if (points.length === 0 && !drawn)
|
|
34
|
+
return;
|
|
35
|
+
drawnEnd = end;
|
|
36
|
+
drawnTip = tip !== null;
|
|
37
|
+
drawn = points.length > 0;
|
|
38
|
+
for (const layer of layers)
|
|
39
|
+
layer.setLatLngs(points);
|
|
40
|
+
};
|
|
41
|
+
// While the kept prefix only grows, swapping the old tip for the new points
|
|
42
|
+
// yields the same polyline as a full rebuild at O(new points) cost.
|
|
43
|
+
const drawTail = (prevEnd, end, tip) => {
|
|
44
|
+
const drop = drawnTip ? 1 : 0;
|
|
45
|
+
const points = keptPoints(prevEnd + 1, end);
|
|
46
|
+
if (tip !== null)
|
|
47
|
+
points.push(tip);
|
|
48
|
+
drawnEnd = end;
|
|
49
|
+
drawnTip = tip !== null;
|
|
50
|
+
drawn = end >= 0 || drawnTip;
|
|
51
|
+
if (drop === 0 && points.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
for (const layer of layers)
|
|
54
|
+
layer.spliceTail(drop, points);
|
|
55
|
+
};
|
|
20
56
|
return {
|
|
21
57
|
setFrame(i) {
|
|
22
58
|
if (i === lastFrame)
|
|
23
59
|
return;
|
|
60
|
+
lastFrame = i;
|
|
24
61
|
const tip = i >= 0 && i < frames.lat.length ? [frames.lat[i], frames.lon[i]] : null;
|
|
25
62
|
// A kept point at exactly frame i would duplicate the tip's position.
|
|
26
63
|
let end = lastIndexAtOrBefore(trail.frame, i);
|
|
27
64
|
if (tip !== null && trail.frame[end] === i)
|
|
28
65
|
end -= 1;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
points.push(tip);
|
|
34
|
-
lastFrame = i;
|
|
35
|
-
if (points.length === 0 && !drawn)
|
|
36
|
-
return;
|
|
37
|
-
drawn = points.length > 0;
|
|
38
|
-
for (const layer of layers)
|
|
39
|
-
layer.setLatLngs(points);
|
|
66
|
+
if (drawnEnd === null || end < drawnEnd)
|
|
67
|
+
drawFull(end, tip);
|
|
68
|
+
else
|
|
69
|
+
drawTail(drawnEnd, end, tip);
|
|
40
70
|
},
|
|
41
71
|
};
|
|
42
72
|
}
|
package/dist/restyle.js
CHANGED
package/dist/tiles.js
CHANGED
|
@@ -26,6 +26,7 @@ const DOWNLOAD_WORKERS = 2;
|
|
|
26
26
|
const REQUEST_INTERVAL_MS = 500;
|
|
27
27
|
const RETRY_DELAY_MS = 500;
|
|
28
28
|
const FETCH_TIMEOUT_MS = 20000;
|
|
29
|
+
const MAX_TILE_BYTES = 2 * 1024 * 1024;
|
|
29
30
|
// p-queue starts higher priorities first, so 'now' jumps the queued pre-warm.
|
|
30
31
|
const TASK_PRIORITY = { now: 1, background: 0 };
|
|
31
32
|
function tileUrl(style, tile) {
|
|
@@ -42,14 +43,41 @@ function tileUrl(style, tile) {
|
|
|
42
43
|
function canceledError(signal) {
|
|
43
44
|
return new Error('tile download canceled', { cause: signal.reason });
|
|
44
45
|
}
|
|
46
|
+
async function readCappedBody(res) {
|
|
47
|
+
const reader = res.body?.getReader();
|
|
48
|
+
if (!reader)
|
|
49
|
+
return Buffer.alloc(0);
|
|
50
|
+
const chunks = [];
|
|
51
|
+
let size = 0;
|
|
52
|
+
try {
|
|
53
|
+
while (true) {
|
|
54
|
+
const next = await reader.read();
|
|
55
|
+
if (next.done)
|
|
56
|
+
return Buffer.concat(chunks, size);
|
|
57
|
+
size += next.value.byteLength;
|
|
58
|
+
if (size > MAX_TILE_BYTES)
|
|
59
|
+
throw new Error('tile response too large');
|
|
60
|
+
chunks.push(next.value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
void reader.cancel().catch(() => { });
|
|
65
|
+
reader.releaseLock();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
45
68
|
async function fetchBody(url, userAgent, signal) {
|
|
46
69
|
const res = await fetch(url, {
|
|
47
70
|
headers: { 'User-Agent': userAgent },
|
|
71
|
+
redirect: 'error',
|
|
48
72
|
signal: signal
|
|
49
73
|
? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
|
|
50
74
|
: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
51
75
|
});
|
|
52
|
-
|
|
76
|
+
if (!res.ok || Number(res.headers.get('content-length')) > MAX_TILE_BYTES) {
|
|
77
|
+
void res.body?.cancel().catch(() => { });
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return readCappedBody(res);
|
|
53
81
|
}
|
|
54
82
|
async function downloadTile(ctx, url, priority, signal) {
|
|
55
83
|
for (let attempt = 0; attempt < DOWNLOAD_ATTEMPTS; attempt++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path-engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Plan and render flight-path map overlays from drone telemetry.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"author": "Manuel Warum",
|
|
25
25
|
"license": "MIT",
|
|
26
|
-
"homepage": "https://
|
|
26
|
+
"homepage": "https://dronepath.dev",
|
|
27
27
|
"keywords": [
|
|
28
28
|
"dji",
|
|
29
29
|
"drone",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"directory": "packages/engine"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@types/leaflet": "
|
|
44
|
-
"drone-path-core": "
|
|
45
|
-
"leaflet": "
|
|
46
|
-
"p-queue": "
|
|
47
|
-
"playwright-core": "
|
|
48
|
-
"zod": "
|
|
43
|
+
"@types/leaflet": "^1.9.23",
|
|
44
|
+
"drone-path-core": "^2.0.0",
|
|
45
|
+
"leaflet": "^1.9.4",
|
|
46
|
+
"p-queue": "^10.0.0",
|
|
47
|
+
"playwright-core": "^1.65.0",
|
|
48
|
+
"zod": "^4.6.7"
|
|
49
49
|
}
|
|
50
50
|
}
|