@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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +15 -17
- package/assoc.js +0 -1
- package/bind.js +0 -1
- package/buffered.js +0 -1
- package/clear.js +0 -1
- package/compare.js +0 -1
- package/contains.js +0 -1
- package/copy.js +0 -1
- package/decorators/configurable.js +5 -8
- package/decorators/deprecated.js +14 -19
- package/decorators/nomixin.js +5 -9
- package/decorators/sealed.js +6 -8
- package/deref.js +6 -13
- package/dissoc.js +0 -1
- package/empty.js +0 -1
- package/enable.js +0 -1
- package/equiv.js +0 -1
- package/event.js +0 -1
- package/fn.js +8 -14
- package/get.js +0 -1
- package/grid.js +0 -1
- package/hash.js +0 -1
- package/hiccup.js +0 -1
- package/id.js +0 -1
- package/indexed.js +0 -1
- package/into.js +0 -1
- package/keyval.js +0 -1
- package/length.js +0 -1
- package/meta.js +0 -1
- package/mixin.js +31 -41
- package/mixins/ienable.js +22 -25
- package/mixins/igrid.js +116 -158
- package/mixins/inotify.js +57 -58
- package/mixins/iterable.js +7 -4
- package/mixins/iwatch.js +29 -26
- package/null.js +0 -1
- package/object.js +0 -1
- package/package.json +7 -4
- package/path.js +0 -1
- package/predicate.js +0 -1
- package/prim.js +0 -1
- package/range.js +0 -1
- package/release.js +0 -1
- package/reset.js +0 -1
- package/select.js +0 -1
- package/seq.js +0 -1
- package/set.js +0 -1
- package/stack.js +0 -1
- package/tuple.js +0 -1
- package/typedarray.js +142 -261
- package/watch.js +0 -1
package/typedarray.js
CHANGED
|
@@ -1,276 +1,157 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
57
|
+
const FLOAT_ARRAY_CTORS = {
|
|
58
|
+
f32: Float32Array,
|
|
59
|
+
f64: Float64Array
|
|
86
60
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
61
|
+
const INT_ARRAY_CTORS = {
|
|
62
|
+
i8: Int8Array,
|
|
63
|
+
i16: Int16Array,
|
|
64
|
+
i32: Int32Array
|
|
91
65
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
66
|
+
const UINT_ARRAY_CTORS = {
|
|
67
|
+
u8: Uint8Array,
|
|
68
|
+
u8c: Uint8ClampedArray,
|
|
69
|
+
u16: Uint16Array,
|
|
70
|
+
u32: Uint32Array
|
|
97
71
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
72
|
+
const BIGINT_ARRAY_CTORS = {
|
|
73
|
+
i64: BigInt64Array,
|
|
74
|
+
u64: BigUint64Array
|
|
101
75
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
76
|
+
const TYPEDARRAY_CTORS = {
|
|
77
|
+
...FLOAT_ARRAY_CTORS,
|
|
78
|
+
...INT_ARRAY_CTORS,
|
|
79
|
+
...UINT_ARRAY_CTORS
|
|
106
80
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
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 {};
|