aprog 1.3.7 → 1.3.9

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/README.md CHANGED
@@ -147,8 +147,8 @@ onInput: (event) => {
147
147
  - *redirect(url, { newTab: bool, replace: bool }), reload(delaySeconds)*
148
148
  - *encrypt(str), decrypt(encryptedStr)*
149
149
 
150
- - *div, span, button, a, img, meta, label, input, select, option, options, form, hr, textarea, table, caption, thead, tbody, tr, th, td, pre*
151
- - *_get, GUID, apState, cookie, date, pause, apFetch, chars, elementToObject, copyText, scrollToTop, scrollToBottom, firstKey, checkArrays, ucfirst, deepEqual, nodeListToObject*
150
+ - *div, span, button, a, img, meta, label, input, select, option, options, form, hr, textarea, table, caption, thead, tbody, tr, th, td, pre, attachCustomTitle*
151
+ - *_get, GUID, apState, date, pause, apFetch, chars, elementToObject, copyText, scrollToTop, scrollToBottom, firstKey, checkArrays, ucfirst, deepEqual, nodeListToObject*
152
152
  - *isEmpty, isNull, isFloat, isNumeric, isObject, isArray, isNumber, isString, isPromise, isNull, isFloat, isNumeric, isObject*
153
153
 
154
154
  - *router({ routes, main, "Page Not Found" })*
@@ -157,6 +157,8 @@ onInput: (event) => {
157
157
 
158
158
  - *mathInput(event.target)*
159
159
 
160
+ - *cookie, storage*
161
+
160
162
  ### Info
161
163
 
162
164
  - Додано безплатний чат із Gemini
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export {
2
2
  div, span, button, a, img, meta, label, input, select, option, options, form, hr, textarea,
3
- table, caption, thead, tbody, tr, th, td, pre, _get, GUID, isEmpty, apState, cookie, date, pause, apFetch,
3
+ table, caption, thead, tbody, tr, th, td, pre, attachCustomTitle, _get, GUID, isEmpty, apState, date, pause, apFetch,
4
4
  chars, isNull, isFloat, isNumeric, isObject, elementToObject, copyText, scrollToTop, scrollToBottom,
5
5
  firstKey, isArray, checkArrays, isNumber, isString, isPromise, ucfirst, deepEqual, nodeListToObject
6
6
  } from './src/aprog.js';
@@ -9,4 +9,5 @@ export { redirect, reload } from './src/redirect.js';
9
9
  export { router, navigateTo } from './src/router.js';
10
10
  export { encrypt, decrypt } from './src/shifrator.js';
11
11
  export { gemini } from './src/OpenAI.js';
12
- export { mathInput } from './src/math.js';
12
+ export { mathInput } from './src/math.js';
13
+ export { cookie, storage } from './src/storage.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aprog",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "description": "Допоміжна бібліотека js",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/aprog.js CHANGED
@@ -241,7 +241,7 @@ export const input = (attributes = {}) => {
241
241
  let input = document.createElement("input");
242
242
  if (attributes) {
243
243
  Object.entries(attributes).forEach(([name, attrValue]) => {
244
- if (name.startsWith('on') && typeof attrValue === 'function') {
244
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
245
245
  const eventType = name.slice(2).toLowerCase();
246
246
  input.addEventListener(eventType, attrValue);
247
247
  } else {
@@ -290,7 +290,7 @@ export const label = (attributes = {}) => {
290
290
  label.setAttribute("for", "...");
291
291
  if (attributes) {
292
292
  Object.entries(attributes).forEach(([name, attrValue]) => {
293
- if (name.startsWith('on') && typeof attrValue === 'function') {
293
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
294
294
  const eventType = name.slice(2).toLowerCase();
295
295
  label.addEventListener(eventType, attrValue);
296
296
  } else {
@@ -341,7 +341,7 @@ export const form = (attributes = {}) => {
341
341
  let form = document.createElement("form");
342
342
  if (attributes) {
343
343
  Object.entries(attributes).forEach(([name, attrValue]) => {
344
- if (name.startsWith('on') && typeof attrValue === 'function') {
344
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
345
345
  const eventType = name.slice(2).toLowerCase();
346
346
  form.addEventListener(eventType, attrValue);
347
347
  } else {
@@ -401,7 +401,7 @@ export const div = (attributes = {}) => {
401
401
  let div = document.createElement("div");
402
402
  if (attributes) {
403
403
  Object.entries(attributes).forEach(([name, attrValue]) => {
404
- if (name.startsWith('on') && typeof attrValue === 'function') {
404
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
405
405
  const eventType = name.slice(2).toLowerCase();
406
406
  div.addEventListener(eventType, attrValue);
407
407
  } else {
@@ -452,7 +452,7 @@ export const a = (attributes = {}) => {
452
452
  let a = document.createElement("a");
453
453
  if (attributes) {
454
454
  Object.entries(attributes).forEach(([name, attrValue]) => {
455
- if (name.startsWith('on') && typeof attrValue === 'function') {
455
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
456
456
  const eventType = name.slice(2).toLowerCase();
457
457
  a.addEventListener(eventType, attrValue);
458
458
  } else {
@@ -503,7 +503,7 @@ export const span = (attributes = {}) => {
503
503
  let span = document.createElement("span");
504
504
  if (attributes) {
505
505
  Object.entries(attributes).forEach(([name, attrValue]) => {
506
- if (name.startsWith('on') && typeof attrValue === 'function') {
506
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
507
507
  const eventType = name.slice(2).toLowerCase();
508
508
  span.addEventListener(eventType, attrValue);
509
509
  } else {
@@ -554,7 +554,7 @@ export const textarea = (attributes = {}) => {
554
554
  let textarea = document.createElement("textarea");
555
555
  if (attributes) {
556
556
  Object.entries(attributes).forEach(([name, attrValue]) => {
557
- if (name.startsWith('on') && typeof attrValue === 'function') {
557
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
558
558
  const eventType = name.slice(2).toLowerCase();
559
559
  textarea.addEventListener(eventType, attrValue);
560
560
  } else {
@@ -605,7 +605,7 @@ export const pre = (attributes = {}) => {
605
605
  let pre = document.createElement("pre");
606
606
  if (attributes) {
607
607
  Object.entries(attributes).forEach(([name, attrValue]) => {
608
- if (name.startsWith('on') && typeof attrValue === 'function') {
608
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
609
609
  const eventType = name.slice(2).toLowerCase();
610
610
  pre.addEventListener(eventType, attrValue);
611
611
  } else {
@@ -656,7 +656,7 @@ export const button = (attributes = {}) => {
656
656
  let button = document.createElement("button");
657
657
  if (attributes) {
658
658
  Object.entries(attributes).forEach(([name, attrValue]) => {
659
- if (name.startsWith('on') && typeof attrValue === 'function') {
659
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
660
660
  const eventType = name.slice(2).toLowerCase();
661
661
  button.addEventListener(eventType, attrValue);
662
662
  } else {
@@ -708,7 +708,7 @@ export const select = (attributes = {}) => {
708
708
  let option = document.createElement("option");
709
709
  if (attributes) {
710
710
  Object.entries(attributes).forEach(([name, attrValue]) => {
711
- if (name.startsWith('on') && typeof attrValue === 'function') {
711
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
712
712
  const eventType = name.slice(2).toLowerCase();
713
713
  select.addEventListener(eventType, attrValue);
714
714
  } else {
@@ -848,7 +848,7 @@ export const table = (attributes = {}) => {
848
848
  let table = document.createElement("table");
849
849
  if (attributes) {
850
850
  Object.entries(attributes).forEach(([name, attrValue]) => {
851
- if (name.startsWith('on') && typeof attrValue === 'function') {
851
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
852
852
  const eventType = name.slice(2).toLowerCase();
853
853
  table.addEventListener(eventType, attrValue);
854
854
  } else {
@@ -899,7 +899,7 @@ export const caption = (attributes = {}) => {
899
899
  let caption = document.createElement("caption");
900
900
  if (attributes) {
901
901
  Object.entries(attributes).forEach(([name, attrValue]) => {
902
- if (name.startsWith('on') && typeof attrValue === 'function') {
902
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
903
903
  const eventType = name.slice(2).toLowerCase();
904
904
  caption.addEventListener(eventType, attrValue);
905
905
  } else {
@@ -953,7 +953,7 @@ export const thead = (attributes = {}) => {
953
953
  let thead = document.createElement("thead");
954
954
  if (attributes) {
955
955
  Object.entries(attributes).forEach(([name, attrValue]) => {
956
- if (name.startsWith('on') && typeof attrValue === 'function') {
956
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
957
957
  const eventType = name.slice(2).toLowerCase();
958
958
  thead.addEventListener(eventType, attrValue);
959
959
  } else {
@@ -1004,7 +1004,7 @@ export const tbody = (attributes = {}) => {
1004
1004
  let tbody = document.createElement("tbody");
1005
1005
  if (attributes) {
1006
1006
  Object.entries(attributes).forEach(([name, attrValue]) => {
1007
- if (name.startsWith('on') && typeof attrValue === 'function') {
1007
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1008
1008
  const eventType = name.slice(2).toLowerCase();
1009
1009
  tbody.addEventListener(eventType, attrValue);
1010
1010
  } else {
@@ -1055,7 +1055,7 @@ export const tr = (attributes = {}) => {
1055
1055
  let tr = document.createElement("tr");
1056
1056
  if (attributes) {
1057
1057
  Object.entries(attributes).forEach(([name, attrValue]) => {
1058
- if (name.startsWith('on') && typeof attrValue === 'function') {
1058
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1059
1059
  const eventType = name.slice(2).toLowerCase();
1060
1060
  tr.addEventListener(eventType, attrValue);
1061
1061
  } else {
@@ -1106,7 +1106,7 @@ export const th = (attributes = {}) => {
1106
1106
  let th = document.createElement("th");
1107
1107
  if (attributes) {
1108
1108
  Object.entries(attributes).forEach(([name, attrValue]) => {
1109
- if (name.startsWith('on') && typeof attrValue === 'function') {
1109
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1110
1110
  const eventType = name.slice(2).toLowerCase();
1111
1111
  th.addEventListener(eventType, attrValue);
1112
1112
  } else {
@@ -1157,7 +1157,7 @@ export const td = (attributes = {}) => {
1157
1157
  let td = document.createElement("td");
1158
1158
  if (attributes) {
1159
1159
  Object.entries(attributes).forEach(([name, attrValue]) => {
1160
- if (name.startsWith('on') && typeof attrValue === 'function') {
1160
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1161
1161
  const eventType = name.slice(2).toLowerCase();
1162
1162
  td.addEventListener(eventType, attrValue);
1163
1163
  } else {
@@ -1208,7 +1208,7 @@ export const img = (attributes = {}) => {
1208
1208
  img.alt = "img...";
1209
1209
  if (attributes) {
1210
1210
  Object.entries(attributes).forEach(([name, attrValue]) => {
1211
- if (name.startsWith('on') && typeof attrValue === 'function') {
1211
+ if ((name.startsWith('on') || name.startsWith("mouse")) && typeof attrValue === 'function') {
1212
1212
  const eventType = name.slice(2).toLowerCase();
1213
1213
  img.addEventListener(eventType, attrValue);
1214
1214
  } else {
@@ -1324,33 +1324,6 @@ export const GUID = () => {
1324
1324
  });
1325
1325
  }
1326
1326
 
1327
- export const cookie = {
1328
- get(name) {
1329
- const cookies = document.cookie.split('; ');
1330
- for (let cookie of cookies) {
1331
- let [key, value] = cookie.split('=');
1332
- if (key === name) {
1333
- return decodeURIComponent(value);
1334
- }
1335
- }
1336
- return null;
1337
- },
1338
-
1339
- set(name, value, days = 7) {
1340
- let expires = "";
1341
- if (days) {
1342
- let date = new Date();
1343
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
1344
- expires = "; expires=" + date.toUTCString();
1345
- }
1346
- document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
1347
- },
1348
-
1349
- delete(name) {
1350
- document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
1351
- }
1352
- };
1353
-
1354
1327
  export const checkArrays = (arr1, arr2, checkAll = false) => {
1355
1328
  const set1 = new Set(arr1);
1356
1329
  if (checkAll) {
@@ -1359,3 +1332,46 @@ export const checkArrays = (arr1, arr2, checkAll = false) => {
1359
1332
  return arr2.some(item => set1.has(item));
1360
1333
  }
1361
1334
  }
1335
+
1336
+ const customTitle = (text) => {
1337
+ const title = div({
1338
+ style: {
1339
+ position: "absolute",
1340
+ background: "rgba(0, 0, 0, 0.8)",
1341
+ color: "white",
1342
+ padding: "6px 10px",
1343
+ borderRadius: "5px",
1344
+ fontSize: "14px",
1345
+ whiteSpace: "nowrap",
1346
+ display: "none",
1347
+ pointerEvents: "none",
1348
+ zIndex: 1000,
1349
+ },
1350
+ value: text
1351
+ });
1352
+ document.body.appendChild(title);
1353
+
1354
+ return title;
1355
+ };
1356
+
1357
+ export const attachCustomTitle = (element, text) => {
1358
+ let tooltip = element._customTooltip;
1359
+
1360
+ if (!tooltip) {
1361
+ tooltip = customTitle(text);
1362
+ element._customTooltip = tooltip;
1363
+ }
1364
+
1365
+ element.addEventListener("mouseenter", () => {
1366
+ tooltip.style.display = "block";
1367
+ });
1368
+
1369
+ element.addEventListener("mousemove", (e) => {
1370
+ tooltip.style.left = `${e.pageX + 10}px`;
1371
+ tooltip.style.top = `${e.pageY + 10}px`;
1372
+ });
1373
+
1374
+ element.addEventListener("mouseleave", () => {
1375
+ tooltip.style.display = "none";
1376
+ });
1377
+ };
package/src/storage.js ADDED
@@ -0,0 +1,40 @@
1
+ export const cookie = {
2
+ get(name) {
3
+ const cookies = document.cookie.split('; ');
4
+ for (let cookie of cookies) {
5
+ let [key, value] = cookie.split('=');
6
+ if (key === name) {
7
+ return decodeURIComponent(value);
8
+ }
9
+ }
10
+ return null;
11
+ },
12
+
13
+ set(name, value, days = 7) {
14
+ let expires = "";
15
+ if (days) {
16
+ let date = new Date();
17
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
18
+ expires = "; expires=" + date.toUTCString();
19
+ }
20
+ document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
21
+ },
22
+
23
+ delete(name) {
24
+ document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
25
+ }
26
+ };
27
+
28
+ export const storage = {
29
+ get(key, defaulting = null) {
30
+ return JSON.parse(localStorage.getItem(key)) || defaulting;
31
+ },
32
+
33
+ set(key, data) {
34
+ localStorage.setItem(key, JSON.stringify(data));
35
+ },
36
+
37
+ delete(key) {
38
+ localStorage.removeItem(key);
39
+ }
40
+ };