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