@next2d/events 2.13.1 → 3.0.1
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 +301 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,307 @@
|
|
|
1
|
-
@next2d/events
|
|
2
|
-
=============
|
|
1
|
+
# @next2d/events
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
**重要**: `@next2d/events` は他の packages の import を禁止しています。このパッケージは基盤モジュールであり、循環依存を避けるために独立を維持する必要があります。
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
**Important**: `@next2d/events` prohibits importing other packages. This package is a foundational module that must remain independent to avoid circular dependencies.
|
|
6
|
+
|
|
7
|
+
## 概要 / Overview
|
|
8
|
+
|
|
9
|
+
`@next2d/events` パッケージは、EventDispatcher パターンに基づく包括的なイベント処理システムを提供します。このパッケージは、イベントのバブリング、キャプチャリング、およびインタラクティブアプリケーションで一般的に使用される様々なイベントタイプをサポートする堅牢なイベントフロー機構を実装しています。
|
|
10
|
+
|
|
11
|
+
The `@next2d/events` package provides a comprehensive event handling system based on the EventDispatcher pattern. This package implements a robust event flow mechanism with support for event bubbling, capturing, and various event types commonly used in interactive applications.
|
|
12
|
+
|
|
13
|
+
## インストール / Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
7
16
|
npm install @next2d/events
|
|
8
17
|
```
|
|
9
18
|
|
|
10
|
-
##
|
|
19
|
+
## 特徴 / Features
|
|
20
|
+
|
|
21
|
+
- **EventDispatcher パターン**: イベント駆動型アーキテクチャのためのオブザーバーパターンの完全な実装
|
|
22
|
+
- Complete implementation of the observer pattern for event-driven architecture
|
|
23
|
+
- **イベントフロー制御**: イベント伝播制御を備えたキャプチャリングフェーズとバブリングフェーズのサポート
|
|
24
|
+
- Support for capturing and bubbling phases with event propagation control
|
|
25
|
+
- **複数のイベントタイプ**: 一般的なユースケース(ポインター、キーボード、フォーカス、ビデオなど)のための事前定義されたイベントクラス
|
|
26
|
+
- Pre-defined event classes for common use cases (pointer, keyboard, focus, video, etc.)
|
|
27
|
+
- **型安全性**: 包括的な型定義による完全な TypeScript サポート
|
|
28
|
+
- Full TypeScript support with comprehensive type definitions
|
|
29
|
+
- **サービスベースアーキテクチャ**: イベントディスパッチャー操作のためのモジュラーサービス層
|
|
30
|
+
- Modular service layer for event dispatcher operations
|
|
31
|
+
|
|
32
|
+
## ディレクトリ構造 / Directory Structure
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
@next2d/events/
|
|
36
|
+
├── src/
|
|
37
|
+
│ ├── Event.ts # 基本イベントクラス / Base event class
|
|
38
|
+
│ ├── EventDispatcher.ts # イベントディスパッチャーの実装 / Event dispatcher implementation
|
|
39
|
+
│ ├── EventPhase.ts # イベントフェーズ定数 / Event phase constants
|
|
40
|
+
│ ├── EventUtil.ts # イベントユーティリティ関数 / Event utility functions
|
|
41
|
+
│ │
|
|
42
|
+
│ ├── EventDispatcher/
|
|
43
|
+
│ │ └── service/ # イベントディスパッチャーサービス層 / Event dispatcher service layer
|
|
44
|
+
│ │ ├── EventDispatcherAddEventListenerService.ts
|
|
45
|
+
│ │ ├── EventDispatcherDispatchEventService.ts
|
|
46
|
+
│ │ ├── EventDispatcherHasEventListenerService.ts
|
|
47
|
+
│ │ ├── EventDispatcherRemoveEventListenerService.ts
|
|
48
|
+
│ │ ├── EventDispatcherRemoveAllEventListenerService.ts
|
|
49
|
+
│ │ └── EventDispatcherWillTriggerService.ts
|
|
50
|
+
│ │
|
|
51
|
+
│ ├── interface/ # TypeScript インターフェース / TypeScript interfaces
|
|
52
|
+
│ │ ├── IEvent.ts
|
|
53
|
+
│ │ ├── IEventDispatcher.ts
|
|
54
|
+
│ │ ├── IEventListener.ts
|
|
55
|
+
│ │ └── IURLRequestHeader.ts
|
|
56
|
+
│ │
|
|
57
|
+
│ └── [イベントタイプ / Event Types]
|
|
58
|
+
│ ├── PointerEvent.ts # マウスとタッチイベント / Mouse and touch events
|
|
59
|
+
│ ├── KeyboardEvent.ts # キーボード入力イベント / Keyboard input events
|
|
60
|
+
│ ├── FocusEvent.ts # フォーカス変更イベント / Focus change events
|
|
61
|
+
│ ├── WheelEvent.ts # マウスホイールイベント / Mouse wheel events
|
|
62
|
+
│ ├── VideoEvent.ts # ビデオ再生イベント / Video playback events
|
|
63
|
+
│ ├── JobEvent.ts # Tween ジョブイベント / Tween job events
|
|
64
|
+
│ ├── HTTPStatusEvent.ts # HTTP ステータスイベント / HTTP status events
|
|
65
|
+
│ ├── IOErrorEvent.ts # I/O エラーイベント / I/O error events
|
|
66
|
+
│ └── ProgressEvent.ts # ロード進捗イベント / Load progress events
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## イベントフロー / Event Flow
|
|
70
|
+
|
|
71
|
+
イベントシステムは、W3C DOM イベントモデルと同様の3フェーズイベントフロー機構を実装しています。
|
|
72
|
+
|
|
73
|
+
The event system implements a three-phase event flow mechanism similar to the W3C DOM event model.
|
|
74
|
+
|
|
75
|
+
```mermaid
|
|
76
|
+
sequenceDiagram
|
|
77
|
+
participant Stage as Stage / ステージ
|
|
78
|
+
participant Parent as Parent / 親
|
|
79
|
+
participant Target as Target / ターゲット
|
|
80
|
+
|
|
81
|
+
Note over Stage,Target: Phase 1: Capturing Phase / キャプチャリングフェーズ
|
|
82
|
+
Stage->>Parent: eventPhase = CAPTURING_PHASE (1)
|
|
83
|
+
Parent->>Target: eventPhase = CAPTURING_PHASE (1)
|
|
84
|
+
|
|
85
|
+
Note over Target: Phase 2: Target Phase / ターゲットフェーズ
|
|
86
|
+
Target->>Target: eventPhase = AT_TARGET (2)
|
|
87
|
+
|
|
88
|
+
Note over Target,Stage: Phase 3: Bubbling Phase (if bubbles=true) / バブリングフェーズ
|
|
89
|
+
Target->>Parent: eventPhase = BUBBLING_PHASE (3)
|
|
90
|
+
Parent->>Stage: eventPhase = BUBBLING_PHASE (3)
|
|
91
|
+
|
|
92
|
+
Note over Stage,Target: Event Flow Control / イベントフロー制御
|
|
93
|
+
rect rgb(255, 240, 240)
|
|
94
|
+
Note over Target: stopPropagation()<br/>Stops further propagation / 以降の伝播を停止
|
|
95
|
+
end
|
|
96
|
+
rect rgb(255, 230, 230)
|
|
97
|
+
Note over Target: stopImmediatePropagation()<br/>Stops all listeners immediately / すべてのリスナーを即座に停止
|
|
98
|
+
end
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## コアクラス / Core Classes
|
|
102
|
+
|
|
103
|
+
### Event
|
|
104
|
+
|
|
105
|
+
すべてのイベントの基本クラス。コアイベントプロパティと伝播制御メソッドを提供します。
|
|
106
|
+
|
|
107
|
+
The base class for all events. Provides core event properties and propagation control methods.
|
|
108
|
+
|
|
109
|
+
**主要プロパティ / Key Properties:**
|
|
110
|
+
- `type`: イベントタイプ識別子 / Event type identifier
|
|
111
|
+
- `bubbles`: イベントがバブリングフェーズに参加するかどうか / Whether the event participates in the bubbling phase
|
|
112
|
+
- `target`: イベントリスナーを登録したオブジェクト / The object that registered the event listener
|
|
113
|
+
- `currentTarget`: 現在イベントを処理しているオブジェクト / The object currently processing the event
|
|
114
|
+
- `eventPhase`: イベントフローの現在のフェーズ / Current phase of event flow (CAPTURING_PHASE, AT_TARGET, BUBBLING_PHASE)
|
|
115
|
+
|
|
116
|
+
**メソッド / Methods:**
|
|
117
|
+
- `stopPropagation()`: 後続ノードでの処理を防止 / Prevents processing in subsequent nodes
|
|
118
|
+
- `stopImmediatePropagation()`: 残りのすべてのリスナーの処理を防止 / Prevents processing of all remaining listeners
|
|
119
|
+
|
|
120
|
+
### EventDispatcher
|
|
121
|
+
|
|
122
|
+
イベントを送出するすべてのクラスの基本クラス。イベントリスナーの登録とイベントの送出を管理します。
|
|
123
|
+
|
|
124
|
+
The base class for all classes that dispatch events. Manages event listener registration and event dispatching.
|
|
125
|
+
|
|
126
|
+
**メソッド / Methods:**
|
|
127
|
+
- `addEventListener(type, listener, useCapture, priority)`: イベントリスナーを登録 / Register an event listener
|
|
128
|
+
- `removeEventListener(type, listener, useCapture)`: イベントリスナーを削除 / Remove an event listener
|
|
129
|
+
- `removeAllEventListener(type, useCapture)`: 特定タイプのすべてのリスナーを削除 / Remove all listeners of a specific type
|
|
130
|
+
- `dispatchEvent(event)`: イベントをイベントフローに送出 / Dispatch an event into the event flow
|
|
131
|
+
- `hasEventListener(type)`: イベントタイプのリスナーが存在するか確認 / Check if a listener exists for an event type
|
|
132
|
+
- `willTrigger(type)`: このオブジェクトまたは祖先がイベントタイプのリスナーを持つか確認 / Check if this object or ancestors have listeners for an event type
|
|
133
|
+
|
|
134
|
+
### EventPhase
|
|
135
|
+
|
|
136
|
+
イベントフローの現在のフェーズを定義する定数。
|
|
137
|
+
|
|
138
|
+
Constants defining the current phase of event flow.
|
|
139
|
+
|
|
140
|
+
- `CAPTURING_PHASE = 1`: キャプチャフェーズ / The capture phase
|
|
141
|
+
- `AT_TARGET = 2`: ターゲットフェーズ / The target phase
|
|
142
|
+
- `BUBBLING_PHASE = 3`: バブリングフェーズ / The bubbling phase
|
|
143
|
+
|
|
144
|
+
## イベントタイプ / Event Types
|
|
145
|
+
|
|
146
|
+
### PointerEvent
|
|
147
|
+
|
|
148
|
+
ポインターデバイスの操作(マウス、ペン、タッチ)を処理します。
|
|
149
|
+
|
|
150
|
+
Handles pointer device interactions (mouse, pen, touch).
|
|
151
|
+
|
|
152
|
+
**イベントタイプ / Event Types:**
|
|
153
|
+
- `POINTER_DOWN`: ボタンの押下開始 / Button press started
|
|
154
|
+
- `POINTER_UP`: ボタンの解放 / Button released
|
|
155
|
+
- `POINTER_MOVE`: ポインター座標の変化 / Pointer coordinates changed
|
|
156
|
+
- `POINTER_OVER`: ポインターがヒットテスト境界に入った / Pointer entered hit test boundary
|
|
157
|
+
- `POINTER_OUT`: ポインターがヒットテスト境界を出た / Pointer left hit test boundary
|
|
158
|
+
- `POINTER_LEAVE`: ポインターが要素領域を離れた / Pointer left element area
|
|
159
|
+
- `POINTER_CANCEL`: ポインター操作がキャンセルされた / Pointer interaction canceled
|
|
160
|
+
- `DOUBLE_CLICK`: ダブルクリック/タップが発生 / Double-click/tap occurred
|
|
161
|
+
|
|
162
|
+
### KeyboardEvent
|
|
163
|
+
|
|
164
|
+
キーボード入力を処理します。
|
|
165
|
+
|
|
166
|
+
Handles keyboard input.
|
|
167
|
+
|
|
168
|
+
**イベントタイプ / Event Types:**
|
|
169
|
+
- `KEY_DOWN`: キーが押された / Key pressed
|
|
170
|
+
- `KEY_UP`: キーが離された / Key released
|
|
171
|
+
|
|
172
|
+
### FocusEvent
|
|
173
|
+
|
|
174
|
+
表示オブジェクト間のフォーカス変更を処理します。
|
|
175
|
+
|
|
176
|
+
Handles focus changes between display objects.
|
|
177
|
+
|
|
178
|
+
**イベントタイプ / Event Types:**
|
|
179
|
+
- `FOCUS_IN`: 要素がフォーカスを受け取った / Element received focus
|
|
180
|
+
- `FOCUS_OUT`: 要素がフォーカスを失った / Element lost focus
|
|
181
|
+
|
|
182
|
+
### WheelEvent
|
|
183
|
+
|
|
184
|
+
マウスホイールの操作を処理します。
|
|
185
|
+
|
|
186
|
+
Handles mouse wheel interactions.
|
|
187
|
+
|
|
188
|
+
**イベントタイプ / Event Types:**
|
|
189
|
+
- `WHEEL`: マウスホイールが回転した / Mouse wheel rotated
|
|
190
|
+
|
|
191
|
+
### VideoEvent
|
|
192
|
+
|
|
193
|
+
ビデオ再生の状態変化を処理します。
|
|
194
|
+
|
|
195
|
+
Handles video playback state changes.
|
|
196
|
+
|
|
197
|
+
**イベントタイプ / Event Types:**
|
|
198
|
+
- `PLAY`: ビデオ再生がリクエストされた / Video play requested
|
|
199
|
+
- `PLAYING`: ビデオ再生が開始された / Video playback started
|
|
200
|
+
- `PAUSE`: ビデオが一時停止された / Video paused
|
|
201
|
+
- `SEEK`: ビデオシーク操作 / Video seek operation
|
|
202
|
+
|
|
203
|
+
### JobEvent
|
|
204
|
+
|
|
205
|
+
Tween アニメーションイベントを処理します。
|
|
206
|
+
|
|
207
|
+
Handles tween animation events.
|
|
208
|
+
|
|
209
|
+
**イベントタイプ / Event Types:**
|
|
210
|
+
- `UPDATE`: Tween プロパティが更新された / Tween property updated
|
|
211
|
+
- `STOP`: Tween ジョブが停止した / Tween job stopped
|
|
212
|
+
|
|
213
|
+
### ProgressEvent
|
|
214
|
+
|
|
215
|
+
ファイルやデータのロード進捗を処理します。
|
|
216
|
+
|
|
217
|
+
Handles loading progress for files and data.
|
|
218
|
+
|
|
219
|
+
**プロパティ / Properties:**
|
|
220
|
+
- `bytesLoaded`: これまでにロードされたバイト数 / Bytes loaded so far
|
|
221
|
+
- `bytesTotal`: ロードする合計バイト数 / Total bytes to load
|
|
222
|
+
|
|
223
|
+
**イベントタイプ / Event Types:**
|
|
224
|
+
- `PROGRESS`: ロード進捗の更新 / Loading progress update
|
|
225
|
+
|
|
226
|
+
### HTTPStatusEvent
|
|
227
|
+
|
|
228
|
+
HTTP レスポンスステータスを処理します。
|
|
229
|
+
|
|
230
|
+
Handles HTTP response status.
|
|
231
|
+
|
|
232
|
+
**プロパティ / Properties:**
|
|
233
|
+
- `status`: HTTP ステータスコード / HTTP status code
|
|
234
|
+
- `responseURL`: レスポンス URL / Response URL
|
|
235
|
+
- `responseHeaders`: レスポンスヘッダーの配列 / Array of response headers
|
|
236
|
+
|
|
237
|
+
**イベントタイプ / Event Types:**
|
|
238
|
+
- `HTTP_STATUS`: HTTP ステータスを受信 / HTTP status received
|
|
239
|
+
|
|
240
|
+
### IOErrorEvent
|
|
241
|
+
|
|
242
|
+
I/O 操作エラーを処理します。
|
|
243
|
+
|
|
244
|
+
Handles I/O operation errors.
|
|
245
|
+
|
|
246
|
+
**プロパティ / Properties:**
|
|
247
|
+
- `text`: エラーメッセージテキスト / Error message text
|
|
248
|
+
|
|
249
|
+
**イベントタイプ / Event Types:**
|
|
250
|
+
- `IO_ERROR`: I/O エラーが発生 / I/O error occurred
|
|
251
|
+
|
|
252
|
+
## 使用例 / Usage Example
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { EventDispatcher, Event, PointerEvent } from '@next2d/events';
|
|
256
|
+
|
|
257
|
+
// イベントディスパッチャーを作成 / Create an event dispatcher
|
|
258
|
+
const dispatcher = new EventDispatcher();
|
|
259
|
+
|
|
260
|
+
// イベントリスナーを追加 / Add event listener
|
|
261
|
+
dispatcher.addEventListener(PointerEvent.POINTER_DOWN, (event: Event) => {
|
|
262
|
+
console.log('ポインターダウン / Pointer down:', event.target);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// イベントを送出 / Dispatch event
|
|
266
|
+
const event = new PointerEvent(PointerEvent.POINTER_DOWN, true);
|
|
267
|
+
dispatcher.dispatchEvent(event);
|
|
268
|
+
|
|
269
|
+
// イベントリスナーを削除 / Remove event listener
|
|
270
|
+
dispatcher.removeEventListener(PointerEvent.POINTER_DOWN, listener);
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### イベントバブリングの例 / Event Bubbling Example
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { EventDispatcher, Event } from '@next2d/events';
|
|
277
|
+
|
|
278
|
+
const stage = new EventDispatcher();
|
|
279
|
+
const parent = new EventDispatcher();
|
|
280
|
+
const child = new EventDispatcher();
|
|
281
|
+
|
|
282
|
+
// 階層を設定(child -> parent -> stage)
|
|
283
|
+
// Setup hierarchy (child -> parent -> stage)
|
|
284
|
+
|
|
285
|
+
// キャプチャフェーズリスナーを追加 / Add capturing phase listener
|
|
286
|
+
stage.addEventListener(Event.ADDED, (e) => {
|
|
287
|
+
console.log('ステージ / Stage: Capturing', e.eventPhase); // 1
|
|
288
|
+
}, true);
|
|
289
|
+
|
|
290
|
+
// ターゲットフェーズリスナーを追加 / Add target phase listener
|
|
291
|
+
child.addEventListener(Event.ADDED, (e) => {
|
|
292
|
+
console.log('子 / Child: Target', e.eventPhase); // 2
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// バブリングフェーズリスナーを追加 / Add bubbling phase listener
|
|
296
|
+
parent.addEventListener(Event.ADDED, (e) => {
|
|
297
|
+
console.log('親 / Parent: Bubbling', e.eventPhase); // 3
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// 子からバブリングイベントを送出 / Dispatch bubbling event from child
|
|
301
|
+
const event = new Event(Event.ADDED, true); // bubbles = true
|
|
302
|
+
child.dispatchEvent(event);
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## ライセンス / License
|
|
306
|
+
|
|
11
307
|
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details.
|