@next2d/display 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/Loader.js ADDED
@@ -0,0 +1,318 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { DisplayObjectContainer } from "./DisplayObjectContainer";
11
+ import { LoaderInfo } from "./LoaderInfo";
12
+ import { MovieClip } from "./MovieClip";
13
+ import { $getMap } from "@next2d/share";
14
+ import { IOErrorEvent, Event, ProgressEvent as Next2DProgressEvent, HTTPStatusEvent } from "@next2d/events";
15
+ import { $ajax, $headerToArray, $unzipQueues, $updateUnzipWorkerStatus, $getUnzipWorker, $currentPlayer, $useUnzipWorker } from "@next2d/util";
16
+ /**
17
+ * Loader クラスは、JSON ファイルまたはイメージ(JPEG、PNG、または GIF)ファイルを読み込むために使用します。
18
+ * 読み込みを開始するには load() メソッドを使用します。
19
+ * 読み込まれた表示オブジェクトは Loader オブジェクトの子として追加されます。
20
+ *
21
+ * The Loader class is used to load JSON files or image (JPEG, PNG, or GIF) files.
22
+ * Use the load() method to initiate loading.
23
+ * The loaded display object is added as a child of the Loader object.
24
+ *
25
+ * @class
26
+ * @memberOf next2d.display
27
+ * @extends DisplayObjectContainer
28
+ */
29
+ export class Loader extends DisplayObjectContainer {
30
+ /**
31
+ * @constructor
32
+ * @public
33
+ */
34
+ constructor() {
35
+ super();
36
+ /**
37
+ * @type {LoaderInfo}
38
+ * @private
39
+ */
40
+ this._$loaderInfo = new LoaderInfo();
41
+ }
42
+ /**
43
+ * @description 指定されたクラスのストリングを返します。
44
+ * Returns the string representation of the specified class.
45
+ *
46
+ * @return {string}
47
+ * @default [class Loader]
48
+ * @method
49
+ * @static
50
+ */
51
+ static toString() {
52
+ return "[class Loader]";
53
+ }
54
+ /**
55
+ * @description 指定されたクラスの空間名を返します。
56
+ * Returns the space name of the specified class.
57
+ *
58
+ * @return {string}
59
+ * @default next2d.display.Loader
60
+ * @const
61
+ * @static
62
+ */
63
+ static get namespace() {
64
+ return "next2d.display.Loader";
65
+ }
66
+ /**
67
+ * @description 指定されたオブジェクトのストリングを返します。
68
+ * Returns the string representation of the specified object.
69
+ *
70
+ * @return {string}
71
+ * @default [object Loader]
72
+ * @method
73
+ * @public
74
+ */
75
+ toString() {
76
+ return "[object Loader]";
77
+ }
78
+ /**
79
+ * @description 指定されたオブジェクトの空間名を返します。
80
+ * Returns the space name of the specified object.
81
+ *
82
+ * @return {string}
83
+ * @default next2d.display.Loader
84
+ * @const
85
+ * @public
86
+ */
87
+ get namespace() {
88
+ return "next2d.display.Loader";
89
+ }
90
+ /**
91
+ * @description load メソッドを使用して読み込まれた JSON のルート表示オブジェクトが含まれます。
92
+ * It contains a JSON root display object loaded using the load method.
93
+ *
94
+ * @member {MovieClip | Sprite | null}
95
+ * @readonly
96
+ * @public
97
+ */
98
+ get content() {
99
+ return this._$loaderInfo ? this._$loaderInfo.content : null;
100
+ }
101
+ /**
102
+ * @description 読み込まれているオブジェクトに対応する LoaderInfo オブジェクトを返します。
103
+ * Returns a LoaderInfo object corresponding to the object being loaded.
104
+ *
105
+ * @member {LoaderInfo}
106
+ * @readonly
107
+ * @public
108
+ */
109
+ get contentLoaderInfo() {
110
+ return this._$loaderInfo;
111
+ }
112
+ /**
113
+ * @description JSONファイルを、この Loader オブジェクトの子であるcontentプロパティにロードします。
114
+ * JPEG、GIF、PNGなどの画像データは loadImage で同様にcontentプロパティにロードします。
115
+ * Load the JSON file into the content property, which is a child of this Loader object.
116
+ * Image data such as JPEG, GIF, PNG, etc.
117
+ * are loaded into the content property in the same way with loadImage.
118
+ *
119
+ * @param {URLRequest} request
120
+ * @returns {void}
121
+ * @method
122
+ * @public
123
+ */
124
+ load(request) {
125
+ const loaderInfo = this._$loaderInfo;
126
+ if (!loaderInfo) {
127
+ return;
128
+ }
129
+ loaderInfo.url = request.url;
130
+ loaderInfo.format = request.responseDataFormat;
131
+ $ajax({
132
+ "format": request.responseDataFormat,
133
+ "url": request.url,
134
+ "method": request.method,
135
+ "data": request.data,
136
+ "headers": request.headers,
137
+ "withCredentials": request.withCredentials,
138
+ "event": {
139
+ "loadstart": (event) => {
140
+ this._$loadstart(event);
141
+ },
142
+ "progress": (event) => {
143
+ this._$progress(event);
144
+ },
145
+ "loadend": (event) => {
146
+ this._$loadend(event);
147
+ }
148
+ }
149
+ });
150
+ }
151
+ /**
152
+ * @param {ProgressEvent} event
153
+ * @return {void}
154
+ * @method
155
+ * @private
156
+ */
157
+ _$loadend(event) {
158
+ const loaderInfo = this._$loaderInfo;
159
+ if (!loaderInfo) {
160
+ return;
161
+ }
162
+ // set
163
+ loaderInfo.bytesLoaded = event.loaded;
164
+ loaderInfo.bytesTotal = event.total;
165
+ // progress event
166
+ if (loaderInfo.willTrigger(Next2DProgressEvent.PROGRESS)) {
167
+ loaderInfo.dispatchEvent(new Next2DProgressEvent(Next2DProgressEvent.PROGRESS, false, false, event.loaded, event.total));
168
+ }
169
+ const target = event.target;
170
+ // http status event
171
+ if (loaderInfo.willTrigger(HTTPStatusEvent.HTTP_STATUS)) {
172
+ const responseHeaders = $headerToArray(target.getAllResponseHeaders());
173
+ loaderInfo.dispatchEvent(new HTTPStatusEvent(HTTPStatusEvent.HTTP_STATUS, false, false, target.status, target.responseURL, responseHeaders));
174
+ }
175
+ if (199 < target.status && 400 > target.status) {
176
+ if (loaderInfo.format === "json") {
177
+ const json = target.response;
178
+ if (json.type === "zlib") {
179
+ if ($useUnzipWorker()) {
180
+ $unzipQueues.push({
181
+ "json": json,
182
+ "scope": this
183
+ });
184
+ return;
185
+ }
186
+ $updateUnzipWorkerStatus(true);
187
+ const unzipWorker = $getUnzipWorker();
188
+ const buffer = new Uint8Array(json.buffer);
189
+ unzipWorker.onmessage = (event) => __awaiter(this, void 0, void 0, function* () {
190
+ this._$unzipHandler(event);
191
+ });
192
+ unzipWorker.postMessage(buffer, [buffer.buffer]);
193
+ }
194
+ else {
195
+ this._$build(json);
196
+ }
197
+ }
198
+ else {
199
+ throw new Error("LoaderInfo format is `json`");
200
+ }
201
+ }
202
+ else {
203
+ if (loaderInfo.willTrigger(IOErrorEvent.IO_ERROR)) {
204
+ loaderInfo.dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, target.statusText));
205
+ }
206
+ }
207
+ }
208
+ /**
209
+ * @param {MessageEvent} event
210
+ * @return {void}
211
+ * @method
212
+ * @private
213
+ */
214
+ _$unzipHandler(event) {
215
+ this._$build(event.data);
216
+ if ($unzipQueues.length) {
217
+ const object = $unzipQueues.pop();
218
+ if (!object) {
219
+ return;
220
+ }
221
+ const buffer = new Uint8Array(object.json.buffer);
222
+ const unzipWorker = $getUnzipWorker();
223
+ unzipWorker.onmessage = (event) => {
224
+ object.scope._$unzipHandler(event);
225
+ };
226
+ unzipWorker.postMessage(buffer, [buffer.buffer]);
227
+ }
228
+ else {
229
+ $updateUnzipWorkerStatus(false);
230
+ }
231
+ }
232
+ /**
233
+ * @param {ProgressEvent} event
234
+ * @return {void}
235
+ * @method
236
+ * @private
237
+ */
238
+ _$loadstart(event) {
239
+ const loaderInfo = this._$loaderInfo;
240
+ if (!loaderInfo) {
241
+ return;
242
+ }
243
+ loaderInfo.bytesLoaded = event.loaded;
244
+ loaderInfo.bytesTotal = event.total;
245
+ if (loaderInfo.willTrigger(Event.OPEN)) {
246
+ loaderInfo.dispatchEvent(new Event(Event.OPEN));
247
+ }
248
+ if (loaderInfo.willTrigger(Next2DProgressEvent.PROGRESS)) {
249
+ loaderInfo.dispatchEvent(new Next2DProgressEvent(Next2DProgressEvent.PROGRESS, false, false, event.loaded, event.total));
250
+ }
251
+ }
252
+ /**
253
+ * @param {ProgressEvent} event
254
+ * @return {void}
255
+ * @method
256
+ * @private
257
+ */
258
+ _$progress(event) {
259
+ const loaderInfo = this._$loaderInfo;
260
+ if (!loaderInfo) {
261
+ return;
262
+ }
263
+ // set
264
+ loaderInfo.bytesLoaded = event.loaded;
265
+ loaderInfo.bytesTotal = event.total;
266
+ // progress event
267
+ if (loaderInfo.willTrigger(Next2DProgressEvent.PROGRESS)) {
268
+ loaderInfo.dispatchEvent(new Next2DProgressEvent(Next2DProgressEvent.PROGRESS, false, false, event.loaded, event.total));
269
+ }
270
+ }
271
+ /**
272
+ * @param {object} object
273
+ * @return {void}
274
+ * @method
275
+ * @private
276
+ */
277
+ _$build(object) {
278
+ const loaderInfo = this._$loaderInfo;
279
+ if (!loaderInfo) {
280
+ return;
281
+ }
282
+ const symbols = $getMap();
283
+ if (object.symbols.length) {
284
+ for (let idx = 0; idx < object.symbols.length; ++idx) {
285
+ const values = object.symbols[idx];
286
+ symbols.set(values[0], values[1]);
287
+ }
288
+ }
289
+ loaderInfo._$data = {
290
+ "stage": object.stage,
291
+ "characters": object.characters,
292
+ "symbols": symbols
293
+ };
294
+ // setup
295
+ loaderInfo._$content = new MovieClip();
296
+ // build root
297
+ const root = object.characters[0];
298
+ loaderInfo._$content._$build({
299
+ "characterId": 0,
300
+ "clipDepth": 0,
301
+ "depth": 0,
302
+ "endFrame": root.controller.length,
303
+ "startFrame": 1
304
+ }, this);
305
+ // fixed logic
306
+ loaderInfo._$content._$parent = null;
307
+ this.addChild(loaderInfo._$content);
308
+ // fixed logic
309
+ loaderInfo._$content._$added = false;
310
+ loaderInfo._$content._$addedStage = false;
311
+ // to event
312
+ const player = $currentPlayer();
313
+ player._$loaders.push(loaderInfo);
314
+ if (player._$loadStatus === 1) { // LOAD_START
315
+ player._$loadStatus = 2; // LOAD_END
316
+ }
317
+ }
318
+ }
@@ -0,0 +1,120 @@
1
+ import { EventDispatcher } from "@next2d/events";
2
+ import { URLLoaderDataFormatImpl, ParentImpl, LoaderInfoDataImpl } from "@next2d/interface";
3
+ /**
4
+ * LoaderInfo クラスは、読み込まれる JSON ファイルやイメージファイル(JPEG、GIF、PNG ファイルなど)に関する情報を提供します。
5
+ * LoaderInfo オブジェクトは、すべての表示オブジェクトで使用できます。
6
+ * 提供される情報には、読み込みの進行状況、読み込む側と読み込まれたコンテンツの URL、メディアの総バイト数、メディアの規格高さと幅などが含まれます。
7
+ *
8
+ * The LoaderInfo class provides information about a loaded JSON file or a loaded image file (JPEG, GIF, or PNG).
9
+ * LoaderInfo objects are available for any display object.
10
+ * The information provided includes load progress, the URLs of the loader and loaded content,
11
+ * the number of bytes total for the media, and the nominal height and width of the media.
12
+ *
13
+ * @class
14
+ * @memberOf next2d.display
15
+ * @extends EventDispatcher
16
+ */
17
+ export declare class LoaderInfo extends EventDispatcher {
18
+ readonly _$id: number;
19
+ _$content: ParentImpl<any> | null;
20
+ _$data: LoaderInfoDataImpl | null;
21
+ private _$bytesLoaded;
22
+ private _$bytesTotal;
23
+ private _$url;
24
+ private _$format;
25
+ /**
26
+ * @constructor
27
+ * @public
28
+ */
29
+ constructor();
30
+ /**
31
+ * @description 指定されたクラスのストリングを返します。
32
+ * Returns the string representation of the specified class.
33
+ *
34
+ * @return {string}
35
+ * @default [class LoaderInfo]
36
+ * @method
37
+ * @static
38
+ */
39
+ static toString(): string;
40
+ /**
41
+ * @description 指定されたクラスの空間名を返します。
42
+ * Returns the space name of the specified class.
43
+ *
44
+ * @return {string}
45
+ * @default next2d.display.LoaderInfo
46
+ * @const
47
+ * @static
48
+ */
49
+ static get namespace(): string;
50
+ /**
51
+ * @description 指定されたオブジェクトのストリングを返します。
52
+ * Returns the string representation of the specified object.
53
+ *
54
+ * @return {string}
55
+ * @default [object LoaderInfo]
56
+ * @method
57
+ * @public
58
+ */
59
+ toString(): string;
60
+ /**
61
+ * @description 指定されたオブジェクトの空間名を返します。
62
+ * Returns the space name of the specified object.
63
+ *
64
+ * @return {string}
65
+ * @default next2d.display.LoaderInfo
66
+ * @const
67
+ * @public
68
+ */
69
+ get namespace(): string;
70
+ /**
71
+ * @description そのメディアのロード済みのバイト数です。
72
+ * The uint of bytes that are loaded for the media.
73
+ *
74
+ * @member {number}
75
+ * @default 0
76
+ * @public
77
+ */
78
+ get bytesLoaded(): number;
79
+ set bytesLoaded(bytes_loaded: number);
80
+ /**
81
+ * @description メディアファイル全体のバイト数です。
82
+ * The number of bytes in the entire media file.
83
+ *
84
+ * @member {number}
85
+ * @default 0
86
+ * @public
87
+ */
88
+ get bytesTotal(): number;
89
+ set bytesTotal(bytes_total: number);
90
+ /**
91
+ * @description LoaderInfo オブジェクトに関係したロードされたオブジェクトです。
92
+ * The loaded object associated with this LoaderInfo object.
93
+ *
94
+ * @member {DisplayObject}
95
+ * @public
96
+ */
97
+ get content(): ParentImpl<any>;
98
+ set content(content: ParentImpl<any>);
99
+ /**
100
+ * @description 読み込まれるメディアの URL です。
101
+ * The URL of the media being loaded.
102
+ *
103
+ * @member {string}
104
+ * @default ""
105
+ * @readonly
106
+ * @public
107
+ */
108
+ get url(): string;
109
+ set url(url: string);
110
+ /**
111
+ * @description 読み込まれるメディアの データフォーマット です。
112
+ * The data format of the media being loaded.
113
+ *
114
+ * @member {string}
115
+ * @default "json"
116
+ * @public
117
+ */
118
+ get format(): URLLoaderDataFormatImpl;
119
+ set format(format: URLLoaderDataFormatImpl);
120
+ }
@@ -0,0 +1,184 @@
1
+ import { EventDispatcher } from "@next2d/events";
2
+ import { $getLoaderInfoId } from "@next2d/util";
3
+ /**
4
+ * LoaderInfo クラスは、読み込まれる JSON ファイルやイメージファイル(JPEG、GIF、PNG ファイルなど)に関する情報を提供します。
5
+ * LoaderInfo オブジェクトは、すべての表示オブジェクトで使用できます。
6
+ * 提供される情報には、読み込みの進行状況、読み込む側と読み込まれたコンテンツの URL、メディアの総バイト数、メディアの規格高さと幅などが含まれます。
7
+ *
8
+ * The LoaderInfo class provides information about a loaded JSON file or a loaded image file (JPEG, GIF, or PNG).
9
+ * LoaderInfo objects are available for any display object.
10
+ * The information provided includes load progress, the URLs of the loader and loaded content,
11
+ * the number of bytes total for the media, and the nominal height and width of the media.
12
+ *
13
+ * @class
14
+ * @memberOf next2d.display
15
+ * @extends EventDispatcher
16
+ */
17
+ export class LoaderInfo extends EventDispatcher {
18
+ /**
19
+ * @constructor
20
+ * @public
21
+ */
22
+ constructor() {
23
+ super();
24
+ /**
25
+ * @type {number}
26
+ * @private
27
+ */
28
+ this._$id = $getLoaderInfoId();
29
+ /**
30
+ * @type {number}
31
+ * @default 0
32
+ * @private
33
+ */
34
+ this._$bytesLoaded = 0;
35
+ /**
36
+ * @type {number}
37
+ * @default 0
38
+ * @private
39
+ */
40
+ this._$bytesTotal = 0;
41
+ /**
42
+ * @type {string}
43
+ * @default ""
44
+ * @private
45
+ */
46
+ this._$url = "";
47
+ /**
48
+ * @type {DisplayObject}
49
+ * @default null
50
+ * @private
51
+ */
52
+ this._$content = null;
53
+ /**
54
+ * @type {object}
55
+ * @default null
56
+ * @private
57
+ */
58
+ this._$data = null;
59
+ /**
60
+ * @type {string}
61
+ * @default "json"
62
+ * @private
63
+ */
64
+ this._$format = "json";
65
+ }
66
+ /**
67
+ * @description 指定されたクラスのストリングを返します。
68
+ * Returns the string representation of the specified class.
69
+ *
70
+ * @return {string}
71
+ * @default [class LoaderInfo]
72
+ * @method
73
+ * @static
74
+ */
75
+ static toString() {
76
+ return "[class LoaderInfo]";
77
+ }
78
+ /**
79
+ * @description 指定されたクラスの空間名を返します。
80
+ * Returns the space name of the specified class.
81
+ *
82
+ * @return {string}
83
+ * @default next2d.display.LoaderInfo
84
+ * @const
85
+ * @static
86
+ */
87
+ static get namespace() {
88
+ return "next2d.display.LoaderInfo";
89
+ }
90
+ /**
91
+ * @description 指定されたオブジェクトのストリングを返します。
92
+ * Returns the string representation of the specified object.
93
+ *
94
+ * @return {string}
95
+ * @default [object LoaderInfo]
96
+ * @method
97
+ * @public
98
+ */
99
+ toString() {
100
+ return "[object LoaderInfo]";
101
+ }
102
+ /**
103
+ * @description 指定されたオブジェクトの空間名を返します。
104
+ * Returns the space name of the specified object.
105
+ *
106
+ * @return {string}
107
+ * @default next2d.display.LoaderInfo
108
+ * @const
109
+ * @public
110
+ */
111
+ get namespace() {
112
+ return "next2d.display.LoaderInfo";
113
+ }
114
+ /**
115
+ * @description そのメディアのロード済みのバイト数です。
116
+ * The uint of bytes that are loaded for the media.
117
+ *
118
+ * @member {number}
119
+ * @default 0
120
+ * @public
121
+ */
122
+ get bytesLoaded() {
123
+ return this._$bytesLoaded;
124
+ }
125
+ set bytesLoaded(bytes_loaded) {
126
+ this._$bytesLoaded = bytes_loaded | 0;
127
+ }
128
+ /**
129
+ * @description メディアファイル全体のバイト数です。
130
+ * The number of bytes in the entire media file.
131
+ *
132
+ * @member {number}
133
+ * @default 0
134
+ * @public
135
+ */
136
+ get bytesTotal() {
137
+ return this._$bytesTotal;
138
+ }
139
+ set bytesTotal(bytes_total) {
140
+ this._$bytesTotal = bytes_total | 0;
141
+ }
142
+ /**
143
+ * @description LoaderInfo オブジェクトに関係したロードされたオブジェクトです。
144
+ * The loaded object associated with this LoaderInfo object.
145
+ *
146
+ * @member {DisplayObject}
147
+ * @public
148
+ */
149
+ get content() {
150
+ return this._$content;
151
+ }
152
+ set content(content) {
153
+ this._$content = content;
154
+ }
155
+ /**
156
+ * @description 読み込まれるメディアの URL です。
157
+ * The URL of the media being loaded.
158
+ *
159
+ * @member {string}
160
+ * @default ""
161
+ * @readonly
162
+ * @public
163
+ */
164
+ get url() {
165
+ return this._$url;
166
+ }
167
+ set url(url) {
168
+ this._$url = url;
169
+ }
170
+ /**
171
+ * @description 読み込まれるメディアの データフォーマット です。
172
+ * The data format of the media being loaded.
173
+ *
174
+ * @member {string}
175
+ * @default "json"
176
+ * @public
177
+ */
178
+ get format() {
179
+ return this._$format;
180
+ }
181
+ set format(format) {
182
+ this._$format = format;
183
+ }
184
+ }