aprog 1.7.6 → 1.7.8

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/index.js CHANGED
@@ -10,7 +10,8 @@ export { redirect, reload, validateEmail, validatePassword } from './src/redirec
10
10
  export { router, navigateTo, navi } from './src/router.js';
11
11
  export { encrypt, decrypt } from './src/shifrator.js';
12
12
  export { gemini } from './src/OpenAI.js';
13
- export { mathInput } from './src/math.js';
13
+ export { mathInput, autoPPI } from './src/math.js';
14
14
  export { cookie, storage } from './src/storage.js';
15
15
  export { paginate, parseData } from './src/paginate.js';
16
16
  export { saveItem, loadItem, setSecretKey } from './src/secretStorage.js';
17
+ export { pushHTMLElementPrototype } from './src/window.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aprog",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "Допоміжна бібліотека js",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/math.js CHANGED
@@ -14,4 +14,42 @@ export const mathInput = (target) => {
14
14
  }
15
15
 
16
16
  return result;
17
- }
17
+ }
18
+
19
+ /**
20
+ * Автоматичне обчислення PPI
21
+ * @param {Object} params
22
+ * @param {number} [params.widthPx] - ширина в пікселях
23
+ * @param {number} [params.heightPx] - висота в пікселях
24
+ * @param {number|null} [params.diagonalInch] - діагональ в дюймах
25
+ * @param {number|null} [params.widthMm] - фізична ширина в міліметрах
26
+ * @param {number|null} [params.heightMm] - фізична висота в міліметрах
27
+ * @returns {number} PPI
28
+ */
29
+ export const autoPPI = ({
30
+ widthPx = window.screen.width * window.devicePixelRatio,
31
+ heightPx = window.screen.height * window.devicePixelRatio,
32
+ diagonalInch = null,
33
+ widthMm = null,
34
+ heightMm = null
35
+ } = {}) => {
36
+ // Якщо є фізичні розміри — обчислюємо діагональ у дюймах
37
+ if (!diagonalInch && widthMm && heightMm) {
38
+ const widthInch = widthMm / 25.4;
39
+ const heightInch = heightMm / 25.4;
40
+ diagonalInch = Math.sqrt(widthInch ** 2 + heightInch ** 2);
41
+ }
42
+
43
+ // Якщо все ще нема діагоналі — питаємо
44
+ if (!diagonalInch) {
45
+ const input = prompt('Введи діагональ екрана в дюймах:');
46
+ diagonalInch = parseFloat(input);
47
+ }
48
+
49
+ if (![widthPx, heightPx, diagonalInch].every(n => typeof n === 'number' && n > 0)) {
50
+ throw new Error('Недостатньо даних для обчислення PPI');
51
+ }
52
+
53
+ const pixelDiagonal = Math.sqrt(widthPx ** 2 + heightPx ** 2);
54
+ return +(pixelDiagonal / diagonalInch).toFixed(2);
55
+ };
package/src/redirect.js CHANGED
@@ -1,10 +1,17 @@
1
- export const redirect = (url, { newTab = false, replace = false } = {}) => {
1
+ export const redirect = (url, {
2
+ newTab = false,
3
+ replace = false,
4
+ props = {}
5
+ } = {}) => {
6
+ const query = new URLSearchParams(props).toString();
7
+ const finalUrl = query ? `${url}?${query}` : url;
8
+
2
9
  if (newTab) {
3
- window.open(url, "_blank");
10
+ window.open(finalUrl, "_blank");
4
11
  } else if (replace) {
5
- window.location.replace(url);
12
+ window.location.replace(finalUrl);
6
13
  } else {
7
- window.location.href = url;
14
+ window.location.href = finalUrl;
8
15
  }
9
16
  };
10
17
 
package/src/window.js ADDED
@@ -0,0 +1,10 @@
1
+ export function pushHTMLElementPrototype() {
2
+ if (!HTMLElement.prototype.push) {
3
+ HTMLElement.prototype.push = function(element) {
4
+ this.innerHTML = null;
5
+ this.append(element);
6
+ };
7
+ }
8
+ }
9
+
10
+ pushHTMLElementPrototype();