@3dsource/utils 1.0.8 → 1.0.10

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.
Files changed (139) hide show
  1. package/eslint.config.js +37 -0
  2. package/ng-package.json +7 -0
  3. package/package.json +5 -14
  4. package/{lib/color/CMYKtoRGB.d.ts → src/lib/color/CMYKtoRGB.ts} +11 -1
  5. package/src/lib/color/HEXtoRGB.ts +9 -0
  6. package/src/lib/color/HSVtoRGB.ts +82 -0
  7. package/{lib/color/RGBtoCMYK.d.ts → src/lib/color/RGBtoCMYK.ts} +31 -1
  8. package/src/lib/color/RGBtoHEX.ts +17 -0
  9. package/src/lib/color/RGBtoHSV.ts +53 -0
  10. package/src/lib/color/hsv.ts +14 -0
  11. package/src/lib/color/max.ts +18 -0
  12. package/src/lib/color/min.ts +18 -0
  13. package/src/lib/color/overlay.ts +25 -0
  14. package/{lib/color/rgb.d.ts → src/lib/color/rgb.ts} +3 -1
  15. package/src/lib/color/sub.ts +18 -0
  16. package/src/lib/color/subtract.ts +27 -0
  17. package/src/lib/color/sum.ts +19 -0
  18. package/{lib/color/toRGB.d.ts → src/lib/color/toRGB.ts} +7 -1
  19. package/src/lib/color/toRGBA.ts +8 -0
  20. package/src/lib/constants/color-codes.constant.ts +9 -0
  21. package/src/lib/csv/CSV2Array.ts +66 -0
  22. package/src/lib/csv/CSV2Records.ts +56 -0
  23. package/src/lib/csv/ObjectToCSV.ts +21 -0
  24. package/src/lib/dev/dev3d.ts +1 -0
  25. package/src/lib/dev/logger.ts +94 -0
  26. package/src/lib/dev/timeToString.ts +16 -0
  27. package/src/lib/filenaming/cleanupFileName.ts +18 -0
  28. package/src/lib/filenaming/makePath.ts +5 -0
  29. package/src/lib/filenaming/normalizePath.ts +9 -0
  30. package/src/lib/geom/expandOverRectangle.ts +17 -0
  31. package/src/lib/geom/fitIntoRectangle.ts +43 -0
  32. package/{lib/geom/interfaces/area.interface.d.ts → src/lib/geom/interfaces/area.interface.ts} +2 -1
  33. package/{lib/geom/interfaces/rect.interface.d.ts → src/lib/geom/interfaces/rect.interface.ts} +2 -2
  34. package/src/lib/geom/interfaces/size.interface.ts +4 -0
  35. package/src/lib/geom/interfaces//321/201oords.interface.ts +4 -0
  36. package/src/lib/helpers/BatchLoader.ts +243 -0
  37. package/src/lib/helpers/KeyboardNumericCode.ts +118 -0
  38. package/src/lib/helpers/debounce.ts +10 -0
  39. package/src/lib/helpers/generate-uuid.ts +5 -0
  40. package/{lib/helpers/index.d.ts → src/lib/helpers/index.ts} +2 -0
  41. package/src/lib/helpers/save-to-local-drive.ts +31 -0
  42. package/src/lib/helpers/serialize.ts +11 -0
  43. package/src/lib/helpers/short-hash.ts +20 -0
  44. package/src/lib/helpers/signal.ts +46 -0
  45. package/src/lib/helpers/sleep.ts +3 -0
  46. package/src/lib/helpers/trimLastSlashFromUrl.ts +9 -0
  47. package/src/lib/image/SaveImage.ts +65 -0
  48. package/src/lib/image/getCanvasCached.ts +16 -0
  49. package/src/lib/image/getSnapshot.ts +99 -0
  50. package/src/lib/image/loadImage.ts +13 -0
  51. package/src/lib/interfaces/image-output.ts +8 -0
  52. package/{lib/interfaces/load-args-tmp.interface.d.ts → src/lib/interfaces/load-args-tmp.interface.ts} +2 -1
  53. package/src/lib/interfaces/load-args.interface.ts +15 -0
  54. package/{lib/math/baseSortedIndex.d.ts → src/lib/math/baseSortedIndex.ts} +19 -1
  55. package/{lib/math/calculateMedian.d.ts → src/lib/math/calculateMedian.ts} +17 -1
  56. package/{lib/math/circularIndex.d.ts → src/lib/math/circularIndex.ts} +5 -1
  57. package/src/lib/math/clampf.ts +14 -0
  58. package/src/lib/math/degrees.ts +7 -0
  59. package/{lib/math/floatCompare.d.ts → src/lib/math/floatCompare.ts} +30 -3
  60. package/{lib/math/inverseLerp.d.ts → src/lib/math/inverseLerp.ts} +22 -1
  61. package/src/lib/math/lerp.ts +12 -0
  62. package/{lib/mutex/Mutex.d.ts → src/lib/mutex/Mutex.ts} +15 -8
  63. package/{lib/mutex/Semaphore.d.ts → src/lib/mutex/Semaphore.ts} +27 -7
  64. package/src/lib/mutex/TaskRunner.ts +26 -0
  65. package/src/lib/predicates/operators.ts +75 -0
  66. package/{lib/predicates/textForSearch.d.ts → src/lib/predicates/textForSearch.ts} +17 -1
  67. package/{lib/predicates/where.d.ts → src/lib/predicates/where.ts} +32 -2
  68. package/src/lib/rxjs/leadingTrailingDebounceTime.ts +86 -0
  69. package/{lib/rxjs/smoothTransition.d.ts → src/lib/rxjs/smoothTransition.ts} +19 -1
  70. package/src/lib/rxjs/tapLog.ts +13 -0
  71. package/src/lib/strings/pad.ts +18 -0
  72. package/tsconfig.lib.json +13 -0
  73. package/tsconfig.lib.prod.json +11 -0
  74. package/fesm2022/3dsource-utils.mjs +0 -1881
  75. package/fesm2022/3dsource-utils.mjs.map +0 -1
  76. package/index.d.ts +0 -5
  77. package/lib/color/HEXtoRGB.d.ts +0 -5
  78. package/lib/color/HSVtoRGB.d.ts +0 -21
  79. package/lib/color/RGBtoHEX.d.ts +0 -1
  80. package/lib/color/RGBtoHSV.d.ts +0 -19
  81. package/lib/color/hsv.d.ts +0 -1
  82. package/lib/color/max.d.ts +0 -1
  83. package/lib/color/min.d.ts +0 -1
  84. package/lib/color/overlay.d.ts +0 -1
  85. package/lib/color/sub.d.ts +0 -1
  86. package/lib/color/subtract.d.ts +0 -1
  87. package/lib/color/sum.d.ts +0 -1
  88. package/lib/color/toRGBA.d.ts +0 -1
  89. package/lib/constants/color-codes.constant.d.ts +0 -9
  90. package/lib/csv/CSV2Array.d.ts +0 -1
  91. package/lib/csv/CSV2Records.d.ts +0 -1
  92. package/lib/csv/ObjectToCSV.d.ts +0 -1
  93. package/lib/dev/dev3d.d.ts +0 -1
  94. package/lib/dev/logger.d.ts +0 -11
  95. package/lib/dev/timeToString.d.ts +0 -5
  96. package/lib/filenaming/cleanupFileName.d.ts +0 -1
  97. package/lib/filenaming/makePath.d.ts +0 -1
  98. package/lib/filenaming/normalizePath.d.ts +0 -1
  99. package/lib/geom/expandOverRectangle.d.ts +0 -2
  100. package/lib/geom/fitIntoRectangle.d.ts +0 -2
  101. package/lib/geom/interfaces/size.interface.d.ts +0 -4
  102. package/lib/geom/interfaces//321/201oords.interface.d.ts +0 -4
  103. package/lib/helpers/BatchLoader.d.ts +0 -47
  104. package/lib/helpers/KeyboardNumericCode.d.ts +0 -103
  105. package/lib/helpers/debounce.d.ts +0 -1
  106. package/lib/helpers/save-to-local-drive.d.ts +0 -1
  107. package/lib/helpers/serialize.d.ts +0 -1
  108. package/lib/helpers/signal.d.ts +0 -23
  109. package/lib/helpers/sleep.d.ts +0 -1
  110. package/lib/helpers/trimLastSlashFromUrl.d.ts +0 -1
  111. package/lib/image/SaveImage.d.ts +0 -18
  112. package/lib/image/getCanvasCached.d.ts +0 -4
  113. package/lib/image/getSnapshot.d.ts +0 -2
  114. package/lib/image/loadImage.d.ts +0 -1
  115. package/lib/interfaces/image-output.d.ts +0 -7
  116. package/lib/interfaces/load-args.interface.d.ts +0 -15
  117. package/lib/math/clampf.d.ts +0 -8
  118. package/lib/math/degrees.d.ts +0 -2
  119. package/lib/math/lerp.d.ts +0 -7
  120. package/lib/mutex/TaskRunner.d.ts +0 -5
  121. package/lib/predicates/operators.d.ts +0 -32
  122. package/lib/rxjs/leadingTrailingDebounceTime.d.ts +0 -15
  123. package/lib/rxjs/tapLog.d.ts +0 -2
  124. package/lib/strings/pad.d.ts +0 -8
  125. /package/{lib/color/index.d.ts → src/lib/color/index.ts} +0 -0
  126. /package/{lib/constants/index.d.ts → src/lib/constants/index.ts} +0 -0
  127. /package/{lib/csv/index.d.ts → src/lib/csv/index.ts} +0 -0
  128. /package/{lib/dev/index.d.ts → src/lib/dev/index.ts} +0 -0
  129. /package/{lib/filenaming/index.d.ts → src/lib/filenaming/index.ts} +0 -0
  130. /package/{lib/geom/index.d.ts → src/lib/geom/index.ts} +0 -0
  131. /package/{lib/geom/interfaces/index.d.ts → src/lib/geom/interfaces/index.ts} +0 -0
  132. /package/{lib/image/index.d.ts → src/lib/image/index.ts} +0 -0
  133. /package/{lib/interfaces/index.d.ts → src/lib/interfaces/index.ts} +0 -0
  134. /package/{lib/math/index.d.ts → src/lib/math/index.ts} +0 -0
  135. /package/{lib/mutex/index.d.ts → src/lib/mutex/index.ts} +0 -0
  136. /package/{lib/predicates/index.d.ts → src/lib/predicates/index.ts} +0 -0
  137. /package/{lib/rxjs/index.d.ts → src/lib/rxjs/index.ts} +0 -0
  138. /package/{lib/strings/index.d.ts → src/lib/strings/index.ts} +0 -0
  139. /package/{public-api.d.ts → src/public-api.ts} +0 -0
@@ -1,4 +1,6 @@
1
+ import { textForSearch } from './textForSearch';
1
2
  import type { TruthyTypesOf } from 'rxjs';
3
+
2
4
  /**
3
5
  * Creates a predicate function to filter records from a collection based on specified criteria.
4
6
  *
@@ -42,5 +44,33 @@ import type { TruthyTypesOf } from 'rxjs';
42
44
  * ensuring the function is only used with object types. This generic approach allows for flexible usage
43
45
  * with various record structures.
44
46
  */
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;
47
+
48
+ export function where<T extends object>(
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
+ }
@@ -0,0 +1,86 @@
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
+ }
@@ -1,4 +1,8 @@
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
+
2
6
  /**
3
7
  * Creates an observable that emits values transitioning smoothly from the start value to the end value over a specified duration.
4
8
  * The transition is performed using linear interpolation (lerp) and clamped to the range [0, 1].
@@ -8,4 +12,18 @@ import type { Observable } from 'rxjs';
8
12
  * @param {number} duration - The duration of the transition in milliseconds.
9
13
  * @returns {Observable<number>} An observable that emits the interpolated values from start to end over the specified duration.
10
14
  */
11
- export declare const smoothTransition: (start: number, end: number, duration: number) => Observable<number>;
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
+ };
@@ -0,0 +1,13 @@
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
+ );
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ }