archidocs 1.0.0 → 1.3.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 +231 -0
- package/dist/cli/commands.d.ts +543 -0
- package/dist/cli/commands.js +299 -0
- package/dist/cli/format.d.ts +2 -2
- package/dist/cli/format.js +9 -5
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +2 -2
- package/dist/cli/main.js +27 -73
- package/dist/core/compare.d.ts +2 -13
- package/dist/core/compare.js +2 -35
- package/dist/core/index.d.ts +3 -6
- package/dist/core/index.js +3 -6
- package/dist/core/query.d.ts +1 -1
- package/dist/core/rules.d.ts +30 -0
- package/dist/core/rules.js +194 -7
- package/dist/core/views/compare.d.ts +12 -0
- package/dist/core/views/compare.js +37 -0
- package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
- package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
- package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
- package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
- package/dist/core/views/generated.d.ts +18 -0
- package/dist/core/views/generated.js +92 -0
- package/dist/core/views/ids.d.ts +36 -0
- package/dist/core/views/ids.js +51 -0
- package/dist/core/views/index.d.ts +13 -0
- package/dist/core/views/index.js +12 -0
- package/dist/core/views/lens.d.ts +27 -0
- package/dist/core/views/lens.js +112 -0
- package/dist/core/views/model.d.ts +21 -0
- package/dist/core/views/model.js +69 -0
- package/dist/core/views/resolve.d.ts +42 -0
- package/dist/core/views/resolve.js +81 -0
- package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
- package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
- package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
- package/dist/core/{saved-views.js → views/saved.js} +8 -103
- package/dist/core/views/types.d.ts +91 -0
- package/dist/core/views/types.js +2 -0
- package/dist/mcp/errors.d.ts +37 -0
- package/dist/mcp/errors.js +35 -0
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/server.d.ts +1 -2
- package/dist/mcp/server.js +15 -13
- 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/layout.d.ts +20 -3
- package/dist/render/layout.js +49 -12
- package/dist/render/png.d.ts +1 -1
- package/dist/render/png.js +5 -5
- package/dist/render/sequence-svg.d.ts +8 -3
- package/dist/render/sequence-svg.js +32 -32
- package/dist/render/sequence.d.ts +1 -1
- package/dist/render/sequence.js +1 -1
- package/dist/render/svg.d.ts +19 -6
- package/dist/render/svg.js +148 -85
- 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/schema/adr.js +18 -13
- package/dist/schema/workspace.js +226 -130
- package/dist/viewer/assets/index-BXa5R96a.js +138 -0
- package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
- package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
- package/dist/viewer/assets/{png-D1zzLB1s.js → png-CAaXWR-k.js} +1 -1
- package/dist/viewer/assets/svg-BPVHfD36.js +2 -0
- package/dist/viewer/index.html +2 -2
- package/guide/SKILL.md +1 -1
- package/guide/topics/bootstrap.md +1 -1
- package/guide/topics/relationships.md +1 -1
- package/package.json +20 -4
- package/schemas/adr.schema.json +18 -15
- package/schemas/model.schema.json +637 -1144
- package/schemas/project.schema.json +8 -4
- package/schemas/workspace.schema.json +39 -20
- package/dist/core/views.d.ts +0 -126
- package/dist/core/views.js +0 -217
- package/dist/viewer/assets/index-BwUCSYuf.js +0 -113
- package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
- package/dist/viewer/assets/svg-Cw4FMsm3.js +0 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { ResolvedDynamicView } from "../core/
|
|
1
|
+
import type { ResolvedDynamicView } from "../core/views/index.ts";
|
|
2
2
|
import type { Bundle } from "../schema/bundle.ts";
|
|
3
3
|
import { type MessageStyle } from "./sequence.ts";
|
|
4
|
-
import type
|
|
4
|
+
import { type RenderSource } from "./svg.ts";
|
|
5
|
+
import { type Theme } from "./tokens.ts";
|
|
5
6
|
export interface SequenceRenderInput {
|
|
6
7
|
/** The Bundle the View was resolved from: it gives each participant's name and Team. */
|
|
7
8
|
bundle: Bundle;
|
|
@@ -9,6 +10,10 @@ export interface SequenceRenderInput {
|
|
|
9
10
|
source: RenderSource;
|
|
10
11
|
/** Draws each event Step as a publish and a deliver leg through its broker. */
|
|
11
12
|
brokers?: boolean;
|
|
13
|
+
/** The palette: the viewer's light tokens (the default) or its Night shift dark ones. */
|
|
14
|
+
theme?: Theme;
|
|
15
|
+
/** Replaces the source line under the title, such as `Big Bank · v1.2.0`. */
|
|
16
|
+
label?: string;
|
|
12
17
|
}
|
|
13
18
|
/** The header box's height; its lifeline runs down from its bottom. */
|
|
14
19
|
export declare const HEADER_BOX = 44;
|
|
@@ -23,6 +28,6 @@ export declare const ARROW: Record<MessageStyle, {
|
|
|
23
28
|
* one numbered arrow per Step (or leg), and a key. Pure, like `renderSvg`,
|
|
24
29
|
* and laid out by the same `layoutSequence` the viewer uses.
|
|
25
30
|
*/
|
|
26
|
-
export declare function renderSequenceSvg({ bundle, view, source, brokers }: SequenceRenderInput): string;
|
|
31
|
+
export declare function renderSequenceSvg({ bundle, view, source, brokers, theme, label }: SequenceRenderInput): string;
|
|
27
32
|
/** Arrowheads: filled for sync calls, open for async and returns. */
|
|
28
33
|
export declare const heads: (fill: string) => string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { FONT_BASE64, FONT_FAMILY } from "./font.js";
|
|
2
1
|
import { layoutSequence, SEQUENCE, viaLine } from "./sequence.js";
|
|
2
|
+
import { codeTile, opening, sourceLine } from "./svg.js";
|
|
3
3
|
import { teamStyles } from "./teams.js";
|
|
4
4
|
import { cut, fmt, text, textWidth } from "./text.js";
|
|
5
|
+
import { PALETTES } from "./tokens.js";
|
|
5
6
|
const PAD = 24;
|
|
6
7
|
const TITLE = 72;
|
|
7
8
|
const KEY = 44;
|
|
8
9
|
/** The header box's height; its lifeline runs down from its bottom. */
|
|
9
10
|
export const HEADER_BOX = 44;
|
|
10
|
-
const COLOR = { background: "#ffffff", ink: "#1b2330", muted: "#5b6573", border: "#8a94a3", node: "#ffffff", bar: "#eef1f5", edge: "#3d4654", badge: "#1b2330" };
|
|
11
11
|
/** How each style is drawn: its dash pattern and arrowhead. */
|
|
12
12
|
export const ARROW = {
|
|
13
13
|
sync: { dash: null, head: "filled" },
|
|
@@ -20,30 +20,28 @@ export const ARROW = {
|
|
|
20
20
|
* one numbered arrow per Step (or leg), and a key. Pure, like `renderSvg`,
|
|
21
21
|
* and laid out by the same `layoutSequence` the viewer uses.
|
|
22
22
|
*/
|
|
23
|
-
export function renderSequenceSvg({ bundle, view, source, brokers = false }) {
|
|
23
|
+
export function renderSequenceSvg({ bundle, view, source, brokers = false, theme = "light", label }) {
|
|
24
|
+
const c = PALETTES[theme];
|
|
24
25
|
const elements = new Map(bundle.elements.map((e) => [e.id, e]));
|
|
25
26
|
const name = (id) => elements.get(id)?.name ?? id;
|
|
26
27
|
const layout = layoutSequence(view, { name, brokers });
|
|
27
28
|
const teams = teamStyles(bundle);
|
|
28
|
-
const
|
|
29
|
-
const key = drawKey();
|
|
30
|
-
const width = Math.ceil(Math.max(layout.width, key.width, textWidth(view.title, 20), textWidth(
|
|
29
|
+
const subtitle = sourceLine(source, label);
|
|
30
|
+
const key = drawKey(c);
|
|
31
|
+
const width = Math.ceil(Math.max(layout.width, key.width, textWidth(view.title, 20, 700), textWidth(subtitle, 12)) + 2 * PAD);
|
|
31
32
|
const height = Math.ceil(TITLE + layout.height + KEY);
|
|
32
33
|
return [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
`<rect width="${width}" height="${height}" fill="${COLOR.background}"/>`,
|
|
37
|
-
text(PAD, 34, view.title, { size: 20, fill: COLOR.ink }),
|
|
38
|
-
text(PAD, 56, sourceLine, { size: 12, fill: COLOR.muted }),
|
|
34
|
+
...opening(width, height, c.ground, heads(c.ink)),
|
|
35
|
+
text(PAD, 34, view.title, { size: 20, fill: c.ink, weight: 700 }),
|
|
36
|
+
text(PAD, 56, subtitle, { size: 12, fill: c.muted }),
|
|
39
37
|
`<g transform="translate(${PAD},${TITLE})">`,
|
|
40
|
-
...layout.columns.map((
|
|
38
|
+
...layout.columns.map((col) => lifeline(c, col.x, layout)),
|
|
41
39
|
...layout.activations.map((a) => {
|
|
42
|
-
const x = layout.columns.find((
|
|
43
|
-
return `<rect x="${fmt(x)}" y="${fmt(a.top - 6)}" width="${SEQUENCE.bar}" height="${fmt(a.bottom - a.top + 12)}" fill="${
|
|
40
|
+
const x = layout.columns.find((col) => col.id === a.participant).x - SEQUENCE.bar / 2 + (a.depth * SEQUENCE.bar) / 2;
|
|
41
|
+
return `<rect x="${fmt(x)}" y="${fmt(a.top - 6)}" width="${SEQUENCE.bar}" height="${fmt(a.bottom - a.top + 12)}" fill="${c.tint}" stroke="${c.faint}"/>`;
|
|
44
42
|
}),
|
|
45
|
-
...layout.columns.map((
|
|
46
|
-
...layout.rows.map((r) => arrow(r, name)),
|
|
43
|
+
...layout.columns.map((col) => header(c, col.id, col.x, col.width, elements.get(col.id), teams.get(elements.get(col.id)?.owner ?? ""))),
|
|
44
|
+
...layout.rows.map((r) => arrow(c, r, name)),
|
|
47
45
|
`</g>`,
|
|
48
46
|
`<g transform="translate(${PAD},${fmt(TITLE + layout.height)})">`,
|
|
49
47
|
...key.parts,
|
|
@@ -55,20 +53,22 @@ export function renderSequenceSvg({ bundle, view, source, brokers = false }) {
|
|
|
55
53
|
/** Arrowheads: filled for sync calls, open for async and returns. */
|
|
56
54
|
export const heads = (fill) => `<marker id="head-filled" 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>` +
|
|
57
55
|
`<marker id="head-open" 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" fill="none" stroke="${fill}" stroke-width="1.5"/></marker>`;
|
|
58
|
-
const lifeline = (x, layout) => `<path d="M${fmt(x)},${HEADER_BOX} L${fmt(x)},${fmt(layout.height - 10)}" fill="none" stroke="${
|
|
59
|
-
function header(id, x, w, element, team) {
|
|
56
|
+
const lifeline = (c, x, layout) => `<path d="M${fmt(x)},${HEADER_BOX} L${fmt(x)},${fmt(layout.height - 10)}" fill="none" stroke="${c.faint}" stroke-dasharray="3 4"/>`;
|
|
57
|
+
function header(c, id, x, w, element, team) {
|
|
60
58
|
const left = x - w / 2;
|
|
61
59
|
const name = element?.name ?? id;
|
|
62
|
-
const
|
|
60
|
+
const external = element !== undefined && "external" in element && element.external;
|
|
61
|
+
// The code tile sits 6px in from the right, 4px clear of the name; `SEQUENCE.headerPad` budgets for both.
|
|
62
|
+
const tileWidth = team ? textWidth(team.code, 10, 700) + 16 + 4 : 0;
|
|
63
63
|
return [
|
|
64
64
|
`<g>`,
|
|
65
|
-
`<rect x="${fmt(left)}" y="0" width="${fmt(w)}" height="${HEADER_BOX}"
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
`<rect x="${fmt(left)}" y="0" width="${fmt(w)}" height="${HEADER_BOX}" fill="${external ? c.ground : c.paper}" stroke="${c.ink}" stroke-width="1.5"${external ? ` stroke-dasharray="6 4"` : ""}/>`,
|
|
66
|
+
text(left + 14, 27, cut(name, SEQUENCE.nameSize, w - 20 - tileWidth, 700), { size: SEQUENCE.nameSize, fill: c.ink, weight: 700 }),
|
|
67
|
+
...(team ? [codeTile(c, team, left + w - 6, HEADER_BOX / 2 - 8)] : []),
|
|
68
68
|
`</g>`,
|
|
69
69
|
].join("");
|
|
70
70
|
}
|
|
71
|
-
function arrow(r, name) {
|
|
71
|
+
function arrow(c, r, name) {
|
|
72
72
|
const { dash, head } = ARROW[r.style];
|
|
73
73
|
const way = r.x2 >= r.x1 ? 1 : -1;
|
|
74
74
|
const badgeX = r.x1 + way * 14;
|
|
@@ -76,22 +76,22 @@ function arrow(r, name) {
|
|
|
76
76
|
const anchor = way > 0 ? undefined : "end";
|
|
77
77
|
const under = [viaLine(r, name), r.note].filter((s) => s !== undefined);
|
|
78
78
|
return [
|
|
79
|
-
`<path data-step="${r.key}" d="M${fmt(r.x1)},${fmt(r.y)} L${fmt(r.x2)},${fmt(r.y)}" fill="none" stroke="${
|
|
80
|
-
`<circle cx="${fmt(badgeX)}" cy="${fmt(r.y)}" r="9" fill="${
|
|
81
|
-
text(badgeX, r.y + 3.5, r.key, { size: r.key.length > 2 ? 8 : 10, fill:
|
|
82
|
-
text(labelX, r.y - 7, r.label, { size: SEQUENCE.labelSize, fill:
|
|
83
|
-
...under.map((s, i) => text(labelX, r.y + 16 + i * SEQUENCE.lineHeight, s, { size: SEQUENCE.subSize, fill:
|
|
79
|
+
`<path data-step="${r.key}" d="M${fmt(r.x1)},${fmt(r.y)} L${fmt(r.x2)},${fmt(r.y)}" fill="none" stroke="${c.ink}" stroke-width="1.5"${dash ? ` stroke-dasharray="${dash}"` : ""} marker-end="url(#head-${head})"/>`,
|
|
80
|
+
`<circle cx="${fmt(badgeX)}" cy="${fmt(r.y)}" r="9" fill="${c.ink}"/>`,
|
|
81
|
+
text(badgeX, r.y + 3.5, r.key, { size: r.key.length > 2 ? 8 : 10, fill: c.paper, anchor: "middle", weight: 700 }),
|
|
82
|
+
text(labelX, r.y - 7, r.label, { size: SEQUENCE.labelSize, fill: c.ink, ...(anchor ? { anchor } : {}) }),
|
|
83
|
+
...under.map((s, i) => text(labelX, r.y + 16 + i * SEQUENCE.lineHeight, s, { size: SEQUENCE.subSize, fill: c.muted, ...(anchor ? { anchor } : {}) })),
|
|
84
84
|
].join("");
|
|
85
85
|
}
|
|
86
86
|
/** The key: what each arrow style means. */
|
|
87
|
-
function drawKey() {
|
|
87
|
+
function drawKey(c) {
|
|
88
88
|
const parts = [];
|
|
89
89
|
let x = 0;
|
|
90
90
|
for (const [label, style] of [["Sync call", "sync"], ["Async", "async"], ["Return", "return"]]) {
|
|
91
91
|
const { dash, head } = ARROW[style];
|
|
92
|
-
parts.push(`<path d="M${x},12 L${x + 32},12" fill="none" stroke="${
|
|
92
|
+
parts.push(`<path d="M${x},12 L${x + 32},12" fill="none" stroke="${c.ink}" stroke-width="1.5"${dash ? ` stroke-dasharray="${dash}"` : ""} marker-end="url(#head-${head})"/>`);
|
|
93
93
|
x += 40;
|
|
94
|
-
parts.push(text(x, 16, label, { size: 11, fill:
|
|
94
|
+
parts.push(text(x, 16, label, { size: 11, fill: c.muted }));
|
|
95
95
|
x += textWidth(label, 11) + 24;
|
|
96
96
|
}
|
|
97
97
|
return { parts, width: x - 24 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedDynamicView, ResolvedStep } from "../core/
|
|
1
|
+
import type { ResolvedDynamicView, ResolvedStep } from "../core/views/index.ts";
|
|
2
2
|
/** How a message is drawn: sync is solid with a filled head, async solid with an open head, return dashed with an open head. */
|
|
3
3
|
export type MessageStyle = "sync" | "async" | "return";
|
|
4
4
|
/**
|
package/dist/render/sequence.js
CHANGED
|
@@ -72,7 +72,7 @@ export function layoutSequence(view, options) {
|
|
|
72
72
|
const messages = sequenceMessages(view, options);
|
|
73
73
|
const ids = sequenceParticipants(view, options);
|
|
74
74
|
const index = new Map(ids.map((id, i) => [id, i]));
|
|
75
|
-
const widths = ids.map((id) => Math.min(S.maxColumn, Math.max(S.minColumn, textWidth(options.name(id), S.nameSize) + S.headerPad)));
|
|
75
|
+
const widths = ids.map((id) => Math.min(S.maxColumn, Math.max(S.minColumn, textWidth(options.name(id), S.nameSize, 700) + S.headerPad)));
|
|
76
76
|
const labelWidths = messages.map((m) => {
|
|
77
77
|
const via = viaLine(m, options.name);
|
|
78
78
|
return Math.max(textWidth(m.label, S.labelSize), via ? textWidth(via, S.subSize) : 0, m.note ? textWidth(m.note, S.subSize) : 0);
|
package/dist/render/svg.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ResolvedView } from "../core/views/index.ts";
|
|
2
2
|
import type { Bundle } from "../schema/bundle.ts";
|
|
3
3
|
import type { Layout } from "./layout.ts";
|
|
4
|
+
import { type TeamStyle } from "./teams.ts";
|
|
5
|
+
import { type Palette, type Theme } from "./tokens.ts";
|
|
4
6
|
/** Where a picture comes from, for its source line: the Workspace's name, the commit and its date (both null before the first commit). */
|
|
5
7
|
export interface RenderSource {
|
|
6
8
|
workspace: string;
|
|
@@ -13,11 +15,22 @@ export interface RenderInput {
|
|
|
13
15
|
view: ResolvedView;
|
|
14
16
|
layout: Layout;
|
|
15
17
|
source: RenderSource;
|
|
18
|
+
/** The palette: the viewer's light tokens (the default) or its Night shift dark ones. */
|
|
19
|
+
theme?: Theme;
|
|
20
|
+
/** Replaces the source line under the title, such as `Big Bank · v1.2.0`. */
|
|
21
|
+
label?: string;
|
|
16
22
|
}
|
|
23
|
+
/** The line under a picture's title: the label if given, else the Workspace, short commit and date. */
|
|
24
|
+
export declare const sourceLine: (source: RenderSource, label?: string) => string;
|
|
25
|
+
/** The `<svg>` open tag, embedded fonts and background every picture starts with. */
|
|
26
|
+
export declare const opening: (width: number, height: number, ground: string, defs: string) => string[];
|
|
17
27
|
/**
|
|
18
|
-
* Draws a laid-out View as one SVG document
|
|
19
|
-
* nodes and edges, and a key. It is a
|
|
20
|
-
*
|
|
21
|
-
* runs in Node and the browser alike.
|
|
28
|
+
* Draws a laid-out View as one SVG document in the viewer's Wayfinding Plate
|
|
29
|
+
* look: the title and source line, the nodes and edges, and a key. It is a
|
|
30
|
+
* pure function of its input, so the same View at the same commit always
|
|
31
|
+
* gives the same bytes; it needs no DOM, and runs in Node and the browser alike.
|
|
32
|
+
* Nothing in it is faded: what a Lens leaves out steps back to solid faint colours.
|
|
22
33
|
*/
|
|
23
|
-
export declare function renderSvg({ bundle, view, layout, source }: RenderInput): string;
|
|
34
|
+
export declare function renderSvg({ bundle, view, layout, source, theme, label }: RenderInput): string;
|
|
35
|
+
/** A reversed Team code tile with the Team colour as its leading band, its right edge at `right`. */
|
|
36
|
+
export declare function codeTile(c: Palette, team: TeamStyle, right: number, top: number): string;
|
package/dist/render/svg.js
CHANGED
|
@@ -1,60 +1,61 @@
|
|
|
1
|
-
import { describeLens } from "../core/
|
|
2
|
-
import {
|
|
1
|
+
import { describeLens } from "../core/views/index.js";
|
|
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, bundle, 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, bundle, 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(bundle, 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. */
|