@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/react.js CHANGED
@@ -434,7 +434,8 @@ function createElement(tag, attrs, ...children) {
434
434
  }
435
435
  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>`;
436
436
  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>`;
437
- 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>`;
437
+ 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>`;
438
+ 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>`;
438
439
  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>`;
439
440
  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>`;
440
441
  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>`;
@@ -454,6 +455,7 @@ var ICON_MAP = {
454
455
  "zoom-in": ICON_ZOOM_IN,
455
456
  "zoom-out": ICON_ZOOM_OUT,
456
457
  "fit-page": ICON_FIT_PAGE,
458
+ "fit-width": ICON_FIT_WIDTH,
457
459
  "fit-slide": ICON_FIT_PAGE,
458
460
  "rotate-cw": ICON_ROTATE_CW,
459
461
  "rotate-ccw": ICON_ROTATE_CCW,
@@ -1400,6 +1402,7 @@ var PdfPlugin = class {
1400
1402
  let currentPage = 1;
1401
1403
  let zoomScale = 1;
1402
1404
  let rotation = 0;
1405
+ let fitMode = "width";
1403
1406
  let currentRenderTask = null;
1404
1407
  const renderPage = async (pageNum) => {
1405
1408
  if (currentRenderTask) {
@@ -1419,11 +1422,16 @@ var PdfPlugin = class {
1419
1422
  const containerWidth = container.clientWidth || 900;
1420
1423
  const containerHeight = container.clientHeight || 700;
1421
1424
  const unscaledVp = page.getViewport({ scale: 1, rotation });
1422
- const availWidth = Math.max(100, containerWidth - 48);
1423
- const availHeight = Math.max(100, containerHeight - 88);
1425
+ const availWidth = Math.max(280, containerWidth - 48);
1426
+ const availHeight = Math.max(280, containerHeight - 88);
1424
1427
  const scaleW = availWidth / unscaledVp.width;
1425
1428
  const scaleH = availHeight / unscaledVp.height;
1426
- const fitScale = Math.min(scaleW, scaleH);
1429
+ let fitScale;
1430
+ if (fitMode === "page") {
1431
+ fitScale = Math.max(0.5, Math.min(scaleW, scaleH));
1432
+ } else {
1433
+ fitScale = Math.max(0.65, Math.min(1.15, scaleW));
1434
+ }
1427
1435
  const effectiveScale = (fitScale > 0 ? fitScale : 1) * zoomScale;
1428
1436
  const pixelRatio = window.devicePixelRatio || 1;
1429
1437
  const viewport = page.getViewport({ scale: effectiveScale, rotation });
@@ -1492,6 +1500,7 @@ var PdfPlugin = class {
1492
1500
  renderPage(currentPage);
1493
1501
  },
1494
1502
  fitToPage: () => {
1503
+ fitMode = fitMode === "width" ? "page" : "width";
1495
1504
  zoomScale = 1;
1496
1505
  rotation = 0;
1497
1506
  renderPage(currentPage);
@@ -2045,8 +2054,53 @@ var DocxPlugin = class {
2045
2054
  }
2046
2055
  }
2047
2056
  }
2048
- const sections = wrapper.querySelectorAll("section.docx");
2049
- const cards = wrapper.querySelectorAll(".fp-docx-page-card");
2057
+ let sections = Array.from(wrapper.querySelectorAll("section.docx"));
2058
+ const cards = Array.from(wrapper.querySelectorAll(".fp-docx-page-card"));
2059
+ if (sections.length === 1 && cards.length === 0) {
2060
+ const singleSec = sections[0];
2061
+ const pageH = 1056;
2062
+ const secH = singleSec.offsetHeight || singleSec.scrollHeight;
2063
+ if (secH > pageH * 1.25) {
2064
+ const children = Array.from(singleSec.children);
2065
+ if (children.length > 1) {
2066
+ const parent = singleSec.parentElement || wrapper;
2067
+ const newSections = [singleSec];
2068
+ singleSec.innerHTML = "";
2069
+ singleSec.style.minHeight = `${pageH}px`;
2070
+ singleSec.style.maxHeight = `${pageH}px`;
2071
+ singleSec.style.overflow = "hidden";
2072
+ singleSec.style.boxSizing = "border-box";
2073
+ let curSec = singleSec;
2074
+ let curH = 0;
2075
+ const maxH = pageH - 96;
2076
+ for (let i = 0; i < children.length; i++) {
2077
+ const child = children[i];
2078
+ curSec.appendChild(child);
2079
+ const chH = child.offsetHeight || 28;
2080
+ curH += chH;
2081
+ if (curH >= maxH && i < children.length - 1) {
2082
+ const nextSec = document.createElement("section");
2083
+ nextSec.className = singleSec.className;
2084
+ nextSec.style.cssText = singleSec.style.cssText;
2085
+ nextSec.style.width = singleSec.style.width || "816px";
2086
+ nextSec.style.minHeight = `${pageH}px`;
2087
+ nextSec.style.maxHeight = `${pageH}px`;
2088
+ nextSec.style.overflow = "hidden";
2089
+ nextSec.style.boxSizing = "border-box";
2090
+ nextSec.style.backgroundColor = "#ffffff";
2091
+ nextSec.style.boxShadow = "0 4px 24px rgba(0, 0, 0, 0.08)";
2092
+ nextSec.style.borderRadius = "4px";
2093
+ nextSec.style.marginBottom = "24px";
2094
+ parent.appendChild(nextSec);
2095
+ newSections.push(nextSec);
2096
+ curSec = nextSec;
2097
+ curH = 0;
2098
+ }
2099
+ }
2100
+ sections = newSections;
2101
+ }
2102
+ }
2103
+ }
2050
2104
  const pageElements = sections.length > 0 ? sections : cards;
2051
2105
  const totalPages = Math.max(1, pageElements.length);
2052
2106
  let currentPage = 1;
@@ -2090,22 +2144,27 @@ var DocxPlugin = class {
2090
2144
  }
2091
2145
  scale = 1;
2092
2146
  let rotation = 0;
2093
- const calculateFitScale = () => {
2147
+ let fitMode = "width";
2148
+ const calculateFitScale = (mode = fitMode) => {
2094
2149
  const activeEl = pageElements[currentPage - 1] || wrapper.firstElementChild || wrapper;
2095
2150
  const elW = activeEl.offsetWidth || 816;
2096
- const elH = activeEl.offsetHeight || 1056;
2097
- const availW = Math.max(200, ctx.container.clientWidth - 48);
2098
- const availH = Math.max(200, ctx.container.clientHeight - 80);
2151
+ const singlePageH = Math.min(activeEl.offsetHeight || 1056, Math.round(elW * 1.32));
2152
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
2153
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
2099
2154
  const sW = availW / elW;
2100
- const sH = availH / elH;
2101
- return Math.min(1.1, Math.min(sW, sH));
2155
+ const sH = availH / singlePageH;
2156
+ if (mode === "page") {
2157
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
2158
+ }
2159
+ return Math.max(0.65, Math.min(1.05, sW));
2102
2160
  };
2103
2161
  const applyTransform = () => {
2104
2162
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
2105
2163
  wrapper.style.transformOrigin = "top center";
2106
2164
  };
2107
2165
  setTimeout(() => {
2108
- scale = calculateFitScale();
2166
+ fitMode = "width";
2167
+ scale = calculateFitScale("width");
2109
2168
  applyTransform();
2110
2169
  }, 60);
2111
2170
  const cleanup = () => {
@@ -2139,7 +2198,8 @@ var DocxPlugin = class {
2139
2198
  applyTransform();
2140
2199
  },
2141
2200
  fitToPage: () => {
2142
- scale = calculateFitScale();
2201
+ fitMode = fitMode === "width" ? "page" : "width";
2202
+ scale = calculateFitScale(fitMode);
2143
2203
  rotation = 0;
2144
2204
  applyTransform();
2145
2205
  },
@@ -2583,11 +2643,9 @@ var ExcelPlugin = class {
2583
2643
  const calculateFitScale = () => {
2584
2644
  const table = contentArea.querySelector("table");
2585
2645
  if (!table) return 1;
2586
- const availW = Math.max(200, container.clientWidth - 48);
2587
- const availH = Math.max(200, container.clientHeight - 80);
2646
+ const availW = Math.max(280, container.clientWidth - 48);
2588
2647
  const tW = table.offsetWidth || 800;
2589
- const tH = table.offsetHeight || 600;
2590
- return Math.min(1, Math.min(availW / tW, availH / tH));
2648
+ return Math.max(0.65, Math.min(1, availW / tW));
2591
2649
  };
2592
2650
  try {
2593
2651
  wb = XLSX.read(new Uint8Array(ctx.buffer), { type: "array", cellDates: true });
@@ -3184,7 +3242,7 @@ var CodePlugin = class {
3184
3242
  fitToPage: () => {
3185
3243
  fontSize = 13;
3186
3244
  rotation = 0;
3187
- zoomLevel = 1;
3245
+ zoomLevel = isTxt ? Math.max(0.65, Math.min(1.05, (container.clientWidth - 48) / 816)) : 1;
3188
3246
  updateTransform();
3189
3247
  },
3190
3248
  rotateCW: () => {
@@ -4166,20 +4224,27 @@ var RtfPlugin = class {
4166
4224
  let scale = 1;
4167
4225
  let rotation = 0;
4168
4226
  let pageElements = [];
4169
- const calculateFitScale = () => {
4227
+ let fitMode = "width";
4228
+ const calculateFitScale = (mode = fitMode) => {
4170
4229
  const activeEl = pageElements[currentPage - 1] || wrapper;
4171
4230
  const elW = activeEl.offsetWidth || 850;
4172
- const elH = activeEl.offsetHeight || 1e3;
4173
- const availW = Math.max(200, ctx.container.clientWidth - 48);
4174
- const availH = Math.max(200, ctx.container.clientHeight - 80);
4175
- return Math.min(1.1, Math.min(availW / elW, availH / elH));
4231
+ const singlePageH = Math.min(activeEl.offsetHeight || 1056, Math.round(elW * 1.32));
4232
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
4233
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
4234
+ const sW = availW / elW;
4235
+ const sH = availH / singlePageH;
4236
+ if (mode === "page") {
4237
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
4238
+ }
4239
+ return Math.max(0.65, Math.min(1.05, sW));
4176
4240
  };
4177
4241
  const applyTransform = () => {
4178
4242
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
4179
4243
  wrapper.style.transformOrigin = "top center";
4180
4244
  };
4181
4245
  setTimeout(() => {
4182
- scale = calculateFitScale();
4246
+ fitMode = "width";
4247
+ scale = calculateFitScale("width");
4183
4248
  applyTransform();
4184
4249
  }, 60);
4185
4250
  try {
@@ -4288,7 +4353,8 @@ var RtfPlugin = class {
4288
4353
  applyTransform();
4289
4354
  },
4290
4355
  fitToPage: () => {
4291
- scale = calculateFitScale();
4356
+ fitMode = fitMode === "width" ? "page" : "width";
4357
+ scale = calculateFitScale(fitMode);
4292
4358
  rotation = 0;
4293
4359
  applyTransform();
4294
4360
  },
@@ -4607,19 +4673,29 @@ var OpenDocumentPlugin = class {
4607
4673
  ctx.container.appendChild(container);
4608
4674
  let scale = 1;
4609
4675
  let rotation = 0;
4610
- const calculateFitScale = () => {
4676
+ let fitMode = "width";
4677
+ const calculateFitScale = (mode = fitMode) => {
4611
4678
  const elW = wrapper.offsetWidth || 850;
4612
- const elH = wrapper.offsetHeight || (isPresentation ? 540 : 1e3);
4613
- const availW = Math.max(200, ctx.container.clientWidth - 48);
4614
- const availH = Math.max(200, ctx.container.clientHeight - 80);
4615
- return Math.min(1, Math.min(availW / elW, availH / elH));
4679
+ const singlePageH = Math.min(wrapper.offsetHeight || 1056, Math.round(elW * 1.32));
4680
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
4681
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
4682
+ const sW = availW / elW;
4683
+ const sH = availH / (isPresentation ? 540 : singlePageH);
4684
+ if (isPresentation) {
4685
+ return Math.min(1, Math.min(sW, sH));
4686
+ }
4687
+ if (mode === "page") {
4688
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
4689
+ }
4690
+ return Math.max(0.65, Math.min(1.05, sW));
4616
4691
  };
4617
4692
  const applyTransform = () => {
4618
4693
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
4619
4694
  wrapper.style.transformOrigin = "top center";
4620
4695
  };
4621
4696
  setTimeout(() => {
4622
- scale = calculateFitScale();
4697
+ fitMode = "width";
4698
+ scale = calculateFitScale("width");
4623
4699
  applyTransform();
4624
4700
  }, 60);
4625
4701
  let currentPage = 1;
@@ -4780,7 +4856,8 @@ var OpenDocumentPlugin = class {
4780
4856
  applyTransform();
4781
4857
  },
4782
4858
  fitToPage: () => {
4783
- scale = calculateFitScale();
4859
+ fitMode = fitMode === "width" ? "page" : "width";
4860
+ scale = calculateFitScale(fitMode);
4784
4861
  rotation = 0;
4785
4862
  applyTransform();
4786
4863
  },
@@ -5257,15 +5334,22 @@ var DocPlugin = class {
5257
5334
  if (totalPages > 1) {
5258
5335
  showPage(1);
5259
5336
  }
5260
- const calculateFitScale = () => {
5337
+ let fitMode = "width";
5338
+ const calculateFitScale = (mode = fitMode) => {
5261
5339
  const elW = 816;
5262
5340
  const elH = 1056;
5263
- const availW = Math.max(200, ctx.container.clientWidth - 48);
5264
- const availH = Math.max(200, ctx.container.clientHeight - 80);
5265
- return Math.min(1.1, Math.min(availW / elW, availH / elH));
5341
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
5342
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
5343
+ const sW = availW / elW;
5344
+ const sH = availH / elH;
5345
+ if (mode === "page") {
5346
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
5347
+ }
5348
+ return Math.max(0.65, Math.min(1.05, sW));
5266
5349
  };
5267
5350
  setTimeout(() => {
5268
- scale = calculateFitScale();
5351
+ fitMode = "width";
5352
+ scale = calculateFitScale("width");
5269
5353
  applyTransform();
5270
5354
  }, 60);
5271
5355
  const cleanup = () => {
@@ -5293,7 +5377,8 @@ var DocPlugin = class {
5293
5377
  applyTransform();
5294
5378
  },
5295
5379
  fitToPage: () => {
5296
- scale = calculateFitScale();
5380
+ fitMode = fitMode === "width" ? "page" : "width";
5381
+ scale = calculateFitScale(fitMode);
5297
5382
  rotation = 0;
5298
5383
  applyTransform();
5299
5384
  },