@danielsimonjr/mathts-core 0.19.0 → 0.21.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 (40) hide show
  1. package/README.md +30 -5
  2. package/dist/collection.d.ts +35 -23
  3. package/dist/collection.d.ts.map +1 -1
  4. package/dist/index.d.ts +4 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +121 -17
  7. package/dist/internal.d.ts +3 -2
  8. package/dist/internal.d.ts.map +1 -1
  9. package/dist/internal.js +161 -2
  10. package/dist/numeric/rng.d.ts +88 -0
  11. package/dist/numeric/rng.d.ts.map +1 -0
  12. package/dist/numeric/strides.d.ts +18 -0
  13. package/dist/numeric/strides.d.ts.map +1 -0
  14. package/dist/object.d.ts +20 -2
  15. package/dist/object.d.ts.map +1 -1
  16. package/dist/shared.d.ts +19 -0
  17. package/dist/shared.d.ts.map +1 -1
  18. package/dist/switch.d.ts +2 -4
  19. package/dist/switch.d.ts.map +1 -1
  20. package/dist/types/bignumber.d.ts +7 -0
  21. package/dist/types/bignumber.d.ts.map +1 -1
  22. package/dist/types/complex.d.ts +20 -18
  23. package/dist/types/complex.d.ts.map +1 -1
  24. package/dist/types/fraction.d.ts +5 -0
  25. package/dist/types/fraction.d.ts.map +1 -1
  26. package/dist/types/si-dimension-vector.d.ts +62 -7
  27. package/dist/types/si-dimension-vector.d.ts.map +1 -1
  28. package/dist/types/unit/Unit.d.ts.map +1 -1
  29. package/dist/types/unit/index.d.ts +2 -2
  30. package/dist/types/unit/index.d.ts.map +1 -1
  31. package/dist/types/unit/unit-table.d.ts +12 -0
  32. package/dist/types/unit/unit-table.d.ts.map +1 -1
  33. package/dist/types/unit.d.ts +2 -2
  34. package/dist/types/unit.d.ts.map +1 -1
  35. package/dist/{unit-l_r8z5Fv.js → unit-D3yD3jbu.js} +106 -65
  36. package/dist/wasm-as-header.d.ts +17 -0
  37. package/dist/wasm-as-header.d.ts.map +1 -0
  38. package/dist/wasm-loader.d.ts +33 -1
  39. package/dist/wasm-loader.d.ts.map +1 -1
  40. package/package.json +2 -1
@@ -1,4 +1,23 @@
1
1
  //#region src/types/complex.ts
2
+ const HYPERBOLIC_OVERFLOW_ARG = 700;
3
+ function createTanFamilyMethod(name, sign, hyperbolic) {
4
+ const method = function() {
5
+ const t = (hyperbolic ? this.im : this.re) * 2;
6
+ const h = (hyperbolic ? this.re : this.im) * 2;
7
+ let s;
8
+ let q;
9
+ if (Math.abs(h) > HYPERBOLIC_OVERFLOW_ARG) {
10
+ s = 2 * Math.sin(t) * Math.exp(-Math.abs(h));
11
+ q = Math.sign(h);
12
+ } else {
13
+ const d = Math.cosh(h) + sign * Math.cos(t);
14
+ s = Math.sin(t) / d;
15
+ q = Math.sinh(h) / d;
16
+ }
17
+ return hyperbolic ? new Complex(q, s * sign) : new Complex(s, q * sign);
18
+ };
19
+ return Object.defineProperty(method, "name", { value: name });
20
+ }
2
21
  function isComplex$1(value) {
3
22
  return value instanceof Complex;
4
23
  }
@@ -18,6 +37,35 @@ var Complex = class Complex {
18
37
  this.re = re;
19
38
  this.im = im;
20
39
  }
40
+ static {
41
+ for (const [name, sign, hyperbolic] of [
42
+ [
43
+ "tan",
44
+ 1,
45
+ false
46
+ ],
47
+ [
48
+ "cot",
49
+ -1,
50
+ false
51
+ ],
52
+ [
53
+ "tanh",
54
+ 1,
55
+ true
56
+ ],
57
+ [
58
+ "coth",
59
+ -1,
60
+ true
61
+ ]
62
+ ]) Object.defineProperty(Complex.prototype, name, {
63
+ value: createTanFamilyMethod(name, sign, hyperbolic),
64
+ writable: true,
65
+ configurable: true,
66
+ enumerable: false
67
+ });
68
+ }
21
69
  static fromPolar(r, theta) {
22
70
  const cosT = Math.cos(theta);
23
71
  const sinT = Math.sin(theta);
@@ -231,18 +279,6 @@ var Complex = class Complex {
231
279
  cos() {
232
280
  return new Complex(Math.cos(this.re) * Math.cosh(this.im), -Math.sin(this.re) * Math.sinh(this.im));
233
281
  }
234
- tan() {
235
- const x2 = this.re * 2;
236
- const y2 = this.im * 2;
237
- const d = Math.cos(x2) + Math.cosh(y2);
238
- return new Complex(Math.sin(x2) / d, Math.sinh(y2) / d);
239
- }
240
- cot() {
241
- const x2 = this.re * 2;
242
- const y2 = this.im * 2;
243
- const d = Math.cosh(y2) - Math.cos(x2);
244
- return new Complex(Math.sin(x2) / d, -Math.sinh(y2) / d);
245
- }
246
282
  sec() {
247
283
  return this.cos().inverse();
248
284
  }
@@ -255,18 +291,6 @@ var Complex = class Complex {
255
291
  cosh() {
256
292
  return new Complex(Math.cosh(this.re) * Math.cos(this.im), Math.sinh(this.re) * Math.sin(this.im));
257
293
  }
258
- tanh() {
259
- const x2 = this.re * 2;
260
- const y2 = this.im * 2;
261
- const d = Math.cosh(x2) + Math.cos(y2);
262
- return new Complex(Math.sinh(x2) / d, Math.sin(y2) / d);
263
- }
264
- coth() {
265
- const x2 = this.re * 2;
266
- const y2 = this.im * 2;
267
- const d = Math.cosh(x2) - Math.cos(y2);
268
- return new Complex(Math.sinh(x2) / d, -Math.sin(y2) / d);
269
- }
270
294
  sech() {
271
295
  return this.cosh().inverse();
272
296
  }
@@ -720,6 +744,12 @@ function _toNumberOrDefault(value, defaultValue) {
720
744
  function hasOwnProperty(object, property) {
721
745
  return !!object && Object.hasOwnProperty.call(object, property);
722
746
  }
747
+ function isPollutingKey(prop) {
748
+ return prop in Object.prototype || prop in Function.prototype;
749
+ }
750
+ function isPrototypeKey(prop) {
751
+ return prop === "__proto__";
752
+ }
723
753
  function endsWith(text, search) {
724
754
  const start = text.length - search.length;
725
755
  return text.substring(start, text.length) === search;
@@ -770,12 +800,12 @@ function clone(x) {
770
800
  }
771
801
  function mapObject(object, callback) {
772
802
  const clone = {};
773
- for (const key in object) if (hasOwnProperty(object, key)) clone[key] = callback(object[key]);
803
+ for (const key in object) if (hasOwnProperty(object, key) && !isPrototypeKey(key)) clone[key] = callback(object[key]);
774
804
  return clone;
775
805
  }
776
806
  function extend(a, b) {
777
807
  const target = a;
778
- for (const prop in b) if (hasOwnProperty(b, prop)) target[prop] = b[prop];
808
+ for (const prop in b) if (hasOwnProperty(b, prop) && !isPrototypeKey(prop)) target[prop] = b[prop];
779
809
  return a;
780
810
  }
781
811
  function deepExtend(a, b) {
@@ -795,7 +825,7 @@ function deepExtend(a, b) {
795
825
  }
796
826
  return a;
797
827
  }
798
- for (const prop in b) if (hasOwnProperty(b, prop) && !(prop in Object.prototype) && !(prop in Function.prototype)) {
828
+ for (const prop in b) if (hasOwnProperty(b, prop) && !isPollutingKey(prop)) {
799
829
  const bValue = b[prop];
800
830
  const aValue = a[prop];
801
831
  if (bValue && bValue.constructor === Object) {
@@ -835,7 +865,7 @@ function deepFlatten(nestedObject) {
835
865
  return flattenedObject;
836
866
  }
837
867
  function _deepFlatten(nestedObject, flattenedObject) {
838
- for (const prop in nestedObject) if (hasOwnProperty(nestedObject, prop)) {
868
+ for (const prop in nestedObject) if (hasOwnProperty(nestedObject, prop) && !isPrototypeKey(prop)) {
839
869
  const value = nestedObject[prop];
840
870
  if (typeof value === "object" && value !== null) _deepFlatten(value, flattenedObject);
841
871
  else flattenedObject[prop] = value;
@@ -1217,23 +1247,20 @@ var Fraction = class Fraction {
1217
1247
  denominator: this.denominator
1218
1248
  };
1219
1249
  }
1220
- add(other) {
1250
+ addSub(other, combine) {
1221
1251
  if (other instanceof Fraction) {
1222
- if (this.denominator === other.denominator) return new Fraction(this.numerator + other.numerator, this.denominator);
1223
- const num = this.numerator * other.denominator + other.numerator * this.denominator;
1252
+ if (this.denominator === other.denominator) return new Fraction(combine(this.numerator, other.numerator), this.denominator);
1253
+ const num = combine(this.numerator * other.denominator, other.numerator * this.denominator);
1224
1254
  const den = this.denominator * other.denominator;
1225
1255
  return new Fraction(num, den);
1226
1256
  }
1227
- return this.add(Fraction.fromNumber(Number(other.valueOf())));
1257
+ return this.addSub(Fraction.fromNumber(Number(other.valueOf())), combine);
1258
+ }
1259
+ add(other) {
1260
+ return this.addSub(other, (a, b) => a + b);
1228
1261
  }
1229
1262
  subtract(other) {
1230
- if (other instanceof Fraction) {
1231
- if (this.denominator === other.denominator) return new Fraction(this.numerator - other.numerator, this.denominator);
1232
- const num = this.numerator * other.denominator - other.numerator * this.denominator;
1233
- const den = this.denominator * other.denominator;
1234
- return new Fraction(num, den);
1235
- }
1236
- return this.subtract(Fraction.fromNumber(Number(other.valueOf())));
1263
+ return this.addSub(other, (a, b) => a - b);
1237
1264
  }
1238
1265
  multiply(other) {
1239
1266
  if (other instanceof Fraction) return new Fraction(this.numerator * other.numerator, this.denominator * other.denominator);
@@ -1323,15 +1350,20 @@ var Fraction = class Fraction {
1323
1350
  return this.numerator === 1n || this.numerator === -1n;
1324
1351
  }
1325
1352
  floor() {
1326
- if (this.denominator === 1n) return this;
1327
- const quot = this.numerator / this.denominator;
1328
- if (this.numerator >= 0n || this.numerator % this.denominator === 0n) return new Fraction(quot, 1n);
1329
- return new Fraction(quot - 1n, 1n);
1353
+ return this.truncBound("floor");
1330
1354
  }
1331
1355
  ceil() {
1356
+ return this.truncBound("ceil");
1357
+ }
1358
+ truncBound(toward) {
1332
1359
  if (this.denominator === 1n) return this;
1333
1360
  const quot = this.numerator / this.denominator;
1334
- if (this.numerator <= 0n || this.numerator % this.denominator === 0n) return new Fraction(quot, 1n);
1361
+ const exact = this.numerator % this.denominator === 0n;
1362
+ if (toward === "floor") {
1363
+ if (this.numerator >= 0n || exact) return new Fraction(quot, 1n);
1364
+ return new Fraction(quot - 1n, 1n);
1365
+ }
1366
+ if (this.numerator <= 0n || exact) return new Fraction(quot, 1n);
1335
1367
  return new Fraction(quot + 1n, 1n);
1336
1368
  }
1337
1369
  round() {
@@ -2074,33 +2106,25 @@ var BigNumber = class BigNumber {
2074
2106
  else if (reduced.compareTo(BIGNUMBER_PI.negate()) < 0) reduced = reduced.add(twoPi);
2075
2107
  return reduced;
2076
2108
  }
2077
- _sinTaylor() {
2109
+ _alternatingEvenTaylor(initialTerm, initialSum, denom) {
2078
2110
  const precision = globalConfig.precision;
2079
- let term = this.clone();
2080
- let sum = this.clone();
2111
+ let term = initialTerm;
2112
+ let sum = initialSum;
2081
2113
  const xSquared = this.multiply(this);
2082
2114
  const maxIter = precision + 20;
2083
2115
  for (let n = 1; n <= maxIter; n++) {
2084
- term = term.multiply(xSquared).divide(BigNumber.fromNumber(2 * n * (2 * n + 1))).negate();
2116
+ term = term.multiply(xSquared).divide(BigNumber.fromNumber(denom(n))).negate();
2085
2117
  const newSum = sum.add(term);
2086
2118
  if (sum.equals(newSum)) break;
2087
2119
  sum = newSum;
2088
2120
  }
2089
2121
  return sum.roundToPrecision(precision);
2090
2122
  }
2123
+ _sinTaylor() {
2124
+ return this._alternatingEvenTaylor(this.clone(), this.clone(), (n) => 2 * n * (2 * n + 1));
2125
+ }
2091
2126
  _cosTaylor() {
2092
- const precision = globalConfig.precision;
2093
- let term = BigNumber.fromNumber(1);
2094
- let sum = BigNumber.fromNumber(1);
2095
- const xSquared = this.multiply(this);
2096
- const maxIter = precision + 20;
2097
- for (let n = 1; n <= maxIter; n++) {
2098
- term = term.multiply(xSquared).divide(BigNumber.fromNumber((2 * n - 1) * (2 * n))).negate();
2099
- const newSum = sum.add(term);
2100
- if (sum.equals(newSum)) break;
2101
- sum = newSum;
2102
- }
2103
- return sum.roundToPrecision(precision);
2127
+ return this._alternatingEvenTaylor(BigNumber.fromNumber(1), BigNumber.fromNumber(1), (n) => (2 * n - 1) * (2 * n));
2104
2128
  }
2105
2129
  _atanTaylor() {
2106
2130
  const precision = globalConfig.precision;
@@ -3633,7 +3657,7 @@ const UNIT_ROWS = Object.freeze({
3633
3657
  },
3634
3658
  psi: {
3635
3659
  base: "PRESSURE",
3636
- prefixes: "NONE",
3660
+ prefixes: "SHORT",
3637
3661
  scale: "lbf/inch^2"
3638
3662
  },
3639
3663
  atm: {
@@ -3648,7 +3672,7 @@ const UNIT_ROWS = Object.freeze({
3648
3672
  },
3649
3673
  torr: {
3650
3674
  base: "PRESSURE",
3651
- prefixes: "NONE",
3675
+ prefixes: "SHORT",
3652
3676
  scale: "standard_atmosphere/760"
3653
3677
  },
3654
3678
  mmHg: {
@@ -3949,6 +3973,7 @@ const UNIT_ROW_ALIASES = Object.freeze({
3949
3973
  rods: "rod",
3950
3974
  chains: "chain",
3951
3975
  angstroms: "angstrom",
3976
+ Angstrom: "angstrom",
3952
3977
  lt: "l",
3953
3978
  litres: "litre",
3954
3979
  liter: "litre",
@@ -4038,6 +4063,7 @@ const UNIT_ROW_ALIASES = Object.freeze({
4038
4063
  bit: "bits",
4039
4064
  byte: "bytes",
4040
4065
  calories: "calorie",
4066
+ d: "day",
4041
4067
  G: "gauss",
4042
4068
  Gauss: "gauss",
4043
4069
  poise: "P",
@@ -4052,6 +4078,14 @@ const UNIT_ROW_ALIASES = Object.freeze({
4052
4078
  Ohm: "ohm",
4053
4079
  Å: "angstrom"
4054
4080
  });
4081
+ const REFUSED_UNIT_SPELLINGS = Object.freeze({
4082
+ dB: "dB is a logarithmic unit; give the quantity in its linear unit, or a reference level",
4083
+ dBm: "dBm is a logarithmic unit (decibels over 1 mW); give watts",
4084
+ dBW: "dBW is a logarithmic unit (decibels over 1 W); give watts",
4085
+ Np: "Np is a logarithmic unit (the neper); give the quantity in its linear unit, or a reference level",
4086
+ Mach: "Mach is a ratio to the local speed of sound; give m/s, or the ratio as a bare number",
4087
+ mach: "mach is a ratio to the local speed of sound; give m/s, or the ratio as a bare number"
4088
+ });
4055
4089
  const namedCache = /* @__PURE__ */ new Map();
4056
4090
  function namedExactScale(name) {
4057
4091
  const cached = namedCache.get(name);
@@ -4402,7 +4436,11 @@ const createUnitClass = /* #__PURE__ */ factory("Unit", [
4402
4436
  if (uStr === null) throw new UnitParseError("Unexpected \"" + oldC + "\" in \"" + text + "\" at index " + index.toString());
4403
4437
  } else break;
4404
4438
  const res = _findUnit(uStr);
4405
- if (res === null) throw new UnitParseError("Unit \"" + uStr + "\" not found.");
4439
+ if (res === null) {
4440
+ const refused = Object.hasOwn(REFUSED_UNIT_SPELLINGS, uStr) ? REFUSED_UNIT_SPELLINGS[uStr] : void 0;
4441
+ if (refused !== void 0) throw new UnitParseError("Unit \"" + uStr + "\" is refused: " + refused);
4442
+ throw new UnitParseError("Unit \"" + uStr + "\" not found.");
4443
+ }
4406
4444
  let power = powerMultiplierCurrent * powerMultiplierStackProduct;
4407
4445
  skipWhitespace();
4408
4446
  if (parseCharacter("^")) {
@@ -5728,7 +5766,10 @@ const createUnitClass = /* #__PURE__ */ factory("Unit", [
5728
5766
  if (aliases) for (let i = 0; i < aliases.length; i++) Unit.deleteUnit(aliases[i]);
5729
5767
  }
5730
5768
  let lastUnit;
5731
- for (const key in obj) if (hasOwnProperty(obj, key)) lastUnit = Unit.createUnitSingle(key, obj[key]);
5769
+ for (const key in obj) if (hasOwnProperty(obj, key)) {
5770
+ if (isPollutingKey(key)) throw new TypeError(`unsafe unit name '${key}'`);
5771
+ lastUnit = Unit.createUnitSingle(key, obj[key]);
5772
+ }
5732
5773
  return lastUnit;
5733
5774
  };
5734
5775
  Unit.createUnitSingle = function(name, obj) {
@@ -5914,4 +5955,4 @@ const unitDependencies = {
5914
5955
  //#region src/types/unit/index.ts
5915
5956
  const Unit = createUnitClass(unitDependencies);
5916
5957
  //#endregion
5917
- export { BIGNUMBER_LN2 as $, log1p as $t, irrationalPower as A, isRegExp as An, isLegacyFactory as At, addScalar as B, I as Bn, warnOnce as Bt, decimalExactScale as C, isIndex as Cn, canDefineProperty as Ct, exactScaleToNumber as D, isNumber as Dn, deepStrictEqual as Dt, exactScaleOf as E, isNull as En, deepFlatten as Et, ratioExactScale as F, typeOf as Fn, set as Ft, multiplyScalar as G, copysign as Gt, equal as H, asinh as Ht, readScaleExpression as I, COMPLEX_NEG_ONE as In, traverse as It, round as J, expm1 as Jt, number as K, cosh as Kt, DimensionMismatchError as L, COMPLEX_ONE as Ln, endsWith as Lt, multiplyExactScales as M, isString as Mn, mapObject as Mt, namedIrrationalScale as N, isUndefined as Nn, pick as Nt, exactScalesEqual as O, isObject as On, extend as Ot, powerExactScale as P, isUnit as Pn, pickShallow as Pt, BIGNUMBER_LN10 as Q, log10 as Qt, UnitParseError as R, COMPLEX_ZERO as Rn, hasOwnProperty as Rt, clearExactScaleNumberCache as S, isFunction as Sn, MathjsError as St, exactScaleNumberCacheSize as T, isMatrix as Tn, deepExtend as Tt, fix as U, atanh as Ut, divideScalar as V, isComplex$1 as Vn, acosh as Vt, isNumeric as W, cbrt as Wt, DEFAULT_CONFIG as X, isInteger as Xt, subtractScalar$1 as Y, format as Yt, BIGNUMBER_E as Z, isPowZeroAtInfinity as Zt, NAMED_IRRATIONALS as _, isCollection as _n, factory as _t, UNIT_PREFIX_SETS as a, sign as an, BigNumber as at, addExactScales as b, isDenseMatrix as bn, sortFactories as bt, getUnitPrefix as c, tanh as cn, FRACTION_NEG_ONE as ct, readUnitScale as d, toFixed as dn, FRACTION_THIRD as dt, log2 as en, BIGNUMBER_NEG_ONE as et, unitPrefixExactScale as f, toPrecision as fn, FRACTION_ZERO as ft, LN2_EXACT_SCALE as g, isBoolean as gn, create as gt, unitRowValue as h, isBigNumber$1 as hn, assertDependencies as ht, NAMED_SCALES as i, safeNumberType as in, BIGNUMBER_ZERO as it, isRationalScale as j, isSparseMatrix as jn, lazy as jt, formatExactScale as k, isRange as kn, get as kt, getUnitRow as l, toEngineering as ln, FRACTION_ONE as lt, unitRowExactScale as m, isBigInt as mn, isFraction as mt, unitDependencies as n, normalizeFormatOptions as nn, BIGNUMBER_PI as nt, UNIT_ROWS as o, sinh as on, isBigNumber as ot, unitRowExactOffset as p, isArray as pn, Fraction as pt, pow as q, digits as qt, createUnitClass as r, roundDigits as rn, BIGNUMBER_TEN as rt, UNIT_ROW_ALIASES as s, splitNumber as sn, FRACTION_HALF as st, Unit as t, nearlyEqual as tn, BIGNUMBER_ONE as tt, namedExactScale as u, toExponential as un, FRACTION_QUARTER as ut, PI_EXACT_SCALE as v, isComplex as vn, isFactory as vt, divideExactScales as w, isMap as wn, clone as wt, binaryExactScale as x, isFraction$1 as xn, stripOptionalNotation as xt, UNIT_EXACT_SCALE as y, isDate as yn, isOptionalDependency as yt, abs as z, Complex as zn, memoize as zt };
5958
+ export { BIGNUMBER_LN10 as $, log10 as $t, formatExactScale as A, isRange as An, get as At, abs as B, Complex as Bn, memoize as Bt, clearExactScaleNumberCache as C, isFunction as Cn, MathjsError as Ct, exactScaleOf as D, isNull as Dn, deepFlatten as Dt, exactScaleNumberCacheSize as E, isMatrix as En, deepExtend as Et, powerExactScale as F, isUnit as Fn, pickShallow as Ft, isNumeric as G, cbrt as Gt, divideScalar as H, isComplex$1 as Hn, acosh as Ht, ratioExactScale as I, typeOf as In, set as It, pow as J, digits as Jt, multiplyScalar as K, copysign as Kt, readScaleExpression as L, COMPLEX_NEG_ONE as Ln, traverse as Lt, isRationalScale as M, isSparseMatrix as Mn, lazy as Mt, multiplyExactScales as N, isString as Nn, mapObject as Nt, exactScaleToNumber as O, isNumber as On, deepStrictEqual as Ot, namedIrrationalScale as P, isUndefined as Pn, pick as Pt, BIGNUMBER_E as Q, isPowZeroAtInfinity as Qt, DimensionMismatchError as R, COMPLEX_ONE as Rn, endsWith as Rt, binaryExactScale as S, isFraction$1 as Sn, stripOptionalNotation as St, divideExactScales as T, isMap as Tn, clone as Tt, equal as U, asinh as Ut, addScalar as V, I as Vn, warnOnce as Vt, fix as W, atanh as Wt, subtractScalar$1 as X, format as Xt, round as Y, expm1 as Yt, DEFAULT_CONFIG as Z, isInteger as Zt, LN2_EXACT_SCALE as _, isBoolean as _n, create as _t, REFUSED_UNIT_SPELLINGS as a, safeNumberType as an, BIGNUMBER_ZERO as at, UNIT_EXACT_SCALE as b, isDate as bn, isOptionalDependency as bt, UNIT_ROW_ALIASES as c, splitNumber as cn, FRACTION_HALF as ct, namedExactScale as d, toExponential as dn, FRACTION_QUARTER as dt, log1p as en, BIGNUMBER_LN2 as et, readUnitScale as f, toFixed as fn, FRACTION_THIRD as ft, unitRowValue as g, isBigNumber$1 as gn, assertDependencies as gt, unitRowExactScale as h, isBigInt as hn, isFraction as ht, NAMED_SCALES as i, roundDigits as in, BIGNUMBER_TEN as it, irrationalPower as j, isRegExp as jn, isLegacyFactory as jt, exactScalesEqual as k, isObject as kn, extend as kt, getUnitPrefix as l, tanh as ln, FRACTION_NEG_ONE as lt, unitRowExactOffset as m, isArray as mn, Fraction as mt, unitDependencies as n, nearlyEqual as nn, BIGNUMBER_ONE as nt, UNIT_PREFIX_SETS as o, sign as on, BigNumber as ot, unitPrefixExactScale as p, toPrecision as pn, FRACTION_ZERO as pt, number as q, cosh as qt, createUnitClass as r, normalizeFormatOptions as rn, BIGNUMBER_PI as rt, UNIT_ROWS as s, sinh as sn, isBigNumber as st, Unit as t, log2 as tn, BIGNUMBER_NEG_ONE as tt, getUnitRow as u, toEngineering as un, FRACTION_ONE as ut, NAMED_IRRATIONALS as v, isCollection as vn, factory as vt, decimalExactScale as w, isIndex as wn, canDefineProperty as wt, addExactScales as x, isDenseMatrix as xn, sortFactories as xt, PI_EXACT_SCALE as y, isComplex as yn, isFactory as yt, UnitParseError as z, COMPLEX_ZERO as zn, hasOwnProperty as zt };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * AssemblyScript managed ArrayBuffer + typed-array header allocation.
3
+ *
4
+ * Shared by `functions` WASM bridges and `matrix` AS backend allocation.
5
+ * Exported only from `@danielsimonjr/mathts-core/internal`.
6
+ */
7
+ export interface AsHeaderRuntime {
8
+ __new(size: number, id: number): number;
9
+ __pin(ptr: number): number;
10
+ memory: WebAssembly.Memory;
11
+ }
12
+ /** Pin a data buffer and write the 12-byte AS typed-array header. */
13
+ export declare function allocAsHeader(mod: AsHeaderRuntime, byteLength: number, typeId: number): {
14
+ headerPtr: number;
15
+ bufferPtr: number;
16
+ };
17
+ //# sourceMappingURL=wasm-as-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-as-header.d.ts","sourceRoot":"","sources":["../src/wasm-as-header.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;CAC5B;AAED,qEAAqE;AACrE,wBAAgB,aAAa,CAC3B,GAAG,EAAE,eAAe,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAS1C"}
@@ -39,7 +39,7 @@
39
39
  *
40
40
  * @module @danielsimonjr/mathts-core/internal (wasm-loader)
41
41
  */
42
- import type { WasmManifest } from './types/wasm-loader.js';
42
+ import type { LoadingMetrics, WasmManifest } from './types/wasm-loader.js';
43
43
  export type { WasmManifest };
44
44
  /**
45
45
  * Compute the SHA-384 digest of a buffer and return base64 encoding,
@@ -94,4 +94,36 @@ export declare function resolvePackagedWasm(metaUrl: string, wasmFile: string):
94
94
  export declare function defaultWasmLocation(metaUrl: string, wasmFile: string, opts?: {
95
95
  browser?: boolean;
96
96
  }): Promise<string>;
97
+ /**
98
+ * Shared load / instantiate orchestration for the two package-local
99
+ * `WasmLoader` singletons (`functions` and `matrix`). Subclasses keep their own
100
+ * `WasmModule` ABI type and path resolution; the Node and browser load arms
101
+ * (`precompile`, `loadNodeWasm`, `loadBrowserWasm`) live here and call
102
+ * {@link verifyWasmIntegrity} before every compile/instantiate (G45–G47, P6-10).
103
+ */
104
+ export declare abstract class WasmModuleLoader<TModule> {
105
+ protected wasmModule: TModule | null;
106
+ protected compiledModule: WebAssembly.Module | null;
107
+ protected loading: Promise<TModule> | null;
108
+ protected isNode: boolean;
109
+ protected lastMetrics: LoadingMetrics | null;
110
+ protected constructor();
111
+ /**
112
+ * Load the WASM module (cached; concurrent callers share one in-flight promise).
113
+ */
114
+ load(wasmPath?: string): Promise<TModule>;
115
+ private loadModule;
116
+ protected abstract getDefaultWasmPath(): Promise<string>;
117
+ /**
118
+ * Precompile the WASM module without instantiation.
119
+ * Useful for build-time or startup optimization.
120
+ *
121
+ * Same integrity rule as `load()`: the bytes are hashed against the manifest before
122
+ * `WebAssembly.compile`. The browser arm streams only when no manifest exists.
123
+ */
124
+ precompile(wasmPath?: string): Promise<void>;
125
+ protected loadNodeWasm(path: string, totalStart: number): Promise<TModule>;
126
+ protected loadBrowserWasm(path: string, totalStart: number): Promise<TModule>;
127
+ protected getImports(): WebAssembly.Imports;
128
+ }
97
129
  //# sourceMappingURL=wasm-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wasm-loader.d.ts","sourceRoot":"","sources":["../src/wasm-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,CAAC;AAI7B;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBtF;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAmBrF;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,WAAW,GAAG,UAAU,EAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GACnE,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3B,OAAO,CAAC,MAAM,CAAC,CAmBjB"}
1
+ {"version":3,"file":"wasm-loader.d.ts","sourceRoot":"","sources":["../src/wasm-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3E,YAAY,EAAE,YAAY,EAAE,CAAC;AAI7B;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBtF;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAmBrF;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,WAAW,GAAG,UAAU,EAChC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,GACnE,OAAO,CAAC,IAAI,CAAC,CAmCf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3B,OAAO,CAAC,MAAM,CAAC,CAmBjB;AAED;;;;;;GAMG;AACH,8BAAsB,gBAAgB,CAAC,OAAO;IAC5C,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAQ;IAC5C,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAQ;IAC3D,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAQ;IAClD,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,WAAW,EAAE,cAAc,GAAG,IAAI,CAAQ;IAEpD,SAAS,eAER;IAED;;OAEG;IACU,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBrD;YAEa,UAAU;IAwBxB,SAAS,CAAC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzD;;;;;;OAMG;IACU,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkCxD;IAED,UAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA8B/E;IAED,UAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA+ClF;IAED,SAAS,CAAC,UAAU,IAAI,WAAW,CAAC,OAAO,CAY1C;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-core",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Core types, utilities, and configuration for MathTS",
5
5
  "author": "Daniel Simon Jr.",
6
6
  "license": "MIT",
@@ -39,6 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^26.4.0",
42
+ "fast-check": "^4.9.0",
42
43
  "tsdown": "^0.23.0",
43
44
  "typescript": "^7.0.2",
44
45
  "vitest": "^5.0.0"