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