cynx-lib 1.3.101 → 1.3.102

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/gen.js +77 -77
  2. package/package.json +1 -1
  3. package/ui/components/ActionsMenu.jsx +357 -357
  4. package/ui/components/Drawer.jsx +208 -208
  5. package/ui/components/Globe.jsx +764 -0
  6. package/ui/components/HoverCard.jsx +85 -85
  7. package/ui/components/Input.jsx +54 -4
  8. package/ui/components/Pagination.jsx +145 -145
  9. package/ui/components/PrivacyBlur.jsx +603 -603
  10. package/ui/components/XTable.jsx +112 -112
  11. package/ui/index.cjs +5 -0
  12. package/ui/index.js +3 -0
  13. package/utils/index.js +24 -24
  14. package/utils/utils/duration.js +139 -139
  15. package/utils/utils/oidc.js +214 -214
  16. package/utils/utils/realtime.js +1634 -1634
  17. package/utils/utils/server.js +371 -371
  18. package/utils/utils/session.js +131 -131
  19. package/utils/utils/session_manager.js +580 -580
  20. package/utils/utils/sso_manager.js +702 -702
  21. package/utils/utils/storage.js +393 -393
  22. package/utils/utils/ui.js +111 -111
  23. package/vue/components/Badge.vue +79 -79
  24. package/vue/components/Button.vue +209 -209
  25. package/vue/components/Checkbox.vue +103 -103
  26. package/vue/components/CircularProgress.vue +383 -383
  27. package/vue/components/Divider.vue +94 -94
  28. package/vue/components/Drawer.vue +243 -243
  29. package/vue/components/InfoBadge.vue +223 -223
  30. package/vue/components/Input.vue +341 -341
  31. package/vue/components/LinearProgress.vue +268 -268
  32. package/vue/components/Modal.vue +226 -226
  33. package/vue/components/Pagination.vue +199 -199
  34. package/vue/components/Select.vue +713 -713
  35. package/vue/components/Sidebar.vue +955 -955
  36. package/vue/components/Skeleton.vue +91 -91
  37. package/vue/components/Spinner.vue +263 -263
  38. package/vue/components/StatusTag.vue +89 -89
  39. package/vue/components/TabBar.vue +176 -176
  40. package/vue/components/Table.vue +388 -388
  41. package/vue/components/TimePicker.vue +399 -399
  42. package/vue/components/Toggle.vue +115 -115
  43. package/vue/components/XTable.vue +140 -140
  44. package/vue/composables/useAutoSkeletonRows.ts +71 -71
  45. package/vue/index.d.ts +67 -67
  46. package/vue/index.js +86 -86
@@ -1,112 +1,112 @@
1
- const TABLE_STYLES = `
2
- table.cynx-table {
3
- width: 100%;
4
- border-collapse: collapse;
5
- table-layout: fixed;
6
- font-size: .8rem;
7
- }
8
- .cynx-tr {
9
- border-bottom: 1px solid var(--border-light, #ebebf0);
10
- transition: background .12s;
11
- }
12
- tbody tr.cynx-tr:last-child,
13
- .cynx-table tbody tr:last-child {
14
- border-bottom: none;
15
- }
16
- @keyframes shimmer{0%{background-position:-600px 0}100%{background-position:600px 0}}
17
- @keyframes sk-shimmer{0%{background-position:-600px 0}100%{background-position:600px 0}}
18
- `;
19
-
20
- let _tbl_style_id = 'cynx-table-styles';
21
- function ensureTableStyles() {
22
- if (typeof document === 'undefined') return;
23
- if (document.getElementById(_tbl_style_id)) return;
24
- const tag = document.createElement('style');
25
- tag.id = _tbl_style_id;
26
- tag.textContent = TABLE_STYLES;
27
- document.head.appendChild(tag);
28
- }
29
- if (typeof document !== 'undefined') ensureTableStyles();
30
-
31
- export function XTable({ children, style, className = '', ...props }) {
32
- ensureTableStyles();
33
- return (
34
- <table
35
- className={`cynx-table ${className}`.trim()}
36
- style={{ width: '100%', borderCollapse: 'collapse', tableLayout: 'fixed', fontSize: '.8rem', ...style }}
37
- {...props}
38
- >
39
- {children}
40
- </table>
41
- );
42
- }
43
-
44
- export function XThead({ children, ...props }) { return <thead {...props}>{children}</thead>; }
45
- export function XTbody({ children, ...props }) { return <tbody {...props}>{children}</tbody>; }
46
-
47
- export function XTr({ children, onClick, style, className = '', ...props }) {
48
- ensureTableStyles();
49
- return (
50
- <tr
51
- onClick={onClick}
52
- className={`cynx-tr ${className}`.trim()}
53
- style={{
54
- cursor: onClick ? 'pointer' : undefined,
55
- ...style,
56
- }}
57
- {...props}
58
- >
59
- {children}
60
- </tr>
61
- );
62
- }
63
-
64
- export function XTh({ children, style, className = '', ...props }) {
65
- return (
66
- <th
67
- className={className}
68
- style={{
69
- textAlign: 'left',
70
- padding: '8px 10px',
71
- fontSize: '.68rem',
72
- fontWeight: 600,
73
- textTransform: 'uppercase',
74
- letterSpacing: '.06em',
75
- color: 'var(--muted, #9b9daa)',
76
- borderBottom: '1px solid var(--border-light, #ebebf0)',
77
- ...style,
78
- }}
79
- {...props}
80
- >
81
- {children}
82
- </th>
83
- );
84
- }
85
-
86
- export function XTd({ children, style, className = '', colSpan, ...props }) {
87
- return (
88
- <td
89
- className={className}
90
- style={{ padding: '9px 10px', verticalAlign: 'middle', color: 'var(--primary-text, #0f111c)', ...style }}
91
- colSpan={colSpan}
92
- {...props}
93
- >
94
- {children}
95
- </td>
96
- );
97
- }
98
-
99
- export function SkeletonTable({ rows = 6, cols = 5 }) {
100
- ensureTableStyles();
101
- return (
102
- <div>
103
- {Array.from({ length: rows }).map((_, i) => (
104
- <div key={i} style={{ display: 'flex', gap: 8, padding: '8px 10px', borderBottom: i === rows - 1 ? 'none' : '1px solid var(--border-light, #ebebf0)' }}>
105
- {Array.from({ length: cols }).map((_, j) => (
106
- <div key={j} style={{ height: 12, flex: 1, background: 'linear-gradient(90deg, var(--grey-1, #f5f5f8) 25%, var(--border-light, #ebebf0) 50%, var(--grey-1, #f5f5f8) 75%)', backgroundSize: '600px 100%', animation: 'shimmer 1.4s ease infinite', borderRadius: 'var(--radxs, 6px)' }} />
107
- ))}
108
- </div>
109
- ))}
110
- </div>
111
- );
112
- }
1
+ const TABLE_STYLES = `
2
+ table.cynx-table {
3
+ width: 100%;
4
+ border-collapse: collapse;
5
+ table-layout: fixed;
6
+ font-size: .8rem;
7
+ }
8
+ .cynx-tr {
9
+ border-bottom: 1px solid var(--border-light, #ebebf0);
10
+ transition: background .12s;
11
+ }
12
+ tbody tr.cynx-tr:last-child,
13
+ .cynx-table tbody tr:last-child {
14
+ border-bottom: none;
15
+ }
16
+ @keyframes shimmer{0%{background-position:-600px 0}100%{background-position:600px 0}}
17
+ @keyframes sk-shimmer{0%{background-position:-600px 0}100%{background-position:600px 0}}
18
+ `;
19
+
20
+ let _tbl_style_id = 'cynx-table-styles';
21
+ function ensureTableStyles() {
22
+ if (typeof document === 'undefined') return;
23
+ if (document.getElementById(_tbl_style_id)) return;
24
+ const tag = document.createElement('style');
25
+ tag.id = _tbl_style_id;
26
+ tag.textContent = TABLE_STYLES;
27
+ document.head.appendChild(tag);
28
+ }
29
+ if (typeof document !== 'undefined') ensureTableStyles();
30
+
31
+ export function XTable({ children, style, className = '', ...props }) {
32
+ ensureTableStyles();
33
+ return (
34
+ <table
35
+ className={`cynx-table ${className}`.trim()}
36
+ style={{ width: '100%', borderCollapse: 'collapse', tableLayout: 'fixed', fontSize: '.8rem', ...style }}
37
+ {...props}
38
+ >
39
+ {children}
40
+ </table>
41
+ );
42
+ }
43
+
44
+ export function XThead({ children, ...props }) { return <thead {...props}>{children}</thead>; }
45
+ export function XTbody({ children, ...props }) { return <tbody {...props}>{children}</tbody>; }
46
+
47
+ export function XTr({ children, onClick, style, className = '', ...props }) {
48
+ ensureTableStyles();
49
+ return (
50
+ <tr
51
+ onClick={onClick}
52
+ className={`cynx-tr ${className}`.trim()}
53
+ style={{
54
+ cursor: onClick ? 'pointer' : undefined,
55
+ ...style,
56
+ }}
57
+ {...props}
58
+ >
59
+ {children}
60
+ </tr>
61
+ );
62
+ }
63
+
64
+ export function XTh({ children, style, className = '', ...props }) {
65
+ return (
66
+ <th
67
+ className={className}
68
+ style={{
69
+ textAlign: 'left',
70
+ padding: '8px 10px',
71
+ fontSize: '.68rem',
72
+ fontWeight: 600,
73
+ textTransform: 'uppercase',
74
+ letterSpacing: '.06em',
75
+ color: 'var(--muted, #9b9daa)',
76
+ borderBottom: '1px solid var(--border-light, #ebebf0)',
77
+ ...style,
78
+ }}
79
+ {...props}
80
+ >
81
+ {children}
82
+ </th>
83
+ );
84
+ }
85
+
86
+ export function XTd({ children, style, className = '', colSpan, ...props }) {
87
+ return (
88
+ <td
89
+ className={className}
90
+ style={{ padding: '9px 10px', verticalAlign: 'middle', color: 'var(--primary-text, #0f111c)', ...style }}
91
+ colSpan={colSpan}
92
+ {...props}
93
+ >
94
+ {children}
95
+ </td>
96
+ );
97
+ }
98
+
99
+ export function SkeletonTable({ rows = 6, cols = 5 }) {
100
+ ensureTableStyles();
101
+ return (
102
+ <div>
103
+ {Array.from({ length: rows }).map((_, i) => (
104
+ <div key={i} style={{ display: 'flex', gap: 8, padding: '8px 10px', borderBottom: i === rows - 1 ? 'none' : '1px solid var(--border-light, #ebebf0)' }}>
105
+ {Array.from({ length: cols }).map((_, j) => (
106
+ <div key={j} style={{ height: 12, flex: 1, background: 'linear-gradient(90deg, var(--grey-1, #f5f5f8) 25%, var(--border-light, #ebebf0) 50%, var(--grey-1, #f5f5f8) 75%)', backgroundSize: '600px 100%', animation: 'shimmer 1.4s ease infinite', borderRadius: 'var(--radxs, 6px)' }} />
107
+ ))}
108
+ </div>
109
+ ))}
110
+ </div>
111
+ );
112
+ }
package/ui/index.cjs CHANGED
@@ -44,6 +44,7 @@ __export(index_exports, {
44
44
  Drawer: () => Drawer,
45
45
  Dropzone: () => Dropzone,
46
46
  FilePicker: () => FilePicker,
47
+ Globe: () => Globe,
47
48
  HoverCard: () => HoverCard,
48
49
  ImageUpload: () => ImageUpload,
49
50
  InfoBadge: () => InfoBadge,
@@ -87,6 +88,7 @@ __export(index_exports, {
87
88
  XThead: () => XThead,
88
89
  XTr: () => XTr,
89
90
  confirm: () => confirm,
91
+ createGlobe: () => createGlobe,
90
92
  toast: () => toast,
91
93
  useToast: () => useToast
92
94
  });
@@ -133,6 +135,7 @@ var import_Layout = __toESM(require("./components/Layout.jsx"), 1);
133
135
  var import_Sidebar = __toESM(require("./components/Sidebar.jsx"), 1);
134
136
  var import_LoginPage = __toESM(require("./components/LoginPage.jsx"), 1);
135
137
  var import_PrivacyBlur = __toESM(require("./components/PrivacyBlur.jsx"), 1);
138
+ var import_Globe = __toESM(require("./components/Globe.jsx"), 1);
136
139
  const Layout = import_Layout.default;
137
140
  const Sidebar = import_Sidebar.default;
138
141
  const LoginPage = import_LoginPage.default;
@@ -195,3 +198,5 @@ const CardHdr = import_Card.CardHdr;
195
198
  const StatCard = import_Card.StatCard;
196
199
  const StatCardSkeleton = import_Card.StatCardSkeleton;
197
200
  const PrivacyBlur = import_PrivacyBlur.default;
201
+ const Globe = import_Globe.default || import_Globe.Globe;
202
+ const createGlobe = import_Globe.createGlobe;
package/ui/index.js CHANGED
@@ -42,6 +42,7 @@ import { default as _Layout } from './components/Layout.jsx';
42
42
  import { default as _Sidebar } from './components/Sidebar.jsx';
43
43
  import { default as _LoginPage } from './components/LoginPage.jsx';
44
44
  import { default as _PrivacyBlur } from './components/PrivacyBlur.jsx';
45
+ import { default as _Globe, createGlobe as _createGlobe, Globe as _GlobeNamed } from './components/Globe.jsx';
45
46
 
46
47
  export const Layout = _Layout;
47
48
  export const Sidebar = _Sidebar;
@@ -105,3 +106,5 @@ export const CardHdr = _CardHdr;
105
106
  export const StatCard = _StatCard;
106
107
  export const StatCardSkeleton = _StatCardSkeleton;
107
108
  export const PrivacyBlur = _PrivacyBlur;
109
+ export const Globe = _Globe || _GlobeNamed;
110
+ export const createGlobe = _createGlobe;
package/utils/index.js CHANGED
@@ -1,24 +1,24 @@
1
- // cynx/utils — shared utility functions
2
- export * from './utils/uid.js';
3
- export * from './utils/realtime.js';
4
- export * from './utils/tz.js';
5
- export * from './utils/oidc.js';
6
- export * from './utils/storage.js';
7
- export * from './utils/duration.js';
8
- export * from './utils/session.js';
9
- export * from './utils/session_manager.js';
10
- export * from './utils/sso_manager.js';
11
- export * from './utils/ui.js';
12
- export * from './utils/db.js';
13
-
14
- export { default as uidUtil } from './utils/uid.js';
15
- export { default as realtimeUtil } from './utils/realtime.js';
16
- export { default as tzUtil } from './utils/tz.js';
17
- export { default as oidcUtil } from './utils/oidc.js';
18
- export { default as storageUtil } from './utils/storage.js';
19
- export { default as durationUtil } from './utils/duration.js';
20
- export { default as sessionUtil } from './utils/session.js';
21
- export { default as sessionManagerUtil } from './utils/session_manager.js';
22
- export { default as ssoManagerUtil } from './utils/sso_manager.js';
23
- export { default as uiUtil } from './utils/ui.js';
24
- export { default as dbUtil } from './utils/db.js';
1
+ // cynx/utils — shared utility functions
2
+ export * from './utils/uid.js';
3
+ export * from './utils/realtime.js';
4
+ export * from './utils/tz.js';
5
+ export * from './utils/oidc.js';
6
+ export * from './utils/storage.js';
7
+ export * from './utils/duration.js';
8
+ export * from './utils/session.js';
9
+ export * from './utils/session_manager.js';
10
+ export * from './utils/sso_manager.js';
11
+ export * from './utils/ui.js';
12
+ export * from './utils/db.js';
13
+
14
+ export { default as uidUtil } from './utils/uid.js';
15
+ export { default as realtimeUtil } from './utils/realtime.js';
16
+ export { default as tzUtil } from './utils/tz.js';
17
+ export { default as oidcUtil } from './utils/oidc.js';
18
+ export { default as storageUtil } from './utils/storage.js';
19
+ export { default as durationUtil } from './utils/duration.js';
20
+ export { default as sessionUtil } from './utils/session.js';
21
+ export { default as sessionManagerUtil } from './utils/session_manager.js';
22
+ export { default as ssoManagerUtil } from './utils/sso_manager.js';
23
+ export { default as uiUtil } from './utils/ui.js';
24
+ export { default as dbUtil } from './utils/db.js';
@@ -1,139 +1,139 @@
1
- /**
2
- * cynx/utils — Duration Parser and Formatter (duration.js)
3
- *
4
- * Universal utility for parsing human-readable duration strings (e.g. '15m', '2h', '3d', '1w', '1mo')
5
- * into seconds or milliseconds, and formatting durations into short tags or localized labels.
6
- *
7
- * Works across Browser and Node.js environments.
8
- */
9
-
10
- /**
11
- * Parse a human-readable duration string or number into seconds.
12
- * Supported units:
13
- * - s : seconds (e.g. '30s', '45s')
14
- * - m : minutes (e.g. '1m', '5m', '15m', '30m')
15
- * - h : hours (e.g. '1h', '5h', '12h', '24h')
16
- * - d : days (e.g. '1d', '3d', '7d')
17
- * - w : weeks (e.g. '1w', '2w')
18
- * - mo : months (e.g. '1mo', '3mo', treated as 30 days)
19
- *
20
- * @param {string|number} input
21
- * @param {number} [minSeconds=60] Minimum allowed seconds
22
- * @returns {number} Seconds
23
- */
24
- export function parseDurationToSeconds(input, minSeconds = 60) {
25
- if (input === null || input === undefined || input === '') {
26
- return minSeconds;
27
- }
28
-
29
- if (typeof input === 'number') {
30
- if (isNaN(input) || input <= 0) return minSeconds;
31
- return Math.max(minSeconds, Math.round(input));
32
- }
33
-
34
- const str = String(input).trim().toLowerCase();
35
-
36
- // If plain digits string: '300'
37
- if (/^\d+$/.test(str)) {
38
- const num = parseInt(str, 10);
39
- return Math.max(minSeconds, num);
40
- }
41
-
42
- // Match number + unit: '15m', '2h', '1mo', '3d', '1w', '45s'
43
- const match = str.match(/^(\d+(?:\.\d+)?)\s*(mo|w|d|h|m|s)?$/);
44
- if (!match) {
45
- return minSeconds;
46
- }
47
-
48
- const val = parseFloat(match[1]);
49
- const unit = match[2] || 's';
50
-
51
- let totalSec = 0;
52
- switch (unit) {
53
- case 'mo':
54
- totalSec = val * 30 * 86400; // 30 days
55
- break;
56
- case 'w':
57
- totalSec = val * 7 * 86400; // 7 days
58
- break;
59
- case 'd':
60
- totalSec = val * 86400;
61
- break;
62
- case 'h':
63
- totalSec = val * 3600;
64
- break;
65
- case 'm':
66
- totalSec = val * 60;
67
- break;
68
- case 's':
69
- default:
70
- totalSec = val;
71
- break;
72
- }
73
-
74
- const rounded = Math.round(totalSec);
75
- return Math.max(minSeconds, rounded);
76
- }
77
-
78
- /**
79
- * Parse a human-readable duration string into milliseconds.
80
- *
81
- * @param {string|number} val
82
- * @param {number} [defaultMs=2592000000] Default ms (30 days)
83
- * @returns {number} Milliseconds
84
- */
85
- export function parseDurationMs(val, defaultMs = 30 * 24 * 60 * 60 * 1000) {
86
- if (!val || val === 'off' || val === '0' || val === 0) return 0;
87
- if (typeof val === 'number') return val > 0 ? val : defaultMs;
88
- const str = String(val).trim().toLowerCase();
89
- const match = str.match(/^(\d+(?:\.\d+)?)\s*([a-z]+)?$/);
90
- if (!match) return defaultMs;
91
- const num = parseFloat(match[1]);
92
- const unit = match[2] || 'd';
93
- if (unit.startsWith('s')) return Math.round(num * 1000);
94
- if (unit.startsWith('m')) return Math.round(num * 60 * 1000);
95
- if (unit.startsWith('h')) return Math.round(num * 60 * 60 * 1000);
96
- if (unit.startsWith('d')) return Math.round(num * 24 * 60 * 60 * 1000);
97
- if (unit.startsWith('w')) return Math.round(num * 7 * 24 * 60 * 60 * 1000);
98
- return defaultMs;
99
- }
100
-
101
- /**
102
- * Format seconds into a short clean tag (e.g. '1m', '5m', '1h', '24h', '1w', '1mo').
103
- * @param {number} seconds
104
- * @returns {string} Short duration string
105
- */
106
- export function formatDurationTag(seconds) {
107
- const s = Number(seconds) || 60;
108
- if (s >= 2592000 && s % 2592000 === 0) return `${s / 2592000}mo`;
109
- if (s >= 604800 && s % 604800 === 0) return `${s / 604800}w`;
110
- if (s >= 86400 && s % 86400 === 0) return `${s / 86400}d`;
111
- if (s >= 3600 && s % 3600 === 0) return `${s / 3600}h`;
112
- if (s >= 60 && s % 60 === 0) return `${s / 60}m`;
113
- return `${s}s`;
114
- }
115
-
116
- /**
117
- * Format seconds into human readable label.
118
- * @param {number} seconds
119
- * @returns {string} Human readable label
120
- */
121
- export function formatDurationLabel(seconds) {
122
- const s = Number(seconds) || 60;
123
- if (s === 60) return '1 мин';
124
- if (s === 300) return '5 мин';
125
- if (s === 600) return '10 мин';
126
- if (s === 1800) return '30 мин';
127
- if (s === 3600) return '1 час';
128
- if (s === 18000) return '5 часов';
129
- if (s === 43200) return '12 часов';
130
- if (s === 86400) return '24 часа';
131
- return formatDurationTag(s);
132
- }
133
-
134
- export default {
135
- parseDurationToSeconds,
136
- parseDurationMs,
137
- formatDurationTag,
138
- formatDurationLabel,
139
- };
1
+ /**
2
+ * cynx/utils — Duration Parser and Formatter (duration.js)
3
+ *
4
+ * Universal utility for parsing human-readable duration strings (e.g. '15m', '2h', '3d', '1w', '1mo')
5
+ * into seconds or milliseconds, and formatting durations into short tags or localized labels.
6
+ *
7
+ * Works across Browser and Node.js environments.
8
+ */
9
+
10
+ /**
11
+ * Parse a human-readable duration string or number into seconds.
12
+ * Supported units:
13
+ * - s : seconds (e.g. '30s', '45s')
14
+ * - m : minutes (e.g. '1m', '5m', '15m', '30m')
15
+ * - h : hours (e.g. '1h', '5h', '12h', '24h')
16
+ * - d : days (e.g. '1d', '3d', '7d')
17
+ * - w : weeks (e.g. '1w', '2w')
18
+ * - mo : months (e.g. '1mo', '3mo', treated as 30 days)
19
+ *
20
+ * @param {string|number} input
21
+ * @param {number} [minSeconds=60] Minimum allowed seconds
22
+ * @returns {number} Seconds
23
+ */
24
+ export function parseDurationToSeconds(input, minSeconds = 60) {
25
+ if (input === null || input === undefined || input === '') {
26
+ return minSeconds;
27
+ }
28
+
29
+ if (typeof input === 'number') {
30
+ if (isNaN(input) || input <= 0) return minSeconds;
31
+ return Math.max(minSeconds, Math.round(input));
32
+ }
33
+
34
+ const str = String(input).trim().toLowerCase();
35
+
36
+ // If plain digits string: '300'
37
+ if (/^\d+$/.test(str)) {
38
+ const num = parseInt(str, 10);
39
+ return Math.max(minSeconds, num);
40
+ }
41
+
42
+ // Match number + unit: '15m', '2h', '1mo', '3d', '1w', '45s'
43
+ const match = str.match(/^(\d+(?:\.\d+)?)\s*(mo|w|d|h|m|s)?$/);
44
+ if (!match) {
45
+ return minSeconds;
46
+ }
47
+
48
+ const val = parseFloat(match[1]);
49
+ const unit = match[2] || 's';
50
+
51
+ let totalSec = 0;
52
+ switch (unit) {
53
+ case 'mo':
54
+ totalSec = val * 30 * 86400; // 30 days
55
+ break;
56
+ case 'w':
57
+ totalSec = val * 7 * 86400; // 7 days
58
+ break;
59
+ case 'd':
60
+ totalSec = val * 86400;
61
+ break;
62
+ case 'h':
63
+ totalSec = val * 3600;
64
+ break;
65
+ case 'm':
66
+ totalSec = val * 60;
67
+ break;
68
+ case 's':
69
+ default:
70
+ totalSec = val;
71
+ break;
72
+ }
73
+
74
+ const rounded = Math.round(totalSec);
75
+ return Math.max(minSeconds, rounded);
76
+ }
77
+
78
+ /**
79
+ * Parse a human-readable duration string into milliseconds.
80
+ *
81
+ * @param {string|number} val
82
+ * @param {number} [defaultMs=2592000000] Default ms (30 days)
83
+ * @returns {number} Milliseconds
84
+ */
85
+ export function parseDurationMs(val, defaultMs = 30 * 24 * 60 * 60 * 1000) {
86
+ if (!val || val === 'off' || val === '0' || val === 0) return 0;
87
+ if (typeof val === 'number') return val > 0 ? val : defaultMs;
88
+ const str = String(val).trim().toLowerCase();
89
+ const match = str.match(/^(\d+(?:\.\d+)?)\s*([a-z]+)?$/);
90
+ if (!match) return defaultMs;
91
+ const num = parseFloat(match[1]);
92
+ const unit = match[2] || 'd';
93
+ if (unit.startsWith('s')) return Math.round(num * 1000);
94
+ if (unit.startsWith('m')) return Math.round(num * 60 * 1000);
95
+ if (unit.startsWith('h')) return Math.round(num * 60 * 60 * 1000);
96
+ if (unit.startsWith('d')) return Math.round(num * 24 * 60 * 60 * 1000);
97
+ if (unit.startsWith('w')) return Math.round(num * 7 * 24 * 60 * 60 * 1000);
98
+ return defaultMs;
99
+ }
100
+
101
+ /**
102
+ * Format seconds into a short clean tag (e.g. '1m', '5m', '1h', '24h', '1w', '1mo').
103
+ * @param {number} seconds
104
+ * @returns {string} Short duration string
105
+ */
106
+ export function formatDurationTag(seconds) {
107
+ const s = Number(seconds) || 60;
108
+ if (s >= 2592000 && s % 2592000 === 0) return `${s / 2592000}mo`;
109
+ if (s >= 604800 && s % 604800 === 0) return `${s / 604800}w`;
110
+ if (s >= 86400 && s % 86400 === 0) return `${s / 86400}d`;
111
+ if (s >= 3600 && s % 3600 === 0) return `${s / 3600}h`;
112
+ if (s >= 60 && s % 60 === 0) return `${s / 60}m`;
113
+ return `${s}s`;
114
+ }
115
+
116
+ /**
117
+ * Format seconds into human readable label.
118
+ * @param {number} seconds
119
+ * @returns {string} Human readable label
120
+ */
121
+ export function formatDurationLabel(seconds) {
122
+ const s = Number(seconds) || 60;
123
+ if (s === 60) return '1 мин';
124
+ if (s === 300) return '5 мин';
125
+ if (s === 600) return '10 мин';
126
+ if (s === 1800) return '30 мин';
127
+ if (s === 3600) return '1 час';
128
+ if (s === 18000) return '5 часов';
129
+ if (s === 43200) return '12 часов';
130
+ if (s === 86400) return '24 часа';
131
+ return formatDurationTag(s);
132
+ }
133
+
134
+ export default {
135
+ parseDurationToSeconds,
136
+ parseDurationMs,
137
+ formatDurationTag,
138
+ formatDurationLabel,
139
+ };