ballistics-engine 0.25.1 → 0.30.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.
@@ -1,9 +1,656 @@
1
1
  /* @ts-self-types="./ballistics_engine.d.ts" */
2
2
 
3
- import * as wasm from "./ballistics_engine_bg.wasm";
4
- import { __wbg_set_wasm } from "./ballistics_engine_bg.js";
5
- __wbg_set_wasm(wasm);
6
- wasm.__wbindgen_start();
7
- export {
8
- Calculator, WasmBallistics
9
- } from "./ballistics_engine_bg.js";
3
+ /**
4
+ * Object-oriented calculator for programmatic use
5
+ * Provides a type-safe, fluent API alternative to the CLI interface
6
+ */
7
+ export class Calculator {
8
+ static __wrap(ptr) {
9
+ const obj = Object.create(Calculator.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ CalculatorFinalization.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
+ CalculatorFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_calculator_free(ptr, 0);
23
+ }
24
+ /**
25
+ * Add a downrange wind segment: `speed_mph` from `direction_deg`
26
+ * (wind-FROM: 0 = headwind, 90 = from the right) out to `until_yards`.
27
+ * Each segment applies from the previous boundary to `until_yards`; wind is
28
+ * zero beyond the last segment. When any segment is added it overrides the
29
+ * scalar `setWind` value. Repeatable.
30
+ * @param {number} speed_mph
31
+ * @param {number} direction_deg
32
+ * @param {number} until_yards
33
+ * @returns {Calculator}
34
+ */
35
+ addWindSegment(speed_mph, direction_deg, until_yards) {
36
+ const ptr = this.__destroy_into_raw();
37
+ const ret = wasm.calculator_addWindSegment(ptr, speed_mph, direction_deg, until_yards);
38
+ return Calculator.__wrap(ret);
39
+ }
40
+ /**
41
+ * Calculate trajectory and return result as JavaScript object
42
+ * Returns: { range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }
43
+ * @param {number} range_yards
44
+ * @returns {any}
45
+ */
46
+ calculateTrajectory(range_yards) {
47
+ const ret = wasm.calculator_calculateTrajectory(this.__wbg_ptr, range_yards);
48
+ if (ret[2]) {
49
+ throw takeFromExternrefTable0(ret[1]);
50
+ }
51
+ return takeFromExternrefTable0(ret[0]);
52
+ }
53
+ /**
54
+ * Remove all downrange wind segments (reverts to the scalar `setWind`).
55
+ * @returns {Calculator}
56
+ */
57
+ clearWindSegments() {
58
+ const ptr = this.__destroy_into_raw();
59
+ const ret = wasm.calculator_clearWindSegments(ptr);
60
+ return Calculator.__wrap(ret);
61
+ }
62
+ /**
63
+ * @param {boolean} enabled
64
+ * @param {number | null} [latitude]
65
+ * @returns {Calculator}
66
+ */
67
+ enableCoriolis(enabled, latitude) {
68
+ const ptr = this.__destroy_into_raw();
69
+ const ret = wasm.calculator_enableCoriolis(ptr, enabled, !isLikeNone(latitude), isLikeNone(latitude) ? 0 : latitude);
70
+ return Calculator.__wrap(ret);
71
+ }
72
+ /**
73
+ * @param {boolean} enabled
74
+ * @param {number | null} [twist_rate]
75
+ * @returns {Calculator}
76
+ */
77
+ enableSpinDrift(enabled, twist_rate) {
78
+ const ptr = this.__destroy_into_raw();
79
+ const ret = wasm.calculator_enableSpinDrift(ptr, enabled, !isLikeNone(twist_rate), isLikeNone(twist_rate) ? 0 : twist_rate);
80
+ return Calculator.__wrap(ret);
81
+ }
82
+ /**
83
+ * Get full trajectory table as array of points
84
+ * Returns array of: [{ range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }, ...]
85
+ * @returns {any}
86
+ */
87
+ getFullTrajectory() {
88
+ const ret = wasm.calculator_getFullTrajectory(this.__wbg_ptr);
89
+ if (ret[2]) {
90
+ throw takeFromExternrefTable0(ret[1]);
91
+ }
92
+ return takeFromExternrefTable0(ret[0]);
93
+ }
94
+ /**
95
+ * Create a new calculator with default values
96
+ * Defaults: .308 Winchester 168gr at 2700 fps, standard atmosphere
97
+ */
98
+ constructor() {
99
+ const ret = wasm.calculator_new();
100
+ this.__wbg_ptr = ret;
101
+ CalculatorFinalization.register(this, this.__wbg_ptr, this);
102
+ return this;
103
+ }
104
+ /**
105
+ * @param {number} altitude_ft
106
+ * @returns {Calculator}
107
+ */
108
+ setAltitude(altitude_ft) {
109
+ const ptr = this.__destroy_into_raw();
110
+ const ret = wasm.calculator_setAltitude(ptr, altitude_ft);
111
+ return Calculator.__wrap(ret);
112
+ }
113
+ /**
114
+ * @param {number} bc
115
+ * @returns {Calculator}
116
+ */
117
+ setBC(bc) {
118
+ const ptr = this.__destroy_into_raw();
119
+ const ret = wasm.calculator_setBC(ptr, bc);
120
+ return Calculator.__wrap(ret);
121
+ }
122
+ /**
123
+ * @param {number} diameter_inches
124
+ * @returns {Calculator}
125
+ */
126
+ setDiameter(diameter_inches) {
127
+ const ptr = this.__destroy_into_raw();
128
+ const ret = wasm.calculator_setDiameter(ptr, diameter_inches);
129
+ return Calculator.__wrap(ret);
130
+ }
131
+ /**
132
+ * @param {string} model
133
+ * @returns {Calculator}
134
+ */
135
+ setDragModel(model) {
136
+ const ptr = this.__destroy_into_raw();
137
+ const ptr0 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
138
+ const len0 = WASM_VECTOR_LEN;
139
+ const ret = wasm.calculator_setDragModel(ptr, ptr0, len0);
140
+ return Calculator.__wrap(ret);
141
+ }
142
+ /**
143
+ * @param {number} humidity
144
+ * @returns {Calculator}
145
+ */
146
+ setHumidity(humidity) {
147
+ const ptr = this.__destroy_into_raw();
148
+ const ret = wasm.calculator_setHumidity(ptr, humidity);
149
+ return Calculator.__wrap(ret);
150
+ }
151
+ /**
152
+ * @param {number} mass_grains
153
+ * @returns {Calculator}
154
+ */
155
+ setMass(mass_grains) {
156
+ const ptr = this.__destroy_into_raw();
157
+ const ret = wasm.calculator_setMass(ptr, mass_grains);
158
+ return Calculator.__wrap(ret);
159
+ }
160
+ /**
161
+ * @param {number} range_yards
162
+ * @returns {Calculator}
163
+ */
164
+ setMaxRange(range_yards) {
165
+ const ptr = this.__destroy_into_raw();
166
+ const ret = wasm.calculator_setMaxRange(ptr, range_yards);
167
+ return Calculator.__wrap(ret);
168
+ }
169
+ /**
170
+ * @param {number} pressure_inhg
171
+ * @returns {Calculator}
172
+ */
173
+ setPressure(pressure_inhg) {
174
+ const ptr = this.__destroy_into_raw();
175
+ const ret = wasm.calculator_setPressure(ptr, pressure_inhg);
176
+ return Calculator.__wrap(ret);
177
+ }
178
+ /**
179
+ * @param {number} height_inches
180
+ * @returns {Calculator}
181
+ */
182
+ setSightHeight(height_inches) {
183
+ const ptr = this.__destroy_into_raw();
184
+ const ret = wasm.calculator_setSightHeight(ptr, height_inches);
185
+ return Calculator.__wrap(ret);
186
+ }
187
+ /**
188
+ * @param {number} temp_f
189
+ * @returns {Calculator}
190
+ */
191
+ setTemperature(temp_f) {
192
+ const ptr = this.__destroy_into_raw();
193
+ const ret = wasm.calculator_setTemperature(ptr, temp_f);
194
+ return Calculator.__wrap(ret);
195
+ }
196
+ /**
197
+ * @param {number} velocity_fps
198
+ * @returns {Calculator}
199
+ */
200
+ setVelocity(velocity_fps) {
201
+ const ptr = this.__destroy_into_raw();
202
+ const ret = wasm.calculator_setVelocity(ptr, velocity_fps);
203
+ return Calculator.__wrap(ret);
204
+ }
205
+ /**
206
+ * @param {number} speed_mph
207
+ * @param {number} direction_deg
208
+ * @returns {Calculator}
209
+ */
210
+ setWind(speed_mph, direction_deg) {
211
+ const ptr = this.__destroy_into_raw();
212
+ const ret = wasm.calculator_setWind(ptr, speed_mph, direction_deg);
213
+ return Calculator.__wrap(ret);
214
+ }
215
+ /**
216
+ * @param {number} range_yards
217
+ * @returns {Calculator}
218
+ */
219
+ setZeroRange(range_yards) {
220
+ const ptr = this.__destroy_into_raw();
221
+ const ret = wasm.calculator_setZeroRange(ptr, range_yards);
222
+ return Calculator.__wrap(ret);
223
+ }
224
+ }
225
+ if (Symbol.dispose) Calculator.prototype[Symbol.dispose] = Calculator.prototype.free;
226
+
227
+ export class WasmBallistics {
228
+ __destroy_into_raw() {
229
+ const ptr = this.__wbg_ptr;
230
+ this.__wbg_ptr = 0;
231
+ WasmBallisticsFinalization.unregister(this);
232
+ return ptr;
233
+ }
234
+ free() {
235
+ const ptr = this.__destroy_into_raw();
236
+ wasm.__wbg_wasmballistics_free(ptr, 0);
237
+ }
238
+ /**
239
+ * Unload any custom drag table previously installed via [`Self::load_drag_table`],
240
+ * reverting every subsequent `trajectory`, `zero`, `lead`, and `monte-carlo` run to the
241
+ * standard G-model + BC drag (the `-b`/`--bc` value with the selected G1/G7 curve).
242
+ *
243
+ * The inverse of `loadDragTable`. It lets a single engine instance alternate between a
244
+ * measured-curve (CDM) solve and a plain G7-BC solve without constructing a second
245
+ * instance: `load → solve CDM → clear → solve G7`, with the G7 half uncontaminated —
246
+ * the same load/clear pattern `clearWindSegments` provides for segmented wind.
247
+ *
248
+ * Returns `true` if a table was loaded (and is now cleared), `false` if none was loaded
249
+ * (a harmless no-op). Idempotent.
250
+ * @returns {boolean}
251
+ */
252
+ clearDragTable() {
253
+ const ret = wasm.wasmballistics_clearDragTable(this.__wbg_ptr);
254
+ return ret !== 0;
255
+ }
256
+ /**
257
+ * Report whether a BC5D table is currently loaded.
258
+ * @returns {boolean}
259
+ */
260
+ hasBc5dTable() {
261
+ const ret = wasm.wasmballistics_hasBc5dTable(this.__wbg_ptr);
262
+ return ret !== 0;
263
+ }
264
+ /**
265
+ * Report whether a custom drag table is currently loaded.
266
+ * @returns {boolean}
267
+ */
268
+ hasDragTable() {
269
+ const ret = wasm.wasmballistics_hasDragTable(this.__wbg_ptr);
270
+ return ret !== 0;
271
+ }
272
+ /**
273
+ * Load a BC5D correction table from the raw bytes of a `bc5d_<caliber>.bin`
274
+ * file. The host (browser `fetch()` or Node `fs`/`fetch`) is responsible
275
+ * for retrieving the file — WASM has no filesystem or network — and passes
276
+ * the bytes here.
277
+ *
278
+ * Once loaded, any `trajectory` run that includes `--use-bc-segments` will
279
+ * apply velocity-dependent BC segments synthesized from this table. Load a
280
+ * table matching the bullet's caliber (e.g. `bc5d_308.bin` for a .308).
281
+ *
282
+ * Returns a short human-readable summary of the loaded table. Replaces any
283
+ * previously loaded table.
284
+ * @param {Uint8Array} bytes
285
+ * @returns {string}
286
+ */
287
+ loadBc5dTable(bytes) {
288
+ let deferred3_0;
289
+ let deferred3_1;
290
+ try {
291
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
292
+ const len0 = WASM_VECTOR_LEN;
293
+ const ret = wasm.wasmballistics_loadBc5dTable(this.__wbg_ptr, ptr0, len0);
294
+ var ptr2 = ret[0];
295
+ var len2 = ret[1];
296
+ if (ret[3]) {
297
+ ptr2 = 0; len2 = 0;
298
+ throw takeFromExternrefTable0(ret[2]);
299
+ }
300
+ deferred3_0 = ptr2;
301
+ deferred3_1 = len2;
302
+ return getStringFromWasm0(ptr2, len2);
303
+ } finally {
304
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
305
+ }
306
+ }
307
+ /**
308
+ * Load a custom Mach:Cd drag table (MBA-1328) — a measured or manufacturer-published
309
+ * drag curve (Hornady CDM data, a Lapua/Doppler-radar-derived deck, or your own) — from
310
+ * the raw bytes of a CSV file. The host (browser `fetch()` or Node `fs`/`fetch`) is
311
+ * responsible for retrieving the file — WASM has no filesystem or network — and passes
312
+ * the bytes here, mirroring [`Self::load_bc5d_table`].
313
+ *
314
+ * The bytes must be valid UTF-8 CSV text; parsing is delegated to
315
+ * [`crate::drag::DragTable::from_csv_str`] — the SAME parser native `--drag-table`
316
+ * uses — so the accepted format is identical: two columns `mach,cd` per line, blank
317
+ * lines and `#` comments ignored, a single leading textual header row tolerated, Mach
318
+ * strictly ascending with at least 2 points, Cd finite and > 0.
319
+ *
320
+ * Once loaded, EVERY subsequent `trajectory`, `zero`, `lead`, and `monte-carlo` run
321
+ * applies the table automatically — no `--use-*` gate flag is needed (unlike a loaded
322
+ * BC5D table, which only takes effect with `--use-bc-segments`). A loaded table is a
323
+ * full physical substitute for the G-model + BC (see `calculate_drag_coefficient`):
324
+ * `-b`/`--bc` may still be supplied but is ignored for drag once a table is active
325
+ * (matching the native `--drag-table` CLI semantics documented in CLI_USAGE.md).
326
+ *
327
+ * Returns a short human-readable summary of the loaded table (point count + Mach
328
+ * range). Replaces any previously loaded table.
329
+ *
330
+ * MBA-1409: also accepts `.drg` vendor drag-curve text (the same format the native
331
+ * `--drag-table` CLI accepts by `.drg` file extension) as a fallback. WASM has no
332
+ * filesystem and thus no extension to dispatch on, so the bytes are tried as CSV first
333
+ * (exactly as before this change); only on CSV failure, if the text
334
+ * [`crate::drag_file::looks_like_drg`], it is retried through
335
+ * [`crate::drag_file::parse_drg`]. If both fail, the returned error names both formats.
336
+ * @param {Uint8Array} bytes
337
+ * @returns {string}
338
+ */
339
+ loadDragTable(bytes) {
340
+ let deferred3_0;
341
+ let deferred3_1;
342
+ try {
343
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
344
+ const len0 = WASM_VECTOR_LEN;
345
+ const ret = wasm.wasmballistics_loadDragTable(this.__wbg_ptr, ptr0, len0);
346
+ var ptr2 = ret[0];
347
+ var len2 = ret[1];
348
+ if (ret[3]) {
349
+ ptr2 = 0; len2 = 0;
350
+ throw takeFromExternrefTable0(ret[2]);
351
+ }
352
+ deferred3_0 = ptr2;
353
+ deferred3_1 = len2;
354
+ return getStringFromWasm0(ptr2, len2);
355
+ } finally {
356
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
357
+ }
358
+ }
359
+ constructor() {
360
+ const ret = wasm.wasmballistics_new();
361
+ this.__wbg_ptr = ret;
362
+ WasmBallisticsFinalization.register(this, this.__wbg_ptr, this);
363
+ return this;
364
+ }
365
+ /**
366
+ * Run a command and return the output
367
+ * @param {string} command
368
+ * @returns {string}
369
+ */
370
+ runCommand(command) {
371
+ let deferred3_0;
372
+ let deferred3_1;
373
+ try {
374
+ const ptr0 = passStringToWasm0(command, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
375
+ const len0 = WASM_VECTOR_LEN;
376
+ const ret = wasm.wasmballistics_runCommand(this.__wbg_ptr, ptr0, len0);
377
+ var ptr2 = ret[0];
378
+ var len2 = ret[1];
379
+ if (ret[3]) {
380
+ ptr2 = 0; len2 = 0;
381
+ throw takeFromExternrefTable0(ret[2]);
382
+ }
383
+ deferred3_0 = ptr2;
384
+ deferred3_1 = len2;
385
+ return getStringFromWasm0(ptr2, len2);
386
+ } finally {
387
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
388
+ }
389
+ }
390
+ }
391
+ if (Symbol.dispose) WasmBallistics.prototype[Symbol.dispose] = WasmBallistics.prototype.free;
392
+ function __wbg_get_imports() {
393
+ const import0 = {
394
+ __proto__: null,
395
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
396
+ throw new Error(getStringFromWasm0(arg0, arg1));
397
+ },
398
+ __wbg_getRandomValues_cc7f052a444bb2ce: function() { return handleError(function (arg0, arg1) {
399
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
400
+ }, arguments); },
401
+ __wbg_new_32b398fb48b6d94a: function() {
402
+ const ret = new Array();
403
+ return ret;
404
+ },
405
+ __wbg_new_da52cf8fe3429cb2: function() {
406
+ const ret = new Object();
407
+ return ret;
408
+ },
409
+ __wbg_push_d2ae3af0c1217ae6: function(arg0, arg1) {
410
+ const ret = arg0.push(arg1);
411
+ return ret;
412
+ },
413
+ __wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
414
+ const ret = Reflect.set(arg0, arg1, arg2);
415
+ return ret;
416
+ }, arguments); },
417
+ __wbindgen_cast_0000000000000001: function(arg0) {
418
+ // Cast intrinsic for `F64 -> Externref`.
419
+ const ret = arg0;
420
+ return ret;
421
+ },
422
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
423
+ // Cast intrinsic for `Ref(String) -> Externref`.
424
+ const ret = getStringFromWasm0(arg0, arg1);
425
+ return ret;
426
+ },
427
+ __wbindgen_init_externref_table: function() {
428
+ const table = wasm.__wbindgen_externrefs;
429
+ const offset = table.grow(4);
430
+ table.set(0, undefined);
431
+ table.set(offset + 0, undefined);
432
+ table.set(offset + 1, null);
433
+ table.set(offset + 2, true);
434
+ table.set(offset + 3, false);
435
+ },
436
+ };
437
+ return {
438
+ __proto__: null,
439
+ "./ballistics_engine_bg.js": import0,
440
+ };
441
+ }
442
+
443
+ const CalculatorFinalization = (typeof FinalizationRegistry === 'undefined')
444
+ ? { register: () => {}, unregister: () => {} }
445
+ : new FinalizationRegistry(ptr => wasm.__wbg_calculator_free(ptr, 1));
446
+ const WasmBallisticsFinalization = (typeof FinalizationRegistry === 'undefined')
447
+ ? { register: () => {}, unregister: () => {} }
448
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmballistics_free(ptr, 1));
449
+
450
+ function addToExternrefTable0(obj) {
451
+ const idx = wasm.__externref_table_alloc();
452
+ wasm.__wbindgen_externrefs.set(idx, obj);
453
+ return idx;
454
+ }
455
+
456
+ function getArrayU8FromWasm0(ptr, len) {
457
+ ptr = ptr >>> 0;
458
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
459
+ }
460
+
461
+ function getStringFromWasm0(ptr, len) {
462
+ return decodeText(ptr >>> 0, len);
463
+ }
464
+
465
+ let cachedUint8ArrayMemory0 = null;
466
+ function getUint8ArrayMemory0() {
467
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
468
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
469
+ }
470
+ return cachedUint8ArrayMemory0;
471
+ }
472
+
473
+ function handleError(f, args) {
474
+ try {
475
+ return f.apply(this, args);
476
+ } catch (e) {
477
+ const idx = addToExternrefTable0(e);
478
+ wasm.__wbindgen_exn_store(idx);
479
+ }
480
+ }
481
+
482
+ function isLikeNone(x) {
483
+ return x === undefined || x === null;
484
+ }
485
+
486
+ function passArray8ToWasm0(arg, malloc) {
487
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
488
+ getUint8ArrayMemory0().set(arg, ptr / 1);
489
+ WASM_VECTOR_LEN = arg.length;
490
+ return ptr;
491
+ }
492
+
493
+ function passStringToWasm0(arg, malloc, realloc) {
494
+ if (realloc === undefined) {
495
+ const buf = cachedTextEncoder.encode(arg);
496
+ const ptr = malloc(buf.length, 1) >>> 0;
497
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
498
+ WASM_VECTOR_LEN = buf.length;
499
+ return ptr;
500
+ }
501
+
502
+ let len = arg.length;
503
+ let ptr = malloc(len, 1) >>> 0;
504
+
505
+ const mem = getUint8ArrayMemory0();
506
+
507
+ let offset = 0;
508
+
509
+ for (; offset < len; offset++) {
510
+ const code = arg.charCodeAt(offset);
511
+ if (code > 0x7F) break;
512
+ mem[ptr + offset] = code;
513
+ }
514
+ if (offset !== len) {
515
+ if (offset !== 0) {
516
+ arg = arg.slice(offset);
517
+ }
518
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
519
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
520
+ const ret = cachedTextEncoder.encodeInto(arg, view);
521
+
522
+ offset += ret.written;
523
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
524
+ }
525
+
526
+ WASM_VECTOR_LEN = offset;
527
+ return ptr;
528
+ }
529
+
530
+ function takeFromExternrefTable0(idx) {
531
+ const value = wasm.__wbindgen_externrefs.get(idx);
532
+ wasm.__externref_table_dealloc(idx);
533
+ return value;
534
+ }
535
+
536
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
537
+ cachedTextDecoder.decode();
538
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
539
+ let numBytesDecoded = 0;
540
+ function decodeText(ptr, len) {
541
+ numBytesDecoded += len;
542
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
543
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
544
+ cachedTextDecoder.decode();
545
+ numBytesDecoded = len;
546
+ }
547
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
548
+ }
549
+
550
+ const cachedTextEncoder = new TextEncoder();
551
+
552
+ if (!('encodeInto' in cachedTextEncoder)) {
553
+ cachedTextEncoder.encodeInto = function (arg, view) {
554
+ const buf = cachedTextEncoder.encode(arg);
555
+ view.set(buf);
556
+ return {
557
+ read: arg.length,
558
+ written: buf.length
559
+ };
560
+ };
561
+ }
562
+
563
+ let WASM_VECTOR_LEN = 0;
564
+
565
+ let wasmModule, wasmInstance, wasm;
566
+ function __wbg_finalize_init(instance, module) {
567
+ wasmInstance = instance;
568
+ wasm = instance.exports;
569
+ wasmModule = module;
570
+ cachedUint8ArrayMemory0 = null;
571
+ wasm.__wbindgen_start();
572
+ return wasm;
573
+ }
574
+
575
+ async function __wbg_load(module, imports) {
576
+ if (typeof Response === 'function' && module instanceof Response) {
577
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
578
+ try {
579
+ return await WebAssembly.instantiateStreaming(module, imports);
580
+ } catch (e) {
581
+ const validResponse = module.ok && expectedResponseType(module.type);
582
+
583
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
584
+ 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);
585
+
586
+ } else { throw e; }
587
+ }
588
+ }
589
+
590
+ const bytes = await module.arrayBuffer();
591
+ return await WebAssembly.instantiate(bytes, imports);
592
+ } else {
593
+ const instance = await WebAssembly.instantiate(module, imports);
594
+
595
+ if (instance instanceof WebAssembly.Instance) {
596
+ return { instance, module };
597
+ } else {
598
+ return instance;
599
+ }
600
+ }
601
+
602
+ function expectedResponseType(type) {
603
+ switch (type) {
604
+ case 'basic': case 'cors': case 'default': return true;
605
+ }
606
+ return false;
607
+ }
608
+ }
609
+
610
+ function initSync(module) {
611
+ if (wasm !== undefined) return wasm;
612
+
613
+
614
+ if (module !== undefined) {
615
+ if (Object.getPrototypeOf(module) === Object.prototype) {
616
+ ({module} = module)
617
+ } else {
618
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
619
+ }
620
+ }
621
+
622
+ const imports = __wbg_get_imports();
623
+ if (!(module instanceof WebAssembly.Module)) {
624
+ module = new WebAssembly.Module(module);
625
+ }
626
+ const instance = new WebAssembly.Instance(module, imports);
627
+ return __wbg_finalize_init(instance, module);
628
+ }
629
+
630
+ async function __wbg_init(module_or_path) {
631
+ if (wasm !== undefined) return wasm;
632
+
633
+
634
+ if (module_or_path !== undefined) {
635
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
636
+ ({module_or_path} = module_or_path)
637
+ } else {
638
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
639
+ }
640
+ }
641
+
642
+ if (module_or_path === undefined) {
643
+ module_or_path = new URL('ballistics_engine_bg.wasm', import.meta.url);
644
+ }
645
+ const imports = __wbg_get_imports();
646
+
647
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
648
+ module_or_path = fetch(module_or_path);
649
+ }
650
+
651
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
652
+
653
+ return __wbg_finalize_init(instance, module);
654
+ }
655
+
656
+ export { initSync, __wbg_init as default };
Binary file
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "collaborators": [
5
5
  "Alex Jokela <email@tinycomputers.io>"
6
6
  ],
7
- "description": "High-performance ballistics trajectory engine with professional physics (WASM build)",
8
- "version": "0.25.1",
7
+ "description": "High-performance ballistics trajectory engine with professional physics",
8
+ "version": "0.30.0",
9
9
  "license": "MIT OR Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",
@@ -14,26 +14,18 @@
14
14
  "files": [
15
15
  "ballistics_engine_bg.wasm",
16
16
  "ballistics_engine.js",
17
- "ballistics_engine_bg.js",
18
- "ballistics_engine.d.ts",
19
- "LICENSE-APACHE"
17
+ "ballistics_engine.d.ts"
20
18
  ],
21
19
  "main": "ballistics_engine.js",
22
20
  "homepage": "https://ballistics.rs/",
23
21
  "types": "ballistics_engine.d.ts",
24
22
  "sideEffects": [
25
- "./ballistics_engine.js",
26
23
  "./snippets/*"
27
24
  ],
28
25
  "keywords": [
29
26
  "ballistics",
30
27
  "trajectory",
31
28
  "physics",
32
- "simulation",
33
- "wasm",
34
- "webassembly"
35
- ],
36
- "publishConfig": {
37
- "access": "public"
38
- }
39
- }
29
+ "simulation"
30
+ ]
31
+ }