@aseity/igrid-react 0.4.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @aseity/igrid-react
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Improve CJK wrapping across rich-text runs, preserve explicit paragraph
8
+ indentation, and use actual font bounds to prevent overly tight multiline spacing.
9
+ - Update the exact engine dependency to `@aseity/igrid-engine@0.5.0`, adding
10
+ named-constant calculation and correcting merged borders and hidden dimensions.
11
+
12
+ ## 0.4.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Prevent text strokes from being clipped in short rows and correct raised text when the font box is taller than the row. Keep visible glyphs inside the row while preserving normal alignment in taller rows.
17
+ - Synchronize the exact engine dependency to `@aseity/igrid-engine@0.4.1`.
18
+
3
19
  ## 0.4.0
4
20
 
5
21
  ### Minor Changes
package/dist/text.js CHANGED
@@ -16,9 +16,6 @@ export function drawText(context, list, index) {
16
16
  ];
17
17
  }
18
18
  const lines = wrap ? wrapLines(context, segments, available) : [segments];
19
- const lineHeight = ((Math.max(base.size, ...segments.map((segment) => segment.size)) * 96) /
20
- 72) *
21
- 1.25;
22
19
  context.textBaseline = "alphabetic";
23
20
  const metrics = lines
24
21
  .flat()
@@ -29,16 +26,41 @@ export function drawText(context, list, index) {
29
26
  });
30
27
  const ascent = Math.max(0, ...metrics.map((metric) => metric.fontBoundingBoxAscent));
31
28
  const descent = Math.max(0, ...metrics.map((metric) => metric.fontBoundingBoxDescent));
29
+ const lineHeight = Math.max(((Math.max(base.size, ...segments.map((segment) => segment.size)) * 96) /
30
+ 72) *
31
+ 1.25, ascent + descent);
32
32
  const blockHeight = (lines.length - 1) * lineHeight + ascent + descent;
33
33
  const top = vertical === 0
34
34
  ? y + 2
35
35
  : vertical === 1
36
36
  ? y + (height - blockHeight) / 2
37
37
  : y + height - blockHeight - 1;
38
+ let firstBaseline = top + ascent;
39
+ if (blockHeight > height - 2) {
40
+ const ink = lines.flatMap((line, lineIndex) => line
41
+ .filter((segment) => !segment.spacing && segment.text.trim())
42
+ .map((segment) => {
43
+ context.font = segment.font;
44
+ const metrics = context.measureText(segment.text);
45
+ return {
46
+ top: lineIndex * lineHeight - metrics.actualBoundingBoxAscent,
47
+ bottom: lineIndex * lineHeight + metrics.actualBoundingBoxDescent,
48
+ };
49
+ }));
50
+ if (ink.length) {
51
+ const inkTop = Math.min(...ink.map((bounds) => bounds.top));
52
+ const inkBottom = Math.max(...ink.map((bounds) => bounds.bottom));
53
+ const spare = height - (inkBottom - inkTop);
54
+ if (spare >= 0) {
55
+ const inset = Math.min(1, spare / 2);
56
+ firstBaseline = Math.max(y + inset - inkTop, Math.min(firstBaseline, y + height - inset - inkBottom));
57
+ }
58
+ }
59
+ }
38
60
  const [left, right] = list.text_bounds.subarray(index * 2, index * 2 + 2);
39
61
  context.save();
40
62
  context.beginPath();
41
- context.rect(left + 1, y + 1, Math.max(0, right - left - 2), Math.max(0, height - 2));
63
+ context.rect(left + 1, y, Math.max(0, right - left - 2), Math.max(0, height));
42
64
  context.clip();
43
65
  context.textAlign = "left";
44
66
  context.textBaseline = "alphabetic";
@@ -49,7 +71,7 @@ export function drawText(context, list, index) {
49
71
  : horizontal === 2
50
72
  ? x + (width - lineWidth) / 2
51
73
  : x + padding;
52
- const baseline = top + lineIndex * lineHeight + ascent;
74
+ const baseline = firstBaseline + lineIndex * lineHeight;
53
75
  for (const segment of line) {
54
76
  context.font = segment.font;
55
77
  context.fillStyle = segment.color;
@@ -142,24 +164,27 @@ function glyphs(data, index) {
142
164
  function wrapLines(context, segments, available) {
143
165
  const lines = [[]];
144
166
  let width = 0;
145
- const newline = () => {
167
+ let paragraphStart = true;
168
+ const newline = (explicit = false) => {
146
169
  lines.push([]);
147
170
  width = 0;
171
+ paragraphStart = explicit;
148
172
  };
149
173
  for (const segment of segments) {
150
174
  context.font = segment.font;
151
- for (const token of segment.text.split(/(\n|[^\S\n]+)/)) {
175
+ for (const token of segment.text.split(/(\r\n|[\r\n]|[^\S\r\n]+|[(「『【《〈“‘]*[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Bopomofo}][,。、;:!?)』」】》〉”’]*)/u)) {
152
176
  if (!token)
153
177
  continue;
154
- if (token === "\n") {
155
- newline();
178
+ if (/^[\r\n]+$/.test(token)) {
179
+ newline(true);
156
180
  continue;
157
181
  }
158
182
  let tokenWidth = context.measureText(token).width;
159
- if (width && width + tokenWidth > available)
183
+ if (width && width + tokenWidth > available && tokenWidth <= available)
160
184
  newline();
161
- if (!width && /^\s+$/.test(token))
185
+ if (!width && !paragraphStart && /^\s+$/.test(token))
162
186
  continue;
187
+ paragraphStart = false;
163
188
  if (tokenWidth <= available) {
164
189
  lines[lines.length - 1].push({
165
190
  ...segment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aseity/igrid-react",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -11,7 +11,7 @@
11
11
  "./styles.css": "./dist/style.css"
12
12
  },
13
13
  "dependencies": {
14
- "@aseity/igrid-engine": "0.4.0",
14
+ "@aseity/igrid-engine": "0.5.0",
15
15
  "echarts": "6.1.0"
16
16
  },
17
17
  "peerDependencies": {