@math.gl/core 5.0.0-alpha.17 → 5.0.0-alpha.19

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 (148) hide show
  1. package/README.md +4 -0
  2. package/dist/classes/base/math-array.d.ts +1 -1
  3. package/dist/classes/base/math-array.d.ts.map +1 -1
  4. package/dist/classes/base/matrix.d.ts +1 -1
  5. package/dist/classes/base/matrix.d.ts.map +1 -1
  6. package/dist/classes/base/vector.d.ts +1 -1
  7. package/dist/classes/base/vector.d.ts.map +1 -1
  8. package/dist/classes/euler.d.ts +1 -1
  9. package/dist/classes/euler.d.ts.map +1 -1
  10. package/dist/classes/matrix3.d.ts +1 -1
  11. package/dist/classes/matrix3.d.ts.map +1 -1
  12. package/dist/classes/matrix4.d.ts +1 -1
  13. package/dist/classes/matrix4.d.ts.map +1 -1
  14. package/dist/classes/pose.d.ts +1 -1
  15. package/dist/classes/pose.d.ts.map +1 -1
  16. package/dist/classes/quaternion.d.ts +1 -1
  17. package/dist/classes/quaternion.d.ts.map +1 -1
  18. package/dist/classes/vector2.d.ts +1 -1
  19. package/dist/classes/vector2.d.ts.map +1 -1
  20. package/dist/classes/vector3.d.ts +1 -1
  21. package/dist/classes/vector3.d.ts.map +1 -1
  22. package/dist/classes/vector4.d.ts +1 -1
  23. package/dist/classes/vector4.d.ts.map +1 -1
  24. package/dist/expressions/expression-eval.d.ts +98 -0
  25. package/dist/expressions/expression-eval.d.ts.map +1 -0
  26. package/dist/expressions/expression-eval.js +302 -0
  27. package/dist/expressions/expression-eval.js.map +1 -0
  28. package/dist/expressions/function-libraries.d.ts +60 -0
  29. package/dist/expressions/function-libraries.d.ts.map +1 -0
  30. package/dist/expressions/function-libraries.js +69 -0
  31. package/dist/expressions/function-libraries.js.map +1 -0
  32. package/dist/expressions/function-registry.d.ts +93 -0
  33. package/dist/expressions/function-registry.d.ts.map +1 -0
  34. package/dist/expressions/function-registry.js +131 -0
  35. package/dist/expressions/function-registry.js.map +1 -0
  36. package/dist/expressions/get.d.ts +9 -0
  37. package/dist/expressions/get.d.ts.map +1 -0
  38. package/dist/expressions/get.js +32 -0
  39. package/dist/expressions/get.js.map +1 -0
  40. package/dist/expressions/index.cjs +1483 -0
  41. package/dist/expressions/index.cjs.map +6 -0
  42. package/dist/expressions/index.d.ts +7 -0
  43. package/dist/expressions/index.d.ts.map +1 -0
  44. package/dist/expressions/index.js +8 -0
  45. package/dist/expressions/index.js.map +1 -0
  46. package/dist/expressions/parse-expression-string.d.ts +21 -0
  47. package/dist/expressions/parse-expression-string.d.ts.map +1 -0
  48. package/dist/expressions/parse-expression-string.js +61 -0
  49. package/dist/expressions/parse-expression-string.js.map +1 -0
  50. package/dist/expressions/vendor/jsep/runtime.d.ts +3 -0
  51. package/dist/expressions/vendor/jsep/runtime.d.ts.map +1 -0
  52. package/dist/expressions/vendor/jsep/runtime.js +972 -0
  53. package/dist/expressions/vendor/jsep/runtime.js.map +1 -0
  54. package/dist/expressions/vendor/jsep/types.d.ts +141 -0
  55. package/dist/expressions/vendor/jsep/types.d.ts.map +1 -0
  56. package/dist/expressions/vendor/jsep/types.js +4 -0
  57. package/dist/expressions/vendor/jsep/types.js.map +1 -0
  58. package/dist/gl-matrix/common.d.ts +1 -1
  59. package/dist/gl-matrix/vec2.d.ts +1 -1
  60. package/dist/gl-matrix/vec2.d.ts.map +1 -1
  61. package/dist/index.d.ts +3 -3
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/lib/common.d.ts +1 -1
  64. package/dist/lib/common.d.ts.map +1 -1
  65. package/dist/lib/gl-matrix-extras.d.ts +1 -1
  66. package/dist/lib/gl-matrix-extras.d.ts.map +1 -1
  67. package/dist/lib/validators.d.ts +1 -1
  68. package/dist/lib/validators.d.ts.map +1 -1
  69. package/dist/local-frame.d.ts +1 -1
  70. package/dist/local-frame.d.ts.map +1 -1
  71. package/dist/spheroid.d.ts +1 -1
  72. package/dist/spheroid.d.ts.map +1 -1
  73. package/dist/types/array-types.d.ts +98 -0
  74. package/dist/types/array-types.d.ts.map +1 -0
  75. package/dist/types/array-types.js +6 -0
  76. package/dist/types/array-types.js.map +1 -0
  77. package/dist/types/bigint.d.ts +21 -0
  78. package/dist/types/bigint.d.ts.map +1 -0
  79. package/dist/types/bigint.js +48 -0
  80. package/dist/types/bigint.js.map +1 -0
  81. package/dist/types/bounds-types.d.ts +11 -0
  82. package/dist/types/bounds-types.d.ts.map +1 -0
  83. package/dist/types/bounds-types.js +17 -0
  84. package/dist/types/bounds-types.js.map +1 -0
  85. package/dist/types/float16.d.ts +32 -0
  86. package/dist/types/float16.d.ts.map +1 -0
  87. package/dist/types/float16.js +41 -0
  88. package/dist/types/float16.js.map +1 -0
  89. package/dist/types/index.d.ts +6 -0
  90. package/dist/types/index.d.ts.map +1 -0
  91. package/dist/types/index.js +6 -0
  92. package/dist/types/index.js.map +1 -0
  93. package/dist/types/is-array.d.ts +22 -0
  94. package/dist/types/is-array.d.ts.map +1 -0
  95. package/dist/types/is-array.js +36 -0
  96. package/dist/types/is-array.js.map +1 -0
  97. package/dist/types/spheroid.d.ts +8 -0
  98. package/dist/types/spheroid.d.ts.map +1 -0
  99. package/dist/types/spheroid.js +5 -0
  100. package/dist/types/spheroid.js.map +1 -0
  101. package/dist/types/typed-array-brand.d.ts +2 -0
  102. package/dist/types/typed-array-brand.d.ts.map +1 -0
  103. package/dist/types/typed-array-brand.js +10 -0
  104. package/dist/types/typed-array-brand.js.map +1 -0
  105. package/dist/types.cjs +67 -0
  106. package/dist/types.cjs.map +6 -0
  107. package/dist/types.d.ts +2 -0
  108. package/dist/types.d.ts.map +1 -0
  109. package/dist/types.js +5 -0
  110. package/dist/types.js.map +1 -0
  111. package/package.json +12 -5
  112. package/src/classes/base/math-array.ts +1 -1
  113. package/src/classes/base/matrix.ts +1 -1
  114. package/src/classes/base/vector.ts +1 -1
  115. package/src/classes/euler.ts +1 -1
  116. package/src/classes/matrix3.ts +1 -1
  117. package/src/classes/matrix4.ts +1 -1
  118. package/src/classes/pose.ts +1 -1
  119. package/src/classes/quaternion.ts +1 -1
  120. package/src/classes/vector2.ts +1 -1
  121. package/src/classes/vector3.ts +1 -1
  122. package/src/classes/vector4.ts +1 -1
  123. package/src/expressions/expression-eval.ts +435 -0
  124. package/src/expressions/function-libraries.ts +123 -0
  125. package/src/expressions/function-registry.ts +163 -0
  126. package/src/expressions/get.ts +37 -0
  127. package/src/expressions/index.ts +22 -0
  128. package/src/expressions/parse-expression-string.ts +80 -0
  129. package/src/expressions/vendor/jsep/LICENSE.txt +23 -0
  130. package/src/expressions/vendor/jsep/README.md +22 -0
  131. package/src/expressions/vendor/jsep/runtime.ts +949 -0
  132. package/src/expressions/vendor/jsep/types.ts +179 -0
  133. package/src/gl-matrix/vec2.ts +1 -1
  134. package/src/index.ts +3 -3
  135. package/src/lib/common.ts +1 -1
  136. package/src/lib/gl-matrix-extras.ts +1 -1
  137. package/src/lib/validators.ts +1 -1
  138. package/src/local-frame.ts +1 -1
  139. package/src/spheroid.ts +1 -1
  140. package/src/types/array-types.ts +148 -0
  141. package/src/types/bigint.ts +56 -0
  142. package/src/types/bounds-types.ts +29 -0
  143. package/src/types/float16.ts +47 -0
  144. package/src/types/index.ts +45 -0
  145. package/src/types/is-array.ts +41 -0
  146. package/src/types/spheroid.ts +11 -0
  147. package/src/types/typed-array-brand.ts +14 -0
  148. package/src/types.ts +5 -0
@@ -0,0 +1,1483 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/expressions/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ BASIC_MATH_FUNCTION_LIBRARY: () => BASIC_MATH_FUNCTION_LIBRARY,
23
+ ExpressionFunctionRegistry: () => ExpressionFunctionRegistry,
24
+ addBinaryOp: () => addBinaryOp,
25
+ addUnaryOp: () => addUnaryOp,
26
+ compile: () => compile,
27
+ compileAsync: () => compileAsync,
28
+ eval: () => evaluateExpression,
29
+ evalAsync: () => evalAsync,
30
+ mergeFunctionLibraries: () => mergeFunctionLibraries,
31
+ parse: () => parse,
32
+ parseExpressionString: () => parseExpressionString
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // dist/expressions/function-registry.js
37
+ var FUNCTION_NAME_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
38
+ var DISALLOWED_FUNCTION_NAMES = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
39
+ var ExpressionFunctionRegistry = class {
40
+ /**
41
+ * Creates a function registry.
42
+ *
43
+ * @param functionTables - Function tables to register in order.
44
+ * @throws If a table contains an invalid or duplicate function name.
45
+ */
46
+ constructor(functionTables = []) {
47
+ this.functions = /* @__PURE__ */ Object.create(null);
48
+ for (const functionTable of functionTables) {
49
+ this.registerFunctions(functionTable);
50
+ }
51
+ }
52
+ /**
53
+ * Registers one named function.
54
+ *
55
+ * @param name - Identifier used to call the function from an expression.
56
+ * @param fn - JavaScript function invoked with evaluated expression arguments.
57
+ * @param options - Duplicate registration behavior.
58
+ * @returns This registry.
59
+ * @throws If the name is invalid, the value is not a function, or the name is
60
+ * already registered and replacement was not requested.
61
+ */
62
+ registerFunction(name, fn, options = {}) {
63
+ validateFunction(name, fn);
64
+ if (this.hasFunction(name) && !options.replace) {
65
+ throw new Error(`Expression function "${name}" is already registered.`);
66
+ }
67
+ this.functions[name] = fn;
68
+ return this;
69
+ }
70
+ /**
71
+ * Registers all entries in a function table.
72
+ *
73
+ * @param functionTable - Map from expression identifiers to JavaScript functions.
74
+ * @param options - Duplicate registration behavior.
75
+ * @returns This registry.
76
+ * @throws If any entry is invalid or conflicts with an existing registration.
77
+ *
78
+ * @remarks
79
+ * Validation is atomic: no entries are registered when any entry is invalid.
80
+ */
81
+ registerFunctions(functionTable, options = {}) {
82
+ const entries = Object.entries(functionTable);
83
+ const names = /* @__PURE__ */ new Set();
84
+ for (const [name, fn] of entries) {
85
+ validateFunction(name, fn);
86
+ if (names.has(name) || this.hasFunction(name) && !options.replace) {
87
+ throw new Error(`Expression function "${name}" is already registered.`);
88
+ }
89
+ names.add(name);
90
+ }
91
+ for (const [name, fn] of entries) {
92
+ this.functions[name] = fn;
93
+ }
94
+ return this;
95
+ }
96
+ /**
97
+ * Removes a registered function.
98
+ *
99
+ * @param name - Function name to remove.
100
+ * @returns `true` when a function was removed.
101
+ */
102
+ unregisterFunction(name) {
103
+ if (!this.hasFunction(name)) {
104
+ return false;
105
+ }
106
+ return delete this.functions[name];
107
+ }
108
+ /**
109
+ * Tests whether a function is registered.
110
+ *
111
+ * @param name - Function name to inspect.
112
+ * @returns `true` when the registry contains the name.
113
+ */
114
+ hasFunction(name) {
115
+ return Object.prototype.hasOwnProperty.call(this.functions, name);
116
+ }
117
+ /**
118
+ * Returns a registered function.
119
+ *
120
+ * @param name - Function name to retrieve.
121
+ * @returns The registered function, or `undefined`.
122
+ */
123
+ getFunction(name) {
124
+ return this.functions[name];
125
+ }
126
+ /**
127
+ * Returns an immutable snapshot of all registered functions.
128
+ *
129
+ * @returns A frozen function table.
130
+ */
131
+ getFunctionTable() {
132
+ return Object.freeze({ ...this.functions });
133
+ }
134
+ };
135
+ function validateFunction(name, fn) {
136
+ if (!FUNCTION_NAME_PATTERN.test(name) || DISALLOWED_FUNCTION_NAMES.has(name)) {
137
+ throw new Error(`Invalid expression function name "${name}".`);
138
+ }
139
+ if (typeof fn !== "function") {
140
+ throw new TypeError(`Expression function "${name}" must be a function.`);
141
+ }
142
+ }
143
+
144
+ // dist/expressions/vendor/jsep/runtime.js
145
+ var Hooks = class {
146
+ /**
147
+ * @callback HookCallback
148
+ * @this {*|Jsep} this
149
+ * @param {Jsep} env
150
+ * @returns: void
151
+ */
152
+ /**
153
+ * Adds the given callback to the list of callbacks for the given hook.
154
+ *
155
+ * The callback will be invoked when the hook it is registered for is run.
156
+ *
157
+ * One callback function can be registered to multiple hooks and the same hook multiple times.
158
+ *
159
+ * @param {string|object} name The name of the hook, or an object of callbacks keyed by name
160
+ * @param {HookCallback|boolean} callback The callback function which is given environment variables.
161
+ * @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)
162
+ * @public
163
+ */
164
+ add(name, callback, first) {
165
+ if (typeof arguments[0] != "string") {
166
+ for (let name2 in arguments[0]) {
167
+ this.add(name2, arguments[0][name2], arguments[1]);
168
+ }
169
+ } else {
170
+ (Array.isArray(name) ? name : [name]).forEach(function(name2) {
171
+ this[name2] = this[name2] || [];
172
+ if (callback) {
173
+ this[name2][first ? "unshift" : "push"](callback);
174
+ }
175
+ }, this);
176
+ }
177
+ }
178
+ /**
179
+ * Runs a hook invoking all registered callbacks with the given environment variables.
180
+ *
181
+ * Callbacks will be invoked synchronously and in the order in which they were registered.
182
+ *
183
+ * @param {string} name The name of the hook.
184
+ * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
185
+ * @public
186
+ */
187
+ run(name, env) {
188
+ this[name] = this[name] || [];
189
+ this[name].forEach(function(callback) {
190
+ callback.call(env && env.context ? env.context : env, env);
191
+ });
192
+ }
193
+ };
194
+ var Plugins = class {
195
+ constructor(jsep22) {
196
+ this.jsep = jsep22;
197
+ this.registered = {};
198
+ }
199
+ /**
200
+ * @callback PluginSetup
201
+ * @this {Jsep} jsep
202
+ * @returns: void
203
+ */
204
+ /**
205
+ * Adds the given plugin(s) to the registry
206
+ *
207
+ * @param {object} plugins
208
+ * @param {string} plugins.name The name of the plugin
209
+ * @param {PluginSetup} plugins.init The init function
210
+ * @public
211
+ */
212
+ register(...plugins) {
213
+ plugins.forEach((plugin) => {
214
+ if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
215
+ throw new Error("Invalid JSEP plugin format");
216
+ }
217
+ if (this.registered[plugin.name]) {
218
+ return;
219
+ }
220
+ plugin.init(this.jsep);
221
+ this.registered[plugin.name] = plugin;
222
+ });
223
+ }
224
+ };
225
+ var Jsep = class _Jsep {
226
+ /**
227
+ * @returns {string}
228
+ */
229
+ static get version() {
230
+ return "1.4.0";
231
+ }
232
+ /**
233
+ * @returns {string}
234
+ */
235
+ static toString() {
236
+ return "JavaScript Expression Parser (JSEP) v" + _Jsep.version;
237
+ }
238
+ // ==================== CONFIG ================================
239
+ /**
240
+ * @method addUnaryOp
241
+ * @param {string} op_name The name of the unary op to add
242
+ * @returns {Jsep}
243
+ */
244
+ static addUnaryOp(op_name) {
245
+ _Jsep.max_unop_len = Math.max(op_name.length, _Jsep.max_unop_len);
246
+ _Jsep.unary_ops[op_name] = 1;
247
+ return _Jsep;
248
+ }
249
+ /**
250
+ * @method jsep.addBinaryOp
251
+ * @param {string} op_name The name of the binary op to add
252
+ * @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence
253
+ * @param {boolean} [isRightAssociative=false] whether operator is right-associative
254
+ * @returns {Jsep}
255
+ */
256
+ static addBinaryOp(op_name, precedence, isRightAssociative) {
257
+ _Jsep.max_binop_len = Math.max(op_name.length, _Jsep.max_binop_len);
258
+ _Jsep.binary_ops[op_name] = precedence;
259
+ if (isRightAssociative) {
260
+ _Jsep.right_associative.add(op_name);
261
+ } else {
262
+ _Jsep.right_associative.delete(op_name);
263
+ }
264
+ return _Jsep;
265
+ }
266
+ /**
267
+ * @method addIdentifierChar
268
+ * @param {string} char The additional character to treat as a valid part of an identifier
269
+ * @returns {Jsep}
270
+ */
271
+ static addIdentifierChar(char) {
272
+ _Jsep.additional_identifier_chars.add(char);
273
+ return _Jsep;
274
+ }
275
+ /**
276
+ * @method addLiteral
277
+ * @param {string} literal_name The name of the literal to add
278
+ * @param {*} literal_value The value of the literal
279
+ * @returns {Jsep}
280
+ */
281
+ static addLiteral(literal_name, literal_value) {
282
+ _Jsep.literals[literal_name] = literal_value;
283
+ return _Jsep;
284
+ }
285
+ /**
286
+ * @method removeUnaryOp
287
+ * @param {string} op_name The name of the unary op to remove
288
+ * @returns {Jsep}
289
+ */
290
+ static removeUnaryOp(op_name) {
291
+ delete _Jsep.unary_ops[op_name];
292
+ if (op_name.length === _Jsep.max_unop_len) {
293
+ _Jsep.max_unop_len = _Jsep.getMaxKeyLen(_Jsep.unary_ops);
294
+ }
295
+ return _Jsep;
296
+ }
297
+ /**
298
+ * @method removeAllUnaryOps
299
+ * @returns {Jsep}
300
+ */
301
+ static removeAllUnaryOps() {
302
+ _Jsep.unary_ops = {};
303
+ _Jsep.max_unop_len = 0;
304
+ return _Jsep;
305
+ }
306
+ /**
307
+ * @method removeIdentifierChar
308
+ * @param {string} char The additional character to stop treating as a valid part of an identifier
309
+ * @returns {Jsep}
310
+ */
311
+ static removeIdentifierChar(char) {
312
+ _Jsep.additional_identifier_chars.delete(char);
313
+ return _Jsep;
314
+ }
315
+ /**
316
+ * @method removeBinaryOp
317
+ * @param {string} op_name The name of the binary op to remove
318
+ * @returns {Jsep}
319
+ */
320
+ static removeBinaryOp(op_name) {
321
+ delete _Jsep.binary_ops[op_name];
322
+ if (op_name.length === _Jsep.max_binop_len) {
323
+ _Jsep.max_binop_len = _Jsep.getMaxKeyLen(_Jsep.binary_ops);
324
+ }
325
+ _Jsep.right_associative.delete(op_name);
326
+ return _Jsep;
327
+ }
328
+ /**
329
+ * @method removeAllBinaryOps
330
+ * @returns {Jsep}
331
+ */
332
+ static removeAllBinaryOps() {
333
+ _Jsep.binary_ops = {};
334
+ _Jsep.max_binop_len = 0;
335
+ return _Jsep;
336
+ }
337
+ /**
338
+ * @method removeLiteral
339
+ * @param {string} literal_name The name of the literal to remove
340
+ * @returns {Jsep}
341
+ */
342
+ static removeLiteral(literal_name) {
343
+ delete _Jsep.literals[literal_name];
344
+ return _Jsep;
345
+ }
346
+ /**
347
+ * @method removeAllLiterals
348
+ * @returns {Jsep}
349
+ */
350
+ static removeAllLiterals() {
351
+ _Jsep.literals = {};
352
+ return _Jsep;
353
+ }
354
+ // ==================== END CONFIG ============================
355
+ /**
356
+ * @returns {string}
357
+ */
358
+ get char() {
359
+ return this.expr.charAt(this.index);
360
+ }
361
+ /**
362
+ * @returns {number}
363
+ */
364
+ get code() {
365
+ return this.expr.charCodeAt(this.index);
366
+ }
367
+ /**
368
+ * @param {string} expr a string with the passed in express
369
+ * @returns Jsep
370
+ */
371
+ constructor(expr) {
372
+ this.expr = expr;
373
+ this.index = 0;
374
+ }
375
+ /**
376
+ * static top-level parser
377
+ * @returns {jsep.Expression}
378
+ */
379
+ static parse(expr) {
380
+ return new _Jsep(expr).parse();
381
+ }
382
+ /**
383
+ * Get the longest key length of any object
384
+ * @param {object} obj
385
+ * @returns {number}
386
+ */
387
+ static getMaxKeyLen(obj) {
388
+ return Math.max(0, ...Object.keys(obj).map((k) => k.length));
389
+ }
390
+ /**
391
+ * `ch` is a character code in the next three functions
392
+ * @param {number} ch
393
+ * @returns {boolean}
394
+ */
395
+ static isDecimalDigit(ch) {
396
+ return ch >= 48 && ch <= 57;
397
+ }
398
+ /**
399
+ * Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.
400
+ * @param {string} op_val
401
+ * @returns {number}
402
+ */
403
+ static binaryPrecedence(op_val) {
404
+ return _Jsep.binary_ops[op_val] || 0;
405
+ }
406
+ /**
407
+ * Looks for start of identifier
408
+ * @param {number} ch
409
+ * @returns {boolean}
410
+ */
411
+ static isIdentifierStart(ch) {
412
+ return ch >= 65 && ch <= 90 || // A...Z
413
+ ch >= 97 && ch <= 122 || // a...z
414
+ ch >= 128 && !_Jsep.binary_ops[String.fromCharCode(ch)] || // any non-ASCII that is not an operator
415
+ _Jsep.additional_identifier_chars.has(String.fromCharCode(ch));
416
+ }
417
+ /**
418
+ * @param {number} ch
419
+ * @returns {boolean}
420
+ */
421
+ static isIdentifierPart(ch) {
422
+ return _Jsep.isIdentifierStart(ch) || _Jsep.isDecimalDigit(ch);
423
+ }
424
+ /**
425
+ * throw error at index of the expression
426
+ * @param {string} message
427
+ * @throws
428
+ */
429
+ throwError(message) {
430
+ const error = new Error(message + " at character " + this.index);
431
+ error.index = this.index;
432
+ error.description = message;
433
+ throw error;
434
+ }
435
+ /**
436
+ * Run a given hook
437
+ * @param {string} name
438
+ * @param {jsep.Expression|false} [node]
439
+ * @returns {?jsep.Expression}
440
+ */
441
+ runHook(name, node) {
442
+ if (_Jsep.hooks[name]) {
443
+ const env = { context: this, node };
444
+ _Jsep.hooks.run(name, env);
445
+ return env.node;
446
+ }
447
+ return node;
448
+ }
449
+ /**
450
+ * Runs a given hook until one returns a node
451
+ * @param {string} name
452
+ * @returns {?jsep.Expression}
453
+ */
454
+ searchHook(name) {
455
+ if (_Jsep.hooks[name]) {
456
+ const env = { context: this };
457
+ _Jsep.hooks[name].find(function(callback) {
458
+ callback.call(env.context, env);
459
+ return env.node;
460
+ });
461
+ return env.node;
462
+ }
463
+ }
464
+ /**
465
+ * Push `index` up to the next non-space character
466
+ */
467
+ gobbleSpaces() {
468
+ let ch = this.code;
469
+ while (ch === _Jsep.SPACE_CODE || ch === _Jsep.TAB_CODE || ch === _Jsep.LF_CODE || ch === _Jsep.CR_CODE) {
470
+ ch = this.expr.charCodeAt(++this.index);
471
+ }
472
+ this.runHook("gobble-spaces");
473
+ }
474
+ /**
475
+ * Top-level method to parse all expressions and returns compound or single node
476
+ * @returns {jsep.Expression}
477
+ */
478
+ parse() {
479
+ this.runHook("before-all");
480
+ const nodes = this.gobbleExpressions();
481
+ const node = nodes.length === 1 ? nodes[0] : {
482
+ type: _Jsep.COMPOUND,
483
+ body: nodes
484
+ };
485
+ return this.runHook("after-all", node);
486
+ }
487
+ /**
488
+ * top-level parser (but can be reused within as well)
489
+ * @param {number} [untilICode]
490
+ * @returns {jsep.Expression[]}
491
+ */
492
+ gobbleExpressions(untilICode) {
493
+ let nodes = [], ch_i, node;
494
+ while (this.index < this.expr.length) {
495
+ ch_i = this.code;
496
+ if (ch_i === _Jsep.SEMCOL_CODE || ch_i === _Jsep.COMMA_CODE) {
497
+ this.index++;
498
+ } else {
499
+ if (node = this.gobbleExpression()) {
500
+ nodes.push(node);
501
+ } else if (this.index < this.expr.length) {
502
+ if (ch_i === untilICode) {
503
+ break;
504
+ }
505
+ this.throwError('Unexpected "' + this.char + '"');
506
+ }
507
+ }
508
+ }
509
+ return nodes;
510
+ }
511
+ /**
512
+ * The main parsing function.
513
+ * @returns {?jsep.Expression}
514
+ */
515
+ gobbleExpression() {
516
+ const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
517
+ this.gobbleSpaces();
518
+ return this.runHook("after-expression", node);
519
+ }
520
+ /**
521
+ * Search for the operation portion of the string (e.g. `+`, `===`)
522
+ * Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)
523
+ * and move down from 3 to 2 to 1 character until a matching binary operation is found
524
+ * then, return that binary operation
525
+ * @returns {string|boolean}
526
+ */
527
+ gobbleBinaryOp() {
528
+ this.gobbleSpaces();
529
+ let to_check = this.expr.substr(this.index, _Jsep.max_binop_len);
530
+ let tc_len = to_check.length;
531
+ while (tc_len > 0) {
532
+ if (_Jsep.binary_ops.hasOwnProperty(to_check) && (!_Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !_Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
533
+ this.index += tc_len;
534
+ return to_check;
535
+ }
536
+ to_check = to_check.substr(0, --tc_len);
537
+ }
538
+ return false;
539
+ }
540
+ /**
541
+ * This function is responsible for gobbling an individual expression,
542
+ * e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`
543
+ * @returns {?jsep.BinaryExpression}
544
+ */
545
+ gobbleBinaryExpression() {
546
+ let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
547
+ left = this.gobbleToken();
548
+ if (!left) {
549
+ return left;
550
+ }
551
+ biop = this.gobbleBinaryOp();
552
+ if (!biop) {
553
+ return left;
554
+ }
555
+ biop_info = { value: biop, prec: _Jsep.binaryPrecedence(biop), right_a: _Jsep.right_associative.has(biop) };
556
+ right = this.gobbleToken();
557
+ if (!right) {
558
+ this.throwError("Expected expression after " + biop);
559
+ }
560
+ stack = [left, biop_info, right];
561
+ while (biop = this.gobbleBinaryOp()) {
562
+ prec = _Jsep.binaryPrecedence(biop);
563
+ if (prec === 0) {
564
+ this.index -= biop.length;
565
+ break;
566
+ }
567
+ biop_info = { value: biop, prec, right_a: _Jsep.right_associative.has(biop) };
568
+ cur_biop = biop;
569
+ const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
570
+ while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
571
+ right = stack.pop();
572
+ biop = stack.pop().value;
573
+ left = stack.pop();
574
+ node = {
575
+ type: _Jsep.BINARY_EXP,
576
+ operator: biop,
577
+ left,
578
+ right
579
+ };
580
+ stack.push(node);
581
+ }
582
+ node = this.gobbleToken();
583
+ if (!node) {
584
+ this.throwError("Expected expression after " + cur_biop);
585
+ }
586
+ stack.push(biop_info, node);
587
+ }
588
+ i = stack.length - 1;
589
+ node = stack[i];
590
+ while (i > 1) {
591
+ node = {
592
+ type: _Jsep.BINARY_EXP,
593
+ operator: stack[i - 1].value,
594
+ left: stack[i - 2],
595
+ right: node
596
+ };
597
+ i -= 2;
598
+ }
599
+ return node;
600
+ }
601
+ /**
602
+ * An individual part of a binary expression:
603
+ * e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis)
604
+ * @returns {boolean|jsep.Expression}
605
+ */
606
+ gobbleToken() {
607
+ let ch, to_check, tc_len, node;
608
+ this.gobbleSpaces();
609
+ node = this.searchHook("gobble-token");
610
+ if (node) {
611
+ return this.runHook("after-token", node);
612
+ }
613
+ ch = this.code;
614
+ if (_Jsep.isDecimalDigit(ch) || ch === _Jsep.PERIOD_CODE) {
615
+ return this.gobbleNumericLiteral();
616
+ }
617
+ if (ch === _Jsep.SQUOTE_CODE || ch === _Jsep.DQUOTE_CODE) {
618
+ node = this.gobbleStringLiteral();
619
+ } else if (ch === _Jsep.OBRACK_CODE) {
620
+ node = this.gobbleArray();
621
+ } else {
622
+ to_check = this.expr.substr(this.index, _Jsep.max_unop_len);
623
+ tc_len = to_check.length;
624
+ while (tc_len > 0) {
625
+ if (_Jsep.unary_ops.hasOwnProperty(to_check) && (!_Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !_Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
626
+ this.index += tc_len;
627
+ const argument = this.gobbleToken();
628
+ if (!argument) {
629
+ this.throwError("missing unaryOp argument");
630
+ }
631
+ return this.runHook("after-token", {
632
+ type: _Jsep.UNARY_EXP,
633
+ operator: to_check,
634
+ argument,
635
+ prefix: true
636
+ });
637
+ }
638
+ to_check = to_check.substr(0, --tc_len);
639
+ }
640
+ if (_Jsep.isIdentifierStart(ch)) {
641
+ node = this.gobbleIdentifier();
642
+ if (_Jsep.literals.hasOwnProperty(node.name)) {
643
+ node = {
644
+ type: _Jsep.LITERAL,
645
+ value: _Jsep.literals[node.name],
646
+ raw: node.name
647
+ };
648
+ } else if (node.name === _Jsep.this_str) {
649
+ node = { type: _Jsep.THIS_EXP };
650
+ }
651
+ } else if (ch === _Jsep.OPAREN_CODE) {
652
+ node = this.gobbleGroup();
653
+ }
654
+ }
655
+ if (!node) {
656
+ return this.runHook("after-token", false);
657
+ }
658
+ node = this.gobbleTokenProperty(node);
659
+ return this.runHook("after-token", node);
660
+ }
661
+ /**
662
+ * Gobble properties of of identifiers/strings/arrays/groups.
663
+ * e.g. `foo`, `bar.baz`, `foo['bar'].baz`
664
+ * It also gobbles function calls:
665
+ * e.g. `Math.acos(obj.angle)`
666
+ * @param {jsep.Expression} node
667
+ * @returns {jsep.Expression}
668
+ */
669
+ gobbleTokenProperty(node) {
670
+ this.gobbleSpaces();
671
+ let ch = this.code;
672
+ while (ch === _Jsep.PERIOD_CODE || ch === _Jsep.OBRACK_CODE || ch === _Jsep.OPAREN_CODE || ch === _Jsep.QUMARK_CODE) {
673
+ let optional;
674
+ if (ch === _Jsep.QUMARK_CODE) {
675
+ if (this.expr.charCodeAt(this.index + 1) !== _Jsep.PERIOD_CODE) {
676
+ break;
677
+ }
678
+ optional = true;
679
+ this.index += 2;
680
+ this.gobbleSpaces();
681
+ ch = this.code;
682
+ }
683
+ this.index++;
684
+ if (ch === _Jsep.OBRACK_CODE) {
685
+ node = {
686
+ type: _Jsep.MEMBER_EXP,
687
+ computed: true,
688
+ object: node,
689
+ property: this.gobbleExpression()
690
+ };
691
+ if (!node.property) {
692
+ this.throwError('Unexpected "' + this.char + '"');
693
+ }
694
+ this.gobbleSpaces();
695
+ ch = this.code;
696
+ if (ch !== _Jsep.CBRACK_CODE) {
697
+ this.throwError("Unclosed [");
698
+ }
699
+ this.index++;
700
+ } else if (ch === _Jsep.OPAREN_CODE) {
701
+ node = {
702
+ type: _Jsep.CALL_EXP,
703
+ "arguments": this.gobbleArguments(_Jsep.CPAREN_CODE),
704
+ callee: node
705
+ };
706
+ } else if (ch === _Jsep.PERIOD_CODE || optional) {
707
+ if (optional) {
708
+ this.index--;
709
+ }
710
+ this.gobbleSpaces();
711
+ node = {
712
+ type: _Jsep.MEMBER_EXP,
713
+ computed: false,
714
+ object: node,
715
+ property: this.gobbleIdentifier()
716
+ };
717
+ }
718
+ if (optional) {
719
+ node.optional = true;
720
+ }
721
+ this.gobbleSpaces();
722
+ ch = this.code;
723
+ }
724
+ return node;
725
+ }
726
+ /**
727
+ * Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to
728
+ * keep track of everything in the numeric literal and then calling `parseFloat` on that string
729
+ * @returns {jsep.Literal}
730
+ */
731
+ gobbleNumericLiteral() {
732
+ let number = "", ch, chCode;
733
+ while (_Jsep.isDecimalDigit(this.code)) {
734
+ number += this.expr.charAt(this.index++);
735
+ }
736
+ if (this.code === _Jsep.PERIOD_CODE) {
737
+ number += this.expr.charAt(this.index++);
738
+ while (_Jsep.isDecimalDigit(this.code)) {
739
+ number += this.expr.charAt(this.index++);
740
+ }
741
+ }
742
+ ch = this.char;
743
+ if (ch === "e" || ch === "E") {
744
+ number += this.expr.charAt(this.index++);
745
+ ch = this.char;
746
+ if (ch === "+" || ch === "-") {
747
+ number += this.expr.charAt(this.index++);
748
+ }
749
+ while (_Jsep.isDecimalDigit(this.code)) {
750
+ number += this.expr.charAt(this.index++);
751
+ }
752
+ if (!_Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
753
+ this.throwError("Expected exponent (" + number + this.char + ")");
754
+ }
755
+ }
756
+ chCode = this.code;
757
+ if (_Jsep.isIdentifierStart(chCode)) {
758
+ this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
759
+ } else if (chCode === _Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === _Jsep.PERIOD_CODE) {
760
+ this.throwError("Unexpected period");
761
+ }
762
+ return {
763
+ type: _Jsep.LITERAL,
764
+ value: parseFloat(number),
765
+ raw: number
766
+ };
767
+ }
768
+ /**
769
+ * Parses a string literal, staring with single or double quotes with basic support for escape codes
770
+ * e.g. `"hello world"`, `'this is\nJSEP'`
771
+ * @returns {jsep.Literal}
772
+ */
773
+ gobbleStringLiteral() {
774
+ let str = "";
775
+ const startIndex = this.index;
776
+ const quote = this.expr.charAt(this.index++);
777
+ let closed = false;
778
+ while (this.index < this.expr.length) {
779
+ let ch = this.expr.charAt(this.index++);
780
+ if (ch === quote) {
781
+ closed = true;
782
+ break;
783
+ } else if (ch === "\\") {
784
+ ch = this.expr.charAt(this.index++);
785
+ switch (ch) {
786
+ case "n":
787
+ str += "\n";
788
+ break;
789
+ case "r":
790
+ str += "\r";
791
+ break;
792
+ case "t":
793
+ str += " ";
794
+ break;
795
+ case "b":
796
+ str += "\b";
797
+ break;
798
+ case "f":
799
+ str += "\f";
800
+ break;
801
+ case "v":
802
+ str += "\v";
803
+ break;
804
+ default:
805
+ str += ch;
806
+ }
807
+ } else {
808
+ str += ch;
809
+ }
810
+ }
811
+ if (!closed) {
812
+ this.throwError('Unclosed quote after "' + str + '"');
813
+ }
814
+ return {
815
+ type: _Jsep.LITERAL,
816
+ value: str,
817
+ raw: this.expr.substring(startIndex, this.index)
818
+ };
819
+ }
820
+ /**
821
+ * Gobbles only identifiers
822
+ * e.g.: `foo`, `_value`, `$x1`
823
+ * Also, this function checks if that identifier is a literal:
824
+ * (e.g. `true`, `false`, `null`) or `this`
825
+ * @returns {jsep.Identifier}
826
+ */
827
+ gobbleIdentifier() {
828
+ let ch = this.code, start = this.index;
829
+ if (_Jsep.isIdentifierStart(ch)) {
830
+ this.index++;
831
+ } else {
832
+ this.throwError("Unexpected " + this.char);
833
+ }
834
+ while (this.index < this.expr.length) {
835
+ ch = this.code;
836
+ if (_Jsep.isIdentifierPart(ch)) {
837
+ this.index++;
838
+ } else {
839
+ break;
840
+ }
841
+ }
842
+ return {
843
+ type: _Jsep.IDENTIFIER,
844
+ name: this.expr.slice(start, this.index)
845
+ };
846
+ }
847
+ /**
848
+ * Gobbles a list of arguments within the context of a function call
849
+ * or array literal. This function also assumes that the opening character
850
+ * `(` or `[` has already been gobbled, and gobbles expressions and commas
851
+ * until the terminator character `)` or `]` is encountered.
852
+ * e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`
853
+ * @param {number} termination
854
+ * @returns {jsep.Expression[]}
855
+ */
856
+ gobbleArguments(termination) {
857
+ const args = [];
858
+ let closed = false;
859
+ let separator_count = 0;
860
+ while (this.index < this.expr.length) {
861
+ this.gobbleSpaces();
862
+ let ch_i = this.code;
863
+ if (ch_i === termination) {
864
+ closed = true;
865
+ this.index++;
866
+ if (termination === _Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
867
+ this.throwError("Unexpected token " + String.fromCharCode(termination));
868
+ }
869
+ break;
870
+ } else if (ch_i === _Jsep.COMMA_CODE) {
871
+ this.index++;
872
+ separator_count++;
873
+ if (separator_count !== args.length) {
874
+ if (termination === _Jsep.CPAREN_CODE) {
875
+ this.throwError("Unexpected token ,");
876
+ } else if (termination === _Jsep.CBRACK_CODE) {
877
+ for (let arg = args.length; arg < separator_count; arg++) {
878
+ args.push(null);
879
+ }
880
+ }
881
+ }
882
+ } else if (args.length !== separator_count && separator_count !== 0) {
883
+ this.throwError("Expected comma");
884
+ } else {
885
+ const node = this.gobbleExpression();
886
+ if (!node || node.type === _Jsep.COMPOUND) {
887
+ this.throwError("Expected comma");
888
+ }
889
+ args.push(node);
890
+ }
891
+ }
892
+ if (!closed) {
893
+ this.throwError("Expected " + String.fromCharCode(termination));
894
+ }
895
+ return args;
896
+ }
897
+ /**
898
+ * Responsible for parsing a group of things within parentheses `()`
899
+ * that have no identifier in front (so not a function call)
900
+ * This function assumes that it needs to gobble the opening parenthesis
901
+ * and then tries to gobble everything within that parenthesis, assuming
902
+ * that the next thing it should see is the close parenthesis. If not,
903
+ * then the expression probably doesn't have a `)`
904
+ * @returns {boolean|jsep.Expression}
905
+ */
906
+ gobbleGroup() {
907
+ this.index++;
908
+ let nodes = this.gobbleExpressions(_Jsep.CPAREN_CODE);
909
+ if (this.code === _Jsep.CPAREN_CODE) {
910
+ this.index++;
911
+ if (nodes.length === 1) {
912
+ return nodes[0];
913
+ } else if (!nodes.length) {
914
+ return false;
915
+ } else {
916
+ return {
917
+ type: _Jsep.SEQUENCE_EXP,
918
+ expressions: nodes
919
+ };
920
+ }
921
+ } else {
922
+ this.throwError("Unclosed (");
923
+ }
924
+ }
925
+ /**
926
+ * Responsible for parsing Array literals `[1, 2, 3]`
927
+ * This function assumes that it needs to gobble the opening bracket
928
+ * and then tries to gobble the expressions as arguments.
929
+ * @returns {jsep.ArrayExpression}
930
+ */
931
+ gobbleArray() {
932
+ this.index++;
933
+ return {
934
+ type: _Jsep.ARRAY_EXP,
935
+ elements: this.gobbleArguments(_Jsep.CBRACK_CODE)
936
+ };
937
+ }
938
+ };
939
+ var hooks = new Hooks();
940
+ Object.assign(Jsep, {
941
+ hooks,
942
+ plugins: new Plugins(Jsep),
943
+ // Node Types
944
+ // ----------
945
+ // This is the full set of types that any JSEP node can be.
946
+ // Store them here to save space when minified
947
+ COMPOUND: "Compound",
948
+ SEQUENCE_EXP: "SequenceExpression",
949
+ IDENTIFIER: "Identifier",
950
+ MEMBER_EXP: "MemberExpression",
951
+ LITERAL: "Literal",
952
+ THIS_EXP: "ThisExpression",
953
+ CALL_EXP: "CallExpression",
954
+ UNARY_EXP: "UnaryExpression",
955
+ BINARY_EXP: "BinaryExpression",
956
+ ARRAY_EXP: "ArrayExpression",
957
+ TAB_CODE: 9,
958
+ LF_CODE: 10,
959
+ CR_CODE: 13,
960
+ SPACE_CODE: 32,
961
+ PERIOD_CODE: 46,
962
+ // '.'
963
+ COMMA_CODE: 44,
964
+ // ','
965
+ SQUOTE_CODE: 39,
966
+ // single quote
967
+ DQUOTE_CODE: 34,
968
+ // double quotes
969
+ OPAREN_CODE: 40,
970
+ // (
971
+ CPAREN_CODE: 41,
972
+ // )
973
+ OBRACK_CODE: 91,
974
+ // [
975
+ CBRACK_CODE: 93,
976
+ // ]
977
+ QUMARK_CODE: 63,
978
+ // ?
979
+ SEMCOL_CODE: 59,
980
+ // ;
981
+ COLON_CODE: 58,
982
+ // :
983
+ // Operations
984
+ // ----------
985
+ // Use a quickly-accessible map to store all of the unary operators
986
+ // Values are set to `1` (it really doesn't matter)
987
+ unary_ops: {
988
+ "-": 1,
989
+ "!": 1,
990
+ "~": 1,
991
+ "+": 1
992
+ },
993
+ // Also use a map for the binary operations but set their values to their
994
+ // binary precedence for quick reference (higher number = higher precedence)
995
+ // see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
996
+ binary_ops: {
997
+ "||": 1,
998
+ "??": 1,
999
+ "&&": 2,
1000
+ "|": 3,
1001
+ "^": 4,
1002
+ "&": 5,
1003
+ "==": 6,
1004
+ "!=": 6,
1005
+ "===": 6,
1006
+ "!==": 6,
1007
+ "<": 7,
1008
+ ">": 7,
1009
+ "<=": 7,
1010
+ ">=": 7,
1011
+ "<<": 8,
1012
+ ">>": 8,
1013
+ ">>>": 8,
1014
+ "+": 9,
1015
+ "-": 9,
1016
+ "*": 10,
1017
+ "/": 10,
1018
+ "%": 10,
1019
+ "**": 11
1020
+ },
1021
+ // sets specific binary_ops as right-associative
1022
+ right_associative: /* @__PURE__ */ new Set(["**"]),
1023
+ // Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)
1024
+ additional_identifier_chars: /* @__PURE__ */ new Set(["$", "_"]),
1025
+ // Literals
1026
+ // ----------
1027
+ // Store the values to return for the various literals we may encounter
1028
+ literals: {
1029
+ "true": true,
1030
+ "false": false,
1031
+ "null": null
1032
+ },
1033
+ // Except for `this`, which is special. This could be changed to something like `'self'` as well
1034
+ this_str: "this"
1035
+ });
1036
+ Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
1037
+ Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
1038
+ var jsep = (expr) => new Jsep(expr).parse();
1039
+ var stdClassProps = Object.getOwnPropertyNames(class Test {
1040
+ });
1041
+ Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === void 0).forEach((m) => {
1042
+ jsep[m] = Jsep[m];
1043
+ });
1044
+ jsep.Jsep = Jsep;
1045
+ var CONDITIONAL_EXP = "ConditionalExpression";
1046
+ var ternary = {
1047
+ name: "ternary",
1048
+ init(jsep22) {
1049
+ jsep22.hooks.add("after-expression", function gobbleTernary(env) {
1050
+ if (env.node && this.code === jsep22.QUMARK_CODE) {
1051
+ this.index++;
1052
+ const test = env.node;
1053
+ const consequent = this.gobbleExpression();
1054
+ if (!consequent) {
1055
+ this.throwError("Expected expression");
1056
+ }
1057
+ this.gobbleSpaces();
1058
+ if (this.code === jsep22.COLON_CODE) {
1059
+ this.index++;
1060
+ const alternate = this.gobbleExpression();
1061
+ if (!alternate) {
1062
+ this.throwError("Expected expression");
1063
+ }
1064
+ env.node = {
1065
+ type: CONDITIONAL_EXP,
1066
+ test,
1067
+ consequent,
1068
+ alternate
1069
+ };
1070
+ if (test.operator && jsep22.binary_ops[test.operator] <= 0.9) {
1071
+ let newTest = test;
1072
+ while (newTest.right.operator && jsep22.binary_ops[newTest.right.operator] <= 0.9) {
1073
+ newTest = newTest.right;
1074
+ }
1075
+ env.node.test = newTest.right;
1076
+ newTest.right = env.node;
1077
+ env.node = test;
1078
+ }
1079
+ } else {
1080
+ this.throwError("Expected :");
1081
+ }
1082
+ }
1083
+ });
1084
+ }
1085
+ };
1086
+ jsep.plugins.register(ternary);
1087
+ var runtime_default = jsep;
1088
+
1089
+ // dist/lib/math-utils.js
1090
+ var EPSILON14 = 1e-14;
1091
+ var PI_OVER_TWO = Math.PI / 2;
1092
+ var PI_OVER_FOUR = Math.PI / 4;
1093
+ var PI_OVER_SIX = Math.PI / 6;
1094
+ var PI = Math.PI;
1095
+ var TWO_PI = Math.PI * 2;
1096
+
1097
+ // dist/lib/common.js
1098
+ var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
1099
+ var DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
1100
+ var DEFAULT_CONFIG = {
1101
+ EPSILON: 1e-12,
1102
+ debug: false,
1103
+ precision: 4,
1104
+ printTypes: false,
1105
+ printDegrees: false,
1106
+ printRowMajor: true,
1107
+ _cartographicRadians: false
1108
+ };
1109
+ globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
1110
+ var config = globalThis.mathgl.config;
1111
+ function isArray(value) {
1112
+ return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
1113
+ }
1114
+ function toRadians(degrees2) {
1115
+ return radians(degrees2);
1116
+ }
1117
+ function toDegrees(radians2) {
1118
+ return degrees(radians2);
1119
+ }
1120
+ function radians(degrees2, result) {
1121
+ return map(degrees2, (degrees3) => degrees3 * DEGREES_TO_RADIANS, result);
1122
+ }
1123
+ function degrees(radians2, result) {
1124
+ return map(radians2, (radians3) => radians3 * RADIANS_TO_DEGREES, result);
1125
+ }
1126
+ function safeMod(m, n) {
1127
+ if (Math.sign(m) === Math.sign(n) && Math.abs(m) < Math.abs(n)) {
1128
+ return m;
1129
+ }
1130
+ return (m % n + n) % n;
1131
+ }
1132
+ function normalizeAngle(angle, range) {
1133
+ switch (range) {
1134
+ case "negative-pi-to-pi":
1135
+ return negativePiToPi(angle);
1136
+ case "zero-to-two-pi":
1137
+ return zeroToTwoPi(angle);
1138
+ default:
1139
+ return angle;
1140
+ }
1141
+ }
1142
+ function zeroToTwoPi(angle) {
1143
+ if (angle >= 0 && angle <= TWO_PI) {
1144
+ return angle;
1145
+ }
1146
+ const remainder = safeMod(angle, TWO_PI);
1147
+ if (Math.abs(remainder) < EPSILON14 && Math.abs(angle) > EPSILON14) {
1148
+ return TWO_PI;
1149
+ }
1150
+ return remainder;
1151
+ }
1152
+ function negativePiToPi(angle) {
1153
+ if (angle >= -PI && angle <= PI) {
1154
+ return angle;
1155
+ }
1156
+ return zeroToTwoPi(angle + PI) - PI;
1157
+ }
1158
+ function clamp(value, min, max) {
1159
+ return map(value, (value2) => Math.max(min, Math.min(max, value2)));
1160
+ }
1161
+ function lerp(a, b, t) {
1162
+ if (isArray(a)) {
1163
+ return a.map((ai, i) => lerp(ai, b[i], t));
1164
+ }
1165
+ return t * b + (1 - t) * a;
1166
+ }
1167
+ function duplicateArray(array) {
1168
+ return array.clone ? array.clone() : new Array(array.length);
1169
+ }
1170
+ function map(value, func, result) {
1171
+ if (isArray(value)) {
1172
+ const array = value;
1173
+ result = result || duplicateArray(array);
1174
+ for (let i = 0; i < result.length && i < array.length; ++i) {
1175
+ const val = typeof value === "number" ? value : value[i];
1176
+ result[i] = func(val, i, result);
1177
+ }
1178
+ return result;
1179
+ }
1180
+ return func(value);
1181
+ }
1182
+
1183
+ // dist/expressions/function-libraries.js
1184
+ var BASIC_MATH_FUNCTION_LIBRARY = {
1185
+ abs: Math.abs,
1186
+ acos: Math.acos,
1187
+ asin: Math.asin,
1188
+ atan: Math.atan,
1189
+ ceil: Math.ceil,
1190
+ clamp,
1191
+ cos: Math.cos,
1192
+ degrees,
1193
+ exp: Math.exp,
1194
+ floor: Math.floor,
1195
+ lerp,
1196
+ log: Math.log,
1197
+ max: Math.max,
1198
+ min: Math.min,
1199
+ normalizeAngle,
1200
+ pow: Math.pow,
1201
+ radians,
1202
+ round: Math.round,
1203
+ safeMod,
1204
+ sign: Math.sign,
1205
+ sin: Math.sin,
1206
+ sqrt: Math.sqrt,
1207
+ tan: Math.tan,
1208
+ toDegrees,
1209
+ toRadians,
1210
+ trunc: Math.trunc
1211
+ };
1212
+ function mergeFunctionLibraries(context, options) {
1213
+ var _a, _b;
1214
+ if (!((_a = options == null ? void 0 : options.libraries) == null ? void 0 : _a.length)) {
1215
+ if (!(options == null ? void 0 : options.registry)) {
1216
+ return context;
1217
+ }
1218
+ }
1219
+ return Object.assign({}, (_b = options.registry) == null ? void 0 : _b.getFunctionTable(), ...options.libraries || [], context);
1220
+ }
1221
+
1222
+ // dist/expressions/expression-eval.js
1223
+ var jsep2 = runtime_default;
1224
+ var DEFAULT_PRECEDENCE = {
1225
+ "||": 1,
1226
+ "&&": 2,
1227
+ "|": 3,
1228
+ "^": 4,
1229
+ "&": 5,
1230
+ "==": 6,
1231
+ "!=": 6,
1232
+ "===": 6,
1233
+ "!==": 6,
1234
+ "<": 7,
1235
+ ">": 7,
1236
+ "<=": 7,
1237
+ ">=": 7,
1238
+ "<<": 8,
1239
+ ">>": 8,
1240
+ ">>>": 8,
1241
+ "+": 9,
1242
+ "-": 9,
1243
+ "*": 10,
1244
+ "/": 10,
1245
+ "%": 10
1246
+ };
1247
+ var binops = {
1248
+ "||": (a, b) => a || b,
1249
+ "&&": (a, b) => a && b,
1250
+ "|": (a, b) => a | b,
1251
+ "^": (a, b) => a ^ b,
1252
+ "&": (a, b) => a & b,
1253
+ "==": (a, b) => {
1254
+ return a == b;
1255
+ },
1256
+ "!=": (a, b) => {
1257
+ return a != b;
1258
+ },
1259
+ "===": (a, b) => a === b,
1260
+ "!==": (a, b) => a !== b,
1261
+ "<": (a, b) => a < b,
1262
+ ">": (a, b) => a > b,
1263
+ "<=": (a, b) => a <= b,
1264
+ ">=": (a, b) => a >= b,
1265
+ "<<": (a, b) => a << b,
1266
+ ">>": (a, b) => a >> b,
1267
+ ">>>": (a, b) => a >>> b,
1268
+ "+": (a, b) => {
1269
+ return a + b;
1270
+ },
1271
+ "-": (a, b) => a - b,
1272
+ "*": (a, b) => a * b,
1273
+ "/": (a, b) => a / b,
1274
+ "%": (a, b) => a % b
1275
+ };
1276
+ var unops = {
1277
+ "-": (a) => -a,
1278
+ "+": (a) => {
1279
+ return +a;
1280
+ },
1281
+ "~": (a) => ~a,
1282
+ "!": (a) => !a
1283
+ };
1284
+ function evaluateArray(list, context) {
1285
+ return list.map((value) => evaluate(value, context));
1286
+ }
1287
+ async function evaluateArrayAsync(list, context) {
1288
+ return await Promise.all(list.map((value) => evalAsync(value, context)));
1289
+ }
1290
+ function evaluateMember(node, context) {
1291
+ const object = evaluate(node.object, context);
1292
+ const key = node.computed ? evaluate(node.property, context) : node.property.name;
1293
+ if (/^__proto__|prototype|constructor$/.test(key)) {
1294
+ throw new Error(`Access to member "${key}" disallowed.`);
1295
+ }
1296
+ return [object, object == null ? void 0 : object[key]];
1297
+ }
1298
+ async function evaluateMemberAsync(node, context) {
1299
+ const object = await evalAsync(node.object, context);
1300
+ const key = node.computed ? await evalAsync(node.property, context) : node.property.name;
1301
+ if (/^__proto__|prototype|constructor$/.test(key)) {
1302
+ throw new Error(`Access to member "${key}" disallowed.`);
1303
+ }
1304
+ return [object, object == null ? void 0 : object[key]];
1305
+ }
1306
+ function evaluateExpression(node, context, options) {
1307
+ const expression = node;
1308
+ const mergedContext = mergeFunctionLibraries(context, options);
1309
+ switch (expression.type) {
1310
+ case "ArrayExpression":
1311
+ return evaluateArray(expression.elements, mergedContext);
1312
+ case "BinaryExpression":
1313
+ if (expression.operator === "||") {
1314
+ return evaluate(expression.left, mergedContext) || evaluate(expression.right, mergedContext);
1315
+ }
1316
+ if (expression.operator === "&&") {
1317
+ return evaluate(expression.left, mergedContext) && evaluate(expression.right, mergedContext);
1318
+ }
1319
+ return binops[expression.operator](evaluate(expression.left, mergedContext), evaluate(expression.right, mergedContext));
1320
+ case "CallExpression": {
1321
+ let caller;
1322
+ let fn;
1323
+ if (expression.callee.type === "MemberExpression") {
1324
+ const member = evaluateMember(expression.callee, mergedContext);
1325
+ caller = member[0];
1326
+ fn = member[1];
1327
+ } else {
1328
+ fn = evaluate(expression.callee, mergedContext);
1329
+ }
1330
+ if (typeof fn !== "function") {
1331
+ return void 0;
1332
+ }
1333
+ return fn.apply(caller, evaluateArray(expression.arguments, mergedContext));
1334
+ }
1335
+ case "ConditionalExpression":
1336
+ return evaluate(expression.test, mergedContext) ? evaluate(expression.consequent, mergedContext) : evaluate(expression.alternate, mergedContext);
1337
+ case "Identifier":
1338
+ return mergedContext[expression.name];
1339
+ case "Literal":
1340
+ return expression.value;
1341
+ case "MemberExpression":
1342
+ return evaluateMember(expression, mergedContext)[1];
1343
+ case "ThisExpression":
1344
+ return mergedContext;
1345
+ case "UnaryExpression":
1346
+ return unops[expression.operator](evaluate(expression.argument, mergedContext));
1347
+ default:
1348
+ return void 0;
1349
+ }
1350
+ }
1351
+ function evaluate(node, context) {
1352
+ return evaluateExpression(node, context);
1353
+ }
1354
+ async function evalAsync(node, context, options) {
1355
+ const expression = node;
1356
+ const mergedContext = mergeFunctionLibraries(context, options);
1357
+ switch (expression.type) {
1358
+ case "ArrayExpression":
1359
+ return await evaluateArrayAsync(expression.elements, mergedContext);
1360
+ case "BinaryExpression":
1361
+ if (expression.operator === "||") {
1362
+ return await evalAsync(expression.left, mergedContext) || await evalAsync(expression.right, mergedContext);
1363
+ }
1364
+ if (expression.operator === "&&") {
1365
+ return await evalAsync(expression.left, mergedContext) && await evalAsync(expression.right, mergedContext);
1366
+ }
1367
+ return binops[expression.operator](await evalAsync(expression.left, mergedContext), await evalAsync(expression.right, mergedContext));
1368
+ case "CallExpression": {
1369
+ let caller;
1370
+ let fn;
1371
+ if (expression.callee.type === "MemberExpression") {
1372
+ const member = await evaluateMemberAsync(expression.callee, mergedContext);
1373
+ caller = member[0];
1374
+ fn = member[1];
1375
+ } else {
1376
+ fn = await evalAsync(expression.callee, mergedContext);
1377
+ }
1378
+ if (typeof fn !== "function") {
1379
+ return void 0;
1380
+ }
1381
+ return await fn.apply(caller, await evaluateArrayAsync(expression.arguments, mergedContext));
1382
+ }
1383
+ case "ConditionalExpression":
1384
+ return await evalAsync(expression.test, mergedContext) ? await evalAsync(expression.consequent, mergedContext) : await evalAsync(expression.alternate, mergedContext);
1385
+ case "Identifier":
1386
+ return mergedContext[expression.name];
1387
+ case "Literal":
1388
+ return expression.value;
1389
+ case "MemberExpression":
1390
+ return (await evaluateMemberAsync(expression, mergedContext))[1];
1391
+ case "ThisExpression":
1392
+ return mergedContext;
1393
+ case "UnaryExpression":
1394
+ return unops[expression.operator](await evalAsync(expression.argument, mergedContext));
1395
+ default:
1396
+ return void 0;
1397
+ }
1398
+ }
1399
+ function compile(expression, options) {
1400
+ const ast = parse(expression);
1401
+ return (context) => evaluateExpression(ast, context, options);
1402
+ }
1403
+ function compileAsync(expression, options) {
1404
+ const ast = parse(expression);
1405
+ return (context) => evalAsync(ast, context, options);
1406
+ }
1407
+ function addUnaryOp(operator, fn) {
1408
+ jsep2.addUnaryOp(operator);
1409
+ unops[operator] = fn;
1410
+ }
1411
+ function addBinaryOp(operator, precedenceOrFn, fn) {
1412
+ if (fn) {
1413
+ jsep2.addBinaryOp(operator, precedenceOrFn);
1414
+ binops[operator] = fn;
1415
+ return;
1416
+ }
1417
+ jsep2.addBinaryOp(operator, DEFAULT_PRECEDENCE[operator] || 1);
1418
+ binops[operator] = precedenceOrFn;
1419
+ }
1420
+ function parse(expression) {
1421
+ return typeof expression === "string" ? jsep2(expression) : expression;
1422
+ }
1423
+
1424
+ // dist/expressions/get.js
1425
+ function get(container, compositeKey) {
1426
+ let value = container;
1427
+ for (const key of getKeys(compositeKey)) {
1428
+ value = isObject(value) ? value[key] : void 0;
1429
+ }
1430
+ return value;
1431
+ }
1432
+ function isObject(value) {
1433
+ return value !== null && typeof value === "object";
1434
+ }
1435
+ var keyMap = {};
1436
+ function getKeys(compositeKey) {
1437
+ let keyList = keyMap[compositeKey];
1438
+ if (!keyList) {
1439
+ keyList = compositeKey.split(".");
1440
+ keyMap[compositeKey] = keyList;
1441
+ }
1442
+ return keyList;
1443
+ }
1444
+
1445
+ // dist/expressions/parse-expression-string.js
1446
+ var cachedExpressionMap = {
1447
+ "-": (object) => object
1448
+ };
1449
+ function parseExpressionString(propValue) {
1450
+ if (propValue in cachedExpressionMap) {
1451
+ return cachedExpressionMap[propValue];
1452
+ }
1453
+ const ast = parse(propValue);
1454
+ const func = ast.type === "Identifier" ? (row) => get(row, propValue) : compileAst(ast);
1455
+ cachedExpressionMap[propValue] = func;
1456
+ return func;
1457
+ }
1458
+ function compileAst(ast) {
1459
+ traverse(ast, (node) => {
1460
+ if (node.type === "CallExpression") {
1461
+ throw new Error("Function calls not allowed in expression accessors");
1462
+ }
1463
+ });
1464
+ return (row) => evaluateExpression(ast, row);
1465
+ }
1466
+ function traverse(node, visitor) {
1467
+ if (Array.isArray(node)) {
1468
+ node.forEach((element) => traverse(element, visitor));
1469
+ return;
1470
+ }
1471
+ if (node && typeof node === "object") {
1472
+ if (isNodeLike(node)) {
1473
+ visitor(node);
1474
+ }
1475
+ for (const key in node) {
1476
+ traverse(node[key], visitor);
1477
+ }
1478
+ }
1479
+ }
1480
+ function isNodeLike(node) {
1481
+ return "type" in node && typeof node.type === "string";
1482
+ }
1483
+ //# sourceMappingURL=index.cjs.map