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