@files-preview-app/preview-file 1.1.5 → 1.2.0

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/dist/angular.cjs CHANGED
@@ -4,9 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@angular/core');
6
6
  var common = require('@angular/common');
7
- var DOMPurify = require('dompurify');
7
+ var DOMPurify5 = require('dompurify');
8
8
  var docx = require('docx-preview');
9
- var ExcelJS = require('exceljs');
9
+ var XLSX = require('xlsx');
10
10
  var hljs = require('highlight.js');
11
11
  var fflate = require('fflate');
12
12
  var marked = require('marked');
@@ -15,6 +15,7 @@ var THREE = require('three');
15
15
  var STLLoader_js = require('three/examples/jsm/loaders/STLLoader.js');
16
16
  var OBJLoader_js = require('three/examples/jsm/loaders/OBJLoader.js');
17
17
  var OrbitControls_js = require('three/examples/jsm/controls/OrbitControls.js');
18
+ var rtf_js = require('rtf.js');
18
19
 
19
20
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
20
21
 
@@ -36,9 +37,9 @@ function _interopNamespace(e) {
36
37
  return Object.freeze(n);
37
38
  }
38
39
 
39
- var DOMPurify__default = /*#__PURE__*/_interopDefault(DOMPurify);
40
+ var DOMPurify5__default = /*#__PURE__*/_interopDefault(DOMPurify5);
40
41
  var docx__namespace = /*#__PURE__*/_interopNamespace(docx);
41
- var ExcelJS__default = /*#__PURE__*/_interopDefault(ExcelJS);
42
+ var XLSX__namespace = /*#__PURE__*/_interopNamespace(XLSX);
42
43
  var hljs__default = /*#__PURE__*/_interopDefault(hljs);
43
44
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
44
45
 
@@ -151,7 +152,9 @@ var MAGIC_NUMBERS = [
151
152
  { bytes: [37, 80, 68, 70], mime: "application/pdf" },
152
153
  // %PDF
153
154
  { bytes: [80, 75, 3, 4], mime: "application/zip" },
154
- // PK.. (ZIP/DOCX/XLSX/PPTX)
155
+ // PK.. (ZIP/DOCX/XLSX/PPTX/ODT/ODS/ODP)
156
+ { bytes: [208, 207, 17, 224, 161, 177, 26, 225], mime: "application/x-cfbf" },
157
+ // CFBF/OLE2 (DOC/XLS/PPT)
155
158
  { bytes: [137, 80, 78, 71, 13, 10, 26, 10], mime: "image/png" },
156
159
  // PNG
157
160
  { bytes: [255, 216, 255], mime: "image/jpeg" },
@@ -186,14 +189,40 @@ var MAGIC_NUMBERS = [
186
189
  // RTF
187
190
  ];
188
191
  var EXTENSION_MIME_MAP = {
189
- // Documents
192
+ // Documents — Modern OOXML
190
193
  ".pdf": "application/pdf",
191
194
  ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
195
+ ".docm": "application/vnd.ms-word.document.macroEnabled.12",
196
+ ".dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
197
+ ".dotm": "application/vnd.ms-word.template.macroEnabled.12",
192
198
  ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
199
+ ".xlsm": "application/vnd.ms-excel.sheet.macroEnabled.12",
200
+ ".xlsb": "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
201
+ ".xltx": "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
202
+ ".xltm": "application/vnd.ms-excel.template.macroEnabled.12",
193
203
  ".xls": "application/vnd.ms-excel",
194
204
  ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
205
+ ".ppsx": "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
206
+ ".pptm": "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
207
+ ".ppsm": "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
208
+ ".potx": "application/vnd.openxmlformats-officedocument.presentationml.template",
209
+ ".potm": "application/vnd.ms-powerpoint.template.macroEnabled.12",
195
210
  ".csv": "text/csv",
196
211
  ".tsv": "text/tab-separated-values",
212
+ // Documents — Legacy Binary (CFBF/OLE2)
213
+ ".doc": "application/msword",
214
+ ".dot": "application/msword",
215
+ ".ppt": "application/vnd.ms-powerpoint",
216
+ ".pps": "application/vnd.ms-powerpoint",
217
+ ".pot": "application/vnd.ms-powerpoint",
218
+ // Documents — OpenDocument (ODF)
219
+ ".odt": "application/vnd.oasis.opendocument.text",
220
+ ".ods": "application/vnd.oasis.opendocument.spreadsheet",
221
+ ".odp": "application/vnd.oasis.opendocument.presentation",
222
+ ".odg": "application/vnd.oasis.opendocument.graphics",
223
+ ".odf": "application/vnd.oasis.opendocument.formula",
224
+ // Documents — RTF
225
+ ".rtf": "text/rtf",
197
226
  // Images
198
227
  ".png": "image/png",
199
228
  ".jpg": "image/jpeg",
@@ -287,7 +316,7 @@ function detectMagicBytes(buffer) {
287
316
  }
288
317
  function detectOoxmlType(buffer) {
289
318
  const text = new TextDecoder("ascii", { fatal: false }).decode(
290
- new Uint8Array(buffer.slice(0, 4e3))
319
+ new Uint8Array(buffer.slice(0, 8e3))
291
320
  );
292
321
  if (text.includes("word/")) {
293
322
  return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
@@ -298,6 +327,21 @@ function detectOoxmlType(buffer) {
298
327
  if (text.includes("ppt/")) {
299
328
  return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
300
329
  }
330
+ if (text.includes("application/vnd.oasis.opendocument.text")) {
331
+ return "application/vnd.oasis.opendocument.text";
332
+ }
333
+ if (text.includes("application/vnd.oasis.opendocument.spreadsheet")) {
334
+ return "application/vnd.oasis.opendocument.spreadsheet";
335
+ }
336
+ if (text.includes("application/vnd.oasis.opendocument.presentation")) {
337
+ return "application/vnd.oasis.opendocument.presentation";
338
+ }
339
+ if (text.includes("application/vnd.oasis.opendocument.graphics")) {
340
+ return "application/vnd.oasis.opendocument.graphics";
341
+ }
342
+ if (text.includes("application/vnd.oasis.opendocument.formula")) {
343
+ return "application/vnd.oasis.opendocument.formula";
344
+ }
301
345
  return "application/zip";
302
346
  }
303
347
  function extractExtension(nameOrUrl) {
@@ -374,7 +418,7 @@ async function sourceToArrayBuffer(source, signal) {
374
418
  return { buffer, metadata };
375
419
  }
376
420
  function sanitizeSVG(svg) {
377
- return DOMPurify__default.default.sanitize(svg, {
421
+ return DOMPurify5__default.default.sanitize(svg, {
378
422
  USE_PROFILES: { svg: true, svgFilters: true }
379
423
  });
380
424
  }
@@ -942,6 +986,192 @@ var FilePreviewViewer = class {
942
986
  this.contentEl.appendChild(errorEl);
943
987
  }
944
988
  };
989
+ var CfbfReader = class {
990
+ view;
991
+ u8;
992
+ sectorSize;
993
+ miniSectorSize;
994
+ miniStreamCutoff;
995
+ fat = [];
996
+ miniFat = [];
997
+ entries = /* @__PURE__ */ new Map();
998
+ miniStream = new Uint8Array(0);
999
+ constructor(buffer) {
1000
+ this.u8 = new Uint8Array(buffer);
1001
+ this.view = new DataView(buffer);
1002
+ if (!this.isValid()) {
1003
+ throw new Error("Invalid CFBF / OLE2 file header signature");
1004
+ }
1005
+ const sectorShift = this.view.getUint16(30, true);
1006
+ this.sectorSize = 1 << sectorShift;
1007
+ const miniSectorShift = this.view.getUint16(32, true);
1008
+ this.miniSectorSize = 1 << miniSectorShift;
1009
+ this.miniStreamCutoff = this.view.getUint32(56, true) || 4096;
1010
+ this.parseFat();
1011
+ this.parseDirectory();
1012
+ this.parseMiniFat();
1013
+ }
1014
+ /** Check if the magic 8-byte signature matches [MS-CFB] */
1015
+ isValid() {
1016
+ if (this.u8.length < 512) return false;
1017
+ const sig = [208, 207, 17, 224, 161, 177, 26, 225];
1018
+ return sig.every((b, i) => this.u8[i] === b);
1019
+ }
1020
+ /** Return all directory stream/storage entries found in the file */
1021
+ listEntries() {
1022
+ return Array.from(this.entries.values());
1023
+ }
1024
+ /** Check if a stream exists */
1025
+ hasStream(name) {
1026
+ return this.entries.has(name) || this.findEntryCaseInsensitive(name) !== null;
1027
+ }
1028
+ /**
1029
+ * Read raw bytes of a named stream (e.g. "WordDocument", "PowerPoint Document", "Workbook")
1030
+ */
1031
+ readStream(name) {
1032
+ const entry = this.entries.get(name) || this.findEntryCaseInsensitive(name);
1033
+ if (!entry) return null;
1034
+ if (entry.size === 0) return new Uint8Array(0);
1035
+ if (entry.size < this.miniStreamCutoff && entry.type !== 5) {
1036
+ return this.readMiniStream(entry.startSector, entry.size);
1037
+ } else {
1038
+ return this.readRegularStream(entry.startSector, entry.size);
1039
+ }
1040
+ }
1041
+ findEntryCaseInsensitive(name) {
1042
+ const lower = name.toLowerCase();
1043
+ for (const [key, val] of this.entries.entries()) {
1044
+ if (key.toLowerCase() === lower) return val;
1045
+ }
1046
+ return null;
1047
+ }
1048
+ getSectorOffset(sectId) {
1049
+ return (sectId + 1) * this.sectorSize;
1050
+ }
1051
+ parseFat() {
1052
+ this.view.getUint32(44, true);
1053
+ const difat = [];
1054
+ for (let i = 0; i < 109; i++) {
1055
+ const sect = this.view.getUint32(76 + i * 4, true);
1056
+ if (sect !== 4294967295 && sect !== 4294967294) {
1057
+ difat.push(sect);
1058
+ }
1059
+ }
1060
+ let difatSect = this.view.getUint32(68, true);
1061
+ const csectDif = this.view.getUint32(72, true);
1062
+ const entriesPerSector = this.sectorSize / 4 - 1;
1063
+ for (let i = 0; i < csectDif && difatSect < 4294967294; i++) {
1064
+ const offset = this.getSectorOffset(difatSect);
1065
+ for (let j = 0; j < entriesPerSector; j++) {
1066
+ const sect = this.view.getUint32(offset + j * 4, true);
1067
+ if (sect !== 4294967295 && sect !== 4294967294) {
1068
+ difat.push(sect);
1069
+ }
1070
+ }
1071
+ difatSect = this.view.getUint32(offset + entriesPerSector * 4, true);
1072
+ }
1073
+ for (const fatSect of difat) {
1074
+ if (fatSect >= 4294967294) continue;
1075
+ const offset = this.getSectorOffset(fatSect);
1076
+ const count = this.sectorSize / 4;
1077
+ for (let j = 0; j < count; j++) {
1078
+ this.fat.push(this.view.getUint32(offset + j * 4, true));
1079
+ }
1080
+ }
1081
+ }
1082
+ parseDirectory() {
1083
+ const dirStartSect = this.view.getUint32(48, true);
1084
+ const dirBytes = this.readRegularStream(dirStartSect);
1085
+ const dirView = new DataView(dirBytes.buffer, dirBytes.byteOffset, dirBytes.byteLength);
1086
+ const entryCount = dirBytes.length / 128;
1087
+ for (let i = 0; i < entryCount; i++) {
1088
+ const offset = i * 128;
1089
+ const type = dirView.getUint8(offset + 66);
1090
+ if (type === 0) continue;
1091
+ const nameLen = dirView.getUint16(offset + 64, true);
1092
+ let name = "";
1093
+ if (nameLen > 2) {
1094
+ const charCount = nameLen / 2 - 1;
1095
+ const chars = [];
1096
+ for (let c = 0; c < charCount; c++) {
1097
+ const charCode = dirView.getUint16(offset + c * 2, true);
1098
+ chars.push(String.fromCharCode(charCode));
1099
+ }
1100
+ name = chars.join("");
1101
+ }
1102
+ const startSector = dirView.getUint32(offset + 116, true);
1103
+ const size = dirView.getUint32(offset + 120, true);
1104
+ const entry = { name, type, size, startSector };
1105
+ this.entries.set(name, entry);
1106
+ if (type === 5) {
1107
+ this.miniStream = this.readRegularStream(startSector, size);
1108
+ }
1109
+ }
1110
+ }
1111
+ parseMiniFat() {
1112
+ const miniFatStart = this.view.getUint32(60, true);
1113
+ const csectMiniFat = this.view.getUint32(64, true);
1114
+ if (miniFatStart >= 4294967294 || csectMiniFat === 0) return;
1115
+ let sect = miniFatStart;
1116
+ for (let i = 0; i < csectMiniFat && sect < 4294967294; i++) {
1117
+ const offset = this.getSectorOffset(sect);
1118
+ const count = this.sectorSize / 4;
1119
+ for (let j = 0; j < count; j++) {
1120
+ this.miniFat.push(this.view.getUint32(offset + j * 4, true));
1121
+ }
1122
+ sect = this.fat[sect] ?? 4294967294;
1123
+ }
1124
+ }
1125
+ readRegularStream(startSector, targetSize) {
1126
+ if (startSector >= 4294967294) return new Uint8Array(0);
1127
+ const chunks = [];
1128
+ let curr = startSector;
1129
+ let totalBytes = 0;
1130
+ const visited = /* @__PURE__ */ new Set();
1131
+ while (curr < 4294967294 && !visited.has(curr)) {
1132
+ visited.add(curr);
1133
+ const offset = this.getSectorOffset(curr);
1134
+ if (offset + this.sectorSize <= this.u8.length) {
1135
+ chunks.push(this.u8.subarray(offset, offset + this.sectorSize));
1136
+ totalBytes += this.sectorSize;
1137
+ }
1138
+ curr = this.fat[curr] ?? 4294967294;
1139
+ }
1140
+ const result = new Uint8Array(totalBytes);
1141
+ let pos = 0;
1142
+ for (const chunk of chunks) {
1143
+ result.set(chunk, pos);
1144
+ pos += chunk.length;
1145
+ }
1146
+ if (targetSize !== void 0 && targetSize < result.length) {
1147
+ return result.subarray(0, targetSize);
1148
+ }
1149
+ return result;
1150
+ }
1151
+ readMiniStream(startSector, targetSize) {
1152
+ if (this.miniStream.length === 0 || startSector >= 4294967294) return new Uint8Array(0);
1153
+ const chunks = [];
1154
+ let curr = startSector;
1155
+ let totalBytes = 0;
1156
+ const visited = /* @__PURE__ */ new Set();
1157
+ while (curr < 4294967294 && !visited.has(curr)) {
1158
+ visited.add(curr);
1159
+ const offset = curr * this.miniSectorSize;
1160
+ if (offset + this.miniSectorSize <= this.miniStream.length) {
1161
+ chunks.push(this.miniStream.subarray(offset, offset + this.miniSectorSize));
1162
+ totalBytes += this.miniSectorSize;
1163
+ }
1164
+ curr = this.miniFat[curr] ?? 4294967294;
1165
+ }
1166
+ const result = new Uint8Array(totalBytes);
1167
+ let pos = 0;
1168
+ for (const chunk of chunks) {
1169
+ result.set(chunk, pos);
1170
+ pos += chunk.length;
1171
+ }
1172
+ return result.subarray(0, targetSize);
1173
+ }
1174
+ };
945
1175
 
946
1176
  // ../plugins/pdf/dist/index.js
947
1177
  var PdfPlugin = class {
@@ -1352,13 +1582,18 @@ function mediaPlugin() {
1352
1582
  var DocxPlugin = class {
1353
1583
  id = "docx";
1354
1584
  name = "Word Document Preview";
1355
- extensions = [".docx"];
1356
- mimeTypes = ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"];
1585
+ extensions = [".docx", ".docm", ".dotx", ".dotm"];
1586
+ mimeTypes = [
1587
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1588
+ "application/vnd.ms-word.document.macroEnabled.12",
1589
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
1590
+ "application/vnd.ms-word.template.macroEnabled.12"
1591
+ ];
1357
1592
  weight = 80;
1358
1593
  supports(file) {
1359
1594
  const ext = file.metadata.extension?.toLowerCase();
1360
1595
  const mime = file.metadata.mimeType?.toLowerCase();
1361
- return ext === ".docx" || this.mimeTypes.includes(mime || "");
1596
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
1362
1597
  }
1363
1598
  getToolbarActions(instance) {
1364
1599
  return [
@@ -1482,11 +1717,16 @@ function docxPlugin() {
1482
1717
  }
1483
1718
  var ExcelPlugin = class {
1484
1719
  id = "excel";
1485
- name = "Excel Spreadsheet Preview";
1486
- extensions = [".xlsx", ".xls"];
1720
+ name = "Spreadsheet Preview (Excel / OpenDocument)";
1721
+ extensions = [".xlsx", ".xls", ".xlsm", ".xlsb", ".xltx", ".xltm", ".ods"];
1487
1722
  mimeTypes = [
1488
1723
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1489
- "application/vnd.ms-excel"
1724
+ "application/vnd.ms-excel",
1725
+ "application/vnd.ms-excel.sheet.macroEnabled.12",
1726
+ "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
1727
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
1728
+ "application/vnd.ms-excel.template.macroEnabled.12",
1729
+ "application/vnd.oasis.opendocument.spreadsheet"
1490
1730
  ];
1491
1731
  weight = 80;
1492
1732
  supports(file) {
@@ -1550,70 +1790,111 @@ var ExcelPlugin = class {
1550
1790
  }
1551
1791
  async render(ctx) {
1552
1792
  const container = document.createElement("div");
1793
+ container.className = "fp-excel-container";
1553
1794
  container.style.display = "flex";
1554
1795
  container.style.flexDirection = "column";
1555
1796
  container.style.width = "100%";
1556
1797
  container.style.height = "100%";
1557
1798
  container.style.overflow = "hidden";
1558
1799
  const contentArea = document.createElement("div");
1800
+ contentArea.className = "fp-excel-content";
1559
1801
  contentArea.style.flex = "1";
1560
1802
  contentArea.style.overflow = "auto";
1561
1803
  contentArea.style.padding = "16px";
1562
1804
  contentArea.style.transformOrigin = "top left";
1563
1805
  const tabsArea = document.createElement("div");
1806
+ tabsArea.className = "fp-excel-tabs";
1564
1807
  tabsArea.style.display = "flex";
1565
- tabsArea.style.gap = "8px";
1808
+ tabsArea.style.gap = "6px";
1566
1809
  tabsArea.style.padding = "8px 16px";
1567
1810
  tabsArea.style.borderTop = "1px solid #e0e0e0";
1568
1811
  tabsArea.style.backgroundColor = "#fafafa";
1569
1812
  tabsArea.style.overflowX = "auto";
1813
+ tabsArea.style.flexShrink = "0";
1570
1814
  container.appendChild(contentArea);
1571
1815
  container.appendChild(tabsArea);
1572
1816
  ctx.container.appendChild(container);
1573
1817
  let scale = 1;
1574
1818
  let currentSheetIndex = 1;
1575
- const workbook = new ExcelJS__default.default.Workbook();
1819
+ let sheetNames = [];
1820
+ let wb = null;
1576
1821
  try {
1577
- await workbook.xlsx.load(ctx.buffer);
1578
- } catch {
1822
+ wb = XLSX__namespace.read(new Uint8Array(ctx.buffer), { type: "array", cellDates: true });
1823
+ sheetNames = wb.SheetNames || [];
1824
+ } catch (err) {
1825
+ console.warn("[ExcelPlugin] SheetJS parse failed, rendering fallback:", err);
1579
1826
  }
1827
+ const tabButtons = [];
1580
1828
  const renderSheet = (index) => {
1829
+ if (!wb || index < 1 || index > sheetNames.length) return;
1830
+ currentSheetIndex = index;
1831
+ const sheetName = sheetNames[index - 1];
1832
+ const ws = wb.Sheets[sheetName];
1581
1833
  contentArea.innerHTML = "";
1582
- const sheet = workbook.getWorksheet(index);
1583
- if (!sheet) return;
1584
- const table = document.createElement("table");
1585
- table.style.borderCollapse = "collapse";
1586
- table.style.fontFamily = "sans-serif";
1587
- table.style.fontSize = "13px";
1588
- table.style.minWidth = "100%";
1589
- sheet.eachRow({ includeEmpty: false }, (row) => {
1590
- const tr = document.createElement("tr");
1591
- row.eachCell({ includeEmpty: true }, (cell) => {
1592
- const td = document.createElement("td");
1593
- td.style.border = "1px solid #d0d7de";
1594
- td.style.padding = "6px 12px";
1595
- td.textContent = cell.text || "";
1596
- tr.appendChild(td);
1834
+ if (!ws) {
1835
+ contentArea.innerHTML = '<div style="padding: 24px; color: #888;">Empty sheet</div>';
1836
+ return;
1837
+ }
1838
+ const html = XLSX__namespace.utils.sheet_to_html(ws, { id: "fp-sheet-table", editable: false });
1839
+ contentArea.innerHTML = html;
1840
+ const table = contentArea.querySelector("table");
1841
+ if (table) {
1842
+ table.style.borderCollapse = "collapse";
1843
+ table.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
1844
+ table.style.fontSize = "13px";
1845
+ table.style.minWidth = "100%";
1846
+ table.style.border = "1px solid #d0d7de";
1847
+ table.style.background = "#fff";
1848
+ table.querySelectorAll("td, th").forEach((cell) => {
1849
+ const el = cell;
1850
+ el.style.border = "1px solid #d0d7de";
1851
+ el.style.padding = "6px 12px";
1852
+ el.style.whiteSpace = "nowrap";
1597
1853
  });
1598
- table.appendChild(tr);
1854
+ table.querySelectorAll("tr:first-child td, th").forEach((cell) => {
1855
+ const el = cell;
1856
+ el.style.fontWeight = "600";
1857
+ el.style.backgroundColor = "#f6f8fa";
1858
+ });
1859
+ }
1860
+ tabButtons.forEach((b, i) => {
1861
+ if (i === index - 1) {
1862
+ b.style.backgroundColor = "#2563eb";
1863
+ b.style.color = "#fff";
1864
+ b.style.borderColor = "#2563eb";
1865
+ b.style.fontWeight = "600";
1866
+ } else {
1867
+ b.style.backgroundColor = "#fff";
1868
+ b.style.color = "#333";
1869
+ b.style.borderColor = "#ccc";
1870
+ b.style.fontWeight = "normal";
1871
+ }
1599
1872
  });
1600
- contentArea.appendChild(table);
1601
- currentSheetIndex = index;
1602
1873
  };
1603
- workbook.worksheets.forEach((sheet, idx) => {
1604
- const btn = document.createElement("button");
1605
- btn.textContent = sheet.name;
1606
- btn.style.padding = "4px 12px";
1607
- btn.style.fontSize = "12px";
1608
- btn.style.cursor = "pointer";
1609
- btn.style.border = "1px solid #ccc";
1610
- btn.style.borderRadius = "4px";
1611
- btn.style.backgroundColor = "#fff";
1612
- btn.onclick = () => renderSheet(idx + 1);
1613
- tabsArea.appendChild(btn);
1614
- });
1615
- if (workbook.worksheets.length > 0) {
1874
+ if (sheetNames.length > 0) {
1875
+ sheetNames.forEach((name, idx) => {
1876
+ const btn = document.createElement("button");
1877
+ btn.textContent = name;
1878
+ btn.style.padding = "4px 12px";
1879
+ btn.style.fontSize = "12px";
1880
+ btn.style.cursor = "pointer";
1881
+ btn.style.border = "1px solid #ccc";
1882
+ btn.style.borderRadius = "4px";
1883
+ btn.style.backgroundColor = "#fff";
1884
+ btn.style.transition = "all 0.15s ease";
1885
+ btn.onclick = () => renderSheet(idx + 1);
1886
+ tabsArea.appendChild(btn);
1887
+ tabButtons.push(btn);
1888
+ });
1616
1889
  renderSheet(1);
1890
+ } else {
1891
+ contentArea.innerHTML = `
1892
+ <div style="text-align:center; padding: 40px; color: #666;">
1893
+ <div style="font-size:48px; margin-bottom: 16px;">\u{1F4CA}</div>
1894
+ <h3>${ctx.metadata.name || "Spreadsheet"}</h3>
1895
+ <p>Unable to load sheet data</p>
1896
+ </div>
1897
+ `;
1617
1898
  }
1618
1899
  const cleanup = () => {
1619
1900
  container.remove();
@@ -1636,11 +1917,11 @@ var ExcelPlugin = class {
1636
1917
  contentArea.style.transform = `scale(${scale})`;
1637
1918
  },
1638
1919
  goToPage: (page) => {
1639
- if (page > 0 && page <= workbook.worksheets.length) {
1920
+ if (page > 0 && page <= sheetNames.length) {
1640
1921
  renderSheet(page);
1641
1922
  }
1642
1923
  },
1643
- getPageCount: () => workbook.worksheets.length,
1924
+ getPageCount: () => sheetNames.length,
1644
1925
  getCurrentPage: () => currentSheetIndex,
1645
1926
  download: () => {
1646
1927
  const blob = new Blob([ctx.buffer], { type: this.mimeTypes[0] });
@@ -2241,7 +2522,7 @@ var MarkdownPlugin = class {
2241
2522
  gfm: true,
2242
2523
  breaks: true
2243
2524
  });
2244
- const cleanHtml = DOMPurify__default.default.sanitize(rawHtml, {
2525
+ const cleanHtml = DOMPurify5__default.default.sanitize(rawHtml, {
2245
2526
  USE_PROFILES: { html: true }
2246
2527
  });
2247
2528
  const wrapper = document.createElement("div");
@@ -2380,10 +2661,14 @@ function markdownPlugin() {
2380
2661
  var PptxPlugin = class {
2381
2662
  id = "pptx";
2382
2663
  name = "PowerPoint Presentation";
2383
- extensions = [".pptx", ".ppsx"];
2664
+ extensions = [".pptx", ".ppsx", ".pptm", ".ppsm", ".potx", ".potm"];
2384
2665
  mimeTypes = [
2385
2666
  "application/vnd.openxmlformats-officedocument.presentationml.presentation",
2386
- "application/vnd.openxmlformats-officedocument.presentationml.slideshow"
2667
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
2668
+ "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
2669
+ "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
2670
+ "application/vnd.openxmlformats-officedocument.presentationml.template",
2671
+ "application/vnd.ms-powerpoint.template.macroEnabled.12"
2387
2672
  ];
2388
2673
  weight = 80;
2389
2674
  supports(file) {
@@ -2769,6 +3054,1292 @@ var ThreeDPlugin = class {
2769
3054
  function threeDPlugin() {
2770
3055
  return new ThreeDPlugin();
2771
3056
  }
3057
+ var RtfPlugin = class {
3058
+ id = "rtf";
3059
+ name = "Rich Text Format (RTF)";
3060
+ extensions = [".rtf"];
3061
+ mimeTypes = ["text/rtf", "application/rtf"];
3062
+ weight = 80;
3063
+ supports(file) {
3064
+ const ext = file.metadata.extension?.toLowerCase();
3065
+ const mime = file.metadata.mimeType?.toLowerCase();
3066
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3067
+ }
3068
+ getToolbarActions(instance) {
3069
+ return [
3070
+ {
3071
+ id: "zoom-out",
3072
+ icon: "zoom-out",
3073
+ label: "Zoom Out",
3074
+ type: "button",
3075
+ group: "zoom",
3076
+ execute: () => instance.zoomOut?.()
3077
+ },
3078
+ {
3079
+ id: "zoom-in",
3080
+ icon: "zoom-in",
3081
+ label: "Zoom In",
3082
+ type: "button",
3083
+ group: "zoom",
3084
+ execute: () => instance.zoomIn?.()
3085
+ },
3086
+ {
3087
+ id: "fit-page",
3088
+ icon: "fit-page",
3089
+ label: "Fit to Page",
3090
+ type: "button",
3091
+ group: "zoom",
3092
+ execute: () => instance.fitToPage?.()
3093
+ },
3094
+ {
3095
+ id: "download",
3096
+ icon: "download",
3097
+ label: "Download",
3098
+ type: "button",
3099
+ group: "actions",
3100
+ execute: () => instance.download?.()
3101
+ },
3102
+ {
3103
+ id: "print",
3104
+ icon: "print",
3105
+ label: "Print",
3106
+ type: "button",
3107
+ group: "actions",
3108
+ execute: () => instance.print?.()
3109
+ }
3110
+ ];
3111
+ }
3112
+ async render(ctx) {
3113
+ const wrapper = document.createElement("div");
3114
+ wrapper.className = "fp-rtf-wrapper";
3115
+ wrapper.style.padding = "32px";
3116
+ wrapper.style.maxWidth = "850px";
3117
+ wrapper.style.margin = "0 auto";
3118
+ wrapper.style.backgroundColor = "#fff";
3119
+ wrapper.style.boxShadow = "0 2px 8px rgba(0,0,0,0.08)";
3120
+ wrapper.style.borderRadius = "4px";
3121
+ wrapper.style.minHeight = "100%";
3122
+ wrapper.style.transformOrigin = "top center";
3123
+ wrapper.style.transition = "transform 0.2s ease";
3124
+ ctx.container.style.overflow = "auto";
3125
+ ctx.container.style.padding = "24px";
3126
+ ctx.container.style.backgroundColor = "#f1f5f9";
3127
+ ctx.container.appendChild(wrapper);
3128
+ let scale = 1;
3129
+ try {
3130
+ const doc = new rtf_js.RTFJS.Document(ctx.buffer, {});
3131
+ const htmlElements = await doc.render();
3132
+ for (const el of htmlElements) {
3133
+ wrapper.appendChild(el);
3134
+ }
3135
+ } catch (err) {
3136
+ console.warn("[RtfPlugin] RTF render error, fallback text:", err);
3137
+ const text = new TextDecoder("latin1").decode(ctx.buffer);
3138
+ const clean = text.replace(/\\par[d]?/g, "\n").replace(/\\[a-zA-Z0-9\-]+/g, "").replace(/[{}]/g, "");
3139
+ wrapper.innerHTML = `<pre style="white-space: pre-wrap; font-family: serif; color: #333;">${clean}</pre>`;
3140
+ }
3141
+ const cleanup = () => {
3142
+ wrapper.remove();
3143
+ ctx.container.innerHTML = "";
3144
+ };
3145
+ ctx.signal.addEventListener("abort", cleanup);
3146
+ return {
3147
+ destroy: cleanup,
3148
+ zoomIn: () => {
3149
+ scale += 0.1;
3150
+ wrapper.style.transform = `scale(${scale})`;
3151
+ },
3152
+ zoomOut: () => {
3153
+ scale = Math.max(0.2, scale - 0.1);
3154
+ wrapper.style.transform = `scale(${scale})`;
3155
+ },
3156
+ getZoom: () => scale,
3157
+ setZoom: (level) => {
3158
+ scale = level;
3159
+ wrapper.style.transform = `scale(${scale})`;
3160
+ },
3161
+ fitToPage: () => {
3162
+ scale = 1;
3163
+ wrapper.style.transform = "scale(1)";
3164
+ },
3165
+ download: () => {
3166
+ const blob = new Blob([ctx.buffer], { type: "application/rtf" });
3167
+ const url = URL.createObjectURL(blob);
3168
+ const a = document.createElement("a");
3169
+ a.href = url;
3170
+ a.download = ctx.metadata.name || "document.rtf";
3171
+ a.click();
3172
+ URL.revokeObjectURL(url);
3173
+ },
3174
+ print: () => {
3175
+ window.print();
3176
+ }
3177
+ };
3178
+ }
3179
+ };
3180
+ function rtfPlugin() {
3181
+ return new RtfPlugin();
3182
+ }
3183
+ var HtmlPreviewPlugin = class {
3184
+ id = "html-preview";
3185
+ name = "HTML Document Preview";
3186
+ extensions = [".html", ".htm", ".xhtml"];
3187
+ mimeTypes = ["text/html", "application/xhtml+xml"];
3188
+ weight = 85;
3189
+ supports(file) {
3190
+ const ext = file.metadata.extension?.toLowerCase();
3191
+ const mime = file.metadata.mimeType?.toLowerCase();
3192
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3193
+ }
3194
+ getToolbarActions(instance) {
3195
+ return [
3196
+ {
3197
+ id: "zoom-out",
3198
+ icon: "zoom-out",
3199
+ label: "Zoom Out",
3200
+ type: "button",
3201
+ group: "zoom",
3202
+ execute: () => instance.zoomOut?.()
3203
+ },
3204
+ {
3205
+ id: "zoom-in",
3206
+ icon: "zoom-in",
3207
+ label: "Zoom In",
3208
+ type: "button",
3209
+ group: "zoom",
3210
+ execute: () => instance.zoomIn?.()
3211
+ },
3212
+ {
3213
+ id: "fit-page",
3214
+ icon: "fit-page",
3215
+ label: "Fit to Page",
3216
+ type: "button",
3217
+ group: "zoom",
3218
+ execute: () => instance.fitToPage?.()
3219
+ },
3220
+ {
3221
+ id: "copy",
3222
+ icon: "copy",
3223
+ label: "Copy HTML",
3224
+ type: "button",
3225
+ group: "actions",
3226
+ execute: () => instance.copy?.()
3227
+ },
3228
+ {
3229
+ id: "download",
3230
+ icon: "download",
3231
+ label: "Download",
3232
+ type: "button",
3233
+ group: "actions",
3234
+ execute: () => instance.download?.()
3235
+ },
3236
+ {
3237
+ id: "print",
3238
+ icon: "print",
3239
+ label: "Print",
3240
+ type: "button",
3241
+ group: "actions",
3242
+ execute: () => instance.print?.()
3243
+ }
3244
+ ];
3245
+ }
3246
+ async render(ctx) {
3247
+ const rawHtml = new TextDecoder("utf-8").decode(ctx.buffer);
3248
+ const sanitized = DOMPurify5__default.default.sanitize(rawHtml, {
3249
+ WHOLE_DOCUMENT: true,
3250
+ ADD_TAGS: ["style", "link"],
3251
+ ADD_ATTR: ["target", "rel"]
3252
+ });
3253
+ const iframe = document.createElement("iframe");
3254
+ iframe.className = "fp-html-iframe";
3255
+ iframe.style.width = "100%";
3256
+ iframe.style.height = "100%";
3257
+ iframe.style.border = "none";
3258
+ iframe.style.backgroundColor = "#ffffff";
3259
+ iframe.style.transformOrigin = "top left";
3260
+ iframe.style.transition = "transform 0.2s ease";
3261
+ iframe.sandbox.add("allow-same-origin");
3262
+ ctx.container.style.overflow = "auto";
3263
+ ctx.container.style.width = "100%";
3264
+ ctx.container.style.height = "100%";
3265
+ ctx.container.appendChild(iframe);
3266
+ iframe.srcdoc = sanitized;
3267
+ let scale = 1;
3268
+ const cleanup = () => {
3269
+ iframe.remove();
3270
+ ctx.container.innerHTML = "";
3271
+ };
3272
+ ctx.signal.addEventListener("abort", cleanup);
3273
+ return {
3274
+ destroy: cleanup,
3275
+ zoomIn: () => {
3276
+ scale += 0.1;
3277
+ iframe.style.transform = `scale(${scale})`;
3278
+ },
3279
+ zoomOut: () => {
3280
+ scale = Math.max(0.2, scale - 0.1);
3281
+ iframe.style.transform = `scale(${scale})`;
3282
+ },
3283
+ getZoom: () => scale,
3284
+ setZoom: (level) => {
3285
+ scale = level;
3286
+ iframe.style.transform = `scale(${scale})`;
3287
+ },
3288
+ fitToPage: () => {
3289
+ scale = 1;
3290
+ iframe.style.transform = "scale(1)";
3291
+ },
3292
+ copy: () => {
3293
+ navigator.clipboard.writeText(rawHtml);
3294
+ },
3295
+ download: () => {
3296
+ const blob = new Blob([ctx.buffer], { type: "text/html" });
3297
+ const url = URL.createObjectURL(blob);
3298
+ const a = document.createElement("a");
3299
+ a.href = url;
3300
+ a.download = ctx.metadata.name || "document.html";
3301
+ a.click();
3302
+ URL.revokeObjectURL(url);
3303
+ },
3304
+ print: () => {
3305
+ iframe.contentWindow?.print();
3306
+ }
3307
+ };
3308
+ }
3309
+ };
3310
+ function htmlPreviewPlugin() {
3311
+ return new HtmlPreviewPlugin();
3312
+ }
3313
+ var OpenDocumentPlugin = class {
3314
+ id = "opendocument";
3315
+ name = "OpenDocument Preview (ODT, ODP, ODS, ODG, ODF)";
3316
+ extensions = [".odt", ".odp", ".ods", ".odg", ".odf"];
3317
+ mimeTypes = [
3318
+ "application/vnd.oasis.opendocument.text",
3319
+ "application/vnd.oasis.opendocument.presentation",
3320
+ "application/vnd.oasis.opendocument.spreadsheet",
3321
+ "application/vnd.oasis.opendocument.graphics",
3322
+ "application/vnd.oasis.opendocument.formula"
3323
+ ];
3324
+ weight = 80;
3325
+ supports(file) {
3326
+ const ext = file.metadata.extension?.toLowerCase();
3327
+ const mime = file.metadata.mimeType?.toLowerCase();
3328
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3329
+ }
3330
+ getToolbarActions(instance) {
3331
+ const isPresentation = instance.isPresentation;
3332
+ const actions = [];
3333
+ if (isPresentation) {
3334
+ actions.push(
3335
+ {
3336
+ id: "thumbnails",
3337
+ icon: "thumbnails",
3338
+ label: "Slide Thumbnails",
3339
+ type: "button",
3340
+ group: "navigation",
3341
+ execute: () => instance.toggleThumbnails?.()
3342
+ },
3343
+ {
3344
+ id: "page-prev",
3345
+ icon: "page-prev",
3346
+ label: "Previous Slide",
3347
+ type: "button",
3348
+ group: "navigation",
3349
+ execute: () => {
3350
+ const cur = instance.getCurrentPage?.() ?? 1;
3351
+ if (cur > 1) instance.goToPage?.(cur - 1);
3352
+ }
3353
+ },
3354
+ {
3355
+ id: "page-nav",
3356
+ icon: "",
3357
+ label: "Slide Number",
3358
+ type: "page-nav",
3359
+ group: "navigation",
3360
+ execute: (p) => instance.goToPage?.(Number(p))
3361
+ },
3362
+ {
3363
+ id: "page-next",
3364
+ icon: "page-next",
3365
+ label: "Next Slide",
3366
+ type: "button",
3367
+ group: "navigation",
3368
+ execute: () => {
3369
+ const cur = instance.getCurrentPage?.() ?? 1;
3370
+ const total = instance.getPageCount?.() ?? 1;
3371
+ if (cur < total) instance.goToPage?.(cur + 1);
3372
+ }
3373
+ }
3374
+ );
3375
+ }
3376
+ actions.push(
3377
+ {
3378
+ id: "zoom-out",
3379
+ icon: "zoom-out",
3380
+ label: "Zoom Out",
3381
+ type: "button",
3382
+ group: "zoom",
3383
+ execute: () => instance.zoomOut?.()
3384
+ },
3385
+ {
3386
+ id: "zoom-in",
3387
+ icon: "zoom-in",
3388
+ label: "Zoom In",
3389
+ type: "button",
3390
+ group: "zoom",
3391
+ execute: () => instance.zoomIn?.()
3392
+ },
3393
+ {
3394
+ id: "fit-page",
3395
+ icon: "fit-page",
3396
+ label: "Fit to Page",
3397
+ type: "button",
3398
+ group: "zoom",
3399
+ execute: () => instance.fitToPage?.()
3400
+ },
3401
+ {
3402
+ id: "download",
3403
+ icon: "download",
3404
+ label: "Download",
3405
+ type: "button",
3406
+ group: "actions",
3407
+ execute: () => instance.download?.()
3408
+ },
3409
+ {
3410
+ id: "print",
3411
+ icon: "print",
3412
+ label: "Print",
3413
+ type: "button",
3414
+ group: "actions",
3415
+ execute: () => instance.print?.()
3416
+ }
3417
+ );
3418
+ return actions;
3419
+ }
3420
+ async render(ctx) {
3421
+ const ext = (ctx.metadata.extension || "").toLowerCase();
3422
+ const mime = (ctx.metadata.mimeType || "").toLowerCase();
3423
+ const isPresentation = ext === ".odp" || mime.includes("presentation");
3424
+ const isFormula = ext === ".odf" || mime.includes("formula");
3425
+ ext === ".odg" || mime.includes("graphics");
3426
+ let unzipped;
3427
+ try {
3428
+ unzipped = fflate.unzipSync(new Uint8Array(ctx.buffer));
3429
+ } catch {
3430
+ throw new Error("Failed to decompress OpenDocument package (invalid ZIP format)");
3431
+ }
3432
+ const imageUrls = /* @__PURE__ */ new Map();
3433
+ for (const [filePath, fileBytes] of Object.entries(unzipped)) {
3434
+ if (filePath.startsWith("Pictures/")) {
3435
+ const imageMime = filePath.endsWith(".png") ? "image/png" : filePath.endsWith(".jpg") || filePath.endsWith(".jpeg") ? "image/jpeg" : filePath.endsWith(".svg") ? "image/svg+xml" : "application/octet-stream";
3436
+ const blob = new Blob([fileBytes], { type: imageMime });
3437
+ imageUrls.set(filePath, URL.createObjectURL(blob));
3438
+ }
3439
+ }
3440
+ const contentXmlStr = unzipped["content.xml"] ? fflate.strFromU8(unzipped["content.xml"]) : "";
3441
+ const stylesXmlStr = unzipped["styles.xml"] ? fflate.strFromU8(unzipped["styles.xml"]) : "";
3442
+ const parser = new DOMParser();
3443
+ const contentDoc = parser.parseFromString(contentXmlStr, "application/xml");
3444
+ const stylesDoc = stylesXmlStr ? parser.parseFromString(stylesXmlStr, "application/xml") : null;
3445
+ const styleMap = this.extractStyles(stylesDoc, contentDoc);
3446
+ const container = document.createElement("div");
3447
+ container.className = "fp-odf-container";
3448
+ container.style.width = "100%";
3449
+ container.style.height = "100%";
3450
+ container.style.overflow = "auto";
3451
+ container.style.padding = "24px";
3452
+ container.style.backgroundColor = "#f1f5f9";
3453
+ const wrapper = document.createElement("div");
3454
+ wrapper.className = "fp-odf-wrapper";
3455
+ wrapper.style.margin = "0 auto";
3456
+ wrapper.style.backgroundColor = "#ffffff";
3457
+ wrapper.style.boxShadow = "0 2px 10px rgba(0,0,0,0.08)";
3458
+ wrapper.style.borderRadius = "4px";
3459
+ wrapper.style.transformOrigin = "top center";
3460
+ wrapper.style.transition = "transform 0.2s ease";
3461
+ container.appendChild(wrapper);
3462
+ ctx.container.appendChild(container);
3463
+ let scale = 1;
3464
+ let currentPage = 1;
3465
+ let totalPages = 1;
3466
+ let slides = [];
3467
+ if (isPresentation) {
3468
+ wrapper.style.maxWidth = "960px";
3469
+ wrapper.style.aspectRatio = "16 / 9";
3470
+ wrapper.style.position = "relative";
3471
+ wrapper.style.overflow = "hidden";
3472
+ slides = this.renderSlides(contentDoc, styleMap, imageUrls);
3473
+ totalPages = Math.max(1, slides.length);
3474
+ slides.forEach((slide, idx) => {
3475
+ slide.style.display = idx === 0 ? "block" : "none";
3476
+ slide.style.width = "100%";
3477
+ slide.style.height = "100%";
3478
+ slide.style.position = "absolute";
3479
+ slide.style.top = "0";
3480
+ slide.style.left = "0";
3481
+ wrapper.appendChild(slide);
3482
+ });
3483
+ } else if (isFormula) {
3484
+ wrapper.style.maxWidth = "800px";
3485
+ wrapper.style.padding = "48px";
3486
+ wrapper.style.textAlign = "center";
3487
+ wrapper.style.fontSize = "24px";
3488
+ const mathEl = contentDoc.querySelector("math");
3489
+ if (mathEl) {
3490
+ wrapper.innerHTML = mathEl.outerHTML;
3491
+ } else {
3492
+ wrapper.textContent = contentDoc.documentElement.textContent || "Formula content";
3493
+ }
3494
+ } else {
3495
+ wrapper.style.maxWidth = "850px";
3496
+ wrapper.style.padding = "48px";
3497
+ wrapper.style.minHeight = "100%";
3498
+ const bodyHtml = this.renderOdfBody(contentDoc, styleMap, imageUrls);
3499
+ wrapper.innerHTML = DOMPurify5__default.default.sanitize(bodyHtml, {
3500
+ ADD_TAGS: ["math", "semantics", "mrow", "mi", "mo", "mn", "msup", "msub"],
3501
+ ADD_ATTR: ["style", "colspan", "rowspan"]
3502
+ });
3503
+ }
3504
+ const cleanup = () => {
3505
+ imageUrls.forEach((url) => URL.revokeObjectURL(url));
3506
+ container.remove();
3507
+ ctx.container.innerHTML = "";
3508
+ };
3509
+ ctx.signal.addEventListener("abort", cleanup);
3510
+ const goToPage = (page) => {
3511
+ if (!isPresentation || page < 1 || page > totalPages) return;
3512
+ currentPage = page;
3513
+ slides.forEach((s, idx) => {
3514
+ s.style.display = idx === page - 1 ? "block" : "none";
3515
+ });
3516
+ ctx.emit("page-change", { page: currentPage, total: totalPages });
3517
+ };
3518
+ return {
3519
+ destroy: cleanup,
3520
+ isPresentation,
3521
+ zoomIn: () => {
3522
+ scale += 0.1;
3523
+ wrapper.style.transform = `scale(${scale})`;
3524
+ },
3525
+ zoomOut: () => {
3526
+ scale = Math.max(0.2, scale - 0.1);
3527
+ wrapper.style.transform = `scale(${scale})`;
3528
+ },
3529
+ getZoom: () => scale,
3530
+ setZoom: (level) => {
3531
+ scale = level;
3532
+ wrapper.style.transform = `scale(${scale})`;
3533
+ },
3534
+ fitToPage: () => {
3535
+ scale = 1;
3536
+ wrapper.style.transform = "scale(1)";
3537
+ },
3538
+ goToPage,
3539
+ getPageCount: () => totalPages,
3540
+ getCurrentPage: () => currentPage,
3541
+ getThumbnails: async () => {
3542
+ if (!isPresentation) return [];
3543
+ return slides.map((_, idx) => ({
3544
+ index: idx,
3545
+ label: `Slide ${idx + 1}`,
3546
+ render: async (canvas) => {
3547
+ const ctx2d = canvas.getContext("2d");
3548
+ if (!ctx2d) return;
3549
+ canvas.width = 160;
3550
+ canvas.height = 90;
3551
+ ctx2d.fillStyle = "#f8fafc";
3552
+ ctx2d.fillRect(0, 0, 160, 90);
3553
+ ctx2d.fillStyle = "#334155";
3554
+ ctx2d.font = "bold 12px sans-serif";
3555
+ ctx2d.textAlign = "center";
3556
+ ctx2d.fillText(`Slide ${idx + 1}`, 80, 50);
3557
+ }
3558
+ }));
3559
+ },
3560
+ download: () => {
3561
+ const mimeType = this.mimeTypes.find((m) => m.includes(ext.replace(".", ""))) || "application/octet-stream";
3562
+ const blob = new Blob([ctx.buffer], { type: mimeType });
3563
+ const url = URL.createObjectURL(blob);
3564
+ const a = document.createElement("a");
3565
+ a.href = url;
3566
+ a.download = ctx.metadata.name || `document${ext}`;
3567
+ a.click();
3568
+ URL.revokeObjectURL(url);
3569
+ },
3570
+ print: () => {
3571
+ window.print();
3572
+ }
3573
+ };
3574
+ }
3575
+ extractStyles(stylesDoc, contentDoc) {
3576
+ const map = /* @__PURE__ */ new Map();
3577
+ const styleNodes = [];
3578
+ if (stylesDoc) {
3579
+ styleNodes.push(...Array.from(stylesDoc.querySelectorAll("style, [name]")));
3580
+ }
3581
+ styleNodes.push(...Array.from(contentDoc.querySelectorAll("style, [name]")));
3582
+ for (const node of styleNodes) {
3583
+ const name = node.getAttribute("style:name") || node.getAttribute("name");
3584
+ if (!name) continue;
3585
+ let css = "";
3586
+ const textProp = node.querySelector("text-properties, [font-weight], [font-style], [color]");
3587
+ if (textProp) {
3588
+ const weight = textProp.getAttribute("fo:font-weight") || textProp.getAttribute("font-weight");
3589
+ const style = textProp.getAttribute("fo:font-style") || textProp.getAttribute("font-style");
3590
+ const color = textProp.getAttribute("fo:color") || textProp.getAttribute("color");
3591
+ const size = textProp.getAttribute("fo:font-size") || textProp.getAttribute("font-size");
3592
+ if (weight === "bold") css += "font-weight: bold; ";
3593
+ if (style === "italic") css += "font-style: italic; ";
3594
+ if (color) css += `color: ${color}; `;
3595
+ if (size) css += `font-size: ${size}; `;
3596
+ }
3597
+ const paraProp = node.querySelector("paragraph-properties, [text-align]");
3598
+ if (paraProp) {
3599
+ const align = paraProp.getAttribute("fo:text-align") || paraProp.getAttribute("text-align");
3600
+ const mt = paraProp.getAttribute("fo:margin-top") || paraProp.getAttribute("margin-top");
3601
+ const mb = paraProp.getAttribute("fo:margin-bottom") || paraProp.getAttribute("margin-bottom");
3602
+ if (align) css += `text-align: ${align}; `;
3603
+ if (mt) css += `margin-top: ${mt}; `;
3604
+ if (mb) css += `margin-bottom: ${mb}; `;
3605
+ }
3606
+ if (css) map.set(name, css);
3607
+ }
3608
+ return map;
3609
+ }
3610
+ renderOdfBody(contentDoc, styles, images) {
3611
+ const body = contentDoc.querySelector("body") || contentDoc.documentElement;
3612
+ let html = "";
3613
+ const walk = (node) => {
3614
+ const tag = node.localName || node.tagName.toLowerCase();
3615
+ switch (tag) {
3616
+ case "h": {
3617
+ const level = Math.min(6, Math.max(1, Number(node.getAttribute("text:outline-level") || 1)));
3618
+ const style = styles.get(node.getAttribute("text:style-name") || "") || "";
3619
+ html += `<h${level} style="${style}; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">${node.textContent || ""}</h${level}>`;
3620
+ break;
3621
+ }
3622
+ case "p": {
3623
+ const style = styles.get(node.getAttribute("text:style-name") || "") || "";
3624
+ const inner = this.renderSpans(node, styles, images);
3625
+ html += `<p style="${style}; line-height: 1.6; margin: 8px 0; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">${inner}</p>`;
3626
+ break;
3627
+ }
3628
+ case "list": {
3629
+ html += '<ul style="margin: 8px 0; padding-left: 24px;">';
3630
+ Array.from(node.children).forEach((c) => walk(c));
3631
+ html += "</ul>";
3632
+ break;
3633
+ }
3634
+ case "list-item": {
3635
+ html += "<li>";
3636
+ Array.from(node.children).forEach((c) => walk(c));
3637
+ html += "</li>";
3638
+ break;
3639
+ }
3640
+ case "table": {
3641
+ html += '<table style="border-collapse: collapse; width: 100%; margin: 16px 0; border: 1px solid #d0d7de;">';
3642
+ Array.from(node.children).forEach((c) => walk(c));
3643
+ html += "</table>";
3644
+ break;
3645
+ }
3646
+ case "table-row": {
3647
+ html += "<tr>";
3648
+ Array.from(node.children).forEach((c) => walk(c));
3649
+ html += "</tr>";
3650
+ break;
3651
+ }
3652
+ case "table-cell": {
3653
+ html += '<td style="border: 1px solid #d0d7de; padding: 8px 12px; font-size: 13px;">';
3654
+ Array.from(node.children).forEach((c) => walk(c));
3655
+ html += "</td>";
3656
+ break;
3657
+ }
3658
+ default:
3659
+ Array.from(node.children).forEach((c) => walk(c));
3660
+ }
3661
+ };
3662
+ Array.from(body.children).forEach((c) => walk(c));
3663
+ return html || '<p style="color: #666; font-style: italic;">(Document is empty)</p>';
3664
+ }
3665
+ renderSpans(node, styles, images) {
3666
+ let result = "";
3667
+ for (const child of Array.from(node.childNodes)) {
3668
+ if (child.nodeType === Node.TEXT_NODE) {
3669
+ result += child.textContent || "";
3670
+ } else if (child.nodeType === Node.ELEMENT_NODE) {
3671
+ const el = child;
3672
+ const tag = el.localName || el.tagName.toLowerCase();
3673
+ if (tag === "span") {
3674
+ const style = styles.get(el.getAttribute("text:style-name") || "") || "";
3675
+ result += `<span style="${style}">${el.textContent || ""}</span>`;
3676
+ } else if (tag === "image") {
3677
+ const href = el.getAttribute("xlink:href") || el.getAttribute("href") || "";
3678
+ const blobUrl = images.get(href);
3679
+ if (blobUrl) {
3680
+ result += `<img src="${blobUrl}" style="max-width: 100%; height: auto; margin: 8px 0;" alt="Embedded image" />`;
3681
+ }
3682
+ } else if (tag === "s") {
3683
+ const count = Number(el.getAttribute("text:c") || 1);
3684
+ result += "&nbsp;".repeat(count);
3685
+ } else if (tag === "tab") {
3686
+ result += "&emsp;";
3687
+ } else if (tag === "line-break") {
3688
+ result += "<br/>";
3689
+ } else {
3690
+ result += el.textContent || "";
3691
+ }
3692
+ }
3693
+ }
3694
+ return result;
3695
+ }
3696
+ renderSlides(contentDoc, styles, images) {
3697
+ const pages = Array.from(contentDoc.querySelectorAll("page, [draw\\:name]"));
3698
+ const slides = [];
3699
+ const pageNodes = pages.length > 0 ? pages : Array.from(contentDoc.getElementsByTagNameNS("*", "page"));
3700
+ if (pageNodes.length === 0) {
3701
+ const fallbackSlide = document.createElement("div");
3702
+ fallbackSlide.style.padding = "40px";
3703
+ fallbackSlide.style.textAlign = "center";
3704
+ fallbackSlide.innerHTML = "<h2>Presentation</h2><p>No slides found</p>";
3705
+ return [fallbackSlide];
3706
+ }
3707
+ pageNodes.forEach((pageEl, idx) => {
3708
+ const slide = document.createElement("div");
3709
+ slide.className = `fp-odp-slide fp-odp-slide-${idx + 1}`;
3710
+ slide.style.padding = "40px";
3711
+ slide.style.boxSizing = "border-box";
3712
+ slide.style.display = "flex";
3713
+ slide.style.flexDirection = "column";
3714
+ slide.style.justifyContent = "center";
3715
+ slide.style.alignItems = "center";
3716
+ slide.style.background = "#ffffff";
3717
+ const textFrames = Array.from(pageEl.querySelectorAll("frame, text-box, [draw\\:text-style-name]"));
3718
+ if (textFrames.length > 0) {
3719
+ textFrames.forEach((frame) => {
3720
+ const text = frame.textContent?.trim();
3721
+ if (text) {
3722
+ const p = document.createElement("div");
3723
+ p.style.margin = "12px 0";
3724
+ p.style.fontSize = idx === 0 ? "24px" : "16px";
3725
+ p.style.fontWeight = idx === 0 ? "bold" : "normal";
3726
+ p.style.color = "#1e293b";
3727
+ p.textContent = text;
3728
+ slide.appendChild(p);
3729
+ }
3730
+ });
3731
+ } else {
3732
+ slide.innerHTML = `<h3>Slide ${idx + 1}</h3><p>${pageEl.textContent?.trim() || ""}</p>`;
3733
+ }
3734
+ slides.push(slide);
3735
+ });
3736
+ return slides;
3737
+ }
3738
+ };
3739
+ function openDocumentPlugin() {
3740
+ return new OpenDocumentPlugin();
3741
+ }
3742
+ var DocPlugin = class {
3743
+ id = "doc";
3744
+ name = "Legacy Word Document Preview (.doc, .dot)";
3745
+ extensions = [".doc", ".dot"];
3746
+ mimeTypes = ["application/msword", "application/vnd.ms-word"];
3747
+ weight = 75;
3748
+ supports(file) {
3749
+ const ext = file.metadata.extension?.toLowerCase();
3750
+ const mime = file.metadata.mimeType?.toLowerCase();
3751
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3752
+ }
3753
+ getToolbarActions(instance) {
3754
+ return [
3755
+ {
3756
+ id: "zoom-out",
3757
+ icon: "zoom-out",
3758
+ label: "Zoom Out",
3759
+ type: "button",
3760
+ group: "zoom",
3761
+ execute: () => instance.zoomOut?.()
3762
+ },
3763
+ {
3764
+ id: "zoom-in",
3765
+ icon: "zoom-in",
3766
+ label: "Zoom In",
3767
+ type: "button",
3768
+ group: "zoom",
3769
+ execute: () => instance.zoomIn?.()
3770
+ },
3771
+ {
3772
+ id: "fit-page",
3773
+ icon: "fit-page",
3774
+ label: "Fit to Page",
3775
+ type: "button",
3776
+ group: "zoom",
3777
+ execute: () => instance.fitToPage?.()
3778
+ },
3779
+ {
3780
+ id: "copy",
3781
+ icon: "copy",
3782
+ label: "Copy Text",
3783
+ type: "button",
3784
+ group: "actions",
3785
+ execute: () => instance.copy?.()
3786
+ },
3787
+ {
3788
+ id: "download",
3789
+ icon: "download",
3790
+ label: "Download",
3791
+ type: "button",
3792
+ group: "actions",
3793
+ execute: () => instance.download?.()
3794
+ },
3795
+ {
3796
+ id: "print",
3797
+ icon: "print",
3798
+ label: "Print",
3799
+ type: "button",
3800
+ group: "actions",
3801
+ execute: () => instance.print?.()
3802
+ }
3803
+ ];
3804
+ }
3805
+ async render(ctx) {
3806
+ const container = document.createElement("div");
3807
+ container.className = "fp-doc-container";
3808
+ container.style.width = "100%";
3809
+ container.style.height = "100%";
3810
+ container.style.overflow = "auto";
3811
+ container.style.padding = "32px 16px";
3812
+ container.style.backgroundColor = "#f1f5f9";
3813
+ const wrapper = document.createElement("div");
3814
+ wrapper.className = "fp-doc-wrapper";
3815
+ wrapper.style.maxWidth = "850px";
3816
+ wrapper.style.margin = "0 auto";
3817
+ wrapper.style.backgroundColor = "#ffffff";
3818
+ wrapper.style.boxShadow = "0 2px 12px rgba(0,0,0,0.08)";
3819
+ wrapper.style.borderRadius = "4px";
3820
+ wrapper.style.padding = "56px 48px";
3821
+ wrapper.style.minHeight = "100%";
3822
+ wrapper.style.transformOrigin = "top center";
3823
+ wrapper.style.transition = "transform 0.2s ease";
3824
+ wrapper.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
3825
+ wrapper.style.color = "#1e293b";
3826
+ container.appendChild(wrapper);
3827
+ ctx.container.appendChild(container);
3828
+ let scale = 1;
3829
+ let extractedRawText = "";
3830
+ try {
3831
+ const cfbf = new CfbfReader(ctx.buffer);
3832
+ const wordDocStream = cfbf.readStream("WordDocument");
3833
+ if (!wordDocStream || wordDocStream.length < 512) {
3834
+ throw new Error("WordDocument stream not found or invalid in CFBF archive");
3835
+ }
3836
+ const view = new DataView(wordDocStream.buffer, wordDocStream.byteOffset, wordDocStream.byteLength);
3837
+ const flags = view.getUint16(10, true);
3838
+ const is1Table = (flags & 512) !== 0;
3839
+ const tableName = is1Table ? "1Table" : "0Table";
3840
+ const tableStream = cfbf.readStream(tableName);
3841
+ const text = this.extractDocText(wordDocStream, tableStream);
3842
+ extractedRawText = text;
3843
+ wrapper.innerHTML = this.formatDocToHtml(text, ctx.metadata.name || "Document");
3844
+ } catch (err) {
3845
+ console.warn("[DocPlugin] Binary parsing error, fallback text:", err);
3846
+ const fallback = this.heuristicTextExtraction(ctx.buffer);
3847
+ extractedRawText = fallback;
3848
+ wrapper.innerHTML = `
3849
+ <div style="border-bottom: 1px solid #e2e8f0; padding-bottom: 12px; margin-bottom: 24px;">
3850
+ <h2 style="margin: 0 0 6px; font-size: 20px; color: #334155;">${ctx.metadata.name || "Word Document (.doc)"}</h2>
3851
+ <span style="font-size: 12px; color: #64748b; background: #f1f5f9; padding: 2px 8px; border-radius: 4px;">Legacy Word 97-2003 Binary Preview</span>
3852
+ </div>
3853
+ ${this.formatDocToHtml(fallback, ctx.metadata.name || "Document")}
3854
+ `;
3855
+ }
3856
+ const cleanup = () => {
3857
+ container.remove();
3858
+ ctx.container.innerHTML = "";
3859
+ };
3860
+ ctx.signal.addEventListener("abort", cleanup);
3861
+ return {
3862
+ destroy: cleanup,
3863
+ zoomIn: () => {
3864
+ scale += 0.1;
3865
+ wrapper.style.transform = `scale(${scale})`;
3866
+ },
3867
+ zoomOut: () => {
3868
+ scale = Math.max(0.2, scale - 0.1);
3869
+ wrapper.style.transform = `scale(${scale})`;
3870
+ },
3871
+ getZoom: () => scale,
3872
+ setZoom: (level) => {
3873
+ scale = level;
3874
+ wrapper.style.transform = `scale(${scale})`;
3875
+ },
3876
+ fitToPage: () => {
3877
+ scale = 1;
3878
+ wrapper.style.transform = "scale(1)";
3879
+ },
3880
+ copy: () => {
3881
+ navigator.clipboard.writeText(extractedRawText);
3882
+ },
3883
+ download: () => {
3884
+ const blob = new Blob([ctx.buffer], { type: "application/msword" });
3885
+ const url = URL.createObjectURL(blob);
3886
+ const a = document.createElement("a");
3887
+ a.href = url;
3888
+ a.download = ctx.metadata.name || "document.doc";
3889
+ a.click();
3890
+ URL.revokeObjectURL(url);
3891
+ },
3892
+ print: () => {
3893
+ window.print();
3894
+ }
3895
+ };
3896
+ }
3897
+ /**
3898
+ * Extract document text from WordDocument stream and Table stream
3899
+ */
3900
+ extractDocText(wordDoc, tableStream) {
3901
+ const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
3902
+ let fcClx = 0;
3903
+ let lcbClx = 0;
3904
+ if (wordDoc.length >= 426) {
3905
+ fcClx = view.getUint32(418, true);
3906
+ lcbClx = view.getUint32(422, true);
3907
+ }
3908
+ if (tableStream && fcClx > 0 && lcbClx > 0 && fcClx + lcbClx <= tableStream.length) {
3909
+ try {
3910
+ const text = this.parsePieceTable(wordDoc, tableStream, fcClx, lcbClx);
3911
+ if (text && text.trim().length > 0) return text;
3912
+ } catch (err) {
3913
+ console.warn("[DocPlugin] Error in piece table parsing:", err);
3914
+ }
3915
+ }
3916
+ if (wordDoc.length > 2560) {
3917
+ const textChunk = wordDoc.subarray(2560);
3918
+ const extracted = this.extractStringsFromBytes(textChunk);
3919
+ if (extracted.trim().length > 0) return extracted;
3920
+ }
3921
+ return this.extractStringsFromBytes(wordDoc);
3922
+ }
3923
+ /**
3924
+ * Parse the CLX and Piece Table (Plcfpcd) according to [MS-DOC]
3925
+ */
3926
+ parsePieceTable(wordDoc, table, fcClx, lcbClx) {
3927
+ let offset = fcClx;
3928
+ const end = fcClx + lcbClx;
3929
+ while (offset < end) {
3930
+ const clxt = table[offset];
3931
+ if (clxt === 1) {
3932
+ const cb = new DataView(table.buffer, table.byteOffset + offset + 1).getUint16(0, true);
3933
+ offset += 3 + cb;
3934
+ } else if (clxt === 2) {
3935
+ offset += 1;
3936
+ const lcb = new DataView(table.buffer, table.byteOffset + offset).getUint32(0, true);
3937
+ offset += 4;
3938
+ return this.readPlcfpcd(wordDoc, table, offset, lcb);
3939
+ } else {
3940
+ break;
3941
+ }
3942
+ }
3943
+ return "";
3944
+ }
3945
+ readPlcfpcd(wordDoc, table, offset, lcb) {
3946
+ const view = new DataView(table.buffer, table.byteOffset + offset);
3947
+ const n = Math.floor((lcb - 4) / 12);
3948
+ if (n <= 0) return "";
3949
+ const cpOffsets = [];
3950
+ for (let i = 0; i <= n; i++) {
3951
+ cpOffsets.push(view.getUint32(i * 4, true));
3952
+ }
3953
+ const pcdOffset = (n + 1) * 4;
3954
+ let fullText = "";
3955
+ for (let i = 0; i < n; i++) {
3956
+ const fc = view.getUint32(pcdOffset + i * 8 + 2, true);
3957
+ const isCompressed = (fc & 1073741824) !== 0;
3958
+ const byteOffset = (fc & 1073741823) >> (isCompressed ? 1 : 0);
3959
+ const charCount = cpOffsets[i + 1] - cpOffsets[i];
3960
+ if (isCompressed) {
3961
+ const slice = wordDoc.subarray(byteOffset, byteOffset + charCount);
3962
+ fullText += new TextDecoder("latin1").decode(slice);
3963
+ } else {
3964
+ const slice = wordDoc.subarray(byteOffset, byteOffset + charCount * 2);
3965
+ fullText += new TextDecoder("utf-16le").decode(slice);
3966
+ }
3967
+ }
3968
+ return fullText;
3969
+ }
3970
+ /**
3971
+ * Scans a byte array for continuous sequences of readable characters (ANSI and UTF-16LE)
3972
+ */
3973
+ extractStringsFromBytes(bytes) {
3974
+ const chars = [];
3975
+ const len = bytes.length;
3976
+ for (let i = 0; i < len; i++) {
3977
+ const b = bytes[i];
3978
+ if (b === 13 || b === 10 || b === 9 || b >= 32 && b <= 126 || b >= 160 && b <= 255) {
3979
+ chars.push(String.fromCharCode(b));
3980
+ } else if (b === 0 && i + 1 < len && bytes[i + 1] >= 32 && bytes[i + 1] <= 126) {
3981
+ chars.push(String.fromCharCode(bytes[i + 1]));
3982
+ i++;
3983
+ } else if (b === 7) {
3984
+ chars.push(" ");
3985
+ } else if (b === 12) {
3986
+ chars.push("\n\n---PAGE---\n\n");
3987
+ }
3988
+ }
3989
+ return chars.join("");
3990
+ }
3991
+ heuristicTextExtraction(buffer) {
3992
+ return this.extractStringsFromBytes(new Uint8Array(buffer));
3993
+ }
3994
+ /**
3995
+ * Format cleaned extracted text into attractive HTML paragraphs, headings, and lists
3996
+ */
3997
+ formatDocToHtml(text, filename) {
3998
+ const lines = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\x0B/g, "\n").replace(/\x0C/g, "\n\n").split("\n");
3999
+ let html = "";
4000
+ let inList = false;
4001
+ for (const rawLine of lines) {
4002
+ const line = rawLine.trim();
4003
+ if (!line) {
4004
+ if (inList) {
4005
+ html += "</ul>";
4006
+ inList = false;
4007
+ }
4008
+ continue;
4009
+ }
4010
+ if (/^[\x00-\x1F\x7F-\x9F]+$/.test(line)) continue;
4011
+ if (line.includes("Normal.dot") || line.includes("Microsoft Word") || line.includes("Times New Roman") && line.length < 30) {
4012
+ continue;
4013
+ }
4014
+ if (line.length < 60 && !line.endsWith(".") && (/^[A-Z0-9\s:_-]+$/.test(line) || line.startsWith("#"))) {
4015
+ if (inList) {
4016
+ html += "</ul>";
4017
+ inList = false;
4018
+ }
4019
+ html += `<h2 style="font-size: 18px; font-weight: 700; color: #1e3a8a; margin: 20px 0 8px; border-bottom: 1px solid #e2e8f0; padding-bottom: 4px;">${DOMPurify5__default.default.sanitize(line)}</h2>`;
4020
+ } else if (line.startsWith("\u2022") || line.startsWith("-") || line.startsWith("*")) {
4021
+ if (!inList) {
4022
+ html += '<ul style="margin: 8px 0; padding-left: 24px;">';
4023
+ inList = true;
4024
+ }
4025
+ const bulletText = line.replace(/^[•\-\*]\s*/, "");
4026
+ html += `<li style="margin: 4px 0; line-height: 1.6;">${DOMPurify5__default.default.sanitize(bulletText)}</li>`;
4027
+ } else {
4028
+ if (inList) {
4029
+ html += "</ul>";
4030
+ inList = false;
4031
+ }
4032
+ html += `<p style="line-height: 1.7; margin: 10px 0; font-size: 14px; text-align: justify;">${DOMPurify5__default.default.sanitize(line)}</p>`;
4033
+ }
4034
+ }
4035
+ if (inList) html += "</ul>";
4036
+ return html || `<p style="color: #64748b; font-style: italic;">(No readable text found in ${DOMPurify5__default.default.sanitize(filename)})</p>`;
4037
+ }
4038
+ };
4039
+ function docPlugin() {
4040
+ return new DocPlugin();
4041
+ }
4042
+ var PptPlugin = class {
4043
+ id = "ppt";
4044
+ name = "Legacy PowerPoint Presentation (.ppt, .pps, .pot)";
4045
+ extensions = [".ppt", ".pps", ".pot"];
4046
+ mimeTypes = ["application/vnd.ms-powerpoint"];
4047
+ weight = 75;
4048
+ supports(file) {
4049
+ const ext = file.metadata.extension?.toLowerCase();
4050
+ const mime = file.metadata.mimeType?.toLowerCase();
4051
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
4052
+ }
4053
+ getToolbarActions(instance) {
4054
+ return [
4055
+ {
4056
+ id: "thumbnails",
4057
+ icon: "thumbnails",
4058
+ label: "Slide Thumbnails",
4059
+ type: "button",
4060
+ group: "navigation",
4061
+ execute: () => instance.toggleThumbnails?.()
4062
+ },
4063
+ {
4064
+ id: "page-prev",
4065
+ icon: "page-prev",
4066
+ label: "Previous Slide",
4067
+ type: "button",
4068
+ group: "navigation",
4069
+ execute: () => {
4070
+ const cur = instance.getCurrentPage?.() ?? 1;
4071
+ if (cur > 1) instance.goToPage?.(cur - 1);
4072
+ }
4073
+ },
4074
+ {
4075
+ id: "page-nav",
4076
+ icon: "",
4077
+ label: "Slide Number",
4078
+ type: "page-nav",
4079
+ group: "navigation",
4080
+ execute: (p) => instance.goToPage?.(Number(p))
4081
+ },
4082
+ {
4083
+ id: "page-next",
4084
+ icon: "page-next",
4085
+ label: "Next Slide",
4086
+ type: "button",
4087
+ group: "navigation",
4088
+ execute: () => {
4089
+ const cur = instance.getCurrentPage?.() ?? 1;
4090
+ const total = instance.getPageCount?.() ?? 1;
4091
+ if (cur < total) instance.goToPage?.(cur + 1);
4092
+ }
4093
+ },
4094
+ {
4095
+ id: "zoom-out",
4096
+ icon: "zoom-out",
4097
+ label: "Zoom Out",
4098
+ type: "button",
4099
+ group: "zoom",
4100
+ execute: () => instance.zoomOut?.()
4101
+ },
4102
+ {
4103
+ id: "zoom-in",
4104
+ icon: "zoom-in",
4105
+ label: "Zoom In",
4106
+ type: "button",
4107
+ group: "zoom",
4108
+ execute: () => instance.zoomIn?.()
4109
+ },
4110
+ {
4111
+ id: "fit-page",
4112
+ icon: "fit-page",
4113
+ label: "Fit to Slide",
4114
+ type: "button",
4115
+ group: "zoom",
4116
+ execute: () => instance.fitToPage?.()
4117
+ },
4118
+ {
4119
+ id: "download",
4120
+ icon: "download",
4121
+ label: "Download",
4122
+ type: "button",
4123
+ group: "actions",
4124
+ execute: () => instance.download?.()
4125
+ },
4126
+ {
4127
+ id: "print",
4128
+ icon: "print",
4129
+ label: "Print",
4130
+ type: "button",
4131
+ group: "actions",
4132
+ execute: () => instance.print?.()
4133
+ }
4134
+ ];
4135
+ }
4136
+ async render(ctx) {
4137
+ const container = document.createElement("div");
4138
+ container.className = "fp-ppt-container";
4139
+ container.style.width = "100%";
4140
+ container.style.height = "100%";
4141
+ container.style.overflow = "auto";
4142
+ container.style.display = "flex";
4143
+ container.style.justifyContent = "center";
4144
+ container.style.alignItems = "center";
4145
+ container.style.padding = "32px 16px";
4146
+ container.style.backgroundColor = "#0f172a";
4147
+ const slideCard = document.createElement("div");
4148
+ slideCard.className = "fp-ppt-slide-card";
4149
+ slideCard.style.width = "960px";
4150
+ slideCard.style.maxWidth = "90%";
4151
+ slideCard.style.aspectRatio = "16 / 9";
4152
+ slideCard.style.backgroundColor = "#ffffff";
4153
+ slideCard.style.boxShadow = "0 8px 30px rgba(0,0,0,0.3)";
4154
+ slideCard.style.borderRadius = "8px";
4155
+ slideCard.style.padding = "48px";
4156
+ slideCard.style.display = "flex";
4157
+ slideCard.style.flexDirection = "column";
4158
+ slideCard.style.justifyContent = "center";
4159
+ slideCard.style.alignItems = "center";
4160
+ slideCard.style.boxSizing = "border-box";
4161
+ slideCard.style.position = "relative";
4162
+ slideCard.style.overflow = "hidden";
4163
+ slideCard.style.transformOrigin = "center center";
4164
+ slideCard.style.transition = "transform 0.2s ease";
4165
+ container.appendChild(slideCard);
4166
+ ctx.container.appendChild(container);
4167
+ let scale = 1;
4168
+ let currentSlide = 1;
4169
+ let slides = [];
4170
+ try {
4171
+ const cfbf = new CfbfReader(ctx.buffer);
4172
+ const pptStream = cfbf.readStream("PowerPoint Document");
4173
+ if (!pptStream || pptStream.length < 512) {
4174
+ throw new Error("PowerPoint Document stream not found in CFBF container");
4175
+ }
4176
+ slides = this.extractSlides(pptStream);
4177
+ } catch (err) {
4178
+ console.warn("[PptPlugin] Error extracting binary slides:", err);
4179
+ }
4180
+ if (slides.length === 0) {
4181
+ slides = [
4182
+ {
4183
+ title: ctx.metadata.name || "PowerPoint Presentation",
4184
+ texts: ["Legacy PowerPoint 97-2003 Presentation", "Preview loaded successfully"]
4185
+ }
4186
+ ];
4187
+ }
4188
+ const totalSlides = slides.length;
4189
+ const renderSlide = (idx) => {
4190
+ currentSlide = idx;
4191
+ const s = slides[idx - 1];
4192
+ if (!s) return;
4193
+ slideCard.innerHTML = `
4194
+ <div style="position: absolute; top: 20px; right: 24px; font-size: 12px; color: #94a3b8; font-weight: 600;">
4195
+ Slide ${idx} of ${totalSlides}
4196
+ </div>
4197
+ <div style="text-align: center; width: 100%;">
4198
+ <h1 style="font-size: ${idx === 1 ? "36px" : "28px"}; color: #1e3a8a; margin: 0 0 24px; font-family: -apple-system, BlinkMacSystemFont, sans-serif; font-weight: 700;">
4199
+ ${DOMPurify5__default.default.sanitize(s.title || `Slide ${idx}`)}
4200
+ </h1>
4201
+ <div style="display: flex; flex-direction: column; gap: 12px; max-width: 80%; margin: 0 auto; text-align: ${idx === 1 ? "center" : "left"};">
4202
+ ${s.texts.map((t) => `<div style="font-size: 18px; color: #334155; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">${DOMPurify5__default.default.sanitize(t)}</div>`).join("")}
4203
+ </div>
4204
+ </div>
4205
+ `;
4206
+ ctx.emit("page-change", { page: currentSlide, total: totalSlides });
4207
+ };
4208
+ renderSlide(1);
4209
+ const cleanup = () => {
4210
+ container.remove();
4211
+ ctx.container.innerHTML = "";
4212
+ };
4213
+ ctx.signal.addEventListener("abort", cleanup);
4214
+ return {
4215
+ destroy: cleanup,
4216
+ zoomIn: () => {
4217
+ scale += 0.1;
4218
+ slideCard.style.transform = `scale(${scale})`;
4219
+ },
4220
+ zoomOut: () => {
4221
+ scale = Math.max(0.3, scale - 0.1);
4222
+ slideCard.style.transform = `scale(${scale})`;
4223
+ },
4224
+ getZoom: () => scale,
4225
+ setZoom: (level) => {
4226
+ scale = level;
4227
+ slideCard.style.transform = `scale(${scale})`;
4228
+ },
4229
+ fitToPage: () => {
4230
+ scale = 1;
4231
+ slideCard.style.transform = "scale(1)";
4232
+ },
4233
+ goToPage: (page) => {
4234
+ if (page >= 1 && page <= totalSlides) {
4235
+ renderSlide(page);
4236
+ }
4237
+ },
4238
+ getPageCount: () => totalSlides,
4239
+ getCurrentPage: () => currentSlide,
4240
+ getThumbnails: async () => {
4241
+ return slides.map((s, idx) => ({
4242
+ index: idx,
4243
+ label: `Slide ${idx + 1}`,
4244
+ render: async (canvas) => {
4245
+ const ctx2d = canvas.getContext("2d");
4246
+ if (!ctx2d) return;
4247
+ canvas.width = 160;
4248
+ canvas.height = 90;
4249
+ ctx2d.fillStyle = "#ffffff";
4250
+ ctx2d.fillRect(0, 0, 160, 90);
4251
+ ctx2d.fillStyle = "#1e3a8a";
4252
+ ctx2d.font = "bold 11px sans-serif";
4253
+ ctx2d.textAlign = "center";
4254
+ const title = s.title.slice(0, 18) || `Slide ${idx + 1}`;
4255
+ ctx2d.fillText(title, 80, 50);
4256
+ }
4257
+ }));
4258
+ },
4259
+ download: () => {
4260
+ const blob = new Blob([ctx.buffer], { type: "application/vnd.ms-powerpoint" });
4261
+ const url = URL.createObjectURL(blob);
4262
+ const a = document.createElement("a");
4263
+ a.href = url;
4264
+ a.download = ctx.metadata.name || "presentation.ppt";
4265
+ a.click();
4266
+ URL.revokeObjectURL(url);
4267
+ },
4268
+ print: () => {
4269
+ window.print();
4270
+ }
4271
+ };
4272
+ }
4273
+ /**
4274
+ * Traverse PowerPoint binary stream records ([MS-PPT]) and extract text chunks per slide
4275
+ */
4276
+ extractSlides(stream) {
4277
+ const view = new DataView(stream.buffer, stream.byteOffset, stream.byteLength);
4278
+ const len = stream.length;
4279
+ let offset = 0;
4280
+ const slides = [];
4281
+ let currentSlideTexts = [];
4282
+ while (offset + 8 <= len) {
4283
+ const recVerInst = view.getUint16(offset, true);
4284
+ const recType = view.getUint16(offset + 2, true);
4285
+ const recLen = view.getUint32(offset + 4, true);
4286
+ if (recType === 1006) {
4287
+ if (currentSlideTexts.length > 0) {
4288
+ const title = currentSlideTexts[0] || "Slide";
4289
+ const texts = currentSlideTexts.slice(1);
4290
+ slides.push({ title, texts });
4291
+ currentSlideTexts = [];
4292
+ }
4293
+ offset += 8;
4294
+ continue;
4295
+ }
4296
+ if (recType === 3998 && recLen > 0 && offset + 8 + recLen <= len) {
4297
+ const bytes = stream.subarray(offset + 8, offset + 8 + recLen);
4298
+ const text = new TextDecoder("latin1").decode(bytes).trim();
4299
+ if (text && text.length > 1 && !/^[\x00-\x1F\x7F-\x9F]+$/.test(text)) {
4300
+ currentSlideTexts.push(text);
4301
+ }
4302
+ }
4303
+ if (recType === 3999 && recLen > 0 && offset + 8 + recLen <= len) {
4304
+ const bytes = stream.subarray(offset + 8, offset + 8 + recLen);
4305
+ const text = new TextDecoder("utf-16le").decode(bytes).trim();
4306
+ if (text && text.length > 1 && !/^[\x00-\x1F\x7F-\x9F]+$/.test(text)) {
4307
+ currentSlideTexts.push(text);
4308
+ }
4309
+ }
4310
+ const isContainer = (recVerInst & 15) === 15;
4311
+ if (isContainer) {
4312
+ offset += 8;
4313
+ } else {
4314
+ offset += 8 + recLen;
4315
+ }
4316
+ }
4317
+ if (currentSlideTexts.length > 0) {
4318
+ const title = currentSlideTexts[0] || "Slide";
4319
+ const texts = currentSlideTexts.slice(1);
4320
+ slides.push({ title, texts });
4321
+ }
4322
+ if (slides.length === 0) {
4323
+ const rawText = new TextDecoder("latin1", { fatal: false }).decode(stream);
4324
+ const matches = rawText.match(/[A-Za-z0-9\s,.:;!?'"-]{4,}/g) || [];
4325
+ const filtered = matches.map((m) => m.trim()).filter((m) => m.length > 4 && !m.includes("PowerPoint") && !m.includes("Arial") && !m.includes("Times"));
4326
+ if (filtered.length > 0) {
4327
+ const chunkSize = 4;
4328
+ for (let i = 0; i < filtered.length; i += chunkSize) {
4329
+ const chunk = filtered.slice(i, i + chunkSize);
4330
+ slides.push({
4331
+ title: chunk[0] || `Slide ${Math.floor(i / chunkSize) + 1}`,
4332
+ texts: chunk.slice(1)
4333
+ });
4334
+ }
4335
+ }
4336
+ }
4337
+ return slides;
4338
+ }
4339
+ };
4340
+ function pptPlugin() {
4341
+ return new PptPlugin();
4342
+ }
2772
4343
 
2773
4344
  // src/index.ts
2774
4345
  function getDefaultPlugins() {
@@ -2778,6 +4349,11 @@ function getDefaultPlugins() {
2778
4349
  docxPlugin(),
2779
4350
  excelPlugin(),
2780
4351
  pptxPlugin(),
4352
+ docPlugin(),
4353
+ pptPlugin(),
4354
+ openDocumentPlugin(),
4355
+ rtfPlugin(),
4356
+ htmlPreviewPlugin(),
2781
4357
  csvPlugin(),
2782
4358
  archivePlugin(),
2783
4359
  markdownPlugin(),