@limitlesspc/std 0.21.1 → 0.23.0
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/dist/array.d.ts +21 -4
- package/dist/array.js +5 -4
- package/dist/async/index.d.ts +1 -1
- package/dist/async/index.js +1 -13
- package/dist/{chunk-65SNM7MP.js → chunk-4POIKW4G.js} +9 -13
- package/dist/{chunk-WBSY6KRH.js → chunk-CCBSTDYA.js} +1 -1
- package/dist/{chunk-WNQNVZFS.js → chunk-ONMV3ICF.js} +219 -282
- package/dist/{chunk-O3YCU3KN.js → chunk-SSSOLDLG.js} +2 -2
- package/dist/cmath/index.js +1 -1
- package/dist/events.js +5 -6
- package/dist/fn/index.d.ts +14 -1
- package/dist/fn/index.js +1 -2
- package/dist/gfx/index.d.ts +1 -1
- package/dist/gfx/index.js +5 -6
- package/dist/iter/index.js +2 -3
- package/dist/math/index.d.ts +58 -58
- package/dist/math/index.js +7 -14
- package/dist/random.js +4 -5
- package/dist/string/index.js +5 -3
- package/dist/structs/index.d.ts +2 -75
- package/dist/structs/index.js +232 -18
- package/dist/types.js +0 -1
- package/dist/{vec3-S_YuL-W1.d.ts → vec3-BQ6mZ-wg.d.ts} +14 -24
- package/package.json +46 -50
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-DYKZK6B5.js +0 -523
- package/dist/easing.d.ts +0 -37
- package/dist/easing.js +0 -157
- /package/dist/{chunk-MG5VQSTV.js → chunk-NXILTE26.js} +0 -0
package/dist/structs/index.js
CHANGED
|
@@ -1,24 +1,238 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "../chunk-DYKZK6B5.js";
|
|
10
|
-
import "../chunk-65SNM7MP.js";
|
|
11
|
-
import "../chunk-WBSY6KRH.js";
|
|
12
|
-
import "../chunk-MG5VQSTV.js";
|
|
13
|
-
import "../chunk-6F4PWJZI.js";
|
|
14
|
-
import "../chunk-TMLWLR46.js";
|
|
2
|
+
swap
|
|
3
|
+
} from "../chunk-4POIKW4G.js";
|
|
4
|
+
import "../chunk-CCBSTDYA.js";
|
|
5
|
+
import "../chunk-NXILTE26.js";
|
|
6
|
+
import {
|
|
7
|
+
ascend
|
|
8
|
+
} from "../chunk-TMLWLR46.js";
|
|
15
9
|
import "../chunk-LJSF3QBT.js";
|
|
10
|
+
|
|
11
|
+
// src/structs/heap.ts
|
|
12
|
+
var Heap = class _Heap {
|
|
13
|
+
constructor(compare, data = [], heapify = true) {
|
|
14
|
+
this.compare = compare;
|
|
15
|
+
if (heapify) {
|
|
16
|
+
this.data = [];
|
|
17
|
+
this.push(...data);
|
|
18
|
+
} else {
|
|
19
|
+
this.data = data;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
data;
|
|
23
|
+
get length() {
|
|
24
|
+
return this.data.length;
|
|
25
|
+
}
|
|
26
|
+
get height() {
|
|
27
|
+
return Math.floor(Math.log2(this.length)) + 1;
|
|
28
|
+
}
|
|
29
|
+
valueOf() {
|
|
30
|
+
return this.peek();
|
|
31
|
+
}
|
|
32
|
+
copy() {
|
|
33
|
+
return new _Heap(this.compare, [...this.data], false);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the first value in the heap
|
|
37
|
+
*/
|
|
38
|
+
peek() {
|
|
39
|
+
return this.data[0];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Removes the first value from the heap and returns it
|
|
43
|
+
*/
|
|
44
|
+
pop() {
|
|
45
|
+
const first = this.data[0];
|
|
46
|
+
swap(this.data, 0, this.length - 1);
|
|
47
|
+
this.data.pop();
|
|
48
|
+
this.heapify();
|
|
49
|
+
return first;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Inserts values into the heap and makes sure the first value is the min/max
|
|
53
|
+
* @param values
|
|
54
|
+
* @returns The new length of the heap
|
|
55
|
+
*/
|
|
56
|
+
push(...values) {
|
|
57
|
+
const { data, compare } = this;
|
|
58
|
+
for (const value of values) {
|
|
59
|
+
data.push(value);
|
|
60
|
+
let i = data.length - 1;
|
|
61
|
+
let parent = Math.floor((i - 1) / 2);
|
|
62
|
+
while (i > 0 && compare(data[i], data[parent]) < 0) {
|
|
63
|
+
swap(data, i, parent);
|
|
64
|
+
i = parent;
|
|
65
|
+
parent = Math.floor((i - 1) / 2);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return data.length;
|
|
69
|
+
}
|
|
70
|
+
*drain() {
|
|
71
|
+
while (this.length) {
|
|
72
|
+
yield this.pop();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
[Symbol.iterator]() {
|
|
76
|
+
return this.data.values();
|
|
77
|
+
}
|
|
78
|
+
heapify(i = 0) {
|
|
79
|
+
const { length, compare, data } = this;
|
|
80
|
+
const left = 2 * i + 1;
|
|
81
|
+
const right = 2 * i + 2;
|
|
82
|
+
let largest = i;
|
|
83
|
+
if (left < length && compare(data[left], data[largest]) < 0) {
|
|
84
|
+
largest = left;
|
|
85
|
+
}
|
|
86
|
+
if (right < length && compare(data[right], data[largest]) < 0) {
|
|
87
|
+
largest = right;
|
|
88
|
+
}
|
|
89
|
+
if (largest !== i) {
|
|
90
|
+
swap(data, i, largest);
|
|
91
|
+
this.heapify(largest);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/structs/sorted-array.ts
|
|
97
|
+
var SortedArray = class _SortedArray {
|
|
98
|
+
constructor(data = [], compare = ascend, sort = true) {
|
|
99
|
+
this.data = data;
|
|
100
|
+
this.compare = compare;
|
|
101
|
+
if (sort) {
|
|
102
|
+
this.data.sort(compare);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
valueOf() {
|
|
106
|
+
return this.at(0);
|
|
107
|
+
}
|
|
108
|
+
keys() {
|
|
109
|
+
return this.data.keys();
|
|
110
|
+
}
|
|
111
|
+
values() {
|
|
112
|
+
return this.data.values();
|
|
113
|
+
}
|
|
114
|
+
entries() {
|
|
115
|
+
return this.data.entries();
|
|
116
|
+
}
|
|
117
|
+
[Symbol.iterator]() {
|
|
118
|
+
return this.values();
|
|
119
|
+
}
|
|
120
|
+
length() {
|
|
121
|
+
return this.data.length;
|
|
122
|
+
}
|
|
123
|
+
at(index) {
|
|
124
|
+
return this.data[index];
|
|
125
|
+
}
|
|
126
|
+
copy() {
|
|
127
|
+
return new _SortedArray([...this.data], this.compare, false);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns the index of the value if it exists, otherwise -1
|
|
131
|
+
* @param value
|
|
132
|
+
*/
|
|
133
|
+
indexOf(value) {
|
|
134
|
+
const { data } = this;
|
|
135
|
+
let low = 0;
|
|
136
|
+
let high = data.length - 1;
|
|
137
|
+
while (low <= high) {
|
|
138
|
+
const mid = Math.floor((low + high) / 2);
|
|
139
|
+
const cmp = this.compare(value, data[mid]);
|
|
140
|
+
if (cmp < 0) {
|
|
141
|
+
high = mid - 1;
|
|
142
|
+
} else if (cmp > 0) {
|
|
143
|
+
low = mid + 1;
|
|
144
|
+
} else {
|
|
145
|
+
return mid;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return -1;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns if the array has the value
|
|
152
|
+
* @param value
|
|
153
|
+
*/
|
|
154
|
+
has(value) {
|
|
155
|
+
return this.indexOf(value) !== -1;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Binary inserts a value into the array while maintaining sorted order
|
|
159
|
+
* @param value
|
|
160
|
+
* @returns the index of where the value was inserted
|
|
161
|
+
*/
|
|
162
|
+
push(value) {
|
|
163
|
+
const { data, compare } = this;
|
|
164
|
+
let low = 0;
|
|
165
|
+
let high = data.length - 1;
|
|
166
|
+
while (low <= high) {
|
|
167
|
+
const mid = Math.floor((low + high) / 2);
|
|
168
|
+
const cmp = compare(value, data[mid]);
|
|
169
|
+
if (cmp < 0) {
|
|
170
|
+
high = mid - 1;
|
|
171
|
+
} else if (cmp > 0) {
|
|
172
|
+
low = mid + 1;
|
|
173
|
+
} else {
|
|
174
|
+
data.splice(mid, 0, value);
|
|
175
|
+
return mid;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
data.splice(low, 0, value);
|
|
179
|
+
return low;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/structs/unordered-array.ts
|
|
184
|
+
var UnorderedArray = class _UnorderedArray extends Array {
|
|
185
|
+
copy() {
|
|
186
|
+
return new _UnorderedArray(...this);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Inserts new elements at the end of an unordered array, and returns the new length of the unordered array.
|
|
190
|
+
* @param items Elements to insert at the end of the array.
|
|
191
|
+
*/
|
|
192
|
+
unshift(...items) {
|
|
193
|
+
return super.push(...items);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Removes the last element from an array and returns it.
|
|
197
|
+
* If the array is empty, undefined is returned and the array is not modified.
|
|
198
|
+
*/
|
|
199
|
+
shift() {
|
|
200
|
+
return super.pop();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Removes an item by index
|
|
204
|
+
* @param index the index of the item to remove
|
|
205
|
+
* @returns the removed item, if it exists
|
|
206
|
+
*/
|
|
207
|
+
removeIndex(index) {
|
|
208
|
+
swap(this, index, this.length - 1);
|
|
209
|
+
return this.pop();
|
|
210
|
+
}
|
|
211
|
+
splice(start, deleteCount = this.length - start, ...items) {
|
|
212
|
+
const spliced = [];
|
|
213
|
+
for (let i = 0; i < deleteCount; i++) {
|
|
214
|
+
const replacement = items[i];
|
|
215
|
+
let removed;
|
|
216
|
+
if (replacement) {
|
|
217
|
+
removed = this[start + i];
|
|
218
|
+
this[start + i] = replacement;
|
|
219
|
+
} else {
|
|
220
|
+
removed = this.removeIndex(start);
|
|
221
|
+
}
|
|
222
|
+
if (removed) {
|
|
223
|
+
spliced.push(removed);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return spliced;
|
|
227
|
+
}
|
|
228
|
+
toSpliced(start, deleteCount = this.length - start, ...items) {
|
|
229
|
+
const copy = this.copy();
|
|
230
|
+
copy.splice(start, deleteCount, ...items);
|
|
231
|
+
return copy;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
16
234
|
export {
|
|
17
|
-
|
|
18
|
-
LinkedList,
|
|
19
|
-
MaxHeap,
|
|
20
|
-
MinHeap,
|
|
21
|
-
Queue,
|
|
235
|
+
Heap,
|
|
22
236
|
SortedArray,
|
|
23
237
|
UnorderedArray
|
|
24
238
|
};
|
package/dist/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./chunk-6F4PWJZI.js";
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
setMag: (n: number) => this;
|
|
6
|
-
magSq: () => number;
|
|
7
|
-
limit: (max: number) => this;
|
|
8
|
-
normalize: () => this;
|
|
1
|
+
interface ReadonlyVec3Like {
|
|
2
|
+
readonly x: number;
|
|
3
|
+
readonly y: number;
|
|
4
|
+
readonly z: number;
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
type Vec3Like = [x: number, y: number, z: number] | Float32Array;
|
|
12
|
-
type ReadonlyVec3Like = Readonly<Vec3Like>;
|
|
13
6
|
type First = ReadonlyVec3Like | number;
|
|
14
|
-
declare class Vec3
|
|
15
|
-
|
|
7
|
+
declare class Vec3 {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
z: number;
|
|
16
11
|
constructor(x?: First, y?: number, z?: number);
|
|
17
|
-
get x(): number;
|
|
18
|
-
set x(value: number);
|
|
19
|
-
get y(): number;
|
|
20
|
-
set y(value: number);
|
|
21
|
-
get z(): number;
|
|
22
|
-
set z(value: number);
|
|
23
12
|
get r(): number;
|
|
24
13
|
set r(value: number);
|
|
25
14
|
get g(): number;
|
|
@@ -30,6 +19,7 @@ declare class Vec3 extends Float32Array implements Vec {
|
|
|
30
19
|
copy(): Vec3;
|
|
31
20
|
static random(mag?: number): Vec3;
|
|
32
21
|
eq(x: First, y?: number, z?: number): boolean;
|
|
22
|
+
set(x: First, y?: number, z?: number): this;
|
|
33
23
|
neg(): Vec3;
|
|
34
24
|
add(x: First, y?: number, z?: number): this;
|
|
35
25
|
static add(v1: Vec3, x: First, y?: number, z?: number): Vec3;
|
|
@@ -40,10 +30,10 @@ declare class Vec3 extends Float32Array implements Vec {
|
|
|
40
30
|
div(x: First, y?: number, z?: number): this;
|
|
41
31
|
static div(v1: Vec3, x: First, y?: number, z?: number): Vec3;
|
|
42
32
|
static fma(a: ReadonlyVec3Like, b: ReadonlyVec3Like, c: ReadonlyVec3Like): Vec3;
|
|
43
|
-
lt(
|
|
44
|
-
lte(
|
|
45
|
-
gt(
|
|
46
|
-
gte(
|
|
33
|
+
lt(v: ReadonlyVec3Like): Vec3;
|
|
34
|
+
lte(v: ReadonlyVec3Like): Vec3;
|
|
35
|
+
gt(v: ReadonlyVec3Like): Vec3;
|
|
36
|
+
gte(v: ReadonlyVec3Like): Vec3;
|
|
47
37
|
limit(max: number): this;
|
|
48
38
|
normalize(): this;
|
|
49
39
|
static normalize(v: Vec3): Vec3;
|
|
@@ -67,4 +57,4 @@ declare class Vec3 extends Float32Array implements Vec {
|
|
|
67
57
|
}
|
|
68
58
|
declare function vec3(x?: First, y?: number, z?: number): Vec3;
|
|
69
59
|
|
|
70
|
-
export { type ReadonlyVec3Like as R,
|
|
60
|
+
export { type ReadonlyVec3Like as R, Vec3 as V, vec3 as v };
|
package/package.json
CHANGED
|
@@ -1,85 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@limitlesspc/std",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.23.0",
|
|
5
5
|
"description": "A standard library for JavaScript",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
7
|
"exports": {
|
|
11
8
|
"./package.json": "./package.json",
|
|
12
9
|
"./async": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
10
|
+
"types": "./dist/async/index.d.ts",
|
|
11
|
+
"default": "./dist/async/index.js"
|
|
15
12
|
},
|
|
16
13
|
"./cmath": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
14
|
+
"types": "./dist/cmath/index.d.ts",
|
|
15
|
+
"default": "./dist/cmath/index.js"
|
|
19
16
|
},
|
|
20
17
|
"./fn": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
18
|
+
"types": "./dist/fn/index.d.ts",
|
|
19
|
+
"default": "./dist/fn/index.js"
|
|
23
20
|
},
|
|
24
21
|
"./gfx": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
22
|
+
"types": "./dist/gfx/index.d.ts",
|
|
23
|
+
"default": "./dist/gfx/index.js"
|
|
27
24
|
},
|
|
28
25
|
"./iter": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
26
|
+
"types": "./dist/iter/index.d.ts",
|
|
27
|
+
"default": "./dist/iter/index.js"
|
|
31
28
|
},
|
|
32
29
|
"./math": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
30
|
+
"types": "./dist/math/index.d.ts",
|
|
31
|
+
"default": "./dist/math/index.js"
|
|
35
32
|
},
|
|
36
33
|
"./string": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
34
|
+
"types": "./dist/string/index.d.ts",
|
|
35
|
+
"default": "./dist/string/index.js"
|
|
39
36
|
},
|
|
40
37
|
"./structs": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
38
|
+
"types": "./dist/structs/index.d.ts",
|
|
39
|
+
"default": "./dist/structs/index.js"
|
|
43
40
|
},
|
|
44
41
|
"./time": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
42
|
+
"types": "./dist/time/index.d.ts",
|
|
43
|
+
"default": "./dist/time/index.js"
|
|
47
44
|
},
|
|
48
45
|
"./array": {
|
|
49
|
-
"
|
|
50
|
-
"
|
|
46
|
+
"types": "./dist/array.d.ts",
|
|
47
|
+
"default": "./dist/array.js"
|
|
51
48
|
},
|
|
52
49
|
"./bytes": {
|
|
53
|
-
"
|
|
54
|
-
"
|
|
50
|
+
"types": "./dist/bytes.d.ts",
|
|
51
|
+
"default": "./dist/bytes.js"
|
|
55
52
|
},
|
|
56
53
|
"./cmp": {
|
|
57
|
-
"
|
|
58
|
-
"
|
|
54
|
+
"types": "./dist/cmp.d.ts",
|
|
55
|
+
"default": "./dist/cmp.js"
|
|
59
56
|
},
|
|
60
57
|
"./csv": {
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
},
|
|
64
|
-
"./easing": {
|
|
65
|
-
"default": "./dist/easing.js",
|
|
66
|
-
"types": "./dist/easing.d.ts"
|
|
58
|
+
"types": "./dist/csv.d.ts",
|
|
59
|
+
"default": "./dist/csv.js"
|
|
67
60
|
},
|
|
68
61
|
"./events": {
|
|
69
|
-
"
|
|
70
|
-
"
|
|
62
|
+
"types": "./dist/events.d.ts",
|
|
63
|
+
"default": "./dist/events.js"
|
|
71
64
|
},
|
|
72
65
|
"./object": {
|
|
73
|
-
"
|
|
74
|
-
"
|
|
66
|
+
"types": "./dist/object.d.ts",
|
|
67
|
+
"default": "./dist/object.js"
|
|
75
68
|
},
|
|
76
69
|
"./random": {
|
|
77
|
-
"
|
|
78
|
-
"
|
|
70
|
+
"types": "./dist/random.d.ts",
|
|
71
|
+
"default": "./dist/random.js"
|
|
79
72
|
},
|
|
80
73
|
"./types": {
|
|
81
|
-
"
|
|
82
|
-
"
|
|
74
|
+
"types": "./dist/types.d.ts",
|
|
75
|
+
"default": "./dist/types.js"
|
|
83
76
|
}
|
|
84
77
|
},
|
|
85
78
|
"files": [
|
|
@@ -87,22 +80,25 @@
|
|
|
87
80
|
],
|
|
88
81
|
"prettier": "@limitlesspc/prettier-config",
|
|
89
82
|
"devDependencies": {
|
|
90
|
-
"@limitlesspc/eslint-config": "^0.
|
|
91
|
-
"@limitlesspc/prettier-config": "^1.
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
83
|
+
"@limitlesspc/eslint-config": "^0.18.4",
|
|
84
|
+
"@limitlesspc/prettier-config": "^1.2.1",
|
|
85
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
86
|
+
"bumpp": "^10.3.2",
|
|
87
|
+
"eslint": "^9.39.2",
|
|
88
|
+
"prettier": "^3.7.4",
|
|
89
|
+
"tsup": "^8.5.1",
|
|
90
|
+
"typescript": "^5.9.3",
|
|
91
|
+
"vitest": "^4.0.15"
|
|
96
92
|
},
|
|
97
93
|
"scripts": {
|
|
98
94
|
"build": "tsup",
|
|
99
|
-
"test": "vitest",
|
|
100
95
|
"fmt": "prettier . --write --cache --ignore-unknown",
|
|
101
96
|
"fmt:check": "prettier . --check --cache --ignore-unknown",
|
|
102
97
|
"lint": "eslint",
|
|
103
98
|
"lint:fix": "eslint --fix",
|
|
104
99
|
"lint:fix-dry": "eslint --fix-dry-run",
|
|
105
|
-
"
|
|
100
|
+
"test": "vitest",
|
|
101
|
+
"coverage": "vitest run --coverage",
|
|
106
102
|
"release": "bumpp && pnpm publish",
|
|
107
103
|
"typecheck": "tsc --noEmit"
|
|
108
104
|
}
|
package/dist/chunk-6F4PWJZI.js
DELETED
|
File without changes
|