@windoc/core 0.3.24 → 0.3.26
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/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +3322 -161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3352 -161
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var version = "0.3.
|
|
2
|
+
var version = "0.3.26";
|
|
3
3
|
|
|
4
4
|
// src/dataset/enum/Common.ts
|
|
5
5
|
var MaxHeightRatio = /* @__PURE__ */ ((MaxHeightRatio2) => {
|
|
@@ -177,6 +177,13 @@ function downloadFile(href, fileName) {
|
|
|
177
177
|
a.download = fileName;
|
|
178
178
|
a.click();
|
|
179
179
|
}
|
|
180
|
+
function downloadBlob(blob, fileName) {
|
|
181
|
+
const href = URL.createObjectURL(blob);
|
|
182
|
+
downloadFile(href, fileName);
|
|
183
|
+
window.setTimeout(() => {
|
|
184
|
+
URL.revokeObjectURL(href);
|
|
185
|
+
}, 0);
|
|
186
|
+
}
|
|
180
187
|
function threeClick(dom, fn) {
|
|
181
188
|
nClickEvent(3, dom, fn);
|
|
182
189
|
}
|
|
@@ -3802,23 +3809,23 @@ var ListStyle = /* @__PURE__ */ ((ListStyle3) => {
|
|
|
3802
3809
|
ListStyle3["CHECKBOX"] = "checkbox" /* CHECKBOX */;
|
|
3803
3810
|
return ListStyle3;
|
|
3804
3811
|
})(ListStyle || {});
|
|
3805
|
-
var OlPreset = /* @__PURE__ */ ((
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
return
|
|
3812
|
+
var OlPreset = /* @__PURE__ */ ((OlPreset3) => {
|
|
3813
|
+
OlPreset3["DEFAULT"] = "olDefault";
|
|
3814
|
+
OlPreset3["PARENTHESIS"] = "olParen";
|
|
3815
|
+
OlPreset3["OUTLINE"] = "olOutline";
|
|
3816
|
+
OlPreset3["UPPER_ALPHA"] = "olUpperA";
|
|
3817
|
+
OlPreset3["ROMAN"] = "olRoman";
|
|
3818
|
+
OlPreset3["ZERO_PAD"] = "olZeroPad";
|
|
3819
|
+
return OlPreset3;
|
|
3813
3820
|
})(OlPreset || {});
|
|
3814
|
-
var UlPreset = /* @__PURE__ */ ((
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
return
|
|
3821
|
+
var UlPreset = /* @__PURE__ */ ((UlPreset3) => {
|
|
3822
|
+
UlPreset3["DEFAULT"] = "ulDefault";
|
|
3823
|
+
UlPreset3["DIAMOND"] = "ulDiamond";
|
|
3824
|
+
UlPreset3["HOLLOW_SQ"] = "ulHollowSq";
|
|
3825
|
+
UlPreset3["ARROW"] = "ulArrow";
|
|
3826
|
+
UlPreset3["STAR"] = "ulStar";
|
|
3827
|
+
UlPreset3["CHECK_ARROW"] = "ulCheckArr";
|
|
3828
|
+
return UlPreset3;
|
|
3822
3829
|
})(UlPreset || {});
|
|
3823
3830
|
|
|
3824
3831
|
// src/dataset/constant/List.ts
|
|
@@ -24258,6 +24265,8 @@ var Command = class {
|
|
|
24258
24265
|
this.executeSearchNavigateNext = adapt.searchNavigateNext.bind(adapt);
|
|
24259
24266
|
this.executeReplace = adapt.replace.bind(adapt);
|
|
24260
24267
|
this.executePrint = adapt.print.bind(adapt);
|
|
24268
|
+
this.executeExportDocx = adapt.exportDocx.bind(adapt);
|
|
24269
|
+
this.executeExportPdf = adapt.exportPdf.bind(adapt);
|
|
24261
24270
|
this.executeReplaceImageElement = adapt.replaceImageElement.bind(adapt);
|
|
24262
24271
|
this.executeSaveAsImageElement = adapt.saveAsImageElement.bind(adapt);
|
|
24263
24272
|
this.executeSetImageCrop = adapt.setImageCrop.bind(adapt);
|
|
@@ -24338,172 +24347,3344 @@ var Command = class {
|
|
|
24338
24347
|
}
|
|
24339
24348
|
};
|
|
24340
24349
|
|
|
24341
|
-
// src/utils/
|
|
24342
|
-
|
|
24343
|
-
|
|
24344
|
-
|
|
24345
|
-
|
|
24346
|
-
|
|
24347
|
-
|
|
24348
|
-
|
|
24349
|
-
|
|
24350
|
-
|
|
24351
|
-
|
|
24352
|
-
|
|
24353
|
-
|
|
24354
|
-
|
|
24355
|
-
|
|
24356
|
-
|
|
24357
|
-
|
|
24358
|
-
|
|
24359
|
-
|
|
24360
|
-
|
|
24361
|
-
|
|
24362
|
-
|
|
24363
|
-
|
|
24350
|
+
// src/utils/docx.ts
|
|
24351
|
+
import {
|
|
24352
|
+
AlignmentType,
|
|
24353
|
+
BorderStyle,
|
|
24354
|
+
ColumnBreak,
|
|
24355
|
+
Document as Document2,
|
|
24356
|
+
ExternalHyperlink,
|
|
24357
|
+
Footer as Footer2,
|
|
24358
|
+
Header as Header2,
|
|
24359
|
+
HeadingLevel,
|
|
24360
|
+
ImageRun,
|
|
24361
|
+
LevelFormat,
|
|
24362
|
+
LineRuleType,
|
|
24363
|
+
Packer,
|
|
24364
|
+
PageBreak,
|
|
24365
|
+
PageNumber as PageNumber2,
|
|
24366
|
+
PageOrientation,
|
|
24367
|
+
Paragraph,
|
|
24368
|
+
ShadingType,
|
|
24369
|
+
Table,
|
|
24370
|
+
TableCell,
|
|
24371
|
+
TableLayoutType,
|
|
24372
|
+
TableRow,
|
|
24373
|
+
TextRun,
|
|
24374
|
+
UnderlineType,
|
|
24375
|
+
VerticalAlign as DocxVerticalAlign,
|
|
24376
|
+
WidthType
|
|
24377
|
+
} from "docx";
|
|
24378
|
+
var DEFAULT_DOCX_FILE_NAME = "document.docx";
|
|
24379
|
+
var DEFAULT_IMAGE_WIDTH = 320;
|
|
24380
|
+
var DEFAULT_IMAGE_HEIGHT = 180;
|
|
24381
|
+
var DEFAULT_LINE_HEIGHT = 1.15;
|
|
24382
|
+
var DOCX_FOOTER_TEXT_COLOR = "#000000";
|
|
24383
|
+
var docxBulletCharMap = {
|
|
24384
|
+
["disc" /* DISC */]: "\u2022",
|
|
24385
|
+
["circle" /* CIRCLE */]: "\u25E6",
|
|
24386
|
+
["square" /* SQUARE */]: "\u25A0",
|
|
24387
|
+
["checkbox" /* CHECKBOX */]: "\u2611"
|
|
24388
|
+
};
|
|
24389
|
+
var titleHeadingMap = {
|
|
24390
|
+
["first" /* FIRST */]: HeadingLevel.HEADING_1,
|
|
24391
|
+
["second" /* SECOND */]: HeadingLevel.HEADING_2,
|
|
24392
|
+
["third" /* THIRD */]: HeadingLevel.HEADING_3,
|
|
24393
|
+
["fourth" /* FOURTH */]: HeadingLevel.HEADING_4,
|
|
24394
|
+
["fifth" /* FIFTH */]: HeadingLevel.HEADING_5,
|
|
24395
|
+
["sixth" /* SIXTH */]: HeadingLevel.HEADING_6
|
|
24396
|
+
};
|
|
24397
|
+
var orderedStyleFormatMap = {
|
|
24398
|
+
["decimal" /* DECIMAL */]: LevelFormat.DECIMAL,
|
|
24399
|
+
["lowerAlpha" /* LOWER_ALPHA */]: LevelFormat.LOWER_LETTER,
|
|
24400
|
+
["upperAlpha" /* UPPER_ALPHA */]: LevelFormat.UPPER_LETTER,
|
|
24401
|
+
["lowerRoman" /* LOWER_ROMAN */]: LevelFormat.LOWER_ROMAN,
|
|
24402
|
+
["upperRoman" /* UPPER_ROMAN */]: LevelFormat.UPPER_ROMAN,
|
|
24403
|
+
["decimalParen" /* DECIMAL_PAREN */]: LevelFormat.DECIMAL,
|
|
24404
|
+
decimalZero: LevelFormat.DECIMAL_ZERO,
|
|
24405
|
+
lowerAlphaParen: LevelFormat.LOWER_LETTER,
|
|
24406
|
+
lowerRomanParen: LevelFormat.LOWER_ROMAN,
|
|
24407
|
+
outline: LevelFormat.DECIMAL
|
|
24408
|
+
};
|
|
24409
|
+
async function exportEditorDataToDocx(payload, options = {}) {
|
|
24410
|
+
const fileName = normalizeDocxFileName(options.fileName);
|
|
24411
|
+
const file = await createDocxDocument(payload);
|
|
24412
|
+
const blob = await Packer.toBlob(file);
|
|
24364
24413
|
return {
|
|
24365
|
-
|
|
24366
|
-
|
|
24367
|
-
height: `${height}px`
|
|
24414
|
+
blob,
|
|
24415
|
+
fileName
|
|
24368
24416
|
};
|
|
24369
24417
|
}
|
|
24370
|
-
function
|
|
24371
|
-
const {
|
|
24372
|
-
const
|
|
24373
|
-
|
|
24374
|
-
|
|
24375
|
-
|
|
24376
|
-
|
|
24377
|
-
|
|
24378
|
-
|
|
24379
|
-
|
|
24380
|
-
|
|
24381
|
-
const
|
|
24382
|
-
|
|
24383
|
-
|
|
24384
|
-
|
|
24385
|
-
|
|
24386
|
-
|
|
24387
|
-
|
|
24388
|
-
|
|
24389
|
-
image.style.height = direction === "horizontal" /* HORIZONTAL */ ? paperSize.width : paperSize.height;
|
|
24390
|
-
image.src = base64;
|
|
24391
|
-
container.append(image);
|
|
24392
|
-
});
|
|
24393
|
-
const style = document.createElement("style");
|
|
24394
|
-
const stylesheet = `
|
|
24395
|
-
* {
|
|
24396
|
-
margin: 0;
|
|
24397
|
-
padding: 0;
|
|
24418
|
+
async function createDocxDocument(payload) {
|
|
24419
|
+
const { data: data2, options } = payload;
|
|
24420
|
+
const editorOptions = options;
|
|
24421
|
+
const context = createSerializeContext();
|
|
24422
|
+
const headerChildren = editorOptions.header.disabled ? [] : await serializeElementList(data2.header || [], editorOptions, context);
|
|
24423
|
+
const docxFooterElementList = forceDocxFooterTextColor(data2.footer || []);
|
|
24424
|
+
const footerChildren = editorOptions.footer.disabled ? [] : await serializeElementList(
|
|
24425
|
+
docxFooterElementList,
|
|
24426
|
+
editorOptions,
|
|
24427
|
+
context
|
|
24428
|
+
);
|
|
24429
|
+
const pageNumberParagraph = createPageNumberParagraph(
|
|
24430
|
+
{
|
|
24431
|
+
...editorOptions.pageNumber,
|
|
24432
|
+
color: DOCX_FOOTER_TEXT_COLOR
|
|
24433
|
+
}
|
|
24434
|
+
);
|
|
24435
|
+
if (pageNumberParagraph) {
|
|
24436
|
+
footerChildren.push(pageNumberParagraph);
|
|
24398
24437
|
}
|
|
24399
|
-
|
|
24400
|
-
|
|
24401
|
-
|
|
24402
|
-
|
|
24403
|
-
|
|
24404
|
-
|
|
24405
|
-
|
|
24406
|
-
|
|
24407
|
-
|
|
24408
|
-
|
|
24409
|
-
|
|
24410
|
-
|
|
24411
|
-
|
|
24412
|
-
|
|
24438
|
+
const sectionChildren = await serializeElementList(
|
|
24439
|
+
data2.main,
|
|
24440
|
+
editorOptions,
|
|
24441
|
+
context
|
|
24442
|
+
);
|
|
24443
|
+
const { width, height, paperDirection } = editorOptions;
|
|
24444
|
+
const pageWidth = paperDirection === "horizontal" /* HORIZONTAL */ ? height : width;
|
|
24445
|
+
const pageHeight = paperDirection === "horizontal" /* HORIZONTAL */ ? width : height;
|
|
24446
|
+
return new Document2({
|
|
24447
|
+
features: {
|
|
24448
|
+
updateFields: true
|
|
24449
|
+
},
|
|
24450
|
+
numbering: {
|
|
24451
|
+
config: createNumberingConfig()
|
|
24452
|
+
},
|
|
24453
|
+
sections: [
|
|
24413
24454
|
{
|
|
24414
|
-
|
|
24455
|
+
properties: {
|
|
24456
|
+
page: {
|
|
24457
|
+
size: {
|
|
24458
|
+
width: pxToTwips(pageWidth),
|
|
24459
|
+
height: pxToTwips(pageHeight),
|
|
24460
|
+
orientation: paperDirection === "horizontal" /* HORIZONTAL */ ? PageOrientation.LANDSCAPE : PageOrientation.PORTRAIT
|
|
24461
|
+
},
|
|
24462
|
+
margin: {
|
|
24463
|
+
top: pxToTwips(editorOptions.margins[0]),
|
|
24464
|
+
right: pxToTwips(editorOptions.margins[1]),
|
|
24465
|
+
bottom: pxToTwips(editorOptions.margins[2]),
|
|
24466
|
+
left: pxToTwips(editorOptions.margins[3]),
|
|
24467
|
+
header: pxToTwips(editorOptions.header.top),
|
|
24468
|
+
footer: pxToTwips(editorOptions.footer.bottom)
|
|
24469
|
+
},
|
|
24470
|
+
pageNumbers: !editorOptions.pageNumber.disabled && editorOptions.pageNumber.fromPageNo === 0 ? {
|
|
24471
|
+
start: editorOptions.pageNumber.startPageNo
|
|
24472
|
+
} : void 0
|
|
24473
|
+
}
|
|
24474
|
+
},
|
|
24475
|
+
headers: headerChildren.length > 0 ? {
|
|
24476
|
+
default: new Header2({
|
|
24477
|
+
children: headerChildren
|
|
24478
|
+
})
|
|
24479
|
+
} : void 0,
|
|
24480
|
+
footers: footerChildren.length > 0 ? {
|
|
24481
|
+
default: new Footer2({
|
|
24482
|
+
children: footerChildren
|
|
24483
|
+
})
|
|
24484
|
+
} : void 0,
|
|
24485
|
+
children: sectionChildren.length ? sectionChildren : [new Paragraph({})]
|
|
24415
24486
|
}
|
|
24416
|
-
|
|
24487
|
+
]
|
|
24417
24488
|
});
|
|
24418
24489
|
}
|
|
24419
|
-
|
|
24420
|
-
|
|
24421
|
-
|
|
24422
|
-
|
|
24423
|
-
|
|
24424
|
-
|
|
24425
|
-
|
|
24426
|
-
|
|
24427
|
-
|
|
24428
|
-
|
|
24429
|
-
|
|
24430
|
-
|
|
24431
|
-
|
|
24432
|
-
|
|
24433
|
-
|
|
24434
|
-
|
|
24490
|
+
async function serializeElementList(elementList, options, context) {
|
|
24491
|
+
const blocks = [];
|
|
24492
|
+
let inlineBuffer = [];
|
|
24493
|
+
const flushInlineBuffer = async () => {
|
|
24494
|
+
if (!inlineBuffer.length) return;
|
|
24495
|
+
blocks.push(
|
|
24496
|
+
...await serializeInlineElements(inlineBuffer, options, context)
|
|
24497
|
+
);
|
|
24498
|
+
inlineBuffer = [];
|
|
24499
|
+
};
|
|
24500
|
+
for (let i = 0; i < elementList.length; i++) {
|
|
24501
|
+
const element = elementList[i];
|
|
24502
|
+
if (element.type === "area" /* AREA */ && element.valueList?.length) {
|
|
24503
|
+
await flushInlineBuffer();
|
|
24504
|
+
blocks.push(
|
|
24505
|
+
...await serializeElementList(element.valueList, options, context)
|
|
24506
|
+
);
|
|
24507
|
+
continue;
|
|
24508
|
+
}
|
|
24509
|
+
if (element.type === "title" /* TITLE */ && element.valueList?.length) {
|
|
24510
|
+
await flushInlineBuffer();
|
|
24511
|
+
blocks.push(
|
|
24512
|
+
...await serializeInlineElements(element.valueList, options, context, {
|
|
24513
|
+
heading: titleHeadingMap[element.level || "first" /* FIRST */]
|
|
24514
|
+
})
|
|
24515
|
+
);
|
|
24516
|
+
continue;
|
|
24517
|
+
}
|
|
24518
|
+
if (element.type === "list" /* LIST */ && element.valueList?.length) {
|
|
24519
|
+
await flushInlineBuffer();
|
|
24520
|
+
blocks.push(...await serializeListElement(element, options, context));
|
|
24521
|
+
continue;
|
|
24522
|
+
}
|
|
24523
|
+
if (element.type === "table" /* TABLE */ && element.trList?.length) {
|
|
24524
|
+
await flushInlineBuffer();
|
|
24525
|
+
blocks.push(await serializeTableElement(element, options, context));
|
|
24526
|
+
continue;
|
|
24527
|
+
}
|
|
24528
|
+
if (element.type === "pageBreak" /* PAGE_BREAK */) {
|
|
24529
|
+
await flushInlineBuffer();
|
|
24530
|
+
blocks.push(
|
|
24531
|
+
new Paragraph({
|
|
24532
|
+
children: [new PageBreak()]
|
|
24533
|
+
})
|
|
24534
|
+
);
|
|
24535
|
+
continue;
|
|
24536
|
+
}
|
|
24537
|
+
if (element.type === "separator" /* SEPARATOR */) {
|
|
24538
|
+
await flushInlineBuffer();
|
|
24539
|
+
blocks.push(
|
|
24540
|
+
new Paragraph({
|
|
24541
|
+
thematicBreak: true
|
|
24542
|
+
})
|
|
24543
|
+
);
|
|
24544
|
+
continue;
|
|
24545
|
+
}
|
|
24546
|
+
if (element.type === "image" /* IMAGE */ && element.imgDisplay && element.imgDisplay !== "inline") {
|
|
24547
|
+
await flushInlineBuffer();
|
|
24548
|
+
blocks.push(...await serializeInlineElements([element], options));
|
|
24549
|
+
continue;
|
|
24550
|
+
}
|
|
24551
|
+
if (element.type === "block" /* BLOCK */) {
|
|
24552
|
+
await flushInlineBuffer();
|
|
24553
|
+
const blockText = getBlockFallbackText(element);
|
|
24554
|
+
if (blockText) {
|
|
24555
|
+
blocks.push(
|
|
24556
|
+
...await serializeInlineElements(
|
|
24557
|
+
[{ value: blockText }],
|
|
24558
|
+
options,
|
|
24559
|
+
context
|
|
24560
|
+
)
|
|
24561
|
+
);
|
|
24562
|
+
}
|
|
24563
|
+
continue;
|
|
24564
|
+
}
|
|
24565
|
+
inlineBuffer.push(element);
|
|
24435
24566
|
}
|
|
24436
|
-
|
|
24437
|
-
|
|
24438
|
-
|
|
24439
|
-
|
|
24440
|
-
|
|
24441
|
-
|
|
24442
|
-
|
|
24443
|
-
|
|
24444
|
-
|
|
24445
|
-
|
|
24446
|
-
|
|
24447
|
-
|
|
24448
|
-
|
|
24449
|
-
|
|
24450
|
-
|
|
24451
|
-
|
|
24567
|
+
await flushInlineBuffer();
|
|
24568
|
+
return blocks;
|
|
24569
|
+
}
|
|
24570
|
+
async function serializeInlineElements(elementList, options, _context, overrides = {}) {
|
|
24571
|
+
const paragraphs = [];
|
|
24572
|
+
let current = null;
|
|
24573
|
+
const getParagraphContext = (element) => ({
|
|
24574
|
+
heading: overrides.heading,
|
|
24575
|
+
numbering: overrides.numbering,
|
|
24576
|
+
alignment: overrides.alignment !== void 0 ? overrides.alignment : mapRowFlexToAlignment(element?.rowFlex),
|
|
24577
|
+
rowMargin: overrides.rowMargin !== void 0 ? overrides.rowMargin : element?.rowMargin
|
|
24578
|
+
});
|
|
24579
|
+
const flushParagraph = (context) => {
|
|
24580
|
+
if (!current) {
|
|
24581
|
+
if (!context) return;
|
|
24582
|
+
paragraphs.push(createParagraph([], context, options.defaultRowMargin));
|
|
24583
|
+
return;
|
|
24584
|
+
}
|
|
24585
|
+
paragraphs.push(
|
|
24586
|
+
createParagraph(
|
|
24587
|
+
current.children,
|
|
24588
|
+
current.context,
|
|
24589
|
+
options.defaultRowMargin
|
|
24590
|
+
)
|
|
24591
|
+
);
|
|
24592
|
+
current = null;
|
|
24593
|
+
};
|
|
24594
|
+
const ensureParagraph = (element) => {
|
|
24595
|
+
if (!current) {
|
|
24596
|
+
current = {
|
|
24597
|
+
children: [],
|
|
24598
|
+
context: getParagraphContext(element)
|
|
24599
|
+
};
|
|
24600
|
+
}
|
|
24601
|
+
return current;
|
|
24602
|
+
};
|
|
24603
|
+
const appendText = (element, text, childFactory, preserveTrailingBreak = false) => {
|
|
24604
|
+
const normalized = normalizeText(text);
|
|
24605
|
+
const parts = normalized.split("\n");
|
|
24606
|
+
let lastSeparatorFlushedContent = false;
|
|
24607
|
+
for (let i = 0; i < parts.length; i++) {
|
|
24608
|
+
const segment = parts[i];
|
|
24609
|
+
if (segment) {
|
|
24610
|
+
ensureParagraph(element).children.push(childFactory(segment));
|
|
24611
|
+
}
|
|
24612
|
+
if (i < parts.length - 1) {
|
|
24613
|
+
if (!current) {
|
|
24614
|
+
paragraphs.push(
|
|
24615
|
+
createParagraph(
|
|
24616
|
+
[],
|
|
24617
|
+
getParagraphContext(element),
|
|
24618
|
+
options.defaultRowMargin
|
|
24619
|
+
)
|
|
24620
|
+
);
|
|
24621
|
+
lastSeparatorFlushedContent = false;
|
|
24622
|
+
} else {
|
|
24623
|
+
flushParagraph();
|
|
24624
|
+
lastSeparatorFlushedContent = true;
|
|
24452
24625
|
}
|
|
24453
|
-
result.push(element);
|
|
24454
24626
|
}
|
|
24455
|
-
};
|
|
24456
|
-
collect(selection);
|
|
24457
|
-
if (!textLikeOnly) {
|
|
24458
|
-
return result;
|
|
24459
24627
|
}
|
|
24460
|
-
|
|
24461
|
-
(
|
|
24628
|
+
if (preserveTrailingBreak && normalized.endsWith("\n") && lastSeparatorFlushedContent) {
|
|
24629
|
+
paragraphs.push(
|
|
24630
|
+
createParagraph(
|
|
24631
|
+
[],
|
|
24632
|
+
getParagraphContext(element),
|
|
24633
|
+
options.defaultRowMargin
|
|
24634
|
+
)
|
|
24635
|
+
);
|
|
24636
|
+
}
|
|
24637
|
+
};
|
|
24638
|
+
for (let i = 0; i < elementList.length; i++) {
|
|
24639
|
+
const element = elementList[i];
|
|
24640
|
+
if (element.type === "hyperlink" /* HYPERLINK */ && element.valueList?.length) {
|
|
24641
|
+
const hyperlink = await createHyperlinkChild(element, options);
|
|
24642
|
+
if (hyperlink) {
|
|
24643
|
+
ensureParagraph(element).children.push(hyperlink);
|
|
24644
|
+
}
|
|
24645
|
+
continue;
|
|
24646
|
+
}
|
|
24647
|
+
if (element.type === "image" /* IMAGE */) {
|
|
24648
|
+
const imageChild = await createImageChild(element);
|
|
24649
|
+
if (!imageChild) {
|
|
24650
|
+
appendText(
|
|
24651
|
+
element,
|
|
24652
|
+
"[Image unavailable]",
|
|
24653
|
+
(segment) => createTextRun(
|
|
24654
|
+
segment,
|
|
24655
|
+
element,
|
|
24656
|
+
options.defaultSize,
|
|
24657
|
+
options.defaultFont
|
|
24658
|
+
),
|
|
24659
|
+
i === elementList.length - 1
|
|
24660
|
+
);
|
|
24661
|
+
continue;
|
|
24662
|
+
}
|
|
24663
|
+
ensureParagraph(element).children.push(imageChild);
|
|
24664
|
+
continue;
|
|
24665
|
+
}
|
|
24666
|
+
if (element.type === "columnBreak" /* COLUMN_BREAK */) {
|
|
24667
|
+
ensureParagraph(element).children.push(new ColumnBreak());
|
|
24668
|
+
continue;
|
|
24669
|
+
}
|
|
24670
|
+
if (element.type === "tab" /* TAB */) {
|
|
24671
|
+
appendText(
|
|
24672
|
+
element,
|
|
24673
|
+
" ",
|
|
24674
|
+
(segment) => createTextRun(
|
|
24675
|
+
segment,
|
|
24676
|
+
element,
|
|
24677
|
+
options.defaultSize,
|
|
24678
|
+
options.defaultFont
|
|
24679
|
+
),
|
|
24680
|
+
i === elementList.length - 1
|
|
24681
|
+
);
|
|
24682
|
+
continue;
|
|
24683
|
+
}
|
|
24684
|
+
const textValue = getInlineElementText(element);
|
|
24685
|
+
if (!textValue) {
|
|
24686
|
+
continue;
|
|
24687
|
+
}
|
|
24688
|
+
appendText(
|
|
24689
|
+
element,
|
|
24690
|
+
textValue,
|
|
24691
|
+
(segment) => createTextRun(
|
|
24692
|
+
segment,
|
|
24693
|
+
element,
|
|
24694
|
+
options.defaultSize,
|
|
24695
|
+
options.defaultFont
|
|
24696
|
+
),
|
|
24697
|
+
i === elementList.length - 1
|
|
24462
24698
|
);
|
|
24463
24699
|
}
|
|
24464
|
-
|
|
24465
|
-
|
|
24700
|
+
if (current) {
|
|
24701
|
+
flushParagraph();
|
|
24466
24702
|
}
|
|
24467
|
-
|
|
24468
|
-
|
|
24469
|
-
|
|
24470
|
-
|
|
24703
|
+
return paragraphs.length ? paragraphs : [createParagraph([], overrides, options.defaultRowMargin)];
|
|
24704
|
+
}
|
|
24705
|
+
async function serializeListElement(element, options, context) {
|
|
24706
|
+
const zipList = zipElementList(element.valueList || []);
|
|
24707
|
+
const listItemMap = splitListElement(zipList);
|
|
24708
|
+
const paragraphs = [];
|
|
24709
|
+
const listInstance = createListInstance(context);
|
|
24710
|
+
for (const listItemElements of listItemMap.values()) {
|
|
24711
|
+
const numbering = getListNumbering(
|
|
24712
|
+
getListItemNumberingElement(listItemElements, element),
|
|
24713
|
+
listInstance
|
|
24714
|
+
);
|
|
24715
|
+
paragraphs.push(
|
|
24716
|
+
...await serializeInlineElements(listItemElements, options, context, {
|
|
24717
|
+
numbering
|
|
24718
|
+
})
|
|
24719
|
+
);
|
|
24471
24720
|
}
|
|
24472
|
-
|
|
24473
|
-
|
|
24721
|
+
return paragraphs;
|
|
24722
|
+
}
|
|
24723
|
+
async function serializeTableElement(element, options, context) {
|
|
24724
|
+
const rows = [];
|
|
24725
|
+
const trList = element.trList || [];
|
|
24726
|
+
const tableContext = createTableSerializeContext(element);
|
|
24727
|
+
for (let i = 0; i < trList.length; i++) {
|
|
24728
|
+
rows.push(
|
|
24729
|
+
await serializeTableRow(trList[i], options, context, tableContext)
|
|
24730
|
+
);
|
|
24474
24731
|
}
|
|
24475
|
-
|
|
24476
|
-
|
|
24477
|
-
|
|
24478
|
-
|
|
24732
|
+
const tableWidth = getTableWidthFromColgroup(element.colgroup);
|
|
24733
|
+
return new Table({
|
|
24734
|
+
rows,
|
|
24735
|
+
width: tableWidth ? {
|
|
24736
|
+
size: pxToTwips(tableWidth),
|
|
24737
|
+
type: WidthType.DXA
|
|
24738
|
+
} : {
|
|
24739
|
+
size: 100,
|
|
24740
|
+
type: WidthType.PERCENTAGE
|
|
24741
|
+
},
|
|
24742
|
+
columnWidths: element.colgroup?.map((col) => pxToTwips(col.width)),
|
|
24743
|
+
layout: TableLayoutType.FIXED,
|
|
24744
|
+
borders: createTableBorders(element)
|
|
24745
|
+
});
|
|
24746
|
+
}
|
|
24747
|
+
async function serializeTableRow(tr, options, context, tableContext) {
|
|
24748
|
+
const children = [];
|
|
24749
|
+
for (let i = 0; i < tr.tdList.length; i++) {
|
|
24750
|
+
children.push(
|
|
24751
|
+
await serializeTableCell(tr.tdList[i], options, context, tableContext)
|
|
24752
|
+
);
|
|
24479
24753
|
}
|
|
24480
|
-
|
|
24481
|
-
|
|
24754
|
+
return new TableRow({
|
|
24755
|
+
children
|
|
24756
|
+
});
|
|
24757
|
+
}
|
|
24758
|
+
async function serializeTableCell(td, options, context, tableContext) {
|
|
24759
|
+
const children = await serializeElementList(td.value, options, context);
|
|
24760
|
+
const shadingFill = td.backgroundColor ? normalizeHexColor(td.backgroundColor) : void 0;
|
|
24761
|
+
const cellWidth = tableContext.cellLayoutMap.get(td)?.width || td.width;
|
|
24762
|
+
return new TableCell({
|
|
24763
|
+
children: children.length ? children : [new Paragraph({})],
|
|
24764
|
+
columnSpan: td.colspan > 1 ? td.colspan : void 0,
|
|
24765
|
+
rowSpan: td.rowspan > 1 ? td.rowspan : void 0,
|
|
24766
|
+
verticalAlign: mapCellVerticalAlign(td.verticalAlign),
|
|
24767
|
+
width: cellWidth ? {
|
|
24768
|
+
size: pxToTwips(cellWidth),
|
|
24769
|
+
type: WidthType.DXA
|
|
24770
|
+
} : void 0,
|
|
24771
|
+
shading: shadingFill ? {
|
|
24772
|
+
fill: shadingFill,
|
|
24773
|
+
type: ShadingType.CLEAR
|
|
24774
|
+
} : void 0,
|
|
24775
|
+
margins: mapPaddingToTableMargins(td.padding),
|
|
24776
|
+
borders: createTableCellBorders(
|
|
24777
|
+
td,
|
|
24778
|
+
tableContext.borderColor,
|
|
24779
|
+
tableContext.borderWidth
|
|
24780
|
+
)
|
|
24781
|
+
});
|
|
24782
|
+
}
|
|
24783
|
+
function createParagraph(children, context, defaultRowMargin) {
|
|
24784
|
+
return new Paragraph({
|
|
24785
|
+
children,
|
|
24786
|
+
heading: context.heading,
|
|
24787
|
+
numbering: context.numbering,
|
|
24788
|
+
alignment: context.alignment,
|
|
24789
|
+
spacing: {
|
|
24790
|
+
line: Math.round(
|
|
24791
|
+
240 * (context.rowMargin || defaultRowMargin || DEFAULT_LINE_HEIGHT)
|
|
24792
|
+
),
|
|
24793
|
+
lineRule: LineRuleType.AUTO
|
|
24794
|
+
}
|
|
24795
|
+
});
|
|
24796
|
+
}
|
|
24797
|
+
function createTextRun(text, element, defaultSize, defaultFont) {
|
|
24798
|
+
const color = element.color ? normalizeHexColor(element.color, "000000") : void 0;
|
|
24799
|
+
const highlightFill = element.highlight ? normalizeHexColor(element.highlight) : void 0;
|
|
24800
|
+
return new TextRun({
|
|
24801
|
+
text,
|
|
24802
|
+
bold: !!element.bold,
|
|
24803
|
+
italics: !!element.italic,
|
|
24804
|
+
strike: !!element.strikeout,
|
|
24805
|
+
subScript: element.type === "subscript" /* SUBSCRIPT */,
|
|
24806
|
+
superScript: element.type === "superscript" /* SUPERSCRIPT */,
|
|
24807
|
+
color,
|
|
24808
|
+
shading: highlightFill ? {
|
|
24809
|
+
fill: highlightFill,
|
|
24810
|
+
type: ShadingType.CLEAR
|
|
24811
|
+
} : void 0,
|
|
24812
|
+
underline: element.underline ? {
|
|
24813
|
+
type: mapUnderlineType(element.textDecoration?.style)
|
|
24814
|
+
} : void 0,
|
|
24815
|
+
font: element.font || defaultFont,
|
|
24816
|
+
size: Math.round((element.size || defaultSize) * 2)
|
|
24817
|
+
});
|
|
24818
|
+
}
|
|
24819
|
+
async function createHyperlinkChild(element, options) {
|
|
24820
|
+
if (!element.url) {
|
|
24821
|
+
const fallbackText = getTextFromElementList(element.valueList || []);
|
|
24822
|
+
return fallbackText ? createTextRun(
|
|
24823
|
+
fallbackText,
|
|
24824
|
+
element.valueList?.[0] || element,
|
|
24825
|
+
options.defaultSize,
|
|
24826
|
+
options.defaultFont
|
|
24827
|
+
) : null;
|
|
24828
|
+
}
|
|
24829
|
+
const children = await createHyperlinkRuns(
|
|
24830
|
+
element.valueList || [],
|
|
24831
|
+
options.defaultSize,
|
|
24832
|
+
options.defaultFont
|
|
24833
|
+
);
|
|
24834
|
+
if (!children.length) {
|
|
24835
|
+
return null;
|
|
24482
24836
|
}
|
|
24483
|
-
|
|
24484
|
-
|
|
24485
|
-
|
|
24486
|
-
|
|
24487
|
-
|
|
24488
|
-
|
|
24489
|
-
|
|
24490
|
-
|
|
24837
|
+
return new ExternalHyperlink({
|
|
24838
|
+
link: element.url,
|
|
24839
|
+
children
|
|
24840
|
+
});
|
|
24841
|
+
}
|
|
24842
|
+
async function createHyperlinkRuns(valueList, defaultSize, defaultFont) {
|
|
24843
|
+
const children = [];
|
|
24844
|
+
for (let i = 0; i < valueList.length; i++) {
|
|
24845
|
+
const element = valueList[i];
|
|
24846
|
+
if (element.type === "tab" /* TAB */) {
|
|
24847
|
+
children.push(createTextRun(" ", element, defaultSize, defaultFont));
|
|
24848
|
+
continue;
|
|
24491
24849
|
}
|
|
24492
|
-
|
|
24493
|
-
|
|
24494
|
-
|
|
24495
|
-
|
|
24496
|
-
|
|
24497
|
-
);
|
|
24498
|
-
} else {
|
|
24499
|
-
this.draw.spliceElementList(elementList, startIndex, 1);
|
|
24850
|
+
const text = normalizeText(getInlineElementText(element)).replace(
|
|
24851
|
+
/\n/g,
|
|
24852
|
+
" "
|
|
24853
|
+
);
|
|
24854
|
+
if (text) {
|
|
24855
|
+
children.push(createTextRun(text, element, defaultSize, defaultFont));
|
|
24500
24856
|
}
|
|
24501
|
-
const curIndex = isCollapsed ? startIndex - 1 : startIndex;
|
|
24502
|
-
this.range.setRange(curIndex, curIndex);
|
|
24503
|
-
this.draw.render({ curIndex });
|
|
24504
24857
|
}
|
|
24505
|
-
|
|
24506
|
-
|
|
24858
|
+
return children;
|
|
24859
|
+
}
|
|
24860
|
+
async function createImageChild(element) {
|
|
24861
|
+
try {
|
|
24862
|
+
const image = await loadImagePayload(element.value);
|
|
24863
|
+
const width = Math.max(1, Math.round(element.width || DEFAULT_IMAGE_WIDTH));
|
|
24864
|
+
const height = Math.max(
|
|
24865
|
+
1,
|
|
24866
|
+
Math.round(element.height || DEFAULT_IMAGE_HEIGHT)
|
|
24867
|
+
);
|
|
24868
|
+
if (image.type === "svg" && image.fallbackPng) {
|
|
24869
|
+
return new ImageRun({
|
|
24870
|
+
type: "svg",
|
|
24871
|
+
data: image.data,
|
|
24872
|
+
fallback: {
|
|
24873
|
+
type: "png",
|
|
24874
|
+
data: image.fallbackPng
|
|
24875
|
+
},
|
|
24876
|
+
transformation: {
|
|
24877
|
+
width,
|
|
24878
|
+
height
|
|
24879
|
+
}
|
|
24880
|
+
});
|
|
24881
|
+
}
|
|
24882
|
+
return new ImageRun({
|
|
24883
|
+
type: image.type,
|
|
24884
|
+
data: image.data,
|
|
24885
|
+
transformation: {
|
|
24886
|
+
width,
|
|
24887
|
+
height
|
|
24888
|
+
}
|
|
24889
|
+
});
|
|
24890
|
+
} catch {
|
|
24891
|
+
return null;
|
|
24892
|
+
}
|
|
24893
|
+
}
|
|
24894
|
+
async function loadImagePayload(src) {
|
|
24895
|
+
const source = src.trim();
|
|
24896
|
+
if (source.startsWith("data:")) {
|
|
24897
|
+
return getImagePayloadFromDataUrl(source);
|
|
24898
|
+
}
|
|
24899
|
+
const response = await fetch(source);
|
|
24900
|
+
if (!response.ok) {
|
|
24901
|
+
throw new Error(`Image request failed: ${response.status}`);
|
|
24902
|
+
}
|
|
24903
|
+
const contentType = response.headers.get("content-type") || "";
|
|
24904
|
+
const data2 = await response.arrayBuffer();
|
|
24905
|
+
return normalizeImagePayload(data2, contentType);
|
|
24906
|
+
}
|
|
24907
|
+
async function getImagePayloadFromDataUrl(src) {
|
|
24908
|
+
const [, meta = "", encoded = ""] = src.match(/^data:([^,]*),(.*)$/) || [];
|
|
24909
|
+
const mime = meta.split(";")[0] || "";
|
|
24910
|
+
const isBase64 = meta.includes(";base64");
|
|
24911
|
+
const text = isBase64 ? atob(encoded) : decodeURIComponent(encoded);
|
|
24912
|
+
const bytes = new Uint8Array(text.length);
|
|
24913
|
+
for (let i = 0; i < text.length; i++) {
|
|
24914
|
+
bytes[i] = text.charCodeAt(i);
|
|
24915
|
+
}
|
|
24916
|
+
return normalizeImagePayload(bytes.buffer, mime);
|
|
24917
|
+
}
|
|
24918
|
+
async function normalizeImagePayload(data2, mime) {
|
|
24919
|
+
const type = getRegularImageType(mime);
|
|
24920
|
+
if (type) {
|
|
24921
|
+
return {
|
|
24922
|
+
type,
|
|
24923
|
+
data: data2
|
|
24924
|
+
};
|
|
24925
|
+
}
|
|
24926
|
+
if (mime.includes("svg")) {
|
|
24927
|
+
return {
|
|
24928
|
+
type: "svg",
|
|
24929
|
+
data: data2,
|
|
24930
|
+
fallbackPng: await rasterizeSvgToPng(data2)
|
|
24931
|
+
};
|
|
24932
|
+
}
|
|
24933
|
+
const fallbackPng = await rasterizeImageToPng(data2, mime);
|
|
24934
|
+
return {
|
|
24935
|
+
type: "png",
|
|
24936
|
+
data: fallbackPng
|
|
24937
|
+
};
|
|
24938
|
+
}
|
|
24939
|
+
async function rasterizeSvgToPng(data2) {
|
|
24940
|
+
return rasterizeImageToPng(data2, "image/svg+xml");
|
|
24941
|
+
}
|
|
24942
|
+
async function rasterizeImageToPng(data2, mime) {
|
|
24943
|
+
const blob = new Blob([data2], {
|
|
24944
|
+
type: mime || "image/png"
|
|
24945
|
+
});
|
|
24946
|
+
const url = URL.createObjectURL(blob);
|
|
24947
|
+
try {
|
|
24948
|
+
const image = await loadHtmlImage(url);
|
|
24949
|
+
const canvas = document.createElement("canvas");
|
|
24950
|
+
canvas.width = image.naturalWidth || DEFAULT_IMAGE_WIDTH;
|
|
24951
|
+
canvas.height = image.naturalHeight || DEFAULT_IMAGE_HEIGHT;
|
|
24952
|
+
const context = canvas.getContext("2d");
|
|
24953
|
+
if (!context) {
|
|
24954
|
+
throw new Error("Canvas context is unavailable");
|
|
24955
|
+
}
|
|
24956
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
24957
|
+
const pngBlob = await new Promise((resolve, reject) => {
|
|
24958
|
+
canvas.toBlob((output) => {
|
|
24959
|
+
if (output) {
|
|
24960
|
+
resolve(output);
|
|
24961
|
+
} else {
|
|
24962
|
+
reject(new Error("Failed to create PNG blob"));
|
|
24963
|
+
}
|
|
24964
|
+
}, "image/png");
|
|
24965
|
+
});
|
|
24966
|
+
return await pngBlob.arrayBuffer();
|
|
24967
|
+
} finally {
|
|
24968
|
+
URL.revokeObjectURL(url);
|
|
24969
|
+
}
|
|
24970
|
+
}
|
|
24971
|
+
function loadHtmlImage(src) {
|
|
24972
|
+
return new Promise((resolve, reject) => {
|
|
24973
|
+
const image = new Image();
|
|
24974
|
+
image.onload = () => resolve(image);
|
|
24975
|
+
image.onerror = () => reject(new Error("Failed to load image"));
|
|
24976
|
+
image.src = src;
|
|
24977
|
+
});
|
|
24978
|
+
}
|
|
24979
|
+
function createPageNumberParagraph(pageNumber) {
|
|
24980
|
+
if (pageNumber.disabled || pageNumber.fromPageNo > 0) {
|
|
24981
|
+
return null;
|
|
24982
|
+
}
|
|
24983
|
+
const children = [];
|
|
24984
|
+
const format = pageNumber.format || FORMAT_PLACEHOLDER.PAGE_NO;
|
|
24985
|
+
const tokens = format.split(/(\{pageNo\}|\{pageCount\})/);
|
|
24986
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
24987
|
+
const token = tokens[i];
|
|
24988
|
+
if (!token) continue;
|
|
24989
|
+
const runChildren = token === FORMAT_PLACEHOLDER.PAGE_NO ? [PageNumber2.CURRENT] : token === FORMAT_PLACEHOLDER.PAGE_COUNT ? [PageNumber2.TOTAL_PAGES] : void 0;
|
|
24990
|
+
children.push(
|
|
24991
|
+
new TextRun({
|
|
24992
|
+
text: runChildren ? void 0 : token,
|
|
24993
|
+
children: runChildren,
|
|
24994
|
+
color: normalizeHexColor(pageNumber.color || "#000000", "000000"),
|
|
24995
|
+
font: pageNumber.font,
|
|
24996
|
+
size: Math.round((pageNumber.size || 12) * 2)
|
|
24997
|
+
})
|
|
24998
|
+
);
|
|
24999
|
+
}
|
|
25000
|
+
return new Paragraph({
|
|
25001
|
+
children,
|
|
25002
|
+
alignment: mapRowFlexToAlignment(pageNumber.rowFlex)
|
|
25003
|
+
});
|
|
25004
|
+
}
|
|
25005
|
+
function forceDocxFooterTextColor(elementList) {
|
|
25006
|
+
const footerElementList = deepClone(elementList);
|
|
25007
|
+
forceColorValue(footerElementList);
|
|
25008
|
+
return footerElementList;
|
|
25009
|
+
}
|
|
25010
|
+
function forceColorValue(value) {
|
|
25011
|
+
if (!value || typeof value !== "object") {
|
|
25012
|
+
return;
|
|
25013
|
+
}
|
|
25014
|
+
if (Array.isArray(value)) {
|
|
25015
|
+
for (let i = 0; i < value.length; i++) {
|
|
25016
|
+
forceColorValue(value[i]);
|
|
25017
|
+
}
|
|
25018
|
+
return;
|
|
25019
|
+
}
|
|
25020
|
+
const record = value;
|
|
25021
|
+
if ("color" in record) {
|
|
25022
|
+
record.color = DOCX_FOOTER_TEXT_COLOR;
|
|
25023
|
+
}
|
|
25024
|
+
const keys = Object.keys(record);
|
|
25025
|
+
for (let i = 0; i < keys.length; i++) {
|
|
25026
|
+
forceColorValue(record[keys[i]]);
|
|
25027
|
+
}
|
|
25028
|
+
}
|
|
25029
|
+
function createNumberingConfig() {
|
|
25030
|
+
const config = [
|
|
25031
|
+
createOrderedReference("windoc-ol-decimal", Array(9).fill("decimal" /* DECIMAL */)),
|
|
25032
|
+
createOrderedReference(
|
|
25033
|
+
"windoc-ol-lower-alpha",
|
|
25034
|
+
Array(9).fill("lowerAlpha" /* LOWER_ALPHA */)
|
|
25035
|
+
),
|
|
25036
|
+
createOrderedReference(
|
|
25037
|
+
"windoc-ol-upper-alpha",
|
|
25038
|
+
Array(9).fill("upperAlpha" /* UPPER_ALPHA */)
|
|
25039
|
+
),
|
|
25040
|
+
createOrderedReference(
|
|
25041
|
+
"windoc-ol-lower-roman",
|
|
25042
|
+
Array(9).fill("lowerRoman" /* LOWER_ROMAN */)
|
|
25043
|
+
),
|
|
25044
|
+
createOrderedReference(
|
|
25045
|
+
"windoc-ol-upper-roman",
|
|
25046
|
+
Array(9).fill("upperRoman" /* UPPER_ROMAN */)
|
|
25047
|
+
),
|
|
25048
|
+
createOrderedReference(
|
|
25049
|
+
"windoc-ol-decimal-paren",
|
|
25050
|
+
Array(9).fill("decimalParen" /* DECIMAL_PAREN */)
|
|
25051
|
+
),
|
|
25052
|
+
createOrderedReference(
|
|
25053
|
+
`windoc-ol-${"olDefault" /* DEFAULT */}`,
|
|
25054
|
+
createCycleList(olPresetCycles["olDefault" /* DEFAULT */], 9)
|
|
25055
|
+
),
|
|
25056
|
+
createOrderedReference(
|
|
25057
|
+
`windoc-ol-${"olParen" /* PARENTHESIS */}`,
|
|
25058
|
+
createCycleList(olPresetCycles["olParen" /* PARENTHESIS */], 9)
|
|
25059
|
+
),
|
|
25060
|
+
createOrderedReference(
|
|
25061
|
+
`windoc-ol-${"olOutline" /* OUTLINE */}`,
|
|
25062
|
+
createCycleList(olPresetCycles["olOutline" /* OUTLINE */], 9)
|
|
25063
|
+
),
|
|
25064
|
+
createOrderedReference(
|
|
25065
|
+
`windoc-ol-${"olUpperA" /* UPPER_ALPHA */}`,
|
|
25066
|
+
createCycleList(olPresetCycles["olUpperA" /* UPPER_ALPHA */], 9)
|
|
25067
|
+
),
|
|
25068
|
+
createOrderedReference(
|
|
25069
|
+
`windoc-ol-${"olRoman" /* ROMAN */}`,
|
|
25070
|
+
createCycleList(olPresetCycles["olRoman" /* ROMAN */], 9)
|
|
25071
|
+
),
|
|
25072
|
+
createOrderedReference(
|
|
25073
|
+
`windoc-ol-${"olZeroPad" /* ZERO_PAD */}`,
|
|
25074
|
+
createCycleList(olPresetCycles["olZeroPad" /* ZERO_PAD */], 9)
|
|
25075
|
+
),
|
|
25076
|
+
createBulletReference(
|
|
25077
|
+
"windoc-ul-disc",
|
|
25078
|
+
Array(9).fill(docxBulletCharMap["disc" /* DISC */])
|
|
25079
|
+
),
|
|
25080
|
+
createBulletReference(
|
|
25081
|
+
"windoc-ul-circle",
|
|
25082
|
+
Array(9).fill(docxBulletCharMap["circle" /* CIRCLE */])
|
|
25083
|
+
),
|
|
25084
|
+
createBulletReference(
|
|
25085
|
+
"windoc-ul-square",
|
|
25086
|
+
Array(9).fill(docxBulletCharMap["square" /* SQUARE */])
|
|
25087
|
+
),
|
|
25088
|
+
createBulletReference(
|
|
25089
|
+
"windoc-ul-checkbox",
|
|
25090
|
+
Array(9).fill(docxBulletCharMap["checkbox" /* CHECKBOX */])
|
|
25091
|
+
),
|
|
25092
|
+
createBulletReference(
|
|
25093
|
+
`windoc-ul-${"ulDefault" /* DEFAULT */}`,
|
|
25094
|
+
createCycleList(ulPresetCycles["ulDefault" /* DEFAULT */], 9)
|
|
25095
|
+
),
|
|
25096
|
+
createBulletReference(
|
|
25097
|
+
`windoc-ul-${"ulDiamond" /* DIAMOND */}`,
|
|
25098
|
+
createCycleList(ulPresetCycles["ulDiamond" /* DIAMOND */], 9)
|
|
25099
|
+
),
|
|
25100
|
+
createBulletReference(
|
|
25101
|
+
`windoc-ul-${"ulHollowSq" /* HOLLOW_SQ */}`,
|
|
25102
|
+
createCycleList(ulPresetCycles["ulHollowSq" /* HOLLOW_SQ */], 9)
|
|
25103
|
+
),
|
|
25104
|
+
createBulletReference(
|
|
25105
|
+
`windoc-ul-${"ulArrow" /* ARROW */}`,
|
|
25106
|
+
createCycleList(ulPresetCycles["ulArrow" /* ARROW */], 9)
|
|
25107
|
+
),
|
|
25108
|
+
createBulletReference(
|
|
25109
|
+
`windoc-ul-${"ulStar" /* STAR */}`,
|
|
25110
|
+
createCycleList(ulPresetCycles["ulStar" /* STAR */], 9)
|
|
25111
|
+
),
|
|
25112
|
+
createBulletReference(
|
|
25113
|
+
`windoc-ul-${"ulCheckArr" /* CHECK_ARROW */}`,
|
|
25114
|
+
createCycleList(ulPresetCycles["ulCheckArr" /* CHECK_ARROW */], 9)
|
|
25115
|
+
)
|
|
25116
|
+
];
|
|
25117
|
+
return config;
|
|
25118
|
+
}
|
|
25119
|
+
function createOrderedReference(reference, styles) {
|
|
25120
|
+
return {
|
|
25121
|
+
reference,
|
|
25122
|
+
levels: styles.map((style, level) => ({
|
|
25123
|
+
level,
|
|
25124
|
+
format: orderedStyleFormatMap[style] || LevelFormat.DECIMAL,
|
|
25125
|
+
text: getOrderedLevelText(style, level),
|
|
25126
|
+
alignment: AlignmentType.START,
|
|
25127
|
+
style: {
|
|
25128
|
+
paragraph: {
|
|
25129
|
+
indent: {
|
|
25130
|
+
left: 720 * (level + 1),
|
|
25131
|
+
hanging: 360
|
|
25132
|
+
}
|
|
25133
|
+
}
|
|
25134
|
+
}
|
|
25135
|
+
}))
|
|
25136
|
+
};
|
|
25137
|
+
}
|
|
25138
|
+
function createBulletReference(reference, bullets) {
|
|
25139
|
+
return {
|
|
25140
|
+
reference,
|
|
25141
|
+
levels: bullets.map((bullet, level) => ({
|
|
25142
|
+
level,
|
|
25143
|
+
format: LevelFormat.BULLET,
|
|
25144
|
+
text: bullet,
|
|
25145
|
+
alignment: AlignmentType.START,
|
|
25146
|
+
style: {
|
|
25147
|
+
paragraph: {
|
|
25148
|
+
indent: {
|
|
25149
|
+
left: 720 * (level + 1),
|
|
25150
|
+
hanging: 360
|
|
25151
|
+
}
|
|
25152
|
+
}
|
|
25153
|
+
}
|
|
25154
|
+
}))
|
|
25155
|
+
};
|
|
25156
|
+
}
|
|
25157
|
+
function getOrderedLevelText(style, level) {
|
|
25158
|
+
const placeholder = `%${level + 1}`;
|
|
25159
|
+
if (style === "outline") {
|
|
25160
|
+
return Array.from({ length: level + 1 }, (_, index) => `%${index + 1}`).join(
|
|
25161
|
+
"."
|
|
25162
|
+
) + ".";
|
|
25163
|
+
}
|
|
25164
|
+
if (style.endsWith("Paren") || style === "decimalParen" /* DECIMAL_PAREN */) {
|
|
25165
|
+
return `${placeholder})`;
|
|
25166
|
+
}
|
|
25167
|
+
return `${placeholder}.`;
|
|
25168
|
+
}
|
|
25169
|
+
function createCycleList(source = [], size) {
|
|
25170
|
+
const result = [];
|
|
25171
|
+
for (let i = 0; i < size; i++) {
|
|
25172
|
+
result.push(source[i % source.length]);
|
|
25173
|
+
}
|
|
25174
|
+
return result;
|
|
25175
|
+
}
|
|
25176
|
+
function getListNumbering(element, instance) {
|
|
25177
|
+
const level = Math.max(0, Math.min(element.listLevel || 0, 8));
|
|
25178
|
+
if (element.listType === "ul" /* UL */) {
|
|
25179
|
+
const reference2 = element.listPreset ? `windoc-ul-${element.listPreset}` : `windoc-ul-${element.listStyle || "disc" /* DISC */}`;
|
|
25180
|
+
return {
|
|
25181
|
+
reference: reference2,
|
|
25182
|
+
level,
|
|
25183
|
+
instance
|
|
25184
|
+
};
|
|
25185
|
+
}
|
|
25186
|
+
const reference = element.listPreset ? `windoc-ol-${element.listPreset}` : getOrderedReferenceFromStyle(element.listStyle);
|
|
25187
|
+
return {
|
|
25188
|
+
reference,
|
|
25189
|
+
level,
|
|
25190
|
+
instance
|
|
25191
|
+
};
|
|
25192
|
+
}
|
|
25193
|
+
function getOrderedReferenceFromStyle(style) {
|
|
25194
|
+
switch (style) {
|
|
25195
|
+
case "lowerAlpha" /* LOWER_ALPHA */:
|
|
25196
|
+
return "windoc-ol-lower-alpha";
|
|
25197
|
+
case "upperAlpha" /* UPPER_ALPHA */:
|
|
25198
|
+
return "windoc-ol-upper-alpha";
|
|
25199
|
+
case "lowerRoman" /* LOWER_ROMAN */:
|
|
25200
|
+
return "windoc-ol-lower-roman";
|
|
25201
|
+
case "upperRoman" /* UPPER_ROMAN */:
|
|
25202
|
+
return "windoc-ol-upper-roman";
|
|
25203
|
+
case "decimalParen" /* DECIMAL_PAREN */:
|
|
25204
|
+
return "windoc-ol-decimal-paren";
|
|
25205
|
+
default:
|
|
25206
|
+
return "windoc-ol-decimal";
|
|
25207
|
+
}
|
|
25208
|
+
}
|
|
25209
|
+
function createTableBorders(element) {
|
|
25210
|
+
const outerBorder = createBorder(
|
|
25211
|
+
element.borderColor,
|
|
25212
|
+
BorderStyle.SINGLE,
|
|
25213
|
+
element.borderExternalWidth || element.borderWidth
|
|
25214
|
+
);
|
|
25215
|
+
const innerBorder = createBorder(
|
|
25216
|
+
element.borderColor,
|
|
25217
|
+
BorderStyle.SINGLE,
|
|
25218
|
+
element.borderWidth
|
|
25219
|
+
);
|
|
25220
|
+
switch (element.borderType) {
|
|
25221
|
+
case "empty" /* EMPTY */:
|
|
25222
|
+
return {
|
|
25223
|
+
top: noneBorder(),
|
|
25224
|
+
bottom: noneBorder(),
|
|
25225
|
+
left: noneBorder(),
|
|
25226
|
+
right: noneBorder(),
|
|
25227
|
+
insideHorizontal: noneBorder(),
|
|
25228
|
+
insideVertical: noneBorder()
|
|
25229
|
+
};
|
|
25230
|
+
case "external" /* EXTERNAL */:
|
|
25231
|
+
return {
|
|
25232
|
+
top: outerBorder,
|
|
25233
|
+
bottom: outerBorder,
|
|
25234
|
+
left: outerBorder,
|
|
25235
|
+
right: outerBorder,
|
|
25236
|
+
insideHorizontal: noneBorder(),
|
|
25237
|
+
insideVertical: noneBorder()
|
|
25238
|
+
};
|
|
25239
|
+
case "internal" /* INTERNAL */:
|
|
25240
|
+
return {
|
|
25241
|
+
top: noneBorder(),
|
|
25242
|
+
bottom: noneBorder(),
|
|
25243
|
+
left: noneBorder(),
|
|
25244
|
+
right: noneBorder(),
|
|
25245
|
+
insideHorizontal: innerBorder,
|
|
25246
|
+
insideVertical: innerBorder
|
|
25247
|
+
};
|
|
25248
|
+
case "dash" /* DASH */:
|
|
25249
|
+
return {
|
|
25250
|
+
top: createBorder(
|
|
25251
|
+
element.borderColor,
|
|
25252
|
+
BorderStyle.DASHED,
|
|
25253
|
+
element.borderExternalWidth || element.borderWidth
|
|
25254
|
+
),
|
|
25255
|
+
bottom: createBorder(
|
|
25256
|
+
element.borderColor,
|
|
25257
|
+
BorderStyle.DASHED,
|
|
25258
|
+
element.borderExternalWidth || element.borderWidth
|
|
25259
|
+
),
|
|
25260
|
+
left: createBorder(
|
|
25261
|
+
element.borderColor,
|
|
25262
|
+
BorderStyle.DASHED,
|
|
25263
|
+
element.borderExternalWidth || element.borderWidth
|
|
25264
|
+
),
|
|
25265
|
+
right: createBorder(
|
|
25266
|
+
element.borderColor,
|
|
25267
|
+
BorderStyle.DASHED,
|
|
25268
|
+
element.borderExternalWidth || element.borderWidth
|
|
25269
|
+
),
|
|
25270
|
+
insideHorizontal: createBorder(
|
|
25271
|
+
element.borderColor,
|
|
25272
|
+
BorderStyle.DASHED,
|
|
25273
|
+
element.borderWidth
|
|
25274
|
+
),
|
|
25275
|
+
insideVertical: createBorder(
|
|
25276
|
+
element.borderColor,
|
|
25277
|
+
BorderStyle.DASHED,
|
|
25278
|
+
element.borderWidth
|
|
25279
|
+
)
|
|
25280
|
+
};
|
|
25281
|
+
default:
|
|
25282
|
+
return {
|
|
25283
|
+
top: outerBorder,
|
|
25284
|
+
bottom: outerBorder,
|
|
25285
|
+
left: outerBorder,
|
|
25286
|
+
right: outerBorder,
|
|
25287
|
+
insideHorizontal: innerBorder,
|
|
25288
|
+
insideVertical: innerBorder
|
|
25289
|
+
};
|
|
25290
|
+
}
|
|
25291
|
+
}
|
|
25292
|
+
function createTableCellBorders(td, inheritedColor, inheritedWidth) {
|
|
25293
|
+
if (!td.borderTypes?.length && !td.borderColor) {
|
|
25294
|
+
return void 0;
|
|
25295
|
+
}
|
|
25296
|
+
const color = td.borderColor || inheritedColor;
|
|
25297
|
+
const createCellBorder = () => createBorder(color, BorderStyle.SINGLE, inheritedWidth);
|
|
25298
|
+
if (td.borderColor && !td.borderTypes?.length) {
|
|
25299
|
+
return {
|
|
25300
|
+
top: createCellBorder(),
|
|
25301
|
+
right: createCellBorder(),
|
|
25302
|
+
bottom: createCellBorder(),
|
|
25303
|
+
left: createCellBorder()
|
|
25304
|
+
};
|
|
25305
|
+
}
|
|
25306
|
+
const top = td.borderTypes?.includes("top" /* TOP */) ? createCellBorder() : noneBorder();
|
|
25307
|
+
const right2 = td.borderTypes?.includes("right" /* RIGHT */) ? createCellBorder() : noneBorder();
|
|
25308
|
+
const bottom = td.borderTypes?.includes("bottom" /* BOTTOM */) ? createCellBorder() : noneBorder();
|
|
25309
|
+
const left2 = td.borderTypes?.includes("left" /* LEFT */) ? createCellBorder() : noneBorder();
|
|
25310
|
+
return {
|
|
25311
|
+
top,
|
|
25312
|
+
right: right2,
|
|
25313
|
+
bottom,
|
|
25314
|
+
left: left2
|
|
25315
|
+
};
|
|
25316
|
+
}
|
|
25317
|
+
function createBorder(color = "#000000", style = BorderStyle.SINGLE, width = 1) {
|
|
25318
|
+
return {
|
|
25319
|
+
style,
|
|
25320
|
+
color: normalizeHexColor(color, "000000") || "000000",
|
|
25321
|
+
size: pxBorderToDocxSize(width)
|
|
25322
|
+
};
|
|
25323
|
+
}
|
|
25324
|
+
function noneBorder() {
|
|
25325
|
+
return {
|
|
25326
|
+
style: BorderStyle.NONE,
|
|
25327
|
+
size: 0,
|
|
25328
|
+
color: "FFFFFF"
|
|
25329
|
+
};
|
|
25330
|
+
}
|
|
25331
|
+
function mapPaddingToTableMargins(padding) {
|
|
25332
|
+
if (!padding) return void 0;
|
|
25333
|
+
return {
|
|
25334
|
+
top: pxToTwips(padding[0]),
|
|
25335
|
+
right: pxToTwips(padding[1]),
|
|
25336
|
+
bottom: pxToTwips(padding[2]),
|
|
25337
|
+
left: pxToTwips(padding[3]),
|
|
25338
|
+
marginUnitType: WidthType.DXA
|
|
25339
|
+
};
|
|
25340
|
+
}
|
|
25341
|
+
function mapCellVerticalAlign(verticalAlign) {
|
|
25342
|
+
switch (verticalAlign) {
|
|
25343
|
+
case VerticalAlign.CENTER:
|
|
25344
|
+
return DocxVerticalAlign.CENTER;
|
|
25345
|
+
case "bottom" /* BOTTOM */:
|
|
25346
|
+
return DocxVerticalAlign.BOTTOM;
|
|
25347
|
+
default:
|
|
25348
|
+
return DocxVerticalAlign.TOP;
|
|
25349
|
+
}
|
|
25350
|
+
}
|
|
25351
|
+
function mapRowFlexToAlignment(rowFlex) {
|
|
25352
|
+
switch (rowFlex) {
|
|
25353
|
+
case "center" /* CENTER */:
|
|
25354
|
+
return AlignmentType.CENTER;
|
|
25355
|
+
case "right" /* RIGHT */:
|
|
25356
|
+
return AlignmentType.RIGHT;
|
|
25357
|
+
case "alignment" /* ALIGNMENT */:
|
|
25358
|
+
case "justify" /* JUSTIFY */:
|
|
25359
|
+
return AlignmentType.JUSTIFIED;
|
|
25360
|
+
default:
|
|
25361
|
+
return AlignmentType.LEFT;
|
|
25362
|
+
}
|
|
25363
|
+
}
|
|
25364
|
+
function mapUnderlineType(style) {
|
|
25365
|
+
switch (style) {
|
|
25366
|
+
case "double" /* DOUBLE */:
|
|
25367
|
+
return UnderlineType.DOUBLE;
|
|
25368
|
+
case "dashed" /* DASHED */:
|
|
25369
|
+
return UnderlineType.DASH;
|
|
25370
|
+
case "dotted" /* DOTTED */:
|
|
25371
|
+
return UnderlineType.DOTTED;
|
|
25372
|
+
case "wavy" /* WAVY */:
|
|
25373
|
+
return UnderlineType.WAVE;
|
|
25374
|
+
default:
|
|
25375
|
+
return UnderlineType.SINGLE;
|
|
25376
|
+
}
|
|
25377
|
+
}
|
|
25378
|
+
function getInlineElementText(element) {
|
|
25379
|
+
switch (element.type) {
|
|
25380
|
+
case "control" /* CONTROL */:
|
|
25381
|
+
return getControlText(element.control);
|
|
25382
|
+
case "date" /* DATE */:
|
|
25383
|
+
return element.valueList?.length ? getTextFromElementList(element.valueList) : element.value;
|
|
25384
|
+
case "checkbox" /* CHECKBOX */:
|
|
25385
|
+
return element.checkbox?.value ? "\u2611" : "\u2610";
|
|
25386
|
+
case "radio" /* RADIO */:
|
|
25387
|
+
return element.radio?.value ? "\u25C9" : "\u25CB";
|
|
25388
|
+
case "label" /* LABEL */:
|
|
25389
|
+
case "latex" /* LATEX */:
|
|
25390
|
+
case "subscript" /* SUBSCRIPT */:
|
|
25391
|
+
case "superscript" /* SUPERSCRIPT */:
|
|
25392
|
+
return element.value;
|
|
25393
|
+
default:
|
|
25394
|
+
return element.value;
|
|
25395
|
+
}
|
|
25396
|
+
}
|
|
25397
|
+
function getControlText(control) {
|
|
25398
|
+
if (!control) return "";
|
|
25399
|
+
if (control.type === "text" /* TEXT */ || control.type === "date" /* DATE */ || control.type === "number" /* NUMBER */) {
|
|
25400
|
+
const value = control.value?.length ? getTextFromElementList(control.value) : "";
|
|
25401
|
+
const content = value || control.placeholder || "";
|
|
25402
|
+
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
25403
|
+
}
|
|
25404
|
+
if (control.type === "select" /* SELECT */) {
|
|
25405
|
+
const labels = getSelectedControlLabels(control.code, control.valueSets);
|
|
25406
|
+
const content = labels.length ? labels.join(control.multiSelectDelimiter || ", ") : control.placeholder || "";
|
|
25407
|
+
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
25408
|
+
}
|
|
25409
|
+
if (control.type === "checkbox" /* CHECKBOX */ || control.type === "radio" /* RADIO */) {
|
|
25410
|
+
const isRadio = control.type === "radio" /* RADIO */;
|
|
25411
|
+
return (control.valueSets || []).map((valueSet) => {
|
|
25412
|
+
const checked = control.code?.split(",").includes(valueSet.code) || false;
|
|
25413
|
+
return `${checked ? isRadio ? "\u25C9" : "\u2611" : isRadio ? "\u25CB" : "\u2610"} ${valueSet.value}`;
|
|
25414
|
+
}).join(" ");
|
|
25415
|
+
}
|
|
25416
|
+
return "";
|
|
25417
|
+
}
|
|
25418
|
+
function getSelectedControlLabels(code, valueSets) {
|
|
25419
|
+
if (!code || !valueSets?.length) return [];
|
|
25420
|
+
return code.split(",").map(
|
|
25421
|
+
(selectCode) => valueSets.find((valueSet) => valueSet.code === selectCode)?.value
|
|
25422
|
+
).filter((value) => !!value);
|
|
25423
|
+
}
|
|
25424
|
+
function getBlockFallbackText(element) {
|
|
25425
|
+
if (element.block?.iframeBlock?.src) {
|
|
25426
|
+
return element.block.iframeBlock.src;
|
|
25427
|
+
}
|
|
25428
|
+
if (element.block?.videoBlock?.src) {
|
|
25429
|
+
return element.block.videoBlock.src;
|
|
25430
|
+
}
|
|
25431
|
+
return "";
|
|
25432
|
+
}
|
|
25433
|
+
function normalizeText(text = "") {
|
|
25434
|
+
return text.replace(new RegExp(ZERO, "g"), "").replace(/\r\n/g, "\n");
|
|
25435
|
+
}
|
|
25436
|
+
function createSerializeContext() {
|
|
25437
|
+
return {
|
|
25438
|
+
nextListInstance: 1
|
|
25439
|
+
};
|
|
25440
|
+
}
|
|
25441
|
+
function getListItemNumberingElement(listItemElements, fallback) {
|
|
25442
|
+
return listItemElements.find(
|
|
25443
|
+
(listItem) => listItem.listId || listItem.listLevel !== void 0 || !!listItem.listPreset || !!listItem.listStyle || !!listItem.listType
|
|
25444
|
+
) || fallback;
|
|
25445
|
+
}
|
|
25446
|
+
function createListInstance(context) {
|
|
25447
|
+
return context.nextListInstance++;
|
|
25448
|
+
}
|
|
25449
|
+
function createTableSerializeContext(element) {
|
|
25450
|
+
return {
|
|
25451
|
+
cellLayoutMap: computeTableCellLayout(
|
|
25452
|
+
element.trList || [],
|
|
25453
|
+
element.colgroup || []
|
|
25454
|
+
),
|
|
25455
|
+
borderColor: element.borderColor,
|
|
25456
|
+
borderWidth: element.borderWidth,
|
|
25457
|
+
borderExternalWidth: element.borderExternalWidth
|
|
25458
|
+
};
|
|
25459
|
+
}
|
|
25460
|
+
function computeTableCellLayout(trList, colgroup) {
|
|
25461
|
+
const cellLayoutMap = /* @__PURE__ */ new WeakMap();
|
|
25462
|
+
if (!trList.length || !colgroup.length) {
|
|
25463
|
+
return cellLayoutMap;
|
|
25464
|
+
}
|
|
25465
|
+
const occupiedUntilRow = Array(colgroup.length).fill(0);
|
|
25466
|
+
for (let rowIndex = 0; rowIndex < trList.length; rowIndex++) {
|
|
25467
|
+
const tr = trList[rowIndex];
|
|
25468
|
+
let colIndex = 0;
|
|
25469
|
+
for (let tdIndex = 0; tdIndex < tr.tdList.length; tdIndex++) {
|
|
25470
|
+
while (colIndex < colgroup.length && occupiedUntilRow[colIndex] > rowIndex) {
|
|
25471
|
+
colIndex += 1;
|
|
25472
|
+
}
|
|
25473
|
+
const td = tr.tdList[tdIndex];
|
|
25474
|
+
let width = 0;
|
|
25475
|
+
for (let currentCol = colIndex; currentCol < colIndex + td.colspan && currentCol < colgroup.length; currentCol++) {
|
|
25476
|
+
width += colgroup[currentCol].width;
|
|
25477
|
+
occupiedUntilRow[currentCol] = Math.max(
|
|
25478
|
+
occupiedUntilRow[currentCol],
|
|
25479
|
+
rowIndex + td.rowspan
|
|
25480
|
+
);
|
|
25481
|
+
}
|
|
25482
|
+
cellLayoutMap.set(td, { width });
|
|
25483
|
+
colIndex += td.colspan;
|
|
25484
|
+
}
|
|
25485
|
+
}
|
|
25486
|
+
return cellLayoutMap;
|
|
25487
|
+
}
|
|
25488
|
+
function getTableWidthFromColgroup(colgroup) {
|
|
25489
|
+
if (!colgroup?.length) {
|
|
25490
|
+
return void 0;
|
|
25491
|
+
}
|
|
25492
|
+
return colgroup.reduce((sum, col) => sum + col.width, 0);
|
|
25493
|
+
}
|
|
25494
|
+
function normalizeHexColor(color, fallback) {
|
|
25495
|
+
const normalized = normalizeHexLiteral(color) || normalizeRgbColor(color) || normalizeBrowserColor(color);
|
|
25496
|
+
if (normalized) {
|
|
25497
|
+
return normalized;
|
|
25498
|
+
}
|
|
25499
|
+
return fallback ? normalizeHexLiteral(fallback) || void 0 : void 0;
|
|
25500
|
+
}
|
|
25501
|
+
function normalizeHexLiteral(color) {
|
|
25502
|
+
const value = color.trim().replace(/^#/, "");
|
|
25503
|
+
if (/^[\da-f]{3}$/i.test(value)) {
|
|
25504
|
+
return value.split("").map((part) => `${part}${part}`).join("").toUpperCase();
|
|
25505
|
+
}
|
|
25506
|
+
if (/^[\da-f]{4}$/i.test(value)) {
|
|
25507
|
+
return value.slice(0, 3).split("").map((part) => `${part}${part}`).join("").toUpperCase();
|
|
25508
|
+
}
|
|
25509
|
+
if (/^[\da-f]{6}$/i.test(value)) {
|
|
25510
|
+
return value.toUpperCase();
|
|
25511
|
+
}
|
|
25512
|
+
if (/^[\da-f]{8}$/i.test(value)) {
|
|
25513
|
+
return value.slice(0, 6).toUpperCase();
|
|
25514
|
+
}
|
|
25515
|
+
return void 0;
|
|
25516
|
+
}
|
|
25517
|
+
function normalizeRgbColor(color) {
|
|
25518
|
+
const match = color.trim().match(/^rgba?\((.+)\)$/i);
|
|
25519
|
+
if (!match) {
|
|
25520
|
+
return void 0;
|
|
25521
|
+
}
|
|
25522
|
+
const parts = match[1].replace(/\s*\/\s*/g, ",").split(/\s*,\s*|\s+/).filter(Boolean);
|
|
25523
|
+
if (parts.length < 3) {
|
|
25524
|
+
return void 0;
|
|
25525
|
+
}
|
|
25526
|
+
const red = parseRgbChannel(parts[0]);
|
|
25527
|
+
const green = parseRgbChannel(parts[1]);
|
|
25528
|
+
const blue = parseRgbChannel(parts[2]);
|
|
25529
|
+
if (red === null || green === null || blue === null) {
|
|
25530
|
+
return void 0;
|
|
25531
|
+
}
|
|
25532
|
+
const alpha = parts[3] !== void 0 ? parseAlphaChannel(parts[3]) : 1;
|
|
25533
|
+
if (alpha === null || alpha <= 0) {
|
|
25534
|
+
return void 0;
|
|
25535
|
+
}
|
|
25536
|
+
const flattened = alpha >= 1 ? [red, green, blue] : [
|
|
25537
|
+
flattenChannel(red, alpha),
|
|
25538
|
+
flattenChannel(green, alpha),
|
|
25539
|
+
flattenChannel(blue, alpha)
|
|
25540
|
+
];
|
|
25541
|
+
return flattened.map(toHexChannel).join("");
|
|
25542
|
+
}
|
|
25543
|
+
function normalizeBrowserColor(color) {
|
|
25544
|
+
if (typeof document === "undefined") {
|
|
25545
|
+
return void 0;
|
|
25546
|
+
}
|
|
25547
|
+
const canvas = document.createElement("canvas");
|
|
25548
|
+
const context = canvas.getContext("2d");
|
|
25549
|
+
if (!context) {
|
|
25550
|
+
return void 0;
|
|
25551
|
+
}
|
|
25552
|
+
context.fillStyle = "#000000";
|
|
25553
|
+
context.fillStyle = color;
|
|
25554
|
+
const normalized = context.fillStyle;
|
|
25555
|
+
if (typeof normalized !== "string") {
|
|
25556
|
+
return void 0;
|
|
25557
|
+
}
|
|
25558
|
+
return normalizeHexLiteral(normalized) || normalizeRgbColor(normalized);
|
|
25559
|
+
}
|
|
25560
|
+
function parseRgbChannel(value) {
|
|
25561
|
+
if (value.endsWith("%")) {
|
|
25562
|
+
const percent = Number(value.slice(0, -1));
|
|
25563
|
+
if (!Number.isFinite(percent)) {
|
|
25564
|
+
return null;
|
|
25565
|
+
}
|
|
25566
|
+
return clampColorChannel(Math.round(percent / 100 * 255));
|
|
25567
|
+
}
|
|
25568
|
+
const channel = Number(value);
|
|
25569
|
+
if (!Number.isFinite(channel)) {
|
|
25570
|
+
return null;
|
|
25571
|
+
}
|
|
25572
|
+
return clampColorChannel(Math.round(channel));
|
|
25573
|
+
}
|
|
25574
|
+
function parseAlphaChannel(value) {
|
|
25575
|
+
if (value.endsWith("%")) {
|
|
25576
|
+
const percent = Number(value.slice(0, -1));
|
|
25577
|
+
if (!Number.isFinite(percent)) {
|
|
25578
|
+
return null;
|
|
25579
|
+
}
|
|
25580
|
+
return Math.min(Math.max(percent / 100, 0), 1);
|
|
25581
|
+
}
|
|
25582
|
+
const alpha = Number(value);
|
|
25583
|
+
if (!Number.isFinite(alpha)) {
|
|
25584
|
+
return null;
|
|
25585
|
+
}
|
|
25586
|
+
return Math.min(Math.max(alpha, 0), 1);
|
|
25587
|
+
}
|
|
25588
|
+
function clampColorChannel(value) {
|
|
25589
|
+
return Math.min(Math.max(value, 0), 255);
|
|
25590
|
+
}
|
|
25591
|
+
function flattenChannel(value, alpha) {
|
|
25592
|
+
return clampColorChannel(Math.round(255 * (1 - alpha) + value * alpha));
|
|
25593
|
+
}
|
|
25594
|
+
function toHexChannel(value) {
|
|
25595
|
+
return value.toString(16).padStart(2, "0").toUpperCase();
|
|
25596
|
+
}
|
|
25597
|
+
function pxBorderToDocxSize(width) {
|
|
25598
|
+
const safeWidth = Number.isFinite(width) && width > 0 ? width : 1;
|
|
25599
|
+
return Math.max(2, Math.round(safeWidth * 6));
|
|
25600
|
+
}
|
|
25601
|
+
function getRegularImageType(mime) {
|
|
25602
|
+
if (mime.includes("png")) return "png";
|
|
25603
|
+
if (mime.includes("jpeg") || mime.includes("jpg")) return "jpg";
|
|
25604
|
+
if (mime.includes("gif")) return "gif";
|
|
25605
|
+
if (mime.includes("bmp")) return "bmp";
|
|
25606
|
+
return null;
|
|
25607
|
+
}
|
|
25608
|
+
function normalizeDocxFileName(fileName) {
|
|
25609
|
+
const trimmed = fileName?.trim();
|
|
25610
|
+
if (!trimmed) {
|
|
25611
|
+
return DEFAULT_DOCX_FILE_NAME;
|
|
25612
|
+
}
|
|
25613
|
+
return trimmed.toLowerCase().endsWith(".docx") ? trimmed : `${trimmed}.docx`;
|
|
25614
|
+
}
|
|
25615
|
+
function pxToTwips(px) {
|
|
25616
|
+
return Math.round(px * 15);
|
|
25617
|
+
}
|
|
25618
|
+
|
|
25619
|
+
// src/utils/pdf.ts
|
|
25620
|
+
import {
|
|
25621
|
+
PDFDocument,
|
|
25622
|
+
StandardFonts,
|
|
25623
|
+
rgb
|
|
25624
|
+
} from "pdf-lib";
|
|
25625
|
+
var DEFAULT_PDF_FILE_NAME = "document.pdf";
|
|
25626
|
+
var DEFAULT_IMAGE_WIDTH2 = 320;
|
|
25627
|
+
var DEFAULT_IMAGE_HEIGHT2 = 180;
|
|
25628
|
+
var DEFAULT_LINE_HEIGHT2 = 1.15;
|
|
25629
|
+
var PAGE_REGION_GAP = 12;
|
|
25630
|
+
var SEPARATOR_HEIGHT = 12;
|
|
25631
|
+
var LIST_GAP = 8;
|
|
25632
|
+
var FOOTER_MIN_BAR_HEIGHT = 29;
|
|
25633
|
+
var PDF_TEXT_FALLBACKS = {
|
|
25634
|
+
"\u2297": "x",
|
|
25635
|
+
"\u2611": "[x]",
|
|
25636
|
+
"\u2612": "[x]",
|
|
25637
|
+
"\u2610": "[]",
|
|
25638
|
+
"\u2713": "v",
|
|
25639
|
+
"\u2714": "v",
|
|
25640
|
+
"\u2717": "x",
|
|
25641
|
+
"\u2715": "x",
|
|
25642
|
+
"\u25E6": "o",
|
|
25643
|
+
"\u25AA": "*",
|
|
25644
|
+
"\u25A0": "*"
|
|
25645
|
+
};
|
|
25646
|
+
var pdfTextCache = /* @__PURE__ */ new WeakMap();
|
|
25647
|
+
var bulletCharMap = {
|
|
25648
|
+
["disc" /* DISC */]: "\u2022",
|
|
25649
|
+
["circle" /* CIRCLE */]: "\u25E6",
|
|
25650
|
+
["square" /* SQUARE */]: "\u25A0",
|
|
25651
|
+
["checkbox" /* CHECKBOX */]: "\u2611"
|
|
25652
|
+
};
|
|
25653
|
+
async function exportEditorDataToPdf(payload, options = {}) {
|
|
25654
|
+
const editorOptions = payload.options;
|
|
25655
|
+
const pdfDoc = await PDFDocument.create();
|
|
25656
|
+
const context = await createPdfContext(pdfDoc, editorOptions);
|
|
25657
|
+
const headerBlocks = editorOptions.header.disabled ? [] : await parseElementList(payload.data.header || [], context, editorOptions);
|
|
25658
|
+
const footerBlocks = editorOptions.footer.disabled ? [] : await parseElementList(payload.data.footer || [], context, editorOptions);
|
|
25659
|
+
const mainBlocks = await parseElementList(
|
|
25660
|
+
payload.data.main,
|
|
25661
|
+
context,
|
|
25662
|
+
editorOptions
|
|
25663
|
+
);
|
|
25664
|
+
const headerHeight = measureBlocksHeight(
|
|
25665
|
+
headerBlocks,
|
|
25666
|
+
context.contentWidth,
|
|
25667
|
+
context
|
|
25668
|
+
);
|
|
25669
|
+
const footerHeight = measureBlocksHeight(
|
|
25670
|
+
footerBlocks,
|
|
25671
|
+
context.contentWidth,
|
|
25672
|
+
context
|
|
25673
|
+
);
|
|
25674
|
+
const footerBarHeight = getFooterBarHeight(footerHeight, context);
|
|
25675
|
+
const pageNumberHeight = getPageNumberHeight(editorOptions.pageNumber);
|
|
25676
|
+
const contentTop = Math.max(
|
|
25677
|
+
context.margins[0],
|
|
25678
|
+
context.headerTop + headerHeight + (headerBlocks.length ? context.headerGap : 0)
|
|
25679
|
+
);
|
|
25680
|
+
const contentBottom = Math.max(
|
|
25681
|
+
context.margins[2],
|
|
25682
|
+
context.footerBottom + footerBarHeight,
|
|
25683
|
+
getReservedPageNumberBottom(editorOptions.pageNumber, pageNumberHeight)
|
|
25684
|
+
);
|
|
25685
|
+
const pages = renderMainBlocks(
|
|
25686
|
+
mainBlocks,
|
|
25687
|
+
context,
|
|
25688
|
+
contentTop,
|
|
25689
|
+
contentBottom
|
|
25690
|
+
);
|
|
25691
|
+
renderPageDecorations(
|
|
25692
|
+
pages,
|
|
25693
|
+
context,
|
|
25694
|
+
headerBlocks,
|
|
25695
|
+
footerBlocks,
|
|
25696
|
+
headerHeight,
|
|
25697
|
+
footerHeight,
|
|
25698
|
+
footerBarHeight,
|
|
25699
|
+
editorOptions.pageNumber
|
|
25700
|
+
);
|
|
25701
|
+
const bytes = await pdfDoc.save();
|
|
25702
|
+
return {
|
|
25703
|
+
blob: new Blob([bytes], { type: "application/pdf" }),
|
|
25704
|
+
fileName: normalizePdfFileName(options.fileName)
|
|
25705
|
+
};
|
|
25706
|
+
}
|
|
25707
|
+
async function createPdfContext(pdfDoc, options) {
|
|
25708
|
+
const [sans, sansBold, sansItalic, sansBoldItalic] = await Promise.all([
|
|
25709
|
+
pdfDoc.embedFont(StandardFonts.Helvetica),
|
|
25710
|
+
pdfDoc.embedFont(StandardFonts.HelveticaBold),
|
|
25711
|
+
pdfDoc.embedFont(StandardFonts.HelveticaOblique),
|
|
25712
|
+
pdfDoc.embedFont(StandardFonts.HelveticaBoldOblique)
|
|
25713
|
+
]);
|
|
25714
|
+
const [serif, serifBold, serifItalic, serifBoldItalic] = await Promise.all([
|
|
25715
|
+
pdfDoc.embedFont(StandardFonts.TimesRoman),
|
|
25716
|
+
pdfDoc.embedFont(StandardFonts.TimesRomanBold),
|
|
25717
|
+
pdfDoc.embedFont(StandardFonts.TimesRomanItalic),
|
|
25718
|
+
pdfDoc.embedFont(StandardFonts.TimesRomanBoldItalic)
|
|
25719
|
+
]);
|
|
25720
|
+
const [mono, monoBold, monoItalic, monoBoldItalic] = await Promise.all([
|
|
25721
|
+
pdfDoc.embedFont(StandardFonts.Courier),
|
|
25722
|
+
pdfDoc.embedFont(StandardFonts.CourierBold),
|
|
25723
|
+
pdfDoc.embedFont(StandardFonts.CourierOblique),
|
|
25724
|
+
pdfDoc.embedFont(StandardFonts.CourierBoldOblique)
|
|
25725
|
+
]);
|
|
25726
|
+
const pageWidth = options.paperDirection === "horizontal" /* HORIZONTAL */ ? pxToPt(options.height) : pxToPt(options.width);
|
|
25727
|
+
const pageHeight = options.paperDirection === "horizontal" /* HORIZONTAL */ ? pxToPt(options.width) : pxToPt(options.height);
|
|
25728
|
+
const margins = options.margins.map(pxToPt);
|
|
25729
|
+
return {
|
|
25730
|
+
pdfDoc,
|
|
25731
|
+
options,
|
|
25732
|
+
fonts: {
|
|
25733
|
+
sans: {
|
|
25734
|
+
regular: sans,
|
|
25735
|
+
bold: sansBold,
|
|
25736
|
+
italic: sansItalic,
|
|
25737
|
+
boldItalic: sansBoldItalic
|
|
25738
|
+
},
|
|
25739
|
+
serif: {
|
|
25740
|
+
regular: serif,
|
|
25741
|
+
bold: serifBold,
|
|
25742
|
+
italic: serifItalic,
|
|
25743
|
+
boldItalic: serifBoldItalic
|
|
25744
|
+
},
|
|
25745
|
+
mono: {
|
|
25746
|
+
regular: mono,
|
|
25747
|
+
bold: monoBold,
|
|
25748
|
+
italic: monoItalic,
|
|
25749
|
+
boldItalic: monoBoldItalic
|
|
25750
|
+
}
|
|
25751
|
+
},
|
|
25752
|
+
pageWidth,
|
|
25753
|
+
pageHeight,
|
|
25754
|
+
margins,
|
|
25755
|
+
contentWidth: pageWidth - margins[1] - margins[3],
|
|
25756
|
+
headerTop: pxToPt(options.header.top),
|
|
25757
|
+
footerBottom: pxToPt(options.footer.bottom),
|
|
25758
|
+
headerGap: PAGE_REGION_GAP,
|
|
25759
|
+
footerGap: PAGE_REGION_GAP,
|
|
25760
|
+
separatorGap: SEPARATOR_HEIGHT,
|
|
25761
|
+
imageCache: /* @__PURE__ */ new Map()
|
|
25762
|
+
};
|
|
25763
|
+
}
|
|
25764
|
+
async function parseElementList(elementList, context, options) {
|
|
25765
|
+
const blocks = [];
|
|
25766
|
+
let inlineBuffer = [];
|
|
25767
|
+
const flushInlineBuffer = async () => {
|
|
25768
|
+
if (!inlineBuffer.length) return;
|
|
25769
|
+
blocks.push(...await parseInlineElements(inlineBuffer, context, options));
|
|
25770
|
+
inlineBuffer = [];
|
|
25771
|
+
};
|
|
25772
|
+
for (let i = 0; i < elementList.length; i++) {
|
|
25773
|
+
const element = elementList[i];
|
|
25774
|
+
if (element.type === "area" /* AREA */ && element.valueList?.length) {
|
|
25775
|
+
await flushInlineBuffer();
|
|
25776
|
+
blocks.push(
|
|
25777
|
+
...await parseElementList(element.valueList, context, options)
|
|
25778
|
+
);
|
|
25779
|
+
continue;
|
|
25780
|
+
}
|
|
25781
|
+
if (element.type === "title" /* TITLE */ && element.valueList?.length) {
|
|
25782
|
+
await flushInlineBuffer();
|
|
25783
|
+
blocks.push(
|
|
25784
|
+
...await parseInlineElements(element.valueList, context, options, {
|
|
25785
|
+
alignment: element.rowFlex,
|
|
25786
|
+
rowMargin: element.rowMargin,
|
|
25787
|
+
listMarker: void 0,
|
|
25788
|
+
titleLevel: element.level || "first" /* FIRST */
|
|
25789
|
+
})
|
|
25790
|
+
);
|
|
25791
|
+
continue;
|
|
25792
|
+
}
|
|
25793
|
+
if (element.type === "list" /* LIST */ && element.valueList?.length) {
|
|
25794
|
+
await flushInlineBuffer();
|
|
25795
|
+
blocks.push(...await parseListBlock(element, context, options));
|
|
25796
|
+
continue;
|
|
25797
|
+
}
|
|
25798
|
+
if (element.type === "table" /* TABLE */ && element.trList?.length) {
|
|
25799
|
+
await flushInlineBuffer();
|
|
25800
|
+
blocks.push(await parseTableBlock(element, context, options));
|
|
25801
|
+
continue;
|
|
25802
|
+
}
|
|
25803
|
+
if (element.type === "pageBreak" /* PAGE_BREAK */) {
|
|
25804
|
+
await flushInlineBuffer();
|
|
25805
|
+
blocks.push({ type: "pageBreak" });
|
|
25806
|
+
continue;
|
|
25807
|
+
}
|
|
25808
|
+
if (element.type === "separator" /* SEPARATOR */) {
|
|
25809
|
+
await flushInlineBuffer();
|
|
25810
|
+
blocks.push({ type: "separator" });
|
|
25811
|
+
continue;
|
|
25812
|
+
}
|
|
25813
|
+
if (element.type === "image" /* IMAGE */ && element.imgDisplay && element.imgDisplay !== "inline") {
|
|
25814
|
+
await flushInlineBuffer();
|
|
25815
|
+
const imageBlock = await createImageBlock(element, context);
|
|
25816
|
+
if (imageBlock) {
|
|
25817
|
+
blocks.push(imageBlock);
|
|
25818
|
+
}
|
|
25819
|
+
continue;
|
|
25820
|
+
}
|
|
25821
|
+
if (element.type === "block" /* BLOCK */) {
|
|
25822
|
+
await flushInlineBuffer();
|
|
25823
|
+
const blockText = getBlockFallbackText2(element);
|
|
25824
|
+
if (blockText) {
|
|
25825
|
+
blocks.push(
|
|
25826
|
+
...await parseInlineElements(
|
|
25827
|
+
[{ value: blockText }],
|
|
25828
|
+
context,
|
|
25829
|
+
options
|
|
25830
|
+
)
|
|
25831
|
+
);
|
|
25832
|
+
}
|
|
25833
|
+
continue;
|
|
25834
|
+
}
|
|
25835
|
+
inlineBuffer.push(element);
|
|
25836
|
+
}
|
|
25837
|
+
await flushInlineBuffer();
|
|
25838
|
+
return blocks;
|
|
25839
|
+
}
|
|
25840
|
+
async function parseInlineElements(elementList, context, options, overrides = {}) {
|
|
25841
|
+
const paragraphs = [];
|
|
25842
|
+
let current = null;
|
|
25843
|
+
const getParagraphContext = (element) => ({
|
|
25844
|
+
alignment: overrides.alignment !== void 0 ? overrides.alignment : element?.rowFlex,
|
|
25845
|
+
rowMargin: overrides.rowMargin !== void 0 ? overrides.rowMargin : element?.rowMargin,
|
|
25846
|
+
listMarker: overrides.listMarker
|
|
25847
|
+
});
|
|
25848
|
+
const ensureParagraph = (element) => {
|
|
25849
|
+
if (!current) {
|
|
25850
|
+
current = {
|
|
25851
|
+
runs: [],
|
|
25852
|
+
context: getParagraphContext(element)
|
|
25853
|
+
};
|
|
25854
|
+
}
|
|
25855
|
+
return current;
|
|
25856
|
+
};
|
|
25857
|
+
const flushParagraph = (contextValue) => {
|
|
25858
|
+
if (!current) {
|
|
25859
|
+
if (!contextValue) return;
|
|
25860
|
+
paragraphs.push({
|
|
25861
|
+
type: "paragraph",
|
|
25862
|
+
runs: [],
|
|
25863
|
+
context: contextValue
|
|
25864
|
+
});
|
|
25865
|
+
return;
|
|
25866
|
+
}
|
|
25867
|
+
paragraphs.push({
|
|
25868
|
+
type: "paragraph",
|
|
25869
|
+
runs: current.runs,
|
|
25870
|
+
context: current.context
|
|
25871
|
+
});
|
|
25872
|
+
current = null;
|
|
25873
|
+
};
|
|
25874
|
+
const appendText = (element, text, factory, preserveTrailingBreak = false) => {
|
|
25875
|
+
const normalized = normalizeText2(text);
|
|
25876
|
+
const parts = normalized.split("\n");
|
|
25877
|
+
let lastSeparatorFlushedContent = false;
|
|
25878
|
+
for (let i = 0; i < parts.length; i++) {
|
|
25879
|
+
const segment = parts[i];
|
|
25880
|
+
if (segment) {
|
|
25881
|
+
ensureParagraph(element).runs.push(factory(segment));
|
|
25882
|
+
}
|
|
25883
|
+
if (i < parts.length - 1) {
|
|
25884
|
+
if (!current) {
|
|
25885
|
+
paragraphs.push({
|
|
25886
|
+
type: "paragraph",
|
|
25887
|
+
runs: [],
|
|
25888
|
+
context: getParagraphContext(element)
|
|
25889
|
+
});
|
|
25890
|
+
lastSeparatorFlushedContent = false;
|
|
25891
|
+
} else {
|
|
25892
|
+
flushParagraph();
|
|
25893
|
+
lastSeparatorFlushedContent = true;
|
|
25894
|
+
}
|
|
25895
|
+
}
|
|
25896
|
+
}
|
|
25897
|
+
if (preserveTrailingBreak && normalized.endsWith("\n") && lastSeparatorFlushedContent) {
|
|
25898
|
+
paragraphs.push({
|
|
25899
|
+
type: "paragraph",
|
|
25900
|
+
runs: [],
|
|
25901
|
+
context: getParagraphContext(element)
|
|
25902
|
+
});
|
|
25903
|
+
}
|
|
25904
|
+
};
|
|
25905
|
+
for (let i = 0; i < elementList.length; i++) {
|
|
25906
|
+
const element = elementList[i];
|
|
25907
|
+
if (element.type === "hyperlink" /* HYPERLINK */ && element.valueList?.length) {
|
|
25908
|
+
const children = element.valueList || [];
|
|
25909
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
25910
|
+
const child = children[childIndex];
|
|
25911
|
+
const text = normalizeText2(getInlineElementText2(child));
|
|
25912
|
+
if (!text) continue;
|
|
25913
|
+
appendText(
|
|
25914
|
+
element,
|
|
25915
|
+
text,
|
|
25916
|
+
(segment) => {
|
|
25917
|
+
const run = createTextRun2(
|
|
25918
|
+
child,
|
|
25919
|
+
options,
|
|
25920
|
+
overrides.titleLevel,
|
|
25921
|
+
segment
|
|
25922
|
+
);
|
|
25923
|
+
run.color = run.color || options.defaultHyperlinkColor;
|
|
25924
|
+
run.underline = true;
|
|
25925
|
+
return run;
|
|
25926
|
+
},
|
|
25927
|
+
i === elementList.length - 1 && childIndex === children.length - 1
|
|
25928
|
+
);
|
|
25929
|
+
}
|
|
25930
|
+
continue;
|
|
25931
|
+
}
|
|
25932
|
+
if (element.type === "image" /* IMAGE */) {
|
|
25933
|
+
const imageRun = await createInlineImageRun(element, context);
|
|
25934
|
+
if (imageRun) {
|
|
25935
|
+
ensureParagraph(element).runs.push(imageRun);
|
|
25936
|
+
}
|
|
25937
|
+
continue;
|
|
25938
|
+
}
|
|
25939
|
+
if (element.type === "columnBreak" /* COLUMN_BREAK */) {
|
|
25940
|
+
flushParagraph(getParagraphContext(element));
|
|
25941
|
+
continue;
|
|
25942
|
+
}
|
|
25943
|
+
if (element.type === "pageBreak" /* PAGE_BREAK */) {
|
|
25944
|
+
flushParagraph();
|
|
25945
|
+
paragraphs.push({ type: "pageBreak" });
|
|
25946
|
+
continue;
|
|
25947
|
+
}
|
|
25948
|
+
if (element.type === "tab" /* TAB */) {
|
|
25949
|
+
ensureParagraph(element).runs.push({
|
|
25950
|
+
type: "tab",
|
|
25951
|
+
width: pxToPt(options.defaultTabWidth)
|
|
25952
|
+
});
|
|
25953
|
+
continue;
|
|
25954
|
+
}
|
|
25955
|
+
if (element.type === "label" /* LABEL */) {
|
|
25956
|
+
const badgeRun = createBadgeRun(element, options, overrides.titleLevel);
|
|
25957
|
+
ensureParagraph(element).runs.push(badgeRun);
|
|
25958
|
+
continue;
|
|
25959
|
+
}
|
|
25960
|
+
const textValue = getInlineElementText2(element);
|
|
25961
|
+
if (!textValue) {
|
|
25962
|
+
continue;
|
|
25963
|
+
}
|
|
25964
|
+
appendText(
|
|
25965
|
+
element,
|
|
25966
|
+
textValue,
|
|
25967
|
+
(segment) => createTextRun2(element, options, overrides.titleLevel, segment),
|
|
25968
|
+
i === elementList.length - 1
|
|
25969
|
+
);
|
|
25970
|
+
}
|
|
25971
|
+
if (current) {
|
|
25972
|
+
flushParagraph();
|
|
25973
|
+
}
|
|
25974
|
+
return paragraphs.length ? paragraphs : [
|
|
25975
|
+
{
|
|
25976
|
+
type: "paragraph",
|
|
25977
|
+
runs: [],
|
|
25978
|
+
context: getParagraphContext()
|
|
25979
|
+
}
|
|
25980
|
+
];
|
|
25981
|
+
}
|
|
25982
|
+
async function parseListBlock(element, context, options) {
|
|
25983
|
+
const zipList = zipElementList(element.valueList || []);
|
|
25984
|
+
const listItemMap = splitListElement(zipList);
|
|
25985
|
+
const blocks = [];
|
|
25986
|
+
const orderedCounts = Array(9).fill(0);
|
|
25987
|
+
for (const listItemElements of listItemMap.values()) {
|
|
25988
|
+
const itemElement = getListItemNumberingElement2(listItemElements, element);
|
|
25989
|
+
const marker = getListMarker(itemElement, orderedCounts);
|
|
25990
|
+
blocks.push(
|
|
25991
|
+
...await parseInlineElements(listItemElements, context, options, {
|
|
25992
|
+
alignment: itemElement.rowFlex,
|
|
25993
|
+
rowMargin: itemElement.rowMargin,
|
|
25994
|
+
listMarker: marker
|
|
25995
|
+
})
|
|
25996
|
+
);
|
|
25997
|
+
}
|
|
25998
|
+
return blocks;
|
|
25999
|
+
}
|
|
26000
|
+
async function parseTableBlock(element, context, options) {
|
|
26001
|
+
const placements = computeTableCellPlacement(
|
|
26002
|
+
element.trList || [],
|
|
26003
|
+
element.colgroup || []
|
|
26004
|
+
);
|
|
26005
|
+
const rows = [];
|
|
26006
|
+
for (let rowIndex = 0; rowIndex < (element.trList || []).length; rowIndex++) {
|
|
26007
|
+
const tr = element.trList[rowIndex];
|
|
26008
|
+
const cells = [];
|
|
26009
|
+
for (let cellIndex = 0; cellIndex < tr.tdList.length; cellIndex++) {
|
|
26010
|
+
const td = tr.tdList[cellIndex];
|
|
26011
|
+
const placement = placements.get(td);
|
|
26012
|
+
cells.push({
|
|
26013
|
+
colspan: td.colspan,
|
|
26014
|
+
rowspan: td.rowspan,
|
|
26015
|
+
blocks: await parseElementList(td.value, context, options),
|
|
26016
|
+
colIndex: placement?.colIndex || 0,
|
|
26017
|
+
width: placement?.width || td.width || 0,
|
|
26018
|
+
padding: td.padding || options.table.tdPadding,
|
|
26019
|
+
verticalAlign: td.verticalAlign,
|
|
26020
|
+
backgroundColor: td.backgroundColor,
|
|
26021
|
+
borderColor: td.borderColor,
|
|
26022
|
+
borderTypes: td.borderTypes
|
|
26023
|
+
});
|
|
26024
|
+
}
|
|
26025
|
+
rows.push({
|
|
26026
|
+
height: Math.max(tr.height || 0, options.table.defaultTrMinHeight),
|
|
26027
|
+
cells
|
|
26028
|
+
});
|
|
26029
|
+
}
|
|
26030
|
+
return {
|
|
26031
|
+
type: "table",
|
|
26032
|
+
rows,
|
|
26033
|
+
colWidths: (element.colgroup || []).map((col) => col.width),
|
|
26034
|
+
borderType: element.borderType,
|
|
26035
|
+
borderColor: element.borderColor || options.table.defaultBorderColor,
|
|
26036
|
+
borderWidth: element.borderWidth || 1,
|
|
26037
|
+
borderExternalWidth: element.borderExternalWidth
|
|
26038
|
+
};
|
|
26039
|
+
}
|
|
26040
|
+
async function createImageBlock(element, context) {
|
|
26041
|
+
const image = await loadPdfImage(element.value, context);
|
|
26042
|
+
if (!image) {
|
|
26043
|
+
return null;
|
|
26044
|
+
}
|
|
26045
|
+
return {
|
|
26046
|
+
type: "image",
|
|
26047
|
+
image,
|
|
26048
|
+
width: pxToPt(
|
|
26049
|
+
Math.max(1, Math.round(element.width || DEFAULT_IMAGE_WIDTH2))
|
|
26050
|
+
),
|
|
26051
|
+
height: pxToPt(
|
|
26052
|
+
Math.max(1, Math.round(element.height || DEFAULT_IMAGE_HEIGHT2))
|
|
26053
|
+
),
|
|
26054
|
+
alignment: element.rowFlex
|
|
26055
|
+
};
|
|
26056
|
+
}
|
|
26057
|
+
async function createInlineImageRun(element, context) {
|
|
26058
|
+
const image = await loadPdfImage(element.value, context);
|
|
26059
|
+
if (!image) {
|
|
26060
|
+
return null;
|
|
26061
|
+
}
|
|
26062
|
+
return {
|
|
26063
|
+
type: "image",
|
|
26064
|
+
image,
|
|
26065
|
+
width: pxToPt(
|
|
26066
|
+
Math.max(1, Math.round(element.width || DEFAULT_IMAGE_WIDTH2))
|
|
26067
|
+
),
|
|
26068
|
+
height: pxToPt(
|
|
26069
|
+
Math.max(1, Math.round(element.height || DEFAULT_IMAGE_HEIGHT2))
|
|
26070
|
+
)
|
|
26071
|
+
};
|
|
26072
|
+
}
|
|
26073
|
+
function createTextRun2(element, options, titleLevel, text) {
|
|
26074
|
+
const titleSize = getTitleSize(titleLevel, options);
|
|
26075
|
+
const size = element.size || titleSize || options.defaultSize;
|
|
26076
|
+
const isTitle = !!titleLevel;
|
|
26077
|
+
return {
|
|
26078
|
+
type: "text",
|
|
26079
|
+
text,
|
|
26080
|
+
size,
|
|
26081
|
+
font: element.font || options.defaultFont,
|
|
26082
|
+
bold: isTitle ? true : !!element.bold,
|
|
26083
|
+
italic: !!element.italic,
|
|
26084
|
+
underline: !!element.underline,
|
|
26085
|
+
strikeout: !!element.strikeout,
|
|
26086
|
+
color: element.color || (isTitle ? "#000000" : void 0),
|
|
26087
|
+
highlight: element.highlight,
|
|
26088
|
+
superscript: element.type === "superscript" /* SUPERSCRIPT */,
|
|
26089
|
+
subscript: element.type === "subscript" /* SUBSCRIPT */
|
|
26090
|
+
};
|
|
26091
|
+
}
|
|
26092
|
+
function createBadgeRun(element, options, titleLevel) {
|
|
26093
|
+
const titleSize = getTitleSize(titleLevel, options);
|
|
26094
|
+
return {
|
|
26095
|
+
type: "badge",
|
|
26096
|
+
text: element.value,
|
|
26097
|
+
size: element.size || titleSize || options.defaultSize,
|
|
26098
|
+
font: element.font || options.defaultFont,
|
|
26099
|
+
bold: titleLevel ? true : !!element.bold,
|
|
26100
|
+
italic: !!element.italic,
|
|
26101
|
+
underline: !!element.underline,
|
|
26102
|
+
strikeout: !!element.strikeout,
|
|
26103
|
+
color: element.label?.color || element.color,
|
|
26104
|
+
backgroundColor: element.label?.backgroundColor,
|
|
26105
|
+
borderColor: element.label?.borderColor,
|
|
26106
|
+
padding: element.label?.padding || [2, 4, 2, 4]
|
|
26107
|
+
};
|
|
26108
|
+
}
|
|
26109
|
+
function renderMainBlocks(blocks, context, contentTop, contentBottom) {
|
|
26110
|
+
const pages = [];
|
|
26111
|
+
const contentEnd = context.pageHeight - contentBottom;
|
|
26112
|
+
const createPage = () => {
|
|
26113
|
+
const page = context.pdfDoc.addPage([
|
|
26114
|
+
context.pageWidth,
|
|
26115
|
+
context.pageHeight
|
|
26116
|
+
]);
|
|
26117
|
+
const state = {
|
|
26118
|
+
page,
|
|
26119
|
+
cursorY: contentTop,
|
|
26120
|
+
isEmpty: true
|
|
26121
|
+
};
|
|
26122
|
+
pages.push(state);
|
|
26123
|
+
return state;
|
|
26124
|
+
};
|
|
26125
|
+
let currentPage = createPage();
|
|
26126
|
+
const ensureSpace = (height) => {
|
|
26127
|
+
if (currentPage.cursorY + height <= contentEnd || currentPage.isEmpty) {
|
|
26128
|
+
return;
|
|
26129
|
+
}
|
|
26130
|
+
currentPage = createPage();
|
|
26131
|
+
};
|
|
26132
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
26133
|
+
const block = blocks[i];
|
|
26134
|
+
if (block.type === "pageBreak") {
|
|
26135
|
+
currentPage = createPage();
|
|
26136
|
+
continue;
|
|
26137
|
+
}
|
|
26138
|
+
if (block.type === "paragraph") {
|
|
26139
|
+
currentPage = renderParagraphAcrossPages(
|
|
26140
|
+
block,
|
|
26141
|
+
currentPage,
|
|
26142
|
+
pages,
|
|
26143
|
+
context,
|
|
26144
|
+
contentTop,
|
|
26145
|
+
contentEnd
|
|
26146
|
+
);
|
|
26147
|
+
continue;
|
|
26148
|
+
}
|
|
26149
|
+
if (block.type === "separator") {
|
|
26150
|
+
ensureSpace(context.separatorGap);
|
|
26151
|
+
renderSeparator(
|
|
26152
|
+
currentPage.page,
|
|
26153
|
+
context,
|
|
26154
|
+
currentPage.cursorY,
|
|
26155
|
+
context.margins[3],
|
|
26156
|
+
context.contentWidth
|
|
26157
|
+
);
|
|
26158
|
+
currentPage.cursorY += context.separatorGap;
|
|
26159
|
+
currentPage.isEmpty = false;
|
|
26160
|
+
continue;
|
|
26161
|
+
}
|
|
26162
|
+
if (block.type === "image") {
|
|
26163
|
+
ensureSpace(block.height);
|
|
26164
|
+
renderImageBlock(currentPage.page, block, context, currentPage.cursorY);
|
|
26165
|
+
currentPage.cursorY += block.height;
|
|
26166
|
+
currentPage.isEmpty = false;
|
|
26167
|
+
continue;
|
|
26168
|
+
}
|
|
26169
|
+
const tableLayout = layoutTable(block, context.contentWidth, context);
|
|
26170
|
+
currentPage = renderTableAcrossPages(
|
|
26171
|
+
block,
|
|
26172
|
+
tableLayout,
|
|
26173
|
+
currentPage,
|
|
26174
|
+
pages,
|
|
26175
|
+
context,
|
|
26176
|
+
contentTop,
|
|
26177
|
+
contentEnd
|
|
26178
|
+
);
|
|
26179
|
+
}
|
|
26180
|
+
return pages;
|
|
26181
|
+
}
|
|
26182
|
+
function renderParagraphAcrossPages(block, currentPage, pages, context, contentTop, contentEnd) {
|
|
26183
|
+
const layout = layoutParagraph(block, context.contentWidth, context);
|
|
26184
|
+
for (let lineIndex = 0; lineIndex < layout.lines.length; lineIndex++) {
|
|
26185
|
+
const line = layout.lines[lineIndex];
|
|
26186
|
+
if (currentPage.cursorY + line.height > contentEnd && !currentPage.isEmpty) {
|
|
26187
|
+
const page = context.pdfDoc.addPage([
|
|
26188
|
+
context.pageWidth,
|
|
26189
|
+
context.pageHeight
|
|
26190
|
+
]);
|
|
26191
|
+
currentPage = {
|
|
26192
|
+
page,
|
|
26193
|
+
cursorY: contentTop,
|
|
26194
|
+
isEmpty: true
|
|
26195
|
+
};
|
|
26196
|
+
pages.push(currentPage);
|
|
26197
|
+
}
|
|
26198
|
+
renderParagraphLine(
|
|
26199
|
+
currentPage.page,
|
|
26200
|
+
block,
|
|
26201
|
+
line,
|
|
26202
|
+
lineIndex === 0,
|
|
26203
|
+
layout,
|
|
26204
|
+
context,
|
|
26205
|
+
currentPage.cursorY,
|
|
26206
|
+
context.margins[3],
|
|
26207
|
+
context.contentWidth
|
|
26208
|
+
);
|
|
26209
|
+
currentPage.cursorY += line.height;
|
|
26210
|
+
currentPage.isEmpty = false;
|
|
26211
|
+
}
|
|
26212
|
+
return currentPage;
|
|
26213
|
+
}
|
|
26214
|
+
function renderTableAcrossPages(block, tableLayout, currentPage, pages, context, contentTop, contentEnd) {
|
|
26215
|
+
const scaledColWidths = scaleColumnWidths(
|
|
26216
|
+
block.colWidths,
|
|
26217
|
+
context.contentWidth
|
|
26218
|
+
);
|
|
26219
|
+
let tableTop = currentPage.cursorY;
|
|
26220
|
+
for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex++) {
|
|
26221
|
+
const row = block.rows[rowIndex];
|
|
26222
|
+
const rowHeight = tableLayout.rowHeights[rowIndex];
|
|
26223
|
+
const spanHeight = getSpanningRowHeight(
|
|
26224
|
+
block.rows,
|
|
26225
|
+
tableLayout.rowHeights,
|
|
26226
|
+
rowIndex
|
|
26227
|
+
);
|
|
26228
|
+
if (currentPage.cursorY + spanHeight > contentEnd && !currentPage.isEmpty) {
|
|
26229
|
+
const page = context.pdfDoc.addPage([
|
|
26230
|
+
context.pageWidth,
|
|
26231
|
+
context.pageHeight
|
|
26232
|
+
]);
|
|
26233
|
+
currentPage = {
|
|
26234
|
+
page,
|
|
26235
|
+
cursorY: contentTop,
|
|
26236
|
+
isEmpty: true
|
|
26237
|
+
};
|
|
26238
|
+
pages.push(currentPage);
|
|
26239
|
+
tableTop = currentPage.cursorY;
|
|
26240
|
+
}
|
|
26241
|
+
const rowTop = currentPage.cursorY;
|
|
26242
|
+
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
|
|
26243
|
+
const cell = row.cells[cellIndex];
|
|
26244
|
+
const cellX = context.margins[3] + getColumnOffset(scaledColWidths, cell.colIndex);
|
|
26245
|
+
const cellWidth = getColumnSpanWidth(
|
|
26246
|
+
scaledColWidths,
|
|
26247
|
+
cell.colIndex,
|
|
26248
|
+
cell.colspan
|
|
26249
|
+
);
|
|
26250
|
+
const cellHeight = getRowSpanHeight(
|
|
26251
|
+
tableLayout.rowHeights,
|
|
26252
|
+
rowIndex,
|
|
26253
|
+
cell.rowspan
|
|
26254
|
+
);
|
|
26255
|
+
renderTableCell(
|
|
26256
|
+
currentPage.page,
|
|
26257
|
+
cell,
|
|
26258
|
+
context,
|
|
26259
|
+
block,
|
|
26260
|
+
cellX,
|
|
26261
|
+
rowTop,
|
|
26262
|
+
cellWidth,
|
|
26263
|
+
cellHeight
|
|
26264
|
+
);
|
|
26265
|
+
}
|
|
26266
|
+
currentPage.cursorY += rowHeight;
|
|
26267
|
+
currentPage.isEmpty = false;
|
|
26268
|
+
}
|
|
26269
|
+
return currentPage;
|
|
26270
|
+
}
|
|
26271
|
+
function renderPageDecorations(pages, context, headerBlocks, footerBlocks, headerHeight, footerHeight, footerBarHeight, pageNumber) {
|
|
26272
|
+
const totalPages = pages.length;
|
|
26273
|
+
for (let index = 0; index < pages.length; index++) {
|
|
26274
|
+
const pageState = pages[index];
|
|
26275
|
+
if (headerBlocks.length) {
|
|
26276
|
+
renderBlocksInRegion(
|
|
26277
|
+
pageState.page,
|
|
26278
|
+
headerBlocks,
|
|
26279
|
+
context,
|
|
26280
|
+
context.margins[3],
|
|
26281
|
+
context.headerTop,
|
|
26282
|
+
context.contentWidth
|
|
26283
|
+
);
|
|
26284
|
+
}
|
|
26285
|
+
if (footerBarHeight > 0) {
|
|
26286
|
+
if (context.options.footer.backgroundColor) {
|
|
26287
|
+
pageState.page.drawRectangle({
|
|
26288
|
+
x: 0,
|
|
26289
|
+
y: context.footerBottom,
|
|
26290
|
+
width: context.pageWidth,
|
|
26291
|
+
height: footerBarHeight,
|
|
26292
|
+
color: toPdfColor(context.options.footer.backgroundColor, "#FFFFFF")
|
|
26293
|
+
});
|
|
26294
|
+
}
|
|
26295
|
+
if (footerBlocks.length) {
|
|
26296
|
+
const footerTop = context.pageHeight - context.footerBottom - footerBarHeight;
|
|
26297
|
+
const footerContentTop = footerTop + Math.max(0, (footerBarHeight - footerHeight) / 2);
|
|
26298
|
+
renderBlocksInRegion(
|
|
26299
|
+
pageState.page,
|
|
26300
|
+
footerBlocks,
|
|
26301
|
+
context,
|
|
26302
|
+
context.margins[3],
|
|
26303
|
+
footerContentTop,
|
|
26304
|
+
context.contentWidth
|
|
26305
|
+
);
|
|
26306
|
+
}
|
|
26307
|
+
}
|
|
26308
|
+
renderPageNumber(pageState.page, context, pageNumber, index, totalPages);
|
|
26309
|
+
}
|
|
26310
|
+
}
|
|
26311
|
+
function renderBlocksInRegion(page, blocks, context, x, top, width) {
|
|
26312
|
+
let cursorY = top;
|
|
26313
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
26314
|
+
const block = blocks[i];
|
|
26315
|
+
if (block.type === "pageBreak") {
|
|
26316
|
+
continue;
|
|
26317
|
+
}
|
|
26318
|
+
if (block.type === "paragraph") {
|
|
26319
|
+
const layout = layoutParagraph(block, width, context);
|
|
26320
|
+
for (let lineIndex = 0; lineIndex < layout.lines.length; lineIndex++) {
|
|
26321
|
+
const line = layout.lines[lineIndex];
|
|
26322
|
+
renderParagraphLine(
|
|
26323
|
+
page,
|
|
26324
|
+
block,
|
|
26325
|
+
line,
|
|
26326
|
+
lineIndex === 0,
|
|
26327
|
+
layout,
|
|
26328
|
+
context,
|
|
26329
|
+
cursorY,
|
|
26330
|
+
x,
|
|
26331
|
+
width
|
|
26332
|
+
);
|
|
26333
|
+
cursorY += line.height;
|
|
26334
|
+
}
|
|
26335
|
+
continue;
|
|
26336
|
+
}
|
|
26337
|
+
if (block.type === "separator") {
|
|
26338
|
+
renderSeparator(page, context, cursorY, x, width);
|
|
26339
|
+
cursorY += context.separatorGap;
|
|
26340
|
+
continue;
|
|
26341
|
+
}
|
|
26342
|
+
if (block.type === "image") {
|
|
26343
|
+
renderImageBlock(page, block, context, cursorY, x, width);
|
|
26344
|
+
cursorY += block.height;
|
|
26345
|
+
continue;
|
|
26346
|
+
}
|
|
26347
|
+
const tableLayout = layoutTable(block, width, context);
|
|
26348
|
+
const scaledColWidths = scaleColumnWidths(block.colWidths, width);
|
|
26349
|
+
for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex++) {
|
|
26350
|
+
const row = block.rows[rowIndex];
|
|
26351
|
+
const rowTop = cursorY;
|
|
26352
|
+
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
|
|
26353
|
+
const cell = row.cells[cellIndex];
|
|
26354
|
+
const cellX = x + getColumnOffset(scaledColWidths, cell.colIndex);
|
|
26355
|
+
const cellWidth = getColumnSpanWidth(
|
|
26356
|
+
scaledColWidths,
|
|
26357
|
+
cell.colIndex,
|
|
26358
|
+
cell.colspan
|
|
26359
|
+
);
|
|
26360
|
+
const cellHeight = getRowSpanHeight(
|
|
26361
|
+
tableLayout.rowHeights,
|
|
26362
|
+
rowIndex,
|
|
26363
|
+
cell.rowspan
|
|
26364
|
+
);
|
|
26365
|
+
renderTableCell(
|
|
26366
|
+
page,
|
|
26367
|
+
cell,
|
|
26368
|
+
context,
|
|
26369
|
+
block,
|
|
26370
|
+
cellX,
|
|
26371
|
+
rowTop,
|
|
26372
|
+
cellWidth,
|
|
26373
|
+
cellHeight
|
|
26374
|
+
);
|
|
26375
|
+
}
|
|
26376
|
+
cursorY += tableLayout.rowHeights[rowIndex];
|
|
26377
|
+
}
|
|
26378
|
+
}
|
|
26379
|
+
}
|
|
26380
|
+
function renderParagraphLine(page, block, line, isFirstLine, layout, context, top, baseX, regionWidth) {
|
|
26381
|
+
const alignment = normalizeAlignment(block.context.alignment);
|
|
26382
|
+
const lineWidth = line.width;
|
|
26383
|
+
const availableWidth = Math.max(
|
|
26384
|
+
1,
|
|
26385
|
+
regionWidth - layout.listIndent - layout.markerWidth
|
|
26386
|
+
);
|
|
26387
|
+
const justifyExtra = alignment === "justify" /* JUSTIFY */ && !isLastParagraphLine(layout, line) ? getJustifyExtra(line, availableWidth) : 0;
|
|
26388
|
+
let offsetX = 0;
|
|
26389
|
+
if (alignment === "center" /* CENTER */) {
|
|
26390
|
+
offsetX = (availableWidth - lineWidth) / 2;
|
|
26391
|
+
} else if (alignment === "right" /* RIGHT */) {
|
|
26392
|
+
offsetX = availableWidth - lineWidth;
|
|
26393
|
+
}
|
|
26394
|
+
const lineStart = baseX + layout.listIndent + layout.markerWidth + Math.max(0, offsetX);
|
|
26395
|
+
if (isFirstLine && block.context.listMarker) {
|
|
26396
|
+
const markerRun = getMarkerRun(block, context);
|
|
26397
|
+
const markerText = block.context.listMarker.text;
|
|
26398
|
+
drawTextRun(
|
|
26399
|
+
page,
|
|
26400
|
+
markerRun,
|
|
26401
|
+
markerText,
|
|
26402
|
+
baseX + layout.listIndent,
|
|
26403
|
+
top,
|
|
26404
|
+
line.height,
|
|
26405
|
+
context
|
|
26406
|
+
);
|
|
26407
|
+
}
|
|
26408
|
+
let cursorX = lineStart;
|
|
26409
|
+
for (let index = 0; index < line.fragments.length; index++) {
|
|
26410
|
+
const fragment = line.fragments[index];
|
|
26411
|
+
if (fragment.kind === "space" && justifyExtra > 0) {
|
|
26412
|
+
cursorX += justifyExtra;
|
|
26413
|
+
}
|
|
26414
|
+
drawLineFragment(page, fragment, cursorX, top, line.height, context);
|
|
26415
|
+
cursorX += fragment.width;
|
|
26416
|
+
}
|
|
26417
|
+
}
|
|
26418
|
+
function renderSeparator(page, context, top, x, width) {
|
|
26419
|
+
const lineY = toPdfY(context.pageHeight, top + SEPARATOR_HEIGHT / 2);
|
|
26420
|
+
page.drawLine({
|
|
26421
|
+
start: { x, y: lineY },
|
|
26422
|
+
end: { x: x + width, y: lineY },
|
|
26423
|
+
thickness: 1,
|
|
26424
|
+
color: rgb(0.6, 0.6, 0.6)
|
|
26425
|
+
});
|
|
26426
|
+
}
|
|
26427
|
+
function renderImageBlock(page, block, context, top, baseX = context.margins[3], width = context.contentWidth) {
|
|
26428
|
+
const alignment = normalizeAlignment(block.alignment);
|
|
26429
|
+
let x = baseX;
|
|
26430
|
+
if (alignment === "center" /* CENTER */) {
|
|
26431
|
+
x += Math.max(0, (width - block.width) / 2);
|
|
26432
|
+
} else if (alignment === "right" /* RIGHT */) {
|
|
26433
|
+
x += Math.max(0, width - block.width);
|
|
26434
|
+
}
|
|
26435
|
+
page.drawImage(block.image, {
|
|
26436
|
+
x,
|
|
26437
|
+
y: toPdfY(context.pageHeight, top, block.height),
|
|
26438
|
+
width: block.width,
|
|
26439
|
+
height: block.height
|
|
26440
|
+
});
|
|
26441
|
+
}
|
|
26442
|
+
function renderTableCell(page, cell, context, table, x, top, width, height) {
|
|
26443
|
+
if (cell.backgroundColor) {
|
|
26444
|
+
page.drawRectangle({
|
|
26445
|
+
x,
|
|
26446
|
+
y: toPdfY(context.pageHeight, top, height),
|
|
26447
|
+
width,
|
|
26448
|
+
height,
|
|
26449
|
+
color: toPdfColor(cell.backgroundColor)
|
|
26450
|
+
});
|
|
26451
|
+
}
|
|
26452
|
+
drawTableCellBorders(page, cell, context, table, x, top, width, height);
|
|
26453
|
+
const padding = getPadding(cell.padding || defaultTableOption.tdPadding).map(
|
|
26454
|
+
pxToPt
|
|
26455
|
+
);
|
|
26456
|
+
const contentWidth = Math.max(1, width - padding[1] - padding[3]);
|
|
26457
|
+
const contentHeight = measureBlocksHeight(cell.blocks, contentWidth, context);
|
|
26458
|
+
let contentTop = top + padding[0];
|
|
26459
|
+
if (cell.verticalAlign === VerticalAlign.CENTER) {
|
|
26460
|
+
contentTop = top + (height - contentHeight) / 2;
|
|
26461
|
+
} else if (cell.verticalAlign === "bottom" /* BOTTOM */) {
|
|
26462
|
+
contentTop = top + height - contentHeight - padding[2];
|
|
26463
|
+
}
|
|
26464
|
+
renderBlocksInRegion(
|
|
26465
|
+
page,
|
|
26466
|
+
cell.blocks,
|
|
26467
|
+
context,
|
|
26468
|
+
x + padding[3],
|
|
26469
|
+
contentTop,
|
|
26470
|
+
contentWidth
|
|
26471
|
+
);
|
|
26472
|
+
}
|
|
26473
|
+
function renderPageNumber(page, context, pageNumber, pageIndex, totalPages) {
|
|
26474
|
+
if (pageNumber.disabled || pageIndex < pageNumber.fromPageNo || Number.isInteger(pageNumber.maxPageNo) && pageIndex >= pageNumber.maxPageNo) {
|
|
26475
|
+
return;
|
|
26476
|
+
}
|
|
26477
|
+
let text = pageNumber.format || FORMAT_PLACEHOLDER.PAGE_NO;
|
|
26478
|
+
const currentValue = pageIndex + pageNumber.startPageNo - pageNumber.fromPageNo;
|
|
26479
|
+
const totalValue = totalPages - pageNumber.fromPageNo;
|
|
26480
|
+
text = text.replace(
|
|
26481
|
+
new RegExp(FORMAT_PLACEHOLDER.PAGE_NO, "g"),
|
|
26482
|
+
`${currentValue}`
|
|
26483
|
+
);
|
|
26484
|
+
text = text.replace(
|
|
26485
|
+
new RegExp(FORMAT_PLACEHOLDER.PAGE_COUNT, "g"),
|
|
26486
|
+
`${Math.max(0, totalValue)}`
|
|
26487
|
+
);
|
|
26488
|
+
const font = getFont(
|
|
26489
|
+
pageNumber.font || context.options.defaultFont,
|
|
26490
|
+
false,
|
|
26491
|
+
false,
|
|
26492
|
+
context
|
|
26493
|
+
);
|
|
26494
|
+
const size = pageNumber.size || 12;
|
|
26495
|
+
const bottom = pxToPt(pageNumber.bottom || 0);
|
|
26496
|
+
const safeText = sanitizeTextForPdf(text, font);
|
|
26497
|
+
const width = font.widthOfTextAtSize(safeText, size);
|
|
26498
|
+
const descenderHeight = Math.max(
|
|
26499
|
+
0,
|
|
26500
|
+
font.heightAtSize(size) - font.heightAtSize(size, { descender: false })
|
|
26501
|
+
);
|
|
26502
|
+
let x = context.margins[3];
|
|
26503
|
+
const alignment = normalizeAlignment(pageNumber.rowFlex);
|
|
26504
|
+
if (alignment === "center" /* CENTER */) {
|
|
26505
|
+
x = (context.pageWidth - width) / 2;
|
|
26506
|
+
} else if (alignment === "right" /* RIGHT */) {
|
|
26507
|
+
x = context.pageWidth - context.margins[1] - width;
|
|
26508
|
+
}
|
|
26509
|
+
page.drawText(safeText, {
|
|
26510
|
+
x,
|
|
26511
|
+
// Canvas draw uses the alphabetic baseline at `pageHeight - bottom`.
|
|
26512
|
+
// pdf-lib positions text from the text box bottom, so compensate by the
|
|
26513
|
+
// descender height to keep the baseline aligned.
|
|
26514
|
+
y: bottom - descenderHeight,
|
|
26515
|
+
size,
|
|
26516
|
+
font,
|
|
26517
|
+
color: toPdfColor(pageNumber.color, "#000000")
|
|
26518
|
+
});
|
|
26519
|
+
}
|
|
26520
|
+
function layoutParagraph(block, width, context) {
|
|
26521
|
+
const markerWidth = getMarkerWidth(block, context);
|
|
26522
|
+
const listIndent = block.context.listMarker ? pxToPt(block.context.listMarker.level * INDENT_PER_LEVEL) : 0;
|
|
26523
|
+
const availableWidth = Math.max(1, width - listIndent - markerWidth);
|
|
26524
|
+
const tokens = tokenizeParagraphRuns(block.runs, context);
|
|
26525
|
+
const lines = [];
|
|
26526
|
+
let line = {
|
|
26527
|
+
fragments: [],
|
|
26528
|
+
width: 0,
|
|
26529
|
+
height: getEmptyLineHeight(block, context)
|
|
26530
|
+
};
|
|
26531
|
+
const commitLine = () => {
|
|
26532
|
+
trimTrailingSpaces(line);
|
|
26533
|
+
lines.push(line);
|
|
26534
|
+
line = {
|
|
26535
|
+
fragments: [],
|
|
26536
|
+
width: 0,
|
|
26537
|
+
height: getEmptyLineHeight(block, context)
|
|
26538
|
+
};
|
|
26539
|
+
};
|
|
26540
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
26541
|
+
let token = tokens[i];
|
|
26542
|
+
if (token.kind === "space" && !line.fragments.length) {
|
|
26543
|
+
continue;
|
|
26544
|
+
}
|
|
26545
|
+
if (token.width > availableWidth && token.kind === "text" && token.run.type === "text") {
|
|
26546
|
+
const segments = splitTextToken(token, availableWidth, context);
|
|
26547
|
+
for (let segmentIndex = 0; segmentIndex < segments.length; segmentIndex++) {
|
|
26548
|
+
tokens.splice(i + segmentIndex, 0, segments[segmentIndex]);
|
|
26549
|
+
}
|
|
26550
|
+
continue;
|
|
26551
|
+
}
|
|
26552
|
+
if (line.width + token.width > availableWidth && line.fragments.length) {
|
|
26553
|
+
commitLine();
|
|
26554
|
+
i--;
|
|
26555
|
+
continue;
|
|
26556
|
+
}
|
|
26557
|
+
line.fragments.push(token);
|
|
26558
|
+
line.width += token.width;
|
|
26559
|
+
line.height = Math.max(line.height, token.height);
|
|
26560
|
+
}
|
|
26561
|
+
if (line.fragments.length || !lines.length) {
|
|
26562
|
+
commitLine();
|
|
26563
|
+
}
|
|
26564
|
+
return {
|
|
26565
|
+
lines,
|
|
26566
|
+
height: lines.reduce((sum, current) => sum + current.height, 0),
|
|
26567
|
+
markerWidth,
|
|
26568
|
+
listIndent
|
|
26569
|
+
};
|
|
26570
|
+
}
|
|
26571
|
+
function tokenizeParagraphRuns(runs, context) {
|
|
26572
|
+
const fragments = [];
|
|
26573
|
+
for (let index = 0; index < runs.length; index++) {
|
|
26574
|
+
const run = runs[index];
|
|
26575
|
+
if (run.type === "tab") {
|
|
26576
|
+
fragments.push({
|
|
26577
|
+
kind: "tab",
|
|
26578
|
+
width: run.width,
|
|
26579
|
+
height: 0,
|
|
26580
|
+
run
|
|
26581
|
+
});
|
|
26582
|
+
continue;
|
|
26583
|
+
}
|
|
26584
|
+
if (run.type === "image") {
|
|
26585
|
+
fragments.push({
|
|
26586
|
+
kind: "image",
|
|
26587
|
+
width: run.width,
|
|
26588
|
+
height: run.height,
|
|
26589
|
+
run
|
|
26590
|
+
});
|
|
26591
|
+
continue;
|
|
26592
|
+
}
|
|
26593
|
+
if (run.type === "badge") {
|
|
26594
|
+
const badgeWidth = measureBadgeWidth(run, context);
|
|
26595
|
+
const badgeHeight = measureBadgeHeight(run);
|
|
26596
|
+
fragments.push({
|
|
26597
|
+
kind: "badge",
|
|
26598
|
+
width: badgeWidth,
|
|
26599
|
+
height: badgeHeight,
|
|
26600
|
+
run
|
|
26601
|
+
});
|
|
26602
|
+
continue;
|
|
26603
|
+
}
|
|
26604
|
+
const parts = run.text.split(/(\s+)/);
|
|
26605
|
+
for (let partIndex = 0; partIndex < parts.length; partIndex++) {
|
|
26606
|
+
const part = parts[partIndex];
|
|
26607
|
+
if (!part) continue;
|
|
26608
|
+
const isWhitespace = /^\s+$/.test(part);
|
|
26609
|
+
fragments.push({
|
|
26610
|
+
kind: isWhitespace ? "space" : "text",
|
|
26611
|
+
width: measureTextWidth(part, run, context),
|
|
26612
|
+
height: getRunHeight(run),
|
|
26613
|
+
run: { ...run, text: part }
|
|
26614
|
+
});
|
|
26615
|
+
}
|
|
26616
|
+
}
|
|
26617
|
+
return fragments;
|
|
26618
|
+
}
|
|
26619
|
+
function splitTextToken(token, availableWidth, context) {
|
|
26620
|
+
if (token.run.type !== "text") {
|
|
26621
|
+
return [token];
|
|
26622
|
+
}
|
|
26623
|
+
const chars = splitText(token.run.text);
|
|
26624
|
+
const result = [];
|
|
26625
|
+
let current = "";
|
|
26626
|
+
for (let i = 0; i < chars.length; i++) {
|
|
26627
|
+
const next = current + chars[i];
|
|
26628
|
+
const width = measureTextWidth(next, token.run, context);
|
|
26629
|
+
if (width > availableWidth && current) {
|
|
26630
|
+
result.push({
|
|
26631
|
+
kind: "text",
|
|
26632
|
+
width: measureTextWidth(current, token.run, context),
|
|
26633
|
+
height: getRunHeight(token.run),
|
|
26634
|
+
run: { ...token.run, text: current }
|
|
26635
|
+
});
|
|
26636
|
+
current = chars[i];
|
|
26637
|
+
} else {
|
|
26638
|
+
current = next;
|
|
26639
|
+
}
|
|
26640
|
+
}
|
|
26641
|
+
if (current) {
|
|
26642
|
+
result.push({
|
|
26643
|
+
kind: /^\s+$/.test(current) ? "space" : "text",
|
|
26644
|
+
width: measureTextWidth(current, token.run, context),
|
|
26645
|
+
height: getRunHeight(token.run),
|
|
26646
|
+
run: { ...token.run, text: current }
|
|
26647
|
+
});
|
|
26648
|
+
}
|
|
26649
|
+
return result.length ? result : [token];
|
|
26650
|
+
}
|
|
26651
|
+
function trimTrailingSpaces(line) {
|
|
26652
|
+
while (line.fragments.length && line.fragments[line.fragments.length - 1].kind === "space") {
|
|
26653
|
+
const fragment = line.fragments.pop();
|
|
26654
|
+
line.width -= fragment.width;
|
|
26655
|
+
}
|
|
26656
|
+
}
|
|
26657
|
+
function layoutTable(table, width, context) {
|
|
26658
|
+
const rowHeights = table.rows.map(
|
|
26659
|
+
(row) => Math.max(
|
|
26660
|
+
pxToPt(row.height),
|
|
26661
|
+
pxToPt(context.options.table.defaultTrMinHeight)
|
|
26662
|
+
)
|
|
26663
|
+
);
|
|
26664
|
+
const scaledColWidths = scaleColumnWidths(table.colWidths, width);
|
|
26665
|
+
for (let rowIndex = 0; rowIndex < table.rows.length; rowIndex++) {
|
|
26666
|
+
const row = table.rows[rowIndex];
|
|
26667
|
+
for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
|
|
26668
|
+
const cell = row.cells[cellIndex];
|
|
26669
|
+
const cellWidth = getColumnSpanWidth(
|
|
26670
|
+
scaledColWidths,
|
|
26671
|
+
cell.colIndex,
|
|
26672
|
+
cell.colspan
|
|
26673
|
+
);
|
|
26674
|
+
const padding = getPadding(
|
|
26675
|
+
cell.padding || defaultTableOption.tdPadding
|
|
26676
|
+
).map(pxToPt);
|
|
26677
|
+
const contentWidth = Math.max(1, cellWidth - padding[1] - padding[3]);
|
|
26678
|
+
const contentHeight = measureBlocksHeight(cell.blocks, contentWidth, context) + padding[0] + padding[2];
|
|
26679
|
+
const spanHeight = getRowSpanHeight(rowHeights, rowIndex, cell.rowspan);
|
|
26680
|
+
if (contentHeight > spanHeight) {
|
|
26681
|
+
rowHeights[rowIndex + cell.rowspan - 1] += contentHeight - spanHeight;
|
|
26682
|
+
}
|
|
26683
|
+
}
|
|
26684
|
+
}
|
|
26685
|
+
return {
|
|
26686
|
+
rowHeights,
|
|
26687
|
+
totalHeight: rowHeights.reduce((sum, height) => sum + height, 0)
|
|
26688
|
+
};
|
|
26689
|
+
}
|
|
26690
|
+
function measureBlocksHeight(blocks, width, context) {
|
|
26691
|
+
let height = 0;
|
|
26692
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
26693
|
+
const block = blocks[i];
|
|
26694
|
+
if (block.type === "pageBreak") {
|
|
26695
|
+
continue;
|
|
26696
|
+
}
|
|
26697
|
+
if (block.type === "paragraph") {
|
|
26698
|
+
height += layoutParagraph(block, width, context).height;
|
|
26699
|
+
continue;
|
|
26700
|
+
}
|
|
26701
|
+
if (block.type === "separator") {
|
|
26702
|
+
height += context.separatorGap;
|
|
26703
|
+
continue;
|
|
26704
|
+
}
|
|
26705
|
+
if (block.type === "image") {
|
|
26706
|
+
height += block.height;
|
|
26707
|
+
continue;
|
|
26708
|
+
}
|
|
26709
|
+
height += layoutTable(block, width, context).totalHeight;
|
|
26710
|
+
}
|
|
26711
|
+
return height;
|
|
26712
|
+
}
|
|
26713
|
+
function drawLineFragment(page, fragment, x, top, lineHeight, context) {
|
|
26714
|
+
if (fragment.run.type === "tab") {
|
|
26715
|
+
return;
|
|
26716
|
+
}
|
|
26717
|
+
if (fragment.run.type === "image") {
|
|
26718
|
+
const imageTop = top + (lineHeight - fragment.run.height) / 2;
|
|
26719
|
+
page.drawImage(fragment.run.image, {
|
|
26720
|
+
x,
|
|
26721
|
+
y: toPdfY(context.pageHeight, imageTop, fragment.run.height),
|
|
26722
|
+
width: fragment.run.width,
|
|
26723
|
+
height: fragment.run.height
|
|
26724
|
+
});
|
|
26725
|
+
return;
|
|
26726
|
+
}
|
|
26727
|
+
if (fragment.run.type === "badge") {
|
|
26728
|
+
const badgeHeight = measureBadgeHeight(fragment.run);
|
|
26729
|
+
const badgeTop = top + (lineHeight - badgeHeight) / 2;
|
|
26730
|
+
const padding = getPadding(fragment.run.padding || [2, 4, 2, 4]).map(
|
|
26731
|
+
pxToPt
|
|
26732
|
+
);
|
|
26733
|
+
page.drawRectangle({
|
|
26734
|
+
x,
|
|
26735
|
+
y: toPdfY(context.pageHeight, badgeTop, badgeHeight),
|
|
26736
|
+
width: fragment.width,
|
|
26737
|
+
height: badgeHeight,
|
|
26738
|
+
color: toPdfColor(fragment.run.backgroundColor, "#FFFFFF"),
|
|
26739
|
+
borderColor: fragment.run.borderColor ? toPdfColor(fragment.run.borderColor) : void 0,
|
|
26740
|
+
borderWidth: fragment.run.borderColor ? 0.75 : void 0
|
|
26741
|
+
});
|
|
26742
|
+
drawTextRun(
|
|
26743
|
+
page,
|
|
26744
|
+
fragment.run,
|
|
26745
|
+
fragment.run.text,
|
|
26746
|
+
x + padding[3],
|
|
26747
|
+
badgeTop + padding[0],
|
|
26748
|
+
badgeHeight - padding[0] - padding[2],
|
|
26749
|
+
context
|
|
26750
|
+
);
|
|
26751
|
+
return;
|
|
26752
|
+
}
|
|
26753
|
+
if (fragment.run.type !== "text") {
|
|
26754
|
+
return;
|
|
26755
|
+
}
|
|
26756
|
+
drawTextRun(
|
|
26757
|
+
page,
|
|
26758
|
+
fragment.run,
|
|
26759
|
+
fragment.run.text,
|
|
26760
|
+
x,
|
|
26761
|
+
top,
|
|
26762
|
+
lineHeight,
|
|
26763
|
+
context
|
|
26764
|
+
);
|
|
26765
|
+
}
|
|
26766
|
+
function drawTextRun(page, run, text, x, top, lineHeight, context) {
|
|
26767
|
+
const resolved = resolveTextMetrics(run, context);
|
|
26768
|
+
const safeText = sanitizeTextForPdf(text, resolved.font);
|
|
26769
|
+
let textTop = top + (lineHeight - resolved.size) / 2;
|
|
26770
|
+
if (run.type === "text" && run.superscript) {
|
|
26771
|
+
textTop -= resolved.size * 0.25;
|
|
26772
|
+
}
|
|
26773
|
+
if (run.type === "text" && run.subscript) {
|
|
26774
|
+
textTop += resolved.size * 0.2;
|
|
26775
|
+
}
|
|
26776
|
+
const textY = toPdfY(context.pageHeight, textTop, resolved.size);
|
|
26777
|
+
if ("highlight" in run && run.highlight) {
|
|
26778
|
+
page.drawRectangle({
|
|
26779
|
+
x,
|
|
26780
|
+
y: textY,
|
|
26781
|
+
width: resolved.font.widthOfTextAtSize(safeText, resolved.size),
|
|
26782
|
+
height: resolved.size * 1.05,
|
|
26783
|
+
color: toPdfColor(run.highlight)
|
|
26784
|
+
});
|
|
26785
|
+
}
|
|
26786
|
+
page.drawText(safeText, {
|
|
26787
|
+
x,
|
|
26788
|
+
y: textY,
|
|
26789
|
+
size: resolved.size,
|
|
26790
|
+
font: resolved.font,
|
|
26791
|
+
color: toPdfColor(run.color, "#000000")
|
|
26792
|
+
});
|
|
26793
|
+
const textWidth = resolved.font.widthOfTextAtSize(safeText, resolved.size);
|
|
26794
|
+
if (run.underline) {
|
|
26795
|
+
const underlineY = textY - 1;
|
|
26796
|
+
page.drawLine({
|
|
26797
|
+
start: { x, y: underlineY },
|
|
26798
|
+
end: { x: x + textWidth, y: underlineY },
|
|
26799
|
+
thickness: 0.75,
|
|
26800
|
+
color: toPdfColor(run.color, "#000000")
|
|
26801
|
+
});
|
|
26802
|
+
}
|
|
26803
|
+
if (run.strikeout) {
|
|
26804
|
+
const strikeY = textY + resolved.size * 0.35;
|
|
26805
|
+
page.drawLine({
|
|
26806
|
+
start: { x, y: strikeY },
|
|
26807
|
+
end: { x: x + textWidth, y: strikeY },
|
|
26808
|
+
thickness: 0.75,
|
|
26809
|
+
color: toPdfColor(run.color, "#000000")
|
|
26810
|
+
});
|
|
26811
|
+
}
|
|
26812
|
+
}
|
|
26813
|
+
function drawTableCellBorders(page, cell, context, table, x, top, width, height) {
|
|
26814
|
+
const tableColor = table.borderColor || context.options.table.defaultBorderColor;
|
|
26815
|
+
const innerWidth = table.borderWidth || 1;
|
|
26816
|
+
const outerWidth = table.borderExternalWidth || innerWidth;
|
|
26817
|
+
const color = cell.borderColor || tableColor;
|
|
26818
|
+
const isEmpty = table.borderType === "empty" /* EMPTY */;
|
|
26819
|
+
const isExternal = table.borderType === "external" /* EXTERNAL */;
|
|
26820
|
+
const isInternal = table.borderType === "internal" /* INTERNAL */;
|
|
26821
|
+
const isDash = table.borderType === "dash" /* DASH */;
|
|
26822
|
+
const dashArray = isDash ? [3, 3] : void 0;
|
|
26823
|
+
const lineColor = toPdfColor(color, "#000000");
|
|
26824
|
+
const bottomY = toPdfY(context.pageHeight, top, height);
|
|
26825
|
+
const topY = toPdfY(context.pageHeight, top);
|
|
26826
|
+
const rightX = x + width;
|
|
26827
|
+
const drawEdge = (startX, startY, endX, endY, thickness) => {
|
|
26828
|
+
page.drawLine({
|
|
26829
|
+
start: { x: startX, y: startY },
|
|
26830
|
+
end: { x: endX, y: endY },
|
|
26831
|
+
thickness,
|
|
26832
|
+
color: lineColor,
|
|
26833
|
+
dashArray
|
|
26834
|
+
});
|
|
26835
|
+
};
|
|
26836
|
+
if (cell.borderTypes?.length) {
|
|
26837
|
+
if (cell.borderTypes.includes("top" /* TOP */)) {
|
|
26838
|
+
drawEdge(x, topY, rightX, topY, innerWidth);
|
|
26839
|
+
}
|
|
26840
|
+
if (cell.borderTypes.includes("right" /* RIGHT */)) {
|
|
26841
|
+
drawEdge(rightX, topY, rightX, bottomY, innerWidth);
|
|
26842
|
+
}
|
|
26843
|
+
if (cell.borderTypes.includes("bottom" /* BOTTOM */)) {
|
|
26844
|
+
drawEdge(x, bottomY, rightX, bottomY, innerWidth);
|
|
26845
|
+
}
|
|
26846
|
+
if (cell.borderTypes.includes("left" /* LEFT */)) {
|
|
26847
|
+
drawEdge(x, topY, x, bottomY, innerWidth);
|
|
26848
|
+
}
|
|
26849
|
+
}
|
|
26850
|
+
if (cell.borderColor && !cell.borderTypes?.length) {
|
|
26851
|
+
drawEdge(x, topY, rightX, topY, innerWidth);
|
|
26852
|
+
drawEdge(rightX, topY, rightX, bottomY, innerWidth);
|
|
26853
|
+
drawEdge(x, bottomY, rightX, bottomY, innerWidth);
|
|
26854
|
+
drawEdge(x, topY, x, bottomY, innerWidth);
|
|
26855
|
+
return;
|
|
26856
|
+
}
|
|
26857
|
+
if (isEmpty) {
|
|
26858
|
+
return;
|
|
26859
|
+
}
|
|
26860
|
+
if (!isInternal) {
|
|
26861
|
+
drawEdge(x, topY, rightX, topY, outerWidth);
|
|
26862
|
+
drawEdge(x, topY, x, bottomY, outerWidth);
|
|
26863
|
+
drawEdge(rightX, topY, rightX, bottomY, outerWidth);
|
|
26864
|
+
drawEdge(x, bottomY, rightX, bottomY, outerWidth);
|
|
26865
|
+
if (isExternal) {
|
|
26866
|
+
return;
|
|
26867
|
+
}
|
|
26868
|
+
}
|
|
26869
|
+
drawEdge(rightX, topY, rightX, bottomY, innerWidth);
|
|
26870
|
+
drawEdge(x, bottomY, rightX, bottomY, innerWidth);
|
|
26871
|
+
}
|
|
26872
|
+
function getMarkerWidth(block, context) {
|
|
26873
|
+
if (!block.context.listMarker) {
|
|
26874
|
+
return 0;
|
|
26875
|
+
}
|
|
26876
|
+
const markerRun = getMarkerRun(block, context);
|
|
26877
|
+
return measureTextWidth(block.context.listMarker.text, markerRun, context) + pxToPt(LIST_GAP);
|
|
26878
|
+
}
|
|
26879
|
+
function getMarkerRun(block, context) {
|
|
26880
|
+
const firstTextRun = block.runs.find((run) => run.type === "text" || run.type === "badge") || null;
|
|
26881
|
+
if (!firstTextRun) {
|
|
26882
|
+
return {
|
|
26883
|
+
type: "text",
|
|
26884
|
+
text: "",
|
|
26885
|
+
size: context.options.defaultSize,
|
|
26886
|
+
font: context.options.defaultFont
|
|
26887
|
+
};
|
|
26888
|
+
}
|
|
26889
|
+
if (firstTextRun.type === "badge") {
|
|
26890
|
+
return {
|
|
26891
|
+
type: "text",
|
|
26892
|
+
text: firstTextRun.text,
|
|
26893
|
+
size: firstTextRun.size,
|
|
26894
|
+
font: firstTextRun.font,
|
|
26895
|
+
bold: firstTextRun.bold,
|
|
26896
|
+
italic: firstTextRun.italic,
|
|
26897
|
+
color: firstTextRun.color
|
|
26898
|
+
};
|
|
26899
|
+
}
|
|
26900
|
+
return firstTextRun;
|
|
26901
|
+
}
|
|
26902
|
+
function getEmptyLineHeight(block, context) {
|
|
26903
|
+
const markerRun = getMarkerRun(block, context);
|
|
26904
|
+
return getRunHeight(
|
|
26905
|
+
markerRun,
|
|
26906
|
+
block.context.rowMargin || context.options.defaultRowMargin
|
|
26907
|
+
);
|
|
26908
|
+
}
|
|
26909
|
+
function getRunHeight(run, rowMargin = DEFAULT_LINE_HEIGHT2) {
|
|
26910
|
+
return run.size * rowMargin;
|
|
26911
|
+
}
|
|
26912
|
+
function resolveTextMetrics(run, context) {
|
|
26913
|
+
let size = run.size || context.options.defaultSize;
|
|
26914
|
+
if ("superscript" in run && run.superscript) {
|
|
26915
|
+
size *= 0.65;
|
|
26916
|
+
}
|
|
26917
|
+
if ("subscript" in run && run.subscript) {
|
|
26918
|
+
size *= 0.65;
|
|
26919
|
+
}
|
|
26920
|
+
return {
|
|
26921
|
+
size,
|
|
26922
|
+
font: getFont(
|
|
26923
|
+
run.font || context.options.defaultFont,
|
|
26924
|
+
!!run.bold,
|
|
26925
|
+
!!run.italic,
|
|
26926
|
+
context
|
|
26927
|
+
)
|
|
26928
|
+
};
|
|
26929
|
+
}
|
|
26930
|
+
function measureTextWidth(text, run, context) {
|
|
26931
|
+
const resolved = resolveTextMetrics(run, context);
|
|
26932
|
+
const safeText = sanitizeTextForPdf(text, resolved.font);
|
|
26933
|
+
return resolved.font.widthOfTextAtSize(safeText, resolved.size);
|
|
26934
|
+
}
|
|
26935
|
+
function measureBadgeWidth(run, context) {
|
|
26936
|
+
const padding = getPadding(run.padding || [2, 4, 2, 4]).map(pxToPt);
|
|
26937
|
+
return measureTextWidth(run.text, run, context) + padding[1] + padding[3];
|
|
26938
|
+
}
|
|
26939
|
+
function measureBadgeHeight(run) {
|
|
26940
|
+
const padding = getPadding(run.padding || [2, 4, 2, 4]).map(pxToPt);
|
|
26941
|
+
return run.size + padding[0] + padding[2];
|
|
26942
|
+
}
|
|
26943
|
+
function getJustifyExtra(line, availableWidth) {
|
|
26944
|
+
const spaceCount = line.fragments.filter(
|
|
26945
|
+
(fragment) => fragment.kind === "space"
|
|
26946
|
+
).length;
|
|
26947
|
+
if (!spaceCount || line.width >= availableWidth) {
|
|
26948
|
+
return 0;
|
|
26949
|
+
}
|
|
26950
|
+
return (availableWidth - line.width) / spaceCount;
|
|
26951
|
+
}
|
|
26952
|
+
function isLastParagraphLine(layout, line) {
|
|
26953
|
+
return layout.lines[layout.lines.length - 1] === line;
|
|
26954
|
+
}
|
|
26955
|
+
function getSpanningRowHeight(rows, rowHeights, rowIndex) {
|
|
26956
|
+
const row = rows[rowIndex];
|
|
26957
|
+
let maxHeight = rowHeights[rowIndex];
|
|
26958
|
+
for (let i = 0; i < row.cells.length; i++) {
|
|
26959
|
+
const cell = row.cells[i];
|
|
26960
|
+
maxHeight = Math.max(
|
|
26961
|
+
maxHeight,
|
|
26962
|
+
getRowSpanHeight(rowHeights, rowIndex, cell.rowspan)
|
|
26963
|
+
);
|
|
26964
|
+
}
|
|
26965
|
+
return maxHeight;
|
|
26966
|
+
}
|
|
26967
|
+
function getRowSpanHeight(rowHeights, rowIndex, rowSpan) {
|
|
26968
|
+
let height = 0;
|
|
26969
|
+
for (let i = rowIndex; i < rowIndex + rowSpan; i++) {
|
|
26970
|
+
height += rowHeights[i] || 0;
|
|
26971
|
+
}
|
|
26972
|
+
return height;
|
|
26973
|
+
}
|
|
26974
|
+
function scaleColumnWidths(widths, maxWidth) {
|
|
26975
|
+
const ptWidths = widths.map(pxToPt);
|
|
26976
|
+
const total = ptWidths.reduce((sum, width) => sum + width, 0);
|
|
26977
|
+
if (!total || total <= maxWidth) {
|
|
26978
|
+
return ptWidths;
|
|
26979
|
+
}
|
|
26980
|
+
const ratio = maxWidth / total;
|
|
26981
|
+
return ptWidths.map((width) => width * ratio);
|
|
26982
|
+
}
|
|
26983
|
+
function getColumnOffset(widths, colIndex) {
|
|
26984
|
+
let offset = 0;
|
|
26985
|
+
for (let i = 0; i < colIndex; i++) {
|
|
26986
|
+
offset += widths[i] || 0;
|
|
26987
|
+
}
|
|
26988
|
+
return offset;
|
|
26989
|
+
}
|
|
26990
|
+
function getColumnSpanWidth(widths, colIndex, span) {
|
|
26991
|
+
let width = 0;
|
|
26992
|
+
for (let i = colIndex; i < colIndex + span; i++) {
|
|
26993
|
+
width += widths[i] || 0;
|
|
26994
|
+
}
|
|
26995
|
+
return width;
|
|
26996
|
+
}
|
|
26997
|
+
function computeTableCellPlacement(trList, colgroup) {
|
|
26998
|
+
const placementMap = /* @__PURE__ */ new WeakMap();
|
|
26999
|
+
if (!trList.length || !colgroup.length) {
|
|
27000
|
+
return placementMap;
|
|
27001
|
+
}
|
|
27002
|
+
const occupiedUntilRow = Array(colgroup.length).fill(0);
|
|
27003
|
+
for (let rowIndex = 0; rowIndex < trList.length; rowIndex++) {
|
|
27004
|
+
const tr = trList[rowIndex];
|
|
27005
|
+
let colIndex = 0;
|
|
27006
|
+
for (let tdIndex = 0; tdIndex < tr.tdList.length; tdIndex++) {
|
|
27007
|
+
while (colIndex < colgroup.length && occupiedUntilRow[colIndex] > rowIndex) {
|
|
27008
|
+
colIndex += 1;
|
|
27009
|
+
}
|
|
27010
|
+
const td = tr.tdList[tdIndex];
|
|
27011
|
+
let width = 0;
|
|
27012
|
+
for (let currentCol = colIndex; currentCol < colIndex + td.colspan; currentCol++) {
|
|
27013
|
+
width += colgroup[currentCol]?.width || 0;
|
|
27014
|
+
occupiedUntilRow[currentCol] = Math.max(
|
|
27015
|
+
occupiedUntilRow[currentCol],
|
|
27016
|
+
rowIndex + td.rowspan
|
|
27017
|
+
);
|
|
27018
|
+
}
|
|
27019
|
+
placementMap.set(td, { colIndex, width });
|
|
27020
|
+
colIndex += td.colspan;
|
|
27021
|
+
}
|
|
27022
|
+
}
|
|
27023
|
+
return placementMap;
|
|
27024
|
+
}
|
|
27025
|
+
async function loadPdfImage(src, context) {
|
|
27026
|
+
if (context.imageCache.has(src)) {
|
|
27027
|
+
return context.imageCache.get(src);
|
|
27028
|
+
}
|
|
27029
|
+
try {
|
|
27030
|
+
const payload = await loadPdfImagePayload(src);
|
|
27031
|
+
const image = payload.type === "jpg" ? await context.pdfDoc.embedJpg(payload.data) : await context.pdfDoc.embedPng(payload.data);
|
|
27032
|
+
context.imageCache.set(src, image);
|
|
27033
|
+
return image;
|
|
27034
|
+
} catch {
|
|
27035
|
+
return null;
|
|
27036
|
+
}
|
|
27037
|
+
}
|
|
27038
|
+
async function loadPdfImagePayload(src) {
|
|
27039
|
+
const source = src.trim();
|
|
27040
|
+
if (source.startsWith("data:")) {
|
|
27041
|
+
return getPdfImagePayloadFromDataUrl(source);
|
|
27042
|
+
}
|
|
27043
|
+
const response = await fetch(source);
|
|
27044
|
+
if (!response.ok) {
|
|
27045
|
+
throw new Error(`Image request failed: ${response.status}`);
|
|
27046
|
+
}
|
|
27047
|
+
const contentType = response.headers.get("content-type") || "";
|
|
27048
|
+
const data2 = await response.arrayBuffer();
|
|
27049
|
+
return normalizePdfImagePayload(data2, contentType);
|
|
27050
|
+
}
|
|
27051
|
+
async function getPdfImagePayloadFromDataUrl(src) {
|
|
27052
|
+
const [, meta = "", encoded = ""] = src.match(/^data:([^,]*),(.*)$/) || [];
|
|
27053
|
+
const mime = meta.split(";")[0] || "";
|
|
27054
|
+
const isBase64 = meta.includes(";base64");
|
|
27055
|
+
const text = isBase64 ? atob(encoded) : decodeURIComponent(encoded);
|
|
27056
|
+
const bytes = new Uint8Array(text.length);
|
|
27057
|
+
for (let i = 0; i < text.length; i++) {
|
|
27058
|
+
bytes[i] = text.charCodeAt(i);
|
|
27059
|
+
}
|
|
27060
|
+
return normalizePdfImagePayload(bytes.buffer, mime);
|
|
27061
|
+
}
|
|
27062
|
+
async function normalizePdfImagePayload(data2, mime) {
|
|
27063
|
+
const lower = mime.toLowerCase();
|
|
27064
|
+
if (lower.includes("jpeg") || lower.includes("jpg")) {
|
|
27065
|
+
return {
|
|
27066
|
+
type: "jpg",
|
|
27067
|
+
data: data2
|
|
27068
|
+
};
|
|
27069
|
+
}
|
|
27070
|
+
if (lower.includes("png")) {
|
|
27071
|
+
return {
|
|
27072
|
+
type: "png",
|
|
27073
|
+
data: data2
|
|
27074
|
+
};
|
|
27075
|
+
}
|
|
27076
|
+
return {
|
|
27077
|
+
type: "png",
|
|
27078
|
+
data: await rasterizeImageToPng2(data2, mime)
|
|
27079
|
+
};
|
|
27080
|
+
}
|
|
27081
|
+
async function rasterizeImageToPng2(data2, mime) {
|
|
27082
|
+
const blob = new Blob([data2], {
|
|
27083
|
+
type: mime || "image/png"
|
|
27084
|
+
});
|
|
27085
|
+
const url = URL.createObjectURL(blob);
|
|
27086
|
+
try {
|
|
27087
|
+
const image = await loadHtmlImage2(url);
|
|
27088
|
+
const canvas = document.createElement("canvas");
|
|
27089
|
+
canvas.width = image.naturalWidth || DEFAULT_IMAGE_WIDTH2;
|
|
27090
|
+
canvas.height = image.naturalHeight || DEFAULT_IMAGE_HEIGHT2;
|
|
27091
|
+
const context = canvas.getContext("2d");
|
|
27092
|
+
if (!context) {
|
|
27093
|
+
throw new Error("Canvas context is unavailable");
|
|
27094
|
+
}
|
|
27095
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
27096
|
+
const pngBlob = await new Promise((resolve, reject) => {
|
|
27097
|
+
canvas.toBlob((output) => {
|
|
27098
|
+
if (output) {
|
|
27099
|
+
resolve(output);
|
|
27100
|
+
} else {
|
|
27101
|
+
reject(new Error("Failed to create PNG blob"));
|
|
27102
|
+
}
|
|
27103
|
+
}, "image/png");
|
|
27104
|
+
});
|
|
27105
|
+
return await pngBlob.arrayBuffer();
|
|
27106
|
+
} finally {
|
|
27107
|
+
URL.revokeObjectURL(url);
|
|
27108
|
+
}
|
|
27109
|
+
}
|
|
27110
|
+
function loadHtmlImage2(src) {
|
|
27111
|
+
return new Promise((resolve, reject) => {
|
|
27112
|
+
const image = new Image();
|
|
27113
|
+
image.onload = () => resolve(image);
|
|
27114
|
+
image.onerror = () => reject(new Error("Failed to load image"));
|
|
27115
|
+
image.src = src;
|
|
27116
|
+
});
|
|
27117
|
+
}
|
|
27118
|
+
function getInlineElementText2(element) {
|
|
27119
|
+
switch (element.type) {
|
|
27120
|
+
case "control" /* CONTROL */:
|
|
27121
|
+
return getControlText2(element.control);
|
|
27122
|
+
case "date" /* DATE */:
|
|
27123
|
+
return element.valueList?.length ? getTextFromElementList(element.valueList) : element.value;
|
|
27124
|
+
case "checkbox" /* CHECKBOX */:
|
|
27125
|
+
return element.checkbox?.value ? "\u2611" : "\u2610";
|
|
27126
|
+
case "radio" /* RADIO */:
|
|
27127
|
+
return element.radio?.value ? "\u25C9" : "\u25CB";
|
|
27128
|
+
case "label" /* LABEL */:
|
|
27129
|
+
case "latex" /* LATEX */:
|
|
27130
|
+
case "subscript" /* SUBSCRIPT */:
|
|
27131
|
+
case "superscript" /* SUPERSCRIPT */:
|
|
27132
|
+
return element.value;
|
|
27133
|
+
default:
|
|
27134
|
+
return element.value;
|
|
27135
|
+
}
|
|
27136
|
+
}
|
|
27137
|
+
function getControlText2(control) {
|
|
27138
|
+
if (!control) return "";
|
|
27139
|
+
if (control.type === "text" /* TEXT */ || control.type === "date" /* DATE */ || control.type === "number" /* NUMBER */) {
|
|
27140
|
+
const value = control.value?.length ? getTextFromElementList(control.value) : "";
|
|
27141
|
+
const content = value || control.placeholder || "";
|
|
27142
|
+
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
27143
|
+
}
|
|
27144
|
+
if (control.type === "select" /* SELECT */) {
|
|
27145
|
+
const labels = getSelectedControlLabels2(control.code, control.valueSets);
|
|
27146
|
+
const content = labels.length ? labels.join(control.multiSelectDelimiter || ", ") : control.placeholder || "";
|
|
27147
|
+
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
27148
|
+
}
|
|
27149
|
+
if (control.type === "checkbox" /* CHECKBOX */ || control.type === "radio" /* RADIO */) {
|
|
27150
|
+
const isRadio = control.type === "radio" /* RADIO */;
|
|
27151
|
+
return (control.valueSets || []).map((valueSet) => {
|
|
27152
|
+
const checked = control.code?.split(",").includes(valueSet.code) || false;
|
|
27153
|
+
return `${checked ? isRadio ? "\u25C9" : "\u2611" : isRadio ? "\u25CB" : "\u2610"} ${valueSet.value}`;
|
|
27154
|
+
}).join(" ");
|
|
27155
|
+
}
|
|
27156
|
+
return "";
|
|
27157
|
+
}
|
|
27158
|
+
function getSelectedControlLabels2(code, valueSets) {
|
|
27159
|
+
if (!code || !valueSets?.length) return [];
|
|
27160
|
+
return code.split(",").map(
|
|
27161
|
+
(selectCode) => valueSets.find((valueSet) => valueSet.code === selectCode)?.value
|
|
27162
|
+
).filter((value) => !!value);
|
|
27163
|
+
}
|
|
27164
|
+
function getBlockFallbackText2(element) {
|
|
27165
|
+
if (element.block?.iframeBlock?.src) {
|
|
27166
|
+
return element.block.iframeBlock.src;
|
|
27167
|
+
}
|
|
27168
|
+
if (element.block?.videoBlock?.src) {
|
|
27169
|
+
return element.block.videoBlock.src;
|
|
27170
|
+
}
|
|
27171
|
+
return "";
|
|
27172
|
+
}
|
|
27173
|
+
function getListItemNumberingElement2(listItemElements, fallback) {
|
|
27174
|
+
return listItemElements.find(
|
|
27175
|
+
(listItem) => listItem.listId || listItem.listLevel !== void 0 || !!listItem.listPreset || !!listItem.listStyle || !!listItem.listType
|
|
27176
|
+
) || fallback;
|
|
27177
|
+
}
|
|
27178
|
+
function getListMarker(element, orderedCounts) {
|
|
27179
|
+
const level = Math.max(0, Math.min(element.listLevel || 0, 8));
|
|
27180
|
+
if (element.listType === "ul" /* UL */) {
|
|
27181
|
+
return {
|
|
27182
|
+
text: getUnorderedMarkerText(element, level),
|
|
27183
|
+
level
|
|
27184
|
+
};
|
|
27185
|
+
}
|
|
27186
|
+
while (orderedCounts.length <= level) {
|
|
27187
|
+
orderedCounts.push(0);
|
|
27188
|
+
}
|
|
27189
|
+
orderedCounts[level] += 1;
|
|
27190
|
+
orderedCounts.length = level + 1;
|
|
27191
|
+
const style = element.listPreset ? getOrderedPresetStyle(element.listPreset, level) : getOrderedStyle(element.listStyle);
|
|
27192
|
+
const outlinePrefix = style === "outline" ? orderedCounts.slice(0, level + 1).join(".") : void 0;
|
|
27193
|
+
return {
|
|
27194
|
+
text: formatOlNumber2(orderedCounts[level] - 1, style, outlinePrefix),
|
|
27195
|
+
level
|
|
27196
|
+
};
|
|
27197
|
+
}
|
|
27198
|
+
function getOrderedPresetStyle(preset, level = 0) {
|
|
27199
|
+
const cycle = preset ? olPresetCycles[preset] : void 0;
|
|
27200
|
+
if (!cycle?.length) {
|
|
27201
|
+
return "decimal";
|
|
27202
|
+
}
|
|
27203
|
+
return cycle[level % cycle.length];
|
|
27204
|
+
}
|
|
27205
|
+
function getOrderedStyle(style) {
|
|
27206
|
+
switch (style) {
|
|
27207
|
+
case "lowerAlpha" /* LOWER_ALPHA */:
|
|
27208
|
+
return "lowerAlpha";
|
|
27209
|
+
case "upperAlpha" /* UPPER_ALPHA */:
|
|
27210
|
+
return "upperAlpha";
|
|
27211
|
+
case "lowerRoman" /* LOWER_ROMAN */:
|
|
27212
|
+
return "lowerRoman";
|
|
27213
|
+
case "upperRoman" /* UPPER_ROMAN */:
|
|
27214
|
+
return "upperRoman";
|
|
27215
|
+
case "decimalParen" /* DECIMAL_PAREN */:
|
|
27216
|
+
return "decimalParen";
|
|
27217
|
+
default:
|
|
27218
|
+
return "decimal";
|
|
27219
|
+
}
|
|
27220
|
+
}
|
|
27221
|
+
function getUnorderedMarkerText(element, level) {
|
|
27222
|
+
if (element.listPreset) {
|
|
27223
|
+
const cycle = ulPresetCycles[element.listPreset];
|
|
27224
|
+
if (cycle?.length) {
|
|
27225
|
+
return cycle[level % cycle.length];
|
|
27226
|
+
}
|
|
27227
|
+
}
|
|
27228
|
+
return bulletCharMap[element.listStyle || "disc" /* DISC */] || bulletCharMap["disc" /* DISC */];
|
|
27229
|
+
}
|
|
27230
|
+
function toAlpha2(n, upper) {
|
|
27231
|
+
let result = "";
|
|
27232
|
+
let num = n + 1;
|
|
27233
|
+
while (num > 0) {
|
|
27234
|
+
num--;
|
|
27235
|
+
result = String.fromCharCode((upper ? 65 : 97) + num % 26) + result;
|
|
27236
|
+
num = Math.floor(num / 26);
|
|
27237
|
+
}
|
|
27238
|
+
return result;
|
|
27239
|
+
}
|
|
27240
|
+
function toRoman2(n, upper) {
|
|
27241
|
+
const num = n + 1;
|
|
27242
|
+
const vals = [1e3, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
|
|
27243
|
+
const syms = [
|
|
27244
|
+
"M",
|
|
27245
|
+
"CM",
|
|
27246
|
+
"D",
|
|
27247
|
+
"CD",
|
|
27248
|
+
"C",
|
|
27249
|
+
"XC",
|
|
27250
|
+
"L",
|
|
27251
|
+
"XL",
|
|
27252
|
+
"X",
|
|
27253
|
+
"IX",
|
|
27254
|
+
"V",
|
|
27255
|
+
"IV",
|
|
27256
|
+
"I"
|
|
27257
|
+
];
|
|
27258
|
+
let result = "";
|
|
27259
|
+
let remaining = num;
|
|
27260
|
+
for (let i = 0; i < vals.length; i++) {
|
|
27261
|
+
while (remaining >= vals[i]) {
|
|
27262
|
+
result += syms[i];
|
|
27263
|
+
remaining -= vals[i];
|
|
27264
|
+
}
|
|
27265
|
+
}
|
|
27266
|
+
return upper ? result : result.toLowerCase();
|
|
27267
|
+
}
|
|
27268
|
+
function formatOlNumber2(index, style, outlinePrefix) {
|
|
27269
|
+
switch (style) {
|
|
27270
|
+
case "decimal":
|
|
27271
|
+
return `${index + 1}.`;
|
|
27272
|
+
case "decimalParen":
|
|
27273
|
+
return `${index + 1})`;
|
|
27274
|
+
case "decimalZero":
|
|
27275
|
+
return `${String(index + 1).padStart(2, "0")}.`;
|
|
27276
|
+
case "lowerAlpha":
|
|
27277
|
+
return `${toAlpha2(index, false)}.`;
|
|
27278
|
+
case "lowerAlphaParen":
|
|
27279
|
+
return `${toAlpha2(index, false)})`;
|
|
27280
|
+
case "upperAlpha":
|
|
27281
|
+
return `${toAlpha2(index, true)}.`;
|
|
27282
|
+
case "lowerRoman":
|
|
27283
|
+
return `${toRoman2(index, false)}.`;
|
|
27284
|
+
case "lowerRomanParen":
|
|
27285
|
+
return `${toRoman2(index, false)})`;
|
|
27286
|
+
case "upperRoman":
|
|
27287
|
+
return `${toRoman2(index, true)}.`;
|
|
27288
|
+
case "outline":
|
|
27289
|
+
return outlinePrefix ? `${outlinePrefix}.` : `${index + 1}.`;
|
|
27290
|
+
default:
|
|
27291
|
+
return `${index + 1}.`;
|
|
27292
|
+
}
|
|
27293
|
+
}
|
|
27294
|
+
function normalizeAlignment(rowFlex) {
|
|
27295
|
+
if (rowFlex === "alignment" /* ALIGNMENT */) {
|
|
27296
|
+
return "justify" /* JUSTIFY */;
|
|
27297
|
+
}
|
|
27298
|
+
return rowFlex || "left" /* LEFT */;
|
|
27299
|
+
}
|
|
27300
|
+
function getFont(family, bold, italic, context) {
|
|
27301
|
+
const fontSet = context.fonts[resolveFontFamily(family)];
|
|
27302
|
+
if (bold && italic) {
|
|
27303
|
+
return fontSet.boldItalic;
|
|
27304
|
+
}
|
|
27305
|
+
if (bold) {
|
|
27306
|
+
return fontSet.bold;
|
|
27307
|
+
}
|
|
27308
|
+
if (italic) {
|
|
27309
|
+
return fontSet.italic;
|
|
27310
|
+
}
|
|
27311
|
+
return fontSet.regular;
|
|
27312
|
+
}
|
|
27313
|
+
function resolveFontFamily(font) {
|
|
27314
|
+
const normalized = (font || "").trim().toLowerCase();
|
|
27315
|
+
if (normalized.includes("sans-serif") || normalized.includes("arial") || normalized.includes("helvetica") || normalized.includes("yahei") || normalized.includes("microsoft") || normalized.includes("inter") || normalized.includes("roboto")) {
|
|
27316
|
+
return "sans";
|
|
27317
|
+
}
|
|
27318
|
+
if (normalized.includes("times") || normalized === "serif" || normalized.endsWith(", serif")) {
|
|
27319
|
+
return "serif";
|
|
27320
|
+
}
|
|
27321
|
+
if (normalized.includes("courier") || normalized.includes("mono") || normalized.includes("code")) {
|
|
27322
|
+
return "mono";
|
|
27323
|
+
}
|
|
27324
|
+
return "sans";
|
|
27325
|
+
}
|
|
27326
|
+
function sanitizeTextForPdf(text, font) {
|
|
27327
|
+
let fontCache = pdfTextCache.get(font);
|
|
27328
|
+
if (!fontCache) {
|
|
27329
|
+
fontCache = /* @__PURE__ */ new Map();
|
|
27330
|
+
pdfTextCache.set(font, fontCache);
|
|
27331
|
+
}
|
|
27332
|
+
if (fontCache.has(text)) {
|
|
27333
|
+
return fontCache.get(text);
|
|
27334
|
+
}
|
|
27335
|
+
let safeText = text;
|
|
27336
|
+
try {
|
|
27337
|
+
font.encodeText(text);
|
|
27338
|
+
} catch {
|
|
27339
|
+
safeText = Array.from(text).map((char) => sanitizePdfChar(char, font)).join("");
|
|
27340
|
+
}
|
|
27341
|
+
fontCache.set(text, safeText);
|
|
27342
|
+
return safeText;
|
|
27343
|
+
}
|
|
27344
|
+
function sanitizePdfChar(char, font) {
|
|
27345
|
+
try {
|
|
27346
|
+
font.encodeText(char);
|
|
27347
|
+
return char;
|
|
27348
|
+
} catch {
|
|
27349
|
+
const directFallback = PDF_TEXT_FALLBACKS[char];
|
|
27350
|
+
if (directFallback) {
|
|
27351
|
+
return directFallback;
|
|
27352
|
+
}
|
|
27353
|
+
if (/^\s$/u.test(char)) {
|
|
27354
|
+
return " ";
|
|
27355
|
+
}
|
|
27356
|
+
const normalized = char.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^\x20-\x7E]/g, "");
|
|
27357
|
+
if (normalized) {
|
|
27358
|
+
try {
|
|
27359
|
+
font.encodeText(normalized);
|
|
27360
|
+
return normalized;
|
|
27361
|
+
} catch {
|
|
27362
|
+
return "?";
|
|
27363
|
+
}
|
|
27364
|
+
}
|
|
27365
|
+
return "?";
|
|
27366
|
+
}
|
|
27367
|
+
}
|
|
27368
|
+
function getPadding(padding) {
|
|
27369
|
+
return [padding[0] ?? 0, padding[1] ?? 0, padding[2] ?? 0, padding[3] ?? 0];
|
|
27370
|
+
}
|
|
27371
|
+
function getTitleSize(titleLevel, options) {
|
|
27372
|
+
if (!titleLevel) {
|
|
27373
|
+
return void 0;
|
|
27374
|
+
}
|
|
27375
|
+
return options.title[titleSizeMapping[titleLevel]];
|
|
27376
|
+
}
|
|
27377
|
+
function getPageNumberHeight(pageNumber) {
|
|
27378
|
+
if (pageNumber.disabled) {
|
|
27379
|
+
return 0;
|
|
27380
|
+
}
|
|
27381
|
+
return pageNumber.size || 12;
|
|
27382
|
+
}
|
|
27383
|
+
function getFooterBarHeight(footerHeight, context) {
|
|
27384
|
+
if (context.options.footer.disabled) {
|
|
27385
|
+
return 0;
|
|
27386
|
+
}
|
|
27387
|
+
return Math.max(footerHeight, pxToPt(FOOTER_MIN_BAR_HEIGHT));
|
|
27388
|
+
}
|
|
27389
|
+
function getReservedPageNumberBottom(pageNumber, pageNumberHeight) {
|
|
27390
|
+
if (pageNumber.disabled) {
|
|
27391
|
+
return 0;
|
|
27392
|
+
}
|
|
27393
|
+
return pxToPt(pageNumber.bottom + 4) + pageNumberHeight;
|
|
27394
|
+
}
|
|
27395
|
+
function normalizeText2(text = "") {
|
|
27396
|
+
return text.replace(new RegExp(ZERO, "g"), "").replace(/\r\n/g, "\n");
|
|
27397
|
+
}
|
|
27398
|
+
function normalizePdfFileName(fileName) {
|
|
27399
|
+
const trimmed = fileName?.trim();
|
|
27400
|
+
if (!trimmed) {
|
|
27401
|
+
return DEFAULT_PDF_FILE_NAME;
|
|
27402
|
+
}
|
|
27403
|
+
return trimmed.toLowerCase().endsWith(".pdf") ? trimmed : `${trimmed}.pdf`;
|
|
27404
|
+
}
|
|
27405
|
+
function pxToPt(px) {
|
|
27406
|
+
return px * (72 / 96);
|
|
27407
|
+
}
|
|
27408
|
+
function toPdfY(pageHeight, top, height = 0) {
|
|
27409
|
+
return pageHeight - top - height;
|
|
27410
|
+
}
|
|
27411
|
+
function toPdfColor(color, fallback = "#000000") {
|
|
27412
|
+
const hex = normalizeHexColor2(color || fallback, "000000") || "000000";
|
|
27413
|
+
const red = parseInt(hex.slice(0, 2), 16) / 255;
|
|
27414
|
+
const green = parseInt(hex.slice(2, 4), 16) / 255;
|
|
27415
|
+
const blue = parseInt(hex.slice(4, 6), 16) / 255;
|
|
27416
|
+
return rgb(red, green, blue);
|
|
27417
|
+
}
|
|
27418
|
+
function normalizeHexColor2(color, fallback) {
|
|
27419
|
+
const normalized = normalizeHexLiteral2(color) || normalizeRgbColor2(color) || normalizeBrowserColor2(color);
|
|
27420
|
+
if (normalized) {
|
|
27421
|
+
return normalized;
|
|
27422
|
+
}
|
|
27423
|
+
return fallback ? normalizeHexLiteral2(fallback) || void 0 : void 0;
|
|
27424
|
+
}
|
|
27425
|
+
function normalizeHexLiteral2(color) {
|
|
27426
|
+
const value = color.trim().replace(/^#/, "");
|
|
27427
|
+
if (/^[\da-f]{3}$/i.test(value)) {
|
|
27428
|
+
return value.split("").map((part) => `${part}${part}`).join("").toUpperCase();
|
|
27429
|
+
}
|
|
27430
|
+
if (/^[\da-f]{4}$/i.test(value)) {
|
|
27431
|
+
return value.slice(0, 3).split("").map((part) => `${part}${part}`).join("").toUpperCase();
|
|
27432
|
+
}
|
|
27433
|
+
if (/^[\da-f]{6}$/i.test(value)) {
|
|
27434
|
+
return value.toUpperCase();
|
|
27435
|
+
}
|
|
27436
|
+
if (/^[\da-f]{8}$/i.test(value)) {
|
|
27437
|
+
return value.slice(0, 6).toUpperCase();
|
|
27438
|
+
}
|
|
27439
|
+
return void 0;
|
|
27440
|
+
}
|
|
27441
|
+
function normalizeRgbColor2(color) {
|
|
27442
|
+
const match = color.trim().match(/^rgba?\((.+)\)$/i);
|
|
27443
|
+
if (!match) {
|
|
27444
|
+
return void 0;
|
|
27445
|
+
}
|
|
27446
|
+
const parts = match[1].replace(/\s*\/\s*/g, ",").split(/\s*,\s*|\s+/).filter(Boolean);
|
|
27447
|
+
if (parts.length < 3) {
|
|
27448
|
+
return void 0;
|
|
27449
|
+
}
|
|
27450
|
+
const red = parseRgbChannel2(parts[0]);
|
|
27451
|
+
const green = parseRgbChannel2(parts[1]);
|
|
27452
|
+
const blue = parseRgbChannel2(parts[2]);
|
|
27453
|
+
if (red === null || green === null || blue === null) {
|
|
27454
|
+
return void 0;
|
|
27455
|
+
}
|
|
27456
|
+
const alpha = parts[3] !== void 0 ? parseAlphaChannel2(parts[3]) : 1;
|
|
27457
|
+
if (alpha === null || alpha <= 0) {
|
|
27458
|
+
return void 0;
|
|
27459
|
+
}
|
|
27460
|
+
const flattened = alpha >= 1 ? [red, green, blue] : [
|
|
27461
|
+
flattenChannel2(red, alpha),
|
|
27462
|
+
flattenChannel2(green, alpha),
|
|
27463
|
+
flattenChannel2(blue, alpha)
|
|
27464
|
+
];
|
|
27465
|
+
return flattened.map(toHexChannel2).join("");
|
|
27466
|
+
}
|
|
27467
|
+
function normalizeBrowserColor2(color) {
|
|
27468
|
+
if (typeof document === "undefined") {
|
|
27469
|
+
return void 0;
|
|
27470
|
+
}
|
|
27471
|
+
const canvas = document.createElement("canvas");
|
|
27472
|
+
const context = canvas.getContext("2d");
|
|
27473
|
+
if (!context) {
|
|
27474
|
+
return void 0;
|
|
27475
|
+
}
|
|
27476
|
+
context.fillStyle = "#000000";
|
|
27477
|
+
context.fillStyle = color;
|
|
27478
|
+
const normalized = context.fillStyle;
|
|
27479
|
+
if (typeof normalized !== "string") {
|
|
27480
|
+
return void 0;
|
|
27481
|
+
}
|
|
27482
|
+
return normalizeHexLiteral2(normalized) || normalizeRgbColor2(normalized);
|
|
27483
|
+
}
|
|
27484
|
+
function parseRgbChannel2(value) {
|
|
27485
|
+
if (value.endsWith("%")) {
|
|
27486
|
+
const percent = Number(value.slice(0, -1));
|
|
27487
|
+
if (!Number.isFinite(percent)) {
|
|
27488
|
+
return null;
|
|
27489
|
+
}
|
|
27490
|
+
return clampColorChannel2(Math.round(percent / 100 * 255));
|
|
27491
|
+
}
|
|
27492
|
+
const channel = Number(value);
|
|
27493
|
+
if (!Number.isFinite(channel)) {
|
|
27494
|
+
return null;
|
|
27495
|
+
}
|
|
27496
|
+
return clampColorChannel2(Math.round(channel));
|
|
27497
|
+
}
|
|
27498
|
+
function parseAlphaChannel2(value) {
|
|
27499
|
+
if (value.endsWith("%")) {
|
|
27500
|
+
const percent = Number(value.slice(0, -1));
|
|
27501
|
+
if (!Number.isFinite(percent)) {
|
|
27502
|
+
return null;
|
|
27503
|
+
}
|
|
27504
|
+
return Math.min(Math.max(percent / 100, 0), 1);
|
|
27505
|
+
}
|
|
27506
|
+
const alpha = Number(value);
|
|
27507
|
+
if (!Number.isFinite(alpha)) {
|
|
27508
|
+
return null;
|
|
27509
|
+
}
|
|
27510
|
+
return Math.min(Math.max(alpha, 0), 1);
|
|
27511
|
+
}
|
|
27512
|
+
function clampColorChannel2(value) {
|
|
27513
|
+
return Math.min(Math.max(value, 0), 255);
|
|
27514
|
+
}
|
|
27515
|
+
function flattenChannel2(value, alpha) {
|
|
27516
|
+
return clampColorChannel2(Math.round(255 * (1 - alpha) + value * alpha));
|
|
27517
|
+
}
|
|
27518
|
+
function toHexChannel2(value) {
|
|
27519
|
+
return value.toString(16).padStart(2, "0").toUpperCase();
|
|
27520
|
+
}
|
|
27521
|
+
|
|
27522
|
+
// src/utils/print.ts
|
|
27523
|
+
function convertPxToPaperSize(width, height) {
|
|
27524
|
+
if (width === 1125 && height === 1593) {
|
|
27525
|
+
return {
|
|
27526
|
+
size: "a3",
|
|
27527
|
+
width: "297mm",
|
|
27528
|
+
height: "420mm"
|
|
27529
|
+
};
|
|
27530
|
+
}
|
|
27531
|
+
if (width === 794 && height === 1123) {
|
|
27532
|
+
return {
|
|
27533
|
+
size: "a4",
|
|
27534
|
+
width: "210mm",
|
|
27535
|
+
height: "297mm"
|
|
27536
|
+
};
|
|
27537
|
+
}
|
|
27538
|
+
if (width === 565 && height === 796) {
|
|
27539
|
+
return {
|
|
27540
|
+
size: "a5",
|
|
27541
|
+
width: "148mm",
|
|
27542
|
+
height: "210mm"
|
|
27543
|
+
};
|
|
27544
|
+
}
|
|
27545
|
+
return {
|
|
27546
|
+
size: "",
|
|
27547
|
+
width: `${width}px`,
|
|
27548
|
+
height: `${height}px`
|
|
27549
|
+
};
|
|
27550
|
+
}
|
|
27551
|
+
function printImageBase64(base64List, options) {
|
|
27552
|
+
const { width, height, direction = "vertical" /* VERTICAL */ } = options;
|
|
27553
|
+
const iframe = document.createElement("iframe");
|
|
27554
|
+
iframe.style.visibility = "hidden";
|
|
27555
|
+
iframe.style.position = "absolute";
|
|
27556
|
+
iframe.style.left = "0";
|
|
27557
|
+
iframe.style.top = "0";
|
|
27558
|
+
iframe.style.width = "0";
|
|
27559
|
+
iframe.style.height = "0";
|
|
27560
|
+
iframe.style.border = "none";
|
|
27561
|
+
document.body.append(iframe);
|
|
27562
|
+
const contentWindow = iframe.contentWindow;
|
|
27563
|
+
const doc = contentWindow.document;
|
|
27564
|
+
doc.open();
|
|
27565
|
+
const container = document.createElement("div");
|
|
27566
|
+
const paperSize = convertPxToPaperSize(width, height);
|
|
27567
|
+
base64List.forEach((base64) => {
|
|
27568
|
+
const image = document.createElement("img");
|
|
27569
|
+
image.style.width = direction === "horizontal" /* HORIZONTAL */ ? paperSize.height : paperSize.width;
|
|
27570
|
+
image.style.height = direction === "horizontal" /* HORIZONTAL */ ? paperSize.width : paperSize.height;
|
|
27571
|
+
image.src = base64;
|
|
27572
|
+
container.append(image);
|
|
27573
|
+
});
|
|
27574
|
+
const style = document.createElement("style");
|
|
27575
|
+
const stylesheet = `
|
|
27576
|
+
* {
|
|
27577
|
+
margin: 0;
|
|
27578
|
+
padding: 0;
|
|
27579
|
+
}
|
|
27580
|
+
@page {
|
|
27581
|
+
margin: 0;
|
|
27582
|
+
size: ${paperSize.size} ${direction === "horizontal" /* HORIZONTAL */ ? `landscape` : `portrait`};
|
|
27583
|
+
}`;
|
|
27584
|
+
style.append(document.createTextNode(stylesheet));
|
|
27585
|
+
setTimeout(() => {
|
|
27586
|
+
doc.write(`${style.outerHTML}${container.innerHTML}`);
|
|
27587
|
+
contentWindow.print();
|
|
27588
|
+
doc.close();
|
|
27589
|
+
window.addEventListener(
|
|
27590
|
+
"mouseover",
|
|
27591
|
+
() => {
|
|
27592
|
+
iframe?.remove();
|
|
27593
|
+
},
|
|
27594
|
+
{
|
|
27595
|
+
once: true
|
|
27596
|
+
}
|
|
27597
|
+
);
|
|
27598
|
+
});
|
|
27599
|
+
}
|
|
27600
|
+
|
|
27601
|
+
// src/core/command/CommandAdapt.ts
|
|
27602
|
+
var CommandAdapt = class {
|
|
27603
|
+
constructor(draw) {
|
|
27604
|
+
this.draw = draw;
|
|
27605
|
+
this.range = draw.getRange();
|
|
27606
|
+
this.position = draw.getPosition();
|
|
27607
|
+
this.historyManager = draw.getHistoryManager();
|
|
27608
|
+
this.canvasEvent = draw.getCanvasEvent();
|
|
27609
|
+
this.options = draw.getOptions();
|
|
27610
|
+
this.control = draw.getControl();
|
|
27611
|
+
this.workerManager = draw.getWorkerManager();
|
|
27612
|
+
this.searchManager = draw.getSearch();
|
|
27613
|
+
this.i18n = draw.getI18n();
|
|
27614
|
+
this.zone = draw.getZone();
|
|
27615
|
+
this.tableOperate = draw.getTableOperate();
|
|
27616
|
+
}
|
|
27617
|
+
getStyleSelectionElementList(options = {}) {
|
|
27618
|
+
const selection = this.range.getSelectionElementList();
|
|
27619
|
+
if (!selection?.length) return null;
|
|
27620
|
+
const { textLikeOnly = false } = options;
|
|
27621
|
+
const result = [];
|
|
27622
|
+
const collect = (elementList) => {
|
|
27623
|
+
for (let i = 0; i < elementList.length; i++) {
|
|
27624
|
+
const element = elementList[i];
|
|
27625
|
+
if (element.type === "table" /* TABLE */ && element.trList?.length) {
|
|
27626
|
+
for (let t = 0; t < element.trList.length; t++) {
|
|
27627
|
+
const tr = element.trList[t];
|
|
27628
|
+
for (let d = 0; d < tr.tdList.length; d++) {
|
|
27629
|
+
collect(tr.tdList[d].value);
|
|
27630
|
+
}
|
|
27631
|
+
}
|
|
27632
|
+
continue;
|
|
27633
|
+
}
|
|
27634
|
+
result.push(element);
|
|
27635
|
+
}
|
|
27636
|
+
};
|
|
27637
|
+
collect(selection);
|
|
27638
|
+
if (!textLikeOnly) {
|
|
27639
|
+
return result;
|
|
27640
|
+
}
|
|
27641
|
+
return result.filter(
|
|
27642
|
+
(element) => isTextLikeElement(element) || element.type === "label" /* LABEL */
|
|
27643
|
+
);
|
|
27644
|
+
}
|
|
27645
|
+
mode(payload) {
|
|
27646
|
+
this.draw.setMode(payload);
|
|
27647
|
+
}
|
|
27648
|
+
async cut() {
|
|
27649
|
+
const isDisabled = this.draw.isReadonly() || this.draw.isDisabled();
|
|
27650
|
+
if (isDisabled) return;
|
|
27651
|
+
await this.canvasEvent.cut();
|
|
27652
|
+
}
|
|
27653
|
+
async copy(payload) {
|
|
27654
|
+
await this.canvasEvent.copy(payload);
|
|
27655
|
+
}
|
|
27656
|
+
paste(payload) {
|
|
27657
|
+
const isDisabled = this.draw.isReadonly() || this.draw.isDisabled();
|
|
27658
|
+
if (isDisabled) return;
|
|
27659
|
+
pasteByApi(this.canvasEvent, payload);
|
|
27660
|
+
}
|
|
27661
|
+
selectAll() {
|
|
27662
|
+
this.canvasEvent.selectAll();
|
|
27663
|
+
}
|
|
27664
|
+
backspace() {
|
|
27665
|
+
const isDisabled = this.draw.isReadonly() || this.draw.isDisabled();
|
|
27666
|
+
if (isDisabled) return;
|
|
27667
|
+
const elementList = this.draw.getElementList();
|
|
27668
|
+
const { startIndex, endIndex } = this.range.getRange();
|
|
27669
|
+
const isCollapsed = startIndex === endIndex;
|
|
27670
|
+
if (isCollapsed && elementList[startIndex].value === ZERO && startIndex === 0) {
|
|
27671
|
+
return;
|
|
27672
|
+
}
|
|
27673
|
+
if (!isCollapsed) {
|
|
27674
|
+
this.draw.spliceElementList(
|
|
27675
|
+
elementList,
|
|
27676
|
+
startIndex + 1,
|
|
27677
|
+
endIndex - startIndex
|
|
27678
|
+
);
|
|
27679
|
+
} else {
|
|
27680
|
+
this.draw.spliceElementList(elementList, startIndex, 1);
|
|
27681
|
+
}
|
|
27682
|
+
const curIndex = isCollapsed ? startIndex - 1 : startIndex;
|
|
27683
|
+
this.range.setRange(curIndex, curIndex);
|
|
27684
|
+
this.draw.render({ curIndex });
|
|
27685
|
+
}
|
|
27686
|
+
setRange(startIndex, endIndex, tableId, startTdIndex, endTdIndex, startTrIndex, endTrIndex) {
|
|
27687
|
+
if (startIndex < 0 || endIndex < 0 || endIndex < startIndex) return;
|
|
24507
27688
|
this.range.setRange(
|
|
24508
27689
|
startIndex,
|
|
24509
27690
|
endIndex,
|
|
@@ -25550,6 +28731,16 @@ var CommandAdapt = class {
|
|
|
25550
28731
|
this.draw.setPageScale(scale);
|
|
25551
28732
|
}
|
|
25552
28733
|
}
|
|
28734
|
+
async exportDocx(payload = {}) {
|
|
28735
|
+
const result = this.draw.getValue();
|
|
28736
|
+
const { blob, fileName } = await exportEditorDataToDocx(result, payload);
|
|
28737
|
+
downloadBlob(blob, fileName);
|
|
28738
|
+
}
|
|
28739
|
+
async exportPdf(payload = {}) {
|
|
28740
|
+
const result = this.draw.getValue();
|
|
28741
|
+
const { blob, fileName } = await exportEditorDataToPdf(result, payload);
|
|
28742
|
+
downloadBlob(blob, fileName);
|
|
28743
|
+
}
|
|
25553
28744
|
replaceImageElement(payload) {
|
|
25554
28745
|
const { startIndex } = this.range.getRange();
|
|
25555
28746
|
const elementList = this.draw.getElementList();
|