@next2d/media 1.18.11 → 2.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.
Files changed (110) hide show
  1. package/README.md +2 -2
  2. package/package.json +13 -26
  3. package/src/MediaUtil.d.ts +104 -0
  4. package/src/MediaUtil.js +203 -0
  5. package/src/Sound/service/SoundDecodeService.d.ts +10 -0
  6. package/src/Sound/service/SoundDecodeService.js +30 -0
  7. package/src/Sound/service/SoundEndedEventService.d.ts +11 -0
  8. package/src/Sound/service/SoundEndedEventService.js +21 -0
  9. package/src/Sound/service/SoundLoadStartEventService.d.ts +12 -0
  10. package/src/Sound/service/SoundLoadStartEventService.js +19 -0
  11. package/src/Sound/service/SoundProgressEventService.d.ts +12 -0
  12. package/src/Sound/service/SoundProgressEventService.js +16 -0
  13. package/src/Sound/usecase/SoundBuildFromCharacterUseCase.d.ts +13 -0
  14. package/src/Sound/usecase/SoundBuildFromCharacterUseCase.js +23 -0
  15. package/src/Sound/usecase/SoundLoadEndEventUseCase.d.ts +12 -0
  16. package/src/Sound/usecase/SoundLoadEndEventUseCase.js +35 -0
  17. package/src/Sound/usecase/SoundLoadUseCase.d.ts +13 -0
  18. package/src/Sound/usecase/SoundLoadUseCase.js +38 -0
  19. package/src/Sound.d.ts +136 -0
  20. package/src/Sound.js +247 -0
  21. package/src/SoundMixer/service/SoundMixerStopAllService.d.ts +9 -0
  22. package/src/SoundMixer/service/SoundMixerStopAllService.js +32 -0
  23. package/src/SoundMixer/service/SoundMixerUpdateVolumeService.d.ts +9 -0
  24. package/src/SoundMixer/service/SoundMixerUpdateVolumeService.js +29 -0
  25. package/src/SoundMixer.d.ts +28 -0
  26. package/src/SoundMixer.js +37 -0
  27. package/src/SoundTransform.d.ts +35 -0
  28. package/src/SoundTransform.js +48 -0
  29. package/src/Video/service/VideoApplyChangesService.d.ts +11 -0
  30. package/src/Video/service/VideoApplyChangesService.js +16 -0
  31. package/src/Video/service/VideoCreateElementService.d.ts +9 -0
  32. package/src/Video/service/VideoCreateElementService.js +16 -0
  33. package/src/Video/service/VideoEndedEventService.d.ts +11 -0
  34. package/src/Video/service/VideoEndedEventService.js +22 -0
  35. package/src/Video/service/VideoLoadedmetadataEventService.d.ts +12 -0
  36. package/src/Video/service/VideoLoadedmetadataEventService.js +21 -0
  37. package/src/Video/service/VideoProgressEventService.d.ts +11 -0
  38. package/src/Video/service/VideoProgressEventService.js +15 -0
  39. package/src/Video/usecase/VideoBuildFromCharacterUseCase.d.ts +13 -0
  40. package/src/Video/usecase/VideoBuildFromCharacterUseCase.js +22 -0
  41. package/src/Video/usecase/VideoCanplaythroughEventUseCase.d.ts +11 -0
  42. package/src/Video/usecase/VideoCanplaythroughEventUseCase.js +26 -0
  43. package/src/Video/usecase/VideoPlayEventUseCase.d.ts +11 -0
  44. package/src/Video/usecase/VideoPlayEventUseCase.js +31 -0
  45. package/src/Video/usecase/VideoRegisterEventUseCase.d.ts +12 -0
  46. package/src/Video/usecase/VideoRegisterEventUseCase.js +29 -0
  47. package/src/Video.d.ts +245 -0
  48. package/src/Video.js +428 -0
  49. package/{dist → src}/index.d.ts +1 -0
  50. package/{dist → src}/index.js +1 -0
  51. package/src/interface/IAjaxEvent.d.ts +5 -0
  52. package/src/interface/IAjaxEvent.js +1 -0
  53. package/src/interface/IAjaxOption.d.ts +13 -0
  54. package/src/interface/IAjaxOption.js +1 -0
  55. package/src/interface/IBlendMode.d.ts +1 -0
  56. package/src/interface/IBlendMode.js +1 -0
  57. package/src/interface/IBounds.d.ts +6 -0
  58. package/src/interface/IBounds.js +1 -0
  59. package/src/interface/ICharacter.d.ts +5 -0
  60. package/src/interface/ICharacter.js +1 -0
  61. package/src/interface/IDictionaryTag.d.ts +8 -0
  62. package/src/interface/IDictionaryTag.js +1 -0
  63. package/src/interface/IFilterArray.d.ts +2 -0
  64. package/src/interface/IFilterArray.js +1 -0
  65. package/src/interface/IGrid.d.ts +6 -0
  66. package/src/interface/IGrid.js +1 -0
  67. package/src/interface/ILoopConfig.d.ts +8 -0
  68. package/src/interface/ILoopConfig.js +1 -0
  69. package/src/interface/ILoopType.d.ts +1 -0
  70. package/src/interface/ILoopType.js +1 -0
  71. package/src/interface/IMovieClipActionObject.d.ts +5 -0
  72. package/src/interface/IMovieClipActionObject.js +1 -0
  73. package/src/interface/IMovieClipCharacter.d.ts +17 -0
  74. package/src/interface/IMovieClipCharacter.js +1 -0
  75. package/src/interface/IMovieClipLabelObject.d.ts +4 -0
  76. package/src/interface/IMovieClipLabelObject.js +1 -0
  77. package/src/interface/IMovieClipSoundObject.d.ts +5 -0
  78. package/src/interface/IMovieClipSoundObject.js +1 -0
  79. package/src/interface/IPlaceObject.d.ts +14 -0
  80. package/src/interface/IPlaceObject.js +1 -0
  81. package/src/interface/IShapeCharacter.d.ts +14 -0
  82. package/src/interface/IShapeCharacter.js +1 -0
  83. package/src/interface/ISoundCharacter.d.ts +4 -0
  84. package/src/interface/ISoundCharacter.js +1 -0
  85. package/src/interface/ISoundTag.d.ts +6 -0
  86. package/src/interface/ISoundTag.js +1 -0
  87. package/src/interface/ISurfaceFilter.d.ts +6 -0
  88. package/src/interface/ISurfaceFilter.js +1 -0
  89. package/src/interface/ITextFieldCharacter.d.ts +26 -0
  90. package/src/interface/ITextFieldCharacter.js +1 -0
  91. package/src/interface/ITextFieldType.d.ts +1 -0
  92. package/src/interface/ITextFieldType.js +1 -0
  93. package/src/interface/ITextFormatAlign.d.ts +1 -0
  94. package/src/interface/ITextFormatAlign.js +1 -0
  95. package/src/interface/IURLLoaderDataFormat.d.ts +1 -0
  96. package/src/interface/IURLLoaderDataFormat.js +1 -0
  97. package/src/interface/IURLRequestHeader.d.ts +4 -0
  98. package/src/interface/IURLRequestHeader.js +1 -0
  99. package/src/interface/IURLRequestMethod.d.ts +1 -0
  100. package/src/interface/IURLRequestMethod.js +1 -0
  101. package/src/interface/IVideoCharacter.d.ts +11 -0
  102. package/src/interface/IVideoCharacter.js +1 -0
  103. package/dist/Sound.d.ts +0 -206
  104. package/dist/Sound.js +0 -501
  105. package/dist/SoundMixer.d.ts +0 -68
  106. package/dist/SoundMixer.js +0 -114
  107. package/dist/SoundTransform.d.ts +0 -80
  108. package/dist/SoundTransform.js +0 -111
  109. package/dist/Video.d.ts +0 -328
  110. package/dist/Video.js +0 -897
package/dist/Video.js DELETED
@@ -1,897 +0,0 @@
1
- import { SoundMixer } from "./SoundMixer";
2
- import { DisplayObject } from "@next2d/display";
3
- import { VideoEvent } from "@next2d/events";
4
- import { $document, $audioContext, $currentPlayer, $isTouch, $rendererWorker } from "@next2d/util";
5
- import { $Math, $cancelAnimationFrame, $requestAnimationFrame, $getBoundsObject, $boundsMatrix, $clamp, $multiplicationMatrix, $poolFloat32Array6, $MATRIX_ARRAY_IDENTITY, $OffscreenCanvas, $multiplicationColor, $poolFloat32Array8, $Infinity, $poolBoundsObject, $getArray, $Number, $poolArray, $cacheStore, $getFloat32Array6 } from "@next2d/share";
6
- /**
7
- * サーバーまたはローカルに保存された録画済みビデオファイルを再生する Video オブジェクトです。
8
- * ビデオストリームを再生するには、attachNetStream() を使用して、ビデオを Video オブジェクトに関連付けます。
9
- * 次に、addChild() を使用して、Video オブジェクトを表示リストに追加します。
10
- *
11
- * A Video object that plays a recorded video file stored on a server or locally.
12
- * To play a video stream, use attachNetStream() to attach the video to the Video object.
13
- * Then, add the Video object to the display list using addChild().
14
- *
15
- * @class
16
- * @memberOf next2d.media
17
- * @extends DisplayObject
18
- */
19
- export class Video extends DisplayObject {
20
- /**
21
- * @param {number} [width = 0]
22
- * @param {number} [height = 0]
23
- *
24
- * @constructor
25
- * @public
26
- */
27
- constructor(width = 0, height = 0) {
28
- super();
29
- /**
30
- * @type {boolean}
31
- * @default true
32
- * @private
33
- */
34
- this._$smoothing = true;
35
- /**
36
- * @type {boolean}
37
- * @default false
38
- * @private
39
- */
40
- this._$loop = false;
41
- /**
42
- * @type {boolean}
43
- * @default true
44
- * @private
45
- */
46
- this._$autoPlay = true;
47
- /**
48
- * @type {object}
49
- * @private
50
- */
51
- this._$bounds = $getBoundsObject(0, width, 0, height);
52
- /**
53
- * @type {number}
54
- * @default 0
55
- * @private
56
- */
57
- this._$bytesLoaded = 0;
58
- /**
59
- * @type {number}
60
- * @default 0
61
- * @private
62
- */
63
- this._$bytesTotal = 0;
64
- /**
65
- * @type {number}
66
- * @default -1
67
- * @private
68
- */
69
- this._$timerId = -1;
70
- /**
71
- * @type {HTMLVideoElement}
72
- * @default null
73
- * @private
74
- */
75
- this._$video = null;
76
- /**
77
- * @type {boolean}
78
- * @default true
79
- * @private
80
- */
81
- this._$stop = true;
82
- /**
83
- * @type {boolean}
84
- * @default false
85
- * @private
86
- */
87
- this._$ready = false;
88
- /**
89
- * @type {number}
90
- * @default 1
91
- * @private
92
- */
93
- this._$volume = 1;
94
- /**
95
- * @type {CanvasRenderingContext2D}
96
- * @default null
97
- * @private
98
- */
99
- this._$context = null;
100
- /**
101
- * @type {array}
102
- * @private
103
- */
104
- this._$cacheKeys = $getArray();
105
- /**
106
- * @type {array}
107
- * @private
108
- */
109
- this._$cacheParams = $getArray(0, 0, 0);
110
- }
111
- /**
112
- * @description 指定されたクラスのストリングを返します。
113
- * Returns the string representation of the specified class.
114
- *
115
- * @return {string}
116
- * @default [class Video]
117
- * @method
118
- * @static
119
- */
120
- static toString() {
121
- return "[class Video]";
122
- }
123
- /**
124
- * @description 指定されたクラスの空間名を返します。
125
- * Returns the space name of the specified class.
126
- *
127
- * @return {string}
128
- * @default next2d.media.Video
129
- * @const
130
- * @static
131
- */
132
- static get namespace() {
133
- return "next2d.media.Video";
134
- }
135
- /**
136
- * @description 指定されたオブジェクトのストリングを返します。
137
- * Returns the string representation of the specified object.
138
- *
139
- * @return {string}
140
- * @default [object Video]
141
- * @method
142
- * @public
143
- */
144
- toString() {
145
- return "[object Video]";
146
- }
147
- /**
148
- * @description 指定されたオブジェクトの空間名を返します。
149
- * Returns the space name of the specified object.
150
- *
151
- * @return {string}
152
- * @default next2d.media.Video
153
- * @const
154
- * @public
155
- */
156
- get namespace() {
157
- return "next2d.media.Video";
158
- }
159
- /**
160
- * @description 既にアプリケーションにロードされているデータのバイト数です。
161
- * The number of bytes of data that have been loaded into the application.
162
- *
163
- * @member {number}
164
- * @default 0
165
- * @readonly
166
- * @public
167
- */
168
- get bytesLoaded() {
169
- return this._$bytesLoaded;
170
- }
171
- /**
172
- * @description アプリケーションにロードされるファイルの総バイト数。
173
- * The total size in bytes of the file being loaded into the application.
174
- *
175
- * @member {number}
176
- * @default 0
177
- * @readonly
178
- * @public
179
- */
180
- get bytesTotal() {
181
- return this._$bytesTotal;
182
- }
183
- /**
184
- * @description 現在のキーフレーム
185
- * Current keyframe
186
- *
187
- *
188
- * @member {number}
189
- * @readonly
190
- * @public
191
- */
192
- get currentTime() {
193
- return this._$video ? this._$video.currentTime : 0;
194
- }
195
- /**
196
- * @description キーフレーム総数
197
- * Total number of keyframes
198
- *
199
- * @member {number}
200
- * @readonly
201
- * @public
202
- */
203
- get duration() {
204
- return this._$video ? this._$video.duration : 0;
205
- }
206
- /**
207
- * @description ビデオをループ生成するかどうかを指定します。
208
- * Specifies whether to generate a video loop.
209
- *
210
- * @member {boolean}
211
- * @default false
212
- * @public
213
- */
214
- get loop() {
215
- return this._$loop;
216
- }
217
- set loop(loop) {
218
- this._$loop = !!loop;
219
- }
220
- /**
221
- * @description ビデオの自動再生の設定。
222
- * Setting up automatic video playback.
223
- *
224
- * @member {boolean}
225
- * @default true
226
- * @public
227
- */
228
- get autoPlay() {
229
- return this._$autoPlay;
230
- }
231
- set autoPlay(auto_play) {
232
- this._$autoPlay = !!auto_play;
233
- }
234
- /**
235
- * @description ビデオを拡大 / 縮小する際にスムージング(補間)するかどうかを指定します。
236
- * Specifies whether the video should be smoothed (interpolated)
237
- * when it is scaled.
238
- *
239
- * @member {boolean}
240
- * @default true
241
- * @public
242
- */
243
- get smoothing() {
244
- return this._$smoothing;
245
- }
246
- set smoothing(smoothing) {
247
- this._$smoothing = !!smoothing;
248
- }
249
- /**
250
- * @description 映像コンテンツへの URL を指定します。
251
- * Specifies the URL to the video content.
252
- *
253
- * @member {string}
254
- * @default ""
255
- * @public
256
- */
257
- get src() {
258
- return this._$video ? this._$video.src : "";
259
- }
260
- set src(src) {
261
- if (!this._$video) {
262
- this._$video = this._$initializeVideo();
263
- }
264
- this._$video.src = src;
265
- this._$video.load();
266
- }
267
- /**
268
- * @description ビデオストリームの高さをピクセル単位で指定する整数です。
269
- * An integer specifying the height of the video stream, in pixels.
270
- *
271
- * @member {number}
272
- * @default 320
273
- * @readonly
274
- * @public
275
- */
276
- get videoHeight() {
277
- return this._$video ? this._$video.videoHeight : this._$bounds.yMax;
278
- }
279
- /**
280
- * @description ビデオストリームの幅をピクセル単位で指定する整数です。
281
- * An integer specifying the width of the video stream, in pixels.
282
- *
283
- * @member {number}
284
- * @default 240
285
- * @readonly
286
- * @public
287
- */
288
- get videoWidth() {
289
- return this._$video ? this._$video.videoWidth : this._$bounds.xMax;
290
- }
291
- /**
292
- * @description ボリュームです。範囲は 0(無音)~ 1(フルボリューム)です。
293
- * The volume, ranging from 0 (silent) to 1 (full volume).
294
- *
295
- * @member {number}
296
- * @default 1
297
- * @public
298
- */
299
- get volume() {
300
- return this._$volume;
301
- }
302
- set volume(volume) {
303
- this._$volume = $clamp($Math.min(SoundMixer.volume, volume), 0, 1, 1);
304
- if (this._$video) {
305
- this._$video.volume = this._$volume;
306
- }
307
- }
308
- /**
309
- * @description Video オブジェクトに現在表示されているイメージ(ビデオストリームではない)をクリアします。
310
- * Clears the image currently displayed
311
- * in the Video object (not the video stream).
312
- *
313
- * @return {void}
314
- * @method
315
- * @public
316
- */
317
- clear() {
318
- if (this._$video) {
319
- this._$video.pause();
320
- }
321
- // reset
322
- this._$video = null;
323
- this._$bounds.xMax = 0;
324
- this._$bounds.yMax = 0;
325
- this._$doChanged();
326
- }
327
- /**
328
- * @description ビデオストリームの再生を一時停止します。
329
- * Pauses playback of a video stream.
330
- *
331
- * @return {void}
332
- * @method
333
- * @public
334
- */
335
- pause() {
336
- if (this._$video && !this._$stop) {
337
- this._$stop = true;
338
- this._$video.pause();
339
- $cancelAnimationFrame(this._$timerId);
340
- this._$timerId = -1;
341
- if (this.hasEventListener(VideoEvent.PAUSE)) {
342
- this.dispatchEvent(new VideoEvent(VideoEvent.PAUSE, false, false, this._$bytesLoaded, this._$bytesTotal));
343
- }
344
- const player = $currentPlayer();
345
- player._$videos.splice(player._$videos.indexOf(this), 1);
346
- }
347
- }
348
- /**
349
- * @description ローカルディレクトリまたは Web サーバーからメディアファイルを再生します。
350
- * Plays a media file from a local directory or a web server;
351
- *
352
- * @returns {void}
353
- * @method
354
- * @public
355
- */
356
- play() {
357
- if (this._$video && this._$stop) {
358
- this._$stop = false;
359
- this._$video.volume = $Math.min(this._$volume, SoundMixer.volume);
360
- this
361
- ._$video
362
- .play()
363
- .then(() => {
364
- this._$timerId = $requestAnimationFrame(() => {
365
- this._$update();
366
- });
367
- if (this.hasEventListener(VideoEvent.PLAY)) {
368
- this.dispatchEvent(new VideoEvent(VideoEvent.PLAY, false, false, this._$bytesLoaded, this._$bytesTotal));
369
- }
370
- const player = $currentPlayer();
371
- if (player._$videos.indexOf(this) === -1) {
372
- player._$videos.push(this);
373
- }
374
- this._$ready = true;
375
- });
376
- }
377
- }
378
- /**
379
- * @description 指定された位置に最も近いキーフレームをシークします。
380
- * Seeks the keyframe closest to the specified location.
381
- *
382
- * @param {number} offset
383
- * @return {void}
384
- * @method
385
- * @public
386
- */
387
- seek(offset) {
388
- if (this._$video) {
389
- this._$video.currentTime = offset;
390
- if (this.hasEventListener(VideoEvent.SEEK)) {
391
- this.dispatchEvent(new VideoEvent(VideoEvent.SEEK, false, false, this._$bytesLoaded, this._$bytesTotal));
392
- }
393
- }
394
- }
395
- /**
396
- * @return {void}
397
- * @method
398
- * @private
399
- */
400
- _$update() {
401
- const player = $currentPlayer();
402
- if (!this.stage || !this._$video) {
403
- if (this._$video) {
404
- this._$video.pause();
405
- }
406
- $cancelAnimationFrame(this._$timerId);
407
- this._$timerId = -1;
408
- player._$videos.splice(player._$videos.indexOf(this), 1);
409
- return;
410
- }
411
- if ($rendererWorker) {
412
- this._$postProperty();
413
- }
414
- // update
415
- this._$bytesLoaded = this._$video.currentTime;
416
- if (this._$video.currentTime) {
417
- if (this.hasEventListener(VideoEvent.PROGRESS)) {
418
- this.dispatchEvent(new VideoEvent(VideoEvent.PROGRESS, false, false, this._$bytesLoaded, this._$bytesTotal));
419
- }
420
- this._$doChanged();
421
- }
422
- this._$timerId = $requestAnimationFrame(() => {
423
- this._$update();
424
- });
425
- }
426
- /**
427
- * @return {void}
428
- * @method
429
- * @private
430
- */
431
- _$start() {
432
- if (!this._$video) {
433
- return;
434
- }
435
- this._$bounds.xMax = this._$video.videoWidth;
436
- this._$bounds.yMax = this._$video.videoHeight;
437
- this._$bytesTotal = this._$video.duration;
438
- const player = $currentPlayer();
439
- if (this._$autoPlay) {
440
- this._$stop = false;
441
- this
442
- ._$video
443
- .play()
444
- .then(() => {
445
- if (player._$videos.indexOf(this) === -1) {
446
- player._$videos.push(this);
447
- }
448
- if (this.hasEventListener(VideoEvent.PLAY_START)) {
449
- this.dispatchEvent(new VideoEvent(VideoEvent.PLAY_START, false, false, this._$bytesLoaded, this._$bytesTotal));
450
- }
451
- this._$timerId = $requestAnimationFrame(() => {
452
- this._$update();
453
- });
454
- this._$ready = true;
455
- this._$doChanged();
456
- });
457
- }
458
- this._$createContext();
459
- }
460
- /**
461
- * @return {HTMLVideoElement}
462
- * @method
463
- * @private
464
- */
465
- _$initializeVideo() {
466
- // clear cache key
467
- this._$cacheKeys.length = 0;
468
- const video = $document.createElement("video");
469
- video.autoplay = false;
470
- video.crossOrigin = "anonymous";
471
- if (!$audioContext) {
472
- video.muted = true;
473
- }
474
- if ($isTouch) {
475
- video.setAttribute("playsinline", "");
476
- }
477
- video.addEventListener("canplaythrough", () => {
478
- this._$start();
479
- });
480
- video.addEventListener("ended", () => {
481
- if (this._$loop) {
482
- video.currentTime = 0;
483
- return;
484
- }
485
- if (this.hasEventListener(VideoEvent.PLAY_END)) {
486
- this.dispatchEvent(new VideoEvent(VideoEvent.PLAY_END, false, false, this._$bytesLoaded, this._$bytesTotal));
487
- }
488
- $cancelAnimationFrame(this._$timerId);
489
- this._$timerId = -1;
490
- });
491
- return video;
492
- }
493
- /**
494
- * @return {void}
495
- * @method
496
- * @private
497
- */
498
- _$createContext() {
499
- if ($rendererWorker) {
500
- const canvas = new $OffscreenCanvas(this._$bounds.xMax, this._$bounds.yMax);
501
- this._$context = canvas.getContext("2d");
502
- }
503
- }
504
- /**
505
- * @param {object} character
506
- * @return {void}
507
- * @method
508
- * @private
509
- */
510
- _$buildCharacter(character) {
511
- if (character.buffer && !character._$buffer) {
512
- character._$buffer = new Uint8Array(character.buffer);
513
- character.buffer = null;
514
- }
515
- this._$loop = character.loop;
516
- this._$autoPlay = character.autoPlay;
517
- this._$bounds.xMin = character.bounds.xMin;
518
- this._$bounds.yMin = character.bounds.yMin;
519
- this._$bounds.xMax = character.bounds.xMax;
520
- this._$bounds.yMax = character.bounds.yMax;
521
- if (!this._$video) {
522
- this._$video = this._$initializeVideo();
523
- }
524
- this._$video.src = URL.createObjectURL(new Blob([character._$buffer], { "type": "video/mp4" }));
525
- // setup
526
- this._$video.volume = $Math.min(character.volume, SoundMixer.volume);
527
- this._$video.load();
528
- if ($rendererWorker && this._$stage) {
529
- this._$createWorkerInstance();
530
- }
531
- }
532
- /**
533
- * @param {object} character
534
- * @return {void}
535
- * @method
536
- * @private
537
- */
538
- _$sync(character) {
539
- this._$buildCharacter(character);
540
- }
541
- /**
542
- * @param {object} tag
543
- * @param {DisplayObjectContainer} parent
544
- * @return {object}
545
- * @method
546
- * @private
547
- */
548
- _$build(tag, parent) {
549
- const character = this._$baseBuild(tag, parent);
550
- this._$buildCharacter(character);
551
- return character;
552
- }
553
- /**
554
- * @param {CanvasToWebGLContext} context
555
- * @param {Float32Array} matrix
556
- * @returns {void}
557
- * @method
558
- * @private
559
- */
560
- _$clip(context, matrix) {
561
- const width = this._$bounds.xMax;
562
- const height = this._$bounds.yMax;
563
- if (!width || !height) {
564
- return;
565
- }
566
- let multiMatrix = matrix;
567
- const rawMatrix = this._$transform._$rawMatrix();
568
- if (rawMatrix[0] !== 1 || rawMatrix[1] !== 0
569
- || rawMatrix[2] !== 0 || rawMatrix[3] !== 1
570
- || rawMatrix[4] !== 0 || rawMatrix[5] !== 0) {
571
- multiMatrix = $multiplicationMatrix(matrix, rawMatrix);
572
- }
573
- context.reset();
574
- context.setTransform(multiMatrix[0], multiMatrix[1], multiMatrix[2], multiMatrix[3], multiMatrix[4], multiMatrix[5]);
575
- context.beginPath();
576
- context.moveTo(0, 0);
577
- context.lineTo(width, 0);
578
- context.lineTo(width, height);
579
- context.lineTo(0, height);
580
- context.lineTo(0, 0);
581
- context.clip();
582
- if (multiMatrix !== matrix) {
583
- $poolFloat32Array6(multiMatrix);
584
- }
585
- }
586
- /**
587
- * @param {CanvasToWebGLContext} context
588
- * @param {Float32Array} matrix
589
- * @param {Float32Array} color_transform
590
- * @return {void}
591
- * @method
592
- * @private
593
- */
594
- _$draw(context, matrix, color_transform) {
595
- if (!this._$visible || !this._$video || !this._$ready) {
596
- return;
597
- }
598
- let multiColor = color_transform;
599
- const rawColor = this._$transform._$rawColorTransform();
600
- if (rawColor[0] !== 1 || rawColor[1] !== 1
601
- || rawColor[2] !== 1 || rawColor[3] !== 1
602
- || rawColor[4] !== 0 || rawColor[5] !== 0
603
- || rawColor[6] !== 0 || rawColor[7] !== 0) {
604
- multiColor = $multiplicationColor(color_transform, rawColor);
605
- }
606
- const alpha = $clamp(multiColor[3] + multiColor[7] / 255, 0, 1, 0);
607
- if (!alpha) {
608
- if (multiColor !== color_transform) {
609
- $poolFloat32Array8(multiColor);
610
- }
611
- return;
612
- }
613
- let multiMatrix = matrix;
614
- const rawMatrix = this._$transform._$rawMatrix();
615
- if (rawMatrix[0] !== 1 || rawMatrix[1] !== 0
616
- || rawMatrix[2] !== 0 || rawMatrix[3] !== 1
617
- || rawMatrix[4] !== 0 || rawMatrix[5] !== 0) {
618
- multiMatrix = $multiplicationMatrix(matrix, rawMatrix);
619
- }
620
- // default bounds
621
- const bounds = $boundsMatrix(this._$bounds, multiMatrix);
622
- const xMax = +bounds.xMax;
623
- const xMin = +bounds.xMin;
624
- const yMax = +bounds.yMax;
625
- const yMin = +bounds.yMin;
626
- $poolBoundsObject(bounds);
627
- const width = $Math.ceil($Math.abs(xMax - xMin));
628
- const height = $Math.ceil($Math.abs(yMax - yMin));
629
- switch (true) {
630
- case width === 0:
631
- case height === 0:
632
- case width === -$Infinity:
633
- case height === -$Infinity:
634
- case width === $Infinity:
635
- case height === $Infinity:
636
- return;
637
- default:
638
- break;
639
- }
640
- let xScale = +$Math.sqrt(multiMatrix[0] * multiMatrix[0]
641
- + multiMatrix[1] * multiMatrix[1]);
642
- if (!$Number.isInteger(xScale)) {
643
- const value = xScale.toString();
644
- const index = value.indexOf("e");
645
- if (index !== -1) {
646
- xScale = +value.slice(0, index);
647
- }
648
- xScale = +xScale.toFixed(4);
649
- }
650
- let yScale = +$Math.sqrt(multiMatrix[2] * multiMatrix[2]
651
- + multiMatrix[3] * multiMatrix[3]);
652
- if (!$Number.isInteger(yScale)) {
653
- const value = yScale.toString();
654
- const index = value.indexOf("e");
655
- if (index !== -1) {
656
- yScale = +value.slice(0, index);
657
- }
658
- yScale = +yScale.toFixed(4);
659
- }
660
- const filters = this._$filters || this.filters;
661
- const canApply = filters && filters.length > 0 && this._$canApply(filters);
662
- let filterBounds = $getBoundsObject(0, width, 0, height);
663
- if (canApply) {
664
- for (let idx = 0; idx < filters.length; ++idx) {
665
- filterBounds = filters[idx]
666
- ._$generateFilterRect(filterBounds, xScale, yScale);
667
- }
668
- }
669
- // cache current buffer
670
- const manager = context.frameBuffer;
671
- const currentAttachment = manager.currentAttachment;
672
- if (!currentAttachment
673
- || xMin - filterBounds.xMin > currentAttachment.width
674
- || yMin - filterBounds.yMin > currentAttachment.height) {
675
- $poolBoundsObject(filterBounds);
676
- return;
677
- }
678
- if (0 > xMin + filterBounds.xMax || 0 > yMin + filterBounds.yMax) {
679
- $poolBoundsObject(filterBounds);
680
- return;
681
- }
682
- $poolBoundsObject(filterBounds);
683
- if (!this._$cacheKeys.length
684
- || this._$cacheParams[0] !== xScale
685
- || this._$cacheParams[1] !== yScale
686
- || this._$cacheParams[2] !== color_transform[7]) {
687
- const keys = $getArray();
688
- keys[0] = xScale;
689
- keys[1] = yScale;
690
- this._$cacheKeys = $cacheStore.generateKeys(this._$instanceId, keys, color_transform);
691
- $poolArray(keys);
692
- this._$cacheParams[0] = xScale;
693
- this._$cacheParams[1] = yScale;
694
- this._$cacheParams[2] = color_transform[7];
695
- }
696
- const blendMode = this._$blendMode || this.blendMode;
697
- context.cachePosition = $cacheStore.get(this._$cacheKeys);
698
- if (!context.cachePosition) {
699
- const width = $Math.ceil($Math.abs(this._$bounds.xMax - this._$bounds.xMin));
700
- const height = $Math.ceil($Math.abs(this._$bounds.yMax - this._$bounds.yMin));
701
- const position = manager
702
- .createCachePosition(width, height);
703
- context.cachePosition = position;
704
- $cacheStore.set(this._$cacheKeys, position);
705
- }
706
- const texture = manager.createTextureFromVideo(this._$video, this._$smoothing);
707
- let offsetX = 0;
708
- let offsetY = 0;
709
- if (canApply) {
710
- const currentAttachment = manager.currentAttachment;
711
- const attachment = manager
712
- .createCacheAttachment(width, height);
713
- context._$bind(attachment);
714
- context.reset();
715
- const parentMatrix = $getFloat32Array6(xScale, 0, 0, yScale, width / 2, height / 2);
716
- const baseMatrix = $getFloat32Array6(1, 0, 0, 1, -texture.width / 2, -texture.height / 2);
717
- const scaleMatrix = $multiplicationMatrix(parentMatrix, baseMatrix);
718
- $poolFloat32Array6(parentMatrix);
719
- $poolFloat32Array6(baseMatrix);
720
- context.setTransform(scaleMatrix[0], scaleMatrix[1], scaleMatrix[2], scaleMatrix[3], scaleMatrix[4], scaleMatrix[5]);
721
- context.drawImage(texture, 0, 0, texture.width, texture.height);
722
- const videoTexture = manager.getTextureFromCurrentAttachment();
723
- context._$bind(currentAttachment);
724
- manager.releaseAttachment(attachment);
725
- // release
726
- context.drawTextureFromRect(texture, context.cachePosition);
727
- const position = this._$drawFilter(context, multiMatrix, filters, width, height, videoTexture);
728
- if (position.offsetX) {
729
- offsetX = position.offsetX;
730
- }
731
- if (position.offsetY) {
732
- offsetY = position.offsetY;
733
- }
734
- // update
735
- context.cachePosition = position;
736
- context.setTransform(1, 0, 0, 1, xMin - offsetX, yMin - offsetY);
737
- }
738
- else {
739
- context.drawTextureFromRect(texture, context.cachePosition);
740
- context.setTransform(multiMatrix[0], multiMatrix[1], multiMatrix[2], multiMatrix[3], multiMatrix[4], multiMatrix[5]);
741
- }
742
- // draw
743
- if (context.cachePosition) {
744
- context.globalAlpha = alpha;
745
- context.imageSmoothingEnabled = true;
746
- context.globalCompositeOperation = blendMode;
747
- context.drawInstance(xMin - offsetX, yMin - offsetY, xMax, yMax, color_transform);
748
- // cache position clear
749
- context.cachePosition = null;
750
- }
751
- // pool
752
- if (multiMatrix !== matrix) {
753
- $poolFloat32Array6(multiMatrix);
754
- }
755
- if (multiColor !== color_transform) {
756
- $poolFloat32Array8(multiColor);
757
- }
758
- }
759
- /**
760
- * @param {CanvasRenderingContext2D} context
761
- * @param {Float32Array} matrix
762
- * @param {object} options
763
- * @return {boolean}
764
- * @method
765
- * @private
766
- */
767
- _$mouseHit(context, matrix, options) {
768
- if (!this._$visible) {
769
- return false;
770
- }
771
- return this._$hit(context, matrix, options);
772
- }
773
- /**
774
- * @param {CanvasRenderingContext2D} context
775
- * @param {array} matrix
776
- * @param {object} options
777
- * @return {boolean}
778
- * @method
779
- * @private
780
- */
781
- _$hit(context, matrix, options) {
782
- let multiMatrix = matrix;
783
- const rawMatrix = this._$transform._$rawMatrix();
784
- if (rawMatrix !== $MATRIX_ARRAY_IDENTITY) {
785
- multiMatrix = $multiplicationMatrix(matrix, rawMatrix);
786
- }
787
- const baseBounds = this._$getBounds(null);
788
- const bounds = $boundsMatrix(baseBounds, multiMatrix);
789
- const xMax = +bounds.xMax;
790
- const xMin = +bounds.xMin;
791
- const yMax = +bounds.yMax;
792
- const yMin = +bounds.yMin;
793
- $poolBoundsObject(bounds);
794
- $poolBoundsObject(baseBounds);
795
- const width = $Math.ceil($Math.abs(xMax - xMin));
796
- const height = $Math.ceil($Math.abs(yMax - yMin));
797
- context.setTransform(1, 0, 0, 1, xMin, yMin);
798
- context.beginPath();
799
- context.moveTo(0, 0);
800
- context.lineTo(width, 0);
801
- context.lineTo(width, height);
802
- context.lineTo(0, height);
803
- context.lineTo(0, 0);
804
- if (multiMatrix !== matrix) {
805
- $poolFloat32Array6(multiMatrix);
806
- }
807
- return context.isPointInPath(options.x, options.y);
808
- }
809
- /**
810
- * @param {Float32Array} [matrix=null]
811
- * @return {object}
812
- * @method
813
- * @private
814
- */
815
- _$getBounds(matrix = null) {
816
- if (matrix) {
817
- let multiMatrix = matrix;
818
- const rawMatrix = this._$transform._$rawMatrix();
819
- if (rawMatrix[0] !== 1 || rawMatrix[1] !== 0
820
- || rawMatrix[2] !== 0 || rawMatrix[3] !== 1
821
- || rawMatrix[4] !== 0 || rawMatrix[5] !== 0) {
822
- multiMatrix = $multiplicationMatrix(matrix, rawMatrix);
823
- }
824
- const bounds = $boundsMatrix(this._$bounds, multiMatrix);
825
- if (multiMatrix !== matrix) {
826
- $poolFloat32Array6(multiMatrix);
827
- }
828
- return bounds;
829
- }
830
- return $getBoundsObject(this._$bounds.xMin, this._$bounds.xMax, this._$bounds.yMin, this._$bounds.yMax);
831
- }
832
- /**
833
- * @return {void}
834
- * @method
835
- * @private
836
- */
837
- _$createWorkerInstance() {
838
- if (!$rendererWorker || this._$created) {
839
- return;
840
- }
841
- this._$created = true;
842
- const message = {
843
- "command": "createVideo",
844
- "buffer": new Float32Array(),
845
- "instanceId": this._$instanceId,
846
- "parentId": this._$parent ? this._$parent._$instanceId : -1,
847
- "smoothing": this._$smoothing,
848
- "xMin": this._$bounds.xMin,
849
- "yMin": this._$bounds.yMin,
850
- "xMax": this._$bounds.xMax,
851
- "yMax": this._$bounds.yMax
852
- };
853
- if (this._$characterId > -1) {
854
- message.characterId = this._$characterId;
855
- }
856
- if (this._$loaderInfo) {
857
- message.loaderInfoId = this._$loaderInfo._$id;
858
- }
859
- if (this._$scale9Grid) {
860
- message.grid = {
861
- "x": this._$scale9Grid.x,
862
- "y": this._$scale9Grid.y,
863
- "w": this._$scale9Grid.width,
864
- "h": this._$scale9Grid.height
865
- };
866
- }
867
- $rendererWorker.postMessage(message);
868
- }
869
- /**
870
- * @return {void}
871
- * @method
872
- * @private
873
- */
874
- _$postProperty() {
875
- if (!$rendererWorker) {
876
- return;
877
- }
878
- const message = this._$createMessage();
879
- message.smoothing = this._$smoothing;
880
- const options = $getArray();
881
- const context = this._$context;
882
- if (context && this._$video) {
883
- message.xMin = this._$bounds.xMin;
884
- message.yMin = this._$bounds.yMin;
885
- message.xMax = this._$bounds.xMax;
886
- message.yMax = this._$bounds.yMax;
887
- context.drawImage(this._$video, 0, 0);
888
- const imageBitmap = context.canvas.transferToImageBitmap();
889
- message.imageBitmap = imageBitmap;
890
- options.push(imageBitmap);
891
- }
892
- $rendererWorker.postMessage(message, options);
893
- $poolArray(options);
894
- this._$posted = true;
895
- this._$updated = false;
896
- }
897
- }