@leafer-ui/text 1.0.0-beta.6 → 1.0.0-beta.8
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 +4 -4
- package/src/CharType.ts +29 -4
- package/src/TextLayout.ts +2 -0
- package/src/TextRows.ts +4 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/text",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.8",
|
|
4
4
|
"description": "@leafer-ui/text",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer-ui/core": "1.0.0-beta.
|
|
22
|
+
"@leafer-ui/core": "1.0.0-beta.8"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.0.0-beta.
|
|
26
|
-
"@leafer-ui/interface": "1.0.0-beta.
|
|
25
|
+
"@leafer/interface": "1.0.0-beta.8",
|
|
26
|
+
"@leafer-ui/interface": "1.0.0-beta.8"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/CharType.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { IBooleanMap } from '@leafer-ui/interface'
|
|
|
3
3
|
const money = '¥¥$€££¢¢'
|
|
4
4
|
const letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'
|
|
5
5
|
|
|
6
|
-
const langBefore = '
|
|
7
|
-
const langAfter = '
|
|
6
|
+
const langBefore = '《(「〈『〖【〔{┌<‘“=' + money
|
|
7
|
+
const langAfter = '》)」〉』〗】〕}┐>’”!?,、。:;‰'
|
|
8
8
|
const langSymbol = '≮≯≈≠=…'
|
|
9
9
|
const langBreak = '—/~|┆·'
|
|
10
10
|
|
|
@@ -13,6 +13,31 @@ const afterChar = '>)]}%!?,.:;\'"' + langAfter
|
|
|
13
13
|
const symbolChar = afterChar + '_#~&*+\\=|' + langSymbol
|
|
14
14
|
const breakChar = '- ' + langBreak
|
|
15
15
|
|
|
16
|
+
const cjkRangeList = [
|
|
17
|
+
[0x4E00, 0x9FFF], // CJK Unified Ideographs
|
|
18
|
+
[0x3400, 0x4DBF], // CJK Unified Ideographs Extension A
|
|
19
|
+
[0x20000, 0x2A6DF], // CJK Unified Ideographs Extension B
|
|
20
|
+
[0x2A700, 0x2B73F], // CJK Unified Ideographs Extension C
|
|
21
|
+
[0x2B740, 0x2B81F], // CJK Unified Ideographs Extension D
|
|
22
|
+
[0x2B820, 0x2CEAF], // CJK Unified Ideographs Extension E
|
|
23
|
+
[0x2CEB0, 0x2EBEF], // CJK Unified Ideographs Extension F
|
|
24
|
+
[0x30000, 0x3134F], // CJK Unified Ideographs Extension G
|
|
25
|
+
[0x31350, 0x323AF], // CJK Unified Ideographs Extension H
|
|
26
|
+
[0x2E80, 0x2EFF], // CJK Radicals Supplement
|
|
27
|
+
[0x2F00, 0x2FDF], // Kangxi Radicals
|
|
28
|
+
[0x2FF0, 0x2FFF], // Ideographic Description Characters
|
|
29
|
+
[0x3000, 0x303F], // CJK Symbols and Punctuation
|
|
30
|
+
[0x31C0, 0x31EF], // CJK Strokes
|
|
31
|
+
[0x3200, 0x32FF], // Enclosed CJK Letters and Months
|
|
32
|
+
[0x3300, 0x33FF], // CJK Compatibility
|
|
33
|
+
[0xF900, 0xFAFF], // CJK Compatibility Ideographs
|
|
34
|
+
[0xFE30, 0xFE4F], // CJK Compatibility Forms
|
|
35
|
+
[0x1F200, 0x1F2FF], // Enclosed Ideographic Supplement
|
|
36
|
+
[0x2F800, 0x2FA1F], // CJK Compatibility Ideographs Supplement
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join('|'))
|
|
40
|
+
|
|
16
41
|
function mapChar(str: string): IBooleanMap {
|
|
17
42
|
const map: IBooleanMap = {}
|
|
18
43
|
str.split('').forEach(char => map[char] = true)
|
|
@@ -42,14 +67,14 @@ export function getCharType(char: string): CharType {
|
|
|
42
67
|
return Letter
|
|
43
68
|
} else if (breakMap[char]) {
|
|
44
69
|
return Break
|
|
45
|
-
} else if (/[\u3400-\u9FBF]/.test(char)) { // 4e00-\u9FBF cjk
|
|
46
|
-
return Single
|
|
47
70
|
} else if (beforeMap[char]) {
|
|
48
71
|
return Before
|
|
49
72
|
} else if (afterMap[char]) {
|
|
50
73
|
return After
|
|
51
74
|
} else if (symbolMap[char]) {
|
|
52
75
|
return Symbol
|
|
76
|
+
} else if (cjkReg.test(char)) {
|
|
77
|
+
return Single
|
|
53
78
|
} else {
|
|
54
79
|
return Letter
|
|
55
80
|
}
|
package/src/TextLayout.ts
CHANGED
package/src/TextRows.ts
CHANGED
|
@@ -23,7 +23,7 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
23
23
|
const { __letterSpacing, paraIndent, textCase } = style
|
|
24
24
|
const { canvas } = Platform
|
|
25
25
|
const { width, height } = bounds
|
|
26
|
-
const charMode = width || height || __letterSpacing || textCase
|
|
26
|
+
const charMode = width || height || __letterSpacing || (textCase !== 'none')
|
|
27
27
|
|
|
28
28
|
if (charMode) {
|
|
29
29
|
|
|
@@ -103,7 +103,7 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
103
103
|
if (wordWidth) addWord()
|
|
104
104
|
if (rowWidth) addRow()
|
|
105
105
|
|
|
106
|
-
rows[rows.length - 1].paraEnd = true
|
|
106
|
+
rows.length > 0 && (rows[rows.length - 1].paraEnd = true)
|
|
107
107
|
|
|
108
108
|
} else {
|
|
109
109
|
|
|
@@ -136,9 +136,8 @@ function addRow(): void {
|
|
|
136
136
|
paraStart = false
|
|
137
137
|
}
|
|
138
138
|
row.width = rowWidth
|
|
139
|
-
trimRight(row)
|
|
139
|
+
if (bounds.width) trimRight(row)
|
|
140
140
|
rows.push(row)
|
|
141
|
-
if (row.width > bounds.width) bounds.width = row.width
|
|
142
141
|
row = { words: [] }
|
|
143
142
|
rowWidth = 0
|
|
144
|
-
}
|
|
143
|
+
}
|