@diagc/cli 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/dist/cli.js +1 -1
- package/dist/commands/tui.d.ts +1 -1
- package/dist/commands/tui.js +10 -2
- package/dist/text/ansi.js +11 -5
- package/dist/text/canvas.d.ts +9 -2
- package/dist/text/canvas.js +25 -7
- package/dist/text/dos.d.ts +69 -0
- package/dist/text/dos.js +93 -0
- package/dist/text/glyphs.d.ts +4 -3
- package/dist/text/glyphs.js +18 -2
- package/dist/text/layout.d.ts +10 -1
- package/dist/text/layout.js +10 -7
- package/dist/text/legend.js +17 -13
- package/dist/text/paint.d.ts +6 -4
- package/dist/text/paint.js +69 -17
- package/dist/text/scene.d.ts +4 -0
- package/dist/text/scene.js +10 -2
- package/dist/tui/actions.d.ts +5 -0
- package/dist/tui/actions.js +3 -0
- package/dist/tui/app.d.ts +3 -0
- package/dist/tui/app.js +18 -5
- package/dist/tui/nav.d.ts +16 -10
- package/dist/tui/nav.js +26 -4
- package/dist/tui/overview.d.ts +4 -2
- package/dist/tui/overview.js +38 -8
- package/dist/tui/screen.d.ts +10 -0
- package/dist/tui/screen.js +104 -23
- package/dist/tui/state.d.ts +12 -10
- package/dist/tui/state.js +12 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ Diagrams as code, with a local studio. diagc turns diagram sources that live in
|
|
|
5
5
|
- **Pages and pictures.** `diagc publish` writes one self-contained HTML page per diagram, and a PNG. The page folds, zooms and switches views in the browser, with no server behind it. Host the pages on GitHub Pages, GitLab Pages or any static host, and put the PNG in a README.
|
|
6
6
|
- **Diffs in pull requests.** A GitHub Action comments on a pull request that changes a diagram: the list of changes, and the before and after pictures.
|
|
7
7
|
- **A local studio.** `diagc studio` opens a browser app against your repository. Draw a diagram there and the studio saves it as a file in the repository. `diagc eject` turns a drawn diagram into TypeScript.
|
|
8
|
+
- **In the terminal.** `diagc show` prints a diagram as text, for a pipe or a coding agent. `diagc tui` browses the diagrams full-screen and redraws as you edit.
|
|
8
9
|
|
|
9
10
|
Diagrams are plain files in your repository, so they diff, review and refactor like the rest of it.
|
|
10
11
|
|
|
@@ -30,12 +31,16 @@ diagc studio # opens the editor, recompiling as you edit
|
|
|
30
31
|
| `diagc init` | Set a repository up: a starter diagram (`--type c4` for a C4 one), the `.gitignore` lines, and with `--agents` a pointer to the guide for coding agents (`AGENTS.md` / `CLAUDE.md`, and a Claude Code skill). |
|
|
31
32
|
| `diagc compile` | Compile `.diagrams/src/**/*.diagram.{ts,json}` into validated artifacts under `.diagrams/.artifacts/`. The default command. |
|
|
32
33
|
| `diagc lint` | Report what compiles but is probably a mistake — typos, duplicates, unused or undrawn parts. `--json` for a script or an agent; exit 1 until clean. |
|
|
33
|
-
| `diagc watch` |
|
|
34
|
-
| `diagc studio` | Serve the visual editor against the current directory (default `http://127.0.0.1:5173`). Diagrams drawn here are saved back as `.diagram.json`. |
|
|
34
|
+
| `diagc watch` | Compile, then again on every change. |
|
|
35
35
|
| `diagc publish` | Write self-contained HTML pages to `.diagrams/html/` and PNGs to `.diagrams/static/`. |
|
|
36
|
+
| `diagc show` | Print a diagram as text: boxes, lines and labels in box-drawing characters, coloured on a terminal and plain in a pipe. `--plane`, `--layers`, `--depth` and `--root` choose the view, `--ascii` the characters. |
|
|
37
|
+
| `diagc studio` | Serve the visual editor against the current directory (default `http://127.0.0.1:5173`). Diagrams drawn here are saved back as `.diagram.json`. |
|
|
38
|
+
| `diagc tui` | Browse the diagrams full-screen in the terminal: fold and unfold, go into a group, switch planes and layers, search. Redraws as the sources change. |
|
|
39
|
+
| `diagc eject` | Replace a drawn `.diagram.json` with a generated `.diagram.ts`, checked first to rebuild the same model. |
|
|
40
|
+
| `diagc diff` | Draw what changed in the diagrams between two git refs, or a ref and the working tree: before and after pages and PNGs, and a summary. |
|
|
36
41
|
| `diagc guide` | Print how to write a diagram: the DSL, then one topic per diagram type (`diagc guide c4`). Written for a coding agent as much as for a person. |
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
`diagc --help` lists every command and flag, and the [CLI reference](https://ferroman.github.io/diagc/docs/reference/cli.html) has the details.
|
|
39
44
|
|
|
40
45
|
PNG export drives headless Chrome. Without one, `publish` writes HTML and says so; point `CHROME_PATH` at a browser to get images.
|
|
41
46
|
|
package/dist/cli.js
CHANGED
|
@@ -49,7 +49,7 @@ Options:
|
|
|
49
49
|
--no-images Publish (or diff) HTML without rendering PNG images
|
|
50
50
|
--link url Publish with a link to url in the index header
|
|
51
51
|
--style id Publish: take the PNGs in this style preset (clean, sketch, …) in
|
|
52
|
-
place of each diagram's own
|
|
52
|
+
place of each diagram's own; tui: draw every diagram in dos or clean
|
|
53
53
|
--theme t Publish: take the PNGs light (the default) or dark
|
|
54
54
|
--plane id show: draw this plane (default: the first)
|
|
55
55
|
--layers a,b show: draw these layers in place of the plane's own ('' for none)
|
package/dist/commands/tui.d.ts
CHANGED
package/dist/commands/tui.js
CHANGED
|
@@ -5,13 +5,20 @@ import { screenColorMode } from '../text/ansi.js';
|
|
|
5
5
|
import { runTui, watchSources } from '../tui/app.js';
|
|
6
6
|
import { processTerminal } from '../tui/terminal.js';
|
|
7
7
|
import { LOCKED, sourceOf } from './shared.js';
|
|
8
|
+
/** The styles a terminal draws, which `--style` may name here. */
|
|
9
|
+
const TEXT_STYLES = ['clean', 'dos'];
|
|
8
10
|
/** `diagc tui [name]`: the diagrams in the terminal, live, until it is quit. */
|
|
9
11
|
export const tui = {
|
|
10
|
-
flags: [],
|
|
12
|
+
flags: ['--style'],
|
|
11
13
|
positionals: { max: 1, what: 'one diagram name' },
|
|
12
14
|
// Its compile-watch loop resolves includes locked, as the studio's does.
|
|
13
15
|
whyNot: LOCKED,
|
|
14
|
-
async run({ positionals }, { io, home }) {
|
|
16
|
+
async run({ positionals, flags }, { io, home }) {
|
|
17
|
+
const style = flags['--style'];
|
|
18
|
+
if (style !== undefined && !TEXT_STYLES.includes(style)) {
|
|
19
|
+
io.err(`diagc: the terminal draws the clean and dos styles, not '${style}'`);
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
15
22
|
const name = positionals[0] === undefined ? undefined : diagramName(positionals[0]);
|
|
16
23
|
if (name !== undefined && sourceOf(name) === undefined) {
|
|
17
24
|
io.err(`diagc: no diagram '${name}'`);
|
|
@@ -30,6 +37,7 @@ export const tui = {
|
|
|
30
37
|
...(name !== undefined ? { name } : {}),
|
|
31
38
|
watch: watchSources(srcDir, artifactsDir, home.coreEntry),
|
|
32
39
|
color: screenColorMode(process.env),
|
|
40
|
+
...(style !== undefined ? { style: style } : {}),
|
|
33
41
|
});
|
|
34
42
|
return 0;
|
|
35
43
|
},
|
package/dist/text/ansi.js
CHANGED
|
@@ -59,10 +59,13 @@ function palette256([r, g, b]) {
|
|
|
59
59
|
? 232 + grey
|
|
60
60
|
: 16 + 36 * ri + 6 * gi + bi;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
/** The SGR parameters for `color` as the text's colour, or with `ground` as the cell's
|
|
63
|
+
* background: each code is the foreground's plus ten. */
|
|
64
|
+
function colorCode(color, mode, ground = false) {
|
|
65
|
+
const base = ground ? 10 : 0;
|
|
63
66
|
if ('ansi' in color)
|
|
64
|
-
return String(color.ansi < 8 ? 30 + color.ansi : 90 + color.ansi - 8);
|
|
65
|
-
return mode === 'truecolor' ?
|
|
67
|
+
return String(base + (color.ansi < 8 ? 30 + color.ansi : 90 + color.ansi - 8));
|
|
68
|
+
return mode === 'truecolor' ? `${38 + base};2;${color.rgb.join(';')}` : `${38 + base};5;${palette256(color.rgb)}`;
|
|
66
69
|
}
|
|
67
70
|
/** The escape that sets `style`, or `''` for the plain style. */
|
|
68
71
|
export function sgr(style, mode) {
|
|
@@ -77,11 +80,14 @@ export function sgr(style, mode) {
|
|
|
77
80
|
codes.push('7');
|
|
78
81
|
if (style.fg !== undefined && mode !== 'mono')
|
|
79
82
|
codes.push(colorCode(style.fg, mode));
|
|
83
|
+
if (style.bg !== undefined && mode !== 'mono')
|
|
84
|
+
codes.push(colorCode(style.bg, mode, true));
|
|
80
85
|
return codes.length === 0 ? '' : `\x1b[${codes.join(';')}m`;
|
|
81
86
|
}
|
|
82
87
|
const RESET = '\x1b[0m';
|
|
83
|
-
/** A blank that shows nothing: trailing ones can go. An inverse blank is a bar
|
|
84
|
-
|
|
88
|
+
/** A blank that shows nothing: trailing ones can go. An inverse blank is a bar, and a
|
|
89
|
+
* blank on a background is a patch of it. */
|
|
90
|
+
const invisible = (cell) => cell.ch === ' ' && cell.style.inverse !== true && cell.style.bg === undefined;
|
|
85
91
|
/**
|
|
86
92
|
* The picture as text, one string per row. Trailing blanks are trimmed unless `trim`
|
|
87
93
|
* is false (a full-screen frame keeps its width). A row that set a style ends with a
|
package/dist/text/canvas.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type Color = {
|
|
|
7
7
|
};
|
|
8
8
|
export interface Style {
|
|
9
9
|
fg?: Color;
|
|
10
|
+
/** the cell's background */
|
|
11
|
+
bg?: Color;
|
|
10
12
|
bold?: boolean;
|
|
11
13
|
dim?: boolean;
|
|
12
14
|
inverse?: boolean;
|
|
@@ -39,7 +41,8 @@ export declare class Canvas {
|
|
|
39
41
|
private readonly slots;
|
|
40
42
|
constructor(width: number, height: number);
|
|
41
43
|
private slot;
|
|
42
|
-
/** Adds line directions to a cell. The heavier weight wins a shared cell
|
|
44
|
+
/** Adds line directions to a cell. The heavier weight wins a shared cell, and the
|
|
45
|
+
* directions drawn lighter are kept, for a junction that can show both. */
|
|
43
46
|
stroke({ x, y }: CellPoint, mask: number, weight: Weight, style?: Style): void;
|
|
44
47
|
/** An axis-aligned line from `a` to `b`, both ends included. */
|
|
45
48
|
segment(a: CellPoint, b: CellPoint, weight: Weight, style?: Style): void;
|
|
@@ -47,8 +50,12 @@ export declare class Canvas {
|
|
|
47
50
|
rect({ x, y, width, height }: CellRect, weight: Weight, style?: Style, corner?: Corner): void;
|
|
48
51
|
/** Blanks a rectangle: what was drawn there, lines included, is gone. */
|
|
49
52
|
clear({ x, y, width, height }: CellRect): void;
|
|
50
|
-
/** Puts one character in a cell, over whatever was there. */
|
|
53
|
+
/** Puts one character in a cell, over whatever was there but its ground. */
|
|
51
54
|
put({ x, y }: CellPoint, ch: string, style?: Style): void;
|
|
55
|
+
/** Lays a style under a rectangle: what is drawn there, before or after, takes its
|
|
56
|
+
* colours where it sets none of its own. A box's fill is its ground, which the text
|
|
57
|
+
* written in it keeps. `clear` takes the ground away with the rest. */
|
|
58
|
+
ground({ x, y, width, height }: CellRect, style: Style): void;
|
|
52
59
|
/**
|
|
53
60
|
* Writes `text` from (x, y) rightwards, stopping before `maxX` (exclusive) or the
|
|
54
61
|
* edge, and never splitting a wide character. A combining mark joins the cell
|
package/dist/text/canvas.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DOWN, LEFT, RIGHT, UP } from './glyphs.js';
|
|
2
2
|
import { charWidth, isControl } from './width.js';
|
|
3
|
-
const RANK = { dashed: 0, light: 1, heavy: 2 };
|
|
4
|
-
const blank = () => ({ ch: ' ', style: {}, mask: 0, weight: 'dashed' });
|
|
3
|
+
const RANK = { dashed: 0, light: 1, heavy: 2, double: 3 };
|
|
4
|
+
const blank = () => ({ ch: ' ', style: {}, mask: 0, weight: 'dashed', top: 0 });
|
|
5
5
|
/**
|
|
6
6
|
* A grid of character cells that lines, boxes and text are drawn into. Lines are
|
|
7
7
|
* kept as direction masks until `cells` resolves them, so whatever meets in a cell
|
|
@@ -21,7 +21,8 @@ export class Canvas {
|
|
|
21
21
|
slot(x, y) {
|
|
22
22
|
return this.slots[y]?.[x];
|
|
23
23
|
}
|
|
24
|
-
/** Adds line directions to a cell. The heavier weight wins a shared cell
|
|
24
|
+
/** Adds line directions to a cell. The heavier weight wins a shared cell, and the
|
|
25
|
+
* directions drawn lighter are kept, for a junction that can show both. */
|
|
25
26
|
stroke({ x, y }, mask, weight, style) {
|
|
26
27
|
const s = this.slot(x, y);
|
|
27
28
|
if (s === undefined)
|
|
@@ -31,7 +32,9 @@ export class Canvas {
|
|
|
31
32
|
this.unwide(x, y);
|
|
32
33
|
s.mask |= mask;
|
|
33
34
|
if (was === 0 || RANK[weight] > RANK[s.weight])
|
|
34
|
-
s.weight = weight;
|
|
35
|
+
[s.weight, s.top] = [weight, mask];
|
|
36
|
+
else if (weight === s.weight)
|
|
37
|
+
s.top |= mask;
|
|
35
38
|
if (style !== undefined)
|
|
36
39
|
s.style = style;
|
|
37
40
|
}
|
|
@@ -83,13 +86,25 @@ export class Canvas {
|
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
|
-
/** Puts one character in a cell, over whatever was there. */
|
|
89
|
+
/** Puts one character in a cell, over whatever was there but its ground. */
|
|
87
90
|
put({ x, y }, ch, style = {}) {
|
|
88
91
|
const s = this.slot(x, y);
|
|
89
92
|
if (s === undefined)
|
|
90
93
|
return;
|
|
91
94
|
this.unwide(x, y);
|
|
92
|
-
this.slots[y][x] = { ch, style, mask: 0, weight: 'dashed' };
|
|
95
|
+
this.slots[y][x] = { ch, style, mask: 0, weight: 'dashed', top: 0, ...(s.ground ? { ground: s.ground } : {}) };
|
|
96
|
+
}
|
|
97
|
+
/** Lays a style under a rectangle: what is drawn there, before or after, takes its
|
|
98
|
+
* colours where it sets none of its own. A box's fill is its ground, which the text
|
|
99
|
+
* written in it keeps. `clear` takes the ground away with the rest. */
|
|
100
|
+
ground({ x, y, width, height }, style) {
|
|
101
|
+
for (let cy = y; cy < y + height; cy++) {
|
|
102
|
+
for (let cx = x; cx < x + width; cx++) {
|
|
103
|
+
const s = this.slot(cx, cy);
|
|
104
|
+
if (s !== undefined)
|
|
105
|
+
s.ground = style;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
93
108
|
}
|
|
94
109
|
/**
|
|
95
110
|
* Writes `text` from (x, y) rightwards, stopping before `maxX` (exclusive) or the
|
|
@@ -134,7 +149,10 @@ export class Canvas {
|
|
|
134
149
|
}
|
|
135
150
|
/** The finished picture, lines resolved with `glyphs`. */
|
|
136
151
|
cells(glyphs) {
|
|
137
|
-
return this.slots.map((row) => row.map((s) => ({
|
|
152
|
+
return this.slots.map((row) => row.map((s) => ({
|
|
153
|
+
ch: s.mask === 0 ? s.ch : glyphs.line(s.mask, s.weight, s.corner, s.mask & ~s.top),
|
|
154
|
+
style: s.ground === undefined ? s.style : { ...s.ground, ...s.style },
|
|
155
|
+
})));
|
|
138
156
|
}
|
|
139
157
|
/** Before a cell is overwritten: if it is half of a wide character, blank the other
|
|
140
158
|
* half, so no orphaned half is left to shift the rest of the row. */
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { DiagramModel, NotationId } from '@diagc/core/internal';
|
|
2
|
+
import type { Canvas, CellRect, Color, Style } from './canvas.js';
|
|
3
|
+
import { type TextShape } from './vocabulary.js';
|
|
4
|
+
/** The styles a terminal draws: its own, and DOS. The rest are the browser's. */
|
|
5
|
+
export type TextStyle = 'clean' | 'dos';
|
|
6
|
+
/** The style a diagram asks to be drawn in, as far as a terminal has it. */
|
|
7
|
+
export declare const styleOf: (model: Pick<DiagramModel, "style">) => TextStyle;
|
|
8
|
+
/** CGA's light colours, the boxes' by type in slot order: every one takes black text. */
|
|
9
|
+
export declare const DOS_PALETTE: readonly string[];
|
|
10
|
+
/** A colour a palette or an author wrote down, as against one of the terminal's own. */
|
|
11
|
+
export type Rgb = Extract<Color, {
|
|
12
|
+
rgb: unknown;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const BLUE: {
|
|
15
|
+
rgb: [number, number, number];
|
|
16
|
+
};
|
|
17
|
+
export declare const WHITE: {
|
|
18
|
+
rgb: [number, number, number];
|
|
19
|
+
};
|
|
20
|
+
export declare const BLACK: {
|
|
21
|
+
rgb: [number, number, number];
|
|
22
|
+
};
|
|
23
|
+
export declare const GREY: {
|
|
24
|
+
rgb: [number, number, number];
|
|
25
|
+
};
|
|
26
|
+
export declare const CYAN: {
|
|
27
|
+
rgb: [number, number, number];
|
|
28
|
+
};
|
|
29
|
+
export declare const YELLOW: {
|
|
30
|
+
rgb: [number, number, number];
|
|
31
|
+
};
|
|
32
|
+
export declare const RED: {
|
|
33
|
+
rgb: [number, number, number];
|
|
34
|
+
};
|
|
35
|
+
/** What the picture, and the screen round it, lie on. */
|
|
36
|
+
export declare const DESKTOP: Style;
|
|
37
|
+
/** A box's block shadow: what it falls on, dark grey on black, as Turbo Vision casts it. */
|
|
38
|
+
export declare const SHADOW: Style;
|
|
39
|
+
/** How far right and down the shadow falls: two columns to one row, a cell being about
|
|
40
|
+
* twice as tall as it is wide. */
|
|
41
|
+
export declare const SHADOW_REACH: {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Each node type's palette slot, as the renderer's `typeSlots` gives it: by first
|
|
47
|
+
* appearance, the types of the nodes that contain nothing first, and the types a
|
|
48
|
+
* notation fills alike (C4's containers) sharing one. Counted over the whole model, so
|
|
49
|
+
* a drill or a plane switch never recolours a box.
|
|
50
|
+
*/
|
|
51
|
+
export declare function dosSlots(model: Pick<DiagramModel, 'nodes' | 'containment'>, notation?: NotationId): Map<string, number>;
|
|
52
|
+
/** A box's colour: its own (`css`, as the author or the notation set it), else its
|
|
53
|
+
* type's from the palette; nothing for an untyped box, which is grey. */
|
|
54
|
+
export declare function dosHue(css: string | undefined, type: string | undefined, slots: ReadonlyMap<string, number>): Rgb;
|
|
55
|
+
/** A box's fill, as its type's legend swatch shows it too: its colour (`dosHue`), but a
|
|
56
|
+
* table's body grey under its cyan head, as the page draws one. */
|
|
57
|
+
export declare const dosFill: (shape: TextShape, css: string | undefined, type: string | undefined, slots: ReadonlyMap<string, number>) => Rgb;
|
|
58
|
+
/** Black or white, whichever reads on `rgb`: the renderer's `hueInk`. */
|
|
59
|
+
export declare function inkOn([r, g, b]: readonly number[]): Rgb;
|
|
60
|
+
/** `share` of `a` over `b`: a box's small print, its ink 70% over its fill as the page
|
|
61
|
+
* mixes it. */
|
|
62
|
+
export declare const mixed: (a: readonly number[], b: readonly number[], share: number) => Rgb;
|
|
63
|
+
/**
|
|
64
|
+
* Each box's block shadow, laid as the ground beside it and below it before anything is
|
|
65
|
+
* drawn there: a line, which takes its colour from the ground, is shaded with it, while
|
|
66
|
+
* an arrowhead or a label, drawn in a colour of its own, stays bright on the black. A
|
|
67
|
+
* box drawn over another's shadow lays its own ground.
|
|
68
|
+
*/
|
|
69
|
+
export declare function castShadows(canvas: Canvas, boxes: readonly CellRect[]): void;
|
package/dist/text/dos.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { parseColor } from './ansi.js';
|
|
2
|
+
import { typeLook } from './vocabulary.js';
|
|
3
|
+
/** The style a diagram asks to be drawn in, as far as a terminal has it. */
|
|
4
|
+
export const styleOf = (model) => (model.style === 'dos' ? 'dos' : 'clean');
|
|
5
|
+
/** CGA's light colours, the boxes' by type in slot order: every one takes black text. */
|
|
6
|
+
export const DOS_PALETTE = [
|
|
7
|
+
'#aaaaaa',
|
|
8
|
+
'#00aaaa',
|
|
9
|
+
'#00aa00',
|
|
10
|
+
'#55ffff',
|
|
11
|
+
'#ffff55',
|
|
12
|
+
'#55ff55',
|
|
13
|
+
'#ff55ff',
|
|
14
|
+
'#ff5555',
|
|
15
|
+
];
|
|
16
|
+
const cga = (css) => ({ rgb: parseColor(css) });
|
|
17
|
+
export const BLUE = cga('#0000aa');
|
|
18
|
+
export const WHITE = cga('#ffffff');
|
|
19
|
+
export const BLACK = cga('#000000');
|
|
20
|
+
export const GREY = cga('#aaaaaa');
|
|
21
|
+
export const CYAN = cga('#00aaaa');
|
|
22
|
+
export const YELLOW = cga('#ffff55');
|
|
23
|
+
export const RED = cga('#aa0000');
|
|
24
|
+
const DARK_GREY = cga('#555555');
|
|
25
|
+
/** What the picture, and the screen round it, lie on. */
|
|
26
|
+
export const DESKTOP = { bg: BLUE, fg: WHITE };
|
|
27
|
+
/** A box's block shadow: what it falls on, dark grey on black, as Turbo Vision casts it. */
|
|
28
|
+
export const SHADOW = { bg: BLACK, fg: DARK_GREY };
|
|
29
|
+
/** How far right and down the shadow falls: two columns to one row, a cell being about
|
|
30
|
+
* twice as tall as it is wide. */
|
|
31
|
+
export const SHADOW_REACH = { x: 2, y: 1 };
|
|
32
|
+
/**
|
|
33
|
+
* Each node type's palette slot, as the renderer's `typeSlots` gives it: by first
|
|
34
|
+
* appearance, the types of the nodes that contain nothing first, and the types a
|
|
35
|
+
* notation fills alike (C4's containers) sharing one. Counted over the whole model, so
|
|
36
|
+
* a drill or a plane switch never recolours a box.
|
|
37
|
+
*/
|
|
38
|
+
export function dosSlots(model, notation) {
|
|
39
|
+
const parents = new Set(model.containment.map((e) => e.parent));
|
|
40
|
+
const ordered = [...model.nodes.filter((n) => !parents.has(n.id)), ...model.nodes.filter((n) => parents.has(n.id))];
|
|
41
|
+
const byKey = new Map();
|
|
42
|
+
const slots = new Map();
|
|
43
|
+
for (const n of ordered) {
|
|
44
|
+
if (n.type === undefined || slots.has(n.type))
|
|
45
|
+
continue;
|
|
46
|
+
// a notation's fill is the accent the text vocabulary keeps for the type
|
|
47
|
+
const key = typeLook(n.type, notation).accent ?? `type:${n.type}`;
|
|
48
|
+
const slot = byKey.get(key) ?? byKey.size;
|
|
49
|
+
byKey.set(key, slot);
|
|
50
|
+
slots.set(n.type, slot);
|
|
51
|
+
}
|
|
52
|
+
return slots;
|
|
53
|
+
}
|
|
54
|
+
/** A box's colour: its own (`css`, as the author or the notation set it), else its
|
|
55
|
+
* type's from the palette; nothing for an untyped box, which is grey. */
|
|
56
|
+
export function dosHue(css, type, slots) {
|
|
57
|
+
const own = css === undefined ? undefined : parseColor(css);
|
|
58
|
+
if (own !== undefined)
|
|
59
|
+
return { rgb: own };
|
|
60
|
+
const slot = type === undefined ? undefined : slots.get(type);
|
|
61
|
+
return slot === undefined ? GREY : cga(DOS_PALETTE[slot % DOS_PALETTE.length]);
|
|
62
|
+
}
|
|
63
|
+
/** A box's fill, as its type's legend swatch shows it too: its colour (`dosHue`), but a
|
|
64
|
+
* table's body grey under its cyan head, as the page draws one. */
|
|
65
|
+
export const dosFill = (shape, css, type, slots) => (shape === 'table' ? GREY : dosHue(css, type, slots));
|
|
66
|
+
/** Black or white, whichever reads on `rgb`: the renderer's `hueInk`. */
|
|
67
|
+
export function inkOn([r, g, b]) {
|
|
68
|
+
const linear = (v) => {
|
|
69
|
+
const c = v / 255;
|
|
70
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
71
|
+
};
|
|
72
|
+
// 0.179 is the luminance at which black and white text contrast equally
|
|
73
|
+
return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b) > 0.179 ? BLACK : WHITE;
|
|
74
|
+
}
|
|
75
|
+
/** `share` of `a` over `b`: a box's small print, its ink 70% over its fill as the page
|
|
76
|
+
* mixes it. */
|
|
77
|
+
export const mixed = (a, b, share) => ({
|
|
78
|
+
rgb: [0, 1, 2].map((i) => Math.round(a[i] * share + b[i] * (1 - share))),
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Each box's block shadow, laid as the ground beside it and below it before anything is
|
|
82
|
+
* drawn there: a line, which takes its colour from the ground, is shaded with it, while
|
|
83
|
+
* an arrowhead or a label, drawn in a colour of its own, stays bright on the black. A
|
|
84
|
+
* box drawn over another's shadow lays its own ground.
|
|
85
|
+
*/
|
|
86
|
+
export function castShadows(canvas, boxes) {
|
|
87
|
+
const { x: dx, y: dy } = SHADOW_REACH;
|
|
88
|
+
for (const b of boxes) {
|
|
89
|
+
const [right, bottom] = [b.x + b.width, b.y + b.height];
|
|
90
|
+
canvas.ground({ x: right, y: b.y + dy, width: dx, height: b.height }, SHADOW);
|
|
91
|
+
canvas.ground({ x: b.x + dx, y: bottom, width: b.width - dx, height: dy }, SHADOW);
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/text/glyphs.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ export declare const UP = 1;
|
|
|
3
3
|
export declare const DOWN = 2;
|
|
4
4
|
export declare const LEFT = 4;
|
|
5
5
|
export declare const RIGHT = 8;
|
|
6
|
-
export type Weight = 'light' | 'heavy' | 'dashed';
|
|
6
|
+
export type Weight = 'light' | 'heavy' | 'dashed' | 'double';
|
|
7
7
|
export type Corner = 'round' | 'chamfer';
|
|
8
8
|
export type ArrowDirection = 'up' | 'down' | 'left' | 'right';
|
|
9
9
|
export interface Glyphs {
|
|
10
10
|
/** the character for a cell whose lines leave it in `mask`'s directions; `corner`
|
|
11
|
-
* applies only while the mask is a plain corner
|
|
12
|
-
|
|
11
|
+
* applies only while the mask is a plain corner, and `minor` names the directions
|
|
12
|
+
* drawn lighter than `weight`, which only a double line has characters to show */
|
|
13
|
+
line(mask: number, weight: Weight, corner?: Corner, minor?: number): string;
|
|
13
14
|
arrow(direction: ArrowDirection): string;
|
|
14
15
|
/** a line one cell a row, a fishbone's bone or tick: falling to the right, or rising */
|
|
15
16
|
slant(falling: boolean): string;
|
package/dist/text/glyphs.js
CHANGED
|
@@ -15,6 +15,20 @@ function table(chars) {
|
|
|
15
15
|
const LIGHT = table(' │││─┘┐┤─└┌├─┴┬┼');
|
|
16
16
|
const HEAVY = table(' ┃┃┃━┛┓┫━┗┏┣━┻┳╋');
|
|
17
17
|
const CORNERS = new Set([DOWN | RIGHT, DOWN | LEFT, UP | RIGHT, UP | LEFT]);
|
|
18
|
+
const DOUBLE = table(' ║║║═╝╗╣═╚╔╠═╩╦╬');
|
|
19
|
+
// The mixed junctions: double one way and single the other. Unicode has them only
|
|
20
|
+
// whole, so a line is double along an axis when any of its directions there is.
|
|
21
|
+
const DOUBLE_ACROSS = table(' │││═╛╕╡═╘╒╞═╧╤╪');
|
|
22
|
+
const DOUBLE_DOWN = table(' ║║║─╜╖╢─╙╓╟─╨╥╫');
|
|
23
|
+
/** A double line, with what joins it single where `minor` says. */
|
|
24
|
+
function double(mask, minor) {
|
|
25
|
+
const strong = mask & ~minor;
|
|
26
|
+
const across = (strong & (LEFT | RIGHT)) !== 0;
|
|
27
|
+
const down = (strong & (UP | DOWN)) !== 0;
|
|
28
|
+
if (across === down)
|
|
29
|
+
return across ? DOUBLE(mask) : LIGHT(mask);
|
|
30
|
+
return across ? DOUBLE_ACROSS(mask) : DOUBLE_DOWN(mask);
|
|
31
|
+
}
|
|
18
32
|
const ROUND = { [DOWN | RIGHT]: '╭', [DOWN | LEFT]: '╮', [UP | RIGHT]: '╰', [UP | LEFT]: '╯' };
|
|
19
33
|
const CHAMFER = {
|
|
20
34
|
[DOWN | RIGHT]: '╱',
|
|
@@ -23,7 +37,9 @@ const CHAMFER = {
|
|
|
23
37
|
[UP | LEFT]: '╱',
|
|
24
38
|
};
|
|
25
39
|
export const UNICODE = {
|
|
26
|
-
line(mask, weight, corner) {
|
|
40
|
+
line(mask, weight, corner, minor = 0) {
|
|
41
|
+
if (weight === 'double')
|
|
42
|
+
return double(mask, minor);
|
|
27
43
|
if (corner !== undefined && CORNERS.has(mask))
|
|
28
44
|
return (corner === 'round' ? ROUND : CHAMFER)[mask];
|
|
29
45
|
if (weight === 'heavy')
|
|
@@ -68,7 +84,7 @@ export const ASCII = {
|
|
|
68
84
|
if (vertical)
|
|
69
85
|
return weight === 'dashed' ? ':' : '|';
|
|
70
86
|
if (horizontal)
|
|
71
|
-
return weight === 'dashed' ? '.' : weight === 'heavy' ? '=' : '-';
|
|
87
|
+
return weight === 'dashed' ? '.' : weight === 'heavy' || weight === 'double' ? '=' : '-';
|
|
72
88
|
return '+';
|
|
73
89
|
},
|
|
74
90
|
arrow: (direction) => ({ up: '^', down: 'v', left: '<', right: '>' })[direction],
|
package/dist/text/layout.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ export interface TextLayout {
|
|
|
47
47
|
* root and on every container alike.
|
|
48
48
|
*/
|
|
49
49
|
export declare const CELL_OPTIONS: Readonly<Record<string, string>>;
|
|
50
|
+
/** How the cells are laid out: the way the plane flows, and how far right and down a
|
|
51
|
+
* box's shadow falls where the style casts one (DOS), which keeps it off a frame. */
|
|
52
|
+
export interface Flow {
|
|
53
|
+
direction: string;
|
|
54
|
+
shadow?: {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
50
59
|
/** Where a box is from an end of a route that stops beside it: the direction (a
|
|
51
60
|
* glyph mask bit) to step from the end to reach its border; undefined when the end is
|
|
52
61
|
* not beside it. */
|
|
@@ -58,4 +67,4 @@ export declare const STEP: Readonly<Record<number, CellPoint>>;
|
|
|
58
67
|
* so that turning a layer on or off never moves a box (the renderer's rule); the
|
|
59
68
|
* routes of the edges actually drawn are picked from the result by id.
|
|
60
69
|
*/
|
|
61
|
-
export declare function layoutCells(view: CompiledView, boxes: ReadonlyMap<string, BoxText>,
|
|
70
|
+
export declare function layoutCells(view: CompiledView, boxes: ReadonlyMap<string, BoxText>, flow: Flow, labels: ReadonlyMap<string, string>): Promise<TextLayout>;
|
package/dist/text/layout.js
CHANGED
|
@@ -25,8 +25,9 @@ export const CELL_OPTIONS = {
|
|
|
25
25
|
'elk.separateConnectedComponents': 'true',
|
|
26
26
|
};
|
|
27
27
|
/** Inside a container's frame: the title row and a blank one above the children, a
|
|
28
|
-
* row below, two columns either side
|
|
29
|
-
|
|
28
|
+
* row below, two columns either side, and the reach of a child's shadow beyond that,
|
|
29
|
+
* as the page's padding holds it. */
|
|
30
|
+
const containerPadding = ({ x, y } = { x: 0, y: 0 }) => `[top=2,left=2,bottom=${1 + y},right=${2 + x}]`;
|
|
30
31
|
/** The gaps for a flow. A cell is about twice as tall as it is wide, so a sideways
|
|
31
32
|
* flow's gap between neighbours, counted in rows, is half a downward one's, counted in
|
|
32
33
|
* columns, and its gap between levels twice: turned, the boxes keep their spacing. Only
|
|
@@ -38,7 +39,8 @@ function cellOptions(direction) {
|
|
|
38
39
|
return { ...CELL_OPTIONS, 'elk.spacing.nodeNode': '2', 'elk.layered.spacing.nodeNodeBetweenLayers': '4' };
|
|
39
40
|
}
|
|
40
41
|
const elk = new ELK();
|
|
41
|
-
function elkNode(vn, boxes,
|
|
42
|
+
function elkNode(vn, boxes, flow) {
|
|
43
|
+
const { direction } = flow;
|
|
42
44
|
const box = boxes.get(vn.id);
|
|
43
45
|
const width = box?.width ?? 5;
|
|
44
46
|
const height = box?.height ?? 3;
|
|
@@ -54,11 +56,11 @@ function elkNode(vn, boxes, direction) {
|
|
|
54
56
|
layoutOptions: {
|
|
55
57
|
...cellOptions(direction),
|
|
56
58
|
'elk.direction': direction,
|
|
57
|
-
'elk.padding':
|
|
59
|
+
'elk.padding': containerPadding(flow.shadow),
|
|
58
60
|
'elk.nodeSize.constraints': 'MINIMUM_SIZE',
|
|
59
61
|
'elk.nodeSize.minimum': vertical ? `(${height}, ${width})` : `(${width}, ${height})`,
|
|
60
62
|
},
|
|
61
|
-
children: vn.children.map((c) => elkNode(c, boxes,
|
|
63
|
+
children: vn.children.map((c) => elkNode(c, boxes, flow)),
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
66
|
function elkEdges(view, labels) {
|
|
@@ -309,7 +311,8 @@ function normalize(boxes, routes) {
|
|
|
309
311
|
* so that turning a layer on or off never moves a box (the renderer's rule); the
|
|
310
312
|
* routes of the edges actually drawn are picked from the result by id.
|
|
311
313
|
*/
|
|
312
|
-
export async function layoutCells(view, boxes,
|
|
314
|
+
export async function layoutCells(view, boxes, flow, labels) {
|
|
315
|
+
const { direction } = flow;
|
|
313
316
|
if (view.roots.length === 0)
|
|
314
317
|
return { width: 0, height: 0, boxes: new Map(), routes: new Map() };
|
|
315
318
|
const graph = {
|
|
@@ -320,7 +323,7 @@ export async function layoutCells(view, boxes, direction, labels) {
|
|
|
320
323
|
'elk.padding': '[top=0,left=0,bottom=0,right=0]',
|
|
321
324
|
'elk.hierarchyHandling': 'INCLUDE_CHILDREN',
|
|
322
325
|
},
|
|
323
|
-
children: view.roots.map((vn) => elkNode(vn, boxes,
|
|
326
|
+
children: view.roots.map((vn) => elkNode(vn, boxes, flow)),
|
|
324
327
|
edges: elkEdges(view, labels),
|
|
325
328
|
};
|
|
326
329
|
const laid = collect(await elk.layout(graph));
|
package/dist/text/legend.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { buildHierarchy, presetLayers, relationLayer, relationOnPlane, scopeToRoot, } from '@diagc/core/internal';
|
|
2
2
|
import { Canvas } from './canvas.js';
|
|
3
3
|
import { typeMark } from './content.js';
|
|
4
|
+
import { dosFill, dosSlots } from './dos.js';
|
|
4
5
|
import { DOWN, LEFT, RIGHT } from './glyphs.js';
|
|
5
|
-
import { accentCss, CORNER, rgb, WEIGHT } from './paint.js';
|
|
6
|
+
import { accentCss, colorCss, CORNER, rgb, WEIGHT } from './paint.js';
|
|
6
7
|
import { KIND_LOOKS, kindLook, TYPE_LOOKS, typeLook } from './vocabulary.js';
|
|
7
8
|
import { cellWidth, fitCells, printable } from './width.js';
|
|
8
9
|
/** A swatch's cells: three, the width of a line with a mark at each end. */
|
|
@@ -53,13 +54,14 @@ function lineSwatch(look, glyphs) {
|
|
|
53
54
|
return `${end(look.start, 'left')}${line}${end(look.end, 'right')}`;
|
|
54
55
|
}
|
|
55
56
|
/** A box of the type as the picture draws it: the mark its name follows where it has
|
|
56
|
-
* one, else the top of its border, which carries its corners and its dashes
|
|
57
|
-
|
|
57
|
+
* one, else the top of its border, which carries its corners and its dashes (in `dos`,
|
|
58
|
+
* square and double). */
|
|
59
|
+
function shapeSwatch(type, look, glyphs, dos) {
|
|
58
60
|
const mark = typeMark(type, look.shape, glyphs);
|
|
59
61
|
if (mark !== undefined)
|
|
60
62
|
return centre(mark);
|
|
61
|
-
const weight = look.shape === 'bar' ? 'heavy' : look.dashed === true ? 'dashed' : 'light';
|
|
62
|
-
const corner = CORNER[look.shape];
|
|
63
|
+
const weight = look.shape === 'bar' ? 'heavy' : look.dashed === true ? 'dashed' : dos ? 'double' : 'light';
|
|
64
|
+
const corner = dos ? undefined : CORNER[look.shape];
|
|
63
65
|
return `${glyphs.line(DOWN | RIGHT, weight, corner)}${glyphs.line(LEFT | RIGHT, weight)}${glyphs.line(DOWN | LEFT, weight, corner)}`;
|
|
64
66
|
}
|
|
65
67
|
const vocabulary = (caption) => caption !== undefined ? { vocabulary: true } : {};
|
|
@@ -121,17 +123,18 @@ function kindRows(scene, glyphs) {
|
|
|
121
123
|
}
|
|
122
124
|
function typeRows(scene, glyphs) {
|
|
123
125
|
const { model } = scene.input;
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
const slots = scene.input.style === 'dos' ? dosSlots(model, scene.notation) : undefined;
|
|
127
|
+
// a DOS box is filled in its own colour or its type's slot, never the notation's accent
|
|
128
|
+
const css = (node) => slots === undefined ? accentCss(model, node, scene.notation, scene.accents) : colorCss(model, node, scene.accents);
|
|
129
|
+
const accents = agreed([...scene.nodes.values()].flatMap((vn) => vn.node.type === undefined ? [] : [[vn.node.type, css(vn.node)]]));
|
|
127
130
|
return ordered(accents.keys(), Object.keys(TYPE_LOOKS)).map((type) => {
|
|
128
131
|
const look = typeLook(type, scene.notation);
|
|
129
132
|
// `label: ''` keeps a glyph type's box free of a subtitle; it is not a caption
|
|
130
133
|
const label = look.legend ?? (look.label === undefined || look.label === '' ? printable(type) : look.label);
|
|
131
134
|
return {
|
|
132
135
|
id: `types:${type}`,
|
|
133
|
-
swatch: shapeSwatch(type, look, glyphs),
|
|
134
|
-
style: colour(accents.get(type)),
|
|
136
|
+
swatch: shapeSwatch(type, look, glyphs, slots !== undefined),
|
|
137
|
+
style: slots === undefined ? colour(accents.get(type)) : { fg: dosFill(look.shape, accents.get(type), type, slots) },
|
|
135
138
|
label,
|
|
136
139
|
...vocabulary(look.legend),
|
|
137
140
|
};
|
|
@@ -156,7 +159,8 @@ function markRows(scene) {
|
|
|
156
159
|
}
|
|
157
160
|
/** The hand-written rows. One naming a kind or a type already keyed recaptions that row
|
|
158
161
|
* in place, keeping its swatch; the rest are rows of their own. */
|
|
159
|
-
function itemRows(items, derived,
|
|
162
|
+
function itemRows(items, derived, scene, glyphs) {
|
|
163
|
+
const { notation } = scene;
|
|
160
164
|
return items.flatMap((item, i) => {
|
|
161
165
|
const label = printable(item.label);
|
|
162
166
|
const target = item.kind !== undefined ? `kinds:${item.kind}` : item.type !== undefined ? `types:${item.type}` : '';
|
|
@@ -170,7 +174,7 @@ function itemRows(items, derived, notation, glyphs) {
|
|
|
170
174
|
const swatch = item.kind !== undefined
|
|
171
175
|
? lineSwatch(kindLook({ kind: item.kind }, notation), glyphs)
|
|
172
176
|
: item.type !== undefined
|
|
173
|
-
? shapeSwatch(item.type, typeLook(item.type, notation), glyphs)
|
|
177
|
+
? shapeSwatch(item.type, typeLook(item.type, notation), glyphs, scene.input.style === 'dos')
|
|
174
178
|
: item.color !== undefined
|
|
175
179
|
? centre(glyphs.mark('square'))
|
|
176
180
|
: centre('');
|
|
@@ -195,7 +199,7 @@ export function legendOf(scene, glyphs) {
|
|
|
195
199
|
types,
|
|
196
200
|
marks: shown.includes('marks') ? markRows(scene) : [],
|
|
197
201
|
};
|
|
198
|
-
const items = itemRows(config.items ?? [], [...derived.kinds, ...derived.types], scene
|
|
202
|
+
const items = itemRows(config.items ?? [], [...derived.kinds, ...derived.types], scene, glyphs);
|
|
199
203
|
const sections = ['layers', 'kinds', 'types', 'marks', 'items']
|
|
200
204
|
.map((s) => ({ title: TITLES[s], rows: s === 'items' ? items : derived[s] }))
|
|
201
205
|
.filter((s) => s.rows.length > 0);
|
package/dist/text/paint.d.ts
CHANGED
|
@@ -12,14 +12,16 @@ export interface PaintOptions {
|
|
|
12
12
|
export declare const WEIGHT: Record<LineStyle, Weight>;
|
|
13
13
|
export declare const CORNER: Partial<Record<TextShape, Corner>>;
|
|
14
14
|
export declare const rgb: (css: string | undefined) => Color | undefined;
|
|
15
|
-
/** A node's
|
|
16
|
-
* gives it (a lane's, a bone's), the model's
|
|
17
|
-
|
|
15
|
+
/** A node's own colour, as the renderer resolves it: its own, the one its notation
|
|
16
|
+
* gives it (a lane's, a bone's), the model's for its type (or for every type). */
|
|
17
|
+
export declare function colorCss(model: DiagramModel, node: DiagramNode, accents: Accents): string | undefined;
|
|
18
|
+
/** A node's accent: its own colour, then the notation's for the type. */
|
|
18
19
|
export declare function accentCss(model: DiagramModel, node: DiagramNode, notation: NotationId | undefined, accents: Accents): string | undefined;
|
|
19
20
|
/**
|
|
20
21
|
* The scene as a canvas, in layers: open containers' frames from the outside in,
|
|
21
22
|
* then the edges' lines, then the boxes over them (a box clears what is under it)
|
|
22
23
|
* and the frames' titles, then edge labels and the ends of the edges, last so
|
|
23
|
-
* nothing covers an arrowhead.
|
|
24
|
+
* nothing covers an arrowhead. In the DOS style (the scene's `style`) it all lies on
|
|
25
|
+
* the desktop, the boxes' shadows laid on it first.
|
|
24
26
|
*/
|
|
25
27
|
export declare function paint(scene: Scene, options: PaintOptions): Canvas;
|