tetr-ttrx 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TTRX contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # TTRX
2
+
3
+ TTRX is a Rust converter for TETR.IO `.ttr` and `.ttrm` replay files. It writes a versioned `.ttrx` binary container and converts that container back to canonical JSON.
4
+
5
+ The first implemented profile is `source-semantic`: it preserves the parsed JSON data model, including object and array order, duplicate object keys, exact number lexemes, unknown fields, and unknown events. Whitespace and equivalent string escaping are canonicalized when decoding. Because input events and their values are retained, the reverse conversion preserves the source behavior without inventing game state.
6
+
7
+ This profile is the first vertical implementation of the converter. Deterministic action compilation and board regeneration described in the design documents are future format profiles; they are not claimed by the current executable.
8
+
9
+ ## Build and use
10
+
11
+ ```powershell
12
+ cargo build --release -p ttrx-cli
13
+
14
+ target\release\ttrx encode replay.ttr
15
+ target\release\ttrx encode match.ttrm -o match.ttrx
16
+ target\release\ttrx decode match.ttrx
17
+ target\release\ttrx inspect match.ttrx
18
+ target\release\ttrx verify replay.ttr
19
+ ```
20
+
21
+ Output files are not overwritten unless `--force` is supplied, and `--force` only replaces a regular file. `encode` infers `.ttr` or `.ttrm` from the extension and also checks the replay shape. `decode` restores the extension recorded in the container. Use `-o` to choose another output path.
22
+
23
+ On Windows, replacing an existing file uses a uniquely named sibling backup because the standard rename operation cannot replace a destination. Ordinary failures restore that backup. If the process or machine stops between the two rename operations, the previous file may remain beside the output under a hidden `previous` temporary name and can be restored manually.
24
+
25
+ The core crate has no external dependencies. The WebAssembly wrapper uses `wasm-bindgen`; the CLI uses only the standard library and `ttrx-core`.
26
+
27
+ ## WebAssembly
28
+
29
+ The wrapper exports `encode_ttr`, `encode_ttrm`, `decode_ttrx`, `ttrx_source_extension`, source/container inspection and verification functions, plus `ttrx_version`. `ttrx_source_extension` tells a browser caller whether decoded bytes should be saved as `.ttr`, `.ttrm`, or `.json`. Build it and generate Node.js glue with the pinned `wasm-bindgen` schema version:
30
+
31
+ ```powershell
32
+ rustup target add wasm32-unknown-unknown
33
+ cargo install --locked wasm-bindgen-cli --version 0.2.126
34
+ wasm-bindgen --version # must report wasm-bindgen 0.2.126
35
+ cargo build --release -p ttrx-wasm --target wasm32-unknown-unknown
36
+ wasm-bindgen target\wasm32-unknown-unknown\release\ttrx_wasm.wasm `
37
+ --target nodejs --out-dir work\wasm
38
+ node scripts\wasm-smoke.cjs work\wasm\ttrx_wasm.js replay.ttr match.ttrm
39
+ ```
40
+
41
+ The exported encode/decode functions accept and return JavaScript `Uint8Array` values. Browser bundlers can use the same Wasm artifact with the matching `wasm-bindgen` target and CLI version.
42
+
43
+ ## npm package
44
+
45
+ The `tetr-ttrx` npm package ships the WebAssembly converter for Node.js and browser-aware bundlers. It exposes the same eleven functions documented above, with CommonJS and ES module entry points for Node.js and an ES module WebAssembly entry point selected by browser bundlers.
46
+
47
+ ```sh
48
+ npm install tetr-ttrx
49
+ ```
50
+
51
+ ```js
52
+ import { readFile, writeFile } from 'node:fs/promises';
53
+ import { decode_ttrx, encode_ttr } from 'tetr-ttrx';
54
+
55
+ const source = await readFile('replay.ttr');
56
+ const container = encode_ttr(source);
57
+ await writeFile('replay.ttrx', container);
58
+
59
+ const canonicalJson = decode_ttrx(container);
60
+ await writeFile('replay.decoded.ttr', canonicalJson);
61
+ ```
62
+
63
+ CommonJS consumers can use `const ttrx = require('tetr-ttrx')`. The `inspect_*` and `verify_*` functions return human-readable strings; the encode/decode functions accept and return `Uint8Array` values and throw JavaScript errors for invalid inputs.
64
+
65
+ To build the npm package from source, install the `wasm32-unknown-unknown` Rust target and `wasm-bindgen-cli` 0.2.126, then run `npm run build`. `npm test` runs the Rust workspace tests, and `npm run test:package` checks both Node.js module formats after a build.
66
+
67
+ ## Fidelity
68
+
69
+ The current profile is stricter than placement-only equivalence: it round-trips the complete parsed JSON tree. It does not promise byte-for-byte JSON identity because insignificant whitespace and equivalent escapes are not retained. No TETR.IO game engine is run during conversion, so `verify` proves container/data-model round-trip, not independent board simulation.
70
+
71
+ See [project requirements](docs/ttrx/requirements.md), [TTRX 1.0 binary format](docs/ttrx/format-v1.md), [implementation status](docs/ttrx/implementation-status.md), [validation evidence](docs/ttrx/validation.md), [TETR.IO source audit](docs/tetrio/README.md), and [open verification work](docs/tetrio/verification/coverage-and-open-items.md).
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,106 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decode a TTRX container to canonical TETR.IO replay JSON bytes.
6
+ *
7
+ * # Errors
8
+ *
9
+ * Returns a JavaScript error when the container header, checksum, payload, or
10
+ * decoded JSON data model is invalid.
11
+ */
12
+ export function decode_ttrx(container: Uint8Array): Uint8Array;
13
+
14
+ /**
15
+ * Encode one single-player TETR.IO replay JSON document.
16
+ *
17
+ * # Errors
18
+ *
19
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
20
+ * single-player replay, or cannot be represented by the TTRX codec.
21
+ */
22
+ export function encode_ttr(source: Uint8Array): Uint8Array;
23
+
24
+ /**
25
+ * Encode one multiplayer TETR.IO replay JSON document.
26
+ *
27
+ * # Errors
28
+ *
29
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
30
+ * multiplayer replay, or cannot be represented by the TTRX codec.
31
+ */
32
+ export function encode_ttrm(source: Uint8Array): Uint8Array;
33
+
34
+ /**
35
+ * Describe a single-player source replay without executing game rules.
36
+ *
37
+ * # Errors
38
+ *
39
+ * Returns a JavaScript error when the source is invalid JSON or its structure
40
+ * is incompatible with a single-player replay.
41
+ */
42
+ export function inspect_ttr(source: Uint8Array): string;
43
+
44
+ /**
45
+ * Describe a multiplayer source replay without executing game rules.
46
+ *
47
+ * # Errors
48
+ *
49
+ * Returns a JavaScript error when the source is invalid JSON or its structure
50
+ * is incompatible with a multiplayer replay.
51
+ */
52
+ export function inspect_ttrm(source: Uint8Array): string;
53
+
54
+ /**
55
+ * Validate and describe both the binary container and its decoded replay.
56
+ *
57
+ * # Errors
58
+ *
59
+ * Returns a JavaScript error when the container or decoded replay is invalid.
60
+ */
61
+ export function inspect_ttrx(container: Uint8Array): string;
62
+
63
+ /**
64
+ * Return the source extension recorded by a TTRX container (`ttr`, `ttrm`,
65
+ * or `json` when the source kind is unknown).
66
+ *
67
+ * # Errors
68
+ *
69
+ * Returns a JavaScript error when the container is invalid.
70
+ */
71
+ export function ttrx_source_extension(container: Uint8Array): string;
72
+
73
+ /**
74
+ * Return the converter package version.
75
+ */
76
+ export function ttrx_version(): string;
77
+
78
+ /**
79
+ * Verify a single-player source replay through an encode/decode round trip.
80
+ *
81
+ * # Errors
82
+ *
83
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
84
+ * data-model comparison fails.
85
+ */
86
+ export function verify_ttr(source: Uint8Array): string;
87
+
88
+ /**
89
+ * Verify a multiplayer source replay through an encode/decode round trip.
90
+ *
91
+ * # Errors
92
+ *
93
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
94
+ * data-model comparison fails.
95
+ */
96
+ export function verify_ttrm(source: Uint8Array): string;
97
+
98
+ /**
99
+ * Validate a binary container and verify its decoded replay data model.
100
+ *
101
+ * # Errors
102
+ *
103
+ * Returns a JavaScript error when container validation or the decoded replay's
104
+ * encode/decode verification fails.
105
+ */
106
+ export function verify_ttrx(container: Uint8Array): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./ttrx_wasm.d.ts" */
2
+ import * as wasm from "./ttrx_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./ttrx_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+
7
+ export {
8
+ decode_ttrx, encode_ttr, encode_ttrm, inspect_ttr, inspect_ttrm, inspect_ttrx, ttrx_source_extension, ttrx_version, verify_ttr, verify_ttrm, verify_ttrx
9
+ } from "./ttrx_wasm_bg.js";
@@ -0,0 +1,457 @@
1
+ /**
2
+ * Decode a TTRX container to canonical TETR.IO replay JSON bytes.
3
+ *
4
+ * # Errors
5
+ *
6
+ * Returns a JavaScript error when the container header, checksum, payload, or
7
+ * decoded JSON data model is invalid.
8
+ * @param {Uint8Array} container
9
+ * @returns {Uint8Array}
10
+ */
11
+ export function decode_ttrx(container) {
12
+ try {
13
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
14
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ wasm.decode_ttrx(retptr, ptr0, len0);
17
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
18
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
19
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
20
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
21
+ if (r3) {
22
+ throw takeObject(r2);
23
+ }
24
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
25
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
26
+ return v2;
27
+ } finally {
28
+ wasm.__wbindgen_add_to_stack_pointer(16);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Encode one single-player TETR.IO replay JSON document.
34
+ *
35
+ * # Errors
36
+ *
37
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
38
+ * single-player replay, or cannot be represented by the TTRX codec.
39
+ * @param {Uint8Array} source
40
+ * @returns {Uint8Array}
41
+ */
42
+ export function encode_ttr(source) {
43
+ try {
44
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
45
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ wasm.encode_ttr(retptr, ptr0, len0);
48
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
49
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
50
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
51
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
52
+ if (r3) {
53
+ throw takeObject(r2);
54
+ }
55
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
56
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
57
+ return v2;
58
+ } finally {
59
+ wasm.__wbindgen_add_to_stack_pointer(16);
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Encode one multiplayer TETR.IO replay JSON document.
65
+ *
66
+ * # Errors
67
+ *
68
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
69
+ * multiplayer replay, or cannot be represented by the TTRX codec.
70
+ * @param {Uint8Array} source
71
+ * @returns {Uint8Array}
72
+ */
73
+ export function encode_ttrm(source) {
74
+ try {
75
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
76
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
77
+ const len0 = WASM_VECTOR_LEN;
78
+ wasm.encode_ttrm(retptr, ptr0, len0);
79
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
80
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
81
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
82
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
83
+ if (r3) {
84
+ throw takeObject(r2);
85
+ }
86
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
87
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
88
+ return v2;
89
+ } finally {
90
+ wasm.__wbindgen_add_to_stack_pointer(16);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Describe a single-player source replay without executing game rules.
96
+ *
97
+ * # Errors
98
+ *
99
+ * Returns a JavaScript error when the source is invalid JSON or its structure
100
+ * is incompatible with a single-player replay.
101
+ * @param {Uint8Array} source
102
+ * @returns {string}
103
+ */
104
+ export function inspect_ttr(source) {
105
+ let deferred3_0;
106
+ let deferred3_1;
107
+ try {
108
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
109
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
110
+ const len0 = WASM_VECTOR_LEN;
111
+ wasm.inspect_ttr(retptr, ptr0, len0);
112
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
113
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
114
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
115
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
116
+ var ptr2 = r0;
117
+ var len2 = r1;
118
+ if (r3) {
119
+ ptr2 = 0; len2 = 0;
120
+ throw takeObject(r2);
121
+ }
122
+ deferred3_0 = ptr2;
123
+ deferred3_1 = len2;
124
+ return getStringFromWasm0(ptr2, len2);
125
+ } finally {
126
+ wasm.__wbindgen_add_to_stack_pointer(16);
127
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Describe a multiplayer source replay without executing game rules.
133
+ *
134
+ * # Errors
135
+ *
136
+ * Returns a JavaScript error when the source is invalid JSON or its structure
137
+ * is incompatible with a multiplayer replay.
138
+ * @param {Uint8Array} source
139
+ * @returns {string}
140
+ */
141
+ export function inspect_ttrm(source) {
142
+ let deferred3_0;
143
+ let deferred3_1;
144
+ try {
145
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
146
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
147
+ const len0 = WASM_VECTOR_LEN;
148
+ wasm.inspect_ttrm(retptr, ptr0, len0);
149
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
150
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
151
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
152
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
153
+ var ptr2 = r0;
154
+ var len2 = r1;
155
+ if (r3) {
156
+ ptr2 = 0; len2 = 0;
157
+ throw takeObject(r2);
158
+ }
159
+ deferred3_0 = ptr2;
160
+ deferred3_1 = len2;
161
+ return getStringFromWasm0(ptr2, len2);
162
+ } finally {
163
+ wasm.__wbindgen_add_to_stack_pointer(16);
164
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Validate and describe both the binary container and its decoded replay.
170
+ *
171
+ * # Errors
172
+ *
173
+ * Returns a JavaScript error when the container or decoded replay is invalid.
174
+ * @param {Uint8Array} container
175
+ * @returns {string}
176
+ */
177
+ export function inspect_ttrx(container) {
178
+ let deferred3_0;
179
+ let deferred3_1;
180
+ try {
181
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
182
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
183
+ const len0 = WASM_VECTOR_LEN;
184
+ wasm.inspect_ttrx(retptr, ptr0, len0);
185
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
186
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
187
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
188
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
189
+ var ptr2 = r0;
190
+ var len2 = r1;
191
+ if (r3) {
192
+ ptr2 = 0; len2 = 0;
193
+ throw takeObject(r2);
194
+ }
195
+ deferred3_0 = ptr2;
196
+ deferred3_1 = len2;
197
+ return getStringFromWasm0(ptr2, len2);
198
+ } finally {
199
+ wasm.__wbindgen_add_to_stack_pointer(16);
200
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Return the source extension recorded by a TTRX container (`ttr`, `ttrm`,
206
+ * or `json` when the source kind is unknown).
207
+ *
208
+ * # Errors
209
+ *
210
+ * Returns a JavaScript error when the container is invalid.
211
+ * @param {Uint8Array} container
212
+ * @returns {string}
213
+ */
214
+ export function ttrx_source_extension(container) {
215
+ let deferred3_0;
216
+ let deferred3_1;
217
+ try {
218
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
219
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
220
+ const len0 = WASM_VECTOR_LEN;
221
+ wasm.ttrx_source_extension(retptr, ptr0, len0);
222
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
223
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
224
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
225
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
226
+ var ptr2 = r0;
227
+ var len2 = r1;
228
+ if (r3) {
229
+ ptr2 = 0; len2 = 0;
230
+ throw takeObject(r2);
231
+ }
232
+ deferred3_0 = ptr2;
233
+ deferred3_1 = len2;
234
+ return getStringFromWasm0(ptr2, len2);
235
+ } finally {
236
+ wasm.__wbindgen_add_to_stack_pointer(16);
237
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Return the converter package version.
243
+ * @returns {string}
244
+ */
245
+ export function ttrx_version() {
246
+ let deferred1_0;
247
+ let deferred1_1;
248
+ try {
249
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
250
+ wasm.ttrx_version(retptr);
251
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
252
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
253
+ deferred1_0 = r0;
254
+ deferred1_1 = r1;
255
+ return getStringFromWasm0(r0, r1);
256
+ } finally {
257
+ wasm.__wbindgen_add_to_stack_pointer(16);
258
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Verify a single-player source replay through an encode/decode round trip.
264
+ *
265
+ * # Errors
266
+ *
267
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
268
+ * data-model comparison fails.
269
+ * @param {Uint8Array} source
270
+ * @returns {string}
271
+ */
272
+ export function verify_ttr(source) {
273
+ let deferred3_0;
274
+ let deferred3_1;
275
+ try {
276
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
277
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
278
+ const len0 = WASM_VECTOR_LEN;
279
+ wasm.verify_ttr(retptr, ptr0, len0);
280
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
281
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
282
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
283
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
284
+ var ptr2 = r0;
285
+ var len2 = r1;
286
+ if (r3) {
287
+ ptr2 = 0; len2 = 0;
288
+ throw takeObject(r2);
289
+ }
290
+ deferred3_0 = ptr2;
291
+ deferred3_1 = len2;
292
+ return getStringFromWasm0(ptr2, len2);
293
+ } finally {
294
+ wasm.__wbindgen_add_to_stack_pointer(16);
295
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Verify a multiplayer source replay through an encode/decode round trip.
301
+ *
302
+ * # Errors
303
+ *
304
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
305
+ * data-model comparison fails.
306
+ * @param {Uint8Array} source
307
+ * @returns {string}
308
+ */
309
+ export function verify_ttrm(source) {
310
+ let deferred3_0;
311
+ let deferred3_1;
312
+ try {
313
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
314
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
315
+ const len0 = WASM_VECTOR_LEN;
316
+ wasm.verify_ttrm(retptr, ptr0, len0);
317
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
318
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
319
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
320
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
321
+ var ptr2 = r0;
322
+ var len2 = r1;
323
+ if (r3) {
324
+ ptr2 = 0; len2 = 0;
325
+ throw takeObject(r2);
326
+ }
327
+ deferred3_0 = ptr2;
328
+ deferred3_1 = len2;
329
+ return getStringFromWasm0(ptr2, len2);
330
+ } finally {
331
+ wasm.__wbindgen_add_to_stack_pointer(16);
332
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Validate a binary container and verify its decoded replay data model.
338
+ *
339
+ * # Errors
340
+ *
341
+ * Returns a JavaScript error when container validation or the decoded replay's
342
+ * encode/decode verification fails.
343
+ * @param {Uint8Array} container
344
+ * @returns {string}
345
+ */
346
+ export function verify_ttrx(container) {
347
+ let deferred3_0;
348
+ let deferred3_1;
349
+ try {
350
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
351
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
352
+ const len0 = WASM_VECTOR_LEN;
353
+ wasm.verify_ttrx(retptr, ptr0, len0);
354
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
355
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
356
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
357
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
358
+ var ptr2 = r0;
359
+ var len2 = r1;
360
+ if (r3) {
361
+ ptr2 = 0; len2 = 0;
362
+ throw takeObject(r2);
363
+ }
364
+ deferred3_0 = ptr2;
365
+ deferred3_1 = len2;
366
+ return getStringFromWasm0(ptr2, len2);
367
+ } finally {
368
+ wasm.__wbindgen_add_to_stack_pointer(16);
369
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
370
+ }
371
+ }
372
+ export function __wbindgen_cast_0000000000000001(arg0, arg1) {
373
+ // Cast intrinsic for `Ref(String) -> Externref`.
374
+ const ret = getStringFromWasm0(arg0, arg1);
375
+ return addHeapObject(ret);
376
+ }
377
+ function addHeapObject(obj) {
378
+ if (heap_next === heap.length) heap.push(heap.length + 1);
379
+ const idx = heap_next;
380
+ heap_next = heap[idx];
381
+
382
+ heap[idx] = obj;
383
+ return idx;
384
+ }
385
+
386
+ function dropObject(idx) {
387
+ if (idx < 1028) return;
388
+ heap[idx] = heap_next;
389
+ heap_next = idx;
390
+ }
391
+
392
+ function getArrayU8FromWasm0(ptr, len) {
393
+ ptr = ptr >>> 0;
394
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
395
+ }
396
+
397
+ let cachedDataViewMemory0 = null;
398
+ function getDataViewMemory0() {
399
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
400
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
401
+ }
402
+ return cachedDataViewMemory0;
403
+ }
404
+
405
+ function getStringFromWasm0(ptr, len) {
406
+ return decodeText(ptr >>> 0, len);
407
+ }
408
+
409
+ let cachedUint8ArrayMemory0 = null;
410
+ function getUint8ArrayMemory0() {
411
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
412
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
413
+ }
414
+ return cachedUint8ArrayMemory0;
415
+ }
416
+
417
+ function getObject(idx) { return heap[idx]; }
418
+
419
+ let heap = new Array(1024).fill(undefined);
420
+ heap.push(undefined, null, true, false);
421
+
422
+ let heap_next = heap.length;
423
+
424
+ function passArray8ToWasm0(arg, malloc) {
425
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
426
+ getUint8ArrayMemory0().set(arg, ptr / 1);
427
+ WASM_VECTOR_LEN = arg.length;
428
+ return ptr;
429
+ }
430
+
431
+ function takeObject(idx) {
432
+ const ret = getObject(idx);
433
+ dropObject(idx);
434
+ return ret;
435
+ }
436
+
437
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
438
+ cachedTextDecoder.decode();
439
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
440
+ let numBytesDecoded = 0;
441
+ function decodeText(ptr, len) {
442
+ numBytesDecoded += len;
443
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
444
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
445
+ cachedTextDecoder.decode();
446
+ numBytesDecoded = len;
447
+ }
448
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
449
+ }
450
+
451
+ let WASM_VECTOR_LEN = 0;
452
+
453
+
454
+ let wasm;
455
+ export function __wbg_set_wasm(val) {
456
+ wasm = val;
457
+ }
Binary file
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const decode_ttrx: (a: number, b: number, c: number) => void;
5
+ export const encode_ttr: (a: number, b: number, c: number) => void;
6
+ export const encode_ttrm: (a: number, b: number, c: number) => void;
7
+ export const inspect_ttr: (a: number, b: number, c: number) => void;
8
+ export const inspect_ttrm: (a: number, b: number, c: number) => void;
9
+ export const inspect_ttrx: (a: number, b: number, c: number) => void;
10
+ export const ttrx_source_extension: (a: number, b: number, c: number) => void;
11
+ export const ttrx_version: (a: number) => void;
12
+ export const verify_ttr: (a: number, b: number, c: number) => void;
13
+ export const verify_ttrm: (a: number, b: number, c: number) => void;
14
+ export const verify_ttrx: (a: number, b: number, c: number) => void;
15
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
16
+ export const __wbindgen_export: (a: number, b: number) => number;
17
+ export const __wbindgen_export2: (a: number, b: number, c: number) => void;
@@ -0,0 +1,17 @@
1
+ import binding from './ttrx_wasm.js';
2
+
3
+ export const {
4
+ decode_ttrx,
5
+ encode_ttr,
6
+ encode_ttrm,
7
+ inspect_ttr,
8
+ inspect_ttrm,
9
+ inspect_ttrx,
10
+ ttrx_source_extension,
11
+ ttrx_version,
12
+ verify_ttr,
13
+ verify_ttrm,
14
+ verify_ttrx,
15
+ } = binding;
16
+
17
+ export default binding;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,106 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Decode a TTRX container to canonical TETR.IO replay JSON bytes.
6
+ *
7
+ * # Errors
8
+ *
9
+ * Returns a JavaScript error when the container header, checksum, payload, or
10
+ * decoded JSON data model is invalid.
11
+ */
12
+ export function decode_ttrx(container: Uint8Array): Uint8Array;
13
+
14
+ /**
15
+ * Encode one single-player TETR.IO replay JSON document.
16
+ *
17
+ * # Errors
18
+ *
19
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
20
+ * single-player replay, or cannot be represented by the TTRX codec.
21
+ */
22
+ export function encode_ttr(source: Uint8Array): Uint8Array;
23
+
24
+ /**
25
+ * Encode one multiplayer TETR.IO replay JSON document.
26
+ *
27
+ * # Errors
28
+ *
29
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
30
+ * multiplayer replay, or cannot be represented by the TTRX codec.
31
+ */
32
+ export function encode_ttrm(source: Uint8Array): Uint8Array;
33
+
34
+ /**
35
+ * Describe a single-player source replay without executing game rules.
36
+ *
37
+ * # Errors
38
+ *
39
+ * Returns a JavaScript error when the source is invalid JSON or its structure
40
+ * is incompatible with a single-player replay.
41
+ */
42
+ export function inspect_ttr(source: Uint8Array): string;
43
+
44
+ /**
45
+ * Describe a multiplayer source replay without executing game rules.
46
+ *
47
+ * # Errors
48
+ *
49
+ * Returns a JavaScript error when the source is invalid JSON or its structure
50
+ * is incompatible with a multiplayer replay.
51
+ */
52
+ export function inspect_ttrm(source: Uint8Array): string;
53
+
54
+ /**
55
+ * Validate and describe both the binary container and its decoded replay.
56
+ *
57
+ * # Errors
58
+ *
59
+ * Returns a JavaScript error when the container or decoded replay is invalid.
60
+ */
61
+ export function inspect_ttrx(container: Uint8Array): string;
62
+
63
+ /**
64
+ * Return the source extension recorded by a TTRX container (`ttr`, `ttrm`,
65
+ * or `json` when the source kind is unknown).
66
+ *
67
+ * # Errors
68
+ *
69
+ * Returns a JavaScript error when the container is invalid.
70
+ */
71
+ export function ttrx_source_extension(container: Uint8Array): string;
72
+
73
+ /**
74
+ * Return the converter package version.
75
+ */
76
+ export function ttrx_version(): string;
77
+
78
+ /**
79
+ * Verify a single-player source replay through an encode/decode round trip.
80
+ *
81
+ * # Errors
82
+ *
83
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
84
+ * data-model comparison fails.
85
+ */
86
+ export function verify_ttr(source: Uint8Array): string;
87
+
88
+ /**
89
+ * Verify a multiplayer source replay through an encode/decode round trip.
90
+ *
91
+ * # Errors
92
+ *
93
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
94
+ * data-model comparison fails.
95
+ */
96
+ export function verify_ttrm(source: Uint8Array): string;
97
+
98
+ /**
99
+ * Validate a binary container and verify its decoded replay data model.
100
+ *
101
+ * # Errors
102
+ *
103
+ * Returns a JavaScript error when container validation or the decoded replay's
104
+ * encode/decode verification fails.
105
+ */
106
+ export function verify_ttrx(container: Uint8Array): string;
@@ -0,0 +1,472 @@
1
+ /* @ts-self-types="./ttrx_wasm.d.ts" */
2
+
3
+ /**
4
+ * Decode a TTRX container to canonical TETR.IO replay JSON bytes.
5
+ *
6
+ * # Errors
7
+ *
8
+ * Returns a JavaScript error when the container header, checksum, payload, or
9
+ * decoded JSON data model is invalid.
10
+ * @param {Uint8Array} container
11
+ * @returns {Uint8Array}
12
+ */
13
+ function decode_ttrx(container) {
14
+ try {
15
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
16
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
17
+ const len0 = WASM_VECTOR_LEN;
18
+ wasm.decode_ttrx(retptr, ptr0, len0);
19
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
20
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
21
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
22
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
23
+ if (r3) {
24
+ throw takeObject(r2);
25
+ }
26
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
27
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
28
+ return v2;
29
+ } finally {
30
+ wasm.__wbindgen_add_to_stack_pointer(16);
31
+ }
32
+ }
33
+ exports.decode_ttrx = decode_ttrx;
34
+
35
+ /**
36
+ * Encode one single-player TETR.IO replay JSON document.
37
+ *
38
+ * # Errors
39
+ *
40
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
41
+ * single-player replay, or cannot be represented by the TTRX codec.
42
+ * @param {Uint8Array} source
43
+ * @returns {Uint8Array}
44
+ */
45
+ function encode_ttr(source) {
46
+ try {
47
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
48
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
49
+ const len0 = WASM_VECTOR_LEN;
50
+ wasm.encode_ttr(retptr, ptr0, len0);
51
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
52
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
53
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
54
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
55
+ if (r3) {
56
+ throw takeObject(r2);
57
+ }
58
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
59
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
60
+ return v2;
61
+ } finally {
62
+ wasm.__wbindgen_add_to_stack_pointer(16);
63
+ }
64
+ }
65
+ exports.encode_ttr = encode_ttr;
66
+
67
+ /**
68
+ * Encode one multiplayer TETR.IO replay JSON document.
69
+ *
70
+ * # Errors
71
+ *
72
+ * Returns a JavaScript error when the bytes are invalid JSON, do not contain a
73
+ * multiplayer replay, or cannot be represented by the TTRX codec.
74
+ * @param {Uint8Array} source
75
+ * @returns {Uint8Array}
76
+ */
77
+ function encode_ttrm(source) {
78
+ try {
79
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
80
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
81
+ const len0 = WASM_VECTOR_LEN;
82
+ wasm.encode_ttrm(retptr, ptr0, len0);
83
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
84
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
85
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
86
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
87
+ if (r3) {
88
+ throw takeObject(r2);
89
+ }
90
+ var v2 = getArrayU8FromWasm0(r0, r1).slice();
91
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
92
+ return v2;
93
+ } finally {
94
+ wasm.__wbindgen_add_to_stack_pointer(16);
95
+ }
96
+ }
97
+ exports.encode_ttrm = encode_ttrm;
98
+
99
+ /**
100
+ * Describe a single-player source replay without executing game rules.
101
+ *
102
+ * # Errors
103
+ *
104
+ * Returns a JavaScript error when the source is invalid JSON or its structure
105
+ * is incompatible with a single-player replay.
106
+ * @param {Uint8Array} source
107
+ * @returns {string}
108
+ */
109
+ function inspect_ttr(source) {
110
+ let deferred3_0;
111
+ let deferred3_1;
112
+ try {
113
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
114
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
115
+ const len0 = WASM_VECTOR_LEN;
116
+ wasm.inspect_ttr(retptr, ptr0, len0);
117
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
118
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
119
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
120
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
121
+ var ptr2 = r0;
122
+ var len2 = r1;
123
+ if (r3) {
124
+ ptr2 = 0; len2 = 0;
125
+ throw takeObject(r2);
126
+ }
127
+ deferred3_0 = ptr2;
128
+ deferred3_1 = len2;
129
+ return getStringFromWasm0(ptr2, len2);
130
+ } finally {
131
+ wasm.__wbindgen_add_to_stack_pointer(16);
132
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
133
+ }
134
+ }
135
+ exports.inspect_ttr = inspect_ttr;
136
+
137
+ /**
138
+ * Describe a multiplayer source replay without executing game rules.
139
+ *
140
+ * # Errors
141
+ *
142
+ * Returns a JavaScript error when the source is invalid JSON or its structure
143
+ * is incompatible with a multiplayer replay.
144
+ * @param {Uint8Array} source
145
+ * @returns {string}
146
+ */
147
+ function inspect_ttrm(source) {
148
+ let deferred3_0;
149
+ let deferred3_1;
150
+ try {
151
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
152
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
153
+ const len0 = WASM_VECTOR_LEN;
154
+ wasm.inspect_ttrm(retptr, ptr0, len0);
155
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
156
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
157
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
158
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
159
+ var ptr2 = r0;
160
+ var len2 = r1;
161
+ if (r3) {
162
+ ptr2 = 0; len2 = 0;
163
+ throw takeObject(r2);
164
+ }
165
+ deferred3_0 = ptr2;
166
+ deferred3_1 = len2;
167
+ return getStringFromWasm0(ptr2, len2);
168
+ } finally {
169
+ wasm.__wbindgen_add_to_stack_pointer(16);
170
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
171
+ }
172
+ }
173
+ exports.inspect_ttrm = inspect_ttrm;
174
+
175
+ /**
176
+ * Validate and describe both the binary container and its decoded replay.
177
+ *
178
+ * # Errors
179
+ *
180
+ * Returns a JavaScript error when the container or decoded replay is invalid.
181
+ * @param {Uint8Array} container
182
+ * @returns {string}
183
+ */
184
+ function inspect_ttrx(container) {
185
+ let deferred3_0;
186
+ let deferred3_1;
187
+ try {
188
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
189
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
190
+ const len0 = WASM_VECTOR_LEN;
191
+ wasm.inspect_ttrx(retptr, ptr0, len0);
192
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
193
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
194
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
195
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
196
+ var ptr2 = r0;
197
+ var len2 = r1;
198
+ if (r3) {
199
+ ptr2 = 0; len2 = 0;
200
+ throw takeObject(r2);
201
+ }
202
+ deferred3_0 = ptr2;
203
+ deferred3_1 = len2;
204
+ return getStringFromWasm0(ptr2, len2);
205
+ } finally {
206
+ wasm.__wbindgen_add_to_stack_pointer(16);
207
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
208
+ }
209
+ }
210
+ exports.inspect_ttrx = inspect_ttrx;
211
+
212
+ /**
213
+ * Return the source extension recorded by a TTRX container (`ttr`, `ttrm`,
214
+ * or `json` when the source kind is unknown).
215
+ *
216
+ * # Errors
217
+ *
218
+ * Returns a JavaScript error when the container is invalid.
219
+ * @param {Uint8Array} container
220
+ * @returns {string}
221
+ */
222
+ function ttrx_source_extension(container) {
223
+ let deferred3_0;
224
+ let deferred3_1;
225
+ try {
226
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
227
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
228
+ const len0 = WASM_VECTOR_LEN;
229
+ wasm.ttrx_source_extension(retptr, ptr0, len0);
230
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
231
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
232
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
233
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
234
+ var ptr2 = r0;
235
+ var len2 = r1;
236
+ if (r3) {
237
+ ptr2 = 0; len2 = 0;
238
+ throw takeObject(r2);
239
+ }
240
+ deferred3_0 = ptr2;
241
+ deferred3_1 = len2;
242
+ return getStringFromWasm0(ptr2, len2);
243
+ } finally {
244
+ wasm.__wbindgen_add_to_stack_pointer(16);
245
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
246
+ }
247
+ }
248
+ exports.ttrx_source_extension = ttrx_source_extension;
249
+
250
+ /**
251
+ * Return the converter package version.
252
+ * @returns {string}
253
+ */
254
+ function ttrx_version() {
255
+ let deferred1_0;
256
+ let deferred1_1;
257
+ try {
258
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
259
+ wasm.ttrx_version(retptr);
260
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
261
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
262
+ deferred1_0 = r0;
263
+ deferred1_1 = r1;
264
+ return getStringFromWasm0(r0, r1);
265
+ } finally {
266
+ wasm.__wbindgen_add_to_stack_pointer(16);
267
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
268
+ }
269
+ }
270
+ exports.ttrx_version = ttrx_version;
271
+
272
+ /**
273
+ * Verify a single-player source replay through an encode/decode round trip.
274
+ *
275
+ * # Errors
276
+ *
277
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
278
+ * data-model comparison fails.
279
+ * @param {Uint8Array} source
280
+ * @returns {string}
281
+ */
282
+ function verify_ttr(source) {
283
+ let deferred3_0;
284
+ let deferred3_1;
285
+ try {
286
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
287
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
288
+ const len0 = WASM_VECTOR_LEN;
289
+ wasm.verify_ttr(retptr, ptr0, len0);
290
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
291
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
292
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
293
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
294
+ var ptr2 = r0;
295
+ var len2 = r1;
296
+ if (r3) {
297
+ ptr2 = 0; len2 = 0;
298
+ throw takeObject(r2);
299
+ }
300
+ deferred3_0 = ptr2;
301
+ deferred3_1 = len2;
302
+ return getStringFromWasm0(ptr2, len2);
303
+ } finally {
304
+ wasm.__wbindgen_add_to_stack_pointer(16);
305
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
306
+ }
307
+ }
308
+ exports.verify_ttr = verify_ttr;
309
+
310
+ /**
311
+ * Verify a multiplayer source replay through an encode/decode round trip.
312
+ *
313
+ * # Errors
314
+ *
315
+ * Returns a JavaScript error when validation, encoding, decoding, or semantic
316
+ * data-model comparison fails.
317
+ * @param {Uint8Array} source
318
+ * @returns {string}
319
+ */
320
+ function verify_ttrm(source) {
321
+ let deferred3_0;
322
+ let deferred3_1;
323
+ try {
324
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
325
+ const ptr0 = passArray8ToWasm0(source, wasm.__wbindgen_export);
326
+ const len0 = WASM_VECTOR_LEN;
327
+ wasm.verify_ttrm(retptr, ptr0, len0);
328
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
329
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
330
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
331
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
332
+ var ptr2 = r0;
333
+ var len2 = r1;
334
+ if (r3) {
335
+ ptr2 = 0; len2 = 0;
336
+ throw takeObject(r2);
337
+ }
338
+ deferred3_0 = ptr2;
339
+ deferred3_1 = len2;
340
+ return getStringFromWasm0(ptr2, len2);
341
+ } finally {
342
+ wasm.__wbindgen_add_to_stack_pointer(16);
343
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
344
+ }
345
+ }
346
+ exports.verify_ttrm = verify_ttrm;
347
+
348
+ /**
349
+ * Validate a binary container and verify its decoded replay data model.
350
+ *
351
+ * # Errors
352
+ *
353
+ * Returns a JavaScript error when container validation or the decoded replay's
354
+ * encode/decode verification fails.
355
+ * @param {Uint8Array} container
356
+ * @returns {string}
357
+ */
358
+ function verify_ttrx(container) {
359
+ let deferred3_0;
360
+ let deferred3_1;
361
+ try {
362
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
363
+ const ptr0 = passArray8ToWasm0(container, wasm.__wbindgen_export);
364
+ const len0 = WASM_VECTOR_LEN;
365
+ wasm.verify_ttrx(retptr, ptr0, len0);
366
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
367
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
368
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
369
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
370
+ var ptr2 = r0;
371
+ var len2 = r1;
372
+ if (r3) {
373
+ ptr2 = 0; len2 = 0;
374
+ throw takeObject(r2);
375
+ }
376
+ deferred3_0 = ptr2;
377
+ deferred3_1 = len2;
378
+ return getStringFromWasm0(ptr2, len2);
379
+ } finally {
380
+ wasm.__wbindgen_add_to_stack_pointer(16);
381
+ wasm.__wbindgen_export2(deferred3_0, deferred3_1, 1);
382
+ }
383
+ }
384
+ exports.verify_ttrx = verify_ttrx;
385
+ function __wbg_get_imports() {
386
+ const import0 = {
387
+ __proto__: null,
388
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
389
+ // Cast intrinsic for `Ref(String) -> Externref`.
390
+ const ret = getStringFromWasm0(arg0, arg1);
391
+ return addHeapObject(ret);
392
+ },
393
+ };
394
+ return {
395
+ __proto__: null,
396
+ "./ttrx_wasm_bg.js": import0,
397
+ };
398
+ }
399
+
400
+ function addHeapObject(obj) {
401
+ if (heap_next === heap.length) heap.push(heap.length + 1);
402
+ const idx = heap_next;
403
+ heap_next = heap[idx];
404
+
405
+ heap[idx] = obj;
406
+ return idx;
407
+ }
408
+
409
+ function dropObject(idx) {
410
+ if (idx < 1028) return;
411
+ heap[idx] = heap_next;
412
+ heap_next = idx;
413
+ }
414
+
415
+ function getArrayU8FromWasm0(ptr, len) {
416
+ ptr = ptr >>> 0;
417
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
418
+ }
419
+
420
+ let cachedDataViewMemory0 = null;
421
+ function getDataViewMemory0() {
422
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
423
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
424
+ }
425
+ return cachedDataViewMemory0;
426
+ }
427
+
428
+ function getStringFromWasm0(ptr, len) {
429
+ return decodeText(ptr >>> 0, len);
430
+ }
431
+
432
+ let cachedUint8ArrayMemory0 = null;
433
+ function getUint8ArrayMemory0() {
434
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
435
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
436
+ }
437
+ return cachedUint8ArrayMemory0;
438
+ }
439
+
440
+ function getObject(idx) { return heap[idx]; }
441
+
442
+ let heap = new Array(1024).fill(undefined);
443
+ heap.push(undefined, null, true, false);
444
+
445
+ let heap_next = heap.length;
446
+
447
+ function passArray8ToWasm0(arg, malloc) {
448
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
449
+ getUint8ArrayMemory0().set(arg, ptr / 1);
450
+ WASM_VECTOR_LEN = arg.length;
451
+ return ptr;
452
+ }
453
+
454
+ function takeObject(idx) {
455
+ const ret = getObject(idx);
456
+ dropObject(idx);
457
+ return ret;
458
+ }
459
+
460
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
461
+ cachedTextDecoder.decode();
462
+ function decodeText(ptr, len) {
463
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
464
+ }
465
+
466
+ let WASM_VECTOR_LEN = 0;
467
+
468
+ const wasmPath = `${__dirname}/ttrx_wasm_bg.wasm`;
469
+ const wasmBytes = require('fs').readFileSync(wasmPath);
470
+ const wasmModule = new WebAssembly.Module(wasmBytes);
471
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
472
+ let wasm = wasmInstance.exports;
Binary file
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const decode_ttrx: (a: number, b: number, c: number) => void;
5
+ export const encode_ttr: (a: number, b: number, c: number) => void;
6
+ export const encode_ttrm: (a: number, b: number, c: number) => void;
7
+ export const inspect_ttr: (a: number, b: number, c: number) => void;
8
+ export const inspect_ttrm: (a: number, b: number, c: number) => void;
9
+ export const inspect_ttrx: (a: number, b: number, c: number) => void;
10
+ export const ttrx_source_extension: (a: number, b: number, c: number) => void;
11
+ export const ttrx_version: (a: number) => void;
12
+ export const verify_ttr: (a: number, b: number, c: number) => void;
13
+ export const verify_ttrm: (a: number, b: number, c: number) => void;
14
+ export const verify_ttrx: (a: number, b: number, c: number) => void;
15
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
16
+ export const __wbindgen_export: (a: number, b: number) => number;
17
+ export const __wbindgen_export2: (a: number, b: number, c: number) => void;
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "tetr-ttrx",
3
+ "version": "0.1.0",
4
+ "description": "Convert TETR.IO .ttr and .ttrm replays to a compact, reversible .ttrx binary format.",
5
+ "license": "MIT",
6
+ "author": "daejunnom",
7
+ "type": "commonjs",
8
+ "main": "./dist/node/ttrx_wasm.js",
9
+ "module": "./dist/bundler/ttrx_wasm.js",
10
+ "browser": "./dist/bundler/ttrx_wasm.js",
11
+ "types": "./dist/node/ttrx_wasm.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/node/ttrx_wasm.d.ts",
15
+ "browser": "./dist/bundler/ttrx_wasm.js",
16
+ "import": "./dist/node/index.mjs",
17
+ "require": "./dist/node/ttrx_wasm.js",
18
+ "default": "./dist/bundler/ttrx_wasm.js"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "dist/",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "sideEffects": [
28
+ "./dist/bundler/ttrx_wasm.js"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "keywords": [
34
+ "tetrio",
35
+ "tetris",
36
+ "replay",
37
+ "wasm",
38
+ "webassembly",
39
+ "ttrx"
40
+ ],
41
+ "scripts": {
42
+ "build": "node scripts/build-npm.mjs",
43
+ "check:release": "node scripts/check-release-version.mjs",
44
+ "test": "cargo test --workspace --all-targets --locked",
45
+ "test:package:cjs": "node scripts/npm-package-smoke.cjs",
46
+ "test:package:esm": "node scripts/npm-package-smoke.mjs",
47
+ "test:package": "npm run test:package:cjs && npm run test:package:esm",
48
+ "prepack": "npm run build && npm run test:package"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "https://github.com/daejunnom/TTRX"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/daejunnom/TTRX/issues"
59
+ },
60
+ "homepage": "https://github.com/daejunnom/TTRX#readme"
61
+ }