@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/angular.cjs CHANGED
@@ -5462,6 +5462,24 @@ function renderRtfTableElement(table) {
5462
5462
  tableEl.appendChild(tbody);
5463
5463
  return tableEl;
5464
5464
  }
5465
+ function extractMediaFingerprint(el) {
5466
+ const img = el.tagName.toLowerCase() === "img" ? el : el.querySelector("img");
5467
+ if (img && img.src) {
5468
+ const s = img.src;
5469
+ return s.length > 300 ? `img_${s.slice(0, 80)}_${s.length}_${s.slice(-80)}` : `img_${s}`;
5470
+ }
5471
+ const innerImg = el.querySelector("image");
5472
+ if (innerImg) {
5473
+ const h = innerImg.getAttribute("xlink:href") || innerImg.getAttribute("href") || "";
5474
+ if (h) return h.length > 300 ? `svgimg_${h.slice(0, 80)}_${h.length}_${h.slice(-80)}` : `svgimg_${h}`;
5475
+ }
5476
+ const svg = el.tagName.toLowerCase() === "svg" ? el : el.querySelector("svg");
5477
+ if (svg) {
5478
+ const vb = svg.getAttribute("viewBox") || "";
5479
+ return `svg_${vb}_${svg.innerHTML.length}`;
5480
+ }
5481
+ return null;
5482
+ }
5465
5483
  var RtfPlugin = class {
5466
5484
  id = "rtf";
5467
5485
  name = "Rich Text Format (RTF)";
@@ -5634,9 +5652,27 @@ var RtfPlugin = class {
5634
5652
  }
5635
5653
  const rawText = new TextDecoder("latin1").decode(ctx.buffer);
5636
5654
  const tables = parseRtfTables(rawText);
5637
- const doc = new RTFJS__namespace.Document(ctx.buffer, {});
5655
+ const seenMediaSignatures = /* @__PURE__ */ new Set();
5656
+ const doc = new RTFJS__namespace.Document(ctx.buffer, {
5657
+ onPicture: (isLegacy, createPic) => {
5658
+ if (isLegacy === true) {
5659
+ return null;
5660
+ }
5661
+ const pic = createPic();
5662
+ if (!pic) return null;
5663
+ const fp = extractMediaFingerprint(pic);
5664
+ if (fp) {
5665
+ if (seenMediaSignatures.has(fp)) {
5666
+ return null;
5667
+ }
5668
+ seenMediaSignatures.add(fp);
5669
+ }
5670
+ return pic;
5671
+ }
5672
+ });
5638
5673
  const htmlElements = await doc.render();
5639
5674
  const contentNodes = [];
5675
+ const seenInContentBlocks = /* @__PURE__ */ new Set();
5640
5676
  const extractBlocks = (nodes) => {
5641
5677
  for (const item of nodes) {
5642
5678
  if (!item || !(item instanceof HTMLElement)) continue;
@@ -5648,6 +5684,18 @@ var RtfPlugin = class {
5648
5684
  if (hasChildBlocks && !["table", "tr", "td", "th", "ul", "ol", "li"].includes(tag)) {
5649
5685
  extractBlocks(Array.from(item.children));
5650
5686
  } else {
5687
+ const fp = extractMediaFingerprint(item);
5688
+ if (fp) {
5689
+ if (seenInContentBlocks.has(fp)) {
5690
+ continue;
5691
+ }
5692
+ seenInContentBlocks.add(fp);
5693
+ }
5694
+ const hasMedia = item.querySelector("img, svg, canvas, table") !== null || ["img", "svg", "table"].includes(tag);
5695
+ const textContent = (item.textContent || "").trim();
5696
+ if (!hasMedia && textContent.length === 0) {
5697
+ continue;
5698
+ }
5651
5699
  const svgs = item.querySelectorAll("svg, img");
5652
5700
  svgs.forEach((s) => {
5653
5701
  const el = s;
@@ -5703,38 +5751,59 @@ var RtfPlugin = class {
5703
5751
  }
5704
5752
  }
5705
5753
  });
5706
- wrapper.innerHTML = "";
5707
- contentNodes.forEach((node) => wrapper.appendChild(node));
5708
- const childHeights = contentNodes.map((c) => {
5709
- const rectH = c.getBoundingClientRect ? c.getBoundingClientRect().height : 0;
5710
- const offH = c.offsetHeight || 0;
5711
- const realH = Math.max(rectH, offH);
5712
- if (realH > 0) return realH;
5713
- const textLen = c.textContent?.trim().length || 0;
5714
- return Math.max(24, Math.ceil(textLen / 95) * 22 + 12);
5715
- });
5716
- wrapper.innerHTML = "";
5717
- const createRtfCard = () => {
5754
+ const createRtfCard = (pageNum) => {
5718
5755
  const card = document.createElement("div");
5719
5756
  card.className = "fp-rtf-page-card";
5757
+ card.setAttribute("data-page-number", String(pageNum));
5720
5758
  card.style.backgroundColor = "#ffffff";
5721
- card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08)";
5759
+ card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04)";
5722
5760
  card.style.borderRadius = "4px";
5723
5761
  card.style.padding = "64px 56px";
5724
5762
  card.style.width = "816px";
5725
5763
  card.style.minHeight = "1056px";
5764
+ card.style.maxHeight = "1056px";
5765
+ card.style.overflow = "hidden";
5726
5766
  card.style.boxSizing = "border-box";
5727
5767
  card.style.marginBottom = "24px";
5728
5768
  card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
5729
5769
  card.style.lineHeight = "1.6";
5730
5770
  card.style.color = "#1e293b";
5771
+ card.style.position = "relative";
5731
5772
  return card;
5732
5773
  };
5733
- let curCard = createRtfCard();
5774
+ wrapper.innerHTML = "";
5775
+ const measureCard = createRtfCard(0);
5776
+ measureCard.style.maxHeight = "none";
5777
+ measureCard.style.height = "auto";
5778
+ wrapper.appendChild(measureCard);
5779
+ contentNodes.forEach((node) => measureCard.appendChild(node));
5780
+ const childHeights = contentNodes.map((c) => {
5781
+ const rect = c.getBoundingClientRect ? c.getBoundingClientRect() : null;
5782
+ const rectH = rect ? rect.height : 0;
5783
+ const offH = c.offsetHeight || 0;
5784
+ let realH = Math.max(rectH, offH);
5785
+ try {
5786
+ const cs = window.getComputedStyle(c);
5787
+ realH += (parseFloat(cs.marginTop) || 0) + (parseFloat(cs.marginBottom) || 0);
5788
+ } catch {
5789
+ }
5790
+ const hasMedia = c.querySelector("img, svg") !== null || ["img", "svg"].includes(c.tagName.toLowerCase());
5791
+ const hasTable = c.querySelector("table") !== null || c.tagName.toLowerCase() === "table";
5792
+ if (hasMedia) {
5793
+ realH = Math.max(realH, 300);
5794
+ } else if (hasTable) {
5795
+ realH = Math.max(realH, 240);
5796
+ }
5797
+ if (realH > 0) return realH;
5798
+ const textLen = c.textContent?.trim().length || 0;
5799
+ return Math.max(28, Math.ceil(textLen / 75) * 26 + 16);
5800
+ });
5801
+ wrapper.innerHTML = "";
5802
+ let curCard = createRtfCard(1);
5734
5803
  wrapper.appendChild(curCard);
5735
5804
  pageElements = [curCard];
5736
5805
  let curH = 0;
5737
- const maxH = 928;
5806
+ const maxH = 860;
5738
5807
  for (let i = 0; i < contentNodes.length; i++) {
5739
5808
  const child = contentNodes[i];
5740
5809
  const chH = childHeights[i];
@@ -5742,8 +5811,10 @@ var RtfPlugin = class {
5742
5811
  if (curH === 0 && isChildEmpty) {
5743
5812
  continue;
5744
5813
  }
5745
- if (curH + chH > maxH && curCard.childNodes.length > 0) {
5746
- curCard = createRtfCard();
5814
+ const isTable = child.querySelector("table") !== null || child.tagName.toLowerCase() === "table";
5815
+ const shouldBreakBeforeTable = isTable && curH > 400 && curCard.childNodes.length > 0;
5816
+ if ((curH + chH > maxH || shouldBreakBeforeTable) && curCard.childNodes.length > 0) {
5817
+ curCard = createRtfCard(pageElements.length + 1);
5747
5818
  wrapper.appendChild(curCard);
5748
5819
  pageElements.push(curCard);
5749
5820
  curH = 0;