@files-preview-app/preview-file 1.0.0 → 1.1.2

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/react.cjs CHANGED
@@ -7,6 +7,13 @@ var DOMPurify = require('dompurify');
7
7
  var docx = require('docx-preview');
8
8
  var ExcelJS = require('exceljs');
9
9
  var hljs = require('highlight.js');
10
+ var fflate = require('fflate');
11
+ var marked = require('marked');
12
+ var pptxBrowser = require('pptx-browser');
13
+ var THREE = require('three');
14
+ var STLLoader_js = require('three/examples/jsm/loaders/STLLoader.js');
15
+ var OBJLoader_js = require('three/examples/jsm/loaders/OBJLoader.js');
16
+ var OrbitControls_js = require('three/examples/jsm/controls/OrbitControls.js');
10
17
  var jsxRuntime = require('react/jsx-runtime');
11
18
 
12
19
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -33,6 +40,7 @@ var DOMPurify__default = /*#__PURE__*/_interopDefault(DOMPurify);
33
40
  var docx__namespace = /*#__PURE__*/_interopNamespace(docx);
34
41
  var ExcelJS__default = /*#__PURE__*/_interopDefault(ExcelJS);
35
42
  var hljs__default = /*#__PURE__*/_interopDefault(hljs);
43
+ var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
36
44
 
37
45
  // src/react.tsx
38
46
  var EventEmitter = class {
@@ -323,6 +331,27 @@ function sanitizeSVG(svg) {
323
331
  USE_PROFILES: { svg: true, svgFilters: true }
324
332
  });
325
333
  }
334
+ function downloadFile(buffer, filename, mimeType) {
335
+ const blob = new Blob([buffer], { type: mimeType ?? "application/octet-stream" });
336
+ const url = URL.createObjectURL(blob);
337
+ const link = document.createElement("a");
338
+ link.href = url;
339
+ link.download = filename;
340
+ link.style.display = "none";
341
+ document.body.appendChild(link);
342
+ link.click();
343
+ setTimeout(() => {
344
+ document.body.removeChild(link);
345
+ URL.revokeObjectURL(url);
346
+ }, 100);
347
+ }
348
+ function formatFileSize(bytes) {
349
+ if (bytes === 0) return "0 B";
350
+ const units = ["B", "KB", "MB", "GB", "TB"];
351
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
352
+ const size = bytes / Math.pow(1024, i);
353
+ return `${size.toFixed(i > 0 ? 1 : 0)} ${units[i]}`;
354
+ }
326
355
  function createElement(tag, attrs, ...children) {
327
356
  const el = document.createElement(tag);
328
357
  if (attrs) {
@@ -1741,6 +1770,798 @@ var CodePlugin = class {
1741
1770
  function codePlugin() {
1742
1771
  return new CodePlugin();
1743
1772
  }
1773
+ var ArchivePlugin = class {
1774
+ id = "archive";
1775
+ name = "Archive Explorer";
1776
+ extensions = [".zip"];
1777
+ mimeTypes = ["application/zip", "application/x-zip-compressed"];
1778
+ weight = 70;
1779
+ supports(file) {
1780
+ const ext = file.metadata.extension?.toLowerCase();
1781
+ const mime = file.metadata.mimeType?.toLowerCase();
1782
+ return ext === ".zip" || this.mimeTypes.includes(mime || "");
1783
+ }
1784
+ getToolbarActions(instance) {
1785
+ return [
1786
+ {
1787
+ id: "zoom-out",
1788
+ icon: "zoom-out",
1789
+ label: "Zoom Out",
1790
+ type: "button",
1791
+ group: "zoom",
1792
+ execute: () => instance.zoomOut?.()
1793
+ },
1794
+ {
1795
+ id: "zoom-in",
1796
+ icon: "zoom-in",
1797
+ label: "Zoom In",
1798
+ type: "button",
1799
+ group: "zoom",
1800
+ execute: () => instance.zoomIn?.()
1801
+ },
1802
+ {
1803
+ id: "fit-page",
1804
+ icon: "fit-page",
1805
+ label: "Reset Zoom",
1806
+ type: "button",
1807
+ group: "zoom",
1808
+ execute: () => instance.fitToPage?.()
1809
+ },
1810
+ {
1811
+ id: "download",
1812
+ icon: "download",
1813
+ label: "Download Archive",
1814
+ type: "button",
1815
+ group: "actions",
1816
+ execute: () => instance.download?.()
1817
+ },
1818
+ {
1819
+ id: "print",
1820
+ icon: "print",
1821
+ label: "Print File List",
1822
+ type: "button",
1823
+ group: "actions",
1824
+ execute: () => instance.print?.()
1825
+ }
1826
+ ];
1827
+ }
1828
+ async render(ctx) {
1829
+ const wrapper = document.createElement("div");
1830
+ wrapper.className = "fp-archive-wrapper";
1831
+ wrapper.style.cssText = `
1832
+ width: 100%;
1833
+ height: 100%;
1834
+ overflow: auto;
1835
+ padding: 24px;
1836
+ box-sizing: border-box;
1837
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
1838
+ transform-origin: top left;
1839
+ transition: transform 0.2s ease;
1840
+ `;
1841
+ ctx.container.innerHTML = "";
1842
+ ctx.container.style.overflow = "auto";
1843
+ ctx.container.appendChild(wrapper);
1844
+ let scale = 1;
1845
+ const entries = await new Promise((resolve, reject) => {
1846
+ fflate.unzip(new Uint8Array(ctx.buffer), (err, unzipped) => {
1847
+ if (err) {
1848
+ reject(err);
1849
+ return;
1850
+ }
1851
+ const list = Object.entries(unzipped).map(([path, data]) => {
1852
+ const isDir = path.endsWith("/");
1853
+ const parts = path.split("/").filter(Boolean);
1854
+ const name = parts[parts.length - 1] || path;
1855
+ return {
1856
+ path,
1857
+ name,
1858
+ isDir,
1859
+ size: data.length,
1860
+ data
1861
+ };
1862
+ });
1863
+ resolve(list);
1864
+ });
1865
+ });
1866
+ const totalUncompressedSize = entries.reduce((acc, e) => acc + e.size, 0);
1867
+ const renderUI = (filteredEntries) => {
1868
+ wrapper.innerHTML = `
1869
+ <div style="max-width: 900px; margin: 0 auto; background: var(--fp-bg, #ffffff); border: 1px solid var(--fp-border, #e5e7eb); border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); overflow: hidden;">
1870
+ <div style="padding: 16px 20px; background: var(--fp-toolbar-bg, #f9fafb); border-bottom: 1px solid var(--fp-border, #e5e7eb); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;">
1871
+ <div>
1872
+ <h3 style="margin: 0 0 4px 0; font-size: 16px; font-weight: 600; color: var(--fp-text, #111827);">
1873
+ \u{1F4E6} ${ctx.metadata.name || "Archive.zip"}
1874
+ </h3>
1875
+ <div style="font-size: 13px; color: var(--fp-text-muted, #6b7280);">
1876
+ ${entries.length} items \xB7 Total size: ${formatFileSize(totalUncompressedSize)} (Compressed: ${formatFileSize(ctx.buffer.byteLength)})
1877
+ </div>
1878
+ </div>
1879
+ <div>
1880
+ <input type="text" id="fp-archive-search" placeholder="Search files in archive..." style="padding: 6px 12px; font-size: 13px; border: 1px solid var(--fp-border, #d1d5db); border-radius: 6px; outline: none; width: 220px;" />
1881
+ </div>
1882
+ </div>
1883
+ <div style="max-height: 550px; overflow-y: auto;">
1884
+ <table style="width: 100%; border-collapse: collapse; font-size: 13px; text-align: left;">
1885
+ <thead>
1886
+ <tr style="background: var(--fp-toolbar-bg, #f3f4f6); color: var(--fp-text-muted, #4b5563); border-bottom: 1px solid var(--fp-border, #e5e7eb);">
1887
+ <th style="padding: 10px 16px; font-weight: 600;">Name / Path</th>
1888
+ <th style="padding: 10px 16px; font-weight: 600; width: 120px;">Size</th>
1889
+ <th style="padding: 10px 16px; font-weight: 600; width: 100px; text-align: right;">Action</th>
1890
+ </tr>
1891
+ </thead>
1892
+ <tbody id="fp-archive-body">
1893
+ </tbody>
1894
+ </table>
1895
+ </div>
1896
+ </div>
1897
+ `;
1898
+ const tbody = wrapper.querySelector("#fp-archive-body");
1899
+ if (filteredEntries.length === 0) {
1900
+ tbody.innerHTML = `<tr><td colspan="3" style="padding: 24px; text-align: center; color: #9ca3af;">No matching files found</td></tr>`;
1901
+ } else {
1902
+ tbody.innerHTML = filteredEntries.map((e, idx) => `
1903
+ <tr style="border-bottom: 1px solid var(--fp-border, #f3f4f6); transition: background 0.15s ease;" onmouseover="this.style.background='var(--fp-hover, #f9fafb)'" onmouseout="this.style.background='transparent'">
1904
+ <td style="padding: 10px 16px; color: var(--fp-text, #1f2937); word-break: break-all;">
1905
+ <span style="margin-right: 8px;">${e.isDir ? "\u{1F4C1}" : "\u{1F4C4}"}</span>
1906
+ ${e.path}
1907
+ </td>
1908
+ <td style="padding: 10px 16px; color: var(--fp-text-muted, #6b7280);">
1909
+ ${e.isDir ? "-" : formatFileSize(e.size)}
1910
+ </td>
1911
+ <td style="padding: 10px 16px; text-align: right;">
1912
+ ${!e.isDir ? `<button data-idx="${idx}" class="fp-entry-dl" style="padding: 4px 8px; font-size: 12px; background: transparent; border: 1px solid var(--fp-border, #d1d5db); border-radius: 4px; cursor: pointer; color: var(--fp-text, #374151);">\u2B07\uFE0F Save</button>` : ""}
1913
+ </td>
1914
+ </tr>
1915
+ `).join("");
1916
+ }
1917
+ tbody.querySelectorAll(".fp-entry-dl").forEach((btn) => {
1918
+ btn.addEventListener("click", (ev) => {
1919
+ const target = ev.currentTarget;
1920
+ const idx = Number(target.getAttribute("data-idx"));
1921
+ const entry = filteredEntries[idx];
1922
+ if (entry && entry.data) {
1923
+ downloadFile(entry.data.buffer, entry.name);
1924
+ }
1925
+ });
1926
+ });
1927
+ const searchInput = wrapper.querySelector("#fp-archive-search");
1928
+ if (searchInput) {
1929
+ searchInput.addEventListener("input", () => {
1930
+ const q = searchInput.value.toLowerCase().trim();
1931
+ const filtered = q ? entries.filter((e) => e.path.toLowerCase().includes(q)) : entries;
1932
+ renderUI(filtered);
1933
+ const newSearch = wrapper.querySelector("#fp-archive-search");
1934
+ if (newSearch) {
1935
+ newSearch.value = q;
1936
+ newSearch.focus();
1937
+ }
1938
+ });
1939
+ }
1940
+ };
1941
+ renderUI(entries);
1942
+ const cleanup = () => {
1943
+ wrapper.remove();
1944
+ ctx.container.innerHTML = "";
1945
+ };
1946
+ ctx.signal.addEventListener("abort", cleanup);
1947
+ return {
1948
+ destroy: cleanup,
1949
+ zoomIn: () => {
1950
+ scale += 0.1;
1951
+ wrapper.style.transform = `scale(${scale})`;
1952
+ },
1953
+ zoomOut: () => {
1954
+ scale = Math.max(0.3, scale - 0.1);
1955
+ wrapper.style.transform = `scale(${scale})`;
1956
+ },
1957
+ getZoom: () => scale,
1958
+ setZoom: (level) => {
1959
+ scale = level;
1960
+ wrapper.style.transform = `scale(${scale})`;
1961
+ },
1962
+ fitToPage: () => {
1963
+ scale = 1;
1964
+ wrapper.style.transform = `scale(1)`;
1965
+ },
1966
+ download: () => {
1967
+ downloadFile(ctx.buffer, ctx.metadata.name || "archive.zip", "application/zip");
1968
+ },
1969
+ print: () => {
1970
+ window.print();
1971
+ }
1972
+ };
1973
+ }
1974
+ };
1975
+ function archivePlugin() {
1976
+ return new ArchivePlugin();
1977
+ }
1978
+ var MarkdownPlugin = class {
1979
+ id = "markdown";
1980
+ name = "Markdown Preview";
1981
+ extensions = [".md", ".markdown", ".mdown", ".mkd"];
1982
+ mimeTypes = ["text/markdown", "text/x-markdown"];
1983
+ weight = 90;
1984
+ // Higher than generic text/code plugin
1985
+ supports(file) {
1986
+ const ext = file.metadata.extension?.toLowerCase();
1987
+ const mime = file.metadata.mimeType?.toLowerCase();
1988
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
1989
+ }
1990
+ getToolbarActions(instance) {
1991
+ return [
1992
+ {
1993
+ id: "zoom-out",
1994
+ icon: "zoom-out",
1995
+ label: "Decrease Font",
1996
+ type: "button",
1997
+ group: "zoom",
1998
+ execute: () => instance.zoomOut?.()
1999
+ },
2000
+ {
2001
+ id: "zoom-in",
2002
+ icon: "zoom-in",
2003
+ label: "Increase Font",
2004
+ type: "button",
2005
+ group: "zoom",
2006
+ execute: () => instance.zoomIn?.()
2007
+ },
2008
+ {
2009
+ id: "fit-page",
2010
+ icon: "fit-page",
2011
+ label: "Default Size",
2012
+ type: "button",
2013
+ group: "zoom",
2014
+ execute: () => instance.fitToPage?.()
2015
+ },
2016
+ {
2017
+ id: "download",
2018
+ icon: "download",
2019
+ label: "Download Markdown",
2020
+ type: "button",
2021
+ group: "actions",
2022
+ execute: () => instance.download?.()
2023
+ },
2024
+ {
2025
+ id: "print",
2026
+ icon: "print",
2027
+ label: "Print Document",
2028
+ type: "button",
2029
+ group: "actions",
2030
+ execute: () => instance.print?.()
2031
+ }
2032
+ ];
2033
+ }
2034
+ async render(ctx) {
2035
+ const text = new TextDecoder("utf-8", { fatal: false }).decode(ctx.buffer);
2036
+ const rawHtml = await marked.marked.parse(text, {
2037
+ gfm: true,
2038
+ breaks: true
2039
+ });
2040
+ const cleanHtml = DOMPurify__default.default.sanitize(rawHtml, {
2041
+ USE_PROFILES: { html: true }
2042
+ });
2043
+ const wrapper = document.createElement("div");
2044
+ wrapper.className = "fp-markdown-wrapper";
2045
+ wrapper.style.cssText = `
2046
+ width: 100%;
2047
+ height: 100%;
2048
+ overflow: auto;
2049
+ padding: 32px 40px;
2050
+ box-sizing: border-box;
2051
+ line-height: 1.6;
2052
+ font-size: 15px;
2053
+ color: var(--fp-text, #24292f);
2054
+ background: var(--fp-bg, #ffffff);
2055
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
2056
+ `;
2057
+ wrapper.innerHTML = `
2058
+ <style>
2059
+ .fp-markdown-wrapper h1, .fp-markdown-wrapper h2, .fp-markdown-wrapper h3,
2060
+ .fp-markdown-wrapper h4, .fp-markdown-wrapper h5, .fp-markdown-wrapper h6 {
2061
+ margin-top: 24px;
2062
+ margin-bottom: 16px;
2063
+ font-weight: 600;
2064
+ line-height: 1.25;
2065
+ color: var(--fp-text, #1f2328);
2066
+ }
2067
+ .fp-markdown-wrapper h1 { font-size: 2em; padding-bottom: 0.3em; border-bottom: 1px solid var(--fp-border, #d0d7de); }
2068
+ .fp-markdown-wrapper h2 { font-size: 1.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--fp-border, #d0d7de); }
2069
+ .fp-markdown-wrapper h3 { font-size: 1.25em; }
2070
+ .fp-markdown-wrapper p { margin-top: 0; margin-bottom: 16px; }
2071
+ .fp-markdown-wrapper table {
2072
+ border-spacing: 0;
2073
+ border-collapse: collapse;
2074
+ margin-top: 0;
2075
+ margin-bottom: 16px;
2076
+ width: 100%;
2077
+ overflow: auto;
2078
+ }
2079
+ .fp-markdown-wrapper table th, .fp-markdown-wrapper table td {
2080
+ padding: 6px 13px;
2081
+ border: 1px solid var(--fp-border, #d0d7de);
2082
+ }
2083
+ .fp-markdown-wrapper table tr:nth-child(2n) {
2084
+ background-color: var(--fp-toolbar-bg, #f6f8fa);
2085
+ }
2086
+ .fp-markdown-wrapper blockquote {
2087
+ margin: 0 0 16px 0;
2088
+ padding: 0 1em;
2089
+ color: var(--fp-text-muted, #59636e);
2090
+ border-left: 0.25em solid var(--fp-border, #d0d7de);
2091
+ }
2092
+ .fp-markdown-wrapper pre {
2093
+ padding: 16px;
2094
+ overflow: auto;
2095
+ font-size: 85%;
2096
+ line-height: 1.45;
2097
+ background-color: var(--fp-toolbar-bg, #f6f8fa);
2098
+ border-radius: 6px;
2099
+ border: 1px solid var(--fp-border, #d0d7de);
2100
+ }
2101
+ .fp-markdown-wrapper code {
2102
+ padding: 0.2em 0.4em;
2103
+ margin: 0;
2104
+ font-size: 85%;
2105
+ background-color: rgba(175, 184, 193, 0.2);
2106
+ border-radius: 4px;
2107
+ font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
2108
+ }
2109
+ .fp-markdown-wrapper pre code {
2110
+ padding: 0;
2111
+ background: transparent;
2112
+ }
2113
+ .fp-markdown-wrapper ul, .fp-markdown-wrapper ol {
2114
+ padding-left: 2em;
2115
+ margin-top: 0;
2116
+ margin-bottom: 16px;
2117
+ }
2118
+ .fp-markdown-wrapper hr {
2119
+ height: 0.25em;
2120
+ padding: 0;
2121
+ margin: 24px 0;
2122
+ background-color: var(--fp-border, #d0d7de);
2123
+ border: 0;
2124
+ }
2125
+ </style>
2126
+ <div class="fp-markdown-content" style="max-width: 860px; margin: 0 auto;">
2127
+ ${cleanHtml}
2128
+ </div>
2129
+ `;
2130
+ wrapper.querySelectorAll("pre code").forEach((block) => {
2131
+ hljs__default.default.highlightElement(block);
2132
+ });
2133
+ ctx.container.innerHTML = "";
2134
+ ctx.container.style.overflow = "auto";
2135
+ ctx.container.appendChild(wrapper);
2136
+ let fontSize = 15;
2137
+ const cleanup = () => {
2138
+ wrapper.remove();
2139
+ ctx.container.innerHTML = "";
2140
+ };
2141
+ ctx.signal.addEventListener("abort", cleanup);
2142
+ return {
2143
+ destroy: cleanup,
2144
+ zoomIn: () => {
2145
+ fontSize = Math.min(28, fontSize + 2);
2146
+ wrapper.style.fontSize = `${fontSize}px`;
2147
+ },
2148
+ zoomOut: () => {
2149
+ fontSize = Math.max(10, fontSize - 2);
2150
+ wrapper.style.fontSize = `${fontSize}px`;
2151
+ },
2152
+ getZoom: () => fontSize / 15,
2153
+ setZoom: (level) => {
2154
+ fontSize = Math.round(15 * level);
2155
+ wrapper.style.fontSize = `${fontSize}px`;
2156
+ },
2157
+ fitToPage: () => {
2158
+ fontSize = 15;
2159
+ wrapper.style.fontSize = "15px";
2160
+ },
2161
+ download: () => {
2162
+ downloadFile(ctx.buffer, ctx.metadata.name || "document.md", "text/markdown");
2163
+ },
2164
+ print: () => {
2165
+ window.print();
2166
+ }
2167
+ };
2168
+ }
2169
+ };
2170
+ function markdownPlugin() {
2171
+ return new MarkdownPlugin();
2172
+ }
2173
+ var PptxPlugin = class {
2174
+ id = "pptx";
2175
+ name = "PowerPoint Presentation";
2176
+ extensions = [".pptx", ".ppsx"];
2177
+ mimeTypes = [
2178
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
2179
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow"
2180
+ ];
2181
+ weight = 80;
2182
+ supports(file) {
2183
+ const ext = file.metadata.extension?.toLowerCase();
2184
+ const mime = file.metadata.mimeType?.toLowerCase();
2185
+ return this.extensions.includes(ext || "") || this.mimeTypes.includes(mime || "");
2186
+ }
2187
+ getToolbarActions(instance) {
2188
+ return [
2189
+ {
2190
+ id: "thumbnails",
2191
+ icon: "thumbnails",
2192
+ label: "Slide Thumbnails",
2193
+ type: "button",
2194
+ group: "navigation",
2195
+ execute: () => instance.toggleThumbnails?.()
2196
+ },
2197
+ {
2198
+ id: "page-prev",
2199
+ icon: "page-prev",
2200
+ label: "Previous Slide",
2201
+ type: "button",
2202
+ group: "navigation",
2203
+ execute: () => {
2204
+ const cur = instance.getCurrentPage?.() ?? 1;
2205
+ if (cur > 1) instance.goToPage?.(cur - 1);
2206
+ }
2207
+ },
2208
+ {
2209
+ id: "page-nav",
2210
+ icon: "",
2211
+ label: "Slide Number",
2212
+ type: "page-nav",
2213
+ group: "navigation",
2214
+ execute: (page) => instance.goToPage?.(Number(page))
2215
+ },
2216
+ {
2217
+ id: "page-next",
2218
+ icon: "page-next",
2219
+ label: "Next Slide",
2220
+ type: "button",
2221
+ group: "navigation",
2222
+ execute: () => {
2223
+ const cur = instance.getCurrentPage?.() ?? 1;
2224
+ const total = instance.getPageCount?.() ?? 1;
2225
+ if (cur < total) instance.goToPage?.(cur + 1);
2226
+ }
2227
+ },
2228
+ {
2229
+ id: "zoom-out",
2230
+ icon: "zoom-out",
2231
+ label: "Zoom Out",
2232
+ type: "button",
2233
+ group: "zoom",
2234
+ execute: () => instance.zoomOut?.()
2235
+ },
2236
+ {
2237
+ id: "zoom-in",
2238
+ icon: "zoom-in",
2239
+ label: "Zoom In",
2240
+ type: "button",
2241
+ group: "zoom",
2242
+ execute: () => instance.zoomIn?.()
2243
+ },
2244
+ {
2245
+ id: "fit-page",
2246
+ icon: "fit-page",
2247
+ label: "Fit to Slide",
2248
+ type: "button",
2249
+ group: "zoom",
2250
+ execute: () => instance.fitToPage?.()
2251
+ },
2252
+ {
2253
+ id: "download",
2254
+ icon: "download",
2255
+ label: "Download PPTX",
2256
+ type: "button",
2257
+ group: "actions",
2258
+ execute: () => instance.download?.()
2259
+ },
2260
+ {
2261
+ id: "print",
2262
+ icon: "print",
2263
+ label: "Print Presentation",
2264
+ type: "button",
2265
+ group: "actions",
2266
+ execute: () => instance.print?.()
2267
+ }
2268
+ ];
2269
+ }
2270
+ async render(ctx) {
2271
+ const renderer = new pptxBrowser.PptxRenderer();
2272
+ await renderer.load(ctx.buffer);
2273
+ const slideCount = renderer.slidePaths?.length || 1;
2274
+ let currentSlide = 1;
2275
+ let scale = 1;
2276
+ const wrapper = document.createElement("div");
2277
+ wrapper.className = "fp-pptx-wrapper";
2278
+ wrapper.style.cssText = `
2279
+ width: 100%;
2280
+ height: 100%;
2281
+ overflow: auto;
2282
+ display: flex;
2283
+ justify-content: center;
2284
+ align-items: flex-start;
2285
+ padding: 24px;
2286
+ box-sizing: border-box;
2287
+ background: var(--fp-bg-canvas, #525659);
2288
+ `;
2289
+ const slideContainer = document.createElement("div");
2290
+ slideContainer.className = "fp-slide-container";
2291
+ slideContainer.style.cssText = `
2292
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
2293
+ border-radius: 4px;
2294
+ overflow: hidden;
2295
+ background: #ffffff;
2296
+ transform-origin: top center;
2297
+ transition: transform 0.2s ease;
2298
+ `;
2299
+ const canvas = document.createElement("canvas");
2300
+ slideContainer.appendChild(canvas);
2301
+ wrapper.appendChild(slideContainer);
2302
+ ctx.container.innerHTML = "";
2303
+ ctx.container.style.overflow = "auto";
2304
+ ctx.container.appendChild(wrapper);
2305
+ const renderCurrentSlide = async () => {
2306
+ try {
2307
+ await renderer.renderSlide(currentSlide - 1, canvas, 1280);
2308
+ ctx.emit("page-change", { page: currentSlide, totalPages: slideCount });
2309
+ } catch (err) {
2310
+ console.error("[PptxPlugin] Failed to render slide:", err);
2311
+ }
2312
+ };
2313
+ await renderCurrentSlide();
2314
+ const cleanup = () => {
2315
+ renderer.destroy();
2316
+ wrapper.remove();
2317
+ ctx.container.innerHTML = "";
2318
+ };
2319
+ ctx.signal.addEventListener("abort", cleanup);
2320
+ const instance = {
2321
+ destroy: cleanup,
2322
+ goToPage: (page) => {
2323
+ if (page >= 1 && page <= slideCount) {
2324
+ currentSlide = page;
2325
+ renderCurrentSlide();
2326
+ }
2327
+ },
2328
+ getPageCount: () => slideCount,
2329
+ getCurrentPage: () => currentSlide,
2330
+ zoomIn: () => {
2331
+ scale += 0.1;
2332
+ slideContainer.style.transform = `scale(${scale})`;
2333
+ },
2334
+ zoomOut: () => {
2335
+ scale = Math.max(0.2, scale - 0.1);
2336
+ slideContainer.style.transform = `scale(${scale})`;
2337
+ },
2338
+ getZoom: () => scale,
2339
+ setZoom: (level) => {
2340
+ scale = level;
2341
+ slideContainer.style.transform = `scale(${scale})`;
2342
+ },
2343
+ fitToPage: () => {
2344
+ scale = 1;
2345
+ slideContainer.style.transform = "scale(1)";
2346
+ },
2347
+ getThumbnails: () => {
2348
+ const list = [];
2349
+ for (let i = 0; i < slideCount; i++) {
2350
+ const slideIdx = i;
2351
+ list.push({
2352
+ index: slideIdx,
2353
+ label: `Slide ${slideIdx + 1}`,
2354
+ render: async (thumbCanvas) => {
2355
+ await renderer.renderSlide(slideIdx, thumbCanvas, 240);
2356
+ }
2357
+ });
2358
+ }
2359
+ return list;
2360
+ },
2361
+ download: () => {
2362
+ downloadFile(
2363
+ ctx.buffer,
2364
+ ctx.metadata.name || "presentation.pptx",
2365
+ this.mimeTypes[0]
2366
+ );
2367
+ },
2368
+ print: () => {
2369
+ window.print();
2370
+ }
2371
+ };
2372
+ return instance;
2373
+ }
2374
+ };
2375
+ function pptxPlugin() {
2376
+ return new PptxPlugin();
2377
+ }
2378
+ var ThreeDPlugin = class {
2379
+ id = "3d";
2380
+ name = "3D Model Preview";
2381
+ extensions = [".stl", ".obj"];
2382
+ mimeTypes = ["model/stl", "model/obj", "application/sla", "text/plain"];
2383
+ weight = 75;
2384
+ supports(file) {
2385
+ const ext = file.metadata.extension?.toLowerCase();
2386
+ return ext === ".stl" || ext === ".obj";
2387
+ }
2388
+ getToolbarActions(instance) {
2389
+ return [
2390
+ {
2391
+ id: "zoom-out",
2392
+ icon: "zoom-out",
2393
+ label: "Zoom Out",
2394
+ type: "button",
2395
+ group: "zoom",
2396
+ execute: () => instance.zoomOut?.()
2397
+ },
2398
+ {
2399
+ id: "zoom-in",
2400
+ icon: "zoom-in",
2401
+ label: "Zoom In",
2402
+ type: "button",
2403
+ group: "zoom",
2404
+ execute: () => instance.zoomIn?.()
2405
+ },
2406
+ {
2407
+ id: "fit-page",
2408
+ icon: "fit-page",
2409
+ label: "Reset Camera View",
2410
+ type: "button",
2411
+ group: "zoom",
2412
+ execute: () => instance.fitToPage?.()
2413
+ },
2414
+ {
2415
+ id: "rotate-cw",
2416
+ icon: "rotate-cw",
2417
+ label: "Toggle Wireframe",
2418
+ type: "button",
2419
+ group: "view",
2420
+ execute: () => instance.rotateCW?.()
2421
+ },
2422
+ {
2423
+ id: "download",
2424
+ icon: "download",
2425
+ label: "Download 3D Model",
2426
+ type: "button",
2427
+ group: "actions",
2428
+ execute: () => instance.download?.()
2429
+ }
2430
+ ];
2431
+ }
2432
+ async render(ctx) {
2433
+ const container = ctx.container;
2434
+ container.innerHTML = "";
2435
+ container.style.overflow = "hidden";
2436
+ container.style.position = "relative";
2437
+ container.style.width = "100%";
2438
+ container.style.height = "100%";
2439
+ container.style.background = "#1a1a1a";
2440
+ const width = container.clientWidth || 800;
2441
+ const height = container.clientHeight || 600;
2442
+ const scene = new THREE__namespace.Scene();
2443
+ scene.background = new THREE__namespace.Color(1973796);
2444
+ const camera = new THREE__namespace.PerspectiveCamera(45, width / height, 0.1, 2e3);
2445
+ const renderer = new THREE__namespace.WebGLRenderer({ antialias: true });
2446
+ renderer.setSize(width, height);
2447
+ renderer.setPixelRatio(window.devicePixelRatio);
2448
+ renderer.shadowMap.enabled = true;
2449
+ container.appendChild(renderer.domElement);
2450
+ const controls = new OrbitControls_js.OrbitControls(camera, renderer.domElement);
2451
+ controls.enableDamping = true;
2452
+ controls.dampingFactor = 0.05;
2453
+ const ambientLight = new THREE__namespace.AmbientLight(16777215, 0.8);
2454
+ scene.add(ambientLight);
2455
+ const dirLight1 = new THREE__namespace.DirectionalLight(16777215, 1.2);
2456
+ dirLight1.position.set(100, 200, 100);
2457
+ scene.add(dirLight1);
2458
+ const dirLight2 = new THREE__namespace.DirectionalLight(16777215, 0.6);
2459
+ dirLight2.position.set(-100, -100, -100);
2460
+ scene.add(dirLight2);
2461
+ const grid = new THREE__namespace.GridHelper(200, 20, 4473924, 2236962);
2462
+ scene.add(grid);
2463
+ let meshGroup = new THREE__namespace.Group();
2464
+ let isWireframe = false;
2465
+ const ext = ctx.metadata.extension?.toLowerCase();
2466
+ const materials = [];
2467
+ if (ext === ".stl") {
2468
+ const loader = new STLLoader_js.STLLoader();
2469
+ const geometry = loader.parse(ctx.buffer);
2470
+ geometry.computeVertexNormals();
2471
+ geometry.center();
2472
+ const material = new THREE__namespace.MeshStandardMaterial({
2473
+ color: 3900150,
2474
+ roughness: 0.4,
2475
+ metalness: 0.2
2476
+ });
2477
+ materials.push(material);
2478
+ const mesh = new THREE__namespace.Mesh(geometry, material);
2479
+ meshGroup.add(mesh);
2480
+ } else if (ext === ".obj") {
2481
+ const loader = new OBJLoader_js.OBJLoader();
2482
+ const text = new TextDecoder().decode(ctx.buffer);
2483
+ const obj = loader.parse(text);
2484
+ obj.traverse((child) => {
2485
+ if (child.isMesh) {
2486
+ const m = child;
2487
+ m.geometry.computeVertexNormals();
2488
+ const mat = new THREE__namespace.MeshStandardMaterial({
2489
+ color: 1096065,
2490
+ roughness: 0.5,
2491
+ metalness: 0.1
2492
+ });
2493
+ materials.push(mat);
2494
+ m.material = mat;
2495
+ }
2496
+ });
2497
+ meshGroup.add(obj);
2498
+ }
2499
+ scene.add(meshGroup);
2500
+ const box = new THREE__namespace.Box3().setFromObject(meshGroup);
2501
+ const sphere = box.getBoundingSphere(new THREE__namespace.Sphere());
2502
+ const radius = Math.max(sphere.radius, 10);
2503
+ const fitCamera = () => {
2504
+ camera.position.set(radius * 1.5, radius * 1.2, radius * 2);
2505
+ camera.lookAt(0, 0, 0);
2506
+ controls.target.set(0, 0, 0);
2507
+ controls.update();
2508
+ };
2509
+ fitCamera();
2510
+ let animId;
2511
+ const animate = () => {
2512
+ animId = requestAnimationFrame(animate);
2513
+ controls.update();
2514
+ renderer.render(scene, camera);
2515
+ };
2516
+ animate();
2517
+ const resizeObserver = new ResizeObserver(() => {
2518
+ const newWidth = container.clientWidth || 800;
2519
+ const newHeight = container.clientHeight || 600;
2520
+ camera.aspect = newWidth / newHeight;
2521
+ camera.updateProjectionMatrix();
2522
+ renderer.setSize(newWidth, newHeight);
2523
+ });
2524
+ resizeObserver.observe(container);
2525
+ const cleanup = () => {
2526
+ cancelAnimationFrame(animId);
2527
+ resizeObserver.disconnect();
2528
+ controls.dispose();
2529
+ renderer.dispose();
2530
+ materials.forEach((m) => m.dispose());
2531
+ meshGroup.traverse((child) => {
2532
+ if (child.geometry) {
2533
+ child.geometry.dispose();
2534
+ }
2535
+ });
2536
+ container.innerHTML = "";
2537
+ };
2538
+ ctx.signal.addEventListener("abort", cleanup);
2539
+ return {
2540
+ destroy: cleanup,
2541
+ zoomIn: () => {
2542
+ camera.position.multiplyScalar(0.85);
2543
+ controls.update();
2544
+ },
2545
+ zoomOut: () => {
2546
+ camera.position.multiplyScalar(1.15);
2547
+ controls.update();
2548
+ },
2549
+ fitToPage: fitCamera,
2550
+ rotateCW: () => {
2551
+ isWireframe = !isWireframe;
2552
+ materials.forEach((m) => {
2553
+ m.wireframe = isWireframe;
2554
+ });
2555
+ },
2556
+ download: () => {
2557
+ downloadFile(ctx.buffer, ctx.metadata.name || `model${ext || ".stl"}`);
2558
+ }
2559
+ };
2560
+ }
2561
+ };
2562
+ function threeDPlugin() {
2563
+ return new ThreeDPlugin();
2564
+ }
1744
2565
 
1745
2566
  // src/index.ts
1746
2567
  function getDefaultPlugins() {
@@ -1749,7 +2570,11 @@ function getDefaultPlugins() {
1749
2570
  mediaPlugin(),
1750
2571
  docxPlugin(),
1751
2572
  excelPlugin(),
2573
+ pptxPlugin(),
1752
2574
  csvPlugin(),
2575
+ archivePlugin(),
2576
+ markdownPlugin(),
2577
+ threeDPlugin(),
1753
2578
  codePlugin()
1754
2579
  ];
1755
2580
  }