drone-path 0.0.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +179 -0
- package/LICENSE +21 -0
- package/README.md +83 -6
- package/THIRD-PARTY-NOTICES.md +77 -0
- package/app/main.mjs +496 -0
- package/app/preload.cjs +31 -0
- package/app/update-policy.d.mts +6 -0
- package/app/update-policy.mjs +6 -0
- package/app/update.d.mts +10 -0
- package/app/update.mjs +54 -0
- package/bin/drone-path.mjs +5 -0
- package/dist/appassets.js +44 -0
- package/dist/apppaths.js +28 -0
- package/dist/appsession.js +128 -0
- package/dist/appstate.js +109 -0
- package/dist/assets.js +67 -0
- package/dist/cammeta.js +292 -0
- package/dist/changeset-gate.js +46 -0
- package/dist/cli.js +156 -0
- package/dist/config.js +469 -0
- package/dist/configfile.js +81 -0
- package/dist/decimate.js +94 -0
- package/dist/errors.js +4 -0
- package/dist/exportjob.js +106 -0
- package/dist/ff.js +121 -0
- package/dist/fftools.js +65 -0
- package/dist/geo.js +70 -0
- package/dist/inputs.js +59 -0
- package/dist/manual/anchors.js +23 -0
- package/dist/manual/build.js +78 -0
- package/dist/manual/cliref.js +36 -0
- package/dist/manual/links.js +76 -0
- package/dist/manual/markdown.js +101 -0
- package/dist/manual/model.js +4 -0
- package/dist/manual/module.js +8 -0
- package/dist/manual/nav.js +13 -0
- package/dist/manual/reference.js +26 -0
- package/dist/page.js +108 -0
- package/dist/paths.js +28 -0
- package/dist/plan.js +119 -0
- package/dist/png.js +52 -0
- package/dist/proto.js +102 -0
- package/dist/range.js +58 -0
- package/dist/render.js +408 -0
- package/dist/renderer/boot.js +7 -0
- package/dist/renderer/dom.js +132 -0
- package/dist/renderer/framemath.js +34 -0
- package/dist/renderer/leaflet.js +5 -0
- package/dist/renderer/scene.js +358 -0
- package/dist/renderer/theme.js +34 -0
- package/dist/renderer/tilesources.js +34 -0
- package/dist/renderer/trail.js +53 -0
- package/dist/restyle.js +24 -0
- package/dist/run.js +446 -0
- package/dist/serve.js +70 -0
- package/dist/srt.js +76 -0
- package/dist/summary.js +22 -0
- package/dist/telemetry-math.js +302 -0
- package/dist/telemetry.js +38 -0
- package/dist/tilecache.js +26 -0
- package/dist/tiles.js +241 -0
- package/dist/tracing.js +208 -0
- package/dist/version.js +3 -0
- package/package.json +93 -7
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The manual build: reads docs/user/*.md and docs/images, validates the
|
|
2
|
+
// corpus, then emits the typed UI module and the bundled images. Imperative
|
|
3
|
+
// shell over the pure compiler; paths are injectable so tests run it against
|
|
4
|
+
// a temporary corpus.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { compileMarkdown } from './markdown.js';
|
|
9
|
+
import { bundleModuleSource } from './module.js';
|
|
10
|
+
import { navFromIndex } from './nav.js';
|
|
11
|
+
import { pageSlugOf, sourceNameOf, validateCorpus } from './links.js';
|
|
12
|
+
/** The repository's real paths, resolved from a built or source tree. */
|
|
13
|
+
export function defaultManualPaths(root) {
|
|
14
|
+
return {
|
|
15
|
+
userDir: path.join(root, 'docs', 'user'),
|
|
16
|
+
imagesDir: path.join(root, 'docs', 'images'),
|
|
17
|
+
moduleFile: path.join(root, 'ui', 'lib', 'manual', 'generated', 'manual.ts'),
|
|
18
|
+
assetDir: path.join(root, 'ui', 'public', 'manual', 'images'),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function buildManual(paths) {
|
|
22
|
+
const files = fs
|
|
23
|
+
.readdirSync(paths.userDir)
|
|
24
|
+
.filter((file) => file.endsWith('.md'))
|
|
25
|
+
.sort();
|
|
26
|
+
const compiled = files.map((file) => {
|
|
27
|
+
const source = fs.readFileSync(path.join(paths.userDir, file), 'utf8');
|
|
28
|
+
return compileMarkdown(source, pageSlugOf(file));
|
|
29
|
+
});
|
|
30
|
+
const issues = [];
|
|
31
|
+
for (const { slug, page } of compiled) {
|
|
32
|
+
if (page.title === '') {
|
|
33
|
+
issues.push(`docs/user/${sourceNameOf(slug)} needs a level-1 "# " heading as its title`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const index = compiled.find((c) => c.slug === 'index');
|
|
37
|
+
if (!index)
|
|
38
|
+
issues.push('docs/user/README.md is missing; it is the manual index');
|
|
39
|
+
const imageFiles = new Set(fs.existsSync(paths.imagesDir) ? fs.readdirSync(paths.imagesDir) : []);
|
|
40
|
+
for (const issue of validateCorpus(compiled, imageFiles)) {
|
|
41
|
+
issues.push(`${issue.file}: ${issue.message}`);
|
|
42
|
+
}
|
|
43
|
+
if (issues.length > 0) {
|
|
44
|
+
throw new Error(`manual corpus has ${issues.length} issue(s):\n${issues.map((i) => ` - ${i}`).join('\n')}`);
|
|
45
|
+
}
|
|
46
|
+
// The nav comes from the index; pages sort by slug so the bundle is stable.
|
|
47
|
+
const bundle = {
|
|
48
|
+
nav: index ? navFromIndex(index) : [],
|
|
49
|
+
pages: {},
|
|
50
|
+
};
|
|
51
|
+
for (const entry of [...compiled].sort((a, b) => (a.slug < b.slug ? -1 : 1))) {
|
|
52
|
+
bundle.pages[entry.slug] = entry.page;
|
|
53
|
+
}
|
|
54
|
+
fs.mkdirSync(path.dirname(paths.moduleFile), { recursive: true });
|
|
55
|
+
fs.writeFileSync(paths.moduleFile, bundleModuleSource(bundle));
|
|
56
|
+
const referenced = [
|
|
57
|
+
...new Set(compiled.flatMap((c) => c.refs.images.map((image) => image.file))),
|
|
58
|
+
].sort();
|
|
59
|
+
fs.mkdirSync(paths.assetDir, { recursive: true });
|
|
60
|
+
for (const file of referenced) {
|
|
61
|
+
fs.copyFileSync(path.join(paths.imagesDir, file), path.join(paths.assetDir, file));
|
|
62
|
+
}
|
|
63
|
+
return { pages: compiled.length, images: referenced };
|
|
64
|
+
}
|
|
65
|
+
function main() {
|
|
66
|
+
try {
|
|
67
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
68
|
+
const result = buildManual(defaultManualPaths(root));
|
|
69
|
+
process.stderr.write(`[drone-path] manual: ${result.pages} page(s), ${result.images.length} image(s)\n`);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
process.stderr.write(`[drone-path] ERROR: ${e.message}\n`);
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
77
|
+
main();
|
|
78
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The generated CLI/config reference: one table over the option vocabulary in
|
|
2
|
+
// src/config.ts, plus the config-file flag. The result is checked in as
|
|
3
|
+
// docs/user/cli-reference.md so GitHub renders it; a unit test compares the
|
|
4
|
+
// checked-in file against this generator so the two cannot drift.
|
|
5
|
+
import { CONFIG_FILE_OPTION, CONFIG_OPTIONS, cliDefaultOf } from '../config.js';
|
|
6
|
+
function defaultCell(key) {
|
|
7
|
+
const value = cliDefaultOf(key);
|
|
8
|
+
if (typeof value === 'boolean')
|
|
9
|
+
return value ? 'on' : 'off';
|
|
10
|
+
return value === '' ? '—' : `\`${value}\``;
|
|
11
|
+
}
|
|
12
|
+
function describe(row) {
|
|
13
|
+
// Angle brackets in help text would read as HTML on GitHub; the entity form
|
|
14
|
+
// renders back to "<" and ">" everywhere.
|
|
15
|
+
const help = row.cli.help.replace(/</g, '<').replace(/>/g, '>');
|
|
16
|
+
return row.cli.choices ? `${help} (choices: ${row.cli.choices.join(', ')})` : help;
|
|
17
|
+
}
|
|
18
|
+
export function generateCliReference() {
|
|
19
|
+
const rows = CONFIG_OPTIONS.map((row) => `| \`${row.key}\` | \`${row.cli.flags}\` | ${defaultCell(row.key)} | ${describe(row)} |`);
|
|
20
|
+
rows.push(`| — | \`${CONFIG_FILE_OPTION.flags}\` | — | ${CONFIG_FILE_OPTION.help} |`);
|
|
21
|
+
return [
|
|
22
|
+
'<!-- Generated from the option vocabulary in src/config.ts by "npm run docs:reference". Do not edit by hand. -->',
|
|
23
|
+
'',
|
|
24
|
+
'# CLI and config reference',
|
|
25
|
+
'',
|
|
26
|
+
'Every `drone-path` option with its config-file key and built-in default.',
|
|
27
|
+
'In a [config file](config-file.md) every key is optional: anything omitted',
|
|
28
|
+
'falls back to the default below. Run `npx drone-path --help` for the same',
|
|
29
|
+
'table in the terminal.',
|
|
30
|
+
'',
|
|
31
|
+
'| Config key | CLI flag | Default | Description |',
|
|
32
|
+
'|---|---|---|---|',
|
|
33
|
+
...rows,
|
|
34
|
+
'',
|
|
35
|
+
].join('\n');
|
|
36
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Manual reference rules: what an internal link or image may point at, and
|
|
2
|
+
// the pure validation that keeps the checked-in corpus consistent. The
|
|
3
|
+
// compiler rewrites what parses here; validation then proves every reference
|
|
4
|
+
// resolves inside the corpus.
|
|
5
|
+
const SCHEME_RX = /^[a-z][a-z0-9+.-]*:/i;
|
|
6
|
+
/** README.md is the index page "index"; foo.md is "foo". */
|
|
7
|
+
export function pageSlugOf(file) {
|
|
8
|
+
const base = file.split('/').pop() ?? file;
|
|
9
|
+
return base === 'README.md' ? 'index' : base.replace(/\.md$/, '');
|
|
10
|
+
}
|
|
11
|
+
/** True for links that leave the manual (web, mail). */
|
|
12
|
+
export function isExternalTarget(raw) {
|
|
13
|
+
return SCHEME_RX.test(raw);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parses an internal Markdown link target: "foo.md", "foo.md#bar", "#bar"
|
|
17
|
+
* (same page). Anything else returns null and counts as unknown.
|
|
18
|
+
*/
|
|
19
|
+
export function parsePageLink(raw, currentSlug) {
|
|
20
|
+
const [path, hash, ...rest] = raw.split('#');
|
|
21
|
+
if (rest.length > 0)
|
|
22
|
+
return null;
|
|
23
|
+
const anchor = hash === undefined || hash === '' ? null : hash;
|
|
24
|
+
if (path === '')
|
|
25
|
+
return anchor === null ? null : { slug: currentSlug, anchor };
|
|
26
|
+
const clean = path.startsWith('./') ? path.slice(2) : path;
|
|
27
|
+
if (!clean.endsWith('.md') || clean.includes('/'))
|
|
28
|
+
return null;
|
|
29
|
+
return { slug: pageSlugOf(clean), anchor };
|
|
30
|
+
}
|
|
31
|
+
/** Parses an image target: "../images/foo.jpg" becomes "foo.jpg". */
|
|
32
|
+
export function parseImageRef(raw) {
|
|
33
|
+
const match = /^\.\.\/images\/([^/?#]+)$/.exec(raw);
|
|
34
|
+
return match ? (match[1] ?? null) : null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Validates every reference of every compiled page against the corpus:
|
|
38
|
+
* internal links resolve to a page, anchors to a heading in that page, images
|
|
39
|
+
* to a file in `imageFiles`. Unknown targets are rejected outright.
|
|
40
|
+
*/
|
|
41
|
+
export function validateCorpus(pages, imageFiles) {
|
|
42
|
+
const bySlug = new Map(pages.map((p) => [p.slug, p]));
|
|
43
|
+
const issues = [];
|
|
44
|
+
for (const { slug, refs } of pages) {
|
|
45
|
+
const file = `docs/user/${sourceNameOf(slug)}`;
|
|
46
|
+
for (const raw of refs.unknown) {
|
|
47
|
+
issues.push({
|
|
48
|
+
file,
|
|
49
|
+
message: `link "${raw}" is neither a .md page link nor a web link; link pages as "other.md" or "other.md#anchor", and mention plain file paths in backticks`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
for (const link of refs.links) {
|
|
53
|
+
const target = bySlug.get(link.slug);
|
|
54
|
+
if (!target) {
|
|
55
|
+
issues.push({ file, message: `link "${link.raw}" points at missing page "${link.slug}.md"` });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (link.anchor !== null && !target.page.headings.some((h) => h.id === link.anchor)) {
|
|
59
|
+
issues.push({
|
|
60
|
+
file,
|
|
61
|
+
message: `link "${link.raw}" points at missing anchor "#${link.anchor}" in "${sourceNameOf(link.slug)}"`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const image of refs.images) {
|
|
66
|
+
if (!imageFiles.has(image.file)) {
|
|
67
|
+
issues.push({ file, message: `image "${image.raw}" points at missing file "docs/images/${image.file}"` });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return issues;
|
|
72
|
+
}
|
|
73
|
+
/** The Markdown file name a slug was compiled from. */
|
|
74
|
+
export function sourceNameOf(slug) {
|
|
75
|
+
return slug === 'index' ? 'README.md' : `${slug}.md`;
|
|
76
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// The one Markdown adapter: GFM in, sanitized HTML plus structured references
|
|
2
|
+
// out. Raw HTML is escaped so the manual stays plain GitHub Flavored Markdown,
|
|
3
|
+
// internal links become data-attribute navigations the help overlay routes,
|
|
4
|
+
// and images point at bundled assets. Everything here is pure: one source
|
|
5
|
+
// string in, one page model out.
|
|
6
|
+
import { Marked } from 'marked';
|
|
7
|
+
import { createSlugger } from './anchors.js';
|
|
8
|
+
import { isExternalTarget, parseImageRef, parsePageLink } from './links.js';
|
|
9
|
+
function escapeHtml(value) {
|
|
10
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
11
|
+
}
|
|
12
|
+
function escapeAttr(value) {
|
|
13
|
+
return escapeHtml(value).replace(/"/g, '"');
|
|
14
|
+
}
|
|
15
|
+
/** The readable text of inline tokens, for titles, slugs and link labels. */
|
|
16
|
+
function inlineText(tokens) {
|
|
17
|
+
if (!tokens)
|
|
18
|
+
return '';
|
|
19
|
+
let out = '';
|
|
20
|
+
for (const token of tokens) {
|
|
21
|
+
switch (token.type) {
|
|
22
|
+
case 'text':
|
|
23
|
+
case 'escape':
|
|
24
|
+
case 'codespan':
|
|
25
|
+
out += token.text;
|
|
26
|
+
break;
|
|
27
|
+
case 'image':
|
|
28
|
+
out += token.text;
|
|
29
|
+
break;
|
|
30
|
+
case 'br':
|
|
31
|
+
out += ' ';
|
|
32
|
+
break;
|
|
33
|
+
case 'html':
|
|
34
|
+
case 'tag':
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
if ('tokens' in token && token.tokens)
|
|
38
|
+
out += inlineText(token.tokens);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function titleAttr(title) {
|
|
44
|
+
return title ? ` title="${escapeAttr(title)}"` : '';
|
|
45
|
+
}
|
|
46
|
+
export function compileMarkdown(source, slug) {
|
|
47
|
+
const slugger = createSlugger();
|
|
48
|
+
const headings = [];
|
|
49
|
+
const links = [];
|
|
50
|
+
const images = [];
|
|
51
|
+
const unknown = [];
|
|
52
|
+
const md = new Marked({ gfm: true, breaks: false });
|
|
53
|
+
md.use({
|
|
54
|
+
renderer: {
|
|
55
|
+
heading({ tokens, depth }) {
|
|
56
|
+
const text = inlineText(tokens);
|
|
57
|
+
const id = slugger(text);
|
|
58
|
+
headings.push({ id, text, level: depth });
|
|
59
|
+
return `<h${depth} id="${escapeAttr(id)}">${this.parser.parseInline(tokens)}</h${depth}>\n`;
|
|
60
|
+
},
|
|
61
|
+
link({ href, title, tokens }) {
|
|
62
|
+
const inner = this.parser.parseInline(tokens);
|
|
63
|
+
const label = inlineText(tokens);
|
|
64
|
+
if (isExternalTarget(href)) {
|
|
65
|
+
return `<a href="${escapeAttr(href)}"${titleAttr(title)} target="_blank" rel="noopener noreferrer">${inner}</a>`;
|
|
66
|
+
}
|
|
67
|
+
const target = parsePageLink(href, slug);
|
|
68
|
+
if (!target) {
|
|
69
|
+
unknown.push(href);
|
|
70
|
+
return `<a href="${escapeAttr(href)}"${titleAttr(title)}>${inner}</a>`;
|
|
71
|
+
}
|
|
72
|
+
links.push({ raw: href, label, slug: target.slug, anchor: target.anchor });
|
|
73
|
+
const anchor = target.anchor === null ? '' : ` data-manual-anchor="${escapeAttr(target.anchor)}"`;
|
|
74
|
+
return `<a href="#manual/${escapeAttr(target.slug)}"${anchor} data-manual-slug="${escapeAttr(target.slug)}"${titleAttr(title)}>${inner}</a>`;
|
|
75
|
+
},
|
|
76
|
+
image({ href, title, text }) {
|
|
77
|
+
const file = parseImageRef(href);
|
|
78
|
+
if (!file) {
|
|
79
|
+
unknown.push(href);
|
|
80
|
+
return `<img src="${escapeAttr(href)}" alt="${escapeAttr(text)}"${titleAttr(title)}>`;
|
|
81
|
+
}
|
|
82
|
+
images.push({ raw: href, file });
|
|
83
|
+
return `<img src="/manual/images/${escapeAttr(file)}" alt="${escapeAttr(text)}"${titleAttr(title)}>`;
|
|
84
|
+
},
|
|
85
|
+
html({ text }) {
|
|
86
|
+
// Comments disappear like on GitHub; any other raw HTML is escaped so
|
|
87
|
+
// it shows as text instead of markup.
|
|
88
|
+
return /^<!--[\s\S]*-->$/.test(text) ? '' : escapeHtml(text);
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
// parser(lexer(...)) instead of parse(): the instance is synchronous, and
|
|
93
|
+
// only the two-step form types the output as a plain string.
|
|
94
|
+
const html = md.parser(md.lexer(source));
|
|
95
|
+
const title = headings.find((h) => h.level === 1)?.text ?? '';
|
|
96
|
+
return {
|
|
97
|
+
slug,
|
|
98
|
+
page: { slug, title, headings, html },
|
|
99
|
+
refs: { links, images, unknown },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Serialization of the manual bundle into the typed module the UI bundles.
|
|
2
|
+
// The output is deterministic (stable JSON, fixed header) so regeneration is
|
|
3
|
+
// idempotent and a drift check can byte-compare.
|
|
4
|
+
export function bundleModuleSource(bundle) {
|
|
5
|
+
const header = '// Generated by src/manual/build.ts from docs/user/*.md. Do not edit.\n' +
|
|
6
|
+
"import type { ManualBundle } from '../../../../src/manual/model.js';\n\n";
|
|
7
|
+
return `${header}export const MANUAL: ManualBundle = ${JSON.stringify(bundle, null, 2)};\n`;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Navigation derivation: the manual's nav is the ordered link list of the
|
|
2
|
+
// index page (docs/user/README.md), with the index itself as the first entry.
|
|
3
|
+
export function navFromIndex(index) {
|
|
4
|
+
const nav = [{ slug: index.slug, label: index.page.title }];
|
|
5
|
+
const seen = new Set([index.slug]);
|
|
6
|
+
for (const link of index.refs.links) {
|
|
7
|
+
if (seen.has(link.slug))
|
|
8
|
+
continue;
|
|
9
|
+
seen.add(link.slug);
|
|
10
|
+
nav.push({ slug: link.slug, label: link.label });
|
|
11
|
+
}
|
|
12
|
+
return nav;
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Writes the checked-in CLI/config reference from the option vocabulary.
|
|
2
|
+
// Run "npm run docs:reference" after changing src/config.ts; a unit test
|
|
3
|
+
// fails when the checked-in file no longer matches the generator.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { generateCliReference } from './cliref.js';
|
|
8
|
+
export function writeReference(file) {
|
|
9
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
10
|
+
fs.writeFileSync(file, generateCliReference());
|
|
11
|
+
}
|
|
12
|
+
function main() {
|
|
13
|
+
try {
|
|
14
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
15
|
+
const file = path.join(root, 'docs', 'user', 'cli-reference.md');
|
|
16
|
+
writeReference(file);
|
|
17
|
+
process.stderr.write(`[drone-path] manual: wrote ${path.relative(root, file)}\n`);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
process.stderr.write(`[drone-path] ERROR: ${e.message}\n`);
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
25
|
+
main();
|
|
26
|
+
}
|
package/dist/page.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// The generated headless page receives all telemetry inline (no fetch) and
|
|
2
|
+
// exposes window.__setFrame(i) for per-frame marker/trail updates; it resolves
|
|
3
|
+
// after the canvas has painted so screenshots are frame-exact. The map scene
|
|
4
|
+
// itself lives in src/renderer/ - one shared implementation with the app's
|
|
5
|
+
// React map island.
|
|
6
|
+
//
|
|
7
|
+
// Views:
|
|
8
|
+
// overview - static map fitted to the whole track (trail grows with time)
|
|
9
|
+
// follow - drone marker stays in the frame center and the map slides under
|
|
10
|
+
// it (all tiles are loaded once up-front; the per-frame move is a
|
|
11
|
+
// pure CSS transform, so no tile loads happen mid-render)
|
|
12
|
+
import { hasAltitude, resolveHudSpec } from './config.js';
|
|
13
|
+
import { decimateTrack } from './decimate.js';
|
|
14
|
+
import { unproject } from './geo.js';
|
|
15
|
+
import { planIntroOutroFrames, planView } from './plan.js';
|
|
16
|
+
import { TILE_SOURCES } from './renderer/tilesources.js';
|
|
17
|
+
// The one settings + telemetry -> page mapping. The pipeline's recording
|
|
18
|
+
// mapping and the app's live restyle both plan through here, so a preview and
|
|
19
|
+
// an export from the same settings agree frame for frame. The bbox must be
|
|
20
|
+
// the telemetry's fix bbox (what the tile prefetch warms), never the smaller
|
|
21
|
+
// frame-sample bbox.
|
|
22
|
+
export function planPageOpts(opts) {
|
|
23
|
+
const { bbox, width, height, config, source, frames, planned, previous } = opts;
|
|
24
|
+
const overview = planned?.overview ?? planView(bbox, width, height, config);
|
|
25
|
+
const introOutro = planned?.introOutro ?? planIntroOutroFrames(config, source);
|
|
26
|
+
const hud = planned?.hud ?? resolveHudSpec(config.hud, hasAltitude(frames.alt));
|
|
27
|
+
// Decimation depends only on the track and the working zoom, so an
|
|
28
|
+
// unchanged zoom keeps the identical arrays and consumers can tell that no
|
|
29
|
+
// trail work is needed.
|
|
30
|
+
const decimated = previous && previous.zoom === overview.zoom
|
|
31
|
+
? previous.decimated
|
|
32
|
+
: decimateTrack(frames.lat, frames.lon, overview.zoom);
|
|
33
|
+
return {
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
style: config.style,
|
|
37
|
+
view: config.view,
|
|
38
|
+
center: unproject(overview.centerPx.x, overview.centerPx.y, overview.zoom),
|
|
39
|
+
zoom: overview.zoom,
|
|
40
|
+
attribution: TILE_SOURCES[config.style].attribution,
|
|
41
|
+
introN: introOutro.introN,
|
|
42
|
+
outroN: introOutro.outroN,
|
|
43
|
+
lat: frames.lat,
|
|
44
|
+
lon: frames.lon,
|
|
45
|
+
alt: frames.alt,
|
|
46
|
+
speed: frames.speed,
|
|
47
|
+
headingDeg: frames.headingDeg,
|
|
48
|
+
hud,
|
|
49
|
+
decimated,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// The scene data both consumers drive: the generated page inlines it as
|
|
53
|
+
// window.__DATA, the app delivers it as the session payload. Tile URLs are
|
|
54
|
+
// rooted at the consumer's serving base ("/tiles" or "app://bundle/tiles").
|
|
55
|
+
export function buildSceneData(opts, tileBase) {
|
|
56
|
+
const { width, height, style, view, center, zoom, attribution, lat, lon, alt, speed, headingDeg, hud, decimated, introN = 0, outroN = 0, } = opts;
|
|
57
|
+
return {
|
|
58
|
+
style,
|
|
59
|
+
tileUrl: tileBase + '/' + style + '/{z}/{x}/{y}.png',
|
|
60
|
+
view,
|
|
61
|
+
width,
|
|
62
|
+
height,
|
|
63
|
+
zoom,
|
|
64
|
+
center: { lat: center.lat, lon: center.lon },
|
|
65
|
+
attribution,
|
|
66
|
+
introN,
|
|
67
|
+
outroN,
|
|
68
|
+
lat, lon, alt, speed, headingDeg,
|
|
69
|
+
hud,
|
|
70
|
+
trailLat: decimated.lat,
|
|
71
|
+
trailLon: decimated.lon,
|
|
72
|
+
trailFrame: decimated.frame,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// The module boot: boots the shared scene and bridges the globals the
|
|
76
|
+
// headless capture uses. Runs after the DOM is parsed (module semantics), so
|
|
77
|
+
// the scene always finds its host element.
|
|
78
|
+
function bootScript(dataJson) {
|
|
79
|
+
return `import { bootScene } from '/renderer/boot.js';
|
|
80
|
+
var D = window.__DATA = ${dataJson};
|
|
81
|
+
var scene = bootScene(document.getElementById('scene-host'), D, window.L);
|
|
82
|
+
window.__setFrame = function (i) { return scene.setFrame(i); };
|
|
83
|
+
window.__relayout = function () { scene.relayout(); };
|
|
84
|
+
scene.ready.then(function () { window.__READY = true; });`;
|
|
85
|
+
}
|
|
86
|
+
export function buildPageHtml(opts) {
|
|
87
|
+
const data = buildSceneData(opts, '/tiles');
|
|
88
|
+
// "</" must not appear verbatim: the JSON is inlined into a <script> tag.
|
|
89
|
+
const json = JSON.stringify(data).replace(/</g, '\\u003c');
|
|
90
|
+
return `<!DOCTYPE html>
|
|
91
|
+
<html>
|
|
92
|
+
<head>
|
|
93
|
+
<meta charset="utf-8">
|
|
94
|
+
<title>flight map</title>
|
|
95
|
+
<link rel="stylesheet" href="/leaflet/leaflet.css">
|
|
96
|
+
<style>
|
|
97
|
+
html, body { margin: 0; padding: 0; overflow: hidden; background: ${TILE_SOURCES[opts.style].bg}; }
|
|
98
|
+
</style>
|
|
99
|
+
</head>
|
|
100
|
+
<body>
|
|
101
|
+
<div id="scene-host"></div>
|
|
102
|
+
<script src="/leaflet/leaflet.js"></script>
|
|
103
|
+
<script type="module">
|
|
104
|
+
${bootScript(json)}
|
|
105
|
+
</script>
|
|
106
|
+
</body>
|
|
107
|
+
</html>`;
|
|
108
|
+
}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Path identity and collision-free output naming have exactly one home.
|
|
2
|
+
// Identity follows the platform's own file-name rules: Windows file names
|
|
3
|
+
// are case-insensitive, POSIX file names are case-sensitive. The same
|
|
4
|
+
// inputs can therefore plan different names per platform, deterministic
|
|
5
|
+
// and idempotent on each. Case-insensitive macOS volumes are treated like
|
|
6
|
+
// POSIX: folding darwin too would merge two genuinely distinct files on
|
|
7
|
+
// case-sensitive volumes, and the desktop matrix is Windows + Linux.
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
// Resolved so separator and `..` spellings of one file share a key;
|
|
10
|
+
// toLowerCase is locale-independent, so the key stays deterministic.
|
|
11
|
+
export function pathKey(p, platform = process.platform) {
|
|
12
|
+
const resolved = platform === 'win32' ? path.win32.resolve(p) : path.posix.resolve(p);
|
|
13
|
+
return platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
14
|
+
}
|
|
15
|
+
export function samePath(a, b, platform = process.platform) {
|
|
16
|
+
return pathKey(a, platform) === pathKey(b, platform);
|
|
17
|
+
}
|
|
18
|
+
// First free name `stem.ext`, `stem-2.ext`, `stem-3.ext`, ... in dir. The
|
|
19
|
+
// caller says what "taken" means (names planned in this run, or files on
|
|
20
|
+
// disk); existing names are never reused or deleted.
|
|
21
|
+
export function uniquePath(dir, stem, ext, isTaken) {
|
|
22
|
+
for (let n = 1;; n++) {
|
|
23
|
+
const name = n === 1 ? `${stem}${ext}` : `${stem}-${n}${ext}`;
|
|
24
|
+
const candidate = path.join(dir, name);
|
|
25
|
+
if (!isTaken(candidate))
|
|
26
|
+
return candidate;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/plan.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Pure planning shared by the headless pipeline and the app UI: which zoom,
|
|
2
|
+
// center and tiles cover a track at a given frame size, and how intro/outro
|
|
3
|
+
// timing maps to frames. No I/O lives here, so the browser bundle can import
|
|
4
|
+
// it; the preview and an export therefore always plan identically.
|
|
5
|
+
import { project } from './geo.js';
|
|
6
|
+
import { TILE_SOURCES } from './renderer/tilesources.js';
|
|
7
|
+
const MIN_ZOOM = 2;
|
|
8
|
+
const HOVER_ZOOM_FLOOR = 16;
|
|
9
|
+
const MIN_TRACK_SPAN_PX = 80; // tiny/hovering tracks stay a useful close-up
|
|
10
|
+
const TILE_SIZE_PX = 256;
|
|
11
|
+
function fitZoomToTrack(bbox, availW, availH, maxZoom) {
|
|
12
|
+
for (let zoom = maxZoom; zoom >= MIN_ZOOM; zoom--) {
|
|
13
|
+
const northWest = project(bbox.minLon, bbox.maxLat, zoom);
|
|
14
|
+
const southEast = project(bbox.maxLon, bbox.minLat, zoom);
|
|
15
|
+
const fits = southEast.x - northWest.x <= availW &&
|
|
16
|
+
southEast.y - northWest.y <= availH;
|
|
17
|
+
if (fits)
|
|
18
|
+
return zoom;
|
|
19
|
+
}
|
|
20
|
+
return MIN_ZOOM;
|
|
21
|
+
}
|
|
22
|
+
// Never zoom a tiny (hovering) track past a useful overview.
|
|
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
|
+
// The map element is 2x the frame (intro/outro zoom-out shows up to 2x the
|
|
36
|
+
// area) and in follow mode it also slides across the track extent. With a
|
|
37
|
+
// native-zoom limit the tiles live one or more levels below the view zoom.
|
|
38
|
+
function tilesCovering(centerPx, trackSpanPx, zoom, width, height, follow, maxNativeZoom) {
|
|
39
|
+
const tileZoom = maxNativeZoom
|
|
40
|
+
? Math.min(zoom, maxNativeZoom)
|
|
41
|
+
: zoom;
|
|
42
|
+
const scale = 2 ** (tileZoom - zoom);
|
|
43
|
+
const halfW = (width + TILE_SIZE_PX + (follow ? trackSpanPx.x / 2 : 0)) * scale;
|
|
44
|
+
const halfH = (height + TILE_SIZE_PX + (follow ? trackSpanPx.y / 2 : 0)) * scale;
|
|
45
|
+
const maxTileIndex = 2 ** tileZoom - 1;
|
|
46
|
+
const xMin = Math.max(0, Math.floor((centerPx.x * scale - halfW) / TILE_SIZE_PX));
|
|
47
|
+
const xMax = Math.min(maxTileIndex, Math.floor((centerPx.x * scale + halfW) / TILE_SIZE_PX));
|
|
48
|
+
const yMin = Math.max(0, Math.floor((centerPx.y * scale - halfH) / TILE_SIZE_PX));
|
|
49
|
+
const yMax = Math.min(maxTileIndex, Math.floor((centerPx.y * scale + halfH) / TILE_SIZE_PX));
|
|
50
|
+
const tiles = [];
|
|
51
|
+
for (let x = xMin; x <= xMax; x++) {
|
|
52
|
+
for (let y = yMin; y <= yMax; y++)
|
|
53
|
+
tiles.push({ z: tileZoom, x, y });
|
|
54
|
+
}
|
|
55
|
+
return tiles;
|
|
56
|
+
}
|
|
57
|
+
// zoomOut adds surroundings context; follow mode slides the map under a
|
|
58
|
+
// centered marker. When the source has a maxNativeZoom below the view zoom,
|
|
59
|
+
// tiles are fetched at the native level (Leaflet scales them).
|
|
60
|
+
export function computeOverview({ bbox, width, height, maxZoom = 19, zoomOut = 0, follow = false, maxNativeZoom = null, zoomOverride = 0, }) {
|
|
61
|
+
const padX = Math.round(width * 0.08);
|
|
62
|
+
const padY = Math.round(height * 0.08);
|
|
63
|
+
const availW = Math.max(64, width - 2 * padX);
|
|
64
|
+
const availH = Math.max(64, height - 2 * padY);
|
|
65
|
+
let zoom;
|
|
66
|
+
if (zoomOverride > 0) {
|
|
67
|
+
zoom = Math.max(MIN_ZOOM, Math.min(maxZoom, Math.round(zoomOverride)));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
zoom = pullBackTinyTracks(fitZoomToTrack(bbox, availW, availH, maxZoom), bbox);
|
|
71
|
+
zoom = Math.max(MIN_ZOOM, zoom - Math.max(0, Math.floor(zoomOut)));
|
|
72
|
+
}
|
|
73
|
+
// Degenerate (hovering) track: show a close-up around the single point.
|
|
74
|
+
const northWest = project(bbox.minLon, bbox.maxLat, zoom);
|
|
75
|
+
const southEast = project(bbox.maxLon, bbox.minLat, zoom);
|
|
76
|
+
const centerPx = {
|
|
77
|
+
x: (northWest.x + southEast.x) / 2,
|
|
78
|
+
y: (northWest.y + southEast.y) / 2,
|
|
79
|
+
};
|
|
80
|
+
const trackSpanPx = {
|
|
81
|
+
x: southEast.x - northWest.x,
|
|
82
|
+
y: southEast.y - northWest.y,
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
centerPx,
|
|
86
|
+
zoom,
|
|
87
|
+
tiles: tilesCovering(centerPx, trackSpanPx, zoom, width, height, follow, maxNativeZoom),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// The one place that turns look settings into view planning: the tile-source
|
|
91
|
+
// constraints (maxZoom, native zoom) are part of the rule, so callers never
|
|
92
|
+
// hand-roll the computeOverview inputs.
|
|
93
|
+
export function planView(bbox, width, height, config) {
|
|
94
|
+
const src = TILE_SOURCES[config.style];
|
|
95
|
+
return computeOverview({
|
|
96
|
+
bbox,
|
|
97
|
+
width,
|
|
98
|
+
height,
|
|
99
|
+
maxZoom: src.maxZoom || 19,
|
|
100
|
+
maxNativeZoom: src.maxNativeZoom ?? null,
|
|
101
|
+
zoomOut: config.zoomOut,
|
|
102
|
+
zoomOverride: config.zoom,
|
|
103
|
+
follow: config.view === 'follow',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Intro/outro zoom timing (frames); clamp for very short clips. The clamp is
|
|
107
|
+
// returned as data so the owning caller can report it.
|
|
108
|
+
export function planIntroOutroFrames(config, source) {
|
|
109
|
+
let introN = Math.max(0, Math.round(config.introSec * source.fps));
|
|
110
|
+
let outroN = Math.max(0, Math.round(config.outroSec * source.fps));
|
|
111
|
+
const budget = Math.max(2, Math.floor(source.frames / 2));
|
|
112
|
+
const clamped = introN + outroN > budget;
|
|
113
|
+
if (clamped) {
|
|
114
|
+
const scale = budget / (introN + outroN);
|
|
115
|
+
introN = Math.floor(introN * scale);
|
|
116
|
+
outroN = Math.floor(outroN * scale);
|
|
117
|
+
}
|
|
118
|
+
return { introN, outroN, clamped };
|
|
119
|
+
}
|
package/dist/png.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// A minimal PNG encoder: just enough (IHDR/IDAT/IEND, 8-bit RGB rows) to
|
|
2
|
+
// emit valid solid-color tiles for the placeholder fallback, with no
|
|
3
|
+
// dependencies beyond zlib.
|
|
4
|
+
import zlib from 'node:zlib';
|
|
5
|
+
const CRC_TABLE = (() => {
|
|
6
|
+
const table = new Int32Array(256);
|
|
7
|
+
for (let n = 0; n < 256; n++) {
|
|
8
|
+
let c = n;
|
|
9
|
+
for (let k = 0; k < 8; k++)
|
|
10
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
11
|
+
table[n] = c;
|
|
12
|
+
}
|
|
13
|
+
return table;
|
|
14
|
+
})();
|
|
15
|
+
function crc32(buf) {
|
|
16
|
+
let crc = 0xffffffff;
|
|
17
|
+
for (let i = 0; i < buf.length; i++) {
|
|
18
|
+
crc = CRC_TABLE[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
|
|
19
|
+
}
|
|
20
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
21
|
+
}
|
|
22
|
+
function pngChunk(type, data) {
|
|
23
|
+
const len = Buffer.alloc(4);
|
|
24
|
+
len.writeUInt32BE(data.length);
|
|
25
|
+
const body = Buffer.concat([Buffer.from(type, 'ascii'), data]);
|
|
26
|
+
const crc = Buffer.alloc(4);
|
|
27
|
+
crc.writeUInt32BE(crc32(body));
|
|
28
|
+
return Buffer.concat([len, body, crc]);
|
|
29
|
+
}
|
|
30
|
+
export function solidPng(hexColor, size = 256) {
|
|
31
|
+
const r = Number.parseInt(hexColor.slice(1, 3), 16);
|
|
32
|
+
const g = Number.parseInt(hexColor.slice(3, 5), 16);
|
|
33
|
+
const b = Number.parseInt(hexColor.slice(5, 7), 16);
|
|
34
|
+
const row = Buffer.alloc(1 + size * 3);
|
|
35
|
+
for (let x = 0; x < size; x++) {
|
|
36
|
+
row[1 + x * 3] = r;
|
|
37
|
+
row[2 + x * 3] = g;
|
|
38
|
+
row[3 + x * 3] = b;
|
|
39
|
+
}
|
|
40
|
+
const raw = Buffer.concat(Array.from({ length: size }, () => row));
|
|
41
|
+
const ihdr = Buffer.alloc(13);
|
|
42
|
+
ihdr.writeUInt32BE(size, 0);
|
|
43
|
+
ihdr.writeUInt32BE(size, 4);
|
|
44
|
+
ihdr[8] = 8; // bit depth
|
|
45
|
+
ihdr[9] = 2; // color type RGB
|
|
46
|
+
return Buffer.concat([
|
|
47
|
+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
48
|
+
pngChunk('IHDR', ihdr),
|
|
49
|
+
pngChunk('IDAT', zlib.deflateSync(raw)),
|
|
50
|
+
pngChunk('IEND', Buffer.alloc(0)),
|
|
51
|
+
]);
|
|
52
|
+
}
|