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