eaglelandsonce commited on
Commit
b950d11
·
verified ·
1 Parent(s): 71bac66

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +396 -18
index.html CHANGED
@@ -1,19 +1,397 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>PDF Slide Viewer</title>
7
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.16.105/pdf.min.js"></script>
8
+ <style>
9
+ body {
10
+ margin: 0;
11
+ overflow: hidden;
12
+ font-family: Arial, sans-serif;
13
+ background-color: #000;
14
+ color: #fff;
15
+ position: relative;
16
+ }
17
+ canvas {
18
+ display: block;
19
+ margin: 0 auto;
20
+ width: 100vw;
21
+ height: 100vh;
22
+ object-fit: contain;
23
+ cursor: crosshair;
24
+ }
25
+ .arrow-button {
26
+ position: absolute;
27
+ top: 50%;
28
+ transform: translateY(-50%);
29
+ background-color: rgba(0, 0, 0, 0.5);
30
+ color: #fff;
31
+ border: none;
32
+ font-size: 24px;
33
+ padding: 10px;
34
+ cursor: pointer;
35
+ z-index: 10;
36
+ }
37
+ .arrow-button:disabled {
38
+ cursor: not-allowed;
39
+ background-color: rgba(100, 100, 100, 0.5);
40
+ }
41
+ #prev-slide {
42
+ left: 10px;
43
+ }
44
+ #next-slide {
45
+ right: 10px;
46
+ }
47
+ .links-container {
48
+ position: absolute;
49
+ bottom: 20px;
50
+ left: 50%;
51
+ transform: translateX(-50%);
52
+ display: flex;
53
+ flex-wrap: wrap;
54
+ gap: 10px;
55
+ justify-content: center;
56
+ }
57
+ .link-button {
58
+ padding: 10px 15px;
59
+ background-color: #1a73e8;
60
+ color: #fff;
61
+ text-decoration: none;
62
+ font-size: 14px;
63
+ border-radius: 5px;
64
+ border: none;
65
+ cursor: pointer;
66
+ }
67
+ .link-button:hover {
68
+ background-color: #1558b8;
69
+ }
70
+ .toolbar {
71
+ position: absolute;
72
+ top: 20px;
73
+ left: 10px;
74
+ z-index: 10;
75
+ display: flex;
76
+ flex-direction: column;
77
+ gap: 10px;
78
+ }
79
+ .toolbar button {
80
+ width: 30px;
81
+ height: 30px;
82
+ font-size: 16px;
83
+ cursor: pointer;
84
+ border: none;
85
+ border-radius: 50%;
86
+ background-color: #444;
87
+ color: #fff;
88
+ text-align: center;
89
+ }
90
+ .toolbar button.active {
91
+ background-color: #1a73e8;
92
+ }
93
+ .color-button {
94
+ width: 30px;
95
+ height: 30px;
96
+ border-radius: 50%;
97
+ border: 2px solid #fff;
98
+ cursor: pointer;
99
+ }
100
+ .color-button.red {
101
+ background-color: red;
102
+ }
103
+ .color-button.green {
104
+ background-color: green;
105
+ }
106
+ .color-button.blue {
107
+ background-color: blue;
108
+ }
109
+ .color-button.yellow {
110
+ background-color: yellow;
111
+ }
112
+ .slider-container {
113
+ position: absolute;
114
+ bottom: 20px;
115
+ left: 10px;
116
+ display: flex;
117
+ flex-direction: column;
118
+ align-items: center;
119
+ z-index: 10;
120
+ }
121
+ #page-slider {
122
+ width: 200px;
123
+ }
124
+ #page-number-input {
125
+ margin-top: 10px;
126
+ width: 60px;
127
+ text-align: center;
128
+ font-size: 16px;
129
+ }
130
+ .flash-message {
131
+ position: absolute;
132
+ top: 10px;
133
+ left: 50%;
134
+ transform: translateX(-50%);
135
+ background-color: red;
136
+ color: white;
137
+ padding: 5px 10px;
138
+ border-radius: 5px;
139
+ font-size: 14px;
140
+ display: none;
141
+ z-index: 10;
142
+ }
143
+ /* Add styles for full-screen button */
144
+ #fullscreen-btn {
145
+ position: absolute;
146
+ top: 20px;
147
+ right: 10px;
148
+ z-index: 10;
149
+ background-color: #444;
150
+ color: #fff;
151
+ border: none;
152
+ font-size: 16px;
153
+ padding: 10px;
154
+ cursor: pointer;
155
+ border-radius: 5px;
156
+ }
157
+ #fullscreen-btn:hover {
158
+ background-color: #1a73e8;
159
+ }
160
+ </style>
161
+ </head>
162
+ <body>
163
+ <canvas id="pdf-canvas"></canvas>
164
+ <button id="prev-slide" class="arrow-button">&#8249;</button>
165
+ <button id="next-slide" class="arrow-button">&#8250;</button>
166
+ <div id="links-container" class="links-container"></div>
167
+ <div class="toolbar">
168
+ <button id="toggle-draw" class="color-button">D</button>
169
+ <button id="clear-draw" class="color-button">E</button>
170
+ <button class="color-button red" data-color="red"></button>
171
+ <button class="color-button green" data-color="green"></button>
172
+ <button class="color-button blue" data-color="blue"></button>
173
+ <button class="color-button yellow" data-color="yellow"></button>
174
+ </div>
175
+ <div class="slider-container">
176
+ <input type="range" id="page-slider" min="1" max="1" value="1">
177
+ <input type="number" id="page-number-input" min="1" value="1">
178
+ </div>
179
+ <div id="flash-message" class="flash-message">Invalid Page Number!</div>
180
+ <button id="fullscreen-btn">Full Screen</button>
181
+ <script>
182
+ const pdfUrl = 'mypdf.pdf'; // Replace with the path to your PDF file
183
+
184
+ const pdfCanvas = document.getElementById('pdf-canvas');
185
+ const ctx = pdfCanvas.getContext('2d');
186
+ const prevSlideBtn = document.getElementById('prev-slide');
187
+ const nextSlideBtn = document.getElementById('next-slide');
188
+ const linksContainer = document.getElementById('links-container');
189
+ const toggleDrawBtn = document.getElementById('toggle-draw');
190
+ const clearDrawBtn = document.getElementById('clear-draw');
191
+ const colorButtons = document.querySelectorAll('.color-button');
192
+ const pageSlider = document.getElementById('page-slider');
193
+ const pageNumberInput = document.getElementById('page-number-input');
194
+ const flashMessage = document.getElementById('flash-message');
195
+ // Get the toolbar (drawing tools) element for toggling visibility
196
+ const toolbar = document.querySelector('.toolbar');
197
+
198
+ let pdfDoc = null;
199
+ let currentPage = 1;
200
+ let totalPages = 0;
201
+ let isDrawing = false;
202
+ let drawMode = false;
203
+ let drawColor = 'red'; // Default drawing color
204
+
205
+ function clearLinks() {
206
+ linksContainer.innerHTML = '';
207
+ }
208
+
209
+ async function renderPage(pageNumber) {
210
+ const page = await pdfDoc.getPage(pageNumber);
211
+
212
+ const viewport = page.getViewport({ scale: 2 });
213
+ pdfCanvas.width = viewport.width;
214
+ pdfCanvas.height = viewport.height;
215
+
216
+ const renderContext = {
217
+ canvasContext: ctx,
218
+ viewport: viewport,
219
+ enableWebGL: true
220
+ };
221
+
222
+ ctx.clearRect(0, 0, pdfCanvas.width, pdfCanvas.height);
223
+ clearLinks();
224
+ await page.render(renderContext).promise;
225
+
226
+ const annotations = await page.getAnnotations();
227
+ annotations.forEach(annotation => {
228
+ if (annotation.url) {
229
+ const linkButton = document.createElement('a');
230
+ linkButton.href = annotation.url;
231
+ linkButton.target = '_blank';
232
+ linkButton.className = 'link-button';
233
+ linkButton.textContent = annotation.title || annotation.url;
234
+ linksContainer.appendChild(linkButton);
235
+ }
236
+ });
237
+
238
+ prevSlideBtn.disabled = currentPage === 1;
239
+ nextSlideBtn.disabled = currentPage === totalPages;
240
+ }
241
+
242
+ async function loadPdf() {
243
+ pdfDoc = await pdfjsLib.getDocument(pdfUrl).promise;
244
+ totalPages = pdfDoc.numPages;
245
+ pageSlider.max = totalPages;
246
+ renderPage(currentPage);
247
+ }
248
+
249
+ function showFlashMessage() {
250
+ flashMessage.style.display = 'block';
251
+ setTimeout(() => {
252
+ flashMessage.style.display = 'none';
253
+ }, 2000);
254
+ }
255
+
256
+ // Keyboard events
257
+ document.addEventListener('keydown', (event) => {
258
+ switch (event.key) {
259
+ case 'ArrowLeft':
260
+ if (currentPage > 1) {
261
+ currentPage--;
262
+ pageSlider.value = currentPage;
263
+ pageNumberInput.value = currentPage;
264
+ renderPage(currentPage);
265
+ }
266
+ break;
267
+ case 'ArrowRight':
268
+ if (currentPage < totalPages) {
269
+ currentPage++;
270
+ pageSlider.value = currentPage;
271
+ pageNumberInput.value = currentPage;
272
+ renderPage(currentPage);
273
+ }
274
+ break;
275
+ case 'd':
276
+ drawMode = true;
277
+ toggleDrawBtn.classList.add('active');
278
+ break;
279
+ case 's':
280
+ drawMode = false;
281
+ toggleDrawBtn.classList.remove('active');
282
+ break;
283
+ case 'e':
284
+ ctx.clearRect(0, 0, pdfCanvas.width, pdfCanvas.height);
285
+ renderPage(currentPage);
286
+ break;
287
+ case 'r':
288
+ drawColor = 'red';
289
+ break;
290
+ case 'g':
291
+ drawColor = 'green';
292
+ break;
293
+ case 'b':
294
+ drawColor = 'blue';
295
+ break;
296
+ case 'y':
297
+ drawColor = 'yellow';
298
+ break;
299
+ case 'h':
300
+ // Toggle the display of the toolbar (drawing tools)
301
+ if (toolbar.style.display === 'none') {
302
+ toolbar.style.display = 'flex';
303
+ } else {
304
+ toolbar.style.display = 'none';
305
+ }
306
+ break;
307
+ }
308
+ });
309
+
310
+ // Arrow button click events to change slides
311
+ prevSlideBtn.addEventListener('click', () => {
312
+ if (currentPage > 1) {
313
+ currentPage--;
314
+ pageSlider.value = currentPage;
315
+ pageNumberInput.value = currentPage;
316
+ renderPage(currentPage);
317
+ }
318
+ });
319
+
320
+ nextSlideBtn.addEventListener('click', () => {
321
+ if (currentPage < totalPages) {
322
+ currentPage++;
323
+ pageSlider.value = currentPage;
324
+ pageNumberInput.value = currentPage;
325
+ renderPage(currentPage);
326
+ }
327
+ });
328
+
329
+ // Slider and number input events
330
+ pageSlider.addEventListener('input', (event) => {
331
+ currentPage = parseInt(event.target.value);
332
+ pageNumberInput.value = currentPage;
333
+ renderPage(currentPage);
334
+ });
335
+
336
+ pageNumberInput.addEventListener('change', (event) => {
337
+ const page = parseInt(event.target.value);
338
+ if (page >= 1 && page <= totalPages) {
339
+ currentPage = page;
340
+ pageSlider.value = currentPage;
341
+ renderPage(currentPage);
342
+ } else {
343
+ showFlashMessage();
344
+ }
345
+ });
346
+
347
+ // ---- CHANGES START HERE: Scale mouse coordinates to match canvas's internal dimensions ----
348
+ pdfCanvas.addEventListener('mousedown', (e) => {
349
+ if (!drawMode) return;
350
+ isDrawing = true;
351
+ const rect = pdfCanvas.getBoundingClientRect();
352
+ const scaleX = pdfCanvas.width / rect.width;
353
+ const scaleY = pdfCanvas.height / rect.height;
354
+ const x = (e.clientX - rect.left) * scaleX;
355
+ const y = (e.clientY - rect.top) * scaleY;
356
+ ctx.beginPath();
357
+ ctx.moveTo(x, y);
358
+ });
359
+
360
+ pdfCanvas.addEventListener('mousemove', (e) => {
361
+ if (!isDrawing || !drawMode) return;
362
+ const rect = pdfCanvas.getBoundingClientRect();
363
+ const scaleX = pdfCanvas.width / rect.width;
364
+ const scaleY = pdfCanvas.height / rect.height;
365
+ const x = (e.clientX - rect.left) * scaleX;
366
+ const y = (e.clientY - rect.top) * scaleY;
367
+ ctx.lineTo(x, y);
368
+ ctx.strokeStyle = drawColor;
369
+ ctx.lineWidth = 2;
370
+ ctx.stroke();
371
+ });
372
+
373
+ pdfCanvas.addEventListener('mouseup', () => {
374
+ if (!drawMode) return;
375
+ isDrawing = false;
376
+ ctx.closePath();
377
+ });
378
+ // ---- CHANGES END HERE ----
379
+
380
+ loadPdf().catch(error => {
381
+ console.error('Error loading PDF:', error);
382
+ alert('Failed to load PDF. Please check the file path.');
383
+ });
384
+
385
+ // Fullscreen functionality
386
+ document.getElementById('fullscreen-btn').addEventListener('click', () => {
387
+ if (!document.fullscreenElement) {
388
+ document.documentElement.requestFullscreen();
389
+ } else {
390
+ if (document.exitFullscreen) {
391
+ document.exitFullscreen();
392
+ }
393
+ }
394
+ });
395
+ </script>
396
+ </body>
397
  </html>