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