@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 +89 -18
- package/dist/angular.cjs.map +1 -1
- package/dist/angular.js +89 -18
- package/dist/angular.js.map +1 -1
- package/dist/index.cjs +89 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +89 -18
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +89 -18
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +89 -18
- package/dist/react.js.map +1 -1
- package/dist/vue.cjs +89 -18
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.js +89 -18
- package/dist/vue.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5496,6 +5496,24 @@ function renderRtfTableElement(table) {
|
|
|
5496
5496
|
tableEl.appendChild(tbody);
|
|
5497
5497
|
return tableEl;
|
|
5498
5498
|
}
|
|
5499
|
+
function extractMediaFingerprint(el) {
|
|
5500
|
+
const img = el.tagName.toLowerCase() === "img" ? el : el.querySelector("img");
|
|
5501
|
+
if (img && img.src) {
|
|
5502
|
+
const s = img.src;
|
|
5503
|
+
return s.length > 300 ? `img_${s.slice(0, 80)}_${s.length}_${s.slice(-80)}` : `img_${s}`;
|
|
5504
|
+
}
|
|
5505
|
+
const innerImg = el.querySelector("image");
|
|
5506
|
+
if (innerImg) {
|
|
5507
|
+
const h = innerImg.getAttribute("xlink:href") || innerImg.getAttribute("href") || "";
|
|
5508
|
+
if (h) return h.length > 300 ? `svgimg_${h.slice(0, 80)}_${h.length}_${h.slice(-80)}` : `svgimg_${h}`;
|
|
5509
|
+
}
|
|
5510
|
+
const svg = el.tagName.toLowerCase() === "svg" ? el : el.querySelector("svg");
|
|
5511
|
+
if (svg) {
|
|
5512
|
+
const vb = svg.getAttribute("viewBox") || "";
|
|
5513
|
+
return `svg_${vb}_${svg.innerHTML.length}`;
|
|
5514
|
+
}
|
|
5515
|
+
return null;
|
|
5516
|
+
}
|
|
5499
5517
|
var RtfPlugin = class {
|
|
5500
5518
|
id = "rtf";
|
|
5501
5519
|
name = "Rich Text Format (RTF)";
|
|
@@ -5668,9 +5686,27 @@ var RtfPlugin = class {
|
|
|
5668
5686
|
}
|
|
5669
5687
|
const rawText = new TextDecoder("latin1").decode(ctx.buffer);
|
|
5670
5688
|
const tables = parseRtfTables(rawText);
|
|
5671
|
-
const
|
|
5689
|
+
const seenMediaSignatures = /* @__PURE__ */ new Set();
|
|
5690
|
+
const doc = new RTFJS__namespace.Document(ctx.buffer, {
|
|
5691
|
+
onPicture: (isLegacy, createPic) => {
|
|
5692
|
+
if (isLegacy === true) {
|
|
5693
|
+
return null;
|
|
5694
|
+
}
|
|
5695
|
+
const pic = createPic();
|
|
5696
|
+
if (!pic) return null;
|
|
5697
|
+
const fp = extractMediaFingerprint(pic);
|
|
5698
|
+
if (fp) {
|
|
5699
|
+
if (seenMediaSignatures.has(fp)) {
|
|
5700
|
+
return null;
|
|
5701
|
+
}
|
|
5702
|
+
seenMediaSignatures.add(fp);
|
|
5703
|
+
}
|
|
5704
|
+
return pic;
|
|
5705
|
+
}
|
|
5706
|
+
});
|
|
5672
5707
|
const htmlElements = await doc.render();
|
|
5673
5708
|
const contentNodes = [];
|
|
5709
|
+
const seenInContentBlocks = /* @__PURE__ */ new Set();
|
|
5674
5710
|
const extractBlocks = (nodes) => {
|
|
5675
5711
|
for (const item of nodes) {
|
|
5676
5712
|
if (!item || !(item instanceof HTMLElement)) continue;
|
|
@@ -5682,6 +5718,18 @@ var RtfPlugin = class {
|
|
|
5682
5718
|
if (hasChildBlocks && !["table", "tr", "td", "th", "ul", "ol", "li"].includes(tag)) {
|
|
5683
5719
|
extractBlocks(Array.from(item.children));
|
|
5684
5720
|
} else {
|
|
5721
|
+
const fp = extractMediaFingerprint(item);
|
|
5722
|
+
if (fp) {
|
|
5723
|
+
if (seenInContentBlocks.has(fp)) {
|
|
5724
|
+
continue;
|
|
5725
|
+
}
|
|
5726
|
+
seenInContentBlocks.add(fp);
|
|
5727
|
+
}
|
|
5728
|
+
const hasMedia = item.querySelector("img, svg, canvas, table") !== null || ["img", "svg", "table"].includes(tag);
|
|
5729
|
+
const textContent = (item.textContent || "").trim();
|
|
5730
|
+
if (!hasMedia && textContent.length === 0) {
|
|
5731
|
+
continue;
|
|
5732
|
+
}
|
|
5685
5733
|
const svgs = item.querySelectorAll("svg, img");
|
|
5686
5734
|
svgs.forEach((s) => {
|
|
5687
5735
|
const el = s;
|
|
@@ -5737,38 +5785,59 @@ var RtfPlugin = class {
|
|
|
5737
5785
|
}
|
|
5738
5786
|
}
|
|
5739
5787
|
});
|
|
5740
|
-
|
|
5741
|
-
contentNodes.forEach((node) => wrapper.appendChild(node));
|
|
5742
|
-
const childHeights = contentNodes.map((c) => {
|
|
5743
|
-
const rectH = c.getBoundingClientRect ? c.getBoundingClientRect().height : 0;
|
|
5744
|
-
const offH = c.offsetHeight || 0;
|
|
5745
|
-
const realH = Math.max(rectH, offH);
|
|
5746
|
-
if (realH > 0) return realH;
|
|
5747
|
-
const textLen = c.textContent?.trim().length || 0;
|
|
5748
|
-
return Math.max(24, Math.ceil(textLen / 95) * 22 + 12);
|
|
5749
|
-
});
|
|
5750
|
-
wrapper.innerHTML = "";
|
|
5751
|
-
const createRtfCard = () => {
|
|
5788
|
+
const createRtfCard = (pageNum) => {
|
|
5752
5789
|
const card = document.createElement("div");
|
|
5753
5790
|
card.className = "fp-rtf-page-card";
|
|
5791
|
+
card.setAttribute("data-page-number", String(pageNum));
|
|
5754
5792
|
card.style.backgroundColor = "#ffffff";
|
|
5755
|
-
card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08)";
|
|
5793
|
+
card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04)";
|
|
5756
5794
|
card.style.borderRadius = "4px";
|
|
5757
5795
|
card.style.padding = "64px 56px";
|
|
5758
5796
|
card.style.width = "816px";
|
|
5759
5797
|
card.style.minHeight = "1056px";
|
|
5798
|
+
card.style.maxHeight = "1056px";
|
|
5799
|
+
card.style.overflow = "hidden";
|
|
5760
5800
|
card.style.boxSizing = "border-box";
|
|
5761
5801
|
card.style.marginBottom = "24px";
|
|
5762
5802
|
card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5763
5803
|
card.style.lineHeight = "1.6";
|
|
5764
5804
|
card.style.color = "#1e293b";
|
|
5805
|
+
card.style.position = "relative";
|
|
5765
5806
|
return card;
|
|
5766
5807
|
};
|
|
5767
|
-
|
|
5808
|
+
wrapper.innerHTML = "";
|
|
5809
|
+
const measureCard = createRtfCard(0);
|
|
5810
|
+
measureCard.style.maxHeight = "none";
|
|
5811
|
+
measureCard.style.height = "auto";
|
|
5812
|
+
wrapper.appendChild(measureCard);
|
|
5813
|
+
contentNodes.forEach((node) => measureCard.appendChild(node));
|
|
5814
|
+
const childHeights = contentNodes.map((c) => {
|
|
5815
|
+
const rect = c.getBoundingClientRect ? c.getBoundingClientRect() : null;
|
|
5816
|
+
const rectH = rect ? rect.height : 0;
|
|
5817
|
+
const offH = c.offsetHeight || 0;
|
|
5818
|
+
let realH = Math.max(rectH, offH);
|
|
5819
|
+
try {
|
|
5820
|
+
const cs = window.getComputedStyle(c);
|
|
5821
|
+
realH += (parseFloat(cs.marginTop) || 0) + (parseFloat(cs.marginBottom) || 0);
|
|
5822
|
+
} catch {
|
|
5823
|
+
}
|
|
5824
|
+
const hasMedia = c.querySelector("img, svg") !== null || ["img", "svg"].includes(c.tagName.toLowerCase());
|
|
5825
|
+
const hasTable = c.querySelector("table") !== null || c.tagName.toLowerCase() === "table";
|
|
5826
|
+
if (hasMedia) {
|
|
5827
|
+
realH = Math.max(realH, 300);
|
|
5828
|
+
} else if (hasTable) {
|
|
5829
|
+
realH = Math.max(realH, 240);
|
|
5830
|
+
}
|
|
5831
|
+
if (realH > 0) return realH;
|
|
5832
|
+
const textLen = c.textContent?.trim().length || 0;
|
|
5833
|
+
return Math.max(28, Math.ceil(textLen / 75) * 26 + 16);
|
|
5834
|
+
});
|
|
5835
|
+
wrapper.innerHTML = "";
|
|
5836
|
+
let curCard = createRtfCard(1);
|
|
5768
5837
|
wrapper.appendChild(curCard);
|
|
5769
5838
|
pageElements = [curCard];
|
|
5770
5839
|
let curH = 0;
|
|
5771
|
-
const maxH =
|
|
5840
|
+
const maxH = 860;
|
|
5772
5841
|
for (let i = 0; i < contentNodes.length; i++) {
|
|
5773
5842
|
const child = contentNodes[i];
|
|
5774
5843
|
const chH = childHeights[i];
|
|
@@ -5776,8 +5845,10 @@ var RtfPlugin = class {
|
|
|
5776
5845
|
if (curH === 0 && isChildEmpty) {
|
|
5777
5846
|
continue;
|
|
5778
5847
|
}
|
|
5779
|
-
|
|
5780
|
-
|
|
5848
|
+
const isTable = child.querySelector("table") !== null || child.tagName.toLowerCase() === "table";
|
|
5849
|
+
const shouldBreakBeforeTable = isTable && curH > 400 && curCard.childNodes.length > 0;
|
|
5850
|
+
if ((curH + chH > maxH || shouldBreakBeforeTable) && curCard.childNodes.length > 0) {
|
|
5851
|
+
curCard = createRtfCard(pageElements.length + 1);
|
|
5781
5852
|
wrapper.appendChild(curCard);
|
|
5782
5853
|
pageElements.push(curCard);
|
|
5783
5854
|
curH = 0;
|