@cortex-js/compute-engine 0.25.1 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/compute-engine.esm.js +26832 -23014
  2. package/dist/compute-engine.js +26836 -23006
  3. package/dist/compute-engine.min.esm.js +88 -23
  4. package/dist/compute-engine.min.js +88 -23
  5. package/dist/math-json.esm.js +22 -139
  6. package/dist/math-json.js +22 -139
  7. package/dist/math-json.min.esm.js +22 -139
  8. package/dist/math-json.min.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +30 -4
  10. package/dist/types/common/buffer.d.ts +9 -0
  11. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  12. package/dist/types/common/one-of.d.ts +9 -0
  13. package/dist/types/common/signals.d.ts +1 -1
  14. package/dist/types/common/styled-text.d.ts +28 -0
  15. package/dist/types/common/suggest.d.ts +1 -0
  16. package/dist/types/common/syntax-highlighter.d.ts +40 -0
  17. package/dist/types/common/terminal.d.ts +19 -0
  18. package/dist/types/common/type/parse.d.ts +4 -0
  19. package/dist/types/common/type/primitive.d.ts +8 -0
  20. package/dist/types/common/type/serialize.d.ts +2 -0
  21. package/dist/types/common/type/subtype.d.ts +6 -0
  22. package/dist/types/common/type/types.d.ts +249 -0
  23. package/dist/types/common/type/utils.d.ts +39 -0
  24. package/dist/types/common/utils.d.ts +2 -1
  25. package/dist/types/compute-engine/assume.d.ts +13 -13
  26. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +70 -47
  27. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  28. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -0
  29. package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +12 -0
  30. package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +16 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +20 -0
  32. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  33. package/dist/types/compute-engine/boxed-expression/box.d.ts +13 -71
  34. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +31 -13
  35. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +66 -45
  36. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +41 -37
  37. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
  38. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +13 -9
  39. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +34 -66
  40. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +63 -41
  41. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +44 -27
  42. package/dist/types/compute-engine/boxed-expression/cache.d.ts +6 -0
  43. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  45. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  46. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -6
  48. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  49. package/dist/types/compute-engine/boxed-expression/hold.d.ts +9 -0
  50. package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -4
  51. package/dist/types/compute-engine/boxed-expression/negate.d.ts +10 -0
  52. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +5 -39
  53. package/dist/types/compute-engine/boxed-expression/order.d.ts +26 -14
  54. package/dist/types/compute-engine/{symbolic → boxed-expression}/polynomials.d.ts +11 -15
  55. package/dist/types/compute-engine/{symbolic → boxed-expression}/product.d.ts +18 -24
  56. package/dist/types/compute-engine/boxed-expression/public.d.ts +906 -634
  57. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  58. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
  59. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +6 -0
  60. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  61. package/dist/types/compute-engine/{solve.d.ts → boxed-expression/solve.d.ts} +5 -5
  62. package/dist/types/compute-engine/{symbolic → boxed-expression}/tensor-fields.d.ts +3 -3
  63. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  64. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +10 -0
  65. package/dist/types/compute-engine/boxed-expression/utils.d.ts +22 -16
  66. package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -7
  67. package/dist/types/compute-engine/collection-utils.d.ts +24 -2
  68. package/dist/types/compute-engine/compile.d.ts +3 -3
  69. package/dist/types/compute-engine/compute-engine.d.ts +132 -165
  70. package/dist/types/compute-engine/cost-function.d.ts +11 -1
  71. package/dist/types/compute-engine/function-utils.d.ts +5 -5
  72. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  73. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  74. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  75. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  76. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  86. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
  87. package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -30
  88. package/dist/types/compute-engine/latex-syntax/public.d.ts +22 -18
  89. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
  90. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -8
  92. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  93. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -2
  94. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  95. package/dist/types/compute-engine/library/collections.d.ts +24 -1
  96. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  97. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  98. package/dist/types/compute-engine/library/core.d.ts +1 -3
  99. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  100. package/dist/types/compute-engine/library/library.d.ts +2 -4
  101. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  102. package/dist/types/compute-engine/library/logic.d.ts +5 -1
  103. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  104. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  105. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  106. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  107. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  108. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  109. package/dist/types/compute-engine/library/utils.d.ts +46 -40
  110. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +59 -0
  111. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +77 -0
  112. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +58 -0
  113. package/dist/types/compute-engine/numeric-value/public.d.ts +110 -0
  114. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  115. package/dist/types/compute-engine/numerics/bignum.d.ts +12 -0
  116. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  117. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  118. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +19 -0
  119. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +4 -14
  120. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +6 -9
  121. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  122. package/dist/types/compute-engine/numerics/numeric.d.ts +9 -59
  123. package/dist/types/compute-engine/numerics/primes.d.ts +3 -3
  124. package/dist/types/compute-engine/numerics/rationals.d.ts +29 -13
  125. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  126. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  127. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  128. package/dist/types/compute-engine/public.d.ts +8 -4
  129. package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -2
  130. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  131. package/dist/types/compute-engine/{simplify-rules.d.ts → symbolic/simplify-rules.d.ts} +1 -1
  132. package/dist/types/compute-engine/{symbolic → tensor}/tensors.d.ts +3 -3
  133. package/dist/types/compute-engine.d.ts +4 -2
  134. package/dist/types/math-json/identifiers.d.ts +11 -0
  135. package/dist/types/math-json/{math-json-format.d.ts → types.d.ts} +4 -9
  136. package/dist/types/math-json/utils.d.ts +15 -23
  137. package/dist/types/math-json.d.ts +3 -3
  138. package/package.json +3 -3
  139. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -48
  140. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +0 -40
  141. package/dist/types/compute-engine/boxed-expression/coefficient-field.d.ts +0 -56
  142. package/dist/types/compute-engine/domain-utils.d.ts +0 -19
  143. package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
  144. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -16
  145. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
  146. package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
  147. package/dist/types/compute-engine/library/domains.d.ts +0 -16
  148. package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
  149. package/dist/types/compute-engine/rules.d.ts +0 -20
  150. package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
  151. package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
  152. package/dist/types/compute-engine/symbolic/negate.d.ts +0 -11
  153. package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.25.1 */
1
+ /** Compute Engine 0.26.0 */
2
2
 
3
3
  // src/math-json/utils.ts
4
4
  function isSymbolObject(expr) {
@@ -10,126 +10,29 @@ function isStringObject(expr) {
10
10
  function isFunctionObject(expr) {
11
11
  return expr !== null && typeof expr === "object" && "fn" in expr;
12
12
  }
13
- function isDictionaryObject(expr) {
14
- return expr !== null && typeof expr === "object" && "dict" in expr;
15
- }
16
- var recommendedScriptsRegex;
17
- function isRecommendedScripts(text) {
18
- if (!recommendedScriptsRegex) {
19
- const recommendedScripts = [
20
- "Zyyy",
21
- "Zinh",
22
- "Arab",
23
- "Armn",
24
- "Beng",
25
- "Bopo",
26
- "Cyrl",
27
- "Deva",
28
- "Ethi",
29
- "Geor",
30
- "Grek",
31
- "Gujr",
32
- "Guru",
33
- "Hang",
34
- "Hani",
35
- "Hebr",
36
- "Hira",
37
- "Kana",
38
- "Knda",
39
- "Khmr",
40
- "Laoo",
41
- "Latn",
42
- "Mlym",
43
- "Mymr",
44
- "Orya",
45
- "Sinh",
46
- "Taml",
47
- "Telu",
48
- "Thaa",
49
- "Thai",
50
- "Tibt"
51
- ];
52
- const regexPattern = `^[${recommendedScripts.map((x) => `\\p{Script=${x}}`).join("")}]*$`;
53
- recommendedScriptsRegex = new RegExp(regexPattern, "u");
54
- }
55
- return recommendedScriptsRegex.test(text);
56
- }
57
- function isValidIdentifier(s) {
58
- if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)) return true;
59
- if (ONLY_EMOJIS.test(s)) return true;
60
- if (!isRecommendedScripts(s)) return false;
61
- return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
62
- }
63
- var VS16 = "\\u{FE0F}";
64
- var KEYCAP = "\\u{20E3}";
65
- var ZWJ = "\\u{200D}";
66
- var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
67
- var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
68
- var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
69
- var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
70
- var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
71
- var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
72
- var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
73
- var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
74
- function validateIdentifier(s) {
75
- if (typeof s !== "string") return "not-a-string";
76
- if (s === "") return "empty-string";
77
- if (s.normalize() !== s) return "expected-nfc";
78
- if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
79
- return "unexpected-bidi-marker";
80
- if (ONLY_EMOJIS.test(s)) return "valid";
81
- if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
82
- return "unexpected-mixed-emoji";
83
- if (!isRecommendedScripts(s)) return "unexpected-script";
84
- if (!isValidIdentifier(s)) {
85
- if (!isValidIdentifier(s[0])) return "invalid-first-char";
86
- return "invalid-char";
87
- }
88
- return "valid";
89
- }
90
13
  function stringValue(expr) {
91
14
  if (expr === null || expr === void 0) return null;
92
15
  if (typeof expr === "object" && "str" in expr) return expr.str;
93
16
  if (typeof expr !== "string") return null;
94
17
  if (expr.length < 2) return null;
95
- if (expr[0] !== "'" || expr[expr.length - 1] !== "'") return null;
18
+ if (expr.at(0) !== "'" || expr.at(-1) !== "'") return null;
96
19
  return expr.substring(1, expr.length - 1);
97
20
  }
98
- function head(expr) {
99
- if (Array.isArray(expr)) {
100
- if (typeof expr[0] === "string" && !isValidIdentifier(expr[0])) {
101
- console.error(
102
- `Invalid identifier "${expr[0]}": ${validateIdentifier(expr[0])}`
103
- );
104
- return null;
105
- }
106
- return expr[0];
107
- }
108
- if (expr === null || expr === void 0) return null;
21
+ function operator(expr) {
22
+ if (Array.isArray(expr)) return expr[0];
23
+ if (expr === null || expr === void 0) return "";
109
24
  if (isFunctionObject(expr)) return expr.fn[0];
110
- return null;
25
+ return "";
111
26
  }
112
- function headName(expr) {
113
- const h = head(expr);
114
- return typeof h === "string" ? h : "";
115
- }
116
- function ops(expr) {
27
+ function operands(expr) {
117
28
  if (Array.isArray(expr)) return expr.slice(1);
118
- if (expr === null || expr === void 0) return null;
119
- if (isFunctionObject(expr)) return expr.fn.slice(1);
120
- return null;
29
+ if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
30
+ return [];
121
31
  }
122
- function op(expr, n) {
32
+ function operand(expr, n) {
123
33
  if (Array.isArray(expr)) return expr[n] ?? null;
124
- if (expr === null || expr === void 0) return null;
125
- if (isFunctionObject(expr)) return expr.fn[n] ?? null;
126
- return null;
127
- }
128
- function op1(expr) {
129
- return op(expr, 1);
130
- }
131
- function op2(expr) {
132
- return op(expr, 2);
34
+ if (expr === null || !isFunctionObject(expr)) return null;
35
+ return expr.fn[n] ?? null;
133
36
  }
134
37
  function nops(expr) {
135
38
  if (expr === null || expr === void 0) return 0;
@@ -150,47 +53,31 @@ function symbol(expr) {
150
53
  return s;
151
54
  }
152
55
  function keyValuePair(expr) {
153
- const h = head(expr);
56
+ const h = operator(expr);
154
57
  if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
155
- const key = stringValue(op1(expr));
58
+ const [k, v] = operands(expr);
59
+ const key = stringValue(k);
156
60
  if (!key) return null;
157
- return [key, op2(expr) ?? "Nothing"];
61
+ return [key, v ?? "Nothing"];
158
62
  }
159
63
  return null;
160
64
  }
161
65
  function dictionary(expr) {
162
66
  if (expr === null) return null;
163
- if (typeof expr === "object" && "dict" in expr) return expr.dict;
164
67
  const kv = keyValuePair(expr);
165
68
  if (kv) return { [kv[0]]: kv[1] };
166
- const h = head(expr);
69
+ const h = operator(expr);
167
70
  if (h === "Dictionary") {
168
71
  const result = {};
72
+ const ops = operands(expr);
169
73
  for (let i = 1; i < nops(expr); i++) {
170
- const kv2 = keyValuePair(op(expr, i));
74
+ const kv2 = keyValuePair(ops[i]);
171
75
  if (kv2) result[kv2[0]] = kv2[1];
172
76
  }
173
77
  return result;
174
78
  }
175
79
  return null;
176
80
  }
177
- function applyRecursively(expr, fn) {
178
- const h = head(expr);
179
- if (h !== null) {
180
- return [
181
- fn(h),
182
- ...(ops(expr) ?? []).map(fn)
183
- ];
184
- }
185
- const dict = dictionary(expr);
186
- if (dict !== null) {
187
- const keys = Object.keys(dict);
188
- const result = {};
189
- for (const key of keys) result[key] = fn(dict[key]);
190
- return { dict: result };
191
- }
192
- return fn(expr);
193
- }
194
81
  function mapArgs(expr, fn) {
195
82
  let args = null;
196
83
  if (Array.isArray(expr)) args = expr;
@@ -206,20 +93,16 @@ function mapArgs(expr, fn) {
206
93
  }
207
94
 
208
95
  // src/math-json.ts
209
- var version = "0.25.1";
96
+ var version = "0.26.0";
210
97
  export {
211
- applyRecursively,
212
98
  dictionary as getDictionary,
213
99
  stringValue as getStringValue,
214
- head,
215
- headName,
216
- isDictionaryObject,
217
100
  isFunctionObject,
218
101
  isStringObject,
219
102
  isSymbolObject,
220
103
  mapArgs,
221
- nops,
222
- op,
104
+ operand,
105
+ operator,
223
106
  symbol,
224
107
  version
225
108
  };
package/dist/math-json.js CHANGED
@@ -1,4 +1,4 @@
1
- /** MathJSON 0.25.1 */
1
+ /** MathJSON 0.26.0 */
2
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
3
  var MathJson = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -22,18 +22,14 @@ var MathJson = (() => {
22
22
  // src/math-json.ts
23
23
  var math_json_exports = {};
24
24
  __export(math_json_exports, {
25
- applyRecursively: () => applyRecursively,
26
25
  getDictionary: () => dictionary,
27
26
  getStringValue: () => stringValue,
28
- head: () => head,
29
- headName: () => headName,
30
- isDictionaryObject: () => isDictionaryObject,
31
27
  isFunctionObject: () => isFunctionObject,
32
28
  isStringObject: () => isStringObject,
33
29
  isSymbolObject: () => isSymbolObject,
34
30
  mapArgs: () => mapArgs,
35
- nops: () => nops,
36
- op: () => op,
31
+ operand: () => operand,
32
+ operator: () => operator,
37
33
  symbol: () => symbol,
38
34
  version: () => version
39
35
  });
@@ -48,126 +44,29 @@ var MathJson = (() => {
48
44
  function isFunctionObject(expr) {
49
45
  return expr !== null && typeof expr === "object" && "fn" in expr;
50
46
  }
51
- function isDictionaryObject(expr) {
52
- return expr !== null && typeof expr === "object" && "dict" in expr;
53
- }
54
- var recommendedScriptsRegex;
55
- function isRecommendedScripts(text) {
56
- if (!recommendedScriptsRegex) {
57
- const recommendedScripts = [
58
- "Zyyy",
59
- "Zinh",
60
- "Arab",
61
- "Armn",
62
- "Beng",
63
- "Bopo",
64
- "Cyrl",
65
- "Deva",
66
- "Ethi",
67
- "Geor",
68
- "Grek",
69
- "Gujr",
70
- "Guru",
71
- "Hang",
72
- "Hani",
73
- "Hebr",
74
- "Hira",
75
- "Kana",
76
- "Knda",
77
- "Khmr",
78
- "Laoo",
79
- "Latn",
80
- "Mlym",
81
- "Mymr",
82
- "Orya",
83
- "Sinh",
84
- "Taml",
85
- "Telu",
86
- "Thaa",
87
- "Thai",
88
- "Tibt"
89
- ];
90
- const regexPattern = `^[${recommendedScripts.map((x) => `\\p{Script=${x}}`).join("")}]*$`;
91
- recommendedScriptsRegex = new RegExp(regexPattern, "u");
92
- }
93
- return recommendedScriptsRegex.test(text);
94
- }
95
- function isValidIdentifier(s) {
96
- if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)) return true;
97
- if (ONLY_EMOJIS.test(s)) return true;
98
- if (!isRecommendedScripts(s)) return false;
99
- return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
100
- }
101
- var VS16 = "\\u{FE0F}";
102
- var KEYCAP = "\\u{20E3}";
103
- var ZWJ = "\\u{200D}";
104
- var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
105
- var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
106
- var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
107
- var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
108
- var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
109
- var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
110
- var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
111
- var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
112
- function validateIdentifier(s) {
113
- if (typeof s !== "string") return "not-a-string";
114
- if (s === "") return "empty-string";
115
- if (s.normalize() !== s) return "expected-nfc";
116
- if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
117
- return "unexpected-bidi-marker";
118
- if (ONLY_EMOJIS.test(s)) return "valid";
119
- if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
120
- return "unexpected-mixed-emoji";
121
- if (!isRecommendedScripts(s)) return "unexpected-script";
122
- if (!isValidIdentifier(s)) {
123
- if (!isValidIdentifier(s[0])) return "invalid-first-char";
124
- return "invalid-char";
125
- }
126
- return "valid";
127
- }
128
47
  function stringValue(expr) {
129
48
  if (expr === null || expr === void 0) return null;
130
49
  if (typeof expr === "object" && "str" in expr) return expr.str;
131
50
  if (typeof expr !== "string") return null;
132
51
  if (expr.length < 2) return null;
133
- if (expr[0] !== "'" || expr[expr.length - 1] !== "'") return null;
52
+ if (expr.at(0) !== "'" || expr.at(-1) !== "'") return null;
134
53
  return expr.substring(1, expr.length - 1);
135
54
  }
136
- function head(expr) {
137
- if (Array.isArray(expr)) {
138
- if (typeof expr[0] === "string" && !isValidIdentifier(expr[0])) {
139
- console.error(
140
- `Invalid identifier "${expr[0]}": ${validateIdentifier(expr[0])}`
141
- );
142
- return null;
143
- }
144
- return expr[0];
145
- }
146
- if (expr === null || expr === void 0) return null;
55
+ function operator(expr) {
56
+ if (Array.isArray(expr)) return expr[0];
57
+ if (expr === null || expr === void 0) return "";
147
58
  if (isFunctionObject(expr)) return expr.fn[0];
148
- return null;
59
+ return "";
149
60
  }
150
- function headName(expr) {
151
- const h = head(expr);
152
- return typeof h === "string" ? h : "";
153
- }
154
- function ops(expr) {
61
+ function operands(expr) {
155
62
  if (Array.isArray(expr)) return expr.slice(1);
156
- if (expr === null || expr === void 0) return null;
157
- if (isFunctionObject(expr)) return expr.fn.slice(1);
158
- return null;
63
+ if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
64
+ return [];
159
65
  }
160
- function op(expr, n) {
66
+ function operand(expr, n) {
161
67
  if (Array.isArray(expr)) return expr[n] ?? null;
162
- if (expr === null || expr === void 0) return null;
163
- if (isFunctionObject(expr)) return expr.fn[n] ?? null;
164
- return null;
165
- }
166
- function op1(expr) {
167
- return op(expr, 1);
168
- }
169
- function op2(expr) {
170
- return op(expr, 2);
68
+ if (expr === null || !isFunctionObject(expr)) return null;
69
+ return expr.fn[n] ?? null;
171
70
  }
172
71
  function nops(expr) {
173
72
  if (expr === null || expr === void 0) return 0;
@@ -188,47 +87,31 @@ var MathJson = (() => {
188
87
  return s;
189
88
  }
190
89
  function keyValuePair(expr) {
191
- const h = head(expr);
90
+ const h = operator(expr);
192
91
  if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
193
- const key = stringValue(op1(expr));
92
+ const [k, v] = operands(expr);
93
+ const key = stringValue(k);
194
94
  if (!key) return null;
195
- return [key, op2(expr) ?? "Nothing"];
95
+ return [key, v ?? "Nothing"];
196
96
  }
197
97
  return null;
198
98
  }
199
99
  function dictionary(expr) {
200
100
  if (expr === null) return null;
201
- if (typeof expr === "object" && "dict" in expr) return expr.dict;
202
101
  const kv = keyValuePair(expr);
203
102
  if (kv) return { [kv[0]]: kv[1] };
204
- const h = head(expr);
103
+ const h = operator(expr);
205
104
  if (h === "Dictionary") {
206
105
  const result = {};
106
+ const ops = operands(expr);
207
107
  for (let i = 1; i < nops(expr); i++) {
208
- const kv2 = keyValuePair(op(expr, i));
108
+ const kv2 = keyValuePair(ops[i]);
209
109
  if (kv2) result[kv2[0]] = kv2[1];
210
110
  }
211
111
  return result;
212
112
  }
213
113
  return null;
214
114
  }
215
- function applyRecursively(expr, fn) {
216
- const h = head(expr);
217
- if (h !== null) {
218
- return [
219
- fn(h),
220
- ...(ops(expr) ?? []).map(fn)
221
- ];
222
- }
223
- const dict = dictionary(expr);
224
- if (dict !== null) {
225
- const keys = Object.keys(dict);
226
- const result = {};
227
- for (const key of keys) result[key] = fn(dict[key]);
228
- return { dict: result };
229
- }
230
- return fn(expr);
231
- }
232
115
  function mapArgs(expr, fn) {
233
116
  let args = null;
234
117
  if (Array.isArray(expr)) args = expr;
@@ -244,7 +127,7 @@ var MathJson = (() => {
244
127
  }
245
128
 
246
129
  // src/math-json.ts
247
- var version = "0.25.1";
130
+ var version = "0.26.0";
248
131
  return __toCommonJS(math_json_exports);
249
132
  })();
250
133
  Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.25.1 */
1
+ /** Compute Engine 0.26.0 */
2
2
 
3
3
  // src/math-json/utils.ts
4
4
  function isSymbolObject(expr) {
@@ -10,126 +10,29 @@ function isStringObject(expr) {
10
10
  function isFunctionObject(expr) {
11
11
  return expr !== null && typeof expr === "object" && "fn" in expr;
12
12
  }
13
- function isDictionaryObject(expr) {
14
- return expr !== null && typeof expr === "object" && "dict" in expr;
15
- }
16
- var recommendedScriptsRegex;
17
- function isRecommendedScripts(text) {
18
- if (!recommendedScriptsRegex) {
19
- const recommendedScripts = [
20
- "Zyyy",
21
- "Zinh",
22
- "Arab",
23
- "Armn",
24
- "Beng",
25
- "Bopo",
26
- "Cyrl",
27
- "Deva",
28
- "Ethi",
29
- "Geor",
30
- "Grek",
31
- "Gujr",
32
- "Guru",
33
- "Hang",
34
- "Hani",
35
- "Hebr",
36
- "Hira",
37
- "Kana",
38
- "Knda",
39
- "Khmr",
40
- "Laoo",
41
- "Latn",
42
- "Mlym",
43
- "Mymr",
44
- "Orya",
45
- "Sinh",
46
- "Taml",
47
- "Telu",
48
- "Thaa",
49
- "Thai",
50
- "Tibt"
51
- ];
52
- const regexPattern = `^[${recommendedScripts.map((x) => `\\p{Script=${x}}`).join("")}]*$`;
53
- recommendedScriptsRegex = new RegExp(regexPattern, "u");
54
- }
55
- return recommendedScriptsRegex.test(text);
56
- }
57
- function isValidIdentifier(s) {
58
- if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)) return true;
59
- if (ONLY_EMOJIS.test(s)) return true;
60
- if (!isRecommendedScripts(s)) return false;
61
- return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
62
- }
63
- var VS16 = "\\u{FE0F}";
64
- var KEYCAP = "\\u{20E3}";
65
- var ZWJ = "\\u{200D}";
66
- var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
67
- var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
68
- var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
69
- var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
70
- var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
71
- var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
72
- var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
73
- var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
74
- function validateIdentifier(s) {
75
- if (typeof s !== "string") return "not-a-string";
76
- if (s === "") return "empty-string";
77
- if (s.normalize() !== s) return "expected-nfc";
78
- if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
79
- return "unexpected-bidi-marker";
80
- if (ONLY_EMOJIS.test(s)) return "valid";
81
- if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
82
- return "unexpected-mixed-emoji";
83
- if (!isRecommendedScripts(s)) return "unexpected-script";
84
- if (!isValidIdentifier(s)) {
85
- if (!isValidIdentifier(s[0])) return "invalid-first-char";
86
- return "invalid-char";
87
- }
88
- return "valid";
89
- }
90
13
  function stringValue(expr) {
91
14
  if (expr === null || expr === void 0) return null;
92
15
  if (typeof expr === "object" && "str" in expr) return expr.str;
93
16
  if (typeof expr !== "string") return null;
94
17
  if (expr.length < 2) return null;
95
- if (expr[0] !== "'" || expr[expr.length - 1] !== "'") return null;
18
+ if (expr.at(0) !== "'" || expr.at(-1) !== "'") return null;
96
19
  return expr.substring(1, expr.length - 1);
97
20
  }
98
- function head(expr) {
99
- if (Array.isArray(expr)) {
100
- if (typeof expr[0] === "string" && !isValidIdentifier(expr[0])) {
101
- console.error(
102
- `Invalid identifier "${expr[0]}": ${validateIdentifier(expr[0])}`
103
- );
104
- return null;
105
- }
106
- return expr[0];
107
- }
108
- if (expr === null || expr === void 0) return null;
21
+ function operator(expr) {
22
+ if (Array.isArray(expr)) return expr[0];
23
+ if (expr === null || expr === void 0) return "";
109
24
  if (isFunctionObject(expr)) return expr.fn[0];
110
- return null;
25
+ return "";
111
26
  }
112
- function headName(expr) {
113
- const h = head(expr);
114
- return typeof h === "string" ? h : "";
115
- }
116
- function ops(expr) {
27
+ function operands(expr) {
117
28
  if (Array.isArray(expr)) return expr.slice(1);
118
- if (expr === null || expr === void 0) return null;
119
- if (isFunctionObject(expr)) return expr.fn.slice(1);
120
- return null;
29
+ if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
30
+ return [];
121
31
  }
122
- function op(expr, n) {
32
+ function operand(expr, n) {
123
33
  if (Array.isArray(expr)) return expr[n] ?? null;
124
- if (expr === null || expr === void 0) return null;
125
- if (isFunctionObject(expr)) return expr.fn[n] ?? null;
126
- return null;
127
- }
128
- function op1(expr) {
129
- return op(expr, 1);
130
- }
131
- function op2(expr) {
132
- return op(expr, 2);
34
+ if (expr === null || !isFunctionObject(expr)) return null;
35
+ return expr.fn[n] ?? null;
133
36
  }
134
37
  function nops(expr) {
135
38
  if (expr === null || expr === void 0) return 0;
@@ -150,47 +53,31 @@ function symbol(expr) {
150
53
  return s;
151
54
  }
152
55
  function keyValuePair(expr) {
153
- const h = head(expr);
56
+ const h = operator(expr);
154
57
  if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
155
- const key = stringValue(op1(expr));
58
+ const [k, v] = operands(expr);
59
+ const key = stringValue(k);
156
60
  if (!key) return null;
157
- return [key, op2(expr) ?? "Nothing"];
61
+ return [key, v ?? "Nothing"];
158
62
  }
159
63
  return null;
160
64
  }
161
65
  function dictionary(expr) {
162
66
  if (expr === null) return null;
163
- if (typeof expr === "object" && "dict" in expr) return expr.dict;
164
67
  const kv = keyValuePair(expr);
165
68
  if (kv) return { [kv[0]]: kv[1] };
166
- const h = head(expr);
69
+ const h = operator(expr);
167
70
  if (h === "Dictionary") {
168
71
  const result = {};
72
+ const ops = operands(expr);
169
73
  for (let i = 1; i < nops(expr); i++) {
170
- const kv2 = keyValuePair(op(expr, i));
74
+ const kv2 = keyValuePair(ops[i]);
171
75
  if (kv2) result[kv2[0]] = kv2[1];
172
76
  }
173
77
  return result;
174
78
  }
175
79
  return null;
176
80
  }
177
- function applyRecursively(expr, fn) {
178
- const h = head(expr);
179
- if (h !== null) {
180
- return [
181
- fn(h),
182
- ...(ops(expr) ?? []).map(fn)
183
- ];
184
- }
185
- const dict = dictionary(expr);
186
- if (dict !== null) {
187
- const keys = Object.keys(dict);
188
- const result = {};
189
- for (const key of keys) result[key] = fn(dict[key]);
190
- return { dict: result };
191
- }
192
- return fn(expr);
193
- }
194
81
  function mapArgs(expr, fn) {
195
82
  let args = null;
196
83
  if (Array.isArray(expr)) args = expr;
@@ -206,20 +93,16 @@ function mapArgs(expr, fn) {
206
93
  }
207
94
 
208
95
  // src/math-json.ts
209
- var version = "0.25.1";
96
+ var version = "0.26.0";
210
97
  export {
211
- applyRecursively,
212
98
  dictionary as getDictionary,
213
99
  stringValue as getStringValue,
214
- head,
215
- headName,
216
- isDictionaryObject,
217
100
  isFunctionObject,
218
101
  isStringObject,
219
102
  isSymbolObject,
220
103
  mapArgs,
221
- nops,
222
- op,
104
+ operand,
105
+ operator,
223
106
  symbol,
224
107
  version
225
108
  };