@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
@@ -0,0 +1,37 @@
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
+ );
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../../dist/3dsource/utils",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,22 +1,13 @@
1
1
  {
2
2
  "name": "@3dsource/utils",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "sideEffects": false,
5
5
  "dependencies": {
6
6
  "tslib": "^2.8.1"
7
7
  },
8
8
  "peerDependencies": {
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
- }
9
+ "rxjs": "^7.8.2",
10
+ "uuid": "^11.1.0",
11
+ "ts-md5": "^1.3.1"
21
12
  }
22
- }
13
+ }
@@ -7,4 +7,14 @@
7
7
  * K - number between 0 and 255 representing black
8
8
  *
9
9
  **/
10
- export declare function CMYKtoRGB(c: number, m: number, y: number, k: number): any[];
10
+ export function CMYKtoRGB(c: number, m: number, y: number, k: number): any[] {
11
+ c = 255 - c;
12
+ m = 255 - m;
13
+ y = 255 - y;
14
+ k = 255 - k;
15
+ return [
16
+ ((255 - c) * (255 - k)) / 255,
17
+ ((255 - m) * (255 - k)) / 255,
18
+ ((255 - y) * (255 - k)) / 255,
19
+ ];
20
+ }
@@ -0,0 +1,9 @@
1
+ export function HEXtoRGB(color: number | string) {
2
+ if (typeof color === 'string') {
3
+ color = parseInt(color.replace('#', ''), 16);
4
+ }
5
+ const r = (color >> 16) & 255;
6
+ const g = (color >> 8) & 255;
7
+ const b = color & 255;
8
+ return { r: r, g: g, b: b };
9
+ }
@@ -0,0 +1,82 @@
1
+ /* eslint-disable prefer-const */
2
+ /**
3
+ * HSV from each of the RGB values to determine a return as an any[].
4
+ * RGB values are as follows.
5
+ * R - a number from 0 to 255
6
+ * G - a number from 0 to 255
7
+ * B - a number from 0 to 255
8
+ *
9
+ * HSV values are as follows.
10
+ * H - a number between 360-0
11
+ * S - number between 0 and 1.0
12
+ * V - number between 0 and 1.0
13
+ *
14
+ * H is replaced with equivalent numbers in the range of the 360-0 that is out of range.
15
+ * Cannot compute, including alpha.
16
+ *
17
+ * @ Param h hue (Hue) number that indicates (to 360-0)
18
+ * @ Param s the saturation (Saturation) shows the number (0.0 to 1.0)
19
+ * @ Param v lightness (Value) indicates the number (0.0 to 1.0)
20
+ * @ Return RGB values into an any[] of [R, G, B]
21
+ **/
22
+
23
+ export function HSVtoRGB(h: number, s: number, v: number): number[] {
24
+ let r = 0,
25
+ g = 0,
26
+ b = 0;
27
+ let i, x, y, z;
28
+ if (s < 0) {
29
+ s = 0;
30
+ }
31
+ if (s > 1) {
32
+ s = 1;
33
+ }
34
+ if (v < 0) {
35
+ v = 0;
36
+ }
37
+ if (v > 1) {
38
+ v = 1;
39
+ }
40
+ h = h % 360;
41
+ if (h < 0) {
42
+ h += 360;
43
+ }
44
+ h /= 60;
45
+ i = h >> 0;
46
+ x = v * (1 - s);
47
+ y = v * (1 - s * (h - i));
48
+ z = v * (1 - s * (1 - h + i));
49
+ switch (i) {
50
+ case 0:
51
+ r = v;
52
+ g = z;
53
+ b = x;
54
+ break;
55
+ case 1:
56
+ r = y;
57
+ g = v;
58
+ b = x;
59
+ break;
60
+ case 2:
61
+ r = x;
62
+ g = v;
63
+ b = z;
64
+ break;
65
+ case 3:
66
+ r = x;
67
+ g = y;
68
+ b = v;
69
+ break;
70
+ case 4:
71
+ r = z;
72
+ g = x;
73
+ b = v;
74
+ break;
75
+ case 5:
76
+ r = v;
77
+ g = x;
78
+ b = y;
79
+ break;
80
+ }
81
+ return [(r * 255) >> 0, (g * 255) >> 0, (b * 255) >> 0];
82
+ }
@@ -17,4 +17,34 @@
17
17
  * @ Param b blue (B) shows the number (0x00 to 0xFF to)
18
18
  * @ Return CMYK values into an any[] of [H, S, V]
19
19
  **/
20
- export declare function RGBtoCMYK(r: number, g: number, b: number): any[];
20
+ export function RGBtoCMYK(r: number, g: number, b: number): any[] {
21
+ let c = 0;
22
+ let m = 0;
23
+ let y = 0;
24
+ let k = 0;
25
+
26
+ c = 255 - r;
27
+ m = 255 - g;
28
+ y = 255 - b;
29
+ k = 255;
30
+
31
+ if (c < k) {
32
+ k = c;
33
+ }
34
+ if (m < k) {
35
+ k = m;
36
+ }
37
+ if (y < k) {
38
+ k = y;
39
+ }
40
+ if (k === 255) {
41
+ c = 0;
42
+ m = 0;
43
+ y = 0;
44
+ } else {
45
+ c = Math.round((255 * (c - k)) / (255 - k));
46
+ m = Math.round((255 * (m - k)) / (255 - k));
47
+ y = Math.round((255 * (y - k)) / (255 - k));
48
+ }
49
+ return [c, m, y, k];
50
+ }
@@ -0,0 +1,17 @@
1
+ export function RGBtoHEX(r: number, g: number, b: number): string {
2
+ let redColor = r.toString(16);
3
+ let greenColor = g.toString(16);
4
+ let blackColor = b.toString(16);
5
+
6
+ if (redColor.length === 1) {
7
+ redColor = '0' + redColor;
8
+ }
9
+ if (greenColor.length === 1) {
10
+ greenColor = '0' + greenColor;
11
+ }
12
+ if (blackColor.length === 1) {
13
+ blackColor = '0' + blackColor;
14
+ }
15
+
16
+ return (redColor + greenColor + blackColor).toUpperCase();
17
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * RGB from the respective figures, HSV sequences in terms of returns.
3
+ * RGB values are as follows.
4
+ * R - a number from 0 to 255
5
+ * G - a number from 0 to 255
6
+ * B - a number from 0 to 255
7
+ *
8
+ * HSV values are as follows.
9
+ * H - a number between 360-0
10
+ * S - number between 0 and 1.0
11
+ * V - number between 0 and 1.0
12
+ *
13
+ * Cannot compute, including alpha.
14
+ * @ Param r the red (R) indicating the number (0x00 to 0xFF to)
15
+ * @ Param g green (G) indicates the number (0x00 to 0xFF to)
16
+ * @ Param b blue (B) shows the number (0x00 to 0xFF to)
17
+ * @ Return HSV values into an any[] of [H, S, V]
18
+ **/
19
+ export function RGBtoHSV(r: number, g: number, b: number): number[] {
20
+ r /= 255;
21
+ g /= 255;
22
+ b /= 255;
23
+ let h = 0,
24
+ s = 0,
25
+ v = 0;
26
+ let x: number, y: number;
27
+ if (r >= g) x = r;
28
+ else x = g;
29
+ if (b > x) x = b;
30
+ if (r <= g) y = r;
31
+ else y = g;
32
+ if (b < y) y = b;
33
+ v = x;
34
+ const c: number = x - y;
35
+ if (x === 0) s = 0;
36
+ else s = c / x;
37
+ if (s !== 0) {
38
+ if (r === x) {
39
+ h = (g - b) / c;
40
+ } else {
41
+ if (g === x) {
42
+ h = 2 + (b - r) / c;
43
+ } else {
44
+ if (b === x) {
45
+ h = 4 + (r - g) / c;
46
+ }
47
+ }
48
+ }
49
+ h = h * 60;
50
+ if (h < 0) h = h + 360;
51
+ }
52
+ return [h, s, v];
53
+ }
@@ -0,0 +1,14 @@
1
+ /* eslint-disable prefer-spread */
2
+ /**
3
+ * HSV calculated from the numbers of each RGB color value.
4
+ * @ Param h hue (Hue) number that indicates (to 360-0)
5
+ * @ Param s the saturation (Saturation) shows the number (0.0 to 1.0)
6
+ * @ Param v lightness (Value) indicates the number (0.0 to 1.0)
7
+ * @ Return obtained from the RGB color value for each indicating the number
8
+ **/
9
+ import { rgb } from './rgb';
10
+ import { HSVtoRGB } from './HSVtoRGB';
11
+
12
+ export function hsv(h: number, s: number, v: number): number {
13
+ return rgb.apply(null, HSVtoRGB(h, s, v) as any);
14
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Comparison (light).
3
+ * 2 RGB single number that indicates (0x000000 0xFFFFFF up from) to compare,
4
+ * RGB values combined with higher returns to their numbers.
5
+ * @ Param col1 RGB numbers show (0x000000 0xFFFFFF up from)
6
+ * @ Param col2 RGB numbers show (0x000000 0xFFFFFF up from)
7
+ * @ Return comparison (light) value
8
+ **/
9
+ import { toRGB } from './toRGB';
10
+
11
+ export function max(col1: number, col2: number): number {
12
+ const c1: any[] = toRGB(col1);
13
+ const c2: any[] = toRGB(col2);
14
+ const r: number = Math.max(c1[0], c2[0]);
15
+ const g: number = Math.max(c1[1], c2[1]);
16
+ const b: number = Math.max(c1[2], c2[2]);
17
+ return (r << 16) | (g << 8) | b;
18
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Comparison (dark).
3
+ * 2 RGB single numbers that indicate (0x000000 0xFFFFFF up from) to compare,
4
+ * RGB lower combined returns a numeric value for each number.
5
+ * @ Param col1 RGB numbers show (0x000000 0xFFFFFF up from)
6
+ * @ Param col2 RGB numbers show (0x000000 0xFFFFFF up from)
7
+ * @ Return comparison (dark) values
8
+ **/
9
+ import { toRGB } from './toRGB';
10
+
11
+ export function min(col1: number, col2: number): number {
12
+ const c1: any[] = toRGB(col1);
13
+ const c2: any[] = toRGB(col2);
14
+ const r: number = Math.min(c1[0], c2[0]);
15
+ const g: number = Math.min(c1[1], c2[1]);
16
+ const b: number = Math.min(c1[2], c2[2]);
17
+ return (r << 16) | (g << 8) | b;
18
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ *
3
+ There are two part of formula:
4
+ First part: If Lower Layer Value > 127.5, then do the following -
5
+ Value Unit = (255-Lower Layer Value)/127.5
6
+ Min Value = Lower Layer Value - (255-Lower Layer Value)
7
+ Overlay = (Upper Layer Value * Value Unit) + Min Value
8
+ Second part: If Lower Layer Value < 127.5, then do the following -
9
+ Value Unit=Lower Layer Value/127.5
10
+
11
+ Overlay = Upper Layer Value * Value Unit
12
+ * @param {number} col1
13
+ * @param {number} col2
14
+ * @return {number}
15
+ */
16
+ import { toRGB } from './toRGB';
17
+
18
+ export function overlay(col1: number, col2: number): number {
19
+ const c1: any[] = toRGB(col1);
20
+ const c2: any[] = toRGB(col2);
21
+ const r: number = Math.max(c1[0], c2[0]);
22
+ const g: number = Math.max(c1[1], c2[1]);
23
+ const b: number = Math.max(c1[2], c2[2]);
24
+ return (r << 16) | (g << 8) | b;
25
+ }
@@ -5,4 +5,6 @@
5
5
  * @ Param b blue (B) shows the number (0-255)
6
6
  * @ Return obtained from the RGB color value for each indicating the number
7
7
  **/
8
- export declare function rgb(r: number, g: number, b: number): number;
8
+ export function rgb(r: number, g: number, b: number): number {
9
+ return (r << 16) | (g << 8) | b;
10
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Subtractive.
3
+ * 2 RGB single numbers that indicate (0x000000 0xFFFFFF up from) Return the value
4
+ * of the subtractive color.
5
+ * @ Param col1 RGB numbers show (0x000000 0xFFFFFF up from)
6
+ * @ Param col2 RGB numbers show (0x000000 0xFFFFFF up from)
7
+ * @ Return the subtractive
8
+ **/
9
+ import { toRGB } from './toRGB';
10
+
11
+ export function sub(col1: number, col2: number): number {
12
+ const c1: any[] = toRGB(col1);
13
+ const c2: any[] = toRGB(col2);
14
+ const r: number = Math.max(c1[0] - c2[0], 0);
15
+ const g: number = Math.max(c1[1] - c2[1], 0);
16
+ const b: number = Math.max(c1[2] - c2[2], 0);
17
+ return (r << 16) | (g << 8) | b;
18
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Subtraction.
3
+ * 2 RGB single number that indicates (0x000000 0xFFFFFF up from) is subtracted
4
+ * from the return numbers.
5
+ * @ Param col1 RGB numbers show (0x000000 0xFFFFFF up from)
6
+ * @ Param col2 RGB numbers show (0x000000 0xFFFFFF up from)
7
+ * @ Return value subtracted Blend
8
+ **/
9
+ import { toRGB } from './toRGB';
10
+
11
+ export function subtract(col1: number, col2: number): number {
12
+ const colA: any[] = toRGB(col1);
13
+ const colB: any[] = toRGB(col2);
14
+ const r: number = Math.max(
15
+ Math.max(colB[0] - (256 - colA[0]), colA[0] - (256 - colB[0])),
16
+ 0,
17
+ );
18
+ const g: number = Math.max(
19
+ Math.max(colB[1] - (256 - colA[1]), colA[1] - (256 - colB[1])),
20
+ 0,
21
+ );
22
+ const b: number = Math.max(
23
+ Math.max(colB[2] - (256 - colA[2]), colA[2] - (256 - colB[2])),
24
+ 0,
25
+ );
26
+ return (r << 16) | (g << 8) | b;
27
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Additive color.
3
+ * 2 RGB single numbers that indicate (0x000000 0xFFFFFF up from) Return the value
4
+ * of the additive mixture.
5
+ * @ Param col1 RGB numbers show (0x000000 0xFFFFFF up from)
6
+ * @ Param col2 RGB numbers show (0x000000 0xFFFFFF up from)
7
+ * @ Return the additive color
8
+ **/
9
+ import { toRGB } from './toRGB';
10
+
11
+ export function sum(col1: number, col2: number): number {
12
+ const c1: any[] = toRGB(col1);
13
+ const c2: any[] = toRGB(col2);
14
+ const r: number = Math.min(c1[0] + c2[0], 255);
15
+ const g: number = Math.min(c1[1] + c2[1], 255);
16
+ const b: number = Math.min(c1[2] + c2[2], 255);
17
+
18
+ return (r << 16) | (g << 8) | b;
19
+ }
@@ -5,4 +5,10 @@
5
5
  * @ Param rgb numbers show (0x000000 0xFFFFFF up from)
6
6
  * @ Return any[] indicates the value of each color [R, G, B]
7
7
  **/
8
- export declare function toRGB(rgb: number): number[];
8
+ export function toRGB(rgb: number): number[] {
9
+ const r: number = (rgb >> 16) & 0xff;
10
+ const g: number = (rgb >> 8) & 0xff;
11
+ const b: number = rgb & 0xff;
12
+
13
+ return [r, g, b];
14
+ }
@@ -0,0 +1,8 @@
1
+ export function toRGBA(rgba: number): number[] {
2
+ const a: number = (rgba >> 24) & 0xff;
3
+ const r: number = (rgba >> 16) & 0xff;
4
+ const g: number = (rgba >> 8) & 0xff;
5
+ const b: number = rgba & 0xff;
6
+
7
+ return [r, g, b, a];
8
+ }
@@ -0,0 +1,9 @@
1
+ export const COLOR_CODES = {
2
+ TO_UNREAL: ['#ffffff', '#005912', `UNREAL <-`],
3
+ TAP_LOG: ['#ffff00', '#1976d2', ' [TAPLOG]'],
4
+ FROM_UNREAL: ['#ffff00', '#898989', 'UNREAL ->'],
5
+ FROM_UNREAL_ERROR: ['#ffffff', '#ff0000', 'UNREAL ERROR ->'],
6
+ FROM_CIRRUS: ['#ffffff', '#ef702b', 'CIRRUS ->'],
7
+ FROM_CIRRUS_ERROR: ['#ffffff', '#ff0000', 'CIRRUS ->'],
8
+ TO_CIRRUS: ['#ffffff', '#3c9738', 'CIRRUS <-'],
9
+ } as const;
@@ -0,0 +1,66 @@
1
+ export function CSV2Array(strData: any, strDelimiter?: string): any[] {
2
+ // Check to see if the delimiter is defined. If not,
3
+ // then default to comma.
4
+ strDelimiter = strDelimiter || ',';
5
+
6
+ // Create a regular expression to parse the CSV values.
7
+ const objPattern = new RegExp(
8
+ // Delimiters.
9
+ '(\\' +
10
+ strDelimiter +
11
+ '|\\r?\\n|\\r|^)' +
12
+ // Quoted fields.
13
+ '(?:"([^"]*(?:""[^"]*)*)"|' +
14
+ // Standard fields.
15
+ '([^"\\' +
16
+ strDelimiter +
17
+ '\\r\\n]*))',
18
+ 'gi',
19
+ );
20
+
21
+ // Create an array to hold our data. Give the array
22
+ // a default empty first row.
23
+ const arrData: any[] = [[]];
24
+
25
+ // Create an array to hold our individual pattern
26
+ // matching groups.
27
+ let arrMatches = null;
28
+
29
+ // Keep looping over the regular expression matches
30
+ // until we can no longer find a match.
31
+ while ((arrMatches = objPattern.exec(strData))) {
32
+ // Get the delimiter that was found.
33
+ const strMatchedDelimiter = arrMatches[1];
34
+
35
+ // Check to see if the given delimiter has a length
36
+ // (is not the start of string) and if it matches
37
+ // field delimiter. If idKey does not, then we know
38
+ // that this delimiter is a row delimiter.
39
+ if (strMatchedDelimiter.length && strMatchedDelimiter !== strDelimiter) {
40
+ // Since we have reached a new row of data,
41
+ // add an empty row to our data array.
42
+ arrData.push([]);
43
+ }
44
+
45
+ let strMatchedValue: any;
46
+
47
+ // Now that we have our delimiter out of the way,
48
+ // let's check to see which kind of value we
49
+ // captured (quoted or unquoted).
50
+ if (arrMatches[2]) {
51
+ // We found a quoted value. When we capture
52
+ // this value, unescape any double quotes.
53
+ strMatchedValue = arrMatches[2].replace(new RegExp('""', 'g'), '"');
54
+ } else {
55
+ // We found a non-quoted value.
56
+ strMatchedValue = arrMatches[3];
57
+ }
58
+
59
+ // Now that we have our value string, let's add
60
+ // it to the data array.
61
+ arrData[arrData.length - 1].push(strMatchedValue);
62
+ }
63
+
64
+ // Return the parsed data.
65
+ return arrData;
66
+ }
@@ -0,0 +1,56 @@
1
+ import { CSV2Array } from './CSV2Array';
2
+
3
+ const booleanRegex = /^(true|false)$/i;
4
+ const trueRegex = /^(true)$/i;
5
+ const jsonRegex = /([\d.]+)|(\[])|(\[.+])|({.+})/i;
6
+
7
+ const zipObject = (props: string[], values: any[]) =>
8
+ props.reduce(
9
+ (obj: any, prop, index) => ((obj[prop] = values[index]), obj),
10
+ {},
11
+ );
12
+
13
+ const toHead = (input: any): string => {
14
+ return String(input).trim();
15
+ };
16
+
17
+ const toCorrectString = (input: any): any => {
18
+ if (typeof input === 'string') {
19
+ if (input.match(jsonRegex)) {
20
+ // optimization for use try-catch only after regex match. much faster than without regex
21
+ try {
22
+ return JSON.parse(input);
23
+ } catch {
24
+ /* empty */
25
+ }
26
+ }
27
+ if (input.match(booleanRegex)) {
28
+ return !!input.match(trueRegex);
29
+ }
30
+ return input.trim();
31
+ } else if (typeof input === 'number') {
32
+ return input;
33
+ }
34
+ };
35
+
36
+ export function CSV2Records(
37
+ csv: string,
38
+ useRowAsHead = 0,
39
+ strDelimiter?: string,
40
+ ): any {
41
+ const arr = CSV2Array(csv, strDelimiter);
42
+ const total = arr.length;
43
+ const keys = arr[useRowAsHead].map(toHead);
44
+ const data: any[] = [];
45
+
46
+ let tmpSKU = 0;
47
+
48
+ for (let i = useRowAsHead + 1; i < total; i++) {
49
+ const obj = zipObject(keys, arr[i].map(toCorrectString));
50
+ data.push(obj);
51
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
52
+ tmpSKU++;
53
+ }
54
+
55
+ return data.filter(Boolean);
56
+ }
@@ -0,0 +1,21 @@
1
+ export function ObjectToCSV<T extends object>(records: T[]) {
2
+ if (records.length === 0) {
3
+ return;
4
+ }
5
+
6
+ const uniqueFields = Array.from(
7
+ records.reduce((fields, record) => {
8
+ Object.keys(record).forEach((field: string) => fields.add(field));
9
+ return fields;
10
+ }, new Set<string>()),
11
+ );
12
+
13
+ const csvHeader = uniqueFields.join(',') + '\n';
14
+ const csvRows = records
15
+ .map((record: any) =>
16
+ uniqueFields.map((field: any) => `"${record[field] || ''}"`).join(','),
17
+ )
18
+ .join('\n');
19
+
20
+ return csvHeader + csvRows;
21
+ }
@@ -0,0 +1 @@
1
+ export const isLocalhost = !!window.location.href.match(/localhost/gi);