@datamoc/mw_games 0.15.0 → 0.17.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 (139) hide show
  1. package/CHANGELOG.md +154 -1
  2. package/README.md +21 -1
  3. package/dist/ai/lua.d.ts.map +1 -1
  4. package/dist/ai/lua.js +1 -0
  5. package/dist/ai/lua.js.map +1 -1
  6. package/dist/core/ActionJournal.d.ts +5 -0
  7. package/dist/core/ActionJournal.d.ts.map +1 -1
  8. package/dist/core/ActionJournal.js +12 -1
  9. package/dist/core/ActionJournal.js.map +1 -1
  10. package/dist/core/Clone.d.ts +31 -0
  11. package/dist/core/Clone.d.ts.map +1 -0
  12. package/dist/core/Clone.js +84 -0
  13. package/dist/core/Clone.js.map +1 -0
  14. package/dist/core/Collection.d.ts +1 -0
  15. package/dist/core/Collection.d.ts.map +1 -1
  16. package/dist/core/Collection.js +6 -2
  17. package/dist/core/Collection.js.map +1 -1
  18. package/dist/core/HttpTransport.d.ts +17 -0
  19. package/dist/core/HttpTransport.d.ts.map +1 -1
  20. package/dist/core/HttpTransport.js +61 -0
  21. package/dist/core/HttpTransport.js.map +1 -1
  22. package/dist/core/Multiplayer.d.ts +9 -0
  23. package/dist/core/Multiplayer.d.ts.map +1 -1
  24. package/dist/core/Multiplayer.js +48 -4
  25. package/dist/core/Multiplayer.js.map +1 -1
  26. package/dist/core/News.d.ts.map +1 -1
  27. package/dist/core/News.js +1 -2
  28. package/dist/core/News.js.map +1 -1
  29. package/dist/core/Sanitize.d.ts +19 -0
  30. package/dist/core/Sanitize.d.ts.map +1 -1
  31. package/dist/core/Sanitize.js +37 -0
  32. package/dist/core/Sanitize.js.map +1 -1
  33. package/dist/core/Save.d.ts +18 -9
  34. package/dist/core/Save.d.ts.map +1 -1
  35. package/dist/core/Save.js +37 -21
  36. package/dist/core/Save.js.map +1 -1
  37. package/dist/core/SaveSync.js +4 -4
  38. package/dist/core/SaveSync.js.map +1 -1
  39. package/dist/core/Settings.d.ts.map +1 -1
  40. package/dist/core/Settings.js +2 -1
  41. package/dist/core/Settings.js.map +1 -1
  42. package/dist/core/State.d.ts.map +1 -1
  43. package/dist/core/State.js +8 -7
  44. package/dist/core/State.js.map +1 -1
  45. package/dist/core/StoredValue.d.ts +1 -1
  46. package/dist/core/StoredValue.d.ts.map +1 -1
  47. package/dist/core/StoredValue.js +3 -2
  48. package/dist/core/StoredValue.js.map +1 -1
  49. package/dist/core/Telemetry.d.ts +19 -1
  50. package/dist/core/Telemetry.d.ts.map +1 -1
  51. package/dist/core/Telemetry.js +26 -1
  52. package/dist/core/Telemetry.js.map +1 -1
  53. package/dist/core/index.d.ts +2 -1
  54. package/dist/core/index.d.ts.map +1 -1
  55. package/dist/core/index.js +2 -1
  56. package/dist/core/index.js.map +1 -1
  57. package/dist/mw_games.global.js +107 -107
  58. package/dist/mwl/MapFile.js +11 -1
  59. package/dist/mwl/MapFile.js.map +1 -1
  60. package/dist/mwl/expression.js +38 -5
  61. package/dist/mwl/expression.js.map +1 -1
  62. package/dist/mwl/fengari.d.ts +8 -0
  63. package/dist/mwl/fengari.d.ts.map +1 -1
  64. package/dist/mwl/fengari.js +72 -2
  65. package/dist/mwl/fengari.js.map +1 -1
  66. package/dist/mwl/persistence.d.ts.map +1 -1
  67. package/dist/mwl/persistence.js +2 -1
  68. package/dist/mwl/persistence.js.map +1 -1
  69. package/dist/mwl/runtime.d.ts.map +1 -1
  70. package/dist/mwl/runtime.js +6 -1
  71. package/dist/mwl/runtime.js.map +1 -1
  72. package/dist/rpg/Marshal.d.ts.map +1 -1
  73. package/dist/rpg/Marshal.js +13 -0
  74. package/dist/rpg/Marshal.js.map +1 -1
  75. package/dist/simulation/Campaign.d.ts.map +1 -1
  76. package/dist/simulation/Campaign.js +9 -5
  77. package/dist/simulation/Campaign.js.map +1 -1
  78. package/dist/simulation/Harness.d.ts.map +1 -1
  79. package/dist/simulation/Harness.js +2 -1
  80. package/dist/simulation/Harness.js.map +1 -1
  81. package/dist/simulation/Runtime.d.ts +10 -0
  82. package/dist/simulation/Runtime.d.ts.map +1 -1
  83. package/dist/simulation/Runtime.js +25 -4
  84. package/dist/simulation/Runtime.js.map +1 -1
  85. package/dist/testing/index.d.ts +105 -0
  86. package/dist/testing/index.d.ts.map +1 -0
  87. package/dist/testing/index.js +134 -0
  88. package/dist/testing/index.js.map +1 -0
  89. package/dist/two-d/render/RpgmAutotile.d.ts +217 -0
  90. package/dist/two-d/render/RpgmAutotile.d.ts.map +1 -1
  91. package/dist/two-d/render/RpgmAutotile.js +756 -0
  92. package/dist/two-d/render/RpgmAutotile.js.map +1 -1
  93. package/dist/two-d/render/TileMap.d.ts +90 -0
  94. package/dist/two-d/render/TileMap.d.ts.map +1 -1
  95. package/dist/two-d/render/TileMap.js +319 -31
  96. package/dist/two-d/render/TileMap.js.map +1 -1
  97. package/dist/two-d/render/index.d.ts +3 -3
  98. package/dist/two-d/render/index.d.ts.map +1 -1
  99. package/dist/two-d/render/index.js +1 -1
  100. package/dist/two-d/render/index.js.map +1 -1
  101. package/dist/version.d.ts +1 -1
  102. package/dist/version.js +1 -1
  103. package/package.json +90 -25
  104. package/sbom.cdx.json +5589 -0
  105. package/tools/benchmark-browser.d.mts +33 -0
  106. package/tools/benchmark-browser.mjs +163 -0
  107. package/tools/benchmark-history.d.mts +8 -0
  108. package/tools/benchmark-history.mjs +31 -0
  109. package/tools/browser-smoke.d.mts +30 -0
  110. package/tools/browser-smoke.mjs +167 -0
  111. package/tools/bundle-size.d.mts +11 -0
  112. package/tools/bundle-size.mjs +138 -0
  113. package/tools/csp.d.mts +7 -0
  114. package/tools/csp.mjs +56 -0
  115. package/tools/emit-page.d.mts +44 -0
  116. package/tools/emit-page.mjs +188 -0
  117. package/tools/extract-rgssad.d.mts +5 -0
  118. package/tools/extract-rgssad.mjs +64 -0
  119. package/tools/find-chrome.d.mts +7 -0
  120. package/tools/find-chrome.mjs +104 -0
  121. package/tools/i18n-edit.d.mts +29 -0
  122. package/tools/i18n-edit.mjs +748 -0
  123. package/tools/make-example-assets.d.mts +2 -0
  124. package/tools/make-example-assets.mjs +727 -0
  125. package/tools/multiplayer-server.d.mts +27 -0
  126. package/tools/multiplayer-server.mjs +195 -0
  127. package/tools/mwl.mjs +1 -0
  128. package/tools/sbom.d.mts +83 -0
  129. package/tools/sbom.mjs +330 -0
  130. package/tools/vendored/rgssad-wasm/LICENSE-MIT +21 -0
  131. package/tools/vendored/rgssad-wasm/README.md +15 -0
  132. package/tools/vendored/rgssad-wasm/package.json +17 -0
  133. package/tools/vendored/rgssad-wasm/rgssad_wasm.d.ts +41 -0
  134. package/tools/vendored/rgssad-wasm/rgssad_wasm.js +6 -0
  135. package/tools/vendored/rgssad-wasm/rgssad_wasm_bg.js +399 -0
  136. package/tools/vendored/rgssad-wasm/rgssad_wasm_bg.wasm +0 -0
  137. package/tools/vendored/rgssad-wasm/rgssad_wasm_bg.wasm.d.ts +17 -0
  138. package/tools/vite.d.mts +17 -0
  139. package/tools/vite.mjs +83 -0
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "rgssad-wasm",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "files": [
6
+ "rgssad_wasm_bg.wasm",
7
+ "rgssad_wasm.js",
8
+ "rgssad_wasm_bg.js",
9
+ "rgssad_wasm.d.ts"
10
+ ],
11
+ "module": "rgssad_wasm.js",
12
+ "types": "rgssad_wasm.d.ts",
13
+ "sideEffects": [
14
+ "./rgssad_wasm.js",
15
+ "./snippets/*"
16
+ ]
17
+ }
@@ -0,0 +1,41 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * An Archive Reader
5
+ */
6
+ export class Reader {
7
+ free(): void;
8
+ /**
9
+ * Make a new [`Reader`].
10
+ *
11
+ * Accepts either an [`Uint8Array`] or an [`ArrayBuffer`].
12
+ * @param {any} value
13
+ */
14
+ constructor(value: any);
15
+ /**
16
+ * Get the next entry.
17
+ *
18
+ * # Arguments
19
+ * Takes a function as an argument.
20
+ * This function gets the file name and size as arguments.
21
+ * If this function returns true, it is skipped.
22
+ * If this function is absent, the entry is not skipped.
23
+ * @param {Function | undefined} skip
24
+ * @returns {ReaderEntry | undefined}
25
+ */
26
+ readEntry(skip?: Function): ReaderEntry | undefined;
27
+ }
28
+ /**
29
+ * An entry from a [`Reader`].
30
+ */
31
+ export class ReaderEntry {
32
+ free(): void;
33
+ /**
34
+ * Get the file data
35
+ */
36
+ readonly data: Uint8Array;
37
+ /**
38
+ * Get the file name.
39
+ */
40
+ readonly fileName: string;
41
+ }
@@ -0,0 +1,6 @@
1
+ import * as wasm from "./rgssad_wasm_bg.wasm";
2
+ import { __wbg_set_wasm } from "./rgssad_wasm_bg.js";
3
+ __wbg_set_wasm(wasm);
4
+ export * from "./rgssad_wasm_bg.js";
5
+
6
+ wasm.__wbindgen_start();
@@ -0,0 +1,399 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ function debugString(val) {
8
+ // primitive types
9
+ const type = typeof val;
10
+ if (type == 'number' || type == 'boolean' || val == null) {
11
+ return `${val}`;
12
+ }
13
+ if (type == 'string') {
14
+ return `"${val}"`;
15
+ }
16
+ if (type == 'symbol') {
17
+ const description = val.description;
18
+ if (description == null) {
19
+ return 'Symbol';
20
+ } else {
21
+ return `Symbol(${description})`;
22
+ }
23
+ }
24
+ if (type == 'function') {
25
+ const name = val.name;
26
+ if (typeof name == 'string' && name.length > 0) {
27
+ return `Function(${name})`;
28
+ } else {
29
+ return 'Function';
30
+ }
31
+ }
32
+ // objects
33
+ if (Array.isArray(val)) {
34
+ const length = val.length;
35
+ let debug = '[';
36
+ if (length > 0) {
37
+ debug += debugString(val[0]);
38
+ }
39
+ for(let i = 1; i < length; i++) {
40
+ debug += ', ' + debugString(val[i]);
41
+ }
42
+ debug += ']';
43
+ return debug;
44
+ }
45
+ // Test for built-in
46
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
47
+ let className;
48
+ if (builtInMatches.length > 1) {
49
+ className = builtInMatches[1];
50
+ } else {
51
+ // Failed to match the standard '[object ClassName]'
52
+ return toString.call(val);
53
+ }
54
+ if (className == 'Object') {
55
+ // we're a user defined class or Object
56
+ // JSON.stringify avoids problems with cycles, and is generally much
57
+ // easier than looping through ownProperties of `val`.
58
+ try {
59
+ return 'Object(' + JSON.stringify(val) + ')';
60
+ } catch (_) {
61
+ return 'Object';
62
+ }
63
+ }
64
+ // errors
65
+ if (val instanceof Error) {
66
+ return `${val.name}: ${val.message}\n${val.stack}`;
67
+ }
68
+ // TODO we could test for more things here, like `Set`s and `Map`s.
69
+ return className;
70
+ }
71
+
72
+ let WASM_VECTOR_LEN = 0;
73
+
74
+ let cachedUint8Memory0 = null;
75
+
76
+ function getUint8Memory0() {
77
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
78
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
79
+ }
80
+ return cachedUint8Memory0;
81
+ }
82
+
83
+ const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
84
+
85
+ let cachedTextEncoder = new lTextEncoder('utf-8');
86
+
87
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
88
+ ? function (arg, view) {
89
+ return cachedTextEncoder.encodeInto(arg, view);
90
+ }
91
+ : function (arg, view) {
92
+ const buf = cachedTextEncoder.encode(arg);
93
+ view.set(buf);
94
+ return {
95
+ read: arg.length,
96
+ written: buf.length
97
+ };
98
+ });
99
+
100
+ function passStringToWasm0(arg, malloc, realloc) {
101
+
102
+ if (realloc === undefined) {
103
+ const buf = cachedTextEncoder.encode(arg);
104
+ const ptr = malloc(buf.length, 1) >>> 0;
105
+ getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
106
+ WASM_VECTOR_LEN = buf.length;
107
+ return ptr;
108
+ }
109
+
110
+ let len = arg.length;
111
+ let ptr = malloc(len, 1) >>> 0;
112
+
113
+ const mem = getUint8Memory0();
114
+
115
+ let offset = 0;
116
+
117
+ for (; offset < len; offset++) {
118
+ const code = arg.charCodeAt(offset);
119
+ if (code > 0x7F) break;
120
+ mem[ptr + offset] = code;
121
+ }
122
+
123
+ if (offset !== len) {
124
+ if (offset !== 0) {
125
+ arg = arg.slice(offset);
126
+ }
127
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
128
+ const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
129
+ const ret = encodeString(arg, view);
130
+
131
+ offset += ret.written;
132
+ }
133
+
134
+ WASM_VECTOR_LEN = offset;
135
+ return ptr;
136
+ }
137
+
138
+ let cachedInt32Memory0 = null;
139
+
140
+ function getInt32Memory0() {
141
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
142
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
143
+ }
144
+ return cachedInt32Memory0;
145
+ }
146
+
147
+ const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
148
+
149
+ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
150
+
151
+ cachedTextDecoder.decode();
152
+
153
+ function getStringFromWasm0(ptr, len) {
154
+ ptr = ptr >>> 0;
155
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
156
+ }
157
+
158
+ function takeFromExternrefTable0(idx) {
159
+ const value = wasm.__wbindgen_export_2.get(idx);
160
+ wasm.__wbindgen_export_3(idx);
161
+ return value;
162
+ }
163
+
164
+ function isLikeNone(x) {
165
+ return x === undefined || x === null;
166
+ }
167
+
168
+ function addToExternrefTable0(obj) {
169
+ const idx = wasm.__wbindgen_export_4();
170
+ wasm.__wbindgen_export_2.set(idx, obj);
171
+ return idx;
172
+ }
173
+
174
+ function handleError(f, args) {
175
+ try {
176
+ return f.apply(this, args);
177
+ } catch (e) {
178
+ const idx = addToExternrefTable0(e);
179
+ wasm.__wbindgen_export_5(idx);
180
+ }
181
+ }
182
+ /**
183
+ * An Archive Reader
184
+ */
185
+ export class Reader {
186
+
187
+ static __wrap(ptr) {
188
+ ptr = ptr >>> 0;
189
+ const obj = Object.create(Reader.prototype);
190
+ obj.__wbg_ptr = ptr;
191
+
192
+ return obj;
193
+ }
194
+
195
+ __destroy_into_raw() {
196
+ const ptr = this.__wbg_ptr;
197
+ this.__wbg_ptr = 0;
198
+
199
+ return ptr;
200
+ }
201
+
202
+ free() {
203
+ const ptr = this.__destroy_into_raw();
204
+ wasm.__wbg_reader_free(ptr);
205
+ }
206
+ /**
207
+ * Make a new [`Reader`].
208
+ *
209
+ * Accepts either an [`Uint8Array`] or an [`ArrayBuffer`].
210
+ * @param {any} value
211
+ */
212
+ constructor(value) {
213
+ try {
214
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
215
+ wasm.reader_new(retptr, value);
216
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
217
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
218
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
219
+ if (r2) {
220
+ throw takeFromExternrefTable0(r1);
221
+ }
222
+ return Reader.__wrap(r0);
223
+ } finally {
224
+ wasm.__wbindgen_add_to_stack_pointer(16);
225
+ }
226
+ }
227
+ /**
228
+ * Get the next entry.
229
+ *
230
+ * # Arguments
231
+ * Takes a function as an argument.
232
+ * This function gets the file name and size as arguments.
233
+ * If this function returns true, it is skipped.
234
+ * If this function is absent, the entry is not skipped.
235
+ * @param {Function | undefined} skip
236
+ * @returns {ReaderEntry | undefined}
237
+ */
238
+ readEntry(skip) {
239
+ try {
240
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
241
+ wasm.reader_readEntry(retptr, this.__wbg_ptr, isLikeNone(skip) ? 0 : addToExternrefTable0(skip));
242
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
243
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
244
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
245
+ if (r2) {
246
+ throw takeFromExternrefTable0(r1);
247
+ }
248
+ return r0 === 0 ? undefined : ReaderEntry.__wrap(r0);
249
+ } finally {
250
+ wasm.__wbindgen_add_to_stack_pointer(16);
251
+ }
252
+ }
253
+ }
254
+ /**
255
+ * An entry from a [`Reader`].
256
+ */
257
+ export class ReaderEntry {
258
+
259
+ static __wrap(ptr) {
260
+ ptr = ptr >>> 0;
261
+ const obj = Object.create(ReaderEntry.prototype);
262
+ obj.__wbg_ptr = ptr;
263
+
264
+ return obj;
265
+ }
266
+
267
+ __destroy_into_raw() {
268
+ const ptr = this.__wbg_ptr;
269
+ this.__wbg_ptr = 0;
270
+
271
+ return ptr;
272
+ }
273
+
274
+ free() {
275
+ const ptr = this.__destroy_into_raw();
276
+ wasm.__wbg_readerentry_free(ptr);
277
+ }
278
+ /**
279
+ * Get the file name.
280
+ * @returns {string}
281
+ */
282
+ get fileName() {
283
+ const ret = wasm.readerentry_fileName(this.__wbg_ptr);
284
+ return ret;
285
+ }
286
+ /**
287
+ * Get the file data
288
+ * @returns {Uint8Array}
289
+ */
290
+ get data() {
291
+ const ret = wasm.readerentry_data(this.__wbg_ptr);
292
+ return ret;
293
+ }
294
+ }
295
+
296
+ export function __wbindgen_debug_string(arg0, arg1) {
297
+ const ret = debugString(arg1);
298
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
299
+ const len1 = WASM_VECTOR_LEN;
300
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
301
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
302
+ };
303
+
304
+ export function __wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4(arg0) {
305
+ let result;
306
+ try {
307
+ result = arg0 instanceof Uint8Array;
308
+ } catch {
309
+ result = false;
310
+ }
311
+ const ret = result;
312
+ return ret;
313
+ };
314
+
315
+ export function __wbg_instanceof_ArrayBuffer_39ac22089b74fddb(arg0) {
316
+ let result;
317
+ try {
318
+ result = arg0 instanceof ArrayBuffer;
319
+ } catch {
320
+ result = false;
321
+ }
322
+ const ret = result;
323
+ return ret;
324
+ };
325
+
326
+ export function __wbg_new_8125e318e6245eed(arg0) {
327
+ const ret = new Uint8Array(arg0);
328
+ return ret;
329
+ };
330
+
331
+ export function __wbindgen_error_new(arg0, arg1) {
332
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
333
+ return ret;
334
+ };
335
+
336
+ export function __wbindgen_string_new(arg0, arg1) {
337
+ const ret = getStringFromWasm0(arg0, arg1);
338
+ return ret;
339
+ };
340
+
341
+ export function __wbindgen_number_new(arg0) {
342
+ const ret = arg0;
343
+ return ret;
344
+ };
345
+
346
+ export function __wbg_call_4c92f6aec1e1d6e6() { return handleError(function (arg0, arg1, arg2, arg3) {
347
+ const ret = arg0.call(arg1, arg2, arg3);
348
+ return ret;
349
+ }, arguments) };
350
+
351
+ export function __wbindgen_is_falsy(arg0) {
352
+ const ret = !arg0;
353
+ return ret;
354
+ };
355
+
356
+ export function __wbg_newwithlength_e5d69174d6984cd7(arg0) {
357
+ const ret = new Uint8Array(arg0 >>> 0);
358
+ return ret;
359
+ };
360
+
361
+ export function __wbg_length_72e2208bbc0efc61(arg0) {
362
+ const ret = arg0.length;
363
+ return ret;
364
+ };
365
+
366
+ export function __wbindgen_memory() {
367
+ const ret = wasm.memory;
368
+ return ret;
369
+ };
370
+
371
+ export function __wbg_buffer_085ec1f694018c4f(arg0) {
372
+ const ret = arg0.buffer;
373
+ return ret;
374
+ };
375
+
376
+ export function __wbg_newwithbyteoffsetandlength_6da8e527659b86aa(arg0, arg1, arg2) {
377
+ const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
378
+ return ret;
379
+ };
380
+
381
+ export function __wbg_set_5cf90238115182c3(arg0, arg1, arg2) {
382
+ arg0.set(arg1, arg2 >>> 0);
383
+ };
384
+
385
+ export function __wbindgen_throw(arg0, arg1) {
386
+ throw new Error(getStringFromWasm0(arg0, arg1));
387
+ };
388
+
389
+ export function __wbindgen_init_externref_table() {
390
+ const table = wasm.__wbindgen_export_2;
391
+ const offset = table.grow(4);
392
+ table.set(0, undefined);
393
+ table.set(offset + 0, undefined);
394
+ table.set(offset + 1, null);
395
+ table.set(offset + 2, true);
396
+ table.set(offset + 3, false);
397
+ ;
398
+ };
399
+
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export function __wbg_reader_free(a: number): void;
5
+ export function reader_new(a: number, b: number): void;
6
+ export function reader_readEntry(a: number, b: number, c: number): void;
7
+ export function __wbg_readerentry_free(a: number): void;
8
+ export function readerentry_fileName(a: number): number;
9
+ export function readerentry_data(a: number): number;
10
+ export function __wbindgen_export_0(a: number, b: number): number;
11
+ export function __wbindgen_export_1(a: number, b: number, c: number, d: number): number;
12
+ export const __wbindgen_export_2: WebAssembly.Table;
13
+ export function __wbindgen_add_to_stack_pointer(a: number): number;
14
+ export function __wbindgen_export_3(a: number): void;
15
+ export function __wbindgen_export_4(): number;
16
+ export function __wbindgen_export_5(a: number): void;
17
+ export function __wbindgen_start(): void;
@@ -0,0 +1,17 @@
1
+ import type { EmitPageOptions } from './emit-page.mjs';
2
+
3
+ export interface MwgPageOptions extends Omit<EmitPageOptions, 'dist' | 'assets'> {
4
+ /** the asset source folder, relative to the vite root; served in dev and compiled in the build. Default `'assets'`, `false` for none */
5
+ assets?: string | false;
6
+ /** write `sbom.cdx.json`, the CycloneDX SBOM of what the build ships; default true */
7
+ sbom?: boolean;
8
+ }
9
+
10
+ /** the vite plugin that makes `vite build` alone write a page that opens from `file://` */
11
+ export function mwgPage(options?: MwgPageOptions): {
12
+ name: string;
13
+ config(): Record<string, unknown>;
14
+ configResolved(config: { root: string; command: string; build: { outDir: string } }): void;
15
+ generateBundle(options: unknown, bundle: Record<string, { type: string; modules?: Record<string, unknown> }>): void;
16
+ closeBundle(this: { meta?: { watchMode?: boolean } }): Promise<void>;
17
+ };
package/tools/vite.mjs ADDED
@@ -0,0 +1,83 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { writeFile } from 'node:fs/promises';
3
+ import { basename, join, resolve } from 'node:path';
4
+ import { emitPage } from './emit-page.mjs';
5
+ import { buildArtifactSbom, serialize, shippedFiles } from './sbom.mjs';
6
+
7
+ /**
8
+ * The vite side of a `file://` game in one plugin: `plugins: [mwgPage()]` and `vite build` alone
9
+ * writes a folder that opens by double-clicking, the build every example here uses.
10
+ *
11
+ * It sets the configuration that target needs (a classic IIFE bundle named `game.js`, relative
12
+ * urls through `base: './'`, no inlined or copied assets since they are compiled instead) and
13
+ * serves `assets` (default `'assets'`, `false` for none) as the public folder, so an asset path reads the same in `vite` dev as in the
14
+ * build. At the end of the build it runs `emitPage` over the output folder with the same
15
+ * options. A setting the game's own config gives explicitly still wins, since vite merges a
16
+ * plugin's `config` result under the user's.
17
+ *
18
+ * It also writes `sbom.cdx.json` into the output folder (`sbom: false` to skip it): a CycloneDX
19
+ * SBOM of what this build ships, the npm packages whose modules reached the bundle, from vite's
20
+ * own module graph, and every shipped file with its SHA-256. That is the inventory a player's
21
+ * copy actually contains, which a lockfile SBOM (`mwg-sbom`) cannot give: the lockfile lists
22
+ * vite and TypeScript, and cannot tell which dependencies tree-shaking kept.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * // vite.config.ts
27
+ * import { defineConfig } from 'vite';
28
+ * import { mwgPage } from '@datamoc/mw_games/tools/vite';
29
+ *
30
+ * export default defineConfig({ plugins: [mwgPage({ assets: 'assets', singleFile: true })] });
31
+ * ```
32
+ */
33
+ export function mwgPage(options = {}) {
34
+ const assets = options.assets ?? 'assets';
35
+ let root = process.cwd();
36
+ let outDir = 'dist';
37
+ let building = false;
38
+ const modules = new Set();
39
+ return {
40
+ name: 'mwg-page',
41
+ config() {
42
+ return {
43
+ base: './',
44
+ publicDir: assets || false,
45
+ build: {
46
+ target: 'es2022',
47
+ assetsInlineLimit: 0,
48
+ copyPublicDir: false,
49
+ //emitPage writes real .gz/.br files, so vite need not estimate them in memory
50
+ reportCompressedSize: false,
51
+ rollupOptions: {
52
+ output: { format: 'iife', entryFileNames: 'game.js', assetFileNames: '[name][extname]' },
53
+ },
54
+ },
55
+ };
56
+ },
57
+ generateBundle(_options, bundle) {
58
+ for (const chunk of Object.values(bundle))
59
+ if (chunk.type === 'chunk') for (const id of Object.keys(chunk.modules)) modules.add(id);
60
+ },
61
+ configResolved(config) {
62
+ root = config.root;
63
+ outDir = config.build.outDir;
64
+ building = config.command === 'build';
65
+ },
66
+ async closeBundle() {
67
+ //vite also closes the bundle when a dev server stops; only a real build is finished
68
+ if (!building || this.meta?.watchMode) return;
69
+ const { assets: _assets, sbom = true, ...emitOptions } = options;
70
+ const source = assets ? resolve(root, assets) : undefined;
71
+ const dist = resolve(root, outDir);
72
+ await emitPage({ ...emitOptions, dist, assets: source && existsSync(source) ? source : undefined });
73
+ if (sbom) {
74
+ const manifest = join(root, 'package.json');
75
+ const packageJson = existsSync(manifest)
76
+ ? JSON.parse(readFileSync(manifest, 'utf8'))
77
+ : { name: basename(root), version: '0.0.0' };
78
+ const bom = buildArtifactSbom({ packageJson, modules: [...modules], files: await shippedFiles(dist) });
79
+ await writeFile(join(dist, 'sbom.cdx.json'), serialize(bom), 'utf8');
80
+ }
81
+ },
82
+ };
83
+ }