drone-path-engine 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +33 -2
- package/THIRD-PARTY-NOTICES.md +11 -0
- package/dist/assets.d.ts +34 -0
- package/dist/assets.js +60 -0
- package/dist/config.d.ts +208 -0
- package/dist/config.js +577 -0
- package/dist/configfile.d.ts +20 -0
- package/dist/configfile.js +82 -0
- package/dist/decimate.d.ts +2 -0
- package/dist/decimate.js +1 -0
- package/dist/ffmpeg-output.d.ts +9 -0
- package/dist/ffmpeg-output.js +40 -0
- package/dist/logging.d.ts +1 -0
- package/dist/logging.js +1 -0
- package/dist/paths.d.ts +4 -0
- package/dist/paths.js +21 -0
- package/dist/pipeline.d.ts +90 -0
- package/dist/pipeline.js +436 -0
- package/dist/plan.d.ts +47 -0
- package/dist/plan.js +113 -0
- package/dist/png.d.ts +1 -0
- package/dist/png.js +32 -0
- package/dist/range.d.ts +19 -0
- package/dist/range.js +50 -0
- package/dist/recordings.d.ts +5 -0
- package/dist/recordings.js +45 -0
- package/dist/render-page.d.ts +35 -0
- package/dist/render-page.js +85 -0
- package/dist/render.d.ts +57 -0
- package/dist/render.js +397 -0
- package/dist/renderer/boot.d.ts +4 -0
- package/dist/renderer/boot.js +28 -0
- package/dist/renderer/dom.d.ts +28 -0
- package/dist/renderer/dom.js +179 -0
- package/dist/renderer/framemath.d.ts +5 -0
- package/dist/renderer/framemath.js +30 -0
- package/dist/renderer/scene.d.ts +38 -0
- package/dist/renderer/scene.js +394 -0
- package/dist/renderer/theme.d.ts +13 -0
- package/dist/renderer/theme.js +82 -0
- package/dist/renderer/tilesources.d.ts +14 -0
- package/dist/renderer/tilesources.js +38 -0
- package/dist/renderer/trail.d.ts +18 -0
- package/dist/renderer/trail.js +42 -0
- package/dist/restyle.d.ts +13 -0
- package/dist/restyle.js +16 -0
- package/dist/serve.d.ts +6 -0
- package/dist/serve.js +27 -0
- package/dist/tilecache.d.ts +12 -0
- package/dist/tilecache.js +21 -0
- package/dist/tiles.d.ts +25 -0
- package/dist/tiles.js +215 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/package.json +37 -4
package/dist/plan.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { MIN_DIMENSION } from './config.js';
|
|
2
|
+
import { project } from 'drone-path-core/geo';
|
|
3
|
+
import { TILE_SOURCES } from './renderer/tilesources.js';
|
|
4
|
+
const MIN_ZOOM = 2;
|
|
5
|
+
const HOVER_ZOOM_FLOOR = 16;
|
|
6
|
+
const MIN_TRACK_SPAN_PX = 80;
|
|
7
|
+
const TILE_SIZE_PX = 256;
|
|
8
|
+
/** The zoom levels the planner renders: the floor and the map style's tile maximum. */
|
|
9
|
+
export function zoomLimits(style) {
|
|
10
|
+
return { min: MIN_ZOOM, max: TILE_SOURCES[style].maxZoom || 19 };
|
|
11
|
+
}
|
|
12
|
+
function fitZoomToTrack(bbox, availW, availH, maxZoom) {
|
|
13
|
+
for (let zoom = maxZoom; zoom >= MIN_ZOOM; zoom--) {
|
|
14
|
+
const northWest = project(bbox.minLon, bbox.maxLat, zoom);
|
|
15
|
+
const southEast = project(bbox.maxLon, bbox.minLat, zoom);
|
|
16
|
+
const fits = southEast.x - northWest.x <= availW &&
|
|
17
|
+
southEast.y - northWest.y <= availH;
|
|
18
|
+
if (fits)
|
|
19
|
+
return zoom;
|
|
20
|
+
}
|
|
21
|
+
return MIN_ZOOM;
|
|
22
|
+
}
|
|
23
|
+
function pullBackTinyTracks(zoom, bbox) {
|
|
24
|
+
while (zoom > HOVER_ZOOM_FLOOR) {
|
|
25
|
+
const northWest = project(bbox.minLon, bbox.maxLat, zoom);
|
|
26
|
+
const southEast = project(bbox.maxLon, bbox.minLat, zoom);
|
|
27
|
+
const spansEnough = southEast.x - northWest.x >= MIN_TRACK_SPAN_PX ||
|
|
28
|
+
southEast.y - northWest.y >= MIN_TRACK_SPAN_PX;
|
|
29
|
+
if (spansEnough)
|
|
30
|
+
break;
|
|
31
|
+
zoom--;
|
|
32
|
+
}
|
|
33
|
+
return zoom;
|
|
34
|
+
}
|
|
35
|
+
function tilesCovering(centerPx, trackSpanPx, zoom, width, height, follow, maxNativeZoom) {
|
|
36
|
+
const tileZoom = maxNativeZoom
|
|
37
|
+
? Math.min(zoom, maxNativeZoom)
|
|
38
|
+
: zoom;
|
|
39
|
+
const scale = 2 ** (tileZoom - zoom);
|
|
40
|
+
const halfW = (width + TILE_SIZE_PX + (follow ? trackSpanPx.x / 2 : 0)) * scale;
|
|
41
|
+
const halfH = (height + TILE_SIZE_PX + (follow ? trackSpanPx.y / 2 : 0)) * scale;
|
|
42
|
+
const maxTileIndex = 2 ** tileZoom - 1;
|
|
43
|
+
const xMin = Math.max(0, Math.floor((centerPx.x * scale - halfW) / TILE_SIZE_PX));
|
|
44
|
+
const xMax = Math.min(maxTileIndex, Math.floor((centerPx.x * scale + halfW) / TILE_SIZE_PX));
|
|
45
|
+
const yMin = Math.max(0, Math.floor((centerPx.y * scale - halfH) / TILE_SIZE_PX));
|
|
46
|
+
const yMax = Math.min(maxTileIndex, Math.floor((centerPx.y * scale + halfH) / TILE_SIZE_PX));
|
|
47
|
+
const tiles = [];
|
|
48
|
+
for (let x = xMin; x <= xMax; x++) {
|
|
49
|
+
for (let y = yMin; y <= yMax; y++)
|
|
50
|
+
tiles.push({ z: tileZoom, x, y });
|
|
51
|
+
}
|
|
52
|
+
return tiles;
|
|
53
|
+
}
|
|
54
|
+
export function computeOverview({ bbox, width, height, maxZoom = 19, zoomOut = 0, follow = false, maxNativeZoom = null, zoomOverride = 0, }) {
|
|
55
|
+
const padX = Math.round(width * 0.08);
|
|
56
|
+
const padY = Math.round(height * 0.08);
|
|
57
|
+
const availW = Math.max(MIN_DIMENSION, width - 2 * padX);
|
|
58
|
+
const availH = Math.max(MIN_DIMENSION, height - 2 * padY);
|
|
59
|
+
let zoom;
|
|
60
|
+
if (zoomOverride > 0) {
|
|
61
|
+
zoom = Math.max(MIN_ZOOM, Math.min(maxZoom, Math.round(zoomOverride)));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
zoom = pullBackTinyTracks(fitZoomToTrack(bbox, availW, availH, maxZoom), bbox);
|
|
65
|
+
zoom = Math.max(MIN_ZOOM, zoom - Math.max(0, Math.floor(zoomOut)));
|
|
66
|
+
}
|
|
67
|
+
const northWest = project(bbox.minLon, bbox.maxLat, zoom);
|
|
68
|
+
const southEast = project(bbox.maxLon, bbox.minLat, zoom);
|
|
69
|
+
const centerPx = {
|
|
70
|
+
x: (northWest.x + southEast.x) / 2,
|
|
71
|
+
y: (northWest.y + southEast.y) / 2,
|
|
72
|
+
};
|
|
73
|
+
const trackSpanPx = {
|
|
74
|
+
x: southEast.x - northWest.x,
|
|
75
|
+
y: southEast.y - northWest.y,
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
centerPx,
|
|
79
|
+
zoom,
|
|
80
|
+
tiles: tilesCovering(centerPx, trackSpanPx, zoom, width, height, follow, maxNativeZoom),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function planView(bbox, width, height, config) {
|
|
84
|
+
const src = TILE_SOURCES[config.style];
|
|
85
|
+
return computeOverview({
|
|
86
|
+
bbox,
|
|
87
|
+
width,
|
|
88
|
+
height,
|
|
89
|
+
maxZoom: zoomLimits(config.style).max,
|
|
90
|
+
maxNativeZoom: src.maxNativeZoom ?? null,
|
|
91
|
+
zoomOut: config.zoomOut,
|
|
92
|
+
zoomOverride: config.zoom,
|
|
93
|
+
follow: config.view === 'follow',
|
|
94
|
+
});
|
|
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
|
+
export const PREPARE_STAGE_ORDER = ['probe', 'telemetry', 'plan'];
|
|
109
|
+
export const INITIAL_PREPARE_PROGRESS = {
|
|
110
|
+
stage: PREPARE_STAGE_ORDER[0],
|
|
111
|
+
done: 0,
|
|
112
|
+
total: PREPARE_STAGE_ORDER.length,
|
|
113
|
+
};
|
package/dist/png.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function solidPng(hexColor: string, size?: number): Buffer;
|
package/dist/png.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import zlib from 'node:zlib';
|
|
2
|
+
function pngChunk(type, data) {
|
|
3
|
+
const len = Buffer.alloc(4);
|
|
4
|
+
len.writeUInt32BE(data.length);
|
|
5
|
+
const body = Buffer.concat([Buffer.from(type, 'ascii'), data]);
|
|
6
|
+
const crc = Buffer.alloc(4);
|
|
7
|
+
crc.writeUInt32BE(zlib.crc32(body));
|
|
8
|
+
return Buffer.concat([len, body, crc]);
|
|
9
|
+
}
|
|
10
|
+
export function solidPng(hexColor, size = 256) {
|
|
11
|
+
const r = Number.parseInt(hexColor.slice(1, 3), 16);
|
|
12
|
+
const g = Number.parseInt(hexColor.slice(3, 5), 16);
|
|
13
|
+
const b = Number.parseInt(hexColor.slice(5, 7), 16);
|
|
14
|
+
const row = Buffer.alloc(1 + size * 3);
|
|
15
|
+
for (let x = 0; x < size; x++) {
|
|
16
|
+
row[1 + x * 3] = r;
|
|
17
|
+
row[2 + x * 3] = g;
|
|
18
|
+
row[3 + x * 3] = b;
|
|
19
|
+
}
|
|
20
|
+
const raw = Buffer.concat(Array.from({ length: size }, () => row));
|
|
21
|
+
const ihdr = Buffer.alloc(13);
|
|
22
|
+
ihdr.writeUInt32BE(size, 0);
|
|
23
|
+
ihdr.writeUInt32BE(size, 4);
|
|
24
|
+
ihdr[8] = 8; // bit depth
|
|
25
|
+
ihdr[9] = 2; // color type RGB
|
|
26
|
+
return Buffer.concat([
|
|
27
|
+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
28
|
+
pngChunk('IHDR', ihdr),
|
|
29
|
+
pngChunk('IDAT', zlib.deflateSync(raw)),
|
|
30
|
+
pngChunk('IEND', Buffer.alloc(0)),
|
|
31
|
+
]);
|
|
32
|
+
}
|
package/dist/range.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface ByteRange {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function parseByteRange(header: string | string[] | undefined, size: number): ByteRange | null | 'unsatisfiable';
|
|
6
|
+
type ByteRangePlan = {
|
|
7
|
+
status: 200;
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
} | {
|
|
10
|
+
status: 206;
|
|
11
|
+
headers: Record<string, string>;
|
|
12
|
+
span: ByteRange;
|
|
13
|
+
} | {
|
|
14
|
+
status: 416;
|
|
15
|
+
headers: Record<string, string>;
|
|
16
|
+
body: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function planByteRange(header: string | string[] | undefined, size: number, mime: string): ByteRangePlan;
|
|
19
|
+
export {};
|
package/dist/range.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function parseByteRange(header, size) {
|
|
2
|
+
if (header === undefined)
|
|
3
|
+
return null;
|
|
4
|
+
const text = Array.isArray(header) ? header[0] : header;
|
|
5
|
+
const m = /^bytes=(\d*)-(\d*)$/.exec(text.trim());
|
|
6
|
+
if (!m)
|
|
7
|
+
return null;
|
|
8
|
+
const from = m[1];
|
|
9
|
+
const to = m[2];
|
|
10
|
+
if (from === '' && to === '')
|
|
11
|
+
return null;
|
|
12
|
+
let start;
|
|
13
|
+
let end;
|
|
14
|
+
if (from === '') {
|
|
15
|
+
const suffix = Number(to);
|
|
16
|
+
if (!Number.isFinite(suffix) || suffix <= 0)
|
|
17
|
+
return 'unsatisfiable';
|
|
18
|
+
start = Math.max(0, size - suffix);
|
|
19
|
+
end = size - 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
start = Number(from);
|
|
23
|
+
end = to === '' ? size - 1 : Number(to);
|
|
24
|
+
if (!Number.isFinite(start) || !Number.isFinite(end))
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (start > end || start >= size)
|
|
28
|
+
return 'unsatisfiable';
|
|
29
|
+
return { start, end: Math.min(end, size - 1) };
|
|
30
|
+
}
|
|
31
|
+
export function planByteRange(header, size, mime) {
|
|
32
|
+
const range = parseByteRange(header, size);
|
|
33
|
+
if (range === 'unsatisfiable') {
|
|
34
|
+
return {
|
|
35
|
+
status: 416,
|
|
36
|
+
headers: { 'Content-Range': `bytes */${size}`, 'Content-Type': 'text/plain' },
|
|
37
|
+
body: 'range not satisfiable',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const headers = {
|
|
41
|
+
'Content-Type': mime,
|
|
42
|
+
'Accept-Ranges': 'bytes',
|
|
43
|
+
'Cache-Control': 'no-store',
|
|
44
|
+
'Content-Length': String(range === null ? size : range.end - range.start + 1),
|
|
45
|
+
};
|
|
46
|
+
if (range === null)
|
|
47
|
+
return { status: 200, headers };
|
|
48
|
+
headers['Content-Range'] = `bytes ${range.start}-${range.end}/${size}`;
|
|
49
|
+
return { status: 206, headers, span: range };
|
|
50
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function isRecordingName(name) {
|
|
4
|
+
return name.toLowerCase().endsWith('.mp4');
|
|
5
|
+
}
|
|
6
|
+
export function videoBaseName(filePath) {
|
|
7
|
+
return path.basename(filePath).replace(/\.[^.]+$/, '');
|
|
8
|
+
}
|
|
9
|
+
function listMp4(dir, recurse) {
|
|
10
|
+
const found = [];
|
|
11
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
12
|
+
const full = path.join(dir, entry.name);
|
|
13
|
+
if (entry.isDirectory()) {
|
|
14
|
+
if (recurse)
|
|
15
|
+
found.push(...listMp4(full, recurse));
|
|
16
|
+
}
|
|
17
|
+
else if (entry.isFile() && isRecordingName(entry.name)) {
|
|
18
|
+
found.push(full);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return found;
|
|
22
|
+
}
|
|
23
|
+
export function collectRecordings(inputs, opts) {
|
|
24
|
+
const files = [];
|
|
25
|
+
for (const item of inputs) {
|
|
26
|
+
const full = path.resolve(item);
|
|
27
|
+
if (!fs.existsSync(full))
|
|
28
|
+
throw new Error(`input not found: ${item}`);
|
|
29
|
+
const st = fs.statSync(full);
|
|
30
|
+
if (st.isDirectory()) {
|
|
31
|
+
files.push(...listMp4(full, opts.recurse));
|
|
32
|
+
}
|
|
33
|
+
else if (isRecordingName(full)) {
|
|
34
|
+
files.push(full);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Error(`not an .mp4 recording: ${full}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const unique = [...new Set(files.map((f) => path.resolve(f)))].sort((a, b) => a.localeCompare(b, 'en'));
|
|
41
|
+
if (unique.length === 0) {
|
|
42
|
+
throw new Error('no .mp4 recordings found in the given input');
|
|
43
|
+
}
|
|
44
|
+
return unique;
|
|
45
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AppearanceSettings, HudLayout, RenderConfig } from './config.js';
|
|
2
|
+
import type { DecimatedTrack } from './decimate.js';
|
|
3
|
+
import type { Bbox, LatLon } from 'drone-path-core/geo';
|
|
4
|
+
import type { IntroOutroFrames, OverviewPlan } from './plan.js';
|
|
5
|
+
import type { SceneData } from './renderer/scene.js';
|
|
6
|
+
import type { FrameChannels } from 'drone-path-core/telemetry-math';
|
|
7
|
+
export interface RenderPageOpts extends FrameChannels, Pick<RenderConfig, 'width' | 'height'>, Pick<AppearanceSettings, 'style' | 'view' | 'zoom' | 'trailColor' | 'hud'> {
|
|
8
|
+
center: LatLon;
|
|
9
|
+
attribution: string;
|
|
10
|
+
decimated: DecimatedTrack;
|
|
11
|
+
introN?: number;
|
|
12
|
+
outroN?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function planPageOpts(opts: {
|
|
15
|
+
bbox: Bbox;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
config: AppearanceSettings;
|
|
19
|
+
source: {
|
|
20
|
+
fps: number;
|
|
21
|
+
frames: number;
|
|
22
|
+
};
|
|
23
|
+
frames: FrameChannels;
|
|
24
|
+
planned?: {
|
|
25
|
+
overview: OverviewPlan;
|
|
26
|
+
introOutro: IntroOutroFrames;
|
|
27
|
+
hud: HudLayout;
|
|
28
|
+
};
|
|
29
|
+
previous?: {
|
|
30
|
+
zoom: number;
|
|
31
|
+
decimated: DecimatedTrack;
|
|
32
|
+
};
|
|
33
|
+
}): RenderPageOpts;
|
|
34
|
+
export declare function buildSceneData(opts: RenderPageOpts, tileBase: string): SceneData;
|
|
35
|
+
export declare function buildPageHtml(opts: RenderPageOpts): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { hasAltitude, resolveHudLayout } from './config.js';
|
|
2
|
+
import { decimateTrack } from './decimate.js';
|
|
3
|
+
import { unproject } from 'drone-path-core/geo';
|
|
4
|
+
import { planIntroOutroFrames, planView } from './plan.js';
|
|
5
|
+
import { TILE_SOURCES } from './renderer/tilesources.js';
|
|
6
|
+
export function planPageOpts(opts) {
|
|
7
|
+
const { bbox, width, height, config, source, frames, planned, previous } = opts;
|
|
8
|
+
const overview = planned?.overview ?? planView(bbox, width, height, config);
|
|
9
|
+
const introOutro = planned?.introOutro ?? planIntroOutroFrames(config, source);
|
|
10
|
+
const hud = planned?.hud ?? resolveHudLayout(config.hud, hasAltitude(frames.alt));
|
|
11
|
+
const decimated = previous && previous.zoom === overview.zoom
|
|
12
|
+
? previous.decimated
|
|
13
|
+
: decimateTrack(frames.lat, frames.lon, overview.zoom);
|
|
14
|
+
return {
|
|
15
|
+
width,
|
|
16
|
+
height,
|
|
17
|
+
style: config.style,
|
|
18
|
+
trailColor: config.trailColor,
|
|
19
|
+
view: config.view,
|
|
20
|
+
center: unproject(overview.centerPx.x, overview.centerPx.y, overview.zoom),
|
|
21
|
+
zoom: overview.zoom,
|
|
22
|
+
attribution: TILE_SOURCES[config.style].attribution,
|
|
23
|
+
introN: introOutro.introN,
|
|
24
|
+
outroN: introOutro.outroN,
|
|
25
|
+
lat: frames.lat,
|
|
26
|
+
lon: frames.lon,
|
|
27
|
+
alt: frames.alt,
|
|
28
|
+
speed: frames.speed,
|
|
29
|
+
headingDeg: frames.headingDeg,
|
|
30
|
+
hud,
|
|
31
|
+
decimated,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function buildSceneData(opts, tileBase) {
|
|
35
|
+
const { width, height, style, trailColor, view, center, zoom, attribution, lat, lon, alt, speed, headingDeg, hud, decimated, introN = 0, outroN = 0, } = opts;
|
|
36
|
+
return {
|
|
37
|
+
style,
|
|
38
|
+
trailColor,
|
|
39
|
+
tileUrl: tileBase + '/' + style + '/{z}/{x}/{y}.png',
|
|
40
|
+
view,
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
43
|
+
zoom,
|
|
44
|
+
center: { lat: center.lat, lon: center.lon },
|
|
45
|
+
attribution,
|
|
46
|
+
introN,
|
|
47
|
+
outroN,
|
|
48
|
+
lat, lon, alt, speed, headingDeg,
|
|
49
|
+
hud,
|
|
50
|
+
trailLat: decimated.lat,
|
|
51
|
+
trailLon: decimated.lon,
|
|
52
|
+
trailFrame: decimated.frame,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function bootScript(dataJson) {
|
|
56
|
+
return `import { bootScene } from '/renderer/boot.js';
|
|
57
|
+
var D = window.__DATA = ${dataJson};
|
|
58
|
+
var scene = bootScene(document.getElementById('scene-host'), D, window.L);
|
|
59
|
+
window.__setFrame = function (i) { return scene.setFrame(i); };
|
|
60
|
+
window.__relayout = function () { scene.relayout(); };
|
|
61
|
+
scene.ready.then(function () { window.__READY = true; });`;
|
|
62
|
+
}
|
|
63
|
+
export function buildPageHtml(opts) {
|
|
64
|
+
const data = buildSceneData(opts, '/tiles');
|
|
65
|
+
// "</" must not appear verbatim: the JSON is inlined into a <script> tag.
|
|
66
|
+
const json = JSON.stringify(data).replace(/</g, '\\u003c');
|
|
67
|
+
return `<!DOCTYPE html>
|
|
68
|
+
<html>
|
|
69
|
+
<head>
|
|
70
|
+
<meta charset="utf-8">
|
|
71
|
+
<title>flight map</title>
|
|
72
|
+
<link rel="stylesheet" href="/leaflet/leaflet.css">
|
|
73
|
+
<style>
|
|
74
|
+
html, body { margin: 0; padding: 0; overflow: hidden; background: ${TILE_SOURCES[opts.style].bg}; }
|
|
75
|
+
</style>
|
|
76
|
+
</head>
|
|
77
|
+
<body>
|
|
78
|
+
<div id="scene-host"></div>
|
|
79
|
+
<script src="/leaflet/leaflet.js"></script>
|
|
80
|
+
<script type="module">
|
|
81
|
+
${bootScript(json)}
|
|
82
|
+
</script>
|
|
83
|
+
</body>
|
|
84
|
+
</html>`;
|
|
85
|
+
}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Writable } from 'node:stream';
|
|
2
|
+
import type { RenderConfig } from './config.js';
|
|
3
|
+
import type { FfmpegToolPaths } from 'drone-path-core/ffmpeg-tools';
|
|
4
|
+
import type { LogFn } from './logging.js';
|
|
5
|
+
interface Encoder {
|
|
6
|
+
stdin: Writable;
|
|
7
|
+
stopped: Promise<string>;
|
|
8
|
+
closed: Promise<number | null>;
|
|
9
|
+
stderrText(): string;
|
|
10
|
+
spawnError(): Error | null;
|
|
11
|
+
kill(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class OrderedFrameStream {
|
|
14
|
+
private readonly encoder;
|
|
15
|
+
private readonly maxPending;
|
|
16
|
+
private readonly pending;
|
|
17
|
+
private nextIndex;
|
|
18
|
+
private flushing;
|
|
19
|
+
private waiters;
|
|
20
|
+
private abortedError;
|
|
21
|
+
private abortReject;
|
|
22
|
+
private readonly abortPromise;
|
|
23
|
+
constructor(encoder: Pick<Encoder, 'stdin' | 'stopped' | 'stderrText'>, maxPending?: number);
|
|
24
|
+
submit(index: number, frame: Buffer): Promise<void>;
|
|
25
|
+
flushReady(): Promise<void>;
|
|
26
|
+
abort(err: unknown): void;
|
|
27
|
+
end(): void;
|
|
28
|
+
private drainReady;
|
|
29
|
+
private waitForSpace;
|
|
30
|
+
private wakeWaiters;
|
|
31
|
+
private rejectWaiters;
|
|
32
|
+
}
|
|
33
|
+
export interface CaptureProgress {
|
|
34
|
+
done: number;
|
|
35
|
+
total: number;
|
|
36
|
+
}
|
|
37
|
+
export interface RenderJobOptions extends Pick<RenderConfig, 'style' | 'tileCache' | 'width' | 'height' | 'workers' | 'capture' | 'codec' | 'quality' | 'preset'> {
|
|
38
|
+
html: string;
|
|
39
|
+
frames: number;
|
|
40
|
+
frameStart?: number;
|
|
41
|
+
fpsStr: string;
|
|
42
|
+
outPath: string;
|
|
43
|
+
log?: LogFn;
|
|
44
|
+
browserPath?: string | null;
|
|
45
|
+
tools: FfmpegToolPaths;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
onCapture?: (progress: CaptureProgress) => void;
|
|
48
|
+
}
|
|
49
|
+
interface RenderProfile {
|
|
50
|
+
evalMs: number;
|
|
51
|
+
captureMs: number;
|
|
52
|
+
emitMs: number;
|
|
53
|
+
}
|
|
54
|
+
export declare function renderVideo(opts: RenderJobOptions): Promise<{
|
|
55
|
+
profile: RenderProfile;
|
|
56
|
+
}>;
|
|
57
|
+
export {};
|