@math.gl/core 5.0.0-alpha.18 → 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,972 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) 2013 Stephen Oney
3
+ // @ts-nocheck
4
+ // Generated by scripts/vendor-expression-timezone-deps.mjs; see README.md and LICENSE files.
5
+ // jsep/dist/jsep.js
6
+ var Hooks = class {
7
+ /**
8
+ * @callback HookCallback
9
+ * @this {*|Jsep} this
10
+ * @param {Jsep} env
11
+ * @returns: void
12
+ */
13
+ /**
14
+ * Adds the given callback to the list of callbacks for the given hook.
15
+ *
16
+ * The callback will be invoked when the hook it is registered for is run.
17
+ *
18
+ * One callback function can be registered to multiple hooks and the same hook multiple times.
19
+ *
20
+ * @param {string|object} name The name of the hook, or an object of callbacks keyed by name
21
+ * @param {HookCallback|boolean} callback The callback function which is given environment variables.
22
+ * @param {?boolean} [first=false] Will add the hook to the top of the list (defaults to the bottom)
23
+ * @public
24
+ */
25
+ add(name, callback, first) {
26
+ if (typeof arguments[0] != "string") {
27
+ for (let name2 in arguments[0]) {
28
+ this.add(name2, arguments[0][name2], arguments[1]);
29
+ }
30
+ }
31
+ else {
32
+ (Array.isArray(name) ? name : [name]).forEach(function (name2) {
33
+ this[name2] = this[name2] || [];
34
+ if (callback) {
35
+ this[name2][first ? "unshift" : "push"](callback);
36
+ }
37
+ }, this);
38
+ }
39
+ }
40
+ /**
41
+ * Runs a hook invoking all registered callbacks with the given environment variables.
42
+ *
43
+ * Callbacks will be invoked synchronously and in the order in which they were registered.
44
+ *
45
+ * @param {string} name The name of the hook.
46
+ * @param {Object<string, any>} env The environment variables of the hook passed to all callbacks registered.
47
+ * @public
48
+ */
49
+ run(name, env) {
50
+ this[name] = this[name] || [];
51
+ this[name].forEach(function (callback) {
52
+ callback.call(env && env.context ? env.context : env, env);
53
+ });
54
+ }
55
+ };
56
+ var Plugins = class {
57
+ constructor(jsep2) {
58
+ this.jsep = jsep2;
59
+ this.registered = {};
60
+ }
61
+ /**
62
+ * @callback PluginSetup
63
+ * @this {Jsep} jsep
64
+ * @returns: void
65
+ */
66
+ /**
67
+ * Adds the given plugin(s) to the registry
68
+ *
69
+ * @param {object} plugins
70
+ * @param {string} plugins.name The name of the plugin
71
+ * @param {PluginSetup} plugins.init The init function
72
+ * @public
73
+ */
74
+ register(...plugins) {
75
+ plugins.forEach((plugin) => {
76
+ if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
77
+ throw new Error("Invalid JSEP plugin format");
78
+ }
79
+ if (this.registered[plugin.name]) {
80
+ return;
81
+ }
82
+ plugin.init(this.jsep);
83
+ this.registered[plugin.name] = plugin;
84
+ });
85
+ }
86
+ };
87
+ var Jsep = class _Jsep {
88
+ /**
89
+ * @returns {string}
90
+ */
91
+ static get version() {
92
+ return "1.4.0";
93
+ }
94
+ /**
95
+ * @returns {string}
96
+ */
97
+ static toString() {
98
+ return "JavaScript Expression Parser (JSEP) v" + _Jsep.version;
99
+ }
100
+ // ==================== CONFIG ================================
101
+ /**
102
+ * @method addUnaryOp
103
+ * @param {string} op_name The name of the unary op to add
104
+ * @returns {Jsep}
105
+ */
106
+ static addUnaryOp(op_name) {
107
+ _Jsep.max_unop_len = Math.max(op_name.length, _Jsep.max_unop_len);
108
+ _Jsep.unary_ops[op_name] = 1;
109
+ return _Jsep;
110
+ }
111
+ /**
112
+ * @method jsep.addBinaryOp
113
+ * @param {string} op_name The name of the binary op to add
114
+ * @param {number} precedence The precedence of the binary op (can be a float). Higher number = higher precedence
115
+ * @param {boolean} [isRightAssociative=false] whether operator is right-associative
116
+ * @returns {Jsep}
117
+ */
118
+ static addBinaryOp(op_name, precedence, isRightAssociative) {
119
+ _Jsep.max_binop_len = Math.max(op_name.length, _Jsep.max_binop_len);
120
+ _Jsep.binary_ops[op_name] = precedence;
121
+ if (isRightAssociative) {
122
+ _Jsep.right_associative.add(op_name);
123
+ }
124
+ else {
125
+ _Jsep.right_associative.delete(op_name);
126
+ }
127
+ return _Jsep;
128
+ }
129
+ /**
130
+ * @method addIdentifierChar
131
+ * @param {string} char The additional character to treat as a valid part of an identifier
132
+ * @returns {Jsep}
133
+ */
134
+ static addIdentifierChar(char) {
135
+ _Jsep.additional_identifier_chars.add(char);
136
+ return _Jsep;
137
+ }
138
+ /**
139
+ * @method addLiteral
140
+ * @param {string} literal_name The name of the literal to add
141
+ * @param {*} literal_value The value of the literal
142
+ * @returns {Jsep}
143
+ */
144
+ static addLiteral(literal_name, literal_value) {
145
+ _Jsep.literals[literal_name] = literal_value;
146
+ return _Jsep;
147
+ }
148
+ /**
149
+ * @method removeUnaryOp
150
+ * @param {string} op_name The name of the unary op to remove
151
+ * @returns {Jsep}
152
+ */
153
+ static removeUnaryOp(op_name) {
154
+ delete _Jsep.unary_ops[op_name];
155
+ if (op_name.length === _Jsep.max_unop_len) {
156
+ _Jsep.max_unop_len = _Jsep.getMaxKeyLen(_Jsep.unary_ops);
157
+ }
158
+ return _Jsep;
159
+ }
160
+ /**
161
+ * @method removeAllUnaryOps
162
+ * @returns {Jsep}
163
+ */
164
+ static removeAllUnaryOps() {
165
+ _Jsep.unary_ops = {};
166
+ _Jsep.max_unop_len = 0;
167
+ return _Jsep;
168
+ }
169
+ /**
170
+ * @method removeIdentifierChar
171
+ * @param {string} char The additional character to stop treating as a valid part of an identifier
172
+ * @returns {Jsep}
173
+ */
174
+ static removeIdentifierChar(char) {
175
+ _Jsep.additional_identifier_chars.delete(char);
176
+ return _Jsep;
177
+ }
178
+ /**
179
+ * @method removeBinaryOp
180
+ * @param {string} op_name The name of the binary op to remove
181
+ * @returns {Jsep}
182
+ */
183
+ static removeBinaryOp(op_name) {
184
+ delete _Jsep.binary_ops[op_name];
185
+ if (op_name.length === _Jsep.max_binop_len) {
186
+ _Jsep.max_binop_len = _Jsep.getMaxKeyLen(_Jsep.binary_ops);
187
+ }
188
+ _Jsep.right_associative.delete(op_name);
189
+ return _Jsep;
190
+ }
191
+ /**
192
+ * @method removeAllBinaryOps
193
+ * @returns {Jsep}
194
+ */
195
+ static removeAllBinaryOps() {
196
+ _Jsep.binary_ops = {};
197
+ _Jsep.max_binop_len = 0;
198
+ return _Jsep;
199
+ }
200
+ /**
201
+ * @method removeLiteral
202
+ * @param {string} literal_name The name of the literal to remove
203
+ * @returns {Jsep}
204
+ */
205
+ static removeLiteral(literal_name) {
206
+ delete _Jsep.literals[literal_name];
207
+ return _Jsep;
208
+ }
209
+ /**
210
+ * @method removeAllLiterals
211
+ * @returns {Jsep}
212
+ */
213
+ static removeAllLiterals() {
214
+ _Jsep.literals = {};
215
+ return _Jsep;
216
+ }
217
+ // ==================== END CONFIG ============================
218
+ /**
219
+ * @returns {string}
220
+ */
221
+ get char() {
222
+ return this.expr.charAt(this.index);
223
+ }
224
+ /**
225
+ * @returns {number}
226
+ */
227
+ get code() {
228
+ return this.expr.charCodeAt(this.index);
229
+ }
230
+ /**
231
+ * @param {string} expr a string with the passed in express
232
+ * @returns Jsep
233
+ */
234
+ constructor(expr) {
235
+ this.expr = expr;
236
+ this.index = 0;
237
+ }
238
+ /**
239
+ * static top-level parser
240
+ * @returns {jsep.Expression}
241
+ */
242
+ static parse(expr) {
243
+ return new _Jsep(expr).parse();
244
+ }
245
+ /**
246
+ * Get the longest key length of any object
247
+ * @param {object} obj
248
+ * @returns {number}
249
+ */
250
+ static getMaxKeyLen(obj) {
251
+ return Math.max(0, ...Object.keys(obj).map((k) => k.length));
252
+ }
253
+ /**
254
+ * `ch` is a character code in the next three functions
255
+ * @param {number} ch
256
+ * @returns {boolean}
257
+ */
258
+ static isDecimalDigit(ch) {
259
+ return ch >= 48 && ch <= 57;
260
+ }
261
+ /**
262
+ * Returns the precedence of a binary operator or `0` if it isn't a binary operator. Can be float.
263
+ * @param {string} op_val
264
+ * @returns {number}
265
+ */
266
+ static binaryPrecedence(op_val) {
267
+ return _Jsep.binary_ops[op_val] || 0;
268
+ }
269
+ /**
270
+ * Looks for start of identifier
271
+ * @param {number} ch
272
+ * @returns {boolean}
273
+ */
274
+ static isIdentifierStart(ch) {
275
+ return ch >= 65 && ch <= 90 || // A...Z
276
+ ch >= 97 && ch <= 122 || // a...z
277
+ ch >= 128 && !_Jsep.binary_ops[String.fromCharCode(ch)] || // any non-ASCII that is not an operator
278
+ _Jsep.additional_identifier_chars.has(String.fromCharCode(ch));
279
+ }
280
+ /**
281
+ * @param {number} ch
282
+ * @returns {boolean}
283
+ */
284
+ static isIdentifierPart(ch) {
285
+ return _Jsep.isIdentifierStart(ch) || _Jsep.isDecimalDigit(ch);
286
+ }
287
+ /**
288
+ * throw error at index of the expression
289
+ * @param {string} message
290
+ * @throws
291
+ */
292
+ throwError(message) {
293
+ const error = new Error(message + " at character " + this.index);
294
+ error.index = this.index;
295
+ error.description = message;
296
+ throw error;
297
+ }
298
+ /**
299
+ * Run a given hook
300
+ * @param {string} name
301
+ * @param {jsep.Expression|false} [node]
302
+ * @returns {?jsep.Expression}
303
+ */
304
+ runHook(name, node) {
305
+ if (_Jsep.hooks[name]) {
306
+ const env = { context: this, node };
307
+ _Jsep.hooks.run(name, env);
308
+ return env.node;
309
+ }
310
+ return node;
311
+ }
312
+ /**
313
+ * Runs a given hook until one returns a node
314
+ * @param {string} name
315
+ * @returns {?jsep.Expression}
316
+ */
317
+ searchHook(name) {
318
+ if (_Jsep.hooks[name]) {
319
+ const env = { context: this };
320
+ _Jsep.hooks[name].find(function (callback) {
321
+ callback.call(env.context, env);
322
+ return env.node;
323
+ });
324
+ return env.node;
325
+ }
326
+ }
327
+ /**
328
+ * Push `index` up to the next non-space character
329
+ */
330
+ gobbleSpaces() {
331
+ let ch = this.code;
332
+ while (ch === _Jsep.SPACE_CODE || ch === _Jsep.TAB_CODE || ch === _Jsep.LF_CODE || ch === _Jsep.CR_CODE) {
333
+ ch = this.expr.charCodeAt(++this.index);
334
+ }
335
+ this.runHook("gobble-spaces");
336
+ }
337
+ /**
338
+ * Top-level method to parse all expressions and returns compound or single node
339
+ * @returns {jsep.Expression}
340
+ */
341
+ parse() {
342
+ this.runHook("before-all");
343
+ const nodes = this.gobbleExpressions();
344
+ const node = nodes.length === 1 ? nodes[0] : {
345
+ type: _Jsep.COMPOUND,
346
+ body: nodes
347
+ };
348
+ return this.runHook("after-all", node);
349
+ }
350
+ /**
351
+ * top-level parser (but can be reused within as well)
352
+ * @param {number} [untilICode]
353
+ * @returns {jsep.Expression[]}
354
+ */
355
+ gobbleExpressions(untilICode) {
356
+ let nodes = [], ch_i, node;
357
+ while (this.index < this.expr.length) {
358
+ ch_i = this.code;
359
+ if (ch_i === _Jsep.SEMCOL_CODE || ch_i === _Jsep.COMMA_CODE) {
360
+ this.index++;
361
+ }
362
+ else {
363
+ if (node = this.gobbleExpression()) {
364
+ nodes.push(node);
365
+ }
366
+ else if (this.index < this.expr.length) {
367
+ if (ch_i === untilICode) {
368
+ break;
369
+ }
370
+ this.throwError('Unexpected "' + this.char + '"');
371
+ }
372
+ }
373
+ }
374
+ return nodes;
375
+ }
376
+ /**
377
+ * The main parsing function.
378
+ * @returns {?jsep.Expression}
379
+ */
380
+ gobbleExpression() {
381
+ const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
382
+ this.gobbleSpaces();
383
+ return this.runHook("after-expression", node);
384
+ }
385
+ /**
386
+ * Search for the operation portion of the string (e.g. `+`, `===`)
387
+ * Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)
388
+ * and move down from 3 to 2 to 1 character until a matching binary operation is found
389
+ * then, return that binary operation
390
+ * @returns {string|boolean}
391
+ */
392
+ gobbleBinaryOp() {
393
+ this.gobbleSpaces();
394
+ let to_check = this.expr.substr(this.index, _Jsep.max_binop_len);
395
+ let tc_len = to_check.length;
396
+ while (tc_len > 0) {
397
+ 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)))) {
398
+ this.index += tc_len;
399
+ return to_check;
400
+ }
401
+ to_check = to_check.substr(0, --tc_len);
402
+ }
403
+ return false;
404
+ }
405
+ /**
406
+ * This function is responsible for gobbling an individual expression,
407
+ * e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`
408
+ * @returns {?jsep.BinaryExpression}
409
+ */
410
+ gobbleBinaryExpression() {
411
+ let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
412
+ left = this.gobbleToken();
413
+ if (!left) {
414
+ return left;
415
+ }
416
+ biop = this.gobbleBinaryOp();
417
+ if (!biop) {
418
+ return left;
419
+ }
420
+ biop_info = { value: biop, prec: _Jsep.binaryPrecedence(biop), right_a: _Jsep.right_associative.has(biop) };
421
+ right = this.gobbleToken();
422
+ if (!right) {
423
+ this.throwError("Expected expression after " + biop);
424
+ }
425
+ stack = [left, biop_info, right];
426
+ while (biop = this.gobbleBinaryOp()) {
427
+ prec = _Jsep.binaryPrecedence(biop);
428
+ if (prec === 0) {
429
+ this.index -= biop.length;
430
+ break;
431
+ }
432
+ biop_info = { value: biop, prec, right_a: _Jsep.right_associative.has(biop) };
433
+ cur_biop = biop;
434
+ const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
435
+ while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
436
+ right = stack.pop();
437
+ biop = stack.pop().value;
438
+ left = stack.pop();
439
+ node = {
440
+ type: _Jsep.BINARY_EXP,
441
+ operator: biop,
442
+ left,
443
+ right
444
+ };
445
+ stack.push(node);
446
+ }
447
+ node = this.gobbleToken();
448
+ if (!node) {
449
+ this.throwError("Expected expression after " + cur_biop);
450
+ }
451
+ stack.push(biop_info, node);
452
+ }
453
+ i = stack.length - 1;
454
+ node = stack[i];
455
+ while (i > 1) {
456
+ node = {
457
+ type: _Jsep.BINARY_EXP,
458
+ operator: stack[i - 1].value,
459
+ left: stack[i - 2],
460
+ right: node
461
+ };
462
+ i -= 2;
463
+ }
464
+ return node;
465
+ }
466
+ /**
467
+ * An individual part of a binary expression:
468
+ * e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis)
469
+ * @returns {boolean|jsep.Expression}
470
+ */
471
+ gobbleToken() {
472
+ let ch, to_check, tc_len, node;
473
+ this.gobbleSpaces();
474
+ node = this.searchHook("gobble-token");
475
+ if (node) {
476
+ return this.runHook("after-token", node);
477
+ }
478
+ ch = this.code;
479
+ if (_Jsep.isDecimalDigit(ch) || ch === _Jsep.PERIOD_CODE) {
480
+ return this.gobbleNumericLiteral();
481
+ }
482
+ if (ch === _Jsep.SQUOTE_CODE || ch === _Jsep.DQUOTE_CODE) {
483
+ node = this.gobbleStringLiteral();
484
+ }
485
+ else if (ch === _Jsep.OBRACK_CODE) {
486
+ node = this.gobbleArray();
487
+ }
488
+ else {
489
+ to_check = this.expr.substr(this.index, _Jsep.max_unop_len);
490
+ tc_len = to_check.length;
491
+ while (tc_len > 0) {
492
+ 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)))) {
493
+ this.index += tc_len;
494
+ const argument = this.gobbleToken();
495
+ if (!argument) {
496
+ this.throwError("missing unaryOp argument");
497
+ }
498
+ return this.runHook("after-token", {
499
+ type: _Jsep.UNARY_EXP,
500
+ operator: to_check,
501
+ argument,
502
+ prefix: true
503
+ });
504
+ }
505
+ to_check = to_check.substr(0, --tc_len);
506
+ }
507
+ if (_Jsep.isIdentifierStart(ch)) {
508
+ node = this.gobbleIdentifier();
509
+ if (_Jsep.literals.hasOwnProperty(node.name)) {
510
+ node = {
511
+ type: _Jsep.LITERAL,
512
+ value: _Jsep.literals[node.name],
513
+ raw: node.name
514
+ };
515
+ }
516
+ else if (node.name === _Jsep.this_str) {
517
+ node = { type: _Jsep.THIS_EXP };
518
+ }
519
+ }
520
+ else if (ch === _Jsep.OPAREN_CODE) {
521
+ node = this.gobbleGroup();
522
+ }
523
+ }
524
+ if (!node) {
525
+ return this.runHook("after-token", false);
526
+ }
527
+ node = this.gobbleTokenProperty(node);
528
+ return this.runHook("after-token", node);
529
+ }
530
+ /**
531
+ * Gobble properties of of identifiers/strings/arrays/groups.
532
+ * e.g. `foo`, `bar.baz`, `foo['bar'].baz`
533
+ * It also gobbles function calls:
534
+ * e.g. `Math.acos(obj.angle)`
535
+ * @param {jsep.Expression} node
536
+ * @returns {jsep.Expression}
537
+ */
538
+ gobbleTokenProperty(node) {
539
+ this.gobbleSpaces();
540
+ let ch = this.code;
541
+ while (ch === _Jsep.PERIOD_CODE || ch === _Jsep.OBRACK_CODE || ch === _Jsep.OPAREN_CODE || ch === _Jsep.QUMARK_CODE) {
542
+ let optional;
543
+ if (ch === _Jsep.QUMARK_CODE) {
544
+ if (this.expr.charCodeAt(this.index + 1) !== _Jsep.PERIOD_CODE) {
545
+ break;
546
+ }
547
+ optional = true;
548
+ this.index += 2;
549
+ this.gobbleSpaces();
550
+ ch = this.code;
551
+ }
552
+ this.index++;
553
+ if (ch === _Jsep.OBRACK_CODE) {
554
+ node = {
555
+ type: _Jsep.MEMBER_EXP,
556
+ computed: true,
557
+ object: node,
558
+ property: this.gobbleExpression()
559
+ };
560
+ if (!node.property) {
561
+ this.throwError('Unexpected "' + this.char + '"');
562
+ }
563
+ this.gobbleSpaces();
564
+ ch = this.code;
565
+ if (ch !== _Jsep.CBRACK_CODE) {
566
+ this.throwError("Unclosed [");
567
+ }
568
+ this.index++;
569
+ }
570
+ else if (ch === _Jsep.OPAREN_CODE) {
571
+ node = {
572
+ type: _Jsep.CALL_EXP,
573
+ "arguments": this.gobbleArguments(_Jsep.CPAREN_CODE),
574
+ callee: node
575
+ };
576
+ }
577
+ else if (ch === _Jsep.PERIOD_CODE || optional) {
578
+ if (optional) {
579
+ this.index--;
580
+ }
581
+ this.gobbleSpaces();
582
+ node = {
583
+ type: _Jsep.MEMBER_EXP,
584
+ computed: false,
585
+ object: node,
586
+ property: this.gobbleIdentifier()
587
+ };
588
+ }
589
+ if (optional) {
590
+ node.optional = true;
591
+ }
592
+ this.gobbleSpaces();
593
+ ch = this.code;
594
+ }
595
+ return node;
596
+ }
597
+ /**
598
+ * Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to
599
+ * keep track of everything in the numeric literal and then calling `parseFloat` on that string
600
+ * @returns {jsep.Literal}
601
+ */
602
+ gobbleNumericLiteral() {
603
+ let number = "", ch, chCode;
604
+ while (_Jsep.isDecimalDigit(this.code)) {
605
+ number += this.expr.charAt(this.index++);
606
+ }
607
+ if (this.code === _Jsep.PERIOD_CODE) {
608
+ number += this.expr.charAt(this.index++);
609
+ while (_Jsep.isDecimalDigit(this.code)) {
610
+ number += this.expr.charAt(this.index++);
611
+ }
612
+ }
613
+ ch = this.char;
614
+ if (ch === "e" || ch === "E") {
615
+ number += this.expr.charAt(this.index++);
616
+ ch = this.char;
617
+ if (ch === "+" || ch === "-") {
618
+ number += this.expr.charAt(this.index++);
619
+ }
620
+ while (_Jsep.isDecimalDigit(this.code)) {
621
+ number += this.expr.charAt(this.index++);
622
+ }
623
+ if (!_Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
624
+ this.throwError("Expected exponent (" + number + this.char + ")");
625
+ }
626
+ }
627
+ chCode = this.code;
628
+ if (_Jsep.isIdentifierStart(chCode)) {
629
+ this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
630
+ }
631
+ else if (chCode === _Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === _Jsep.PERIOD_CODE) {
632
+ this.throwError("Unexpected period");
633
+ }
634
+ return {
635
+ type: _Jsep.LITERAL,
636
+ value: parseFloat(number),
637
+ raw: number
638
+ };
639
+ }
640
+ /**
641
+ * Parses a string literal, staring with single or double quotes with basic support for escape codes
642
+ * e.g. `"hello world"`, `'this is\nJSEP'`
643
+ * @returns {jsep.Literal}
644
+ */
645
+ gobbleStringLiteral() {
646
+ let str = "";
647
+ const startIndex = this.index;
648
+ const quote = this.expr.charAt(this.index++);
649
+ let closed = false;
650
+ while (this.index < this.expr.length) {
651
+ let ch = this.expr.charAt(this.index++);
652
+ if (ch === quote) {
653
+ closed = true;
654
+ break;
655
+ }
656
+ else if (ch === "\\") {
657
+ ch = this.expr.charAt(this.index++);
658
+ switch (ch) {
659
+ case "n":
660
+ str += "\n";
661
+ break;
662
+ case "r":
663
+ str += "\r";
664
+ break;
665
+ case "t":
666
+ str += " ";
667
+ break;
668
+ case "b":
669
+ str += "\b";
670
+ break;
671
+ case "f":
672
+ str += "\f";
673
+ break;
674
+ case "v":
675
+ str += "\v";
676
+ break;
677
+ default:
678
+ str += ch;
679
+ }
680
+ }
681
+ else {
682
+ str += ch;
683
+ }
684
+ }
685
+ if (!closed) {
686
+ this.throwError('Unclosed quote after "' + str + '"');
687
+ }
688
+ return {
689
+ type: _Jsep.LITERAL,
690
+ value: str,
691
+ raw: this.expr.substring(startIndex, this.index)
692
+ };
693
+ }
694
+ /**
695
+ * Gobbles only identifiers
696
+ * e.g.: `foo`, `_value`, `$x1`
697
+ * Also, this function checks if that identifier is a literal:
698
+ * (e.g. `true`, `false`, `null`) or `this`
699
+ * @returns {jsep.Identifier}
700
+ */
701
+ gobbleIdentifier() {
702
+ let ch = this.code, start = this.index;
703
+ if (_Jsep.isIdentifierStart(ch)) {
704
+ this.index++;
705
+ }
706
+ else {
707
+ this.throwError("Unexpected " + this.char);
708
+ }
709
+ while (this.index < this.expr.length) {
710
+ ch = this.code;
711
+ if (_Jsep.isIdentifierPart(ch)) {
712
+ this.index++;
713
+ }
714
+ else {
715
+ break;
716
+ }
717
+ }
718
+ return {
719
+ type: _Jsep.IDENTIFIER,
720
+ name: this.expr.slice(start, this.index)
721
+ };
722
+ }
723
+ /**
724
+ * Gobbles a list of arguments within the context of a function call
725
+ * or array literal. This function also assumes that the opening character
726
+ * `(` or `[` has already been gobbled, and gobbles expressions and commas
727
+ * until the terminator character `)` or `]` is encountered.
728
+ * e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`
729
+ * @param {number} termination
730
+ * @returns {jsep.Expression[]}
731
+ */
732
+ gobbleArguments(termination) {
733
+ const args = [];
734
+ let closed = false;
735
+ let separator_count = 0;
736
+ while (this.index < this.expr.length) {
737
+ this.gobbleSpaces();
738
+ let ch_i = this.code;
739
+ if (ch_i === termination) {
740
+ closed = true;
741
+ this.index++;
742
+ if (termination === _Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
743
+ this.throwError("Unexpected token " + String.fromCharCode(termination));
744
+ }
745
+ break;
746
+ }
747
+ else if (ch_i === _Jsep.COMMA_CODE) {
748
+ this.index++;
749
+ separator_count++;
750
+ if (separator_count !== args.length) {
751
+ if (termination === _Jsep.CPAREN_CODE) {
752
+ this.throwError("Unexpected token ,");
753
+ }
754
+ else if (termination === _Jsep.CBRACK_CODE) {
755
+ for (let arg = args.length; arg < separator_count; arg++) {
756
+ args.push(null);
757
+ }
758
+ }
759
+ }
760
+ }
761
+ else if (args.length !== separator_count && separator_count !== 0) {
762
+ this.throwError("Expected comma");
763
+ }
764
+ else {
765
+ const node = this.gobbleExpression();
766
+ if (!node || node.type === _Jsep.COMPOUND) {
767
+ this.throwError("Expected comma");
768
+ }
769
+ args.push(node);
770
+ }
771
+ }
772
+ if (!closed) {
773
+ this.throwError("Expected " + String.fromCharCode(termination));
774
+ }
775
+ return args;
776
+ }
777
+ /**
778
+ * Responsible for parsing a group of things within parentheses `()`
779
+ * that have no identifier in front (so not a function call)
780
+ * This function assumes that it needs to gobble the opening parenthesis
781
+ * and then tries to gobble everything within that parenthesis, assuming
782
+ * that the next thing it should see is the close parenthesis. If not,
783
+ * then the expression probably doesn't have a `)`
784
+ * @returns {boolean|jsep.Expression}
785
+ */
786
+ gobbleGroup() {
787
+ this.index++;
788
+ let nodes = this.gobbleExpressions(_Jsep.CPAREN_CODE);
789
+ if (this.code === _Jsep.CPAREN_CODE) {
790
+ this.index++;
791
+ if (nodes.length === 1) {
792
+ return nodes[0];
793
+ }
794
+ else if (!nodes.length) {
795
+ return false;
796
+ }
797
+ else {
798
+ return {
799
+ type: _Jsep.SEQUENCE_EXP,
800
+ expressions: nodes
801
+ };
802
+ }
803
+ }
804
+ else {
805
+ this.throwError("Unclosed (");
806
+ }
807
+ }
808
+ /**
809
+ * Responsible for parsing Array literals `[1, 2, 3]`
810
+ * This function assumes that it needs to gobble the opening bracket
811
+ * and then tries to gobble the expressions as arguments.
812
+ * @returns {jsep.ArrayExpression}
813
+ */
814
+ gobbleArray() {
815
+ this.index++;
816
+ return {
817
+ type: _Jsep.ARRAY_EXP,
818
+ elements: this.gobbleArguments(_Jsep.CBRACK_CODE)
819
+ };
820
+ }
821
+ };
822
+ var hooks = new Hooks();
823
+ Object.assign(Jsep, {
824
+ hooks,
825
+ plugins: new Plugins(Jsep),
826
+ // Node Types
827
+ // ----------
828
+ // This is the full set of types that any JSEP node can be.
829
+ // Store them here to save space when minified
830
+ COMPOUND: "Compound",
831
+ SEQUENCE_EXP: "SequenceExpression",
832
+ IDENTIFIER: "Identifier",
833
+ MEMBER_EXP: "MemberExpression",
834
+ LITERAL: "Literal",
835
+ THIS_EXP: "ThisExpression",
836
+ CALL_EXP: "CallExpression",
837
+ UNARY_EXP: "UnaryExpression",
838
+ BINARY_EXP: "BinaryExpression",
839
+ ARRAY_EXP: "ArrayExpression",
840
+ TAB_CODE: 9,
841
+ LF_CODE: 10,
842
+ CR_CODE: 13,
843
+ SPACE_CODE: 32,
844
+ PERIOD_CODE: 46,
845
+ // '.'
846
+ COMMA_CODE: 44,
847
+ // ','
848
+ SQUOTE_CODE: 39,
849
+ // single quote
850
+ DQUOTE_CODE: 34,
851
+ // double quotes
852
+ OPAREN_CODE: 40,
853
+ // (
854
+ CPAREN_CODE: 41,
855
+ // )
856
+ OBRACK_CODE: 91,
857
+ // [
858
+ CBRACK_CODE: 93,
859
+ // ]
860
+ QUMARK_CODE: 63,
861
+ // ?
862
+ SEMCOL_CODE: 59,
863
+ // ;
864
+ COLON_CODE: 58,
865
+ // :
866
+ // Operations
867
+ // ----------
868
+ // Use a quickly-accessible map to store all of the unary operators
869
+ // Values are set to `1` (it really doesn't matter)
870
+ unary_ops: {
871
+ "-": 1,
872
+ "!": 1,
873
+ "~": 1,
874
+ "+": 1
875
+ },
876
+ // Also use a map for the binary operations but set their values to their
877
+ // binary precedence for quick reference (higher number = higher precedence)
878
+ // see [Order of operations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
879
+ binary_ops: {
880
+ "||": 1,
881
+ "??": 1,
882
+ "&&": 2,
883
+ "|": 3,
884
+ "^": 4,
885
+ "&": 5,
886
+ "==": 6,
887
+ "!=": 6,
888
+ "===": 6,
889
+ "!==": 6,
890
+ "<": 7,
891
+ ">": 7,
892
+ "<=": 7,
893
+ ">=": 7,
894
+ "<<": 8,
895
+ ">>": 8,
896
+ ">>>": 8,
897
+ "+": 9,
898
+ "-": 9,
899
+ "*": 10,
900
+ "/": 10,
901
+ "%": 10,
902
+ "**": 11
903
+ },
904
+ // sets specific binary_ops as right-associative
905
+ right_associative: /* @__PURE__ */ new Set(["**"]),
906
+ // Additional valid identifier chars, apart from a-z, A-Z and 0-9 (except on the starting char)
907
+ additional_identifier_chars: /* @__PURE__ */ new Set(["$", "_"]),
908
+ // Literals
909
+ // ----------
910
+ // Store the values to return for the various literals we may encounter
911
+ literals: {
912
+ "true": true,
913
+ "false": false,
914
+ "null": null
915
+ },
916
+ // Except for `this`, which is special. This could be changed to something like `'self'` as well
917
+ this_str: "this"
918
+ });
919
+ Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
920
+ Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
921
+ var jsep = (expr) => new Jsep(expr).parse();
922
+ var stdClassProps = Object.getOwnPropertyNames(class Test {
923
+ });
924
+ Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === void 0).forEach((m) => {
925
+ jsep[m] = Jsep[m];
926
+ });
927
+ jsep.Jsep = Jsep;
928
+ var CONDITIONAL_EXP = "ConditionalExpression";
929
+ var ternary = {
930
+ name: "ternary",
931
+ init(jsep2) {
932
+ jsep2.hooks.add("after-expression", function gobbleTernary(env) {
933
+ if (env.node && this.code === jsep2.QUMARK_CODE) {
934
+ this.index++;
935
+ const test = env.node;
936
+ const consequent = this.gobbleExpression();
937
+ if (!consequent) {
938
+ this.throwError("Expected expression");
939
+ }
940
+ this.gobbleSpaces();
941
+ if (this.code === jsep2.COLON_CODE) {
942
+ this.index++;
943
+ const alternate = this.gobbleExpression();
944
+ if (!alternate) {
945
+ this.throwError("Expected expression");
946
+ }
947
+ env.node = {
948
+ type: CONDITIONAL_EXP,
949
+ test,
950
+ consequent,
951
+ alternate
952
+ };
953
+ if (test.operator && jsep2.binary_ops[test.operator] <= 0.9) {
954
+ let newTest = test;
955
+ while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
956
+ newTest = newTest.right;
957
+ }
958
+ env.node.test = newTest.right;
959
+ newTest.right = env.node;
960
+ env.node = test;
961
+ }
962
+ }
963
+ else {
964
+ this.throwError("Expected :");
965
+ }
966
+ }
967
+ });
968
+ }
969
+ };
970
+ jsep.plugins.register(ternary);
971
+ export default jsep;
972
+ //# sourceMappingURL=runtime.js.map