@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.cjs CHANGED
@@ -5415,6 +5415,24 @@ function renderRtfTableElement(table) {
5415
5415
  tableEl.appendChild(tbody);
5416
5416
  return tableEl;
5417
5417
  }
5418
+ function extractMediaFingerprint(el) {
5419
+ const img = el.tagName.toLowerCase() === "img" ? el : el.querySelector("img");
5420
+ if (img && img.src) {
5421
+ const s = img.src;
5422
+ return s.length > 300 ? `img_${s.slice(0, 80)}_${s.length}_${s.slice(-80)}` : `img_${s}`;
5423
+ }
5424
+ const innerImg = el.querySelector("image");
5425
+ if (innerImg) {
5426
+ const h = innerImg.getAttribute("xlink:href") || innerImg.getAttribute("href") || "";
5427
+ if (h) return h.length > 300 ? `svgimg_${h.slice(0, 80)}_${h.length}_${h.slice(-80)}` : `svgimg_${h}`;
5428
+ }
5429
+ const svg = el.tagName.toLowerCase() === "svg" ? el : el.querySelector("svg");
5430
+ if (svg) {
5431
+ const vb = svg.getAttribute("viewBox") || "";
5432
+ return `svg_${vb}_${svg.innerHTML.length}`;
5433
+ }
5434
+ return null;
5435
+ }
5418
5436
  var RtfPlugin = class {
5419
5437
  id = "rtf";
5420
5438
  name = "Rich Text Format (RTF)";
@@ -5587,9 +5605,27 @@ var RtfPlugin = class {
5587
5605
  }
5588
5606
  const rawText = new TextDecoder("latin1").decode(ctx.buffer);
5589
5607
  const tables = parseRtfTables(rawText);
5590
- const doc = new RTFJS__namespace.Document(ctx.buffer, {});
5608
+ const seenMediaSignatures = /* @__PURE__ */ new Set();
5609
+ const doc = new RTFJS__namespace.Document(ctx.buffer, {
5610
+ onPicture: (isLegacy, createPic) => {
5611
+ if (isLegacy === true) {
5612
+ return null;
5613
+ }
5614
+ const pic = createPic();
5615
+ if (!pic) return null;
5616
+ const fp = extractMediaFingerprint(pic);
5617
+ if (fp) {
5618
+ if (seenMediaSignatures.has(fp)) {
5619
+ return null;
5620
+ }
5621
+ seenMediaSignatures.add(fp);
5622
+ }
5623
+ return pic;
5624
+ }
5625
+ });
5591
5626
  const htmlElements = await doc.render();
5592
5627
  const contentNodes = [];
5628
+ const seenInContentBlocks = /* @__PURE__ */ new Set();
5593
5629
  const extractBlocks = (nodes) => {
5594
5630
  for (const item of nodes) {
5595
5631
  if (!item || !(item instanceof HTMLElement)) continue;
@@ -5601,6 +5637,18 @@ var RtfPlugin = class {
5601
5637
  if (hasChildBlocks && !["table", "tr", "td", "th", "ul", "ol", "li"].includes(tag)) {
5602
5638
  extractBlocks(Array.from(item.children));
5603
5639
  } else {
5640
+ const fp = extractMediaFingerprint(item);
5641
+ if (fp) {
5642
+ if (seenInContentBlocks.has(fp)) {
5643
+ continue;
5644
+ }
5645
+ seenInContentBlocks.add(fp);
5646
+ }
5647
+ const hasMedia = item.querySelector("img, svg, canvas, table") !== null || ["img", "svg", "table"].includes(tag);
5648
+ const textContent = (item.textContent || "").trim();
5649
+ if (!hasMedia && textContent.length === 0) {
5650
+ continue;
5651
+ }
5604
5652
  const svgs = item.querySelectorAll("svg, img");
5605
5653
  svgs.forEach((s) => {
5606
5654
  const el = s;
@@ -5656,38 +5704,59 @@ var RtfPlugin = class {
5656
5704
  }
5657
5705
  }
5658
5706
  });
5659
- wrapper.innerHTML = "";
5660
- contentNodes.forEach((node) => wrapper.appendChild(node));
5661
- const childHeights = contentNodes.map((c) => {
5662
- const rectH = c.getBoundingClientRect ? c.getBoundingClientRect().height : 0;
5663
- const offH = c.offsetHeight || 0;
5664
- const realH = Math.max(rectH, offH);
5665
- if (realH > 0) return realH;
5666
- const textLen = c.textContent?.trim().length || 0;
5667
- return Math.max(24, Math.ceil(textLen / 95) * 22 + 12);
5668
- });
5669
- wrapper.innerHTML = "";
5670
- const createRtfCard = () => {
5707
+ const createRtfCard = (pageNum) => {
5671
5708
  const card = document.createElement("div");
5672
5709
  card.className = "fp-rtf-page-card";
5710
+ card.setAttribute("data-page-number", String(pageNum));
5673
5711
  card.style.backgroundColor = "#ffffff";
5674
- card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08)";
5712
+ card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04)";
5675
5713
  card.style.borderRadius = "4px";
5676
5714
  card.style.padding = "64px 56px";
5677
5715
  card.style.width = "816px";
5678
5716
  card.style.minHeight = "1056px";
5717
+ card.style.maxHeight = "1056px";
5718
+ card.style.overflow = "hidden";
5679
5719
  card.style.boxSizing = "border-box";
5680
5720
  card.style.marginBottom = "24px";
5681
5721
  card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
5682
5722
  card.style.lineHeight = "1.6";
5683
5723
  card.style.color = "#1e293b";
5724
+ card.style.position = "relative";
5684
5725
  return card;
5685
5726
  };
5686
- let curCard = createRtfCard();
5727
+ wrapper.innerHTML = "";
5728
+ const measureCard = createRtfCard(0);
5729
+ measureCard.style.maxHeight = "none";
5730
+ measureCard.style.height = "auto";
5731
+ wrapper.appendChild(measureCard);
5732
+ contentNodes.forEach((node) => measureCard.appendChild(node));
5733
+ const childHeights = contentNodes.map((c) => {
5734
+ const rect = c.getBoundingClientRect ? c.getBoundingClientRect() : null;
5735
+ const rectH = rect ? rect.height : 0;
5736
+ const offH = c.offsetHeight || 0;
5737
+ let realH = Math.max(rectH, offH);
5738
+ try {
5739
+ const cs = window.getComputedStyle(c);
5740
+ realH += (parseFloat(cs.marginTop) || 0) + (parseFloat(cs.marginBottom) || 0);
5741
+ } catch {
5742
+ }
5743
+ const hasMedia = c.querySelector("img, svg") !== null || ["img", "svg"].includes(c.tagName.toLowerCase());
5744
+ const hasTable = c.querySelector("table") !== null || c.tagName.toLowerCase() === "table";
5745
+ if (hasMedia) {
5746
+ realH = Math.max(realH, 300);
5747
+ } else if (hasTable) {
5748
+ realH = Math.max(realH, 240);
5749
+ }
5750
+ if (realH > 0) return realH;
5751
+ const textLen = c.textContent?.trim().length || 0;
5752
+ return Math.max(28, Math.ceil(textLen / 75) * 26 + 16);
5753
+ });
5754
+ wrapper.innerHTML = "";
5755
+ let curCard = createRtfCard(1);
5687
5756
  wrapper.appendChild(curCard);
5688
5757
  pageElements = [curCard];
5689
5758
  let curH = 0;
5690
- const maxH = 928;
5759
+ const maxH = 860;
5691
5760
  for (let i = 0; i < contentNodes.length; i++) {
5692
5761
  const child = contentNodes[i];
5693
5762
  const chH = childHeights[i];
@@ -5695,8 +5764,10 @@ var RtfPlugin = class {
5695
5764
  if (curH === 0 && isChildEmpty) {
5696
5765
  continue;
5697
5766
  }
5698
- if (curH + chH > maxH && curCard.childNodes.length > 0) {
5699
- curCard = createRtfCard();
5767
+ const isTable = child.querySelector("table") !== null || child.tagName.toLowerCase() === "table";
5768
+ const shouldBreakBeforeTable = isTable && curH > 400 && curCard.childNodes.length > 0;
5769
+ if ((curH + chH > maxH || shouldBreakBeforeTable) && curCard.childNodes.length > 0) {
5770
+ curCard = createRtfCard(pageElements.length + 1);
5700
5771
  wrapper.appendChild(curCard);
5701
5772
  pageElements.push(curCard);
5702
5773
  curH = 0;