@adecore/diagram 0.39.0 → 0.40.1
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/dist/layout.js +24 -24
- package/dist/order.js +2 -3
- package/dist/route.d.ts +1 -4
- package/dist/route.js +5 -7
- package/package.json +5 -5
- package/src/across.ts +52 -0
- package/src/layout.ts +183 -25
- package/src/order.ts +49 -3
- package/src/protocol.ts +14 -0
- package/src/reading-order.ts +5 -0
- package/src/route.ts +53 -8
- package/src/shapes.ts +8 -0
- package/src/svg.ts +7 -0
- package/src/text.ts +19 -0
package/src/text.ts
CHANGED
|
@@ -17,24 +17,31 @@ function ratioOf(char: string): number {
|
|
|
17
17
|
if (NARROW.has(char)) {
|
|
18
18
|
return 0.3;
|
|
19
19
|
}
|
|
20
|
+
|
|
20
21
|
if (SEMI.has(char)) {
|
|
21
22
|
return 0.4;
|
|
22
23
|
}
|
|
24
|
+
|
|
23
25
|
if (WIDE_LOWER.has(char)) {
|
|
24
26
|
return 0.86;
|
|
25
27
|
}
|
|
28
|
+
|
|
26
29
|
if (WIDE.has(char)) {
|
|
27
30
|
return 1;
|
|
28
31
|
}
|
|
32
|
+
|
|
29
33
|
if (char >= 'a' && char <= 'z') {
|
|
30
34
|
return 0.6;
|
|
31
35
|
}
|
|
36
|
+
|
|
32
37
|
if (char >= 'A' && char <= 'Z') {
|
|
33
38
|
return 0.74;
|
|
34
39
|
}
|
|
40
|
+
|
|
35
41
|
if (char >= '0' && char <= '9') {
|
|
36
42
|
return 0.64;
|
|
37
43
|
}
|
|
44
|
+
|
|
38
45
|
// CJK and everything after it is set on a full em; any other letter is taken as a wide Latin one.
|
|
39
46
|
return char.codePointAt(0)! >= 0x2e80 ? 1 : 0.64;
|
|
40
47
|
}
|
|
@@ -44,23 +51,29 @@ const REGULAR = 0.94;
|
|
|
44
51
|
/* No DOM in this package, so text is estimated rather than measured, the same way on every machine. */
|
|
45
52
|
export function estimateTextWidth(text: string, size: number, bold = false): number {
|
|
46
53
|
let units = 0;
|
|
54
|
+
|
|
47
55
|
for (const char of text) {
|
|
48
56
|
units += ratioOf(char);
|
|
49
57
|
}
|
|
58
|
+
|
|
50
59
|
return Math.ceil(units * size * (bold ? 1 : REGULAR));
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
function breakWord(word: string, size: number, bold: boolean, maxWidth: number): string[] {
|
|
54
63
|
const pieces: string[] = [];
|
|
55
64
|
let piece = '';
|
|
65
|
+
|
|
56
66
|
for (const char of word) {
|
|
57
67
|
if (piece !== '' && estimateTextWidth(piece + char, size, bold) > maxWidth) {
|
|
58
68
|
pieces.push(piece);
|
|
59
69
|
piece = '';
|
|
60
70
|
}
|
|
71
|
+
|
|
61
72
|
piece += char;
|
|
62
73
|
}
|
|
74
|
+
|
|
63
75
|
pieces.push(piece);
|
|
76
|
+
|
|
64
77
|
return pieces;
|
|
65
78
|
}
|
|
66
79
|
|
|
@@ -69,12 +82,16 @@ export function wrapText(text: string, size: number, bold: boolean, maxWidth: nu
|
|
|
69
82
|
.trim()
|
|
70
83
|
.split(/\s+/)
|
|
71
84
|
.filter((word) => word !== '');
|
|
85
|
+
|
|
72
86
|
const lines: string[] = [];
|
|
73
87
|
let line = '';
|
|
88
|
+
|
|
74
89
|
for (const word of words) {
|
|
75
90
|
const pieces = estimateTextWidth(word, size, bold) > maxWidth ? breakWord(word, size, bold, maxWidth) : [word];
|
|
91
|
+
|
|
76
92
|
for (const piece of pieces) {
|
|
77
93
|
const joined = line === '' ? piece : `${line} ${piece}`;
|
|
94
|
+
|
|
78
95
|
if (line !== '' && estimateTextWidth(joined, size, bold) > maxWidth) {
|
|
79
96
|
lines.push(line);
|
|
80
97
|
line = piece;
|
|
@@ -83,7 +100,9 @@ export function wrapText(text: string, size: number, bold: boolean, maxWidth: nu
|
|
|
83
100
|
}
|
|
84
101
|
}
|
|
85
102
|
}
|
|
103
|
+
|
|
86
104
|
lines.push(line);
|
|
105
|
+
|
|
87
106
|
return lines;
|
|
88
107
|
}
|
|
89
108
|
|