@edc4it/reveal.js-railroad 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.md +96 -0
- package/dist/impl/main.d.ts +3 -0
- package/dist/impl/styles.d.ts +3 -0
- package/dist/options.d.ts +13 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/railroad-D1NexFHb.mjs +1203 -0
- package/dist/railroad.es.js +110 -0
- package/dist/railroad.umd.js +57 -0
- package/dist/util/utility-types.d.ts +3 -0
- package/package.json +63 -0
|
@@ -0,0 +1,1203 @@
|
|
|
1
|
+
var Z = Object.defineProperty;
|
|
2
|
+
var J = (c, t, e) => t in c ? Z(c, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : c[t] = e;
|
|
3
|
+
var N = (c, t, e) => (J(c, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
const k = {}, s = {
|
|
5
|
+
DEBUG: !1,
|
|
6
|
+
// if true, writes some debug information into attributes
|
|
7
|
+
VS: 8,
|
|
8
|
+
// minimum vertical separation between things. For a 3px stroke, must be at least 4
|
|
9
|
+
AR: 10,
|
|
10
|
+
// radius of arcs
|
|
11
|
+
DIAGRAM_CLASS: "railroad-diagram",
|
|
12
|
+
// class to put on the root <svg>
|
|
13
|
+
STROKE_ODD_PIXEL_LENGTH: !0,
|
|
14
|
+
// is the stroke width an odd (1px, 3px, etc) pixel length?
|
|
15
|
+
INTERNAL_ALIGNMENT: "center",
|
|
16
|
+
// how to align items when they have extra space. left/right/center
|
|
17
|
+
CHAR_WIDTH: 8.5,
|
|
18
|
+
// width of each monospace character. play until you find the right value for your font
|
|
19
|
+
COMMENT_CHAR_WIDTH: 7,
|
|
20
|
+
// comments are in smaller text by default
|
|
21
|
+
ESCAPE_HTML: !0
|
|
22
|
+
// Should Diagram.toText() produce HTML-escaped text, or raw?
|
|
23
|
+
}, Q = `
|
|
24
|
+
svg {
|
|
25
|
+
background-color: hsl(30,20%,95%);
|
|
26
|
+
}
|
|
27
|
+
path {
|
|
28
|
+
stroke-width: 3;
|
|
29
|
+
stroke: black;
|
|
30
|
+
fill: rgba(0,0,0,0);
|
|
31
|
+
}
|
|
32
|
+
text {
|
|
33
|
+
font: bold 14px monospace;
|
|
34
|
+
text-anchor: middle;
|
|
35
|
+
white-space: pre;
|
|
36
|
+
}
|
|
37
|
+
text.diagram-text {
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
}
|
|
40
|
+
text.diagram-arrow {
|
|
41
|
+
font-size: 16px;
|
|
42
|
+
}
|
|
43
|
+
text.label {
|
|
44
|
+
text-anchor: start;
|
|
45
|
+
}
|
|
46
|
+
text.comment {
|
|
47
|
+
font: italic 12px monospace;
|
|
48
|
+
}
|
|
49
|
+
g.non-terminal text {
|
|
50
|
+
/*font-style: italic;*/
|
|
51
|
+
}
|
|
52
|
+
rect {
|
|
53
|
+
stroke-width: 3;
|
|
54
|
+
stroke: black;
|
|
55
|
+
fill: hsl(120,100%,90%);
|
|
56
|
+
}
|
|
57
|
+
rect.group-box {
|
|
58
|
+
stroke: gray;
|
|
59
|
+
stroke-dasharray: 10 5;
|
|
60
|
+
fill: none;
|
|
61
|
+
}
|
|
62
|
+
path.diagram-text {
|
|
63
|
+
stroke-width: 3;
|
|
64
|
+
stroke: black;
|
|
65
|
+
fill: white;
|
|
66
|
+
cursor: help;
|
|
67
|
+
}
|
|
68
|
+
g.diagram-text:hover path.diagram-text {
|
|
69
|
+
fill: #eee;
|
|
70
|
+
}`;
|
|
71
|
+
class A {
|
|
72
|
+
constructor(t, e, r) {
|
|
73
|
+
r ? this.children = r : this.children = [], this.tagName = t, this.attrs = D(e, {});
|
|
74
|
+
}
|
|
75
|
+
format(t, e, r) {
|
|
76
|
+
}
|
|
77
|
+
addTo(t) {
|
|
78
|
+
if (t instanceof A)
|
|
79
|
+
return t.children.push(this), this;
|
|
80
|
+
var e = this.toSVG();
|
|
81
|
+
return t.appendChild(e), e;
|
|
82
|
+
}
|
|
83
|
+
toSVG() {
|
|
84
|
+
var t = dt(this.tagName, this.attrs);
|
|
85
|
+
return typeof this.children == "string" ? t.textContent = this.children : this.children.forEach(function(e) {
|
|
86
|
+
t.appendChild(e.toSVG());
|
|
87
|
+
}), t;
|
|
88
|
+
}
|
|
89
|
+
toString() {
|
|
90
|
+
var t = "<" + this.tagName, e = this.tagName == "g" || this.tagName == "svg";
|
|
91
|
+
for (var r in this.attrs)
|
|
92
|
+
t += " " + r + '="' + (this.attrs[r] + "").replace(/&/g, "&").replace(/"/g, """) + '"';
|
|
93
|
+
return t += ">", e && (t += `
|
|
94
|
+
`), typeof this.children == "string" ? t += lt(this.children) : this.children.forEach(function(h) {
|
|
95
|
+
t += h;
|
|
96
|
+
}), t += "</" + this.tagName + `>
|
|
97
|
+
`, t;
|
|
98
|
+
}
|
|
99
|
+
toTextDiagram() {
|
|
100
|
+
return new _(0, 0, []);
|
|
101
|
+
}
|
|
102
|
+
toText() {
|
|
103
|
+
var t = this.toTextDiagram(), e = t.lines.join(`
|
|
104
|
+
`) + `
|
|
105
|
+
`;
|
|
106
|
+
return s.ESCAPE_HTML && (e = e.replace("&", "&").replace("<", "<").replace(">", ">").replace('"', """)), e;
|
|
107
|
+
}
|
|
108
|
+
walk(t) {
|
|
109
|
+
t(this);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class f extends A {
|
|
113
|
+
constructor(t, e) {
|
|
114
|
+
super("path"), this.attrs.d = "M" + t + " " + e;
|
|
115
|
+
}
|
|
116
|
+
m(t, e) {
|
|
117
|
+
return this.attrs.d += "m" + t + " " + e, this;
|
|
118
|
+
}
|
|
119
|
+
h(t) {
|
|
120
|
+
return this.attrs.d += "h" + t, this;
|
|
121
|
+
}
|
|
122
|
+
right(t) {
|
|
123
|
+
return this.h(Math.max(0, t));
|
|
124
|
+
}
|
|
125
|
+
left(t) {
|
|
126
|
+
return this.h(-Math.max(0, t));
|
|
127
|
+
}
|
|
128
|
+
v(t) {
|
|
129
|
+
return this.attrs.d += "v" + t, this;
|
|
130
|
+
}
|
|
131
|
+
down(t) {
|
|
132
|
+
return this.v(Math.max(0, t));
|
|
133
|
+
}
|
|
134
|
+
up(t) {
|
|
135
|
+
return this.v(-Math.max(0, t));
|
|
136
|
+
}
|
|
137
|
+
arc(t) {
|
|
138
|
+
var e = s.AR, r = s.AR;
|
|
139
|
+
(t[0] == "e" || t[1] == "w") && (e *= -1), (t[0] == "s" || t[1] == "n") && (r *= -1);
|
|
140
|
+
var h;
|
|
141
|
+
return t == "ne" || t == "es" || t == "sw" || t == "wn" ? h = 1 : h = 0, this.attrs.d += "a" + s.AR + " " + s.AR + " 0 0 " + h + " " + e + " " + r, this;
|
|
142
|
+
}
|
|
143
|
+
arc_8(t, e) {
|
|
144
|
+
const r = s.AR, h = 1 / Math.sqrt(2) * r, i = r - h;
|
|
145
|
+
let n = "a " + r + " " + r + " 0 0 " + (e == "cw" ? "1" : "0") + " ";
|
|
146
|
+
const o = t + e, w = o == "ncw" ? [h, i] : o == "necw" ? [i, h] : o == "ecw" ? [-i, h] : o == "secw" ? [-h, i] : o == "scw" ? [-h, -i] : o == "swcw" ? [-i, -h] : o == "wcw" ? [i, -h] : o == "nwcw" ? [h, -i] : o == "nccw" ? [-h, i] : o == "nwccw" ? [-i, h] : o == "wccw" ? [i, h] : o == "swccw" ? [h, i] : o == "sccw" ? [h, -i] : o == "seccw" ? [i, -h] : o == "eccw" ? [-i, -h] : o == "neccw" ? [-h, -i] : null;
|
|
147
|
+
return n += w.join(" "), this.attrs.d += n, this;
|
|
148
|
+
}
|
|
149
|
+
l(t, e) {
|
|
150
|
+
return this.attrs.d += "l" + t + " " + e, this;
|
|
151
|
+
}
|
|
152
|
+
format() {
|
|
153
|
+
return this.attrs.d += "h.5", this;
|
|
154
|
+
}
|
|
155
|
+
toTextDiagram() {
|
|
156
|
+
return new _(0, 0, []);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
class G extends A {
|
|
160
|
+
constructor(t, e, r, h) {
|
|
161
|
+
super(t, r, h), this.items = e.map(P);
|
|
162
|
+
}
|
|
163
|
+
walk(t) {
|
|
164
|
+
t(this), this.items.forEach((e) => e.walk(t));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
class Y extends G {
|
|
168
|
+
constructor(...t) {
|
|
169
|
+
super("svg", t, { class: s.DIAGRAM_CLASS }), this.items[0] instanceof U || this.items.unshift(new U()), this.items[this.items.length - 1] instanceof H || this.items.push(new H()), this.up = this.down = this.height = this.width = 0;
|
|
170
|
+
for (const e of this.items)
|
|
171
|
+
this.width += e.width + (e.needsSpace ? 20 : 0), this.up = Math.max(this.up, e.up - this.height), this.height += e.height, this.down = Math.max(this.down - e.height, e.down);
|
|
172
|
+
this.formatted = !1;
|
|
173
|
+
}
|
|
174
|
+
format(t, e, r, h) {
|
|
175
|
+
t = D(t, 20), e = D(e, t, 20), r = D(r, t, 20), h = D(h, e, 20);
|
|
176
|
+
var i = h, n = t;
|
|
177
|
+
n += this.up;
|
|
178
|
+
for (var o = new A("g", s.STROKE_ODD_PIXEL_LENGTH ? { transform: "translate(.5 .5)" } : {}), w = 0; w < this.items.length; w++) {
|
|
179
|
+
var d = this.items[w];
|
|
180
|
+
d.needsSpace && (new f(i, n).h(10).addTo(o), i += 10), d.format(i, n, d.width).addTo(o), i += d.width, n += d.height, d.needsSpace && (new f(i, n).h(10).addTo(o), i += 10);
|
|
181
|
+
}
|
|
182
|
+
return this.attrs.width = this.width + h + e, this.attrs.height = this.up + this.height + this.down + t + r, this.attrs.viewBox = "0 0 " + this.attrs.width + " " + this.attrs.height, o.addTo(this), this.formatted = !0, this;
|
|
183
|
+
}
|
|
184
|
+
addTo(t) {
|
|
185
|
+
if (!t) {
|
|
186
|
+
var e = document.getElementsByTagName("script");
|
|
187
|
+
e = e[e.length - 1], t = e.parentNode;
|
|
188
|
+
}
|
|
189
|
+
return super.addTo.call(this, t);
|
|
190
|
+
}
|
|
191
|
+
toSVG() {
|
|
192
|
+
return this.formatted || this.format(), super.toSVG.call(this);
|
|
193
|
+
}
|
|
194
|
+
toString() {
|
|
195
|
+
return this.formatted || this.format(), super.toString.call(this);
|
|
196
|
+
}
|
|
197
|
+
toStandalone(t) {
|
|
198
|
+
this.formatted || this.format();
|
|
199
|
+
const e = new A("style", {}, t || Q);
|
|
200
|
+
this.children.push(e), this.attrs.xmlns = "http://www.w3.org/2000/svg", this.attrs["xmlns:xlink"] = "http://www.w3.org/1999/xlink";
|
|
201
|
+
const r = super.toString.call(this);
|
|
202
|
+
return this.children.pop(), delete this.attrs.xmlns, r;
|
|
203
|
+
}
|
|
204
|
+
toTextDiagram() {
|
|
205
|
+
var [t] = _._getParts(["separator"]), e = this.items[0].toTextDiagram();
|
|
206
|
+
for (const h of this.items.slice(1)) {
|
|
207
|
+
var r = h.toTextDiagram();
|
|
208
|
+
h.needsSpace && (r = r.expand(1, 1, 0, 0)), e = e.appendRight(r, t);
|
|
209
|
+
}
|
|
210
|
+
return e;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
k.Diagram = (...c) => new Y(...c);
|
|
214
|
+
class $ extends A {
|
|
215
|
+
constructor(...t) {
|
|
216
|
+
var e = new Y(...t);
|
|
217
|
+
return e.items[0] = new U({ type: "complex" }), e.items[e.items.length - 1] = new H({ type: "complex" }), e;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
k.ComplexDiagram = (...c) => new $(...c);
|
|
221
|
+
class z extends G {
|
|
222
|
+
constructor(...t) {
|
|
223
|
+
super("g", t), this.items.length, this.needsSpace = !0, this.up = this.down = this.height = this.width = 0;
|
|
224
|
+
for (var e = 0; e < this.items.length; e++) {
|
|
225
|
+
var r = this.items[e];
|
|
226
|
+
this.width += r.width + (r.needsSpace ? 20 : 0), this.up = Math.max(this.up, r.up - this.height), this.height += r.height, this.down = Math.max(this.down - r.height, r.down);
|
|
227
|
+
}
|
|
228
|
+
this.items[0].needsSpace && (this.width -= 10), this.items[this.items.length - 1].needsSpace && (this.width -= 10), s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "sequence");
|
|
229
|
+
}
|
|
230
|
+
format(t, e, r) {
|
|
231
|
+
var h = B(r, this.width);
|
|
232
|
+
new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e + this.height).h(h[1]).addTo(this), t += h[0];
|
|
233
|
+
for (var i = 0; i < this.items.length; i++) {
|
|
234
|
+
var n = this.items[i];
|
|
235
|
+
n.needsSpace && i > 0 && (new f(t, e).h(10).addTo(this), t += 10), n.format(t, e, n.width).addTo(this), t += n.width, e += n.height, n.needsSpace && i < this.items.length - 1 && (new f(t, e).h(10).addTo(this), t += 10);
|
|
236
|
+
}
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
toTextDiagram() {
|
|
240
|
+
var [t] = _._getParts(["separator"]), e = new _(0, 0, [""]);
|
|
241
|
+
for (const h of this.items) {
|
|
242
|
+
var r = h.toTextDiagram();
|
|
243
|
+
h.needsSpace && (r = r.expand(1, 1, 0, 0)), e = e.appendRight(r, t);
|
|
244
|
+
}
|
|
245
|
+
return e;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
k.Sequence = (...c) => new z(...c);
|
|
249
|
+
class tt extends G {
|
|
250
|
+
constructor(...t) {
|
|
251
|
+
if (super("g", t), t.length === 0)
|
|
252
|
+
throw new RangeError("Stack() must have at least one child.");
|
|
253
|
+
this.width = Math.max.apply(null, this.items.map(function(i) {
|
|
254
|
+
return i.width + (i.needsSpace ? 20 : 0);
|
|
255
|
+
})), this.items.length > 1 && (this.width += s.AR * 2), this.needsSpace = !0, this.up = this.items[0].up, this.down = this.items[this.items.length - 1].down, this.height = 0;
|
|
256
|
+
for (var e = this.items.length - 1, r = 0; r < this.items.length; r++) {
|
|
257
|
+
var h = this.items[r];
|
|
258
|
+
this.height += h.height, r > 0 && (this.height += Math.max(s.AR * 2, h.up + s.VS)), r < e && (this.height += Math.max(s.AR * 2, h.down + s.VS));
|
|
259
|
+
}
|
|
260
|
+
s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "stack");
|
|
261
|
+
}
|
|
262
|
+
format(t, e, r) {
|
|
263
|
+
var h = B(r, this.width);
|
|
264
|
+
new f(t, e).h(h[0]).addTo(this), t += h[0];
|
|
265
|
+
var i = t;
|
|
266
|
+
this.items.length > 1 && (new f(t, e).h(s.AR).addTo(this), t += s.AR);
|
|
267
|
+
for (var n = 0; n < this.items.length; n++) {
|
|
268
|
+
var o = this.items[n], w = this.width - (this.items.length > 1 ? s.AR * 2 : 0);
|
|
269
|
+
o.format(t, e, w).addTo(this), t += w, e += o.height, n !== this.items.length - 1 && (new f(t, e).arc("ne").down(Math.max(0, o.down + s.VS - s.AR * 2)).arc("es").left(w).arc("nw").down(Math.max(0, this.items[n + 1].up + s.VS - s.AR * 2)).arc("ws").addTo(this), e += Math.max(o.down + s.VS, s.AR * 2) + Math.max(this.items[n + 1].up + s.VS, s.AR * 2), t = i + s.AR);
|
|
270
|
+
}
|
|
271
|
+
return this.items.length > 1 && (new f(t, e).h(s.AR).addTo(this), t += s.AR), new f(t, e).h(h[1]).addTo(this), this;
|
|
272
|
+
}
|
|
273
|
+
toTextDiagram() {
|
|
274
|
+
var [t, e, r, h, i, n] = _._getParts(["corner_bot_left", "corner_bot_right", "corner_top_left", "corner_top_right", "line", "line_vertical"]), o = [];
|
|
275
|
+
for (const S of this.items)
|
|
276
|
+
o.push(S.toTextDiagram());
|
|
277
|
+
var w = Math.max(...o.map(function(S) {
|
|
278
|
+
return S.width;
|
|
279
|
+
})), d = [], p = [], u = new _(0, 0, [i.repeat(w)]), a = null;
|
|
280
|
+
for (var [l, g] of O(o)) {
|
|
281
|
+
if (l == 0) {
|
|
282
|
+
d.push(i + i);
|
|
283
|
+
for (var v = 0; v < g.height - g.entry - 1; v++)
|
|
284
|
+
d.push(" ");
|
|
285
|
+
} else {
|
|
286
|
+
for (a = a.appendBelow(u, []), d.push(r + i), v = 0; v < g.entry; v++)
|
|
287
|
+
d.push(n + " ");
|
|
288
|
+
for (d.push(t + i), v = 0; v < g.height - g.entry - 1; v++)
|
|
289
|
+
d.push(" ");
|
|
290
|
+
for (v = 0; v < g.exit; v++)
|
|
291
|
+
p.push(" ");
|
|
292
|
+
}
|
|
293
|
+
if (l < o.length - 1) {
|
|
294
|
+
for (p.push(i + h), v = 0; v < g.height - g.exit - 1; v++)
|
|
295
|
+
p.push(" " + n);
|
|
296
|
+
p.push(i + e);
|
|
297
|
+
} else
|
|
298
|
+
p.push(i + i);
|
|
299
|
+
var [T, m] = _._gaps(w, g.width);
|
|
300
|
+
g = g.expand(T, m, 0, 0), l == 0 ? a = g : a = a.appendBelow(g, []);
|
|
301
|
+
}
|
|
302
|
+
var x = new _(0, 0, d);
|
|
303
|
+
a = x.appendRight(a, "");
|
|
304
|
+
var I = new _(0, p.length - 1, p);
|
|
305
|
+
return a = a.appendRight(I, ""), a;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
k.Stack = (...c) => new tt(...c);
|
|
309
|
+
class et extends G {
|
|
310
|
+
constructor(...t) {
|
|
311
|
+
if (super("g", t), t.length === 0)
|
|
312
|
+
throw new RangeError("OptionalSequence() must have at least one child.");
|
|
313
|
+
if (t.length === 1)
|
|
314
|
+
return new z(t);
|
|
315
|
+
var e = s.AR;
|
|
316
|
+
this.needsSpace = !1, this.width = 0, this.up = 0, this.height = y(this.items, function(o) {
|
|
317
|
+
return o.height;
|
|
318
|
+
}), this.down = this.items[0].down;
|
|
319
|
+
for (var r = 0, h = 0; h < this.items.length; h++) {
|
|
320
|
+
var i = this.items[h];
|
|
321
|
+
this.up = Math.max(this.up, Math.max(e * 2, i.up + s.VS) - r), r += i.height, h > 0 && (this.down = Math.max(this.height + this.down, r + Math.max(e * 2, i.down + s.VS)) - this.height);
|
|
322
|
+
var n = (i.needsSpace ? 10 : 0) + i.width;
|
|
323
|
+
h === 0 ? this.width += e + Math.max(n, e) : this.width += e * 2 + Math.max(n, e) + e;
|
|
324
|
+
}
|
|
325
|
+
s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "optseq");
|
|
326
|
+
}
|
|
327
|
+
format(t, e, r) {
|
|
328
|
+
var h = s.AR, i = B(r, this.width);
|
|
329
|
+
new f(t, e).right(i[0]).addTo(this), new f(t + i[0] + this.width, e + this.height).right(i[1]).addTo(this), t += i[0];
|
|
330
|
+
for (var n = e - this.up, o = this.items.length - 1, w = 0; w < this.items.length; w++) {
|
|
331
|
+
var d = this.items[w], p = d.needsSpace ? 10 : 0, u = d.width + p;
|
|
332
|
+
w === 0 ? (new f(t, e).arc("se").up(e - n - h * 2).arc("wn").right(u - h).arc("ne").down(e + d.height - n - h * 2).arc("ws").addTo(this), new f(t, e).right(p + h).addTo(this), d.format(t + p + h, e, d.width).addTo(this), t += u + h, e += d.height) : w < o ? (new f(t, n).right(h * 2 + Math.max(u, h) + h).arc("ne").down(e - n + d.height - h * 2).arc("ws").addTo(this), new f(t, e).right(h * 2).addTo(this), d.format(t + h * 2, e, d.width).addTo(this), new f(t + d.width + h * 2, e + d.height).right(p + h).addTo(this), new f(t, e).arc("ne").down(d.height + Math.max(d.down + s.VS, h * 2) - h * 2).arc("ws").right(u - h).arc("se").up(d.down + s.VS - h * 2).arc("wn").addTo(this), t += h * 2 + Math.max(u, h) + h, e += d.height) : (new f(t, e).right(h * 2).addTo(this), d.format(t + h * 2, e, d.width).addTo(this), new f(t + h * 2 + d.width, e + d.height).right(p + h).addTo(this), new f(t, e).arc("ne").down(d.height + Math.max(d.down + s.VS, h * 2) - h * 2).arc("ws").right(u - h).arc("se").up(d.down + s.VS - h * 2).arc("wn").addTo(this));
|
|
333
|
+
}
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
toTextDiagram() {
|
|
337
|
+
var [t, e, r, h, i, n] = _._getParts(["line", "line_vertical", "roundcorner_bot_left", "roundcorner_bot_right", "roundcorner_top_left", "roundcorner_top_right"]), o = [];
|
|
338
|
+
for (const M of this.items)
|
|
339
|
+
o.push(M.toTextDiagram());
|
|
340
|
+
for (var w = Math.max(...o.map(function(M) {
|
|
341
|
+
return M.entry;
|
|
342
|
+
})), d = Math.max(...o.slice(0, -1).map(function(M) {
|
|
343
|
+
return M.entry;
|
|
344
|
+
})), p = w - d, u = [], a = 0; a < p; a++)
|
|
345
|
+
u.push(" ");
|
|
346
|
+
for (u.push(i + t), a = 0; a < d; a++)
|
|
347
|
+
u.push(e + " ");
|
|
348
|
+
u.push(h + t);
|
|
349
|
+
var l = new _(u.length - 1, u.length - 1, u);
|
|
350
|
+
for (const [M, V] of O(o)) {
|
|
351
|
+
if (M > 0) {
|
|
352
|
+
for (u = [], a = 0; a < p; a++)
|
|
353
|
+
u.push(" ");
|
|
354
|
+
for (u.push(t + t), a = 0; a < l.exit - p - 1; a++)
|
|
355
|
+
u.push(" ");
|
|
356
|
+
for (u.push(t + n), a = 0; a < V.height - V.entry - 1; a++)
|
|
357
|
+
u.push(" " + e);
|
|
358
|
+
u.push(" " + r);
|
|
359
|
+
var g = new _(l.exit, l.exit, u);
|
|
360
|
+
for (l = l.appendRight(g, ""), u = [], a = 0; a < p; a++)
|
|
361
|
+
u.push(" ");
|
|
362
|
+
var v = M < o.length - 1 ? t : " ";
|
|
363
|
+
for (u.push(t + n + v), a = 0; a < l.exit - p - 1; a++)
|
|
364
|
+
u.push(" " + e + " ");
|
|
365
|
+
for (u.push(t + r + t), a = 0; a < V.height - V.entry - 1; a++)
|
|
366
|
+
u.push(" ");
|
|
367
|
+
u.push(t + t + t);
|
|
368
|
+
var T = new _(l.exit, l.exit, u);
|
|
369
|
+
l = l.appendRight(T, "");
|
|
370
|
+
}
|
|
371
|
+
var m = new _(0, 0, []);
|
|
372
|
+
if (M < o.length - 1) {
|
|
373
|
+
for (u = [], u.push(t.repeat(V.width)), a = 0; a < d - V.entry; a++)
|
|
374
|
+
u.push(" ".repeat(V.width));
|
|
375
|
+
var x = new _(0, 0, u);
|
|
376
|
+
m = m.appendBelow(x, []);
|
|
377
|
+
}
|
|
378
|
+
if (m = m.appendBelow(V, [], !0, !0), M > 0) {
|
|
379
|
+
var I = new _(0, 0, [t.repeat(V.width)]);
|
|
380
|
+
m = m.appendBelow(I, []);
|
|
381
|
+
}
|
|
382
|
+
if (l = l.appendRight(m, ""), 0 < M) {
|
|
383
|
+
for (u = [], a = 0; a < p; a++)
|
|
384
|
+
u.push(" ");
|
|
385
|
+
var S = M < o.length - 1 ? t : " ";
|
|
386
|
+
for (u.push(S.repeat(2)), a = 0; a < l.exit - p - 1; a++)
|
|
387
|
+
u.push(" ");
|
|
388
|
+
for (u.push(t + i), a = 0; a < m.height - m.exit - 2; a++)
|
|
389
|
+
u.push(" " + e);
|
|
390
|
+
u.push(t + h);
|
|
391
|
+
var E = new _(l.exit, l.exit, u);
|
|
392
|
+
l = l.appendRight(E, "");
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return l;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
k.OptionalSequence = (...c) => new et(...c);
|
|
399
|
+
class ht extends G {
|
|
400
|
+
constructor(...t) {
|
|
401
|
+
if (super("g", t), t.length === 1)
|
|
402
|
+
return new z(t);
|
|
403
|
+
if (t.length !== 2)
|
|
404
|
+
throw new RangeError("AlternatingSequence() must have one or two children.");
|
|
405
|
+
this.needsSpace = !1;
|
|
406
|
+
const e = s.AR, r = s.VS, h = Math.max, i = this.items[0], n = this.items[1], o = 1 / Math.sqrt(2) * e * 2, w = (1 - 1 / Math.sqrt(2)) * e * 2, d = Math.max(e, s.VS), p = d - w + o, u = h(e + e, d / 2 + e + e, d / 2 + r + i.down);
|
|
407
|
+
this.up = u + i.height + i.up;
|
|
408
|
+
const a = h(e + e, d / 2 + e + e, d / 2 + r + n.up);
|
|
409
|
+
this.down = a + n.height + n.down, this.height = 0;
|
|
410
|
+
const l = 2 * (i.needsSpace ? 10 : 0) + i.width, g = 2 * (n.needsSpace ? 10 : 0) + n.width;
|
|
411
|
+
this.width = 2 * e + h(l, p, g) + 2 * e, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "altseq");
|
|
412
|
+
}
|
|
413
|
+
format(t, e, r) {
|
|
414
|
+
const h = s.AR, i = B(r, this.width);
|
|
415
|
+
new f(t, e).right(i[0]).addTo(this), t += i[0], new f(t + this.width, e).right(i[1]).addTo(this);
|
|
416
|
+
const n = this.items[0], o = this.items[1], w = this.up - n.up, d = this.up - n.up - n.height;
|
|
417
|
+
new f(t, e).arc("se").up(w - 2 * h).arc("wn").addTo(this), n.format(t + 2 * h, e - w, this.width - 4 * h).addTo(this), new f(t + this.width - 2 * h, e - d).arc("ne").down(d - 2 * h).arc("ws").addTo(this);
|
|
418
|
+
const p = this.down - o.down - o.height, u = this.down - o.down;
|
|
419
|
+
new f(t, e).arc("ne").down(p - 2 * h).arc("ws").addTo(this), o.format(t + 2 * h, e + p, this.width - 4 * h).addTo(this), new f(t + this.width - 2 * h, e + u).arc("se").up(u - 2 * h).arc("wn").addTo(this);
|
|
420
|
+
const a = 1 / Math.sqrt(2) * h * 2, l = (1 - 1 / Math.sqrt(2)) * h * 2, g = Math.max(h, s.VS), v = g - l + a, T = (this.width - 4 * h - v) / 2;
|
|
421
|
+
return new f(t + h, e - g / 2 - h).arc("ws").right(T).arc_8("n", "cw").l(v - a, g - l).arc_8("sw", "ccw").right(T).arc("ne").addTo(this), new f(t + h, e + g / 2 + h).arc("wn").right(T).arc_8("s", "ccw").l(v - a, -(g - l)).arc_8("nw", "cw").right(T).arc("se").addTo(this), this;
|
|
422
|
+
}
|
|
423
|
+
toTextDiagram() {
|
|
424
|
+
for (var [t, e, r, h, i, n, o, w, d] = _._getParts(["cross_diag", "roundcorner_bot_left", "roundcorner_bot_right", "roundcorner_top_left", "roundcorner_top_right", "line", "line_vertical", "tee_left", "tee_right"]), p = this.items[0].toTextDiagram(), u = this.items[1].toTextDiagram(), a = _._maxWidth(p, u), [l, g] = _._gaps(a, 0), v = [], T = [], m = [], [x, I] = _._gaps(p.width, 0), S = p.expand(l - x, g - I, 0, 0), E = 0; E < S.entry; E++)
|
|
425
|
+
v.push(" ");
|
|
426
|
+
for (v.push(h + n), E = 0; E < S.height - S.entry - 1; E++)
|
|
427
|
+
v.push(o + " ");
|
|
428
|
+
for (v.push(e + n), E = 0; E < S.exit; E++)
|
|
429
|
+
T.push(" ");
|
|
430
|
+
for (T.push(n + i), E = 0; E < S.height - S.exit - 1; E++)
|
|
431
|
+
T.push(" " + o);
|
|
432
|
+
for (T.push(n + r), m.push(n.repeat(l - 1) + i + " " + h + n.repeat(g - 2)), m.push(" ".repeat(l - 1) + " " + t + " " + " ".repeat(g - 2)), m.push(n.repeat(l - 1) + r + " " + e + n.repeat(g - 2)), v.push(" "), T.push(" "), [x, I] = _._gaps(u.width, 0), u = u.expand(l - x, g - I, 0, 0), S = S.appendBelow(u, m, !0, !0), v.push(h + n), E = 0; E < u.entry; E++)
|
|
433
|
+
v.push(o + " ");
|
|
434
|
+
for (v.push(e + n), T.push(n + i), E = 0; E < u.exit; E++)
|
|
435
|
+
T.push(" " + o);
|
|
436
|
+
T.push(n + r), S = S.alter(p.height + Math.trunc(m.length / 2), p.height + Math.trunc(m.length / 2));
|
|
437
|
+
var M = new _(p.height + Math.trunc(m.length / 2), p.height + Math.trunc(m.length / 2), v), V = new _(p.height + Math.trunc(m.length / 2), p.height + Math.trunc(m.length / 2), T);
|
|
438
|
+
return S = M.appendRight(S, "").appendRight(V, ""), S = new _(1, 1, [h, w, e]).appendRight(S, "").appendRight(new _(1, 1, [i, d, r]), ""), S;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
k.AlternatingSequence = (...c) => new ht(...c);
|
|
442
|
+
class L extends G {
|
|
443
|
+
constructor(t, ...e) {
|
|
444
|
+
if (super("g", e), typeof t != "number" || t !== Math.floor(t))
|
|
445
|
+
throw new TypeError("The first argument of Choice() must be an integer.");
|
|
446
|
+
if (t < 0 || t >= e.length)
|
|
447
|
+
throw new RangeError("The first argument of Choice() must be an index for one of the items.");
|
|
448
|
+
this.normal = t, this.width = q(this.items, (w) => w.width) + s.AR * 4;
|
|
449
|
+
var r = this.items[0], h = this.items[e.length - 1], i = this.items[t];
|
|
450
|
+
this.separators = Array.from({ length: e.length - 1 }, (w) => 0), this.up = 0;
|
|
451
|
+
for (var n, o = t - 1; o >= 0; o--) {
|
|
452
|
+
o == t - 1 ? n = s.AR * 2 : n = s.AR;
|
|
453
|
+
let w = this.items[o], d = this.items[o + 1], p = d.up + s.VS + w.down + w.height, u = d.height + d.up + s.VS + w.down, a = s.VS;
|
|
454
|
+
(u < n || p < n) && (a += Math.max(n - p, n - u)), this.separators[o] = a, this.up += d.up + a + w.down + w.height;
|
|
455
|
+
}
|
|
456
|
+
this.up += r.up, this.height = i.height, this.down = 0;
|
|
457
|
+
for (var o = t + 1; o < this.items.length; o++) {
|
|
458
|
+
o == t + 1 ? n = s.AR * 2 : n = s.AR;
|
|
459
|
+
let d = this.items[o], p = this.items[o - 1], u = p.height + p.down + s.VS + d.up, a = p.down + s.VS + d.up + d.height, l = s.VS;
|
|
460
|
+
(u < n || a < n) && (l += Math.max(n - u, n - a)), this.separators[o - 1] = l, this.down += p.down + l + d.up + d.height;
|
|
461
|
+
}
|
|
462
|
+
this.down += h.down, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "choice");
|
|
463
|
+
}
|
|
464
|
+
format(t, e, r) {
|
|
465
|
+
var h = B(r, this.width);
|
|
466
|
+
new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e + this.height).h(h[1]).addTo(this), t += h[0];
|
|
467
|
+
for (var i = this.items.length - 1, n = this.width - s.AR * 4, w = 0, o = this.normal - 1; o >= 0; o--) {
|
|
468
|
+
let d = this.items[o], p = this.items[o + 1];
|
|
469
|
+
w += p.up + this.separators[o] + d.down + d.height, new f(t, e).arc("se").up(w - s.AR * 2).arc("wn").addTo(this), d.format(t + s.AR * 2, e - w, n).addTo(this), new f(t + s.AR * 2 + n, e - w + d.height).arc("ne").down(w - d.height + this.height - s.AR * 2).arc("ws").addTo(this);
|
|
470
|
+
}
|
|
471
|
+
new f(t, e).right(s.AR * 2).addTo(this), this.items[this.normal].format(t + s.AR * 2, e, n).addTo(this), new f(t + s.AR * 2 + n, e + this.height).right(s.AR * 2).addTo(this);
|
|
472
|
+
for (var w = 0, o = this.normal + 1; o <= i; o++) {
|
|
473
|
+
let p = this.items[o], u = this.items[o - 1];
|
|
474
|
+
w += u.height + u.down + this.separators[o - 1] + p.up, new f(t, e).arc("ne").down(w - s.AR * 2).arc("ws").addTo(this), p.format || console.log(p), p.format(t + s.AR * 2, e + w, n).addTo(this), new f(t + s.AR * 2 + n, e + w + p.height).arc("se").up(w - s.AR * 2 + p.height - this.height).arc("wn").addTo(this);
|
|
475
|
+
}
|
|
476
|
+
return this;
|
|
477
|
+
}
|
|
478
|
+
toTextDiagram() {
|
|
479
|
+
var [t, e, r, h, i, n, o] = _._getParts(["cross", "line", "line_vertical", "roundcorner_bot_left", "roundcorner_bot_right", "roundcorner_top_left", "roundcorner_top_right"]), w = [];
|
|
480
|
+
for (const b of this.items)
|
|
481
|
+
w.push(b.toTextDiagram().expand(1, 1, 0, 0));
|
|
482
|
+
var d = Math.max(...w.map(function(b) {
|
|
483
|
+
return b.width;
|
|
484
|
+
})), p = new _(0, 0, []);
|
|
485
|
+
for (var [u, a] of O(w)) {
|
|
486
|
+
var [l, g] = _._gaps(d, a.width);
|
|
487
|
+
a = a.expand(l, g, 0, 0);
|
|
488
|
+
for (var v = !0, T = [], m = [], x = 0; x < a.height; x++)
|
|
489
|
+
T.push(r), m.push(r);
|
|
490
|
+
var I = !1, S = !1;
|
|
491
|
+
if (u <= this.normal && (T[a.entry] = n, m[a.exit] = o, u == 0)) {
|
|
492
|
+
for (v = !1, x = 0; x < a.entry; x++)
|
|
493
|
+
T[x] = " ";
|
|
494
|
+
for (x = 0; x < a.exit; x++)
|
|
495
|
+
m[x] = " ";
|
|
496
|
+
}
|
|
497
|
+
if (u >= this.normal && (T[a.entry] = h, m[a.exit] = i, u == 0 && (v = !1), u == this.items.length - 1)) {
|
|
498
|
+
for (x = a.entry + 1; x < a.height; x++)
|
|
499
|
+
T[x] = " ";
|
|
500
|
+
for (x = a.exit + 1; x < a.height; x++)
|
|
501
|
+
m[x] = " ";
|
|
502
|
+
}
|
|
503
|
+
u == this.normal && (T[a.entry] = t, m[a.exit] = t, I = !0, S = !0, u == 0 && u == this.items.length - 1 ? (T[a.entry] = e, m[a.exit] = e) : u == 0 ? (T[a.entry] = o, m[a.exit] = n) : u == this.items.length - 1 && (T[a.entry] = i, m[a.exit] = h));
|
|
504
|
+
var E = new _(a.entry, a.entry, T), M = new _(a.exit, a.exit, m);
|
|
505
|
+
a = E.appendRight(a, "").appendRight(M, "");
|
|
506
|
+
var V = v ? [r + " ".repeat(_._maxWidth(p, a) - 2) + r] : [];
|
|
507
|
+
p = p.appendBelow(a, V, I, S);
|
|
508
|
+
}
|
|
509
|
+
return p;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
k.Choice = (...c) => new L(...c);
|
|
513
|
+
class rt extends G {
|
|
514
|
+
constructor(...t) {
|
|
515
|
+
if (super("g", t), t.length === 0)
|
|
516
|
+
throw new RangeError("HorizontalChoice() must have at least one child.");
|
|
517
|
+
if (t.length === 1)
|
|
518
|
+
return new z(t);
|
|
519
|
+
const e = this.items.slice(0, -1), r = this.items.slice(1, -1), h = this.items[0], i = this.items[this.items.length - 1];
|
|
520
|
+
this.needsSpace = !1, this.width = s.AR, this.width += s.AR * 2 * (this.items.length - 1), this.width += y(this.items, (n) => n.width + (n.needsSpace ? 20 : 0)), this.width += i.height > 0 ? s.AR : 0, this.width += s.AR, this.height = 0, this._upperTrack = Math.max(
|
|
521
|
+
s.AR * 2,
|
|
522
|
+
s.VS,
|
|
523
|
+
q(e, (n) => n.up) + s.VS
|
|
524
|
+
), this.up = Math.max(this._upperTrack, i.up), this._lowerTrack = Math.max(
|
|
525
|
+
s.VS,
|
|
526
|
+
q(r, (n) => n.height + Math.max(n.down + s.VS, s.AR * 2)),
|
|
527
|
+
i.height + i.down + s.VS
|
|
528
|
+
), h.height < this._lowerTrack && (this._lowerTrack = Math.max(this._lowerTrack, h.height + s.AR * 2)), this.down = Math.max(this._lowerTrack, h.height + h.down), s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "horizontalchoice");
|
|
529
|
+
}
|
|
530
|
+
format(t, e, r) {
|
|
531
|
+
var h = B(r, this.width);
|
|
532
|
+
new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e + this.height).h(h[1]).addTo(this), t += h[0];
|
|
533
|
+
const i = this.items[0], n = this.items[this.items.length - 1], o = this.items.slice(1), w = this.items.slice(0, -1);
|
|
534
|
+
var d = y(w, (l) => l.width + (l.needsSpace ? 20 : 0)) + (this.items.length - 2) * s.AR * 2 - s.AR;
|
|
535
|
+
new f(t, e).arc("se").v(-(this._upperTrack - s.AR * 2)).arc("wn").h(d).addTo(this);
|
|
536
|
+
var p = y(o, (l) => l.width + (l.needsSpace ? 20 : 0)) + (this.items.length - 2) * s.AR * 2 + (n.height > 0 ? s.AR : 0) - s.AR, u = t + s.AR + i.width + (i.needsSpace ? 20 : 0) + s.AR * 2;
|
|
537
|
+
new f(u, e + this._lowerTrack).h(p).arc("se").v(-(this._lowerTrack - s.AR * 2)).arc("wn").addTo(this);
|
|
538
|
+
for (const [l, g] of O(this.items)) {
|
|
539
|
+
l === 0 ? (new f(t, e).h(s.AR).addTo(this), t += s.AR) : (new f(t, e - this._upperTrack).arc("ne").v(this._upperTrack - s.AR * 2).arc("ws").addTo(this), t += s.AR * 2);
|
|
540
|
+
var a = g.width + (g.needsSpace ? 20 : 0);
|
|
541
|
+
g.format(t, e, a).addTo(this), t += a, l === this.items.length - 1 ? g.height === 0 ? new f(t, e).h(s.AR).addTo(this) : new f(t, e + g.height).arc("se").addTo(this) : l === 0 && g.height > this._lowerTrack ? g.height - this._lowerTrack >= s.AR * 2 ? new f(t, e + g.height).arc("se").v(this._lowerTrack - g.height + s.AR * 2).arc("wn").addTo(this) : new f(t, e + g.height).l(s.AR * 2, this._lowerTrack - g.height).addTo(this) : new f(t, e + g.height).arc("ne").v(this._lowerTrack - g.height - s.AR * 2).arc("ws").addTo(this);
|
|
542
|
+
}
|
|
543
|
+
return this;
|
|
544
|
+
}
|
|
545
|
+
toTextDiagram() {
|
|
546
|
+
var [t, e, r, h, i, n] = _._getParts(["line", "line_vertical", "roundcorner_bot_left", "roundcorner_bot_right", "roundcorner_top_left", "roundcorner_top_right"]), o = [];
|
|
547
|
+
for (const b of this.items)
|
|
548
|
+
o.push(b.toTextDiagram());
|
|
549
|
+
for (var w = Math.max(...o.map(function(b) {
|
|
550
|
+
return b.entry;
|
|
551
|
+
})), d = Math.max(...o.slice(0, -1).map(function(b) {
|
|
552
|
+
return b.entry;
|
|
553
|
+
})), p = w - d, u = Math.max(...o.slice(1).map(function(b) {
|
|
554
|
+
return b.height - Math.min(b.entry, b.exit) - 1;
|
|
555
|
+
})), a = [], l = 0; l < p; l++)
|
|
556
|
+
a.push(" ");
|
|
557
|
+
for (a.push(i + t), l = 0; l < d; l++)
|
|
558
|
+
a.push(e + " ");
|
|
559
|
+
a.push(h + t);
|
|
560
|
+
var g = new _(a.length - 1, a.length - 1, a);
|
|
561
|
+
for (const [b, C] of O(o)) {
|
|
562
|
+
if (b > 0) {
|
|
563
|
+
for (a = [], l = 0; l < p; l++)
|
|
564
|
+
a.push(" ");
|
|
565
|
+
var v = b == o.length - 1 ? " " : t;
|
|
566
|
+
for (a.push(n + v), l = 0; l < d; l++)
|
|
567
|
+
a.push(e + " ");
|
|
568
|
+
for (a.push(r + t), l = 0; l < u; l++)
|
|
569
|
+
a.push(e + " ");
|
|
570
|
+
a.push(t + t);
|
|
571
|
+
var T = new _(g.exit, g.exit, a);
|
|
572
|
+
g = g.appendRight(T, "");
|
|
573
|
+
}
|
|
574
|
+
var m = new _(0, 0, []);
|
|
575
|
+
if (b < o.length - 1) {
|
|
576
|
+
for (a = [], a.push(t.repeat(C.width)), l = 0; l < d - C.entry; l++)
|
|
577
|
+
a.push(" ".repeat(C.width));
|
|
578
|
+
var x = new _(0, 0, a);
|
|
579
|
+
m = m.appendBelow(x, []);
|
|
580
|
+
}
|
|
581
|
+
if (m = m.appendBelow(C, [], !0, !0), b > 0) {
|
|
582
|
+
for (a = [], l = 0; l < u - (C.height - C.entry) + 1; l++)
|
|
583
|
+
a.push(" ".repeat(C.width));
|
|
584
|
+
a.push(t.repeat(C.width));
|
|
585
|
+
var I = new _(0, 0, a);
|
|
586
|
+
m = m.appendBelow(I, []);
|
|
587
|
+
}
|
|
588
|
+
if (g = g.appendRight(m, ""), b < o.length - 1) {
|
|
589
|
+
for (a = [], l = 0; l < p; l++)
|
|
590
|
+
a.push(" ");
|
|
591
|
+
for (a.push(t + t), l = 0; l < g.exit - p - 1; l++)
|
|
592
|
+
a.push(" ");
|
|
593
|
+
for (a.push(t + n), l = 0; l < u - (g.exit - g.entry); l++)
|
|
594
|
+
a.push(" " + e);
|
|
595
|
+
var S = b > 0 ? t : " ";
|
|
596
|
+
a.push(S + r);
|
|
597
|
+
var E = w + 1 + (g.exit - g.entry), M = new _(E, w + 1, a);
|
|
598
|
+
g = g.appendRight(M, "");
|
|
599
|
+
} else {
|
|
600
|
+
a = [];
|
|
601
|
+
var V = g.exit != g.entry ? " " : t;
|
|
602
|
+
for (a.push(V + i), l = 0; l < g.exit - g.entry - 1; l++)
|
|
603
|
+
a.push(" " + e);
|
|
604
|
+
for (g.exit != g.entry && a.push(t + h), l = 0; l < u - (g.exit - g.entry); l++)
|
|
605
|
+
a.push(" " + e);
|
|
606
|
+
a.push(t + h), M = new _(g.exit - g.entry, 0, a), g = g.appendRight(M, "");
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return g;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
k.HorizontalChoice = (...c) => new rt(...c);
|
|
613
|
+
class st extends G {
|
|
614
|
+
constructor(t, e, ...r) {
|
|
615
|
+
if (super("g", r), typeof t != "number" || t !== Math.floor(t))
|
|
616
|
+
throw new TypeError("The first argument of MultipleChoice() must be an integer.");
|
|
617
|
+
if (t < 0 || t >= r.length)
|
|
618
|
+
throw new RangeError("The first argument of MultipleChoice() must be an index for one of the items.");
|
|
619
|
+
if (this.normal = t, e != "any" && e != "all")
|
|
620
|
+
throw new SyntaxError("The second argument of MultipleChoice must be 'any' or 'all'.");
|
|
621
|
+
this.type = e, this.needsSpace = !0, this.innerWidth = q(this.items, function(i) {
|
|
622
|
+
return i.width;
|
|
623
|
+
}), this.width = 30 + s.AR + this.innerWidth + s.AR + 20, this.up = this.items[0].up, this.down = this.items[this.items.length - 1].down, this.height = this.items[t].height;
|
|
624
|
+
for (var h = 0; h < this.items.length; h++) {
|
|
625
|
+
let i = this.items[h], n;
|
|
626
|
+
h == t - 1 || h == t + 1 ? n = 10 + s.AR : n = s.AR, h < t ? this.up += Math.max(n, i.height + i.down + s.VS + this.items[h + 1].up) : h > t && (this.down += Math.max(n, i.up + s.VS + this.items[h - 1].down + this.items[h - 1].height));
|
|
627
|
+
}
|
|
628
|
+
this.down -= this.items[t].height, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "multiplechoice");
|
|
629
|
+
}
|
|
630
|
+
format(t, e, r) {
|
|
631
|
+
var h = B(r, this.width);
|
|
632
|
+
new f(t, e).right(h[0]).addTo(this), new f(t + h[0] + this.width, e + this.height).right(h[1]).addTo(this), t += h[0];
|
|
633
|
+
for (var i = this.items[this.normal], n, o = this.normal - 1; o >= 0; o--) {
|
|
634
|
+
var w = this.items[o];
|
|
635
|
+
o == this.normal - 1 && (n = Math.max(10 + s.AR, i.up + s.VS + w.down + w.height)), new f(t + 30, e).up(n - s.AR).arc("wn").addTo(this), w.format(t + 30 + s.AR, e - n, this.innerWidth).addTo(this), new f(t + 30 + s.AR + this.innerWidth, e - n + w.height).arc("ne").down(n - w.height + this.height - s.AR - 10).addTo(this), o !== 0 && (n += Math.max(s.AR, w.up + s.VS + this.items[o - 1].down + this.items[o - 1].height));
|
|
636
|
+
}
|
|
637
|
+
for (new f(t + 30, e).right(s.AR).addTo(this), i.format(t + 30 + s.AR, e, this.innerWidth).addTo(this), new f(t + 30 + s.AR + this.innerWidth, e + this.height).right(s.AR).addTo(this), o = this.normal + 1; o < this.items.length; o++) {
|
|
638
|
+
let p = this.items[o];
|
|
639
|
+
o == this.normal + 1 && (n = Math.max(10 + s.AR, i.height + i.down + s.VS + p.up)), new f(t + 30, e).down(n - s.AR).arc("ws").addTo(this), p.format(t + 30 + s.AR, e + n, this.innerWidth).addTo(this), new f(t + 30 + s.AR + this.innerWidth, e + n + p.height).arc("se").up(n - s.AR + p.height - i.height).addTo(this), o != this.items.length - 1 && (n += Math.max(s.AR, p.height + p.down + s.VS + this.items[o + 1].up));
|
|
640
|
+
}
|
|
641
|
+
var d = new A("g", { class: "diagram-text" }).addTo(this);
|
|
642
|
+
return new A("title", {}, this.type == "any" ? "take one or more branches, once each, in any order" : "take all branches, once each, in any order").addTo(d), new A("path", {
|
|
643
|
+
d: "M " + (t + 30) + " " + (e - 10) + " h -26 a 4 4 0 0 0 -4 4 v 12 a 4 4 0 0 0 4 4 h 26 z",
|
|
644
|
+
class: "diagram-text"
|
|
645
|
+
}).addTo(d), new A("text", {
|
|
646
|
+
x: t + 15,
|
|
647
|
+
y: e + 4,
|
|
648
|
+
class: "diagram-text"
|
|
649
|
+
}, this.type == "any" ? "1+" : "all").addTo(d), new A("path", {
|
|
650
|
+
d: "M " + (t + this.width - 20) + " " + (e - 10) + " h 16 a 4 4 0 0 1 4 4 v 12 a 4 4 0 0 1 -4 4 h -16 z",
|
|
651
|
+
class: "diagram-text"
|
|
652
|
+
}).addTo(d), new A("path", {
|
|
653
|
+
d: "M " + (t + this.width - 13) + " " + (e - 2) + " a 4 4 0 1 0 6 -1 m 2.75 -1 h -4 v 4 m 0 -3 h 2",
|
|
654
|
+
style: "stroke-width: 1.75"
|
|
655
|
+
}).addTo(d), this;
|
|
656
|
+
}
|
|
657
|
+
toTextDiagram() {
|
|
658
|
+
var [t] = _._getParts(["multi_repeat"]);
|
|
659
|
+
if (this.type == "any")
|
|
660
|
+
var e = _.rect("1+");
|
|
661
|
+
else
|
|
662
|
+
e = _.rect("all");
|
|
663
|
+
var r = L.prototype.toTextDiagram.call(this), h = _.rect(t);
|
|
664
|
+
return r = e.appendRight(r, ""), r = r.appendRight(h, ""), r;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
k.MultipleChoice = (...c) => new st(...c);
|
|
668
|
+
class F extends A {
|
|
669
|
+
constructor(t, e) {
|
|
670
|
+
if (e === void 0)
|
|
671
|
+
return new L(1, new W(), t);
|
|
672
|
+
if (e === "skip")
|
|
673
|
+
return new L(0, new W(), t);
|
|
674
|
+
throw "Unknown value for Optional()'s 'skip' argument.";
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
k.Optional = (...c) => new F(...c);
|
|
678
|
+
class X extends A {
|
|
679
|
+
constructor(t, e) {
|
|
680
|
+
super("g"), e = e || new W(), this.item = P(t), this.rep = P(e), this.width = Math.max(this.item.width, this.rep.width) + s.AR * 2, this.height = this.item.height, this.up = this.item.up, this.down = Math.max(s.AR * 2, this.item.down + s.VS + this.rep.up + this.rep.height + this.rep.down), this.needsSpace = !0, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "oneormore");
|
|
681
|
+
}
|
|
682
|
+
format(t, e, r) {
|
|
683
|
+
var h = B(r, this.width);
|
|
684
|
+
new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e + this.height).h(h[1]).addTo(this), t += h[0], new f(t, e).right(s.AR).addTo(this), this.item.format(t + s.AR, e, this.width - s.AR * 2).addTo(this), new f(t + this.width - s.AR, e + this.height).right(s.AR).addTo(this);
|
|
685
|
+
var i = Math.max(s.AR * 2, this.item.height + this.item.down + s.VS + this.rep.up);
|
|
686
|
+
return new f(t + s.AR, e).arc("nw").down(i - s.AR * 2).arc("ws").addTo(this), this.rep.format(t + s.AR, e + i, this.width - s.AR * 2).addTo(this), new f(t + this.width - s.AR, e + i + this.rep.height).arc("se").up(i - s.AR * 2 + this.rep.height - this.item.height).arc("en").addTo(this), this;
|
|
687
|
+
}
|
|
688
|
+
toTextDiagram() {
|
|
689
|
+
var [t, e, r, h, i, n, o] = _._getParts(["line", "repeat_top_left", "repeat_left", "repeat_bot_left", "repeat_top_right", "repeat_right", "repeat_bot_right"]), w = this.item.toTextDiagram(), d = this.rep.toTextDiagram(), p = _._maxWidth(w, d);
|
|
690
|
+
d = d.expand(0, p - d.width, 0, 0), w = w.expand(0, p - w.width, 0, 0);
|
|
691
|
+
var u = w.appendBelow(d, []), a = [];
|
|
692
|
+
a.push(e + t);
|
|
693
|
+
for (var l = 0; l < w.height - w.entry + d.entry - 1; l++)
|
|
694
|
+
a.push(r + " ");
|
|
695
|
+
a.push(h + t);
|
|
696
|
+
var g = new _(0, 0, a);
|
|
697
|
+
g = g.appendRight(u, "");
|
|
698
|
+
var v = [];
|
|
699
|
+
for (v.push(t + i), l = 0; l < w.height - w.exit + d.exit - 1; l++)
|
|
700
|
+
v.push(" " + n);
|
|
701
|
+
v.push(t + o);
|
|
702
|
+
var T = new _(0, 0, v), m = g.appendRight(T, "");
|
|
703
|
+
return m;
|
|
704
|
+
}
|
|
705
|
+
walk(t) {
|
|
706
|
+
t(this), this.item.walk(t), this.rep.walk(t);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
k.OneOrMore = (...c) => new X(...c);
|
|
710
|
+
class it extends A {
|
|
711
|
+
constructor(t, e, r) {
|
|
712
|
+
return new F(new X(t, e), r);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
k.ZeroOrMore = (...c) => new it(...c);
|
|
716
|
+
class at extends A {
|
|
717
|
+
constructor(t, e) {
|
|
718
|
+
super("g"), this.item = P(t), this.label = e instanceof A ? e : e ? new K(e) : void 0, this.width = Math.max(
|
|
719
|
+
this.item.width + (this.item.needsSpace ? 20 : 0),
|
|
720
|
+
this.label ? this.label.width : 0,
|
|
721
|
+
s.AR * 2
|
|
722
|
+
), this.height = this.item.height, this.boxUp = this.up = Math.max(this.item.up + s.VS, s.AR), this.label && (this.up += this.label.up + this.label.height + this.label.down), this.down = Math.max(this.item.down + s.VS, s.AR), this.needsSpace = !0, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "group");
|
|
723
|
+
}
|
|
724
|
+
format(t, e, r) {
|
|
725
|
+
var h = B(r, this.width);
|
|
726
|
+
return new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e + this.height).h(h[1]).addTo(this), t += h[0], new A("rect", {
|
|
727
|
+
x: t,
|
|
728
|
+
y: e - this.boxUp,
|
|
729
|
+
width: this.width,
|
|
730
|
+
height: this.boxUp + this.height + this.down,
|
|
731
|
+
rx: s.AR,
|
|
732
|
+
ry: s.AR,
|
|
733
|
+
class: "group-box"
|
|
734
|
+
}).addTo(this), this.item.format(t, e, this.width).addTo(this), this.label && this.label.format(
|
|
735
|
+
t,
|
|
736
|
+
e - (this.boxUp + this.label.down + this.label.height),
|
|
737
|
+
this.label.width
|
|
738
|
+
).addTo(this), this;
|
|
739
|
+
}
|
|
740
|
+
toTextDiagram() {
|
|
741
|
+
var t = _.roundrect(this.item.toTextDiagram(), !0);
|
|
742
|
+
if (this.label != null) {
|
|
743
|
+
var e = this.label.toTextDiagram();
|
|
744
|
+
t = e.appendBelow(t, [], !0, !0).expand(0, 0, 1, 0);
|
|
745
|
+
}
|
|
746
|
+
return t;
|
|
747
|
+
}
|
|
748
|
+
walk(t) {
|
|
749
|
+
t(this), this.item.walk(t), this.label.walk(t);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
k.Group = (...c) => new at(...c);
|
|
753
|
+
class U extends A {
|
|
754
|
+
constructor({ type: t = "simple", label: e } = {}) {
|
|
755
|
+
super("g"), this.width = 20, this.height = 0, this.up = 10, this.down = 10, this.type = t, e && (this.label = "" + e, this.width = Math.max(20, this.label.length * s.CHAR_WIDTH + 10)), s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "start");
|
|
756
|
+
}
|
|
757
|
+
format(t, e) {
|
|
758
|
+
let r = new f(t, e - 10);
|
|
759
|
+
return this.type === "complex" ? r.down(20).m(0, -10).right(this.width).addTo(this) : r.down(20).m(10, -20).down(20).m(-10, -10).right(this.width).addTo(this), this.label && new A("text", { x: t, y: e - 15, style: "text-anchor:start" }, this.label).addTo(this), this;
|
|
760
|
+
}
|
|
761
|
+
toTextDiagram() {
|
|
762
|
+
var [t, e, r] = _._getParts(["cross", "line", "tee_right"]);
|
|
763
|
+
if (this.type === "simple")
|
|
764
|
+
var h = r + t + e;
|
|
765
|
+
else
|
|
766
|
+
h = r + e;
|
|
767
|
+
var i = new _(0, 0, []);
|
|
768
|
+
this.label != null && (i = new _(0, 0, [this.label]), h = _._padR(h, i.width, e));
|
|
769
|
+
var n = new _(0, 0, [h]);
|
|
770
|
+
return i.appendBelow(n, [], !0, !0);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
k.Start = (...c) => new U(...c);
|
|
774
|
+
class H extends A {
|
|
775
|
+
constructor({ type: t = "simple" } = {}) {
|
|
776
|
+
super("path"), this.width = 20, this.height = 0, this.up = 10, this.down = 10, this.type = t, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "end");
|
|
777
|
+
}
|
|
778
|
+
format(t, e) {
|
|
779
|
+
return this.type === "complex" ? this.attrs.d = "M " + t + " " + e + " h 20 m 0 -10 v 20" : this.attrs.d = "M " + t + " " + e + " h 20 m -10 -10 v 20 m 10 -20 v 20", this;
|
|
780
|
+
}
|
|
781
|
+
toTextDiagram() {
|
|
782
|
+
var [t, e, r] = _._getParts(["cross", "line", "tee_left"]);
|
|
783
|
+
if (this.type === "simple")
|
|
784
|
+
var h = e + t + r;
|
|
785
|
+
else
|
|
786
|
+
h = e + r;
|
|
787
|
+
return new _(0, 0, [h]);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
k.End = (...c) => new H(...c);
|
|
791
|
+
class j extends A {
|
|
792
|
+
constructor(t, { href: e, title: r, cls: h } = {}) {
|
|
793
|
+
super("g", { class: ["terminal", h].join(" ") }), this.text = "" + t, this.href = e, this.title = r, this.cls = h, this.width = this.text.length * s.CHAR_WIDTH + 20, this.height = 0, this.up = 11, this.down = 11, this.needsSpace = !0, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "terminal");
|
|
794
|
+
}
|
|
795
|
+
format(t, e, r) {
|
|
796
|
+
var h = B(r, this.width);
|
|
797
|
+
new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e).h(h[1]).addTo(this), t += h[0], new A("rect", { x: t, y: e - 11, width: this.width, height: this.up + this.down, rx: 10, ry: 10 }).addTo(this);
|
|
798
|
+
var i = new A("text", { x: t + this.width / 2, y: e + 4 }, this.text);
|
|
799
|
+
return this.href ? new A("a", { "xlink:href": this.href }, [i]).addTo(this) : i.addTo(this), this.title && new A("title", {}, [this.title]).addTo(this), this;
|
|
800
|
+
}
|
|
801
|
+
toTextDiagram() {
|
|
802
|
+
return _.roundrect(this.text);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
k.Terminal = (...c) => new j(...c);
|
|
806
|
+
class nt extends A {
|
|
807
|
+
constructor(t, { href: e, title: r, cls: h = "" } = {}) {
|
|
808
|
+
super("g", { class: ["non-terminal", h].join(" ") }), this.text = "" + t, this.href = e, this.title = r, this.cls = h, this.width = this.text.length * s.CHAR_WIDTH + 20, this.height = 0, this.up = 11, this.down = 11, this.needsSpace = !0, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "nonterminal");
|
|
809
|
+
}
|
|
810
|
+
format(t, e, r) {
|
|
811
|
+
var h = B(r, this.width);
|
|
812
|
+
new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e).h(h[1]).addTo(this), t += h[0], new A("rect", { x: t, y: e - 11, width: this.width, height: this.up + this.down }).addTo(this);
|
|
813
|
+
var i = new A("text", { x: t + this.width / 2, y: e + 4 }, this.text);
|
|
814
|
+
return this.href ? new A("a", { "xlink:href": this.href }, [i]).addTo(this) : i.addTo(this), this.title && new A("title", {}, [this.title]).addTo(this), this;
|
|
815
|
+
}
|
|
816
|
+
toTextDiagram() {
|
|
817
|
+
return _.rect(this.text);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
k.NonTerminal = (...c) => new nt(...c);
|
|
821
|
+
class K extends A {
|
|
822
|
+
constructor(t, { href: e, title: r, cls: h = "" } = {}) {
|
|
823
|
+
super("g", { class: ["comment", h].join(" ") }), this.text = "" + t, this.href = e, this.title = r, this.cls = h, this.width = this.text.length * s.COMMENT_CHAR_WIDTH + 10, this.height = 0, this.up = 8, this.down = 8, this.needsSpace = !0, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "comment");
|
|
824
|
+
}
|
|
825
|
+
format(t, e, r) {
|
|
826
|
+
var h = B(r, this.width);
|
|
827
|
+
new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e + this.height).h(h[1]).addTo(this), t += h[0];
|
|
828
|
+
var i = new A("text", { x: t + this.width / 2, y: e + 5, class: "comment" }, this.text);
|
|
829
|
+
return this.href ? new A("a", { "xlink:href": this.href }, [i]).addTo(this) : i.addTo(this), this.title && new A("title", {}, this.title).addTo(this), this;
|
|
830
|
+
}
|
|
831
|
+
toTextDiagram() {
|
|
832
|
+
return new _(0, 0, [this.text]);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
k.Comment = (...c) => new K(...c);
|
|
836
|
+
class W extends A {
|
|
837
|
+
constructor() {
|
|
838
|
+
super("g"), this.width = 0, this.height = 0, this.up = 0, this.down = 0, this.needsSpace = !1, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "skip");
|
|
839
|
+
}
|
|
840
|
+
format(t, e, r) {
|
|
841
|
+
return new f(t, e).right(r).addTo(this), this;
|
|
842
|
+
}
|
|
843
|
+
toTextDiagram() {
|
|
844
|
+
var [t] = _._getParts(["line"]);
|
|
845
|
+
return new _(0, 0, [t]);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
k.Skip = (...c) => new W(...c);
|
|
849
|
+
class ot extends A {
|
|
850
|
+
constructor({ width: t = 50, up: e = 15, height: r = 25, down: h = 15, needsSpace: i = !0 } = {}) {
|
|
851
|
+
super("g"), this.width = t, this.height = r, this.up = e, this.down = h, this.needsSpace = !0, s.DEBUG && (this.attrs["data-updown"] = this.up + " " + this.height + " " + this.down, this.attrs["data-type"] = "block");
|
|
852
|
+
}
|
|
853
|
+
format(t, e, r) {
|
|
854
|
+
var h = B(r, this.width);
|
|
855
|
+
return new f(t, e).h(h[0]).addTo(this), new f(t + h[0] + this.width, e).h(h[1]).addTo(this), t += h[0], new A("rect", { x: t, y: e - this.up, width: this.width, height: this.up + this.height + this.down }).addTo(this), this;
|
|
856
|
+
}
|
|
857
|
+
toTextDiagram() {
|
|
858
|
+
return _.rect("");
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
k.Block = (...c) => new ot(...c);
|
|
862
|
+
const R = class R {
|
|
863
|
+
constructor(t, e, r) {
|
|
864
|
+
if (this.entry = t, this.exit = e, this.height = r.length, this.lines = Array.from(r), this.width = r.length > 0 ? r[0].length : 0, t > r.length)
|
|
865
|
+
throw new Error(`Entry is not within diagram vertically:
|
|
866
|
+
` + this._dump(!1));
|
|
867
|
+
if (e > r.length)
|
|
868
|
+
throw new Error(`Exit is not within diagram vertically:
|
|
869
|
+
` + this._dump(!1));
|
|
870
|
+
for (var h = 0; h < r.length; h++)
|
|
871
|
+
if (r[0].length != r[h].length)
|
|
872
|
+
throw new Error(`Diagram data is not rectangular:
|
|
873
|
+
` + this._dump(!1));
|
|
874
|
+
}
|
|
875
|
+
alter(t = null, e = null, r = null) {
|
|
876
|
+
var h = t || this.entry, i = e || this.exit, n = r || this.lines;
|
|
877
|
+
return new R(h, i, Array.from(n));
|
|
878
|
+
}
|
|
879
|
+
appendBelow(t, e, r = !1, h = !1) {
|
|
880
|
+
var i = Math.max(this.width, t.width), n = [], o = this.center(i, " ").lines;
|
|
881
|
+
for (const p of o)
|
|
882
|
+
n.push(p);
|
|
883
|
+
for (const p of e)
|
|
884
|
+
n.push(R._padR(p, i, " "));
|
|
885
|
+
o = t.center(i, " ").lines;
|
|
886
|
+
for (const p of o)
|
|
887
|
+
n.push(p);
|
|
888
|
+
var w = r ? this.height + e.length + t.entry : this.entry, d = h ? this.height + e.length + t.exit : this.exit;
|
|
889
|
+
return new R(w, d, n);
|
|
890
|
+
}
|
|
891
|
+
appendRight(t, e) {
|
|
892
|
+
for (var r = Math.max(this.exit, t.entry), h = Math.max(this.height - this.exit, t.height - t.entry) + r, i = r - this.exit, n = h - this.height - i, o = r - t.entry, w = h - t.height - o, d = this.expand(0, 0, i, n), p = t.expand(0, 0, o, w), u = [], a = 0; a < h; a++) {
|
|
893
|
+
var l = a != r ? " ".repeat(e.length) : e;
|
|
894
|
+
u.push(d.lines[a] + l + p.lines[a]);
|
|
895
|
+
}
|
|
896
|
+
var g = this.entry + i, v = t.exit + o;
|
|
897
|
+
return new R(g, v, u);
|
|
898
|
+
}
|
|
899
|
+
center(t, e) {
|
|
900
|
+
if (t < this.width)
|
|
901
|
+
throw new Error("Cannot center into smaller width");
|
|
902
|
+
if (t === this.width)
|
|
903
|
+
return this.copy();
|
|
904
|
+
for (var r = t - this.width, h = Math.trunc(r / 2), i = [], n = 0; n < this.height; n++)
|
|
905
|
+
i.push(e.repeat(h));
|
|
906
|
+
var o = [];
|
|
907
|
+
for (n = 0; n < this.height; n++)
|
|
908
|
+
o.push(e.repeat(r - h));
|
|
909
|
+
return new R(this.entry, this.exit, R._encloseLines(this.lines, i, o));
|
|
910
|
+
}
|
|
911
|
+
copy() {
|
|
912
|
+
return new R(this.entry, this.exit, Array.from(this.lines));
|
|
913
|
+
}
|
|
914
|
+
expand(t, e, r, h) {
|
|
915
|
+
if (t < 0 || e < 0 || r < 0 || h < 0)
|
|
916
|
+
throw new Error("Expansion values cannot be negative");
|
|
917
|
+
if (t + e + r + h === 0)
|
|
918
|
+
return this.copy();
|
|
919
|
+
for (var i = R.parts.line, n = [], o = 0; o < r; o++)
|
|
920
|
+
n.push(" ".repeat(this.width + t + e));
|
|
921
|
+
for (o = 0; o < this.height; o++) {
|
|
922
|
+
var w = o === this.entry ? i : " ", d = o === this.exit ? i : " ";
|
|
923
|
+
n.push(w.repeat(t) + this.lines[o] + d.repeat(e));
|
|
924
|
+
}
|
|
925
|
+
for (o = 0; o < h; o++)
|
|
926
|
+
n.push(" ".repeat(this.width + t + e));
|
|
927
|
+
return new R(this.entry + r, this.exit + r, n);
|
|
928
|
+
}
|
|
929
|
+
static rect(t, e = !1) {
|
|
930
|
+
return R._rectish("rect", t, e);
|
|
931
|
+
}
|
|
932
|
+
static roundrect(t, e = !1) {
|
|
933
|
+
return R._rectish("roundrect", t, e);
|
|
934
|
+
}
|
|
935
|
+
static setFormatting(t = null, e = null) {
|
|
936
|
+
t !== null && (R.parts = {}, e !== null && (R.parts = { ...R.parts, ...e }), R.parts = { ...R.parts, ...t });
|
|
937
|
+
for (const [r, h] of R.parts)
|
|
938
|
+
h.length != 1;
|
|
939
|
+
}
|
|
940
|
+
_dump(t = !0) {
|
|
941
|
+
var e = `
|
|
942
|
+
`, r = "height=" + this.height + " lines.length=" + this.lines.length;
|
|
943
|
+
this.entry > this.lines.length && (r += "; entry outside diagram: entry=" + this.entry), this.exit > this.lines.length && (r += "; exit outside diagram: exit=" + this.exit);
|
|
944
|
+
for (var h = 0; h < Math.max(this.lines.length, this.entry + 1, this.exit + 1); h++)
|
|
945
|
+
r = r + e + "[" + ("00" + h).slice(-3) + "]", h < this.lines.length && (r += " '" + this.lines[h] + "' len=" + this.lines[h].length), h === this.entry && h === this.exit ? r += " <- entry, exit" : h === this.entry ? r += " <- entry" : h === this.exit && (r += " <- exit");
|
|
946
|
+
return t && console.log(r), r;
|
|
947
|
+
}
|
|
948
|
+
static _encloseLines(t, e, r) {
|
|
949
|
+
if (t.length != e.length)
|
|
950
|
+
throw new Error("All arguments must be the same length");
|
|
951
|
+
if (t.length != r.length)
|
|
952
|
+
throw new Error("All arguments must be the same length");
|
|
953
|
+
for (var h = [], i = 0; i < t.length; i++)
|
|
954
|
+
h.push(e[i] + t[i] + r[i]);
|
|
955
|
+
return h;
|
|
956
|
+
}
|
|
957
|
+
static _gaps(t, e) {
|
|
958
|
+
var r = t - e;
|
|
959
|
+
if (s.INTERNAL_ALIGNMENT === "left")
|
|
960
|
+
return [0, r];
|
|
961
|
+
if (s.INTERNAL_ALIGNMENT === "right")
|
|
962
|
+
return [r, 0];
|
|
963
|
+
var h = Math.trunc(r / 2), i = r - h;
|
|
964
|
+
return [h, i];
|
|
965
|
+
}
|
|
966
|
+
static _getParts(t) {
|
|
967
|
+
var e = [];
|
|
968
|
+
for (const r of t) {
|
|
969
|
+
if (R.parts[r] == null)
|
|
970
|
+
throw new Error("Text diagram part " + r + "not found.");
|
|
971
|
+
e.push(R.parts[r]);
|
|
972
|
+
}
|
|
973
|
+
return e;
|
|
974
|
+
}
|
|
975
|
+
static _maxWidth(...t) {
|
|
976
|
+
var e = 0;
|
|
977
|
+
for (const h of t) {
|
|
978
|
+
if (h instanceof R)
|
|
979
|
+
var r = h.width;
|
|
980
|
+
else
|
|
981
|
+
h instanceof Array ? r = Math.max(h.map(function(i) {
|
|
982
|
+
return i.length;
|
|
983
|
+
})) : Number.isInteger(h) ? r = Number.toString(h).length : r = h.length;
|
|
984
|
+
e = r > e ? r : e;
|
|
985
|
+
}
|
|
986
|
+
return e;
|
|
987
|
+
}
|
|
988
|
+
static _padL(t, e, r) {
|
|
989
|
+
if ((e - t.length) % r.length != 0)
|
|
990
|
+
throw new Error("Gap " + (e - t.length) + " must be a multiple of pad string '" + r + "'");
|
|
991
|
+
return r.repeat(Math.trunc(e - t.length / r.length)) + t;
|
|
992
|
+
}
|
|
993
|
+
static _padR(t, e, r) {
|
|
994
|
+
if ((e - t.length) % r.length != 0)
|
|
995
|
+
throw new Error("Gap " + (e - t.length) + " must be a multiple of pad string '" + r + "'");
|
|
996
|
+
return t + r.repeat(Math.trunc(e - t.length / r.length));
|
|
997
|
+
}
|
|
998
|
+
static _rectish(t, e, r = !1) {
|
|
999
|
+
var h = r ? "_dashed" : "", [i, n, o, w, d, p, u, a, l, g] = R._getParts([t + "_top_left", t + "_left" + h, t + "_bot_left", t + "_top_right", t + "_right" + h, t + "_bot_right", t + "_top" + h, t + "_bot" + h, "line", "cross"]), v = e instanceof R;
|
|
1000
|
+
if (v)
|
|
1001
|
+
var T = e;
|
|
1002
|
+
else
|
|
1003
|
+
T = new R(0, 0, [e]);
|
|
1004
|
+
var m = [];
|
|
1005
|
+
if (m.push(u.repeat(T.width + 2)), v)
|
|
1006
|
+
m += T.expand(1, 1, 0, 0).lines;
|
|
1007
|
+
else
|
|
1008
|
+
for (var x = 0; x < T.lines.length; x++)
|
|
1009
|
+
m.push(" " + T.lines[x] + " ");
|
|
1010
|
+
m.push(a.repeat(T.width + 2));
|
|
1011
|
+
var I = T.entry + 1, S = T.exit + 1, E = R._maxWidth(i, n, o), M = [];
|
|
1012
|
+
for (M.push(R._padR(i, E, u)), x = 1; x < m.length - 1; x++)
|
|
1013
|
+
M.push(R._padR(n, E, " "));
|
|
1014
|
+
M.push(R._padR(o, E, a)), v && (M[I] = g);
|
|
1015
|
+
var V = R._maxWidth(w, d, p), b = [];
|
|
1016
|
+
for (b.push(R._padL(w, V, u)), x = 1; x < m.length - 1; x++)
|
|
1017
|
+
b.push(R._padL(d, V, " "));
|
|
1018
|
+
for (b.push(R._padL(p, V, a)), v && (b[S] = g), m = R._encloseLines(m, M, b), M = [], x = 0; x < m.length; x++)
|
|
1019
|
+
M.push(" ");
|
|
1020
|
+
for (M[I] = l, b = [], x = 0; x < m.length; x++)
|
|
1021
|
+
b.push(" ");
|
|
1022
|
+
return b[S] = l, m = R._encloseLines(m, M, b), new R(I, S, m);
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
// Note: All the drawing sequences below MUST be single characters. setFormatting() checks this.
|
|
1026
|
+
// Unicode 25xx box drawing characters, plus a few others.
|
|
1027
|
+
N(R, "PARTS_UNICODE", {
|
|
1028
|
+
cross_diag: "╳",
|
|
1029
|
+
corner_bot_left: "└",
|
|
1030
|
+
corner_bot_right: "┘",
|
|
1031
|
+
corner_top_left: "┌",
|
|
1032
|
+
corner_top_right: "┐",
|
|
1033
|
+
cross: "┼",
|
|
1034
|
+
left: "│",
|
|
1035
|
+
line: "─",
|
|
1036
|
+
line_vertical: "│",
|
|
1037
|
+
multi_repeat: "↺",
|
|
1038
|
+
rect_bot: "─",
|
|
1039
|
+
rect_bot_dashed: "┄",
|
|
1040
|
+
rect_bot_left: "└",
|
|
1041
|
+
rect_bot_right: "┘",
|
|
1042
|
+
rect_left: "│",
|
|
1043
|
+
rect_left_dashed: "┆",
|
|
1044
|
+
rect_right: "│",
|
|
1045
|
+
rect_right_dashed: "┆",
|
|
1046
|
+
rect_top: "─",
|
|
1047
|
+
rect_top_dashed: "┄",
|
|
1048
|
+
rect_top_left: "┌",
|
|
1049
|
+
rect_top_right: "┐",
|
|
1050
|
+
repeat_bot_left: "╰",
|
|
1051
|
+
repeat_bot_right: "╯",
|
|
1052
|
+
repeat_left: "│",
|
|
1053
|
+
repeat_right: "│",
|
|
1054
|
+
repeat_top_left: "╭",
|
|
1055
|
+
repeat_top_right: "╮",
|
|
1056
|
+
right: "│",
|
|
1057
|
+
roundcorner_bot_left: "╰",
|
|
1058
|
+
roundcorner_bot_right: "╯",
|
|
1059
|
+
roundcorner_top_left: "╭",
|
|
1060
|
+
roundcorner_top_right: "╮",
|
|
1061
|
+
roundrect_bot: "─",
|
|
1062
|
+
roundrect_bot_dashed: "┄",
|
|
1063
|
+
roundrect_bot_left: "╰",
|
|
1064
|
+
roundrect_bot_right: "╯",
|
|
1065
|
+
roundrect_left: "│",
|
|
1066
|
+
roundrect_left_dashed: "┆",
|
|
1067
|
+
roundrect_right: "│",
|
|
1068
|
+
roundrect_right_dashed: "┆",
|
|
1069
|
+
roundrect_top: "─",
|
|
1070
|
+
roundrect_top_dashed: "┄",
|
|
1071
|
+
roundrect_top_left: "╭",
|
|
1072
|
+
roundrect_top_right: "╮",
|
|
1073
|
+
separator: "─",
|
|
1074
|
+
tee_left: "┤",
|
|
1075
|
+
tee_right: "├"
|
|
1076
|
+
}), // Plain old ASCII characters.
|
|
1077
|
+
N(R, "PARTS_ASCII", {
|
|
1078
|
+
cross_diag: "X",
|
|
1079
|
+
corner_bot_left: "\\",
|
|
1080
|
+
corner_bot_right: "/",
|
|
1081
|
+
corner_top_left: "/",
|
|
1082
|
+
corner_top_right: "\\",
|
|
1083
|
+
cross: "+",
|
|
1084
|
+
left: "|",
|
|
1085
|
+
line: "-",
|
|
1086
|
+
line_vertical: "|",
|
|
1087
|
+
multi_repeat: "&",
|
|
1088
|
+
rect_bot: "-",
|
|
1089
|
+
rect_bot_dashed: "-",
|
|
1090
|
+
rect_bot_left: "+",
|
|
1091
|
+
rect_bot_right: "+",
|
|
1092
|
+
rect_left: "|",
|
|
1093
|
+
rect_left_dashed: "|",
|
|
1094
|
+
rect_right: "|",
|
|
1095
|
+
rect_right_dashed: "|",
|
|
1096
|
+
rect_top_dashed: "-",
|
|
1097
|
+
rect_top: "-",
|
|
1098
|
+
rect_top_left: "+",
|
|
1099
|
+
rect_top_right: "+",
|
|
1100
|
+
repeat_bot_left: "\\",
|
|
1101
|
+
repeat_bot_right: "/",
|
|
1102
|
+
repeat_left: "|",
|
|
1103
|
+
repeat_right: "|",
|
|
1104
|
+
repeat_top_left: "/",
|
|
1105
|
+
repeat_top_right: "\\",
|
|
1106
|
+
right: "|",
|
|
1107
|
+
roundcorner_bot_left: "\\",
|
|
1108
|
+
roundcorner_bot_right: "/",
|
|
1109
|
+
roundcorner_top_left: "/",
|
|
1110
|
+
roundcorner_top_right: "\\",
|
|
1111
|
+
roundrect_bot: "-",
|
|
1112
|
+
roundrect_bot_dashed: "-",
|
|
1113
|
+
roundrect_bot_left: "\\",
|
|
1114
|
+
roundrect_bot_right: "/",
|
|
1115
|
+
roundrect_left: "|",
|
|
1116
|
+
roundrect_left_dashed: "|",
|
|
1117
|
+
roundrect_right: "|",
|
|
1118
|
+
roundrect_right_dashed: "|",
|
|
1119
|
+
roundrect_top: "-",
|
|
1120
|
+
roundrect_top_dashed: "-",
|
|
1121
|
+
roundrect_top_left: "/",
|
|
1122
|
+
roundrect_top_right: "\\",
|
|
1123
|
+
separator: "-",
|
|
1124
|
+
tee_left: "|",
|
|
1125
|
+
tee_right: "|"
|
|
1126
|
+
}), // Characters to use in drawing diagrams. See setFormatting(), PARTS_ASCII, and PARTS_UNICODE.
|
|
1127
|
+
N(R, "parts", R.PARTS_UNICODE);
|
|
1128
|
+
let _ = R;
|
|
1129
|
+
function D(...c) {
|
|
1130
|
+
return c.reduce(function(t, e) {
|
|
1131
|
+
return t !== void 0 ? t : e;
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
function B(c, t) {
|
|
1135
|
+
var e = c - t;
|
|
1136
|
+
switch (s.INTERNAL_ALIGNMENT) {
|
|
1137
|
+
case "left":
|
|
1138
|
+
return [0, e];
|
|
1139
|
+
case "right":
|
|
1140
|
+
return [e, 0];
|
|
1141
|
+
default:
|
|
1142
|
+
return [e / 2, e / 2];
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
function P(c) {
|
|
1146
|
+
return c instanceof A ? c : new j("" + c);
|
|
1147
|
+
}
|
|
1148
|
+
function y(c, t) {
|
|
1149
|
+
return t || (t = function(e) {
|
|
1150
|
+
return e;
|
|
1151
|
+
}), c.map(t).reduce(function(e, r) {
|
|
1152
|
+
return e + r;
|
|
1153
|
+
}, 0);
|
|
1154
|
+
}
|
|
1155
|
+
function q(c, t = (e) => e) {
|
|
1156
|
+
return Math.max.apply(null, c.map(t));
|
|
1157
|
+
}
|
|
1158
|
+
function dt(c, t, e) {
|
|
1159
|
+
t = t || {}, e = e || "";
|
|
1160
|
+
var r = document.createElementNS("http://www.w3.org/2000/svg", c);
|
|
1161
|
+
for (var h in t)
|
|
1162
|
+
h === "xlink:href" ? r.setAttributeNS("http://www.w3.org/1999/xlink", "href", t[h]) : r.setAttribute(h, t[h]);
|
|
1163
|
+
return r.textContent = e, r;
|
|
1164
|
+
}
|
|
1165
|
+
function lt(c) {
|
|
1166
|
+
return c.replace(/[*_\`\[\]<&]/g, function(t) {
|
|
1167
|
+
return "&#" + t.charCodeAt(0) + ";";
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
function* O(c) {
|
|
1171
|
+
var t = 0;
|
|
1172
|
+
for (const e of c)
|
|
1173
|
+
yield [t, e], t++;
|
|
1174
|
+
}
|
|
1175
|
+
export {
|
|
1176
|
+
ht as AlternatingSequence,
|
|
1177
|
+
ot as Block,
|
|
1178
|
+
L as Choice,
|
|
1179
|
+
K as Comment,
|
|
1180
|
+
$ as ComplexDiagram,
|
|
1181
|
+
Y as Diagram,
|
|
1182
|
+
G as DiagramMultiContainer,
|
|
1183
|
+
H as End,
|
|
1184
|
+
A as FakeSVG,
|
|
1185
|
+
at as Group,
|
|
1186
|
+
rt as HorizontalChoice,
|
|
1187
|
+
st as MultipleChoice,
|
|
1188
|
+
nt as NonTerminal,
|
|
1189
|
+
X as OneOrMore,
|
|
1190
|
+
F as Optional,
|
|
1191
|
+
et as OptionalSequence,
|
|
1192
|
+
s as Options,
|
|
1193
|
+
f as Path,
|
|
1194
|
+
z as Sequence,
|
|
1195
|
+
W as Skip,
|
|
1196
|
+
tt as Stack,
|
|
1197
|
+
U as Start,
|
|
1198
|
+
j as Terminal,
|
|
1199
|
+
_ as TextDiagram,
|
|
1200
|
+
it as ZeroOrMore,
|
|
1201
|
+
k as default,
|
|
1202
|
+
Q as defaultCSS
|
|
1203
|
+
};
|