@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.cjs CHANGED
@@ -466,7 +466,8 @@ function createElement(tag, attrs, ...children) {
466
466
  }
467
467
  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>`;
468
468
  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>`;
469
- 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>`;
469
+ 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>`;
470
+ 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>`;
470
471
  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>`;
471
472
  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>`;
472
473
  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>`;
@@ -486,6 +487,7 @@ var ICON_MAP = {
486
487
  "zoom-in": ICON_ZOOM_IN,
487
488
  "zoom-out": ICON_ZOOM_OUT,
488
489
  "fit-page": ICON_FIT_PAGE,
490
+ "fit-width": ICON_FIT_WIDTH,
489
491
  "fit-slide": ICON_FIT_PAGE,
490
492
  "rotate-cw": ICON_ROTATE_CW,
491
493
  "rotate-ccw": ICON_ROTATE_CCW,
@@ -1432,6 +1434,7 @@ var PdfPlugin = class {
1432
1434
  let currentPage = 1;
1433
1435
  let zoomScale = 1;
1434
1436
  let rotation = 0;
1437
+ let fitMode = "width";
1435
1438
  let currentRenderTask = null;
1436
1439
  const renderPage = async (pageNum) => {
1437
1440
  if (currentRenderTask) {
@@ -1451,11 +1454,16 @@ var PdfPlugin = class {
1451
1454
  const containerWidth = container.clientWidth || 900;
1452
1455
  const containerHeight = container.clientHeight || 700;
1453
1456
  const unscaledVp = page.getViewport({ scale: 1, rotation });
1454
- const availWidth = Math.max(100, containerWidth - 48);
1455
- const availHeight = Math.max(100, containerHeight - 88);
1457
+ const availWidth = Math.max(280, containerWidth - 48);
1458
+ const availHeight = Math.max(280, containerHeight - 88);
1456
1459
  const scaleW = availWidth / unscaledVp.width;
1457
1460
  const scaleH = availHeight / unscaledVp.height;
1458
- const fitScale = Math.min(scaleW, scaleH);
1461
+ let fitScale;
1462
+ if (fitMode === "page") {
1463
+ fitScale = Math.max(0.5, Math.min(scaleW, scaleH));
1464
+ } else {
1465
+ fitScale = Math.max(0.65, Math.min(1.15, scaleW));
1466
+ }
1459
1467
  const effectiveScale = (fitScale > 0 ? fitScale : 1) * zoomScale;
1460
1468
  const pixelRatio = window.devicePixelRatio || 1;
1461
1469
  const viewport = page.getViewport({ scale: effectiveScale, rotation });
@@ -1524,6 +1532,7 @@ var PdfPlugin = class {
1524
1532
  renderPage(currentPage);
1525
1533
  },
1526
1534
  fitToPage: () => {
1535
+ fitMode = fitMode === "width" ? "page" : "width";
1527
1536
  zoomScale = 1;
1528
1537
  rotation = 0;
1529
1538
  renderPage(currentPage);
@@ -2077,8 +2086,53 @@ var DocxPlugin = class {
2077
2086
  }
2078
2087
  }
2079
2088
  }
2080
- const sections = wrapper.querySelectorAll("section.docx");
2081
- const cards = wrapper.querySelectorAll(".fp-docx-page-card");
2089
+ let sections = Array.from(wrapper.querySelectorAll("section.docx"));
2090
+ const cards = Array.from(wrapper.querySelectorAll(".fp-docx-page-card"));
2091
+ if (sections.length === 1 && cards.length === 0) {
2092
+ const singleSec = sections[0];
2093
+ const pageH = 1056;
2094
+ const secH = singleSec.offsetHeight || singleSec.scrollHeight;
2095
+ if (secH > pageH * 1.25) {
2096
+ const children = Array.from(singleSec.children);
2097
+ if (children.length > 1) {
2098
+ const parent = singleSec.parentElement || wrapper;
2099
+ const newSections = [singleSec];
2100
+ singleSec.innerHTML = "";
2101
+ singleSec.style.minHeight = `${pageH}px`;
2102
+ singleSec.style.maxHeight = `${pageH}px`;
2103
+ singleSec.style.overflow = "hidden";
2104
+ singleSec.style.boxSizing = "border-box";
2105
+ let curSec = singleSec;
2106
+ let curH = 0;
2107
+ const maxH = pageH - 96;
2108
+ for (let i = 0; i < children.length; i++) {
2109
+ const child = children[i];
2110
+ curSec.appendChild(child);
2111
+ const chH = child.offsetHeight || 28;
2112
+ curH += chH;
2113
+ if (curH >= maxH && i < children.length - 1) {
2114
+ const nextSec = document.createElement("section");
2115
+ nextSec.className = singleSec.className;
2116
+ nextSec.style.cssText = singleSec.style.cssText;
2117
+ nextSec.style.width = singleSec.style.width || "816px";
2118
+ nextSec.style.minHeight = `${pageH}px`;
2119
+ nextSec.style.maxHeight = `${pageH}px`;
2120
+ nextSec.style.overflow = "hidden";
2121
+ nextSec.style.boxSizing = "border-box";
2122
+ nextSec.style.backgroundColor = "#ffffff";
2123
+ nextSec.style.boxShadow = "0 4px 24px rgba(0, 0, 0, 0.08)";
2124
+ nextSec.style.borderRadius = "4px";
2125
+ nextSec.style.marginBottom = "24px";
2126
+ parent.appendChild(nextSec);
2127
+ newSections.push(nextSec);
2128
+ curSec = nextSec;
2129
+ curH = 0;
2130
+ }
2131
+ }
2132
+ sections = newSections;
2133
+ }
2134
+ }
2135
+ }
2082
2136
  const pageElements = sections.length > 0 ? sections : cards;
2083
2137
  const totalPages = Math.max(1, pageElements.length);
2084
2138
  let currentPage = 1;
@@ -2122,22 +2176,27 @@ var DocxPlugin = class {
2122
2176
  }
2123
2177
  scale = 1;
2124
2178
  let rotation = 0;
2125
- const calculateFitScale = () => {
2179
+ let fitMode = "width";
2180
+ const calculateFitScale = (mode = fitMode) => {
2126
2181
  const activeEl = pageElements[currentPage - 1] || wrapper.firstElementChild || wrapper;
2127
2182
  const elW = activeEl.offsetWidth || 816;
2128
- const elH = activeEl.offsetHeight || 1056;
2129
- const availW = Math.max(200, ctx.container.clientWidth - 48);
2130
- const availH = Math.max(200, ctx.container.clientHeight - 80);
2183
+ const singlePageH = Math.min(activeEl.offsetHeight || 1056, Math.round(elW * 1.32));
2184
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
2185
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
2131
2186
  const sW = availW / elW;
2132
- const sH = availH / elH;
2133
- return Math.min(1.1, Math.min(sW, sH));
2187
+ const sH = availH / singlePageH;
2188
+ if (mode === "page") {
2189
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
2190
+ }
2191
+ return Math.max(0.65, Math.min(1.05, sW));
2134
2192
  };
2135
2193
  const applyTransform = () => {
2136
2194
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
2137
2195
  wrapper.style.transformOrigin = "top center";
2138
2196
  };
2139
2197
  setTimeout(() => {
2140
- scale = calculateFitScale();
2198
+ fitMode = "width";
2199
+ scale = calculateFitScale("width");
2141
2200
  applyTransform();
2142
2201
  }, 60);
2143
2202
  const cleanup = () => {
@@ -2171,7 +2230,8 @@ var DocxPlugin = class {
2171
2230
  applyTransform();
2172
2231
  },
2173
2232
  fitToPage: () => {
2174
- scale = calculateFitScale();
2233
+ fitMode = fitMode === "width" ? "page" : "width";
2234
+ scale = calculateFitScale(fitMode);
2175
2235
  rotation = 0;
2176
2236
  applyTransform();
2177
2237
  },
@@ -2615,11 +2675,9 @@ var ExcelPlugin = class {
2615
2675
  const calculateFitScale = () => {
2616
2676
  const table = contentArea.querySelector("table");
2617
2677
  if (!table) return 1;
2618
- const availW = Math.max(200, container.clientWidth - 48);
2619
- const availH = Math.max(200, container.clientHeight - 80);
2678
+ const availW = Math.max(280, container.clientWidth - 48);
2620
2679
  const tW = table.offsetWidth || 800;
2621
- const tH = table.offsetHeight || 600;
2622
- return Math.min(1, Math.min(availW / tW, availH / tH));
2680
+ return Math.max(0.65, Math.min(1, availW / tW));
2623
2681
  };
2624
2682
  try {
2625
2683
  wb = XLSX__namespace.read(new Uint8Array(ctx.buffer), { type: "array", cellDates: true });
@@ -3216,7 +3274,7 @@ var CodePlugin = class {
3216
3274
  fitToPage: () => {
3217
3275
  fontSize = 13;
3218
3276
  rotation = 0;
3219
- zoomLevel = 1;
3277
+ zoomLevel = isTxt ? Math.max(0.65, Math.min(1.05, (container.clientWidth - 48) / 816)) : 1;
3220
3278
  updateTransform();
3221
3279
  },
3222
3280
  rotateCW: () => {
@@ -4198,20 +4256,27 @@ var RtfPlugin = class {
4198
4256
  let scale = 1;
4199
4257
  let rotation = 0;
4200
4258
  let pageElements = [];
4201
- const calculateFitScale = () => {
4259
+ let fitMode = "width";
4260
+ const calculateFitScale = (mode = fitMode) => {
4202
4261
  const activeEl = pageElements[currentPage - 1] || wrapper;
4203
4262
  const elW = activeEl.offsetWidth || 850;
4204
- const elH = activeEl.offsetHeight || 1e3;
4205
- const availW = Math.max(200, ctx.container.clientWidth - 48);
4206
- const availH = Math.max(200, ctx.container.clientHeight - 80);
4207
- return Math.min(1.1, Math.min(availW / elW, availH / elH));
4263
+ const singlePageH = Math.min(activeEl.offsetHeight || 1056, Math.round(elW * 1.32));
4264
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
4265
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
4266
+ const sW = availW / elW;
4267
+ const sH = availH / singlePageH;
4268
+ if (mode === "page") {
4269
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
4270
+ }
4271
+ return Math.max(0.65, Math.min(1.05, sW));
4208
4272
  };
4209
4273
  const applyTransform = () => {
4210
4274
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
4211
4275
  wrapper.style.transformOrigin = "top center";
4212
4276
  };
4213
4277
  setTimeout(() => {
4214
- scale = calculateFitScale();
4278
+ fitMode = "width";
4279
+ scale = calculateFitScale("width");
4215
4280
  applyTransform();
4216
4281
  }, 60);
4217
4282
  try {
@@ -4320,7 +4385,8 @@ var RtfPlugin = class {
4320
4385
  applyTransform();
4321
4386
  },
4322
4387
  fitToPage: () => {
4323
- scale = calculateFitScale();
4388
+ fitMode = fitMode === "width" ? "page" : "width";
4389
+ scale = calculateFitScale(fitMode);
4324
4390
  rotation = 0;
4325
4391
  applyTransform();
4326
4392
  },
@@ -4639,19 +4705,29 @@ var OpenDocumentPlugin = class {
4639
4705
  ctx.container.appendChild(container);
4640
4706
  let scale = 1;
4641
4707
  let rotation = 0;
4642
- const calculateFitScale = () => {
4708
+ let fitMode = "width";
4709
+ const calculateFitScale = (mode = fitMode) => {
4643
4710
  const elW = wrapper.offsetWidth || 850;
4644
- const elH = wrapper.offsetHeight || (isPresentation ? 540 : 1e3);
4645
- const availW = Math.max(200, ctx.container.clientWidth - 48);
4646
- const availH = Math.max(200, ctx.container.clientHeight - 80);
4647
- return Math.min(1, Math.min(availW / elW, availH / elH));
4711
+ const singlePageH = Math.min(wrapper.offsetHeight || 1056, Math.round(elW * 1.32));
4712
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
4713
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
4714
+ const sW = availW / elW;
4715
+ const sH = availH / (isPresentation ? 540 : singlePageH);
4716
+ if (isPresentation) {
4717
+ return Math.min(1, Math.min(sW, sH));
4718
+ }
4719
+ if (mode === "page") {
4720
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
4721
+ }
4722
+ return Math.max(0.65, Math.min(1.05, sW));
4648
4723
  };
4649
4724
  const applyTransform = () => {
4650
4725
  wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
4651
4726
  wrapper.style.transformOrigin = "top center";
4652
4727
  };
4653
4728
  setTimeout(() => {
4654
- scale = calculateFitScale();
4729
+ fitMode = "width";
4730
+ scale = calculateFitScale("width");
4655
4731
  applyTransform();
4656
4732
  }, 60);
4657
4733
  let currentPage = 1;
@@ -4812,7 +4888,8 @@ var OpenDocumentPlugin = class {
4812
4888
  applyTransform();
4813
4889
  },
4814
4890
  fitToPage: () => {
4815
- scale = calculateFitScale();
4891
+ fitMode = fitMode === "width" ? "page" : "width";
4892
+ scale = calculateFitScale(fitMode);
4816
4893
  rotation = 0;
4817
4894
  applyTransform();
4818
4895
  },
@@ -5289,15 +5366,22 @@ var DocPlugin = class {
5289
5366
  if (totalPages > 1) {
5290
5367
  showPage(1);
5291
5368
  }
5292
- const calculateFitScale = () => {
5369
+ let fitMode = "width";
5370
+ const calculateFitScale = (mode = fitMode) => {
5293
5371
  const elW = 816;
5294
5372
  const elH = 1056;
5295
- const availW = Math.max(200, ctx.container.clientWidth - 48);
5296
- const availH = Math.max(200, ctx.container.clientHeight - 80);
5297
- return Math.min(1.1, Math.min(availW / elW, availH / elH));
5373
+ const availW = Math.max(280, ctx.container.clientWidth - 48);
5374
+ const availH = Math.max(280, ctx.container.clientHeight - 80);
5375
+ const sW = availW / elW;
5376
+ const sH = availH / elH;
5377
+ if (mode === "page") {
5378
+ return Math.max(0.55, Math.min(1.15, Math.min(sW, sH)));
5379
+ }
5380
+ return Math.max(0.65, Math.min(1.05, sW));
5298
5381
  };
5299
5382
  setTimeout(() => {
5300
- scale = calculateFitScale();
5383
+ fitMode = "width";
5384
+ scale = calculateFitScale("width");
5301
5385
  applyTransform();
5302
5386
  }, 60);
5303
5387
  const cleanup = () => {
@@ -5325,7 +5409,8 @@ var DocPlugin = class {
5325
5409
  applyTransform();
5326
5410
  },
5327
5411
  fitToPage: () => {
5328
- scale = calculateFitScale();
5412
+ fitMode = fitMode === "width" ? "page" : "width";
5413
+ scale = calculateFitScale(fitMode);
5329
5414
  rotation = 0;
5330
5415
  applyTransform();
5331
5416
  },