@files-preview-app/preview-file 1.1.6 → 1.2.1

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/vue.cjs CHANGED
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var vue = require('vue');
6
- var DOMPurify = require('dompurify');
6
+ var DOMPurify5 = require('dompurify');
7
7
  var docx = require('docx-preview');
8
- var ExcelJS = require('exceljs');
8
+ var XLSX = require('xlsx');
9
9
  var hljs = require('highlight.js');
10
10
  var fflate = require('fflate');
11
11
  var marked = require('marked');
@@ -14,6 +14,7 @@ var THREE = require('three');
14
14
  var STLLoader_js = require('three/examples/jsm/loaders/STLLoader.js');
15
15
  var OBJLoader_js = require('three/examples/jsm/loaders/OBJLoader.js');
16
16
  var OrbitControls_js = require('three/examples/jsm/controls/OrbitControls.js');
17
+ var rtf_js = require('rtf.js');
17
18
 
18
19
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
20
 
@@ -35,9 +36,9 @@ function _interopNamespace(e) {
35
36
  return Object.freeze(n);
36
37
  }
37
38
 
38
- var DOMPurify__default = /*#__PURE__*/_interopDefault(DOMPurify);
39
+ var DOMPurify5__default = /*#__PURE__*/_interopDefault(DOMPurify5);
39
40
  var docx__namespace = /*#__PURE__*/_interopNamespace(docx);
40
- var ExcelJS__default = /*#__PURE__*/_interopDefault(ExcelJS);
41
+ var XLSX__namespace = /*#__PURE__*/_interopNamespace(XLSX);
41
42
  var hljs__default = /*#__PURE__*/_interopDefault(hljs);
42
43
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
43
44
 
@@ -103,7 +104,9 @@ var MAGIC_NUMBERS = [
103
104
  { bytes: [37, 80, 68, 70], mime: "application/pdf" },
104
105
  // %PDF
105
106
  { bytes: [80, 75, 3, 4], mime: "application/zip" },
106
- // PK.. (ZIP/DOCX/XLSX/PPTX)
107
+ // PK.. (ZIP/DOCX/XLSX/PPTX/ODT/ODS/ODP)
108
+ { bytes: [208, 207, 17, 224, 161, 177, 26, 225], mime: "application/x-cfbf" },
109
+ // CFBF/OLE2 (DOC/XLS/PPT)
107
110
  { bytes: [137, 80, 78, 71, 13, 10, 26, 10], mime: "image/png" },
108
111
  // PNG
109
112
  { bytes: [255, 216, 255], mime: "image/jpeg" },
@@ -138,14 +141,40 @@ var MAGIC_NUMBERS = [
138
141
  // RTF
139
142
  ];
140
143
  var EXTENSION_MIME_MAP = {
141
- // Documents
144
+ // Documents — Modern OOXML
142
145
  ".pdf": "application/pdf",
143
146
  ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
147
+ ".docm": "application/vnd.ms-word.document.macroEnabled.12",
148
+ ".dotx": "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
149
+ ".dotm": "application/vnd.ms-word.template.macroEnabled.12",
144
150
  ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
151
+ ".xlsm": "application/vnd.ms-excel.sheet.macroEnabled.12",
152
+ ".xlsb": "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
153
+ ".xltx": "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
154
+ ".xltm": "application/vnd.ms-excel.template.macroEnabled.12",
145
155
  ".xls": "application/vnd.ms-excel",
146
156
  ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
157
+ ".ppsx": "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
158
+ ".pptm": "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
159
+ ".ppsm": "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
160
+ ".potx": "application/vnd.openxmlformats-officedocument.presentationml.template",
161
+ ".potm": "application/vnd.ms-powerpoint.template.macroEnabled.12",
147
162
  ".csv": "text/csv",
148
163
  ".tsv": "text/tab-separated-values",
164
+ // Documents — Legacy Binary (CFBF/OLE2)
165
+ ".doc": "application/msword",
166
+ ".dot": "application/msword",
167
+ ".ppt": "application/vnd.ms-powerpoint",
168
+ ".pps": "application/vnd.ms-powerpoint",
169
+ ".pot": "application/vnd.ms-powerpoint",
170
+ // Documents — OpenDocument (ODF)
171
+ ".odt": "application/vnd.oasis.opendocument.text",
172
+ ".ods": "application/vnd.oasis.opendocument.spreadsheet",
173
+ ".odp": "application/vnd.oasis.opendocument.presentation",
174
+ ".odg": "application/vnd.oasis.opendocument.graphics",
175
+ ".odf": "application/vnd.oasis.opendocument.formula",
176
+ // Documents — RTF
177
+ ".rtf": "text/rtf",
149
178
  // Images
150
179
  ".png": "image/png",
151
180
  ".jpg": "image/jpeg",
@@ -239,7 +268,7 @@ function detectMagicBytes(buffer) {
239
268
  }
240
269
  function detectOoxmlType(buffer) {
241
270
  const text = new TextDecoder("ascii", { fatal: false }).decode(
242
- new Uint8Array(buffer.slice(0, 4e3))
271
+ new Uint8Array(buffer.slice(0, 8e3))
243
272
  );
244
273
  if (text.includes("word/")) {
245
274
  return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
@@ -250,6 +279,21 @@ function detectOoxmlType(buffer) {
250
279
  if (text.includes("ppt/")) {
251
280
  return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
252
281
  }
282
+ if (text.includes("application/vnd.oasis.opendocument.text")) {
283
+ return "application/vnd.oasis.opendocument.text";
284
+ }
285
+ if (text.includes("application/vnd.oasis.opendocument.spreadsheet")) {
286
+ return "application/vnd.oasis.opendocument.spreadsheet";
287
+ }
288
+ if (text.includes("application/vnd.oasis.opendocument.presentation")) {
289
+ return "application/vnd.oasis.opendocument.presentation";
290
+ }
291
+ if (text.includes("application/vnd.oasis.opendocument.graphics")) {
292
+ return "application/vnd.oasis.opendocument.graphics";
293
+ }
294
+ if (text.includes("application/vnd.oasis.opendocument.formula")) {
295
+ return "application/vnd.oasis.opendocument.formula";
296
+ }
253
297
  return "application/zip";
254
298
  }
255
299
  function extractExtension(nameOrUrl) {
@@ -326,7 +370,7 @@ async function sourceToArrayBuffer(source, signal) {
326
370
  return { buffer, metadata };
327
371
  }
328
372
  function sanitizeSVG(svg) {
329
- return DOMPurify__default.default.sanitize(svg, {
373
+ return DOMPurify5__default.default.sanitize(svg, {
330
374
  USE_PROFILES: { svg: true, svgFilters: true }
331
375
  });
332
376
  }
@@ -894,6 +938,192 @@ var FilePreviewViewer = class {
894
938
  this.contentEl.appendChild(errorEl);
895
939
  }
896
940
  };
941
+ var CfbfReader = class {
942
+ view;
943
+ u8;
944
+ sectorSize;
945
+ miniSectorSize;
946
+ miniStreamCutoff;
947
+ fat = [];
948
+ miniFat = [];
949
+ entries = /* @__PURE__ */ new Map();
950
+ miniStream = new Uint8Array(0);
951
+ constructor(buffer) {
952
+ this.u8 = new Uint8Array(buffer);
953
+ this.view = new DataView(buffer);
954
+ if (!this.isValid()) {
955
+ throw new Error("Invalid CFBF / OLE2 file header signature");
956
+ }
957
+ const sectorShift = this.view.getUint16(30, true);
958
+ this.sectorSize = 1 << sectorShift;
959
+ const miniSectorShift = this.view.getUint16(32, true);
960
+ this.miniSectorSize = 1 << miniSectorShift;
961
+ this.miniStreamCutoff = this.view.getUint32(56, true) || 4096;
962
+ this.parseFat();
963
+ this.parseDirectory();
964
+ this.parseMiniFat();
965
+ }
966
+ /** Check if the magic 8-byte signature matches [MS-CFB] */
967
+ isValid() {
968
+ if (this.u8.length < 512) return false;
969
+ const sig = [208, 207, 17, 224, 161, 177, 26, 225];
970
+ return sig.every((b, i) => this.u8[i] === b);
971
+ }
972
+ /** Return all directory stream/storage entries found in the file */
973
+ listEntries() {
974
+ return Array.from(this.entries.values());
975
+ }
976
+ /** Check if a stream exists */
977
+ hasStream(name) {
978
+ return this.entries.has(name) || this.findEntryCaseInsensitive(name) !== null;
979
+ }
980
+ /**
981
+ * Read raw bytes of a named stream (e.g. "WordDocument", "PowerPoint Document", "Workbook")
982
+ */
983
+ readStream(name) {
984
+ const entry = this.entries.get(name) || this.findEntryCaseInsensitive(name);
985
+ if (!entry) return null;
986
+ if (entry.size === 0) return new Uint8Array(0);
987
+ if (entry.size < this.miniStreamCutoff && entry.type !== 5) {
988
+ return this.readMiniStream(entry.startSector, entry.size);
989
+ } else {
990
+ return this.readRegularStream(entry.startSector, entry.size);
991
+ }
992
+ }
993
+ findEntryCaseInsensitive(name) {
994
+ const lower = name.toLowerCase();
995
+ for (const [key, val] of this.entries.entries()) {
996
+ if (key.toLowerCase() === lower) return val;
997
+ }
998
+ return null;
999
+ }
1000
+ getSectorOffset(sectId) {
1001
+ return (sectId + 1) * this.sectorSize;
1002
+ }
1003
+ parseFat() {
1004
+ this.view.getUint32(44, true);
1005
+ const difat = [];
1006
+ for (let i = 0; i < 109; i++) {
1007
+ const sect = this.view.getUint32(76 + i * 4, true);
1008
+ if (sect !== 4294967295 && sect !== 4294967294) {
1009
+ difat.push(sect);
1010
+ }
1011
+ }
1012
+ let difatSect = this.view.getUint32(68, true);
1013
+ const csectDif = this.view.getUint32(72, true);
1014
+ const entriesPerSector = this.sectorSize / 4 - 1;
1015
+ for (let i = 0; i < csectDif && difatSect < 4294967294; i++) {
1016
+ const offset = this.getSectorOffset(difatSect);
1017
+ for (let j = 0; j < entriesPerSector; j++) {
1018
+ const sect = this.view.getUint32(offset + j * 4, true);
1019
+ if (sect !== 4294967295 && sect !== 4294967294) {
1020
+ difat.push(sect);
1021
+ }
1022
+ }
1023
+ difatSect = this.view.getUint32(offset + entriesPerSector * 4, true);
1024
+ }
1025
+ for (const fatSect of difat) {
1026
+ if (fatSect >= 4294967294) continue;
1027
+ const offset = this.getSectorOffset(fatSect);
1028
+ const count = this.sectorSize / 4;
1029
+ for (let j = 0; j < count; j++) {
1030
+ this.fat.push(this.view.getUint32(offset + j * 4, true));
1031
+ }
1032
+ }
1033
+ }
1034
+ parseDirectory() {
1035
+ const dirStartSect = this.view.getUint32(48, true);
1036
+ const dirBytes = this.readRegularStream(dirStartSect);
1037
+ const dirView = new DataView(dirBytes.buffer, dirBytes.byteOffset, dirBytes.byteLength);
1038
+ const entryCount = dirBytes.length / 128;
1039
+ for (let i = 0; i < entryCount; i++) {
1040
+ const offset = i * 128;
1041
+ const type = dirView.getUint8(offset + 66);
1042
+ if (type === 0) continue;
1043
+ const nameLen = dirView.getUint16(offset + 64, true);
1044
+ let name = "";
1045
+ if (nameLen > 2) {
1046
+ const charCount = nameLen / 2 - 1;
1047
+ const chars = [];
1048
+ for (let c = 0; c < charCount; c++) {
1049
+ const charCode = dirView.getUint16(offset + c * 2, true);
1050
+ chars.push(String.fromCharCode(charCode));
1051
+ }
1052
+ name = chars.join("");
1053
+ }
1054
+ const startSector = dirView.getUint32(offset + 116, true);
1055
+ const size = dirView.getUint32(offset + 120, true);
1056
+ const entry = { name, type, size, startSector };
1057
+ this.entries.set(name, entry);
1058
+ if (type === 5) {
1059
+ this.miniStream = this.readRegularStream(startSector, size);
1060
+ }
1061
+ }
1062
+ }
1063
+ parseMiniFat() {
1064
+ const miniFatStart = this.view.getUint32(60, true);
1065
+ const csectMiniFat = this.view.getUint32(64, true);
1066
+ if (miniFatStart >= 4294967294 || csectMiniFat === 0) return;
1067
+ let sect = miniFatStart;
1068
+ for (let i = 0; i < csectMiniFat && sect < 4294967294; i++) {
1069
+ const offset = this.getSectorOffset(sect);
1070
+ const count = this.sectorSize / 4;
1071
+ for (let j = 0; j < count; j++) {
1072
+ this.miniFat.push(this.view.getUint32(offset + j * 4, true));
1073
+ }
1074
+ sect = this.fat[sect] ?? 4294967294;
1075
+ }
1076
+ }
1077
+ readRegularStream(startSector, targetSize) {
1078
+ if (startSector >= 4294967294) return new Uint8Array(0);
1079
+ const chunks = [];
1080
+ let curr = startSector;
1081
+ let totalBytes = 0;
1082
+ const visited = /* @__PURE__ */ new Set();
1083
+ while (curr < 4294967294 && !visited.has(curr)) {
1084
+ visited.add(curr);
1085
+ const offset = this.getSectorOffset(curr);
1086
+ if (offset + this.sectorSize <= this.u8.length) {
1087
+ chunks.push(this.u8.subarray(offset, offset + this.sectorSize));
1088
+ totalBytes += this.sectorSize;
1089
+ }
1090
+ curr = this.fat[curr] ?? 4294967294;
1091
+ }
1092
+ const result = new Uint8Array(totalBytes);
1093
+ let pos = 0;
1094
+ for (const chunk of chunks) {
1095
+ result.set(chunk, pos);
1096
+ pos += chunk.length;
1097
+ }
1098
+ if (targetSize !== void 0 && targetSize < result.length) {
1099
+ return result.subarray(0, targetSize);
1100
+ }
1101
+ return result;
1102
+ }
1103
+ readMiniStream(startSector, targetSize) {
1104
+ if (this.miniStream.length === 0 || startSector >= 4294967294) return new Uint8Array(0);
1105
+ const chunks = [];
1106
+ let curr = startSector;
1107
+ let totalBytes = 0;
1108
+ const visited = /* @__PURE__ */ new Set();
1109
+ while (curr < 4294967294 && !visited.has(curr)) {
1110
+ visited.add(curr);
1111
+ const offset = curr * this.miniSectorSize;
1112
+ if (offset + this.miniSectorSize <= this.miniStream.length) {
1113
+ chunks.push(this.miniStream.subarray(offset, offset + this.miniSectorSize));
1114
+ totalBytes += this.miniSectorSize;
1115
+ }
1116
+ curr = this.miniFat[curr] ?? 4294967294;
1117
+ }
1118
+ const result = new Uint8Array(totalBytes);
1119
+ let pos = 0;
1120
+ for (const chunk of chunks) {
1121
+ result.set(chunk, pos);
1122
+ pos += chunk.length;
1123
+ }
1124
+ return result.subarray(0, targetSize);
1125
+ }
1126
+ };
897
1127
 
898
1128
  // ../plugins/pdf/dist/index.js
899
1129
  var PdfPlugin = class {
@@ -1304,13 +1534,18 @@ function mediaPlugin() {
1304
1534
  var DocxPlugin = class {
1305
1535
  id = "docx";
1306
1536
  name = "Word Document Preview";
1307
- extensions = [".docx"];
1308
- mimeTypes = ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"];
1537
+ extensions = [".docx", ".docm", ".dotx", ".dotm"];
1538
+ mimeTypes = [
1539
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1540
+ "application/vnd.ms-word.document.macroEnabled.12",
1541
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
1542
+ "application/vnd.ms-word.template.macroEnabled.12"
1543
+ ];
1309
1544
  weight = 80;
1310
1545
  supports(file) {
1311
1546
  const ext = file.metadata.extension?.toLowerCase();
1312
1547
  const mime = file.metadata.mimeType?.toLowerCase();
1313
- return ext === ".docx" || this.mimeTypes.includes(mime || "");
1548
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
1314
1549
  }
1315
1550
  getToolbarActions(instance) {
1316
1551
  return [
@@ -1434,11 +1669,16 @@ function docxPlugin() {
1434
1669
  }
1435
1670
  var ExcelPlugin = class {
1436
1671
  id = "excel";
1437
- name = "Excel Spreadsheet Preview";
1438
- extensions = [".xlsx", ".xls"];
1672
+ name = "Spreadsheet Preview (Excel / OpenDocument)";
1673
+ extensions = [".xlsx", ".xls", ".xlsm", ".xlsb", ".xltx", ".xltm", ".ods"];
1439
1674
  mimeTypes = [
1440
1675
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1441
- "application/vnd.ms-excel"
1676
+ "application/vnd.ms-excel",
1677
+ "application/vnd.ms-excel.sheet.macroEnabled.12",
1678
+ "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
1679
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
1680
+ "application/vnd.ms-excel.template.macroEnabled.12",
1681
+ "application/vnd.oasis.opendocument.spreadsheet"
1442
1682
  ];
1443
1683
  weight = 80;
1444
1684
  supports(file) {
@@ -1502,70 +1742,111 @@ var ExcelPlugin = class {
1502
1742
  }
1503
1743
  async render(ctx) {
1504
1744
  const container = document.createElement("div");
1745
+ container.className = "fp-excel-container";
1505
1746
  container.style.display = "flex";
1506
1747
  container.style.flexDirection = "column";
1507
1748
  container.style.width = "100%";
1508
1749
  container.style.height = "100%";
1509
1750
  container.style.overflow = "hidden";
1510
1751
  const contentArea = document.createElement("div");
1752
+ contentArea.className = "fp-excel-content";
1511
1753
  contentArea.style.flex = "1";
1512
1754
  contentArea.style.overflow = "auto";
1513
1755
  contentArea.style.padding = "16px";
1514
1756
  contentArea.style.transformOrigin = "top left";
1515
1757
  const tabsArea = document.createElement("div");
1758
+ tabsArea.className = "fp-excel-tabs";
1516
1759
  tabsArea.style.display = "flex";
1517
- tabsArea.style.gap = "8px";
1760
+ tabsArea.style.gap = "6px";
1518
1761
  tabsArea.style.padding = "8px 16px";
1519
1762
  tabsArea.style.borderTop = "1px solid #e0e0e0";
1520
1763
  tabsArea.style.backgroundColor = "#fafafa";
1521
1764
  tabsArea.style.overflowX = "auto";
1765
+ tabsArea.style.flexShrink = "0";
1522
1766
  container.appendChild(contentArea);
1523
1767
  container.appendChild(tabsArea);
1524
1768
  ctx.container.appendChild(container);
1525
1769
  let scale = 1;
1526
1770
  let currentSheetIndex = 1;
1527
- const workbook = new ExcelJS__default.default.Workbook();
1771
+ let sheetNames = [];
1772
+ let wb = null;
1528
1773
  try {
1529
- await workbook.xlsx.load(ctx.buffer);
1530
- } catch {
1774
+ wb = XLSX__namespace.read(new Uint8Array(ctx.buffer), { type: "array", cellDates: true });
1775
+ sheetNames = wb.SheetNames || [];
1776
+ } catch (err) {
1777
+ console.warn("[ExcelPlugin] SheetJS parse failed, rendering fallback:", err);
1531
1778
  }
1779
+ const tabButtons = [];
1532
1780
  const renderSheet = (index) => {
1781
+ if (!wb || index < 1 || index > sheetNames.length) return;
1782
+ currentSheetIndex = index;
1783
+ const sheetName = sheetNames[index - 1];
1784
+ const ws = wb.Sheets[sheetName];
1533
1785
  contentArea.innerHTML = "";
1534
- const sheet = workbook.getWorksheet(index);
1535
- if (!sheet) return;
1536
- const table = document.createElement("table");
1537
- table.style.borderCollapse = "collapse";
1538
- table.style.fontFamily = "sans-serif";
1539
- table.style.fontSize = "13px";
1540
- table.style.minWidth = "100%";
1541
- sheet.eachRow({ includeEmpty: false }, (row) => {
1542
- const tr = document.createElement("tr");
1543
- row.eachCell({ includeEmpty: true }, (cell) => {
1544
- const td = document.createElement("td");
1545
- td.style.border = "1px solid #d0d7de";
1546
- td.style.padding = "6px 12px";
1547
- td.textContent = cell.text || "";
1548
- tr.appendChild(td);
1786
+ if (!ws) {
1787
+ contentArea.innerHTML = '<div style="padding: 24px; color: #888;">Empty sheet</div>';
1788
+ return;
1789
+ }
1790
+ const html = XLSX__namespace.utils.sheet_to_html(ws, { id: "fp-sheet-table", editable: false });
1791
+ contentArea.innerHTML = html;
1792
+ const table = contentArea.querySelector("table");
1793
+ if (table) {
1794
+ table.style.borderCollapse = "collapse";
1795
+ table.style.fontFamily = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
1796
+ table.style.fontSize = "13px";
1797
+ table.style.minWidth = "100%";
1798
+ table.style.border = "1px solid #d0d7de";
1799
+ table.style.background = "#fff";
1800
+ table.querySelectorAll("td, th").forEach((cell) => {
1801
+ const el = cell;
1802
+ el.style.border = "1px solid #d0d7de";
1803
+ el.style.padding = "6px 12px";
1804
+ el.style.whiteSpace = "nowrap";
1549
1805
  });
1550
- table.appendChild(tr);
1806
+ table.querySelectorAll("tr:first-child td, th").forEach((cell) => {
1807
+ const el = cell;
1808
+ el.style.fontWeight = "600";
1809
+ el.style.backgroundColor = "#f6f8fa";
1810
+ });
1811
+ }
1812
+ tabButtons.forEach((b, i) => {
1813
+ if (i === index - 1) {
1814
+ b.style.backgroundColor = "#2563eb";
1815
+ b.style.color = "#fff";
1816
+ b.style.borderColor = "#2563eb";
1817
+ b.style.fontWeight = "600";
1818
+ } else {
1819
+ b.style.backgroundColor = "#fff";
1820
+ b.style.color = "#333";
1821
+ b.style.borderColor = "#ccc";
1822
+ b.style.fontWeight = "normal";
1823
+ }
1551
1824
  });
1552
- contentArea.appendChild(table);
1553
- currentSheetIndex = index;
1554
1825
  };
1555
- workbook.worksheets.forEach((sheet, idx) => {
1556
- const btn = document.createElement("button");
1557
- btn.textContent = sheet.name;
1558
- btn.style.padding = "4px 12px";
1559
- btn.style.fontSize = "12px";
1560
- btn.style.cursor = "pointer";
1561
- btn.style.border = "1px solid #ccc";
1562
- btn.style.borderRadius = "4px";
1563
- btn.style.backgroundColor = "#fff";
1564
- btn.onclick = () => renderSheet(idx + 1);
1565
- tabsArea.appendChild(btn);
1566
- });
1567
- if (workbook.worksheets.length > 0) {
1826
+ if (sheetNames.length > 0) {
1827
+ sheetNames.forEach((name, idx) => {
1828
+ const btn = document.createElement("button");
1829
+ btn.textContent = name;
1830
+ btn.style.padding = "4px 12px";
1831
+ btn.style.fontSize = "12px";
1832
+ btn.style.cursor = "pointer";
1833
+ btn.style.border = "1px solid #ccc";
1834
+ btn.style.borderRadius = "4px";
1835
+ btn.style.backgroundColor = "#fff";
1836
+ btn.style.transition = "all 0.15s ease";
1837
+ btn.onclick = () => renderSheet(idx + 1);
1838
+ tabsArea.appendChild(btn);
1839
+ tabButtons.push(btn);
1840
+ });
1568
1841
  renderSheet(1);
1842
+ } else {
1843
+ contentArea.innerHTML = `
1844
+ <div style="text-align:center; padding: 40px; color: #666;">
1845
+ <div style="font-size:48px; margin-bottom: 16px;">\u{1F4CA}</div>
1846
+ <h3>${ctx.metadata.name || "Spreadsheet"}</h3>
1847
+ <p>Unable to load sheet data</p>
1848
+ </div>
1849
+ `;
1569
1850
  }
1570
1851
  const cleanup = () => {
1571
1852
  container.remove();
@@ -1588,11 +1869,11 @@ var ExcelPlugin = class {
1588
1869
  contentArea.style.transform = `scale(${scale})`;
1589
1870
  },
1590
1871
  goToPage: (page) => {
1591
- if (page > 0 && page <= workbook.worksheets.length) {
1872
+ if (page > 0 && page <= sheetNames.length) {
1592
1873
  renderSheet(page);
1593
1874
  }
1594
1875
  },
1595
- getPageCount: () => workbook.worksheets.length,
1876
+ getPageCount: () => sheetNames.length,
1596
1877
  getCurrentPage: () => currentSheetIndex,
1597
1878
  download: () => {
1598
1879
  const blob = new Blob([ctx.buffer], { type: this.mimeTypes[0] });
@@ -2193,7 +2474,7 @@ var MarkdownPlugin = class {
2193
2474
  gfm: true,
2194
2475
  breaks: true
2195
2476
  });
2196
- const cleanHtml = DOMPurify__default.default.sanitize(rawHtml, {
2477
+ const cleanHtml = DOMPurify5__default.default.sanitize(rawHtml, {
2197
2478
  USE_PROFILES: { html: true }
2198
2479
  });
2199
2480
  const wrapper = document.createElement("div");
@@ -2332,10 +2613,14 @@ function markdownPlugin() {
2332
2613
  var PptxPlugin = class {
2333
2614
  id = "pptx";
2334
2615
  name = "PowerPoint Presentation";
2335
- extensions = [".pptx", ".ppsx"];
2616
+ extensions = [".pptx", ".ppsx", ".pptm", ".ppsm", ".potx", ".potm"];
2336
2617
  mimeTypes = [
2337
2618
  "application/vnd.openxmlformats-officedocument.presentationml.presentation",
2338
- "application/vnd.openxmlformats-officedocument.presentationml.slideshow"
2619
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
2620
+ "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
2621
+ "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
2622
+ "application/vnd.openxmlformats-officedocument.presentationml.template",
2623
+ "application/vnd.ms-powerpoint.template.macroEnabled.12"
2339
2624
  ];
2340
2625
  weight = 80;
2341
2626
  supports(file) {
@@ -2721,6 +3006,1292 @@ var ThreeDPlugin = class {
2721
3006
  function threeDPlugin() {
2722
3007
  return new ThreeDPlugin();
2723
3008
  }
3009
+ var RtfPlugin = class {
3010
+ id = "rtf";
3011
+ name = "Rich Text Format (RTF)";
3012
+ extensions = [".rtf"];
3013
+ mimeTypes = ["text/rtf", "application/rtf"];
3014
+ weight = 80;
3015
+ supports(file) {
3016
+ const ext = file.metadata.extension?.toLowerCase();
3017
+ const mime = file.metadata.mimeType?.toLowerCase();
3018
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3019
+ }
3020
+ getToolbarActions(instance) {
3021
+ return [
3022
+ {
3023
+ id: "zoom-out",
3024
+ icon: "zoom-out",
3025
+ label: "Zoom Out",
3026
+ type: "button",
3027
+ group: "zoom",
3028
+ execute: () => instance.zoomOut?.()
3029
+ },
3030
+ {
3031
+ id: "zoom-in",
3032
+ icon: "zoom-in",
3033
+ label: "Zoom In",
3034
+ type: "button",
3035
+ group: "zoom",
3036
+ execute: () => instance.zoomIn?.()
3037
+ },
3038
+ {
3039
+ id: "fit-page",
3040
+ icon: "fit-page",
3041
+ label: "Fit to Page",
3042
+ type: "button",
3043
+ group: "zoom",
3044
+ execute: () => instance.fitToPage?.()
3045
+ },
3046
+ {
3047
+ id: "download",
3048
+ icon: "download",
3049
+ label: "Download",
3050
+ type: "button",
3051
+ group: "actions",
3052
+ execute: () => instance.download?.()
3053
+ },
3054
+ {
3055
+ id: "print",
3056
+ icon: "print",
3057
+ label: "Print",
3058
+ type: "button",
3059
+ group: "actions",
3060
+ execute: () => instance.print?.()
3061
+ }
3062
+ ];
3063
+ }
3064
+ async render(ctx) {
3065
+ const wrapper = document.createElement("div");
3066
+ wrapper.className = "fp-rtf-wrapper";
3067
+ wrapper.style.padding = "32px";
3068
+ wrapper.style.maxWidth = "850px";
3069
+ wrapper.style.margin = "0 auto";
3070
+ wrapper.style.backgroundColor = "#fff";
3071
+ wrapper.style.boxShadow = "0 2px 8px rgba(0,0,0,0.08)";
3072
+ wrapper.style.borderRadius = "4px";
3073
+ wrapper.style.minHeight = "100%";
3074
+ wrapper.style.transformOrigin = "top center";
3075
+ wrapper.style.transition = "transform 0.2s ease";
3076
+ ctx.container.style.overflow = "auto";
3077
+ ctx.container.style.padding = "24px";
3078
+ ctx.container.style.backgroundColor = "#f1f5f9";
3079
+ ctx.container.appendChild(wrapper);
3080
+ let scale = 1;
3081
+ try {
3082
+ const doc = new rtf_js.RTFJS.Document(ctx.buffer, {});
3083
+ const htmlElements = await doc.render();
3084
+ for (const el of htmlElements) {
3085
+ wrapper.appendChild(el);
3086
+ }
3087
+ } catch (err) {
3088
+ console.warn("[RtfPlugin] RTF render error, fallback text:", err);
3089
+ const text = new TextDecoder("latin1").decode(ctx.buffer);
3090
+ const clean = text.replace(/\\par[d]?/g, "\n").replace(/\\[a-zA-Z0-9\-]+/g, "").replace(/[{}]/g, "");
3091
+ wrapper.innerHTML = `<pre style="white-space: pre-wrap; font-family: serif; color: #333;">${clean}</pre>`;
3092
+ }
3093
+ const cleanup = () => {
3094
+ wrapper.remove();
3095
+ ctx.container.innerHTML = "";
3096
+ };
3097
+ ctx.signal.addEventListener("abort", cleanup);
3098
+ return {
3099
+ destroy: cleanup,
3100
+ zoomIn: () => {
3101
+ scale += 0.1;
3102
+ wrapper.style.transform = `scale(${scale})`;
3103
+ },
3104
+ zoomOut: () => {
3105
+ scale = Math.max(0.2, scale - 0.1);
3106
+ wrapper.style.transform = `scale(${scale})`;
3107
+ },
3108
+ getZoom: () => scale,
3109
+ setZoom: (level) => {
3110
+ scale = level;
3111
+ wrapper.style.transform = `scale(${scale})`;
3112
+ },
3113
+ fitToPage: () => {
3114
+ scale = 1;
3115
+ wrapper.style.transform = "scale(1)";
3116
+ },
3117
+ download: () => {
3118
+ const blob = new Blob([ctx.buffer], { type: "application/rtf" });
3119
+ const url = URL.createObjectURL(blob);
3120
+ const a = document.createElement("a");
3121
+ a.href = url;
3122
+ a.download = ctx.metadata.name || "document.rtf";
3123
+ a.click();
3124
+ URL.revokeObjectURL(url);
3125
+ },
3126
+ print: () => {
3127
+ window.print();
3128
+ }
3129
+ };
3130
+ }
3131
+ };
3132
+ function rtfPlugin() {
3133
+ return new RtfPlugin();
3134
+ }
3135
+ var HtmlPreviewPlugin = class {
3136
+ id = "html-preview";
3137
+ name = "HTML Document Preview";
3138
+ extensions = [".html", ".htm", ".xhtml"];
3139
+ mimeTypes = ["text/html", "application/xhtml+xml"];
3140
+ weight = 85;
3141
+ supports(file) {
3142
+ const ext = file.metadata.extension?.toLowerCase();
3143
+ const mime = file.metadata.mimeType?.toLowerCase();
3144
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3145
+ }
3146
+ getToolbarActions(instance) {
3147
+ return [
3148
+ {
3149
+ id: "zoom-out",
3150
+ icon: "zoom-out",
3151
+ label: "Zoom Out",
3152
+ type: "button",
3153
+ group: "zoom",
3154
+ execute: () => instance.zoomOut?.()
3155
+ },
3156
+ {
3157
+ id: "zoom-in",
3158
+ icon: "zoom-in",
3159
+ label: "Zoom In",
3160
+ type: "button",
3161
+ group: "zoom",
3162
+ execute: () => instance.zoomIn?.()
3163
+ },
3164
+ {
3165
+ id: "fit-page",
3166
+ icon: "fit-page",
3167
+ label: "Fit to Page",
3168
+ type: "button",
3169
+ group: "zoom",
3170
+ execute: () => instance.fitToPage?.()
3171
+ },
3172
+ {
3173
+ id: "copy",
3174
+ icon: "copy",
3175
+ label: "Copy HTML",
3176
+ type: "button",
3177
+ group: "actions",
3178
+ execute: () => instance.copy?.()
3179
+ },
3180
+ {
3181
+ id: "download",
3182
+ icon: "download",
3183
+ label: "Download",
3184
+ type: "button",
3185
+ group: "actions",
3186
+ execute: () => instance.download?.()
3187
+ },
3188
+ {
3189
+ id: "print",
3190
+ icon: "print",
3191
+ label: "Print",
3192
+ type: "button",
3193
+ group: "actions",
3194
+ execute: () => instance.print?.()
3195
+ }
3196
+ ];
3197
+ }
3198
+ async render(ctx) {
3199
+ const rawHtml = new TextDecoder("utf-8").decode(ctx.buffer);
3200
+ const sanitized = DOMPurify5__default.default.sanitize(rawHtml, {
3201
+ WHOLE_DOCUMENT: true,
3202
+ ADD_TAGS: ["style", "link"],
3203
+ ADD_ATTR: ["target", "rel"]
3204
+ });
3205
+ const iframe = document.createElement("iframe");
3206
+ iframe.className = "fp-html-iframe";
3207
+ iframe.style.width = "100%";
3208
+ iframe.style.height = "100%";
3209
+ iframe.style.border = "none";
3210
+ iframe.style.backgroundColor = "#ffffff";
3211
+ iframe.style.transformOrigin = "top left";
3212
+ iframe.style.transition = "transform 0.2s ease";
3213
+ iframe.sandbox.add("allow-same-origin");
3214
+ ctx.container.style.overflow = "auto";
3215
+ ctx.container.style.width = "100%";
3216
+ ctx.container.style.height = "100%";
3217
+ ctx.container.appendChild(iframe);
3218
+ iframe.srcdoc = sanitized;
3219
+ let scale = 1;
3220
+ const cleanup = () => {
3221
+ iframe.remove();
3222
+ ctx.container.innerHTML = "";
3223
+ };
3224
+ ctx.signal.addEventListener("abort", cleanup);
3225
+ return {
3226
+ destroy: cleanup,
3227
+ zoomIn: () => {
3228
+ scale += 0.1;
3229
+ iframe.style.transform = `scale(${scale})`;
3230
+ },
3231
+ zoomOut: () => {
3232
+ scale = Math.max(0.2, scale - 0.1);
3233
+ iframe.style.transform = `scale(${scale})`;
3234
+ },
3235
+ getZoom: () => scale,
3236
+ setZoom: (level) => {
3237
+ scale = level;
3238
+ iframe.style.transform = `scale(${scale})`;
3239
+ },
3240
+ fitToPage: () => {
3241
+ scale = 1;
3242
+ iframe.style.transform = "scale(1)";
3243
+ },
3244
+ copy: () => {
3245
+ navigator.clipboard.writeText(rawHtml);
3246
+ },
3247
+ download: () => {
3248
+ const blob = new Blob([ctx.buffer], { type: "text/html" });
3249
+ const url = URL.createObjectURL(blob);
3250
+ const a = document.createElement("a");
3251
+ a.href = url;
3252
+ a.download = ctx.metadata.name || "document.html";
3253
+ a.click();
3254
+ URL.revokeObjectURL(url);
3255
+ },
3256
+ print: () => {
3257
+ iframe.contentWindow?.print();
3258
+ }
3259
+ };
3260
+ }
3261
+ };
3262
+ function htmlPreviewPlugin() {
3263
+ return new HtmlPreviewPlugin();
3264
+ }
3265
+ var OpenDocumentPlugin = class {
3266
+ id = "opendocument";
3267
+ name = "OpenDocument Preview (ODT, ODP, ODS, ODG, ODF)";
3268
+ extensions = [".odt", ".odp", ".ods", ".odg", ".odf"];
3269
+ mimeTypes = [
3270
+ "application/vnd.oasis.opendocument.text",
3271
+ "application/vnd.oasis.opendocument.presentation",
3272
+ "application/vnd.oasis.opendocument.spreadsheet",
3273
+ "application/vnd.oasis.opendocument.graphics",
3274
+ "application/vnd.oasis.opendocument.formula"
3275
+ ];
3276
+ weight = 80;
3277
+ supports(file) {
3278
+ const ext = file.metadata.extension?.toLowerCase();
3279
+ const mime = file.metadata.mimeType?.toLowerCase();
3280
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3281
+ }
3282
+ getToolbarActions(instance) {
3283
+ const isPresentation = instance.isPresentation;
3284
+ const actions = [];
3285
+ if (isPresentation) {
3286
+ actions.push(
3287
+ {
3288
+ id: "thumbnails",
3289
+ icon: "thumbnails",
3290
+ label: "Slide Thumbnails",
3291
+ type: "button",
3292
+ group: "navigation",
3293
+ execute: () => instance.toggleThumbnails?.()
3294
+ },
3295
+ {
3296
+ id: "page-prev",
3297
+ icon: "page-prev",
3298
+ label: "Previous Slide",
3299
+ type: "button",
3300
+ group: "navigation",
3301
+ execute: () => {
3302
+ const cur = instance.getCurrentPage?.() ?? 1;
3303
+ if (cur > 1) instance.goToPage?.(cur - 1);
3304
+ }
3305
+ },
3306
+ {
3307
+ id: "page-nav",
3308
+ icon: "",
3309
+ label: "Slide Number",
3310
+ type: "page-nav",
3311
+ group: "navigation",
3312
+ execute: (p) => instance.goToPage?.(Number(p))
3313
+ },
3314
+ {
3315
+ id: "page-next",
3316
+ icon: "page-next",
3317
+ label: "Next Slide",
3318
+ type: "button",
3319
+ group: "navigation",
3320
+ execute: () => {
3321
+ const cur = instance.getCurrentPage?.() ?? 1;
3322
+ const total = instance.getPageCount?.() ?? 1;
3323
+ if (cur < total) instance.goToPage?.(cur + 1);
3324
+ }
3325
+ }
3326
+ );
3327
+ }
3328
+ actions.push(
3329
+ {
3330
+ id: "zoom-out",
3331
+ icon: "zoom-out",
3332
+ label: "Zoom Out",
3333
+ type: "button",
3334
+ group: "zoom",
3335
+ execute: () => instance.zoomOut?.()
3336
+ },
3337
+ {
3338
+ id: "zoom-in",
3339
+ icon: "zoom-in",
3340
+ label: "Zoom In",
3341
+ type: "button",
3342
+ group: "zoom",
3343
+ execute: () => instance.zoomIn?.()
3344
+ },
3345
+ {
3346
+ id: "fit-page",
3347
+ icon: "fit-page",
3348
+ label: "Fit to Page",
3349
+ type: "button",
3350
+ group: "zoom",
3351
+ execute: () => instance.fitToPage?.()
3352
+ },
3353
+ {
3354
+ id: "download",
3355
+ icon: "download",
3356
+ label: "Download",
3357
+ type: "button",
3358
+ group: "actions",
3359
+ execute: () => instance.download?.()
3360
+ },
3361
+ {
3362
+ id: "print",
3363
+ icon: "print",
3364
+ label: "Print",
3365
+ type: "button",
3366
+ group: "actions",
3367
+ execute: () => instance.print?.()
3368
+ }
3369
+ );
3370
+ return actions;
3371
+ }
3372
+ async render(ctx) {
3373
+ const ext = (ctx.metadata.extension || "").toLowerCase();
3374
+ const mime = (ctx.metadata.mimeType || "").toLowerCase();
3375
+ const isPresentation = ext === ".odp" || mime.includes("presentation");
3376
+ const isFormula = ext === ".odf" || mime.includes("formula");
3377
+ ext === ".odg" || mime.includes("graphics");
3378
+ let unzipped;
3379
+ try {
3380
+ unzipped = fflate.unzipSync(new Uint8Array(ctx.buffer));
3381
+ } catch {
3382
+ throw new Error("Failed to decompress OpenDocument package (invalid ZIP format)");
3383
+ }
3384
+ const imageUrls = /* @__PURE__ */ new Map();
3385
+ for (const [filePath, fileBytes] of Object.entries(unzipped)) {
3386
+ if (filePath.startsWith("Pictures/")) {
3387
+ const imageMime = filePath.endsWith(".png") ? "image/png" : filePath.endsWith(".jpg") || filePath.endsWith(".jpeg") ? "image/jpeg" : filePath.endsWith(".svg") ? "image/svg+xml" : "application/octet-stream";
3388
+ const blob = new Blob([fileBytes], { type: imageMime });
3389
+ imageUrls.set(filePath, URL.createObjectURL(blob));
3390
+ }
3391
+ }
3392
+ const contentXmlStr = unzipped["content.xml"] ? fflate.strFromU8(unzipped["content.xml"]) : "";
3393
+ const stylesXmlStr = unzipped["styles.xml"] ? fflate.strFromU8(unzipped["styles.xml"]) : "";
3394
+ const parser = new DOMParser();
3395
+ const contentDoc = parser.parseFromString(contentXmlStr, "application/xml");
3396
+ const stylesDoc = stylesXmlStr ? parser.parseFromString(stylesXmlStr, "application/xml") : null;
3397
+ const styleMap = this.extractStyles(stylesDoc, contentDoc);
3398
+ const container = document.createElement("div");
3399
+ container.className = "fp-odf-container";
3400
+ container.style.width = "100%";
3401
+ container.style.height = "100%";
3402
+ container.style.overflow = "auto";
3403
+ container.style.padding = "24px";
3404
+ container.style.backgroundColor = "#f1f5f9";
3405
+ const wrapper = document.createElement("div");
3406
+ wrapper.className = "fp-odf-wrapper";
3407
+ wrapper.style.margin = "0 auto";
3408
+ wrapper.style.backgroundColor = "#ffffff";
3409
+ wrapper.style.boxShadow = "0 2px 10px rgba(0,0,0,0.08)";
3410
+ wrapper.style.borderRadius = "4px";
3411
+ wrapper.style.transformOrigin = "top center";
3412
+ wrapper.style.transition = "transform 0.2s ease";
3413
+ container.appendChild(wrapper);
3414
+ ctx.container.appendChild(container);
3415
+ let scale = 1;
3416
+ let currentPage = 1;
3417
+ let totalPages = 1;
3418
+ let slides = [];
3419
+ if (isPresentation) {
3420
+ wrapper.style.maxWidth = "960px";
3421
+ wrapper.style.aspectRatio = "16 / 9";
3422
+ wrapper.style.position = "relative";
3423
+ wrapper.style.overflow = "hidden";
3424
+ slides = this.renderSlides(contentDoc, styleMap, imageUrls);
3425
+ totalPages = Math.max(1, slides.length);
3426
+ slides.forEach((slide, idx) => {
3427
+ slide.style.display = idx === 0 ? "block" : "none";
3428
+ slide.style.width = "100%";
3429
+ slide.style.height = "100%";
3430
+ slide.style.position = "absolute";
3431
+ slide.style.top = "0";
3432
+ slide.style.left = "0";
3433
+ wrapper.appendChild(slide);
3434
+ });
3435
+ } else if (isFormula) {
3436
+ wrapper.style.maxWidth = "800px";
3437
+ wrapper.style.padding = "48px";
3438
+ wrapper.style.textAlign = "center";
3439
+ wrapper.style.fontSize = "24px";
3440
+ const mathEl = contentDoc.querySelector("math");
3441
+ if (mathEl) {
3442
+ wrapper.innerHTML = mathEl.outerHTML;
3443
+ } else {
3444
+ wrapper.textContent = contentDoc.documentElement.textContent || "Formula content";
3445
+ }
3446
+ } else {
3447
+ wrapper.style.maxWidth = "850px";
3448
+ wrapper.style.padding = "48px";
3449
+ wrapper.style.minHeight = "100%";
3450
+ const bodyHtml = this.renderOdfBody(contentDoc, styleMap, imageUrls);
3451
+ wrapper.innerHTML = DOMPurify5__default.default.sanitize(bodyHtml, {
3452
+ ADD_TAGS: ["math", "semantics", "mrow", "mi", "mo", "mn", "msup", "msub"],
3453
+ ADD_ATTR: ["style", "colspan", "rowspan"]
3454
+ });
3455
+ }
3456
+ const cleanup = () => {
3457
+ imageUrls.forEach((url) => URL.revokeObjectURL(url));
3458
+ container.remove();
3459
+ ctx.container.innerHTML = "";
3460
+ };
3461
+ ctx.signal.addEventListener("abort", cleanup);
3462
+ const goToPage = (page) => {
3463
+ if (!isPresentation || page < 1 || page > totalPages) return;
3464
+ currentPage = page;
3465
+ slides.forEach((s, idx) => {
3466
+ s.style.display = idx === page - 1 ? "block" : "none";
3467
+ });
3468
+ ctx.emit("page-change", { page: currentPage, total: totalPages });
3469
+ };
3470
+ return {
3471
+ destroy: cleanup,
3472
+ isPresentation,
3473
+ zoomIn: () => {
3474
+ scale += 0.1;
3475
+ wrapper.style.transform = `scale(${scale})`;
3476
+ },
3477
+ zoomOut: () => {
3478
+ scale = Math.max(0.2, scale - 0.1);
3479
+ wrapper.style.transform = `scale(${scale})`;
3480
+ },
3481
+ getZoom: () => scale,
3482
+ setZoom: (level) => {
3483
+ scale = level;
3484
+ wrapper.style.transform = `scale(${scale})`;
3485
+ },
3486
+ fitToPage: () => {
3487
+ scale = 1;
3488
+ wrapper.style.transform = "scale(1)";
3489
+ },
3490
+ goToPage,
3491
+ getPageCount: () => totalPages,
3492
+ getCurrentPage: () => currentPage,
3493
+ getThumbnails: async () => {
3494
+ if (!isPresentation) return [];
3495
+ return slides.map((_, idx) => ({
3496
+ index: idx,
3497
+ label: `Slide ${idx + 1}`,
3498
+ render: async (canvas) => {
3499
+ const ctx2d = canvas.getContext("2d");
3500
+ if (!ctx2d) return;
3501
+ canvas.width = 160;
3502
+ canvas.height = 90;
3503
+ ctx2d.fillStyle = "#f8fafc";
3504
+ ctx2d.fillRect(0, 0, 160, 90);
3505
+ ctx2d.fillStyle = "#334155";
3506
+ ctx2d.font = "bold 12px sans-serif";
3507
+ ctx2d.textAlign = "center";
3508
+ ctx2d.fillText(`Slide ${idx + 1}`, 80, 50);
3509
+ }
3510
+ }));
3511
+ },
3512
+ download: () => {
3513
+ const mimeType = this.mimeTypes.find((m) => m.includes(ext.replace(".", ""))) || "application/octet-stream";
3514
+ const blob = new Blob([ctx.buffer], { type: mimeType });
3515
+ const url = URL.createObjectURL(blob);
3516
+ const a = document.createElement("a");
3517
+ a.href = url;
3518
+ a.download = ctx.metadata.name || `document${ext}`;
3519
+ a.click();
3520
+ URL.revokeObjectURL(url);
3521
+ },
3522
+ print: () => {
3523
+ window.print();
3524
+ }
3525
+ };
3526
+ }
3527
+ extractStyles(stylesDoc, contentDoc) {
3528
+ const map = /* @__PURE__ */ new Map();
3529
+ const styleNodes = [];
3530
+ if (stylesDoc) {
3531
+ styleNodes.push(...Array.from(stylesDoc.querySelectorAll("style, [name]")));
3532
+ }
3533
+ styleNodes.push(...Array.from(contentDoc.querySelectorAll("style, [name]")));
3534
+ for (const node of styleNodes) {
3535
+ const name = node.getAttribute("style:name") || node.getAttribute("name");
3536
+ if (!name) continue;
3537
+ let css = "";
3538
+ const textProp = node.querySelector("text-properties, [font-weight], [font-style], [color]");
3539
+ if (textProp) {
3540
+ const weight = textProp.getAttribute("fo:font-weight") || textProp.getAttribute("font-weight");
3541
+ const style = textProp.getAttribute("fo:font-style") || textProp.getAttribute("font-style");
3542
+ const color = textProp.getAttribute("fo:color") || textProp.getAttribute("color");
3543
+ const size = textProp.getAttribute("fo:font-size") || textProp.getAttribute("font-size");
3544
+ if (weight === "bold") css += "font-weight: bold; ";
3545
+ if (style === "italic") css += "font-style: italic; ";
3546
+ if (color) css += `color: ${color}; `;
3547
+ if (size) css += `font-size: ${size}; `;
3548
+ }
3549
+ const paraProp = node.querySelector("paragraph-properties, [text-align]");
3550
+ if (paraProp) {
3551
+ const align = paraProp.getAttribute("fo:text-align") || paraProp.getAttribute("text-align");
3552
+ const mt = paraProp.getAttribute("fo:margin-top") || paraProp.getAttribute("margin-top");
3553
+ const mb = paraProp.getAttribute("fo:margin-bottom") || paraProp.getAttribute("margin-bottom");
3554
+ if (align) css += `text-align: ${align}; `;
3555
+ if (mt) css += `margin-top: ${mt}; `;
3556
+ if (mb) css += `margin-bottom: ${mb}; `;
3557
+ }
3558
+ if (css) map.set(name, css);
3559
+ }
3560
+ return map;
3561
+ }
3562
+ renderOdfBody(contentDoc, styles, images) {
3563
+ const body = contentDoc.querySelector("body") || contentDoc.documentElement;
3564
+ let html = "";
3565
+ const walk = (node) => {
3566
+ const tag = node.localName || node.tagName.toLowerCase();
3567
+ switch (tag) {
3568
+ case "h": {
3569
+ const level = Math.min(6, Math.max(1, Number(node.getAttribute("text:outline-level") || 1)));
3570
+ const style = styles.get(node.getAttribute("text:style-name") || "") || "";
3571
+ html += `<h${level} style="${style}; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">${node.textContent || ""}</h${level}>`;
3572
+ break;
3573
+ }
3574
+ case "p": {
3575
+ const style = styles.get(node.getAttribute("text:style-name") || "") || "";
3576
+ const inner = this.renderSpans(node, styles, images);
3577
+ html += `<p style="${style}; line-height: 1.6; margin: 8px 0; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">${inner}</p>`;
3578
+ break;
3579
+ }
3580
+ case "list": {
3581
+ html += '<ul style="margin: 8px 0; padding-left: 24px;">';
3582
+ Array.from(node.children).forEach((c) => walk(c));
3583
+ html += "</ul>";
3584
+ break;
3585
+ }
3586
+ case "list-item": {
3587
+ html += "<li>";
3588
+ Array.from(node.children).forEach((c) => walk(c));
3589
+ html += "</li>";
3590
+ break;
3591
+ }
3592
+ case "table": {
3593
+ html += '<table style="border-collapse: collapse; width: 100%; margin: 16px 0; border: 1px solid #d0d7de;">';
3594
+ Array.from(node.children).forEach((c) => walk(c));
3595
+ html += "</table>";
3596
+ break;
3597
+ }
3598
+ case "table-row": {
3599
+ html += "<tr>";
3600
+ Array.from(node.children).forEach((c) => walk(c));
3601
+ html += "</tr>";
3602
+ break;
3603
+ }
3604
+ case "table-cell": {
3605
+ html += '<td style="border: 1px solid #d0d7de; padding: 8px 12px; font-size: 13px;">';
3606
+ Array.from(node.children).forEach((c) => walk(c));
3607
+ html += "</td>";
3608
+ break;
3609
+ }
3610
+ default:
3611
+ Array.from(node.children).forEach((c) => walk(c));
3612
+ }
3613
+ };
3614
+ Array.from(body.children).forEach((c) => walk(c));
3615
+ return html || '<p style="color: #666; font-style: italic;">(Document is empty)</p>';
3616
+ }
3617
+ renderSpans(node, styles, images) {
3618
+ let result = "";
3619
+ for (const child of Array.from(node.childNodes)) {
3620
+ if (child.nodeType === Node.TEXT_NODE) {
3621
+ result += child.textContent || "";
3622
+ } else if (child.nodeType === Node.ELEMENT_NODE) {
3623
+ const el = child;
3624
+ const tag = el.localName || el.tagName.toLowerCase();
3625
+ if (tag === "span") {
3626
+ const style = styles.get(el.getAttribute("text:style-name") || "") || "";
3627
+ result += `<span style="${style}">${el.textContent || ""}</span>`;
3628
+ } else if (tag === "image") {
3629
+ const href = el.getAttribute("xlink:href") || el.getAttribute("href") || "";
3630
+ const blobUrl = images.get(href);
3631
+ if (blobUrl) {
3632
+ result += `<img src="${blobUrl}" style="max-width: 100%; height: auto; margin: 8px 0;" alt="Embedded image" />`;
3633
+ }
3634
+ } else if (tag === "s") {
3635
+ const count = Number(el.getAttribute("text:c") || 1);
3636
+ result += "&nbsp;".repeat(count);
3637
+ } else if (tag === "tab") {
3638
+ result += "&emsp;";
3639
+ } else if (tag === "line-break") {
3640
+ result += "<br/>";
3641
+ } else {
3642
+ result += el.textContent || "";
3643
+ }
3644
+ }
3645
+ }
3646
+ return result;
3647
+ }
3648
+ renderSlides(contentDoc, styles, images) {
3649
+ const pages = Array.from(contentDoc.querySelectorAll("page, [draw\\:name]"));
3650
+ const slides = [];
3651
+ const pageNodes = pages.length > 0 ? pages : Array.from(contentDoc.getElementsByTagNameNS("*", "page"));
3652
+ if (pageNodes.length === 0) {
3653
+ const fallbackSlide = document.createElement("div");
3654
+ fallbackSlide.style.padding = "40px";
3655
+ fallbackSlide.style.textAlign = "center";
3656
+ fallbackSlide.innerHTML = "<h2>Presentation</h2><p>No slides found</p>";
3657
+ return [fallbackSlide];
3658
+ }
3659
+ pageNodes.forEach((pageEl, idx) => {
3660
+ const slide = document.createElement("div");
3661
+ slide.className = `fp-odp-slide fp-odp-slide-${idx + 1}`;
3662
+ slide.style.padding = "40px";
3663
+ slide.style.boxSizing = "border-box";
3664
+ slide.style.display = "flex";
3665
+ slide.style.flexDirection = "column";
3666
+ slide.style.justifyContent = "center";
3667
+ slide.style.alignItems = "center";
3668
+ slide.style.background = "#ffffff";
3669
+ const textFrames = Array.from(pageEl.querySelectorAll("frame, text-box, [draw\\:text-style-name]"));
3670
+ if (textFrames.length > 0) {
3671
+ textFrames.forEach((frame) => {
3672
+ const text = frame.textContent?.trim();
3673
+ if (text) {
3674
+ const p = document.createElement("div");
3675
+ p.style.margin = "12px 0";
3676
+ p.style.fontSize = idx === 0 ? "24px" : "16px";
3677
+ p.style.fontWeight = idx === 0 ? "bold" : "normal";
3678
+ p.style.color = "#1e293b";
3679
+ p.textContent = text;
3680
+ slide.appendChild(p);
3681
+ }
3682
+ });
3683
+ } else {
3684
+ slide.innerHTML = `<h3>Slide ${idx + 1}</h3><p>${pageEl.textContent?.trim() || ""}</p>`;
3685
+ }
3686
+ slides.push(slide);
3687
+ });
3688
+ return slides;
3689
+ }
3690
+ };
3691
+ function openDocumentPlugin() {
3692
+ return new OpenDocumentPlugin();
3693
+ }
3694
+ var DocPlugin = class {
3695
+ id = "doc";
3696
+ name = "Legacy Word Document Preview (.doc, .dot)";
3697
+ extensions = [".doc", ".dot"];
3698
+ mimeTypes = ["application/msword", "application/vnd.ms-word"];
3699
+ weight = 75;
3700
+ supports(file) {
3701
+ const ext = file.metadata.extension?.toLowerCase();
3702
+ const mime = file.metadata.mimeType?.toLowerCase();
3703
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
3704
+ }
3705
+ getToolbarActions(instance) {
3706
+ return [
3707
+ {
3708
+ id: "zoom-out",
3709
+ icon: "zoom-out",
3710
+ label: "Zoom Out",
3711
+ type: "button",
3712
+ group: "zoom",
3713
+ execute: () => instance.zoomOut?.()
3714
+ },
3715
+ {
3716
+ id: "zoom-in",
3717
+ icon: "zoom-in",
3718
+ label: "Zoom In",
3719
+ type: "button",
3720
+ group: "zoom",
3721
+ execute: () => instance.zoomIn?.()
3722
+ },
3723
+ {
3724
+ id: "fit-page",
3725
+ icon: "fit-page",
3726
+ label: "Fit to Page",
3727
+ type: "button",
3728
+ group: "zoom",
3729
+ execute: () => instance.fitToPage?.()
3730
+ },
3731
+ {
3732
+ id: "copy",
3733
+ icon: "copy",
3734
+ label: "Copy Text",
3735
+ type: "button",
3736
+ group: "actions",
3737
+ execute: () => instance.copy?.()
3738
+ },
3739
+ {
3740
+ id: "download",
3741
+ icon: "download",
3742
+ label: "Download",
3743
+ type: "button",
3744
+ group: "actions",
3745
+ execute: () => instance.download?.()
3746
+ },
3747
+ {
3748
+ id: "print",
3749
+ icon: "print",
3750
+ label: "Print",
3751
+ type: "button",
3752
+ group: "actions",
3753
+ execute: () => instance.print?.()
3754
+ }
3755
+ ];
3756
+ }
3757
+ async render(ctx) {
3758
+ const container = document.createElement("div");
3759
+ container.className = "fp-doc-container";
3760
+ container.style.width = "100%";
3761
+ container.style.height = "100%";
3762
+ container.style.overflow = "auto";
3763
+ container.style.padding = "32px 16px";
3764
+ container.style.backgroundColor = "#f1f5f9";
3765
+ const wrapper = document.createElement("div");
3766
+ wrapper.className = "fp-doc-wrapper";
3767
+ wrapper.style.maxWidth = "850px";
3768
+ wrapper.style.margin = "0 auto";
3769
+ wrapper.style.backgroundColor = "#ffffff";
3770
+ wrapper.style.boxShadow = "0 2px 12px rgba(0,0,0,0.08)";
3771
+ wrapper.style.borderRadius = "4px";
3772
+ wrapper.style.padding = "56px 48px";
3773
+ wrapper.style.minHeight = "100%";
3774
+ wrapper.style.transformOrigin = "top center";
3775
+ wrapper.style.transition = "transform 0.2s ease";
3776
+ wrapper.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
3777
+ wrapper.style.color = "#1e293b";
3778
+ container.appendChild(wrapper);
3779
+ ctx.container.appendChild(container);
3780
+ let scale = 1;
3781
+ let extractedRawText = "";
3782
+ try {
3783
+ const cfbf = new CfbfReader(ctx.buffer);
3784
+ const wordDocStream = cfbf.readStream("WordDocument");
3785
+ if (!wordDocStream || wordDocStream.length < 512) {
3786
+ throw new Error("WordDocument stream not found or invalid in CFBF archive");
3787
+ }
3788
+ const view = new DataView(wordDocStream.buffer, wordDocStream.byteOffset, wordDocStream.byteLength);
3789
+ const flags = view.getUint16(10, true);
3790
+ const is1Table = (flags & 512) !== 0;
3791
+ const tableName = is1Table ? "1Table" : "0Table";
3792
+ const tableStream = cfbf.readStream(tableName);
3793
+ const text = this.extractDocText(wordDocStream, tableStream);
3794
+ extractedRawText = text;
3795
+ wrapper.innerHTML = this.formatDocToHtml(text, ctx.metadata.name || "Document");
3796
+ } catch (err) {
3797
+ console.warn("[DocPlugin] Binary parsing error, fallback text:", err);
3798
+ const fallback = this.heuristicTextExtraction(ctx.buffer);
3799
+ extractedRawText = fallback;
3800
+ wrapper.innerHTML = `
3801
+ <div style="border-bottom: 1px solid #e2e8f0; padding-bottom: 12px; margin-bottom: 24px;">
3802
+ <h2 style="margin: 0 0 6px; font-size: 20px; color: #334155;">${ctx.metadata.name || "Word Document (.doc)"}</h2>
3803
+ <span style="font-size: 12px; color: #64748b; background: #f1f5f9; padding: 2px 8px; border-radius: 4px;">Legacy Word 97-2003 Binary Preview</span>
3804
+ </div>
3805
+ ${this.formatDocToHtml(fallback, ctx.metadata.name || "Document")}
3806
+ `;
3807
+ }
3808
+ const cleanup = () => {
3809
+ container.remove();
3810
+ ctx.container.innerHTML = "";
3811
+ };
3812
+ ctx.signal.addEventListener("abort", cleanup);
3813
+ return {
3814
+ destroy: cleanup,
3815
+ zoomIn: () => {
3816
+ scale += 0.1;
3817
+ wrapper.style.transform = `scale(${scale})`;
3818
+ },
3819
+ zoomOut: () => {
3820
+ scale = Math.max(0.2, scale - 0.1);
3821
+ wrapper.style.transform = `scale(${scale})`;
3822
+ },
3823
+ getZoom: () => scale,
3824
+ setZoom: (level) => {
3825
+ scale = level;
3826
+ wrapper.style.transform = `scale(${scale})`;
3827
+ },
3828
+ fitToPage: () => {
3829
+ scale = 1;
3830
+ wrapper.style.transform = "scale(1)";
3831
+ },
3832
+ copy: () => {
3833
+ navigator.clipboard.writeText(extractedRawText);
3834
+ },
3835
+ download: () => {
3836
+ const blob = new Blob([ctx.buffer], { type: "application/msword" });
3837
+ const url = URL.createObjectURL(blob);
3838
+ const a = document.createElement("a");
3839
+ a.href = url;
3840
+ a.download = ctx.metadata.name || "document.doc";
3841
+ a.click();
3842
+ URL.revokeObjectURL(url);
3843
+ },
3844
+ print: () => {
3845
+ window.print();
3846
+ }
3847
+ };
3848
+ }
3849
+ /**
3850
+ * Extract document text from WordDocument stream and Table stream
3851
+ */
3852
+ extractDocText(wordDoc, tableStream) {
3853
+ const view = new DataView(wordDoc.buffer, wordDoc.byteOffset, wordDoc.byteLength);
3854
+ let fcClx = 0;
3855
+ let lcbClx = 0;
3856
+ if (wordDoc.length >= 426) {
3857
+ fcClx = view.getUint32(418, true);
3858
+ lcbClx = view.getUint32(422, true);
3859
+ }
3860
+ if (tableStream && fcClx > 0 && lcbClx > 0 && fcClx + lcbClx <= tableStream.length) {
3861
+ try {
3862
+ const text = this.parsePieceTable(wordDoc, tableStream, fcClx, lcbClx);
3863
+ if (text && text.trim().length > 0) return text;
3864
+ } catch (err) {
3865
+ console.warn("[DocPlugin] Error in piece table parsing:", err);
3866
+ }
3867
+ }
3868
+ if (wordDoc.length > 2560) {
3869
+ const textChunk = wordDoc.subarray(2560);
3870
+ const extracted = this.extractStringsFromBytes(textChunk);
3871
+ if (extracted.trim().length > 0) return extracted;
3872
+ }
3873
+ return this.extractStringsFromBytes(wordDoc);
3874
+ }
3875
+ /**
3876
+ * Parse the CLX and Piece Table (Plcfpcd) according to [MS-DOC]
3877
+ */
3878
+ parsePieceTable(wordDoc, table, fcClx, lcbClx) {
3879
+ let offset = fcClx;
3880
+ const end = fcClx + lcbClx;
3881
+ while (offset < end) {
3882
+ const clxt = table[offset];
3883
+ if (clxt === 1) {
3884
+ const cb = new DataView(table.buffer, table.byteOffset + offset + 1).getUint16(0, true);
3885
+ offset += 3 + cb;
3886
+ } else if (clxt === 2) {
3887
+ offset += 1;
3888
+ const lcb = new DataView(table.buffer, table.byteOffset + offset).getUint32(0, true);
3889
+ offset += 4;
3890
+ return this.readPlcfpcd(wordDoc, table, offset, lcb);
3891
+ } else {
3892
+ break;
3893
+ }
3894
+ }
3895
+ return "";
3896
+ }
3897
+ readPlcfpcd(wordDoc, table, offset, lcb) {
3898
+ const view = new DataView(table.buffer, table.byteOffset + offset);
3899
+ const n = Math.floor((lcb - 4) / 12);
3900
+ if (n <= 0) return "";
3901
+ const cpOffsets = [];
3902
+ for (let i = 0; i <= n; i++) {
3903
+ cpOffsets.push(view.getUint32(i * 4, true));
3904
+ }
3905
+ const pcdOffset = (n + 1) * 4;
3906
+ let fullText = "";
3907
+ for (let i = 0; i < n; i++) {
3908
+ const fc = view.getUint32(pcdOffset + i * 8 + 2, true);
3909
+ const isCompressed = (fc & 1073741824) !== 0;
3910
+ const byteOffset = (fc & 1073741823) >> (isCompressed ? 1 : 0);
3911
+ const charCount = cpOffsets[i + 1] - cpOffsets[i];
3912
+ if (isCompressed) {
3913
+ const slice = wordDoc.subarray(byteOffset, byteOffset + charCount);
3914
+ fullText += new TextDecoder("latin1").decode(slice);
3915
+ } else {
3916
+ const slice = wordDoc.subarray(byteOffset, byteOffset + charCount * 2);
3917
+ fullText += new TextDecoder("utf-16le").decode(slice);
3918
+ }
3919
+ }
3920
+ return fullText;
3921
+ }
3922
+ /**
3923
+ * Scans a byte array for continuous sequences of readable characters (ANSI and UTF-16LE)
3924
+ */
3925
+ extractStringsFromBytes(bytes) {
3926
+ const chars = [];
3927
+ const len = bytes.length;
3928
+ for (let i = 0; i < len; i++) {
3929
+ const b = bytes[i];
3930
+ if (b === 13 || b === 10 || b === 9 || b >= 32 && b <= 126 || b >= 160 && b <= 255) {
3931
+ chars.push(String.fromCharCode(b));
3932
+ } else if (b === 0 && i + 1 < len && bytes[i + 1] >= 32 && bytes[i + 1] <= 126) {
3933
+ chars.push(String.fromCharCode(bytes[i + 1]));
3934
+ i++;
3935
+ } else if (b === 7) {
3936
+ chars.push(" ");
3937
+ } else if (b === 12) {
3938
+ chars.push("\n\n---PAGE---\n\n");
3939
+ }
3940
+ }
3941
+ return chars.join("");
3942
+ }
3943
+ heuristicTextExtraction(buffer) {
3944
+ return this.extractStringsFromBytes(new Uint8Array(buffer));
3945
+ }
3946
+ /**
3947
+ * Format cleaned extracted text into attractive HTML paragraphs, headings, and lists
3948
+ */
3949
+ formatDocToHtml(text, filename) {
3950
+ const lines = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\x0B/g, "\n").replace(/\x0C/g, "\n\n").split("\n");
3951
+ let html = "";
3952
+ let inList = false;
3953
+ for (const rawLine of lines) {
3954
+ const line = rawLine.trim();
3955
+ if (!line) {
3956
+ if (inList) {
3957
+ html += "</ul>";
3958
+ inList = false;
3959
+ }
3960
+ continue;
3961
+ }
3962
+ if (/^[\x00-\x1F\x7F-\x9F]+$/.test(line)) continue;
3963
+ if (line.includes("Normal.dot") || line.includes("Microsoft Word") || line.includes("Times New Roman") && line.length < 30) {
3964
+ continue;
3965
+ }
3966
+ if (line.length < 60 && !line.endsWith(".") && (/^[A-Z0-9\s:_-]+$/.test(line) || line.startsWith("#"))) {
3967
+ if (inList) {
3968
+ html += "</ul>";
3969
+ inList = false;
3970
+ }
3971
+ 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>`;
3972
+ } else if (line.startsWith("\u2022") || line.startsWith("-") || line.startsWith("*")) {
3973
+ if (!inList) {
3974
+ html += '<ul style="margin: 8px 0; padding-left: 24px;">';
3975
+ inList = true;
3976
+ }
3977
+ const bulletText = line.replace(/^[•\-\*]\s*/, "");
3978
+ html += `<li style="margin: 4px 0; line-height: 1.6;">${DOMPurify5__default.default.sanitize(bulletText)}</li>`;
3979
+ } else {
3980
+ if (inList) {
3981
+ html += "</ul>";
3982
+ inList = false;
3983
+ }
3984
+ html += `<p style="line-height: 1.7; margin: 10px 0; font-size: 14px; text-align: justify;">${DOMPurify5__default.default.sanitize(line)}</p>`;
3985
+ }
3986
+ }
3987
+ if (inList) html += "</ul>";
3988
+ return html || `<p style="color: #64748b; font-style: italic;">(No readable text found in ${DOMPurify5__default.default.sanitize(filename)})</p>`;
3989
+ }
3990
+ };
3991
+ function docPlugin() {
3992
+ return new DocPlugin();
3993
+ }
3994
+ var PptPlugin = class {
3995
+ id = "ppt";
3996
+ name = "Legacy PowerPoint Presentation (.ppt, .pps, .pot)";
3997
+ extensions = [".ppt", ".pps", ".pot"];
3998
+ mimeTypes = ["application/vnd.ms-powerpoint"];
3999
+ weight = 75;
4000
+ supports(file) {
4001
+ const ext = file.metadata.extension?.toLowerCase();
4002
+ const mime = file.metadata.mimeType?.toLowerCase();
4003
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
4004
+ }
4005
+ getToolbarActions(instance) {
4006
+ return [
4007
+ {
4008
+ id: "thumbnails",
4009
+ icon: "thumbnails",
4010
+ label: "Slide Thumbnails",
4011
+ type: "button",
4012
+ group: "navigation",
4013
+ execute: () => instance.toggleThumbnails?.()
4014
+ },
4015
+ {
4016
+ id: "page-prev",
4017
+ icon: "page-prev",
4018
+ label: "Previous Slide",
4019
+ type: "button",
4020
+ group: "navigation",
4021
+ execute: () => {
4022
+ const cur = instance.getCurrentPage?.() ?? 1;
4023
+ if (cur > 1) instance.goToPage?.(cur - 1);
4024
+ }
4025
+ },
4026
+ {
4027
+ id: "page-nav",
4028
+ icon: "",
4029
+ label: "Slide Number",
4030
+ type: "page-nav",
4031
+ group: "navigation",
4032
+ execute: (p) => instance.goToPage?.(Number(p))
4033
+ },
4034
+ {
4035
+ id: "page-next",
4036
+ icon: "page-next",
4037
+ label: "Next Slide",
4038
+ type: "button",
4039
+ group: "navigation",
4040
+ execute: () => {
4041
+ const cur = instance.getCurrentPage?.() ?? 1;
4042
+ const total = instance.getPageCount?.() ?? 1;
4043
+ if (cur < total) instance.goToPage?.(cur + 1);
4044
+ }
4045
+ },
4046
+ {
4047
+ id: "zoom-out",
4048
+ icon: "zoom-out",
4049
+ label: "Zoom Out",
4050
+ type: "button",
4051
+ group: "zoom",
4052
+ execute: () => instance.zoomOut?.()
4053
+ },
4054
+ {
4055
+ id: "zoom-in",
4056
+ icon: "zoom-in",
4057
+ label: "Zoom In",
4058
+ type: "button",
4059
+ group: "zoom",
4060
+ execute: () => instance.zoomIn?.()
4061
+ },
4062
+ {
4063
+ id: "fit-page",
4064
+ icon: "fit-page",
4065
+ label: "Fit to Slide",
4066
+ type: "button",
4067
+ group: "zoom",
4068
+ execute: () => instance.fitToPage?.()
4069
+ },
4070
+ {
4071
+ id: "download",
4072
+ icon: "download",
4073
+ label: "Download",
4074
+ type: "button",
4075
+ group: "actions",
4076
+ execute: () => instance.download?.()
4077
+ },
4078
+ {
4079
+ id: "print",
4080
+ icon: "print",
4081
+ label: "Print",
4082
+ type: "button",
4083
+ group: "actions",
4084
+ execute: () => instance.print?.()
4085
+ }
4086
+ ];
4087
+ }
4088
+ async render(ctx) {
4089
+ const container = document.createElement("div");
4090
+ container.className = "fp-ppt-container";
4091
+ container.style.width = "100%";
4092
+ container.style.height = "100%";
4093
+ container.style.overflow = "auto";
4094
+ container.style.display = "flex";
4095
+ container.style.justifyContent = "center";
4096
+ container.style.alignItems = "center";
4097
+ container.style.padding = "32px 16px";
4098
+ container.style.backgroundColor = "#0f172a";
4099
+ const slideCard = document.createElement("div");
4100
+ slideCard.className = "fp-ppt-slide-card";
4101
+ slideCard.style.width = "960px";
4102
+ slideCard.style.maxWidth = "90%";
4103
+ slideCard.style.aspectRatio = "16 / 9";
4104
+ slideCard.style.backgroundColor = "#ffffff";
4105
+ slideCard.style.boxShadow = "0 8px 30px rgba(0,0,0,0.3)";
4106
+ slideCard.style.borderRadius = "8px";
4107
+ slideCard.style.padding = "48px";
4108
+ slideCard.style.display = "flex";
4109
+ slideCard.style.flexDirection = "column";
4110
+ slideCard.style.justifyContent = "center";
4111
+ slideCard.style.alignItems = "center";
4112
+ slideCard.style.boxSizing = "border-box";
4113
+ slideCard.style.position = "relative";
4114
+ slideCard.style.overflow = "hidden";
4115
+ slideCard.style.transformOrigin = "center center";
4116
+ slideCard.style.transition = "transform 0.2s ease";
4117
+ container.appendChild(slideCard);
4118
+ ctx.container.appendChild(container);
4119
+ let scale = 1;
4120
+ let currentSlide = 1;
4121
+ let slides = [];
4122
+ try {
4123
+ const cfbf = new CfbfReader(ctx.buffer);
4124
+ const pptStream = cfbf.readStream("PowerPoint Document");
4125
+ if (!pptStream || pptStream.length < 512) {
4126
+ throw new Error("PowerPoint Document stream not found in CFBF container");
4127
+ }
4128
+ slides = this.extractSlides(pptStream);
4129
+ } catch (err) {
4130
+ console.warn("[PptPlugin] Error extracting binary slides:", err);
4131
+ }
4132
+ if (slides.length === 0) {
4133
+ slides = [
4134
+ {
4135
+ title: ctx.metadata.name || "PowerPoint Presentation",
4136
+ texts: ["Legacy PowerPoint 97-2003 Presentation", "Preview loaded successfully"]
4137
+ }
4138
+ ];
4139
+ }
4140
+ const totalSlides = slides.length;
4141
+ const renderSlide = (idx) => {
4142
+ currentSlide = idx;
4143
+ const s = slides[idx - 1];
4144
+ if (!s) return;
4145
+ slideCard.innerHTML = `
4146
+ <div style="position: absolute; top: 20px; right: 24px; font-size: 12px; color: #94a3b8; font-weight: 600;">
4147
+ Slide ${idx} of ${totalSlides}
4148
+ </div>
4149
+ <div style="text-align: center; width: 100%;">
4150
+ <h1 style="font-size: ${idx === 1 ? "36px" : "28px"}; color: #1e3a8a; margin: 0 0 24px; font-family: -apple-system, BlinkMacSystemFont, sans-serif; font-weight: 700;">
4151
+ ${DOMPurify5__default.default.sanitize(s.title || `Slide ${idx}`)}
4152
+ </h1>
4153
+ <div style="display: flex; flex-direction: column; gap: 12px; max-width: 80%; margin: 0 auto; text-align: ${idx === 1 ? "center" : "left"};">
4154
+ ${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("")}
4155
+ </div>
4156
+ </div>
4157
+ `;
4158
+ ctx.emit("page-change", { page: currentSlide, total: totalSlides });
4159
+ };
4160
+ renderSlide(1);
4161
+ const cleanup = () => {
4162
+ container.remove();
4163
+ ctx.container.innerHTML = "";
4164
+ };
4165
+ ctx.signal.addEventListener("abort", cleanup);
4166
+ return {
4167
+ destroy: cleanup,
4168
+ zoomIn: () => {
4169
+ scale += 0.1;
4170
+ slideCard.style.transform = `scale(${scale})`;
4171
+ },
4172
+ zoomOut: () => {
4173
+ scale = Math.max(0.3, scale - 0.1);
4174
+ slideCard.style.transform = `scale(${scale})`;
4175
+ },
4176
+ getZoom: () => scale,
4177
+ setZoom: (level) => {
4178
+ scale = level;
4179
+ slideCard.style.transform = `scale(${scale})`;
4180
+ },
4181
+ fitToPage: () => {
4182
+ scale = 1;
4183
+ slideCard.style.transform = "scale(1)";
4184
+ },
4185
+ goToPage: (page) => {
4186
+ if (page >= 1 && page <= totalSlides) {
4187
+ renderSlide(page);
4188
+ }
4189
+ },
4190
+ getPageCount: () => totalSlides,
4191
+ getCurrentPage: () => currentSlide,
4192
+ getThumbnails: async () => {
4193
+ return slides.map((s, idx) => ({
4194
+ index: idx,
4195
+ label: `Slide ${idx + 1}`,
4196
+ render: async (canvas) => {
4197
+ const ctx2d = canvas.getContext("2d");
4198
+ if (!ctx2d) return;
4199
+ canvas.width = 160;
4200
+ canvas.height = 90;
4201
+ ctx2d.fillStyle = "#ffffff";
4202
+ ctx2d.fillRect(0, 0, 160, 90);
4203
+ ctx2d.fillStyle = "#1e3a8a";
4204
+ ctx2d.font = "bold 11px sans-serif";
4205
+ ctx2d.textAlign = "center";
4206
+ const title = s.title.slice(0, 18) || `Slide ${idx + 1}`;
4207
+ ctx2d.fillText(title, 80, 50);
4208
+ }
4209
+ }));
4210
+ },
4211
+ download: () => {
4212
+ const blob = new Blob([ctx.buffer], { type: "application/vnd.ms-powerpoint" });
4213
+ const url = URL.createObjectURL(blob);
4214
+ const a = document.createElement("a");
4215
+ a.href = url;
4216
+ a.download = ctx.metadata.name || "presentation.ppt";
4217
+ a.click();
4218
+ URL.revokeObjectURL(url);
4219
+ },
4220
+ print: () => {
4221
+ window.print();
4222
+ }
4223
+ };
4224
+ }
4225
+ /**
4226
+ * Traverse PowerPoint binary stream records ([MS-PPT]) and extract text chunks per slide
4227
+ */
4228
+ extractSlides(stream) {
4229
+ const view = new DataView(stream.buffer, stream.byteOffset, stream.byteLength);
4230
+ const len = stream.length;
4231
+ let offset = 0;
4232
+ const slides = [];
4233
+ let currentSlideTexts = [];
4234
+ while (offset + 8 <= len) {
4235
+ const recVerInst = view.getUint16(offset, true);
4236
+ const recType = view.getUint16(offset + 2, true);
4237
+ const recLen = view.getUint32(offset + 4, true);
4238
+ if (recType === 1006) {
4239
+ if (currentSlideTexts.length > 0) {
4240
+ const title = currentSlideTexts[0] || "Slide";
4241
+ const texts = currentSlideTexts.slice(1);
4242
+ slides.push({ title, texts });
4243
+ currentSlideTexts = [];
4244
+ }
4245
+ offset += 8;
4246
+ continue;
4247
+ }
4248
+ if (recType === 3998 && recLen > 0 && offset + 8 + recLen <= len) {
4249
+ const bytes = stream.subarray(offset + 8, offset + 8 + recLen);
4250
+ const text = new TextDecoder("latin1").decode(bytes).trim();
4251
+ if (text && text.length > 1 && !/^[\x00-\x1F\x7F-\x9F]+$/.test(text)) {
4252
+ currentSlideTexts.push(text);
4253
+ }
4254
+ }
4255
+ if (recType === 3999 && recLen > 0 && offset + 8 + recLen <= len) {
4256
+ const bytes = stream.subarray(offset + 8, offset + 8 + recLen);
4257
+ const text = new TextDecoder("utf-16le").decode(bytes).trim();
4258
+ if (text && text.length > 1 && !/^[\x00-\x1F\x7F-\x9F]+$/.test(text)) {
4259
+ currentSlideTexts.push(text);
4260
+ }
4261
+ }
4262
+ const isContainer = (recVerInst & 15) === 15;
4263
+ if (isContainer) {
4264
+ offset += 8;
4265
+ } else {
4266
+ offset += 8 + recLen;
4267
+ }
4268
+ }
4269
+ if (currentSlideTexts.length > 0) {
4270
+ const title = currentSlideTexts[0] || "Slide";
4271
+ const texts = currentSlideTexts.slice(1);
4272
+ slides.push({ title, texts });
4273
+ }
4274
+ if (slides.length === 0) {
4275
+ const rawText = new TextDecoder("latin1", { fatal: false }).decode(stream);
4276
+ const matches = rawText.match(/[A-Za-z0-9\s,.:;!?'"-]{4,}/g) || [];
4277
+ const filtered = matches.map((m) => m.trim()).filter((m) => m.length > 4 && !m.includes("PowerPoint") && !m.includes("Arial") && !m.includes("Times"));
4278
+ if (filtered.length > 0) {
4279
+ const chunkSize = 4;
4280
+ for (let i = 0; i < filtered.length; i += chunkSize) {
4281
+ const chunk = filtered.slice(i, i + chunkSize);
4282
+ slides.push({
4283
+ title: chunk[0] || `Slide ${Math.floor(i / chunkSize) + 1}`,
4284
+ texts: chunk.slice(1)
4285
+ });
4286
+ }
4287
+ }
4288
+ }
4289
+ return slides;
4290
+ }
4291
+ };
4292
+ function pptPlugin() {
4293
+ return new PptPlugin();
4294
+ }
2724
4295
 
2725
4296
  // src/index.ts
2726
4297
  function getDefaultPlugins() {
@@ -2730,6 +4301,11 @@ function getDefaultPlugins() {
2730
4301
  docxPlugin(),
2731
4302
  excelPlugin(),
2732
4303
  pptxPlugin(),
4304
+ docPlugin(),
4305
+ pptPlugin(),
4306
+ openDocumentPlugin(),
4307
+ rtfPlugin(),
4308
+ htmlPreviewPlugin(),
2733
4309
  csvPlugin(),
2734
4310
  archivePlugin(),
2735
4311
  markdownPlugin(),