@files-preview-app/preview-file 1.3.4 → 1.3.5
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 +261 -210
- package/dist/angular.cjs.map +1 -1
- package/dist/angular.js +261 -210
- package/dist/angular.js.map +1 -1
- package/dist/index.cjs +261 -210
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +261 -210
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +261 -210
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +261 -210
- package/dist/react.js.map +1 -1
- package/dist/vue.cjs +261 -210
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.js +261 -210
- package/dist/vue.js.map +1 -1
- package/package.json +1 -1
package/dist/angular.js
CHANGED
|
@@ -5294,7 +5294,7 @@ function cleanRtfText(raw) {
|
|
|
5294
5294
|
return String.fromCharCode(num);
|
|
5295
5295
|
}).replace(/\\'([0-9a-fA-F]{2})/g, (_, hex) => {
|
|
5296
5296
|
return String.fromCharCode(parseInt(hex, 16));
|
|
5297
|
-
}).replace(/\\tab\b/g, " ").replace(/\\emdash\b/g, "\u2014").replace(/\\endash\b/g, "\u2013").replace(/\\bullet\b/g, "\u2022").replace(/\\lquote\b/g, "\u2018").replace(/\\rquote\b/g, "\u2019").replace(/\\ldblquote\b/g, "\u201C").replace(/\\rdblquote\b/g, "\u201D").replace(
|
|
5297
|
+
}).replace(/\\tab\b/g, " ").replace(/\\emdash\b/g, "\u2014").replace(/\\endash\b/g, "\u2013").replace(/\\bullet\b/g, "\u2022").replace(/\\lquote\b/g, "\u2018").replace(/\\rquote\b/g, "\u2019").replace(/\\ldblquote\b/g, "\u201C").replace(/\\rdblquote\b/g, "\u201D").replace(/\\[a-zA-Z]+-?\d*\s?/g, " ").replace(/[{}\r\n]/g, " ").replace(/\s+/g, " ").trim();
|
|
5298
5298
|
}
|
|
5299
5299
|
function parseRtfTables(rtfText) {
|
|
5300
5300
|
const rowSegments = rtfText.split(/\\row\b/);
|
|
@@ -5334,17 +5334,12 @@ function parseRtfTables(rtfText) {
|
|
|
5334
5334
|
}
|
|
5335
5335
|
const isNewTable = !currentTable || segmentStart - currentTable.lastEnd > 2500;
|
|
5336
5336
|
if (isNewTable) {
|
|
5337
|
-
const prevTextSlice = rtfText.slice(Math.max(0, segmentStart - 4e3), segmentStart);
|
|
5338
|
-
const cleanPrev = cleanRtfText(prevTextSlice);
|
|
5339
|
-
const anchorBefore = cleanPrev.slice(-80).trim();
|
|
5340
5337
|
currentTable = {
|
|
5341
5338
|
id: `RTF_TABLE_${rawTables.length}`,
|
|
5342
5339
|
startPos: segmentStart,
|
|
5343
5340
|
lastEnd: segmentEnd,
|
|
5344
5341
|
rows: [],
|
|
5345
|
-
columnWidths: cellWidths
|
|
5346
|
-
anchorBefore,
|
|
5347
|
-
anchorAfter: ""
|
|
5342
|
+
columnWidths: cellWidths
|
|
5348
5343
|
};
|
|
5349
5344
|
rawTables.push(currentTable);
|
|
5350
5345
|
}
|
|
@@ -5358,20 +5353,13 @@ function parseRtfTables(rtfText) {
|
|
|
5358
5353
|
}
|
|
5359
5354
|
charOffset += segment.length + 4;
|
|
5360
5355
|
}
|
|
5361
|
-
rawTables.forEach((tbl) => {
|
|
5362
|
-
const afterSlice = rtfText.slice(tbl.lastEnd, Math.min(rtfText.length, tbl.lastEnd + 2e3));
|
|
5363
|
-
const cleanAfter = cleanRtfText(afterSlice);
|
|
5364
|
-
tbl.anchorAfter = cleanAfter.slice(0, 80).trim();
|
|
5365
|
-
});
|
|
5366
5356
|
return rawTables.map((tbl) => {
|
|
5367
5357
|
const totalW = (tbl.columnWidths || []).reduce((a, b) => a + b, 0);
|
|
5368
5358
|
const colPercents = totalW > 0 ? tbl.columnWidths.map((w) => Math.round(w / totalW * 100)) : [];
|
|
5369
5359
|
return {
|
|
5370
5360
|
id: tbl.id,
|
|
5371
5361
|
rows: tbl.rows.map((r) => r.cells),
|
|
5372
|
-
colPercents
|
|
5373
|
-
anchorBefore: tbl.anchorBefore,
|
|
5374
|
-
anchorAfter: tbl.anchorAfter
|
|
5362
|
+
colPercents
|
|
5375
5363
|
};
|
|
5376
5364
|
});
|
|
5377
5365
|
}
|
|
@@ -5384,8 +5372,6 @@ function renderRtfTableElement(table) {
|
|
|
5384
5372
|
tableEl.style.fontSize = "10pt";
|
|
5385
5373
|
tableEl.style.lineHeight = "1.5";
|
|
5386
5374
|
tableEl.style.border = "1px solid #cbd5e1";
|
|
5387
|
-
tableEl.style.borderRadius = "4px";
|
|
5388
|
-
tableEl.style.boxSizing = "border-box";
|
|
5389
5375
|
tableEl.style.backgroundColor = "#ffffff";
|
|
5390
5376
|
const thead = document.createElement("thead");
|
|
5391
5377
|
const tbody = document.createElement("tbody");
|
|
@@ -5394,27 +5380,17 @@ function renderRtfTableElement(table) {
|
|
|
5394
5380
|
const isHeader = rIdx === 0;
|
|
5395
5381
|
if (isHeader) {
|
|
5396
5382
|
tr.style.backgroundColor = "#f8fafc";
|
|
5397
|
-
tr.style.borderBottom = "2px solid #cbd5e1";
|
|
5398
|
-
} else {
|
|
5399
|
-
tr.style.borderBottom = "1px solid #e2e8f0";
|
|
5400
|
-
if (rIdx % 2 === 0) {
|
|
5401
|
-
tr.style.backgroundColor = "#fcfdfe";
|
|
5402
|
-
}
|
|
5403
5383
|
}
|
|
5404
5384
|
rowCells.forEach((cellText, cIdx) => {
|
|
5405
5385
|
const cellEl = document.createElement(isHeader ? "th" : "td");
|
|
5406
5386
|
cellEl.style.padding = "8px 12px";
|
|
5407
5387
|
cellEl.style.border = "1px solid #cbd5e1";
|
|
5408
5388
|
cellEl.style.verticalAlign = "top";
|
|
5409
|
-
cellEl.style.color = isHeader ? "#0f172a" : "#1e293b";
|
|
5410
|
-
cellEl.style.fontWeight = isHeader ? "600" : "normal";
|
|
5411
5389
|
if (table.colPercents && table.colPercents[cIdx]) {
|
|
5412
5390
|
cellEl.style.width = `${table.colPercents[cIdx]}%`;
|
|
5413
5391
|
}
|
|
5414
5392
|
if (/^\d+$/.test(cellText.trim()) || cellText.trim() === "#") {
|
|
5415
5393
|
cellEl.style.textAlign = "center";
|
|
5416
|
-
} else {
|
|
5417
|
-
cellEl.style.textAlign = "left";
|
|
5418
5394
|
}
|
|
5419
5395
|
cellEl.textContent = cellText;
|
|
5420
5396
|
tr.appendChild(cellEl);
|
|
@@ -5429,23 +5405,19 @@ function renderRtfTableElement(table) {
|
|
|
5429
5405
|
tableEl.appendChild(tbody);
|
|
5430
5406
|
return tableEl;
|
|
5431
5407
|
}
|
|
5432
|
-
function
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
const vb = svg.getAttribute("viewBox") || "";
|
|
5446
|
-
return `svg_${vb}_${svg.innerHTML.length}`;
|
|
5447
|
-
}
|
|
5448
|
-
return null;
|
|
5408
|
+
function isHeadingElement(el) {
|
|
5409
|
+
if (["H1", "H2", "H3", "H4"].includes(el.tagName)) return true;
|
|
5410
|
+
const spans = el.querySelectorAll ? Array.from(el.querySelectorAll("span, b, strong, div")) : [];
|
|
5411
|
+
for (const s of spans) {
|
|
5412
|
+
const hEl = s;
|
|
5413
|
+
const fs = parseFloat(hEl.style.fontSize) || 0;
|
|
5414
|
+
const isBold = hEl.style.fontWeight === "bold" || parseInt(hEl.style.fontWeight, 10) >= 600 || ["B", "STRONG"].includes(hEl.tagName);
|
|
5415
|
+
if (isBold && fs >= 14) return true;
|
|
5416
|
+
}
|
|
5417
|
+
const elFs = parseFloat(el.style.fontSize) || 0;
|
|
5418
|
+
const elBold = el.style.fontWeight === "bold" || parseInt(el.style.fontWeight, 10) >= 600;
|
|
5419
|
+
if (elBold && elFs >= 14) return true;
|
|
5420
|
+
return false;
|
|
5449
5421
|
}
|
|
5450
5422
|
var RtfPlugin = class {
|
|
5451
5423
|
id = "rtf";
|
|
@@ -5558,10 +5530,66 @@ var RtfPlugin = class {
|
|
|
5558
5530
|
return actions;
|
|
5559
5531
|
}
|
|
5560
5532
|
async render(ctx) {
|
|
5533
|
+
const rawRtf = new TextDecoder("latin1").decode(ctx.buffer);
|
|
5534
|
+
const paperwMatch = rawRtf.match(/\\paperw(\d+)/);
|
|
5535
|
+
const paperhMatch = rawRtf.match(/\\paperh(\d+)/);
|
|
5536
|
+
const marglMatch = rawRtf.match(/\\margl(\d+)/);
|
|
5537
|
+
const margrMatch = rawRtf.match(/\\margr(\d+)/);
|
|
5538
|
+
const margtMatch = rawRtf.match(/\\margt(\d+)/);
|
|
5539
|
+
const margbMatch = rawRtf.match(/\\margb(\d+)/);
|
|
5540
|
+
const paperwTwips = paperwMatch ? parseInt(paperwMatch[1], 10) : 11906;
|
|
5541
|
+
const paperhTwips = paperhMatch ? parseInt(paperhMatch[1], 10) : 16838;
|
|
5542
|
+
const marglTwips = marglMatch ? parseInt(marglMatch[1], 10) : 1134;
|
|
5543
|
+
const margrTwips = margrMatch ? parseInt(margrMatch[1], 10) : 1134;
|
|
5544
|
+
const margtTwips = margtMatch ? parseInt(margtMatch[1], 10) : 1134;
|
|
5545
|
+
const margbTwips = margbMatch ? parseInt(margbMatch[1], 10) : 1134;
|
|
5546
|
+
const pageWidth = Math.round(paperwTwips / 15);
|
|
5547
|
+
const pageHeight = Math.round(paperhTwips / 15);
|
|
5548
|
+
const padLeft = Math.round(marglTwips / 15);
|
|
5549
|
+
const padRight = Math.round(margrTwips / 15);
|
|
5550
|
+
const padTop = Math.round(margtTwips / 15);
|
|
5551
|
+
const padBottom = Math.round(margbTwips / 15);
|
|
5552
|
+
const printableHeight = pageHeight - padTop - padBottom;
|
|
5553
|
+
const extractedImages = [];
|
|
5554
|
+
let p = 0;
|
|
5555
|
+
while ((p = rawRtf.indexOf("\\pict", p)) !== -1) {
|
|
5556
|
+
const startP = p;
|
|
5557
|
+
p += 5;
|
|
5558
|
+
const header = rawRtf.substring(startP, startP + 600);
|
|
5559
|
+
let mime = "";
|
|
5560
|
+
let magic = "";
|
|
5561
|
+
if (header.includes("\\pngblip")) {
|
|
5562
|
+
mime = "image/png";
|
|
5563
|
+
magic = "89504e47";
|
|
5564
|
+
} else if (header.includes("\\jpegblip")) {
|
|
5565
|
+
mime = "image/jpeg";
|
|
5566
|
+
magic = "ffd8ff";
|
|
5567
|
+
}
|
|
5568
|
+
if (!mime || !magic) continue;
|
|
5569
|
+
const magicPos = rawRtf.indexOf(magic, startP);
|
|
5570
|
+
if (magicPos === -1 || magicPos - startP > 3e3) continue;
|
|
5571
|
+
let endP = magicPos;
|
|
5572
|
+
while (endP < rawRtf.length && /[0-9a-fA-F\r\n\s]/.test(rawRtf[endP])) {
|
|
5573
|
+
endP++;
|
|
5574
|
+
}
|
|
5575
|
+
const cleanHex = rawRtf.substring(magicPos, endP).replace(/[\r\n\s]/g, "");
|
|
5576
|
+
if (cleanHex.length < 100) continue;
|
|
5577
|
+
const hexLen = cleanHex.length / 2;
|
|
5578
|
+
const u8 = new Uint8Array(hexLen);
|
|
5579
|
+
for (let k = 0; k < hexLen; k++) {
|
|
5580
|
+
u8[k] = parseInt(cleanHex.substr(k * 2, 2), 16);
|
|
5581
|
+
}
|
|
5582
|
+
let bStr = "";
|
|
5583
|
+
for (let k = 0; k < u8.length; k += 8192) {
|
|
5584
|
+
bStr += String.fromCharCode.apply(null, Array.from(u8.subarray(k, k + 8192)));
|
|
5585
|
+
}
|
|
5586
|
+
extractedImages.push({ mime, dataUrl: `data:${mime};base64,${btoa(bStr)}`, offset: startP });
|
|
5587
|
+
}
|
|
5588
|
+
const tables = parseRtfTables(rawRtf);
|
|
5561
5589
|
const wrapper = document.createElement("div");
|
|
5562
5590
|
wrapper.className = "fp-rtf-wrapper";
|
|
5563
5591
|
wrapper.style.padding = "0";
|
|
5564
|
-
wrapper.style.width =
|
|
5592
|
+
wrapper.style.width = `${pageWidth}px`;
|
|
5565
5593
|
wrapper.style.margin = "0 auto";
|
|
5566
5594
|
wrapper.style.boxSizing = "border-box";
|
|
5567
5595
|
wrapper.style.display = "flex";
|
|
@@ -5581,9 +5609,8 @@ var RtfPlugin = class {
|
|
|
5581
5609
|
let isUserZoomed = false;
|
|
5582
5610
|
let fitMode = ctx?.options?.fitMode || "width";
|
|
5583
5611
|
const calculateFitScale = (mode = fitMode) => {
|
|
5584
|
-
const
|
|
5585
|
-
const
|
|
5586
|
-
const singlePageH = activeEl?.offsetHeight || 1056;
|
|
5612
|
+
const elW = pageWidth;
|
|
5613
|
+
const singlePageH = pageHeight;
|
|
5587
5614
|
const availW = Math.max(280, ctx.container.clientWidth - 32);
|
|
5588
5615
|
const availH = Math.max(280, ctx.container.clientHeight - 32);
|
|
5589
5616
|
const sW = availW / elW;
|
|
@@ -5596,8 +5623,7 @@ var RtfPlugin = class {
|
|
|
5596
5623
|
const applyTransform = () => {
|
|
5597
5624
|
wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
|
|
5598
5625
|
wrapper.style.transformOrigin = "top center";
|
|
5599
|
-
const
|
|
5600
|
-
const baseH = activeEl?.offsetHeight || 1056;
|
|
5626
|
+
const baseH = pageHeight;
|
|
5601
5627
|
const scaledH = baseH * scale;
|
|
5602
5628
|
const extraH = Math.max(0, scaledH - baseH);
|
|
5603
5629
|
wrapper.style.marginBottom = `${extraH + 32}px`;
|
|
@@ -5617,193 +5643,220 @@ var RtfPlugin = class {
|
|
|
5617
5643
|
if (typeof RTFJS.loggingEnabled === "function") {
|
|
5618
5644
|
RTFJS.loggingEnabled(false);
|
|
5619
5645
|
}
|
|
5620
|
-
const rawText = new TextDecoder("latin1").decode(ctx.buffer);
|
|
5621
|
-
const tables = parseRtfTables(rawText);
|
|
5622
|
-
const seenMediaSignatures = /* @__PURE__ */ new Set();
|
|
5623
5646
|
const doc = new RTFJS.Document(ctx.buffer, {
|
|
5624
5647
|
onPicture: (isLegacy, createPic) => {
|
|
5625
|
-
if (isLegacy === true)
|
|
5626
|
-
|
|
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;
|
|
5648
|
+
if (isLegacy === true) return null;
|
|
5649
|
+
return createPic();
|
|
5638
5650
|
}
|
|
5639
5651
|
});
|
|
5640
|
-
const
|
|
5641
|
-
|
|
5642
|
-
const
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
const
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
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
|
-
}
|
|
5666
|
-
const svgs = item.querySelectorAll("svg, img");
|
|
5667
|
-
svgs.forEach((s) => {
|
|
5668
|
-
const el = s;
|
|
5669
|
-
el.style.maxWidth = "100%";
|
|
5670
|
-
el.style.maxHeight = "360px";
|
|
5671
|
-
el.style.display = "block";
|
|
5672
|
-
el.style.margin = "12px auto";
|
|
5673
|
-
if (s.tagName.toLowerCase() === "svg") {
|
|
5674
|
-
s.removeAttribute("width");
|
|
5675
|
-
s.removeAttribute("height");
|
|
5676
|
-
el.style.width = "100%";
|
|
5677
|
-
el.style.maxHeight = "360px";
|
|
5678
|
-
}
|
|
5679
|
-
});
|
|
5680
|
-
if (tag === "p" || tag === "div") {
|
|
5681
|
-
item.style.display = "block";
|
|
5682
|
-
item.style.marginBottom = "12px";
|
|
5683
|
-
item.style.lineHeight = "1.6";
|
|
5684
|
-
}
|
|
5685
|
-
contentNodes.push(item);
|
|
5652
|
+
const elements = await doc.render();
|
|
5653
|
+
let unsupportedIndex = 1;
|
|
5654
|
+
const usedTables = /* @__PURE__ */ new Set();
|
|
5655
|
+
for (let i = 0; i < elements.length; i++) {
|
|
5656
|
+
const el = elements[i];
|
|
5657
|
+
const text = el.textContent || "";
|
|
5658
|
+
if (text.includes("[Unsupported image format]")) {
|
|
5659
|
+
if (extractedImages[unsupportedIndex]) {
|
|
5660
|
+
const img = document.createElement("img");
|
|
5661
|
+
img.src = extractedImages[unsupportedIndex].dataUrl;
|
|
5662
|
+
img.style.width = "100%";
|
|
5663
|
+
img.style.height = "auto";
|
|
5664
|
+
img.style.maxHeight = "430px";
|
|
5665
|
+
img.style.objectFit = "contain";
|
|
5666
|
+
img.style.display = "block";
|
|
5667
|
+
img.style.margin = "12px auto";
|
|
5668
|
+
el.innerHTML = "";
|
|
5669
|
+
el.appendChild(img);
|
|
5670
|
+
unsupportedIndex++;
|
|
5686
5671
|
}
|
|
5687
5672
|
}
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
|
|
5673
|
+
if (tables.length > 0) {
|
|
5674
|
+
for (let t = 0; t < tables.length; t++) {
|
|
5675
|
+
if (usedTables.has(t)) continue;
|
|
5676
|
+
const tbl = tables[t];
|
|
5677
|
+
if (tbl.rows.length >= 2) {
|
|
5678
|
+
const sampleCell1 = tbl.rows[1]?.[1] || tbl.rows[0]?.[1] || "";
|
|
5679
|
+
const sampleCell2 = tbl.rows[2]?.[1] || tbl.rows[1]?.[0] || "";
|
|
5680
|
+
const match1 = sampleCell1 && text.includes(sampleCell1.slice(0, 15).trim());
|
|
5681
|
+
const match2 = sampleCell2 && text.includes(sampleCell2.slice(0, 15).trim());
|
|
5682
|
+
if (match1 && match2) {
|
|
5683
|
+
el.innerHTML = "";
|
|
5684
|
+
el.appendChild(renderRtfTableElement(tbl));
|
|
5685
|
+
usedTables.add(t);
|
|
5686
|
+
break;
|
|
5687
|
+
}
|
|
5700
5688
|
}
|
|
5701
5689
|
}
|
|
5702
5690
|
}
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5691
|
+
}
|
|
5692
|
+
elements.forEach((el) => {
|
|
5693
|
+
const svgs = el.querySelectorAll ? Array.from(el.querySelectorAll("svg")) : [];
|
|
5694
|
+
svgs.forEach((svg) => {
|
|
5695
|
+
svg.removeAttribute("width");
|
|
5696
|
+
svg.removeAttribute("height");
|
|
5697
|
+
svg.style.maxWidth = "100%";
|
|
5698
|
+
svg.style.maxHeight = "430px";
|
|
5699
|
+
svg.style.height = "auto";
|
|
5700
|
+
svg.style.display = "block";
|
|
5701
|
+
svg.style.margin = "12px auto";
|
|
5702
|
+
});
|
|
5703
|
+
const imgs = el.querySelectorAll ? Array.from(el.querySelectorAll("img")) : [];
|
|
5704
|
+
imgs.forEach((img) => {
|
|
5705
|
+
img.style.maxWidth = "100%";
|
|
5706
|
+
img.style.maxHeight = "430px";
|
|
5707
|
+
img.style.height = "auto";
|
|
5708
|
+
img.style.objectFit = "contain";
|
|
5709
|
+
img.style.display = "block";
|
|
5710
|
+
img.style.margin = "12px auto";
|
|
5711
|
+
});
|
|
5712
|
+
});
|
|
5713
|
+
const allImgs = Array.from(document.querySelectorAll("img")).concat(
|
|
5714
|
+
elements.flatMap((el) => Array.from(el.querySelectorAll ? el.querySelectorAll("img") : []))
|
|
5715
|
+
);
|
|
5716
|
+
await Promise.all(allImgs.map((img) => {
|
|
5717
|
+
if (img.complete && img.naturalHeight > 0) return Promise.resolve();
|
|
5718
|
+
if (img.decode) return img.decode().catch(() => {
|
|
5719
|
+
});
|
|
5720
|
+
return new Promise((r) => {
|
|
5721
|
+
img.onload = r;
|
|
5722
|
+
img.onerror = r;
|
|
5723
|
+
});
|
|
5724
|
+
}));
|
|
5725
|
+
elements.forEach((el) => {
|
|
5726
|
+
const text = el.textContent || "";
|
|
5727
|
+
if (text.includes("\uF0B7")) {
|
|
5728
|
+
const cleanText = text.replace(/^[\s\uf0b7\t]+/, "");
|
|
5729
|
+
el.style.display = "flex";
|
|
5730
|
+
el.style.alignItems = "flex-start";
|
|
5731
|
+
el.style.margin = "6px 0 6px 28px";
|
|
5732
|
+
el.style.fontSize = "11pt";
|
|
5733
|
+
el.style.lineHeight = "1.5";
|
|
5734
|
+
el.innerHTML = `<span style="margin-right:10px; user-select:none;">□</span><span>${cleanText}</span>`;
|
|
5712
5735
|
}
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5736
|
+
});
|
|
5737
|
+
elements.forEach((el) => {
|
|
5738
|
+
const text = (el.textContent || "").trim();
|
|
5739
|
+
const hasMedia = el.querySelector("img, svg, canvas, table") !== null || ["IMG", "SVG", "TABLE"].includes(el.tagName);
|
|
5740
|
+
if (isHeadingElement(el)) {
|
|
5741
|
+
el.style.marginTop = "20px";
|
|
5742
|
+
el.style.marginBottom = "10px";
|
|
5743
|
+
el.style.lineHeight = "1.25";
|
|
5744
|
+
} else if (text.length > 0 && !hasMedia) {
|
|
5745
|
+
el.style.marginBottom = "12px";
|
|
5746
|
+
el.style.lineHeight = "1.45";
|
|
5719
5747
|
}
|
|
5720
5748
|
});
|
|
5721
|
-
const
|
|
5749
|
+
const measureCard = document.createElement("div");
|
|
5750
|
+
measureCard.style.width = `${pageWidth}px`;
|
|
5751
|
+
measureCard.style.padding = `${padTop}px ${padRight}px ${padBottom}px ${padLeft}px`;
|
|
5752
|
+
measureCard.style.boxSizing = "border-box";
|
|
5753
|
+
measureCard.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5754
|
+
measureCard.style.lineHeight = "1.45";
|
|
5755
|
+
measureCard.style.visibility = "hidden";
|
|
5756
|
+
measureCard.style.position = "absolute";
|
|
5757
|
+
measureCard.style.top = "-99999px";
|
|
5758
|
+
document.body.appendChild(measureCard);
|
|
5759
|
+
const createPageCard = (num) => {
|
|
5722
5760
|
const card = document.createElement("div");
|
|
5723
5761
|
card.className = "fp-rtf-page-card";
|
|
5724
|
-
card.setAttribute("data-page-number", String(
|
|
5762
|
+
card.setAttribute("data-page-number", String(num));
|
|
5725
5763
|
card.style.backgroundColor = "#ffffff";
|
|
5726
5764
|
card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04)";
|
|
5727
5765
|
card.style.borderRadius = "4px";
|
|
5728
|
-
card.style.
|
|
5729
|
-
card.style.
|
|
5730
|
-
card.style.
|
|
5731
|
-
card.style.maxHeight = "1056px";
|
|
5732
|
-
card.style.overflow = "hidden";
|
|
5766
|
+
card.style.width = `${pageWidth}px`;
|
|
5767
|
+
card.style.height = `${pageHeight}px`;
|
|
5768
|
+
card.style.padding = `${padTop}px ${padRight}px ${padBottom}px ${padLeft}px`;
|
|
5733
5769
|
card.style.boxSizing = "border-box";
|
|
5770
|
+
card.style.overflow = "hidden";
|
|
5734
5771
|
card.style.marginBottom = "24px";
|
|
5735
|
-
card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5736
|
-
card.style.lineHeight = "1.6";
|
|
5737
5772
|
card.style.color = "#1e293b";
|
|
5773
|
+
card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5774
|
+
card.style.lineHeight = "1.45";
|
|
5738
5775
|
card.style.position = "relative";
|
|
5776
|
+
card.style.textAlign = "left";
|
|
5739
5777
|
return card;
|
|
5740
5778
|
};
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
const
|
|
5749
|
-
const
|
|
5750
|
-
const
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
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);
|
|
5770
|
-
wrapper.appendChild(curCard);
|
|
5771
|
-
pageElements = [curCard];
|
|
5772
|
-
let curH = 0;
|
|
5773
|
-
const maxH = 860;
|
|
5774
|
-
for (let i = 0; i < contentNodes.length; i++) {
|
|
5775
|
-
const child = contentNodes[i];
|
|
5776
|
-
const chH = childHeights[i];
|
|
5777
|
-
const isChildEmpty = (child.textContent || "").trim().length === 0 && !child.querySelector("table, img, svg, canvas");
|
|
5778
|
-
if (curH === 0 && isChildEmpty) {
|
|
5779
|
+
const pages = [];
|
|
5780
|
+
let curCard = createPageCard(1);
|
|
5781
|
+
pages.push(curCard);
|
|
5782
|
+
let curHeight = 0;
|
|
5783
|
+
for (let i = 0; i < elements.length; i++) {
|
|
5784
|
+
const el = elements[i];
|
|
5785
|
+
if (!el || !(el instanceof HTMLElement)) continue;
|
|
5786
|
+
const text = (el.textContent || "").trim();
|
|
5787
|
+
const hasMedia = el.querySelector("img, svg, canvas, table") !== null || ["IMG", "SVG", "TABLE"].includes(el.tagName);
|
|
5788
|
+
const isEmptyPar = !hasMedia && text.length === 0;
|
|
5789
|
+
if (isEmptyPar) {
|
|
5790
|
+
const emptyH = 35;
|
|
5791
|
+
if (curHeight + emptyH > printableHeight) {
|
|
5792
|
+
if (curCard.childNodes.length > 0) {
|
|
5793
|
+
curCard = createPageCard(pages.length + 1);
|
|
5794
|
+
pages.push(curCard);
|
|
5795
|
+
curHeight = 0;
|
|
5796
|
+
}
|
|
5797
|
+
}
|
|
5798
|
+
const spacer = document.createElement("div");
|
|
5799
|
+
spacer.style.height = `${emptyH}px`;
|
|
5800
|
+
curCard.appendChild(spacer);
|
|
5801
|
+
curHeight += emptyH;
|
|
5779
5802
|
continue;
|
|
5780
5803
|
}
|
|
5781
|
-
|
|
5782
|
-
const
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5804
|
+
measureCard.innerHTML = "";
|
|
5805
|
+
const clone = el.cloneNode(true);
|
|
5806
|
+
measureCard.appendChild(clone);
|
|
5807
|
+
const compStyle = window.getComputedStyle(clone);
|
|
5808
|
+
const mt = parseFloat(compStyle.marginTop) || 0;
|
|
5809
|
+
const mb = parseFloat(compStyle.marginBottom) || 0;
|
|
5810
|
+
const elH = clone.offsetHeight + mt + mb;
|
|
5811
|
+
const isHeading = isHeadingElement(el);
|
|
5812
|
+
let nextContentH = 0;
|
|
5813
|
+
if (isHeading || hasMedia) {
|
|
5814
|
+
for (let j = i + 1; j < elements.length; j++) {
|
|
5815
|
+
const nextEl = elements[j];
|
|
5816
|
+
if (nextEl && (nextEl.textContent || "").trim().length > 0) {
|
|
5817
|
+
measureCard.innerHTML = "";
|
|
5818
|
+
const nClone = nextEl.cloneNode(true);
|
|
5819
|
+
measureCard.appendChild(nClone);
|
|
5820
|
+
const nStyle = window.getComputedStyle(nClone);
|
|
5821
|
+
nextContentH = nClone.offsetHeight + (parseFloat(nStyle.marginTop) || 0) + (parseFloat(nStyle.marginBottom) || 0);
|
|
5822
|
+
break;
|
|
5823
|
+
}
|
|
5824
|
+
}
|
|
5788
5825
|
}
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5826
|
+
const remainingSpace = printableHeight - curHeight;
|
|
5827
|
+
const isLargeMedia = hasMedia && elH > 300;
|
|
5828
|
+
const keepWithNextOverflow = isHeading && nextContentH > 0 && elH + nextContentH + 20 > remainingSpace;
|
|
5829
|
+
const largeMediaOverflow = isLargeMedia && curHeight > 0 && elH + 80 > remainingSpace;
|
|
5830
|
+
const shouldBreak = (curHeight + elH > printableHeight || keepWithNextOverflow || largeMediaOverflow) && curCard.childNodes.length > 0;
|
|
5831
|
+
if (shouldBreak) {
|
|
5832
|
+
curCard = createPageCard(pages.length + 1);
|
|
5833
|
+
pages.push(curCard);
|
|
5834
|
+
curHeight = 0;
|
|
5835
|
+
}
|
|
5836
|
+
curCard.appendChild(el);
|
|
5837
|
+
curHeight += elH;
|
|
5838
|
+
}
|
|
5839
|
+
measureCard.remove();
|
|
5840
|
+
pageElements = pages.filter((card) => {
|
|
5793
5841
|
const hasText = (card.textContent || "").trim().length > 0;
|
|
5794
|
-
const
|
|
5795
|
-
return hasText ||
|
|
5842
|
+
const hasCardMedia = card.querySelector("table, img, svg, canvas") !== null;
|
|
5843
|
+
return hasText || hasCardMedia;
|
|
5796
5844
|
});
|
|
5797
5845
|
if (pageElements.length === 0) {
|
|
5798
5846
|
pageElements = [curCard];
|
|
5799
5847
|
}
|
|
5848
|
+
wrapper.innerHTML = "";
|
|
5849
|
+
pageElements.forEach((card, idx) => {
|
|
5850
|
+
card.setAttribute("data-page-number", String(idx + 1));
|
|
5851
|
+
card.style.display = idx === 0 ? "block" : "none";
|
|
5852
|
+
wrapper.appendChild(card);
|
|
5853
|
+
});
|
|
5800
5854
|
} catch (err) {
|
|
5801
5855
|
console.warn("[RtfPlugin] RTF render error, fallback text:", err);
|
|
5802
|
-
const text =
|
|
5803
|
-
const tables = parseRtfTables(text);
|
|
5856
|
+
const text = rawRtf;
|
|
5804
5857
|
const rawPages = text.split(/\\page\b/).map((segment) => {
|
|
5805
5858
|
return segment.replace(/\\par[d]?/g, "\n").replace(/\\[a-zA-Z0-9\-]+/g, "").replace(/[{}]/g, "").trim();
|
|
5806
|
-
}).filter((
|
|
5859
|
+
}).filter((p2) => p2.length > 0);
|
|
5807
5860
|
const pages = rawPages.length > 0 ? rawPages : [text.replace(/\\par[d]?/g, "\n").replace(/\\[a-zA-Z0-9\-]+/g, "").replace(/[{}]/g, "").trim()];
|
|
5808
5861
|
for (let i = 0; i < pages.length; i++) {
|
|
5809
5862
|
const pageCard = document.createElement("div");
|
|
@@ -5811,9 +5864,9 @@ var RtfPlugin = class {
|
|
|
5811
5864
|
pageCard.style.backgroundColor = "#ffffff";
|
|
5812
5865
|
pageCard.style.boxShadow = "0 2px 12px rgba(0,0,0,0.08)";
|
|
5813
5866
|
pageCard.style.borderRadius = "4px";
|
|
5814
|
-
pageCard.style.padding =
|
|
5815
|
-
pageCard.style.width =
|
|
5816
|
-
pageCard.style.minHeight =
|
|
5867
|
+
pageCard.style.padding = `${padTop}px ${padRight}px ${padBottom}px ${padLeft}px`;
|
|
5868
|
+
pageCard.style.width = `${pageWidth}px`;
|
|
5869
|
+
pageCard.style.minHeight = `${pageHeight}px`;
|
|
5817
5870
|
pageCard.style.boxSizing = "border-box";
|
|
5818
5871
|
pageCard.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5819
5872
|
pageCard.style.fontSize = "12pt";
|
|
@@ -5833,11 +5886,9 @@ var RtfPlugin = class {
|
|
|
5833
5886
|
let currentPage = 1;
|
|
5834
5887
|
const showPage = (pageNum) => {
|
|
5835
5888
|
currentPage = Math.max(1, Math.min(totalPages, pageNum));
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
});
|
|
5840
|
-
}
|
|
5889
|
+
pageElements.forEach((el, idx) => {
|
|
5890
|
+
el.style.display = idx + 1 === currentPage ? "block" : "none";
|
|
5891
|
+
});
|
|
5841
5892
|
ctx.container.scrollTop = 0;
|
|
5842
5893
|
ctx.emit("page-change", { page: currentPage, total: totalPages });
|
|
5843
5894
|
};
|