@windoc/core 0.3.25 → 0.3.27
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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +953 -1158
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +953 -1160
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -78,7 +78,7 @@ __export(index_exports, {
|
|
|
78
78
|
module.exports = __toCommonJS(index_exports);
|
|
79
79
|
|
|
80
80
|
// src/version.ts
|
|
81
|
-
var version = "0.3.
|
|
81
|
+
var version = "0.3.27";
|
|
82
82
|
|
|
83
83
|
// src/dataset/enum/Common.ts
|
|
84
84
|
var MaxHeightRatio = /* @__PURE__ */ ((MaxHeightRatio2) => {
|
|
@@ -19190,10 +19190,11 @@ var ListParticle = class {
|
|
|
19190
19190
|
if (!cycle) return "\u25CF";
|
|
19191
19191
|
return cycle[level % cycle.length];
|
|
19192
19192
|
}
|
|
19193
|
-
|
|
19194
|
-
|
|
19193
|
+
// Marker x for a list row's first line (shared by canvas drawing and export)
|
|
19194
|
+
getListMarkerX(row, position) {
|
|
19195
|
+
const { elementList, offsetX } = row;
|
|
19195
19196
|
const startElement = elementList[0];
|
|
19196
|
-
if (startElement.value !== ZERO || startElement.listWrap) return;
|
|
19197
|
+
if (startElement.value !== ZERO || startElement.listWrap) return null;
|
|
19197
19198
|
let tabWidth = 0;
|
|
19198
19199
|
const { defaultTabWidth, scale } = this.options;
|
|
19199
19200
|
for (let i = 1; i < elementList.length; i++) {
|
|
@@ -19203,12 +19204,29 @@ var ListParticle = class {
|
|
|
19203
19204
|
}
|
|
19204
19205
|
const {
|
|
19205
19206
|
coordinate: {
|
|
19206
|
-
leftTop: [startX
|
|
19207
|
+
leftTop: [startX]
|
|
19207
19208
|
}
|
|
19208
19209
|
} = position;
|
|
19209
19210
|
const indentWidth = this.getListIndentWidth(startElement);
|
|
19210
|
-
|
|
19211
|
-
|
|
19211
|
+
return startX - offsetX + tabWidth + indentWidth;
|
|
19212
|
+
}
|
|
19213
|
+
getListMarker(row) {
|
|
19214
|
+
const startElement = row.elementList[0];
|
|
19215
|
+
if (startElement.listStyle === "checkbox" /* CHECKBOX */) return null;
|
|
19216
|
+
const text = this._getListMarkerText(startElement, row.listIndex);
|
|
19217
|
+
if (!text) return null;
|
|
19218
|
+
return {
|
|
19219
|
+
text,
|
|
19220
|
+
styleElement: this._getListMarkerStyleElement(row.elementList)
|
|
19221
|
+
};
|
|
19222
|
+
}
|
|
19223
|
+
drawListStyle(ctx, row, position) {
|
|
19224
|
+
const { elementList, ascent } = row;
|
|
19225
|
+
const startElement = elementList[0];
|
|
19226
|
+
const x = this.getListMarkerX(row, position);
|
|
19227
|
+
if (x === null) return;
|
|
19228
|
+
const { scale } = this.options;
|
|
19229
|
+
const y = position.coordinate.leftTop[1] + ascent;
|
|
19212
19230
|
if (startElement.listStyle === "checkbox" /* CHECKBOX */) {
|
|
19213
19231
|
const { width, height, gap } = this.options.checkbox;
|
|
19214
19232
|
const checkboxRowElement = {
|
|
@@ -19233,12 +19251,11 @@ var ListParticle = class {
|
|
|
19233
19251
|
}
|
|
19234
19252
|
});
|
|
19235
19253
|
} else {
|
|
19236
|
-
const
|
|
19237
|
-
if (!
|
|
19238
|
-
const markerStyleElement = this._getListMarkerStyleElement(elementList);
|
|
19254
|
+
const marker = this.getListMarker(row);
|
|
19255
|
+
if (!marker) return;
|
|
19239
19256
|
ctx.save();
|
|
19240
|
-
ctx.font = this.draw.getElementFont(
|
|
19241
|
-
ctx.fillText(text, x, y);
|
|
19257
|
+
ctx.font = this.draw.getElementFont(marker.styleElement, scale);
|
|
19258
|
+
ctx.fillText(marker.text, x, y);
|
|
19242
19259
|
ctx.restore();
|
|
19243
19260
|
}
|
|
19244
19261
|
}
|
|
@@ -24426,1214 +24443,992 @@ var Command = class {
|
|
|
24426
24443
|
}
|
|
24427
24444
|
};
|
|
24428
24445
|
|
|
24446
|
+
// src/utils/docxLayout.ts
|
|
24447
|
+
var import_docx2 = require("docx");
|
|
24448
|
+
|
|
24429
24449
|
// src/utils/docx.ts
|
|
24430
24450
|
var import_docx = require("docx");
|
|
24431
24451
|
var DEFAULT_DOCX_FILE_NAME = "document.docx";
|
|
24432
24452
|
var DEFAULT_IMAGE_WIDTH = 320;
|
|
24433
24453
|
var DEFAULT_IMAGE_HEIGHT = 180;
|
|
24434
|
-
|
|
24435
|
-
|
|
24436
|
-
|
|
24437
|
-
|
|
24438
|
-
|
|
24439
|
-
|
|
24440
|
-
|
|
24441
|
-
|
|
24442
|
-
|
|
24443
|
-
|
|
24444
|
-
|
|
24445
|
-
|
|
24446
|
-
|
|
24447
|
-
|
|
24448
|
-
|
|
24449
|
-
|
|
24450
|
-
|
|
24451
|
-
|
|
24452
|
-
|
|
24453
|
-
|
|
24454
|
-
|
|
24455
|
-
|
|
24456
|
-
|
|
24457
|
-
|
|
24458
|
-
|
|
24459
|
-
|
|
24460
|
-
|
|
24461
|
-
|
|
24462
|
-
|
|
24463
|
-
|
|
24464
|
-
|
|
24454
|
+
async function loadImagePayload(src) {
|
|
24455
|
+
const source = src.trim();
|
|
24456
|
+
if (source.startsWith("data:")) {
|
|
24457
|
+
return getImagePayloadFromDataUrl(source);
|
|
24458
|
+
}
|
|
24459
|
+
const response = await fetch(source);
|
|
24460
|
+
if (!response.ok) {
|
|
24461
|
+
throw new Error(`Image request failed: ${response.status}`);
|
|
24462
|
+
}
|
|
24463
|
+
const contentType = response.headers.get("content-type") || "";
|
|
24464
|
+
const data2 = await response.arrayBuffer();
|
|
24465
|
+
return normalizeImagePayload(data2, contentType);
|
|
24466
|
+
}
|
|
24467
|
+
async function getImagePayloadFromDataUrl(src) {
|
|
24468
|
+
const [, meta = "", encoded = ""] = src.match(/^data:([^,]*),(.*)$/) || [];
|
|
24469
|
+
const mime = meta.split(";")[0] || "";
|
|
24470
|
+
const isBase64 = meta.includes(";base64");
|
|
24471
|
+
const text = isBase64 ? atob(encoded) : decodeURIComponent(encoded);
|
|
24472
|
+
const bytes = new Uint8Array(text.length);
|
|
24473
|
+
for (let i = 0; i < text.length; i++) {
|
|
24474
|
+
bytes[i] = text.charCodeAt(i);
|
|
24475
|
+
}
|
|
24476
|
+
return normalizeImagePayload(bytes.buffer, mime);
|
|
24477
|
+
}
|
|
24478
|
+
async function normalizeImagePayload(data2, mime) {
|
|
24479
|
+
const type = getRegularImageType(mime);
|
|
24480
|
+
if (type) {
|
|
24481
|
+
return {
|
|
24482
|
+
type,
|
|
24483
|
+
data: data2
|
|
24484
|
+
};
|
|
24485
|
+
}
|
|
24486
|
+
if (mime.includes("svg")) {
|
|
24487
|
+
return {
|
|
24488
|
+
type: "svg",
|
|
24489
|
+
data: data2,
|
|
24490
|
+
fallbackPng: await rasterizeSvgToPng(data2)
|
|
24491
|
+
};
|
|
24492
|
+
}
|
|
24493
|
+
const fallbackPng = await rasterizeImageToPng(data2, mime);
|
|
24465
24494
|
return {
|
|
24466
|
-
|
|
24467
|
-
|
|
24495
|
+
type: "png",
|
|
24496
|
+
data: fallbackPng
|
|
24468
24497
|
};
|
|
24469
24498
|
}
|
|
24470
|
-
async function
|
|
24471
|
-
|
|
24472
|
-
|
|
24473
|
-
|
|
24474
|
-
const
|
|
24475
|
-
|
|
24476
|
-
|
|
24477
|
-
|
|
24478
|
-
|
|
24479
|
-
|
|
24480
|
-
|
|
24499
|
+
async function rasterizeSvgToPng(data2) {
|
|
24500
|
+
return rasterizeImageToPng(data2, "image/svg+xml");
|
|
24501
|
+
}
|
|
24502
|
+
async function rasterizeImageToPng(data2, mime) {
|
|
24503
|
+
const blob = new Blob([data2], {
|
|
24504
|
+
type: mime || "image/png"
|
|
24505
|
+
});
|
|
24506
|
+
const url = URL.createObjectURL(blob);
|
|
24507
|
+
try {
|
|
24508
|
+
const image = await loadHtmlImage(url);
|
|
24509
|
+
const canvas = document.createElement("canvas");
|
|
24510
|
+
canvas.width = image.naturalWidth || DEFAULT_IMAGE_WIDTH;
|
|
24511
|
+
canvas.height = image.naturalHeight || DEFAULT_IMAGE_HEIGHT;
|
|
24512
|
+
const context = canvas.getContext("2d");
|
|
24513
|
+
if (!context) {
|
|
24514
|
+
throw new Error("Canvas context is unavailable");
|
|
24515
|
+
}
|
|
24516
|
+
context.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
24517
|
+
const pngBlob = await new Promise((resolve, reject) => {
|
|
24518
|
+
canvas.toBlob((output) => {
|
|
24519
|
+
if (output) {
|
|
24520
|
+
resolve(output);
|
|
24521
|
+
} else {
|
|
24522
|
+
reject(new Error("Failed to create PNG blob"));
|
|
24523
|
+
}
|
|
24524
|
+
}, "image/png");
|
|
24525
|
+
});
|
|
24526
|
+
return await pngBlob.arrayBuffer();
|
|
24527
|
+
} finally {
|
|
24528
|
+
URL.revokeObjectURL(url);
|
|
24481
24529
|
}
|
|
24482
|
-
|
|
24483
|
-
|
|
24484
|
-
|
|
24485
|
-
|
|
24486
|
-
|
|
24487
|
-
|
|
24488
|
-
|
|
24489
|
-
|
|
24490
|
-
|
|
24491
|
-
|
|
24492
|
-
|
|
24493
|
-
|
|
24494
|
-
|
|
24495
|
-
|
|
24530
|
+
}
|
|
24531
|
+
function loadHtmlImage(src) {
|
|
24532
|
+
return new Promise((resolve, reject) => {
|
|
24533
|
+
const image = new Image();
|
|
24534
|
+
image.onload = () => resolve(image);
|
|
24535
|
+
image.onerror = () => reject(new Error("Failed to load image"));
|
|
24536
|
+
image.src = src;
|
|
24537
|
+
});
|
|
24538
|
+
}
|
|
24539
|
+
function mapUnderlineType(style) {
|
|
24540
|
+
switch (style) {
|
|
24541
|
+
case "double" /* DOUBLE */:
|
|
24542
|
+
return import_docx.UnderlineType.DOUBLE;
|
|
24543
|
+
case "dashed" /* DASHED */:
|
|
24544
|
+
return import_docx.UnderlineType.DASH;
|
|
24545
|
+
case "dotted" /* DOTTED */:
|
|
24546
|
+
return import_docx.UnderlineType.DOTTED;
|
|
24547
|
+
case "wavy" /* WAVY */:
|
|
24548
|
+
return import_docx.UnderlineType.WAVE;
|
|
24549
|
+
default:
|
|
24550
|
+
return import_docx.UnderlineType.SINGLE;
|
|
24551
|
+
}
|
|
24552
|
+
}
|
|
24553
|
+
function normalizeHexColor(color, fallback) {
|
|
24554
|
+
const normalized = normalizeHexLiteral(color) || normalizeRgbColor(color) || normalizeBrowserColor(color);
|
|
24555
|
+
if (normalized) {
|
|
24556
|
+
return normalized;
|
|
24557
|
+
}
|
|
24558
|
+
return fallback ? normalizeHexLiteral(fallback) || void 0 : void 0;
|
|
24559
|
+
}
|
|
24560
|
+
function normalizeHexLiteral(color) {
|
|
24561
|
+
const value = color.trim().replace(/^#/, "");
|
|
24562
|
+
if (/^[\da-f]{3}$/i.test(value)) {
|
|
24563
|
+
return value.split("").map((part) => `${part}${part}`).join("").toUpperCase();
|
|
24564
|
+
}
|
|
24565
|
+
if (/^[\da-f]{4}$/i.test(value)) {
|
|
24566
|
+
return value.slice(0, 3).split("").map((part) => `${part}${part}`).join("").toUpperCase();
|
|
24567
|
+
}
|
|
24568
|
+
if (/^[\da-f]{6}$/i.test(value)) {
|
|
24569
|
+
return value.toUpperCase();
|
|
24570
|
+
}
|
|
24571
|
+
if (/^[\da-f]{8}$/i.test(value)) {
|
|
24572
|
+
return value.slice(0, 6).toUpperCase();
|
|
24573
|
+
}
|
|
24574
|
+
return void 0;
|
|
24575
|
+
}
|
|
24576
|
+
function normalizeRgbColor(color) {
|
|
24577
|
+
const match = color.trim().match(/^rgba?\((.+)\)$/i);
|
|
24578
|
+
if (!match) {
|
|
24579
|
+
return void 0;
|
|
24580
|
+
}
|
|
24581
|
+
const parts = match[1].replace(/\s*\/\s*/g, ",").split(/\s*,\s*|\s+/).filter(Boolean);
|
|
24582
|
+
if (parts.length < 3) {
|
|
24583
|
+
return void 0;
|
|
24584
|
+
}
|
|
24585
|
+
const red = parseRgbChannel(parts[0]);
|
|
24586
|
+
const green = parseRgbChannel(parts[1]);
|
|
24587
|
+
const blue = parseRgbChannel(parts[2]);
|
|
24588
|
+
if (red === null || green === null || blue === null) {
|
|
24589
|
+
return void 0;
|
|
24590
|
+
}
|
|
24591
|
+
const alpha = parts[3] !== void 0 ? parseAlphaChannel(parts[3]) : 1;
|
|
24592
|
+
if (alpha === null || alpha <= 0) {
|
|
24593
|
+
return void 0;
|
|
24594
|
+
}
|
|
24595
|
+
const flattened = alpha >= 1 ? [red, green, blue] : [
|
|
24596
|
+
flattenChannel(red, alpha),
|
|
24597
|
+
flattenChannel(green, alpha),
|
|
24598
|
+
flattenChannel(blue, alpha)
|
|
24599
|
+
];
|
|
24600
|
+
return flattened.map(toHexChannel).join("");
|
|
24601
|
+
}
|
|
24602
|
+
function normalizeBrowserColor(color) {
|
|
24603
|
+
if (typeof document === "undefined") {
|
|
24604
|
+
return void 0;
|
|
24605
|
+
}
|
|
24606
|
+
const canvas = document.createElement("canvas");
|
|
24607
|
+
const context = canvas.getContext("2d");
|
|
24608
|
+
if (!context) {
|
|
24609
|
+
return void 0;
|
|
24610
|
+
}
|
|
24611
|
+
context.fillStyle = "#000000";
|
|
24612
|
+
context.fillStyle = color;
|
|
24613
|
+
const normalized = context.fillStyle;
|
|
24614
|
+
if (typeof normalized !== "string") {
|
|
24615
|
+
return void 0;
|
|
24616
|
+
}
|
|
24617
|
+
return normalizeHexLiteral(normalized) || normalizeRgbColor(normalized);
|
|
24618
|
+
}
|
|
24619
|
+
function parseRgbChannel(value) {
|
|
24620
|
+
if (value.endsWith("%")) {
|
|
24621
|
+
const percent = Number(value.slice(0, -1));
|
|
24622
|
+
if (!Number.isFinite(percent)) {
|
|
24623
|
+
return null;
|
|
24624
|
+
}
|
|
24625
|
+
return clampColorChannel(Math.round(percent / 100 * 255));
|
|
24626
|
+
}
|
|
24627
|
+
const channel = Number(value);
|
|
24628
|
+
if (!Number.isFinite(channel)) {
|
|
24629
|
+
return null;
|
|
24630
|
+
}
|
|
24631
|
+
return clampColorChannel(Math.round(channel));
|
|
24632
|
+
}
|
|
24633
|
+
function parseAlphaChannel(value) {
|
|
24634
|
+
if (value.endsWith("%")) {
|
|
24635
|
+
const percent = Number(value.slice(0, -1));
|
|
24636
|
+
if (!Number.isFinite(percent)) {
|
|
24637
|
+
return null;
|
|
24638
|
+
}
|
|
24639
|
+
return Math.min(Math.max(percent / 100, 0), 1);
|
|
24640
|
+
}
|
|
24641
|
+
const alpha = Number(value);
|
|
24642
|
+
if (!Number.isFinite(alpha)) {
|
|
24643
|
+
return null;
|
|
24644
|
+
}
|
|
24645
|
+
return Math.min(Math.max(alpha, 0), 1);
|
|
24646
|
+
}
|
|
24647
|
+
function clampColorChannel(value) {
|
|
24648
|
+
return Math.min(Math.max(value, 0), 255);
|
|
24649
|
+
}
|
|
24650
|
+
function flattenChannel(value, alpha) {
|
|
24651
|
+
return clampColorChannel(Math.round(255 * (1 - alpha) + value * alpha));
|
|
24652
|
+
}
|
|
24653
|
+
function toHexChannel(value) {
|
|
24654
|
+
return value.toString(16).padStart(2, "0").toUpperCase();
|
|
24655
|
+
}
|
|
24656
|
+
function getRegularImageType(mime) {
|
|
24657
|
+
if (mime.includes("png")) return "png";
|
|
24658
|
+
if (mime.includes("jpeg") || mime.includes("jpg")) return "jpg";
|
|
24659
|
+
if (mime.includes("gif")) return "gif";
|
|
24660
|
+
if (mime.includes("bmp")) return "bmp";
|
|
24661
|
+
return null;
|
|
24662
|
+
}
|
|
24663
|
+
function normalizeDocxFileName(fileName) {
|
|
24664
|
+
const trimmed = fileName?.trim();
|
|
24665
|
+
if (!trimmed) {
|
|
24666
|
+
return DEFAULT_DOCX_FILE_NAME;
|
|
24667
|
+
}
|
|
24668
|
+
return trimmed.toLowerCase().endsWith(".docx") ? trimmed : `${trimmed}.docx`;
|
|
24669
|
+
}
|
|
24670
|
+
|
|
24671
|
+
// src/utils/docxLayout.ts
|
|
24672
|
+
var PX_TO_TWIP = 15;
|
|
24673
|
+
var ANCHOR_EPS = 0.5;
|
|
24674
|
+
var RIGHT_SLACK_TWIP = -14400;
|
|
24675
|
+
var TINY_TWIP = 1;
|
|
24676
|
+
var tw = (ctx, layoutPx) => Math.round(layoutPx / ctx.scale * PX_TO_TWIP);
|
|
24677
|
+
var pxTw = (px) => Math.round(px * PX_TO_TWIP);
|
|
24678
|
+
async function exportDrawToDocx(draw, options = {}) {
|
|
24679
|
+
const canvas = document.createElement("canvas");
|
|
24680
|
+
const measureCtx = canvas.getContext("2d");
|
|
24681
|
+
const ctx = {
|
|
24682
|
+
draw,
|
|
24683
|
+
scale: draw.getOptions().scale,
|
|
24684
|
+
measureCtx
|
|
24685
|
+
};
|
|
24686
|
+
const file = await createDocument(ctx);
|
|
24687
|
+
const blob = await import_docx2.Packer.toBlob(file);
|
|
24688
|
+
return { blob, fileName: normalizeDocxFileName(options.fileName) };
|
|
24689
|
+
}
|
|
24690
|
+
async function createDocument(ctx) {
|
|
24691
|
+
const { draw, scale } = ctx;
|
|
24692
|
+
const opts = draw.getOptions();
|
|
24693
|
+
const width = draw.getOriginalWidth();
|
|
24694
|
+
const height = draw.getOriginalHeight();
|
|
24695
|
+
const margins = draw.getOriginalMargins();
|
|
24696
|
+
const header = draw.getHeader();
|
|
24697
|
+
const footer = draw.getFooter();
|
|
24698
|
+
const headerTop = header.getHeaderTop() / scale;
|
|
24699
|
+
const headerExtra = header.getExtraHeight() / scale;
|
|
24700
|
+
const footerExtra = footer.getExtraHeight() / scale;
|
|
24701
|
+
const layoutMargins = draw.getMargins();
|
|
24702
|
+
const body = await serializeMain(ctx, layoutMargins[3]);
|
|
24703
|
+
const headerChildren = opts.header.disabled ? [] : await serializeRows(ctx, header.getRowList(), {
|
|
24704
|
+
startX: layoutMargins[3],
|
|
24705
|
+
width: draw.getInnerWidth(),
|
|
24706
|
+
positionList: header.getPositionList()
|
|
24707
|
+
});
|
|
24708
|
+
const footerChildren = opts.footer.disabled ? [] : await serializeFooter(ctx, width, height, margins);
|
|
24709
|
+
const { pageNumber } = draw.getOptions();
|
|
24710
|
+
return new import_docx2.Document({
|
|
24711
|
+
compatabilityModeVersion: 15,
|
|
24712
|
+
// LibreOffice formats PAGE/NUMPAGES results from the paragraph style
|
|
24713
|
+
styles: {
|
|
24714
|
+
paragraphStyles: [
|
|
24715
|
+
{
|
|
24716
|
+
id: PAGE_NUMBER_STYLE,
|
|
24717
|
+
name: "Windoc Page Number",
|
|
24718
|
+
run: pageNumberRunStyle(pageNumber)
|
|
24719
|
+
}
|
|
24720
|
+
]
|
|
24496
24721
|
},
|
|
24722
|
+
defaultTabStop: pxTw(width),
|
|
24497
24723
|
sections: [
|
|
24498
24724
|
{
|
|
24499
24725
|
properties: {
|
|
24500
24726
|
page: {
|
|
24501
24727
|
size: {
|
|
24502
|
-
width:
|
|
24503
|
-
height:
|
|
24504
|
-
orientation: paperDirection === "horizontal" /* HORIZONTAL */ ?
|
|
24728
|
+
width: pxTw(width),
|
|
24729
|
+
height: pxTw(height),
|
|
24730
|
+
orientation: opts.paperDirection === "horizontal" /* HORIZONTAL */ ? import_docx2.PageOrientation.LANDSCAPE : import_docx2.PageOrientation.PORTRAIT
|
|
24505
24731
|
},
|
|
24506
24732
|
margin: {
|
|
24507
|
-
top:
|
|
24508
|
-
right:
|
|
24509
|
-
bottom:
|
|
24510
|
-
left:
|
|
24511
|
-
header:
|
|
24512
|
-
footer:
|
|
24513
|
-
|
|
24514
|
-
|
|
24515
|
-
start: editorOptions.pageNumber.startPageNo
|
|
24516
|
-
} : void 0
|
|
24733
|
+
top: pxTw(margins[0] + headerExtra),
|
|
24734
|
+
right: pxTw(margins[1]),
|
|
24735
|
+
bottom: pxTw(margins[2] + footerExtra),
|
|
24736
|
+
left: pxTw(margins[3]),
|
|
24737
|
+
header: pxTw(headerTop),
|
|
24738
|
+
footer: pxTw(footer.getFooterBottom() / scale),
|
|
24739
|
+
gutter: 0
|
|
24740
|
+
}
|
|
24517
24741
|
}
|
|
24518
24742
|
},
|
|
24519
|
-
headers: headerChildren.length
|
|
24520
|
-
|
|
24521
|
-
|
|
24522
|
-
})
|
|
24523
|
-
} : void 0,
|
|
24524
|
-
footers: footerChildren.length > 0 ? {
|
|
24525
|
-
default: new import_docx.Footer({
|
|
24526
|
-
children: footerChildren
|
|
24527
|
-
})
|
|
24528
|
-
} : void 0,
|
|
24529
|
-
children: sectionChildren.length ? sectionChildren : [new import_docx.Paragraph({})]
|
|
24743
|
+
headers: headerChildren.length ? { default: new import_docx2.Header({ children: headerChildren }) } : void 0,
|
|
24744
|
+
footers: footerChildren.length ? { default: new import_docx2.Footer({ children: footerChildren }) } : void 0,
|
|
24745
|
+
children: body.length ? body : [new import_docx2.Paragraph({})]
|
|
24530
24746
|
}
|
|
24531
24747
|
]
|
|
24532
24748
|
});
|
|
24533
24749
|
}
|
|
24534
|
-
async function
|
|
24535
|
-
const
|
|
24536
|
-
|
|
24537
|
-
|
|
24538
|
-
|
|
24539
|
-
|
|
24540
|
-
...await serializeInlineElements(inlineBuffer, options, context)
|
|
24541
|
-
);
|
|
24542
|
-
inlineBuffer = [];
|
|
24750
|
+
async function serializeMain(ctx, startX) {
|
|
24751
|
+
const { draw } = ctx;
|
|
24752
|
+
const zone = {
|
|
24753
|
+
startX,
|
|
24754
|
+
width: draw.getInnerWidth(),
|
|
24755
|
+
positionList: draw.getPosition().getOriginalMainPositionList()
|
|
24543
24756
|
};
|
|
24544
|
-
|
|
24545
|
-
|
|
24546
|
-
|
|
24547
|
-
|
|
24548
|
-
|
|
24549
|
-
|
|
24550
|
-
)
|
|
24551
|
-
|
|
24552
|
-
|
|
24553
|
-
|
|
24554
|
-
|
|
24555
|
-
|
|
24556
|
-
|
|
24557
|
-
|
|
24558
|
-
|
|
24559
|
-
|
|
24560
|
-
|
|
24561
|
-
|
|
24562
|
-
|
|
24563
|
-
|
|
24564
|
-
|
|
24565
|
-
|
|
24566
|
-
|
|
24567
|
-
|
|
24568
|
-
|
|
24569
|
-
blocks.push(await serializeTableElement(element, options, context));
|
|
24570
|
-
continue;
|
|
24571
|
-
}
|
|
24572
|
-
if (element.type === "pageBreak" /* PAGE_BREAK */) {
|
|
24573
|
-
await flushInlineBuffer();
|
|
24574
|
-
blocks.push(
|
|
24575
|
-
new import_docx.Paragraph({
|
|
24576
|
-
children: [new import_docx.PageBreak()]
|
|
24577
|
-
})
|
|
24578
|
-
);
|
|
24579
|
-
continue;
|
|
24580
|
-
}
|
|
24581
|
-
if (element.type === "separator" /* SEPARATOR */) {
|
|
24582
|
-
await flushInlineBuffer();
|
|
24583
|
-
blocks.push(
|
|
24584
|
-
new import_docx.Paragraph({
|
|
24585
|
-
thematicBreak: true
|
|
24586
|
-
})
|
|
24587
|
-
);
|
|
24588
|
-
continue;
|
|
24589
|
-
}
|
|
24590
|
-
if (element.type === "image" /* IMAGE */ && element.imgDisplay && element.imgDisplay !== "inline") {
|
|
24591
|
-
await flushInlineBuffer();
|
|
24592
|
-
blocks.push(...await serializeInlineElements([element], options));
|
|
24593
|
-
continue;
|
|
24594
|
-
}
|
|
24595
|
-
if (element.type === "block" /* BLOCK */) {
|
|
24596
|
-
await flushInlineBuffer();
|
|
24597
|
-
const blockText = getBlockFallbackText(element);
|
|
24598
|
-
if (blockText) {
|
|
24599
|
-
blocks.push(
|
|
24600
|
-
...await serializeInlineElements(
|
|
24601
|
-
[{ value: blockText }],
|
|
24602
|
-
options,
|
|
24603
|
-
context
|
|
24757
|
+
const children = [];
|
|
24758
|
+
const pageRowList = draw.getPageRowList();
|
|
24759
|
+
for (let p = 0; p < pageRowList.length; p++) {
|
|
24760
|
+
children.push(
|
|
24761
|
+
...await serializeRows(ctx, pageRowList[p], zone, {
|
|
24762
|
+
pageBreakBefore: p > 0
|
|
24763
|
+
})
|
|
24764
|
+
);
|
|
24765
|
+
}
|
|
24766
|
+
return children;
|
|
24767
|
+
}
|
|
24768
|
+
async function serializeRows(ctx, rowList, zone, options = {}) {
|
|
24769
|
+
const { pageBreakBefore = false, padTop = 0, padBottom = 0 } = options;
|
|
24770
|
+
const children = [];
|
|
24771
|
+
for (let r = 0; r < rowList.length; r++) {
|
|
24772
|
+
const row = rowList[r];
|
|
24773
|
+
const isFirst = r === 0;
|
|
24774
|
+
const isLast = r === rowList.length - 1;
|
|
24775
|
+
const table = row.elementList.find((el) => el.type === "table" /* TABLE */);
|
|
24776
|
+
if (table) {
|
|
24777
|
+
if (isFirst && (pageBreakBefore || padTop) || row.offsetY) {
|
|
24778
|
+
children.push(
|
|
24779
|
+
createSpacerParagraph(
|
|
24780
|
+
isFirst && pageBreakBefore,
|
|
24781
|
+
(isFirst ? padTop : 0) + (row.offsetY || 0) / ctx.scale
|
|
24604
24782
|
)
|
|
24605
24783
|
);
|
|
24606
24784
|
}
|
|
24785
|
+
const position = zone.positionList[row.startIndex + row.elementList.indexOf(table)];
|
|
24786
|
+
children.push(await serializeTable(ctx, table, position, zone));
|
|
24787
|
+
const rest = (row.height + (row.spaceBelow || 0)) / ctx.scale - table.height + (isLast ? padBottom : 0);
|
|
24788
|
+
if (rest * PX_TO_TWIP >= 1) {
|
|
24789
|
+
children.push(createSpacerParagraph(false, rest));
|
|
24790
|
+
}
|
|
24607
24791
|
continue;
|
|
24608
24792
|
}
|
|
24609
|
-
|
|
24793
|
+
const rowOptions = {
|
|
24794
|
+
pageBreakBefore: isFirst && pageBreakBefore,
|
|
24795
|
+
padTop: isFirst ? padTop : 0,
|
|
24796
|
+
padBottom: isLast ? padBottom : 0
|
|
24797
|
+
};
|
|
24798
|
+
if (!isFirst && isTextRow(rowList[r - 1])) rowOptions.skipLead = true;
|
|
24799
|
+
rowOptions.rowY = rowY(zone, row);
|
|
24800
|
+
if (!isLast && isTextRow(rowList[r + 1])) {
|
|
24801
|
+
rowOptions.extraAfter = rowLead(ctx, rowList[r + 1], {
|
|
24802
|
+
rowY: rowY(zone, rowList[r + 1])
|
|
24803
|
+
});
|
|
24804
|
+
}
|
|
24805
|
+
const lead = rowOptions.pageBreakBefore ? rowLead(ctx, row, rowOptions) : 0;
|
|
24806
|
+
if (lead) {
|
|
24807
|
+
children.push(createSpacerParagraph(true, lead / PX_TO_TWIP));
|
|
24808
|
+
rowOptions.pageBreakBefore = false;
|
|
24809
|
+
rowOptions.skipLead = true;
|
|
24810
|
+
}
|
|
24811
|
+
children.push(await serializeRow(ctx, row, zone, rowOptions));
|
|
24610
24812
|
}
|
|
24611
|
-
|
|
24612
|
-
return blocks;
|
|
24813
|
+
return children;
|
|
24613
24814
|
}
|
|
24614
|
-
|
|
24615
|
-
|
|
24616
|
-
|
|
24617
|
-
|
|
24618
|
-
|
|
24619
|
-
|
|
24620
|
-
|
|
24621
|
-
|
|
24622
|
-
}
|
|
24623
|
-
const
|
|
24624
|
-
|
|
24625
|
-
|
|
24626
|
-
|
|
24815
|
+
function rowY(zone, row) {
|
|
24816
|
+
return zone.positionList[row.startIndex]?.coordinate.leftTop[1];
|
|
24817
|
+
}
|
|
24818
|
+
function isTextRow(row) {
|
|
24819
|
+
return !row.elementList.some((el) => el.type === "table" /* TABLE */);
|
|
24820
|
+
}
|
|
24821
|
+
async function serializeRow(ctx, row, zone, options, suffix) {
|
|
24822
|
+
const { pageBreakBefore = false } = options;
|
|
24823
|
+
const { draw, scale } = ctx;
|
|
24824
|
+
const positions = zone.positionList;
|
|
24825
|
+
const children = [];
|
|
24826
|
+
const tabStops = [];
|
|
24827
|
+
const firstPosition = positions[row.startIndex];
|
|
24828
|
+
let pen = 0;
|
|
24829
|
+
let indent = firstPosition ? (firstPosition.coordinate.leftTop[0] - zone.startX) / scale : 0;
|
|
24830
|
+
let started = false;
|
|
24831
|
+
const anchorTo = (layoutX) => {
|
|
24832
|
+
const target = (layoutX - zone.startX) / scale;
|
|
24833
|
+
if (!started) {
|
|
24834
|
+
indent = target;
|
|
24835
|
+
pen = target;
|
|
24836
|
+
started = true;
|
|
24627
24837
|
return;
|
|
24628
24838
|
}
|
|
24629
|
-
|
|
24630
|
-
|
|
24631
|
-
|
|
24632
|
-
|
|
24633
|
-
options.defaultRowMargin
|
|
24634
|
-
)
|
|
24635
|
-
);
|
|
24636
|
-
current = null;
|
|
24637
|
-
};
|
|
24638
|
-
const ensureParagraph = (element) => {
|
|
24639
|
-
if (!current) {
|
|
24640
|
-
current = {
|
|
24641
|
-
children: [],
|
|
24642
|
-
context: getParagraphContext(element)
|
|
24643
|
-
};
|
|
24839
|
+
if (target - pen > ANCHOR_EPS) {
|
|
24840
|
+
tabStops.push(pxTw(target));
|
|
24841
|
+
children.push(new import_docx2.TextRun({ children: [new import_docx2.Tab()] }));
|
|
24842
|
+
pen = target;
|
|
24644
24843
|
}
|
|
24645
|
-
return current;
|
|
24646
24844
|
};
|
|
24647
|
-
|
|
24648
|
-
const
|
|
24649
|
-
const
|
|
24650
|
-
|
|
24651
|
-
|
|
24652
|
-
|
|
24653
|
-
|
|
24654
|
-
|
|
24655
|
-
|
|
24656
|
-
|
|
24657
|
-
|
|
24658
|
-
|
|
24659
|
-
|
|
24660
|
-
|
|
24661
|
-
|
|
24662
|
-
|
|
24663
|
-
|
|
24664
|
-
|
|
24665
|
-
|
|
24666
|
-
|
|
24667
|
-
|
|
24668
|
-
|
|
24669
|
-
|
|
24670
|
-
|
|
24671
|
-
|
|
24672
|
-
|
|
24673
|
-
|
|
24674
|
-
|
|
24675
|
-
|
|
24676
|
-
|
|
24677
|
-
|
|
24678
|
-
)
|
|
24845
|
+
if (row.isList && firstPosition) {
|
|
24846
|
+
const listParticle = draw.getListParticle();
|
|
24847
|
+
const markerX = listParticle.getListMarkerX(row, firstPosition);
|
|
24848
|
+
const marker = markerX === null ? null : listParticle.getListMarker(row);
|
|
24849
|
+
if (markerX !== null && marker) {
|
|
24850
|
+
anchorTo(markerX);
|
|
24851
|
+
children.push(createTextRun(ctx, marker.text, marker.styleElement));
|
|
24852
|
+
pen += measure(ctx, marker.text, marker.styleElement);
|
|
24853
|
+
}
|
|
24854
|
+
}
|
|
24855
|
+
let run = null;
|
|
24856
|
+
const flush = () => {
|
|
24857
|
+
if (!run) return;
|
|
24858
|
+
children.push(createTextRun(ctx, run.text, run.element));
|
|
24859
|
+
run = null;
|
|
24860
|
+
};
|
|
24861
|
+
for (let j = 0; j < row.elementList.length; j++) {
|
|
24862
|
+
const element = row.elementList[j];
|
|
24863
|
+
const position = positions[row.startIndex + j];
|
|
24864
|
+
if (!position) continue;
|
|
24865
|
+
if (element.hide || element.control?.hide || element.area?.hide) continue;
|
|
24866
|
+
if (element.type === "separator" /* SEPARATOR */) {
|
|
24867
|
+
flush();
|
|
24868
|
+
return createSeparatorParagraph(
|
|
24869
|
+
ctx,
|
|
24870
|
+
row,
|
|
24871
|
+
element,
|
|
24872
|
+
position.coordinate.leftTop[0],
|
|
24873
|
+
position.coordinate.leftTop[1],
|
|
24874
|
+
zone,
|
|
24875
|
+
options
|
|
24679
24876
|
);
|
|
24680
24877
|
}
|
|
24681
|
-
|
|
24682
|
-
for (let i = 0; i < elementList.length; i++) {
|
|
24683
|
-
const element = elementList[i];
|
|
24684
|
-
if (element.type === "hyperlink" /* HYPERLINK */ && element.valueList?.length) {
|
|
24685
|
-
const hyperlink = await createHyperlinkChild(element, options);
|
|
24686
|
-
if (hyperlink) {
|
|
24687
|
-
ensureParagraph(element).children.push(hyperlink);
|
|
24688
|
-
}
|
|
24878
|
+
if (element.value === ZERO || element.type === "tab" /* TAB */ || element.type === "pageBreak" /* PAGE_BREAK */ || element.type === "columnBreak" /* COLUMN_BREAK */) {
|
|
24689
24879
|
continue;
|
|
24690
24880
|
}
|
|
24881
|
+
const x = position.coordinate.leftTop[0];
|
|
24882
|
+
const layoutWidth = element.metrics.width / scale;
|
|
24691
24883
|
if (element.type === "image" /* IMAGE */) {
|
|
24692
|
-
|
|
24693
|
-
|
|
24694
|
-
|
|
24695
|
-
|
|
24696
|
-
|
|
24697
|
-
(segment) => createTextRun(
|
|
24698
|
-
segment,
|
|
24699
|
-
element,
|
|
24700
|
-
options.defaultSize,
|
|
24701
|
-
options.defaultFont
|
|
24702
|
-
),
|
|
24703
|
-
i === elementList.length - 1
|
|
24704
|
-
);
|
|
24705
|
-
continue;
|
|
24706
|
-
}
|
|
24707
|
-
ensureParagraph(element).children.push(imageChild);
|
|
24884
|
+
flush();
|
|
24885
|
+
anchorTo(x);
|
|
24886
|
+
const image = await createImageRun(element);
|
|
24887
|
+
if (image) children.push(image);
|
|
24888
|
+
pen += layoutWidth;
|
|
24708
24889
|
continue;
|
|
24709
24890
|
}
|
|
24710
|
-
if (element.type === "
|
|
24711
|
-
|
|
24712
|
-
|
|
24713
|
-
|
|
24714
|
-
|
|
24715
|
-
|
|
24716
|
-
element,
|
|
24717
|
-
" ",
|
|
24718
|
-
(segment) => createTextRun(
|
|
24719
|
-
segment,
|
|
24720
|
-
element,
|
|
24721
|
-
options.defaultSize,
|
|
24722
|
-
options.defaultFont
|
|
24723
|
-
),
|
|
24724
|
-
i === elementList.length - 1
|
|
24891
|
+
if (element.type === "label" /* LABEL */) {
|
|
24892
|
+
flush();
|
|
24893
|
+
const padding = element.label?.padding || draw.getOptions().label.defaultPadding;
|
|
24894
|
+
anchorTo(x + padding[3] * scale);
|
|
24895
|
+
children.push(
|
|
24896
|
+
createTextRun(ctx, element.value, element, labelShading(ctx, element))
|
|
24725
24897
|
);
|
|
24898
|
+
pen += measure(ctx, element.value, element);
|
|
24726
24899
|
continue;
|
|
24727
24900
|
}
|
|
24728
|
-
const
|
|
24729
|
-
if (!
|
|
24730
|
-
|
|
24731
|
-
|
|
24732
|
-
|
|
24733
|
-
|
|
24734
|
-
|
|
24735
|
-
|
|
24736
|
-
|
|
24737
|
-
|
|
24738
|
-
|
|
24739
|
-
|
|
24740
|
-
)
|
|
24741
|
-
|
|
24742
|
-
|
|
24743
|
-
|
|
24744
|
-
|
|
24745
|
-
|
|
24746
|
-
|
|
24747
|
-
return paragraphs.length ? paragraphs : [createParagraph([], overrides, options.defaultRowMargin)];
|
|
24748
|
-
}
|
|
24749
|
-
async function serializeListElement(element, options, context) {
|
|
24750
|
-
const zipList = zipElementList(element.valueList || []);
|
|
24751
|
-
const listItemMap = splitListElement(zipList);
|
|
24752
|
-
const paragraphs = [];
|
|
24753
|
-
const listInstance = createListInstance(context);
|
|
24754
|
-
for (const listItemElements of listItemMap.values()) {
|
|
24755
|
-
const numbering = getListNumbering(
|
|
24756
|
-
getListItemNumberingElement(listItemElements, element),
|
|
24757
|
-
listInstance
|
|
24758
|
-
);
|
|
24759
|
-
paragraphs.push(
|
|
24760
|
-
...await serializeInlineElements(listItemElements, options, context, {
|
|
24761
|
-
numbering
|
|
24762
|
-
})
|
|
24763
|
-
);
|
|
24764
|
-
}
|
|
24765
|
-
return paragraphs;
|
|
24766
|
-
}
|
|
24767
|
-
async function serializeTableElement(element, options, context) {
|
|
24768
|
-
const rows = [];
|
|
24769
|
-
const trList = element.trList || [];
|
|
24770
|
-
const tableContext = createTableSerializeContext(element);
|
|
24771
|
-
for (let i = 0; i < trList.length; i++) {
|
|
24772
|
-
rows.push(
|
|
24773
|
-
await serializeTableRow(trList[i], options, context, tableContext)
|
|
24774
|
-
);
|
|
24775
|
-
}
|
|
24776
|
-
const tableWidth = getTableWidthFromColgroup(element.colgroup);
|
|
24777
|
-
return new import_docx.Table({
|
|
24778
|
-
rows,
|
|
24779
|
-
width: tableWidth ? {
|
|
24780
|
-
size: pxToTwips(tableWidth),
|
|
24781
|
-
type: import_docx.WidthType.DXA
|
|
24782
|
-
} : {
|
|
24783
|
-
size: 100,
|
|
24784
|
-
type: import_docx.WidthType.PERCENTAGE
|
|
24785
|
-
},
|
|
24786
|
-
columnWidths: element.colgroup?.map((col) => pxToTwips(col.width)),
|
|
24787
|
-
layout: import_docx.TableLayoutType.FIXED,
|
|
24788
|
-
borders: createTableBorders(element)
|
|
24789
|
-
});
|
|
24790
|
-
}
|
|
24791
|
-
async function serializeTableRow(tr, options, context, tableContext) {
|
|
24792
|
-
const children = [];
|
|
24793
|
-
for (let i = 0; i < tr.tdList.length; i++) {
|
|
24794
|
-
children.push(
|
|
24795
|
-
await serializeTableCell(tr.tdList[i], options, context, tableContext)
|
|
24796
|
-
);
|
|
24797
|
-
}
|
|
24798
|
-
return new import_docx.TableRow({
|
|
24799
|
-
children
|
|
24800
|
-
});
|
|
24801
|
-
}
|
|
24802
|
-
async function serializeTableCell(td, options, context, tableContext) {
|
|
24803
|
-
const children = await serializeElementList(td.value, options, context);
|
|
24804
|
-
const shadingFill = td.backgroundColor ? normalizeHexColor(td.backgroundColor) : void 0;
|
|
24805
|
-
const cellWidth = tableContext.cellLayoutMap.get(td)?.width || td.width;
|
|
24806
|
-
return new import_docx.TableCell({
|
|
24807
|
-
children: children.length ? children : [new import_docx.Paragraph({})],
|
|
24808
|
-
columnSpan: td.colspan > 1 ? td.colspan : void 0,
|
|
24809
|
-
rowSpan: td.rowspan > 1 ? td.rowspan : void 0,
|
|
24810
|
-
verticalAlign: mapCellVerticalAlign(td.verticalAlign),
|
|
24811
|
-
width: cellWidth ? {
|
|
24812
|
-
size: pxToTwips(cellWidth),
|
|
24813
|
-
type: import_docx.WidthType.DXA
|
|
24814
|
-
} : void 0,
|
|
24815
|
-
shading: shadingFill ? {
|
|
24816
|
-
fill: shadingFill,
|
|
24817
|
-
type: import_docx.ShadingType.CLEAR
|
|
24818
|
-
} : void 0,
|
|
24819
|
-
margins: mapPaddingToTableMargins(td.padding),
|
|
24820
|
-
borders: createTableCellBorders(
|
|
24821
|
-
td,
|
|
24822
|
-
tableContext.borderColor,
|
|
24823
|
-
tableContext.borderWidth
|
|
24824
|
-
)
|
|
24825
|
-
});
|
|
24826
|
-
}
|
|
24827
|
-
function createParagraph(children, context, defaultRowMargin) {
|
|
24828
|
-
return new import_docx.Paragraph({
|
|
24829
|
-
children,
|
|
24830
|
-
heading: context.heading,
|
|
24831
|
-
numbering: context.numbering,
|
|
24832
|
-
alignment: context.alignment,
|
|
24833
|
-
spacing: {
|
|
24834
|
-
line: Math.round(
|
|
24835
|
-
240 * (context.rowMargin || defaultRowMargin || DEFAULT_LINE_HEIGHT)
|
|
24836
|
-
),
|
|
24837
|
-
lineRule: import_docx.LineRuleType.AUTO
|
|
24838
|
-
}
|
|
24839
|
-
});
|
|
24840
|
-
}
|
|
24841
|
-
function createTextRun(text, element, defaultSize, defaultFont) {
|
|
24842
|
-
const color = element.color ? normalizeHexColor(element.color, "000000") : void 0;
|
|
24843
|
-
const highlightFill = element.highlight ? normalizeHexColor(element.highlight) : void 0;
|
|
24844
|
-
return new import_docx.TextRun({
|
|
24845
|
-
text,
|
|
24846
|
-
bold: !!element.bold,
|
|
24847
|
-
italics: !!element.italic,
|
|
24848
|
-
strike: !!element.strikeout,
|
|
24849
|
-
subScript: element.type === "subscript" /* SUBSCRIPT */,
|
|
24850
|
-
superScript: element.type === "superscript" /* SUPERSCRIPT */,
|
|
24851
|
-
color,
|
|
24852
|
-
shading: highlightFill ? {
|
|
24853
|
-
fill: highlightFill,
|
|
24854
|
-
type: import_docx.ShadingType.CLEAR
|
|
24855
|
-
} : void 0,
|
|
24856
|
-
underline: element.underline ? {
|
|
24857
|
-
type: mapUnderlineType(element.textDecoration?.style)
|
|
24858
|
-
} : void 0,
|
|
24859
|
-
font: element.font || defaultFont,
|
|
24860
|
-
size: Math.round((element.size || defaultSize) * 2)
|
|
24861
|
-
});
|
|
24862
|
-
}
|
|
24863
|
-
async function createHyperlinkChild(element, options) {
|
|
24864
|
-
if (!element.url) {
|
|
24865
|
-
const fallbackText = getTextFromElementList(element.valueList || []);
|
|
24866
|
-
return fallbackText ? createTextRun(
|
|
24867
|
-
fallbackText,
|
|
24868
|
-
element.valueList?.[0] || element,
|
|
24869
|
-
options.defaultSize,
|
|
24870
|
-
options.defaultFont
|
|
24871
|
-
) : null;
|
|
24872
|
-
}
|
|
24873
|
-
const children = await createHyperlinkRuns(
|
|
24874
|
-
element.valueList || [],
|
|
24875
|
-
options.defaultSize,
|
|
24876
|
-
options.defaultFont
|
|
24877
|
-
);
|
|
24878
|
-
if (!children.length) {
|
|
24879
|
-
return null;
|
|
24880
|
-
}
|
|
24881
|
-
return new import_docx.ExternalHyperlink({
|
|
24882
|
-
link: element.url,
|
|
24883
|
-
children
|
|
24884
|
-
});
|
|
24885
|
-
}
|
|
24886
|
-
async function createHyperlinkRuns(valueList, defaultSize, defaultFont) {
|
|
24887
|
-
const children = [];
|
|
24888
|
-
for (let i = 0; i < valueList.length; i++) {
|
|
24889
|
-
const element = valueList[i];
|
|
24890
|
-
if (element.type === "tab" /* TAB */) {
|
|
24891
|
-
children.push(createTextRun(" ", element, defaultSize, defaultFont));
|
|
24892
|
-
continue;
|
|
24893
|
-
}
|
|
24894
|
-
const text = normalizeText(getInlineElementText(element)).replace(
|
|
24895
|
-
/\n/g,
|
|
24896
|
-
" "
|
|
24897
|
-
);
|
|
24898
|
-
if (text) {
|
|
24899
|
-
children.push(createTextRun(text, element, defaultSize, defaultFont));
|
|
24900
|
-
}
|
|
24901
|
-
}
|
|
24902
|
-
return children;
|
|
24903
|
-
}
|
|
24904
|
-
async function createImageChild(element) {
|
|
24905
|
-
try {
|
|
24906
|
-
const image = await loadImagePayload(element.value);
|
|
24907
|
-
const width = Math.max(1, Math.round(element.width || DEFAULT_IMAGE_WIDTH));
|
|
24908
|
-
const height = Math.max(
|
|
24909
|
-
1,
|
|
24910
|
-
Math.round(element.height || DEFAULT_IMAGE_HEIGHT)
|
|
24911
|
-
);
|
|
24912
|
-
if (image.type === "svg" && image.fallbackPng) {
|
|
24913
|
-
return new import_docx.ImageRun({
|
|
24914
|
-
type: "svg",
|
|
24915
|
-
data: image.data,
|
|
24916
|
-
fallback: {
|
|
24917
|
-
type: "png",
|
|
24918
|
-
data: image.fallbackPng
|
|
24919
|
-
},
|
|
24920
|
-
transformation: {
|
|
24921
|
-
width,
|
|
24922
|
-
height
|
|
24923
|
-
}
|
|
24924
|
-
});
|
|
24925
|
-
}
|
|
24926
|
-
return new import_docx.ImageRun({
|
|
24927
|
-
type: image.type,
|
|
24928
|
-
data: image.data,
|
|
24929
|
-
transformation: {
|
|
24930
|
-
width,
|
|
24931
|
-
height
|
|
24901
|
+
const text = getElementText(element);
|
|
24902
|
+
if (!text) continue;
|
|
24903
|
+
const natural = measure(ctx, text, element);
|
|
24904
|
+
const target = (x - zone.startX) / scale;
|
|
24905
|
+
const isDrift = !started || target - pen > ANCHOR_EPS;
|
|
24906
|
+
const extra = layoutWidth - natural;
|
|
24907
|
+
const needsSpacing = Math.abs(extra) * PX_TO_TWIP >= 1;
|
|
24908
|
+
const canJoin = run && !isDrift && !needsSpacing && isSameRunStyle(run.element, element);
|
|
24909
|
+
if (canJoin) {
|
|
24910
|
+
run.text += text;
|
|
24911
|
+
} else {
|
|
24912
|
+
flush();
|
|
24913
|
+
anchorTo(x);
|
|
24914
|
+
if (needsSpacing) {
|
|
24915
|
+
children.push(
|
|
24916
|
+
createTextRun(ctx, text, element, void 0, pxTw(extra))
|
|
24917
|
+
);
|
|
24918
|
+
} else {
|
|
24919
|
+
run = { text, element };
|
|
24932
24920
|
}
|
|
24933
|
-
});
|
|
24934
|
-
} catch {
|
|
24935
|
-
return null;
|
|
24936
|
-
}
|
|
24937
|
-
}
|
|
24938
|
-
async function loadImagePayload(src) {
|
|
24939
|
-
const source = src.trim();
|
|
24940
|
-
if (source.startsWith("data:")) {
|
|
24941
|
-
return getImagePayloadFromDataUrl(source);
|
|
24942
|
-
}
|
|
24943
|
-
const response = await fetch(source);
|
|
24944
|
-
if (!response.ok) {
|
|
24945
|
-
throw new Error(`Image request failed: ${response.status}`);
|
|
24946
|
-
}
|
|
24947
|
-
const contentType = response.headers.get("content-type") || "";
|
|
24948
|
-
const data2 = await response.arrayBuffer();
|
|
24949
|
-
return normalizeImagePayload(data2, contentType);
|
|
24950
|
-
}
|
|
24951
|
-
async function getImagePayloadFromDataUrl(src) {
|
|
24952
|
-
const [, meta = "", encoded = ""] = src.match(/^data:([^,]*),(.*)$/) || [];
|
|
24953
|
-
const mime = meta.split(";")[0] || "";
|
|
24954
|
-
const isBase64 = meta.includes(";base64");
|
|
24955
|
-
const text = isBase64 ? atob(encoded) : decodeURIComponent(encoded);
|
|
24956
|
-
const bytes = new Uint8Array(text.length);
|
|
24957
|
-
for (let i = 0; i < text.length; i++) {
|
|
24958
|
-
bytes[i] = text.charCodeAt(i);
|
|
24959
|
-
}
|
|
24960
|
-
return normalizeImagePayload(bytes.buffer, mime);
|
|
24961
|
-
}
|
|
24962
|
-
async function normalizeImagePayload(data2, mime) {
|
|
24963
|
-
const type = getRegularImageType(mime);
|
|
24964
|
-
if (type) {
|
|
24965
|
-
return {
|
|
24966
|
-
type,
|
|
24967
|
-
data: data2
|
|
24968
|
-
};
|
|
24969
|
-
}
|
|
24970
|
-
if (mime.includes("svg")) {
|
|
24971
|
-
return {
|
|
24972
|
-
type: "svg",
|
|
24973
|
-
data: data2,
|
|
24974
|
-
fallbackPng: await rasterizeSvgToPng(data2)
|
|
24975
|
-
};
|
|
24976
|
-
}
|
|
24977
|
-
const fallbackPng = await rasterizeImageToPng(data2, mime);
|
|
24978
|
-
return {
|
|
24979
|
-
type: "png",
|
|
24980
|
-
data: fallbackPng
|
|
24981
|
-
};
|
|
24982
|
-
}
|
|
24983
|
-
async function rasterizeSvgToPng(data2) {
|
|
24984
|
-
return rasterizeImageToPng(data2, "image/svg+xml");
|
|
24985
|
-
}
|
|
24986
|
-
async function rasterizeImageToPng(data2, mime) {
|
|
24987
|
-
const blob = new Blob([data2], {
|
|
24988
|
-
type: mime || "image/png"
|
|
24989
|
-
});
|
|
24990
|
-
const url = URL.createObjectURL(blob);
|
|
24991
|
-
try {
|
|
24992
|
-
const image = await loadHtmlImage(url);
|
|
24993
|
-
const canvas = document.createElement("canvas");
|
|
24994
|
-
canvas.width = image.naturalWidth || DEFAULT_IMAGE_WIDTH;
|
|
24995
|
-
canvas.height = image.naturalHeight || DEFAULT_IMAGE_HEIGHT;
|
|
24996
|
-
const context = canvas.getContext("2d");
|
|
24997
|
-
if (!context) {
|
|
24998
|
-
throw new Error("Canvas context is unavailable");
|
|
24999
24921
|
}
|
|
25000
|
-
|
|
25001
|
-
const pngBlob = await new Promise((resolve, reject) => {
|
|
25002
|
-
canvas.toBlob((output) => {
|
|
25003
|
-
if (output) {
|
|
25004
|
-
resolve(output);
|
|
25005
|
-
} else {
|
|
25006
|
-
reject(new Error("Failed to create PNG blob"));
|
|
25007
|
-
}
|
|
25008
|
-
}, "image/png");
|
|
25009
|
-
});
|
|
25010
|
-
return await pngBlob.arrayBuffer();
|
|
25011
|
-
} finally {
|
|
25012
|
-
URL.revokeObjectURL(url);
|
|
25013
|
-
}
|
|
25014
|
-
}
|
|
25015
|
-
function loadHtmlImage(src) {
|
|
25016
|
-
return new Promise((resolve, reject) => {
|
|
25017
|
-
const image = new Image();
|
|
25018
|
-
image.onload = () => resolve(image);
|
|
25019
|
-
image.onerror = () => reject(new Error("Failed to load image"));
|
|
25020
|
-
image.src = src;
|
|
25021
|
-
});
|
|
25022
|
-
}
|
|
25023
|
-
function createPageNumberParagraph(pageNumber) {
|
|
25024
|
-
if (pageNumber.disabled || pageNumber.fromPageNo > 0) {
|
|
25025
|
-
return null;
|
|
25026
|
-
}
|
|
25027
|
-
const children = [];
|
|
25028
|
-
const format = pageNumber.format || FORMAT_PLACEHOLDER.PAGE_NO;
|
|
25029
|
-
const tokens = format.split(/(\{pageNo\}|\{pageCount\})/);
|
|
25030
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
25031
|
-
const token = tokens[i];
|
|
25032
|
-
if (!token) continue;
|
|
25033
|
-
const runChildren = token === FORMAT_PLACEHOLDER.PAGE_NO ? [import_docx.PageNumber.CURRENT] : token === FORMAT_PLACEHOLDER.PAGE_COUNT ? [import_docx.PageNumber.TOTAL_PAGES] : void 0;
|
|
25034
|
-
children.push(
|
|
25035
|
-
new import_docx.TextRun({
|
|
25036
|
-
text: runChildren ? void 0 : token,
|
|
25037
|
-
children: runChildren,
|
|
25038
|
-
color: normalizeHexColor(pageNumber.color || "#000000", "000000"),
|
|
25039
|
-
font: pageNumber.font,
|
|
25040
|
-
size: Math.round((pageNumber.size || 12) * 2)
|
|
25041
|
-
})
|
|
25042
|
-
);
|
|
25043
|
-
}
|
|
25044
|
-
return new import_docx.Paragraph({
|
|
25045
|
-
children,
|
|
25046
|
-
alignment: mapRowFlexToAlignment(pageNumber.rowFlex)
|
|
25047
|
-
});
|
|
25048
|
-
}
|
|
25049
|
-
function createNumberingConfig() {
|
|
25050
|
-
const config = [
|
|
25051
|
-
createOrderedReference("windoc-ol-decimal", Array(9).fill("decimal" /* DECIMAL */)),
|
|
25052
|
-
createOrderedReference(
|
|
25053
|
-
"windoc-ol-lower-alpha",
|
|
25054
|
-
Array(9).fill("lowerAlpha" /* LOWER_ALPHA */)
|
|
25055
|
-
),
|
|
25056
|
-
createOrderedReference(
|
|
25057
|
-
"windoc-ol-upper-alpha",
|
|
25058
|
-
Array(9).fill("upperAlpha" /* UPPER_ALPHA */)
|
|
25059
|
-
),
|
|
25060
|
-
createOrderedReference(
|
|
25061
|
-
"windoc-ol-lower-roman",
|
|
25062
|
-
Array(9).fill("lowerRoman" /* LOWER_ROMAN */)
|
|
25063
|
-
),
|
|
25064
|
-
createOrderedReference(
|
|
25065
|
-
"windoc-ol-upper-roman",
|
|
25066
|
-
Array(9).fill("upperRoman" /* UPPER_ROMAN */)
|
|
25067
|
-
),
|
|
25068
|
-
createOrderedReference(
|
|
25069
|
-
"windoc-ol-decimal-paren",
|
|
25070
|
-
Array(9).fill("decimalParen" /* DECIMAL_PAREN */)
|
|
25071
|
-
),
|
|
25072
|
-
createOrderedReference(
|
|
25073
|
-
`windoc-ol-${"olDefault" /* DEFAULT */}`,
|
|
25074
|
-
createCycleList(olPresetCycles["olDefault" /* DEFAULT */], 9)
|
|
25075
|
-
),
|
|
25076
|
-
createOrderedReference(
|
|
25077
|
-
`windoc-ol-${"olParen" /* PARENTHESIS */}`,
|
|
25078
|
-
createCycleList(olPresetCycles["olParen" /* PARENTHESIS */], 9)
|
|
25079
|
-
),
|
|
25080
|
-
createOrderedReference(
|
|
25081
|
-
`windoc-ol-${"olOutline" /* OUTLINE */}`,
|
|
25082
|
-
createCycleList(olPresetCycles["olOutline" /* OUTLINE */], 9)
|
|
25083
|
-
),
|
|
25084
|
-
createOrderedReference(
|
|
25085
|
-
`windoc-ol-${"olUpperA" /* UPPER_ALPHA */}`,
|
|
25086
|
-
createCycleList(olPresetCycles["olUpperA" /* UPPER_ALPHA */], 9)
|
|
25087
|
-
),
|
|
25088
|
-
createOrderedReference(
|
|
25089
|
-
`windoc-ol-${"olRoman" /* ROMAN */}`,
|
|
25090
|
-
createCycleList(olPresetCycles["olRoman" /* ROMAN */], 9)
|
|
25091
|
-
),
|
|
25092
|
-
createOrderedReference(
|
|
25093
|
-
`windoc-ol-${"olZeroPad" /* ZERO_PAD */}`,
|
|
25094
|
-
createCycleList(olPresetCycles["olZeroPad" /* ZERO_PAD */], 9)
|
|
25095
|
-
),
|
|
25096
|
-
createBulletReference(
|
|
25097
|
-
"windoc-ul-disc",
|
|
25098
|
-
Array(9).fill(docxBulletCharMap["disc" /* DISC */])
|
|
25099
|
-
),
|
|
25100
|
-
createBulletReference(
|
|
25101
|
-
"windoc-ul-circle",
|
|
25102
|
-
Array(9).fill(docxBulletCharMap["circle" /* CIRCLE */])
|
|
25103
|
-
),
|
|
25104
|
-
createBulletReference(
|
|
25105
|
-
"windoc-ul-square",
|
|
25106
|
-
Array(9).fill(docxBulletCharMap["square" /* SQUARE */])
|
|
25107
|
-
),
|
|
25108
|
-
createBulletReference(
|
|
25109
|
-
"windoc-ul-checkbox",
|
|
25110
|
-
Array(9).fill(docxBulletCharMap["checkbox" /* CHECKBOX */])
|
|
25111
|
-
),
|
|
25112
|
-
createBulletReference(
|
|
25113
|
-
`windoc-ul-${"ulDefault" /* DEFAULT */}`,
|
|
25114
|
-
createCycleList(ulPresetCycles["ulDefault" /* DEFAULT */], 9)
|
|
25115
|
-
),
|
|
25116
|
-
createBulletReference(
|
|
25117
|
-
`windoc-ul-${"ulDiamond" /* DIAMOND */}`,
|
|
25118
|
-
createCycleList(ulPresetCycles["ulDiamond" /* DIAMOND */], 9)
|
|
25119
|
-
),
|
|
25120
|
-
createBulletReference(
|
|
25121
|
-
`windoc-ul-${"ulHollowSq" /* HOLLOW_SQ */}`,
|
|
25122
|
-
createCycleList(ulPresetCycles["ulHollowSq" /* HOLLOW_SQ */], 9)
|
|
25123
|
-
),
|
|
25124
|
-
createBulletReference(
|
|
25125
|
-
`windoc-ul-${"ulArrow" /* ARROW */}`,
|
|
25126
|
-
createCycleList(ulPresetCycles["ulArrow" /* ARROW */], 9)
|
|
25127
|
-
),
|
|
25128
|
-
createBulletReference(
|
|
25129
|
-
`windoc-ul-${"ulStar" /* STAR */}`,
|
|
25130
|
-
createCycleList(ulPresetCycles["ulStar" /* STAR */], 9)
|
|
25131
|
-
),
|
|
25132
|
-
createBulletReference(
|
|
25133
|
-
`windoc-ul-${"ulCheckArr" /* CHECK_ARROW */}`,
|
|
25134
|
-
createCycleList(ulPresetCycles["ulCheckArr" /* CHECK_ARROW */], 9)
|
|
25135
|
-
)
|
|
25136
|
-
];
|
|
25137
|
-
return config;
|
|
25138
|
-
}
|
|
25139
|
-
function createOrderedReference(reference, styles) {
|
|
25140
|
-
return {
|
|
25141
|
-
reference,
|
|
25142
|
-
levels: styles.map((style, level) => ({
|
|
25143
|
-
level,
|
|
25144
|
-
format: orderedStyleFormatMap[style] || import_docx.LevelFormat.DECIMAL,
|
|
25145
|
-
text: getOrderedLevelText(style, level),
|
|
25146
|
-
alignment: import_docx.AlignmentType.START,
|
|
25147
|
-
style: {
|
|
25148
|
-
paragraph: {
|
|
25149
|
-
indent: {
|
|
25150
|
-
left: 720 * (level + 1),
|
|
25151
|
-
hanging: 360
|
|
25152
|
-
}
|
|
25153
|
-
}
|
|
25154
|
-
}
|
|
25155
|
-
}))
|
|
25156
|
-
};
|
|
25157
|
-
}
|
|
25158
|
-
function createBulletReference(reference, bullets) {
|
|
25159
|
-
return {
|
|
25160
|
-
reference,
|
|
25161
|
-
levels: bullets.map((bullet, level) => ({
|
|
25162
|
-
level,
|
|
25163
|
-
format: import_docx.LevelFormat.BULLET,
|
|
25164
|
-
text: bullet,
|
|
25165
|
-
alignment: import_docx.AlignmentType.START,
|
|
25166
|
-
style: {
|
|
25167
|
-
paragraph: {
|
|
25168
|
-
indent: {
|
|
25169
|
-
left: 720 * (level + 1),
|
|
25170
|
-
hanging: 360
|
|
25171
|
-
}
|
|
25172
|
-
}
|
|
25173
|
-
}
|
|
25174
|
-
}))
|
|
25175
|
-
};
|
|
25176
|
-
}
|
|
25177
|
-
function getOrderedLevelText(style, level) {
|
|
25178
|
-
const placeholder = `%${level + 1}`;
|
|
25179
|
-
if (style === "outline") {
|
|
25180
|
-
return Array.from({ length: level + 1 }, (_, index) => `%${index + 1}`).join(
|
|
25181
|
-
"."
|
|
25182
|
-
) + ".";
|
|
25183
|
-
}
|
|
25184
|
-
if (style.endsWith("Paren") || style === "decimalParen" /* DECIMAL_PAREN */) {
|
|
25185
|
-
return `${placeholder})`;
|
|
25186
|
-
}
|
|
25187
|
-
return `${placeholder}.`;
|
|
25188
|
-
}
|
|
25189
|
-
function createCycleList(source = [], size) {
|
|
25190
|
-
const result = [];
|
|
25191
|
-
for (let i = 0; i < size; i++) {
|
|
25192
|
-
result.push(source[i % source.length]);
|
|
25193
|
-
}
|
|
25194
|
-
return result;
|
|
25195
|
-
}
|
|
25196
|
-
function getListNumbering(element, instance) {
|
|
25197
|
-
const level = Math.max(0, Math.min(element.listLevel || 0, 8));
|
|
25198
|
-
if (element.listType === "ul" /* UL */) {
|
|
25199
|
-
const reference2 = element.listPreset ? `windoc-ul-${element.listPreset}` : `windoc-ul-${element.listStyle || "disc" /* DISC */}`;
|
|
25200
|
-
return {
|
|
25201
|
-
reference: reference2,
|
|
25202
|
-
level,
|
|
25203
|
-
instance
|
|
25204
|
-
};
|
|
25205
|
-
}
|
|
25206
|
-
const reference = element.listPreset ? `windoc-ol-${element.listPreset}` : getOrderedReferenceFromStyle(element.listStyle);
|
|
25207
|
-
return {
|
|
25208
|
-
reference,
|
|
25209
|
-
level,
|
|
25210
|
-
instance
|
|
25211
|
-
};
|
|
25212
|
-
}
|
|
25213
|
-
function getOrderedReferenceFromStyle(style) {
|
|
25214
|
-
switch (style) {
|
|
25215
|
-
case "lowerAlpha" /* LOWER_ALPHA */:
|
|
25216
|
-
return "windoc-ol-lower-alpha";
|
|
25217
|
-
case "upperAlpha" /* UPPER_ALPHA */:
|
|
25218
|
-
return "windoc-ol-upper-alpha";
|
|
25219
|
-
case "lowerRoman" /* LOWER_ROMAN */:
|
|
25220
|
-
return "windoc-ol-lower-roman";
|
|
25221
|
-
case "upperRoman" /* UPPER_ROMAN */:
|
|
25222
|
-
return "windoc-ol-upper-roman";
|
|
25223
|
-
case "decimalParen" /* DECIMAL_PAREN */:
|
|
25224
|
-
return "windoc-ol-decimal-paren";
|
|
25225
|
-
default:
|
|
25226
|
-
return "windoc-ol-decimal";
|
|
25227
|
-
}
|
|
25228
|
-
}
|
|
25229
|
-
function createTableBorders(element) {
|
|
25230
|
-
const outerBorder = createBorder(
|
|
25231
|
-
element.borderColor,
|
|
25232
|
-
import_docx.BorderStyle.SINGLE,
|
|
25233
|
-
element.borderExternalWidth || element.borderWidth
|
|
25234
|
-
);
|
|
25235
|
-
const innerBorder = createBorder(
|
|
25236
|
-
element.borderColor,
|
|
25237
|
-
import_docx.BorderStyle.SINGLE,
|
|
25238
|
-
element.borderWidth
|
|
25239
|
-
);
|
|
25240
|
-
switch (element.borderType) {
|
|
25241
|
-
case "empty" /* EMPTY */:
|
|
25242
|
-
return {
|
|
25243
|
-
top: noneBorder(),
|
|
25244
|
-
bottom: noneBorder(),
|
|
25245
|
-
left: noneBorder(),
|
|
25246
|
-
right: noneBorder(),
|
|
25247
|
-
insideHorizontal: noneBorder(),
|
|
25248
|
-
insideVertical: noneBorder()
|
|
25249
|
-
};
|
|
25250
|
-
case "external" /* EXTERNAL */:
|
|
25251
|
-
return {
|
|
25252
|
-
top: outerBorder,
|
|
25253
|
-
bottom: outerBorder,
|
|
25254
|
-
left: outerBorder,
|
|
25255
|
-
right: outerBorder,
|
|
25256
|
-
insideHorizontal: noneBorder(),
|
|
25257
|
-
insideVertical: noneBorder()
|
|
25258
|
-
};
|
|
25259
|
-
case "internal" /* INTERNAL */:
|
|
25260
|
-
return {
|
|
25261
|
-
top: noneBorder(),
|
|
25262
|
-
bottom: noneBorder(),
|
|
25263
|
-
left: noneBorder(),
|
|
25264
|
-
right: noneBorder(),
|
|
25265
|
-
insideHorizontal: innerBorder,
|
|
25266
|
-
insideVertical: innerBorder
|
|
25267
|
-
};
|
|
25268
|
-
case "dash" /* DASH */:
|
|
25269
|
-
return {
|
|
25270
|
-
top: createBorder(
|
|
25271
|
-
element.borderColor,
|
|
25272
|
-
import_docx.BorderStyle.DASHED,
|
|
25273
|
-
element.borderExternalWidth || element.borderWidth
|
|
25274
|
-
),
|
|
25275
|
-
bottom: createBorder(
|
|
25276
|
-
element.borderColor,
|
|
25277
|
-
import_docx.BorderStyle.DASHED,
|
|
25278
|
-
element.borderExternalWidth || element.borderWidth
|
|
25279
|
-
),
|
|
25280
|
-
left: createBorder(
|
|
25281
|
-
element.borderColor,
|
|
25282
|
-
import_docx.BorderStyle.DASHED,
|
|
25283
|
-
element.borderExternalWidth || element.borderWidth
|
|
25284
|
-
),
|
|
25285
|
-
right: createBorder(
|
|
25286
|
-
element.borderColor,
|
|
25287
|
-
import_docx.BorderStyle.DASHED,
|
|
25288
|
-
element.borderExternalWidth || element.borderWidth
|
|
25289
|
-
),
|
|
25290
|
-
insideHorizontal: createBorder(
|
|
25291
|
-
element.borderColor,
|
|
25292
|
-
import_docx.BorderStyle.DASHED,
|
|
25293
|
-
element.borderWidth
|
|
25294
|
-
),
|
|
25295
|
-
insideVertical: createBorder(
|
|
25296
|
-
element.borderColor,
|
|
25297
|
-
import_docx.BorderStyle.DASHED,
|
|
25298
|
-
element.borderWidth
|
|
25299
|
-
)
|
|
25300
|
-
};
|
|
25301
|
-
default:
|
|
25302
|
-
return {
|
|
25303
|
-
top: outerBorder,
|
|
25304
|
-
bottom: outerBorder,
|
|
25305
|
-
left: outerBorder,
|
|
25306
|
-
right: outerBorder,
|
|
25307
|
-
insideHorizontal: innerBorder,
|
|
25308
|
-
insideVertical: innerBorder
|
|
25309
|
-
};
|
|
25310
|
-
}
|
|
25311
|
-
}
|
|
25312
|
-
function createTableCellBorders(td, inheritedColor, inheritedWidth) {
|
|
25313
|
-
if (!td.borderTypes?.length && !td.borderColor) {
|
|
25314
|
-
return void 0;
|
|
25315
|
-
}
|
|
25316
|
-
const color = td.borderColor || inheritedColor;
|
|
25317
|
-
const createCellBorder = () => createBorder(color, import_docx.BorderStyle.SINGLE, inheritedWidth);
|
|
25318
|
-
if (td.borderColor && !td.borderTypes?.length) {
|
|
25319
|
-
return {
|
|
25320
|
-
top: createCellBorder(),
|
|
25321
|
-
right: createCellBorder(),
|
|
25322
|
-
bottom: createCellBorder(),
|
|
25323
|
-
left: createCellBorder()
|
|
25324
|
-
};
|
|
25325
|
-
}
|
|
25326
|
-
const top = td.borderTypes?.includes("top" /* TOP */) ? createCellBorder() : noneBorder();
|
|
25327
|
-
const right2 = td.borderTypes?.includes("right" /* RIGHT */) ? createCellBorder() : noneBorder();
|
|
25328
|
-
const bottom = td.borderTypes?.includes("bottom" /* BOTTOM */) ? createCellBorder() : noneBorder();
|
|
25329
|
-
const left2 = td.borderTypes?.includes("left" /* LEFT */) ? createCellBorder() : noneBorder();
|
|
25330
|
-
return {
|
|
25331
|
-
top,
|
|
25332
|
-
right: right2,
|
|
25333
|
-
bottom,
|
|
25334
|
-
left: left2
|
|
25335
|
-
};
|
|
25336
|
-
}
|
|
25337
|
-
function createBorder(color = "#000000", style = import_docx.BorderStyle.SINGLE, width = 1) {
|
|
25338
|
-
return {
|
|
25339
|
-
style,
|
|
25340
|
-
color: normalizeHexColor(color, "000000") || "000000",
|
|
25341
|
-
size: pxBorderToDocxSize(width)
|
|
25342
|
-
};
|
|
25343
|
-
}
|
|
25344
|
-
function noneBorder() {
|
|
25345
|
-
return {
|
|
25346
|
-
style: import_docx.BorderStyle.NONE,
|
|
25347
|
-
size: 0,
|
|
25348
|
-
color: "FFFFFF"
|
|
25349
|
-
};
|
|
25350
|
-
}
|
|
25351
|
-
function mapPaddingToTableMargins(padding) {
|
|
25352
|
-
if (!padding) return void 0;
|
|
25353
|
-
return {
|
|
25354
|
-
top: pxToTwips(padding[0]),
|
|
25355
|
-
right: pxToTwips(padding[1]),
|
|
25356
|
-
bottom: pxToTwips(padding[2]),
|
|
25357
|
-
left: pxToTwips(padding[3]),
|
|
25358
|
-
marginUnitType: import_docx.WidthType.DXA
|
|
25359
|
-
};
|
|
25360
|
-
}
|
|
25361
|
-
function mapCellVerticalAlign(verticalAlign) {
|
|
25362
|
-
switch (verticalAlign) {
|
|
25363
|
-
case VerticalAlign.CENTER:
|
|
25364
|
-
return import_docx.VerticalAlign.CENTER;
|
|
25365
|
-
case "bottom" /* BOTTOM */:
|
|
25366
|
-
return import_docx.VerticalAlign.BOTTOM;
|
|
25367
|
-
default:
|
|
25368
|
-
return import_docx.VerticalAlign.TOP;
|
|
25369
|
-
}
|
|
25370
|
-
}
|
|
25371
|
-
function mapRowFlexToAlignment(rowFlex) {
|
|
25372
|
-
switch (rowFlex) {
|
|
25373
|
-
case "center" /* CENTER */:
|
|
25374
|
-
return import_docx.AlignmentType.CENTER;
|
|
25375
|
-
case "right" /* RIGHT */:
|
|
25376
|
-
return import_docx.AlignmentType.RIGHT;
|
|
25377
|
-
case "alignment" /* ALIGNMENT */:
|
|
25378
|
-
case "justify" /* JUSTIFY */:
|
|
25379
|
-
return import_docx.AlignmentType.JUSTIFIED;
|
|
25380
|
-
default:
|
|
25381
|
-
return import_docx.AlignmentType.LEFT;
|
|
25382
|
-
}
|
|
25383
|
-
}
|
|
25384
|
-
function mapUnderlineType(style) {
|
|
25385
|
-
switch (style) {
|
|
25386
|
-
case "double" /* DOUBLE */:
|
|
25387
|
-
return import_docx.UnderlineType.DOUBLE;
|
|
25388
|
-
case "dashed" /* DASHED */:
|
|
25389
|
-
return import_docx.UnderlineType.DASH;
|
|
25390
|
-
case "dotted" /* DOTTED */:
|
|
25391
|
-
return import_docx.UnderlineType.DOTTED;
|
|
25392
|
-
case "wavy" /* WAVY */:
|
|
25393
|
-
return import_docx.UnderlineType.WAVE;
|
|
25394
|
-
default:
|
|
25395
|
-
return import_docx.UnderlineType.SINGLE;
|
|
25396
|
-
}
|
|
25397
|
-
}
|
|
25398
|
-
function getInlineElementText(element) {
|
|
25399
|
-
switch (element.type) {
|
|
25400
|
-
case "control" /* CONTROL */:
|
|
25401
|
-
return getControlText(element.control);
|
|
25402
|
-
case "date" /* DATE */:
|
|
25403
|
-
return element.valueList?.length ? getTextFromElementList(element.valueList) : element.value;
|
|
25404
|
-
case "checkbox" /* CHECKBOX */:
|
|
25405
|
-
return element.checkbox?.value ? "\u2611" : "\u2610";
|
|
25406
|
-
case "radio" /* RADIO */:
|
|
25407
|
-
return element.radio?.value ? "\u25C9" : "\u25CB";
|
|
25408
|
-
case "label" /* LABEL */:
|
|
25409
|
-
case "latex" /* LATEX */:
|
|
25410
|
-
case "subscript" /* SUBSCRIPT */:
|
|
25411
|
-
case "superscript" /* SUPERSCRIPT */:
|
|
25412
|
-
return element.value;
|
|
25413
|
-
default:
|
|
25414
|
-
return element.value;
|
|
25415
|
-
}
|
|
25416
|
-
}
|
|
25417
|
-
function getControlText(control) {
|
|
25418
|
-
if (!control) return "";
|
|
25419
|
-
if (control.type === "text" /* TEXT */ || control.type === "date" /* DATE */ || control.type === "number" /* NUMBER */) {
|
|
25420
|
-
const value = control.value?.length ? getTextFromElementList(control.value) : "";
|
|
25421
|
-
const content = value || control.placeholder || "";
|
|
25422
|
-
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
25423
|
-
}
|
|
25424
|
-
if (control.type === "select" /* SELECT */) {
|
|
25425
|
-
const labels = getSelectedControlLabels(control.code, control.valueSets);
|
|
25426
|
-
const content = labels.length ? labels.join(control.multiSelectDelimiter || ", ") : control.placeholder || "";
|
|
25427
|
-
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
25428
|
-
}
|
|
25429
|
-
if (control.type === "checkbox" /* CHECKBOX */ || control.type === "radio" /* RADIO */) {
|
|
25430
|
-
const isRadio = control.type === "radio" /* RADIO */;
|
|
25431
|
-
return (control.valueSets || []).map((valueSet) => {
|
|
25432
|
-
const checked = control.code?.split(",").includes(valueSet.code) || false;
|
|
25433
|
-
return `${checked ? isRadio ? "\u25C9" : "\u2611" : isRadio ? "\u25CB" : "\u2610"} ${valueSet.value}`;
|
|
25434
|
-
}).join(" ");
|
|
25435
|
-
}
|
|
25436
|
-
return "";
|
|
25437
|
-
}
|
|
25438
|
-
function getSelectedControlLabels(code, valueSets) {
|
|
25439
|
-
if (!code || !valueSets?.length) return [];
|
|
25440
|
-
return code.split(",").map(
|
|
25441
|
-
(selectCode) => valueSets.find((valueSet) => valueSet.code === selectCode)?.value
|
|
25442
|
-
).filter((value) => !!value);
|
|
25443
|
-
}
|
|
25444
|
-
function getBlockFallbackText(element) {
|
|
25445
|
-
if (element.block?.iframeBlock?.src) {
|
|
25446
|
-
return element.block.iframeBlock.src;
|
|
24922
|
+
pen = target + layoutWidth;
|
|
25447
24923
|
}
|
|
25448
|
-
|
|
25449
|
-
|
|
24924
|
+
flush();
|
|
24925
|
+
if (!children.length && !suffix) {
|
|
24926
|
+
const total = (options.skipLead ? 0 : rowLead(ctx, row, options)) + rowLine(ctx, row).lineTw + rowSpacing(ctx, row, options).after;
|
|
24927
|
+
return createSpacerParagraph(pageBreakBefore, total / PX_TO_TWIP);
|
|
25450
24928
|
}
|
|
25451
|
-
|
|
24929
|
+
const stops = tabStops.map((position) => ({ type: import_docx2.TabStopType.LEFT, position }));
|
|
24930
|
+
if (suffix) {
|
|
24931
|
+
stops.push({ type: suffix.tabType, position: suffix.tabStop });
|
|
24932
|
+
children.push(new import_docx2.TextRun({ children: [new import_docx2.Tab()] }), ...suffix.children);
|
|
24933
|
+
}
|
|
24934
|
+
return new import_docx2.Paragraph({
|
|
24935
|
+
children,
|
|
24936
|
+
style: suffix?.style,
|
|
24937
|
+
pageBreakBefore,
|
|
24938
|
+
widowControl: false,
|
|
24939
|
+
tabStops: stops,
|
|
24940
|
+
indent: { left: pxTw(indent), right: RIGHT_SLACK_TWIP },
|
|
24941
|
+
spacing: rowSpacing(ctx, row, options)
|
|
24942
|
+
});
|
|
25452
24943
|
}
|
|
25453
|
-
|
|
25454
|
-
|
|
24944
|
+
var EXACT_BASELINE_RATIO = 0.8;
|
|
24945
|
+
function rowLine(ctx, row, baseline = row.ascent / ctx.scale) {
|
|
24946
|
+
const { scale } = ctx;
|
|
24947
|
+
const height = row.height / scale;
|
|
24948
|
+
const ascent = Math.min(baseline, height);
|
|
24949
|
+
const line = Math.min(
|
|
24950
|
+
ascent / EXACT_BASELINE_RATIO,
|
|
24951
|
+
(height - ascent) / (1 - EXACT_BASELINE_RATIO)
|
|
24952
|
+
);
|
|
24953
|
+
const lineTw = Math.max(TINY_TWIP, pxTw(line));
|
|
24954
|
+
const beforeTw = Math.max(
|
|
24955
|
+
0,
|
|
24956
|
+
pxTw(ascent) - Math.round(lineTw * EXACT_BASELINE_RATIO)
|
|
24957
|
+
);
|
|
24958
|
+
const afterTw = Math.max(0, pxTw(height) - lineTw - beforeTw);
|
|
24959
|
+
return { lineTw, beforeTw, afterTw };
|
|
25455
24960
|
}
|
|
25456
|
-
function
|
|
24961
|
+
function rowLead(ctx, row, options) {
|
|
24962
|
+
const separator = row.elementList.find(
|
|
24963
|
+
(el) => el.type === "separator" /* SEPARATOR */
|
|
24964
|
+
);
|
|
24965
|
+
const baseline = separator && options.rowY !== void 0 ? separatorBaseline(
|
|
24966
|
+
ctx,
|
|
24967
|
+
row,
|
|
24968
|
+
options.rowY,
|
|
24969
|
+
separator.lineWidth || ctx.draw.getOptions().separator.lineWidth
|
|
24970
|
+
) : void 0;
|
|
24971
|
+
return rowLine(ctx, row, baseline).beforeTw + tw(ctx, (row.offsetY || 0) + (row.spaceAbove || 0)) + pxTw(options.padTop || 0);
|
|
24972
|
+
}
|
|
24973
|
+
function rowSpacing(ctx, row, options) {
|
|
24974
|
+
const { lineTw, afterTw } = rowLine(ctx, row);
|
|
25457
24975
|
return {
|
|
25458
|
-
|
|
24976
|
+
before: options.skipLead ? 0 : rowLead(ctx, row, options),
|
|
24977
|
+
after: afterTw + tw(ctx, row.spaceBelow || 0) + pxTw(options.padBottom || 0) + (options.extraAfter || 0),
|
|
24978
|
+
line: lineTw,
|
|
24979
|
+
lineRule: import_docx2.LineRuleType.EXACT
|
|
25459
24980
|
};
|
|
25460
24981
|
}
|
|
25461
|
-
function
|
|
25462
|
-
|
|
25463
|
-
|
|
25464
|
-
|
|
25465
|
-
|
|
25466
|
-
|
|
25467
|
-
|
|
24982
|
+
function createSeparatorParagraph(ctx, row, element, x, rowY2, zone, options) {
|
|
24983
|
+
const { scale } = ctx;
|
|
24984
|
+
const opts = ctx.draw.getOptions();
|
|
24985
|
+
const lineWidth = element.lineWidth || opts.separator.lineWidth;
|
|
24986
|
+
const sideGap = 4;
|
|
24987
|
+
const left2 = (x - zone.startX) / scale + sideGap;
|
|
24988
|
+
const width = Math.max(1, (element.width || 0) - sideGap * 2);
|
|
24989
|
+
const color = element.color || opts.separator.strokeStyle;
|
|
24990
|
+
const line = rowLine(ctx, row, separatorBaseline(ctx, row, rowY2, lineWidth));
|
|
24991
|
+
return new import_docx2.Paragraph({
|
|
24992
|
+
pageBreakBefore: options.pageBreakBefore,
|
|
24993
|
+
widowControl: false,
|
|
24994
|
+
indent: { left: pxTw(left2), right: RIGHT_SLACK_TWIP },
|
|
24995
|
+
children: [
|
|
24996
|
+
new import_docx2.ImageRun({
|
|
24997
|
+
type: "png",
|
|
24998
|
+
data: createLineImage(width, lineWidth, color, element.dashArray),
|
|
24999
|
+
transformation: { width, height: lineWidth }
|
|
25000
|
+
})
|
|
25001
|
+
],
|
|
25002
|
+
spacing: {
|
|
25003
|
+
before: options.skipLead ? 0 : rowLead(ctx, row, options),
|
|
25004
|
+
after: line.afterTw + tw(ctx, row.spaceBelow || 0) + pxTw(options.padBottom || 0) + (options.extraAfter || 0),
|
|
25005
|
+
line: line.lineTw,
|
|
25006
|
+
lineRule: import_docx2.LineRuleType.EXACT
|
|
25007
|
+
}
|
|
25008
|
+
});
|
|
25468
25009
|
}
|
|
25469
|
-
function
|
|
25470
|
-
return
|
|
25471
|
-
cellLayoutMap: computeTableCellLayout(
|
|
25472
|
-
element.trList || [],
|
|
25473
|
-
element.colgroup || []
|
|
25474
|
-
),
|
|
25475
|
-
borderColor: element.borderColor,
|
|
25476
|
-
borderWidth: element.borderWidth,
|
|
25477
|
-
borderExternalWidth: element.borderExternalWidth
|
|
25478
|
-
};
|
|
25010
|
+
function separatorBaseline(ctx, row, rowY2, lineWidth) {
|
|
25011
|
+
return (Math.round(rowY2 + row.ascent) - rowY2) / ctx.scale + lineWidth;
|
|
25479
25012
|
}
|
|
25480
|
-
function
|
|
25481
|
-
const
|
|
25482
|
-
|
|
25483
|
-
|
|
25484
|
-
|
|
25485
|
-
const
|
|
25486
|
-
|
|
25487
|
-
|
|
25488
|
-
|
|
25489
|
-
|
|
25490
|
-
|
|
25491
|
-
|
|
25492
|
-
|
|
25493
|
-
|
|
25494
|
-
|
|
25495
|
-
|
|
25496
|
-
|
|
25497
|
-
|
|
25498
|
-
|
|
25499
|
-
|
|
25500
|
-
|
|
25501
|
-
|
|
25502
|
-
|
|
25503
|
-
|
|
25013
|
+
function createLineImage(width, height, color, dashArray) {
|
|
25014
|
+
const ratio = 4;
|
|
25015
|
+
const canvas = document.createElement("canvas");
|
|
25016
|
+
canvas.width = Math.max(1, Math.round(width * ratio));
|
|
25017
|
+
canvas.height = Math.max(1, Math.round(height * ratio));
|
|
25018
|
+
const ctx = canvas.getContext("2d");
|
|
25019
|
+
ctx.strokeStyle = color;
|
|
25020
|
+
ctx.lineWidth = canvas.height;
|
|
25021
|
+
if (dashArray?.length) ctx.setLineDash(dashArray.map((v) => v * ratio));
|
|
25022
|
+
ctx.beginPath();
|
|
25023
|
+
ctx.moveTo(0, canvas.height / 2);
|
|
25024
|
+
ctx.lineTo(canvas.width, canvas.height / 2);
|
|
25025
|
+
ctx.stroke();
|
|
25026
|
+
const binary = atob(canvas.toDataURL("image/png").split(",")[1]);
|
|
25027
|
+
const bytes = new Uint8Array(binary.length);
|
|
25028
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
25029
|
+
return bytes;
|
|
25030
|
+
}
|
|
25031
|
+
function createSpacerParagraph(pageBreakBefore, height = 0) {
|
|
25032
|
+
return new import_docx2.Paragraph({
|
|
25033
|
+
pageBreakBefore,
|
|
25034
|
+
widowControl: false,
|
|
25035
|
+
children: [new import_docx2.TextRun({ text: "", size: 2 })],
|
|
25036
|
+
spacing: {
|
|
25037
|
+
before: 0,
|
|
25038
|
+
after: 0,
|
|
25039
|
+
line: Math.max(TINY_TWIP, pxTw(height)),
|
|
25040
|
+
lineRule: import_docx2.LineRuleType.EXACT
|
|
25504
25041
|
}
|
|
25505
|
-
}
|
|
25506
|
-
return cellLayoutMap;
|
|
25042
|
+
});
|
|
25507
25043
|
}
|
|
25508
|
-
function
|
|
25509
|
-
|
|
25510
|
-
|
|
25044
|
+
async function serializeTable(ctx, element, position, zone) {
|
|
25045
|
+
const { draw, scale } = ctx;
|
|
25046
|
+
const opts = draw.getOptions();
|
|
25047
|
+
const tableX = position.coordinate.leftTop[0];
|
|
25048
|
+
const trList = element.trList || [];
|
|
25049
|
+
const colgroup = element.colgroup || [];
|
|
25050
|
+
const rows = [];
|
|
25051
|
+
for (let t = 0; t < trList.length; t++) {
|
|
25052
|
+
const tr = trList[t];
|
|
25053
|
+
const cells = [];
|
|
25054
|
+
let rowTopBorder = 0;
|
|
25055
|
+
for (let d = 0; d < tr.tdList.length; d++) {
|
|
25056
|
+
const td = tr.tdList[d];
|
|
25057
|
+
const padding = td.padding || opts.table.tdPadding;
|
|
25058
|
+
const borders = createCellBorders(ctx, element, td);
|
|
25059
|
+
const topBorder = t === 0 ? borderPx(borders.top) : 0;
|
|
25060
|
+
rowTopBorder = Math.max(rowTopBorder, topBorder);
|
|
25061
|
+
const cellChildren = await serializeRows(
|
|
25062
|
+
ctx,
|
|
25063
|
+
td.rowList || [],
|
|
25064
|
+
{
|
|
25065
|
+
startX: (td.x + padding[3]) * scale + tableX,
|
|
25066
|
+
width: (td.width - padding[1] - padding[3]) * scale,
|
|
25067
|
+
positionList: td.positionList || []
|
|
25068
|
+
},
|
|
25069
|
+
{ padTop: Math.max(0, padding[0] - topBorder), padBottom: padding[2] }
|
|
25070
|
+
);
|
|
25071
|
+
cells.push(
|
|
25072
|
+
new import_docx2.TableCell({
|
|
25073
|
+
children: cellChildren.length ? cellChildren : [createSpacerParagraph(false)],
|
|
25074
|
+
columnSpan: td.colspan > 1 ? td.colspan : void 0,
|
|
25075
|
+
rowSpan: td.rowspan > 1 ? td.rowspan : void 0,
|
|
25076
|
+
width: { size: pxTw(td.width), type: import_docx2.WidthType.DXA },
|
|
25077
|
+
verticalAlign: mapVerticalAlign(td.verticalAlign),
|
|
25078
|
+
margins: {
|
|
25079
|
+
top: 0,
|
|
25080
|
+
right: pxTw(padding[1]),
|
|
25081
|
+
bottom: 0,
|
|
25082
|
+
left: pxTw(Math.max(0, padding[3] - borderPx(borders.left) / 2)),
|
|
25083
|
+
marginUnitType: import_docx2.WidthType.DXA
|
|
25084
|
+
},
|
|
25085
|
+
shading: td.backgroundColor ? {
|
|
25086
|
+
fill: normalizeHexColor(td.backgroundColor, "FFFFFF"),
|
|
25087
|
+
type: import_docx2.ShadingType.CLEAR,
|
|
25088
|
+
color: "auto"
|
|
25089
|
+
} : void 0,
|
|
25090
|
+
borders
|
|
25091
|
+
})
|
|
25092
|
+
);
|
|
25093
|
+
}
|
|
25094
|
+
rows.push(
|
|
25095
|
+
new import_docx2.TableRow({
|
|
25096
|
+
children: cells,
|
|
25097
|
+
cantSplit: true,
|
|
25098
|
+
height: {
|
|
25099
|
+
value: pxTw(tr.height - rowTopBorder),
|
|
25100
|
+
rule: import_docx2.HeightRule.EXACT
|
|
25101
|
+
}
|
|
25102
|
+
})
|
|
25103
|
+
);
|
|
25511
25104
|
}
|
|
25512
|
-
return
|
|
25105
|
+
return new import_docx2.Table({
|
|
25106
|
+
rows,
|
|
25107
|
+
layout: import_docx2.TableLayoutType.FIXED,
|
|
25108
|
+
width: { size: pxTw(element.width), type: import_docx2.WidthType.DXA },
|
|
25109
|
+
columnWidths: colgroup.map((col) => pxTw(col.width)),
|
|
25110
|
+
indent: { size: tw(ctx, tableX - zone.startX), type: import_docx2.WidthType.DXA },
|
|
25111
|
+
borders: noTableBorders()
|
|
25112
|
+
});
|
|
25513
25113
|
}
|
|
25514
|
-
function
|
|
25515
|
-
const
|
|
25516
|
-
|
|
25517
|
-
|
|
25518
|
-
|
|
25519
|
-
|
|
25114
|
+
function createCellBorders(ctx, table, td) {
|
|
25115
|
+
const opts = ctx.draw.getOptions();
|
|
25116
|
+
const color = normalizeHexColor(
|
|
25117
|
+
td.borderColor || table.borderColor || opts.table.defaultBorderColor,
|
|
25118
|
+
"000000"
|
|
25119
|
+
);
|
|
25120
|
+
const width = table.borderWidth || 1;
|
|
25121
|
+
const externalWidth = table.borderExternalWidth || width;
|
|
25122
|
+
const isDash = table.borderType === "dash" /* DASH */;
|
|
25123
|
+
const line = (w) => ({
|
|
25124
|
+
style: isDash ? import_docx2.BorderStyle.DASHED : import_docx2.BorderStyle.SINGLE,
|
|
25125
|
+
size: Math.max(2, Math.round(w * 6)),
|
|
25126
|
+
color
|
|
25127
|
+
});
|
|
25128
|
+
const none = { style: import_docx2.BorderStyle.NONE, size: 0, color: "auto" };
|
|
25129
|
+
const isTop = td.rowIndex === 0;
|
|
25130
|
+
const isLeft = td.colIndex === 0;
|
|
25131
|
+
const isBottom = td.rowIndex + td.rowspan === table.trList.length;
|
|
25132
|
+
const isRight = td.colIndex + td.colspan === table.colgroup.length;
|
|
25133
|
+
const edge = (outer) => outer ? line(externalWidth) : line(width);
|
|
25134
|
+
let top = none;
|
|
25135
|
+
let right2 = none;
|
|
25136
|
+
let bottom = none;
|
|
25137
|
+
let left2 = none;
|
|
25138
|
+
switch (table.borderType) {
|
|
25139
|
+
case "empty" /* EMPTY */:
|
|
25140
|
+
break;
|
|
25141
|
+
case "external" /* EXTERNAL */:
|
|
25142
|
+
if (isTop) top = edge(true);
|
|
25143
|
+
if (isBottom) bottom = edge(true);
|
|
25144
|
+
if (isLeft) left2 = edge(true);
|
|
25145
|
+
if (isRight) right2 = edge(true);
|
|
25146
|
+
break;
|
|
25147
|
+
case "internal" /* INTERNAL */:
|
|
25148
|
+
if (!isTop) top = edge(false);
|
|
25149
|
+
if (!isBottom) bottom = edge(false);
|
|
25150
|
+
if (!isLeft) left2 = edge(false);
|
|
25151
|
+
if (!isRight) right2 = edge(false);
|
|
25152
|
+
break;
|
|
25153
|
+
default:
|
|
25154
|
+
top = edge(isTop);
|
|
25155
|
+
bottom = edge(isBottom);
|
|
25156
|
+
left2 = edge(isLeft);
|
|
25157
|
+
right2 = edge(isRight);
|
|
25158
|
+
}
|
|
25159
|
+
if (td.borderTypes?.includes("top" /* TOP */)) top = line(width);
|
|
25160
|
+
if (td.borderTypes?.includes("right" /* RIGHT */)) right2 = line(width);
|
|
25161
|
+
if (td.borderTypes?.includes("bottom" /* BOTTOM */)) bottom = line(width);
|
|
25162
|
+
if (td.borderTypes?.includes("left" /* LEFT */)) left2 = line(width);
|
|
25163
|
+
return { top, right: right2, bottom, left: left2 };
|
|
25164
|
+
}
|
|
25165
|
+
function borderPx(border) {
|
|
25166
|
+
return border.style === import_docx2.BorderStyle.NONE ? 0 : border.size / 8 * (4 / 3);
|
|
25167
|
+
}
|
|
25168
|
+
function noTableBorders() {
|
|
25169
|
+
const none = { style: import_docx2.BorderStyle.NONE, size: 0, color: "auto" };
|
|
25170
|
+
return {
|
|
25171
|
+
top: none,
|
|
25172
|
+
bottom: none,
|
|
25173
|
+
left: none,
|
|
25174
|
+
right: none,
|
|
25175
|
+
insideHorizontal: none,
|
|
25176
|
+
insideVertical: none
|
|
25177
|
+
};
|
|
25520
25178
|
}
|
|
25521
|
-
function
|
|
25522
|
-
|
|
25523
|
-
|
|
25524
|
-
|
|
25525
|
-
|
|
25526
|
-
|
|
25527
|
-
|
|
25528
|
-
|
|
25529
|
-
|
|
25530
|
-
|
|
25179
|
+
function mapVerticalAlign(verticalAlign) {
|
|
25180
|
+
switch (verticalAlign) {
|
|
25181
|
+
case "middle" /* MIDDLE */:
|
|
25182
|
+
return import_docx2.VerticalAlign.CENTER;
|
|
25183
|
+
case "bottom" /* BOTTOM */:
|
|
25184
|
+
return import_docx2.VerticalAlign.BOTTOM;
|
|
25185
|
+
default:
|
|
25186
|
+
return import_docx2.VerticalAlign.TOP;
|
|
25187
|
+
}
|
|
25188
|
+
}
|
|
25189
|
+
async function serializeFooter(ctx, pageWidth, pageHeight, margins) {
|
|
25190
|
+
const { draw, scale } = ctx;
|
|
25191
|
+
const footer = draw.getFooter();
|
|
25192
|
+
const opts = draw.getOptions();
|
|
25193
|
+
const barHeight = footer.getHeight() / scale;
|
|
25194
|
+
const contentHeight = footer.getRowHeight() / scale;
|
|
25195
|
+
const paddingTop = Math.floor(Math.max(0, (barHeight - contentHeight) / 2) * scale) / scale;
|
|
25196
|
+
const zone = {
|
|
25197
|
+
startX: draw.getMargins()[3],
|
|
25198
|
+
width: draw.getInnerWidth(),
|
|
25199
|
+
positionList: footer.getPositionList()
|
|
25200
|
+
};
|
|
25201
|
+
const rowList = footer.getRowList();
|
|
25202
|
+
const textWidth = pageWidth - margins[1] - margins[3];
|
|
25203
|
+
const pageNumber = createPageNumberRuns(ctx, pageHeight, textWidth);
|
|
25204
|
+
let pageNumberRow = -1;
|
|
25205
|
+
if (pageNumber) {
|
|
25206
|
+
pageNumberRow = rowList.length - 1;
|
|
25207
|
+
for (let r = 0; r < rowList.length; r++) {
|
|
25208
|
+
const top = zone.positionList[rowList[r].startIndex].coordinate.leftTop[1] / scale;
|
|
25209
|
+
if (pageNumber.baseline <= top + rowList[r].height / scale) {
|
|
25210
|
+
pageNumberRow = r;
|
|
25211
|
+
break;
|
|
25212
|
+
}
|
|
25213
|
+
}
|
|
25531
25214
|
}
|
|
25532
|
-
|
|
25533
|
-
|
|
25215
|
+
const children = [];
|
|
25216
|
+
for (let r = 0; r < rowList.length; r++) {
|
|
25217
|
+
const row = rowList[r];
|
|
25218
|
+
const rowOptions = { padTop: r === 0 ? paddingTop : 0 };
|
|
25219
|
+
if (r !== pageNumberRow) {
|
|
25220
|
+
children.push(...await serializeRows(ctx, [row], zone, rowOptions));
|
|
25221
|
+
continue;
|
|
25222
|
+
}
|
|
25223
|
+
const top = zone.positionList[row.startIndex].coordinate.leftTop[1] / scale;
|
|
25224
|
+
const shift = pageNumber.baseline - (top + row.ascent / scale);
|
|
25225
|
+
children.push(
|
|
25226
|
+
await serializeRow(ctx, row, zone, rowOptions, {
|
|
25227
|
+
tabStop: pageNumber.tabStop,
|
|
25228
|
+
tabType: pageNumber.tabType,
|
|
25229
|
+
children: pageNumber.runs(shift),
|
|
25230
|
+
style: PAGE_NUMBER_STYLE
|
|
25231
|
+
})
|
|
25232
|
+
);
|
|
25534
25233
|
}
|
|
25535
|
-
|
|
25234
|
+
const fill = opts.footer.backgroundColor ? normalizeHexColor(opts.footer.backgroundColor, "FFFFFF") : void 0;
|
|
25235
|
+
const none = { style: import_docx2.BorderStyle.NONE, size: 0, color: "auto" };
|
|
25236
|
+
const band = new import_docx2.Table({
|
|
25237
|
+
layout: import_docx2.TableLayoutType.FIXED,
|
|
25238
|
+
width: { size: pxTw(pageWidth), type: import_docx2.WidthType.DXA },
|
|
25239
|
+
columnWidths: [pxTw(pageWidth)],
|
|
25240
|
+
indent: { size: -pxTw(margins[3]), type: import_docx2.WidthType.DXA },
|
|
25241
|
+
borders: noTableBorders(),
|
|
25242
|
+
rows: [
|
|
25243
|
+
new import_docx2.TableRow({
|
|
25244
|
+
cantSplit: true,
|
|
25245
|
+
height: { value: pxTw(barHeight), rule: import_docx2.HeightRule.EXACT },
|
|
25246
|
+
children: [
|
|
25247
|
+
new import_docx2.TableCell({
|
|
25248
|
+
width: { size: pxTw(pageWidth), type: import_docx2.WidthType.DXA },
|
|
25249
|
+
margins: {
|
|
25250
|
+
top: 0,
|
|
25251
|
+
bottom: 0,
|
|
25252
|
+
left: pxTw(margins[3]),
|
|
25253
|
+
right: pxTw(margins[1]),
|
|
25254
|
+
marginUnitType: import_docx2.WidthType.DXA
|
|
25255
|
+
},
|
|
25256
|
+
shading: fill ? { fill, type: import_docx2.ShadingType.CLEAR, color: "auto" } : void 0,
|
|
25257
|
+
borders: { top: none, right: none, bottom: none, left: none },
|
|
25258
|
+
children: children.length ? children : [createSpacerParagraph(false)]
|
|
25259
|
+
})
|
|
25260
|
+
]
|
|
25261
|
+
})
|
|
25262
|
+
]
|
|
25263
|
+
});
|
|
25264
|
+
return [band];
|
|
25536
25265
|
}
|
|
25537
|
-
|
|
25538
|
-
|
|
25539
|
-
|
|
25540
|
-
|
|
25266
|
+
var PAGE_NUMBER_STYLE = "WindocPageNumber";
|
|
25267
|
+
var FieldCharAttributes = class extends import_docx2.XmlAttributeComponent {
|
|
25268
|
+
constructor() {
|
|
25269
|
+
super(...arguments);
|
|
25270
|
+
this.xmlKeys = { type: "w:fldCharType" };
|
|
25541
25271
|
}
|
|
25542
|
-
|
|
25543
|
-
|
|
25544
|
-
|
|
25272
|
+
};
|
|
25273
|
+
var FieldChar = class extends import_docx2.XmlComponent {
|
|
25274
|
+
constructor(type) {
|
|
25275
|
+
super("w:fldChar");
|
|
25276
|
+
this.root.push(new FieldCharAttributes({ type }));
|
|
25545
25277
|
}
|
|
25546
|
-
|
|
25547
|
-
|
|
25548
|
-
|
|
25549
|
-
|
|
25550
|
-
|
|
25278
|
+
};
|
|
25279
|
+
var InstrTextAttributes = class extends import_docx2.XmlAttributeComponent {
|
|
25280
|
+
constructor() {
|
|
25281
|
+
super(...arguments);
|
|
25282
|
+
this.xmlKeys = { space: "xml:space" };
|
|
25551
25283
|
}
|
|
25552
|
-
|
|
25553
|
-
|
|
25554
|
-
|
|
25284
|
+
};
|
|
25285
|
+
var InstrText = class extends import_docx2.XmlComponent {
|
|
25286
|
+
constructor(instruction) {
|
|
25287
|
+
super("w:instrText");
|
|
25288
|
+
this.root.push(new InstrTextAttributes({ space: "preserve" }));
|
|
25289
|
+
this.root.push(` ${instruction} `);
|
|
25555
25290
|
}
|
|
25556
|
-
|
|
25557
|
-
|
|
25558
|
-
|
|
25559
|
-
|
|
25291
|
+
};
|
|
25292
|
+
function createFieldRuns(instruction, cached, style) {
|
|
25293
|
+
return [
|
|
25294
|
+
new import_docx2.TextRun({ ...style, children: [new FieldChar("begin")] }),
|
|
25295
|
+
new import_docx2.TextRun({ ...style, children: [new InstrText(instruction)] }),
|
|
25296
|
+
new import_docx2.TextRun({ ...style, children: [new FieldChar("separate")] }),
|
|
25297
|
+
new import_docx2.TextRun({ ...style, text: cached }),
|
|
25298
|
+
new import_docx2.TextRun({ ...style, children: [new FieldChar("end")] })
|
|
25560
25299
|
];
|
|
25561
|
-
return flattened.map(toHexChannel).join("");
|
|
25562
25300
|
}
|
|
25563
|
-
function
|
|
25564
|
-
|
|
25565
|
-
|
|
25566
|
-
|
|
25567
|
-
|
|
25568
|
-
|
|
25569
|
-
|
|
25570
|
-
return void 0;
|
|
25571
|
-
}
|
|
25572
|
-
context.fillStyle = "#000000";
|
|
25573
|
-
context.fillStyle = color;
|
|
25574
|
-
const normalized = context.fillStyle;
|
|
25575
|
-
if (typeof normalized !== "string") {
|
|
25576
|
-
return void 0;
|
|
25577
|
-
}
|
|
25578
|
-
return normalizeHexLiteral(normalized) || normalizeRgbColor(normalized);
|
|
25301
|
+
function pageNumberRunStyle(pageNumber) {
|
|
25302
|
+
return {
|
|
25303
|
+
font: mapFont(pageNumber?.font || "sans-serif"),
|
|
25304
|
+
// PageNumber draws `${size}px`; half-points = px * 0.75 * 2
|
|
25305
|
+
size: Math.round((pageNumber?.size || 12) * 1.5),
|
|
25306
|
+
color: normalizeHexColor(pageNumber?.color || "#000000", "000000")
|
|
25307
|
+
};
|
|
25579
25308
|
}
|
|
25580
|
-
function
|
|
25581
|
-
|
|
25582
|
-
|
|
25583
|
-
|
|
25584
|
-
|
|
25585
|
-
}
|
|
25586
|
-
|
|
25587
|
-
|
|
25588
|
-
const
|
|
25589
|
-
|
|
25590
|
-
|
|
25309
|
+
function createPageNumberRuns(ctx, pageHeight, textWidth) {
|
|
25310
|
+
const { pageNumber } = ctx.draw.getOptions();
|
|
25311
|
+
if (pageNumber.disabled || pageNumber.fromPageNo > 0) return null;
|
|
25312
|
+
const pageCount = ctx.draw.getPageCount();
|
|
25313
|
+
const tokens = (pageNumber.format || FORMAT_PLACEHOLDER.PAGE_NO).split(
|
|
25314
|
+
/(\{pageNo\}|\{pageCount\})/
|
|
25315
|
+
);
|
|
25316
|
+
const tabType = pageNumber.rowFlex === "center" /* CENTER */ ? import_docx2.TabStopType.CENTER : pageNumber.rowFlex === "right" /* RIGHT */ ? import_docx2.TabStopType.RIGHT : import_docx2.TabStopType.LEFT;
|
|
25317
|
+
const tabStop = tabType === import_docx2.TabStopType.CENTER ? pxTw(textWidth / 2) : tabType === import_docx2.TabStopType.RIGHT ? pxTw(textWidth) : 0;
|
|
25318
|
+
const position = (shift) => {
|
|
25319
|
+
const halfPoints = Math.round(-shift * 0.75 * 2);
|
|
25320
|
+
return halfPoints ? `${halfPoints}` : void 0;
|
|
25321
|
+
};
|
|
25322
|
+
return {
|
|
25323
|
+
baseline: pageHeight - pageNumber.bottom,
|
|
25324
|
+
tabType,
|
|
25325
|
+
tabStop,
|
|
25326
|
+
// shift > 0 means the number sits lower than the row baseline
|
|
25327
|
+
runs: (shift) => tokens.filter(Boolean).map((token) => {
|
|
25328
|
+
const style = {
|
|
25329
|
+
...pageNumberRunStyle(pageNumber),
|
|
25330
|
+
position: position(shift)
|
|
25331
|
+
};
|
|
25332
|
+
const field = token === FORMAT_PLACEHOLDER.PAGE_NO ? { instruction: "PAGE", cached: "1" } : token === FORMAT_PLACEHOLDER.PAGE_COUNT ? { instruction: "NUMPAGES", cached: `${pageCount}` } : null;
|
|
25333
|
+
if (!field) return [new import_docx2.TextRun({ text: token, ...style })];
|
|
25334
|
+
return createFieldRuns(field.instruction, field.cached, style);
|
|
25335
|
+
}).flat()
|
|
25336
|
+
};
|
|
25337
|
+
}
|
|
25338
|
+
function createTextRun(ctx, text, element, shading, characterSpacing) {
|
|
25339
|
+
const opts = ctx.draw.getOptions();
|
|
25340
|
+
const isLink = element.type === "hyperlink" /* HYPERLINK */;
|
|
25341
|
+
const color = normalizeHexColor(
|
|
25342
|
+
element.color || (isLink ? opts.defaultHyperlinkColor : opts.defaultColor),
|
|
25343
|
+
"000000"
|
|
25344
|
+
);
|
|
25345
|
+
const highlight = element.highlight ? normalizeHexColor(element.highlight) : void 0;
|
|
25346
|
+
const textRun = new import_docx2.TextRun({
|
|
25347
|
+
text,
|
|
25348
|
+
font: mapFont(element.font || opts.defaultFont),
|
|
25349
|
+
size: Math.round(getSize(ctx, element) * 2),
|
|
25350
|
+
bold: !!element.bold,
|
|
25351
|
+
italics: !!element.italic,
|
|
25352
|
+
strike: !!element.strikeout,
|
|
25353
|
+
superScript: element.type === "superscript" /* SUPERSCRIPT */,
|
|
25354
|
+
subScript: element.type === "subscript" /* SUBSCRIPT */,
|
|
25355
|
+
underline: element.underline || isLink ? { type: mapUnderlineType(element.textDecoration?.style) } : void 0,
|
|
25356
|
+
color,
|
|
25357
|
+
shading: shading || (highlight ? { fill: highlight, type: import_docx2.ShadingType.CLEAR, color: "auto" } : void 0),
|
|
25358
|
+
characterSpacing
|
|
25359
|
+
});
|
|
25360
|
+
if (isLink && element.url) {
|
|
25361
|
+
return new import_docx2.ExternalHyperlink({ link: element.url, children: [textRun] });
|
|
25591
25362
|
}
|
|
25592
|
-
return
|
|
25363
|
+
return textRun;
|
|
25593
25364
|
}
|
|
25594
|
-
function
|
|
25595
|
-
|
|
25596
|
-
|
|
25597
|
-
|
|
25598
|
-
|
|
25365
|
+
function labelShading(ctx, element) {
|
|
25366
|
+
const { defaultBackgroundColor } = ctx.draw.getOptions().label;
|
|
25367
|
+
return {
|
|
25368
|
+
fill: normalizeHexColor(
|
|
25369
|
+
element.label?.backgroundColor || defaultBackgroundColor,
|
|
25370
|
+
"FFFFFF"
|
|
25371
|
+
),
|
|
25372
|
+
type: import_docx2.ShadingType.CLEAR,
|
|
25373
|
+
color: "auto"
|
|
25374
|
+
};
|
|
25375
|
+
}
|
|
25376
|
+
async function createImageRun(element) {
|
|
25377
|
+
try {
|
|
25378
|
+
const image = await loadImagePayload(element.value);
|
|
25379
|
+
const transformation = {
|
|
25380
|
+
width: Math.max(1, element.width || 1),
|
|
25381
|
+
height: Math.max(1, element.height || 1)
|
|
25382
|
+
};
|
|
25383
|
+
if (image.type === "svg" && image.fallbackPng) {
|
|
25384
|
+
return new import_docx2.ImageRun({
|
|
25385
|
+
type: "svg",
|
|
25386
|
+
data: image.data,
|
|
25387
|
+
fallback: { type: "png", data: image.fallbackPng },
|
|
25388
|
+
transformation
|
|
25389
|
+
});
|
|
25599
25390
|
}
|
|
25600
|
-
return
|
|
25601
|
-
|
|
25602
|
-
|
|
25603
|
-
|
|
25391
|
+
return new import_docx2.ImageRun({
|
|
25392
|
+
type: image.type,
|
|
25393
|
+
data: image.data,
|
|
25394
|
+
transformation
|
|
25395
|
+
});
|
|
25396
|
+
} catch {
|
|
25604
25397
|
return null;
|
|
25605
25398
|
}
|
|
25606
|
-
return Math.min(Math.max(alpha, 0), 1);
|
|
25607
|
-
}
|
|
25608
|
-
function clampColorChannel(value) {
|
|
25609
|
-
return Math.min(Math.max(value, 0), 255);
|
|
25610
25399
|
}
|
|
25611
|
-
function
|
|
25612
|
-
|
|
25400
|
+
function getElementText(element) {
|
|
25401
|
+
switch (element.type) {
|
|
25402
|
+
case "checkbox" /* CHECKBOX */:
|
|
25403
|
+
return element.checkbox?.value ? "\u2611" : "\u2610";
|
|
25404
|
+
case "radio" /* RADIO */:
|
|
25405
|
+
return element.radio?.value ? "\u25C9" : "\u25CB";
|
|
25406
|
+
default:
|
|
25407
|
+
return (element.value || "").replace(new RegExp(ZERO, "g"), "");
|
|
25408
|
+
}
|
|
25613
25409
|
}
|
|
25614
|
-
function
|
|
25615
|
-
return
|
|
25410
|
+
function getSize(ctx, element) {
|
|
25411
|
+
return element.actualSize || element.size || ctx.draw.getOptions().defaultSize;
|
|
25616
25412
|
}
|
|
25617
|
-
function
|
|
25618
|
-
|
|
25619
|
-
return
|
|
25413
|
+
function measure(ctx, text, element) {
|
|
25414
|
+
ctx.measureCtx.font = ctx.draw.getElementFont(element, 1);
|
|
25415
|
+
return ctx.measureCtx.measureText(text).width;
|
|
25620
25416
|
}
|
|
25621
|
-
function
|
|
25622
|
-
|
|
25623
|
-
if (mime.includes("jpeg") || mime.includes("jpg")) return "jpg";
|
|
25624
|
-
if (mime.includes("gif")) return "gif";
|
|
25625
|
-
if (mime.includes("bmp")) return "bmp";
|
|
25626
|
-
return null;
|
|
25417
|
+
function isSameRunStyle(a, b) {
|
|
25418
|
+
return a.type === b.type && a.font === b.font && a.size === b.size && a.actualSize === b.actualSize && !!a.bold === !!b.bold && !!a.italic === !!b.italic && !!a.underline === !!b.underline && !!a.strikeout === !!b.strikeout && a.color === b.color && a.highlight === b.highlight && a.url === b.url;
|
|
25627
25419
|
}
|
|
25628
|
-
function
|
|
25629
|
-
const
|
|
25630
|
-
|
|
25631
|
-
|
|
25420
|
+
function mapFont(font) {
|
|
25421
|
+
const name = font.trim().replace(/^['"]|['"]$/g, "");
|
|
25422
|
+
switch (name.toLowerCase()) {
|
|
25423
|
+
case "sans-serif":
|
|
25424
|
+
return "Arial";
|
|
25425
|
+
case "serif":
|
|
25426
|
+
return "Times New Roman";
|
|
25427
|
+
case "monospace":
|
|
25428
|
+
return "Courier New";
|
|
25429
|
+
default:
|
|
25430
|
+
return name;
|
|
25632
25431
|
}
|
|
25633
|
-
return trimmed.toLowerCase().endsWith(".docx") ? trimmed : `${trimmed}.docx`;
|
|
25634
|
-
}
|
|
25635
|
-
function pxToTwips(px) {
|
|
25636
|
-
return Math.round(px * 15);
|
|
25637
25432
|
}
|
|
25638
25433
|
|
|
25639
25434
|
// src/utils/pdf.ts
|
|
@@ -25641,7 +25436,7 @@ var import_pdf_lib = require("pdf-lib");
|
|
|
25641
25436
|
var DEFAULT_PDF_FILE_NAME = "document.pdf";
|
|
25642
25437
|
var DEFAULT_IMAGE_WIDTH2 = 320;
|
|
25643
25438
|
var DEFAULT_IMAGE_HEIGHT2 = 180;
|
|
25644
|
-
var
|
|
25439
|
+
var DEFAULT_LINE_HEIGHT = 1.15;
|
|
25645
25440
|
var PAGE_REGION_GAP = 12;
|
|
25646
25441
|
var SEPARATOR_HEIGHT = 12;
|
|
25647
25442
|
var LIST_GAP = 8;
|
|
@@ -25836,7 +25631,7 @@ async function parseElementList(elementList, context, options) {
|
|
|
25836
25631
|
}
|
|
25837
25632
|
if (element.type === "block" /* BLOCK */) {
|
|
25838
25633
|
await flushInlineBuffer();
|
|
25839
|
-
const blockText =
|
|
25634
|
+
const blockText = getBlockFallbackText(element);
|
|
25840
25635
|
if (blockText) {
|
|
25841
25636
|
blocks.push(
|
|
25842
25637
|
...await parseInlineElements(
|
|
@@ -25888,7 +25683,7 @@ async function parseInlineElements(elementList, context, options, overrides = {}
|
|
|
25888
25683
|
current = null;
|
|
25889
25684
|
};
|
|
25890
25685
|
const appendText = (element, text, factory, preserveTrailingBreak = false) => {
|
|
25891
|
-
const normalized =
|
|
25686
|
+
const normalized = normalizeText(text);
|
|
25892
25687
|
const parts = normalized.split("\n");
|
|
25893
25688
|
let lastSeparatorFlushedContent = false;
|
|
25894
25689
|
for (let i = 0; i < parts.length; i++) {
|
|
@@ -25924,7 +25719,7 @@ async function parseInlineElements(elementList, context, options, overrides = {}
|
|
|
25924
25719
|
const children = element.valueList || [];
|
|
25925
25720
|
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
25926
25721
|
const child = children[childIndex];
|
|
25927
|
-
const text =
|
|
25722
|
+
const text = normalizeText(getInlineElementText(child));
|
|
25928
25723
|
if (!text) continue;
|
|
25929
25724
|
appendText(
|
|
25930
25725
|
element,
|
|
@@ -25973,7 +25768,7 @@ async function parseInlineElements(elementList, context, options, overrides = {}
|
|
|
25973
25768
|
ensureParagraph(element).runs.push(badgeRun);
|
|
25974
25769
|
continue;
|
|
25975
25770
|
}
|
|
25976
|
-
const textValue =
|
|
25771
|
+
const textValue = getInlineElementText(element);
|
|
25977
25772
|
if (!textValue) {
|
|
25978
25773
|
continue;
|
|
25979
25774
|
}
|
|
@@ -26001,7 +25796,7 @@ async function parseListBlock(element, context, options) {
|
|
|
26001
25796
|
const blocks = [];
|
|
26002
25797
|
const orderedCounts = Array(9).fill(0);
|
|
26003
25798
|
for (const listItemElements of listItemMap.values()) {
|
|
26004
|
-
const itemElement =
|
|
25799
|
+
const itemElement = getListItemNumberingElement(listItemElements, element);
|
|
26005
25800
|
const marker = getListMarker(itemElement, orderedCounts);
|
|
26006
25801
|
blocks.push(
|
|
26007
25802
|
...await parseInlineElements(listItemElements, context, options, {
|
|
@@ -26560,10 +26355,11 @@ function layoutParagraph(block, width, context) {
|
|
|
26560
26355
|
}
|
|
26561
26356
|
if (token.width > availableWidth && token.kind === "text" && token.run.type === "text") {
|
|
26562
26357
|
const segments = splitTextToken(token, availableWidth, context);
|
|
26563
|
-
|
|
26564
|
-
tokens.splice(i
|
|
26358
|
+
if (segments.length > 1) {
|
|
26359
|
+
tokens.splice(i, 1, ...segments);
|
|
26360
|
+
i--;
|
|
26361
|
+
continue;
|
|
26565
26362
|
}
|
|
26566
|
-
continue;
|
|
26567
26363
|
}
|
|
26568
26364
|
if (line.width + token.width > availableWidth && line.fragments.length) {
|
|
26569
26365
|
commitLine();
|
|
@@ -26922,7 +26718,7 @@ function getEmptyLineHeight(block, context) {
|
|
|
26922
26718
|
block.context.rowMargin || context.options.defaultRowMargin
|
|
26923
26719
|
);
|
|
26924
26720
|
}
|
|
26925
|
-
function getRunHeight(run, rowMargin =
|
|
26721
|
+
function getRunHeight(run, rowMargin = DEFAULT_LINE_HEIGHT) {
|
|
26926
26722
|
return run.size * rowMargin;
|
|
26927
26723
|
}
|
|
26928
26724
|
function resolveTextMetrics(run, context) {
|
|
@@ -27131,10 +26927,10 @@ function loadHtmlImage2(src) {
|
|
|
27131
26927
|
image.src = src;
|
|
27132
26928
|
});
|
|
27133
26929
|
}
|
|
27134
|
-
function
|
|
26930
|
+
function getInlineElementText(element) {
|
|
27135
26931
|
switch (element.type) {
|
|
27136
26932
|
case "control" /* CONTROL */:
|
|
27137
|
-
return
|
|
26933
|
+
return getControlText(element.control);
|
|
27138
26934
|
case "date" /* DATE */:
|
|
27139
26935
|
return element.valueList?.length ? getTextFromElementList(element.valueList) : element.value;
|
|
27140
26936
|
case "checkbox" /* CHECKBOX */:
|
|
@@ -27150,7 +26946,7 @@ function getInlineElementText2(element) {
|
|
|
27150
26946
|
return element.value;
|
|
27151
26947
|
}
|
|
27152
26948
|
}
|
|
27153
|
-
function
|
|
26949
|
+
function getControlText(control) {
|
|
27154
26950
|
if (!control) return "";
|
|
27155
26951
|
if (control.type === "text" /* TEXT */ || control.type === "date" /* DATE */ || control.type === "number" /* NUMBER */) {
|
|
27156
26952
|
const value = control.value?.length ? getTextFromElementList(control.value) : "";
|
|
@@ -27158,7 +26954,7 @@ function getControlText2(control) {
|
|
|
27158
26954
|
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
27159
26955
|
}
|
|
27160
26956
|
if (control.type === "select" /* SELECT */) {
|
|
27161
|
-
const labels =
|
|
26957
|
+
const labels = getSelectedControlLabels(control.code, control.valueSets);
|
|
27162
26958
|
const content = labels.length ? labels.join(control.multiSelectDelimiter || ", ") : control.placeholder || "";
|
|
27163
26959
|
return `${control.preText || ""}${content}${control.postText || ""}`;
|
|
27164
26960
|
}
|
|
@@ -27171,13 +26967,13 @@ function getControlText2(control) {
|
|
|
27171
26967
|
}
|
|
27172
26968
|
return "";
|
|
27173
26969
|
}
|
|
27174
|
-
function
|
|
26970
|
+
function getSelectedControlLabels(code, valueSets) {
|
|
27175
26971
|
if (!code || !valueSets?.length) return [];
|
|
27176
26972
|
return code.split(",").map(
|
|
27177
26973
|
(selectCode) => valueSets.find((valueSet) => valueSet.code === selectCode)?.value
|
|
27178
26974
|
).filter((value) => !!value);
|
|
27179
26975
|
}
|
|
27180
|
-
function
|
|
26976
|
+
function getBlockFallbackText(element) {
|
|
27181
26977
|
if (element.block?.iframeBlock?.src) {
|
|
27182
26978
|
return element.block.iframeBlock.src;
|
|
27183
26979
|
}
|
|
@@ -27186,7 +26982,7 @@ function getBlockFallbackText2(element) {
|
|
|
27186
26982
|
}
|
|
27187
26983
|
return "";
|
|
27188
26984
|
}
|
|
27189
|
-
function
|
|
26985
|
+
function getListItemNumberingElement(listItemElements, fallback) {
|
|
27190
26986
|
return listItemElements.find(
|
|
27191
26987
|
(listItem) => listItem.listId || listItem.listLevel !== void 0 || !!listItem.listPreset || !!listItem.listStyle || !!listItem.listType
|
|
27192
26988
|
) || fallback;
|
|
@@ -27408,7 +27204,7 @@ function getReservedPageNumberBottom(pageNumber, pageNumberHeight) {
|
|
|
27408
27204
|
}
|
|
27409
27205
|
return pxToPt(pageNumber.bottom + 4) + pageNumberHeight;
|
|
27410
27206
|
}
|
|
27411
|
-
function
|
|
27207
|
+
function normalizeText(text = "") {
|
|
27412
27208
|
return text.replace(new RegExp(ZERO, "g"), "").replace(/\r\n/g, "\n");
|
|
27413
27209
|
}
|
|
27414
27210
|
function normalizePdfFileName(fileName) {
|
|
@@ -28748,8 +28544,7 @@ var CommandAdapt = class {
|
|
|
28748
28544
|
}
|
|
28749
28545
|
}
|
|
28750
28546
|
async exportDocx(payload = {}) {
|
|
28751
|
-
const
|
|
28752
|
-
const { blob, fileName } = await exportEditorDataToDocx(result, payload);
|
|
28547
|
+
const { blob, fileName } = await exportDrawToDocx(this.draw, payload);
|
|
28753
28548
|
downloadBlob(blob, fileName);
|
|
28754
28549
|
}
|
|
28755
28550
|
async exportPdf(payload = {}) {
|