@thi.ng/api 8.9.11 → 8.9.13

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.
package/typedarray.js CHANGED
@@ -1,276 +1,157 @@
1
- /**
2
- * WebGL numeric type constants. Use {@link GL2TYPE} to convert, if needed.
3
- *
4
- * {@link Type}
5
- * {@link GL2TYPE}
6
- * {@link TYPE2GL}
7
- */
8
- export var GLType;
9
- (function (GLType) {
10
- GLType[GLType["I8"] = 5120] = "I8";
11
- GLType[GLType["U8"] = 5121] = "U8";
12
- GLType[GLType["I16"] = 5122] = "I16";
13
- GLType[GLType["U16"] = 5123] = "U16";
14
- GLType[GLType["I32"] = 5124] = "I32";
15
- GLType[GLType["U32"] = 5125] = "U32";
16
- GLType[GLType["F32"] = 5126] = "F32";
17
- })(GLType || (GLType = {}));
18
- /**
19
- * Conversion from {@link GLType} to {@link Type} enums.
20
- */
21
- export const GL2TYPE = {
22
- [GLType.I8]: "i8",
23
- [GLType.U8]: "u8",
24
- [GLType.I16]: "i16",
25
- [GLType.U16]: "u16",
26
- [GLType.I32]: "i32",
27
- [GLType.U32]: "u32",
28
- [GLType.F32]: "f32",
1
+ var GLType = /* @__PURE__ */ ((GLType2) => {
2
+ GLType2[GLType2["I8"] = 5120] = "I8";
3
+ GLType2[GLType2["U8"] = 5121] = "U8";
4
+ GLType2[GLType2["I16"] = 5122] = "I16";
5
+ GLType2[GLType2["U16"] = 5123] = "U16";
6
+ GLType2[GLType2["I32"] = 5124] = "I32";
7
+ GLType2[GLType2["U32"] = 5125] = "U32";
8
+ GLType2[GLType2["F32"] = 5126] = "F32";
9
+ return GLType2;
10
+ })(GLType || {});
11
+ const GL2TYPE = {
12
+ [5120 /* I8 */]: "i8",
13
+ [5121 /* U8 */]: "u8",
14
+ [5122 /* I16 */]: "i16",
15
+ [5123 /* U16 */]: "u16",
16
+ [5124 /* I32 */]: "i32",
17
+ [5125 /* U32 */]: "u32",
18
+ [5126 /* F32 */]: "f32"
29
19
  };
30
- /**
31
- * Potentially lossy conversion from {@link Type} to {@link GLType} enums.
32
- *
33
- * Not all enums are mappable:
34
- *
35
- * - `F64` maps to `undefined`, since unsupported by WebGL
36
- * - `U8C` maps to "u8"
37
- */
38
- export const TYPE2GL = {
39
- i8: GLType.I8,
40
- u8: GLType.U8,
41
- u8c: GLType.U8,
42
- i16: GLType.I16,
43
- u16: GLType.U16,
44
- i32: GLType.I32,
45
- u32: GLType.U32,
46
- f32: GLType.F32,
47
- f64: undefined,
20
+ const TYPE2GL = {
21
+ i8: 5120 /* I8 */,
22
+ u8: 5121 /* U8 */,
23
+ u8c: 5121 /* U8 */,
24
+ i16: 5122 /* I16 */,
25
+ u16: 5123 /* U16 */,
26
+ i32: 5124 /* I32 */,
27
+ u32: 5125 /* U32 */,
28
+ f32: 5126 /* F32 */,
29
+ f64: void 0
48
30
  };
49
- /**
50
- * Size information (in bytes) for {@link Type} and {@link BigType}. Also see
51
- * {@link sizeOf}.
52
- */
53
- export const SIZEOF = {
54
- u8: 1,
55
- u8c: 1,
56
- i8: 1,
57
- u16: 2,
58
- i16: 2,
59
- u32: 4,
60
- i32: 4,
61
- i64: 8,
62
- u64: 8,
63
- f32: 4,
64
- f64: 8,
31
+ const SIZEOF = {
32
+ u8: 1,
33
+ u8c: 1,
34
+ i8: 1,
35
+ u16: 2,
36
+ i16: 2,
37
+ u32: 4,
38
+ i32: 4,
39
+ i64: 8,
40
+ u64: 8,
41
+ f32: 4,
42
+ f64: 8
65
43
  };
66
- /**
67
- * Bit shift values to convert byte addresses into array indices for all
68
- * {@link Type}s and {@link BigType}s.
69
- */
70
- export const BIT_SHIFTS = {
71
- i8: 0,
72
- u8: 0,
73
- u8c: 0,
74
- i16: 1,
75
- u16: 1,
76
- i32: 2,
77
- u32: 2,
78
- i64: 3,
79
- u64: 3,
80
- f32: 2,
81
- f64: 3,
44
+ const BIT_SHIFTS = {
45
+ i8: 0,
46
+ u8: 0,
47
+ u8c: 0,
48
+ i16: 1,
49
+ u16: 1,
50
+ i32: 2,
51
+ u32: 2,
52
+ i64: 3,
53
+ u64: 3,
54
+ f32: 2,
55
+ f64: 3
82
56
  };
83
- export const FLOAT_ARRAY_CTORS = {
84
- f32: Float32Array,
85
- f64: Float64Array,
57
+ const FLOAT_ARRAY_CTORS = {
58
+ f32: Float32Array,
59
+ f64: Float64Array
86
60
  };
87
- export const INT_ARRAY_CTORS = {
88
- i8: Int8Array,
89
- i16: Int16Array,
90
- i32: Int32Array,
61
+ const INT_ARRAY_CTORS = {
62
+ i8: Int8Array,
63
+ i16: Int16Array,
64
+ i32: Int32Array
91
65
  };
92
- export const UINT_ARRAY_CTORS = {
93
- u8: Uint8Array,
94
- u8c: Uint8ClampedArray,
95
- u16: Uint16Array,
96
- u32: Uint32Array,
66
+ const UINT_ARRAY_CTORS = {
67
+ u8: Uint8Array,
68
+ u8c: Uint8ClampedArray,
69
+ u16: Uint16Array,
70
+ u32: Uint32Array
97
71
  };
98
- export const BIGINT_ARRAY_CTORS = {
99
- i64: BigInt64Array,
100
- u64: BigUint64Array,
72
+ const BIGINT_ARRAY_CTORS = {
73
+ i64: BigInt64Array,
74
+ u64: BigUint64Array
101
75
  };
102
- export const TYPEDARRAY_CTORS = {
103
- ...FLOAT_ARRAY_CTORS,
104
- ...INT_ARRAY_CTORS,
105
- ...UINT_ARRAY_CTORS,
76
+ const TYPEDARRAY_CTORS = {
77
+ ...FLOAT_ARRAY_CTORS,
78
+ ...INT_ARRAY_CTORS,
79
+ ...UINT_ARRAY_CTORS
106
80
  };
107
- /**
108
- * Returns canonical {@link Type} value of `type` by first
109
- * attempting to resolve it as {@link GLType} enum.
110
- *
111
- * @example
112
- * ```ts
113
- * asNativeType(GLType.F32) => "f32"
114
- * asNativeType("f32") => "f32"
115
- * ```
116
- *
117
- * @param type -
118
- */
119
- export const asNativeType = (type) => {
120
- const t = GL2TYPE[type];
121
- return t !== undefined ? t : type;
81
+ const asNativeType = (type) => {
82
+ const t = GL2TYPE[type];
83
+ return t !== void 0 ? t : type;
122
84
  };
123
- /**
124
- * Returns suitable {@link GLType} enum of `type`.
125
- *
126
- * @example
127
- * ```ts
128
- * asGLType("f32") => GLType.F32
129
- * asGLType(GLType.F32) => GLType.F32
130
- * ```
131
- *
132
- * @param type -
133
- */
134
- export const asGLType = (type) => {
135
- const t = TYPE2GL[type];
136
- return t !== undefined ? t : type;
85
+ const asGLType = (type) => {
86
+ const t = TYPE2GL[type];
87
+ return t !== void 0 ? t : type;
137
88
  };
138
- /**
139
- * Coerces given numeric args to integer values.
140
- */
141
- export const asInt = (...args) => args.map((x) => x | 0);
142
- /**
143
- * Returns byte size for given {@link Type} ID or {@link GLType} enum.
144
- *
145
- * @param type -
146
- */
147
- export const sizeOf = (type) => SIZEOF[type] || SIZEOF[asNativeType(type)];
148
- export function typedArray(type, ...xs) {
149
- const ctor = BIGINT_ARRAY_CTORS[type];
150
- return new (ctor || TYPEDARRAY_CTORS[asNativeType(type)])(...xs);
89
+ const asInt = (...args) => args.map((x) => x | 0);
90
+ const sizeOf = (type) => SIZEOF[type] || SIZEOF[asNativeType(type)];
91
+ function typedArray(type, ...xs) {
92
+ const ctor = BIGINT_ARRAY_CTORS[type];
93
+ return new (ctor || TYPEDARRAY_CTORS[asNativeType(type)])(...xs);
151
94
  }
152
- export function typedArrayOfVec(type, data, stride) {
153
- const $data = Array.isArray(data) ? data : [...data];
154
- if (stride === undefined)
155
- stride = $data[0].length;
156
- const num = $data.length;
157
- const res = typedArray(type, num * stride);
158
- for (let i = 0, j = 0; i < num; i++, j += stride) {
159
- res.set($data[i], j);
160
- }
161
- return res;
95
+ function typedArrayOfVec(type, data, stride) {
96
+ const $data = Array.isArray(data) ? data : [...data];
97
+ if (stride === void 0)
98
+ stride = $data[0].length;
99
+ const num = $data.length;
100
+ const res = typedArray(type, num * stride);
101
+ for (let i = 0, j = 0; i < num; i++, j += stride) {
102
+ res.set($data[i], j);
103
+ }
104
+ return res;
162
105
  }
163
- /**
164
- * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
165
- * Standard JS arrays will default to {@link "f64"}.
166
- *
167
- * @param x -
168
- */
169
- export const typedArrayType = (x) => {
170
- if (Array.isArray(x))
171
- return "f64";
172
- for (let id in TYPEDARRAY_CTORS) {
173
- if (x instanceof TYPEDARRAY_CTORS[id])
174
- return id;
175
- }
106
+ const typedArrayType = (x) => {
107
+ if (Array.isArray(x))
176
108
  return "f64";
109
+ for (let id in TYPEDARRAY_CTORS) {
110
+ if (x instanceof TYPEDARRAY_CTORS[id])
111
+ return id;
112
+ }
113
+ return "f64";
114
+ };
115
+ const uintTypeForSize = (x) => x <= 256 ? "u8" : x <= 65536 ? "u16" : "u32";
116
+ const intTypeForSize = (x) => x >= -128 && x < 128 ? "i8" : x >= -32768 && x < 32768 ? "i16" : "i32";
117
+ const uintTypeForBits = (x) => x > 16 ? "u32" : x > 8 ? "u16" : "u8";
118
+ const intTypeForBits = (x) => x > 16 ? "i32" : x > 8 ? "i16" : "i8";
119
+ const narrowInt = (t) => t === "i64" ? "i32" : t === "i32" ? "i16" : t === "i16" ? "i8" : "i8";
120
+ const widenInt = (t) => t === "i8" ? "i16" : t === "i16" ? "i32" : t === "i32" ? "i64" : "i64";
121
+ const narrowUint = (t) => t === "u64" ? "u32" : t === "u32" ? "u16" : t === "u16" ? "u8" : "u8";
122
+ const widenUint = (t) => t === "u8" || t === "u8c" ? "u16" : t === "u16" ? "u32" : t === "u32" ? "u64" : "u64";
123
+ const narrowFloat = (t) => t === "f64" ? "f32" : "f32";
124
+ const widenFloat = (t) => t === "f32" ? "f64" : "f64";
125
+ const narrowType = (t) => t[0] === "i" ? narrowInt(t) : t[0] === "u" ? narrowUint(t) : narrowFloat(t);
126
+ const widenType = (t) => t[0] === "i" ? widenInt(t) : t[0] === "u" ? widenUint(t) : widenFloat(t);
127
+ export {
128
+ BIGINT_ARRAY_CTORS,
129
+ BIT_SHIFTS,
130
+ FLOAT_ARRAY_CTORS,
131
+ GL2TYPE,
132
+ GLType,
133
+ INT_ARRAY_CTORS,
134
+ SIZEOF,
135
+ TYPE2GL,
136
+ TYPEDARRAY_CTORS,
137
+ UINT_ARRAY_CTORS,
138
+ asGLType,
139
+ asInt,
140
+ asNativeType,
141
+ intTypeForBits,
142
+ intTypeForSize,
143
+ narrowFloat,
144
+ narrowInt,
145
+ narrowType,
146
+ narrowUint,
147
+ sizeOf,
148
+ typedArray,
149
+ typedArrayOfVec,
150
+ typedArrayType,
151
+ uintTypeForBits,
152
+ uintTypeForSize,
153
+ widenFloat,
154
+ widenInt,
155
+ widenType,
156
+ widenUint
177
157
  };
178
- /**
179
- * Returns the smallest possible *unsigned* int type enum for given `x`.
180
- * E.g. if `x <= 256`, the function returns `"u8"`.
181
- *
182
- * @param x - value to classify
183
- */
184
- export const uintTypeForSize = (x) => x <= 0x100 ? "u8" : x <= 0x10000 ? "u16" : "u32";
185
- /**
186
- * Returns the smallest possible *signed* int type enum for given `x`.
187
- * E.g. if `x >= -128 && x < 128`, the function returns `"i8"`.
188
- *
189
- * @param x - value to classify
190
- */
191
- export const intTypeForSize = (x) => x >= -0x80 && x < 0x80 ? "i8" : x >= -0x8000 && x < 0x8000 ? "i16" : "i32";
192
- /**
193
- * Returns suitable {@link UintType} for given bit size (`[0,32]` range)
194
- *
195
- * @param x -
196
- */
197
- export const uintTypeForBits = (x) => x > 16 ? "u32" : x > 8 ? "u16" : "u8";
198
- /**
199
- * Returns suitable {@link IntType} for given bit size (`[0,32]` range)
200
- *
201
- * @param x -
202
- */
203
- export const intTypeForBits = (x) => x > 16 ? "i32" : x > 8 ? "i16" : "i8";
204
- /**
205
- * Returns the next smaller {@link IntType} for given type (or the same type if
206
- * already the narrowest).
207
- *
208
- * @param t
209
- */
210
- export const narrowInt = (t) => t === "i64" ? "i32" : t === "i32" ? "i16" : t === "i16" ? "i8" : "i8";
211
- /**
212
- * Returns the next larger {@link IntType} for given type (or the same type if
213
- * already the widest).
214
- *
215
- * @param t
216
- */
217
- export const widenInt = (t) => t === "i8" ? "i16" : t === "i16" ? "i32" : t === "i32" ? "i64" : "i64";
218
- /**
219
- * Returns the next smaller {@link UintType} for given type (or the same type if
220
- * already the narrowest).
221
- *
222
- * @remarks
223
- * If type is `u8c`, returns `u8`.
224
- *
225
- * @param t
226
- */
227
- export const narrowUint = (t) => t === "u64" ? "u32" : t === "u32" ? "u16" : t === "u16" ? "u8" : "u8";
228
- /**
229
- * Returns the next larger {@link UintType} for given type (or the same type if
230
- * already the widest).
231
- *
232
- * @param t
233
- */
234
- export const widenUint = (t) => t === "u8" || t === "u8c"
235
- ? "u16"
236
- : t === "u16"
237
- ? "u32"
238
- : t === "u32"
239
- ? "u64"
240
- : "u64";
241
- /**
242
- * Returns the next smaller {@link FloatType} for given type (or the same type
243
- * if already the narrowest).
244
- *
245
- * @param t
246
- */
247
- export const narrowFloat = (t) => (t === "f64" ? "f32" : "f32");
248
- /**
249
- * Returns the next larger {@link FloatType} for given type (or the same type if
250
- * already the widest).
251
- *
252
- * @param t
253
- */
254
- export const widenFloat = (t) => (t === "f32" ? "f64" : "f64");
255
- /**
256
- * Returns the next smaller type (i.e. {@link IntType}, {@link UintType} or
257
- * {@link FloatType}) for given type (or the same type if already the smallest).
258
- *
259
- * @param t
260
- */
261
- export const narrowType = (t) => t[0] === "i"
262
- ? narrowInt(t)
263
- : t[0] === "u"
264
- ? narrowUint(t)
265
- : narrowFloat(t);
266
- /**
267
- * Returns the next larger type (i.e. {@link IntType}, {@link UintType} or
268
- * {@link FloatType}) for given type (or the same type if already the widest).
269
- *
270
- * @param t
271
- */
272
- export const widenType = (t) => t[0] === "i"
273
- ? widenInt(t)
274
- : t[0] === "u"
275
- ? widenUint(t)
276
- : widenFloat(t);
package/watch.js CHANGED
@@ -1 +0,0 @@
1
- export {};