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