archidocs 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +182 -0
- package/dist/cli/commands.d.ts +322 -0
- package/dist/cli/commands.js +174 -0
- package/dist/cli/format.d.ts +2 -2
- package/dist/cli/format.js +9 -5
- package/dist/cli/main.js +19 -60
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/query.d.ts +1 -1
- package/dist/core/rules.d.ts +20 -0
- package/dist/core/rules.js +8 -0
- package/dist/mcp/server.js +3 -1
- package/dist/mcp/writes.js +2 -1
- package/dist/render/font.d.ts +14 -8
- package/dist/render/font.js +11 -10
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.js +1 -0
- package/dist/render/png.d.ts +1 -1
- package/dist/render/png.js +5 -5
- package/dist/render/sequence-svg.d.ts +7 -2
- package/dist/render/sequence-svg.js +32 -32
- package/dist/render/sequence.js +1 -1
- package/dist/render/svg.d.ts +18 -5
- package/dist/render/svg.js +147 -84
- package/dist/render/text.d.ts +6 -4
- package/dist/render/text.js +11 -9
- package/dist/render/tokens.d.ts +53 -0
- package/dist/render/tokens.js +71 -0
- package/dist/viewer/assets/{index-BwUCSYuf.js → index-gucix3xm.js} +2 -2
- package/dist/viewer/assets/{png-D1zzLB1s.js → png-BDKIXtm5.js} +1 -1
- package/dist/viewer/assets/svg-Bulv5YWn.js +2 -0
- package/dist/viewer/index.html +1 -1
- package/package.json +19 -4
- package/dist/viewer/assets/svg-Cw4FMsm3.js +0 -2
package/dist/render/svg.js
CHANGED
|
@@ -1,60 +1,61 @@
|
|
|
1
1
|
import { describeLens } from "../core/saved-views.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FONT_FAMILY, FONTS } from "./font.js";
|
|
3
3
|
import { teamStyles } from "./teams.js";
|
|
4
4
|
import { cut, fmt, text, textWidth } from "./text.js";
|
|
5
|
+
import { flatten, PALETTES } from "./tokens.js";
|
|
5
6
|
const PAD = 24;
|
|
6
7
|
const HEADER = 72;
|
|
7
8
|
const KEY = 44;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
/** Every frame, as the viewer draws it. */
|
|
10
|
+
const FRAME = 1.5;
|
|
11
|
+
/** A node's Team-coloured left edge. */
|
|
12
|
+
const EDGE = 6;
|
|
13
|
+
/** The line under a picture's title: the label if given, else the Workspace, short commit and date. */
|
|
14
|
+
export const sourceLine = (source, label) => label ?? [source.workspace, source.commit?.slice(0, 7) ?? "uncommitted", ...(source.date ? [source.date.slice(0, 10)] : [])].join(" · ");
|
|
15
|
+
/** The `<svg>` open tag, embedded fonts and background every picture starts with. */
|
|
16
|
+
export const opening = (width, height, ground, defs) => [
|
|
17
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" font-family="${FONT_FAMILY}, sans-serif">`,
|
|
18
|
+
`<style>${FONTS.map((f) => `@font-face{font-family:"${FONT_FAMILY}";font-weight:${f.weight};src:url(data:font/ttf;base64,${f.base64}) format("truetype")}`).join("")}</style>`,
|
|
19
|
+
`<defs>${defs}</defs>`,
|
|
20
|
+
`<rect width="${width}" height="${height}" fill="${ground}"/>`,
|
|
21
|
+
];
|
|
21
22
|
/**
|
|
22
|
-
* Draws a laid-out View as one SVG document
|
|
23
|
-
* nodes and edges, and a key. It is a
|
|
24
|
-
*
|
|
25
|
-
* runs in Node and the browser alike.
|
|
23
|
+
* Draws a laid-out View as one SVG document in the viewer's Wayfinding Plate
|
|
24
|
+
* look: the title and source line, the nodes and edges, and a key. It is a
|
|
25
|
+
* pure function of its input, so the same View at the same commit always
|
|
26
|
+
* gives the same bytes; it needs no DOM, and runs in Node and the browser alike.
|
|
27
|
+
* Nothing in it is faded: what a Lens leaves out steps back to solid faint colours.
|
|
26
28
|
*/
|
|
27
|
-
export function renderSvg({ bundle, view, layout, source }) {
|
|
29
|
+
export function renderSvg({ bundle, view, layout, source, theme = "light", label }) {
|
|
30
|
+
const c = PALETTES[theme];
|
|
28
31
|
const elements = new Map(bundle.elements.map((e) => [e.id, e]));
|
|
29
32
|
const targets = new Map(bundle.targets.map((t) => [t.id, t]));
|
|
30
33
|
const teams = teamStyles(bundle);
|
|
31
34
|
const boxes = new Map(layout.nodes.map((n) => [n.id, n]));
|
|
32
35
|
const containers = new Set(view.nodes.map((n) => n.parent).filter((p) => p !== null));
|
|
33
36
|
const title = view.title;
|
|
34
|
-
const
|
|
35
|
-
const key = drawKey(
|
|
36
|
-
const width = Math.ceil(Math.max(layout.width, key.width, textWidth(title, 20), textWidth(
|
|
37
|
+
const subtitle = sourceLine(source, label);
|
|
38
|
+
const key = drawKey(c, view.lens);
|
|
39
|
+
const width = Math.ceil(Math.max(layout.width, key.width, textWidth(title, 20, 700), textWidth(subtitle, 12)) + 2 * PAD);
|
|
37
40
|
const height = Math.ceil(HEADER + layout.height + PAD + KEY);
|
|
38
41
|
const depth = (n) => (n.parent === null ? 0 : 1 + depth(view.nodes.find((p) => p.id === n.parent)));
|
|
39
42
|
const byDepth = view.nodes.map((n) => ({ n, d: depth(n) })).sort((a, b) => a.d - b.d).map(({ n }) => n);
|
|
43
|
+
const ring = view.lens !== undefined && "team" in view.lens;
|
|
44
|
+
let clips = 0;
|
|
40
45
|
const drawn = (n) => {
|
|
41
46
|
const box = boxes.get(n.id);
|
|
42
47
|
const element = elements.get(n.element ?? n.id);
|
|
43
48
|
const target = n.kind === "target" ? targets.get(n.id) : undefined;
|
|
44
49
|
const team = teams.get(element?.owner ?? target?.owner ?? "");
|
|
45
|
-
|
|
46
|
-
return n.mark && !n.mark.hit ? `<g opacity="${DIM}">${drawing}</g>` : drawing;
|
|
50
|
+
return containers.has(n.id) ? drawContainer(c, n, box, team, target?.kind) : drawNode(c, n, box, element, team, ring, `clip-${clips++}`);
|
|
47
51
|
};
|
|
48
52
|
return [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
`<rect width="${width}" height="${height}" fill="${COLOR.background}"/>`,
|
|
53
|
-
text(PAD, 34, title, { size: 20, fill: COLOR.ink }),
|
|
54
|
-
text(PAD, 56, sourceLine, { size: 12, fill: COLOR.muted }),
|
|
53
|
+
...opening(width, height, c.ground, `${marker("arrow", c.edge)}${view.lens ? marker("arrow-faint", c["edge-faint"]) + marker("arrow-lit", c.ink) : ""}${brokerPattern(c)}`),
|
|
54
|
+
text(PAD, 34, title, { size: 20, fill: c.ink, weight: 700 }),
|
|
55
|
+
text(PAD, 56, subtitle, { size: 12, fill: c.muted }),
|
|
55
56
|
`<g transform="translate(${PAD},${HEADER})">`,
|
|
56
57
|
...byDepth.filter((n) => containers.has(n.id)).map(drawn),
|
|
57
|
-
...layout.edges.map((e) => drawEdge(e.points, view.edges.find((v) => v.from === e.from && v.to === e.to))),
|
|
58
|
+
...layout.edges.map((e) => drawEdge(c, e.points, view.edges.find((v) => v.from === e.from && v.to === e.to))),
|
|
58
59
|
...byDepth.filter((n) => !containers.has(n.id)).map(drawn),
|
|
59
60
|
`</g>`,
|
|
60
61
|
`<g transform="translate(${PAD},${fmt(HEADER + layout.height + PAD)})">`,
|
|
@@ -65,88 +66,150 @@ export function renderSvg({ bundle, view, layout, source }) {
|
|
|
65
66
|
].join("\n");
|
|
66
67
|
}
|
|
67
68
|
const marker = (id, fill) => `<marker id="${id}" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="${fill}"/></marker>`;
|
|
68
|
-
/** A
|
|
69
|
-
const
|
|
70
|
-
/** A
|
|
71
|
-
function
|
|
72
|
-
|
|
69
|
+
/** A broker's vertical stripes, in the rule colour. */
|
|
70
|
+
const brokerPattern = (c) => `<pattern id="broker" width="12" height="12" patternUnits="userSpaceOnUse"><rect x="8" width="4" height="12" fill="${c.rule}"/></pattern>`;
|
|
71
|
+
/** A rectangle with its own radius per corner (top-left, top-right, bottom-right, bottom-left), as a path. */
|
|
72
|
+
function shape(x, y, w, h, [tl, tr, br, bl]) {
|
|
73
|
+
const arc = (r, x2, y2) => (r ? `A${fmt(r)},${fmt(r)} 0 0 1 ${fmt(x2)},${fmt(y2)} ` : "");
|
|
74
|
+
return (`M${fmt(x + tl)},${fmt(y)} L${fmt(x + w - tr)},${fmt(y)} ${arc(tr, x + w, y + tr)}` +
|
|
75
|
+
`L${fmt(x + w)},${fmt(y + h - br)} ${arc(br, x + w - br, y + h)}` +
|
|
76
|
+
`L${fmt(x + bl)},${fmt(y + h)} ${arc(bl, x, y + h - bl)}` +
|
|
77
|
+
`L${fmt(x)},${fmt(y + tl)} ${arc(tl, x + tl, y)}Z`);
|
|
78
|
+
}
|
|
79
|
+
/** A reversed Team code tile with the Team colour as its leading band, its right edge at `right`. */
|
|
80
|
+
export function codeTile(c, team, right, top) {
|
|
81
|
+
const w = textWidth(team.code, 10, 700) + 16;
|
|
82
|
+
const x = right - w;
|
|
83
|
+
return [
|
|
84
|
+
`<rect x="${fmt(x)}" y="${fmt(top)}" width="${fmt(w)}" height="16" fill="${c["code-bg"]}"/>`,
|
|
85
|
+
`<rect x="${fmt(x)}" y="${fmt(top)}" width="5" height="16" fill="${team.color}"/>`,
|
|
86
|
+
text(x + 10, top + 12, team.code, { size: 10, fill: c["code-fg"], weight: 700 }),
|
|
87
|
+
].join("");
|
|
88
|
+
}
|
|
89
|
+
function look(c, n, fill, team, ringLens) {
|
|
90
|
+
const plain = { frame: c.ink, fill, name: c.ink, sub: c.muted, edge: team?.color ?? c.ink };
|
|
91
|
+
const mark = n.mark;
|
|
92
|
+
if (!mark)
|
|
93
|
+
return plain;
|
|
94
|
+
if (!mark.hit)
|
|
95
|
+
return { frame: c.line, fill: c.ground, name: c.faint, sub: c.faint, edge: c.line };
|
|
96
|
+
if (ringLens)
|
|
97
|
+
return { ...plain, fill: c.paper, ring: team?.color ?? c.ink };
|
|
98
|
+
if (mark.side === "origin")
|
|
99
|
+
return { ...plain, fill: c.herebg, edge: c.ink, ring: c.here };
|
|
100
|
+
if (mark.side === "upstream")
|
|
101
|
+
return { ...plain, frame: c.up, fill: c.upbg, edge: c.up };
|
|
102
|
+
if (mark.side === "downstream")
|
|
103
|
+
return { ...plain, frame: c.down, fill: c.downbg, edge: c.down, double: true };
|
|
104
|
+
return { ...plain, frame: c.path, fill: c.pathbg, edge: c.path };
|
|
105
|
+
}
|
|
106
|
+
/** An impact badge on a node's top edge: the origin, or the side and distance from it; a bare distance on a path lens. */
|
|
107
|
+
function badge(c, n, box) {
|
|
108
|
+
const mark = n.mark;
|
|
109
|
+
if (mark?.distance === undefined)
|
|
73
110
|
return [];
|
|
74
|
-
const
|
|
75
|
-
const
|
|
111
|
+
const words = mark.side === "origin" ? "ORIGIN" : mark.side ? `${mark.side.toUpperCase()} ${mark.distance}` : String(mark.distance);
|
|
112
|
+
const w = textWidth(words, 10, 700) + 12;
|
|
113
|
+
const x = box.x + box.width - 36 - w;
|
|
114
|
+
const y = box.y - 10;
|
|
115
|
+
const [fill, ink, frame] = mark.side === "origin" ? [c.here, c["on-here"], c.ink] : mark.side === "upstream" ? [c.up, c.paper, undefined] : mark.side === "downstream" ? [c.down, c.paper, undefined] : [c.paper, c.ink, c.ink];
|
|
76
116
|
return [
|
|
77
|
-
`<
|
|
78
|
-
text(
|
|
117
|
+
`<rect x="${fmt(x)}" y="${fmt(y)}" width="${fmt(w)}" height="16" fill="${fill}"${frame ? ` stroke="${frame}" stroke-width="${FRAME}"` : ""}/>`,
|
|
118
|
+
text(x + 6, y + 12, words, { size: 10, fill: ink, weight: 700 }),
|
|
79
119
|
];
|
|
80
120
|
}
|
|
81
|
-
function drawNode(n, box, element, team) {
|
|
121
|
+
function drawNode(c, n, box, element, team, ringLens, clip) {
|
|
82
122
|
const { x, y, width: w, height: h } = box;
|
|
83
|
-
const
|
|
123
|
+
const type = element?.kind === "service" ? element.type : undefined;
|
|
124
|
+
const system = n.kind === "system";
|
|
125
|
+
const l = look(c, n, system ? c.tint : c.paper, team, ringLens);
|
|
126
|
+
const r = n.kind === "person" ? Math.min(36, h / 2) : 0;
|
|
127
|
+
const d = shape(x, y, w, h, n.kind === "person" ? [r, r, r, r] : type === "datastore" ? [0, 0, 12, 12] : [0, 0, 0, 0]);
|
|
84
128
|
const dash = n.external ? ` stroke-dasharray="6 4"` : "";
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const left = person ? 20 : 16;
|
|
129
|
+
const frameWidth = system ? 2 : FRAME;
|
|
130
|
+
const tileWidth = team ? textWidth(team.code, 10, 700) + 16 + 8 : 0;
|
|
131
|
+
const left = x + EDGE + (n.kind === "person" ? 12 : 8);
|
|
132
|
+
const right = n.kind === "person" ? x + w - 16 : x + w - 10;
|
|
90
133
|
return [
|
|
91
134
|
`<g>`,
|
|
92
|
-
`<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
...
|
|
135
|
+
...(l.ring ? [`<path d="${shape(x - 4, y - 4, w + 8, h + 8, r ? [r + 4, r + 4, r + 4, r + 4] : type === "datastore" ? [0, 0, 16, 16] : [0, 0, 0, 0])}" fill="${l.ring}"/>`] : []),
|
|
136
|
+
`<clipPath id="${clip}"><path d="${d}"/></clipPath>`,
|
|
137
|
+
`<path d="${d}" fill="${l.fill}"/>`,
|
|
138
|
+
...(type === "broker" ? [`<path d="${d}" fill="url(#broker)"/>`] : []),
|
|
139
|
+
`<path d="${d}" fill="none" stroke="${l.frame}" stroke-width="${frameWidth}"${dash}/>`,
|
|
140
|
+
...(l.double ? [`<path d="${shape(x + 3, y + 3, w - 6, h - 6, [0, 0, type === "datastore" ? 9 : 0, type === "datastore" ? 9 : 0])}" fill="none" stroke="${l.frame}" stroke-width="${FRAME}"/>`] : []),
|
|
141
|
+
`<rect x="${fmt(x - 1)}" y="${fmt(y - 1)}" width="${EDGE + 1}" height="${fmt(h + 2)}" fill="${l.edge}" clip-path="url(#${clip})"/>`,
|
|
142
|
+
text(left, y + h / 2 - 4, cut(n.name, 13, right - left - tileWidth, 700), { size: 13, fill: l.name, weight: 700 }),
|
|
143
|
+
text(left, y + h / 2 + 13, cut(subLabel(n, element), 11, right - left), { size: 11, fill: l.sub }),
|
|
144
|
+
...(team ? [codeTile(c, team, right, y + 8)] : []),
|
|
145
|
+
...badge(c, n, box),
|
|
146
|
+
...(n.mark?.hit && n.collapsed ? [`<rect x="${fmt(x + w - 42)}" y="${fmt(y + h - 18)}" width="10" height="10" fill="${c.ink}" stroke="${c.paper}" stroke-width="2"/>`] : []),
|
|
98
147
|
`</g>`,
|
|
99
148
|
].join("");
|
|
100
149
|
}
|
|
101
|
-
|
|
150
|
+
/** An open box: a quiet line frame on the open-box tint, its head row at the top; a Deployment Target is a quiet frame with no fill. */
|
|
151
|
+
function drawContainer(c, n, box, team, targetKind) {
|
|
102
152
|
const { x, y, width: w, height: h } = box;
|
|
153
|
+
const target = n.kind === "target";
|
|
154
|
+
const dimmed = n.mark && !n.mark.hit;
|
|
155
|
+
const frame = n.external ? c.ink : c.line;
|
|
156
|
+
const fill = target || dimmed ? "none" : flatten(c.container, c.ground);
|
|
103
157
|
const dash = n.external ? ` stroke-dasharray="6 4"` : "";
|
|
104
|
-
const
|
|
105
|
-
const
|
|
158
|
+
const tileWidth = team ? textWidth(team.code, 10, 700) + 16 + 8 : 0;
|
|
159
|
+
const left = x + (target ? 12 : EDGE + 10);
|
|
106
160
|
return [
|
|
107
161
|
`<g>`,
|
|
108
|
-
`<rect x="${fmt(x)}" y="${fmt(y)}" width="${fmt(w)}" height="${fmt(h)}"
|
|
109
|
-
...(
|
|
110
|
-
text(
|
|
111
|
-
...(
|
|
112
|
-
...
|
|
162
|
+
`<rect x="${fmt(x)}" y="${fmt(y)}" width="${fmt(w)}" height="${fmt(h)}" fill="${fill}" stroke="${frame}" stroke-width="${FRAME}"${dash}/>`,
|
|
163
|
+
...(target ? [] : [`<rect x="${fmt(x - FRAME / 2)}" y="${fmt(y - FRAME / 2)}" width="${EDGE}" height="${fmt(h + FRAME)}" fill="${frame}"/>`]),
|
|
164
|
+
text(left, y + 22, cut(`${n.name} · ${targetKind ?? kindName(n)}`, 13, x + w - 10 - left - tileWidth, 700), { size: 13, fill: dimmed ? c.faint : c.ink, weight: 700 }),
|
|
165
|
+
...(team ? [codeTile(c, team, x + w - 10, y + 9)] : []),
|
|
166
|
+
...badge(c, n, box),
|
|
113
167
|
`</g>`,
|
|
114
168
|
].join("");
|
|
115
169
|
}
|
|
116
|
-
|
|
117
|
-
|
|
170
|
+
/** A Relationship line: lit in ink by a Lens, stepped back to a solid fainter stroke when the Lens misses it. */
|
|
171
|
+
function drawEdge(c, points, edge) {
|
|
118
172
|
const d = points.map((p, i) => `${i === 0 ? "M" : "L"}${fmt(p.x)},${fmt(p.y)}`).join(" ");
|
|
119
|
-
const dash = async ? ` stroke-dasharray="6 4"` : "";
|
|
120
173
|
if (edge.lit)
|
|
121
|
-
return `<path d="${d}" fill="none" stroke="${
|
|
122
|
-
|
|
123
|
-
|
|
174
|
+
return `<path d="${d}" fill="none" stroke="${c.ink}" stroke-width="2.5" marker-end="url(#arrow-lit)"/>`;
|
|
175
|
+
if (edge.lit === false)
|
|
176
|
+
return `<path d="${d}" fill="none" stroke="${c["edge-faint"]}" stroke-width="${FRAME}" marker-end="url(#arrow-faint)"/>`;
|
|
177
|
+
return `<path d="${d}" fill="none" stroke="${c.edge}" stroke-width="${FRAME}" marker-end="url(#arrow)"/>`;
|
|
124
178
|
}
|
|
125
|
-
/** The key
|
|
126
|
-
function drawKey(lens) {
|
|
179
|
+
/** The key, in the canvas's own vocabulary: the Team tile, External, broker, and the Lens if there is one. */
|
|
180
|
+
function drawKey(c, lens) {
|
|
127
181
|
const parts = [];
|
|
128
182
|
let x = 0;
|
|
129
183
|
const label = (s) => {
|
|
130
|
-
parts.push(text(x, 16, s, { size: 11, fill:
|
|
184
|
+
parts.push(text(x, 16, s, { size: 11, fill: c.muted }));
|
|
131
185
|
x += textWidth(s, 11) + 24;
|
|
132
186
|
};
|
|
133
|
-
|
|
134
|
-
parts.push(`<
|
|
135
|
-
x +=
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
parts.push(`<rect x="${x + 1}" y="3" width="5" height="18" fill="${COLOR.muted}"/>`);
|
|
140
|
-
parts.push(text(x + 33, 15, "ABC", { size: 8, fill: COLOR.muted, anchor: "end" }));
|
|
141
|
-
x += 44;
|
|
187
|
+
const swatch = (attrs) => {
|
|
188
|
+
parts.push(`<rect x="${fmt(x)}" y="4" width="28" height="16" ${attrs}/>`);
|
|
189
|
+
x += 36;
|
|
190
|
+
};
|
|
191
|
+
parts.push(codeTile(c, { code: "ABC", color: c.muted }, x + textWidth("ABC", 10, 700) + 16, 4));
|
|
192
|
+
x += textWidth("ABC", 10, 700) + 24;
|
|
142
193
|
label("Team (stripe and code)");
|
|
143
|
-
|
|
144
|
-
x += 44;
|
|
194
|
+
swatch(`fill="${c.paper}" stroke="${c.ink}" stroke-width="${FRAME}" stroke-dasharray="6 4"`);
|
|
145
195
|
label("External");
|
|
196
|
+
parts.push(`<rect x="${fmt(x)}" y="4" width="28" height="16" fill="${c.paper}"/><rect x="${fmt(x)}" y="4" width="28" height="16" fill="url(#broker)" stroke="${c.ink}" stroke-width="${FRAME}"/>`);
|
|
197
|
+
x += 36;
|
|
198
|
+
label("Broker");
|
|
146
199
|
if (lens) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
200
|
+
if ("impact" in lens) {
|
|
201
|
+
swatch(`fill="${c.herebg}" stroke="${c.here}" stroke-width="2.5"`);
|
|
202
|
+
label("Origin");
|
|
203
|
+
swatch(`fill="${c.up}"`);
|
|
204
|
+
label("Upstream");
|
|
205
|
+
swatch(`fill="${c.down}"`);
|
|
206
|
+
label("Downstream");
|
|
207
|
+
}
|
|
208
|
+
else if ("team" in lens)
|
|
209
|
+
swatch(`fill="${c.paper}" stroke="${c.muted}" stroke-width="3"`);
|
|
210
|
+
else
|
|
211
|
+
swatch(`fill="${c.pathbg}" stroke="${c.path}" stroke-width="${FRAME}"`);
|
|
212
|
+
label(`Lens: ${describeLens(lens)}`);
|
|
150
213
|
}
|
|
151
214
|
return { parts, width: x - 24 };
|
|
152
215
|
}
|
package/dist/render/text.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type FontWeight } from "./font.ts";
|
|
2
|
+
/** A string's width in the embedded font at `size` px and `weight` (Regular by default). */
|
|
3
|
+
export declare function textWidth(s: string, size: number, weight?: FontWeight): number;
|
|
3
4
|
/** `s` if it fits in `max` px, else as much of it as fits followed by an ellipsis. */
|
|
4
|
-
export declare function cut(s: string, size: number, max: number): string;
|
|
5
|
+
export declare function cut(s: string, size: number, max: number, weight?: FontWeight): string;
|
|
5
6
|
/** One `<text>` element. */
|
|
6
|
-
export declare function text(x: number, y: number, s: string, { size, fill, anchor }: {
|
|
7
|
+
export declare function text(x: number, y: number, s: string, { size, fill, anchor, weight }: {
|
|
7
8
|
size: number;
|
|
8
9
|
fill: string;
|
|
9
10
|
anchor?: "end" | "middle";
|
|
11
|
+
weight?: FontWeight;
|
|
10
12
|
}): string;
|
|
11
13
|
export declare const escape: (s: string) => string;
|
|
12
14
|
/** A coordinate to at most two decimals, so output doesn't depend on float noise. */
|
package/dist/render/text.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { FONTS, UNITS_PER_EM } from "./font.js";
|
|
2
|
+
const ADVANCES = new Map(FONTS.map((f) => [f.weight, f.advances]));
|
|
3
|
+
/** A string's width in the embedded font at `size` px and `weight` (Regular by default). */
|
|
4
|
+
export function textWidth(s, size, weight = 400) {
|
|
5
|
+
const advances = ADVANCES.get(weight);
|
|
4
6
|
let units = 0;
|
|
5
7
|
for (const ch of s)
|
|
6
|
-
units +=
|
|
8
|
+
units += advances[ch.codePointAt(0)] ?? advances[77];
|
|
7
9
|
return (units * size) / UNITS_PER_EM;
|
|
8
10
|
}
|
|
9
11
|
/** `s` if it fits in `max` px, else as much of it as fits followed by an ellipsis. */
|
|
10
|
-
export function cut(s, size, max) {
|
|
11
|
-
if (textWidth(s, size) <= max)
|
|
12
|
+
export function cut(s, size, max, weight = 400) {
|
|
13
|
+
if (textWidth(s, size, weight) <= max)
|
|
12
14
|
return s;
|
|
13
15
|
const chars = [...s];
|
|
14
|
-
while (chars.length > 0 && textWidth(chars.join("").trimEnd() + "…", size) > max)
|
|
16
|
+
while (chars.length > 0 && textWidth(chars.join("").trimEnd() + "…", size, weight) > max)
|
|
15
17
|
chars.pop();
|
|
16
18
|
return chars.join("").trimEnd() + "…";
|
|
17
19
|
}
|
|
18
20
|
/** One `<text>` element. */
|
|
19
|
-
export function text(x, y, s, { size, fill, anchor }) {
|
|
20
|
-
return `<text x="${fmt(x)}" y="${fmt(y)}" font-size="${size}" fill="${fill}"${anchor ? ` text-anchor="${anchor}"` : ""}>${escape(s)}</text>`;
|
|
21
|
+
export function text(x, y, s, { size, fill, anchor, weight = 400 }) {
|
|
22
|
+
return `<text x="${fmt(x)}" y="${fmt(y)}" font-size="${size}"${weight === 400 ? "" : ` font-weight="${weight}"`} fill="${fill}"${anchor ? ` text-anchor="${anchor}"` : ""}>${escape(s)}</text>`;
|
|
21
23
|
}
|
|
22
24
|
export const escape = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
23
25
|
/** A coordinate to at most two decimals, so output doesn't depend on float noise. */
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The diagram palette: the Wayfinding Plate tokens (DESIGN.md) that a drawn
|
|
3
|
+
* View uses, in light and in "Night shift" dark. This is the one source for
|
|
4
|
+
* `renderSvg` and `renderSequenceSvg`; the viewer's CSS custom properties of
|
|
5
|
+
* the same names in `viewer/src/styles.css` are checked against it by
|
|
6
|
+
* `test/render/tokens.test.ts`, so the export and the viewer can't drift.
|
|
7
|
+
*/
|
|
8
|
+
export declare const themes: readonly ["light", "dark"];
|
|
9
|
+
export type Theme = (typeof themes)[number];
|
|
10
|
+
/** Each token by its CSS custom property name, without the leading `--`. */
|
|
11
|
+
export interface Palette {
|
|
12
|
+
/** The canvas: the pale stone ground the map sits on. */
|
|
13
|
+
ground: string;
|
|
14
|
+
/** Nodes, headers, the key. */
|
|
15
|
+
paper: string;
|
|
16
|
+
/** Station Slate: text and every 1.5px frame. */
|
|
17
|
+
ink: string;
|
|
18
|
+
muted: string;
|
|
19
|
+
faint: string;
|
|
20
|
+
/** Quiet frames: Deployment Targets, open boxes and stepped-back nodes. */
|
|
21
|
+
line: string;
|
|
22
|
+
/** Hairlines and broker stripes. */
|
|
23
|
+
rule: string;
|
|
24
|
+
/** A collapsed System's fill, activation bars. */
|
|
25
|
+
tint: string;
|
|
26
|
+
/** Wayfinding Yellow: the lens origin ring, and nothing decorative. */
|
|
27
|
+
here: string;
|
|
28
|
+
/** Text on the yellow. */
|
|
29
|
+
"on-here": string;
|
|
30
|
+
herebg: string;
|
|
31
|
+
"code-bg": string;
|
|
32
|
+
"code-fg": string;
|
|
33
|
+
/** Upstream Rust and Downstream Blue: the Impact lens sides. */
|
|
34
|
+
up: string;
|
|
35
|
+
upbg: string;
|
|
36
|
+
down: string;
|
|
37
|
+
downbg: string;
|
|
38
|
+
/** Path Violet: a path lens. */
|
|
39
|
+
path: string;
|
|
40
|
+
pathbg: string;
|
|
41
|
+
edge: string;
|
|
42
|
+
/** A stepped-back edge: solid, fainter, never faded or dashed. */
|
|
43
|
+
"edge-faint": string;
|
|
44
|
+
/** An open box's translucent tint, as the viewer's CSS writes it. */
|
|
45
|
+
container: string;
|
|
46
|
+
}
|
|
47
|
+
export declare const PALETTES: Record<Theme, Palette>;
|
|
48
|
+
/**
|
|
49
|
+
* `rgba(r, g, b, a)` painted over a solid hex colour, as one solid hex. The
|
|
50
|
+
* export flattens the open-box tint onto the ground this way, so no element
|
|
51
|
+
* in it carries an opacity below 1.
|
|
52
|
+
*/
|
|
53
|
+
export declare function flatten(rgba: string, under: string): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The diagram palette: the Wayfinding Plate tokens (DESIGN.md) that a drawn
|
|
3
|
+
* View uses, in light and in "Night shift" dark. This is the one source for
|
|
4
|
+
* `renderSvg` and `renderSequenceSvg`; the viewer's CSS custom properties of
|
|
5
|
+
* the same names in `viewer/src/styles.css` are checked against it by
|
|
6
|
+
* `test/render/tokens.test.ts`, so the export and the viewer can't drift.
|
|
7
|
+
*/
|
|
8
|
+
export const themes = ["light", "dark"];
|
|
9
|
+
export const PALETTES = {
|
|
10
|
+
light: {
|
|
11
|
+
ground: "#f3f4f1",
|
|
12
|
+
paper: "#ffffff",
|
|
13
|
+
ink: "#1c2633",
|
|
14
|
+
muted: "#4f5966",
|
|
15
|
+
faint: "#616a76",
|
|
16
|
+
line: "#c4c9c1",
|
|
17
|
+
rule: "#e2e4df",
|
|
18
|
+
tint: "#e8eae5",
|
|
19
|
+
here: "#ffc629",
|
|
20
|
+
"on-here": "#1c2633",
|
|
21
|
+
herebg: "#fff4cc",
|
|
22
|
+
"code-bg": "#1c2633",
|
|
23
|
+
"code-fg": "#ffffff",
|
|
24
|
+
up: "#a4461a",
|
|
25
|
+
upbg: "#fbeee6",
|
|
26
|
+
down: "#1d5fa8",
|
|
27
|
+
downbg: "#e8f0fa",
|
|
28
|
+
path: "#5b3aa8",
|
|
29
|
+
pathbg: "#efeaf9",
|
|
30
|
+
edge: "#5b6573",
|
|
31
|
+
"edge-faint": "#80878f",
|
|
32
|
+
container: "rgba(232, 234, 229, 0.6)",
|
|
33
|
+
},
|
|
34
|
+
dark: {
|
|
35
|
+
ground: "#10151c",
|
|
36
|
+
paper: "#18202a",
|
|
37
|
+
ink: "#e6eaef",
|
|
38
|
+
muted: "#a9b2bd",
|
|
39
|
+
faint: "#8f99a5",
|
|
40
|
+
line: "#36414f",
|
|
41
|
+
rule: "#252e3a",
|
|
42
|
+
tint: "#232c38",
|
|
43
|
+
here: "#ffc629",
|
|
44
|
+
"on-here": "#10151c",
|
|
45
|
+
herebg: "#3a3216",
|
|
46
|
+
"code-bg": "#e6eaef",
|
|
47
|
+
"code-fg": "#10151c",
|
|
48
|
+
up: "#f0925f",
|
|
49
|
+
upbg: "#3a2419",
|
|
50
|
+
down: "#78aef5",
|
|
51
|
+
downbg: "#172a45",
|
|
52
|
+
path: "#b79cff",
|
|
53
|
+
pathbg: "#2a2142",
|
|
54
|
+
edge: "#8f99a5",
|
|
55
|
+
"edge-faint": "#646d78",
|
|
56
|
+
container: "rgba(35, 44, 56, 0.55)",
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* `rgba(r, g, b, a)` painted over a solid hex colour, as one solid hex. The
|
|
61
|
+
* export flattens the open-box tint onto the ground this way, so no element
|
|
62
|
+
* in it carries an opacity below 1.
|
|
63
|
+
*/
|
|
64
|
+
export function flatten(rgba, under) {
|
|
65
|
+
const m = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)$/.exec(rgba);
|
|
66
|
+
if (!m)
|
|
67
|
+
return rgba;
|
|
68
|
+
const alpha = Number(m[4]);
|
|
69
|
+
const base = [1, 3, 5].map((i) => parseInt(under.slice(i, i + 2), 16));
|
|
70
|
+
return `#${[m[1], m[2], m[3]].map((c, i) => Math.round(Number(c) * alpha + base[i] * (1 - alpha)).toString(16).padStart(2, "0")).join("")}`;
|
|
71
|
+
}
|