@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.
Files changed (94) hide show
  1. package/.github/workflows/main.yml +6 -5
  2. package/README.md +1 -1
  3. package/lib/cjs/ActionResult.d.ts +1 -1
  4. package/lib/cjs/ActionResult.js +3 -3
  5. package/lib/cjs/ArrayUtils.d.ts +1 -1
  6. package/lib/cjs/ArrayUtils.js +4 -4
  7. package/lib/cjs/ColorUtils.d.ts +1 -1
  8. package/lib/cjs/ColorUtils.js +2 -2
  9. package/lib/cjs/DataTypes.d.ts +6 -6
  10. package/lib/cjs/DataTypes.js +50 -51
  11. package/lib/cjs/DateUtils.d.ts +1 -1
  12. package/lib/cjs/DateUtils.js +27 -28
  13. package/lib/cjs/DomUtils.d.ts +3 -3
  14. package/lib/cjs/DomUtils.js +64 -73
  15. package/lib/cjs/ExtendUtils.d.ts +1 -1
  16. package/lib/cjs/ExtendUtils.js +6 -6
  17. package/lib/cjs/IActionResult.d.ts +15 -2
  18. package/lib/cjs/NumberUtils.d.ts +1 -1
  19. package/lib/cjs/NumberUtils.js +9 -9
  20. package/lib/cjs/StorageUtils.js +2 -2
  21. package/lib/cjs/Utils.d.ts +4 -4
  22. package/lib/cjs/Utils.js +58 -62
  23. package/lib/cjs/index.d.ts +22 -22
  24. package/lib/cjs/storage/WindowStorage.d.ts +1 -1
  25. package/lib/cjs/types/ContentDisposition.d.ts +2 -2
  26. package/lib/cjs/types/ContentDisposition.js +11 -13
  27. package/lib/cjs/types/EColor.js +5 -7
  28. package/lib/cjs/types/EHistory.d.ts +3 -3
  29. package/lib/cjs/types/EHistory.js +4 -4
  30. package/lib/cjs/types/ErrorData.d.ts +1 -1
  31. package/lib/cjs/types/EventClass.js +1 -1
  32. package/lib/mjs/ActionResult.d.ts +1 -1
  33. package/lib/mjs/ActionResult.js +3 -3
  34. package/lib/mjs/ArrayUtils.d.ts +1 -1
  35. package/lib/mjs/ArrayUtils.js +5 -5
  36. package/lib/mjs/ColorUtils.d.ts +1 -1
  37. package/lib/mjs/ColorUtils.js +3 -3
  38. package/lib/mjs/DataTypes.d.ts +6 -6
  39. package/lib/mjs/DataTypes.js +50 -51
  40. package/lib/mjs/DateUtils.d.ts +1 -1
  41. package/lib/mjs/DateUtils.js +27 -28
  42. package/lib/mjs/DomUtils.d.ts +3 -3
  43. package/lib/mjs/DomUtils.js +67 -76
  44. package/lib/mjs/ExtendUtils.d.ts +1 -1
  45. package/lib/mjs/ExtendUtils.js +6 -6
  46. package/lib/mjs/IActionResult.d.ts +15 -2
  47. package/lib/mjs/NumberUtils.d.ts +1 -1
  48. package/lib/mjs/NumberUtils.js +9 -9
  49. package/lib/mjs/StorageUtils.js +4 -4
  50. package/lib/mjs/Utils.d.ts +4 -4
  51. package/lib/mjs/Utils.js +61 -65
  52. package/lib/mjs/index.d.ts +22 -22
  53. package/lib/mjs/index.js +22 -22
  54. package/lib/mjs/storage/WindowStorage.d.ts +1 -1
  55. package/lib/mjs/storage/WindowStorage.js +2 -2
  56. package/lib/mjs/types/ContentDisposition.d.ts +2 -2
  57. package/lib/mjs/types/ContentDisposition.js +12 -14
  58. package/lib/mjs/types/EColor.js +5 -7
  59. package/lib/mjs/types/EHistory.d.ts +3 -3
  60. package/lib/mjs/types/EHistory.js +5 -5
  61. package/lib/mjs/types/ErrorData.d.ts +1 -1
  62. package/lib/mjs/types/EventClass.js +1 -1
  63. package/package.json +61 -63
  64. package/src/ActionResult.ts +23 -23
  65. package/src/ArrayUtils.ts +164 -172
  66. package/src/ColorUtils.ts +80 -82
  67. package/src/DataTypes.ts +745 -754
  68. package/src/DateUtils.ts +266 -268
  69. package/src/DomUtils.ts +806 -831
  70. package/src/ExtendUtils.ts +191 -191
  71. package/src/IActionResult.ts +55 -40
  72. package/src/Keyboard.ts +258 -258
  73. package/src/NumberUtils.ts +135 -135
  74. package/src/StorageUtils.ts +117 -117
  75. package/src/Utils.ts +908 -930
  76. package/src/index.ts +22 -22
  77. package/src/node/Storage.ts +53 -53
  78. package/src/storage/IStorage.ts +62 -62
  79. package/src/storage/WindowStorage.ts +140 -140
  80. package/src/types/ContentDisposition.ts +59 -63
  81. package/src/types/DataError.ts +15 -15
  82. package/src/types/DelayedExecutorType.ts +15 -15
  83. package/src/types/EColor.ts +241 -248
  84. package/src/types/EHistory.ts +151 -151
  85. package/src/types/ErrorData.ts +11 -11
  86. package/src/types/EventClass.ts +220 -220
  87. package/src/types/FormData.ts +25 -25
  88. package/src/types/ParsedPath.ts +5 -5
  89. package/tsconfig.cjs.json +16 -16
  90. package/tsconfig.json +16 -16
  91. package/.eslintignore +0 -3
  92. package/.eslintrc.json +0 -29
  93. package/.prettierignore +0 -5
  94. package/.prettierrc +0 -6
@@ -1,185 +1,185 @@
1
- import { EventBase, EventClass } from './EventClass';
1
+ import { EventBase, EventClass } from "./EventClass";
2
2
 
3
3
  interface EHistoryEventData {
4
- /**
5
- * Current index
6
- */
7
- index: number;
4
+ /**
5
+ * Current index
6
+ */
7
+ index: number;
8
8
  }
9
9
 
10
10
  interface EHistoryNavigateEventData extends EHistoryEventData {
11
- /**
12
- * Delta
13
- */
14
- delta: number;
11
+ /**
12
+ * Delta
13
+ */
14
+ delta: number;
15
15
  }
16
16
 
17
17
  type EHistoryEventDef = {
18
- clear: EHistoryEventData;
19
- navigate: EHistoryNavigateEventData;
20
- push: EHistoryEventData;
21
- replace: EHistoryEventData;
18
+ clear: EHistoryEventData;
19
+ navigate: EHistoryNavigateEventData;
20
+ push: EHistoryEventData;
21
+ replace: EHistoryEventData;
22
22
  };
23
23
 
24
- type EHistoryEventType = Exclude<keyof EHistoryEventDef, 'navigate'>;
24
+ type EHistoryEventType = Exclude<keyof EHistoryEventDef, "navigate">;
25
25
 
26
26
  /**
27
27
  * ETSOO Extended history event
28
28
  */
29
29
  export class EHistoryEvent extends EventBase<
30
- EHistoryEventType,
31
- EHistoryEventData
30
+ EHistoryEventType,
31
+ EHistoryEventData
32
32
  > {}
33
33
 
34
34
  /**
35
35
  * ETSOO Extended history navigate event
36
36
  */
37
37
  export class EHistoryNavigateEvent extends EventBase<
38
- 'navigate',
39
- EHistoryNavigateEventData
38
+ "navigate",
39
+ EHistoryNavigateEventData
40
40
  > {
41
- constructor(target: {}, data: EHistoryNavigateEventData) {
42
- super(target, 'navigate', data);
43
- }
41
+ constructor(target: {}, data: EHistoryNavigateEventData) {
42
+ super(target, "navigate", data);
43
+ }
44
44
  }
45
45
 
46
46
  /**
47
47
  * ETSOO Extended abstract history class
48
48
  */
49
49
  export abstract class EHistory<T> extends EventClass<EHistoryEventDef> {
50
- // Index
51
- private _index: number = -1;
52
-
53
- /**
54
- * States
55
- */
56
- readonly states: T[] = [];
57
-
58
- /**
59
- * States length
60
- */
61
- get length() {
62
- return this.states.length;
63
- }
64
-
65
- /**
66
- * Get current state index
67
- */
68
- get index() {
69
- return this._index;
70
- }
71
-
72
- /**
73
- * Get current state
74
- */
75
- get state() {
76
- if (this._index === -1) return undefined;
77
- return this.states[this._index];
78
- }
79
-
80
- /**
81
- * Constructor
82
- * @param maxDepth Max depth of the history
83
- */
84
- constructor(public readonly maxDepth: number = 20) {
85
- super();
86
- }
87
-
88
- /**
89
- * Back to the previous state
90
- */
91
- back() {
92
- this.go(-1);
93
- }
94
-
95
- /**
96
- * Clear all states but keep event listeners
97
- */
98
- clear() {
99
- // https://stackoverflow.com/questions/1232040/how-do-i-empty-an-array-in-javascript
100
- this.states.length = 0;
101
- this._index = -1;
102
- this.trigger(this.createEvent('clear', this._index));
103
- }
104
-
105
- /**
106
- * Create event
107
- * @param type Type
108
- * @param index Current index
109
- */
110
- protected createEvent<T extends EHistoryEventType>(type: T, index: number) {
111
- return new EHistoryEvent(this, type, { index });
112
- }
113
-
114
- protected createNavigateEvent(index: number, delta: number) {
115
- return new EHistoryNavigateEvent(this, { index, delta });
116
- }
117
-
118
- /**
119
- * Forward to the next state
120
- */
121
- forward() {
122
- this.go(1);
123
- }
124
-
125
- /**
126
- * Get [undo, redo] status
127
- */
128
- getStatus(): [boolean, boolean] {
129
- if (this.length < 2) return [false, false];
130
- if (this._index <= 0) return [false, true];
131
- if (this._index + 1 >= this.length) return [true, false];
132
- return [true, true];
133
- }
134
-
135
- /**
136
- * Go to the specific state
137
- * @param delta A negative value moves backwards, a positive value moves forwards
138
- */
139
- go(delta: number) {
140
- // No data
141
- if (this._index === -1) return undefined;
142
-
143
- // New index
144
- const newIndex = this._index + delta;
145
-
146
- // Not in the range
147
- if (newIndex < 0 || newIndex >= this.length) return undefined;
148
-
149
- // Update the index
150
- this._index = newIndex;
151
-
152
- // Trigger event
153
- this.trigger(this.createNavigateEvent(newIndex, delta));
50
+ // Index
51
+ private _index: number = -1;
52
+
53
+ /**
54
+ * States
55
+ */
56
+ readonly states: T[] = [];
57
+
58
+ /**
59
+ * States length
60
+ */
61
+ get length() {
62
+ return this.states.length;
63
+ }
64
+
65
+ /**
66
+ * Get current state index
67
+ */
68
+ get index() {
69
+ return this._index;
70
+ }
71
+
72
+ /**
73
+ * Get current state
74
+ */
75
+ get state() {
76
+ if (this._index === -1) return undefined;
77
+ return this.states[this._index];
78
+ }
79
+
80
+ /**
81
+ * Constructor
82
+ * @param maxDepth Max depth of the history
83
+ */
84
+ constructor(public readonly maxDepth: number = 20) {
85
+ super();
86
+ }
87
+
88
+ /**
89
+ * Back to the previous state
90
+ */
91
+ back() {
92
+ this.go(-1);
93
+ }
94
+
95
+ /**
96
+ * Clear all states but keep event listeners
97
+ */
98
+ clear() {
99
+ // https://stackoverflow.com/questions/1232040/how-do-i-empty-an-array-in-javascript
100
+ this.states.length = 0;
101
+ this._index = -1;
102
+ this.trigger(this.createEvent("clear", this._index));
103
+ }
104
+
105
+ /**
106
+ * Create event
107
+ * @param type Type
108
+ * @param index Current index
109
+ */
110
+ protected createEvent<T extends EHistoryEventType>(type: T, index: number) {
111
+ return new EHistoryEvent(this, type, { index });
112
+ }
113
+
114
+ protected createNavigateEvent(index: number, delta: number) {
115
+ return new EHistoryNavigateEvent(this, { index, delta });
116
+ }
117
+
118
+ /**
119
+ * Forward to the next state
120
+ */
121
+ forward() {
122
+ this.go(1);
123
+ }
124
+
125
+ /**
126
+ * Get [undo, redo] status
127
+ */
128
+ getStatus(): [boolean, boolean] {
129
+ if (this.length < 2) return [false, false];
130
+ if (this._index <= 0) return [false, true];
131
+ if (this._index + 1 >= this.length) return [true, false];
132
+ return [true, true];
133
+ }
134
+
135
+ /**
136
+ * Go to the specific state
137
+ * @param delta A negative value moves backwards, a positive value moves forwards
138
+ */
139
+ go(delta: number) {
140
+ // No data
141
+ if (this._index === -1) return undefined;
142
+
143
+ // New index
144
+ const newIndex = this._index + delta;
145
+
146
+ // Not in the range
147
+ if (newIndex < 0 || newIndex >= this.length) return undefined;
148
+
149
+ // Update the index
150
+ this._index = newIndex;
151
+
152
+ // Trigger event
153
+ this.trigger(this.createNavigateEvent(newIndex, delta));
154
+ }
155
+
156
+ /**
157
+ * Adds an entry to the history stack
158
+ * @param state State
159
+ */
160
+ pushState(state: T) {
161
+ if (this._index >= 0) {
162
+ // Remove states after the index
163
+ this.states.splice(this._index + 1);
154
164
  }
155
165
 
156
- /**
157
- * Adds an entry to the history stack
158
- * @param state State
159
- */
160
- pushState(state: T) {
161
- if (this._index >= 0) {
162
- // Remove states after the index
163
- this.states.splice(this._index + 1);
164
- }
166
+ this.states.push(state);
167
+ this._index++;
165
168
 
166
- this.states.push(state);
167
- this._index++;
168
-
169
- if (this.length > this.maxDepth) {
170
- this.states.shift();
171
- }
172
-
173
- this.trigger(this.createEvent('push', this._index));
169
+ if (this.length > this.maxDepth) {
170
+ this.states.shift();
174
171
  }
175
172
 
176
- /**
177
- * Modifies the current history entry
178
- * @param state State
179
- */
180
- replaceState(state: T) {
181
- if (this._index === -1) return;
182
- this.states[this._index] = state;
183
- this.trigger(this.createEvent('replace', this._index));
184
- }
173
+ this.trigger(this.createEvent("push", this._index));
174
+ }
175
+
176
+ /**
177
+ * Modifies the current history entry
178
+ * @param state State
179
+ */
180
+ replaceState(state: T) {
181
+ if (this._index === -1) return;
182
+ this.states[this._index] = state;
183
+ this.trigger(this.createEvent("replace", this._index));
184
+ }
185
185
  }
@@ -1,15 +1,15 @@
1
1
  export type ErrorType =
2
- | 'error'
3
- | 'unhandledrejection'
4
- | 'consoleWarn'
5
- | 'consoleError';
2
+ | "error"
3
+ | "unhandledrejection"
4
+ | "consoleWarn"
5
+ | "consoleError";
6
6
 
7
7
  export type ErrorData = {
8
- type: ErrorType;
9
- subType?: string;
10
- message: string;
11
- source?: string;
12
- lineNo?: number;
13
- colNo?: number;
14
- stack?: string;
8
+ type: ErrorType;
9
+ subType?: string;
10
+ message: string;
11
+ source?: string;
12
+ lineNo?: number;
13
+ colNo?: number;
14
+ stack?: string;
15
15
  };