@next2d/events 1.14.20

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/dist/Event.js ADDED
@@ -0,0 +1,560 @@
1
+ import { EventPhase } from "./EventPhase";
2
+ /**
3
+ * Event クラスのメソッドは、イベントリスナー関数で使用してイベントオブジェクトの動作に影響を与えることができます。
4
+ * 一部のイベントにはデフォルトの動作が関連付けられています。
5
+ * 例えば、doubleClick イベントには、イベント時にマウスポインター位置の単語がハイライト表示されるというデフォルトの動作が関連付けられています。
6
+ * イベントリスナーで preventDefault() メソッドを呼び出してこの動作をキャンセルできます。
7
+ * また、stopPropagation() メソッドまたは stopImmediatePropagation() メソッドを呼び出すと、
8
+ * 現在のイベントリスナーを、イベントを処理する最後のイベントリスナーにすることができます。
9
+ *
10
+ * The methods of the Event class can be used in event listener functions to affect the behavior of the event object.
11
+ * Some events have an associated default behavior. For example,
12
+ * the doubleClick event has an associated default behavior that highlights the word under the mouse pointer at the time of the event.
13
+ * Your event listener can cancel this behavior by calling the preventDefault() method.
14
+ * You can also make the current event listener the last one to process
15
+ * an event by calling the stopPropagation() or stopImmediatePropagation() method.
16
+ *
17
+ * @class
18
+ * @memberOf next2d.events
19
+ */
20
+ export class Event {
21
+ /**
22
+ * @param {string} type
23
+ * @param {boolean} [bubbles=false]
24
+ * @param {boolean} [cancelable=false]
25
+ *
26
+ * @constructor
27
+ * @public
28
+ */
29
+ constructor(type, bubbles = false, cancelable = false) {
30
+ /**
31
+ * @type {string}
32
+ * @private
33
+ */
34
+ this._$type = `${type}`;
35
+ /**
36
+ * @type {boolean}
37
+ * @private
38
+ */
39
+ this._$bubbles = bubbles;
40
+ /**
41
+ * @type {boolean}
42
+ * @private
43
+ */
44
+ this._$cancelable = cancelable;
45
+ /**
46
+ * @type {EventDispatcher}
47
+ * @private
48
+ */
49
+ this._$target = null;
50
+ /**
51
+ * @type {EventDispatcher}
52
+ * @default null
53
+ * @private
54
+ */
55
+ this._$currentTarget = null;
56
+ /**
57
+ * @type {number}
58
+ * @default EventPhase.AT_TARGET
59
+ * @private
60
+ */
61
+ this._$eventPhase = EventPhase.AT_TARGET;
62
+ /**
63
+ * @type {function}
64
+ * @default null
65
+ * @private
66
+ */
67
+ this._$listener = null;
68
+ /**
69
+ * @type {boolean}
70
+ * @default false
71
+ * @private
72
+ */
73
+ this._$stopImmediatePropagation = false;
74
+ /**
75
+ * @type {boolean}
76
+ * @default false
77
+ * @private
78
+ */
79
+ this._$stopPropagation = false;
80
+ }
81
+ /**
82
+ * 指定されたクラスのストリングを返します。
83
+ * Returns the string representation of the specified class.
84
+ *
85
+ * @return {string}
86
+ * @default [class Event]
87
+ * @method
88
+ * @static
89
+ */
90
+ static toString() {
91
+ return "[class Event]";
92
+ }
93
+ /**
94
+ * @description 指定されたクラスの空間名を返します。
95
+ * Returns the space name of the specified class.
96
+ *
97
+ * @member {string}
98
+ * @default next2d.events.Event
99
+ * @const
100
+ * @static
101
+ */
102
+ static get namespace() {
103
+ return "next2d.events.Event";
104
+ }
105
+ /**
106
+ * @description 指定されたオブジェクトのストリングを返します。
107
+ * Returns the string representation of the specified object.
108
+ *
109
+ * @return {string}
110
+ * @method
111
+ * @public
112
+ */
113
+ toString() {
114
+ return this.formatToString("Event", "type", "bubbles", "cancelable", "eventPhase");
115
+ }
116
+ /**
117
+ * @description 指定されたオブジェクトの空間名を返します。
118
+ * Returns the space name of the specified object.
119
+ *
120
+ * @member {string}
121
+ * @default next2d.events.Event
122
+ * @const
123
+ * @public
124
+ */
125
+ get namespace() {
126
+ return "next2d.events.Event";
127
+ }
128
+ /**
129
+ * @description ACTIVATE 定数は、type プロパティ(activate イベントオブジェクト)の値を定義します。
130
+ * The ACTIVATE constant defines the value
131
+ * of the type property of an activate event object.
132
+ *
133
+ * @return {string}
134
+ * @default activate
135
+ * @const
136
+ * @static
137
+ */
138
+ static get ACTIVATE() {
139
+ return "activate";
140
+ }
141
+ /**
142
+ * @description Event.ADDED 定数は、added イベントオブジェクトの type プロパティの値を定義します。
143
+ * The Event.ADDED constant defines the value
144
+ * of the type property of an added event object.
145
+ *
146
+ * @return {string}
147
+ * @default added
148
+ * @const
149
+ * @static
150
+ */
151
+ static get ADDED() {
152
+ return "added";
153
+ }
154
+ /**
155
+ * @description Event.ADDED_TO_STAGE 定数は、type プロパティ(addedToStage イベントオブジェクト)の値を定義します。
156
+ * The Event.ADDED_TO_STAGE constant defines the value
157
+ * of the type property of an addedToStage event object.
158
+ *
159
+ * @return {string}
160
+ * @default addedToStage
161
+ * @const
162
+ * @static
163
+ */
164
+ static get ADDED_TO_STAGE() {
165
+ return "addedToStage";
166
+ }
167
+ /**
168
+ * @description Event.CHANGE 定数は、type プロパティ(change イベントオブジェクト)の値を定義します。
169
+ * The Event.CHANGE constant defines the value
170
+ * of the type property of a change event object.
171
+ *
172
+ * @return {string}
173
+ * @default change
174
+ * @const
175
+ * @static
176
+ */
177
+ static get CHANGE() {
178
+ return "change";
179
+ }
180
+ /**
181
+ * @description Event.COMPLETE 定数は、complete イベントオブジェクトの type プロパティの値を定義します。
182
+ * The Event.COMPLETE constant defines the value
183
+ * of the type property of a complete event object.
184
+ *
185
+ * @return {string}
186
+ * @default complete
187
+ * @const
188
+ * @static
189
+ */
190
+ static get COMPLETE() {
191
+ return "complete";
192
+ }
193
+ /**
194
+ * @description Event.DEACTIVATE 定数は、deactivate イベントオブジェクトの type プロパティの値を定義します。
195
+ * The Event.DEACTIVATE constant defines the value
196
+ * of the type property of a deactivate event object.
197
+ *
198
+ * @return {string}
199
+ * @default deactivate
200
+ * @const
201
+ * @static
202
+ */
203
+ static get DEACTIVATE() {
204
+ return "deactivate";
205
+ }
206
+ /**
207
+ * @description Event.ENTER_FRAME 定数は、enterFrame イベントオブジェクトの type プロパティの値を定義します。
208
+ * The Event.ENTER_FRAME constant defines the value
209
+ * of the type property of an enterFrame event object.
210
+ *
211
+ * @return {string}
212
+ * @default enterFrame
213
+ * @const
214
+ * @static
215
+ */
216
+ static get ENTER_FRAME() {
217
+ return "enterFrame";
218
+ }
219
+ /**
220
+ * @description Event.EXIT_FRAME 定数は、exitFrame イベントオブジェクトの type プロパティの値を定義します。
221
+ * The Event.EXIT_FRAME constant defines the value
222
+ * of the type property of an exitFrame event object.
223
+ *
224
+ * @return {string}
225
+ * @default exitFrame
226
+ * @const
227
+ * @static
228
+ */
229
+ static get EXIT_FRAME() {
230
+ return "exitFrame";
231
+ }
232
+ /**
233
+ * @description Event.FRAME_CONSTRUCTED 定数は、frameConstructed イベントオブジェクトの type プロパティの値を定義します。
234
+ * The Event.FRAME_CONSTRUCTED constant defines the value
235
+ * of the type property of an frameConstructed event object.
236
+ *
237
+ * @return {string}
238
+ * @default frameConstructed
239
+ * @const
240
+ * @static
241
+ */
242
+ static get FRAME_CONSTRUCTED() {
243
+ return "frameConstructed";
244
+ }
245
+ /**
246
+ * @description Event.FRAME_LABEL 定数は、frameLabel イベントオブジェクトの type プロパティの値を定義します。
247
+ * The Event.FRAME_LABEL constant defines the value
248
+ * of the type property of an frameLabel event object.
249
+ *
250
+ * @return {string}
251
+ * @default frameLabel
252
+ * @const
253
+ * @static
254
+ */
255
+ static get FRAME_LABEL() {
256
+ return "frameLabel";
257
+ }
258
+ /**
259
+ * @description Event.INIT 定数は、init イベントオブジェクトの type プロパティの値を定義します。
260
+ * The Event.INIT constant defines the value
261
+ * of the type property of an init event object.
262
+ *
263
+ * @return {string}
264
+ * @default frameConstructed
265
+ * @const
266
+ * @static
267
+ */
268
+ static get INIT() {
269
+ return "init";
270
+ }
271
+ /**
272
+ * @description Event.LOAD 定数は、load イベントオブジェクトの type プロパティの値を定義します。
273
+ * The Event.LOAD constant defines the value
274
+ * of the type property of an load event object.
275
+ *
276
+ * @return {string}
277
+ * @default frameConstructed
278
+ * @const
279
+ * @static
280
+ */
281
+ static get LOAD() {
282
+ return "load";
283
+ }
284
+ /**
285
+ * @description Event.MOUSE_LEAVE 定数は、mouseLeave イベントオブジェクトの type プロパティの値を定義します。
286
+ * The Event.MOUSE_LEAVE constant defines the value
287
+ * of the type property of a mouseLeave event object.
288
+ *
289
+ * @return {string}
290
+ * @default mouseLeave
291
+ * @const
292
+ * @static
293
+ */
294
+ static get MOUSE_LEAVE() {
295
+ return "mouseLeave";
296
+ }
297
+ /**
298
+ * @description Event.REMOVED 定数は、removed プロパティ(paste イベントオブジェクト)の値を定義します。
299
+ * The Event.REMOVED constant defines the value
300
+ * of the type property of a removed event object.
301
+ *
302
+ * @return {string}
303
+ * @default removed
304
+ * @const
305
+ * @static
306
+ */
307
+ static get REMOVED() {
308
+ return "removed";
309
+ }
310
+ /**
311
+ * @description Event.REMOVED_FROM_STAGE 定数は、removedFromStage イベントオブジェクトの type プロパティの値を定義します。
312
+ * The Event.REMOVED_FROM_STAGE constant defines the value
313
+ * of the type property of a removedFromStage event object.
314
+ *
315
+ * @return {string}
316
+ * @default removedFromStage
317
+ * @const
318
+ * @static
319
+ */
320
+ static get REMOVED_FROM_STAGE() {
321
+ return "removedFromStage";
322
+ }
323
+ /**
324
+ * @description Event.RENDER 定数は、render イベントオブジェクトの
325
+ * type プロパティの値を定義します。
326
+ * The Event.RENDER constant defines the value
327
+ * of the type property of a render event object.
328
+ *
329
+ * @return {string}
330
+ * @default render
331
+ * @const
332
+ * @static
333
+ */
334
+ static get RENDER() {
335
+ return "render";
336
+ }
337
+ /**
338
+ * @description Event.RESIZE 定数は、resize イベントオブジェクトの
339
+ * type プロパティの値を定義します。
340
+ * The Event.RESIZE constant defines the value
341
+ * of the type property of a resize event object.
342
+ *
343
+ * @return {string}
344
+ * @default resize
345
+ * @const
346
+ * @static
347
+ */
348
+ static get RESIZE() {
349
+ return "resize";
350
+ }
351
+ /**
352
+ * @description Event.SCROLL 定数は、render イベントオブジェクトの
353
+ * type プロパティの値を定義します。
354
+ * The Event.SCROLL constant defines the value
355
+ * of the type property of a render event object.
356
+ *
357
+ * @return {string}
358
+ * @default scroll
359
+ * @const
360
+ * @static
361
+ */
362
+ static get SCROLL() {
363
+ return "scroll";
364
+ }
365
+ /**
366
+ * @description Event.OPEN 定数は、render イベントオブジェクトの
367
+ * type プロパティの値を定義します。
368
+ * The Event.OPEN constant defines the value
369
+ * of the type property of a render event object.
370
+ *
371
+ * @return {string}
372
+ * @default open
373
+ * @const
374
+ * @static
375
+ */
376
+ static get OPEN() {
377
+ return "open";
378
+ }
379
+ /**
380
+ * @description Event.STOP 定数は、render イベントオブジェクトの
381
+ * type プロパティの値を定義します。
382
+ * The Event.STOP constant defines the value
383
+ * of the type property of a render event object.
384
+ *
385
+ * @return {string}
386
+ * @default stop
387
+ * @const
388
+ * @static
389
+ */
390
+ static get STOP() {
391
+ return "stop";
392
+ }
393
+ /**
394
+ * @description Event.SOUND_COMPLETE 定数は、soundComplete イベントオブジェクトの type プロパティの値を定義します。
395
+ * The Event.SOUND_COMPLETE constant defines the value
396
+ * of the type property of a soundComplete event object.
397
+ *
398
+ * @return {string}
399
+ * @default render
400
+ * @const
401
+ * @static
402
+ */
403
+ static get SOUND_COMPLETE() {
404
+ return "soundComplete";
405
+ }
406
+ /**
407
+ * @description Event.UPDATE 定数は、render イベントオブジェクトの
408
+ * type プロパティの値を定義します。
409
+ * The Event.STOP constant defines the value
410
+ * of the type property of a render event object.
411
+ *
412
+ * @return {string}
413
+ * @default update
414
+ * @const
415
+ * @static
416
+ */
417
+ static get UPDATE() {
418
+ return "update";
419
+ }
420
+ /**
421
+ * @description イベントがバブリングイベントかどうかを示します。
422
+ * Indicates whether an event is a bubbling event.
423
+ *
424
+ * @member {boolean}
425
+ * @readonly
426
+ * @public
427
+ */
428
+ get bubbles() {
429
+ return this._$bubbles;
430
+ }
431
+ /**
432
+ * @description イベントに関連付けられた動作を回避できるかどうかを示します。
433
+ * Indicates whether the behavior associated
434
+ * with the event can be prevented.
435
+ *
436
+ * @member {boolean}
437
+ * @readonly
438
+ * @public
439
+ */
440
+ get cancelable() {
441
+ return this._$cancelable;
442
+ }
443
+ /**
444
+ * @description イベントリスナーで Event オブジェクトをアクティブに処理しているオブジェクトです。
445
+ * The object that is actively processing the Event object
446
+ * with an event listener.
447
+ *
448
+ * @member {EventDispatcher|null}
449
+ * @public
450
+ */
451
+ get currentTarget() {
452
+ return this._$currentTarget;
453
+ }
454
+ set currentTarget(current_target) {
455
+ this._$currentTarget = current_target;
456
+ }
457
+ /**
458
+ * @description イベントフローの現在の段階です。
459
+ * The current phase in the event flow.
460
+ *
461
+ * @member {number}
462
+ * @public
463
+ */
464
+ get eventPhase() {
465
+ return this._$eventPhase;
466
+ }
467
+ set eventPhase(event_phase) {
468
+ this._$eventPhase = event_phase;
469
+ }
470
+ /**
471
+ * @description 現在コールされている関数
472
+ * Function currently being called.
473
+ *
474
+ * @member {function}
475
+ * @public
476
+ */
477
+ get listener() {
478
+ return this._$listener;
479
+ }
480
+ set listener(listener) {
481
+ this._$listener = listener;
482
+ }
483
+ /**
484
+ * @description イベントターゲットです。
485
+ * The event target.
486
+ *
487
+ * @member {EventDispatcher|null}
488
+ * @public
489
+ */
490
+ get target() {
491
+ return this._$target ? this._$target : this._$currentTarget;
492
+ }
493
+ set target(target) {
494
+ this._$target = target;
495
+ }
496
+ /**
497
+ * @description イベントのタイプです。
498
+ * The type of event.
499
+ *
500
+ * @member {string}
501
+ * @readonly
502
+ * @public
503
+ */
504
+ get type() {
505
+ return this._$type;
506
+ }
507
+ /**
508
+ * @description カスタム ActionScript 3.0 Event クラスに
509
+ * toString() メソッドを実装するためのユーティリティ関数です。
510
+ * A utility function for implementing the toString() method
511
+ * in custom ActionScript 3.0 Event classes.
512
+ *
513
+ * @return {string}
514
+ * @method
515
+ * @public
516
+ */
517
+ formatToString(...args) {
518
+ let str = `[${args[0]}`;
519
+ for (let idx = 1; idx < args.length; ++idx) {
520
+ // eslint-disable-next-line prefer-rest-params
521
+ const name = args[idx];
522
+ str += ` ${name}=`;
523
+ // @ts-ignore
524
+ const value = this[name];
525
+ if (typeof value === "string") {
526
+ str += `"${value}"`;
527
+ }
528
+ else {
529
+ str += `${value}`;
530
+ }
531
+ }
532
+ return `${str}]`;
533
+ }
534
+ /**
535
+ * @description イベントフローの現在のノードおよび後続するノードで、
536
+ * イベントリスナーが処理されないようにします。
537
+ * Prevents processing of any event listeners in the current node
538
+ * and any subsequent nodes in the event flow.
539
+ *
540
+ * @return {void}
541
+ * @method
542
+ * @public
543
+ */
544
+ stopImmediatePropagation() {
545
+ this._$stopImmediatePropagation = true;
546
+ }
547
+ /**
548
+ * @description イベントフローの現在のノードに後続するノードで
549
+ * イベントリスナーが処理されないようにします。
550
+ * Prevents processing of any event listeners in nodes subsequent
551
+ * to the current node in the event flow.
552
+ *
553
+ * @return {void}
554
+ * @method
555
+ * @public
556
+ */
557
+ stopPropagation() {
558
+ this._$stopPropagation = true;
559
+ }
560
+ }
@@ -0,0 +1,138 @@
1
+ import { Event } from "./Event";
2
+ import { EventListenerImpl } from "@next2d/interface";
3
+ /**
4
+ * EventDispatcher クラスは、イベントを送出するすべてのクラスの基本クラスです。
5
+ *
6
+ * The EventDispatcher class is the base class for all classes that dispatch events.
7
+ *
8
+ * @example <caption>Example usage of EventDispatcher.</caption>
9
+ * // new ColorTransform
10
+ * const {EventDispatcher} = next2d.events;
11
+ * const eventDispatcher = new EventDispatcher();
12
+ * eventDispatcher.addEventListener(Event.ENTER_FRAME, function (event)
13
+ * {
14
+ * // more...
15
+ * });
16
+ *
17
+ * @class
18
+ * @memberOf next2d.events
19
+ */
20
+ export declare class EventDispatcher {
21
+ _$events: Map<string, EventListenerImpl[]> | null;
22
+ /**
23
+ * @constructor
24
+ * @public
25
+ */
26
+ constructor();
27
+ /**
28
+ * 指定されたクラスのストリングを返します。
29
+ * Returns the string representation of the specified class.
30
+ *
31
+ * @return {string}
32
+ * @default [class EventDispatcher]
33
+ * @method
34
+ * @static
35
+ */
36
+ static toString(): string;
37
+ /**
38
+ * @description 指定されたクラスの空間名を返します。
39
+ * Returns the space name of the specified class.
40
+ *
41
+ * @member {string}
42
+ * @default next2d.events.EventDispatcher
43
+ * @const
44
+ * @static
45
+ */
46
+ static get namespace(): string;
47
+ /**
48
+ * @description 指定されたオブジェクトのストリングを返します。
49
+ * Returns the string representation of the specified object.
50
+ *
51
+ * @return {string}
52
+ * @method
53
+ * @public
54
+ */
55
+ toString(): string;
56
+ /**
57
+ * @description 指定されたオブジェクトの空間名を返します。
58
+ * Returns the space name of the specified object.
59
+ *
60
+ * @member {string}
61
+ * @default next2d.events.EventDispatcher
62
+ * @const
63
+ * @public
64
+ */
65
+ get namespace(): string;
66
+ /**
67
+ * @description イベントリスナーオブジェクトを EventDispatcher オブジェクトに登録し、
68
+ * リスナーがイベントの通知を受け取るようにします。
69
+ * Registers an event listener object with an EventDispatcher object
70
+ * so that the listener receives notification of an event.
71
+ *
72
+ * @param {string} type
73
+ * @param {function} listener
74
+ * @param {boolean} [use_capture=false]
75
+ * @param {number} [priority=0]
76
+ * @return {void}
77
+ * @method
78
+ * @public
79
+ */
80
+ addEventListener(type: string, listener: Function, use_capture?: boolean, priority?: number): void;
81
+ /**
82
+ * @description イベントをイベントフローに送出します。
83
+ * Dispatches an event into the event flow.
84
+ *
85
+ * @param {Event} event
86
+ * @return {boolean}
87
+ * @method
88
+ * @public
89
+ */
90
+ dispatchEvent(event: Event): boolean;
91
+ /**
92
+ * @description EventDispatcher オブジェクトに、特定のイベントタイプに対して登録されたリスナーがあるかどうかを確認します。
93
+ * Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
94
+ *
95
+ * @param {string} type
96
+ * @return {boolean}
97
+ * @method
98
+ * @public
99
+ */
100
+ hasEventListener(type: string): boolean;
101
+ /**
102
+ * @description EventDispatcher オブジェクトからリスナーを削除します。
103
+ * Removes a listener from the EventDispatcher object.
104
+ *
105
+ * @param {string} type
106
+ * @param {function} [listener = null]
107
+ * @param {boolean} [use_capture = false]
108
+ * @return {void}
109
+ * @method
110
+ * @public
111
+ */
112
+ removeEventListener(type: string, listener: Function | null, use_capture?: boolean): void;
113
+ /**
114
+ * @description EventDispatcherオブジェクトから指定したタイプのリスナーを全て削除します。
115
+ * Removes all listeners of the specified type from the EventDispatcher object.
116
+ *
117
+ * @param {string} type
118
+ * @param {boolean} [use_capture=false]
119
+ * @return {void}
120
+ * @method
121
+ * @public
122
+ */
123
+ removeAllEventListener(type: string, use_capture?: boolean): void;
124
+ /**
125
+ * @description 指定されたイベントタイプについて、
126
+ * この EventDispatcher オブジェクトまたはその祖先にイベントリスナーが
127
+ * 登録されているかどうかを確認します。
128
+ * Checks whether an event listener is registered
129
+ * with this EventDispatcher object or
130
+ * any of its ancestors for the specified event type.
131
+ *
132
+ * @param {string} type
133
+ * @return {boolean}
134
+ * @method
135
+ * @public
136
+ */
137
+ willTrigger(type: string): boolean;
138
+ }