@cortex-js/compute-engine 0.32.0 → 0.32.1

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 (153) hide show
  1. package/dist/compute-engine.esm.js +42905 -0
  2. package/dist/compute-engine.min.esm.js +125 -0
  3. package/dist/compute-engine.min.umd.js +127 -0
  4. package/dist/compute-engine.umd.js +42930 -0
  5. package/dist/math-json.esm.js +130 -0
  6. package/dist/math-json.min.esm.js +130 -0
  7. package/dist/math-json.min.umd.js +4 -0
  8. package/dist/math-json.umd.js +155 -0
  9. package/dist/types/common/ansi-codes.d.ts +41 -0
  10. package/dist/types/common/configuration-change.d.ts +28 -0
  11. package/dist/types/common/fuzzy-string-match.d.ts +2 -0
  12. package/dist/types/common/grapheme-splitter.d.ts +15 -0
  13. package/dist/types/common/interruptible.d.ts +20 -0
  14. package/dist/types/common/one-of.d.ts +10 -0
  15. package/dist/types/common/signals.d.ts +96 -0
  16. package/dist/types/common/type/ast-nodes.d.ts +146 -0
  17. package/dist/types/common/type/boxed-type.d.ts +30 -0
  18. package/dist/types/common/type/lexer.d.ts +51 -0
  19. package/dist/types/common/type/parse.d.ts +211 -0
  20. package/dist/types/common/type/parser.d.ts +45 -0
  21. package/dist/types/common/type/primitive.d.ts +10 -0
  22. package/dist/types/common/type/serialize.d.ts +2 -0
  23. package/dist/types/common/type/subtype.d.ts +6 -0
  24. package/dist/types/common/type/type-builder.d.ts +32 -0
  25. package/dist/types/common/type/types.d.ts +300 -0
  26. package/dist/types/common/type/utils.d.ts +36 -0
  27. package/dist/types/common/utils.d.ts +23 -0
  28. package/dist/types/compute-engine/assume.d.ts +26 -0
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +165 -0
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +16 -0
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +27 -0
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +38 -0
  34. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  35. package/dist/types/compute-engine/boxed-expression/box.d.ts +47 -0
  36. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +44 -0
  37. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +136 -0
  38. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +103 -0
  39. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +53 -0
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +107 -0
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +27 -0
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +170 -0
  43. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +83 -0
  44. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +7 -0
  46. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
  47. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -0
  48. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  49. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  50. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  51. package/dist/types/compute-engine/boxed-expression/factor.d.ts +10 -0
  52. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  53. package/dist/types/compute-engine/boxed-expression/hold.d.ts +10 -0
  54. package/dist/types/compute-engine/boxed-expression/match.d.ts +41 -0
  55. package/dist/types/compute-engine/boxed-expression/negate.d.ts +11 -0
  56. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +34 -0
  57. package/dist/types/compute-engine/boxed-expression/order.d.ts +71 -0
  58. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +105 -0
  59. package/dist/types/compute-engine/boxed-expression/product.d.ts +66 -0
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -0
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +46 -0
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +20 -0
  65. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  66. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +9 -0
  67. package/dist/types/compute-engine/boxed-expression/utils.d.ts +64 -0
  68. package/dist/types/compute-engine/boxed-expression/validate.d.ts +58 -0
  69. package/dist/types/compute-engine/collection-utils.d.ts +35 -0
  70. package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
  71. package/dist/types/compute-engine/compilation/javascript-target.d.ts +68 -0
  72. package/dist/types/compute-engine/compilation/types.d.ts +83 -0
  73. package/dist/types/compute-engine/cost-function.d.ts +13 -0
  74. package/dist/types/compute-engine/function-utils.d.ts +120 -0
  75. package/dist/types/compute-engine/global-types.d.ts +2930 -0
  76. package/dist/types/compute-engine/index.d.ts +660 -0
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +2 -0
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +27 -0
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +2 -0
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +2 -0
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
  88. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +3 -0
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  90. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +88 -0
  91. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  92. package/dist/types/compute-engine/latex-syntax/parse.d.ts +316 -0
  93. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +29 -0
  94. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +10 -0
  95. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +37 -0
  96. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +18 -0
  97. package/dist/types/compute-engine/latex-syntax/types.d.ts +896 -0
  98. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  99. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -0
  100. package/dist/types/compute-engine/library/calculus.d.ts +2 -0
  101. package/dist/types/compute-engine/library/collections.d.ts +27 -0
  102. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  103. package/dist/types/compute-engine/library/complex.d.ts +2 -0
  104. package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
  105. package/dist/types/compute-engine/library/core.d.ts +2 -0
  106. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  107. package/dist/types/compute-engine/library/library.d.ts +17 -0
  108. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
  109. package/dist/types/compute-engine/library/logic-analysis.d.ts +64 -0
  110. package/dist/types/compute-engine/library/logic-utils.d.ts +58 -0
  111. package/dist/types/compute-engine/library/logic.d.ts +7 -0
  112. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  113. package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
  114. package/dist/types/compute-engine/library/random-expression.d.ts +2 -0
  115. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
  116. package/dist/types/compute-engine/library/sets.d.ts +2 -0
  117. package/dist/types/compute-engine/library/statistics.d.ts +2 -0
  118. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
  119. package/dist/types/compute-engine/library/utils.d.ts +77 -0
  120. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +57 -0
  121. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +75 -0
  122. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +56 -0
  123. package/dist/types/compute-engine/numeric-value/types.d.ts +116 -0
  124. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  125. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  126. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  127. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -0
  128. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +18 -0
  129. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +9 -0
  130. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  131. package/dist/types/compute-engine/numerics/numeric.d.ts +60 -0
  132. package/dist/types/compute-engine/numerics/primes.d.ts +7 -0
  133. package/dist/types/compute-engine/numerics/rationals.d.ts +43 -0
  134. package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
  135. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  136. package/dist/types/compute-engine/numerics/statistics.d.ts +24 -0
  137. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  138. package/dist/types/compute-engine/numerics/types.d.ts +30 -0
  139. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  140. package/dist/types/compute-engine/symbolic/derivative.d.ts +18 -0
  141. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  142. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +6 -0
  143. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +27 -0
  144. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +6 -0
  145. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +128 -0
  146. package/dist/types/compute-engine/tensor/tensors.d.ts +93 -0
  147. package/dist/types/compute-engine/types.d.ts +8 -0
  148. package/dist/types/compute-engine.d.ts +3 -0
  149. package/dist/types/math-json/symbols.d.ts +11 -0
  150. package/dist/types/math-json/types.d.ts +122 -0
  151. package/dist/types/math-json/utils.d.ts +87 -0
  152. package/dist/types/math-json.d.ts +3 -0
  153. package/package.json +1 -1
@@ -0,0 +1,130 @@
1
+ /** Compute Engine 0.32.1 */
2
+
3
+ // src/math-json/utils.ts
4
+ function isNumberObject(expr) {
5
+ return expr !== null && typeof expr === "object" && "num" in expr;
6
+ }
7
+ function isSymbolObject(expr) {
8
+ return expr !== null && typeof expr === "object" && "sym" in expr;
9
+ }
10
+ function isStringObject(expr) {
11
+ return expr !== null && typeof expr === "object" && "str" in expr;
12
+ }
13
+ function isDictionaryObject(expr) {
14
+ return expr !== null && typeof expr === "object" && "dict" in expr && typeof expr.dict === "object" && !Array.isArray(expr.dict) && expr.dict !== null;
15
+ }
16
+ function isFunctionObject(expr) {
17
+ return expr !== null && typeof expr === "object" && "fn" in expr && Array.isArray(expr.fn) && expr.fn.length > 0 && typeof expr.fn[0] === "string";
18
+ }
19
+ function stringValue(expr) {
20
+ if (expr === null || expr === void 0) return null;
21
+ if (typeof expr === "object" && "str" in expr) return expr.str;
22
+ if (typeof expr !== "string") return null;
23
+ if (expr.length >= 2 && expr.at(0) === "'" && expr.at(-1) === "'")
24
+ return expr.substring(1, expr.length - 1);
25
+ if (matchesNumber(expr) || matchesSymbol(expr)) return null;
26
+ return expr;
27
+ }
28
+ function operator(expr) {
29
+ if (Array.isArray(expr)) return expr[0];
30
+ if (expr === null || expr === void 0) return "";
31
+ if (isFunctionObject(expr)) return expr.fn[0];
32
+ return "";
33
+ }
34
+ function operands(expr) {
35
+ if (Array.isArray(expr)) return expr.slice(1);
36
+ if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
37
+ return [];
38
+ }
39
+ function operand(expr, n) {
40
+ if (Array.isArray(expr)) return expr[n] ?? null;
41
+ if (expr === null || !isFunctionObject(expr)) return null;
42
+ return expr.fn[n] ?? null;
43
+ }
44
+ function nops(expr) {
45
+ if (expr === null || expr === void 0) return 0;
46
+ if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
47
+ if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
48
+ return 0;
49
+ }
50
+ function symbol(expr) {
51
+ if (typeof expr === "string" && matchesSymbol(expr)) {
52
+ if (expr.length >= 2 && expr.at(0) === "`" && expr.at(-1) === "`")
53
+ return expr.slice(1, -1);
54
+ return expr;
55
+ }
56
+ if (expr === null || expr === void 0) return null;
57
+ if (isSymbolObject(expr)) return expr.sym;
58
+ return null;
59
+ }
60
+ function keyValuePair(expr) {
61
+ const h = operator(expr);
62
+ if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
63
+ const [k, v] = operands(expr);
64
+ const key = stringValue(k);
65
+ if (!key) return null;
66
+ return [key, v ?? "Nothing"];
67
+ }
68
+ return null;
69
+ }
70
+ function dictionaryFromExpression(expr) {
71
+ if (expr === null) return null;
72
+ if (isDictionaryObject(expr)) return expr;
73
+ const kv = keyValuePair(expr);
74
+ if (kv) return { [kv[0]]: kv[1] };
75
+ if (operator(expr) === "Dictionary") {
76
+ const dict = {};
77
+ const ops = operands(expr);
78
+ for (let i = 1; i < nops(expr); i++) {
79
+ const kv2 = keyValuePair(ops[i]);
80
+ if (kv2) {
81
+ dict[kv2[0]] = expressionToDictionaryValue(kv2[1]) ?? "Nothing";
82
+ }
83
+ }
84
+ return { dict };
85
+ }
86
+ return null;
87
+ }
88
+ function mapArgs(expr, fn) {
89
+ let args = null;
90
+ if (Array.isArray(expr)) args = expr;
91
+ if (isFunctionObject(expr)) args = expr.fn;
92
+ if (args === null) return [];
93
+ let i = 1;
94
+ const result = [];
95
+ while (i < args.length) {
96
+ result.push(fn(args[i]));
97
+ i += 1;
98
+ }
99
+ return result;
100
+ }
101
+ function matchesNumber(s) {
102
+ return /^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(s) || /^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(s);
103
+ }
104
+ function matchesSymbol(s) {
105
+ return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
106
+ }
107
+ function expressionToDictionaryValue(expr) {
108
+ if (expr === null || expr === void 0) return null;
109
+ if (isStringObject(expr)) return expr.str;
110
+ if (isNumberObject(expr)) return parseFloat(expr.num);
111
+ if (isSymbolObject(expr)) return expr.sym;
112
+ if (typeof expr === "string" || typeof expr === "number") return expr;
113
+ if (Array.isArray(expr)) return { fn: expr };
114
+ return expr;
115
+ }
116
+
117
+ // src/math-json.ts
118
+ var version = "0.32.1";
119
+ export {
120
+ dictionaryFromExpression,
121
+ isFunctionObject,
122
+ isStringObject,
123
+ isSymbolObject,
124
+ mapArgs,
125
+ operand,
126
+ operator,
127
+ stringValue,
128
+ symbol,
129
+ version
130
+ };
@@ -0,0 +1,130 @@
1
+ /** Compute Engine 0.32.1 */
2
+
3
+ // src/math-json/utils.ts
4
+ function isNumberObject(expr) {
5
+ return expr !== null && typeof expr === "object" && "num" in expr;
6
+ }
7
+ function isSymbolObject(expr) {
8
+ return expr !== null && typeof expr === "object" && "sym" in expr;
9
+ }
10
+ function isStringObject(expr) {
11
+ return expr !== null && typeof expr === "object" && "str" in expr;
12
+ }
13
+ function isDictionaryObject(expr) {
14
+ return expr !== null && typeof expr === "object" && "dict" in expr && typeof expr.dict === "object" && !Array.isArray(expr.dict) && expr.dict !== null;
15
+ }
16
+ function isFunctionObject(expr) {
17
+ return expr !== null && typeof expr === "object" && "fn" in expr && Array.isArray(expr.fn) && expr.fn.length > 0 && typeof expr.fn[0] === "string";
18
+ }
19
+ function stringValue(expr) {
20
+ if (expr === null || expr === void 0) return null;
21
+ if (typeof expr === "object" && "str" in expr) return expr.str;
22
+ if (typeof expr !== "string") return null;
23
+ if (expr.length >= 2 && expr.at(0) === "'" && expr.at(-1) === "'")
24
+ return expr.substring(1, expr.length - 1);
25
+ if (matchesNumber(expr) || matchesSymbol(expr)) return null;
26
+ return expr;
27
+ }
28
+ function operator(expr) {
29
+ if (Array.isArray(expr)) return expr[0];
30
+ if (expr === null || expr === void 0) return "";
31
+ if (isFunctionObject(expr)) return expr.fn[0];
32
+ return "";
33
+ }
34
+ function operands(expr) {
35
+ if (Array.isArray(expr)) return expr.slice(1);
36
+ if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
37
+ return [];
38
+ }
39
+ function operand(expr, n) {
40
+ if (Array.isArray(expr)) return expr[n] ?? null;
41
+ if (expr === null || !isFunctionObject(expr)) return null;
42
+ return expr.fn[n] ?? null;
43
+ }
44
+ function nops(expr) {
45
+ if (expr === null || expr === void 0) return 0;
46
+ if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
47
+ if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
48
+ return 0;
49
+ }
50
+ function symbol(expr) {
51
+ if (typeof expr === "string" && matchesSymbol(expr)) {
52
+ if (expr.length >= 2 && expr.at(0) === "`" && expr.at(-1) === "`")
53
+ return expr.slice(1, -1);
54
+ return expr;
55
+ }
56
+ if (expr === null || expr === void 0) return null;
57
+ if (isSymbolObject(expr)) return expr.sym;
58
+ return null;
59
+ }
60
+ function keyValuePair(expr) {
61
+ const h = operator(expr);
62
+ if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
63
+ const [k, v] = operands(expr);
64
+ const key = stringValue(k);
65
+ if (!key) return null;
66
+ return [key, v ?? "Nothing"];
67
+ }
68
+ return null;
69
+ }
70
+ function dictionaryFromExpression(expr) {
71
+ if (expr === null) return null;
72
+ if (isDictionaryObject(expr)) return expr;
73
+ const kv = keyValuePair(expr);
74
+ if (kv) return { [kv[0]]: kv[1] };
75
+ if (operator(expr) === "Dictionary") {
76
+ const dict = {};
77
+ const ops = operands(expr);
78
+ for (let i = 1; i < nops(expr); i++) {
79
+ const kv2 = keyValuePair(ops[i]);
80
+ if (kv2) {
81
+ dict[kv2[0]] = expressionToDictionaryValue(kv2[1]) ?? "Nothing";
82
+ }
83
+ }
84
+ return { dict };
85
+ }
86
+ return null;
87
+ }
88
+ function mapArgs(expr, fn) {
89
+ let args = null;
90
+ if (Array.isArray(expr)) args = expr;
91
+ if (isFunctionObject(expr)) args = expr.fn;
92
+ if (args === null) return [];
93
+ let i = 1;
94
+ const result = [];
95
+ while (i < args.length) {
96
+ result.push(fn(args[i]));
97
+ i += 1;
98
+ }
99
+ return result;
100
+ }
101
+ function matchesNumber(s) {
102
+ return /^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(s) || /^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(s);
103
+ }
104
+ function matchesSymbol(s) {
105
+ return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
106
+ }
107
+ function expressionToDictionaryValue(expr) {
108
+ if (expr === null || expr === void 0) return null;
109
+ if (isStringObject(expr)) return expr.str;
110
+ if (isNumberObject(expr)) return parseFloat(expr.num);
111
+ if (isSymbolObject(expr)) return expr.sym;
112
+ if (typeof expr === "string" || typeof expr === "number") return expr;
113
+ if (Array.isArray(expr)) return { fn: expr };
114
+ return expr;
115
+ }
116
+
117
+ // src/math-json.ts
118
+ var version = "0.32.1";
119
+ export {
120
+ dictionaryFromExpression,
121
+ isFunctionObject,
122
+ isStringObject,
123
+ isSymbolObject,
124
+ mapArgs,
125
+ operand,
126
+ operator,
127
+ stringValue,
128
+ symbol,
129
+ version
130
+ };
@@ -0,0 +1,4 @@
1
+ /** MathJSON 0.32.1 */
2
+ (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
3
+ var MathJson=(()=>{var f=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var A=(n,t)=>{for(var i in t)f(n,i,{get:t[i],enumerable:!0})},J=(n,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of O(t))!M.call(n,e)&&e!==i&&f(n,e,{get:()=>t[e],enumerable:!(r=j(t,e))||r.enumerable});return n};var S=n=>J(f({},"__esModule",{value:!0}),n);var T={};A(T,{dictionaryFromExpression:()=>E,isFunctionObject:()=>u,isStringObject:()=>a,isSymbolObject:()=>o,mapArgs:()=>h,operand:()=>d,operator:()=>s,stringValue:()=>c,symbol:()=>m,version:()=>V});function N(n){return n!==null&&typeof n=="object"&&"num"in n}function o(n){return n!==null&&typeof n=="object"&&"sym"in n}function a(n){return n!==null&&typeof n=="object"&&"str"in n}function p(n){return n!==null&&typeof n=="object"&&"dict"in n&&typeof n.dict=="object"&&!Array.isArray(n.dict)&&n.dict!==null}function u(n){return n!==null&&typeof n=="object"&&"fn"in n&&Array.isArray(n.fn)&&n.fn.length>0&&typeof n.fn[0]=="string"}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"?null:n.length>=2&&n.at(0)==="'"&&n.at(-1)==="'"?n.substring(1,n.length-1):k(n)||g(n)?null:n}function s(n){return Array.isArray(n)?n[0]:n==null?"":u(n)?n.fn[0]:""}function b(n){return Array.isArray(n)?n.slice(1):n!==void 0&&u(n)?n.fn.slice(1):[]}function d(n,t){return Array.isArray(n)?n[t]??null:n===null||!u(n)?null:n.fn[t]??null}function D(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):u(n)?Math.max(0,n.fn.length-1):0}function m(n){return typeof n=="string"&&g(n)?n.length>=2&&n.at(0)==="`"&&n.at(-1)==="`"?n.slice(1,-1):n:n==null?null:o(n)?n.sym:null}function y(n){let t=s(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[i,r]=b(n),e=c(i);return e?[e,r??"Nothing"]:null}return null}function E(n){if(n===null)return null;if(p(n))return n;let t=y(n);if(t)return{[t[0]]:t[1]};if(s(n)==="Dictionary"){let i={},r=b(n);for(let e=1;e<D(n);e++){let l=y(r[e]);l&&(i[l[0]]=F(l[1])??"Nothing")}return{dict:i}}return null}function h(n,t){let i=null;if(Array.isArray(n)&&(i=n),u(n)&&(i=n.fn),i===null)return[];let r=1,e=[];for(;r<i.length;)e.push(t(i[r])),r+=1;return e}function k(n){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(n)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(n)}function g(n){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||n.length>=2&&n[0]==="`"&&n[n.length-1]==="`"}function F(n){return n==null?null:a(n)?n.str:N(n)?parseFloat(n.num):o(n)?n.sym:typeof n=="string"||typeof n=="number"?n:Array.isArray(n)?{fn:n}:n}var V="0.32.1";return S(T);})();
4
+ Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -0,0 +1,155 @@
1
+ /** MathJSON 0.32.1 */
2
+ (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
3
+ var MathJson = (() => {
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/math-json.ts
23
+ var math_json_exports = {};
24
+ __export(math_json_exports, {
25
+ dictionaryFromExpression: () => dictionaryFromExpression,
26
+ isFunctionObject: () => isFunctionObject,
27
+ isStringObject: () => isStringObject,
28
+ isSymbolObject: () => isSymbolObject,
29
+ mapArgs: () => mapArgs,
30
+ operand: () => operand,
31
+ operator: () => operator,
32
+ stringValue: () => stringValue,
33
+ symbol: () => symbol,
34
+ version: () => version
35
+ });
36
+
37
+ // src/math-json/utils.ts
38
+ function isNumberObject(expr) {
39
+ return expr !== null && typeof expr === "object" && "num" in expr;
40
+ }
41
+ function isSymbolObject(expr) {
42
+ return expr !== null && typeof expr === "object" && "sym" in expr;
43
+ }
44
+ function isStringObject(expr) {
45
+ return expr !== null && typeof expr === "object" && "str" in expr;
46
+ }
47
+ function isDictionaryObject(expr) {
48
+ return expr !== null && typeof expr === "object" && "dict" in expr && typeof expr.dict === "object" && !Array.isArray(expr.dict) && expr.dict !== null;
49
+ }
50
+ function isFunctionObject(expr) {
51
+ return expr !== null && typeof expr === "object" && "fn" in expr && Array.isArray(expr.fn) && expr.fn.length > 0 && typeof expr.fn[0] === "string";
52
+ }
53
+ function stringValue(expr) {
54
+ if (expr === null || expr === void 0) return null;
55
+ if (typeof expr === "object" && "str" in expr) return expr.str;
56
+ if (typeof expr !== "string") return null;
57
+ if (expr.length >= 2 && expr.at(0) === "'" && expr.at(-1) === "'")
58
+ return expr.substring(1, expr.length - 1);
59
+ if (matchesNumber(expr) || matchesSymbol(expr)) return null;
60
+ return expr;
61
+ }
62
+ function operator(expr) {
63
+ if (Array.isArray(expr)) return expr[0];
64
+ if (expr === null || expr === void 0) return "";
65
+ if (isFunctionObject(expr)) return expr.fn[0];
66
+ return "";
67
+ }
68
+ function operands(expr) {
69
+ if (Array.isArray(expr)) return expr.slice(1);
70
+ if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
71
+ return [];
72
+ }
73
+ function operand(expr, n) {
74
+ if (Array.isArray(expr)) return expr[n] ?? null;
75
+ if (expr === null || !isFunctionObject(expr)) return null;
76
+ return expr.fn[n] ?? null;
77
+ }
78
+ function nops(expr) {
79
+ if (expr === null || expr === void 0) return 0;
80
+ if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
81
+ if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
82
+ return 0;
83
+ }
84
+ function symbol(expr) {
85
+ if (typeof expr === "string" && matchesSymbol(expr)) {
86
+ if (expr.length >= 2 && expr.at(0) === "`" && expr.at(-1) === "`")
87
+ return expr.slice(1, -1);
88
+ return expr;
89
+ }
90
+ if (expr === null || expr === void 0) return null;
91
+ if (isSymbolObject(expr)) return expr.sym;
92
+ return null;
93
+ }
94
+ function keyValuePair(expr) {
95
+ const h = operator(expr);
96
+ if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
97
+ const [k, v] = operands(expr);
98
+ const key = stringValue(k);
99
+ if (!key) return null;
100
+ return [key, v ?? "Nothing"];
101
+ }
102
+ return null;
103
+ }
104
+ function dictionaryFromExpression(expr) {
105
+ if (expr === null) return null;
106
+ if (isDictionaryObject(expr)) return expr;
107
+ const kv = keyValuePair(expr);
108
+ if (kv) return { [kv[0]]: kv[1] };
109
+ if (operator(expr) === "Dictionary") {
110
+ const dict = {};
111
+ const ops = operands(expr);
112
+ for (let i = 1; i < nops(expr); i++) {
113
+ const kv2 = keyValuePair(ops[i]);
114
+ if (kv2) {
115
+ dict[kv2[0]] = expressionToDictionaryValue(kv2[1]) ?? "Nothing";
116
+ }
117
+ }
118
+ return { dict };
119
+ }
120
+ return null;
121
+ }
122
+ function mapArgs(expr, fn) {
123
+ let args = null;
124
+ if (Array.isArray(expr)) args = expr;
125
+ if (isFunctionObject(expr)) args = expr.fn;
126
+ if (args === null) return [];
127
+ let i = 1;
128
+ const result = [];
129
+ while (i < args.length) {
130
+ result.push(fn(args[i]));
131
+ i += 1;
132
+ }
133
+ return result;
134
+ }
135
+ function matchesNumber(s) {
136
+ return /^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(s) || /^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(s);
137
+ }
138
+ function matchesSymbol(s) {
139
+ return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s) || s.length >= 2 && s[0] === "`" && s[s.length - 1] === "`";
140
+ }
141
+ function expressionToDictionaryValue(expr) {
142
+ if (expr === null || expr === void 0) return null;
143
+ if (isStringObject(expr)) return expr.str;
144
+ if (isNumberObject(expr)) return parseFloat(expr.num);
145
+ if (isSymbolObject(expr)) return expr.sym;
146
+ if (typeof expr === "string" || typeof expr === "number") return expr;
147
+ if (Array.isArray(expr)) return { fn: expr };
148
+ return expr;
149
+ }
150
+
151
+ // src/math-json.ts
152
+ var version = "0.32.1";
153
+ return __toCommonJS(math_json_exports);
154
+ })();
155
+ Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -0,0 +1,41 @@
1
+ /* 0.32.1 */
2
+ export declare const DEFAULT_COLOR = "\u001B[39m";
3
+ export declare const DEFAULT_BG = "\u001B[49m";
4
+ export declare const WHITE_BG = "\u001B[47m";
5
+ export declare const BLACK_BG = "\u001B[40m";
6
+ export declare const GREY_BG = "\u001B[100m";
7
+ export declare const GREEN_BG = "\u001B[42m";
8
+ export declare const RED_BG = "\u001B[41m";
9
+ export declare const YELLOW_BG = "\u001B[43m";
10
+ export declare const BLUE_BG = "\u001B[44m";
11
+ export declare const MAGENTA_BG = "\u001B[45m";
12
+ export declare const CYAN_BG = "\u001B[46m";
13
+ export declare const WHITE = "\u001B[37;1m";
14
+ export declare const BLACK = "\u001B[30;1m";
15
+ export declare const GREY = "\u001B[30;1m";
16
+ export declare const GREEN = "\u001B[32;1m";
17
+ export declare const RED = "\u001B[31;1m";
18
+ export declare const YELLOW = "\u001B[33m";
19
+ export declare const BLUE = "\u001B[34;1m";
20
+ export declare const MAGENTA = "\u001B[35;1m";
21
+ export declare const CYAN = "\u001B[36;1m";
22
+ export declare const INVERSE_RED = "\u001B[101;97m";
23
+ export declare const INVERSE_GREEN = "\u001B[102;97m";
24
+ export declare const INVERSE_YELLOW = "\u001B[103;97m";
25
+ export declare const INVERSE_BLUE = "\u001B[104;97m";
26
+ export declare const BOLD = "\u001B[1m";
27
+ export declare const BOLD_OFF = "\u001B[22m";
28
+ export declare const DIM = "\u001B[2m";
29
+ export declare const DIM_OFF = "\u001B[22m";
30
+ export declare const ITALIC = "\u001B[3m";
31
+ export declare const ITALIC_OFF = "\u001B[23m";
32
+ export declare const UNDERLINE = "\u001B[4m";
33
+ export declare const UNDERLINE_OFF = "\u001B[24m";
34
+ export declare const BLINK = "\u001B[5m";
35
+ export declare const BLINK_OFF = "\u001B[25m";
36
+ export declare const INVERSE = "\u001B[7m";
37
+ export declare const INVERSE_OFF = "\u001B[27m";
38
+ export declare const HIDDEN = "\u001B[8m";
39
+ export declare const HIDDEN_OFF = "\u001B[28m";
40
+ export declare function ansiFgColor(color: string | number, mode: 'none' | 'basic' | 'full'): number[];
41
+ export declare function ansiBgColor(color: string, mode: 'none' | 'basic' | 'full'): number[];
@@ -0,0 +1,28 @@
1
+ /* 0.32.1 */
2
+ private _listeners;
3
+ private _pending;
4
+ private _version;
5
+ /**
6
+ * Registers a listener for configuration changes.
7
+ * Returns a function to unsubscribe the listener.
8
+ * Prevents duplicate subscriptions: if the listener is already registered,
9
+ * returns the existing unsubscribe logic without adding a duplicate.
10
+ */
11
+ listen(listener: ConfigurationChangeListener): () => void;
12
+ private _unsubscribe;
13
+ /**
14
+ * Notifies all live listeners of a configuration change.
15
+ * Also prunes any dead references from the list.
16
+ * Prevents infinite loops from recursive notify() calls.
17
+ */
18
+ notify(): void;
19
+ /**
20
+ * Immediately notifies all live listeners of a configuration change.
21
+ * Also prunes any dead references from the list.
22
+ * Increments the version and clears the pending flag.
23
+ */
24
+ notifyNow(): void;
25
+ }
26
+ export interface ConfigurationChangeListener {
27
+ onConfigurationChange?: () => void;
28
+ }
@@ -0,0 +1,2 @@
1
+ /* 0.32.1 */
2
+ export declare function fuzzyStringMatch(invalidWord: string, validWords: string[]): string | null;
@@ -0,0 +1,15 @@
1
+ /* 0.32.1 */
2
+ /**
3
+ * Return a string or an array of graphemes.
4
+ *
5
+ * This includes:
6
+ * - emoji with skin and hair modifiers
7
+ * - emoji combination (for example "female pilot")
8
+ * - text emoji with an emoji presentation style modifier
9
+ * - U+1F512 U+FE0E 🔒︎
10
+ * - U+1F512 U+FE0F 🔒️
11
+ * - flags represented as two regional indicator codepoints
12
+ * - flags represented as a flag emoji + zwj + an emoji tag
13
+ * - other combinations (for example, rainbow flag)
14
+ */
15
+ export declare function splitGraphemes(string: string): string | string[];
@@ -0,0 +1,20 @@
1
+ /* 0.32.1 */
2
+ cause: unknown;
3
+ value: T;
4
+ constructor({ message, value, cause, }?: {
5
+ message?: string;
6
+ value?: T;
7
+ cause?: unknown;
8
+ });
9
+ }
10
+ /**
11
+ * Executes a generator asynchronously with timeout and abort signal support.
12
+ *
13
+ * @param gen - The generator to execute.
14
+ * @param timeLimitMs - The maximum time (in milliseconds) allowed for execution.
15
+ * @param signal - An AbortSignal to cancel execution prematurely.
16
+ * @returns The final value produced by the generator.
17
+ * @throws CancellationError if the operation is canceled or times out.
18
+ */
19
+ export declare function runAsync<T>(gen: Generator<T>, timeLimitMs: number, signal?: AbortSignal): Promise<T>;
20
+ export declare function run<T>(gen: Generator<T>, timeLimitMs: number): T;
@@ -0,0 +1,10 @@
1
+ /* 0.32.1 */
2
+ infer Head,
3
+ ...infer Rem
4
+ ] ? MergeTypes<Rem, Res & Head> : Res;
5
+ /** @internal */
6
+ export type OneOf<TypesArray extends any[], Res = never, AllProperties = MergeTypes<TypesArray>> = TypesArray extends [infer Head, ...infer Rem] ? OneOf<Rem, Res | OnlyFirst<Head, AllProperties>, AllProperties> : Res;
7
+ type OnlyFirst<F, S> = F & {
8
+ [Key in keyof Omit<S, keyof F>]?: never;
9
+ };
10
+ export {};
@@ -0,0 +1,96 @@
1
+ /* 0.32.1 */
2
+ export type RuntimeSignalCode = 'timeout' | 'out-of-memory' | 'recursion-depth-exceeded' | 'iteration-limit-exceeded';
3
+ /** @category Error Handling */
4
+ export type SignalCode = RuntimeSignalCode | ('invalid-name' | 'expected-predicate' | 'expected-symbol' | 'operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'prefix-operator-requires-one-operand' | 'unbalanced-symbols' | 'expected-argument' | 'unexpected-command' | 'cyclic-definition' | 'invalid-supersets' | 'expected-supersets' | 'unknown-domain' | 'duplicate-wikidata' | 'invalid-dictionary-entry' | 'syntax-error');
5
+ /** @category Error Handling */
6
+ export type SignalMessage = SignalCode | [SignalCode, ...any[]];
7
+ /** @category Error Handling */
8
+ export type SignalOrigin = {
9
+ url?: string;
10
+ source?: string;
11
+ offset?: number;
12
+ line?: number;
13
+ column?: number;
14
+ around?: string;
15
+ };
16
+ /** @category Error Handling */
17
+ export type Signal = {
18
+ severity?: 'warning' | 'error';
19
+ /** An error/warning code or, a code with one or more arguments specific to
20
+ * the signal code.
21
+ */
22
+ message: SignalMessage;
23
+ /** If applicable, the head of the function about which the
24
+ * signal was raised
25
+ */
26
+ head?: string;
27
+ /** Location where the signal was raised. */
28
+ origin?: SignalOrigin;
29
+ };
30
+ /** @category Error Handling */
31
+ export type ErrorSignal = Signal & {
32
+ severity: 'error';
33
+ };
34
+ /** @category Error Handling */
35
+ export type WarningSignal = Signal & {
36
+ severity: 'warning';
37
+ };
38
+ /** @category Error Handling */
39
+ export type WarningSignalHandler = (warnings: WarningSignal[]) => void;
40
+ /**
41
+ * The error codes can be used in an `ErrorCode` expression:
42
+ *
43
+ * `["ErrorCode", "'syntax-error'", arg1]`
44
+ *
45
+ * It evaluates to a localized, human-readable string.
46
+ *
47
+ *
48
+ * * `unknown-symbol`: a symbol was encountered which does not have a
49
+ * definition.
50
+ *
51
+ * * `unknown-operator`: a presumed operator was encountered which does not
52
+ * have a definition.
53
+ *
54
+ * * `unknown-function`: a LaTeX command was encountered which does not
55
+ * have a definition.
56
+ *
57
+ * * `unexpected-command`: a LaTeX command was encountered when only a string
58
+ * was expected
59
+ *
60
+ * * `unexpected-superscript`: a superscript was encountered in an unexpected
61
+ * context, or no `powerFunction` was defined. By default, superscript can
62
+ * be applied to numbers, symbols or expressions, but not to operators (e.g.
63
+ * `2+^34`) or to punctuation.
64
+ *
65
+ * * `unexpected-subscript`: a subscript was encountered in an unexpected
66
+ * context or no 'subscriptFunction` was defined. By default, subscripts
67
+ * are not expected on numbers, operators or symbols. Some commands (e.g. `\sum`)
68
+ * do expected a subscript.
69
+ *
70
+ * * `unexpected-sequence`: some adjacent elements were encountered (for
71
+ * example `xy`), but the elements could not be combined. By default, adjacent
72
+ * symbols are combined with `Multiply`, but adjacent numbers or adjacent
73
+ * operators are not combined.
74
+ *
75
+ * * `expected-argument`: a LaTeX command that requires one or more argument
76
+ * was encountered without the required arguments.
77
+ *
78
+ * * `expected-operand`: an operator was encountered without its required
79
+ * operands.
80
+ *
81
+ * * `non-associative-operator`: an operator which is not associative was
82
+ * encountered in an associative context, for example: `a < b < c` (assuming
83
+ * `<` is defined as non-associative)
84
+ *
85
+ * * `postfix-operator-requires-one-operand`: a postfix operator which requires
86
+ * a single argument was encountered with no arguments or more than one argument
87
+ *
88
+ * * `prefix-operator-requires-one-operand`: a prefix operator which requires
89
+ * a single argument was encountered with no arguments or more than one argument
90
+ *
91
+ * * `base-out-of-range`: The base is expected to be between 2 and 36.
92
+ *
93
+ * @category Error Handling
94
+ *
95
+ */
96
+ export type ErrorCode = 'expected-argument' | 'unexpected-argument' | 'expected-operator' | 'expected-operand' | 'invalid-name' | 'invalid-dictionary-entry' | 'unknown-symbol' | 'unknown-operator' | 'unknown-function' | 'unknown-command' | 'unexpected-command' | 'unbalanced-symbols' | 'unexpected-superscript' | 'unexpected-subscript' | 'unexpected-sequence' | 'non-associative-operator' | 'function-has-too-many-arguments' | 'function-has-too-few-arguments' | 'operator-requires-one-operand' | 'infix-operator-requires-two-operands' | 'prefix-operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'associative-function-has-too-few-arguments' | 'commutative-function-has-too-few-arguments' | 'threadable-function-has-too-few-arguments' | 'hold-first-function-has-too-few-arguments' | 'hold-rest-function-has-too-few-arguments' | 'base-out-of-range' | 'syntax-error';