@leafer-ui/text 1.0.0-rc.8 → 1.0.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 +5 -5
- package/src/CharLayout.ts +4 -4
- package/src/TextClip.ts +7 -6
- package/src/TextConvert.ts +28 -32
- package/src/TextLayout.ts +8 -6
- package/src/TextRows.ts +3 -3
- package/src/index.ts +7 -1
- package/types/index.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/text",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "@leafer-ui/text",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/leaferjs/ui.git"
|
|
17
17
|
},
|
|
18
|
-
"homepage": "https://github.com/leaferjs/ui/tree/main/packages/text",
|
|
18
|
+
"homepage": "https://github.com/leaferjs/ui/tree/main/packages/partner/text",
|
|
19
19
|
"bugs": "https://github.com/leaferjs/ui/issues",
|
|
20
20
|
"keywords": [
|
|
21
21
|
"leafer-ui",
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer
|
|
25
|
+
"@leafer/core": "1.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0
|
|
29
|
-
"@leafer-ui/interface": "1.0.0
|
|
28
|
+
"@leafer/interface": "1.0.0",
|
|
29
|
+
"@leafer-ui/interface": "1.0.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/CharLayout.ts
CHANGED
|
@@ -36,11 +36,11 @@ export function layoutChar(drawData: ITextDrawData, style: ITextData, width: num
|
|
|
36
36
|
|
|
37
37
|
wordChar = { char: '', x: charX }
|
|
38
38
|
charX = toWordChar(word.data, charX, wordChar)
|
|
39
|
-
if (wordChar.char !== ' ') row.data.push(wordChar)
|
|
39
|
+
if (row.isOverflow || wordChar.char !== ' ') row.data.push(wordChar)
|
|
40
40
|
|
|
41
41
|
} else {
|
|
42
42
|
|
|
43
|
-
charX = toChar(word.data, charX, row.data)
|
|
43
|
+
charX = toChar(word.data, charX, row.data, row.isOverflow)
|
|
44
44
|
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -75,9 +75,9 @@ function toWordChar(data: ITextCharData[], charX: number, wordChar: ITextCharDat
|
|
|
75
75
|
return charX
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
function toChar(data: ITextCharData[], charX: number, rowData: ITextCharData[]): number {
|
|
78
|
+
function toChar(data: ITextCharData[], charX: number, rowData: ITextCharData[], isOverflow?: boolean): number {
|
|
79
79
|
data.forEach(char => {
|
|
80
|
-
if (char.char !== ' ') {
|
|
80
|
+
if (isOverflow || char.char !== ' ') {
|
|
81
81
|
char.x = charX
|
|
82
82
|
rowData.push(char)
|
|
83
83
|
}
|
package/src/TextClip.ts
CHANGED
|
@@ -3,19 +3,20 @@ import { Platform } from '@leafer/core'
|
|
|
3
3
|
import { ITextCharData, ITextData, ITextDrawData, ITextRowData } from '@leafer-ui/interface'
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
export function clipText(drawData: ITextDrawData, style: ITextData): void {
|
|
6
|
+
export function clipText(drawData: ITextDrawData, style: ITextData, x: number, width: number): void {
|
|
7
|
+
if (!width) return
|
|
7
8
|
|
|
8
9
|
const { rows, overflow } = drawData
|
|
9
10
|
let { textOverflow } = style
|
|
10
11
|
rows.splice(overflow)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (textOverflow === 'ellipsis') textOverflow = '...'
|
|
13
|
+
if (textOverflow && textOverflow !== 'show') {
|
|
14
|
+
if (textOverflow === 'hide') textOverflow = ''
|
|
15
|
+
else if (textOverflow === 'ellipsis') textOverflow = '...'
|
|
15
16
|
|
|
16
17
|
let char: ITextCharData, charRight: number
|
|
17
|
-
const ellipsisWidth = Platform.canvas.measureText(textOverflow).width
|
|
18
|
-
const right =
|
|
18
|
+
const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0
|
|
19
|
+
const right = x + width - ellipsisWidth
|
|
19
20
|
const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]]
|
|
20
21
|
|
|
21
22
|
list.forEach(row => {
|
package/src/TextConvert.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Platform, Direction4 } from '@leafer/core'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ITextData, ITextDrawData } from '@leafer-ui/interface'
|
|
4
4
|
|
|
5
5
|
import { createRows } from './TextRows'
|
|
6
6
|
import { layoutChar } from './CharLayout'
|
|
@@ -11,52 +11,48 @@ import { decorationText } from './TextDecoration'
|
|
|
11
11
|
|
|
12
12
|
const { top, right, bottom, left } = Direction4
|
|
13
13
|
|
|
14
|
-
export
|
|
14
|
+
export function getDrawData(content: string, style: ITextData): ITextDrawData {
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
if (typeof content !== 'string') content = String(content)
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
let x = 0, y = 0
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
let width = style.__getInput('width') || 0
|
|
21
|
+
let height = style.__getInput('height') || 0
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
let height = style.__getInput('height') || 0
|
|
23
|
+
const { textDecoration, __font, __padding: padding } = style
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
x = padding[left]
|
|
30
|
-
width -= (padding[right] + padding[left])
|
|
31
|
-
}
|
|
32
|
-
if (height) {
|
|
33
|
-
y = padding[top]
|
|
34
|
-
height -= (padding[top] + padding[bottom])
|
|
35
|
-
}
|
|
25
|
+
if (padding) {
|
|
26
|
+
if (width) {
|
|
27
|
+
x = padding[left]
|
|
28
|
+
width -= (padding[right] + padding[left])
|
|
36
29
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
rows: [],
|
|
41
|
-
paraNumber: 0,
|
|
42
|
-
font: Platform.canvas.font = __font
|
|
30
|
+
if (height) {
|
|
31
|
+
y = padding[top]
|
|
32
|
+
height -= (padding[top] + padding[bottom])
|
|
43
33
|
}
|
|
34
|
+
}
|
|
44
35
|
|
|
45
|
-
|
|
36
|
+
const drawData: ITextDrawData = {
|
|
37
|
+
bounds: { x, y, width, height },
|
|
38
|
+
rows: [],
|
|
39
|
+
paraNumber: 0,
|
|
40
|
+
font: Platform.canvas.font = __font
|
|
41
|
+
}
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
createRows(drawData, content, style) // set rows, paraNumber
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
if (padding) padAutoText(padding, drawData, style, width, height)
|
|
50
46
|
|
|
51
|
-
|
|
47
|
+
layoutText(drawData, style) // set bounds
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
layoutChar(drawData, style, width, height) // set char.x
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
if (drawData.overflow) clipText(drawData, style, x, width)
|
|
56
52
|
|
|
57
|
-
|
|
53
|
+
if (textDecoration !== 'none') decorationText(drawData, style)
|
|
58
54
|
|
|
59
|
-
|
|
55
|
+
return drawData
|
|
60
56
|
|
|
61
57
|
}
|
|
62
58
|
|
package/src/TextLayout.ts
CHANGED
|
@@ -33,12 +33,14 @@ export function layoutText(drawData: ITextDrawData, style: ITextData): void {
|
|
|
33
33
|
row = rows[i]
|
|
34
34
|
row.x = x
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
if (row.width < width || (row.width > width && !__clipText)) {
|
|
37
|
+
switch (textAlign) {
|
|
38
|
+
case 'center':
|
|
39
|
+
row.x += (width - row.width) / 2
|
|
40
|
+
break
|
|
41
|
+
case 'right':
|
|
42
|
+
row.x += width - row.width
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing
|
package/src/TextRows.ts
CHANGED
|
@@ -69,7 +69,7 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
69
69
|
if (breakAll) {
|
|
70
70
|
|
|
71
71
|
if (wordWidth) addWord() // break
|
|
72
|
-
addRow()
|
|
72
|
+
if (rowWidth) addRow()
|
|
73
73
|
|
|
74
74
|
} else {
|
|
75
75
|
if (!afterBreak) afterBreak = charType === Letter && lastCharType == After // split ,S
|
|
@@ -77,11 +77,11 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
77
77
|
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
|
|
78
78
|
|
|
79
79
|
if (wordWidth) addWord() // break
|
|
80
|
-
addRow()
|
|
80
|
+
if (rowWidth) addRow()
|
|
81
81
|
|
|
82
82
|
} else {
|
|
83
83
|
|
|
84
|
-
addRow()
|
|
84
|
+
if (rowWidth) addRow()
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
package/src/index.ts
CHANGED
package/types/index.d.ts
CHANGED