@leafer-ui/text 1.0.0-beta → 1.0.0-beta.10

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.0.0-beta",
3
+ "version": "1.0.0-beta.10",
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.10"
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.10",
26
+ "@leafer-ui/interface": "1.0.0-beta.10"
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 = '《(「〈『〖【〔{┌<’“=' + money
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
@@ -11,21 +11,19 @@ export function layoutText(drawData: ITextDrawData, style: ITextData): void {
11
11
 
12
12
  // verticalAlign
13
13
 
14
- if (height) {
15
- if (textOverflow !== 'show' && realHeight > height) {
16
- realHeight = Math.max(height, __lineHeight)
17
- drawData.overflow = rows.length
18
- } else {
19
- switch (verticalAlign) {
20
- case 'middle':
21
- y += (height - realHeight) / 2
22
- break
23
- case 'bottom':
24
- y += (height - realHeight)
25
- }
14
+ if (textOverflow !== 'show' && realHeight > height) {
15
+ realHeight = Math.max(height, __lineHeight)
16
+ drawData.overflow = rows.length
17
+ } else {
18
+ switch (verticalAlign) {
19
+ case 'middle':
20
+ y += (height - realHeight) / 2
21
+ break
22
+ case 'bottom':
23
+ y += (height - realHeight)
26
24
  }
27
- starY += y
28
25
  }
26
+ starY += y
29
27
 
30
28
  // textAlign
31
29
 
@@ -53,6 +51,9 @@ export function layoutText(drawData: ITextDrawData, style: ITextData): void {
53
51
  row.isOverflow = true
54
52
  drawData.overflow = i + 1
55
53
  }
54
+
55
+ if (row.x < bounds.x) bounds.x = row.x
56
+ if (row.width > bounds.width) bounds.width = row.width
56
57
  }
57
58
 
58
59
  bounds.y = y
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
 
@@ -74,7 +74,11 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
74
74
 
75
75
  }
76
76
 
77
- if (!(char === ' ' && (rowWidth + wordWidth) === 0)) {
77
+ if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) {
78
+
79
+ // trim space
80
+
81
+ } else {
78
82
 
79
83
  if (charType === Break) {
80
84
 
@@ -103,7 +107,7 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
103
107
  if (wordWidth) addWord()
104
108
  if (rowWidth) addRow()
105
109
 
106
- rows[rows.length - 1].paraEnd = true
110
+ rows.length > 0 && (rows[rows.length - 1].paraEnd = true)
107
111
 
108
112
  } else {
109
113
 
@@ -136,9 +140,8 @@ function addRow(): void {
136
140
  paraStart = false
137
141
  }
138
142
  row.width = rowWidth
139
- trimRight(row)
143
+ if (bounds.width) trimRight(row)
140
144
  rows.push(row)
141
- if (row.width > bounds.width) bounds.width = row.width
142
145
  row = { words: [] }
143
146
  rowWidth = 0
144
- }
147
+ }