fastdraw 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +193 -2
- package/agents/AGENTS-snippet.md +10 -0
- package/agents/README.md +11 -0
- package/agents/claude-skill/fastdraw/SKILL.md +14 -0
- package/dist/cli.js +3694 -0
- package/fonts/Geist-Medium.ttf +0 -0
- package/fonts/Geist-Regular.ttf +0 -0
- package/fonts/Geist-SemiBold.ttf +0 -0
- package/fonts/GeistMono-Medium.ttf +0 -0
- package/fonts/GeistMono-Regular.ttf +0 -0
- package/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/fonts/InstrumentSerif-Regular.ttf +0 -0
- package/fonts/LibreFranklin-Bold.ttf +0 -0
- package/fonts/LibreFranklin-Medium.ttf +0 -0
- package/fonts/LibreFranklin-Regular.ttf +0 -0
- package/fonts/LibreFranklin-SemiBold.ttf +0 -0
- package/fonts/Newsreader-Italic.ttf +0 -0
- package/fonts/Newsreader-Medium.ttf +0 -0
- package/fonts/Newsreader-Regular.ttf +0 -0
- package/fonts/Newsreader-SemiBold.ttf +0 -0
- package/fonts/OFL-Geist.txt +93 -0
- package/fonts/OFL-InstrumentSerif.txt +93 -0
- package/fonts/OFL-LibreFranklin.txt +93 -0
- package/fonts/OFL-Newsreader.txt +93 -0
- package/fonts/OFL-SketchHand.txt +49 -0
- package/fonts/SketchHand-Regular.ttf +0 -0
- package/guide/architecture-delta.md +52 -0
- package/guide/architecture.md +28 -0
- package/guide/axonometric-plan.md +54 -0
- package/guide/bar.md +61 -0
- package/guide/data-flow.md +42 -0
- package/guide/db-schema.md +46 -0
- package/guide/dependency.md +38 -0
- package/guide/deployment.md +46 -0
- package/guide/er.md +49 -0
- package/guide/exploded.md +53 -0
- package/guide/fishbone.md +44 -0
- package/guide/flowchart.md +22 -0
- package/guide/gantt.md +48 -0
- package/guide/guide.md +278 -0
- package/guide/heatmap.md +59 -0
- package/guide/high-level.md +38 -0
- package/guide/integration.md +33 -0
- package/guide/it-state.md +33 -0
- package/guide/journey.md +35 -0
- package/guide/kanban.md +53 -0
- package/guide/layers.md +49 -0
- package/guide/line.md +112 -0
- package/guide/look.md +174 -0
- package/guide/loop.md +45 -0
- package/guide/medallion.md +37 -0
- package/guide/nested.md +36 -0
- package/guide/org-chart.md +48 -0
- package/guide/polar.md +57 -0
- package/guide/process.md +41 -0
- package/guide/pyramid.md +46 -0
- package/guide/quadrant.md +44 -0
- package/guide/radar.md +60 -0
- package/guide/sankey.md +53 -0
- package/guide/scatter.md +73 -0
- package/guide/security-matrix.md +47 -0
- package/guide/sequence.md +39 -0
- package/guide/state.md +38 -0
- package/guide/story-map.md +29 -0
- package/guide/swimlane.md +40 -0
- package/guide/timeline.md +49 -0
- package/guide/tree.md +33 -0
- package/guide/treemap.md +67 -0
- package/guide/uml-class.md +59 -0
- package/guide/venn.md +48 -0
- package/guide/wardley.md +35 -0
- package/guide/waterfall.md +47 -0
- package/package.json +59 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,3694 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, readdirSync as readdirSync3, existsSync as existsSync4 } from "node:fs";
|
|
5
|
+
import { dirname as dirname4, join as join3, resolve as resolve3, basename } from "node:path";
|
|
6
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7
|
+
|
|
8
|
+
// src/node.ts
|
|
9
|
+
import { readFileSync, readdirSync, existsSync } from "node:fs";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
// src/fontmeta.ts
|
|
13
|
+
function fontMeta(b) {
|
|
14
|
+
try {
|
|
15
|
+
const dv = new DataView(b.buffer, b.byteOffset, b.byteLength);
|
|
16
|
+
const tag = dv.getUint32(0);
|
|
17
|
+
if (tag !== 65536 && tag !== 1330926671 && tag !== 1953658213) return null;
|
|
18
|
+
const tables = /* @__PURE__ */ new Map();
|
|
19
|
+
const n = dv.getUint16(4);
|
|
20
|
+
if (12 + n * 16 > b.length) return null;
|
|
21
|
+
for (let i = 0; i < n; i++) {
|
|
22
|
+
const o = 12 + i * 16;
|
|
23
|
+
tables.set(String.fromCharCode(b[o], b[o + 1], b[o + 2], b[o + 3]), dv.getUint32(o + 8));
|
|
24
|
+
}
|
|
25
|
+
const name2 = tables.get("name");
|
|
26
|
+
if (name2 === void 0) return null;
|
|
27
|
+
if (name2 + 6 > b.length) return null;
|
|
28
|
+
const count = dv.getUint16(name2 + 2), store = name2 + dv.getUint16(name2 + 4);
|
|
29
|
+
if (name2 + 6 + count * 12 > b.length) return null;
|
|
30
|
+
const found = /* @__PURE__ */ new Map();
|
|
31
|
+
for (let i = 0; i < count && found.size < 4; i++) {
|
|
32
|
+
const r = name2 + 6 + i * 12;
|
|
33
|
+
const platform = dv.getUint16(r), id = dv.getUint16(r + 6), len = dv.getUint16(r + 8), off = store + dv.getUint16(r + 10);
|
|
34
|
+
if (id !== 1 && id !== 16 || platform !== 3 && platform !== 0 && platform !== 1) continue;
|
|
35
|
+
if (found.has(id * 10 + (platform === 1 ? 1 : 0)) || len > 256 || off + len > b.length) continue;
|
|
36
|
+
let s = "";
|
|
37
|
+
if (platform === 1) for (let k = 0; k < len; k++) s += String.fromCharCode(b[off + k]);
|
|
38
|
+
else for (let k = 0; k + 1 < len; k += 2) s += String.fromCharCode(dv.getUint16(off + k));
|
|
39
|
+
const key = id * 10 + (platform === 1 ? 1 : 0);
|
|
40
|
+
if (s && !found.has(key)) found.set(key, s);
|
|
41
|
+
}
|
|
42
|
+
const family = found.get(160) ?? found.get(161) ?? found.get(10) ?? found.get(11);
|
|
43
|
+
if (!family) return null;
|
|
44
|
+
const os2 = tables.get("OS/2");
|
|
45
|
+
const hasOs2 = os2 !== void 0 && os2 + 64 <= b.length;
|
|
46
|
+
const weight = hasOs2 ? dv.getUint16(os2 + 4) : 400;
|
|
47
|
+
const italic = hasOs2 ? (dv.getUint16(os2 + 62) & 1) === 1 : false;
|
|
48
|
+
return { family, weight: weight >= 1 && weight <= 1e3 ? weight : 400, italic };
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/node.ts
|
|
55
|
+
import { dirname, resolve } from "node:path";
|
|
56
|
+
|
|
57
|
+
// src/parse.ts
|
|
58
|
+
function stripComment(s) {
|
|
59
|
+
let inQ = false;
|
|
60
|
+
for (let i = 0; i < s.length; i++) {
|
|
61
|
+
const c = s[i];
|
|
62
|
+
if (c === "\\" && inQ) {
|
|
63
|
+
i++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (c === '"') inQ = !inQ;
|
|
67
|
+
else if (!inQ && c === "/" && s[i + 1] === "/") return s.slice(0, i);
|
|
68
|
+
}
|
|
69
|
+
return s;
|
|
70
|
+
}
|
|
71
|
+
function tokenize(s) {
|
|
72
|
+
const out = [];
|
|
73
|
+
let i = 0;
|
|
74
|
+
const n = s.length;
|
|
75
|
+
while (i < n) {
|
|
76
|
+
while (i < n && /\s/.test(s[i])) i++;
|
|
77
|
+
if (i >= n) break;
|
|
78
|
+
const startsQuoted = s[i] === '"';
|
|
79
|
+
const start = i;
|
|
80
|
+
let buf = "";
|
|
81
|
+
let inQ = false;
|
|
82
|
+
while (i < n && (inQ || !/\s/.test(s[i]))) {
|
|
83
|
+
const c = s[i];
|
|
84
|
+
if (c === '"') inQ = !inQ;
|
|
85
|
+
else if (c === "\\" && inQ && i + 1 < n) {
|
|
86
|
+
i++;
|
|
87
|
+
buf += s[i] === "n" ? "\n" : s[i];
|
|
88
|
+
} else buf += c;
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
if (startsQuoted) {
|
|
92
|
+
out.push({ t: "str", v: buf });
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const m = /^([A-Za-z][\w./#-]*)=([\s\S]*)$/.exec(buf);
|
|
96
|
+
if (m) out.push(s[start + m[1].length + 1] === '"' ? { t: "prop", k: m[1], v: m[2], q: true } : { t: "prop", k: m[1], v: m[2] });
|
|
97
|
+
else out.push({ t: "word", v: buf });
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
function parseStatements(src) {
|
|
102
|
+
const stmts = [];
|
|
103
|
+
const lines = src.split(/\r?\n/);
|
|
104
|
+
lines.forEach((raw, idx) => {
|
|
105
|
+
const trimmed = raw.trim();
|
|
106
|
+
if (!trimmed) return;
|
|
107
|
+
if (trimmed === "#" || trimmed.startsWith("# ")) return;
|
|
108
|
+
const text = stripComment(raw);
|
|
109
|
+
if (!text.trim()) return;
|
|
110
|
+
const toks = tokenize(text);
|
|
111
|
+
if (/^\s/.test(raw) && stmts.length) {
|
|
112
|
+
const last = stmts[stmts.length - 1];
|
|
113
|
+
last.toks.push(...toks);
|
|
114
|
+
last.end = idx + 1;
|
|
115
|
+
} else stmts.push({ line: idx + 1, end: idx + 1, toks });
|
|
116
|
+
});
|
|
117
|
+
return stmts;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/defaultLook.ts
|
|
121
|
+
var DEFAULT_LOOK = `// FastDraw default look. Copy it with "fastdraw init-look" and change anything.
|
|
122
|
+
// A cool light page, white cards with rounded corners and a two-tone icon, softly tinted zones,
|
|
123
|
+
// slate greys for everything else and one indigo for the subject and the main path. Geist for names and details, Geist Mono for small technical labels.
|
|
124
|
+
|
|
125
|
+
canvas paper=paper dots=ink/0.07 dotgap=24
|
|
126
|
+
|
|
127
|
+
color paper #f6f7fb
|
|
128
|
+
color card #ffffff
|
|
129
|
+
color ink #0f172a
|
|
130
|
+
color muted #475569
|
|
131
|
+
color soft #94a3b8
|
|
132
|
+
color accent #4f46e5
|
|
133
|
+
color link #0284c7
|
|
134
|
+
color teal #0d9488
|
|
135
|
+
color amber #d97706
|
|
136
|
+
color rose #e11d48
|
|
137
|
+
color violet #7c3aed
|
|
138
|
+
|
|
139
|
+
font sans "Geist"
|
|
140
|
+
font mono "Geist Mono"
|
|
141
|
+
font serif "Newsreader"
|
|
142
|
+
|
|
143
|
+
// ---- boxes ----------------------------------------------------------------
|
|
144
|
+
style node shape=rect radius=10 size=144x64 fill=#ffffff stroke=ink/0.14 sw=1 sub.font=sans sub.color=muted
|
|
145
|
+
tag.color=muted tag.border=ink/0.18 tag.font=mono icon.color=accent icon.fill=accent/0.14
|
|
146
|
+
use="default box: a backend, service, component or step"
|
|
147
|
+
style focal extends node fill=#ffffff stroke=accent sw=2 title.color=accent
|
|
148
|
+
tag.color=accent tag.border=accent/0.4 ghost.color=accent/0.10
|
|
149
|
+
use="the one or two elements the diagram is about"
|
|
150
|
+
style store extends node shape=path stroke=ink/0.18 icon.color=violet icon.fill=violet/0.14 tag.color=violet tag.border=violet/0.4
|
|
151
|
+
path="M0,0.1 C0,-0.035 1,-0.035 1,0.1 L1,0.9 C1,1.035 0,1.035 0,0.9 Z M0,0.1 C0,0.235 1,0.235 1,0.1 C1,0.235 0,0.235 0,0.1"
|
|
152
|
+
use="something that holds data or state"
|
|
153
|
+
style cloud extends node stroke=link/0.45 icon.color=link icon.fill=link/0.14 tag.color=link tag.border=link/0.4
|
|
154
|
+
use="a hosted or third-party platform"
|
|
155
|
+
style external extends node stroke=ink/0.28 dash=5,4 icon.color=muted icon.fill=ink/0.06
|
|
156
|
+
use="a person or system outside what you own"
|
|
157
|
+
style optional extends node fill=#ffffff/0.7 stroke=ink/0.22 dash=3,3 tag.color=soft tag.border=ink/0.18
|
|
158
|
+
use="optional or asynchronous participant"
|
|
159
|
+
style sticky extends node radius=4 size=120x120 fill=#fff7d6 stroke=amber/0.35 tag.color=ink tag.border=ink/0.3
|
|
160
|
+
use="a yellow sticky note: an idea, comment or open question"
|
|
161
|
+
style sticky-orange extends sticky fill=#ffe4e6 stroke=rose/0.35 use="an orange sticky note: a risk or issue"
|
|
162
|
+
style sticky-violet extends sticky fill=#ede9fe stroke=violet/0.35 use="a violet sticky note: a decision or note"
|
|
163
|
+
|
|
164
|
+
// ---- flowchart shapes -----------------------------------------------------
|
|
165
|
+
style step extends node size=160x48 use="flowchart action"
|
|
166
|
+
style terminal extends node radius=24 size=160x48 fill=#ffffff stroke=ink/0.30
|
|
167
|
+
use="flowchart start or end"
|
|
168
|
+
style terminal-focal extends terminal stroke=accent sw=2 title.color=accent
|
|
169
|
+
use="the flowchart outcome that matters most"
|
|
170
|
+
style decision shape=diamond size=200x96 fill=#ffffff stroke=ink/0.30 sw=1
|
|
171
|
+
use="flowchart yes/no question; put the text on two short lines"
|
|
172
|
+
|
|
173
|
+
// ---- regions and markers --------------------------------------------------
|
|
174
|
+
style zone shape=rect radius=16 fill=ink/0.025 stroke=ink/0.12 sw=1 layer=back
|
|
175
|
+
title.pos=top title.align=left title.font=sans title.size=11 title.weight=600 title.color=muted title.spacing=0 title.caps=0
|
|
176
|
+
use="a labelled region drawn behind a group of boxes; always give WxH"
|
|
177
|
+
style bar shape=rect radius=2 size=8x80 fill=accent/0.10 stroke=accent/0.6 sw=1
|
|
178
|
+
use="sequence diagram activation bar, centred on a lifeline; always give WxH"
|
|
179
|
+
|
|
180
|
+
style table shape=table radius=10 fill=#ffffff stroke=ink/0.16 sw=1 head.fill=accent/0.08 rule=ink/0.08
|
|
181
|
+
cell.font=mono cell.size=10 detail.color=muted
|
|
182
|
+
use="an entity, class or database table: a header and rows. One line per row: | id \\"name\\" \\"type\\" \\"key\\". Arrows can end on a row: orders.user_id -> users.id"
|
|
183
|
+
style matrix extends table align=center grid=1 cell.font=sans
|
|
184
|
+
use="a grid of values: first row with |= for the column headings, first cell of each row is its name"
|
|
185
|
+
style chart shape=chart fill=none stroke=ink/0.5 sw=1 mask=0 bar.radius=2 grid.color=ink/0.08
|
|
186
|
+
tick.font=mono tick.size=9 tick.color=muted
|
|
187
|
+
use="axes with your numbers drawn for you: chart at x,y WxH x=\\"Q1,Q2,Q3\\" y=0..100, then a line per series: | bars \\"Revenue\\" 42 61 75"
|
|
188
|
+
|
|
189
|
+
// ---- lines ----------------------------------------------------------------
|
|
190
|
+
style arrow line stroke=ink/0.45 sw=1.4 route=ortho radius=8 label.font=sans label.size=10 label.color=muted label.spacing=0 label.caps=0
|
|
191
|
+
use="default arrow"
|
|
192
|
+
style primary extends arrow stroke=accent sw=2 label.color=accent use="the main path; at most two per diagram"
|
|
193
|
+
style link extends arrow stroke=link label.color=link use="an HTTP or API request crossing a boundary"
|
|
194
|
+
style return extends arrow dash=5,4 use="a response, or something optional or asynchronous"
|
|
195
|
+
style relation extends relation stroke=ink/0.5 label.font=sans label.size=10 label.spacing=0 label.caps=0
|
|
196
|
+
style lifeline line head=none stroke=ink/0.20 sw=1 dash=4,4 route=straight use="sequence diagram lifeline"
|
|
197
|
+
style rule line head=none stroke=ink/0.10 sw=1 route=straight use="thin separator, e.g. above a legend"
|
|
198
|
+
|
|
199
|
+
// ---- text -----------------------------------------------------------------
|
|
200
|
+
style h1 text font=sans size=26 weight=600 color=ink use="diagram title"
|
|
201
|
+
style kicker text font=mono size=10 weight=500 color=accent spacing=0.12 caps=1 use="optional: a short category above the title, e.g. PROCESS"
|
|
202
|
+
style dek text font=sans size=14 color=muted use="optional: one line under the title saying what the diagram shows"
|
|
203
|
+
style eyebrow text font=mono size=8 color=muted spacing=0.14 caps=1 use="small caps label, e.g. LEGEND"
|
|
204
|
+
style caption text font=sans size=9.5 color=muted use="small explanatory text"
|
|
205
|
+
style legend extends legend rule=ink/0.1 title.font=mono item.size=9.5
|
|
206
|
+
style note text font=sans size=13 color=muted use="a short aside; at most two"
|
|
207
|
+
style small text font=mono size=9 color=muted use="technical detail: a port, path or command"
|
|
208
|
+
|
|
209
|
+
guidance "focal, terminal-focal and primary are the accent. Use the accent on at most two things in one diagram."
|
|
210
|
+
guidance "Never fill a shape with ink to make it stand out; use the accent, or a tint such as accent/0.14."
|
|
211
|
+
guidance "tag= is a 3 or 4 letter type marker in the corner of a box (EXT, EDGE, API, DB). Use it on architecture boxes, not flowchart shapes."
|
|
212
|
+
guidance "sub= is a short second line of detail: a product name, path, port or protocol. Names of things go in the main text."
|
|
213
|
+
guidance "kicker and dek are optional. Add a kicker only when the diagram belongs to a named category, and a dek only when there is one clear message; most diagrams need neither."
|
|
214
|
+
guidance "Finish with a legend: one statement, 'legend at x,y' followed by style=\\"what it means\\" for each style you used."
|
|
215
|
+
`;
|
|
216
|
+
|
|
217
|
+
// src/icons.ts
|
|
218
|
+
var ICONS = {
|
|
219
|
+
"active-directory": ["M20 6v12a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2", "M10 16h6", "M11 11a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M4 8h3", "M4 12h3", "M4 16h3"],
|
|
220
|
+
"admin": ["M6 21v-2a4 4 0 0 1 4 -4h2", "M22 16c0 4 -2.5 6 -3.5 6s-3.5 -2 -3.5 -6c1 0 2.5 -.5 3.5 -1.5c1 1 2.5 1.5 3.5 1.5", "M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0"],
|
|
221
|
+
"ai": ["M15.5 13a3.5 3.5 0 0 0 -3.5 3.5v1a3.5 3.5 0 0 0 7 0v-1.8", "M8.5 13a3.5 3.5 0 0 1 3.5 3.5v1a3.5 3.5 0 0 1 -7 0v-1.8", "M17.5 16a3.5 3.5 0 0 0 0 -7h-.5", "M19 9.3v-2.8a3.5 3.5 0 0 0 -7 0", "M6.5 16a3.5 3.5 0 0 1 0 -7h.5", "M5 9.3v-2.8a3.5 3.5 0 0 1 7 0v10"],
|
|
222
|
+
"alert": ["M12 9v4", "M10.363 3.591l-8.106 13.534a1.914 1.914 0 0 0 1.636 2.871h16.214a1.914 1.914 0 0 0 1.636 -2.87l-8.106 -13.536a1.914 1.914 0 0 0 -3.274 0", "M12 16h.01"],
|
|
223
|
+
"antenna": ["M20 4v8", "M16 4.5v7", "M12 5v16", "M8 5.5v5", "M4 6v4", "M20 8h-16"],
|
|
224
|
+
"api": ["M7 4a2 2 0 0 0 -2 2v3a2 3 0 0 1 -2 3a2 3 0 0 1 2 3v3a2 2 0 0 0 2 2", "M17 4a2 2 0 0 1 2 2v3a2 3 0 0 0 2 3a2 3 0 0 0 -2 3v3a2 2 0 0 1 -2 2"],
|
|
225
|
+
"app": ["M3 5m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z", "M6 8h.01", "M9 8h.01"],
|
|
226
|
+
"archive": ["M3 4m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z", "M5 8v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-10", "M10 12l4 0"],
|
|
227
|
+
"audit": ["M14 3v4a1 1 0 0 0 1 1h4", "M12 21h-5a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v4.5", "M16.5 17.5m-2.5 0a2.5 2.5 0 1 0 5 0a2.5 2.5 0 1 0 -5 0", "M18.5 19.5l2.5 2.5"],
|
|
228
|
+
"backup": ["M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2", "M10 14a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M14 4l0 4l-6 0l0 -4"],
|
|
229
|
+
"bank": ["M3 21l18 0", "M3 10l18 0", "M5 6l7 -3l7 3", "M4 10l0 11", "M20 10l0 11", "M8 14l0 3", "M12 14l0 3", "M16 14l0 3"],
|
|
230
|
+
"bell": ["M10 5a2 2 0 1 1 4 0a7 7 0 0 1 4 6v3a4 4 0 0 0 2 3h-16a4 4 0 0 0 2 -3v-3a7 7 0 0 1 4 -6", "M9 17v1a3 3 0 0 0 6 0v-1"],
|
|
231
|
+
"book": ["M3 19a9 9 0 0 1 9 0a9 9 0 0 1 9 0", "M3 6a9 9 0 0 1 9 0a9 9 0 0 1 9 0", "M3 6l0 13", "M12 6l0 13", "M21 6l0 13"],
|
|
232
|
+
"box": ["M12 3l8 4.5l0 9l-8 4.5l-8 -4.5l0 -9l8 -4.5", "M12 12l8 -4.5", "M12 12l0 9", "M12 12l-8 -4.5"],
|
|
233
|
+
"broadcast": ["M18.364 19.364a9 9 0 1 0 -12.728 0", "M15.536 16.536a5 5 0 1 0 -7.072 0", "M12 13m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"],
|
|
234
|
+
"browser": ["M4 4m0 1a1 1 0 0 1 1 -1h14a1 1 0 0 1 1 1v14a1 1 0 0 1 -1 1h-14a1 1 0 0 1 -1 -1z", "M4 8l16 0", "M8 4l0 4"],
|
|
235
|
+
"bucket": ["M4 7a8 4 0 1 0 16 0a8 4 0 1 0 -16 0", "M4 7c0 .664 .088 1.324 .263 1.965l2.737 10.035c.5 1.5 2.239 2 5 2s4.5 -.5 5 -2c.333 -1 1.246 -4.345 2.737 -10.035a7.45 7.45 0 0 0 .263 -1.965"],
|
|
236
|
+
"bug": ["M9 9v-1a3 3 0 0 1 6 0v1", "M8 9h8a6 6 0 0 1 1 3v3a5 5 0 0 1 -10 0v-3a6 6 0 0 1 1 -3", "M3 13l4 0", "M17 13l4 0", "M12 20l0 -6", "M4 19l3.35 -2", "M20 19l-3.35 -2", "M4 7l3.75 2.4", "M20 7l-3.75 2.4"],
|
|
237
|
+
"building": ["M3 21l18 0", "M9 8l1 0", "M9 12l1 0", "M9 16l1 0", "M14 8l1 0", "M14 12l1 0", "M14 16l1 0", "M5 21v-16a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v16"],
|
|
238
|
+
"cache": ["M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11"],
|
|
239
|
+
"calendar": ["M4 7a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12z", "M16 3v4", "M8 3v4", "M4 11h16", "M11 15h1", "M12 15v3"],
|
|
240
|
+
"camera": ["M5 7h1a2 2 0 0 0 2 -2a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1a2 2 0 0 0 2 2h1a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2", "M9 13a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"],
|
|
241
|
+
"cart": ["M6 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M17 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M17 17h-11v-14h-2", "M6 5l14 1l-1 7h-13"],
|
|
242
|
+
"cdn": ["M19.5 7a9 9 0 0 0 -7.5 -4a8.991 8.991 0 0 0 -7.484 4", "M11.5 3a16.989 16.989 0 0 0 -1.826 4", "M12.5 3a16.989 16.989 0 0 1 1.828 4", "M19.5 17a9 9 0 0 1 -7.5 4a8.991 8.991 0 0 1 -7.484 -4", "M11.5 21a16.989 16.989 0 0 1 -1.826 -4", "M12.5 21a16.989 16.989 0 0 0 1.828 -4", "M2 10l1 4l1.5 -4l1.5 4l1 -4", "M17 10l1 4l1.5 -4l1.5 4l1 -4", "M9.5 10l1 4l1.5 -4l1.5 4l1 -4"],
|
|
243
|
+
"certificate": ["M15 15m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0", "M13 17.5v4.5l2 -1.5l2 1.5v-4.5", "M10 19h-5a2 2 0 0 1 -2 -2v-10c0 -1.1 .9 -2 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -1 1.73", "M6 9l12 0", "M6 12l3 0", "M6 15l2 0"],
|
|
244
|
+
"chart": ["M3 13a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v6a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z", "M15 9a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v10a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z", "M9 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v14a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1z", "M4 20h14"],
|
|
245
|
+
"chat": ["M21 14l-3 -3h-7a1 1 0 0 1 -1 -1v-6a1 1 0 0 1 1 -1h9a1 1 0 0 1 1 1v10", "M14 15v2a1 1 0 0 1 -1 1h-7l-3 3v-10a1 1 0 0 1 1 -1h2"],
|
|
246
|
+
"check": ["M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0", "M9 12l2 2l4 -4"],
|
|
247
|
+
"clock": ["M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", "M12 7v5l3 3"],
|
|
248
|
+
"cloud": ["M6.657 18c-2.572 0 -4.657 -2.007 -4.657 -4.483c0 -2.475 2.085 -4.482 4.657 -4.482c.393 -1.762 1.794 -3.2 3.675 -3.773c1.88 -.572 3.956 -.193 5.444 1c1.488 1.19 2.162 3.007 1.77 4.769h.99c1.913 0 3.464 1.56 3.464 3.486c0 1.927 -1.551 3.487 -3.465 3.487h-11.878"],
|
|
249
|
+
"code": ["M7 8l-4 4l4 4", "M17 8l4 4l-4 4", "M14 4l-4 16"],
|
|
250
|
+
"container": ["M12 3l8 4.5l0 9l-8 4.5l-8 -4.5l0 -9l8 -4.5", "M12 12l8 -4.5", "M12 12l0 9", "M12 12l-8 -4.5", "M16 5.25l-8 4.5"],
|
|
251
|
+
"cpu": ["M5 5m0 1a1 1 0 0 1 1 -1h12a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-12a1 1 0 0 1 -1 -1z", "M9 9h6v6h-6z", "M3 10h2", "M3 14h2", "M10 3v2", "M14 3v2", "M21 10h-2", "M21 14h-2", "M14 21v-2", "M10 21v-2"],
|
|
252
|
+
"csv": ["M14 3v4a1 1 0 0 0 1 1h4", "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", "M7 16.5a1.5 1.5 0 0 0 -3 0v3a1.5 1.5 0 0 0 3 0", "M10 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75", "M16 15l2 6l2 -6"],
|
|
253
|
+
"dashboard": ["M5 4h4a1 1 0 0 1 1 1v6a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1v-6a1 1 0 0 1 1 -1", "M5 16h4a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1", "M15 12h4a1 1 0 0 1 1 1v6a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1v-6a1 1 0 0 1 1 -1", "M15 4h4a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1"],
|
|
254
|
+
"database": ["M4 6a8 3 0 1 0 16 0a8 3 0 1 0 -16 0", "M4 6v6a8 3 0 0 0 16 0v-6", "M4 12v6a8 3 0 0 0 16 0v-6"],
|
|
255
|
+
"deployment": ["M4 13a8 8 0 0 1 7 7a6 6 0 0 0 3 -5a9 9 0 0 0 6 -8a3 3 0 0 0 -3 -3a9 9 0 0 0 -8 6a6 6 0 0 0 -5 3", "M7 14a6 6 0 0 0 -3 6a6 6 0 0 0 6 -3", "M14 9a1 1 0 1 0 2 0a1 1 0 1 0 -2 0"],
|
|
256
|
+
"desktop": ["M3 5a1 1 0 0 1 1 -1h16a1 1 0 0 1 1 1v10a1 1 0 0 1 -1 1h-16a1 1 0 0 1 -1 -1v-10", "M7 20h10", "M9 16v4", "M15 16v4"],
|
|
257
|
+
"dns": ["M6.5 7.5a1 1 0 1 0 2 0a1 1 0 1 0 -2 0", "M3 6v5.172a2 2 0 0 0 .586 1.414l7.71 7.71a2.41 2.41 0 0 0 3.408 0l5.592 -5.592a2.41 2.41 0 0 0 0 -3.408l-7.71 -7.71a2 2 0 0 0 -1.414 -.586h-5.172a3 3 0 0 0 -3 3"],
|
|
258
|
+
"document": ["M14 3v4a1 1 0 0 0 1 1h4", "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2z", "M9 9l1 0", "M9 13l6 0", "M9 17l6 0"],
|
|
259
|
+
"download": ["M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2", "M7 11l5 5l5 -5", "M12 4l0 12"],
|
|
260
|
+
"error": ["M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0", "M10 10l4 4m0 -4l-4 4"],
|
|
261
|
+
"excel": ["M14 3v4a1 1 0 0 0 1 1h4", "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", "M4 15l4 6", "M4 21l4 -6", "M17 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75", "M11 15v6h3"],
|
|
262
|
+
"eye": ["M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0", "M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6"],
|
|
263
|
+
"factory": ["M4 21c1.147 -4.02 1.983 -8.027 2 -12h6c.017 3.973 .853 7.98 2 12", "M12.5 13h4.5c.025 2.612 .894 5.296 2 8", "M9 5a2.4 2.4 0 0 1 2 -1a2.4 2.4 0 0 1 2 1a2.4 2.4 0 0 0 2 1a2.4 2.4 0 0 0 2 -1a2.4 2.4 0 0 1 2 -1a2.4 2.4 0 0 1 2 1", "M3 21l19 0"],
|
|
264
|
+
"file": ["M14 3v4a1 1 0 0 0 1 1h4", "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2"],
|
|
265
|
+
"filter": ["M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227z"],
|
|
266
|
+
"fingerprint": ["M18.9 7a8 8 0 0 1 1.1 5v1a6 6 0 0 0 .8 3", "M8 11a4 4 0 0 1 8 0v1a10 10 0 0 0 2 6", "M12 11v2a14 14 0 0 0 2.5 8", "M8 15a18 18 0 0 0 1.8 6", "M4.9 19a22 22 0 0 1 -.9 -7v-1a8 8 0 0 1 12 -6.95"],
|
|
267
|
+
"firewall": ["M4 6a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2l0 -12", "M4 8h16", "M20 12h-16", "M4 16h16", "M9 4v4", "M14 8v4", "M8 12v4", "M16 12v4", "M11 16v4"],
|
|
268
|
+
"flag": ["M5 5a5 5 0 0 1 7 0a5 5 0 0 0 7 0v9a5 5 0 0 1 -7 0a5 5 0 0 0 -7 0v-9z", "M5 21v-7"],
|
|
269
|
+
"folder": ["M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2"],
|
|
270
|
+
"function": ["M6 20l6.5 -9", "M19 20c-6 0 -6 -16 -12 -16"],
|
|
271
|
+
"gateway": ["M13 12v.01", "M3 21h18", "M5 21v-16a2 2 0 0 1 2 -2h6m4 10.5v7.5", "M21 7h-7m3 -3l-3 3l3 3"],
|
|
272
|
+
"git-branch": ["M5 18a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M5 6a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M15 6a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M7 8l0 8", "M9 18h6a2 2 0 0 0 2 -2v-5", "M14 14l3 -3l3 3"],
|
|
273
|
+
"git-commit": ["M12 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0", "M12 3l0 6", "M12 15l0 6"],
|
|
274
|
+
"git-merge": ["M7 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M7 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M17 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M7 8l0 8", "M7 8a4 4 0 0 0 4 4h4"],
|
|
275
|
+
"git-pull-request": ["M6 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M6 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M18 18m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M6 8l0 8", "M11 6h5a2 2 0 0 1 2 2v8", "M14 9l-3 -3l3 -3"],
|
|
276
|
+
"hierarchy": ["M12 5m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M5 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M19 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M6.5 17.5l5.5 -4.5l5.5 4.5", "M12 7l0 6"],
|
|
277
|
+
"home": ["M5 12l-2 0l9 -9l9 9l-2 0", "M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7", "M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6"],
|
|
278
|
+
"id": ["M3 4m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v10a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z", "M9 10m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M15 8l2 0", "M15 12l2 0", "M7 16l10 0"],
|
|
279
|
+
"idea": ["M3 12h1m8 -9v1m8 8h1m-15.4 -6.4l.7 .7m12.1 -.7l-.7 .7", "M9 16a5 5 0 1 1 6 0a3.5 3.5 0 0 0 -1 3a2 2 0 0 1 -4 0a3.5 3.5 0 0 0 -1 -3", "M9.7 17l4.6 0"],
|
|
280
|
+
"image": ["M15 8h.01", "M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12z", "M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5", "M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3"],
|
|
281
|
+
"info": ["M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", "M12 9h.01", "M11 12h1v4h1"],
|
|
282
|
+
"ingress": ["M8 12h13", "M18 9l3 3l-3 3", "M5.5 9.5l-2.5 2.5l2.5 2.5l2.5 -2.5l-2.5 -2.5"],
|
|
283
|
+
"internet": ["M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", "M3.6 9h16.8", "M3.6 15h16.8", "M11.5 3a17 17 0 0 0 0 18", "M12.5 3a17 17 0 0 1 0 18"],
|
|
284
|
+
"key": ["M16.555 3.843l3.602 3.602a2.877 2.877 0 0 1 0 4.069l-2.643 2.643a2.877 2.877 0 0 1 -4.069 0l-.301 -.301l-6.558 6.558a2 2 0 0 1 -1.239 .578l-.175 .008h-1.172a1 1 0 0 1 -.993 -.883l-.007 -.117v-1.172a2 2 0 0 1 .467 -1.284l.119 -.13l.414 -.414h2v-2h2v-2l2.144 -2.144l-.301 -.301a2.877 2.877 0 0 1 0 -4.069l2.643 -2.643a2.877 2.877 0 0 1 4.069 0", "M15 9h.01"],
|
|
285
|
+
"laptop": ["M3 19l18 0", "M5 7a1 1 0 0 1 1 -1h12a1 1 0 0 1 1 1v8a1 1 0 0 1 -1 1h-12a1 1 0 0 1 -1 -1l0 -8"],
|
|
286
|
+
"list": ["M9 6l11 0", "M9 12l11 0", "M9 18l11 0", "M5 6l0 .01", "M5 12l0 .01", "M5 18l0 .01"],
|
|
287
|
+
"load-balancer": ["M21 17h-8l-3.5 -5h-6.5", "M21 7h-8l-3.495 5", "M18 10l3 -3l-3 -3", "M18 20l3 -3l-3 -3"],
|
|
288
|
+
"location": ["M9 11a3 3 0 1 0 6 0a3 3 0 0 0 -6 0", "M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0z"],
|
|
289
|
+
"lock": ["M5 13a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-6", "M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0", "M8 11v-4a4 4 0 1 1 8 0v4"],
|
|
290
|
+
"log": ["M14 3v4a1 1 0 0 0 1 1h4", "M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2", "M9 9l1 0", "M9 13l6 0", "M9 17l6 0"],
|
|
291
|
+
"mail": ["M3 7a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10z", "M3 7l9 6l9 -6"],
|
|
292
|
+
"message": ["M8 9h8", "M8 13h6", "M18 4a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-5l-5 3v-3h-2a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3h12z"],
|
|
293
|
+
"money": ["M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0", "M14.8 9a2 2 0 0 0 -1.8 -1h-2a2 2 0 1 0 0 4h2a2 2 0 1 1 0 4h-2a2 2 0 0 1 -1.8 -1", "M12 7v10"],
|
|
294
|
+
"monitoring": ["M4 19l16 0", "M4 15l4 -6l4 2l4 -5l4 4"],
|
|
295
|
+
"network": ["M6 9a6 6 0 1 0 12 0a6 6 0 0 0 -12 0", "M12 3c1.333 .333 2 2.333 2 6s-.667 5.667 -2 6", "M12 3c-1.333 .333 -2 2.333 -2 6s.667 5.667 2 6", "M6 9h12", "M3 20h7", "M14 20h7", "M10 20a2 2 0 1 0 4 0a2 2 0 0 0 -4 0", "M12 15v3"],
|
|
296
|
+
"node": ["M8 18a2 2 0 1 0 -4 0a2 2 0 0 0 4 0", "M20 6a2 2 0 1 0 -4 0a2 2 0 0 0 4 0", "M8 6a2 2 0 1 0 -4 0a2 2 0 0 0 4 0", "M20 18a2 2 0 1 0 -4 0a2 2 0 0 0 4 0", "M14 12a2 2 0 1 0 -4 0a2 2 0 0 0 4 0", "M7.5 7.5l3 3", "M7.5 16.5l3 -3", "M13.5 13.5l3 3", "M16.5 7.5l-3 3"],
|
|
297
|
+
"notebook": ["M6 4h11a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-11a1 1 0 0 1 -1 -1v-14a1 1 0 0 1 1 -1m3 0v18", "M13 8l2 0", "M13 12l2 0"],
|
|
298
|
+
"package": ["M12 3l8 4.5l0 9l-8 4.5l-8 -4.5l0 -9l8 -4.5", "M12 12l8 -4.5", "M12 12l0 9", "M12 12l-8 -4.5", "M16 5.25l-8 4.5"],
|
|
299
|
+
"password": ["M12 10v4", "M10 13l4 -2", "M10 11l4 2", "M5 10v4", "M3 13l4 -2", "M3 11l4 2", "M19 10v4", "M17 13l4 -2", "M17 11l4 2"],
|
|
300
|
+
"payment": ["M3 5m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z", "M3 10l18 0", "M7 15l.01 0", "M11 15l2 0"],
|
|
301
|
+
"phone": ["M6 5a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-14", "M11 4h2", "M12 17v.01"],
|
|
302
|
+
"pipeline": ["M5 18a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M5 6a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M15 12a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M7 8l0 8", "M7 8a4 4 0 0 0 4 4h4"],
|
|
303
|
+
"plug": ["M9.785 6l8.215 8.215l-2.054 2.054a5.81 5.81 0 1 1 -8.215 -8.215l2.054 -2.054z", "M4 20l3.5 -3.5", "M15 4l-3.5 3.5", "M20 9l-3.5 3.5"],
|
|
304
|
+
"plugin": ["M4 7h3a1 1 0 0 0 1 -1v-1a2 2 0 0 1 4 0v1a1 1 0 0 0 1 1h3a1 1 0 0 1 1 1v3a1 1 0 0 0 1 1h1a2 2 0 0 1 0 4h-1a1 1 0 0 0 -1 1v3a1 1 0 0 1 -1 1h-3a1 1 0 0 1 -1 -1v-1a2 2 0 0 0 -4 0v1a1 1 0 0 1 -1 1h-3a1 1 0 0 1 -1 -1v-3a1 1 0 0 1 1 -1h1a2 2 0 0 0 0 -4h-1a1 1 0 0 1 -1 -1v-3a1 1 0 0 1 1 -1"],
|
|
305
|
+
"pod": ["M19.875 6.27a2.225 2.225 0 0 1 1.125 1.948v7.284c0 .809 -.443 1.555 -1.158 1.948l-6.75 4.27a2.269 2.269 0 0 1 -2.184 0l-6.75 -4.27a2.225 2.225 0 0 1 -1.158 -1.948v-7.285c0 -.809 .443 -1.554 1.158 -1.947l6.75 -3.98a2.33 2.33 0 0 1 2.25 0l6.75 3.98h-.033"],
|
|
306
|
+
"printer": ["M17 17h2a2 2 0 0 0 2 -2v-4a2 2 0 0 0 -2 -2h-14a2 2 0 0 0 -2 2v4a2 2 0 0 0 2 2h2", "M17 9v-4a2 2 0 0 0 -2 -2h-6a2 2 0 0 0 -2 2v4", "M7 13m0 2a2 2 0 0 1 2 -2h6a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-6a2 2 0 0 1 -2 -2z"],
|
|
307
|
+
"question": ["M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", "M12 16v.01", "M12 13a2 2 0 0 0 .914 -3.782a1.98 1.98 0 0 0 -2.414 .483"],
|
|
308
|
+
"queue": ["M12 4l-8 4l8 4l8 -4l-8 -4", "M4 12l8 4l8 -4", "M4 16l8 4l8 -4"],
|
|
309
|
+
"report": ["M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2", "M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z", "M9 17v-5", "M12 17v-1", "M15 17v-3"],
|
|
310
|
+
"request": ["M5 12l14 0", "M13 18l6 -6", "M13 6l6 6"],
|
|
311
|
+
"response": ["M5 12l14 0", "M5 12l6 6", "M5 12l6 -6"],
|
|
312
|
+
"robot": ["M6 6a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2l0 -4", "M12 2v2", "M9 12v9", "M15 12v9", "M5 16l4 -2", "M15 14l4 2", "M9 18h6", "M10 8v.01", "M14 8v.01"],
|
|
313
|
+
"route": ["M3 19a2 2 0 1 0 4 0a2 2 0 0 0 -4 0", "M19 7a2 2 0 1 0 0 -4a2 2 0 0 0 0 4z", "M11 19h5.5a3.5 3.5 0 0 0 0 -7h-8a3.5 3.5 0 0 1 0 -7h4.5"],
|
|
314
|
+
"router": ["M3 13m0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v4a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z", "M17 17l0 .01", "M13 17l0 .01", "M15 13l0 -2", "M11.75 8.75a4 4 0 0 1 6.5 0", "M8.5 6.5a8 8 0 0 1 13 0"],
|
|
315
|
+
"scheduler": ["M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4", "M18 18m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0", "M15 3v4", "M7 3v4", "M3 11h16", "M18 16.496v1.504l1 1"],
|
|
316
|
+
"search": ["M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0", "M21 21l-6 -6"],
|
|
317
|
+
"server": ["M3 7a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v2a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3", "M3 15a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v2a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3l0 -2", "M7 8l0 .01", "M7 16l0 .01"],
|
|
318
|
+
"service": ["M21 12a9 9 0 1 0 -8.979 9", "M3.6 9h16.8", "M3.6 15h8.9", "M11.5 3a17 17 0 0 0 0 18", "M12.5 3a16.992 16.992 0 0 1 2.522 10.376", "M17.001 19a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M19.001 15.5v1.5", "M19.001 21v1.5", "M22.032 17.25l-1.299 .75", "M17.27 20l-1.3 .75", "M15.97 17.25l1.3 .75", "M20.733 20l1.3 .75"],
|
|
319
|
+
"settings": ["M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z", "M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"],
|
|
320
|
+
"shield": ["M12 3a12 12 0 0 0 8.5 3a12 12 0 0 1 -8.5 15a12 12 0 0 1 -8.5 -15a12 12 0 0 0 8.5 -3"],
|
|
321
|
+
"sparkles": ["M16 18a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2zm0 -12a2 2 0 0 1 2 2a2 2 0 0 1 2 -2a2 2 0 0 1 -2 -2a2 2 0 0 1 -2 2zm-7 12a6 6 0 0 1 6 -6a6 6 0 0 1 -6 -6a6 6 0 0 1 -6 6a6 6 0 0 1 6 6z"],
|
|
322
|
+
"sql": ["M12 8a2 2 0 0 1 2 2v4a2 2 0 1 1 -4 0v-4a2 2 0 0 1 2 -2", "M17 8v8h4", "M13 15l1 1", "M3 15a1 1 0 0 0 1 1h2a1 1 0 0 0 1 -1v-2a1 1 0 0 0 -1 -1h-2a1 1 0 0 1 -1 -1v-2a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1"],
|
|
323
|
+
"star": ["M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873z"],
|
|
324
|
+
"store": ["M3 21l18 0", "M3 7v1a3 3 0 0 0 6 0v-1m0 1a3 3 0 0 0 6 0v-1m0 1a3 3 0 0 0 6 0v-1h-18l2 -4h14l2 4", "M5 21l0 -10.15", "M19 21l0 -10.15", "M9 21v-4a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v4"],
|
|
325
|
+
"support": ["M4 14v-3a8 8 0 1 1 16 0v3", "M18 19c0 1.657 -2.686 3 -6 3", "M4 14a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v3a2 2 0 0 1 -2 2h-1a2 2 0 0 1 -2 -2v-3z", "M15 14a2 2 0 0 1 2 -2h1a2 2 0 0 1 2 2v3a2 2 0 0 1 -2 2h-1a2 2 0 0 1 -2 -2v-3z"],
|
|
326
|
+
"sync": ["M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4", "M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4"],
|
|
327
|
+
"table": ["M3 5a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-14z", "M3 10h18", "M10 3v18"],
|
|
328
|
+
"tablet": ["M5 4a1 1 0 0 1 1 -1h12a1 1 0 0 1 1 1v16a1 1 0 0 1 -1 1h-12a1 1 0 0 1 -1 -1v-16z", "M11 17a1 1 0 1 0 2 0a1 1 0 0 0 -2 0"],
|
|
329
|
+
"target": ["M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0", "M12 12m-5 0a5 5 0 1 0 10 0a5 5 0 1 0 -10 0", "M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0"],
|
|
330
|
+
"team": ["M10 13a2 2 0 1 0 4 0a2 2 0 0 0 -4 0", "M8 21v-1a2 2 0 0 1 2 -2h4a2 2 0 0 1 2 2v1", "M15 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0", "M17 10h2a2 2 0 0 1 2 2v1", "M5 5a2 2 0 1 0 4 0a2 2 0 0 0 -4 0", "M3 13v-1a2 2 0 0 1 2 -2h2"],
|
|
331
|
+
"terminal": ["M5 7l5 5l-5 5", "M12 19l7 0"],
|
|
332
|
+
"test": ["M20 8.04l-12.122 12.124a2.857 2.857 0 1 1 -4.041 -4.04l12.122 -12.124", "M7 13h8", "M19 15l1.5 1.6a2 2 0 1 1 -3 0l1.5 -1.6", "M15 3l6 6"],
|
|
333
|
+
"tool": ["M7 10h3v-3l-3.5 -3.5a6 6 0 0 1 8 8l6 6a2 2 0 0 1 -3 3l-6 -6a6 6 0 0 1 -8 -8l3.5 3.5"],
|
|
334
|
+
"trend": ["M3 17l6 -6l4 4l8 -8", "M14 7l7 0l0 7"],
|
|
335
|
+
"truck": ["M7 17m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M17 17m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0", "M5 17h-2v-11a1 1 0 0 1 1 -1h9v12m-4 0h6m4 0h2v-6h-8m0 -5h5l3 5"],
|
|
336
|
+
"txt": ["M14 3v4a1 1 0 0 0 1 1h4", "M14 3v4a1 1 0 0 0 1 1h4", "M16.5 15h3", "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4", "M4.5 15h3", "M6 15v6", "M18 15v6", "M10 15l4 6", "M10 21l4 -6"],
|
|
337
|
+
"upload": ["M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2", "M7 9l5 -5l5 5", "M12 4l0 12"],
|
|
338
|
+
"user": ["M8 7a4 4 0 1 0 8 0a4 4 0 0 0 -8 0", "M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"],
|
|
339
|
+
"users": ["M5 7a4 4 0 1 0 8 0a4 4 0 1 0 -8 0", "M3 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2", "M16 3.13a4 4 0 0 1 0 7.75", "M21 21v-2a4 4 0 0 0 -3 -3.85"],
|
|
340
|
+
"video": ["M15 10l4.553 -2.276a1 1 0 0 1 1.447 .894v6.764a1 1 0 0 1 -1.447 .894l-4.553 -2.276v-4z", "M3 6m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z"],
|
|
341
|
+
"vm": ["M21 16.008v-8.018a1.98 1.98 0 0 0 -1 -1.717l-7 -4.008a2.016 2.016 0 0 0 -2 0l-7 4.008c-.619 .355 -1 1.01 -1 1.718v8.018c0 .709 .381 1.363 1 1.717l7 4.008a2.016 2.016 0 0 0 2 0l7 -4.008c.619 -.355 1 -1.01 1 -1.718", "M12 22v-10", "M12 12l8.73 -5.04", "M3.27 6.96l8.73 5.04"],
|
|
342
|
+
"volume": ["M7 21h10a2 2 0 0 0 2 -2v-14a2 2 0 0 0 -2 -2h-6.172a2 2 0 0 0 -1.414 .586l-3.828 3.828a2 2 0 0 0 -.586 1.414v10.172a2 2 0 0 0 2 2", "M13 6v2", "M16 6v2", "M10 7v1"],
|
|
343
|
+
"vpn": ["M12 3a12 12 0 0 0 8.5 3a12 12 0 0 1 -8.5 15a12 12 0 0 1 -8.5 -15a12 12 0 0 0 8.5 -3", "M11 11a1 1 0 1 0 2 0a1 1 0 1 0 -2 0", "M12 12l0 2.5"],
|
|
344
|
+
"warehouse": ["M3 21v-13l9 -4l9 4v13", "M13 13h4v8h-10v-6h6", "M13 21v-9a1 1 0 0 0 -1 -1h-2a1 1 0 0 0 -1 1v3"],
|
|
345
|
+
"webhook": ["M4.876 13.61a4 4 0 1 0 6.124 3.39h6", "M15.066 20.502a4 4 0 1 0 1.934 -7.502c-.706 0 -1.424 .179 -2 .5l-3 -5.5", "M16 8a4 4 0 1 0 -8 0c0 1.506 .77 2.818 2 3.5l-3 5.5"],
|
|
346
|
+
"wifi": ["M12 18l.01 0", "M9.172 15.172a4 4 0 0 1 5.656 0", "M6.343 12.343a8 8 0 0 1 11.314 0", "M3.515 9.515c4.686 -4.687 12.284 -4.687 17 0"]
|
|
347
|
+
};
|
|
348
|
+
var ICON_WORDS = {
|
|
349
|
+
"active-directory": "ad identity directory ldap",
|
|
350
|
+
admin: "administrator superuser",
|
|
351
|
+
alert: "warning danger",
|
|
352
|
+
api: "endpoint rest interface",
|
|
353
|
+
backup: "save snapshot",
|
|
354
|
+
bucket: "object storage blob s3",
|
|
355
|
+
cache: "fast redis memcached",
|
|
356
|
+
cdn: "edge",
|
|
357
|
+
cloud: "saas hosted",
|
|
358
|
+
container: "docker image",
|
|
359
|
+
database: "db store table postgres mysql",
|
|
360
|
+
deployment: "release launch rocket",
|
|
361
|
+
desktop: "pc computer monitor",
|
|
362
|
+
dns: "domain name",
|
|
363
|
+
file: "document",
|
|
364
|
+
firewall: "security waf",
|
|
365
|
+
gateway: "proxy entry",
|
|
366
|
+
ingress: "entry inbound",
|
|
367
|
+
internet: "web globe www",
|
|
368
|
+
key: "secret credential vault",
|
|
369
|
+
"load-balancer": "lb balancer traffic",
|
|
370
|
+
lock: "secure private auth",
|
|
371
|
+
log: "logs logging audit",
|
|
372
|
+
monitoring: "metrics observability graph",
|
|
373
|
+
node: "cluster graph mesh",
|
|
374
|
+
phone: "mobile smartphone device",
|
|
375
|
+
pipeline: "ci cd build workflow",
|
|
376
|
+
pod: "kubernetes k8s",
|
|
377
|
+
queue: "messages broker kafka rabbitmq sqs topic",
|
|
378
|
+
request: "send outbound",
|
|
379
|
+
response: "reply return",
|
|
380
|
+
robot: "bot agent automation",
|
|
381
|
+
server: "host machine rack",
|
|
382
|
+
service: "microservice backend",
|
|
383
|
+
sql: "query",
|
|
384
|
+
sync: "replicate refresh",
|
|
385
|
+
terminal: "cli shell console",
|
|
386
|
+
test: "lab experiment qa",
|
|
387
|
+
user: "person customer actor account",
|
|
388
|
+
users: "people group customers",
|
|
389
|
+
vm: "virtual machine instance compute",
|
|
390
|
+
volume: "disk storage ssd",
|
|
391
|
+
vpn: "tunnel private network",
|
|
392
|
+
mail: "email inbox smtp",
|
|
393
|
+
message: "sms notification",
|
|
394
|
+
chat: "conversation messages talk",
|
|
395
|
+
bell: "notification alert alarm",
|
|
396
|
+
settings: "config configuration gear preferences",
|
|
397
|
+
cpu: "processor chip compute",
|
|
398
|
+
function: "lambda serverless faas",
|
|
399
|
+
code: "source developer",
|
|
400
|
+
browser: "web frontend website",
|
|
401
|
+
app: "application window frontend",
|
|
402
|
+
webhook: "callback hook event",
|
|
403
|
+
calendar: "date schedule",
|
|
404
|
+
clock: "time cron",
|
|
405
|
+
scheduler: "cron job timer",
|
|
406
|
+
folder: "directory files",
|
|
407
|
+
archive: "cold storage",
|
|
408
|
+
chart: "analytics bar graph",
|
|
409
|
+
dashboard: "panel overview",
|
|
410
|
+
report: "analytics bi",
|
|
411
|
+
shield: "security protection defense",
|
|
412
|
+
certificate: "tls ssl cert",
|
|
413
|
+
fingerprint: "biometric identity",
|
|
414
|
+
id: "identity badge card",
|
|
415
|
+
password: "credential login secret",
|
|
416
|
+
cart: "shop checkout ecommerce",
|
|
417
|
+
payment: "card billing checkout",
|
|
418
|
+
money: "cost price coin finance",
|
|
419
|
+
building: "office company",
|
|
420
|
+
store: "shop retail",
|
|
421
|
+
factory: "manufacturing plant",
|
|
422
|
+
warehouse: "inventory depot",
|
|
423
|
+
bank: "finance",
|
|
424
|
+
home: "house",
|
|
425
|
+
location: "map pin place geo",
|
|
426
|
+
wifi: "wireless",
|
|
427
|
+
router: "network switch",
|
|
428
|
+
network: "lan topology",
|
|
429
|
+
plug: "connector integration",
|
|
430
|
+
printer: "print",
|
|
431
|
+
camera: "photo",
|
|
432
|
+
antenna: "iot signal radio",
|
|
433
|
+
ai: "brain ml model llm intelligence",
|
|
434
|
+
sparkles: "magic ai new",
|
|
435
|
+
package: "artifact npm library",
|
|
436
|
+
box: "product",
|
|
437
|
+
truck: "delivery shipping logistics",
|
|
438
|
+
broadcast: "stream publish pubsub event",
|
|
439
|
+
"git-merge": "merge",
|
|
440
|
+
"git-commit": "commit version",
|
|
441
|
+
"git-pull-request": "pr review",
|
|
442
|
+
hierarchy: "tree org structure",
|
|
443
|
+
table: "grid spreadsheet",
|
|
444
|
+
list: "items",
|
|
445
|
+
filter: "funnel",
|
|
446
|
+
upload: "import",
|
|
447
|
+
download: "export",
|
|
448
|
+
check: "ok success done",
|
|
449
|
+
error: "fail failure x",
|
|
450
|
+
info: "about help",
|
|
451
|
+
question: "help faq unknown",
|
|
452
|
+
plugin: "extension addon puzzle",
|
|
453
|
+
tool: "wrench maintenance",
|
|
454
|
+
eye: "view watch visible",
|
|
455
|
+
star: "favourite favorite rating",
|
|
456
|
+
flag: "feature toggle",
|
|
457
|
+
route: "path routing workflow",
|
|
458
|
+
audit: "inspect search review",
|
|
459
|
+
document: "doc text page",
|
|
460
|
+
image: "picture photo",
|
|
461
|
+
video: "media stream",
|
|
462
|
+
notebook: "jupyter notes",
|
|
463
|
+
book: "docs documentation wiki",
|
|
464
|
+
tablet: "ipad device",
|
|
465
|
+
team: "group people org",
|
|
466
|
+
support: "helpdesk customer service headset",
|
|
467
|
+
idea: "bulb lightbulb insight",
|
|
468
|
+
target: "goal objective",
|
|
469
|
+
trend: "growth increase"
|
|
470
|
+
};
|
|
471
|
+
function iconMatches(name2, word) {
|
|
472
|
+
const w = word.trim().toLowerCase().replace(/\s+/g, "-");
|
|
473
|
+
if (!w || name2.includes(w)) return true;
|
|
474
|
+
const words = ICON_WORDS[name2];
|
|
475
|
+
return !!words && words.split(" ").some((x) => x.startsWith(w) || x === w.replace(/-/g, ""));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/bundledLooks.ts
|
|
479
|
+
var BUNDLED_LOOKS = {
|
|
480
|
+
headline: `// Headline. A named alternative to the built-in look: serif headline over flat newspaper-graphics blocks.
|
|
481
|
+
// Drawn like a newspaper graphics desk: a serif headline over flat, square, pale-grey blocks set in
|
|
482
|
+
// one grotesque, grey for context and one muted crimson for the subject. No shadows, no black fills.
|
|
483
|
+
|
|
484
|
+
canvas paper=paper
|
|
485
|
+
|
|
486
|
+
color paper #ffffff
|
|
487
|
+
color ink #1f2328
|
|
488
|
+
color muted #5f6670
|
|
489
|
+
color soft #a3a9b1
|
|
490
|
+
color block #e4e7eb
|
|
491
|
+
color hair #cfd4da
|
|
492
|
+
color accent #b3354d
|
|
493
|
+
color link #45607e
|
|
494
|
+
|
|
495
|
+
font sans "Libre Franklin"
|
|
496
|
+
font mono "Geist Mono"
|
|
497
|
+
font serif "Newsreader"
|
|
498
|
+
|
|
499
|
+
// ---- boxes ----------------------------------------------------------------
|
|
500
|
+
style node shape=rect radius=2 size=144x64 fill=block stroke=none sw=0
|
|
501
|
+
title.weight=700 title.size=12 title.color=ink sub.font=sans sub.size=10 sub.color=muted
|
|
502
|
+
tag.font=sans tag.size=8 tag.weight=700 tag.color=muted tag.border=none
|
|
503
|
+
use="default box: a service, component or step"
|
|
504
|
+
style focal extends node fill=accent title.color=#ffffff sub.color=#ffffff/0.85
|
|
505
|
+
tag.color=#ffffff/0.85 ghost.color=#ffffff/0.15
|
|
506
|
+
use="the one or two elements the diagram is about"
|
|
507
|
+
style store extends node size=144x72
|
|
508
|
+
path="M0,0.1 C0,-0.035 1,-0.035 1,0.1 L1,0.9 C1,1.035 0,1.035 0,0.9 Z M0,0.1 C0,0.235 1,0.235 1,0.1 C1,0.235 0,0.235 0,0.1"
|
|
509
|
+
shape=path stroke=#ffffff sw=1.5
|
|
510
|
+
use="something that holds data or state"
|
|
511
|
+
style cloud extends node fill=link/0.12 title.color=link sub.color=link/0.8
|
|
512
|
+
use="a hosted or third-party platform"
|
|
513
|
+
style external extends node fill=paper stroke=soft sw=1 dash=3,3
|
|
514
|
+
use="a person or system outside what you own"
|
|
515
|
+
style optional extends node fill=paper stroke=hair sw=1 dash=2,3
|
|
516
|
+
use="optional or asynchronous participant"
|
|
517
|
+
style sticky extends node size=120x120 fill=#efe3a2 title.weight=500
|
|
518
|
+
use="a yellow sticky note: an idea, comment or open question"
|
|
519
|
+
style sticky-orange extends sticky fill=#efd2bb use="an orange sticky note: a risk or issue"
|
|
520
|
+
style sticky-violet extends sticky fill=#ddd8ec use="a violet sticky note: a decision or note"
|
|
521
|
+
|
|
522
|
+
// ---- flowchart shapes -----------------------------------------------------
|
|
523
|
+
style step extends node size=160x48 use="flowchart action"
|
|
524
|
+
style terminal shape=rect radius=24 size=160x48 fill=paper stroke=ink sw=1 title.weight=700 title.size=12 title.color=ink sub.font=sans sub.size=10 sub.color=muted
|
|
525
|
+
use="flowchart start or end"
|
|
526
|
+
style terminal-focal extends terminal fill=accent stroke=accent title.color=#ffffff sub.color=#ffffff/0.85
|
|
527
|
+
use="the flowchart outcome that matters most"
|
|
528
|
+
style decision shape=diamond size=200x96 fill=block stroke=none title.weight=700 title.size=12
|
|
529
|
+
use="flowchart yes/no question; put the text on two short lines"
|
|
530
|
+
|
|
531
|
+
// ---- other shapes ---------------------------------------------------------
|
|
532
|
+
style zone shape=rect radius=0 fill=none stroke=hair sw=1 dash=1,3 layer=back
|
|
533
|
+
title.pos=top title.align=left title.font=sans title.size=10 title.weight=700 title.caps=1 title.spacing=0.06 title.color=muted
|
|
534
|
+
use="a labelled region drawn behind a group of boxes; always give WxH"
|
|
535
|
+
style bar shape=rect size=8x80 fill=block stroke=none
|
|
536
|
+
use="sequence diagram activation bar, centred on a lifeline; always give WxH"
|
|
537
|
+
|
|
538
|
+
style table shape=table radius=0 fill=paper stroke=hair sw=1 head.fill=block rule=hair
|
|
539
|
+
cell.font=sans cell.size=10 detail.color=muted
|
|
540
|
+
use="an entity, class or database table: a header and rows. One line per row: | id \\"name\\" \\"type\\" \\"key\\". Arrows can end on a row: orders.user_id -> users.id"
|
|
541
|
+
style matrix extends table align=center grid=1
|
|
542
|
+
use="a grid of values: first row with |= for the column headings, first cell of each row is its name"
|
|
543
|
+
style chart shape=chart fill=none stroke=ink/0.6 sw=1 mask=0 bar.radius=0 grid.color=ink/0.08
|
|
544
|
+
use="axes with your numbers drawn for you: chart at x,y WxH x=\\"Q1,Q2,Q3\\" y=0..100, then a line per series: | bars \\"Revenue\\" 42 61 75"
|
|
545
|
+
|
|
546
|
+
// ---- lines ----------------------------------------------------------------
|
|
547
|
+
style arrow line stroke=#80868f sw=1.25 route=ortho radius=4 label.font=sans label.size=10 label.caps=0 label.spacing=0 label.color=muted
|
|
548
|
+
use="default arrow"
|
|
549
|
+
style primary extends arrow stroke=accent sw=2.25 label.color=accent label.weight=700 use="the main path; at most two per diagram"
|
|
550
|
+
style link extends arrow stroke=link label.color=link use="a request crossing a boundary"
|
|
551
|
+
style return extends arrow stroke=soft dash=3,3 use="a response, or something optional or asynchronous"
|
|
552
|
+
style relation extends relation stroke=#80868f label.font=sans label.size=10 label.caps=0 label.spacing=0 label.color=muted
|
|
553
|
+
style lifeline line head=none stroke=hair sw=1 dash=1,3 route=straight use="sequence diagram lifeline"
|
|
554
|
+
style rule line head=none stroke=hair sw=1 route=straight use="thin separator"
|
|
555
|
+
|
|
556
|
+
// ---- text -----------------------------------------------------------------
|
|
557
|
+
style h1 text font=serif size=28 weight=500 color=ink use="diagram title, a serif headline"
|
|
558
|
+
style kicker text font=sans size=10 weight=700 color=accent caps=1 spacing=0.08 use="optional: a short category above the title, e.g. PROCESS"
|
|
559
|
+
style dek text font=sans size=15 color=muted use="one line under the title that says what the diagram shows"
|
|
560
|
+
style eyebrow text font=sans size=10 weight=700 color=muted caps=1 spacing=0.06 use="small heading"
|
|
561
|
+
style caption text font=sans size=10 color=muted use="small explanatory text"
|
|
562
|
+
style legend extends legend rule=hair title.font=sans title.size=9 title.weight=700 title.spacing=0.06 item.font=sans item.size=10
|
|
563
|
+
style note text font=serif italic=1 size=15 color=muted use="a short aside; at most two"
|
|
564
|
+
style small text font=sans size=10 color=soft use="source line, or technical detail: a port, path or command"
|
|
565
|
+
|
|
566
|
+
guidance "focal, terminal-focal and primary are the accent. Use the accent on at most two things in one diagram."
|
|
567
|
+
guidance "Never fill a shape with ink to make it stand out; use the accent, or a tint such as accent/0.14 or block."
|
|
568
|
+
guidance "tag= is a 3 or 4 letter type marker in the corner of a box. sub= is a short second line of detail."
|
|
569
|
+
guidance "A title reads best with a dek under it: one plain sentence saying what the diagram shows."
|
|
570
|
+
guidance "Finish with a legend: one statement, 'legend at x,y' followed by style=\\"what it means\\" for each style you used."
|
|
571
|
+
`,
|
|
572
|
+
night: `// Night: the built-in look after dark. A deep navy page, raised navy cards with a two-tone icon,
|
|
573
|
+
// softly tinted zones, cool greys for everything else and one bright indigo for the subject and the
|
|
574
|
+
// main path. Same styles as the built-in look, so a diagram moves between them without changes.
|
|
575
|
+
|
|
576
|
+
canvas paper=paper dots=ink/0.08 dotgap=24
|
|
577
|
+
|
|
578
|
+
color paper #0b1226
|
|
579
|
+
color card #131c38
|
|
580
|
+
color ink #e2e8f0
|
|
581
|
+
color muted #94a3b8
|
|
582
|
+
color soft #64748b
|
|
583
|
+
color accent #8b8cff
|
|
584
|
+
color link #38bdf8
|
|
585
|
+
color teal #2dd4bf
|
|
586
|
+
color amber #fbbf24
|
|
587
|
+
color rose #fb7185
|
|
588
|
+
color violet #a78bfa
|
|
589
|
+
|
|
590
|
+
font sans "Geist"
|
|
591
|
+
font mono "Geist Mono"
|
|
592
|
+
font serif "Newsreader"
|
|
593
|
+
|
|
594
|
+
// ---- boxes ----------------------------------------------------------------
|
|
595
|
+
style node shape=rect radius=10 size=144x64 fill=#131c38 stroke=ink/0.14 sw=1 sub.font=sans sub.color=muted
|
|
596
|
+
tag.color=muted tag.border=ink/0.18 tag.font=mono icon.color=accent icon.fill=accent/0.14
|
|
597
|
+
use="default box: a backend, service, component or step"
|
|
598
|
+
style focal extends node fill=#131c38 stroke=accent sw=2 title.color=accent
|
|
599
|
+
tag.color=accent tag.border=accent/0.4 ghost.color=accent/0.10
|
|
600
|
+
use="the one or two elements the diagram is about"
|
|
601
|
+
style store extends node shape=path stroke=ink/0.18 icon.color=violet icon.fill=violet/0.14 tag.color=violet tag.border=violet/0.4
|
|
602
|
+
path="M0,0.1 C0,-0.035 1,-0.035 1,0.1 L1,0.9 C1,1.035 0,1.035 0,0.9 Z M0,0.1 C0,0.235 1,0.235 1,0.1 C1,0.235 0,0.235 0,0.1"
|
|
603
|
+
use="something that holds data or state"
|
|
604
|
+
style cloud extends node stroke=link/0.45 icon.color=link icon.fill=link/0.14 tag.color=link tag.border=link/0.4
|
|
605
|
+
use="a hosted or third-party platform"
|
|
606
|
+
style external extends node stroke=ink/0.28 dash=5,4 icon.color=muted icon.fill=ink/0.06
|
|
607
|
+
use="a person or system outside what you own"
|
|
608
|
+
style optional extends node fill=#131c38/0.6 stroke=ink/0.22 dash=3,3 tag.color=soft tag.border=ink/0.18
|
|
609
|
+
use="optional or asynchronous participant"
|
|
610
|
+
style sticky extends node radius=4 size=120x120 fill=#3a3315 stroke=amber/0.45 tag.color=ink tag.border=ink/0.3
|
|
611
|
+
use="a yellow sticky note: an idea, comment or open question"
|
|
612
|
+
style sticky-orange extends sticky fill=#3b1d26 stroke=rose/0.45 use="an orange sticky note: a risk or issue"
|
|
613
|
+
style sticky-violet extends sticky fill=#261f45 stroke=violet/0.45 use="a violet sticky note: a decision or note"
|
|
614
|
+
|
|
615
|
+
// ---- flowchart shapes -----------------------------------------------------
|
|
616
|
+
style step extends node size=160x48 use="flowchart action"
|
|
617
|
+
style terminal extends node radius=24 size=160x48 fill=#131c38 stroke=ink/0.30
|
|
618
|
+
use="flowchart start or end"
|
|
619
|
+
style terminal-focal extends terminal stroke=accent sw=2 title.color=accent
|
|
620
|
+
use="the flowchart outcome that matters most"
|
|
621
|
+
style decision shape=diamond size=200x96 fill=#131c38 stroke=ink/0.30 sw=1
|
|
622
|
+
use="flowchart yes/no question; put the text on two short lines"
|
|
623
|
+
|
|
624
|
+
// ---- regions and markers --------------------------------------------------
|
|
625
|
+
style zone shape=rect radius=16 fill=ink/0.03 stroke=ink/0.12 sw=1 layer=back
|
|
626
|
+
title.pos=top title.align=left title.font=sans title.size=11 title.weight=600 title.color=muted title.spacing=0 title.caps=0
|
|
627
|
+
use="a labelled region drawn behind a group of boxes; always give WxH"
|
|
628
|
+
style bar shape=rect radius=2 size=8x80 fill=accent/0.10 stroke=accent/0.6 sw=1
|
|
629
|
+
use="sequence diagram activation bar, centred on a lifeline; always give WxH"
|
|
630
|
+
|
|
631
|
+
style table shape=table radius=10 fill=#131c38 stroke=ink/0.16 sw=1 head.fill=accent/0.08 rule=ink/0.08
|
|
632
|
+
cell.font=mono cell.size=10 detail.color=muted
|
|
633
|
+
use="an entity, class or database table: a header and rows. One line per row: | id \\"name\\" \\"type\\" \\"key\\". Arrows can end on a row: orders.user_id -> users.id"
|
|
634
|
+
style matrix extends table align=center grid=1 cell.font=sans
|
|
635
|
+
use="a grid of values: first row with |= for the column headings, first cell of each row is its name"
|
|
636
|
+
style chart shape=chart fill=none stroke=ink/0.5 sw=1 mask=0 bar.radius=2 grid.color=ink/0.08
|
|
637
|
+
tick.font=mono tick.size=9 tick.color=muted
|
|
638
|
+
use="axes with your numbers drawn for you: chart at x,y WxH x=\\"Q1,Q2,Q3\\" y=0..100, then a line per series: | bars \\"Revenue\\" 42 61 75"
|
|
639
|
+
|
|
640
|
+
// ---- lines ----------------------------------------------------------------
|
|
641
|
+
style arrow line stroke=ink/0.45 sw=1.4 route=ortho radius=8 label.font=sans label.size=10 label.color=muted label.spacing=0 label.caps=0
|
|
642
|
+
use="default arrow"
|
|
643
|
+
style primary extends arrow stroke=accent sw=2 label.color=accent use="the main path; at most two per diagram"
|
|
644
|
+
style link extends arrow stroke=link label.color=link use="an HTTP or API request crossing a boundary"
|
|
645
|
+
style return extends arrow dash=5,4 use="a response, or something optional or asynchronous"
|
|
646
|
+
style relation extends relation stroke=ink/0.5 label.font=sans label.size=10 label.spacing=0 label.caps=0
|
|
647
|
+
style lifeline line head=none stroke=ink/0.20 sw=1 dash=4,4 route=straight use="sequence diagram lifeline"
|
|
648
|
+
style rule line head=none stroke=ink/0.10 sw=1 route=straight use="thin separator, e.g. above a legend"
|
|
649
|
+
|
|
650
|
+
// ---- text -----------------------------------------------------------------
|
|
651
|
+
style h1 text font=sans size=26 weight=600 color=ink use="diagram title"
|
|
652
|
+
style kicker text font=mono size=10 weight=500 color=accent spacing=0.12 caps=1 use="optional: a short category above the title, e.g. PROCESS"
|
|
653
|
+
style dek text font=sans size=14 color=muted use="optional: one line under the title saying what the diagram shows"
|
|
654
|
+
style eyebrow text font=mono size=8 color=muted spacing=0.14 caps=1 use="small caps label, e.g. LEGEND"
|
|
655
|
+
style caption text font=sans size=9.5 color=muted use="small explanatory text"
|
|
656
|
+
style legend extends legend rule=ink/0.1 title.font=mono item.size=9.5
|
|
657
|
+
style note text font=sans size=13 color=muted use="a short aside; at most two"
|
|
658
|
+
style small text font=mono size=9 color=muted use="technical detail: a port, path or command"
|
|
659
|
+
|
|
660
|
+
guidance "focal, terminal-focal and primary are the accent. Use the accent on at most two things in one diagram."
|
|
661
|
+
guidance "Never fill a shape with ink to make it stand out; use the accent, or a tint such as accent/0.14."
|
|
662
|
+
guidance "tag= is a 3 or 4 letter type marker in the corner of a box (EXT, EDGE, API, DB). Use it on architecture boxes, not flowchart shapes."
|
|
663
|
+
guidance "sub= is a short second line of detail: a product name, path, port or protocol. Names of things go in the main text."
|
|
664
|
+
guidance "kicker and dek are optional. Add a kicker only when the diagram belongs to a named category, and a dek only when there is one clear message; most diagrams need neither."
|
|
665
|
+
guidance "Finish with a legend: one statement, 'legend at x,y' followed by style=\\"what it means\\" for each style you used."
|
|
666
|
+
`,
|
|
667
|
+
reference: `// Reference look for the quality comparison.
|
|
668
|
+
// It mirrors the palette and type of diagram-design's default skin so the two can be
|
|
669
|
+
// judged side by side. It is a test fixture, not the look FastDraw will ship with.
|
|
670
|
+
|
|
671
|
+
canvas paper=paper dots=ink/0.055 dotgap=22
|
|
672
|
+
|
|
673
|
+
color paper #f5f5f5
|
|
674
|
+
color ink #2d3142
|
|
675
|
+
color muted #4f5d75
|
|
676
|
+
color soft #7a8399
|
|
677
|
+
color accent #eb6c36
|
|
678
|
+
color link #2e5aa8
|
|
679
|
+
|
|
680
|
+
font sans "Geist"
|
|
681
|
+
font mono "Geist Mono"
|
|
682
|
+
font serif "Instrument Serif"
|
|
683
|
+
|
|
684
|
+
// ---- boxes ----------------------------------------------------------------
|
|
685
|
+
style node shape=rect radius=6 size=144x64 fill=#ffffff stroke=ink sw=1
|
|
686
|
+
tag.color=ink tag.border=ink/0.4
|
|
687
|
+
use="default box: a backend, service, component or step"
|
|
688
|
+
style focal extends node fill=accent/0.08 stroke=accent
|
|
689
|
+
tag.color=accent tag.border=accent/0.5 ghost.color=accent/0.10
|
|
690
|
+
use="the one or two elements the diagram is about"
|
|
691
|
+
style store extends node fill=ink/0.05 stroke=muted tag.color=muted tag.border=muted/0.5
|
|
692
|
+
use="something that holds data or state"
|
|
693
|
+
style cloud extends node fill=ink/0.03 stroke=ink/0.30 tag.color=soft tag.border=ink/0.22
|
|
694
|
+
use="a hosted or third-party platform"
|
|
695
|
+
style external extends node fill=muted/0.10 stroke=soft tag.color=soft tag.border=soft/0.4
|
|
696
|
+
use="a person or system outside what you own"
|
|
697
|
+
style optional extends node fill=ink/0.02 stroke=ink/0.22 dash=4,3 tag.color=soft tag.border=ink/0.22
|
|
698
|
+
use="optional or asynchronous participant"
|
|
699
|
+
style sticky extends node size=120x120 fill=#fdf0a6 stroke=ink/0.25 tag.color=ink tag.border=ink/0.3
|
|
700
|
+
use="a yellow sticky note: an idea, comment or open question"
|
|
701
|
+
style sticky-orange extends sticky fill=#fdd8b8 use="an orange sticky note: a risk or issue"
|
|
702
|
+
style sticky-violet extends sticky fill=#e2dbfb use="a violet sticky note: a decision or note"
|
|
703
|
+
|
|
704
|
+
// ---- flowchart shapes -----------------------------------------------------
|
|
705
|
+
style step extends node size=160x48 use="flowchart action"
|
|
706
|
+
style terminal shape=rect radius=24 size=160x48 fill=ink/0.03 stroke=ink/0.30 sw=1
|
|
707
|
+
use="flowchart start or end"
|
|
708
|
+
style terminal-focal extends terminal fill=accent/0.08 stroke=accent
|
|
709
|
+
use="the flowchart outcome that matters most"
|
|
710
|
+
style decision shape=diamond size=200x96 fill=#ffffff stroke=ink sw=1
|
|
711
|
+
use="flowchart yes/no question; put the text on two short lines"
|
|
712
|
+
|
|
713
|
+
// ---- other shapes ---------------------------------------------------------
|
|
714
|
+
style zone shape=rect radius=8 fill=ink/0.02 stroke=ink/0.10 sw=0.8 layer=back
|
|
715
|
+
title.pos=top title.font=mono title.size=7 title.weight=400 title.color=ink/0.40 title.spacing=0.14 title.caps=1
|
|
716
|
+
use="a labelled region drawn behind a group of boxes; always give WxH"
|
|
717
|
+
style bar shape=rect size=8x80 fill=ink/0.06 stroke=muted sw=0.8
|
|
718
|
+
use="sequence diagram activation bar, centred on a lifeline; always give WxH"
|
|
719
|
+
|
|
720
|
+
style table shape=table radius=6 fill=#ffffff stroke=ink sw=1 head.fill=ink/0.06 rule=ink/0.1
|
|
721
|
+
cell.font=mono cell.size=9.5 detail.color=muted
|
|
722
|
+
use="an entity, class or database table: a header and rows. One line per row: | id \\"name\\" \\"type\\" \\"key\\". Arrows can end on a row: orders.user_id -> users.id"
|
|
723
|
+
style matrix extends table align=center grid=1 cell.font=sans
|
|
724
|
+
use="a grid of values: first row with |= for the column headings, first cell of each row is its name"
|
|
725
|
+
style chart shape=chart fill=none stroke=ink/0.5 sw=1 mask=0 bar.radius=2 grid.color=ink/0.07
|
|
726
|
+
tick.font=mono tick.size=8 tick.color=muted
|
|
727
|
+
use="axes with your numbers drawn for you: chart at x,y WxH x=\\"Q1,Q2,Q3\\" y=0..100, then a line per series: | bars \\"Revenue\\" 42 61 75"
|
|
728
|
+
|
|
729
|
+
// ---- lines ----------------------------------------------------------------
|
|
730
|
+
style arrow line stroke=muted sw=1.2 route=ortho radius=8 label.font=mono label.size=8 label.spacing=0.08
|
|
731
|
+
use="default arrow"
|
|
732
|
+
style primary extends arrow stroke=accent sw=1.4 use="the main path; at most two per diagram"
|
|
733
|
+
style link extends arrow stroke=link use="an HTTP or API request crossing a boundary"
|
|
734
|
+
style return extends arrow dash=5,4 use="a response, or something optional or asynchronous"
|
|
735
|
+
style relation extends relation label.font=mono label.size=8 label.spacing=0.08
|
|
736
|
+
style lifeline line head=none stroke=ink/0.22 sw=1 dash=3,3 route=straight use="sequence diagram lifeline"
|
|
737
|
+
style rule line head=none stroke=ink/0.10 sw=0.8 route=straight use="thin separator, e.g. above a legend"
|
|
738
|
+
|
|
739
|
+
// ---- text -----------------------------------------------------------------
|
|
740
|
+
style h1 text font=serif size=28 color=ink use="diagram title"
|
|
741
|
+
style kicker text font=mono size=9 color=accent spacing=0.18 caps=1 use="optional: a short category above the title, e.g. PROCESS"
|
|
742
|
+
style dek text font=sans size=14 color=muted use="optional: one line under the title saying what the diagram shows"
|
|
743
|
+
style eyebrow text font=mono size=8 color=muted spacing=0.18 caps=1 use="small caps label, e.g. LEGEND"
|
|
744
|
+
style caption text font=sans size=8.5 color=muted use="legend entry"
|
|
745
|
+
style legend extends legend title.size=7.5 item.font=sans item.size=8.5
|
|
746
|
+
style note text font=serif italic=1 size=14 color=muted use="a short editorial aside; at most two"
|
|
747
|
+
style small text font=mono size=9 color=muted use="technical detail: a port, path or command"
|
|
748
|
+
|
|
749
|
+
guidance "focal, terminal-focal and primary are the accent. Use the accent on at most two things in one diagram."
|
|
750
|
+
guidance "tag= is a 3 or 4 letter type marker in the corner of a box (EXT, EDGE, API, DB). Use it on architecture boxes, not flowchart shapes."
|
|
751
|
+
guidance "sub= is for technical detail in mono type: a product name, path, port or protocol. Names of things go in the main text."
|
|
752
|
+
guidance "Finish with a legend: one statement, 'legend at x,y' followed by style=\\"what it means\\" for each style you used."
|
|
753
|
+
`,
|
|
754
|
+
sketch: `// Sketch. A named look drawn by hand, like a whiteboard tool: marker-weight outlines that wobble
|
|
755
|
+
// and double back at the corners, a handwritten font for everything, pastel fills and pencil
|
|
756
|
+
// hatching for the subject. White page, near-black ink, one blue for what the diagram is about.
|
|
757
|
+
|
|
758
|
+
canvas paper=paper sketch=1
|
|
759
|
+
fontdir "./fonts"
|
|
760
|
+
|
|
761
|
+
color paper #ffffff
|
|
762
|
+
color ink #1e1e1e
|
|
763
|
+
color muted #495057
|
|
764
|
+
color soft #868e96
|
|
765
|
+
color accent #1971c2
|
|
766
|
+
color sky #a5d8ff
|
|
767
|
+
color mint #b2f2bb
|
|
768
|
+
color leaf #2f9e44
|
|
769
|
+
color butter #ffec99
|
|
770
|
+
color amber #f08c00
|
|
771
|
+
color rose #ffc9c9
|
|
772
|
+
color link #6741d9
|
|
773
|
+
|
|
774
|
+
font sans "Sketch Hand"
|
|
775
|
+
font serif "Sketch Hand"
|
|
776
|
+
font mono "Geist Mono"
|
|
777
|
+
|
|
778
|
+
// ---- boxes ----------------------------------------------------------------
|
|
779
|
+
style node shape=rect radius=10 size=144x64 fill=paper stroke=ink sw=2
|
|
780
|
+
title.font=sans title.size=14 title.weight=400 title.color=ink sub.font=sans sub.size=10.5 sub.color=muted
|
|
781
|
+
tag.font=sans tag.size=9 tag.color=muted tag.border=ink/0.35
|
|
782
|
+
use="default box: a backend, service, component or step"
|
|
783
|
+
style focal extends node fill=sky/0.35 hatch=accent/0.5 hatch.gap=8 hatch.sw=1.2 stroke=accent
|
|
784
|
+
title.color=ink tag.color=accent tag.border=accent/0.6 ghost.color=accent/0.12
|
|
785
|
+
use="the one or two elements the diagram is about"
|
|
786
|
+
style store extends node size=144x72
|
|
787
|
+
path="M0,0.1 C0,-0.035 1,-0.035 1,0.1 L1,0.9 C1,1.035 0,1.035 0,0.9 Z M0,0.1 C0,0.235 1,0.235 1,0.1 C1,0.235 0,0.235 0,0.1"
|
|
788
|
+
shape=path fill=butter stroke=ink
|
|
789
|
+
use="something that holds data or state"
|
|
790
|
+
style cloud extends node fill=mint/0.7 stroke=leaf tag.color=leaf tag.border=leaf/0.5
|
|
791
|
+
use="a hosted or third-party platform"
|
|
792
|
+
style external extends node fill=paper stroke=muted dash=8,7 tag.color=soft
|
|
793
|
+
use="a person or system outside what you own"
|
|
794
|
+
style optional extends node fill=paper stroke=soft dash=2,6 tag.color=soft
|
|
795
|
+
use="optional or asynchronous participant"
|
|
796
|
+
style sticky extends node size=128x128 radius=4 fill=butter stroke=ink sw=1.5
|
|
797
|
+
use="a yellow sticky note: an idea, comment or open question"
|
|
798
|
+
style sticky-orange extends sticky fill=#ffd8a8 use="an orange sticky note: a risk or issue"
|
|
799
|
+
style sticky-violet extends sticky fill=#d0bfff use="a violet sticky note: a decision or note"
|
|
800
|
+
|
|
801
|
+
// ---- flowchart shapes -----------------------------------------------------
|
|
802
|
+
style step extends node size=160x56 use="flowchart action"
|
|
803
|
+
style terminal extends node shape=ellipse size=168x60 fill=rose/0.6
|
|
804
|
+
use="flowchart start or end"
|
|
805
|
+
style terminal-focal extends terminal fill=sky/0.35 hatch=accent/0.5 hatch.gap=8 hatch.sw=1.2 stroke=accent
|
|
806
|
+
use="the flowchart outcome that matters most"
|
|
807
|
+
style decision extends node shape=diamond size=208x104 fill=butter/0.8
|
|
808
|
+
use="flowchart yes/no question; put the text on two short lines"
|
|
809
|
+
|
|
810
|
+
// ---- other shapes ---------------------------------------------------------
|
|
811
|
+
style zone shape=rect radius=12 fill=none stroke=soft sw=1.5 dash=10,8 layer=back
|
|
812
|
+
title.pos=top title.font=sans title.size=13 title.weight=400 title.color=muted
|
|
813
|
+
use="a labelled region drawn behind a group of boxes; always give WxH"
|
|
814
|
+
style bar shape=rect size=10x80 fill=sky/0.5 stroke=ink sw=1.5
|
|
815
|
+
use="sequence diagram activation bar, centred on a lifeline; always give WxH"
|
|
816
|
+
|
|
817
|
+
style table shape=table radius=6 fill=paper stroke=ink sw=2 head.fill=sky/0.45 rule=ink/0.2
|
|
818
|
+
title.font=sans title.size=14 title.weight=400 cell.font=sans cell.size=12 detail.color=muted
|
|
819
|
+
use="an entity, class or database table: a header and rows. One line per row: | id \\"name\\" \\"type\\" \\"key\\". Arrows can end on a row: orders.user_id -> users.id"
|
|
820
|
+
style matrix extends table align=center grid=1
|
|
821
|
+
use="a grid of values: first row with |= for the column headings, first cell of each row is its name"
|
|
822
|
+
style chart shape=chart fill=none stroke=ink sw=1.5 mask=0 bar.radius=3 grid.color=ink/0.1
|
|
823
|
+
tick.font=sans tick.size=11 tick.color=muted
|
|
824
|
+
use="axes with your numbers drawn for you: chart at x,y WxH x=\\"Q1,Q2,Q3\\" y=0..100, then a line per series: | bars \\"Revenue\\" 42 61 75"
|
|
825
|
+
|
|
826
|
+
// ---- lines ----------------------------------------------------------------
|
|
827
|
+
style arrow line stroke=ink sw=2 route=ortho radius=14 label.font=sans label.size=12 label.spacing=0 label.caps=0 label.color=muted
|
|
828
|
+
use="default arrow"
|
|
829
|
+
style primary extends arrow stroke=accent sw=2.5 label.color=accent use="the main path; at most two per diagram"
|
|
830
|
+
style link extends arrow stroke=link label.color=link use="an HTTP or API request crossing a boundary"
|
|
831
|
+
style return extends arrow stroke=muted dash=8,7 use="a response, or something optional or asynchronous"
|
|
832
|
+
style relation extends relation sw=1.8 label.font=sans label.size=12 label.spacing=0 label.caps=0
|
|
833
|
+
style lifeline line head=none stroke=soft sw=1.5 dash=6,6 route=straight use="sequence diagram lifeline"
|
|
834
|
+
style rule line head=none stroke=ink/0.25 sw=1.5 route=straight use="thin separator, e.g. above a legend"
|
|
835
|
+
|
|
836
|
+
// ---- text -----------------------------------------------------------------
|
|
837
|
+
style h1 text font=sans size=30 weight=400 color=ink use="diagram title"
|
|
838
|
+
style kicker text font=sans size=13 color=accent use="optional: a short category above the title"
|
|
839
|
+
style dek text font=sans size=16 color=muted use="optional: one line under the title saying what the diagram shows"
|
|
840
|
+
style eyebrow text font=sans size=12 color=muted use="small heading, e.g. Legend"
|
|
841
|
+
style caption text font=sans size=11 color=muted use="small explanatory text"
|
|
842
|
+
style legend extends legend title.font=sans title.size=13 title.caps=0 title.spacing=0 item.font=sans item.size=12
|
|
843
|
+
style note text font=sans size=16 color=accent use="a short handwritten aside; at most two"
|
|
844
|
+
style small text font=mono size=10 color=muted use="technical detail: a port, path or command"
|
|
845
|
+
|
|
846
|
+
guidance "Everything is drawn by hand (canvas sketch=1). Keep diagrams loose and roomy: the handwriting is wider than a normal sans, so give boxes a little more width."
|
|
847
|
+
guidance "focal, terminal-focal and primary are the accent blue. Use the accent on at most two things in one diagram."
|
|
848
|
+
guidance "Colour by meaning with the pastel fills: fill=sky/0.5, fill=mint/0.7, fill=butter, fill=rose/0.6. Never fill a shape with ink."
|
|
849
|
+
guidance "hatch=colour fills a shape with pencil hatching; hatch.gap spaces the lines."
|
|
850
|
+
guidance "Finish with a legend: one statement, 'legend at x,y' followed by style=\\"what it means\\" for each style you used."
|
|
851
|
+
`,
|
|
852
|
+
whiteboard: `// Whiteboard: an online-whiteboard look. A white board with a light dot grid, white rounded
|
|
853
|
+
// shapes with a dark outline, pastel sticky notes for the kinds of thing, curved dark connectors,
|
|
854
|
+
// one bright blue for the subject and the main path, and sans type throughout.
|
|
855
|
+
|
|
856
|
+
canvas paper=paper dots=ink/0.14 dotgap=24
|
|
857
|
+
|
|
858
|
+
color paper #fafafb
|
|
859
|
+
color ink #1a1b25
|
|
860
|
+
color muted #4b4d5c
|
|
861
|
+
color soft #8a8c99
|
|
862
|
+
color accent #4262ff
|
|
863
|
+
color link #2b7a78
|
|
864
|
+
|
|
865
|
+
// sticky-note pastels
|
|
866
|
+
color yellow #fff6a6
|
|
867
|
+
color blue #c6e2ff
|
|
868
|
+
color green #d3f2b4
|
|
869
|
+
color pink #ffd1e6
|
|
870
|
+
color orange #ffd8b0
|
|
871
|
+
color violet #e2d6ff
|
|
872
|
+
|
|
873
|
+
font sans "Geist"
|
|
874
|
+
font mono "Geist Mono"
|
|
875
|
+
font serif "Newsreader"
|
|
876
|
+
|
|
877
|
+
// ---- boxes ----------------------------------------------------------------
|
|
878
|
+
// plain boards shapes are white with a dark outline; stickies have no outline
|
|
879
|
+
style node shape=rect radius=10 size=144x64 fill=#ffffff stroke=ink sw=1.6
|
|
880
|
+
title.font=sans title.weight=500 title.color=ink sub.font=sans sub.color=muted
|
|
881
|
+
tag.color=ink tag.border=ink/0.35
|
|
882
|
+
use="default box: a backend, service, component or step"
|
|
883
|
+
style focal extends node fill=accent/0.10 stroke=accent sw=2.2
|
|
884
|
+
title.color=accent tag.color=accent tag.border=accent/0.5 ghost.color=accent/0.12
|
|
885
|
+
use="the one or two elements the diagram is about"
|
|
886
|
+
style store extends node radius=3 fill=blue stroke=none sw=0 tag.color=ink tag.border=ink/0.3
|
|
887
|
+
use="something that holds data or state (blue sticky)"
|
|
888
|
+
style cloud extends node radius=3 fill=green stroke=none sw=0 tag.color=ink tag.border=ink/0.3
|
|
889
|
+
use="a hosted or third-party platform (green sticky)"
|
|
890
|
+
style external extends node radius=3 fill=pink stroke=none sw=0 tag.color=ink tag.border=ink/0.3
|
|
891
|
+
use="a person or system outside what you own (pink sticky)"
|
|
892
|
+
style optional extends node fill=#ffffff stroke=soft sw=1.4 dash=6,4 tag.color=soft tag.border=soft/0.5
|
|
893
|
+
title.color=muted
|
|
894
|
+
use="optional or asynchronous participant"
|
|
895
|
+
style sticky extends node radius=3 size=120x120 fill=yellow stroke=none sw=0 title.weight=400
|
|
896
|
+
tag.color=ink tag.border=ink/0.3
|
|
897
|
+
use="a yellow sticky note: an idea, comment or open question"
|
|
898
|
+
style sticky-orange extends sticky fill=orange use="an orange sticky note: a risk or issue"
|
|
899
|
+
style sticky-violet extends sticky fill=violet use="a violet sticky note: a decision or note"
|
|
900
|
+
|
|
901
|
+
// ---- flowchart shapes -----------------------------------------------------
|
|
902
|
+
style step extends node size=160x48 use="flowchart action"
|
|
903
|
+
style terminal shape=rect radius=24 size=160x48 fill=#ffffff stroke=ink sw=1.6 title.weight=500
|
|
904
|
+
sub.font=sans sub.color=muted tag.color=ink tag.border=ink/0.35
|
|
905
|
+
use="flowchart start or end"
|
|
906
|
+
style terminal-focal extends terminal fill=accent stroke=accent title.color=#ffffff
|
|
907
|
+
sub.color=#ffffff/0.85 tag.color=#ffffff tag.border=#ffffff/0.6
|
|
908
|
+
use="the flowchart outcome that matters most"
|
|
909
|
+
style decision shape=diamond size=200x96 fill=yellow stroke=ink sw=1.6 title.weight=500
|
|
910
|
+
use="flowchart yes/no question; put the text on two short lines"
|
|
911
|
+
|
|
912
|
+
// ---- other shapes ---------------------------------------------------------
|
|
913
|
+
// a zone is a board frame: white sheet, light outline, plain sans name
|
|
914
|
+
style zone shape=rect radius=6 fill=#ffffff/0.7 stroke=ink/0.16 sw=1 layer=back
|
|
915
|
+
title.pos=top title.font=sans title.size=11 title.weight=500 title.color=muted title.spacing=0 title.caps=0
|
|
916
|
+
use="a labelled region drawn behind a group of boxes; always give WxH"
|
|
917
|
+
style bar shape=rect radius=2 size=8x80 fill=accent/0.14 stroke=accent sw=1
|
|
918
|
+
use="sequence diagram activation bar, centred on a lifeline; always give WxH"
|
|
919
|
+
|
|
920
|
+
style table shape=table radius=8 fill=#ffffff stroke=ink sw=1.4 head.fill=blue rule=ink/0.1
|
|
921
|
+
cell.font=sans cell.size=10.5 detail.color=muted
|
|
922
|
+
use="an entity, class or database table: a header and rows. One line per row: | id \\"name\\" \\"type\\" \\"key\\". Arrows can end on a row: orders.user_id -> users.id"
|
|
923
|
+
style matrix extends table align=center grid=1 cell.font=sans
|
|
924
|
+
use="a grid of values: first row with |= for the column headings, first cell of each row is its name"
|
|
925
|
+
style chart shape=chart fill=none stroke=ink/0.6 sw=1.2 mask=0 bar.radius=3 grid.color=ink/0.08
|
|
926
|
+
tick.font=sans tick.size=10 tick.color=muted
|
|
927
|
+
use="axes with your numbers drawn for you: chart at x,y WxH x=\\"Q1,Q2,Q3\\" y=0..100, then a line per series: | bars \\"Revenue\\" 42 61 75"
|
|
928
|
+
|
|
929
|
+
// ---- lines ----------------------------------------------------------------
|
|
930
|
+
style arrow line stroke=ink sw=1.6 route=curve radius=10 label.font=sans label.size=10.5 label.color=muted label.spacing=0 label.caps=0
|
|
931
|
+
use="default connector"
|
|
932
|
+
style primary extends arrow stroke=accent sw=2.2 use="the main path; at most two per diagram"
|
|
933
|
+
style link extends arrow stroke=link use="an HTTP or API request crossing a boundary"
|
|
934
|
+
style return extends arrow stroke=muted dash=6,4 use="a response, or something optional or asynchronous"
|
|
935
|
+
style relation extends relation label.font=sans label.size=10.5 label.spacing=0 label.caps=0
|
|
936
|
+
style lifeline line head=none stroke=ink/0.25 sw=1.2 dash=4,4 route=straight use="sequence diagram lifeline"
|
|
937
|
+
style rule line head=none stroke=ink/0.12 sw=1 route=straight use="thin separator, e.g. above a legend"
|
|
938
|
+
|
|
939
|
+
// ---- text -----------------------------------------------------------------
|
|
940
|
+
style h1 text font=sans size=28 weight=600 color=ink use="diagram title"
|
|
941
|
+
style kicker text font=sans size=11 weight=600 color=accent spacing=0.06 caps=1 use="optional: a short category above the title, e.g. PROCESS"
|
|
942
|
+
style dek text font=sans size=14 color=muted use="optional: one line under the title saying what the diagram shows"
|
|
943
|
+
style eyebrow text font=sans size=9 weight=600 color=muted spacing=0.08 caps=1 use="small caps label, e.g. LEGEND"
|
|
944
|
+
style caption text font=sans size=10 color=muted use="small explanatory text"
|
|
945
|
+
style legend extends legend title.font=sans item.font=sans item.size=10
|
|
946
|
+
style note text font=sans size=13 color=muted use="a short aside; at most two"
|
|
947
|
+
style small text font=mono size=9.5 color=muted use="technical detail: a port, path or command"
|
|
948
|
+
|
|
949
|
+
guidance "focal, terminal-focal and primary are the blue accent. Use the accent on at most two things in one diagram."
|
|
950
|
+
guidance "store, cloud and external are sticky notes (blue, green, pink). sticky, sticky-orange and sticky-violet are free notes for ideas, risks and decisions; keep their text short."
|
|
951
|
+
guidance "Never fill a shape with ink to make it stand out; use the accent."
|
|
952
|
+
guidance "tag= is a 3 or 4 letter type marker in the corner of a box (EXT, EDGE, API, DB). Use it on architecture boxes, not flowchart shapes."
|
|
953
|
+
guidance "Finish with a legend: one statement, 'legend at x,y' followed by style=\\"what it means\\" for each style you used."
|
|
954
|
+
`
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
// src/look.ts
|
|
958
|
+
var BUILTIN = [
|
|
959
|
+
{ name: "rect", kind: "shape", props: { shape: "rect", fill: "none", stroke: "ink", sw: "1" } },
|
|
960
|
+
{ name: "ellipse", kind: "shape", props: { shape: "ellipse", fill: "none", stroke: "ink", sw: "1" } },
|
|
961
|
+
{ name: "diamond", kind: "shape", props: { shape: "diamond", fill: "none", stroke: "ink", sw: "1" } },
|
|
962
|
+
{ name: "polygon", kind: "shape", props: { shape: "polygon", fill: "none", stroke: "ink", sw: "1", size: "automatic", use: "any outline from exact corners: polygon at x,y points=60,0;120,100;0,100 (measured from at). open=1 leaves it unclosed, smooth=1 rounds it" } },
|
|
963
|
+
{ name: "freehand", kind: "shape", props: { shape: "polygon", open: "1", smooth: "1", fill: "none", stroke: "ink", sw: "2", cap: "round", overlap: "ok", mask: "0", size: "automatic", use: "a stroke drawn by hand in the editor: freehand at x,y points=0,12;18,2;40,9 (measured from at), a smooth open line through the points. Not for diagrams written as text: use lines, arrows and polygons there" } },
|
|
964
|
+
{ name: "arc", kind: "shape", props: { shape: "arc", fill: "none", stroke: "ink", sw: "1", use: "a slice of a circle: arc at x,y WxH from=0 to=90 (degrees clockwise from the top). inner=0.6 makes it a ring segment, open=1 draws only the curved edge" } },
|
|
965
|
+
{ name: "icon", kind: "shape", props: { shape: "icon", mask: "0", size: "24x24", use: "an icon on its own, with no box: icon at x,y icon=database. fill=, stroke= and sw= style the icon itself; its text is a caption underneath (give WxH for another size)" } },
|
|
966
|
+
{ name: "text", kind: "text", props: { font: "sans", size: "12", color: "ink" } },
|
|
967
|
+
{ name: "arrow", kind: "line", props: { stroke: "muted", sw: "1.2", head: "arrow", route: "ortho", radius: "8" } },
|
|
968
|
+
{ name: "line", kind: "line", props: { stroke: "muted", sw: "1", head: "none", route: "straight" } },
|
|
969
|
+
{ name: "relation", kind: "line", props: { stroke: "ink", sw: "1.2", head: "none", route: "ortho", radius: "6", use: "a relationship between two tables or classes; write it with -- and choose the ends with head= and tail=" } },
|
|
970
|
+
{
|
|
971
|
+
name: "table",
|
|
972
|
+
kind: "shape",
|
|
973
|
+
props: {
|
|
974
|
+
shape: "table",
|
|
975
|
+
fill: "paper",
|
|
976
|
+
stroke: "ink",
|
|
977
|
+
sw: "1",
|
|
978
|
+
size: "automatic",
|
|
979
|
+
use: 'a box with a header and rows; add a line per row: | id "cell" "cell". An arrow can end on a row: other -> table.id'
|
|
980
|
+
}
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
name: "chart",
|
|
984
|
+
kind: "shape",
|
|
985
|
+
props: {
|
|
986
|
+
shape: "chart",
|
|
987
|
+
fill: "none",
|
|
988
|
+
stroke: "ink/0.5",
|
|
989
|
+
sw: "1",
|
|
990
|
+
mask: "0",
|
|
991
|
+
use: 'axes with your numbers drawn for you: chart at x,y WxH x="Q1,Q2,Q3" y=0..100, then a line per series: | bars "Revenue" 42 61 75'
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
name: "legend",
|
|
996
|
+
kind: "shape",
|
|
997
|
+
props: {
|
|
998
|
+
shape: "legend",
|
|
999
|
+
fill: "none",
|
|
1000
|
+
stroke: "none",
|
|
1001
|
+
mask: "0",
|
|
1002
|
+
rule: "ink/0.12",
|
|
1003
|
+
title: "Legend",
|
|
1004
|
+
size: "automatic",
|
|
1005
|
+
use: 'a whole legend in one statement: legend at x,y focal="what it means" primary="what it means" ...',
|
|
1006
|
+
"title.font": "mono",
|
|
1007
|
+
"title.size": "8",
|
|
1008
|
+
"title.color": "muted",
|
|
1009
|
+
"title.spacing": "0.18",
|
|
1010
|
+
"title.caps": "1",
|
|
1011
|
+
"item.font": "sans",
|
|
1012
|
+
"item.size": "8.5",
|
|
1013
|
+
"item.color": "muted"
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
];
|
|
1017
|
+
function emptyLook() {
|
|
1018
|
+
const look = {
|
|
1019
|
+
colors: /* @__PURE__ */ new Map([["ink", "#222222"], ["muted", "#666666"], ["paper", "#ffffff"], ["card", "#ffffff"]]),
|
|
1020
|
+
fonts: /* @__PURE__ */ new Map([["sans", "Helvetica"], ["mono", "monospace"], ["serif", "serif"]]),
|
|
1021
|
+
fontDirs: [],
|
|
1022
|
+
canvas: {},
|
|
1023
|
+
styles: /* @__PURE__ */ new Map(),
|
|
1024
|
+
icons: new Map(Object.entries(ICONS)),
|
|
1025
|
+
iconDirs: [],
|
|
1026
|
+
images: /* @__PURE__ */ new Map(),
|
|
1027
|
+
guidance: [],
|
|
1028
|
+
issues: []
|
|
1029
|
+
};
|
|
1030
|
+
for (const s of BUILTIN) look.styles.set(s.name, { ...s, props: { ...s.props } });
|
|
1031
|
+
return look;
|
|
1032
|
+
}
|
|
1033
|
+
function parseLook(src, path = "look") {
|
|
1034
|
+
const look = emptyLook();
|
|
1035
|
+
for (const st of parseStatements(src)) {
|
|
1036
|
+
const [head, ...rest] = st.toks;
|
|
1037
|
+
const err = (msg) => look.issues.push({ line: st.line, level: "error", msg, file: path });
|
|
1038
|
+
if (head.t !== "word") {
|
|
1039
|
+
err("a look statement must start with canvas, color, font, fontdir, style, icon, icondir or guidance");
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
if (head.v === "icondir") {
|
|
1043
|
+
if (!rest[0]) err('icondir needs a folder of SVG files, e.g. icondir "./icons"');
|
|
1044
|
+
else look.iconDirs.push(rest[0].v);
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
if (head.v === "icon") {
|
|
1048
|
+
const name2 = rest[0]?.t === "word" ? rest[0].v : void 0, paths = rest.slice(1).filter((t) => t.t === "str").map((t) => t.v);
|
|
1049
|
+
if (!name2 || !/^[a-z][a-z0-9-]*$/.test(name2)) err('icon needs a name in small letters, e.g. icon queue "M4 6h16 M4 12h16 M4 18h16"');
|
|
1050
|
+
else if (!paths.length || paths.some((d) => !/^[MmLlHhVvCcSsQqTtAaZz0-9eE\s,.+-]+$/.test(d) || d.length > 4e3) || paths.length > 12) err(`icon ${name2} needs its outline as SVG path data in quotes, drawn in a 24x24 box, e.g. "M4 6h16 M4 12h16"`);
|
|
1051
|
+
else look.icons.set(name2, paths);
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (head.v === "fontdir") {
|
|
1055
|
+
if (!rest[0]) err('fontdir needs a folder, e.g. fontdir "./fonts"');
|
|
1056
|
+
else look.fontDirs.push(rest[0].v);
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
if (head.v === "canvas") {
|
|
1060
|
+
for (const t of rest) if (t.t === "prop") look.canvas[t.k] = t.v;
|
|
1061
|
+
} else if (head.v === "color" || head.v === "font") {
|
|
1062
|
+
if (rest.length < 2) {
|
|
1063
|
+
err(`${head.v} needs a name and a value`);
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
(head.v === "color" ? look.colors : look.fonts).set(rest[0].v, rest[1].v);
|
|
1067
|
+
} else if (head.v === "guidance") {
|
|
1068
|
+
for (const t of rest) if (t.t === "str") look.guidance.push(t.v);
|
|
1069
|
+
} else if (head.v === "style") {
|
|
1070
|
+
const name2 = rest[0]?.v;
|
|
1071
|
+
if (!name2) {
|
|
1072
|
+
err("style needs a name");
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
let kind;
|
|
1076
|
+
let props = {};
|
|
1077
|
+
for (let i = 1; i < rest.length; i++) {
|
|
1078
|
+
const t = rest[i];
|
|
1079
|
+
if (t.t === "prop") {
|
|
1080
|
+
props[t.k] = t.v;
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
if (t.v === "extends") {
|
|
1084
|
+
const base = look.styles.get(rest[++i]?.v);
|
|
1085
|
+
if (!base) {
|
|
1086
|
+
err(`style "${name2}" extends an unknown style "${rest[i]?.v}" (define the base first)`);
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
kind = kind ?? base.kind;
|
|
1090
|
+
props = { ...base.props, ...props };
|
|
1091
|
+
} else if (t.v === "line" || t.v === "text" || t.v === "shape") kind = t.v;
|
|
1092
|
+
else err(`unexpected word "${t.v}" in style "${name2}"`);
|
|
1093
|
+
}
|
|
1094
|
+
look.styles.set(name2, { name: name2, kind: kind ?? "shape", props });
|
|
1095
|
+
} else err(`unknown look statement "${head.v}"`);
|
|
1096
|
+
}
|
|
1097
|
+
return look;
|
|
1098
|
+
}
|
|
1099
|
+
function hexToRgb(hex) {
|
|
1100
|
+
let h = hex.slice(1);
|
|
1101
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
1102
|
+
if (!/^[0-9a-fA-F]{6}$/.test(h)) return null;
|
|
1103
|
+
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
|
|
1104
|
+
}
|
|
1105
|
+
function color(look, v) {
|
|
1106
|
+
if (!v || v === "none" || v === "transparent") return "none";
|
|
1107
|
+
let alpha;
|
|
1108
|
+
const m = /^(.*)\/([0-9.]+)$/.exec(v);
|
|
1109
|
+
if (m && !v.startsWith("rgb")) {
|
|
1110
|
+
v = m[1];
|
|
1111
|
+
alpha = parseFloat(m[2]);
|
|
1112
|
+
}
|
|
1113
|
+
let base = look.colors.get(v) ?? v;
|
|
1114
|
+
base = look.colors.get(base) ?? base;
|
|
1115
|
+
if (alpha === void 0) return base;
|
|
1116
|
+
const rgb = base.startsWith("#") ? hexToRgb(base) : null;
|
|
1117
|
+
if (!rgb) return base;
|
|
1118
|
+
return `rgba(${rgb[0]},${rgb[1]},${rgb[2]},${alpha})`;
|
|
1119
|
+
}
|
|
1120
|
+
function fontFamily(look, v) {
|
|
1121
|
+
const name2 = v ?? "sans";
|
|
1122
|
+
const fam2 = look.fonts.get(name2) ?? name2;
|
|
1123
|
+
const generic = name2 === "mono" ? "monospace" : name2 === "serif" ? "serif" : "sans-serif";
|
|
1124
|
+
return `'${fam2}', ${generic}`;
|
|
1125
|
+
}
|
|
1126
|
+
var cachedDefault;
|
|
1127
|
+
var BUNDLED_LOOK_NAMES = Object.keys(BUNDLED_LOOKS);
|
|
1128
|
+
var isBundledLook = (p) => !!p && Object.hasOwn(BUNDLED_LOOKS, p);
|
|
1129
|
+
var bundledCache = /* @__PURE__ */ new Map();
|
|
1130
|
+
function bundledLook(name2) {
|
|
1131
|
+
if (!isBundledLook(name2)) return null;
|
|
1132
|
+
let l = bundledCache.get(name2);
|
|
1133
|
+
if (!l) bundledCache.set(name2, l = parseLook(BUNDLED_LOOKS[name2], `${name2} look`));
|
|
1134
|
+
return l;
|
|
1135
|
+
}
|
|
1136
|
+
function defaultLook() {
|
|
1137
|
+
cachedDefault ??= parseLook(DEFAULT_LOOK, "default look");
|
|
1138
|
+
return cachedDefault;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// src/router.ts
|
|
1142
|
+
function segHits(A, B, r) {
|
|
1143
|
+
let t0 = 0, t1 = 1;
|
|
1144
|
+
const dx = B.x - A.x, dy = B.y - A.y;
|
|
1145
|
+
const edges = [[-dx, A.x - r.x], [dx, r.x + r.w - A.x], [-dy, A.y - r.y], [dy, r.y + r.h - A.y]];
|
|
1146
|
+
for (const [p, q] of edges) {
|
|
1147
|
+
if (p === 0) {
|
|
1148
|
+
if (q <= 0) return false;
|
|
1149
|
+
continue;
|
|
1150
|
+
}
|
|
1151
|
+
const t = q / p;
|
|
1152
|
+
if (p < 0) {
|
|
1153
|
+
if (t > t1) return false;
|
|
1154
|
+
if (t > t0) t0 = t;
|
|
1155
|
+
} else {
|
|
1156
|
+
if (t < t0) return false;
|
|
1157
|
+
if (t < t1) t1 = t;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return t1 - t0 > 1e-6;
|
|
1161
|
+
}
|
|
1162
|
+
var grow = (b, n) => ({ x: b.x - n, y: b.y - n, w: b.w + 2 * n, h: b.h + 2 * n });
|
|
1163
|
+
var inside = (b, p) => p.x > b.x && p.x < b.x + b.w && p.y > b.y && p.y < b.y + b.h;
|
|
1164
|
+
function crosses(pts, obstacles) {
|
|
1165
|
+
for (let i = 0; i < pts.length - 1; i++) for (const o of obstacles) if (segHits(pts[i], pts[i + 1], grow(o, -1))) return true;
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
function simplify(pts) {
|
|
1169
|
+
const out = [];
|
|
1170
|
+
for (const p of pts) {
|
|
1171
|
+
const a = out[out.length - 2], b = out[out.length - 1];
|
|
1172
|
+
if (b && b.x === p.x && b.y === p.y) continue;
|
|
1173
|
+
if (a && b && (a.x === b.x && b.x === p.x || a.y === b.y && b.y === p.y)) out[out.length - 1] = p;
|
|
1174
|
+
else out.push(p);
|
|
1175
|
+
}
|
|
1176
|
+
return out;
|
|
1177
|
+
}
|
|
1178
|
+
var CLEAR = 12;
|
|
1179
|
+
var STUB = 20;
|
|
1180
|
+
var BEND = 30;
|
|
1181
|
+
var SHARE = 160;
|
|
1182
|
+
var LANES = [CLEAR, CLEAR + 12, CLEAR + 24];
|
|
1183
|
+
function routeAround(P0, d0, P1, d1, obstacles, taken = []) {
|
|
1184
|
+
const S = d0 ? { x: P0.x + d0.x * STUB, y: P0.y + d0.y * STUB } : P0;
|
|
1185
|
+
const E = d1 ? { x: P1.x + d1.x * STUB, y: P1.y + d1.y * STUB } : P1;
|
|
1186
|
+
const uniq = (v) => [...new Set(v.map((n) => Math.round(n)))].sort((a, b) => a - b);
|
|
1187
|
+
const xs = uniq([S.x, E.x, ...obstacles.flatMap((o) => LANES.flatMap((l) => [o.x - l, o.x + o.w + l]))]);
|
|
1188
|
+
const ys = uniq([S.y, E.y, ...obstacles.flatMap((o) => LANES.flatMap((l) => [o.y - l, o.y + o.h + l]))]);
|
|
1189
|
+
const W = xs.length, H = ys.length;
|
|
1190
|
+
if (W * H > 6e4) return null;
|
|
1191
|
+
const shared = (A, B) => taken.some(([C, D]) => A.y === B.y && C.y === D.y && A.y === C.y && Math.min(Math.max(A.x, B.x), Math.max(C.x, D.x)) - Math.max(Math.min(A.x, B.x), Math.min(C.x, D.x)) > 0 || A.x === B.x && C.x === D.x && A.x === C.x && Math.min(Math.max(A.y, B.y), Math.max(C.y, D.y)) - Math.max(Math.min(A.y, B.y), Math.min(C.y, D.y)) > 0);
|
|
1192
|
+
const si = xs.indexOf(Math.round(S.x)) + ys.indexOf(Math.round(S.y)) * W;
|
|
1193
|
+
const ei = xs.indexOf(Math.round(E.x)) + ys.indexOf(Math.round(E.y)) * W;
|
|
1194
|
+
const pt = (i) => ({ x: xs[i % W], y: ys[Math.floor(i / W)] });
|
|
1195
|
+
const wide = obstacles.map((o) => grow(o, CLEAR - 1)), tight = obstacles.map((o) => grow(o, 2));
|
|
1196
|
+
const free = (i) => i === si || i === ei || !wide.some((o) => inside(o, pt(i)));
|
|
1197
|
+
const open = (a, b) => {
|
|
1198
|
+
const A = pt(a), B = pt(b);
|
|
1199
|
+
return !tight.some((o) => segHits(A, B, o));
|
|
1200
|
+
};
|
|
1201
|
+
const N = W * H * 2;
|
|
1202
|
+
const dist = new Float64Array(N).fill(Infinity), prev = new Int32Array(N).fill(-1);
|
|
1203
|
+
const heap = [];
|
|
1204
|
+
const push = (s) => {
|
|
1205
|
+
heap.push(s);
|
|
1206
|
+
let i = heap.length - 1;
|
|
1207
|
+
while (i > 0) {
|
|
1208
|
+
const p = i - 1 >> 1;
|
|
1209
|
+
if (dist[heap[p]] <= dist[heap[i]]) break;
|
|
1210
|
+
[heap[p], heap[i]] = [heap[i], heap[p]];
|
|
1211
|
+
i = p;
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
const pop = () => {
|
|
1215
|
+
const top = heap[0], last = heap.pop();
|
|
1216
|
+
if (heap.length) {
|
|
1217
|
+
heap[0] = last;
|
|
1218
|
+
for (let i = 0; ; ) {
|
|
1219
|
+
const l = 2 * i + 1, r = l + 1;
|
|
1220
|
+
let m = i;
|
|
1221
|
+
if (l < heap.length && dist[heap[l]] < dist[heap[m]]) m = l;
|
|
1222
|
+
if (r < heap.length && dist[heap[r]] < dist[heap[m]]) m = r;
|
|
1223
|
+
if (m === i) break;
|
|
1224
|
+
[heap[m], heap[i]] = [heap[i], heap[m]];
|
|
1225
|
+
i = m;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
return top;
|
|
1229
|
+
};
|
|
1230
|
+
const startDirs = d0 ? [d0.x !== 0 ? 0 : 1] : [0, 1];
|
|
1231
|
+
for (const d of startDirs) {
|
|
1232
|
+
dist[si * 2 + d] = 0;
|
|
1233
|
+
push(si * 2 + d);
|
|
1234
|
+
}
|
|
1235
|
+
const endDir = d1 ? d1.x !== 0 ? 0 : 1 : -1;
|
|
1236
|
+
let goal = -1;
|
|
1237
|
+
while (heap.length) {
|
|
1238
|
+
const s = pop(), i = s >> 1, dir = s & 1;
|
|
1239
|
+
if (i === ei) {
|
|
1240
|
+
goal = s;
|
|
1241
|
+
break;
|
|
1242
|
+
}
|
|
1243
|
+
const x = i % W, y = Math.floor(i / W);
|
|
1244
|
+
const steps = [];
|
|
1245
|
+
if (x > 0) steps.push([i - 1, 0]);
|
|
1246
|
+
if (x < W - 1) steps.push([i + 1, 0]);
|
|
1247
|
+
if (y > 0) steps.push([i - W, 1]);
|
|
1248
|
+
if (y < H - 1) steps.push([i + W, 1]);
|
|
1249
|
+
for (const [j, nd] of steps) {
|
|
1250
|
+
if (!free(j) || !open(i, j)) continue;
|
|
1251
|
+
const A = pt(i), B = pt(j);
|
|
1252
|
+
let cost = dist[s] + Math.abs(A.x - B.x) + Math.abs(A.y - B.y) + (nd !== dir ? BEND : 0) + (taken.length && shared(A, B) ? SHARE : 0);
|
|
1253
|
+
if (j === ei && endDir >= 0 && nd !== endDir) cost += BEND;
|
|
1254
|
+
const t = j * 2 + nd;
|
|
1255
|
+
if (cost < dist[t]) {
|
|
1256
|
+
dist[t] = cost;
|
|
1257
|
+
prev[t] = s;
|
|
1258
|
+
push(t);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
if (goal < 0) return null;
|
|
1263
|
+
const path = [];
|
|
1264
|
+
for (let s = goal; s >= 0; s = prev[s]) path.push(pt(s >> 1));
|
|
1265
|
+
path.reverse();
|
|
1266
|
+
return simplify([P0, ...path, P1]);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
// src/scene.ts
|
|
1270
|
+
var SERIES = ["bars", "line", "area", "dots"];
|
|
1271
|
+
var CANVAS_KEYS = ["paper", "dots", "dotgap"];
|
|
1272
|
+
var MARKERS = ["none", "arrow", "open", "triangle", "diamond", "diamond-solid", "dot", "circle", "one", "only-one", "many", "one-many", "zero-one", "zero-many"];
|
|
1273
|
+
var DIRS = { top: { x: 0, y: -1 }, bottom: { x: 0, y: 1 }, left: { x: -1, y: 0 }, right: { x: 1, y: 0 } };
|
|
1274
|
+
var num = (v, d) => v === void 0 || v === "" || isNaN(+v) ? d : +v;
|
|
1275
|
+
function textWidth(text, size, font, weight, spacing) {
|
|
1276
|
+
const f = font === "mono" ? 0.6 : font === "serif" ? 0.46 : weight >= 600 ? 0.58 : 0.56;
|
|
1277
|
+
return text.length * size * (f + spacing);
|
|
1278
|
+
}
|
|
1279
|
+
var cx = (b) => b.x + b.w / 2;
|
|
1280
|
+
var cy = (b) => b.y + b.h / 2;
|
|
1281
|
+
var within = (v, lo, hi) => v >= lo && v <= hi;
|
|
1282
|
+
function autoSides(A, B) {
|
|
1283
|
+
if (within(cx(A), B.x, B.x + B.w) || within(cx(B), A.x, A.x + A.w)) return cy(A) <= cy(B) ? ["bottom", "top"] : ["top", "bottom"];
|
|
1284
|
+
if (within(cy(A), B.y, B.y + B.h) || within(cy(B), A.y, A.y + A.h)) return cx(A) <= cx(B) ? ["right", "left"] : ["left", "right"];
|
|
1285
|
+
return [cx(B) > cx(A) ? "right" : "left", cy(A) < cy(B) ? "top" : "bottom"];
|
|
1286
|
+
}
|
|
1287
|
+
function sidePoint(s, side, v, f) {
|
|
1288
|
+
const horiz = side === "top" || side === "bottom";
|
|
1289
|
+
const frac = v !== void 0 && v <= 1 ? v : f;
|
|
1290
|
+
let along = v !== void 0 && v > 1 ? v : horiz ? s.x + frac * s.w : s.y + frac * s.h;
|
|
1291
|
+
along = Math.round(Math.min(Math.max(along, horiz ? s.x : s.y), horiz ? s.x + s.w : s.y + s.h));
|
|
1292
|
+
let inset2 = 0;
|
|
1293
|
+
const t = horiz ? Math.abs(along - cx(s)) / (s.w / 2 || 1) : Math.abs(along - cy(s)) / (s.h / 2 || 1);
|
|
1294
|
+
const half = horiz ? s.h / 2 : s.w / 2;
|
|
1295
|
+
if (s.shape === "diamond") inset2 = half * t;
|
|
1296
|
+
else if (s.shape === "ellipse") inset2 = half * (1 - Math.sqrt(Math.max(0, 1 - t * t)));
|
|
1297
|
+
inset2 = Math.round(inset2);
|
|
1298
|
+
if (side === "top") return { x: along, y: s.y + inset2 };
|
|
1299
|
+
if (side === "bottom") return { x: along, y: s.y + s.h - inset2 };
|
|
1300
|
+
if (side === "left") return { x: s.x + inset2, y: along };
|
|
1301
|
+
return { x: s.x + s.w - inset2, y: along };
|
|
1302
|
+
}
|
|
1303
|
+
function corner(A, B, horizFirst) {
|
|
1304
|
+
return horizFirst ? { x: B.x, y: A.y } : { x: A.x, y: B.y };
|
|
1305
|
+
}
|
|
1306
|
+
function route(c, via) {
|
|
1307
|
+
const P0 = c.a.pt, P1 = c.b.pt, d0 = c.a.dir, d1 = c.b.dir;
|
|
1308
|
+
if (!c.ortho) return [P0, ...via, P1];
|
|
1309
|
+
if (via.length === 0) {
|
|
1310
|
+
const aligned = P0.x === P1.x || P0.y === P1.y;
|
|
1311
|
+
if (d0 && d1) {
|
|
1312
|
+
const h0 = d0.x !== 0, h1 = d1.x !== 0;
|
|
1313
|
+
if (h0 !== h1) return [P0, corner(P0, P1, h0), P1];
|
|
1314
|
+
const same = d0.x === d1.x && d0.y === d1.y;
|
|
1315
|
+
if (same) {
|
|
1316
|
+
c.ushape = true;
|
|
1317
|
+
const off = num(c.p.loop, 36);
|
|
1318
|
+
if (h0) {
|
|
1319
|
+
const ox = d0.x > 0 ? Math.max(P0.x, P1.x) + off : Math.min(P0.x, P1.x) - off;
|
|
1320
|
+
return [P0, { x: ox, y: P0.y }, { x: ox, y: P1.y }, P1];
|
|
1321
|
+
}
|
|
1322
|
+
const oy = d0.y > 0 ? Math.max(P0.y, P1.y) + off : Math.min(P0.y, P1.y) - off;
|
|
1323
|
+
return [P0, { x: P0.x, y: oy }, { x: P1.x, y: oy }, P1];
|
|
1324
|
+
}
|
|
1325
|
+
if (h0 ? P0.y === P1.y : P0.x === P1.x) return [P0, P1];
|
|
1326
|
+
if (h0) {
|
|
1327
|
+
const mx = Math.round((P0.x + P1.x) / 2);
|
|
1328
|
+
return [P0, { x: mx, y: P0.y }, { x: mx, y: P1.y }, P1];
|
|
1329
|
+
}
|
|
1330
|
+
const my = Math.round((P0.y + P1.y) / 2);
|
|
1331
|
+
return [P0, { x: P0.x, y: my }, { x: P1.x, y: my }, P1];
|
|
1332
|
+
}
|
|
1333
|
+
if (aligned) return [P0, P1];
|
|
1334
|
+
const dx = P1.x - P0.x, dy = P1.y - P0.y, horiz = Math.abs(dx) >= Math.abs(dy);
|
|
1335
|
+
const zig = () => {
|
|
1336
|
+
if (horiz) {
|
|
1337
|
+
const mx = Math.round((P0.x + P1.x) / 2);
|
|
1338
|
+
return [P0, { x: mx, y: P0.y }, { x: mx, y: P1.y }, P1];
|
|
1339
|
+
}
|
|
1340
|
+
const my = Math.round((P0.y + P1.y) / 2);
|
|
1341
|
+
return [P0, { x: P0.x, y: my }, { x: P1.x, y: my }, P1];
|
|
1342
|
+
};
|
|
1343
|
+
const faces = (d, s) => horiz ? d.x * dx * s > 0 : d.y * dy * s > 0;
|
|
1344
|
+
if (d0) return faces(d0, 1) ? zig() : [P0, corner(P0, P1, d0.x !== 0), P1];
|
|
1345
|
+
if (d1) return faces(d1, -1) ? zig() : [P0, corner(P0, P1, d1.x === 0), P1];
|
|
1346
|
+
return zig();
|
|
1347
|
+
}
|
|
1348
|
+
const pts = [P0, ...via, P1];
|
|
1349
|
+
const out = [P0];
|
|
1350
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
1351
|
+
const A = pts[i], B = pts[i + 1];
|
|
1352
|
+
if (A.x !== B.x && A.y !== B.y) {
|
|
1353
|
+
let hf;
|
|
1354
|
+
if (i === pts.length - 2 && d1) hf = d1.x === 0;
|
|
1355
|
+
else if (i === 0 && d0) hf = d0.x !== 0;
|
|
1356
|
+
else {
|
|
1357
|
+
const prev = out[out.length - 2];
|
|
1358
|
+
hf = prev ? prev.y !== A.y : true;
|
|
1359
|
+
}
|
|
1360
|
+
out.push(corner(A, B, hf));
|
|
1361
|
+
}
|
|
1362
|
+
out.push(B);
|
|
1363
|
+
}
|
|
1364
|
+
return out;
|
|
1365
|
+
}
|
|
1366
|
+
function curvePts(P0, d0, P1, d1, via, bend) {
|
|
1367
|
+
const segs = [];
|
|
1368
|
+
const dx = P1.x - P0.x, dy = P1.y - P0.y, dist = Math.hypot(dx, dy) || 1;
|
|
1369
|
+
if (via.length) {
|
|
1370
|
+
const P = [P0, ...via, P1];
|
|
1371
|
+
const unit = (x, y) => {
|
|
1372
|
+
const l = Math.hypot(x, y) || 1;
|
|
1373
|
+
return { x: x / l, y: y / l };
|
|
1374
|
+
};
|
|
1375
|
+
const T = P.map((p, i) => i === 0 ? d0 ?? unit(P[1].x - p.x, P[1].y - p.y) : i === P.length - 1 ? d1 ? { x: -d1.x, y: -d1.y } : unit(p.x - P[i - 1].x, p.y - P[i - 1].y) : unit(P[i + 1].x - P[i - 1].x, P[i + 1].y - P[i - 1].y));
|
|
1376
|
+
for (let i = 0; i < P.length - 1; i++) {
|
|
1377
|
+
const p1 = P[i], p2 = P[i + 1], L = Math.hypot(p2.x - p1.x, p2.y - p1.y) / 3;
|
|
1378
|
+
segs.push([p1, { x: p1.x + T[i].x * L, y: p1.y + T[i].y * L }, { x: p2.x - T[i + 1].x * L, y: p2.y - T[i + 1].y * L }, p2]);
|
|
1379
|
+
}
|
|
1380
|
+
} else if (!isNaN(bend)) {
|
|
1381
|
+
const ox = dy / dist * bend * (4 / 3), oy = -dx / dist * bend * (4 / 3);
|
|
1382
|
+
segs.push([P0, { x: P0.x + dx / 3 + ox, y: P0.y + dy / 3 + oy }, { x: P0.x + 2 * dx / 3 + ox, y: P0.y + 2 * dy / 3 + oy }, P1]);
|
|
1383
|
+
} else {
|
|
1384
|
+
const k = Math.min(Math.max(dist * 0.4, 24), 160);
|
|
1385
|
+
const flat = Math.abs(dx) >= Math.abs(dy);
|
|
1386
|
+
const u0 = d0 ?? (flat ? { x: Math.sign(dx) || 1, y: 0 } : { x: 0, y: Math.sign(dy) || 1 });
|
|
1387
|
+
const u1 = d1 ?? (flat ? { x: -(Math.sign(dx) || 1), y: 0 } : { x: 0, y: -(Math.sign(dy) || 1) });
|
|
1388
|
+
segs.push([P0, { x: P0.x + u0.x * k, y: P0.y + u0.y * k }, { x: P1.x + u1.x * k, y: P1.y + u1.y * k }, P1]);
|
|
1389
|
+
}
|
|
1390
|
+
const out = [P0];
|
|
1391
|
+
const N = 24;
|
|
1392
|
+
for (const [a, b, c, d] of segs) for (let i = 1; i <= N; i++) {
|
|
1393
|
+
const t = i / N, m = 1 - t;
|
|
1394
|
+
const f = (p) => m * m * m * a[p] + 3 * m * m * t * b[p] + 3 * m * t * t * c[p] + t * t * t * d[p];
|
|
1395
|
+
out.push(i === N ? d : { x: Math.round(f("x") * 10) / 10, y: Math.round(f("y") * 10) / 10 });
|
|
1396
|
+
}
|
|
1397
|
+
return out;
|
|
1398
|
+
}
|
|
1399
|
+
function pointAlong(c, v) {
|
|
1400
|
+
const first = c.pts[0], last = c.pts[c.pts.length - 1];
|
|
1401
|
+
if (v > 1) {
|
|
1402
|
+
if (first.x === last.x) return { x: first.x, y: v };
|
|
1403
|
+
if (first.y === last.y) return { x: v, y: first.y };
|
|
1404
|
+
}
|
|
1405
|
+
const f = Math.min(Math.max(v, 0), 1);
|
|
1406
|
+
return { x: Math.round(first.x + (last.x - first.x) * f), y: Math.round(first.y + (last.y - first.y) * f) };
|
|
1407
|
+
}
|
|
1408
|
+
function makeLabel(c, avoid = []) {
|
|
1409
|
+
if (!c.text) return void 0;
|
|
1410
|
+
const size = num(c.p["label.size"], 8), spacing = num(c.p["label.spacing"], 0.08), font = c.p["label.font"] ?? "mono";
|
|
1411
|
+
const text = c.p["label.caps"] === "0" ? c.text : c.text.toUpperCase();
|
|
1412
|
+
const w = Math.ceil((textWidth(text, size, font, 400, spacing) + 12) / 4) * 4, h = size + 4;
|
|
1413
|
+
if (c.p.lpos) {
|
|
1414
|
+
const [lx, ly] = c.p.lpos.split(",").map(Number);
|
|
1415
|
+
return { text, cx: lx, baseline: ly, x: lx - w / 2, y: ly - h + 2, w, h, size, spacing, font };
|
|
1416
|
+
}
|
|
1417
|
+
let best = 0;
|
|
1418
|
+
if (c.curve) best = Math.floor((c.pts.length - 1) / 2);
|
|
1419
|
+
else if (c.ushape && c.pts.length === 4) best = 1;
|
|
1420
|
+
else {
|
|
1421
|
+
let len = -1;
|
|
1422
|
+
for (let i = 0; i < c.pts.length - 1; i++) {
|
|
1423
|
+
const l = Math.abs(c.pts[i + 1].x - c.pts[i].x) + Math.abs(c.pts[i + 1].y - c.pts[i].y);
|
|
1424
|
+
if (l > len) {
|
|
1425
|
+
len = l;
|
|
1426
|
+
best = i;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
const A = c.pts[best], B = c.pts[best + 1];
|
|
1431
|
+
const mx = (A.x + B.x) / 2, my = (A.y + B.y) / 2;
|
|
1432
|
+
const at = (side) => {
|
|
1433
|
+
if (c.curve) {
|
|
1434
|
+
const P = c.pts[best], Q = c.pts[Math.min(best + 1, c.pts.length - 1)], O = c.pts[Math.max(best - 1, 0)];
|
|
1435
|
+
const tx = Q.x - O.x, ty = Q.y - O.y, tl = Math.hypot(tx, ty) || 1;
|
|
1436
|
+
let nx = ty / tl, ny = -tx / tl;
|
|
1437
|
+
if (ny > 0 || ny === 0 && nx < 0) {
|
|
1438
|
+
nx = -nx;
|
|
1439
|
+
ny = -ny;
|
|
1440
|
+
}
|
|
1441
|
+
if (side === "below" || side === "left") {
|
|
1442
|
+
nx = -nx;
|
|
1443
|
+
ny = -ny;
|
|
1444
|
+
}
|
|
1445
|
+
const off = 6 + (Math.abs(nx) * w + Math.abs(ny) * h) / 2;
|
|
1446
|
+
const lx = Math.round(P.x + nx * off), ly = Math.round(P.y + ny * off);
|
|
1447
|
+
return { text, cx: lx, baseline: ly + h / 2 - 3, x: lx - w / 2, y: ly - h / 2, w, h, size, spacing, font };
|
|
1448
|
+
}
|
|
1449
|
+
if (A.x === B.x && A.y !== B.y) {
|
|
1450
|
+
const x = side === "left" ? A.x - 8 - w : A.x + 8;
|
|
1451
|
+
return { text, cx: x + w / 2, baseline: Math.round(my) + 3, x, y: Math.round(my) - h + 5, w, h, size, spacing, font };
|
|
1452
|
+
}
|
|
1453
|
+
const baseline = side === "below" ? Math.round(my) + 18 : Math.round(my) - 10;
|
|
1454
|
+
return { text, cx: Math.round(mx), baseline, x: Math.round(mx) - w / 2, y: baseline - h + 2, w, h, size, spacing, font };
|
|
1455
|
+
};
|
|
1456
|
+
const hits = (l) => avoid.some((o) => l.x < o.x + o.w && l.x + l.w > o.x && l.y < o.y + o.h && l.y + l.h > o.y);
|
|
1457
|
+
const first = at(c.p.lside);
|
|
1458
|
+
if (c.p.lside || !hits(first)) return first;
|
|
1459
|
+
const other = at(A.x === B.x && A.y !== B.y ? "left" : "below");
|
|
1460
|
+
return hits(other) ? first : other;
|
|
1461
|
+
}
|
|
1462
|
+
function layoutTable(sh, rows, minW, err, warn) {
|
|
1463
|
+
const p = sh.p;
|
|
1464
|
+
const fs = num(p["cell.size"], 10), font = p["cell.font"] ?? "mono";
|
|
1465
|
+
const rowH = num(p["row.h"], 24), pad = num(p["cell.pad"], 12), gap = num(p["cell.gap"], 16);
|
|
1466
|
+
const tsize = num(p["title.size"], 12), tlines = sh.text ? sh.text.split("\n") : [];
|
|
1467
|
+
const headH = sh.text ? num(p["head.h"], 32) + (tlines.length - 1) * Math.ceil(tsize * 1.25 / 4) * 4 : 0;
|
|
1468
|
+
const n = Math.max(0, ...rows.map((r) => r.cells.length));
|
|
1469
|
+
const widths = [];
|
|
1470
|
+
const spans = (r) => n > 1 && r.cells.length === 1 && r.kind !== "head";
|
|
1471
|
+
for (let j = 0; j < n; j++) widths.push(Math.max(0, ...rows.filter((r) => !spans(r)).map((r) => r.cells[j] === void 0 ? 0 : textWidth(r.cells[j], fs, font, r.kind === "head" ? 600 : 400, 0))));
|
|
1472
|
+
if (p.align === "center" && n > 1) {
|
|
1473
|
+
const m = Math.max(...widths.slice(1));
|
|
1474
|
+
for (let j = 1; j < n; j++) widths[j] = m;
|
|
1475
|
+
}
|
|
1476
|
+
const spanW = Math.max(0, ...rows.filter(spans).map((r) => textWidth(r.cells[0], fs, font, 400, 0) + pad * 2));
|
|
1477
|
+
const colsW = n ? pad * 2 + widths.reduce((a, b) => a + b, 0) + gap * (n - 1) : 0;
|
|
1478
|
+
const natural = Math.max(spanW, colsW);
|
|
1479
|
+
const titleW = sh.text ? Math.max(...tlines.map((l) => textWidth(l, tsize, p["title.font"] ?? "sans", num(p["title.weight"], 600), num(p["title.spacing"], 0)))) + pad * 2 : 0;
|
|
1480
|
+
const W = Math.ceil(Math.max(minW, natural, titleW, 48) / 4) * 4;
|
|
1481
|
+
if (minW && Math.max(natural, titleW) > minW + 4) warn(`${sh.id} was given a width of ${minW} but its content needs ${W}, so it is drawn ${W} wide; shorten the cells or give it room`);
|
|
1482
|
+
if (n) widths[0] += W - colsW;
|
|
1483
|
+
const cols = [];
|
|
1484
|
+
let x = pad;
|
|
1485
|
+
for (const w of widths) {
|
|
1486
|
+
cols.push({ x, w });
|
|
1487
|
+
x += w + gap;
|
|
1488
|
+
}
|
|
1489
|
+
let y = sh.y + headH;
|
|
1490
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1491
|
+
for (const r of rows) {
|
|
1492
|
+
r.y = y;
|
|
1493
|
+
r.h = r.kind === "rule" ? 0 : num(r.p.h, rowH);
|
|
1494
|
+
y += r.h;
|
|
1495
|
+
if (r.id) {
|
|
1496
|
+
if (seen.has(r.id)) err(`the row id "${r.id}" is used twice in ${sh.id}`);
|
|
1497
|
+
seen.add(r.id);
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
sh.w = W;
|
|
1501
|
+
sh.h = Math.max(y - sh.y, rowH);
|
|
1502
|
+
sh.rows = rows;
|
|
1503
|
+
sh.cols = cols;
|
|
1504
|
+
sh.headH = headH;
|
|
1505
|
+
}
|
|
1506
|
+
function parseEnd(raw) {
|
|
1507
|
+
const base = { raw, pt: { x: 0, y: 0 }, dir: null };
|
|
1508
|
+
let m = /^(\+\d+(?:\.\d+)?),([+-]?\d+(?:\.\d+)?)$/.exec(raw) ?? /^(-\d+(?:\.\d+)?),(\+\d+(?:\.\d+)?)$/.exec(raw);
|
|
1509
|
+
if (m) return { ...base, kind: "rel", rel: { x: +m[1], y: +m[2] } };
|
|
1510
|
+
m = /^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/.exec(raw);
|
|
1511
|
+
if (m) return { ...base, kind: "point", pt: { x: +m[1], y: +m[2] } };
|
|
1512
|
+
m = /^([A-Za-z_][\w-]*)(?:\.([A-Za-z_][\w-]*))?(?:\.(left|right))?(?:@(-?[\d.]+))?$/.exec(raw);
|
|
1513
|
+
if (m) {
|
|
1514
|
+
const isSide = m[2] !== void 0 && m[2] in DIRS;
|
|
1515
|
+
if (isSide && m[3]) return null;
|
|
1516
|
+
return { ...base, kind: "shape", id: m[1], row: isSide ? void 0 : m[2], side: isSide ? m[2] : m[3], v: m[4] === void 0 ? void 0 : +m[4] };
|
|
1517
|
+
}
|
|
1518
|
+
return null;
|
|
1519
|
+
}
|
|
1520
|
+
function lookPath(src) {
|
|
1521
|
+
const st = parseStatements(src).find((s) => s.toks[0]?.t === "word" && s.toks[0].v === "look");
|
|
1522
|
+
return st?.toks[1]?.v;
|
|
1523
|
+
}
|
|
1524
|
+
function buildScene(src, lookIn, file = "") {
|
|
1525
|
+
const issues = [];
|
|
1526
|
+
const err = (line, msg) => issues.push({ line, level: "error", msg });
|
|
1527
|
+
const warn = (line, msg) => issues.push({ line, level: "warn", msg });
|
|
1528
|
+
const stmts = parseStatements(src);
|
|
1529
|
+
const lookStmt = stmts.find((s) => s.toks[0]?.v === "look" && s.toks[0].t === "word");
|
|
1530
|
+
const named = bundledLook(lookStmt?.toks[1]?.v ?? "");
|
|
1531
|
+
let look = named ?? lookIn ?? (lookStmt ? emptyLook() : defaultLook());
|
|
1532
|
+
const baseCanvas = look.canvas;
|
|
1533
|
+
if (lookStmt) {
|
|
1534
|
+
const p = lookStmt.toks[1]?.v;
|
|
1535
|
+
if (!p) err(lookStmt.line, `look needs a name or a path, e.g. look sketch or look "./team.look" (named looks: ${BUNDLED_LOOK_NAMES.join(", ")})`);
|
|
1536
|
+
else if (!named && !lookIn) err(lookStmt.line, /[\\/]|\.look$/i.test(p) ? `look file not found: ${p}` : `no look named ${p}; named looks: ${BUNDLED_LOOK_NAMES.join(", ")}, or give a path to a .look file`);
|
|
1537
|
+
else for (const i of look.issues) issues.push({ ...i, line: lookStmt.line, msg: `${i.msg} (in look, line ${i.line})` });
|
|
1538
|
+
}
|
|
1539
|
+
const shapes = [], texts = [], conns = [];
|
|
1540
|
+
const ids = /* @__PURE__ */ new Map();
|
|
1541
|
+
let canvasLine, canvasSize = false;
|
|
1542
|
+
const legends = [];
|
|
1543
|
+
const unplaced = [];
|
|
1544
|
+
const styleNames = () => [...look.styles.values()];
|
|
1545
|
+
for (const st of stmts) {
|
|
1546
|
+
const toks = st.toks;
|
|
1547
|
+
const first = toks[0];
|
|
1548
|
+
if (first.t === "word" && first.v === "look") continue;
|
|
1549
|
+
if (first.t === "word" && first.v === "canvas") {
|
|
1550
|
+
canvasLine = st.line;
|
|
1551
|
+
const bg = {};
|
|
1552
|
+
for (const t of toks.slice(1)) {
|
|
1553
|
+
if (/^\d+x\d+$/.test(t.v ?? "")) canvasSize = true;
|
|
1554
|
+
else if (t.t === "prop" && CANVAS_KEYS.includes(t.k)) bg[t.k] = t.v;
|
|
1555
|
+
else err(st.line, `canvas only takes ${CANVAS_KEYS.map((k) => k + "=").join(", ")}; remove ${t.t === "prop" ? t.k + "=" : t.v}`);
|
|
1556
|
+
}
|
|
1557
|
+
if (Object.keys(bg).length) look = { ...look, canvas: { ...look.canvas, ...bg } };
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
let i = 0;
|
|
1561
|
+
let id;
|
|
1562
|
+
if (first.t === "word" && first.v.endsWith(":") && first.v.length > 1) {
|
|
1563
|
+
id = first.v.slice(0, -1);
|
|
1564
|
+
i = 1;
|
|
1565
|
+
}
|
|
1566
|
+
const opIdx = toks.findIndex((t) => t.t === "word" && (t.v === "->" || t.v === "--" || t.v === "<->"));
|
|
1567
|
+
const register = (kind, auto) => {
|
|
1568
|
+
const finalId = id ?? `_${auto}${st.line}`;
|
|
1569
|
+
if (ids.has(finalId)) err(st.line, `the id "${finalId}" is already used; ids must be unique`);
|
|
1570
|
+
ids.set(finalId, kind);
|
|
1571
|
+
return finalId;
|
|
1572
|
+
};
|
|
1573
|
+
if (opIdx >= 0) {
|
|
1574
|
+
const aTok = toks[opIdx - 1], bTok = toks[opIdx + 1];
|
|
1575
|
+
if (!aTok || opIdx - 1 < i || !bTok) {
|
|
1576
|
+
err(st.line, "a connector needs something on both sides, e.g. a -> b");
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
const a = parseEnd(aTok.v), b = parseEnd(bTok.v);
|
|
1580
|
+
if (!a || !b) {
|
|
1581
|
+
err(st.line, `cannot read the connector end "${!a ? aTok.v : bTok.v}"; use an id, id.side, id.side@pos, id@pos or x,y`);
|
|
1582
|
+
continue;
|
|
1583
|
+
}
|
|
1584
|
+
const op = toks[opIdx].v;
|
|
1585
|
+
const over3 = {};
|
|
1586
|
+
let text2;
|
|
1587
|
+
for (const t of toks.slice(opIdx + 2)) {
|
|
1588
|
+
if (t.t === "str") text2 = text2 ?? t.v;
|
|
1589
|
+
else if (t.t === "prop") over3[t.k] = t.v;
|
|
1590
|
+
else err(st.line, `unexpected word "${t.v}" after the connector; properties look like key=value`);
|
|
1591
|
+
}
|
|
1592
|
+
const styleName2 = over3.style ?? (op === "--" ? a.row || b.row ? "relation" : "line" : "arrow");
|
|
1593
|
+
const style2 = look.styles.get(styleName2);
|
|
1594
|
+
if (!style2 || style2.kind !== "line") {
|
|
1595
|
+
err(st.line, `"${styleName2}" is not a line style in the look; line styles: ${styleNames().filter((s) => s.kind === "line").map((s) => s.name).join(", ")}`);
|
|
1596
|
+
continue;
|
|
1597
|
+
}
|
|
1598
|
+
const p2 = { ...style2.props, ...over3 };
|
|
1599
|
+
if (p2.route && !["ortho", "straight", "curve"].includes(p2.route)) err(st.line, `route=${p2.route} is not a route; use ortho, straight or curve`);
|
|
1600
|
+
const styleHead = style2.props.head && style2.props.head !== "none" ? style2.props.head : "arrow";
|
|
1601
|
+
const plain = style2.props.head === "none" && styleName2 !== "line";
|
|
1602
|
+
const headM = over3.head ?? (op === "--" || plain ? "none" : styleHead);
|
|
1603
|
+
const tailM = over3.tail ?? (op === "<->" ? headM : op === "--" ? "none" : style2.props.tail ?? "none");
|
|
1604
|
+
for (const mk of [headM, tailM]) if (!MARKERS.includes(mk)) err(st.line, `"${mk}" is not an end marker; use one of: ${MARKERS.join(", ")}`);
|
|
1605
|
+
const ok = (mk) => MARKERS.includes(mk) ? mk : "arrow";
|
|
1606
|
+
conns.push({
|
|
1607
|
+
id: register("conn", "c"),
|
|
1608
|
+
line: st.line,
|
|
1609
|
+
style: styleName2,
|
|
1610
|
+
p: p2,
|
|
1611
|
+
a,
|
|
1612
|
+
b,
|
|
1613
|
+
pts: [],
|
|
1614
|
+
head: headM !== "none",
|
|
1615
|
+
tail: tailM !== "none",
|
|
1616
|
+
headM: ok(headM),
|
|
1617
|
+
tailM: ok(tailM),
|
|
1618
|
+
ortho: (p2.route ?? "ortho") === "ortho",
|
|
1619
|
+
curve: p2.route === "curve",
|
|
1620
|
+
ushape: false,
|
|
1621
|
+
text: text2
|
|
1622
|
+
});
|
|
1623
|
+
continue;
|
|
1624
|
+
}
|
|
1625
|
+
const kindTok = toks[i++];
|
|
1626
|
+
if (!kindTok || kindTok.t !== "word") {
|
|
1627
|
+
err(st.line, 'expected: id: style "text" at x,y');
|
|
1628
|
+
continue;
|
|
1629
|
+
}
|
|
1630
|
+
let style = look.styles.get(kindTok.v);
|
|
1631
|
+
if (!style || style.kind === "line") {
|
|
1632
|
+
err(st.line, `unknown style "${kindTok.v}"; available: ${styleNames().filter((s) => s.kind !== "line").map((s) => s.name).join(", ")}`);
|
|
1633
|
+
continue;
|
|
1634
|
+
}
|
|
1635
|
+
let text, at, size;
|
|
1636
|
+
const over2 = {};
|
|
1637
|
+
const rows = [];
|
|
1638
|
+
for (; i < toks.length; i++) {
|
|
1639
|
+
const t = toks[i];
|
|
1640
|
+
if (t.t === "word" && (t.v === "|" || t.v === "|=")) {
|
|
1641
|
+
rows.push({ kind: t.v === "|" ? "row" : "head", cells: [], vals: [], p: {}, y: 0, h: 0 });
|
|
1642
|
+
continue;
|
|
1643
|
+
}
|
|
1644
|
+
const row = rows[rows.length - 1];
|
|
1645
|
+
if (row) {
|
|
1646
|
+
if (t.t === "str") row.cells.push(t.v);
|
|
1647
|
+
else if (t.t === "prop") row.p[t.k] = t.v;
|
|
1648
|
+
else if (t.v === "---" && !row.cells.length && !row.id) row.kind = "rule";
|
|
1649
|
+
else if (!row.id && !row.cells.length && /^[A-Za-z_][\w-]*$/.test(t.v) && !(t.v in DIRS)) row.id = t.v;
|
|
1650
|
+
else if (/^([+-]?\d*\.?\d+(,[+-]?\d*\.?\d+){0,2}|_)$/.test(t.v)) row.vals.push(t.v);
|
|
1651
|
+
else err(st.line, `unexpected word "${t.v}" in a table row; a row is: | id "cell" "cell" (the id is optional, and cannot be top, bottom, left or right)`);
|
|
1652
|
+
continue;
|
|
1653
|
+
}
|
|
1654
|
+
if (t.t === "str") text = text ?? t.v;
|
|
1655
|
+
else if (t.t === "prop") over2[t.k] = t.v;
|
|
1656
|
+
else if (t.v === "at") {
|
|
1657
|
+
const m = /^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/.exec(toks[++i]?.v ?? "");
|
|
1658
|
+
if (!m) err(st.line, 'after "at" write the position as x,y with no space, e.g. at 40,240');
|
|
1659
|
+
else at = { x: +m[1], y: +m[2] };
|
|
1660
|
+
} else if (/^\d+(\.\d+)?x\d+(\.\d+)?$/.test(t.v)) {
|
|
1661
|
+
const [w, h] = t.v.split("x").map(Number);
|
|
1662
|
+
size = { w, h };
|
|
1663
|
+
} else err(st.line, `unexpected word "${t.v}"; properties look like key=value and text goes in "quotes"`);
|
|
1664
|
+
}
|
|
1665
|
+
let base = style.props;
|
|
1666
|
+
let styleName = style.name;
|
|
1667
|
+
if (over2.style) {
|
|
1668
|
+
const s2 = look.styles.get(over2.style);
|
|
1669
|
+
if (!s2 || s2.kind !== style.kind) err(st.line, `style=${over2.style} is not a ${style.kind} style in the look`);
|
|
1670
|
+
else {
|
|
1671
|
+
base = { ...base, ...s2.props };
|
|
1672
|
+
styleName = s2.name;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
const p = { ...base, ...over2 };
|
|
1676
|
+
if (style.kind === "text") {
|
|
1677
|
+
if (!at) {
|
|
1678
|
+
err(st.line, "text needs a position: at x,y");
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
const fs = num(p.size, 12);
|
|
1682
|
+
const lines = (text ?? "").split("\n");
|
|
1683
|
+
const t2 = p.caps === "1" ? (text ?? "").toUpperCase() : text ?? "";
|
|
1684
|
+
const w = Math.max(...lines.map((l) => textWidth(l, fs, p.font ?? "sans", num(p.weight, 400), num(p.spacing, 0))));
|
|
1685
|
+
const anchor = p.anchor ?? "start";
|
|
1686
|
+
const x = anchor === "middle" ? at.x - w / 2 : anchor === "end" ? at.x - w : at.x;
|
|
1687
|
+
const th = fs * 1.3 * lines.length;
|
|
1688
|
+
const rot = num(p.rotate, 0);
|
|
1689
|
+
if (p.rotate !== void 0 && ![0, 90, -90].includes(rot)) err(st.line, `rotate=${p.rotate}: text can be turned by 90 (reading down) or -90 (reading up)`);
|
|
1690
|
+
const dx = x - at.x;
|
|
1691
|
+
const box = rot === -90 ? { x: at.x - fs, y: at.y - dx - w, w: th, h: w } : rot === 90 ? { x: at.x - th + fs, y: at.y + dx, w: th, h: w } : { x, y: at.y - fs, w, h: th };
|
|
1692
|
+
texts.push({ id: register("text", "t"), line: st.line, style: styleName, p, text: t2, ax: at.x, ay: at.y, ...box });
|
|
1693
|
+
continue;
|
|
1694
|
+
}
|
|
1695
|
+
if (!size && p.size) {
|
|
1696
|
+
const m = /^(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)$/.exec(p.size);
|
|
1697
|
+
if (m) size = { w: +m[1], h: +m[2] };
|
|
1698
|
+
}
|
|
1699
|
+
const size0 = size;
|
|
1700
|
+
size = size ?? { w: 120, h: 48 };
|
|
1701
|
+
const sh = {
|
|
1702
|
+
id: register("shape", "s"),
|
|
1703
|
+
line: st.line,
|
|
1704
|
+
style: styleName,
|
|
1705
|
+
p,
|
|
1706
|
+
shape: p.shape ?? "rect",
|
|
1707
|
+
text,
|
|
1708
|
+
back: p.layer === "back",
|
|
1709
|
+
x: at?.x ?? 0,
|
|
1710
|
+
y: at?.y ?? 0,
|
|
1711
|
+
w: size.w,
|
|
1712
|
+
h: size.h
|
|
1713
|
+
};
|
|
1714
|
+
if (p.icon && p.icon !== "none" && !look.icons.has(p.icon) && !look.images.has(p.icon)) {
|
|
1715
|
+
const all = [...look.images.keys(), ...look.icons.keys()];
|
|
1716
|
+
const near = all.filter((n) => iconMatches(n, p.icon) || n.length > 2 && p.icon.includes(n)), list2 = [.../* @__PURE__ */ new Set([...near, ...all])].slice(0, 40);
|
|
1717
|
+
const folder = look.iconDirs.length && !look.images.size ? ` (the look's icon folder ${look.iconDirs.join(", ")} could not be read here)` : "";
|
|
1718
|
+
err(st.line, `there is no icon called "${p.icon}"${folder}; the look has: ${list2.join(", ")}${all.length > list2.length ? `, and ${all.length - list2.length} more (run "fastdraw icons" to see them all)` : ""}`);
|
|
1719
|
+
}
|
|
1720
|
+
if (p["icon.width"] !== void 0 && !(Number(p["icon.width"]) > 0 && Number(p["icon.width"]) <= 8)) err(st.line, `icon.width=${p["icon.width"]}: the icon's line thickness in pixels, a number from 0.5 to 8 (e.g. icon.width=2)`);
|
|
1721
|
+
if (p["icon.pos"] && !["left", "top"].includes(p["icon.pos"])) err(st.line, `icon.pos=${p["icon.pos"]}: an icon sits left of the text or on top of it (icon.pos=left or icon.pos=top)`);
|
|
1722
|
+
for (const k of ["color", "weight", "font", "italic"]) if (over2[k] !== void 0) warn(st.line, `${k}= does nothing on a shape; its text is set with title.${k}= (and sub.${k}= for the second line)`);
|
|
1723
|
+
if (sh.shape === "polygon") {
|
|
1724
|
+
const rel = (p.points ?? "").split(";").filter(Boolean).map((q) => {
|
|
1725
|
+
const [x, y] = q.split(",").map(Number);
|
|
1726
|
+
return { x, y };
|
|
1727
|
+
});
|
|
1728
|
+
if (rel.length < 2 || rel.some((q) => isNaN(q.x) || isNaN(q.y))) err(st.line, 'a polygon needs its corners: points=x,y;x,y;x,y measured from its "at" position, e.g. points=60,0;120,100;0,100');
|
|
1729
|
+
else {
|
|
1730
|
+
const nw = Math.max(...rel.map((q) => q.x)), nh = Math.max(...rel.map((q) => q.y));
|
|
1731
|
+
if (rel.some((q) => q.x < 0 || q.y < 0)) err(st.line, 'polygon points cannot be negative; they are measured from the "at" position, which is the top-left of the shape');
|
|
1732
|
+
if (!size0) {
|
|
1733
|
+
sh.w = nw;
|
|
1734
|
+
sh.h = nh;
|
|
1735
|
+
}
|
|
1736
|
+
const kx = nw ? sh.w / nw : 1, ky = nh ? sh.h / nh : 1;
|
|
1737
|
+
sh.poly = rel.map((q) => ({ x: Math.round((sh.x + q.x * kx) * 100) / 100, y: Math.round((sh.y + q.y * ky) * 100) / 100 }));
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
if (sh.shape === "arc") {
|
|
1741
|
+
for (const k of ["from", "to", "inner"]) if (p[k] !== void 0 && isNaN(+p[k])) err(st.line, `${k}=${p[k]} must be a number (from= and to= are degrees clockwise from the top; inner= is 0 to 1)`);
|
|
1742
|
+
}
|
|
1743
|
+
if (sh.shape === "table") layoutTable(sh, rows, size0?.w ?? 0, (m) => err(st.line, m), (m) => warn(st.line, m));
|
|
1744
|
+
else if (sh.shape === "chart") {
|
|
1745
|
+
sh.rows = rows;
|
|
1746
|
+
if (!size0) err(st.line, "a chart needs a size for its plot area: at x,y WxH");
|
|
1747
|
+
for (const k of ["step", "xstep"]) if (p[k] !== void 0 && !(Number(p[k]) > 0)) err(st.line, `${k}=${p[k]} must be a number above 0`);
|
|
1748
|
+
for (const k of ["x", "y"]) {
|
|
1749
|
+
const m = /^(-?[\d.]+)\.\.(-?[\d.]+)$/.exec(p[k] ?? "");
|
|
1750
|
+
if (m && !(+m[2] > +m[1])) err(st.line, `${k}=${p[k]} must run upwards, e.g. ${k}=0..100`);
|
|
1751
|
+
}
|
|
1752
|
+
const n = p.x && !/^-?[\d.]+\.\.-?[\d.]+$/.test(p.x) ? p.x.split(",").length : 0;
|
|
1753
|
+
for (const r of rows) {
|
|
1754
|
+
if (!r.id || !SERIES.includes(r.id)) err(st.line, `a chart row starts with the kind of series: ${SERIES.join(", ")}; e.g. | bars "Revenue" 42 61 75`);
|
|
1755
|
+
else if (!r.vals.length) err(st.line, `the ${r.id} series ${r.cells[0] ? `"${r.cells[0]}" ` : ""}has no numbers; write them after the name: | ${r.id} "Name" 42 61 75`);
|
|
1756
|
+
else if (n && r.vals.length !== n && !r.vals[0].includes(",")) warn(st.line, `the ${r.id} series ${r.cells[0] ? `"${r.cells[0]}" ` : ""}has ${r.vals.length} values but x= names ${n} categories`);
|
|
1757
|
+
}
|
|
1758
|
+
} else if (rows.length) err(st.line, `rows (the parts starting with "|") only work on a table style; "${styleName}" is not one`);
|
|
1759
|
+
if (sh.shape === "legend") {
|
|
1760
|
+
const adhoc = (k) => /^(swatch|dot|line)\.(.+)$/.exec(k);
|
|
1761
|
+
const entries = Object.entries(over2).filter(([k]) => k !== "style" && (look.styles.has(k) || adhoc(k)));
|
|
1762
|
+
const fs = num(p["item.size"], 8.5), font = p["item.font"] ?? "sans";
|
|
1763
|
+
const titled = (p.title ?? "none") !== "none";
|
|
1764
|
+
const layout = (W) => {
|
|
1765
|
+
const items = entries.map(([k, label]) => {
|
|
1766
|
+
const m = adhoc(k);
|
|
1767
|
+
if (m) {
|
|
1768
|
+
const c = m[2];
|
|
1769
|
+
if (m[1] === "line") return { style: k, kind: "line", label, x: 0, baseline: 0, sample: 28, props: { stroke: c, sw: "1.6", head: "none" } };
|
|
1770
|
+
return { style: k, kind: "shape", label, x: 0, baseline: 0, sample: 14, props: m[1] === "dot" ? { shape: "dot", fill: c, stroke: "none" } : { shape: "rect", fill: c, stroke: "none", radius: "2" } };
|
|
1771
|
+
}
|
|
1772
|
+
const st2 = look.styles.get(k);
|
|
1773
|
+
const sample = st2.kind === "line" ? 28 : st2.kind === "text" ? 16 : st2.props.shape === "diamond" ? 22 : 14;
|
|
1774
|
+
return { style: k, kind: st2.kind, label, x: 0, baseline: 0, sample };
|
|
1775
|
+
});
|
|
1776
|
+
const widths = items.map((it) => it.sample + 6 + textWidth(it.label, fs, font, 400, 0));
|
|
1777
|
+
const rows2 = [[]];
|
|
1778
|
+
let run = 0;
|
|
1779
|
+
widths.forEach((w, i2) => {
|
|
1780
|
+
const row = rows2[rows2.length - 1];
|
|
1781
|
+
if (row.length && run + 20 + w > W) {
|
|
1782
|
+
rows2.push([i2]);
|
|
1783
|
+
run = w;
|
|
1784
|
+
} else {
|
|
1785
|
+
run += (row.length ? 20 : 0) + w;
|
|
1786
|
+
row.push(i2);
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
const first2 = sh.y + (titled ? 40 : 20);
|
|
1790
|
+
rows2.forEach((row, r) => {
|
|
1791
|
+
const sum = row.reduce((a, i2) => a + widths[i2], 0);
|
|
1792
|
+
const gap = rows2.length === 1 && row.length > 1 ? Math.min(64, Math.max(20, (W - sum) / (row.length - 1))) : 24;
|
|
1793
|
+
let x = sh.x;
|
|
1794
|
+
for (const i2 of row) {
|
|
1795
|
+
items[i2].x = Math.round(x);
|
|
1796
|
+
items[i2].baseline = first2 + r * 20;
|
|
1797
|
+
x += widths[i2] + gap;
|
|
1798
|
+
}
|
|
1799
|
+
});
|
|
1800
|
+
sh.w = W;
|
|
1801
|
+
sh.h = (titled ? 40 : 20) + (rows2.length - 1) * 20 + 12;
|
|
1802
|
+
sh.legend = items;
|
|
1803
|
+
};
|
|
1804
|
+
if (size0) layout(sh.w);
|
|
1805
|
+
else legends.push(() => {
|
|
1806
|
+
const rights = [
|
|
1807
|
+
...shapes.filter((o) => o.shape !== "legend").map((o) => o.x + o.w),
|
|
1808
|
+
...texts.map((t) => t.x + t.w),
|
|
1809
|
+
...conns.flatMap((c) => [c.a, c.b].filter((e) => e.kind === "point").map((e) => e.pt.x))
|
|
1810
|
+
];
|
|
1811
|
+
layout(rights.length ? Math.max(200, Math.round((Math.max(...rights) - sh.x) / 4) * 4) : 920);
|
|
1812
|
+
});
|
|
1813
|
+
if (!entries.length) warn(st.line, 'this legend has no entries; add style="what it means" for each style, e.g. focal="The main service"');
|
|
1814
|
+
}
|
|
1815
|
+
if (!at) unplaced.push(sh);
|
|
1816
|
+
shapes.push(sh);
|
|
1817
|
+
}
|
|
1818
|
+
for (const l of legends) l();
|
|
1819
|
+
if (unplaced.length) {
|
|
1820
|
+
const placed = shapes.filter((s) => !unplaced.includes(s));
|
|
1821
|
+
let x = 40;
|
|
1822
|
+
const y = placed.length ? Math.max(...placed.map((s) => s.y + s.h)) + 40 : 40;
|
|
1823
|
+
for (const s of unplaced) {
|
|
1824
|
+
s.x = x;
|
|
1825
|
+
s.y = y;
|
|
1826
|
+
x += s.w + 40;
|
|
1827
|
+
warn(s.line, `${s.id} has no position ("at x,y"); it was dropped in a row at ${s.x},${s.y}`);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
const shapeById = /* @__PURE__ */ new Map();
|
|
1831
|
+
for (const s of shapes) shapeById.set(s.id, s);
|
|
1832
|
+
for (const t of texts) shapeById.set(t.id, { x: t.x - 4, y: t.y - 2, w: t.w + 8, h: t.h + 4 });
|
|
1833
|
+
const connById = new Map(conns.map((c) => [c.id, c]));
|
|
1834
|
+
const rowsById = new Map(shapes.filter((s) => s.rows).map((s) => [s.id, s.rows]));
|
|
1835
|
+
const tgt = (e) => {
|
|
1836
|
+
const S = shapeById.get(e.id);
|
|
1837
|
+
const r = e.row ? rowsById.get(e.id)?.find((q) => q.id === e.row) : void 0;
|
|
1838
|
+
return r ? { x: S.x, y: r.y, w: S.w, h: r.h } : S;
|
|
1839
|
+
};
|
|
1840
|
+
const sideKey = (e) => `${e.id}${e.row ? "." + e.row : ""}|${e.side}`;
|
|
1841
|
+
const done = /* @__PURE__ */ new Set();
|
|
1842
|
+
const bad = /* @__PURE__ */ new Set();
|
|
1843
|
+
for (const c of conns) for (const e of [c.a, c.b]) {
|
|
1844
|
+
if (e.kind !== "shape") continue;
|
|
1845
|
+
if (shapeById.has(e.id)) {
|
|
1846
|
+
if (e.row && !rowsById.get(e.id)?.some((r) => r.id === e.row)) {
|
|
1847
|
+
const have = (rowsById.get(e.id) ?? []).filter((r) => r.id).map((r) => r.id);
|
|
1848
|
+
err(c.line, `${e.raw}: "${e.id}" has no row called "${e.row}"${have.length ? `; its rows: ${have.join(", ")}` : " (only a table has rows; a side is top, bottom, left or right)"}`);
|
|
1849
|
+
bad.add(c);
|
|
1850
|
+
}
|
|
1851
|
+
continue;
|
|
1852
|
+
}
|
|
1853
|
+
if (connById.has(e.id)) {
|
|
1854
|
+
e.kind = "conn";
|
|
1855
|
+
if (e.side) {
|
|
1856
|
+
err(c.line, `${e.raw}: "${e.id}" is a line, so it has no sides; use ${e.id}@position`);
|
|
1857
|
+
bad.add(c);
|
|
1858
|
+
}
|
|
1859
|
+
if (e.v === void 0) e.v = 0.5;
|
|
1860
|
+
} else {
|
|
1861
|
+
err(c.line, `connector refers to "${e.id}", which does not exist`);
|
|
1862
|
+
bad.add(c);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
for (const c of conns) if (c.a.kind === "rel" && c.b.kind === "rel") {
|
|
1866
|
+
err(c.line, "only one end of a connector can be relative (+dx,+dy)");
|
|
1867
|
+
bad.add(c);
|
|
1868
|
+
}
|
|
1869
|
+
const taken = [];
|
|
1870
|
+
const resolvePass = (batch) => {
|
|
1871
|
+
const boxOf = (e) => {
|
|
1872
|
+
if (e.kind === "shape") return tgt(e);
|
|
1873
|
+
if (e.kind === "point") return { x: e.pt.x, y: e.pt.y, w: 0, h: 0 };
|
|
1874
|
+
if (e.kind === "conn") {
|
|
1875
|
+
e.pt = pointAlong(connById.get(e.id), e.v);
|
|
1876
|
+
return { x: e.pt.x, y: e.pt.y, w: 0, h: 0 };
|
|
1877
|
+
}
|
|
1878
|
+
return null;
|
|
1879
|
+
};
|
|
1880
|
+
for (const c of batch) {
|
|
1881
|
+
const ba = boxOf(c.a), bb = boxOf(c.b);
|
|
1882
|
+
const relSide = (r) => Math.abs(r.y) >= Math.abs(r.x) ? r.y >= 0 ? "bottom" : "top" : r.x >= 0 ? "right" : "left";
|
|
1883
|
+
const rowSide = (me, other, rel) => (other ? cx(other) >= cx(me) : rel.x >= 0) ? "right" : "left";
|
|
1884
|
+
if (c.a.kind === "shape" && !c.a.side) {
|
|
1885
|
+
c.a.side = c.a.row ? rowSide(ba, bb, c.b.rel ?? { x: 0, y: 0 }) : bb ? autoSides(ba, bb)[0] : relSide(c.b.rel);
|
|
1886
|
+
c.a.fanned = true;
|
|
1887
|
+
}
|
|
1888
|
+
if (c.b.kind === "shape" && !c.b.side) {
|
|
1889
|
+
const back = c.a.rel ? { x: -c.a.rel.x, y: -c.a.rel.y } : { x: 0, y: 0 };
|
|
1890
|
+
c.b.side = c.b.row ? rowSide(bb, ba, back) : ba ? autoSides(ba, bb)[1] : relSide(back);
|
|
1891
|
+
c.b.fanned = true;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1895
|
+
for (const c of batch) for (const [e, o] of [[c.a, c.b], [c.b, c.a]]) {
|
|
1896
|
+
if (e.kind !== "shape" || e.v !== void 0) continue;
|
|
1897
|
+
const k = sideKey(e);
|
|
1898
|
+
if (!groups.has(k)) groups.set(k, []);
|
|
1899
|
+
groups.get(k).push({ c, e, o });
|
|
1900
|
+
}
|
|
1901
|
+
const frac = /* @__PURE__ */ new Map();
|
|
1902
|
+
const single = /* @__PURE__ */ new Set();
|
|
1903
|
+
for (const [k, g] of groups) {
|
|
1904
|
+
const horiz = k.endsWith("top") || k.endsWith("bottom");
|
|
1905
|
+
const ref = (o) => {
|
|
1906
|
+
const b = boxOf(o);
|
|
1907
|
+
return b ? horiz ? cx(b) : cy(b) : 0;
|
|
1908
|
+
};
|
|
1909
|
+
if (g.length === 1) {
|
|
1910
|
+
frac.set(g[0].e, 0.5);
|
|
1911
|
+
single.add(g[0].e);
|
|
1912
|
+
continue;
|
|
1913
|
+
}
|
|
1914
|
+
const order = g.map((m, idx) => ({ m, idx, r: ref(m.o) })).sort((p, q) => p.r - q.r || p.idx - q.idx);
|
|
1915
|
+
order.forEach((o, n) => frac.set(o.m.e, (n + 1) / (g.length + 1)));
|
|
1916
|
+
}
|
|
1917
|
+
for (const c of batch) {
|
|
1918
|
+
for (const e of [c.a, c.b]) {
|
|
1919
|
+
if (e.kind === "shape") {
|
|
1920
|
+
const S = tgt(e);
|
|
1921
|
+
e.pt = sidePoint(S, e.side, e.v, frac.get(e) ?? 0.5);
|
|
1922
|
+
e.dir = DIRS[e.side];
|
|
1923
|
+
if (e.v !== void 0 && e.v > 1) {
|
|
1924
|
+
const horiz = e.side === "top" || e.side === "bottom";
|
|
1925
|
+
const lo = horiz ? S.x : S.y, hi = horiz ? S.x + S.w : S.y + S.h;
|
|
1926
|
+
if (e.v < lo || e.v > hi) warn(c.line, `${e.raw}: ${e.v} is outside the ${e.side} side of ${e.id}, which runs from ${lo} to ${hi}; the end was moved to the nearest point`);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
const a = c.a, b = c.b;
|
|
1931
|
+
const opposing = a.dir && b.dir && a.dir.x === -b.dir.x && a.dir.y === -b.dir.y;
|
|
1932
|
+
if (a.kind === "shape" && b.kind === "shape" && opposing) {
|
|
1933
|
+
const A = tgt(a), B = tgt(b);
|
|
1934
|
+
const horiz = a.side === "top" || a.side === "bottom";
|
|
1935
|
+
const lo = horiz ? Math.max(A.x, B.x) : Math.max(A.y, B.y);
|
|
1936
|
+
const hi = horiz ? Math.min(A.x + A.w, B.x + B.w) : Math.min(A.y + A.h, B.y + B.h);
|
|
1937
|
+
if (hi > lo) {
|
|
1938
|
+
let pos;
|
|
1939
|
+
if (single.has(a) && single.has(b)) {
|
|
1940
|
+
const ca = horiz ? cx(A) : cy(A), cb = horiz ? cx(B) : cy(B);
|
|
1941
|
+
const small = (horiz ? A.w <= B.w : A.h <= B.h) ? ca : cb, other = small === ca ? cb : ca;
|
|
1942
|
+
pos = within(small, lo, hi) ? small : within(other, lo, hi) ? other : (lo + hi) / 2;
|
|
1943
|
+
} else if (!single.has(a) && !single.has(b) && a.v === void 0 && b.v === void 0) {
|
|
1944
|
+
const ga = groups.get(sideKey(a)), gb = groups.get(sideKey(b));
|
|
1945
|
+
const same = ga.length === gb.length && ga.every((m) => gb.some((n) => n.c === m.c));
|
|
1946
|
+
if (same) pos = lo + (hi - lo) * frac.get(a);
|
|
1947
|
+
} else if (single.has(a) && b.v !== void 0) pos = horiz ? b.pt.x : b.pt.y;
|
|
1948
|
+
else if (single.has(b) && a.v !== void 0) pos = horiz ? a.pt.x : a.pt.y;
|
|
1949
|
+
if (pos !== void 0 && within(pos, lo, hi)) {
|
|
1950
|
+
a.pt = sidePoint(A, a.side, Math.max(pos, 1.0001), 0.5);
|
|
1951
|
+
b.pt = sidePoint(B, b.side, Math.max(pos, 1.0001), 0.5);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
for (const [e, o] of [[a, b], [b, a]]) {
|
|
1956
|
+
if (e.kind !== "shape" || !single.has(e) || o.kind !== "point" && o.kind !== "conn") continue;
|
|
1957
|
+
const S = tgt(e);
|
|
1958
|
+
const horiz = e.side === "top" || e.side === "bottom";
|
|
1959
|
+
const pos = horiz ? o.pt.x : o.pt.y;
|
|
1960
|
+
if (within(pos, (horiz ? S.x : S.y) + 2, (horiz ? S.x + S.w : S.y + S.h) - 2)) e.pt = sidePoint(S, e.side, Math.max(pos, 1.0001), 0.5);
|
|
1961
|
+
}
|
|
1962
|
+
if (a.kind === "rel") a.pt = { x: b.pt.x + a.rel.x, y: b.pt.y + a.rel.y };
|
|
1963
|
+
if (b.kind === "rel") b.pt = { x: a.pt.x + b.rel.x, y: a.pt.y + b.rel.y };
|
|
1964
|
+
let via = [];
|
|
1965
|
+
if (c.p.via) {
|
|
1966
|
+
via = c.p.via.split(";").map((s) => {
|
|
1967
|
+
const [x, y] = s.split(",").map(Number);
|
|
1968
|
+
return { x, y };
|
|
1969
|
+
});
|
|
1970
|
+
if (via.some((v) => isNaN(v.x) || isNaN(v.y))) {
|
|
1971
|
+
err(c.line, "via must look like via=x,y or via=x,y;x,y");
|
|
1972
|
+
via = [];
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (a.pt.x === b.pt.x && a.pt.y === b.pt.y) warn(c.line, `${c.a.raw} and ${c.b.raw} meet at the same point (${a.pt.x},${a.pt.y}), so this line has no length and is not drawn; attach it to other sides`);
|
|
1976
|
+
c.pts = c.curve ? curvePts(a.pt, a.dir, b.pt, b.dir, via, num(c.p.bend, NaN)) : route(c, via);
|
|
1977
|
+
if (c.ortho && !via.length && !c.ushape) {
|
|
1978
|
+
const strictlyIn = (o, p) => p.x > o.x + 1 && p.x < o.x + o.w - 1 && p.y > o.y + 1 && p.y < o.y + o.h - 1;
|
|
1979
|
+
const obs = shapes.filter((o) => !o.back && o.shape !== "legend" && !(o.poly && o.p.open === "1") && Math.min(o.w, o.h) > 12 && !strictlyIn(o, a.pt) && !strictlyIn(o, b.pt));
|
|
1980
|
+
for (const o of shapes) {
|
|
1981
|
+
const cb = o.id !== c.a.id && o.id !== c.b.id ? captionBox(o) : null;
|
|
1982
|
+
if (cb) obs.push({ x: cb.x - 4, y: cb.y - 2, w: cb.w + 8, h: cb.h + 4 });
|
|
1983
|
+
}
|
|
1984
|
+
if (crosses(c.pts, obs)) {
|
|
1985
|
+
const alt = routeAround(a.pt, a.dir, b.pt, b.dir, obs, taken);
|
|
1986
|
+
if (alt) c.pts = alt;
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
if (c.ortho) for (let i = 0; i < c.pts.length - 1; i++) taken.push([c.pts[i], c.pts[i + 1]]);
|
|
1990
|
+
c.label = makeLabel(c, shapes.filter((o) => !o.back && o.shape !== "legend"));
|
|
1991
|
+
done.add(c);
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
const good = conns.filter((c) => !bad.has(c));
|
|
1995
|
+
const refsConn = (c) => c.a.kind === "conn" || c.b.kind === "conn";
|
|
1996
|
+
resolvePass(good.filter((c) => !refsConn(c)));
|
|
1997
|
+
const second = good.filter(refsConn);
|
|
1998
|
+
for (const c of second) for (const e of [c.a, c.b]) {
|
|
1999
|
+
if (e.kind === "conn" && !done.has(connById.get(e.id))) {
|
|
2000
|
+
err(c.line, `"${e.id}" is itself attached to a line; attach to a line that starts at a shape or a point`);
|
|
2001
|
+
bad.add(c);
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
resolvePass(second.filter((c) => !bad.has(c)));
|
|
2005
|
+
const finalConns = conns.filter((c) => done.has(c));
|
|
2006
|
+
const ext = extent([...shapes, ...shapes.map(captionBox).filter((b) => !!b)], texts, finalConns);
|
|
2007
|
+
return { file, ...ext, look, canvasLine, canvasSize, baseCanvas, shapes, texts, conns: finalConns, issues };
|
|
2008
|
+
}
|
|
2009
|
+
var ICON_CAPTION_GAP = 6;
|
|
2010
|
+
function captionBox(s) {
|
|
2011
|
+
if (s.shape !== "icon" || !s.text && !s.p.sub) return null;
|
|
2012
|
+
const p = s.p, size = +(p["title.size"] ?? 11) || 11, sub = +(p["sub.size"] ?? 9) || 9;
|
|
2013
|
+
const lines = s.text ? s.text.split("\n") : [], subs = p.sub ? p.sub.split("\n") : [];
|
|
2014
|
+
const w = Math.max(0, ...lines.map((l) => textWidth(l, size, p["title.font"] ?? "sans", +(p["title.weight"] ?? 600) || 600, 0)), ...subs.map((l) => textWidth(l, sub, p["sub.font"] ?? "mono", 400, 0)));
|
|
2015
|
+
const h = lines.length * Math.round(size * 1.17) + (subs.length ? 2 + subs.length * Math.round(sub * 1.3) : 0);
|
|
2016
|
+
return { x: s.x + s.w / 2 - w / 2, y: s.y + s.h + ICON_CAPTION_GAP, w, h };
|
|
2017
|
+
}
|
|
2018
|
+
var MARGIN = 40;
|
|
2019
|
+
function extent(shapes, texts, conns) {
|
|
2020
|
+
const boxes = [...shapes, ...texts, ...conns.flatMap((c) => [...c.pts.map((p) => ({ x: p.x, y: p.y, w: 0, h: 0 })), ...c.label ? [c.label] : []])];
|
|
2021
|
+
if (!boxes.length) return { x: 0, y: 0, w: 400, h: 240 };
|
|
2022
|
+
const x0 = Math.min(...boxes.map((b) => b.x)), y0 = Math.min(...boxes.map((b) => b.y));
|
|
2023
|
+
const x1 = Math.max(...boxes.map((b) => b.x + b.w)), y1 = Math.max(...boxes.map((b) => b.y + b.h));
|
|
2024
|
+
const x = Math.floor((x0 - MARGIN) / 4) * 4, y = Math.floor((y0 - MARGIN) / 4) * 4;
|
|
2025
|
+
return { x, y, w: Math.ceil((x1 + MARGIN) / 4) * 4 - x, h: Math.ceil((y1 + MARGIN) / 4) * 4 - y };
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
// src/iconfiles.ts
|
|
2029
|
+
var MAX_ICON_BYTES = 3e5;
|
|
2030
|
+
var MAX_ICON_FILES = 3e3;
|
|
2031
|
+
var URI = /^data:image\/svg\+xml;base64,[A-Za-z0-9+/]+=*$/;
|
|
2032
|
+
var isIconUri = (v) => typeof v === "string" && v.length < MAX_ICON_BYTES * 1.4 && URI.test(v);
|
|
2033
|
+
function iconName(file) {
|
|
2034
|
+
return file.replace(/\.svg$/i, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^\d+-icon-service-/, "").replace(/^-+|-+$/g, "");
|
|
2035
|
+
}
|
|
2036
|
+
function svgDataUri(bytes) {
|
|
2037
|
+
if (bytes.length === 0 || bytes.length > MAX_ICON_BYTES) return null;
|
|
2038
|
+
const head = new TextDecoder().decode(bytes.subarray(0, 2e3));
|
|
2039
|
+
if (!/<svg[\s>]/i.test(head)) return null;
|
|
2040
|
+
let bin = "";
|
|
2041
|
+
for (let i = 0; i < bytes.length; i += 32768) bin += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
2042
|
+
return "data:image/svg+xml;base64," + btoa(bin);
|
|
2043
|
+
}
|
|
2044
|
+
function withIconImages(look, files, uris = {}) {
|
|
2045
|
+
const images = new Map(look.images);
|
|
2046
|
+
for (const [k, v] of Object.entries(uris)) if (images.size < MAX_ICON_FILES && /^[a-z0-9-]{1,80}$/.test(k) && isIconUri(v)) images.set(k, v);
|
|
2047
|
+
for (const f of [...files].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2048
|
+
const name2 = iconName(f.name), uri = name2 && name2.length <= 80 ? svgDataUri(f.bytes) : null;
|
|
2049
|
+
if (uri && images.size < MAX_ICON_FILES && !images.has(name2)) images.set(name2, uri);
|
|
2050
|
+
}
|
|
2051
|
+
return { ...look, images };
|
|
2052
|
+
}
|
|
2053
|
+
function usedIconImages(look, names) {
|
|
2054
|
+
const out = {};
|
|
2055
|
+
for (const n of names) {
|
|
2056
|
+
const u = look.images.get(n);
|
|
2057
|
+
if (u) out[n] = u;
|
|
2058
|
+
}
|
|
2059
|
+
return out;
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
// src/node.ts
|
|
2063
|
+
import { lstatSync, realpathSync } from "node:fs";
|
|
2064
|
+
import { isAbsolute, relative, sep } from "node:path";
|
|
2065
|
+
function lookFolder(lookFile, d) {
|
|
2066
|
+
if (isAbsolute(d)) return null;
|
|
2067
|
+
try {
|
|
2068
|
+
const home = realpathSync(dirname(lookFile)), dir = realpathSync(resolve(home, d));
|
|
2069
|
+
const rel = relative(home, dir);
|
|
2070
|
+
return rel.startsWith("..") || isAbsolute(rel) || !lstatSync(dir).isDirectory() ? null : dir;
|
|
2071
|
+
} catch {
|
|
2072
|
+
return null;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
function plainFiles(dir, ext, maxBytes, maxFiles) {
|
|
2076
|
+
const out = [];
|
|
2077
|
+
for (const f of readdirSync(dir).filter((n) => ext.test(n)).sort()) {
|
|
2078
|
+
if (out.length >= maxFiles) break;
|
|
2079
|
+
const full = dir + sep + f;
|
|
2080
|
+
try {
|
|
2081
|
+
const st = lstatSync(full);
|
|
2082
|
+
if (st.isFile() && !st.isSymbolicLink() && st.size <= maxBytes) out.push(full);
|
|
2083
|
+
} catch {
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
return out;
|
|
2087
|
+
}
|
|
2088
|
+
function iconFiles(lookFile, look) {
|
|
2089
|
+
const out = [];
|
|
2090
|
+
for (const d of look.iconDirs) {
|
|
2091
|
+
const dir = lookFolder(lookFile, d);
|
|
2092
|
+
if (!dir) {
|
|
2093
|
+
look.issues.push({ line: 0, level: "warn", msg: `icon folder not used: ${d} (icondir must be a folder inside the folder that holds the look file)` });
|
|
2094
|
+
continue;
|
|
2095
|
+
}
|
|
2096
|
+
for (const full of plainFiles(dir, /\.svg$/i, MAX_ICON_BYTES, MAX_ICON_FILES - out.length)) out.push({ name: full.slice(dir.length + 1), bytes: new Uint8Array(readFileSync(full)) });
|
|
2097
|
+
}
|
|
2098
|
+
return out;
|
|
2099
|
+
}
|
|
2100
|
+
var withIcons = (lookFile, look) => look.iconDirs.length ? withIconImages(look, iconFiles(lookFile, look)) : look;
|
|
2101
|
+
function loadLook(path) {
|
|
2102
|
+
try {
|
|
2103
|
+
return withIcons(path, parseLook(readFileSync(path, "utf8"), path));
|
|
2104
|
+
} catch {
|
|
2105
|
+
const look = emptyLook();
|
|
2106
|
+
look.issues.push({ line: 0, level: "error", msg: `look file not found: ${path}` });
|
|
2107
|
+
return look;
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
var isFont = (f) => /\.(ttf|otf)$/i.test(f);
|
|
2111
|
+
var listFonts = (dir) => existsSync(dir) ? readdirSync(dir).filter(isFont).map((f) => resolve(dir, f)) : [];
|
|
2112
|
+
var bundledFontDir = resolve(dirname(fileURLToPath(import.meta.url)), "..", "fonts");
|
|
2113
|
+
var bundledFonts = () => listFonts(bundledFontDir);
|
|
2114
|
+
function lookFonts(lookFile, look) {
|
|
2115
|
+
const files = lookFile ? look.fontDirs.flatMap((d) => {
|
|
2116
|
+
const dir = lookFolder(lookFile, d);
|
|
2117
|
+
return dir ? plainFiles(dir, /\.(ttf|otf)$/i, 2e7, 200) : [];
|
|
2118
|
+
}) : [];
|
|
2119
|
+
const have = /* @__PURE__ */ new Set();
|
|
2120
|
+
for (const f of [...bundledFonts(), ...files]) {
|
|
2121
|
+
const m = fontMeta(new Uint8Array(readFileSync(f)));
|
|
2122
|
+
if (m) have.add(m.family.toLowerCase());
|
|
2123
|
+
}
|
|
2124
|
+
const generic = /* @__PURE__ */ new Set(["sans-serif", "serif", "monospace", "helvetica", "system-ui"]);
|
|
2125
|
+
const missing = [...new Set(look.fonts.values())].filter((fam2) => !have.has(fam2.toLowerCase()) && !generic.has(fam2.toLowerCase()));
|
|
2126
|
+
return { files, missing };
|
|
2127
|
+
}
|
|
2128
|
+
function readLook(file, p) {
|
|
2129
|
+
if (!p) return { text: null, refused: false };
|
|
2130
|
+
if (!p.toLowerCase().endsWith(".look")) return { text: null, refused: true };
|
|
2131
|
+
try {
|
|
2132
|
+
return { text: readFileSync(resolve(dirname(file), p), "utf8"), refused: false };
|
|
2133
|
+
} catch {
|
|
2134
|
+
return { text: null, refused: false };
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
function loadScene(file) {
|
|
2138
|
+
let src = "";
|
|
2139
|
+
try {
|
|
2140
|
+
src = readFileSync(file, "utf8");
|
|
2141
|
+
} catch {
|
|
2142
|
+
const sc2 = buildScene("", null, file);
|
|
2143
|
+
sc2.issues.unshift({ line: 0, level: "error", msg: `cannot read ${file}` });
|
|
2144
|
+
return sc2;
|
|
2145
|
+
}
|
|
2146
|
+
const p = lookPath(src);
|
|
2147
|
+
const r = readLook(file, p);
|
|
2148
|
+
const sc = buildScene(src, r.text === null ? null : withIcons(resolve(dirname(file), p), parseLook(r.text, p)), file);
|
|
2149
|
+
const fonts = lookFonts(r.text === null ? void 0 : resolve(dirname(file), p), sc.look);
|
|
2150
|
+
sc.fontFiles = fonts.files;
|
|
2151
|
+
for (const fam2 of fonts.missing) {
|
|
2152
|
+
sc.issues.push({ line: 1, level: "warn", msg: `the look names the font "${fam2}", but no TTF or OTF file for it was found, so text will be drawn in a fallback font; put its files in a folder next to the look and add fontdir "./fonts" to the look` });
|
|
2153
|
+
}
|
|
2154
|
+
if (r.refused) {
|
|
2155
|
+
for (const i of sc.issues) if (i.msg.startsWith("look file not found")) i.msg = `the look path must end in .look; "${p}" was not read`;
|
|
2156
|
+
}
|
|
2157
|
+
return sc;
|
|
2158
|
+
}
|
|
2159
|
+
function readSources(file, sc) {
|
|
2160
|
+
const diagram = readFileSync(file, "utf8");
|
|
2161
|
+
const p = lookPath(diagram);
|
|
2162
|
+
const { text } = readLook(file, p);
|
|
2163
|
+
const clean = text !== null && parseLook(text, p).issues.every((i) => i.level !== "error");
|
|
2164
|
+
const icons = sc ? usedIconImages(sc.look, sc.shapes.map((s) => s.p.icon).filter(Boolean)) : {};
|
|
2165
|
+
return { diagram, look: clean ? text : null, ...Object.keys(icons).length ? { icons } : {} };
|
|
2166
|
+
}
|
|
2167
|
+
function lookFileOf(diagramFile) {
|
|
2168
|
+
try {
|
|
2169
|
+
const p = lookPath(readFileSync(diagramFile, "utf8"));
|
|
2170
|
+
return p && p.toLowerCase().endsWith(".look") ? resolve(dirname(diagramFile), p) : void 0;
|
|
2171
|
+
} catch {
|
|
2172
|
+
return void 0;
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
// src/embed.ts
|
|
2177
|
+
var b64 = (s) => {
|
|
2178
|
+
const b = new TextEncoder().encode(s);
|
|
2179
|
+
let bin = "";
|
|
2180
|
+
for (let i = 0; i < b.length; i += 32768) bin += String.fromCharCode(...b.subarray(i, i + 32768));
|
|
2181
|
+
return btoa(bin);
|
|
2182
|
+
};
|
|
2183
|
+
function embedSvg(svg, p) {
|
|
2184
|
+
return svg.replace(/(<svg[^>]*>)/, `$1
|
|
2185
|
+
<metadata id="fastdraw-source">${b64(JSON.stringify(p))}</metadata>`);
|
|
2186
|
+
}
|
|
2187
|
+
var KEY = "fastdraw-source";
|
|
2188
|
+
var table;
|
|
2189
|
+
function crc32(buf) {
|
|
2190
|
+
if (!table) {
|
|
2191
|
+
table = new Uint32Array(256);
|
|
2192
|
+
for (let n = 0; n < 256; n++) {
|
|
2193
|
+
let c2 = n;
|
|
2194
|
+
for (let k = 0; k < 8; k++) c2 = c2 & 1 ? 3988292384 ^ c2 >>> 1 : c2 >>> 1;
|
|
2195
|
+
table[n] = c2 >>> 0;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
let c = 4294967295;
|
|
2199
|
+
for (let i = 0; i < buf.length; i++) c = table[(c ^ buf[i]) & 255] ^ c >>> 8;
|
|
2200
|
+
return (c ^ 4294967295) >>> 0;
|
|
2201
|
+
}
|
|
2202
|
+
var isPng = (b) => b.length > 8 && b[0] === 137 && b[1] === 80 && b[2] === 78 && b[3] === 71;
|
|
2203
|
+
function embedPng(png, p) {
|
|
2204
|
+
if (!isPng(png)) return png;
|
|
2205
|
+
const text = new TextEncoder().encode(`${KEY}\0${b64(JSON.stringify(p))}`);
|
|
2206
|
+
const chunk = new Uint8Array(12 + text.length), dv = new DataView(chunk.buffer);
|
|
2207
|
+
dv.setUint32(0, text.length);
|
|
2208
|
+
chunk.set([116, 69, 88, 116], 4);
|
|
2209
|
+
chunk.set(text, 8);
|
|
2210
|
+
dv.setUint32(8 + text.length, crc32(chunk.subarray(4, 8 + text.length)));
|
|
2211
|
+
const iend = png.length - 12;
|
|
2212
|
+
const out = new Uint8Array(png.length + chunk.length);
|
|
2213
|
+
out.set(png.subarray(0, iend), 0);
|
|
2214
|
+
out.set(chunk, iend);
|
|
2215
|
+
out.set(png.subarray(iend), iend + chunk.length);
|
|
2216
|
+
return out;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
// src/chart.ts
|
|
2220
|
+
var PALETTE = ["accent", "link", "ink/0.55", "soft", "accent/0.5", "link/0.5"];
|
|
2221
|
+
function niceStep(span, max = 6) {
|
|
2222
|
+
if (!(span > 0)) return 1;
|
|
2223
|
+
const raw = span / max, pow = Math.pow(10, Math.floor(Math.log10(raw)));
|
|
2224
|
+
for (const m of [1, 2, 2.5, 5, 10]) if (m * pow >= raw) return m * pow;
|
|
2225
|
+
return 10 * pow;
|
|
2226
|
+
}
|
|
2227
|
+
var safeStep = (v, span) => {
|
|
2228
|
+
const s = Number(v);
|
|
2229
|
+
return v !== void 0 && Number.isFinite(s) && s > 0 && span / s <= 200 ? s : niceStep(span);
|
|
2230
|
+
};
|
|
2231
|
+
function ticks(lo, hi, step) {
|
|
2232
|
+
const k0 = Math.ceil(lo / step - 1e-9), k1 = Math.floor(hi / step + 1e-9), out = [];
|
|
2233
|
+
if (!Number.isFinite(k0) || !Number.isFinite(k1)) return out;
|
|
2234
|
+
for (let k = k0; k <= k1 && out.length <= 200; k++) out.push(k * step);
|
|
2235
|
+
return out;
|
|
2236
|
+
}
|
|
2237
|
+
var fmt = (v) => String(Math.round(v * 1e3) / 1e3);
|
|
2238
|
+
var range = (v) => {
|
|
2239
|
+
const m = /^(-?[\d.]+)\.\.(-?[\d.]+)$/.exec(v ?? "");
|
|
2240
|
+
return m && Math.abs(+m[1]) < 1e15 && Math.abs(+m[2]) < 1e15 && +m[2] > +m[1] ? [+m[1], +m[2]] : null;
|
|
2241
|
+
};
|
|
2242
|
+
function drawChart(look, s) {
|
|
2243
|
+
const p = s.p, rows = (s.rows ?? []).filter((r) => r.id && r.vals.length), out = [];
|
|
2244
|
+
const { x, y, w, h } = s;
|
|
2245
|
+
const pairs = (v) => v === "_" ? [] : v.split(",").map(Number);
|
|
2246
|
+
const xr = range(p.x), cats = !xr && p.x ? p.x.split(",").map((c) => c.trim()) : [];
|
|
2247
|
+
const n = xr ? 0 : Math.max(cats.length, ...rows.map((r) => r.vals.length), 1);
|
|
2248
|
+
const finite = (v) => Number.isFinite(v);
|
|
2249
|
+
const ys = rows.flatMap((r) => r.vals.flatMap((v) => r.id === "bars" || r.id === "dots" && !xr ? pairs(v) : pairs(v).slice(-1)));
|
|
2250
|
+
const stacked = p.stack === "1";
|
|
2251
|
+
if (stacked) for (let i = 0; i < n; i++) ys.push(rows.filter((r) => r.id === "bars").reduce((a, r) => a + (+r.vals[i] || 0), 0));
|
|
2252
|
+
for (let i = ys.length - 1; i >= 0; i--) if (!finite(ys[i]) || Math.abs(ys[i]) >= 1e15) ys.splice(i, 1);
|
|
2253
|
+
const yr = range(p.y);
|
|
2254
|
+
let y0 = yr ? yr[0] : Math.min(0, ...ys), y1 = yr ? yr[1] : Math.max(0, ...ys);
|
|
2255
|
+
if (!(y1 > y0)) y1 = y0 + 1;
|
|
2256
|
+
const step = safeStep(p.step, y1 - y0);
|
|
2257
|
+
if (!yr) {
|
|
2258
|
+
y0 = Math.floor(y0 / step) * step;
|
|
2259
|
+
y1 = Math.ceil(y1 / step) * step;
|
|
2260
|
+
if (y1 === y0) y1 = y0 + step;
|
|
2261
|
+
}
|
|
2262
|
+
const Y = (v) => r2(y + h - (v - y0) / (y1 - y0) * h);
|
|
2263
|
+
const bw = n ? w / n : 0;
|
|
2264
|
+
const X = (i) => r2(x + bw * (i + 0.5));
|
|
2265
|
+
const XV = (v) => xr ? r2(x + (v - xr[0]) / (xr[1] - xr[0]) * w) : 0;
|
|
2266
|
+
const base = Y(Math.min(Math.max(0, y0), y1));
|
|
2267
|
+
const tick = textAttrs(look, p, "tick.", { font: "mono", size: 9, weight: 400, color: "muted" });
|
|
2268
|
+
const axis = col(look, p.stroke ?? "ink/0.5"), grid = col(look, p["grid.color"] ?? "ink/0.08"), sw = num2(p.sw, 1);
|
|
2269
|
+
const unit = p.unit ?? "", pre = p.prefix ?? "";
|
|
2270
|
+
if (p.fill && p.fill !== "none") out.push(`<rect x="${x}" y="${y}" width="${w}" height="${h}" fill="${col(look, p.fill)}"/>`);
|
|
2271
|
+
for (const v of ticks(y0, y1, step)) {
|
|
2272
|
+
const gy = Y(v);
|
|
2273
|
+
if (p.grid !== "0" && p.grid !== "x" && Math.abs(gy - (y + h)) > 0.5) out.push(`<line x1="${x}" y1="${gy}" x2="${x + w}" y2="${gy}" stroke="${grid}" stroke-width="1"/>`);
|
|
2274
|
+
if (p.yaxis !== "0") out.push(`<text x="${x - 8}" y="${r2(gy + tick.size * 0.35)}" text-anchor="end" ${tick.a}>${esc(pre + fmt(v) + unit)}</text>`);
|
|
2275
|
+
}
|
|
2276
|
+
if (xr) {
|
|
2277
|
+
const xs = safeStep(p.xstep, xr[1] - xr[0]);
|
|
2278
|
+
for (const v of ticks(xr[0], xr[1], xs)) {
|
|
2279
|
+
if ((p.grid === "both" || p.grid === "x") && v > xr[0]) out.push(`<line x1="${XV(v)}" y1="${y}" x2="${XV(v)}" y2="${y + h}" stroke="${grid}" stroke-width="1"/>`);
|
|
2280
|
+
out.push(`<text x="${XV(v)}" y="${y + h + 8 + tick.size}" text-anchor="middle" ${tick.a}>${esc(fmt(v) + (p.xunit ?? ""))}</text>`);
|
|
2281
|
+
}
|
|
2282
|
+
} else cats.forEach((c, i) => {
|
|
2283
|
+
if (p.grid === "x" && i > 0) out.push(`<line x1="${r2(x + bw * i)}" y1="${y}" x2="${r2(x + bw * i)}" y2="${y + h}" stroke="${grid}" stroke-width="1"/>`);
|
|
2284
|
+
out.push(`<text x="${X(i)}" y="${y + h + 8 + tick.size}" text-anchor="middle" ${tick.a}>${esc(c)}</text>`);
|
|
2285
|
+
});
|
|
2286
|
+
const lab = textAttrs(look, p, "value.", { font: "mono", size: 9, weight: 400, color: "ink" });
|
|
2287
|
+
const labels = p.labels === "1";
|
|
2288
|
+
const value = (cx2, cy2, v, plus = false) => labels && out.push(`<text x="${cx2}" y="${r2(cy2)}" text-anchor="middle" ${lab.a}>${esc((plus ? "+" : "") + pre + fmt(v) + unit)}</text>`);
|
|
2289
|
+
const bars = rows.filter((r) => r.id === "bars");
|
|
2290
|
+
const colour = (r, k) => r.p[k] ?? r.p.fill ?? r.p.stroke ?? PALETTE[rows.indexOf(r) % PALETTE.length];
|
|
2291
|
+
const group = bw * num2(p["bar.width"], 0.64), each = stacked || !bars.length ? group : group / bars.length;
|
|
2292
|
+
const tops = [];
|
|
2293
|
+
bars.forEach((r, k) => {
|
|
2294
|
+
const rad = num2(p["bar.radius"], 2);
|
|
2295
|
+
const outline2 = r.p.stroke && r.p.fill ? ` stroke="${col(look, r.p.stroke)}" stroke-width="${num2(r.p.sw, 1)}"` : "";
|
|
2296
|
+
r.vals.forEach((raw, i) => {
|
|
2297
|
+
const q = pairs(raw);
|
|
2298
|
+
if (!q.length) return;
|
|
2299
|
+
let lo = q.length === 2 ? q[0] : 0, hi = q.length === 2 ? q[1] : q[0];
|
|
2300
|
+
if (stacked && q.length === 1) {
|
|
2301
|
+
lo = tops[i] ?? 0;
|
|
2302
|
+
hi = lo + q[0];
|
|
2303
|
+
tops[i] = hi;
|
|
2304
|
+
}
|
|
2305
|
+
const top = Math.min(Y(lo), Y(hi)), bh = Math.abs(Y(lo) - Y(hi));
|
|
2306
|
+
const bx = r2(X(i) - group / 2 + (stacked ? 0 : k * each) + (each > 6 ? 1 : 0)), ww = r2(each - (each > 6 ? 2 : 0));
|
|
2307
|
+
out.push(`<rect x="${bx}" y="${top}" width="${ww}" height="${r2(Math.max(bh, 0.5))}"${rad && bh > rad * 2 && !stacked ? ` rx="${rad}"` : ""} fill="${col(look, r.p[`fill.${i + 1}`] ?? colour(r, "fill"))}"${outline2}/>`);
|
|
2308
|
+
value(r2(bx + ww / 2), hi >= lo ? top - 4 : top + bh + lab.size + 2, q.length === 2 ? hi - lo : q[0], q.length === 2 && lo !== 0 && hi > lo);
|
|
2309
|
+
});
|
|
2310
|
+
});
|
|
2311
|
+
for (const r of rows) {
|
|
2312
|
+
if (r.id === "bars") continue;
|
|
2313
|
+
const stroke = col(look, colour(r, "stroke")), lw = num2(r.p.sw, 2);
|
|
2314
|
+
const pts = r.vals.map((raw, i) => ({ raw, i })).filter((e) => e.raw !== "_").map(({ raw, i }) => {
|
|
2315
|
+
const q = pairs(raw);
|
|
2316
|
+
return q.length >= 2 && xr ? { x: XV(q[0]), y: Y(q[1]), v: q[1], r: q[2] ?? 0, i } : { x: X(i), y: Y(q[0]), v: q[0], r: q[1] ?? 0, i };
|
|
2317
|
+
});
|
|
2318
|
+
if (!pts.length) continue;
|
|
2319
|
+
const d = pts.map((q) => `${q.x},${q.y}`).join(" ");
|
|
2320
|
+
if (r.id === "area") out.push(`<polygon points="${pts[0].x},${base} ${d} ${pts[pts.length - 1].x},${base}" fill="${col(look, r.p.fill ?? colour(r, "stroke") + (/\/[\d.]+$/.test(colour(r, "stroke")) ? "" : "/0.1"))}"/>`);
|
|
2321
|
+
if (r.id !== "dots") out.push(`<polyline points="${d}" fill="none" stroke="${stroke}" stroke-width="${lw}" stroke-linejoin="round" stroke-linecap="round"${r.p.dash ? ` stroke-dasharray="${esc(r.p.dash)}"` : ""}/>`);
|
|
2322
|
+
if (r.id === "dots" || r.p.dots === "1") for (const q of pts) out.push(`<circle cx="${q.x}" cy="${q.y}" r="${r.id === "dots" ? num2(r.p.r, q.r || 4) : 3}" fill="${r.id === "dots" ? col(look, r.p[`fill.${q.i + 1}`] ?? r.p.fill ?? colour(r, "stroke")) : col(look, look.canvas.paper ?? "paper")}" stroke="${r.id === "dots" && !(r.p.fill && r.p.stroke) ? "none" : stroke}" stroke-width="${r.id === "dots" ? num2(r.p.sw, 1.2) : lw}"${r.id === "dots" && r.p.opacity ? ` fill-opacity="${num2(r.p.opacity, 1)}"` : ""}/>`);
|
|
2323
|
+
for (const q of pts) value(q.x, q.y - 8, q.v);
|
|
2324
|
+
}
|
|
2325
|
+
out.push(`<path d="M ${x},${y} L ${x},${y + h} L ${x + w},${y + h}" fill="none" stroke="${axis}" stroke-width="${sw}"/>`);
|
|
2326
|
+
if (y0 < 0 && y1 > 0 && p.zero !== "0") out.push(`<line x1="${x}" y1="${base}" x2="${x + w}" y2="${base}" stroke="${axis}" stroke-width="${sw}"/>`);
|
|
2327
|
+
const ttl = textAttrs(look, p, "axis.", { font: "sans", size: 10, weight: 400, color: "muted" });
|
|
2328
|
+
if (p.xtitle) out.push(`<text x="${x + w / 2}" y="${y + h + 36}" text-anchor="middle" ${ttl.a}>${esc(p.xtitle)}</text>`);
|
|
2329
|
+
if (p.ytitle) out.push(`<text x="${x}" y="${y - 12}" ${ttl.a}>${esc(p.ytitle)}</text>`);
|
|
2330
|
+
const named = rows.filter((r) => r.cells[0]);
|
|
2331
|
+
if (named.length > 1 && p.key !== "0") {
|
|
2332
|
+
let kx = x + w;
|
|
2333
|
+
for (const r of [...named].reverse()) {
|
|
2334
|
+
const tw = textWidth(r.cells[0], ttl.size, ttl.font, 400, 0);
|
|
2335
|
+
kx -= tw;
|
|
2336
|
+
out.push(`<text x="${r2(kx)}" y="${y - 12}" ${ttl.a}>${esc(r.cells[0])}</text>`);
|
|
2337
|
+
kx -= 14;
|
|
2338
|
+
out.push(`<rect x="${r2(kx)}" y="${y - 20}" width="10" height="10" rx="2" fill="${col(look, colour(r, r.id === "bars" ? "fill" : "stroke"))}"/>`);
|
|
2339
|
+
kx -= 16;
|
|
2340
|
+
}
|
|
2341
|
+
}
|
|
2342
|
+
if (s.text) {
|
|
2343
|
+
const t = textAttrs(look, p, "title.", { font: "sans", size: 12, weight: 600, color: "ink" });
|
|
2344
|
+
out.push(`<text x="${x}" y="${y - (p.ytitle || named.length > 1 && p.key !== "0" ? 32 : 12)}" ${t.a}>${esc(s.text)}</text>`);
|
|
2345
|
+
}
|
|
2346
|
+
return out.join("\n");
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
// src/sketch.ts
|
|
2350
|
+
function seeded(text, pass) {
|
|
2351
|
+
let h = 2166136261 ^ pass;
|
|
2352
|
+
for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 16777619);
|
|
2353
|
+
return () => {
|
|
2354
|
+
h = h + 1831565813 | 0;
|
|
2355
|
+
let t = Math.imul(h ^ h >>> 15, 1 | h);
|
|
2356
|
+
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
|
|
2357
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
function canSketch(d) {
|
|
2361
|
+
return /^[MLCQZ0-9eE\s,.+-]*$/.test(d);
|
|
2362
|
+
}
|
|
2363
|
+
function roughPath(d, amount, pass) {
|
|
2364
|
+
const rnd = seeded(d, pass), off = (k) => (rnd() - 0.5) * 2 * k;
|
|
2365
|
+
const jit = (p, k) => ({ x: p.x + off(k), y: p.y + off(k) });
|
|
2366
|
+
const out = [];
|
|
2367
|
+
let cur = { x: 0, y: 0 }, start = cur, pen = cur;
|
|
2368
|
+
const line = (to) => {
|
|
2369
|
+
const dx = to.x - cur.x, dy = to.y - cur.y, len = Math.hypot(dx, dy);
|
|
2370
|
+
if (len < 0.5) return;
|
|
2371
|
+
const bow = off(Math.min(len * 0.02, 3.2) * amount), nx = -dy / len, ny = dx / len;
|
|
2372
|
+
const k = Math.min(1.8, 0.35 + len * 0.012) * amount;
|
|
2373
|
+
const end = jit(to, k);
|
|
2374
|
+
const c1 = { x: pen.x + dx / 3 + nx * bow, y: pen.y + dy / 3 + ny * bow };
|
|
2375
|
+
const c2 = { x: pen.x + dx * 2 / 3 + nx * bow, y: pen.y + dy * 2 / 3 + ny * bow };
|
|
2376
|
+
out.push(`C ${r2(c1.x)},${r2(c1.y)} ${r2(c2.x)},${r2(c2.y)} ${r2(end.x)},${r2(end.y)}`);
|
|
2377
|
+
cur = to;
|
|
2378
|
+
pen = end;
|
|
2379
|
+
};
|
|
2380
|
+
const toks = d.match(/[MLCQZ]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi) ?? [];
|
|
2381
|
+
let i = 0;
|
|
2382
|
+
const pt = () => ({ x: +toks[i++], y: +toks[i++] });
|
|
2383
|
+
while (i < toks.length) {
|
|
2384
|
+
const c = toks[i++];
|
|
2385
|
+
if (c === "M") {
|
|
2386
|
+
cur = start = pt();
|
|
2387
|
+
pen = jit(cur, 0.6 * amount);
|
|
2388
|
+
out.push(`M ${r2(pen.x)},${r2(pen.y)}`);
|
|
2389
|
+
} else if (c === "L") {
|
|
2390
|
+
while (i < toks.length && !/[A-Z]/i.test(toks[i])) line(pt());
|
|
2391
|
+
} else if (c === "C") {
|
|
2392
|
+
while (i < toks.length && !/[A-Z]/i.test(toks[i])) {
|
|
2393
|
+
const a = jit(pt(), 0.9 * amount), b = jit(pt(), 0.9 * amount);
|
|
2394
|
+
cur = pt();
|
|
2395
|
+
pen = jit(cur, 0.6 * amount);
|
|
2396
|
+
out.push(`C ${r2(a.x)},${r2(a.y)} ${r2(b.x)},${r2(b.y)} ${r2(pen.x)},${r2(pen.y)}`);
|
|
2397
|
+
}
|
|
2398
|
+
} else if (c === "Q") {
|
|
2399
|
+
while (i < toks.length && !/[A-Z]/i.test(toks[i])) {
|
|
2400
|
+
const a = jit(pt(), 0.6 * amount);
|
|
2401
|
+
cur = pt();
|
|
2402
|
+
pen = jit(cur, 0.5 * amount);
|
|
2403
|
+
out.push(`Q ${r2(a.x)},${r2(a.y)} ${r2(pen.x)},${r2(pen.y)}`);
|
|
2404
|
+
}
|
|
2405
|
+
} else if (c === "Z") line(start);
|
|
2406
|
+
else i++;
|
|
2407
|
+
}
|
|
2408
|
+
return out.join(" ");
|
|
2409
|
+
}
|
|
2410
|
+
function sketchSvg(d, attrs, amount, under = "") {
|
|
2411
|
+
const fill = /fill="([^"]*)"/.exec(attrs)?.[1] ?? "none";
|
|
2412
|
+
const strokeAttrs2 = attrs.replace(/fill="[^"]*"/, 'fill="none"');
|
|
2413
|
+
const hasStroke = !/stroke="none"/.test(attrs) && /stroke="/.test(attrs);
|
|
2414
|
+
const dashed = /stroke-dasharray/.test(attrs);
|
|
2415
|
+
const out = [];
|
|
2416
|
+
if (fill !== "none") out.push(`<path d="${roughPath(d, amount * 0.5, 0)}" fill="${fill}" stroke="none"/>`);
|
|
2417
|
+
if (under) out.push(under.replace("{d}", roughPath(d, amount * 0.5, 0)));
|
|
2418
|
+
if (hasStroke) {
|
|
2419
|
+
const cap = ' stroke-linecap="round" stroke-linejoin="round"';
|
|
2420
|
+
out.push(`<path d="${roughPath(d, amount, 1)}" ${strokeAttrs2}${cap}/>`);
|
|
2421
|
+
if (!dashed) out.push(`<path d="${roughPath(d, amount, 2)}" ${strokeAttrs2.replace(/stroke-width="([\d.]+)"/, (_, w) => `stroke-width="${r2(+w * 0.85)}"`)}${cap}/>`);
|
|
2422
|
+
}
|
|
2423
|
+
return out.join("\n");
|
|
2424
|
+
}
|
|
2425
|
+
function rectD(x, y, w, h, r) {
|
|
2426
|
+
if (!r) return `M ${x},${y} L ${x + w},${y} L ${x + w},${y + h} L ${x},${y + h} Z`;
|
|
2427
|
+
return `M ${x + r},${y} L ${x + w - r},${y} Q ${x + w},${y} ${x + w},${y + r} L ${x + w},${y + h - r} Q ${x + w},${y + h} ${x + w - r},${y + h} L ${x + r},${y + h} Q ${x},${y + h} ${x},${y + h - r} L ${x},${y + r} Q ${x},${y} ${x + r},${y} Z`;
|
|
2428
|
+
}
|
|
2429
|
+
function ellipseD(x, y, w, h) {
|
|
2430
|
+
const cx2 = x + w / 2, cy2 = y + h / 2, rx = w / 2, ry = h / 2, k = 0.5523;
|
|
2431
|
+
return `M ${r2(cx2 + rx)},${r2(cy2)} C ${r2(cx2 + rx)},${r2(cy2 + ry * k)} ${r2(cx2 + rx * k)},${r2(cy2 + ry)} ${r2(cx2)},${r2(cy2 + ry)} C ${r2(cx2 - rx * k)},${r2(cy2 + ry)} ${r2(cx2 - rx)},${r2(cy2 + ry * k)} ${r2(cx2 - rx)},${r2(cy2)} C ${r2(cx2 - rx)},${r2(cy2 - ry * k)} ${r2(cx2 - rx * k)},${r2(cy2 - ry)} ${r2(cx2)},${r2(cy2 - ry)} C ${r2(cx2 + rx * k)},${r2(cy2 - ry)} ${r2(cx2 + rx)},${r2(cy2 - ry * k)} ${r2(cx2 + rx)},${r2(cy2 + ry * 0.08)}`;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
// src/render.ts
|
|
2435
|
+
var R = { amt: 0, defs: /* @__PURE__ */ new Map() };
|
|
2436
|
+
var roughOf = (p) => p.sketch === "0" ? 0 : R.amt;
|
|
2437
|
+
function hatchFill(look, p) {
|
|
2438
|
+
if (!p.hatch || p.hatch === "none") return null;
|
|
2439
|
+
const c = col(look, p.hatch), gap = num2(p["hatch.gap"], 6), sw = num2(p["hatch.sw"], 1), key = `${c}|${gap}|${sw}`;
|
|
2440
|
+
let id = R.defs.get(key);
|
|
2441
|
+
if (!id) {
|
|
2442
|
+
id = `fd-hatch-${R.defs.size}`;
|
|
2443
|
+
R.defs.set(key, id);
|
|
2444
|
+
}
|
|
2445
|
+
return `url(#${id})`;
|
|
2446
|
+
}
|
|
2447
|
+
function hatchDefs() {
|
|
2448
|
+
return [...R.defs].map(([key, id]) => {
|
|
2449
|
+
const [c, gap, sw] = key.split("|");
|
|
2450
|
+
return `<pattern id="${id}" width="${gap}" height="${gap}" patternUnits="userSpaceOnUse" patternTransform="rotate(-41)"><line x1="0" y1="0" x2="0" y2="${gap}" stroke="${c}" stroke-width="${sw}" stroke-linecap="round"/></pattern>`;
|
|
2451
|
+
}).join("");
|
|
2452
|
+
}
|
|
2453
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
2454
|
+
var num2 = (v, d) => v === void 0 || v === "" || isNaN(+v) ? d : +v;
|
|
2455
|
+
var r2 = (n) => Math.round(n * 100) / 100;
|
|
2456
|
+
var col = (look, v) => esc(color(look, v));
|
|
2457
|
+
var fam = (look, v) => esc(fontFamily(look, v));
|
|
2458
|
+
function textAttrs(look, p, pre, d) {
|
|
2459
|
+
const g = (k) => p[pre + k];
|
|
2460
|
+
const size = num2(g("size"), d.size);
|
|
2461
|
+
const spacing = num2(g("spacing"), 0);
|
|
2462
|
+
let a = `font-family="${fam(look, g("font") ?? d.font)}" font-size="${size}" fill="${col(look, g("color") ?? d.color)}"`;
|
|
2463
|
+
const weight = num2(g("weight"), d.weight);
|
|
2464
|
+
if (weight !== 400) a += ` font-weight="${weight}"`;
|
|
2465
|
+
if (g("italic") === "1") a += ' font-style="italic"';
|
|
2466
|
+
if (spacing) a += ` letter-spacing="${r2(spacing * size)}"`;
|
|
2467
|
+
return { a, size, spacing, font: g("font") ?? d.font, weight };
|
|
2468
|
+
}
|
|
2469
|
+
function strokeAttrs(look, p) {
|
|
2470
|
+
let a = `fill="${col(look, p.fill)}" stroke="${col(look, p.stroke)}"`;
|
|
2471
|
+
if (p.stroke && p.stroke !== "none") a += ` stroke-width="${num2(p.sw, 1)}"`;
|
|
2472
|
+
if (p.dash && p.dash !== "none") a += ` stroke-dasharray="${esc(p.dash)}"`;
|
|
2473
|
+
if (p.cap === "round") a += ' stroke-linecap="round"';
|
|
2474
|
+
return a;
|
|
2475
|
+
}
|
|
2476
|
+
function shapeD(s) {
|
|
2477
|
+
const { x, y, w, h } = s;
|
|
2478
|
+
if (s.shape === "ellipse") return ellipseD(x, y, w, h);
|
|
2479
|
+
if (s.shape === "diamond") return `M ${x + w / 2},${y} L ${x + w},${y + h / 2} L ${x + w / 2},${y + h} L ${x},${y + h / 2} Z`;
|
|
2480
|
+
if (s.shape === "polygon") return s.poly ? polyD(s) : null;
|
|
2481
|
+
if (s.shape === "path") return s.p.path ? scaledPath(s) : null;
|
|
2482
|
+
if (s.shape === "arc") return null;
|
|
2483
|
+
return rectD(x, y, w, h, Math.min(num2(s.p.radius, 0), w / 2, h / 2));
|
|
2484
|
+
}
|
|
2485
|
+
function scaledPath(s) {
|
|
2486
|
+
let isX = true;
|
|
2487
|
+
return s.p.path.replace(/-?\d*\.?\d+/g, (n) => {
|
|
2488
|
+
const v = isX ? s.x + +n * s.w : s.y + +n * s.h;
|
|
2489
|
+
isX = !isX;
|
|
2490
|
+
return String(r2(v));
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2493
|
+
function polyD(s) {
|
|
2494
|
+
const P = s.poly, open = s.p.open === "1";
|
|
2495
|
+
if (s.p.smooth === "1" && P.length > 2) {
|
|
2496
|
+
const at = (i) => open ? P[Math.min(Math.max(i, 0), P.length - 1)] : P[(i + P.length) % P.length];
|
|
2497
|
+
let d = `M ${P[0].x},${P[0].y}`;
|
|
2498
|
+
for (let i = 0; i < (open ? P.length - 1 : P.length); i++) {
|
|
2499
|
+
const p0 = at(i - 1), p1 = at(i), p2 = at(i + 1), p3 = at(i + 2);
|
|
2500
|
+
d += ` C ${r2(p1.x + (p2.x - p0.x) / 6)},${r2(p1.y + (p2.y - p0.y) / 6)} ${r2(p2.x - (p3.x - p1.x) / 6)},${r2(p2.y - (p3.y - p1.y) / 6)} ${p2.x},${p2.y}`;
|
|
2501
|
+
}
|
|
2502
|
+
return d + (open ? "" : " Z");
|
|
2503
|
+
}
|
|
2504
|
+
return `M ${P.map((q) => `${q.x},${q.y}`).join(" L ")}${open ? "" : " Z"}`;
|
|
2505
|
+
}
|
|
2506
|
+
function outline(s, attrs, under) {
|
|
2507
|
+
const amt = roughOf(s.p);
|
|
2508
|
+
if (amt) {
|
|
2509
|
+
const d = shapeD(s);
|
|
2510
|
+
if (d && canSketch(d)) {
|
|
2511
|
+
const a = s.shape === "polygon" && s.p.open === "1" ? attrs.replace(/fill="[^"]*"/, 'fill="none"') : attrs;
|
|
2512
|
+
return sketchSvg(d, a, amt, under ? `<path d="{d}" fill="${under}" stroke="none"/>` : "");
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
if (!under) return outlinePlain(s, attrs);
|
|
2516
|
+
return [outlinePlain(s, attrs.replace(/stroke="[^"]*"/, 'stroke="none"')), outlinePlain(s, `fill="${under}" stroke="none"`), outlinePlain(s, attrs.replace(/fill="[^"]*"/, 'fill="none"'))].join("\n");
|
|
2517
|
+
}
|
|
2518
|
+
function outlinePlain(s, attrs) {
|
|
2519
|
+
const { x, y, w, h } = s;
|
|
2520
|
+
if (s.shape === "ellipse") return `<ellipse cx="${x + w / 2}" cy="${y + h / 2}" rx="${w / 2}" ry="${h / 2}" ${attrs}/>`;
|
|
2521
|
+
if (s.shape === "diamond") return `<polygon points="${x + w / 2},${y} ${x + w},${y + h / 2} ${x + w / 2},${y + h} ${x},${y + h / 2}" ${attrs}/>`;
|
|
2522
|
+
if (s.shape === "path" && s.p.path) {
|
|
2523
|
+
let isX = true;
|
|
2524
|
+
const d = s.p.path.replace(/-?\d*\.?\d+/g, (n) => {
|
|
2525
|
+
const v = isX ? x + +n * w : y + +n * h;
|
|
2526
|
+
isX = !isX;
|
|
2527
|
+
return String(r2(v));
|
|
2528
|
+
});
|
|
2529
|
+
return `<path d="${esc(d)}" ${attrs}/>`;
|
|
2530
|
+
}
|
|
2531
|
+
if (s.shape === "polygon" && s.poly) {
|
|
2532
|
+
const P = s.poly, open = s.p.open === "1";
|
|
2533
|
+
const a = open ? attrs.replace(/fill="[^"]*"/, 'fill="none"') : attrs;
|
|
2534
|
+
if (s.p.smooth === "1" && P.length > 2) {
|
|
2535
|
+
const at = (i) => open ? P[Math.min(Math.max(i, 0), P.length - 1)] : P[(i + P.length) % P.length];
|
|
2536
|
+
let d = `M ${P[0].x},${P[0].y}`;
|
|
2537
|
+
for (let i = 0; i < (open ? P.length - 1 : P.length); i++) {
|
|
2538
|
+
const p0 = at(i - 1), p1 = at(i), p2 = at(i + 1), p3 = at(i + 2);
|
|
2539
|
+
d += ` C ${r2(p1.x + (p2.x - p0.x) / 6)},${r2(p1.y + (p2.y - p0.y) / 6)} ${r2(p2.x - (p3.x - p1.x) / 6)},${r2(p2.y - (p3.y - p1.y) / 6)} ${p2.x},${p2.y}`;
|
|
2540
|
+
}
|
|
2541
|
+
return `<path d="${d}${open ? "" : " Z"}" stroke-linejoin="round" ${a}/>`;
|
|
2542
|
+
}
|
|
2543
|
+
return `<${open ? "polyline" : "polygon"} points="${P.map((q) => `${q.x},${q.y}`).join(" ")}" stroke-linejoin="round" ${a}/>`;
|
|
2544
|
+
}
|
|
2545
|
+
if (s.shape === "arc") {
|
|
2546
|
+
const a0 = num2(s.p.from, 0), a1 = num2(s.p.to, 360), inner = Math.min(Math.max(num2(s.p.inner, 0), 0), 0.98), open = s.p.open === "1";
|
|
2547
|
+
const cx0 = x + w / 2, cy0 = y + h / 2;
|
|
2548
|
+
const pt = (deg, k) => `${r2(cx0 + w / 2 * k * Math.sin(deg * Math.PI / 180))},${r2(cy0 - h / 2 * k * Math.cos(deg * Math.PI / 180))}`;
|
|
2549
|
+
const sweep = (k, f, t) => {
|
|
2550
|
+
const mid = (f + t) / 2, dir = t > f ? 1 : 0, r = `${r2(w / 2 * k)} ${r2(h / 2 * k)}`;
|
|
2551
|
+
return `A ${r} 0 0 ${dir} ${pt(mid, k)} A ${r} 0 0 ${dir} ${pt(t, k)}`;
|
|
2552
|
+
};
|
|
2553
|
+
const full = Math.abs(a1 - a0) >= 360;
|
|
2554
|
+
let d = `M ${pt(a0, 1)} ${sweep(1, a0, a1)}`;
|
|
2555
|
+
if (open) return `<path d="${d}" ${attrs.replace(/fill="[^"]*"/, 'fill="none"')} stroke-linecap="round"/>`;
|
|
2556
|
+
if (inner > 0) d += full ? ` Z M ${pt(a1, inner)} ${sweep(inner, a1, a0)} Z` : ` L ${pt(a1, inner)} ${sweep(inner, a1, a0)} Z`;
|
|
2557
|
+
else d += full ? " Z" : ` L ${r2(cx0)},${r2(cy0)} Z`;
|
|
2558
|
+
return `<path d="${d}" fill-rule="evenodd" stroke-linejoin="round" ${attrs}/>`;
|
|
2559
|
+
}
|
|
2560
|
+
const rx = Math.min(num2(s.p.radius, 0), w / 2, h / 2);
|
|
2561
|
+
return `<rect x="${x}" y="${y}" width="${w}" height="${h}"${rx ? ` rx="${rx}"` : ""} ${attrs}/>`;
|
|
2562
|
+
}
|
|
2563
|
+
function drawLegend(look, s) {
|
|
2564
|
+
const p = s.p, out = [];
|
|
2565
|
+
out.push(`<line x1="${s.x}" y1="${s.y}" x2="${s.x + s.w}" y2="${s.y}" stroke="${col(look, p.rule ?? "ink/0.12")}" stroke-width="0.8"/>`);
|
|
2566
|
+
if ((p.title ?? "none") !== "none") {
|
|
2567
|
+
const t = textAttrs(look, p, "title.", { font: "mono", size: 8, weight: 400, color: "muted" });
|
|
2568
|
+
out.push(`<text x="${s.x}" y="${s.y + 16}" ${t.a}>${esc(p["title.caps"] === "0" ? p.title : p.title.toUpperCase())}</text>`);
|
|
2569
|
+
}
|
|
2570
|
+
const it = textAttrs(look, p, "item.", { font: "sans", size: 8.5, weight: 400, color: "muted" });
|
|
2571
|
+
for (const e of s.legend ?? []) {
|
|
2572
|
+
const sp = e.props ?? look.styles.get(e.style)?.props ?? {};
|
|
2573
|
+
const y = e.baseline;
|
|
2574
|
+
if (e.kind === "line") {
|
|
2575
|
+
const sw = Math.min(num2(sp.sw, 1.2), 1.6), stroke = col(look, sp.stroke ?? "muted");
|
|
2576
|
+
const mk = sp.head === "none" || sp.route === "straight" ? "none" : sp.head ?? "arrow", head = mk !== "none";
|
|
2577
|
+
const hm = marker(mk, { x: e.x + 28, y: y - 3 }, { x: e.x, y: y - 3 }, sw, stroke, col(look, look.canvas.paper ?? "paper"));
|
|
2578
|
+
const dash = sp.dash && sp.dash !== "none" ? ` stroke-dasharray="${esc(sp.dash)}"` : "";
|
|
2579
|
+
out.push(R.amt ? sketchSvg(`M ${e.x},${y - 3} L ${r2(e.x + 28 - hm.trim)},${y - 3}`, `fill="none" stroke="${stroke}" stroke-width="${sw}"${dash}`, R.amt * 0.6) : `<line x1="${e.x}" y1="${y - 3}" x2="${r2(e.x + 28 - hm.trim)}" y2="${y - 3}" stroke="${stroke}" stroke-width="${sw}"${dash}/>`);
|
|
2580
|
+
if (head) out.push(hm.svg);
|
|
2581
|
+
} else if (e.kind === "text") {
|
|
2582
|
+
const t = textAttrs(look, { ...sp, size: String(Math.min(num2(sp.size, 12), 11)) }, "", { font: "sans", size: 11, weight: 400, color: "ink" });
|
|
2583
|
+
out.push(`<text x="${e.x}" y="${y}" ${t.a}>Aa</text>`);
|
|
2584
|
+
} else {
|
|
2585
|
+
const a = strokeAttrs(look, { ...sp, sw: String(Math.min(num2(sp.sw, 1), 1.2)) });
|
|
2586
|
+
const m = /^(\d+(?:\.\d+)?)x/.exec(sp.size ?? "");
|
|
2587
|
+
if (sp.shape === "dot") out.push(`<circle cx="${e.x + 7}" cy="${y - 3}" r="4.5" ${a}/>`);
|
|
2588
|
+
else if (sp.shape === "diamond") out.push(`<polygon points="${e.x + 11},${y - 9} ${e.x + 22},${y - 3} ${e.x + 11},${y + 3} ${e.x},${y - 3}" ${a}/>`);
|
|
2589
|
+
else if (m && +m[1] <= 12) out.push(`<rect x="${e.x + 5}" y="${y - 11}" width="4" height="14" ${a}/>`);
|
|
2590
|
+
else out.push(`<rect x="${e.x}" y="${y - 8}" width="14" height="10" rx="${num2(sp.radius, 0) >= 12 ? 5 : 2}" ${a}/>`);
|
|
2591
|
+
}
|
|
2592
|
+
out.push(`<text x="${e.x + e.sample + 6}" y="${y}" ${it.a}>${esc(e.label)}</text>`);
|
|
2593
|
+
}
|
|
2594
|
+
return out.join("\n");
|
|
2595
|
+
}
|
|
2596
|
+
function drawTable(look, s) {
|
|
2597
|
+
const p = s.p, out = [], rows = s.rows ?? [], cols = s.cols ?? [], headH = s.headH ?? 0;
|
|
2598
|
+
const paper = col(look, look.canvas.paper ?? "paper"), stroke = col(look, p.stroke), sw = num2(p.sw, 1);
|
|
2599
|
+
const r = Math.min(num2(p.radius, 0), s.w / 2, s.h / 2), x2 = s.x + s.w;
|
|
2600
|
+
out.push(`<rect x="${s.x}" y="${s.y}" width="${s.w}" height="${s.h}"${r ? ` rx="${r}"` : ""} fill="${paper}"/>`);
|
|
2601
|
+
out.push(`<rect x="${s.x}" y="${s.y}" width="${s.w}" height="${s.h}"${r ? ` rx="${r}"` : ""} fill="${col(look, p.fill)}"/>`);
|
|
2602
|
+
if (headH) {
|
|
2603
|
+
const hy = s.y + headH;
|
|
2604
|
+
out.push(`<path d="M ${s.x},${hy} L ${s.x},${s.y + r} Q ${s.x},${s.y} ${s.x + r},${s.y} L ${x2 - r},${s.y} Q ${x2},${s.y} ${x2},${s.y + r} L ${x2},${hy} Z" fill="${col(look, p["head.fill"] ?? "ink/0.06")}"/>`);
|
|
2605
|
+
const t = textAttrs(look, p, "title.", { font: "sans", size: 12, weight: 600, color: "ink" });
|
|
2606
|
+
const txt = p["title.caps"] === "1" ? s.text.toUpperCase() : s.text;
|
|
2607
|
+
const tl = txt.split("\n"), tlh = Math.round(t.size * 1.25), left = p["title.align"] === "left";
|
|
2608
|
+
tl.forEach((l, i) => out.push(`<text x="${left ? s.x + num2(p["cell.pad"], 12) : s.x + s.w / 2}" y="${r2(hy - headH / 2 + t.size * 0.36 + (i - (tl.length - 1) / 2) * tlh)}" text-anchor="${left ? "start" : "middle"}" ${t.a}>${esc(l)}</text>`));
|
|
2609
|
+
if (rows.length) out.push(`<line x1="${s.x}" y1="${hy}" x2="${x2}" y2="${hy}" stroke="${stroke}" stroke-width="${sw}"/>`);
|
|
2610
|
+
}
|
|
2611
|
+
const first = textAttrs(look, p, "cell.", { font: "mono", size: 10, weight: 400, color: "ink" });
|
|
2612
|
+
const rest = textAttrs(look, { ...p, "cell.color": p["detail.color"] ?? "muted" }, "cell.", { font: "mono", size: 10, weight: 400, color: "muted" });
|
|
2613
|
+
const strong = textAttrs(look, { ...p, "cell.weight": "600" }, "cell.", { font: "mono", size: 10, weight: 600, color: "ink" });
|
|
2614
|
+
const center = p.align === "center", rule = col(look, p.rule ?? "ink/0.1");
|
|
2615
|
+
rows.forEach((row, i) => {
|
|
2616
|
+
if (row.kind === "rule") {
|
|
2617
|
+
out.push(`<line x1="${s.x}" y1="${row.y}" x2="${x2}" y2="${row.y}" stroke="${stroke}" stroke-width="${sw}"/>`);
|
|
2618
|
+
return;
|
|
2619
|
+
}
|
|
2620
|
+
const fill = row.p.fill ?? (row.kind === "head" ? p["head.fill"] ?? "ink/0.06" : void 0);
|
|
2621
|
+
if (fill && fill !== "none") out.push(`<rect x="${s.x + sw / 2}" y="${row.y}" width="${s.w - sw}" height="${row.h - (i === rows.length - 1 ? sw / 2 : 0)}" fill="${col(look, fill)}"/>`);
|
|
2622
|
+
const prev = rows[i - 1];
|
|
2623
|
+
if (prev && prev.kind !== "rule" && p.rules !== "0") out.push(`<line x1="${s.x}" y1="${row.y}" x2="${x2}" y2="${row.y}" stroke="${rule}" stroke-width="0.8"/>`);
|
|
2624
|
+
row.cells.forEach((cell, j) => {
|
|
2625
|
+
const c = cols[j];
|
|
2626
|
+
if (!c) return;
|
|
2627
|
+
const cf = row.p[`fill.${j + 1}`], cc = row.p[`color.${j + 1}`], g = num2(p["cell.gap"], 16);
|
|
2628
|
+
if (cf && cf !== "none") {
|
|
2629
|
+
const x0 = j === 0 ? s.x + sw / 2 : s.x + c.x - g / 2, x1 = j === cols.length - 1 ? x2 - sw / 2 : s.x + cols[j + 1].x - g / 2;
|
|
2630
|
+
out.push(`<rect x="${r2(x0)}" y="${row.y}" width="${r2(x1 - x0)}" height="${row.h}" fill="${col(look, cf)}"/>`);
|
|
2631
|
+
}
|
|
2632
|
+
if (cell === "") return;
|
|
2633
|
+
const base = row.kind === "head" ? strong : j === 0 ? first : rest;
|
|
2634
|
+
const a = cc ? { ...base, a: base.a.replace(/fill="[^"]*"/, () => `fill="${col(look, cc)}"`) } : base;
|
|
2635
|
+
const mid = center && j > 0;
|
|
2636
|
+
out.push(`<text x="${r2(s.x + c.x + (mid ? c.w / 2 : 0))}" y="${r2(row.y + row.h / 2 + a.size * 0.36)}"${mid ? ' text-anchor="middle"' : ""} ${a.a}>${esc(cell)}</text>`);
|
|
2637
|
+
});
|
|
2638
|
+
});
|
|
2639
|
+
if (p.grid === "1" && rows.length) for (const c of cols.slice(1)) {
|
|
2640
|
+
const gx = r2(s.x + c.x - num2(p["cell.gap"], 16) / 2);
|
|
2641
|
+
out.push(`<line x1="${gx}" y1="${s.y + headH}" x2="${gx}" y2="${s.y + s.h}" stroke="${rule}" stroke-width="0.8"/>`);
|
|
2642
|
+
}
|
|
2643
|
+
let border = `fill="none" stroke="${stroke}"`;
|
|
2644
|
+
if (p.stroke && p.stroke !== "none") border += ` stroke-width="${sw}"`;
|
|
2645
|
+
if (p.dash && p.dash !== "none") border += ` stroke-dasharray="${esc(p.dash)}"`;
|
|
2646
|
+
out.push(roughOf(p) ? sketchSvg(rectD(s.x, s.y, s.w, s.h, r), border, roughOf(p)) : `<rect x="${s.x}" y="${s.y}" width="${s.w}" height="${s.h}"${r ? ` rx="${r}"` : ""} ${border}/>`);
|
|
2647
|
+
return out.join("\n");
|
|
2648
|
+
}
|
|
2649
|
+
function iconBox(s) {
|
|
2650
|
+
const p = s.p;
|
|
2651
|
+
if (!p.icon || p.icon === "none") return null;
|
|
2652
|
+
const hasText = !!(s.text || p.sub) && p["title.pos"] !== "top";
|
|
2653
|
+
const size = num2(p["icon.size"], hasText ? 20 : Math.max(8, Math.min(s.w, s.h, 96) - (s.style === "icon" ? 0 : 16)));
|
|
2654
|
+
if (!hasText) return { x: s.x + (s.w - size) / 2, y: s.y + (s.h - size) / 2, size, dx: 0, dy: 0 };
|
|
2655
|
+
if (p["icon.pos"] === "top") return { x: s.x + (s.w - size) / 2, y: 0, size, dx: 0, dy: (size + 6) / 2 };
|
|
2656
|
+
if (p["title.align"] === "left" || p["title.align"] === "right") return { x: s.x + 12, y: s.y + (s.h - size) / 2, size, dx: (size + 8) / 2, dy: 0 };
|
|
2657
|
+
const widths = [
|
|
2658
|
+
...(s.text ? s.text.split("\n") : []).map((l) => textWidth(p["title.caps"] === "1" ? l.toUpperCase() : l, num2(p["title.size"], 12), p["title.font"] ?? "sans", num2(p["title.weight"], 600), num2(p["title.spacing"], 0))),
|
|
2659
|
+
...(p.sub ? p.sub.split("\n") : []).map((l) => textWidth(l, num2(p["sub.size"], 9), p["sub.font"] ?? "mono", 400, 0))
|
|
2660
|
+
];
|
|
2661
|
+
const tw = Math.max(0, ...widths), x = Math.max(s.x + 8, s.x + (s.w - (size + 8 + tw)) / 2);
|
|
2662
|
+
return { x, y: s.y + (s.h - size) / 2, size, dx: (size + 8) / 2, dy: 0 };
|
|
2663
|
+
}
|
|
2664
|
+
function drawIcon(look, p, x, y, size) {
|
|
2665
|
+
const name2 = p.icon, img = look.images.get(name2);
|
|
2666
|
+
if (img) return isIconUri(img) ? `<image x="${r2(x)}" y="${r2(y)}" width="${r2(size)}" height="${r2(size)}" href="${esc(img)}"/>` : "";
|
|
2667
|
+
const k = r2(size / 24);
|
|
2668
|
+
const stroke = col(look, p["icon.color"] ?? p["title.color"] ?? "ink"), fill = col(look, p["icon.fill"] ?? "none");
|
|
2669
|
+
const px = num2(p["icon.width"], 0), sw = px > 0 ? Math.min(px, 8) / k : Math.max(1.5, 1.2 / k);
|
|
2670
|
+
const paths = (look.icons.get(name2) ?? []).map((d) => `<path d="${esc(d)}"/>`).join("");
|
|
2671
|
+
return `<g transform="translate(${r2(x)} ${r2(y)}) scale(${k})" fill="${fill}" stroke="${stroke}" stroke-width="${r2(sw)}" stroke-linecap="round" stroke-linejoin="round">${paths}</g>`;
|
|
2672
|
+
}
|
|
2673
|
+
function drawIconShape(look, s) {
|
|
2674
|
+
const p = s.p, size = Math.min(s.w, s.h), out = [];
|
|
2675
|
+
const ip = { ...p, "icon.fill": p.fill ?? p["icon.fill"] ?? "none", "icon.color": p.stroke ?? p["icon.color"] ?? "ink", "icon.width": p.sw ?? p["icon.width"] ?? "" };
|
|
2676
|
+
if (p.icon && p.icon !== "none") out.push(drawIcon(look, ip, s.x + (s.w - size) / 2, s.y + (s.h - size) / 2, size));
|
|
2677
|
+
const cx2 = s.x + s.w / 2;
|
|
2678
|
+
let y = s.y + s.h + ICON_CAPTION_GAP;
|
|
2679
|
+
if (s.text) {
|
|
2680
|
+
const t = textAttrs(look, p, "title.", { font: "sans", size: 11, weight: 600, color: "ink" }), lh = Math.round(t.size * 1.17);
|
|
2681
|
+
(p["title.caps"] === "1" ? s.text.toUpperCase() : s.text).split("\n").forEach((l) => {
|
|
2682
|
+
out.push(`<text x="${cx2}" y="${r2(y + t.size * 0.86)}" text-anchor="middle" ${t.a}>${esc(l)}</text>`);
|
|
2683
|
+
y += lh;
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
if (p.sub) {
|
|
2687
|
+
const t = textAttrs(look, p, "sub.", { font: "mono", size: 9, weight: 400, color: "muted" }), lh = Math.round(t.size * 1.3);
|
|
2688
|
+
y += 2;
|
|
2689
|
+
p.sub.split("\n").forEach((l) => {
|
|
2690
|
+
out.push(`<text x="${cx2}" y="${r2(y + t.size * 0.86)}" text-anchor="middle" ${t.a}>${esc(l)}</text>`);
|
|
2691
|
+
y += lh;
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
return out.join("\n");
|
|
2695
|
+
}
|
|
2696
|
+
function drawShape(look, s) {
|
|
2697
|
+
if (s.shape === "legend") return drawLegend(look, s);
|
|
2698
|
+
if (s.shape === "table") return drawTable(look, s);
|
|
2699
|
+
if (s.shape === "chart") return drawChart(look, s);
|
|
2700
|
+
if (s.shape === "icon") return drawIconShape(look, s);
|
|
2701
|
+
const p = s.p, out = [];
|
|
2702
|
+
const paper = col(look, look.canvas.paper ?? "paper");
|
|
2703
|
+
if (!s.back && p.mask !== "0" && p.fill && p.fill !== "none") out.push(outline(s, `fill="${paper}"`));
|
|
2704
|
+
out.push(outline(s, strokeAttrs(look, p), hatchFill(look, p) ?? void 0));
|
|
2705
|
+
let cxm = s.x + s.w / 2, cym = s.y + s.h / 2;
|
|
2706
|
+
if (s.shape === "polygon" && s.poly && s.p.open !== "1") {
|
|
2707
|
+
let A = 0, gx = 0, gy = 0;
|
|
2708
|
+
s.poly.forEach((q, i) => {
|
|
2709
|
+
const n = s.poly[(i + 1) % s.poly.length], k = q.x * n.y - n.x * q.y;
|
|
2710
|
+
A += k;
|
|
2711
|
+
gx += (q.x + n.x) * k;
|
|
2712
|
+
gy += (q.y + n.y) * k;
|
|
2713
|
+
});
|
|
2714
|
+
if (Math.abs(A) > 1) {
|
|
2715
|
+
cxm = r2(gx / (3 * A));
|
|
2716
|
+
cym = r2(gy / (3 * A));
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
if (s.shape === "arc" && Math.abs(num2(p.to, 360) - num2(p.from, 0)) < 360) {
|
|
2720
|
+
const mid = (num2(p.from, 0) + num2(p.to, 360)) / 2 * (Math.PI / 180), inner = num2(p.inner, 0), k = inner > 0 ? (1 + inner) / 2 : 0.62;
|
|
2721
|
+
cxm = r2(cxm + s.w / 2 * k * Math.sin(mid));
|
|
2722
|
+
cym = r2(cym - s.h / 2 * k * Math.cos(mid));
|
|
2723
|
+
}
|
|
2724
|
+
if (p.ghost) {
|
|
2725
|
+
const t = textAttrs(look, p, "ghost.", { font: "mono", size: 32, weight: 600, color: "ink/0.06" });
|
|
2726
|
+
out.push(`<text x="${s.x + s.w - 8}" y="${s.y + s.h - 4}" text-anchor="end" ${t.a}>${esc(p.ghost)}</text>`);
|
|
2727
|
+
}
|
|
2728
|
+
const title = textAttrs(look, p, "title.", { font: "sans", size: 12, weight: 600, color: "ink" });
|
|
2729
|
+
const tb = p.tag ? tagLayout(s, look, textBlock(s, title.size), title.size, cym + (iconBox(s)?.dy ?? 0)) : null;
|
|
2730
|
+
if (tb) {
|
|
2731
|
+
const t = textAttrs(look, p, "tag.", { font: "mono", size: 7, weight: 400, color: "muted" });
|
|
2732
|
+
const tw = tagWidth(look, p);
|
|
2733
|
+
out.push(`<rect x="${s.x + tb.x}" y="${s.y + tb.y}" width="${tw}" height="${tb.h}" rx="2" fill="none" stroke="${col(look, p["tag.border"] ?? "muted/0.4")}" stroke-width="0.8"/>`);
|
|
2734
|
+
out.push(`<text x="${s.x + tb.x + tw / 2}" y="${r2(s.y + tb.y + tb.h / 2 + t.size * 0.36)}" text-anchor="middle" ${t.a}>${esc(p.tag)}</text>`);
|
|
2735
|
+
}
|
|
2736
|
+
const ib = iconBox(s);
|
|
2737
|
+
if (ib) {
|
|
2738
|
+
cxm += ib.dx;
|
|
2739
|
+
cym += ib.dy;
|
|
2740
|
+
}
|
|
2741
|
+
if (ib && !(ib.dy > 0)) out.push(drawIcon(look, p, ib.x, ib.y, ib.size));
|
|
2742
|
+
if (s.text && p["title.pos"] === "top") {
|
|
2743
|
+
const txt = p["title.caps"] === "1" ? s.text.toUpperCase() : s.text;
|
|
2744
|
+
const tw = Math.ceil((textWidth(txt, title.size, title.font, title.weight, title.spacing) + 12) / 4) * 4;
|
|
2745
|
+
const al = p["title.align"], mid = al === "left" ? s.x + 12 + tw / 2 : al === "right" ? s.x + s.w - 12 - tw / 2 : cxm;
|
|
2746
|
+
out.push(`<rect x="${mid - tw / 2}" y="${s.y + 4}" width="${tw}" height="12" rx="2" fill="${paper}"/>`);
|
|
2747
|
+
out.push(`<text x="${mid}" y="${s.y + 13}" text-anchor="middle" ${title.a}>${esc(txt)}</text>`);
|
|
2748
|
+
} else if (s.text || p.sub) {
|
|
2749
|
+
const lines = s.text ? (p["title.caps"] === "1" ? s.text.toUpperCase() : s.text).split("\n") : [];
|
|
2750
|
+
const lh = Math.round(title.size * 1.17);
|
|
2751
|
+
const sub = textAttrs(look, p, "sub.", { font: "mono", size: 9, weight: 400, color: "muted" });
|
|
2752
|
+
const subs = p.sub ? p.sub.split("\n") : [], slh = Math.round(sub.size * 1.3);
|
|
2753
|
+
const block = lines.length * lh + (subs.length ? sub.size + 7 + (subs.length - 1) * slh : 0);
|
|
2754
|
+
const top = tb ? tb.top : cym - block / 2;
|
|
2755
|
+
if (ib && ib.dy > 0) out.push(drawIcon(look, p, ib.x, top - ib.size - 6, ib.size));
|
|
2756
|
+
const al = p["title.align"], tx = al === "left" ? s.x + 12 + (ib && ib.dx ? ib.size + 8 : 0) : al === "right" ? s.x + s.w - 12 : cxm, anchor = al === "left" ? "start" : al === "right" ? "end" : "middle";
|
|
2757
|
+
lines.forEach((l, i) => out.push(`<text x="${tx}" y="${r2(top + title.size * 0.86 + i * lh)}" text-anchor="${anchor}" ${title.a}>${esc(l)}</text>`));
|
|
2758
|
+
subs.forEach((l, i) => out.push(`<text x="${tx}" y="${r2(top + lines.length * lh + sub.size + 3 + i * slh)}" text-anchor="${anchor}" ${sub.a}>${esc(l)}</text>`));
|
|
2759
|
+
}
|
|
2760
|
+
return out.join("\n");
|
|
2761
|
+
}
|
|
2762
|
+
function pathD(pts, radius, trimEnd, trimStart) {
|
|
2763
|
+
const P = pts.map((p) => ({ ...p }));
|
|
2764
|
+
const trim = (i, j, by) => {
|
|
2765
|
+
const dx = P[j].x - P[i].x, dy = P[j].y - P[i].y, len = Math.hypot(dx, dy);
|
|
2766
|
+
if (len > by + 1) {
|
|
2767
|
+
P[i].x += dx / len * by;
|
|
2768
|
+
P[i].y += dy / len * by;
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
if (trimEnd) trim(P.length - 1, P.length - 2, trimEnd);
|
|
2772
|
+
if (trimStart) trim(0, 1, trimStart);
|
|
2773
|
+
let d = `M ${r2(P[0].x)},${r2(P[0].y)}`;
|
|
2774
|
+
for (let i = 1; i < P.length; i++) {
|
|
2775
|
+
const cur = P[i], prev = P[i - 1], next = P[i + 1];
|
|
2776
|
+
if (!next || !radius) {
|
|
2777
|
+
d += ` L ${r2(cur.x)},${r2(cur.y)}`;
|
|
2778
|
+
continue;
|
|
2779
|
+
}
|
|
2780
|
+
const l1 = Math.hypot(cur.x - prev.x, cur.y - prev.y), l2 = Math.hypot(next.x - cur.x, next.y - cur.y);
|
|
2781
|
+
const r = Math.min(radius, l1 / 2, l2 / 2);
|
|
2782
|
+
const a = { x: cur.x - (cur.x - prev.x) / l1 * r, y: cur.y - (cur.y - prev.y) / l1 * r };
|
|
2783
|
+
const b = { x: cur.x + (next.x - cur.x) / l2 * r, y: cur.y + (next.y - cur.y) / l2 * r };
|
|
2784
|
+
d += ` L ${r2(a.x)},${r2(a.y)} Q ${cur.x},${cur.y} ${r2(b.x)},${r2(b.y)}`;
|
|
2785
|
+
}
|
|
2786
|
+
return d;
|
|
2787
|
+
}
|
|
2788
|
+
function textBlock(s, titleSize) {
|
|
2789
|
+
const p = s.p, subSize = num2(p["sub.size"], 9), subs = p.sub ? p.sub.split("\n").length : 0;
|
|
2790
|
+
const lines = s.text ? s.text.split("\n").length : 0;
|
|
2791
|
+
return lines * Math.round(titleSize * 1.17) + (subs ? subSize + 7 + (subs - 1) * Math.round(subSize * 1.3) : 0);
|
|
2792
|
+
}
|
|
2793
|
+
function tagLayout(s, look, block, titleSize, cym) {
|
|
2794
|
+
const p = s.p, rough = p.sketch === "0" ? 0 : Math.max(0, Math.min(num2(look.canvas.sketch, 0), 4));
|
|
2795
|
+
const x = 8 + (rough ? 2 : 0), h = Math.max(12, Math.ceil(num2(p["tag.size"], 7) + 4)), glyph = titleSize * 0.14;
|
|
2796
|
+
const below = outlineClear(s, x, tagWidth(look, p), h, 6, 3 + rough);
|
|
2797
|
+
const at = (y, pad) => {
|
|
2798
|
+
const clear = s.y + y + h + 3 - glyph, floor = s.y + s.h - pad - block;
|
|
2799
|
+
return { y, top: Math.min(Math.max(cym - block / 2 + 8, clear), Math.max(floor, cym - block / 2)), fits: clear <= floor + 0.5 };
|
|
2800
|
+
};
|
|
2801
|
+
const roomy = at(Math.max(8, below), 4), tight = roomy.fits ? roomy : at(Math.max(6, below), 2);
|
|
2802
|
+
if (!roomy.fits && !tight.fits) {
|
|
2803
|
+
const y = Math.max(8, below), top = Math.min(cym - block / 2 + 8, Math.max(s.y + s.h - 4 - block, cym - block / 2));
|
|
2804
|
+
if (besideTag(s, look, x + tagWidth(look, p), s.y + y - 2, s.y + y + h + 2, top)) return { x, h, y, top, fits: true };
|
|
2805
|
+
}
|
|
2806
|
+
return { x, h, ...tight.fits ? tight : roomy };
|
|
2807
|
+
}
|
|
2808
|
+
function besideTag(s, look, right, y0, y1, top) {
|
|
2809
|
+
const p = s.p;
|
|
2810
|
+
if (p["title.align"] || p.icon) return false;
|
|
2811
|
+
const title = textAttrs(look, p, "title.", { font: "sans", size: 12, weight: 600, color: "ink" });
|
|
2812
|
+
const sub = textAttrs(look, p, "sub.", { font: "mono", size: 9, weight: 400, color: "muted" });
|
|
2813
|
+
const lines = s.text ? (p["title.caps"] === "1" ? s.text.toUpperCase() : s.text).split("\n") : [];
|
|
2814
|
+
const lh = Math.round(title.size * 1.17), slh = Math.round(sub.size * 1.3), subs = p.sub ? p.sub.split("\n") : [];
|
|
2815
|
+
const rows = [
|
|
2816
|
+
...lines.map((l, i) => ({ w: textWidth(l, title.size, title.font, title.weight, title.spacing), a: top + i * lh + title.size * 0.14, b: top + i * lh + title.size * 1.05 })),
|
|
2817
|
+
...subs.map((l, i) => {
|
|
2818
|
+
const base = top + lines.length * lh + sub.size + 3 + i * slh;
|
|
2819
|
+
return { w: textWidth(l, sub.size, sub.font, 400, sub.spacing), a: base - sub.size * 0.75, b: base + sub.size * 0.2 };
|
|
2820
|
+
})
|
|
2821
|
+
];
|
|
2822
|
+
return rows.every((r) => r.b < y0 || r.a > y1 || s.w / 2 - r.w / 2 >= right + 2);
|
|
2823
|
+
}
|
|
2824
|
+
function tagWidth(look, p) {
|
|
2825
|
+
const t = textAttrs(look, p, "tag.", { font: "mono", size: 7, weight: 400, color: "muted" });
|
|
2826
|
+
return Math.ceil((textWidth(p.tag ?? "", t.size, t.font, 400, t.spacing) + 12) / 4) * 4;
|
|
2827
|
+
}
|
|
2828
|
+
function outlinePts(s) {
|
|
2829
|
+
const { w, h } = s, out = [];
|
|
2830
|
+
const line = (a, b) => {
|
|
2831
|
+
const n = Math.max(1, Math.ceil(Math.hypot(b.x - a.x, b.y - a.y) / 2));
|
|
2832
|
+
for (let i = 0; i <= n; i++) out.push({ x: a.x + (b.x - a.x) * i / n, y: a.y + (b.y - a.y) * i / n });
|
|
2833
|
+
};
|
|
2834
|
+
if (s.shape === "ellipse") {
|
|
2835
|
+
for (let i = 0; i < 180; i++) {
|
|
2836
|
+
const t = i / 180 * 2 * Math.PI;
|
|
2837
|
+
out.push({ x: w / 2 + w / 2 * Math.cos(t), y: h / 2 + h / 2 * Math.sin(t) });
|
|
2838
|
+
}
|
|
2839
|
+
return out;
|
|
2840
|
+
}
|
|
2841
|
+
if (s.shape === "diamond") {
|
|
2842
|
+
const c = [{ x: w / 2, y: 0 }, { x: w, y: h / 2 }, { x: w / 2, y: h }, { x: 0, y: h / 2 }];
|
|
2843
|
+
c.forEach((a, i) => line(a, c[(i + 1) % 4]));
|
|
2844
|
+
return out;
|
|
2845
|
+
}
|
|
2846
|
+
if (s.shape === "polygon" && s.poly) {
|
|
2847
|
+
const c = s.poly.map((q) => ({ x: q.x - s.x, y: q.y - s.y }));
|
|
2848
|
+
c.forEach((a, i) => line(a, c[(i + 1) % c.length]));
|
|
2849
|
+
return out;
|
|
2850
|
+
}
|
|
2851
|
+
if (s.shape === "path" && s.p.path) {
|
|
2852
|
+
const tok = s.p.path.match(/[MLCZ]|-?\d*\.?\d+/gi) ?? [];
|
|
2853
|
+
let cmd2 = "M", cur = { x: 0, y: 0 }, start = cur, i = 0;
|
|
2854
|
+
const pt = () => ({ x: +tok[i++] * w, y: +tok[i++] * h });
|
|
2855
|
+
while (i < tok.length) {
|
|
2856
|
+
if (/[a-z]/i.test(tok[i])) {
|
|
2857
|
+
cmd2 = tok[i++].toUpperCase();
|
|
2858
|
+
if (cmd2 === "Z") {
|
|
2859
|
+
line(cur, start);
|
|
2860
|
+
cur = start;
|
|
2861
|
+
}
|
|
2862
|
+
continue;
|
|
2863
|
+
}
|
|
2864
|
+
if (cmd2 === "M") {
|
|
2865
|
+
cur = start = pt();
|
|
2866
|
+
cmd2 = "L";
|
|
2867
|
+
} else if (cmd2 === "L") {
|
|
2868
|
+
const b = pt();
|
|
2869
|
+
line(cur, b);
|
|
2870
|
+
cur = b;
|
|
2871
|
+
} else if (cmd2 === "C") {
|
|
2872
|
+
const c1 = pt(), c2 = pt(), b = pt();
|
|
2873
|
+
for (let k = 1; k <= 24; k++) {
|
|
2874
|
+
const t = k / 24, m = 1 - t;
|
|
2875
|
+
const q = { x: m * m * m * cur.x + 3 * m * m * t * c1.x + 3 * m * t * t * c2.x + t * t * t * b.x, y: m * m * m * cur.y + 3 * m * m * t * c1.y + 3 * m * t * t * c2.y + t * t * t * b.y };
|
|
2876
|
+
line(out.length ? out[out.length - 1] : cur, q);
|
|
2877
|
+
}
|
|
2878
|
+
cur = b;
|
|
2879
|
+
} else i++;
|
|
2880
|
+
}
|
|
2881
|
+
return out;
|
|
2882
|
+
}
|
|
2883
|
+
return null;
|
|
2884
|
+
}
|
|
2885
|
+
function outlineClear(s, x, w, h, from, gap) {
|
|
2886
|
+
const pts = outlinePts(s);
|
|
2887
|
+
if (!pts) return 0;
|
|
2888
|
+
for (let y = from; y < s.h / 2; y++) {
|
|
2889
|
+
if (!pts.some((q) => q.x > x - gap && q.x < x + w + gap && q.y > y - gap && q.y < y + h + gap)) return y;
|
|
2890
|
+
}
|
|
2891
|
+
return 0;
|
|
2892
|
+
}
|
|
2893
|
+
function marker(kind, tip, from, sw, stroke, paper) {
|
|
2894
|
+
const dx = tip.x - from.x, dy = tip.y - from.y, len = Math.hypot(dx, dy) || 1;
|
|
2895
|
+
const ux = dx / len, uy = dy / len;
|
|
2896
|
+
const at = (back, side) => `${r2(tip.x - ux * back - uy * side)},${r2(tip.y - uy * back + ux * side)}`;
|
|
2897
|
+
const line = `fill="none" stroke="${stroke}" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"`;
|
|
2898
|
+
const hollow = `fill="${paper}" stroke="${stroke}" stroke-width="${sw}" stroke-linejoin="round"`;
|
|
2899
|
+
const bar = (b) => `<path d="M ${at(b, 6)} L ${at(b, -6)}" ${line}/>`;
|
|
2900
|
+
const ring = (b, r, a) => `<circle cx="${r2(tip.x - ux * b)}" cy="${r2(tip.y - uy * b)}" r="${r}" ${a}/>`;
|
|
2901
|
+
const crow = `<path d="M ${at(0, 6)} L ${at(12, 0)} L ${at(0, -6)}" ${line}/>`;
|
|
2902
|
+
if (R.amt && (kind === "arrow" || kind === "open")) {
|
|
2903
|
+
const b = 13, w = 6;
|
|
2904
|
+
return { svg: sketchSvg(`M ${at(b, w)} L ${at(0, 0)} L ${at(b, -w)}`, `fill="none" stroke="${stroke}" stroke-width="${sw}"`, R.amt * 0.6), trim: 0 };
|
|
2905
|
+
}
|
|
2906
|
+
switch (kind) {
|
|
2907
|
+
case "none":
|
|
2908
|
+
return { svg: "", trim: 0 };
|
|
2909
|
+
case "open":
|
|
2910
|
+
return { svg: `<path d="M ${at(10, 5)} L ${at(0, 0)} L ${at(10, -5)}" ${line}/>`, trim: 0 };
|
|
2911
|
+
case "triangle":
|
|
2912
|
+
return { svg: `<polygon points="${at(0, 0)} ${at(11, 6)} ${at(11, -6)}" ${hollow}/>`, trim: 11 };
|
|
2913
|
+
case "diamond":
|
|
2914
|
+
return { svg: `<polygon points="${at(0, 0)} ${at(8, 4.5)} ${at(16, 0)} ${at(8, -4.5)}" ${hollow}/>`, trim: 16 };
|
|
2915
|
+
case "diamond-solid":
|
|
2916
|
+
return { svg: `<polygon points="${at(0, 0)} ${at(8, 4.5)} ${at(16, 0)} ${at(8, -4.5)}" fill="${stroke}" stroke="${stroke}" stroke-width="${sw}" stroke-linejoin="round"/>`, trim: 16 };
|
|
2917
|
+
case "dot":
|
|
2918
|
+
return { svg: ring(3.5, 3.5, `fill="${stroke}"`), trim: 3.5 };
|
|
2919
|
+
case "circle":
|
|
2920
|
+
return { svg: ring(4, 4, hollow), trim: 8 };
|
|
2921
|
+
case "one":
|
|
2922
|
+
return { svg: bar(8), trim: 0 };
|
|
2923
|
+
case "only-one":
|
|
2924
|
+
return { svg: bar(7) + bar(12), trim: 0 };
|
|
2925
|
+
case "many":
|
|
2926
|
+
return { svg: crow, trim: 0 };
|
|
2927
|
+
case "one-many":
|
|
2928
|
+
return { svg: crow + bar(16), trim: 0 };
|
|
2929
|
+
case "zero-one":
|
|
2930
|
+
return { svg: bar(8) + ring(16, 4, hollow), trim: 0 };
|
|
2931
|
+
case "zero-many":
|
|
2932
|
+
return { svg: crow + ring(17, 4, hollow), trim: 0 };
|
|
2933
|
+
default:
|
|
2934
|
+
return { svg: `<polygon points="${at(0, 0)} ${at(10, 4)} ${at(10, -4)}" fill="${stroke}"/>`, trim: 7 };
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
function backAlong(pts, dist) {
|
|
2938
|
+
let left = dist;
|
|
2939
|
+
for (let i = pts.length - 1; i > 0; i--) {
|
|
2940
|
+
const a = pts[i], b = pts[i - 1], l = Math.hypot(a.x - b.x, a.y - b.y);
|
|
2941
|
+
if (l >= left) return { x: a.x + (b.x - a.x) / l * left, y: a.y + (b.y - a.y) / l * left };
|
|
2942
|
+
left -= l;
|
|
2943
|
+
}
|
|
2944
|
+
return pts[0];
|
|
2945
|
+
}
|
|
2946
|
+
function cutEnd(pts, dist) {
|
|
2947
|
+
if (!dist) return pts;
|
|
2948
|
+
let left = dist;
|
|
2949
|
+
for (let i = pts.length - 1; i > 0; i--) {
|
|
2950
|
+
const a = pts[i], b = pts[i - 1], l = Math.hypot(a.x - b.x, a.y - b.y);
|
|
2951
|
+
if (l > left) return [...pts.slice(0, i), { x: a.x + (b.x - a.x) / l * left, y: a.y + (b.y - a.y) / l * left }];
|
|
2952
|
+
left -= l;
|
|
2953
|
+
}
|
|
2954
|
+
return pts.slice(0, 2);
|
|
2955
|
+
}
|
|
2956
|
+
function drawConn(look, c) {
|
|
2957
|
+
const p = c.p, sw = num2(p.sw, 1.2), stroke = col(look, p.stroke ?? "muted");
|
|
2958
|
+
const n = c.pts.length, paper = col(look, look.canvas.paper ?? "paper");
|
|
2959
|
+
const hFrom = c.curve ? backAlong(c.pts, 10) : c.pts[n - 2], tFrom = c.curve ? backAlong([...c.pts].reverse(), 10) : c.pts[1];
|
|
2960
|
+
const head = marker(c.headM, c.pts[n - 1], hFrom, sw, stroke, paper), tail = marker(c.tailM, c.pts[0], tFrom, sw, stroke, paper);
|
|
2961
|
+
const d = c.curve ? pathD(cutEnd(cutEnd(c.pts, head.trim).reverse(), tail.trim).reverse(), 0, 0, 0) : pathD(c.pts, c.ortho ? num2(p.radius, 8) : 0, head.trim, tail.trim);
|
|
2962
|
+
const a = `fill="none" stroke="${stroke}" stroke-width="${sw}"${p.dash && p.dash !== "none" ? ` stroke-dasharray="${esc(p.dash)}"` : ""}`;
|
|
2963
|
+
let s = roughOf(p) ? sketchSvg(d, a, roughOf(p)) : `<path d="${d}" ${a}/>`;
|
|
2964
|
+
if (head.svg) s += "\n" + head.svg;
|
|
2965
|
+
if (tail.svg) s += "\n" + tail.svg;
|
|
2966
|
+
return s;
|
|
2967
|
+
}
|
|
2968
|
+
function drawLabel(look, c) {
|
|
2969
|
+
const l = c.label;
|
|
2970
|
+
const paper = col(look, look.canvas.paper ?? "paper");
|
|
2971
|
+
const fill = col(look, c.p["label.color"] ?? c.p.stroke ?? "muted");
|
|
2972
|
+
return `<rect x="${r2(l.x)}" y="${r2(l.y)}" width="${l.w}" height="${l.h}" rx="2" fill="${paper}"/>
|
|
2973
|
+
<text x="${r2(l.cx)}" y="${r2(l.baseline)}" text-anchor="middle" font-family="${fam(look, l.font)}" font-size="${l.size}" fill="${fill}"${l.spacing ? ` letter-spacing="${r2(l.spacing * l.size)}"` : ""}>${esc(l.text)}</text>`;
|
|
2974
|
+
}
|
|
2975
|
+
function drawText(look, t) {
|
|
2976
|
+
const a = textAttrs(look, t.p, "", { font: "sans", size: 12, weight: 400, color: "ink" });
|
|
2977
|
+
const anchor = t.p.anchor && t.p.anchor !== "start" ? ` text-anchor="${esc(t.p.anchor)}"` : "";
|
|
2978
|
+
const rot = num2(t.p.rotate, 0);
|
|
2979
|
+
const body = t.text.split("\n").map((l, i) => `<text x="${t.ax}" y="${r2(t.ay + i * a.size * 1.3)}"${anchor} ${a.a}>${esc(l)}</text>`).join("\n");
|
|
2980
|
+
return rot === 90 || rot === -90 ? `<g transform="rotate(${rot} ${t.ax} ${t.ay})">${body}</g>` : body;
|
|
2981
|
+
}
|
|
2982
|
+
function renderBody(sc, background = true) {
|
|
2983
|
+
const look = sc.look, cv = look.canvas;
|
|
2984
|
+
const out = [];
|
|
2985
|
+
R = { amt: Math.max(0, Math.min(num2(cv.sketch, 0), 4)), defs: /* @__PURE__ */ new Map() };
|
|
2986
|
+
if (background) out.push(`<rect class="fd-page" x="${sc.x}" y="${sc.y}" width="${sc.w}" height="${sc.h}" fill="${col(look, cv.paper ?? "paper")}"/>`);
|
|
2987
|
+
if (background && cv.dots && cv.dots !== "none") {
|
|
2988
|
+
const gap = num2(cv.dotgap, 22);
|
|
2989
|
+
out.push(`<defs><pattern id="fd-dots" width="${gap}" height="${gap}" patternUnits="userSpaceOnUse"><circle cx="1" cy="1" r="0.9" fill="${col(look, cv.dots)}"/></pattern></defs>`);
|
|
2990
|
+
out.push(`<rect class="fd-page" x="${sc.x}" y="${sc.y}" width="${sc.w}" height="${sc.h}" fill="url(#fd-dots)"/>`);
|
|
2991
|
+
}
|
|
2992
|
+
for (const s of sc.shapes) if (s.back) out.push(drawShape(look, s));
|
|
2993
|
+
const under = sc.conns.filter((c) => c.p.layer !== "front"), over2 = sc.conns.filter((c) => c.p.layer === "front");
|
|
2994
|
+
for (const c of under) out.push(drawConn(look, c));
|
|
2995
|
+
for (const c of under) if (c.label) out.push(drawLabel(look, c));
|
|
2996
|
+
for (const s of sc.shapes) if (!s.back) out.push(drawShape(look, s));
|
|
2997
|
+
for (const c of over2) out.push(drawConn(look, c));
|
|
2998
|
+
for (const c of over2) if (c.label) out.push(drawLabel(look, c));
|
|
2999
|
+
for (const t of sc.texts) out.push(drawText(look, t));
|
|
3000
|
+
if (R.defs.size) out.splice(1, 0, `<defs>${hatchDefs()}</defs>`);
|
|
3001
|
+
return out.join("\n");
|
|
3002
|
+
}
|
|
3003
|
+
function renderSvg(sc, css, opts = {}) {
|
|
3004
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${sc.x} ${sc.y} ${sc.w} ${sc.h}" width="${sc.w}" height="${sc.h}">
|
|
3005
|
+
` + (css ? `<style>${css.replace(/&/g, "&").replace(/</g, "<")}</style>
|
|
3006
|
+
` : "") + renderBody(sc, opts.background ?? true) + "\n</svg>";
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
// src/check.ts
|
|
3010
|
+
var num3 = (v, d) => v === void 0 || v === "" || isNaN(+v) ? d : +v;
|
|
3011
|
+
var inter = (a, b, pad = 0) => a.x + pad < b.x + b.w && b.x + pad < a.x + a.w && a.y + pad < b.y + b.h && b.y + pad < a.y + a.h;
|
|
3012
|
+
var contains = (o, i) => i.x >= o.x && i.y >= o.y && i.x + i.w <= o.x + o.w && i.y + i.h <= o.y + o.h;
|
|
3013
|
+
var hasPt = (b, p) => p.x >= b.x && p.x <= b.x + b.w && p.y >= b.y && p.y <= b.y + b.h;
|
|
3014
|
+
var inset = (b, n) => ({ x: b.x + n, y: b.y + n, w: b.w - 2 * n, h: b.h - 2 * n });
|
|
3015
|
+
var name = (c) => c.id.startsWith("_") ? `${c.a.raw} ${c.head ? "->" : "--"} ${c.b.raw}` : c.id;
|
|
3016
|
+
var tiny = (s) => Math.min(s.w, s.h) <= 12;
|
|
3017
|
+
var isLine = (s) => !!s.poly && s.p.open === "1";
|
|
3018
|
+
function rgba(look, v) {
|
|
3019
|
+
const c = color(look, v);
|
|
3020
|
+
let m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(c);
|
|
3021
|
+
if (m) {
|
|
3022
|
+
const h = m[1].length === 3 ? m[1].split("").map((x) => x + x).join("") : m[1];
|
|
3023
|
+
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16), 1];
|
|
3024
|
+
}
|
|
3025
|
+
m = /^rgba\((\d+),(\d+),(\d+),([\d.]+)\)$/.exec(c);
|
|
3026
|
+
return m ? [+m[1], +m[2], +m[3], Math.min(1, +m[4])] : null;
|
|
3027
|
+
}
|
|
3028
|
+
var over = (top, under) => top ? [0, 1, 2].map((i) => top[i] * top[3] + under[i] * (1 - top[3])) : under;
|
|
3029
|
+
function contrast(a, b) {
|
|
3030
|
+
const lum = (c) => {
|
|
3031
|
+
const [r, g, bl] = c.map((v) => {
|
|
3032
|
+
const x = v / 255;
|
|
3033
|
+
return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
|
|
3034
|
+
});
|
|
3035
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * bl;
|
|
3036
|
+
};
|
|
3037
|
+
const la = lum(a), lb = lum(b);
|
|
3038
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
3039
|
+
}
|
|
3040
|
+
var FAINT = 1.8;
|
|
3041
|
+
function check(sc) {
|
|
3042
|
+
const out = [...sc.issues];
|
|
3043
|
+
const warn = (line, msg) => out.push({ line, level: "warn", msg });
|
|
3044
|
+
const hint = (line, msg) => out.push({ line, level: "hint", msg });
|
|
3045
|
+
const front = sc.shapes.filter((s) => !s.back);
|
|
3046
|
+
for (let i = 0; i < front.length; i++) for (let j = i + 1; j < front.length; j++) {
|
|
3047
|
+
const a = front[i], b = front[j];
|
|
3048
|
+
if (!inter(a, b, 0.5) || contains(a, b) || contains(b, a) || a.p.overlap === "ok" || b.p.overlap === "ok") continue;
|
|
3049
|
+
const ox = Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x), oy = Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y);
|
|
3050
|
+
warn(b.line, `${b.id} overlaps ${a.id} by ${Math.round(Math.min(ox, oy))}px; move one of them`);
|
|
3051
|
+
}
|
|
3052
|
+
const paperRgb = over(rgba(sc.look, sc.look.canvas.paper ?? "paper"), [255, 255, 255]);
|
|
3053
|
+
const fillOf = (s) => s.shape !== "icon" && s.p.fill && s.p.fill !== "none" && rgba(sc.look, s.p.fill) ? over(rgba(sc.look, s.p.fill), paperRgb) : null;
|
|
3054
|
+
for (const s of front) {
|
|
3055
|
+
if (s.rows || s.shape === "legend" || s.shape === "chart" || s.p["title.pos"] === "top") continue;
|
|
3056
|
+
const cxs = s.x + s.w / 2, cys = s.y + s.h / 2, at = sc.shapes.indexOf(s);
|
|
3057
|
+
const below = fillOf(s) ? void 0 : sc.shapes.slice(0, at).reverse().find((o) => !o.back && !o.rows && fillOf(o) && cxs >= o.x && cxs <= o.x + o.w && cys >= o.y && cys <= o.y + o.h);
|
|
3058
|
+
const bg = fillOf(s) ?? (below ? fillOf(below) : paperRgb);
|
|
3059
|
+
for (const [what, has, key, dflt] of [["text", s.text, "title.color", "ink"], ["second line", s.p.sub, "sub.color", "muted"]]) {
|
|
3060
|
+
const fg = rgba(sc.look, s.p[key] ?? dflt);
|
|
3061
|
+
if (has && fg && fg[3] > 0.3 && contrast(over(fg, bg), bg) < FAINT) warn(s.line, `the ${what} of ${s.id} is almost the same colour as its background and cannot be read; set ${key}= to a colour that stands out (on a dark or accent fill, #ffffff)`);
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
for (const t of sc.texts) {
|
|
3065
|
+
const mx = t.x + t.w / 2, my = t.y + t.h / 2;
|
|
3066
|
+
const under = [...sc.shapes].reverse().find((s) => !s.rows && s.shape !== "legend" && s.shape !== "chart" && fillOf(s) && mx >= s.x && mx <= s.x + s.w && my >= s.y && my <= s.y + s.h);
|
|
3067
|
+
const fg = rgba(sc.look, t.p.color ?? "ink");
|
|
3068
|
+
if (!fg || fg[3] <= 0.3) continue;
|
|
3069
|
+
const bg = under ? fillOf(under) : paperRgb;
|
|
3070
|
+
if (contrast(over(fg, bg), bg) < FAINT) warn(t.line, `text ${t.id} is almost the same colour as ${under ? under.id : "the paper"} behind it and cannot be read; change its color=`);
|
|
3071
|
+
}
|
|
3072
|
+
for (const s of front) {
|
|
3073
|
+
if (tiny(s)) continue;
|
|
3074
|
+
const off = s.shape !== "polygon" && [s.x, s.y, s.w, s.h].some((v) => v % 4 !== 0);
|
|
3075
|
+
if (off) hint(s.line, `${s.id} is off the 4px grid (${s.x},${s.y} ${s.w}x${s.h}); use multiples of 4`);
|
|
3076
|
+
if (s.shape === "icon") continue;
|
|
3077
|
+
const p = s.p;
|
|
3078
|
+
if (s.text && p["title.pos"] !== "top") {
|
|
3079
|
+
const size = num3(p["title.size"], 12), ib = iconBox(s), room = (s.shape === "diamond" || s.shape === "ellipse" ? s.w * 0.72 : s.w - 16) - (ib && ib.dx ? ib.size + 8 + 8 : 0);
|
|
3080
|
+
for (const l of s.text.split("\n")) {
|
|
3081
|
+
const tw = textWidth(l, size, p["title.font"] ?? "sans", num3(p["title.weight"], 600), num3(p["title.spacing"], 0));
|
|
3082
|
+
if (tw > room) warn(s.line, `text "${l}" (~${Math.round(tw)}px) does not fit in ${s.id} (${Math.round(room)}px of room); widen it or break the line with \\n`);
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
const ic = iconBox(s);
|
|
3086
|
+
if (ic && ic.dy > 0) {
|
|
3087
|
+
const lines = s.text ? s.text.split("\n").length : 0, subs = p.sub ? p.sub.split("\n").length : 0;
|
|
3088
|
+
const need = Math.ceil((lines * Math.round(num3(p["title.size"], 12) * 1.17) + (subs ? num3(p["sub.size"], 9) + 7 + (subs - 1) * Math.round(num3(p["sub.size"], 9) * 1.3) : 0) + ic.size + 6 + 16) / 4) * 4;
|
|
3089
|
+
if (s.h < need) warn(s.line, `the icon and text of ${s.id} need ${need}px of height; make it taller or use icon.pos=left`);
|
|
3090
|
+
} else if (ic && ic.size + 8 > Math.min(s.w, s.h) && s.style !== "icon") warn(s.line, `the ${ic.size}px icon does not fit in ${s.id}; make the box bigger or set icon.size=`);
|
|
3091
|
+
for (const l of p.sub ? p.sub.split("\n") : []) {
|
|
3092
|
+
const tw = textWidth(l, num3(p["sub.size"], 9), p["sub.font"] ?? "mono", 400, 0);
|
|
3093
|
+
if (tw > s.w - 12) warn(s.line, `sub text "${l}" (~${Math.round(tw)}px) does not fit in ${s.id} (${s.w - 12}px of room)`);
|
|
3094
|
+
}
|
|
3095
|
+
if (p.tag && (s.text || p.sub) && p["title.pos"] !== "top" && !s.rows && s.shape !== "chart") {
|
|
3096
|
+
const size = num3(p["title.size"], 12), block = textBlock(s, size);
|
|
3097
|
+
const fits = (h) => tagLayout({ ...s, h }, sc.look, block, size, s.y + h / 2).fits;
|
|
3098
|
+
let need = Math.ceil(s.h / 4) * 4;
|
|
3099
|
+
while (!fits(need) && need < s.h + 400) need += 4;
|
|
3100
|
+
if (!fits(s.h)) warn(s.line, `the tag "${p.tag}" sits on the text of ${s.id}; make it at least ${need}px tall or drop the tag`);
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3104
|
+
for (let i = 0; i < front.length; i++) for (let j = i + 1; j < front.length; j++) {
|
|
3105
|
+
const a = front[i], b = front[j];
|
|
3106
|
+
if (tiny(a) || tiny(b) || contains(a, b) || contains(b, a) || a.p.overlap === "ok" || b.p.overlap === "ok") continue;
|
|
3107
|
+
const pairs = [
|
|
3108
|
+
["top edges", a.y, b.y],
|
|
3109
|
+
["vertical centres", a.y + a.h / 2, b.y + b.h / 2],
|
|
3110
|
+
["left edges", a.x, b.x],
|
|
3111
|
+
["horizontal centres", a.x + a.w / 2, b.x + b.w / 2]
|
|
3112
|
+
];
|
|
3113
|
+
for (const [what, va, vb] of pairs) {
|
|
3114
|
+
const d = Math.abs(va - vb);
|
|
3115
|
+
if (d > 0 && d <= 3 && !seen.has(a.id + b.id)) {
|
|
3116
|
+
seen.add(a.id + b.id);
|
|
3117
|
+
hint(b.line, `${b.id} and ${a.id} have ${what} ${d}px apart; line them up?`);
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
for (const c of sc.conns) {
|
|
3122
|
+
const hit = /* @__PURE__ */ new Set();
|
|
3123
|
+
for (let i = 0; i < c.pts.length - 1; i++) {
|
|
3124
|
+
const A2 = c.pts[i], B = c.pts[i + 1];
|
|
3125
|
+
if (c.ortho && A2.x !== B.x && A2.y !== B.y) warn(c.line, `${name(c)} has a diagonal segment (${A2.x},${A2.y} to ${B.x},${B.y}); fix the via points so each step is horizontal or vertical`);
|
|
3126
|
+
for (const s of front) {
|
|
3127
|
+
if (c.p.layer === "back" || c.p.layer === "front") break;
|
|
3128
|
+
if (s.id === c.a.id || s.id === c.b.id || tiny(s) || hit.has(s.id) || isLine(s)) continue;
|
|
3129
|
+
if (hasPt(s, c.pts[0]) || hasPt(s, c.pts[c.pts.length - 1])) continue;
|
|
3130
|
+
if (segHits(A2, B, inset(s, 1))) {
|
|
3131
|
+
hit.add(s.id);
|
|
3132
|
+
warn(c.line, `${name(c)} passes through ${s.id}; route around it with from=/to= sides or via=x,y`);
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
const first = c.pts[0], last = c.pts[c.pts.length - 1];
|
|
3137
|
+
const l = c.label;
|
|
3138
|
+
if (!l) continue;
|
|
3139
|
+
for (const s of front) if (!tiny(s) && !isLine(s) && inter(l, s, 1)) warn(c.line, `label "${l.text}" of ${name(c)} collides with ${s.id}; shorten it, move things apart, or place it with lpos=x,y or lside=below|left`);
|
|
3140
|
+
for (const z of sc.shapes) {
|
|
3141
|
+
if (!z.back || !inter(l, z, 0) || contains(z, l)) continue;
|
|
3142
|
+
warn(c.line, `label "${l.text}" of ${name(c)} sits on the border of ${z.id}; place it on a clear stretch of the line with lpos=x,y`);
|
|
3143
|
+
}
|
|
3144
|
+
for (let i = 0; i < c.pts.length - 1; i++) {
|
|
3145
|
+
if (segHits(c.pts[i], c.pts[i + 1], inset(l, 1))) {
|
|
3146
|
+
warn(c.line, `label "${l.text}" of ${name(c)} sits on its own line; move it with lpos=x,y or lside=`);
|
|
3147
|
+
break;
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
for (const o of sc.conns) {
|
|
3151
|
+
if (o === c) continue;
|
|
3152
|
+
if (o.label && o.line > c.line && inter(l, o.label, 0)) warn(o.line, `labels "${o.label.text}" and "${l.text}" overlap; move one with lpos=x,y or lside=`);
|
|
3153
|
+
for (let i = 0; i < o.pts.length - 1; i++) {
|
|
3154
|
+
if (segHits(o.pts[i], o.pts[i + 1], inset(l, 1))) {
|
|
3155
|
+
warn(c.line, `label "${l.text}" of ${name(c)} sits on the line ${name(o)}; move it with lpos=x,y or lside=`);
|
|
3156
|
+
break;
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
const segLen = Math.max(...c.pts.slice(1).map((p, i) => Math.abs(p.x - c.pts[i].x) + Math.abs(p.y - c.pts[i].y)));
|
|
3161
|
+
const A = c.pts[0];
|
|
3162
|
+
if (!c.p.lpos && c.pts.every((p) => p.y === A.y) && l.w > segLen - 8) warn(c.line, `label "${l.text}" (${l.w}px) is wider than its line (${Math.round(segLen)}px); shorten the label or give the line more room`);
|
|
3163
|
+
}
|
|
3164
|
+
for (let i = 0; i < sc.conns.length; i++) for (let j = i + 1; j < sc.conns.length; j++) {
|
|
3165
|
+
const a = sc.conns[i], b = sc.conns[j];
|
|
3166
|
+
if (a.p.layer === "front" || b.p.layer === "front") continue;
|
|
3167
|
+
const same = (p, q) => p.x === q.x && p.y === q.y;
|
|
3168
|
+
if (same(a.pts[0], b.pts[0]) || same(a.pts[a.pts.length - 1], b.pts[b.pts.length - 1])) continue;
|
|
3169
|
+
let done = false;
|
|
3170
|
+
for (let m = 0; m < a.pts.length - 1 && !done; m++) for (let n = 0; n < b.pts.length - 1 && !done; n++) {
|
|
3171
|
+
const [A, B, C, D] = [a.pts[m], a.pts[m + 1], b.pts[n], b.pts[n + 1]];
|
|
3172
|
+
const ah = A.y === B.y, av = A.x === B.x, bh = C.y === D.y, bv = C.x === D.x;
|
|
3173
|
+
let ov = 0, gap = Infinity;
|
|
3174
|
+
if (ah && bh && !(av || bv)) {
|
|
3175
|
+
ov = Math.min(Math.max(A.x, B.x), Math.max(C.x, D.x)) - Math.max(Math.min(A.x, B.x), Math.min(C.x, D.x));
|
|
3176
|
+
gap = Math.abs(A.y - C.y);
|
|
3177
|
+
} else if (av && bv && !(ah || bh)) {
|
|
3178
|
+
ov = Math.min(Math.max(A.y, B.y), Math.max(C.y, D.y)) - Math.max(Math.min(A.y, B.y), Math.min(C.y, D.y));
|
|
3179
|
+
gap = Math.abs(A.x - C.x);
|
|
3180
|
+
}
|
|
3181
|
+
if (ov > 4 && gap < 1) {
|
|
3182
|
+
warn(b.line, `${name(b)} runs on top of ${name(a)} for ${Math.round(ov)}px; give them separate attach points (from=side@pos) or routes`);
|
|
3183
|
+
done = true;
|
|
3184
|
+
} else if (ov > 12 && gap < 8) {
|
|
3185
|
+
hint(b.line, `${name(b)} runs ${gap}px from ${name(a)}; keep parallel lines at least 12px apart`);
|
|
3186
|
+
done = true;
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
for (const t of sc.texts) {
|
|
3191
|
+
for (const s of front) if (!tiny(s) && s.shape !== "chart" && s.p.overlap !== "ok" && t.p.overlap !== "ok" && inter(t, s, 1) && !contains(s, t)) warn(t.line, `text ${t.id} overlaps ${s.id}`);
|
|
3192
|
+
for (const o of sc.texts) if (o.line > t.line && inter(t, o, 1) && t.p.overlap !== "ok" && o.p.overlap !== "ok") warn(o.line, `text ${o.id} overlaps text ${t.id}`);
|
|
3193
|
+
}
|
|
3194
|
+
if (sc.canvasSize && sc.canvasLine) hint(sc.canvasLine, "the canvas has no size any more: the picture is as big as what is drawn, plus a margin; remove WxH from this line");
|
|
3195
|
+
for (const i of out) i.msg = i.msg.replace(/(^|[\s("])_[stc](\d+)\b/g, "$1the unnamed element on line $2");
|
|
3196
|
+
const rank = { error: 0, warn: 1, hint: 2 };
|
|
3197
|
+
return out.sort((a, b) => rank[a.level] - rank[b.level] || a.line - b.line);
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
// src/serve.ts
|
|
3201
|
+
import { createServer } from "node:http";
|
|
3202
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync2, writeFileSync, statSync, lstatSync as lstatSync2, realpathSync as realpathSync2, existsSync as existsSync2 } from "node:fs";
|
|
3203
|
+
import { join, resolve as resolve2, sep as sep2, extname, dirname as dirname2 } from "node:path";
|
|
3204
|
+
import { randomBytes } from "node:crypto";
|
|
3205
|
+
var DEFAULT_EDITOR = "https://fastdraw.dev/edit/";
|
|
3206
|
+
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "bin", "obj", ".next", "target"]);
|
|
3207
|
+
var MAX_FILES = 2e3;
|
|
3208
|
+
var MAX_WRITE = 2 * 1024 * 1024;
|
|
3209
|
+
var WRITABLE = /* @__PURE__ */ new Set([".fdraw", ".look"]);
|
|
3210
|
+
var TYPES = {
|
|
3211
|
+
".fdraw": "text/plain; charset=utf-8",
|
|
3212
|
+
".look": "text/plain; charset=utf-8",
|
|
3213
|
+
".svg": "image/svg+xml",
|
|
3214
|
+
".png": "image/png",
|
|
3215
|
+
".ttf": "font/ttf",
|
|
3216
|
+
".otf": "font/otf",
|
|
3217
|
+
".txt": "text/plain; charset=utf-8"
|
|
3218
|
+
};
|
|
3219
|
+
function list(root2) {
|
|
3220
|
+
const out = [];
|
|
3221
|
+
const walk = (dir, prefix, depth) => {
|
|
3222
|
+
if (depth > 6) return;
|
|
3223
|
+
for (const d of readdirSync2(dir, { withFileTypes: true })) {
|
|
3224
|
+
if (out.length >= MAX_FILES || d.name.startsWith(".")) continue;
|
|
3225
|
+
const full = join(dir, d.name);
|
|
3226
|
+
if (d.isDirectory()) {
|
|
3227
|
+
if (!SKIP.has(d.name)) walk(full, prefix + d.name + "/", depth + 1);
|
|
3228
|
+
} else if (d.isFile()) {
|
|
3229
|
+
const s = statSync(full);
|
|
3230
|
+
out.push({ path: prefix + d.name, size: s.size, mtime: Math.floor(s.mtimeMs) });
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
};
|
|
3234
|
+
walk(root2, "", 0);
|
|
3235
|
+
return out;
|
|
3236
|
+
}
|
|
3237
|
+
function inside2(root2, rel) {
|
|
3238
|
+
const parts = rel.split("/").map((p) => {
|
|
3239
|
+
try {
|
|
3240
|
+
return decodeURIComponent(p);
|
|
3241
|
+
} catch {
|
|
3242
|
+
return "\0";
|
|
3243
|
+
}
|
|
3244
|
+
});
|
|
3245
|
+
if (!parts.length || parts.some((p) => !p || p.startsWith(".") || p.includes("\0") || p.includes("\\") || p.includes(sep2))) return null;
|
|
3246
|
+
const full = resolve2(root2, ...parts);
|
|
3247
|
+
if (!full.startsWith(root2 + sep2)) return null;
|
|
3248
|
+
try {
|
|
3249
|
+
const parent = realpathSync2(dirname2(full));
|
|
3250
|
+
if (parent !== root2 && !parent.startsWith(root2 + sep2)) return null;
|
|
3251
|
+
if (existsSync2(full) && !realpathSync2(full).startsWith(root2 + sep2)) return null;
|
|
3252
|
+
} catch {
|
|
3253
|
+
return null;
|
|
3254
|
+
}
|
|
3255
|
+
return full;
|
|
3256
|
+
}
|
|
3257
|
+
function serveFolder(folder, opts = {}) {
|
|
3258
|
+
const root2 = realpathSync2(resolve2(folder));
|
|
3259
|
+
const editor = new URL(opts.editor ?? DEFAULT_EDITOR);
|
|
3260
|
+
const allowed = editor.origin;
|
|
3261
|
+
const token = randomBytes(18).toString("base64url");
|
|
3262
|
+
const prefix = `/${token}/`;
|
|
3263
|
+
const handle = (req, res) => {
|
|
3264
|
+
const origin = req.headers.origin;
|
|
3265
|
+
const send = (status, body = "", headers = {}) => {
|
|
3266
|
+
res.writeHead(status, { "Cache-Control": "no-store", ...headers });
|
|
3267
|
+
res.end(body);
|
|
3268
|
+
};
|
|
3269
|
+
if (origin !== void 0 && origin !== allowed) return send(403, "not this origin");
|
|
3270
|
+
if (origin) {
|
|
3271
|
+
res.setHeader("Access-Control-Allow-Origin", origin);
|
|
3272
|
+
res.setHeader("Vary", "Origin");
|
|
3273
|
+
res.setHeader("Access-Control-Expose-Headers", "X-Mtime");
|
|
3274
|
+
}
|
|
3275
|
+
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
3276
|
+
if (!url.pathname.startsWith(prefix)) return send(404);
|
|
3277
|
+
const rest = url.pathname.slice(prefix.length);
|
|
3278
|
+
if (req.method === "OPTIONS") {
|
|
3279
|
+
return send(204, "", {
|
|
3280
|
+
"Access-Control-Allow-Methods": "GET, PUT",
|
|
3281
|
+
"Access-Control-Allow-Headers": "Content-Type",
|
|
3282
|
+
"Access-Control-Allow-Private-Network": "true",
|
|
3283
|
+
"Access-Control-Max-Age": "600"
|
|
3284
|
+
});
|
|
3285
|
+
}
|
|
3286
|
+
if (rest === "list" && req.method === "GET") return send(200, JSON.stringify({ files: list(root2) }), { "Content-Type": "application/json" });
|
|
3287
|
+
if (!rest.startsWith("f/")) return send(404);
|
|
3288
|
+
const file = inside2(root2, rest.slice(2));
|
|
3289
|
+
if (!file) return send(403, "outside the folder");
|
|
3290
|
+
if (req.method === "GET") {
|
|
3291
|
+
try {
|
|
3292
|
+
const s = statSync(file);
|
|
3293
|
+
if (!s.isFile()) return send(404);
|
|
3294
|
+
return send(200, readFileSync2(file), { "Content-Type": TYPES[extname(file).toLowerCase()] ?? "application/octet-stream", "X-Mtime": String(Math.floor(s.mtimeMs)) });
|
|
3295
|
+
} catch {
|
|
3296
|
+
return send(404);
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
if (req.method === "PUT") {
|
|
3300
|
+
if (!WRITABLE.has(extname(file).toLowerCase())) return send(403, "only .fdraw and .look files are written");
|
|
3301
|
+
try {
|
|
3302
|
+
if (lstatSync2(file).isSymbolicLink()) return send(403, "not written through a link");
|
|
3303
|
+
} catch {
|
|
3304
|
+
}
|
|
3305
|
+
const chunks = [];
|
|
3306
|
+
let size = 0;
|
|
3307
|
+
req.on("data", (c) => {
|
|
3308
|
+
size += c.length;
|
|
3309
|
+
if (size <= MAX_WRITE) chunks.push(c);
|
|
3310
|
+
});
|
|
3311
|
+
req.on("end", () => {
|
|
3312
|
+
if (size > MAX_WRITE) return send(413, "too large");
|
|
3313
|
+
try {
|
|
3314
|
+
writeFileSync(file, Buffer.concat(chunks));
|
|
3315
|
+
const mtime = Math.floor(statSync(file).mtimeMs);
|
|
3316
|
+
send(200, JSON.stringify({ mtime }), { "Content-Type": "application/json", "X-Mtime": String(mtime) });
|
|
3317
|
+
} catch (e) {
|
|
3318
|
+
send(500, e.message);
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3321
|
+
return;
|
|
3322
|
+
}
|
|
3323
|
+
send(405);
|
|
3324
|
+
};
|
|
3325
|
+
return new Promise((ok, fail) => {
|
|
3326
|
+
const server = createServer(handle);
|
|
3327
|
+
server.on("error", fail);
|
|
3328
|
+
server.listen(opts.port ?? 0, "127.0.0.1", () => {
|
|
3329
|
+
const port = server.address().port;
|
|
3330
|
+
const base = `http://127.0.0.1:${port}/${token}`;
|
|
3331
|
+
const open = new URL(editor);
|
|
3332
|
+
open.searchParams.set("serve", base);
|
|
3333
|
+
if (opts.open) open.searchParams.set("open", opts.open);
|
|
3334
|
+
ok({ url: open.href, base, port, close: () => new Promise((done) => {
|
|
3335
|
+
server.closeAllConnections();
|
|
3336
|
+
server.close(() => done());
|
|
3337
|
+
}) });
|
|
3338
|
+
});
|
|
3339
|
+
});
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3342
|
+
// src/cli.ts
|
|
3343
|
+
import { spawn } from "node:child_process";
|
|
3344
|
+
|
|
3345
|
+
// src/sizes.ts
|
|
3346
|
+
function sizesReport(look, missingFonts = []) {
|
|
3347
|
+
const out = [];
|
|
3348
|
+
for (const i of look.issues) out.push(`look:${i.line} ${i.level} ${i.msg}`);
|
|
3349
|
+
const rows = [...look.styles.values()];
|
|
3350
|
+
for (const kind of ["shape", "line", "text"]) {
|
|
3351
|
+
out.push(`
|
|
3352
|
+
${kind} styles`);
|
|
3353
|
+
for (const s of rows.filter((r) => r.kind === kind)) {
|
|
3354
|
+
const p = s.props;
|
|
3355
|
+
const bits = [];
|
|
3356
|
+
if (kind === "shape") bits.push(`shape=${p.shape ?? "rect"}`, p.shape === "table" ? "sizes itself from its rows" : p.shape === "polygon" ? "sized by its points" : p.shape === "chart" ? "always give WxH: the plot area" : p.size ? `default size ${p.size}` : "no default size: always give WxH", p.layer === "back" ? "drawn behind everything" : "");
|
|
3357
|
+
if (kind === "line") bits.push(`route=${p.route ?? "ortho"}`, p.dash ? `dash=${p.dash}` : "solid", `stroke=${p.stroke ?? "muted"}`);
|
|
3358
|
+
if (kind === "text") bits.push(`font=${p.font ?? "sans"}`, `size=${p.size ?? 12}`, p.caps === "1" ? "caps" : "");
|
|
3359
|
+
if (p.use) bits.push(`use: ${p.use}`);
|
|
3360
|
+
out.push(` ${s.name.padEnd(12)} ${bits.filter(Boolean).join(" \xB7 ")}`);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
out.push("\nfonts");
|
|
3364
|
+
for (const [role, fam2] of look.fonts) out.push(` ${role.padEnd(12)} ${fam2}${missingFonts.includes(fam2) ? " (no font file found: will fall back)" : ""}`);
|
|
3365
|
+
const own = [...look.images.keys()];
|
|
3366
|
+
if (own.length) out.push(`
|
|
3367
|
+
icons from the look's folders (${own.length}; "fastdraw icons <look> [word]" lists or searches them)
|
|
3368
|
+
${own.slice(0, 60).join(", ")}${own.length > 60 ? ", ..." : ""}`);
|
|
3369
|
+
out.push(`
|
|
3370
|
+
${own.length ? "built-in outline icons" : "icons"} (icon=name on any box, or a box of style "icon")
|
|
3371
|
+
${[...look.icons.keys()].join(", ")}`);
|
|
3372
|
+
if (look.guidance.length) {
|
|
3373
|
+
out.push("\nguidance from this look");
|
|
3374
|
+
for (const g of look.guidance) out.push(` - ${g}`);
|
|
3375
|
+
}
|
|
3376
|
+
return out.join("\n");
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
// src/setup.ts
|
|
3380
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, existsSync as existsSync3, mkdirSync, realpathSync as realpathSync3, lstatSync as lstatSync3 } from "node:fs";
|
|
3381
|
+
import { join as join2, relative as relative2, sep as sep3 } from "node:path";
|
|
3382
|
+
import { homedir } from "node:os";
|
|
3383
|
+
var TARGETS = ["claude", "agents", "copilot"];
|
|
3384
|
+
var START = "<!-- fastdraw:start -->";
|
|
3385
|
+
var END = "<!-- fastdraw:end -->";
|
|
3386
|
+
function snippet(root2) {
|
|
3387
|
+
return readFileSync3(join2(root2, "agents", "AGENTS-snippet.md"), "utf8").replace(/^<!--.*?-->\s*/s, "").trim();
|
|
3388
|
+
}
|
|
3389
|
+
function prepare(base, file) {
|
|
3390
|
+
const refuse = () => {
|
|
3391
|
+
throw new Error(`not writing ${file}: it is a link, or leads outside ${base}`);
|
|
3392
|
+
};
|
|
3393
|
+
const top = realpathSync3(base);
|
|
3394
|
+
const parts = relative2(base, file).split(sep3);
|
|
3395
|
+
if (!parts.length || parts.includes("..")) refuse();
|
|
3396
|
+
let at = base;
|
|
3397
|
+
for (let i = 0; i < parts.length; i++) {
|
|
3398
|
+
at = join2(at, parts[i]);
|
|
3399
|
+
let st;
|
|
3400
|
+
try {
|
|
3401
|
+
st = lstatSync3(at);
|
|
3402
|
+
} catch {
|
|
3403
|
+
st = null;
|
|
3404
|
+
}
|
|
3405
|
+
if (st?.isSymbolicLink()) refuse();
|
|
3406
|
+
if (st && i < parts.length - 1) {
|
|
3407
|
+
const real = realpathSync3(at);
|
|
3408
|
+
if (!st.isDirectory() || real !== top && !real.startsWith(top + sep3)) refuse();
|
|
3409
|
+
}
|
|
3410
|
+
if (!st && i < parts.length - 1) mkdirSync(at);
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
function upsert(base, file, body) {
|
|
3414
|
+
const block = `${START}
|
|
3415
|
+
${body}
|
|
3416
|
+
${END}`;
|
|
3417
|
+
prepare(base, file);
|
|
3418
|
+
if (!existsSync3(file)) {
|
|
3419
|
+
writeFileSync2(file, block + "\n");
|
|
3420
|
+
return "created";
|
|
3421
|
+
}
|
|
3422
|
+
const text = readFileSync3(file, "utf8");
|
|
3423
|
+
const a = text.indexOf(START), b = text.indexOf(END);
|
|
3424
|
+
if (a >= 0 && b > a) {
|
|
3425
|
+
writeFileSync2(file, text.slice(0, a) + block + text.slice(b + END.length));
|
|
3426
|
+
return "updated";
|
|
3427
|
+
}
|
|
3428
|
+
writeFileSync2(file, text.replace(/\s*$/, "") + "\n\n" + block + "\n");
|
|
3429
|
+
return "added to";
|
|
3430
|
+
}
|
|
3431
|
+
function detect(dir) {
|
|
3432
|
+
const found = [];
|
|
3433
|
+
if (existsSync3(join2(dir, ".claude")) || existsSync3(join2(dir, "CLAUDE.md"))) found.push("claude");
|
|
3434
|
+
if (existsSync3(join2(dir, "AGENTS.md"))) found.push("agents");
|
|
3435
|
+
if (existsSync3(join2(dir, ".github", "copilot-instructions.md"))) found.push("copilot");
|
|
3436
|
+
return found.length ? found : ["claude", "agents"];
|
|
3437
|
+
}
|
|
3438
|
+
function setup(root2, dir, targets, global = false) {
|
|
3439
|
+
const lines = [];
|
|
3440
|
+
const show = (f) => f.startsWith(dir) ? relative2(dir, f) : f.replace(homedir(), "~");
|
|
3441
|
+
for (const t of targets) {
|
|
3442
|
+
if (t === "claude") {
|
|
3443
|
+
const base = global ? join2(homedir(), ".claude") : dir;
|
|
3444
|
+
const file = join2(global ? base : join2(dir, ".claude"), "skills", "fastdraw", "SKILL.md");
|
|
3445
|
+
const was = existsSync3(file);
|
|
3446
|
+
if (global) mkdirSync(base, { recursive: true });
|
|
3447
|
+
prepare(base, file);
|
|
3448
|
+
writeFileSync2(file, readFileSync3(join2(root2, "agents", "claude-skill", "fastdraw", "SKILL.md"), "utf8"));
|
|
3449
|
+
lines.push(`${was ? "updated" : "wrote"} ${show(file)} (Claude Code skill)`);
|
|
3450
|
+
} else {
|
|
3451
|
+
const file = t === "agents" ? join2(dir, "AGENTS.md") : join2(dir, ".github", "copilot-instructions.md");
|
|
3452
|
+
lines.push(`${upsert(dir, file, snippet(root2))} ${show(file)} (${t === "agents" ? "Codex, OpenCode and other agents that read AGENTS.md" : "GitHub Copilot"})`);
|
|
3453
|
+
}
|
|
3454
|
+
}
|
|
3455
|
+
return lines;
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
// src/cli.ts
|
|
3459
|
+
var root = resolve3(dirname4(fileURLToPath2(import.meta.url)), "..");
|
|
3460
|
+
var [cmd, ...args] = process.argv.slice(2);
|
|
3461
|
+
function usage() {
|
|
3462
|
+
console.log(`fastdraw <command>
|
|
3463
|
+
|
|
3464
|
+
check <file.fdraw> report problems, with line numbers
|
|
3465
|
+
render <file.fdraw> [-o out.png|.svg] [--scale 2] [--transparent] [--no-embed]
|
|
3466
|
+
draw the diagram (PNG by default)
|
|
3467
|
+
sizes [file.fdraw | file.look] list the look's styles and their sizes
|
|
3468
|
+
(the built-in look when no file is given)
|
|
3469
|
+
init-look [path] write the built-in look to a file to make your own
|
|
3470
|
+
preview-look [file.look] [-o out.png] draw every style of a look on one sheet
|
|
3471
|
+
icons [file.look] [word] list the icons a look offers, or search them
|
|
3472
|
+
open <file.fdraw> [--editor URL] [--no-browser]
|
|
3473
|
+
open the diagram in the web editor (${DEFAULT_EDITOR}) with its
|
|
3474
|
+
look, fonts and icons; edits there save back to the file.
|
|
3475
|
+
Keeps running while you edit; Ctrl-C stops it
|
|
3476
|
+
guide [topic] print the language guide, or the guide for one kind of diagram
|
|
3477
|
+
guide list list the kinds of diagram that have a guide
|
|
3478
|
+
setup [claude|agents|copilot ...] [--global]
|
|
3479
|
+
tell this repo's coding agents about FastDraw: a Claude Code
|
|
3480
|
+
skill, a section in AGENTS.md, or in Copilot's instructions.
|
|
3481
|
+
With no name, sets up the agents the repo already uses.
|
|
3482
|
+
--global puts the Claude Code skill in ~/.claude for every repo`);
|
|
3483
|
+
process.exit(2);
|
|
3484
|
+
}
|
|
3485
|
+
function report(file) {
|
|
3486
|
+
const sc = loadScene(file);
|
|
3487
|
+
const issues = check(sc);
|
|
3488
|
+
for (const i of issues) console.log(`${basename(file)}:${i.line} ${i.level.padEnd(5)} ${i.msg}`);
|
|
3489
|
+
const errors = issues.filter((i) => i.level === "error").length;
|
|
3490
|
+
const warns = issues.filter((i) => i.level === "warn").length;
|
|
3491
|
+
const hints = issues.length - errors - warns;
|
|
3492
|
+
console.log(issues.length ? `
|
|
3493
|
+
${errors} error(s), ${warns} warning(s), ${hints} hint(s)` : "ok: no problems found");
|
|
3494
|
+
return { errors, warns };
|
|
3495
|
+
}
|
|
3496
|
+
if (cmd === "check") {
|
|
3497
|
+
if (!args[0]) usage();
|
|
3498
|
+
process.exit(report(args[0]).errors ? 1 : 0);
|
|
3499
|
+
} else if (cmd === "render") {
|
|
3500
|
+
const file = args.find((a, i) => !a.startsWith("-") && args[i - 1] !== "-o" && args[i - 1] !== "--scale");
|
|
3501
|
+
if (!file) usage();
|
|
3502
|
+
const oi = args.indexOf("-o"), si = args.indexOf("--scale");
|
|
3503
|
+
const out = oi >= 0 ? args[oi + 1] : file.replace(/\.fdraw$/, "") + ".png";
|
|
3504
|
+
const scale = si >= 0 ? +args[si + 1] : 2;
|
|
3505
|
+
const sc = loadScene(file);
|
|
3506
|
+
const errors = sc.issues.filter((i) => i.level === "error");
|
|
3507
|
+
if (errors.length) {
|
|
3508
|
+
for (const i of errors) console.log(`${basename(file)}:${i.line} error ${i.msg}`);
|
|
3509
|
+
console.log("\nnot rendered: fix the errors first");
|
|
3510
|
+
process.exit(1);
|
|
3511
|
+
}
|
|
3512
|
+
if (!(scale > 0)) {
|
|
3513
|
+
console.log("--scale takes a number above 0, like 1, 2 or 3");
|
|
3514
|
+
process.exit(1);
|
|
3515
|
+
}
|
|
3516
|
+
const transparent = args.includes("--transparent"), embed = !args.includes("--no-embed");
|
|
3517
|
+
const svg = renderSvg(sc, void 0, { background: !transparent });
|
|
3518
|
+
const payload = { v: 1, ...readSources(file, sc) };
|
|
3519
|
+
if (out.endsWith(".svg")) writeFileSync3(out, embed ? embedSvg(svg, payload) : svg);
|
|
3520
|
+
else {
|
|
3521
|
+
const { Resvg } = await import("@resvg/resvg-js");
|
|
3522
|
+
const fontFiles = [...bundledFonts(), ...sc.fontFiles ?? []];
|
|
3523
|
+
const png = new Uint8Array(new Resvg(svg, { font: { fontFiles, loadSystemFonts: true, defaultFontFamily: "Geist" }, fitTo: { mode: "zoom", value: scale } }).render().asPng());
|
|
3524
|
+
writeFileSync3(out, embed ? embedPng(png, payload) : png);
|
|
3525
|
+
}
|
|
3526
|
+
const notes = [out.endsWith(".svg") ? "" : `at ${scale}x`, transparent ? "no background" : "", embed ? "" : "no diagram inside"].filter(Boolean);
|
|
3527
|
+
console.log(`wrote ${out} (${sc.w}x${sc.h}${notes.length ? ", " + notes.join(", ") : ""})`);
|
|
3528
|
+
} else if (cmd === "sizes") {
|
|
3529
|
+
const look = !args[0] ? defaultLook() : args[0].endsWith(".look") ? loadLook(args[0]) : loadScene(args[0]).look;
|
|
3530
|
+
const lf = lookFonts(!args[0] ? void 0 : args[0].endsWith(".look") ? args[0] : lookFileOf(args[0]), look);
|
|
3531
|
+
console.log(sizesReport(look, lf.missing));
|
|
3532
|
+
} else if (cmd === "init-look") {
|
|
3533
|
+
const out = args[0] ?? "team.look";
|
|
3534
|
+
if (existsSync4(out)) {
|
|
3535
|
+
console.log(`${out} already exists; choose another path or remove it first`);
|
|
3536
|
+
process.exit(1);
|
|
3537
|
+
}
|
|
3538
|
+
writeFileSync3(out, DEFAULT_LOOK);
|
|
3539
|
+
console.log(`wrote ${out}. Point a diagram at it with: look "./${basename(out)}"`);
|
|
3540
|
+
} else if (cmd === "preview-look") {
|
|
3541
|
+
const file = args.find((a, i) => !a.startsWith("-") && args[i - 1] !== "-o");
|
|
3542
|
+
const oi = args.indexOf("-o");
|
|
3543
|
+
const out = oi >= 0 ? args[oi + 1] : (file ? file.replace(/\.look$/, "") : "default") + "-preview.png";
|
|
3544
|
+
const look = file ? loadLook(file) : defaultLook();
|
|
3545
|
+
const errs = look.issues.filter((i) => i.level === "error");
|
|
3546
|
+
if (errs.length) {
|
|
3547
|
+
for (const i of errs) console.log(`${file}:${i.line} error ${i.msg}`);
|
|
3548
|
+
process.exit(1);
|
|
3549
|
+
}
|
|
3550
|
+
const skip = /* @__PURE__ */ new Set(["rect", "ellipse", "diamond", "polygon", "freehand", "arc", "icon", "text", "line", "legend"]);
|
|
3551
|
+
const all = [...look.styles.values()].filter((s) => !skip.has(s.name));
|
|
3552
|
+
const L = [];
|
|
3553
|
+
const W = 880;
|
|
3554
|
+
let y = 40;
|
|
3555
|
+
const heading = (t) => {
|
|
3556
|
+
L.push(`text ${JSON.stringify(t)} at 40,${y + 10} size=11 weight=600 color=muted font=sans`);
|
|
3557
|
+
y += 28;
|
|
3558
|
+
};
|
|
3559
|
+
heading("Shapes");
|
|
3560
|
+
let x = 40, rowH = 0;
|
|
3561
|
+
all.filter((s) => s.kind === "shape").forEach((s, i) => {
|
|
3562
|
+
const m = /^(\d+(?:\.\d+)?)x(\d+(?:\.\d+)?)$/.exec(s.props.size ?? "");
|
|
3563
|
+
const table2 = s.props.shape === "table";
|
|
3564
|
+
const w = table2 ? 160 : m ? +m[1] : 144, h = table2 ? 104 : m ? +m[2] : 64;
|
|
3565
|
+
const cell = Math.max(w, 144) + 40;
|
|
3566
|
+
if (x + cell > W + 40) {
|
|
3567
|
+
x = 40;
|
|
3568
|
+
y += rowH + 44;
|
|
3569
|
+
rowH = 0;
|
|
3570
|
+
}
|
|
3571
|
+
const narrow = w <= 12, back = s.props.layer === "back";
|
|
3572
|
+
if (s.props.shape === "chart") {
|
|
3573
|
+
if (x + 280 > W + 40) {
|
|
3574
|
+
x = 40;
|
|
3575
|
+
y += rowH + 44;
|
|
3576
|
+
rowH = 0;
|
|
3577
|
+
}
|
|
3578
|
+
L.push(`p${i}: ${s.name} ${JSON.stringify(s.name)} at ${x + 32},${y + 28} 200x100 x="A,B,C,D"
|
|
3579
|
+
| bars "one" 30 50 40 70
|
|
3580
|
+
| line "two" 40 45 55 60`);
|
|
3581
|
+
x += 280;
|
|
3582
|
+
rowH = Math.max(rowH, 148);
|
|
3583
|
+
return;
|
|
3584
|
+
}
|
|
3585
|
+
if (table2) {
|
|
3586
|
+
const grid = s.props.align === "center";
|
|
3587
|
+
L.push(`p${i}: ${s.name} ${JSON.stringify(s.name)} at ${x},${y} 160x0
|
|
3588
|
+
${grid ? '|= "" "A" "B"' : '| "id" "uuid" "PK"'}
|
|
3589
|
+
| "name" ${grid ? '"yes" "no"' : '"text" ""'}
|
|
3590
|
+
| "more" ${grid ? '"no" "yes"' : '"int" ""'}`);
|
|
3591
|
+
x += cell;
|
|
3592
|
+
rowH = Math.max(rowH, h);
|
|
3593
|
+
return;
|
|
3594
|
+
}
|
|
3595
|
+
L.push(`p${i}: ${s.name} ${narrow ? "" : JSON.stringify(s.name)} at ${x},${y} ${w}x${h}${narrow || back || s.props.shape === "diamond" ? "" : ' sub="second line" tag="TAG"' + (i < 2 ? ` ghost="0${i + 1}"` : "")}`);
|
|
3596
|
+
if (narrow) L.push(`text ${JSON.stringify(s.name)} at ${x + 20},${y + 14} size=10 color=muted font=sans`);
|
|
3597
|
+
x += cell;
|
|
3598
|
+
rowH = Math.max(rowH, h);
|
|
3599
|
+
});
|
|
3600
|
+
y += rowH + 48;
|
|
3601
|
+
heading("Lines and arrows");
|
|
3602
|
+
all.filter((s) => s.kind === "line").forEach((s, i) => {
|
|
3603
|
+
const cx2 = 40 + i % 4 * 216;
|
|
3604
|
+
if (i && i % 4 === 0) y += 44;
|
|
3605
|
+
L.push(`${cx2},${y + 16} ${s.props.head === "none" || s.props.route === "straight" ? "--" : "->"} ${cx2 + 176},${y + 16} ${JSON.stringify(s.name)} style=${s.name}`);
|
|
3606
|
+
});
|
|
3607
|
+
y += 60;
|
|
3608
|
+
heading("Icons");
|
|
3609
|
+
[...look.icons.keys()].forEach((n, i) => {
|
|
3610
|
+
const cx2 = 40 + i % 11 * 80;
|
|
3611
|
+
if (i && i % 11 === 0) y += 60;
|
|
3612
|
+
L.push(`icon at ${cx2 + 20},${y} icon=${n}`);
|
|
3613
|
+
L.push(`text ${JSON.stringify(n)} at ${cx2 + 32},${y + 40} size=8 color=muted font=sans anchor=middle`);
|
|
3614
|
+
});
|
|
3615
|
+
y += 76;
|
|
3616
|
+
heading("Text");
|
|
3617
|
+
for (const s of all.filter((t) => t.kind === "text")) {
|
|
3618
|
+
const size = +(s.props.size ?? 12);
|
|
3619
|
+
y += Math.max(size, 10) + 4;
|
|
3620
|
+
L.push(`text ${JSON.stringify(`${s.name}: The quick brown fox`)} at 40,${y} style=${s.name}`);
|
|
3621
|
+
y += 12;
|
|
3622
|
+
}
|
|
3623
|
+
y += 32;
|
|
3624
|
+
const entries = all.filter((s) => s.kind !== "text").slice(0, 8).map((s) => `${s.name}=${JSON.stringify(s.name)}`).join(" ");
|
|
3625
|
+
L.push(`legend at 40,${y} ${W}x10 ${entries}`);
|
|
3626
|
+
const sc = buildScene(L.join("\n"), look);
|
|
3627
|
+
const bad = sc.issues.filter((i) => i.level === "error");
|
|
3628
|
+
if (bad.length) {
|
|
3629
|
+
for (const i of bad) console.log(`preview: ${i.msg}`);
|
|
3630
|
+
process.exit(1);
|
|
3631
|
+
}
|
|
3632
|
+
const svg = renderSvg(sc);
|
|
3633
|
+
if (out.endsWith(".svg")) writeFileSync3(out, svg);
|
|
3634
|
+
else {
|
|
3635
|
+
const { Resvg } = await import("@resvg/resvg-js");
|
|
3636
|
+
const lf = lookFonts(file, look);
|
|
3637
|
+
for (const fam2 of lf.missing) console.log(`warning: no font file found for "${fam2}"; it will be drawn in a fallback font`);
|
|
3638
|
+
const fontFiles = [...bundledFonts(), ...lf.files];
|
|
3639
|
+
writeFileSync3(out, new Resvg(svg, { font: { fontFiles, loadSystemFonts: true, defaultFontFamily: "Geist" }, fitTo: { mode: "zoom", value: 2 } }).render().asPng());
|
|
3640
|
+
}
|
|
3641
|
+
console.log(`wrote ${out}: ${all.length} styles`);
|
|
3642
|
+
} else if (cmd === "icons") {
|
|
3643
|
+
const file = args[0]?.endsWith(".look") ? args[0] : void 0, word = (file ? args[1] : args[0])?.toLowerCase();
|
|
3644
|
+
const look = file ? loadLook(file) : defaultLook();
|
|
3645
|
+
const names = [.../* @__PURE__ */ new Set([...look.images.keys(), ...look.icons.keys()])].filter((n) => !word || iconMatches(n, word));
|
|
3646
|
+
console.log(names.length ? names.join("\n") : `no icon${word ? ` for "${word}"` : ""}`);
|
|
3647
|
+
} else if (cmd === "guide") {
|
|
3648
|
+
const topic = args[0];
|
|
3649
|
+
const file = join3(root, "guide", topic ? `${topic}.md` : "guide.md");
|
|
3650
|
+
const topics = readdirSync3(join3(root, "guide")).filter((f) => f.endsWith(".md") && f !== "guide.md").map((f) => f.slice(0, -3)).sort();
|
|
3651
|
+
if (topic === "list") {
|
|
3652
|
+
console.log(topics.join("\n"));
|
|
3653
|
+
process.exit(0);
|
|
3654
|
+
}
|
|
3655
|
+
if (!existsSync4(file) || /[\\/]/.test(topic ?? "")) {
|
|
3656
|
+
console.log(`no guide called "${topic}". Topics: ${topics.join(", ")}`);
|
|
3657
|
+
process.exit(1);
|
|
3658
|
+
}
|
|
3659
|
+
console.log(readFileSync4(file, "utf8"));
|
|
3660
|
+
} else if (cmd === "open") {
|
|
3661
|
+
const file = args.find((a, i) => !a.startsWith("--") && args[i - 1] !== "--editor");
|
|
3662
|
+
if (!file || !file.endsWith(".fdraw") || !existsSync4(file)) usage();
|
|
3663
|
+
const ei = args.indexOf("--editor");
|
|
3664
|
+
const editor = ei >= 0 ? args[ei + 1] : process.env.FASTDRAW_EDITOR ?? DEFAULT_EDITOR;
|
|
3665
|
+
const s = await serveFolder(dirname4(resolve3(file)), { editor, open: basename(file) });
|
|
3666
|
+
console.log(`serving ${dirname4(resolve3(file))} to the editor until this stops (Ctrl-C)
|
|
3667
|
+
${s.url}`);
|
|
3668
|
+
if (!args.includes("--no-browser")) {
|
|
3669
|
+
const [prog, ...pre] = process.platform === "darwin" ? ["open"] : process.platform === "win32" ? ["rundll32", "url.dll,FileProtocolHandler"] : ["xdg-open"];
|
|
3670
|
+
spawn(prog, [...pre, s.url], { stdio: "ignore", detached: true }).on("error", () => console.log("open the link above in your browser")).unref();
|
|
3671
|
+
}
|
|
3672
|
+
const stop = () => {
|
|
3673
|
+
s.close().then(() => process.exit(0));
|
|
3674
|
+
};
|
|
3675
|
+
process.on("SIGINT", stop);
|
|
3676
|
+
process.on("SIGTERM", stop);
|
|
3677
|
+
} else if (cmd === "setup") {
|
|
3678
|
+
const global = args.includes("--global");
|
|
3679
|
+
const named = args.filter((a) => !a.startsWith("--"));
|
|
3680
|
+
const wrong = named.filter((a) => !TARGETS.includes(a));
|
|
3681
|
+
if (wrong.length) {
|
|
3682
|
+
console.log(`unknown agent: ${wrong.join(", ")}. Choose from: ${TARGETS.join(", ")}`);
|
|
3683
|
+
process.exit(1);
|
|
3684
|
+
}
|
|
3685
|
+
const targets = named.length ? named : global ? ["claude"] : detect(process.cwd());
|
|
3686
|
+
try {
|
|
3687
|
+
for (const l of setup(root, process.cwd(), targets, global)) console.log(l);
|
|
3688
|
+
} catch (e) {
|
|
3689
|
+
console.log(e.message);
|
|
3690
|
+
process.exit(1);
|
|
3691
|
+
}
|
|
3692
|
+
console.log(`
|
|
3693
|
+
Ask your agent for a diagram, for example: "Draw this repo's architecture as docs/architecture.fdraw".`);
|
|
3694
|
+
} else usage();
|