@next2d/text 3.0.5 → 3.2.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 +6 -6
- package/src/TextParser/service/TextParserHtmlParserService.d.ts +14 -0
- package/src/TextParser/service/TextParserHtmlParserService.js +316 -0
- package/src/TextParser/usecase/TextParserParseHtmlTextUseCase.js +1 -2
- package/src/TextParser/usecase/TextParserParseTagUseCase.d.ts +5 -5
- package/src/TextParser/usecase/TextParserParseTagUseCase.js +497 -30
- package/src/interface/IHtmlNode.d.ts +24 -0
- package/src/interface/IHtmlNode.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/text",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Next2D Text Package",
|
|
5
5
|
"author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"url": "git+https://github.com/Next2D/Player.git"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@next2d/display": "3.0
|
|
28
|
-
"@next2d/geom": "3.0
|
|
29
|
-
"@next2d/events": "3.0
|
|
30
|
-
"@next2d/ui": "3.0
|
|
31
|
-
"@next2d/cache": "3.0
|
|
27
|
+
"@next2d/display": "3.2.0",
|
|
28
|
+
"@next2d/geom": "3.2.0",
|
|
29
|
+
"@next2d/events": "3.2.0",
|
|
30
|
+
"@next2d/ui": "3.2.0",
|
|
31
|
+
"@next2d/cache": "3.2.0"
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IHtmlNode } from "../../interface/IHtmlNode";
|
|
2
|
+
/**
|
|
3
|
+
* @description 軽量HTMLパーサ — TextField用の限定HTMLサブセットを1-passで解析
|
|
4
|
+
* 対応タグ: B, I, U, P, BR, DIV, FONT, SPAN
|
|
5
|
+
* 対応属性: align, face, size, color, style, letterSpacing,
|
|
6
|
+
* leading, leftMargin, rightMargin, underline, bold, italic
|
|
7
|
+
* Lightweight HTML parser — single-pass parse for TextField HTML subset
|
|
8
|
+
*
|
|
9
|
+
* @param {string} html - 解析対象のHTML文字列 / HTML string to parse
|
|
10
|
+
* @return {IHtmlNode[]} 解析結果のノード配列 / Array of parsed nodes
|
|
11
|
+
* @method
|
|
12
|
+
* @protected
|
|
13
|
+
*/
|
|
14
|
+
export declare const execute: (html: string) => IHtmlNode[];
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description モジュールレベルのパーサ状態(クロージャ生成を回避)
|
|
3
|
+
* Module-level parser state (avoids closure allocation)
|
|
4
|
+
*
|
|
5
|
+
* @type {string}
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
let _$html = "";
|
|
9
|
+
/**
|
|
10
|
+
* @description 現在の解析位置
|
|
11
|
+
* Current parse position
|
|
12
|
+
*
|
|
13
|
+
* @type {number}
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
let _$pos = 0;
|
|
17
|
+
/**
|
|
18
|
+
* @description HTML文字列の長さ(キャッシュ)
|
|
19
|
+
* Cached length of the HTML string
|
|
20
|
+
*
|
|
21
|
+
* @type {number}
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
let _$len = 0;
|
|
25
|
+
/**
|
|
26
|
+
* @description void要素(BR等)の空children共有インスタンス
|
|
27
|
+
* 再利用によりアロケーションを回避する
|
|
28
|
+
* Shared empty children array for void elements (e.g. BR)
|
|
29
|
+
* Reused across calls to avoid allocation
|
|
30
|
+
*
|
|
31
|
+
* @type {IHtmlNode[]}
|
|
32
|
+
* @const
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
const $EMPTY_CHILDREN = [];
|
|
36
|
+
/**
|
|
37
|
+
* @description 軽量HTMLパーサ — TextField用の限定HTMLサブセットを1-passで解析
|
|
38
|
+
* 対応タグ: B, I, U, P, BR, DIV, FONT, SPAN
|
|
39
|
+
* 対応属性: align, face, size, color, style, letterSpacing,
|
|
40
|
+
* leading, leftMargin, rightMargin, underline, bold, italic
|
|
41
|
+
* Lightweight HTML parser — single-pass parse for TextField HTML subset
|
|
42
|
+
*
|
|
43
|
+
* @param {string} html - 解析対象のHTML文字列 / HTML string to parse
|
|
44
|
+
* @return {IHtmlNode[]} 解析結果のノード配列 / Array of parsed nodes
|
|
45
|
+
* @method
|
|
46
|
+
* @protected
|
|
47
|
+
*/
|
|
48
|
+
export const execute = (html) => {
|
|
49
|
+
_$html = html;
|
|
50
|
+
_$pos = 0;
|
|
51
|
+
_$len = html.length;
|
|
52
|
+
const result = $parseChildren("");
|
|
53
|
+
_$html = "";
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* @description 子ノードを再帰的に解析する
|
|
58
|
+
* parentTagに一致する閉じタグを検出すると、そのスコープの解析を終了して返却する
|
|
59
|
+
* Recursively parse child nodes.
|
|
60
|
+
* Returns when a closing tag matching parent_tag is found.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} parent_tag - 親要素のタグ名(大文字)。ルートの場合は空文字列
|
|
63
|
+
* Parent element tag name (uppercase). Empty string for root.
|
|
64
|
+
* @return {IHtmlNode[]} 解析された子ノード配列 / Array of parsed child nodes
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
const $parseChildren = (parent_tag) => {
|
|
68
|
+
const nodes = [];
|
|
69
|
+
while (_$pos < _$len) {
|
|
70
|
+
const ltIdx = _$html.indexOf("<", _$pos);
|
|
71
|
+
if (ltIdx === -1) {
|
|
72
|
+
if (_$pos < _$len) {
|
|
73
|
+
nodes[nodes.length] = {
|
|
74
|
+
"type": "text",
|
|
75
|
+
"value": _$html.substring(_$pos)
|
|
76
|
+
};
|
|
77
|
+
_$pos = _$len;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
if (ltIdx > _$pos) {
|
|
82
|
+
nodes[nodes.length] = {
|
|
83
|
+
"type": "text",
|
|
84
|
+
"value": _$html.substring(_$pos, ltIdx)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
_$pos = ltIdx + 1;
|
|
88
|
+
if (_$pos >= _$len) {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
// closing tag: '</'
|
|
92
|
+
if (_$html.charCodeAt(_$pos) === 0x2F) {
|
|
93
|
+
_$pos++;
|
|
94
|
+
const gtIdx = _$html.indexOf(">", _$pos);
|
|
95
|
+
if (gtIdx === -1) {
|
|
96
|
+
_$pos = _$len;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (parent_tag && $matchesUpperCase(_$pos, gtIdx, parent_tag)) {
|
|
100
|
+
_$pos = gtIdx + 1;
|
|
101
|
+
return nodes;
|
|
102
|
+
}
|
|
103
|
+
_$pos = gtIdx + 1;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const tagStart = _$pos;
|
|
107
|
+
while (_$pos < _$len) {
|
|
108
|
+
const c = _$html.charCodeAt(_$pos);
|
|
109
|
+
if (c === 0x3E || c === 0x2F || c === 0x20 || c === 0x09) {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
_$pos++;
|
|
113
|
+
}
|
|
114
|
+
const tagName = $toUpperCase(tagStart, _$pos);
|
|
115
|
+
const attributes = $parseAttributes();
|
|
116
|
+
// self-closing '/>'
|
|
117
|
+
let selfClosing = false;
|
|
118
|
+
if (_$pos < _$len && _$html.charCodeAt(_$pos) === 0x2F) {
|
|
119
|
+
selfClosing = true;
|
|
120
|
+
_$pos++;
|
|
121
|
+
}
|
|
122
|
+
if (_$pos < _$len && _$html.charCodeAt(_$pos) === 0x3E) {
|
|
123
|
+
_$pos++;
|
|
124
|
+
}
|
|
125
|
+
if (selfClosing || tagName === "BR") {
|
|
126
|
+
nodes[nodes.length] = {
|
|
127
|
+
"type": "element",
|
|
128
|
+
"tagName": tagName,
|
|
129
|
+
"attributes": attributes,
|
|
130
|
+
"children": $EMPTY_CHILDREN
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
nodes[nodes.length] = {
|
|
135
|
+
"type": "element",
|
|
136
|
+
"tagName": tagName,
|
|
137
|
+
"attributes": attributes,
|
|
138
|
+
"children": $parseChildren(tagName)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return nodes;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* @description 現在位置から開始タグの属性を解析して IAttributeObject[] として返す
|
|
146
|
+
* 属性形式: name="value", name='value', name=value, name (boolean)
|
|
147
|
+
* '>' または '/' に到達した時点で解析を終了する
|
|
148
|
+
* Parse attributes from current position and return as IAttributeObject[].
|
|
149
|
+
* Supports: name="value", name='value', name=value, name (boolean).
|
|
150
|
+
* Stops when '>' or '/' is encountered.
|
|
151
|
+
*
|
|
152
|
+
* @return {IAttributeObject[]} 解析された属性オブジェクトの配列 / Array of parsed attribute objects
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
const $parseAttributes = () => {
|
|
156
|
+
const attrs = [];
|
|
157
|
+
while (_$pos < _$len) {
|
|
158
|
+
while (_$pos < _$len) {
|
|
159
|
+
const c = _$html.charCodeAt(_$pos);
|
|
160
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
_$pos++;
|
|
164
|
+
}
|
|
165
|
+
if (_$pos >= _$len) {
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
const ch = _$html.charCodeAt(_$pos);
|
|
169
|
+
// '>' or '/'
|
|
170
|
+
if (ch === 0x3E || ch === 0x2F) {
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
const nameStart = _$pos;
|
|
174
|
+
while (_$pos < _$len) {
|
|
175
|
+
const c = _$html.charCodeAt(_$pos);
|
|
176
|
+
if (c === 0x3D || c === 0x3E || c === 0x2F || c === 0x20 || c === 0x09) {
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
_$pos++;
|
|
180
|
+
}
|
|
181
|
+
if (_$pos === nameStart) {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
const name = _$html.substring(nameStart, _$pos);
|
|
185
|
+
while (_$pos < _$len) {
|
|
186
|
+
const c = _$html.charCodeAt(_$pos);
|
|
187
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
_$pos++;
|
|
191
|
+
}
|
|
192
|
+
if (_$pos < _$len && _$html.charCodeAt(_$pos) === 0x3D) {
|
|
193
|
+
_$pos++;
|
|
194
|
+
while (_$pos < _$len) {
|
|
195
|
+
const c = _$html.charCodeAt(_$pos);
|
|
196
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
_$pos++;
|
|
200
|
+
}
|
|
201
|
+
let value;
|
|
202
|
+
const quote = _$html.charCodeAt(_$pos);
|
|
203
|
+
if (quote === 0x22 || quote === 0x27) {
|
|
204
|
+
_$pos++;
|
|
205
|
+
const closeIdx = _$html.indexOf(quote === 0x22 ? "\"" : "'", _$pos);
|
|
206
|
+
if (closeIdx === -1) {
|
|
207
|
+
value = _$html.substring(_$pos);
|
|
208
|
+
_$pos = _$len;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
value = _$html.substring(_$pos, closeIdx);
|
|
212
|
+
_$pos = closeIdx + 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
// unquoted value
|
|
217
|
+
const valStart = _$pos;
|
|
218
|
+
while (_$pos < _$len) {
|
|
219
|
+
const c = _$html.charCodeAt(_$pos);
|
|
220
|
+
if (c === 0x3E || c === 0x2F || c === 0x20 || c === 0x09) {
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
_$pos++;
|
|
224
|
+
}
|
|
225
|
+
value = _$html.substring(valStart, _$pos);
|
|
226
|
+
}
|
|
227
|
+
attrs[attrs.length] = { "name": name, "value": value };
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
attrs[attrs.length] = { "name": name, "value": true };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return attrs;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* @description 閉じタグ名を文字列生成せずにparentTag(大文字)と照合する
|
|
237
|
+
* _$html[start..end) の範囲を1文字ずつ大文字変換しながら比較する
|
|
238
|
+
* ゼロアロケーションで一致判定を行い、GC圧を回避する
|
|
239
|
+
* Compare closing tag name against parent_tag (uppercase) without string allocation.
|
|
240
|
+
* Converts each character to uppercase via charCode and compares in-place.
|
|
241
|
+
* Zero-allocation comparison to avoid GC pressure.
|
|
242
|
+
*
|
|
243
|
+
* @param {number} start - 照合開始位置('</' の直後)/ Start index (right after '</')
|
|
244
|
+
* @param {number} end - 照合終了位置('>' の位置)/ End index (position of '>')
|
|
245
|
+
* @param {string} tag - 比較対象の親タグ名(大文字)/ Parent tag name to match (uppercase)
|
|
246
|
+
* @return {boolean} 一致する場合true / True if the closing tag matches
|
|
247
|
+
* @private
|
|
248
|
+
*/
|
|
249
|
+
const $matchesUpperCase = (start, end, tag) => {
|
|
250
|
+
while (start < end) {
|
|
251
|
+
const c = _$html.charCodeAt(start);
|
|
252
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
start++;
|
|
256
|
+
}
|
|
257
|
+
while (end > start) {
|
|
258
|
+
const c = _$html.charCodeAt(end - 1);
|
|
259
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
end--;
|
|
263
|
+
}
|
|
264
|
+
const tagLen = tag.length;
|
|
265
|
+
if (end - start !== tagLen) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
for (let i = 0; i < tagLen; i++) {
|
|
269
|
+
let c = _$html.charCodeAt(start + i);
|
|
270
|
+
if (c >= 0x61 && c <= 0x7A) {
|
|
271
|
+
c -= 0x20;
|
|
272
|
+
}
|
|
273
|
+
if (c !== tag.charCodeAt(i)) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return true;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* @description _$html[start..end) の部分文字列を大文字化して返す
|
|
281
|
+
* 1-2文字はString.fromCharCodeで直接生成(短いタグ名の最速パス)
|
|
282
|
+
* 3文字以上はsubstring().toUpperCase()にフォールバック
|
|
283
|
+
* Convert _$html[start..end) substring to uppercase.
|
|
284
|
+
* 1-2 char tags use String.fromCharCode (fastest path for short tag names).
|
|
285
|
+
* 3+ chars fall back to substring().toUpperCase().
|
|
286
|
+
*
|
|
287
|
+
* @param {number} start - 開始位置 / Start index
|
|
288
|
+
* @param {number} end - 終了位置 / End index (exclusive)
|
|
289
|
+
* @return {string} 大文字化されたタグ名 / Uppercased tag name
|
|
290
|
+
* @private
|
|
291
|
+
*/
|
|
292
|
+
const $toUpperCase = (start, end) => {
|
|
293
|
+
const length = end - start;
|
|
294
|
+
// 1文字タグ (B, I, U, P) — 最頻出パスを最速処理
|
|
295
|
+
if (length === 1) {
|
|
296
|
+
let c = _$html.charCodeAt(start);
|
|
297
|
+
if (c >= 0x61 && c <= 0x7A) {
|
|
298
|
+
c -= 0x20;
|
|
299
|
+
}
|
|
300
|
+
return String.fromCharCode(c);
|
|
301
|
+
}
|
|
302
|
+
// 2文字タグ (BR, DIV先頭判定高速化)
|
|
303
|
+
if (length === 2) {
|
|
304
|
+
let c0 = _$html.charCodeAt(start);
|
|
305
|
+
let c1 = _$html.charCodeAt(start + 1);
|
|
306
|
+
if (c0 >= 0x61 && c0 <= 0x7A) {
|
|
307
|
+
c0 -= 0x20;
|
|
308
|
+
}
|
|
309
|
+
if (c1 >= 0x61 && c1 <= 0x7A) {
|
|
310
|
+
c1 -= 0x20;
|
|
311
|
+
}
|
|
312
|
+
return String.fromCharCode(c0, c1);
|
|
313
|
+
}
|
|
314
|
+
// 3-4文字タグ (DIV, FONT, SPAN)
|
|
315
|
+
return _$html.substring(start, end).toUpperCase();
|
|
316
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TextData } from "../../TextData";
|
|
2
|
-
import { parseDocument } from "htmlparser2";
|
|
3
2
|
import { execute as textParserCreateNewLineUseCase } from "./TextParserCreateNewLineUseCase";
|
|
4
3
|
import { execute as textParserAdjustmentHeightService } from "../service/TextParserAdjustmentHeightService";
|
|
5
4
|
import { execute as textParserParseTagUseCase } from "./TextParserParseTagUseCase";
|
|
@@ -31,7 +30,7 @@ export const execute = (html_text, text_format, options) => {
|
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
textParserCreateNewLineUseCase(textData, textFormat);
|
|
34
|
-
textParserParseTagUseCase(
|
|
33
|
+
textParserParseTagUseCase(htmlText, textFormat, textData, options);
|
|
35
34
|
textParserAdjustmentHeightService(textData);
|
|
36
35
|
return textData;
|
|
37
36
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { TextFormat } from "../../TextFormat";
|
|
2
2
|
import type { TextData } from "../../TextData";
|
|
3
3
|
import type { IOptions } from "../../interface/IOptions";
|
|
4
|
-
import type { Document } from "domhandler";
|
|
5
4
|
/**
|
|
6
|
-
* @description
|
|
7
|
-
*
|
|
5
|
+
* @description HTMLタグを直接解析してTextDataを構築
|
|
6
|
+
* 中間ツリーなし、タグ名文字列なし、clone()なし、属性オブジェクトなし
|
|
7
|
+
* Parse HTML directly — no tree, no tag strings, no clone, no attr objects
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {string} html
|
|
10
10
|
* @param {TextFormat} text_format
|
|
11
11
|
* @param {TextData} text_data
|
|
12
12
|
* @param {IOptions} options
|
|
@@ -14,4 +14,4 @@ import type { Document } from "domhandler";
|
|
|
14
14
|
* @method
|
|
15
15
|
* @protected
|
|
16
16
|
*/
|
|
17
|
-
export declare const execute: (
|
|
17
|
+
export declare const execute: (html: string, text_format: TextFormat, text_data: TextData, options: IOptions) => void;
|
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
import { execute as textParserParseTextUseCase } from "./TextParserParseTextUseCase";
|
|
2
2
|
import { execute as textParserCreateNewLineUseCase } from "./TextParserCreateNewLineUseCase";
|
|
3
|
-
import { execute as
|
|
3
|
+
import { execute as textParserParseStyleService } from "../service/TextParserParseStyleService";
|
|
4
|
+
import { $toColorInt } from "../../TextUtil";
|
|
4
5
|
/**
|
|
5
|
-
* @description
|
|
6
|
-
*
|
|
6
|
+
* @description 数値タグID — 文字列生成を完全排除
|
|
7
|
+
* Numeric tag IDs — eliminates all tag string allocation
|
|
8
|
+
*/
|
|
9
|
+
const $TAG_NONE = 0;
|
|
10
|
+
const $TAG_B = 1;
|
|
11
|
+
const $TAG_I = 2;
|
|
12
|
+
const $TAG_U = 3;
|
|
13
|
+
const $TAG_P = 4;
|
|
14
|
+
const $TAG_BR = 5;
|
|
15
|
+
const $TAG_DIV = 6;
|
|
16
|
+
const $TAG_FONT = 7;
|
|
17
|
+
const $TAG_SPAN = 8;
|
|
18
|
+
/**
|
|
19
|
+
* @description モジュールレベルのパーサ状態
|
|
20
|
+
* Module-level parser state
|
|
21
|
+
*/
|
|
22
|
+
let _$html = "";
|
|
23
|
+
let _$pos = 0;
|
|
24
|
+
let _$len = 0;
|
|
25
|
+
/**
|
|
26
|
+
* @description HTMLタグを直接解析してTextDataを構築
|
|
27
|
+
* 中間ツリーなし、タグ名文字列なし、clone()なし、属性オブジェクトなし
|
|
28
|
+
* Parse HTML directly — no tree, no tag strings, no clone, no attr objects
|
|
7
29
|
*
|
|
8
|
-
* @param {
|
|
30
|
+
* @param {string} html
|
|
9
31
|
* @param {TextFormat} text_format
|
|
10
32
|
* @param {TextData} text_data
|
|
11
33
|
* @param {IOptions} options
|
|
@@ -13,45 +35,490 @@ import { execute as textParserSetAttributesUseCase } from "./TextParserSetAttrib
|
|
|
13
35
|
* @method
|
|
14
36
|
* @protected
|
|
15
37
|
*/
|
|
16
|
-
export const execute = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
export const execute = (html, text_format, text_data, options) => {
|
|
39
|
+
_$html = html;
|
|
40
|
+
_$pos = 0;
|
|
41
|
+
_$len = html.length;
|
|
42
|
+
$processChildren($TAG_NONE, text_format, text_data, options);
|
|
43
|
+
_$html = "";
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @description 子要素をストリーミング解析・処理(再帰)
|
|
47
|
+
* save/restoreでTextFormatをスタック管理 — clone()ゼロ
|
|
48
|
+
* Stream-parse children with stack-based format — zero clone()
|
|
49
|
+
*/
|
|
50
|
+
const $processChildren = (parent_tag_id, text_format, text_data, options) => {
|
|
51
|
+
while (_$pos < _$len) {
|
|
52
|
+
const ltIdx = _$html.indexOf("<", _$pos);
|
|
53
|
+
if (ltIdx === -1) {
|
|
54
|
+
textParserParseTextUseCase(_$html.substring(_$pos), text_format, text_data, options);
|
|
55
|
+
_$pos = _$len;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (ltIdx > _$pos) {
|
|
59
|
+
textParserParseTextUseCase(_$html.substring(_$pos, ltIdx), text_format, text_data, options);
|
|
60
|
+
}
|
|
61
|
+
_$pos = ltIdx + 1;
|
|
62
|
+
if (_$pos >= _$len) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
// closing tag: '</'
|
|
66
|
+
if (_$html.charCodeAt(_$pos) === 0x2F) {
|
|
67
|
+
_$pos++;
|
|
68
|
+
const gtIdx = _$html.indexOf(">", _$pos);
|
|
69
|
+
if (gtIdx === -1) {
|
|
70
|
+
_$pos = _$len;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (parent_tag_id !== $TAG_NONE && $identifyTag(_$pos, gtIdx) === parent_tag_id) {
|
|
74
|
+
_$pos = gtIdx + 1;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
_$pos = gtIdx + 1;
|
|
21
78
|
continue;
|
|
22
79
|
}
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
80
|
+
const tagStart = _$pos;
|
|
81
|
+
while (_$pos < _$len) {
|
|
82
|
+
const c = _$html.charCodeAt(_$pos);
|
|
83
|
+
if (c === 0x3E || c === 0x2F || c === 0x20 || c === 0x09) {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
_$pos++;
|
|
87
|
+
}
|
|
88
|
+
const tagId = $identifyTag(tagStart, _$pos);
|
|
89
|
+
switch (tagId) {
|
|
90
|
+
case $TAG_B: {
|
|
91
|
+
const saved = text_format.bold;
|
|
92
|
+
text_format.bold = true;
|
|
93
|
+
$skipToClose();
|
|
94
|
+
$processChildren(tagId, text_format, text_data, options);
|
|
95
|
+
text_format.bold = saved;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
case $TAG_I: {
|
|
99
|
+
const saved = text_format.italic;
|
|
100
|
+
text_format.italic = true;
|
|
101
|
+
$skipToClose();
|
|
102
|
+
$processChildren(tagId, text_format, text_data, options);
|
|
103
|
+
text_format.italic = saved;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
case $TAG_U: {
|
|
107
|
+
const saved = text_format.underline;
|
|
108
|
+
text_format.underline = true;
|
|
109
|
+
$skipToClose();
|
|
110
|
+
$processChildren(tagId, text_format, text_data, options);
|
|
111
|
+
text_format.underline = saved;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
case $TAG_DIV:
|
|
115
|
+
case $TAG_P:
|
|
116
|
+
case $TAG_FONT:
|
|
117
|
+
case $TAG_SPAN: {
|
|
118
|
+
const sFont = text_format.font;
|
|
119
|
+
const sSize = text_format.size;
|
|
120
|
+
const sColor = text_format.color;
|
|
121
|
+
const sBold = text_format.bold;
|
|
122
|
+
const sItalic = text_format.italic;
|
|
123
|
+
const sUnderline = text_format.underline;
|
|
124
|
+
const sAlign = text_format.align;
|
|
125
|
+
const sLeftMargin = text_format.leftMargin;
|
|
126
|
+
const sRightMargin = text_format.rightMargin;
|
|
127
|
+
const sLeading = text_format.leading;
|
|
128
|
+
const sLetterSpacing = text_format.letterSpacing;
|
|
129
|
+
$applyAttributesInline(text_format, options);
|
|
130
|
+
$finishOpenTag();
|
|
131
|
+
if ((tagId === $TAG_P || tagId === $TAG_DIV) && options.multiline) {
|
|
132
|
+
textParserCreateNewLineUseCase(text_data, text_format);
|
|
133
|
+
}
|
|
134
|
+
$processChildren(tagId, text_format, text_data, options);
|
|
135
|
+
text_format.font = sFont;
|
|
136
|
+
text_format.size = sSize;
|
|
137
|
+
text_format.color = sColor;
|
|
138
|
+
text_format.bold = sBold;
|
|
139
|
+
text_format.italic = sItalic;
|
|
140
|
+
text_format.underline = sUnderline;
|
|
141
|
+
text_format.align = sAlign;
|
|
142
|
+
text_format.leftMargin = sLeftMargin;
|
|
143
|
+
text_format.rightMargin = sRightMargin;
|
|
144
|
+
text_format.leading = sLeading;
|
|
145
|
+
text_format.letterSpacing = sLetterSpacing;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
case $TAG_BR:
|
|
149
|
+
$skipToClose();
|
|
28
150
|
if (options.multiline) {
|
|
29
|
-
textParserCreateNewLineUseCase(text_data,
|
|
151
|
+
textParserCreateNewLineUseCase(text_data, text_format);
|
|
30
152
|
}
|
|
31
|
-
execute(node, textFormat, text_data, options);
|
|
32
153
|
continue;
|
|
33
|
-
|
|
34
|
-
|
|
154
|
+
default:
|
|
155
|
+
$skipToClose();
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* @description '>' までスキップ(V8 SIMD最適化のindexOf使用)
|
|
162
|
+
* Skip to '>' using SIMD-optimized indexOf
|
|
163
|
+
*/
|
|
164
|
+
const $skipToClose = () => {
|
|
165
|
+
const idx = _$html.indexOf(">", _$pos);
|
|
166
|
+
_$pos = idx === -1 ? _$len : idx + 1;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* @description 属性パース後のタグ末尾処理
|
|
170
|
+
* Handle end of opening tag after attribute parsing
|
|
171
|
+
*/
|
|
172
|
+
const $finishOpenTag = () => {
|
|
173
|
+
if (_$pos < _$len && _$html.charCodeAt(_$pos) === 0x2F) {
|
|
174
|
+
_$pos++;
|
|
175
|
+
}
|
|
176
|
+
if (_$pos < _$len && _$html.charCodeAt(_$pos) === 0x3E) {
|
|
177
|
+
_$pos++;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* @description 属性をインラインで解析・直接適用
|
|
182
|
+
* IAttributeObject配列・オブジェクト・属性名文字列を一切生成しない
|
|
183
|
+
* Parse and apply attributes inline — zero arrays, objects, name strings
|
|
184
|
+
*/
|
|
185
|
+
const $applyAttributesInline = (text_format, options) => {
|
|
186
|
+
for (;;) {
|
|
187
|
+
while (_$pos < _$len) {
|
|
188
|
+
const c = _$html.charCodeAt(_$pos);
|
|
189
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
35
190
|
break;
|
|
36
|
-
|
|
37
|
-
|
|
191
|
+
}
|
|
192
|
+
_$pos++;
|
|
193
|
+
}
|
|
194
|
+
if (_$pos >= _$len) {
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
const ch = _$html.charCodeAt(_$pos);
|
|
198
|
+
if (ch === 0x3E || ch === 0x2F) {
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
const nameStart = _$pos;
|
|
202
|
+
while (_$pos < _$len) {
|
|
203
|
+
const c = _$html.charCodeAt(_$pos);
|
|
204
|
+
if (c === 0x3D || c === 0x3E || c === 0x2F || c === 0x20 || c === 0x09) {
|
|
38
205
|
break;
|
|
39
|
-
|
|
40
|
-
|
|
206
|
+
}
|
|
207
|
+
_$pos++;
|
|
208
|
+
}
|
|
209
|
+
if (_$pos === nameStart) {
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
const name_len = _$pos - nameStart;
|
|
213
|
+
const name_c0 = _$html.charCodeAt(nameStart);
|
|
214
|
+
while (_$pos < _$len) {
|
|
215
|
+
const c = _$html.charCodeAt(_$pos);
|
|
216
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
41
217
|
break;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
218
|
+
}
|
|
219
|
+
_$pos++;
|
|
220
|
+
}
|
|
221
|
+
if (_$pos < _$len && _$html.charCodeAt(_$pos) === 0x3D) {
|
|
222
|
+
_$pos++;
|
|
223
|
+
while (_$pos < _$len) {
|
|
224
|
+
const c = _$html.charCodeAt(_$pos);
|
|
225
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
_$pos++;
|
|
229
|
+
}
|
|
230
|
+
let value;
|
|
231
|
+
const quote = _$html.charCodeAt(_$pos);
|
|
232
|
+
if (quote === 0x22 || quote === 0x27) {
|
|
233
|
+
_$pos++;
|
|
234
|
+
const closeIdx = _$html.indexOf(quote === 0x22 ? "\"" : "'", _$pos);
|
|
235
|
+
if (closeIdx === -1) {
|
|
236
|
+
value = _$html.substring(_$pos);
|
|
237
|
+
_$pos = _$len;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
value = _$html.substring(_$pos, closeIdx);
|
|
241
|
+
_$pos = closeIdx + 1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
const valStart = _$pos;
|
|
246
|
+
while (_$pos < _$len) {
|
|
247
|
+
const c = _$html.charCodeAt(_$pos);
|
|
248
|
+
if (c === 0x3E || c === 0x2F || c === 0x20 || c === 0x09) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
_$pos++;
|
|
252
|
+
}
|
|
253
|
+
value = _$html.substring(valStart, _$pos);
|
|
254
|
+
}
|
|
255
|
+
$applyAttribute(name_len, name_c0, value, text_format, options);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
$applyBooleanAttribute(name_len, name_c0, text_format);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* @description 属性名をcharCodeで識別して値を直接適用
|
|
264
|
+
* Identify attribute name by charCode and apply value directly
|
|
265
|
+
*
|
|
266
|
+
* name lengths: face(4), size(4), bold(4), style(5), align(5), color(5),
|
|
267
|
+
* italic(6), leading(7), underline(9), leftMargin(10),
|
|
268
|
+
* rightMargin(11), letterSpacing(14)
|
|
269
|
+
*/
|
|
270
|
+
const $applyAttribute = (name_len, name_c0, value, text_format, options) => {
|
|
271
|
+
switch (name_len) {
|
|
272
|
+
case 4:
|
|
273
|
+
// face(0x66/0x46) | size(0x73/0x53) | bold(0x62/0x42)
|
|
274
|
+
if (name_c0 === 0x66 || name_c0 === 0x46) {
|
|
275
|
+
text_format.font = value;
|
|
276
|
+
}
|
|
277
|
+
else if (name_c0 === 0x73 || name_c0 === 0x53) {
|
|
278
|
+
text_format.size = +value;
|
|
279
|
+
if (options.subFontSize) {
|
|
280
|
+
text_format.size -= options.subFontSize;
|
|
281
|
+
if (1 > text_format.size) {
|
|
282
|
+
text_format.size = 1;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
else if (name_c0 === 0x62 || name_c0 === 0x42) {
|
|
287
|
+
text_format.bold = true;
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
case 5:
|
|
291
|
+
// color(0x63/0x43) | style(0x73/0x53) | align(0x61/0x41)
|
|
292
|
+
if (name_c0 === 0x63 || name_c0 === 0x43) {
|
|
293
|
+
text_format.color = $toColorInt(value);
|
|
294
|
+
}
|
|
295
|
+
else if (name_c0 === 0x73 || name_c0 === 0x53) {
|
|
296
|
+
$applyStyleAttributes(textParserParseStyleService(value), text_format, options);
|
|
297
|
+
}
|
|
298
|
+
else if (name_c0 === 0x61 || name_c0 === 0x41) {
|
|
299
|
+
text_format.align = value;
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
case 6:
|
|
303
|
+
// italic(0x69/0x49)
|
|
304
|
+
if (name_c0 === 0x69 || name_c0 === 0x49) {
|
|
305
|
+
text_format.italic = true;
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
308
|
+
case 7:
|
|
309
|
+
// leading(0x6C/0x4C)
|
|
310
|
+
if (name_c0 === 0x6C || name_c0 === 0x4C) {
|
|
311
|
+
text_format.leading = parseInt(value);
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
case 9:
|
|
315
|
+
// underline(0x75/0x55)
|
|
316
|
+
if (name_c0 === 0x75 || name_c0 === 0x55) {
|
|
317
|
+
text_format.underline = true;
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
case 10:
|
|
321
|
+
// leftMargin(0x6C/0x4C)
|
|
322
|
+
if (name_c0 === 0x6C || name_c0 === 0x4C) {
|
|
323
|
+
text_format.leftMargin = parseInt(value);
|
|
324
|
+
}
|
|
325
|
+
break;
|
|
326
|
+
case 11:
|
|
327
|
+
// rightMargin(0x72/0x52)
|
|
328
|
+
if (name_c0 === 0x72 || name_c0 === 0x52) {
|
|
329
|
+
text_format.rightMargin = parseInt(value);
|
|
330
|
+
}
|
|
331
|
+
break;
|
|
332
|
+
case 14:
|
|
333
|
+
// letterSpacing(0x6C/0x4C)
|
|
334
|
+
if (name_c0 === 0x6C || name_c0 === 0x4C) {
|
|
335
|
+
text_format.letterSpacing = parseInt(value);
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
default:
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* @description 値なし属性をcharCodeで識別して直接適用
|
|
344
|
+
* Apply boolean (no-value) attributes by charCode
|
|
345
|
+
*/
|
|
346
|
+
const $applyBooleanAttribute = (name_len, name_c0, text_format) => {
|
|
347
|
+
if (name_len === 4 && (name_c0 === 0x62 || name_c0 === 0x42)) {
|
|
348
|
+
text_format.bold = true;
|
|
349
|
+
}
|
|
350
|
+
else if (name_len === 6 && (name_c0 === 0x69 || name_c0 === 0x49)) {
|
|
351
|
+
text_format.italic = true;
|
|
352
|
+
}
|
|
353
|
+
else if (name_len === 9 && (name_c0 === 0x75 || name_c0 === 0x55)) {
|
|
354
|
+
text_format.underline = true;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* @description style属性の解析結果をtext_formatに直接適用
|
|
359
|
+
* Apply parsed style attributes directly to text_format
|
|
360
|
+
*/
|
|
361
|
+
const $applyStyleAttributes = (attributes, text_format, options) => {
|
|
362
|
+
for (let idx = 0; idx < attributes.length; ++idx) {
|
|
363
|
+
const attr = attributes[idx];
|
|
364
|
+
switch (attr.name) {
|
|
365
|
+
case "face":
|
|
366
|
+
text_format.font = attr.value;
|
|
45
367
|
break;
|
|
46
|
-
case "
|
|
47
|
-
|
|
48
|
-
|
|
368
|
+
case "size":
|
|
369
|
+
text_format.size = +attr.value;
|
|
370
|
+
if (options.subFontSize) {
|
|
371
|
+
text_format.size -= options.subFontSize;
|
|
372
|
+
if (1 > text_format.size) {
|
|
373
|
+
text_format.size = 1;
|
|
374
|
+
}
|
|
49
375
|
}
|
|
50
|
-
|
|
376
|
+
break;
|
|
377
|
+
case "color":
|
|
378
|
+
text_format.color = $toColorInt(attr.value);
|
|
379
|
+
break;
|
|
380
|
+
case "align":
|
|
381
|
+
text_format.align = attr.value;
|
|
382
|
+
break;
|
|
383
|
+
case "letterSpacing":
|
|
384
|
+
text_format.letterSpacing = parseInt(attr.value);
|
|
385
|
+
break;
|
|
386
|
+
case "leading":
|
|
387
|
+
text_format.leading = parseInt(attr.value);
|
|
388
|
+
break;
|
|
389
|
+
case "leftMargin":
|
|
390
|
+
text_format.leftMargin = parseInt(attr.value);
|
|
391
|
+
break;
|
|
392
|
+
case "rightMargin":
|
|
393
|
+
text_format.rightMargin = parseInt(attr.value);
|
|
394
|
+
break;
|
|
395
|
+
case "underline":
|
|
396
|
+
text_format.underline = true;
|
|
397
|
+
break;
|
|
398
|
+
case "bold":
|
|
399
|
+
text_format.bold = true;
|
|
400
|
+
break;
|
|
401
|
+
case "italic":
|
|
402
|
+
text_format.italic = true;
|
|
51
403
|
break;
|
|
52
404
|
default:
|
|
53
405
|
break;
|
|
54
406
|
}
|
|
55
|
-
execute(node, textFormat, text_data, options);
|
|
56
407
|
}
|
|
57
408
|
};
|
|
409
|
+
/**
|
|
410
|
+
* @description 文字列未生成でタグを数値IDに変換
|
|
411
|
+
* Zero-allocation tag identification via character comparison
|
|
412
|
+
*/
|
|
413
|
+
const $identifyTag = (start, end) => {
|
|
414
|
+
while (start < end) {
|
|
415
|
+
const c = _$html.charCodeAt(start);
|
|
416
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
start++;
|
|
420
|
+
}
|
|
421
|
+
while (end > start) {
|
|
422
|
+
const c = _$html.charCodeAt(end - 1);
|
|
423
|
+
if (c !== 0x20 && c !== 0x09) {
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
end--;
|
|
427
|
+
}
|
|
428
|
+
const length = end - start;
|
|
429
|
+
if (length === 1) {
|
|
430
|
+
let c = _$html.charCodeAt(start);
|
|
431
|
+
if (c >= 0x61) {
|
|
432
|
+
c -= 0x20;
|
|
433
|
+
}
|
|
434
|
+
if (c === 0x42) {
|
|
435
|
+
return $TAG_B;
|
|
436
|
+
} // B
|
|
437
|
+
if (c === 0x49) {
|
|
438
|
+
return $TAG_I;
|
|
439
|
+
} // I
|
|
440
|
+
if (c === 0x55) {
|
|
441
|
+
return $TAG_U;
|
|
442
|
+
} // U
|
|
443
|
+
if (c === 0x50) {
|
|
444
|
+
return $TAG_P;
|
|
445
|
+
} // P
|
|
446
|
+
return $TAG_NONE;
|
|
447
|
+
}
|
|
448
|
+
if (length === 2) {
|
|
449
|
+
let c0 = _$html.charCodeAt(start);
|
|
450
|
+
let c1 = _$html.charCodeAt(start + 1);
|
|
451
|
+
if (c0 >= 0x61) {
|
|
452
|
+
c0 -= 0x20;
|
|
453
|
+
}
|
|
454
|
+
if (c1 >= 0x61) {
|
|
455
|
+
c1 -= 0x20;
|
|
456
|
+
}
|
|
457
|
+
if (c0 === 0x42 && c1 === 0x52) {
|
|
458
|
+
return $TAG_BR;
|
|
459
|
+
} // BR
|
|
460
|
+
return $TAG_NONE;
|
|
461
|
+
}
|
|
462
|
+
if (length === 3) {
|
|
463
|
+
let c0 = _$html.charCodeAt(start);
|
|
464
|
+
if (c0 >= 0x61) {
|
|
465
|
+
c0 -= 0x20;
|
|
466
|
+
}
|
|
467
|
+
if (c0 === 0x44) { // D
|
|
468
|
+
let c1 = _$html.charCodeAt(start + 1);
|
|
469
|
+
let c2 = _$html.charCodeAt(start + 2);
|
|
470
|
+
if (c1 >= 0x61) {
|
|
471
|
+
c1 -= 0x20;
|
|
472
|
+
}
|
|
473
|
+
if (c2 >= 0x61) {
|
|
474
|
+
c2 -= 0x20;
|
|
475
|
+
}
|
|
476
|
+
if (c1 === 0x49 && c2 === 0x56) {
|
|
477
|
+
return $TAG_DIV;
|
|
478
|
+
} // DIV
|
|
479
|
+
}
|
|
480
|
+
return $TAG_NONE;
|
|
481
|
+
}
|
|
482
|
+
if (length === 4) {
|
|
483
|
+
let c0 = _$html.charCodeAt(start);
|
|
484
|
+
if (c0 >= 0x61) {
|
|
485
|
+
c0 -= 0x20;
|
|
486
|
+
}
|
|
487
|
+
if (c0 === 0x46) { // F
|
|
488
|
+
let c1 = _$html.charCodeAt(start + 1);
|
|
489
|
+
let c2 = _$html.charCodeAt(start + 2);
|
|
490
|
+
let c3 = _$html.charCodeAt(start + 3);
|
|
491
|
+
if (c1 >= 0x61) {
|
|
492
|
+
c1 -= 0x20;
|
|
493
|
+
}
|
|
494
|
+
if (c2 >= 0x61) {
|
|
495
|
+
c2 -= 0x20;
|
|
496
|
+
}
|
|
497
|
+
if (c3 >= 0x61) {
|
|
498
|
+
c3 -= 0x20;
|
|
499
|
+
}
|
|
500
|
+
if (c1 === 0x4F && c2 === 0x4E && c3 === 0x54) {
|
|
501
|
+
return $TAG_FONT;
|
|
502
|
+
} // FONT
|
|
503
|
+
}
|
|
504
|
+
if (c0 === 0x53) { // S
|
|
505
|
+
let c1 = _$html.charCodeAt(start + 1);
|
|
506
|
+
let c2 = _$html.charCodeAt(start + 2);
|
|
507
|
+
let c3 = _$html.charCodeAt(start + 3);
|
|
508
|
+
if (c1 >= 0x61) {
|
|
509
|
+
c1 -= 0x20;
|
|
510
|
+
}
|
|
511
|
+
if (c2 >= 0x61) {
|
|
512
|
+
c2 -= 0x20;
|
|
513
|
+
}
|
|
514
|
+
if (c3 >= 0x61) {
|
|
515
|
+
c3 -= 0x20;
|
|
516
|
+
}
|
|
517
|
+
if (c1 === 0x50 && c2 === 0x41 && c3 === 0x4E) {
|
|
518
|
+
return $TAG_SPAN;
|
|
519
|
+
} // SPAN
|
|
520
|
+
}
|
|
521
|
+
return $TAG_NONE;
|
|
522
|
+
}
|
|
523
|
+
return $TAG_NONE;
|
|
524
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IAttributeObject } from "./IAttributeObject";
|
|
2
|
+
/**
|
|
3
|
+
* @description テキストノード
|
|
4
|
+
* Text node
|
|
5
|
+
*/
|
|
6
|
+
export interface IHtmlTextNode {
|
|
7
|
+
readonly type: "text";
|
|
8
|
+
readonly value: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @description 要素ノード
|
|
12
|
+
* Element node
|
|
13
|
+
*/
|
|
14
|
+
export interface IHtmlElementNode {
|
|
15
|
+
readonly type: "element";
|
|
16
|
+
readonly tagName: string;
|
|
17
|
+
readonly attributes: IAttributeObject[];
|
|
18
|
+
readonly children: IHtmlNode[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @description HTMLノード共用型
|
|
22
|
+
* HTML node union type
|
|
23
|
+
*/
|
|
24
|
+
export type IHtmlNode = IHtmlTextNode | IHtmlElementNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|