@swf2es/player-hosts 0.1.3 → 0.1.5

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 (45) hide show
  1. package/dist/thread/format/bitmap.js +13 -14
  2. package/dist/thread/format/index.js +1 -1
  3. package/dist/thread/format/swf.js +11 -1
  4. package/dist/thread/player/avm1/globals/BitmapData.js +2 -1
  5. package/dist/thread/player/avm1/keyboard.js +13 -0
  6. package/dist/thread/player/avm1/loads.js +3 -0
  7. package/dist/thread/player/bitmap/composite.js +767 -0
  8. package/dist/thread/player/bitmap/draw.js +3 -3
  9. package/dist/thread/player/bitmap/filters.js +32 -32
  10. package/dist/thread/player/bitmap/ops.js +2 -766
  11. package/dist/thread/player/bitmap/pixel-bender.js +4 -1
  12. package/dist/thread/player/display/displayobject.js +1 -1
  13. package/dist/thread/player/display/instantiate.js +28 -29
  14. package/dist/thread/player/input/keyboard.js +20 -1
  15. package/dist/thread/player/input/text-input.js +99 -0
  16. package/dist/thread/player/media/audio.js +11 -0
  17. package/dist/thread/player/media/sounds.js +20 -0
  18. package/dist/thread/player/player.js +3 -1
  19. package/dist/thread/player/playerglobal/flash/desktop/NativeApplication.js +1 -1
  20. package/dist/thread/player/playerglobal/flash/display/BitmapData.js +3 -2
  21. package/dist/thread/player/playerglobal/flash/display/SimpleButton.js +12 -11
  22. package/dist/thread/player/playerglobal/flash/display/Stage.js +2 -8
  23. package/dist/thread/player/playerglobal/flash/display/shaders.js +1 -1
  24. package/dist/thread/player/playerglobal/flash/filesystem/paths.js +1 -1
  25. package/dist/thread/player/playerglobal/flash/filesystem/writes.js +1 -1
  26. package/dist/thread/player/playerglobal/flash/globalization/locale.js +1 -1
  27. package/dist/thread/player/playerglobal/flash/media/Sound.js +3 -0
  28. package/dist/thread/player/scripting/events.js +2 -2
  29. package/dist/thread/player/scripting/loads.js +4 -1
  30. package/dist/thread/player/scripting/symbols.js +24 -30
  31. package/dist/thread/player/scripting.js +1 -6
  32. package/dist/thread/runtime/avm1/errors.js +1 -1
  33. package/dist/thread/runtime/avm1/numbers.js +7 -8
  34. package/dist/thread/runtime/avm2/amf.js +2 -1
  35. package/dist/thread/runtime/avm2/names.js +0 -4
  36. package/dist/thread/runtime/avm2/natives/bytearray.js +6 -166
  37. package/dist/thread/runtime/avm2/natives/regexp.js +68 -64
  38. package/dist/thread/runtime/avm2/natives/shell-workers.js +1 -1
  39. package/dist/thread/runtime/avm2/natives/shell.js +2 -1
  40. package/dist/thread/runtime/avm2/natives/xml/parser.js +2 -2
  41. package/dist/thread/runtime/avm2/numbers.js +1 -1
  42. package/dist/thread/runtime/avm2/runtime.js +10 -8
  43. package/dist/thread/runtime/avm2/traits.js +1 -1
  44. package/dist/thread/runtime/avm2/utf8.js +167 -0
  45. package/package.json +2 -2
@@ -97,20 +97,19 @@ function cleanJpeg(data) {
97
97
  if (data[at] !== 0xff) {
98
98
  return null;
99
99
  }
100
- const marker = data[at + 1];
101
- if (marker === 0xd8 || marker === 0xd9) {
102
- at += 2;
103
- continue;
104
- }
105
- if (marker === 0xff) {
106
- // Fill bytes before a marker.
107
- at++;
108
- continue;
109
- }
110
- if (marker === 0xda) {
111
- // The scan, and everything after it, as it is.
112
- out.push(data.subarray(at));
113
- return concatAll(out);
100
+ switch (data[at + 1]) {
101
+ case 0xd8:
102
+ case 0xd9:
103
+ at += 2;
104
+ continue;
105
+ case 0xff:
106
+ // Fill bytes before a marker.
107
+ at++;
108
+ continue;
109
+ case 0xda:
110
+ // The scan, and everything after it, as it is.
111
+ out.push(data.subarray(at));
112
+ return concatAll(out);
114
113
  }
115
114
  if (at + 3 >= data.length) {
116
115
  return null;
@@ -20,7 +20,7 @@ export { glyphOf, readFont, readFont4, readFontAlignZones, readFontInfo, } from
20
20
  export { PBJ_RULES, PBJ_STRING, PBJ_TYPE_SIZES, PBJ_TYPES, PbjError, PbjOp, pbjFloatType, readPbj, } from "./pbj.js";
21
21
  export { IDENTITY, readColorTransform, readMatrix, readMorphShape, readShape, } from "./shape.js";
22
22
  export { readButtonSound, readSound, readSoundInfo, readSoundStreamBlock, readSoundStreamHead, readStartSound, } from "./sound.js";
23
- export { backgroundColor, fileAttributes, isAs3, readSwf, readSwfHeader, readTags, SwfReader, } from "./swf.js";
23
+ export { backgroundColor, definesInput, fileAttributes, isAs3, readSwf, readSwfHeader, readTags, SwfReader, } from "./swf.js";
24
24
  export * as tags from "./tags.js";
25
25
  export { readCsmTextSettings, readEditText, readFontName, readStaticText, } from "./text.js";
26
26
  export { readZip, ZipError } from "./zip.js";
@@ -3,7 +3,7 @@
3
3
  // decompression, the frame size as a RECT, the frame rate as 8.8 fixed
4
4
  // point, the frame count, then tags to an End tag or the body's end.
5
5
  import { decompressSwf, decompressSwfPrefix } from "./compression.js";
6
- import { End, FileAttributes, SetBackgroundColor } from "./tags.js";
6
+ import { DefineButton, DefineButton2, DefineEditText, End, FileAttributes, SetBackgroundColor, } from "./tags.js";
7
7
  const SIGNATURES = { FWS: "none", CWS: "zlib", ZWS: "lzma" };
8
8
  /** Read the 8-byte header every SWF starts with. */
9
9
  export function readSwfHeader(bytes) {
@@ -161,3 +161,13 @@ export function isAs3(swf) {
161
161
  const tag = swf.tags.find((t) => t.code === FileAttributes);
162
162
  return !!tag && tag.length >= 1 && (swf.bytes[tag.offset] & 0x08) !== 0;
163
163
  }
164
+ /**
165
+ * Whether the SWF defines what the pointer or the keys reach with no script
166
+ * of its own: a button, which shows its over and down states, or a text
167
+ * field, which may be selected or typed in. Flash plays such a SWF's
168
+ * buttons and fields as any other's, so a host gives it the VM that takes
169
+ * input even when it has no code to run.
170
+ */
171
+ export function definesInput(swf) {
172
+ return swf.tags.some((t) => t.code === DefineButton || t.code === DefineButton2 || t.code === DefineEditText);
173
+ }
@@ -9,9 +9,10 @@
9
9
  // -4 for a rectangle that is none.
10
10
  import { avm1 } from "../../../runtime/index.js";
11
11
  import { BitmapStore, pixelRect, spanRect } from "../../bitmap/bitmap.js";
12
+ import { drawBitmap } from "../../bitmap/composite.js";
12
13
  import { drawDisplayObject } from "../../bitmap/draw.js";
13
14
  import { applyFilter, filterRefusal, GLOWS, generatedRect } from "../../bitmap/filters.js";
14
- import { alphaAt, colorBounds, colorTransform, comparePixels, copyChannel, drawBitmap, floodFill, isThresholdOperation, merge, noise, paletteMap, perlinNoise, pixelDissolve, scroll, threshold, } from "../../bitmap/ops.js";
15
+ import { alphaAt, colorBounds, colorTransform, comparePixels, copyChannel, floodFill, isThresholdOperation, merge, noise, paletteMap, perlinNoise, pixelDissolve, scroll, threshold, } from "../../bitmap/ops.js";
15
16
  import { BLEND_MODES } from "../../display/displayobject.js";
16
17
  import { filterRecordOf } from "./filters.js";
17
18
  import { colorValues, makeGeom } from "./geom.js";
@@ -65,6 +65,19 @@ export class Avm1Keyboard {
65
65
  const used = this.avm1.input.keyPress(printable(k.charCode));
66
66
  return used || this.edit(k);
67
67
  }
68
+ get editing() {
69
+ return this.field()?.type === "input";
70
+ }
71
+ /** An input method's text: no key went with it, so no keyPress, only the field's edit. */
72
+ insert(text) {
73
+ this.handled++;
74
+ const field = this.field();
75
+ if (field?.type !== "input") {
76
+ return false;
77
+ }
78
+ const typed = pasteable(field.multiline, text);
79
+ return typed !== "" && this.editor.type(field, typed);
80
+ }
68
81
  field() {
69
82
  const d = this.avm1.focused;
70
83
  return !this.avm1.halted && d instanceof TextObject && !this.avm1.removed(d) ? d : null;
@@ -19,6 +19,7 @@ import { BitmapStore } from "../bitmap/bitmap.js";
19
19
  import { decodeImageFile, decodeImages, imageFormat } from "../bitmap/images.js";
20
20
  import { BitmapObject, EMPTY_TIMELINE, MovieClip } from "../display/display.js";
21
21
  import { readLibrary, } from "../display/timeline.js";
22
+ import { warmAudioFor } from "../media/sounds.js";
22
23
  import { resolve } from "../scripting/loads.js";
23
24
  import { formRequest } from "./globals/LoadVars.js";
24
25
  import { textFor } from "./net.js";
@@ -171,6 +172,8 @@ export class MovieLoads {
171
172
  if (load.status !== "pending") {
172
173
  return SKIPPED;
173
174
  }
175
+ // Its sounds' device opens as it arrives, before the frame that shows it.
176
+ warmAudioFor(this.movie.audio, a.library);
174
177
  return { ...a, blocks: await this.movie.compile(a.swf, a.library.actions ?? null) };
175
178
  })
176
179
  .catch(() => ({ type: "unknown", status: 0 }));