@meltemi/diagrams-layout 0.0.0-stage → 1.9.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.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/dist/audit.d.ts +58 -0
  4. package/dist/audit.d.ts.map +1 -0
  5. package/dist/audit.js +239 -0
  6. package/dist/audit.js.map +1 -0
  7. package/dist/checks.d.ts +38 -0
  8. package/dist/checks.d.ts.map +1 -0
  9. package/dist/checks.js +331 -0
  10. package/dist/checks.js.map +1 -0
  11. package/dist/constraints.d.ts +20 -0
  12. package/dist/constraints.d.ts.map +1 -0
  13. package/dist/constraints.js +149 -0
  14. package/dist/constraints.js.map +1 -0
  15. package/dist/engine.d.ts +96 -0
  16. package/dist/engine.d.ts.map +1 -0
  17. package/dist/engine.js +3 -0
  18. package/dist/engine.js.map +1 -0
  19. package/dist/frame.d.ts +17 -0
  20. package/dist/frame.d.ts.map +1 -0
  21. package/dist/frame.js +51 -0
  22. package/dist/frame.js.map +1 -0
  23. package/dist/free.d.ts +75 -0
  24. package/dist/free.d.ts.map +1 -0
  25. package/dist/free.js +122 -0
  26. package/dist/free.js.map +1 -0
  27. package/dist/geometry.d.ts +58 -0
  28. package/dist/geometry.d.ts.map +1 -0
  29. package/dist/geometry.js +223 -0
  30. package/dist/geometry.js.map +1 -0
  31. package/dist/icons.d.ts +16 -0
  32. package/dist/icons.d.ts.map +1 -0
  33. package/dist/icons.js +94 -0
  34. package/dist/icons.js.map +1 -0
  35. package/dist/index.d.ts +20 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +19 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/layout.d.ts +206 -0
  40. package/dist/layout.d.ts.map +1 -0
  41. package/dist/layout.js +3527 -0
  42. package/dist/layout.js.map +1 -0
  43. package/dist/mark.d.ts +24 -0
  44. package/dist/mark.d.ts.map +1 -0
  45. package/dist/mark.js +60 -0
  46. package/dist/mark.js.map +1 -0
  47. package/dist/markers.d.ts +62 -0
  48. package/dist/markers.d.ts.map +1 -0
  49. package/dist/markers.js +255 -0
  50. package/dist/markers.js.map +1 -0
  51. package/dist/measure.d.ts +38 -0
  52. package/dist/measure.d.ts.map +1 -0
  53. package/dist/measure.js +44 -0
  54. package/dist/measure.js.map +1 -0
  55. package/dist/messages/en.d.ts +160 -0
  56. package/dist/messages/en.d.ts.map +1 -0
  57. package/dist/messages/en.js +163 -0
  58. package/dist/messages/en.js.map +1 -0
  59. package/dist/messages/es.d.ts +4 -0
  60. package/dist/messages/es.d.ts.map +1 -0
  61. package/dist/messages/es.js +104 -0
  62. package/dist/messages/es.js.map +1 -0
  63. package/dist/messages/index.d.ts +86 -0
  64. package/dist/messages/index.d.ts.map +1 -0
  65. package/dist/messages/index.js +17 -0
  66. package/dist/messages/index.js.map +1 -0
  67. package/dist/routing.d.ts +94 -0
  68. package/dist/routing.d.ts.map +1 -0
  69. package/dist/routing.js +549 -0
  70. package/dist/routing.js.map +1 -0
  71. package/dist/scene.d.ts +220 -0
  72. package/dist/scene.d.ts.map +1 -0
  73. package/dist/scene.js +5 -0
  74. package/dist/scene.js.map +1 -0
  75. package/dist/sequence.d.ts +17 -0
  76. package/dist/sequence.d.ts.map +1 -0
  77. package/dist/sequence.js +875 -0
  78. package/dist/sequence.js.map +1 -0
  79. package/dist/shapes.d.ts +140 -0
  80. package/dist/shapes.d.ts.map +1 -0
  81. package/dist/shapes.js +1030 -0
  82. package/dist/shapes.js.map +1 -0
  83. package/dist/styles.d.ts +58 -0
  84. package/dist/styles.d.ts.map +1 -0
  85. package/dist/styles.js +106 -0
  86. package/dist/styles.js.map +1 -0
  87. package/dist/text.d.ts +8 -0
  88. package/dist/text.d.ts.map +1 -0
  89. package/dist/text.js +28 -0
  90. package/dist/text.js.map +1 -0
  91. package/dist/theme.d.ts +100 -0
  92. package/dist/theme.d.ts.map +1 -0
  93. package/dist/theme.js +246 -0
  94. package/dist/theme.js.map +1 -0
  95. package/dist/viewport.d.ts +98 -0
  96. package/dist/viewport.d.ts.map +1 -0
  97. package/dist/viewport.js +177 -0
  98. package/dist/viewport.js.map +1 -0
  99. package/package.json +49 -3
@@ -0,0 +1,255 @@
1
+ import { polygonPath } from "./geometry.js";
2
+ /** Steps of the curve that replaces a bend when corners are rounded. */
3
+ const SAMPLES_PER_CORNER = 8;
4
+ /** How far a rounded corner starts from its bend, along each segment, at most. */
5
+ export const CORNER_RADIUS = 10;
6
+ function samePoint(a, b) {
7
+ return Math.abs(a.x - b.x) < 1e-9 && Math.abs(a.y - b.y) < 1e-9;
8
+ }
9
+ function lineLength(points) {
10
+ let total = 0;
11
+ for (let i = 1; i < points.length; i++) {
12
+ total += Math.hypot(points[i].x - points[i - 1].x, points[i].y - points[i - 1].y);
13
+ }
14
+ return total;
15
+ }
16
+ /**
17
+ * The line shortened by `by` at its end, along its last segment; when that segment is shorter,
18
+ * the line ends at its previous point, as the triangle head always did.
19
+ */
20
+ function trimEnd(points, by) {
21
+ if (by <= 0 || points.length < 2)
22
+ return [...points];
23
+ const tip = points[points.length - 1];
24
+ const from = points[points.length - 2];
25
+ const segment = Math.hypot(tip.x - from.x, tip.y - from.y);
26
+ const line = points.slice(0, -1);
27
+ if (segment > by) {
28
+ const k = (segment - by) / segment;
29
+ line.push({ x: from.x + (tip.x - from.x) * k, y: from.y + (tip.y - from.y) * k });
30
+ }
31
+ else {
32
+ line.push(from);
33
+ }
34
+ return line;
35
+ }
36
+ /** How far back from its tip a head of a kind reaches along its line, for the arrow size `length`. */
37
+ export function markerReach(kind, length) {
38
+ switch (kind) {
39
+ case "none":
40
+ return 0;
41
+ case "diamond":
42
+ case "diamondOutline":
43
+ return 1.5 * length;
44
+ case "oneOrMany":
45
+ return 1.3 * length;
46
+ case "zeroOrOne":
47
+ case "zeroOrMany":
48
+ return 1.9 * length;
49
+ default:
50
+ return length;
51
+ }
52
+ }
53
+ /**
54
+ * The head of kind `kind` at the last point of `points`, in a frame where `length` is the theme's
55
+ * arrow size and `width` the base of a triangle, and the line trimmed where the head needs it:
56
+ * filled and outlined shapes stop the line at their back, so nothing shows through an outline.
57
+ */
58
+ export function endMarker(points, kind, length, width) {
59
+ if (kind === "none" || points.length < 1)
60
+ return { line: [...points], parts: [] };
61
+ const tip = points[points.length - 1];
62
+ let from = points[points.length - 2] ?? { x: tip.x, y: tip.y - 1 };
63
+ if (samePoint(from, tip))
64
+ from = { x: tip.x, y: tip.y - 1 };
65
+ const distance = Math.hypot(tip.x - from.x, tip.y - from.y);
66
+ const ux = (tip.x - from.x) / distance;
67
+ const uy = (tip.y - from.y) / distance;
68
+ // `back` along the line from the tip, `side` across it.
69
+ const at = (back, side) => ({
70
+ x: tip.x - ux * back - uy * side,
71
+ y: tip.y - uy * back + ux * side,
72
+ });
73
+ const L = length;
74
+ const W = width;
75
+ const r = 0.45 * L;
76
+ const bar = (back) => ({
77
+ kind: "polyline",
78
+ points: [at(back, 0.6 * W), at(back, -0.6 * W)],
79
+ });
80
+ const crowsFoot = {
81
+ kind: "polyline",
82
+ points: [at(0, 0.6 * W), at(L, 0), at(0, -0.6 * W)],
83
+ };
84
+ const stem = { kind: "polyline", points: [at(L, 0), tip] };
85
+ const circle = (back, filled) => ({
86
+ kind: "circle",
87
+ center: at(back, 0),
88
+ r,
89
+ filled,
90
+ });
91
+ switch (kind) {
92
+ case "triangle":
93
+ case "triangleOutline":
94
+ return {
95
+ line: trimEnd(points, L),
96
+ parts: [
97
+ {
98
+ kind: "polygon",
99
+ points: [tip, at(L, W / 2), at(L, -W / 2)],
100
+ filled: kind === "triangle",
101
+ },
102
+ ],
103
+ };
104
+ case "open":
105
+ return {
106
+ line: [...points],
107
+ parts: [{ kind: "polyline", points: [at(L, W / 2), tip, at(L, -W / 2)] }],
108
+ };
109
+ case "diamond":
110
+ case "diamondOutline": {
111
+ const D = 1.5 * L;
112
+ return {
113
+ line: trimEnd(points, D),
114
+ parts: [
115
+ {
116
+ kind: "polygon",
117
+ points: [tip, at(D / 2, W / 2), at(D, 0), at(D / 2, -W / 2)],
118
+ filled: kind === "diamond",
119
+ },
120
+ ],
121
+ };
122
+ }
123
+ case "circle":
124
+ case "circleOutline":
125
+ return { line: trimEnd(points, 2 * r), parts: [circle(r, kind === "circle")] };
126
+ case "bar":
127
+ return { line: [...points], parts: [bar(L / 2)] };
128
+ case "cross": {
129
+ const c = 0.6 * L;
130
+ return {
131
+ line: [...points],
132
+ parts: [
133
+ { kind: "polyline", points: [at(c - W / 2, W / 2), at(c + W / 2, -W / 2)] },
134
+ { kind: "polyline", points: [at(c - W / 2, -W / 2), at(c + W / 2, W / 2)] },
135
+ ],
136
+ };
137
+ }
138
+ case "many":
139
+ return { line: [...points], parts: [crowsFoot] };
140
+ case "oneOrMany":
141
+ return { line: [...points], parts: [crowsFoot, bar(1.3 * L)] };
142
+ case "onlyOne":
143
+ return { line: [...points], parts: [bar(L / 2), bar(L)] };
144
+ case "zeroOrOne":
145
+ return {
146
+ line: trimEnd(points, L + 2 * r),
147
+ parts: [stem, bar(L / 2), circle(L + r, false)],
148
+ };
149
+ case "zeroOrMany":
150
+ return {
151
+ line: trimEnd(points, L + 2 * r),
152
+ parts: [stem, crowsFoot, circle(L + r, false)],
153
+ };
154
+ }
155
+ }
156
+ /**
157
+ * The heads of both ends of a line and the line between them. The start head is the end head's
158
+ * geometry on the reversed line. When the line is too short for both heads, it is kept whole.
159
+ */
160
+ export function relationEnds(points, start, end, length, width) {
161
+ const atEnd = endMarker(points, end, length, width);
162
+ const atStart = endMarker([...atEnd.line].reverse(), start, length, width);
163
+ const line = [...atStart.line].reverse();
164
+ const kept = lineLength(line) > 0.5 || lineLength(points) < 1 ? line : [...points];
165
+ return { line: kept, start: atStart.parts, end: atEnd.parts };
166
+ }
167
+ /**
168
+ * The line with every bend replaced by a quadratic curve through it, `radius` from the bend along
169
+ * each segment (half the shorter segment when that is less), sampled in eight steps, so the line
170
+ * stays a polyline for labels, checks and motion.
171
+ */
172
+ export function roundCorners(points, radius) {
173
+ if (points.length < 3 || radius <= 0)
174
+ return [...points];
175
+ const out = [points[0]];
176
+ for (let i = 1; i < points.length - 1; i++) {
177
+ const a = points[i - 1];
178
+ const v = points[i];
179
+ const b = points[i + 1];
180
+ const la = Math.hypot(a.x - v.x, a.y - v.y);
181
+ const lb = Math.hypot(b.x - v.x, b.y - v.y);
182
+ // A straight joint or a doubled point has no corner to round.
183
+ const cross = (v.x - a.x) * (b.y - v.y) - (v.y - a.y) * (b.x - v.x);
184
+ if (la < 1e-6 || lb < 1e-6 || Math.abs(cross) < 1e-6) {
185
+ out.push(v);
186
+ continue;
187
+ }
188
+ const r = Math.min(radius, la / 2, lb / 2);
189
+ const c1 = { x: v.x + ((a.x - v.x) * r) / la, y: v.y + ((a.y - v.y) * r) / la };
190
+ const c2 = { x: v.x + ((b.x - v.x) * r) / lb, y: v.y + ((b.y - v.y) * r) / lb };
191
+ for (let s = 0; s <= SAMPLES_PER_CORNER; s++) {
192
+ const t = s / SAMPLES_PER_CORNER;
193
+ const u = 1 - t;
194
+ out.push({
195
+ x: u * u * c1.x + 2 * u * t * v.x + t * t * c2.x,
196
+ y: u * u * c1.y + 2 * u * t * v.y + t * t * c2.y,
197
+ });
198
+ }
199
+ }
200
+ out.push(points[points.length - 1]);
201
+ return out;
202
+ }
203
+ const n = (value) => {
204
+ const rounded = Math.round(value * 100) / 100;
205
+ return Object.is(rounded, -0) ? "0" : String(rounded);
206
+ };
207
+ /** A circle as path data with two arcs. */
208
+ export function circleD(center, r) {
209
+ return `M${n(center.x - r)} ${n(center.y)} A${n(r)} ${n(r)} 0 1 0 ${n(center.x + r)} ${n(center.y)} A${n(r)} ${n(r)} 0 1 0 ${n(center.x - r)} ${n(center.y)} Z`;
210
+ }
211
+ const r2 = (value) => {
212
+ const rounded = Math.round(value * 100) / 100;
213
+ return Object.is(rounded, -0) ? 0 : rounded;
214
+ };
215
+ /** Every point a head reaches, for the bounds of the drawing. */
216
+ export function markerPoints(parts) {
217
+ const out = [];
218
+ for (const part of parts) {
219
+ if (part.kind === "circle") {
220
+ const { center: c, r } = part;
221
+ out.push({ x: c.x - r, y: c.y - r }, { x: c.x + r, y: c.y + r });
222
+ }
223
+ else
224
+ out.push(...part.points);
225
+ }
226
+ return out;
227
+ }
228
+ /** A head with every point moved by `move`. */
229
+ export function shiftMarker(parts, move) {
230
+ return parts.map((part) => part.kind === "circle"
231
+ ? { ...part, center: move(part.center) }
232
+ : { ...part, points: part.points.map(move) });
233
+ }
234
+ /**
235
+ * The scene items of a head in the line's colour and width: filled shapes are filled with the
236
+ * stroke colour, outlined ones are stroked and unfilled, and lines are never dashed.
237
+ */
238
+ export function markerItems(parts, stroke, strokeWidth) {
239
+ return parts.map((part) => {
240
+ if (part.kind === "polyline") {
241
+ return {
242
+ kind: "polyline",
243
+ points: part.points.map((p) => ({ x: r2(p.x), y: r2(p.y) })),
244
+ stroke,
245
+ strokeWidth,
246
+ dashed: false,
247
+ };
248
+ }
249
+ const d = part.kind === "circle" ? circleD(part.center, part.r) : polygonPath(part.points);
250
+ return part.filled
251
+ ? { kind: "path", d, fill: stroke, stroke: "none", strokeWidth: 0, dashed: false }
252
+ : { kind: "path", d, fill: "none", stroke, strokeWidth, dashed: false };
253
+ });
254
+ }
255
+ //# sourceMappingURL=markers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markers.js","sourceRoot":"","sources":["../src/markers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA6B5C,wEAAwE;AACxE,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,kFAAkF;AAClF,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAEhC,SAAS,SAAS,CAAC,CAAQ,EAAE,CAAQ;IACnC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC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I,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3F,OAAO,IAAI,CAAC,MAAM;YAChB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE;YAClF,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC5E,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { FontRole } from "./scene.js";
2
+ import type { Theme } from "./theme.js";
3
+ /**
4
+ * Measures text in the font a CSS font stack resolves to. Hosts with fonts pass a real measurer
5
+ * (`@meltemi/diagrams-fonts`); hosts without them use `estimateMeasurer`.
6
+ */
7
+ export interface TextMeasurer {
8
+ /** Advance width in pixels of `text`. */
9
+ width(text: string, fontStack: string, weight: number, size: number): number;
10
+ /** Cap height in ems, used to centre text vertically. */
11
+ capHeight(fontStack: string, weight: number): number;
12
+ /** Whether the stack resolves to a font the measurer has metrics for. */
13
+ knows(fontStack: string): boolean;
14
+ /** Characters of `text` no font of the stack covers, when the measurer can tell. */
15
+ uncovered?(text: string, fontStack: string): string[];
16
+ }
17
+ /** Width estimates from character classes, for hosts without fonts. Cap height 0.7 em. */
18
+ export declare const estimateMeasurer: TextMeasurer;
19
+ /** Horizontal padding of the default theme between a box edge and its text (the `padding` token). */
20
+ export declare const TEXT_PADDING = 16;
21
+ /** Smallest gap between text and a box edge before `layout.text-overflow` is reported. */
22
+ export declare const MIN_TEXT_MARGIN = 6;
23
+ /**
24
+ * Measures the text of one diagram with its theme's fonts and remembers what could not be
25
+ * measured exactly, for the `layout.unmeasured-font` diagnostic.
26
+ */
27
+ export declare class TextMetrics {
28
+ private readonly measurer;
29
+ private readonly theme;
30
+ readonly unknownFonts: Set<string>;
31
+ readonly uncovered: Set<string>;
32
+ constructor(measurer: TextMeasurer, theme: Theme);
33
+ private resolve;
34
+ width(text: string, role: FontRole, weight: number, size: number): number;
35
+ /** The baseline of a text centred on `centreY`. */
36
+ baseline(centreY: number, role: FontRole, weight: number, size: number): number;
37
+ }
38
+ //# sourceMappingURL=measure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../src/measure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7E,yDAAyD;IACzD,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACrD,yEAAyE;IACzE,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,oFAAoF;IACpF,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACvD;AAED,0FAA0F;AAC1F,eAAO,MAAM,gBAAgB,EAAE,YAK9B,CAAC;AAEF,qGAAqG;AACrG,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,0FAA0F;AAC1F,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC;;;GAGG;AACH,qBAAa,WAAW;IAKpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IALxB,QAAQ,CAAC,YAAY,cAAqB;IAC1C,QAAQ,CAAC,SAAS,cAAqB;gBAGpB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,KAAK;IAG/B,OAAO,CAAC,OAAO;IAOf,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAMzE,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;CAIhF"}
@@ -0,0 +1,44 @@
1
+ import { estimateTextWidth } from "./text.js";
2
+ /** Width estimates from character classes, for hosts without fonts. Cap height 0.7 em. */
3
+ export const estimateMeasurer = {
4
+ width: (text, fontStack, _weight, size) => estimateTextWidth(text, size, /mono/i.test(fontStack) ? "mono" : "body"),
5
+ capHeight: () => 0.7,
6
+ knows: () => true,
7
+ };
8
+ /** Horizontal padding of the default theme between a box edge and its text (the `padding` token). */
9
+ export const TEXT_PADDING = 16;
10
+ /** Smallest gap between text and a box edge before `layout.text-overflow` is reported. */
11
+ export const MIN_TEXT_MARGIN = 6;
12
+ /**
13
+ * Measures the text of one diagram with its theme's fonts and remembers what could not be
14
+ * measured exactly, for the `layout.unmeasured-font` diagnostic.
15
+ */
16
+ export class TextMetrics {
17
+ measurer;
18
+ theme;
19
+ unknownFonts = new Set();
20
+ uncovered = new Set();
21
+ constructor(measurer, theme) {
22
+ this.measurer = measurer;
23
+ this.theme = theme;
24
+ }
25
+ resolve(role) {
26
+ const stack = role === "mono" ? this.theme.mono : this.theme.font;
27
+ if (this.measurer.knows(stack))
28
+ return { measurer: this.measurer, stack };
29
+ this.unknownFonts.add(stack);
30
+ return { measurer: estimateMeasurer, stack };
31
+ }
32
+ width(text, role, weight, size) {
33
+ const { measurer, stack } = this.resolve(role);
34
+ for (const ch of measurer.uncovered?.(text, stack) ?? [])
35
+ this.uncovered.add(ch);
36
+ return measurer.width(text, stack, weight, size);
37
+ }
38
+ /** The baseline of a text centred on `centreY`. */
39
+ baseline(centreY, role, weight, size) {
40
+ const { measurer, stack } = this.resolve(role);
41
+ return centreY + (measurer.capHeight(stack, weight) * size) / 2;
42
+ }
43
+ }
44
+ //# sourceMappingURL=measure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measure.js","sourceRoot":"","sources":["../src/measure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAkB9C,0FAA0F;AAC1F,MAAM,CAAC,MAAM,gBAAgB,GAAiB;IAC5C,KAAK,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CACxC,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IAC1E,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG;IACpB,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI;CAClB,CAAC;AAEF,qGAAqG;AACrG,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,0FAA0F;AAC1F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AAEjC;;;GAGG;AACH,MAAM,OAAO,WAAW;IAKH;IACA;IALV,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IAEvC,YACmB,QAAsB,EACtB,KAAY;QADZ,aAAQ,GAAR,QAAQ,CAAc;QACtB,UAAK,GAAL,KAAK,CAAO;IAC5B,CAAC;IAEI,OAAO,CAAC,IAAc;QAC5B,MAAM,KAAK,GAAG,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAClE,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;QAC1E,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,IAAY,EAAE,IAAc,EAAE,MAAc,EAAE,IAAY;QAC9D,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,KAAK,MAAM,EAAE,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE;YAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACjF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,mDAAmD;IACnD,QAAQ,CAAC,OAAe,EAAE,IAAc,EAAE,MAAc,EAAE,IAAY;QACpE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,OAAO,OAAO,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAClE,CAAC;CACF"}
@@ -0,0 +1,160 @@
1
+ import type { AlignEdge } from "@meltemi/diagrams-model";
2
+ /** What cuts a label in the label audit: its own shape, the label behind it, or the picture. */
3
+ export type CutBy = "shape" | "background" | "picture";
4
+ /** What a label lies on in the label audit. An owner of `null` is the frame. */
5
+ export type LabelObstacle = {
6
+ readonly kind: "text";
7
+ readonly owner: string | null;
8
+ readonly text: string;
9
+ } | {
10
+ readonly kind: "box" | "connector";
11
+ readonly owner: string;
12
+ };
13
+ /**
14
+ * The layout's words in English. `drawing` holds the words the layout adds to drawings, which are
15
+ * content: they are read only in the content language a caller passes (`drawingWords`). The other
16
+ * groups are what the layout says about the person's text, written in the interface language when
17
+ * a diagnostic is made. Sentences with values are functions, so each language builds its own
18
+ * grammar; code in them (keywords, ids, samples) stays as written.
19
+ */
20
+ export declare const en: {
21
+ /** The type lines of C4 entities, drawn under their names, and the titles of boundaries. */
22
+ drawing: {
23
+ c4: {
24
+ person: string;
25
+ system: string;
26
+ container: string;
27
+ component: string;
28
+ externalPerson: string;
29
+ externalSystem: string;
30
+ externalContainer: string;
31
+ externalComponent: string;
32
+ };
33
+ };
34
+ /** The messages of the layout's diagnostics; the code of each is in its comment. */
35
+ diagnostics: {
36
+ /** `layout.overlap`: two boxes of the same layer. */
37
+ overlap: (a: string, b: string) => string;
38
+ /** `layout.overlap`: a box out of the group that declares it. */
39
+ crossesGroup: (shape: string, group: string) => string;
40
+ /** `layout.overlap`: a box on a group that does not declare it. */
41
+ overlapsGroup: (shape: string, group: string) => string;
42
+ /** `layout.container-margin`. */
43
+ containerMargin: (shape: string, group: string) => string;
44
+ /** `layout.label-under-connector`: the relation whose label it is, the connector it lies on. */
45
+ labelUnderConnector: (label: string, connector: string) => string;
46
+ /** `layout.connector-overlap`: two relations and the length they share, in pixels. */
47
+ connectorOverlap: (a: string, b: string, length: number) => string;
48
+ /** `layout.connector-crossing`: a relation and the box it runs through. */
49
+ connectorCrossing: (relation: string, box: string) => string;
50
+ /** `layout.label-cut`: a text (shortened), its owner, how far it goes beyond, and what. */
51
+ labelCut: (text: string, owner: string | null, overflow: number, by: CutBy) => string;
52
+ /** `layout.label-overlap`: a text (shortened), its owner, and what it lies on. */
53
+ labelOverlap: (text: string, owner: string | null, other: LabelObstacle) => string;
54
+ /** `layout.unknown-theme`: the name written and the theme drawn instead. */
55
+ unknownTheme: (written: string, fallback: string) => string;
56
+ /** `layout.missing-placement`: a group of a free diagram without `place`. */
57
+ groupWithoutPlace: (group: string) => string;
58
+ /** `layout.missing-placement`: an element of a `layout manual` diagram without `place`. */
59
+ elementWithoutPlace: (element: string) => string;
60
+ /** `layout.missing-placement`: a group with only one of `place` and `size`. */
61
+ groupHalfPlaced: (group: string, written: "place" | "size") => string;
62
+ /** `layout.missing-placement`: a group with nothing to fit and no place or size. */
63
+ groupUnplaced: (group: string) => string;
64
+ /** `layout.mode-unsupported`: the mode and the elements that are not placed. */
65
+ modeUnsupported: (mode: string, elements: readonly string[]) => string;
66
+ /** `layout.placement-ignored`. */
67
+ placementIgnored: string;
68
+ /** `layout.image-unavailable`: the path written and the image object. */
69
+ imageUnavailable: (source: string, element: string) => string;
70
+ /** `layout.icon-missing`: an element drawn as its icon (`shape icon`) without one. */
71
+ iconMissing: (element: string) => string;
72
+ /** `layout.label-position-ignored`: an element whose icon is not the centre piece. */
73
+ labelPositionIgnored: (element: string) => string;
74
+ /**
75
+ * `layout.label-position-ignored` of a `labelPosition` the theme gives: the first element it
76
+ * styles. Reported once, when no element it styles has its icon as the centre piece.
77
+ */
78
+ labelPositionIgnoredByTheme: (element: string) => string;
79
+ /**
80
+ * `layout.text-overflow` of an icon shape whose written size leaves its icon under its least
81
+ * size: the element, its size and the size that holds the icon.
82
+ */
83
+ iconTooSmall: (element: string, width: number, height: number, needsWidth: number, needsHeight: number) => string;
84
+ /** `layout.engine-failed`: the engine's name and its own words, which end the sentence. */
85
+ engineFailed: (engine: string, reason: string) => string;
86
+ /**
87
+ * `layout.constraint-conflict` of `align`, `row` and `column`: the constraint, its elements,
88
+ * the edge, the element furthest off, by how many pixels, and the first element.
89
+ */
90
+ alignConflict: (kind: string, elements: readonly string[], edge: AlignEdge, worst: string, off: number, first: string) => string;
91
+ /** `layout.constraint-conflict` of `order`: the element out of order and the one before it. */
92
+ orderConflict: (elements: readonly string[], current: string, axis: "x" | "y", previous: string) => string;
93
+ /** `layout.constraint-conflict` of `distance`: the gap there is and the one asked for. */
94
+ distanceConflict: (a: string, b: string, gap: number, distance: number) => string;
95
+ /** `layout.unmeasured-font`: fonts that are not bundled and characters no font covers. */
96
+ unmeasuredFont: (fonts: readonly string[], characters: readonly string[]) => string;
97
+ /** `layout.too-large` of `preset document`. */
98
+ tooWideForDocument: (width: number, max: number) => string;
99
+ /** `layout.too-large` of `preset slide`. */
100
+ tooLargeForSlide: (width: number, height: number, slideWidth: number, slideHeight: number) => string;
101
+ /** `layout.too-large` of `canvas`. */
102
+ tooLargeForCanvas: (width: number, height: number, canvasWidth: number, canvasHeight: number) => string;
103
+ /** `layout.text-overflow`: the element, its width, the widest text and the width it needs. */
104
+ textOverflow: (element: string, width: number, withIcon: boolean, text: string, needs: number) => string;
105
+ /**
106
+ * `layout.text-overflow` of a shape whose text needs a taller box: the element, its size, the
107
+ * widest text and the size it needs; only the heights when the width is enough.
108
+ */
109
+ textOverflowTall: (element: string, width: number, height: number, withIcon: boolean, text: string, needsWidth: number, needsHeight: number) => string;
110
+ };
111
+ /** The hints of the layout's diagnostics. */
112
+ hints: {
113
+ /** `layout.label-cut` by the edge of the picture. */
114
+ labelCutByPicture: string;
115
+ /** `layout.label-cut` by a shape or a label. */
116
+ labelCut: string;
117
+ /** `layout.label-overlap` on a connector. */
118
+ labelOnConnector: string;
119
+ /** `layout.label-overlap` on a text or a box. */
120
+ labelOverlap: string;
121
+ /** `layout.unknown-theme`: the built-in themes and those the file can name. */
122
+ themes: (builtIn: readonly string[], inScope: readonly string[]) => string;
123
+ /** `layout.missing-placement`. */
124
+ addPlace: (id: string) => string;
125
+ /** `layout.missing-placement` of a group without placed children. */
126
+ addPlaceAndSize: (id: string) => string;
127
+ /** `layout.mode-unsupported`. */
128
+ engine: string;
129
+ /** `layout.placement-ignored`. */
130
+ assisted: string;
131
+ /** `layout.image-unavailable` when the host reads images. */
132
+ imageFile: string;
133
+ /** `layout.image-unavailable` when the host does not read images. */
134
+ imageHost: string;
135
+ /** `layout.icon-missing`: the element, as code. */
136
+ iconMissing: (element: string) => string;
137
+ /** `layout.label-position-ignored`. */
138
+ labelPositionIgnored: string;
139
+ /**
140
+ * `layout.label-position-ignored` on kinds whose icon is never the centre piece: groups, tags,
141
+ * notes, free texts, icons and images, sequence and C4 kinds.
142
+ */
143
+ labelPositionNeverUsed: string;
144
+ /** `layout.label-position-ignored` of a `labelPosition` the theme gives. */
145
+ labelPositionIgnoredByTheme: string;
146
+ /** `layout.text-overflow` of an icon shape too small for its icon: the size that holds it. */
147
+ iconTooSmall: (element: string, width: number, height: number) => string;
148
+ /** `layout.constraint-conflict`. */
149
+ constraint: string;
150
+ /** `layout.unmeasured-font`. */
151
+ bundledFonts: string;
152
+ /** `layout.too-large`. */
153
+ tooLarge: string;
154
+ /** `layout.text-overflow`: the size that fits, as code. */
155
+ textOverflow: (element: string, width: number, height: number) => string;
156
+ /** `layout.overlap` of a box declared before a box that holds it: the outer and inner boxes. */
157
+ stackOrder: (outer: string, inner: string) => string;
158
+ };
159
+ };
160
+ //# sourceMappingURL=en.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,gGAAgG;AAChG,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC;AAEvD,gFAAgF;AAChF,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/E;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,WAAW,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAKnE;;;;;;GAMG;AACH,eAAO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