vgapp 1.4.4 → 1.4.6

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 (123) hide show
  1. package/README.md +270 -270
  2. package/app/langs/en/buttons.json +17 -17
  3. package/app/langs/en/messages.json +36 -36
  4. package/app/langs/ru/buttons.json +17 -17
  5. package/app/langs/ru/messages.json +36 -36
  6. package/app/modules/vgalert/js/vgalert.js +266 -266
  7. package/app/modules/vgalert/scss/_variables.scss +16 -16
  8. package/app/modules/vgalert/scss/vgalert.scss +107 -107
  9. package/app/modules/vgcollapse/scss/_variables.scss +7 -7
  10. package/app/modules/vgcollapse/scss/vgcollapse.scss +5 -5
  11. package/app/modules/vgdropdown/scss/_variables.scss +14 -14
  12. package/app/modules/vgdropdown/scss/vgdropdown.scss +5 -5
  13. package/app/modules/vgdynamictable/index.js +4 -4
  14. package/app/modules/vgdynamictable/js/filters.js +21 -21
  15. package/app/modules/vgdynamictable/js/fixed.js +179 -179
  16. package/app/modules/vgdynamictable/js/options.js +3 -3
  17. package/app/modules/vgdynamictable/js/pagination.js +1 -1
  18. package/app/modules/vgdynamictable/js/search.js +12 -12
  19. package/app/modules/vgdynamictable/js/skeleton.js +27 -19
  20. package/app/modules/vgdynamictable/js/sortable.js +71 -71
  21. package/app/modules/vgdynamictable/js/summary-footer.js +28 -28
  22. package/app/modules/vgdynamictable/js/table-url-state.js +31 -31
  23. package/app/modules/vgdynamictable/js/utils/common.js +48 -48
  24. package/app/modules/vgdynamictable/js/vgdynamictable.js +79 -79
  25. package/app/modules/vgdynamictable/scss/_actions.scss +19 -19
  26. package/app/modules/vgdynamictable/scss/_pagination.scss +5 -5
  27. package/app/modules/vgdynamictable/scss/_skeleton.scss +11 -11
  28. package/app/modules/vgdynamictable/scss/_sortable.scss +28 -28
  29. package/app/modules/vgdynamictable/scss/_table.scss +7 -30
  30. package/app/modules/vgdynamictable/scss/_variables.scss +46 -46
  31. package/app/modules/vgdynamictable/scss/vgdynamictable.scss +28 -36
  32. package/app/modules/vgfilepreview/js/i18n.js +56 -56
  33. package/app/modules/vgfilepreview/js/renderers/image-modal.js +145 -145
  34. package/app/modules/vgfilepreview/js/renderers/image.js +92 -92
  35. package/app/modules/vgfilepreview/js/renderers/index.js +19 -19
  36. package/app/modules/vgfilepreview/js/renderers/office-modal.js +168 -168
  37. package/app/modules/vgfilepreview/js/renderers/office.js +79 -79
  38. package/app/modules/vgfilepreview/js/renderers/pdf-modal.js +260 -260
  39. package/app/modules/vgfilepreview/js/renderers/pdf.js +76 -76
  40. package/app/modules/vgfilepreview/js/renderers/playlist.js +71 -71
  41. package/app/modules/vgfilepreview/js/renderers/text-modal.js +343 -343
  42. package/app/modules/vgfilepreview/js/renderers/text.js +83 -83
  43. package/app/modules/vgfilepreview/js/renderers/video-modal.js +272 -272
  44. package/app/modules/vgfilepreview/js/renderers/video.js +80 -80
  45. package/app/modules/vgfilepreview/js/renderers/zip-modal.js +522 -522
  46. package/app/modules/vgfilepreview/js/renderers/zip.js +89 -89
  47. package/app/modules/vgfilepreview/js/vgfilepreview.js +7 -7
  48. package/app/modules/vgfilepreview/readme.md +68 -68
  49. package/app/modules/vgfilepreview/scss/_variables.scss +115 -115
  50. package/app/modules/vgfilepreview/scss/vgfilepreview.scss +463 -463
  51. package/app/modules/vgfiles/js/droppable.js +20 -9
  52. package/app/modules/vgfiles/js/render.js +153 -153
  53. package/app/modules/vgfiles/js/vgfiles.js +104 -104
  54. package/app/modules/vgfiles/readme.md +123 -123
  55. package/app/modules/vgfiles/scss/_mixins.scss +9 -9
  56. package/app/modules/vgfiles/scss/_variables.scss +41 -41
  57. package/app/modules/vgfiles/scss/vgfiles.scss +161 -161
  58. package/app/modules/vgformsender/js/hideshowpass.js +21 -16
  59. package/app/modules/vgformsender/js/vgformsender.js +4 -6
  60. package/app/modules/vgformsender/readme.md +1 -1
  61. package/app/modules/vgformsender/scss/_variables.scss +5 -5
  62. package/app/modules/vgformsender/scss/vgformsender.scss +42 -42
  63. package/app/modules/vglawcookie/js/vglawcookie.js +11 -8
  64. package/app/modules/vglawcookie/scss/_variables.scss +13 -13
  65. package/app/modules/vglawcookie/scss/vglawcookie.scss +5 -5
  66. package/app/modules/vgmodal/js/vgmodal.interaction.js +216 -216
  67. package/app/modules/vgmodal/js/vgmodal.js +355 -355
  68. package/app/modules/vgmodal/js/vgmodal.minimized.js +227 -227
  69. package/app/modules/vgmodal/scss/_variables.scss +17 -17
  70. package/app/modules/vgmodal/scss/vgmodal.scss +77 -77
  71. package/app/modules/vgnav/js/vgnav.js +180 -180
  72. package/app/modules/vgnav/scss/_breakpoints.scss +36 -36
  73. package/app/modules/vgnav/scss/_hamburger.scss +5 -5
  74. package/app/modules/vgnav/scss/_placement.scss +5 -5
  75. package/app/modules/vgnav/scss/_toggle.scss +5 -5
  76. package/app/modules/vgnav/scss/_variables.scss +26 -26
  77. package/app/modules/vgnav/scss/vgnav.scss +41 -41
  78. package/app/modules/vgnestable/README.md +39 -39
  79. package/app/modules/vgnestable/js/vgnestable.js +358 -358
  80. package/app/modules/vgnestable/scss/_variables.scss +35 -35
  81. package/app/modules/vgnestable/scss/vgnestable.scss +55 -55
  82. package/app/modules/vgrangeslider/js/skins.js +222 -222
  83. package/app/modules/vgrangeslider/js/vgrangeslider.js +704 -704
  84. package/app/modules/vgrangeslider/scss/_variables.scss +55 -55
  85. package/app/modules/vgrangeslider/scss/vgrangeslider.scss +239 -239
  86. package/app/modules/vgrollup/scss/_variables.scss +15 -15
  87. package/app/modules/vgrollup/scss/vgrollup.scss +6 -6
  88. package/app/modules/vgselect/js/vgselect.js +129 -129
  89. package/app/modules/vgselect/readme.md +11 -11
  90. package/app/modules/vgselect/scss/_variables.scss +50 -50
  91. package/app/modules/vgselect/scss/vgselect.scss +48 -48
  92. package/app/modules/vgsidebar/js/vgsidebar.js +79 -79
  93. package/app/modules/vgsidebar/scss/_variables.scss +10 -10
  94. package/app/modules/vgsidebar/scss/vgsidebar.scss +5 -5
  95. package/app/modules/vgtabs/scss/_variables.scss +23 -23
  96. package/app/modules/vgtabs/scss/vgtabs.scss +5 -5
  97. package/app/modules/vgtoast/scss/_variables.scss +13 -13
  98. package/app/modules/vgtoast/scss/vgtoast.scss +5 -5
  99. package/app/modules/vgtooltip/js/vgtooltip.js +107 -51
  100. package/app/modules/vgtooltip/scss/_variables.scss +10 -10
  101. package/app/modules/vgtooltip/scss/vgtooltip.scss +5 -5
  102. package/app/utils/js/components/audio-metadata.js +240 -240
  103. package/app/utils/js/components/backdrop.js +116 -116
  104. package/app/utils/js/components/file-icon.js +109 -109
  105. package/app/utils/js/components/file-preview.js +304 -304
  106. package/app/utils/js/components/sanitize.js +150 -150
  107. package/app/utils/js/components/video-metadata.js +140 -140
  108. package/app/utils/scss/_backdrop.scss +5 -5
  109. package/app/utils/scss/_theme-default.scss +12 -12
  110. package/app/utils/scss/_theme.scss +7 -7
  111. package/app/utils/scss/_tokens.scss +170 -170
  112. package/app/utils/scss/default.scss +9 -9
  113. package/app/utils/scss/functions.scss +21 -21
  114. package/app/utils/scss/index.scss +4 -4
  115. package/app/utils/scss/mixin.scss +16 -16
  116. package/app/utils/scss/variables.scss +105 -105
  117. package/app/vgapp.js +295 -295
  118. package/build/vgapp.css +1 -1
  119. package/build/vgapp.css.map +1 -1
  120. package/build/vgapp.js +1 -1
  121. package/build/vgapp.js.map +1 -1
  122. package/index.scss +20 -20
  123. package/package.json +4 -2
@@ -1,304 +1,304 @@
1
- const DEFAULT_OPTIONS = {
2
- pathAttribute: 'data-vg-filepreview',
3
- fieldsAttribute: 'data-fields',
4
- validAttribute: 'data-vg-filepreview-valid',
5
- errorAttribute: 'data-vg-filepreview-error',
6
- errorValue: 'invalid-file-path',
7
- fieldAttribute: 'data-vg-filepreview-field',
8
- editableAttribute: 'data-vg-filepreview-editable',
9
- editableFieldsAttribute: 'data-vg-filepreview-editable-fields',
10
- missingFieldsAttribute: 'data-vg-filepreview-missing-fields'
11
- };
12
-
13
- class FilePreviewHelper {
14
- constructor(element, options = {}) {
15
- this._element = element;
16
- this._options = Object.assign({}, DEFAULT_OPTIONS, options);
17
- }
18
-
19
- getFilePath() {
20
- if (!this._element) {
21
- return '';
22
- }
23
-
24
- const filePath = this._element.getAttribute(this._options.pathAttribute);
25
- return typeof filePath === 'string' ? filePath.trim() : '';
26
- }
27
-
28
- getFields() {
29
- if (!this._element) {
30
- return [];
31
- }
32
-
33
- const rawFields = this._element.getAttribute(this._options.fieldsAttribute);
34
- if (typeof rawFields !== 'string' || !rawFields.trim()) {
35
- return [];
36
- }
37
-
38
- return rawFields
39
- .split(',')
40
- .map(field => field.trim())
41
- .filter(field => field && /^[-_a-zA-Z0-9]+$/.test(field));
42
- }
43
-
44
- validateFilePath(path) {
45
- if (!path || path === '#' || /^javascript:/i.test(path)) {
46
- return { isValid: false, fileUrl: null };
47
- }
48
-
49
- try {
50
- const parsed = new URL(path, window.location.origin);
51
- const protocol = parsed.protocol;
52
-
53
- if (!['http:', 'https:', 'blob:', 'data:'].includes(protocol)) {
54
- return { isValid: false, fileUrl: null };
55
- }
56
-
57
- if (protocol === 'data:' || protocol === 'blob:') {
58
- return { isValid: true, fileUrl: parsed };
59
- }
60
-
61
- const pathname = parsed.pathname || '';
62
- const fileName = pathname.split('/').filter(Boolean).pop() || '';
63
- if (!fileName || !fileName.includes('.')) {
64
- return { isValid: false, fileUrl: null };
65
- }
66
-
67
- return { isValid: true, fileUrl: parsed };
68
- } catch {
69
- return { isValid: false, fileUrl: null };
70
- }
71
- }
72
-
73
- syncState(isValid) {
74
- if (!this._element) {
75
- return;
76
- }
77
-
78
- this._element.setAttribute(this._options.validAttribute, isValid ? 'true' : 'false');
79
-
80
- if (isValid) {
81
- this._element.removeAttribute(this._options.errorAttribute);
82
- return;
83
- }
84
-
85
- this._element.setAttribute(this._options.errorAttribute, this._options.errorValue);
86
- }
87
-
88
- resolveEditableFields(fields = []) {
89
- if (!this._element || !Array.isArray(fields) || !fields.length) {
90
- return {};
91
- }
92
-
93
- return fields.reduce((acc, field) => {
94
- acc[field] = this._element.querySelector(`.${this._escapeClassName(field)}`);
95
- return acc;
96
- }, {});
97
- }
98
-
99
- syncEditableFields(fieldsMap = {}) {
100
- if (!this._element) {
101
- return;
102
- }
103
-
104
- const previousMarkedFields = this._element.querySelectorAll(`[${this._options.fieldAttribute}]`);
105
- previousMarkedFields.forEach((node) => {
106
- node.removeAttribute(this._options.fieldAttribute);
107
- node.setAttribute(this._options.editableAttribute, 'false');
108
- });
109
-
110
- const editableFields = [];
111
- const missingFields = [];
112
-
113
- Object.entries(fieldsMap).forEach(([field, node]) => {
114
- if (!node) {
115
- missingFields.push(field);
116
- return;
117
- }
118
-
119
- node.setAttribute(this._options.fieldAttribute, field);
120
- node.setAttribute(this._options.editableAttribute, 'true');
121
- editableFields.push(field);
122
- });
123
-
124
- if (editableFields.length) {
125
- this._element.setAttribute(this._options.editableFieldsAttribute, editableFields.join(','));
126
- } else {
127
- this._element.removeAttribute(this._options.editableFieldsAttribute);
128
- }
129
-
130
- if (missingFields.length) {
131
- this._element.setAttribute(this._options.missingFieldsAttribute, missingFields.join(','));
132
- } else {
133
- this._element.removeAttribute(this._options.missingFieldsAttribute);
134
- }
135
- }
136
-
137
- _escapeClassName(value) {
138
- if (window.CSS && typeof window.CSS.escape === 'function') {
139
- return window.CSS.escape(value);
140
- }
141
-
142
- return String(value).replace(/([ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, '\\$1');
143
- }
144
-
145
- getFileMeta(path) {
146
- const normalizedPath = typeof path === 'string' ? path.trim() : '';
147
- const fallback = {
148
- name: '',
149
- ext: '',
150
- originalName: '',
151
- isMedia: false,
152
- sizeBytes: null,
153
- sizeText: ''
154
- };
155
-
156
- if (!normalizedPath) {
157
- return fallback;
158
- }
159
-
160
- try {
161
- const parsedUrl = new URL(normalizedPath, window.location.origin);
162
- const pathname = parsedUrl.pathname || '';
163
- const params = parsedUrl.searchParams;
164
- const originalName = this._readOriginalName(params);
165
- let fileName = decodeURIComponent(pathname.split('/').pop() || '');
166
-
167
- // blob/data urls often do not contain real filename; prefer explicit original name
168
- if (!fileName || !fileName.includes('.')) {
169
- fileName = originalName || fileName;
170
- }
171
-
172
- const ext = fileName.includes('.') ? `.${fileName.split('.').pop() || ''}` : '';
173
- const sizeBytes = this._readSize(params);
174
- const mediaByExt = ['.mp3', '.wav', '.ogg', '.flac', '.aac', '.m4a', '.mp4', '.webm', '.mov', '.mkv', '.avi'];
175
-
176
- return {
177
- name: fileName,
178
- ext: ext.toLowerCase(),
179
- originalName,
180
- isMedia: mediaByExt.includes(ext.toLowerCase()),
181
- sizeBytes,
182
- sizeText: this._formatSize(sizeBytes)
183
- };
184
- } catch {
185
- const cleanPath = normalizedPath.split('#')[0].split('?')[0];
186
- let fileName = decodeURIComponent(cleanPath.split('/').pop() || '');
187
- const originalName = this._readOriginalName(null);
188
- if (!fileName || !fileName.includes('.')) {
189
- fileName = originalName || fileName;
190
- }
191
- const ext = fileName.includes('.') ? `.${fileName.split('.').pop() || ''}` : '';
192
- const sizeBytes = this._readSize(null);
193
-
194
- return {
195
- name: fileName,
196
- ext: ext.toLowerCase(),
197
- originalName: originalName || '',
198
- isMedia: false,
199
- sizeBytes,
200
- sizeText: this._formatSize(sizeBytes)
201
- };
202
- }
203
- }
204
-
205
- _readOriginalName(searchParams) {
206
- const fromData = this._element?.getAttribute('data-original-name')
207
- || this._element?.getAttribute('data-vg-filepreview-original-name')
208
- || '';
209
- if (fromData) {
210
- return String(fromData).trim();
211
- }
212
-
213
- const keys = ['original_name', 'originalName', 'filename', 'name'];
214
- for (const key of keys) {
215
- const value = searchParams.get(key);
216
- if (value) {
217
- return String(value).trim();
218
- }
219
- }
220
-
221
- return '';
222
- }
223
-
224
- _readSize(searchParams) {
225
- const dataCandidates = [
226
- this._element?.getAttribute('data-size'),
227
- this._element?.getAttribute('data-vg-filepreview-size')
228
- ];
229
-
230
- for (const value of dataCandidates) {
231
- const parsed = this._parseSizeValue(value);
232
- if (parsed !== null) {
233
- return parsed;
234
- }
235
- }
236
-
237
- if (!searchParams) {
238
- return null;
239
- }
240
-
241
- const keys = ['size', 'size_bytes', 'bytes'];
242
- for (const key of keys) {
243
- const value = searchParams.get(key);
244
- const parsed = this._parseSizeValue(value);
245
- if (parsed !== null) {
246
- return parsed;
247
- }
248
- }
249
-
250
- return null;
251
- }
252
-
253
- _parseSizeValue(value) {
254
- if (value === null || value === undefined) {
255
- return null;
256
- }
257
-
258
- const normalized = String(value).trim().toLowerCase();
259
- if (!normalized) {
260
- return null;
261
- }
262
-
263
- const match = normalized.match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb|tb)?$/i);
264
- if (!match) {
265
- return null;
266
- }
267
-
268
- const number = Number.parseFloat(match[1]);
269
- if (!Number.isFinite(number) || number < 0) {
270
- return null;
271
- }
272
-
273
- const unit = (match[2] || 'b').toLowerCase();
274
- const multipliers = {
275
- b: 1,
276
- kb: 1024,
277
- mb: 1024 * 1024,
278
- gb: 1024 * 1024 * 1024,
279
- tb: 1024 * 1024 * 1024 * 1024
280
- };
281
-
282
- return Math.round(number * (multipliers[unit] || 1));
283
- }
284
-
285
- _formatSize(bytes) {
286
- if (!Number.isFinite(bytes) || bytes < 0) {
287
- return '';
288
- }
289
-
290
- const units = ['B', 'KB', 'MB', 'GB', 'TB'];
291
- let value = bytes;
292
- let unitIndex = 0;
293
-
294
- while (value >= 1024 && unitIndex < units.length - 1) {
295
- value /= 1024;
296
- unitIndex += 1;
297
- }
298
-
299
- const fractionDigits = value >= 100 || unitIndex === 0 ? 0 : 2;
300
- return `${value.toFixed(fractionDigits)} ${units[unitIndex]}`;
301
- }
302
- }
303
-
304
- export default FilePreviewHelper;
1
+ const DEFAULT_OPTIONS = {
2
+ pathAttribute: 'data-vg-filepreview',
3
+ fieldsAttribute: 'data-fields',
4
+ validAttribute: 'data-vg-filepreview-valid',
5
+ errorAttribute: 'data-vg-filepreview-error',
6
+ errorValue: 'invalid-file-path',
7
+ fieldAttribute: 'data-vg-filepreview-field',
8
+ editableAttribute: 'data-vg-filepreview-editable',
9
+ editableFieldsAttribute: 'data-vg-filepreview-editable-fields',
10
+ missingFieldsAttribute: 'data-vg-filepreview-missing-fields'
11
+ };
12
+
13
+ class FilePreviewHelper {
14
+ constructor(element, options = {}) {
15
+ this._element = element;
16
+ this._options = Object.assign({}, DEFAULT_OPTIONS, options);
17
+ }
18
+
19
+ getFilePath() {
20
+ if (!this._element) {
21
+ return '';
22
+ }
23
+
24
+ const filePath = this._element.getAttribute(this._options.pathAttribute);
25
+ return typeof filePath === 'string' ? filePath.trim() : '';
26
+ }
27
+
28
+ getFields() {
29
+ if (!this._element) {
30
+ return [];
31
+ }
32
+
33
+ const rawFields = this._element.getAttribute(this._options.fieldsAttribute);
34
+ if (typeof rawFields !== 'string' || !rawFields.trim()) {
35
+ return [];
36
+ }
37
+
38
+ return rawFields
39
+ .split(',')
40
+ .map(field => field.trim())
41
+ .filter(field => field && /^[-_a-zA-Z0-9]+$/.test(field));
42
+ }
43
+
44
+ validateFilePath(path) {
45
+ if (!path || path === '#' || /^javascript:/i.test(path)) {
46
+ return { isValid: false, fileUrl: null };
47
+ }
48
+
49
+ try {
50
+ const parsed = new URL(path, window.location.origin);
51
+ const protocol = parsed.protocol;
52
+
53
+ if (!['http:', 'https:', 'blob:', 'data:'].includes(protocol)) {
54
+ return { isValid: false, fileUrl: null };
55
+ }
56
+
57
+ if (protocol === 'data:' || protocol === 'blob:') {
58
+ return { isValid: true, fileUrl: parsed };
59
+ }
60
+
61
+ const pathname = parsed.pathname || '';
62
+ const fileName = pathname.split('/').filter(Boolean).pop() || '';
63
+ if (!fileName || !fileName.includes('.')) {
64
+ return { isValid: false, fileUrl: null };
65
+ }
66
+
67
+ return { isValid: true, fileUrl: parsed };
68
+ } catch {
69
+ return { isValid: false, fileUrl: null };
70
+ }
71
+ }
72
+
73
+ syncState(isValid) {
74
+ if (!this._element) {
75
+ return;
76
+ }
77
+
78
+ this._element.setAttribute(this._options.validAttribute, isValid ? 'true' : 'false');
79
+
80
+ if (isValid) {
81
+ this._element.removeAttribute(this._options.errorAttribute);
82
+ return;
83
+ }
84
+
85
+ this._element.setAttribute(this._options.errorAttribute, this._options.errorValue);
86
+ }
87
+
88
+ resolveEditableFields(fields = []) {
89
+ if (!this._element || !Array.isArray(fields) || !fields.length) {
90
+ return {};
91
+ }
92
+
93
+ return fields.reduce((acc, field) => {
94
+ acc[field] = this._element.querySelector(`.${this._escapeClassName(field)}`);
95
+ return acc;
96
+ }, {});
97
+ }
98
+
99
+ syncEditableFields(fieldsMap = {}) {
100
+ if (!this._element) {
101
+ return;
102
+ }
103
+
104
+ const previousMarkedFields = this._element.querySelectorAll(`[${this._options.fieldAttribute}]`);
105
+ previousMarkedFields.forEach((node) => {
106
+ node.removeAttribute(this._options.fieldAttribute);
107
+ node.setAttribute(this._options.editableAttribute, 'false');
108
+ });
109
+
110
+ const editableFields = [];
111
+ const missingFields = [];
112
+
113
+ Object.entries(fieldsMap).forEach(([field, node]) => {
114
+ if (!node) {
115
+ missingFields.push(field);
116
+ return;
117
+ }
118
+
119
+ node.setAttribute(this._options.fieldAttribute, field);
120
+ node.setAttribute(this._options.editableAttribute, 'true');
121
+ editableFields.push(field);
122
+ });
123
+
124
+ if (editableFields.length) {
125
+ this._element.setAttribute(this._options.editableFieldsAttribute, editableFields.join(','));
126
+ } else {
127
+ this._element.removeAttribute(this._options.editableFieldsAttribute);
128
+ }
129
+
130
+ if (missingFields.length) {
131
+ this._element.setAttribute(this._options.missingFieldsAttribute, missingFields.join(','));
132
+ } else {
133
+ this._element.removeAttribute(this._options.missingFieldsAttribute);
134
+ }
135
+ }
136
+
137
+ _escapeClassName(value) {
138
+ if (window.CSS && typeof window.CSS.escape === 'function') {
139
+ return window.CSS.escape(value);
140
+ }
141
+
142
+ return String(value).replace(/([ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g, '\\$1');
143
+ }
144
+
145
+ getFileMeta(path) {
146
+ const normalizedPath = typeof path === 'string' ? path.trim() : '';
147
+ const fallback = {
148
+ name: '',
149
+ ext: '',
150
+ originalName: '',
151
+ isMedia: false,
152
+ sizeBytes: null,
153
+ sizeText: ''
154
+ };
155
+
156
+ if (!normalizedPath) {
157
+ return fallback;
158
+ }
159
+
160
+ try {
161
+ const parsedUrl = new URL(normalizedPath, window.location.origin);
162
+ const pathname = parsedUrl.pathname || '';
163
+ const params = parsedUrl.searchParams;
164
+ const originalName = this._readOriginalName(params);
165
+ let fileName = decodeURIComponent(pathname.split('/').pop() || '');
166
+
167
+ // blob/data urls often do not contain real filename; prefer explicit original name
168
+ if (!fileName || !fileName.includes('.')) {
169
+ fileName = originalName || fileName;
170
+ }
171
+
172
+ const ext = fileName.includes('.') ? `.${fileName.split('.').pop() || ''}` : '';
173
+ const sizeBytes = this._readSize(params);
174
+ const mediaByExt = ['.mp3', '.wav', '.ogg', '.flac', '.aac', '.m4a', '.mp4', '.webm', '.mov', '.mkv', '.avi'];
175
+
176
+ return {
177
+ name: fileName,
178
+ ext: ext.toLowerCase(),
179
+ originalName,
180
+ isMedia: mediaByExt.includes(ext.toLowerCase()),
181
+ sizeBytes,
182
+ sizeText: this._formatSize(sizeBytes)
183
+ };
184
+ } catch {
185
+ const cleanPath = normalizedPath.split('#')[0].split('?')[0];
186
+ let fileName = decodeURIComponent(cleanPath.split('/').pop() || '');
187
+ const originalName = this._readOriginalName(null);
188
+ if (!fileName || !fileName.includes('.')) {
189
+ fileName = originalName || fileName;
190
+ }
191
+ const ext = fileName.includes('.') ? `.${fileName.split('.').pop() || ''}` : '';
192
+ const sizeBytes = this._readSize(null);
193
+
194
+ return {
195
+ name: fileName,
196
+ ext: ext.toLowerCase(),
197
+ originalName: originalName || '',
198
+ isMedia: false,
199
+ sizeBytes,
200
+ sizeText: this._formatSize(sizeBytes)
201
+ };
202
+ }
203
+ }
204
+
205
+ _readOriginalName(searchParams) {
206
+ const fromData = this._element?.getAttribute('data-original-name')
207
+ || this._element?.getAttribute('data-vg-filepreview-original-name')
208
+ || '';
209
+ if (fromData) {
210
+ return String(fromData).trim();
211
+ }
212
+
213
+ const keys = ['original_name', 'originalName', 'filename', 'name'];
214
+ for (const key of keys) {
215
+ const value = searchParams.get(key);
216
+ if (value) {
217
+ return String(value).trim();
218
+ }
219
+ }
220
+
221
+ return '';
222
+ }
223
+
224
+ _readSize(searchParams) {
225
+ const dataCandidates = [
226
+ this._element?.getAttribute('data-size'),
227
+ this._element?.getAttribute('data-vg-filepreview-size')
228
+ ];
229
+
230
+ for (const value of dataCandidates) {
231
+ const parsed = this._parseSizeValue(value);
232
+ if (parsed !== null) {
233
+ return parsed;
234
+ }
235
+ }
236
+
237
+ if (!searchParams) {
238
+ return null;
239
+ }
240
+
241
+ const keys = ['size', 'size_bytes', 'bytes'];
242
+ for (const key of keys) {
243
+ const value = searchParams.get(key);
244
+ const parsed = this._parseSizeValue(value);
245
+ if (parsed !== null) {
246
+ return parsed;
247
+ }
248
+ }
249
+
250
+ return null;
251
+ }
252
+
253
+ _parseSizeValue(value) {
254
+ if (value === null || value === undefined) {
255
+ return null;
256
+ }
257
+
258
+ const normalized = String(value).trim().toLowerCase();
259
+ if (!normalized) {
260
+ return null;
261
+ }
262
+
263
+ const match = normalized.match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb|tb)?$/i);
264
+ if (!match) {
265
+ return null;
266
+ }
267
+
268
+ const number = Number.parseFloat(match[1]);
269
+ if (!Number.isFinite(number) || number < 0) {
270
+ return null;
271
+ }
272
+
273
+ const unit = (match[2] || 'b').toLowerCase();
274
+ const multipliers = {
275
+ b: 1,
276
+ kb: 1024,
277
+ mb: 1024 * 1024,
278
+ gb: 1024 * 1024 * 1024,
279
+ tb: 1024 * 1024 * 1024 * 1024
280
+ };
281
+
282
+ return Math.round(number * (multipliers[unit] || 1));
283
+ }
284
+
285
+ _formatSize(bytes) {
286
+ if (!Number.isFinite(bytes) || bytes < 0) {
287
+ return '';
288
+ }
289
+
290
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
291
+ let value = bytes;
292
+ let unitIndex = 0;
293
+
294
+ while (value >= 1024 && unitIndex < units.length - 1) {
295
+ value /= 1024;
296
+ unitIndex += 1;
297
+ }
298
+
299
+ const fractionDigits = value >= 100 || unitIndex === 0 ? 0 : 2;
300
+ return `${value.toFixed(fractionDigits)} ${units[unitIndex]}`;
301
+ }
302
+ }
303
+
304
+ export default FilePreviewHelper;