@files-preview-app/preview-file 1.2.7 → 1.2.8

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
@@ -476,7 +476,8 @@ function createElement(tag, attrs, ...children) {
476
476
  }
477
477
  var ICON_ZOOM_IN = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line><line x1="11" y1="8" x2="11" y2="14"></line><line x1="8" y1="11" x2="14" y2="11"></line></svg>`;
478
478
  var ICON_ZOOM_OUT = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line><line x1="8" y1="11" x2="14" y2="11"></line></svg>`;
479
- var ICON_FIT_PAGE = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" y1="3" x2="14" y2="10"></line><line x1="3" y1="21" x2="10" y2="14"></line></svg>`;
479
+ var ICON_FIT_PAGE = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"></rect><line x1="8" y1="12" x2="16" y2="12"></line><polyline points="11 9 8 12 11 15"></polyline><polyline points="13 9 16 12 13 15"></polyline></svg>`;
480
+ var ICON_FIT_WIDTH = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="2" y1="12" x2="22" y2="12"></line><polyline points="5 9 2 12 5 15"></polyline><polyline points="19 9 22 12 19 15"></polyline><line x1="2" y1="5" x2="2" y2="19"></line><line x1="22" y1="5" x2="22" y2="19"></line></svg>`;
480
481
  var ICON_ROTATE_CW = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"></polyline><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path></svg>`;
481
482
  var ICON_ROTATE_CCW = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="1 4 1 10 7 10"></polyline><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path></svg>`;
482
483
  var ICON_DOWNLOAD = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>`;
@@ -496,6 +497,7 @@ var ICON_MAP = {
496
497
  "zoom-in": ICON_ZOOM_IN,
497
498
  "zoom-out": ICON_ZOOM_OUT,
498
499
  "fit-page": ICON_FIT_PAGE,
500
+ "fit-width": ICON_FIT_WIDTH,
499
501
  "fit-slide": ICON_FIT_PAGE,
500
502
  "rotate-cw": ICON_ROTATE_CW,
501
503
  "rotate-ccw": ICON_ROTATE_CCW,
@@ -1442,6 +1444,7 @@ var PdfPlugin = class {
1442
1444
  let currentPage = 1;
1443
1445
  let zoomScale = 1;
1444
1446
  let rotation = 0;
1447
+ let fitMode = "width";
1445
1448
  let currentRenderTask = null;
1446
1449
  const renderPage = async (pageNum) => {
1447
1450
  if (currentRenderTask) {
@@ -1461,11 +1464,16 @@ var PdfPlugin = class {
1461
1464
  const containerWidth = container.clientWidth || 900;
1462
1465
  const containerHeight = container.clientHeight || 700;
1463
1466
  const unscaledVp = page.getViewport({ scale: 1, rotation });
1464
- const availWidth = Math.max(100, containerWidth - 48);
1465
- const availHeight = Math.max(100, containerHeight - 88);
1467
+ const availWidth = Math.max(280, containerWidth - 48);
1468
+ const availHeight = Math.max(280, containerHeight - 88);
1466
1469
  const scaleW = availWidth / unscaledVp.width;
1467
1470
  const scaleH = availHeight / unscaledVp.height;
1468
- const fitScale = Math.min(scaleW, scaleH);
1471
+ let fitScale;
1472
+ if (fitMode === "page") {
1473
+ fitScale = Math.max(0.5, Math.min(scaleW, scaleH));
1474
+ } else {
1475
+ fitScale = Math.max(0.65, Math.min(1.15, scaleW));
1476
+ }
1469
1477
  const effectiveScale = (fitScale > 0 ? fitScale : 1) * zoomScale;
1470
1478
  const pixelRatio = window.devicePixelRatio || 1;
1471
1479
  const viewport = page.getViewport({ scale: effectiveScale, rotation });
@@ -1534,6 +1542,7 @@ var PdfPlugin = class {
1534
1542
  renderPage(currentPage);
1535
1543
  },
1536
1544
  fitToPage: () => {
1545
+ fitMode = fitMode === "width" ? "page" : "width";
1537
1546
  zoomScale = 1;
1538
1547
  rotation = 0;
1539
1548
  renderPage(currentPage);
@@ -2087,8 +2096,53 @@ var DocxPlugin = class {
2087
2096
  }
2088
2097
  }
2089
2098
  }
2090
- const sections = wrapper.querySelectorAll("section.docx");
2091
- const cards = wrapper.querySelectorAll(".fp-docx-page-card");
2099
+ let sections = Array.from(wrapper.querySelectorAll("section.docx"));
2100
+ const cards = Array.from(wrapper.querySelectorAll(".fp-docx-page-card"));
2101
+ if (sections.length === 1 && cards.length === 0) {
2102
+ const singleSec = sections[0];
2103
+ const pageH = 1056;
2104
+ const secH = singleSec.offsetHeight || singleSec.scrollHeight;
2105
+ if (secH > pageH * 1.25) {
2106
+ const children = Array.from(singleSec.children);
2107
+ if (children.length > 1) {
2108
+ const parent = singleSec.parentElement || wrapper;
2109
+ const newSections = [singleSec];
2110
+ singleSec.innerHTML = "";
2111
+ singleSec.style.minHeight = `${pageH}px`;
2112
+ singleSec.style.maxHeight = `${pageH}px`;
2113
+ singleSec.style.overflow = "hidden";
2114
+ singleSec.style.boxSizing = "border-box";
2115
+ let curSec = singleSec;
2116
+ let curH = 0;
2117
+ const maxH = pageH - 96;
2118
+ for (let i = 0; i < children.length; i++) {
2119
+ const child = children[i];
2120
+ curSec.appendChild(child);
2121
+ const chH = child.offsetHeight || 28;
2122
+ curH += chH;
2123
+ if (curH >= maxH && i < children.length - 1) {
2124
+ const nextSec = document.createElement("section");
2125
+ nextSec.className = singleSec.className;
2126
+ nextSec.style.cssText = singleSec.style.cssText;
2127
+ nextSec.style.width = singleSec.style.width || "816px";
2128
+ nextSec.style.minHeight = `${pageH}px`;
2129
+ nextSec.style.maxHeight = `${pageH}px`;
2130
+ nextSec.style.overflow = "hidden";
2131
+ nextSec.style.boxSizing = "border-box";
2132
+ nextSec.style.backgroundColor = "#ffffff";
2133
+ nextSec.style.boxShadow = "0 4px 24px rgba(0, 0, 0, 0.08)";
2134
+ nextSec.style.borderRadius = "4px";
2135
+ nextSec.style.marginBottom = "24px";
2136
+ parent.appendChild(nextSec);
2137
+ newSections.push(nextSec);
2138
+ curSec = nextSec;
2139
+ curH = 0;
2140
+ }
2141
+ }
2142
+ sections = newSections;
2143
+ }
2144
+ }
2145
+ }
2092
2146
  const pageElements = sections.length > 0 ? sections : cards;
2093
2147
  const totalPages = Math.max(1, pageElements.length);
2094
2148
  let currentPage = 1;
@@ -2132,22 +2186,27 @@ var DocxPlugin = class {
2132
2186
  }
2133
2187
  scale = 1;
2134
2188
  let rotation = 0;
2135
- const calculateFitScale = () => {
2189
+ let fitMode = "width";
2190
+ const calculateFitScale = (mode = fitMode) => {
2136
2191
  const activeEl = pageElements[currentPage - 1] || wrapper.firstElementChild || wrapper;
2137
2192
  const elW = activeEl.offsetWidth || 816;
2138
- const elH = activeEl.offsetHeight || 1056;
2139
- const availW = Math.max(200, ctx.container.clientWidth - 48);
2140
- const availH = Math.max(200, ctx.container.clientHeight - 80);
2193
+ const singlePageH = Math.min(activeEl.offsetHeight || 1056, Math.round(elW * 1.32));
2194
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
2195
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
2141
2196
  const sW = availW / elW;
2142
- const sH = availH / elH;
2143
- return Math.min(1.1, Math.min(sW, sH));
2197
+ const sH = availH / singlePageH;
2198
+ if (mode === "page") {
2199
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
2200
+ }
2201
+ return Math.max(0.65, Math.min(1.05, sW));
2144
2202
  };
2145
2203
  const applyTransform = () => {
2146
2204
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
2147
2205
  wrapper.style.transformOrigin = "top center";
2148
2206
  };
2149
2207
  setTimeout(() => {
2150
- scale = calculateFitScale();
2208
+ fitMode = "width";
2209
+ scale = calculateFitScale("width");
2151
2210
  applyTransform();
2152
2211
  }, 60);
2153
2212
  const cleanup = () => {
@@ -2181,7 +2240,8 @@ var DocxPlugin = class {
2181
2240
  applyTransform();
2182
2241
  },
2183
2242
  fitToPage: () => {
2184
- scale = calculateFitScale();
2243
+ fitMode = fitMode === "width" ? "page" : "width";
2244
+ scale = calculateFitScale(fitMode);
2185
2245
  rotation = 0;
2186
2246
  applyTransform();
2187
2247
  },
@@ -2625,11 +2685,9 @@ var ExcelPlugin = class {
2625
2685
  const calculateFitScale = () => {
2626
2686
  const table = contentArea.querySelector("table");
2627
2687
  if (!table) return 1;
2628
- const availW = Math.max(200, container.clientWidth - 48);
2629
- const availH = Math.max(200, container.clientHeight - 80);
2688
+ const availW = Math.max(280, container.clientWidth - 48);
2630
2689
  const tW = table.offsetWidth || 800;
2631
- const tH = table.offsetHeight || 600;
2632
- return Math.min(1, Math.min(availW / tW, availH / tH));
2690
+ return Math.max(0.65, Math.min(1, availW / tW));
2633
2691
  };
2634
2692
  try {
2635
2693
  wb = XLSX.read(new Uint8Array(ctx.buffer), { type: "array", cellDates: true });
@@ -3226,7 +3284,7 @@ var CodePlugin = class {
3226
3284
  fitToPage: () => {
3227
3285
  fontSize = 13;
3228
3286
  rotation = 0;
3229
- zoomLevel = 1;
3287
+ zoomLevel = isTxt ? Math.max(0.65, Math.min(1.05, (container.clientWidth - 48) / 816)) : 1;
3230
3288
  updateTransform();
3231
3289
  },
3232
3290
  rotateCW: () => {
@@ -4208,20 +4266,27 @@ var RtfPlugin = class {
4208
4266
  let scale = 1;
4209
4267
  let rotation = 0;
4210
4268
  let pageElements = [];
4211
- const calculateFitScale = () => {
4269
+ let fitMode = "width";
4270
+ const calculateFitScale = (mode = fitMode) => {
4212
4271
  const activeEl = pageElements[currentPage - 1] || wrapper;
4213
4272
  const elW = activeEl.offsetWidth || 850;
4214
- const elH = activeEl.offsetHeight || 1e3;
4215
- const availW = Math.max(200, ctx.container.clientWidth - 48);
4216
- const availH = Math.max(200, ctx.container.clientHeight - 80);
4217
- return Math.min(1.1, Math.min(availW / elW, availH / elH));
4273
+ const singlePageH = Math.min(activeEl.offsetHeight || 1056, Math.round(elW * 1.32));
4274
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
4275
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
4276
+ const sW = availW / elW;
4277
+ const sH = availH / singlePageH;
4278
+ if (mode === "page") {
4279
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
4280
+ }
4281
+ return Math.max(0.65, Math.min(1.05, sW));
4218
4282
  };
4219
4283
  const applyTransform = () => {
4220
4284
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
4221
4285
  wrapper.style.transformOrigin = "top center";
4222
4286
  };
4223
4287
  setTimeout(() => {
4224
- scale = calculateFitScale();
4288
+ fitMode = "width";
4289
+ scale = calculateFitScale("width");
4225
4290
  applyTransform();
4226
4291
  }, 60);
4227
4292
  try {
@@ -4330,7 +4395,8 @@ var RtfPlugin = class {
4330
4395
  applyTransform();
4331
4396
  },
4332
4397
  fitToPage: () => {
4333
- scale = calculateFitScale();
4398
+ fitMode = fitMode === "width" ? "page" : "width";
4399
+ scale = calculateFitScale(fitMode);
4334
4400
  rotation = 0;
4335
4401
  applyTransform();
4336
4402
  },
@@ -4649,19 +4715,29 @@ var OpenDocumentPlugin = class {
4649
4715
  ctx.container.appendChild(container);
4650
4716
  let scale = 1;
4651
4717
  let rotation = 0;
4652
- const calculateFitScale = () => {
4718
+ let fitMode = "width";
4719
+ const calculateFitScale = (mode = fitMode) => {
4653
4720
  const elW = wrapper.offsetWidth || 850;
4654
- const elH = wrapper.offsetHeight || (isPresentation ? 540 : 1e3);
4655
- const availW = Math.max(200, ctx.container.clientWidth - 48);
4656
- const availH = Math.max(200, ctx.container.clientHeight - 80);
4657
- return Math.min(1, Math.min(availW / elW, availH / elH));
4721
+ const singlePageH = Math.min(wrapper.offsetHeight || 1056, Math.round(elW * 1.32));
4722
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
4723
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
4724
+ const sW = availW / elW;
4725
+ const sH = availH / (isPresentation ? 540 : singlePageH);
4726
+ if (isPresentation) {
4727
+ return Math.min(1, Math.min(sW, sH));
4728
+ }
4729
+ if (mode === "page") {
4730
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
4731
+ }
4732
+ return Math.max(0.65, Math.min(1.05, sW));
4658
4733
  };
4659
4734
  const applyTransform = () => {
4660
4735
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
4661
4736
  wrapper.style.transformOrigin = "top center";
4662
4737
  };
4663
4738
  setTimeout(() => {
4664
- scale = calculateFitScale();
4739
+ fitMode = "width";
4740
+ scale = calculateFitScale("width");
4665
4741
  applyTransform();
4666
4742
  }, 60);
4667
4743
  let currentPage = 1;
@@ -4822,7 +4898,8 @@ var OpenDocumentPlugin = class {
4822
4898
  applyTransform();
4823
4899
  },
4824
4900
  fitToPage: () => {
4825
- scale = calculateFitScale();
4901
+ fitMode = fitMode === "width" ? "page" : "width";
4902
+ scale = calculateFitScale(fitMode);
4826
4903
  rotation = 0;
4827
4904
  applyTransform();
4828
4905
  },
@@ -5299,15 +5376,22 @@ var DocPlugin = class {
5299
5376
  if (totalPages > 1) {
5300
5377
  showPage(1);
5301
5378
  }
5302
- const calculateFitScale = () => {
5379
+ let fitMode = "width";
5380
+ const calculateFitScale = (mode = fitMode) => {
5303
5381
  const elW = 816;
5304
5382
  const elH = 1056;
5305
- const availW = Math.max(200, ctx.container.clientWidth - 48);
5306
- const availH = Math.max(200, ctx.container.clientHeight - 80);
5307
- return Math.min(1.1, Math.min(availW / elW, availH / elH));
5383
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
5384
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
5385
+ const sW = availW / elW;
5386
+ const sH = availH / elH;
5387
+ if (mode === "page") {
5388
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
5389
+ }
5390
+ return Math.max(0.65, Math.min(1.05, sW));
5308
5391
  };
5309
5392
  setTimeout(() => {
5310
- scale = calculateFitScale();
5393
+ fitMode = "width";
5394
+ scale = calculateFitScale("width");
5311
5395
  applyTransform();
5312
5396
  }, 60);
5313
5397
  const cleanup = () => {
@@ -5335,7 +5419,8 @@ var DocPlugin = class {
5335
5419
  applyTransform();
5336
5420
  },
5337
5421
  fitToPage: () => {
5338
- scale = calculateFitScale();
5422
+ fitMode = fitMode === "width" ? "page" : "width";
5423
+ scale = calculateFitScale(fitMode);
5339
5424
  rotation = 0;
5340
5425
  applyTransform();
5341
5426
  },