@files-preview-app/preview-file 1.3.3 → 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 +267 -145
- package/dist/angular.cjs.map +1 -1
- package/dist/angular.js +267 -145
- package/dist/angular.js.map +1 -1
- package/dist/index.cjs +267 -145
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +267 -145
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +267 -145
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +267 -145
- package/dist/react.js.map +1 -1
- package/dist/vue.cjs +267 -145
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.js +267 -145
- package/dist/vue.js.map +1 -1
- package/package.json +1 -1
package/dist/vue.js
CHANGED
|
@@ -5246,7 +5246,7 @@ function cleanRtfText(raw) {
|
|
|
5246
5246
|
return String.fromCharCode(num);
|
|
5247
5247
|
}).replace(/\\'([0-9a-fA-F]{2})/g, (_, hex) => {
|
|
5248
5248
|
return String.fromCharCode(parseInt(hex, 16));
|
|
5249
|
-
}).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(
|
|
5249
|
+
}).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();
|
|
5250
5250
|
}
|
|
5251
5251
|
function parseRtfTables(rtfText) {
|
|
5252
5252
|
const rowSegments = rtfText.split(/\\row\b/);
|
|
@@ -5286,17 +5286,12 @@ function parseRtfTables(rtfText) {
|
|
|
5286
5286
|
}
|
|
5287
5287
|
const isNewTable = !currentTable || segmentStart - currentTable.lastEnd > 2500;
|
|
5288
5288
|
if (isNewTable) {
|
|
5289
|
-
const prevTextSlice = rtfText.slice(Math.max(0, segmentStart - 4e3), segmentStart);
|
|
5290
|
-
const cleanPrev = cleanRtfText(prevTextSlice);
|
|
5291
|
-
const anchorBefore = cleanPrev.slice(-80).trim();
|
|
5292
5289
|
currentTable = {
|
|
5293
5290
|
id: `RTF_TABLE_${rawTables.length}`,
|
|
5294
5291
|
startPos: segmentStart,
|
|
5295
5292
|
lastEnd: segmentEnd,
|
|
5296
5293
|
rows: [],
|
|
5297
|
-
columnWidths: cellWidths
|
|
5298
|
-
anchorBefore,
|
|
5299
|
-
anchorAfter: ""
|
|
5294
|
+
columnWidths: cellWidths
|
|
5300
5295
|
};
|
|
5301
5296
|
rawTables.push(currentTable);
|
|
5302
5297
|
}
|
|
@@ -5310,20 +5305,13 @@ function parseRtfTables(rtfText) {
|
|
|
5310
5305
|
}
|
|
5311
5306
|
charOffset += segment.length + 4;
|
|
5312
5307
|
}
|
|
5313
|
-
rawTables.forEach((tbl) => {
|
|
5314
|
-
const afterSlice = rtfText.slice(tbl.lastEnd, Math.min(rtfText.length, tbl.lastEnd + 2e3));
|
|
5315
|
-
const cleanAfter = cleanRtfText(afterSlice);
|
|
5316
|
-
tbl.anchorAfter = cleanAfter.slice(0, 80).trim();
|
|
5317
|
-
});
|
|
5318
5308
|
return rawTables.map((tbl) => {
|
|
5319
5309
|
const totalW = (tbl.columnWidths || []).reduce((a, b) => a + b, 0);
|
|
5320
5310
|
const colPercents = totalW > 0 ? tbl.columnWidths.map((w) => Math.round(w / totalW * 100)) : [];
|
|
5321
5311
|
return {
|
|
5322
5312
|
id: tbl.id,
|
|
5323
5313
|
rows: tbl.rows.map((r) => r.cells),
|
|
5324
|
-
colPercents
|
|
5325
|
-
anchorBefore: tbl.anchorBefore,
|
|
5326
|
-
anchorAfter: tbl.anchorAfter
|
|
5314
|
+
colPercents
|
|
5327
5315
|
};
|
|
5328
5316
|
});
|
|
5329
5317
|
}
|
|
@@ -5336,8 +5324,6 @@ function renderRtfTableElement(table) {
|
|
|
5336
5324
|
tableEl.style.fontSize = "10pt";
|
|
5337
5325
|
tableEl.style.lineHeight = "1.5";
|
|
5338
5326
|
tableEl.style.border = "1px solid #cbd5e1";
|
|
5339
|
-
tableEl.style.borderRadius = "4px";
|
|
5340
|
-
tableEl.style.boxSizing = "border-box";
|
|
5341
5327
|
tableEl.style.backgroundColor = "#ffffff";
|
|
5342
5328
|
const thead = document.createElement("thead");
|
|
5343
5329
|
const tbody = document.createElement("tbody");
|
|
@@ -5346,27 +5332,17 @@ function renderRtfTableElement(table) {
|
|
|
5346
5332
|
const isHeader = rIdx === 0;
|
|
5347
5333
|
if (isHeader) {
|
|
5348
5334
|
tr.style.backgroundColor = "#f8fafc";
|
|
5349
|
-
tr.style.borderBottom = "2px solid #cbd5e1";
|
|
5350
|
-
} else {
|
|
5351
|
-
tr.style.borderBottom = "1px solid #e2e8f0";
|
|
5352
|
-
if (rIdx % 2 === 0) {
|
|
5353
|
-
tr.style.backgroundColor = "#fcfdfe";
|
|
5354
|
-
}
|
|
5355
5335
|
}
|
|
5356
5336
|
rowCells.forEach((cellText, cIdx) => {
|
|
5357
5337
|
const cellEl = document.createElement(isHeader ? "th" : "td");
|
|
5358
5338
|
cellEl.style.padding = "8px 12px";
|
|
5359
5339
|
cellEl.style.border = "1px solid #cbd5e1";
|
|
5360
5340
|
cellEl.style.verticalAlign = "top";
|
|
5361
|
-
cellEl.style.color = isHeader ? "#0f172a" : "#1e293b";
|
|
5362
|
-
cellEl.style.fontWeight = isHeader ? "600" : "normal";
|
|
5363
5341
|
if (table.colPercents && table.colPercents[cIdx]) {
|
|
5364
5342
|
cellEl.style.width = `${table.colPercents[cIdx]}%`;
|
|
5365
5343
|
}
|
|
5366
5344
|
if (/^\d+$/.test(cellText.trim()) || cellText.trim() === "#") {
|
|
5367
5345
|
cellEl.style.textAlign = "center";
|
|
5368
|
-
} else {
|
|
5369
|
-
cellEl.style.textAlign = "left";
|
|
5370
5346
|
}
|
|
5371
5347
|
cellEl.textContent = cellText;
|
|
5372
5348
|
tr.appendChild(cellEl);
|
|
@@ -5381,6 +5357,20 @@ function renderRtfTableElement(table) {
|
|
|
5381
5357
|
tableEl.appendChild(tbody);
|
|
5382
5358
|
return tableEl;
|
|
5383
5359
|
}
|
|
5360
|
+
function isHeadingElement(el) {
|
|
5361
|
+
if (["H1", "H2", "H3", "H4"].includes(el.tagName)) return true;
|
|
5362
|
+
const spans = el.querySelectorAll ? Array.from(el.querySelectorAll("span, b, strong, div")) : [];
|
|
5363
|
+
for (const s of spans) {
|
|
5364
|
+
const hEl = s;
|
|
5365
|
+
const fs = parseFloat(hEl.style.fontSize) || 0;
|
|
5366
|
+
const isBold = hEl.style.fontWeight === "bold" || parseInt(hEl.style.fontWeight, 10) >= 600 || ["B", "STRONG"].includes(hEl.tagName);
|
|
5367
|
+
if (isBold && fs >= 14) return true;
|
|
5368
|
+
}
|
|
5369
|
+
const elFs = parseFloat(el.style.fontSize) || 0;
|
|
5370
|
+
const elBold = el.style.fontWeight === "bold" || parseInt(el.style.fontWeight, 10) >= 600;
|
|
5371
|
+
if (elBold && elFs >= 14) return true;
|
|
5372
|
+
return false;
|
|
5373
|
+
}
|
|
5384
5374
|
var RtfPlugin = class {
|
|
5385
5375
|
id = "rtf";
|
|
5386
5376
|
name = "Rich Text Format (RTF)";
|
|
@@ -5492,10 +5482,66 @@ var RtfPlugin = class {
|
|
|
5492
5482
|
return actions;
|
|
5493
5483
|
}
|
|
5494
5484
|
async render(ctx) {
|
|
5485
|
+
const rawRtf = new TextDecoder("latin1").decode(ctx.buffer);
|
|
5486
|
+
const paperwMatch = rawRtf.match(/\\paperw(\d+)/);
|
|
5487
|
+
const paperhMatch = rawRtf.match(/\\paperh(\d+)/);
|
|
5488
|
+
const marglMatch = rawRtf.match(/\\margl(\d+)/);
|
|
5489
|
+
const margrMatch = rawRtf.match(/\\margr(\d+)/);
|
|
5490
|
+
const margtMatch = rawRtf.match(/\\margt(\d+)/);
|
|
5491
|
+
const margbMatch = rawRtf.match(/\\margb(\d+)/);
|
|
5492
|
+
const paperwTwips = paperwMatch ? parseInt(paperwMatch[1], 10) : 11906;
|
|
5493
|
+
const paperhTwips = paperhMatch ? parseInt(paperhMatch[1], 10) : 16838;
|
|
5494
|
+
const marglTwips = marglMatch ? parseInt(marglMatch[1], 10) : 1134;
|
|
5495
|
+
const margrTwips = margrMatch ? parseInt(margrMatch[1], 10) : 1134;
|
|
5496
|
+
const margtTwips = margtMatch ? parseInt(margtMatch[1], 10) : 1134;
|
|
5497
|
+
const margbTwips = margbMatch ? parseInt(margbMatch[1], 10) : 1134;
|
|
5498
|
+
const pageWidth = Math.round(paperwTwips / 15);
|
|
5499
|
+
const pageHeight = Math.round(paperhTwips / 15);
|
|
5500
|
+
const padLeft = Math.round(marglTwips / 15);
|
|
5501
|
+
const padRight = Math.round(margrTwips / 15);
|
|
5502
|
+
const padTop = Math.round(margtTwips / 15);
|
|
5503
|
+
const padBottom = Math.round(margbTwips / 15);
|
|
5504
|
+
const printableHeight = pageHeight - padTop - padBottom;
|
|
5505
|
+
const extractedImages = [];
|
|
5506
|
+
let p = 0;
|
|
5507
|
+
while ((p = rawRtf.indexOf("\\pict", p)) !== -1) {
|
|
5508
|
+
const startP = p;
|
|
5509
|
+
p += 5;
|
|
5510
|
+
const header = rawRtf.substring(startP, startP + 600);
|
|
5511
|
+
let mime = "";
|
|
5512
|
+
let magic = "";
|
|
5513
|
+
if (header.includes("\\pngblip")) {
|
|
5514
|
+
mime = "image/png";
|
|
5515
|
+
magic = "89504e47";
|
|
5516
|
+
} else if (header.includes("\\jpegblip")) {
|
|
5517
|
+
mime = "image/jpeg";
|
|
5518
|
+
magic = "ffd8ff";
|
|
5519
|
+
}
|
|
5520
|
+
if (!mime || !magic) continue;
|
|
5521
|
+
const magicPos = rawRtf.indexOf(magic, startP);
|
|
5522
|
+
if (magicPos === -1 || magicPos - startP > 3e3) continue;
|
|
5523
|
+
let endP = magicPos;
|
|
5524
|
+
while (endP < rawRtf.length && /[0-9a-fA-F\r\n\s]/.test(rawRtf[endP])) {
|
|
5525
|
+
endP++;
|
|
5526
|
+
}
|
|
5527
|
+
const cleanHex = rawRtf.substring(magicPos, endP).replace(/[\r\n\s]/g, "");
|
|
5528
|
+
if (cleanHex.length < 100) continue;
|
|
5529
|
+
const hexLen = cleanHex.length / 2;
|
|
5530
|
+
const u8 = new Uint8Array(hexLen);
|
|
5531
|
+
for (let k = 0; k < hexLen; k++) {
|
|
5532
|
+
u8[k] = parseInt(cleanHex.substr(k * 2, 2), 16);
|
|
5533
|
+
}
|
|
5534
|
+
let bStr = "";
|
|
5535
|
+
for (let k = 0; k < u8.length; k += 8192) {
|
|
5536
|
+
bStr += String.fromCharCode.apply(null, Array.from(u8.subarray(k, k + 8192)));
|
|
5537
|
+
}
|
|
5538
|
+
extractedImages.push({ mime, dataUrl: `data:${mime};base64,${btoa(bStr)}`, offset: startP });
|
|
5539
|
+
}
|
|
5540
|
+
const tables = parseRtfTables(rawRtf);
|
|
5495
5541
|
const wrapper = document.createElement("div");
|
|
5496
5542
|
wrapper.className = "fp-rtf-wrapper";
|
|
5497
5543
|
wrapper.style.padding = "0";
|
|
5498
|
-
wrapper.style.width =
|
|
5544
|
+
wrapper.style.width = `${pageWidth}px`;
|
|
5499
5545
|
wrapper.style.margin = "0 auto";
|
|
5500
5546
|
wrapper.style.boxSizing = "border-box";
|
|
5501
5547
|
wrapper.style.display = "flex";
|
|
@@ -5515,9 +5561,8 @@ var RtfPlugin = class {
|
|
|
5515
5561
|
let isUserZoomed = false;
|
|
5516
5562
|
let fitMode = ctx?.options?.fitMode || "width";
|
|
5517
5563
|
const calculateFitScale = (mode = fitMode) => {
|
|
5518
|
-
const
|
|
5519
|
-
const
|
|
5520
|
-
const singlePageH = activeEl?.offsetHeight || 1056;
|
|
5564
|
+
const elW = pageWidth;
|
|
5565
|
+
const singlePageH = pageHeight;
|
|
5521
5566
|
const availW = Math.max(280, ctx.container.clientWidth - 32);
|
|
5522
5567
|
const availH = Math.max(280, ctx.container.clientHeight - 32);
|
|
5523
5568
|
const sW = availW / elW;
|
|
@@ -5530,8 +5575,7 @@ var RtfPlugin = class {
|
|
|
5530
5575
|
const applyTransform = () => {
|
|
5531
5576
|
wrapper.style.transform = `scale(${scale}) rotate(${rotation}deg)`;
|
|
5532
5577
|
wrapper.style.transformOrigin = "top center";
|
|
5533
|
-
const
|
|
5534
|
-
const baseH = activeEl?.offsetHeight || 1056;
|
|
5578
|
+
const baseH = pageHeight;
|
|
5535
5579
|
const scaledH = baseH * scale;
|
|
5536
5580
|
const extraH = Math.max(0, scaledH - baseH);
|
|
5537
5581
|
wrapper.style.marginBottom = `${extraH + 32}px`;
|
|
@@ -5551,140 +5595,220 @@ var RtfPlugin = class {
|
|
|
5551
5595
|
if (typeof RTFJS.loggingEnabled === "function") {
|
|
5552
5596
|
RTFJS.loggingEnabled(false);
|
|
5553
5597
|
}
|
|
5554
|
-
const
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
const contentNodes = [];
|
|
5559
|
-
const extractBlocks = (nodes) => {
|
|
5560
|
-
for (const item of nodes) {
|
|
5561
|
-
if (!item || !(item instanceof HTMLElement)) continue;
|
|
5562
|
-
const tag = item.tagName.toLowerCase();
|
|
5563
|
-
const hasChildBlocks = Array.from(item.children).some((c) => {
|
|
5564
|
-
const ct = c.tagName.toLowerCase();
|
|
5565
|
-
return ["p", "div", "table", "h1", "h2", "h3", "h4", "h5", "h6", "section", "article", "ul", "ol"].includes(ct);
|
|
5566
|
-
});
|
|
5567
|
-
if (hasChildBlocks && !["table", "tr", "td", "th", "ul", "ol", "li"].includes(tag)) {
|
|
5568
|
-
extractBlocks(Array.from(item.children));
|
|
5569
|
-
} else {
|
|
5570
|
-
const svgs = item.querySelectorAll("svg, img");
|
|
5571
|
-
svgs.forEach((s) => {
|
|
5572
|
-
const el = s;
|
|
5573
|
-
el.style.maxWidth = "100%";
|
|
5574
|
-
el.style.maxHeight = "360px";
|
|
5575
|
-
el.style.display = "block";
|
|
5576
|
-
el.style.margin = "12px auto";
|
|
5577
|
-
if (s.tagName.toLowerCase() === "svg") {
|
|
5578
|
-
s.removeAttribute("width");
|
|
5579
|
-
s.removeAttribute("height");
|
|
5580
|
-
el.style.width = "100%";
|
|
5581
|
-
el.style.maxHeight = "360px";
|
|
5582
|
-
}
|
|
5583
|
-
});
|
|
5584
|
-
if (tag === "p" || tag === "div") {
|
|
5585
|
-
item.style.display = "block";
|
|
5586
|
-
item.style.marginBottom = "12px";
|
|
5587
|
-
item.style.lineHeight = "1.6";
|
|
5588
|
-
}
|
|
5589
|
-
contentNodes.push(item);
|
|
5590
|
-
}
|
|
5598
|
+
const doc = new RTFJS.Document(ctx.buffer, {
|
|
5599
|
+
onPicture: (isLegacy, createPic) => {
|
|
5600
|
+
if (isLegacy === true) return null;
|
|
5601
|
+
return createPic();
|
|
5591
5602
|
}
|
|
5592
|
-
};
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5603
|
+
});
|
|
5604
|
+
const elements = await doc.render();
|
|
5605
|
+
let unsupportedIndex = 1;
|
|
5606
|
+
const usedTables = /* @__PURE__ */ new Set();
|
|
5607
|
+
for (let i = 0; i < elements.length; i++) {
|
|
5608
|
+
const el = elements[i];
|
|
5609
|
+
const text = el.textContent || "";
|
|
5610
|
+
if (text.includes("[Unsupported image format]")) {
|
|
5611
|
+
if (extractedImages[unsupportedIndex]) {
|
|
5612
|
+
const img = document.createElement("img");
|
|
5613
|
+
img.src = extractedImages[unsupportedIndex].dataUrl;
|
|
5614
|
+
img.style.width = "100%";
|
|
5615
|
+
img.style.height = "auto";
|
|
5616
|
+
img.style.maxHeight = "430px";
|
|
5617
|
+
img.style.objectFit = "contain";
|
|
5618
|
+
img.style.display = "block";
|
|
5619
|
+
img.style.margin = "12px auto";
|
|
5620
|
+
el.innerHTML = "";
|
|
5621
|
+
el.appendChild(img);
|
|
5622
|
+
unsupportedIndex++;
|
|
5605
5623
|
}
|
|
5606
5624
|
}
|
|
5607
|
-
if (
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5625
|
+
if (tables.length > 0) {
|
|
5626
|
+
for (let t = 0; t < tables.length; t++) {
|
|
5627
|
+
if (usedTables.has(t)) continue;
|
|
5628
|
+
const tbl = tables[t];
|
|
5629
|
+
if (tbl.rows.length >= 2) {
|
|
5630
|
+
const sampleCell1 = tbl.rows[1]?.[1] || tbl.rows[0]?.[1] || "";
|
|
5631
|
+
const sampleCell2 = tbl.rows[2]?.[1] || tbl.rows[1]?.[0] || "";
|
|
5632
|
+
const match1 = sampleCell1 && text.includes(sampleCell1.slice(0, 15).trim());
|
|
5633
|
+
const match2 = sampleCell2 && text.includes(sampleCell2.slice(0, 15).trim());
|
|
5634
|
+
if (match1 && match2) {
|
|
5635
|
+
el.innerHTML = "";
|
|
5636
|
+
el.appendChild(renderRtfTableElement(tbl));
|
|
5637
|
+
usedTables.add(t);
|
|
5638
|
+
break;
|
|
5639
|
+
}
|
|
5614
5640
|
}
|
|
5615
5641
|
}
|
|
5616
5642
|
}
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5643
|
+
}
|
|
5644
|
+
elements.forEach((el) => {
|
|
5645
|
+
const svgs = el.querySelectorAll ? Array.from(el.querySelectorAll("svg")) : [];
|
|
5646
|
+
svgs.forEach((svg) => {
|
|
5647
|
+
svg.removeAttribute("width");
|
|
5648
|
+
svg.removeAttribute("height");
|
|
5649
|
+
svg.style.maxWidth = "100%";
|
|
5650
|
+
svg.style.maxHeight = "430px";
|
|
5651
|
+
svg.style.height = "auto";
|
|
5652
|
+
svg.style.display = "block";
|
|
5653
|
+
svg.style.margin = "12px auto";
|
|
5654
|
+
});
|
|
5655
|
+
const imgs = el.querySelectorAll ? Array.from(el.querySelectorAll("img")) : [];
|
|
5656
|
+
imgs.forEach((img) => {
|
|
5657
|
+
img.style.maxWidth = "100%";
|
|
5658
|
+
img.style.maxHeight = "430px";
|
|
5659
|
+
img.style.height = "auto";
|
|
5660
|
+
img.style.objectFit = "contain";
|
|
5661
|
+
img.style.display = "block";
|
|
5662
|
+
img.style.margin = "12px auto";
|
|
5663
|
+
});
|
|
5664
|
+
});
|
|
5665
|
+
const allImgs = Array.from(document.querySelectorAll("img")).concat(
|
|
5666
|
+
elements.flatMap((el) => Array.from(el.querySelectorAll ? el.querySelectorAll("img") : []))
|
|
5667
|
+
);
|
|
5668
|
+
await Promise.all(allImgs.map((img) => {
|
|
5669
|
+
if (img.complete && img.naturalHeight > 0) return Promise.resolve();
|
|
5670
|
+
if (img.decode) return img.decode().catch(() => {
|
|
5671
|
+
});
|
|
5672
|
+
return new Promise((r) => {
|
|
5673
|
+
img.onload = r;
|
|
5674
|
+
img.onerror = r;
|
|
5675
|
+
});
|
|
5676
|
+
}));
|
|
5677
|
+
elements.forEach((el) => {
|
|
5678
|
+
const text = el.textContent || "";
|
|
5679
|
+
if (text.includes("\uF0B7")) {
|
|
5680
|
+
const cleanText = text.replace(/^[\s\uf0b7\t]+/, "");
|
|
5681
|
+
el.style.display = "flex";
|
|
5682
|
+
el.style.alignItems = "flex-start";
|
|
5683
|
+
el.style.margin = "6px 0 6px 28px";
|
|
5684
|
+
el.style.fontSize = "11pt";
|
|
5685
|
+
el.style.lineHeight = "1.5";
|
|
5686
|
+
el.innerHTML = `<span style="margin-right:10px; user-select:none;">□</span><span>${cleanText}</span>`;
|
|
5623
5687
|
}
|
|
5624
5688
|
});
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5633
|
-
|
|
5689
|
+
elements.forEach((el) => {
|
|
5690
|
+
const text = (el.textContent || "").trim();
|
|
5691
|
+
const hasMedia = el.querySelector("img, svg, canvas, table") !== null || ["IMG", "SVG", "TABLE"].includes(el.tagName);
|
|
5692
|
+
if (isHeadingElement(el)) {
|
|
5693
|
+
el.style.marginTop = "20px";
|
|
5694
|
+
el.style.marginBottom = "10px";
|
|
5695
|
+
el.style.lineHeight = "1.25";
|
|
5696
|
+
} else if (text.length > 0 && !hasMedia) {
|
|
5697
|
+
el.style.marginBottom = "12px";
|
|
5698
|
+
el.style.lineHeight = "1.45";
|
|
5699
|
+
}
|
|
5634
5700
|
});
|
|
5635
|
-
|
|
5636
|
-
|
|
5701
|
+
const measureCard = document.createElement("div");
|
|
5702
|
+
measureCard.style.width = `${pageWidth}px`;
|
|
5703
|
+
measureCard.style.padding = `${padTop}px ${padRight}px ${padBottom}px ${padLeft}px`;
|
|
5704
|
+
measureCard.style.boxSizing = "border-box";
|
|
5705
|
+
measureCard.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5706
|
+
measureCard.style.lineHeight = "1.45";
|
|
5707
|
+
measureCard.style.visibility = "hidden";
|
|
5708
|
+
measureCard.style.position = "absolute";
|
|
5709
|
+
measureCard.style.top = "-99999px";
|
|
5710
|
+
document.body.appendChild(measureCard);
|
|
5711
|
+
const createPageCard = (num) => {
|
|
5637
5712
|
const card = document.createElement("div");
|
|
5638
5713
|
card.className = "fp-rtf-page-card";
|
|
5714
|
+
card.setAttribute("data-page-number", String(num));
|
|
5639
5715
|
card.style.backgroundColor = "#ffffff";
|
|
5640
|
-
card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08)";
|
|
5716
|
+
card.style.boxShadow = "0 4px 24px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04)";
|
|
5641
5717
|
card.style.borderRadius = "4px";
|
|
5642
|
-
card.style.
|
|
5643
|
-
card.style.
|
|
5644
|
-
card.style.
|
|
5718
|
+
card.style.width = `${pageWidth}px`;
|
|
5719
|
+
card.style.height = `${pageHeight}px`;
|
|
5720
|
+
card.style.padding = `${padTop}px ${padRight}px ${padBottom}px ${padLeft}px`;
|
|
5645
5721
|
card.style.boxSizing = "border-box";
|
|
5722
|
+
card.style.overflow = "hidden";
|
|
5646
5723
|
card.style.marginBottom = "24px";
|
|
5647
|
-
card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5648
|
-
card.style.lineHeight = "1.6";
|
|
5649
5724
|
card.style.color = "#1e293b";
|
|
5725
|
+
card.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5726
|
+
card.style.lineHeight = "1.45";
|
|
5727
|
+
card.style.position = "relative";
|
|
5728
|
+
card.style.textAlign = "left";
|
|
5650
5729
|
return card;
|
|
5651
5730
|
};
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
let
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
const
|
|
5660
|
-
const
|
|
5661
|
-
|
|
5731
|
+
const pages = [];
|
|
5732
|
+
let curCard = createPageCard(1);
|
|
5733
|
+
pages.push(curCard);
|
|
5734
|
+
let curHeight = 0;
|
|
5735
|
+
for (let i = 0; i < elements.length; i++) {
|
|
5736
|
+
const el = elements[i];
|
|
5737
|
+
if (!el || !(el instanceof HTMLElement)) continue;
|
|
5738
|
+
const text = (el.textContent || "").trim();
|
|
5739
|
+
const hasMedia = el.querySelector("img, svg, canvas, table") !== null || ["IMG", "SVG", "TABLE"].includes(el.tagName);
|
|
5740
|
+
const isEmptyPar = !hasMedia && text.length === 0;
|
|
5741
|
+
if (isEmptyPar) {
|
|
5742
|
+
const emptyH = 35;
|
|
5743
|
+
if (curHeight + emptyH > printableHeight) {
|
|
5744
|
+
if (curCard.childNodes.length > 0) {
|
|
5745
|
+
curCard = createPageCard(pages.length + 1);
|
|
5746
|
+
pages.push(curCard);
|
|
5747
|
+
curHeight = 0;
|
|
5748
|
+
}
|
|
5749
|
+
}
|
|
5750
|
+
const spacer = document.createElement("div");
|
|
5751
|
+
spacer.style.height = `${emptyH}px`;
|
|
5752
|
+
curCard.appendChild(spacer);
|
|
5753
|
+
curHeight += emptyH;
|
|
5662
5754
|
continue;
|
|
5663
5755
|
}
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5756
|
+
measureCard.innerHTML = "";
|
|
5757
|
+
const clone = el.cloneNode(true);
|
|
5758
|
+
measureCard.appendChild(clone);
|
|
5759
|
+
const compStyle = window.getComputedStyle(clone);
|
|
5760
|
+
const mt = parseFloat(compStyle.marginTop) || 0;
|
|
5761
|
+
const mb = parseFloat(compStyle.marginBottom) || 0;
|
|
5762
|
+
const elH = clone.offsetHeight + mt + mb;
|
|
5763
|
+
const isHeading = isHeadingElement(el);
|
|
5764
|
+
let nextContentH = 0;
|
|
5765
|
+
if (isHeading || hasMedia) {
|
|
5766
|
+
for (let j = i + 1; j < elements.length; j++) {
|
|
5767
|
+
const nextEl = elements[j];
|
|
5768
|
+
if (nextEl && (nextEl.textContent || "").trim().length > 0) {
|
|
5769
|
+
measureCard.innerHTML = "";
|
|
5770
|
+
const nClone = nextEl.cloneNode(true);
|
|
5771
|
+
measureCard.appendChild(nClone);
|
|
5772
|
+
const nStyle = window.getComputedStyle(nClone);
|
|
5773
|
+
nextContentH = nClone.offsetHeight + (parseFloat(nStyle.marginTop) || 0) + (parseFloat(nStyle.marginBottom) || 0);
|
|
5774
|
+
break;
|
|
5775
|
+
}
|
|
5776
|
+
}
|
|
5669
5777
|
}
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5778
|
+
const remainingSpace = printableHeight - curHeight;
|
|
5779
|
+
const isLargeMedia = hasMedia && elH > 300;
|
|
5780
|
+
const keepWithNextOverflow = isHeading && nextContentH > 0 && elH + nextContentH + 20 > remainingSpace;
|
|
5781
|
+
const largeMediaOverflow = isLargeMedia && curHeight > 0 && elH + 80 > remainingSpace;
|
|
5782
|
+
const shouldBreak = (curHeight + elH > printableHeight || keepWithNextOverflow || largeMediaOverflow) && curCard.childNodes.length > 0;
|
|
5783
|
+
if (shouldBreak) {
|
|
5784
|
+
curCard = createPageCard(pages.length + 1);
|
|
5785
|
+
pages.push(curCard);
|
|
5786
|
+
curHeight = 0;
|
|
5787
|
+
}
|
|
5788
|
+
curCard.appendChild(el);
|
|
5789
|
+
curHeight += elH;
|
|
5790
|
+
}
|
|
5791
|
+
measureCard.remove();
|
|
5792
|
+
pageElements = pages.filter((card) => {
|
|
5674
5793
|
const hasText = (card.textContent || "").trim().length > 0;
|
|
5675
|
-
const
|
|
5676
|
-
return hasText ||
|
|
5794
|
+
const hasCardMedia = card.querySelector("table, img, svg, canvas") !== null;
|
|
5795
|
+
return hasText || hasCardMedia;
|
|
5677
5796
|
});
|
|
5678
5797
|
if (pageElements.length === 0) {
|
|
5679
5798
|
pageElements = [curCard];
|
|
5680
5799
|
}
|
|
5800
|
+
wrapper.innerHTML = "";
|
|
5801
|
+
pageElements.forEach((card, idx) => {
|
|
5802
|
+
card.setAttribute("data-page-number", String(idx + 1));
|
|
5803
|
+
card.style.display = idx === 0 ? "block" : "none";
|
|
5804
|
+
wrapper.appendChild(card);
|
|
5805
|
+
});
|
|
5681
5806
|
} catch (err) {
|
|
5682
5807
|
console.warn("[RtfPlugin] RTF render error, fallback text:", err);
|
|
5683
|
-
const text =
|
|
5684
|
-
const tables = parseRtfTables(text);
|
|
5808
|
+
const text = rawRtf;
|
|
5685
5809
|
const rawPages = text.split(/\\page\b/).map((segment) => {
|
|
5686
5810
|
return segment.replace(/\\par[d]?/g, "\n").replace(/\\[a-zA-Z0-9\-]+/g, "").replace(/[{}]/g, "").trim();
|
|
5687
|
-
}).filter((
|
|
5811
|
+
}).filter((p2) => p2.length > 0);
|
|
5688
5812
|
const pages = rawPages.length > 0 ? rawPages : [text.replace(/\\par[d]?/g, "\n").replace(/\\[a-zA-Z0-9\-]+/g, "").replace(/[{}]/g, "").trim()];
|
|
5689
5813
|
for (let i = 0; i < pages.length; i++) {
|
|
5690
5814
|
const pageCard = document.createElement("div");
|
|
@@ -5692,9 +5816,9 @@ var RtfPlugin = class {
|
|
|
5692
5816
|
pageCard.style.backgroundColor = "#ffffff";
|
|
5693
5817
|
pageCard.style.boxShadow = "0 2px 12px rgba(0,0,0,0.08)";
|
|
5694
5818
|
pageCard.style.borderRadius = "4px";
|
|
5695
|
-
pageCard.style.padding =
|
|
5696
|
-
pageCard.style.width =
|
|
5697
|
-
pageCard.style.minHeight =
|
|
5819
|
+
pageCard.style.padding = `${padTop}px ${padRight}px ${padBottom}px ${padLeft}px`;
|
|
5820
|
+
pageCard.style.width = `${pageWidth}px`;
|
|
5821
|
+
pageCard.style.minHeight = `${pageHeight}px`;
|
|
5698
5822
|
pageCard.style.boxSizing = "border-box";
|
|
5699
5823
|
pageCard.style.fontFamily = 'Calibri, "Segoe UI", Arial, sans-serif';
|
|
5700
5824
|
pageCard.style.fontSize = "12pt";
|
|
@@ -5714,11 +5838,9 @@ var RtfPlugin = class {
|
|
|
5714
5838
|
let currentPage = 1;
|
|
5715
5839
|
const showPage = (pageNum) => {
|
|
5716
5840
|
currentPage = Math.max(1, Math.min(totalPages, pageNum));
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
});
|
|
5721
|
-
}
|
|
5841
|
+
pageElements.forEach((el, idx) => {
|
|
5842
|
+
el.style.display = idx + 1 === currentPage ? "block" : "none";
|
|
5843
|
+
});
|
|
5722
5844
|
ctx.container.scrollTop = 0;
|
|
5723
5845
|
ctx.emit("page-change", { page: currentPage, total: totalPages });
|
|
5724
5846
|
};
|