@carlsebastian/jsu 1.0.34

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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/package.json +58 -0
  3. package/src/global.js +7 -0
  4. package/src/types/api/api.d.ts +147 -0
  5. package/src/types/api/element.d.ts +55 -0
  6. package/src/types/custom/custom.d.ts +8 -0
  7. package/src/types/custom/error/builder/error.builder.d.ts +78 -0
  8. package/src/types/custom/error/constructor/error.base.d.ts +4 -0
  9. package/src/types/custom/error/constructor/error.custom.d.ts +34 -0
  10. package/src/types/custom/error/constructor/error.meta.d.ts +18 -0
  11. package/src/types/custom/error/error.d.ts +5 -0
  12. package/src/types/custom/utils/custom.utils.d.ts +42 -0
  13. package/src/types/custom/utils/generator/generator.d.ts +92 -0
  14. package/src/types/dom/attr/attr.class.d.ts +81 -0
  15. package/src/types/dom/attr/attr.id.d.ts +23 -0
  16. package/src/types/dom/attr/attr.style.d.ts +32 -0
  17. package/src/types/dom/dom.d.ts +8 -0
  18. package/src/types/dom/element/create/element.create.d.ts +67 -0
  19. package/src/types/dom/element/getElementBy/dom.getElementBy.d.ts +71 -0
  20. package/src/types/dom/element/tag-verifier/verifier.d.ts +16 -0
  21. package/src/types/global.d.ts +13 -0
  22. package/src/types/guards/data-types/data-types.d.ts +5 -0
  23. package/src/types/guards/formats/formats.d.ts +5 -0
  24. package/src/types/guards/guards.d.ts +8 -0
  25. package/src/types/primitives/obj/obj.accessor.d.ts +5 -0
  26. package/src/types/primitives/obj/obj.iterator.d.ts +5 -0
  27. package/src/types/primitives/primitives.d.ts +8 -0
  28. package/src/types/primitives/str/str.d.ts +26 -0
  29. package/src/types/storage/local/storage.local.d.ts +86 -0
  30. package/src/types/storage/session/storage.session.d.ts +86 -0
  31. package/src/types/storage/storage.d.ts +8 -0
  32. package/src/utils/custom/custom.js +20 -0
  33. package/src/utils/custom/error/builder/error.builder.js +181 -0
  34. package/src/utils/custom/error/constructor/error.base.js +71 -0
  35. package/src/utils/custom/error/constructor/error.custom.js +107 -0
  36. package/src/utils/custom/error/error.js +23 -0
  37. package/src/utils/custom/utils/custom.utils.js +150 -0
  38. package/src/utils/custom/utils/generator/generator.js +222 -0
  39. package/src/utils/dom/attr/attr.class.js +186 -0
  40. package/src/utils/dom/attr/attr.id.js +64 -0
  41. package/src/utils/dom/attr/attr.style.js +128 -0
  42. package/src/utils/dom/dom.js +29 -0
  43. package/src/utils/dom/element/create/element.create.js +312 -0
  44. package/src/utils/dom/element/getElementBy/dom.getElementBy.js +171 -0
  45. package/src/utils/dom/element/query/dom.query.js +75 -0
  46. package/src/utils/dom/element/tag-verifier/verifier.js +60 -0
  47. package/src/utils/dom/lifecycle/mount.js +48 -0
  48. package/src/utils/dom/lifecycle/unmount.js +43 -0
  49. package/src/utils/guards/data-types/data-types.js +201 -0
  50. package/src/utils/guards/formats/formats.js +274 -0
  51. package/src/utils/guards/guards.js +21 -0
  52. package/src/utils/primitives/obj/obj.accessor.js +242 -0
  53. package/src/utils/primitives/obj/obj.iterator.js +148 -0
  54. package/src/utils/primitives/primitives.js +23 -0
  55. package/src/utils/primitives/str/str.js +52 -0
  56. package/src/utils/storage/local/storage.local.js +236 -0
  57. package/src/utils/storage/session/storage.session.js +236 -0
  58. package/src/utils/storage/storage.js +59 -0
  59. package/src/utils/variables.js +78 -0
@@ -0,0 +1,222 @@
1
+ import { IsPlainObjEmpty } from '../../../guards/formats/formats.js';
2
+ import { IsBool, IsNum, IsPlainObj } from '../../../guards/data-types/data-types.js';
3
+ import { CountOf, KeysOf } from '../../../primitives/obj/obj.accessor.js';
4
+ import { EachOf, MapOf } from '../../../primitives/obj/obj.iterator.js';
5
+ import Str from '../../../primitives/str/str.js';
6
+ import Emit from '../../error/builder/error.builder.js';
7
+ import { Clamp } from '../custom.utils.js';
8
+
9
+ /**
10
+ * A collection of generators module.
11
+ */
12
+ export default class Generator {
13
+ /**
14
+ * The `size` of generators in this `@class` to be used.
15
+ */
16
+ Size = 0;
17
+
18
+ /**
19
+ * A configuration that allows you to customize the generators contents.
20
+ */
21
+ Conf = {
22
+ /**
23
+ * @type { boolean } - Includes or excludes numerical characters (0-9) from generator's contents.
24
+ */
25
+ numbers: true,
26
+
27
+ /**
28
+ * @type { boolean } - Includes or excludes symbol characters (!@#...) from generator's contents.
29
+ */
30
+ symbols: true,
31
+
32
+ /**
33
+ * @type { boolean } - Includes or excludes lowercase characters (a-z) from generator's contents.
34
+ */
35
+ lowercase: true,
36
+
37
+ /**
38
+ * @type { boolean } - Includes or excludes uppercase characters (A-Z) from generator's contents.
39
+ */
40
+ uppercase: true,
41
+
42
+ /**
43
+ * @type { boolean } - Whether to change its entropy from `Math.random()` into `window.crypto`.
44
+ *
45
+ * ***Notes***:
46
+ * - When entropy set to `window.crypto` it makes the generator of integer more secure but with some
47
+ * performance cost. While `Math.random()` does no reduce performance but procures a non-secure random integer value.
48
+ */
49
+ secure: false,
50
+ };
51
+
52
+ /**
53
+ * Construct the specified size and configuration to use throughout the generators.
54
+ *
55
+ * ***Notes***:
56
+ * - If the specified `size` is less than 1, it will be automatically set by the generators requirement.
57
+ * - If `size` is below 0, it will be automatically converted into its absolute value.
58
+ * - The maximum `size` of generator(s) are 25, it will be automatically clamped if its above the maximum.
59
+ * - The generators in this class is not for security related use, as its uses `Math.random()` as its entropy.
60
+ *
61
+ * @param { number } [Size] - The `size` of contents to generate. {Default: Generator-Specified}
62
+ * @param {{ numbers?: boolean, symbols?: boolean, lowercase?: boolean, uppercase?: boolean, secure?: boolean }} [Conf] - A configuration for security and customization of the generator's contents.
63
+ */
64
+ constructor(Size = this.Size, Conf = this.Conf) {
65
+ Size = Math.abs(parseInt(Size));
66
+ const CONFKeys = ["numbers", "symbols", "lowercase", "uppercase", "secure"];
67
+
68
+ if (!IsNum(Size))
69
+ Emit._ArgumentError(this.constructor.name, "Size", Size, "Number");
70
+
71
+ if (!IsPlainObj(Conf))
72
+ Emit._ArgumentError(this.constructor.name, "Conf", Conf, "Plain Object");
73
+
74
+ if (IsPlainObjEmpty(Conf))
75
+ Conf = { numbers: true, symbols: true, lowercase: true, uppercase: true, secure: false };
76
+
77
+ Conf = CONFKeys.reduce((Acc, Key) => {
78
+ const Keys = KeysOf(Conf);
79
+
80
+ const Pos = MapOf(Keys, K => K.toLowerCase()).indexOf(Key);
81
+ if (Pos < 0 || !IsBool(Conf[Keys[Pos]]))
82
+ Acc[Key] = Key === "secure" ? false : true;
83
+ else
84
+ Acc[Key] = Conf[Keys[Pos]];
85
+
86
+ return Acc;
87
+ }, {});
88
+
89
+ this.Conf = Conf;
90
+ this.Size = Size;
91
+ Object.defineProperties(this, {
92
+ Max: {
93
+ value: 25,
94
+ writable: false, configurable: false, enumerable: false
95
+ },
96
+ Chars: {
97
+ value: MapOf(KeysOf(Str.Chars), K => Str.Chars[K]()),
98
+ writable: false, configurable: false, enumerable: false
99
+ }
100
+ });
101
+ }
102
+
103
+ /**
104
+ * Generate a randomized integer value within the specified `maximum` value.
105
+ *
106
+ * ***Notes***:
107
+ * - If `max` is below zero (0), it will be automatically converted into its absolute value.
108
+ * - When `max` is zero, the generator would add a 1 to `max` value. (E.g. max = 0 -> max = 0 + 1)
109
+ *
110
+ * @overload
111
+ * @param { number } [max] - The specified maximum value of integer to generate. (Default: 10)
112
+ * @returns { number } Returns a randomized integer within the specified range.
113
+ */
114
+ /**
115
+ * Generate a randomized integer value within the specified `minimum` and `maximum` range.
116
+ *
117
+ * ***Notes***:
118
+ * - If `min` and/or `max` are below zero (0), it will automatically converted into their absolute value.
119
+ * - When `min` is greater than `max`, their value will be switched. (min -> max, max -> min)
120
+ * - If `min` and `max` are the same, the generator would add a 1 to `max` value. (E.g. min & max = 10, max + 1);
121
+ *
122
+ * @overload
123
+ * @param { number } [min] - The specified minimum value of integer to generate. (Default: 0)
124
+ * @param { number } [max] - The specified maximum value of integer to generate. (Default: 1)
125
+ * @returns { number } Returns a randomized integer within the specified range.
126
+ */
127
+ RandomInteger(min = 0, max = 1) {
128
+ const Method = "RandomInteger";
129
+ let Range = MapOf([min, max], Val => Math.abs(parseInt(Val, 10)));
130
+
131
+ EachOf(Range, (R, Pos) => {
132
+ if (!IsNum(R))
133
+ Emit._ArgumentError(Method, ["min", "max"][Pos], R, "Number");
134
+ });
135
+
136
+ if (Range[0] > Range[1])
137
+ [Range[0], Range[1]] = [Range[1], Range[0]];
138
+
139
+ if (Range[0] === Range[1])
140
+ Range[1]++;
141
+
142
+ const R = (Range[1] - Range[0]) + 1;
143
+ if (this.Conf.secure) {
144
+ // console.log(`--[GENERATING IN ${this.Conf.secure ? "SECURE-MODE" : "NON-SECURE-MODE"}]--`);
145
+ const Arr = new Uint32Array(1); // 32-bit
146
+ const MaxUInt = 0xFFFFFFFF; // 32-bit
147
+ crypto.getRandomValues(Arr);
148
+ return Range[0] + Math.floor((Arr[0] / (MaxUInt + 1)) * R);
149
+ }
150
+
151
+ return Math.floor(Math.random() * (Range[1] - Range[0] + 1) + Range[0]);
152
+ }
153
+
154
+ /**
155
+ * Generates a set of randomized characters (numeric & symbol characters are not included) within the specified `size`.
156
+ *
157
+ * ***Notes***:
158
+ * - If `size` is below 6 or higher than 25, it will be automatically clamped between this value.
159
+ * - If both of configuration `lowercase` and `uppercase` as set to false, the generated will use `uppercase` as default.
160
+ *
161
+ * @returns { string } The generated random characters.
162
+ */
163
+ RandomCharacters() {
164
+ const Method = "RandomCharacters", CONFKeys = ["lowercase", "uppercase"];
165
+ let [Size, Conf] = [
166
+ Clamp(this.Size, 6, this.Max),
167
+ { lowercase: this.Conf.lowercase, uppercase: this.Conf.uppercase }
168
+ ];
169
+
170
+ const Map = Conf.lowercase ? Conf.uppercase ? (this.Chars[CountOf(this.Chars) - 1] + this.Chars[0]) : this.Chars[0] : this.Chars[CountOf(this.Chars) - 1];
171
+
172
+ return Array.from({ length: Size }, (_, I) => {
173
+ return Map[this.RandomInteger(Map.length - 1)];
174
+ }).join("");
175
+ }
176
+
177
+ /**
178
+ * Generates a randomized token string that can be used as temporary id, lobby, etc., and returns it.
179
+ *
180
+ * ***Notes***:
181
+ * - If `size` is below 7 or higher than 25, it will be automatically clamped between this value.
182
+ * - If both of configuration `lowercase` and `uppercase` as set to false, the generated will use `uppercase` as default.
183
+ *
184
+ * @returns { string } The generated token.
185
+ */
186
+ NewToken() {
187
+ const Method = "NewToken";
188
+ let [Size, Conf] = [Clamp(this.Size, 7, this.Max), this.Conf], Token = "";
189
+ const CharsOnly = (Conf.lowercase || Conf.uppercase) && (!Conf.numbers && !Conf.symbols);
190
+ const Chars = Conf.uppercase ? Conf.lowercase ? (this.Chars[CountOf(this.Chars) - 1] + this.Chars[0]) : this.Chars[CountOf(this.Chars) - 1] : this.Chars[0];
191
+ const Map = Chars + (Conf.numbers ? Conf.symbols ? (this.Chars[1] + this.Chars[2]) : this.Chars[1] : this.Chars[2]);
192
+
193
+ for (let I = 0; I < Size; I++) {
194
+ if (CharsOnly) {
195
+ Token += Chars[this.RandomInteger(Chars.length - 1)];
196
+ continue;
197
+ }
198
+
199
+ if (/([A-Za-z]{6,})$/.test(Token)) {
200
+ const NS = (Conf.numbers ? this.Chars[1] : "") + (Conf.symbols ? this.Chars[2] : "");
201
+ Token += NS[this.RandomInteger(NS.length - 1)];
202
+ continue;
203
+ }
204
+
205
+ if (Conf.symbols && /([^A-Za-z\d]{3,})$/.test(Token)) {
206
+ const CN = Chars + (Conf.numbers ? this.Chars[1] : "");
207
+ Token += CN[this.RandomInteger(CN.length - 1)];
208
+ continue;
209
+ }
210
+
211
+ if (Conf.numbers && /\d{2,}$/.test(Token)) {
212
+ const CS = Chars + (Conf.symbols ? this.Chars[2] : "");
213
+ Token += CS[this.RandomInteger(CS.length - 1)];
214
+ continue;
215
+ }
216
+
217
+ Token += Map[this.RandomInteger(Map.length - 1)];
218
+ }
219
+
220
+ return Token;
221
+ }
222
+ }
@@ -0,0 +1,186 @@
1
+ import Emit from '../../custom/error/builder/error.builder.js';
2
+ import { IsStrEmpty } from '../../guards/formats/formats.js';
3
+ import { IsArr, IsElement, IsStr } from '../../guards/data-types/data-types.js';
4
+ import { CountOf } from '../../primitives/obj/obj.accessor.js';
5
+
6
+ /**
7
+ * Access the `DOMTokenList` ('class') attribute of the specified target element.
8
+ *
9
+ * @param { Element } element - The target element.
10
+ * @returns The response object methods for mutating class of element.
11
+ *
12
+ * @throws {ArgumentError} - When there's no element provided or an invalid element provided.
13
+ * @throws {NotSupportedError} - When the provided element does not support 'classList' property.
14
+ */
15
+ export default function ClassOf(element) {
16
+ const Method = "ClassOf";
17
+
18
+ if (!IsElement(element))
19
+ Emit._ArgumentError(Method, "element", element, "Element");
20
+
21
+ if (!("classList" in element))
22
+ Emit._NotSupportedError(Method, "classList");
23
+
24
+ const ClassList = element.classList;
25
+ return {
26
+ /**
27
+ * Checks if the specified `class` token is existing at the element's `DOMTokenList`.
28
+ *
29
+ * @overload
30
+ * @param { string } token - The token to check.
31
+ * @returns { boolean } The response state result of validation.
32
+ */
33
+ /**
34
+ * Checks if the specified collection of `class` tokens are existing at the element's `DOMTokenList`.
35
+ *
36
+ * @overload
37
+ * @param { string[] } tokens - The collection of tokens to check.
38
+ * @returns { boolean } The response state result of validation.
39
+ */
40
+ Has(...tokens) {
41
+ const Caller = `${Method}.Has`, ICtr = CountOf(tokens);
42
+
43
+ if (ICtr === 0)
44
+ return false;
45
+
46
+ if (ICtr === 1)
47
+ return IsStr(tokens[0]) && !IsStrEmpty(tokens[0]) && ClassList.contains(tokens[0]);
48
+
49
+ return tokens.every(token =>
50
+ IsStr(token) && !IsStrEmpty(token) && ClassList.contains(token)
51
+ );
52
+ },
53
+
54
+ /**
55
+ * Retrieve and returns the collection of element's `DOMTokenList`.
56
+ *
57
+ * @returns { DOMTokenList } The response object result of retrieval.
58
+ */
59
+ List() {
60
+ return ClassList;
61
+ },
62
+
63
+ /**
64
+ * Removes the specified `class` token from the element's `DOMTokenList`.
65
+ *
66
+ * @overload
67
+ * @param { string } token - The token to remove.
68
+ * @returns { boolean } The response state result of token removal.
69
+ */
70
+ /**
71
+ * Removes the specified collection of `class` tokens from the element's `DOMTokenList`.
72
+ *
73
+ * @overload
74
+ * @param { string[] } tokens - The collection of tokens to remove.
75
+ * @returns { boolean } The response state result of tokens removal.
76
+ */
77
+ Remove(...tokens) {
78
+ const Caller = `${Method}.Remove`, ICtr = CountOf(tokens);
79
+
80
+ if (ICtr === 0)
81
+ return false;
82
+
83
+ for (const token of tokens) {
84
+ if (!IsStr(token)) {
85
+ console.warn(`${Caller}(@${ICtr > 1 ? "tokens" : "token"}: ${ICtr > 1 ? `[${token}]` : token}): Expected to be in string format! (Skipped)`);
86
+ continue;
87
+ }
88
+
89
+ if (IsStrEmpty(token))
90
+ continue;
91
+
92
+ ClassList.remove(token);
93
+ }
94
+
95
+ return true;
96
+ },
97
+
98
+ /**
99
+ * Set (or update) the specified `class` token from the element's `DOMTokenList`.
100
+ *
101
+ * @overload
102
+ * @param { string } token - The token to set (or update).
103
+ * @returns { void }
104
+ */
105
+ /**
106
+ * Set (or update) the specified collection of `class` tokens from the element's `DOMTokenList`.
107
+ *
108
+ * @overload
109
+ * @param { string[] } tokens - The collection of tokens to set (or update).
110
+ * @returns { void }
111
+ */
112
+ Set(...tokens) {
113
+ const Caller = `${Method}.Set`, ICtr = CountOf(tokens);
114
+
115
+ if (ICtr === 0)
116
+ return;
117
+
118
+ for (const token of tokens.flat(Infinity)) {
119
+ if (!IsStr(token)) {
120
+ console.warn(`${Caller}(@${ICtr > 1 ? "tokens" : "token"}: ${ICtr > 1 ? `[${token}]` : token}): Expected to be in string format! (Skipped)`);
121
+ continue;
122
+ }
123
+
124
+ if (IsStrEmpty(token))
125
+ continue;
126
+
127
+ ClassList.add(token);
128
+ }
129
+ },
130
+
131
+ /**
132
+ * Toggles the state of the specified `class` token from the element's `DOMTokenList`.
133
+ *
134
+ * ***States***:
135
+ * - If the specified token is not currently existing in the element's `DOMTokenList`,
136
+ * it will be added automatically to the element's `DOMTokenList`, or else, if present, it will be removed
137
+ * from the element's `DOMTokenList`.
138
+ *
139
+ * @overload
140
+ * @param { string } token - The token to toggle.
141
+ * @param { boolean } [forceState] - A state to set forcefully from the token despite its current state.
142
+ * @returns { boolean } The response state result of toggled state.
143
+ */
144
+ /**
145
+ * Toggles the state of the specified collection of `class` tokens from the element's `DOMTokenList`.
146
+ *
147
+ * ***States***
148
+ * - If a certain token from the collection of tokens is not currently existing in the element's `DOMTokenList`,
149
+ * it will be added automatically to the element's `DOMTokenList`, or else, if present, it will be removed
150
+ * from the element's `DOMTokenList`.
151
+ *
152
+ * @overload
153
+ * @param { string[] } tokens - The collection of tokens to toggle.
154
+ * @param { boolean } [forceState] - A state to set forcefully from the token despite its current state.
155
+ * @returns { boolean } The response state result of toggled states.
156
+ */
157
+ Toggle(tokens, forceState) {
158
+ const Caller = `${Method}.Toggle`;
159
+
160
+ if (!IsArr(tokens))
161
+ tokens = [tokens];
162
+
163
+ const ICtr = CountOf(tokens);
164
+ if (ICtr === 0)
165
+ return false;
166
+
167
+ if (forceState && typeof forceState !== "boolean")
168
+ Emit._ArgumentError(Caller, "forceState", forceState, "Boolean");
169
+
170
+ const Response = [];
171
+ for (const token of tokens) {
172
+ if (!IsStr(token)) {
173
+ console.warn(`${Caller}(@${ICtr > 1 ? "tokens" : "token"}: ${ICtr > 1 ? `[${token}]` : token}): Expected to be in string format! (Skipped)`);
174
+ continue;
175
+ }
176
+
177
+ if (IsStrEmpty(token))
178
+ continue;
179
+
180
+ Response.push(forceState ? ClassList.toggle(token, forceState) : ClassList.toggle(token));
181
+ }
182
+
183
+ return CountOf(Response) > 1 ? Response : Response[0];
184
+ },
185
+ }
186
+ }
@@ -0,0 +1,64 @@
1
+ import Emit from '../../custom/error/builder/error.builder.js';
2
+ import { IsStrEmpty } from '../../guards/formats/formats.js';
3
+ import { IsElement, IsNullOrUndefined, IsStr } from '../../guards/data-types/data-types.js';
4
+
5
+ /**
6
+ * Access the `id` attribute of element and returns a set of methods for it.
7
+ *
8
+ * @param { Element } element - The element to access the `id` attribute.
9
+ * @returns The set of methods for `id` attribute.
10
+ */
11
+ export default function IdOf(element) {
12
+ const Method = "IdOf";
13
+
14
+ if (!IsElement(element))
15
+ Emit._ArgumentError(Method, "element", element, "Element");
16
+
17
+ return {
18
+ /**
19
+ * The current unique `id` of element.
20
+ *
21
+ * ***Note***:
22
+ * - If the element has no `id`, the default value would be '\<NO_ID\>'.
23
+ */
24
+ Value: IsStrEmpty(element.id) || IsNullOrUndefined(element.id) ? "\<NO_ID\>" : element.id,
25
+
26
+ /**
27
+ * Removes the `id` of the element.
28
+ *
29
+ * @returns { boolean } The response state result of removal `id` process.
30
+ */
31
+ Remove() {
32
+ if (!element.hasAttribute("id")) {
33
+ console.warn(`${Method}.Remove(@element): Does not currently have an id! (Exited)`);
34
+ return false;
35
+ }
36
+
37
+ element.removeAttribute("id");
38
+ this.Value = "<NO_ID>";
39
+ return true;
40
+ },
41
+
42
+ /**
43
+ * Set the current unique `id` of the element.
44
+ *
45
+ * @param id - The new unique `id` to set.
46
+ * @returns { string } The new current unique `id` of element.
47
+ */
48
+ Set(id = "") {
49
+ const Caller = `${Method}.Set`;
50
+
51
+ if (!IsStr(id))
52
+ Emit._ArgumentError(Caller, "id", id, "String");
53
+
54
+ if (IsStrEmpty(id)) {
55
+ element.removeAttribute("id");
56
+ this.Value = "<NO_ID>";
57
+ return "<NO_ID>";
58
+ }
59
+
60
+ element.setAttribute("id", id);
61
+ this.Value = id;
62
+ },
63
+ }
64
+ }
@@ -0,0 +1,128 @@
1
+ import Emit from '../../custom/error/builder/error.builder.js';
2
+ import { IsPlainObjEmpty, IsStrEmpty } from '../../guards/formats/formats.js';
3
+ import { IsArr, IsElement, IsPlainObj, IsStr } from '../../guards/data-types/data-types.js';
4
+ import { CountOf } from '../../primitives/obj/obj.accessor.js';
5
+
6
+ /**
7
+ * Access the element's style object and returns a collection object methods for it.
8
+ *
9
+ * @param { Element } element - The target element.
10
+ * @returns The response object method for mutating style of element.
11
+ */
12
+ export default function StyleOf(element) {
13
+ const Method = "StyleOf";
14
+
15
+ if (!IsElement(element))
16
+ Emit._ArgumentError(Method, "element", element, "Element");
17
+
18
+ if (!("style" in element))
19
+ Emit._NotSupportedError(Method, "style");
20
+
21
+ /** @type { CSSStyleDeclaration } */
22
+ const StyleObj = element.style;
23
+ return {
24
+ /**
25
+ * Set and apply the CSSStyle object properties from the target element.
26
+ *
27
+ * @param { CSSStyleDeclaration } CSSObj - The CSSStyle object properties.
28
+ * @returns { void }
29
+ */
30
+ Set(CSSObj = {}) {
31
+ const Caller = `${Method}.Set`;
32
+
33
+ if (!IsPlainObj(CSSObj))
34
+ Emit._ArgumentError(Caller, "CSSObj", CSSObj, "Plain Object ({})");
35
+
36
+ if (IsPlainObjEmpty(CSSObj))
37
+ return;
38
+
39
+ for (const [SK, SV] of Object.entries(CSSObj)) {
40
+ if (!(SK in StyleObj)) {
41
+ console.warn(`${Caller}(@CSSObj: { ${SK}: ... }): Unknown CSS property! (Skipped)`);
42
+ continue;
43
+ }
44
+
45
+ if (!IsStr(SV)) {
46
+ console.warn(`${Caller}(@CSSObj: { ${SK}: ${SV} }): Expects a string format value! (Skipped)`);
47
+ continue;
48
+ }
49
+
50
+ if (IsStrEmpty(SV)) {
51
+ console.warn(`${Caller}(@CSSObj: { ${SK}: "" }): Expects a value! (Skipped)`);
52
+ continue;
53
+ }
54
+
55
+ StyleObj[SK] = SV;
56
+ }
57
+ },
58
+
59
+ /**
60
+ * Removes the specified CSS property from the target element.
61
+ *
62
+ * @overload
63
+ * @param { keyof CSSStyleDeclaration } CSSProperty - The CSS property to remove.
64
+ * @returns { boolean }
65
+ */
66
+ /**
67
+ * Removes the specified CSS properties from the target element.
68
+ *
69
+ * @overload
70
+ * @param { Array<keyof CSSStyleDeclaration> } CSSProperties - The CSS properties to remove.
71
+ * @returns { boolean }
72
+ */
73
+ Remove(...CSSProperties) {
74
+ const Caller = `${Method}.Remove`, ICtr = CountOf(CSSProperties), P = ICtr > 1 ? "CSSProperties" : "CSSProperty";
75
+
76
+ if (ICtr === 0)
77
+ return false;
78
+
79
+ for (const SK of CSSProperties) {
80
+ const PV = ICtr > 1 ? `[${SK}]` : `: ${SK}`
81
+ if (!IsStr(SK)) {
82
+ console.warn(`${Caller}(@${P}${PV}): Expects a CSS property to be in string format! (Skipped)`);
83
+ continue;
84
+ }
85
+
86
+ if (IsStrEmpty(SK)) {
87
+ console.warn(`${Caller}(@${P}${PV}): Expects a non-empty value! (Skipped)`);
88
+ continue;
89
+ }
90
+
91
+ if (!(SK in StyleObj)) {
92
+ console.warn(`${Method}(@${P}${PV}): Unknown CSS Property! (Skipped)`);
93
+ continue;
94
+ }
95
+
96
+ StyleObj.removeProperty(SK);
97
+ }
98
+
99
+ return true;
100
+ },
101
+
102
+ /**
103
+ * Returns the current value of the specified CSSStyle property.
104
+ *
105
+ * @param { keyof CSSStyleDeclaration } CSSProperty - The CSS property to retrieve.
106
+ * @returns { string | null }
107
+ */
108
+ Get(CSSProperty) {
109
+ const Caller = `${Method}.Get`;
110
+ if (!IsStr(CSSProperty))
111
+ Emit._ArgumentError(Caller, "CSSProperty", CSSProperty, "String");
112
+
113
+ if (IsStrEmpty(CSSProperty)) {
114
+ console.warn(`${Caller}(@CSSProperty: ${CSSProperty}): Expects a non-empty string key value! (Exited with null)`);
115
+ return null;
116
+ }
117
+
118
+ if (!(CSSProperty in StyleObj)) {
119
+ console.warn(`${Caller}(@CSSProperty: ${CSSProperty}): Unknown CSS property! (Exited with null)`);
120
+ return null;
121
+ }
122
+
123
+ const Value = StyleObj[CSSProperty];
124
+
125
+ return IsStrEmpty(Value) ? "<NO_DATA>" : Value;
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,29 @@
1
+ import { DefineProperty, Global, NameOf } from '../custom/utils/custom.utils.js';
2
+ import ClassOf from './attr/attr.class.js';
3
+ import StyleOf from './attr/attr.style.js';
4
+ import Create from './element/create/element.create.js';
5
+ import VerifyTag from './element/tag-verifier/verifier.js';
6
+ import Mount from './lifecycle/mount.js';
7
+ import Unmount from './lifecycle/unmount.js';
8
+ import { Select, SelectAll } from "./element/query/dom.query.js";
9
+ import GetElementBy from "./element/getElementBy/dom.getElementBy.js";
10
+ import { IsNullOrUndefined, IsPropertyAt } from '../guards/data-types/data-types.js';
11
+ import { IsStrEmpty } from '../guards/formats/formats.js';
12
+
13
+ /**
14
+ * A customized or enhanced collection of `DOM` methods.
15
+ */
16
+ export default function DOM() {
17
+ const DomAPI = {};
18
+
19
+ for (const Method of [ClassOf, Create, GetElementBy, Mount, Unmount, Select, SelectAll, StyleOf, VerifyTag]) {
20
+ const Key = NameOf(Method);
21
+
22
+ if (!IsNullOrUndefined(Key) && !IsStrEmpty(Key) && !IsPropertyAt(DomAPI, Key) && !(Key === "(ANONYMOUS)"))
23
+ DefineProperty(DomAPI, Key, Method, "med");
24
+ }
25
+
26
+ Global("DOM", DomAPI, "soft");
27
+ }
28
+
29
+ DOM();