vgapp 1.3.3 → 1.3.5
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 +5 -12
- package/app/langs/en/buttons.json +17 -17
- package/app/langs/en/messages.json +36 -36
- package/app/langs/ru/buttons.json +17 -17
- package/app/langs/ru/messages.json +36 -36
- package/app/modules/base-module.js +111 -111
- package/app/modules/vgalert/js/vgalert.js +52 -52
- package/app/modules/vgalert/readme.md +105 -105
- package/app/modules/vgdynamictable/index.js +5 -5
- package/app/modules/vgdynamictable/js/editable.js +19 -19
- package/app/modules/vgdynamictable/js/filters.js +21 -21
- package/app/modules/vgdynamictable/js/fixed.js +179 -179
- package/app/modules/vgdynamictable/js/pagination.js +1 -1
- package/app/modules/vgdynamictable/js/search.js +12 -12
- package/app/modules/vgdynamictable/js/sortable.js +71 -71
- package/app/modules/vgdynamictable/js/summary-footer.js +28 -28
- package/app/modules/vgdynamictable/js/table-remote.js +79 -79
- package/app/modules/vgdynamictable/js/table-url-state.js +31 -31
- package/app/modules/vgdynamictable/js/utils/common.js +48 -48
- package/app/modules/vgdynamictable/js/vgdynamictable.js +268 -268
- package/app/modules/vgdynamictable/readme.md +250 -250
- package/app/modules/vgdynamictable/scss/_skeleton.scss +6 -6
- package/app/modules/vgdynamictable/scss/_sortable.scss +24 -24
- package/app/modules/vgdynamictable/scss/_table.scss +4 -4
- package/app/modules/vgdynamictable/scss/_variables.scss +79 -79
- package/app/modules/vgdynamictable/scss/vgdynamictable.scss +27 -27
- package/app/modules/vgfilepreview/js/i18n.js +56 -56
- package/app/modules/vgfilepreview/js/renderers/image-modal.js +145 -145
- package/app/modules/vgfilepreview/js/renderers/image.js +92 -92
- package/app/modules/vgfilepreview/js/renderers/index.js +19 -19
- package/app/modules/vgfilepreview/js/renderers/office-modal.js +168 -168
- package/app/modules/vgfilepreview/js/renderers/office.js +79 -79
- package/app/modules/vgfilepreview/js/renderers/pdf-modal.js +260 -260
- package/app/modules/vgfilepreview/js/renderers/pdf.js +76 -76
- package/app/modules/vgfilepreview/js/renderers/playlist.js +71 -71
- package/app/modules/vgfilepreview/js/renderers/text-modal.js +343 -343
- package/app/modules/vgfilepreview/js/renderers/text.js +83 -83
- package/app/modules/vgfilepreview/js/renderers/video-modal.js +272 -272
- package/app/modules/vgfilepreview/js/renderers/video.js +80 -80
- package/app/modules/vgfilepreview/js/renderers/zip-modal.js +522 -522
- package/app/modules/vgfilepreview/js/renderers/zip.js +89 -89
- package/app/modules/vgfilepreview/js/vgfilepreview.js +7 -7
- package/app/modules/vgfilepreview/readme.md +68 -68
- package/app/modules/vgfilepreview/scss/_variables.scss +113 -113
- package/app/modules/vgfilepreview/scss/vgfilepreview.scss +464 -464
- package/app/modules/vgfiles/js/base.js +26 -26
- package/app/modules/vgfiles/js/droppable.js +260 -260
- package/app/modules/vgfiles/js/render.js +153 -153
- package/app/modules/vgfiles/js/vgfiles.js +104 -104
- package/app/modules/vgfiles/readme.md +123 -123
- package/app/modules/vgfiles/scss/_variables.scss +18 -18
- package/app/modules/vgfiles/scss/vgfiles.scss +148 -148
- package/app/modules/vgformsender/js/hideshowpass.js +16 -16
- package/app/modules/vgformsender/scss/vgformsender.scss +34 -34
- package/app/modules/vgmodal/js/vgmodal.drag.js +332 -332
- package/app/modules/vgmodal/js/vgmodal.js +188 -188
- package/app/modules/vgmodal/js/vgmodal.resize.js +27 -27
- package/app/modules/vgmodal/scss/vgmodal.scss +14 -14
- package/app/modules/vgnav/js/vgnav.js +135 -135
- package/app/modules/vgnav/readme.md +67 -67
- package/app/modules/vgnestable/README.md +307 -307
- package/app/modules/vgnestable/scss/_variables.scss +60 -60
- package/app/modules/vgnestable/scss/vgnestable.scss +163 -163
- package/app/modules/vgrangeslider/js/skins.js +222 -222
- package/app/modules/vgrangeslider/js/vgrangeslider.js +704 -704
- package/app/modules/vgrangeslider/readme.md +523 -523
- package/app/modules/vgrangeslider/scss/_variables.scss +53 -53
- package/app/modules/vgrangeslider/scss/vgrangeslider.scss +240 -240
- package/app/modules/vgselect/js/vgselect.js +39 -39
- package/app/modules/vgselect/scss/vgselect.scss +22 -22
- package/app/modules/vgspy/readme.md +28 -28
- package/app/modules/vgtoast/readme.md +18 -18
- package/app/modules/vgtoast/scss/vgtoast.scss +48 -48
- package/app/modules/vgtooltip/js/vgtooltip.js +89 -89
- package/app/modules/vgtooltip/readme.md +181 -181
- package/app/utils/js/components/ajax.js +117 -117
- package/app/utils/js/components/audio-metadata.js +240 -240
- package/app/utils/js/components/backdrop.js +17 -17
- package/app/utils/js/components/file-icon.js +109 -109
- package/app/utils/js/components/file-preview.js +304 -304
- package/app/utils/js/components/sanitize.js +150 -150
- package/app/utils/js/components/video-metadata.js +140 -140
- package/app/vgapp.js +21 -21
- package/build/vgapp.css +1 -1
- package/build/vgapp.css.map +1 -1
- package/build/vgapp.js +1 -1
- package/build/vgapp.js.map +1 -1
- package/index.js +14 -14
- package/package.json +3 -2
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
2
|
-
const DEFAULT_ALLOWED_SVG_TAGS = new Set([
|
|
3
|
-
"svg",
|
|
4
|
-
"g",
|
|
5
|
-
"path",
|
|
6
|
-
"line",
|
|
7
|
-
"polyline",
|
|
8
|
-
"polygon",
|
|
9
|
-
"circle",
|
|
10
|
-
"ellipse",
|
|
11
|
-
"rect",
|
|
12
|
-
"defs",
|
|
13
|
-
"symbol",
|
|
14
|
-
"title",
|
|
15
|
-
"use"
|
|
16
|
-
]);
|
|
17
|
-
const DEFAULT_ALLOWED_SVG_ATTRS = new Set([
|
|
18
|
-
"xmlns",
|
|
19
|
-
"viewbox",
|
|
20
|
-
"width",
|
|
21
|
-
"height",
|
|
22
|
-
"fill",
|
|
23
|
-
"stroke",
|
|
24
|
-
"stroke-width",
|
|
25
|
-
"stroke-linecap",
|
|
26
|
-
"stroke-linejoin",
|
|
27
|
-
"stroke-miterlimit",
|
|
28
|
-
"stroke-dasharray",
|
|
29
|
-
"stroke-dashoffset",
|
|
30
|
-
"opacity",
|
|
31
|
-
"transform",
|
|
32
|
-
"class",
|
|
33
|
-
"x",
|
|
34
|
-
"y",
|
|
35
|
-
"x1",
|
|
36
|
-
"y1",
|
|
37
|
-
"x2",
|
|
38
|
-
"y2",
|
|
39
|
-
"cx",
|
|
40
|
-
"cy",
|
|
41
|
-
"r",
|
|
42
|
-
"rx",
|
|
43
|
-
"ry",
|
|
44
|
-
"points",
|
|
45
|
-
"d",
|
|
46
|
-
"role",
|
|
47
|
-
"focusable",
|
|
48
|
-
"aria-hidden",
|
|
49
|
-
"href",
|
|
50
|
-
"xlink:href"
|
|
51
|
-
]);
|
|
52
|
-
|
|
53
|
-
function escapeHtml(value) {
|
|
54
|
-
return String(value)
|
|
55
|
-
.replace(/&/g, "&")
|
|
56
|
-
.replace(/</g, "<")
|
|
57
|
-
.replace(/>/g, ">")
|
|
58
|
-
.replace(/"/g, """)
|
|
59
|
-
.replace(/'/g, "'");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function sanitizeSvgNode(node, allowedTags = DEFAULT_ALLOWED_SVG_TAGS, allowedAttrs = DEFAULT_ALLOWED_SVG_ATTRS) {
|
|
63
|
-
if (!node) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
68
|
-
return document.createTextNode(node.textContent || "");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const tagName = node.tagName.toLowerCase();
|
|
76
|
-
if (!allowedTags.has(tagName)) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const safeNode = document.createElementNS(SVG_NAMESPACE, tagName);
|
|
81
|
-
|
|
82
|
-
Array.from(node.attributes || []).forEach((attr) => {
|
|
83
|
-
const name = attr.name.toLowerCase();
|
|
84
|
-
const attrValue = attr.value || "";
|
|
85
|
-
|
|
86
|
-
if (!allowedAttrs.has(name) || name.startsWith("on")) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if ((name === "href" || name === "xlink:href") && attrValue && !attrValue.startsWith("#")) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
safeNode.setAttribute(name, attrValue);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
Array.from(node.childNodes || []).forEach((child) => {
|
|
98
|
-
const safeChild = sanitizeSvgNode(child, allowedTags, allowedAttrs);
|
|
99
|
-
if (safeChild) {
|
|
100
|
-
safeNode.append(safeChild);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return safeNode;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function toSafeHtmlString(value, {
|
|
108
|
-
allowedSvgTags = DEFAULT_ALLOWED_SVG_TAGS,
|
|
109
|
-
allowedSvgAttrs = DEFAULT_ALLOWED_SVG_ATTRS
|
|
110
|
-
} = {}) {
|
|
111
|
-
if (value === null || value === undefined) {
|
|
112
|
-
return "";
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const content = String(value).trim();
|
|
116
|
-
if (!content) {
|
|
117
|
-
return "";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!content.includes("<")) {
|
|
121
|
-
return escapeHtml(content);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const template = document.createElement("template");
|
|
125
|
-
template.innerHTML = content;
|
|
126
|
-
|
|
127
|
-
const sanitizedParts = Array.from(template.content.childNodes)
|
|
128
|
-
.map((node) => sanitizeSvgNode(node, allowedSvgTags, allowedSvgAttrs))
|
|
129
|
-
.filter(Boolean)
|
|
130
|
-
.map((node) => {
|
|
131
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
132
|
-
return escapeHtml(node.textContent || "");
|
|
133
|
-
}
|
|
134
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
135
|
-
return node.outerHTML;
|
|
136
|
-
}
|
|
137
|
-
return "";
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const sanitized = sanitizedParts.join("");
|
|
141
|
-
return sanitized || escapeHtml(content);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
class Sanitize {
|
|
145
|
-
static toSafeHtmlString(value, options) {
|
|
146
|
-
return toSafeHtmlString(value, options);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export default Sanitize;
|
|
1
|
+
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
2
|
+
const DEFAULT_ALLOWED_SVG_TAGS = new Set([
|
|
3
|
+
"svg",
|
|
4
|
+
"g",
|
|
5
|
+
"path",
|
|
6
|
+
"line",
|
|
7
|
+
"polyline",
|
|
8
|
+
"polygon",
|
|
9
|
+
"circle",
|
|
10
|
+
"ellipse",
|
|
11
|
+
"rect",
|
|
12
|
+
"defs",
|
|
13
|
+
"symbol",
|
|
14
|
+
"title",
|
|
15
|
+
"use"
|
|
16
|
+
]);
|
|
17
|
+
const DEFAULT_ALLOWED_SVG_ATTRS = new Set([
|
|
18
|
+
"xmlns",
|
|
19
|
+
"viewbox",
|
|
20
|
+
"width",
|
|
21
|
+
"height",
|
|
22
|
+
"fill",
|
|
23
|
+
"stroke",
|
|
24
|
+
"stroke-width",
|
|
25
|
+
"stroke-linecap",
|
|
26
|
+
"stroke-linejoin",
|
|
27
|
+
"stroke-miterlimit",
|
|
28
|
+
"stroke-dasharray",
|
|
29
|
+
"stroke-dashoffset",
|
|
30
|
+
"opacity",
|
|
31
|
+
"transform",
|
|
32
|
+
"class",
|
|
33
|
+
"x",
|
|
34
|
+
"y",
|
|
35
|
+
"x1",
|
|
36
|
+
"y1",
|
|
37
|
+
"x2",
|
|
38
|
+
"y2",
|
|
39
|
+
"cx",
|
|
40
|
+
"cy",
|
|
41
|
+
"r",
|
|
42
|
+
"rx",
|
|
43
|
+
"ry",
|
|
44
|
+
"points",
|
|
45
|
+
"d",
|
|
46
|
+
"role",
|
|
47
|
+
"focusable",
|
|
48
|
+
"aria-hidden",
|
|
49
|
+
"href",
|
|
50
|
+
"xlink:href"
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
function escapeHtml(value) {
|
|
54
|
+
return String(value)
|
|
55
|
+
.replace(/&/g, "&")
|
|
56
|
+
.replace(/</g, "<")
|
|
57
|
+
.replace(/>/g, ">")
|
|
58
|
+
.replace(/"/g, """)
|
|
59
|
+
.replace(/'/g, "'");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function sanitizeSvgNode(node, allowedTags = DEFAULT_ALLOWED_SVG_TAGS, allowedAttrs = DEFAULT_ALLOWED_SVG_ATTRS) {
|
|
63
|
+
if (!node) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
68
|
+
return document.createTextNode(node.textContent || "");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const tagName = node.tagName.toLowerCase();
|
|
76
|
+
if (!allowedTags.has(tagName)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const safeNode = document.createElementNS(SVG_NAMESPACE, tagName);
|
|
81
|
+
|
|
82
|
+
Array.from(node.attributes || []).forEach((attr) => {
|
|
83
|
+
const name = attr.name.toLowerCase();
|
|
84
|
+
const attrValue = attr.value || "";
|
|
85
|
+
|
|
86
|
+
if (!allowedAttrs.has(name) || name.startsWith("on")) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if ((name === "href" || name === "xlink:href") && attrValue && !attrValue.startsWith("#")) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
safeNode.setAttribute(name, attrValue);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
Array.from(node.childNodes || []).forEach((child) => {
|
|
98
|
+
const safeChild = sanitizeSvgNode(child, allowedTags, allowedAttrs);
|
|
99
|
+
if (safeChild) {
|
|
100
|
+
safeNode.append(safeChild);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return safeNode;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function toSafeHtmlString(value, {
|
|
108
|
+
allowedSvgTags = DEFAULT_ALLOWED_SVG_TAGS,
|
|
109
|
+
allowedSvgAttrs = DEFAULT_ALLOWED_SVG_ATTRS
|
|
110
|
+
} = {}) {
|
|
111
|
+
if (value === null || value === undefined) {
|
|
112
|
+
return "";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const content = String(value).trim();
|
|
116
|
+
if (!content) {
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!content.includes("<")) {
|
|
121
|
+
return escapeHtml(content);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const template = document.createElement("template");
|
|
125
|
+
template.innerHTML = content;
|
|
126
|
+
|
|
127
|
+
const sanitizedParts = Array.from(template.content.childNodes)
|
|
128
|
+
.map((node) => sanitizeSvgNode(node, allowedSvgTags, allowedSvgAttrs))
|
|
129
|
+
.filter(Boolean)
|
|
130
|
+
.map((node) => {
|
|
131
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
132
|
+
return escapeHtml(node.textContent || "");
|
|
133
|
+
}
|
|
134
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
135
|
+
return node.outerHTML;
|
|
136
|
+
}
|
|
137
|
+
return "";
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const sanitized = sanitizedParts.join("");
|
|
141
|
+
return sanitized || escapeHtml(content);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
class Sanitize {
|
|
145
|
+
static toSafeHtmlString(value, options) {
|
|
146
|
+
return toSafeHtmlString(value, options);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default Sanitize;
|
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
const VIDEO_EXTENSIONS = new Set([
|
|
2
|
-
'mp4',
|
|
3
|
-
'webm',
|
|
4
|
-
'mov',
|
|
5
|
-
'mkv',
|
|
6
|
-
'avi',
|
|
7
|
-
'm4v',
|
|
8
|
-
'ogv'
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
const getFileExtension = (file) => {
|
|
12
|
-
const fileName = String(file?.name || '').toLowerCase();
|
|
13
|
-
const dot = fileName.lastIndexOf('.');
|
|
14
|
-
if (dot < 0 || dot >= fileName.length - 1) {
|
|
15
|
-
return '';
|
|
16
|
-
}
|
|
17
|
-
return fileName.slice(dot + 1);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const waitEvent = (node, eventName) => new Promise((resolve, reject) => {
|
|
21
|
-
const onResolve = () => {
|
|
22
|
-
cleanup();
|
|
23
|
-
resolve(true);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const onReject = () => {
|
|
27
|
-
cleanup();
|
|
28
|
-
reject(new Error(eventName));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const cleanup = () => {
|
|
32
|
-
node.removeEventListener(eventName, onResolve);
|
|
33
|
-
node.removeEventListener('error', onReject);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
node.addEventListener(eventName, onResolve, { once: true });
|
|
37
|
-
node.addEventListener('error', onReject, { once: true });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const seekVideo = (video, time) => new Promise((resolve, reject) => {
|
|
41
|
-
const onSeeked = () => {
|
|
42
|
-
cleanup();
|
|
43
|
-
resolve(true);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const onError = () => {
|
|
47
|
-
cleanup();
|
|
48
|
-
reject(new Error('seek'));
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const cleanup = () => {
|
|
52
|
-
video.removeEventListener('seeked', onSeeked);
|
|
53
|
-
video.removeEventListener('error', onError);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
video.addEventListener('seeked', onSeeked, { once: true });
|
|
57
|
-
video.addEventListener('error', onError, { once: true });
|
|
58
|
-
video.currentTime = time;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const canvasToBlob = (canvas, type = 'image/jpeg', quality = 0.92) => new Promise((resolve) => {
|
|
62
|
-
canvas.toBlob((blob) => resolve(blob || null), type, quality);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const extractVideoMetadata = async (file) => {
|
|
66
|
-
if (!(file instanceof File)) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const ext = getFileExtension(file);
|
|
71
|
-
const isVideoType = String(file.type || '').toLowerCase().startsWith('video/');
|
|
72
|
-
if (!isVideoType && !VIDEO_EXTENSIONS.has(ext)) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!file.size) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let objectUrl = '';
|
|
81
|
-
try {
|
|
82
|
-
objectUrl = URL.createObjectURL(file);
|
|
83
|
-
|
|
84
|
-
const video = document.createElement('video');
|
|
85
|
-
video.preload = 'metadata';
|
|
86
|
-
video.muted = true;
|
|
87
|
-
video.playsInline = true;
|
|
88
|
-
video.crossOrigin = 'anonymous';
|
|
89
|
-
video.src = objectUrl;
|
|
90
|
-
|
|
91
|
-
await waitEvent(video, 'loadedmetadata');
|
|
92
|
-
|
|
93
|
-
const width = Number(video.videoWidth || 0);
|
|
94
|
-
const height = Number(video.videoHeight || 0);
|
|
95
|
-
const duration = Number(video.duration || 0);
|
|
96
|
-
|
|
97
|
-
if (!width || !height || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
98
|
-
return {
|
|
99
|
-
duration: Number.isFinite(duration) ? duration : 0,
|
|
100
|
-
width: 0,
|
|
101
|
-
height: 0
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const seekTime = duration > 1 ? Math.min(1, Math.max(0, duration / 2)) : 0;
|
|
106
|
-
await seekVideo(video, seekTime);
|
|
107
|
-
|
|
108
|
-
const canvas = document.createElement('canvas');
|
|
109
|
-
canvas.width = width;
|
|
110
|
-
canvas.height = height;
|
|
111
|
-
const ctx = canvas.getContext('2d');
|
|
112
|
-
if (!ctx) {
|
|
113
|
-
return {
|
|
114
|
-
duration: Number.isFinite(duration) ? duration : 0,
|
|
115
|
-
width,
|
|
116
|
-
height
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
ctx.drawImage(video, 0, 0, width, height);
|
|
121
|
-
const posterBlob = await canvasToBlob(canvas, 'image/jpeg', 0.92);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
duration: Number.isFinite(duration) ? duration : 0,
|
|
125
|
-
width,
|
|
126
|
-
height,
|
|
127
|
-
posterBlob: posterBlob || null
|
|
128
|
-
};
|
|
129
|
-
} catch {
|
|
130
|
-
return null;
|
|
131
|
-
} finally {
|
|
132
|
-
if (objectUrl) {
|
|
133
|
-
URL.revokeObjectURL(objectUrl);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export {
|
|
139
|
-
extractVideoMetadata
|
|
140
|
-
};
|
|
1
|
+
const VIDEO_EXTENSIONS = new Set([
|
|
2
|
+
'mp4',
|
|
3
|
+
'webm',
|
|
4
|
+
'mov',
|
|
5
|
+
'mkv',
|
|
6
|
+
'avi',
|
|
7
|
+
'm4v',
|
|
8
|
+
'ogv'
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const getFileExtension = (file) => {
|
|
12
|
+
const fileName = String(file?.name || '').toLowerCase();
|
|
13
|
+
const dot = fileName.lastIndexOf('.');
|
|
14
|
+
if (dot < 0 || dot >= fileName.length - 1) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
return fileName.slice(dot + 1);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const waitEvent = (node, eventName) => new Promise((resolve, reject) => {
|
|
21
|
+
const onResolve = () => {
|
|
22
|
+
cleanup();
|
|
23
|
+
resolve(true);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const onReject = () => {
|
|
27
|
+
cleanup();
|
|
28
|
+
reject(new Error(eventName));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const cleanup = () => {
|
|
32
|
+
node.removeEventListener(eventName, onResolve);
|
|
33
|
+
node.removeEventListener('error', onReject);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
node.addEventListener(eventName, onResolve, { once: true });
|
|
37
|
+
node.addEventListener('error', onReject, { once: true });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const seekVideo = (video, time) => new Promise((resolve, reject) => {
|
|
41
|
+
const onSeeked = () => {
|
|
42
|
+
cleanup();
|
|
43
|
+
resolve(true);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const onError = () => {
|
|
47
|
+
cleanup();
|
|
48
|
+
reject(new Error('seek'));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const cleanup = () => {
|
|
52
|
+
video.removeEventListener('seeked', onSeeked);
|
|
53
|
+
video.removeEventListener('error', onError);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
video.addEventListener('seeked', onSeeked, { once: true });
|
|
57
|
+
video.addEventListener('error', onError, { once: true });
|
|
58
|
+
video.currentTime = time;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const canvasToBlob = (canvas, type = 'image/jpeg', quality = 0.92) => new Promise((resolve) => {
|
|
62
|
+
canvas.toBlob((blob) => resolve(blob || null), type, quality);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const extractVideoMetadata = async (file) => {
|
|
66
|
+
if (!(file instanceof File)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const ext = getFileExtension(file);
|
|
71
|
+
const isVideoType = String(file.type || '').toLowerCase().startsWith('video/');
|
|
72
|
+
if (!isVideoType && !VIDEO_EXTENSIONS.has(ext)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!file.size) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let objectUrl = '';
|
|
81
|
+
try {
|
|
82
|
+
objectUrl = URL.createObjectURL(file);
|
|
83
|
+
|
|
84
|
+
const video = document.createElement('video');
|
|
85
|
+
video.preload = 'metadata';
|
|
86
|
+
video.muted = true;
|
|
87
|
+
video.playsInline = true;
|
|
88
|
+
video.crossOrigin = 'anonymous';
|
|
89
|
+
video.src = objectUrl;
|
|
90
|
+
|
|
91
|
+
await waitEvent(video, 'loadedmetadata');
|
|
92
|
+
|
|
93
|
+
const width = Number(video.videoWidth || 0);
|
|
94
|
+
const height = Number(video.videoHeight || 0);
|
|
95
|
+
const duration = Number(video.duration || 0);
|
|
96
|
+
|
|
97
|
+
if (!width || !height || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
98
|
+
return {
|
|
99
|
+
duration: Number.isFinite(duration) ? duration : 0,
|
|
100
|
+
width: 0,
|
|
101
|
+
height: 0
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const seekTime = duration > 1 ? Math.min(1, Math.max(0, duration / 2)) : 0;
|
|
106
|
+
await seekVideo(video, seekTime);
|
|
107
|
+
|
|
108
|
+
const canvas = document.createElement('canvas');
|
|
109
|
+
canvas.width = width;
|
|
110
|
+
canvas.height = height;
|
|
111
|
+
const ctx = canvas.getContext('2d');
|
|
112
|
+
if (!ctx) {
|
|
113
|
+
return {
|
|
114
|
+
duration: Number.isFinite(duration) ? duration : 0,
|
|
115
|
+
width,
|
|
116
|
+
height
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
ctx.drawImage(video, 0, 0, width, height);
|
|
121
|
+
const posterBlob = await canvasToBlob(canvas, 'image/jpeg', 0.92);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
duration: Number.isFinite(duration) ? duration : 0,
|
|
125
|
+
width,
|
|
126
|
+
height,
|
|
127
|
+
posterBlob: posterBlob || null
|
|
128
|
+
};
|
|
129
|
+
} catch {
|
|
130
|
+
return null;
|
|
131
|
+
} finally {
|
|
132
|
+
if (objectUrl) {
|
|
133
|
+
URL.revokeObjectURL(objectUrl);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
extractVideoMetadata
|
|
140
|
+
};
|
package/app/vgapp.js
CHANGED
|
@@ -28,29 +28,15 @@ class VGApp {
|
|
|
28
28
|
this._isInitialized = false;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
register(
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
return entry;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return entry ? [entry] : [];
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
for (const Module of modules) {
|
|
41
|
-
const candidate = Module?.default ?? Module;
|
|
42
|
-
const name = String(candidate?.NAME || '').trim();
|
|
43
|
-
|
|
44
|
-
if (!name) {
|
|
45
|
-
const moduleKeys = Module && typeof Module === 'object'
|
|
46
|
-
? Object.keys(Module).join(', ')
|
|
47
|
-
: '';
|
|
48
|
-
throw new Error(`VGApp.register() ожидает модуль со статическим NAME. Получено: ${moduleKeys || typeof Module}`);
|
|
49
|
-
}
|
|
31
|
+
register(name, Module) {
|
|
32
|
+
const normalizedName = String(name || '').trim();
|
|
33
|
+
const candidate = this._resolveModuleCandidate(Module);
|
|
50
34
|
|
|
51
|
-
|
|
35
|
+
if (!normalizedName) {
|
|
36
|
+
throw new Error('VGApp.register() ожидает строковое имя модуля первым аргументом.');
|
|
52
37
|
}
|
|
53
38
|
|
|
39
|
+
this._modules.set(normalizedName, candidate);
|
|
54
40
|
return this;
|
|
55
41
|
}
|
|
56
42
|
|
|
@@ -79,6 +65,16 @@ class VGApp {
|
|
|
79
65
|
return this._modules.has(String(name).trim());
|
|
80
66
|
}
|
|
81
67
|
|
|
68
|
+
_resolveModuleCandidate(Module) {
|
|
69
|
+
const candidate = Module?.default ?? Module;
|
|
70
|
+
|
|
71
|
+
if (!candidate) {
|
|
72
|
+
throw new Error('VGApp.register() ожидает валидный модуль.');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return candidate;
|
|
76
|
+
}
|
|
77
|
+
|
|
82
78
|
_resolveModuleConfig(name, config) {
|
|
83
79
|
if (!config || typeof config !== 'object') {
|
|
84
80
|
return undefined;
|
|
@@ -123,7 +119,11 @@ const defaultModules = [
|
|
|
123
119
|
];
|
|
124
120
|
|
|
125
121
|
const vgapp = new VGApp({
|
|
126
|
-
initializer: (app) =>
|
|
122
|
+
initializer: (app) => {
|
|
123
|
+
defaultModules.forEach((Module) => {
|
|
124
|
+
app.register(Module.NAME, Module);
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
export { VGApp, vgapp };
|