@files-preview-app/preview-file 1.3.3 → 1.3.4

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
@@ -5382,6 +5382,24 @@ function renderRtfTableElement(table) {
5382
5382
  tableEl.appendChild(tbody);
5383
5383
  return tableEl;
5384
5384
  }
5385
+ function extractMediaFingerprint(el) {
5386
+ const img = el.tagName.toLowerCase() === "img" ? el : el.querySelector("img");
5387
+ if (img && img.src) {
5388
+ const s = img.src;
5389
+ return s.length > 300 ? `img_${s.slice(0, 80)}_${s.length}_${s.slice(-80)}` : `img_${s}`;
5390
+ }
5391
+ const innerImg = el.querySelector("image");
5392
+ if (innerImg) {
5393
+ const h = innerImg.getAttribute("xlink:href") || innerImg.getAttribute("href") || "";
5394
+ if (h) return h.length > 300 ? `svgimg_${h.slice(0, 80)}_${h.length}_${h.slice(-80)}` : `svgimg_${h}`;
5395
+ }
5396
+ const svg = el.tagName.toLowerCase() === "svg" ? el : el.querySelector("svg");
5397
+ if (svg) {
5398
+ const vb = svg.getAttribute("viewBox") || "";
5399
+ return `svg_${vb}_${svg.innerHTML.length}`;
5400
+ }
5401
+ return null;
5402
+ }
5385
5403
  var RtfPlugin = class {
5386
5404
  id = "rtf";
5387
5405
  name = "Rich Text Format (RTF)";
@@ -5554,9 +5572,27 @@ var RtfPlugin = class {
5554
5572
  }
5555
5573
  const rawText = new TextDecoder("latin1").decode(ctx.buffer);
5556
5574
  const tables = parseRtfTables(rawText);
5557
- const doc = new RTFJS.Document(ctx.buffer, {});
5575
+ const seenMediaSignatures = /* @__PURE__ */ new Set();
5576
+ const doc = new RTFJS.Document(ctx.buffer, {
5577
+ onPicture: (isLegacy, createPic) => {
5578
+ if (isLegacy === true) {
5579
+ return null;
5580
+ }
5581
+ const pic = createPic();
5582
+ if (!pic) return null;
5583
+ const fp = extractMediaFingerprint(pic);
5584
+ if (fp) {
5585
+ if (seenMediaSignatures.has(fp)) {
5586
+ return null;
5587
+ }
5588
+ seenMediaSignatures.add(fp);
5589
+ }
5590
+ return pic;
5591
+ }
5592
+ });
5558
5593
  const htmlElements = await doc.render();
5559
5594
  const contentNodes = [];
5595
+ const seenInContentBlocks = /* @__PURE__ */ new Set();
5560
5596
  const extractBlocks = (nodes) => {
5561
5597
  for (const item of nodes) {
5562
5598
  if (!item || !(item instanceof HTMLElement)) continue;
@@ -5568,6 +5604,18 @@ var RtfPlugin = class {
5568
5604
  if (hasChildBlocks && !["table", "tr", "td", "th", "ul", "ol", "li"].includes(tag)) {
5569
5605
  extractBlocks(Array.from(item.children));
5570
5606
  } else {
5607
+ const fp = extractMediaFingerprint(item);
5608
+ if (fp) {
5609
+ if (seenInContentBlocks.has(fp)) {
5610
+ continue;
5611
+ }
5612
+ seenInContentBlocks.add(fp);
5613
+ }
5614
+ const hasMedia = item.querySelector("img, svg, canvas, table") !== null || ["img", "svg", "table"].includes(tag);
5615
+ const textContent = (item.textContent || "").trim();
5616
+ if (!hasMedia && textContent.length === 0) {
5617
+ continue;
5618
+ }
5571
5619
  const svgs = item.querySelectorAll("svg, img");
5572
5620
  svgs.forEach((s) => {
5573
5621
  const el = s;
@@ -5623,38 +5671,59 @@ var RtfPlugin = class {
5623
5671
  }
5624
5672
  }
5625
5673
  });
5626
- wrapper.innerHTML = "";
5627
- contentNodes.forEach((node) => wrapper.appendChild(node));
5628
- const childHeights = contentNodes.map((c) => {
5629
- const rectH = c.getBoundingClientRect ? c.getBoundingClientRect().height : 0;
5630
- const offH = c.offsetHeight || 0;
5631
- const realH = Math.max(rectH, offH);
5632
- if (realH > 0) return realH;
5633
- const textLen = c.textContent?.trim().length || 0;
5634
- return Math.max(24, Math.ceil(textLen / 95) * 22 + 12);
5635
- });
5636
- wrapper.innerHTML = "";
5637
- const createRtfCard = () => {
5674
+ const createRtfCard = (pageNum) => {
5638
5675
  const card = document.createElement("div");
5639
5676
  card.className = "fp-rtf-page-card";
5677
+ card.setAttribute("data-page-number", String(pageNum));
5640
5678
  card.style.backgroundColor = "#ffffff";
5641
- card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08)";
5679
+ card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04)";
5642
5680
  card.style.borderRadius = "4px";
5643
5681
  card.style.padding = "64px 56px";
5644
5682
  card.style.width = "816px";
5645
5683
  card.style.minHeight = "1056px";
5684
+ card.style.maxHeight = "1056px";
5685
+ card.style.overflow = "hidden";
5646
5686
  card.style.boxSizing = "border-box";
5647
5687
  card.style.marginBottom = "24px";
5648
5688
  card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
5649
5689
  card.style.lineHeight = "1.6";
5650
5690
  card.style.color = "#1e293b";
5691
+ card.style.position = "relative";
5651
5692
  return card;
5652
5693
  };
5653
- let curCard = createRtfCard();
5694
+ wrapper.innerHTML = "";
5695
+ const measureCard = createRtfCard(0);
5696
+ measureCard.style.maxHeight = "none";
5697
+ measureCard.style.height = "auto";
5698
+ wrapper.appendChild(measureCard);
5699
+ contentNodes.forEach((node) => measureCard.appendChild(node));
5700
+ const childHeights = contentNodes.map((c) => {
5701
+ const rect = c.getBoundingClientRect ? c.getBoundingClientRect() : null;
5702
+ const rectH = rect ? rect.height : 0;
5703
+ const offH = c.offsetHeight || 0;
5704
+ let realH = Math.max(rectH, offH);
5705
+ try {
5706
+ const cs = window.getComputedStyle(c);
5707
+ realH += (parseFloat(cs.marginTop) || 0) + (parseFloat(cs.marginBottom) || 0);
5708
+ } catch {
5709
+ }
5710
+ const hasMedia = c.querySelector("img, svg") !== null || ["img", "svg"].includes(c.tagName.toLowerCase());
5711
+ const hasTable = c.querySelector("table") !== null || c.tagName.toLowerCase() === "table";
5712
+ if (hasMedia) {
5713
+ realH = Math.max(realH, 300);
5714
+ } else if (hasTable) {
5715
+ realH = Math.max(realH, 240);
5716
+ }
5717
+ if (realH > 0) return realH;
5718
+ const textLen = c.textContent?.trim().length || 0;
5719
+ return Math.max(28, Math.ceil(textLen / 75) * 26 + 16);
5720
+ });
5721
+ wrapper.innerHTML = "";
5722
+ let curCard = createRtfCard(1);
5654
5723
  wrapper.appendChild(curCard);
5655
5724
  pageElements = [curCard];
5656
5725
  let curH = 0;
5657
- const maxH = 928;
5726
+ const maxH = 860;
5658
5727
  for (let i = 0; i < contentNodes.length; i++) {
5659
5728
  const child = contentNodes[i];
5660
5729
  const chH = childHeights[i];
@@ -5662,8 +5731,10 @@ var RtfPlugin = class {
5662
5731
  if (curH === 0 && isChildEmpty) {
5663
5732
  continue;
5664
5733
  }
5665
- if (curH + chH > maxH && curCard.childNodes.length > 0) {
5666
- curCard = createRtfCard();
5734
+ const isTable = child.querySelector("table") !== null || child.tagName.toLowerCase() === "table";
5735
+ const shouldBreakBeforeTable = isTable && curH > 400 && curCard.childNodes.length > 0;
5736
+ if ((curH + chH > maxH || shouldBreakBeforeTable) && curCard.childNodes.length > 0) {
5737
+ curCard = createRtfCard(pageElements.length + 1);
5667
5738
  wrapper.appendChild(curCard);
5668
5739
  pageElements.push(curCard);
5669
5740
  curH = 0;