swf-toolkit 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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -2
  3. package/README.tr.md +126 -0
  4. package/dist/abc/abc-file.d.ts +168 -0
  5. package/dist/abc/abc-file.js +656 -0
  6. package/dist/abc/analysis.d.ts +36 -0
  7. package/dist/abc/analysis.js +213 -0
  8. package/dist/abc/code.d.ts +59 -0
  9. package/dist/abc/code.js +379 -0
  10. package/dist/abc/constants.d.ts +80 -0
  11. package/dist/abc/constants.js +93 -0
  12. package/dist/abc/interner.d.ts +46 -0
  13. package/dist/abc/interner.js +168 -0
  14. package/dist/abc/model.d.ts +40 -0
  15. package/dist/abc/model.js +146 -0
  16. package/dist/abc/opcodes.d.ts +39 -0
  17. package/dist/abc/opcodes.js +196 -0
  18. package/dist/abc/pcode/assembler.d.ts +42 -0
  19. package/dist/abc/pcode/assembler.js +635 -0
  20. package/dist/abc/pcode/disassembler.d.ts +17 -0
  21. package/dist/abc/pcode/disassembler.js +147 -0
  22. package/dist/abc/pcode/format.d.ts +23 -0
  23. package/dist/abc/pcode/format.js +131 -0
  24. package/dist/abc/pcode/lexer.d.ts +34 -0
  25. package/dist/abc/pcode/lexer.js +183 -0
  26. package/dist/assets/assets.d.ts +26 -0
  27. package/dist/assets/assets.js +151 -0
  28. package/dist/assets/images.d.ts +31 -0
  29. package/dist/assets/images.js +238 -0
  30. package/dist/assets/png.d.ts +12 -0
  31. package/dist/assets/png.js +196 -0
  32. package/dist/assets/sounds.d.ts +37 -0
  33. package/dist/assets/sounds.js +236 -0
  34. package/dist/avm1/avm1.d.ts +55 -0
  35. package/dist/avm1/avm1.js +642 -0
  36. package/dist/avm1/project.d.ts +16 -0
  37. package/dist/avm1/project.js +81 -0
  38. package/dist/cjs/abc/abc-file.d.ts +168 -0
  39. package/dist/cjs/abc/abc-file.js +663 -0
  40. package/dist/cjs/abc/analysis.d.ts +36 -0
  41. package/dist/cjs/abc/analysis.js +221 -0
  42. package/dist/cjs/abc/code.d.ts +59 -0
  43. package/dist/cjs/abc/code.js +387 -0
  44. package/dist/cjs/abc/constants.d.ts +80 -0
  45. package/dist/cjs/abc/constants.js +97 -0
  46. package/dist/cjs/abc/interner.d.ts +46 -0
  47. package/dist/cjs/abc/interner.js +172 -0
  48. package/dist/cjs/abc/model.d.ts +40 -0
  49. package/dist/cjs/abc/model.js +155 -0
  50. package/dist/cjs/abc/opcodes.d.ts +39 -0
  51. package/dist/cjs/abc/opcodes.js +201 -0
  52. package/dist/cjs/abc/pcode/assembler.d.ts +42 -0
  53. package/dist/cjs/abc/pcode/assembler.js +640 -0
  54. package/dist/cjs/abc/pcode/disassembler.d.ts +17 -0
  55. package/dist/cjs/abc/pcode/disassembler.js +152 -0
  56. package/dist/cjs/abc/pcode/format.d.ts +23 -0
  57. package/dist/cjs/abc/pcode/format.js +141 -0
  58. package/dist/cjs/abc/pcode/lexer.d.ts +34 -0
  59. package/dist/cjs/abc/pcode/lexer.js +188 -0
  60. package/dist/cjs/assets/assets.d.ts +26 -0
  61. package/dist/cjs/assets/assets.js +159 -0
  62. package/dist/cjs/assets/images.d.ts +31 -0
  63. package/dist/cjs/assets/images.js +246 -0
  64. package/dist/cjs/assets/png.d.ts +12 -0
  65. package/dist/cjs/assets/png.js +202 -0
  66. package/dist/cjs/assets/sounds.d.ts +37 -0
  67. package/dist/cjs/assets/sounds.js +246 -0
  68. package/dist/cjs/avm1/avm1.d.ts +55 -0
  69. package/dist/cjs/avm1/avm1.js +649 -0
  70. package/dist/cjs/avm1/project.d.ts +16 -0
  71. package/dist/cjs/avm1/project.js +88 -0
  72. package/dist/cjs/compiler/ast.d.ts +285 -0
  73. package/dist/cjs/compiler/ast.js +3 -0
  74. package/dist/cjs/compiler/class-compiler.d.ts +34 -0
  75. package/dist/cjs/compiler/class-compiler.js +440 -0
  76. package/dist/cjs/compiler/codegen.d.ts +144 -0
  77. package/dist/cjs/compiler/codegen.js +1589 -0
  78. package/dist/cjs/compiler/lexer.d.ts +27 -0
  79. package/dist/cjs/compiler/lexer.js +254 -0
  80. package/dist/cjs/compiler/parser.d.ts +58 -0
  81. package/dist/cjs/compiler/parser.js +989 -0
  82. package/dist/cjs/compiler/program.d.ts +29 -0
  83. package/dist/cjs/compiler/program.js +36 -0
  84. package/dist/cjs/compiler/scope.d.ts +22 -0
  85. package/dist/cjs/compiler/scope.js +242 -0
  86. package/dist/cjs/compression/lzma.d.ts +37 -0
  87. package/dist/cjs/compression/lzma.js +575 -0
  88. package/dist/cjs/compression/swf-container.d.ts +19 -0
  89. package/dist/cjs/compression/swf-container.js +92 -0
  90. package/dist/cjs/decompiler/ast.d.ts +228 -0
  91. package/dist/cjs/decompiler/ast.js +455 -0
  92. package/dist/cjs/decompiler/cfg.d.ts +40 -0
  93. package/dist/cjs/decompiler/cfg.js +236 -0
  94. package/dist/cjs/decompiler/class-printer.d.ts +9 -0
  95. package/dist/cjs/decompiler/class-printer.js +173 -0
  96. package/dist/cjs/decompiler/method.d.ts +41 -0
  97. package/dist/cjs/decompiler/method.js +436 -0
  98. package/dist/cjs/decompiler/simulate.d.ts +55 -0
  99. package/dist/cjs/decompiler/simulate.js +591 -0
  100. package/dist/cjs/decompiler/structure.d.ts +48 -0
  101. package/dist/cjs/decompiler/structure.js +764 -0
  102. package/dist/cjs/errors.d.ts +11 -0
  103. package/dist/cjs/errors.js +25 -0
  104. package/dist/cjs/index.d.ts +41 -0
  105. package/dist/cjs/index.js +82 -0
  106. package/dist/cjs/io/reader.d.ts +48 -0
  107. package/dist/cjs/io/reader.js +180 -0
  108. package/dist/cjs/io/writer.d.ts +37 -0
  109. package/dist/cjs/io/writer.js +175 -0
  110. package/dist/cjs/package.json +1 -0
  111. package/dist/cjs/project/pcode-project.d.ts +32 -0
  112. package/dist/cjs/project/pcode-project.js +210 -0
  113. package/dist/cjs/project/source-export.d.ts +12 -0
  114. package/dist/cjs/project/source-export.js +51 -0
  115. package/dist/cjs/project/source-import.d.ts +13 -0
  116. package/dist/cjs/project/source-import.js +73 -0
  117. package/dist/cjs/swf/swf.d.ts +63 -0
  118. package/dist/cjs/swf/swf.js +147 -0
  119. package/dist/cjs/swf/tag-codes.d.ts +77 -0
  120. package/dist/cjs/swf/tag-codes.js +109 -0
  121. package/dist/cjs/swf/tags.d.ts +118 -0
  122. package/dist/cjs/swf/tags.js +330 -0
  123. package/dist/cli.d.ts +2 -0
  124. package/dist/cli.js +296 -0
  125. package/dist/compiler/ast.d.ts +285 -0
  126. package/dist/compiler/ast.js +2 -0
  127. package/dist/compiler/class-compiler.d.ts +34 -0
  128. package/dist/compiler/class-compiler.js +437 -0
  129. package/dist/compiler/codegen.d.ts +144 -0
  130. package/dist/compiler/codegen.js +1585 -0
  131. package/dist/compiler/lexer.d.ts +27 -0
  132. package/dist/compiler/lexer.js +249 -0
  133. package/dist/compiler/parser.d.ts +58 -0
  134. package/dist/compiler/parser.js +984 -0
  135. package/dist/compiler/program.d.ts +29 -0
  136. package/dist/compiler/program.js +32 -0
  137. package/dist/compiler/scope.d.ts +22 -0
  138. package/dist/compiler/scope.js +238 -0
  139. package/dist/compression/lzma.d.ts +37 -0
  140. package/dist/compression/lzma.js +569 -0
  141. package/dist/compression/swf-container.d.ts +19 -0
  142. package/dist/compression/swf-container.js +87 -0
  143. package/dist/decompiler/ast.d.ts +228 -0
  144. package/dist/decompiler/ast.js +441 -0
  145. package/dist/decompiler/cfg.d.ts +40 -0
  146. package/dist/decompiler/cfg.js +231 -0
  147. package/dist/decompiler/class-printer.d.ts +9 -0
  148. package/dist/decompiler/class-printer.js +170 -0
  149. package/dist/decompiler/method.d.ts +41 -0
  150. package/dist/decompiler/method.js +427 -0
  151. package/dist/decompiler/simulate.d.ts +55 -0
  152. package/dist/decompiler/simulate.js +586 -0
  153. package/dist/decompiler/structure.d.ts +48 -0
  154. package/dist/decompiler/structure.js +760 -0
  155. package/dist/errors.d.ts +11 -0
  156. package/dist/errors.js +20 -0
  157. package/dist/index.d.ts +41 -0
  158. package/dist/index.js +49 -0
  159. package/dist/io/reader.d.ts +48 -0
  160. package/dist/io/reader.js +176 -0
  161. package/dist/io/writer.d.ts +37 -0
  162. package/dist/io/writer.js +169 -0
  163. package/dist/project/pcode-project.d.ts +32 -0
  164. package/dist/project/pcode-project.js +203 -0
  165. package/dist/project/source-export.d.ts +12 -0
  166. package/dist/project/source-export.js +47 -0
  167. package/dist/project/source-import.d.ts +13 -0
  168. package/dist/project/source-import.js +70 -0
  169. package/dist/swf/swf.d.ts +63 -0
  170. package/dist/swf/swf.js +143 -0
  171. package/dist/swf/tag-codes.d.ts +77 -0
  172. package/dist/swf/tag-codes.js +105 -0
  173. package/dist/swf/tags.d.ts +118 -0
  174. package/dist/swf/tags.js +316 -0
  175. package/package.json +71 -4
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Whole-program helpers: compile AS3 sources into a fresh ABC / SWF.
3
+ */
4
+ import { AbcFile } from '../abc/abc-file.js';
5
+ import { Swf } from '../swf/swf.js';
6
+ import { type CompileClassResult } from './class-compiler.js';
7
+ export interface SourceFile {
8
+ /** File name (used in error messages). */
9
+ name: string;
10
+ text: string;
11
+ }
12
+ /** Compiles source files into `abc` (a new ABC when omitted). */
13
+ export declare function compileSources(sources: SourceFile[], abc?: AbcFile): {
14
+ abc: AbcFile;
15
+ result: CompileClassResult;
16
+ };
17
+ export interface CreateSwfOptions {
18
+ /** Fully qualified document class (instantiated as the main timeline). */
19
+ documentClass: string;
20
+ width?: number;
21
+ height?: number;
22
+ frameRate?: number;
23
+ /** SWF version (default 15). */
24
+ version?: number;
25
+ /** RGB background colour (default white). */
26
+ background?: number;
27
+ }
28
+ /** Builds a minimal AS3 SWF around an ABC. */
29
+ export declare function createSwf(abc: AbcFile, options: CreateSwfOptions): Swf;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileSources = compileSources;
4
+ exports.createSwf = createSwf;
5
+ /**
6
+ * Whole-program helpers: compile AS3 sources into a fresh ABC / SWF.
7
+ */
8
+ const abc_file_js_1 = require("../abc/abc-file.js");
9
+ const interner_js_1 = require("../abc/interner.js");
10
+ const swf_js_1 = require("../swf/swf.js");
11
+ const tag_codes_js_1 = require("../swf/tag-codes.js");
12
+ const tags_js_1 = require("../swf/tags.js");
13
+ const class_compiler_js_1 = require("./class-compiler.js");
14
+ /** Compiles source files into `abc` (a new ABC when omitted). */
15
+ function compileSources(sources, abc = new abc_file_js_1.AbcFile()) {
16
+ const interner = new interner_js_1.Interner(abc);
17
+ const result = { changes: [] };
18
+ for (const f of sources) {
19
+ const r = (0, class_compiler_js_1.compileClassSource)(abc, f.text, { source: f.name, interner, baseline: null });
20
+ result.changes.push(...r.changes);
21
+ }
22
+ return { abc, result };
23
+ }
24
+ /** Builds a minimal AS3 SWF around an ABC. */
25
+ function createSwf(abc, options) {
26
+ const bg = options.background ?? 0xffffff;
27
+ const swf = new swf_js_1.Swf({
28
+ version: options.version ?? 15,
29
+ compression: 'zlib',
30
+ frameSize: { xMin: 0, xMax: (options.width ?? 550) * 20, yMin: 0, yMax: (options.height ?? 400) * 20 },
31
+ frameRate: options.frameRate ?? 24,
32
+ frameCount: 1,
33
+ });
34
+ swf.tags.push(new tags_js_1.FileAttributesTag(0x08 | 0x01), new tags_js_1.RawTag(tag_codes_js_1.TagCode.SetBackgroundColor, new Uint8Array([(bg >> 16) & 0xff, (bg >> 8) & 0xff, bg & 0xff])), tags_js_1.DoABCTag.create(abc, 'main'), new tags_js_1.SymbolTableTag(tag_codes_js_1.TagCode.SymbolClass, [{ id: 0, name: options.documentClass }]), new tags_js_1.RawTag(tag_codes_js_1.TagCode.ShowFrame, new Uint8Array(0)), new tags_js_1.RawTag(tag_codes_js_1.TagCode.End, new Uint8Array(0)));
35
+ return swf;
36
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Builds the name-resolution environment (open namespaces, type resolution)
3
+ * for compiling code that belongs to a class of an existing ABC.
4
+ */
5
+ import type { AbcFile } from '../abc/abc-file.js';
6
+ import type { Interner } from '../abc/interner.js';
7
+ import { type ClassScope } from './codegen.js';
8
+ export interface ScopeInput {
9
+ abc: AbcFile;
10
+ pool: Interner;
11
+ pkg: string;
12
+ imports: string[];
13
+ useNamespaces: string[];
14
+ /** Existing class index, or -1 for code outside an existing class. */
15
+ classIndex: number;
16
+ /** Local member names of the class (they shadow imports). */
17
+ memberNames: Set<string>;
18
+ source?: string;
19
+ }
20
+ export declare function buildClassScope(input: ScopeInput): ClassScope;
21
+ /** Namespace for a member declared with the given access keyword. */
22
+ export declare function memberNamespace(scope: ClassScope, access: string): number;
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildClassScope = buildClassScope;
4
+ exports.memberNamespace = memberNamespace;
5
+ const code_js_1 = require("../abc/code.js");
6
+ const constants_js_1 = require("../abc/constants.js");
7
+ const model_js_1 = require("../abc/model.js");
8
+ const codegen_js_1 = require("./codegen.js");
9
+ const AS3_NS = 'http://adobe.com/AS3/2006/builtin';
10
+ /** Package names → short names, harvested from QNames in the constant pool. */
11
+ function knownQNames(abc) {
12
+ const map = new Map();
13
+ for (const m of abc.multinames) {
14
+ if (m.kind !== constants_js_1.MultinameKind.QName)
15
+ continue;
16
+ const ns = abc.namespaces[m.ns];
17
+ if (!ns || ns.kind !== constants_js_1.NamespaceKind.PackageNamespace)
18
+ continue;
19
+ const name = abc.strings[m.name];
20
+ if (!name)
21
+ continue;
22
+ const pkg = abc.strings[ns.name] ?? '';
23
+ let set = map.get(name);
24
+ if (!set)
25
+ map.set(name, (set = new Set()));
26
+ set.add(pkg);
27
+ }
28
+ return map;
29
+ }
30
+ const knownCache = new WeakMap();
31
+ /** The namespace set most used by a class's existing code (its "open namespaces"). */
32
+ function classNsSet(abc, classIndex) {
33
+ const counts = new Map();
34
+ for (const r of (0, model_js_1.classMethods)(abc, classIndex, false)) {
35
+ const body = abc.methodBody(r.methodIndex);
36
+ if (!body)
37
+ continue;
38
+ let items;
39
+ try {
40
+ items = (0, code_js_1.decodeCode)(body.code, body.exceptions).items;
41
+ }
42
+ catch {
43
+ continue;
44
+ }
45
+ for (const it of items) {
46
+ if (it.type !== 'op')
47
+ continue;
48
+ for (const a of it.args) {
49
+ const m = abc.multinames[a];
50
+ if (m && (m.kind === constants_js_1.MultinameKind.Multiname || m.kind === constants_js_1.MultinameKind.MultinameL) && m.nsSet) {
51
+ counts.set(m.nsSet, (counts.get(m.nsSet) ?? 0) + 1);
52
+ }
53
+ }
54
+ }
55
+ }
56
+ let best = -1;
57
+ for (const [s, n] of counts)
58
+ if (best < 0 || n > counts.get(best))
59
+ best = s;
60
+ return best >= 0 ? [...abc.nsSets[best]] : undefined;
61
+ }
62
+ function lastSegment(uri) {
63
+ return uri.split(/[/:]/).filter(Boolean).pop() ?? '';
64
+ }
65
+ function buildClassScope(input) {
66
+ const { abc, pool, pkg, classIndex } = input;
67
+ const pkgNs = (p) => pool.namespace(constants_js_1.NamespaceKind.PackageNamespace, p);
68
+ const inst = classIndex >= 0 ? abc.instances[classIndex] : undefined;
69
+ // Namespaces of the class.
70
+ let privateNs;
71
+ const findPrivate = (traits) => {
72
+ for (const t of traits) {
73
+ const m = abc.multinames[t.name];
74
+ const ns = m ? abc.namespaces[m.ns] : undefined;
75
+ if (ns && ns.kind === constants_js_1.NamespaceKind.PrivateNs && privateNs === undefined)
76
+ privateNs = m.ns;
77
+ }
78
+ };
79
+ if (inst) {
80
+ findPrivate(inst.traits);
81
+ findPrivate(abc.classes[classIndex].traits);
82
+ }
83
+ const existingSet = classIndex >= 0 ? classNsSet(abc, classIndex) : undefined;
84
+ if (privateNs === undefined && existingSet)
85
+ privateNs = existingSet.find((n) => abc.namespaces[n]?.kind === constants_js_1.NamespaceKind.PrivateNs);
86
+ if (privateNs === undefined) {
87
+ const cname = inst ? abc.multinameName(inst.name) : 'script';
88
+ privateNs = pool.addNs(constants_js_1.NamespaceKind.PrivateNs, pool.string(pkg ? `${pkg}:${cname}` : cname));
89
+ }
90
+ const protectedNs = inst && inst.protectedNs ? inst.protectedNs : undefined;
91
+ let staticProtectedNs;
92
+ if (existingSet)
93
+ staticProtectedNs = existingSet.find((n) => abc.namespaces[n]?.kind === constants_js_1.NamespaceKind.StaticProtectedNs);
94
+ if (staticProtectedNs === undefined && inst) {
95
+ for (const t of abc.classes[classIndex].traits) {
96
+ const m = abc.multinames[t.name];
97
+ if (m && abc.namespaces[m.ns]?.kind === constants_js_1.NamespaceKind.StaticProtectedNs)
98
+ staticProtectedNs = m.ns;
99
+ }
100
+ }
101
+ if (staticProtectedNs === undefined && inst && protectedNs) {
102
+ staticProtectedNs = pool.namespace(constants_js_1.NamespaceKind.StaticProtectedNs, abc.strings[abc.namespaces[protectedNs].name] ?? '');
103
+ }
104
+ const custom = new Map();
105
+ abc.namespaces.forEach((ns, i) => {
106
+ if (i === 0 || ns.kind !== constants_js_1.NamespaceKind.Namespace)
107
+ return;
108
+ const uri = abc.strings[ns.name] ?? '';
109
+ const seg = lastSegment(uri);
110
+ if (seg && !custom.has(seg))
111
+ custom.set(seg, i);
112
+ });
113
+ // Open namespace set.
114
+ const set = existingSet ? [...existingSet] : [];
115
+ const add = (n) => {
116
+ if (n !== undefined && !set.includes(n))
117
+ set.push(n);
118
+ };
119
+ add(privateNs);
120
+ add(pkgNs(''));
121
+ add(pkgNs(pkg));
122
+ add(pool.namespace(constants_js_1.NamespaceKind.PackageInternalNs, pkg));
123
+ add(protectedNs);
124
+ add(staticProtectedNs);
125
+ // Every namespace the class's own members live in (static protected, custom...).
126
+ if (inst) {
127
+ for (const t of [...inst.traits, ...abc.classes[classIndex].traits]) {
128
+ const m = abc.multinames[t.name];
129
+ if (m && (m.kind === constants_js_1.MultinameKind.QName || m.kind === constants_js_1.MultinameKind.QNameA) && m.ns)
130
+ add(m.ns);
131
+ }
132
+ }
133
+ add(pool.namespace(constants_js_1.NamespaceKind.Namespace, AS3_NS));
134
+ for (const imp of input.imports) {
135
+ const dot = imp.lastIndexOf('.');
136
+ if (dot > 0)
137
+ add(pkgNs(imp.slice(0, dot)));
138
+ }
139
+ for (const u of input.useNamespaces)
140
+ add(custom.get(lastSegment(u)) ?? custom.get(u));
141
+ const openNsSet = pool.nsSet(set);
142
+ // Type resolution.
143
+ let known = knownCache.get(abc);
144
+ if (!known)
145
+ knownCache.set(abc, (known = knownQNames(abc)));
146
+ const definedClasses = new Map();
147
+ for (let c = 0; c < abc.instances.length; c++) {
148
+ const q = abc.className(c);
149
+ const dot = q.lastIndexOf('.');
150
+ const short = dot >= 0 ? q.slice(dot + 1) : q;
151
+ let s = definedClasses.get(short);
152
+ if (!s)
153
+ definedClasses.set(short, (s = new Set()));
154
+ s.add(dot >= 0 ? q.slice(0, dot) : '');
155
+ }
156
+ const explicitImports = new Map();
157
+ const wildcard = [];
158
+ for (const imp of input.imports) {
159
+ if (imp.endsWith('.*'))
160
+ wildcard.push(imp.slice(0, -2));
161
+ else {
162
+ const dot = imp.lastIndexOf('.');
163
+ explicitImports.set(imp.slice(dot + 1), dot > 0 ? imp.slice(0, dot) : '');
164
+ }
165
+ }
166
+ /** Package for a short class name, or undefined when unknown. */
167
+ const packageOf = (short) => {
168
+ const imp = explicitImports.get(short);
169
+ if (imp !== undefined)
170
+ return imp;
171
+ const defined = definedClasses.get(short);
172
+ if (defined?.has(pkg))
173
+ return pkg;
174
+ if (codegen_js_1.TOPLEVEL_NAMES.has(short))
175
+ return '';
176
+ const candidates = new Set([...(defined ?? []), ...(known.get(short) ?? [])]);
177
+ for (const w of wildcard)
178
+ if (candidates.has(w))
179
+ return w;
180
+ if (candidates.has(''))
181
+ return '';
182
+ if (candidates.size === 1)
183
+ return [...candidates][0];
184
+ return undefined;
185
+ };
186
+ const resolveType = (t) => {
187
+ if (t.name === '*')
188
+ return 0;
189
+ if (t.params) {
190
+ const base = resolveType({ name: t.name === 'Vector' ? '__AS3__.vec.Vector' : t.name, pos: t.pos });
191
+ return pool.multiname({ kind: constants_js_1.MultinameKind.TypeName, base, params: t.params.map(resolveType) });
192
+ }
193
+ const dot = t.name.lastIndexOf('.');
194
+ if (dot > 0)
195
+ return pool.qname(pkgNs(t.name.slice(0, dot)), t.name.slice(dot + 1));
196
+ const p = t.name === 'Vector' ? '__AS3__.vec' : packageOf(t.name);
197
+ if (p !== undefined)
198
+ return pool.qname(pkgNs(p), t.name);
199
+ return pool.multiname({ kind: constants_js_1.MultinameKind.Multiname, name: pool.string(t.name), nsSet: openNsSet });
200
+ };
201
+ const resolveName = (name) => {
202
+ if (input.memberNames.has(name))
203
+ return undefined;
204
+ if (name === 'Vector')
205
+ return pool.qname(pkgNs('__AS3__.vec'), 'Vector');
206
+ if (explicitImports.has(name))
207
+ return pool.qname(pkgNs(explicitImports.get(name)), name);
208
+ if (!/^[A-Z]/.test(name) && !codegen_js_1.TOPLEVEL_NAMES.has(name))
209
+ return undefined;
210
+ const p = explicitImports.get(name) ?? (definedClasses.get(name)?.has(pkg) ? pkg : undefined) ?? (codegen_js_1.TOPLEVEL_NAMES.has(name) ? '' : undefined);
211
+ return p === undefined ? undefined : pool.qname(pkgNs(p), name);
212
+ };
213
+ const namespaceByName = (name) => {
214
+ switch (name) {
215
+ case 'private':
216
+ return privateNs;
217
+ case 'protected':
218
+ return protectedNs;
219
+ case 'static protected':
220
+ return staticProtectedNs ?? protectedNs;
221
+ case 'public':
222
+ return pkgNs('');
223
+ case 'internal':
224
+ return pool.namespace(constants_js_1.NamespaceKind.PackageInternalNs, pkg);
225
+ case 'AS3':
226
+ return pool.namespace(constants_js_1.NamespaceKind.Namespace, AS3_NS);
227
+ default:
228
+ return custom.get(name);
229
+ }
230
+ };
231
+ return { abc, pool, pkg, openNsSet, namespaceByName, resolveType, resolveName, source: input.source };
232
+ }
233
+ /** Namespace for a member declared with the given access keyword. */
234
+ function memberNamespace(scope, access) {
235
+ if (access.startsWith('ns:')) {
236
+ const n = scope.namespaceByName(access.slice(3));
237
+ if (n === undefined)
238
+ throw new Error(`Unknown namespace '${access.slice(3)}'`);
239
+ return n;
240
+ }
241
+ return scope.namespaceByName(access === 'internal' ? 'internal' : access);
242
+ }
@@ -0,0 +1,37 @@
1
+ export interface LzmaProperties {
2
+ lc: number;
3
+ lp: number;
4
+ pb: number;
5
+ dictSize: number;
6
+ }
7
+ export declare function parseLzmaProperties(props: Uint8Array): LzmaProperties;
8
+ export declare function encodeLzmaProperties(p: LzmaProperties): Uint8Array;
9
+ /**
10
+ * Decompress raw LZMA data.
11
+ * @param props 5-byte LZMA properties
12
+ * @param data compressed stream (without properties)
13
+ * @param outSize exact uncompressed size
14
+ */
15
+ export declare function lzmaDecompress(props: Uint8Array, data: Uint8Array, outSize: number): Uint8Array;
16
+ export interface LzmaCompressOptions {
17
+ /** Literal context bits (0-8). Default 3. */
18
+ lc?: number;
19
+ /** Literal position bits (0-4). Default 0. */
20
+ lp?: number;
21
+ /** Position bits (0-4). Default 2. */
22
+ pb?: number;
23
+ /** Dictionary size in bytes. Defaults to the input size rounded up to a power of two (max 64 MiB). */
24
+ dictSize?: number;
25
+ /** Maximum hash-chain depth for the match finder. Higher = better ratio, slower. Default 48. */
26
+ depth?: number;
27
+ /** Stop searching once a match of this length is found. Default 128. */
28
+ niceLength?: number;
29
+ }
30
+ /**
31
+ * Compress data with LZMA. Returns the 5-byte properties and the raw stream
32
+ * (no end marker, no size header), as stored in ZWS SWF files.
33
+ */
34
+ export declare function lzmaCompress(input: Uint8Array, options?: LzmaCompressOptions): {
35
+ props: Uint8Array;
36
+ data: Uint8Array;
37
+ };