@standarx/graph 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.fr.md +436 -0
- package/README.md +435 -2
- package/THIRD_PARTY_NOTICES.md +22 -0
- package/assets/fonts/Inter-Regular.ttf +0 -0
- package/assets/fonts/Inter-SemiBold.ttf +0 -0
- package/assets/fonts/OFL.txt +92 -0
- package/dist/adapter-0bggwh8x.js +393 -0
- package/dist/cli-4m00785g.js +20 -0
- package/dist/cli-5v9761s9.js +330 -0
- package/dist/cli-9f1pdw5q.js +462 -0
- package/dist/cli-a4ax1vkc.js +172 -0
- package/dist/cli-b4n941t8.js +1439 -0
- package/dist/cli-eqq7a3wz.js +1144 -0
- package/dist/cli-gh5166k6.js +1565 -0
- package/dist/cli-kzp16pt5.js +207 -0
- package/dist/cli-mzmjkk5v.js +11 -0
- package/dist/cli-njgyf690.js +1060 -0
- package/dist/cli-nkm2j980.js +141 -0
- package/dist/cli-nyckgf1t.js +4 -0
- package/dist/cli-sfdqkbd1.js +433 -0
- package/dist/cli-txrzzr2q.js +0 -0
- package/dist/cli-vecew2na.js +709 -0
- package/dist/cli-wt9dmbhm.js +560 -0
- package/dist/cli-xhdxp3cj.js +387 -0
- package/dist/cli-ywgtv1cg.js +39 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +415 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +93 -0
- package/dist/core/spatial.d.ts +16 -0
- package/dist/core/threshold.d.ts +1 -0
- package/dist/core/view.d.ts +80 -0
- package/dist/export/index.d.ts +18 -0
- package/dist/export/index.js +172 -0
- package/dist/export/pdf.d.ts +5 -0
- package/dist/export/png.d.ts +4 -0
- package/dist/format/index.d.ts +4 -0
- package/dist/format/index.js +71 -0
- package/dist/format/json-schema.d.ts +2 -0
- package/dist/format/schema.d.ts +787 -0
- package/dist/format/semantic/er.d.ts +3 -0
- package/dist/format/semantic/graph.d.ts +3 -0
- package/dist/format/semantic/sequence.d.ts +3 -0
- package/dist/format/semantic/shared.d.ts +14 -0
- package/dist/format/semantic/state.d.ts +3 -0
- package/dist/format/semantic/tree.d.ts +3 -0
- package/dist/format/transition-label.d.ts +2 -0
- package/dist/format/validate.d.ts +11 -0
- package/dist/html/index.d.ts +3 -0
- package/dist/html/index.js +127 -0
- package/dist/html/layout-worker.d.ts +1 -0
- package/dist/html/layout-worker.generated.d.ts +1 -0
- package/dist/html/mount.d.ts +12 -0
- package/dist/html/page.d.ts +14 -0
- package/dist/html/render.d.ts +7 -0
- package/dist/html/runtime.d.ts +1 -0
- package/dist/html/runtime.generated.d.ts +1 -0
- package/dist/html/shell.d.ts +10 -0
- package/dist/html/svg-adapter.d.ts +8 -0
- package/dist/html/ui.d.ts +34 -0
- package/dist/language/analysis.d.ts +38 -0
- package/dist/language/complete.d.ts +3 -0
- package/dist/language/docs.d.ts +11 -0
- package/dist/language/format.d.ts +17 -0
- package/dist/language/hover.d.ts +3 -0
- package/dist/language/index.d.ts +6 -0
- package/dist/language/index.js +1385 -0
- package/dist/language/navigation.d.ts +9 -0
- package/dist/language/positions.d.ts +7 -0
- package/dist/language/symbols.d.ts +3 -0
- package/dist/language/types.d.ts +34 -0
- package/dist/layout/elk.d.ts +35 -0
- package/dist/layout/er.d.ts +3 -0
- package/dist/layout/font-metrics.d.ts +9 -0
- package/dist/layout/graph.d.ts +3 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +17 -0
- package/dist/layout/measure.d.ts +10 -0
- package/dist/layout/sequence.d.ts +3 -0
- package/dist/layout/shapes.d.ts +16 -0
- package/dist/layout/shared.d.ts +31 -0
- package/dist/layout/state.d.ts +3 -0
- package/dist/layout/tree.d.ts +3 -0
- package/dist/layout/types.d.ts +198 -0
- package/dist/layout-worker.generated-emmvgfb1.js +34 -0
- package/dist/mermaid/common.d.ts +36 -0
- package/dist/mermaid/er.d.ts +3 -0
- package/dist/mermaid/graph.d.ts +4 -0
- package/dist/mermaid/index.d.ts +6 -0
- package/dist/mermaid/index.js +6 -0
- package/dist/mermaid/mindmap.d.ts +3 -0
- package/dist/mermaid/sequence.d.ts +3 -0
- package/dist/mermaid/state.d.ts +3 -0
- package/dist/remark/index.d.ts +9 -0
- package/dist/remark/index.js +104 -0
- package/dist/shared/errors.d.ts +6 -0
- package/dist/shared/package-root.d.ts +5 -0
- package/dist/svg/escape.d.ts +1 -0
- package/dist/svg/index.d.ts +3 -0
- package/dist/svg/index.js +25 -0
- package/dist/svg/render.d.ts +9 -0
- package/dist/svg/theme.d.ts +62 -0
- package/dist/svg-adapter-gq5vmp6q.js +227 -0
- package/dist/text/build.d.ts +10 -0
- package/dist/text/canonical.d.ts +10 -0
- package/dist/text/errors.d.ts +33 -0
- package/dist/text/highlight.d.ts +13 -0
- package/dist/text/index.d.ts +33 -0
- package/dist/text/index.js +27 -0
- package/dist/text/lexer.d.ts +29 -0
- package/dist/text/parser.d.ts +160 -0
- package/dist/text/print.d.ts +6 -0
- package/dist/text/slug.d.ts +1 -0
- package/dist/text/syntax.d.ts +8 -0
- package/dist/version.d.ts +1 -0
- package/dist/webgl/adapter.d.ts +4 -0
- package/dist/webgl/index.d.ts +7 -0
- package/dist/webgl/index.js +15 -0
- package/dist/webgl/runtime.d.ts +1 -0
- package/dist/webgl/runtime.generated.d.ts +1 -0
- package/grammars/standargraph.tmLanguage.json +599 -0
- package/language-configuration.json +35 -0
- package/licenses/EPL-2.0.txt +277 -0
- package/licenses/MPL-2.0.txt +373 -0
- package/package.json +133 -4
- package/schema/graph-document.v1.json +1737 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Meta } from "../format/schema";
|
|
2
|
+
export declare class Ids {
|
|
3
|
+
private readonly table;
|
|
4
|
+
private readonly used;
|
|
5
|
+
add(key: string, id: string): string;
|
|
6
|
+
get(key: string): string;
|
|
7
|
+
}
|
|
8
|
+
export declare class Warnings {
|
|
9
|
+
private readonly seen;
|
|
10
|
+
readonly list: string[];
|
|
11
|
+
add(message: string): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const FLOW_DIRECTIONS: {
|
|
14
|
+
readonly down: "TD";
|
|
15
|
+
readonly right: "LR";
|
|
16
|
+
readonly up: "BT";
|
|
17
|
+
readonly left: "RL";
|
|
18
|
+
};
|
|
19
|
+
export declare const BLOCK_DIRECTIONS: {
|
|
20
|
+
readonly down: "TB";
|
|
21
|
+
readonly right: "LR";
|
|
22
|
+
readonly up: "BT";
|
|
23
|
+
readonly left: "RL";
|
|
24
|
+
};
|
|
25
|
+
export declare function mlabel(text: string): string;
|
|
26
|
+
export declare function plainText(text: string): string;
|
|
27
|
+
type Lossy = {
|
|
28
|
+
type?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
link?: string;
|
|
31
|
+
position?: unknown;
|
|
32
|
+
meta?: Meta;
|
|
33
|
+
};
|
|
34
|
+
export declare function noteLosses(warnings: Warnings, item: Lossy): void;
|
|
35
|
+
export declare function frontMatter(title: string | undefined): string[];
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GraphDocument, TreeDocument } from "../format/schema";
|
|
2
|
+
import { type Warnings } from "./common";
|
|
3
|
+
export declare function graphLines(doc: GraphDocument, warnings: Warnings): string[];
|
|
4
|
+
export declare function treeFlowLines(doc: TreeDocument, warnings: Warnings): string[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Root } from "mdast";
|
|
2
|
+
import { type ThemeName } from "../svg/theme";
|
|
3
|
+
export { VERSION } from "../version";
|
|
4
|
+
export type RemarkStandargraphOptions = {
|
|
5
|
+
outDir?: string;
|
|
6
|
+
publicPath?: string;
|
|
7
|
+
theme?: ThemeName | "auto";
|
|
8
|
+
};
|
|
9
|
+
export declare function remarkStandargraph(options?: RemarkStandargraphOptions): (tree: Root) => Promise<void>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import"../cli-gh5166k6.js";
|
|
2
|
+
import {
|
|
3
|
+
lightTheme
|
|
4
|
+
} from "../cli-5v9761s9.js";
|
|
5
|
+
import"../cli-a4ax1vkc.js";
|
|
6
|
+
import {
|
|
7
|
+
VERSION2
|
|
8
|
+
} from "../cli-nkm2j980.js";
|
|
9
|
+
import"../cli-kzp16pt5.js";
|
|
10
|
+
import"../cli-xhdxp3cj.js";
|
|
11
|
+
import"../cli-txrzzr2q.js";
|
|
12
|
+
import {
|
|
13
|
+
layout2
|
|
14
|
+
} from "../cli-eqq7a3wz.js";
|
|
15
|
+
import {
|
|
16
|
+
loadSource2
|
|
17
|
+
} from "../cli-b4n941t8.js";
|
|
18
|
+
import"../cli-njgyf690.js";
|
|
19
|
+
import {
|
|
20
|
+
renderHtml2
|
|
21
|
+
} from "../cli-ywgtv1cg.js";
|
|
22
|
+
import {
|
|
23
|
+
formatLoadErrors
|
|
24
|
+
} from "../cli-4m00785g.js";
|
|
25
|
+
import {
|
|
26
|
+
renderSvg2
|
|
27
|
+
} from "../cli-wt9dmbhm.js";
|
|
28
|
+
|
|
29
|
+
// src/remark/index.ts
|
|
30
|
+
import { createHash } from "node:crypto";
|
|
31
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
32
|
+
import { join } from "node:path";
|
|
33
|
+
function escapeHtml(value) {
|
|
34
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
35
|
+
}
|
|
36
|
+
function failure(message) {
|
|
37
|
+
return {
|
|
38
|
+
failed: true,
|
|
39
|
+
node: {
|
|
40
|
+
type: "html",
|
|
41
|
+
value: `<pre class="standargraph-error">${escapeHtml(message)}</pre>`
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function convert(source, options) {
|
|
46
|
+
const loaded = loadSource2(source);
|
|
47
|
+
if (!loaded.ok) {
|
|
48
|
+
return failure(`Invalid document:
|
|
49
|
+
${formatLoadErrors(loaded.errors)}`);
|
|
50
|
+
}
|
|
51
|
+
const document = loaded.document;
|
|
52
|
+
try {
|
|
53
|
+
const laidOut = await layout2(document);
|
|
54
|
+
const hash = createHash("sha256").update(source).digest("hex").slice(0, 12);
|
|
55
|
+
const svg = renderSvg2(laidOut, {
|
|
56
|
+
theme: lightTheme(options.theme),
|
|
57
|
+
standalone: false,
|
|
58
|
+
idPrefix: `sg${hash}`
|
|
59
|
+
}).trim();
|
|
60
|
+
let content = svg;
|
|
61
|
+
if (options.outDir !== undefined) {
|
|
62
|
+
mkdirSync(options.outDir, { recursive: true });
|
|
63
|
+
writeFileSync(join(options.outDir, `${hash}.html`), renderHtml2(document, laidOut, { theme: options.theme }));
|
|
64
|
+
const prefix = options.publicPath === undefined ? "" : `${options.publicPath.replace(/\/+$/, "")}/`;
|
|
65
|
+
content = `<a href="${escapeHtml(`${prefix}${hash}.html`)}">${svg}</a>`;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
failed: false,
|
|
69
|
+
node: {
|
|
70
|
+
type: "html",
|
|
71
|
+
value: `<figure class="standargraph">${content}</figure>`
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
} catch (error) {
|
|
75
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
76
|
+
return failure(`Cannot render the diagram: ${reason}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function walk(parent, options) {
|
|
80
|
+
const children = [];
|
|
81
|
+
for (const child of parent.children) {
|
|
82
|
+
if (child.type === "code" && (child.lang === "standargraph" || child.lang === "sg")) {
|
|
83
|
+
const converted = await convert(child.value, options);
|
|
84
|
+
if (converted.failed)
|
|
85
|
+
children.push(child);
|
|
86
|
+
children.push(converted.node);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if ("children" in child) {
|
|
90
|
+
await walk(child, options);
|
|
91
|
+
}
|
|
92
|
+
children.push(child);
|
|
93
|
+
}
|
|
94
|
+
parent.children = children;
|
|
95
|
+
}
|
|
96
|
+
function remarkStandargraph(options = {}) {
|
|
97
|
+
return async (tree) => {
|
|
98
|
+
await walk(tree, options);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
VERSION2 as VERSION,
|
|
103
|
+
remarkStandargraph
|
|
104
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function esc(value: string): string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { VERSION } from "../version";
|
|
2
|
+
export { type RenderOptions, renderSvg } from "./render";
|
|
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 "./theme";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VERSION2
|
|
3
|
+
} from "../cli-nkm2j980.js";
|
|
4
|
+
import"../cli-gh5166k6.js";
|
|
5
|
+
import {
|
|
6
|
+
THEME_NAMES2,
|
|
7
|
+
THEMES2,
|
|
8
|
+
PALETTES2,
|
|
9
|
+
paletteEntry2,
|
|
10
|
+
resolveTheme2,
|
|
11
|
+
themeVariables2
|
|
12
|
+
} from "../cli-5v9761s9.js";
|
|
13
|
+
import {
|
|
14
|
+
renderSvg2
|
|
15
|
+
} from "../cli-wt9dmbhm.js";
|
|
16
|
+
export {
|
|
17
|
+
PALETTES2 as PALETTES,
|
|
18
|
+
THEMES2 as THEMES,
|
|
19
|
+
THEME_NAMES2 as THEME_NAMES,
|
|
20
|
+
VERSION2 as VERSION,
|
|
21
|
+
paletteEntry2 as paletteEntry,
|
|
22
|
+
renderSvg2 as renderSvg,
|
|
23
|
+
resolveTheme2 as resolveTheme,
|
|
24
|
+
themeVariables2 as themeVariables
|
|
25
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LaidOut } from "../layout/types";
|
|
2
|
+
import { type ThemeOption } from "./theme";
|
|
3
|
+
export type RenderOptions = {
|
|
4
|
+
theme?: ThemeOption;
|
|
5
|
+
standalone?: boolean;
|
|
6
|
+
styles?: boolean;
|
|
7
|
+
idPrefix?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function renderSvg(laidOut: LaidOut, options?: RenderOptions): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { LaidOut } from "../layout/types";
|
|
2
|
+
export type ThemeTokens = {
|
|
3
|
+
bg: string;
|
|
4
|
+
fg: string;
|
|
5
|
+
muted: string;
|
|
6
|
+
nodeFill: string;
|
|
7
|
+
nodeStroke: string;
|
|
8
|
+
unknownFill: string;
|
|
9
|
+
groupFill: string;
|
|
10
|
+
groupStroke: string;
|
|
11
|
+
edge: string;
|
|
12
|
+
labelBg: string;
|
|
13
|
+
accent: string;
|
|
14
|
+
lifeline: string;
|
|
15
|
+
headerFill: string;
|
|
16
|
+
};
|
|
17
|
+
export type TypeStyle = {
|
|
18
|
+
fill?: string;
|
|
19
|
+
stroke?: string;
|
|
20
|
+
text?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const THEME_NAMES: readonly ["light", "dark", "nord", "solarized-light", "solarized-dark", "high-contrast"];
|
|
23
|
+
export type ThemeName = (typeof THEME_NAMES)[number];
|
|
24
|
+
export type PaletteEntry = {
|
|
25
|
+
fill: string;
|
|
26
|
+
stroke: string;
|
|
27
|
+
text: string;
|
|
28
|
+
};
|
|
29
|
+
export type Palette = readonly PaletteEntry[];
|
|
30
|
+
export type Theme = {
|
|
31
|
+
base?: ThemeName;
|
|
32
|
+
tokens?: Partial<ThemeTokens>;
|
|
33
|
+
types?: Record<string, TypeStyle>;
|
|
34
|
+
palette?: false;
|
|
35
|
+
};
|
|
36
|
+
export type ThemeOption = ThemeName | Theme;
|
|
37
|
+
export type PageThemeOption = ThemeName | "auto" | Theme | {
|
|
38
|
+
light: Theme;
|
|
39
|
+
dark: Theme;
|
|
40
|
+
};
|
|
41
|
+
export declare const THEMES: Readonly<Record<ThemeName, ThemeTokens>>;
|
|
42
|
+
export declare const THEME_BASES: Readonly<Record<ThemeName, "light" | "dark">>;
|
|
43
|
+
export declare const PALETTES: Readonly<Record<ThemeName, Palette>>;
|
|
44
|
+
export declare function isThemeName(value: unknown): value is ThemeName;
|
|
45
|
+
export declare function typeHash(type: string): number;
|
|
46
|
+
export declare function paletteEntry(palette: Palette, type: string): PaletteEntry;
|
|
47
|
+
export type ResolvedTheme = {
|
|
48
|
+
tokens: ThemeTokens;
|
|
49
|
+
types: Record<string, TypeStyle>;
|
|
50
|
+
palette: Palette | undefined;
|
|
51
|
+
};
|
|
52
|
+
export type EffectiveTheme = Pick<ResolvedTheme, "tokens" | "types">;
|
|
53
|
+
export declare function resolveTheme(option: ThemeOption | undefined): ResolvedTheme;
|
|
54
|
+
export declare function withPalette(resolved: ResolvedTheme, typeNames: readonly string[]): ResolvedTheme;
|
|
55
|
+
export declare function typesPresent(laidOut: LaidOut): string[];
|
|
56
|
+
export declare function escapedTheme({ tokens, types }: EffectiveTheme): EffectiveTheme;
|
|
57
|
+
export declare function themeVariables(option: ThemeOption): string;
|
|
58
|
+
export declare function typeRules(types: Record<string, TypeStyle>, scope: string): string;
|
|
59
|
+
export declare function isAdaptive(option: PageThemeOption | undefined): boolean;
|
|
60
|
+
export declare function withoutPalette(option: PageThemeOption): PageThemeOption;
|
|
61
|
+
export declare function lightTheme(option: PageThemeOption | undefined): ThemeOption;
|
|
62
|
+
export declare function themeStyle(option: PageThemeOption, typeNames?: readonly string[]): string;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HOVERABLE2,
|
|
3
|
+
sceneItemCount2,
|
|
4
|
+
createView2
|
|
5
|
+
} from "./cli-vecew2na.js";
|
|
6
|
+
import {
|
|
7
|
+
part,
|
|
8
|
+
bindScheme,
|
|
9
|
+
createPanel,
|
|
10
|
+
bindInteraction
|
|
11
|
+
} from "./cli-9f1pdw5q.js";
|
|
12
|
+
|
|
13
|
+
// src/html/svg-adapter.ts
|
|
14
|
+
var IDLE_MS = 150;
|
|
15
|
+
var CULL_MIN_ITEMS = 400;
|
|
16
|
+
function startSvg(doc, scene) {
|
|
17
|
+
const viewport = part("sg-viewport");
|
|
18
|
+
const stage = part("sg-stage");
|
|
19
|
+
const panel = part("sg-panel");
|
|
20
|
+
const search = part("sg-search");
|
|
21
|
+
const svg = stage.querySelector("svg");
|
|
22
|
+
if (svg === null)
|
|
23
|
+
return;
|
|
24
|
+
const root = svg;
|
|
25
|
+
bindScheme(part("sg-app"));
|
|
26
|
+
const view = createView2(scene);
|
|
27
|
+
const panelControl = createPanel(view, doc, panel);
|
|
28
|
+
const elements = new Map;
|
|
29
|
+
for (const item of root.querySelectorAll("[data-kind]")) {
|
|
30
|
+
elements.set(`${item.getAttribute("data-kind")}:${item.getAttribute("data-id")}`, item);
|
|
31
|
+
}
|
|
32
|
+
const elementByRef = new Map;
|
|
33
|
+
function elementOf(ref) {
|
|
34
|
+
let found = elementByRef.get(ref);
|
|
35
|
+
if (found === undefined) {
|
|
36
|
+
found = elements.get(`${ref.kind}:${ref.id}`);
|
|
37
|
+
if (found !== undefined)
|
|
38
|
+
elementByRef.set(ref, found);
|
|
39
|
+
}
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
const culling = sceneItemCount2(scene) > CULL_MIN_ITEMS;
|
|
43
|
+
let lastMove = 0;
|
|
44
|
+
let idleTimer = 0;
|
|
45
|
+
let willChange = false;
|
|
46
|
+
let scheduled = false;
|
|
47
|
+
let cullDirty = false;
|
|
48
|
+
let pending = new Set;
|
|
49
|
+
let shown = new Set(view.visible().items);
|
|
50
|
+
let previousActive = new Set;
|
|
51
|
+
let previousFocused = false;
|
|
52
|
+
let selectedElement = null;
|
|
53
|
+
function touch() {
|
|
54
|
+
lastMove = performance.now();
|
|
55
|
+
if (!willChange) {
|
|
56
|
+
willChange = true;
|
|
57
|
+
stage.style.willChange = "transform";
|
|
58
|
+
}
|
|
59
|
+
if (idleTimer === 0)
|
|
60
|
+
idleTimer = window.setTimeout(idle, IDLE_MS);
|
|
61
|
+
}
|
|
62
|
+
function idle() {
|
|
63
|
+
const remaining = IDLE_MS - (performance.now() - lastMove);
|
|
64
|
+
if (remaining > 1) {
|
|
65
|
+
idleTimer = window.setTimeout(idle, remaining);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
idleTimer = 0;
|
|
69
|
+
willChange = false;
|
|
70
|
+
stage.style.willChange = "";
|
|
71
|
+
if (cullDirty)
|
|
72
|
+
applyVisible();
|
|
73
|
+
if (ui.pointer !== null)
|
|
74
|
+
schedule();
|
|
75
|
+
}
|
|
76
|
+
function applyCamera() {
|
|
77
|
+
const camera = view.camera();
|
|
78
|
+
stage.style.transform = `translate(${camera.x}px, ${camera.y}px) scale(${camera.scale})`;
|
|
79
|
+
}
|
|
80
|
+
function applyLod() {
|
|
81
|
+
const lod = view.lod();
|
|
82
|
+
root.classList.toggle("sg-lod-nolabels", !lod.labels);
|
|
83
|
+
root.classList.toggle("sg-lod-nocaptions", !lod.captions);
|
|
84
|
+
root.classList.toggle("sg-lod-noedgelabels", !lod.edgeLabels);
|
|
85
|
+
}
|
|
86
|
+
function applyHighlight() {
|
|
87
|
+
const { focused, active } = view.highlight();
|
|
88
|
+
if (focused !== previousFocused) {
|
|
89
|
+
root.classList.toggle("sg-focus", focused);
|
|
90
|
+
previousFocused = focused;
|
|
91
|
+
}
|
|
92
|
+
for (const key of previousActive) {
|
|
93
|
+
if (!active.has(key))
|
|
94
|
+
elements.get(key)?.classList.remove("sg-hl");
|
|
95
|
+
}
|
|
96
|
+
for (const key of active) {
|
|
97
|
+
if (!previousActive.has(key))
|
|
98
|
+
elements.get(key)?.classList.add("sg-hl");
|
|
99
|
+
}
|
|
100
|
+
previousActive = active;
|
|
101
|
+
}
|
|
102
|
+
function applyVisible() {
|
|
103
|
+
cullDirty = false;
|
|
104
|
+
const next = new Set(view.visible().items);
|
|
105
|
+
for (const ref of shown) {
|
|
106
|
+
if (next.has(ref))
|
|
107
|
+
continue;
|
|
108
|
+
const target = elementOf(ref);
|
|
109
|
+
if (target instanceof SVGElement)
|
|
110
|
+
target.style.display = "none";
|
|
111
|
+
}
|
|
112
|
+
for (const ref of next) {
|
|
113
|
+
if (shown.has(ref))
|
|
114
|
+
continue;
|
|
115
|
+
const target = elementOf(ref);
|
|
116
|
+
if (target instanceof SVGElement)
|
|
117
|
+
target.style.display = "";
|
|
118
|
+
}
|
|
119
|
+
shown = next;
|
|
120
|
+
}
|
|
121
|
+
function revealVisible() {
|
|
122
|
+
cullDirty = true;
|
|
123
|
+
const next = view.visible().items;
|
|
124
|
+
const grown = new Set(shown);
|
|
125
|
+
for (const ref of next) {
|
|
126
|
+
if (grown.has(ref))
|
|
127
|
+
continue;
|
|
128
|
+
const target = elementOf(ref);
|
|
129
|
+
if (target instanceof SVGElement)
|
|
130
|
+
target.style.display = "";
|
|
131
|
+
grown.add(ref);
|
|
132
|
+
}
|
|
133
|
+
shown = grown;
|
|
134
|
+
}
|
|
135
|
+
function applyHover() {
|
|
136
|
+
const pointer = ui.pointer;
|
|
137
|
+
if (pointer === null || ui.dragging)
|
|
138
|
+
return;
|
|
139
|
+
if (performance.now() - ui.lastWheel < IDLE_MS)
|
|
140
|
+
return;
|
|
141
|
+
const hit = view.hitTest(pointer.x, pointer.y);
|
|
142
|
+
ui.pointer = null;
|
|
143
|
+
view.hover(hit !== null && hoverable(hit) ? hit : null);
|
|
144
|
+
}
|
|
145
|
+
function hoverable(ref) {
|
|
146
|
+
if (!HOVERABLE2.has(ref.kind))
|
|
147
|
+
return false;
|
|
148
|
+
return ref.kind !== "state" || view.item({ kind: "state", id: ref.id })?.composite !== true;
|
|
149
|
+
}
|
|
150
|
+
function frame() {
|
|
151
|
+
applyHover();
|
|
152
|
+
scheduled = false;
|
|
153
|
+
const changes = pending;
|
|
154
|
+
pending = new Set;
|
|
155
|
+
if (changes.has("camera"))
|
|
156
|
+
applyCamera();
|
|
157
|
+
if (changes.has("lod"))
|
|
158
|
+
applyLod();
|
|
159
|
+
if (changes.has("hover") || changes.has("search"))
|
|
160
|
+
applyHighlight();
|
|
161
|
+
if (culling && changes.has("visible")) {
|
|
162
|
+
if (willChange)
|
|
163
|
+
revealVisible();
|
|
164
|
+
else
|
|
165
|
+
applyVisible();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function schedule() {
|
|
169
|
+
if (scheduled)
|
|
170
|
+
return;
|
|
171
|
+
scheduled = true;
|
|
172
|
+
requestAnimationFrame(frame);
|
|
173
|
+
}
|
|
174
|
+
view.subscribe((changes) => {
|
|
175
|
+
if (changes.has("selection"))
|
|
176
|
+
applySelection();
|
|
177
|
+
if (changes.has("camera"))
|
|
178
|
+
touch();
|
|
179
|
+
for (const change of changes)
|
|
180
|
+
pending.add(change);
|
|
181
|
+
schedule();
|
|
182
|
+
});
|
|
183
|
+
function applySelection() {
|
|
184
|
+
selectedElement?.classList.remove("sg-selected");
|
|
185
|
+
selectedElement = null;
|
|
186
|
+
const ref = view.selected();
|
|
187
|
+
if (ref !== null) {
|
|
188
|
+
selectedElement = elementOf(ref) ?? null;
|
|
189
|
+
selectedElement?.classList.add("sg-selected");
|
|
190
|
+
}
|
|
191
|
+
panelControl.update();
|
|
192
|
+
}
|
|
193
|
+
function pickable(target) {
|
|
194
|
+
if (!(target instanceof Element))
|
|
195
|
+
return null;
|
|
196
|
+
const found = target.closest("[data-kind]");
|
|
197
|
+
if (found === null || found.getAttribute("data-kind") === "group")
|
|
198
|
+
return null;
|
|
199
|
+
return {
|
|
200
|
+
kind: found.getAttribute("data-kind") ?? "",
|
|
201
|
+
id: found.getAttribute("data-id") ?? ""
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const ui = bindInteraction({
|
|
205
|
+
view,
|
|
206
|
+
viewport,
|
|
207
|
+
search,
|
|
208
|
+
pick: (event) => pickable(event.target),
|
|
209
|
+
onPointer: schedule
|
|
210
|
+
});
|
|
211
|
+
applyCamera();
|
|
212
|
+
applyLod();
|
|
213
|
+
if (culling)
|
|
214
|
+
applyVisible();
|
|
215
|
+
part("sg-app").dataset.sgReady = "1";
|
|
216
|
+
return {
|
|
217
|
+
view,
|
|
218
|
+
destroy() {
|
|
219
|
+
ui.destroy();
|
|
220
|
+
panelControl.destroy();
|
|
221
|
+
clearTimeout(idleTimer);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
startSvg
|
|
227
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Range, Sink } from "./errors";
|
|
2
|
+
import type { Ast } from "./parser";
|
|
3
|
+
type Json = Record<string, unknown>;
|
|
4
|
+
export type Marks = Map<string, Range>;
|
|
5
|
+
type Ctx = {
|
|
6
|
+
sink: Sink;
|
|
7
|
+
marks: Marks;
|
|
8
|
+
};
|
|
9
|
+
export declare function build(ast: Ast, ctx: Ctx): Json;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Document, Node } from "../format/schema";
|
|
2
|
+
type Linked = {
|
|
3
|
+
id: string;
|
|
4
|
+
parent?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function walk<T extends Linked>(items: readonly T[], enter: (item: T, depth: number, children: number) => void, exit?: (item: T, depth: number, children: number) => void): void;
|
|
7
|
+
export declare function preorder<T extends Linked>(items: readonly T[]): T[];
|
|
8
|
+
export declare function groupNodes(nodes: readonly Node[]): Map<string | undefined, Node[]>;
|
|
9
|
+
export declare function canonicalize(document: Document): Document;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type TextErrorCode = "E_HEADER" | "E_TOKEN" | "E_STRING" | "E_ESCAPE" | "E_EXPECTED" | "E_OPERATOR" | "E_ATTR" | "E_VALUE" | "E_DUPLICATE" | "E_REGION" | "E_BLOCK" | "E_INDENT" | "E_ROOT" | "E_VALIDATE";
|
|
2
|
+
export type TextError = {
|
|
3
|
+
line: number;
|
|
4
|
+
column: number;
|
|
5
|
+
endLine: number;
|
|
6
|
+
endColumn: number;
|
|
7
|
+
code: TextErrorCode;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
export type Range = {
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
};
|
|
14
|
+
export declare const STOP: unique symbol;
|
|
15
|
+
export declare class LineMap {
|
|
16
|
+
private readonly starts;
|
|
17
|
+
constructor(source: string);
|
|
18
|
+
line(offset: number): number;
|
|
19
|
+
position(offset: number): {
|
|
20
|
+
line: number;
|
|
21
|
+
column: number;
|
|
22
|
+
};
|
|
23
|
+
error(code: TextErrorCode, range: Range, message: string): TextError;
|
|
24
|
+
}
|
|
25
|
+
export declare class Sink {
|
|
26
|
+
readonly lines: LineMap;
|
|
27
|
+
readonly errors: TextError[];
|
|
28
|
+
muted: number;
|
|
29
|
+
constructor(lines: LineMap);
|
|
30
|
+
lineOf(offset: number): number;
|
|
31
|
+
report(code: TextErrorCode, range: Range, message: string): void;
|
|
32
|
+
sorted(): TextError[];
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const SEMANTIC_TOKEN_TYPES: readonly ["namespace", "type", "variable", "property", "enumMember", "keyword", "comment", "string", "number", "operator"];
|
|
2
|
+
export declare const SEMANTIC_TOKEN_MODIFIERS: readonly ["declaration", "defaultLibrary"];
|
|
3
|
+
export type SemanticTokenType = (typeof SEMANTIC_TOKEN_TYPES)[number];
|
|
4
|
+
export type SemanticTokenModifier = (typeof SEMANTIC_TOKEN_MODIFIERS)[number];
|
|
5
|
+
export type HighlightToken = {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
type: SemanticTokenType;
|
|
11
|
+
modifiers?: SemanticTokenModifier[];
|
|
12
|
+
};
|
|
13
|
+
export declare function highlight(source: string): HighlightToken[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Document } from "../format/schema";
|
|
2
|
+
import { type TextError } from "./errors";
|
|
3
|
+
export { VERSION } from "../version";
|
|
4
|
+
export { canonicalize } from "./canonical";
|
|
5
|
+
export type { TextError, TextErrorCode } from "./errors";
|
|
6
|
+
export { highlight, SEMANTIC_TOKEN_MODIFIERS, SEMANTIC_TOKEN_TYPES, type HighlightToken, type SemanticTokenModifier, type SemanticTokenType, } from "./highlight";
|
|
7
|
+
export { print, type PrintOptions, type PrintStyle } from "./print";
|
|
8
|
+
export type ParseResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
document: Document;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
errors: TextError[];
|
|
14
|
+
};
|
|
15
|
+
export declare function parse(source: string): ParseResult;
|
|
16
|
+
export type LoadError = {
|
|
17
|
+
message: string;
|
|
18
|
+
line?: number;
|
|
19
|
+
column?: number;
|
|
20
|
+
path?: string;
|
|
21
|
+
code?: string;
|
|
22
|
+
};
|
|
23
|
+
export type Loaded = {
|
|
24
|
+
ok: true;
|
|
25
|
+
format: "json" | "text";
|
|
26
|
+
document: Document;
|
|
27
|
+
} | {
|
|
28
|
+
ok: false;
|
|
29
|
+
format: "json" | "text";
|
|
30
|
+
errors: LoadError[];
|
|
31
|
+
};
|
|
32
|
+
export declare function sniff(source: string): "json" | "text";
|
|
33
|
+
export declare function loadSource(source: string): Loaded;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicalize2,
|
|
3
|
+
SEMANTIC_TOKEN_TYPES2,
|
|
4
|
+
SEMANTIC_TOKEN_MODIFIERS2,
|
|
5
|
+
highlight2,
|
|
6
|
+
print2,
|
|
7
|
+
parse2,
|
|
8
|
+
sniff2,
|
|
9
|
+
loadSource2
|
|
10
|
+
} from "../cli-b4n941t8.js";
|
|
11
|
+
import"../cli-njgyf690.js";
|
|
12
|
+
import"../cli-xhdxp3cj.js";
|
|
13
|
+
import"../cli-kzp16pt5.js";
|
|
14
|
+
import {
|
|
15
|
+
VERSION2
|
|
16
|
+
} from "../cli-nkm2j980.js";
|
|
17
|
+
export {
|
|
18
|
+
SEMANTIC_TOKEN_MODIFIERS2 as SEMANTIC_TOKEN_MODIFIERS,
|
|
19
|
+
SEMANTIC_TOKEN_TYPES2 as SEMANTIC_TOKEN_TYPES,
|
|
20
|
+
VERSION2 as VERSION,
|
|
21
|
+
canonicalize2 as canonicalize,
|
|
22
|
+
highlight2 as highlight,
|
|
23
|
+
loadSource2 as loadSource,
|
|
24
|
+
parse2 as parse,
|
|
25
|
+
print2 as print,
|
|
26
|
+
sniff2 as sniff
|
|
27
|
+
};
|