@spellkave/world-map 0.0.0-bootstrap → 0.0.0-stage

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/svg/types.ts DELETED
@@ -1,244 +0,0 @@
1
- /** Shared spatial-graph view types (tool-result shaped; not ADR-0029 projection). */
2
-
3
- export interface SpatialGraphNode {
4
- id: string;
5
- label: string;
6
- graphId: string;
7
- x: number;
8
- y: number;
9
- /** Graph-local pose_elevation; 0 when absent. */
10
- elevation: number;
11
- /** True when pose_elevation_present was set on the row. */
12
- elevationPresent: boolean;
13
- substrateId: string | null;
14
- /** H3 res10 hex index when authored (outdoor world compose). */
15
- cellRes10Hex?: string | null;
16
- /** World-map short label (optional). */
17
- shortLabel?: string | null;
18
- /** Outdoor node that portals into an indoor graph. */
19
- portalEntrance?: boolean;
20
- /** Node footprint DIAMETER in graph-local units, derived from the node's
21
- * own authored extent (place_node.extent_shape_id/extent_params_json,
22
- * metre-native HALF-extents — sphere → 2·radius_m, cube → 2·extent_m —
23
- * divided by the graph's metres_per_unit). Absent when the node authors no explicit
24
- * extent (bundle-default extents are NOT resolved here: the tool row set
25
- * carries no mod_bundle rows) — callers fall back to a 1-unit footprint.
26
- * Retained as the maximum planar diameter for compatibility; new drawing
27
- * code should use `extent` so it does not collapse non-uniform shapes. */
28
- extentUnits?: number;
29
- /** Parsed explicit extent geometry. Params stay attached so adding a kernel
30
- * shape is a renderer arm, not a model rewrite. width/height are the planar
31
- * full extents in graph-local units; per-axis params take precedence over
32
- * the legacy uniform scalar when present. */
33
- extent?: SpatialGraphNodeExtent;
34
- /** Draw the mark, suppress the text label (sk-pej D-3). Set on composed
35
- * tactical-grid cells: 100 cells means 100 labels, which collapse into an
36
- * unreadable smear over the backdrop art and say nothing a reader wants —
37
- * "Cell 4,7" is a coordinate, not a place name. The cells stay in the SVG
38
- * as marks with their `data-node-id`; the text inventory summarizes the grid
39
- * and names only occupied or notable cells. */
40
- unlabeled?: boolean;
41
- }
42
-
43
- export interface SpatialGraphNodeExtent {
44
- shapeId: string;
45
- params: Readonly<Record<string, unknown>>;
46
- widthUnits: number;
47
- heightUnits: number;
48
- /** Full authored vertical extent in metres. Unlike x/y this stays metre-native,
49
- * because a 2D sheet has no meaningful screen-space z scale. */
50
- depthMetres: number;
51
- }
52
-
53
- export interface SpatialGraphEdge {
54
- from: string;
55
- to: string;
56
- graphId: string;
57
- }
58
-
59
- export interface SpatialGraphActorCluster {
60
- placeNodeId: string;
61
- count: number;
62
- }
63
-
64
- export interface SpatialGraphMeta {
65
- graphId: string;
66
- /** place_graph.metres_per_unit: one graph unit → metres (ADR-0029). Default 1. */
67
- metresPerUnit: number;
68
- substrateId: string | null;
69
- displayName: string | null;
70
- /** Composition parent (empty = root). */
71
- parentGraphId?: string;
72
- /** Root outdoor H3 anchor (hex), when set. */
73
- originCellRes10Hex?: string | null;
74
- /** Clockwise degrees (ADR-0029). */
75
- bearing?: number;
76
- anchorNodeId?: string | null;
77
- }
78
-
79
- export interface SpatialGraphModel {
80
- nodes: SpatialGraphNode[];
81
- edges: SpatialGraphEdge[];
82
- actorClusters: SpatialGraphActorCluster[];
83
- /** Authored graph rows touched by the drawn nodes (metres_per_unit/bearing source). */
84
- graphs: SpatialGraphMeta[];
85
- root: string | null;
86
- reachable: string[];
87
- unreachable: string[];
88
- /** Floors discovered before slice filtering (sorted ascending). */
89
- floors: number[];
90
- /** Active slice description for inventory/chrome. */
91
- sliceLabel: string;
92
- notableScopes: SpatialGraphNotableScope[];
93
- }
94
-
95
- export interface SpatialGraphNotableScope {
96
- anchorNodeId: string;
97
- nicheId: string;
98
- x: number;
99
- y: number;
100
- extent: SpatialGraphNodeExtent;
101
- }
102
-
103
- export interface SpatialGraphBackdrop {
104
- graph_id: string;
105
- scene: string;
106
- module: string;
107
- asset: string;
108
- width_cells: number;
109
- height_cells: number;
110
- image_origin_cells: [number, number];
111
- image_bounds_cells: [[number, number], [number, number], [number, number], [number, number]];
112
- rotation_deg: number;
113
- state: "aligned" | "provisional" | "unmatched";
114
- }
115
-
116
- export interface SpatialGraphHexFootprint {
117
- hex: string;
118
- ring: Array<{ x: number; y: number }>;
119
- /** CSS class suffix for fill (terrain / ownership prep). */
120
- fillKind?: "root" | "settlement" | "wilderness" | "default";
121
- }
122
-
123
- export interface SpatialGraphLayout {
124
- nodes: SpatialGraphNode[];
125
- edges: SpatialGraphEdge[];
126
- graphs: Array<{ graphId: string; offsetX: number; offsetY: number }>;
127
- /** Optional floor panel labels for all_floors_offset. */
128
- floorPanels?: Array<{
129
- elevation: number;
130
- title: string;
131
- minX: number;
132
- minY: number;
133
- maxX: number;
134
- maxY: number;
135
- }>;
136
- /** Edges that cross floor panels (stairs) — dashed in SVG. */
137
- crossFloorEdgeKeys?: string[];
138
- /** H3 cell outlines in layout plane (outdoor world compose). */
139
- hexes?: SpatialGraphHexFootprint[];
140
- }
141
-
142
- export interface SpatialGraphToolRows {
143
- place_graphs?: readonly Record<string, unknown>[];
144
- place_nodes?: readonly Record<string, unknown>[];
145
- place_edges?: readonly Record<string, unknown>[];
146
- actor_spatial_locations?: readonly Record<string, unknown>[];
147
- /**
148
- * Optional, unfiltered `[[map_layers]]` rows. sk-pej D-2's session-grid
149
- * composition needs the PARENT graph's own `grid_distance_m` to convert
150
- * the grid's metre-native `cell_size` into the parent's own backdrop-cell
151
- * coordinate space (see `compose.ts`'s `metresPerParentLocalUnit`) — a
152
- * DIFFERENT concern from `RenderSvgOptions.backdrops`, which is what
153
- * actually draws the artwork. Absent, or no row matching the composed
154
- * parent's `place_graph_id`, falls back to
155
- * `place_graph_definition.metres_per_unit`.
156
- */
157
- map_layers?: readonly Record<string, unknown>[];
158
- visible_spatial_niche_attachments?: readonly Record<string, unknown>[];
159
- /** Public geometry used only for visible attachment scopes, never rendered. */
160
- notable_anchor_nodes?: readonly Record<string, unknown>[];
161
- }
162
-
163
- /**
164
- * How to project a (possibly multi-floor / unpositioned) graph into 2D.
165
- * - elevation_band: one floor (default for indoor multi-z)
166
- * - all_floors_offset: floors side-by-side
167
- * - topology_only: ignore coords; place by adjacency
168
- * - metric: all positioned nodes in one plane (legacy outdoor)
169
- */
170
- export type SpatialSliceMode =
171
- | "elevation_band"
172
- | "all_floors_offset"
173
- | "topology_only"
174
- | "metric"
175
- /** Outdoor multi-graph compose from cell_res10 (h3-js), same idea as web WorldMapView. */
176
- | "h3_world";
177
-
178
- export type SpatialLod = "structure" | "furnished";
179
-
180
- export interface SpatialViewOptions {
181
- graphId?: string;
182
- /** Slice mode; auto-picked when omitted. */
183
- slice?: SpatialSliceMode;
184
- /** Elevation for elevation_band (default 0). */
185
- z?: number;
186
- /** Half-width of elevation band (default 0.5). */
187
- zTolerance?: number;
188
- /** structure = rooms only; furnished = + occupancy badges (default). */
189
- lod?: SpatialLod;
190
- /**
191
- * Keep authored x/y (no indoor Y-flip). Use when placing nodes in map-image
192
- * cell space under a [[map_layers]] backdrop (map-from-image product views).
193
- */
194
- sheetAlign?: boolean;
195
- /**
196
- * Prefer H3 cell plane for unfiltered outdoor compose when nodes carry cell_res10.
197
- * Default true. Set false to force graph-local metric side-by-side compose.
198
- */
199
- preferH3World?: boolean;
200
- /**
201
- * Compose an ephemeral session-grid graph (`graphId`) over its parent
202
- * location's own topology when `graphId` resolves to a
203
- * `place_graph_definition` row with `is_ephemeral_instance = true` and a
204
- * resolvable `parent_graph_id` (bead sk-pej D-2, operator decision
205
- * 2026-08-13: "compose by default... one picture, no mode switch").
206
- * Default true — the map tool's own `compose_parent` param is this
207
- * option's escape hatch, settable to `false` to force the grid-alone
208
- * single view. Has NO effect when `graphId` is not itself an ephemeral
209
- * instance (an ordinary authored nested graph, e.g. elven-mini's
210
- * `tomb`/`inn` under `hamlet`, never composes regardless of this flag —
211
- * see `isEphemeralInstanceGraph` in `compose.ts`), so existing non-grid
212
- * callers render byte-identically whether this is set or omitted.
213
- */
214
- composeParent?: boolean;
215
- }
216
-
217
- export interface RenderSvgOptions {
218
- width?: number;
219
- height?: number;
220
- pad?: number;
221
- /** Optional backdrop image href resolver; when omitted, backdrops are skipped. */
222
- backdropHref?: (backdrop: SpatialGraphBackdrop) => string | null;
223
- backdrops?: readonly SpatialGraphBackdrop[];
224
- ariaLabel?: string;
225
- /** Hide actor badges (structure LOD). */
226
- hideOccupancy?: boolean;
227
- /** Extra title drawn under chrome (slice label). */
228
- sliceCaption?: string;
229
- /** Annotate explicit footprints with their full vertical span (for example ↕ 3 m). */
230
- showExtentDepth?: boolean;
231
- /**
232
- * Mask backdrop `<image>`s to the drawn nodes' own footprints (player-map
233
- * PNG mode) — an SVG `<mask>` built from `layout.nodes` (already the
234
- * fog-of-war-filtered known set for PLAYER callers), each node revealing its
235
- * own extent shape plus a fixed legibility margin.
236
- * Default false/undefined — written and tested, but NOT enabled by any
237
- * caller today: `spellkave_map` (tools.ts) renders the backdrop in
238
- * full/unmasked per operator decision 2026-08-12 (the fog-of-war applies
239
- * to the GRAPH drawn on top, not to the art). AUTHOR's `spellkave_map_graph`
240
- * never sets this either, so its SVG output stays byte-identical. Turning
241
- * this on for the player tool is tracked as bead sk-ubx.
242
- */
243
- maskBackdropToNodes?: boolean;
244
- }
package/src/tags.ts DELETED
@@ -1,68 +0,0 @@
1
- /**
2
- * ADR-0123 D-2 tag helpers: indoor/outdoor class via coordinate_kind_id,
3
- * level index from elevation, and the LEVEL_HEIGHT_M convention.
4
- *
5
- * Class is NEVER matched on the substrate_id string literal. A modder-authored
6
- * `cave` substrate on `graph_local` is indoor-class.
7
- */
8
-
9
- /** Default storey height (metres) — ADR-0123 D-2 / G-1. */
10
- export const LEVEL_HEIGHT_M = 3.0;
11
-
12
- export type SpatialClass = "indoor" | "outdoor" | "tactical" | "drop";
13
-
14
- /** Kernel bootstrap seed used when substrate_definitions rows are absent. */
15
- export const CORE_SUBSTRATE_KINDS: Readonly<Record<string, string>> = {
16
- outdoor: "h3_cell",
17
- indoor: "graph_local",
18
- tactical: "tactical_grid",
19
- };
20
-
21
- export function spatialClassOf(
22
- substrateId: string,
23
- kindBySubstrate: ReadonlyMap<string, string>,
24
- ): SpatialClass {
25
- const kind = kindBySubstrate.get(substrateId) ?? CORE_SUBSTRATE_KINDS[substrateId] ?? "";
26
- if (kind === "graph_local") return "indoor";
27
- if (kind === "h3_cell") return "outdoor";
28
- if (kind === "tactical_grid") return "tactical";
29
- // Unknown kind: outdoor-class (no SIT tags) rather than inventing floors.
30
- return "outdoor";
31
- }
32
-
33
- /**
34
- * Build substrate_id → coordinate_kind_id map.
35
- * Starts from the kernel bootstrap seed, then overlays authored
36
- * substrate_definitions. Returns whether the bootstrap fallback was needed
37
- * (no authored rows, or a row still resolved only via CORE_SUBSTRATE_KINDS).
38
- */
39
- export function buildCoordinateKindMap(
40
- substrateDefinitions: readonly { substrate_id: string; coordinate_kind_id: string }[],
41
- ): { kindBySubstrate: Map<string, string>; usedBootstrapFallback: boolean } {
42
- const kindBySubstrate = new Map<string, string>();
43
- for (const [id, kind] of Object.entries(CORE_SUBSTRATE_KINDS)) {
44
- kindBySubstrate.set(id, kind);
45
- }
46
- let authored = 0;
47
- for (const s of substrateDefinitions) {
48
- if (s.substrate_id && s.coordinate_kind_id) {
49
- kindBySubstrate.set(s.substrate_id, s.coordinate_kind_id);
50
- authored += 1;
51
- }
52
- }
53
- return {
54
- kindBySubstrate,
55
- usedBootstrapFallback: authored === 0,
56
- };
57
- }
58
-
59
- /** level index = round(elevation / LEVEL_HEIGHT_M) when indoor/tactical-class + elevation present. */
60
- export function levelIndex(
61
- poseElevationPresent: boolean,
62
- poseElevation: number,
63
- cls: SpatialClass,
64
- ): number | null {
65
- if (!poseElevationPresent) return null;
66
- if (cls !== "indoor" && cls !== "tactical") return null;
67
- return Math.round(poseElevation / LEVEL_HEIGHT_M);
68
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * MVT encode (geojson-vt tile → vt-pbf).
3
- */
4
-
5
- import { createRequire } from "node:module";
6
-
7
- import { TILE_LAYER_NAMES, type TileLayerName, type WorldTilesCache } from "./layers.ts";
8
-
9
- const require = createRequire(import.meta.url);
10
- // vt-pbf is CJS.
11
- const vtpbf = require("vt-pbf") as {
12
- fromGeojsonVt: (
13
- layers: Record<string, unknown>,
14
- options?: { version?: number; extent?: number },
15
- ) => Uint8Array;
16
- };
17
-
18
- export function encodeMvtTile(
19
- cache: WorldTilesCache,
20
- z: number,
21
- x: number,
22
- y: number,
23
- ): Uint8Array | null {
24
- const layers: Record<string, unknown> = {};
25
- let any = false;
26
- for (const name of TILE_LAYER_NAMES) {
27
- const tile = cache.indexes[name as TileLayerName].getTile(z, x, y);
28
- if (tile && tile.features && tile.features.length > 0) {
29
- layers[name] = tile;
30
- any = true;
31
- }
32
- }
33
- if (!any) return null;
34
- return vtpbf.fromGeojsonVt(layers, { version: 2, extent: 4096 });
35
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * @spellkave/world-map/tiles — MVT builders, TileJSON, MapLibre style.
3
- * Not HTTP: the gateway keeps routing, auth, CORS, asset/font serving.
4
- */
5
-
6
- export { encodeMvtTile } from "./encode.ts";
7
- export {
8
- backdropsOf,
9
- buildWorldTilesCache,
10
- buildWorldTilesCacheFromExport,
11
- GEOJSON_VT_OPTIONS,
12
- manifestOf,
13
- splitTileLayers,
14
- TILE_LAYER_NAMES,
15
- type TileLayerFields,
16
- type TileLayerName,
17
- vectorLayerFields,
18
- type WorldTilesCache,
19
- } from "./layers.ts";
20
- export {
21
- buildMapLibreStyle,
22
- buildTileJson,
23
- resolveBackdropUrls,
24
- validateMapLibreStyle,
25
- } from "./style.ts";