@sccharts-lab/diagram 0.0.0-stage → 0.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.
- package/LICENSE +277 -0
- package/README.md +169 -2
- package/dist/dataflow.d.ts +18 -0
- package/dist/dataflow.js +216 -0
- package/dist/dataflow.js.map +1 -0
- package/dist/diagram.css +521 -0
- package/dist/elk-types.d.ts +50 -0
- package/dist/elk-types.js +5 -0
- package/dist/elk-types.js.map +1 -0
- package/dist/elk-worker.d.ts +10 -0
- package/dist/elk-worker.js +18 -0
- package/dist/elk-worker.js.map +1 -0
- package/dist/font-metrics.d.ts +13 -0
- package/dist/font-metrics.js +23 -0
- package/dist/font-metrics.js.map +1 -0
- package/dist/fonts/atkinson-hyperlegible-mono-latin-ext-wght-normal.woff2 +0 -0
- package/dist/fonts/atkinson-hyperlegible-mono-latin-wght-normal.woff2 +0 -0
- package/dist/fonts/atkinson-hyperlegible-mono.LICENSE.txt +93 -0
- package/dist/fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2 +0 -0
- package/dist/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2 +0 -0
- package/dist/fonts/atkinson-hyperlegible-next.LICENSE.txt +93 -0
- package/dist/fonts.css +42 -0
- package/dist/geometry.d.ts +24 -0
- package/dist/geometry.js +115 -0
- package/dist/geometry.js.map +1 -0
- package/dist/highlight.d.ts +35 -0
- package/dist/highlight.js +83 -0
- package/dist/highlight.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +6 -0
- package/dist/layout.js +838 -0
- package/dist/layout.js.map +1 -0
- package/dist/measure.d.ts +23 -0
- package/dist/measure.js +73 -0
- package/dist/measure.js.map +1 -0
- package/dist/render.d.ts +3 -0
- package/dist/render.js +327 -0
- package/dist/render.js.map +1 -0
- package/dist/types.d.ts +221 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/package.json +70 -3
package/dist/render.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// renderSvg: draws a DiagramLayout as SVG markup in KIELER's notation. Pure and deterministic.
|
|
2
|
+
//
|
|
3
|
+
// Colours are not in the markup: every element carries stable classes (sc-state, sc-transition, ...) that
|
|
4
|
+
// diagram.css colours through the --sc-* custom properties, and a simulation highlights by toggling classes
|
|
5
|
+
// (is-active, is-taken, ...) on the elements with the matching data-id. The only definition, a fade mask for
|
|
6
|
+
// KIELER's state gradients, is theme-independent.
|
|
7
|
+
import { endTangent, flatten, pathData, place, r2, sampleAt } from "./geometry.js";
|
|
8
|
+
import { MONO_FAMILY, SANS_FAMILY } from "./measure.js";
|
|
9
|
+
const MARGIN = 6;
|
|
10
|
+
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
11
|
+
const num = (n) => String(r2(n));
|
|
12
|
+
function hash(s) {
|
|
13
|
+
let h = 2166136261;
|
|
14
|
+
for (let i = 0; i < s.length; i++) {
|
|
15
|
+
h ^= s.charCodeAt(i);
|
|
16
|
+
h = Math.imul(h, 16777619);
|
|
17
|
+
}
|
|
18
|
+
return (h >>> 0).toString(36);
|
|
19
|
+
}
|
|
20
|
+
function cls(base, id, extra) {
|
|
21
|
+
const all = id && extra?.[id] ? [...base, ...extra[id]] : base;
|
|
22
|
+
return all.join(' ');
|
|
23
|
+
}
|
|
24
|
+
function polygon(points) {
|
|
25
|
+
return 'M' + points.map(p => `${num(p.x)} ${num(p.y)}`).join('L') + 'Z';
|
|
26
|
+
}
|
|
27
|
+
/** A rounded rectangle as a path (so a stroke can be drawn inside a highlight without SVG rx quirks). */
|
|
28
|
+
function rect(x, y, w, h, r) {
|
|
29
|
+
const rr = Math.max(0, Math.min(r, w / 2, h / 2));
|
|
30
|
+
return `x="${num(x)}" y="${num(y)}" width="${num(w)}" height="${num(h)}"${rr ? ` rx="${num(rr)}"` : ''}`;
|
|
31
|
+
}
|
|
32
|
+
function textLine(line, extraClass = '') {
|
|
33
|
+
const classes = ['sc-text', `sc-${line.role}`];
|
|
34
|
+
if (line.bold)
|
|
35
|
+
classes.push('sc-bold');
|
|
36
|
+
if (line.mono)
|
|
37
|
+
classes.push('sc-mono');
|
|
38
|
+
if (extraClass)
|
|
39
|
+
classes.push(extraClass);
|
|
40
|
+
const ids = line.ids?.length ? ` data-id="${esc(line.ids[0])}"${line.ids.length > 1 ? ` data-ids="${esc(line.ids.join(' '))}"` : ''}` : '';
|
|
41
|
+
const spans = line.runs.map(run => {
|
|
42
|
+
const runCls = run.format === 'keyword' ? 'sc-kw' : run.format === 'highlight' ? 'sc-hl' : run.format === 'schedule' ? 'sc-sd' : '';
|
|
43
|
+
return `<tspan x="${num(line.x + run.dx)}"${runCls ? ` class="${runCls}"` : ''}>${esc(run.text)}</tspan>`;
|
|
44
|
+
}).join('');
|
|
45
|
+
return `<text class="${classes.join(' ')}" y="${num(line.y)}" font-size="${line.size}"${ids}>${spans}</text>`;
|
|
46
|
+
}
|
|
47
|
+
function renderState(s, ctx) {
|
|
48
|
+
const base = ['sc-state'];
|
|
49
|
+
if (s.shape === 'root')
|
|
50
|
+
base.push('sc-root', 'sc-superstate');
|
|
51
|
+
else if (s.shape === 'superstate')
|
|
52
|
+
base.push('sc-superstate');
|
|
53
|
+
else if (s.shape === 'connector')
|
|
54
|
+
base.push('sc-connector');
|
|
55
|
+
else
|
|
56
|
+
base.push('sc-simple');
|
|
57
|
+
if (s.initial)
|
|
58
|
+
base.push('sc-initial');
|
|
59
|
+
if (s.final)
|
|
60
|
+
base.push('sc-final');
|
|
61
|
+
if (s.reference)
|
|
62
|
+
base.push('sc-reference');
|
|
63
|
+
if (s.violation)
|
|
64
|
+
base.push('sc-violation');
|
|
65
|
+
if (s.violation && s.finalInset && !s.final)
|
|
66
|
+
base.push('sc-halt');
|
|
67
|
+
const out = [`<g class="${cls(base, s.id, ctx.classes)}" data-id="${esc(s.id)}">`];
|
|
68
|
+
if (s.shape === 'connector') {
|
|
69
|
+
out.push(`<circle class="sc-shape" cx="${num(s.x + s.width / 2)}" cy="${num(s.y + s.height / 2)}" r="${num(s.width / 2 - 0.5)}"/>`);
|
|
70
|
+
out.push('</g>');
|
|
71
|
+
return out.join('');
|
|
72
|
+
}
|
|
73
|
+
if (ctx.shadows)
|
|
74
|
+
out.push(`<rect class="sc-shadow" ${rect(s.x + 3, s.y + 3, s.width, s.height, s.radius)}/>`);
|
|
75
|
+
// KIELER's vertical gradient: the end colour, the top colour faded out by a (theme-independent) mask, then
|
|
76
|
+
// the border on top. Colours come from CSS, so the markup is the same in every theme.
|
|
77
|
+
const figure = (x, y, w, h, r, extra = '') => {
|
|
78
|
+
const g = rect(x, y, w, h, r);
|
|
79
|
+
return `<rect class="sc-fill" ${g}/><rect class="sc-fill-top" ${g} mask="url(#${ctx.prefix}-fade)"/><rect class="sc-shape${extra}" ${g}/>`;
|
|
80
|
+
};
|
|
81
|
+
const inset = s.finalInset ?? 0;
|
|
82
|
+
if (s.shape === 'root') {
|
|
83
|
+
out.push(`<rect class="sc-shape" ${rect(s.x, s.y, s.width, s.height, s.radius)}/>`);
|
|
84
|
+
}
|
|
85
|
+
else if (inset) {
|
|
86
|
+
// Final state: an outer border, then the figure `inset` inside it.
|
|
87
|
+
out.push(`<rect class="sc-shape sc-final-outer" ${rect(s.x, s.y, s.width, s.height, s.radius)}/>`);
|
|
88
|
+
out.push(figure(s.x + inset, s.y + inset, s.width - 2 * inset, s.height - 2 * inset, s.radius - inset, ' sc-final-inner'));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
out.push(figure(s.x, s.y, s.width, s.height, s.radius));
|
|
92
|
+
}
|
|
93
|
+
for (const line of s.lines)
|
|
94
|
+
out.push(textLine(line));
|
|
95
|
+
for (const r of s.regions)
|
|
96
|
+
out.push(renderRegion(r, ctx));
|
|
97
|
+
out.push('</g>');
|
|
98
|
+
return out.join('');
|
|
99
|
+
}
|
|
100
|
+
function renderRegion(r, ctx) {
|
|
101
|
+
const base = ['sc-region'];
|
|
102
|
+
if (r.dataflow)
|
|
103
|
+
base.push('sc-dataflow');
|
|
104
|
+
if (r.collapsed)
|
|
105
|
+
base.push('sc-collapsed');
|
|
106
|
+
if (r.final)
|
|
107
|
+
base.push('sc-final-region');
|
|
108
|
+
if (r.abort)
|
|
109
|
+
base.push('sc-abort-region');
|
|
110
|
+
if (r.override)
|
|
111
|
+
base.push('sc-override-region');
|
|
112
|
+
if (r.reference)
|
|
113
|
+
base.push('sc-reference-region');
|
|
114
|
+
if (r.method)
|
|
115
|
+
base.push('sc-method', `sc-method-${r.method}`);
|
|
116
|
+
const out = [`<g class="${cls(base, r.id, ctx.classes)}" data-id="${esc(r.id)}">`];
|
|
117
|
+
out.push(`<rect class="sc-region-frame" ${rect(r.x, r.y, r.width, r.height, 0)}/>`);
|
|
118
|
+
if (r.final)
|
|
119
|
+
out.push(`<rect class="sc-region-frame sc-region-frame-inner" ${rect(r.x + 3, r.y + 3, r.width - 6, r.height - 6, 0)}/>`);
|
|
120
|
+
if (ctx.regionCorner && !r.empty) {
|
|
121
|
+
// KIELER's expand/collapse button: "-" when expanded, "+" when collapsed, blank for an abstract method.
|
|
122
|
+
const x = r.x + 0.5, y = r.y + 0.5;
|
|
123
|
+
out.push(`<path class="sc-region-corner" d="M${num(x)} ${num(y)}L${num(x)} ${num(y + 19.5)}L${num(x + 19.5)} ${num(y)}Z"/>`);
|
|
124
|
+
if (r.method !== 'abstract') {
|
|
125
|
+
const mark = r.collapsed || r.reference ? `M${num(x + 2.5)} ${num(y + 5.5)}h6M${num(x + 5.5)} ${num(y + 2.5)}v6` : `M${num(x + 2.5)} ${num(y + 5.5)}h5`;
|
|
126
|
+
out.push(`<path class="sc-region-corner-mark" d="${mark}"/>`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (r.label)
|
|
130
|
+
out.push(textLine(r.label));
|
|
131
|
+
for (const line of r.lines)
|
|
132
|
+
out.push(textLine(line));
|
|
133
|
+
if (r.circuit)
|
|
134
|
+
out.push(renderCircuit(r.circuit));
|
|
135
|
+
for (const s of r.states)
|
|
136
|
+
out.push(renderState(s, ctx));
|
|
137
|
+
for (const t of r.transitions)
|
|
138
|
+
out.push(renderTransition(t, ctx));
|
|
139
|
+
for (const c of r.comments)
|
|
140
|
+
out.push(renderComment(c));
|
|
141
|
+
out.push('</g>');
|
|
142
|
+
return out.join('');
|
|
143
|
+
}
|
|
144
|
+
// KLighD's head arrow (KPolylineExtensions.addHeadArrowDecorator): 8 long, 6 wide, notched, its tip 2 px
|
|
145
|
+
// past the decorator's origin.
|
|
146
|
+
const ARROW = [[-6, -3], [-2.8, 0], [-6, 3], [2, 0]];
|
|
147
|
+
// TransitionStyles.addNormalTerminationDecorator: an 11 × 11 triangle pointing along the edge.
|
|
148
|
+
const TRIANGLE = [[-5.5, -5.5], [5.5, 0], [-5.5, 5.5]];
|
|
149
|
+
function renderTransition(t, ctx) {
|
|
150
|
+
const base = ['sc-transition'];
|
|
151
|
+
if (t.immediate)
|
|
152
|
+
base.push('sc-immediate');
|
|
153
|
+
if (t.preemption === 'strong')
|
|
154
|
+
base.push('sc-strong');
|
|
155
|
+
if (t.preemption === 'termination')
|
|
156
|
+
base.push('sc-termination');
|
|
157
|
+
if (t.history)
|
|
158
|
+
base.push('sc-history', `sc-history-${t.history}`);
|
|
159
|
+
if (t.deferred)
|
|
160
|
+
base.push('sc-deferred');
|
|
161
|
+
if (t.nondeterministic)
|
|
162
|
+
base.push('sc-nondeterministic');
|
|
163
|
+
else if (t.probability !== undefined && t.probability > 0)
|
|
164
|
+
base.push('sc-probabilistic');
|
|
165
|
+
const d = pathData(t.points);
|
|
166
|
+
const poly = flatten(t.points);
|
|
167
|
+
const out = [`<g class="${cls(base, t.id, ctx.classes)}" data-id="${esc(t.id)}">`];
|
|
168
|
+
if (t.points.length < 2) {
|
|
169
|
+
// ELK found no route (should not happen); keep the element so highlighting still finds it.
|
|
170
|
+
if (t.label)
|
|
171
|
+
out.push(renderLabel(t.label));
|
|
172
|
+
out.push('</g>');
|
|
173
|
+
return out.join('');
|
|
174
|
+
}
|
|
175
|
+
out.push(`<path class="sc-edge-hit" d="${d}"/>`);
|
|
176
|
+
out.push(`<path class="sc-edge" d="${d}"/>`);
|
|
177
|
+
// Head decorators (TransitionStyles): the arrow moves back to make room for history/deferred markers.
|
|
178
|
+
let arrowAt = -2;
|
|
179
|
+
if (t.history)
|
|
180
|
+
arrowAt = t.deferred ? -26 : -17;
|
|
181
|
+
else if (t.deferred)
|
|
182
|
+
arrowAt = -11;
|
|
183
|
+
const head = arrowAt === -2 ? { point: sampleAt(poly, -2).point, tangent: endTangent(t.points) } : sampleAt(poly, arrowAt);
|
|
184
|
+
out.push(`<path class="sc-arrow" d="${polygon(place(head.point, head.tangent, ARROW))}"/>`);
|
|
185
|
+
if (t.history) {
|
|
186
|
+
const at = sampleAt(poly, -6).point;
|
|
187
|
+
const deep = t.history === 'deep';
|
|
188
|
+
// The circled H (H* for deep history), KLighD's polyline letter.
|
|
189
|
+
const hx = deep ? -5 : -3, hw = 6;
|
|
190
|
+
const letter = `M${num(at.x + hx)} ${num(at.y - 4)}V${num(at.y + 4)}M${num(at.x + hx)} ${num(at.y)}H${num(at.x + hx + hw)}M${num(at.x + hx + hw)} ${num(at.y - 4)}V${num(at.y + 4)}`;
|
|
191
|
+
const star = deep ? `<path class="sc-history-star" d="M${num(at.x + 4)} ${num(at.y - 5)}v4M${num(at.x + 2.27)} ${num(at.y - 4)}l3.46 2M${num(at.x + 2.27)} ${num(at.y - 2)}l3.46 -2"/>` : '';
|
|
192
|
+
out.push(`<g class="sc-history-marker"><circle cx="${num(at.x)}" cy="${num(at.y)}" r="8"/><path class="sc-history-letter" d="${letter}"/>${star}</g>`);
|
|
193
|
+
}
|
|
194
|
+
if (t.deferred) {
|
|
195
|
+
const at = sampleAt(poly, t.history ? -19 : -4).point;
|
|
196
|
+
const star = t.deferred === 'deep' ? `<path class="sc-deferred-star" d="M${num(at.x)} ${num(at.y - 3)}v6M${num(at.x - 2.6)} ${num(at.y - 1.5)}l5.2 3M${num(at.x - 2.6)} ${num(at.y + 1.5)}l5.2 -3"/>` : '';
|
|
197
|
+
out.push(`<g class="sc-deferred-marker"><circle cx="${num(at.x)}" cy="${num(at.y)}" r="5"/>${star}</g>`);
|
|
198
|
+
}
|
|
199
|
+
// Tail decorators.
|
|
200
|
+
if (t.preemption === 'strong') {
|
|
201
|
+
const at = sampleAt(poly, 4).point;
|
|
202
|
+
out.push(`<circle class="sc-strong-marker" cx="${num(at.x)}" cy="${num(at.y)}" r="5"/>`);
|
|
203
|
+
}
|
|
204
|
+
else if (t.preemption === 'termination') {
|
|
205
|
+
const at = sampleAt(poly, 5);
|
|
206
|
+
out.push(`<path class="sc-termination-marker" d="${polygon(place(at.point, at.tangent, TRIANGLE))}"/>`);
|
|
207
|
+
}
|
|
208
|
+
for (const c of t.comments ?? [])
|
|
209
|
+
out.push(renderLabel(c, 'sc-label sc-label-comment'));
|
|
210
|
+
if (t.label)
|
|
211
|
+
out.push(renderLabel(t.label));
|
|
212
|
+
out.push('</g>');
|
|
213
|
+
return out.join('');
|
|
214
|
+
}
|
|
215
|
+
function renderLabel(l, className = 'sc-label') {
|
|
216
|
+
const { x, y, width: w, height: h } = l;
|
|
217
|
+
const out = [`<g class="${className}">`];
|
|
218
|
+
out.push(`<rect class="sc-label-bg" ${rect(x, y, w, h, 0)}/>`);
|
|
219
|
+
// LabelPlacementSideHook (on-edge labels): bars across the edge at both ends, a small arrow pointing on.
|
|
220
|
+
let bars, arrow;
|
|
221
|
+
if (l.direction === 'right' || l.direction === 'left') {
|
|
222
|
+
bars = `M${num(x + 0.5)} ${num(y)}V${num(y + h)}M${num(x + w - 0.5)} ${num(y)}V${num(y + h)}`;
|
|
223
|
+
const cy = y + h / 2;
|
|
224
|
+
arrow = l.direction === 'right'
|
|
225
|
+
? [{ x: x + w, y: cy - 4 }, { x: x + w + 4, y: cy }, { x: x + w, y: cy + 4 }]
|
|
226
|
+
: [{ x, y: cy - 4 }, { x: x - 4, y: cy }, { x, y: cy + 4 }];
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
bars = `M${num(x)} ${num(y + 0.5)}H${num(x + w)}M${num(x)} ${num(y + h - 0.5)}H${num(x + w)}`;
|
|
230
|
+
const cx = x + w / 2;
|
|
231
|
+
arrow = l.direction === 'down'
|
|
232
|
+
? [{ x: cx - 4, y: y + h }, { x: cx, y: y + h + 4 }, { x: cx + 4, y: y + h }]
|
|
233
|
+
: [{ x: cx - 4, y }, { x: cx, y: y - 4 }, { x: cx + 4, y }];
|
|
234
|
+
}
|
|
235
|
+
out.push(`<path class="sc-label-bars" d="${bars}"/>`);
|
|
236
|
+
out.push(`<path class="sc-label-arrow" d="${polygon(arrow)}"/>`);
|
|
237
|
+
for (const line of l.lines)
|
|
238
|
+
out.push(textLine(line));
|
|
239
|
+
out.push('</g>');
|
|
240
|
+
return out.join('');
|
|
241
|
+
}
|
|
242
|
+
function renderComment(c) {
|
|
243
|
+
const out = [`<g class="sc-comment" data-id="${esc(c.id)}">`];
|
|
244
|
+
if (c.points?.length)
|
|
245
|
+
out.push(`<path class="sc-comment-edge" d="${pathData(c.points)}"/>`);
|
|
246
|
+
// CommentStyles.addCommentFigure: a rectangle with 1 px corners.
|
|
247
|
+
out.push(`<rect class="sc-comment-box" ${rect(c.x, c.y, c.width, c.height, 1)}/>`);
|
|
248
|
+
for (const line of c.lines)
|
|
249
|
+
out.push(textLine(line));
|
|
250
|
+
out.push('</g>');
|
|
251
|
+
return out.join('');
|
|
252
|
+
}
|
|
253
|
+
function renderCircuit(c) {
|
|
254
|
+
const out = ['<g class="sc-circuit">'];
|
|
255
|
+
for (const w of c.wires)
|
|
256
|
+
out.push(`<path class="sc-wire" data-id="${esc(w.id)}" d="${pathData(w.points)}"/>`);
|
|
257
|
+
for (const n of c.nodes) {
|
|
258
|
+
const { x, y, width: w, height: h } = n;
|
|
259
|
+
let shape;
|
|
260
|
+
if (n.kind === 'input')
|
|
261
|
+
shape = `<path class="sc-df-shape" d="M${num(x)} ${num(y)}H${num(x + w - 6)}L${num(x + w)} ${num(y + h / 2)}L${num(x + w - 6)} ${num(y + h)}H${num(x)}Z"/>`;
|
|
262
|
+
else if (n.kind === 'output')
|
|
263
|
+
shape = `<path class="sc-df-shape" d="M${num(x)} ${num(y)}H${num(x + w - 6)}L${num(x + w)} ${num(y + h / 2)}L${num(x + w - 6)} ${num(y + h)}H${num(x)}L${num(x + 6)} ${num(y + h / 2)}Z"/>`;
|
|
264
|
+
else if (n.kind === 'actor')
|
|
265
|
+
shape = `<rect class="sc-df-shape" ${rect(x, y, w, h, 4)}/><path class="sc-df-divider" d="M${num(x)} ${num(n.lines[0].y + 4)}H${num(x + w)}"/>`;
|
|
266
|
+
else
|
|
267
|
+
shape = `<rect class="sc-df-shape" ${rect(x, y, w, h, n.kind === 'constant' ? 0 : 3)}/>`;
|
|
268
|
+
out.push(`<g class="sc-df-node sc-df-${n.kind}" data-id="${esc(n.id)}">${shape}${n.lines.map((l, i) => textLine(l, n.kind === 'actor' && i > 0 ? 'sc-df-port' : '')).join('')}</g>`);
|
|
269
|
+
}
|
|
270
|
+
out.push('</g>');
|
|
271
|
+
return out.join('');
|
|
272
|
+
}
|
|
273
|
+
function describe(layout) {
|
|
274
|
+
const states = [];
|
|
275
|
+
const transitions = [];
|
|
276
|
+
const name = (id) => id.slice(id.lastIndexOf('.') + 1);
|
|
277
|
+
const walk = (s) => {
|
|
278
|
+
for (const r of s.regions) {
|
|
279
|
+
for (const c of r.states) {
|
|
280
|
+
const kind = [c.initial && 'initial', c.final && 'final', c.shape === 'connector' && 'connector', c.shape === 'superstate' && 'superstate'].filter(Boolean);
|
|
281
|
+
states.push(name(c.id) + (kind.length ? ` (${kind.join(', ')})` : ''));
|
|
282
|
+
walk(c);
|
|
283
|
+
}
|
|
284
|
+
for (const t of r.transitions) {
|
|
285
|
+
const label = t.label ? ': ' + t.label.lines.map(l => l.runs.map(x => x.text).join(' ')).join(' ') : '';
|
|
286
|
+
transitions.push(`${name(t.source)} to ${name(t.target)}${label}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
walk(layout.root);
|
|
291
|
+
return `States: ${states.join(', ') || 'none'}. Transitions: ${transitions.join('; ') || 'none'}.`;
|
|
292
|
+
}
|
|
293
|
+
/** Draws a laid-out chart. The result is an <svg> element as a string, sized by `options.fit`. */
|
|
294
|
+
export function renderSvg(layout, options = {}) {
|
|
295
|
+
const scale = options.scale ?? 1.25;
|
|
296
|
+
const fit = options.fit ?? 'natural';
|
|
297
|
+
const prefix = options.idPrefix ?? `sc-${layout.chart.replace(/[^A-Za-z0-9_-]/g, '_')}-${hash(JSON.stringify(layout.root)).slice(0, 6)}`;
|
|
298
|
+
const ctx = { prefix, classes: options.classes, regionCorner: options.regionCorner ?? true, shadows: options.shadows ?? layout.shadows ?? true };
|
|
299
|
+
const vw = layout.width + 2 * MARGIN, vh = layout.height + 2 * MARGIN;
|
|
300
|
+
const naturalW = r2(vw * scale), naturalH = r2(vh * scale);
|
|
301
|
+
let size;
|
|
302
|
+
let style = `--sc-font-fallback:'${SANS_FAMILY}';--sc-mono-fallback:'${MONO_FAMILY}'`;
|
|
303
|
+
if (fit === 'none')
|
|
304
|
+
size = `width="${naturalW}" height="${naturalH}"`;
|
|
305
|
+
else {
|
|
306
|
+
size = 'width="100%"';
|
|
307
|
+
style += `;height:auto;display:block${fit === 'natural' ? `;max-width:${naturalW}px` : ''}`;
|
|
308
|
+
if (options.minScale !== undefined)
|
|
309
|
+
style += `;min-width:${r2(naturalW * options.minScale)}px`;
|
|
310
|
+
}
|
|
311
|
+
const title = options.title ?? `SCChart ${layout.chart}`;
|
|
312
|
+
const defs = `<linearGradient id="${prefix}-fade-g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#000"/></linearGradient>`
|
|
313
|
+
+ `<mask id="${prefix}-fade" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox" x="0" y="0" width="1" height="1"><rect width="1" height="1" fill="url(#${prefix}-fade-g)"/></mask>`;
|
|
314
|
+
const classes = ['sc-diagram', options.className].filter(Boolean).join(' ');
|
|
315
|
+
return [
|
|
316
|
+
`<svg xmlns="http://www.w3.org/2000/svg" class="${esc(classes)}" viewBox="${-MARGIN} ${-MARGIN} ${num(vw)} ${num(vh)}" ${size}`,
|
|
317
|
+
` role="img" aria-labelledby="${prefix}-title ${prefix}-desc" data-chart="${esc(layout.chart)}" data-natural-width="${naturalW}"`,
|
|
318
|
+
` data-natural-height="${naturalH}" style="${esc(style)}">`,
|
|
319
|
+
`<title id="${prefix}-title">${esc(title)}</title><desc id="${prefix}-desc">${esc(describe(layout))}</desc>`,
|
|
320
|
+
options.stylesheet ? `<style><![CDATA[\n${options.stylesheet.replaceAll(']]>', ']]]]><![CDATA[>')}\n]]></style>` : '',
|
|
321
|
+
`<defs>${defs}</defs>`,
|
|
322
|
+
renderState(layout.root, ctx),
|
|
323
|
+
layout.root.comments.map(renderComment).join(''),
|
|
324
|
+
'</svg>',
|
|
325
|
+
].join('');
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,EAAE;AACF,0GAA0G;AAC1G,4GAA4G;AAC5G,6GAA6G;AAC7G,kDAAkD;AAElD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,sBAAkB;AAC/E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,qBAAiB;AAMpD,MAAM,MAAM,GAAG,CAAC,CAAA;AAEhB,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE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AC,cAAc,CAAC,MAAM,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE;QAC/H,gCAAgC,MAAM,UAAU,MAAM,sBAAsB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,QAAQ,GAAG;QACjI,yBAAyB,QAAQ,YAAY,GAAG,CAAC,KAAK,CAAC,IAAI;QAC3D,cAAc,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC,qBAAqB,MAAM,UAAU,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS;QAC5G,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,qBAAqB,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE;QACrH,SAAS,IAAI,SAAS;QACtB,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,QAAQ;KACX,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACd,CAAC","sourcesContent":["// renderSvg: draws a DiagramLayout as SVG markup in KIELER's notation. Pure and deterministic.\n//\n// Colours are not in the markup: every element carries stable classes (sc-state, sc-transition, ...) that\n// diagram.css colours through the --sc-* custom properties, and a simulation highlights by toggling classes\n// (is-active, is-taken, ...) on the elements with the matching data-id. The only definition, a fade mask for\n// KIELER's state gradients, is theme-independent.\n\nimport { endTangent, flatten, pathData, place, r2, sampleAt } from './geometry'\nimport { MONO_FAMILY, SANS_FAMILY } from './measure'\nimport type {\n CommentLayout, DataflowLayout, DiagramLayout, Point, RegionLayout, RenderOptions, StateLayout, TextLine,\n TransitionLabelLayout, TransitionLayout,\n} from './types'\n\nconst MARGIN = 6\n\nconst esc = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"')\nconst num = (n: number) => String(r2(n))\n\nfunction hash(s: string): string {\n let h = 2166136261\n for (let i = 0; i < s.length; i++) {\n h ^= s.charCodeAt(i)\n h = Math.imul(h, 16777619)\n }\n return (h >>> 0).toString(36)\n}\n\nfunction cls(base: string[], id: string | undefined, extra: Record<string, string[]> | undefined): string {\n const all = id && extra?.[id] ? [...base, ...extra[id]] : base\n return all.join(' ')\n}\n\nfunction polygon(points: Point[]): string {\n return 'M' + points.map(p => `${num(p.x)} ${num(p.y)}`).join('L') + 'Z'\n}\n\n/** A rounded rectangle as a path (so a stroke can be drawn inside a highlight without SVG rx quirks). */\nfunction rect(x: number, y: number, w: number, h: number, r: number): string {\n const rr = Math.max(0, Math.min(r, w / 2, h / 2))\n return `x=\"${num(x)}\" y=\"${num(y)}\" width=\"${num(w)}\" height=\"${num(h)}\"${rr ? ` rx=\"${num(rr)}\"` : ''}`\n}\n\nfunction textLine(line: TextLine, extraClass = ''): string {\n const classes = ['sc-text', `sc-${line.role}`]\n if (line.bold) classes.push('sc-bold')\n if (line.mono) classes.push('sc-mono')\n if (extraClass) classes.push(extraClass)\n const ids = line.ids?.length ? ` data-id=\"${esc(line.ids[0])}\"${line.ids.length > 1 ? ` data-ids=\"${esc(line.ids.join(' '))}\"` : ''}` : ''\n const spans = line.runs.map(run => {\n const runCls = run.format === 'keyword' ? 'sc-kw' : run.format === 'highlight' ? 'sc-hl' : run.format === 'schedule' ? 'sc-sd' : ''\n return `<tspan x=\"${num(line.x + run.dx)}\"${runCls ? ` class=\"${runCls}\"` : ''}>${esc(run.text)}</tspan>`\n }).join('')\n return `<text class=\"${classes.join(' ')}\" y=\"${num(line.y)}\" font-size=\"${line.size}\"${ids}>${spans}</text>`\n}\n\ninterface Ctx {\n prefix: string\n classes?: Record<string, string[]>\n regionCorner: boolean\n shadows: boolean\n}\n\nfunction renderState(s: StateLayout, ctx: Ctx): string {\n const base = ['sc-state']\n if (s.shape === 'root') base.push('sc-root', 'sc-superstate')\n else if (s.shape === 'superstate') base.push('sc-superstate')\n else if (s.shape === 'connector') base.push('sc-connector')\n else base.push('sc-simple')\n if (s.initial) base.push('sc-initial')\n if (s.final) base.push('sc-final')\n if (s.reference) base.push('sc-reference')\n if (s.violation) base.push('sc-violation')\n if (s.violation && s.finalInset && !s.final) base.push('sc-halt')\n const out: string[] = [`<g class=\"${cls(base, s.id, ctx.classes)}\" data-id=\"${esc(s.id)}\">`]\n if (s.shape === 'connector') {\n out.push(`<circle class=\"sc-shape\" cx=\"${num(s.x + s.width / 2)}\" cy=\"${num(s.y + s.height / 2)}\" r=\"${num(s.width / 2 - 0.5)}\"/>`)\n out.push('</g>')\n return out.join('')\n }\n if (ctx.shadows) out.push(`<rect class=\"sc-shadow\" ${rect(s.x + 3, s.y + 3, s.width, s.height, s.radius)}/>`)\n // KIELER's vertical gradient: the end colour, the top colour faded out by a (theme-independent) mask, then\n // the border on top. Colours come from CSS, so the markup is the same in every theme.\n const figure = (x: number, y: number, w: number, h: number, r: number, extra = '') => {\n const g = rect(x, y, w, h, r)\n return `<rect class=\"sc-fill\" ${g}/><rect class=\"sc-fill-top\" ${g} mask=\"url(#${ctx.prefix}-fade)\"/><rect class=\"sc-shape${extra}\" ${g}/>`\n }\n const inset = s.finalInset ?? 0\n if (s.shape === 'root') {\n out.push(`<rect class=\"sc-shape\" ${rect(s.x, s.y, s.width, s.height, s.radius)}/>`)\n } else if (inset) {\n // Final state: an outer border, then the figure `inset` inside it.\n out.push(`<rect class=\"sc-shape sc-final-outer\" ${rect(s.x, s.y, s.width, s.height, s.radius)}/>`)\n out.push(figure(s.x + inset, s.y + inset, s.width - 2 * inset, s.height - 2 * inset, s.radius - inset, ' sc-final-inner'))\n } else {\n out.push(figure(s.x, s.y, s.width, s.height, s.radius))\n }\n for (const line of s.lines) out.push(textLine(line))\n for (const r of s.regions) out.push(renderRegion(r, ctx))\n out.push('</g>')\n return out.join('')\n}\n\nfunction renderRegion(r: RegionLayout, ctx: Ctx): string {\n const base = ['sc-region']\n if (r.dataflow) base.push('sc-dataflow')\n if (r.collapsed) base.push('sc-collapsed')\n if (r.final) base.push('sc-final-region')\n if (r.abort) base.push('sc-abort-region')\n if (r.override) base.push('sc-override-region')\n if (r.reference) base.push('sc-reference-region')\n if (r.method) base.push('sc-method', `sc-method-${r.method}`)\n const out: string[] = [`<g class=\"${cls(base, r.id, ctx.classes)}\" data-id=\"${esc(r.id)}\">`]\n out.push(`<rect class=\"sc-region-frame\" ${rect(r.x, r.y, r.width, r.height, 0)}/>`)\n if (r.final) out.push(`<rect class=\"sc-region-frame sc-region-frame-inner\" ${rect(r.x + 3, r.y + 3, r.width - 6, r.height - 6, 0)}/>`)\n if (ctx.regionCorner && !r.empty) {\n // KIELER's expand/collapse button: \"-\" when expanded, \"+\" when collapsed, blank for an abstract method.\n const x = r.x + 0.5, y = r.y + 0.5\n out.push(`<path class=\"sc-region-corner\" d=\"M${num(x)} ${num(y)}L${num(x)} ${num(y + 19.5)}L${num(x + 19.5)} ${num(y)}Z\"/>`)\n if (r.method !== 'abstract') {\n const mark = r.collapsed || r.reference ? `M${num(x + 2.5)} ${num(y + 5.5)}h6M${num(x + 5.5)} ${num(y + 2.5)}v6` : `M${num(x + 2.5)} ${num(y + 5.5)}h5`\n out.push(`<path class=\"sc-region-corner-mark\" d=\"${mark}\"/>`)\n }\n }\n if (r.label) out.push(textLine(r.label))\n for (const line of r.lines) out.push(textLine(line))\n if (r.circuit) out.push(renderCircuit(r.circuit))\n for (const s of r.states) out.push(renderState(s, ctx))\n for (const t of r.transitions) out.push(renderTransition(t, ctx))\n for (const c of r.comments) out.push(renderComment(c))\n out.push('</g>')\n return out.join('')\n}\n\n// KLighD's head arrow (KPolylineExtensions.addHeadArrowDecorator): 8 long, 6 wide, notched, its tip 2 px\n// past the decorator's origin.\nconst ARROW: [number, number][] = [[-6, -3], [-2.8, 0], [-6, 3], [2, 0]]\n// TransitionStyles.addNormalTerminationDecorator: an 11 × 11 triangle pointing along the edge.\nconst TRIANGLE: [number, number][] = [[-5.5, -5.5], [5.5, 0], [-5.5, 5.5]]\n\nfunction renderTransition(t: TransitionLayout, ctx: Ctx): string {\n const base = ['sc-transition']\n if (t.immediate) base.push('sc-immediate')\n if (t.preemption === 'strong') base.push('sc-strong')\n if (t.preemption === 'termination') base.push('sc-termination')\n if (t.history) base.push('sc-history', `sc-history-${t.history}`)\n if (t.deferred) base.push('sc-deferred')\n if (t.nondeterministic) base.push('sc-nondeterministic')\n else if (t.probability !== undefined && t.probability > 0) base.push('sc-probabilistic')\n const d = pathData(t.points)\n const poly = flatten(t.points)\n const out: string[] = [`<g class=\"${cls(base, t.id, ctx.classes)}\" data-id=\"${esc(t.id)}\">`]\n if (t.points.length < 2) {\n // ELK found no route (should not happen); keep the element so highlighting still finds it.\n if (t.label) out.push(renderLabel(t.label))\n out.push('</g>')\n return out.join('')\n }\n out.push(`<path class=\"sc-edge-hit\" d=\"${d}\"/>`)\n out.push(`<path class=\"sc-edge\" d=\"${d}\"/>`)\n // Head decorators (TransitionStyles): the arrow moves back to make room for history/deferred markers.\n let arrowAt = -2\n if (t.history) arrowAt = t.deferred ? -26 : -17\n else if (t.deferred) arrowAt = -11\n const head = arrowAt === -2 ? { point: sampleAt(poly, -2).point, tangent: endTangent(t.points) } : sampleAt(poly, arrowAt)\n out.push(`<path class=\"sc-arrow\" d=\"${polygon(place(head.point, head.tangent, ARROW))}\"/>`)\n if (t.history) {\n const at = sampleAt(poly, -6).point\n const deep = t.history === 'deep'\n // The circled H (H* for deep history), KLighD's polyline letter.\n const hx = deep ? -5 : -3, hw = 6\n const letter = `M${num(at.x + hx)} ${num(at.y - 4)}V${num(at.y + 4)}M${num(at.x + hx)} ${num(at.y)}H${num(at.x + hx + hw)}M${num(at.x + hx + hw)} ${num(at.y - 4)}V${num(at.y + 4)}`\n const star = deep ? `<path class=\"sc-history-star\" d=\"M${num(at.x + 4)} ${num(at.y - 5)}v4M${num(at.x + 2.27)} ${num(at.y - 4)}l3.46 2M${num(at.x + 2.27)} ${num(at.y - 2)}l3.46 -2\"/>` : ''\n out.push(`<g class=\"sc-history-marker\"><circle cx=\"${num(at.x)}\" cy=\"${num(at.y)}\" r=\"8\"/><path class=\"sc-history-letter\" d=\"${letter}\"/>${star}</g>`)\n }\n if (t.deferred) {\n const at = sampleAt(poly, t.history ? -19 : -4).point\n const star = t.deferred === 'deep' ? `<path class=\"sc-deferred-star\" d=\"M${num(at.x)} ${num(at.y - 3)}v6M${num(at.x - 2.6)} ${num(at.y - 1.5)}l5.2 3M${num(at.x - 2.6)} ${num(at.y + 1.5)}l5.2 -3\"/>` : ''\n out.push(`<g class=\"sc-deferred-marker\"><circle cx=\"${num(at.x)}\" cy=\"${num(at.y)}\" r=\"5\"/>${star}</g>`)\n }\n // Tail decorators.\n if (t.preemption === 'strong') {\n const at = sampleAt(poly, 4).point\n out.push(`<circle class=\"sc-strong-marker\" cx=\"${num(at.x)}\" cy=\"${num(at.y)}\" r=\"5\"/>`)\n } else if (t.preemption === 'termination') {\n const at = sampleAt(poly, 5)\n out.push(`<path class=\"sc-termination-marker\" d=\"${polygon(place(at.point, at.tangent, TRIANGLE))}\"/>`)\n }\n for (const c of t.comments ?? []) out.push(renderLabel(c, 'sc-label sc-label-comment'))\n if (t.label) out.push(renderLabel(t.label))\n out.push('</g>')\n return out.join('')\n}\n\nfunction renderLabel(l: TransitionLabelLayout, className = 'sc-label'): string {\n const { x, y, width: w, height: h } = l\n const out: string[] = [`<g class=\"${className}\">`]\n out.push(`<rect class=\"sc-label-bg\" ${rect(x, y, w, h, 0)}/>`)\n // LabelPlacementSideHook (on-edge labels): bars across the edge at both ends, a small arrow pointing on.\n let bars: string, arrow: Point[]\n if (l.direction === 'right' || l.direction === 'left') {\n bars = `M${num(x + 0.5)} ${num(y)}V${num(y + h)}M${num(x + w - 0.5)} ${num(y)}V${num(y + h)}`\n const cy = y + h / 2\n arrow = l.direction === 'right'\n ? [{ x: x + w, y: cy - 4 }, { x: x + w + 4, y: cy }, { x: x + w, y: cy + 4 }]\n : [{ x, y: cy - 4 }, { x: x - 4, y: cy }, { x, y: cy + 4 }]\n } else {\n bars = `M${num(x)} ${num(y + 0.5)}H${num(x + w)}M${num(x)} ${num(y + h - 0.5)}H${num(x + w)}`\n const cx = x + w / 2\n arrow = l.direction === 'down'\n ? [{ x: cx - 4, y: y + h }, { x: cx, y: y + h + 4 }, { x: cx + 4, y: y + h }]\n : [{ x: cx - 4, y }, { x: cx, y: y - 4 }, { x: cx + 4, y }]\n }\n out.push(`<path class=\"sc-label-bars\" d=\"${bars}\"/>`)\n out.push(`<path class=\"sc-label-arrow\" d=\"${polygon(arrow)}\"/>`)\n for (const line of l.lines) out.push(textLine(line))\n out.push('</g>')\n return out.join('')\n}\n\nfunction renderComment(c: CommentLayout): string {\n const out: string[] = [`<g class=\"sc-comment\" data-id=\"${esc(c.id)}\">`]\n if (c.points?.length) out.push(`<path class=\"sc-comment-edge\" d=\"${pathData(c.points)}\"/>`)\n // CommentStyles.addCommentFigure: a rectangle with 1 px corners.\n out.push(`<rect class=\"sc-comment-box\" ${rect(c.x, c.y, c.width, c.height, 1)}/>`)\n for (const line of c.lines) out.push(textLine(line))\n out.push('</g>')\n return out.join('')\n}\n\nfunction renderCircuit(c: DataflowLayout): string {\n const out: string[] = ['<g class=\"sc-circuit\">']\n for (const w of c.wires) out.push(`<path class=\"sc-wire\" data-id=\"${esc(w.id)}\" d=\"${pathData(w.points)}\"/>`)\n for (const n of c.nodes) {\n const { x, y, width: w, height: h } = n\n let shape: string\n if (n.kind === 'input') shape = `<path class=\"sc-df-shape\" d=\"M${num(x)} ${num(y)}H${num(x + w - 6)}L${num(x + w)} ${num(y + h / 2)}L${num(x + w - 6)} ${num(y + h)}H${num(x)}Z\"/>`\n else if (n.kind === 'output') shape = `<path class=\"sc-df-shape\" d=\"M${num(x)} ${num(y)}H${num(x + w - 6)}L${num(x + w)} ${num(y + h / 2)}L${num(x + w - 6)} ${num(y + h)}H${num(x)}L${num(x + 6)} ${num(y + h / 2)}Z\"/>`\n else if (n.kind === 'actor') shape = `<rect class=\"sc-df-shape\" ${rect(x, y, w, h, 4)}/><path class=\"sc-df-divider\" d=\"M${num(x)} ${num(n.lines[0].y + 4)}H${num(x + w)}\"/>`\n else shape = `<rect class=\"sc-df-shape\" ${rect(x, y, w, h, n.kind === 'constant' ? 0 : 3)}/>`\n out.push(`<g class=\"sc-df-node sc-df-${n.kind}\" data-id=\"${esc(n.id)}\">${shape}${n.lines.map((l, i) => textLine(l, n.kind === 'actor' && i > 0 ? 'sc-df-port' : '')).join('')}</g>`)\n }\n out.push('</g>')\n return out.join('')\n}\n\nfunction describe(layout: DiagramLayout): string {\n const states: string[] = []\n const transitions: string[] = []\n const name = (id: string) => id.slice(id.lastIndexOf('.') + 1)\n const walk = (s: StateLayout) => {\n for (const r of s.regions) {\n for (const c of r.states) {\n const kind = [c.initial && 'initial', c.final && 'final', c.shape === 'connector' && 'connector', c.shape === 'superstate' && 'superstate'].filter(Boolean)\n states.push(name(c.id) + (kind.length ? ` (${kind.join(', ')})` : ''))\n walk(c)\n }\n for (const t of r.transitions) {\n const label = t.label ? ': ' + t.label.lines.map(l => l.runs.map(x => x.text).join(' ')).join(' ') : ''\n transitions.push(`${name(t.source)} to ${name(t.target)}${label}`)\n }\n }\n }\n walk(layout.root)\n return `States: ${states.join(', ') || 'none'}. Transitions: ${transitions.join('; ') || 'none'}.`\n}\n\n/** Draws a laid-out chart. The result is an <svg> element as a string, sized by `options.fit`. */\nexport function renderSvg(layout: DiagramLayout, options: RenderOptions = {}): string {\n const scale = options.scale ?? 1.25\n const fit = options.fit ?? 'natural'\n const prefix = options.idPrefix ?? `sc-${layout.chart.replace(/[^A-Za-z0-9_-]/g, '_')}-${hash(JSON.stringify(layout.root)).slice(0, 6)}`\n const ctx: Ctx = { prefix, classes: options.classes, regionCorner: options.regionCorner ?? true, shadows: options.shadows ?? layout.shadows ?? true }\n const vw = layout.width + 2 * MARGIN, vh = layout.height + 2 * MARGIN\n const naturalW = r2(vw * scale), naturalH = r2(vh * scale)\n let size: string\n let style = `--sc-font-fallback:'${SANS_FAMILY}';--sc-mono-fallback:'${MONO_FAMILY}'`\n if (fit === 'none') size = `width=\"${naturalW}\" height=\"${naturalH}\"`\n else {\n size = 'width=\"100%\"'\n style += `;height:auto;display:block${fit === 'natural' ? `;max-width:${naturalW}px` : ''}`\n if (options.minScale !== undefined) style += `;min-width:${r2(naturalW * options.minScale)}px`\n }\n const title = options.title ?? `SCChart ${layout.chart}`\n const defs = `<linearGradient id=\"${prefix}-fade-g\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#fff\"/><stop offset=\"1\" stop-color=\"#000\"/></linearGradient>`\n + `<mask id=\"${prefix}-fade\" maskUnits=\"objectBoundingBox\" maskContentUnits=\"objectBoundingBox\" x=\"0\" y=\"0\" width=\"1\" height=\"1\"><rect width=\"1\" height=\"1\" fill=\"url(#${prefix}-fade-g)\"/></mask>`\n const classes = ['sc-diagram', options.className].filter(Boolean).join(' ')\n return [\n `<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"${esc(classes)}\" viewBox=\"${-MARGIN} ${-MARGIN} ${num(vw)} ${num(vh)}\" ${size}`,\n ` role=\"img\" aria-labelledby=\"${prefix}-title ${prefix}-desc\" data-chart=\"${esc(layout.chart)}\" data-natural-width=\"${naturalW}\"`,\n ` data-natural-height=\"${naturalH}\" style=\"${esc(style)}\">`,\n `<title id=\"${prefix}-title\">${esc(title)}</title><desc id=\"${prefix}-desc\">${esc(describe(layout))}</desc>`,\n options.stylesheet ? `<style><![CDATA[\\n${options.stylesheet.replaceAll(']]>', ']]]]><![CDATA[>')}\\n]]></style>` : '',\n `<defs>${defs}</defs>`,\n renderState(layout.root, ctx),\n layout.root.comments.map(renderComment).join(''),\n '</svg>',\n ].join('')\n}\n"]}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type { ElkNode } from "./elk-types.js";
|
|
2
|
+
import type { FormatContext, TextFormat } from "@sccharts-lab/engine/format";
|
|
3
|
+
import type { Program, Span, State } from "@sccharts-lab/engine/types";
|
|
4
|
+
import type { TextMeasurer } from "./measure.js";
|
|
5
|
+
export interface Point {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
export interface Box {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
/** A run of text on a line, `dx` from the line's start. Keywords are bold and coloured. */
|
|
16
|
+
export interface TextRun {
|
|
17
|
+
text: string;
|
|
18
|
+
dx: number;
|
|
19
|
+
width: number;
|
|
20
|
+
format: TextFormat;
|
|
21
|
+
}
|
|
22
|
+
export type TextRole = 'title' | 'state-label' | 'declaration' | 'action' | 'region-label' | 'edge-label' | 'equation' | 'comment';
|
|
23
|
+
/** One line of text. Coordinates are absolute: `x` is the left end, `y` the baseline. */
|
|
24
|
+
export interface TextLine {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
/** Font size in diagram units. */
|
|
29
|
+
size: number;
|
|
30
|
+
/** The whole line is bold (state names, transition labels). Keyword runs are bold anyway. */
|
|
31
|
+
bold?: boolean;
|
|
32
|
+
mono?: boolean;
|
|
33
|
+
runs: TextRun[];
|
|
34
|
+
role: TextRole;
|
|
35
|
+
/** Model elements the line shows: the action's id, or the ids of a declaration's valued objects. */
|
|
36
|
+
ids?: string[];
|
|
37
|
+
}
|
|
38
|
+
export type StateShape = 'root' | 'superstate' | 'simple' | 'connector';
|
|
39
|
+
export interface StateLayout extends Box {
|
|
40
|
+
kind: 'state';
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
shape: StateShape;
|
|
44
|
+
initial: boolean;
|
|
45
|
+
final: boolean;
|
|
46
|
+
violation: boolean;
|
|
47
|
+
/** `state S is Other(...)`. */
|
|
48
|
+
reference: boolean;
|
|
49
|
+
/** Corner radius of the outer figure. */
|
|
50
|
+
radius: number;
|
|
51
|
+
/** Border width of the outer figure: 1, or 3 for an initial state. */
|
|
52
|
+
lineWidth: number;
|
|
53
|
+
/** Final states (and violation states that cannot be left): distance between the outer and the inner
|
|
54
|
+
* border. */
|
|
55
|
+
finalInset?: number;
|
|
56
|
+
/** The name (simple states) or the title row and the declaration and action lines (superstates). */
|
|
57
|
+
lines: TextLine[];
|
|
58
|
+
regions: RegionLayout[];
|
|
59
|
+
comments: CommentLayout[];
|
|
60
|
+
span?: Span;
|
|
61
|
+
}
|
|
62
|
+
export interface RegionLayout extends Box {
|
|
63
|
+
kind: 'region';
|
|
64
|
+
id: string;
|
|
65
|
+
name?: string;
|
|
66
|
+
dataflow: boolean;
|
|
67
|
+
/** Drawn as a closed box with only its label (`@collapse`, or the region of a reference state). */
|
|
68
|
+
collapsed: boolean;
|
|
69
|
+
final: boolean;
|
|
70
|
+
abort: boolean;
|
|
71
|
+
override: boolean;
|
|
72
|
+
/** `region R is Other(...)`: drawn collapsed with KIELER's reference style. */
|
|
73
|
+
reference?: boolean;
|
|
74
|
+
/** A control-flow region without states: KIELER draws a bare frame, without label or button. */
|
|
75
|
+
empty?: boolean;
|
|
76
|
+
/** A method of the state, drawn as KIELER does: a collapsed grey region labelled with the signature (its
|
|
77
|
+
* id is the method's valued object id). 'abstract' when it has no body. */
|
|
78
|
+
method?: 'implemented' | 'abstract';
|
|
79
|
+
/** ELK layout direction of the region's states. */
|
|
80
|
+
direction: 'RIGHT' | 'DOWN' | 'LEFT' | 'UP';
|
|
81
|
+
label?: TextLine;
|
|
82
|
+
/** Region-level declarations and actions; for a dataflow region drawn as a list, its equations. */
|
|
83
|
+
lines: TextLine[];
|
|
84
|
+
states: StateLayout[];
|
|
85
|
+
transitions: TransitionLayout[];
|
|
86
|
+
/** Dataflow regions drawn as a circuit. */
|
|
87
|
+
circuit?: DataflowLayout;
|
|
88
|
+
comments: CommentLayout[];
|
|
89
|
+
span?: Span;
|
|
90
|
+
}
|
|
91
|
+
export type LabelDirection = 'right' | 'left' | 'down' | 'up';
|
|
92
|
+
export interface TransitionLabelLayout extends Box {
|
|
93
|
+
lines: TextLine[];
|
|
94
|
+
/** Direction of the edge at the label, for KIELER's on-edge label decoration. */
|
|
95
|
+
direction: LabelDirection;
|
|
96
|
+
}
|
|
97
|
+
export interface TransitionLayout {
|
|
98
|
+
kind: 'transition';
|
|
99
|
+
id: string;
|
|
100
|
+
source: string;
|
|
101
|
+
target: string;
|
|
102
|
+
priority: number;
|
|
103
|
+
/** ELK's routing points: start, cubic Bézier control points, end (1 + 3k points when splines are used). */
|
|
104
|
+
points: Point[];
|
|
105
|
+
immediate: boolean;
|
|
106
|
+
preemption: 'weak' | 'strong' | 'termination';
|
|
107
|
+
history?: 'shallow' | 'deep';
|
|
108
|
+
deferred?: 'shallow' | 'deep';
|
|
109
|
+
nondeterministic?: boolean;
|
|
110
|
+
probability?: number;
|
|
111
|
+
label?: TransitionLabelLayout;
|
|
112
|
+
/** The transition's doc comments, each an extra label stacked in front of the main one (KIELER's
|
|
113
|
+
* "Comment Nodes" option). */
|
|
114
|
+
comments?: TransitionLabelLayout[];
|
|
115
|
+
span?: Span;
|
|
116
|
+
}
|
|
117
|
+
export interface CommentLayout extends Box {
|
|
118
|
+
id: string;
|
|
119
|
+
lines: TextLine[];
|
|
120
|
+
/** Connection from the element it documents to the comment (a state's comments; a region's have none). */
|
|
121
|
+
points?: Point[];
|
|
122
|
+
}
|
|
123
|
+
/** A dataflow region as a small circuit: inputs, operators and outputs joined by wires. */
|
|
124
|
+
export interface DataflowLayout {
|
|
125
|
+
nodes: DataflowNodeLayout[];
|
|
126
|
+
wires: {
|
|
127
|
+
id: string;
|
|
128
|
+
points: Point[];
|
|
129
|
+
}[];
|
|
130
|
+
}
|
|
131
|
+
export interface DataflowNodeLayout extends Box {
|
|
132
|
+
id: string;
|
|
133
|
+
kind: 'input' | 'output' | 'operator' | 'constant' | 'actor';
|
|
134
|
+
text: string;
|
|
135
|
+
lines: TextLine[];
|
|
136
|
+
}
|
|
137
|
+
export interface DiagramLayout {
|
|
138
|
+
/** Bumped when the shape of this data changes. */
|
|
139
|
+
version: 1;
|
|
140
|
+
/** Id (and name) of the chart. */
|
|
141
|
+
chart: string;
|
|
142
|
+
width: number;
|
|
143
|
+
height: number;
|
|
144
|
+
root: StateLayout;
|
|
145
|
+
/** The direction setting the layout was made with. */
|
|
146
|
+
direction: LayoutDirection;
|
|
147
|
+
/** `@diagram[shadows] false` on the chart: renderSvg draws no shadows unless told otherwise. */
|
|
148
|
+
shadows?: false;
|
|
149
|
+
}
|
|
150
|
+
export type LayoutDirection = 'HV' | 'VH' | 'down' | 'right';
|
|
151
|
+
/** What `layoutChart` needs from ELK: elkjs's `ELK` instance, possibly backed by a Web Worker. */
|
|
152
|
+
export interface ElkLike {
|
|
153
|
+
layout(graph: ElkNode): Promise<ElkNode>;
|
|
154
|
+
}
|
|
155
|
+
export interface LayoutOptions {
|
|
156
|
+
/** The ELK instance: elkjs's `ELK`, e.g. `new ELK({ workerFactory })` from `elkjs/lib/elk-api.js` to lay out in a Web
|
|
157
|
+
* Worker. `layoutChart` from `@sccharts-lab/diagram` defaults to a shared `elkjs/lib/elk.bundled.js` instance (on
|
|
158
|
+
* the calling thread, loaded on first use); the one from `@sccharts-lab/diagram/layout` needs it, so a bundle that
|
|
159
|
+
* only imports that never contains the 1.4 MB bundled build. */
|
|
160
|
+
elk?: ElkLike;
|
|
161
|
+
/** Text measurement. Default: the generated width table of the diagram font (identical in Node and the
|
|
162
|
+
* browser). */
|
|
163
|
+
measure?: TextMeasurer;
|
|
164
|
+
/** The program the chart belongs to: its other charts give referenced instances in dataflow regions their
|
|
165
|
+
* ports, and its declarations and pragmas the formatter's context. */
|
|
166
|
+
program?: Program;
|
|
167
|
+
/** Charts of other files (`import`ed), for references to them (e.g. `compile(...).index.programs`' charts).
|
|
168
|
+
* `program`'s own charts come first. */
|
|
169
|
+
charts?: State[];
|
|
170
|
+
/** Declaration lookup and symbol table for the formatter. Default: built from `program`, or from the chart
|
|
171
|
+
* itself. */
|
|
172
|
+
format?: FormatContext;
|
|
173
|
+
/** KIELER's "User Labels": show `label "..."` instead of trigger and effects. Default true. */
|
|
174
|
+
userLabels?: boolean;
|
|
175
|
+
/** KIELER's "Comment Nodes": `/** doc comments *\/` of the chart, states and regions as comment boxes, those of
|
|
176
|
+
* transitions as extra labels. Default true (as in KIELER). */
|
|
177
|
+
comments?: boolean;
|
|
178
|
+
/** Show declarations. Default true. */
|
|
179
|
+
declarations?: boolean;
|
|
180
|
+
/** Show entry/during/exit/suspend actions. Default true. */
|
|
181
|
+
actions?: boolean;
|
|
182
|
+
/** Layout direction: 'HV' (KIELER's default: top level left to right, alternating with depth), 'VH',
|
|
183
|
+
* 'down' or 'right'. */
|
|
184
|
+
direction?: LayoutDirection;
|
|
185
|
+
/** Soft-wrap width of transition label lines (KIELER: 200). 0 disables wrapping. */
|
|
186
|
+
labelWidth?: number;
|
|
187
|
+
/** Region ids to draw collapsed, in addition to regions annotated `@collapse`. */
|
|
188
|
+
collapsed?: Iterable<string>;
|
|
189
|
+
/** Reference states (`state S is Other(...)`): 'collapsed' (KIELER's initial view, default), 'expanded'
|
|
190
|
+
* (the referenced chart drawn inside, needs `program`), or the ids of the reference states to expand.
|
|
191
|
+
* Elements of an expanded chart get ids `<reference state id>/<id in the referenced chart>`. */
|
|
192
|
+
references?: 'collapsed' | 'expanded' | Iterable<string>;
|
|
193
|
+
/** Draw dataflow regions as a circuit (true, default) or as a list of equations (false). */
|
|
194
|
+
dataflowCircuit?: boolean;
|
|
195
|
+
}
|
|
196
|
+
export interface RenderOptions {
|
|
197
|
+
/** How the SVG sizes itself: 'natural' (default: width 100%, at most the natural width), 'width'
|
|
198
|
+
* (always fills the container's width), or 'none' (fixed natural size, for a scrolling frame). */
|
|
199
|
+
fit?: 'natural' | 'width' | 'none';
|
|
200
|
+
/** With fit 'natural' or 'width': never shrink below this fraction of the natural size (sets min-width), so
|
|
201
|
+
* a wide chart scrolls inside an `overflow-x: auto` frame instead of becoming unreadable on a phone. */
|
|
202
|
+
minScale?: number;
|
|
203
|
+
/** Natural size relative to diagram units. Default 1.25 (KIELER's 11 px names show at about 14 px). */
|
|
204
|
+
scale?: number;
|
|
205
|
+
/** Prefix for ids inside the SVG (gradients). Default derived from the chart name. Must be unique
|
|
206
|
+
* among different charts on one page. */
|
|
207
|
+
idPrefix?: string;
|
|
208
|
+
/** Accessible name. Default "SCChart <name>". */
|
|
209
|
+
title?: string;
|
|
210
|
+
/** Extra classes on the root <svg>. */
|
|
211
|
+
className?: string;
|
|
212
|
+
/** Initial highlight classes per element id, e.g. { 'ABRO.WaitAB': ['is-active'] }. */
|
|
213
|
+
classes?: Record<string, string[]>;
|
|
214
|
+
/** Draw the KIELER region "collapse" corner (default true). */
|
|
215
|
+
regionCorner?: boolean;
|
|
216
|
+
/** Draw state shadows (default true). */
|
|
217
|
+
shadows?: boolean;
|
|
218
|
+
/** CSS to embed in the SVG as a `<style>` element: diagram.css's text makes a standalone .svg file that looks the
|
|
219
|
+
* same in any viewer. Leave it out for an SVG inside a page that loads diagram.css. */
|
|
220
|
+
stylesheet?: string;
|
|
221
|
+
}
|
package/dist/types.js
ADDED