@cardenelabs/dragon 0.33.0 → 0.35.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/README.md +39 -720
- package/dist/cli.cjs +4529 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +4523 -0
- package/dist/cli.js.map +1 -0
- package/dist/export.cjs +3912 -0
- package/dist/export.cjs.map +1 -0
- package/dist/export.d.cts +36 -0
- package/dist/export.d.ts +36 -0
- package/dist/export.js +3907 -0
- package/dist/export.js.map +1 -0
- package/dist/fonts.cjs +7 -0
- package/dist/fonts.cjs.map +1 -0
- package/dist/fonts.js +4 -0
- package/dist/fonts.js.map +1 -0
- package/dist/index.cjs +4105 -20299
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +227 -5524
- package/dist/index.d.ts +227 -5524
- package/dist/index.js +4091 -20226
- package/dist/index.js.map +1 -1
- package/dist/player.global.js +2 -0
- package/dist/schema-BBWfniwH.d.cts +112 -0
- package/dist/schema-BBWfniwH.d.ts +112 -0
- package/package.json +39 -24
- package/src/cli.ts +237 -0
- package/src/export/capture.ts +277 -0
- package/src/export/fonts.ts +68 -0
- package/src/export/html.ts +32 -0
- package/src/export/index.ts +146 -0
- package/src/field-messages.ts +104 -0
- package/src/figure-text.ts +42 -0
- package/src/index.ts +30 -283
- package/src/layout/architecture.ts +381 -0
- package/src/layout/measure.ts +21 -0
- package/src/layout/scene.ts +353 -0
- package/src/layout/sequence.ts +189 -0
- package/src/load-fonts.ts +8 -0
- package/src/look/fonts.ts +33 -0
- package/src/look/palettes.json +209 -0
- package/src/look/values.ts +155 -0
- package/src/markdown.ts +35 -0
- package/src/messages.ts +122 -0
- package/src/parser.ts +342 -310
- package/src/player-global.ts +4 -0
- package/src/player.ts +271 -0
- package/src/printer.ts +76 -0
- package/src/render/icons.ts +41 -0
- package/src/render/motion.ts +106 -0
- package/src/render/parts.ts +279 -0
- package/src/render/svg.ts +341 -0
- package/src/schema.ts +161 -16
- package/src/schemas/diagram.schema.json +150 -0
- package/src/schemas/validate-diagram.d.ts +12 -0
- package/src/schemas/validate-diagram.js +8 -0
- package/src/timeline.ts +166 -0
- package/src/tokenize.ts +20 -281
- package/src/version.ts +55 -0
- package/src/view.ts +16 -0
- package/src/words.ts +79 -0
- package/examples/quick-start.md +0 -142
- package/src/canvas-bounds.ts +0 -52
- package/src/color.ts +0 -197
- package/src/compile/actor-ids.ts +0 -297
- package/src/compile/actor-option-notice.ts +0 -379
- package/src/compile/actors.ts +0 -103
- package/src/compile/c4.ts +0 -74
- package/src/compile/chain.ts +0 -93
- package/src/compile/chart-fields.ts +0 -193
- package/src/compile/deep-rewrite.ts +0 -30
- package/src/compile/derived-source.ts +0 -18
- package/src/compile/direction.ts +0 -102
- package/src/compile/edge-option-notice.ts +0 -112
- package/src/compile/er-relation.ts +0 -200
- package/src/compile/flow.ts +0 -54
- package/src/compile/flowchart.ts +0 -344
- package/src/compile/funnel.ts +0 -87
- package/src/compile/gantt.ts +0 -337
- package/src/compile/generic.ts +0 -696
- package/src/compile/hierarchy.ts +0 -92
- package/src/compile/journey.ts +0 -93
- package/src/compile/kinds.ts +0 -148
- package/src/compile/lanes.ts +0 -138
- package/src/compile/metro.ts +0 -271
- package/src/compile/mind.ts +0 -393
- package/src/compile/node-title.ts +0 -24
- package/src/compile/notice.ts +0 -141
- package/src/compile/order.ts +0 -62
- package/src/compile/parts-lookup.ts +0 -17
- package/src/compile/parts.ts +0 -2709
- package/src/compile/placement-apply.ts +0 -689
- package/src/compile/placement.ts +0 -15
- package/src/compile/quadrant.ts +0 -265
- package/src/compile/record.ts +0 -75
- package/src/compile/row-marks.ts +0 -128
- package/src/compile/rows.ts +0 -40
- package/src/compile/sequence.ts +0 -305
- package/src/compile/slug.ts +0 -37
- package/src/compile/stages.ts +0 -247
- package/src/compile/subtitle.ts +0 -35
- package/src/compile/swimlane-marks.ts +0 -87
- package/src/compile/swimlane.ts +0 -82
- package/src/compile/timeline.ts +0 -213
- package/src/compile/topology.ts +0 -44
- package/src/compile/tree.ts +0 -69
- package/src/compile/value-chart.ts +0 -337
- package/src/compile/values.ts +0 -432
- package/src/compile/word-state.ts +0 -82
- package/src/compile.ts +0 -3169
- package/src/focus.ts +0 -46
- package/src/input-size.ts +0 -181
- package/src/json-line-map.ts +0 -30
- package/src/json-parser.ts +0 -4289
- package/src/keywords.ts +0 -418
- package/src/near-name.ts +0 -42
- package/src/notation-lint.ts +0 -342
- package/src/relative-pos.ts +0 -251
- package/src/schemas/diagram.json +0 -3089
- package/src/types.ts +0 -1009
- package/src/v05/index.ts +0 -9
- package/src/v05/input-table.generated.ts +0 -138
- package/src/v05/parser-types.ts +0 -32
- package/src/v05/parser.ts +0 -6664
- package/src/v05/readout-table.generated.ts +0 -1088
- package/src/value-syntax.ts +0 -313
- package/src/write-position.ts +0 -270
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,4529 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var util = require('util');
|
|
7
|
+
var module$1 = require('module');
|
|
8
|
+
var promises = require('fs/promises');
|
|
9
|
+
|
|
10
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.23_tsx@4.22.4_typescript@5.9.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
|
|
11
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
12
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
13
|
+
|
|
14
|
+
// src/look/palettes.json
|
|
15
|
+
var palettes_default = {
|
|
16
|
+
clear: {
|
|
17
|
+
name: "\u6F84\u3093\u3060\u8272",
|
|
18
|
+
note: "\u767D\u3044\u5730\u306B\u3001\u4E2D\u304F\u3089\u3044\u306E\u660E\u308B\u3055\u306E\u9BAE\u3084\u304B\u306A 6 \u8272\u3002\u4ECA\u306E\u898B\u672C\u5E33\u306E\u8272",
|
|
19
|
+
light: {
|
|
20
|
+
page: "#f3f4f7",
|
|
21
|
+
bg: "#ffffff",
|
|
22
|
+
surf: "#ffffff",
|
|
23
|
+
sunk: "#f5f6f8",
|
|
24
|
+
ink: "#12141a",
|
|
25
|
+
ink2: "#3f4451",
|
|
26
|
+
mute: "#6b7180",
|
|
27
|
+
hair: "#12141a1c",
|
|
28
|
+
line: "#12141a40",
|
|
29
|
+
sh: "#101828",
|
|
30
|
+
"on-c": "#ffffff",
|
|
31
|
+
"c-blue": "#467deb",
|
|
32
|
+
"t-blue": "#2e62ce",
|
|
33
|
+
"c-amber": "#d28008",
|
|
34
|
+
"t-amber": "#975b04",
|
|
35
|
+
"c-green": "#0ea886",
|
|
36
|
+
"t-green": "#07775e",
|
|
37
|
+
"c-violet": "#6c3bb2",
|
|
38
|
+
"t-violet": "#6c3bb2",
|
|
39
|
+
"c-rose": "#ba3e40",
|
|
40
|
+
"t-rose": "#b83c3f",
|
|
41
|
+
"c-slate": "#5d6677",
|
|
42
|
+
"t-slate": "#5d6677",
|
|
43
|
+
coin: "#e9b114",
|
|
44
|
+
coint: "#856300",
|
|
45
|
+
coinin: "#a8740c",
|
|
46
|
+
tint: "5%",
|
|
47
|
+
edge: "20%",
|
|
48
|
+
shA: ".05",
|
|
49
|
+
shB: ".08",
|
|
50
|
+
carry: "#65686f"
|
|
51
|
+
},
|
|
52
|
+
dark: {
|
|
53
|
+
page: "#08090c",
|
|
54
|
+
bg: "#0d0e12",
|
|
55
|
+
surf: "#17191f",
|
|
56
|
+
sunk: "#121419",
|
|
57
|
+
ink: "#eceef3",
|
|
58
|
+
ink2: "#c4c8d2",
|
|
59
|
+
mute: "#9198a6",
|
|
60
|
+
hair: "#eceef31f",
|
|
61
|
+
line: "#eceef340",
|
|
62
|
+
sh: "#000000",
|
|
63
|
+
"on-c": "#0d0e12",
|
|
64
|
+
"c-blue": "#7e7ef6",
|
|
65
|
+
"t-blue": "#989cfd",
|
|
66
|
+
"c-amber": "#c78135",
|
|
67
|
+
"t-amber": "#dd954b",
|
|
68
|
+
"c-green": "#20ac7a",
|
|
69
|
+
"t-green": "#35b986",
|
|
70
|
+
"c-violet": "#695b9f",
|
|
71
|
+
"t-violet": "#a79ae3",
|
|
72
|
+
"c-rose": "#bc434b",
|
|
73
|
+
"t-rose": "#fd7d81",
|
|
74
|
+
"c-slate": "#9ba3b2",
|
|
75
|
+
"t-slate": "#9da5b4",
|
|
76
|
+
coin: "#f0c040",
|
|
77
|
+
coint: "#f0c040",
|
|
78
|
+
coinin: "#9a6a0c",
|
|
79
|
+
tint: "6%",
|
|
80
|
+
edge: "19%",
|
|
81
|
+
shA: ".45",
|
|
82
|
+
shB: ".35"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
paper: {
|
|
86
|
+
name: "\u7D19\u3068\u58A8",
|
|
87
|
+
note: "\u751F\u6210\u308A\u306E\u7D19\u306E\u5730\u306B\u3001\u85CD / \u9EC4\u571F / \u82D4 / \u8461\u8404 / \u6731 / \u920D\u306E\u304F\u3059\u3093\u3060 6 \u8272",
|
|
88
|
+
light: {
|
|
89
|
+
page: "#ece7dd",
|
|
90
|
+
bg: "#f9f6f0",
|
|
91
|
+
surf: "#fffcf6",
|
|
92
|
+
sunk: "#f2ede4",
|
|
93
|
+
ink: "#221e18",
|
|
94
|
+
ink2: "#4b453b",
|
|
95
|
+
mute: "#7b7366",
|
|
96
|
+
hair: "#221e181f",
|
|
97
|
+
line: "#221e1847",
|
|
98
|
+
sh: "#3a2a10",
|
|
99
|
+
"on-c": "#fffcf6",
|
|
100
|
+
"c-blue": "#487dd5",
|
|
101
|
+
"t-blue": "#2d60b5",
|
|
102
|
+
"c-amber": "#c38405",
|
|
103
|
+
"t-amber": "#885a01",
|
|
104
|
+
"c-green": "#57a271",
|
|
105
|
+
"t-green": "#237143",
|
|
106
|
+
"c-violet": "#904698",
|
|
107
|
+
"t-violet": "#904698",
|
|
108
|
+
"c-rose": "#a9513e",
|
|
109
|
+
"t-rose": "#9f4836",
|
|
110
|
+
"c-slate": "#6a645a",
|
|
111
|
+
"t-slate": "#696359",
|
|
112
|
+
coin: "#d4a52a",
|
|
113
|
+
coint: "#7d5e05",
|
|
114
|
+
coinin: "#9a7016",
|
|
115
|
+
tint: "6%",
|
|
116
|
+
edge: "22%",
|
|
117
|
+
shA: ".06",
|
|
118
|
+
shB: ".07",
|
|
119
|
+
carry: "#68635c"
|
|
120
|
+
},
|
|
121
|
+
dark: {
|
|
122
|
+
page: "#0e0d0b",
|
|
123
|
+
bg: "#15130f",
|
|
124
|
+
surf: "#1e1b17",
|
|
125
|
+
sunk: "#191612",
|
|
126
|
+
ink: "#ede6d8",
|
|
127
|
+
ink2: "#cbc2b1",
|
|
128
|
+
mute: "#9c9283",
|
|
129
|
+
hair: "#ede6d81f",
|
|
130
|
+
line: "#ede6d842",
|
|
131
|
+
sh: "#000000",
|
|
132
|
+
"on-c": "#15130f",
|
|
133
|
+
"c-blue": "#5785d5",
|
|
134
|
+
"t-blue": "#76a6f9",
|
|
135
|
+
"c-amber": "#be8802",
|
|
136
|
+
"t-amber": "#d59e2f",
|
|
137
|
+
"c-green": "#52aa71",
|
|
138
|
+
"t-green": "#61b87e",
|
|
139
|
+
"c-violet": "#90529b",
|
|
140
|
+
"t-violet": "#d08edb",
|
|
141
|
+
"c-rose": "#bb4e3d",
|
|
142
|
+
"t-rose": "#f98672",
|
|
143
|
+
"c-slate": "#a9a295",
|
|
144
|
+
"t-slate": "#aca598",
|
|
145
|
+
coin: "#dcb24e",
|
|
146
|
+
coint: "#dcb24e",
|
|
147
|
+
coinin: "#8a6a14",
|
|
148
|
+
tint: "6%",
|
|
149
|
+
edge: "19%",
|
|
150
|
+
shA: ".45",
|
|
151
|
+
shB: ".35"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
night: {
|
|
155
|
+
name: "\u591C\u306E\u8A08\u5668",
|
|
156
|
+
note: "\u9752\u307F\u306E\u9ED2\u306E\u5730\u306B\u3001\u5149\u308B\u6C34\u8272 / \u7425\u73C0 / \u82E5\u7DD1 / \u83EB / \u6843 \u306E 6 \u8272\u3002\u660E\u308B\u3044\u5074\u306F\u9752\u7070\u306E\u5730",
|
|
157
|
+
light: {
|
|
158
|
+
page: "#e9eef5",
|
|
159
|
+
bg: "#f6f9fc",
|
|
160
|
+
surf: "#ffffff",
|
|
161
|
+
sunk: "#eef3f8",
|
|
162
|
+
ink: "#0b1424",
|
|
163
|
+
ink2: "#34425a",
|
|
164
|
+
mute: "#64748b",
|
|
165
|
+
hair: "#0b14241c",
|
|
166
|
+
line: "#0b142440",
|
|
167
|
+
sh: "#0b1424",
|
|
168
|
+
"on-c": "#ffffff",
|
|
169
|
+
"c-blue": "#0385cd",
|
|
170
|
+
"t-blue": "#086aa3",
|
|
171
|
+
"c-amber": "#ba8e0f",
|
|
172
|
+
"t-amber": "#7f5f04",
|
|
173
|
+
"c-green": "#0a8857",
|
|
174
|
+
"t-green": "#027449",
|
|
175
|
+
"c-violet": "#5839ba",
|
|
176
|
+
"t-violet": "#5839ba",
|
|
177
|
+
"c-rose": "#dd4a94",
|
|
178
|
+
"t-rose": "#b82375",
|
|
179
|
+
"c-slate": "#64748b",
|
|
180
|
+
"t-slate": "#56667c",
|
|
181
|
+
coin: "#eab308",
|
|
182
|
+
coint: "#7e6005",
|
|
183
|
+
coinin: "#a16207",
|
|
184
|
+
tint: "5%",
|
|
185
|
+
edge: "22%",
|
|
186
|
+
shA: ".06",
|
|
187
|
+
shB: ".09",
|
|
188
|
+
carry: "#596579"
|
|
189
|
+
},
|
|
190
|
+
dark: {
|
|
191
|
+
page: "#060a12",
|
|
192
|
+
bg: "#0a101c",
|
|
193
|
+
surf: "#111a2a",
|
|
194
|
+
sunk: "#0d1522",
|
|
195
|
+
ink: "#e6edf7",
|
|
196
|
+
ink2: "#b8c4d6",
|
|
197
|
+
mute: "#8090a8",
|
|
198
|
+
hair: "#e6edf71c",
|
|
199
|
+
line: "#9fb3d145",
|
|
200
|
+
sh: "#000000",
|
|
201
|
+
"on-c": "#0a101c",
|
|
202
|
+
"c-blue": "#3884b6",
|
|
203
|
+
"t-blue": "#62ace1",
|
|
204
|
+
"c-amber": "#be8533",
|
|
205
|
+
"t-amber": "#d59b4b",
|
|
206
|
+
"c-green": "#3ba774",
|
|
207
|
+
"t-green": "#4fb884",
|
|
208
|
+
"c-violet": "#7d4ecd",
|
|
209
|
+
"t-violet": "#b494fd",
|
|
210
|
+
"c-rose": "#bc3a74",
|
|
211
|
+
"t-rose": "#ff77ad",
|
|
212
|
+
"c-slate": "#96a3b5",
|
|
213
|
+
"t-slate": "#99a6b8",
|
|
214
|
+
coin: "#facc15",
|
|
215
|
+
coint: "#facc15",
|
|
216
|
+
coinin: "#a16207",
|
|
217
|
+
tint: "6%",
|
|
218
|
+
edge: "19%",
|
|
219
|
+
shA: ".5",
|
|
220
|
+
shB: ".4"
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// src/look/fonts.ts
|
|
226
|
+
var FONTS = { sans: "Noto Sans JP Variable", mono: "JetBrains Mono Variable" };
|
|
227
|
+
var SANS_ADVANCE = { "0": 590, "1": 590, "2": 590, "3": 590, "4": 590, "5": 590, "6": 590, "7": 590, "8": 590, "9": 590, " ": 228, "!": 371, '"': 575, "#": 590, "$": 590, "%": 963, "&": 740, "'": 325, "(": 378, ")": 378, "*": 507, "+": 590, ",": 325, "-": 371, ".": 325, "/": 390, ":": 325, ";": 325, "<": 590, "=": 590, ">": 590, "?": 514, "@": 1007, "A": 642, "B": 682, "C": 657, "D": 715, "E": 616, "F": 586, "G": 718, "H": 758, "I": 330, "J": 568, "K": 686, "L": 579, "M": 854, "N": 750, "O": 771, "P": 668, "Q": 771, "R": 682, "S": 624, "T": 626, "U": 748, "V": 619, "W": 915, "X": 627, "Y": 581, "Z": 614, "[": 378, "\\": 390, "]": 378, "^": 590, "_": 568, "`": 626, "a": 591, "b": 644, "c": 528, "d": 645, "e": 581, "f": 372, "g": 598, "h": 640, "i": 305, "j": 306, "k": 605, "l": 315, "m": 964, "n": 641, "o": 626, "p": 645, "q": 645, "r": 437, "s": 495, "t": 421, "u": 638, "v": 576, "w": 863, "x": 562, "y": 575, "z": 512, "{": 378, "|": 297, "}": 378, "~": 590, "\u2026": 1e3, "\u2212": 590, "\xD7": 1e3, "\u2192": 1e3, "\u2190": 1e3, "\u2191": 1e3, "\u2193": 1e3, "\u2013": 545, "\u2014": 908, "\u2018": 325, "\u2019": 325, "\u201C": 575, "\u201D": 575, "\xB0": 404, "\xB1": 1e3, "\xB7": 593, "\u2022": 379 };
|
|
228
|
+
var MONO_ADVANCE = 600;
|
|
229
|
+
var WIDE_FROM = 11904;
|
|
230
|
+
var EM = 1e3;
|
|
231
|
+
function advance(ch, family) {
|
|
232
|
+
if ((ch.codePointAt(0) ?? 0) >= WIDE_FROM) return EM;
|
|
233
|
+
if (family === "mono") return MONO_ADVANCE;
|
|
234
|
+
return SANS_ADVANCE[ch] ?? EM;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/look/values.ts
|
|
238
|
+
var DEFAULT_PALETTE = "paper";
|
|
239
|
+
var PALETTES = Object.fromEntries(
|
|
240
|
+
Object.entries(palettes_default).map(([id, p]) => [id, { id, ...p }])
|
|
241
|
+
);
|
|
242
|
+
function resolvePalette(id) {
|
|
243
|
+
const found = id !== void 0 && Object.hasOwn(PALETTES, id) ? PALETTES[id] : void 0;
|
|
244
|
+
return found ?? PALETTES[DEFAULT_PALETTE];
|
|
245
|
+
}
|
|
246
|
+
function paletteVars(palette, theme) {
|
|
247
|
+
return Object.entries(palette[theme]).map(([key, value]) => `--${key}:${value}`).join(";");
|
|
248
|
+
}
|
|
249
|
+
var FONT_VARS = `--sans:"${FONTS.sans}";--mono:"${FONTS.mono}"`;
|
|
250
|
+
var COLOR_ORDER = ["blue", "amber", "green", "violet", "rose"];
|
|
251
|
+
var text = (size, weight, family = "sans") => ({ size, weight, family });
|
|
252
|
+
var TYPE = {
|
|
253
|
+
boxName: text(13, 650),
|
|
254
|
+
boxSub: text(11, 500),
|
|
255
|
+
boxSubStrong: text(11, 700),
|
|
256
|
+
regionName: text(12.5, 700),
|
|
257
|
+
regionNote: text(11, 500),
|
|
258
|
+
label: text(11, 600, "mono"),
|
|
259
|
+
labelJa: text(11, 650),
|
|
260
|
+
action: text(11, 650),
|
|
261
|
+
badge: text(10.5, 700, "mono"),
|
|
262
|
+
carrier: text(10.5, 700, "mono"),
|
|
263
|
+
carrierJa: text(10.5, 700),
|
|
264
|
+
stripTitle: text(12.5, 700),
|
|
265
|
+
fieldName: text(10.5, 600),
|
|
266
|
+
fieldValue: text(12, 600, "mono"),
|
|
267
|
+
fieldValueJa: text(12, 600),
|
|
268
|
+
tag: text(10.5, 700),
|
|
269
|
+
miniTitle: text(10.5, 700),
|
|
270
|
+
stepTitle: text(15, 700),
|
|
271
|
+
stepBody: text(13.5, 500),
|
|
272
|
+
stepNo: text(13, 700, "mono"),
|
|
273
|
+
button: text(14, 700)
|
|
274
|
+
};
|
|
275
|
+
var LOOK = {
|
|
276
|
+
/** 部品どうしの最小の隙間 */
|
|
277
|
+
gap: 10,
|
|
278
|
+
/** 図の外周の余白 */
|
|
279
|
+
margin: 14,
|
|
280
|
+
box: { h: 72, minW: 92, padX: 12, radius: 12, icon: 24, iconRadius: 7, iconY: -16, iconScale: 0.74, nameY: 12, subY: 27 },
|
|
281
|
+
region: { pad: 18, gap: 10, radius: 14, inset: 14, icon: 24, iconRadius: 7, iconScale: 0.68, nameY: 58, line: 16, minH: 108 },
|
|
282
|
+
architecture: { columns: 4, columnGap: 56, maxColumnGap: 160, rowGap: 44, labelRoom: 16 },
|
|
283
|
+
sequence: { columnGap: 40, labelRoom: 16, firstRow: 22, rowGap: 14, stepGap: 8, minPitch: 40, tail: 18, selfW: 34, selfH: 18 },
|
|
284
|
+
edge: { inset: 3, arrow: 6, arrowHalf: 3.5, parallel: 5, ghostDash: 5, flowDash: 9 },
|
|
285
|
+
label: { h: 20, padX: 9, radius: 10, offset: 22, side: 14, search: 4, searchMax: 400, soft: 6 },
|
|
286
|
+
action: { h: 22, padX: 10, radius: 11 },
|
|
287
|
+
badge: { r: 9.5, ring: 9, inset: 4, along: 14, short: 44 },
|
|
288
|
+
carrier: { envW: 24, envH: 17, coinR: 6.5, coinIn: 3.8, tagH: 18, tagPadX: 8, samples: 16 },
|
|
289
|
+
strip: { h: 72, line: 44, pad: 12, icon: 24, titleX: 44, fieldGap: 22, sepInset: 14, tagGap: 6, tagH: 15, tagPadX: 7, nameY: 22, valueY: 43 },
|
|
290
|
+
stroke: { hair: 1, edge: 1.7, edgeOn: 2.25, arrow: 1.5, flow: 1.3, halo: 7, on: 1.75, glyph: 2, lifeline: 1.2, envelope: 1.5, badgeRing: 1.5 },
|
|
291
|
+
shadow: { near: 0.8, far: 4, nearY: 1, farY: 3 },
|
|
292
|
+
mini: { w: 168, pad: 8, title: 14, inset: 12, radius: 10 },
|
|
293
|
+
/** 寄って追う見せ方の窓の高さの、幅に対する割合と下限 */
|
|
294
|
+
follow: { aspect: 0.75, minH: 320, ease: 0.6 },
|
|
295
|
+
/** 色を混ぜる割合 (%) */
|
|
296
|
+
mix: { icon: 14, regionIcon: 16, regionIconEdge: 34, cap: 12, capEdge: 42, badgePast: 14, badgePastEdge: 70, mini: 62, miniBand: 16, miniBandEdge: 36, view: 6 },
|
|
297
|
+
/** 字の並びの基準線を、置きたい高さの真ん中からどれだけ下げるか */
|
|
298
|
+
baseline: { label: 3.8, badge: 3.5, carrier: 3.7, stripTitle: 4.5, tag: 3.6, action: 3.8 },
|
|
299
|
+
/** 浮いて出る物が下から上がる長さと、弾んで出る物の始まりの大きさ */
|
|
300
|
+
rise: 5,
|
|
301
|
+
popFrom: 0.4};
|
|
302
|
+
var MOTION = {
|
|
303
|
+
/** 最初の段の前に全体を見せる長さ */
|
|
304
|
+
intro: 1.4,
|
|
305
|
+
/** 最後の段の後に全体を見せる長さ */
|
|
306
|
+
outro: 4.6,
|
|
307
|
+
/** 繰り返す前に消えていく長さ */
|
|
308
|
+
tail: 0.6,
|
|
309
|
+
/** 段の長さ。本文の字数で伸ばし、段で起きることが全部見えてから dwell 秒は留める */
|
|
310
|
+
stepBase: 1.2,
|
|
311
|
+
perChar: 0.025,
|
|
312
|
+
stepMin: 2.2,
|
|
313
|
+
stepMax: 5,
|
|
314
|
+
dwell: 1.2,
|
|
315
|
+
/** 段の中で最初の線を引き始めるまでと、続く線を引き始める間 */
|
|
316
|
+
edgeAt: 0.1,
|
|
317
|
+
stagger: 0.5,
|
|
318
|
+
/** 線を引く長さ。運ぶ物を載せた線は運ぶ物が走るので長い */
|
|
319
|
+
draw: 0.55,
|
|
320
|
+
drawCarry: 0.9,
|
|
321
|
+
/** 処理を読む間 (次の線と書き換えはこれだけ待つ) と、書き換えが続く間 */
|
|
322
|
+
action: 0.9,
|
|
323
|
+
change: 0.12,
|
|
324
|
+
/** 箱の下の字が見えている短さの下限。これより早く次の字に替わる字は出さない */
|
|
325
|
+
minShow: 0.8,
|
|
326
|
+
/** 線の名前が線より遅れて出る長さと、出入りの長さ */
|
|
327
|
+
labelDelay: 0.15,
|
|
328
|
+
fade: 0.3,
|
|
329
|
+
popFade: 0.4,
|
|
330
|
+
untilFade: 0.2,
|
|
331
|
+
/** 段の止め絵を撮る時刻を、段の終わりからどれだけ前にするか */
|
|
332
|
+
still: 0.45
|
|
333
|
+
};
|
|
334
|
+
var READABLE_PX = 10.5;
|
|
335
|
+
var EASE = {
|
|
336
|
+
inOut: "cubic-bezier(.65,0,.35,1)",
|
|
337
|
+
out: "cubic-bezier(.22,1,.36,1)",
|
|
338
|
+
pop: "cubic-bezier(.34,1.56,.64,1)"
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// src/figure-text.ts
|
|
342
|
+
var FIGURE_TEXT = {
|
|
343
|
+
ja: {
|
|
344
|
+
cannotDraw: (detail2) => `\u56F3\u3092\u63CF\u3051\u306A\u3044: ${detail2}`,
|
|
345
|
+
overview: "\u5168\u4F53\u56F3",
|
|
346
|
+
prev: "\u524D\u306E\u6BB5",
|
|
347
|
+
pause: "\u6B62\u3081\u308B",
|
|
348
|
+
play: "\u52D5\u304B\u3059",
|
|
349
|
+
next: "\u6B21\u306E\u6BB5",
|
|
350
|
+
steps: (title) => `${title} \u306E\u6BB5`
|
|
351
|
+
},
|
|
352
|
+
en: {
|
|
353
|
+
cannotDraw: (detail2) => `Cannot draw the diagram: ${detail2}`,
|
|
354
|
+
overview: "Overview",
|
|
355
|
+
prev: "Previous step",
|
|
356
|
+
pause: "Pause",
|
|
357
|
+
play: "Play",
|
|
358
|
+
next: "Next step",
|
|
359
|
+
steps: (title) => `Steps of ${title}`
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// src/layout/measure.ts
|
|
364
|
+
var hasWide = (text2) => [...text2].some((ch) => (ch.codePointAt(0) ?? 0) >= 11904);
|
|
365
|
+
function familyFor(text2, preferred) {
|
|
366
|
+
return preferred === "mono" && hasWide(text2) ? "sans" : preferred;
|
|
367
|
+
}
|
|
368
|
+
function textWidth(text2, style) {
|
|
369
|
+
const family = familyFor(text2, style.family);
|
|
370
|
+
let sum = 0;
|
|
371
|
+
for (const ch of text2) sum += advance(ch, family);
|
|
372
|
+
return sum * style.size / EM;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/layout/scene.ts
|
|
376
|
+
function edgesOf(diagram) {
|
|
377
|
+
return diagram.steps.flatMap(
|
|
378
|
+
(step, s) => step.events.flatMap((event, e) => event.type === "edge" ? [{ step: s, event: e, edge: event }] : [])
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
function boxColors(diagram) {
|
|
382
|
+
const regions = regionColors(diagram);
|
|
383
|
+
const colors = /* @__PURE__ */ new Map();
|
|
384
|
+
diagram.boxes.forEach((box, i) => {
|
|
385
|
+
const fromRegion = box.region === void 0 ? void 0 : regions.get(box.region);
|
|
386
|
+
colors.set(box.id, box.color ?? fromRegion ?? COLOR_ORDER[i % COLOR_ORDER.length]);
|
|
387
|
+
});
|
|
388
|
+
return colors;
|
|
389
|
+
}
|
|
390
|
+
function regionColors(diagram) {
|
|
391
|
+
const colors = /* @__PURE__ */ new Map();
|
|
392
|
+
(diagram.regions ?? []).forEach((region, i) => colors.set(region.id, region.color ?? COLOR_ORDER[i % COLOR_ORDER.length]));
|
|
393
|
+
return colors;
|
|
394
|
+
}
|
|
395
|
+
var edgeColor = (edge2, colors) => edge2.carry.kind === "coin" ? "coin" : colors.get(edge2.from) ?? "slate";
|
|
396
|
+
function boxWidth(diagram, id, withActions) {
|
|
397
|
+
const box = diagram.boxes.find((b) => b.id === id);
|
|
398
|
+
if (!box) return LOOK.box.minW;
|
|
399
|
+
const lines = [textWidth(box.name, TYPE.boxName), textWidth(box.sub ?? "", TYPE.boxSub)];
|
|
400
|
+
for (const step of diagram.steps) {
|
|
401
|
+
for (const event of step.events) {
|
|
402
|
+
if (event.type === "swap" && event.box === id) lines.push(textWidth(event.text, TYPE.boxSubStrong));
|
|
403
|
+
if (withActions && event.type === "action" && event.box === id) lines.push(textWidth(event.label, TYPE.boxSubStrong));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return Math.max(LOOK.box.minW, Math.max(...lines) + LOOK.box.padX * 2);
|
|
407
|
+
}
|
|
408
|
+
function gapBetween(a, b) {
|
|
409
|
+
const dx = Math.max(b.x - (a.x + a.w), a.x - (b.x + b.w));
|
|
410
|
+
const dy = Math.max(b.y - (a.y + a.h), a.y - (b.y + b.h));
|
|
411
|
+
return Math.max(dx, dy);
|
|
412
|
+
}
|
|
413
|
+
function longest(points) {
|
|
414
|
+
let best = { a: points[0], b: points[1] ?? points[0], length: -1 };
|
|
415
|
+
for (let i = 1; i < points.length; i++) {
|
|
416
|
+
const a = points[i - 1];
|
|
417
|
+
const b = points[i];
|
|
418
|
+
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
419
|
+
if (length > best.length) best = { a, b, length };
|
|
420
|
+
}
|
|
421
|
+
return { a: best.a, b: best.b, vertical: Math.abs(best.b[0] - best.a[0]) < Math.abs(best.b[1] - best.a[1]) };
|
|
422
|
+
}
|
|
423
|
+
function along(points, distance) {
|
|
424
|
+
let left = distance;
|
|
425
|
+
for (let i = 1; i < points.length; i++) {
|
|
426
|
+
const a = points[i - 1];
|
|
427
|
+
const b = points[i];
|
|
428
|
+
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
429
|
+
if (left <= length && length > 0) return [a[0] + (b[0] - a[0]) * left / length, a[1] + (b[1] - a[1]) * left / length];
|
|
430
|
+
left -= length;
|
|
431
|
+
}
|
|
432
|
+
return points[points.length - 1];
|
|
433
|
+
}
|
|
434
|
+
function pathLength(points) {
|
|
435
|
+
let sum = 0;
|
|
436
|
+
for (let i = 1; i < points.length; i++) {
|
|
437
|
+
const a = points[i - 1];
|
|
438
|
+
const b = points[i];
|
|
439
|
+
sum += Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
440
|
+
}
|
|
441
|
+
return sum;
|
|
442
|
+
}
|
|
443
|
+
function badgeOnPath(points) {
|
|
444
|
+
const length = pathLength(points);
|
|
445
|
+
return along(points, length < LOOK.badge.short ? length / 2 : LOOK.badge.along);
|
|
446
|
+
}
|
|
447
|
+
var labelStyle = (text2) => hasWide(text2) ? TYPE.labelJa : TYPE.label;
|
|
448
|
+
function placeLabel(request, obstacles) {
|
|
449
|
+
const w = textWidth(request.text, labelStyle(request.text)) + LOOK.label.padX * 2;
|
|
450
|
+
const h = LOOK.label.h;
|
|
451
|
+
const segment = longest(request.points);
|
|
452
|
+
const mx = (segment.a[0] + segment.b[0]) / 2;
|
|
453
|
+
const my = (segment.a[1] + segment.b[1]) / 2;
|
|
454
|
+
const side = request.side ?? (segment.vertical ? "right" : "above");
|
|
455
|
+
const { offset, side: sideGap } = LOOK.label;
|
|
456
|
+
const base = side === "above" ? { x: mx - w / 2, y: my - offset - h / 2, w, h } : side === "below" ? { x: mx - w / 2, y: my + offset - h / 2, w, h } : side === "left" ? { x: mx - sideGap - w, y: my - h / 2, w, h } : { x: mx + sideGap, y: my - h / 2, w, h };
|
|
457
|
+
const away = side === "above" ? [0, -1] : side === "below" ? [0, 1] : side === "left" ? [-1, 0] : [1, 0];
|
|
458
|
+
const slideAxis = [Math.abs(away[1]), Math.abs(away[0])];
|
|
459
|
+
const slideMax = side === "above" || side === "below" ? w : h * 4;
|
|
460
|
+
const clear = (rect) => obstacles.hard.every((box) => gapBetween(rect, box) >= LOOK.gap) && obstacles.soft.every((other) => gapBetween(rect, other) >= LOOK.label.soft);
|
|
461
|
+
const { search, searchMax } = LOOK.label;
|
|
462
|
+
for (let d = 0; d <= searchMax; d += search) {
|
|
463
|
+
for (let s = 0; s <= slideMax; s += search) {
|
|
464
|
+
for (const sign of s === 0 ? [1] : [1, -1]) {
|
|
465
|
+
const rect = { x: base.x + away[0] * d + slideAxis[0] * s * sign, y: base.y + away[1] * d + slideAxis[1] * s * sign, w, h };
|
|
466
|
+
if (clear(rect)) return { ...rect, step: request.step, event: request.event, text: request.text, family: labelStyle(request.text).family, color: request.color };
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return { ...base, step: request.step, event: request.event, text: request.text, family: labelStyle(request.text).family, color: request.color };
|
|
471
|
+
}
|
|
472
|
+
function fieldWidth(diagram, name) {
|
|
473
|
+
let value = 0;
|
|
474
|
+
let tag = 0;
|
|
475
|
+
for (const step of diagram.steps) {
|
|
476
|
+
for (const event of step.events) {
|
|
477
|
+
if (event.type !== "strip" || event.field !== name) continue;
|
|
478
|
+
if (event.value !== void 0) value = Math.max(value, textWidth(event.value, hasWide(event.value) ? TYPE.fieldValueJa : TYPE.fieldValue));
|
|
479
|
+
if (event.tag !== void 0) tag = Math.max(tag, textWidth(event.tag, TYPE.tag) + LOOK.strip.tagPadX * 2);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const both = value + (tag > 0 ? (value > 0 ? LOOK.strip.tagGap : 0) + tag : 0);
|
|
483
|
+
return Math.max(textWidth(name, TYPE.fieldName), both);
|
|
484
|
+
}
|
|
485
|
+
function stripNeed(diagram) {
|
|
486
|
+
if (!diagram.strip) return 0;
|
|
487
|
+
const { titleX, fieldGap, pad: pad2 } = LOOK.strip;
|
|
488
|
+
const start = titleX + textWidth(diagram.strip.title, TYPE.stripTitle) + fieldGap;
|
|
489
|
+
return start + diagram.strip.fields.reduce((sum, name) => sum + fieldWidth(diagram, name) + fieldGap, 0) - fieldGap + pad2;
|
|
490
|
+
}
|
|
491
|
+
function layoutStrip(diagram, x, y, width) {
|
|
492
|
+
if (!diagram.strip) return void 0;
|
|
493
|
+
const { titleX, fieldGap, pad: pad2, line, h } = LOOK.strip;
|
|
494
|
+
const start = titleX + textWidth(diagram.strip.title, TYPE.stripTitle) + fieldGap;
|
|
495
|
+
const fields = [];
|
|
496
|
+
let cx = start;
|
|
497
|
+
let row = 0;
|
|
498
|
+
for (const name of diagram.strip.fields) {
|
|
499
|
+
const w = fieldWidth(diagram, name);
|
|
500
|
+
if (cx > start && cx + w > width - pad2) {
|
|
501
|
+
cx = start;
|
|
502
|
+
row++;
|
|
503
|
+
}
|
|
504
|
+
fields.push({ name, x: x + cx, y: y + row * line, w });
|
|
505
|
+
cx += w + fieldGap;
|
|
506
|
+
}
|
|
507
|
+
return { x, y, w: width, h: h + row * line, title: diagram.strip.title, fields };
|
|
508
|
+
}
|
|
509
|
+
function shiftContent(layout, dx, dy) {
|
|
510
|
+
const move = (rect) => {
|
|
511
|
+
rect.x += dx;
|
|
512
|
+
rect.y += dy;
|
|
513
|
+
};
|
|
514
|
+
for (const box of layout.boxes) {
|
|
515
|
+
move(box);
|
|
516
|
+
box.cx += dx;
|
|
517
|
+
box.cy += dy;
|
|
518
|
+
}
|
|
519
|
+
for (const region of layout.regions) {
|
|
520
|
+
region.y += dy;
|
|
521
|
+
move(region.header);
|
|
522
|
+
}
|
|
523
|
+
for (const line of layout.lifelines) {
|
|
524
|
+
line.x += dx;
|
|
525
|
+
line.y1 += dy;
|
|
526
|
+
line.y2 += dy;
|
|
527
|
+
}
|
|
528
|
+
for (const edge2 of layout.edges) {
|
|
529
|
+
edge2.points = edge2.points.map(([px, py]) => [px + dx, py + dy]);
|
|
530
|
+
if (edge2.settle) edge2.settle = [edge2.settle[0] + dx, edge2.settle[1] + dy];
|
|
531
|
+
}
|
|
532
|
+
for (const label2 of layout.labels) move(label2);
|
|
533
|
+
for (const action2 of layout.actions) move(action2);
|
|
534
|
+
for (const badge2 of layout.badges) {
|
|
535
|
+
badge2.x += dx;
|
|
536
|
+
badge2.y += dy;
|
|
537
|
+
}
|
|
538
|
+
if (layout.strip) {
|
|
539
|
+
layout.strip.y += dy;
|
|
540
|
+
for (const field of layout.strip.fields) {
|
|
541
|
+
field.x += dx;
|
|
542
|
+
field.y += dy;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function cornerBadge(events, step, layout) {
|
|
547
|
+
const { inset } = LOOK.badge;
|
|
548
|
+
for (const event of events) {
|
|
549
|
+
const id = event.type === "swap" || event.type === "action" ? event.box : void 0;
|
|
550
|
+
const box2 = layout.boxes.find((b) => b.id === id);
|
|
551
|
+
if (box2) return { step, x: box2.x + inset, y: box2.y + inset, color: box2.color };
|
|
552
|
+
}
|
|
553
|
+
if (layout.strip && events.some((event) => event.type === "strip")) return { step, x: layout.strip.x + inset, y: layout.strip.y + inset, color: "slate" };
|
|
554
|
+
const box = layout.boxes[0];
|
|
555
|
+
return { step, x: box.x + inset, y: box.y + inset, color: box.color };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// src/layout/architecture.ts
|
|
559
|
+
function layoutArchitecture(diagram) {
|
|
560
|
+
const groups = groupsOf(diagram);
|
|
561
|
+
const slots = placeBoxes(diagram, groups);
|
|
562
|
+
const rooms = groups.map(() => ({ top: 0, bottom: 0 }));
|
|
563
|
+
let layout = arrange(diagram, groups, slots, rooms);
|
|
564
|
+
for (let pass = 0; pass < 3 && grow(layout, groups, slots, rooms); pass++) layout = arrange(diagram, groups, slots, rooms);
|
|
565
|
+
return layout;
|
|
566
|
+
}
|
|
567
|
+
function groupsOf(diagram) {
|
|
568
|
+
const regions = diagram.regions ?? [];
|
|
569
|
+
const known = new Set(regions.map((r) => r.id));
|
|
570
|
+
const groups = regions.map((region) => ({ region, members: diagram.boxes.filter((b) => b.region === region.id).map((b) => b.id) }));
|
|
571
|
+
const loose = diagram.boxes.filter((b) => b.region === void 0 || !known.has(b.region)).map((b) => b.id);
|
|
572
|
+
if (loose.length > 0) groups.push({ members: loose });
|
|
573
|
+
return groups;
|
|
574
|
+
}
|
|
575
|
+
var vertical = (side) => side === "left" || side === "right";
|
|
576
|
+
function placeBoxes(diagram, groups) {
|
|
577
|
+
const columns = LOOK.architecture.columns;
|
|
578
|
+
const edges = edgesOf(diagram).map((e) => e.edge);
|
|
579
|
+
const slots = /* @__PURE__ */ new Map();
|
|
580
|
+
groups.forEach((group, g) => {
|
|
581
|
+
const inGroup = new Set(group.members);
|
|
582
|
+
const taken = /* @__PURE__ */ new Set();
|
|
583
|
+
const free = (col, row) => col >= 0 && col < columns && !taken.has(`${col},${row}`);
|
|
584
|
+
const near = (col, row) => {
|
|
585
|
+
const start = Math.min(columns - 1, Math.max(0, col));
|
|
586
|
+
for (let r = row; ; r++) {
|
|
587
|
+
for (let d = 0; d < columns; d++) {
|
|
588
|
+
for (const c of [start + d, start - d]) if (free(c, r)) return [c, r];
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
const put = (id, col, row) => {
|
|
593
|
+
slots.set(id, { group: g, col, row });
|
|
594
|
+
taken.add(`${col},${row}`);
|
|
595
|
+
};
|
|
596
|
+
let dir = 1;
|
|
597
|
+
const visit = (id) => {
|
|
598
|
+
for (const edge2 of edges) {
|
|
599
|
+
const partner = edge2.from === id ? edge2.to : edge2.to === id ? edge2.from : void 0;
|
|
600
|
+
if (partner === void 0 || !inGroup.has(partner) || slots.has(partner)) continue;
|
|
601
|
+
const me = slots.get(id);
|
|
602
|
+
const [c, r] = vertical(edge2.labelSide) ? near(me.col, me.row + 1) : free(me.col + dir, me.row) ? [me.col + dir, me.row] : near(me.col + dir, me.row);
|
|
603
|
+
put(partner, c, r);
|
|
604
|
+
visit(partner);
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
const anchorOf = (id) => {
|
|
608
|
+
for (let i = 0; i < edges.length; i++) {
|
|
609
|
+
const edge2 = edges[i];
|
|
610
|
+
const partner = edge2?.from === id ? edge2.to : edge2?.to === id ? edge2.from : void 0;
|
|
611
|
+
const slot = partner === void 0 ? void 0 : slots.get(partner);
|
|
612
|
+
if (slot && slot.group < g) return { order: i, col: slot.col };
|
|
613
|
+
}
|
|
614
|
+
return void 0;
|
|
615
|
+
};
|
|
616
|
+
let placed = 0;
|
|
617
|
+
for (; ; ) {
|
|
618
|
+
const rest = group.members.filter((id) => !slots.has(id));
|
|
619
|
+
if (rest.length === 0) break;
|
|
620
|
+
const anchored = rest.map((id) => ({ id, anchor: anchorOf(id) })).filter((a) => a.anchor !== void 0);
|
|
621
|
+
anchored.sort((a, b) => (a.anchor?.order ?? 0) - (b.anchor?.order ?? 0));
|
|
622
|
+
const pick = anchored[0] ?? { id: rest[0], anchor: void 0 };
|
|
623
|
+
const want = pick.anchor?.col ?? 0;
|
|
624
|
+
if (placed === 0) dir = want >= (columns - 1) / 2 ? -1 : 1;
|
|
625
|
+
const [c, r] = free(want, 0) ? [want, 0] : near(want, 0);
|
|
626
|
+
put(pick.id, c, r);
|
|
627
|
+
visit(pick.id);
|
|
628
|
+
placed++;
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
const used = [...new Set([...slots.values()].map((s) => s.col))].sort((a, b) => a - b);
|
|
632
|
+
for (const slot of slots.values()) slot.col = used.indexOf(slot.col);
|
|
633
|
+
return slots;
|
|
634
|
+
}
|
|
635
|
+
function nameLines(name) {
|
|
636
|
+
const spaces = [...name.matchAll(/ /g)].map((m) => m.index);
|
|
637
|
+
if (spaces.length === 0) return [name];
|
|
638
|
+
const at2 = spaces.reduce((best, i) => Math.abs(i - name.length / 2) < Math.abs(best - name.length / 2) ? i : best);
|
|
639
|
+
return [name.slice(0, at2), name.slice(at2 + 1)];
|
|
640
|
+
}
|
|
641
|
+
function headerSize(region) {
|
|
642
|
+
const { icon, nameY, line, inset } = LOOK.region;
|
|
643
|
+
const lines = nameLines(region.name);
|
|
644
|
+
const w = Math.max(icon, ...lines.map((l) => textWidth(l, TYPE.regionName)), textWidth(region.note ?? "", TYPE.regionNote));
|
|
645
|
+
const h = nameY - inset + (lines.length - 1) * line + (region.note ? line : 0) + LOOK.gap / 2;
|
|
646
|
+
return { w, h, lines };
|
|
647
|
+
}
|
|
648
|
+
function arrange(diagram, groups, slots, rooms) {
|
|
649
|
+
const { box: B, region: R, architecture: A, margin, gap } = LOOK;
|
|
650
|
+
const colors = boxColors(diagram);
|
|
651
|
+
const regionColor = regionColors(diagram);
|
|
652
|
+
const edges = edgesOf(diagram);
|
|
653
|
+
const columnCount = Math.max(1, ...[...slots.values()].map((s) => s.col + 1));
|
|
654
|
+
const widths = new Map(diagram.boxes.map((b) => [b.id, boxWidth(diagram, b.id, true)]));
|
|
655
|
+
const colW = Array.from({ length: columnCount }, (_, c) => Math.max(B.minW, ...[...slots].filter(([, s]) => s.col === c).map(([id]) => widths.get(id) ?? B.minW)));
|
|
656
|
+
const between = Array.from({ length: Math.max(0, columnCount - 1) }, () => A.columnGap);
|
|
657
|
+
for (const { edge: edge2 } of edges) {
|
|
658
|
+
const a = slots.get(edge2.from);
|
|
659
|
+
const b = slots.get(edge2.to);
|
|
660
|
+
if (!a || !b || edge2.label === void 0 || a.group !== b.group || a.row !== b.row || Math.abs(a.col - b.col) !== 1 || vertical(edge2.labelSide)) continue;
|
|
661
|
+
const need = textWidth(edge2.label, labelStyle(edge2.label)) + LOOK.label.padX * 2 + A.labelRoom * 2;
|
|
662
|
+
const i = Math.min(a.col, b.col);
|
|
663
|
+
if (need <= A.maxColumnGap) between[i] = Math.max(between[i] ?? 0, need);
|
|
664
|
+
}
|
|
665
|
+
const headers = groups.map((g) => g.region ? headerSize(g.region) : void 0);
|
|
666
|
+
const headerW = Math.max(0, ...headers.map((h) => h ? h.w + R.inset * 2 : 0));
|
|
667
|
+
const colLeft = [];
|
|
668
|
+
for (let c = 0; c < columnCount; c++) colLeft.push(c === 0 ? margin + (headerW > 0 ? headerW : R.pad) : colLeft[c - 1] + colW[c - 1] + between[c - 1]);
|
|
669
|
+
const center = (c) => colLeft[c] + colW[c] / 2;
|
|
670
|
+
const boxes = [];
|
|
671
|
+
const bands = [];
|
|
672
|
+
let cursor = margin;
|
|
673
|
+
groups.forEach((group, g) => {
|
|
674
|
+
const rows = Math.max(1, ...group.members.map((id) => (slots.get(id)?.row ?? 0) + 1));
|
|
675
|
+
const room = rooms[g];
|
|
676
|
+
const top = cursor + R.pad + room.top;
|
|
677
|
+
for (const id of group.members) {
|
|
678
|
+
const slot = slots.get(id);
|
|
679
|
+
const source = diagram.boxes.find((b) => b.id === id);
|
|
680
|
+
const w = widths.get(id) ?? B.minW;
|
|
681
|
+
const cx = center(slot.col);
|
|
682
|
+
const y = top + slot.row * (B.h + A.rowGap);
|
|
683
|
+
boxes.push({
|
|
684
|
+
id,
|
|
685
|
+
name: source?.name ?? id,
|
|
686
|
+
...source?.sub !== void 0 ? { sub: source.sub } : {},
|
|
687
|
+
...source?.icon !== void 0 ? { icon: source.icon } : {},
|
|
688
|
+
color: colors.get(id) ?? "slate",
|
|
689
|
+
x: cx - w / 2,
|
|
690
|
+
y,
|
|
691
|
+
w,
|
|
692
|
+
h: B.h,
|
|
693
|
+
cx,
|
|
694
|
+
cy: y + B.h / 2
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
const contentBottom = top + rows * B.h + (rows - 1) * A.rowGap;
|
|
698
|
+
const header = headers[g];
|
|
699
|
+
const h = Math.max(contentBottom + R.pad + room.bottom - cursor, header ? header.h + R.inset * 2 : 0, group.region ? R.minH : 0);
|
|
700
|
+
bands.push({ group: g, y: cursor, h, rows });
|
|
701
|
+
cursor += h + R.gap;
|
|
702
|
+
});
|
|
703
|
+
const bandsBottom = cursor - R.gap;
|
|
704
|
+
const byId = new Map(boxes.map((b) => [b.id, b]));
|
|
705
|
+
const bandOf = (id) => bands[slots.get(id)?.group ?? 0];
|
|
706
|
+
const blocked = (points, a, b) => boxes.some((box) => {
|
|
707
|
+
if (box.id === a || box.id === b) return false;
|
|
708
|
+
const pad2 = LOOK.label.search;
|
|
709
|
+
for (let i = 1; i < points.length; i++) {
|
|
710
|
+
const [x1, y1] = points[i - 1];
|
|
711
|
+
const [x2, y2] = points[i];
|
|
712
|
+
if (Math.min(x1, x2) <= box.x + box.w + pad2 && Math.max(x1, x2) >= box.x - pad2 && Math.min(y1, y2) <= box.y + box.h + pad2 && Math.max(y1, y2) >= box.y - pad2) return true;
|
|
713
|
+
}
|
|
714
|
+
return false;
|
|
715
|
+
});
|
|
716
|
+
const laneBelow = (id) => {
|
|
717
|
+
const box = byId.get(id);
|
|
718
|
+
const band2 = bandOf(id);
|
|
719
|
+
return (slots.get(id)?.row ?? 0) < band2.rows - 1 ? box.y + box.h + A.rowGap / 2 : Math.min(box.y + box.h + R.pad / 2, band2.y + band2.h - LOOK.edge.inset);
|
|
720
|
+
};
|
|
721
|
+
const laneAbove = (id) => {
|
|
722
|
+
const box = byId.get(id);
|
|
723
|
+
const band2 = bandOf(id);
|
|
724
|
+
return (slots.get(id)?.row ?? 0) > 0 ? box.y - A.rowGap / 2 : Math.max(box.y - R.pad / 2, band2.y + LOOK.edge.inset);
|
|
725
|
+
};
|
|
726
|
+
const inset = LOOK.edge.inset;
|
|
727
|
+
const route = (from, to) => {
|
|
728
|
+
const a = byId.get(from);
|
|
729
|
+
const b = byId.get(to);
|
|
730
|
+
const sa = slots.get(from);
|
|
731
|
+
const sb = slots.get(to);
|
|
732
|
+
if (sa.group === sb.group && sa.row === sb.row) {
|
|
733
|
+
const right2 = b.cx > a.cx;
|
|
734
|
+
const straight = [
|
|
735
|
+
[right2 ? a.x + a.w : a.x, a.cy],
|
|
736
|
+
[right2 ? b.x - inset : b.x + b.w + inset, b.cy]
|
|
737
|
+
];
|
|
738
|
+
if (!blocked(straight, from, to)) return straight;
|
|
739
|
+
const lane2 = laneBelow(from);
|
|
740
|
+
return [
|
|
741
|
+
[a.cx, a.y + a.h],
|
|
742
|
+
[a.cx, lane2],
|
|
743
|
+
[b.cx, lane2],
|
|
744
|
+
[b.cx, b.y + b.h + inset]
|
|
745
|
+
];
|
|
746
|
+
}
|
|
747
|
+
const down = b.cy > a.cy;
|
|
748
|
+
const leave = [a.cx, down ? a.y + a.h : a.y];
|
|
749
|
+
const enter = [b.cx, down ? b.y - inset : b.y + b.h + inset];
|
|
750
|
+
if (sa.col === sb.col) {
|
|
751
|
+
const straight = [leave, enter];
|
|
752
|
+
if (!blocked(straight, from, to)) return straight;
|
|
753
|
+
const x = a.x + a.w + (between[sa.col] ?? A.columnGap) / 2;
|
|
754
|
+
return [
|
|
755
|
+
[a.x + a.w, a.cy],
|
|
756
|
+
[x, a.cy],
|
|
757
|
+
[x, b.cy],
|
|
758
|
+
[b.x + b.w + inset, b.cy]
|
|
759
|
+
];
|
|
760
|
+
}
|
|
761
|
+
const right = b.cx > a.cx;
|
|
762
|
+
const lane = down ? laneBelow(from) : laneAbove(from);
|
|
763
|
+
const candidates = [
|
|
764
|
+
[leave, [a.cx, b.cy], [right ? b.x - inset : b.x + b.w + inset, b.cy]],
|
|
765
|
+
[[right ? a.x + a.w : a.x, a.cy], [b.cx, a.cy], enter],
|
|
766
|
+
[leave, [a.cx, lane], [b.cx, lane], enter]
|
|
767
|
+
];
|
|
768
|
+
return candidates.find((points) => !blocked(points, from, to)) ?? candidates[2];
|
|
769
|
+
};
|
|
770
|
+
const sceneEdges = edges.map(({ step, event, edge: edge2 }) => {
|
|
771
|
+
const target = byId.get(edge2.to);
|
|
772
|
+
return {
|
|
773
|
+
step,
|
|
774
|
+
event,
|
|
775
|
+
from: edge2.from,
|
|
776
|
+
to: edge2.to,
|
|
777
|
+
points: route(edge2.from, edge2.to),
|
|
778
|
+
color: edgeColor(edge2, colors),
|
|
779
|
+
carry: edge2.carry,
|
|
780
|
+
settle: [target.cx, target.cy + B.iconY]
|
|
781
|
+
};
|
|
782
|
+
});
|
|
783
|
+
for (const edge2 of sceneEdges) {
|
|
784
|
+
if (edge2.points.length !== 2) continue;
|
|
785
|
+
const back = sceneEdges.some((other) => other.from === edge2.to && other.to === edge2.from && other.points.length === 2);
|
|
786
|
+
if (!back) continue;
|
|
787
|
+
const [p, q] = edge2.points;
|
|
788
|
+
const flat = Math.abs(q[1] - p[1]) < Math.abs(q[0] - p[0]);
|
|
789
|
+
const d = (edge2.from < edge2.to ? 1 : -1) * LOOK.edge.parallel;
|
|
790
|
+
edge2.points = edge2.points.map(([x, y]) => flat ? [x, y + d] : [x + d, y]);
|
|
791
|
+
}
|
|
792
|
+
const regions = [];
|
|
793
|
+
groups.forEach((group, g) => {
|
|
794
|
+
const band2 = bands[g];
|
|
795
|
+
const header = headers[g];
|
|
796
|
+
if (!group.region || !header) return;
|
|
797
|
+
regions.push({
|
|
798
|
+
id: group.region.id,
|
|
799
|
+
lines: header.lines,
|
|
800
|
+
...group.region.note !== void 0 ? { note: group.region.note } : {},
|
|
801
|
+
...group.region.icon !== void 0 ? { icon: group.region.icon } : {},
|
|
802
|
+
color: regionColor.get(group.region.id) ?? "slate",
|
|
803
|
+
x: margin,
|
|
804
|
+
y: band2.y,
|
|
805
|
+
w: 0,
|
|
806
|
+
h: band2.h,
|
|
807
|
+
header: { x: margin + R.inset, y: band2.y + R.inset, w: header.w, h: header.h }
|
|
808
|
+
});
|
|
809
|
+
});
|
|
810
|
+
const labels = [];
|
|
811
|
+
for (const edge2 of sceneEdges) {
|
|
812
|
+
const source = diagram.steps[edge2.step]?.events[edge2.event];
|
|
813
|
+
if (source?.type !== "edge" || source.label === void 0) continue;
|
|
814
|
+
const soft = [...regions.map((r) => r.header), ...labels.filter((l) => l.step === edge2.step)];
|
|
815
|
+
labels.push(
|
|
816
|
+
placeLabel(
|
|
817
|
+
{ step: edge2.step, event: edge2.event, text: source.label, points: edge2.points, color: edge2.color, ...source.labelSide ? { side: source.labelSide } : {} },
|
|
818
|
+
{ hard: boxes, soft }
|
|
819
|
+
)
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
const layout = { kind: "architecture", width: 0, height: 0, regions, boxes, lifelines: [], edges: sceneEdges, labels, actions: [], badges: [] };
|
|
823
|
+
const shift = labels.length > 0 ? Math.max(0, margin + LOOK.label.soft - Math.min(...labels.map((l) => l.x))) : 0;
|
|
824
|
+
if (shift > 0) shiftContent(layout, shift, 0);
|
|
825
|
+
const contentRight = Math.max(...boxes.map((b) => b.x + b.w + R.pad), ...labels.map((l) => l.x + l.w + LOOK.label.soft), ...sceneEdges.flatMap((e) => e.points.map((p) => p[0] + R.pad)));
|
|
826
|
+
const width = Math.max(contentRight + margin, stripNeed(diagram) + margin * 2);
|
|
827
|
+
for (const region of regions) region.w = width - margin * 2;
|
|
828
|
+
const strip2 = layoutStrip(diagram, margin, bandsBottom + gap, width - margin * 2);
|
|
829
|
+
layout.width = width;
|
|
830
|
+
layout.height = (strip2 ? strip2.y + strip2.h : bandsBottom) + margin;
|
|
831
|
+
if (strip2) layout.strip = strip2;
|
|
832
|
+
layout.badges = diagram.steps.map((step, s) => {
|
|
833
|
+
const edge2 = sceneEdges.find((e) => e.step === s);
|
|
834
|
+
if (!edge2) return cornerBadge(step.events, s, layout);
|
|
835
|
+
const [x, y] = badgeOnPath(edge2.points);
|
|
836
|
+
return { step: s, x, y, color: edge2.color };
|
|
837
|
+
});
|
|
838
|
+
return layout;
|
|
839
|
+
}
|
|
840
|
+
function grow(layout, groups, slots, rooms) {
|
|
841
|
+
let grown = false;
|
|
842
|
+
const soft = LOOK.label.soft;
|
|
843
|
+
for (const label2 of layout.labels) {
|
|
844
|
+
const edge2 = layout.edges.find((e) => e.step === label2.step && e.event === label2.event);
|
|
845
|
+
const a = edge2 && slots.get(edge2.from);
|
|
846
|
+
const b = edge2 && slots.get(edge2.to);
|
|
847
|
+
if (!a || !b || a.group !== b.group || !groups[a.group]?.region) continue;
|
|
848
|
+
const region = layout.regions.find((r) => r.id === groups[a.group]?.region?.id);
|
|
849
|
+
const room = rooms[a.group];
|
|
850
|
+
if (!region || !room) continue;
|
|
851
|
+
const over = region.y + soft - label2.y;
|
|
852
|
+
const under = label2.y + label2.h - (region.y + region.h - soft);
|
|
853
|
+
if (over > 0) {
|
|
854
|
+
room.top += over;
|
|
855
|
+
grown = true;
|
|
856
|
+
}
|
|
857
|
+
if (under > 0) {
|
|
858
|
+
room.bottom += under;
|
|
859
|
+
grown = true;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return grown;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// src/layout/sequence.ts
|
|
866
|
+
function layoutSequence(diagram) {
|
|
867
|
+
const { box: B, sequence: Q, label: L, margin, gap } = LOOK;
|
|
868
|
+
const colors = boxColors(diagram);
|
|
869
|
+
const listed = diagram.sequence?.lifelines ?? [];
|
|
870
|
+
const order = [...listed, ...diagram.boxes.map((b) => b.id).filter((id) => !listed.includes(id))];
|
|
871
|
+
const column = new Map(order.map((id, i) => [id, i]));
|
|
872
|
+
const widths = order.map((id) => boxWidth(diagram, id, false));
|
|
873
|
+
const spacing = widths.slice(1).map((w, i) => widths[i] / 2 + w / 2 + Q.columnGap);
|
|
874
|
+
const needs = [];
|
|
875
|
+
for (const step of diagram.steps) {
|
|
876
|
+
for (const event of step.events) {
|
|
877
|
+
if (event.type !== "edge" || event.label === void 0) continue;
|
|
878
|
+
const a = column.get(event.from) ?? 0;
|
|
879
|
+
const b = column.get(event.to) ?? 0;
|
|
880
|
+
const w = textWidth(event.label, labelStyle(event.label)) + L.padX * 2;
|
|
881
|
+
if (a === b) {
|
|
882
|
+
if (a < spacing.length) needs.push({ from: a, to: a + 1, need: Q.selfW + L.side + w + Q.labelRoom });
|
|
883
|
+
} else {
|
|
884
|
+
needs.push({ from: Math.min(a, b), to: Math.max(a, b), need: w + Q.labelRoom * 2 });
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
needs.sort((x, y2) => x.to - x.from - (y2.to - y2.from));
|
|
889
|
+
for (const { from, to, need } of needs) {
|
|
890
|
+
let have = 0;
|
|
891
|
+
for (let i = from; i < to; i++) have += spacing[i] ?? 0;
|
|
892
|
+
if (have >= need) continue;
|
|
893
|
+
const add = (need - have) / (to - from);
|
|
894
|
+
for (let i = from; i < to; i++) spacing[i] = (spacing[i] ?? 0) + add;
|
|
895
|
+
}
|
|
896
|
+
const xs = [];
|
|
897
|
+
order.forEach((_, i) => xs.push(i === 0 ? margin + widths[0] / 2 : xs[i - 1] + spacing[i - 1]));
|
|
898
|
+
const boxes = order.map((id, i) => {
|
|
899
|
+
const source = diagram.boxes.find((b) => b.id === id);
|
|
900
|
+
const w = widths[i];
|
|
901
|
+
const cx = xs[i];
|
|
902
|
+
return {
|
|
903
|
+
id,
|
|
904
|
+
name: source?.name ?? id,
|
|
905
|
+
...source?.sub !== void 0 ? { sub: source.sub } : {},
|
|
906
|
+
...source?.icon !== void 0 ? { icon: source.icon } : {},
|
|
907
|
+
color: colors.get(id) ?? "slate",
|
|
908
|
+
x: cx - w / 2,
|
|
909
|
+
y: margin,
|
|
910
|
+
w,
|
|
911
|
+
h: B.h,
|
|
912
|
+
cx,
|
|
913
|
+
cy: margin + B.h / 2
|
|
914
|
+
};
|
|
915
|
+
});
|
|
916
|
+
const headBottom = margin + B.h;
|
|
917
|
+
const edges = [];
|
|
918
|
+
const actions = [];
|
|
919
|
+
const requests = [];
|
|
920
|
+
let y = headBottom + Q.firstRow;
|
|
921
|
+
let below = 0;
|
|
922
|
+
let first = true;
|
|
923
|
+
diagram.steps.forEach((step, s) => {
|
|
924
|
+
step.events.forEach((event, e) => {
|
|
925
|
+
if (event.type !== "edge" && event.type !== "action") return;
|
|
926
|
+
let above;
|
|
927
|
+
let under;
|
|
928
|
+
if (event.type === "edge") {
|
|
929
|
+
const side = event.labelSide ?? "above";
|
|
930
|
+
const self = event.from === event.to;
|
|
931
|
+
const named = event.label !== void 0;
|
|
932
|
+
above = named && side === "above" ? L.offset + L.h / 2 : gap;
|
|
933
|
+
under = self ? Q.selfH + gap : named && side === "below" ? L.offset + L.h / 2 : gap;
|
|
934
|
+
} else {
|
|
935
|
+
above = LOOK.action.h / 2;
|
|
936
|
+
under = LOOK.action.h / 2;
|
|
937
|
+
}
|
|
938
|
+
y = first ? y + above : y + Math.max(Q.minPitch, below + Q.rowGap + above) + (e === 0 && s > 0 ? Q.stepGap : 0);
|
|
939
|
+
first = false;
|
|
940
|
+
below = under;
|
|
941
|
+
if (event.type === "edge") {
|
|
942
|
+
const xf = xs[column.get(event.from) ?? 0];
|
|
943
|
+
const xt = xs[column.get(event.to) ?? 0];
|
|
944
|
+
const dir = Math.sign(xt - xf) || 1;
|
|
945
|
+
const points = xf === xt ? [
|
|
946
|
+
[xf, y],
|
|
947
|
+
[xf + Q.selfW, y],
|
|
948
|
+
[xf + Q.selfW, y + Q.selfH],
|
|
949
|
+
[xf + LOOK.edge.inset, y + Q.selfH]
|
|
950
|
+
] : [
|
|
951
|
+
[xf, y],
|
|
952
|
+
[xt - dir * LOOK.edge.inset, y]
|
|
953
|
+
];
|
|
954
|
+
const color = edgeColor(event, colors);
|
|
955
|
+
edges.push({ step: s, event: e, from: event.from, to: event.to, points, color, carry: event.carry });
|
|
956
|
+
if (event.label !== void 0) {
|
|
957
|
+
requests.push({
|
|
958
|
+
step: s,
|
|
959
|
+
event: e,
|
|
960
|
+
text: event.label,
|
|
961
|
+
points,
|
|
962
|
+
color,
|
|
963
|
+
...event.labelSide ? { side: event.labelSide } : xf === xt ? { side: "right" } : {}
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
} else {
|
|
967
|
+
const x = xs[column.get(event.box) ?? 0];
|
|
968
|
+
const w = textWidth(event.label, TYPE.action) + LOOK.action.padX * 2;
|
|
969
|
+
actions.push({ step: s, event: e, box: event.box, text: event.label, color: colors.get(event.box) ?? "slate", x: x + LOOK.badge.r + 4, y: y - LOOK.action.h / 2, w, h: LOOK.action.h });
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
const bottom = (first ? headBottom : y + below) + Q.tail;
|
|
974
|
+
const lifelines = order.map((id, i) => ({ id, x: xs[i], y1: headBottom, y2: bottom }));
|
|
975
|
+
const labels = [];
|
|
976
|
+
for (const request of requests) {
|
|
977
|
+
const soft = [...labels.filter((l) => l.step === request.step), ...actions];
|
|
978
|
+
labels.push(placeLabel(request, { hard: boxes, soft }));
|
|
979
|
+
}
|
|
980
|
+
const layout = { kind: "sequence", width: 0, height: 0, regions: [], boxes, lifelines, edges, labels, actions, badges: [] };
|
|
981
|
+
const lefts = [...boxes.map((b) => b.x), ...labels.map((l) => l.x), ...actions.map((a) => a.x)];
|
|
982
|
+
const shift = Math.max(0, margin - Math.min(...lefts));
|
|
983
|
+
if (shift > 0) shiftContent(layout, shift, 0);
|
|
984
|
+
const rights = [...boxes.map((b) => b.x + b.w), ...labels.map((l) => l.x + l.w), ...actions.map((a) => a.x + a.w), ...edges.flatMap((edge2) => edge2.points.map((p) => p[0]))];
|
|
985
|
+
const width = Math.max(Math.max(...rights) + margin, stripNeed(diagram) + margin * 2);
|
|
986
|
+
const strip2 = layoutStrip(diagram, margin, bottom + gap, width - margin * 2);
|
|
987
|
+
layout.width = width;
|
|
988
|
+
layout.height = (strip2 ? strip2.y + strip2.h : bottom) + margin;
|
|
989
|
+
if (strip2) layout.strip = strip2;
|
|
990
|
+
layout.badges = badges(diagram, layout);
|
|
991
|
+
return layout;
|
|
992
|
+
}
|
|
993
|
+
function badges(diagram, layout) {
|
|
994
|
+
return diagram.steps.map((step, s) => {
|
|
995
|
+
const edge2 = layout.edges.find((e) => e.step === s);
|
|
996
|
+
if (edge2) {
|
|
997
|
+
const [x, y] = badgeOnPath(edge2.points);
|
|
998
|
+
return { step: s, x, y, color: edge2.color };
|
|
999
|
+
}
|
|
1000
|
+
const action2 = layout.actions.find((a) => a.step === s);
|
|
1001
|
+
const lifeline2 = action2 && layout.lifelines.find((l) => l.id === action2.box);
|
|
1002
|
+
if (action2 && lifeline2) return { step: s, x: lifeline2.x, y: action2.y + action2.h / 2, color: action2.color };
|
|
1003
|
+
return cornerBadge(step.events, s, layout);
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// src/field-messages.ts
|
|
1008
|
+
var TYPES_JA = {
|
|
1009
|
+
string: "\u6587\u5B57\u5217\u306B\u3059\u308B",
|
|
1010
|
+
integer: "\u6574\u6570\u306B\u3059\u308B",
|
|
1011
|
+
number: "\u6570\u306B\u3059\u308B",
|
|
1012
|
+
object: "\u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u306B\u3059\u308B",
|
|
1013
|
+
array: "\u914D\u5217\u306B\u3059\u308B",
|
|
1014
|
+
boolean: "true \u304B false \u306B\u3059\u308B",
|
|
1015
|
+
null: "null \u306B\u3059\u308B"
|
|
1016
|
+
};
|
|
1017
|
+
var TYPES_EN = {
|
|
1018
|
+
string: "Use a string",
|
|
1019
|
+
integer: "Use an integer",
|
|
1020
|
+
number: "Use a number",
|
|
1021
|
+
object: "Use an object",
|
|
1022
|
+
array: "Use an array",
|
|
1023
|
+
boolean: "Use true or false",
|
|
1024
|
+
null: "Use null"
|
|
1025
|
+
};
|
|
1026
|
+
var plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
1027
|
+
var ja = {
|
|
1028
|
+
additionalProperties: (key) => `${key} \u3068\u3044\u3046\u6B04\u306F\u66F8\u3051\u306A\u3044`,
|
|
1029
|
+
required: (key) => `${key} \u306E\u6B04\u304C\u8981\u308B`,
|
|
1030
|
+
enum: (values) => `${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
|
|
1031
|
+
type: (type) => TYPES_JA[type] ?? `${type} \u306B\u3059\u308B`,
|
|
1032
|
+
minLength: (limit) => `${limit} \u5B57\u4EE5\u4E0A\u66F8\u304F`,
|
|
1033
|
+
pattern: (forbidden) => forbidden ? `${forbidden.space ? "\u7A7A\u767D\u3068 " : ""}${forbidden.chars.join(" ")} \u306F\u4F7F\u3048\u306A\u3044` : "\u4F7F\u3048\u306A\u3044\u5B57\u304C\u5165\u3063\u3066\u3044\u308B",
|
|
1034
|
+
minItems: (limit) => `${limit} \u3064\u4EE5\u4E0A\u66F8\u304F`,
|
|
1035
|
+
minimum: (limit) => `${limit} \u4EE5\u4E0A\u306B\u3059\u308B`,
|
|
1036
|
+
const: (value) => `${value} \u306B\u3059\u308B`,
|
|
1037
|
+
not: (allowed) => allowed ? `${allowed.field} \u306E\u6B04\u306F kind \u304C ${allowed.kind} \u306E\u6642\u3060\u3051\u66F8\u3051\u308B` : "\u3053\u306E\u6B04\u306E\u7D44\u307F\u5408\u308F\u305B\u306F\u66F8\u3051\u306A\u3044",
|
|
1038
|
+
anyOf: (fields) => fields.length > 0 ? `${fields.join(" \u304B ")} \u306E${fields.length === 2 ? "\u3069\u3061\u3089\u304B" : "\u3069\u308C\u304B"}\u306E\u6B04\u304C\u8981\u308B` : "\u66F8\u3051\u308B\u5F62\u306E\u3069\u308C\u306B\u3082\u5408\u308F\u306A\u3044",
|
|
1039
|
+
oneOf: "\u66F8\u3051\u308B\u5F62\u306E\u3069\u308C\u304B 1 \u3064\u3060\u3051\u306B\u5408\u308F\u305B\u308B",
|
|
1040
|
+
discriminator: (tag, values) => `${tag} \u306F ${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
|
|
1041
|
+
newer: (version, tool) => `\u7248 ${version} \u306E\u56F3\u306F\u3001\u3053\u306E\u9053\u5177 (\u7248 ${tool}) \u3088\u308A\u65B0\u3057\u3044\u306E\u3067\u8AAD\u3081\u306A\u3044\u3002\u9053\u5177\u3092\u65B0\u3057\u304F\u3059\u308B`
|
|
1042
|
+
};
|
|
1043
|
+
var en = {
|
|
1044
|
+
additionalProperties: (key) => `The ${key} field is not allowed`,
|
|
1045
|
+
required: (key) => `The ${key} field is required`,
|
|
1046
|
+
enum: (values) => `Use one of ${values.join(" / ")}`,
|
|
1047
|
+
type: (type) => TYPES_EN[type] ?? `Use ${type}`,
|
|
1048
|
+
minLength: (limit) => `Write at least ${plural(limit, "character")}`,
|
|
1049
|
+
pattern: (forbidden) => forbidden ? `Cannot contain ${forbidden.space ? "spaces or " : ""}${forbidden.chars.join(" ")}` : "Contains characters that are not allowed",
|
|
1050
|
+
minItems: (limit) => `Write at least ${plural(limit, "item")}`,
|
|
1051
|
+
minimum: (limit) => `Use ${limit} or greater`,
|
|
1052
|
+
const: (value) => `Use ${value}`,
|
|
1053
|
+
not: (allowed) => allowed ? `The ${allowed.field} field is allowed only when kind is ${allowed.kind}` : "This combination of fields is not allowed",
|
|
1054
|
+
anyOf: (fields) => fields.length > 0 ? `Write one of the ${fields.join(" or ")} fields` : "Does not match any of the allowed shapes",
|
|
1055
|
+
oneOf: "Match exactly one of the allowed shapes",
|
|
1056
|
+
discriminator: (tag, values) => `${tag} is one of ${values.join(" / ")}`,
|
|
1057
|
+
newer: (version, tool) => `Version ${version} diagrams are newer than this tool (version ${tool}) and cannot be read. Update the tool`
|
|
1058
|
+
};
|
|
1059
|
+
var FIELD_MESSAGES = { ja, en };
|
|
1060
|
+
|
|
1061
|
+
// src/schemas/validate-diagram.js
|
|
1062
|
+
function ucs2length(str) {
|
|
1063
|
+
let length = 0;
|
|
1064
|
+
for (const _ of str) length++;
|
|
1065
|
+
return length;
|
|
1066
|
+
}
|
|
1067
|
+
var validate_diagram_default = validate10;
|
|
1068
|
+
var schema11 = { "properties": { "version": { "description": "\u5F62\u5F0F\u306E\u7248", "type": "integer", "minimum": 1 }, "kind": { "description": "\u56F3\u306E\u7A2E\u985E", "enum": ["sequence", "architecture"] }, "title": { "$ref": "#/definitions/text" }, "view": { "description": "\u898B\u305B\u65B9\u3002\u66F8\u304B\u306A\u3051\u308C\u3070\u5B57\u306E\u5927\u304D\u3055\u3067\u9078\u3076\u3002fixed \u306F\u5168\u4F53\u3092\u6B62\u3081\u3066\u4E2D\u3060\u3051\u52D5\u304B\u3057\u3001follow \u306F\u5BC4\u3063\u3066\u52D5\u304B\u3057\u5168\u4F53\u56F3\u3067\u4ECA\u3069\u3053\u304B\u3092\u793A\u3059", "enum": ["fixed", "follow"] }, "regions": { "type": "array", "items": { "$ref": "#/definitions/region" } }, "boxes": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/box" } }, "strip": { "$ref": "#/definitions/strip" }, "steps": { "type": "array", "minItems": 1, "items": { "$ref": "#/definitions/step" } }, "sequence": { "$ref": "#/definitions/sequence" } }};
|
|
1069
|
+
var func2 = Object.prototype.hasOwnProperty;
|
|
1070
|
+
var func3 = ucs2length;
|
|
1071
|
+
var schema17 = { "enum": ["blue", "amber", "green", "violet", "rose", "slate", "coin"] };
|
|
1072
|
+
var pattern0 = new RegExp("^[^\\s\\[\\]\u300C\u300D=:]+$", "u");
|
|
1073
|
+
function validate11(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
1074
|
+
let vErrors = null;
|
|
1075
|
+
let errors = 0;
|
|
1076
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1077
|
+
if (data.id === void 0) {
|
|
1078
|
+
const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "id" }, message: "must have required property 'id'" };
|
|
1079
|
+
if (vErrors === null) {
|
|
1080
|
+
vErrors = [err0];
|
|
1081
|
+
} else {
|
|
1082
|
+
vErrors.push(err0);
|
|
1083
|
+
}
|
|
1084
|
+
errors++;
|
|
1085
|
+
}
|
|
1086
|
+
if (data.name === void 0) {
|
|
1087
|
+
const err1 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "name" }, message: "must have required property 'name'" };
|
|
1088
|
+
if (vErrors === null) {
|
|
1089
|
+
vErrors = [err1];
|
|
1090
|
+
} else {
|
|
1091
|
+
vErrors.push(err1);
|
|
1092
|
+
}
|
|
1093
|
+
errors++;
|
|
1094
|
+
}
|
|
1095
|
+
for (const key0 in data) {
|
|
1096
|
+
if (!(key0 === "id" || key0 === "name" || key0 === "note" || key0 === "color" || key0 === "icon")) {
|
|
1097
|
+
const err2 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
1098
|
+
if (vErrors === null) {
|
|
1099
|
+
vErrors = [err2];
|
|
1100
|
+
} else {
|
|
1101
|
+
vErrors.push(err2);
|
|
1102
|
+
}
|
|
1103
|
+
errors++;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
if (data.id !== void 0) {
|
|
1107
|
+
let data0 = data.id;
|
|
1108
|
+
if (typeof data0 === "string") {
|
|
1109
|
+
if (!pattern0.test(data0)) {
|
|
1110
|
+
const err3 = { instancePath: instancePath + "/id", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
1111
|
+
if (vErrors === null) {
|
|
1112
|
+
vErrors = [err3];
|
|
1113
|
+
} else {
|
|
1114
|
+
vErrors.push(err3);
|
|
1115
|
+
}
|
|
1116
|
+
errors++;
|
|
1117
|
+
}
|
|
1118
|
+
} else {
|
|
1119
|
+
const err4 = { instancePath: instancePath + "/id", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1120
|
+
if (vErrors === null) {
|
|
1121
|
+
vErrors = [err4];
|
|
1122
|
+
} else {
|
|
1123
|
+
vErrors.push(err4);
|
|
1124
|
+
}
|
|
1125
|
+
errors++;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
if (data.name !== void 0) {
|
|
1129
|
+
let data1 = data.name;
|
|
1130
|
+
if (typeof data1 === "string") {
|
|
1131
|
+
if (func3(data1) < 1) {
|
|
1132
|
+
const err5 = { instancePath: instancePath + "/name", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1133
|
+
if (vErrors === null) {
|
|
1134
|
+
vErrors = [err5];
|
|
1135
|
+
} else {
|
|
1136
|
+
vErrors.push(err5);
|
|
1137
|
+
}
|
|
1138
|
+
errors++;
|
|
1139
|
+
}
|
|
1140
|
+
} else {
|
|
1141
|
+
const err6 = { instancePath: instancePath + "/name", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1142
|
+
if (vErrors === null) {
|
|
1143
|
+
vErrors = [err6];
|
|
1144
|
+
} else {
|
|
1145
|
+
vErrors.push(err6);
|
|
1146
|
+
}
|
|
1147
|
+
errors++;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
if (data.note !== void 0) {
|
|
1151
|
+
let data2 = data.note;
|
|
1152
|
+
if (typeof data2 === "string") {
|
|
1153
|
+
if (func3(data2) < 1) {
|
|
1154
|
+
const err7 = { instancePath: instancePath + "/note", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1155
|
+
if (vErrors === null) {
|
|
1156
|
+
vErrors = [err7];
|
|
1157
|
+
} else {
|
|
1158
|
+
vErrors.push(err7);
|
|
1159
|
+
}
|
|
1160
|
+
errors++;
|
|
1161
|
+
}
|
|
1162
|
+
} else {
|
|
1163
|
+
const err8 = { instancePath: instancePath + "/note", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1164
|
+
if (vErrors === null) {
|
|
1165
|
+
vErrors = [err8];
|
|
1166
|
+
} else {
|
|
1167
|
+
vErrors.push(err8);
|
|
1168
|
+
}
|
|
1169
|
+
errors++;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
if (data.color !== void 0) {
|
|
1173
|
+
let data3 = data.color;
|
|
1174
|
+
if (!(data3 === "blue" || data3 === "amber" || data3 === "green" || data3 === "violet" || data3 === "rose" || data3 === "slate" || data3 === "coin")) {
|
|
1175
|
+
const err9 = { instancePath: instancePath + "/color", schemaPath: "#/definitions/color/enum", keyword: "enum", params: { allowedValues: schema17.enum }, message: "must be equal to one of the allowed values" };
|
|
1176
|
+
if (vErrors === null) {
|
|
1177
|
+
vErrors = [err9];
|
|
1178
|
+
} else {
|
|
1179
|
+
vErrors.push(err9);
|
|
1180
|
+
}
|
|
1181
|
+
errors++;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
if (data.icon !== void 0) {
|
|
1185
|
+
let data4 = data.icon;
|
|
1186
|
+
if (typeof data4 === "string") {
|
|
1187
|
+
if (func3(data4) < 1) {
|
|
1188
|
+
const err10 = { instancePath: instancePath + "/icon", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1189
|
+
if (vErrors === null) {
|
|
1190
|
+
vErrors = [err10];
|
|
1191
|
+
} else {
|
|
1192
|
+
vErrors.push(err10);
|
|
1193
|
+
}
|
|
1194
|
+
errors++;
|
|
1195
|
+
}
|
|
1196
|
+
} else {
|
|
1197
|
+
const err11 = { instancePath: instancePath + "/icon", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1198
|
+
if (vErrors === null) {
|
|
1199
|
+
vErrors = [err11];
|
|
1200
|
+
} else {
|
|
1201
|
+
vErrors.push(err11);
|
|
1202
|
+
}
|
|
1203
|
+
errors++;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
} else {
|
|
1207
|
+
const err12 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
1208
|
+
if (vErrors === null) {
|
|
1209
|
+
vErrors = [err12];
|
|
1210
|
+
} else {
|
|
1211
|
+
vErrors.push(err12);
|
|
1212
|
+
}
|
|
1213
|
+
errors++;
|
|
1214
|
+
}
|
|
1215
|
+
validate11.errors = vErrors;
|
|
1216
|
+
return errors === 0;
|
|
1217
|
+
}
|
|
1218
|
+
function validate13(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
1219
|
+
let vErrors = null;
|
|
1220
|
+
let errors = 0;
|
|
1221
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1222
|
+
if (data.id === void 0) {
|
|
1223
|
+
const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "id" }, message: "must have required property 'id'" };
|
|
1224
|
+
if (vErrors === null) {
|
|
1225
|
+
vErrors = [err0];
|
|
1226
|
+
} else {
|
|
1227
|
+
vErrors.push(err0);
|
|
1228
|
+
}
|
|
1229
|
+
errors++;
|
|
1230
|
+
}
|
|
1231
|
+
if (data.name === void 0) {
|
|
1232
|
+
const err1 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "name" }, message: "must have required property 'name'" };
|
|
1233
|
+
if (vErrors === null) {
|
|
1234
|
+
vErrors = [err1];
|
|
1235
|
+
} else {
|
|
1236
|
+
vErrors.push(err1);
|
|
1237
|
+
}
|
|
1238
|
+
errors++;
|
|
1239
|
+
}
|
|
1240
|
+
for (const key0 in data) {
|
|
1241
|
+
if (!(key0 === "id" || key0 === "name" || key0 === "sub" || key0 === "color" || key0 === "icon" || key0 === "region")) {
|
|
1242
|
+
const err2 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
1243
|
+
if (vErrors === null) {
|
|
1244
|
+
vErrors = [err2];
|
|
1245
|
+
} else {
|
|
1246
|
+
vErrors.push(err2);
|
|
1247
|
+
}
|
|
1248
|
+
errors++;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
if (data.id !== void 0) {
|
|
1252
|
+
let data0 = data.id;
|
|
1253
|
+
if (typeof data0 === "string") {
|
|
1254
|
+
if (!pattern0.test(data0)) {
|
|
1255
|
+
const err3 = { instancePath: instancePath + "/id", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
1256
|
+
if (vErrors === null) {
|
|
1257
|
+
vErrors = [err3];
|
|
1258
|
+
} else {
|
|
1259
|
+
vErrors.push(err3);
|
|
1260
|
+
}
|
|
1261
|
+
errors++;
|
|
1262
|
+
}
|
|
1263
|
+
} else {
|
|
1264
|
+
const err4 = { instancePath: instancePath + "/id", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1265
|
+
if (vErrors === null) {
|
|
1266
|
+
vErrors = [err4];
|
|
1267
|
+
} else {
|
|
1268
|
+
vErrors.push(err4);
|
|
1269
|
+
}
|
|
1270
|
+
errors++;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (data.name !== void 0) {
|
|
1274
|
+
let data1 = data.name;
|
|
1275
|
+
if (typeof data1 === "string") {
|
|
1276
|
+
if (func3(data1) < 1) {
|
|
1277
|
+
const err5 = { instancePath: instancePath + "/name", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1278
|
+
if (vErrors === null) {
|
|
1279
|
+
vErrors = [err5];
|
|
1280
|
+
} else {
|
|
1281
|
+
vErrors.push(err5);
|
|
1282
|
+
}
|
|
1283
|
+
errors++;
|
|
1284
|
+
}
|
|
1285
|
+
} else {
|
|
1286
|
+
const err6 = { instancePath: instancePath + "/name", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1287
|
+
if (vErrors === null) {
|
|
1288
|
+
vErrors = [err6];
|
|
1289
|
+
} else {
|
|
1290
|
+
vErrors.push(err6);
|
|
1291
|
+
}
|
|
1292
|
+
errors++;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
if (data.sub !== void 0) {
|
|
1296
|
+
let data2 = data.sub;
|
|
1297
|
+
if (typeof data2 === "string") {
|
|
1298
|
+
if (func3(data2) < 1) {
|
|
1299
|
+
const err7 = { instancePath: instancePath + "/sub", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1300
|
+
if (vErrors === null) {
|
|
1301
|
+
vErrors = [err7];
|
|
1302
|
+
} else {
|
|
1303
|
+
vErrors.push(err7);
|
|
1304
|
+
}
|
|
1305
|
+
errors++;
|
|
1306
|
+
}
|
|
1307
|
+
} else {
|
|
1308
|
+
const err8 = { instancePath: instancePath + "/sub", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1309
|
+
if (vErrors === null) {
|
|
1310
|
+
vErrors = [err8];
|
|
1311
|
+
} else {
|
|
1312
|
+
vErrors.push(err8);
|
|
1313
|
+
}
|
|
1314
|
+
errors++;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
if (data.color !== void 0) {
|
|
1318
|
+
let data3 = data.color;
|
|
1319
|
+
if (!(data3 === "blue" || data3 === "amber" || data3 === "green" || data3 === "violet" || data3 === "rose" || data3 === "slate" || data3 === "coin")) {
|
|
1320
|
+
const err9 = { instancePath: instancePath + "/color", schemaPath: "#/definitions/color/enum", keyword: "enum", params: { allowedValues: schema17.enum }, message: "must be equal to one of the allowed values" };
|
|
1321
|
+
if (vErrors === null) {
|
|
1322
|
+
vErrors = [err9];
|
|
1323
|
+
} else {
|
|
1324
|
+
vErrors.push(err9);
|
|
1325
|
+
}
|
|
1326
|
+
errors++;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
if (data.icon !== void 0) {
|
|
1330
|
+
let data4 = data.icon;
|
|
1331
|
+
if (typeof data4 === "string") {
|
|
1332
|
+
if (func3(data4) < 1) {
|
|
1333
|
+
const err10 = { instancePath: instancePath + "/icon", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1334
|
+
if (vErrors === null) {
|
|
1335
|
+
vErrors = [err10];
|
|
1336
|
+
} else {
|
|
1337
|
+
vErrors.push(err10);
|
|
1338
|
+
}
|
|
1339
|
+
errors++;
|
|
1340
|
+
}
|
|
1341
|
+
} else {
|
|
1342
|
+
const err11 = { instancePath: instancePath + "/icon", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1343
|
+
if (vErrors === null) {
|
|
1344
|
+
vErrors = [err11];
|
|
1345
|
+
} else {
|
|
1346
|
+
vErrors.push(err11);
|
|
1347
|
+
}
|
|
1348
|
+
errors++;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
if (data.region !== void 0) {
|
|
1352
|
+
let data5 = data.region;
|
|
1353
|
+
if (typeof data5 === "string") {
|
|
1354
|
+
if (!pattern0.test(data5)) {
|
|
1355
|
+
const err12 = { instancePath: instancePath + "/region", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
1356
|
+
if (vErrors === null) {
|
|
1357
|
+
vErrors = [err12];
|
|
1358
|
+
} else {
|
|
1359
|
+
vErrors.push(err12);
|
|
1360
|
+
}
|
|
1361
|
+
errors++;
|
|
1362
|
+
}
|
|
1363
|
+
} else {
|
|
1364
|
+
const err13 = { instancePath: instancePath + "/region", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1365
|
+
if (vErrors === null) {
|
|
1366
|
+
vErrors = [err13];
|
|
1367
|
+
} else {
|
|
1368
|
+
vErrors.push(err13);
|
|
1369
|
+
}
|
|
1370
|
+
errors++;
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
} else {
|
|
1374
|
+
const err14 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
1375
|
+
if (vErrors === null) {
|
|
1376
|
+
vErrors = [err14];
|
|
1377
|
+
} else {
|
|
1378
|
+
vErrors.push(err14);
|
|
1379
|
+
}
|
|
1380
|
+
errors++;
|
|
1381
|
+
}
|
|
1382
|
+
validate13.errors = vErrors;
|
|
1383
|
+
return errors === 0;
|
|
1384
|
+
}
|
|
1385
|
+
function validate15(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
1386
|
+
let vErrors = null;
|
|
1387
|
+
let errors = 0;
|
|
1388
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1389
|
+
if (data.title === void 0) {
|
|
1390
|
+
const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "title" }, message: "must have required property 'title'" };
|
|
1391
|
+
if (vErrors === null) {
|
|
1392
|
+
vErrors = [err0];
|
|
1393
|
+
} else {
|
|
1394
|
+
vErrors.push(err0);
|
|
1395
|
+
}
|
|
1396
|
+
errors++;
|
|
1397
|
+
}
|
|
1398
|
+
if (data.fields === void 0) {
|
|
1399
|
+
const err1 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "fields" }, message: "must have required property 'fields'" };
|
|
1400
|
+
if (vErrors === null) {
|
|
1401
|
+
vErrors = [err1];
|
|
1402
|
+
} else {
|
|
1403
|
+
vErrors.push(err1);
|
|
1404
|
+
}
|
|
1405
|
+
errors++;
|
|
1406
|
+
}
|
|
1407
|
+
for (const key0 in data) {
|
|
1408
|
+
if (!(key0 === "title" || key0 === "fields")) {
|
|
1409
|
+
const err2 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
1410
|
+
if (vErrors === null) {
|
|
1411
|
+
vErrors = [err2];
|
|
1412
|
+
} else {
|
|
1413
|
+
vErrors.push(err2);
|
|
1414
|
+
}
|
|
1415
|
+
errors++;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
if (data.title !== void 0) {
|
|
1419
|
+
let data0 = data.title;
|
|
1420
|
+
if (typeof data0 === "string") {
|
|
1421
|
+
if (func3(data0) < 1) {
|
|
1422
|
+
const err3 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1423
|
+
if (vErrors === null) {
|
|
1424
|
+
vErrors = [err3];
|
|
1425
|
+
} else {
|
|
1426
|
+
vErrors.push(err3);
|
|
1427
|
+
}
|
|
1428
|
+
errors++;
|
|
1429
|
+
}
|
|
1430
|
+
} else {
|
|
1431
|
+
const err4 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1432
|
+
if (vErrors === null) {
|
|
1433
|
+
vErrors = [err4];
|
|
1434
|
+
} else {
|
|
1435
|
+
vErrors.push(err4);
|
|
1436
|
+
}
|
|
1437
|
+
errors++;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
if (data.fields !== void 0) {
|
|
1441
|
+
let data1 = data.fields;
|
|
1442
|
+
if (Array.isArray(data1)) {
|
|
1443
|
+
if (data1.length < 1) {
|
|
1444
|
+
const err5 = { instancePath: instancePath + "/fields", schemaPath: "#/properties/fields/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
|
|
1445
|
+
if (vErrors === null) {
|
|
1446
|
+
vErrors = [err5];
|
|
1447
|
+
} else {
|
|
1448
|
+
vErrors.push(err5);
|
|
1449
|
+
}
|
|
1450
|
+
errors++;
|
|
1451
|
+
}
|
|
1452
|
+
const len0 = data1.length;
|
|
1453
|
+
for (let i0 = 0; i0 < len0; i0++) {
|
|
1454
|
+
let data2 = data1[i0];
|
|
1455
|
+
if (typeof data2 === "string") {
|
|
1456
|
+
if (func3(data2) < 1) {
|
|
1457
|
+
const err6 = { instancePath: instancePath + "/fields/" + i0, schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1458
|
+
if (vErrors === null) {
|
|
1459
|
+
vErrors = [err6];
|
|
1460
|
+
} else {
|
|
1461
|
+
vErrors.push(err6);
|
|
1462
|
+
}
|
|
1463
|
+
errors++;
|
|
1464
|
+
}
|
|
1465
|
+
} else {
|
|
1466
|
+
const err7 = { instancePath: instancePath + "/fields/" + i0, schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1467
|
+
if (vErrors === null) {
|
|
1468
|
+
vErrors = [err7];
|
|
1469
|
+
} else {
|
|
1470
|
+
vErrors.push(err7);
|
|
1471
|
+
}
|
|
1472
|
+
errors++;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
} else {
|
|
1476
|
+
const err8 = { instancePath: instancePath + "/fields", schemaPath: "#/properties/fields/type", keyword: "type", params: { type: "array" }, message: "must be array" };
|
|
1477
|
+
if (vErrors === null) {
|
|
1478
|
+
vErrors = [err8];
|
|
1479
|
+
} else {
|
|
1480
|
+
vErrors.push(err8);
|
|
1481
|
+
}
|
|
1482
|
+
errors++;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
} else {
|
|
1486
|
+
const err9 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
1487
|
+
if (vErrors === null) {
|
|
1488
|
+
vErrors = [err9];
|
|
1489
|
+
} else {
|
|
1490
|
+
vErrors.push(err9);
|
|
1491
|
+
}
|
|
1492
|
+
errors++;
|
|
1493
|
+
}
|
|
1494
|
+
validate15.errors = vErrors;
|
|
1495
|
+
return errors === 0;
|
|
1496
|
+
}
|
|
1497
|
+
var schema33 = { "oneOf": [{ "description": "\u7DDA\u3002\u904B\u3076\u7269\u3092\u8F09\u305B\u3066\u9001\u308B\u5074\u304B\u3089\u53D7\u3051\u308B\u5074\u3078\u8D70\u308B", "type": "object", "additionalProperties": false, "required": ["type", "from", "to", "carry"], "properties": { "type": { "const": "edge" }, "from": { "$ref": "#/definitions/id" }, "to": { "$ref": "#/definitions/id" }, "label": { "$ref": "#/definitions/text" }, "carry": { "$ref": "#/definitions/carry" }, "labelSide": { "description": "\u7DDA\u306E\u540D\u524D\u3092\u7F6E\u304F\u5074 (\u5BC4\u305B\u306E\u6307\u793A)", "enum": ["above", "below", "left", "right"] } } }, { "description": "\u7BB1\u306E\u4E2D\u306E\u51E6\u7406", "type": "object", "additionalProperties": false, "required": ["type", "box", "label"], "properties": { "type": { "const": "action" }, "box": { "$ref": "#/definitions/id" }, "label": { "$ref": "#/definitions/text" } } }, { "description": "\u7BB1\u306E\u4E0B\u306E\u5C0F\u3055\u306A\u5B57\u306E\u66F8\u304D\u63DB\u3048", "type": "object", "additionalProperties": false, "required": ["type", "box", "text"], "properties": { "type": { "const": "swap" }, "box": { "$ref": "#/definitions/id" }, "text": { "$ref": "#/definitions/text" } } }, { "description": "\u4E2D\u8EAB\u306E\u5E2F\u306E\u6B04\u306E\u5024\u3068\u672D", "type": "object", "additionalProperties": false, "required": ["type", "field"], "anyOf": [{ "required": ["value"] }, { "required": ["tag"] }], "properties": { "type": { "const": "strip" }, "field": { "$ref": "#/definitions/text" }, "value": { "$ref": "#/definitions/text" }, "tag": { "$ref": "#/definitions/text" } } }] };
|
|
1498
|
+
var schema37 = { "properties": { "kind": { "enum": ["envelope", "tag", "coin", "none"] }}};
|
|
1499
|
+
function validate19(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
1500
|
+
let vErrors = null;
|
|
1501
|
+
let errors = 0;
|
|
1502
|
+
const _errs1 = errors;
|
|
1503
|
+
let valid0 = true;
|
|
1504
|
+
const _errs2 = errors;
|
|
1505
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1506
|
+
if (data.kind === void 0 && ("kind")) {
|
|
1507
|
+
const err0 = {};
|
|
1508
|
+
if (vErrors === null) {
|
|
1509
|
+
vErrors = [err0];
|
|
1510
|
+
} else {
|
|
1511
|
+
vErrors.push(err0);
|
|
1512
|
+
}
|
|
1513
|
+
errors++;
|
|
1514
|
+
} else {
|
|
1515
|
+
if (data.kind !== void 0) {
|
|
1516
|
+
if ("tag" !== data.kind) {
|
|
1517
|
+
const err1 = {};
|
|
1518
|
+
if (vErrors === null) {
|
|
1519
|
+
vErrors = [err1];
|
|
1520
|
+
} else {
|
|
1521
|
+
vErrors.push(err1);
|
|
1522
|
+
}
|
|
1523
|
+
errors++;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
var _valid0 = _errs2 === errors;
|
|
1529
|
+
errors = _errs1;
|
|
1530
|
+
if (vErrors !== null) {
|
|
1531
|
+
if (_errs1) {
|
|
1532
|
+
vErrors.length = _errs1;
|
|
1533
|
+
} else {
|
|
1534
|
+
vErrors = null;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
let ifClause0;
|
|
1538
|
+
if (_valid0) {
|
|
1539
|
+
const _errs4 = errors;
|
|
1540
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1541
|
+
if (data.text === void 0) {
|
|
1542
|
+
const err2 = { instancePath, schemaPath: "#/then/required", keyword: "required", params: { missingProperty: "text" }, message: "must have required property 'text'" };
|
|
1543
|
+
if (vErrors === null) {
|
|
1544
|
+
vErrors = [err2];
|
|
1545
|
+
} else {
|
|
1546
|
+
vErrors.push(err2);
|
|
1547
|
+
}
|
|
1548
|
+
errors++;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
var _valid0 = _errs4 === errors;
|
|
1552
|
+
valid0 = _valid0;
|
|
1553
|
+
ifClause0 = "then";
|
|
1554
|
+
} else {
|
|
1555
|
+
const _errs5 = errors;
|
|
1556
|
+
const _errs6 = errors;
|
|
1557
|
+
const _errs7 = errors;
|
|
1558
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1559
|
+
if (data.text === void 0 && ("text")) {
|
|
1560
|
+
const err3 = {};
|
|
1561
|
+
if (vErrors === null) {
|
|
1562
|
+
vErrors = [err3];
|
|
1563
|
+
} else {
|
|
1564
|
+
vErrors.push(err3);
|
|
1565
|
+
}
|
|
1566
|
+
errors++;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
var valid2 = _errs7 === errors;
|
|
1570
|
+
if (valid2) {
|
|
1571
|
+
const err4 = { instancePath, schemaPath: "#/else/not", keyword: "not", params: {}, message: "must NOT be valid" };
|
|
1572
|
+
if (vErrors === null) {
|
|
1573
|
+
vErrors = [err4];
|
|
1574
|
+
} else {
|
|
1575
|
+
vErrors.push(err4);
|
|
1576
|
+
}
|
|
1577
|
+
errors++;
|
|
1578
|
+
} else {
|
|
1579
|
+
errors = _errs6;
|
|
1580
|
+
if (vErrors !== null) {
|
|
1581
|
+
if (_errs6) {
|
|
1582
|
+
vErrors.length = _errs6;
|
|
1583
|
+
} else {
|
|
1584
|
+
vErrors = null;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
var _valid0 = _errs5 === errors;
|
|
1589
|
+
valid0 = _valid0;
|
|
1590
|
+
ifClause0 = "else";
|
|
1591
|
+
}
|
|
1592
|
+
if (!valid0) {
|
|
1593
|
+
const err5 = { instancePath, schemaPath: "#/if", keyword: "if", params: { failingKeyword: ifClause0 }, message: 'must match "' + ifClause0 + '" schema' };
|
|
1594
|
+
if (vErrors === null) {
|
|
1595
|
+
vErrors = [err5];
|
|
1596
|
+
} else {
|
|
1597
|
+
vErrors.push(err5);
|
|
1598
|
+
}
|
|
1599
|
+
errors++;
|
|
1600
|
+
}
|
|
1601
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1602
|
+
if (data.kind === void 0) {
|
|
1603
|
+
const err6 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "kind" }, message: "must have required property 'kind'" };
|
|
1604
|
+
if (vErrors === null) {
|
|
1605
|
+
vErrors = [err6];
|
|
1606
|
+
} else {
|
|
1607
|
+
vErrors.push(err6);
|
|
1608
|
+
}
|
|
1609
|
+
errors++;
|
|
1610
|
+
}
|
|
1611
|
+
for (const key0 in data) {
|
|
1612
|
+
if (!(key0 === "kind" || key0 === "text")) {
|
|
1613
|
+
const err7 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
1614
|
+
if (vErrors === null) {
|
|
1615
|
+
vErrors = [err7];
|
|
1616
|
+
} else {
|
|
1617
|
+
vErrors.push(err7);
|
|
1618
|
+
}
|
|
1619
|
+
errors++;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
if (data.kind !== void 0) {
|
|
1623
|
+
let data1 = data.kind;
|
|
1624
|
+
if (!(data1 === "envelope" || data1 === "tag" || data1 === "coin" || data1 === "none")) {
|
|
1625
|
+
const err8 = { instancePath: instancePath + "/kind", schemaPath: "#/properties/kind/enum", keyword: "enum", params: { allowedValues: schema37.properties.kind.enum }, message: "must be equal to one of the allowed values" };
|
|
1626
|
+
if (vErrors === null) {
|
|
1627
|
+
vErrors = [err8];
|
|
1628
|
+
} else {
|
|
1629
|
+
vErrors.push(err8);
|
|
1630
|
+
}
|
|
1631
|
+
errors++;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (data.text !== void 0) {
|
|
1635
|
+
let data2 = data.text;
|
|
1636
|
+
if (typeof data2 === "string") {
|
|
1637
|
+
if (func3(data2) < 1) {
|
|
1638
|
+
const err9 = { instancePath: instancePath + "/text", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1639
|
+
if (vErrors === null) {
|
|
1640
|
+
vErrors = [err9];
|
|
1641
|
+
} else {
|
|
1642
|
+
vErrors.push(err9);
|
|
1643
|
+
}
|
|
1644
|
+
errors++;
|
|
1645
|
+
}
|
|
1646
|
+
} else {
|
|
1647
|
+
const err10 = { instancePath: instancePath + "/text", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1648
|
+
if (vErrors === null) {
|
|
1649
|
+
vErrors = [err10];
|
|
1650
|
+
} else {
|
|
1651
|
+
vErrors.push(err10);
|
|
1652
|
+
}
|
|
1653
|
+
errors++;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
} else {
|
|
1657
|
+
const err11 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
1658
|
+
if (vErrors === null) {
|
|
1659
|
+
vErrors = [err11];
|
|
1660
|
+
} else {
|
|
1661
|
+
vErrors.push(err11);
|
|
1662
|
+
}
|
|
1663
|
+
errors++;
|
|
1664
|
+
}
|
|
1665
|
+
validate19.errors = vErrors;
|
|
1666
|
+
return errors === 0;
|
|
1667
|
+
}
|
|
1668
|
+
function validate18(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
1669
|
+
let vErrors = null;
|
|
1670
|
+
let errors = 0;
|
|
1671
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1672
|
+
if (data.type === void 0) {
|
|
1673
|
+
const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "type" }, message: "must have required property 'type'" };
|
|
1674
|
+
if (vErrors === null) {
|
|
1675
|
+
vErrors = [err0];
|
|
1676
|
+
} else {
|
|
1677
|
+
vErrors.push(err0);
|
|
1678
|
+
}
|
|
1679
|
+
errors++;
|
|
1680
|
+
}
|
|
1681
|
+
const tag0 = data.type;
|
|
1682
|
+
if (typeof tag0 == "string") {
|
|
1683
|
+
if (tag0 === "edge") {
|
|
1684
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1685
|
+
if (data.type === void 0) {
|
|
1686
|
+
const err1 = { instancePath, schemaPath: "#/oneOf/0/required", keyword: "required", params: { missingProperty: "type" }, message: "must have required property 'type'" };
|
|
1687
|
+
if (vErrors === null) {
|
|
1688
|
+
vErrors = [err1];
|
|
1689
|
+
} else {
|
|
1690
|
+
vErrors.push(err1);
|
|
1691
|
+
}
|
|
1692
|
+
errors++;
|
|
1693
|
+
}
|
|
1694
|
+
if (data.from === void 0) {
|
|
1695
|
+
const err2 = { instancePath, schemaPath: "#/oneOf/0/required", keyword: "required", params: { missingProperty: "from" }, message: "must have required property 'from'" };
|
|
1696
|
+
if (vErrors === null) {
|
|
1697
|
+
vErrors = [err2];
|
|
1698
|
+
} else {
|
|
1699
|
+
vErrors.push(err2);
|
|
1700
|
+
}
|
|
1701
|
+
errors++;
|
|
1702
|
+
}
|
|
1703
|
+
if (data.to === void 0) {
|
|
1704
|
+
const err3 = { instancePath, schemaPath: "#/oneOf/0/required", keyword: "required", params: { missingProperty: "to" }, message: "must have required property 'to'" };
|
|
1705
|
+
if (vErrors === null) {
|
|
1706
|
+
vErrors = [err3];
|
|
1707
|
+
} else {
|
|
1708
|
+
vErrors.push(err3);
|
|
1709
|
+
}
|
|
1710
|
+
errors++;
|
|
1711
|
+
}
|
|
1712
|
+
if (data.carry === void 0) {
|
|
1713
|
+
const err4 = { instancePath, schemaPath: "#/oneOf/0/required", keyword: "required", params: { missingProperty: "carry" }, message: "must have required property 'carry'" };
|
|
1714
|
+
if (vErrors === null) {
|
|
1715
|
+
vErrors = [err4];
|
|
1716
|
+
} else {
|
|
1717
|
+
vErrors.push(err4);
|
|
1718
|
+
}
|
|
1719
|
+
errors++;
|
|
1720
|
+
}
|
|
1721
|
+
for (const key0 in data) {
|
|
1722
|
+
if (!(key0 === "type" || key0 === "from" || key0 === "to" || key0 === "label" || key0 === "carry" || key0 === "labelSide")) {
|
|
1723
|
+
const err5 = { instancePath, schemaPath: "#/oneOf/0/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
1724
|
+
if (vErrors === null) {
|
|
1725
|
+
vErrors = [err5];
|
|
1726
|
+
} else {
|
|
1727
|
+
vErrors.push(err5);
|
|
1728
|
+
}
|
|
1729
|
+
errors++;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (data.type !== void 0) {
|
|
1733
|
+
if ("edge" !== data.type) {
|
|
1734
|
+
const err6 = { instancePath: instancePath + "/type", schemaPath: "#/oneOf/0/properties/type/const", keyword: "const", params: { allowedValue: "edge" }, message: "must be equal to constant" };
|
|
1735
|
+
if (vErrors === null) {
|
|
1736
|
+
vErrors = [err6];
|
|
1737
|
+
} else {
|
|
1738
|
+
vErrors.push(err6);
|
|
1739
|
+
}
|
|
1740
|
+
errors++;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
if (data.from !== void 0) {
|
|
1744
|
+
let data1 = data.from;
|
|
1745
|
+
if (typeof data1 === "string") {
|
|
1746
|
+
if (!pattern0.test(data1)) {
|
|
1747
|
+
const err7 = { instancePath: instancePath + "/from", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
1748
|
+
if (vErrors === null) {
|
|
1749
|
+
vErrors = [err7];
|
|
1750
|
+
} else {
|
|
1751
|
+
vErrors.push(err7);
|
|
1752
|
+
}
|
|
1753
|
+
errors++;
|
|
1754
|
+
}
|
|
1755
|
+
} else {
|
|
1756
|
+
const err8 = { instancePath: instancePath + "/from", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1757
|
+
if (vErrors === null) {
|
|
1758
|
+
vErrors = [err8];
|
|
1759
|
+
} else {
|
|
1760
|
+
vErrors.push(err8);
|
|
1761
|
+
}
|
|
1762
|
+
errors++;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
if (data.to !== void 0) {
|
|
1766
|
+
let data2 = data.to;
|
|
1767
|
+
if (typeof data2 === "string") {
|
|
1768
|
+
if (!pattern0.test(data2)) {
|
|
1769
|
+
const err9 = { instancePath: instancePath + "/to", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
1770
|
+
if (vErrors === null) {
|
|
1771
|
+
vErrors = [err9];
|
|
1772
|
+
} else {
|
|
1773
|
+
vErrors.push(err9);
|
|
1774
|
+
}
|
|
1775
|
+
errors++;
|
|
1776
|
+
}
|
|
1777
|
+
} else {
|
|
1778
|
+
const err10 = { instancePath: instancePath + "/to", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1779
|
+
if (vErrors === null) {
|
|
1780
|
+
vErrors = [err10];
|
|
1781
|
+
} else {
|
|
1782
|
+
vErrors.push(err10);
|
|
1783
|
+
}
|
|
1784
|
+
errors++;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
if (data.label !== void 0) {
|
|
1788
|
+
let data3 = data.label;
|
|
1789
|
+
if (typeof data3 === "string") {
|
|
1790
|
+
if (func3(data3) < 1) {
|
|
1791
|
+
const err11 = { instancePath: instancePath + "/label", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1792
|
+
if (vErrors === null) {
|
|
1793
|
+
vErrors = [err11];
|
|
1794
|
+
} else {
|
|
1795
|
+
vErrors.push(err11);
|
|
1796
|
+
}
|
|
1797
|
+
errors++;
|
|
1798
|
+
}
|
|
1799
|
+
} else {
|
|
1800
|
+
const err12 = { instancePath: instancePath + "/label", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1801
|
+
if (vErrors === null) {
|
|
1802
|
+
vErrors = [err12];
|
|
1803
|
+
} else {
|
|
1804
|
+
vErrors.push(err12);
|
|
1805
|
+
}
|
|
1806
|
+
errors++;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
if (data.carry !== void 0) {
|
|
1810
|
+
if (!validate19(data.carry, { instancePath: instancePath + "/carry", parentData: data, parentDataProperty: "carry", rootData })) {
|
|
1811
|
+
vErrors = vErrors === null ? validate19.errors : vErrors.concat(validate19.errors);
|
|
1812
|
+
errors = vErrors.length;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
if (data.labelSide !== void 0) {
|
|
1816
|
+
let data5 = data.labelSide;
|
|
1817
|
+
if (!(data5 === "above" || data5 === "below" || data5 === "left" || data5 === "right")) {
|
|
1818
|
+
const err13 = { instancePath: instancePath + "/labelSide", schemaPath: "#/oneOf/0/properties/labelSide/enum", keyword: "enum", params: { allowedValues: schema33.oneOf[0].properties.labelSide.enum }, message: "must be equal to one of the allowed values" };
|
|
1819
|
+
if (vErrors === null) {
|
|
1820
|
+
vErrors = [err13];
|
|
1821
|
+
} else {
|
|
1822
|
+
vErrors.push(err13);
|
|
1823
|
+
}
|
|
1824
|
+
errors++;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
} else {
|
|
1828
|
+
const err14 = { instancePath, schemaPath: "#/oneOf/0/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
1829
|
+
if (vErrors === null) {
|
|
1830
|
+
vErrors = [err14];
|
|
1831
|
+
} else {
|
|
1832
|
+
vErrors.push(err14);
|
|
1833
|
+
}
|
|
1834
|
+
errors++;
|
|
1835
|
+
}
|
|
1836
|
+
} else if (tag0 === "action") {
|
|
1837
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1838
|
+
if (data.type === void 0) {
|
|
1839
|
+
const err15 = { instancePath, schemaPath: "#/oneOf/1/required", keyword: "required", params: { missingProperty: "type" }, message: "must have required property 'type'" };
|
|
1840
|
+
if (vErrors === null) {
|
|
1841
|
+
vErrors = [err15];
|
|
1842
|
+
} else {
|
|
1843
|
+
vErrors.push(err15);
|
|
1844
|
+
}
|
|
1845
|
+
errors++;
|
|
1846
|
+
}
|
|
1847
|
+
if (data.box === void 0) {
|
|
1848
|
+
const err16 = { instancePath, schemaPath: "#/oneOf/1/required", keyword: "required", params: { missingProperty: "box" }, message: "must have required property 'box'" };
|
|
1849
|
+
if (vErrors === null) {
|
|
1850
|
+
vErrors = [err16];
|
|
1851
|
+
} else {
|
|
1852
|
+
vErrors.push(err16);
|
|
1853
|
+
}
|
|
1854
|
+
errors++;
|
|
1855
|
+
}
|
|
1856
|
+
if (data.label === void 0) {
|
|
1857
|
+
const err17 = { instancePath, schemaPath: "#/oneOf/1/required", keyword: "required", params: { missingProperty: "label" }, message: "must have required property 'label'" };
|
|
1858
|
+
if (vErrors === null) {
|
|
1859
|
+
vErrors = [err17];
|
|
1860
|
+
} else {
|
|
1861
|
+
vErrors.push(err17);
|
|
1862
|
+
}
|
|
1863
|
+
errors++;
|
|
1864
|
+
}
|
|
1865
|
+
for (const key1 in data) {
|
|
1866
|
+
if (!(key1 === "type" || key1 === "box" || key1 === "label")) {
|
|
1867
|
+
const err18 = { instancePath, schemaPath: "#/oneOf/1/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key1 }, message: "must NOT have additional properties" };
|
|
1868
|
+
if (vErrors === null) {
|
|
1869
|
+
vErrors = [err18];
|
|
1870
|
+
} else {
|
|
1871
|
+
vErrors.push(err18);
|
|
1872
|
+
}
|
|
1873
|
+
errors++;
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
if (data.type !== void 0) {
|
|
1877
|
+
if ("action" !== data.type) {
|
|
1878
|
+
const err19 = { instancePath: instancePath + "/type", schemaPath: "#/oneOf/1/properties/type/const", keyword: "const", params: { allowedValue: "action" }, message: "must be equal to constant" };
|
|
1879
|
+
if (vErrors === null) {
|
|
1880
|
+
vErrors = [err19];
|
|
1881
|
+
} else {
|
|
1882
|
+
vErrors.push(err19);
|
|
1883
|
+
}
|
|
1884
|
+
errors++;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
if (data.box !== void 0) {
|
|
1888
|
+
let data7 = data.box;
|
|
1889
|
+
if (typeof data7 === "string") {
|
|
1890
|
+
if (!pattern0.test(data7)) {
|
|
1891
|
+
const err20 = { instancePath: instancePath + "/box", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
1892
|
+
if (vErrors === null) {
|
|
1893
|
+
vErrors = [err20];
|
|
1894
|
+
} else {
|
|
1895
|
+
vErrors.push(err20);
|
|
1896
|
+
}
|
|
1897
|
+
errors++;
|
|
1898
|
+
}
|
|
1899
|
+
} else {
|
|
1900
|
+
const err21 = { instancePath: instancePath + "/box", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1901
|
+
if (vErrors === null) {
|
|
1902
|
+
vErrors = [err21];
|
|
1903
|
+
} else {
|
|
1904
|
+
vErrors.push(err21);
|
|
1905
|
+
}
|
|
1906
|
+
errors++;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
if (data.label !== void 0) {
|
|
1910
|
+
let data8 = data.label;
|
|
1911
|
+
if (typeof data8 === "string") {
|
|
1912
|
+
if (func3(data8) < 1) {
|
|
1913
|
+
const err22 = { instancePath: instancePath + "/label", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
1914
|
+
if (vErrors === null) {
|
|
1915
|
+
vErrors = [err22];
|
|
1916
|
+
} else {
|
|
1917
|
+
vErrors.push(err22);
|
|
1918
|
+
}
|
|
1919
|
+
errors++;
|
|
1920
|
+
}
|
|
1921
|
+
} else {
|
|
1922
|
+
const err23 = { instancePath: instancePath + "/label", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
1923
|
+
if (vErrors === null) {
|
|
1924
|
+
vErrors = [err23];
|
|
1925
|
+
} else {
|
|
1926
|
+
vErrors.push(err23);
|
|
1927
|
+
}
|
|
1928
|
+
errors++;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
} else {
|
|
1932
|
+
const err24 = { instancePath, schemaPath: "#/oneOf/1/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
1933
|
+
if (vErrors === null) {
|
|
1934
|
+
vErrors = [err24];
|
|
1935
|
+
} else {
|
|
1936
|
+
vErrors.push(err24);
|
|
1937
|
+
}
|
|
1938
|
+
errors++;
|
|
1939
|
+
}
|
|
1940
|
+
} else if (tag0 === "swap") {
|
|
1941
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
1942
|
+
if (data.type === void 0) {
|
|
1943
|
+
const err25 = { instancePath, schemaPath: "#/oneOf/2/required", keyword: "required", params: { missingProperty: "type" }, message: "must have required property 'type'" };
|
|
1944
|
+
if (vErrors === null) {
|
|
1945
|
+
vErrors = [err25];
|
|
1946
|
+
} else {
|
|
1947
|
+
vErrors.push(err25);
|
|
1948
|
+
}
|
|
1949
|
+
errors++;
|
|
1950
|
+
}
|
|
1951
|
+
if (data.box === void 0) {
|
|
1952
|
+
const err26 = { instancePath, schemaPath: "#/oneOf/2/required", keyword: "required", params: { missingProperty: "box" }, message: "must have required property 'box'" };
|
|
1953
|
+
if (vErrors === null) {
|
|
1954
|
+
vErrors = [err26];
|
|
1955
|
+
} else {
|
|
1956
|
+
vErrors.push(err26);
|
|
1957
|
+
}
|
|
1958
|
+
errors++;
|
|
1959
|
+
}
|
|
1960
|
+
if (data.text === void 0) {
|
|
1961
|
+
const err27 = { instancePath, schemaPath: "#/oneOf/2/required", keyword: "required", params: { missingProperty: "text" }, message: "must have required property 'text'" };
|
|
1962
|
+
if (vErrors === null) {
|
|
1963
|
+
vErrors = [err27];
|
|
1964
|
+
} else {
|
|
1965
|
+
vErrors.push(err27);
|
|
1966
|
+
}
|
|
1967
|
+
errors++;
|
|
1968
|
+
}
|
|
1969
|
+
for (const key2 in data) {
|
|
1970
|
+
if (!(key2 === "type" || key2 === "box" || key2 === "text")) {
|
|
1971
|
+
const err28 = { instancePath, schemaPath: "#/oneOf/2/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key2 }, message: "must NOT have additional properties" };
|
|
1972
|
+
if (vErrors === null) {
|
|
1973
|
+
vErrors = [err28];
|
|
1974
|
+
} else {
|
|
1975
|
+
vErrors.push(err28);
|
|
1976
|
+
}
|
|
1977
|
+
errors++;
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
if (data.type !== void 0) {
|
|
1981
|
+
if ("swap" !== data.type) {
|
|
1982
|
+
const err29 = { instancePath: instancePath + "/type", schemaPath: "#/oneOf/2/properties/type/const", keyword: "const", params: { allowedValue: "swap" }, message: "must be equal to constant" };
|
|
1983
|
+
if (vErrors === null) {
|
|
1984
|
+
vErrors = [err29];
|
|
1985
|
+
} else {
|
|
1986
|
+
vErrors.push(err29);
|
|
1987
|
+
}
|
|
1988
|
+
errors++;
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
if (data.box !== void 0) {
|
|
1992
|
+
let data10 = data.box;
|
|
1993
|
+
if (typeof data10 === "string") {
|
|
1994
|
+
if (!pattern0.test(data10)) {
|
|
1995
|
+
const err30 = { instancePath: instancePath + "/box", schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
1996
|
+
if (vErrors === null) {
|
|
1997
|
+
vErrors = [err30];
|
|
1998
|
+
} else {
|
|
1999
|
+
vErrors.push(err30);
|
|
2000
|
+
}
|
|
2001
|
+
errors++;
|
|
2002
|
+
}
|
|
2003
|
+
} else {
|
|
2004
|
+
const err31 = { instancePath: instancePath + "/box", schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2005
|
+
if (vErrors === null) {
|
|
2006
|
+
vErrors = [err31];
|
|
2007
|
+
} else {
|
|
2008
|
+
vErrors.push(err31);
|
|
2009
|
+
}
|
|
2010
|
+
errors++;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
if (data.text !== void 0) {
|
|
2014
|
+
let data11 = data.text;
|
|
2015
|
+
if (typeof data11 === "string") {
|
|
2016
|
+
if (func3(data11) < 1) {
|
|
2017
|
+
const err32 = { instancePath: instancePath + "/text", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2018
|
+
if (vErrors === null) {
|
|
2019
|
+
vErrors = [err32];
|
|
2020
|
+
} else {
|
|
2021
|
+
vErrors.push(err32);
|
|
2022
|
+
}
|
|
2023
|
+
errors++;
|
|
2024
|
+
}
|
|
2025
|
+
} else {
|
|
2026
|
+
const err33 = { instancePath: instancePath + "/text", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2027
|
+
if (vErrors === null) {
|
|
2028
|
+
vErrors = [err33];
|
|
2029
|
+
} else {
|
|
2030
|
+
vErrors.push(err33);
|
|
2031
|
+
}
|
|
2032
|
+
errors++;
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
} else {
|
|
2036
|
+
const err34 = { instancePath, schemaPath: "#/oneOf/2/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
2037
|
+
if (vErrors === null) {
|
|
2038
|
+
vErrors = [err34];
|
|
2039
|
+
} else {
|
|
2040
|
+
vErrors.push(err34);
|
|
2041
|
+
}
|
|
2042
|
+
errors++;
|
|
2043
|
+
}
|
|
2044
|
+
} else if (tag0 === "strip") {
|
|
2045
|
+
const _errs39 = errors;
|
|
2046
|
+
let valid15 = false;
|
|
2047
|
+
const _errs40 = errors;
|
|
2048
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2049
|
+
if (data.value === void 0) {
|
|
2050
|
+
const err35 = { instancePath, schemaPath: "#/oneOf/3/anyOf/0/required", keyword: "required", params: { missingProperty: "value" }, message: "must have required property 'value'" };
|
|
2051
|
+
if (vErrors === null) {
|
|
2052
|
+
vErrors = [err35];
|
|
2053
|
+
} else {
|
|
2054
|
+
vErrors.push(err35);
|
|
2055
|
+
}
|
|
2056
|
+
errors++;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
var _valid0 = _errs40 === errors;
|
|
2060
|
+
valid15 = valid15 || _valid0;
|
|
2061
|
+
if (!valid15) {
|
|
2062
|
+
const _errs41 = errors;
|
|
2063
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2064
|
+
if (data.tag === void 0) {
|
|
2065
|
+
const err36 = { instancePath, schemaPath: "#/oneOf/3/anyOf/1/required", keyword: "required", params: { missingProperty: "tag" }, message: "must have required property 'tag'" };
|
|
2066
|
+
if (vErrors === null) {
|
|
2067
|
+
vErrors = [err36];
|
|
2068
|
+
} else {
|
|
2069
|
+
vErrors.push(err36);
|
|
2070
|
+
}
|
|
2071
|
+
errors++;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
var _valid0 = _errs41 === errors;
|
|
2075
|
+
valid15 = valid15 || _valid0;
|
|
2076
|
+
}
|
|
2077
|
+
if (!valid15) {
|
|
2078
|
+
const err37 = { instancePath, schemaPath: "#/oneOf/3/anyOf", keyword: "anyOf", params: {}, message: "must match a schema in anyOf" };
|
|
2079
|
+
if (vErrors === null) {
|
|
2080
|
+
vErrors = [err37];
|
|
2081
|
+
} else {
|
|
2082
|
+
vErrors.push(err37);
|
|
2083
|
+
}
|
|
2084
|
+
errors++;
|
|
2085
|
+
} else {
|
|
2086
|
+
errors = _errs39;
|
|
2087
|
+
if (vErrors !== null) {
|
|
2088
|
+
if (_errs39) {
|
|
2089
|
+
vErrors.length = _errs39;
|
|
2090
|
+
} else {
|
|
2091
|
+
vErrors = null;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2096
|
+
if (data.type === void 0) {
|
|
2097
|
+
const err38 = { instancePath, schemaPath: "#/oneOf/3/required", keyword: "required", params: { missingProperty: "type" }, message: "must have required property 'type'" };
|
|
2098
|
+
if (vErrors === null) {
|
|
2099
|
+
vErrors = [err38];
|
|
2100
|
+
} else {
|
|
2101
|
+
vErrors.push(err38);
|
|
2102
|
+
}
|
|
2103
|
+
errors++;
|
|
2104
|
+
}
|
|
2105
|
+
if (data.field === void 0) {
|
|
2106
|
+
const err39 = { instancePath, schemaPath: "#/oneOf/3/required", keyword: "required", params: { missingProperty: "field" }, message: "must have required property 'field'" };
|
|
2107
|
+
if (vErrors === null) {
|
|
2108
|
+
vErrors = [err39];
|
|
2109
|
+
} else {
|
|
2110
|
+
vErrors.push(err39);
|
|
2111
|
+
}
|
|
2112
|
+
errors++;
|
|
2113
|
+
}
|
|
2114
|
+
for (const key3 in data) {
|
|
2115
|
+
if (!(key3 === "type" || key3 === "field" || key3 === "value" || key3 === "tag")) {
|
|
2116
|
+
const err40 = { instancePath, schemaPath: "#/oneOf/3/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key3 }, message: "must NOT have additional properties" };
|
|
2117
|
+
if (vErrors === null) {
|
|
2118
|
+
vErrors = [err40];
|
|
2119
|
+
} else {
|
|
2120
|
+
vErrors.push(err40);
|
|
2121
|
+
}
|
|
2122
|
+
errors++;
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
if (data.type !== void 0) {
|
|
2126
|
+
if ("strip" !== data.type) {
|
|
2127
|
+
const err41 = { instancePath: instancePath + "/type", schemaPath: "#/oneOf/3/properties/type/const", keyword: "const", params: { allowedValue: "strip" }, message: "must be equal to constant" };
|
|
2128
|
+
if (vErrors === null) {
|
|
2129
|
+
vErrors = [err41];
|
|
2130
|
+
} else {
|
|
2131
|
+
vErrors.push(err41);
|
|
2132
|
+
}
|
|
2133
|
+
errors++;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
if (data.field !== void 0) {
|
|
2137
|
+
let data13 = data.field;
|
|
2138
|
+
if (typeof data13 === "string") {
|
|
2139
|
+
if (func3(data13) < 1) {
|
|
2140
|
+
const err42 = { instancePath: instancePath + "/field", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2141
|
+
if (vErrors === null) {
|
|
2142
|
+
vErrors = [err42];
|
|
2143
|
+
} else {
|
|
2144
|
+
vErrors.push(err42);
|
|
2145
|
+
}
|
|
2146
|
+
errors++;
|
|
2147
|
+
}
|
|
2148
|
+
} else {
|
|
2149
|
+
const err43 = { instancePath: instancePath + "/field", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2150
|
+
if (vErrors === null) {
|
|
2151
|
+
vErrors = [err43];
|
|
2152
|
+
} else {
|
|
2153
|
+
vErrors.push(err43);
|
|
2154
|
+
}
|
|
2155
|
+
errors++;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
if (data.value !== void 0) {
|
|
2159
|
+
let data14 = data.value;
|
|
2160
|
+
if (typeof data14 === "string") {
|
|
2161
|
+
if (func3(data14) < 1) {
|
|
2162
|
+
const err44 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2163
|
+
if (vErrors === null) {
|
|
2164
|
+
vErrors = [err44];
|
|
2165
|
+
} else {
|
|
2166
|
+
vErrors.push(err44);
|
|
2167
|
+
}
|
|
2168
|
+
errors++;
|
|
2169
|
+
}
|
|
2170
|
+
} else {
|
|
2171
|
+
const err45 = { instancePath: instancePath + "/value", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2172
|
+
if (vErrors === null) {
|
|
2173
|
+
vErrors = [err45];
|
|
2174
|
+
} else {
|
|
2175
|
+
vErrors.push(err45);
|
|
2176
|
+
}
|
|
2177
|
+
errors++;
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
if (data.tag !== void 0) {
|
|
2181
|
+
let data15 = data.tag;
|
|
2182
|
+
if (typeof data15 === "string") {
|
|
2183
|
+
if (func3(data15) < 1) {
|
|
2184
|
+
const err46 = { instancePath: instancePath + "/tag", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2185
|
+
if (vErrors === null) {
|
|
2186
|
+
vErrors = [err46];
|
|
2187
|
+
} else {
|
|
2188
|
+
vErrors.push(err46);
|
|
2189
|
+
}
|
|
2190
|
+
errors++;
|
|
2191
|
+
}
|
|
2192
|
+
} else {
|
|
2193
|
+
const err47 = { instancePath: instancePath + "/tag", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2194
|
+
if (vErrors === null) {
|
|
2195
|
+
vErrors = [err47];
|
|
2196
|
+
} else {
|
|
2197
|
+
vErrors.push(err47);
|
|
2198
|
+
}
|
|
2199
|
+
errors++;
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
} else {
|
|
2203
|
+
const err48 = { instancePath, schemaPath: "#/oneOf/3/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
2204
|
+
if (vErrors === null) {
|
|
2205
|
+
vErrors = [err48];
|
|
2206
|
+
} else {
|
|
2207
|
+
vErrors.push(err48);
|
|
2208
|
+
}
|
|
2209
|
+
errors++;
|
|
2210
|
+
}
|
|
2211
|
+
} else {
|
|
2212
|
+
const err49 = { instancePath, schemaPath: "#/discriminator", keyword: "discriminator", params: { error: "mapping", tag: "type", tagValue: tag0 }, message: 'value of tag "type" must be in oneOf' };
|
|
2213
|
+
if (vErrors === null) {
|
|
2214
|
+
vErrors = [err49];
|
|
2215
|
+
} else {
|
|
2216
|
+
vErrors.push(err49);
|
|
2217
|
+
}
|
|
2218
|
+
errors++;
|
|
2219
|
+
}
|
|
2220
|
+
} else {
|
|
2221
|
+
const err50 = { instancePath, schemaPath: "#/discriminator", keyword: "discriminator", params: { error: "tag", tag: "type", tagValue: tag0 }, message: 'tag "type" must be string' };
|
|
2222
|
+
if (vErrors === null) {
|
|
2223
|
+
vErrors = [err50];
|
|
2224
|
+
} else {
|
|
2225
|
+
vErrors.push(err50);
|
|
2226
|
+
}
|
|
2227
|
+
errors++;
|
|
2228
|
+
}
|
|
2229
|
+
} else {
|
|
2230
|
+
const err51 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
2231
|
+
if (vErrors === null) {
|
|
2232
|
+
vErrors = [err51];
|
|
2233
|
+
} else {
|
|
2234
|
+
vErrors.push(err51);
|
|
2235
|
+
}
|
|
2236
|
+
errors++;
|
|
2237
|
+
}
|
|
2238
|
+
validate18.errors = vErrors;
|
|
2239
|
+
return errors === 0;
|
|
2240
|
+
}
|
|
2241
|
+
function validate17(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
2242
|
+
let vErrors = null;
|
|
2243
|
+
let errors = 0;
|
|
2244
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2245
|
+
if (data.title === void 0) {
|
|
2246
|
+
const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "title" }, message: "must have required property 'title'" };
|
|
2247
|
+
if (vErrors === null) {
|
|
2248
|
+
vErrors = [err0];
|
|
2249
|
+
} else {
|
|
2250
|
+
vErrors.push(err0);
|
|
2251
|
+
}
|
|
2252
|
+
errors++;
|
|
2253
|
+
}
|
|
2254
|
+
if (data.body === void 0) {
|
|
2255
|
+
const err1 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "body" }, message: "must have required property 'body'" };
|
|
2256
|
+
if (vErrors === null) {
|
|
2257
|
+
vErrors = [err1];
|
|
2258
|
+
} else {
|
|
2259
|
+
vErrors.push(err1);
|
|
2260
|
+
}
|
|
2261
|
+
errors++;
|
|
2262
|
+
}
|
|
2263
|
+
if (data.events === void 0) {
|
|
2264
|
+
const err2 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "events" }, message: "must have required property 'events'" };
|
|
2265
|
+
if (vErrors === null) {
|
|
2266
|
+
vErrors = [err2];
|
|
2267
|
+
} else {
|
|
2268
|
+
vErrors.push(err2);
|
|
2269
|
+
}
|
|
2270
|
+
errors++;
|
|
2271
|
+
}
|
|
2272
|
+
for (const key0 in data) {
|
|
2273
|
+
if (!(key0 === "title" || key0 === "body" || key0 === "code" || key0 === "events")) {
|
|
2274
|
+
const err3 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
2275
|
+
if (vErrors === null) {
|
|
2276
|
+
vErrors = [err3];
|
|
2277
|
+
} else {
|
|
2278
|
+
vErrors.push(err3);
|
|
2279
|
+
}
|
|
2280
|
+
errors++;
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
if (data.title !== void 0) {
|
|
2284
|
+
let data0 = data.title;
|
|
2285
|
+
if (typeof data0 === "string") {
|
|
2286
|
+
if (func3(data0) < 1) {
|
|
2287
|
+
const err4 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2288
|
+
if (vErrors === null) {
|
|
2289
|
+
vErrors = [err4];
|
|
2290
|
+
} else {
|
|
2291
|
+
vErrors.push(err4);
|
|
2292
|
+
}
|
|
2293
|
+
errors++;
|
|
2294
|
+
}
|
|
2295
|
+
} else {
|
|
2296
|
+
const err5 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2297
|
+
if (vErrors === null) {
|
|
2298
|
+
vErrors = [err5];
|
|
2299
|
+
} else {
|
|
2300
|
+
vErrors.push(err5);
|
|
2301
|
+
}
|
|
2302
|
+
errors++;
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
if (data.body !== void 0) {
|
|
2306
|
+
let data1 = data.body;
|
|
2307
|
+
if (typeof data1 === "string") {
|
|
2308
|
+
if (func3(data1) < 1) {
|
|
2309
|
+
const err6 = { instancePath: instancePath + "/body", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2310
|
+
if (vErrors === null) {
|
|
2311
|
+
vErrors = [err6];
|
|
2312
|
+
} else {
|
|
2313
|
+
vErrors.push(err6);
|
|
2314
|
+
}
|
|
2315
|
+
errors++;
|
|
2316
|
+
}
|
|
2317
|
+
} else {
|
|
2318
|
+
const err7 = { instancePath: instancePath + "/body", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2319
|
+
if (vErrors === null) {
|
|
2320
|
+
vErrors = [err7];
|
|
2321
|
+
} else {
|
|
2322
|
+
vErrors.push(err7);
|
|
2323
|
+
}
|
|
2324
|
+
errors++;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
if (data.code !== void 0) {
|
|
2328
|
+
let data2 = data.code;
|
|
2329
|
+
if (typeof data2 === "string") {
|
|
2330
|
+
if (func3(data2) < 1) {
|
|
2331
|
+
const err8 = { instancePath: instancePath + "/code", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2332
|
+
if (vErrors === null) {
|
|
2333
|
+
vErrors = [err8];
|
|
2334
|
+
} else {
|
|
2335
|
+
vErrors.push(err8);
|
|
2336
|
+
}
|
|
2337
|
+
errors++;
|
|
2338
|
+
}
|
|
2339
|
+
} else {
|
|
2340
|
+
const err9 = { instancePath: instancePath + "/code", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2341
|
+
if (vErrors === null) {
|
|
2342
|
+
vErrors = [err9];
|
|
2343
|
+
} else {
|
|
2344
|
+
vErrors.push(err9);
|
|
2345
|
+
}
|
|
2346
|
+
errors++;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
if (data.events !== void 0) {
|
|
2350
|
+
let data3 = data.events;
|
|
2351
|
+
if (Array.isArray(data3)) {
|
|
2352
|
+
const len0 = data3.length;
|
|
2353
|
+
for (let i0 = 0; i0 < len0; i0++) {
|
|
2354
|
+
if (!validate18(data3[i0], { instancePath: instancePath + "/events/" + i0, parentData: data3, parentDataProperty: i0, rootData })) {
|
|
2355
|
+
vErrors = vErrors === null ? validate18.errors : vErrors.concat(validate18.errors);
|
|
2356
|
+
errors = vErrors.length;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
} else {
|
|
2360
|
+
const err10 = { instancePath: instancePath + "/events", schemaPath: "#/properties/events/type", keyword: "type", params: { type: "array" }, message: "must be array" };
|
|
2361
|
+
if (vErrors === null) {
|
|
2362
|
+
vErrors = [err10];
|
|
2363
|
+
} else {
|
|
2364
|
+
vErrors.push(err10);
|
|
2365
|
+
}
|
|
2366
|
+
errors++;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
} else {
|
|
2370
|
+
const err11 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
2371
|
+
if (vErrors === null) {
|
|
2372
|
+
vErrors = [err11];
|
|
2373
|
+
} else {
|
|
2374
|
+
vErrors.push(err11);
|
|
2375
|
+
}
|
|
2376
|
+
errors++;
|
|
2377
|
+
}
|
|
2378
|
+
validate17.errors = vErrors;
|
|
2379
|
+
return errors === 0;
|
|
2380
|
+
}
|
|
2381
|
+
function validate23(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
2382
|
+
let vErrors = null;
|
|
2383
|
+
let errors = 0;
|
|
2384
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2385
|
+
if (data.lifelines === void 0) {
|
|
2386
|
+
const err0 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "lifelines" }, message: "must have required property 'lifelines'" };
|
|
2387
|
+
if (vErrors === null) {
|
|
2388
|
+
vErrors = [err0];
|
|
2389
|
+
} else {
|
|
2390
|
+
vErrors.push(err0);
|
|
2391
|
+
}
|
|
2392
|
+
errors++;
|
|
2393
|
+
}
|
|
2394
|
+
for (const key0 in data) {
|
|
2395
|
+
if (!(key0 === "lifelines")) {
|
|
2396
|
+
const err1 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
2397
|
+
if (vErrors === null) {
|
|
2398
|
+
vErrors = [err1];
|
|
2399
|
+
} else {
|
|
2400
|
+
vErrors.push(err1);
|
|
2401
|
+
}
|
|
2402
|
+
errors++;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
if (data.lifelines !== void 0) {
|
|
2406
|
+
let data0 = data.lifelines;
|
|
2407
|
+
if (Array.isArray(data0)) {
|
|
2408
|
+
if (data0.length < 1) {
|
|
2409
|
+
const err2 = { instancePath: instancePath + "/lifelines", schemaPath: "#/properties/lifelines/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
|
|
2410
|
+
if (vErrors === null) {
|
|
2411
|
+
vErrors = [err2];
|
|
2412
|
+
} else {
|
|
2413
|
+
vErrors.push(err2);
|
|
2414
|
+
}
|
|
2415
|
+
errors++;
|
|
2416
|
+
}
|
|
2417
|
+
const len0 = data0.length;
|
|
2418
|
+
for (let i0 = 0; i0 < len0; i0++) {
|
|
2419
|
+
let data1 = data0[i0];
|
|
2420
|
+
if (typeof data1 === "string") {
|
|
2421
|
+
if (!pattern0.test(data1)) {
|
|
2422
|
+
const err3 = { instancePath: instancePath + "/lifelines/" + i0, schemaPath: "#/definitions/id/pattern", keyword: "pattern", params: { pattern: "^[^\\s\\[\\]\u300C\u300D=:]+$" }, message: 'must match pattern "^[^\\s\\[\\]\u300C\u300D=:]+$"' };
|
|
2423
|
+
if (vErrors === null) {
|
|
2424
|
+
vErrors = [err3];
|
|
2425
|
+
} else {
|
|
2426
|
+
vErrors.push(err3);
|
|
2427
|
+
}
|
|
2428
|
+
errors++;
|
|
2429
|
+
}
|
|
2430
|
+
} else {
|
|
2431
|
+
const err4 = { instancePath: instancePath + "/lifelines/" + i0, schemaPath: "#/definitions/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2432
|
+
if (vErrors === null) {
|
|
2433
|
+
vErrors = [err4];
|
|
2434
|
+
} else {
|
|
2435
|
+
vErrors.push(err4);
|
|
2436
|
+
}
|
|
2437
|
+
errors++;
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
} else {
|
|
2441
|
+
const err5 = { instancePath: instancePath + "/lifelines", schemaPath: "#/properties/lifelines/type", keyword: "type", params: { type: "array" }, message: "must be array" };
|
|
2442
|
+
if (vErrors === null) {
|
|
2443
|
+
vErrors = [err5];
|
|
2444
|
+
} else {
|
|
2445
|
+
vErrors.push(err5);
|
|
2446
|
+
}
|
|
2447
|
+
errors++;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
} else {
|
|
2451
|
+
const err6 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
2452
|
+
if (vErrors === null) {
|
|
2453
|
+
vErrors = [err6];
|
|
2454
|
+
} else {
|
|
2455
|
+
vErrors.push(err6);
|
|
2456
|
+
}
|
|
2457
|
+
errors++;
|
|
2458
|
+
}
|
|
2459
|
+
validate23.errors = vErrors;
|
|
2460
|
+
return errors === 0;
|
|
2461
|
+
}
|
|
2462
|
+
function validate10(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) {
|
|
2463
|
+
let vErrors = null;
|
|
2464
|
+
let errors = 0;
|
|
2465
|
+
const _errs1 = errors;
|
|
2466
|
+
let valid0 = true;
|
|
2467
|
+
const _errs2 = errors;
|
|
2468
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2469
|
+
if (data.kind === void 0 && ("kind")) {
|
|
2470
|
+
const err0 = {};
|
|
2471
|
+
if (vErrors === null) {
|
|
2472
|
+
vErrors = [err0];
|
|
2473
|
+
} else {
|
|
2474
|
+
vErrors.push(err0);
|
|
2475
|
+
}
|
|
2476
|
+
errors++;
|
|
2477
|
+
} else {
|
|
2478
|
+
if (data.kind !== void 0) {
|
|
2479
|
+
if ("sequence" !== data.kind) {
|
|
2480
|
+
const err1 = {};
|
|
2481
|
+
if (vErrors === null) {
|
|
2482
|
+
vErrors = [err1];
|
|
2483
|
+
} else {
|
|
2484
|
+
vErrors.push(err1);
|
|
2485
|
+
}
|
|
2486
|
+
errors++;
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
var _valid0 = _errs2 === errors;
|
|
2492
|
+
errors = _errs1;
|
|
2493
|
+
if (vErrors !== null) {
|
|
2494
|
+
if (_errs1) {
|
|
2495
|
+
vErrors.length = _errs1;
|
|
2496
|
+
} else {
|
|
2497
|
+
vErrors = null;
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
let ifClause0;
|
|
2501
|
+
if (_valid0) {
|
|
2502
|
+
const _errs4 = errors;
|
|
2503
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2504
|
+
if (data.sequence === void 0) {
|
|
2505
|
+
const err2 = { instancePath, schemaPath: "#/then/required", keyword: "required", params: { missingProperty: "sequence" }, message: "must have required property 'sequence'" };
|
|
2506
|
+
if (vErrors === null) {
|
|
2507
|
+
vErrors = [err2];
|
|
2508
|
+
} else {
|
|
2509
|
+
vErrors.push(err2);
|
|
2510
|
+
}
|
|
2511
|
+
errors++;
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
var _valid0 = _errs4 === errors;
|
|
2515
|
+
valid0 = _valid0;
|
|
2516
|
+
ifClause0 = "then";
|
|
2517
|
+
} else {
|
|
2518
|
+
const _errs5 = errors;
|
|
2519
|
+
const _errs6 = errors;
|
|
2520
|
+
const _errs7 = errors;
|
|
2521
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2522
|
+
if (data.sequence === void 0 && ("sequence")) {
|
|
2523
|
+
const err3 = {};
|
|
2524
|
+
if (vErrors === null) {
|
|
2525
|
+
vErrors = [err3];
|
|
2526
|
+
} else {
|
|
2527
|
+
vErrors.push(err3);
|
|
2528
|
+
}
|
|
2529
|
+
errors++;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
var valid2 = _errs7 === errors;
|
|
2533
|
+
if (valid2) {
|
|
2534
|
+
const err4 = { instancePath, schemaPath: "#/else/not", keyword: "not", params: {}, message: "must NOT be valid" };
|
|
2535
|
+
if (vErrors === null) {
|
|
2536
|
+
vErrors = [err4];
|
|
2537
|
+
} else {
|
|
2538
|
+
vErrors.push(err4);
|
|
2539
|
+
}
|
|
2540
|
+
errors++;
|
|
2541
|
+
} else {
|
|
2542
|
+
errors = _errs6;
|
|
2543
|
+
if (vErrors !== null) {
|
|
2544
|
+
if (_errs6) {
|
|
2545
|
+
vErrors.length = _errs6;
|
|
2546
|
+
} else {
|
|
2547
|
+
vErrors = null;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
var _valid0 = _errs5 === errors;
|
|
2552
|
+
valid0 = _valid0;
|
|
2553
|
+
ifClause0 = "else";
|
|
2554
|
+
}
|
|
2555
|
+
if (!valid0) {
|
|
2556
|
+
const err5 = { instancePath, schemaPath: "#/if", keyword: "if", params: { failingKeyword: ifClause0 }, message: 'must match "' + ifClause0 + '" schema' };
|
|
2557
|
+
if (vErrors === null) {
|
|
2558
|
+
vErrors = [err5];
|
|
2559
|
+
} else {
|
|
2560
|
+
vErrors.push(err5);
|
|
2561
|
+
}
|
|
2562
|
+
errors++;
|
|
2563
|
+
}
|
|
2564
|
+
if (data && typeof data == "object" && !Array.isArray(data)) {
|
|
2565
|
+
if (data.version === void 0) {
|
|
2566
|
+
const err6 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "version" }, message: "must have required property 'version'" };
|
|
2567
|
+
if (vErrors === null) {
|
|
2568
|
+
vErrors = [err6];
|
|
2569
|
+
} else {
|
|
2570
|
+
vErrors.push(err6);
|
|
2571
|
+
}
|
|
2572
|
+
errors++;
|
|
2573
|
+
}
|
|
2574
|
+
if (data.kind === void 0) {
|
|
2575
|
+
const err7 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "kind" }, message: "must have required property 'kind'" };
|
|
2576
|
+
if (vErrors === null) {
|
|
2577
|
+
vErrors = [err7];
|
|
2578
|
+
} else {
|
|
2579
|
+
vErrors.push(err7);
|
|
2580
|
+
}
|
|
2581
|
+
errors++;
|
|
2582
|
+
}
|
|
2583
|
+
if (data.title === void 0) {
|
|
2584
|
+
const err8 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "title" }, message: "must have required property 'title'" };
|
|
2585
|
+
if (vErrors === null) {
|
|
2586
|
+
vErrors = [err8];
|
|
2587
|
+
} else {
|
|
2588
|
+
vErrors.push(err8);
|
|
2589
|
+
}
|
|
2590
|
+
errors++;
|
|
2591
|
+
}
|
|
2592
|
+
if (data.boxes === void 0) {
|
|
2593
|
+
const err9 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "boxes" }, message: "must have required property 'boxes'" };
|
|
2594
|
+
if (vErrors === null) {
|
|
2595
|
+
vErrors = [err9];
|
|
2596
|
+
} else {
|
|
2597
|
+
vErrors.push(err9);
|
|
2598
|
+
}
|
|
2599
|
+
errors++;
|
|
2600
|
+
}
|
|
2601
|
+
if (data.steps === void 0) {
|
|
2602
|
+
const err10 = { instancePath, schemaPath: "#/required", keyword: "required", params: { missingProperty: "steps" }, message: "must have required property 'steps'" };
|
|
2603
|
+
if (vErrors === null) {
|
|
2604
|
+
vErrors = [err10];
|
|
2605
|
+
} else {
|
|
2606
|
+
vErrors.push(err10);
|
|
2607
|
+
}
|
|
2608
|
+
errors++;
|
|
2609
|
+
}
|
|
2610
|
+
for (const key0 in data) {
|
|
2611
|
+
if (!func2.call(schema11.properties, key0)) {
|
|
2612
|
+
const err11 = { instancePath, schemaPath: "#/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
|
|
2613
|
+
if (vErrors === null) {
|
|
2614
|
+
vErrors = [err11];
|
|
2615
|
+
} else {
|
|
2616
|
+
vErrors.push(err11);
|
|
2617
|
+
}
|
|
2618
|
+
errors++;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
if (data.version !== void 0) {
|
|
2622
|
+
let data1 = data.version;
|
|
2623
|
+
if (!(typeof data1 == "number" && (!(data1 % 1) && !isNaN(data1)) && isFinite(data1))) {
|
|
2624
|
+
const err12 = { instancePath: instancePath + "/version", schemaPath: "#/properties/version/type", keyword: "type", params: { type: "integer" }, message: "must be integer" };
|
|
2625
|
+
if (vErrors === null) {
|
|
2626
|
+
vErrors = [err12];
|
|
2627
|
+
} else {
|
|
2628
|
+
vErrors.push(err12);
|
|
2629
|
+
}
|
|
2630
|
+
errors++;
|
|
2631
|
+
}
|
|
2632
|
+
if (typeof data1 == "number" && isFinite(data1)) {
|
|
2633
|
+
if (data1 < 1 || isNaN(data1)) {
|
|
2634
|
+
const err13 = { instancePath: instancePath + "/version", schemaPath: "#/properties/version/minimum", keyword: "minimum", params: { comparison: ">=", limit: 1 }, message: "must be >= 1" };
|
|
2635
|
+
if (vErrors === null) {
|
|
2636
|
+
vErrors = [err13];
|
|
2637
|
+
} else {
|
|
2638
|
+
vErrors.push(err13);
|
|
2639
|
+
}
|
|
2640
|
+
errors++;
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
if (data.kind !== void 0) {
|
|
2645
|
+
let data2 = data.kind;
|
|
2646
|
+
if (!(data2 === "sequence" || data2 === "architecture")) {
|
|
2647
|
+
const err14 = { instancePath: instancePath + "/kind", schemaPath: "#/properties/kind/enum", keyword: "enum", params: { allowedValues: schema11.properties.kind.enum }, message: "must be equal to one of the allowed values" };
|
|
2648
|
+
if (vErrors === null) {
|
|
2649
|
+
vErrors = [err14];
|
|
2650
|
+
} else {
|
|
2651
|
+
vErrors.push(err14);
|
|
2652
|
+
}
|
|
2653
|
+
errors++;
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
if (data.title !== void 0) {
|
|
2657
|
+
let data3 = data.title;
|
|
2658
|
+
if (typeof data3 === "string") {
|
|
2659
|
+
if (func3(data3) < 1) {
|
|
2660
|
+
const err15 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/minLength", keyword: "minLength", params: { limit: 1 }, message: "must NOT have fewer than 1 characters" };
|
|
2661
|
+
if (vErrors === null) {
|
|
2662
|
+
vErrors = [err15];
|
|
2663
|
+
} else {
|
|
2664
|
+
vErrors.push(err15);
|
|
2665
|
+
}
|
|
2666
|
+
errors++;
|
|
2667
|
+
}
|
|
2668
|
+
} else {
|
|
2669
|
+
const err16 = { instancePath: instancePath + "/title", schemaPath: "#/definitions/text/type", keyword: "type", params: { type: "string" }, message: "must be string" };
|
|
2670
|
+
if (vErrors === null) {
|
|
2671
|
+
vErrors = [err16];
|
|
2672
|
+
} else {
|
|
2673
|
+
vErrors.push(err16);
|
|
2674
|
+
}
|
|
2675
|
+
errors++;
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
if (data.view !== void 0) {
|
|
2679
|
+
let data4 = data.view;
|
|
2680
|
+
if (!(data4 === "fixed" || data4 === "follow")) {
|
|
2681
|
+
const err17 = { instancePath: instancePath + "/view", schemaPath: "#/properties/view/enum", keyword: "enum", params: { allowedValues: schema11.properties.view.enum }, message: "must be equal to one of the allowed values" };
|
|
2682
|
+
if (vErrors === null) {
|
|
2683
|
+
vErrors = [err17];
|
|
2684
|
+
} else {
|
|
2685
|
+
vErrors.push(err17);
|
|
2686
|
+
}
|
|
2687
|
+
errors++;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
if (data.regions !== void 0) {
|
|
2691
|
+
let data5 = data.regions;
|
|
2692
|
+
if (Array.isArray(data5)) {
|
|
2693
|
+
const len0 = data5.length;
|
|
2694
|
+
for (let i0 = 0; i0 < len0; i0++) {
|
|
2695
|
+
if (!validate11(data5[i0], { instancePath: instancePath + "/regions/" + i0, parentData: data5, parentDataProperty: i0, rootData })) {
|
|
2696
|
+
vErrors = vErrors === null ? validate11.errors : vErrors.concat(validate11.errors);
|
|
2697
|
+
errors = vErrors.length;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
} else {
|
|
2701
|
+
const err18 = { instancePath: instancePath + "/regions", schemaPath: "#/properties/regions/type", keyword: "type", params: { type: "array" }, message: "must be array" };
|
|
2702
|
+
if (vErrors === null) {
|
|
2703
|
+
vErrors = [err18];
|
|
2704
|
+
} else {
|
|
2705
|
+
vErrors.push(err18);
|
|
2706
|
+
}
|
|
2707
|
+
errors++;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
if (data.boxes !== void 0) {
|
|
2711
|
+
let data7 = data.boxes;
|
|
2712
|
+
if (Array.isArray(data7)) {
|
|
2713
|
+
if (data7.length < 1) {
|
|
2714
|
+
const err19 = { instancePath: instancePath + "/boxes", schemaPath: "#/properties/boxes/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
|
|
2715
|
+
if (vErrors === null) {
|
|
2716
|
+
vErrors = [err19];
|
|
2717
|
+
} else {
|
|
2718
|
+
vErrors.push(err19);
|
|
2719
|
+
}
|
|
2720
|
+
errors++;
|
|
2721
|
+
}
|
|
2722
|
+
const len1 = data7.length;
|
|
2723
|
+
for (let i1 = 0; i1 < len1; i1++) {
|
|
2724
|
+
if (!validate13(data7[i1], { instancePath: instancePath + "/boxes/" + i1, parentData: data7, parentDataProperty: i1, rootData })) {
|
|
2725
|
+
vErrors = vErrors === null ? validate13.errors : vErrors.concat(validate13.errors);
|
|
2726
|
+
errors = vErrors.length;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
} else {
|
|
2730
|
+
const err20 = { instancePath: instancePath + "/boxes", schemaPath: "#/properties/boxes/type", keyword: "type", params: { type: "array" }, message: "must be array" };
|
|
2731
|
+
if (vErrors === null) {
|
|
2732
|
+
vErrors = [err20];
|
|
2733
|
+
} else {
|
|
2734
|
+
vErrors.push(err20);
|
|
2735
|
+
}
|
|
2736
|
+
errors++;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
if (data.strip !== void 0) {
|
|
2740
|
+
if (!validate15(data.strip, { instancePath: instancePath + "/strip", parentData: data, parentDataProperty: "strip", rootData })) {
|
|
2741
|
+
vErrors = vErrors === null ? validate15.errors : vErrors.concat(validate15.errors);
|
|
2742
|
+
errors = vErrors.length;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
if (data.steps !== void 0) {
|
|
2746
|
+
let data10 = data.steps;
|
|
2747
|
+
if (Array.isArray(data10)) {
|
|
2748
|
+
if (data10.length < 1) {
|
|
2749
|
+
const err21 = { instancePath: instancePath + "/steps", schemaPath: "#/properties/steps/minItems", keyword: "minItems", params: { limit: 1 }, message: "must NOT have fewer than 1 items" };
|
|
2750
|
+
if (vErrors === null) {
|
|
2751
|
+
vErrors = [err21];
|
|
2752
|
+
} else {
|
|
2753
|
+
vErrors.push(err21);
|
|
2754
|
+
}
|
|
2755
|
+
errors++;
|
|
2756
|
+
}
|
|
2757
|
+
const len2 = data10.length;
|
|
2758
|
+
for (let i2 = 0; i2 < len2; i2++) {
|
|
2759
|
+
if (!validate17(data10[i2], { instancePath: instancePath + "/steps/" + i2, parentData: data10, parentDataProperty: i2, rootData })) {
|
|
2760
|
+
vErrors = vErrors === null ? validate17.errors : vErrors.concat(validate17.errors);
|
|
2761
|
+
errors = vErrors.length;
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
} else {
|
|
2765
|
+
const err22 = { instancePath: instancePath + "/steps", schemaPath: "#/properties/steps/type", keyword: "type", params: { type: "array" }, message: "must be array" };
|
|
2766
|
+
if (vErrors === null) {
|
|
2767
|
+
vErrors = [err22];
|
|
2768
|
+
} else {
|
|
2769
|
+
vErrors.push(err22);
|
|
2770
|
+
}
|
|
2771
|
+
errors++;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
if (data.sequence !== void 0) {
|
|
2775
|
+
if (!validate23(data.sequence, { instancePath: instancePath + "/sequence", parentData: data, parentDataProperty: "sequence", rootData })) {
|
|
2776
|
+
vErrors = vErrors === null ? validate23.errors : vErrors.concat(validate23.errors);
|
|
2777
|
+
errors = vErrors.length;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
} else {
|
|
2781
|
+
const err23 = { instancePath, schemaPath: "#/type", keyword: "type", params: { type: "object" }, message: "must be object" };
|
|
2782
|
+
if (vErrors === null) {
|
|
2783
|
+
vErrors = [err23];
|
|
2784
|
+
} else {
|
|
2785
|
+
vErrors.push(err23);
|
|
2786
|
+
}
|
|
2787
|
+
errors++;
|
|
2788
|
+
}
|
|
2789
|
+
validate10.errors = vErrors;
|
|
2790
|
+
return errors === 0;
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
// src/schema.ts
|
|
2794
|
+
var COLORS = ["blue", "amber", "green", "violet", "rose", "slate", "coin"];
|
|
2795
|
+
var EVENT_TYPES = ["edge", "action", "swap", "strip"];
|
|
2796
|
+
var NOT_ALLOWED = {
|
|
2797
|
+
"": { field: "sequence", kind: "sequence" },
|
|
2798
|
+
carry: { field: "text", kind: "tag" }
|
|
2799
|
+
};
|
|
2800
|
+
var escape = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
2801
|
+
function forbiddenOf(pattern) {
|
|
2802
|
+
const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
|
|
2803
|
+
if (inside === void 0) return void 0;
|
|
2804
|
+
const chars = inside.match(/\\.|[^\\]/gu) ?? [];
|
|
2805
|
+
return { space: chars.includes("\\s"), chars: chars.filter((char) => char !== "\\s").map((char) => char.replace(/^\\/u, "")) };
|
|
2806
|
+
}
|
|
2807
|
+
var branchesOf = (anyOf, errors) => errors.filter(
|
|
2808
|
+
(error) => error !== anyOf && error.schemaPath.startsWith(`${anyOf.schemaPath}/`) && (error.instancePath === anyOf.instancePath || error.instancePath.startsWith(`${anyOf.instancePath}/`))
|
|
2809
|
+
);
|
|
2810
|
+
function toFieldError(error, errors, m) {
|
|
2811
|
+
const params = error.params;
|
|
2812
|
+
const at2 = error.instancePath;
|
|
2813
|
+
switch (error.keyword) {
|
|
2814
|
+
case "additionalProperties": {
|
|
2815
|
+
const key = String(params.additionalProperty);
|
|
2816
|
+
return { pointer: `${at2}/${escape(key)}`, message: m.additionalProperties(key) };
|
|
2817
|
+
}
|
|
2818
|
+
case "required": {
|
|
2819
|
+
const key = String(params.missingProperty);
|
|
2820
|
+
return { pointer: `${at2}/${escape(key)}`, message: m.required(key) };
|
|
2821
|
+
}
|
|
2822
|
+
case "not": {
|
|
2823
|
+
const allowed = NOT_ALLOWED[at2.slice(at2.lastIndexOf("/") + 1)];
|
|
2824
|
+
return { pointer: allowed ? `${at2}/${allowed.field}` : at2, message: m.not(allowed) };
|
|
2825
|
+
}
|
|
2826
|
+
case "anyOf": {
|
|
2827
|
+
const branches = branchesOf(error, errors);
|
|
2828
|
+
const missing = branches.every((branch) => branch.keyword === "required") ? branches.map((branch) => String(branch.params.missingProperty)) : [];
|
|
2829
|
+
return { pointer: at2, message: m.anyOf(missing) };
|
|
2830
|
+
}
|
|
2831
|
+
case "discriminator": {
|
|
2832
|
+
const tag = String(params.tag);
|
|
2833
|
+
return { pointer: `${at2}/${escape(tag)}`, message: m.discriminator(tag, EVENT_TYPES) };
|
|
2834
|
+
}
|
|
2835
|
+
case "enum":
|
|
2836
|
+
return { pointer: at2, message: m.enum(params.allowedValues.map(String)) };
|
|
2837
|
+
case "type":
|
|
2838
|
+
return { pointer: at2, message: m.type(String(params.type)) };
|
|
2839
|
+
case "minLength":
|
|
2840
|
+
return { pointer: at2, message: m.minLength(Number(params.limit)) };
|
|
2841
|
+
case "pattern":
|
|
2842
|
+
return { pointer: at2, message: m.pattern(forbiddenOf(String(params.pattern))) };
|
|
2843
|
+
case "minItems":
|
|
2844
|
+
return { pointer: at2, message: m.minItems(Number(params.limit)) };
|
|
2845
|
+
case "minimum":
|
|
2846
|
+
return { pointer: at2, message: m.minimum(Number(params.limit)) };
|
|
2847
|
+
case "const":
|
|
2848
|
+
return { pointer: at2, message: m.const(String(params.allowedValue)) };
|
|
2849
|
+
case "oneOf":
|
|
2850
|
+
return { pointer: at2, message: m.oneOf };
|
|
2851
|
+
default:
|
|
2852
|
+
return { pointer: at2, message: error.message ?? error.keyword };
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
function validateDiagram(input, options = {}) {
|
|
2856
|
+
if (validate_diagram_default(input)) return { ok: true };
|
|
2857
|
+
const all = validate_diagram_default.errors ?? [];
|
|
2858
|
+
const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
|
|
2859
|
+
const m = FIELD_MESSAGES[options.lang ?? "ja"];
|
|
2860
|
+
const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m));
|
|
2861
|
+
return { ok: false, errors };
|
|
2862
|
+
}
|
|
2863
|
+
|
|
2864
|
+
// src/version.ts
|
|
2865
|
+
var FORMAT_VERSION = 1;
|
|
2866
|
+
function newerThanTool(input) {
|
|
2867
|
+
if (typeof input !== "object" || input === null) return void 0;
|
|
2868
|
+
const version = input.version;
|
|
2869
|
+
return typeof version === "number" && version > FORMAT_VERSION ? version : void 0;
|
|
2870
|
+
}
|
|
2871
|
+
var newerError = (version, lang) => ({
|
|
2872
|
+
pointer: "/version",
|
|
2873
|
+
message: FIELD_MESSAGES[lang].newer(version, FORMAT_VERSION)
|
|
2874
|
+
});
|
|
2875
|
+
function readDiagram(input, options = {}) {
|
|
2876
|
+
const newer = newerThanTool(input);
|
|
2877
|
+
if (newer !== void 0) return { ok: false, errors: [newerError(newer, options.lang ?? "ja")] };
|
|
2878
|
+
const checked = validateDiagram(input, options);
|
|
2879
|
+
if (!checked.ok) return checked;
|
|
2880
|
+
return { ok: true, diagram: input, warnings: [] };
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
// src/timeline.ts
|
|
2884
|
+
function plan(step) {
|
|
2885
|
+
const out = { edges: [], events: [], busy: 0 };
|
|
2886
|
+
let cursor = MOTION.edgeAt;
|
|
2887
|
+
let arrived;
|
|
2888
|
+
let changes = 0;
|
|
2889
|
+
step.events.forEach((event, e) => {
|
|
2890
|
+
if (event.type === "edge") {
|
|
2891
|
+
const carries = event.carry.kind !== "none";
|
|
2892
|
+
const a = cursor;
|
|
2893
|
+
const b = a + (carries ? MOTION.drawCarry : MOTION.draw);
|
|
2894
|
+
out.edges.push({ event: e, a, b, carries, coin: event.carry.kind === "coin", named: event.label !== void 0 });
|
|
2895
|
+
cursor = a + MOTION.stagger;
|
|
2896
|
+
arrived = b;
|
|
2897
|
+
changes = 0;
|
|
2898
|
+
out.busy = Math.max(out.busy, b);
|
|
2899
|
+
} else if (event.type === "action") {
|
|
2900
|
+
out.events.push({ event: e, at: cursor });
|
|
2901
|
+
out.busy = Math.max(out.busy, cursor + MOTION.action);
|
|
2902
|
+
cursor += MOTION.action;
|
|
2903
|
+
changes = 0;
|
|
2904
|
+
} else {
|
|
2905
|
+
const at2 = (arrived ?? cursor) + MOTION.change * changes++;
|
|
2906
|
+
out.events.push({ event: e, at: at2 });
|
|
2907
|
+
out.busy = Math.max(out.busy, at2);
|
|
2908
|
+
}
|
|
2909
|
+
});
|
|
2910
|
+
return out;
|
|
2911
|
+
}
|
|
2912
|
+
function buildTimeline(diagram) {
|
|
2913
|
+
const plans = diagram.steps.map(plan);
|
|
2914
|
+
const steps = [];
|
|
2915
|
+
let t = MOTION.intro;
|
|
2916
|
+
diagram.steps.forEach((step, s) => {
|
|
2917
|
+
const read2 = Math.min(MOTION.stepMax, Math.max(MOTION.stepMin, MOTION.stepBase + [...step.body].length * MOTION.perChar));
|
|
2918
|
+
const length = Math.max(read2, (plans[s]?.busy ?? 0) + MOTION.dwell);
|
|
2919
|
+
steps.push({ start: t, end: t + length });
|
|
2920
|
+
t += length;
|
|
2921
|
+
});
|
|
2922
|
+
const end = t;
|
|
2923
|
+
const total = Math.ceil(end + MOTION.outro);
|
|
2924
|
+
const last = total - MOTION.tail;
|
|
2925
|
+
const edges = [];
|
|
2926
|
+
const labels = [];
|
|
2927
|
+
const events = [];
|
|
2928
|
+
const departures = [];
|
|
2929
|
+
plans.forEach((p, s) => {
|
|
2930
|
+
const span = steps[s];
|
|
2931
|
+
const named = [];
|
|
2932
|
+
for (const edge2 of p.edges) {
|
|
2933
|
+
const a = span.start + edge2.a;
|
|
2934
|
+
edges.push({ step: s, event: edge2.event, start: a, drawn: span.start + edge2.b, end: span.end });
|
|
2935
|
+
if (edge2.carries) departures.push({ step: s, event: edge2.event, who: edge2.coin ? "coin" : "main", a, b: span.start + edge2.b });
|
|
2936
|
+
if (edge2.named) named.push({ step: s, event: edge2.event, start: a + MOTION.labelDelay, end: span.end });
|
|
2937
|
+
}
|
|
2938
|
+
named.forEach((label2, k) => {
|
|
2939
|
+
const later = named[k + 2];
|
|
2940
|
+
if (later) label2.end = Math.min(label2.end, later.start);
|
|
2941
|
+
});
|
|
2942
|
+
labels.push(...named);
|
|
2943
|
+
for (const event of p.events) events.push({ step: s, event: event.event, at: span.start + event.at });
|
|
2944
|
+
});
|
|
2945
|
+
const first = steps[0]?.start ?? 0;
|
|
2946
|
+
const hasMain = departures.some((d) => d.who === "main");
|
|
2947
|
+
const carriers = [];
|
|
2948
|
+
for (const who of ["main", "coin"]) {
|
|
2949
|
+
const list = departures.filter((d) => d.who === who);
|
|
2950
|
+
list.forEach((d, k) => {
|
|
2951
|
+
const next = list[k + 1];
|
|
2952
|
+
const waits = k === 0 && (who === "main" || !hasMain);
|
|
2953
|
+
carriers.push({
|
|
2954
|
+
step: d.step,
|
|
2955
|
+
event: d.event,
|
|
2956
|
+
who,
|
|
2957
|
+
depart: d.a,
|
|
2958
|
+
arrive: d.b,
|
|
2959
|
+
start: waits ? Math.min(first, d.a) : d.a,
|
|
2960
|
+
end: next ? Math.max(next.a, d.b) : last
|
|
2961
|
+
});
|
|
2962
|
+
});
|
|
2963
|
+
}
|
|
2964
|
+
carriers.sort((x, y) => x.depart - y.depart);
|
|
2965
|
+
return {
|
|
2966
|
+
total,
|
|
2967
|
+
last,
|
|
2968
|
+
steps,
|
|
2969
|
+
edges,
|
|
2970
|
+
carriers,
|
|
2971
|
+
labels,
|
|
2972
|
+
badges: steps.map((span, s) => ({ step: s, appears: span.start })),
|
|
2973
|
+
events,
|
|
2974
|
+
stills: steps.map((span) => span.end - MOTION.still)
|
|
2975
|
+
};
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
// src/render/icons.ts
|
|
2979
|
+
var ICONS = {
|
|
2980
|
+
app: "M -9 -7 h18 a2 2 0 0 1 2 2 v10 a2 2 0 0 1 -2 2 h-18 a2 2 0 0 1 -2 -2 v-10 a2 2 0 0 1 2 -2 z M -11 -2 h22",
|
|
2981
|
+
router: "M -9 -4 h16 M 3 -8 l4 4 l-4 4 M 9 5 h-16 M -3 1 l-4 4 l4 4",
|
|
2982
|
+
on: "M -7 7 L 7 -7 M -1 -7 h8 v8",
|
|
2983
|
+
off: "M -7 -7 L 7 7 M 7 -1 v8 h-8",
|
|
2984
|
+
pool: "M -9 -5 a9 3.5 0 1 0 18 0 a9 3.5 0 1 0 -18 0 M -9 -5 v10 a9 3.5 0 0 0 18 0 v-10 M -9 0 a9 3.5 0 0 0 18 0",
|
|
2985
|
+
db: "M -9 -5 a9 3.5 0 1 0 18 0 a9 3.5 0 1 0 -18 0 M -9 -5 v10 a9 3.5 0 0 0 18 0 v-10 M -9 0 a9 3.5 0 0 0 18 0",
|
|
2986
|
+
exe: "M -5 -8 L 7 0 L -5 8 Z",
|
|
2987
|
+
idx: "M -9 -7 h18 M -9 -2 h18 M -9 3 h18 M -9 8 h11",
|
|
2988
|
+
sign: "M -9 4 c 3 -9 5 -9 6 0 s 3 7 6 -2 s 3 -6 6 0",
|
|
2989
|
+
env: "M -8 -5.5 h16 v11 h-16 z M -8 -5.5 l8 6 l8 -6",
|
|
2990
|
+
lock: "M -5.5 -1 h11 v8 h-11 z M -3.5 -1 v-3 a3.5 3.5 0 0 1 7 0 v3",
|
|
2991
|
+
check: "M -5 0 l3.5 3.5 l6.5 -7",
|
|
2992
|
+
x: "M -5 -5 l10 10 M 5 -5 l-10 10",
|
|
2993
|
+
chain: "M -1.5 4.5 l-2 2 a3.5 3.5 0 0 1 -5 -5 l3 -3 a3.5 3.5 0 0 1 5 0 M 1.5 -4.5 l2 -2 a3.5 3.5 0 0 1 5 5 l-3 3 a3.5 3.5 0 0 1 -5 0 M -2.5 2.5 l5 -5",
|
|
2994
|
+
net: "M -1.3 -4.6 L -5.8 3 M 1.3 -4.6 L 5.8 3 M -4.3 5.5 H 4.3 M -2.2 -7 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0 M -9.2 5.5 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0 M 4.8 5.5 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0",
|
|
2995
|
+
user: "M -4 -4.5 a4 4 0 1 0 8 0 a4 4 0 1 0 -8 0 M -8 9 c0 -5 3.6 -7.5 8 -7.5 s8 2.5 8 7.5",
|
|
2996
|
+
server: "M -9 -8 h18 v7 h-18 z M -9 1 h18 v7 h-18 z M -5 -4.5 h0.01 M -5 4.5 h0.01",
|
|
2997
|
+
key: "M -9 0 a3.5 3.5 0 1 0 7 0 a3.5 3.5 0 1 0 -7 0 M -2 0 h10 M 5 0 v3.5 M 8 0 v2.5",
|
|
2998
|
+
shield: "M 0 -9 l8 3 v5 c0 5 -3.5 8 -8 10 c-4.5 -2 -8 -5 -8 -10 v-5 z",
|
|
2999
|
+
globe: "M -9 0 a9 9 0 1 0 18 0 a9 9 0 1 0 -18 0 M -9 0 h18 M 0 -9 c-4.5 4 -4.5 14 0 18 M 0 -9 c4.5 4 4.5 14 0 18",
|
|
3000
|
+
bolt: "M 2 -9 L -5 1 h5 l-2 8 l7 -10 h-5 z",
|
|
3001
|
+
doc: "M -6 -9 h8 l5 5 v13 h-13 z M 2 -9 v5 h5 M -3 1 h7 M -3 5 h5",
|
|
3002
|
+
box: "M -9 -4.5 l9 -4.5 l9 4.5 v9 l-9 4.5 l-9 -4.5 z M -9 -4.5 l9 4.5 l9 -4.5 M 0 0 v9",
|
|
3003
|
+
truck: "M -10 -6 h11 v10 h-11 z M 1 -2 h5 l3.5 3.5 v2.5 h-8.5 M -7.5 6.5 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0 M 3 6.5 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0",
|
|
3004
|
+
card: "M -9 -6.5 h18 a2 2 0 0 1 2 2 v9 a2 2 0 0 1 -2 2 h-18 a2 2 0 0 1 -2 -2 v-9 a2 2 0 0 1 2 -2 z M -11 -2 h22 M -7 3 h5",
|
|
3005
|
+
cart: "M -10 -8 h3 l3 11 h11 l2.5 -8 h-15.5 M -4.5 7.5 a1.5 1.5 0 1 0 3 0 a1.5 1.5 0 1 0 -3 0 M 5 7.5 a1.5 1.5 0 1 0 3 0 a1.5 1.5 0 1 0 -3 0",
|
|
3006
|
+
clock: "M -9 0 a9 9 0 1 0 18 0 a9 9 0 1 0 -18 0 M 0 -5 v5 l3.5 2.5",
|
|
3007
|
+
branch: "M -4 -4.5 v9 M 5 0.5 c0 4 -9 3 -9 6.5 M -6.2 -7 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0 M -6.2 7 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0 M 2.8 -2 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0",
|
|
3008
|
+
cloud: "M -7 6 h13 a4.5 4.5 0 0 0 0.5 -9 a6 6 0 0 0 -11.5 -1 a4.5 4.5 0 0 0 -2 10 z",
|
|
3009
|
+
refresh: "M 7 -3 a7.5 7.5 0 1 0 0.5 5 M 7.5 -8 v5 h-5",
|
|
3010
|
+
layers: "M 0 -8 l9 4.5 l-9 4.5 l-9 -4.5 z M -9 2.5 l9 4.5 l9 -4.5",
|
|
3011
|
+
code: "M -4 -6 l-5 6 l5 6 M 4 -6 l5 6 l-5 6",
|
|
3012
|
+
paint: "M -8 8 c 0 -3 2 -5 4.5 -5 l 9 -9 l 3.5 3.5 l -9 9 c 0 2.5 -2 4.5 -5 4.5 z",
|
|
3013
|
+
block: "M -9 -7 h18 a2 2 0 0 1 2 2 v10 a2 2 0 0 1 -2 2 h-18 a2 2 0 0 1 -2 -2 v-10 a2 2 0 0 1 2 -2 z M -11 -2.5 h22 M -6 2.5 h8"
|
|
3014
|
+
};
|
|
3015
|
+
|
|
3016
|
+
// src/render/parts.ts
|
|
3017
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
3018
|
+
var r1 = (v) => Math.round(v * 100) / 100;
|
|
3019
|
+
var cs = (k) => k === "coin" ? "--c:var(--coin);--ct:var(--coint)" : `--c:var(--c-${k});--ct:var(--t-${k})`;
|
|
3020
|
+
function glyph(name, x, y, scale, cls = "dg-gl") {
|
|
3021
|
+
const d = name === void 0 ? void 0 : ICONS[name];
|
|
3022
|
+
return d ? `<path class="${cls}" transform="translate(${r1(x)} ${r1(y)}) scale(${scale})" d="${d}"/>` : "";
|
|
3023
|
+
}
|
|
3024
|
+
var pathOf = (points) => points.map(([x, y], i) => `${i === 0 ? "M" : "L"} ${r1(x)} ${r1(y)}`).join(" ");
|
|
3025
|
+
function arrowHead(points) {
|
|
3026
|
+
const [ex, ey] = points[points.length - 1];
|
|
3027
|
+
const [px, py] = points[points.length - 2];
|
|
3028
|
+
const len = Math.hypot(ex - px, ey - py) || 1;
|
|
3029
|
+
const dx = (ex - px) / len;
|
|
3030
|
+
const dy = (ey - py) / len;
|
|
3031
|
+
const { arrow: a, arrowHalf: h } = LOOK.edge;
|
|
3032
|
+
return `M ${r1(ex - dx * a - dy * h)} ${r1(ey - dy * a + dx * h)} L ${r1(ex)} ${r1(ey)} L ${r1(ex - dx * a + dy * h)} ${r1(ey - dy * a - dx * h)}`;
|
|
3033
|
+
}
|
|
3034
|
+
function rangeKf(m, ranges2) {
|
|
3035
|
+
const pts = [[0, { opacity: 0 }]];
|
|
3036
|
+
for (const [a, b] of ranges2) pts.push([a, { opacity: 0 }, EASE.out], [a + MOTION.fade, { opacity: 1 }], [b - 0.1, { opacity: 1 }, EASE.inOut], [b + 0.25, { opacity: 0 }]);
|
|
3037
|
+
pts.push([m.total, { opacity: 0 }]);
|
|
3038
|
+
return m.kf(pts);
|
|
3039
|
+
}
|
|
3040
|
+
function activeKf(ctx, on) {
|
|
3041
|
+
const ranges2 = [];
|
|
3042
|
+
for (let k = 0; k < on.length; ) {
|
|
3043
|
+
let e = k;
|
|
3044
|
+
while (e + 1 < on.length && on[e + 1] === on[e] + 1) e++;
|
|
3045
|
+
ranges2.push([ctx.t.steps[on[k]].start, ctx.t.steps[on[e]].end]);
|
|
3046
|
+
k = e + 1;
|
|
3047
|
+
}
|
|
3048
|
+
return rangeKf(ctx.m, ranges2);
|
|
3049
|
+
}
|
|
3050
|
+
function band(region) {
|
|
3051
|
+
const { radius, icon, iconRadius, iconScale, nameY, line } = LOOK.region;
|
|
3052
|
+
const { x, y } = region.header;
|
|
3053
|
+
const lines = region.lines.map((t, k) => `<text class="dg-bz" x="${r1(x)}" y="${r1(region.y + nameY + k * line)}">${esc(t)}</text>`).join("");
|
|
3054
|
+
const note = region.note ? `<text class="dg-bx" x="${r1(x)}" y="${r1(region.y + nameY + region.lines.length * line + 1)}">${esc(region.note)}</text>` : "";
|
|
3055
|
+
const mark = region.icon && ICONS[region.icon] ? `<rect class="dg-bi" x="${r1(x)}" y="${r1(y)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(region.icon, x + icon / 2, y + icon / 2, iconScale)}` : "";
|
|
3056
|
+
return `<g style="${cs(region.color)}"><rect class="dg-band" x="${r1(region.x + 0.5)}" y="${r1(region.y + 0.5)}" width="${r1(region.w - 1)}" height="${r1(region.h - 1)}" rx="${radius}"/>${mark}${lines}${note}</g>`;
|
|
3057
|
+
}
|
|
3058
|
+
function card(box, ctx, on, changes) {
|
|
3059
|
+
const { m, sh } = ctx;
|
|
3060
|
+
const { radius, icon, iconRadius, iconScale, iconY, nameY, subY } = LOOK.box;
|
|
3061
|
+
const seq = [[0, box.sub ?? "", "dg-ss"], ...changes];
|
|
3062
|
+
const subs = seq.map(([t, text2, cls], k) => {
|
|
3063
|
+
const next = seq[k + 1]?.[0];
|
|
3064
|
+
const anim = k === 0 ? next === void 0 ? "" : m.until(next - MOTION.untilFade) : next === void 0 ? m.rise(t) : m.rise(t, next - MOTION.untilFade);
|
|
3065
|
+
if (text2 === "") return "";
|
|
3066
|
+
return `<g${anim ? ` class="dg-a" style="${anim}"` : ""}><text class="${cls}" x="${r1(box.cx)}" y="${r1(box.cy + subY)}" text-anchor="middle">${esc(text2)}</text></g>`;
|
|
3067
|
+
}).join("");
|
|
3068
|
+
const act = on.length > 0 ? activeKf(ctx, on) : void 0;
|
|
3069
|
+
const rect = (cls, extra = "") => `<rect class="${cls}" x="${r1(box.x)}" y="${r1(box.y)}" width="${r1(box.w)}" height="${box.h}" rx="${radius}"${extra}/>`;
|
|
3070
|
+
const mark = box.icon && ICONS[box.icon] ? `<rect class="dg-ic" x="${r1(box.cx - icon / 2)}" y="${r1(box.cy + iconY - icon / 2)}" width="${icon}" height="${icon}" rx="${iconRadius}"/>${glyph(box.icon, box.cx, box.cy + iconY, iconScale)}` : "";
|
|
3071
|
+
return `<g style="${cs(box.color)}">${act ? `<g class="dg-a" style="${act}">${rect("dg-halo")}</g>` : ""}${rect("dg-st", ` ${sh}`)}${act ? `<g class="dg-a" style="${act}">${rect("dg-on")}</g>` : ""}${mark}<text class="dg-sn" x="${r1(box.cx)}" y="${r1(box.cy + nameY)}" text-anchor="middle">${esc(box.name)}</text>${subs}</g>`;
|
|
3072
|
+
}
|
|
3073
|
+
function lifeline(x, y1, y2) {
|
|
3074
|
+
return `<line class="dg-ll" x1="${r1(x)}" y1="${r1(y1)}" x2="${r1(x)}" y2="${r1(y2)}"/>`;
|
|
3075
|
+
}
|
|
3076
|
+
function edge(e, time, ctx) {
|
|
3077
|
+
const { m } = ctx;
|
|
3078
|
+
const d = pathOf(e.points);
|
|
3079
|
+
const head = arrowHead(e.points);
|
|
3080
|
+
const { start: a, drawn: b, end } = time;
|
|
3081
|
+
const tail = [
|
|
3082
|
+
[end, { opacity: 1 }, EASE.inOut],
|
|
3083
|
+
[end + 0.4, { opacity: 0.45 }],
|
|
3084
|
+
[ctx.end + 0.3, { opacity: 0.45 }, EASE.inOut],
|
|
3085
|
+
[ctx.end + 1, { opacity: 0.95 }],
|
|
3086
|
+
[m.last, { opacity: 0.95 }, EASE.inOut],
|
|
3087
|
+
[m.total, { opacity: 0 }]
|
|
3088
|
+
];
|
|
3089
|
+
const line = m.kf([
|
|
3090
|
+
[0, { opacity: 0, "stroke-dashoffset": 1 }],
|
|
3091
|
+
[a, { opacity: 0, "stroke-dashoffset": 1 }, EASE.inOut],
|
|
3092
|
+
[a + 0.05, { opacity: 1 }],
|
|
3093
|
+
[b, { "stroke-dashoffset": 0 }],
|
|
3094
|
+
[m.last, { "stroke-dashoffset": 0 }],
|
|
3095
|
+
[m.total, { "stroke-dashoffset": 1 }],
|
|
3096
|
+
...tail
|
|
3097
|
+
]);
|
|
3098
|
+
const hk = m.kf([[0, { opacity: 0 }], [b - 0.05, { opacity: 0 }], [b, { opacity: 1 }], ...tail]);
|
|
3099
|
+
const run = -(end - b) * 26;
|
|
3100
|
+
const flow = m.kf([
|
|
3101
|
+
[0, { opacity: 0, "stroke-dashoffset": 0 }],
|
|
3102
|
+
[b, { opacity: 0, "stroke-dashoffset": 0 }],
|
|
3103
|
+
[b + 0.25, { opacity: 0.9 }],
|
|
3104
|
+
[end - 0.1, { opacity: 0.9 }, EASE.inOut],
|
|
3105
|
+
[end + 0.2, { opacity: 0, "stroke-dashoffset": run }],
|
|
3106
|
+
[m.total, { opacity: 0, "stroke-dashoffset": run }]
|
|
3107
|
+
]);
|
|
3108
|
+
return {
|
|
3109
|
+
base: `<path class="dg-e" d="${d}"/><path class="dg-eh" d="${head}"/>`,
|
|
3110
|
+
lit: `<g style="${cs(e.color)}"><path class="dg-e-on dg-a" pathLength="1" d="${d}" style="${line}"/><path class="dg-eh-on dg-a" d="${head}" style="${hk}"/><path class="dg-flow dg-a" d="${d}" style="${flow}"/></g>`
|
|
3111
|
+
};
|
|
3112
|
+
}
|
|
3113
|
+
function label(l, time, ctx) {
|
|
3114
|
+
const ja3 = l.family === "sans" ? " dg-capj" : "";
|
|
3115
|
+
const { radius } = LOOK.label;
|
|
3116
|
+
return `<g class="dg-cap${ja3} dg-a" style="${cs(l.color)};${ctx.m.rise(time.start, time.end, true)}"><rect x="${r1(l.x)}" y="${r1(l.y)}" width="${r1(l.w)}" height="${l.h}" rx="${radius}"/><text x="${r1(l.x + l.w / 2)}" y="${r1(l.y + l.h / 2 + LOOK.baseline.label)}" text-anchor="middle">${esc(l.text)}</text></g>`;
|
|
3117
|
+
}
|
|
3118
|
+
function action(a, at2, until, ctx) {
|
|
3119
|
+
return `<g class="dg-act dg-a" style="${cs(a.color)};${ctx.m.rise(at2, until, true)}"><rect x="${r1(a.x)}" y="${r1(a.y)}" width="${r1(a.w)}" height="${a.h}" rx="${LOOK.action.radius}"/><text x="${r1(a.x + a.w / 2)}" y="${r1(a.y + a.h / 2 + LOOK.baseline.action)}" text-anchor="middle">${esc(a.text)}</text></g>`;
|
|
3120
|
+
}
|
|
3121
|
+
function carrierShape(e, sh) {
|
|
3122
|
+
const C = LOOK.carrier;
|
|
3123
|
+
if (e.carry.kind === "coin") return `<circle class="dg-coin" r="${C.coinR}"/><circle class="dg-coin-in" r="${C.coinIn}"/>`;
|
|
3124
|
+
if (e.carry.kind === "tag") {
|
|
3125
|
+
const text2 = e.carry.text;
|
|
3126
|
+
const ja3 = hasWide(text2);
|
|
3127
|
+
const w = textWidth(text2, ja3 ? TYPE.carrierJa : TYPE.carrier) + C.tagPadX * 2;
|
|
3128
|
+
return `<rect class="dg-car" x="${r1(-w / 2)}" y="${ -18 / 2}" width="${r1(w)}" height="${C.tagH}" rx="${C.tagH / 2}" ${sh}/><text class="dg-car-t${ja3 ? " dg-car-tj" : ""}" y="${LOOK.baseline.carrier}" text-anchor="middle">${esc(text2)}</text>`;
|
|
3129
|
+
}
|
|
3130
|
+
return `<rect class="dg-env" x="${ -24 / 2}" y="${ -17 / 2}" width="${C.envW}" height="${C.envH}" rx="3" ${sh}/><path class="dg-env-in" d="M -8 -4.5 L 0 1.5 L 8 -4.5"/>`;
|
|
3131
|
+
}
|
|
3132
|
+
var easeInOut = (t) => t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
|
|
3133
|
+
function carrier(e, time, ctx) {
|
|
3134
|
+
const { m } = ctx;
|
|
3135
|
+
const n = LOOK.carrier.samples;
|
|
3136
|
+
const length = pathLength(e.points);
|
|
3137
|
+
const { depart: a, arrive: b, start: from, end: gone } = time;
|
|
3138
|
+
const path = [];
|
|
3139
|
+
for (let k = 0; k <= n; k++) {
|
|
3140
|
+
const [x, y] = along(e.points, easeInOut(k / n) * length);
|
|
3141
|
+
path.push([a + (b - a) * k / n, x, y]);
|
|
3142
|
+
}
|
|
3143
|
+
const first = path[0];
|
|
3144
|
+
const lastPoint = path[path.length - 1];
|
|
3145
|
+
const rest = e.settle ?? [lastPoint[1], lastPoint[2]];
|
|
3146
|
+
const pts = [[0, first[1], first[2]], ...path];
|
|
3147
|
+
if (e.settle) pts.push([Math.min(b + 0.3, Math.max(gone, b + 0.01)), rest[0], rest[1]]);
|
|
3148
|
+
pts.push([gone, rest[0], rest[1]], [m.total, rest[0], rest[1]]);
|
|
3149
|
+
const fade = gone < m.last ? 0.05 : 0.18;
|
|
3150
|
+
return `<g class="dg-a" style="${m.move(pts, m.blink(from + 0.02, gone, fade))}">${carrierShape(e, ctx.sh)}</g>`;
|
|
3151
|
+
}
|
|
3152
|
+
function badge(b, ctx) {
|
|
3153
|
+
const { m } = ctx;
|
|
3154
|
+
const span = ctx.t.steps[b.step];
|
|
3155
|
+
const a = span.start;
|
|
3156
|
+
const e = span.end;
|
|
3157
|
+
const { r, ring: rr } = LOOK.badge;
|
|
3158
|
+
const fill = m.kf([
|
|
3159
|
+
[0, { opacity: 0, transform: "scale(.5)" }],
|
|
3160
|
+
[a, { opacity: 0, transform: "scale(.5)" }, EASE.pop],
|
|
3161
|
+
[a + 0.35, { opacity: 1, transform: "scale(1)" }],
|
|
3162
|
+
[e, { opacity: 1, transform: "scale(1)" }, EASE.inOut],
|
|
3163
|
+
[e + 0.4, { opacity: 0, transform: "scale(1)" }],
|
|
3164
|
+
[m.total, { opacity: 0, transform: "scale(.5)" }]
|
|
3165
|
+
]);
|
|
3166
|
+
const past = m.kf([[0, { opacity: 0 }], [e, { opacity: 0 }, EASE.inOut], [e + 0.4, { opacity: 1 }], [m.last, { opacity: 1 }, EASE.inOut], [m.total, { opacity: 0 }]]);
|
|
3167
|
+
const ring = m.kf([
|
|
3168
|
+
[0, { opacity: 0, transform: "scale(1)" }],
|
|
3169
|
+
[a + 0.05, { opacity: 0, transform: "scale(1)" }],
|
|
3170
|
+
[a + 0.1, { opacity: 0.7, transform: "scale(1)" }, EASE.out],
|
|
3171
|
+
[a + 0.9, { opacity: 0, transform: "scale(2.3)" }],
|
|
3172
|
+
[m.total, { opacity: 0, transform: "scale(1)" }]
|
|
3173
|
+
]);
|
|
3174
|
+
const x = r1(b.x);
|
|
3175
|
+
const y = r1(b.y);
|
|
3176
|
+
const ty = r1(b.y + LOOK.baseline.badge);
|
|
3177
|
+
const no = b.step + 1;
|
|
3178
|
+
return `<g class="dg-bd" data-step="${b.step}" style="${cs(b.color)}"><circle class="dg-bdr dg-popc dg-a" cx="${x}" cy="${y}" r="${rr}" style="${ring}"/><g class="dg-a" style="${past}"><circle class="dg-bdp" cx="${x}" cy="${y}" r="${rr}"/><text class="dg-bdpt" x="${x}" y="${ty}" text-anchor="middle">${no}</text></g><g class="dg-popc dg-a" style="${fill}"><circle class="dg-bdf" cx="${x}" cy="${y}" r="${r}"/><text class="dg-bdft" x="${x}" y="${ty}" text-anchor="middle">${no}</text></g></g>`;
|
|
3179
|
+
}
|
|
3180
|
+
function strip(s, changes, ctx) {
|
|
3181
|
+
const { m, sh } = ctx;
|
|
3182
|
+
const S2 = LOOK.strip;
|
|
3183
|
+
const my = s.y + S2.h / 2;
|
|
3184
|
+
const parts = [
|
|
3185
|
+
`<rect class="dg-strip" x="${r1(s.x + 0.5)}" y="${r1(s.y + 0.5)}" width="${r1(s.w - 1)}" height="${r1(s.h - 1)}" rx="${LOOK.region.radius}" ${sh}/>`,
|
|
3186
|
+
`<g style="${cs("slate")}"><rect class="dg-bi" x="${r1(s.x + S2.pad)}" y="${r1(my - S2.icon / 2)}" width="${S2.icon}" height="${S2.icon}" rx="${LOOK.box.iconRadius}"/>${glyph("env", s.x + S2.pad + S2.icon / 2, my, 0.78)}</g>`,
|
|
3187
|
+
`<text class="dg-sh" x="${r1(s.x + S2.titleX)}" y="${r1(my + LOOK.baseline.stripTitle)}">${esc(s.title)}</text>`
|
|
3188
|
+
];
|
|
3189
|
+
s.fields.forEach((field, i) => {
|
|
3190
|
+
const prev = s.fields[i - 1];
|
|
3191
|
+
if (prev && prev.y === field.y) {
|
|
3192
|
+
const sx = field.x - S2.fieldGap / 2;
|
|
3193
|
+
parts.push(`<line class="dg-sep" x1="${r1(sx)}" y1="${r1(field.y + S2.sepInset)}" x2="${r1(sx)}" y2="${r1(field.y + S2.h - S2.sepInset)}"/>`);
|
|
3194
|
+
}
|
|
3195
|
+
parts.push(`<text class="dg-fl" x="${r1(field.x)}" y="${r1(field.y + S2.nameY)}">${esc(field.name)}</text>`);
|
|
3196
|
+
const list = changes.get(field.name) ?? [];
|
|
3197
|
+
const values = list.filter((c) => c.value !== void 0);
|
|
3198
|
+
const tags = list.filter((c) => c.tag !== void 0);
|
|
3199
|
+
values.forEach((c, k) => {
|
|
3200
|
+
const next = values[k + 1]?.at;
|
|
3201
|
+
const value = c.value;
|
|
3202
|
+
const anim = next === void 0 ? m.rise(c.at) : m.rise(c.at, next - MOTION.untilFade);
|
|
3203
|
+
parts.push(`<g class="dg-a" style="${anim}"><text class="${hasWide(value) ? "dg-fvj" : "dg-fv"}" x="${r1(field.x)}" y="${r1(field.y + S2.valueY)}">${esc(value)}</text></g>`);
|
|
3204
|
+
});
|
|
3205
|
+
tags.forEach((c, k) => {
|
|
3206
|
+
const next = tags[k + 1]?.at;
|
|
3207
|
+
const tag = c.tag;
|
|
3208
|
+
const shown = [...values].reverse().find((v) => v.at <= c.at + 1e-9)?.value;
|
|
3209
|
+
const x = field.x + (shown ? textWidth(shown, hasWide(shown) ? TYPE.fieldValueJa : TYPE.fieldValue) + S2.tagGap : 0);
|
|
3210
|
+
const w = textWidth(tag, TYPE.tag) + S2.tagPadX * 2;
|
|
3211
|
+
const y = field.y + S2.valueY - S2.tagH / 2 - LOOK.baseline.tag;
|
|
3212
|
+
parts.push(
|
|
3213
|
+
`<g class="dg-tg dg-popc dg-a" style="${cs(c.color)};${next === void 0 ? m.pop(c.at) : m.pop(c.at, next - MOTION.untilFade)}"><rect x="${r1(x)}" y="${r1(y)}" width="${r1(w)}" height="${S2.tagH}" rx="${S2.tagH / 2}"/><text x="${r1(x + w / 2)}" y="${r1(y + S2.tagH / 2 + LOOK.baseline.tag)}" text-anchor="middle">${esc(tag)}</text></g>`
|
|
3214
|
+
);
|
|
3215
|
+
});
|
|
3216
|
+
});
|
|
3217
|
+
return parts.join("");
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
// src/render/motion.ts
|
|
3221
|
+
var r2 = (v) => Math.round(v * 100) / 100;
|
|
3222
|
+
var Motion = class {
|
|
3223
|
+
constructor(prefix, total, last) {
|
|
3224
|
+
this.prefix = prefix;
|
|
3225
|
+
this.total = total;
|
|
3226
|
+
this.last = last;
|
|
3227
|
+
}
|
|
3228
|
+
prefix;
|
|
3229
|
+
total;
|
|
3230
|
+
last;
|
|
3231
|
+
frames = [];
|
|
3232
|
+
count = 0;
|
|
3233
|
+
pct(t) {
|
|
3234
|
+
return +(Math.min(Math.max(t, 0), this.total) / this.total * 100).toFixed(3);
|
|
3235
|
+
}
|
|
3236
|
+
/** keyframes を 1 つ足し、その名前を付ける style の字を返す。 */
|
|
3237
|
+
kf(points) {
|
|
3238
|
+
const name = `${this.prefix}-${this.count++}`;
|
|
3239
|
+
const at2 = /* @__PURE__ */ new Map();
|
|
3240
|
+
for (const [t, props, ease] of [...points].sort((a, b) => a[0] - b[0])) {
|
|
3241
|
+
const p = this.pct(t);
|
|
3242
|
+
const cur = at2.get(p) ?? { props: {} };
|
|
3243
|
+
Object.assign(cur.props, props);
|
|
3244
|
+
if (ease) cur.ease = ease;
|
|
3245
|
+
at2.set(p, cur);
|
|
3246
|
+
}
|
|
3247
|
+
const body = [...at2].map(([p, { props, ease }]) => {
|
|
3248
|
+
const d = Object.entries(props).map(([k, v]) => `${k}:${v}`);
|
|
3249
|
+
if (ease) d.push(`animation-timing-function:${ease}`);
|
|
3250
|
+
return `${p}%{${d.join(";")}}`;
|
|
3251
|
+
}).join("");
|
|
3252
|
+
this.frames.push(`@keyframes ${name}{${body}}`);
|
|
3253
|
+
return `animation-name:${name}`;
|
|
3254
|
+
}
|
|
3255
|
+
/** `a` で出て `b` から消える。`within` を立てると `b` までに消え終わる。 */
|
|
3256
|
+
vis(a, b = this.last, o = {}) {
|
|
3257
|
+
const f = o.f ?? MOTION.fade;
|
|
3258
|
+
const on = o.on ?? {};
|
|
3259
|
+
const off = o.off ?? {};
|
|
3260
|
+
const out = o.within ? Math.max(a + f, b - f) : b;
|
|
3261
|
+
return this.kf([
|
|
3262
|
+
[0, { opacity: 0, ...off }],
|
|
3263
|
+
[a, { opacity: 0, ...off }, o.ein ?? EASE.out],
|
|
3264
|
+
[a + f, { opacity: 1, ...on }],
|
|
3265
|
+
[out, { opacity: 1, ...on }, EASE.inOut],
|
|
3266
|
+
[Math.min(out + f, this.total), { opacity: 0, ...off }],
|
|
3267
|
+
[this.total, { opacity: 0, ...off }]
|
|
3268
|
+
]);
|
|
3269
|
+
}
|
|
3270
|
+
/** 少し下から浮いて出る。 */
|
|
3271
|
+
rise(a, b = this.last, within = false) {
|
|
3272
|
+
return this.vis(a, b, { on: { transform: "translateY(0)" }, off: { transform: `translateY(${LOOK.rise}px)` }, within });
|
|
3273
|
+
}
|
|
3274
|
+
/** 小さな所から弾んで出る。 */
|
|
3275
|
+
pop(a, b = this.last) {
|
|
3276
|
+
return this.vis(a, b, { f: MOTION.popFade, ein: EASE.pop, on: { transform: "scale(1)" }, off: { transform: `scale(${LOOK.popFrom})` } });
|
|
3277
|
+
}
|
|
3278
|
+
/** 初めから出ていて `b` で消える。 */
|
|
3279
|
+
until(b) {
|
|
3280
|
+
const f = MOTION.untilFade;
|
|
3281
|
+
return this.kf([
|
|
3282
|
+
[0, { opacity: 1 }],
|
|
3283
|
+
[b, { opacity: 1 }, EASE.inOut],
|
|
3284
|
+
[b + f, { opacity: 0 }],
|
|
3285
|
+
[this.last, { opacity: 0 }],
|
|
3286
|
+
[this.total, { opacity: 1 }]
|
|
3287
|
+
]);
|
|
3288
|
+
}
|
|
3289
|
+
/** 点を辿って動く。`[時刻, x, y, 大きさ, 次の点までの緩急]` の並び。 */
|
|
3290
|
+
move(points, extra = []) {
|
|
3291
|
+
return this.kf(
|
|
3292
|
+
points.map(([t, x, y, s = 1, ease]) => [t, { transform: `translate(${r2(x)}px,${r2(y)}px) scale(${s})` }, ease]).concat(extra)
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
/** `a` から `b` まで見え、`fade` 秒で消える。 */
|
|
3296
|
+
blink(a, b, fade) {
|
|
3297
|
+
return [
|
|
3298
|
+
[0, { opacity: 0 }],
|
|
3299
|
+
[a - 0.01, { opacity: 0 }],
|
|
3300
|
+
[a, { opacity: 1 }],
|
|
3301
|
+
[b, { opacity: 1 }],
|
|
3302
|
+
[b + fade, { opacity: 0 }],
|
|
3303
|
+
[this.total, { opacity: 0 }]
|
|
3304
|
+
];
|
|
3305
|
+
}
|
|
3306
|
+
};
|
|
3307
|
+
|
|
3308
|
+
// src/render/svg.ts
|
|
3309
|
+
var font = (t) => `font:${t.weight} ${t.size}px var(--${t.family})`;
|
|
3310
|
+
var mix = (pct, base = "var(--surf)") => `color-mix(in srgb,var(--c) ${pct}%,${base})`;
|
|
3311
|
+
var S = LOOK.stroke;
|
|
3312
|
+
var X = LOOK.mix;
|
|
3313
|
+
var PART_CSS = [
|
|
3314
|
+
".dg{display:block;width:100%;height:auto;overflow:visible}",
|
|
3315
|
+
".dg .dg-a{animation-duration:var(--T);animation-timing-function:linear;animation-iteration-count:infinite;animation-fill-mode:both;animation-delay:calc(var(--at,0) * -1s);animation-play-state:var(--play,running)}",
|
|
3316
|
+
".dg .dg-popc{transform-box:fill-box;transform-origin:center}",
|
|
3317
|
+
".dg-bg{fill:var(--bg)}",
|
|
3318
|
+
".dg-band{fill:color-mix(in srgb,var(--c) var(--tint),var(--bg));stroke:color-mix(in srgb,var(--c) var(--edge),transparent)}",
|
|
3319
|
+
`.dg-bi{fill:${mix(X.regionIcon)};stroke:${mix(X.regionIconEdge, "transparent")}}`,
|
|
3320
|
+
`.dg-bz{${font(TYPE.regionName)};fill:var(--ct)}`,
|
|
3321
|
+
`.dg-bx{${font(TYPE.regionNote)};fill:var(--mute)}`,
|
|
3322
|
+
".dg-st{fill:var(--surf);stroke:var(--hair)}",
|
|
3323
|
+
`.dg-halo{fill:none;stroke:var(--c);stroke-width:${S.halo};stroke-opacity:.16}`,
|
|
3324
|
+
`.dg-on{fill:none;stroke:var(--c);stroke-width:${S.on}}`,
|
|
3325
|
+
`.dg-ic{fill:${mix(X.icon)}}`,
|
|
3326
|
+
`.dg-gl{fill:none;stroke:var(--c);stroke-width:${S.glyph};stroke-linecap:round;stroke-linejoin:round}`,
|
|
3327
|
+
`.dg-sn{${font(TYPE.boxName)};fill:var(--ink)}`,
|
|
3328
|
+
`.dg-ss{${font(TYPE.boxSub)};fill:var(--mute)}`,
|
|
3329
|
+
`.dg-ss-ok{${font(TYPE.boxSubStrong)};fill:var(--ct)}`,
|
|
3330
|
+
`.dg-ss-act{${font(TYPE.boxSubStrong)};fill:var(--ink)}`,
|
|
3331
|
+
`.dg-ll{stroke:var(--line);stroke-width:${S.lifeline};stroke-dasharray:3 4}`,
|
|
3332
|
+
`.dg-e{fill:none;stroke:var(--line);stroke-width:${S.edge};stroke-linecap:round;stroke-dasharray:0 ${LOOK.edge.ghostDash}}`,
|
|
3333
|
+
`.dg-eh{fill:none;stroke:var(--line);stroke-width:${S.arrow};stroke-linecap:round;stroke-linejoin:round}`,
|
|
3334
|
+
`.dg-e-on{fill:none;stroke:var(--c);stroke-width:${S.edgeOn};stroke-linecap:round;stroke-dasharray:1 2}`,
|
|
3335
|
+
`.dg-eh-on{fill:none;stroke:var(--c);stroke-width:${S.edgeOn};stroke-linecap:round;stroke-linejoin:round}`,
|
|
3336
|
+
`.dg-flow{fill:none;stroke:var(--surf);stroke-width:${S.flow};stroke-linecap:round;stroke-dasharray:1.5 ${LOOK.edge.flowDash}}`,
|
|
3337
|
+
".dg-bd{cursor:pointer}",
|
|
3338
|
+
".dg-bdf{fill:var(--c)}",
|
|
3339
|
+
`.dg-bdft{${font(TYPE.badge)};fill:var(--on-c)}`,
|
|
3340
|
+
`.dg-bdr{fill:none;stroke:var(--c);stroke-width:${S.badgeRing}}`,
|
|
3341
|
+
`.dg-bdp{fill:${mix(X.badgePast)};stroke:${mix(X.badgePastEdge, "transparent")};stroke-width:${S.hair}}`,
|
|
3342
|
+
`.dg-bdpt{${font(TYPE.badge)};fill:var(--ct)}`,
|
|
3343
|
+
`.dg-cap rect,.dg-act rect{fill:${mix(X.cap)};stroke:${mix(X.capEdge, "transparent")}}`,
|
|
3344
|
+
`.dg-cap text{${font(TYPE.label)};fill:var(--ct)}`,
|
|
3345
|
+
`.dg-capj text{${font(TYPE.labelJa)}}`,
|
|
3346
|
+
`.dg-act text{${font(TYPE.action)};fill:var(--ct)}`,
|
|
3347
|
+
".dg-car{fill:var(--carry,var(--ink))}",
|
|
3348
|
+
`.dg-car-t{${font(TYPE.carrier)};fill:var(--bg)}`,
|
|
3349
|
+
`.dg-car-tj{${font(TYPE.carrierJa)}}`,
|
|
3350
|
+
`.dg-env{fill:var(--carry,var(--ink));stroke:var(--surf);stroke-width:${S.envelope}}`,
|
|
3351
|
+
`.dg-env-in{fill:none;stroke:var(--surf);stroke-width:${S.flow};stroke-linejoin:round;stroke-linecap:round}`,
|
|
3352
|
+
".dg-coin{fill:var(--coin);stroke:var(--surf);stroke-width:1.2}",
|
|
3353
|
+
".dg-coin-in{fill:none;stroke:var(--coinin);stroke-width:1.1}",
|
|
3354
|
+
".dg-strip{fill:var(--surf);stroke:var(--hair)}",
|
|
3355
|
+
`.dg-sep{stroke:var(--hair);stroke-width:${S.hair}}`,
|
|
3356
|
+
`.dg-sh{${font(TYPE.stripTitle)};fill:var(--ink)}`,
|
|
3357
|
+
`.dg-fl{${font(TYPE.fieldName)};fill:var(--mute)}`,
|
|
3358
|
+
`.dg-fv{${font(TYPE.fieldValue)};fill:var(--ink)}`,
|
|
3359
|
+
`.dg-fvj{${font(TYPE.fieldValueJa)};fill:var(--ink)}`,
|
|
3360
|
+
".dg-tg rect{fill:var(--c)}",
|
|
3361
|
+
`.dg-tg text{${font(TYPE.tag)};fill:var(--on-c)}`,
|
|
3362
|
+
".dg-vp-bg{fill:var(--bg)}",
|
|
3363
|
+
".dg-vp-frame{fill:none;stroke:var(--hair)}",
|
|
3364
|
+
".dg-mm-bg{fill:var(--surf);stroke:var(--hair)}",
|
|
3365
|
+
`.dg-mm-t{${font(TYPE.miniTitle)};fill:var(--mute)}`,
|
|
3366
|
+
".dg-mm-world{fill:var(--sunk);stroke:var(--hair)}",
|
|
3367
|
+
`.dg-mm-band{fill:${mix(X.miniBand)};stroke:${mix(X.miniBandEdge, "transparent")};stroke-width:.6}`,
|
|
3368
|
+
`.dg-mm-card{fill:${mix(X.mini)}}`,
|
|
3369
|
+
`.dg-mm-vp{fill:color-mix(in srgb,var(--ink) ${X.view}%,transparent);stroke:var(--ink);stroke-width:${S.badgeRing};vector-effect:non-scaling-stroke}`
|
|
3370
|
+
].join("");
|
|
3371
|
+
function nameOf(text2) {
|
|
3372
|
+
let h = 2166136261;
|
|
3373
|
+
for (let i = 0; i < text2.length; i++) {
|
|
3374
|
+
h ^= text2.charCodeAt(i);
|
|
3375
|
+
h = Math.imul(h, 16777619);
|
|
3376
|
+
}
|
|
3377
|
+
return (h >>> 0).toString(36);
|
|
3378
|
+
}
|
|
3379
|
+
function involved(diagram) {
|
|
3380
|
+
const on = /* @__PURE__ */ new Map();
|
|
3381
|
+
const add = (id, s) => {
|
|
3382
|
+
on.set(id, (on.get(id) ?? /* @__PURE__ */ new Set()).add(s));
|
|
3383
|
+
};
|
|
3384
|
+
diagram.steps.forEach((step, s) => {
|
|
3385
|
+
for (const event of step.events) {
|
|
3386
|
+
if (event.type === "edge") {
|
|
3387
|
+
add(event.from, s);
|
|
3388
|
+
add(event.to, s);
|
|
3389
|
+
} else if (event.type === "action" || event.type === "swap") add(event.box, s);
|
|
3390
|
+
}
|
|
3391
|
+
});
|
|
3392
|
+
return new Map([...on].map(([id, steps]) => [id, [...steps].sort((a, b) => a - b)]));
|
|
3393
|
+
}
|
|
3394
|
+
function subChanges(diagram, timeline, actionsInBox) {
|
|
3395
|
+
const raw = [];
|
|
3396
|
+
let order = 0;
|
|
3397
|
+
for (const time of timeline.events) {
|
|
3398
|
+
const event = diagram.steps[time.step]?.events[time.event];
|
|
3399
|
+
if (event?.type === "swap") raw.push({ t: time.at, order: order++, box: event.box, set: event.text });
|
|
3400
|
+
if (actionsInBox && event?.type === "action") {
|
|
3401
|
+
raw.push({ t: time.at, order: order++, box: event.box, act: event.label });
|
|
3402
|
+
raw.push({ t: timeline.steps[time.step].end, order: order++, box: event.box, act: null });
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
raw.sort((a, b) => a.t - b.t || a.order - b.order);
|
|
3406
|
+
const out = /* @__PURE__ */ new Map();
|
|
3407
|
+
for (const box of diagram.boxes) {
|
|
3408
|
+
let base = [box.sub ?? "", "dg-ss"];
|
|
3409
|
+
let acting;
|
|
3410
|
+
let shown = base.join("|");
|
|
3411
|
+
const list = [];
|
|
3412
|
+
for (const change of raw.filter((r) => r.box === box.id)) {
|
|
3413
|
+
if (change.set !== void 0) {
|
|
3414
|
+
base = [change.set, "dg-ss-ok"];
|
|
3415
|
+
acting = void 0;
|
|
3416
|
+
}
|
|
3417
|
+
if (change.act !== void 0) acting = change.act ?? void 0;
|
|
3418
|
+
const now = acting !== void 0 ? [acting, "dg-ss-act"] : base;
|
|
3419
|
+
if (now.join("|") === shown) continue;
|
|
3420
|
+
shown = now.join("|");
|
|
3421
|
+
list.push([change.t, now[0], now[1]]);
|
|
3422
|
+
}
|
|
3423
|
+
const kept = list.filter((change, k) => {
|
|
3424
|
+
const next = list[k + 1];
|
|
3425
|
+
return next === void 0 || next[0] - change[0] >= MOTION.minShow;
|
|
3426
|
+
});
|
|
3427
|
+
out.set(box.id, kept);
|
|
3428
|
+
}
|
|
3429
|
+
return out;
|
|
3430
|
+
}
|
|
3431
|
+
function fieldChanges(diagram, timeline, layout) {
|
|
3432
|
+
const out = /* @__PURE__ */ new Map();
|
|
3433
|
+
for (const time of timeline.events) {
|
|
3434
|
+
const event = diagram.steps[time.step]?.events[time.event];
|
|
3435
|
+
if (event?.type !== "strip") continue;
|
|
3436
|
+
const color = layout.badges[time.step]?.color ?? "slate";
|
|
3437
|
+
const list = out.get(event.field) ?? [];
|
|
3438
|
+
list.push({ at: time.at, color, ...event.value !== void 0 ? { value: event.value } : {}, ...event.tag !== void 0 ? { tag: event.tag } : {} });
|
|
3439
|
+
out.set(event.field, list);
|
|
3440
|
+
}
|
|
3441
|
+
return out;
|
|
3442
|
+
}
|
|
3443
|
+
function drawSvg(diagram, layout, timeline, palette, theme, follow) {
|
|
3444
|
+
const id = nameOf(`${JSON.stringify(diagram)}|${palette.id}|${theme}|${follow ? `${follow.width}|${follow.lang}` : ""}`);
|
|
3445
|
+
const m = new Motion(`dg${id}`, timeline.total, timeline.last);
|
|
3446
|
+
const ctx = { m, t: timeline, sh: `filter="url(#dg-sh-${id})"`, end: timeline.steps[timeline.steps.length - 1].end };
|
|
3447
|
+
const on = involved(diagram);
|
|
3448
|
+
const subs = subChanges(diagram, timeline, layout.kind === "architecture");
|
|
3449
|
+
const L = { band: [], base: [], lit: [], node: [], badge: [], top: [] };
|
|
3450
|
+
for (const region of layout.regions) L.band.push(band(region));
|
|
3451
|
+
if (layout.strip) L.band.push(strip(layout.strip, fieldChanges(diagram, timeline, layout), ctx));
|
|
3452
|
+
for (const line of layout.lifelines) L.base.push(lifeline(line.x, line.y1, line.y2));
|
|
3453
|
+
for (const e of layout.edges) {
|
|
3454
|
+
const time = timeline.edges.find((t) => t.step === e.step && t.event === e.event);
|
|
3455
|
+
if (!time) continue;
|
|
3456
|
+
const drawn = edge(e, time, ctx);
|
|
3457
|
+
L.base.push(drawn.base);
|
|
3458
|
+
L.lit.push(drawn.lit);
|
|
3459
|
+
}
|
|
3460
|
+
for (const box of layout.boxes) L.node.push(card(box, ctx, on.get(box.id) ?? [], subs.get(box.id) ?? []));
|
|
3461
|
+
for (const b of layout.badges) L.badge.push(badge(b, ctx));
|
|
3462
|
+
for (const l of layout.labels) {
|
|
3463
|
+
const time = timeline.labels.find((t) => t.step === l.step && t.event === l.event);
|
|
3464
|
+
if (time) L.top.push(label(l, time, ctx));
|
|
3465
|
+
}
|
|
3466
|
+
for (const a of layout.actions) {
|
|
3467
|
+
const time = timeline.events.find((t) => t.step === a.step && t.event === a.event);
|
|
3468
|
+
if (time) L.top.push(action(a, time.at, timeline.steps[a.step].end, ctx));
|
|
3469
|
+
}
|
|
3470
|
+
for (const time of timeline.carriers) {
|
|
3471
|
+
const e = layout.edges.find((x) => x.step === time.step && x.event === time.event);
|
|
3472
|
+
if (e) L.top.push(carrier(e, time, ctx));
|
|
3473
|
+
}
|
|
3474
|
+
const content = Object.values(L).map((parts) => parts.join("")).join("");
|
|
3475
|
+
const { near, far, nearY, farY } = LOOK.shadow;
|
|
3476
|
+
const shadow = `<filter id="dg-sh-${id}" x="-20%" y="-30%" width="140%" height="180%"><feDropShadow dx="0" dy="${nearY}" stdDeviation="${near}" style="flood-color:var(--sh);flood-opacity:var(--shA)"/><feDropShadow dx="0" dy="${farY}" stdDeviation="${far}" style="flood-color:var(--sh);flood-opacity:var(--shB)"/></filter>`;
|
|
3477
|
+
const view = follow ? followView(layout, timeline, diagram, m, id, content, follow) : { body: `<rect class="dg-bg" width="${layout.width}" height="${layout.height}" rx="${LOOK.region.radius}"/>${content}`, w: layout.width, h: layout.height };
|
|
3478
|
+
const css = `.dg-${id}{${FONT_VARS};--T:${timeline.total}s;${paletteVars(palette, theme)}}${PART_CSS}${m.frames.join("")}`;
|
|
3479
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" class="dg dg-${id}" viewBox="0 0 ${Math.ceil(view.w)} ${Math.ceil(view.h)}" width="${Math.ceil(view.w)}" height="${Math.ceil(view.h)}" role="img" aria-label="${esc(diagram.title)}" data-dragon="figure" data-view="${follow ? "follow" : "fixed"}"><style>${css}</style><defs>${shadow}</defs>${view.body}</svg>`;
|
|
3480
|
+
}
|
|
3481
|
+
function focusOf(layout, diagram, step) {
|
|
3482
|
+
const rects = [];
|
|
3483
|
+
for (const e of layout.edges.filter((x2) => x2.step === step)) {
|
|
3484
|
+
const xs = e.points.map((p) => p[0]);
|
|
3485
|
+
const ys = e.points.map((p) => p[1]);
|
|
3486
|
+
rects.push({ x: Math.min(...xs), y: Math.min(...ys), w: Math.max(...xs) - Math.min(...xs), h: Math.max(...ys) - Math.min(...ys) });
|
|
3487
|
+
}
|
|
3488
|
+
rects.push(...layout.labels.filter((l) => l.step === step), ...layout.actions.filter((a) => a.step === step));
|
|
3489
|
+
for (const event of diagram.steps[step]?.events ?? []) {
|
|
3490
|
+
const ids = event.type === "edge" ? [event.from, event.to] : event.type === "action" || event.type === "swap" ? [event.box] : [];
|
|
3491
|
+
for (const id of ids) {
|
|
3492
|
+
const box = layout.boxes.find((b) => b.id === id);
|
|
3493
|
+
if (box && (layout.kind === "architecture" || event.type === "swap")) rects.push(box);
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
if (rects.length === 0) return void 0;
|
|
3497
|
+
const x = Math.min(...rects.map((r) => r.x));
|
|
3498
|
+
const y = Math.min(...rects.map((r) => r.y));
|
|
3499
|
+
return { x, y, w: Math.max(...rects.map((r) => r.x + r.w)) - x, h: Math.max(...rects.map((r) => r.y + r.h)) - y };
|
|
3500
|
+
}
|
|
3501
|
+
function followView(layout, timeline, diagram, m, id, content, follow) {
|
|
3502
|
+
const F = LOOK.follow;
|
|
3503
|
+
const M = LOOK.mini;
|
|
3504
|
+
const vw = Math.min(layout.width, Math.max(1, follow.width));
|
|
3505
|
+
const vh = Math.min(layout.height, Math.max(F.minH, vw * F.aspect));
|
|
3506
|
+
const clampX = (x) => Math.min(layout.width - vw / 2, Math.max(vw / 2, x));
|
|
3507
|
+
const clampY = (y) => Math.min(layout.height - vh / 2, Math.max(vh / 2, y));
|
|
3508
|
+
let prev = [layout.width / 2, layout.height / 2];
|
|
3509
|
+
const centers = timeline.steps.map((_, s) => {
|
|
3510
|
+
const f = focusOf(layout, diagram, s);
|
|
3511
|
+
prev = f ? [f.x + f.w / 2, f.y + f.h / 2] : prev;
|
|
3512
|
+
return [clampX(prev[0]), clampY(prev[1])];
|
|
3513
|
+
});
|
|
3514
|
+
const c0 = centers[0];
|
|
3515
|
+
const cam = [
|
|
3516
|
+
[0, c0[0], c0[1]],
|
|
3517
|
+
[timeline.steps[0].start, c0[0], c0[1]]
|
|
3518
|
+
];
|
|
3519
|
+
centers.forEach((c, s) => {
|
|
3520
|
+
if (s === 0) return;
|
|
3521
|
+
const before = centers[s - 1];
|
|
3522
|
+
const start = timeline.steps[s].start;
|
|
3523
|
+
cam.push([start, before[0], before[1], 1, EASE.inOut], [start + F.ease, c[0], c[1]]);
|
|
3524
|
+
});
|
|
3525
|
+
const cl = centers[centers.length - 1];
|
|
3526
|
+
cam.push([timeline.last, cl[0], cl[1], 1, EASE.inOut], [timeline.total, c0[0], c0[1]]);
|
|
3527
|
+
const camKf = m.move(cam.map(([t, cx, cy, s, e]) => [t, vw / 2 - cx, vh / 2 - cy, s, e]));
|
|
3528
|
+
const mw = Math.min(M.w, vw * 0.4, vh * 0.4 / layout.height * layout.width);
|
|
3529
|
+
const k = mw / layout.width;
|
|
3530
|
+
const mh = layout.height * k;
|
|
3531
|
+
const title = FIGURE_TEXT[follow.lang].overview;
|
|
3532
|
+
const bw = Math.max(mw, Math.ceil(textWidth(title, TYPE.miniTitle)));
|
|
3533
|
+
const bx = vw - bw - M.inset - M.pad;
|
|
3534
|
+
const mx = bx + (bw - mw) / 2;
|
|
3535
|
+
const my = M.inset + M.pad + M.title;
|
|
3536
|
+
const shapes = [
|
|
3537
|
+
...layout.regions.map((r) => `<rect class="dg-mm-band" style="${cs(r.color)}" x="${mx + r.x * k}" y="${my + r.y * k}" width="${r.w * k}" height="${r.h * k}" rx="3"/>`),
|
|
3538
|
+
...layout.boxes.map((b) => `<rect class="dg-mm-card" style="${cs(b.color)}" x="${mx + b.x * k}" y="${my + b.y * k}" width="${b.w * k}" height="${b.h * k}" rx="1.5"/>`)
|
|
3539
|
+
].join("");
|
|
3540
|
+
const vp = m.move(cam.map(([t, cx, cy, , e]) => [t, mx + (cx - vw / 2) * k, my + (cy - vh / 2) * k, 1, e]));
|
|
3541
|
+
const mini = `<rect class="dg-mm-bg" x="${bx - M.pad}" y="${my - M.pad - M.title}" width="${bw + M.pad * 2}" height="${mh + M.pad * 2 + M.title}" rx="${M.radius}"/><text class="dg-mm-t" x="${bx}" y="${my - M.pad + 2}">${title}</text><g clip-path="url(#dg-mm-${id})"><rect class="dg-mm-world" x="${mx}" y="${my}" width="${mw}" height="${mh}"/>${shapes}<rect class="dg-mm-vp dg-a" width="${vw * k}" height="${vh * k}" rx="2" style="${vp}"/></g>`;
|
|
3542
|
+
const body = `<defs><clipPath id="dg-vp-${id}"><rect width="${vw}" height="${vh}" rx="${LOOK.region.radius}"/></clipPath><clipPath id="dg-mm-${id}"><rect x="${mx}" y="${my}" width="${mw}" height="${mh}" rx="4"/></clipPath></defs><g clip-path="url(#dg-vp-${id})"><rect class="dg-vp-bg" width="${vw}" height="${vh}"/><g class="dg-a" style="${camKf}">${content}</g></g><rect class="dg-vp-frame" x="0.5" y="0.5" width="${vw - 1}" height="${vh - 1}" rx="${LOOK.region.radius}"/>${mini}`;
|
|
3543
|
+
return { body, w: vw, h: vh };
|
|
3544
|
+
}
|
|
3545
|
+
function renderDiagram(input, options = {}) {
|
|
3546
|
+
const lang = options.lang ?? "ja";
|
|
3547
|
+
const read2 = readDiagram(input, { lang });
|
|
3548
|
+
if (!read2.ok) throw new Error(FIGURE_TEXT[lang].cannotDraw(read2.errors.map((e) => `${e.pointer} ${e.message}`).join(" / ")));
|
|
3549
|
+
const diagram = read2.diagram;
|
|
3550
|
+
const palette = resolvePalette(options.palette);
|
|
3551
|
+
const theme = options.theme === "dark" ? "dark" : "light";
|
|
3552
|
+
const layout = diagram.kind === "sequence" ? layoutSequence(diagram) : layoutArchitecture(diagram);
|
|
3553
|
+
const timeline = buildTimeline(diagram);
|
|
3554
|
+
return {
|
|
3555
|
+
svg: drawSvg(diagram, layout, timeline, palette, theme),
|
|
3556
|
+
palette: palette.id,
|
|
3557
|
+
theme,
|
|
3558
|
+
...diagram.view ? { view: diagram.view } : {},
|
|
3559
|
+
fonts: { ...FONTS },
|
|
3560
|
+
layout,
|
|
3561
|
+
timeline,
|
|
3562
|
+
diagram
|
|
3563
|
+
};
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
// src/view.ts
|
|
3567
|
+
function chooseView(rendered, frameWidth) {
|
|
3568
|
+
const textPx = Math.max(0, frameWidth) / rendered.layout.width * TYPE.boxName.size;
|
|
3569
|
+
if (rendered.view) return { mode: rendered.view, textPx };
|
|
3570
|
+
return { mode: textPx >= READABLE_PX ? "fixed" : "follow", textPx };
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
// src/player.ts
|
|
3574
|
+
var BUTTON_TEXT = { prev: "\u2039", pause: "\u275A\u275A", play: "\u25B6", next: "\u203A" };
|
|
3575
|
+
var pad = (n) => String(n).padStart(2, "0");
|
|
3576
|
+
var stepNo = (step, count) => `${pad(step + 1)}/${pad(count)}`;
|
|
3577
|
+
var require_ = module$1.createRequire(importMetaUrl);
|
|
3578
|
+
var SCRIPTS = {
|
|
3579
|
+
"/mediabunny.js": path.join(path.dirname(require_.resolve("mediabunny")), "mediabunny.min.mjs"),
|
|
3580
|
+
"/gifenc.js": require_.resolve("gifenc/dist/gifenc.esm.js")
|
|
3581
|
+
};
|
|
3582
|
+
var SCALE = 2;
|
|
3583
|
+
var INSTALL_ADD = "`pnpm add -D playwright-core`";
|
|
3584
|
+
var INSTALL_CHROMIUM = "`pnpm exec playwright-core install chromium`";
|
|
3585
|
+
var LAUNCH_TEXT = {
|
|
3586
|
+
ja: {
|
|
3587
|
+
missing: "\u66F8\u304D\u51FA\u3057\u306B\u306F playwright-core \u304C\u8981\u308B\u3002",
|
|
3588
|
+
cannotLaunch: "Chromium \u3092\u8D77\u52D5\u3067\u304D\u306A\u3044\u3002",
|
|
3589
|
+
install: `${INSTALL_ADD} \u3067\u5165\u308C\u3001${INSTALL_CHROMIUM} \u3067 Chromium \u3092\u5165\u308C\u308B`
|
|
3590
|
+
},
|
|
3591
|
+
en: {
|
|
3592
|
+
missing: "Exporting needs playwright-core. ",
|
|
3593
|
+
cannotLaunch: "Cannot launch Chromium. ",
|
|
3594
|
+
install: `Install playwright-core with ${INSTALL_ADD} and Chromium with ${INSTALL_CHROMIUM}`
|
|
3595
|
+
}
|
|
3596
|
+
};
|
|
3597
|
+
async function launch(lang) {
|
|
3598
|
+
const text2 = LAUNCH_TEXT[lang];
|
|
3599
|
+
let chromium;
|
|
3600
|
+
try {
|
|
3601
|
+
({ chromium } = await import('playwright-core'));
|
|
3602
|
+
} catch {
|
|
3603
|
+
throw new Error(`${text2.missing}${text2.install}`);
|
|
3604
|
+
}
|
|
3605
|
+
try {
|
|
3606
|
+
return await chromium.launch();
|
|
3607
|
+
} catch (error) {
|
|
3608
|
+
throw new Error(`${text2.cannotLaunch}${text2.install} (${String(error).split("\n")[0]})`);
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
function sizeOf(svg) {
|
|
3612
|
+
const [, width = "0", height = "0"] = /^<svg\b[^>]*?\swidth="(\d+)"\s+height="(\d+)"/.exec(svg) ?? [];
|
|
3613
|
+
return { width: Number(width), height: Number(height) };
|
|
3614
|
+
}
|
|
3615
|
+
async function stage(browser, svg, fontCss, body) {
|
|
3616
|
+
const { width, height } = sizeOf(svg);
|
|
3617
|
+
const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: SCALE });
|
|
3618
|
+
const paused = svg.replace(/^<svg\b/, '<svg style="--play:paused;--at:0"');
|
|
3619
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><style>${fontCss}html,body{margin:0}body{${body}}svg{display:block}</style><script type="module">import * as mb from "/mediabunny.js";import * as gif from "/gifenc.js";window.__tools={mb,gif};</script></head><body>${paused}</body></html>`;
|
|
3620
|
+
await page.route("http://localhost/**", async (route) => {
|
|
3621
|
+
const path = new URL(route.request().url()).pathname;
|
|
3622
|
+
if (path === "/") return route.fulfill({ contentType: "text/html; charset=utf-8", body: html });
|
|
3623
|
+
const script = SCRIPTS[path];
|
|
3624
|
+
return script ? route.fulfill({ contentType: "text/javascript", body: fs.readFileSync(script) }) : route.fulfill({ status: 404 });
|
|
3625
|
+
});
|
|
3626
|
+
await page.goto("http://localhost/");
|
|
3627
|
+
await page.waitForFunction(() => "__tools" in window);
|
|
3628
|
+
await page.evaluate(async () => {
|
|
3629
|
+
const loads = [];
|
|
3630
|
+
document.fonts.forEach((face) => loads.push(face.load()));
|
|
3631
|
+
await Promise.all(loads);
|
|
3632
|
+
await document.fonts.ready;
|
|
3633
|
+
});
|
|
3634
|
+
return { page, width, height };
|
|
3635
|
+
}
|
|
3636
|
+
async function at(page, t) {
|
|
3637
|
+
await page.evaluate(
|
|
3638
|
+
(t2) => new Promise((done) => {
|
|
3639
|
+
document.querySelector("svg")?.style.setProperty("--at", String(t2));
|
|
3640
|
+
requestAnimationFrame(() => requestAnimationFrame(() => done()));
|
|
3641
|
+
}),
|
|
3642
|
+
t
|
|
3643
|
+
);
|
|
3644
|
+
}
|
|
3645
|
+
async function still(stage2, t) {
|
|
3646
|
+
await at(stage2.page, t);
|
|
3647
|
+
return stage2.page.screenshot({ type: "png", omitBackground: true });
|
|
3648
|
+
}
|
|
3649
|
+
async function film(stage2, plan2) {
|
|
3650
|
+
const { page, width, height } = stage2;
|
|
3651
|
+
await page.evaluate(
|
|
3652
|
+
async ({ width: width2, height: height2, scale, fps, mp4, gifEvery }) => {
|
|
3653
|
+
const { mb, gif } = window.__tools;
|
|
3654
|
+
let add = () => Promise.resolve();
|
|
3655
|
+
let close = () => Promise.resolve(void 0);
|
|
3656
|
+
if (mp4) {
|
|
3657
|
+
const canvas = new OffscreenCanvas(width2 * scale, height2 * scale);
|
|
3658
|
+
const context = canvas.getContext("2d");
|
|
3659
|
+
const target = new mb.BufferTarget();
|
|
3660
|
+
const output = new mb.Output({ format: new mb.Mp4OutputFormat({ fastStart: "in-memory" }), target });
|
|
3661
|
+
const source = new mb.CanvasSource(canvas, { codec: "avc", bitrate: mb.QUALITY_MEDIUM, keyFrameInterval: 2 });
|
|
3662
|
+
output.addVideoTrack(source, { frameRate: fps });
|
|
3663
|
+
await output.start();
|
|
3664
|
+
add = async (bitmap, i) => {
|
|
3665
|
+
context.drawImage(bitmap, 0, 0);
|
|
3666
|
+
await source.add(i / fps, 1 / fps);
|
|
3667
|
+
};
|
|
3668
|
+
close = async () => {
|
|
3669
|
+
await output.finalize();
|
|
3670
|
+
return new Uint8Array(target.buffer);
|
|
3671
|
+
};
|
|
3672
|
+
}
|
|
3673
|
+
const small = new OffscreenCanvas(width2, height2);
|
|
3674
|
+
const smallContext = small.getContext("2d", { willReadFrequently: true });
|
|
3675
|
+
const decode = (png) => createImageBitmap(new Blob([Uint8Array.from(atob(png), (c) => c.charCodeAt(0))], { type: "image/png" }));
|
|
3676
|
+
const read2 = (bitmap) => {
|
|
3677
|
+
smallContext.drawImage(bitmap, 0, 0, width2, height2);
|
|
3678
|
+
return smallContext.getImageData(0, 0, width2, height2).data;
|
|
3679
|
+
};
|
|
3680
|
+
const encoder = gifEvery ? gif.GIFEncoder() : void 0;
|
|
3681
|
+
const delay = gifEvery / fps * 1e3;
|
|
3682
|
+
const sampled = [];
|
|
3683
|
+
let colors = [];
|
|
3684
|
+
const nearest = /* @__PURE__ */ new Map();
|
|
3685
|
+
const toIndex = (data) => {
|
|
3686
|
+
const index = new Uint8Array(data.length / 4);
|
|
3687
|
+
for (let p = 0; p < index.length; p++) {
|
|
3688
|
+
const i = p * 4;
|
|
3689
|
+
const key = data[i] << 16 | data[i + 1] << 8 | data[i + 2];
|
|
3690
|
+
let k = nearest.get(key);
|
|
3691
|
+
if (k === void 0) {
|
|
3692
|
+
k = gif.nearestColorIndex(colors, [data[i], data[i + 1], data[i + 2]]);
|
|
3693
|
+
nearest.set(key, k);
|
|
3694
|
+
}
|
|
3695
|
+
index[p] = k;
|
|
3696
|
+
}
|
|
3697
|
+
return index;
|
|
3698
|
+
};
|
|
3699
|
+
let previous;
|
|
3700
|
+
const writeGif = (data) => {
|
|
3701
|
+
const clear = colors.length;
|
|
3702
|
+
const index = toIndex(data);
|
|
3703
|
+
const before = previous;
|
|
3704
|
+
previous = data;
|
|
3705
|
+
if (!before) {
|
|
3706
|
+
encoder.writeFrame(index, width2, height2, { palette: [...colors, [0, 0, 0]], delay, dispose: 1 });
|
|
3707
|
+
return;
|
|
3708
|
+
}
|
|
3709
|
+
let changed = 0;
|
|
3710
|
+
for (let p = 0; p < index.length; p++) {
|
|
3711
|
+
const i = p * 4;
|
|
3712
|
+
if (data[i] === before[i] && data[i + 1] === before[i + 1] && data[i + 2] === before[i + 2]) index[p] = clear;
|
|
3713
|
+
else changed++;
|
|
3714
|
+
}
|
|
3715
|
+
if (!changed) encoder.writeFrame(new Uint8Array([clear]), 1, 1, { transparent: true, transparentIndex: clear, delay, dispose: 1 });
|
|
3716
|
+
else encoder.writeFrame(index, width2, height2, { transparent: true, transparentIndex: clear, delay, dispose: 1 });
|
|
3717
|
+
};
|
|
3718
|
+
const base64 = (bytes) => {
|
|
3719
|
+
let text2 = "";
|
|
3720
|
+
for (let i = 0; i < bytes.length; i += 32768) text2 += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
3721
|
+
return btoa(text2);
|
|
3722
|
+
};
|
|
3723
|
+
const box = {
|
|
3724
|
+
async sample(png) {
|
|
3725
|
+
const bitmap = await decode(png);
|
|
3726
|
+
sampled.push(read2(bitmap));
|
|
3727
|
+
bitmap.close();
|
|
3728
|
+
},
|
|
3729
|
+
seal() {
|
|
3730
|
+
const all = new Uint8ClampedArray(sampled.reduce((n, data) => n + data.length, 0));
|
|
3731
|
+
let offset = 0;
|
|
3732
|
+
for (const data of sampled) {
|
|
3733
|
+
all.set(data, offset);
|
|
3734
|
+
offset += data.length;
|
|
3735
|
+
}
|
|
3736
|
+
colors = gif.quantize(all, 255);
|
|
3737
|
+
},
|
|
3738
|
+
async push(png, i) {
|
|
3739
|
+
const bitmap = await decode(png);
|
|
3740
|
+
await add(bitmap, i);
|
|
3741
|
+
if (gifEvery && i % gifEvery === 0) writeGif(read2(bitmap));
|
|
3742
|
+
bitmap.close();
|
|
3743
|
+
},
|
|
3744
|
+
async finish() {
|
|
3745
|
+
const video = await close();
|
|
3746
|
+
if (encoder) encoder.finish();
|
|
3747
|
+
return { ...video ? { mp4: base64(video) } : {}, ...encoder ? { gif: base64(encoder.bytes()) } : {} };
|
|
3748
|
+
}
|
|
3749
|
+
};
|
|
3750
|
+
window.__film = box;
|
|
3751
|
+
},
|
|
3752
|
+
{ width, height, scale: SCALE, fps: plan2.fps, mp4: plan2.mp4, gifEvery: plan2.gifEvery }
|
|
3753
|
+
);
|
|
3754
|
+
const cdp = await page.context().newCDPSession(page);
|
|
3755
|
+
const clip = { x: 0, y: 0, width, height, scale: SCALE };
|
|
3756
|
+
const shoot = async (t) => {
|
|
3757
|
+
await at(page, t);
|
|
3758
|
+
return (await cdp.send("Page.captureScreenshot", { format: "png", optimizeForSpeed: true, clip })).data;
|
|
3759
|
+
};
|
|
3760
|
+
if (plan2.gifEvery) {
|
|
3761
|
+
for (const t of plan2.samples) {
|
|
3762
|
+
const png = await shoot(t);
|
|
3763
|
+
await page.evaluate((png2) => window.__film.sample(png2), png);
|
|
3764
|
+
}
|
|
3765
|
+
await page.evaluate(() => window.__film.seal());
|
|
3766
|
+
}
|
|
3767
|
+
const frames = Math.round(plan2.total * plan2.fps);
|
|
3768
|
+
for (let i = 0; i < frames; i++) {
|
|
3769
|
+
const png = await shoot(i / plan2.fps);
|
|
3770
|
+
await page.evaluate(([png2, i2]) => window.__film.push(png2, i2), [png, i]);
|
|
3771
|
+
}
|
|
3772
|
+
const out = await page.evaluate(() => window.__film.finish());
|
|
3773
|
+
return {
|
|
3774
|
+
frames,
|
|
3775
|
+
...out.mp4 ? { mp4: Buffer.from(out.mp4, "base64") } : {},
|
|
3776
|
+
...out.gif ? { gif: Buffer.from(out.gif, "base64") } : {}
|
|
3777
|
+
};
|
|
3778
|
+
}
|
|
3779
|
+
var require_2 = module$1.createRequire(importMetaUrl);
|
|
3780
|
+
var subsetFont = require_2("subset-font");
|
|
3781
|
+
var PACKAGES = [
|
|
3782
|
+
{ family: FONTS.sans, name: "noto-sans-jp" },
|
|
3783
|
+
{ family: FONTS.mono, name: "jetbrains-mono" }
|
|
3784
|
+
];
|
|
3785
|
+
var weights = Object.values(TYPE).map((style) => style.weight);
|
|
3786
|
+
var WEIGHT = { min: Math.min(...weights), max: Math.max(...weights) };
|
|
3787
|
+
function ranges(list) {
|
|
3788
|
+
return list.split(",").map((part) => {
|
|
3789
|
+
const [from = "", to = from] = part.trim().replace(/^U\+/i, "").split("-");
|
|
3790
|
+
return [parseInt(from, 16), parseInt(to, 16)];
|
|
3791
|
+
});
|
|
3792
|
+
}
|
|
3793
|
+
var hex = (code) => `U+${code.toString(16).toUpperCase()}`;
|
|
3794
|
+
function charsOf(texts) {
|
|
3795
|
+
return [.../* @__PURE__ */ new Set([...texts.join("")])].filter((char) => char !== "\n" && char !== "\r" && char !== " ").sort();
|
|
3796
|
+
}
|
|
3797
|
+
async function fontFaces(chars) {
|
|
3798
|
+
const faces = await Promise.all(
|
|
3799
|
+
PACKAGES.flatMap(({ family, name }) => {
|
|
3800
|
+
const base = path.dirname(require_2.resolve(`@fontsource-variable/${name}/unicode.json`));
|
|
3801
|
+
const table = JSON.parse(fs.readFileSync(path.join(base, "unicode.json"), "utf8"));
|
|
3802
|
+
return Object.entries(table).map(async ([key, list]) => {
|
|
3803
|
+
const span = ranges(list);
|
|
3804
|
+
const own = chars.filter((char) => {
|
|
3805
|
+
const code = char.codePointAt(0) ?? -1;
|
|
3806
|
+
return span.some(([from, to]) => code >= from && code <= to);
|
|
3807
|
+
});
|
|
3808
|
+
if (!own.length) return "";
|
|
3809
|
+
const file = path.join(base, "files", `${name}-${key.replace(/[[\]]/g, "")}-wght-normal.woff2`);
|
|
3810
|
+
const woff2 = await subsetFont(await promises.readFile(file), own.join(""), { targetFormat: "woff2", variationAxes: { wght: WEIGHT } });
|
|
3811
|
+
const unicode = own.map((char) => hex(char.codePointAt(0) ?? 0)).join(",");
|
|
3812
|
+
return `@font-face{font-family:"${family}";font-style:normal;font-display:block;font-weight:${WEIGHT.min} ${WEIGHT.max};src:url(data:font/woff2;base64,${woff2.toString("base64")}) format("woff2");unicode-range:${unicode}}`;
|
|
3813
|
+
});
|
|
3814
|
+
})
|
|
3815
|
+
);
|
|
3816
|
+
return faces.join("");
|
|
3817
|
+
}
|
|
3818
|
+
var PLAYER = new URL("./player.global.js", importMetaUrl);
|
|
3819
|
+
function pageHtml(diagram, look, fontCss) {
|
|
3820
|
+
const json = JSON.stringify(diagram).replace(/</g, "\\u003c");
|
|
3821
|
+
const options = JSON.stringify({ palette: look.palette, theme: look.theme, lang: look.lang });
|
|
3822
|
+
return [
|
|
3823
|
+
"<!doctype html>",
|
|
3824
|
+
`<html lang="${look.lang}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">`,
|
|
3825
|
+
`<title>${esc(diagram.title)}</title>`,
|
|
3826
|
+
`<style>${fontCss}:root{${look.vars}}html,body{margin:0}body{background:var(--bg)}</style>`,
|
|
3827
|
+
'</head><body><div id="dragon"></div>',
|
|
3828
|
+
`<script type="application/json" id="dragon-diagram">${json}</script>`,
|
|
3829
|
+
`<script>${fs.readFileSync(PLAYER, "utf8").replace(/<\/script/gi, "<\\/script")}</script>`,
|
|
3830
|
+
`<script>DragonPlayer.mountDiagram(document.getElementById("dragon"),JSON.parse(document.getElementById("dragon-diagram").textContent),${options});</script>`,
|
|
3831
|
+
"</body></html>"
|
|
3832
|
+
].join("\n");
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3835
|
+
// src/export/index.ts
|
|
3836
|
+
var FORMATS = ["mp4", "gif", "html", "png"];
|
|
3837
|
+
var DEFAULTS = { fps: 30, gifFps: 10, followWidth: 728 };
|
|
3838
|
+
var unescape = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&/g, "&");
|
|
3839
|
+
var svgTexts = (svg) => [...svg.matchAll(/<text\b[^>]*>([\s\S]*?)<\/text>/g)].map((m) => unescape((m[1] ?? "").replace(/<[^>]+>/g, "")));
|
|
3840
|
+
function drawnTexts(rendered, followSvg) {
|
|
3841
|
+
const { diagram } = rendered;
|
|
3842
|
+
const svgs = followSvg === void 0 ? [rendered.svg] : [rendered.svg, followSvg];
|
|
3843
|
+
const count = diagram.steps.length;
|
|
3844
|
+
return [...svgs.flatMap(svgTexts), ...diagram.steps.flatMap((step, s) => [step.title, step.body, stepNo(s, count)]), ...Object.values(BUTTON_TEXT)];
|
|
3845
|
+
}
|
|
3846
|
+
async function exportDiagram(input, options) {
|
|
3847
|
+
const formats = options.formats ?? FORMATS;
|
|
3848
|
+
const lang = options.lang ?? "ja";
|
|
3849
|
+
const rendered = renderDiagram(input, {
|
|
3850
|
+
...options.palette ? { palette: options.palette } : {},
|
|
3851
|
+
...options.theme ? { theme: options.theme } : {},
|
|
3852
|
+
lang
|
|
3853
|
+
});
|
|
3854
|
+
const { diagram, layout, timeline, theme } = rendered;
|
|
3855
|
+
const palette = resolvePalette(rendered.palette);
|
|
3856
|
+
const vars = paletteVars(palette, theme);
|
|
3857
|
+
const width = options.width ?? (rendered.view === "follow" ? DEFAULTS.followWidth : layout.width);
|
|
3858
|
+
const view = chooseView(rendered, width).mode;
|
|
3859
|
+
const followSvg = rendered.view === "fixed" ? void 0 : drawSvg(diagram, layout, timeline, palette, theme, { width, lang });
|
|
3860
|
+
const videoSvg = view === "follow" && followSvg ? followSvg : rendered.svg;
|
|
3861
|
+
const fontCss = await fontFaces(charsOf(drawnTexts(rendered, followSvg)));
|
|
3862
|
+
const outputs = [];
|
|
3863
|
+
if (formats.includes("html")) outputs.push(["html", pageHtml(diagram, { palette: palette.id, theme, vars, lang }, fontCss)]);
|
|
3864
|
+
let frames = 0;
|
|
3865
|
+
const mp4 = formats.includes("mp4");
|
|
3866
|
+
const gif = formats.includes("gif");
|
|
3867
|
+
if (mp4 || gif || formats.includes("png")) {
|
|
3868
|
+
const browser = await launch(lang);
|
|
3869
|
+
try {
|
|
3870
|
+
if (formats.includes("png")) {
|
|
3871
|
+
const fixed = await stage(browser, rendered.svg, fontCss, "");
|
|
3872
|
+
outputs.push(["png", await still(fixed, timeline.stills[timeline.stills.length - 1] ?? 0)]);
|
|
3873
|
+
}
|
|
3874
|
+
if (mp4 || gif) {
|
|
3875
|
+
const fps = mp4 ? options.fps ?? DEFAULTS.fps : options.gifFps ?? DEFAULTS.gifFps;
|
|
3876
|
+
const gifEvery = gif ? Math.max(1, Math.round(fps / (options.gifFps ?? DEFAULTS.gifFps))) : 0;
|
|
3877
|
+
const shot = await film(await stage(browser, videoSvg, fontCss, `${vars};background:var(--bg)`), {
|
|
3878
|
+
total: timeline.total,
|
|
3879
|
+
fps,
|
|
3880
|
+
mp4,
|
|
3881
|
+
gifEvery,
|
|
3882
|
+
// GIF の色の表は、最初の絵と段ごとの止め絵から作る
|
|
3883
|
+
samples: [0, ...timeline.stills]
|
|
3884
|
+
});
|
|
3885
|
+
frames = shot.frames;
|
|
3886
|
+
if (shot.mp4) outputs.push(["mp4", shot.mp4]);
|
|
3887
|
+
if (shot.gif) outputs.push(["gif", shot.gif]);
|
|
3888
|
+
}
|
|
3889
|
+
} finally {
|
|
3890
|
+
await browser.close();
|
|
3891
|
+
}
|
|
3892
|
+
}
|
|
3893
|
+
const files = writeOutputs(options.outDir, options.name ?? "diagram", outputs);
|
|
3894
|
+
return { files, view, frames, ...sizeOf(videoSvg) };
|
|
3895
|
+
}
|
|
3896
|
+
function writeOutputs(outDir, name, outputs) {
|
|
3897
|
+
const created = fs.mkdirSync(outDir, { recursive: true });
|
|
3898
|
+
const files = {};
|
|
3899
|
+
try {
|
|
3900
|
+
for (const [format, data] of outputs) {
|
|
3901
|
+
const path$1 = path.join(outDir, `${name}.${format}`);
|
|
3902
|
+
fs.writeFileSync(path$1, data);
|
|
3903
|
+
files[format] = path$1;
|
|
3904
|
+
}
|
|
3905
|
+
} catch (error) {
|
|
3906
|
+
if (created !== void 0) fs.rmSync(created, { recursive: true, force: true });
|
|
3907
|
+
throw error;
|
|
3908
|
+
}
|
|
3909
|
+
return files;
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3912
|
+
// src/words.ts
|
|
3913
|
+
var WORDS = {
|
|
3914
|
+
/** 最初の行の図の種類 */
|
|
3915
|
+
kind: { sequence: { ja: "\u6642\u7CFB\u5217\u56F3", en: "sequence" }, architecture: { ja: "\u69CB\u6210\u56F3", en: "architecture" } },
|
|
3916
|
+
/** 段の見出しより前の行の頭 */
|
|
3917
|
+
head: {
|
|
3918
|
+
region: { ja: "\u533A\u753B", en: "region" },
|
|
3919
|
+
strip: { ja: "\u5E2F", en: "strip" },
|
|
3920
|
+
view: { ja: "\u898B\u305B\u65B9", en: "view" }
|
|
3921
|
+
},
|
|
3922
|
+
/** 行の終わりの `[<鍵> <値>]` の鍵 */
|
|
3923
|
+
attr: {
|
|
3924
|
+
color: { ja: "\u8272", en: "color" },
|
|
3925
|
+
icon: { ja: "\u5370", en: "icon" },
|
|
3926
|
+
region: { ja: "\u533A\u753B", en: "region" },
|
|
3927
|
+
label: { ja: "\u540D\u524D", en: "label" }
|
|
3928
|
+
},
|
|
3929
|
+
/** 線の上を走る物 */
|
|
3930
|
+
carry: {
|
|
3931
|
+
envelope: { ja: "\u5C01\u7B52", en: "envelope" },
|
|
3932
|
+
tag: { ja: "\u672D", en: "tag" },
|
|
3933
|
+
coin: { ja: "\u786C\u8CA8", en: "coin" },
|
|
3934
|
+
none: { ja: "\u306A\u3057", en: "none" }
|
|
3935
|
+
},
|
|
3936
|
+
/** 見せ方の値 */
|
|
3937
|
+
view: { fixed: { ja: "\u6B62\u3081\u308B", en: "fixed" }, follow: { ja: "\u5BC4\u308B", en: "follow" } },
|
|
3938
|
+
/** 線の名前を置く側 */
|
|
3939
|
+
side: {
|
|
3940
|
+
above: { ja: "\u4E0A", en: "above" },
|
|
3941
|
+
below: { ja: "\u4E0B", en: "below" },
|
|
3942
|
+
left: { ja: "\u5DE6", en: "left" },
|
|
3943
|
+
right: { ja: "\u53F3", en: "right" }
|
|
3944
|
+
}
|
|
3945
|
+
};
|
|
3946
|
+
function wordOf(group, value, lang) {
|
|
3947
|
+
return WORDS[group][value][lang];
|
|
3948
|
+
}
|
|
3949
|
+
function valueOf(group, word, lang) {
|
|
3950
|
+
const found = Object.entries(WORDS[group]).find(([, pair]) => pair[lang] === word);
|
|
3951
|
+
return found?.[0];
|
|
3952
|
+
}
|
|
3953
|
+
var otherLang = (lang) => lang === "ja" ? "en" : "ja";
|
|
3954
|
+
function languageOf(headLine) {
|
|
3955
|
+
const first = headLine.trim().split(/\s+/)[0] ?? "";
|
|
3956
|
+
return ["ja", "en"].find((lang) => valueOf("kind", first, lang) !== void 0);
|
|
3957
|
+
}
|
|
3958
|
+
function notationLanguage(notation) {
|
|
3959
|
+
const head = notation.split(/\r?\n/).map((line) => line.trim()).find((line) => line !== "" && !line.startsWith("//"));
|
|
3960
|
+
return head === void 0 ? void 0 : languageOf(head);
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
// src/messages.ts
|
|
3964
|
+
var ja2 = () => {
|
|
3965
|
+
const w = (group, value) => wordOf(group, value, "ja");
|
|
3966
|
+
return {
|
|
3967
|
+
noHead: `\u6700\u521D\u306E\u884C\u306B\u56F3\u306E\u7A2E\u985E (${w("kind", "sequence")} \u304B ${w("kind", "architecture")}) \u3068\u984C\u3092\u66F8\u304F`,
|
|
3968
|
+
badHead: `\u6700\u521D\u306E\u884C\u306F ${w("kind", "sequence")} \u304B ${w("kind", "architecture")} \u3067\u59CB\u3081\u3001\u7D9A\u3051\u3066\u984C\u3092\u66F8\u304F`,
|
|
3969
|
+
duplicate: (id) => `${id} \u306F\u65E2\u306B\u5BA3\u8A00\u3057\u305F\u540D\u672D`,
|
|
3970
|
+
undeclaredBox: (id) => `${id} \u3068\u3044\u3046\u7BB1\u306F\u5BA3\u8A00\u3057\u3066\u3044\u306A\u3044`,
|
|
3971
|
+
noBody: (title) => `\u6BB5\u300C${title}\u300D\u306B\u672C\u6587 (> \u3067\u59CB\u307E\u308B\u884C) \u304C\u8981\u308B`,
|
|
3972
|
+
emptyStepTitle: "\u6BB5\u306E\u898B\u51FA\u3057 (#) \u306B\u984C\u3092\u66F8\u304F",
|
|
3973
|
+
noBoxes: "\u7BB1\u3092 1 \u3064\u4EE5\u4E0A\u5BA3\u8A00\u3059\u308B",
|
|
3974
|
+
noSteps: "\u6BB5 (# \u3067\u59CB\u307E\u308B\u884C) \u3092 1 \u3064\u4EE5\u4E0A\u66F8\u304F",
|
|
3975
|
+
viewTwice: `${w("head", "view")}\u306F 1 \u884C\u3060\u3051\u66F8\u304F`,
|
|
3976
|
+
badView: `${w("head", "view")}\u306F ${w("view", "fixed")} \u304B ${w("view", "follow")}`,
|
|
3977
|
+
stripTwice: "\u4E2D\u8EAB\u306E\u5E2F\u306F 1 \u3064\u3060\u3051\u5BA3\u8A00\u3059\u308B",
|
|
3978
|
+
emptyStripField: "\u5E2F\u306E\u6B04\u306E\u540D\u524D\u304C\u7A7A",
|
|
3979
|
+
stepLineBeforeStep: "\u7DDA\u3084\u51E6\u7406\u306F\u6BB5\u306E\u898B\u51FA\u3057 (#) \u306E\u4E0B\u306B\u66F8\u304F",
|
|
3980
|
+
unreadableDeclaration: "\u8AAD\u3081\u306A\u3044\u884C\u3002\u7BB1\u306E\u5BA3\u8A00\u306F <\u540D\u672D> = <\u540D\u524D>\u300C<\u4E0B\u306E\u5C0F\u3055\u306A\u5B57>\u300D \u306E\u5F62\u3067\u66F8\u304F",
|
|
3981
|
+
emptyName: (id) => `${id} \u306E\u540D\u524D\u304C\u7A7A`,
|
|
3982
|
+
badColor: `${w("attr", "color")}\u306F ${COLORS.join(" / ")} \u306E\u3069\u308C\u304B`,
|
|
3983
|
+
regionFirst: (id) => `${w("attr", "region")} ${id} \u3092\u5148\u306B\u5BA3\u8A00\u3059\u308B`,
|
|
3984
|
+
badAttr: (raw) => `[${raw}] \u306F\u66F8\u3051\u306A\u3044\u6307\u5B9A`,
|
|
3985
|
+
codeTwice: "1 \u3064\u306E\u6BB5\u306B\u547D\u4EE4 (` \u3067\u56F2\u3093\u3060\u884C) \u306F 1 \u884C\u307E\u3067",
|
|
3986
|
+
declarationInStep: "\u7BB1\u306E\u5BA3\u8A00\u306F\u6700\u521D\u306E\u6BB5\u306E\u898B\u51FA\u3057 (#) \u3088\u308A\u524D\u306B\u66F8\u304F",
|
|
3987
|
+
emptySwap: "\u300C\u300D\u306E\u4E2D\u306B\u66F8\u304D\u63DB\u3048\u308B\u5B57\u3092\u66F8\u304F",
|
|
3988
|
+
unreadableStepLine: "\u8AAD\u3081\u306A\u3044\u884C\u3002\u7DDA\u306F <\u540D\u672D> -> <\u540D\u672D> : <\u7DDA\u306E\u540D\u524D>\u3001\u51E6\u7406\u306F <\u540D\u672D> : <\u51E6\u7406\u306E\u540D\u524D> \u306E\u5F62\u3067\u66F8\u304F",
|
|
3989
|
+
edgeShape: "\u7DDA\u306F <\u540D\u672D> -> <\u540D\u672D> : <\u7DDA\u306E\u540D\u524D> \u306E\u5F62\u3067\u66F8\u304F",
|
|
3990
|
+
carryTwice: "\u904B\u3076\u7269\u306F 1 \u672C\u306E\u7DDA\u306B 1 \u3064\u307E\u3067",
|
|
3991
|
+
tagNeedsValue: `${w("carry", "tag")}\u306B\u306F\u5024\u3092\u66F8\u304F ([${w("carry", "tag")} <\u5024>])`,
|
|
3992
|
+
carryTakesNoValue: (key) => `[${key}] \u306B\u306F\u5024\u3092\u66F8\u304B\u306A\u3044`,
|
|
3993
|
+
stripUndeclared: `\u5E2F\u306E\u5024\u3092\u66F8\u304F\u524D\u306B\u3001\u5E2F\u3092\u5BA3\u8A00\u3059\u308B (${w("head", "strip")} <\u984C> = <\u6B04>, <\u6B04>)`,
|
|
3994
|
+
stripTagOnce: "\u5E2F\u306E\u672D\u306F 1 \u3064\u307E\u3067",
|
|
3995
|
+
noSuchField: (field) => `${field} \u3068\u3044\u3046\u6B04\u306F\u5E2F\u306B\u7121\u3044`,
|
|
3996
|
+
stripNeedsValue: "\u5E2F\u306E\u6B04\u306B\u306F = <\u5024> \u304B [<\u672D>] \u3092\u66F8\u304F",
|
|
3997
|
+
otherLanguageWord: (word, own) => `\u3053\u306E\u56F3\u306F\u65E5\u672C\u8A9E\u306E\u8A9E\u3067\u66F8\u304F\u3002${word} \u3067\u306F\u306A\u304F ${own} \u3068\u66F8\u304F`
|
|
3998
|
+
};
|
|
3999
|
+
};
|
|
4000
|
+
var en2 = () => {
|
|
4001
|
+
const w = (group, value) => wordOf(group, value, "en");
|
|
4002
|
+
return {
|
|
4003
|
+
noHead: `Write the diagram kind (${w("kind", "sequence")} or ${w("kind", "architecture")}) and a title on the first line`,
|
|
4004
|
+
badHead: `Start the first line with ${w("kind", "sequence")} or ${w("kind", "architecture")}, followed by the title`,
|
|
4005
|
+
duplicate: (id) => `${id} is already declared`,
|
|
4006
|
+
undeclaredBox: (id) => `No box named ${id} is declared`,
|
|
4007
|
+
noBody: (title) => `Step "${title}" needs a body (a line starting with >)`,
|
|
4008
|
+
emptyStepTitle: "Write a title after the step heading (#)",
|
|
4009
|
+
noBoxes: "Declare at least one box",
|
|
4010
|
+
noSteps: "Write at least one step (a line starting with #)",
|
|
4011
|
+
viewTwice: `Write ${w("head", "view")} only once`,
|
|
4012
|
+
badView: `${w("head", "view")} is ${w("view", "fixed")} or ${w("view", "follow")}`,
|
|
4013
|
+
stripTwice: `Declare only one ${w("head", "strip")}`,
|
|
4014
|
+
emptyStripField: `A ${w("head", "strip")} field name is empty`,
|
|
4015
|
+
stepLineBeforeStep: "Write lines and actions under a step heading (#)",
|
|
4016
|
+
unreadableDeclaration: 'Cannot read this line. Declare a box as <id> = <name> "<caption>"',
|
|
4017
|
+
emptyName: (id) => `${id} has an empty name`,
|
|
4018
|
+
badColor: `${w("attr", "color")} is one of ${COLORS.join(" / ")}`,
|
|
4019
|
+
regionFirst: (id) => `Declare ${w("attr", "region")} ${id} first`,
|
|
4020
|
+
badAttr: (raw) => `[${raw}] cannot be written here`,
|
|
4021
|
+
codeTwice: "A step takes at most one command (a line in backticks)",
|
|
4022
|
+
declarationInStep: "Declare boxes before the first step heading (#)",
|
|
4023
|
+
emptySwap: 'Write the new caption inside "\u2026"',
|
|
4024
|
+
unreadableStepLine: "Cannot read this line. Write a line as <id> -> <id> : <label>, or an action as <id> : <action>",
|
|
4025
|
+
edgeShape: "Write a line as <id> -> <id> : <label>",
|
|
4026
|
+
carryTwice: "A line carries at most one thing",
|
|
4027
|
+
tagNeedsValue: `${w("carry", "tag")} needs a value ([${w("carry", "tag")} <value>])`,
|
|
4028
|
+
carryTakesNoValue: (key) => `[${key}] takes no value`,
|
|
4029
|
+
stripUndeclared: `Declare the ${w("head", "strip")} before writing its values (${w("head", "strip")} <title> = <field>, <field>)`,
|
|
4030
|
+
stripTagOnce: `A ${w("head", "strip")} value takes at most one tag`,
|
|
4031
|
+
noSuchField: (field) => `The ${w("head", "strip")} has no field named ${field}`,
|
|
4032
|
+
stripNeedsValue: `Write = <value> or [<tag>] after the ${w("head", "strip")} field`,
|
|
4033
|
+
otherLanguageWord: (word, own) => `This diagram uses English words. Write ${own} instead of ${word}`
|
|
4034
|
+
};
|
|
4035
|
+
};
|
|
4036
|
+
var MESSAGES = { ja: ja2(), en: en2() };
|
|
4037
|
+
var messagesFor = (lang) => MESSAGES[lang];
|
|
4038
|
+
|
|
4039
|
+
// src/tokenize.ts
|
|
4040
|
+
function columnOf(source, index) {
|
|
4041
|
+
return source.column + Array.from(source.text.slice(0, index)).length;
|
|
4042
|
+
}
|
|
4043
|
+
function tokenize(notation) {
|
|
4044
|
+
const lines = [];
|
|
4045
|
+
notation.split(/\r?\n/).forEach((raw, index) => {
|
|
4046
|
+
const text2 = raw.trim();
|
|
4047
|
+
if (text2 === "" || text2.startsWith("//")) return;
|
|
4048
|
+
const lead = raw.length - raw.trimStart().length;
|
|
4049
|
+
lines.push({ line: index + 1, column: Array.from(raw.slice(0, lead)).length + 1, text: text2 });
|
|
4050
|
+
});
|
|
4051
|
+
return lines;
|
|
4052
|
+
}
|
|
4053
|
+
|
|
4054
|
+
// src/parser.ts
|
|
4055
|
+
var NotationError = class extends Error {
|
|
4056
|
+
constructor(line, column, message) {
|
|
4057
|
+
super(message);
|
|
4058
|
+
this.line = line;
|
|
4059
|
+
this.column = column;
|
|
4060
|
+
}
|
|
4061
|
+
line;
|
|
4062
|
+
column;
|
|
4063
|
+
};
|
|
4064
|
+
var fail = (source, index, message) => new NotationError(source.line, columnOf(source, index), message);
|
|
4065
|
+
function trailingAttrs(source, start) {
|
|
4066
|
+
const attrs = [];
|
|
4067
|
+
let end = source.text.length;
|
|
4068
|
+
for (; ; ) {
|
|
4069
|
+
const found = /\s*\[([^[\]]*)\]$/.exec(source.text.slice(start, end));
|
|
4070
|
+
if (!found) break;
|
|
4071
|
+
const raw = (found[1] ?? "").trim();
|
|
4072
|
+
const [key = "", ...words] = raw.split(/\s+/);
|
|
4073
|
+
attrs.unshift({ raw, key, value: words.join(" "), at: start + found.index + found[0].indexOf("[") });
|
|
4074
|
+
end = start + found.index;
|
|
4075
|
+
}
|
|
4076
|
+
return { end, attrs };
|
|
4077
|
+
}
|
|
4078
|
+
var escape2 = (word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4079
|
+
var QUOTES = {
|
|
4080
|
+
ja: [["\u300C", "\u300D"]],
|
|
4081
|
+
en: [
|
|
4082
|
+
["\u300C", "\u300D"],
|
|
4083
|
+
['"', '"']
|
|
4084
|
+
]
|
|
4085
|
+
};
|
|
4086
|
+
function nameAndNote(text2, lang) {
|
|
4087
|
+
for (const [open, close] of QUOTES[lang]) {
|
|
4088
|
+
const found = new RegExp(`^(.*?)\\s*${escape2(open)}(.*)${escape2(close)}$`).exec(text2);
|
|
4089
|
+
if (found) return { name: (found[1] ?? "").trim(), note: found[2] ?? "" };
|
|
4090
|
+
}
|
|
4091
|
+
return { name: text2.trim() };
|
|
4092
|
+
}
|
|
4093
|
+
function swapLine(text2, lang) {
|
|
4094
|
+
const opens = QUOTES[lang].map(([o]) => escape2(o)).join("");
|
|
4095
|
+
for (const [open, close] of QUOTES[lang]) {
|
|
4096
|
+
const found = new RegExp(`^([^\\s${opens}]+)\\s*${escape2(open)}(.*)${escape2(close)}$`, "d").exec(text2);
|
|
4097
|
+
if (found) return found;
|
|
4098
|
+
}
|
|
4099
|
+
return null;
|
|
4100
|
+
}
|
|
4101
|
+
function headShapes(lang, reading) {
|
|
4102
|
+
const head = (key) => escape2(wordOf("head", key, lang));
|
|
4103
|
+
const opens = QUOTES[reading].map(([open]) => `|${escape2(open)}`).join("");
|
|
4104
|
+
return {
|
|
4105
|
+
view: new RegExp(`^${head("view")}\\s+(\\S+)$`),
|
|
4106
|
+
strip: new RegExp(`^${head("strip")}\\s+(.+?)\\s*=\\s*(.+)$`),
|
|
4107
|
+
region: new RegExp(`^${head("region")}\\s+([^\\s=]+)\\s*=\\s*`, "d"),
|
|
4108
|
+
// 空白を全部読んでから次の字を見る (`\s` を外すと、空白 2 つの `帯 -> 受け手` を帯の値と読む)
|
|
4109
|
+
stripValue: new RegExp(`^${head("strip")}\\s+(?!\\s|->|:|=${opens})`)
|
|
4110
|
+
};
|
|
4111
|
+
}
|
|
4112
|
+
function parseLines(lines, fallback) {
|
|
4113
|
+
const [head, ...rest] = lines;
|
|
4114
|
+
if (!head) throw new NotationError(1, 1, messagesFor(fallback).noHead);
|
|
4115
|
+
const found = languageOf(head.text);
|
|
4116
|
+
const m = messagesFor(found ?? fallback);
|
|
4117
|
+
const header = /^(\S+)\s+(.+)$/.exec(head.text);
|
|
4118
|
+
const kind = found && valueOf("kind", header?.[1] ?? "", found);
|
|
4119
|
+
if (!found || !header || !kind) throw fail(head, 0, m.badHead);
|
|
4120
|
+
const lang = found;
|
|
4121
|
+
const title = header[2] ?? "";
|
|
4122
|
+
const other = otherLang(lang);
|
|
4123
|
+
const own = headShapes(lang, lang);
|
|
4124
|
+
const foreign = headShapes(other, lang);
|
|
4125
|
+
const foreignWord = (source, at2, group, word) => fail(source, at2, m.otherLanguageWord(word, wordOf(group, valueOf(group, word, other), lang)));
|
|
4126
|
+
const regions = [];
|
|
4127
|
+
const boxes = [];
|
|
4128
|
+
const ids = /* @__PURE__ */ new Set();
|
|
4129
|
+
let strip2;
|
|
4130
|
+
let view;
|
|
4131
|
+
const steps = [];
|
|
4132
|
+
let building;
|
|
4133
|
+
const declare = (source, id, at2) => {
|
|
4134
|
+
if (ids.has(id)) throw fail(source, at2, m.duplicate(id));
|
|
4135
|
+
ids.add(id);
|
|
4136
|
+
};
|
|
4137
|
+
const boxAt = (source, id, at2) => {
|
|
4138
|
+
if (!boxes.some((box) => box.id === id)) throw fail(source, at2, m.undeclaredBox(id));
|
|
4139
|
+
return id;
|
|
4140
|
+
};
|
|
4141
|
+
const finish = () => {
|
|
4142
|
+
if (!building) return;
|
|
4143
|
+
if (building.body.length === 0) throw fail(building.source, 0, m.noBody(building.title));
|
|
4144
|
+
steps.push({
|
|
4145
|
+
title: building.title,
|
|
4146
|
+
body: building.body.join("\n"),
|
|
4147
|
+
...building.code !== void 0 ? { code: building.code } : {},
|
|
4148
|
+
events: building.events
|
|
4149
|
+
});
|
|
4150
|
+
};
|
|
4151
|
+
for (const source of rest) {
|
|
4152
|
+
const text2 = source.text;
|
|
4153
|
+
if (text2.startsWith("#")) {
|
|
4154
|
+
finish();
|
|
4155
|
+
const stepTitle = text2.slice(1).trim();
|
|
4156
|
+
if (stepTitle === "") throw fail(source, 0, m.emptyStepTitle);
|
|
4157
|
+
building = { source, title: stepTitle, body: [], events: [] };
|
|
4158
|
+
continue;
|
|
4159
|
+
}
|
|
4160
|
+
if (!building) {
|
|
4161
|
+
parseDeclaration(source);
|
|
4162
|
+
continue;
|
|
4163
|
+
}
|
|
4164
|
+
building.events.push(...parseStepLine(source, building));
|
|
4165
|
+
}
|
|
4166
|
+
finish();
|
|
4167
|
+
if (boxes.length === 0) throw fail(head, 0, m.noBoxes);
|
|
4168
|
+
if (steps.length === 0) throw fail(head, 0, m.noSteps);
|
|
4169
|
+
return {
|
|
4170
|
+
version: FORMAT_VERSION,
|
|
4171
|
+
kind,
|
|
4172
|
+
title,
|
|
4173
|
+
...view ? { view } : {},
|
|
4174
|
+
...regions.length > 0 ? { regions } : {},
|
|
4175
|
+
boxes,
|
|
4176
|
+
...strip2 ? { strip: strip2 } : {},
|
|
4177
|
+
steps,
|
|
4178
|
+
...kind === "sequence" ? { sequence: { lifelines: boxes.map((box) => box.id) } } : {}
|
|
4179
|
+
};
|
|
4180
|
+
function parseDeclaration(source) {
|
|
4181
|
+
const text2 = source.text;
|
|
4182
|
+
const viewDecl = own.view.exec(text2);
|
|
4183
|
+
if (viewDecl) {
|
|
4184
|
+
if (view) throw fail(source, 0, m.viewTwice);
|
|
4185
|
+
const word = viewDecl[1] ?? "";
|
|
4186
|
+
const at2 = text2.indexOf(word);
|
|
4187
|
+
const chosen = valueOf("view", word, lang);
|
|
4188
|
+
if (!chosen) {
|
|
4189
|
+
if (valueOf("view", word, other) !== void 0) throw foreignWord(source, at2, "view", word);
|
|
4190
|
+
throw fail(source, at2, m.badView);
|
|
4191
|
+
}
|
|
4192
|
+
view = chosen;
|
|
4193
|
+
return;
|
|
4194
|
+
}
|
|
4195
|
+
const stripDecl = own.strip.exec(text2);
|
|
4196
|
+
if (stripDecl) {
|
|
4197
|
+
if (strip2) throw fail(source, 0, m.stripTwice);
|
|
4198
|
+
const fields = (stripDecl[2] ?? "").split(",").map((field) => field.trim());
|
|
4199
|
+
if (fields.some((field) => field === "")) throw fail(source, 0, m.emptyStripField);
|
|
4200
|
+
strip2 = { title: stripDecl[1] ?? "", fields };
|
|
4201
|
+
return;
|
|
4202
|
+
}
|
|
4203
|
+
const regionDecl = own.region.exec(text2);
|
|
4204
|
+
const boxDecl = regionDecl ? void 0 : /^([^\s=]+)\s*=(?!>)\s*/d.exec(text2);
|
|
4205
|
+
const decl = regionDecl ?? boxDecl;
|
|
4206
|
+
if (!decl?.indices?.[1]) {
|
|
4207
|
+
if (foreign.view.test(text2) || foreign.strip.test(text2) || foreign.region.test(text2)) {
|
|
4208
|
+
throw foreignWord(source, 0, "head", text2.split(/\s+/)[0] ?? "");
|
|
4209
|
+
}
|
|
4210
|
+
if (looksLikeStepLine(text2, lang)) throw fail(source, 0, m.stepLineBeforeStep);
|
|
4211
|
+
throw fail(source, 0, m.unreadableDeclaration);
|
|
4212
|
+
}
|
|
4213
|
+
const id = decl[1] ?? "";
|
|
4214
|
+
declare(source, id, decl.indices[1][0]);
|
|
4215
|
+
const { end, attrs } = trailingAttrs(source, decl[0].length);
|
|
4216
|
+
const { name, note } = nameAndNote(text2.slice(decl[0].length, end), lang);
|
|
4217
|
+
if (name === "") throw fail(source, decl[0].length, m.emptyName(id));
|
|
4218
|
+
const look = {};
|
|
4219
|
+
for (const attr of attrs) {
|
|
4220
|
+
const key = valueOf("attr", attr.key, lang);
|
|
4221
|
+
if (key === "color") {
|
|
4222
|
+
if (!COLORS.includes(attr.value)) throw fail(source, attr.at, m.badColor);
|
|
4223
|
+
look.color = attr.value;
|
|
4224
|
+
} else if (key === "icon" && attr.value !== "") {
|
|
4225
|
+
look.icon = attr.value;
|
|
4226
|
+
} else if (key === "region" && !regionDecl) {
|
|
4227
|
+
if (!regions.some((region) => region.id === attr.value)) throw fail(source, attr.at, m.regionFirst(attr.value));
|
|
4228
|
+
look.region = attr.value;
|
|
4229
|
+
} else {
|
|
4230
|
+
if (valueOf("attr", attr.key, other) !== void 0) throw foreignWord(source, attr.at, "attr", attr.key);
|
|
4231
|
+
throw fail(source, attr.at, m.badAttr(attr.raw));
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
if (regionDecl) {
|
|
4235
|
+
regions.push({
|
|
4236
|
+
id,
|
|
4237
|
+
name,
|
|
4238
|
+
...note !== void 0 ? { note } : {},
|
|
4239
|
+
...look.color ? { color: look.color } : {},
|
|
4240
|
+
...look.icon ? { icon: look.icon } : {}
|
|
4241
|
+
});
|
|
4242
|
+
return;
|
|
4243
|
+
}
|
|
4244
|
+
boxes.push({
|
|
4245
|
+
id,
|
|
4246
|
+
name,
|
|
4247
|
+
...note !== void 0 ? { sub: note } : {},
|
|
4248
|
+
...look.color ? { color: look.color } : {},
|
|
4249
|
+
...look.icon ? { icon: look.icon } : {},
|
|
4250
|
+
...look.region ? { region: look.region } : {}
|
|
4251
|
+
});
|
|
4252
|
+
}
|
|
4253
|
+
function parseStepLine(source, step) {
|
|
4254
|
+
const text2 = source.text;
|
|
4255
|
+
if (text2.startsWith(">")) {
|
|
4256
|
+
step.body.push(text2.slice(1).trim());
|
|
4257
|
+
return [];
|
|
4258
|
+
}
|
|
4259
|
+
const code = /^`(.*)`$/.exec(text2);
|
|
4260
|
+
if (code) {
|
|
4261
|
+
if (step.code !== void 0) throw fail(source, 0, m.codeTwice);
|
|
4262
|
+
step.code = code[1] ?? "";
|
|
4263
|
+
return [];
|
|
4264
|
+
}
|
|
4265
|
+
if (own.stripValue.test(text2)) return [parseStripValue(source)];
|
|
4266
|
+
if (foreign.stripValue.test(text2)) throw foreignWord(source, 0, "head", text2.split(/\s+/)[0] ?? "");
|
|
4267
|
+
if (text2.includes("->")) return [parseEdge(source)];
|
|
4268
|
+
if (/^[^\s=]+\s*=(?!>)/.test(text2)) throw fail(source, 0, m.declarationInStep);
|
|
4269
|
+
const swap = swapLine(text2, lang);
|
|
4270
|
+
if (swap?.indices?.[1]) {
|
|
4271
|
+
const box = boxAt(source, swap[1] ?? "", swap.indices[1][0]);
|
|
4272
|
+
if ((swap[2] ?? "") === "") throw fail(source, swap.indices[1][1], m.emptySwap);
|
|
4273
|
+
return [{ type: "swap", box, text: swap[2] ?? "" }];
|
|
4274
|
+
}
|
|
4275
|
+
const action2 = /^([^\s:]+)\s*:\s*(.+)$/d.exec(text2);
|
|
4276
|
+
if (action2?.indices?.[1]) return [{ type: "action", box: boxAt(source, action2[1] ?? "", action2.indices[1][0]), label: action2[2] ?? "" }];
|
|
4277
|
+
throw fail(source, 0, m.unreadableStepLine);
|
|
4278
|
+
}
|
|
4279
|
+
function parseEdge(source) {
|
|
4280
|
+
const { end, attrs } = trailingAttrs(source, 0);
|
|
4281
|
+
const edge2 = /^([^\s:]+)\s*->\s*([^\s:]+)(?:\s*:\s*(.+))?$/d.exec(source.text.slice(0, end));
|
|
4282
|
+
if (!edge2?.indices?.[1] || !edge2.indices[2]) throw fail(source, 0, m.edgeShape);
|
|
4283
|
+
const from = boxAt(source, edge2[1] ?? "", edge2.indices[1][0]);
|
|
4284
|
+
const to = boxAt(source, edge2[2] ?? "", edge2.indices[2][0]);
|
|
4285
|
+
let carry;
|
|
4286
|
+
let labelSide;
|
|
4287
|
+
for (const attr of attrs) {
|
|
4288
|
+
const kind2 = valueOf("carry", attr.key, lang);
|
|
4289
|
+
const label2 = valueOf("attr", attr.key, lang) === "label";
|
|
4290
|
+
if (kind2 !== void 0) {
|
|
4291
|
+
if (carry) throw fail(source, attr.at, m.carryTwice);
|
|
4292
|
+
if (kind2 === "tag") {
|
|
4293
|
+
if (attr.value === "") throw fail(source, attr.at, m.tagNeedsValue);
|
|
4294
|
+
carry = { kind: kind2, text: attr.value };
|
|
4295
|
+
} else {
|
|
4296
|
+
if (attr.value !== "") throw fail(source, attr.at, m.carryTakesNoValue(attr.key));
|
|
4297
|
+
carry = { kind: kind2 };
|
|
4298
|
+
}
|
|
4299
|
+
} else if (label2 && valueOf("side", attr.value, lang) !== void 0) {
|
|
4300
|
+
labelSide = valueOf("side", attr.value, lang);
|
|
4301
|
+
} else {
|
|
4302
|
+
if (label2 && valueOf("side", attr.value, other) !== void 0) throw foreignWord(source, attr.at, "side", attr.value);
|
|
4303
|
+
if (valueOf("carry", attr.key, other) !== void 0) throw foreignWord(source, attr.at, "carry", attr.key);
|
|
4304
|
+
if (valueOf("attr", attr.key, other) !== void 0) throw foreignWord(source, attr.at, "attr", attr.key);
|
|
4305
|
+
throw fail(source, attr.at, m.badAttr(attr.raw));
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
return {
|
|
4309
|
+
type: "edge",
|
|
4310
|
+
from,
|
|
4311
|
+
to,
|
|
4312
|
+
...edge2[3] !== void 0 ? { label: edge2[3] } : {},
|
|
4313
|
+
carry: carry ?? { kind: "envelope" },
|
|
4314
|
+
...labelSide ? { labelSide } : {}
|
|
4315
|
+
};
|
|
4316
|
+
}
|
|
4317
|
+
function parseStripValue(source) {
|
|
4318
|
+
if (!strip2) throw fail(source, 0, m.stripUndeclared);
|
|
4319
|
+
const start = new RegExp(`^${escape2(wordOf("head", "strip", lang))}\\s+`).exec(source.text)?.[0].length ?? 0;
|
|
4320
|
+
const { end, attrs } = trailingAttrs(source, start);
|
|
4321
|
+
if (attrs.length > 1) throw fail(source, attrs[1]?.at ?? 0, m.stripTagOnce);
|
|
4322
|
+
const rest2 = source.text.slice(start, end);
|
|
4323
|
+
const assigned = /^(.+?)\s*=\s*(.+)$/.exec(rest2);
|
|
4324
|
+
const field = (assigned ? assigned[1] : rest2)?.trim() ?? "";
|
|
4325
|
+
if (!strip2.fields.includes(field)) throw fail(source, start, m.noSuchField(field));
|
|
4326
|
+
const tag = attrs[0]?.raw;
|
|
4327
|
+
if (!assigned && tag === void 0) throw fail(source, start, m.stripNeedsValue);
|
|
4328
|
+
return {
|
|
4329
|
+
type: "strip",
|
|
4330
|
+
field,
|
|
4331
|
+
...assigned ? { value: assigned[2] ?? "" } : {},
|
|
4332
|
+
...tag !== void 0 ? { tag } : {}
|
|
4333
|
+
};
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
function looksLikeStepLine(text2, lang) {
|
|
4337
|
+
return text2.startsWith(">") || text2.startsWith("`") || text2.includes("->") || swapLine(text2, lang) !== null;
|
|
4338
|
+
}
|
|
4339
|
+
function parseNotation(notation, options = {}) {
|
|
4340
|
+
try {
|
|
4341
|
+
return { ok: true, diagram: parseLines(tokenize(notation), options.lang ?? "ja") };
|
|
4342
|
+
} catch (error) {
|
|
4343
|
+
if (!(error instanceof NotationError)) throw error;
|
|
4344
|
+
return { ok: false, errors: [{ line: error.line, column: error.column, message: error.message }] };
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4347
|
+
|
|
4348
|
+
// src/cli.ts
|
|
4349
|
+
var OPTIONS = {
|
|
4350
|
+
out: { type: "string" },
|
|
4351
|
+
width: { type: "string" },
|
|
4352
|
+
palette: { type: "string" },
|
|
4353
|
+
theme: { type: "string" },
|
|
4354
|
+
lang: { type: "string" },
|
|
4355
|
+
fps: { type: "string" },
|
|
4356
|
+
"gif-fps": { type: "string" },
|
|
4357
|
+
format: { type: "string" }
|
|
4358
|
+
};
|
|
4359
|
+
var THEMES = ["light", "dark"];
|
|
4360
|
+
var PALETTE_NAMES = Object.keys(PALETTES).join(" / ");
|
|
4361
|
+
var CLI_TEXT = {
|
|
4362
|
+
ja: {
|
|
4363
|
+
usage: [
|
|
4364
|
+
"\u4F7F\u3044\u65B9: dragon export <\u56F3\u306E file (.json \u304B .dragon)> [\u8A2D\u5B9A]",
|
|
4365
|
+
" --out <dir> \u66F8\u304D\u51FA\u3059\u5148 (\u65E2\u5B9A\u306F\u4ECA\u306E dir)",
|
|
4366
|
+
" --width <px> \u67A0\u306E\u5E45\u3002\u898B\u305B\u65B9\u3092\u9078\u3073\u3001\u5BC4\u3063\u3066\u898B\u305B\u308B\u7A93\u306E\u5E45\u306B\u306A\u308B",
|
|
4367
|
+
` --palette <\u540D\u524D> \u8272\u5473 (${PALETTE_NAMES})`,
|
|
4368
|
+
" --theme <\u660E\u6697> light \u304B dark",
|
|
4369
|
+
" --lang <\u8A00\u8449> \u56F3\u306E\u4E2D\u306E\u5B57\u3068\u547D\u4EE4\u306E\u6587\u306E\u8A00\u8449 (ja \u304B en)\u3002\u65E2\u5B9A\u306F\u8A18\u6CD5\u306E file \u306E\u8A00\u8449\u3067\u3001JSON \u306F ja",
|
|
4370
|
+
" --fps <\u6570> mp4 \u306E 1 \u79D2\u306E\u30B3\u30DE\u306E\u6570 (\u65E2\u5B9A 30)",
|
|
4371
|
+
" --gif-fps <\u6570> GIF \u306E 1 \u79D2\u306E\u30B3\u30DE\u306E\u6570 (\u65E2\u5B9A 10)",
|
|
4372
|
+
" --format <\u5F62> \u66F8\u304D\u51FA\u3059\u5F62\u3092 , \u3067\u533A\u5207\u308B (\u65E2\u5B9A mp4,gif,html,png)"
|
|
4373
|
+
].join("\n"),
|
|
4374
|
+
unknownOption: (name) => `\u77E5\u3089\u306A\u3044\u8A2D\u5B9A: ${name}`,
|
|
4375
|
+
missingValue: (name) => `\u8A2D\u5B9A\u306B\u5024\u304C\u7121\u3044: ${name}`,
|
|
4376
|
+
extraFiles: (extra) => `\u56F3\u306E file \u306F 1 \u3064\u3060\u3051\u6E21\u3059\u3002\u4F59\u5206\u306A\u5F15\u6570: ${extra.join(" ")}`,
|
|
4377
|
+
noFile: (path) => `\u56F3\u306E file \u304C\u7121\u3044: ${path}`,
|
|
4378
|
+
unreadable: (path, detail2) => `\u56F3\u306E file \u3092\u8AAD\u3081\u306A\u3044: ${path} (${detail2})`,
|
|
4379
|
+
badJson: (path, detail2) => `JSON \u3068\u3057\u3066\u8AAD\u3081\u306A\u3044: ${path} (${detail2})`,
|
|
4380
|
+
cannotWrite: (path, detail2) => `\u66F8\u304D\u51FA\u305B\u306A\u3044: ${path} (${detail2})`,
|
|
4381
|
+
badValue: (option, value, allowed) => `\u4F7F\u3048\u306A\u3044\u5024: ${option} ${value} (${allowed})`,
|
|
4382
|
+
allowed: { lang: "ja \u304B en", theme: "light \u304B dark", positive: "0 \u3088\u308A\u5927\u304D\u3044\u6570", format: `${FORMATS.join(" / ")} \u3092 , \u3067\u533A\u5207\u308B` }
|
|
4383
|
+
},
|
|
4384
|
+
en: {
|
|
4385
|
+
usage: [
|
|
4386
|
+
"Usage: dragon export <diagram file (.json or .dragon)> [options]",
|
|
4387
|
+
" --out <dir> Where to write (default: the current dir)",
|
|
4388
|
+
" --width <px> Frame width. Picks the view and sets the window width when following",
|
|
4389
|
+
` --palette <name> Colors (${PALETTE_NAMES})`,
|
|
4390
|
+
" --theme <mode> light or dark",
|
|
4391
|
+
" --lang <lang> Language of the diagram text and command messages (ja or en). Defaults to the notation file's language, and ja for JSON",
|
|
4392
|
+
" --fps <n> Frames per second of the mp4 (default 30)",
|
|
4393
|
+
" --gif-fps <n> Frames per second of the GIF (default 10)",
|
|
4394
|
+
" --format <list> Formats to write, separated by , (default mp4,gif,html,png)"
|
|
4395
|
+
].join("\n"),
|
|
4396
|
+
unknownOption: (name) => `Unknown option: ${name}`,
|
|
4397
|
+
missingValue: (name) => `Option needs a value: ${name}`,
|
|
4398
|
+
extraFiles: (extra) => `Pass only one diagram file. Extra arguments: ${extra.join(" ")}`,
|
|
4399
|
+
noFile: (path) => `No such diagram file: ${path}`,
|
|
4400
|
+
unreadable: (path, detail2) => `Cannot read the diagram file: ${path} (${detail2})`,
|
|
4401
|
+
badJson: (path, detail2) => `Cannot read as JSON: ${path} (${detail2})`,
|
|
4402
|
+
cannotWrite: (path, detail2) => `Cannot write: ${path} (${detail2})`,
|
|
4403
|
+
badValue: (option, value, allowed) => `Invalid value: ${option} ${value} (${allowed})`,
|
|
4404
|
+
allowed: { lang: "ja or en", theme: "light or dark", positive: "a number above 0", format: `${FORMATS.join(" / ")} separated by ,` }
|
|
4405
|
+
}
|
|
4406
|
+
};
|
|
4407
|
+
var isLang = (value) => value === "ja" || value === "en";
|
|
4408
|
+
var number = (value) => value === void 0 ? void 0 : Number(value);
|
|
4409
|
+
var detail = (error) => error instanceof Error ? error.message : String(error);
|
|
4410
|
+
function langOf(args) {
|
|
4411
|
+
for (const [i, arg] of args.entries()) {
|
|
4412
|
+
if (arg === "--lang") return args[i + 1];
|
|
4413
|
+
if (arg.startsWith("--lang=")) return arg.slice("--lang=".length);
|
|
4414
|
+
}
|
|
4415
|
+
return void 0;
|
|
4416
|
+
}
|
|
4417
|
+
function optionProblem(args, text2) {
|
|
4418
|
+
const { tokens } = util.parseArgs({ args, options: OPTIONS, allowPositionals: true, strict: false, tokens: true });
|
|
4419
|
+
for (const token of tokens) {
|
|
4420
|
+
if (token.kind !== "option") continue;
|
|
4421
|
+
if (!Object.hasOwn(OPTIONS, token.name)) return text2.unknownOption(token.rawName);
|
|
4422
|
+
if (token.value === void 0 || !token.inlineValue && token.value.startsWith("-")) return text2.missingValue(token.rawName);
|
|
4423
|
+
}
|
|
4424
|
+
return void 0;
|
|
4425
|
+
}
|
|
4426
|
+
function valueProblem(values, text2) {
|
|
4427
|
+
const bad = (name, value, allowed) => text2.badValue(`--${name}`, value, allowed);
|
|
4428
|
+
if (values.lang !== void 0 && !isLang(values.lang)) return bad("lang", values.lang, text2.allowed.lang);
|
|
4429
|
+
if (values.theme !== void 0 && !THEMES.some((theme) => theme === values.theme)) return bad("theme", values.theme, text2.allowed.theme);
|
|
4430
|
+
if (values.palette !== void 0 && !Object.hasOwn(PALETTES, values.palette)) return bad("palette", values.palette, PALETTE_NAMES);
|
|
4431
|
+
if (values.format !== void 0 && !values.format.split(",").every((format) => FORMATS.some((known) => known === format))) {
|
|
4432
|
+
return bad("format", values.format, text2.allowed.format);
|
|
4433
|
+
}
|
|
4434
|
+
for (const name of ["width", "fps", "gif-fps"]) {
|
|
4435
|
+
const value = values[name];
|
|
4436
|
+
if (value !== void 0 && !(Number.isFinite(Number(value)) && Number(value) > 0)) return bad(name, value, text2.allowed.positive);
|
|
4437
|
+
}
|
|
4438
|
+
return void 0;
|
|
4439
|
+
}
|
|
4440
|
+
function failedPath(error) {
|
|
4441
|
+
if (!(error instanceof Error) || !("syscall" in error) || !("path" in error)) return void 0;
|
|
4442
|
+
return typeof error.path === "string" ? error.path : void 0;
|
|
4443
|
+
}
|
|
4444
|
+
function read(file, text2) {
|
|
4445
|
+
let source;
|
|
4446
|
+
try {
|
|
4447
|
+
source = fs.readFileSync(file, "utf8");
|
|
4448
|
+
} catch (error) {
|
|
4449
|
+
const missing = error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
4450
|
+
throw new Error(missing ? text2.noFile(file) : text2.unreadable(file, detail(error)));
|
|
4451
|
+
}
|
|
4452
|
+
if (path.extname(file) !== ".dragon") {
|
|
4453
|
+
try {
|
|
4454
|
+
return { diagram: JSON.parse(source) };
|
|
4455
|
+
} catch (error) {
|
|
4456
|
+
throw new Error(text2.badJson(file, detail(error)));
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
4459
|
+
const parsed = parseNotation(source);
|
|
4460
|
+
if (!parsed.ok) throw new Error(parsed.errors.map((e) => `${file}:${e.line} ${e.message}`).join("\n"));
|
|
4461
|
+
const lang = notationLanguage(source);
|
|
4462
|
+
return lang === void 0 ? { diagram: parsed.diagram } : { diagram: parsed.diagram, lang };
|
|
4463
|
+
}
|
|
4464
|
+
async function main(argv) {
|
|
4465
|
+
const [command, ...rest] = argv;
|
|
4466
|
+
const chosen = langOf(argv);
|
|
4467
|
+
const early = CLI_TEXT[isLang(chosen) ? chosen : "ja"];
|
|
4468
|
+
if (command !== "export") {
|
|
4469
|
+
console.error(early.usage);
|
|
4470
|
+
return 2;
|
|
4471
|
+
}
|
|
4472
|
+
const problem = optionProblem(rest, early);
|
|
4473
|
+
if (problem !== void 0) {
|
|
4474
|
+
console.error(`${problem}
|
|
4475
|
+
${early.usage}`);
|
|
4476
|
+
return 2;
|
|
4477
|
+
}
|
|
4478
|
+
const { values, positionals } = util.parseArgs({ args: rest, options: OPTIONS, allowPositionals: true });
|
|
4479
|
+
const badValue = valueProblem(values, early);
|
|
4480
|
+
if (badValue !== void 0) {
|
|
4481
|
+
console.error(`${badValue}
|
|
4482
|
+
${early.usage}`);
|
|
4483
|
+
return 2;
|
|
4484
|
+
}
|
|
4485
|
+
const [file, ...extra] = positionals;
|
|
4486
|
+
if (!file) {
|
|
4487
|
+
console.error(early.usage);
|
|
4488
|
+
return 2;
|
|
4489
|
+
}
|
|
4490
|
+
if (extra.length > 0) {
|
|
4491
|
+
console.error(`${early.extraFiles(extra)}
|
|
4492
|
+
${early.usage}`);
|
|
4493
|
+
return 2;
|
|
4494
|
+
}
|
|
4495
|
+
const width = number(values.width);
|
|
4496
|
+
const fps = number(values.fps);
|
|
4497
|
+
const gifFps = number(values["gif-fps"]);
|
|
4498
|
+
const { diagram, lang: fileLang } = read(file, early);
|
|
4499
|
+
const lang = isLang(chosen) ? chosen : fileLang;
|
|
4500
|
+
let result;
|
|
4501
|
+
try {
|
|
4502
|
+
result = await exportDiagram(diagram, {
|
|
4503
|
+
outDir: path.resolve(values.out ?? "."),
|
|
4504
|
+
name: path.basename(file, path.extname(file)),
|
|
4505
|
+
...values.format ? { formats: values.format.split(",") } : {},
|
|
4506
|
+
...width === void 0 ? {} : { width },
|
|
4507
|
+
...values.palette ? { palette: values.palette } : {},
|
|
4508
|
+
...values.theme ? { theme: values.theme } : {},
|
|
4509
|
+
...lang ? { lang } : {},
|
|
4510
|
+
...fps === void 0 ? {} : { fps },
|
|
4511
|
+
...gifFps === void 0 ? {} : { gifFps }
|
|
4512
|
+
});
|
|
4513
|
+
} catch (error) {
|
|
4514
|
+
const path = failedPath(error);
|
|
4515
|
+
if (path !== void 0) throw new Error(CLI_TEXT[lang ?? "ja"].cannotWrite(path, detail(error)));
|
|
4516
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
4517
|
+
}
|
|
4518
|
+
for (const path of Object.values(result.files)) console.log(path);
|
|
4519
|
+
return 0;
|
|
4520
|
+
}
|
|
4521
|
+
main(process.argv.slice(2)).then(
|
|
4522
|
+
(code) => process.exit(code),
|
|
4523
|
+
(error) => {
|
|
4524
|
+
console.error(detail(error));
|
|
4525
|
+
process.exit(1);
|
|
4526
|
+
}
|
|
4527
|
+
);
|
|
4528
|
+
//# sourceMappingURL=cli.cjs.map
|
|
4529
|
+
//# sourceMappingURL=cli.cjs.map
|