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