@3dsource/utils 1.0.10 → 1.0.11
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 +1898 -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/debounce.d.ts +1 -0
- package/lib/helpers/generate-uuid.d.ts +1 -0
- package/lib/helpers/save-to-local-drive.d.ts +1 -0
- package/lib/helpers/serialize.d.ts +1 -0
- package/lib/helpers/short-hash.d.ts +2 -0
- package/lib/helpers/signal.d.ts +23 -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/operators.d.ts +32 -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/debounce.ts +0 -10
- package/src/lib/helpers/generate-uuid.ts +0 -5
- package/src/lib/helpers/save-to-local-drive.ts +0 -31
- package/src/lib/helpers/serialize.ts +0 -11
- package/src/lib/helpers/short-hash.ts +0 -20
- package/src/lib/helpers/signal.ts +0 -46
- 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/operators.ts +0 -75
- 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
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { fitIntoRectangle } from '../geom';
|
|
2
|
-
import type { ImageOutputValues } from '../interfaces';
|
|
3
|
-
|
|
4
|
-
function getSnapshot2(
|
|
5
|
-
imageElement:
|
|
6
|
-
| HTMLImageElement
|
|
7
|
-
| HTMLCanvasElement
|
|
8
|
-
| HTMLVideoElement
|
|
9
|
-
| ImageBitmap,
|
|
10
|
-
maxWidth = 1024,
|
|
11
|
-
output: ImageOutputValues = 'image/png',
|
|
12
|
-
quality = 0.9,
|
|
13
|
-
): HTMLCanvasElement | string {
|
|
14
|
-
const drawableImage = imageElement as any;
|
|
15
|
-
const canvasHelper: HTMLCanvasElement = document.createElement('canvas');
|
|
16
|
-
const drawCTX: CanvasRenderingContext2D = canvasHelper.getContext(
|
|
17
|
-
'2d',
|
|
18
|
-
) as CanvasRenderingContext2D;
|
|
19
|
-
|
|
20
|
-
const prop = fitIntoRectangle(
|
|
21
|
-
{
|
|
22
|
-
x: 0,
|
|
23
|
-
y: 0,
|
|
24
|
-
w: drawableImage.naturalWidth || drawableImage.width,
|
|
25
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
x: 0,
|
|
29
|
-
y: 0,
|
|
30
|
-
w: maxWidth,
|
|
31
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const width = prop.w;
|
|
36
|
-
const height = prop.h;
|
|
37
|
-
canvasHelper.width = width;
|
|
38
|
-
canvasHelper.height = height;
|
|
39
|
-
|
|
40
|
-
drawCTX.save();
|
|
41
|
-
drawCTX.clearRect(0, 0, width, height);
|
|
42
|
-
drawCTX.drawImage(drawableImage, 0, 0, width, height);
|
|
43
|
-
drawCTX.restore();
|
|
44
|
-
|
|
45
|
-
if (output === 'canvas') {
|
|
46
|
-
return canvasHelper;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return canvasHelper.toDataURL(output, quality);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function getSnapshot(
|
|
53
|
-
imageElement:
|
|
54
|
-
| HTMLImageElement
|
|
55
|
-
| HTMLCanvasElement
|
|
56
|
-
| HTMLVideoElement
|
|
57
|
-
| ImageBitmap,
|
|
58
|
-
maxWidth = 1024,
|
|
59
|
-
output: ImageOutputValues = 'image/png',
|
|
60
|
-
quality = 0.9,
|
|
61
|
-
): HTMLCanvasElement | string {
|
|
62
|
-
const drawableImage = imageElement as any;
|
|
63
|
-
const canvasHelper: HTMLCanvasElement = document.createElement('canvas');
|
|
64
|
-
const drawCTX: CanvasRenderingContext2D = canvasHelper.getContext(
|
|
65
|
-
'2d',
|
|
66
|
-
) as CanvasRenderingContext2D;
|
|
67
|
-
|
|
68
|
-
const prop = fitIntoRectangle(
|
|
69
|
-
{
|
|
70
|
-
x: 0,
|
|
71
|
-
y: 0,
|
|
72
|
-
w: drawableImage.naturalWidth || drawableImage.width,
|
|
73
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
x: 0,
|
|
77
|
-
y: 0,
|
|
78
|
-
w: (drawableImage.naturalWidth || drawableImage.width) / 2,
|
|
79
|
-
h: drawableImage.naturalHeight || drawableImage.height,
|
|
80
|
-
},
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const width = prop.w;
|
|
84
|
-
const height = prop.h;
|
|
85
|
-
canvasHelper.width = width;
|
|
86
|
-
canvasHelper.height = height;
|
|
87
|
-
|
|
88
|
-
drawCTX.save();
|
|
89
|
-
drawCTX.clearRect(0, 0, width, height);
|
|
90
|
-
drawCTX.drawImage(drawableImage, 0, 0, width, height);
|
|
91
|
-
|
|
92
|
-
drawCTX.restore();
|
|
93
|
-
|
|
94
|
-
if (width > maxWidth * 2) {
|
|
95
|
-
return getSnapshot(canvasHelper, maxWidth, output, quality);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return getSnapshot2(drawableImage, maxWidth, output, quality);
|
|
99
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function loadImage(url: string): Promise<HTMLImageElement> {
|
|
2
|
-
return new Promise((resolve: any, reject) => {
|
|
3
|
-
const img = new Image();
|
|
4
|
-
img.crossOrigin = 'anonymous';
|
|
5
|
-
img.onload = () => {
|
|
6
|
-
setTimeout(() => resolve(img), 1);
|
|
7
|
-
};
|
|
8
|
-
img.onerror = () => {
|
|
9
|
-
setTimeout(() => reject(null), 1);
|
|
10
|
-
};
|
|
11
|
-
img.src = url;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
package/src/lib/math/clampf.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Clamps value between min and max;
|
|
3
|
-
* @param min minValue
|
|
4
|
-
* @param max maxValue
|
|
5
|
-
* @param value inputValue
|
|
6
|
-
* @returns number
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export function clampf(min: number, max: number, value: number): number {
|
|
10
|
-
if (min > max) {
|
|
11
|
-
return min;
|
|
12
|
-
}
|
|
13
|
-
return Math.min(max, Math.max(min, value));
|
|
14
|
-
}
|
package/src/lib/math/degrees.ts
DELETED
package/src/lib/math/lerp.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { clampf } from './clampf';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param min minimums
|
|
5
|
-
* @param max maximums
|
|
6
|
-
* @param value current float value in 0-1 range
|
|
7
|
-
* @returns clamped value
|
|
8
|
-
*/
|
|
9
|
-
export function lerp(min: number, max: number, value: number): number {
|
|
10
|
-
value = clampf(0, 1, value);
|
|
11
|
-
return value * (max - min) + min;
|
|
12
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Observable } from 'rxjs';
|
|
2
|
-
import { finalize, from, switchMap } from 'rxjs';
|
|
3
|
-
import { Logger } from '../dev';
|
|
4
|
-
import { Mutex } from './Mutex';
|
|
5
|
-
|
|
6
|
-
export class TaskRunner {
|
|
7
|
-
private mutex = new Mutex();
|
|
8
|
-
|
|
9
|
-
runTask(name: string, task: () => Observable<string | null>) {
|
|
10
|
-
// Log that the task is waiting to acquire the mutex
|
|
11
|
-
Logger.log(`${name} waiting to acquire mutex`);
|
|
12
|
-
|
|
13
|
-
return from(this.mutex.acquire()).pipe(
|
|
14
|
-
switchMap((release) => {
|
|
15
|
-
// Log that the mutex has been acquired
|
|
16
|
-
Logger.log(`${name} acquired mutex`);
|
|
17
|
-
return task().pipe(
|
|
18
|
-
finalize(() => {
|
|
19
|
-
Logger.log(`${name} releasing mutex`);
|
|
20
|
-
release();
|
|
21
|
-
}),
|
|
22
|
-
);
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
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 const Truthy: <T>(value: T) => value is TruthyTypesOf<T> = <T>(
|
|
12
|
-
value?: T,
|
|
13
|
-
): value is TruthyTypesOf<T> =>
|
|
14
|
-
!!value && value !== 'false' && value !== 'undefined' && value !== 'null';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The Boolean object represents an INVERSE truth value: true or false.
|
|
18
|
-
* @param value
|
|
19
|
-
* @constructor
|
|
20
|
-
* Returns:boolean
|
|
21
|
-
*/
|
|
22
|
-
export const Falsy: <T>(value: T) => value is FalsyTypesOf<T> = <T>(
|
|
23
|
-
value?: T,
|
|
24
|
-
): value is FalsyTypesOf<T> => !Truthy(value);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Checks if a value is empty.
|
|
28
|
-
*
|
|
29
|
-
* @param {any} value - The value to check.
|
|
30
|
-
* @return {boolean} Returns true if the value is empty, otherwise false.
|
|
31
|
-
*/
|
|
32
|
-
export const IsEmpty: <T>(value: T) => value is EmptyTypesOf<T> = <T>(
|
|
33
|
-
value: T,
|
|
34
|
-
): value is EmptyTypesOf<T> => {
|
|
35
|
-
return (
|
|
36
|
-
value === undefined ||
|
|
37
|
-
value === null ||
|
|
38
|
-
(typeof value === 'object' && Object.keys(value).length === 0) ||
|
|
39
|
-
(typeof value === 'string' && value.trim().length === 0)
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const NotEmpty: <T>(value: T) => value is NonEmptyTypesOf<T> = <T>(
|
|
44
|
-
value: T,
|
|
45
|
-
): value is NonEmptyTypesOf<T> => {
|
|
46
|
-
return !IsEmpty(value);
|
|
47
|
-
};
|
|
48
|
-
export const isDefined = <T>(arg: T | null | undefined): arg is T =>
|
|
49
|
-
arg !== null && arg !== undefined;
|
|
50
|
-
|
|
51
|
-
export const isNotDefined = <T>(
|
|
52
|
-
arg: T | null | undefined,
|
|
53
|
-
): arg is null | undefined => arg === null || arg === undefined;
|
|
54
|
-
|
|
55
|
-
export const isJSON = (str: string): boolean => {
|
|
56
|
-
try {
|
|
57
|
-
JSON.parse(str);
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.warn(e);
|
|
60
|
-
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return true;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const isEmpty = (value: any) =>
|
|
68
|
-
value === undefined ||
|
|
69
|
-
value === null ||
|
|
70
|
-
(typeof value === 'object' && Object.keys(value).length === 0) ||
|
|
71
|
-
(typeof value === 'string' && value.trim().length === 0);
|
|
72
|
-
|
|
73
|
-
export function isAllValuesTruthy<T extends string, K>(value: Record<T, K>) {
|
|
74
|
-
return Object.values(value).every(Truthy);
|
|
75
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { SchedulerLike, Subscriber, Subscription } from 'rxjs';
|
|
2
|
-
import { asyncScheduler, Observable, timer } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Emits the most recent value emitted by the source Observable after a
|
|
6
|
-
* specified time span has passed without another source emission.
|
|
7
|
-
*
|
|
8
|
-
* This is a combination of `debounceTime` and `auditTime` operators.
|
|
9
|
-
*
|
|
10
|
-
* The leading value is emitted immediately, and trailing values are debounced.
|
|
11
|
-
*
|
|
12
|
-
* @param dueTime The time to wait before emitting the last value.
|
|
13
|
-
* @param scheduler The scheduler to use for the timeout.
|
|
14
|
-
* @returns A function that returns an Observable that mirrors the source Observable, but applies the specified debouncing.
|
|
15
|
-
*/
|
|
16
|
-
export function leadingTrailingDebounceTime<T>(
|
|
17
|
-
dueTime: number,
|
|
18
|
-
scheduler: SchedulerLike = asyncScheduler,
|
|
19
|
-
): (source: Observable<T>) => Observable<T> {
|
|
20
|
-
return (source: Observable<T>) =>
|
|
21
|
-
new Observable<T>((subscriber: Subscriber<T>) => {
|
|
22
|
-
let hasValue = false;
|
|
23
|
-
let lastValue: T | null = null;
|
|
24
|
-
let timerSubscription: Subscription | null = null;
|
|
25
|
-
let leading = true; // Controls whether we emit immediately.
|
|
26
|
-
|
|
27
|
-
const clearTimer = () => {
|
|
28
|
-
if (timerSubscription) {
|
|
29
|
-
timerSubscription.unsubscribe();
|
|
30
|
-
timerSubscription = null;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const resetValues = () => {
|
|
35
|
-
hasValue = false;
|
|
36
|
-
lastValue = null;
|
|
37
|
-
leading = true; // Reset so the next new value is immediate.
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const emitLastValue = () => {
|
|
41
|
-
if (hasValue && lastValue !== null) {
|
|
42
|
-
subscriber.next(lastValue);
|
|
43
|
-
resetValues();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const sourceSubscription = source.subscribe({
|
|
48
|
-
next: (value) => {
|
|
49
|
-
// If we are "leading", emit immediately and switch leading off
|
|
50
|
-
if (leading) {
|
|
51
|
-
subscriber.next(value);
|
|
52
|
-
leading = false;
|
|
53
|
-
timerSubscription = timer(dueTime, scheduler).subscribe(() => {
|
|
54
|
-
resetValues();
|
|
55
|
-
clearTimer();
|
|
56
|
-
});
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Otherwise, save the value and start (or restart) timer
|
|
61
|
-
hasValue = true;
|
|
62
|
-
lastValue = value;
|
|
63
|
-
clearTimer();
|
|
64
|
-
timerSubscription = timer(dueTime, scheduler).subscribe(() => {
|
|
65
|
-
emitLastValue();
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
error: (err: unknown) => {
|
|
69
|
-
clearTimer();
|
|
70
|
-
subscriber.error(err);
|
|
71
|
-
},
|
|
72
|
-
complete: () => {
|
|
73
|
-
// If there is a pending emission, emit it before completing
|
|
74
|
-
clearTimer();
|
|
75
|
-
emitLastValue();
|
|
76
|
-
subscriber.complete();
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Cleanup logic
|
|
81
|
-
return () => {
|
|
82
|
-
clearTimer();
|
|
83
|
-
sourceSubscription.unsubscribe();
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
package/src/lib/rxjs/tapLog.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { tap } from 'rxjs/operators';
|
|
2
|
-
import type { Observable } from 'rxjs';
|
|
3
|
-
import { Logger } from '../dev';
|
|
4
|
-
import { COLOR_CODES } from '../constants';
|
|
5
|
-
|
|
6
|
-
export const tapLog =
|
|
7
|
-
<T>(text: string, ...args: any): ((source: Observable<T>) => Observable<T>) =>
|
|
8
|
-
(source: Observable<T>) =>
|
|
9
|
-
source.pipe(
|
|
10
|
-
tap((data) => {
|
|
11
|
-
Logger.colored(...COLOR_CODES.TAP_LOG, text, data, ...args);
|
|
12
|
-
}),
|
|
13
|
-
);
|
package/src/lib/strings/pad.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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 function pad(
|
|
9
|
-
input: number | string,
|
|
10
|
-
size: number,
|
|
11
|
-
symbol = '0',
|
|
12
|
-
): string {
|
|
13
|
-
let s = input + '';
|
|
14
|
-
while (s.length < size) {
|
|
15
|
-
s = symbol + s;
|
|
16
|
-
}
|
|
17
|
-
return s.slice(-size);
|
|
18
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
-
{
|
|
4
|
-
"extends": "../../../tsconfig.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"outDir": "../../../out-tsc/lib",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"inlineSources": true,
|
|
10
|
-
"types": []
|
|
11
|
-
},
|
|
12
|
-
"exclude": ["**/*.spec.ts"]
|
|
13
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
-
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
-
{
|
|
4
|
-
"extends": "./tsconfig.lib.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"declarationMap": false
|
|
7
|
-
},
|
|
8
|
-
"angularCompilerOptions": {
|
|
9
|
-
"compilationMode": "partial"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|