@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,387 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FORMAT_VERSION2,
|
|
3
|
+
SHAPES2,
|
|
4
|
+
GraphDocumentSchema2,
|
|
5
|
+
SequenceDocumentSchema2,
|
|
6
|
+
PSEUDO2,
|
|
7
|
+
StateDocumentSchema2,
|
|
8
|
+
KEYS2,
|
|
9
|
+
CARDINALITIES3,
|
|
10
|
+
ErDocumentSchema2,
|
|
11
|
+
TREE_LAYOUTS2,
|
|
12
|
+
TreeDocumentSchema2
|
|
13
|
+
} from "./cli-kzp16pt5.js";
|
|
14
|
+
|
|
15
|
+
// src/format/validate.ts
|
|
16
|
+
import { FormatRegistry } from "@sinclair/typebox";
|
|
17
|
+
import { Value, ValueErrorType } from "@sinclair/typebox/value";
|
|
18
|
+
|
|
19
|
+
// src/format/semantic/shared.ts
|
|
20
|
+
function checkUnique(items, collection, label, errors) {
|
|
21
|
+
const seen = new Set;
|
|
22
|
+
items.forEach((item, index) => {
|
|
23
|
+
if (item.id === undefined)
|
|
24
|
+
return;
|
|
25
|
+
if (seen.has(item.id)) {
|
|
26
|
+
errors.push({
|
|
27
|
+
path: `/${collection}/${index}/id`,
|
|
28
|
+
message: `Duplicate ${label} id "${item.id}"`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
seen.add(item.id);
|
|
32
|
+
});
|
|
33
|
+
return seen;
|
|
34
|
+
}
|
|
35
|
+
function parentCycles(items) {
|
|
36
|
+
const ids = new Set(items.map((item) => item.id));
|
|
37
|
+
const parentOf = new Map;
|
|
38
|
+
for (const item of items) {
|
|
39
|
+
if (item.parent !== undefined && ids.has(item.parent)) {
|
|
40
|
+
parentOf.set(item.id, item.parent);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const firstIndex = new Map;
|
|
44
|
+
items.forEach((item, index) => {
|
|
45
|
+
if (!firstIndex.has(item.id))
|
|
46
|
+
firstIndex.set(item.id, index);
|
|
47
|
+
});
|
|
48
|
+
const state = new Map;
|
|
49
|
+
const found = [];
|
|
50
|
+
for (const item of items) {
|
|
51
|
+
if (state.has(item.id))
|
|
52
|
+
continue;
|
|
53
|
+
const path = [];
|
|
54
|
+
const position = new Map;
|
|
55
|
+
let current = item.id;
|
|
56
|
+
while (current !== undefined && !state.has(current)) {
|
|
57
|
+
state.set(current, 1);
|
|
58
|
+
position.set(current, path.length);
|
|
59
|
+
path.push(current);
|
|
60
|
+
current = parentOf.get(current);
|
|
61
|
+
}
|
|
62
|
+
if (current !== undefined && state.get(current) === 1) {
|
|
63
|
+
const members = path.slice(position.get(current));
|
|
64
|
+
let start = 0;
|
|
65
|
+
members.forEach((id, at) => {
|
|
66
|
+
if (firstIndex.get(id) < firstIndex.get(members[start]))
|
|
67
|
+
start = at;
|
|
68
|
+
});
|
|
69
|
+
const cycle = [...members.slice(start), ...members.slice(0, start)];
|
|
70
|
+
found.push({ index: firstIndex.get(cycle[0]), cycle: [...cycle, cycle[0]] });
|
|
71
|
+
}
|
|
72
|
+
for (const id of path)
|
|
73
|
+
state.set(id, 2);
|
|
74
|
+
}
|
|
75
|
+
return found.sort((a, b) => a.index - b.index);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/format/semantic/er.ts
|
|
79
|
+
function semanticErErrors(doc) {
|
|
80
|
+
const errors = [];
|
|
81
|
+
const entityIds = checkUnique(doc.entities, "entities", "entity", errors);
|
|
82
|
+
const relations = doc.relations ?? [];
|
|
83
|
+
checkUnique(relations, "relations", "relation", errors);
|
|
84
|
+
relations.forEach((relation, index) => {
|
|
85
|
+
if (!entityIds.has(relation.from)) {
|
|
86
|
+
errors.push({
|
|
87
|
+
path: `/relations/${index}/from`,
|
|
88
|
+
message: `Relation source "${relation.from}" is not a known entity id`
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (!entityIds.has(relation.to)) {
|
|
92
|
+
errors.push({
|
|
93
|
+
path: `/relations/${index}/to`,
|
|
94
|
+
message: `Relation target "${relation.to}" is not a known entity id`
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
doc.entities.forEach((entity, index) => {
|
|
99
|
+
const names = new Set;
|
|
100
|
+
(entity.attributes ?? []).forEach((attribute, position) => {
|
|
101
|
+
const base = `/entities/${index}/attributes/${position}`;
|
|
102
|
+
if (names.has(attribute.name)) {
|
|
103
|
+
errors.push({
|
|
104
|
+
path: `${base}/name`,
|
|
105
|
+
message: `Duplicate attribute "${attribute.name}" in entity "${entity.id}"`
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
names.add(attribute.name);
|
|
109
|
+
const keys = new Set;
|
|
110
|
+
(attribute.keys ?? []).forEach((key, slot) => {
|
|
111
|
+
if (keys.has(key)) {
|
|
112
|
+
errors.push({ path: `${base}/keys/${slot}`, message: `Duplicate key "${key}"` });
|
|
113
|
+
}
|
|
114
|
+
keys.add(key);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
return errors;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/format/semantic/graph.ts
|
|
122
|
+
function semanticGraphErrors(doc) {
|
|
123
|
+
const errors = [];
|
|
124
|
+
const nodeIds = checkUnique(doc.nodes, "nodes", "node", errors);
|
|
125
|
+
const groups = doc.groups ?? [];
|
|
126
|
+
const groupIds = checkUnique(groups, "groups", "group", errors);
|
|
127
|
+
const edges = doc.edges ?? [];
|
|
128
|
+
checkUnique(edges, "edges", "edge", errors);
|
|
129
|
+
edges.forEach((edge, index) => {
|
|
130
|
+
if (!nodeIds.has(edge.from)) {
|
|
131
|
+
errors.push({
|
|
132
|
+
path: `/edges/${index}/from`,
|
|
133
|
+
message: `Edge source "${edge.from}" is not a known node id`
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (!nodeIds.has(edge.to)) {
|
|
137
|
+
errors.push({
|
|
138
|
+
path: `/edges/${index}/to`,
|
|
139
|
+
message: `Edge target "${edge.to}" is not a known node id`
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
doc.nodes.forEach((node, index) => {
|
|
144
|
+
if (node.group !== undefined && !groupIds.has(node.group)) {
|
|
145
|
+
errors.push({
|
|
146
|
+
path: `/nodes/${index}/group`,
|
|
147
|
+
message: `Group "${node.group}" is not a known group id`
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
groups.forEach((group, index) => {
|
|
152
|
+
if (group.parent !== undefined && !groupIds.has(group.parent)) {
|
|
153
|
+
errors.push({
|
|
154
|
+
path: `/groups/${index}/parent`,
|
|
155
|
+
message: `Parent group "${group.parent}" is not a known group id`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
for (const { index, cycle } of parentCycles(groups)) {
|
|
160
|
+
errors.push({
|
|
161
|
+
path: `/groups/${index}/parent`,
|
|
162
|
+
message: `Group parent cycle: ${cycle.join(" -> ")}`
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return errors;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/format/semantic/sequence.ts
|
|
169
|
+
function semanticSequenceErrors(doc) {
|
|
170
|
+
const errors = [];
|
|
171
|
+
const ids = checkUnique(doc.participants, "participants", "participant", errors);
|
|
172
|
+
doc.messages.forEach((message, index) => {
|
|
173
|
+
if (!ids.has(message.from)) {
|
|
174
|
+
errors.push({
|
|
175
|
+
path: `/messages/${index}/from`,
|
|
176
|
+
message: `Message sender "${message.from}" is not a known participant id`
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (!ids.has(message.to)) {
|
|
180
|
+
errors.push({
|
|
181
|
+
path: `/messages/${index}/to`,
|
|
182
|
+
message: `Message recipient "${message.to}" is not a known participant id`
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return errors;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/format/semantic/state.ts
|
|
190
|
+
function semanticStateErrors(doc) {
|
|
191
|
+
const errors = [];
|
|
192
|
+
const stateIds = checkUnique(doc.states, "states", "state", errors);
|
|
193
|
+
const transitions = doc.transitions ?? [];
|
|
194
|
+
checkUnique(transitions, "transitions", "transition", errors);
|
|
195
|
+
const pseudoOf = new Map;
|
|
196
|
+
for (const state of doc.states) {
|
|
197
|
+
if (!pseudoOf.has(state.id))
|
|
198
|
+
pseudoOf.set(state.id, state.pseudo);
|
|
199
|
+
}
|
|
200
|
+
const outgoing = new Map;
|
|
201
|
+
transitions.forEach((transition, index) => {
|
|
202
|
+
outgoing.set(transition.from, (outgoing.get(transition.from) ?? 0) + 1);
|
|
203
|
+
if (!stateIds.has(transition.from)) {
|
|
204
|
+
errors.push({
|
|
205
|
+
path: `/transitions/${index}/from`,
|
|
206
|
+
message: `Transition source "${transition.from}" is not a known state id`
|
|
207
|
+
});
|
|
208
|
+
} else if (pseudoOf.get(transition.from) === "final") {
|
|
209
|
+
errors.push({
|
|
210
|
+
path: `/transitions/${index}/from`,
|
|
211
|
+
message: `Transition out of a final pseudo-state "${transition.from}"`
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (!stateIds.has(transition.to)) {
|
|
215
|
+
errors.push({
|
|
216
|
+
path: `/transitions/${index}/to`,
|
|
217
|
+
message: `Transition target "${transition.to}" is not a known state id`
|
|
218
|
+
});
|
|
219
|
+
} else if (pseudoOf.get(transition.to) === "initial") {
|
|
220
|
+
errors.push({
|
|
221
|
+
path: `/transitions/${index}/to`,
|
|
222
|
+
message: `Transition into an initial pseudo-state "${transition.to}"`
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
const initialRegions = new Set;
|
|
227
|
+
doc.states.forEach((state, index) => {
|
|
228
|
+
if (state.parent !== undefined) {
|
|
229
|
+
if (!stateIds.has(state.parent)) {
|
|
230
|
+
errors.push({
|
|
231
|
+
path: `/states/${index}/parent`,
|
|
232
|
+
message: `Parent state "${state.parent}" is not a known state id`
|
|
233
|
+
});
|
|
234
|
+
} else if (pseudoOf.get(state.parent) !== undefined) {
|
|
235
|
+
errors.push({
|
|
236
|
+
path: `/states/${index}/parent`,
|
|
237
|
+
message: `Parent state "${state.parent}" is a pseudo-state and cannot contain states`
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (state.pseudo !== undefined && state.actions !== undefined && state.actions.length > 0) {
|
|
242
|
+
errors.push({
|
|
243
|
+
path: `/states/${index}/actions`,
|
|
244
|
+
message: "Pseudo-states carry no actions"
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
if (state.pseudo === "initial") {
|
|
248
|
+
const found = outgoing.get(state.id) ?? 0;
|
|
249
|
+
if (found !== 1) {
|
|
250
|
+
errors.push({
|
|
251
|
+
path: `/states/${index}`,
|
|
252
|
+
message: `Initial pseudo-state "${state.id}" needs exactly one outgoing transition (found ${found})`
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const region = state.parent ?? "root";
|
|
256
|
+
if (initialRegions.has(region)) {
|
|
257
|
+
errors.push({
|
|
258
|
+
path: `/states/${index}/pseudo`,
|
|
259
|
+
message: `More than one initial pseudo-state in region "${region}"`
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
initialRegions.add(region);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
for (const { index, cycle } of parentCycles(doc.states)) {
|
|
266
|
+
errors.push({
|
|
267
|
+
path: `/states/${index}/parent`,
|
|
268
|
+
message: `State parent cycle: ${cycle.join(" -> ")}`
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return errors;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/format/semantic/tree.ts
|
|
275
|
+
function semanticTreeErrors(doc) {
|
|
276
|
+
const errors = [];
|
|
277
|
+
const nodeIds = checkUnique(doc.nodes, "nodes", "node", errors);
|
|
278
|
+
doc.nodes.forEach((node, index) => {
|
|
279
|
+
if (node.parent !== undefined && !nodeIds.has(node.parent)) {
|
|
280
|
+
errors.push({
|
|
281
|
+
path: `/nodes/${index}/parent`,
|
|
282
|
+
message: `Parent node "${node.parent}" is not a known node id`
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
for (const { index, cycle } of parentCycles(doc.nodes)) {
|
|
287
|
+
errors.push({
|
|
288
|
+
path: `/nodes/${index}/parent`,
|
|
289
|
+
message: `Node parent cycle: ${cycle.join(" -> ")}`
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
let first;
|
|
293
|
+
doc.nodes.forEach((node, index) => {
|
|
294
|
+
if (node.parent !== undefined)
|
|
295
|
+
return;
|
|
296
|
+
if (first === undefined) {
|
|
297
|
+
first = node.id;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
errors.push({
|
|
301
|
+
path: `/nodes/${index}`,
|
|
302
|
+
message: `Second root "${node.id}": a tree has exactly one node without parent (first: "${first}")`
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
if (first === undefined) {
|
|
306
|
+
errors.push({
|
|
307
|
+
path: "/nodes",
|
|
308
|
+
message: "A tree needs exactly one root (a node without parent): found none"
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if (doc.layout === "mindmap" && doc.direction !== undefined) {
|
|
312
|
+
errors.push({
|
|
313
|
+
path: "/direction",
|
|
314
|
+
message: 'direction does not apply to layout "mindmap"'
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return errors;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/format/validate.ts
|
|
321
|
+
var DATE_TIME = /^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/;
|
|
322
|
+
var VERSION_MESSAGE = `Missing or unsupported version: this tool supports version ${FORMAT_VERSION2} only`;
|
|
323
|
+
if (!FormatRegistry.Has("date-time")) {
|
|
324
|
+
FormatRegistry.Set("date-time", (value) => DATE_TIME.test(value) && !Number.isNaN(Date.parse(value)));
|
|
325
|
+
}
|
|
326
|
+
function isRecord(value) {
|
|
327
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
328
|
+
}
|
|
329
|
+
function handler(schema, semantic) {
|
|
330
|
+
return { schema, semantic };
|
|
331
|
+
}
|
|
332
|
+
var KINDS = {
|
|
333
|
+
graph: handler(GraphDocumentSchema2, semanticGraphErrors),
|
|
334
|
+
sequence: handler(SequenceDocumentSchema2, semanticSequenceErrors),
|
|
335
|
+
state: handler(StateDocumentSchema2, semanticStateErrors),
|
|
336
|
+
er: handler(ErDocumentSchema2, semanticErErrors),
|
|
337
|
+
tree: handler(TreeDocumentSchema2, semanticTreeErrors)
|
|
338
|
+
};
|
|
339
|
+
var KIND_NAMES = Object.keys(KINDS).map((name) => JSON.stringify(name)).join(", ");
|
|
340
|
+
function structuralErrors(schema, input) {
|
|
341
|
+
const errors = [];
|
|
342
|
+
for (const error of Value.Errors(schema, input)) {
|
|
343
|
+
let message = error.message;
|
|
344
|
+
if (error.path === "/version") {
|
|
345
|
+
message = VERSION_MESSAGE;
|
|
346
|
+
} else if (error.type === ValueErrorType.Union) {
|
|
347
|
+
message = error.path.endsWith("/shape") ? `Expected one of ${SHAPES2.join(", ")}` : error.path.endsWith("/pseudo") ? `Expected one of ${PSEUDO2.join(", ")}` : error.path.endsWith("Cardinality") ? `Expected one of ${CARDINALITIES3.join(", ")}` : /\/keys\/\d+$/.test(error.path) ? `Expected one of ${KEYS2.join(", ")}` : error.path === "/layout" ? `Expected one of ${TREE_LAYOUTS2.join(", ")}` : "Expected a string, a number or a boolean";
|
|
348
|
+
} else if (error.type === ValueErrorType.ObjectAdditionalProperties) {
|
|
349
|
+
message = "Unexpected property";
|
|
350
|
+
} else if (error.type === ValueErrorType.StringFormat) {
|
|
351
|
+
message = `Expected a valid ${String(error.schema.format)} string`;
|
|
352
|
+
}
|
|
353
|
+
errors.push({ path: error.path, message });
|
|
354
|
+
}
|
|
355
|
+
return errors;
|
|
356
|
+
}
|
|
357
|
+
function validate2(input) {
|
|
358
|
+
if (!isRecord(input)) {
|
|
359
|
+
return {
|
|
360
|
+
ok: false,
|
|
361
|
+
errors: [{ path: "", message: "Expected a JSON object" }]
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
const { kind } = input;
|
|
365
|
+
const entry = typeof kind === "string" && Object.hasOwn(KINDS, kind) ? KINDS[kind] : undefined;
|
|
366
|
+
if (entry === undefined) {
|
|
367
|
+
const errors = [
|
|
368
|
+
{
|
|
369
|
+
path: "/kind",
|
|
370
|
+
message: kind === undefined ? `Missing kind: expected one of ${KIND_NAMES}` : `Unknown kind ${JSON.stringify(kind)}: expected one of ${KIND_NAMES}`
|
|
371
|
+
}
|
|
372
|
+
];
|
|
373
|
+
if (input.version !== FORMAT_VERSION2) {
|
|
374
|
+
errors.push({ path: "/version", message: VERSION_MESSAGE });
|
|
375
|
+
}
|
|
376
|
+
return { ok: false, errors };
|
|
377
|
+
}
|
|
378
|
+
const structural = structuralErrors(entry.schema, input);
|
|
379
|
+
if (structural.length > 0)
|
|
380
|
+
return { ok: false, errors: structural };
|
|
381
|
+
const semantic = entry.semantic(input);
|
|
382
|
+
if (semantic.length > 0)
|
|
383
|
+
return { ok: false, errors: semantic };
|
|
384
|
+
return { ok: true, document: input };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export { validate2 };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lightTheme
|
|
3
|
+
} from "./cli-5v9761s9.js";
|
|
4
|
+
import {
|
|
5
|
+
svgViewport,
|
|
6
|
+
renderPage,
|
|
7
|
+
renderWebglHtml2
|
|
8
|
+
} from "./cli-a4ax1vkc.js";
|
|
9
|
+
import {
|
|
10
|
+
renderSvg2
|
|
11
|
+
} from "./cli-wt9dmbhm.js";
|
|
12
|
+
import {
|
|
13
|
+
WEBGL_THRESHOLD2
|
|
14
|
+
} from "./cli-nyckgf1t.js";
|
|
15
|
+
|
|
16
|
+
// src/html/runtime.generated.ts
|
|
17
|
+
var RUNTIME_JS = '(()=>{var pe=1.25;var He={size:12,weight:"regular"};var ge=30,ye=20;var ut=Math.ceil(pe*He.size+6);function Pe(n,r){return n.x<=r.x+r.width&&r.x<=n.x+n.width&&n.y<=r.y+r.height&&r.y<=n.y+n.height}function be(n,r){let c=n.length,L=1/0,v=1/0,l=-1/0,T=-1/0;for(let{box:s}of n)L=Math.min(L,s.x),v=Math.min(v,s.y),l=Math.max(l,s.x+s.width),T=Math.max(T,s.y+s.height);if(c===0)L=v=0,l=T=1;let I=Math.max(1,l-L),g=Math.max(1,T-v),y=r??Math.max(32,Math.sqrt(I*g/Math.max(1,c))*2);while((Math.floor(I/y)+1)*(Math.floor(g/y)+1)>262144)y*=1.5;let D=Math.floor(I/y)+1,H=Math.floor(g/y)+1,O=new Map,A=[],_=(s)=>Math.min(D-1,Math.max(0,Math.floor((s-L)/y))),P=(s)=>Math.min(H-1,Math.max(0,Math.floor((s-v)/y)));n.forEach(({box:s},E)=>{let k=_(s.x),m=_(s.x+s.width),i=P(s.y),f=P(s.y+s.height);if((m-k+1)*(f-i+1)>64){A.push(E);return}for(let S=i;S<=f;S++)for(let C=k;C<=m;C++){let R=S*D+C,F=O.get(R);if(F===void 0)O.set(R,[E]);else F.push(E)}});let h=new Int32Array(c),a=0;function b(s){a+=1;let E=[],k=(m)=>{if(h[m]===a)return;h[m]=a;let i=n[m];if(Pe(i.box,s))E.push(i.value)};if(s.x<=l&&s.x+s.width>=L&&s.y<=T&&s.y+s.height>=v){let m=_(s.x),i=_(s.x+s.width),f=P(s.y),S=P(s.y+s.height);for(let C=f;C<=S;C++)for(let R=m;R<=i;R++){let F=O.get(C*D+R);if(F===void 0)continue;for(let G of F)k(G)}}for(let m of A)k(m);return E}return{size:c,query:b,at:(s,E)=>b({x:s,y:E,width:0,height:0})}}var Ee=new Set(["node","participant","state","entity"]);function ve(n){switch(n.kind){case"graph":return n.groups.length+n.nodes.length+n.edges.length;case"sequence":return n.participants.length+n.messages.length;case"state":return n.states.length+n.transitions.length;case"er":return n.entities.length+n.relations.length;case"tree":return n.nodes.length+n.edges.length;default:return Me(n)}}function Me(n){throw Error(`Unsupported scene: ${JSON.stringify(n)}`)}var De=0.05,$e=8,Be=7,ze=14,Ke=11,Fe=12,Ve=4,Xe=100,xe=16,se=new Set,we=0,ce=1,Q=2,Ge=3;function X(n,r){return`${n}:${r}`}function Ye(n,r,c,L,v,l){let T=v-c,I=l-L,g=T*T+I*I,y=g===0?0:Math.max(0,Math.min(1,((n-c)*T+(r-L)*I)/g));return Math.hypot(n-(c+y*T),r-(L+y*I))}function qe(n){let[r,c,L,v]=n;if(r===void 0||c===void 0||L===void 0||v===void 0)return[...n];let l=[];for(let T=0;T<xe;T++){let I=T/(xe-1),g=1-I,y=g*g*g,D=3*g*g*I,H=3*g*I*I,O=I*I*I;l.push({x:y*r.x+D*c.x+H*L.x+O*v.x,y:y*r.y+D*c.y+H*L.y+O*v.y})}return l}function Le(n,r,c){return r>=n.x&&r<=n.x+n.width&&c>=n.y&&c<=n.y+n.height}function We(n,r){if(n.length!==r.length)return!1;for(let c=0;c<n.length;c++)if(n[c]!==r[c])return!1;return!0}function Te(n,r={}){let c=r.minScale??De,L=r.maxScale??$e,v=r.padding??0,l=r.labelMinPx??Be,T=Math.max(1,n.width),I=Math.max(1,n.height),g=[],y=new Map,D=[],H=new Map,O=[];function A(t,e,o,d=0,p=!1){let w=g.length,x=X(t,e);return g.push({ref:{kind:t,id:e},key:x,depth:d,container:p,item:o}),y.set(x,w),w}function _(t,e,o,d,p,w){let x={x:Math.min(o,p),y:Math.min(d,w),width:Math.abs(p-o),height:Math.abs(w-d)};D.push({box:x,value:{entry:t,role:e,box:x,x1:o,y1:d,x2:p,y2:w}})}function P(t,e,o,d,p){_(t,we,e,o,e+d,o+p)}function h(t,e){let o=e[0];if(o===void 0)return;if(e.length===1)_(t,ce,o.x,o.y,o.x,o.y);for(let d=1;d<e.length;d++){let p=e[d-1],w=e[d];_(t,ce,p.x,p.y,w.x,w.y)}}function a(t,e){let o=H.get(t);if(o===void 0)H.set(t,o=new Set);o.add(e)}switch(n.kind){case"graph":{for(let e of n.groups){let o=A("group",e.id,e,e.depth,!0);P(o,e.x,e.y,e.width,e.height)}let t=[];for(let e of n.edges){let o=A("edge",e.id,e);if(t.push(o),h(o,e.points),e.labelBox!==void 0){let d=e.labelBox;_(o,Q,d.x,d.y,d.x+d.width,d.y+d.height)}}for(let e of n.nodes){let o=A("node",e.id,e);P(o,e.x,e.y,e.width,e.height),O.push({index:o,label:e.label.toLowerCase(),id:e.id.toLowerCase()})}n.edges.forEach((e,o)=>{let d=g[t[o]].key,p=X("node",e.from),w=X("node",e.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)});break}case"sequence":{for(let t of n.participants){let e=A("participant",t.id,t);P(e,t.x,t.y,t.width,t.height),_(e,Ge,t.lifelineX,t.y+t.height,t.lifelineX,n.lifelineBottom),O.push({index:e,label:t.label.toLowerCase(),id:t.id.toLowerCase()})}for(let t of n.messages){let e=String(t.index),o=A("message",e,t);if(t.self){let x=t.x1+ge,N=t.y+ye;h(o,[{x:t.x1,y:t.y},{x,y:t.y},{x,y:N},{x:t.x1,y:N}])}else h(o,[{x:t.x1,y:t.y},{x:t.x2,y:t.y}]);if(t.labelBox!==void 0){let x=t.labelBox;_(o,Q,x.x,x.y,x.x+x.width,x.y+x.height)}let d=g[o].key,p=X("participant",t.from),w=X("participant",t.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)}break}case"state":{let t=(o)=>{let d=A("state",o.id,o,o.depth,o.composite);P(d,o.x,o.y,o.width,o.height),O.push({index:d,label:o.label.toLowerCase(),id:o.id.toLowerCase()})};n.states.filter((o)=>o.composite).sort((o,d)=>o.depth-d.depth).forEach(t);let e=[];for(let o of n.transitions){let d=A("transition",o.id,o);if(e.push(d),h(d,o.points),o.labelBox!==void 0){let p=o.labelBox;_(d,Q,p.x,p.y,p.x+p.width,p.y+p.height)}}n.states.filter((o)=>!o.composite).forEach(t),n.transitions.forEach((o,d)=>{let p=g[e[d]].key,w=X("state",o.from),x=X("state",o.to);for(let[N,J]of[[w,x],[x,w]]){if(!y.has(N))continue;if(a(N,p),y.has(J))a(N,J)}if(y.has(w))a(p,w);if(y.has(x))a(p,x)});break}case"er":{let t=[];for(let e of n.relations){let o=A("relation",e.id,e);if(t.push(o),h(o,e.points),e.labelBox!==void 0){let d=e.labelBox;_(o,Q,d.x,d.y,d.x+d.width,d.y+d.height)}}for(let e of n.entities){let o=A("entity",e.id,e);P(o,e.x,e.y,e.width,e.height),O.push({index:o,label:[e.label,...e.attributes.map((d)=>d.name)].join(" ").toLowerCase(),id:e.id.toLowerCase()})}n.relations.forEach((e,o)=>{let d=g[t[o]].key,p=X("entity",e.from),w=X("entity",e.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)});break}case"tree":{let t=[];for(let e of n.edges){let o=A("edge",e.id,e);t.push(o),h(o,e.curve==="bezier"?qe(e.points):e.points)}for(let e of n.nodes){let o=A("node",e.id,e);P(o,e.x,e.y,e.width,e.height),O.push({index:o,label:e.label.toLowerCase(),id:e.id.toLowerCase()})}n.edges.forEach((e,o)=>{let d=g[t[o]].key,p=X("node",e.from),w=X("node",e.to);for(let[x,N]of[[p,w],[w,p]]){if(!y.has(x))continue;if(a(x,d),y.has(N))a(x,N)}if(y.has(p))a(d,p);if(y.has(w))a(d,w)});break}default:Me(n)}let b=be(D),s=g.length,E=new Int32Array(s),k=0,m={x:0,y:0,scale:1},i={width:0,height:0},f=-1,S=-1,C="",R=se,F={focused:!1,active:se},G=z(),Z=null,j=ne(1),ee=0,V=new Set,W=!1,te=new Set;function ne(t){return{labels:ze*t>=l,captions:Ke*t>=l,edgeLabels:Fe*t>=l}}function U(){let{width:t,height:e}=i;if(t<=0||e<=0)return c;let o=Math.min(Math.max(1,t-2*v)/T,Math.max(1,e-2*v)/I);return Math.min(c,o)}function u(t){return Math.min(L,Math.max(U(),t))}function M(t){if(t.x===m.x&&t.y===m.y&&t.scale===m.scale)return;m=t,V.add("camera"),W=!0}function z(){let{width:t,height:e}=i;if(t<=0||e<=0){let w=new Int32Array(s);for(let x=0;x<s;x++)w[x]=x;return w}let o=Xe/m.scale,d=b.query({x:-m.x/m.scale-o,y:-m.y/m.scale-o,width:t/m.scale+2*o,height:e/m.scale+2*o});k+=1;let p=[];for(let w of d){if(E[w.entry]===k)continue;E[w.entry]=k,p.push(w.entry)}return Int32Array.from(p).sort()}function ie(){if(!W)return;W=!1;let t=ne(m.scale);if(t.labels!==j.labels||t.captions!==j.captions||t.edgeLabels!==j.edgeLabels)j=t,V.add("lod");let e=z();if(!We(e,G))G=e,Z=null,V.add("visible")}function Ne(){if(ie(),V.size===0)return;let t=V;V=new Set;for(let e of[...te])e(t)}function q(t){ee+=1;try{t()}finally{if(ee-=1,ee===0)Ne()}}function me(){if(f>=0){let t=g[f],e=new Set([t.key]);for(let o of H.get(t.key)??[])e.add(o);F={focused:!0,active:e}}else if(C!=="")F={focused:!0,active:R};else F={focused:!1,active:se}}function ae(t){if(t===null)return-1;return y.get(X(t.kind,t.id))??-1}return{scene:n,camera:()=>({...m}),viewport:()=>({...i}),setViewport(t,e){if(t===i.width&&e===i.height)return;q(()=>{i={width:t,height:e},V.add("viewport"),W=!0})},setCamera(t){if(![t.x,t.y,t.scale].every(Number.isFinite)||t.scale<=0)return;q(()=>M({x:t.x,y:t.y,scale:u(t.scale)}))},fit(){let{width:t,height:e}=i;if(t<=0||e<=0)return;q(()=>{let o=Math.min(Math.max(1,t-2*v)/T,Math.max(1,e-2*v)/I),d=u(Math.min(o,1));M({scale:d,x:(t-n.width*d)/2,y:(e-n.height*d)/2})})},panBy(t,e){if(t===0&&e===0)return;q(()=>M({x:m.x+t,y:m.y+e,scale:m.scale}))},zoomAt(t,e,o){if(!Number.isFinite(t)||t<=0)return;q(()=>{let d=u(m.scale*t),p=d/m.scale;M({scale:d,x:e-(e-m.x)*p,y:o-(o-m.y)*p})})},screenToWorld:(t,e)=>({x:(t-m.x)/m.scale,y:(e-m.y)/m.scale}),worldToScreen:(t,e)=>({x:t*m.scale+m.x,y:e*m.scale+m.y}),hitTest(t,e){let o=(t-m.x)/m.scale,d=(e-m.y)/m.scale,p=Ve/m.scale,w=b.query({x:o-p,y:d-p,width:2*p,height:2*p}),x=-1,N=-1,J=1/0,de=-1,le=-1;for(let K of w){let oe=g[K.entry];if(K.role===we){if(!Le(K.box,o,d))continue;if(oe.container){if(oe.depth>le||oe.depth===le&&K.entry>de)de=K.entry,le=oe.depth}else if(K.entry>x)x=K.entry}else if(K.role===ce||K.role===Q){let re=K.role===Q?Le(K.box,o,d)?0:1/0:Ye(o,d,K.x1,K.y1,K.x2,K.y2);if(re<=p&&(re<J||re===J&&K.entry>N))N=K.entry,J=re}}let he=x>=0?x:N>=0?N:de;return he>=0?g[he].ref:null},visible(){if(Z===null)Z=Array.from(G,(t)=>g[t].ref);return{items:Z,count:G.length}},lod:()=>j,hover(t){let e=ae(t);if(e===f)return;q(()=>{f=e,me(),V.add("hover")})},select(t){let e=ae(t);if(e===S)return;q(()=>{S=e,V.add("selection")})},search(t){let e=t.trim().toLowerCase();if(e===C)return;q(()=>{if(C=e,e==="")R=se;else{let o=new Set;for(let d of O)if(d.label.includes(e)||d.id.includes(e))o.add(g[d.index].key);R=o}me(),V.add("search")})},hovered:()=>f>=0?g[f].ref:null,selected:()=>S>=0?g[S].ref:null,highlight:()=>F,item(t){let e=ae(t);return e>=0?g[e].item:void 0},subscribe(t){return te.add(t),()=>{te.delete(t)}},batch:q}}function Se(n){let{event:r,guard:c,action:L}=n;return[r,c===void 0?void 0:`[${c}]`,L===void 0?void 0:`/ ${L}`].filter((v)=>v!==void 0).join(" ")}var Ue=4,je=/^[\\s\\u0000-\\u001f]*(javascript|data|vbscript):/i,Ze;function Y(n){let r=(Ze??document).querySelector(`.${n}`);if(r===null)throw Error(`Missing element .${n}`);return r}function B(n,r,c){let L=document.createElement(n);if(r!==void 0)L.textContent=r;if(c!==void 0)L.className=c;return L}var Je={initial:"Initial",final:"Final",choice:"Choice",fork:"Fork",join:"Join",history:"History"},Qe={one:"1","zero-or-one":"0..1","one-or-more":"1..*","zero-or-more":"0..*"},ke="standargraph-scheme",ue=["auto","light","dark"];function et(){try{let n=localStorage.getItem(ke);return n==="light"||n==="dark"?n:"auto"}catch{return"auto"}}function tt(n){try{localStorage.setItem(ke,n)}catch{return}}function nt(n){let r=n.getAttribute("data-sg-scheme");return r==="light"||r==="dark"?r:"auto"}function Ie(n,r,c=!0){if(r==="auto")n.removeAttribute("data-sg-scheme");else n.setAttribute("data-sg-scheme",r);let L=n.querySelector(".sg-scheme");if(L!==null){let v=`Color scheme: ${r}`;L.textContent=r[0].toUpperCase()+r.slice(1),L.setAttribute("aria-label",v),L.title=v}if(c)tt(r);n.dispatchEvent(new CustomEvent("sg-scheme",{bubbles:!0,detail:r}))}function Ce(n){let r=n.querySelector(".sg-scheme");if(r===null)return;Ie(n,et(),!1),r.addEventListener("click",()=>{let c=ue[(ue.indexOf(nt(n))+1)%ue.length];Ie(n,c)})}function Oe(n,r,c){let L=r.kind==="graph"?r.edges??[]:[];function v(a){return L[a]?.id??`e${a}`}function l(a,b,s){let E=B("dt",b),k=B("dd");if(typeof s==="string")k.textContent=s;else k.appendChild(s);a.append(E,k)}function T(a){if(je.test(a))return document.createTextNode(a);let b=B("a",a);return b.href=a,b.target="_blank",b.rel="noopener noreferrer",b}function I(a,b){if(b===void 0)return;let s=b.provenance;if(s!==void 0){if(l(a,"Source",s.source),s.confidence!==void 0)l(a,"Confidence",s.confidence);if(s.tool!==void 0)l(a,"Tool",s.tool)}if(b.coverage!==void 0)l(a,"Coverage",`${Math.round(b.coverage*1000)/10}%`);if(b.freshness!==void 0){let E=new Date(b.freshness);l(a,"Freshness",Number.isNaN(E.getTime())?b.freshness:E.toLocaleString())}if(b.data!==void 0){let E=B("table",void 0,"sg-data");for(let[k,m]of Object.entries(b.data)){let i=B("tr");i.append(B("th",k),B("td",String(m))),E.appendChild(i)}l(a,"Data",E)}}let g=new Map;if(r.kind==="graph")r.nodes.forEach((a,b)=>g.set(a.id,b));let y=new Map;if(r.kind==="state")r.states.forEach((a,b)=>y.set(a.id,b));let D=new Map;if(r.kind==="er")r.entities.forEach((a,b)=>D.set(a.id,b));let H=new Map;if(r.kind==="tree")r.nodes.forEach((a,b)=>H.set(a.id,b));let O,A,_;function P(a,b){let s=B("dl"),E=b,k;if(a==="node"&&r.kind==="graph"){let i=r.nodes[g.get(b)??-1];if(i===void 0)return;if(E=i.label??i.id,k=i.meta,l(s,"Kind","Node"),i.type!==void 0)l(s,"Type",i.type);if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link))}else if(a==="node"&&r.kind==="tree"){let i=r.nodes[H.get(b)??-1];if(i===void 0)return;if(E=i.label,k=i.meta,l(s,"Kind","Node"),i.parent!==void 0){let S=r.nodes[H.get(i.parent)??-1];l(s,"Parent",S?.label??i.parent)}let f=n.item({kind:"node",id:b});if(f!==void 0&&"depth"in f)l(s,"Depth",String(f.depth));if(i.type!==void 0)l(s,"Type",i.type);if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link))}else if(a==="edge"&&r.kind==="graph"){if(O===void 0)O=new Map,L.forEach((f,S)=>{let C=v(S);if(!O.has(C))O.set(C,S)});let i=L[O.get(b)??-1];if(i===void 0)return;if(E=i.label??`${i.from} → ${i.to}`,k=i.meta,l(s,"Kind","Edge"),l(s,"Connection",`${i.from} → ${i.to}`),i.type!==void 0)l(s,"Type",i.type)}else if(a==="participant"&&r.kind==="sequence"){let i=r.participants.find((f)=>f.id===b);if(i===void 0)return;if(E=i.label??i.id,k=i.meta,l(s,"Kind","Participant"),i.type!==void 0)l(s,"Type",i.type)}else if(a==="message"&&r.kind==="sequence"){let i=r.messages[Number(b)];if(i===void 0)return;E=i.label??`${i.from} → ${i.to}`,k=i.meta,l(s,"Kind","Message"),l(s,"Connection",`${i.from} → ${i.to}`),l(s,"Style",i.style??"sync")}else if(a==="state"&&r.kind==="state"){let i=r.states[y.get(b)??-1];if(i===void 0)return;if(E=i.label??i.id,k=i.meta,l(s,"Kind",i.pseudo===void 0?"State":Je[i.pseudo]),i.type!==void 0)l(s,"Type",i.type);if(i.actions!==void 0&&i.actions.length>0){let f=B("div");for(let S of i.actions)f.appendChild(B("div",S));l(s,"Actions",f)}if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link))}else if(a==="transition"&&r.kind==="state"){let i=r.transitions??[];if(A===void 0)A=new Map,i.forEach((S,C)=>{let R=S.id??`t${C}`;if(!A.has(R))A.set(R,C)});let f=i[A.get(b)??-1];if(f===void 0)return;if(E=Se(f)||`${f.from} → ${f.to}`,k=f.meta,l(s,"Connection",`${f.from} → ${f.to}`),f.event!==void 0)l(s,"Event",f.event);if(f.guard!==void 0)l(s,"Guard",f.guard);if(f.action!==void 0)l(s,"Action",f.action);if(f.type!==void 0)l(s,"Type",f.type)}else if(a==="entity"&&r.kind==="er"){let i=r.entities[D.get(b)??-1];if(i===void 0)return;if(E=i.label??i.id,k=i.meta,i.type!==void 0)l(s,"Type",i.type);if(i.description!==void 0)l(s,"Description",i.description);if(i.link!==void 0)l(s,"Link",T(i.link));let f=i.attributes??[];if(f.length>0){let S=B("table",void 0,"sg-data"),C=B("tr");for(let R of["Name","Type","Keys","Null","Note"])C.appendChild(B("th",R));S.appendChild(C);for(let R of f){let F=B("tr");F.append(B("td",R.name),B("td",R.type??""),B("td",(R.keys??[]).join(", ")),B("td",R.nullable===!0?"yes":""),B("td",R.note??"")),S.appendChild(F)}l(s,"Attributes",S)}}else if(a==="relation"&&r.kind==="er"){let i=r.relations??[];if(_===void 0)_=new Map,i.forEach((S,C)=>{let R=S.id??`r${C}`;if(!_.has(R))_.set(R,C)});let f=i[_.get(b)??-1];if(f===void 0)return;if(E=f.label??`${f.from} → ${f.to}`,k=f.meta,l(s,"Connection",`${f.from} → ${f.to}`),f.fromCardinality!==void 0||f.toCardinality!==void 0){let S=(C)=>C===void 0?"-":Qe[C];l(s,"Cardinality",`${S(f.fromCardinality)} → ${S(f.toCardinality)}`)}if(l(s,"Identifying",f.identifying===!1?"no":"yes"),f.type!==void 0)l(s,"Type",f.type)}else return;I(s,k);let m=B("button","×","sg-close");m.type="button",m.setAttribute("aria-label","Close"),m.addEventListener("click",()=>n.select(null)),c.replaceChildren(m,B("h2",E),s),c.hidden=!1}let h=(a)=>{if(a.key==="Escape"&&!c.hidden)n.select(null)};return document.addEventListener("keydown",h),{update(){let a=n.selected();if(a===null){c.hidden=!0,c.replaceChildren();return}P(a.kind,a.id)},destroy(){document.removeEventListener("keydown",h)}}}function Re(n){let{view:r,viewport:c,search:L}=n,v=c.getBoundingClientRect(),l={pointer:null,dragging:!1,lastWheel:-1/0,rect:()=>v,resize:_,destroy(){P.disconnect()}},T=null,I=0,g=0,y=0,D=0,H=!1;c.addEventListener("pointerdown",(h)=>{if(h.button!==0)return;T=h.pointerId,I=h.clientX,g=h.clientY,y=h.clientX,D=h.clientY,H=!1}),c.addEventListener("pointermove",(h)=>{if(T===h.pointerId){let a=Math.hypot(h.clientX-I,h.clientY-g);if(!H&&a<Ue)return;if(!H)H=!0,l.dragging=!0,c.setPointerCapture(h.pointerId),c.classList.add("sg-dragging");r.panBy(h.clientX-y,h.clientY-D),y=h.clientX,D=h.clientY;return}if(T!==null)return;l.pointer={x:h.clientX-v.left,y:h.clientY-v.top},n.onPointer()});function O(h){if(T!==h.pointerId)return;T=null,l.dragging=!1,c.classList.remove("sg-dragging")}c.addEventListener("pointerup",O),c.addEventListener("pointercancel",O),c.addEventListener("click",(h)=>{if(H){H=!1,h.preventDefault();return}let a=n.pick(h,h.clientX-v.left,h.clientY-v.top);if(a!==null)h.preventDefault(),r.select(a);else if(h.target instanceof Element&&h.target.closest("a")!==null)h.preventDefault()}),c.addEventListener("wheel",(h)=>{h.preventDefault(),l.lastWheel=performance.now(),r.zoomAt(Math.exp(-h.deltaY*0.0015),h.clientX-v.left,h.clientY-v.top)},{passive:!1}),c.addEventListener("mouseleave",()=>{l.pointer=null,r.hover(null)});function A(h){let a=r.viewport();r.zoomAt(h,a.width/2,a.height/2)}Y("sg-zoom-in").addEventListener("click",()=>A(1.25)),Y("sg-zoom-out").addEventListener("click",()=>A(0.8)),Y("sg-fit").addEventListener("click",()=>r.fit()),L.addEventListener("input",()=>r.search(L.value));function _(){v=c.getBoundingClientRect(),r.batch(()=>{r.setViewport(c.clientWidth,c.clientHeight),r.fit()}),n.onResize?.()}let P=new ResizeObserver(_);return P.observe(c),r.batch(()=>{r.setViewport(c.clientWidth,c.clientHeight),r.fit()}),l}var fe=150,it=400;function Ae(n,r){let c=Y("sg-viewport"),L=Y("sg-stage"),v=Y("sg-panel"),l=Y("sg-search"),T=L.querySelector("svg");if(T===null)return;let I=T;Ce(Y("sg-app"));let g=Te(r),y=Oe(g,n,v),D=new Map;for(let u of I.querySelectorAll("[data-kind]"))D.set(`${u.getAttribute("data-kind")}:${u.getAttribute("data-id")}`,u);let H=new Map;function O(u){let M=H.get(u);if(M===void 0){if(M=D.get(`${u.kind}:${u.id}`),M!==void 0)H.set(u,M)}return M}let A=ve(r)>it,_=0,P=0,h=!1,a=!1,b=!1,s=new Set,E=new Set(g.visible().items),k=new Set,m=!1,i=null;function f(){if(_=performance.now(),!h)h=!0,L.style.willChange="transform";if(P===0)P=window.setTimeout(S,fe)}function S(){let u=fe-(performance.now()-_);if(u>1){P=window.setTimeout(S,u);return}if(P=0,h=!1,L.style.willChange="",b)G();if(U.pointer!==null)W()}function C(){let u=g.camera();L.style.transform=`translate(${u.x}px, ${u.y}px) scale(${u.scale})`}function R(){let u=g.lod();I.classList.toggle("sg-lod-nolabels",!u.labels),I.classList.toggle("sg-lod-nocaptions",!u.captions),I.classList.toggle("sg-lod-noedgelabels",!u.edgeLabels)}function F(){let{focused:u,active:M}=g.highlight();if(u!==m)I.classList.toggle("sg-focus",u),m=u;for(let z of k)if(!M.has(z))D.get(z)?.classList.remove("sg-hl");for(let z of M)if(!k.has(z))D.get(z)?.classList.add("sg-hl");k=M}function G(){b=!1;let u=new Set(g.visible().items);for(let M of E){if(u.has(M))continue;let z=O(M);if(z instanceof SVGElement)z.style.display="none"}for(let M of u){if(E.has(M))continue;let z=O(M);if(z instanceof SVGElement)z.style.display=""}E=u}function Z(){b=!0;let u=g.visible().items,M=new Set(E);for(let z of u){if(M.has(z))continue;let ie=O(z);if(ie instanceof SVGElement)ie.style.display="";M.add(z)}E=M}function j(){let u=U.pointer;if(u===null||U.dragging)return;if(performance.now()-U.lastWheel<fe)return;let M=g.hitTest(u.x,u.y);U.pointer=null,g.hover(M!==null&&ee(M)?M:null)}function ee(u){if(!Ee.has(u.kind))return!1;return u.kind!=="state"||g.item({kind:"state",id:u.id})?.composite!==!0}function V(){j(),a=!1;let u=s;if(s=new Set,u.has("camera"))C();if(u.has("lod"))R();if(u.has("hover")||u.has("search"))F();if(A&&u.has("visible"))if(h)Z();else G()}function W(){if(a)return;a=!0,requestAnimationFrame(V)}g.subscribe((u)=>{if(u.has("selection"))te();if(u.has("camera"))f();for(let M of u)s.add(M);W()});function te(){i?.classList.remove("sg-selected"),i=null;let u=g.selected();if(u!==null)i=O(u)??null,i?.classList.add("sg-selected");y.update()}function ne(u){if(!(u instanceof Element))return null;let M=u.closest("[data-kind]");if(M===null||M.getAttribute("data-kind")==="group")return null;return{kind:M.getAttribute("data-kind")??"",id:M.getAttribute("data-id")??""}}let U=Re({view:g,viewport:c,search:l,pick:(u)=>ne(u.target),onPointer:W});if(C(),R(),A)G();return Y("sg-app").dataset.sgReady="1",{view:g,destroy(){U.destroy(),y.destroy(),clearTimeout(P)}}}function _e(n){return JSON.parse(document.getElementById(n).textContent??"{}")}Ae(_e("standargraph-document"),_e("standargraph-scene"));})();';
|
|
18
|
+
|
|
19
|
+
// src/html/render.ts
|
|
20
|
+
function renderHtml2(document, laidOut, options = {}) {
|
|
21
|
+
const renderer = options.renderer ?? "auto";
|
|
22
|
+
const useWebgl = laidOut.kind === "graph" && (renderer === "webgl" || renderer === "auto" && laidOut.nodes.length > WEBGL_THRESHOLD2);
|
|
23
|
+
if (useWebgl)
|
|
24
|
+
return renderWebglHtml2(document, laidOut, options);
|
|
25
|
+
const theme = options.theme ?? "auto";
|
|
26
|
+
const svg = renderSvg2(laidOut, {
|
|
27
|
+
theme: lightTheme(theme),
|
|
28
|
+
standalone: false
|
|
29
|
+
}).trim();
|
|
30
|
+
return renderPage({
|
|
31
|
+
document,
|
|
32
|
+
laidOut,
|
|
33
|
+
options,
|
|
34
|
+
viewport: svgViewport(svg),
|
|
35
|
+
runtime: RUNTIME_JS
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { renderHtml2 };
|
package/dist/cli.d.ts
ADDED