@swf2es/format 0.0.0-stage → 0.1.0

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 (98) hide show
  1. package/LICENSE +202 -0
  2. package/LICENSE.third-party +35 -0
  3. package/README.md +22 -2
  4. package/dist/abc-names.d.ts +3 -0
  5. package/dist/abc-names.d.ts.map +1 -0
  6. package/dist/abc-names.js +127 -0
  7. package/dist/abc-names.js.map +1 -0
  8. package/dist/actions.d.ts +106 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +223 -0
  11. package/dist/actions.js.map +1 -0
  12. package/dist/air-descriptor.d.ts +11 -0
  13. package/dist/air-descriptor.d.ts.map +1 -0
  14. package/dist/air-descriptor.js +64 -0
  15. package/dist/air-descriptor.js.map +1 -0
  16. package/dist/api-versions.d.ts +12 -0
  17. package/dist/api-versions.d.ts.map +1 -0
  18. package/dist/api-versions.js +23 -0
  19. package/dist/api-versions.js.map +1 -0
  20. package/dist/bitmap.d.ts +34 -0
  21. package/dist/bitmap.d.ts.map +1 -0
  22. package/dist/bitmap.js +200 -0
  23. package/dist/bitmap.js.map +1 -0
  24. package/dist/button.d.ts +39 -0
  25. package/dist/button.d.ts.map +1 -0
  26. package/dist/button.js +61 -0
  27. package/dist/button.js.map +1 -0
  28. package/dist/compression.d.ts +47 -0
  29. package/dist/compression.d.ts.map +1 -0
  30. package/dist/compression.js +201 -0
  31. package/dist/compression.js.map +1 -0
  32. package/dist/display.d.ts +106 -0
  33. package/dist/display.d.ts.map +1 -0
  34. package/dist/display.js +306 -0
  35. package/dist/display.js.map +1 -0
  36. package/dist/filters.d.ts +66 -0
  37. package/dist/filters.d.ts.map +1 -0
  38. package/dist/filters.js +137 -0
  39. package/dist/filters.js.map +1 -0
  40. package/dist/font.d.ts +60 -0
  41. package/dist/font.d.ts.map +1 -0
  42. package/dist/font.js +169 -0
  43. package/dist/font.js.map +1 -0
  44. package/dist/index.d.ts +27 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +27 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/lzma.d.ts +33 -0
  49. package/dist/lzma.d.ts.map +1 -0
  50. package/dist/lzma.js +279 -0
  51. package/dist/lzma.js.map +1 -0
  52. package/dist/pbj.d.ts +178 -0
  53. package/dist/pbj.d.ts.map +1 -0
  54. package/dist/pbj.js +485 -0
  55. package/dist/pbj.js.map +1 -0
  56. package/dist/shape.d.ts +152 -0
  57. package/dist/shape.d.ts.map +1 -0
  58. package/dist/shape.js +412 -0
  59. package/dist/shape.js.map +1 -0
  60. package/dist/sound.d.ts +71 -0
  61. package/dist/sound.d.ts.map +1 -0
  62. package/dist/sound.js +92 -0
  63. package/dist/sound.js.map +1 -0
  64. package/dist/swf.d.ts +77 -0
  65. package/dist/swf.d.ts.map +1 -0
  66. package/dist/swf.js +164 -0
  67. package/dist/swf.js.map +1 -0
  68. package/dist/tags.d.ts +57 -0
  69. package/dist/tags.d.ts.map +1 -0
  70. package/dist/tags.js +59 -0
  71. package/dist/tags.js.map +1 -0
  72. package/dist/text.d.ts +75 -0
  73. package/dist/text.d.ts.map +1 -0
  74. package/dist/text.js +136 -0
  75. package/dist/text.js.map +1 -0
  76. package/dist/zip.d.ts +17 -0
  77. package/dist/zip.d.ts.map +1 -0
  78. package/dist/zip.js +92 -0
  79. package/dist/zip.js.map +1 -0
  80. package/package.json +33 -3
  81. package/src/abc-names.ts +138 -0
  82. package/src/actions.ts +319 -0
  83. package/src/air-descriptor.ts +84 -0
  84. package/src/api-versions.ts +27 -0
  85. package/src/bitmap.ts +259 -0
  86. package/src/button.ts +99 -0
  87. package/src/compression.ts +243 -0
  88. package/src/display.ts +419 -0
  89. package/src/filters.ts +206 -0
  90. package/src/font.ts +238 -0
  91. package/src/index.ts +151 -0
  92. package/src/pbj.ts +651 -0
  93. package/src/shape.ts +618 -0
  94. package/src/sound.ts +173 -0
  95. package/src/swf.ts +234 -0
  96. package/src/tags.ts +58 -0
  97. package/src/text.ts +213 -0
  98. package/src/zip.ts +135 -0
@@ -0,0 +1,39 @@
1
+ import type { ActionList } from "./actions.js";
2
+ import { type ColorTransform, type Matrix } from "./shape.js";
3
+ import { type Tag } from "./swf.js";
4
+ /** A button's state, as BUTTONRECORD's flags have them. */
5
+ export declare const BUTTON_UP = 1;
6
+ export declare const BUTTON_OVER = 2;
7
+ export declare const BUTTON_DOWN = 4;
8
+ export declare const BUTTON_HIT_TEST = 8;
9
+ /** A character a button shows in the states `states` names (BUTTON_UP and the rest). */
10
+ export interface ButtonRecord {
11
+ states: number;
12
+ character: number;
13
+ depth: number;
14
+ matrix: Matrix;
15
+ /** DefineButton2's; null in a DefineButton. */
16
+ colorTransform: ColorTransform | null;
17
+ /** The filter list's bytes, undecoded, as a place keeps them; null without one. */
18
+ filters: Uint8Array | null;
19
+ blendMode: number | null;
20
+ }
21
+ export interface Button {
22
+ id: number;
23
+ records: ButtonRecord[];
24
+ /** DefineButton2's TrackAsMenu: a press elsewhere can be released on it. */
25
+ trackAsMenu: boolean;
26
+ /**
27
+ * The indices of its AVM1 actions in the SWF's ActionList; null without
28
+ * them, or when read without the list.
29
+ */
30
+ actions: number[] | null;
31
+ }
32
+ /** A DefineButton or DefineButton2; given the SWF's action list, with the indices of its actions. */
33
+ export declare function readButton(bytes: Uint8Array, tag: Tag, actions?: ActionList): Button;
34
+ /** A button's id, and where its actions start: -1 for a DefineButton2 whose action offset is 0. */
35
+ export declare function buttonActionsOffset(bytes: Uint8Array, tag: Tag): {
36
+ id: number;
37
+ offset: number;
38
+ };
39
+ //# sourceMappingURL=button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../src/button.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAkC,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/C,2DAA2D;AAC3D,eAAO,MAAM,SAAS,IAAO,CAAC;AAC9B,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,eAAe,IAAO,CAAC;AAEpC,wFAAwF;AACxF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,mFAAmF;IACnF,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,4EAA4E;IAC5E,WAAW,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC1B;AAED,qGAAqG;AACrG,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAIpF;AAED,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAG/F"}
package/dist/button.js ADDED
@@ -0,0 +1,61 @@
1
+ import { readFilterBytes } from "./display.js";
2
+ import { readColorTransform, readMatrix } from "./shape.js";
3
+ import { SwfReader } from "./swf.js";
4
+ import { DefineButton2 } from "./tags.js";
5
+ /** A button's state, as BUTTONRECORD's flags have them. */
6
+ export const BUTTON_UP = 0x01;
7
+ export const BUTTON_OVER = 0x02;
8
+ export const BUTTON_DOWN = 0x04;
9
+ export const BUTTON_HIT_TEST = 0x08;
10
+ /** A DefineButton or DefineButton2; given the SWF's action list, with the indices of its actions. */
11
+ export function readButton(bytes, tag, actions) {
12
+ const { button } = parseButton(bytes, tag);
13
+ button.actions = actions?.byTag.get(tag.offset) ?? null;
14
+ return button;
15
+ }
16
+ /** A button's id, and where its actions start: -1 for a DefineButton2 whose action offset is 0. */
17
+ export function buttonActionsOffset(bytes, tag) {
18
+ const { button, actions } = parseButton(bytes, tag);
19
+ return { id: button.id, offset: actions };
20
+ }
21
+ function parseButton(bytes, tag) {
22
+ const r = new SwfReader(bytes, tag.offset, tag.offset + tag.length);
23
+ const two = tag.code === DefineButton2;
24
+ const button = { id: r.u16(), records: [], trackAsMenu: false, actions: null };
25
+ // Only whether it is 0 counts: the actions start after the records' end, as Ruffle reads them.
26
+ let hasActions = true;
27
+ if (two) {
28
+ button.trackAsMenu = (r.u8() & 0x01) !== 0;
29
+ hasActions = r.u16() !== 0;
30
+ }
31
+ // The records end at a flags byte of 0.
32
+ while (r.pos < r.end && !r.overrun) {
33
+ const flags = r.u8();
34
+ if (flags === 0) {
35
+ break;
36
+ }
37
+ const record = {
38
+ states: flags & 0x0f,
39
+ character: r.u16(),
40
+ depth: r.u16(),
41
+ matrix: readMatrix(r),
42
+ colorTransform: null,
43
+ filters: null,
44
+ blendMode: null,
45
+ };
46
+ if (two) {
47
+ record.colorTransform = readColorTransform(r, true);
48
+ if (flags & 0x10) {
49
+ record.filters = readFilterBytes(r);
50
+ }
51
+ if (flags & 0x20) {
52
+ record.blendMode = r.u8();
53
+ }
54
+ }
55
+ if (!r.overrun) {
56
+ button.records.push(record);
57
+ }
58
+ }
59
+ return { button, actions: hasActions ? Math.min(r.pos, r.end) : -1 };
60
+ }
61
+ //# sourceMappingURL=button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.js","sourceRoot":"","sources":["../src/button.ts"],"names":[],"mappings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C;QAED,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YACf,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvE,CAAC"}
@@ -0,0 +1,47 @@
1
+ /** Data a decompressor cannot read: corrupt, truncated, or not what it says. */
2
+ export declare class CompressedDataError extends Error {
3
+ }
4
+ /**
5
+ * Data whose output does not fit: more than the decompressor's memory, or
6
+ * the page's, can hold. avmplus' ByteArray fails such an uncompress with
7
+ * MemoryError 1000, where it fails corrupt data with IOError 2058.
8
+ */
9
+ export declare class CompressedDataTooLargeError extends CompressedDataError {
10
+ }
11
+ /** A deflate level: 0 stores, 1 is fastest, 9 smallest. */
12
+ export type ZlibLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
13
+ /** `data` as a zlib stream, as zlib's deflate writes it at `level`, 9 by default, as avmplus' ByteArray. */
14
+ export declare function zlibCompress(data: Uint8Array, level?: ZlibLevel): Uint8Array;
15
+ /** `data` as a raw deflate stream, with no zlib header or checksum. */
16
+ export declare function deflateCompress(data: Uint8Array): Uint8Array;
17
+ /**
18
+ * The bytes of a zlib stream (or, `raw`, of a raw deflate stream), up to its
19
+ * end: anything after is left, as zlib's inflate leaves it. The header is
20
+ * checked here, so that every way it can be wrong reads as avmplus' does.
21
+ */
22
+ export declare function zlibUncompress(data: Uint8Array, raw?: boolean): Uint8Array;
23
+ /** The size of an LZMA header: its 5 property bytes and the 8-byte length of what it holds. */
24
+ export declare const LZMA_HEADER = 13;
25
+ /** `data` as ByteArray's LZMA: the 5 property bytes, its length in 8 bytes, little-endian, and the stream. */
26
+ export declare function lzmaByteArrayCompress(data: Uint8Array): Uint8Array;
27
+ /**
28
+ * ByteArray's LZMA, as avmplus reads it: the length its header gives must
29
+ * be what the stream holds. A length past 32 bits is not read here; the
30
+ * caller checks it first, as avmplus fails it before trying.
31
+ */
32
+ export declare function lzmaByteArrayUncompress(data: Uint8Array): Uint8Array;
33
+ /**
34
+ * The first `length` bytes of a SWF as an uncompressed one, or fewer if it
35
+ * has fewer, decompressing only as far as they need: the header and the
36
+ * first tags, without trusting the header's file length, which a SWF of
37
+ * 30 bytes may give as 4 GB. Whatever cannot be read ends it early.
38
+ */
39
+ export declare function decompressSwfPrefix(swf: Uint8Array, length: number): Uint8Array;
40
+ /**
41
+ * A SWF's bytes as an uncompressed one: the header as FWS, then the body,
42
+ * inflated for CWS, and for ZWS decoded from LZMA, whose header SWF writes
43
+ * differently (after the 8 bytes of the SWF header, a 4-byte compressed
44
+ * length and the 5 property bytes, and no 8-byte size).
45
+ */
46
+ export declare function decompressSwf(swf: Uint8Array): Uint8Array;
47
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":"AAmBA,gFAAgF;AAChF,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;GAIG;AACH,qBAAa,2BAA4B,SAAQ,mBAAmB;CAAG;AAEvE,2DAA2D;AAC3D,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE9D,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,GAAE,SAAa,GAAG,UAAU,CAE/E;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAE5D;AAmBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,UAAQ,GAAG,UAAU,CAuBxE;AAED,+FAA+F;AAC/F,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B,8GAA8G;AAC9G,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAElE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAgBpE;AAYD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAsC/E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CA4DzD"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Compression as SWF files and ByteArray use it, synchronously and with no
3
+ * platform API, through @swf2es/native/compress: zlib itself for zlib and raw
4
+ * deflate, the LZMA SDK's encoder for LZMA, and an LZMA decoder after the
5
+ * SDK's specification.
6
+ */
7
+ import { CORRUPT, DICTIONARY, DONE, deflate, FULL, inflate, lzmaDecode, lzmaEncode, TRUNCATED, } from "@swf2es/native/compress";
8
+ /** Data a decompressor cannot read: corrupt, truncated, or not what it says. */
9
+ export class CompressedDataError extends Error {
10
+ }
11
+ /**
12
+ * Data whose output does not fit: more than the decompressor's memory, or
13
+ * the page's, can hold. avmplus' ByteArray fails such an uncompress with
14
+ * MemoryError 1000, where it fails corrupt data with IOError 2058.
15
+ */
16
+ export class CompressedDataTooLargeError extends CompressedDataError {
17
+ }
18
+ /** `data` as a zlib stream, as zlib's deflate writes it at `level`, 9 by default, as avmplus' ByteArray. */
19
+ export function zlibCompress(data, level = 9) {
20
+ return deflate(data, level, false);
21
+ }
22
+ /** `data` as a raw deflate stream, with no zlib header or checksum. */
23
+ export function deflateCompress(data) {
24
+ return deflate(data, 9, true);
25
+ }
26
+ /** The most an inflate may write: as much as a wasm32 memory holds. */
27
+ const NO_LIMIT = 2 ** 32 - 1;
28
+ /** A failed decode's status as a CompressedDataError. */
29
+ function failure(result) {
30
+ switch (result.status) {
31
+ case TRUNCATED:
32
+ return new CompressedDataError("truncated");
33
+ case CORRUPT:
34
+ return new CompressedDataError(result.message ?? "corrupt");
35
+ case DICTIONARY:
36
+ return new CompressedDataError("needs a preset dictionary");
37
+ default:
38
+ return new CompressedDataTooLargeError("out of memory");
39
+ }
40
+ }
41
+ /**
42
+ * The bytes of a zlib stream (or, `raw`, of a raw deflate stream), up to its
43
+ * end: anything after is left, as zlib's inflate leaves it. The header is
44
+ * checked here, so that every way it can be wrong reads as avmplus' does.
45
+ */
46
+ export function zlibUncompress(data, raw = false) {
47
+ if (!raw) {
48
+ if (data.length < 2) {
49
+ throw new CompressedDataError("truncated");
50
+ }
51
+ const cmf = data[0];
52
+ const flg = data[1];
53
+ if ((cmf & 0x0f) !== 8 || cmf >> 4 > 7 || ((cmf << 8) | flg) % 31 !== 0) {
54
+ throw new CompressedDataError("incorrect header check");
55
+ }
56
+ if (flg & 0x20) {
57
+ throw new CompressedDataError("needs a preset dictionary");
58
+ }
59
+ }
60
+ const result = inflate(data, raw, NO_LIMIT);
61
+ if (result.status !== DONE) {
62
+ throw failure(result);
63
+ }
64
+ return result.bytes;
65
+ }
66
+ /** The size of an LZMA header: its 5 property bytes and the 8-byte length of what it holds. */
67
+ export const LZMA_HEADER = 13;
68
+ /** `data` as ByteArray's LZMA: the 5 property bytes, its length in 8 bytes, little-endian, and the stream. */
69
+ export function lzmaByteArrayCompress(data) {
70
+ return lzmaEncode(data);
71
+ }
72
+ /**
73
+ * ByteArray's LZMA, as avmplus reads it: the length its header gives must
74
+ * be what the stream holds. A length past 32 bits is not read here; the
75
+ * caller checks it first, as avmplus fails it before trying.
76
+ */
77
+ export function lzmaByteArrayUncompress(data) {
78
+ const length = (data[5] | (data[6] << 8) | (data[7] << 16) | (data[8] << 24)) >>> 0;
79
+ if (length > MAX_LZMA_RATIO * (data.length - LZMA_HEADER) + 4096) {
80
+ throw new CompressedDataError(`${length} bytes in a stream of ${data.length}`);
81
+ }
82
+ const result = lzmaDecode(data, 0, LZMA_HEADER, length);
83
+ if (result.status !== DONE) {
84
+ throw failure(result);
85
+ }
86
+ if (result.bytes.length !== length) {
87
+ throw new CompressedDataError("length mismatch");
88
+ }
89
+ return result.bytes;
90
+ }
91
+ /**
92
+ * More than LZMA can expand a byte to. Its best case, a long run of one
93
+ * byte, is matches of 273 bytes that each cost 14 decisions, each at least
94
+ * the 0.022 bits of LZMA's likeliest probability (2017/2048): 7090:1,
95
+ * which an encoder nears on 32 MB of zeros (6959:1). A header naming more
96
+ * than this of its stream is refused before decoding; one naming less is
97
+ * decoded, and a decoder that would read past the stream's end fails.
98
+ */
99
+ const MAX_LZMA_RATIO = 8192;
100
+ /**
101
+ * The first `length` bytes of a SWF as an uncompressed one, or fewer if it
102
+ * has fewer, decompressing only as far as they need: the header and the
103
+ * first tags, without trusting the header's file length, which a SWF of
104
+ * 30 bytes may give as 4 GB. Whatever cannot be read ends it early.
105
+ */
106
+ export function decompressSwfPrefix(swf, length) {
107
+ const signature = String.fromCharCode(swf[0], swf[1], swf[2]);
108
+ if (swf.length < 8 || signature === "FWS") {
109
+ return swf.subarray(0, length);
110
+ }
111
+ const fileLength = new DataView(swf.buffer, swf.byteOffset, swf.byteLength).getUint32(4, true);
112
+ // No further than the header's length, where decompressSwf stops too.
113
+ const want = Math.max(0, Math.min(length, fileLength) - 8);
114
+ const options = { offset: 8, partial: true };
115
+ let out = new Uint8Array(8);
116
+ // A kilobyte of the body first, as a header and the first tags need, and
117
+ // more only while the input runs out before the output: a large SWF is
118
+ // not copied whole for its first bytes. What decoded before any failure
119
+ // is kept, so a SWF cut short still has its start.
120
+ for (let input = 1024;; input *= 16) {
121
+ const end = Math.min(swf.length, (signature === "ZWS" ? 17 : 8) + input);
122
+ let result = null;
123
+ if (signature === "CWS") {
124
+ result = inflate(swf.subarray(8, end), false, want, options);
125
+ }
126
+ else if (signature === "ZWS" && swf.length >= 17) {
127
+ const size = Math.min(want, Math.max(0, fileLength - 8));
128
+ result = lzmaDecode(swf.subarray(0, end), 12, 17, size, options);
129
+ }
130
+ if (result === null) {
131
+ break;
132
+ }
133
+ out = result.bytes;
134
+ if (result.status !== TRUNCATED || end === swf.length) {
135
+ break;
136
+ }
137
+ }
138
+ out.set(swf.subarray(0, 8), 0);
139
+ out[0] = 0x46; // F
140
+ return out;
141
+ }
142
+ /**
143
+ * A SWF's bytes as an uncompressed one: the header as FWS, then the body,
144
+ * inflated for CWS, and for ZWS decoded from LZMA, whose header SWF writes
145
+ * differently (after the 8 bytes of the SWF header, a 4-byte compressed
146
+ * length and the 5 property bytes, and no 8-byte size).
147
+ */
148
+ export function decompressSwf(swf) {
149
+ const signature = String.fromCharCode(swf[0], swf[1], swf[2]);
150
+ if (signature === "FWS") {
151
+ return swf;
152
+ }
153
+ const fileLength = new DataView(swf.buffer, swf.byteOffset, swf.byteLength).getUint32(4, true);
154
+ if (fileLength < 8 && (signature === "CWS" || signature === "ZWS")) {
155
+ throw new CompressedDataError(`a file length of ${fileLength}, shorter than its header`);
156
+ }
157
+ let result;
158
+ if (signature === "CWS") {
159
+ // A byte past the header's length tells a longer body from one that
160
+ // fits, which then ends with its checksum checked.
161
+ result = inflate(swf.subarray(8), false, fileLength - 8 + 1, { offset: 8 });
162
+ if (result.status === TRUNCATED) {
163
+ // Some SWFs omit the Adler-32 trailer despite holding a complete deflate stream.
164
+ const raw = inflate(swf.subarray(10), true, fileLength - 8 + 1, { offset: 8 });
165
+ if ((raw.status === DONE || raw.status === FULL) && 10 + raw.used + 4 > swf.length) {
166
+ result = raw;
167
+ }
168
+ }
169
+ // A longer body, as a packer may leave bytes after the End tag inside
170
+ // the stream, is read as far as the header's length and no further, as
171
+ // Flash Player plays it, and as a ZWS's decoding stops.
172
+ if (result.status === FULL) {
173
+ result = { ...result, status: DONE, bytes: result.bytes.subarray(0, fileLength) };
174
+ }
175
+ }
176
+ else if (signature === "ZWS") {
177
+ if (swf.length < 17) {
178
+ throw new CompressedDataError("truncated");
179
+ }
180
+ // A length no stream that short can hold is refused before decoding;
181
+ // within it, the decoder stops where the stream does.
182
+ if (fileLength - 8 > MAX_LZMA_RATIO * (swf.length - 17) + 4096) {
183
+ throw new CompressedDataError(`a body of ${fileLength - 8} bytes in ${swf.length} of SWF`);
184
+ }
185
+ result = lzmaDecode(swf, 12, 17, fileLength - 8, { offset: 8 });
186
+ }
187
+ else {
188
+ throw new TypeError(`Not a SWF file (signature ${JSON.stringify(signature)})`);
189
+ }
190
+ if (result.status !== DONE) {
191
+ throw failure(result);
192
+ }
193
+ const file = result.bytes;
194
+ if (file.length !== fileLength) {
195
+ throw new CompressedDataError(`body of ${file.length - 8} bytes where the header says ${fileLength - 8}`);
196
+ }
197
+ file.set(swf.subarray(0, 8), 0);
198
+ file[0] = 0x46; // F
199
+ return file;
200
+ }
201
+ //# sourceMappingURL=compression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.js","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,OAAO,EAEP,UAAU,EACV,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,OAAO,EACP,UAAU,EACV,UAAU,EACV,SAAS,GACV,MAAM,yBAAyB,CAAC;AAEjC,gFAAgF;AAChF,MAAM,OAAO,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;GAIG;AACH,MAAM,OAAO,2BAA4B,SAAQ,mBAAmB;CAAG;AAKvE,4GAA4G;AAC5G,MAAM,UAAU,YAAY,CAAC,IAAgB,EAAE,KAAK,GAAc,CAAC;IACjE,OAAO,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,IAAgB;IAC9C,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,uE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C,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI;IACpB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,106 @@
1
+ import type { ActionList } from "./actions.js";
2
+ import { type ColorTransform, type Matrix } from "./shape.js";
3
+ import { type Rect, SwfReader, type Tag } from "./swf.js";
4
+ /**
5
+ * A place: a new character at a depth, or a move of the one there, with
6
+ * what it sets. Fields it does not set are null or undefined.
7
+ */
8
+ export interface Place {
9
+ depth: number;
10
+ /** Whether it changes the character already at the depth, rather than placing one. */
11
+ move: boolean;
12
+ character: number | null;
13
+ matrix: Matrix | null;
14
+ colorTransform: ColorTransform | null;
15
+ ratio: number | null;
16
+ name: string | null;
17
+ clipDepth: number | null;
18
+ /** PlaceObject3's class name, for a character made by a class. */
19
+ className: string | null;
20
+ /** PlaceObject3's HasImage: the character is a bitmap, as Flash Pro marks one it places. */
21
+ hasImage: boolean;
22
+ blendMode: number | null;
23
+ cacheAsBitmap: boolean | null;
24
+ visible: boolean | null;
25
+ opaqueBackground: number | null;
26
+ /** The filter list's bytes, undecoded; null without one. */
27
+ filters: Uint8Array | null;
28
+ /** PlaceObject4's trailing AMF3 value, undecoded; null without one. */
29
+ metaData: Uint8Array | null;
30
+ /**
31
+ * The indices of its AVM1 clip actions in the SWF's ActionList; null
32
+ * without them, or when read without the list.
33
+ */
34
+ actions: number[] | null;
35
+ /**
36
+ * The field of all events of clip actions that run past the tag, which
37
+ * Flash cannot read: it stops the SWF as the first of them comes; 0 for
38
+ * none (ActionList.corrupt).
39
+ */
40
+ corrupt: number;
41
+ }
42
+ export declare function readString(r: SwfReader): string;
43
+ /**
44
+ * UTF-8 as SWF 6 and later write strings, read as avmplus' Utf8ToUtf16 does
45
+ * (fromUtf8 in the runtime): a malformed or overlong sequence is no
46
+ * sequence, and its first byte stands for itself.
47
+ */
48
+ export declare function utf8(bytes: Uint8Array): string;
49
+ /**
50
+ * A PlaceObject 1 to 4 tag's body; given the SWF's
51
+ * action list, with the indices of its clip actions.
52
+ */
53
+ export declare function readPlace(bytes: Uint8Array, tag: Tag, actions?: ActionList): Place;
54
+ /** Where a PlaceObject 2 to 4's clip actions start, -1 without them, and its depth. */
55
+ export declare function clipActionsOffset(bytes: Uint8Array, tag: Tag): {
56
+ depth: number;
57
+ offset: number;
58
+ };
59
+ /** Filter sizes by id, as FILTER's variants lay them out (6 and 7 have variable length). */
60
+ export declare function readFilterBytes(r: SwfReader): Uint8Array;
61
+ /** A RemoveObject's or RemoveObject2's depth. */
62
+ export declare function readRemove(bytes: Uint8Array, tag: Tag): number;
63
+ export declare function readFrameLabel(bytes: Uint8Array, tag: Tag): string;
64
+ /** A root's scenes and frame labels, each frame counted from 0 the first. */
65
+ export interface SceneData {
66
+ scenes: {
67
+ frame: number;
68
+ name: string;
69
+ }[];
70
+ labels: {
71
+ frame: number;
72
+ name: string;
73
+ }[];
74
+ }
75
+ /** DefineSceneAndFrameLabelData; a count past the tag's end stops where its bytes do. */
76
+ export declare function readSceneData(bytes: Uint8Array, tag: Tag): SceneData;
77
+ /** A DefineSprite's id, frame count and its own tags. */
78
+ export declare function readSprite(bytes: Uint8Array, tag: Tag): {
79
+ id: number;
80
+ frameCount: number;
81
+ tags: Tag[];
82
+ };
83
+ /** DefineScalingGrid: the sprite or button it is for, and its grid, in twips, in the character's space. */
84
+ export declare function readScalingGrid(bytes: Uint8Array, tag: Tag): {
85
+ id: number;
86
+ grid: Rect;
87
+ };
88
+ /** DefineBinaryData: a character's bytes, after its id and 4 reserved bytes, which a ByteArray subclass SymbolClass binds to it holds. */
89
+ export declare function readBinaryData(bytes: Uint8Array, tag: Tag): {
90
+ id: number;
91
+ data: Uint8Array;
92
+ };
93
+ /** SymbolClass's links, including multiple classes of one character; id 0 is the document class. */
94
+ export declare function readSymbolClass(bytes: Uint8Array, tag: Tag): [number, string][];
95
+ /** A DoABC's or DoABC2's ABC bytes, its name, and whether it is to be run lazily (kDoAbcLazyInitializeFlag). */
96
+ export declare function readDoAbc(bytes: Uint8Array, tag: Tag): {
97
+ name: string;
98
+ lazy: boolean;
99
+ abc: Uint8Array;
100
+ };
101
+ /** ExportAssets: the characters it names, each id with its name, in tag order. */
102
+ export declare function readExports(bytes: Uint8Array, tag: Tag): {
103
+ id: number;
104
+ name: string;
105
+ }[];
106
+ //# sourceMappingURL=display.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../src/display.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAkC,MAAM,YAAY,CAAC;AAC9F,OAAO,EAAE,KAAK,IAAI,EAAY,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAUpE;;;GAGG;AACH,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IACtC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,kEAAkE;IAClE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,4FAA4F;IAC5F,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,4DAA4D;IAC5D,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3B,uEAAuE;IACvE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