@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/src/ids.ts ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * FNV-1a 64-bit → OSM positive 63-bit id (ADR-0123 D-3).
3
+ *
4
+ * OSM ids are signed 64-bit; negative means "not yet uploaded" in every
5
+ * editor, so we never emit a sign bit. Collision within a primitive type
6
+ * fails the export — we never silently renumber.
7
+ *
8
+ * Id representation: decimal **string** of a positive 63-bit integer.
9
+ * Never `number` (H3 / OSM ids exceed Number.MAX_SAFE_INTEGER). Internal
10
+ * hashing uses bigint; public surfaces and writers use string.
11
+ */
12
+
13
+ const FNV_OFFSET = 0xcbf29ce484222325n;
14
+ const FNV_PRIME = 0x100000001b3n;
15
+ const MASK64 = 0xffff_ffff_ffff_ffffn;
16
+ /** Drop the sign bit → positive int63. */
17
+ const MASK63 = 0x7fff_ffff_ffff_ffffn;
18
+
19
+ /** Thrown when two different keys hash to the same 63-bit id inside one type. */
20
+ export class OsmIdCollision extends Error {
21
+ readonly id: string;
22
+ readonly keys: readonly [string, string];
23
+
24
+ constructor(id: string, keys: readonly [string, string]) {
25
+ super(`OSM id collision within type: hash=${id} keys=[${keys[0]}, ${keys[1]}] (ADR-0123 D-3)`);
26
+ this.name = "OsmIdCollision";
27
+ this.id = id;
28
+ this.keys = keys;
29
+ }
30
+ }
31
+
32
+ /** Hash an arbitrary UTF-8 key to a positive 63-bit BigInt (≥ 1). */
33
+ export function fnv1a63(key: string): bigint {
34
+ let hash = FNV_OFFSET;
35
+ const bytes = new TextEncoder().encode(key);
36
+ for (const b of bytes) {
37
+ hash ^= BigInt(b);
38
+ hash = (hash * FNV_PRIME) & MASK64;
39
+ }
40
+ let id = hash & MASK63;
41
+ if (id === 0n) id = 1n;
42
+ return id;
43
+ }
44
+
45
+ /** Same as {@link fnv1a63} but returned as a decimal string. */
46
+ export function fnv1a63String(key: string): string {
47
+ return fnv1a63(key).toString(10);
48
+ }
49
+
50
+ export type IdHasher = (key: string) => string;
51
+
52
+ /**
53
+ * Allocate an id for `key` inside one primitive type's namespace.
54
+ * Throws {@link OsmIdCollision} on collision (two different keys → same id).
55
+ */
56
+ export class IdRegistry {
57
+ private readonly byId = new Map<string, string>(); // id → key
58
+ private readonly byKey = new Map<string, string>(); // key → id
59
+ private readonly hash: IdHasher;
60
+
61
+ constructor(hash: IdHasher = fnv1a63String) {
62
+ this.hash = hash;
63
+ }
64
+
65
+ id(key: string): string {
66
+ const existing = this.byKey.get(key);
67
+ if (existing !== undefined) return existing;
68
+ const id = this.hash(key);
69
+ const owner = this.byId.get(id);
70
+ if (owner !== undefined && owner !== key) {
71
+ throw new OsmIdCollision(id, [owner, key]);
72
+ }
73
+ this.byId.set(id, key);
74
+ this.byKey.set(key, id);
75
+ return id;
76
+ }
77
+
78
+ has(key: string): boolean {
79
+ return this.byKey.has(key);
80
+ }
81
+ }
package/src/index.ts ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @spellkave/world-map — pure-TS OSM projection of the place graph (ADR-0123).
3
+ *
4
+ * No DOM. No `node:` imports in this barrel (CLI lives in `cli.ts`).
5
+ */
6
+
7
+ // Coords / projection (D-1)
8
+ export {
9
+ cellCentroidLatLng,
10
+ cellRes10ToHex,
11
+ composeProjection,
12
+ latLngToPlane,
13
+ latLngToRes10Decimal,
14
+ METRES_PER_DEG_LAT,
15
+ type PlacedNode,
16
+ type ProjectionParams,
17
+ type ProjectWorldOpts,
18
+ type ProjectWorldResult,
19
+ placeWorld,
20
+ projectLocalPosition,
21
+ projectSheetPoint,
22
+ projectWorld,
23
+ sheetToLocal,
24
+ type WorldOffset,
25
+ worldOffsetToLatLng,
26
+ worldOffsetToPlane,
27
+ } from "./coords.ts";
28
+ // Export (D-1..D-4)
29
+ export {
30
+ type ExportWorldOpts,
31
+ type ExportWorldResult,
32
+ exportWorld,
33
+ GENERATOR,
34
+ nodeLevelIndex,
35
+ PACKAGE_VERSION,
36
+ } from "./export.ts";
37
+ // Ids (D-3)
38
+ export {
39
+ fnv1a63,
40
+ fnv1a63String,
41
+ type IdHasher,
42
+ IdRegistry,
43
+ OsmIdCollision,
44
+ } from "./ids.ts";
45
+
46
+ // Model
47
+ export type {
48
+ BackdropEntry,
49
+ ExportManifest,
50
+ OsmDocument,
51
+ OsmExport,
52
+ OsmMember,
53
+ OsmMeta,
54
+ OsmNode,
55
+ OsmRelation,
56
+ OsmWay,
57
+ UnplacedGraph,
58
+ } from "./model.ts";
59
+ // POI schema (ADR-0073 / ADR-0130)
60
+ export {
61
+ isPoiNamespace,
62
+ POI_NAMESPACE,
63
+ type PoiMetadataPayload,
64
+ parsePoiMetadata,
65
+ } from "./poi.ts";
66
+ // Rows
67
+ export {
68
+ type EdgeAffordanceRow,
69
+ type EdgeRow,
70
+ type EdgeStateRow,
71
+ type GraphRow,
72
+ type MapLayerRow,
73
+ type MetadataAttachmentRow,
74
+ type NicheDefinitionRow,
75
+ type NodeRow,
76
+ type NodeStateRow,
77
+ type NormalizedRows,
78
+ normalizeWorldOsmInput,
79
+ type SpatialNicheAttachmentRow,
80
+ type SubstrateDef,
81
+ type WorldOsmInput,
82
+ } from "./rows.ts";
83
+ // Tags / class (D-2)
84
+ export {
85
+ buildCoordinateKindMap,
86
+ CORE_SUBSTRATE_KINDS,
87
+ LEVEL_HEIGHT_M,
88
+ levelIndex,
89
+ type SpatialClass,
90
+ spatialClassOf,
91
+ } from "./tags.ts";
92
+ export {
93
+ type GeoJsonFeature,
94
+ type GeoJsonFeatureCollection,
95
+ renderGeoJson,
96
+ renderGeoJsonString,
97
+ } from "./writers/geojson.ts";
98
+ export {
99
+ type OsmJsonDocument,
100
+ type OsmJsonElement,
101
+ renderOsmJson,
102
+ renderOsmJsonString,
103
+ } from "./writers/json.ts";
104
+ // Writers
105
+ export { escapeXml, renderOsmXml, SPELLKAVE_OSM_NS } from "./writers/xml.ts";
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Offline TOML bundle loader for the world-osm CLI.
3
+ *
4
+ * Mirrors the include-merge half of `packages/spellkave-cli/src/bundle.ts`
5
+ * without pulling the CLI package (avoids a heavy dependency for a pure
6
+ * projection tool). Uses smol-toml with `integersAsBigInt: "asNeeded"` so
7
+ * H3 cell ids stay lossless.
8
+ *
9
+ * This module may use `node:fs` — it is CLI-only, not part of the pure barrel.
10
+ */
11
+
12
+ import { readdir, readFile, stat } from "node:fs/promises";
13
+ import { dirname, join, resolve } from "node:path";
14
+ import { parse as parseToml } from "smol-toml";
15
+
16
+ import type { WorldOsmInput } from "./rows.ts";
17
+
18
+ function isRecord(v: unknown): v is Record<string, unknown> {
19
+ return typeof v === "object" && v !== null && !Array.isArray(v);
20
+ }
21
+
22
+ function rowsOf(manifest: Record<string, unknown>, key: string): Record<string, unknown>[] {
23
+ const v = manifest[key];
24
+ if (!Array.isArray(v)) return [];
25
+ return v.filter(isRecord);
26
+ }
27
+
28
+ function mergeDocuments(documents: string[]): Record<string, unknown> {
29
+ const merged: Record<string, unknown> = {};
30
+ for (const toml of documents) {
31
+ if (toml.trim().length === 0) continue;
32
+ let part: Record<string, unknown>;
33
+ try {
34
+ part = parseToml(toml, { integersAsBigInt: "asNeeded" }) as Record<string, unknown>;
35
+ } catch {
36
+ try {
37
+ part = parseToml(toml, { integersAsBigInt: true }) as Record<string, unknown>;
38
+ } catch {
39
+ continue;
40
+ }
41
+ }
42
+ for (const [key, value] of Object.entries(part)) {
43
+ if (Array.isArray(value)) {
44
+ const existing = merged[key];
45
+ merged[key] = Array.isArray(existing) ? [...existing, ...value] : [...value];
46
+ } else if (merged[key] === undefined) {
47
+ merged[key] = value;
48
+ }
49
+ }
50
+ }
51
+ return merged;
52
+ }
53
+
54
+ async function resolveManifestPath(bundleDirOrFile: string): Promise<string> {
55
+ const abs = resolve(bundleDirOrFile);
56
+ const st = await stat(abs);
57
+ if (st.isFile()) return abs;
58
+ const candidates: string[] = [
59
+ join(abs, "adventure.manifest.toml"),
60
+ join(abs, "manifest.toml"),
61
+ join(abs, "..", "adventure.manifest.toml"),
62
+ ];
63
+ try {
64
+ const extras = (await readdir(abs))
65
+ .filter((name) => name.endsWith(".manifest.toml") && name !== "adventure.manifest.toml")
66
+ .sort()
67
+ .map((name) => join(abs, name));
68
+ candidates.push(...extras);
69
+ } catch {
70
+ /* ignore */
71
+ }
72
+ for (const c of candidates) {
73
+ try {
74
+ const s = await stat(c);
75
+ if (s.isFile()) return c;
76
+ } catch {
77
+ /* try next */
78
+ }
79
+ }
80
+ throw new Error(`No manifest.toml / *.manifest.toml under ${abs}`);
81
+ }
82
+
83
+ async function readIncludes(
84
+ manifestPath: string,
85
+ rootToml: string,
86
+ ): Promise<{ bodies: string[]; included: string[] }> {
87
+ const dir = dirname(manifestPath);
88
+ let parsed: Record<string, unknown> = {};
89
+ try {
90
+ parsed = parseToml(rootToml, { integersAsBigInt: "asNeeded" }) as Record<string, unknown>;
91
+ } catch {
92
+ try {
93
+ parsed = parseToml(rootToml, { integersAsBigInt: true }) as Record<string, unknown>;
94
+ } catch {
95
+ /* empty */
96
+ }
97
+ }
98
+ const includes = Array.isArray(parsed.include) ? parsed.include : [];
99
+ const bodies: string[] = [];
100
+ const included: string[] = [];
101
+ for (const entry of includes) {
102
+ if (!isRecord(entry) || typeof entry.path !== "string") continue;
103
+ const p = resolve(dir, entry.path);
104
+ try {
105
+ bodies.push(await readFile(p, "utf8"));
106
+ included.push(entry.path);
107
+ } catch {
108
+ /* missing include skipped */
109
+ }
110
+ }
111
+ return { bodies, included };
112
+ }
113
+
114
+ export interface LoadedBundle {
115
+ rows: WorldOsmInput;
116
+ manifestPath: string;
117
+ includedFiles: string[];
118
+ }
119
+
120
+ /** Load a bundle directory (or manifest path) into plain spatial rows. */
121
+ export async function loadBundle(bundleDirOrFile: string): Promise<LoadedBundle> {
122
+ const manifestPath = await resolveManifestPath(bundleDirOrFile);
123
+ const rootToml = await readFile(manifestPath, "utf8");
124
+ const { bodies, included } = await readIncludes(manifestPath, rootToml);
125
+ const manifest = mergeDocuments([rootToml, ...bodies]);
126
+
127
+ return {
128
+ rows: {
129
+ place_graphs: rowsOf(manifest, "place_graphs"),
130
+ place_nodes: rowsOf(manifest, "place_nodes"),
131
+ place_edges: rowsOf(manifest, "place_edges"),
132
+ map_layers: rowsOf(manifest, "map_layers"),
133
+ substrate_definitions: rowsOf(manifest, "substrate_definitions"),
134
+ bundles: rowsOf(manifest, "bundles"),
135
+ metadata_attachments: rowsOf(manifest, "metadata_attachments"),
136
+ place_edge_affordances: rowsOf(manifest, "place_edge_affordance"),
137
+ spatial_niche_attachments: rowsOf(manifest, "spatial_niche_attachments"),
138
+ niche_definitions: rowsOf(manifest, "niche_definitions"),
139
+ spatial_environment_states: rowsOf(manifest, "spatial_environment_states"),
140
+ },
141
+ manifestPath,
142
+ includedFiles: included,
143
+ };
144
+ }
145
+
146
+ /** Load either a bundle dir/manifest or a pre-serialized rows.json. */
147
+ export async function loadRowsSource(path: string): Promise<LoadedBundle> {
148
+ const abs = resolve(path);
149
+ const st = await stat(abs);
150
+ if (st.isFile() && abs.endsWith(".json")) {
151
+ const raw = JSON.parse(await readFile(abs, "utf8")) as WorldOsmInput;
152
+ return { rows: raw, manifestPath: abs, includedFiles: [] };
153
+ }
154
+ return loadBundle(abs);
155
+ }
package/src/model.ts ADDED
@@ -0,0 +1,106 @@
1
+ /**
2
+ * In-memory OSM document model (ADR-0123 D-3/D-4).
3
+ *
4
+ * **Id representation:** every OSM id is a decimal **string** of a positive
5
+ * 63-bit integer (FNV-1a-64 masked). Never `number` — values exceed
6
+ * Number.MAX_SAFE_INTEGER. Writers emit the string verbatim; consumers that
7
+ * need bigint parse with `BigInt(id)`.
8
+ */
9
+
10
+ export interface OsmMeta {
11
+ /** Decimal string of a positive 63-bit OSM id. */
12
+ id: string;
13
+ version: number;
14
+ changeset: number;
15
+ uid: number;
16
+ user: string;
17
+ visible: boolean;
18
+ timestamp: string;
19
+ }
20
+
21
+ export interface OsmNode extends OsmMeta {
22
+ type: "node";
23
+ lat: number;
24
+ lon: number;
25
+ tags: Record<string, string>;
26
+ }
27
+
28
+ export interface OsmWay extends OsmMeta {
29
+ type: "way";
30
+ /** Ordered node id refs (decimal strings). Closed areas repeat the first ref last. */
31
+ refs: string[];
32
+ tags: Record<string, string>;
33
+ }
34
+
35
+ export interface OsmMember {
36
+ type: "node" | "way" | "relation";
37
+ ref: string;
38
+ role: string;
39
+ }
40
+
41
+ export interface OsmRelation extends OsmMeta {
42
+ type: "relation";
43
+ members: OsmMember[];
44
+ tags: Record<string, string>;
45
+ }
46
+
47
+ export interface OsmDocument {
48
+ generator: string;
49
+ tick: number;
50
+ timestamp: string;
51
+ nodes: OsmNode[];
52
+ ways: OsmWay[];
53
+ relations: OsmRelation[];
54
+ }
55
+
56
+ export interface UnplacedGraph {
57
+ place_graph_id: string;
58
+ reason: string;
59
+ }
60
+
61
+ export interface BackdropEntry {
62
+ id: string;
63
+ graph: string;
64
+ relation_id: string;
65
+ name: string;
66
+ // no description — map_layer has no such column (ADR-0123 G-4)
67
+ url: string;
68
+ asset: { module: string; path: string };
69
+ source: string;
70
+ license: string;
71
+ state: string;
72
+ size_px: [number, number];
73
+ /** MapLibre image source order: TL, TR, BR, BL as [lon, lat]. */
74
+ coordinates: [[number, number], [number, number], [number, number], [number, number]];
75
+ grid_distance_m?: number;
76
+ minzoom?: number;
77
+ maxzoom?: number;
78
+ }
79
+
80
+ export interface ExportManifest {
81
+ generator: string;
82
+ timestamp: string;
83
+ tick: number;
84
+ origin: {
85
+ lat: number;
86
+ lon: number;
87
+ cell_res10_hex: string;
88
+ cell_res10_decimal: string;
89
+ } | null;
90
+ counts: {
91
+ nodes: number;
92
+ ways: number;
93
+ relations: number;
94
+ backdrops: number;
95
+ unplaced_graphs: number;
96
+ };
97
+ unplaced_graphs: UnplacedGraph[];
98
+ /** Human-readable notes (bootstrap fallback, substrate gaps, …). */
99
+ diagnostics: string[];
100
+ }
101
+
102
+ export interface OsmExport {
103
+ doc: OsmDocument;
104
+ backdrops: BackdropEntry[];
105
+ manifest: ExportManifest;
106
+ }
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Resolve authored [[map_layers]] rows to SpatialGraphBackdrop for SVG overlay.
3
+ * Assets stay out-of-repo (ccc3-maps / FVTT_DATA_ROOT); missing files → skip.
4
+ */
5
+ import { execSync } from "node:child_process";
6
+ import { existsSync, readFileSync, statSync } from "node:fs";
7
+ import { dirname, extname, isAbsolute, join } from "node:path";
8
+ import { fileURLToPath, pathToFileURL } from "node:url";
9
+
10
+ import type { SpatialGraphBackdrop } from "../svg/types.ts";
11
+
12
+ function gitSibling(name: string): string | null {
13
+ try {
14
+ const common = execSync("git rev-parse --path-format=absolute --git-common-dir", {
15
+ stdio: ["ignore", "pipe", "ignore"],
16
+ })
17
+ .toString()
18
+ .trim();
19
+ const candidate = join(dirname(common), name);
20
+ return existsSync(candidate) ? candidate : null;
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+
26
+ export function resolveCcc3MapsRoot(env: NodeJS.ProcessEnv = process.env): string | null {
27
+ if (env.CCC3_MAPS_ROOT?.trim()) return env.CCC3_MAPS_ROOT.trim();
28
+ return gitSibling("ccc3-maps");
29
+ }
30
+
31
+ export function resolveFvttDataRoot(env: NodeJS.ProcessEnv = process.env): string | null {
32
+ if (env.FVTT_DATA_ROOT?.trim()) return env.FVTT_DATA_ROOT.trim();
33
+ return gitSibling("foundry-data");
34
+ }
35
+
36
+ /** PNG IHDR width/height without external deps. */
37
+ export function readPngSize(path: string): { width: number; height: number } | null {
38
+ try {
39
+ const fd = readFileSync(path);
40
+ if (fd.length < 24 || fd[0] !== 0x89) return null;
41
+ const width = fd.readUInt32BE(16);
42
+ const height = fd.readUInt32BE(20);
43
+ if (width <= 0 || height <= 0) return null;
44
+ return { width, height };
45
+ } catch {
46
+ return null;
47
+ }
48
+ }
49
+
50
+ export function resolveMapLayerAssetPath(
51
+ row: Record<string, unknown>,
52
+ env: NodeJS.ProcessEnv = process.env,
53
+ ): string | null {
54
+ const assetPath = typeof row.asset_path === "string" ? row.asset_path : "";
55
+ const module = typeof row.asset_module === "string" ? row.asset_module : "";
56
+ if (!assetPath) return null;
57
+ if (isAbsolute(assetPath) && existsSync(assetPath)) return assetPath;
58
+
59
+ const roots: string[] = [];
60
+ if (module === "ccc3-maps" || module === "elven-tower" || module === "") {
61
+ const ccc3 = resolveCcc3MapsRoot(env);
62
+ if (ccc3) roots.push(ccc3);
63
+ }
64
+ const fvtt = resolveFvttDataRoot(env);
65
+ if (fvtt) {
66
+ roots.push(fvtt);
67
+ if (module) roots.push(join(fvtt, module));
68
+ }
69
+
70
+ for (const root of roots) {
71
+ const candidate = join(root, assetPath);
72
+ if (existsSync(candidate) && statSync(candidate).isFile()) return candidate;
73
+ // asset_path sometimes already includes maps/
74
+ const bare = join(root, "maps", assetPath.replace(/^maps\//, ""));
75
+ if (existsSync(bare) && statSync(bare).isFile()) return bare;
76
+ }
77
+ return null;
78
+ }
79
+
80
+ /**
81
+ * resvg does not load `file://` reliably — embed a resolved local backdrop
82
+ * asset as a base64 data URI instead. `null` when the asset can't be read
83
+ * (missing file, permissions) — callers treat that the same as "no backdrop"
84
+ * rather than failing the render. Same idea as
85
+ * `packages/spellkave-srd-cc/src/author/elven-mini/renders.ts`'s own
86
+ * `backdropDataHref` (kept there byte-for-byte, not consolidated, so this
87
+ * addition never risks that file's own churn-guarded renders).
88
+ */
89
+ export function backdropAssetDataHref(backdrop: SpatialGraphBackdrop): string | null {
90
+ const asset = backdrop.asset;
91
+ if (!asset) return null;
92
+ if (asset.startsWith("data:")) return asset;
93
+ try {
94
+ const path = asset.startsWith("file:") ? fileURLToPath(asset) : asset;
95
+ const buf = readFileSync(path);
96
+ const ext = extname(path).toLowerCase();
97
+ const mime = ext === ".png" ? "image/png" : ext === ".webp" ? "image/webp" : "image/jpeg";
98
+ return `data:${mime};base64,${buf.toString("base64")}`;
99
+ } catch {
100
+ return null;
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Build backdrop descriptors from map_layers rows. Only layers whose asset
106
+ * resolves on disk are included (CI-safe when ccc3-maps absent).
107
+ */
108
+ export function mapLayersToBackdrops(
109
+ layers: readonly Record<string, unknown>[],
110
+ env: NodeJS.ProcessEnv = process.env,
111
+ ): { backdrops: SpatialGraphBackdrop[]; resolved: number; skipped: number } {
112
+ const backdrops: SpatialGraphBackdrop[] = [];
113
+ let skipped = 0;
114
+ for (const row of layers) {
115
+ const graphId = typeof row.place_graph_id === "string" ? row.place_graph_id : "";
116
+ if (!graphId) {
117
+ skipped += 1;
118
+ continue;
119
+ }
120
+ const abs = resolveMapLayerAssetPath(row, env);
121
+ if (abs === null) {
122
+ skipped += 1;
123
+ continue;
124
+ }
125
+ const png = readPngSize(abs);
126
+ const gridSize =
127
+ typeof row.grid_size_px === "number" && row.grid_size_px > 0 ? row.grid_size_px : 100;
128
+ const widthPx =
129
+ typeof row.image_width_px === "number" && row.image_width_px > 0
130
+ ? row.image_width_px
131
+ : (png?.width ?? 1000);
132
+ const heightPx =
133
+ typeof row.image_height_px === "number" && row.image_height_px > 0
134
+ ? row.image_height_px
135
+ : (png?.height ?? 1000);
136
+ const widthCells =
137
+ typeof row.local_width_cells === "number" && row.local_width_cells > 0
138
+ ? row.local_width_cells
139
+ : widthPx / gridSize;
140
+ const heightCells =
141
+ typeof row.local_height_cells === "number" && row.local_height_cells > 0
142
+ ? row.local_height_cells
143
+ : heightPx / gridSize;
144
+ const ox = typeof row.image_origin_x === "number" ? row.image_origin_x : 0;
145
+ const oy = typeof row.image_origin_y === "number" ? row.image_origin_y : 0;
146
+ const rot = typeof row.rotation_deg === "number" ? row.rotation_deg : 0;
147
+ const stateRaw = typeof row.state === "string" ? row.state : "template";
148
+ const state =
149
+ stateRaw === "aligned" || stateRaw === "provisional" || stateRaw === "unmatched"
150
+ ? stateRaw
151
+ : "provisional";
152
+
153
+ backdrops.push({
154
+ graph_id: graphId,
155
+ scene: typeof row.display_name === "string" ? row.display_name : graphId,
156
+ module: typeof row.asset_module === "string" ? row.asset_module : "ccc3-maps",
157
+ asset: pathToFileURL(abs).href,
158
+ width_cells: widthCells,
159
+ height_cells: heightCells,
160
+ image_origin_cells: [ox, oy],
161
+ image_bounds_cells: [
162
+ [ox, oy],
163
+ [ox, oy + heightCells],
164
+ [ox + widthCells, oy + heightCells],
165
+ [ox + widthCells, oy],
166
+ ],
167
+ rotation_deg: rot,
168
+ state,
169
+ });
170
+ }
171
+ return { backdrops, resolved: backdrops.length, skipped };
172
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Node-only spatial-graph pieces (`node:fs` / child_process / resvg / timg).
3
+ * Must stay free of `@earendil-works/pi-tui` (optional peer): see `node/terminal.ts`.
4
+ * Browser consumers must use `@spellkave/world-map/svg` only.
5
+ */
6
+
7
+ export { type LoadedBundle, loadBundle, loadRowsSource } from "../load-bundle.ts";
8
+ export {
9
+ backdropAssetDataHref,
10
+ mapLayersToBackdrops,
11
+ readPngSize,
12
+ resolveCcc3MapsRoot,
13
+ resolveFvttDataRoot,
14
+ resolveMapLayerAssetPath,
15
+ } from "./backdrop-resolve.ts";
16
+ export {
17
+ type MapJpegOutputTarget,
18
+ mapLayerFingerprint,
19
+ provenanceHash,
20
+ resolveMapJpegOutput,
21
+ type WriteJpegResult,
22
+ writeJpegWithChurnGuard,
23
+ } from "./jpeg-write.ts";
24
+ export { type RasterizeSvgResult, rasterizeSvgToPng } from "./rasterize.ts";
25
+ // Terminal image-protocol helpers (pi-tui) live in `@spellkave/world-map/node/terminal`
26
+ // — NOT here. This barrel is loaded by the hosted PLAYER MCP gateway
27
+ // (`pnpm deploy --prod`, no devDependencies), where pi-tui is absent (#2468).
28
+ export {
29
+ findTimgBinary,
30
+ isTimgPixelation,
31
+ preferTimgUnicodeBlocks,
32
+ renderPngWithTimg,
33
+ type TimgPixelation,
34
+ timgBytesToLines,
35
+ } from "./timg-backend.ts";
36
+ export {
37
+ attachSpatialGraphImageToToolResult,
38
+ type SpatialToolResultLike,
39
+ } from "./tool-result-image.ts";