@etsoo/shared 1.2.51 → 1.2.54
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/.github/workflows/main.yml +6 -5
- package/README.md +1 -1
- package/lib/cjs/ActionResult.d.ts +1 -1
- package/lib/cjs/ActionResult.js +3 -3
- package/lib/cjs/ArrayUtils.d.ts +1 -1
- package/lib/cjs/ArrayUtils.js +4 -4
- package/lib/cjs/ColorUtils.d.ts +1 -1
- package/lib/cjs/ColorUtils.js +2 -2
- package/lib/cjs/DataTypes.d.ts +6 -6
- package/lib/cjs/DataTypes.js +50 -51
- package/lib/cjs/DateUtils.d.ts +1 -1
- package/lib/cjs/DateUtils.js +27 -28
- package/lib/cjs/DomUtils.d.ts +3 -3
- package/lib/cjs/DomUtils.js +64 -73
- package/lib/cjs/ExtendUtils.d.ts +1 -1
- package/lib/cjs/ExtendUtils.js +6 -6
- package/lib/cjs/IActionResult.d.ts +15 -2
- package/lib/cjs/NumberUtils.d.ts +1 -1
- package/lib/cjs/NumberUtils.js +9 -9
- package/lib/cjs/StorageUtils.js +2 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/cjs/Utils.js +58 -62
- package/lib/cjs/index.d.ts +22 -22
- package/lib/cjs/storage/WindowStorage.d.ts +1 -1
- package/lib/cjs/types/ContentDisposition.d.ts +2 -2
- package/lib/cjs/types/ContentDisposition.js +11 -13
- package/lib/cjs/types/EColor.js +5 -7
- package/lib/cjs/types/EHistory.d.ts +3 -3
- package/lib/cjs/types/EHistory.js +4 -4
- package/lib/cjs/types/ErrorData.d.ts +1 -1
- package/lib/cjs/types/EventClass.js +1 -1
- package/lib/mjs/ActionResult.d.ts +1 -1
- package/lib/mjs/ActionResult.js +3 -3
- package/lib/mjs/ArrayUtils.d.ts +1 -1
- package/lib/mjs/ArrayUtils.js +5 -5
- package/lib/mjs/ColorUtils.d.ts +1 -1
- package/lib/mjs/ColorUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +6 -6
- package/lib/mjs/DataTypes.js +50 -51
- package/lib/mjs/DateUtils.d.ts +1 -1
- package/lib/mjs/DateUtils.js +27 -28
- package/lib/mjs/DomUtils.d.ts +3 -3
- package/lib/mjs/DomUtils.js +67 -76
- package/lib/mjs/ExtendUtils.d.ts +1 -1
- package/lib/mjs/ExtendUtils.js +6 -6
- package/lib/mjs/IActionResult.d.ts +15 -2
- package/lib/mjs/NumberUtils.d.ts +1 -1
- package/lib/mjs/NumberUtils.js +9 -9
- package/lib/mjs/StorageUtils.js +4 -4
- package/lib/mjs/Utils.d.ts +4 -4
- package/lib/mjs/Utils.js +61 -65
- package/lib/mjs/index.d.ts +22 -22
- package/lib/mjs/index.js +22 -22
- package/lib/mjs/storage/WindowStorage.d.ts +1 -1
- package/lib/mjs/storage/WindowStorage.js +2 -2
- package/lib/mjs/types/ContentDisposition.d.ts +2 -2
- package/lib/mjs/types/ContentDisposition.js +12 -14
- package/lib/mjs/types/EColor.js +5 -7
- package/lib/mjs/types/EHistory.d.ts +3 -3
- package/lib/mjs/types/EHistory.js +5 -5
- package/lib/mjs/types/ErrorData.d.ts +1 -1
- package/lib/mjs/types/EventClass.js +1 -1
- package/package.json +61 -63
- package/src/ActionResult.ts +23 -23
- package/src/ArrayUtils.ts +164 -172
- package/src/ColorUtils.ts +80 -82
- package/src/DataTypes.ts +745 -754
- package/src/DateUtils.ts +266 -268
- package/src/DomUtils.ts +806 -831
- package/src/ExtendUtils.ts +191 -191
- package/src/IActionResult.ts +55 -40
- package/src/Keyboard.ts +258 -258
- package/src/NumberUtils.ts +135 -135
- package/src/StorageUtils.ts +117 -117
- package/src/Utils.ts +908 -930
- package/src/index.ts +22 -22
- package/src/node/Storage.ts +53 -53
- package/src/storage/IStorage.ts +62 -62
- package/src/storage/WindowStorage.ts +140 -140
- package/src/types/ContentDisposition.ts +59 -63
- package/src/types/DataError.ts +15 -15
- package/src/types/DelayedExecutorType.ts +15 -15
- package/src/types/EColor.ts +241 -248
- package/src/types/EHistory.ts +151 -151
- package/src/types/ErrorData.ts +11 -11
- package/src/types/EventClass.ts +220 -220
- package/src/types/FormData.ts +25 -25
- package/src/types/ParsedPath.ts +5 -5
- package/tsconfig.cjs.json +16 -16
- package/tsconfig.json +16 -16
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/src/ColorUtils.ts
CHANGED
|
@@ -1,99 +1,97 @@
|
|
|
1
|
-
import { EColor } from
|
|
1
|
+
import { EColor } from "./types/EColor";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Color utils
|
|
5
5
|
*/
|
|
6
6
|
export namespace ColorUtils {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Get HEX or RGB colors
|
|
9
|
+
* @param init Initial color
|
|
10
|
+
* @param factor Increase factor
|
|
11
|
+
* @param adjustOrder Adjust order to increase difference
|
|
12
|
+
* @param hex to HEX or not
|
|
13
|
+
* @returns Result
|
|
14
|
+
*/
|
|
15
|
+
export function getColors(
|
|
16
|
+
init: string = "#000",
|
|
17
|
+
factor: number = 51,
|
|
18
|
+
adjustOrder: boolean = true,
|
|
19
|
+
hex: boolean = true
|
|
20
|
+
) {
|
|
21
|
+
return getEColors(init, factor, adjustOrder).map((c) =>
|
|
22
|
+
hex ? c.toHEXColor() : c.toRGBColor()
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Get EColors
|
|
28
|
+
* @param init Initial color
|
|
29
|
+
* @param factor Increase factor
|
|
30
|
+
* @param adjustOrder Adjust order to increase difference
|
|
31
|
+
* @returns Result
|
|
32
|
+
*/
|
|
33
|
+
export function getEColors(
|
|
34
|
+
init: string = "#000",
|
|
35
|
+
factor: number = 51,
|
|
36
|
+
adjustOrder: boolean = true
|
|
37
|
+
): EColor[] {
|
|
38
|
+
// Init color
|
|
39
|
+
const initColor = EColor.parse(init) ?? new EColor(0, 0, 0);
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
// Factors elements
|
|
42
|
+
// 51 = '00', '33', '66', '99', 'cc', 'ff'
|
|
43
|
+
const factors: number[] = [];
|
|
44
|
+
let f = 0;
|
|
45
|
+
while (f <= 255) {
|
|
46
|
+
factors.push(f);
|
|
47
|
+
f += factor;
|
|
48
|
+
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
50
|
+
// RGB loop
|
|
51
|
+
const colors: (EColor | undefined)[] = [initColor];
|
|
52
|
+
for (const r of factors) {
|
|
53
|
+
for (const g of factors) {
|
|
54
|
+
for (const b of factors) {
|
|
55
|
+
colors.push(initColor.clone(r, g, b));
|
|
58
56
|
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(color): color is EColor => color != null
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// Adjust order
|
|
66
|
-
if (adjustOrder) {
|
|
67
|
-
const firstColor = nColors.shift();
|
|
68
|
-
if (firstColor) {
|
|
69
|
-
let color = firstColor;
|
|
70
|
-
const newColors: EColor[] = [color];
|
|
60
|
+
// Non-nullable colors
|
|
61
|
+
const nColors = colors.filter((color): color is EColor => color != null);
|
|
71
62
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
p.color = c;
|
|
79
|
-
p.index = index;
|
|
80
|
-
}
|
|
81
|
-
return p;
|
|
82
|
-
},
|
|
83
|
-
{ delta: 0, color, index: -1 }
|
|
84
|
-
);
|
|
63
|
+
// Adjust order
|
|
64
|
+
if (adjustOrder) {
|
|
65
|
+
const firstColor = nColors.shift();
|
|
66
|
+
if (firstColor) {
|
|
67
|
+
let color = firstColor;
|
|
68
|
+
const newColors: EColor[] = [color];
|
|
85
69
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
70
|
+
while (nColors.length > 0) {
|
|
71
|
+
const result = nColors.reduce(
|
|
72
|
+
(p, c, index) => {
|
|
73
|
+
const delta = color.getDeltaValue(c);
|
|
74
|
+
if (delta != null && delta > p.delta) {
|
|
75
|
+
p.delta = delta;
|
|
76
|
+
p.color = c;
|
|
77
|
+
p.index = index;
|
|
78
|
+
}
|
|
79
|
+
return p;
|
|
80
|
+
},
|
|
81
|
+
{ delta: 0, color, index: -1 }
|
|
82
|
+
);
|
|
92
83
|
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
if (result.delta > 0) {
|
|
85
|
+
color = result.color;
|
|
86
|
+
newColors.push(color);
|
|
87
|
+
nColors.splice(result.index, 1);
|
|
88
|
+
}
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
return
|
|
91
|
+
return newColors;
|
|
92
|
+
}
|
|
98
93
|
}
|
|
94
|
+
|
|
95
|
+
return nColors;
|
|
96
|
+
}
|
|
99
97
|
}
|