@swf2es/web 0.1.15 → 0.1.17
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/air.d.ts +11 -2
- package/dist/air.d.ts.map +1 -1
- package/dist/air.js +29 -1
- package/dist/air.js.map +1 -1
- package/dist/config.d.ts +23 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +125 -2
- package/dist/element.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +13 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +18 -0
- package/dist/layout.js.map +1 -1
- package/dist/playback.d.ts.map +1 -1
- package/dist/playback.js +21 -6
- package/dist/playback.js.map +1 -1
- package/dist/replace.d.ts.map +1 -1
- package/dist/replace.js +2 -0
- package/dist/replace.js.map +1 -1
- package/dist/uncaught.d.ts +12 -0
- package/dist/uncaught.d.ts.map +1 -0
- package/dist/uncaught.js +31 -0
- package/dist/uncaught.js.map +1 -0
- package/package.json +5 -5
- package/src/air.ts +34 -1
- package/src/config.ts +24 -0
- package/src/element.ts +145 -2
- package/src/index.ts +1 -0
- package/src/layout.ts +24 -0
- package/src/playback.ts +45 -13
- package/src/replace.ts +2 -0
- package/src/uncaught.ts +35 -0
package/src/playback.ts
CHANGED
|
@@ -11,7 +11,14 @@ import {
|
|
|
11
11
|
type TextInput,
|
|
12
12
|
} from "@swf2es/player";
|
|
13
13
|
import type { RenderView } from "@swf2es/player/scene";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
type Placement,
|
|
16
|
+
place,
|
|
17
|
+
type ScaleMode,
|
|
18
|
+
sourceViewport,
|
|
19
|
+
type Viewport,
|
|
20
|
+
viewport,
|
|
21
|
+
} from "./layout.js";
|
|
15
22
|
import type { Stage3DSession } from "./stage3d.js";
|
|
16
23
|
|
|
17
24
|
/** How the element shows its player, read again as the page changes them. */
|
|
@@ -273,10 +280,12 @@ export class Playback {
|
|
|
273
280
|
scripting?.setStageDefaults(look.scale, look.salign ?? "");
|
|
274
281
|
const mode = scripting?.stageScaleMode ?? look.scale;
|
|
275
282
|
const align = scripting?.stageAlign ?? look.salign;
|
|
276
|
-
//
|
|
283
|
+
// In full screen with a fullScreenSourceRect, that part of the stage alone is shown.
|
|
284
|
+
const rect = scripting?.fullScreen.rect ?? null;
|
|
285
|
+
// Live noScale makes the stage the box's size, or the source rect's; every other mode keeps the SWF's.
|
|
277
286
|
const noScale = !!scripting && mode === "noScale";
|
|
278
|
-
const stageWidth = noScale ? this.box.clientWidth : this.player.width;
|
|
279
|
-
const stageHeight = noScale ? this.box.clientHeight : this.player.height;
|
|
287
|
+
const stageWidth = noScale ? (rect?.width ?? this.box.clientWidth) : this.player.width;
|
|
288
|
+
const stageHeight = noScale ? (rect?.height ?? this.box.clientHeight) : this.player.height;
|
|
280
289
|
this.dpr = devicePixelRatio || 1;
|
|
281
290
|
const placed = place(
|
|
282
291
|
this.player.width || 1,
|
|
@@ -289,14 +298,16 @@ export class Playback {
|
|
|
289
298
|
// AIR's top and left edges win where both are named; checked with Stage3D only.
|
|
290
299
|
!!this.stage3D,
|
|
291
300
|
);
|
|
292
|
-
const view =
|
|
293
|
-
this.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
301
|
+
const view = rect
|
|
302
|
+
? sourceViewport(rect, this.box.clientWidth, this.box.clientHeight, this.dpr)
|
|
303
|
+
: viewport(
|
|
304
|
+
this.player.width || 1,
|
|
305
|
+
this.player.height || 1,
|
|
306
|
+
this.box.clientWidth,
|
|
307
|
+
this.box.clientHeight,
|
|
308
|
+
mode,
|
|
309
|
+
placed,
|
|
310
|
+
);
|
|
300
311
|
const canvas = this.view.canvas;
|
|
301
312
|
canvas.style.left = `${view.css.x}px`;
|
|
302
313
|
canvas.style.top = `${view.css.y}px`;
|
|
@@ -329,7 +340,11 @@ export class Playback {
|
|
|
329
340
|
}
|
|
330
341
|
|
|
331
342
|
this.view.setViewport(view.x, view.y, screenWidth, screenHeight);
|
|
332
|
-
this.stage3D?.layout(
|
|
343
|
+
this.stage3D?.layout(
|
|
344
|
+
rect ? stageAround(rect, view, this.player.width, this.player.height) : placed,
|
|
345
|
+
this.player.width,
|
|
346
|
+
this.player.height,
|
|
347
|
+
);
|
|
333
348
|
this.dirty = true;
|
|
334
349
|
// Dispatch only after placement is current: a resize listener may set
|
|
335
350
|
// another layout or reconfigure its Stage3D back buffer synchronously.
|
|
@@ -365,6 +380,23 @@ export class Playback {
|
|
|
365
380
|
}
|
|
366
381
|
}
|
|
367
382
|
|
|
383
|
+
/** Where the whole stage lies in the box when `view` shows `rect` of it: Stage3D's layers are placed by the stage. */
|
|
384
|
+
function stageAround(
|
|
385
|
+
rect: { x: number; y: number; width: number },
|
|
386
|
+
view: Viewport,
|
|
387
|
+
stageWidth: number,
|
|
388
|
+
stageHeight: number,
|
|
389
|
+
): Placement {
|
|
390
|
+
const scale = view.css.width / rect.width;
|
|
391
|
+
return {
|
|
392
|
+
x: view.css.x - rect.x * scale,
|
|
393
|
+
y: view.css.y - rect.y * scale,
|
|
394
|
+
width: stageWidth * scale,
|
|
395
|
+
height: stageHeight * scale,
|
|
396
|
+
resolution: view.resolution,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
368
400
|
/** The most a canvas's multisampled buffers may take, colour and depth-stencil together. */
|
|
369
401
|
const STAGE_BYTES = 256 * 1024 * 1024;
|
|
370
402
|
|
package/src/replace.ts
CHANGED
package/src/uncaught.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// What the element says of an error a SWF's code threw and nothing caught.
|
|
2
|
+
// The release player's message is the error's number alone, so the report
|
|
3
|
+
// adds what the number stands for and where it was thrown; and a SWF that
|
|
4
|
+
// throws the same error every frame is told of once, then at its 10th,
|
|
5
|
+
// 100th and so on, rather than filling the console.
|
|
6
|
+
|
|
7
|
+
/** How many stack lines a report shows: the method that threw and its callers. */
|
|
8
|
+
const FRAMES = 4;
|
|
9
|
+
|
|
10
|
+
export class UncaughtReports {
|
|
11
|
+
/** How often each error was reported, by its text and where it was thrown. */
|
|
12
|
+
private readonly counts = new Map<string, number>();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The line to print for an error whose AS3 text is `text`, e.g.
|
|
16
|
+
* "TypeError: Error #1006": with `detail`, the message in full ("Error
|
|
17
|
+
* #1006: value is not a function."), and `stack`, where it was made, if
|
|
18
|
+
* the runtime has them. Null for a repeat that is not told.
|
|
19
|
+
*/
|
|
20
|
+
line(text: string, detail: string | null, stack: string | null): string | null {
|
|
21
|
+
const frames = stack ? stack.split("\n").slice(0, FRAMES) : [];
|
|
22
|
+
const key = `${text}\n${frames[0] ?? ""}`;
|
|
23
|
+
const count = (this.counts.get(key) ?? 0) + 1;
|
|
24
|
+
this.counts.set(key, count);
|
|
25
|
+
// The text ends in the number where the message is the release player's: its words follow.
|
|
26
|
+
const number = detail?.match(/^Error #\d+/)?.[0];
|
|
27
|
+
const full =
|
|
28
|
+
detail && number && text.endsWith(number) ? text + detail.slice(number.length) : text;
|
|
29
|
+
if (count === 1) {
|
|
30
|
+
return [`swf2es: ${full}`, ...frames].join("\n");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return /^10*$/.test(String(count)) ? `swf2es: ${full} (${count} times)` : null;
|
|
34
|
+
}
|
|
35
|
+
}
|