structured-context-map-views 0.3.1 → 0.4.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/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":["packageJson"],"sources":["../package.json","../src/node/snapshot.ts","../src/node/cli.ts"],"sourcesContent":["{\n \"name\": \"structured-context-map-views\",\n \"version\": \"0.3.1\",\n \"description\": \"Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/mindsocket/structured-context-map-views.git\",\n \"directory\": \"packages/map-views\"\n },\n \"homepage\": \"https://github.com/mindsocket/structured-context-map-views#readme\",\n \"bugs\": \"https://github.com/mindsocket/structured-context-map-views/issues\",\n \"keywords\": [\n \"structured-context\",\n \"visualisation\",\n \"map-view\",\n \"react\"\n ],\n \"files\": [\n \"dist/\"\n ],\n \"sideEffects\": false,\n \"bin\": {\n \"structured-context-map-views\": \"dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./node\": {\n \"types\": \"./dist/types/node/index.d.ts\",\n \"default\": \"./dist/node.js\"\n },\n \"./styles.css\": \"./dist/styles.css\"\n },\n \"scripts\": {\n \"clean\": \"rm -rf dist\",\n \"generate\": \"bun run generate:schemas && bun run generate:definitions\",\n \"generate:schemas\": \"bun scripts/generate-schemas.ts\",\n \"generate:definitions\": \"bun scripts/generate-definitions.ts\",\n \"build\": \"bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/layouts/styles.css -o dist/styles.css && bun scripts/build-artifact-page.ts\",\n \"typecheck\": \"tsc --noEmit\",\n \"capture-fixtures\": \"bun scripts/capture-fixtures.ts\",\n \"test\": \"bun test\",\n \"test:package\": \"bash scripts/test-package.sh\",\n \"prepublishOnly\": \"bun run build\",\n \"preversion\": \"bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run test:package\",\n \"version\": \"bun run generate:schemas --release && git add -A\"\n },\n \"peerDependencies\": {\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.21.0\"\n },\n \"dependencies\": {\n \"ajv\": \"^8.20.0\",\n \"commander\": \"^15.0.0\",\n \"json-schema-to-ts\": \"^3.1.1\",\n \"json5\": \"^2.2.3\"\n },\n \"devDependencies\": {\n \"@tailwindcss/cli\": \"^4.3.3\",\n \"@types/node\": \"^22.20.5\",\n \"@types/react\": \"^19.3.0\",\n \"@types/react-dom\": \"^19.3.0\",\n \"@vitejs/plugin-react\": \"^6.1.1\",\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.21.0\",\n \"tailwindcss\": \"^4.3.3\",\n \"vite\": \"^8.3.2\"\n }\n}\n","import {\n assembleSpaceGraph,\n type Config,\n createSpaceContext,\n exportSpaceGraph,\n validateSpace,\n} from 'structured-context/api';\nimport { type MapViewDefinition, mapViewsForSchema } from '../core/definition';\nimport { loadMapViewDefinitions } from './index';\n\n/**\n * Everything a host without filesystem access needs to render a space: its graph, the validation\n * results that attach to nodes, and the map view definitions that apply to its schema. Plain JSON.\n */\nexport type SpaceSnapshot = {\n space: string;\n schemaId: string | undefined;\n graph: ReturnType<typeof exportSpaceGraph>;\n validation: Awaited<ReturnType<typeof validateSpace>>;\n definitions: MapViewDefinition[];\n};\n\n/** The `validateSpace` options `export` passes through unchanged. */\nexport type ExportValidateOptions = Pick<\n NonNullable<Parameters<typeof validateSpace>[1]>,\n 'depth' | 'includeGated' | 'semantic' | 'ruleFilter'\n>;\n\n/**\n * Node-only: snapshot a space for a browser-only host. Validation is structured-context's own\n * `validateSpace`, which also decides whether a judge runs.\n */\nexport async function exportSnapshot(\n spaceName: string,\n config: Config,\n configDir?: string,\n validateOptions: ExportValidateOptions = {},\n): Promise<SpaceSnapshot> {\n const context = createSpaceContext(spaceName, config);\n const graph = await assembleSpaceGraph(context, {});\n const schemaId = context.schema.$id;\n return {\n space: spaceName,\n schemaId,\n graph: exportSpaceGraph(graph.nodes.values(), context.schema.metadata),\n validation: await validateSpace(context, validateOptions),\n definitions: mapViewsForSchema(loadMapViewDefinitions(config, { configDir }), schemaId),\n };\n}\n","#!/usr/bin/env bun\nimport { dirname, resolve } from 'node:path';\nimport { Command } from 'commander';\nimport { loadConfig, resolveConfigPath, SctxError, setConfigPath } from 'structured-context/api';\nimport packageJson from '../../package.json' with { type: 'json' };\nimport { type ExportValidateOptions, exportSnapshot } from './snapshot';\n\nconst program = new Command();\n\nprogram\n .name('structured-context-map-views')\n .description('Map view tools for structured-context spaces')\n .version(packageJson.version)\n .option('--config <path>', 'Path to config file (overrides config discovery)');\n\nprogram\n .command('export')\n .description('Print a JSON snapshot of a space: its graph, validation results and map view definitions')\n .argument('<space-name>', 'Space name')\n .option('--depth <n>', 'Validate only hierarchy nodes within N levels from the top', (v) => parseInt(v, 10))\n .option('--include-gated', 'Evaluate rules even on nodes gated by an upstream failure')\n .option(\n '--rule-filter <dimension=values>',\n 'Evaluate only matching rules; dimensions: category, severity, type, id (repeatable, e.g. severity=error)',\n (v: string, prev: string[] = []) => [...prev, v],\n )\n .option('--semantic [provider]', 'Evaluate semantic rules, with the configured model provider or the one named')\n .action(async (spaceName: string, options: ExportValidateOptions) => {\n setConfigPath(program.opts().config);\n try {\n const config = loadConfig();\n const configDir = dirname(resolve(resolveConfigPath().path));\n const result = await exportSnapshot(spaceName, config, configDir, options);\n process.stdout.write(`${JSON.stringify(result)}\\n`);\n } catch (err) {\n if (!(err instanceof SctxError)) throw err;\n console.error(`${err.code}: ${err.message}`);\n process.exitCode = 1;\n }\n });\n\nawait program.parseAsync();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AS;EAC3C,QAAQ,WAAW;CACrB;AACF,CAAC;AAEH,MAAM,QAAQ,WAAW"}
1
+ {"version":3,"file":"cli.js","names":["packageJson"],"sources":["../package.json","../src/node/snapshot.ts","../src/node/cli.ts"],"sourcesContent":["{\n \"name\": \"structured-context-map-views\",\n \"version\": \"0.4.0\",\n \"description\": \"Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/mindsocket/structured-context-map-views.git\",\n \"directory\": \"packages/map-views\"\n },\n \"homepage\": \"https://github.com/mindsocket/structured-context-map-views#readme\",\n \"bugs\": \"https://github.com/mindsocket/structured-context-map-views/issues\",\n \"keywords\": [\n \"structured-context\",\n \"visualisation\",\n \"map-view\",\n \"react\"\n ],\n \"files\": [\n \"dist/\"\n ],\n \"sideEffects\": false,\n \"bin\": {\n \"structured-context-map-views\": \"dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./node\": {\n \"types\": \"./dist/types/node/index.d.ts\",\n \"default\": \"./dist/node.js\"\n },\n \"./styles.css\": \"./dist/styles.css\"\n },\n \"scripts\": {\n \"clean\": \"rm -rf dist\",\n \"generate\": \"bun run generate:schemas && bun run generate:definitions\",\n \"generate:schemas\": \"bun scripts/generate-schemas.ts\",\n \"generate:definitions\": \"bun scripts/generate-definitions.ts\",\n \"build\": \"bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/layouts/styles.css -o dist/styles.css && bun scripts/build-artifact-page.ts\",\n \"typecheck\": \"tsc --noEmit\",\n \"capture-fixtures\": \"bun scripts/capture-fixtures.ts\",\n \"test\": \"bun test\",\n \"test:package\": \"bash scripts/test-package.sh\",\n \"prepublishOnly\": \"bun run build\",\n \"preversion\": \"bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run test:package\",\n \"version\": \"bun run generate:schemas --release && git add -A\"\n },\n \"peerDependencies\": {\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.21.0\"\n },\n \"dependencies\": {\n \"ajv\": \"^8.20.0\",\n \"commander\": \"^15.0.0\",\n \"json-schema-to-ts\": \"^3.1.1\",\n \"json5\": \"^2.2.3\"\n },\n \"devDependencies\": {\n \"@tailwindcss/cli\": \"^4.3.3\",\n \"@types/node\": \"^22.20.5\",\n \"@types/react\": \"^19.3.0\",\n \"@types/react-dom\": \"^19.3.0\",\n \"@vitejs/plugin-react\": \"^6.1.1\",\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.21.0\",\n \"tailwindcss\": \"^4.3.3\",\n \"vite\": \"^8.3.2\"\n }\n}\n","import {\n assembleSpaceGraph,\n type Config,\n createSpaceContext,\n exportSpaceGraph,\n validateSpace,\n} from 'structured-context/api';\nimport { type MapViewDefinition, mapViewsForSchema } from '../core/definition';\nimport { loadMapViewDefinitions } from './index';\n\n/**\n * Everything a host without filesystem access needs to render a space: its graph, the validation\n * results that attach to nodes, and the map view definitions that apply to its schema. Plain JSON.\n */\nexport type SpaceSnapshot = {\n space: string;\n schemaId: string | undefined;\n graph: ReturnType<typeof exportSpaceGraph>;\n validation: Awaited<ReturnType<typeof validateSpace>>;\n definitions: MapViewDefinition[];\n};\n\n/** The `validateSpace` options `export` passes through unchanged. */\nexport type ExportValidateOptions = Pick<\n NonNullable<Parameters<typeof validateSpace>[1]>,\n 'depth' | 'includeGated' | 'semantic' | 'ruleFilter'\n>;\n\n/**\n * Node-only: snapshot a space for a browser-only host. Validation is structured-context's own\n * `validateSpace`, which also decides whether a judge runs.\n */\nexport async function exportSnapshot(\n spaceName: string,\n config: Config,\n configDir?: string,\n validateOptions: ExportValidateOptions = {},\n): Promise<SpaceSnapshot> {\n const context = createSpaceContext(spaceName, config);\n const graph = await assembleSpaceGraph(context, {});\n const schemaId = context.schema.$id;\n return {\n space: spaceName,\n schemaId,\n graph: exportSpaceGraph(graph.nodes.values(), context.schema.metadata),\n validation: await validateSpace(context, validateOptions),\n definitions: mapViewsForSchema(loadMapViewDefinitions(config, { configDir }), schemaId),\n };\n}\n","#!/usr/bin/env bun\nimport { dirname, resolve } from 'node:path';\nimport { Command } from 'commander';\nimport { loadConfig, resolveConfigPath, SctxError, setConfigPath } from 'structured-context/api';\nimport packageJson from '../../package.json' with { type: 'json' };\nimport { type ExportValidateOptions, exportSnapshot } from './snapshot';\n\nconst program = new Command();\n\nprogram\n .name('structured-context-map-views')\n .description('Map view tools for structured-context spaces')\n .version(packageJson.version)\n .option('--config <path>', 'Path to config file (overrides config discovery)');\n\nprogram\n .command('export')\n .description('Print a JSON snapshot of a space: its graph, validation results and map view definitions')\n .argument('<space-name>', 'Space name')\n .option('--depth <n>', 'Validate only hierarchy nodes within N levels from the top', (v) => parseInt(v, 10))\n .option('--include-gated', 'Evaluate rules even on nodes gated by an upstream failure')\n .option(\n '--rule-filter <dimension=values>',\n 'Evaluate only matching rules; dimensions: category, severity, type, id (repeatable, e.g. severity=error)',\n (v: string, prev: string[] = []) => [...prev, v],\n )\n .option('--semantic [provider]', 'Evaluate semantic rules, with the configured model provider or the one named')\n .action(async (spaceName: string, options: ExportValidateOptions) => {\n setConfigPath(program.opts().config);\n try {\n const config = loadConfig();\n const configDir = dirname(resolve(resolveConfigPath().path));\n const result = await exportSnapshot(spaceName, config, configDir, options);\n process.stdout.write(`${JSON.stringify(result)}\\n`);\n } catch (err) {\n if (!(err instanceof SctxError)) throw err;\n console.error(`${err.code}: ${err.message}`);\n process.exitCode = 1;\n }\n });\n\nawait program.parseAsync();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgCA,eAAsB,eACpB,WACA,QACA,WACA,kBAAyC,CAAC,GAClB;CAC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.js CHANGED
@@ -1,3 +1,4 @@
1
- import { a as SelectParameterInput, c as annotationsFrom, i as ParameterInput, l as worstSeverity, n as useParameterControls, o as ToggleParameterInput, r as MultiSelectParameterInput, s as MapView, t as ParameterControls } from "./ParameterControls-BsdG5GDk.js";
1
+ import { a as annotationsFrom, r as buildTree, s as worstSeverity } from "./projection-GaO0MCbR.js";
2
2
  import { c as MAP_VIEW_SCHEMAS, i as resolveParameterValues, n as mapViewsForSchema, o as selectionFilter, r as parseMapViewDefinition, s as viewValidationLevel, t as MapViewDefinitionError } from "./definition-Cft28YUA.js";
3
- export { MAP_VIEW_SCHEMAS, MapView, MapViewDefinitionError, MultiSelectParameterInput, ParameterControls, ParameterInput, SelectParameterInput, ToggleParameterInput, annotationsFrom, mapViewsForSchema, parseMapViewDefinition, resolveParameterValues, selectionFilter, useParameterControls, viewValidationLevel, worstSeverity };
3
+ import { a as SelectParameterInput, i as ParameterInput, n as useParameterControls, o as ToggleParameterInput, r as MultiSelectParameterInput, s as MapView, t as ParameterControls } from "./ParameterControls-eKRxNr1P.js";
4
+ export { MAP_VIEW_SCHEMAS, MapView, MapViewDefinitionError, MultiSelectParameterInput, ParameterControls, ParameterInput, SelectParameterInput, ToggleParameterInput, annotationsFrom, buildTree, mapViewsForSchema, parseMapViewDefinition, resolveParameterValues, selectionFilter, useParameterControls, viewValidationLevel, worstSeverity };
@@ -0,0 +1,385 @@
1
+ //#region src/core/annotations.ts
2
+ /**
3
+ * Attach validation results to the nodes of `graph`, by node id. Results that can't be attached are
4
+ * returned in `unattached` for the host to surface: global-scope rules (no node), and nodes that
5
+ * aren't in the graph, which includes every node that failed its schema.
6
+ */
7
+ function annotationsFrom(input, graph) {
8
+ const annotations = /* @__PURE__ */ new Map();
9
+ const unattached = [];
10
+ const add = (nodeId, annotation, location) => {
11
+ if (nodeId !== void 0 && graph.nodes.has(nodeId)) annotations.set(nodeId, [...annotations.get(nodeId) ?? [], annotation]);
12
+ else unattached.push({
13
+ ...annotation,
14
+ nodeId,
15
+ ...location && { location }
16
+ });
17
+ };
18
+ for (const { nodeId, source, issues } of input.nodeErrors ?? []) for (const issue of issues) add(nodeId, {
19
+ severity: "error",
20
+ source: "schema",
21
+ message: issue.message
22
+ }, source);
23
+ for (const { nodeId, description } of input.hierarchyViolations ?? []) add(nodeId, {
24
+ severity: "error",
25
+ source: "hierarchy",
26
+ message: description
27
+ });
28
+ for (const { nodeId, description, severity, ruleId } of input.ruleViolations ?? []) add(nodeId, {
29
+ severity,
30
+ source: "rule",
31
+ message: description,
32
+ ruleId
33
+ });
34
+ return {
35
+ annotations,
36
+ unattached
37
+ };
38
+ }
39
+ var RANK = {
40
+ error: 0,
41
+ warning: 1,
42
+ info: 2
43
+ };
44
+ /** The most serious severity among annotations, or undefined if there are none. */
45
+ function worstSeverity(annotations) {
46
+ return annotations.reduce((worst, { severity }) => worst === void 0 || RANK[severity] < RANK[worst] ? severity : worst, void 0);
47
+ }
48
+ /**
49
+ * The annotations a map view shows: those at `level` or more serious, from `sources`. `off` shows none.
50
+ * Nodes left with no annotations are dropped from the index.
51
+ */
52
+ function filterAnnotations(index, level, sources) {
53
+ if (level === "off") return /* @__PURE__ */ new Map();
54
+ const filtered = /* @__PURE__ */ new Map();
55
+ for (const [id, annotations] of index) {
56
+ const kept = annotations.filter((a) => RANK[a.severity] <= RANK[level] && sources.includes(a.source));
57
+ if (kept.length > 0) filtered.set(id, kept);
58
+ }
59
+ return filtered;
60
+ }
61
+ //#endregion
62
+ //#region src/core/graph.ts
63
+ var NONE = [];
64
+ /**
65
+ * Edges to a node's parents, in the order the node declares them. A graph narrowed by a filter keeps
66
+ * edges to parents outside it; those are left out.
67
+ */
68
+ function parentEdges(graph, id) {
69
+ return (graph.parentEdges.get(id) ?? NONE).filter((edge) => graph.nodes.has(edge.parent));
70
+ }
71
+ /** Edges to a node's children, in graph order of the children. */
72
+ function childEdges(graph, id) {
73
+ return graph.childEdges.get(id) ?? NONE;
74
+ }
75
+ /** Every edge whose parent and child are both in the graph. */
76
+ function edgesWithin(graph) {
77
+ return [...graph.nodes.keys()].flatMap((id) => parentEdges(graph, id));
78
+ }
79
+ /** Whether an edge belongs to the given hierarchy (as opposed to a relationship or another hierarchy). */
80
+ function isHierarchyEdge(edge, hierarchy) {
81
+ return hierarchy !== void 0 && edge.kind === "hierarchy" && edge.hierarchy === hierarchy.name;
82
+ }
83
+ //#endregion
84
+ //#region src/core/occurrence.ts
85
+ /**
86
+ * Path-based key for one occurrence of a node: region, then the steps from the outermost
87
+ * container down to the node. Unique within a map view even when a node appears several times.
88
+ * Hosts can render several map views at once, so layouts scope keys to the map view instance.
89
+ */
90
+ function occurrenceKey(regionId, path) {
91
+ return JSON.stringify([regionId, ...path]);
92
+ }
93
+ //#endregion
94
+ //#region src/core/tree.ts
95
+ /**
96
+ * Lay a space out as a tree over its hierarchy.
97
+ *
98
+ * Roots are root-type nodes with no hierarchy parent. Traversal is depth-first in space order,
99
+ * so a node's primary occurrence is under the parent reached first. Under its other parents a
100
+ * node is either repeated without its subtree (`repeat`), or left out and linked by a cross-edge
101
+ * (`cross-edge`). Either way traversal stops there, which also keeps cycles from recursing.
102
+ */
103
+ function buildTree(graph, regionId, dag = "repeat") {
104
+ const { hierarchy } = graph;
105
+ const levelTypes = new Set(hierarchy?.levels.map((level) => level.type));
106
+ const rootType = hierarchy?.levels[0]?.type;
107
+ const primary = /* @__PURE__ */ new Map();
108
+ const pendingCross = [];
109
+ const hierarchyParents = (title) => parentEdges(graph, title).filter((edge) => isHierarchyEdge(edge, hierarchy));
110
+ const visit = (node, path) => {
111
+ const nodePath = [...path, node.id];
112
+ const key = occurrenceKey(regionId, nodePath);
113
+ primary.set(node.id, key);
114
+ const childTitles = new Set(childEdges(graph, node.id).filter((edge) => isHierarchyEdge(edge, hierarchy)).map((edge) => edge.child));
115
+ const children = [];
116
+ for (const title of childTitles) {
117
+ const child = graph.nodes.get(title);
118
+ const repeatOf = primary.get(title);
119
+ if (repeatOf === void 0) children.push(visit(child, nodePath));
120
+ else if (dag === "repeat") children.push({
121
+ key: occurrenceKey(regionId, [...nodePath, title]),
122
+ node: child,
123
+ children: [],
124
+ repeatOf
125
+ });
126
+ else pendingCross.push({
127
+ from: key,
128
+ child: title
129
+ });
130
+ }
131
+ return {
132
+ key,
133
+ node,
134
+ children
135
+ };
136
+ };
137
+ const levelNodes = [...graph.nodes.values()].filter((node) => levelTypes.has(node.resolvedType));
138
+ const unparented = levelNodes.filter((node) => hierarchyParents(node.id).length === 0);
139
+ const roots = unparented.filter((node) => node.resolvedType === rootType).map((node) => visit(node, []));
140
+ const orphans = unparented.filter((node) => node.resolvedType !== rootType).map((node) => visit(node, []));
141
+ for (const node of levelNodes) if (!primary.has(node.id)) orphans.push(visit(node, []));
142
+ return {
143
+ roots,
144
+ orphans,
145
+ primary,
146
+ crossLinks: pendingCross.map(({ from, child }) => ({
147
+ from,
148
+ to: primary.get(child),
149
+ kind: "cross"
150
+ }))
151
+ };
152
+ }
153
+ /** Parent → child pairs of occurrence keys: one per rendered parent-child link, then cross-links. */
154
+ function treeLinks(tree) {
155
+ const links = [];
156
+ const walk = (occurrence) => {
157
+ for (const child of occurrence.children) {
158
+ links.push({
159
+ from: occurrence.key,
160
+ to: child.key,
161
+ kind: "tree"
162
+ });
163
+ walk(child);
164
+ }
165
+ };
166
+ for (const root of [...tree.roots, ...tree.orphans]) walk(root);
167
+ return [...links, ...tree.crossLinks];
168
+ }
169
+ //#endregion
170
+ //#region src/core/landscape.ts
171
+ /**
172
+ * Lay a space out as nested containers following the layout's grouping levels.
173
+ *
174
+ * Adjacent node levels are joined by any edge between their types, in either direction, or only
175
+ * edges from `edge.field`. A `via` chain joins them through the skipped types. A field level
176
+ * splits the next node level by that field's values. A node reached from several containers
177
+ * appears in each, in full: the levels are finite, so repeating contents can't recurse.
178
+ */
179
+ function buildLandscape(graph, regionId, layout) {
180
+ const levels = layout.group;
181
+ const order = new Map([...graph.nodes.keys()].map((title, i) => [title, i]));
182
+ const first = /* @__PURE__ */ new Map();
183
+ const occurrenceFor = (candidate, levelIdx, path) => {
184
+ const { node } = candidate;
185
+ const nodePath = [...path, node.id];
186
+ const key = occurrenceKey(regionId, nodePath);
187
+ const repeatOf = first.get(node.id);
188
+ if (repeatOf === void 0) first.set(node.id, key);
189
+ return {
190
+ key,
191
+ level: levelIdx,
192
+ item: {
193
+ kind: "node",
194
+ node
195
+ },
196
+ via: candidate.via,
197
+ ...repeatOf !== void 0 && { repeatOf },
198
+ children: place(levelIdx + 1, node, [], nodePath)
199
+ };
200
+ };
201
+ /** Occurrences for level `levelIdx` inside `anchor`, the nearest enclosing node. */
202
+ const place = (levelIdx, anchor, filters, path) => {
203
+ const level = levels[levelIdx];
204
+ if (level === void 0) return [];
205
+ if (isTypeLevel(level)) return candidates(level, anchor, filters).map((c) => occurrenceFor(c, levelIdx, path));
206
+ const nodeLevel = levels.slice(levelIdx).find(isTypeLevel);
207
+ return distinctValues(candidates(nodeLevel, anchor, filters).map((c) => c.node), level.field).map((value) => {
208
+ const valuePath = [...path, [level.field, value]];
209
+ return {
210
+ key: occurrenceKey(regionId, valuePath),
211
+ level: levelIdx,
212
+ item: {
213
+ kind: "value",
214
+ field: level.field,
215
+ value
216
+ },
217
+ via: [],
218
+ children: place(levelIdx + 1, anchor, [...filters, {
219
+ field: level.field,
220
+ value
221
+ }], valuePath)
222
+ };
223
+ });
224
+ };
225
+ /** Nodes of a type level joined to `anchor` (all of the type at the top) and matching the filters. */
226
+ const candidates = (level, anchor, filters) => {
227
+ return (anchor === void 0 ? ofType(level.type).map((node) => ({
228
+ node,
229
+ via: []
230
+ })) : walkChain(anchor, level.via ?? [], level.type, level.edge?.field)).filter(({ node }) => filters.every((f) => hasValue(node, f)));
231
+ };
232
+ const ofType = (type) => [...graph.nodes.values()].filter((node) => node.resolvedType === type);
233
+ /** Neighbours of a node with the given type, across edges in either direction, in space order. */
234
+ const neighbours = (title, type, field) => {
235
+ return [.../* @__PURE__ */ new Set([...childEdges(graph, title).filter((e) => field === void 0 || e.field === field).map((e) => e.child), ...parentEdges(graph, title).filter((e) => field === void 0 || e.field === field).map((e) => e.parent)])].map((t) => graph.nodes.get(t)).filter((node) => node.resolvedType === type).sort((a, b) => order.get(a.id) - order.get(b.id));
236
+ };
237
+ /**
238
+ * Follow edges from `anchor` through each `via` type to `target`, keeping the skipped nodes on
239
+ * the way to each target node. Several chains to one target merge into one candidate.
240
+ */
241
+ const walkChain = (anchor, via, target, field) => {
242
+ let frontier = [{
243
+ node: anchor,
244
+ trail: []
245
+ }];
246
+ for (const type of via) frontier = frontier.flatMap(({ node, trail }) => neighbours(node.id, type, void 0).map((next) => ({
247
+ node: next,
248
+ trail: [...trail, next]
249
+ })));
250
+ const byTitle = /* @__PURE__ */ new Map();
251
+ for (const { node, trail } of frontier) for (const next of neighbours(node.id, target, field)) {
252
+ const candidate = byTitle.get(next.id) ?? {
253
+ node: next,
254
+ via: via.map((type) => ({
255
+ type,
256
+ nodes: []
257
+ }))
258
+ };
259
+ trail.forEach((skipped, i) => {
260
+ const step = candidate.via[i];
261
+ if (!step.nodes.includes(skipped)) step.nodes.push(skipped);
262
+ });
263
+ byTitle.set(next.id, candidate);
264
+ }
265
+ return [...byTitle.values()].sort((a, b) => order.get(a.node.id) - order.get(b.node.id));
266
+ };
267
+ const groups = place(0, void 0, [], []);
268
+ const ungrouped = [];
269
+ levels.forEach((level, levelIdx) => {
270
+ if (levelIdx === 0 || !isTypeLevel(level)) return;
271
+ for (const node of ofType(level.type)) if (!first.has(node.id)) ungrouped.push(occurrenceFor({
272
+ node,
273
+ via: []
274
+ }, levelIdx, [null]));
275
+ });
276
+ return {
277
+ groups,
278
+ ungrouped
279
+ };
280
+ }
281
+ function isTypeLevel(level) {
282
+ return "type" in level;
283
+ }
284
+ /** A field's values as group labels: strings, an entry per array item, `null` when empty. */
285
+ function valuesOf(node, field) {
286
+ const raw = node.schemaData[field];
287
+ const list = (Array.isArray(raw) ? raw : [raw]).filter((v) => v !== void 0 && v !== null && v !== "");
288
+ return list.length === 0 ? [null] : list.map((v) => typeof v === "object" ? JSON.stringify(v) : String(v));
289
+ }
290
+ /** Distinct values in first-seen order, with the empty group last. */
291
+ function distinctValues(nodes, field) {
292
+ const values = new Set(nodes.flatMap((node) => valuesOf(node, field)));
293
+ const present = [...values].filter((v) => v !== null);
294
+ return values.has(null) ? [...present, null] : present;
295
+ }
296
+ function hasValue(node, { field, value }) {
297
+ return valuesOf(node, field).includes(value);
298
+ }
299
+ //#endregion
300
+ //#region src/core/xy.ts
301
+ /**
302
+ * Position nodes by two numeric fields. Every node of a plotted type appears once: on the plot
303
+ * when both its values are numbers inside the axes' domains, otherwise in `unplaced` with the
304
+ * reason. Positions are normalised; layouts decide the plot's size.
305
+ */
306
+ function buildXYPlot(graph, regionId, layout) {
307
+ const { x, y } = layout;
308
+ const nodes = [...graph.nodes.values()];
309
+ const types = new Set(layout.types.length > 0 ? layout.types : nodes.filter((n) => isNumber(n.schemaData[x.field]) || isNumber(n.schemaData[y.field])).map((n) => n.resolvedType));
310
+ const plotted = nodes.filter((n) => types.has(n.resolvedType));
311
+ const domains = {
312
+ x: domainOf(x, plotted),
313
+ y: domainOf(y, plotted)
314
+ };
315
+ const points = [];
316
+ const unplaced = [];
317
+ for (const node of plotted) {
318
+ const key = occurrenceKey(regionId, [node.id]);
319
+ const px = position(node, x, domains.x);
320
+ const py = position(node, y, domains.y);
321
+ if (typeof px === "number" && typeof py === "number") points.push({
322
+ key,
323
+ node,
324
+ x: px,
325
+ y: py
326
+ });
327
+ else unplaced.push({
328
+ key,
329
+ node,
330
+ reasons: [px, py].filter((r) => typeof r === "string")
331
+ });
332
+ }
333
+ const keys = new Map(points.map((p) => [p.node.id, p.key]));
334
+ const fields = new Set(layout.edgeFields);
335
+ const links = edgesWithin(graph).filter((e) => keys.has(e.parent) && keys.has(e.child) && (fields.size === 0 || fields.has(e.field))).map((e) => ({
336
+ from: keys.get(e.parent),
337
+ to: keys.get(e.child),
338
+ field: e.field,
339
+ hierarchy: isHierarchyEdge(e, graph.hierarchy),
340
+ lane: 0
341
+ }));
342
+ assignLanes(links);
343
+ return {
344
+ points,
345
+ unplaced,
346
+ links,
347
+ domains
348
+ };
349
+ }
350
+ function isNumber(value) {
351
+ return typeof value === "number" && Number.isFinite(value);
352
+ }
353
+ /** The axis's fixed domain, or the range of plotted values (widened when they're all equal). */
354
+ function domainOf(axis, nodes) {
355
+ if (Array.isArray(axis.domain)) return [axis.domain[0], axis.domain[1]];
356
+ const values = nodes.map((n) => n.schemaData[axis.field]).filter(isNumber);
357
+ if (values.length === 0) return [0, 1];
358
+ const min = Math.min(...values);
359
+ const max = Math.max(...values);
360
+ return min === max ? [min - 1, max + 1] : [min, max];
361
+ }
362
+ /** The node's normalised position on the axis, or why it has none. */
363
+ function position(node, axis, [min, max]) {
364
+ const value = node.schemaData[axis.field];
365
+ if (value === void 0 || value === null) return `no ${axis.field}`;
366
+ if (!isNumber(value)) return `${axis.field} is not a number`;
367
+ if (value < min || value > max) return `${axis.field} ${value} is outside ${min}–${max}`;
368
+ const t = (value - min) / (max - min);
369
+ return axis.direction === "descending" ? 1 - t : t;
370
+ }
371
+ /** Spread links joining the same pair of nodes (in either direction) into lanes around 0. */
372
+ function assignLanes(links) {
373
+ const byPair = /* @__PURE__ */ new Map();
374
+ for (const link of links) {
375
+ const pair = [link.from, link.to].sort().join("\n");
376
+ byPair.set(pair, [...byPair.get(pair) ?? [], link]);
377
+ }
378
+ for (const group of byPair.values()) group.forEach((link, i) => {
379
+ link.lane = i - (group.length - 1) / 2;
380
+ });
381
+ }
382
+ //#endregion
383
+ export { annotationsFrom as a, treeLinks as i, buildLandscape as n, filterAnnotations as o, buildTree as r, worstSeverity as s, buildXYPlot as t };
384
+
385
+ //# sourceMappingURL=projection-GaO0MCbR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection-GaO0MCbR.js","names":[],"sources":["../src/core/annotations.ts","../src/core/graph.ts","../src/core/occurrence.ts","../src/core/tree.ts","../src/core/landscape.ts","../src/core/xy.ts"],"sourcesContent":["import type { RuleSeverity, SourceLocation, SpaceGraph, SpaceNode, ValidationResult } from 'structured-context/api';\n\n// core doesn't export NodeId from `structured-context/api` yet; this derives it.\ntype NodeId = SpaceNode['id'];\n\n/** How serious a result is: structured-context's rule severity. Schema and hierarchy failures are errors. */\nexport type Severity = RuleSeverity;\n\n/** The kind of check a result came from. */\nexport type AnnotationSource = 'schema' | 'hierarchy' | 'rule';\n\n/** One validation result attached to a node. */\nexport type NodeAnnotation = {\n severity: Severity;\n source: AnnotationSource;\n message: string;\n /** The violated rule, for `rule` results. */\n ruleId?: string;\n};\n\n/** A validation result with no node on the map to attach to. */\nexport type UnattachedAnnotation = NodeAnnotation & {\n /** The node it concerns. Absent for a global-scope rule. A node that failed its schema isn't in the graph. */\n nodeId?: NodeId;\n /** Where that node is defined, if known. */\n location?: SourceLocation;\n};\n\n/** Annotations by the id of the node they apply to. */\nexport type AnnotationIndex = ReadonlyMap<NodeId, readonly NodeAnnotation[]>;\n\n/**\n * The parts of structured-context's `ValidationResult` that attach to a node. Every part is optional:\n * a host that only runs some checks (the Obsidian plugin runs no AI-judged rules, say) passes what it has.\n */\nexport type ValidationInput = Partial<\n Pick<ValidationResult, 'ruleViolations' | 'hierarchyViolations'> & {\n nodeErrors: ReadonlyArray<Pick<ValidationResult['nodeErrors'][number], 'nodeId' | 'source' | 'issues'>>;\n }\n>;\n\n/**\n * Attach validation results to the nodes of `graph`, by node id. Results that can't be attached are\n * returned in `unattached` for the host to surface: global-scope rules (no node), and nodes that\n * aren't in the graph, which includes every node that failed its schema.\n */\nexport function annotationsFrom(\n input: ValidationInput,\n graph: SpaceGraph,\n): { annotations: AnnotationIndex; unattached: UnattachedAnnotation[] } {\n const annotations = new Map<NodeId, NodeAnnotation[]>();\n const unattached: UnattachedAnnotation[] = [];\n const add = (nodeId: NodeId | undefined, annotation: NodeAnnotation, location?: SourceLocation) => {\n if (nodeId !== undefined && graph.nodes.has(nodeId)) {\n annotations.set(nodeId, [...(annotations.get(nodeId) ?? []), annotation]);\n } else {\n unattached.push({ ...annotation, nodeId, ...(location && { location }) });\n }\n };\n\n for (const { nodeId, source, issues } of input.nodeErrors ?? []) {\n for (const issue of issues) {\n add(nodeId, { severity: 'error', source: 'schema', message: issue.message }, source);\n }\n }\n for (const { nodeId, description } of input.hierarchyViolations ?? []) {\n add(nodeId, { severity: 'error', source: 'hierarchy', message: description });\n }\n for (const { nodeId, description, severity, ruleId } of input.ruleViolations ?? []) {\n add(nodeId, { severity, source: 'rule', message: description, ruleId });\n }\n return { annotations, unattached };\n}\n\nconst RANK: Record<Severity, number> = { error: 0, warning: 1, info: 2 };\n\n/** The most serious severity among annotations, or undefined if there are none. */\nexport function worstSeverity(annotations: readonly NodeAnnotation[]): Severity | undefined {\n return annotations.reduce<Severity | undefined>(\n (worst, { severity }) => (worst === undefined || RANK[severity] < RANK[worst] ? severity : worst),\n undefined,\n );\n}\n\n/**\n * The annotations a map view shows: those at `level` or more serious, from `sources`. `off` shows none.\n * Nodes left with no annotations are dropped from the index.\n */\nexport function filterAnnotations(\n index: AnnotationIndex,\n level: Severity | 'off',\n sources: readonly AnnotationSource[],\n): AnnotationIndex {\n if (level === 'off') return new Map();\n const filtered = new Map<NodeId, readonly NodeAnnotation[]>();\n for (const [id, annotations] of index) {\n const kept = annotations.filter((a) => RANK[a.severity] <= RANK[level] && sources.includes(a.source));\n if (kept.length > 0) filtered.set(id, kept);\n }\n return filtered;\n}\n","import type { Hierarchy, SpaceGraph, SpaceNode } from 'structured-context/api';\n\ntype NodeId = SpaceNode['id'];\n\n/** A directed parent → child edge of a space graph, carrying the metadata of the reference it came from. */\nexport type Edge = SpaceGraph['parentEdges'] extends ReadonlyMap<string, readonly (infer E)[]> ? E : never;\n\nconst NONE: readonly Edge[] = [];\n\n/**\n * Edges to a node's parents, in the order the node declares them. A graph narrowed by a filter keeps\n * edges to parents outside it; those are left out.\n */\nexport function parentEdges(graph: SpaceGraph, id: NodeId): readonly Edge[] {\n return (graph.parentEdges.get(id) ?? NONE).filter((edge) => graph.nodes.has(edge.parent));\n}\n\n/** Edges to a node's children, in graph order of the children. */\nexport function childEdges(graph: SpaceGraph, id: NodeId): readonly Edge[] {\n return graph.childEdges.get(id) ?? NONE;\n}\n\n/** Every edge whose parent and child are both in the graph. */\nexport function edgesWithin(graph: SpaceGraph): Edge[] {\n return [...graph.nodes.keys()].flatMap((id) => parentEdges(graph, id));\n}\n\n/** Whether an edge belongs to the given hierarchy (as opposed to a relationship or another hierarchy). */\nexport function isHierarchyEdge(edge: Edge, hierarchy: Hierarchy | undefined): boolean {\n return hierarchy !== undefined && edge.kind === 'hierarchy' && edge.hierarchy === hierarchy.name;\n}\n","/**\n * One step of an occurrence path: a node title, a `[field, value]` group, or `null` for the\n * ungrouped area. Encoded distinctly, so a field group can't collide with a node of the same name.\n */\nexport type PathSegment = string | readonly [field: string, value: string | null] | null;\n\n/**\n * Path-based key for one occurrence of a node: region, then the steps from the outermost\n * container down to the node. Unique within a map view even when a node appears several times.\n * Hosts can render several map views at once, so layouts scope keys to the map view instance.\n */\nexport function occurrenceKey(regionId: string, path: readonly PathSegment[]): string {\n return JSON.stringify([regionId, ...path]);\n}\n","import type { SpaceGraph, SpaceNode } from 'structured-context/api';\nimport type { DagMode } from './definition';\nimport { childEdges, isHierarchyEdge, parentEdges } from './graph';\nimport { occurrenceKey } from './occurrence';\n\n/** One rendered appearance of a node in a tree. */\nexport type TreeOccurrence = {\n /** Path-based key, unique within the map view (see {@link occurrenceKey}). */\n key: string;\n node: SpaceNode;\n children: TreeOccurrence[];\n /**\n * Key of the node's primary occurrence when this is a repeat. A node with several parents\n * appears under each of them, but its subtree is only rendered at its first occurrence.\n */\n repeatOf?: string;\n};\n\nexport type Tree = {\n roots: TreeOccurrence[];\n /**\n * Hierarchy-typed nodes not reachable from a root, rendered as extra roots: nodes with no\n * hierarchy parent in the space, then entry points into otherwise unreachable cycles.\n */\n orphans: TreeOccurrence[];\n /** Key of each node's primary (first, fully rendered) occurrence. */\n primary: ReadonlyMap<string, string>;\n /**\n * In cross-edge mode, links from a node's other parents to its primary occurrence, which\n * replace repeat occurrences. Empty in repeat mode.\n */\n crossLinks: TreeLink[];\n};\n\nexport type TreeLink = { from: string; to: string; kind: 'tree' | 'cross' };\n\n/**\n * Lay a space out as a tree over its hierarchy.\n *\n * Roots are root-type nodes with no hierarchy parent. Traversal is depth-first in space order,\n * so a node's primary occurrence is under the parent reached first. Under its other parents a\n * node is either repeated without its subtree (`repeat`), or left out and linked by a cross-edge\n * (`cross-edge`). Either way traversal stops there, which also keeps cycles from recursing.\n */\nexport function buildTree(graph: SpaceGraph, regionId: string, dag: DagMode = 'repeat'): Tree {\n const { hierarchy } = graph;\n const levelTypes = new Set(hierarchy?.levels.map((level) => level.type));\n const rootType = hierarchy?.levels[0]?.type;\n const primary = new Map<string, string>();\n // Parent occurrence → child title, resolved to the child's primary occurrence afterwards.\n const pendingCross: { from: string; child: string }[] = [];\n\n const hierarchyParents = (title: SpaceNode['id']) =>\n parentEdges(graph, title).filter((edge) => isHierarchyEdge(edge, hierarchy));\n\n const visit = (node: SpaceNode, path: readonly string[]): TreeOccurrence => {\n const nodePath = [...path, node.id];\n const key = occurrenceKey(regionId, nodePath);\n primary.set(node.id, key);\n // A child can reference the same parent through more than one field; it occurs once.\n const childTitles = new Set(\n childEdges(graph, node.id)\n .filter((edge) => isHierarchyEdge(edge, hierarchy))\n .map((edge) => edge.child),\n );\n const children: TreeOccurrence[] = [];\n for (const title of childTitles) {\n const child = graph.nodes.get(title)!;\n const repeatOf = primary.get(title);\n if (repeatOf === undefined) children.push(visit(child, nodePath));\n else if (dag === 'repeat')\n children.push({ key: occurrenceKey(regionId, [...nodePath, title]), node: child, children: [], repeatOf });\n else pendingCross.push({ from: key, child: title });\n }\n return { key, node, children };\n };\n\n const levelNodes = [...graph.nodes.values()].filter((node) => levelTypes.has(node.resolvedType));\n const unparented = levelNodes.filter((node) => hierarchyParents(node.id).length === 0);\n const roots = unparented.filter((node) => node.resolvedType === rootType).map((node) => visit(node, []));\n const orphans = unparented.filter((node) => node.resolvedType !== rootType).map((node) => visit(node, []));\n // Nodes only reachable through a cycle have a parent but no path from a root. Rather than\n // drop them, enter each such cycle at its first node in space order.\n for (const node of levelNodes) {\n if (!primary.has(node.id)) orphans.push(visit(node, []));\n }\n\n const crossLinks = pendingCross.map(({ from, child }) => ({ from, to: primary.get(child)!, kind: 'cross' as const }));\n return { roots, orphans, primary, crossLinks };\n}\n\n/** Parent → child pairs of occurrence keys: one per rendered parent-child link, then cross-links. */\nexport function treeLinks(tree: Tree): TreeLink[] {\n const links: TreeLink[] = [];\n const walk = (occurrence: TreeOccurrence) => {\n for (const child of occurrence.children) {\n links.push({ from: occurrence.key, to: child.key, kind: 'tree' });\n walk(child);\n }\n };\n for (const root of [...tree.roots, ...tree.orphans]) walk(root);\n return [...links, ...tree.crossLinks];\n}\n","import type { SpaceGraph, SpaceNode } from 'structured-context/api';\nimport type { GroupLevel, LandscapeLayoutConfig } from './definition';\nimport { childEdges, parentEdges } from './graph';\nimport { occurrenceKey, type PathSegment } from './occurrence';\n\n/** One rendered container or node in a landscape. */\nexport type LandscapeOccurrence = {\n /** Path-based key, unique within the map view (see {@link occurrenceKey}). */\n key: string;\n /** Index of the grouping level this occurrence belongs to. */\n level: number;\n /** A node, or a field value shared by the nodes inside (`null`: the field is empty). */\n item: { kind: 'node'; node: SpaceNode } | { kind: 'value'; field: string; value: string | null };\n /** Nodes on the `via` chain that joined this node to the node level above, one entry per skipped type. */\n via: ViaStep[];\n /** Key of the node's first occurrence when this is a repeat. Repeats are rendered in full. */\n repeatOf?: string;\n children: LandscapeOccurrence[];\n};\n\nexport type ViaStep = { type: string; nodes: SpaceNode[] };\n\nexport type Landscape = {\n groups: LandscapeOccurrence[];\n /**\n * Nodes of a grouped level that no container above reaches (e.g. an Activity with no\n * Outcome when grouping by Outcomes), each with its own contents.\n */\n ungrouped: LandscapeOccurrence[];\n};\n\ntype Candidate = { node: SpaceNode; via: ViaStep[] };\ntype FieldFilter = { field: string; value: string | null };\n\n/**\n * Lay a space out as nested containers following the layout's grouping levels.\n *\n * Adjacent node levels are joined by any edge between their types, in either direction, or only\n * edges from `edge.field`. A `via` chain joins them through the skipped types. A field level\n * splits the next node level by that field's values. A node reached from several containers\n * appears in each, in full: the levels are finite, so repeating contents can't recurse.\n */\nexport function buildLandscape(graph: SpaceGraph, regionId: string, layout: LandscapeLayoutConfig): Landscape {\n const levels = layout.group;\n const order = new Map([...graph.nodes.keys()].map((title, i) => [title, i]));\n const first = new Map<string, string>();\n\n const occurrenceFor = (candidate: Candidate, levelIdx: number, path: readonly PathSegment[]): LandscapeOccurrence => {\n const { node } = candidate;\n const nodePath = [...path, node.id];\n const key = occurrenceKey(regionId, nodePath);\n const repeatOf = first.get(node.id);\n if (repeatOf === undefined) first.set(node.id, key);\n return {\n key,\n level: levelIdx,\n item: { kind: 'node', node },\n via: candidate.via,\n ...(repeatOf !== undefined && { repeatOf }),\n children: place(levelIdx + 1, node, [], nodePath),\n };\n };\n\n /** Occurrences for level `levelIdx` inside `anchor`, the nearest enclosing node. */\n const place = (\n levelIdx: number,\n anchor: SpaceNode | undefined,\n filters: readonly FieldFilter[],\n path: readonly PathSegment[],\n ): LandscapeOccurrence[] => {\n const level = levels[levelIdx];\n if (level === undefined) return [];\n if (isTypeLevel(level)) {\n return candidates(level, anchor, filters).map((c) => occurrenceFor(c, levelIdx, path));\n }\n\n const nodeLevel = levels.slice(levelIdx).find(isTypeLevel)!;\n const values = distinctValues(\n candidates(nodeLevel, anchor, filters).map((c) => c.node),\n level.field,\n );\n return values.map((value) => {\n const valuePath = [...path, [level.field, value] as const];\n return {\n key: occurrenceKey(regionId, valuePath),\n level: levelIdx,\n item: { kind: 'value', field: level.field, value },\n via: [],\n children: place(levelIdx + 1, anchor, [...filters, { field: level.field, value }], valuePath),\n };\n });\n };\n\n /** Nodes of a type level joined to `anchor` (all of the type at the top) and matching the filters. */\n const candidates = (\n level: TypeLevel,\n anchor: SpaceNode | undefined,\n filters: readonly FieldFilter[],\n ): Candidate[] => {\n const reached: Candidate[] =\n anchor === undefined\n ? ofType(level.type).map((node) => ({ node, via: [] }))\n : walkChain(anchor, level.via ?? [], level.type, level.edge?.field);\n return reached.filter(({ node }) => filters.every((f) => hasValue(node, f)));\n };\n\n const ofType = (type: string) => [...graph.nodes.values()].filter((node) => node.resolvedType === type);\n\n /** Neighbours of a node with the given type, across edges in either direction, in space order. */\n const neighbours = (title: SpaceNode['id'], type: string, field: string | undefined): SpaceNode[] => {\n const titles = new Set([\n ...childEdges(graph, title)\n .filter((e) => field === undefined || e.field === field)\n .map((e) => e.child),\n ...parentEdges(graph, title)\n .filter((e) => field === undefined || e.field === field)\n .map((e) => e.parent),\n ]);\n return [...titles]\n .map((t) => graph.nodes.get(t)!)\n .filter((node) => node.resolvedType === type)\n .sort((a, b) => order.get(a.id)! - order.get(b.id)!);\n };\n\n /**\n * Follow edges from `anchor` through each `via` type to `target`, keeping the skipped nodes on\n * the way to each target node. Several chains to one target merge into one candidate.\n */\n const walkChain = (anchor: SpaceNode, via: readonly string[], target: string, field: string | undefined) => {\n let frontier = [{ node: anchor, trail: [] as SpaceNode[] }];\n for (const type of via) {\n frontier = frontier.flatMap(({ node, trail }) =>\n neighbours(node.id, type, undefined).map((next) => ({ node: next, trail: [...trail, next] })),\n );\n }\n const byTitle = new Map<string, Candidate>();\n for (const { node, trail } of frontier) {\n for (const next of neighbours(node.id, target, field)) {\n const candidate = byTitle.get(next.id) ?? { node: next, via: via.map((type) => ({ type, nodes: [] })) };\n trail.forEach((skipped, i) => {\n const step = candidate.via[i]!;\n if (!step.nodes.includes(skipped)) step.nodes.push(skipped);\n });\n byTitle.set(next.id, candidate);\n }\n }\n return [...byTitle.values()].sort((a, b) => order.get(a.node.id)! - order.get(b.node.id)!);\n };\n\n const groups = place(0, undefined, [], []);\n\n // Nodes of an inner level that no container reached get their own contents, like tree orphans.\n const ungrouped: LandscapeOccurrence[] = [];\n levels.forEach((level, levelIdx) => {\n if (levelIdx === 0 || !isTypeLevel(level)) return;\n for (const node of ofType(level.type)) {\n if (!first.has(node.id)) ungrouped.push(occurrenceFor({ node, via: [] }, levelIdx, [null]));\n }\n });\n\n return { groups, ungrouped };\n}\n\ntype TypeLevel = Extract<GroupLevel, { type: string }>;\n\nfunction isTypeLevel(level: GroupLevel): level is TypeLevel {\n return 'type' in level;\n}\n\n/** A field's values as group labels: strings, an entry per array item, `null` when empty. */\nfunction valuesOf(node: SpaceNode, field: string): (string | null)[] {\n const raw = node.schemaData[field];\n const list = (Array.isArray(raw) ? raw : [raw]).filter((v) => v !== undefined && v !== null && v !== '');\n return list.length === 0 ? [null] : list.map((v) => (typeof v === 'object' ? JSON.stringify(v) : String(v)));\n}\n\n/** Distinct values in first-seen order, with the empty group last. */\nfunction distinctValues(nodes: SpaceNode[], field: string): (string | null)[] {\n const values = new Set(nodes.flatMap((node) => valuesOf(node, field)));\n const present = [...values].filter((v): v is string => v !== null);\n return values.has(null) ? [...present, null] : present;\n}\n\nfunction hasValue(node: SpaceNode, { field, value }: FieldFilter): boolean {\n return valuesOf(node, field).includes(value);\n}\n","import type { SpaceGraph, SpaceNode } from 'structured-context/api';\nimport type { AxisConfig, XYLayoutConfig } from './definition';\nimport { edgesWithin, isHierarchyEdge } from './graph';\nimport { occurrenceKey } from './occurrence';\n\n/** A plotted node. `x` and `y` run from 0 to 1 across the plot, left to right and bottom to top. */\nexport type XYPoint = { key: string; node: SpaceNode; x: number; y: number };\n\n/** Why a node of a plotted type couldn't be placed, per axis. */\nexport type Unplaced = { key: string; node: SpaceNode; reasons: string[] };\n\n/**\n * An edge between plotted nodes. `lane` separates edges joining the same two nodes: 0 when\n * there's one, otherwise centred around 0 (e.g. -0.5 and 0.5), for layouts to draw side by side.\n */\nexport type XYLink = { from: string; to: string; field: string; hierarchy: boolean; lane: number };\n\nexport type XYPlot = {\n points: XYPoint[];\n unplaced: Unplaced[];\n /** Edges between plotted nodes. */\n links: XYLink[];\n /** Each axis's [min, max]; `direction` says which end is drawn where. */\n domains: { x: readonly [number, number]; y: readonly [number, number] };\n};\n\n/**\n * Position nodes by two numeric fields. Every node of a plotted type appears once: on the plot\n * when both its values are numbers inside the axes' domains, otherwise in `unplaced` with the\n * reason. Positions are normalised; layouts decide the plot's size.\n */\nexport function buildXYPlot(graph: SpaceGraph, regionId: string, layout: XYLayoutConfig): XYPlot {\n const { x, y } = layout;\n const nodes = [...graph.nodes.values()];\n const types = new Set(\n layout.types.length > 0\n ? layout.types\n : nodes\n .filter((n) => isNumber(n.schemaData[x.field]) || isNumber(n.schemaData[y.field]))\n .map((n) => n.resolvedType),\n );\n const plotted = nodes.filter((n) => types.has(n.resolvedType));\n\n const domains = {\n x: domainOf(x, plotted),\n y: domainOf(y, plotted),\n };\n\n const points: XYPoint[] = [];\n const unplaced: Unplaced[] = [];\n for (const node of plotted) {\n const key = occurrenceKey(regionId, [node.id]);\n const px = position(node, x, domains.x);\n const py = position(node, y, domains.y);\n if (typeof px === 'number' && typeof py === 'number') points.push({ key, node, x: px, y: py });\n else unplaced.push({ key, node, reasons: [px, py].filter((r): r is string => typeof r === 'string') });\n }\n\n const keys = new Map<string, string>(points.map((p) => [p.node.id, p.key]));\n const fields = new Set(layout.edgeFields);\n const links = edgesWithin(graph)\n .filter((e) => keys.has(e.parent) && keys.has(e.child) && (fields.size === 0 || fields.has(e.field)))\n .map((e) => ({\n from: keys.get(e.parent)!,\n to: keys.get(e.child)!,\n field: e.field,\n hierarchy: isHierarchyEdge(e, graph.hierarchy),\n lane: 0,\n }));\n assignLanes(links);\n\n return { points, unplaced, links, domains };\n}\n\nfunction isNumber(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value);\n}\n\n/** The axis's fixed domain, or the range of plotted values (widened when they're all equal). */\nfunction domainOf(axis: AxisConfig, nodes: readonly SpaceNode[]): readonly [number, number] {\n if (Array.isArray(axis.domain)) return [axis.domain[0]!, axis.domain[1]!];\n const values = nodes.map((n) => n.schemaData[axis.field]).filter(isNumber);\n if (values.length === 0) return [0, 1];\n const min = Math.min(...values);\n const max = Math.max(...values);\n return min === max ? [min - 1, max + 1] : [min, max];\n}\n\n/** The node's normalised position on the axis, or why it has none. */\nfunction position(node: SpaceNode, axis: AxisConfig, [min, max]: readonly [number, number]): number | string {\n const value = node.schemaData[axis.field];\n if (value === undefined || value === null) return `no ${axis.field}`;\n if (!isNumber(value)) return `${axis.field} is not a number`;\n if (value < min || value > max) return `${axis.field} ${value} is outside ${min}–${max}`;\n const t = (value - min) / (max - min);\n return axis.direction === 'descending' ? 1 - t : t;\n}\n\n/** Spread links joining the same pair of nodes (in either direction) into lanes around 0. */\nfunction assignLanes(links: XYLink[]) {\n const byPair = new Map<string, XYLink[]>();\n for (const link of links) {\n const pair = [link.from, link.to].sort().join('\\n');\n byPair.set(pair, [...(byPair.get(pair) ?? []), link]);\n }\n for (const group of byPair.values()) {\n group.forEach((link, i) => {\n link.lane = i - (group.length - 1) / 2;\n });\n }\n}\n"],"mappings":";;;;;;AA8CA,SAAgB,gBACd,OACA,OACsE;CACtE,MAAM,8BAAc,IAAI,IAA8B;CACtD,MAAM,aAAqC,CAAC;CAC5C,MAAM,OAAO,QAA4B,YAA4B,aAA8B;EACjG,IAAI,WAAW,KAAA,KAAa,MAAM,MAAM,IAAI,MAAM,GAChD,YAAY,IAAI,QAAQ,CAAC,GAAI,YAAY,IAAI,MAAM,KAAK,CAAC,GAAI,UAAU,CAAC;OAExE,WAAW,KAAK;GAAE,GAAG;GAAY;GAAQ,GAAI,YAAY,EAAE,SAAS;EAAG,CAAC;CAE5E;CAEA,KAAK,MAAM,EAAE,QAAQ,QAAQ,YAAY,MAAM,cAAc,CAAC,GAC5D,KAAK,MAAM,SAAS,QAClB,IAAI,QAAQ;EAAE,UAAU;EAAS,QAAQ;EAAU,SAAS,MAAM;CAAQ,GAAG,MAAM;CAGvF,KAAK,MAAM,EAAE,QAAQ,iBAAiB,MAAM,uBA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,GAAG,CAAC;CACrC,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAC9B,MAAM,MAAM,KAAK,IAAI,GAAG,MAAM;CAC9B,OAAO,QAAQ,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG;AACrD;;AAGA,SAAS,SAAS,MAAiB,MAAkB,CAAC,KAAK,MAAkD;CAC3G,MAAM,QAAQ,KAAK,WAAW,KAAK;CACnC,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM,OAAO,MAAM,KAAK;CAC7D,IAAI,CAAC,SAAS,KAAK,GAAG,OAAO,GAAG,KAAK,MAAM;CAC3C,IAAI,QAAQ,OAAO,QAAQ,KAAK,OAAO,GAAG,KAAK,MAAM,GAAG,MAAM,cAAc,IAAI,GAAG;CACnF,MAAM,KAAK,QAAQ,QAAQ,MAAM;CACjC,OAAO,KAAK,cAAc,eAAe,IAAI,IAAI;AACnD;;AAGA,SAAS,YAAY,OAAiB;CACpC,MAAM,yBAAS,IAAI,IAAsB;CACzC,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,OAAO,CAAC,KAAK,MAAM,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI;EAClD,OAAO,IAAI,MAAM,CAAC,GAAI,OAAO,IAAI,IAAI,KAAK,CAAC,GAAI,IAAI,CAAC;CACtD;CACA,KAAK,MAAM,SAAS,OAAO,OAAO,GAChC,MAAM,SAAS,MAAM,MAAM;EACzB,KAAK,OAAO,KAAK,MAAM,SAAS,KAAK;CACvC,CAAC;AAEL"}
@@ -1,9 +1,10 @@
1
1
  /**
2
- * The package's public surface. Everything else (layouts, node cards, the edge overlay, the projections)
2
+ * The package's public surface. Everything else (layouts, node cards, the edge overlay, the other projections)
3
3
  * is internal; add an export here when a host needs it.
4
4
  */
5
5
  export { type AnnotationIndex, type AnnotationSource, annotationsFrom, type NodeAnnotation, type Severity, type UnattachedAnnotation, type ValidationInput, worstSeverity, } from './core/annotations';
6
6
  export { MAP_VIEW_SCHEMAS, type MapViewDefinition, MapViewDefinitionError, mapViewsForSchema, type Parameter, type ParameterControl, type ParameterValues, parseMapViewDefinition, resolveParameterValues, selectionFilter, viewValidationLevel, } from './core/definition';
7
+ export { buildTree, type Tree, type TreeOccurrence } from './core/tree';
7
8
  export { MapView } from './layouts/MapView';
8
9
  export { ParameterControls } from './layouts/ParameterControls';
9
10
  export { MultiSelectParameterInput, ParameterInput, SelectParameterInput, ToggleParameterInput, } from './layouts/ParameterInputs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "structured-context-map-views",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.",
5
5
  "license": "MIT",
6
6
  "type": "module",