aprog 2.2.3 → 2.2.4

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/src/general.js CHANGED
@@ -1,1458 +1,1489 @@
1
1
  export const pause = (variable) => {
2
- if (isNumber(variable)) {
3
- return new Promise(resolve => setTimeout(resolve, variable));
4
- } else {
5
- return new Promise(resolve => {
6
- const checkVariable = () => {
7
- if (variable()) {
8
- resolve();
9
- } else {
10
- setTimeout(checkVariable, 100);
11
- }
12
- };
13
- checkVariable();
14
- });
15
- }
2
+ if (isNumber(variable)) {
3
+ return new Promise(resolve => setTimeout(resolve, variable));
4
+ } else {
5
+ return new Promise(resolve => {
6
+ const checkVariable = () => {
7
+ if (variable()) {
8
+ resolve();
9
+ } else {
10
+ setTimeout(checkVariable, 100);
11
+ }
12
+ };
13
+ checkVariable();
14
+ });
15
+ }
16
16
  };
17
17
 
18
18
  export const date = (format, timestamp = Date.now()) => {
19
- const date = new Date(timestamp);
19
+ const date = new Date(timestamp);
20
20
 
21
- const map = {
22
- Y: date.getFullYear(),
23
- m: String(date.getMonth() + 1).padStart(2, '0'),
24
- d: String(date.getDate()).padStart(2, '0'),
25
- H: String(date.getHours()).padStart(2, '0'),
26
- i: String(date.getMinutes()).padStart(2, '0'),
27
- s: String(date.getSeconds()).padStart(2, '0')
28
- };
21
+ const map = {
22
+ Y: date.getFullYear(),
23
+ m: String(date.getMonth() + 1).padStart(2, '0'),
24
+ d: String(date.getDate()).padStart(2, '0'),
25
+ H: String(date.getHours()).padStart(2, '0'),
26
+ i: String(date.getMinutes()).padStart(2, '0'),
27
+ s: String(date.getSeconds()).padStart(2, '0')
28
+ };
29
29
 
30
- return format.replace(/[YmdHis]/g, match => map[match]);
30
+ return format.replace(/[YmdHis]/g, match => map[match]);
31
31
  };
32
32
 
33
33
  export const chars = (word) => {
34
- const cyrillicToLatin = {
35
- 'А': 'A', 'Б': 'B', 'В': 'V', 'Г': 'H', 'Д': 'D', 'Е': 'E', 'Є': 'Ye', 'Ж': 'Zh',
36
- 'З': 'Z', 'И': 'Y', 'І': 'I', 'Ї': 'Yi', 'Й': 'Y', 'К': 'K', 'Л': 'L', 'М': 'M',
37
- 'Н': 'N', 'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U', 'Ф': 'F',
38
- 'Х': 'Kh', 'Ц': 'Ts', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Shch', 'Ю': 'Yu', 'Я': 'Ya',
39
- 'а': 'a', 'б': 'b', 'в': 'v', 'г': 'h', 'д': 'd', 'е': 'e', 'є': 'ye', 'ж': 'zh',
40
- 'з': 'z', 'и': 'y', 'і': 'i', 'ї': 'yi', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm',
41
- 'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u', 'ф': 'f',
42
- 'х': 'kh', 'ц': 'ts', 'ч': 'ch', 'ш': 'sh', 'щ': 'shch', 'ю': 'yu', 'я': 'ya',
43
- 'Ь': '', 'ь': '', 'Ъ': '', 'ъ': '', 'Э': 'E', 'э': 'e', 'Ы': 'Y', 'ы': 'y'
44
- };
45
- return word.split('').map(char => cyrillicToLatin[char] || char).join('');
34
+ const cyrillicToLatin = {
35
+ 'А': 'A', 'Б': 'B', 'В': 'V', 'Г': 'H', 'Д': 'D', 'Е': 'E', 'Є': 'Ye', 'Ж': 'Zh',
36
+ 'З': 'Z', 'И': 'Y', 'І': 'I', 'Ї': 'Yi', 'Й': 'Y', 'К': 'K', 'Л': 'L', 'М': 'M',
37
+ 'Н': 'N', 'О': 'O', 'П': 'P', 'Р': 'R', 'С': 'S', 'Т': 'T', 'У': 'U', 'Ф': 'F',
38
+ 'Х': 'Kh', 'Ц': 'Ts', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Shch', 'Ю': 'Yu', 'Я': 'Ya',
39
+ 'а': 'a', 'б': 'b', 'в': 'v', 'г': 'h', 'д': 'd', 'е': 'e', 'є': 'ye', 'ж': 'zh',
40
+ 'з': 'z', 'и': 'y', 'і': 'i', 'ї': 'yi', 'й': 'y', 'к': 'k', 'л': 'l', 'м': 'm',
41
+ 'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u', 'ф': 'f',
42
+ 'х': 'kh', 'ц': 'ts', 'ч': 'ch', 'ш': 'sh', 'щ': 'shch', 'ю': 'yu', 'я': 'ya',
43
+ 'Ь': '', 'ь': '', 'Ъ': '', 'ъ': '', 'Э': 'E', 'э': 'e', 'Ы': 'Y', 'ы': 'y'
44
+ };
45
+ return word.split('').map(char => cyrillicToLatin[char] || char).join('');
46
46
  };
47
47
 
48
48
  // Validates
49
49
  export const isArray = (value) => {
50
- return Object.prototype.toString.call(value) === '[object Array]';
50
+ return Object.prototype.toString.call(value) === '[object Array]';
51
51
  };
52
52
 
53
53
  export const isObject = (value) => {
54
- return Object.prototype.toString.call(value) === '[object Object]';
54
+ return Object.prototype.toString.call(value) === '[object Object]';
55
55
  };
56
56
 
57
57
  export const isPromise = (value) => {
58
- return Object.prototype.toString.call(value) === '[object Promise]' ||
59
- (typeof value === 'object' && value !== null && typeof value.then === 'function' && typeof value.catch === 'function');
58
+ return Object.prototype.toString.call(value) === '[object Promise]' ||
59
+ (typeof value === 'object' && value !== null && typeof value.then === 'function' && typeof value.catch === 'function');
60
60
  };
61
61
 
62
62
  export const isNumber = (value) => {
63
- return typeof value === 'number' && !Number.isNaN(value);
63
+ return typeof value === 'number' && !Number.isNaN(value);
64
64
  };
65
65
 
66
66
  export const isNumeric = (value) => {
67
- return /^-?\d+(\.\d+)?$/.test(value);
67
+ return /^-?\d+(\.\d+)?$/.test(value);
68
68
  };
69
69
 
70
70
  export const isFloat = (value) => {
71
- return !isNaN(value) && Number(value) === value && !Number.isInteger(value);
71
+ return !isNaN(value) && Number(value) === value && !Number.isInteger(value);
72
72
  };
73
73
 
74
74
  export const isString = (value) => {
75
- return typeof value === 'string';
75
+ return typeof value === 'string';
76
76
  };
77
77
 
78
78
  export const isNull = (value) => {
79
- return value === null || value === undefined;
79
+ return value === null || value === undefined;
80
80
  };
81
81
 
82
82
  const isHtmlElement = (value) => {
83
- const htmlElements = [
84
- 'HTMLDivElement', "HTMLAnchorElement", 'HTMLSpanElement',
85
- 'HTMLButtonElement', 'HTMLSelectElement', "HTMLMainElement",
86
- 'HTMLInputElement', 'HTMLUlElement', "Promise",
87
- 'HTMLListElement', 'HTMLLabelElement', "HTMLTableCaptionElement",
88
- 'HTMLHRElement', 'SVGSVGElement', 'HTMLPreElement',
89
- 'Promise', "HTMLTextAreaElement", "HTMLTableElement",
90
- "HTMLTHeaderElement", "HTMLTBodyElement", "HTMLTRElement",
91
- "HTMLTHElement", "HTMLTDElement", "HTMLTableSectionElement",
92
- "HTMLTableRowElement", "HTMLTableCellElement", "HTMLImageElement",
93
- "HTMLSectionElement"
94
- ]
83
+ const htmlElements = [
84
+ 'HTMLDivElement', "HTMLAnchorElement", 'HTMLSpanElement',
85
+ 'HTMLButtonElement', 'HTMLSelectElement', "HTMLMainElement",
86
+ 'HTMLInputElement', 'HTMLUlElement', "Promise",
87
+ 'HTMLListElement', 'HTMLLabelElement', "HTMLTableCaptionElement",
88
+ 'HTMLHRElement', 'SVGSVGElement', 'HTMLPreElement',
89
+ 'Promise', "HTMLTextAreaElement", "HTMLTableElement",
90
+ "HTMLTHeaderElement", "HTMLTBodyElement", "HTMLTRElement",
91
+ "HTMLTHElement", "HTMLTDElement", "HTMLTableSectionElement",
92
+ "HTMLTableRowElement", "HTMLTableCellElement", "HTMLImageElement",
93
+ "HTMLSectionElement"
94
+ ]
95
95
 
96
- return htmlElements.some((element) => {
97
- return Object.prototype.toString.call(value) === `[object ${element}]`;
98
- });
96
+ return htmlElements.some((element) => {
97
+ return Object.prototype.toString.call(value) === `[object ${element}]`;
98
+ });
99
99
  };
100
100
 
101
101
  export const isEmpty = (variable) => {
102
- if (variable === undefined || variable === null) {
103
- return true;
104
- }
105
- if (typeof variable === 'string' && variable.trim() === '') {
106
- return true;
107
- }
108
- if (Array.isArray(variable) && variable.length === 0) {
109
- return true;
110
- }
111
- if (typeof variable === 'object' && !Array.isArray(variable) && Object.keys(variable).length === 0) {
112
- return true;
113
- }
114
- if (typeof variable === 'number' && variable === 0) {
115
- return false;
116
- }
117
- return !variable;
102
+ if (variable === undefined || variable === null) {
103
+ return true;
104
+ }
105
+ if (typeof variable === 'string' && variable.trim() === '') {
106
+ return true;
107
+ }
108
+ if (Array.isArray(variable) && variable.length === 0) {
109
+ return true;
110
+ }
111
+ if (typeof variable === 'object' && !Array.isArray(variable) && Object.keys(variable).length === 0) {
112
+ return true;
113
+ }
114
+ if (typeof variable === 'number' && variable === 0) {
115
+ return false;
116
+ }
117
+ return !variable;
118
118
  };
119
119
 
120
120
  export const elementToObject = (element) => {
121
- const obj = {};
122
- for (let attr of element.attributes) {
123
- obj[attr.name] = attr.value;
124
- }
125
- if (element.tagName.toLowerCase() === 'input') {
126
- obj['inputValue'] = element.value;
127
- } else if (element.tagName.toLowerCase() === 'select') {
128
- obj['selectValue'] = element.value;
129
- }
130
- return obj;
121
+ const obj = {};
122
+ for (let attr of element.attributes) {
123
+ obj[attr.name] = attr.value;
124
+ }
125
+ if (element.tagName.toLowerCase() === 'input') {
126
+ obj['inputValue'] = element.value;
127
+ } else if (element.tagName.toLowerCase() === 'select') {
128
+ obj['selectValue'] = element.value;
129
+ }
130
+ return obj;
131
131
  };
132
132
 
133
133
  export const nodeListToObject = (nodeList) => {
134
- return Array.from(nodeList).map((el, index) => ({
135
- ...(el.id && {id: el.id}),
136
- ...(el.classList && {classList: [...el.classList]}),
137
- ...(el.name && {name: el.name}),
138
- ...(el.tagName && {element: el.tagName.toLowerCase()}),
139
- ...(el.children && {children: [...nodeListToObject(el.children)]}),
140
- ...(el.attributes && {attributes: Array.from(el.attributes).reduce((acc, attr) => {
141
- acc[attr.name] = attr.value;
142
- return acc;
143
- }, {})}),
144
- ...(el.value && {value: el.value}),
145
- ...(el.innerText && {value: el.innerText}),
146
- index: index
147
- }));
134
+ return Array.from(nodeList).map((el, index) => ({
135
+ ...(el.id && {id: el.id}),
136
+ ...(el.classList && {classList: [...el.classList]}),
137
+ ...(el.name && {name: el.name}),
138
+ ...(el.tagName && {element: el.tagName.toLowerCase()}),
139
+ ...(el.children && {children: [...nodeListToObject(el.children)]}),
140
+ ...(el.attributes && {
141
+ attributes: Array.from(el.attributes).reduce((acc, attr) => {
142
+ acc[attr.name] = attr.value;
143
+ return acc;
144
+ }, {})
145
+ }),
146
+ ...(el.value && {value: el.value}),
147
+ ...(el.innerText && {value: el.innerText}),
148
+ index: index
149
+ }));
148
150
  };
149
151
 
150
152
  export const deepEqual = (obj1, obj2) => {
151
- if (obj1 === obj2) return true;
152
- if (obj1 == null || obj2 == null) return false;
153
- if (typeof obj1 !== 'object' || typeof obj2 !== 'object') return false;
154
- const keys1 = Object.keys(obj1);
155
- const keys2 = Object.keys(obj2);
156
- if (keys1.length !== keys2.length) return false;
157
- for (const key of keys1) {
158
- if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
159
- return false;
160
- }
153
+ if (obj1 === obj2) return true;
154
+ if (obj1 == null || obj2 == null) return false;
155
+ if (typeof obj1 !== 'object' || typeof obj2 !== 'object') return false;
156
+ const keys1 = Object.keys(obj1);
157
+ const keys2 = Object.keys(obj2);
158
+ if (keys1.length !== keys2.length) return false;
159
+ for (const key of keys1) {
160
+ if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
161
+ return false;
161
162
  }
162
- return true;
163
+ }
164
+ return true;
163
165
  };
164
166
 
165
167
  export const ucfirst = (str) => {
166
- if (!str) return str;
167
- return str.charAt(0).toUpperCase() + str.slice(1);
168
+ if (!str) return str;
169
+ return str.charAt(0).toUpperCase() + str.slice(1);
168
170
  };
169
171
 
170
172
  export const firstKey = (object) => {
171
- return Object.keys(object)[0] || null;
173
+ return Object.keys(object)[0] || null;
172
174
  };
173
175
 
174
176
  export const copyText = async (element) => {
175
- try {
176
- const textToCopy = isHtmlElement(element) ? JSON.stringify(JSON.parse(element.innerText)) : element;
177
- await navigator.clipboard.writeText(textToCopy);
178
- console.log("Скопійовано");
179
- } catch (err) {
180
- console.error('Помилка копіювання! Error:', err);
181
- }
177
+ try {
178
+ const textToCopy = isHtmlElement(element) ? JSON.stringify(JSON.parse(element.innerText)) : element;
179
+ await navigator.clipboard.writeText(textToCopy);
180
+ console.log("Скопійовано");
181
+ } catch (err) {
182
+ console.error('Помилка копіювання! Error:', err);
183
+ }
182
184
  };
183
185
 
184
186
  // HTML Elements
185
187
  export const options = (object, selected = null, disabled = null) => {
186
- if (isObject(object)) {
187
- return Object.entries(object).map(([key, value]) => {
188
- key = isNumeric(key) ? parseFloat(key) : key;
189
- return {
190
- value: key,
191
- name: value,
192
- selected: key === selected,
193
- disabled: key === disabled,
194
- };
195
- });
196
- } else {
197
- return object.map((value, index) => {
198
- if (isObject(value)) {
199
- return Object.entries(value).map(([key, value]) => {
200
- key = isNumeric(key) ? parseFloat(key) : key;
201
- return {
202
- value: key,
203
- name: value,
204
- selected: key === selected,
205
- disabled: key === disabled,
206
- };
207
- });
208
- } else {
209
- return {
210
- value: value,
211
- name: value,
212
- selected: value === selected,
213
- disabled: value === disabled,
214
- };
215
- }
188
+ if (isObject(object)) {
189
+ return Object.entries(object).map(([key, value]) => {
190
+ key = isNumeric(key) ? parseFloat(key) : key;
191
+ return {
192
+ value: key,
193
+ name: value,
194
+ selected: key === selected,
195
+ disabled: key === disabled,
196
+ };
197
+ });
198
+ } else {
199
+ return object.map((value, index) => {
200
+ if (isObject(value)) {
201
+ return Object.entries(value).map(([key, value]) => {
202
+ key = isNumeric(key) ? parseFloat(key) : key;
203
+ return {
204
+ value: key,
205
+ name: value,
206
+ selected: key === selected,
207
+ disabled: key === disabled,
208
+ };
216
209
  });
217
- }
210
+ } else {
211
+ return {
212
+ value: value,
213
+ name: value,
214
+ selected: value === selected,
215
+ disabled: value === disabled,
216
+ };
217
+ }
218
+ });
219
+ }
218
220
  };
219
221
 
220
222
  export const input = (attributes = {}) => {
221
- let input = document.createElement("input");
222
- if (attributes) {
223
- Object.entries(attributes).forEach(([name, attrValue]) => {
224
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
225
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
226
- input.addEventListener(eventType, attrValue);
223
+ let input = document.createElement("input");
224
+ if (attributes) {
225
+ Object.entries(attributes).forEach(([name, attrValue]) => {
226
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
227
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
228
+ input.addEventListener(eventType, attrValue);
229
+ } else {
230
+ switch (name) {
231
+ case "type":
232
+ input.type = String(attrValue);
233
+ break;
234
+ case "class":
235
+ case "className":
236
+ input.className = String(attrValue);
237
+ break;
238
+ case "style":
239
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
240
+ switch (styleName) {
241
+ case "zIndex":
242
+ input.style[styleName] = `99999${styleValue}`;
243
+ break;
244
+ default:
245
+ input.style[styleName] = styleValue;
246
+ break;
247
+ }
248
+ });
249
+ break;
250
+ case "disabled":
251
+ input.disabled = attrValue;
252
+ break;
253
+ case "autofocus":
254
+ case "focus":
255
+ input.focus();
256
+ break;
257
+ default:
258
+ if (name.startsWith("data")) {
259
+ const kebabName = name
260
+ .replace(/^data/, "data")
261
+ .replace(/([A-Z])/g, "-$1")
262
+ .toLowerCase();
263
+ input.setAttribute(kebabName, String(attrValue));
227
264
  } else {
228
- switch (name) {
229
- case "type":
230
- input.type = String(attrValue);
231
- break;
232
- case "class":
233
- case "className":
234
- input.className = String(attrValue);
235
- break;
236
- case "style":
237
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
238
- switch (styleName) {
239
- case "zIndex":
240
- input.style[styleName] = `99999${styleValue}`;
241
- break;
242
- default:
243
- input.style[styleName] = styleValue;
244
- break;
245
- }
246
- });
247
- break;
248
- case "disabled":
249
- input.disabled = attrValue;
250
- break;
251
- case "autofocus":
252
- case "focus":
253
- input.focus();
254
- break;
255
- default:
256
- if (name.startsWith("data")) {
257
- const kebabName = name
258
- .replace(/^data/, "data")
259
- .replace(/([A-Z])/g, "-$1")
260
- .toLowerCase();
261
- input.setAttribute(kebabName, String(attrValue));
262
- } else {
263
- input.setAttribute(name, String(attrValue));
264
- }
265
- }
265
+ input.setAttribute(name, String(attrValue));
266
266
  }
267
- });
268
- }
269
- return input;
267
+ }
268
+ }
269
+ });
270
+ }
271
+ return input;
270
272
  };
271
273
 
272
274
  export const label = (attributes = {}) => {
273
- let label = document.createElement("label");
274
- label.setAttribute("for", "...");
275
- if (attributes) {
276
- Object.entries(attributes).forEach(([name, attrValue]) => {
277
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
278
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
279
- label.addEventListener(eventType, attrValue);
275
+ let label = document.createElement("label");
276
+ label.setAttribute("for", "...");
277
+ if (attributes) {
278
+ Object.entries(attributes).forEach(([name, attrValue]) => {
279
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
280
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
281
+ label.addEventListener(eventType, attrValue);
282
+ } else {
283
+ switch (name) {
284
+ case "class":
285
+ case "className":
286
+ label.className = String(attrValue);
287
+ break;
288
+ case "value":
289
+ if (isArray(attrValue)) {
290
+ attrValue.forEach((element) => {
291
+ isHtmlElement(element) ? label.appendChild(element) : label.innerHTML = String(element);
292
+ });
280
293
  } else {
281
- switch (name) {
282
- case "class":
283
- case "className":
284
- label.className = String(attrValue);
285
- break;
286
- case "value":
287
- if (isArray(attrValue)) {
288
- attrValue.forEach((element) => {
289
- isHtmlElement(element) ? label.appendChild(element) : label.innerHTML = String(element);
290
- });
291
- } else {
292
- if (isHtmlElement(attrValue)) {
293
- label.appendChild(attrValue);
294
- } else {
295
- label.innerHTML = String(attrValue);
296
- label.title = String(attrValue);
297
- }
298
- }
299
- break;
300
- case "style":
301
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
302
- switch (styleName) {
303
- case "zIndex":
304
- label.style[styleName] = `99999${styleValue}`;
305
- break;
306
- default:
307
- label.style[styleName] = styleValue;
308
- break;
309
- }
310
- });
311
- break;
312
- default:
313
- if (name.startsWith("data")) {
314
- const kebabName = name
315
- .replace(/^data/, "data")
316
- .replace(/([A-Z])/g, "-$1")
317
- .toLowerCase();
318
- label.setAttribute(kebabName, String(attrValue));
319
- } else {
320
- label.setAttribute(name, String(attrValue));
321
- }
322
- }
294
+ if (isHtmlElement(attrValue)) {
295
+ label.appendChild(attrValue);
296
+ } else {
297
+ label.innerHTML = String(attrValue);
298
+ label.title = String(attrValue);
299
+ }
323
300
  }
324
- });
325
- }
326
- return label;
301
+ break;
302
+ case "style":
303
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
304
+ switch (styleName) {
305
+ case "zIndex":
306
+ label.style[styleName] = `99999${styleValue}`;
307
+ break;
308
+ default:
309
+ label.style[styleName] = styleValue;
310
+ break;
311
+ }
312
+ });
313
+ break;
314
+ default:
315
+ if (name.startsWith("data")) {
316
+ const kebabName = name
317
+ .replace(/^data/, "data")
318
+ .replace(/([A-Z])/g, "-$1")
319
+ .toLowerCase();
320
+ label.setAttribute(kebabName, String(attrValue));
321
+ } else {
322
+ label.setAttribute(name, String(attrValue));
323
+ }
324
+ }
325
+ }
326
+ });
327
+ }
328
+ return label;
327
329
  };
328
330
 
329
331
  export const form = (attributes = {}) => {
330
- let form = document.createElement("form");
331
- if (attributes) {
332
- Object.entries(attributes).forEach(([name, attrValue]) => {
333
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
334
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
335
- form.addEventListener(eventType, attrValue);
332
+ let form = document.createElement("form");
333
+ if (attributes) {
334
+ Object.entries(attributes).forEach(([name, attrValue]) => {
335
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
336
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
337
+ form.addEventListener(eventType, attrValue);
338
+ } else {
339
+ switch (name) {
340
+ case "class":
341
+ case "className":
342
+ form.className = String(attrValue);
343
+ break;
344
+ case "action":
345
+ form.action = String(attrValue);
346
+ break;
347
+ case "method":
348
+ form.method = String(attrValue);
349
+ break;
350
+ case "enctype":
351
+ form.enctype = String(attrValue);
352
+ break;
353
+ case "value":
354
+ if (isArray(attrValue)) {
355
+ attrValue.forEach((element) => {
356
+ isHtmlElement(element) ? form.append(element) : form.innerHTML = String(element);
357
+ });
336
358
  } else {
337
- switch (name) {
338
- case "class":
339
- case "className":
340
- form.className = String(attrValue);
341
- break;
342
- case "action":
343
- form.action = String(attrValue);
344
- break;
345
- case "method":
346
- form.method = String(attrValue);
347
- break;
348
- case "enctype":
349
- form.enctype = String(attrValue);
350
- break;
351
- case "value":
352
- if (isArray(attrValue)) {
353
- attrValue.forEach((element) => {
354
- isHtmlElement(element) ? form.append(element) : form.innerHTML = String(element);
355
- });
356
- } else {
357
- if (isHtmlElement(attrValue)) {
358
- form.appendChild(attrValue);
359
- } else {
360
- form.innerHTML = String(attrValue);
361
- form.title = String(attrValue);
362
- }
363
- }
364
- break;
365
- case "style":
366
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
367
- switch (styleName) {
368
- case "zIndex":
369
- form.style[styleName] = `99999${styleValue}`;
370
- break;
371
- default:
372
- form.style[styleName] = styleValue;
373
- break;
374
- }
375
- });
376
- break;
377
- default:
378
- if (name.startsWith("data")) {
379
- const kebabName = name
380
- .replace(/^data/, "data")
381
- .replace(/([A-Z])/g, "-$1")
382
- .toLowerCase();
383
- form.setAttribute(kebabName, String(attrValue));
384
- } else {
385
- form.setAttribute(name, String(attrValue));
386
- }
387
- }
359
+ if (isHtmlElement(attrValue)) {
360
+ form.appendChild(attrValue);
361
+ } else {
362
+ form.innerHTML = String(attrValue);
363
+ form.title = String(attrValue);
364
+ }
388
365
  }
389
- });
390
- }
391
- return form;
366
+ break;
367
+ case "style":
368
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
369
+ switch (styleName) {
370
+ case "zIndex":
371
+ form.style[styleName] = `99999${styleValue}`;
372
+ break;
373
+ default:
374
+ form.style[styleName] = styleValue;
375
+ break;
376
+ }
377
+ });
378
+ break;
379
+ default:
380
+ if (name.startsWith("data")) {
381
+ const kebabName = name
382
+ .replace(/^data/, "data")
383
+ .replace(/([A-Z])/g, "-$1")
384
+ .toLowerCase();
385
+ form.setAttribute(kebabName, String(attrValue));
386
+ } else {
387
+ form.setAttribute(name, String(attrValue));
388
+ }
389
+ }
390
+ }
391
+ });
392
+ }
393
+ return form;
392
394
  };
393
395
 
394
396
  export const div = (attributes = {}) => {
395
- let div = document.createElement("div");
396
- if (attributes) {
397
- Object.entries(attributes).forEach(([name, attrValue]) => {
398
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
399
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
400
- div.addEventListener(eventType, attrValue);
397
+ let div = document.createElement("div");
398
+ if (attributes) {
399
+ Object.entries(attributes).forEach(([name, attrValue]) => {
400
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
401
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
402
+ div.addEventListener(eventType, attrValue);
403
+ } else {
404
+ switch (name) {
405
+ case "class":
406
+ case "className":
407
+ div.className = String(attrValue);
408
+ break;
409
+ case "value":
410
+ if (isArray(attrValue)) {
411
+ attrValue.forEach((element) => {
412
+ isHtmlElement(element) ? div.append(element) : div.innerHTML = String(element);
413
+ });
401
414
  } else {
402
- switch (name) {
403
- case "class":
404
- case "className":
405
- div.className = String(attrValue);
406
- break;
407
- case "value":
408
- if (isArray(attrValue)) {
409
- attrValue.forEach((element) => {
410
- isHtmlElement(element) ? div.append(element) : div.innerHTML = String(element);
411
- });
412
- } else {
413
- if (isHtmlElement(attrValue)) {
414
- div.appendChild(attrValue);
415
- } else {
416
- div.innerHTML = String(attrValue);
417
- div.title = String(attrValue);
418
- }
419
- }
420
- break;
421
- case "style":
422
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
423
- switch (styleName) {
424
- case "zIndex":
425
- div.style[styleName] = `99999${styleValue}`;
426
- break;
427
- default:
428
- div.style[styleName] = styleValue;
429
- break;
430
- }
431
- });
432
- break;
433
- default:
434
- if (name.startsWith("data")) {
435
- const kebabName = name
436
- .replace(/^data/, "data")
437
- .replace(/([A-Z])/g, "-$1")
438
- .toLowerCase();
439
- div.setAttribute(kebabName, String(attrValue));
440
- } else {
441
- div.setAttribute(name, String(attrValue));
442
- }
443
- }
415
+ if (isHtmlElement(attrValue)) {
416
+ div.appendChild(attrValue);
417
+ } else {
418
+ div.innerHTML = String(attrValue);
419
+ div.title = String(attrValue);
420
+ }
444
421
  }
445
- });
446
- }
447
- return div;
422
+ break;
423
+ case "style":
424
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
425
+ switch (styleName) {
426
+ case "zIndex":
427
+ div.style[styleName] = `99999${styleValue}`;
428
+ break;
429
+ default:
430
+ div.style[styleName] = styleValue;
431
+ break;
432
+ }
433
+ });
434
+ break;
435
+ default:
436
+ if (name.startsWith("data")) {
437
+ const kebabName = name
438
+ .replace(/^data/, "data")
439
+ .replace(/([A-Z])/g, "-$1")
440
+ .toLowerCase();
441
+ div.setAttribute(kebabName, String(attrValue));
442
+ } else {
443
+ div.setAttribute(name, String(attrValue));
444
+ }
445
+ }
446
+ }
447
+ });
448
+ }
449
+ return div;
448
450
  };
449
451
 
450
452
  export const a = (attributes = {}) => {
451
- let a = document.createElement("a");
452
- if (attributes) {
453
- Object.entries(attributes).forEach(([name, attrValue]) => {
454
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
455
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
456
- a.addEventListener(eventType, attrValue);
453
+ let a = document.createElement("a");
454
+ if (attributes) {
455
+ Object.entries(attributes).forEach(([name, attrValue]) => {
456
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
457
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
458
+ a.addEventListener(eventType, attrValue);
459
+ } else {
460
+ switch (name) {
461
+ case "class":
462
+ case "className":
463
+ a.className = String(attrValue);
464
+ break;
465
+ case "value":
466
+ if (isArray(attrValue)) {
467
+ attrValue.forEach((element) => {
468
+ isHtmlElement(element) ? a.append(element) : a.innerHTML = String(element);
469
+ });
457
470
  } else {
458
- switch (name) {
459
- case "class":
460
- case "className":
461
- a.className = String(attrValue);
462
- break;
463
- case "value":
464
- if (isArray(attrValue)) {
465
- attrValue.forEach((element) => {
466
- isHtmlElement(element) ? a.append(element) : a.innerHTML = String(element);
467
- });
468
- } else {
469
- if (isHtmlElement(attrValue)) {
470
- a.appendChild(attrValue);
471
- } else {
472
- a.innerHTML = String(attrValue);
473
- a.title = String(attrValue);
474
- }
475
- }
476
- break;
477
- case "style":
478
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
479
- switch (styleName) {
480
- case "zIndex":
481
- a.style[styleName] = `99999${styleValue}`;
482
- break;
483
- default:
484
- a.style[styleName] = styleValue;
485
- break;
486
- }
487
- });
488
- break;
489
- default:
490
- if (name.startsWith("data")) {
491
- const kebabName = name
492
- .replace(/^data/, "data")
493
- .replace(/([A-Z])/g, "-$1")
494
- .toLowerCase();
495
- a.setAttribute(kebabName, String(attrValue));
496
- } else {
497
- a.setAttribute(name, String(attrValue));
498
- }
499
- }
471
+ if (isHtmlElement(attrValue)) {
472
+ a.appendChild(attrValue);
473
+ } else {
474
+ a.innerHTML = String(attrValue);
475
+ a.title = String(attrValue);
476
+ }
500
477
  }
501
- });
502
- }
503
- return a;
478
+ break;
479
+ case "style":
480
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
481
+ switch (styleName) {
482
+ case "zIndex":
483
+ a.style[styleName] = `99999${styleValue}`;
484
+ break;
485
+ default:
486
+ a.style[styleName] = styleValue;
487
+ break;
488
+ }
489
+ });
490
+ break;
491
+ default:
492
+ if (name.startsWith("data")) {
493
+ const kebabName = name
494
+ .replace(/^data/, "data")
495
+ .replace(/([A-Z])/g, "-$1")
496
+ .toLowerCase();
497
+ a.setAttribute(kebabName, String(attrValue));
498
+ } else {
499
+ a.setAttribute(name, String(attrValue));
500
+ }
501
+ }
502
+ }
503
+ });
504
+ }
505
+ return a;
504
506
  };
505
507
 
506
508
  export const span = (attributes = {}) => {
507
- let span = document.createElement("span");
508
- if (attributes) {
509
- Object.entries(attributes).forEach(([name, attrValue]) => {
510
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
511
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
512
- span.addEventListener(eventType, attrValue);
509
+ let span = document.createElement("span");
510
+ if (attributes) {
511
+ Object.entries(attributes).forEach(([name, attrValue]) => {
512
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
513
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
514
+ span.addEventListener(eventType, attrValue);
515
+ } else {
516
+ switch (name) {
517
+ case "class":
518
+ case "className":
519
+ span.className = String(attrValue);
520
+ break;
521
+ case "value":
522
+ if (isArray(attrValue)) {
523
+ attrValue.forEach((element) => {
524
+ isHtmlElement(element) ? span.append(element) : span.innerHTML = String(element);
525
+ });
513
526
  } else {
514
- switch (name) {
515
- case "class":
516
- case "className":
517
- span.className = String(attrValue);
518
- break;
519
- case "value":
520
- if (isArray(attrValue)) {
521
- attrValue.forEach((element) => {
522
- isHtmlElement(element) ? span.append(element) : span.innerHTML = String(element);
523
- });
524
- } else {
525
- if (isHtmlElement(attrValue)) {
526
- span.appendChild(attrValue);
527
- } else {
528
- span.innerHTML = String(attrValue);
529
- span.title = String(attrValue);
530
- }
531
- }
532
- break;
533
- case "style":
534
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
535
- switch (styleName) {
536
- case "zIndex":
537
- span.style[styleName] = `99999${styleValue}`;
538
- break;
539
- default:
540
- span.style[styleName] = styleValue;
541
- break;
542
- }
543
- });
544
- break;
545
- default:
546
- if (name.startsWith("data")) {
547
- const kebabName = name
548
- .replace(/^data/, "data")
549
- .replace(/([A-Z])/g, "-$1")
550
- .toLowerCase();
551
- span.setAttribute(kebabName, String(attrValue));
552
- } else {
553
- span.setAttribute(name, String(attrValue));
554
- }
555
- }
527
+ if (isHtmlElement(attrValue)) {
528
+ span.appendChild(attrValue);
529
+ } else {
530
+ span.innerHTML = String(attrValue);
531
+ span.title = String(attrValue);
532
+ }
556
533
  }
557
- });
558
- }
559
- return span;
534
+ break;
535
+ case "style":
536
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
537
+ switch (styleName) {
538
+ case "zIndex":
539
+ span.style[styleName] = `99999${styleValue}`;
540
+ break;
541
+ default:
542
+ span.style[styleName] = styleValue;
543
+ break;
544
+ }
545
+ });
546
+ break;
547
+ default:
548
+ if (name.startsWith("data")) {
549
+ const kebabName = name
550
+ .replace(/^data/, "data")
551
+ .replace(/([A-Z])/g, "-$1")
552
+ .toLowerCase();
553
+ span.setAttribute(kebabName, String(attrValue));
554
+ } else {
555
+ span.setAttribute(name, String(attrValue));
556
+ }
557
+ }
558
+ }
559
+ });
560
+ }
561
+ return span;
560
562
  };
561
563
 
562
564
  export const textarea = (attributes = {}) => {
563
- let textarea = document.createElement("textarea");
564
- if (attributes) {
565
- Object.entries(attributes).forEach(([name, attrValue]) => {
566
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
567
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
568
- textarea.addEventListener(eventType, attrValue);
565
+ let textarea = document.createElement("textarea");
566
+ if (attributes) {
567
+ Object.entries(attributes).forEach(([name, attrValue]) => {
568
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
569
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
570
+ textarea.addEventListener(eventType, attrValue);
571
+ } else {
572
+ switch (name) {
573
+ case "class":
574
+ case "className":
575
+ textarea.className = String(attrValue);
576
+ break;
577
+ case "value":
578
+ if (isArray(attrValue)) {
579
+ attrValue.forEach((element) => {
580
+ isHtmlElement(element) ? textarea.appendChild(element) : textarea.innerHTML = String(element);
581
+ });
569
582
  } else {
570
- switch (name) {
571
- case "class":
572
- case "className":
573
- textarea.className = String(attrValue);
574
- break;
575
- case "value":
576
- if (isArray(attrValue)) {
577
- attrValue.forEach((element) => {
578
- isHtmlElement(element) ? textarea.appendChild(element) : textarea.innerHTML = String(element);
579
- });
580
- } else {
581
- if (isHtmlElement(attrValue)) {
582
- textarea.appendChild(attrValue);
583
- } else {
584
- textarea.innerHTML = String(attrValue);
585
- textarea.title = String(attrValue);
586
- }
587
- }
588
- break;
589
- case "style":
590
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
591
- switch (styleName) {
592
- case "zIndex":
593
- textarea.style[styleName] = `99999${styleValue}`;
594
- break;
595
- default:
596
- textarea.style[styleName] = styleValue;
597
- break;
598
- }
599
- });
600
- break;
601
- default:
602
- if (name.startsWith("data")) {
603
- const kebabName = name
604
- .replace(/^data/, "data")
605
- .replace(/([A-Z])/g, "-$1")
606
- .toLowerCase();
607
- textarea.setAttribute(kebabName, String(attrValue));
608
- } else {
609
- textarea.setAttribute(name, String(attrValue));
610
- }
611
- }
583
+ if (isHtmlElement(attrValue)) {
584
+ textarea.appendChild(attrValue);
585
+ } else {
586
+ textarea.innerHTML = String(attrValue);
587
+ textarea.title = String(attrValue);
588
+ }
612
589
  }
613
- });
614
- }
615
- return textarea;
590
+ break;
591
+ case "style":
592
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
593
+ switch (styleName) {
594
+ case "zIndex":
595
+ textarea.style[styleName] = `99999${styleValue}`;
596
+ break;
597
+ default:
598
+ textarea.style[styleName] = styleValue;
599
+ break;
600
+ }
601
+ });
602
+ break;
603
+ default:
604
+ if (name.startsWith("data")) {
605
+ const kebabName = name
606
+ .replace(/^data/, "data")
607
+ .replace(/([A-Z])/g, "-$1")
608
+ .toLowerCase();
609
+ textarea.setAttribute(kebabName, String(attrValue));
610
+ } else {
611
+ textarea.setAttribute(name, String(attrValue));
612
+ }
613
+ }
614
+ }
615
+ });
616
+ }
617
+ return textarea;
616
618
  };
617
619
 
618
620
  export const pre = (attributes = {}) => {
619
- let pre = document.createElement("pre");
620
- if (attributes) {
621
- Object.entries(attributes).forEach(([name, attrValue]) => {
622
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
623
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
624
- pre.addEventListener(eventType, attrValue);
621
+ let pre = document.createElement("pre");
622
+ if (attributes) {
623
+ Object.entries(attributes).forEach(([name, attrValue]) => {
624
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
625
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
626
+ pre.addEventListener(eventType, attrValue);
627
+ } else {
628
+ switch (name) {
629
+ case "class":
630
+ case "className":
631
+ pre.className = String(attrValue);
632
+ break;
633
+ case "value":
634
+ if (isArray(attrValue)) {
635
+ attrValue.forEach((element) => {
636
+ isHtmlElement(element) ? pre.appendChild(element) : pre.innerHTML = String(element);
637
+ });
625
638
  } else {
626
- switch (name) {
627
- case "class":
628
- case "className":
629
- pre.className = String(attrValue);
630
- break;
631
- case "value":
632
- if (isArray(attrValue)) {
633
- attrValue.forEach((element) => {
634
- isHtmlElement(element) ? pre.appendChild(element) : pre.innerHTML = String(element);
635
- });
636
- } else {
637
- if (isHtmlElement(attrValue)) {
638
- pre.appendChild(attrValue);
639
- } else {
640
- pre.innerHTML = String(attrValue);
641
- pre.title = String(attrValue);
642
- }
643
- }
644
- break;
645
- case "style":
646
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
647
- switch (styleName) {
648
- case "zIndex":
649
- pre.style[styleName] = `99999${styleValue}`;
650
- break;
651
- default:
652
- pre.style[styleName] = styleValue;
653
- break;
654
- }
655
- });
656
- break;
657
- default:
658
- if (name.startsWith("data")) {
659
- const kebabName = name
660
- .replace(/^data/, "data")
661
- .replace(/([A-Z])/g, "-$1")
662
- .toLowerCase();
663
- pre.setAttribute(kebabName, String(attrValue));
664
- } else {
665
- pre.setAttribute(name, String(attrValue));
666
- }
667
- }
639
+ if (isHtmlElement(attrValue)) {
640
+ pre.appendChild(attrValue);
641
+ } else {
642
+ pre.innerHTML = String(attrValue);
643
+ pre.title = String(attrValue);
644
+ }
668
645
  }
669
- });
670
- }
671
- return pre;
646
+ break;
647
+ case "style":
648
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
649
+ switch (styleName) {
650
+ case "zIndex":
651
+ pre.style[styleName] = `99999${styleValue}`;
652
+ break;
653
+ default:
654
+ pre.style[styleName] = styleValue;
655
+ break;
656
+ }
657
+ });
658
+ break;
659
+ default:
660
+ if (name.startsWith("data")) {
661
+ const kebabName = name
662
+ .replace(/^data/, "data")
663
+ .replace(/([A-Z])/g, "-$1")
664
+ .toLowerCase();
665
+ pre.setAttribute(kebabName, String(attrValue));
666
+ } else {
667
+ pre.setAttribute(name, String(attrValue));
668
+ }
669
+ }
670
+ }
671
+ });
672
+ }
673
+ return pre;
672
674
  };
673
675
 
674
676
  export const button = (attributes = {}) => {
675
- let button = document.createElement("button");
676
- if (attributes) {
677
- Object.entries(attributes).forEach(([name, attrValue]) => {
678
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
679
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
680
- button.addEventListener(eventType, attrValue);
677
+ let button = document.createElement("button");
678
+ if (attributes) {
679
+ Object.entries(attributes).forEach(([name, attrValue]) => {
680
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
681
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
682
+ button.addEventListener(eventType, attrValue);
683
+ } else {
684
+ switch (name) {
685
+ case "class":
686
+ case "className":
687
+ button.className = String(attrValue);
688
+ break;
689
+ case "type":
690
+ button.type = String(attrValue);
691
+ break;
692
+ case "value":
693
+ button.innerHTML = String(attrValue);
694
+ button.title = String(attrValue);
695
+ break;
696
+ case "disabled":
697
+ button.disabled = attrValue;
698
+ break;
699
+ case "style":
700
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
701
+ switch (styleName) {
702
+ case "zIndex":
703
+ button.style[styleName] = `99999${styleValue}`;
704
+ break;
705
+ default:
706
+ button.style[styleName] = styleValue;
707
+ break;
708
+ }
709
+ });
710
+ break;
711
+ default:
712
+ if (name.startsWith("data")) {
713
+ const kebabName = name
714
+ .replace(/^data/, "data")
715
+ .replace(/([A-Z])/g, "-$1")
716
+ .toLowerCase();
717
+ button.setAttribute(kebabName, String(attrValue));
681
718
  } else {
682
- switch (name) {
683
- case "class":
684
- case "className":
685
- button.className = String(attrValue);
686
- break;
687
- case "type":
688
- button.type = String(attrValue);
689
- break;
690
- case "value":
691
- button.innerHTML = String(attrValue);
692
- button.title = String(attrValue);
693
- break;
694
- case "disabled":
695
- button.disabled = attrValue;
696
- break;
697
- case "style":
698
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
699
- switch (styleName) {
700
- case "zIndex":
701
- button.style[styleName] = `99999${styleValue}`;
702
- break;
703
- default:
704
- button.style[styleName] = styleValue;
705
- break;
706
- }
707
- });
708
- break;
709
- default:
710
- if (name.startsWith("data")) {
711
- const kebabName = name
712
- .replace(/^data/, "data")
713
- .replace(/([A-Z])/g, "-$1")
714
- .toLowerCase();
715
- button.setAttribute(kebabName, String(attrValue));
716
- } else {
717
- button.setAttribute(name, String(attrValue));
718
- }
719
- }
719
+ button.setAttribute(name, String(attrValue));
720
720
  }
721
- });
722
- }
723
- return button;
721
+ }
722
+ }
723
+ });
724
+ }
725
+ return button;
724
726
  };
725
727
 
726
728
  export const select = (attributes = {}) => {
727
- let select = document.createElement("select");
728
- let option = document.createElement("option");
729
- if (attributes) {
730
- Object.entries(attributes).forEach(([name, attrValue]) => {
731
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
732
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
733
- select.addEventListener(eventType, attrValue);
734
- } else {
735
- switch (name) {
736
- case "class":
737
- case "className":
738
- select.className = String(attrValue);
739
- break;
740
- case "style":
741
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
742
- switch (styleName) {
743
- case "zIndex":
744
- select.style[styleName] = `99999${styleValue}`;
745
- break;
746
- default:
747
- select.style[styleName] = styleValue;
748
- break;
749
- }
750
- });
751
- break;
752
- case "option":
753
- Object.entries(attrValue).forEach(([optionName, optionValue]) => {
754
- switch (optionName) {
755
- case "value":
756
- option.setAttribute('value', String(optionValue));
757
- break;
758
- case "name":
759
- option.innerHTML = String(optionValue);
760
- break;
761
- case "selected":
762
- option.selected = true;
763
- break;
764
- case "disabled":
765
- option.disabled = true;
766
- break;
767
- }
768
- });
769
- select.appendChild(option);
770
- break;
771
- case "options":
772
- attrValue.forEach((opt) => {
773
- let customOption = document.createElement("option");
774
- Object.entries(opt).forEach(([optionName, optionValue]) => {
775
- switch (optionName) {
776
- case "value":
777
- customOption.value = String(optionValue);
778
- break;
779
- case "name":
780
- customOption.innerHTML = String(optionValue);
781
- break;
782
- case "selected":
783
- customOption.selected = Boolean(optionValue);
784
- break;
785
- case "disabled":
786
- customOption.disabled = Boolean(optionValue);
787
- break;
788
- }
789
- });
790
- select.appendChild(customOption);
791
- });
792
- break;
793
- default:
794
- if (name.startsWith("data")) {
795
- const kebabName = name
796
- .replace(/^data/, "data")
797
- .replace(/([A-Z])/g, "-$1")
798
- .toLowerCase();
799
- select.setAttribute(kebabName, String(attrValue));
800
- } else {
801
- select.setAttribute(name, String(attrValue));
802
- }
729
+ let select = document.createElement("select");
730
+ let option = document.createElement("option");
731
+ if (attributes) {
732
+ Object.entries(attributes).forEach(([name, attrValue]) => {
733
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
734
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
735
+ select.addEventListener(eventType, attrValue);
736
+ } else {
737
+ switch (name) {
738
+ case "class":
739
+ case "className":
740
+ select.className = String(attrValue);
741
+ break;
742
+ case "style":
743
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
744
+ switch (styleName) {
745
+ case "zIndex":
746
+ select.style[styleName] = `99999${styleValue}`;
747
+ break;
748
+ default:
749
+ select.style[styleName] = styleValue;
750
+ break;
751
+ }
752
+ });
753
+ break;
754
+ case "option":
755
+ Object.entries(attrValue).forEach(([optionName, optionValue]) => {
756
+ switch (optionName) {
757
+ case "value":
758
+ option.setAttribute('value', String(optionValue));
759
+ break;
760
+ case "name":
761
+ option.innerHTML = String(optionValue);
762
+ break;
763
+ case "selected":
764
+ option.selected = true;
765
+ break;
766
+ case "disabled":
767
+ option.disabled = true;
768
+ break;
769
+ }
770
+ });
771
+ select.appendChild(option);
772
+ break;
773
+ case "options":
774
+ attrValue.forEach((opt) => {
775
+ let customOption = document.createElement("option");
776
+ Object.entries(opt).forEach(([optionName, optionValue]) => {
777
+ switch (optionName) {
778
+ case "value":
779
+ customOption.value = String(optionValue);
780
+ break;
781
+ case "name":
782
+ customOption.innerHTML = String(optionValue);
783
+ break;
784
+ case "selected":
785
+ customOption.selected = Boolean(optionValue);
786
+ break;
787
+ case "disabled":
788
+ customOption.disabled = Boolean(optionValue);
789
+ break;
803
790
  }
791
+ });
792
+ select.appendChild(customOption);
793
+ });
794
+ break;
795
+ default:
796
+ if (name.startsWith("data")) {
797
+ const kebabName = name
798
+ .replace(/^data/, "data")
799
+ .replace(/([A-Z])/g, "-$1")
800
+ .toLowerCase();
801
+ select.setAttribute(kebabName, String(attrValue));
802
+ } else {
803
+ select.setAttribute(name, String(attrValue));
804
804
  }
805
- });
806
- }
807
- return select;
805
+ }
806
+ }
807
+ });
808
+ }
809
+ return select;
808
810
  };
809
811
 
810
812
  export const option = (attributes = {}) => {
811
- let option = document.createElement("option");
812
- if (attributes) {
813
- Object.entries(attributes).forEach(([optionName, optionValue]) => {
814
- switch (optionName) {
815
- case "value": option.value = optionValue; break;
816
- case "name": option.textContent = optionValue; break;
817
- case "selected": option.selected = !!optionValue; break;
818
- case "disabled": option.disabled = !!optionValue; break;
819
- }
820
- });
821
- }
822
- return option;
813
+ let option = document.createElement("option");
814
+ if (attributes) {
815
+ Object.entries(attributes).forEach(([optionName, optionValue]) => {
816
+ switch (optionName) {
817
+ case "value":
818
+ option.value = optionValue;
819
+ break;
820
+ case "name":
821
+ option.textContent = optionValue;
822
+ break;
823
+ case "selected":
824
+ option.selected = !!optionValue;
825
+ break;
826
+ case "disabled":
827
+ option.disabled = !!optionValue;
828
+ break;
829
+ }
830
+ });
831
+ }
832
+ return option;
823
833
  };
824
834
 
825
835
  export const hr = (attributes = {}) => {
826
- let hr = document.createElement("hr");
827
- if (attributes) {
828
- Object.entries(attributes).forEach(([name, attrValue]) => {
829
- switch (name) {
830
- case "class":
831
- case "className":
832
- hr.className = String(attrValue);
833
- break;
834
- case "style": Object.entries(attrValue).forEach(([styleName, styleValue]) => {
835
- switch (styleName) {
836
- case "zIndex": hr.style[styleName] = `99999${styleValue}`; break;
837
- default: hr.style[styleName] = styleValue; break;
838
- }
839
- }); break;
840
- default: hr.setAttribute(name, String(attrValue));
836
+ let hr = document.createElement("hr");
837
+ if (attributes) {
838
+ Object.entries(attributes).forEach(([name, attrValue]) => {
839
+ switch (name) {
840
+ case "class":
841
+ case "className":
842
+ hr.className = String(attrValue);
843
+ break;
844
+ case "style":
845
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
846
+ switch (styleName) {
847
+ case "zIndex":
848
+ hr.style[styleName] = `99999${styleValue}`;
849
+ break;
850
+ default:
851
+ hr.style[styleName] = styleValue;
852
+ break;
841
853
  }
842
- });
843
- }
844
- return hr;
854
+ });
855
+ break;
856
+ default:
857
+ hr.setAttribute(name, String(attrValue));
858
+ }
859
+ });
860
+ }
861
+ return hr;
845
862
  };
846
863
 
847
864
  export const meta = (attributes = {}) => {
848
- let meta = document.createElement("meta");
849
- if (attributes) {
850
- Object.entries(attributes).forEach(([name, attrValue]) => {
851
- switch (name) {
852
- case "class":
853
- case "className":
854
- meta.className = String(attrValue);
855
- break;
856
- case "style": Object.entries(attrValue).forEach(([styleName, styleValue]) => {
857
- switch (styleName) {
858
- case "zIndex": meta.style[styleName] = `99999${styleValue}`; break;
859
- default: meta.style[styleName] = styleValue; break;
860
- }
861
- }); break;
862
- default: meta.setAttribute(name, String(attrValue));
865
+ let meta = document.createElement("meta");
866
+ if (attributes) {
867
+ Object.entries(attributes).forEach(([name, attrValue]) => {
868
+ switch (name) {
869
+ case "class":
870
+ case "className":
871
+ meta.className = String(attrValue);
872
+ break;
873
+ case "style":
874
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
875
+ switch (styleName) {
876
+ case "zIndex":
877
+ meta.style[styleName] = `99999${styleValue}`;
878
+ break;
879
+ default:
880
+ meta.style[styleName] = styleValue;
881
+ break;
863
882
  }
864
- });
865
- }
866
- return meta;
883
+ });
884
+ break;
885
+ default:
886
+ meta.setAttribute(name, String(attrValue));
887
+ }
888
+ });
889
+ }
890
+ return meta;
867
891
  };
868
892
 
869
893
  export const table = (attributes = {}) => {
870
- let table = document.createElement("table");
871
- if (attributes) {
872
- Object.entries(attributes).forEach(([name, attrValue]) => {
873
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
874
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
875
- table.addEventListener(eventType, attrValue);
894
+ let table = document.createElement("table");
895
+ if (attributes) {
896
+ Object.entries(attributes).forEach(([name, attrValue]) => {
897
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
898
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
899
+ table.addEventListener(eventType, attrValue);
900
+ } else {
901
+ switch (name) {
902
+ case "class":
903
+ case "className":
904
+ table.className = String(attrValue);
905
+ break;
906
+ case "value":
907
+ if (isArray(attrValue)) {
908
+ attrValue.forEach((element) => {
909
+ isHtmlElement(element) ? table.append(element) : table.innerHTML = String(element);
910
+ });
876
911
  } else {
877
- switch (name) {
878
- case "class":
879
- case "className":
880
- table.className = String(attrValue);
881
- break;
882
- case "value":
883
- if (isArray(attrValue)) {
884
- attrValue.forEach((element) => {
885
- isHtmlElement(element) ? table.append(element) : table.innerHTML = String(element);
886
- });
887
- } else {
888
- if (isHtmlElement(attrValue)) {
889
- table.appendChild(attrValue);
890
- } else {
891
- table.innerHTML = String(attrValue);
892
- table.title = String(attrValue);
893
- }
894
- }
895
- break;
896
- case "style":
897
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
898
- switch (styleName) {
899
- case "zIndex":
900
- table.style[styleName] = `99999${styleValue}`;
901
- break;
902
- default:
903
- table.style[styleName] = styleValue;
904
- break;
905
- }
906
- });
907
- break;
908
- default:
909
- if (name.startsWith("data")) {
910
- const kebabName = name
911
- .replace(/^data/, "data")
912
- .replace(/([A-Z])/g, "-$1")
913
- .toLowerCase();
914
- table.setAttribute(kebabName, String(attrValue));
915
- } else {
916
- table.setAttribute(name, String(attrValue));
917
- }
918
- }
912
+ if (isHtmlElement(attrValue)) {
913
+ table.appendChild(attrValue);
914
+ } else {
915
+ table.innerHTML = String(attrValue);
916
+ table.title = String(attrValue);
917
+ }
919
918
  }
920
- });
921
- }
922
- return table;
919
+ break;
920
+ case "style":
921
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
922
+ switch (styleName) {
923
+ case "zIndex":
924
+ table.style[styleName] = `99999${styleValue}`;
925
+ break;
926
+ default:
927
+ table.style[styleName] = styleValue;
928
+ break;
929
+ }
930
+ });
931
+ break;
932
+ default:
933
+ if (name.startsWith("data")) {
934
+ const kebabName = name
935
+ .replace(/^data/, "data")
936
+ .replace(/([A-Z])/g, "-$1")
937
+ .toLowerCase();
938
+ table.setAttribute(kebabName, String(attrValue));
939
+ } else {
940
+ table.setAttribute(name, String(attrValue));
941
+ }
942
+ }
943
+ }
944
+ });
945
+ }
946
+ return table;
923
947
  };
924
948
 
925
949
  export const caption = (attributes = {}) => {
926
- let caption = document.createElement("caption");
927
- if (attributes) {
928
- Object.entries(attributes).forEach(([name, attrValue]) => {
929
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
930
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
931
- caption.addEventListener(eventType, attrValue);
950
+ let caption = document.createElement("caption");
951
+ if (attributes) {
952
+ Object.entries(attributes).forEach(([name, attrValue]) => {
953
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
954
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
955
+ caption.addEventListener(eventType, attrValue);
956
+ } else {
957
+ switch (name) {
958
+ case "side":
959
+ caption.style.captionSide = String(attrValue);
960
+ break;
961
+ case "class":
962
+ case "className":
963
+ caption.className = String(attrValue);
964
+ break;
965
+ case "value":
966
+ if (isArray(attrValue)) {
967
+ attrValue.forEach((element) => {
968
+ isHtmlElement(element) ? caption.append(element) : caption.innerHTML = String(element);
969
+ });
932
970
  } else {
933
- switch (name) {
934
- case "side":
935
- caption.style.captionSide = String(attrValue);
936
- break;
937
- case "class":
938
- case "className":
939
- caption.className = String(attrValue);
940
- break;
941
- case "value":
942
- if (isArray(attrValue)) {
943
- attrValue.forEach((element) => {
944
- isHtmlElement(element) ? caption.append(element) : caption.innerHTML = String(element);
945
- });
946
- } else {
947
- if (isHtmlElement(attrValue)) {
948
- caption.appendChild(attrValue);
949
- } else {
950
- caption.innerHTML = String(attrValue);
951
- caption.title = String(attrValue);
952
- }
953
- }
954
- break;
955
- case "style":
956
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
957
- switch (styleName) {
958
- case "zIndex":
959
- caption.style[styleName] = `99999${styleValue}`;
960
- break;
961
- default:
962
- caption.style[styleName] = styleValue;
963
- break;
964
- }
965
- });
966
- break;
967
- default:
968
- if (name.startsWith("data")) {
969
- const kebabName = name
970
- .replace(/^data/, "data")
971
- .replace(/([A-Z])/g, "-$1")
972
- .toLowerCase();
973
- caption.setAttribute(kebabName, String(attrValue));
974
- } else {
975
- caption.setAttribute(name, String(attrValue));
976
- }
977
- }
971
+ if (isHtmlElement(attrValue)) {
972
+ caption.appendChild(attrValue);
973
+ } else {
974
+ caption.innerHTML = String(attrValue);
975
+ caption.title = String(attrValue);
976
+ }
978
977
  }
979
- });
980
- }
981
- return caption;
978
+ break;
979
+ case "style":
980
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
981
+ switch (styleName) {
982
+ case "zIndex":
983
+ caption.style[styleName] = `99999${styleValue}`;
984
+ break;
985
+ default:
986
+ caption.style[styleName] = styleValue;
987
+ break;
988
+ }
989
+ });
990
+ break;
991
+ default:
992
+ if (name.startsWith("data")) {
993
+ const kebabName = name
994
+ .replace(/^data/, "data")
995
+ .replace(/([A-Z])/g, "-$1")
996
+ .toLowerCase();
997
+ caption.setAttribute(kebabName, String(attrValue));
998
+ } else {
999
+ caption.setAttribute(name, String(attrValue));
1000
+ }
1001
+ }
1002
+ }
1003
+ });
1004
+ }
1005
+ return caption;
982
1006
  };
983
1007
 
984
1008
  export const thead = (attributes = {}) => {
985
- let thead = document.createElement("thead");
986
- if (attributes) {
987
- Object.entries(attributes).forEach(([name, attrValue]) => {
988
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
989
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
990
- thead.addEventListener(eventType, attrValue);
1009
+ let thead = document.createElement("thead");
1010
+ if (attributes) {
1011
+ Object.entries(attributes).forEach(([name, attrValue]) => {
1012
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1013
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1014
+ thead.addEventListener(eventType, attrValue);
1015
+ } else {
1016
+ switch (name) {
1017
+ case "class":
1018
+ case "className":
1019
+ thead.className = String(attrValue);
1020
+ break;
1021
+ case "value":
1022
+ if (isArray(attrValue)) {
1023
+ attrValue.forEach((element) => {
1024
+ isHtmlElement(element) ? thead.append(element) : thead.innerHTML = String(element);
1025
+ });
991
1026
  } else {
992
- switch (name) {
993
- case "class":
994
- case "className":
995
- thead.className = String(attrValue);
996
- break;
997
- case "value":
998
- if (isArray(attrValue)) {
999
- attrValue.forEach((element) => {
1000
- isHtmlElement(element) ? thead.append(element) : thead.innerHTML = String(element);
1001
- });
1002
- } else {
1003
- if (isHtmlElement(attrValue)) {
1004
- thead.appendChild(attrValue);
1005
- } else {
1006
- thead.innerHTML = String(attrValue);
1007
- thead.title = String(attrValue);
1008
- }
1009
- }
1010
- break;
1011
- case "style":
1012
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1013
- switch (styleName) {
1014
- case "zIndex":
1015
- thead.style[styleName] = `99999${styleValue}`;
1016
- break;
1017
- default:
1018
- thead.style[styleName] = styleValue;
1019
- break;
1020
- }
1021
- });
1022
- break;
1023
- default:
1024
- if (name.startsWith("data")) {
1025
- const kebabName = name
1026
- .replace(/^data/, "data")
1027
- .replace(/([A-Z])/g, "-$1")
1028
- .toLowerCase();
1029
- thead.setAttribute(kebabName, String(attrValue));
1030
- } else {
1031
- thead.setAttribute(name, String(attrValue));
1032
- }
1033
- }
1027
+ if (isHtmlElement(attrValue)) {
1028
+ thead.appendChild(attrValue);
1029
+ } else {
1030
+ thead.innerHTML = String(attrValue);
1031
+ thead.title = String(attrValue);
1032
+ }
1034
1033
  }
1035
- });
1036
- }
1037
- return thead;
1034
+ break;
1035
+ case "style":
1036
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1037
+ switch (styleName) {
1038
+ case "zIndex":
1039
+ thead.style[styleName] = `99999${styleValue}`;
1040
+ break;
1041
+ default:
1042
+ thead.style[styleName] = styleValue;
1043
+ break;
1044
+ }
1045
+ });
1046
+ break;
1047
+ default:
1048
+ if (name.startsWith("data")) {
1049
+ const kebabName = name
1050
+ .replace(/^data/, "data")
1051
+ .replace(/([A-Z])/g, "-$1")
1052
+ .toLowerCase();
1053
+ thead.setAttribute(kebabName, String(attrValue));
1054
+ } else {
1055
+ thead.setAttribute(name, String(attrValue));
1056
+ }
1057
+ }
1058
+ }
1059
+ });
1060
+ }
1061
+ return thead;
1038
1062
  };
1039
1063
 
1040
1064
  export const tbody = (attributes = {}) => {
1041
- let tbody = document.createElement("tbody");
1042
- if (attributes) {
1043
- Object.entries(attributes).forEach(([name, attrValue]) => {
1044
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1045
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1046
- tbody.addEventListener(eventType, attrValue);
1065
+ let tbody = document.createElement("tbody");
1066
+ if (attributes) {
1067
+ Object.entries(attributes).forEach(([name, attrValue]) => {
1068
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1069
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1070
+ tbody.addEventListener(eventType, attrValue);
1071
+ } else {
1072
+ switch (name) {
1073
+ case "class":
1074
+ case "className":
1075
+ tbody.className = String(attrValue);
1076
+ break;
1077
+ case "value":
1078
+ if (isArray(attrValue)) {
1079
+ attrValue.forEach((element) => {
1080
+ isHtmlElement(element) ? tbody.append(element) : tbody.innerHTML = String(element);
1081
+ });
1047
1082
  } else {
1048
- switch (name) {
1049
- case "class":
1050
- case "className":
1051
- tbody.className = String(attrValue);
1052
- break;
1053
- case "value":
1054
- if (isArray(attrValue)) {
1055
- attrValue.forEach((element) => {
1056
- isHtmlElement(element) ? tbody.append(element) : tbody.innerHTML = String(element);
1057
- });
1058
- } else {
1059
- if (isHtmlElement(attrValue)) {
1060
- tbody.appendChild(attrValue);
1061
- } else {
1062
- tbody.innerHTML = String(attrValue);
1063
- tbody.title = String(attrValue);
1064
- }
1065
- }
1066
- break;
1067
- case "style":
1068
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1069
- switch (styleName) {
1070
- case "zIndex":
1071
- tbody.style[styleName] = `99999${styleValue}`;
1072
- break;
1073
- default:
1074
- tbody.style[styleName] = styleValue;
1075
- break;
1076
- }
1077
- });
1078
- break;
1079
- default:
1080
- if (name.startsWith("data")) {
1081
- const kebabName = name
1082
- .replace(/^data/, "data")
1083
- .replace(/([A-Z])/g, "-$1")
1084
- .toLowerCase();
1085
- tbody.setAttribute(kebabName, String(attrValue));
1086
- } else {
1087
- tbody.setAttribute(name, String(attrValue));
1088
- }
1089
- }
1083
+ if (isHtmlElement(attrValue)) {
1084
+ tbody.appendChild(attrValue);
1085
+ } else {
1086
+ tbody.innerHTML = String(attrValue);
1087
+ tbody.title = String(attrValue);
1088
+ }
1090
1089
  }
1091
- });
1092
- }
1093
- return tbody;
1090
+ break;
1091
+ case "style":
1092
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1093
+ switch (styleName) {
1094
+ case "zIndex":
1095
+ tbody.style[styleName] = `99999${styleValue}`;
1096
+ break;
1097
+ default:
1098
+ tbody.style[styleName] = styleValue;
1099
+ break;
1100
+ }
1101
+ });
1102
+ break;
1103
+ default:
1104
+ if (name.startsWith("data")) {
1105
+ const kebabName = name
1106
+ .replace(/^data/, "data")
1107
+ .replace(/([A-Z])/g, "-$1")
1108
+ .toLowerCase();
1109
+ tbody.setAttribute(kebabName, String(attrValue));
1110
+ } else {
1111
+ tbody.setAttribute(name, String(attrValue));
1112
+ }
1113
+ }
1114
+ }
1115
+ });
1116
+ }
1117
+ return tbody;
1094
1118
  };
1095
1119
 
1096
1120
  export const tr = (attributes = {}) => {
1097
- let tr = document.createElement("tr");
1098
- if (attributes) {
1099
- Object.entries(attributes).forEach(([name, attrValue]) => {
1100
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1101
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1102
- tr.addEventListener(eventType, attrValue);
1121
+ let tr = document.createElement("tr");
1122
+ if (attributes) {
1123
+ Object.entries(attributes).forEach(([name, attrValue]) => {
1124
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1125
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1126
+ tr.addEventListener(eventType, attrValue);
1127
+ } else {
1128
+ switch (name) {
1129
+ case "class":
1130
+ case "className":
1131
+ tr.className = String(attrValue);
1132
+ break;
1133
+ case "value":
1134
+ if (isArray(attrValue)) {
1135
+ attrValue.forEach((element) => {
1136
+ isHtmlElement(element) ? tr.append(element) : tr.innerHTML = String(element);
1137
+ });
1103
1138
  } else {
1104
- switch (name) {
1105
- case "class":
1106
- case "className":
1107
- tr.className = String(attrValue);
1108
- break;
1109
- case "value":
1110
- if (isArray(attrValue)) {
1111
- attrValue.forEach((element) => {
1112
- isHtmlElement(element) ? tr.append(element) : tr.innerHTML = String(element);
1113
- });
1114
- } else {
1115
- if (isHtmlElement(attrValue)) {
1116
- tr.appendChild(attrValue);
1117
- } else {
1118
- tr.innerHTML = String(attrValue);
1119
- tr.title = String(attrValue);
1120
- }
1121
- }
1122
- break;
1123
- case "style":
1124
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1125
- switch (styleName) {
1126
- case "zIndex":
1127
- tr.style[styleName] = `99999${styleValue}`;
1128
- break;
1129
- default:
1130
- tr.style[styleName] = styleValue;
1131
- break;
1132
- }
1133
- });
1134
- break;
1135
- default:
1136
- if (name.startsWith("data")) {
1137
- const kebabName = name
1138
- .replace(/^data/, "data")
1139
- .replace(/([A-Z])/g, "-$1")
1140
- .toLowerCase();
1141
- tr.setAttribute(kebabName, String(attrValue));
1142
- } else {
1143
- tr.setAttribute(name, String(attrValue));
1144
- }
1145
- }
1139
+ if (isHtmlElement(attrValue)) {
1140
+ tr.appendChild(attrValue);
1141
+ } else {
1142
+ tr.innerHTML = String(attrValue);
1143
+ tr.title = String(attrValue);
1144
+ }
1146
1145
  }
1147
- });
1148
- }
1149
- return tr;
1146
+ break;
1147
+ case "style":
1148
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1149
+ switch (styleName) {
1150
+ case "zIndex":
1151
+ tr.style[styleName] = `99999${styleValue}`;
1152
+ break;
1153
+ default:
1154
+ tr.style[styleName] = styleValue;
1155
+ break;
1156
+ }
1157
+ });
1158
+ break;
1159
+ default:
1160
+ if (name.startsWith("data")) {
1161
+ const kebabName = name
1162
+ .replace(/^data/, "data")
1163
+ .replace(/([A-Z])/g, "-$1")
1164
+ .toLowerCase();
1165
+ tr.setAttribute(kebabName, String(attrValue));
1166
+ } else {
1167
+ tr.setAttribute(name, String(attrValue));
1168
+ }
1169
+ }
1170
+ }
1171
+ });
1172
+ }
1173
+ return tr;
1150
1174
  };
1151
1175
 
1152
1176
  export const th = (attributes = {}) => {
1153
- let th = document.createElement("th");
1154
- if (attributes) {
1155
- Object.entries(attributes).forEach(([name, attrValue]) => {
1156
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1157
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1158
- th.addEventListener(eventType, attrValue);
1177
+ let th = document.createElement("th");
1178
+ if (attributes) {
1179
+ Object.entries(attributes).forEach(([name, attrValue]) => {
1180
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1181
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1182
+ th.addEventListener(eventType, attrValue);
1183
+ } else {
1184
+ switch (name) {
1185
+ case "class":
1186
+ case "className":
1187
+ th.className = String(attrValue);
1188
+ break;
1189
+ case "value":
1190
+ if (isArray(attrValue)) {
1191
+ attrValue.forEach((element) => {
1192
+ isHtmlElement(element) ? th.append(element) : th.innerHTML = String(element);
1193
+ });
1159
1194
  } else {
1160
- switch (name) {
1161
- case "class":
1162
- case "className":
1163
- th.className = String(attrValue);
1164
- break;
1165
- case "value":
1166
- if (isArray(attrValue)) {
1167
- attrValue.forEach((element) => {
1168
- isHtmlElement(element) ? th.append(element) : th.innerHTML = String(element);
1169
- });
1170
- } else {
1171
- if (isHtmlElement(attrValue)) {
1172
- th.appendChild(attrValue);
1173
- } else {
1174
- th.innerHTML = String(attrValue);
1175
- th.title = String(attrValue);
1176
- }
1177
- }
1178
- break;
1179
- case "style":
1180
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1181
- switch (styleName) {
1182
- case "zIndex":
1183
- th.style[styleName] = `99999${styleValue}`;
1184
- break;
1185
- default:
1186
- th.style[styleName] = styleValue;
1187
- break;
1188
- }
1189
- });
1190
- break;
1191
- default:
1192
- if (name.startsWith("data")) {
1193
- const kebabName = name
1194
- .replace(/^data/, "data")
1195
- .replace(/([A-Z])/g, "-$1")
1196
- .toLowerCase();
1197
- th.setAttribute(kebabName, String(attrValue));
1198
- } else {
1199
- th.setAttribute(name, String(attrValue));
1200
- }
1201
- }
1195
+ if (isHtmlElement(attrValue)) {
1196
+ th.appendChild(attrValue);
1197
+ } else {
1198
+ th.innerHTML = String(attrValue);
1199
+ th.title = String(attrValue);
1200
+ }
1202
1201
  }
1203
- });
1204
- }
1205
- return th;
1202
+ break;
1203
+ case "style":
1204
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1205
+ switch (styleName) {
1206
+ case "zIndex":
1207
+ th.style[styleName] = `99999${styleValue}`;
1208
+ break;
1209
+ default:
1210
+ th.style[styleName] = styleValue;
1211
+ break;
1212
+ }
1213
+ });
1214
+ break;
1215
+ default:
1216
+ if (name.startsWith("data")) {
1217
+ const kebabName = name
1218
+ .replace(/^data/, "data")
1219
+ .replace(/([A-Z])/g, "-$1")
1220
+ .toLowerCase();
1221
+ th.setAttribute(kebabName, String(attrValue));
1222
+ } else {
1223
+ th.setAttribute(name, String(attrValue));
1224
+ }
1225
+ }
1226
+ }
1227
+ });
1228
+ }
1229
+ return th;
1206
1230
  };
1207
1231
 
1208
1232
  export const td = (attributes = {}) => {
1209
- let td = document.createElement("td");
1210
- if (attributes) {
1211
- Object.entries(attributes).forEach(([name, attrValue]) => {
1212
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1213
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1214
- td.addEventListener(eventType, attrValue);
1233
+ let td = document.createElement("td");
1234
+ if (attributes) {
1235
+ Object.entries(attributes).forEach(([name, attrValue]) => {
1236
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1237
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1238
+ td.addEventListener(eventType, attrValue);
1239
+ } else {
1240
+ switch (name) {
1241
+ case "class":
1242
+ case "className":
1243
+ td.className = String(attrValue);
1244
+ break;
1245
+ case "value":
1246
+ if (isArray(attrValue)) {
1247
+ attrValue.forEach((element) => {
1248
+ isHtmlElement(element) ? td.append(element) : td.innerHTML = String(element);
1249
+ });
1215
1250
  } else {
1216
- switch (name) {
1217
- case "class":
1218
- case "className":
1219
- td.className = String(attrValue);
1220
- break;
1221
- case "value":
1222
- if (isArray(attrValue)) {
1223
- attrValue.forEach((element) => {
1224
- isHtmlElement(element) ? td.append(element) : td.innerHTML = String(element);
1225
- });
1226
- } else {
1227
- if (isHtmlElement(attrValue)) {
1228
- td.appendChild(attrValue);
1229
- } else {
1230
- td.innerHTML = String(attrValue);
1231
- td.title = String(attrValue);
1232
- }
1233
- }
1234
- break;
1235
- case "style":
1236
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1237
- switch (styleName) {
1238
- case "zIndex":
1239
- td.style[styleName] = `99999${styleValue}`;
1240
- break;
1241
- default:
1242
- td.style[styleName] = styleValue;
1243
- break;
1244
- }
1245
- });
1246
- break;
1247
- default:
1248
- if (name.startsWith("data")) {
1249
- const kebabName = name
1250
- .replace(/^data/, "data")
1251
- .replace(/([A-Z])/g, "-$1")
1252
- .toLowerCase();
1253
- td.setAttribute(kebabName, String(attrValue));
1254
- } else {
1255
- td.setAttribute(name, String(attrValue));
1256
- }
1257
- }
1251
+ if (isHtmlElement(attrValue)) {
1252
+ td.appendChild(attrValue);
1253
+ } else {
1254
+ td.innerHTML = String(attrValue);
1255
+ td.title = String(attrValue);
1256
+ }
1258
1257
  }
1259
- });
1260
- }
1261
- return td;
1258
+ break;
1259
+ case "style":
1260
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1261
+ switch (styleName) {
1262
+ case "zIndex":
1263
+ td.style[styleName] = `99999${styleValue}`;
1264
+ break;
1265
+ default:
1266
+ td.style[styleName] = styleValue;
1267
+ break;
1268
+ }
1269
+ });
1270
+ break;
1271
+ default:
1272
+ if (name.startsWith("data")) {
1273
+ const kebabName = name
1274
+ .replace(/^data/, "data")
1275
+ .replace(/([A-Z])/g, "-$1")
1276
+ .toLowerCase();
1277
+ td.setAttribute(kebabName, String(attrValue));
1278
+ } else {
1279
+ td.setAttribute(name, String(attrValue));
1280
+ }
1281
+ }
1282
+ }
1283
+ });
1284
+ }
1285
+ return td;
1262
1286
  };
1263
1287
 
1264
1288
  export const img = (attributes = {}) => {
1265
- let img = document.createElement("img");
1266
- img.alt = "img...";
1267
- if (attributes) {
1268
- Object.entries(attributes).forEach(([name, attrValue]) => {
1269
- if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1270
- const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1271
- img.addEventListener(eventType, attrValue);
1289
+ let img = document.createElement("img");
1290
+ img.alt = "img...";
1291
+ if (attributes) {
1292
+ Object.entries(attributes).forEach(([name, attrValue]) => {
1293
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1294
+ const eventType = name.startsWith("mouse") ? name.toLowerCase() : name.slice(2).toLowerCase();
1295
+ img.addEventListener(eventType, attrValue);
1296
+ } else {
1297
+ switch (name) {
1298
+ case "class":
1299
+ case "className":
1300
+ img.className = String(attrValue);
1301
+ break;
1302
+ case "src":
1303
+ img.src = String(attrValue);
1304
+ break;
1305
+ case "alt":
1306
+ img.alt = String(attrValue);
1307
+ break;
1308
+ case "style":
1309
+ Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1310
+ switch (styleName) {
1311
+ case "zIndex":
1312
+ img.style[styleName] = `99999${styleValue}`;
1313
+ break;
1314
+ default:
1315
+ img.style[styleName] = styleValue;
1316
+ break;
1317
+ }
1318
+ });
1319
+ break;
1320
+ default:
1321
+ if (name.startsWith("data")) {
1322
+ const kebabName = name
1323
+ .replace(/^data/, "data")
1324
+ .replace(/([A-Z])/g, "-$1")
1325
+ .toLowerCase();
1326
+ img.setAttribute(kebabName, String(attrValue));
1272
1327
  } else {
1273
- switch (name) {
1274
- case "class":
1275
- case "className":
1276
- img.className = String(attrValue);
1277
- break;
1278
- case "src":
1279
- img.src = String(attrValue);
1280
- break;
1281
- case "alt":
1282
- img.alt = String(attrValue);
1283
- break;
1284
- case "style":
1285
- Object.entries(attrValue).forEach(([styleName, styleValue]) => {
1286
- switch (styleName) {
1287
- case "zIndex":
1288
- img.style[styleName] = `99999${styleValue}`;
1289
- break;
1290
- default:
1291
- img.style[styleName] = styleValue;
1292
- break;
1293
- }
1294
- });
1295
- break;
1296
- default:
1297
- if (name.startsWith("data")) {
1298
- const kebabName = name
1299
- .replace(/^data/, "data")
1300
- .replace(/([A-Z])/g, "-$1")
1301
- .toLowerCase();
1302
- img.setAttribute(kebabName, String(attrValue));
1303
- } else {
1304
- img.setAttribute(name, String(attrValue));
1305
- }
1306
- }
1328
+ img.setAttribute(name, String(attrValue));
1307
1329
  }
1308
- });
1309
- }
1310
- return img;
1330
+ }
1331
+ }
1332
+ });
1333
+ }
1334
+ return img;
1311
1335
  };
1312
1336
 
1313
1337
  export const apState = (initialValue) => {
1314
- let state = initialValue;
1315
- const getState = () => state;
1316
- const setState = (newValue) => {
1317
- if (typeof newValue === "function") {
1318
- state = newValue(state);
1319
- } else {
1320
- state = newValue;
1321
- }
1338
+ let state = initialValue;
1339
+ const getState = () => state;
1340
+ const setState = (newValue) => {
1341
+ if (typeof newValue === "function") {
1342
+ state = newValue(state);
1343
+ } else {
1344
+ state = newValue;
1322
1345
  }
1323
- return [getState, setState];
1346
+ }
1347
+ return [getState, setState];
1324
1348
  };
1325
1349
 
1326
1350
  export const apFetch = async (url, params = {}) => {
1327
- const [data, setData] = apState(null);
1328
- const [error, setError] = apState(null);
1329
- const [isLoading, setIsLoading] = apState(false);
1351
+ const [data, setData] = apState(null);
1352
+ const [error, setError] = apState(null);
1353
+ const [isLoading, setIsLoading] = apState(false);
1330
1354
 
1331
- const fetchData = async () => {
1332
- setIsLoading(true);
1333
- setError(null);
1334
- try {
1335
- const response = await fetch(url, params);
1336
- if (!response.ok) {
1337
- throw new Error(`HTTP error! Status: ${response.status}`);
1338
- }
1339
- const result = await response.json();
1340
- setData(result);
1341
- } catch (err) {
1342
- console.error(err.message)
1343
- setError(err.message);
1344
- } finally {
1345
- setIsLoading(false);
1346
- }
1347
- };
1348
- await fetchData();
1355
+ const fetchData = async () => {
1356
+ setIsLoading(true);
1357
+ setError(null);
1358
+ try {
1359
+ const response = await fetch(url, params);
1360
+ if (!response.ok) {
1361
+ throw new Error(`HTTP error! Status: ${response.status}`);
1362
+ }
1363
+ const result = await response.json();
1364
+ setData(result);
1365
+ } catch (err) {
1366
+ console.error(err.message)
1367
+ setError(err.message);
1368
+ } finally {
1369
+ setIsLoading(false);
1370
+ }
1371
+ };
1372
+ await fetchData();
1349
1373
 
1350
- return [data, error, isLoading];
1374
+ return [data, error, isLoading];
1351
1375
  };
1352
1376
 
1353
1377
  export const scrollToTop = () => {
1354
- window.scrollTo({
1355
- top: 0,
1356
- behavior: "smooth",
1357
- });
1378
+ window.scrollTo({
1379
+ top: 0,
1380
+ behavior: "smooth",
1381
+ });
1358
1382
  };
1359
1383
 
1360
1384
  export const scrollToBottom = () => {
1361
- window.scrollTo({
1362
- top: document.documentElement.scrollHeight,
1363
- behavior: "smooth",
1364
- });
1385
+ window.scrollTo({
1386
+ top: document.documentElement.scrollHeight,
1387
+ behavior: "smooth",
1388
+ });
1365
1389
  };
1366
1390
 
1367
1391
  export const _get = (name, defaulting = null) => {
1368
- let url = new URL(window.location.href);
1369
- let searchParams = new URLSearchParams(url.search);
1370
- if (searchParams.has(name)) {
1371
- return isFloat(searchParams.get(name)) || isNumeric(searchParams.get(name))
1372
- ? parseFloat(searchParams.get(name))
1373
- : searchParams.get(name);
1374
- }
1375
- return defaulting;
1392
+ let url = new URL(window.location.href);
1393
+ let searchParams = new URLSearchParams(url.search);
1394
+ if (searchParams.has(name)) {
1395
+ return isFloat(searchParams.get(name)) || isNumeric(searchParams.get(name))
1396
+ ? parseFloat(searchParams.get(name))
1397
+ : searchParams.get(name);
1398
+ }
1399
+ return defaulting;
1376
1400
  };
1377
1401
 
1378
1402
  export const _getAll = () => {
1379
- let url = new URL(window.location.href);
1380
- let searchParams = new URLSearchParams(url.search);
1381
- let params = {};
1382
- searchParams.forEach((value, key) => {
1383
- params[key] = isFloat(value) || isNumeric(value) ? parseFloat(value) : value;
1384
- });
1385
- return params;
1403
+ let url = new URL(window.location.href);
1404
+ let searchParams = new URLSearchParams(url.search);
1405
+ let params = {};
1406
+ searchParams.forEach((value, key) => {
1407
+ params[key] = isFloat(value) || isNumeric(value) ? parseFloat(value) : value;
1408
+ });
1409
+ return params;
1386
1410
  };
1387
1411
 
1388
1412
  export const GUID = () => {
1389
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) {
1390
- const random = Math.random() * 16 | 0;
1391
- const value = char === 'x' ? random : (random & 0x3 | 0x8);
1392
- return value.toString(16);
1393
- });
1413
+ let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) {
1414
+ const random = Math.random() * 16 | 0;
1415
+ const value = char === 'x' ? random : (random & 0x3 | 0x8);
1416
+ return value.toString(16);
1417
+ });
1418
+
1419
+ if (/^[0-9]/.test(uuid)) {
1420
+ const letter = String.fromCharCode(97 + Math.floor(Math.random() * 6)); // a–f
1421
+ uuid = letter + uuid.slice(1);
1422
+ }
1423
+
1424
+ return uuid;
1394
1425
  };
1395
1426
 
1396
1427
  export const checkArrays = (arr1, arr2, checkAll = false) => {
1397
- const set1 = new Set(arr1);
1398
- if (checkAll) {
1399
- return arr2.every(item => set1.has(item));
1400
- } else {
1401
- return arr2.some(item => set1.has(item));
1402
- }
1428
+ const set1 = new Set(arr1);
1429
+ if (checkAll) {
1430
+ return arr2.every(item => set1.has(item));
1431
+ } else {
1432
+ return arr2.some(item => set1.has(item));
1433
+ }
1403
1434
  };
1404
1435
 
1405
1436
  const customTitle = (text) => {
1406
- const title = div({
1407
- id: "tooltip",
1408
- style: {
1409
- position: "absolute",
1410
- padding: "6px 10px",
1411
- display: "block",
1412
- fontSize: "10px",
1413
- whiteSpace: "nowrap",
1414
- color: "#ffffff",
1415
- background: "rgba(51, 51, 51, 0.8)",
1416
- borderRadius: "0.5rem",
1417
- boxShadow: "0 3 7 rgba(51, 51, 51, 0.8)",
1418
- pointerEvents: "none",
1419
- zIndex: 1000,
1420
- },
1421
- value: text
1422
- });
1423
- document.body.appendChild(title);
1437
+ const title = div({
1438
+ id: "tooltip",
1439
+ style: {
1440
+ position: "absolute",
1441
+ padding: "6px 10px",
1442
+ display: "block",
1443
+ fontSize: "10px",
1444
+ whiteSpace: "nowrap",
1445
+ color: "#ffffff",
1446
+ background: "rgba(51, 51, 51, 0.8)",
1447
+ borderRadius: "0.5rem",
1448
+ boxShadow: "0 3 7 rgba(51, 51, 51, 0.8)",
1449
+ pointerEvents: "none",
1450
+ zIndex: 1000,
1451
+ },
1452
+ value: text
1453
+ });
1454
+ document.body.appendChild(title);
1424
1455
 
1425
- return title;
1456
+ return title;
1426
1457
  };
1427
1458
 
1428
1459
  export const attachCustomTitle = (element, text) => {
1429
- let tooltip = element._customTooltip;
1460
+ let tooltip = element._customTooltip;
1430
1461
 
1431
- if (!tooltip) {
1432
- tooltip = customTitle(text);
1433
- element._customTooltip = tooltip;
1434
- }
1462
+ if (!tooltip) {
1463
+ tooltip = customTitle(text);
1464
+ element._customTooltip = tooltip;
1465
+ }
1435
1466
 
1436
- element.addEventListener("mouseenter", () => {
1437
- tooltip.style.display = "block";
1438
- });
1467
+ element.addEventListener("mouseenter", () => {
1468
+ tooltip.style.display = "block";
1469
+ });
1439
1470
 
1440
- element.addEventListener("mousemove", (e) => {
1441
- tooltip.style.left = `${e.pageX + 10}px`;
1442
- tooltip.style.top = `${e.pageY + 10}px`;
1443
- });
1471
+ element.addEventListener("mousemove", (e) => {
1472
+ tooltip.style.left = `${e.pageX + 10}px`;
1473
+ tooltip.style.top = `${e.pageY + 10}px`;
1474
+ });
1444
1475
 
1445
- element.addEventListener("mouseleave", () => {
1446
- tooltip.style.display = "none";
1447
- });
1476
+ element.addEventListener("mouseleave", () => {
1477
+ tooltip.style.display = "none";
1478
+ });
1448
1479
  };
1449
1480
 
1450
1481
  export const parseCustomMarkup = (text) => {
1451
- text = text.replace(/```([\s\S]*?)```/g, (match, p1) => {
1452
- return `<pre style="width: max-content; padding: 2px 8px; color: #333333; background-color: #fdfdfd; border: 0.03125rem solid #dddddd; border-radius: 4px;"><code style="font-family: Monospaced, serif; font-style: italic; font-weight: 100; letter-spacing: 2px;">${p1.trim()}</code></pre>`;
1453
- });
1454
- text = text.replace(/\*\*(.*?)\*\*/g, '<strong style="font-weight: 700;">$1</strong>');
1455
- text = text.replace(/`([^`]+?)`/g, '<code style="font-family: Monospaced, serif; font-style: italic; font-weight: 100; letter-spacing: 2px;">$1</code>');
1456
- text = text.replace(/^\* (.+)$/gm, '<li style="font-family: Times New Roman, serif; font-weight: 400;">$1</li>');
1457
- return `<div style="font-family: Times New Roman, serif; font-weight: 400;">${text}</div>`;
1482
+ text = text.replace(/```([\s\S]*?)```/g, (match, p1) => {
1483
+ return `<pre style="width: max-content; padding: 2px 8px; color: #333333; background-color: #fdfdfd; border: 0.03125rem solid #dddddd; border-radius: 4px;"><code style="font-family: Monospaced, serif; font-style: italic; font-weight: 100; letter-spacing: 2px;">${p1.trim()}</code></pre>`;
1484
+ });
1485
+ text = text.replace(/\*\*(.*?)\*\*/g, '<strong style="font-weight: 700;">$1</strong>');
1486
+ text = text.replace(/`([^`]+?)`/g, '<code style="font-family: Monospaced, serif; font-style: italic; font-weight: 100; letter-spacing: 2px;">$1</code>');
1487
+ text = text.replace(/^\* (.+)$/gm, '<li style="font-family: Times New Roman, serif; font-weight: 400;">$1</li>');
1488
+ return `<div style="font-family: Times New Roman, serif; font-weight: 400;">${text}</div>`;
1458
1489
  }