@next2d/text 2.13.0 → 3.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/README.md CHANGED
@@ -1,11 +1,382 @@
1
- @next2d/text
2
- =============
1
+ # @next2d/text
3
2
 
4
- ## Installation
3
+ ## Overview / 概要
5
4
 
6
- ```
5
+ The `@next2d/text` package provides comprehensive TextField rendering capabilities with rich HTML text support, interactive input handling, and advanced text formatting. This package is the core text engine for the Next2D player framework.
6
+
7
+ `@next2d/text` パッケージは、リッチHTMLテキストサポート、インタラクティブな入力処理、高度なテキストフォーマット機能を備えた包括的なTextFieldレンダリング機能を提供します。このパッケージは、Next2Dプレイヤーフレームワークのコアテキストエンジンです。
8
+
9
+ ### Key Features / 主な機能
10
+
11
+ - **TextField Rendering**: Display text with various formatting options
12
+ - **HTML Text Support**: Parse and render HTML-formatted text with tags like `<b>`, `<i>`, `<font>`, etc.
13
+ - **Text Input Handling**: Interactive text input with composition events (IME support)
14
+ - **Text Formatting**: Rich text formatting with TextFormat class
15
+ - **Auto-sizing**: Automatic text field resizing based on content
16
+ - **Scrolling**: Horizontal and vertical text scrolling
17
+
18
+ ---
19
+
20
+ - **TextFieldレンダリング**: 様々なフォーマットオプションでテキストを表示
21
+ - **HTMLテキストサポート**: `<b>`, `<i>`, `<font>` などのタグを含むHTML形式のテキストを解析・レンダリング
22
+ - **テキスト入力処理**: コンポジションイベント(IMEサポート)を備えたインタラクティブなテキスト入力
23
+ - **テキストフォーマット**: TextFormatクラスによるリッチテキストフォーマット
24
+ - **自動サイズ調整**: コンテンツに基づいた自動テキストフィールドリサイズ
25
+ - **スクロール**: 水平・垂直テキストスクロール
26
+
27
+ ## Installation / インストール
28
+
29
+ ```bash
7
30
  npm install @next2d/text
8
31
  ```
9
32
 
10
- ## License
33
+ ## Directory Structure / ディレクトリ構造
34
+
35
+ ```
36
+ src/
37
+ ├── TextField.ts # Main TextField class / メインTextFieldクラス
38
+ │ ├── TextField/service/ # TextField services / TextFieldサービス
39
+ │ │ ├── TextFieldApplyChangesService.ts
40
+ │ │ ├── TextFieldBlinkingClearTimeoutService.ts
41
+ │ │ ├── TextFieldCompositionStartService.ts
42
+ │ │ └── TextFieldPasteService.ts
43
+ │ └── TextField/usecase/ # TextField use cases / TextFieldユースケース
44
+ │ ├── TextFieldArrowDownUseCase.ts
45
+ │ ├── TextFieldArrowLeftUseCase.ts
46
+ │ ├── TextFieldArrowRightUseCase.ts
47
+ │ ├── TextFieldArrowUpUseCase.ts
48
+ │ ├── TextFieldBlinkingUseCase.ts
49
+ │ ├── TextFieldBuildFromCharacterUseCase.ts
50
+ │ ├── TextFieldCompositionEndUseCase.ts
51
+ │ ├── TextFieldCompositionUpdateUseCase.ts
52
+ │ ├── TextFieldCopyUseCase.ts
53
+ │ ├── TextFieldDeleteTextUseCase.ts
54
+ │ ├── TextFieldGetLineTextUseCase.ts
55
+ │ ├── TextFieldGetTextDataUseCase.ts
56
+ │ ├── TextFieldHtmlTextToRawTextUseCase.ts
57
+ │ ├── TextFieldInsertTextUseCase.ts
58
+ │ ├── TextFieldKeyDownEventUseCase.ts
59
+ │ ├── TextFieldReloadUseCase.ts
60
+ │ ├── TextFieldReplaceTextUseCase.ts
61
+ │ ├── TextFieldResetUseCase.ts
62
+ │ ├── TextFieldResizeAutoFontSizeUseCase.ts
63
+ │ ├── TextFieldResizeUseCase.ts
64
+ │ ├── TextFieldSelectAllUseCase.ts
65
+ │ ├── TextFieldSelectedFocusMoveUseCase.ts
66
+ │ ├── TextFieldSetFocusIndexUseCase.ts
67
+ │ ├── TextFieldSetFocusUseCase.ts
68
+ │ ├── TextFieldSetScrollXUseCase.ts
69
+ │ ├── TextFieldSetScrollYUseCase.ts
70
+ │ └── TextFieldUpdateStopIndexUseCase.ts
71
+
72
+ ├── TextFormat.ts # Text formatting class / テキストフォーマットクラス
73
+ │ └── TextFormat/service/ # TextFormat services / TextFormatサービス
74
+ │ ├── TextFormatGenerateFontStyleService.ts
75
+ │ ├── TextFormatGetWidthMarginService.ts
76
+ │ ├── TextFormatHtmlTextGenerateStyleService.ts
77
+ │ ├── TextFormatIsSameService.ts
78
+ │ └── TextFormatSetDefaultService.ts
79
+
80
+ ├── TextData.ts # Text data container / テキストデータコンテナ
81
+
82
+ ├── TextArea/ # Input handling / 入力処理
83
+ │ ├── TextArea/service/ # TextArea services / TextAreaサービス
84
+ │ │ └── TextAreaMovePositionService.ts
85
+ │ └── TextArea/usecase/ # TextArea use cases / TextAreaユースケース
86
+ │ ├── TextAreaCompositionEndUseCase.ts
87
+ │ ├── TextAreaCompositionStartUseCase.ts
88
+ │ ├── TextAreaCompositionUpdateUseCase.ts
89
+ │ ├── TextAreaInputUseCase.ts
90
+ │ └── TextAreaRegisterEventUseCase.ts
91
+
92
+ ├── TextParser/ # HTML parsing / HTML解析
93
+ │ ├── TextParser/service/ # TextParser services / TextParserサービス
94
+ │ │ ├── TextParserAdjustmentHeightService.ts
95
+ │ │ └── TextParserParseStyleService.ts
96
+ │ └── TextParser/usecase/ # TextParser use cases / TextParserユースケース
97
+ │ ├── TextParserCreateNewLineUseCase.ts
98
+ │ ├── TextParserParseHtmlTextUseCase.ts
99
+ │ ├── TextParserParseTagUseCase.ts
100
+ │ ├── TextParserParseTextUseCase.ts
101
+ │ └── TextParserSetAttributesUseCase.ts
102
+
103
+ ├── TextUtil.ts # Utility functions / ユーティリティ関数
104
+
105
+ └── interface/ # TypeScript interfaces / TypeScriptインターフェース
106
+ ├── IAttributeObject.ts
107
+ ├── IBlendMode.ts
108
+ ├── IBounds.ts
109
+ ├── ICharacter.ts
110
+ ├── IDictionaryTag.ts
111
+ ├── IElementPosition.ts
112
+ ├── IFilterArray.ts
113
+ ├── IGrid.ts
114
+ ├── ILoopConfig.ts
115
+ ├── ILoopType.ts
116
+ ├── IMovieClipActionObject.ts
117
+ ├── IMovieClipCharacter.ts
118
+ ├── IMovieClipLabelObject.ts
119
+ ├── IMovieClipSoundObject.ts
120
+ ├── IOptions.ts
121
+ ├── IPlaceObject.ts
122
+ ├── IRGBA.ts
123
+ ├── IShapeCharacter.ts
124
+ ├── ISoundTag.ts
125
+ ├── ISurfaceFilter.ts
126
+ ├── ITextFieldAutoSize.ts
127
+ ├── ITextFieldCharacter.ts
128
+ ├── ITextFieldType.ts
129
+ ├── ITextFormatAlign.ts
130
+ ├── ITextFormatObject.ts
131
+ ├── ITextObject.ts
132
+ ├── ITextObjectMode.ts
133
+ └── IVideoCharacter.ts
134
+ ```
135
+
136
+ ## Text Processing Flow / テキスト処理フロー
137
+
138
+ ### HTML Text Rendering Flow / HTMLテキストレンダリングフロー
139
+
140
+ ```mermaid
141
+ flowchart TD
142
+ A[HTML Text Input<br/>HTMLテキスト入力] --> B[TextParser]
143
+ B --> C{Parse HTML<br/>HTML解析}
144
+ C --> D[TextParserParseHtmlTextUseCase]
145
+ D --> E[htmlparser2<br/>HTML Document Parse]
146
+ E --> F[TextParserParseTagUseCase<br/>タグ解析]
147
+ F --> G[TextParserParseTextUseCase<br/>テキスト解析]
148
+ G --> H[TextParserSetAttributesUseCase<br/>属性設定]
149
+ F --> I[TextFormatHtmlTextGenerateStyleService<br/>スタイル生成]
150
+ I --> H
151
+ H --> J[TextData]
152
+ J --> K[TextParserAdjustmentHeightService<br/>高さ調整]
153
+ K --> L[Render to Canvas<br/>Canvasへレンダリング]
154
+
155
+ style A fill:#e1f5ff
156
+ style J fill:#fff4e1
157
+ style L fill:#e8f5e9
158
+ ```
159
+
160
+ ### Text Input Handling Flow / テキスト入力処理フロー
161
+
162
+ ```mermaid
163
+ flowchart TD
164
+ A[User Input<br/>ユーザー入力] --> B{Input Type<br/>入力タイプ}
165
+
166
+ B -->|Keyboard<br/>キーボード| C[TextFieldKeyDownEventUseCase]
167
+ B -->|IME Start<br/>IME開始| D[TextAreaCompositionStartUseCase]
168
+ B -->|IME Update<br/>IME更新| E[TextAreaCompositionUpdateUseCase]
169
+ B -->|IME End<br/>IME確定| F[TextAreaCompositionEndUseCase]
170
+ B -->|Paste<br/>貼り付け| G[TextFieldPasteService]
171
+
172
+ C --> H{Action<br/>アクション}
173
+ H -->|Insert<br/>挿入| I[TextFieldInsertTextUseCase]
174
+ H -->|Delete<br/>削除| J[TextFieldDeleteTextUseCase]
175
+ H -->|Replace<br/>置換| K[TextFieldReplaceTextUseCase]
176
+ H -->|Arrow Keys<br/>矢印キー| L[Arrow UseCase<br/>矢印ユースケース]
177
+ H -->|Copy<br/>コピー| M[TextFieldCopyUseCase]
178
+ H -->|Select All<br/>全選択| N[TextFieldSelectAllUseCase]
179
+
180
+ D --> O[TextFieldCompositionStartService]
181
+ E --> P[TextFieldCompositionUpdateUseCase]
182
+ F --> Q[TextFieldCompositionEndUseCase]
183
+ G --> I
184
+
185
+ I --> R[TextFieldApplyChangesService]
186
+ J --> R
187
+ K --> R
188
+ L --> S[TextFieldSelectedFocusMoveUseCase]
189
+
190
+ O --> T[Update TextArea Element<br/>TextArea要素更新]
191
+ P --> T
192
+ Q --> R
193
+
194
+ R --> U[TextFieldReloadUseCase<br/>再読み込み]
195
+ S --> V[Update Focus Position<br/>フォーカス位置更新]
196
+
197
+ U --> W[Re-render TextField<br/>TextField再描画]
198
+ V --> W
199
+
200
+ style A fill:#e1f5ff
201
+ style T fill:#fff4e1
202
+ style W fill:#e8f5e9
203
+ ```
204
+
205
+ ### Component Relationships / コンポーネント関係図
206
+
207
+ ```mermaid
208
+ flowchart LR
209
+ A[TextField] --> B[TextFormat]
210
+ A --> C[TextData]
211
+ A --> D[TextParser]
212
+ A --> E[TextArea Handler]
213
+
214
+ B --> F[TextFormatService<br/>フォーマットサービス]
215
+
216
+ D --> G[TextParserParseHtmlTextUseCase]
217
+ G --> H[htmlparser2]
218
+ G --> C
219
+
220
+ E --> I[TextAreaInputUseCase<br/>入力ユースケース]
221
+ E --> J[TextAreaCompositionUseCase<br/>コンポジションユースケース]
222
+
223
+ I --> A
224
+ J --> A
225
+
226
+ C --> K[Render Engine<br/>レンダリングエンジン]
227
+
228
+ style A fill:#e3f2fd
229
+ style C fill:#fff3e0
230
+ style K fill:#e8f5e9
231
+ ```
232
+
233
+ ## Core Components / コアコンポーネント
234
+
235
+ ### TextField
236
+
237
+ The main class for text display and input handling. TextField manages text rendering, user interactions, scrolling, and selection.
238
+
239
+ テキスト表示と入力処理のメインクラス。TextFieldはテキストレンダリング、ユーザーインタラクション、スクロール、選択を管理します。
240
+
241
+ **Key Responsibilities / 主な責務:**
242
+ - Text rendering and layout / テキストレンダリングとレイアウト
243
+ - User input event handling / ユーザー入力イベント処理
244
+ - Text selection and cursor management / テキスト選択とカーソル管理
245
+ - Scrolling support / スクロールサポート
246
+ - Auto-sizing / 自動サイズ調整
247
+
248
+ ### TextFormat
249
+
250
+ Represents character formatting information including font, size, color, alignment, and other text properties.
251
+
252
+ フォント、サイズ、色、配置、その他のテキストプロパティを含む文字フォーマット情報を表します。
253
+
254
+ **Properties / プロパティ:**
255
+ - `align`: Text alignment / テキスト配置
256
+ - `bold`: Bold text / 太字
257
+ - `color`: Text color / テキスト色
258
+ - `font`: Font family / フォントファミリー
259
+ - `size`: Font size / フォントサイズ
260
+ - `italic`: Italic text / 斜体
261
+ - `underline`: Underlined text / 下線
262
+ - `url`: Hyperlink URL / ハイパーリンクURL
263
+
264
+ ### TextData
265
+
266
+ Container for parsed text data with layout information. Stores text objects, dimensions, and line metrics.
267
+
268
+ レイアウト情報を含む解析済みテキストデータのコンテナ。テキストオブジェクト、寸法、行メトリクスを格納します。
269
+
270
+ **Data Structure / データ構造:**
271
+ - `textTable`: Text objects per line / 行ごとのテキストオブジェクト
272
+ - `widthTable`: Width per line / 行ごとの幅
273
+ - `heightTable`: Height per line / 行ごとの高さ
274
+ - `ascentTable`: Ascent per line / 行ごとのアセント
275
+
276
+ ### TextParser
277
+
278
+ Parses HTML text and converts it into TextData objects ready for rendering. Supports various HTML tags and CSS-like styling.
279
+
280
+ HTMLテキストを解析し、レンダリング準備が整ったTextDataオブジェクトに変換します。様々なHTMLタグとCSSライクなスタイリングをサポートします。
281
+
282
+ **Supported HTML Tags / サポートされるHTMLタグ:**
283
+ - `<b>`: Bold / 太字
284
+ - `<i>`: Italic / 斜体
285
+ - `<u>`: Underline / 下線
286
+ - `<font>`: Font properties (color, size, face) / フォントプロパティ
287
+ - `<p>`: Paragraph / 段落
288
+ - `<br>`: Line break / 改行
289
+ - `<a>`: Hyperlink / ハイパーリンク
290
+ - `<span>`: Inline styling / インラインスタイル
291
+
292
+ ### TextArea Handler
293
+
294
+ Manages text input through a hidden HTML textarea element, handling keyboard input, IME composition, and clipboard operations.
295
+
296
+ 非表示のHTMLテキストエリア要素を介してテキスト入力を管理し、キーボード入力、IMEコンポジション、クリップボード操作を処理します。
297
+
298
+ **Input Event Handling / 入力イベント処理:**
299
+ 1. **Composition Start**: IME input begins / IME入力開始
300
+ 2. **Composition Update**: IME input updates / IME入力更新
301
+ 3. **Composition End**: IME input confirmed / IME入力確定
302
+ 4. **Input**: Direct text input / 直接テキスト入力
303
+ 5. **Paste**: Clipboard paste / クリップボード貼り付け
304
+ 6. **Copy**: Copy selected text / 選択テキストのコピー
305
+
306
+ ### TextUtil
307
+
308
+ Utility functions for text processing, color conversion, and element positioning.
309
+
310
+ テキスト処理、色変換、要素位置決めのためのユーティリティ関数。
311
+
312
+ ## Usage Example / 使用例
313
+
314
+ ```typescript
315
+ import { TextField } from "@next2d/text";
316
+ import { TextFormat } from "@next2d/text";
317
+
318
+ // Create a text field
319
+ // テキストフィールドを作成
320
+ const textField = new TextField();
321
+ textField.width = 300;
322
+ textField.height = 200;
323
+
324
+ // Set text format
325
+ // テキストフォーマットを設定
326
+ const format = new TextFormat();
327
+ format.font = "Arial";
328
+ format.size = 24;
329
+ format.color = 0x000000;
330
+ format.bold = true;
331
+
332
+ textField.defaultTextFormat = format;
333
+
334
+ // Set HTML text
335
+ // HTMLテキストを設定
336
+ textField.htmlText = "<p>Hello <b>World</b>!</p><p>Welcome to <font color='#FF0000'>Next2D</font></p>";
337
+
338
+ // Enable input
339
+ // 入力を有効化
340
+ textField.type = "input";
341
+ textField.selectable = true;
342
+
343
+ // Handle text changes
344
+ // テキスト変更を処理
345
+ textField.addEventListener("change", (event) => {
346
+ console.log("Text changed:", textField.text);
347
+ });
348
+ ```
349
+
350
+ ## Testing / テスト
351
+
352
+ All major components include comprehensive unit tests with `.test.ts` files.
353
+
354
+ すべての主要コンポーネントには、`.test.ts` ファイルによる包括的なユニットテストが含まれています。
355
+
356
+ ```bash
357
+ npm test
358
+ ```
359
+
360
+ ## Architecture Notes / アーキテクチャノート
361
+
362
+ ### Service vs UseCase / サービス vs ユースケース
363
+
364
+ - **Service**: Low-level, reusable business logic / 低レベルで再利用可能なビジネスロジック
365
+ - **UseCase**: High-level application logic orchestrating multiple services / 複数のサービスを統合する高レベルのアプリケーションロジック
366
+
367
+ ### Clean Architecture / クリーンアーキテクチャ
368
+
369
+ The package follows clean architecture principles with clear separation between:
370
+
371
+ このパッケージは、以下の間で明確に分離されたクリーンアーキテクチャの原則に従っています:
372
+
373
+ - **Domain Layer**: TextField, TextFormat, TextData classes / ドメイン層
374
+ - **Use Case Layer**: Business logic orchestration / ユースケース層
375
+ - **Service Layer**: Reusable utilities and helpers / サービス層
376
+ - **Interface Layer**: TypeScript type definitions / インターフェース層
377
+
378
+ ## License / ライセンス
379
+
11
380
  This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details.
381
+
382
+ このプロジェクトは [MITライセンス](https://opensource.org/licenses/MIT) の下でライセンスされています。詳細については [LICENSE](LICENSE) ファイルをご覧ください。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/text",
3
- "version": "2.13.0",
3
+ "version": "3.0.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": "2.13.0",
28
- "@next2d/geom": "2.13.0",
29
- "@next2d/events": "2.13.0",
30
- "@next2d/ui": "2.13.0",
31
- "@next2d/cache": "2.13.0"
27
+ "@next2d/display": "3.0.0",
28
+ "@next2d/geom": "3.0.0",
29
+ "@next2d/events": "3.0.0",
30
+ "@next2d/ui": "3.0.0",
31
+ "@next2d/cache": "3.0.0"
32
32
  }
33
33
  }
@@ -1 +0,0 @@
1
- export type ITextFieldType = "input" | "static";
@@ -1 +0,0 @@
1
- export {};