@diagc/cli 1.6.0 → 1.8.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/assets/guide/git-graph.md +3 -0
- package/assets/guide/index.md +3 -3
- package/assets/skill/SKILL.md +1 -1
- package/assets/studio/assets/index-CB6jjAka.js +112 -0
- package/assets/studio/index.html +1 -1
- package/assets/viewer/index.html +23 -23
- package/dist/cli/parse.d.ts +8 -1
- package/dist/cli/parse.js +13 -1
- package/dist/cli/run.js +6 -2
- package/dist/cli.js +6 -2
- package/dist/commands/show.d.ts +1 -1
- package/dist/commands/show.js +12 -2
- 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/git.d.ts +52 -0
- package/dist/text/git.js +274 -0
- package/dist/text/glyphs.d.ts +4 -3
- package/dist/text/glyphs.js +18 -2
- package/dist/text/layout.d.ts +39 -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 +164 -17
- package/dist/text/scene.d.ts +7 -0
- package/dist/text/scene.js +16 -4
- package/dist/tui/actions.d.ts +5 -0
- package/dist/tui/actions.js +17 -2
- 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 +105 -23
- package/dist/tui/state.d.ts +14 -10
- package/dist/tui/state.js +13 -4
- package/package.json +2 -2
- package/assets/studio/assets/index-DRsUukzt.js +0 -112
package/dist/cli/parse.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface FlagValues {
|
|
|
15
15
|
'--layers': string[];
|
|
16
16
|
'--depth': number;
|
|
17
17
|
'--root': string;
|
|
18
|
+
'--horizontal': true;
|
|
18
19
|
'--ascii': true;
|
|
19
20
|
'--color': true;
|
|
20
21
|
'--no-color': true;
|
|
@@ -46,13 +47,19 @@ export declare class UsageError extends Error {
|
|
|
46
47
|
readonly exitCode: number;
|
|
47
48
|
constructor(message: string, exitCode: number);
|
|
48
49
|
}
|
|
50
|
+
/** `--version`: the run prints the version, whatever else argv says after it, and ends
|
|
51
|
+
* with exit 0. */
|
|
52
|
+
export declare class VersionRequest extends Error {
|
|
53
|
+
constructor();
|
|
54
|
+
}
|
|
49
55
|
/** The style presets `--style` takes: the renderer's, by id and in its order. The CLI
|
|
50
56
|
* cannot import the renderer (it only couples to the viewer as a built artifact), so
|
|
51
57
|
* the list is written out and styleIds.test.ts pins it to the renderer's. */
|
|
52
58
|
export declare const STYLE_IDS: string[];
|
|
53
59
|
/** Read argv against every flag there is, whichever command it names: which arguments
|
|
54
60
|
* are values depends on the flags alone, and the command may come after its flags. The
|
|
55
|
-
* first mistake in argv's order is thrown as a {@link UsageError}
|
|
61
|
+
* first mistake in argv's order is thrown as a {@link UsageError}, and so is `--help`;
|
|
62
|
+
* `--version` is a {@link VersionRequest}. An unknown flag is an
|
|
56
63
|
* error rather than a file path, so a typo surfaces loudly instead of quietly skewing
|
|
57
64
|
* the file set. */
|
|
58
65
|
export declare function parseArgv(argv: readonly string[]): ParsedArgv;
|
package/dist/cli/parse.js
CHANGED
|
@@ -10,6 +10,14 @@ export class UsageError extends Error {
|
|
|
10
10
|
this.name = 'UsageError';
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
/** `--version`: the run prints the version, whatever else argv says after it, and ends
|
|
14
|
+
* with exit 0. */
|
|
15
|
+
export class VersionRequest extends Error {
|
|
16
|
+
constructor() {
|
|
17
|
+
super('version requested');
|
|
18
|
+
this.name = 'VersionRequest';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
13
21
|
const badValue = (flag, why) => new UsageError(`${flag}: ${why}`, 1);
|
|
14
22
|
/** The style presets `--style` takes: the renderer's, by id and in its order. The CLI
|
|
15
23
|
* cannot import the renderer (it only couples to the viewer as a built artifact), so
|
|
@@ -109,6 +117,7 @@ const FLAGS = {
|
|
|
109
117
|
return Number(next);
|
|
110
118
|
},
|
|
111
119
|
'--root': required('--root', 'needs a node id, e.g. --root checkout'),
|
|
120
|
+
'--horizontal': null,
|
|
112
121
|
'--ascii': null,
|
|
113
122
|
'--color': null,
|
|
114
123
|
'--no-color': null,
|
|
@@ -116,7 +125,8 @@ const FLAGS = {
|
|
|
116
125
|
const isFlag = (arg) => Object.hasOwn(FLAGS, arg);
|
|
117
126
|
/** Read argv against every flag there is, whichever command it names: which arguments
|
|
118
127
|
* are values depends on the flags alone, and the command may come after its flags. The
|
|
119
|
-
* first mistake in argv's order is thrown as a {@link UsageError}
|
|
128
|
+
* first mistake in argv's order is thrown as a {@link UsageError}, and so is `--help`;
|
|
129
|
+
* `--version` is a {@link VersionRequest}. An unknown flag is an
|
|
120
130
|
* error rather than a file path, so a typo surfaces loudly instead of quietly skewing
|
|
121
131
|
* the file set. */
|
|
122
132
|
export function parseArgv(argv) {
|
|
@@ -132,6 +142,8 @@ export function parseArgv(argv) {
|
|
|
132
142
|
}
|
|
133
143
|
if (arg === '--help' || arg === '-h')
|
|
134
144
|
throw new UsageError('help requested', 0);
|
|
145
|
+
if (arg === '--version')
|
|
146
|
+
throw new VersionRequest();
|
|
135
147
|
if (arg.startsWith('--'))
|
|
136
148
|
throw new UsageError(`Unknown flag '${arg}'`, 1);
|
|
137
149
|
// The first argument that is not a flag names the command; anything after it is
|
package/dist/cli/run.js
CHANGED
|
@@ -11,11 +11,11 @@ import { show } from '../commands/show.js';
|
|
|
11
11
|
import { studio } from '../commands/studio.js';
|
|
12
12
|
import { tui } from '../commands/tui.js';
|
|
13
13
|
import { watch } from '../commands/watch.js';
|
|
14
|
-
import { findHome, homePaths } from '../home.js';
|
|
14
|
+
import { cliVersion, findHome, homePaths } from '../home.js';
|
|
15
15
|
import { resolveInclude } from '../includes.js';
|
|
16
16
|
import { RELATIVE_PATHS } from '../paths.js';
|
|
17
17
|
import { snapshotSession } from '../snapshots.js';
|
|
18
|
-
import { checkTaken, parseArgv, UsageError } from './parse.js';
|
|
18
|
+
import { checkTaken, parseArgv, UsageError, VersionRequest } from './parse.js';
|
|
19
19
|
/** Every command by name, in the order the refusal of a flag names the commands that
|
|
20
20
|
* take it. */
|
|
21
21
|
export const COMMANDS = {
|
|
@@ -56,6 +56,10 @@ export async function run(argv, io, usage) {
|
|
|
56
56
|
return await dispatch(parsed, io, usage);
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
|
59
|
+
if (e instanceof VersionRequest) {
|
|
60
|
+
io.out(cliVersion(homePaths(findHome(fileURLToPath(import.meta.url))).root));
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
59
63
|
if (!(e instanceof UsageError)) {
|
|
60
64
|
io.err(errMessage(e));
|
|
61
65
|
return 1;
|
package/dist/cli.js
CHANGED
|
@@ -31,7 +31,8 @@ Commands:
|
|
|
31
31
|
compile Compile *.diagram.{ts,json} sources into overlay artifacts once
|
|
32
32
|
lint Report suspicious diagrams (typos, duplicates, unused or undrawn parts); exit 1 on any
|
|
33
33
|
watch Recompile — and live-recompile — a directory of sources
|
|
34
|
-
publish
|
|
34
|
+
publish publish [names...]: compile, then write an HTML page and PNGs under
|
|
35
|
+
.diagrams/ for each diagram named, or for every diagram with none
|
|
35
36
|
show show <name>: print the diagram as text — boxes, lines and labels in the
|
|
36
37
|
terminal or a pipe, every container open (--depth folds deeper levels)
|
|
37
38
|
studio Run the visual studio against the current directory
|
|
@@ -49,12 +50,14 @@ Options:
|
|
|
49
50
|
--no-images Publish (or diff) HTML without rendering PNG images
|
|
50
51
|
--link url Publish with a link to url in the index header
|
|
51
52
|
--style id Publish: take the PNGs in this style preset (clean, sketch, …) in
|
|
52
|
-
place of each diagram's own
|
|
53
|
+
place of each diagram's own; tui: draw every diagram in dos or clean
|
|
53
54
|
--theme t Publish: take the PNGs light (the default) or dark
|
|
54
55
|
--plane id show: draw this plane (default: the first)
|
|
55
56
|
--layers a,b show: draw these layers in place of the plane's own ('' for none)
|
|
56
57
|
--depth n show: open only the top n levels of containers
|
|
57
58
|
--root id show: draw this container's inside only
|
|
59
|
+
--horizontal show: a git graph across the screen, its lanes as rows, as the page
|
|
60
|
+
draws it (default: down the screen, its lanes as columns)
|
|
58
61
|
--ascii show: plain ASCII in place of box-drawing characters
|
|
59
62
|
--color, --no-color show: colour or not, whatever stdout is (default: a terminal is)
|
|
60
63
|
--json lint: print the findings as a JSON array; diff: the changes as JSON
|
|
@@ -65,6 +68,7 @@ Options:
|
|
|
65
68
|
--agents init: write the coding-agent block into AGENTS.md / CLAUDE.md, and
|
|
66
69
|
the skill into .claude/skills/diagc/ where Claude Code is in use
|
|
67
70
|
--help, -h Show this help and exit
|
|
71
|
+
--version Print diagc's version and exit
|
|
68
72
|
`;
|
|
69
73
|
/** End the process once stdout and stderr have taken everything written to them:
|
|
70
74
|
* `process.exit` straight after a write drops what a pipe has not accepted yet. A
|
package/dist/commands/show.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Command } from '../cli/command.js';
|
|
2
|
-
type ShowFlag = '--plane' | '--layers' | '--depth' | '--root' | '--ascii' | '--color' | '--no-color';
|
|
2
|
+
type ShowFlag = '--plane' | '--layers' | '--depth' | '--root' | '--horizontal' | '--ascii' | '--color' | '--no-color';
|
|
3
3
|
/** `diagc show <name>`: the diagram as text on stdout. */
|
|
4
4
|
export declare const show: Command<ShowFlag>;
|
|
5
5
|
export {};
|
package/dist/commands/show.js
CHANGED
|
@@ -64,7 +64,7 @@ function widthHint(io, lines, name) {
|
|
|
64
64
|
}
|
|
65
65
|
/** `diagc show <name>`: the diagram as text on stdout. */
|
|
66
66
|
export const show = {
|
|
67
|
-
flags: ['--plane', '--layers', '--depth', '--root', '--ascii', '--color', '--no-color'],
|
|
67
|
+
flags: ['--plane', '--layers', '--depth', '--root', '--horizontal', '--ascii', '--color', '--no-color'],
|
|
68
68
|
positionals: { max: 1, what: 'one diagram name' },
|
|
69
69
|
whyNot: LOCKED,
|
|
70
70
|
async run({ positionals, flags }, { io, usage, home, snapshots }) {
|
|
@@ -103,7 +103,17 @@ export const show = {
|
|
|
103
103
|
const plane = flags['--plane'];
|
|
104
104
|
// A printed picture folds as the PNG does; --depth trades that for the top levels.
|
|
105
105
|
const pins = flags['--depth'] !== undefined ? depthPins(model, plane, flags['--depth']) : exportPins(model, overlay);
|
|
106
|
-
const lines = await renderToLines({
|
|
106
|
+
const lines = await renderToLines({
|
|
107
|
+
model,
|
|
108
|
+
pins,
|
|
109
|
+
...defined({
|
|
110
|
+
overlay,
|
|
111
|
+
plane,
|
|
112
|
+
layers: flags['--layers'],
|
|
113
|
+
root: flags['--root'],
|
|
114
|
+
horizontal: flags['--horizontal'],
|
|
115
|
+
}),
|
|
116
|
+
}, { ascii: flags['--ascii'] === true, color: colorModeFor(process.env, io.tty !== undefined, colorFlag(flags)) });
|
|
107
117
|
if (lines.length === 0) {
|
|
108
118
|
io.err(`diagc: nothing to draw in ${name}`);
|
|
109
119
|
return 0;
|
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
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type CompiledView, type DiagramModel } from '@diagc/core/internal';
|
|
2
|
+
import type { BoxText } from './content.js';
|
|
3
|
+
import type { TextLayout } from './layout.js';
|
|
4
|
+
/** The graph's spacing across the screen, in cells. */
|
|
5
|
+
export declare const GIT: {
|
|
6
|
+
/** neighbouring columns' distance when nothing needs more: a dot and three cells of line */
|
|
7
|
+
readonly PITCH: 4;
|
|
8
|
+
/** the least room between two tags on one lane: two cells, as one would read the
|
|
9
|
+
* two as one phrase */
|
|
10
|
+
readonly TAG_GAP: 2;
|
|
11
|
+
/** rows from one lane's line to the next: the next lane's tags and a blank row between */
|
|
12
|
+
readonly LANE: 3;
|
|
13
|
+
/** what a stage's frame needs besides its title: a corner and a cell of border
|
|
14
|
+
* before it, a space either side, a cell of border and a corner after */
|
|
15
|
+
readonly FRAME_ROOM: 6;
|
|
16
|
+
/** from the last column's reach to the lanes' names: the tail's run and a space */
|
|
17
|
+
readonly NAME_GAP: 2;
|
|
18
|
+
/** blank rows between the lanes and the boxes under them */
|
|
19
|
+
readonly STRAY_ROW: 1;
|
|
20
|
+
/** between two boxes in that row */
|
|
21
|
+
readonly STRAY_GAP: 4;
|
|
22
|
+
};
|
|
23
|
+
/** The graph's spacing down the screen, in cells. */
|
|
24
|
+
export declare const GIT_DOWN: {
|
|
25
|
+
/** rows from one column's dots to the next when nothing needs more: a dot and the row
|
|
26
|
+
* a branch turns off on, or a merge turns in */
|
|
27
|
+
readonly PITCH: 2;
|
|
28
|
+
/** rows a stage's frame reaches past its first and last dots: the row a line turns
|
|
29
|
+
* on, then its border, so no line turns along a border */
|
|
30
|
+
readonly FRAME: 2;
|
|
31
|
+
/** the least room between a lane's widest tag, or its name, and the next lane */
|
|
32
|
+
readonly LANE_GAP: 2;
|
|
33
|
+
/** columns left of the first lane where stages are framed: the frame's side and a space */
|
|
34
|
+
readonly MARGIN: 2;
|
|
35
|
+
/** what a stage's frame needs past the last lane besides its title: a cell of border
|
|
36
|
+
* before it, a space either side, a cell of border and a corner after */
|
|
37
|
+
readonly TITLE_ROOM: 5;
|
|
38
|
+
/** rows from the last dot's reach to the lanes' names: the tail's run */
|
|
39
|
+
readonly NAME_GAP: 2;
|
|
40
|
+
};
|
|
41
|
+
/** How a git graph is drawn: on which plane, and across the screen or down it. */
|
|
42
|
+
export interface GitWay {
|
|
43
|
+
plane?: string;
|
|
44
|
+
/** across the screen, as the page draws it; absent = down it */
|
|
45
|
+
across?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The graph in cells, for a git-graph plane: every node the view shows gets a box — a
|
|
49
|
+
* commit its dot and tag, a lane its name, a stage its frame — and every drawn git
|
|
50
|
+
* link between two dots a route from one to the other.
|
|
51
|
+
*/
|
|
52
|
+
export declare function gitCells(model: DiagramModel, view: CompiledView, boxes: ReadonlyMap<string, BoxText>, way: GitWay): TextLayout;
|