@spellkave/world-map 0.0.0-bootstrap

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 ADDED
@@ -0,0 +1,89 @@
1
+ # PolyForm Shield License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/shield/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
12
+
13
+ ## Distribution License
14
+
15
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Notices
18
+
19
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
20
+
21
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
22
+
23
+ ## Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+
27
+ ## Patent License
28
+
29
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
+
31
+ ## Noncompete
32
+
33
+ Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
34
+
35
+ ## Competition
36
+
37
+ Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
38
+
39
+ ## New Products
40
+
41
+ If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
42
+
43
+ ## Discontinued Products
44
+
45
+ You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
46
+
47
+ > Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
48
+
49
+ ## Sales of Business
50
+
51
+ If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
52
+
53
+ ## Fair Use
54
+
55
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
56
+
57
+ ## No Other Rights
58
+
59
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
60
+
61
+ ## Patent Defense
62
+
63
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
64
+
65
+ ## Violations
66
+
67
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
68
+
69
+ ## No Liability
70
+
71
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
76
+
77
+ A **product** can be a good or service, or a combination of them.
78
+
79
+ **You** refers to the individual or entity agreeing to these terms.
80
+
81
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
82
+
83
+ **Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
84
+
85
+ **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
86
+
87
+ **Your licenses** are all the licenses granted to you for the software under these terms.
88
+
89
+ **Use** means anything you do with the software requiring one of your licenses.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # `@spellkave/world-map`
2
+
3
+ One geometry, three outputs — so a new map artefact never means touching two packages.
4
+
5
+ | Subpath | What it is |
6
+ |---|---|
7
+ | `.` | Place-graph → OSM geometry (`coords`, ids, tags, model), `exportWorld`, writers (XML / Overpass JSON / GeoJSON), `normalizeWorldOsmInput` |
8
+ | `./tiles` | MVT layer split, geojson-vt indexes, `encodeMvtTile`, TileJSON, MapLibre style, backdrop URL helpers |
9
+ | `./svg` | Spatial-graph layout + SVG / ASCII / braille / inventory (browser-safe except termdot braille) |
10
+ | `./node` | Node-only raster (no pi-tui): resvg PNG, JPEG write, backdrop file resolve, timg — safe for `pnpm deploy --prod` hosts |
11
+ | `./node/terminal` | Terminal image-protocol helpers (`ensureSpellkaveTerminalImageCapabilities`, `parseImagesModeFlag`, …) via optional peer `@earendil-works/pi-tui` — CLI/TUI only (#2468) |
12
+ | `./cli` / bins | `world-map export …` (bin `world-map`; `world-osm` kept as a one-release alias) |
13
+
14
+ ## What is NOT here
15
+
16
+ **HTTP.** Routing, Bearer auth, CORS, operator cache refresh, asset/font/demo file serving stay in `@spellkave/player-mcp` (`tiles.ts`, `osm-model.ts`). The gateway imports builders from `@spellkave/world-map/tiles` and only transports bytes.
17
+
18
+ ## Consumers
19
+
20
+ - `@spellkave/player-mcp` — OSM API / Overpass / MVT gateway
21
+ - `@spellkave/tool-player` — `spellkave_map` / `spellkave_map_graph` tools
22
+ - `@spellkave/cli` (`sk map-*`) — terminal + file map products
23
+ - `@spellkave/srd-cc` — elven-mini render fixtures
24
+ - `apps/maps` — MapLibre SPA (tiles via gateway; local demo may import export)
25
+
26
+ Import spatial products directly from `@spellkave/world-map/{svg,node}`. Terminal/TUI hosts that need pi-tui capability detection import `@spellkave/world-map/node/terminal` — never pull those helpers through `./node` (hosted PLAYER MCP loads `./node` under prod deploys without pi-tui).
27
+
28
+ ## SVG class hooks
29
+
30
+ A host that inlines the spatial-graph SVG restyles or hides parts by class; it
31
+ does not parse label text.
32
+
33
+ - `text.label` — a place label. Its text node is the plain place name.
34
+ - `tspan.label-floor` — the floor part of that label (`(z=-3)`), a child of
35
+ `text.label`. The separating space stays in the parent's text node, because
36
+ resvg drops a space that leads a `tspan`. The renderer emits the element on
37
+ an `elevation_band` or `metric` slice for a node off the ground floor; a
38
+ floor-panel (`all_floors_offset`) or world (H3) map has none, because the
39
+ panel title already names the floor. The drawn text, `textContent` and the
40
+ PNG/JPG raster still read `Cellar (z=-3)`; a host that says the floor
41
+ elsewhere hides the element (`display: none`). Pinned by
42
+ `src/svg/__tests__/spatial-graph.test.ts`.
43
+
44
+ The markup is written where the SVG is rendered. For `spellkave_map` that is
45
+ the hosted player MCP (`@spellkave/tool-player`), a deployment separate from
46
+ the Play app that inlines the result. Play shows the plain name only once that
47
+ MCP runs a `@spellkave/world-map` with `tspan.label-floor`; against an older
48
+ one the hide rule matches nothing and the card keeps the suffix. Either order
49
+ of rollout is safe, and there is nothing to migrate or roll back: the change
50
+ is additive (same `textContent`, same raster, one more `tspan` in the raw SVG).
51
+
52
+ ## CLI
53
+
54
+ ```bash
55
+ pnpm --filter @spellkave/world-map exec tsx src/cli.ts export <bundle> \
56
+ --xml out.osm --json out.json --backdrops backdrops.json --manifest manifest.json
57
+ # or: just world-map-export <bundle>
58
+ # alias: world-osm / just world-osm-export (one release)
59
+ ```
60
+
61
+ ## Gates
62
+
63
+ ```bash
64
+ pnpm --filter @spellkave/world-map typecheck
65
+ pnpm --filter @spellkave/world-map test
66
+ pnpm --filter @spellkave/world-map test:behaviour # behaviour/*.feature: the real CLI, offline
67
+ ```
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env tsx
2
+ // Thin launcher — run the TypeScript CLI entry. Missing workspace deps surface
3
+ // as an actionable sentence rather than a raw ESM resolution stack.
4
+ try {
5
+ const { runCli } = await import("../src/cli.ts");
6
+ process.exitCode = await runCli(process.argv.slice(2));
7
+ } catch (err) {
8
+ if (err?.code === "ERR_MODULE_NOT_FOUND" && String(err?.message).includes("@spellkave/")) {
9
+ process.stderr.write(
10
+ "world-map: workspace dependency not installed. Run `just bootstrap` (or `pnpm install` at the repo root) once, then retry.\n",
11
+ );
12
+ process.exitCode = 1;
13
+ } else {
14
+ throw err;
15
+ }
16
+ }
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env tsx
2
+ // Compatibility alias for `world-osm` (one release). Prefer `world-map`.
3
+ try {
4
+ const { runCli } = await import("../src/cli.ts");
5
+ process.exitCode = await runCli(process.argv.slice(2));
6
+ } catch (err) {
7
+ if (err?.code === "ERR_MODULE_NOT_FOUND" && String(err?.message).includes("@spellkave/")) {
8
+ process.stderr.write(
9
+ "world-map: workspace dependency not installed. Run `just bootstrap` (or `pnpm install` at the repo root) once, then retry.\n",
10
+ );
11
+ process.exitCode = 1;
12
+ } else {
13
+ throw err;
14
+ }
15
+ }
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@spellkave/world-map",
3
+ "version": "0.0.0-bootstrap",
4
+ "description": "One geometry, three outputs: OSM export, MVT/MapLibre tiles, SVG/ASCII/braille spatial-graph. No HTTP — the gateway keeps routing/auth/CORS/assets.",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "bin": {
9
+ "world-map": "./bin/world-map.js",
10
+ "world-osm": "./bin/world-osm.js"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./src/index.ts",
15
+ "default": "./src/index.ts"
16
+ },
17
+ "./tiles": {
18
+ "types": "./src/tiles/index.ts",
19
+ "default": "./src/tiles/index.ts"
20
+ },
21
+ "./svg": {
22
+ "types": "./src/svg/index.ts",
23
+ "default": "./src/svg/index.ts"
24
+ },
25
+ "./node": {
26
+ "types": "./src/node/index.ts",
27
+ "default": "./src/node/index.ts"
28
+ },
29
+ "./node/terminal": {
30
+ "types": "./src/node/terminal.ts",
31
+ "default": "./src/node/terminal.ts"
32
+ },
33
+ "./cli": {
34
+ "types": "./src/cli.ts",
35
+ "default": "./src/cli.ts"
36
+ }
37
+ },
38
+ "files": [
39
+ "src",
40
+ "bin"
41
+ ],
42
+ "dependencies": {
43
+ "@maplibre/maplibre-gl-style-spec": "26.2.1",
44
+ "@resvg/resvg-js": "^2.6.2",
45
+ "geojson-vt": "4.0.2",
46
+ "h3-js": "^4.5.0",
47
+ "smol-toml": "^1.9.1",
48
+ "termdot": "^0.1.13",
49
+ "tsx": "^4.19.2",
50
+ "vt-pbf": "3.1.3",
51
+ "@spellkave/sdk": "0.0.0-bootstrap"
52
+ },
53
+ "peerDependencies": {
54
+ "@earendil-works/pi-tui": "1.5.2"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "@earendil-works/pi-tui": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "license": "PolyForm-Shield-1.0.0",
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "git+https://github.com/b4mad-technologies/sk-sdk.git",
65
+ "directory": "packages/spellkave-world-map"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public",
69
+ "registry": "https://registry.npmjs.org/"
70
+ }
71
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,204 @@
1
+ /**
2
+ * CLI: `world-map export <bundle-dir|rows.json> --xml … --json … --backdrops … --manifest …`
3
+ * May use node:fs (not part of the pure library barrel).
4
+ */
5
+
6
+ import { mkdir, writeFile } from "node:fs/promises";
7
+ import { dirname, resolve } from "node:path";
8
+
9
+ import { exportWorld } from "./export.ts";
10
+ import { OsmIdCollision } from "./ids.ts";
11
+ import { loadRowsSource } from "./load-bundle.ts";
12
+ import { renderOsmJsonString } from "./writers/json.ts";
13
+ import { renderOsmXml } from "./writers/xml.ts";
14
+
15
+ function usage(): string {
16
+ return `Usage:
17
+ world-map export <bundle-dir|rows.json> [options]
18
+
19
+ Options:
20
+ --xml <path> Write OSM XML 0.6
21
+ --json <path> Write OSM JSON (Overpass shape)
22
+ --backdrops <path> Write backdrops.json sidecar
23
+ --manifest <path> Write export-manifest.json
24
+ --tick <n> World tick (default 0)
25
+ --timestamp <iso> Element timestamp (default now)
26
+ -h, --help Show help
27
+ `;
28
+ }
29
+
30
+ function parseArgs(argv: string[]): {
31
+ cmd: string;
32
+ source?: string;
33
+ xml?: string;
34
+ json?: string;
35
+ backdrops?: string;
36
+ manifest?: string;
37
+ tick: number;
38
+ timestamp?: string;
39
+ help: boolean;
40
+ } {
41
+ const out: ReturnType<typeof parseArgs> = {
42
+ cmd: "",
43
+ tick: 0,
44
+ help: false,
45
+ };
46
+ if (argv.length === 0) {
47
+ out.help = true;
48
+ return out;
49
+ }
50
+ // pnpm run may forward a bare `--` separator; skip it.
51
+ const cleaned = argv[0] === "--" ? argv.slice(1) : argv;
52
+ out.cmd = cleaned[0] ?? "";
53
+ let i = 1;
54
+ if (out.cmd === "export") {
55
+ out.source = cleaned[i++];
56
+ }
57
+ while (i < cleaned.length) {
58
+ const a = cleaned[i]!;
59
+ if (a === "-h" || a === "--help" || a === "help") {
60
+ out.help = true;
61
+ i++;
62
+ continue;
63
+ }
64
+ if (a === "--") {
65
+ i++;
66
+ continue;
67
+ }
68
+ const next = cleaned[i + 1];
69
+ if (a === "--xml" && next) {
70
+ out.xml = next;
71
+ i += 2;
72
+ continue;
73
+ }
74
+ if (a === "--json" && next) {
75
+ out.json = next;
76
+ i += 2;
77
+ continue;
78
+ }
79
+ if (a === "--backdrops" && next) {
80
+ out.backdrops = next;
81
+ i += 2;
82
+ continue;
83
+ }
84
+ if (a === "--manifest" && next) {
85
+ out.manifest = next;
86
+ i += 2;
87
+ continue;
88
+ }
89
+ if (a === "--tick" && next) {
90
+ out.tick = Number(next) || 0;
91
+ i += 2;
92
+ continue;
93
+ }
94
+ if (a === "--timestamp" && next) {
95
+ out.timestamp = next;
96
+ i += 2;
97
+ continue;
98
+ }
99
+ throw new Error(`unknown argument: ${a}`);
100
+ }
101
+ return out;
102
+ }
103
+
104
+ async function ensureParent(path: string): Promise<void> {
105
+ await mkdir(dirname(resolve(path)), { recursive: true });
106
+ }
107
+
108
+ export async function runCli(argv: string[]): Promise<number> {
109
+ let args: ReturnType<typeof parseArgs>;
110
+ try {
111
+ args = parseArgs(argv);
112
+ } catch (err) {
113
+ process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
114
+ process.stderr.write(usage());
115
+ return 2;
116
+ }
117
+
118
+ if (args.help || ["help", "-h", "--help", ""].includes(args.cmd)) {
119
+ process.stdout.write(usage());
120
+ return 0;
121
+ }
122
+
123
+ if (args.cmd !== "export") {
124
+ process.stderr.write(`unknown command: ${args.cmd}\n`);
125
+ process.stderr.write(usage());
126
+ return 2;
127
+ }
128
+
129
+ if (!args.source) {
130
+ process.stderr.write("export requires <bundle-dir|rows.json>\n");
131
+ process.stderr.write(usage());
132
+ return 2;
133
+ }
134
+
135
+ if (!args.xml && !args.json && !args.backdrops && !args.manifest) {
136
+ process.stderr.write(
137
+ "export requires at least one of --xml / --json / --backdrops / --manifest\n",
138
+ );
139
+ return 2;
140
+ }
141
+
142
+ try {
143
+ const loaded = await loadRowsSource(args.source);
144
+ const result = exportWorld(loaded.rows, {
145
+ tick: args.tick,
146
+ timestamp: args.timestamp,
147
+ });
148
+
149
+ if (args.xml) {
150
+ await ensureParent(args.xml);
151
+ await writeFile(args.xml, renderOsmXml(result.doc), "utf8");
152
+ }
153
+ if (args.json) {
154
+ await ensureParent(args.json);
155
+ await writeFile(args.json, renderOsmJsonString(result.doc), "utf8");
156
+ }
157
+ if (args.backdrops) {
158
+ await ensureParent(args.backdrops);
159
+ await writeFile(args.backdrops, JSON.stringify(result.backdrops, null, 2) + "\n", "utf8");
160
+ }
161
+ if (args.manifest) {
162
+ await ensureParent(args.manifest);
163
+ await writeFile(args.manifest, JSON.stringify(result.manifest, null, 2) + "\n", "utf8");
164
+ }
165
+
166
+ const m = result.manifest;
167
+ process.stdout.write(
168
+ JSON.stringify(
169
+ {
170
+ ok: true,
171
+ source: loaded.manifestPath,
172
+ counts: m.counts,
173
+ unplaced_graphs: m.unplaced_graphs.map((u) => u.place_graph_id),
174
+ diagnostics: m.diagnostics,
175
+ },
176
+ null,
177
+ 2,
178
+ ) + "\n",
179
+ );
180
+ return 0;
181
+ } catch (err) {
182
+ if (err instanceof OsmIdCollision) {
183
+ process.stderr.write(`${err.message}\n`);
184
+ return 1;
185
+ }
186
+ process.stderr.write(
187
+ `world-map export failed: ${err instanceof Error ? err.message : String(err)}\n`,
188
+ );
189
+ return 1;
190
+ }
191
+ }
192
+
193
+ // Direct execution via `tsx src/cli.ts`. The bin/ launchers import this module
194
+ // and call runCli themselves, so they must not match here: a match ran every
195
+ // launcher command twice (two summaries on stdout, every file written twice).
196
+ const isDirect =
197
+ typeof process !== "undefined" &&
198
+ process.argv[1] &&
199
+ (process.argv[1].endsWith("/cli.ts") || process.argv[1].endsWith("\\cli.ts"));
200
+
201
+ if (isDirect) {
202
+ const code = await runCli(process.argv.slice(2));
203
+ process.exitCode = code;
204
+ }