swf2js 0.1.0 → 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 +3 -2
- 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,298 @@
|
|
|
1
|
+
import { BitmapData } from './bitmap.js';
|
|
2
|
+
import { GestureEvent, PressAndTapGestureEvent, TransformGestureEvent } from './events.js';
|
|
3
|
+
import { Point, Vector } from './geom.js';
|
|
4
|
+
import { global } from './host.js';
|
|
5
|
+
|
|
6
|
+
export class BitmapFilter {
|
|
7
|
+
clone() { return new BitmapFilter(); }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class DisplacementMapFilterMode {
|
|
11
|
+
static WRAP = 'wrap';
|
|
12
|
+
static CLAMP = 'clamp';
|
|
13
|
+
static IGNORE = 'ignore';
|
|
14
|
+
static COLOR = 'color';
|
|
15
|
+
}
|
|
16
|
+
export class DisplacementMapFilter extends BitmapFilter {
|
|
17
|
+
constructor(mapBitmap, mapPoint, componentX, componentY, scaleX, scaleY, mode, color, alpha) {
|
|
18
|
+
super();
|
|
19
|
+
this._mapBitmap = mapBitmap ?? null;
|
|
20
|
+
this._mapPoint = mapPoint == null ? new Point() : new Point(mapPoint.x, mapPoint.y);
|
|
21
|
+
this.componentX = componentX >>> 0;
|
|
22
|
+
this.componentY = componentY >>> 0;
|
|
23
|
+
this.scaleX = scaleX === undefined ? 0 : +scaleX;
|
|
24
|
+
this.scaleY = scaleY === undefined ? 0 : +scaleY;
|
|
25
|
+
this.mode = mode === undefined ? DisplacementMapFilterMode.WRAP : mode;
|
|
26
|
+
this.color = color >>> 0;
|
|
27
|
+
this.alpha = alpha === undefined ? 0 : +alpha;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clone() {
|
|
31
|
+
return new DisplacementMapFilter(this._mapBitmap, this._mapPoint, this.componentX, this.componentY,
|
|
32
|
+
this.scaleX, this.scaleY, this.mode, this.color, this.alpha);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
Object.defineProperties(DisplacementMapFilter.prototype, {
|
|
36
|
+
mapBitmap: {
|
|
37
|
+
get: function () { return this._mapBitmap; },
|
|
38
|
+
set: function (value) {
|
|
39
|
+
if (!(value instanceof BitmapData)) throw new TypeError('Expected a BitmapData map');
|
|
40
|
+
this._mapBitmap = value;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
mapPoint: {
|
|
44
|
+
get: function () { return this._mapPoint.clone(); },
|
|
45
|
+
set: function (value) {
|
|
46
|
+
if (value == null) throw new TypeError('Expected a displacement map point');
|
|
47
|
+
this._mapPoint = new Point(value.x, value.y);
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
mode: {
|
|
51
|
+
get: function () { return this._mode; },
|
|
52
|
+
set: function (value) {
|
|
53
|
+
if (value == null) throw new TypeError('Expected a displacement map mode');
|
|
54
|
+
value = String(value);
|
|
55
|
+
if (!Object.values(DisplacementMapFilterMode).includes(value)) {
|
|
56
|
+
var error = new Error('Invalid displacement map mode: ' + value);
|
|
57
|
+
error.name = 'ArgumentError';
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
this._mode = value;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export class ColorMatrixFilter extends BitmapFilter {
|
|
66
|
+
constructor(matrix) {
|
|
67
|
+
super();
|
|
68
|
+
this.matrix = matrix || [
|
|
69
|
+
1, 0, 0, 0, 0,
|
|
70
|
+
0, 1, 0, 0, 0,
|
|
71
|
+
0, 0, 1, 0, 0,
|
|
72
|
+
0, 0, 0, 1, 0,
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
clone() {
|
|
77
|
+
return new ColorMatrixFilter(this.matrix.slice());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export class ConvolutionFilter extends BitmapFilter {
|
|
82
|
+
constructor(matrixX, matrixY, matrix, divisor, bias, preserveAlpha, clamp, color, alpha) {
|
|
83
|
+
super();
|
|
84
|
+
this.matrixX = Math.max(0, matrixX | 0);
|
|
85
|
+
this.matrixY = Math.max(0, matrixY | 0);
|
|
86
|
+
this.matrix = Array.isArray(matrix) ? matrix.slice() : [];
|
|
87
|
+
this.divisor = +divisor || 1;
|
|
88
|
+
this.bias = +bias || 0;
|
|
89
|
+
this.preserveAlpha = preserveAlpha === undefined ? true : !!preserveAlpha;
|
|
90
|
+
this.clamp = clamp === undefined ? true : !!clamp;
|
|
91
|
+
this.color = color >>> 0;
|
|
92
|
+
this.alpha = Math.min(1, Math.max(0, +alpha || 0));
|
|
93
|
+
this._swoofFilterKind = 'convolution';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
clone() {
|
|
97
|
+
return new ConvolutionFilter(this.matrixX, this.matrixY, this.matrix, this.divisor, this.bias,
|
|
98
|
+
this.preserveAlpha, this.clamp, this.color, this.alpha);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class BitmapFilterType {
|
|
103
|
+
static INNER = 'inner';
|
|
104
|
+
static OUTER = 'outer';
|
|
105
|
+
static FULL = 'full';
|
|
106
|
+
}
|
|
107
|
+
export class BitmapFilterQuality {
|
|
108
|
+
static LOW = 1;
|
|
109
|
+
static MEDIUM = 2;
|
|
110
|
+
static HIGH = 3;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class BevelFilter extends BitmapFilter {
|
|
114
|
+
constructor(distance, angle, highlightColor, highlightAlpha, shadowColor, shadowAlpha,
|
|
115
|
+
blurX, blurY, strength, quality, type, knockout) {
|
|
116
|
+
super();
|
|
117
|
+
this.distance = distance === undefined ? 4 : +distance;
|
|
118
|
+
this.angle = angle === undefined ? 45 : +angle;
|
|
119
|
+
this.highlightColor = highlightColor === undefined ? 0xffffff : highlightColor >>> 0;
|
|
120
|
+
this.highlightAlpha = highlightAlpha === undefined ? 1 : +highlightAlpha;
|
|
121
|
+
this.shadowColor = shadowColor >>> 0;
|
|
122
|
+
this.shadowAlpha = shadowAlpha === undefined ? 1 : +shadowAlpha;
|
|
123
|
+
this.blurX = blurX === undefined ? 4 : +blurX;
|
|
124
|
+
this.blurY = blurY === undefined ? 4 : +blurY;
|
|
125
|
+
this.strength = strength === undefined ? 1 : +strength;
|
|
126
|
+
this.quality = quality === undefined ? 1 : quality | 0;
|
|
127
|
+
this.type = type === undefined ? BitmapFilterType.INNER : String(type);
|
|
128
|
+
this.knockout = !!knockout;
|
|
129
|
+
this._swoofFilterKind = 'bevel';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
clone() {
|
|
133
|
+
return new BevelFilter(this.distance, this.angle, this.highlightColor, this.highlightAlpha,
|
|
134
|
+
this.shadowColor, this.shadowAlpha, this.blurX, this.blurY, this.strength, this.quality, this.type, this.knockout);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export class GradientEffectFilter extends BitmapFilter {
|
|
139
|
+
constructor(distance, angle, colors, alphas, ratios, blurX, blurY, strength, quality, type, knockout) {
|
|
140
|
+
super();
|
|
141
|
+
this.distance = distance === undefined ? 4 : +distance;
|
|
142
|
+
this.angle = angle === undefined ? 45 : +angle;
|
|
143
|
+
this._colors = Array.isArray(colors) ? colors.slice() : [];
|
|
144
|
+
this._alphas = Array.isArray(alphas) ? alphas.slice() : [];
|
|
145
|
+
this._ratios = Array.isArray(ratios) ? ratios.slice() : [];
|
|
146
|
+
this.blurX = blurX === undefined ? 4 : +blurX;
|
|
147
|
+
this.blurY = blurY === undefined ? 4 : +blurY;
|
|
148
|
+
this.strength = strength === undefined ? 1 : +strength;
|
|
149
|
+
this.quality = quality === undefined ? 1 : quality | 0;
|
|
150
|
+
this.type = type === undefined ? BitmapFilterType.INNER : String(type);
|
|
151
|
+
this.knockout = !!knockout;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
clone() {
|
|
155
|
+
return new this.constructor(this.distance, this.angle, this._colors, this._alphas, this._ratios,
|
|
156
|
+
this.blurX, this.blurY, this.strength, this.quality, this.type, this.knockout);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
['colors', 'alphas', 'ratios'].forEach(function (name) {
|
|
160
|
+
Object.defineProperty(GradientEffectFilter.prototype, name, {
|
|
161
|
+
get: function () { return this['_' + name].slice(); },
|
|
162
|
+
set: function (values) {
|
|
163
|
+
if (!Array.isArray(values)) throw new TypeError(name + ' must be an Array');
|
|
164
|
+
this['_' + name] = values.slice();
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export class GradientGlowFilter extends GradientEffectFilter {
|
|
170
|
+
constructor(...args) {
|
|
171
|
+
super(...args);
|
|
172
|
+
this._swoofFilterKind = 'gradientGlow';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class GradientBevelFilter extends GradientEffectFilter {
|
|
177
|
+
constructor(...args) {
|
|
178
|
+
super(...args);
|
|
179
|
+
this._swoofFilterKind = 'gradientBevel';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export class BlurFilter extends BitmapFilter {
|
|
184
|
+
constructor(blurX, blurY, quality) {
|
|
185
|
+
super();
|
|
186
|
+
this.blurX = blurX == null ? 4 : +blurX;
|
|
187
|
+
this.blurY = blurY == null ? 4 : +blurY;
|
|
188
|
+
this.quality = quality == null ? 1 : quality | 0;
|
|
189
|
+
this._swoofFilterKind = 'blur';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
clone() { return new BlurFilter(this.blurX, this.blurY, this.quality); }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export class DropShadowFilter extends BitmapFilter {
|
|
196
|
+
constructor(distance, angle, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject) {
|
|
197
|
+
super();
|
|
198
|
+
this.distance = distance == null ? 4 : +distance;
|
|
199
|
+
this.angle = angle == null ? 45 : +angle;
|
|
200
|
+
this.color = color == null ? 0 : color;
|
|
201
|
+
this.alpha = alpha == null ? 1 : +alpha;
|
|
202
|
+
this.blurX = blurX == null ? 4 : +blurX;
|
|
203
|
+
this.blurY = blurY == null ? 4 : +blurY;
|
|
204
|
+
this.strength = strength == null ? 1 : +strength;
|
|
205
|
+
this.quality = quality == null ? 1 : quality | 0;
|
|
206
|
+
this.inner = !!inner;
|
|
207
|
+
this.knockout = !!knockout;
|
|
208
|
+
this.hideObject = !!hideObject;
|
|
209
|
+
this._swoofFilterKind = 'shadow';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
clone() {
|
|
213
|
+
return new DropShadowFilter(this.distance, this.angle, this.color, this.alpha, this.blurX, this.blurY,
|
|
214
|
+
this.strength, this.quality, this.inner, this.knockout, this.hideObject);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export class GlowFilter extends BitmapFilter {
|
|
219
|
+
constructor(color, alpha, blurX, blurY, strength, quality, inner, knockout) {
|
|
220
|
+
super();
|
|
221
|
+
this.color = color === undefined ? 0xff0000 : color >>> 0;
|
|
222
|
+
this.alpha = alpha == null ? 1 : +alpha;
|
|
223
|
+
this.blurX = blurX == null ? 6 : +blurX;
|
|
224
|
+
this.blurY = blurY == null ? 6 : +blurY;
|
|
225
|
+
this.strength = strength == null ? 2 : +strength;
|
|
226
|
+
this.quality = quality == null ? 1 : quality | 0;
|
|
227
|
+
this.inner = !!inner;
|
|
228
|
+
this.knockout = !!knockout;
|
|
229
|
+
this._swoofFilterKind = 'glow';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
clone() {
|
|
233
|
+
return new GlowFilter(this.color, this.alpha, this.blurX, this.blurY,
|
|
234
|
+
this.strength, this.quality, this.inner, this.knockout);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export class MouseCursor {
|
|
239
|
+
static AUTO = 'auto';
|
|
240
|
+
static ARROW = 'arrow';
|
|
241
|
+
static BUTTON = 'button';
|
|
242
|
+
static HAND = 'hand';
|
|
243
|
+
static IBEAM = 'ibeam';
|
|
244
|
+
}
|
|
245
|
+
export class MultitouchInputMode {
|
|
246
|
+
static NONE = 'none';
|
|
247
|
+
static GESTURE = 'gesture';
|
|
248
|
+
static TOUCH_POINT = 'touchPoint';
|
|
249
|
+
}
|
|
250
|
+
export var touchInputMode = MultitouchInputMode.GESTURE;
|
|
251
|
+
export var cancelActiveTouches = null;
|
|
252
|
+
export function setCancelActiveTouches(fn) { cancelActiveTouches = fn; }
|
|
253
|
+
export var mapTouchToMouse = true;
|
|
254
|
+
export class Multitouch {
|
|
255
|
+
static get inputMode() { return touchInputMode; }
|
|
256
|
+
static set inputMode(value) {
|
|
257
|
+
if (value !== MultitouchInputMode.NONE && value !== MultitouchInputMode.GESTURE &&
|
|
258
|
+
value !== MultitouchInputMode.TOUCH_POINT) {
|
|
259
|
+
var error = new Error('Invalid touch input mode');
|
|
260
|
+
error.name = 'ArgumentError';
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
if (value === touchInputMode) return;
|
|
264
|
+
touchInputMode = value;
|
|
265
|
+
cancelActiveTouches?.();
|
|
266
|
+
}
|
|
267
|
+
static get mapTouchToMouse() { return mapTouchToMouse; }
|
|
268
|
+
static set mapTouchToMouse(value) { mapTouchToMouse = !!value; }
|
|
269
|
+
static get maxTouchPoints() { return Math.max(0, global.navigator?.maxTouchPoints | 0); }
|
|
270
|
+
static get supportsTouchEvents() {
|
|
271
|
+
return this.maxTouchPoints > 0 && typeof window !== 'undefined' && typeof window.PointerEvent === 'function';
|
|
272
|
+
}
|
|
273
|
+
static get supportsGestureEvents() { return this.supportsTouchEvents; }
|
|
274
|
+
static get supportedGestures() {
|
|
275
|
+
if (!this.supportsGestureEvents) return null;
|
|
276
|
+
var result = new Vector(0, false);
|
|
277
|
+
result.push(TransformGestureEvent.GESTURE_SWIPE);
|
|
278
|
+
if (this.maxTouchPoints >= 2) {
|
|
279
|
+
result.push(TransformGestureEvent.GESTURE_PAN, TransformGestureEvent.GESTURE_ZOOM,
|
|
280
|
+
TransformGestureEvent.GESTURE_ROTATE, GestureEvent.GESTURE_TWO_FINGER_TAP,
|
|
281
|
+
PressAndTapGestureEvent.GESTURE_PRESS_AND_TAP);
|
|
282
|
+
}
|
|
283
|
+
result.__swoofVectorTypeName = 'String';
|
|
284
|
+
Object.defineProperty(result, '__swoofVectorElementClass', { value: String });
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
export function mapsPointerToMouse(event) {
|
|
289
|
+
var isTouch = event?.pointerType === 'touch' ||
|
|
290
|
+
event?.pointerType === 'pen' && touchInputMode === MultitouchInputMode.TOUCH_POINT;
|
|
291
|
+
return !isTouch || mapTouchToMouse;
|
|
292
|
+
}
|
|
293
|
+
export function normalizeFlashWheelDelta(event, pageSpan, axis) {
|
|
294
|
+
var raw = axis === 'x' ? event.deltaX : event.deltaY;
|
|
295
|
+
if (!Number.isFinite(raw) || raw === 0) return 0;
|
|
296
|
+
var lines = event.deltaMode === 1 ? raw : raw * (event.deltaMode === 2 ? pageSpan || 1 : 1) / 40;
|
|
297
|
+
return (lines < 0 ? 1 : -1) * Math.max(1, Math.round(Math.abs(lines)));
|
|
298
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The library surface, declared once.
|
|
3
|
+
* `swoof.geom.Matrix` is this object. Page globals are the same classes without
|
|
4
|
+
* a package, for movies that look a name up unqualified.
|
|
5
|
+
* Qualified names stay `flash.display::Sprite` because that is the string a
|
|
6
|
+
* compiled movie passes to getDefinitionByName.
|
|
7
|
+
*/
|
|
8
|
+
import { ByteArray, Endian, FlashProxy } from './bytearray.js';
|
|
9
|
+
import { Dictionary } from './dictionary.js';
|
|
10
|
+
import { AntiAliasType, AsyncErrorEvent, BlendMode, ContextMenuEvent, Event, EventDispatcher, FocusEvent, GestureEvent, GesturePhase, GridFitType, HTTPStatusEvent, IEventDispatcher, IOErrorEvent, KeyboardEvent, MouseEvent, PressAndTapGestureEvent, ProgressEvent, SecurityErrorEvent, StageAlign, StageQuality, StageScaleMode, StatusEvent, TextEvent, TextFieldAutoSize, TextFieldType, Timer, TimerEvent, TouchEvent, TouchEventIntent, TransformGestureEvent, rootTimers } from './events.js';
|
|
11
|
+
import { ColorTransform, Matrix, Matrix3D, Point, Rectangle, Vector, Vector3D } from './geom.js';
|
|
12
|
+
import { DisplayObject, DisplayObjectContainer, InteractiveObject } from './display.js';
|
|
13
|
+
import { Graphics, GraphicsPathCommand, GraphicsPathWinding, Shape, Sprite } from './graphics.js';
|
|
14
|
+
import { Bitmap, BitmapData, BitmapDataChannel } from './bitmap.js';
|
|
15
|
+
import { As2Color, ContextMenu, ContextMenuBuiltInItems, ContextMenuItem } from './context-menu.js';
|
|
16
|
+
import { BevelFilter, BitmapFilter, BitmapFilterQuality, BitmapFilterType, BlurFilter, ColorMatrixFilter, ConvolutionFilter, DisplacementMapFilter, DisplacementMapFilterMode, DropShadowFilter, GlowFilter, GradientBevelFilter, GradientGlowFilter, MouseCursor, Multitouch, MultitouchInputMode } from './filters.js';
|
|
17
|
+
import { global } from './host.js';
|
|
18
|
+
import { FrameLabel, Loader, LoaderInfo, MovieClip, Scene, SimpleButton } from './loader.js';
|
|
19
|
+
import { PerspectiveProjection } from './projection.js';
|
|
20
|
+
import { ID3Info, Sound, SoundChannel, SoundLoaderContext, SoundMixer, SoundTransform } from './sound.js';
|
|
21
|
+
import { Key, Keyboard, Mouse, MouseCursorData, StageClass } from './stage.js';
|
|
22
|
+
import { ApplicationDomain, Capabilities, ExternalInterface, LoaderContext, LocalConnection, Security, SharedObject, Socket, System, URLLoader, URLLoaderDataFormat, URLRequest, URLRequestHeader, URLRequestMethod, URLVariables, asInt, asUint, describeType, getDefinitionByName, getQualifiedClassName, getTimer, navigateToURL, qualifiedBuiltinNames } from './system.js';
|
|
23
|
+
import { TextField, TextLineMetrics } from './text-field.js';
|
|
24
|
+
import { Font, StyleSheet, TextFormat, TextFormatAlign, textEngine } from './text.js';
|
|
25
|
+
import { Transform } from './transform.js';
|
|
26
|
+
import { XML, XMLDocument, XMLList } from './xml.js';
|
|
27
|
+
|
|
28
|
+
export const asPackages = {};
|
|
29
|
+
export const builtins = {};
|
|
30
|
+
|
|
31
|
+
let packageTree;
|
|
32
|
+
export function flashPackageTree() {
|
|
33
|
+
if (packageTree) return packageTree;
|
|
34
|
+
packageTree = {
|
|
35
|
+
geom: { ColorTransform, Matrix, Matrix3D, Point, Rectangle, Transform, Vector3D },
|
|
36
|
+
events: {
|
|
37
|
+
Event, EventDispatcher, IEventDispatcher, TextEvent, MouseEvent, TouchEvent, TouchEventIntent,
|
|
38
|
+
GestureEvent, GesturePhase, PressAndTapGestureEvent, TransformGestureEvent, KeyboardEvent, FocusEvent,
|
|
39
|
+
ContextMenuEvent, IOErrorEvent, ProgressEvent, HTTPStatusEvent, StatusEvent, AsyncErrorEvent,
|
|
40
|
+
TimerEvent, SecurityErrorEvent,
|
|
41
|
+
},
|
|
42
|
+
display: {
|
|
43
|
+
StageScaleMode, StageAlign, StageQuality, PerspectiveProjection, BlendMode,
|
|
44
|
+
DisplayObject, InteractiveObject, DisplayObjectContainer, Graphics, GraphicsPathCommand, GraphicsPathWinding,
|
|
45
|
+
Sprite, Shape, MovieClip, FrameLabel, Scene, SimpleButton, BitmapData, BitmapDataChannel, Bitmap,
|
|
46
|
+
Stage: StageClass, Loader, LoaderInfo,
|
|
47
|
+
},
|
|
48
|
+
media: { Sound, SoundLoaderContext, SoundChannel, SoundMixer, ID3Info, SoundTransform },
|
|
49
|
+
filters: {
|
|
50
|
+
BitmapFilter, ColorMatrixFilter, ConvolutionFilter, DisplacementMapFilter, DisplacementMapFilterMode,
|
|
51
|
+
BevelFilter, GradientGlowFilter, GradientBevelFilter, BitmapFilterType, BitmapFilterQuality,
|
|
52
|
+
BlurFilter, DropShadowFilter, GlowFilter,
|
|
53
|
+
},
|
|
54
|
+
ui: {
|
|
55
|
+
Mouse, MouseCursor, MouseCursorData, Multitouch, MultitouchInputMode, Keyboard,
|
|
56
|
+
ContextMenu, ContextMenuBuiltInItems, ContextMenuItem,
|
|
57
|
+
},
|
|
58
|
+
system: { System, ApplicationDomain, LoaderContext, Security, Capabilities, SharedObject },
|
|
59
|
+
utils: {
|
|
60
|
+
Timer, getTimer, getQualifiedClassName, describeType, getDefinitionByName,
|
|
61
|
+
ByteArray, Endian, Dictionary, Proxy: FlashProxy,
|
|
62
|
+
},
|
|
63
|
+
text: {
|
|
64
|
+
TextField, TextFormat, TextFormatAlign, Font, StyleSheet, TextLineMetrics, TextFieldType, TextFieldAutoSize,
|
|
65
|
+
AntiAliasType, GridFitType, engine: textEngine,
|
|
66
|
+
},
|
|
67
|
+
net: {
|
|
68
|
+
SharedObject, URLLoader, URLLoaderDataFormat, Socket, LocalConnection,
|
|
69
|
+
URLRequest, URLRequestHeader, URLVariables, URLRequestMethod, navigateToURL,
|
|
70
|
+
},
|
|
71
|
+
external: { ExternalInterface },
|
|
72
|
+
xml: { XMLDocument },
|
|
73
|
+
Vector,
|
|
74
|
+
};
|
|
75
|
+
return packageTree;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function hasSwoofBuiltin(rest, local) {
|
|
79
|
+
if (rest === 'utils' && rootTimers.scheduling &&
|
|
80
|
+
Object.prototype.hasOwnProperty.call(rootTimers.scheduling, local) &&
|
|
81
|
+
rootTimers.scheduling[local] != null) return true;
|
|
82
|
+
const tree = flashPackageTree();
|
|
83
|
+
if (!rest) return local === 'Vector' && tree.Vector != null;
|
|
84
|
+
let node = tree;
|
|
85
|
+
for (const part of String(rest).split('.')) {
|
|
86
|
+
if (node == null || (typeof node !== 'object' && typeof node !== 'function')) return false;
|
|
87
|
+
node = node[part];
|
|
88
|
+
}
|
|
89
|
+
return node != null && Object.prototype.hasOwnProperty.call(node, local) && node[local] != null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function installFlash(names) {
|
|
93
|
+
Object.assign(asPackages, flashPackageTree());
|
|
94
|
+
|
|
95
|
+
for (const name in asPackages) {
|
|
96
|
+
const entry = asPackages[name];
|
|
97
|
+
if (typeof entry !== 'object' || !entry) {
|
|
98
|
+
builtins[name] = entry;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
for (const key in entry) {
|
|
102
|
+
if (key === 'Proxy' || key === 'engine') continue;
|
|
103
|
+
builtins[key] = entry[key];
|
|
104
|
+
}
|
|
105
|
+
if (entry.engine) Object.assign(builtins, entry.engine);
|
|
106
|
+
}
|
|
107
|
+
Object.assign(builtins, { Key, As2Color, XML, XMLList, int: asInt, uint: asUint });
|
|
108
|
+
Object.assign(asPackages.utils, rootTimers.scheduling);
|
|
109
|
+
|
|
110
|
+
// One catalog. The page name `swoof` is this object. A movie runtime
|
|
111
|
+
// inherits it and replaces only the classes that close over that movie.
|
|
112
|
+
for (const name in asPackages) {
|
|
113
|
+
const entry = asPackages[name];
|
|
114
|
+
if (typeof entry !== 'object' || !entry) continue;
|
|
115
|
+
for (const key in entry) {
|
|
116
|
+
const value = entry[key];
|
|
117
|
+
if (typeof value === 'function' && /^[A-Z]/.test(key)) {
|
|
118
|
+
names.set(value, 'flash.' + name + '::' + key);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
global.swoof = asPackages;
|
|
123
|
+
for (const name in builtins) {
|
|
124
|
+
try { global[name] = builtins[name]; } catch (_) {}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function qualifiedAvm2BuiltinName(type) {
|
|
129
|
+
return qualifiedBuiltinNames.get(type);
|
|
130
|
+
}
|