@standarx/graph 0.0.0-stage → 1.1.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.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.fr.md +438 -0
  3. package/README.md +437 -2
  4. package/THIRD_PARTY_NOTICES.md +22 -0
  5. package/assets/fonts/Inter-Regular.ttf +0 -0
  6. package/assets/fonts/Inter-SemiBold.ttf +0 -0
  7. package/assets/fonts/OFL.txt +92 -0
  8. package/dist/adapter-0bggwh8x.js +393 -0
  9. package/dist/cli-4m00785g.js +20 -0
  10. package/dist/cli-5v9761s9.js +330 -0
  11. package/dist/cli-9f1pdw5q.js +462 -0
  12. package/dist/cli-a4ax1vkc.js +172 -0
  13. package/dist/cli-abzdy8pn.js +1144 -0
  14. package/dist/cli-gh5166k6.js +1565 -0
  15. package/dist/cli-m29a3wgx.js +579 -0
  16. package/dist/cli-mzmjkk5v.js +11 -0
  17. package/dist/cli-nhmh6yxk.js +2485 -0
  18. package/dist/cli-nyckgf1t.js +4 -0
  19. package/dist/cli-sfdqkbd1.js +433 -0
  20. package/dist/cli-txrzzr2q.js +0 -0
  21. package/dist/cli-vecew2na.js +709 -0
  22. package/dist/cli-wt9dmbhm.js +560 -0
  23. package/dist/cli-ywgtv1cg.js +39 -0
  24. package/dist/cli-z3ccx2y4.js +141 -0
  25. package/dist/cli.d.ts +2 -0
  26. package/dist/cli.js +413 -0
  27. package/dist/core/index.d.ts +6 -0
  28. package/dist/core/index.js +91 -0
  29. package/dist/core/spatial.d.ts +16 -0
  30. package/dist/core/threshold.d.ts +1 -0
  31. package/dist/core/view.d.ts +80 -0
  32. package/dist/export/index.d.ts +18 -0
  33. package/dist/export/index.js +170 -0
  34. package/dist/export/pdf.d.ts +5 -0
  35. package/dist/export/png.d.ts +4 -0
  36. package/dist/format/index.d.ts +4 -0
  37. package/dist/format/index.js +69 -0
  38. package/dist/format/json-schema.d.ts +2 -0
  39. package/dist/format/schema.d.ts +787 -0
  40. package/dist/format/semantic/er.d.ts +3 -0
  41. package/dist/format/semantic/graph.d.ts +3 -0
  42. package/dist/format/semantic/sequence.d.ts +3 -0
  43. package/dist/format/semantic/shared.d.ts +14 -0
  44. package/dist/format/semantic/state.d.ts +3 -0
  45. package/dist/format/semantic/tree.d.ts +3 -0
  46. package/dist/format/transition-label.d.ts +2 -0
  47. package/dist/format/validate.d.ts +11 -0
  48. package/dist/html/index.d.ts +3 -0
  49. package/dist/html/index.js +125 -0
  50. package/dist/html/layout-worker.d.ts +1 -0
  51. package/dist/html/layout-worker.generated.d.ts +1 -0
  52. package/dist/html/mount.d.ts +12 -0
  53. package/dist/html/page.d.ts +14 -0
  54. package/dist/html/render.d.ts +7 -0
  55. package/dist/html/runtime.d.ts +1 -0
  56. package/dist/html/runtime.generated.d.ts +1 -0
  57. package/dist/html/shell.d.ts +10 -0
  58. package/dist/html/svg-adapter.d.ts +8 -0
  59. package/dist/html/ui.d.ts +34 -0
  60. package/dist/language/actions.d.ts +3 -0
  61. package/dist/language/analysis.d.ts +38 -0
  62. package/dist/language/complete.d.ts +3 -0
  63. package/dist/language/diagnostics.d.ts +14 -0
  64. package/dist/language/docs.d.ts +11 -0
  65. package/dist/language/format.d.ts +17 -0
  66. package/dist/language/hover.d.ts +3 -0
  67. package/dist/language/index.d.ts +8 -0
  68. package/dist/language/index.js +1560 -0
  69. package/dist/language/navigation.d.ts +9 -0
  70. package/dist/language/positions.d.ts +7 -0
  71. package/dist/language/symbols.d.ts +3 -0
  72. package/dist/language/types.d.ts +46 -0
  73. package/dist/layout/elk.d.ts +35 -0
  74. package/dist/layout/er.d.ts +3 -0
  75. package/dist/layout/font-metrics.d.ts +9 -0
  76. package/dist/layout/graph.d.ts +3 -0
  77. package/dist/layout/index.d.ts +5 -0
  78. package/dist/layout/index.js +16 -0
  79. package/dist/layout/measure.d.ts +10 -0
  80. package/dist/layout/sequence.d.ts +3 -0
  81. package/dist/layout/shapes.d.ts +16 -0
  82. package/dist/layout/shared.d.ts +31 -0
  83. package/dist/layout/state.d.ts +3 -0
  84. package/dist/layout/tree.d.ts +3 -0
  85. package/dist/layout/types.d.ts +198 -0
  86. package/dist/layout-worker.generated-xsmtzrfj.js +34 -0
  87. package/dist/mermaid/common.d.ts +36 -0
  88. package/dist/mermaid/er.d.ts +3 -0
  89. package/dist/mermaid/graph.d.ts +4 -0
  90. package/dist/mermaid/index.d.ts +6 -0
  91. package/dist/mermaid/index.js +6 -0
  92. package/dist/mermaid/mindmap.d.ts +3 -0
  93. package/dist/mermaid/sequence.d.ts +3 -0
  94. package/dist/mermaid/state.d.ts +3 -0
  95. package/dist/remark/index.d.ts +9 -0
  96. package/dist/remark/index.js +102 -0
  97. package/dist/shared/errors.d.ts +6 -0
  98. package/dist/shared/package-root.d.ts +5 -0
  99. package/dist/svg/escape.d.ts +1 -0
  100. package/dist/svg/index.d.ts +3 -0
  101. package/dist/svg/index.js +25 -0
  102. package/dist/svg/render.d.ts +9 -0
  103. package/dist/svg/theme.d.ts +62 -0
  104. package/dist/svg-adapter-gq5vmp6q.js +227 -0
  105. package/dist/text/build.d.ts +10 -0
  106. package/dist/text/canonical.d.ts +10 -0
  107. package/dist/text/errors.d.ts +33 -0
  108. package/dist/text/highlight.d.ts +13 -0
  109. package/dist/text/index.d.ts +33 -0
  110. package/dist/text/index.js +25 -0
  111. package/dist/text/lexer.d.ts +29 -0
  112. package/dist/text/parser.d.ts +160 -0
  113. package/dist/text/print.d.ts +6 -0
  114. package/dist/text/slug.d.ts +1 -0
  115. package/dist/text/syntax.d.ts +8 -0
  116. package/dist/version.d.ts +1 -0
  117. package/dist/webgl/adapter.d.ts +4 -0
  118. package/dist/webgl/index.d.ts +7 -0
  119. package/dist/webgl/index.js +15 -0
  120. package/dist/webgl/runtime.d.ts +1 -0
  121. package/dist/webgl/runtime.generated.d.ts +1 -0
  122. package/grammars/standargraph.tmLanguage.json +599 -0
  123. package/language-configuration.json +35 -0
  124. package/licenses/EPL-2.0.txt +277 -0
  125. package/licenses/MPL-2.0.txt +373 -0
  126. package/package.json +133 -4
  127. package/schema/graph-document.v1.json +1737 -0
@@ -0,0 +1,141 @@
1
+ // package.json
2
+ var package_default = {
3
+ name: "@standarx/graph",
4
+ version: "1.1.0",
5
+ type: "module",
6
+ license: "MIT",
7
+ description: "Declarative graph and diagram rendering",
8
+ keywords: [
9
+ "graph",
10
+ "diagram",
11
+ "svg",
12
+ "webgl",
13
+ "elk",
14
+ "sequence-diagram",
15
+ "visualization",
16
+ "cli",
17
+ "remark"
18
+ ],
19
+ homepage: "https://github.com/miralabs-tech/standargraph#readme",
20
+ bugs: {
21
+ url: "https://github.com/miralabs-tech/standargraph/issues"
22
+ },
23
+ repository: {
24
+ type: "git",
25
+ url: "git+https://github.com/miralabs-tech/standargraph.git"
26
+ },
27
+ bin: {
28
+ standargraph: "dist/cli.js"
29
+ },
30
+ exports: {
31
+ "./core": {
32
+ types: "./dist/core/index.d.ts",
33
+ import: "./dist/core/index.js"
34
+ },
35
+ "./format": {
36
+ types: "./dist/format/index.d.ts",
37
+ import: "./dist/format/index.js"
38
+ },
39
+ "./layout": {
40
+ types: "./dist/layout/index.d.ts",
41
+ import: "./dist/layout/index.js"
42
+ },
43
+ "./svg": {
44
+ types: "./dist/svg/index.d.ts",
45
+ import: "./dist/svg/index.js"
46
+ },
47
+ "./html": {
48
+ types: "./dist/html/index.d.ts",
49
+ import: "./dist/html/index.js"
50
+ },
51
+ "./export": {
52
+ types: "./dist/export/index.d.ts",
53
+ import: "./dist/export/index.js"
54
+ },
55
+ "./webgl": {
56
+ types: "./dist/webgl/index.d.ts",
57
+ import: "./dist/webgl/index.js"
58
+ },
59
+ "./remark": {
60
+ types: "./dist/remark/index.d.ts",
61
+ import: "./dist/remark/index.js"
62
+ },
63
+ "./mermaid": {
64
+ types: "./dist/mermaid/index.d.ts",
65
+ import: "./dist/mermaid/index.js"
66
+ },
67
+ "./text": {
68
+ types: "./dist/text/index.d.ts",
69
+ import: "./dist/text/index.js"
70
+ },
71
+ "./language": {
72
+ types: "./dist/language/index.d.ts",
73
+ import: "./dist/language/index.js"
74
+ },
75
+ "./schema/graph-document.v1.json": "./schema/graph-document.v1.json",
76
+ "./grammars/standargraph.tmLanguage.json": "./grammars/standargraph.tmLanguage.json",
77
+ "./language-configuration.json": "./language-configuration.json",
78
+ "./package.json": "./package.json"
79
+ },
80
+ files: [
81
+ "dist",
82
+ "schema",
83
+ "grammars",
84
+ "language-configuration.json",
85
+ "assets",
86
+ "licenses",
87
+ "THIRD_PARTY_NOTICES.md"
88
+ ],
89
+ engines: {
90
+ node: ">=20"
91
+ },
92
+ scripts: {
93
+ build: "bun scripts/clean.ts && bun build src/cli.ts src/core/index.ts src/format/index.ts src/layout/index.ts src/svg/index.ts src/webgl/index.ts src/remark/index.ts src/html/index.ts src/export/index.ts src/text/index.ts src/language/index.ts src/mermaid/index.ts --root src --outdir dist --splitting --target node --format esm --packages external && tsc -p tsconfig.build.json",
94
+ typecheck: "tsc --noEmit",
95
+ schema: "bun scripts/schema.ts",
96
+ metrics: "bun scripts/font-metrics.ts",
97
+ runtime: "bun scripts/build-runtime.ts",
98
+ generate: "bun scripts/generate.ts",
99
+ bench: "bun bench/run.ts",
100
+ test: "bun test",
101
+ prepublishOnly: "bun run typecheck && bun test && bun run build",
102
+ smoke: "bun tools/smoke.ts",
103
+ site: "bun scripts/site.ts",
104
+ "test:browser": "bun test --config=bunfig.browser.toml tests/browser"
105
+ },
106
+ devDependencies: {
107
+ "@types/bun": "^1.4.4",
108
+ "@types/mdast": "^4.0.4",
109
+ "@types/node": "^26.6.6",
110
+ "@types/opentype.js": "^1.3.10",
111
+ "@types/pdfkit": "^0.17.7",
112
+ "opentype.js": "^2.0.0",
113
+ "playwright-core": "^1.65.1",
114
+ "rehype-raw": "^7.0.0",
115
+ "rehype-stringify": "^10.0.1",
116
+ "remark-parse": "^11.0.0",
117
+ "remark-rehype": "^11.1.2",
118
+ typescript: "^7.0.2",
119
+ unified: "^11.0.5",
120
+ "vscode-oniguruma": "^2.0.1",
121
+ "vscode-textmate": "^9.3.2"
122
+ },
123
+ dependencies: {
124
+ "@resvg/resvg-wasm": "^2.6.2",
125
+ "@sinclair/typebox": "^0.34.52",
126
+ elkjs: "^0.12.1",
127
+ graphology: "^0.26.0",
128
+ pdfkit: "^0.20.2",
129
+ sigma: "^4.0.6",
130
+ "svg-to-pdfkit": "^0.1.8"
131
+ },
132
+ publishConfig: {
133
+ access: "public",
134
+ provenance: true
135
+ }
136
+ };
137
+
138
+ // src/version.ts
139
+ var VERSION2 = package_default.version;
140
+
141
+ export { VERSION2 };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function run(argv: string[]): number | Promise<number>;
package/dist/cli.js ADDED
@@ -0,0 +1,413 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ THEME_NAMES2,
4
+ THEMES2,
5
+ isThemeName,
6
+ withoutPalette
7
+ } from "./cli-5v9761s9.js";
8
+ import"./cli-m29a3wgx.js";
9
+ import {
10
+ print2,
11
+ loadSource2
12
+ } from "./cli-nhmh6yxk.js";
13
+ import {
14
+ VERSION2
15
+ } from "./cli-z3ccx2y4.js";
16
+ import {
17
+ formatLoadErrors
18
+ } from "./cli-4m00785g.js";
19
+
20
+ // src/cli.ts
21
+ import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
22
+ import { basename, dirname, extname, join, resolve } from "node:path";
23
+ import { fileURLToPath } from "node:url";
24
+ var USAGE = `Usage: standargraph <command> [options]
25
+
26
+ Commands:
27
+ validate <file> Validate a document (JSON or text syntax) against format v1
28
+ export <file> Export a document to SVG, HTML, PNG, PDF or Mermaid
29
+ layout <file> Write the graph document with every node position computed (JSON)
30
+ convert <file> Convert a document between JSON and the text syntax
31
+
32
+ Convert options:
33
+ --to <format> json or text (default: the other format than the input)
34
+ --out <file> Output file (default: <input base>.json or .sg next to the input)
35
+
36
+ Layout options:
37
+ --out <file> Output file (default: <input>.positioned.json next to the input)
38
+
39
+ Export options:
40
+ --format <list> Comma-separated formats: svg, html, png, pdf, mermaid (default: svg,html)
41
+ --out <dir> Output directory (default: the input file directory)
42
+ --name <base> Output base name (default: the input file name without .json or .sg)
43
+ --theme <theme> auto, a palette name (light, dark, nord, solarized-light, solarized-dark, high-contrast) or a theme file ending in .json (default: auto)
44
+ --no-palette Turn off the automatic color per item type
45
+ --scale <n> PNG scale factor (default: 2)
46
+ --renderer <name> HTML renderer: auto, svg or webgl (default: auto)
47
+ --markdown Print a Markdown snippet linking the SVG preview to the HTML page, then the Mermaid code block when mermaid is exported
48
+
49
+ Options:
50
+ -v, --version Print the version
51
+ -h, --help Show this help
52
+ `;
53
+ function readDocument(file) {
54
+ let source;
55
+ try {
56
+ source = readFileSync(file, "utf8");
57
+ } catch (error) {
58
+ const reason = error instanceof Error ? error.message : String(error);
59
+ process.stderr.write(`Cannot read ${file}: ${reason}
60
+ `);
61
+ return 2;
62
+ }
63
+ const loaded = loadSource2(source);
64
+ if (loaded.ok)
65
+ return { document: loaded.document, format: loaded.format };
66
+ if (loaded.format === "json" && loaded.errors[0]?.path === undefined) {
67
+ process.stderr.write(`Cannot read ${file}: ${loaded.errors[0]?.message}
68
+ `);
69
+ return 2;
70
+ }
71
+ process.stderr.write(`${formatLoadErrors(loaded.errors, file)}
72
+ `);
73
+ return 1;
74
+ }
75
+ function baseName(file) {
76
+ const extension = extname(file);
77
+ return basename(file, extension === ".json" || extension === ".sg" ? extension : "");
78
+ }
79
+ function runValidate(file) {
80
+ if (file === undefined) {
81
+ process.stderr.write(`Usage: standargraph validate <file>
82
+ `);
83
+ return 2;
84
+ }
85
+ const read = readDocument(file);
86
+ if (typeof read === "number")
87
+ return read;
88
+ process.stdout.write(`valid: ${file}
89
+ `);
90
+ return 0;
91
+ }
92
+ var FORMATS = ["svg", "html", "png", "pdf", "mermaid"];
93
+ function fail(message) {
94
+ process.stderr.write(`${message}
95
+ `);
96
+ return;
97
+ }
98
+ function isRecord(value) {
99
+ return typeof value === "object" && value !== null && !Array.isArray(value);
100
+ }
101
+ function isStrings(value, keys) {
102
+ return isRecord(value) && Object.entries(value).every(([key, item]) => keys.includes(key) && typeof item === "string");
103
+ }
104
+ function isTheme(value) {
105
+ if (!isRecord(value))
106
+ return false;
107
+ const { base, tokens, types, palette } = value;
108
+ if (base !== undefined && !isThemeName(base))
109
+ return false;
110
+ if (palette !== undefined && palette !== false)
111
+ return false;
112
+ if (tokens !== undefined && !isStrings(tokens, Object.keys(THEMES2.light)))
113
+ return false;
114
+ if (types === undefined)
115
+ return true;
116
+ return isRecord(types) && Object.values(types).every((style) => isStrings(style, ["fill", "stroke", "text"]));
117
+ }
118
+ function readTheme(file) {
119
+ let value;
120
+ try {
121
+ value = JSON.parse(readFileSync(file, "utf8"));
122
+ } catch (error) {
123
+ const reason = error instanceof Error ? error.message : String(error);
124
+ return fail(`Cannot read theme ${file}: ${reason}`);
125
+ }
126
+ const valid = isRecord(value) && "light" in value && "dark" in value ? isTheme(value.light) && isTheme(value.dark) : isTheme(value);
127
+ return valid ? value : fail(`Invalid theme file: ${file}`);
128
+ }
129
+ function parseExportArgs(args) {
130
+ const values = new Map;
131
+ const valued = new Set(["--format", "--out", "--name", "--theme", "--scale", "--renderer"]);
132
+ let markdown = false;
133
+ let palette = true;
134
+ let file;
135
+ for (let index = 0;index < args.length; index++) {
136
+ const arg = args[index];
137
+ if (!arg.startsWith("--")) {
138
+ if (file !== undefined)
139
+ return fail(`Unexpected argument: ${arg}`);
140
+ file = arg;
141
+ continue;
142
+ }
143
+ const equals = arg.indexOf("=");
144
+ const flag = equals === -1 ? arg : arg.slice(0, equals);
145
+ if (flag === "--markdown" && equals === -1) {
146
+ markdown = true;
147
+ } else if (flag === "--no-palette" && equals === -1) {
148
+ palette = false;
149
+ } else if (valued.has(flag)) {
150
+ const value = equals === -1 ? args[++index] : arg.slice(equals + 1);
151
+ if (value === undefined)
152
+ return fail(`Missing value for ${flag}`);
153
+ values.set(flag, value);
154
+ } else {
155
+ return fail(`Unknown option: ${arg}`);
156
+ }
157
+ }
158
+ if (file === undefined) {
159
+ return fail(`Usage: standargraph export <file> [--format svg,html,png,pdf,mermaid] [--out <dir>] [--name <base>] [--theme auto|${THEME_NAMES2.join("|")}|<file.json>] [--no-palette] [--scale <n>] [--renderer auto|svg|webgl] [--markdown]`);
160
+ }
161
+ const formats = [];
162
+ for (const item of (values.get("--format") ?? "svg,html").split(",")) {
163
+ const format = item.trim();
164
+ if (!FORMATS.includes(format)) {
165
+ return fail(`Unknown format: ${format}`);
166
+ }
167
+ if (!formats.includes(format))
168
+ formats.push(format);
169
+ }
170
+ const themeValue = values.get("--theme") ?? "auto";
171
+ let theme;
172
+ if (themeValue.endsWith(".json")) {
173
+ theme = readTheme(themeValue);
174
+ if (theme === undefined)
175
+ return;
176
+ } else if (themeValue === "auto" || isThemeName(themeValue)) {
177
+ theme = themeValue;
178
+ } else {
179
+ return fail(`Unknown theme: ${themeValue}`);
180
+ }
181
+ const renderer = values.get("--renderer") ?? "auto";
182
+ if (renderer !== "auto" && renderer !== "svg" && renderer !== "webgl") {
183
+ return fail(`Unknown renderer: ${renderer}`);
184
+ }
185
+ const scaleText = values.get("--scale");
186
+ let scale;
187
+ if (scaleText !== undefined) {
188
+ scale = Number(scaleText);
189
+ if (!Number.isFinite(scale) || scale <= 0)
190
+ return fail(`Invalid scale: ${scaleText}`);
191
+ }
192
+ return {
193
+ file,
194
+ formats,
195
+ out: values.get("--out"),
196
+ name: values.get("--name"),
197
+ theme,
198
+ scale,
199
+ renderer,
200
+ markdown,
201
+ palette
202
+ };
203
+ }
204
+ async function runExport(args) {
205
+ const parsed = parseExportArgs(args);
206
+ if (parsed === undefined)
207
+ return 2;
208
+ const read = readDocument(parsed.file);
209
+ if (typeof read === "number")
210
+ return read;
211
+ const document = read.document;
212
+ const base = parsed.name ?? baseName(parsed.file);
213
+ const directory = parsed.out ?? dirname(parsed.file);
214
+ const rendered = parsed.formats.filter((format) => format !== "mermaid");
215
+ let output = {};
216
+ if (rendered.length > 0) {
217
+ const { exportDocument } = await import("./export/index.js");
218
+ output = await exportDocument(document, {
219
+ formats: rendered,
220
+ theme: parsed.palette ? parsed.theme : withoutPalette(parsed.theme),
221
+ scale: parsed.scale,
222
+ renderer: parsed.renderer
223
+ });
224
+ }
225
+ if (rendered.length < parsed.formats.length) {
226
+ const { toMermaid } = await import("./mermaid/index.js");
227
+ const result = toMermaid(document);
228
+ for (const warning of result.warnings)
229
+ process.stderr.write(`warning: ${warning}
230
+ `);
231
+ output.mermaid = result.text;
232
+ }
233
+ try {
234
+ mkdirSync(directory, { recursive: true });
235
+ for (const format of parsed.formats) {
236
+ const data = output[format];
237
+ if (data === undefined)
238
+ continue;
239
+ const target = join(directory, `${base}.${format === "mermaid" ? "mmd" : format}`);
240
+ writeFileSync(target, data);
241
+ process.stdout.write(`wrote ${target}
242
+ `);
243
+ }
244
+ } catch (error) {
245
+ const reason = error instanceof Error ? error.message : String(error);
246
+ process.stderr.write(`Cannot write to ${directory}: ${reason}
247
+ `);
248
+ return 2;
249
+ }
250
+ if (parsed.markdown) {
251
+ const title = document.title ?? base;
252
+ process.stdout.write(`[![${title}](${base}.svg)](${base}.html)
253
+ `);
254
+ if (output.mermaid !== undefined) {
255
+ process.stdout.write(`\`\`\`mermaid
256
+ ${output.mermaid}\`\`\`
257
+ `);
258
+ }
259
+ }
260
+ return 0;
261
+ }
262
+ async function runLayout(args) {
263
+ let file;
264
+ let out;
265
+ for (let index = 0;index < args.length; index++) {
266
+ const arg = args[index];
267
+ if (arg === "--out") {
268
+ out = args[++index];
269
+ if (out === undefined)
270
+ return fail("Missing value for --out") ?? 2;
271
+ } else if (arg.startsWith("--out=")) {
272
+ out = arg.slice("--out=".length);
273
+ } else if (arg.startsWith("--")) {
274
+ return fail(`Unknown option: ${arg}`) ?? 2;
275
+ } else if (file === undefined) {
276
+ file = arg;
277
+ } else {
278
+ return fail(`Unexpected argument: ${arg}`) ?? 2;
279
+ }
280
+ }
281
+ if (file === undefined)
282
+ return fail("Usage: standargraph layout <file> [--out <file>]") ?? 2;
283
+ const read = readDocument(file);
284
+ if (typeof read === "number")
285
+ return read;
286
+ const document = read.document;
287
+ if (document.kind !== "graph") {
288
+ process.stderr.write(`Only graph documents carry node positions
289
+ `);
290
+ return 1;
291
+ }
292
+ const { layout } = await import("./layout/index.js");
293
+ const scene = await layout(document);
294
+ if (scene.kind !== "graph")
295
+ return 1;
296
+ const placed = new Map(scene.nodes.map((node) => [node.id, node]));
297
+ const positioned = {
298
+ ...document,
299
+ nodes: document.nodes.map((node) => {
300
+ const item = placed.get(node.id);
301
+ return item === undefined ? node : { ...node, position: { x: item.x, y: item.y } };
302
+ })
303
+ };
304
+ const target = out ?? join(dirname(file), `${baseName(file)}.positioned.json`);
305
+ try {
306
+ mkdirSync(dirname(target), { recursive: true });
307
+ writeFileSync(target, `${JSON.stringify(positioned, null, 2)}
308
+ `);
309
+ } catch (error) {
310
+ const reason = error instanceof Error ? error.message : String(error);
311
+ process.stderr.write(`Cannot write ${target}: ${reason}
312
+ `);
313
+ return 2;
314
+ }
315
+ process.stdout.write(`wrote ${target}
316
+ `);
317
+ return 0;
318
+ }
319
+ function runConvert(args) {
320
+ let file;
321
+ let out;
322
+ let to;
323
+ for (let index = 0;index < args.length; index++) {
324
+ const arg = args[index];
325
+ const equals = arg.indexOf("=");
326
+ const flag = equals === -1 ? arg : arg.slice(0, equals);
327
+ if (flag === "--out" || flag === "--to") {
328
+ const value = equals === -1 ? args[++index] : arg.slice(equals + 1);
329
+ if (value === undefined)
330
+ return fail(`Missing value for ${flag}`) ?? 2;
331
+ if (flag === "--out")
332
+ out = value;
333
+ else
334
+ to = value;
335
+ } else if (arg.startsWith("--")) {
336
+ return fail(`Unknown option: ${arg}`) ?? 2;
337
+ } else if (file === undefined) {
338
+ file = arg;
339
+ } else {
340
+ return fail(`Unexpected argument: ${arg}`) ?? 2;
341
+ }
342
+ }
343
+ if (file === undefined) {
344
+ return fail("Usage: standargraph convert <file> [--to json|text] [--out <file>]") ?? 2;
345
+ }
346
+ if (to !== undefined && to !== "json" && to !== "text") {
347
+ return fail(`Unknown format: ${to}`) ?? 2;
348
+ }
349
+ const read = readDocument(file);
350
+ if (typeof read === "number")
351
+ return read;
352
+ const target = to ?? (read.format === "json" ? "text" : "json");
353
+ const output = out ?? join(dirname(file), `${baseName(file)}.${target === "json" ? "json" : "sg"}`);
354
+ if (resolve(output) === resolve(file)) {
355
+ return fail("Output would overwrite the input") ?? 2;
356
+ }
357
+ try {
358
+ mkdirSync(dirname(output), { recursive: true });
359
+ writeFileSync(output, target === "json" ? `${JSON.stringify(read.document, null, 2)}
360
+ ` : print2(read.document));
361
+ } catch (error) {
362
+ const reason = error instanceof Error ? error.message : String(error);
363
+ process.stderr.write(`Cannot write ${output}: ${reason}
364
+ `);
365
+ return 2;
366
+ }
367
+ process.stdout.write(`wrote ${output}
368
+ `);
369
+ return 0;
370
+ }
371
+ function run(argv) {
372
+ const [command, ...rest] = argv;
373
+ if (command === undefined || command === "--help" || command === "-h") {
374
+ process.stdout.write(USAGE);
375
+ return 0;
376
+ }
377
+ if (command === "--version" || command === "-v") {
378
+ process.stdout.write(`${VERSION2}
379
+ `);
380
+ return 0;
381
+ }
382
+ if (command === "validate") {
383
+ return runValidate(rest[0]);
384
+ }
385
+ if (command === "export") {
386
+ return runExport(rest);
387
+ }
388
+ if (command === "layout") {
389
+ return runLayout(rest);
390
+ }
391
+ if (command === "convert") {
392
+ return runConvert(rest);
393
+ }
394
+ process.stderr.write(`Unknown command: ${command}
395
+ `);
396
+ return 1;
397
+ }
398
+ function isEntryPoint() {
399
+ const entry = process.argv[1];
400
+ if (entry === undefined)
401
+ return false;
402
+ try {
403
+ return realpathSync(entry) === realpathSync(fileURLToPath(import.meta.url));
404
+ } catch {
405
+ return false;
406
+ }
407
+ }
408
+ if (isEntryPoint()) {
409
+ process.exitCode = await run(process.argv.slice(2));
410
+ }
411
+ export {
412
+ run
413
+ };
@@ -0,0 +1,6 @@
1
+ export * from "../format";
2
+ export { layout, measureText, type TextOptions } from "../layout";
3
+ export type * from "../layout/types";
4
+ export { createSpatialIndex, type Rect, type SpatialEntry, type SpatialIndex } from "./spatial";
5
+ export { type Camera, type Change, createView, type Highlight, HOVERABLE, type ItemKind, type ItemMap, type ItemRef, type Lod, sceneItemCount, type View, type ViewOptions, } from "./view";
6
+ export { WEBGL_THRESHOLD } from "./threshold";
@@ -0,0 +1,91 @@
1
+ import {
2
+ VERSION2
3
+ } from "../cli-z3ccx2y4.js";
4
+ import {
5
+ FORMAT_VERSION2,
6
+ ProvenanceSchema2,
7
+ MetaSchema2,
8
+ SHAPES2,
9
+ ShapeSchema2,
10
+ NodeSchema2,
11
+ EdgeSchema2,
12
+ GroupSchema2,
13
+ DirectionSchema2,
14
+ GraphDocumentSchema2,
15
+ ParticipantSchema2,
16
+ MessageSchema2,
17
+ SequenceDocumentSchema2,
18
+ PSEUDO2,
19
+ StateSchema2,
20
+ TransitionSchema2,
21
+ StateDocumentSchema2,
22
+ KEYS2,
23
+ CARDINALITIES3,
24
+ AttributeSchema2,
25
+ EntitySchema2,
26
+ RelationSchema2,
27
+ ErDocumentSchema2,
28
+ TREE_LAYOUTS2,
29
+ TreeNodeSchema2,
30
+ TreeDocumentSchema2,
31
+ DocumentSchema2,
32
+ validate2
33
+ } from "../cli-m29a3wgx.js";
34
+ import"../cli-txrzzr2q.js";
35
+ import {
36
+ measureText2
37
+ } from "../cli-gh5166k6.js";
38
+ import {
39
+ layout2
40
+ } from "../cli-abzdy8pn.js";
41
+ import {
42
+ createSpatialIndex2,
43
+ HOVERABLE2,
44
+ sceneItemCount2,
45
+ createView2
46
+ } from "../cli-vecew2na.js";
47
+ import {
48
+ transitionLabel2
49
+ } from "../cli-mzmjkk5v.js";
50
+ import {
51
+ WEBGL_THRESHOLD2
52
+ } from "../cli-nyckgf1t.js";
53
+ export {
54
+ AttributeSchema2 as AttributeSchema,
55
+ CARDINALITIES3 as CARDINALITIES,
56
+ DirectionSchema2 as DirectionSchema,
57
+ DocumentSchema2 as DocumentSchema,
58
+ EdgeSchema2 as EdgeSchema,
59
+ EntitySchema2 as EntitySchema,
60
+ ErDocumentSchema2 as ErDocumentSchema,
61
+ FORMAT_VERSION2 as FORMAT_VERSION,
62
+ GraphDocumentSchema2 as GraphDocumentSchema,
63
+ GroupSchema2 as GroupSchema,
64
+ HOVERABLE2 as HOVERABLE,
65
+ KEYS2 as KEYS,
66
+ MessageSchema2 as MessageSchema,
67
+ MetaSchema2 as MetaSchema,
68
+ NodeSchema2 as NodeSchema,
69
+ PSEUDO2 as PSEUDO,
70
+ ParticipantSchema2 as ParticipantSchema,
71
+ ProvenanceSchema2 as ProvenanceSchema,
72
+ RelationSchema2 as RelationSchema,
73
+ SHAPES2 as SHAPES,
74
+ SequenceDocumentSchema2 as SequenceDocumentSchema,
75
+ ShapeSchema2 as ShapeSchema,
76
+ StateDocumentSchema2 as StateDocumentSchema,
77
+ StateSchema2 as StateSchema,
78
+ TREE_LAYOUTS2 as TREE_LAYOUTS,
79
+ TransitionSchema2 as TransitionSchema,
80
+ TreeDocumentSchema2 as TreeDocumentSchema,
81
+ TreeNodeSchema2 as TreeNodeSchema,
82
+ VERSION2 as VERSION,
83
+ WEBGL_THRESHOLD2 as WEBGL_THRESHOLD,
84
+ createSpatialIndex2 as createSpatialIndex,
85
+ createView2 as createView,
86
+ layout2 as layout,
87
+ measureText2 as measureText,
88
+ sceneItemCount2 as sceneItemCount,
89
+ transitionLabel2 as transitionLabel,
90
+ validate2 as validate
91
+ };
@@ -0,0 +1,16 @@
1
+ export type Rect = {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ };
7
+ export type SpatialEntry<T> = {
8
+ box: Rect;
9
+ value: T;
10
+ };
11
+ export interface SpatialIndex<T> {
12
+ readonly size: number;
13
+ query(rect: Rect): T[];
14
+ at(x: number, y: number): T[];
15
+ }
16
+ export declare function createSpatialIndex<T>(entries: readonly SpatialEntry<T>[], cellSize?: number): SpatialIndex<T>;
@@ -0,0 +1 @@
1
+ export declare const WEBGL_THRESHOLD = 2000;