@3dsource/utils 1.0.4 → 1.0.5
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/fesm2022/3dsource-utils.mjs +1793 -0
- package/fesm2022/3dsource-utils.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/{src/lib/color/CMYKtoRGB.ts → lib/color/CMYKtoRGB.d.ts} +1 -11
- package/lib/color/HEXtoRGB.d.ts +5 -0
- package/lib/color/HSVtoRGB.d.ts +21 -0
- package/{src/lib/color/RGBtoCMYK.ts → lib/color/RGBtoCMYK.d.ts} +1 -31
- package/lib/color/RGBtoHEX.d.ts +1 -0
- package/lib/color/RGBtoHSV.d.ts +19 -0
- package/lib/color/hsv.d.ts +1 -0
- package/lib/color/max.d.ts +1 -0
- package/lib/color/min.d.ts +1 -0
- package/lib/color/overlay.d.ts +1 -0
- package/{src/lib/color/rgb.ts → lib/color/rgb.d.ts} +1 -3
- package/lib/color/sub.d.ts +1 -0
- package/lib/color/subtract.d.ts +1 -0
- package/lib/color/sum.d.ts +1 -0
- package/{src/lib/color/toRGB.ts → lib/color/toRGB.d.ts} +1 -7
- package/lib/color/toRGBA.d.ts +1 -0
- package/lib/constants/color-codes.constant.d.ts +9 -0
- package/lib/csv/CSV2Array.d.ts +1 -0
- package/lib/csv/CSV2Records.d.ts +1 -0
- package/lib/csv/ObjectToCSV.d.ts +1 -0
- package/lib/dev/dev3d.d.ts +1 -0
- package/lib/dev/logger.d.ts +11 -0
- package/lib/dev/timeToString.d.ts +5 -0
- package/lib/filenaming/cleanupFileName.d.ts +1 -0
- package/lib/filenaming/makePath.d.ts +1 -0
- package/lib/filenaming/normalizePath.d.ts +1 -0
- package/lib/geom/expandOverRectangle.d.ts +2 -0
- package/lib/geom/fitIntoRectangle.d.ts +2 -0
- package/{src/lib/geom/interfaces/area.interface.ts → lib/geom/interfaces/area.interface.d.ts} +1 -2
- package/{src/lib/geom/interfaces/rect.interface.ts → lib/geom/interfaces/rect.interface.d.ts} +2 -2
- package/lib/geom/interfaces/size.interface.d.ts +4 -0
- package/lib/geom/interfaces//321/201oords.interface.d.ts +4 -0
- package/lib/helpers/BatchLoader.d.ts +47 -0
- package/lib/helpers/KeyboardNumericCode.d.ts +103 -0
- package/lib/helpers/serialize.d.ts +1 -0
- package/lib/helpers/sleep.d.ts +1 -0
- package/lib/helpers/trimLastSlashFromUrl.d.ts +1 -0
- package/lib/image/SaveImage.d.ts +18 -0
- package/lib/image/getCanvasCached.d.ts +4 -0
- package/lib/image/getSnapshot.d.ts +2 -0
- package/lib/image/loadImage.d.ts +1 -0
- package/lib/interfaces/image-output.d.ts +7 -0
- package/{src/lib/interfaces/load-args-tmp.interface.ts → lib/interfaces/load-args-tmp.interface.d.ts} +1 -2
- package/lib/interfaces/load-args.interface.d.ts +15 -0
- package/{src/lib/math/baseSortedIndex.ts → lib/math/baseSortedIndex.d.ts} +1 -19
- package/{src/lib/math/calculateMedian.ts → lib/math/calculateMedian.d.ts} +1 -17
- package/{src/lib/math/circularIndex.ts → lib/math/circularIndex.d.ts} +1 -5
- package/lib/math/clampf.d.ts +8 -0
- package/lib/math/degrees.d.ts +2 -0
- package/{src/lib/math/floatCompare.ts → lib/math/floatCompare.d.ts} +3 -30
- package/{src/lib/math/inverseLerp.ts → lib/math/inverseLerp.d.ts} +1 -22
- package/lib/math/lerp.d.ts +7 -0
- package/{src/lib/mutex/Mutex.ts → lib/mutex/Mutex.d.ts} +8 -15
- package/{src/lib/mutex/Semaphore.ts → lib/mutex/Semaphore.d.ts} +7 -27
- package/lib/mutex/TaskRunner.d.ts +5 -0
- package/lib/predicates/BooleanPredictors.d.ts +27 -0
- package/{src/lib/predicates/textForSearch.ts → lib/predicates/textForSearch.d.ts} +1 -17
- package/{src/lib/predicates/where.ts → lib/predicates/where.d.ts} +2 -32
- package/lib/rxjs/leadingTrailingDebounceTime.d.ts +15 -0
- package/{src/lib/rxjs/smoothTransition.ts → lib/rxjs/smoothTransition.d.ts} +1 -19
- package/lib/rxjs/tapLog.d.ts +2 -0
- package/lib/strings/pad.d.ts +8 -0
- package/package.json +13 -2
- package/eslint.config.js +0 -37
- package/ng-package.json +0 -7
- package/src/lib/color/HEXtoRGB.ts +0 -9
- package/src/lib/color/HSVtoRGB.ts +0 -82
- package/src/lib/color/RGBtoHEX.ts +0 -17
- package/src/lib/color/RGBtoHSV.ts +0 -53
- package/src/lib/color/hsv.ts +0 -14
- package/src/lib/color/max.ts +0 -18
- package/src/lib/color/min.ts +0 -18
- package/src/lib/color/overlay.ts +0 -25
- package/src/lib/color/sub.ts +0 -18
- package/src/lib/color/subtract.ts +0 -27
- package/src/lib/color/sum.ts +0 -19
- package/src/lib/color/toRGBA.ts +0 -8
- package/src/lib/constants/color-codes.constant.ts +0 -9
- package/src/lib/csv/CSV2Array.ts +0 -66
- package/src/lib/csv/CSV2Records.ts +0 -56
- package/src/lib/csv/ObjectToCSV.ts +0 -21
- package/src/lib/dev/dev3d.ts +0 -1
- package/src/lib/dev/logger.ts +0 -94
- package/src/lib/dev/timeToString.ts +0 -16
- package/src/lib/filenaming/cleanupFileName.ts +0 -18
- package/src/lib/filenaming/makePath.ts +0 -5
- package/src/lib/filenaming/normalizePath.ts +0 -9
- package/src/lib/geom/expandOverRectangle.ts +0 -17
- package/src/lib/geom/fitIntoRectangle.ts +0 -43
- package/src/lib/geom/interfaces/size.interface.ts +0 -4
- package/src/lib/geom/interfaces//321/201oords.interface.ts +0 -4
- package/src/lib/helpers/BatchLoader.ts +0 -243
- package/src/lib/helpers/KeyboardNumericCode.ts +0 -118
- package/src/lib/helpers/serialize.ts +0 -11
- package/src/lib/helpers/sleep.ts +0 -3
- package/src/lib/helpers/trimLastSlashFromUrl.ts +0 -9
- package/src/lib/image/SaveImage.ts +0 -65
- package/src/lib/image/getCanvasCached.ts +0 -16
- package/src/lib/image/getSnapshot.ts +0 -99
- package/src/lib/image/loadImage.ts +0 -13
- package/src/lib/interfaces/image-output.ts +0 -8
- package/src/lib/interfaces/load-args.interface.ts +0 -15
- package/src/lib/math/clampf.ts +0 -14
- package/src/lib/math/degrees.ts +0 -7
- package/src/lib/math/lerp.ts +0 -12
- package/src/lib/mutex/TaskRunner.ts +0 -26
- package/src/lib/predicates/BooleanPredictors.ts +0 -47
- package/src/lib/rxjs/leadingTrailingDebounceTime.ts +0 -86
- package/src/lib/rxjs/tapLog.ts +0 -13
- package/src/lib/strings/pad.ts +0 -18
- package/tsconfig.lib.json +0 -13
- package/tsconfig.lib.prod.json +0 -11
- /package/{src/lib/color/index.ts → lib/color/index.d.ts} +0 -0
- /package/{src/lib/constants/index.ts → lib/constants/index.d.ts} +0 -0
- /package/{src/lib/csv/index.ts → lib/csv/index.d.ts} +0 -0
- /package/{src/lib/dev/index.ts → lib/dev/index.d.ts} +0 -0
- /package/{src/lib/filenaming/index.ts → lib/filenaming/index.d.ts} +0 -0
- /package/{src/lib/geom/index.ts → lib/geom/index.d.ts} +0 -0
- /package/{src/lib/geom/interfaces/index.ts → lib/geom/interfaces/index.d.ts} +0 -0
- /package/{src/lib/helpers/index.ts → lib/helpers/index.d.ts} +0 -0
- /package/{src/lib/image/index.ts → lib/image/index.d.ts} +0 -0
- /package/{src/lib/interfaces/index.ts → lib/interfaces/index.d.ts} +0 -0
- /package/{src/lib/math/index.ts → lib/math/index.d.ts} +0 -0
- /package/{src/lib/mutex/index.ts → lib/mutex/index.d.ts} +0 -0
- /package/{src/lib/predicates/index.ts → lib/predicates/index.d.ts} +0 -0
- /package/{src/lib/rxjs/index.ts → lib/rxjs/index.d.ts} +0 -0
- /package/{src/lib/strings/index.ts → lib/strings/index.d.ts} +0 -0
- /package/{src/public-api.ts → public-api.d.ts} +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
declare const KeyboardNumericCode: {
|
|
2
|
+
readonly Backspace: 8;
|
|
3
|
+
readonly Tab: 9;
|
|
4
|
+
readonly Numpad5: 12;
|
|
5
|
+
readonly NumpadEnter: 13;
|
|
6
|
+
readonly ShiftRight: 16;
|
|
7
|
+
readonly ControlRight: 17;
|
|
8
|
+
readonly ControlLeft: 17;
|
|
9
|
+
readonly AltRight: 18;
|
|
10
|
+
readonly Escape: 27;
|
|
11
|
+
readonly Space: 32;
|
|
12
|
+
readonly Numpad9: 33;
|
|
13
|
+
readonly Numpad3: 34;
|
|
14
|
+
readonly Numpad1: 35;
|
|
15
|
+
readonly Numpad7: 36;
|
|
16
|
+
readonly Numpad4: 37;
|
|
17
|
+
readonly Numpad8: 38;
|
|
18
|
+
readonly Numpad6: 39;
|
|
19
|
+
readonly Numpad2: 40;
|
|
20
|
+
readonly Numpad0: 45;
|
|
21
|
+
readonly NumpadDecimal: 46;
|
|
22
|
+
readonly Digit0: 48;
|
|
23
|
+
readonly Digit1: 49;
|
|
24
|
+
readonly Digit2: 50;
|
|
25
|
+
readonly Digit3: 51;
|
|
26
|
+
readonly Digit4: 52;
|
|
27
|
+
readonly Digit5: 53;
|
|
28
|
+
readonly Digit6: 54;
|
|
29
|
+
readonly Digit7: 55;
|
|
30
|
+
readonly Digit8: 56;
|
|
31
|
+
readonly Digit9: 57;
|
|
32
|
+
readonly KeyA: 65;
|
|
33
|
+
readonly KeyB: 66;
|
|
34
|
+
readonly KeyC: 67;
|
|
35
|
+
readonly KeyD: 68;
|
|
36
|
+
readonly KeyE: 69;
|
|
37
|
+
readonly KeyF: 70;
|
|
38
|
+
readonly KeyG: 71;
|
|
39
|
+
readonly KeyH: 72;
|
|
40
|
+
readonly KeyI: 73;
|
|
41
|
+
readonly KeyJ: 74;
|
|
42
|
+
readonly KeyK: 75;
|
|
43
|
+
readonly KeyL: 76;
|
|
44
|
+
readonly KeyM: 77;
|
|
45
|
+
readonly KeyN: 78;
|
|
46
|
+
readonly KeyO: 79;
|
|
47
|
+
readonly KeyP: 80;
|
|
48
|
+
readonly KeyQ: 81;
|
|
49
|
+
readonly KeyR: 82;
|
|
50
|
+
readonly KeyS: 83;
|
|
51
|
+
readonly KeyT: 84;
|
|
52
|
+
readonly KeyU: 85;
|
|
53
|
+
readonly KeyV: 86;
|
|
54
|
+
readonly KeyW: 87;
|
|
55
|
+
readonly KeyX: 88;
|
|
56
|
+
readonly KeyY: 89;
|
|
57
|
+
readonly KeyZ: 90;
|
|
58
|
+
readonly MetaLeft: 91;
|
|
59
|
+
readonly ContextMenu: 93;
|
|
60
|
+
readonly NumpadMultiply: 106;
|
|
61
|
+
readonly NumpadAdd: 107;
|
|
62
|
+
readonly NumpadSubtract: 109;
|
|
63
|
+
readonly NumpadDivide: 111;
|
|
64
|
+
readonly F1: 112;
|
|
65
|
+
readonly F2: 113;
|
|
66
|
+
readonly F3: 114;
|
|
67
|
+
readonly F4: 115;
|
|
68
|
+
readonly F5: 116;
|
|
69
|
+
readonly F6: 117;
|
|
70
|
+
readonly F7: 118;
|
|
71
|
+
readonly F8: 119;
|
|
72
|
+
readonly F9: 120;
|
|
73
|
+
readonly F10: 121;
|
|
74
|
+
readonly F11: 122;
|
|
75
|
+
readonly F12: 123;
|
|
76
|
+
readonly NumLock: 144;
|
|
77
|
+
readonly ScrollLock: 145;
|
|
78
|
+
readonly Semicolon: 186;
|
|
79
|
+
readonly Equal: 187;
|
|
80
|
+
readonly Comma: 188;
|
|
81
|
+
readonly Minus: 189;
|
|
82
|
+
readonly Period: 190;
|
|
83
|
+
readonly Slash: 191;
|
|
84
|
+
readonly Backquote: 192;
|
|
85
|
+
readonly BracketLeft: 219;
|
|
86
|
+
readonly Backslash: 220;
|
|
87
|
+
readonly BracketRight: 221;
|
|
88
|
+
readonly Quote: 222;
|
|
89
|
+
readonly IntlBackslash: 226;
|
|
90
|
+
readonly ArrowUp: 38;
|
|
91
|
+
readonly ArrowDown: 40;
|
|
92
|
+
readonly ArrowLeft: 37;
|
|
93
|
+
readonly ArrowRight: 39;
|
|
94
|
+
};
|
|
95
|
+
type IKeyName = keyof typeof KeyboardNumericCode;
|
|
96
|
+
type IKeyCode = (typeof KeyboardNumericCode)[IKeyName];
|
|
97
|
+
type InvertedKeyMapType = {
|
|
98
|
+
[K in IKeyName as (typeof KeyboardNumericCode)[K]]: K;
|
|
99
|
+
};
|
|
100
|
+
declare const InvertedKeyMap: InvertedKeyMapType;
|
|
101
|
+
declare const KeyboardStringCode: { [K in IKeyName]: K; };
|
|
102
|
+
export type { IKeyName, IKeyCode };
|
|
103
|
+
export { KeyboardStringCode, InvertedKeyMap, KeyboardNumericCode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function serialize(obj: any): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(time: number): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function trimLastSlashFromUrl(baseUrl: string): string | null | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ImageOutputValues } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* USE DownloadImage instead!
|
|
4
|
+
* @deprecated use DownloadImage instead!
|
|
5
|
+
* @param imageSource
|
|
6
|
+
* @param name
|
|
7
|
+
* @param width
|
|
8
|
+
* @param format
|
|
9
|
+
*/
|
|
10
|
+
declare function SaveImage(imageSource: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | ImageBitmap | string, name: string, width?: number, format?: string | ImageOutputValues): any;
|
|
11
|
+
/**
|
|
12
|
+
* @param imageSource
|
|
13
|
+
* @param string name
|
|
14
|
+
* @param number width
|
|
15
|
+
* @param string format
|
|
16
|
+
*/
|
|
17
|
+
declare const DownloadImage: typeof SaveImage;
|
|
18
|
+
export { SaveImage, DownloadImage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadImage(url: string): Promise<HTMLImageElement>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface LoadArgs {
|
|
2
|
+
order: number;
|
|
3
|
+
extra: any;
|
|
4
|
+
item?: HTMLImageElement;
|
|
5
|
+
useXhr?: boolean;
|
|
6
|
+
path: string;
|
|
7
|
+
onLoadEnd: (data: LoadArgs) => void;
|
|
8
|
+
onLoadStart: (data: ProgressEvent) => void;
|
|
9
|
+
onProgress: (data: ProgressEvent) => void;
|
|
10
|
+
id?: string;
|
|
11
|
+
img?: HTMLImageElement;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
fallBack?: string;
|
|
14
|
+
resolutionId: number | string | null;
|
|
15
|
+
}
|
|
@@ -22,22 +22,4 @@
|
|
|
22
22
|
* // returns 1
|
|
23
23
|
* baseSortedIndex([1, 2, 3], 2);
|
|
24
24
|
*/
|
|
25
|
-
export function baseSortedIndex(array: number[], value: number): number
|
|
26
|
-
const MAX_ARRAY_LENGTH = 4294967295;
|
|
27
|
-
const HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
|
28
|
-
let low = 0;
|
|
29
|
-
let high = array?.length || low;
|
|
30
|
-
|
|
31
|
-
if (high <= HALF_MAX_ARRAY_LENGTH) {
|
|
32
|
-
while (low < high) {
|
|
33
|
-
const mid = (low + high) >>> 1;
|
|
34
|
-
const computed = array[mid];
|
|
35
|
-
if (computed !== null && computed < value) {
|
|
36
|
-
low = mid + 1;
|
|
37
|
-
} else {
|
|
38
|
-
high = mid;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return high;
|
|
43
|
-
}
|
|
25
|
+
export declare function baseSortedIndex(array: number[], value: number): number;
|
|
@@ -14,20 +14,4 @@
|
|
|
14
14
|
* console.log(median); // Output: 2.5
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export function calculateMedian(numbers: number[]): number
|
|
18
|
-
if (numbers.length === 0) return 0;
|
|
19
|
-
|
|
20
|
-
// Sort the array in ascending order
|
|
21
|
-
const sorted = [...numbers].sort((a, b) => a - b);
|
|
22
|
-
|
|
23
|
-
const length = sorted.length;
|
|
24
|
-
const middle = Math.floor(length / 2);
|
|
25
|
-
|
|
26
|
-
// If the length is even, return the average of the two middle numbers
|
|
27
|
-
if (length % 2 === 0) {
|
|
28
|
-
return (sorted[middle - 1] + sorted[middle]) / 2;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// If the length is odd, return the middle number
|
|
32
|
-
return sorted[middle];
|
|
33
|
-
}
|
|
17
|
+
export declare function calculateMedian(numbers: number[]): number;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { clampf } from './clampf';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Computes a circular index within a given range.
|
|
5
3
|
*
|
|
@@ -34,6 +32,4 @@ import { clampf } from './clampf';
|
|
|
34
32
|
* const index5 = circularIndex(1, 1);
|
|
35
33
|
* console.log(index5); // Output: 0
|
|
36
34
|
*/
|
|
37
|
-
export function circularIndex(index: number, totalItems: number): number
|
|
38
|
-
return clampf(0, totalItems - 1, (totalItems * 2 + index) % totalItems);
|
|
39
|
-
}
|
|
35
|
+
export declare function circularIndex(index: number, totalItems: number): number;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A small epsilon value used for floating-point comparisons.
|
|
3
|
-
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* The value of `EPSILON` is `0.01`. This can be overridden in the comparison functions if needed.
|
|
6
|
-
*/
|
|
7
|
-
const EPSILON = 0.01;
|
|
8
|
-
|
|
9
1
|
/**
|
|
10
2
|
* Checks if floating-point number `A` is less than `B` considering a small margin of error.
|
|
11
3
|
*
|
|
@@ -19,15 +11,7 @@ const EPSILON = 0.01;
|
|
|
19
11
|
* const result = fpIsALessThanB(0.0034, 0.0066); // true
|
|
20
12
|
* ```
|
|
21
13
|
*/
|
|
22
|
-
export function fpIsALessThanB(
|
|
23
|
-
A: number,
|
|
24
|
-
B: number,
|
|
25
|
-
Epsilon?: number,
|
|
26
|
-
): boolean {
|
|
27
|
-
Epsilon = Epsilon || EPSILON;
|
|
28
|
-
return A - B < Epsilon && Math.abs(A - B) > Epsilon;
|
|
29
|
-
}
|
|
30
|
-
|
|
14
|
+
export declare function fpIsALessThanB(A: number, B: number, Epsilon?: number): boolean;
|
|
31
15
|
/**
|
|
32
16
|
* Checks if floating-point number `A` is greater than `B` considering a small margin of error.
|
|
33
17
|
*
|
|
@@ -41,15 +25,7 @@ export function fpIsALessThanB(
|
|
|
41
25
|
* const result = fpIsAGreaterThanB(0.0066, 0.0034); // true
|
|
42
26
|
* ```
|
|
43
27
|
*/
|
|
44
|
-
export function fpIsAGreaterThanB(
|
|
45
|
-
A: number,
|
|
46
|
-
B: number,
|
|
47
|
-
Epsilon?: number,
|
|
48
|
-
): boolean {
|
|
49
|
-
Epsilon = Epsilon || EPSILON;
|
|
50
|
-
return A - B > Epsilon && Math.abs(A - B) > Epsilon;
|
|
51
|
-
}
|
|
52
|
-
|
|
28
|
+
export declare function fpIsAGreaterThanB(A: number, B: number, Epsilon?: number): boolean;
|
|
53
29
|
/**
|
|
54
30
|
* Checks if floating-point number `A` is approximately the same as `B` considering a small margin of error.
|
|
55
31
|
*
|
|
@@ -63,7 +39,4 @@ export function fpIsAGreaterThanB(
|
|
|
63
39
|
* const result = fpIsASameAsB(0.005, 0.0051); // true
|
|
64
40
|
* ```
|
|
65
41
|
*/
|
|
66
|
-
export function fpIsASameAsB(A: number, B: number, Epsilon?: number): boolean
|
|
67
|
-
Epsilon = Epsilon || EPSILON;
|
|
68
|
-
return Math.abs(A - B) < Epsilon;
|
|
69
|
-
}
|
|
42
|
+
export declare function fpIsASameAsB(A: number, B: number, Epsilon?: number): boolean;
|
|
@@ -14,25 +14,4 @@
|
|
|
14
14
|
* If `clampToNormal` is true, the result is clamped between 0 and 1.
|
|
15
15
|
* If the difference between `min` and `max` is 0, returns 1 to avoid division by zero.
|
|
16
16
|
*/
|
|
17
|
-
export function inverseLerp(
|
|
18
|
-
min: number,
|
|
19
|
-
max: number,
|
|
20
|
-
value: number,
|
|
21
|
-
clampToNormal = false,
|
|
22
|
-
): number {
|
|
23
|
-
if (clampToNormal) {
|
|
24
|
-
value = Math.min(max, value);
|
|
25
|
-
value = Math.max(min, value);
|
|
26
|
-
}
|
|
27
|
-
const difference = max - min;
|
|
28
|
-
|
|
29
|
-
// Avoid JS division error
|
|
30
|
-
if (difference === 0) {
|
|
31
|
-
return 1;
|
|
32
|
-
}
|
|
33
|
-
const result = (value - min) / difference;
|
|
34
|
-
if (clampToNormal) {
|
|
35
|
-
return Math.min(1, Math.max(0, result));
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
17
|
+
export declare function inverseLerp(min: number, max: number, value: number, clampToNormal?: boolean): number;
|
|
@@ -32,19 +32,12 @@
|
|
|
32
32
|
* [LOG]: "Task 4 acquired mutex"
|
|
33
33
|
* [LOG]: "Task 4 releasing mutex"
|
|
34
34
|
*/
|
|
35
|
-
export class Mutex {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
async acquire(): Promise<() => void> {
|
|
44
|
-
let release: () => void;
|
|
45
|
-
const previous = this.mutex;
|
|
46
|
-
this.mutex = new Promise<void>((resolve) => (release = resolve));
|
|
47
|
-
await previous;
|
|
48
|
-
return release!;
|
|
49
|
-
}
|
|
35
|
+
export declare class Mutex {
|
|
36
|
+
private mutex;
|
|
37
|
+
/**
|
|
38
|
+
* Acquires the mutex, returning a promise that resolves when the mutex is acquired.
|
|
39
|
+
* The returned promise provides a release function that should be called to release the mutex.
|
|
40
|
+
* @returns A promise that resolves with a release function.
|
|
41
|
+
*/
|
|
42
|
+
acquire(): Promise<() => void>;
|
|
50
43
|
}
|
|
@@ -32,31 +32,11 @@
|
|
|
32
32
|
* [LOG]: "Task 4 releasing semaphore"
|
|
33
33
|
* [LOG]: "Task 3 releasing semaphore"
|
|
34
34
|
*/
|
|
35
|
-
export class Semaphore {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return new Promise((resolve) => {
|
|
43
|
-
if (this.currentCount < this.maxConcurrency) {
|
|
44
|
-
this.currentCount++;
|
|
45
|
-
resolve();
|
|
46
|
-
} else {
|
|
47
|
-
this.tasks.push(resolve);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public release(): void {
|
|
53
|
-
if (this.tasks.length > 0) {
|
|
54
|
-
const nextTask = this.tasks.shift();
|
|
55
|
-
if (nextTask) {
|
|
56
|
-
nextTask();
|
|
57
|
-
}
|
|
58
|
-
} else if (this.currentCount > 0) {
|
|
59
|
-
this.currentCount--;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
35
|
+
export declare class Semaphore {
|
|
36
|
+
private readonly maxConcurrency;
|
|
37
|
+
private tasks;
|
|
38
|
+
private currentCount;
|
|
39
|
+
constructor(maxConcurrency: number);
|
|
40
|
+
acquire(): Promise<void>;
|
|
41
|
+
release(): void;
|
|
62
42
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type TruthyTypesOf<T> = T extends false | '' | 0 | null | undefined ? never : T;
|
|
2
|
+
type FalsyTypesOf<T> = T extends false | '' | 0 | null | undefined ? T : never;
|
|
3
|
+
type EmptyTypesOf<T> = T extends undefined | null | object | '' ? T : never;
|
|
4
|
+
type NonEmptyTypesOf<T> = T extends undefined | null | object | '' ? never : T;
|
|
5
|
+
/**
|
|
6
|
+
* The Boolean object represents a truth value: true or false.
|
|
7
|
+
* @param value
|
|
8
|
+
* @constructor
|
|
9
|
+
* Returns:boolean
|
|
10
|
+
*/
|
|
11
|
+
export declare const Truthy: <T>(value: T) => value is TruthyTypesOf<T>;
|
|
12
|
+
/**
|
|
13
|
+
* The Boolean object represents a INVERSE truth value: true or false.
|
|
14
|
+
* @param value
|
|
15
|
+
* @constructor
|
|
16
|
+
* Returns:boolean
|
|
17
|
+
*/
|
|
18
|
+
export declare const Falsy: <T>(value: T) => value is FalsyTypesOf<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a value is empty.
|
|
21
|
+
*
|
|
22
|
+
* @param {any} value - The value to check.
|
|
23
|
+
* @return {boolean} Returns true if the value is empty, otherwise false.
|
|
24
|
+
*/
|
|
25
|
+
export declare const IsEmpty: <T>(value: T) => value is EmptyTypesOf<T>;
|
|
26
|
+
export declare const NotEmpty: <T>(value: T) => value is NonEmptyTypesOf<T>;
|
|
27
|
+
export {};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const cache: Record<string, unknown> = {};
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Converts a given value to a string suitable for search comparisons.
|
|
5
3
|
* The resulting string is in lowercase, with consecutive spaces replaced by underscores.
|
|
@@ -17,18 +15,4 @@ const cache: Record<string, unknown> = {};
|
|
|
17
15
|
* retrieved from the cache or freshly computed and then cached.
|
|
18
16
|
*
|
|
19
17
|
*/
|
|
20
|
-
export function textForSearch(value: unknown, caseSensitive
|
|
21
|
-
const key = `${value}_${caseSensitive}`;
|
|
22
|
-
return (cache[key] ||
|
|
23
|
-
(() => {
|
|
24
|
-
let result = String(value).trim().replace(/ +/gi, '_');
|
|
25
|
-
|
|
26
|
-
if (!caseSensitive) {
|
|
27
|
-
result = result.toLowerCase();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
cache[key] = result;
|
|
31
|
-
|
|
32
|
-
return result;
|
|
33
|
-
})()) as string;
|
|
34
|
-
}
|
|
18
|
+
export declare function textForSearch(value: unknown, caseSensitive?: boolean): string;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { textForSearch } from './textForSearch';
|
|
2
1
|
import type { TruthyTypesOf } from 'rxjs';
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
3
|
* Creates a predicate function to filter records from a collection based on specified criteria.
|
|
6
4
|
*
|
|
@@ -44,33 +42,5 @@ import type { TruthyTypesOf } from 'rxjs';
|
|
|
44
42
|
* ensuring the function is only used with object types. This generic approach allows for flexible usage
|
|
45
43
|
* with various record structures.
|
|
46
44
|
*/
|
|
47
|
-
|
|
48
|
-
export function
|
|
49
|
-
criteria: Partial<TruthyTypesOf<T>>,
|
|
50
|
-
caseSensitive = false,
|
|
51
|
-
): (record: T) => boolean {
|
|
52
|
-
const preComputedEntries = Object.entries(criteria)
|
|
53
|
-
.filter(([, value]) => value !== undefined)
|
|
54
|
-
.map(([key, value]) => [key, textForSearch(value, caseSensitive)] as const);
|
|
55
|
-
|
|
56
|
-
return (record: T): boolean => {
|
|
57
|
-
return (
|
|
58
|
-
preComputedEntries.length > 0 &&
|
|
59
|
-
preComputedEntries.every(([key, criterionValue]) => {
|
|
60
|
-
return (
|
|
61
|
-
textForSearch(record[key as keyof T] ?? '', caseSensitive) ===
|
|
62
|
-
criterionValue
|
|
63
|
-
);
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
export function whereNot<T extends object>(
|
|
69
|
-
criteria: Partial<TruthyTypesOf<T>>,
|
|
70
|
-
caseSensitive = false,
|
|
71
|
-
): (record: T) => boolean {
|
|
72
|
-
const whereFunc = where(criteria, caseSensitive);
|
|
73
|
-
return (record: T) => {
|
|
74
|
-
return !whereFunc(record);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
45
|
+
export declare function where<T extends object>(criteria: Partial<TruthyTypesOf<T>>, caseSensitive?: boolean): (record: T) => boolean;
|
|
46
|
+
export declare function whereNot<T extends object>(criteria: Partial<TruthyTypesOf<T>>, caseSensitive?: boolean): (record: T) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SchedulerLike } from 'rxjs';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* Emits the most recent value emitted by the source Observable after a
|
|
5
|
+
* specified time span has passed without another source emission.
|
|
6
|
+
*
|
|
7
|
+
* This is a combination of `debounceTime` and `auditTime` operators.
|
|
8
|
+
*
|
|
9
|
+
* The leading value is emitted immediately, and trailing values are debounced.
|
|
10
|
+
*
|
|
11
|
+
* @param dueTime The time to wait before emitting the last value.
|
|
12
|
+
* @param scheduler The scheduler to use for the timeout.
|
|
13
|
+
* @returns A function that returns an Observable that mirrors the source Observable, but applies the specified debouncing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function leadingTrailingDebounceTime<T>(dueTime: number, scheduler?: SchedulerLike): (source: Observable<T>) => Observable<T>;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import type { Observable } from 'rxjs';
|
|
2
|
-
import { animationFrameScheduler, interval } from 'rxjs';
|
|
3
|
-
import { distinctUntilChanged, map } from 'rxjs/operators';
|
|
4
|
-
import { clampf, lerp } from '../math';
|
|
5
|
-
|
|
6
2
|
/**
|
|
7
3
|
* Creates an observable that emits values transitioning smoothly from the start value to the end value over a specified duration.
|
|
8
4
|
* The transition is performed using linear interpolation (lerp) and clamped to the range [0, 1].
|
|
@@ -12,18 +8,4 @@ import { clampf, lerp } from '../math';
|
|
|
12
8
|
* @param {number} duration - The duration of the transition in milliseconds.
|
|
13
9
|
* @returns {Observable<number>} An observable that emits the interpolated values from start to end over the specified duration.
|
|
14
10
|
*/
|
|
15
|
-
export const smoothTransition
|
|
16
|
-
start: number,
|
|
17
|
-
end: number,
|
|
18
|
-
duration: number,
|
|
19
|
-
): Observable<number> => {
|
|
20
|
-
const startTime = animationFrameScheduler.now();
|
|
21
|
-
return interval(0, animationFrameScheduler).pipe(
|
|
22
|
-
map(() => {
|
|
23
|
-
const elapsed = (animationFrameScheduler.now() - startTime) / duration;
|
|
24
|
-
return clampf(0, 1, elapsed);
|
|
25
|
-
}),
|
|
26
|
-
distinctUntilChanged(),
|
|
27
|
-
map((fraction) => lerp(start, end, fraction)),
|
|
28
|
-
);
|
|
29
|
-
};
|
|
11
|
+
export declare const smoothTransition: (start: number, end: number, duration: number) => Observable<number>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds required number of symbols before input
|
|
3
|
+
* @param input input string
|
|
4
|
+
* @param size amount of total symbols
|
|
5
|
+
* @param symbol filler
|
|
6
|
+
* @returns string
|
|
7
|
+
*/
|
|
8
|
+
export declare function pad(input: number | string, size: number, symbol?: string): string;
|
package/package.json
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3dsource/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2.8.1"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
9
|
"rxjs": "^7.8.2"
|
|
10
|
+
},
|
|
11
|
+
"module": "fesm2022/3dsource-utils.mjs",
|
|
12
|
+
"typings": "index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": {
|
|
15
|
+
"default": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"default": "./fesm2022/3dsource-utils.mjs"
|
|
20
|
+
}
|
|
10
21
|
}
|
|
11
|
-
}
|
|
22
|
+
}
|
package/eslint.config.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
const tseslint = require('typescript-eslint');
|
|
3
|
-
const rootConfig = require('../../../eslint.config.js');
|
|
4
|
-
|
|
5
|
-
module.exports = tseslint.config(
|
|
6
|
-
...rootConfig,
|
|
7
|
-
{
|
|
8
|
-
files: ['**/*.ts'],
|
|
9
|
-
languageOptions: {
|
|
10
|
-
parserOptions: {
|
|
11
|
-
projectService: true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
rules: {
|
|
15
|
-
'@angular-eslint/directive-selector': [
|
|
16
|
-
'error',
|
|
17
|
-
{
|
|
18
|
-
type: 'attribute',
|
|
19
|
-
prefix: 'lib',
|
|
20
|
-
style: 'camelCase',
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
'@angular-eslint/component-selector': [
|
|
24
|
-
'error',
|
|
25
|
-
{
|
|
26
|
-
type: 'element',
|
|
27
|
-
prefix: 'lib',
|
|
28
|
-
style: 'kebab-case',
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
files: ['**/*.html'],
|
|
35
|
-
rules: {},
|
|
36
|
-
},
|
|
37
|
-
);
|
package/ng-package.json
DELETED