autoangel 0.6.4

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 ADDED
@@ -0,0 +1,179 @@
1
+ # autoangel-wasm
2
+
3
+ WebAssembly bindings for parsing Angelica Engine game files in the browser and Node.js.
4
+
5
+ ## Installation
6
+
7
+ ### npm
8
+
9
+ ```bash
10
+ npm install autoangel
11
+ ```
12
+
13
+ ### CDN
14
+
15
+ ```js
16
+ import init, { ElementsData, PckPackage } from 'https://cdn.jsdelivr.net/npm/autoangel@0.6.4/autoangel.js';
17
+ await init();
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Browser — elements.data
23
+
24
+ ```js
25
+ import init, { ElementsData } from 'autoangel';
26
+
27
+ await init();
28
+
29
+ const response = await fetch('elements.data');
30
+ const bytes = new Uint8Array(await response.arrayBuffer());
31
+
32
+ const data = ElementsData.parse(bytes);
33
+ console.log(`Version: ${data.version}, lists: ${data.listCount}`);
34
+
35
+ const list = data.getList(3);
36
+ console.log(`List: ${list.caption}, entries: ${list.entryCount}`);
37
+
38
+ const entry = list.getEntry(0);
39
+ console.log(`Name: ${entry.getField('Name')}`);
40
+
41
+ entry.free();
42
+ list.free();
43
+ data.free();
44
+ ```
45
+
46
+ ### Browser — pck packages
47
+
48
+ ```js
49
+ import init, { PckPackage } from 'autoangel';
50
+
51
+ await init();
52
+
53
+ const bytes = new Uint8Array(await file.arrayBuffer());
54
+ const pkg = PckPackage.parse(bytes);
55
+
56
+ console.log(`Files: ${pkg.fileCount}`);
57
+
58
+ const content = pkg.getFile('some/path/in/package.txt');
59
+ // content is Uint8Array or undefined
60
+
61
+ pkg.free();
62
+ ```
63
+
64
+ ### Node.js
65
+
66
+ ```js
67
+ import { readFileSync } from 'node:fs';
68
+ import { ElementsData } from './pkg-node/autoangel.js';
69
+
70
+ const bytes = readFileSync('elements.data');
71
+ const data = ElementsData.parse(bytes);
72
+ // ... same API as browser
73
+ data.free();
74
+ ```
75
+
76
+ Build for Node.js with `wasm-pack build --target nodejs --out-dir pkg-node`.
77
+
78
+ ## Memory Management
79
+
80
+ WASM objects allocate memory on the WASM heap and must be freed manually:
81
+
82
+ ```js
83
+ const data = ElementsData.parse(bytes);
84
+ // ... use data ...
85
+ data.free();
86
+ ```
87
+
88
+ With [explicit resource management](https://github.com/tc39/proposal-explicit-resource-management) (TypeScript 5.2+):
89
+
90
+ ```ts
91
+ using data = ElementsData.parse(bytes);
92
+ // automatically freed at end of scope
93
+ ```
94
+
95
+ Objects that are not freed will leak memory until the page is reloaded.
96
+
97
+ ## API Reference
98
+
99
+ ### `ElementsConfig`
100
+
101
+ | | |
102
+ |---|---|
103
+ | `ElementsConfig.parse(content, game)` | Parse config from text for a given game dialect |
104
+ | `.name` | Config name (or `undefined`) |
105
+ | `.listCount` | Number of lists |
106
+
107
+ ### `ElementsData`
108
+
109
+ | | |
110
+ |---|---|
111
+ | `ElementsData.parse(bytes, config?)` | Parse from `Uint8Array`; auto-detects config if omitted |
112
+ | `.version` | Data format version |
113
+ | `.listCount` | Number of lists |
114
+ | `.getList(index)` | Get list by index |
115
+ | `.findEntry(id)` | Find entry by ID across all lists |
116
+ | `.saveBytes()` | Serialize to `Uint8Array` |
117
+
118
+ ### `ElementsDataList`
119
+
120
+ | | |
121
+ |---|---|
122
+ | `.caption` | List name |
123
+ | `.entryCount` | Number of entries |
124
+ | `.getEntry(index)` | Get entry by index |
125
+ | `.fieldNames()` | Get field name list |
126
+
127
+ ### `ElementsDataEntry`
128
+
129
+ | | |
130
+ |---|---|
131
+ | `.getField(name)` | Get field value by name |
132
+ | `.keys()` | Get all field names |
133
+ | `.toString()` | String representation |
134
+
135
+ ### `PackageConfig`
136
+
137
+ | | |
138
+ |---|---|
139
+ | `new PackageConfig()` | Create with default encryption keys |
140
+ | `PackageConfig.withKeys(k1, k2, g1, g2)` | Create with custom keys |
141
+ | `.key1`, `.key2`, `.guard1`, `.guard2` | Key/guard values |
142
+
143
+ ### `PckPackage`
144
+
145
+ | | |
146
+ |---|---|
147
+ | `PckPackage.parse(bytes, config?)` | Parse from `Uint8Array` |
148
+ | `.version` | Package format version |
149
+ | `.fileCount` | Number of files |
150
+ | `.fileList()` | Get all file paths |
151
+ | `.findPrefix(prefix)` | Find files matching prefix |
152
+ | `.getFile(path)` | Extract file content (`Uint8Array` or `undefined`) |
153
+
154
+ Full TypeScript definitions are included in the package (`autoangel.d.ts`).
155
+
156
+ ## Live Demo
157
+
158
+ A browser-based PCK viewer built with this package is available at [smertig.github.io/pypck_alpha](https://smertig.github.io/pypck_alpha/master/viewer/).
159
+
160
+ ## Development
161
+
162
+ Requires Rust (1.94.1+), [wasm-pack](https://rustwasm.github.io/wasm-pack/), and Node.js 20+.
163
+
164
+ ```bash
165
+ # Build for browser
166
+ wasm-pack build --target web
167
+
168
+ # Build for Node.js
169
+ wasm-pack build --target nodejs --out-dir pkg-node
170
+
171
+ # Run tests (requires Node.js build)
172
+ node --test tests/test.mjs
173
+ ```
174
+
175
+ The crate depends on `autoangel-core` with `default-features = false` — no filesystem or mmap, all parsing works from byte arrays.
176
+
177
+ ## License
178
+
179
+ [MIT License](../LICENSE)
package/autoangel.d.ts ADDED
@@ -0,0 +1,226 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Configuration for parsing elements.data files.
6
+ */
7
+ export class ElementsConfig {
8
+ private constructor();
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ /**
12
+ * Parse a config from its text content.
13
+ * `game` must be `"pw"` (Perfect World). More games may be supported in the future.
14
+ */
15
+ static parse(content: string, game: string): ElementsConfig;
16
+ /**
17
+ * Number of lists in this config.
18
+ */
19
+ readonly listCount: number;
20
+ /**
21
+ * Config name, if available.
22
+ */
23
+ readonly name: string | undefined;
24
+ }
25
+
26
+ /**
27
+ * Parsed elements.data file.
28
+ */
29
+ export class ElementsData {
30
+ private constructor();
31
+ free(): void;
32
+ [Symbol.dispose](): void;
33
+ /**
34
+ * Find an entry by ID across all lists.
35
+ */
36
+ findEntry(id: number): ElementsDataEntry | undefined;
37
+ /**
38
+ * Get a list by index.
39
+ */
40
+ getList(index: number): ElementsDataList;
41
+ /**
42
+ * Parse elements.data from a byte array, optionally with a specific config.
43
+ * If `config` is not provided, a bundled config is chosen based on the data version.
44
+ */
45
+ static parse(bytes: Uint8Array, config?: ElementsConfig | null): ElementsData;
46
+ /**
47
+ * Save elements.data to a byte array.
48
+ */
49
+ saveBytes(): Uint8Array;
50
+ /**
51
+ * Number of lists.
52
+ */
53
+ readonly listCount: number;
54
+ /**
55
+ * Data version number.
56
+ */
57
+ readonly version: number;
58
+ }
59
+
60
+ /**
61
+ * A single entry (row) within a data list.
62
+ */
63
+ export class ElementsDataEntry {
64
+ private constructor();
65
+ free(): void;
66
+ [Symbol.dispose](): void;
67
+ /**
68
+ * Get a field value by name. Returns a JS value (number, string, or Uint8Array).
69
+ */
70
+ getField(name: string): any;
71
+ /**
72
+ * Get all field names.
73
+ */
74
+ keys(): string[];
75
+ /**
76
+ * String representation of this entry.
77
+ */
78
+ toString(): string;
79
+ }
80
+
81
+ /**
82
+ * A single list within elements.data.
83
+ */
84
+ export class ElementsDataList {
85
+ private constructor();
86
+ free(): void;
87
+ [Symbol.dispose](): void;
88
+ /**
89
+ * Field names for entries in this list.
90
+ */
91
+ fieldNames(): string[];
92
+ /**
93
+ * Get an entry by index.
94
+ */
95
+ getEntry(index: number): ElementsDataEntry;
96
+ /**
97
+ * List caption/name.
98
+ */
99
+ readonly caption: string;
100
+ /**
101
+ * Number of entries.
102
+ */
103
+ readonly entryCount: number;
104
+ }
105
+
106
+ /**
107
+ * Configuration for pck package parsing (encryption keys and guards).
108
+ */
109
+ export class PackageConfig {
110
+ free(): void;
111
+ [Symbol.dispose](): void;
112
+ /**
113
+ * Create a new PackageConfig with default keys.
114
+ */
115
+ constructor();
116
+ /**
117
+ * Create a PackageConfig with custom keys.
118
+ */
119
+ static withKeys(key1: number, key2: number, guard1: number, guard2: number): PackageConfig;
120
+ readonly guard1: number;
121
+ readonly guard2: number;
122
+ readonly key1: number;
123
+ readonly key2: number;
124
+ }
125
+
126
+ /**
127
+ * Parsed pck/pkx package.
128
+ */
129
+ export class PckPackage {
130
+ private constructor();
131
+ free(): void;
132
+ [Symbol.dispose](): void;
133
+ /**
134
+ * List all file paths in the package.
135
+ */
136
+ fileList(): string[];
137
+ /**
138
+ * Find files matching a path prefix. Returns an array of normalized file paths.
139
+ */
140
+ findPrefix(prefix: string): string[];
141
+ /**
142
+ * Get decompressed file content by path. Returns null if not found.
143
+ */
144
+ getFile(path: string): Uint8Array | undefined;
145
+ /**
146
+ * Parse a pck package from bytes.
147
+ */
148
+ static parse(bytes: Uint8Array, config?: PackageConfig | null): PckPackage;
149
+ /**
150
+ * Number of files in the package.
151
+ */
152
+ readonly fileCount: number;
153
+ /**
154
+ * Package version.
155
+ */
156
+ readonly version: number;
157
+ }
158
+
159
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
160
+
161
+ export interface InitOutput {
162
+ readonly memory: WebAssembly.Memory;
163
+ readonly __wbg_elementsconfig_free: (a: number, b: number) => void;
164
+ readonly __wbg_elementsdata_free: (a: number, b: number) => void;
165
+ readonly __wbg_elementsdataentry_free: (a: number, b: number) => void;
166
+ readonly __wbg_elementsdatalist_free: (a: number, b: number) => void;
167
+ readonly elementsconfig_listCount: (a: number) => number;
168
+ readonly elementsconfig_name: (a: number) => [number, number];
169
+ readonly elementsconfig_parse: (a: number, b: number, c: number, d: number) => [number, number, number];
170
+ readonly elementsdata_findEntry: (a: number, b: number) => number;
171
+ readonly elementsdata_getList: (a: number, b: number) => [number, number, number];
172
+ readonly elementsdata_listCount: (a: number) => number;
173
+ readonly elementsdata_parse: (a: number, b: number, c: number) => [number, number, number];
174
+ readonly elementsdata_saveBytes: (a: number) => [number, number, number, number];
175
+ readonly elementsdata_version: (a: number) => number;
176
+ readonly elementsdataentry_getField: (a: number, b: number, c: number) => [number, number, number];
177
+ readonly elementsdataentry_keys: (a: number) => [number, number];
178
+ readonly elementsdataentry_toString: (a: number) => [number, number];
179
+ readonly elementsdatalist_caption: (a: number) => [number, number];
180
+ readonly elementsdatalist_entryCount: (a: number) => number;
181
+ readonly elementsdatalist_fieldNames: (a: number) => [number, number];
182
+ readonly elementsdatalist_getEntry: (a: number, b: number) => [number, number, number];
183
+ readonly __wbg_packageconfig_free: (a: number, b: number) => void;
184
+ readonly __wbg_pckpackage_free: (a: number, b: number) => void;
185
+ readonly packageconfig_guard1: (a: number) => number;
186
+ readonly packageconfig_guard2: (a: number) => number;
187
+ readonly packageconfig_key1: (a: number) => number;
188
+ readonly packageconfig_key2: (a: number) => number;
189
+ readonly packageconfig_new: () => number;
190
+ readonly packageconfig_withKeys: (a: number, b: number, c: number, d: number) => number;
191
+ readonly pckpackage_fileCount: (a: number) => number;
192
+ readonly pckpackage_fileList: (a: number) => [number, number];
193
+ readonly pckpackage_findPrefix: (a: number, b: number, c: number) => [number, number];
194
+ readonly pckpackage_getFile: (a: number, b: number, c: number) => [number, number];
195
+ readonly pckpackage_parse: (a: number, b: number, c: number) => [number, number, number];
196
+ readonly pckpackage_version: (a: number) => number;
197
+ readonly __wbindgen_externrefs: WebAssembly.Table;
198
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
199
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
200
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
201
+ readonly __externref_table_dealloc: (a: number) => void;
202
+ readonly __externref_drop_slice: (a: number, b: number) => void;
203
+ readonly __wbindgen_start: () => void;
204
+ }
205
+
206
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
207
+
208
+ /**
209
+ * Instantiates the given `module`, which can either be bytes or
210
+ * a precompiled `WebAssembly.Module`.
211
+ *
212
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
213
+ *
214
+ * @returns {InitOutput}
215
+ */
216
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
217
+
218
+ /**
219
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
220
+ * for everything else, calls `WebAssembly.instantiate` directly.
221
+ *
222
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
223
+ *
224
+ * @returns {Promise<InitOutput>}
225
+ */
226
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/autoangel.js ADDED
@@ -0,0 +1,750 @@
1
+ /* @ts-self-types="./autoangel.d.ts" */
2
+
3
+ /**
4
+ * Configuration for parsing elements.data files.
5
+ */
6
+ export class ElementsConfig {
7
+ static __wrap(ptr) {
8
+ ptr = ptr >>> 0;
9
+ const obj = Object.create(ElementsConfig.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ ElementsConfigFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ ElementsConfigFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_elementsconfig_free(ptr, 0);
23
+ }
24
+ /**
25
+ * Number of lists in this config.
26
+ * @returns {number}
27
+ */
28
+ get listCount() {
29
+ const ret = wasm.elementsconfig_listCount(this.__wbg_ptr);
30
+ return ret >>> 0;
31
+ }
32
+ /**
33
+ * Config name, if available.
34
+ * @returns {string | undefined}
35
+ */
36
+ get name() {
37
+ const ret = wasm.elementsconfig_name(this.__wbg_ptr);
38
+ let v1;
39
+ if (ret[0] !== 0) {
40
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
41
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
42
+ }
43
+ return v1;
44
+ }
45
+ /**
46
+ * Parse a config from its text content.
47
+ * `game` must be `"pw"` (Perfect World). More games may be supported in the future.
48
+ * @param {string} content
49
+ * @param {string} game
50
+ * @returns {ElementsConfig}
51
+ */
52
+ static parse(content, game) {
53
+ const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
54
+ const len0 = WASM_VECTOR_LEN;
55
+ const ptr1 = passStringToWasm0(game, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
56
+ const len1 = WASM_VECTOR_LEN;
57
+ const ret = wasm.elementsconfig_parse(ptr0, len0, ptr1, len1);
58
+ if (ret[2]) {
59
+ throw takeFromExternrefTable0(ret[1]);
60
+ }
61
+ return ElementsConfig.__wrap(ret[0]);
62
+ }
63
+ }
64
+ if (Symbol.dispose) ElementsConfig.prototype[Symbol.dispose] = ElementsConfig.prototype.free;
65
+
66
+ /**
67
+ * Parsed elements.data file.
68
+ */
69
+ export class ElementsData {
70
+ static __wrap(ptr) {
71
+ ptr = ptr >>> 0;
72
+ const obj = Object.create(ElementsData.prototype);
73
+ obj.__wbg_ptr = ptr;
74
+ ElementsDataFinalization.register(obj, obj.__wbg_ptr, obj);
75
+ return obj;
76
+ }
77
+ __destroy_into_raw() {
78
+ const ptr = this.__wbg_ptr;
79
+ this.__wbg_ptr = 0;
80
+ ElementsDataFinalization.unregister(this);
81
+ return ptr;
82
+ }
83
+ free() {
84
+ const ptr = this.__destroy_into_raw();
85
+ wasm.__wbg_elementsdata_free(ptr, 0);
86
+ }
87
+ /**
88
+ * Find an entry by ID across all lists.
89
+ * @param {number} id
90
+ * @returns {ElementsDataEntry | undefined}
91
+ */
92
+ findEntry(id) {
93
+ const ret = wasm.elementsdata_findEntry(this.__wbg_ptr, id);
94
+ return ret === 0 ? undefined : ElementsDataEntry.__wrap(ret);
95
+ }
96
+ /**
97
+ * Get a list by index.
98
+ * @param {number} index
99
+ * @returns {ElementsDataList}
100
+ */
101
+ getList(index) {
102
+ const ret = wasm.elementsdata_getList(this.__wbg_ptr, index);
103
+ if (ret[2]) {
104
+ throw takeFromExternrefTable0(ret[1]);
105
+ }
106
+ return ElementsDataList.__wrap(ret[0]);
107
+ }
108
+ /**
109
+ * Number of lists.
110
+ * @returns {number}
111
+ */
112
+ get listCount() {
113
+ const ret = wasm.elementsdata_listCount(this.__wbg_ptr);
114
+ return ret >>> 0;
115
+ }
116
+ /**
117
+ * Parse elements.data from a byte array, optionally with a specific config.
118
+ * If `config` is not provided, a bundled config is chosen based on the data version.
119
+ * @param {Uint8Array} bytes
120
+ * @param {ElementsConfig | null} [config]
121
+ * @returns {ElementsData}
122
+ */
123
+ static parse(bytes, config) {
124
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
125
+ const len0 = WASM_VECTOR_LEN;
126
+ let ptr1 = 0;
127
+ if (!isLikeNone(config)) {
128
+ _assertClass(config, ElementsConfig);
129
+ ptr1 = config.__destroy_into_raw();
130
+ }
131
+ const ret = wasm.elementsdata_parse(ptr0, len0, ptr1);
132
+ if (ret[2]) {
133
+ throw takeFromExternrefTable0(ret[1]);
134
+ }
135
+ return ElementsData.__wrap(ret[0]);
136
+ }
137
+ /**
138
+ * Save elements.data to a byte array.
139
+ * @returns {Uint8Array}
140
+ */
141
+ saveBytes() {
142
+ const ret = wasm.elementsdata_saveBytes(this.__wbg_ptr);
143
+ if (ret[3]) {
144
+ throw takeFromExternrefTable0(ret[2]);
145
+ }
146
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
147
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
148
+ return v1;
149
+ }
150
+ /**
151
+ * Data version number.
152
+ * @returns {number}
153
+ */
154
+ get version() {
155
+ const ret = wasm.elementsdata_version(this.__wbg_ptr);
156
+ return ret;
157
+ }
158
+ }
159
+ if (Symbol.dispose) ElementsData.prototype[Symbol.dispose] = ElementsData.prototype.free;
160
+
161
+ /**
162
+ * A single entry (row) within a data list.
163
+ */
164
+ export class ElementsDataEntry {
165
+ static __wrap(ptr) {
166
+ ptr = ptr >>> 0;
167
+ const obj = Object.create(ElementsDataEntry.prototype);
168
+ obj.__wbg_ptr = ptr;
169
+ ElementsDataEntryFinalization.register(obj, obj.__wbg_ptr, obj);
170
+ return obj;
171
+ }
172
+ __destroy_into_raw() {
173
+ const ptr = this.__wbg_ptr;
174
+ this.__wbg_ptr = 0;
175
+ ElementsDataEntryFinalization.unregister(this);
176
+ return ptr;
177
+ }
178
+ free() {
179
+ const ptr = this.__destroy_into_raw();
180
+ wasm.__wbg_elementsdataentry_free(ptr, 0);
181
+ }
182
+ /**
183
+ * Get a field value by name. Returns a JS value (number, string, or Uint8Array).
184
+ * @param {string} name
185
+ * @returns {any}
186
+ */
187
+ getField(name) {
188
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
189
+ const len0 = WASM_VECTOR_LEN;
190
+ const ret = wasm.elementsdataentry_getField(this.__wbg_ptr, ptr0, len0);
191
+ if (ret[2]) {
192
+ throw takeFromExternrefTable0(ret[1]);
193
+ }
194
+ return takeFromExternrefTable0(ret[0]);
195
+ }
196
+ /**
197
+ * Get all field names.
198
+ * @returns {string[]}
199
+ */
200
+ keys() {
201
+ const ret = wasm.elementsdataentry_keys(this.__wbg_ptr);
202
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
203
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
204
+ return v1;
205
+ }
206
+ /**
207
+ * String representation of this entry.
208
+ * @returns {string}
209
+ */
210
+ toString() {
211
+ let deferred1_0;
212
+ let deferred1_1;
213
+ try {
214
+ const ret = wasm.elementsdataentry_toString(this.__wbg_ptr);
215
+ deferred1_0 = ret[0];
216
+ deferred1_1 = ret[1];
217
+ return getStringFromWasm0(ret[0], ret[1]);
218
+ } finally {
219
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
220
+ }
221
+ }
222
+ }
223
+ if (Symbol.dispose) ElementsDataEntry.prototype[Symbol.dispose] = ElementsDataEntry.prototype.free;
224
+
225
+ /**
226
+ * A single list within elements.data.
227
+ */
228
+ export class ElementsDataList {
229
+ static __wrap(ptr) {
230
+ ptr = ptr >>> 0;
231
+ const obj = Object.create(ElementsDataList.prototype);
232
+ obj.__wbg_ptr = ptr;
233
+ ElementsDataListFinalization.register(obj, obj.__wbg_ptr, obj);
234
+ return obj;
235
+ }
236
+ __destroy_into_raw() {
237
+ const ptr = this.__wbg_ptr;
238
+ this.__wbg_ptr = 0;
239
+ ElementsDataListFinalization.unregister(this);
240
+ return ptr;
241
+ }
242
+ free() {
243
+ const ptr = this.__destroy_into_raw();
244
+ wasm.__wbg_elementsdatalist_free(ptr, 0);
245
+ }
246
+ /**
247
+ * List caption/name.
248
+ * @returns {string}
249
+ */
250
+ get caption() {
251
+ let deferred1_0;
252
+ let deferred1_1;
253
+ try {
254
+ const ret = wasm.elementsdatalist_caption(this.__wbg_ptr);
255
+ deferred1_0 = ret[0];
256
+ deferred1_1 = ret[1];
257
+ return getStringFromWasm0(ret[0], ret[1]);
258
+ } finally {
259
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
260
+ }
261
+ }
262
+ /**
263
+ * Number of entries.
264
+ * @returns {number}
265
+ */
266
+ get entryCount() {
267
+ const ret = wasm.elementsdatalist_entryCount(this.__wbg_ptr);
268
+ return ret >>> 0;
269
+ }
270
+ /**
271
+ * Field names for entries in this list.
272
+ * @returns {string[]}
273
+ */
274
+ fieldNames() {
275
+ const ret = wasm.elementsdatalist_fieldNames(this.__wbg_ptr);
276
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
277
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
278
+ return v1;
279
+ }
280
+ /**
281
+ * Get an entry by index.
282
+ * @param {number} index
283
+ * @returns {ElementsDataEntry}
284
+ */
285
+ getEntry(index) {
286
+ const ret = wasm.elementsdatalist_getEntry(this.__wbg_ptr, index);
287
+ if (ret[2]) {
288
+ throw takeFromExternrefTable0(ret[1]);
289
+ }
290
+ return ElementsDataEntry.__wrap(ret[0]);
291
+ }
292
+ }
293
+ if (Symbol.dispose) ElementsDataList.prototype[Symbol.dispose] = ElementsDataList.prototype.free;
294
+
295
+ /**
296
+ * Configuration for pck package parsing (encryption keys and guards).
297
+ */
298
+ export class PackageConfig {
299
+ static __wrap(ptr) {
300
+ ptr = ptr >>> 0;
301
+ const obj = Object.create(PackageConfig.prototype);
302
+ obj.__wbg_ptr = ptr;
303
+ PackageConfigFinalization.register(obj, obj.__wbg_ptr, obj);
304
+ return obj;
305
+ }
306
+ __destroy_into_raw() {
307
+ const ptr = this.__wbg_ptr;
308
+ this.__wbg_ptr = 0;
309
+ PackageConfigFinalization.unregister(this);
310
+ return ptr;
311
+ }
312
+ free() {
313
+ const ptr = this.__destroy_into_raw();
314
+ wasm.__wbg_packageconfig_free(ptr, 0);
315
+ }
316
+ /**
317
+ * @returns {number}
318
+ */
319
+ get guard1() {
320
+ const ret = wasm.packageconfig_guard1(this.__wbg_ptr);
321
+ return ret >>> 0;
322
+ }
323
+ /**
324
+ * @returns {number}
325
+ */
326
+ get guard2() {
327
+ const ret = wasm.packageconfig_guard2(this.__wbg_ptr);
328
+ return ret >>> 0;
329
+ }
330
+ /**
331
+ * @returns {number}
332
+ */
333
+ get key1() {
334
+ const ret = wasm.packageconfig_key1(this.__wbg_ptr);
335
+ return ret >>> 0;
336
+ }
337
+ /**
338
+ * @returns {number}
339
+ */
340
+ get key2() {
341
+ const ret = wasm.packageconfig_key2(this.__wbg_ptr);
342
+ return ret >>> 0;
343
+ }
344
+ /**
345
+ * Create a new PackageConfig with default keys.
346
+ */
347
+ constructor() {
348
+ const ret = wasm.packageconfig_new();
349
+ this.__wbg_ptr = ret >>> 0;
350
+ PackageConfigFinalization.register(this, this.__wbg_ptr, this);
351
+ return this;
352
+ }
353
+ /**
354
+ * Create a PackageConfig with custom keys.
355
+ * @param {number} key1
356
+ * @param {number} key2
357
+ * @param {number} guard1
358
+ * @param {number} guard2
359
+ * @returns {PackageConfig}
360
+ */
361
+ static withKeys(key1, key2, guard1, guard2) {
362
+ const ret = wasm.packageconfig_withKeys(key1, key2, guard1, guard2);
363
+ return PackageConfig.__wrap(ret);
364
+ }
365
+ }
366
+ if (Symbol.dispose) PackageConfig.prototype[Symbol.dispose] = PackageConfig.prototype.free;
367
+
368
+ /**
369
+ * Parsed pck/pkx package.
370
+ */
371
+ export class PckPackage {
372
+ static __wrap(ptr) {
373
+ ptr = ptr >>> 0;
374
+ const obj = Object.create(PckPackage.prototype);
375
+ obj.__wbg_ptr = ptr;
376
+ PckPackageFinalization.register(obj, obj.__wbg_ptr, obj);
377
+ return obj;
378
+ }
379
+ __destroy_into_raw() {
380
+ const ptr = this.__wbg_ptr;
381
+ this.__wbg_ptr = 0;
382
+ PckPackageFinalization.unregister(this);
383
+ return ptr;
384
+ }
385
+ free() {
386
+ const ptr = this.__destroy_into_raw();
387
+ wasm.__wbg_pckpackage_free(ptr, 0);
388
+ }
389
+ /**
390
+ * Number of files in the package.
391
+ * @returns {number}
392
+ */
393
+ get fileCount() {
394
+ const ret = wasm.pckpackage_fileCount(this.__wbg_ptr);
395
+ return ret >>> 0;
396
+ }
397
+ /**
398
+ * List all file paths in the package.
399
+ * @returns {string[]}
400
+ */
401
+ fileList() {
402
+ const ret = wasm.pckpackage_fileList(this.__wbg_ptr);
403
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
404
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
405
+ return v1;
406
+ }
407
+ /**
408
+ * Find files matching a path prefix. Returns an array of normalized file paths.
409
+ * @param {string} prefix
410
+ * @returns {string[]}
411
+ */
412
+ findPrefix(prefix) {
413
+ const ptr0 = passStringToWasm0(prefix, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
414
+ const len0 = WASM_VECTOR_LEN;
415
+ const ret = wasm.pckpackage_findPrefix(this.__wbg_ptr, ptr0, len0);
416
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
417
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
418
+ return v2;
419
+ }
420
+ /**
421
+ * Get decompressed file content by path. Returns null if not found.
422
+ * @param {string} path
423
+ * @returns {Uint8Array | undefined}
424
+ */
425
+ getFile(path) {
426
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
427
+ const len0 = WASM_VECTOR_LEN;
428
+ const ret = wasm.pckpackage_getFile(this.__wbg_ptr, ptr0, len0);
429
+ let v2;
430
+ if (ret[0] !== 0) {
431
+ v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
432
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
433
+ }
434
+ return v2;
435
+ }
436
+ /**
437
+ * Parse a pck package from bytes.
438
+ * @param {Uint8Array} bytes
439
+ * @param {PackageConfig | null} [config]
440
+ * @returns {PckPackage}
441
+ */
442
+ static parse(bytes, config) {
443
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
444
+ const len0 = WASM_VECTOR_LEN;
445
+ let ptr1 = 0;
446
+ if (!isLikeNone(config)) {
447
+ _assertClass(config, PackageConfig);
448
+ ptr1 = config.__destroy_into_raw();
449
+ }
450
+ const ret = wasm.pckpackage_parse(ptr0, len0, ptr1);
451
+ if (ret[2]) {
452
+ throw takeFromExternrefTable0(ret[1]);
453
+ }
454
+ return PckPackage.__wrap(ret[0]);
455
+ }
456
+ /**
457
+ * Package version.
458
+ * @returns {number}
459
+ */
460
+ get version() {
461
+ const ret = wasm.pckpackage_version(this.__wbg_ptr);
462
+ return ret >>> 0;
463
+ }
464
+ }
465
+ if (Symbol.dispose) PckPackage.prototype[Symbol.dispose] = PckPackage.prototype.free;
466
+
467
+ function __wbg_get_imports() {
468
+ const import0 = {
469
+ __proto__: null,
470
+ __wbg_Error_2e59b1b37a9a34c3: function(arg0, arg1) {
471
+ const ret = Error(getStringFromWasm0(arg0, arg1));
472
+ return ret;
473
+ },
474
+ __wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
475
+ throw new Error(getStringFromWasm0(arg0, arg1));
476
+ },
477
+ __wbg_length_0c32cb8543c8e4c8: function(arg0) {
478
+ const ret = arg0.length;
479
+ return ret;
480
+ },
481
+ __wbg_new_with_length_9cedd08484b73942: function(arg0) {
482
+ const ret = new Uint8Array(arg0 >>> 0);
483
+ return ret;
484
+ },
485
+ __wbg_set_16a9c1a07b3d38ec: function(arg0, arg1, arg2) {
486
+ arg0.set(getArrayU8FromWasm0(arg1, arg2));
487
+ },
488
+ __wbindgen_cast_0000000000000001: function(arg0) {
489
+ // Cast intrinsic for `F64 -> Externref`.
490
+ const ret = arg0;
491
+ return ret;
492
+ },
493
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
494
+ // Cast intrinsic for `Ref(String) -> Externref`.
495
+ const ret = getStringFromWasm0(arg0, arg1);
496
+ return ret;
497
+ },
498
+ __wbindgen_init_externref_table: function() {
499
+ const table = wasm.__wbindgen_externrefs;
500
+ const offset = table.grow(4);
501
+ table.set(0, undefined);
502
+ table.set(offset + 0, undefined);
503
+ table.set(offset + 1, null);
504
+ table.set(offset + 2, true);
505
+ table.set(offset + 3, false);
506
+ },
507
+ };
508
+ return {
509
+ __proto__: null,
510
+ "./autoangel_bg.js": import0,
511
+ };
512
+ }
513
+
514
+ const ElementsConfigFinalization = (typeof FinalizationRegistry === 'undefined')
515
+ ? { register: () => {}, unregister: () => {} }
516
+ : new FinalizationRegistry(ptr => wasm.__wbg_elementsconfig_free(ptr >>> 0, 1));
517
+ const ElementsDataFinalization = (typeof FinalizationRegistry === 'undefined')
518
+ ? { register: () => {}, unregister: () => {} }
519
+ : new FinalizationRegistry(ptr => wasm.__wbg_elementsdata_free(ptr >>> 0, 1));
520
+ const ElementsDataEntryFinalization = (typeof FinalizationRegistry === 'undefined')
521
+ ? { register: () => {}, unregister: () => {} }
522
+ : new FinalizationRegistry(ptr => wasm.__wbg_elementsdataentry_free(ptr >>> 0, 1));
523
+ const ElementsDataListFinalization = (typeof FinalizationRegistry === 'undefined')
524
+ ? { register: () => {}, unregister: () => {} }
525
+ : new FinalizationRegistry(ptr => wasm.__wbg_elementsdatalist_free(ptr >>> 0, 1));
526
+ const PackageConfigFinalization = (typeof FinalizationRegistry === 'undefined')
527
+ ? { register: () => {}, unregister: () => {} }
528
+ : new FinalizationRegistry(ptr => wasm.__wbg_packageconfig_free(ptr >>> 0, 1));
529
+ const PckPackageFinalization = (typeof FinalizationRegistry === 'undefined')
530
+ ? { register: () => {}, unregister: () => {} }
531
+ : new FinalizationRegistry(ptr => wasm.__wbg_pckpackage_free(ptr >>> 0, 1));
532
+
533
+ function _assertClass(instance, klass) {
534
+ if (!(instance instanceof klass)) {
535
+ throw new Error(`expected instance of ${klass.name}`);
536
+ }
537
+ }
538
+
539
+ function getArrayJsValueFromWasm0(ptr, len) {
540
+ ptr = ptr >>> 0;
541
+ const mem = getDataViewMemory0();
542
+ const result = [];
543
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
544
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
545
+ }
546
+ wasm.__externref_drop_slice(ptr, len);
547
+ return result;
548
+ }
549
+
550
+ function getArrayU8FromWasm0(ptr, len) {
551
+ ptr = ptr >>> 0;
552
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
553
+ }
554
+
555
+ let cachedDataViewMemory0 = null;
556
+ function getDataViewMemory0() {
557
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
558
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
559
+ }
560
+ return cachedDataViewMemory0;
561
+ }
562
+
563
+ function getStringFromWasm0(ptr, len) {
564
+ ptr = ptr >>> 0;
565
+ return decodeText(ptr, len);
566
+ }
567
+
568
+ let cachedUint8ArrayMemory0 = null;
569
+ function getUint8ArrayMemory0() {
570
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
571
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
572
+ }
573
+ return cachedUint8ArrayMemory0;
574
+ }
575
+
576
+ function isLikeNone(x) {
577
+ return x === undefined || x === null;
578
+ }
579
+
580
+ function passArray8ToWasm0(arg, malloc) {
581
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
582
+ getUint8ArrayMemory0().set(arg, ptr / 1);
583
+ WASM_VECTOR_LEN = arg.length;
584
+ return ptr;
585
+ }
586
+
587
+ function passStringToWasm0(arg, malloc, realloc) {
588
+ if (realloc === undefined) {
589
+ const buf = cachedTextEncoder.encode(arg);
590
+ const ptr = malloc(buf.length, 1) >>> 0;
591
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
592
+ WASM_VECTOR_LEN = buf.length;
593
+ return ptr;
594
+ }
595
+
596
+ let len = arg.length;
597
+ let ptr = malloc(len, 1) >>> 0;
598
+
599
+ const mem = getUint8ArrayMemory0();
600
+
601
+ let offset = 0;
602
+
603
+ for (; offset < len; offset++) {
604
+ const code = arg.charCodeAt(offset);
605
+ if (code > 0x7F) break;
606
+ mem[ptr + offset] = code;
607
+ }
608
+ if (offset !== len) {
609
+ if (offset !== 0) {
610
+ arg = arg.slice(offset);
611
+ }
612
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
613
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
614
+ const ret = cachedTextEncoder.encodeInto(arg, view);
615
+
616
+ offset += ret.written;
617
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
618
+ }
619
+
620
+ WASM_VECTOR_LEN = offset;
621
+ return ptr;
622
+ }
623
+
624
+ function takeFromExternrefTable0(idx) {
625
+ const value = wasm.__wbindgen_externrefs.get(idx);
626
+ wasm.__externref_table_dealloc(idx);
627
+ return value;
628
+ }
629
+
630
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
631
+ cachedTextDecoder.decode();
632
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
633
+ let numBytesDecoded = 0;
634
+ function decodeText(ptr, len) {
635
+ numBytesDecoded += len;
636
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
637
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
638
+ cachedTextDecoder.decode();
639
+ numBytesDecoded = len;
640
+ }
641
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
642
+ }
643
+
644
+ const cachedTextEncoder = new TextEncoder();
645
+
646
+ if (!('encodeInto' in cachedTextEncoder)) {
647
+ cachedTextEncoder.encodeInto = function (arg, view) {
648
+ const buf = cachedTextEncoder.encode(arg);
649
+ view.set(buf);
650
+ return {
651
+ read: arg.length,
652
+ written: buf.length
653
+ };
654
+ };
655
+ }
656
+
657
+ let WASM_VECTOR_LEN = 0;
658
+
659
+ let wasmModule, wasm;
660
+ function __wbg_finalize_init(instance, module) {
661
+ wasm = instance.exports;
662
+ wasmModule = module;
663
+ cachedDataViewMemory0 = null;
664
+ cachedUint8ArrayMemory0 = null;
665
+ wasm.__wbindgen_start();
666
+ return wasm;
667
+ }
668
+
669
+ async function __wbg_load(module, imports) {
670
+ if (typeof Response === 'function' && module instanceof Response) {
671
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
672
+ try {
673
+ return await WebAssembly.instantiateStreaming(module, imports);
674
+ } catch (e) {
675
+ const validResponse = module.ok && expectedResponseType(module.type);
676
+
677
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
678
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
679
+
680
+ } else { throw e; }
681
+ }
682
+ }
683
+
684
+ const bytes = await module.arrayBuffer();
685
+ return await WebAssembly.instantiate(bytes, imports);
686
+ } else {
687
+ const instance = await WebAssembly.instantiate(module, imports);
688
+
689
+ if (instance instanceof WebAssembly.Instance) {
690
+ return { instance, module };
691
+ } else {
692
+ return instance;
693
+ }
694
+ }
695
+
696
+ function expectedResponseType(type) {
697
+ switch (type) {
698
+ case 'basic': case 'cors': case 'default': return true;
699
+ }
700
+ return false;
701
+ }
702
+ }
703
+
704
+ function initSync(module) {
705
+ if (wasm !== undefined) return wasm;
706
+
707
+
708
+ if (module !== undefined) {
709
+ if (Object.getPrototypeOf(module) === Object.prototype) {
710
+ ({module} = module)
711
+ } else {
712
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
713
+ }
714
+ }
715
+
716
+ const imports = __wbg_get_imports();
717
+ if (!(module instanceof WebAssembly.Module)) {
718
+ module = new WebAssembly.Module(module);
719
+ }
720
+ const instance = new WebAssembly.Instance(module, imports);
721
+ return __wbg_finalize_init(instance, module);
722
+ }
723
+
724
+ async function __wbg_init(module_or_path) {
725
+ if (wasm !== undefined) return wasm;
726
+
727
+
728
+ if (module_or_path !== undefined) {
729
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
730
+ ({module_or_path} = module_or_path)
731
+ } else {
732
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
733
+ }
734
+ }
735
+
736
+ if (module_or_path === undefined) {
737
+ module_or_path = new URL('autoangel_bg.wasm', import.meta.url);
738
+ }
739
+ const imports = __wbg_get_imports();
740
+
741
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
742
+ module_or_path = fetch(module_or_path);
743
+ }
744
+
745
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
746
+
747
+ return __wbg_finalize_init(instance, module);
748
+ }
749
+
750
+ export { initSync, __wbg_init as default };
Binary file
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "autoangel",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Smertig <akaraevz@mail.ru>"
6
+ ],
7
+ "description": "WASM bindings for Angelica Engine game file parsing",
8
+ "version": "0.6.4",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/Smertig/pypck_alpha"
13
+ },
14
+ "files": [
15
+ "autoangel_bg.wasm",
16
+ "autoangel.js",
17
+ "autoangel.d.ts"
18
+ ],
19
+ "main": "autoangel.js",
20
+ "types": "autoangel.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ]
24
+ }