@brunosouzas/signwright 0.0.0-stage → 0.19.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 +202 -0
- package/NOTICE +15 -0
- package/README.md +567 -2
- package/dist/scripts/cover.d.ts +29 -0
- package/dist/scripts/cover.js +186 -0
- package/dist/src/fonts/embed.d.ts +7 -0
- package/dist/src/fonts/embed.js +221 -0
- package/dist/src/pieces/bank-objects.d.ts +12 -0
- package/dist/src/pieces/bank-objects.js +52 -0
- package/dist/src/pieces/brand-cast.d.ts +105 -0
- package/dist/src/pieces/brand-cast.js +221 -0
- package/dist/src/pieces/brand-notation-icons.d.ts +12 -0
- package/dist/src/pieces/brand-notation-icons.js +79 -0
- package/dist/src/pieces/category-icon.d.ts +12 -0
- package/dist/src/pieces/category-icon.js +55 -0
- package/dist/src/pieces/cover.d.ts +138 -0
- package/dist/src/pieces/cover.js +635 -0
- package/dist/src/pieces/diagram.d.ts +141 -0
- package/dist/src/pieces/diagram.js +201 -0
- package/dist/src/pieces/eip-icons.d.ts +12 -0
- package/dist/src/pieces/eip-icons.js +468 -0
- package/dist/src/pieces/emote.d.ts +13 -0
- package/dist/src/pieces/emote.js +88 -0
- package/dist/src/pieces/headline.d.ts +11 -0
- package/dist/src/pieces/headline.js +37 -0
- package/dist/src/pieces/index.d.ts +17 -0
- package/dist/src/pieces/index.js +20 -0
- package/dist/src/pieces/ink.d.ts +71 -0
- package/dist/src/pieces/ink.js +57 -0
- package/dist/src/pieces/keyboard.d.ts +9 -0
- package/dist/src/pieces/keyboard.js +33 -0
- package/dist/src/pieces/library.d.ts +320 -0
- package/dist/src/pieces/library.js +355 -0
- package/dist/src/pieces/link-icons.d.ts +23 -0
- package/dist/src/pieces/link-icons.js +101 -0
- package/dist/src/pieces/metro.d.ts +137 -0
- package/dist/src/pieces/metro.js +288 -0
- package/dist/src/pieces/node.d.ts +29 -0
- package/dist/src/pieces/node.js +56 -0
- package/dist/src/pieces/paper.d.ts +31 -0
- package/dist/src/pieces/paper.js +72 -0
- package/dist/src/pieces/params.d.ts +84 -0
- package/dist/src/pieces/params.js +158 -0
- package/dist/src/pieces/piece.d.ts +9 -0
- package/dist/src/pieces/piece.js +28 -0
- package/dist/src/pieces/pose.d.ts +16 -0
- package/dist/src/pieces/pose.js +30 -0
- package/dist/src/pieces/question-token.d.ts +9 -0
- package/dist/src/pieces/question-token.js +49 -0
- package/dist/src/pieces/react.d.ts +4 -0
- package/dist/src/pieces/react.js +13 -0
- package/dist/src/pieces/render.d.ts +2 -0
- package/dist/src/pieces/render.js +22 -0
- package/dist/src/pieces/skin.d.ts +22 -0
- package/dist/src/pieces/skin.js +13 -0
- package/dist/src/pieces/stamp.d.ts +11 -0
- package/dist/src/pieces/stamp.js +29 -0
- package/dist/src/pieces/supporting-cast.d.ts +35 -0
- package/dist/src/pieces/supporting-cast.js +168 -0
- package/dist/src/pieces/symbol.d.ts +13 -0
- package/dist/src/pieces/symbol.js +27 -0
- package/dist/src/pieces/ui-icons.d.ts +21 -0
- package/dist/src/pieces/ui-icons.js +35 -0
- package/dist/tokens/generated/tokens.d.ts +299 -0
- package/dist/tokens/generated/tokens.js +299 -0
- package/fonts/OFL.txt +97 -0
- package/fonts/SourceCodePro-Bold.ttf +0 -0
- package/fonts/SourceCodePro-Regular.ttf +0 -0
- package/fonts/SourceSans3-Black.ttf +0 -0
- package/fonts/SourceSans3-Bold.ttf +0 -0
- package/fonts/SourceSans3-Regular.ttf +0 -0
- package/fonts/SourceSerif4-Bold.ttf +0 -0
- package/package.json +88 -4
- package/tokens/generated/tokens.css +215 -0
- package/tokens/generated/tokens.json +298 -0
- package/tokens/generated/tokens.ts +302 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { type Ink, type SurfaceName } from "./ink.ts";
|
|
2
|
+
export type ShapeParams = Ink & {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
text: string[];
|
|
8
|
+
subtitle?: string;
|
|
9
|
+
fill?: string;
|
|
10
|
+
textSize?: number;
|
|
11
|
+
};
|
|
12
|
+
export type DiagramBoxParams = ShapeParams & {
|
|
13
|
+
radius?: number;
|
|
14
|
+
shape?: "box" | "pill";
|
|
15
|
+
};
|
|
16
|
+
/** A box or a pill with a fill and centred lines: a body diagram's step, system or note. */
|
|
17
|
+
export declare const diagramBox: import("./piece.ts").Piece<DiagramBoxParams>;
|
|
18
|
+
/** A decision: a diamond in its bounds. */
|
|
19
|
+
export declare const decisionNode: import("./piece.ts").Piece<Ink & {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
width: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
text: string[];
|
|
25
|
+
subtitle?: string;
|
|
26
|
+
fill?: string;
|
|
27
|
+
textSize?: number;
|
|
28
|
+
} & {
|
|
29
|
+
height: number;
|
|
30
|
+
}>;
|
|
31
|
+
export type StoreNodeParams = Omit<ShapeParams, "text"> & {
|
|
32
|
+
text?: string[];
|
|
33
|
+
height: number;
|
|
34
|
+
ry?: number;
|
|
35
|
+
};
|
|
36
|
+
/** A store: a cylinder in its bounds, with the front of its lid; empty without `text`. */
|
|
37
|
+
export declare const storeNode: import("./piece.ts").Piece<StoreNodeParams>;
|
|
38
|
+
export type QueueNodeParams = Omit<ShapeParams, "text"> & {
|
|
39
|
+
text?: string[];
|
|
40
|
+
};
|
|
41
|
+
/** A queue: a box with a rail 10 in from each side; empty without `text`. */
|
|
42
|
+
export declare const queueNode: import("./piece.ts").Piece<QueueNodeParams>;
|
|
43
|
+
/** An exchange: a hexagon with its points 0.26 × height in, as the motion shape (src/brand/flow-shapes.ts). */
|
|
44
|
+
export declare const exchangeNode: import("./piece.ts").Piece<ShapeParams>;
|
|
45
|
+
export type TaggedContainerParams = Ink & {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
tag: string;
|
|
51
|
+
tagWidth?: number;
|
|
52
|
+
tagFill?: string;
|
|
53
|
+
fill?: string;
|
|
54
|
+
};
|
|
55
|
+
/** A container (a platform, a broker) with its name on a tab centred on the top edge. */
|
|
56
|
+
export declare const taggedContainer: import("./piece.ts").Piece<TaggedContainerParams>;
|
|
57
|
+
export type LifelineParams = {
|
|
58
|
+
x: number;
|
|
59
|
+
y1: number;
|
|
60
|
+
y2: number;
|
|
61
|
+
state?: "active" | "inactive";
|
|
62
|
+
width?: number;
|
|
63
|
+
surface?: SurfaceName;
|
|
64
|
+
};
|
|
65
|
+
/** A participant's lifeline: dashed while active, sparse dots once nothing calls it. */
|
|
66
|
+
export declare const lifeline: import("./piece.ts").Piece<LifelineParams>;
|
|
67
|
+
export type PhaseBandParams = Ink & {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
width: number;
|
|
71
|
+
height?: number;
|
|
72
|
+
text: string;
|
|
73
|
+
fill: string;
|
|
74
|
+
textSize?: number;
|
|
75
|
+
};
|
|
76
|
+
/** A phase of a sequence: a pill across the diagram in its state's colour. */
|
|
77
|
+
export declare const phaseBand: import("./piece.ts").Piece<PhaseBandParams>;
|
|
78
|
+
type Head = {
|
|
79
|
+
tag: string;
|
|
80
|
+
condition?: string;
|
|
81
|
+
tagWidth?: number;
|
|
82
|
+
conditionWidth?: number;
|
|
83
|
+
};
|
|
84
|
+
export type AltFrameParams = Head & {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
width: number;
|
|
88
|
+
height: number;
|
|
89
|
+
sections?: (Head & {
|
|
90
|
+
y: number;
|
|
91
|
+
})[];
|
|
92
|
+
surface?: SurfaceName;
|
|
93
|
+
};
|
|
94
|
+
/** An alt/else frame: the frame, a dashed divider per section, and a tag (with its condition) per part. */
|
|
95
|
+
export declare const altFrame: import("./piece.ts").Piece<AltFrameParams>;
|
|
96
|
+
export type EdgeLabelParams = {
|
|
97
|
+
x: number;
|
|
98
|
+
y: number;
|
|
99
|
+
lines: string[];
|
|
100
|
+
anchor?: "start" | "middle" | "end";
|
|
101
|
+
backdrop?: boolean;
|
|
102
|
+
width?: number;
|
|
103
|
+
textSize?: number;
|
|
104
|
+
surface?: SurfaceName;
|
|
105
|
+
};
|
|
106
|
+
/** Words next to an arrow: lines down from the baseline (x, y), optionally on a backdrop that hides what is behind. */
|
|
107
|
+
export declare const edgeLabel: import("./piece.ts").Piece<EdgeLabelParams>;
|
|
108
|
+
export type StateStartParams = {
|
|
109
|
+
cx: number;
|
|
110
|
+
cy: number;
|
|
111
|
+
r?: number;
|
|
112
|
+
surface?: SurfaceName;
|
|
113
|
+
};
|
|
114
|
+
/** The initial state of a state machine (change designer-formats, design §4): a filled dot in the surface's text
|
|
115
|
+
* colour, no outline (its own stroke none, so a cover's outlined group does not grow it), no shadow, no text. */
|
|
116
|
+
export declare const stateStart: import("./piece.ts").Piece<StateStartParams>;
|
|
117
|
+
/** The body diagram pieces, in catalogue order (design §3). */
|
|
118
|
+
export declare const DIAGRAM_PIECES: {
|
|
119
|
+
readonly diagramBox: import("./piece.ts").Piece<DiagramBoxParams>;
|
|
120
|
+
readonly decisionNode: import("./piece.ts").Piece<Ink & {
|
|
121
|
+
x: number;
|
|
122
|
+
y: number;
|
|
123
|
+
width: number;
|
|
124
|
+
height?: number;
|
|
125
|
+
text: string[];
|
|
126
|
+
subtitle?: string;
|
|
127
|
+
fill?: string;
|
|
128
|
+
textSize?: number;
|
|
129
|
+
} & {
|
|
130
|
+
height: number;
|
|
131
|
+
}>;
|
|
132
|
+
readonly storeNode: import("./piece.ts").Piece<StoreNodeParams>;
|
|
133
|
+
readonly queueNode: import("./piece.ts").Piece<QueueNodeParams>;
|
|
134
|
+
readonly exchangeNode: import("./piece.ts").Piece<ShapeParams>;
|
|
135
|
+
readonly taggedContainer: import("./piece.ts").Piece<TaggedContainerParams>;
|
|
136
|
+
readonly lifeline: import("./piece.ts").Piece<LifelineParams>;
|
|
137
|
+
readonly phaseBand: import("./piece.ts").Piece<PhaseBandParams>;
|
|
138
|
+
readonly altFrame: import("./piece.ts").Piece<AltFrameParams>;
|
|
139
|
+
readonly edgeLabel: import("./piece.ts").Piece<EdgeLabelParams>;
|
|
140
|
+
};
|
|
141
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// Body diagram pieces (spec illustration-pieces, change body-diagram-pieces,
|
|
2
|
+
// design §3 and §4): the shapes, lines and labels of the blog's body diagrams
|
|
3
|
+
// that the metro and diagram pieces lack. Like those, they paint what the caller
|
|
4
|
+
// lays out; positions, text measurement and truncation stay with the caller.
|
|
5
|
+
//
|
|
6
|
+
// What can go wrong: every parameter is checked by its schema first; the limits
|
|
7
|
+
// between parameters are checked in the order of design §3 and the first one is
|
|
8
|
+
// thrown as a RangeError naming the parameter.
|
|
9
|
+
import { tokens } from "../../tokens/generated/tokens.js";
|
|
10
|
+
import { inkOf, inkSchema, limits, roomFor, spans, sticker, surfaceParam } from "./ink.js";
|
|
11
|
+
import { drawn, el, r2 } from "./node.js";
|
|
12
|
+
import { col, colour, label, MAX_SIZE, pos, size } from "./params.js";
|
|
13
|
+
import { definePiece } from "./piece.js";
|
|
14
|
+
const ink = tokens.color.ink;
|
|
15
|
+
const font = tokens.font.sans;
|
|
16
|
+
const bold = tokens.font.weightBold;
|
|
17
|
+
const M = tokens.map;
|
|
18
|
+
const lines = (max) => ({ kind: "array", required: true, minItems: 1, maxItems: max, of: label() });
|
|
19
|
+
const textSize = { kind: "number", min: 6, max: 48 };
|
|
20
|
+
// ---------- words ----------
|
|
21
|
+
/** Characters of a word for a width estimate: backticks do not count. */
|
|
22
|
+
const characters = (value) => Array.from(value.replace(/`/g, "")).length;
|
|
23
|
+
// Every text sets its own anchor, size and weight, so a surrounding group (a cover's label style) does not leak in.
|
|
24
|
+
const words = (x, y, value, attrs) => el("text", { x: r2(x), y: r2(y), "font-family": font, ...attrs }, ...spans(value));
|
|
25
|
+
/** No fill: the surface's panel with its text; a fill: that token with ink words (ADR 0003). */
|
|
26
|
+
const coloursOf = (fill, params) => {
|
|
27
|
+
const { s } = inkOf(params);
|
|
28
|
+
return fill === undefined ? { face: s.panel, text: s.text, sub: s.muted } : { face: colour(fill, "fill"), text: ink, sub: ink };
|
|
29
|
+
};
|
|
30
|
+
/** Centred lines (bold) and an optional subtitle (11, regular), centred on (cx, cy). */
|
|
31
|
+
const centred = (cx, cy, text, subtitle, c, size_ = M.labelSize) => {
|
|
32
|
+
const step = size_ * 1.25;
|
|
33
|
+
const block = (text.length - 1) * step + (subtitle === undefined ? 0 : 15);
|
|
34
|
+
const first = cy + (4.5 * size_) / 13 - block / 2;
|
|
35
|
+
return [
|
|
36
|
+
...text.map((line, i) => words(cx, first + i * step, line, { fill: c.text, "font-size": size_, "font-weight": bold, "text-anchor": "middle" })),
|
|
37
|
+
...(subtitle === undefined ? [] : [words(cx, first + (text.length - 1) * step + 15, subtitle, { fill: c.sub, "font-size": 11, "font-weight": 400, "text-anchor": "middle" })]),
|
|
38
|
+
];
|
|
39
|
+
};
|
|
40
|
+
/** Room on the smaller of width and height, naming the smaller one. */
|
|
41
|
+
const roomOn = (width, height, params) => width < height ? roomFor("width", width, params) : roomFor("height", height, params);
|
|
42
|
+
const polygon = (points) => (dx, dy, attrs) => el("polygon", { points: points.map(([px, py]) => `${r2(px + dx)},${r2(py + dy)}`).join(" "), ...attrs });
|
|
43
|
+
const rect = (x, y, w, h, rx) => (dx, dy, attrs) => el("rect", { x: r2(x + dx), y: r2(y + dy), width: r2(w), height: r2(h), rx: r2(rx), ...attrs });
|
|
44
|
+
const shapeSchema = (heightRequired) => ({
|
|
45
|
+
x: pos(),
|
|
46
|
+
y: pos(),
|
|
47
|
+
width: size(true),
|
|
48
|
+
height: size(heightRequired),
|
|
49
|
+
text: lines(3),
|
|
50
|
+
subtitle: label(false),
|
|
51
|
+
fill: col(),
|
|
52
|
+
textSize,
|
|
53
|
+
...inkSchema,
|
|
54
|
+
});
|
|
55
|
+
/** A box or a pill with a fill and centred lines: a body diagram's step, system or note. */
|
|
56
|
+
export const diagramBox = definePiece("diagramBox", { ...shapeSchema(false), radius: { kind: "number", min: 0, max: MAX_SIZE }, shape: { kind: "enum", values: ["box", "pill"] } }, (params) => {
|
|
57
|
+
const { x, y, width, height = M.nodeHeight, text, subtitle, fill, shape = "box" } = params;
|
|
58
|
+
const radius = shape === "pill" ? height / 2 : (params.radius ?? Math.min(M.nodeRadius, height / 2));
|
|
59
|
+
const c = coloursOf(fill, params);
|
|
60
|
+
return drawn(sticker(rect(x, y, width, height, radius), c.face, params), centred(x + width / 2, y + height / 2, text, subtitle, c, params.textSize));
|
|
61
|
+
}, (params) => {
|
|
62
|
+
const height = params.height ?? M.nodeHeight;
|
|
63
|
+
return limits(roomOn(params.width, height, params), params.shape === "pill" && params.radius !== undefined && { path: "radius", message: "cannot be combined with shape pill" }, params.radius !== undefined && params.radius > height / 2 && { path: "radius", message: `must be at most half the height (${r2(height / 2)}), found ${r2(params.radius)}` });
|
|
64
|
+
});
|
|
65
|
+
/** A decision: a diamond in its bounds. */
|
|
66
|
+
export const decisionNode = definePiece("decisionNode", shapeSchema(true), (params) => {
|
|
67
|
+
const { x, y, width: w, height: h, text, subtitle, fill } = params;
|
|
68
|
+
const c = coloursOf(fill, params);
|
|
69
|
+
const shape = polygon([[x + w / 2, y], [x + w, y + h / 2], [x + w / 2, y + h], [x, y + h / 2]]);
|
|
70
|
+
return drawn(sticker(shape, c.face, params), centred(x + w / 2, y + h / 2, text, subtitle, c, params.textSize));
|
|
71
|
+
}, (params) => limits(roomOn(params.width, params.height, params)));
|
|
72
|
+
/** Without `text` a store or a queue draws no words, so the parameters that style them have nothing to style (changes store-node-without-words, flat-eip-icons-and-empty-queue). */
|
|
73
|
+
const NO_WORDS = "needs text: it styles words that are not drawn";
|
|
74
|
+
/** A store: a cylinder in its bounds, with the front of its lid; empty without `text`. */
|
|
75
|
+
export const storeNode = definePiece("storeNode", { ...shapeSchema(true), text: { ...lines(3), required: false }, ry: size() }, (params) => {
|
|
76
|
+
const { x, y, width: w, height: h, text = [], subtitle, fill, ry = 8 } = params;
|
|
77
|
+
const c = coloursOf(fill, params);
|
|
78
|
+
const { outline } = inkOf(params);
|
|
79
|
+
const rx = r2(w / 2);
|
|
80
|
+
const body = (dx, dy, attrs) => el("path", { d: `M${r2(x + dx)},${r2(y + ry + dy)} A${rx},${ry} 0 0 1 ${r2(x + w + dx)},${r2(y + ry + dy)} V${r2(y + h - ry + dy)} A${rx},${ry} 0 0 1 ${r2(x + dx)},${r2(y + h - ry + dy)} Z`, ...attrs });
|
|
81
|
+
const lid = el("path", { d: `M${r2(x)},${r2(y + ry)} A${rx},${ry} 0 0 0 ${r2(x + w)},${r2(y + ry)}`, fill: "none", stroke: inkOf(params).line, "stroke-width": r2(0.75 * outline) });
|
|
82
|
+
return drawn([...sticker(body, c.face, params), lid], text.length === 0 ? [] : centred(x + w / 2, y + (h + ry) / 2, text, subtitle, c, params.textSize));
|
|
83
|
+
}, (params) => {
|
|
84
|
+
const ry = params.ry ?? 8;
|
|
85
|
+
const empty = params.text === undefined;
|
|
86
|
+
return limits(empty && params.subtitle !== undefined && { path: "subtitle", message: NO_WORDS }, empty && params.textSize !== undefined && { path: "textSize", message: NO_WORDS }, roomOn(params.width, params.height, params), ry > params.height / 4 && { path: "ry", message: `must be at most a quarter of the height (${r2(params.height / 4)}), found ${r2(ry)}` });
|
|
87
|
+
});
|
|
88
|
+
const RAIL = 10;
|
|
89
|
+
/** A queue: a box with a rail 10 in from each side; empty without `text`. */
|
|
90
|
+
export const queueNode = definePiece("queueNode", { ...shapeSchema(false), text: { ...lines(3), required: false } }, (params) => {
|
|
91
|
+
const { x, y, width: w, height: h = M.nodeHeight, text = [], subtitle, fill } = params;
|
|
92
|
+
const c = coloursOf(fill, params);
|
|
93
|
+
const { outline } = inkOf(params);
|
|
94
|
+
const rails = el("path", { d: `M${r2(x + RAIL)},${r2(y)} V${r2(y + h)} M${r2(x + w - RAIL)},${r2(y)} V${r2(y + h)}`, fill: "none", stroke: inkOf(params).line, "stroke-width": r2(0.75 * outline) });
|
|
95
|
+
return drawn([...sticker(rect(x, y, w, h, tokens.radius.small), c.face, params), rails], text.length === 0 ? [] : centred(x + w / 2, y + h / 2, text, subtitle, c, params.textSize));
|
|
96
|
+
}, (params) => {
|
|
97
|
+
const height = params.height ?? M.nodeHeight;
|
|
98
|
+
const least = Math.max(height, 2 * RAIL + 4 * inkOf(params).outline);
|
|
99
|
+
const empty = params.text === undefined;
|
|
100
|
+
return limits(empty && params.subtitle !== undefined && { path: "subtitle", message: NO_WORDS }, empty && params.textSize !== undefined && { path: "textSize", message: NO_WORDS }, roomFor("height", height, params), params.width < least && { path: "width", message: `must be at least the height and leave room for the rails (${r2(least)}), found ${r2(params.width)}` });
|
|
101
|
+
});
|
|
102
|
+
/** An exchange: a hexagon with its points 0.26 × height in, as the motion shape (src/brand/flow-shapes.ts). */
|
|
103
|
+
export const exchangeNode = definePiece("exchangeNode", shapeSchema(false), (params) => {
|
|
104
|
+
const { x, y, width: w, height: h = M.nodeHeight, text, subtitle, fill } = params;
|
|
105
|
+
const c = coloursOf(fill, params);
|
|
106
|
+
const k = 0.26 * h;
|
|
107
|
+
const shape = polygon([[x + k, y], [x + w - k, y], [x + w, y + h / 2], [x + w - k, y + h], [x + k, y + h], [x, y + h / 2]]);
|
|
108
|
+
return drawn(sticker(shape, c.face, params), centred(x + w / 2, y + h / 2, text, subtitle, c, params.textSize));
|
|
109
|
+
}, (params) => {
|
|
110
|
+
const height = params.height ?? M.nodeHeight;
|
|
111
|
+
return limits(roomFor("height", height, params), params.width < height && { path: "width", message: `must be at least the height (${r2(height)}), found ${r2(params.width)}` });
|
|
112
|
+
});
|
|
113
|
+
// ---------- container ----------
|
|
114
|
+
const TAB = 24;
|
|
115
|
+
const tabWidth = (params) => params.tagWidth ?? 7.2 * characters(params.tag) + 24;
|
|
116
|
+
/** A container (a platform, a broker) with its name on a tab centred on the top edge. */
|
|
117
|
+
export const taggedContainer = definePiece("taggedContainer", { x: pos(), y: pos(), width: size(true), height: size(true), tag: label(), tagWidth: size(), tagFill: col(), fill: col(), ...inkSchema }, (params) => {
|
|
118
|
+
const { x, y, width, height, tag, tagFill = "color.white", fill } = params;
|
|
119
|
+
const tw = tabWidth(params);
|
|
120
|
+
const c = coloursOf(fill, params);
|
|
121
|
+
return drawn([...sticker(rect(x, y, width, height, M.nodeRadius), c.face, params), ...sticker(rect(x + 14, y - TAB / 2, tw, TAB, TAB / 2), colour(tagFill, "tagFill"), params)], [words(x + 14 + tw / 2, y + 4.5, tag, { fill: ink, "font-size": M.badgeTextSize, "font-weight": bold, "text-anchor": "middle" })]);
|
|
122
|
+
}, (params) => {
|
|
123
|
+
const tw = tabWidth(params);
|
|
124
|
+
const need = 4 * inkOf(params).outline;
|
|
125
|
+
return limits(roomOn(params.width, params.height, params), tw < TAB && { path: "tagWidth", message: `must be at least the tab's height (${TAB}), found ${r2(tw)}` }, TAB < need && { path: "inkScale", message: `leaves no room for the tab's outline: the tab is ${TAB} high and needs ${r2(need)}` }, params.width < tw + 28 && { path: "width", message: `leaves no room for the tag: needs at least ${r2(tw + 28)}` });
|
|
126
|
+
});
|
|
127
|
+
/** A participant's lifeline: dashed while active, sparse dots once nothing calls it. */
|
|
128
|
+
export const lifeline = definePiece("lifeline", { x: pos(), y1: pos(), y2: pos(), state: { kind: "enum", values: ["active", "inactive"] }, width: { kind: "number", min: 0, exclusiveMin: true, max: 12 }, surface: surfaceParam }, ({ x, y1, y2, state = "active", width = 1.75, surface = "light" }) => {
|
|
129
|
+
const active = state === "active";
|
|
130
|
+
// Width as given, like pipe's: a valid hairline must not round to zero.
|
|
131
|
+
return drawn([
|
|
132
|
+
el("line", { x1: r2(x), y1: r2(y1), x2: r2(x), y2: r2(y2), stroke: tokens.surface[surface].muted, "stroke-width": width, "stroke-dasharray": active ? "5 5" : "1 6", "stroke-linecap": active ? "butt" : "round" }),
|
|
133
|
+
]);
|
|
134
|
+
}, ({ y1, y2 }) => limits(y1 === y2 && { path: "y2", message: "must differ from y1" }));
|
|
135
|
+
/** A phase of a sequence: a pill across the diagram in its state's colour. */
|
|
136
|
+
export const phaseBand = definePiece("phaseBand", { x: pos(), y: pos(), width: size(true), height: size(), text: label(), fill: { kind: "color", required: true }, textSize, ...inkSchema }, (params) => {
|
|
137
|
+
const { x, y, width, height = 26, text, fill, textSize: size_ = M.labelSize } = params;
|
|
138
|
+
return drawn(sticker(rect(x, y, width, height, height / 2), colour(fill, "fill"), params), [
|
|
139
|
+
words(x + width / 2, y + height / 2 + (4.5 * size_) / 13, text, { fill: ink, "font-size": size_, "font-weight": bold, "text-anchor": "middle" }),
|
|
140
|
+
]);
|
|
141
|
+
}, (params) => {
|
|
142
|
+
const height = params.height ?? 26;
|
|
143
|
+
return limits(roomFor("height", height, params), params.width < height && { path: "width", message: `must be at least the height (${r2(height)}), found ${r2(params.width)}` });
|
|
144
|
+
});
|
|
145
|
+
/** An alt/else frame: the frame, a dashed divider per section, and a tag (with its condition) per part. */
|
|
146
|
+
export const altFrame = definePiece("altFrame", {
|
|
147
|
+
x: pos(),
|
|
148
|
+
y: pos(),
|
|
149
|
+
width: size(true),
|
|
150
|
+
height: size(true),
|
|
151
|
+
tag: label(),
|
|
152
|
+
condition: label(false),
|
|
153
|
+
tagWidth: size(),
|
|
154
|
+
conditionWidth: size(),
|
|
155
|
+
sections: {
|
|
156
|
+
kind: "array",
|
|
157
|
+
maxItems: 10,
|
|
158
|
+
of: { kind: "object", fields: { y: pos(), tag: label(), condition: label(false), tagWidth: size(), conditionWidth: size() } },
|
|
159
|
+
},
|
|
160
|
+
surface: surfaceParam,
|
|
161
|
+
}, ({ x, y, width, height, sections = [], surface = "light", ...first }) => {
|
|
162
|
+
const s = tokens.surface[surface];
|
|
163
|
+
const head = (top, { tag, condition, tagWidth, conditionWidth }) => {
|
|
164
|
+
const tw = tagWidth ?? 6.4 * characters(tag) + 14;
|
|
165
|
+
const body = [el("rect", { x: r2(x + 7), y: r2(top + 6), width: r2(tw), height: 17, rx: 4, fill: s.text, stroke: "none" })];
|
|
166
|
+
const text = [words(x + 7 + tw / 2, top + 18.5, tag, { fill: s.panel, "font-size": 10, "font-weight": tokens.font.weightHeavy, "text-anchor": "middle" })];
|
|
167
|
+
if (condition !== undefined) {
|
|
168
|
+
body.push(el("rect", { x: r2(x + 7 + tw + 2), y: r2(top + 7.5), width: r2(conditionWidth ?? 6.2 * characters(condition) + 8), height: 14, rx: 3, fill: s.background, stroke: "none" }));
|
|
169
|
+
text.push(words(x + 7 + tw + 6, top + 18.5, condition, { fill: s.text, "font-size": 11, "font-weight": bold, "text-anchor": "start" }));
|
|
170
|
+
}
|
|
171
|
+
return { body, text };
|
|
172
|
+
};
|
|
173
|
+
const heads = [head(y, first), ...sections.map((section) => head(section.y, section))];
|
|
174
|
+
return drawn([
|
|
175
|
+
el("rect", { x: r2(x), y: r2(y), width: r2(width), height: r2(height), rx: 7, fill: "none", stroke: s.text, "stroke-width": 1.75 }),
|
|
176
|
+
...sections.map((section) => el("line", { x1: r2(x), y1: r2(section.y), x2: r2(x + width), y2: r2(section.y), stroke: s.text, "stroke-width": 1.4, "stroke-dasharray": "4 4" })),
|
|
177
|
+
...heads.flatMap((part) => part.body),
|
|
178
|
+
], heads.flatMap((part) => part.text));
|
|
179
|
+
}, ({ y, height, sections = [] }) => limits(...sections.map((section, i) => (section.y <= y || section.y >= y + height) && { path: `sections[${i}].y`, message: "must lie inside the frame" })));
|
|
180
|
+
/** Words next to an arrow: lines down from the baseline (x, y), optionally on a backdrop that hides what is behind. */
|
|
181
|
+
export const edgeLabel = definePiece("edgeLabel", { x: pos(), y: pos(), lines: lines(4), anchor: { kind: "enum", values: ["start", "middle", "end"] }, backdrop: { kind: "boolean" }, width: size(), textSize, surface: surfaceParam }, ({ x, y, lines: rows, anchor = "middle", backdrop = false, width, textSize: size_ = 11, surface = "light" }) => {
|
|
182
|
+
const s = tokens.surface[surface];
|
|
183
|
+
const k = size_ / 11;
|
|
184
|
+
const body = backdrop
|
|
185
|
+
? rows.map((row, i) => {
|
|
186
|
+
const w = width ?? (6.2 * characters(row) + 8) * k;
|
|
187
|
+
const left = anchor === "start" ? x - 4 * k : anchor === "end" ? x - w + 4 * k : x - w / 2;
|
|
188
|
+
return el("rect", { x: r2(left), y: r2(y + (i * 13 - 10) * k), width: r2(w), height: r2(14 * k), rx: 3, fill: s.background, stroke: "none" });
|
|
189
|
+
})
|
|
190
|
+
: [];
|
|
191
|
+
return drawn(body, rows.map((row, i) => words(x, y + i * 13 * k, row, { fill: s.text, "font-size": size_, "font-weight": bold, "text-anchor": anchor })));
|
|
192
|
+
});
|
|
193
|
+
/** Default start radius in layout units: the published dot (bodyDiagram.startRadius at the shown width) laid out at 560. */
|
|
194
|
+
const START_RADIUS = (tokens.bodyDiagram.startRadius * tokens.bodyDiagram.layoutWidth) / tokens.bodyDiagram.width;
|
|
195
|
+
/** The initial state of a state machine (change designer-formats, design §4): a filled dot in the surface's text
|
|
196
|
+
* colour, no outline (its own stroke none, so a cover's outlined group does not grow it), no shadow, no text. */
|
|
197
|
+
export const stateStart = definePiece("stateStart", { cx: pos(), cy: pos(), r: size(), surface: surfaceParam }, ({ cx, cy, r = START_RADIUS, surface = "light" }) =>
|
|
198
|
+
// The radius is written as given (a size, never rounded away); the centre is a position.
|
|
199
|
+
drawn([el("circle", { cx: r2(cx), cy: r2(cy), r, fill: tokens.surface[surface].text, stroke: "none" })]));
|
|
200
|
+
/** The body diagram pieces, in catalogue order (design §3). */
|
|
201
|
+
export const DIAGRAM_PIECES = { diagramBox, decisionNode, storeNode, queueNode, exchangeNode, taggedContainer, lifeline, phaseBand, altFrame, edgeLabel };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SvgNode } from "./node.ts";
|
|
2
|
+
export type EipIcon = {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly title: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly nodes: readonly SvgNode[];
|
|
7
|
+
};
|
|
8
|
+
/** Every icon draws in a 64x40 box. */
|
|
9
|
+
export declare const EIP_ICON_WIDTH = 64;
|
|
10
|
+
export declare const EIP_ICON_HEIGHT = 40;
|
|
11
|
+
export declare const EIP_ICONS: readonly EipIcon[];
|
|
12
|
+
export declare const EIP_ICON_NAMES: readonly string[];
|