Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit a445205

Browse files
feat: audio, video and pdf reader (#953)
Co-authored-by: Kjartan Óli Ágústsson <[email protected]>
1 parent 7c09231 commit a445205

File tree

10 files changed

+604
-12
lines changed

10 files changed

+604
-12
lines changed

src/assets/css/filesystem.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,27 @@ div#fs_space_bar > progress::-webkit-progress-value {
262262
bottom: .7vh;
263263
transition: width .5s cubic-bezier(0.4, 0, 1, 1);
264264
}
265+
266+
.pdf_container {
267+
text-align: center;
268+
background: var(--color_light_black);
269+
color: rgb(var(--color_r), var(--color_g), var(--color_b));
270+
border: 0.15vh solid rgb(var(--color_r), var(--color_g), var(--color_b));
271+
padding: 0.4vh 0.2vh;
272+
font-size: 1.4vh;
273+
resize: none;
274+
overflow: auto;
275+
width: 50vw;
276+
height: 50vh;
277+
}
278+
279+
.pdf_options button {
280+
width: 40px;
281+
height: 40px;
282+
padding: 5px;
283+
}
284+
285+
.pdf_options span {
286+
margin-left: 1.5vh;
287+
font-size: 24px;
288+
}

src/assets/css/media_player.css

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
.media_container[data-fullscreen=true] .media {
2+
height: 95%;
3+
width: 100%;
4+
max-width: none;
5+
max-height: none;
6+
}
7+
8+
.media_controls {
9+
border: 2px solid rgb(var(--color_r), var(--color_g), var(--color_b));
10+
background: var(--color_light_black);
11+
}
12+
13+
.media_controls>div {
14+
text-align: center;
15+
display: inline-block;
16+
vertical-align: middle;
17+
padding-left: 0.1em;
18+
padding-right: 0.1em;
19+
}
20+
21+
.media_controls .media_button {
22+
font-size: 1.5em;
23+
height: 1em;
24+
width: 1em;
25+
}
26+
27+
.media_controls .media_button:hover {
28+
cursor: pointer;
29+
background: rgba(var(--color_r), var(--color_g), var(--color_b), 0.5);
30+
}
31+
32+
.media_controls .media_time {
33+
margin-right: 2vw;
34+
width: 4vw;
35+
}
36+
37+
.media_controls .volume_icon {
38+
font-size: 1.5em;
39+
height: 1em;
40+
width: 1em;
41+
}
42+
43+
.media_controls .volume {
44+
height: 2vh;
45+
z-index: 100;
46+
width: 5vw;
47+
cursor: pointer;
48+
}
49+
50+
.media_controls .volume_bkg {
51+
position: absolute;
52+
border-style: solid;
53+
border-width: 0 0 2vh 5vw;
54+
border-color: transparent transparent rgba(var(--color_r), var(--color_g), var(--color_b), 0.7) transparent;
55+
}
56+
57+
.media_controls .volume_bar {
58+
position: absolute;
59+
clip: rect(0px, 5vw, 2vh, 0px);
60+
width: 5vw;
61+
border-style: solid;
62+
border-width: 0 0 2vh 5vw;
63+
border-color: transparent transparent rgb(var(--color_r), var(--color_g), var(--color_b)) transparent;
64+
}
65+
66+
.fs {
67+
float: right;
68+
}
69+
70+
.media_controls .progress_container {
71+
min-width: 20vw;
72+
}
73+
74+
.media_controls .progress {
75+
display: block;
76+
cursor: pointer;
77+
width: 100%;
78+
background-color: rgba(var(--color_r), var(--color_g), var(--color_b), 0.5);
79+
height: 5px;
80+
}
81+
82+
.media_controls .progress_bar {
83+
width: 0%;
84+
height: 100%;
85+
display: block;
86+
background-color: rgb(var(--color_r), var(--color_g), var(--color_b));
87+
}
88+
89+
.fullscreen_hidden {
90+
visibility: hidden;
91+
opacity: 0;
92+
transition: visibility 0s 2s, opacity 2s linear;
93+
}
94+
95+
.volume_icon:hover {
96+
cursor: pointer;
97+
}

src/assets/icons/file-icons.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6284,6 +6284,16 @@
62846284
"height": 512,
62856285
"svg": "<path d=\"M292.5714417,384h-73.142868v-73.1428528h73.142868V384z M365.7142944,321.5925598l-41.9274292-41.9508667c-3.3085938-3.3091431-7.8800354-5.3559875-12.929718-5.3559875H201.1428528c-10.0994263,0-18.2857056,8.1862793-18.2857056,18.2857361v109.7142639c0,4.7594299,1.8188629,9.0942688,4.7977142,12.3468628l42.5194244,42.5102844h-65.6028595c-10.0994263,0-18.2857056-8.1862793-18.2857056-18.2857056V256c0-10.0994415,8.1862793-18.2857208,18.2857056-18.2857208h182.857132c10.0994568,0,18.2857361,8.1862793,18.2857361,18.2857208V321.5925598z M475.4285583,384l-36.5714111-36.5714417l0.0468445-73.1908264l36.5245667-36.5245972V384z M274.2444458,96.3504028c-24.3259277,14.0241699-24.3259277,49.2750244,0.000061,63.2991943C298.5704346,173.6737671,329.1430054,156.0484009,329.1430054,128S298.5704346,82.3261719,274.2444458,96.3504028z M475.4285889,201.1428223l-73.1428833,73.1428833v-36.5714111c0-17.5-12.2943115-32.1199951-28.7142944-35.7160034c17.8331909-19.5103149,28.7142944-45.4822998,28.7142944-73.9971313c0-60.5942993-49.1205444-109.7154541-109.7142944-109.7154541c-57.7845459,0-105.1348267,44.6731567-109.3999634,101.3674316c-19.447998-17.5422974-45.2045898-28.2246094-73.4571533-28.2246094C49.1211548,91.4285278,0,140.5496826,0,201.1439819c0,60.5925903,49.1211548,109.7131348,109.7142944,109.7131348H73.1428833V384h36.5714111v73.1428223c0,20.1983032,16.3731689,36.5714722,36.5714111,36.5714722h219.4285889c20.1982422,0,36.5714111-16.3731689,36.5714111-36.5714722v-36.5714111l73.1428833,73.1428833H512V201.1428223H475.4285889z M146.2849731,201.1430054c0-28.0484009-30.1351929-44.8863525-54.8984985-31.6496582c-27.3225098,14.6047363-25.53302,65.3989868,18.3278198,68.2209473V274.28479C29.0150757,271.7099609,12.666687,172,73.0599365,137.84375c48.8818359-27.645752,109.7970581,7.2024536,109.7970581,63.2992554H146.2849731z M255.9179688,191.2991943c-48.6519165-28.0483398-48.6519775-98.5500488,0-126.5984497C304.5698853,36.6524048,365.7150269,71.9031982,365.7150269,128C365.7150269,184.0967407,304.5698853,219.3475952,255.9179688,191.2991943z\"/>"
62866286
},
6287+
"audio": {
6288+
"width": 24,
6289+
"height": 24,
6290+
"svg": "<path d=\"M12 3v9.28c-.47-.17-.97-.28-1.5-.28C8.01 12 6 14.01 6 16.5S8.01 21 10.5 21c2.31 0 4.2-1.75 4.45-4H15V6h4V3h-7z\"/>"
6291+
},
6292+
"icon-file-pdf": {
6293+
"width": 24,
6294+
"height": 24,
6295+
"svg": "<path d=\"M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-8.5 7.5c0 .83-.67 1.5-1.5 1.5H9v2H7.5V7H10c.83 0 1.5.67 1.5 1.5v1zm5 2c0 .83-.67 1.5-1.5 1.5h-2.5V7H15c.83 0 1.5.67 1.5 1.5v3zm4-3H19v1h1.5V11H19v2h-1.5V7h3v1.5zM9 9.5h1v-1H9v1zM4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm10 5.5h1v-3h-1v3z\"/>"
6296+
},
62876297
"virtualbox-alt": {
62886298
"width": 512,
62896299
"height": 512,
@@ -7623,5 +7633,60 @@
76237633
"width": 24,
76247634
"height": 24,
76257635
"svg": "<path d=\"M 11.9975,13.9987C 10.8938,13.9987 10,13.1 10,11.9975C 10,10.8938 10.8938,10 11.9975,10C 13.105,10 13.9987,10.8938 13.9987,11.9975C 13.9987,13.1 13.105,13.9987 11.9975,13.9987 Z M 11.9975,3.99875C 7.5825,3.99875 3.99875,7.5775 3.99875,11.9975C 3.99875,16.4162 7.5825,20 11.9975,20C 16.4163,20 20,16.4162 20,11.9975C 20,7.5775 16.4163,3.99875 11.9975,3.99875 Z\"/>"
7636+
},
7637+
"zoomIn": {
7638+
"width": 24,
7639+
"height": 24,
7640+
"svg": "<path d=\"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z\"/>"
7641+
},
7642+
"zoomOut": {
7643+
"width": 24,
7644+
"height": 24,
7645+
"svg": "<path d=\"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7z\"/>"
7646+
},
7647+
"arrowBack": {
7648+
"width": 24,
7649+
"height": 24,
7650+
"svg": "<path d=\"M11.67 3.87L9.9 2.1 0 12l9.9 9.9 1.77-1.77L3.54 12z\"/>"
7651+
},
7652+
"arrowNext": {
7653+
"width": 24,
7654+
"height": 24,
7655+
"svg": "<path d=\"M5.88 4.12L13.76 12l-7.88 7.88L8 22l10-10L8 2z\"/>"
7656+
},
7657+
"playArrow": {
7658+
"width": 24,
7659+
"height": 24,
7660+
"svg": "<path d=\"M8 5v14l11-7z\"/>"
7661+
},
7662+
"pause": {
7663+
"width": 24,
7664+
"height": 24,
7665+
"svg": "<path d=\"M6 19h4V5H6v14zm8-14v14h4V5h-4z\"/>"
7666+
},
7667+
"fullscreen": {
7668+
"width": 24,
7669+
"height": 24,
7670+
"svg": "<path d=\"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z\"/>"
7671+
},
7672+
"fullscreenExit": {
7673+
"width": 24,
7674+
"height": 24,
7675+
"svg": "<path d=\"M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z\"/>"
7676+
},
7677+
"volumeUp": {
7678+
"width": 24,
7679+
"height": 24,
7680+
"svg": "<path d=\"M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z\"/>"
7681+
},
7682+
"volumeDown": {
7683+
"width": 24,
7684+
"height": 24,
7685+
"svg": "<path d=\"M18.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM5 9v6h4l5 5V4L9 9H5z\"/>"
7686+
},
7687+
"volumeMute": {
7688+
"width": 24,
7689+
"height": 24,
7690+
"svg": "<path d=\"M7 9v6h4l5 5V4l-5 5H7z\"/>"
76267691
}
76277692
}

src/assets/misc/file-icons-match.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function matchIcon(filename) {
203203
if (/\.s3m$/i.test(filename)) { return "audio"; }
204204
if (/\.sndh$/i.test(filename)) { return "audio"; }
205205
if (/\.wma$/i.test(filename)) { return "audio"; }
206+
if (/\.(ogg)$/i.test(filename)) { return "audio"; }
206207
if (/\.aug$/i.test(filename)) { return "augeas"; }
207208
if (/^aurelia\.json$/i.test(filename)) { return "aurelia"; }
208209
if (/\.ahk$/i.test(filename)) { return "ahk"; }
@@ -2177,7 +2178,7 @@ function matchIcon(filename) {
21772178
if (/\.webm$/i.test(filename)) { return "video"; }
21782179
if (/\.mpe?g$/i.test(filename)) { return "video"; }
21792180
if (/\.(asf|wmv)$/i.test(filename)) { return "video"; }
2180-
if (/\.(ogm|og[gv])$/i.test(filename)) { return "video"; }
2181+
if (/\.(ogm|ogv)$/i.test(filename)) { return "video"; }
21812182
if (/\.(vim|[gn]?vimrc)$/i.test(filename)) { return "vim"; }
21822183
if (/^[.gn_]?vim(rc|info)$/i.test(filename)) { return "vim"; }
21832184
if (/\.vmb$/i.test(filename)) { return "vim"; }

src/classes/docReader.class.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
class DocReader {
2+
constructor(opts) {
3+
pdfjsLib.GlobalWorkerOptions.workerSrc = './node_modules/pdfjs-dist/build/pdf.worker.js';
4+
const modalElementId = "modal_" + opts.modalId;
5+
const path = opts.path;
6+
const scale = 1;
7+
const canvas = document.getElementById(modalElementId).querySelector(".pdf_canvas");
8+
const context = canvas.getContext('2d');
9+
const loadingTask = pdfjsLib.getDocument(path);
10+
let pdfDoc = null,
11+
pageNum = 1,
12+
pageRendering = false,
13+
pageNumPending = null,
14+
zoom = 100
15+
16+
this.renderPage = (num) => {
17+
pageRendering = true;
18+
loadingTask.promise.then(function (pdf) {
19+
pdfDoc.getPage(num).then(function (page) {
20+
const viewport = page.getViewport({ scale: scale });
21+
canvas.height = viewport.height;
22+
canvas.width = viewport.width;
23+
24+
const renderContext = {
25+
canvasContext: context,
26+
viewport: viewport,
27+
};
28+
const renderTask = page.render(renderContext);
29+
renderTask.promise.then(function () {
30+
pageRendering = false;
31+
if (pageNumPending !== null) {
32+
renderPage(pageNumPending);
33+
pageNumPending = null;
34+
}
35+
});
36+
});
37+
});
38+
document.getElementById(modalElementId).querySelector(".page_num").textContent = num;
39+
}
40+
41+
this.queueRenderPage = (num) => {
42+
if (pageRendering) {
43+
pageNumPending = num;
44+
} else {
45+
this.renderPage(num);
46+
}
47+
}
48+
49+
this.onPrevPage = () => {
50+
if (pageNum <= 1) {
51+
return;
52+
}
53+
pageNum--;
54+
this.queueRenderPage(pageNum);
55+
}
56+
57+
this.onNextPage = () => {
58+
if (pageNum >= pdfDoc.numPages) {
59+
return;
60+
}
61+
pageNum++;
62+
this.queueRenderPage(pageNum);
63+
}
64+
65+
this.zoomIn = () => {
66+
if (zoom >= 200) {
67+
return;
68+
}
69+
zoom = zoom + 10;
70+
canvas.style.zoom = zoom + "%";
71+
}
72+
73+
this.zoomOut = () => {
74+
if (zoom <= 50) {
75+
return;
76+
}
77+
zoom = zoom - 10;
78+
canvas.style.zoom = zoom + "%";
79+
}
80+
81+
document.getElementById(modalElementId).querySelector(".previous_page").addEventListener('click', this.onPrevPage);
82+
document.getElementById(modalElementId).querySelector(".next_page").addEventListener('click', this.onNextPage);
83+
document.getElementById(modalElementId).querySelector(".zoom_in").addEventListener('click', this.zoomIn);
84+
document.getElementById(modalElementId).querySelector(".zoom_out").addEventListener('click', this.zoomOut);
85+
86+
pdfjsLib.getDocument(path).promise.then((pdfDoc_) => {
87+
pdfDoc = pdfDoc_;
88+
document.getElementById(modalElementId).querySelector(".page_count").textContent = pdfDoc.numPages;
89+
this.renderPage(pageNum);
90+
});
91+
}
92+
}
93+
94+
module.exports = {
95+
DocReader
96+
};

0 commit comments

Comments
 (0)