@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,163 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {ExpressionFunction, ExpressionFunctionLibrary} from './function-libraries';
6
+
7
+ const FUNCTION_NAME_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
8
+ const DISALLOWED_FUNCTION_NAMES = new Set(['__proto__', 'prototype', 'constructor']);
9
+
10
+ /**
11
+ * Options for registering functions with an {@link ExpressionFunctionRegistry}.
12
+ */
13
+ export type FunctionRegistrationOptions = {
14
+ /**
15
+ * Replace an existing function with the same name.
16
+ *
17
+ * @defaultValue false
18
+ */
19
+ replace?: boolean;
20
+ };
21
+
22
+ /**
23
+ * An isolated collection of named functions available to expression evaluators.
24
+ *
25
+ * @remarks
26
+ * Registries are instance scoped. Registering a function does not affect other
27
+ * registries or evaluators that do not receive the registry.
28
+ *
29
+ * Function names must be valid JavaScript-style identifiers so they can be
30
+ * called directly from JSEP expressions.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const registry = new ExpressionFunctionRegistry()
35
+ * .registerFunction('double', (value) => value * 2)
36
+ * .registerFunctions(BASIC_MATH_FUNCTION_LIBRARY);
37
+ *
38
+ * const evaluate = compile('double(round(value))', {registry});
39
+ * evaluate({value: 2.4});
40
+ * ```
41
+ */
42
+ export class ExpressionFunctionRegistry {
43
+ private readonly functions = Object.create(null) as ExpressionFunctionLibrary;
44
+
45
+ /**
46
+ * Creates a function registry.
47
+ *
48
+ * @param functionTables - Function tables to register in order.
49
+ * @throws If a table contains an invalid or duplicate function name.
50
+ */
51
+ constructor(functionTables: readonly ExpressionFunctionLibrary[] = []) {
52
+ for (const functionTable of functionTables) {
53
+ this.registerFunctions(functionTable);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Registers one named function.
59
+ *
60
+ * @param name - Identifier used to call the function from an expression.
61
+ * @param fn - JavaScript function invoked with evaluated expression arguments.
62
+ * @param options - Duplicate registration behavior.
63
+ * @returns This registry.
64
+ * @throws If the name is invalid, the value is not a function, or the name is
65
+ * already registered and replacement was not requested.
66
+ */
67
+ registerFunction(
68
+ name: string,
69
+ fn: ExpressionFunction,
70
+ options: FunctionRegistrationOptions = {}
71
+ ): this {
72
+ validateFunction(name, fn);
73
+ if (this.hasFunction(name) && !options.replace) {
74
+ throw new Error(`Expression function "${name}" is already registered.`);
75
+ }
76
+ this.functions[name] = fn;
77
+ return this;
78
+ }
79
+
80
+ /**
81
+ * Registers all entries in a function table.
82
+ *
83
+ * @param functionTable - Map from expression identifiers to JavaScript functions.
84
+ * @param options - Duplicate registration behavior.
85
+ * @returns This registry.
86
+ * @throws If any entry is invalid or conflicts with an existing registration.
87
+ *
88
+ * @remarks
89
+ * Validation is atomic: no entries are registered when any entry is invalid.
90
+ */
91
+ registerFunctions(
92
+ functionTable: ExpressionFunctionLibrary,
93
+ options: FunctionRegistrationOptions = {}
94
+ ): this {
95
+ const entries = Object.entries(functionTable);
96
+ const names = new Set<string>();
97
+
98
+ for (const [name, fn] of entries) {
99
+ validateFunction(name, fn);
100
+ if (names.has(name) || (this.hasFunction(name) && !options.replace)) {
101
+ throw new Error(`Expression function "${name}" is already registered.`);
102
+ }
103
+ names.add(name);
104
+ }
105
+
106
+ for (const [name, fn] of entries) {
107
+ this.functions[name] = fn;
108
+ }
109
+ return this;
110
+ }
111
+
112
+ /**
113
+ * Removes a registered function.
114
+ *
115
+ * @param name - Function name to remove.
116
+ * @returns `true` when a function was removed.
117
+ */
118
+ unregisterFunction(name: string): boolean {
119
+ if (!this.hasFunction(name)) {
120
+ return false;
121
+ }
122
+ return delete this.functions[name];
123
+ }
124
+
125
+ /**
126
+ * Tests whether a function is registered.
127
+ *
128
+ * @param name - Function name to inspect.
129
+ * @returns `true` when the registry contains the name.
130
+ */
131
+ hasFunction(name: string): boolean {
132
+ return Object.prototype.hasOwnProperty.call(this.functions, name);
133
+ }
134
+
135
+ /**
136
+ * Returns a registered function.
137
+ *
138
+ * @param name - Function name to retrieve.
139
+ * @returns The registered function, or `undefined`.
140
+ */
141
+ getFunction(name: string): ExpressionFunction | undefined {
142
+ return this.functions[name];
143
+ }
144
+
145
+ /**
146
+ * Returns an immutable snapshot of all registered functions.
147
+ *
148
+ * @returns A frozen function table.
149
+ */
150
+ getFunctionTable(): Readonly<ExpressionFunctionLibrary> {
151
+ return Object.freeze({...this.functions});
152
+ }
153
+ }
154
+
155
+ /** Validates one registry entry. */
156
+ function validateFunction(name: string, fn: ExpressionFunction): void {
157
+ if (!FUNCTION_NAME_PATTERN.test(name) || DISALLOWED_FUNCTION_NAMES.has(name)) {
158
+ throw new Error(`Invalid expression function name "${name}".`);
159
+ }
160
+ if (typeof fn !== 'function') {
161
+ throw new TypeError(`Expression function "${name}" must be a function.`);
162
+ }
163
+ }
@@ -0,0 +1,37 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * Access properties of nested containers using dot-path notation.
7
+ *
8
+ * @param container - Object from which to read a value.
9
+ * @param compositeKey - Dot-separated property path.
10
+ * @returns The nested value, or `undefined` when the path cannot be resolved.
11
+ */
12
+ export function get(container: Record<string, unknown>, compositeKey: string): unknown {
13
+ let value: unknown = container;
14
+
15
+ for (const key of getKeys(compositeKey)) {
16
+ value = isObject(value) ? value[key] : undefined;
17
+ }
18
+
19
+ return value;
20
+ }
21
+
22
+ /** Tests whether a value can be used for property access. */
23
+ function isObject(value: unknown): value is Record<string, unknown> {
24
+ return value !== null && typeof value === 'object';
25
+ }
26
+
27
+ const keyMap: Record<string, string[]> = {};
28
+
29
+ /** Returns a cached list of property names for a dot-separated path. */
30
+ function getKeys(compositeKey: string): string[] {
31
+ let keyList = keyMap[compositeKey];
32
+ if (!keyList) {
33
+ keyList = compositeKey.split('.');
34
+ keyMap[compositeKey] = keyList;
35
+ }
36
+ return keyList;
37
+ }
@@ -0,0 +1,22 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export type {
6
+ ExpressionEvaluationOptions,
7
+ ExpressionFunction,
8
+ ExpressionFunctionLibrary
9
+ } from './function-libraries';
10
+ export {ExpressionFunctionRegistry, type FunctionRegistrationOptions} from './function-registry';
11
+ export type {BinaryOperator, Expression, ExpressionContext, UnaryOperator} from './expression-eval';
12
+ export {
13
+ addBinaryOp,
14
+ addUnaryOp,
15
+ compile,
16
+ compileAsync,
17
+ eval,
18
+ evalAsync,
19
+ parse
20
+ } from './expression-eval';
21
+ export {BASIC_MATH_FUNCTION_LIBRARY, mergeFunctionLibraries} from './function-libraries';
22
+ export {parseExpressionString, type AccessorFunction} from './parse-expression-string';
@@ -0,0 +1,80 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {Jsep as jsep} from './vendor/jsep/types';
6
+ import {eval as evaluate, parse} from './expression-eval';
7
+ import {get} from './get';
8
+
9
+ /**
10
+ * An accessor compiled from a JSON-style expression string.
11
+ *
12
+ * @param row - Data object against which the expression is evaluated.
13
+ * @returns The value produced by the expression.
14
+ */
15
+ export type AccessorFunction = (row: Record<string, unknown>) => unknown;
16
+
17
+ const cachedExpressionMap: Record<string, AccessorFunction> = {
18
+ '-': object => object
19
+ };
20
+
21
+ /**
22
+ * Compiles a JSON-style expression string into an accessor function.
23
+ *
24
+ * @param propValue - Accessor expression to compile.
25
+ * @returns A cached accessor function.
26
+ * @throws If the expression is invalid or contains a function call.
27
+ *
28
+ * @remarks
29
+ * `-` maps to the identity accessor and `a.b.c` maps to nested property
30
+ * access. Function calls are rejected so accessors cannot execute functions
31
+ * supplied by input data.
32
+ */
33
+ export function parseExpressionString(propValue: string): AccessorFunction {
34
+ if (propValue in cachedExpressionMap) {
35
+ return cachedExpressionMap[propValue];
36
+ }
37
+
38
+ const ast = parse(propValue);
39
+ const func =
40
+ ast.type === 'Identifier'
41
+ ? (row: Record<string, unknown>) => get(row, propValue)
42
+ : compileAst(ast);
43
+
44
+ cachedExpressionMap[propValue] = func;
45
+ return func;
46
+ }
47
+
48
+ /** Validates and compiles a parsed accessor expression. */
49
+ function compileAst(ast: jsep.Expression): AccessorFunction {
50
+ traverse(ast, node => {
51
+ if (node.type === 'CallExpression') {
52
+ throw new Error('Function calls not allowed in expression accessors');
53
+ }
54
+ });
55
+
56
+ return (row: Record<string, unknown>) => evaluate(ast, row);
57
+ }
58
+
59
+ /** Visits each AST-like object in a parsed expression. */
60
+ // eslint-disable-next-line complexity
61
+ function traverse(node: unknown, visitor: (node: {type: string}) => void): void {
62
+ if (Array.isArray(node)) {
63
+ node.forEach(element => traverse(element, visitor));
64
+ return;
65
+ }
66
+
67
+ if (node && typeof node === 'object') {
68
+ if (isNodeLike(node)) {
69
+ visitor(node);
70
+ }
71
+ for (const key in node) {
72
+ traverse((node as Record<string, unknown>)[key], visitor);
73
+ }
74
+ }
75
+ }
76
+
77
+ /** Tests whether an object resembles a JSEP AST node. */
78
+ function isNodeLike(node: object): node is {type: string} {
79
+ return 'type' in node && typeof (node as {type?: unknown}).type === 'string';
80
+ }
@@ -0,0 +1,23 @@
1
+ SPDX-License-Identifier: MIT
2
+ SPDX-FileCopyrightText: Copyright (c) 2013 Stephen Oney
3
+
4
+ Copyright (c) 2013 Stephen Oney, https://ericsmekens.github.io/jsep/
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ <!--
2
+ SPDX-License-Identifier: MIT
3
+ SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ -->
5
+
6
+ # Vendored jsep
7
+
8
+ - Upstream: https://github.com/EricSmekens/jsep
9
+ - npm release: jsep 1.4.0 (MIT).
10
+ - Source: published dist/jsep.js and typings/tsd.d.ts.
11
+ - runtime.ts is the ESM runtime bundled without minification; its private default export is typed as any at the boundary. types.ts preserves the upstream declarations, replacing the ambient npm module wrapper with a local Jsep export. No parser algorithms are changed.
12
+ - LICENSE.txt retains the complete upstream license and copyright notice. It is distributed in the package's src directory.
13
+
14
+ ## Refreshing
15
+
16
+ From the repository root after yarn install, run:
17
+
18
+ ```sh
19
+ node scripts/vendor-expression-timezone-deps.mjs
20
+ ```
21
+
22
+ The script pins upstream releases and SHA-512 tarball integrity values, verifies downloads, and never runs upstream package scripts. The repository lockfile pins the esbuild tool used for generation. Review upstream changes and licenses before changing pins. Keep the SPDX headers and license files when refreshing. Run the repository's build and existing expression/timezone and package boundary checks after a refresh. Vendored files are excluded from automatic formatting to preserve reproducible output.