@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,80 @@
1
+ import type { LaidOut, LaidOutEdge, LaidOutEntity, LaidOutGroup, LaidOutMessage, LaidOutNode, LaidOutParticipant, LaidOutRelation, LaidOutState, LaidOutTransition, LaidOutTreeEdge, LaidOutTreeNode } from "../layout/types";
2
+ export type ItemKind = "node" | "edge" | "group" | "participant" | "message" | "state" | "transition" | "entity" | "relation";
3
+ export type ItemRef = {
4
+ kind: ItemKind;
5
+ id: string;
6
+ };
7
+ export type Camera = {
8
+ x: number;
9
+ y: number;
10
+ scale: number;
11
+ };
12
+ export type ViewOptions = {
13
+ minScale?: number;
14
+ maxScale?: number;
15
+ padding?: number;
16
+ labelMinPx?: number;
17
+ };
18
+ export type Lod = {
19
+ labels: boolean;
20
+ captions: boolean;
21
+ edgeLabels: boolean;
22
+ };
23
+ export type Highlight = {
24
+ focused: boolean;
25
+ active: ReadonlySet<string>;
26
+ };
27
+ export type Change = "camera" | "viewport" | "hover" | "selection" | "search" | "lod" | "visible";
28
+ export type ItemMap = {
29
+ node: LaidOutNode | LaidOutTreeNode;
30
+ edge: LaidOutEdge | LaidOutTreeEdge;
31
+ group: LaidOutGroup;
32
+ participant: LaidOutParticipant;
33
+ message: LaidOutMessage;
34
+ state: LaidOutState;
35
+ transition: LaidOutTransition;
36
+ entity: LaidOutEntity;
37
+ relation: LaidOutRelation;
38
+ };
39
+ export declare const HOVERABLE: ReadonlySet<ItemKind>;
40
+ export declare function sceneItemCount(scene: LaidOut): number;
41
+ export interface View {
42
+ readonly scene: LaidOut;
43
+ camera(): Camera;
44
+ viewport(): {
45
+ width: number;
46
+ height: number;
47
+ };
48
+ setViewport(width: number, height: number): void;
49
+ setCamera(camera: Camera): void;
50
+ fit(): void;
51
+ panBy(dx: number, dy: number): void;
52
+ zoomAt(factor: number, screenX: number, screenY: number): void;
53
+ screenToWorld(x: number, y: number): {
54
+ x: number;
55
+ y: number;
56
+ };
57
+ worldToScreen(x: number, y: number): {
58
+ x: number;
59
+ y: number;
60
+ };
61
+ hitTest(screenX: number, screenY: number): ItemRef | null;
62
+ visible(): {
63
+ items: readonly ItemRef[];
64
+ count: number;
65
+ };
66
+ lod(): Lod;
67
+ hover(ref: ItemRef | null): void;
68
+ select(ref: ItemRef | null): void;
69
+ search(query: string): void;
70
+ hovered(): ItemRef | null;
71
+ selected(): ItemRef | null;
72
+ highlight(): Highlight;
73
+ item<K extends ItemKind>(ref: {
74
+ kind: K;
75
+ id: string;
76
+ }): ItemMap[K] | undefined;
77
+ subscribe(listener: (changes: ReadonlySet<Change>) => void): () => void;
78
+ batch(fn: () => void): void;
79
+ }
80
+ export declare function createView(scene: LaidOut, options?: ViewOptions): View;
@@ -0,0 +1,18 @@
1
+ import { type PageThemeOption } from "../svg/theme";
2
+ export { VERSION } from "../version";
3
+ export { type PageThemeOption, type Palette, PALETTES, type PaletteEntry, paletteEntry, resolveTheme, THEME_NAMES, THEMES, type Theme, type ThemeName, type ThemeOption, type ThemeTokens, themeVariables, type TypeStyle, } from "../svg/theme";
4
+ export { type PdfOptions, renderPdf } from "./pdf";
5
+ export { type PngOptions, renderPng } from "./png";
6
+ export declare const EXPORT_FORMATS: readonly ["svg", "html", "png", "pdf", "mermaid"];
7
+ export type ExportFormat = (typeof EXPORT_FORMATS)[number];
8
+ export type ExportOptions = {
9
+ formats?: readonly ExportFormat[];
10
+ theme?: PageThemeOption;
11
+ scale?: number;
12
+ title?: string;
13
+ renderer?: "auto" | "svg" | "webgl";
14
+ };
15
+ export type ExportResult = {
16
+ [K in ExportFormat]?: K extends "svg" | "html" | "mermaid" ? string : Uint8Array;
17
+ };
18
+ export declare function exportDocument(input: unknown, options?: ExportOptions): Promise<ExportResult>;
@@ -0,0 +1,170 @@
1
+ import {
2
+ VERSION2
3
+ } from "../cli-z3ccx2y4.js";
4
+ import {
5
+ validate2
6
+ } from "../cli-m29a3wgx.js";
7
+ import"../cli-txrzzr2q.js";
8
+ import {
9
+ round
10
+ } from "../cli-gh5166k6.js";
11
+ import {
12
+ THEME_NAMES2,
13
+ THEMES2,
14
+ PALETTES2,
15
+ paletteEntry2,
16
+ resolveTheme2,
17
+ themeVariables2,
18
+ lightTheme
19
+ } from "../cli-5v9761s9.js";
20
+ import {
21
+ loadFonts
22
+ } from "../cli-a4ax1vkc.js";
23
+ import {
24
+ layout2
25
+ } from "../cli-abzdy8pn.js";
26
+ import {
27
+ toMermaid2
28
+ } from "../cli-sfdqkbd1.js";
29
+ import {
30
+ loadSource2
31
+ } from "../cli-nhmh6yxk.js";
32
+ import {
33
+ renderHtml2
34
+ } from "../cli-ywgtv1cg.js";
35
+ import {
36
+ formatErrors,
37
+ formatLoadErrors
38
+ } from "../cli-4m00785g.js";
39
+ import {
40
+ renderSvg2
41
+ } from "../cli-wt9dmbhm.js";
42
+
43
+ // src/export/pdf.ts
44
+ import PDFDocument from "pdfkit";
45
+ import SVGtoPDF from "svg-to-pdfkit";
46
+ var FIXED_DATE = new Date("2000-01-01T00:00:00.000Z");
47
+ function renderPdf(svg, options) {
48
+ const fonts = loadFonts();
49
+ const doc = new PDFDocument({
50
+ size: [options.width, options.height],
51
+ margin: 0,
52
+ compress: true,
53
+ info: {
54
+ Producer: "standargraph",
55
+ Creator: "standargraph",
56
+ CreationDate: FIXED_DATE,
57
+ ModDate: FIXED_DATE
58
+ }
59
+ });
60
+ doc.registerFont("Inter", Buffer.from(fonts.regular));
61
+ doc.registerFont("Inter-SemiBold", Buffer.from(fonts.semibold));
62
+ const chunks = [];
63
+ const done = new Promise((resolve, reject) => {
64
+ doc.on("data", (chunk) => chunks.push(chunk));
65
+ doc.on("end", () => resolve(new Uint8Array(Buffer.concat(chunks))));
66
+ doc.on("error", reject);
67
+ });
68
+ SVGtoPDF(doc, svg.replace(/font-weight="600"/g, 'font-weight="bold"'), 0, 0, {
69
+ width: options.width,
70
+ height: options.height,
71
+ assumePt: true,
72
+ fontCallback: (_family, bold) => bold ? "Inter-SemiBold" : "Inter",
73
+ warningCallback: () => {}
74
+ });
75
+ doc.end();
76
+ return done;
77
+ }
78
+
79
+ // src/export/png.ts
80
+ import { readFile } from "node:fs/promises";
81
+ import { createRequire } from "node:module";
82
+ import { initWasm, Resvg } from "@resvg/resvg-wasm";
83
+ var ready;
84
+ function ensureWasm() {
85
+ if (ready === undefined) {
86
+ const path = createRequire(import.meta.url).resolve("@resvg/resvg-wasm/index_bg.wasm");
87
+ ready = readFile(path).then((bytes) => initWasm(bytes));
88
+ }
89
+ return ready;
90
+ }
91
+ async function renderPng(svg, options = {}) {
92
+ await ensureWasm();
93
+ const fonts = loadFonts();
94
+ const resvg = new Resvg(svg, {
95
+ font: {
96
+ fontBuffers: [fonts.regular, fonts.semibold],
97
+ defaultFontFamily: "Inter",
98
+ loadSystemFonts: false
99
+ },
100
+ fitTo: { mode: "zoom", value: options.scale ?? 2 }
101
+ });
102
+ try {
103
+ const image = resvg.render();
104
+ return image.asPng();
105
+ } finally {
106
+ resvg.free();
107
+ }
108
+ }
109
+
110
+ // src/export/index.ts
111
+ var EXPORT_FORMATS = ["svg", "html", "png", "pdf", "mermaid"];
112
+ async function exportDocument(input, options = {}) {
113
+ let document;
114
+ if (typeof input === "string") {
115
+ const loaded = loadSource2(input);
116
+ if (!loaded.ok) {
117
+ throw new Error(`Invalid document:
118
+ ${formatLoadErrors(loaded.errors)}`);
119
+ }
120
+ document = loaded.document;
121
+ } else {
122
+ const result = validate2(input);
123
+ if (!result.ok) {
124
+ throw new Error(`Invalid document:
125
+ ${formatErrors(result.errors)}`);
126
+ }
127
+ document = result.document;
128
+ }
129
+ const theme = options.theme ?? "auto";
130
+ const flatTheme = lightTheme(theme);
131
+ const formats = options.formats ?? ["svg", "html"];
132
+ const rendered = formats.filter((format) => format !== "mermaid");
133
+ const output = {};
134
+ if (rendered.length > 0) {
135
+ const laidOut = await layout2(document);
136
+ for (const format of rendered) {
137
+ if (format === "svg") {
138
+ output.svg = renderSvg2(laidOut, { theme: flatTheme });
139
+ } else if (format === "html") {
140
+ output.html = renderHtml2(document, laidOut, {
141
+ theme,
142
+ title: options.title,
143
+ renderer: options.renderer
144
+ });
145
+ } else {
146
+ const svg = renderSvg2(laidOut, { theme: flatTheme, styles: false });
147
+ output[format] = format === "png" ? await renderPng(svg, { scale: options.scale }) : await renderPdf(svg, {
148
+ width: round(laidOut.width),
149
+ height: round(laidOut.height)
150
+ });
151
+ }
152
+ }
153
+ }
154
+ if (rendered.length < formats.length)
155
+ output.mermaid = toMermaid2(document).text;
156
+ return output;
157
+ }
158
+ export {
159
+ EXPORT_FORMATS,
160
+ PALETTES2 as PALETTES,
161
+ THEMES2 as THEMES,
162
+ THEME_NAMES2 as THEME_NAMES,
163
+ VERSION2 as VERSION,
164
+ exportDocument,
165
+ paletteEntry2 as paletteEntry,
166
+ renderPdf,
167
+ renderPng,
168
+ resolveTheme2 as resolveTheme,
169
+ themeVariables2 as themeVariables
170
+ };
@@ -0,0 +1,5 @@
1
+ export type PdfOptions = {
2
+ width: number;
3
+ height: number;
4
+ };
5
+ export declare function renderPdf(svg: string, options: PdfOptions): Promise<Uint8Array>;
@@ -0,0 +1,4 @@
1
+ export type PngOptions = {
2
+ scale?: number;
3
+ };
4
+ export declare function renderPng(svg: string, options?: PngOptions): Promise<Uint8Array>;
@@ -0,0 +1,4 @@
1
+ export { VERSION } from "../version";
2
+ export * from "./schema";
3
+ export { transitionLabel } from "./transition-label";
4
+ export { validate, type ValidationError, type ValidationResult, } from "./validate";
@@ -0,0 +1,69 @@
1
+ import"../cli-txrzzr2q.js";
2
+ import {
3
+ transitionLabel2
4
+ } from "../cli-mzmjkk5v.js";
5
+ import {
6
+ FORMAT_VERSION2,
7
+ ProvenanceSchema2,
8
+ MetaSchema2,
9
+ SHAPES2,
10
+ ShapeSchema2,
11
+ NodeSchema2,
12
+ EdgeSchema2,
13
+ GroupSchema2,
14
+ DirectionSchema2,
15
+ GraphDocumentSchema2,
16
+ ParticipantSchema2,
17
+ MessageSchema2,
18
+ SequenceDocumentSchema2,
19
+ PSEUDO2,
20
+ StateSchema2,
21
+ TransitionSchema2,
22
+ StateDocumentSchema2,
23
+ KEYS2,
24
+ CARDINALITIES3,
25
+ AttributeSchema2,
26
+ EntitySchema2,
27
+ RelationSchema2,
28
+ ErDocumentSchema2,
29
+ TREE_LAYOUTS2,
30
+ TreeNodeSchema2,
31
+ TreeDocumentSchema2,
32
+ DocumentSchema2,
33
+ validate2
34
+ } from "../cli-m29a3wgx.js";
35
+ import {
36
+ VERSION2
37
+ } from "../cli-z3ccx2y4.js";
38
+ export {
39
+ AttributeSchema2 as AttributeSchema,
40
+ CARDINALITIES3 as CARDINALITIES,
41
+ DirectionSchema2 as DirectionSchema,
42
+ DocumentSchema2 as DocumentSchema,
43
+ EdgeSchema2 as EdgeSchema,
44
+ EntitySchema2 as EntitySchema,
45
+ ErDocumentSchema2 as ErDocumentSchema,
46
+ FORMAT_VERSION2 as FORMAT_VERSION,
47
+ GraphDocumentSchema2 as GraphDocumentSchema,
48
+ GroupSchema2 as GroupSchema,
49
+ KEYS2 as KEYS,
50
+ MessageSchema2 as MessageSchema,
51
+ MetaSchema2 as MetaSchema,
52
+ NodeSchema2 as NodeSchema,
53
+ PSEUDO2 as PSEUDO,
54
+ ParticipantSchema2 as ParticipantSchema,
55
+ ProvenanceSchema2 as ProvenanceSchema,
56
+ RelationSchema2 as RelationSchema,
57
+ SHAPES2 as SHAPES,
58
+ SequenceDocumentSchema2 as SequenceDocumentSchema,
59
+ ShapeSchema2 as ShapeSchema,
60
+ StateDocumentSchema2 as StateDocumentSchema,
61
+ StateSchema2 as StateSchema,
62
+ TREE_LAYOUTS2 as TREE_LAYOUTS,
63
+ TransitionSchema2 as TransitionSchema,
64
+ TreeDocumentSchema2 as TreeDocumentSchema,
65
+ TreeNodeSchema2 as TreeNodeSchema,
66
+ VERSION2 as VERSION,
67
+ transitionLabel2 as transitionLabel,
68
+ validate2 as validate
69
+ };
@@ -0,0 +1,2 @@
1
+ export declare function buildJsonSchema(): Record<string, unknown>;
2
+ export declare function renderJsonSchema(): string;