-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
735 lines (646 loc) · 31.8 KB
/
Copy pathindex.html
File metadata and controls
735 lines (646 loc) · 31.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Office Editor - LibreOffice in Browser</title>
<!-- Service worker disabled - using server-side COOP/COEP headers instead -->
<!-- <script src="coi-serviceworker.js"></script> -->
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
--primary: #1a73e8;
--primary-dark: #1557b0;
--bg: #f8f9fa;
--border: #dadce0;
--text: #202124;
--text-secondary: #5f6368;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
min-height: 100vh;
display: flex;
flex-direction: column;
}
/* Header */
.header {
background: white;
border-bottom: 1px solid var(--border);
padding: 8px 16px;
display: flex;
align-items: center;
gap: 12px;
height: 56px;
}
.logo {
width: 40px;
height: 40px;
background: linear-gradient(135deg, #4285f4, #1a73e8);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
}
.logo svg { width: 24px; height: 24px; fill: white; }
.title-area { flex: 1; }
.doc-title {
font-size: 18px;
font-weight: 500;
border: none;
background: transparent;
padding: 4px 8px;
border-radius: 4px;
width: 300px;
}
.doc-title:hover { background: #e8eaed; }
.doc-title:focus { outline: none; box-shadow: 0 0 0 2px var(--primary); }
.status {
font-size: 12px;
color: #1e8e3e;
padding-left: 8px;
}
/* Toolbar */
.toolbar {
background: var(--bg);
border-bottom: 1px solid var(--border);
padding: 4px 12px;
display: flex;
align-items: center;
gap: 4px;
overflow-x: auto;
}
.toolbar-group {
display: flex;
align-items: center;
gap: 2px;
padding: 0 8px;
border-right: 1px solid var(--border);
}
.toolbar-group:last-child { border-right: none; }
.tb-btn {
width: 28px;
height: 28px;
border: none;
background: transparent;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
.tb-btn:hover { background: #e8eaed; }
.tb-btn:active { background: #d2e3fc; }
.tb-btn svg { width: 18px; height: 18px; }
.tb-select {
height: 28px;
padding: 0 20px 0 8px;
border: none;
background: transparent;
font-size: 13px;
cursor: pointer;
border-radius: 4px;
appearance: none;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24'%3E%3Cpath fill='%235f6368' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 4px center;
}
.tb-select:hover { background-color: #e8eaed; }
/* Main */
.main {
flex: 1;
display: flex;
background: #525659;
overflow: hidden;
}
.canvas-area {
flex: 1;
display: flex;
align-items: flex-start;
justify-content: center;
padding: 20px;
overflow: auto;
}
#qtcanvas {
background: white;
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
/* Status bar */
.statusbar {
background: white;
border-top: 1px solid var(--border);
padding: 4px 16px;
font-size: 11px;
color: var(--text-secondary);
display: flex;
justify-content: space-between;
}
/* Loading */
.loading-screen {
position: fixed;
inset: 0;
background: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 1000;
}
.loading-screen.hidden { display: none; }
.spinner {
width: 48px;
height: 48px;
border: 4px solid #e8eaed;
border-top-color: var(--primary);
border-radius: 50%;
animation: spin 0.8s linear infinite;
margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 18px; font-weight: 500; margin-bottom: 8px; }
.loading-sub { color: var(--text-secondary); margin-bottom: 20px; }
.progress-bar {
width: 300px;
height: 4px;
background: #e8eaed;
border-radius: 2px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: var(--primary);
width: 0%;
transition: width 0.3s;
}
.loading-warning {
margin-top: 24px;
padding: 16px;
background: #fff3cd;
border: 1px solid #ffc107;
border-radius: 8px;
max-width: 400px;
text-align: center;
}
.loading-warning h4 { color: #856404; margin-bottom: 8px; }
.loading-warning p { font-size: 13px; color: #856404; }
/* Error */
.error-screen {
position: fixed;
inset: 0;
background: white;
display: none;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 1000;
padding: 24px;
}
.error-screen.show { display: flex; }
.error-icon {
width: 64px;
height: 64px;
background: #fce8e6;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 16px;
}
.error-icon svg { width: 32px; height: 32px; fill: #d93025; }
.error-title { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.error-msg { color: var(--text-secondary); text-align: center; max-width: 500px; margin-bottom: 24px; line-height: 1.6; }
.error-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn {
padding: 10px 24px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; border: none; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
/* Modal */
.modal-bg {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
display: none;
align-items: center;
justify-content: center;
z-index: 2000;
}
.modal-bg.show { display: flex; }
.modal {
background: white;
border-radius: 12px;
max-width: 450px;
width: 90%;
}
.modal-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-title { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-secondary); }
.modal-body { padding: 20px; }
.export-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.export-opt {
padding: 16px;
border: 2px solid var(--border);
border-radius: 8px;
text-align: center;
cursor: pointer;
}
.export-opt:hover, .export-opt.selected { border-color: var(--primary); background: #e8f0fe; }
.export-opt-icon { font-size: 28px; margin-bottom: 8px; }
.export-opt-title { font-weight: 500; }
.export-opt-ext { font-size: 12px; color: var(--text-secondary); }
.modal-footer {
padding: 16px 20px;
border-top: 1px solid var(--border);
display: flex;
justify-content: flex-end;
gap: 12px;
}
/* Toast */
.toast-box {
position: fixed;
bottom: 40px;
left: 50%;
transform: translateX(-50%);
z-index: 3000;
}
.toast {
background: #323232;
color: white;
padding: 12px 24px;
border-radius: 8px;
font-size: 14px;
}
.toast.success { background: #1e8e3e; }
.toast.error { background: #d93025; }
/* Hidden */
#fileInput, #imgInput { display: none; }
</style>
</head>
<body>
<!-- Header -->
<header class="header">
<div class="logo">
<svg viewBox="0 0 24 24"><path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z"/></svg>
</div>
<div class="title-area">
<input type="text" class="doc-title" value="Untitled document" id="docTitle">
<div class="status">✓ Ready</div>
</div>
</header>
<!-- Toolbar -->
<div class="toolbar">
<div class="toolbar-group">
<button class="tb-btn" id="newBtn" title="New"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"/></svg></button>
<button class="tb-btn" id="openBtn" title="Open"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M20 6h-8l-2-2H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm0 12H4V8h16v10z"/></svg></button>
<button class="tb-btn" id="saveBtn" title="Save"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg></button>
<button class="tb-btn" id="exportBtn" title="Export"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 12v7H5v-7H3v7c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-7h-2zm-6 .67l2.59-2.58L17 11.5l-5 5-5-5 1.41-1.41L11 12.67V3h2v9.67z"/></svg></button>
<button class="tb-btn" id="printBtn" title="Print"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 8H5c-1.66 0-3 1.34-3 3v6h4v4h12v-4h4v-6c0-1.66-1.34-3-3-3zm-3 11H8v-5h8v5zm3-7c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-1-9H6v4h12V3z"/></svg></button>
</div>
<div class="toolbar-group">
<button class="tb-btn" id="undoBtn" title="Undo"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z"/></svg></button>
<button class="tb-btn" id="redoBtn" title="Redo"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z"/></svg></button>
</div>
<div class="toolbar-group">
<select class="tb-select" id="fontSel" style="width:120px">
<option>Liberation Sans</option>
<option>Liberation Serif</option>
<option>DejaVu Sans</option>
</select>
<select class="tb-select" id="sizeSel" style="width:55px">
<option>10</option>
<option>11</option>
<option selected>12</option>
<option>14</option>
<option>18</option>
<option>24</option>
</select>
</div>
<div class="toolbar-group">
<button class="tb-btn" id="boldBtn" title="Bold"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"/></svg></button>
<button class="tb-btn" id="italicBtn" title="Italic"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"/></svg></button>
<button class="tb-btn" id="underlineBtn" title="Underline"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2.69 6 6 6zm-7 2v2h14v-2H5z"/></svg></button>
</div>
<div class="toolbar-group">
<button class="tb-btn" id="leftBtn" title="Align Left"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z"/></svg></button>
<button class="tb-btn" id="centerBtn" title="Center"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z"/></svg></button>
<button class="tb-btn" id="rightBtn" title="Align Right"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z"/></svg></button>
</div>
<div class="toolbar-group">
<button class="tb-btn" id="bulletBtn" title="Bullets"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z"/></svg></button>
<button class="tb-btn" id="numBtn" title="Numbering"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"/></svg></button>
</div>
<div class="toolbar-group">
<button class="tb-btn" id="imgBtn" title="Insert Image"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg></button>
<button class="tb-btn" id="tableBtn" title="Insert Table"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM8 20H4v-4h4v4zm0-6H4v-4h4v4zm0-6H4V4h4v4zm6 12h-4v-4h4v4zm0-6h-4v-4h4v4zm0-6h-4V4h4v4zm6 12h-4v-4h4v4zm0-6h-4v-4h4v4zm0-6h-4V4h4v4z"/></svg></button>
<button class="tb-btn" id="linkBtn" title="Insert Link"><svg viewBox="0 0 24 24" fill="currentColor"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg></button>
</div>
</div>
<!-- Main -->
<main class="main">
<div class="canvas-area">
<canvas id="qtcanvas" width="816" height="1056"></canvas>
</div>
</main>
<!-- Status Bar -->
<footer class="statusbar">
<span id="pageInfo">Page 1</span>
<span id="zoomInfo">100%</span>
</footer>
<!-- Loading -->
<div class="loading-screen" id="loadingScreen">
<div class="spinner"></div>
<div class="loading-text" id="loadingText">Loading LibreOffice...</div>
<div class="loading-sub" id="loadingSub">Please wait while we initialize the office suite</div>
<div class="progress-bar"><div class="progress-fill" id="progressFill"></div></div>
<div class="loading-warning">
<h4>⏳ First Load Notice</h4>
<p>LibreOffice WASM is ~300MB. First load takes 1-3 minutes. Subsequent loads are instant due to caching.</p>
</div>
</div>
<!-- Error -->
<div class="error-screen" id="errorScreen">
<div class="error-icon"><svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/></svg></div>
<h2 class="error-title">Unable to Load LibreOffice</h2>
<p class="error-msg" id="errorMsg">SharedArrayBuffer is not available. The page may need to reload to enable cross-origin isolation.</p>
<div class="error-actions">
<button class="btn btn-primary" onclick="location.reload()">Reload Page</button>
<a href="https://zetaoffice.net/#tryit" target="_blank" class="btn btn-secondary">Try ZetaOffice Demo</a>
</div>
</div>
<!-- Export Modal -->
<div class="modal-bg" id="exportModal">
<div class="modal">
<div class="modal-header">
<h3 class="modal-title">Export Document</h3>
<button class="modal-close" onclick="closeModal()">×</button>
</div>
<div class="modal-body">
<div class="export-grid">
<div class="export-opt selected" data-fmt="odt">
<div class="export-opt-icon">📄</div>
<div class="export-opt-title">ODF</div>
<div class="export-opt-ext">.odt</div>
</div>
<div class="export-opt" data-fmt="docx">
<div class="export-opt-icon">📝</div>
<div class="export-opt-title">Word</div>
<div class="export-opt-ext">.docx</div>
</div>
<div class="export-opt" data-fmt="pdf">
<div class="export-opt-icon">📕</div>
<div class="export-opt-title">PDF</div>
<div class="export-opt-ext">.pdf</div>
</div>
<div class="export-opt" data-fmt="html">
<div class="export-opt-icon">🌐</div>
<div class="export-opt-title">HTML</div>
<div class="export-opt-ext">.html</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" onclick="closeModal()">Cancel</button>
<button class="btn btn-primary" id="doExportBtn">Export</button>
</div>
</div>
</div>
<!-- Toast -->
<div class="toast-box" id="toastBox"></div>
<!-- File inputs -->
<input type="file" id="fileInput" accept=".odt,.ods,.odp,.docx,.xlsx,.pptx,.doc,.xls,.ppt,.rtf,.txt">
<input type="file" id="imgInput" accept="image/*">
<script>
// Worker Blob URL polyfill - fixes cross-origin Worker restriction
(function() {
const OriginalWorker = window.Worker;
const workerBlobCache = new Map();
window.Worker = function(scriptURL, options) {
const url = new URL(scriptURL, window.location.href);
// If same-origin, use original Worker
if (url.origin === window.location.origin) {
return new OriginalWorker(scriptURL, options);
}
// For cross-origin, we need to fetch and create blob
// But Worker constructor is synchronous, so we use a wrapper approach
console.log('[Worker Polyfill] Intercepting cross-origin worker:', url.href);
// Create a blob that imports the cross-origin script
// This works because importScripts() in workers can load cross-origin
const workerCode = `importScripts('${url.href}');`;
const blob = new Blob([workerCode], { type: 'application/javascript' });
const blobURL = URL.createObjectURL(blob);
try {
return new OriginalWorker(blobURL, options);
} catch (e) {
console.error('[Worker Polyfill] Blob worker failed:', e);
// Fallback: try original (will likely fail but gives better error)
return new OriginalWorker(scriptURL, options);
}
};
// Preserve Worker properties
window.Worker.prototype = OriginalWorker.prototype;
console.log('[Worker Polyfill] Cross-origin worker polyfill installed');
})();
// Config - Use local proxy to avoid CORS/COEP issues
const CDN = '/cdn/zetaoffice_latest/';
// State
let zetajs, css, desktop, dispatcher, model, controller;
let exportFmt = 'odt';
// Helpers
function toast(msg, type = '') {
const box = document.getElementById('toastBox');
box.innerHTML = `<div class="toast ${type}">${msg}</div>`;
setTimeout(() => box.innerHTML = '', 3000);
}
function showModal() { document.getElementById('exportModal').classList.add('show'); }
function closeModal() { document.getElementById('exportModal').classList.remove('show'); }
// UNO
function exec(cmd, args = []) {
if (!dispatcher || !controller) return;
try {
dispatcher.executeDispatch(controller.getFrame(), '.uno:' + cmd, '', 0, args);
} catch (e) { console.error(cmd, e); }
}
function prop(n, v) {
if (!zetajs) return null;
const p = new css.beans.PropertyValue();
p.Name = n; p.Value = v;
return p;
}
// File ops
async function openFile(file) {
if (!desktop || !Module?.FS) { toast('Not ready', 'error'); return; }
try {
const data = new Uint8Array(await file.arrayBuffer());
const path = '/tmp/' + file.name;
Module.FS.writeFile(path, data);
model = desktop.loadComponentFromURL('file://' + path, '_default', 0, []);
if (model) {
controller = model.getCurrentController();
document.getElementById('docTitle').value = file.name.replace(/\.[^/.]+$/, '');
toast('Opened: ' + file.name, 'success');
}
} catch (e) { toast('Error: ' + e.message, 'error'); }
}
function doExport(fmt) {
if (!model || !Module?.FS) { toast('No document', 'error'); return; }
const title = document.getElementById('docTitle').value || 'Untitled';
const filters = {
odt: { f: 'writer8', e: '.odt' },
docx: { f: 'MS Word 2007 XML', e: '.docx' },
pdf: { f: 'writer_pdf_Export', e: '.pdf' },
html: { f: 'HTML (StarWriter)', e: '.html' }
};
const fi = filters[fmt] || filters.odt;
const fn = title + fi.e;
const path = '/tmp/' + fn;
try {
model.storeToURL('file://' + path, [prop('FilterName', fi.f), prop('Overwrite', true)]);
const d = Module.FS.readFile(path);
const url = URL.createObjectURL(new Blob([d]));
const a = document.createElement('a');
a.href = url; a.download = fn; a.click();
URL.revokeObjectURL(url);
toast('Exported: ' + fn, 'success');
} catch (e) { toast('Error: ' + e.message, 'error'); }
}
function newDoc() {
if (!desktop) return;
try {
model = desktop.loadComponentFromURL('private:factory/swriter', '_default', 0, []);
if (model) { controller = model.getCurrentController(); document.getElementById('docTitle').value = 'Untitled document'; }
} catch (e) { console.error(e); }
}
// Toolbar
function setupToolbar() {
document.getElementById('newBtn').onclick = newDoc;
document.getElementById('openBtn').onclick = () => document.getElementById('fileInput').click();
document.getElementById('saveBtn').onclick = () => doExport(exportFmt);
document.getElementById('exportBtn').onclick = showModal;
document.getElementById('printBtn').onclick = () => exec('Print');
document.getElementById('undoBtn').onclick = () => exec('Undo');
document.getElementById('redoBtn').onclick = () => exec('Redo');
document.getElementById('boldBtn').onclick = () => exec('Bold');
document.getElementById('italicBtn').onclick = () => exec('Italic');
document.getElementById('underlineBtn').onclick = () => exec('Underline');
document.getElementById('leftBtn').onclick = () => exec('LeftPara');
document.getElementById('centerBtn').onclick = () => exec('CenterPara');
document.getElementById('rightBtn').onclick = () => exec('RightPara');
document.getElementById('bulletBtn').onclick = () => exec('DefaultBullet');
document.getElementById('numBtn').onclick = () => exec('DefaultNumbering');
document.getElementById('imgBtn').onclick = () => document.getElementById('imgInput').click();
document.getElementById('tableBtn').onclick = () => exec('InsertTable');
document.getElementById('linkBtn').onclick = () => exec('InsertHyperlink');
document.getElementById('fontSel').onchange = (e) => exec('CharFontName', [prop('CharFontName', e.target.value)]);
document.getElementById('sizeSel').onchange = (e) => exec('FontHeight', [prop('FontHeight', parseFloat(e.target.value))]);
document.getElementById('fileInput').onchange = (e) => { if (e.target.files[0]) openFile(e.target.files[0]); };
document.getElementById('imgInput').onchange = async (e) => {
if (e.target.files[0] && Module?.FS) {
const f = e.target.files[0];
Module.FS.writeFile('/tmp/' + f.name, new Uint8Array(await f.arrayBuffer()));
exec('InsertGraphic', [prop('FileName', 'file:///tmp/' + f.name)]);
}
};
document.querySelectorAll('.export-opt').forEach(o => {
o.onclick = () => {
document.querySelectorAll('.export-opt').forEach(x => x.classList.remove('selected'));
o.classList.add('selected');
exportFmt = o.dataset.fmt;
};
});
document.getElementById('doExportBtn').onclick = () => { doExport(exportFmt); closeModal(); };
document.addEventListener('keydown', (e) => {
if (e.ctrlKey || e.metaKey) {
switch(e.key.toLowerCase()) {
case 'b': e.preventDefault(); exec('Bold'); break;
case 'i': e.preventDefault(); exec('Italic'); break;
case 'u': e.preventDefault(); exec('Underline'); break;
case 's': e.preventDefault(); doExport(exportFmt); break;
case 'o': e.preventDefault(); document.getElementById('fileInput').click(); break;
case 'z': e.preventDefault(); exec('Undo'); break;
}
}
});
}
// Init ZetaJS
function initZetaJS() {
if (!window.zetajs) return false;
zetajs = window.zetajs;
css = zetajs.uno.com.sun.star;
desktop = css.frame.Desktop.create(zetajs.getUnoComponentContext());
dispatcher = css.frame.DispatchHelper.create(zetajs.getUnoComponentContext());
return true;
}
// Load LibreOffice
function loadLO() {
const progress = document.getElementById('progressFill');
const text = document.getElementById('loadingText');
const sub = document.getElementById('loadingSub');
// Check SharedArrayBuffer
if (typeof SharedArrayBuffer === 'undefined') {
document.getElementById('loadingScreen').classList.add('hidden');
document.getElementById('errorScreen').classList.add('show');
document.getElementById('errorMsg').textContent =
'SharedArrayBuffer is not available. Click "Reload Page" - the service worker needs one reload to activate cross-origin isolation.';
return;
}
// Module config
window.Module = {
canvas: document.getElementById('qtcanvas'),
locateFile: (p) => CDN + p,
onRuntimeInitialized: () => { text.textContent = 'Starting...'; progress.style.width = '90%'; },
setStatus: (t) => { if (t) { sub.textContent = t; const m = t.match(/(\d+)\/(\d+)/); if (m) progress.style.width = (m[1]/m[2]*80) + '%'; } },
print: console.log,
printErr: console.error,
uno_scripts: [window.location.origin + CDN + 'zeta.js']
};
text.textContent = 'Downloading LibreOffice...';
sub.textContent = 'First load is ~300MB';
progress.style.width = '10%';
const script = document.createElement('script');
script.src = CDN + 'soffice.js';
script.onload = () => {
const check = setInterval(() => {
if (window.zetajs && initZetaJS()) {
clearInterval(check);
progress.style.width = '100%';
text.textContent = 'Ready!';
setTimeout(() => {
document.getElementById('loadingScreen').classList.add('hidden');
newDoc();
toast('LibreOffice loaded!', 'success');
}, 500);
}
}, 500);
};
script.onerror = () => {
document.getElementById('loadingScreen').classList.add('hidden');
document.getElementById('errorMsg').textContent = 'Failed to load from CDN.';
document.getElementById('errorScreen').classList.add('show');
};
document.body.appendChild(script);
}
// Start
document.addEventListener('DOMContentLoaded', () => {
setupToolbar();
loadLO();
});
</script>
</body>
</html>