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