@leafer-ui/text 1.4.2 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/text",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "description": "@leafer-ui/text",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.4.2"
25
+ "@leafer/core": "1.5.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.4.2",
29
- "@leafer-ui/interface": "1.4.2"
28
+ "@leafer/interface": "1.5.0",
29
+ "@leafer-ui/interface": "1.5.0"
30
30
  }
31
31
  }
package/src/TextClip.ts CHANGED
@@ -30,7 +30,7 @@ export function clipText(drawData: ITextDrawData, style: ITextData, x: number, w
30
30
  charRight = char.x + char.width
31
31
  if (i === end && charRight < right) {
32
32
  break
33
- } else if (charRight < right && char.char !== ' ') {
33
+ } else if ((charRight < right && char.char !== ' ') || !i) { // 至少保留一个文字
34
34
  row.data.splice(i + 1)
35
35
  row.width -= char.width
36
36
  break
package/src/TextLayout.ts CHANGED
@@ -3,17 +3,17 @@ import { ITextData, ITextDrawData, ITextRowData } from '@leafer-ui/interface'
3
3
 
4
4
  export function layoutText(drawData: ITextDrawData, style: ITextData): void {
5
5
 
6
- const { rows, bounds } = drawData
6
+ const { rows, bounds } = drawData, countRows = rows.length
7
7
  const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style
8
8
 
9
- let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0)
9
+ let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0)
10
10
  let starY: number = __baseLine
11
11
 
12
12
  // verticalAlign
13
13
 
14
14
  if (__clipText && realHeight > height) {
15
15
  realHeight = Math.max(height, __lineHeight)
16
- drawData.overflow = rows.length
16
+ if (countRows > 1) drawData.overflow = countRows
17
17
  } else if (height || autoSizeAlign) {
18
18
  switch (verticalAlign) {
19
19
  case 'middle': y += (height - realHeight) / 2; break
@@ -26,7 +26,7 @@ export function layoutText(drawData: ITextDrawData, style: ITextData): void {
26
26
 
27
27
  let row: ITextRowData, rowX: number, rowWidth: number, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth
28
28
 
29
- for (let i = 0, len = rows.length; i < len; i++) {
29
+ for (let i = 0, len = countRows; i < len; i++) {
30
30
  row = rows[i]
31
31
  row.x = x
32
32