swf2js 0.1.1 → 0.1.2
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 +9 -9
- package/package.json +2 -1
- package/src/cli.js +15 -6
- package/src/emitter/bundle-emitter.js +56 -16
- package/src/runtime/avm1-runtime.js +329 -84
- package/src/runtime/avm2-runtime.js +56 -6
- package/src/runtime/embedded-movie-runtime.js +6 -1
- package/src/runtime/index.js +2 -6
- package/src/runtime/movie-runtime.js +2 -1
- package/src/runtime/swflib/assemble.js +34 -0
- package/src/runtime/swflib/bitmap-image.js +4 -0
- package/src/runtime/swflib/bitmap.js +1004 -0
- package/src/runtime/swflib/builtins.js +156 -0
- package/src/runtime/swflib/bytearray.js +949 -0
- package/src/runtime/swflib/compiled-swf.js +3 -0
- package/src/runtime/swflib/context-menu.js +245 -0
- package/src/runtime/swflib/cursor-flag.js +12 -0
- package/src/runtime/swflib/dictionary.js +121 -0
- package/src/runtime/swflib/display.js +823 -0
- package/src/runtime/swflib/events.js +754 -0
- package/src/runtime/swflib/filters.js +298 -0
- package/src/runtime/swflib/flash.js +130 -0
- package/src/runtime/swflib/geom.js +759 -0
- package/src/runtime/swflib/glyph-metrics.js +14 -0
- package/src/runtime/swflib/graphics.js +735 -0
- package/src/runtime/swflib/host.js +2 -0
- package/src/runtime/swflib/inherit.js +22 -0
- package/src/runtime/swflib/input.js +1085 -0
- package/src/runtime/swflib/loader.js +687 -0
- package/src/runtime/swflib/marks.js +16 -0
- package/src/runtime/swflib/matrix3d.js +144 -0
- package/src/runtime/swflib/pointer-bridge.js +8 -0
- package/src/runtime/swflib/projection.js +158 -0
- package/src/runtime/swflib/render.js +1240 -0
- package/src/runtime/swflib/sound.js +1166 -0
- package/src/runtime/swflib/sprite-drag.js +116 -0
- package/src/runtime/swflib/stage-ref.js +9 -0
- package/src/runtime/swflib/stage.js +484 -0
- package/src/runtime/swflib/system.js +987 -0
- package/src/runtime/swflib/text-field.js +519 -0
- package/src/runtime/swflib/text-paint.js +797 -0
- package/src/runtime/swflib/text.js +1387 -0
- package/src/runtime/swflib/transform.js +133 -0
- package/src/runtime/swflib/xml.js +268 -0
- package/src/transpiler/avm1/avm1-ir.js +2 -1
- package/src/transpiler/avm1/avm1-rewrite.js +23 -2
- package/src/transpiler/avm1/avm1-transpiler.js +4 -1
- package/src/transpiler/avm2/avm2-transpiler.js +38 -7
- package/src/transpiler/timeline/timeline-codegen.js +366 -123
- package/src/runtime/swflib.js +0 -14050
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
import { Bitmap, BitmapData } from './bitmap.js';
|
|
2
|
+
import { ByteArray, decodeBase64Bytes } from './bytearray.js';
|
|
3
|
+
import { compiledSwfByteArrays, compiledSwfEntries } from './compiled-swf.js';
|
|
4
|
+
export { compiledSwfEntries, compiledSwfByteArrays };
|
|
5
|
+
import { DisplayObject, DisplayObjectContainer, InteractiveObject, pointPassesScrollRects } from './display.js';
|
|
6
|
+
import { Event, EventDispatcher, IOErrorEvent, ProgressEvent, unregisterEnterFrameReceiver } from './events.js';
|
|
7
|
+
import { Point, Rectangle } from './geom.js';
|
|
8
|
+
import { Sprite } from './graphics.js';
|
|
9
|
+
import { global } from './host.js';
|
|
10
|
+
import { cursorFlag } from './cursor-flag.js';
|
|
11
|
+
import { stageSingleton } from './stage.js';
|
|
12
|
+
import { ApplicationDomain, Security } from './system.js';
|
|
13
|
+
|
|
14
|
+
class LoaderInfo extends EventDispatcher {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.bytesLoaded = 0;
|
|
18
|
+
this.bytesTotal = 0;
|
|
19
|
+
this.bytes = new ByteArray();
|
|
20
|
+
this.url = (global.location && global.location.href) || 'http://localhost/swoof.swf';
|
|
21
|
+
this.loaderURL = this.url;
|
|
22
|
+
this.parameters = {};
|
|
23
|
+
this.contentType = 'application/x-shockwave-flash';
|
|
24
|
+
this.swfVersion = 9;
|
|
25
|
+
this.width = 0;
|
|
26
|
+
this.height = 0;
|
|
27
|
+
this.frameRate = 30;
|
|
28
|
+
this.content = null;
|
|
29
|
+
this.loader = null;
|
|
30
|
+
this.sharedEvents = new EventDispatcher();
|
|
31
|
+
this.applicationDomain = null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_configureRootLoad(metadata) {
|
|
35
|
+
this.width = metadata.width;
|
|
36
|
+
this.height = metadata.height;
|
|
37
|
+
this.frameRate = metadata.frameRate;
|
|
38
|
+
this.swfVersion = metadata.swfVersion || 9;
|
|
39
|
+
// Standalone bundles have metadata but do not carry the full source SWF.
|
|
40
|
+
this.bytes.clear();
|
|
41
|
+
this.bytes.writeUTFBytes('FWS');
|
|
42
|
+
this.bytes.writeByte(this.swfVersion);
|
|
43
|
+
this.bytesTotal = metadata.bytesTotal || 8;
|
|
44
|
+
for (var i = 0; i < 4; i++) this.bytes.writeByte(this.bytesTotal >>> (8 * i));
|
|
45
|
+
this.bytes.position = 0;
|
|
46
|
+
this.bytesLoaded = 0;
|
|
47
|
+
this.applicationDomain = ApplicationDomain.currentDomain;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_completeRootLoad(content) {
|
|
51
|
+
if (this._rootLoadComplete) return;
|
|
52
|
+
this._rootLoadComplete = true;
|
|
53
|
+
this.content = content || null;
|
|
54
|
+
this.bytesLoaded = this.bytesTotal;
|
|
55
|
+
this.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, this.bytesLoaded, this.bytesTotal));
|
|
56
|
+
this.dispatchEvent(new Event(Event.INIT));
|
|
57
|
+
this.dispatchEvent(new Event(Event.COMPLETE));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const LoaderInfoExport = new Proxy(LoaderInfo, {
|
|
61
|
+
apply(_target, _this, args) {
|
|
62
|
+
var value = args[0];
|
|
63
|
+
if (value == null || value instanceof LoaderInfo) return value == null ? null : value;
|
|
64
|
+
throw new TypeError('Cannot coerce value to LoaderInfo');
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
export { LoaderInfoExport as LoaderInfo };
|
|
68
|
+
|
|
69
|
+
export var embeddedSwfs = new Map();
|
|
70
|
+
export var companionSwfs = new Map();
|
|
71
|
+
|
|
72
|
+
export function isSwfBytes(bytes) {
|
|
73
|
+
return bytes && bytes.length >= 8 &&
|
|
74
|
+
(bytes[0] === 0x46 || bytes[0] === 0x43 || bytes[0] === 0x5a) &&
|
|
75
|
+
bytes[1] === 0x57 && bytes[2] === 0x53;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function embeddedSwfEntry(bytes) {
|
|
79
|
+
var candidates = embeddedSwfs.get(bytes.length) || [];
|
|
80
|
+
return candidates.find(function (entry) {
|
|
81
|
+
return entry.getBytes().every(function (value, index) { return bytes[index] === value; });
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function addEmbeddedSwfEntry(entry) {
|
|
86
|
+
var candidates = embeddedSwfs.get(entry.length);
|
|
87
|
+
if (!candidates) embeddedSwfs.set(entry.length, candidates = []);
|
|
88
|
+
candidates.push(entry);
|
|
89
|
+
return entry;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function registerCompiledSwf(base64, length, version, factory) {
|
|
93
|
+
var decoded = null;
|
|
94
|
+
var entry = {
|
|
95
|
+
length: length, version: version, factory: factory,
|
|
96
|
+
getBytes: function () {
|
|
97
|
+
if (base64 == null) throw new Error('This export omits original embedded SWF bytes');
|
|
98
|
+
if (!decoded) decoded = decodeBase64Bytes(base64);
|
|
99
|
+
return decoded;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
if (base64 != null) addEmbeddedSwfEntry(entry);
|
|
103
|
+
compiledSwfEntries.add(entry);
|
|
104
|
+
return entry;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function registerEmbeddedSwf(bytes, factory) {
|
|
108
|
+
if (!(bytes instanceof Uint8Array) || !isSwfBytes(bytes) || typeof factory !== 'function') {
|
|
109
|
+
throw new TypeError('An embedded SWF requires SWF bytes and a compiled factory');
|
|
110
|
+
}
|
|
111
|
+
if (embeddedSwfEntry(bytes)) return;
|
|
112
|
+
var ownedBytes = bytes.slice();
|
|
113
|
+
addEmbeddedSwfEntry({
|
|
114
|
+
length: ownedBytes.length, version: ownedBytes[3], factory: factory,
|
|
115
|
+
getBytes: function () { return ownedBytes; },
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function companionBaseUrl() {
|
|
120
|
+
return (global.location && global.location.href) || (global.document && global.document.baseURI) || 'http://localhost/swoof.swf';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function companionUrlKey(url) {
|
|
124
|
+
var key = new URL(url.href);
|
|
125
|
+
key.hash = key.search = '';
|
|
126
|
+
// Canonicalize percent escapes without turning encoded path separators into slashes.
|
|
127
|
+
key.pathname = key.pathname.split('/').map(function (part) {
|
|
128
|
+
return encodeURIComponent(decodeURIComponent(part));
|
|
129
|
+
}).join('/');
|
|
130
|
+
return key.href;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function registerCompanionSwf(path, entry) {
|
|
134
|
+
var url = new URL(path, companionBaseUrl());
|
|
135
|
+
companionSwfs.set(companionUrlKey(url), entry);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function paintUnavailableCompanion(ctx, canvas, progress) {
|
|
139
|
+
if (!ctx) return;
|
|
140
|
+
var hop = Math.pow(Math.sin(Math.PI * progress), 2);
|
|
141
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
142
|
+
ctx.fillStyle = 'rgba(37, 44, 54, 0.76)';
|
|
143
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
144
|
+
ctx.save();
|
|
145
|
+
ctx.translate(14, 10 - 1.7 * hop);
|
|
146
|
+
ctx.rotate(0.18 * hop * Math.sin(2 * Math.PI * progress));
|
|
147
|
+
ctx.translate(-14, -10);
|
|
148
|
+
ctx.strokeStyle = 'rgba(225, 233, 244, 0.88)';
|
|
149
|
+
ctx.lineWidth = 1;
|
|
150
|
+
ctx.strokeRect(5.5, 4.5, 17, 11);
|
|
151
|
+
ctx.beginPath();
|
|
152
|
+
ctx.moveTo(9.5, 4.5);
|
|
153
|
+
ctx.lineTo(9.5, 15.5);
|
|
154
|
+
ctx.moveTo(18.5, 4.5);
|
|
155
|
+
ctx.lineTo(18.5, 15.5);
|
|
156
|
+
ctx.moveTo(5.5, 10);
|
|
157
|
+
ctx.lineTo(9.5, 10);
|
|
158
|
+
ctx.moveTo(18.5, 10);
|
|
159
|
+
ctx.lineTo(22.5, 10);
|
|
160
|
+
ctx.stroke();
|
|
161
|
+
|
|
162
|
+
var wink = Math.max(0, 1 - Math.abs(progress - 0.42) * 14);
|
|
163
|
+
ctx.globalAlpha = Math.min(1, Math.max(0, (0.79 - progress) * 5));
|
|
164
|
+
ctx.fillStyle = '#e1e9f4';
|
|
165
|
+
ctx.fillRect(11, 8, 1.5, 2);
|
|
166
|
+
ctx.fillRect(15.5 - 0.25 * wink, 8 + 0.65 * wink, 1.5 + 0.5 * wink, 2 - 1.25 * wink);
|
|
167
|
+
ctx.beginPath();
|
|
168
|
+
ctx.moveTo(12, 11.5);
|
|
169
|
+
ctx.quadraticCurveTo(14, 14.5, 16, 11.5);
|
|
170
|
+
ctx.stroke();
|
|
171
|
+
|
|
172
|
+
var slash = Math.max(0, (progress - 0.66) / 0.34);
|
|
173
|
+
ctx.globalAlpha = 1;
|
|
174
|
+
ctx.lineWidth = 1.5;
|
|
175
|
+
ctx.beginPath();
|
|
176
|
+
ctx.moveTo(8, 17);
|
|
177
|
+
ctx.lineTo(8 + 12 * slash, 17 - 14 * slash);
|
|
178
|
+
ctx.stroke();
|
|
179
|
+
ctx.restore();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export var unavailableCompanionSwf = {
|
|
183
|
+
length: 0,
|
|
184
|
+
version: 8,
|
|
185
|
+
factory: function (environment) {
|
|
186
|
+
var canvas = global.document.createElement('canvas');
|
|
187
|
+
canvas.width = 28;
|
|
188
|
+
canvas.height = 20;
|
|
189
|
+
var ctx = canvas.getContext('2d');
|
|
190
|
+
var frameRate = 24;
|
|
191
|
+
var elapsed = 0;
|
|
192
|
+
|
|
193
|
+
var clip = new MovieClip();
|
|
194
|
+
clip.totalFrames = clip.framesLoaded = 2;
|
|
195
|
+
clip.mouseEnabled = false;
|
|
196
|
+
clip.width = environment.loaderInfo.width = canvas.width;
|
|
197
|
+
clip.height = environment.loaderInfo.height = canvas.height;
|
|
198
|
+
environment.loaderInfo.frameRate = frameRate;
|
|
199
|
+
clip._swoofTimelineCanvas = canvas;
|
|
200
|
+
function advance(rate) {
|
|
201
|
+
if (!clip._playing) return;
|
|
202
|
+
elapsed += 1 / rate;
|
|
203
|
+
if (elapsed >= 1 - 1e-9) {
|
|
204
|
+
paintUnavailableCompanion(ctx, canvas, 1);
|
|
205
|
+
clip.gotoAndStop(2);
|
|
206
|
+
} else {
|
|
207
|
+
paintUnavailableCompanion(ctx, canvas, elapsed);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
clip._swoofTimeline = {
|
|
211
|
+
get frame() { return clip.currentFrame - 1; },
|
|
212
|
+
tick: function () { advance(frameRate); },
|
|
213
|
+
};
|
|
214
|
+
clip.addEventListener(Event.ENTER_FRAME, function () {
|
|
215
|
+
if (!stageSingleton.contains(clip)) return;
|
|
216
|
+
advance(clip.stage?.frameRate > 0 ? clip.stage.frameRate : frameRate);
|
|
217
|
+
});
|
|
218
|
+
paintUnavailableCompanion(ctx, canvas, 0);
|
|
219
|
+
return clip;
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export function stopLoadedMovie(content) {
|
|
224
|
+
if (!content) return;
|
|
225
|
+
if (content instanceof Loader) content.close();
|
|
226
|
+
if (content._listeners) delete content._listeners[Event.ENTER_FRAME];
|
|
227
|
+
unregisterEnterFrameReceiver(content);
|
|
228
|
+
if (typeof content._swoofStopMovieTimers === 'function') content._swoofStopMovieTimers();
|
|
229
|
+
if (typeof content._swoofStopTimelineAudio === 'function') content._swoofStopTimelineAudio();
|
|
230
|
+
var children = content._children ? content._children.slice() : [];
|
|
231
|
+
for (var i = 0; i < children.length; i++) stopLoadedMovie(children[i]);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export class Loader extends DisplayObjectContainer {
|
|
235
|
+
constructor() {
|
|
236
|
+
super();
|
|
237
|
+
this.content = null;
|
|
238
|
+
this.contentLoaderInfo = new LoaderInfo();
|
|
239
|
+
this.contentLoaderInfo.loader = this;
|
|
240
|
+
this._loadGeneration = 0;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
load(request, context) {
|
|
244
|
+
var self = this;
|
|
245
|
+
var info = this.contentLoaderInfo;
|
|
246
|
+
this.close();
|
|
247
|
+
var generation = this._loadGeneration;
|
|
248
|
+
var requestedUrl = request && request.url || '';
|
|
249
|
+
var parentInfo = loaderOwnerInfo(this);
|
|
250
|
+
var resolvedUrl, urlKey, entry;
|
|
251
|
+
if (requestedUrl) {
|
|
252
|
+
try {
|
|
253
|
+
resolvedUrl = new URL(String(requestedUrl), parentInfo && parentInfo.url || companionBaseUrl());
|
|
254
|
+
urlKey = companionUrlKey(resolvedUrl);
|
|
255
|
+
entry = companionSwfs.get(urlKey);
|
|
256
|
+
} catch (_) {}
|
|
257
|
+
}
|
|
258
|
+
if (resolvedUrl && (entry || /\.swf$/i.test(urlKey || resolvedUrl.pathname))) {
|
|
259
|
+
var isGet = !request.method || String(request.method).toUpperCase() === 'GET';
|
|
260
|
+
var selected = entry ? (isGet ? entry : null) : unavailableCompanionSwf;
|
|
261
|
+
this._loadEmbeddedSwf(selected, selected?.length || 0, selected?.version || 0, context,
|
|
262
|
+
generation, resolvedUrl, 'Compiled companion SWFs require a GET request');
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
var scoped = movieLoaderOwners.has(this);
|
|
266
|
+
info.url = scoped && resolvedUrl ? resolvedUrl.href : requestedUrl;
|
|
267
|
+
if (scoped && parentInfo.url) info.loaderURL = parentInfo.url;
|
|
268
|
+
try { info.dispatchEvent(new Event(Event.OPEN)); } catch (_) {}
|
|
269
|
+
if (this._loadGeneration !== generation) return;
|
|
270
|
+
if (typeof Image === 'undefined' || !info.url) {
|
|
271
|
+
setTimeout(function () { self._loadError('Loader requires an image or compiled companion SWF URL', generation); }, 0);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
var url = String(info.url);
|
|
275
|
+
var policy = context && context.checkPolicyFile && Security._checkPolicyFiles(url);
|
|
276
|
+
function startImageLoad() {
|
|
277
|
+
if (self._loadGeneration === generation) self._loadImage(url, null, 'Unable to load image', generation);
|
|
278
|
+
}
|
|
279
|
+
if (policy) policy.then(startImageLoad);
|
|
280
|
+
else startImageLoad();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
loadBytes(bytes, context) {
|
|
284
|
+
this.close();
|
|
285
|
+
var generation = this._loadGeneration;
|
|
286
|
+
var compiled = compiledSwfByteArrays.get(bytes);
|
|
287
|
+
if (compiled) {
|
|
288
|
+
this._loadEmbeddedSwf(compiled, compiled.length, compiled.version, context, generation);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
var raw = bytes && typeof bytes._getU8 === 'function' ? bytes._getU8()
|
|
292
|
+
: bytes instanceof Uint8Array ? bytes : null;
|
|
293
|
+
if (isSwfBytes(raw)) {
|
|
294
|
+
this._loadEmbeddedSwf(embeddedSwfEntry(raw), raw.length, raw[3], context, generation);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
var self = this;
|
|
298
|
+
if (!raw || typeof Blob === 'undefined' || typeof URL === 'undefined' || !URL.createObjectURL) {
|
|
299
|
+
setTimeout(function () { self._loadError('Unsupported Loader bytes', generation); }, 0);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
var type = raw[0] === 0xff && raw[1] === 0xd8 ? 'image/jpeg'
|
|
303
|
+
: raw[0] === 0x89 && raw[1] === 0x50 ? 'image/png'
|
|
304
|
+
: raw[0] === 0x47 && raw[1] === 0x49 ? 'image/gif' : 'application/octet-stream';
|
|
305
|
+
this.contentLoaderInfo.url = '';
|
|
306
|
+
try { this.contentLoaderInfo.dispatchEvent(new Event(Event.OPEN)); } catch (_) {}
|
|
307
|
+
if (this._loadGeneration !== generation) return;
|
|
308
|
+
if (type === 'application/octet-stream' || typeof Image === 'undefined') {
|
|
309
|
+
setTimeout(function () { self._loadError('Unsupported image bytes', generation); }, 0);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
var url = URL.createObjectURL(new Blob([raw], { type: type }));
|
|
313
|
+
this._loadImage(url, url, 'Unable to decode image bytes', generation);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
_loadError(message, generation) {
|
|
317
|
+
if (this._loadGeneration !== generation) return;
|
|
318
|
+
try { this.contentLoaderInfo.dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, message)); } catch (_) {}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
_loadEmbeddedSwf(entry, length, version, context, generation, url, missingMessage) {
|
|
322
|
+
var self = this;
|
|
323
|
+
var info = this.contentLoaderInfo;
|
|
324
|
+
if (context && context.allowCodeImport === false && (!url || context.securityDomain != null)) {
|
|
325
|
+
var error = new Error('LoaderContext.allowCodeImport prohibits importing SWF code');
|
|
326
|
+
error.name = 'SecurityError';
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
var applicationDomain = context && context.applicationDomain;
|
|
330
|
+
if (applicationDomain != null && !(applicationDomain instanceof ApplicationDomain)) {
|
|
331
|
+
throw new TypeError('LoaderContext.applicationDomain must be an ApplicationDomain');
|
|
332
|
+
}
|
|
333
|
+
var parentInfo = loaderOwnerInfo(this);
|
|
334
|
+
applicationDomain = applicationDomain || new ApplicationDomain(parentInfo && parentInfo.applicationDomain);
|
|
335
|
+
this._clearContent();
|
|
336
|
+
if (this._loadGeneration !== generation) return;
|
|
337
|
+
info.url = url ? url.href : '';
|
|
338
|
+
info.loaderURL = parentInfo && (parentInfo.url || parentInfo.loaderURL) || info.loaderURL;
|
|
339
|
+
info.applicationDomain = applicationDomain;
|
|
340
|
+
info.parameters = context && context.parameters || (url ? Object.fromEntries(url.searchParams) : {});
|
|
341
|
+
info.bytesLoaded = 0;
|
|
342
|
+
info.bytesTotal = length;
|
|
343
|
+
if (url) {
|
|
344
|
+
info.width = info.height = 0;
|
|
345
|
+
info.frameRate = 0;
|
|
346
|
+
}
|
|
347
|
+
info.contentType = 'application/x-shockwave-flash';
|
|
348
|
+
info.swfVersion = version;
|
|
349
|
+
info.bytes = length ? new ByteArray(entry) : new ByteArray();
|
|
350
|
+
if (length && entry && !compiledSwfEntries.has(entry)) {
|
|
351
|
+
info.bytes.writeBytes(entry.getBytes());
|
|
352
|
+
info.bytes.position = 0;
|
|
353
|
+
}
|
|
354
|
+
try { info.dispatchEvent(new Event(Event.OPEN)); } catch (_) {}
|
|
355
|
+
Promise.resolve().then(function () {
|
|
356
|
+
if (self._loadGeneration !== generation) return;
|
|
357
|
+
if (!entry) throw new Error(missingMessage || 'No compiled embedded SWF matches the supplied bytes');
|
|
358
|
+
return entry.factory({
|
|
359
|
+
applicationDomain: applicationDomain, loader: self, loaderInfo: info,
|
|
360
|
+
registerPendingStop: function (stop) {
|
|
361
|
+
if (self._loadGeneration === generation) self._pendingEmbeddedStop = stop;
|
|
362
|
+
else stop();
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
}).then(function (content) {
|
|
366
|
+
if (self._loadGeneration !== generation) {
|
|
367
|
+
if (content && !content.parent) stopLoadedMovie(content);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
if (!(content instanceof DisplayObject) || content === self || content.parent) {
|
|
371
|
+
throw new TypeError('An embedded SWF factory must return a detached DisplayObject');
|
|
372
|
+
}
|
|
373
|
+
self._pendingEmbeddedStop = null;
|
|
374
|
+
info.bytesLoaded = info.bytesTotal;
|
|
375
|
+
if (url) {
|
|
376
|
+
try { info.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, info.bytesLoaded, info.bytesTotal)); } catch (_) {}
|
|
377
|
+
if (self._loadGeneration !== generation) { stopLoadedMovie(content); return; }
|
|
378
|
+
}
|
|
379
|
+
content.root = content;
|
|
380
|
+
self._attachLoadedContent(content, generation);
|
|
381
|
+
}).catch(function (error) {
|
|
382
|
+
if (self._loadGeneration === generation) self._stopPendingEmbeddedMovie();
|
|
383
|
+
self._loadError(error && error.message || 'Unable to load embedded SWF', generation);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
_loadImage(url, objectURL, errorMessage, generation) {
|
|
388
|
+
var image = new Image(), self = this;
|
|
389
|
+
this._pendingImage = image;
|
|
390
|
+
this._pendingImageURL = objectURL;
|
|
391
|
+
image.onload = function () {
|
|
392
|
+
if (self._loadGeneration !== generation) return;
|
|
393
|
+
self._clearPendingImage();
|
|
394
|
+
self._finishImageLoad(image, generation);
|
|
395
|
+
};
|
|
396
|
+
image.onerror = function () {
|
|
397
|
+
if (self._loadGeneration !== generation) return;
|
|
398
|
+
self._clearPendingImage();
|
|
399
|
+
self._loadError(errorMessage, generation);
|
|
400
|
+
};
|
|
401
|
+
image.src = url;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
_finishImageLoad(image, generation) {
|
|
405
|
+
var bitmapData = bitmapDataFromImage(image);
|
|
406
|
+
this._clearContent();
|
|
407
|
+
if (this._loadGeneration !== generation) return;
|
|
408
|
+
this.contentLoaderInfo.applicationDomain = null;
|
|
409
|
+
this._attachLoadedContent(new Bitmap(bitmapData), generation);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
_attachLoadedContent(content, generation) {
|
|
413
|
+
content.loaderInfo = this.contentLoaderInfo;
|
|
414
|
+
this.content = this.contentLoaderInfo.content = content;
|
|
415
|
+
this.addChild(content);
|
|
416
|
+
if (this._loadGeneration !== generation) return;
|
|
417
|
+
try { this.contentLoaderInfo.dispatchEvent(new Event(Event.INIT)); } catch (_) {}
|
|
418
|
+
if (this._loadGeneration !== generation) return;
|
|
419
|
+
try { this.contentLoaderInfo.dispatchEvent(new Event(Event.COMPLETE)); } catch (_) {}
|
|
420
|
+
if (this._loadGeneration !== generation) return;
|
|
421
|
+
try { this.dispatchEvent(new Event(Event.COMPLETE)); } catch (_) {}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
_clearContent() {
|
|
425
|
+
this.content = null;
|
|
426
|
+
this.contentLoaderInfo.content = null;
|
|
427
|
+
var children = this._children.slice();
|
|
428
|
+
for (var i = children.length - 1; i >= 0; i--) this.removeChild(children[i]);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
unload() {
|
|
432
|
+
this.close();
|
|
433
|
+
this._clearContent();
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
unloadAndStop(gc) {
|
|
437
|
+
var content = this.content;
|
|
438
|
+
var generation = this._loadGeneration;
|
|
439
|
+
stopLoadedMovie(content);
|
|
440
|
+
if (content && content.stop) { try { content.stop(); } catch (_) {} }
|
|
441
|
+
if (this._loadGeneration === generation) this.unload();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
_clearPendingImage() {
|
|
445
|
+
if (this._pendingImage) { this._pendingImage.onload = this._pendingImage.onerror = null; this._pendingImage = null; }
|
|
446
|
+
if (this._pendingImageURL) {
|
|
447
|
+
URL.revokeObjectURL(this._pendingImageURL);
|
|
448
|
+
this._pendingImageURL = null;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
close() {
|
|
453
|
+
this._loadGeneration++;
|
|
454
|
+
this._clearPendingImage();
|
|
455
|
+
this._stopPendingEmbeddedMovie();
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
_stopPendingEmbeddedMovie() {
|
|
459
|
+
var stop = this._pendingEmbeddedStop;
|
|
460
|
+
this._pendingEmbeddedStop = null;
|
|
461
|
+
if (stop) stop();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
export var movieLoaderOwners = new WeakMap();
|
|
465
|
+
export function createMovieLoader(info, applicationDomain) {
|
|
466
|
+
// A LoaderInfo belongs to the loading Loader and can describe a different
|
|
467
|
+
// movie later. Keep the original origin and domain for the authored class.
|
|
468
|
+
var owner = { url: info.url || info.loaderURL, applicationDomain: applicationDomain };
|
|
469
|
+
class MovieLoader extends Loader {
|
|
470
|
+
constructor() {
|
|
471
|
+
super();
|
|
472
|
+
movieLoaderOwners.set(this, owner);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
Object.defineProperty(MovieLoader, Symbol.hasInstance, { value: function (value) {
|
|
476
|
+
return Function.prototype[Symbol.hasInstance].call(this === MovieLoader ? Loader : this, value);
|
|
477
|
+
} });
|
|
478
|
+
MovieLoader.__swoofQualifiedName = 'flash.display.Loader';
|
|
479
|
+
return MovieLoader;
|
|
480
|
+
}
|
|
481
|
+
export function loaderOwnerInfo(loader) {
|
|
482
|
+
var scoped = movieLoaderOwners.get(loader);
|
|
483
|
+
if (scoped) return scoped;
|
|
484
|
+
var root = loader.root;
|
|
485
|
+
return root && root.loaderInfo;
|
|
486
|
+
}
|
|
487
|
+
export function bitmapDataFromImage(image) {
|
|
488
|
+
var bitmapData = Object.create(BitmapData.prototype);
|
|
489
|
+
bitmapData.width = image.naturalWidth || image.width || 0;
|
|
490
|
+
bitmapData.height = image.naturalHeight || image.height || 0;
|
|
491
|
+
bitmapData.transparent = true;
|
|
492
|
+
bitmapData.rect = new Rectangle(0, 0, bitmapData.width, bitmapData.height);
|
|
493
|
+
bitmapData._canvas = null; bitmapData._ctx = null; bitmapData._img = image;
|
|
494
|
+
return bitmapData;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export class FrameLabel extends EventDispatcher {
|
|
498
|
+
constructor(name, frame) {
|
|
499
|
+
super();
|
|
500
|
+
Object.defineProperties(this, {
|
|
501
|
+
name: { value: name == null ? null : String(name), enumerable: true },
|
|
502
|
+
frame: { value: frame | 0, enumerable: true },
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export class Scene extends EventDispatcher {
|
|
508
|
+
constructor(name, labels, numFrames, offset) {
|
|
509
|
+
super();
|
|
510
|
+
Object.defineProperties(this, {
|
|
511
|
+
name: { value: name == null ? null : String(name), enumerable: true },
|
|
512
|
+
labels: { value: labels || [], enumerable: true },
|
|
513
|
+
numFrames: { value: numFrames | 0, enumerable: true },
|
|
514
|
+
offset: { value: offset | 0 },
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function readOnlyTimelineProperty(name, read) {
|
|
520
|
+
Object.defineProperty(MovieClip.prototype, name, {
|
|
521
|
+
get: function () { return read(this); },
|
|
522
|
+
set: function () {
|
|
523
|
+
throw new ReferenceError('Error #1074: Illegal write to read-only property ' + name + ' on ' + this);
|
|
524
|
+
},
|
|
525
|
+
enumerable: true,
|
|
526
|
+
configurable: true,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
class MovieClip extends Sprite {
|
|
531
|
+
constructor() {
|
|
532
|
+
super();
|
|
533
|
+
this.currentFrame = 1;
|
|
534
|
+
this.totalFrames = 1;
|
|
535
|
+
this.framesLoaded = 1;
|
|
536
|
+
this.currentLabel = null;
|
|
537
|
+
this._swoofCurrentLabels = [];
|
|
538
|
+
this._swoofScenes = [new Scene('Scene 1', [], 1, 0)];
|
|
539
|
+
this._swoofCurrentScene = this._swoofScenes[0];
|
|
540
|
+
this.enabled = true;
|
|
541
|
+
this.trackAsMenu = false;
|
|
542
|
+
this._playing = true;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
play() {
|
|
546
|
+
this._playing = true;
|
|
547
|
+
if (this._swoofHostTimeline) {
|
|
548
|
+
var tl = _hostTimeline(this);
|
|
549
|
+
if (tl && tl.play) tl.play();
|
|
550
|
+
} else if (this._swoofLocalTimeline) this._swoofLocalTimeline.play();
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
stop() {
|
|
554
|
+
this._playing = false;
|
|
555
|
+
if (this._swoofHostTimeline) {
|
|
556
|
+
var tl = _hostTimeline(this);
|
|
557
|
+
if (tl && tl.stop) tl.stop();
|
|
558
|
+
} else if (this._swoofLocalTimeline) this._swoofLocalTimeline.stop();
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
gotoAndPlay(f, scene, sceneBias) {
|
|
562
|
+
if (this._swoofHostTimeline) {
|
|
563
|
+
var tl = _hostTimeline(this);
|
|
564
|
+
if (scene == null && sceneBias == null && typeof f === 'number' && this.currentScene) scene = this.currentScene.name;
|
|
565
|
+
if (tl && tl.gotoAndPlay) { tl.gotoAndPlay(f, scene, sceneBias); return; }
|
|
566
|
+
} else if (this._swoofLocalTimeline) {
|
|
567
|
+
this._swoofLocalTimeline.gotoAndPlay(f);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (typeof f === 'number') this.currentFrame = f | 0;
|
|
571
|
+
this._playing = true;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
gotoAndStop(f, scene, sceneBias) {
|
|
575
|
+
if (this._swoofHostTimeline) {
|
|
576
|
+
var tl = _hostTimeline(this);
|
|
577
|
+
if (scene == null && sceneBias == null && typeof f === 'number' && this.currentScene) scene = this.currentScene.name;
|
|
578
|
+
if (tl && tl.gotoAndStop) { tl.gotoAndStop(f, scene, sceneBias); return; }
|
|
579
|
+
} else if (this._swoofLocalTimeline) {
|
|
580
|
+
this._swoofLocalTimeline.gotoAndStop(f);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (typeof f === 'number') this.currentFrame = f | 0;
|
|
584
|
+
this._playing = false;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
nextFrame() {
|
|
588
|
+
var tl = this._swoofHostTimeline ? _hostTimeline(this) : this._swoofLocalTimeline;
|
|
589
|
+
if (tl && tl.nextFrame) tl.nextFrame();
|
|
590
|
+
else if (this.currentFrame < this.totalFrames) this.gotoAndStop(this.currentFrame + 1);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
prevFrame() {
|
|
594
|
+
var tl = this._swoofHostTimeline ? _hostTimeline(this) : this._swoofLocalTimeline;
|
|
595
|
+
if (tl && tl.prevFrame) tl.prevFrame();
|
|
596
|
+
else if (this.currentFrame > 1) this.gotoAndStop(this.currentFrame - 1);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
nextScene() {
|
|
600
|
+
if (this._swoofHostTimeline) {
|
|
601
|
+
var tl = _hostTimeline(this);
|
|
602
|
+
if (tl && tl.nextScene) tl.nextScene();
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
// A sprite has one scene. Either direction lands on its first frame and stops.
|
|
606
|
+
this.gotoAndStop(1);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
prevScene() {
|
|
610
|
+
if (this._swoofHostTimeline) {
|
|
611
|
+
var tl = _hostTimeline(this);
|
|
612
|
+
if (tl && tl.prevScene) tl.prevScene();
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
this.gotoAndStop(1);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
getBytesLoaded() {
|
|
619
|
+
var info = this.loaderInfo;
|
|
620
|
+
return info ? info.bytesLoaded : 0;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
getBytesTotal() {
|
|
624
|
+
var info = this.loaderInfo;
|
|
625
|
+
return info ? info.bytesTotal : 0;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Flash Player API: addFrameScript(frameIndex0, fn, frameIndex0, fn, ...)
|
|
630
|
+
* frame indices are 0-based (constructor of timeline scripts).
|
|
631
|
+
*/
|
|
632
|
+
addFrameScript() {
|
|
633
|
+
if (!this._frameScripts) this._frameScripts = Object.create(null);
|
|
634
|
+
for (var i = 0; i + 1 < arguments.length; i += 2) {
|
|
635
|
+
var fi = arguments[i] | 0;
|
|
636
|
+
var fn = arguments[i + 1];
|
|
637
|
+
if (typeof fn !== 'function') continue;
|
|
638
|
+
if (!this._frameScripts[fi]) this._frameScripts[fi] = [];
|
|
639
|
+
this._frameScripts[fi].push(fn);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const MovieClipExport = new Proxy(MovieClip, {
|
|
644
|
+
apply(_t, _this, args) { return args.length ? args[0] : undefined; },
|
|
645
|
+
});
|
|
646
|
+
export { MovieClipExport as MovieClip };
|
|
647
|
+
readOnlyTimelineProperty('currentLabels', function (clip) { return clip._swoofCurrentLabels || []; });
|
|
648
|
+
readOnlyTimelineProperty('scenes', function (clip) { return clip._swoofScenes || []; });
|
|
649
|
+
readOnlyTimelineProperty('currentScene', function (clip) { return clip._swoofCurrentScene || null; });
|
|
650
|
+
export function _hostTimeline(clip) {
|
|
651
|
+
if (clip && clip._swoofTimeline) return clip._swoofTimeline;
|
|
652
|
+
try {
|
|
653
|
+
return (typeof global !== 'undefined' && global.__swoof && global.__swoof.timeline) || null;
|
|
654
|
+
} catch (_) { return null; }
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export class SimpleButton extends InteractiveObject {
|
|
658
|
+
constructor() {
|
|
659
|
+
super();
|
|
660
|
+
this.enabled = true;
|
|
661
|
+
this.tabEnabled = true;
|
|
662
|
+
this.upState = null;
|
|
663
|
+
this.overState = null;
|
|
664
|
+
this.downState = null;
|
|
665
|
+
this.hitTestState = null;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
hitTestPoint(x, y, shapeFlag) {
|
|
669
|
+
if (this.visible === false || !pointPassesScrollRects(this, x, y)) return false;
|
|
670
|
+
var target = this.hitTestState || this.upState;
|
|
671
|
+
if (!target) return super.hitTestPoint(x, y, shapeFlag);
|
|
672
|
+
var p = this.globalToLocal(new Point(x, y));
|
|
673
|
+
var bounds = target.graphics && target.graphics.getBounds ? target.graphics.getBounds() : null;
|
|
674
|
+
if (bounds && !(p.x >= bounds.x && p.y >= bounds.y && p.x <= bounds.x + bounds.width && p.y <= bounds.y + bounds.height)) return false;
|
|
675
|
+
if (!bounds) {
|
|
676
|
+
var width = +this.width || +target.width || 0, height = +this.height || +target.height || 0;
|
|
677
|
+
if (!(p.x >= 0 && p.y >= 0 && p.x < width && p.y < height)) return false;
|
|
678
|
+
}
|
|
679
|
+
if (shapeFlag && target.graphics && target.graphics.containsPoint && typeof document !== 'undefined' &&
|
|
680
|
+
typeof Path2D !== 'undefined' && typeof Path2D.prototype?.moveTo === 'function') {
|
|
681
|
+
return target.graphics.containsPoint(p.x, p.y);
|
|
682
|
+
}
|
|
683
|
+
return true;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
Object.defineProperty(SimpleButton.prototype, 'useHandCursor', cursorFlag('_useHandCursor', true));
|
|
687
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Prototype marks. Display code can recognize Sprite and TextLine without importing them. */
|
|
2
|
+
export const displayObjectMark = Symbol('displayObject');
|
|
3
|
+
export const spriteMark = Symbol('sprite');
|
|
4
|
+
export const textLineMark = Symbol('textLine');
|
|
5
|
+
|
|
6
|
+
export function isDisplayObject(value) {
|
|
7
|
+
return value != null && value[displayObjectMark] === true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function isSprite(value) {
|
|
11
|
+
return value != null && value[spriteMark] === true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isTextLine(value) {
|
|
15
|
+
return value != null && value[textLineMark] === true;
|
|
16
|
+
}
|