@cortex-js/compute-engine 0.12.3 → 0.12.5

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 (89) hide show
  1. package/dist/compute-engine.esm.js +24382 -28195
  2. package/dist/compute-engine.js +24557 -0
  3. package/dist/compute-engine.min.esm.js +24540 -2
  4. package/dist/compute-engine.min.js +24553 -2
  5. package/dist/math-json.esm.js +256 -185
  6. package/dist/math-json.js +283 -0
  7. package/dist/math-json.min.esm.js +258 -2
  8. package/dist/math-json.min.js +283 -2
  9. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  10. package/dist/types/common/signals.d.ts +1 -1
  11. package/dist/types/common/utils.d.ts +1 -1
  12. package/dist/types/compute-engine/assume.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -1
  14. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -2
  17. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +4 -3
  19. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +2 -2
  20. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  26. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  27. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  28. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  29. package/dist/types/compute-engine/compute-engine.d.ts +4 -3
  30. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  31. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  32. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  33. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  34. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  35. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  36. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  37. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  38. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  39. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  40. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +25 -16
  43. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +15 -0
  45. package/dist/types/compute-engine/latex-syntax/parse.d.ts +31 -34
  46. package/dist/types/compute-engine/latex-syntax/public.d.ts +63 -66
  47. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +10 -6
  50. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -1
  51. package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -2
  52. package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
  53. package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +2 -2
  54. package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
  55. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  56. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  57. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  58. package/dist/types/compute-engine/library/core.d.ts +1 -1
  59. package/dist/types/compute-engine/library/domains.d.ts +1 -1
  60. package/dist/types/compute-engine/library/library.d.ts +1 -1
  61. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  62. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  63. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  64. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  65. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  66. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  67. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  68. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  69. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  70. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  71. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  72. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  73. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  74. package/dist/types/compute-engine/public.d.ts +17 -8
  75. package/dist/types/compute-engine/rules.d.ts +1 -1
  76. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  77. package/dist/types/compute-engine/solve.d.ts +1 -1
  78. package/dist/types/compute-engine/symbolic/expand.d.ts +18 -10
  79. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  80. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  81. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  82. package/dist/types/compute-engine/symbolic/product.d.ts +4 -1
  83. package/dist/types/compute-engine/symbolic/sum.d.ts +2 -1
  84. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  85. package/dist/types/compute-engine.d.ts +2 -2
  86. package/dist/types/math-json/math-json-format.d.ts +1 -1
  87. package/dist/types/math-json/utils.d.ts +4 -1
  88. package/dist/types/math-json.d.ts +2 -2
  89. package/package.json +5 -14
@@ -0,0 +1,283 @@
1
+ /** CortexJS MathJSON 0.12.5 */
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
+ applyRecursively: () => applyRecursively,
26
+ getDictionary: () => dictionary,
27
+ getStringValue: () => stringValue,
28
+ head: () => head,
29
+ headName: () => headName,
30
+ isDictionaryObject: () => isDictionaryObject,
31
+ isFunctionObject: () => isFunctionObject,
32
+ isStringObject: () => isStringObject,
33
+ isSymbolObject: () => isSymbolObject,
34
+ mapArgs: () => mapArgs,
35
+ nops: () => nops,
36
+ op: () => op,
37
+ symbol: () => symbol,
38
+ version: () => version
39
+ });
40
+
41
+ // src/math-json/utils.ts
42
+ function isSymbolObject(expr) {
43
+ return expr !== null && typeof expr === "object" && "sym" in expr;
44
+ }
45
+ function isStringObject(expr) {
46
+ return expr !== null && typeof expr === "object" && "str" in expr;
47
+ }
48
+ function isFunctionObject(expr) {
49
+ return expr !== null && typeof expr === "object" && "fn" in expr;
50
+ }
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))
97
+ return true;
98
+ if (ONLY_EMOJIS.test(s))
99
+ return true;
100
+ if (!isRecommendedScripts(s))
101
+ return false;
102
+ return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
103
+ }
104
+ var VS16 = "\\u{FE0F}";
105
+ var KEYCAP = "\\u{20E3}";
106
+ var ZWJ = "\\u{200D}";
107
+ var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
108
+ var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
109
+ var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
110
+ var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
111
+ var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
112
+ var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
113
+ var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
114
+ var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
115
+ function validateIdentifier(s) {
116
+ if (typeof s !== "string")
117
+ return "not-a-string";
118
+ if (s === "")
119
+ return "empty-string";
120
+ if (s.normalize() !== s)
121
+ return "expected-nfc";
122
+ if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
123
+ return "unexpected-bidi-marker";
124
+ if (ONLY_EMOJIS.test(s))
125
+ return "valid";
126
+ if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
127
+ return "unexpected-mixed-emoji";
128
+ if (!isRecommendedScripts(s))
129
+ return "unexpected-script";
130
+ if (!isValidIdentifier(s)) {
131
+ if (!isValidIdentifier(s[0]))
132
+ return "invalid-first-char";
133
+ return "invalid-char";
134
+ }
135
+ return "valid";
136
+ }
137
+ function stringValue(expr) {
138
+ if (expr === null || expr === void 0)
139
+ return null;
140
+ if (typeof expr === "object" && "str" in expr)
141
+ return expr.str;
142
+ if (typeof expr !== "string")
143
+ return null;
144
+ if (expr.length < 2)
145
+ return null;
146
+ if (expr[0] !== "'" || expr[expr.length - 1] !== "'")
147
+ return null;
148
+ return expr.substring(1, expr.length - 1);
149
+ }
150
+ function head(expr) {
151
+ if (expr === null || expr === void 0)
152
+ return null;
153
+ if (Array.isArray(expr)) {
154
+ if (typeof expr[0] === "string" && !isValidIdentifier(expr[0])) {
155
+ console.error(
156
+ `Invalid identifier "${expr[0]}": ${validateIdentifier(expr[0])}`
157
+ );
158
+ return null;
159
+ }
160
+ return expr[0];
161
+ }
162
+ if (isFunctionObject(expr))
163
+ return expr.fn[0];
164
+ return null;
165
+ }
166
+ function headName(expr) {
167
+ const h = head(expr);
168
+ return typeof h === "string" ? h : "";
169
+ }
170
+ function ops(expr) {
171
+ if (expr === null || expr === void 0)
172
+ return null;
173
+ if (Array.isArray(expr))
174
+ return expr.slice(1);
175
+ if (isFunctionObject(expr))
176
+ return expr.fn.slice(1);
177
+ return null;
178
+ }
179
+ function op(expr, n) {
180
+ if (expr === null || expr === void 0)
181
+ return null;
182
+ if (Array.isArray(expr))
183
+ return expr[n] ?? null;
184
+ if (isFunctionObject(expr))
185
+ return expr.fn[n] ?? null;
186
+ return null;
187
+ }
188
+ function op1(expr) {
189
+ return op(expr, 1);
190
+ }
191
+ function op2(expr) {
192
+ return op(expr, 2);
193
+ }
194
+ function nops(expr) {
195
+ if (expr === null || expr === void 0)
196
+ return 0;
197
+ if (Array.isArray(expr))
198
+ return Math.max(0, expr.length - 1);
199
+ if (isFunctionObject(expr))
200
+ return Math.max(0, expr.fn.length - 1);
201
+ return 0;
202
+ }
203
+ function symbol(expr) {
204
+ if (expr === null || expr === void 0)
205
+ return null;
206
+ if (typeof expr === "string") {
207
+ if (/^[+\-\.0-9]/.test(expr))
208
+ return null;
209
+ if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
210
+ return null;
211
+ }
212
+ const s = isSymbolObject(expr) ? expr.sym : expr;
213
+ if (typeof s !== "string")
214
+ return null;
215
+ return s;
216
+ }
217
+ function keyValuePair(expr) {
218
+ const h = head(expr);
219
+ if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
220
+ const key = stringValue(op1(expr));
221
+ if (!key)
222
+ return null;
223
+ return [key, op2(expr) ?? "Nothing"];
224
+ }
225
+ return null;
226
+ }
227
+ function dictionary(expr) {
228
+ if (expr === null)
229
+ return null;
230
+ if (typeof expr === "object" && "dict" in expr)
231
+ return expr.dict;
232
+ const kv = keyValuePair(expr);
233
+ if (kv)
234
+ return { [kv[0]]: kv[1] };
235
+ const h = head(expr);
236
+ if (h === "Dictionary") {
237
+ const result = {};
238
+ for (let i = 1; i < nops(expr); i++) {
239
+ const kv2 = keyValuePair(op(expr, i));
240
+ if (kv2)
241
+ result[kv2[0]] = kv2[1];
242
+ }
243
+ return result;
244
+ }
245
+ return null;
246
+ }
247
+ function applyRecursively(expr, fn) {
248
+ const h = head(expr);
249
+ if (h !== null) {
250
+ return [fn(h), ...(ops(expr) ?? []).map(fn)];
251
+ }
252
+ const dict = dictionary(expr);
253
+ if (dict !== null) {
254
+ const keys = Object.keys(dict);
255
+ const result = {};
256
+ for (const key of keys)
257
+ result[key] = fn(dict[key]);
258
+ return { dict: result };
259
+ }
260
+ return fn(expr);
261
+ }
262
+ function mapArgs(expr, fn) {
263
+ let args = null;
264
+ if (Array.isArray(expr))
265
+ args = expr;
266
+ if (isFunctionObject(expr))
267
+ args = expr.fn;
268
+ if (args === null)
269
+ return [];
270
+ let i = 1;
271
+ const result = [];
272
+ while (i < args.length) {
273
+ result.push(fn(args[i]));
274
+ i += 1;
275
+ }
276
+ return result;
277
+ }
278
+
279
+ // src/math-json.ts
280
+ var version = "0.12.5";
281
+ return __toCommonJS(math_json_exports);
282
+ })();
283
+ Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
@@ -1,2 +1,258 @@
1
- /** MathJSON 0.12.3 */
2
- function n(n){return null!==n&&"object"==typeof n&&"sym"in n}function t(n){return null!==n&&"object"==typeof n&&"str"in n}function r(n){return null!==n&&"object"==typeof n&&"fn"in n}function u(n){return null!==n&&"object"==typeof n&&"dict"in n}function l(n){return null==n?null:"object"==typeof n&&"str"in n?n.str:"string"!=typeof n||n.length<2||"'"!==n[0]||"'"!==n[n.length-1]?null:n.substring(1,n.length-1)}function e(n){return null==n?null:Array.isArray(n)?n[0]:r(n)?n.fn[0]:null}function i(n){const t=e(n);return"string"==typeof t?t:""}function o(n){return null==n?null:Array.isArray(n)?n.slice(1):r(n)?n.fn.slice(1):null}function f(n,t){return null==n?null:Array.isArray(n)?n[t]??null:r(n)?n.fn[t]??null:null}function c(n){return f(n,2)}function s(n){return null==n?0:Array.isArray(n)?Math.max(0,n.length-1):r(n)?Math.max(0,n.fn.length-1):0}function y(t){if(null==t)return null;if("string"==typeof t){if(/^[+\-\.0-9]/.test(t))return null;if(t.length>=2&&"'"===t[0]&&"'"===t[t.length-1])return null}const r=n(t)?t.sym:t;return"string"!=typeof r?null:r}function a(n){const t=e(n);if("KeyValuePair"===t||"Tuple"===t||"Pair"===t){const t=l(function(n){return f(n,1)}(n));return t?[t,c(n)??"Nothing"]:null}return null}function g(n){if(null===n)return null;if("object"==typeof n&&"dict"in n)return n.dict;const t=a(n);if(t)return{[t[0]]:t[1]};if("Dictionary"===e(n)){const t={};for(let r=1;r<s(n);r++){const u=a(f(n,r));u&&(t[u[0]]=u[1])}return t}return null}function p(n,t){const r=e(n);if(null!==r)return[t(r),...(o(n)??[]).map(t)];const u=g(n);if(null!==u){const n=Object.keys(u),r={};for(const l of n)r[l]=t(u[l]);return{dict:r}}return t(n)}function h(n,t){let u=null;if(Array.isArray(n)&&(u=n),r(n)&&(u=n.fn),null===u)return[];let l=1;const e=[];for(;l<u.length;)e.push(t(u[l])),l+=1;return e}const A="0.12.3";export{p as applyRecursively,g as getDictionary,l as getStringValue,e as head,i as headName,u as isDictionaryObject,r as isFunctionObject,t as isStringObject,n as isSymbolObject,h as mapArgs,s as nops,f as op,y as symbol,A as version};
1
+ /** CortexJS Compute Engine 0.12.5 */
2
+
3
+ // src/math-json/utils.ts
4
+ function isSymbolObject(expr) {
5
+ return expr !== null && typeof expr === "object" && "sym" in expr;
6
+ }
7
+ function isStringObject(expr) {
8
+ return expr !== null && typeof expr === "object" && "str" in expr;
9
+ }
10
+ function isFunctionObject(expr) {
11
+ return expr !== null && typeof expr === "object" && "fn" in expr;
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))
59
+ return true;
60
+ if (ONLY_EMOJIS.test(s))
61
+ return true;
62
+ if (!isRecommendedScripts(s))
63
+ return false;
64
+ return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
65
+ }
66
+ var VS16 = "\\u{FE0F}";
67
+ var KEYCAP = "\\u{20E3}";
68
+ var ZWJ = "\\u{200D}";
69
+ var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
70
+ var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
71
+ var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
72
+ var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
73
+ var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
74
+ var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
75
+ var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
76
+ var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
77
+ function validateIdentifier(s) {
78
+ if (typeof s !== "string")
79
+ return "not-a-string";
80
+ if (s === "")
81
+ return "empty-string";
82
+ if (s.normalize() !== s)
83
+ return "expected-nfc";
84
+ if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
85
+ return "unexpected-bidi-marker";
86
+ if (ONLY_EMOJIS.test(s))
87
+ return "valid";
88
+ if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
89
+ return "unexpected-mixed-emoji";
90
+ if (!isRecommendedScripts(s))
91
+ return "unexpected-script";
92
+ if (!isValidIdentifier(s)) {
93
+ if (!isValidIdentifier(s[0]))
94
+ return "invalid-first-char";
95
+ return "invalid-char";
96
+ }
97
+ return "valid";
98
+ }
99
+ function stringValue(expr) {
100
+ if (expr === null || expr === void 0)
101
+ return null;
102
+ if (typeof expr === "object" && "str" in expr)
103
+ return expr.str;
104
+ if (typeof expr !== "string")
105
+ return null;
106
+ if (expr.length < 2)
107
+ return null;
108
+ if (expr[0] !== "'" || expr[expr.length - 1] !== "'")
109
+ return null;
110
+ return expr.substring(1, expr.length - 1);
111
+ }
112
+ function head(expr) {
113
+ if (expr === null || expr === void 0)
114
+ return null;
115
+ if (Array.isArray(expr)) {
116
+ if (typeof expr[0] === "string" && !isValidIdentifier(expr[0])) {
117
+ console.error(
118
+ `Invalid identifier "${expr[0]}": ${validateIdentifier(expr[0])}`
119
+ );
120
+ return null;
121
+ }
122
+ return expr[0];
123
+ }
124
+ if (isFunctionObject(expr))
125
+ return expr.fn[0];
126
+ return null;
127
+ }
128
+ function headName(expr) {
129
+ const h = head(expr);
130
+ return typeof h === "string" ? h : "";
131
+ }
132
+ function ops(expr) {
133
+ if (expr === null || expr === void 0)
134
+ return null;
135
+ if (Array.isArray(expr))
136
+ return expr.slice(1);
137
+ if (isFunctionObject(expr))
138
+ return expr.fn.slice(1);
139
+ return null;
140
+ }
141
+ function op(expr, n) {
142
+ if (expr === null || expr === void 0)
143
+ return null;
144
+ if (Array.isArray(expr))
145
+ return expr[n] ?? null;
146
+ if (isFunctionObject(expr))
147
+ return expr.fn[n] ?? null;
148
+ return null;
149
+ }
150
+ function op1(expr) {
151
+ return op(expr, 1);
152
+ }
153
+ function op2(expr) {
154
+ return op(expr, 2);
155
+ }
156
+ function nops(expr) {
157
+ if (expr === null || expr === void 0)
158
+ return 0;
159
+ if (Array.isArray(expr))
160
+ return Math.max(0, expr.length - 1);
161
+ if (isFunctionObject(expr))
162
+ return Math.max(0, expr.fn.length - 1);
163
+ return 0;
164
+ }
165
+ function symbol(expr) {
166
+ if (expr === null || expr === void 0)
167
+ return null;
168
+ if (typeof expr === "string") {
169
+ if (/^[+\-\.0-9]/.test(expr))
170
+ return null;
171
+ if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
172
+ return null;
173
+ }
174
+ const s = isSymbolObject(expr) ? expr.sym : expr;
175
+ if (typeof s !== "string")
176
+ return null;
177
+ return s;
178
+ }
179
+ function keyValuePair(expr) {
180
+ const h = head(expr);
181
+ if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
182
+ const key = stringValue(op1(expr));
183
+ if (!key)
184
+ return null;
185
+ return [key, op2(expr) ?? "Nothing"];
186
+ }
187
+ return null;
188
+ }
189
+ function dictionary(expr) {
190
+ if (expr === null)
191
+ return null;
192
+ if (typeof expr === "object" && "dict" in expr)
193
+ return expr.dict;
194
+ const kv = keyValuePair(expr);
195
+ if (kv)
196
+ return { [kv[0]]: kv[1] };
197
+ const h = head(expr);
198
+ if (h === "Dictionary") {
199
+ const result = {};
200
+ for (let i = 1; i < nops(expr); i++) {
201
+ const kv2 = keyValuePair(op(expr, i));
202
+ if (kv2)
203
+ result[kv2[0]] = kv2[1];
204
+ }
205
+ return result;
206
+ }
207
+ return null;
208
+ }
209
+ function applyRecursively(expr, fn) {
210
+ const h = head(expr);
211
+ if (h !== null) {
212
+ return [fn(h), ...(ops(expr) ?? []).map(fn)];
213
+ }
214
+ const dict = dictionary(expr);
215
+ if (dict !== null) {
216
+ const keys = Object.keys(dict);
217
+ const result = {};
218
+ for (const key of keys)
219
+ result[key] = fn(dict[key]);
220
+ return { dict: result };
221
+ }
222
+ return fn(expr);
223
+ }
224
+ function mapArgs(expr, fn) {
225
+ let args = null;
226
+ if (Array.isArray(expr))
227
+ args = expr;
228
+ if (isFunctionObject(expr))
229
+ args = expr.fn;
230
+ if (args === null)
231
+ return [];
232
+ let i = 1;
233
+ const result = [];
234
+ while (i < args.length) {
235
+ result.push(fn(args[i]));
236
+ i += 1;
237
+ }
238
+ return result;
239
+ }
240
+
241
+ // src/math-json.ts
242
+ var version = "0.12.5";
243
+ export {
244
+ applyRecursively,
245
+ dictionary as getDictionary,
246
+ stringValue as getStringValue,
247
+ head,
248
+ headName,
249
+ isDictionaryObject,
250
+ isFunctionObject,
251
+ isStringObject,
252
+ isSymbolObject,
253
+ mapArgs,
254
+ nops,
255
+ op,
256
+ symbol,
257
+ version
258
+ };