@leafer-ui/text 1.3.3 → 1.4.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.3.3",
3
+ "version": "1.4.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.3.3"
25
+ "@leafer/core": "1.4.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.3.3",
29
- "@leafer-ui/interface": "1.3.3"
28
+ "@leafer/interface": "1.4.0",
29
+ "@leafer-ui/interface": "1.4.0"
30
30
  }
31
31
  }
package/src/CharLayout.ts CHANGED
@@ -9,13 +9,13 @@ export function layoutChar(drawData: ITextDrawData, style: ITextData, width: num
9
9
 
10
10
  const { rows } = drawData
11
11
  const { textAlign, paraIndent, letterSpacing } = style
12
- let charX: number, addWordWidth: number, indentWidth: number, mode: number, wordChar: ITextCharData
12
+ let charX: number, addWordWidth: number, indentWidth: number, mode: number, wordChar: ITextCharData, wordsLength: number
13
13
 
14
14
  rows.forEach(row => {
15
15
  if (row.words) {
16
16
 
17
- indentWidth = paraIndent && row.paraStart ? paraIndent : 0
18
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0
17
+ indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length
18
+ addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0
19
19
  mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode)
20
20
  if (row.isOverflow && !letterSpacing) row.textMode = true
21
21
 
@@ -30,7 +30,7 @@ export function layoutChar(drawData: ITextDrawData, style: ITextData, width: num
30
30
  charX = row.x
31
31
  row.data = []
32
32
 
33
- row.words.forEach(word => {
33
+ row.words.forEach((word, index) => {
34
34
 
35
35
  if (mode === WordMode) {
36
36
 
@@ -44,7 +44,7 @@ export function layoutChar(drawData: ITextDrawData, style: ITextData, width: num
44
44
 
45
45
  }
46
46
 
47
- if (addWordWidth && (!row.paraEnd || textAlign === 'both')) {
47
+ if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
48
48
  charX += addWordWidth
49
49
  row.width += addWordWidth
50
50
  }