@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,179 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) 2013 Stephen Oney
3
+
4
+ declare namespace jsep {
5
+ export type baseTypes = string | number | boolean | RegExp | null | undefined | object;
6
+ export interface Expression {
7
+ type: string;
8
+ [key: string]: baseTypes | Expression | Array<baseTypes | Expression>;
9
+ }
10
+
11
+ export interface ArrayExpression extends Expression {
12
+ type: 'ArrayExpression';
13
+ /** The expression can be null in the case of array holes ([ , , ]) */
14
+ elements: Array<null | Expression>;
15
+ }
16
+
17
+ export interface BinaryExpression extends Expression {
18
+ type: 'BinaryExpression';
19
+ operator: string;
20
+ left: Expression;
21
+ right: Expression;
22
+ }
23
+
24
+ export interface CallExpression extends Expression {
25
+ type: 'CallExpression';
26
+ arguments: Expression[];
27
+ callee: Expression;
28
+ }
29
+
30
+ export interface Compound extends Expression {
31
+ type: 'Compound';
32
+ body: Expression[];
33
+ }
34
+
35
+ export interface SequenceExpression extends Expression {
36
+ type: 'SequenceExpression';
37
+ expressions: Expression[];
38
+ }
39
+
40
+ export interface ConditionalExpression extends Expression {
41
+ type: 'ConditionalExpression';
42
+ test: Expression;
43
+ consequent: Expression;
44
+ alternate: Expression;
45
+ }
46
+
47
+ export interface Identifier extends Expression {
48
+ type: 'Identifier';
49
+ name: string;
50
+ }
51
+
52
+ export interface Literal extends Expression {
53
+ type: 'Literal';
54
+ value: boolean | number | string | RegExp | null;
55
+ raw: string;
56
+ }
57
+
58
+ export interface MemberExpression extends Expression {
59
+ type: 'MemberExpression';
60
+ computed: boolean;
61
+ object: Expression;
62
+ property: Expression;
63
+ optional?: boolean;
64
+ }
65
+
66
+ export interface ThisExpression extends Expression {
67
+ type: 'ThisExpression';
68
+ }
69
+
70
+ export interface UnaryExpression extends Expression {
71
+ type: 'UnaryExpression';
72
+ operator: string;
73
+ argument: Expression;
74
+ prefix: boolean;
75
+ }
76
+
77
+ export type ExpressionType =
78
+ 'Compound'
79
+ | 'SequenceExpression'
80
+ | 'Identifier'
81
+ | 'MemberExpression'
82
+ | 'Literal'
83
+ | 'ThisExpression'
84
+ | 'CallExpression'
85
+ | 'UnaryExpression'
86
+ | 'BinaryExpression'
87
+ | 'ConditionalExpression'
88
+ | 'ArrayExpression';
89
+
90
+ export type CoreExpression =
91
+ ArrayExpression
92
+ | BinaryExpression
93
+ | CallExpression
94
+ | Compound
95
+ | SequenceExpression
96
+ | ConditionalExpression
97
+ | Identifier
98
+ | Literal
99
+ | MemberExpression
100
+ | ThisExpression
101
+ | UnaryExpression;
102
+
103
+ export type PossibleExpression = Expression | undefined;
104
+ export interface HookScope {
105
+ index: number;
106
+ readonly expr: string;
107
+ readonly char: string; // current character of the expression
108
+ readonly code: number; // current character code of the expression
109
+ gobbleSpaces: () => void;
110
+ gobbleExpressions: (untilICode?: number) => Expression[];
111
+ gobbleExpression: () => Expression;
112
+ gobbleBinaryOp: () => PossibleExpression;
113
+ gobbleBinaryExpression: () => PossibleExpression;
114
+ gobbleToken: () => PossibleExpression;
115
+ gobbleTokenProperty: (node: Expression) => Expression
116
+ gobbleNumericLiteral: () => PossibleExpression;
117
+ gobbleStringLiteral: () => PossibleExpression;
118
+ gobbleIdentifier: () => PossibleExpression;
119
+ gobbleArguments: (untilICode: number) => PossibleExpression;
120
+ gobbleGroup: () => Expression;
121
+ gobbleArray: () => PossibleExpression;
122
+ throwError: (msg: string) => never;
123
+ }
124
+
125
+ export type HookType = 'gobble-expression' | 'after-expression' | 'gobble-token' | 'after-token' | 'gobble-spaces';
126
+ export type HookCallback = (this: HookScope, env: { node?: Expression }) => void;
127
+ type HookTypeObj = Partial<{ [key in HookType]: HookCallback}>
128
+
129
+ export interface IHooks extends HookTypeObj {
130
+ add(name: HookType, cb: HookCallback, first?: boolean): void;
131
+ add(obj: { [name in HookType]: HookCallback }, first?: boolean): void;
132
+ run(name: string, env: { context?: typeof jsep, node?: Expression }): void;
133
+ }
134
+ let hooks: IHooks;
135
+
136
+ export interface IPlugin {
137
+ name: string;
138
+ init: (this: typeof jsep) => void;
139
+ }
140
+ export interface IPlugins {
141
+ registered: { [name: string]: IPlugin };
142
+ register: (...plugins: IPlugin[]) => void;
143
+ }
144
+ let plugins: IPlugins;
145
+
146
+ let unary_ops: { [op: string]: any };
147
+ let binary_ops: { [op: string]: number };
148
+ let right_associative: Set<string>;
149
+ let additional_identifier_chars: Set<string>;
150
+ let literals: { [literal: string]: any };
151
+ let this_str: string;
152
+
153
+ function addBinaryOp(operatorName: string, precedence: number, rightToLeft?: boolean): void;
154
+
155
+ function addUnaryOp(operatorName: string): void;
156
+
157
+ function addLiteral(literalName: string, literalValue: any): void;
158
+
159
+ function addIdentifierChar(identifierName: string): void;
160
+
161
+ function removeBinaryOp(operatorName: string): void;
162
+
163
+ function removeUnaryOp(operatorName: string): void;
164
+
165
+ function removeLiteral(literalName: string): void;
166
+
167
+ function removeIdentifierChar(identifierName: string): void;
168
+
169
+ function removeAllBinaryOps(): void;
170
+
171
+ function removeAllUnaryOps(): void;
172
+
173
+ function removeAllLiterals(): void;
174
+
175
+ const version: string;
176
+ }
177
+
178
+ declare function jsep(val: string | jsep.Expression): jsep.Expression;
179
+ export type {jsep as Jsep};
@@ -6,7 +6,7 @@
6
6
  // @eslint-disable
7
7
  // @ts-nocheck
8
8
 
9
- import type {NumericArray} from '@math.gl/types';
9
+ import type {NumericArray} from '../types';
10
10
  import * as glMatrix from './common.js';
11
11
 
12
12
  /**
package/src/index.ts CHANGED
@@ -16,9 +16,9 @@ export type {
16
16
  NumberArray9,
17
17
  NumberArray12,
18
18
  NumberArray16
19
- } from '@math.gl/types';
19
+ } from './types';
20
20
 
21
- export type {isTypedArray, isNumberArray, isNumericArray} from '@math.gl/types';
21
+ export type {isTypedArray, isNumberArray, isNumericArray} from './types';
22
22
 
23
23
  // classes
24
24
  export {MathArray as _MathArray} from './classes/base/math-array';
@@ -69,4 +69,4 @@ export {
69
69
  withEpsilon
70
70
  } from './lib/common';
71
71
 
72
- export type {SpheroidParameters} from '@math.gl/types';
72
+ export type {SpheroidParameters} from './types';
package/src/lib/common.ts CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  /* eslint-disable no-shadow */ // radians and degrees are common variable names
6
6
 
7
- import type {NumericArray} from '@math.gl/types';
7
+ import type {NumericArray} from '../types';
8
8
 
9
9
  import type {MathArray} from '../classes/base/math-array';
10
10
  import {EPSILON14, TWO_PI, PI} from './math-utils';
@@ -3,7 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable camelcase */
6
- import {NumericArray} from '@math.gl/types';
6
+ import {NumericArray} from '../types';
7
7
  // vec2 additions
8
8
 
9
9
  export function vec2_transformMat4AsVector<T extends NumericArray>(
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import {NumericArray} from '@math.gl/types';
5
+ import {NumericArray} from '../types';
6
6
  import {config} from './common';
7
7
 
8
8
  export function validateVector(v: NumericArray, length: number): boolean {
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
  // SPDX-FileComment: Original factored ENU/NED basis, rotations and matrix commits. No CesiumJS or PROJ source is copied.
5
- import type {NumericArray} from '@math.gl/types';
5
+ import type {NumericArray} from './types';
6
6
 
7
7
  export type LocalFramePoint = {x: number; y: number; z: number};
8
8
  export type LocalFrameAxis = 'east' | 'north' | 'up' | 'west' | 'south' | 'down';
package/src/spheroid.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  // SPDX-FileComment: Forward geocentric equations and Hannover inverse moved/adapted from math.gl projection's proj4js 2.22.0 datumUtils.js port. See ../PROJ4-LICENSE.md. Safeguarded nearest-footpoint inverse and numeric output commit are original math.gl code.
6
6
 
7
7
  /** Numeric leaf: angles in radians, distances in axis units; no CRS, global config or scratch. */
8
- import type {SpheroidParameters} from '@math.gl/types';
8
+ import type {SpheroidParameters} from './types';
9
9
  export type SpheroidGeometry = SpheroidParameters & {readonly eccentricitySquared: number};
10
10
  export type SpheroidPoint = {x: number; y: number; z: number};
11
11
 
@@ -0,0 +1,148 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ // Float16Array is declared in a separate TypeScript library. Preserve this reference so
6
+ // published declarations remain self-contained without changing the target or emitting runtime code.
7
+ // eslint-disable-next-line spaced-comment
8
+ /// <reference lib="es2025.float16" preserve="true" />
9
+
10
+ /**
11
+ * Type covering all non-big JavaScript typed arrays, including `Float16Array`.
12
+ *
13
+ * @remarks Including `Float16Array` does not guarantee that `globalThis.Float16Array` exists.
14
+ */
15
+ export type TypedArray =
16
+ | Int8Array
17
+ | Uint8Array
18
+ | Uint8ClampedArray
19
+ | Int16Array
20
+ | Uint16Array
21
+ | Int32Array
22
+ | Uint32Array
23
+ | Float16Array
24
+ | Float32Array
25
+ | Float64Array;
26
+
27
+ /**
28
+ * Type covering constructors for all non-big JavaScript typed arrays, including
29
+ * `Float16ArrayConstructor`.
30
+ *
31
+ * @remarks Including `Float16ArrayConstructor` does not install `globalThis.Float16Array`.
32
+ */
33
+ export type TypedArrayConstructor =
34
+ | Int8ArrayConstructor
35
+ | Uint8ArrayConstructor
36
+ | Uint8ClampedArrayConstructor
37
+ | Int16ArrayConstructor
38
+ | Uint16ArrayConstructor
39
+ | Int32ArrayConstructor
40
+ | Uint32ArrayConstructor
41
+ | Float16ArrayConstructor
42
+ | Float32ArrayConstructor
43
+ | Float64ArrayConstructor;
44
+
45
+ /**
46
+ * Type covering all big typed arrays
47
+ */
48
+ export type BigTypedArray = BigInt64Array | BigUint64Array;
49
+
50
+ /**
51
+ * Type covering constructors for all big typed arrays
52
+ */
53
+ export type BigTypedArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
54
+
55
+ /**
56
+ * Type for classic arrays consisting of numbers
57
+ * @note Included for completeness / orthogonality, prefer `number[]` in actual use
58
+ */
59
+ export type NumberArray = number[];
60
+
61
+ /** Array with exactly 1 number */
62
+ export type NumberArray1 = [number];
63
+
64
+ /** Array with exactly 2 numbers */
65
+ export type NumberArray2 = [number, number];
66
+
67
+ /** Array with exactly 3 numbers */
68
+ export type NumberArray3 = [number, number, number];
69
+
70
+ /** Array with exactly 4 numbers */
71
+ export type NumberArray4 = [number, number, number, number];
72
+
73
+ /** Array with exactly 6 numbers */
74
+ export type NumberArray6 = [number, number, number, number, number, number];
75
+
76
+ /** Array with exactly 8 numbers */
77
+ export type NumberArray8 = [number, number, number, number, number, number, number, number];
78
+
79
+ /** Array with exactly 9 numbers */
80
+ export type NumberArray9 = [number, number, number, number, number, number, number, number, number];
81
+
82
+ /** Array with exactly 12 numbers */
83
+ export type NumberArray12 = [
84
+ number,
85
+ number,
86
+ number,
87
+ number,
88
+ number,
89
+ number,
90
+ number,
91
+ number,
92
+ number,
93
+ number,
94
+ number,
95
+ number
96
+ ];
97
+
98
+ /** Array with exactly 16 numbers */
99
+ export type NumberArray16 = [
100
+ number,
101
+ number,
102
+ number,
103
+ number,
104
+ number,
105
+ number,
106
+ number,
107
+ number,
108
+ number,
109
+ number,
110
+ number,
111
+ number,
112
+ number,
113
+ number,
114
+ number,
115
+ number
116
+ ];
117
+
118
+ /**
119
+ * Type covering classic arrays consisting of numbers as well as typed arrays
120
+ */
121
+ export type NumericArray = TypedArray | number[];
122
+
123
+ /** Array with exactly 1 number, or a typed array */
124
+ export type NumericArray1 = NumberArray1 | TypedArray;
125
+
126
+ /** Array with exactly 2 numbers, or a typed array */
127
+ export type NumericArray2 = NumberArray2 | TypedArray;
128
+
129
+ /** Array with exactly 3 numbers, or a typed array */
130
+ export type NumericArray3 = NumberArray3 | TypedArray;
131
+
132
+ /** Array with exactly 4 numbers, or a typed array */
133
+ export type NumericArray4 = NumberArray4 | TypedArray;
134
+
135
+ /** Array with exactly 6 numbers, or a typed array */
136
+ export type NumericArray6 = NumberArray6 | TypedArray;
137
+
138
+ /** Array with exactly 8 numbers, or a typed array */
139
+ export type NumericArray8 = NumberArray8 | TypedArray;
140
+
141
+ /** Array with exactly 9 numbers, or a typed array */
142
+ export type NumericArray9 = NumberArray9 | TypedArray;
143
+
144
+ /** Array with exactly 12 numbers, or a typed array */
145
+ export type NumericArray12 = NumberArray12 | TypedArray;
146
+
147
+ /** Array with exactly 16 numbers, or a typed array */
148
+ export type NumericArray16 = NumberArray16 | TypedArray;
@@ -0,0 +1,56 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ // BigInt compatibility layer
6
+ // Inspired by ArrowJS (under Apache2 license)
7
+ // https://github.com/apache/arrow/blob/master/js/src/util/compat.ts
8
+ // Requires tsconfig.json: target=esnext or (lib: esnext.bigint)
9
+ // Requires eslint: env: {es2020: true}
10
+
11
+ const ERR_BIGINT_UNAVAILABLE = 'BigInt is not available in this environment';
12
+
13
+ function BigIntUnavailable() {
14
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
15
+ }
16
+ BigIntUnavailable.asIntN = () => {
17
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
18
+ };
19
+ BigIntUnavailable.asUintN = () => {
20
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
21
+ };
22
+
23
+ class BigInt64ArrayUnavailable {
24
+ static get BYTES_PER_ELEMENT() {
25
+ return 8;
26
+ }
27
+ static of() {
28
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
29
+ }
30
+ static from() {
31
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
32
+ }
33
+ constructor() {
34
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
35
+ }
36
+ }
37
+
38
+ export const BigIntAvailable = typeof BigInt !== 'undefined';
39
+ export const BigInt64ArrayAvailable = typeof BigInt64Array !== 'undefined';
40
+ export const BigUint64ArrayAvailable = typeof BigUint64Array !== 'undefined';
41
+
42
+ const BigIntCtor = (() => {
43
+ return BigIntAvailable ? BigInt : BigIntUnavailable;
44
+ })();
45
+
46
+ const BigInt64ArrayCtor = (() => {
47
+ return BigInt64ArrayAvailable ? BigInt64Array : BigInt64ArrayUnavailable;
48
+ })();
49
+
50
+ const BigUint64ArrayCtor = (() => {
51
+ return BigUint64ArrayAvailable ? [BigUint64Array] : [BigInt64ArrayUnavailable];
52
+ })();
53
+
54
+ export {BigIntCtor as BigInt};
55
+ export {BigInt64ArrayCtor as BigInt64Array};
56
+ export {BigUint64ArrayCtor as BigUint64Array};
@@ -0,0 +1,29 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** 2 dimensional bounds [[minX, minY], [maxX, maxY]] */
6
+ export type Bounds2D = [[number, number], [number, number]];
7
+
8
+ /** 3 dimensional bounds [[minX, minY, minZ], [maxX, maxY, maxZ]] */
9
+ export type Bounds3D = [[number, number, number], [number, number, number]];
10
+
11
+ /** 2 or 3 dimensional bounds [[minX, minY], [maxX, maxY]] or [[minX, minY, minZ], [maxX, maxY, maxZ]] */
12
+ export type Bounds =
13
+ | [[number, number], [number, number]]
14
+ | [[number, number, number], [number, number, number]];
15
+
16
+ /** Checks if a `Bounds` is a `Bounds2D` */
17
+ export function isBounds2D(bounds: Bounds): bounds is Bounds2D {
18
+ return bounds.length === 2;
19
+ }
20
+
21
+ /** Accepts 2D and 3D bounds and returns a 2D bound, truncating 3D dimension if necessary */
22
+ export function getBounds2D(bounds: Bounds): Bounds2D {
23
+ return isBounds2D(bounds)
24
+ ? bounds
25
+ : [
26
+ [bounds[0][0], bounds[0][1]],
27
+ [bounds[1][0], bounds[1][1]]
28
+ ];
29
+ }
@@ -0,0 +1,47 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {TypedArrayConstructor} from './array-types';
6
+ import {getTypedArrayName} from './typed-array-brand';
7
+
8
+ /**
9
+ * Checks for native Float16Array values, including arrays from other realms.
10
+ * Does not identify Uint16Array binary16 storage as a decoded Float16Array.
11
+ * Does not require a Float16Array constructor in the current realm.
12
+ */
13
+ export function isFloat16Array(value: unknown): value is Float16Array {
14
+ return getTypedArrayName(value) === 'Float16Array';
15
+ }
16
+
17
+ /**
18
+ * The native `Float16Array` constructor exposed by the current JavaScript runtime.
19
+ *
20
+ * @remarks This is `undefined` when the runtime does not provide `Float16Array`. The value is
21
+ * captured when this module is evaluated, so a polyfill must be installed before importing
22
+ * `@math.gl/core/types`.
23
+ */
24
+ export const NativeFloat16ArrayConstructor: TypedArrayConstructor | undefined =
25
+ globalThis.Float16Array;
26
+
27
+ /**
28
+ * Returns the typed array constructor used for half-precision storage.
29
+ *
30
+ * @returns The native `Float16Array` constructor when available, otherwise `Uint16Array`.
31
+ * @remarks The `Uint16Array` fallback stores encoded IEEE 754 binary16 bit patterns. Unlike a
32
+ * native `Float16Array`, it does not encode numeric assignments or decode values when read.
33
+ */
34
+ export function getFloat16ArrayConstructor(): TypedArrayConstructor {
35
+ return NativeFloat16ArrayConstructor ?? Uint16Array;
36
+ }
37
+
38
+ /**
39
+ * Checks whether a value is the native `Float16Array` constructor for the current runtime.
40
+ *
41
+ * @param value The value to test.
42
+ * @returns `true` when `value` matches `NativeFloat16ArrayConstructor`. Returns `false` for the
43
+ * `Uint16Array` fallback.
44
+ */
45
+ export function isFloat16ArrayConstructor(value: unknown): boolean {
46
+ return Boolean(NativeFloat16ArrayConstructor && value === NativeFloat16ArrayConstructor);
47
+ }
@@ -0,0 +1,45 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export type {
6
+ // typed arrays
7
+ TypedArray,
8
+ TypedArrayConstructor,
9
+ BigTypedArray,
10
+ BigTypedArrayConstructor,
11
+ // numeric arrays (sized number arrays)
12
+ NumberArray,
13
+ NumberArray1,
14
+ NumberArray2,
15
+ NumberArray3,
16
+ NumberArray4,
17
+ NumberArray6,
18
+ NumberArray8,
19
+ NumberArray9,
20
+ NumberArray12,
21
+ NumberArray16,
22
+ // numeric arrays (sized number arrays or typed arrays)
23
+ NumericArray,
24
+ NumericArray1,
25
+ NumericArray2,
26
+ NumericArray3,
27
+ NumericArray4,
28
+ NumericArray6,
29
+ NumericArray8,
30
+ NumericArray9,
31
+ NumericArray12,
32
+ NumericArray16
33
+ } from './array-types';
34
+
35
+ export {isTypedArray, isUint16Array, isNumberArray, isNumericArray} from './is-array';
36
+ export {
37
+ NativeFloat16ArrayConstructor,
38
+ getFloat16ArrayConstructor,
39
+ isFloat16ArrayConstructor,
40
+ isFloat16Array
41
+ } from './float16';
42
+
43
+ export type {Bounds, Bounds2D, Bounds3D} from './bounds-types';
44
+
45
+ export type {SpheroidParameters} from './spheroid';
@@ -0,0 +1,41 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {TypedArray, NumericArray, NumberArray} from './array-types';
6
+ import {getTypedArrayName} from './typed-array-brand';
7
+
8
+ /** Checks for unsigned 16-bit samples, including typed arrays from other realms. */
9
+ export function isUint16Array(value: unknown): value is Uint16Array {
10
+ return getTypedArrayName(value) === 'Uint16Array';
11
+ }
12
+
13
+ /**
14
+ * Check is an array is a typed array
15
+ * @param value value to be tested
16
+ * @returns input with type narrowed to TypedArray, or null
17
+ */
18
+ export function isTypedArray(value: unknown): value is TypedArray {
19
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
20
+ }
21
+
22
+ /**
23
+ * Check is an array is an array of numbers)
24
+ * @param value value to be tested
25
+ * @returns input with type narrowed to NumberArray, or null
26
+ */
27
+ export function isNumberArray(value: unknown): value is NumberArray {
28
+ if (Array.isArray(value)) {
29
+ return value.length === 0 || typeof value[0] === 'number';
30
+ }
31
+ return false;
32
+ }
33
+
34
+ /**
35
+ * Check is an array is a numeric array (typed array or array of numbers)
36
+ * @param value value to be tested
37
+ * @returns input with type narrowed to NumericArray, or null
38
+ */
39
+ export function isNumericArray(value: unknown): value is NumericArray {
40
+ return isTypedArray(value) || isNumberArray(value);
41
+ }
@@ -0,0 +1,11 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** Geometry of a sphere or oblate spheroid, in metres. No datum, axes or epoch metadata.
6
+ * Both axes must be finite and positive, with semiMinorAxis <= semiMajorAxis.
7
+ */
8
+ export type SpheroidParameters = {
9
+ readonly semiMajorAxis: number;
10
+ readonly semiMinorAxis: number;
11
+ };
@@ -0,0 +1,14 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ // Use the intrinsic getter so constructor and Symbol.toStringTag overrides cannot
6
+ // disguise a typed array's element type. It also works for arrays from other realms.
7
+ const typedArrayTagGetter = Object.getOwnPropertyDescriptor(
8
+ Object.getPrototypeOf(Uint8Array.prototype),
9
+ Symbol.toStringTag
10
+ )!.get!;
11
+
12
+ export function getTypedArrayName(value: unknown): string | undefined {
13
+ return ArrayBuffer.isView(value) ? typedArrayTagGetter.call(value) : undefined;
14
+ }
package/src/types.ts ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export * from './types/index';