documents.js 1.38.0 → 1.39.0
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.cjs +797 -67
- package/dist/index.d.cts +146 -11
- package/dist/index.d.ts +146 -11
- package/dist/index.js +788 -69
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -521,7 +521,7 @@ function needsSpacePreserve(text) {
|
|
|
521
521
|
}
|
|
522
522
|
//#endregion
|
|
523
523
|
//#region src/edit/docx/run.ts
|
|
524
|
-
function directChild$
|
|
524
|
+
function directChild$5(parent, tag) {
|
|
525
525
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
526
526
|
}
|
|
527
527
|
function appendUElement(rPr, value) {
|
|
@@ -530,7 +530,7 @@ function appendUElement(rPr, value) {
|
|
|
530
530
|
return created;
|
|
531
531
|
}
|
|
532
532
|
function findOrCreateT(run) {
|
|
533
|
-
const existing = directChild$
|
|
533
|
+
const existing = directChild$5(run, "w:t");
|
|
534
534
|
if (existing !== void 0) return existing;
|
|
535
535
|
const created = el("w:t");
|
|
536
536
|
run.children.push(created);
|
|
@@ -550,7 +550,7 @@ var DocxRun = class {
|
|
|
550
550
|
}
|
|
551
551
|
rPr(create) {
|
|
552
552
|
const node = this.live();
|
|
553
|
-
return create ? ensureFirstChild(node, "w:rPr") : directChild$
|
|
553
|
+
return create ? ensureFirstChild(node, "w:rPr") : directChild$5(node, "w:rPr");
|
|
554
554
|
}
|
|
555
555
|
get text() {
|
|
556
556
|
return (0, ooxml_js.textContent)(this.live());
|
|
@@ -574,14 +574,14 @@ var DocxRun = class {
|
|
|
574
574
|
}
|
|
575
575
|
get underline() {
|
|
576
576
|
const rPr = this.rPr(false);
|
|
577
|
-
const uElement = rPr === void 0 ? void 0 : directChild$
|
|
577
|
+
const uElement = rPr === void 0 ? void 0 : directChild$5(rPr, "w:u");
|
|
578
578
|
if (uElement === void 0) return false;
|
|
579
579
|
for (const a of uElement.attributes) if (a.name === "w:val") return a.value !== "none";
|
|
580
580
|
return true;
|
|
581
581
|
}
|
|
582
582
|
set underline(value) {
|
|
583
583
|
const rPr = this.rPr(true);
|
|
584
|
-
const existing = directChild$
|
|
584
|
+
const existing = directChild$5(rPr, "w:u");
|
|
585
585
|
if (existing === void 0) {
|
|
586
586
|
appendUElement(rPr, value);
|
|
587
587
|
return;
|
|
@@ -628,7 +628,7 @@ function insertRPrChildInOrder(rPr, child) {
|
|
|
628
628
|
}
|
|
629
629
|
rPr.children.push(child);
|
|
630
630
|
}
|
|
631
|
-
function buildRun(init = {}) {
|
|
631
|
+
function buildRun$1(init = {}) {
|
|
632
632
|
const rPrChildren = [];
|
|
633
633
|
if (init.bold === true) rPrChildren.push(el("w:b"));
|
|
634
634
|
if (init.italic === true) rPrChildren.push(el("w:i"));
|
|
@@ -655,7 +655,7 @@ function buildRun(init = {}) {
|
|
|
655
655
|
}
|
|
656
656
|
//#endregion
|
|
657
657
|
//#region src/edit/docx/paragraph.ts
|
|
658
|
-
function directChild$
|
|
658
|
+
function directChild$4(parent, tag) {
|
|
659
659
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
660
660
|
}
|
|
661
661
|
var DocxParagraph = class {
|
|
@@ -674,7 +674,7 @@ var DocxParagraph = class {
|
|
|
674
674
|
}
|
|
675
675
|
pPr(create) {
|
|
676
676
|
const node = this.live();
|
|
677
|
-
return create ? ensureFirstChild(node, "w:pPr") : directChild$
|
|
677
|
+
return create ? ensureFirstChild(node, "w:pPr") : directChild$4(node, "w:pPr");
|
|
678
678
|
}
|
|
679
679
|
get text() {
|
|
680
680
|
return (0, ooxml_js.textContent)(this.live());
|
|
@@ -687,7 +687,7 @@ var DocxParagraph = class {
|
|
|
687
687
|
}
|
|
688
688
|
appendRun(init) {
|
|
689
689
|
const node = this.live();
|
|
690
|
-
const runElement = buildRun(init);
|
|
690
|
+
const runElement = buildRun$1(init);
|
|
691
691
|
node.children.push(runElement);
|
|
692
692
|
return new DocxRun(node.children, runElement);
|
|
693
693
|
}
|
|
@@ -696,7 +696,7 @@ var DocxParagraph = class {
|
|
|
696
696
|
}
|
|
697
697
|
insertRunAt(index, init) {
|
|
698
698
|
const node = this.live();
|
|
699
|
-
const runElement = buildRun(init);
|
|
699
|
+
const runElement = buildRun$1(init);
|
|
700
700
|
const runIndices = [];
|
|
701
701
|
node.children.forEach((child, i) => {
|
|
702
702
|
if (child.type === "element" && child.tag === "w:r") runIndices.push(i);
|
|
@@ -711,7 +711,7 @@ var DocxParagraph = class {
|
|
|
711
711
|
set styleId(value) {
|
|
712
712
|
if (value === void 0) {
|
|
713
713
|
const pPr = this.pPr(false);
|
|
714
|
-
const existing = pPr === void 0 ? void 0 : directChild$
|
|
714
|
+
const existing = pPr === void 0 ? void 0 : directChild$4(pPr, "w:pStyle");
|
|
715
715
|
if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
|
|
716
716
|
return;
|
|
717
717
|
}
|
|
@@ -723,7 +723,7 @@ var DocxParagraph = class {
|
|
|
723
723
|
set alignment(value) {
|
|
724
724
|
if (value === void 0) {
|
|
725
725
|
const pPr = this.pPr(false);
|
|
726
|
-
const existing = pPr === void 0 ? void 0 : directChild$
|
|
726
|
+
const existing = pPr === void 0 ? void 0 : directChild$4(pPr, "w:jc");
|
|
727
727
|
if (existing !== void 0 && pPr !== void 0) removeChild(pPr.children, existing);
|
|
728
728
|
return;
|
|
729
729
|
}
|
|
@@ -731,12 +731,12 @@ var DocxParagraph = class {
|
|
|
731
731
|
}
|
|
732
732
|
get list() {
|
|
733
733
|
const pPr = this.pPr(false);
|
|
734
|
-
const numPr = pPr === void 0 ? void 0 : directChild$
|
|
734
|
+
const numPr = pPr === void 0 ? void 0 : directChild$4(pPr, "w:numPr");
|
|
735
735
|
if (numPr === void 0) return;
|
|
736
|
-
const numIdElement = directChild$
|
|
736
|
+
const numIdElement = directChild$4(numPr, "w:numId");
|
|
737
737
|
const numId = numIdElement === void 0 ? void 0 : (0, ooxml_js.attr)(numIdElement, "w:val");
|
|
738
738
|
if (numId === void 0) return;
|
|
739
|
-
const ilvlElement = directChild$
|
|
739
|
+
const ilvlElement = directChild$4(numPr, "w:ilvl");
|
|
740
740
|
const ilvl = ilvlElement === void 0 ? void 0 : (0, ooxml_js.attr)(ilvlElement, "w:val");
|
|
741
741
|
return {
|
|
742
742
|
numId,
|
|
@@ -746,7 +746,7 @@ var DocxParagraph = class {
|
|
|
746
746
|
set list(value) {
|
|
747
747
|
const pPr = this.pPr(true);
|
|
748
748
|
if (value === void 0) {
|
|
749
|
-
const existing = directChild$
|
|
749
|
+
const existing = directChild$4(pPr, "w:numPr");
|
|
750
750
|
if (existing !== void 0) removeChild(pPr.children, existing);
|
|
751
751
|
return;
|
|
752
752
|
}
|
|
@@ -764,7 +764,7 @@ var DocxParagraph = class {
|
|
|
764
764
|
this.removed = true;
|
|
765
765
|
}
|
|
766
766
|
};
|
|
767
|
-
function buildParagraph(init = {}) {
|
|
767
|
+
function buildParagraph$1(init = {}) {
|
|
768
768
|
const paragraph = el("w:p");
|
|
769
769
|
if (init.styleId !== void 0 || init.alignment !== void 0) {
|
|
770
770
|
const pPr = el("w:pPr");
|
|
@@ -772,7 +772,7 @@ function buildParagraph(init = {}) {
|
|
|
772
772
|
if (init.alignment !== void 0) pPr.children.push(el("w:jc", { "w:val": init.alignment === "justify" ? "both" : init.alignment }));
|
|
773
773
|
paragraph.children.push(pPr);
|
|
774
774
|
}
|
|
775
|
-
if (init.text !== void 0) paragraph.children.push(buildRun({ text: init.text }));
|
|
775
|
+
if (init.text !== void 0) paragraph.children.push(buildRun$1({ text: init.text }));
|
|
776
776
|
return paragraph;
|
|
777
777
|
}
|
|
778
778
|
//#endregion
|
|
@@ -780,7 +780,7 @@ function buildParagraph(init = {}) {
|
|
|
780
780
|
const CONTENT_TYPES_NS$1 = "http://schemas.openxmlformats.org/package/2006/content-types";
|
|
781
781
|
const RELS_NS$1 = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
782
782
|
const WORDML_NS = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
783
|
-
function declaration$
|
|
783
|
+
function declaration$2() {
|
|
784
784
|
return {
|
|
785
785
|
type: "declaration",
|
|
786
786
|
attributes: [
|
|
@@ -849,23 +849,23 @@ function createEmptyDocxPackage() {
|
|
|
849
849
|
return { parts: {
|
|
850
850
|
"[Content_Types].xml": {
|
|
851
851
|
kind: "xml",
|
|
852
|
-
nodes: [declaration$
|
|
852
|
+
nodes: [declaration$2(), contentTypes]
|
|
853
853
|
},
|
|
854
854
|
"_rels/.rels": {
|
|
855
855
|
kind: "xml",
|
|
856
|
-
nodes: [declaration$
|
|
856
|
+
nodes: [declaration$2(), rootRels]
|
|
857
857
|
},
|
|
858
858
|
"word/document.xml": {
|
|
859
859
|
kind: "xml",
|
|
860
|
-
nodes: [declaration$
|
|
860
|
+
nodes: [declaration$2(), document]
|
|
861
861
|
},
|
|
862
862
|
"word/_rels/document.xml.rels": {
|
|
863
863
|
kind: "xml",
|
|
864
|
-
nodes: [declaration$
|
|
864
|
+
nodes: [declaration$2(), documentRels]
|
|
865
865
|
},
|
|
866
866
|
"word/styles.xml": {
|
|
867
867
|
kind: "xml",
|
|
868
|
-
nodes: [declaration$
|
|
868
|
+
nodes: [declaration$2(), styles]
|
|
869
869
|
}
|
|
870
870
|
} };
|
|
871
871
|
}
|
|
@@ -883,7 +883,7 @@ var DocxTableCell = class {
|
|
|
883
883
|
return out;
|
|
884
884
|
}
|
|
885
885
|
appendParagraph(init) {
|
|
886
|
-
const paragraphElement = buildParagraph(init);
|
|
886
|
+
const paragraphElement = buildParagraph$1(init);
|
|
887
887
|
this.node.children.push(paragraphElement);
|
|
888
888
|
return new DocxParagraph(this.node.children, paragraphElement);
|
|
889
889
|
}
|
|
@@ -902,8 +902,8 @@ var DocxTableRow = class {
|
|
|
902
902
|
return out;
|
|
903
903
|
}
|
|
904
904
|
};
|
|
905
|
-
function buildCell() {
|
|
906
|
-
return el("w:tc", {}, [buildParagraph()]);
|
|
905
|
+
function buildCell$1() {
|
|
906
|
+
return el("w:tc", {}, [buildParagraph$1()]);
|
|
907
907
|
}
|
|
908
908
|
var DocxTable = class {
|
|
909
909
|
container;
|
|
@@ -932,7 +932,7 @@ var DocxTable = class {
|
|
|
932
932
|
appendRow(columnCount) {
|
|
933
933
|
const node = this.live();
|
|
934
934
|
const cells = [];
|
|
935
|
-
for (let i = 0; i < columnCount; i++) cells.push(buildCell());
|
|
935
|
+
for (let i = 0; i < columnCount; i++) cells.push(buildCell$1());
|
|
936
936
|
const row = el("w:tr", {}, cells);
|
|
937
937
|
node.children.push(row);
|
|
938
938
|
return new DocxTableRow(row);
|
|
@@ -951,11 +951,11 @@ function buildTblGrid(columns, columnWidthsTwips) {
|
|
|
951
951
|
}
|
|
952
952
|
return el("w:tblGrid", {}, cols);
|
|
953
953
|
}
|
|
954
|
-
function buildTable(init) {
|
|
954
|
+
function buildTable$1(init) {
|
|
955
955
|
const rows = [];
|
|
956
956
|
for (let r = 0; r < init.rows; r++) {
|
|
957
957
|
const cells = [];
|
|
958
|
-
for (let c = 0; c < init.columns; c++) cells.push(buildCell());
|
|
958
|
+
for (let c = 0; c < init.columns; c++) cells.push(buildCell$1());
|
|
959
959
|
rows.push(el("w:tr", {}, cells));
|
|
960
960
|
}
|
|
961
961
|
return el("w:tbl", {}, [buildTblGrid(init.columns, init.columnWidthsTwips), ...rows]);
|
|
@@ -992,19 +992,19 @@ var DocxBodyImpl = class {
|
|
|
992
992
|
this.imageContext = imageContext;
|
|
993
993
|
}
|
|
994
994
|
appendParagraph(init) {
|
|
995
|
-
const paragraphElement = buildParagraph(init);
|
|
995
|
+
const paragraphElement = buildParagraph$1(init);
|
|
996
996
|
this.body.children.splice(bodyInsertionPoint(this.body), 0, paragraphElement);
|
|
997
997
|
return new DocxParagraph(this.body.children, paragraphElement, this.imageContext);
|
|
998
998
|
}
|
|
999
999
|
insertParagraphAt(index, init) {
|
|
1000
|
-
const paragraphElement = buildParagraph(init);
|
|
1000
|
+
const paragraphElement = buildParagraph$1(init);
|
|
1001
1001
|
const indices = bodyElementIndicesByTag(this.body, "w:p");
|
|
1002
1002
|
const insertAt = index < indices.length ? indices[index] ?? bodyInsertionPoint(this.body) : bodyInsertionPoint(this.body);
|
|
1003
1003
|
this.body.children.splice(insertAt, 0, paragraphElement);
|
|
1004
1004
|
return new DocxParagraph(this.body.children, paragraphElement, this.imageContext);
|
|
1005
1005
|
}
|
|
1006
1006
|
appendTable(init) {
|
|
1007
|
-
const tableElement = buildTable(init);
|
|
1007
|
+
const tableElement = buildTable$1(init);
|
|
1008
1008
|
this.body.children.splice(bodyInsertionPoint(this.body), 0, tableElement);
|
|
1009
1009
|
return new DocxTable(this.body.children, tableElement);
|
|
1010
1010
|
}
|
|
@@ -1073,11 +1073,11 @@ function buildDocxPackage(content) {
|
|
|
1073
1073
|
const editor = createDocx();
|
|
1074
1074
|
content.sections.forEach((section, sectionIndex) => {
|
|
1075
1075
|
if (sectionIndex > 0) editor.body.appendPageBreak();
|
|
1076
|
-
for (const block of section.blocks) appendBlock(editor.body, block);
|
|
1076
|
+
for (const block of section.blocks) appendBlock$1(editor.body, block);
|
|
1077
1077
|
});
|
|
1078
1078
|
return editor.toPackage();
|
|
1079
1079
|
}
|
|
1080
|
-
function populateParagraph(paragraph, block) {
|
|
1080
|
+
function populateParagraph$1(paragraph, block) {
|
|
1081
1081
|
paragraph.styleId = block.styleId;
|
|
1082
1082
|
paragraph.alignment = block.alignment;
|
|
1083
1083
|
for (const run of block.runs) {
|
|
@@ -1094,7 +1094,7 @@ function populateParagraph(paragraph, block) {
|
|
|
1094
1094
|
if (run.color !== void 0) docxRun.color = run.color;
|
|
1095
1095
|
}
|
|
1096
1096
|
}
|
|
1097
|
-
function appendTable(body, block) {
|
|
1097
|
+
function appendTable$1(body, block) {
|
|
1098
1098
|
const columns = block.columnWidthsPt.length;
|
|
1099
1099
|
if (block.rows.length === 0 || columns === 0) return;
|
|
1100
1100
|
const table = body.appendTable({
|
|
@@ -1110,17 +1110,17 @@ function appendTable(body, block) {
|
|
|
1110
1110
|
if (tableCell === void 0) return;
|
|
1111
1111
|
const [firstBlock, ...restBlocks] = cell.blocks;
|
|
1112
1112
|
const firstParagraph = tableCell.paragraphs()[0];
|
|
1113
|
-
if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock);
|
|
1114
|
-
else if (firstBlock !== void 0) appendCellBlock(tableCell, firstBlock);
|
|
1115
|
-
for (const remaining of restBlocks) appendCellBlock(tableCell, remaining);
|
|
1113
|
+
if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph$1(firstParagraph, firstBlock);
|
|
1114
|
+
else if (firstBlock !== void 0) appendCellBlock$1(tableCell, firstBlock);
|
|
1115
|
+
for (const remaining of restBlocks) appendCellBlock$1(tableCell, remaining);
|
|
1116
1116
|
});
|
|
1117
1117
|
});
|
|
1118
1118
|
}
|
|
1119
|
-
function appendCellBlock(cell, block) {
|
|
1120
|
-
if (block.kind === "paragraph") populateParagraph(cell.appendParagraph(), block);
|
|
1119
|
+
function appendCellBlock$1(cell, block) {
|
|
1120
|
+
if (block.kind === "paragraph") populateParagraph$1(cell.appendParagraph(), block);
|
|
1121
1121
|
}
|
|
1122
|
-
function appendBlock(body, block) {
|
|
1123
|
-
if (block.kind === "paragraph") populateParagraph(body.appendParagraph(), block);
|
|
1122
|
+
function appendBlock$1(body, block) {
|
|
1123
|
+
if (block.kind === "paragraph") populateParagraph$1(body.appendParagraph(), block);
|
|
1124
1124
|
else if (block.kind === "image") body.appendParagraph().insertImageAfter({
|
|
1125
1125
|
format: block.format,
|
|
1126
1126
|
bytes: (0, ooxml_js.base64ToBytes)(block.base64),
|
|
@@ -1129,7 +1129,7 @@ function appendBlock(body, block) {
|
|
|
1129
1129
|
altText: block.altText
|
|
1130
1130
|
});
|
|
1131
1131
|
else if (block.kind === "pageBreak") body.appendPageBreak();
|
|
1132
|
-
else if (block.kind === "table") appendTable(body, block);
|
|
1132
|
+
else if (block.kind === "table") appendTable$1(body, block);
|
|
1133
1133
|
}
|
|
1134
1134
|
//#endregion
|
|
1135
1135
|
//#region src/edit/pptx/scaffold.ts
|
|
@@ -1156,7 +1156,7 @@ const SLIDE_LAYOUT_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/
|
|
|
1156
1156
|
const THEME_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
|
|
1157
1157
|
const NOTES_MASTER_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster";
|
|
1158
1158
|
const MIN_MASTER_OR_LAYOUT_ID = 2147483648;
|
|
1159
|
-
function declaration() {
|
|
1159
|
+
function declaration$1() {
|
|
1160
1160
|
return {
|
|
1161
1161
|
type: "declaration",
|
|
1162
1162
|
attributes: [
|
|
@@ -1306,7 +1306,7 @@ function ensureNotesMaster(pkg) {
|
|
|
1306
1306
|
});
|
|
1307
1307
|
pkg.parts[NOTES_MASTER_PART_PATH] = {
|
|
1308
1308
|
kind: "xml",
|
|
1309
|
-
nodes: [declaration(), buildNotesMaster()]
|
|
1309
|
+
nodes: [declaration$1(), buildNotesMaster()]
|
|
1310
1310
|
};
|
|
1311
1311
|
ensureContentTypeOverride(pkg, NOTES_MASTER_PART_PATH, NOTES_MASTER_CONTENT_TYPE);
|
|
1312
1312
|
const presentationToNotesMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, NOTES_MASTER_PART_PATH);
|
|
@@ -1345,15 +1345,15 @@ function createEmptyPptxPackage() {
|
|
|
1345
1345
|
const pkg = { parts: {
|
|
1346
1346
|
"[Content_Types].xml": {
|
|
1347
1347
|
kind: "xml",
|
|
1348
|
-
nodes: [declaration(), contentTypes]
|
|
1348
|
+
nodes: [declaration$1(), contentTypes]
|
|
1349
1349
|
},
|
|
1350
1350
|
"_rels/.rels": {
|
|
1351
1351
|
kind: "xml",
|
|
1352
|
-
nodes: [declaration(), rootRels]
|
|
1352
|
+
nodes: [declaration$1(), rootRels]
|
|
1353
1353
|
},
|
|
1354
1354
|
[PRESENTATION_PART_PATH$1]: {
|
|
1355
1355
|
kind: "xml",
|
|
1356
|
-
nodes: [declaration(), el("p:presentation", {
|
|
1356
|
+
nodes: [declaration$1(), el("p:presentation", {
|
|
1357
1357
|
"xmlns:p": PML_NS,
|
|
1358
1358
|
"xmlns:r": R_NS
|
|
1359
1359
|
})]
|
|
@@ -1366,7 +1366,7 @@ function createEmptyPptxPackage() {
|
|
|
1366
1366
|
});
|
|
1367
1367
|
pkg.parts[SLIDE_LAYOUT_PART_PATH] = {
|
|
1368
1368
|
kind: "xml",
|
|
1369
|
-
nodes: [declaration(), buildSlideLayout()]
|
|
1369
|
+
nodes: [declaration$1(), buildSlideLayout()]
|
|
1370
1370
|
};
|
|
1371
1371
|
ensureContentTypeOverride(pkg, SLIDE_LAYOUT_PART_PATH, SLIDE_LAYOUT_CONTENT_TYPE);
|
|
1372
1372
|
const masterToLayoutTarget = buildRelativeTarget(SLIDE_MASTER_PART_PATH, SLIDE_LAYOUT_PART_PATH);
|
|
@@ -1381,12 +1381,12 @@ function createEmptyPptxPackage() {
|
|
|
1381
1381
|
});
|
|
1382
1382
|
pkg.parts[SLIDE_MASTER_PART_PATH] = {
|
|
1383
1383
|
kind: "xml",
|
|
1384
|
-
nodes: [declaration(), buildSlideMaster(masterToLayoutRelId)]
|
|
1384
|
+
nodes: [declaration$1(), buildSlideMaster(masterToLayoutRelId)]
|
|
1385
1385
|
};
|
|
1386
1386
|
ensureContentTypeOverride(pkg, SLIDE_MASTER_PART_PATH, SLIDE_MASTER_CONTENT_TYPE);
|
|
1387
1387
|
pkg.parts[THEME_PART_PATH] = {
|
|
1388
1388
|
kind: "xml",
|
|
1389
|
-
nodes: [declaration(), buildTheme()]
|
|
1389
|
+
nodes: [declaration$1(), buildTheme()]
|
|
1390
1390
|
};
|
|
1391
1391
|
ensureContentTypeOverride(pkg, THEME_PART_PATH, THEME_CONTENT_TYPE);
|
|
1392
1392
|
const presentationToMasterTarget = buildRelativeTarget(PRESENTATION_PART_PATH$1, SLIDE_MASTER_PART_PATH);
|
|
@@ -1411,7 +1411,7 @@ function createEmptyPptxPackage() {
|
|
|
1411
1411
|
}
|
|
1412
1412
|
//#endregion
|
|
1413
1413
|
//#region src/edit/pptx/shape.ts
|
|
1414
|
-
function directChild$
|
|
1414
|
+
function directChild$3(parent, tag) {
|
|
1415
1415
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
1416
1416
|
}
|
|
1417
1417
|
function parseEmuAttr(element, name) {
|
|
@@ -1432,7 +1432,7 @@ var PptxShape = class {
|
|
|
1432
1432
|
}
|
|
1433
1433
|
spPrElement(create) {
|
|
1434
1434
|
const node = this.live();
|
|
1435
|
-
const existing = directChild$
|
|
1435
|
+
const existing = directChild$3(node, "p:spPr");
|
|
1436
1436
|
if (existing !== void 0 || !create) return existing;
|
|
1437
1437
|
const created = el("p:spPr");
|
|
1438
1438
|
node.children.push(created);
|
|
@@ -1440,10 +1440,10 @@ var PptxShape = class {
|
|
|
1440
1440
|
}
|
|
1441
1441
|
get frame() {
|
|
1442
1442
|
const spPr = this.spPrElement(false);
|
|
1443
|
-
const xfrm = spPr === void 0 ? void 0 : directChild$
|
|
1443
|
+
const xfrm = spPr === void 0 ? void 0 : directChild$3(spPr, "a:xfrm");
|
|
1444
1444
|
if (xfrm === void 0) return;
|
|
1445
|
-
const off = directChild$
|
|
1446
|
-
const ext = directChild$
|
|
1445
|
+
const off = directChild$3(xfrm, "a:off");
|
|
1446
|
+
const ext = directChild$3(xfrm, "a:ext");
|
|
1447
1447
|
if (off === void 0 || ext === void 0) return;
|
|
1448
1448
|
const x = parseEmuAttr(off, "x");
|
|
1449
1449
|
const y = parseEmuAttr(off, "y");
|
|
@@ -1459,7 +1459,7 @@ var PptxShape = class {
|
|
|
1459
1459
|
}
|
|
1460
1460
|
set frame(value) {
|
|
1461
1461
|
const spPr = this.spPrElement(true);
|
|
1462
|
-
let xfrm = directChild$
|
|
1462
|
+
let xfrm = directChild$3(spPr, "a:xfrm");
|
|
1463
1463
|
if (xfrm === void 0) {
|
|
1464
1464
|
xfrm = el("a:xfrm");
|
|
1465
1465
|
spPr.children.unshift(xfrm);
|
|
@@ -1473,12 +1473,12 @@ var PptxShape = class {
|
|
|
1473
1473
|
})];
|
|
1474
1474
|
}
|
|
1475
1475
|
get text() {
|
|
1476
|
-
const txBody = directChild$
|
|
1476
|
+
const txBody = directChild$3(this.live(), "p:txBody");
|
|
1477
1477
|
return txBody === void 0 ? "" : (0, ooxml_js.textContent)(txBody);
|
|
1478
1478
|
}
|
|
1479
1479
|
set text(value) {
|
|
1480
1480
|
const node = this.live();
|
|
1481
|
-
let txBody = directChild$
|
|
1481
|
+
let txBody = directChild$3(node, "p:txBody");
|
|
1482
1482
|
if (txBody === void 0) {
|
|
1483
1483
|
txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
|
|
1484
1484
|
node.children.push(txBody);
|
|
@@ -1489,7 +1489,7 @@ var PptxShape = class {
|
|
|
1489
1489
|
}
|
|
1490
1490
|
setParagraphs(paragraphs) {
|
|
1491
1491
|
const node = this.live();
|
|
1492
|
-
let txBody = directChild$
|
|
1492
|
+
let txBody = directChild$3(node, "p:txBody");
|
|
1493
1493
|
if (txBody === void 0) {
|
|
1494
1494
|
txBody = el("p:txBody", {}, [el("a:bodyPr"), el("a:lstStyle")]);
|
|
1495
1495
|
node.children.push(txBody);
|
|
@@ -1600,12 +1600,12 @@ function insertPictureShapeMedia(context, slideRoot, frame, image) {
|
|
|
1600
1600
|
}
|
|
1601
1601
|
//#endregion
|
|
1602
1602
|
//#region src/edit/pptx/slide.ts
|
|
1603
|
-
function directChild$
|
|
1603
|
+
function directChild$2(parent, tag) {
|
|
1604
1604
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
1605
1605
|
}
|
|
1606
1606
|
function findSpTree(slideRoot) {
|
|
1607
|
-
const cSld = directChild$
|
|
1608
|
-
const spTree = cSld === void 0 ? void 0 : directChild$
|
|
1607
|
+
const cSld = directChild$2(slideRoot, "p:cSld");
|
|
1608
|
+
const spTree = cSld === void 0 ? void 0 : directChild$2(cSld, "p:spTree");
|
|
1609
1609
|
if (spTree === void 0) throw new Error("slide has no p:cSld/p:spTree element");
|
|
1610
1610
|
return spTree;
|
|
1611
1611
|
}
|
|
@@ -1737,7 +1737,7 @@ const PRESENTATION_PART_PATH = "ppt/presentation.xml";
|
|
|
1737
1737
|
const MEDIA_DIR = "ppt/media";
|
|
1738
1738
|
const SLIDE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
|
|
1739
1739
|
const SLIDE_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide";
|
|
1740
|
-
function directChild(parent, tag) {
|
|
1740
|
+
function directChild$1(parent, tag) {
|
|
1741
1741
|
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
1742
1742
|
}
|
|
1743
1743
|
function attrValue(element, name) {
|
|
@@ -1749,12 +1749,12 @@ function findPresentationRoot(pkg) {
|
|
|
1749
1749
|
return root;
|
|
1750
1750
|
}
|
|
1751
1751
|
function findSldIdLst(presentationRoot) {
|
|
1752
|
-
const sldIdLst = directChild(presentationRoot, "p:sldIdLst");
|
|
1752
|
+
const sldIdLst = directChild$1(presentationRoot, "p:sldIdLst");
|
|
1753
1753
|
if (sldIdLst === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldIdLst element`);
|
|
1754
1754
|
return sldIdLst;
|
|
1755
1755
|
}
|
|
1756
1756
|
function findSldSz(presentationRoot) {
|
|
1757
|
-
const sldSz = directChild(presentationRoot, "p:sldSz");
|
|
1757
|
+
const sldSz = directChild$1(presentationRoot, "p:sldSz");
|
|
1758
1758
|
if (sldSz === void 0) throw new Error(`${PRESENTATION_PART_PATH} has no p:sldSz element`);
|
|
1759
1759
|
return sldSz;
|
|
1760
1760
|
}
|
|
@@ -1952,6 +1952,697 @@ function appendShape(slide, shape) {
|
|
|
1952
1952
|
}).setParagraphs(paragraphs);
|
|
1953
1953
|
}
|
|
1954
1954
|
//#endregion
|
|
1955
|
+
//#region src/edit/odt/automatic-styles.ts
|
|
1956
|
+
const CONTENT_PART_PATH$1 = "content.xml";
|
|
1957
|
+
function ensureAutomaticStyles(pkg) {
|
|
1958
|
+
const part = pkg.parts[CONTENT_PART_PATH$1];
|
|
1959
|
+
if (part?.kind !== "xml") throw new Error(`ensureAutomaticStyles: package has no ${CONTENT_PART_PATH$1} part`);
|
|
1960
|
+
const root = part.nodes.find((n) => n.type === "element");
|
|
1961
|
+
if (root === void 0) throw new Error(`ensureAutomaticStyles: ${CONTENT_PART_PATH$1} has no root element`);
|
|
1962
|
+
for (const child of root.children) if (child.type === "element" && child.tag === "office:automatic-styles") return child;
|
|
1963
|
+
const created = el("office:automatic-styles");
|
|
1964
|
+
const insertBeforeTags = /* @__PURE__ */ new Set([
|
|
1965
|
+
"office:body",
|
|
1966
|
+
"office:master-styles",
|
|
1967
|
+
"office:settings"
|
|
1968
|
+
]);
|
|
1969
|
+
const insertIndex = root.children.findIndex((n) => n.type === "element" && insertBeforeTags.has(n.tag));
|
|
1970
|
+
if (insertIndex === -1) root.children.push(created);
|
|
1971
|
+
else root.children.splice(insertIndex, 0, created);
|
|
1972
|
+
return created;
|
|
1973
|
+
}
|
|
1974
|
+
function nextStyleName(automaticStyles, tag, prefix) {
|
|
1975
|
+
let max = 0;
|
|
1976
|
+
for (const child of automaticStyles.children) {
|
|
1977
|
+
if (child.type !== "element" || child.tag !== tag) continue;
|
|
1978
|
+
const name = (0, ooxml_js.attr)(child, "style:name");
|
|
1979
|
+
if (!name?.startsWith(prefix)) continue;
|
|
1980
|
+
const rest = name.slice(prefix.length);
|
|
1981
|
+
const n = Number.parseInt(rest, 10);
|
|
1982
|
+
if (!Number.isNaN(n) && String(n) === rest && n > max) max = n;
|
|
1983
|
+
}
|
|
1984
|
+
return `${prefix}${max + 1}`;
|
|
1985
|
+
}
|
|
1986
|
+
const PAGE_BREAK_STYLE_NAME = "OdtPageBreak";
|
|
1987
|
+
function ensurePageBreakStyleName(pkg) {
|
|
1988
|
+
const automaticStyles = ensureAutomaticStyles(pkg);
|
|
1989
|
+
if (automaticStyles.children.find((c) => c.type === "element" && c.tag === "style:style" && (0, ooxml_js.attr)(c, "style:name") === PAGE_BREAK_STYLE_NAME) !== void 0) return PAGE_BREAK_STYLE_NAME;
|
|
1990
|
+
automaticStyles.children.push(el("style:style", {
|
|
1991
|
+
"style:name": PAGE_BREAK_STYLE_NAME,
|
|
1992
|
+
"style:family": "paragraph"
|
|
1993
|
+
}, [el("style:paragraph-properties", { "fo:break-before": "page" })]));
|
|
1994
|
+
return PAGE_BREAK_STYLE_NAME;
|
|
1995
|
+
}
|
|
1996
|
+
//#endregion
|
|
1997
|
+
//#region src/xml/odf-text.ts
|
|
1998
|
+
const MIN_SPACE_RUN_FOR_TEXT_S = 2;
|
|
1999
|
+
function encodeOdfText(text) {
|
|
2000
|
+
const nodes = [];
|
|
2001
|
+
let literal = "";
|
|
2002
|
+
const flushLiteral = () => {
|
|
2003
|
+
if (literal.length > 0) {
|
|
2004
|
+
nodes.push(txt(encodeXmlText(literal)));
|
|
2005
|
+
literal = "";
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
let i = 0;
|
|
2009
|
+
while (i < text.length) {
|
|
2010
|
+
const ch = text[i];
|
|
2011
|
+
if (ch === " ") {
|
|
2012
|
+
let runLength = 1;
|
|
2013
|
+
while (i + runLength < text.length && text[i + runLength] === " ") runLength += 1;
|
|
2014
|
+
if (runLength >= MIN_SPACE_RUN_FOR_TEXT_S) {
|
|
2015
|
+
flushLiteral();
|
|
2016
|
+
nodes.push(el("text:s", { "text:c": String(runLength) }));
|
|
2017
|
+
} else literal += " ";
|
|
2018
|
+
i += runLength;
|
|
2019
|
+
continue;
|
|
2020
|
+
}
|
|
2021
|
+
if (ch === " ") {
|
|
2022
|
+
flushLiteral();
|
|
2023
|
+
nodes.push(el("text:tab"));
|
|
2024
|
+
i += 1;
|
|
2025
|
+
continue;
|
|
2026
|
+
}
|
|
2027
|
+
if (ch === "\n") {
|
|
2028
|
+
flushLiteral();
|
|
2029
|
+
nodes.push(el("text:line-break"));
|
|
2030
|
+
i += 1;
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
literal += ch;
|
|
2034
|
+
i += 1;
|
|
2035
|
+
}
|
|
2036
|
+
flushLiteral();
|
|
2037
|
+
return nodes;
|
|
2038
|
+
}
|
|
2039
|
+
function decodeOdfText(nodes) {
|
|
2040
|
+
const wrapper = el("_odf-text-container", {}, [...nodes]);
|
|
2041
|
+
return (0, odf_js.decodeOdfText)(wrapper);
|
|
2042
|
+
}
|
|
2043
|
+
//#endregion
|
|
2044
|
+
//#region src/edit/odt/props.ts
|
|
2045
|
+
const STYLE_NAME_ATTR = "text:style-name";
|
|
2046
|
+
function readCurrentStyleProperties(pkg, element, family) {
|
|
2047
|
+
const styleName = (0, ooxml_js.attr)(element, STYLE_NAME_ATTR);
|
|
2048
|
+
return (0, odf_js.resolveStyle)(styleName, family, pkg).properties;
|
|
2049
|
+
}
|
|
2050
|
+
function applyStyleChange(pkg, element, family, change) {
|
|
2051
|
+
const merged = {
|
|
2052
|
+
...readCurrentStyleProperties(pkg, element, family),
|
|
2053
|
+
...change
|
|
2054
|
+
};
|
|
2055
|
+
const name = odf_js.StyleRegistry.forPart(pkg, CONTENT_PART_PATH$1).intern({
|
|
2056
|
+
family,
|
|
2057
|
+
properties: merged
|
|
2058
|
+
});
|
|
2059
|
+
setAttr(element, STYLE_NAME_ATTR, name);
|
|
2060
|
+
}
|
|
2061
|
+
//#endregion
|
|
2062
|
+
//#region src/edit/odt/run.ts
|
|
2063
|
+
var OdtRun = class {
|
|
2064
|
+
container;
|
|
2065
|
+
node;
|
|
2066
|
+
pkg;
|
|
2067
|
+
removed = false;
|
|
2068
|
+
constructor(container, node, pkg) {
|
|
2069
|
+
this.container = container;
|
|
2070
|
+
this.node = node;
|
|
2071
|
+
this.pkg = pkg;
|
|
2072
|
+
}
|
|
2073
|
+
live() {
|
|
2074
|
+
if (this.removed) throw new Error("this OdtRun has been removed from its paragraph and can no longer be used");
|
|
2075
|
+
return this.node;
|
|
2076
|
+
}
|
|
2077
|
+
get text() {
|
|
2078
|
+
return decodeOdfText(this.live().children);
|
|
2079
|
+
}
|
|
2080
|
+
set text(value) {
|
|
2081
|
+
this.live().children = encodeOdfText(value);
|
|
2082
|
+
}
|
|
2083
|
+
get bold() {
|
|
2084
|
+
return readCurrentStyleProperties(this.pkg, this.live(), "text").bold ?? false;
|
|
2085
|
+
}
|
|
2086
|
+
set bold(value) {
|
|
2087
|
+
applyStyleChange(this.pkg, this.live(), "text", { bold: value });
|
|
2088
|
+
}
|
|
2089
|
+
get italic() {
|
|
2090
|
+
return readCurrentStyleProperties(this.pkg, this.live(), "text").italic ?? false;
|
|
2091
|
+
}
|
|
2092
|
+
set italic(value) {
|
|
2093
|
+
applyStyleChange(this.pkg, this.live(), "text", { italic: value });
|
|
2094
|
+
}
|
|
2095
|
+
get underline() {
|
|
2096
|
+
return readCurrentStyleProperties(this.pkg, this.live(), "text").underline ?? false;
|
|
2097
|
+
}
|
|
2098
|
+
set underline(value) {
|
|
2099
|
+
applyStyleChange(this.pkg, this.live(), "text", { underline: value });
|
|
2100
|
+
}
|
|
2101
|
+
get fontFamily() {
|
|
2102
|
+
return readCurrentStyleProperties(this.pkg, this.live(), "text").fontFamily;
|
|
2103
|
+
}
|
|
2104
|
+
set fontFamily(value) {
|
|
2105
|
+
applyStyleChange(this.pkg, this.live(), "text", { fontFamily: value });
|
|
2106
|
+
}
|
|
2107
|
+
get sizePt() {
|
|
2108
|
+
return readCurrentStyleProperties(this.pkg, this.live(), "text").sizePt;
|
|
2109
|
+
}
|
|
2110
|
+
set sizePt(value) {
|
|
2111
|
+
applyStyleChange(this.pkg, this.live(), "text", { sizePt: value });
|
|
2112
|
+
}
|
|
2113
|
+
get color() {
|
|
2114
|
+
return readCurrentStyleProperties(this.pkg, this.live(), "text").color;
|
|
2115
|
+
}
|
|
2116
|
+
set color(value) {
|
|
2117
|
+
applyStyleChange(this.pkg, this.live(), "text", { color: value });
|
|
2118
|
+
}
|
|
2119
|
+
remove() {
|
|
2120
|
+
removeChild(this.container, this.live());
|
|
2121
|
+
this.removed = true;
|
|
2122
|
+
}
|
|
2123
|
+
};
|
|
2124
|
+
function buildRun(pkg, init = {}) {
|
|
2125
|
+
const node = el("text:span");
|
|
2126
|
+
if (init.text !== void 0) node.children = encodeOdfText(init.text);
|
|
2127
|
+
const run = new OdtRun([], node, pkg);
|
|
2128
|
+
if (init.bold !== void 0) run.bold = init.bold;
|
|
2129
|
+
if (init.italic !== void 0) run.italic = init.italic;
|
|
2130
|
+
if (init.underline !== void 0) run.underline = init.underline;
|
|
2131
|
+
if (init.fontFamily !== void 0) run.fontFamily = init.fontFamily;
|
|
2132
|
+
if (init.sizePt !== void 0) run.sizePt = init.sizePt;
|
|
2133
|
+
if (init.color !== void 0) run.color = init.color;
|
|
2134
|
+
return node;
|
|
2135
|
+
}
|
|
2136
|
+
//#endregion
|
|
2137
|
+
//#region src/edit/odt/paragraph.ts
|
|
2138
|
+
var OdtParagraph = class {
|
|
2139
|
+
container;
|
|
2140
|
+
node;
|
|
2141
|
+
pkg;
|
|
2142
|
+
removed = false;
|
|
2143
|
+
constructor(container, node, pkg) {
|
|
2144
|
+
this.container = container;
|
|
2145
|
+
this.node = node;
|
|
2146
|
+
this.pkg = pkg;
|
|
2147
|
+
}
|
|
2148
|
+
live() {
|
|
2149
|
+
if (this.removed) throw new Error("this OdtParagraph has been removed from its body and can no longer be used");
|
|
2150
|
+
return this.node;
|
|
2151
|
+
}
|
|
2152
|
+
get text() {
|
|
2153
|
+
return decodeOdfText(this.live().children);
|
|
2154
|
+
}
|
|
2155
|
+
runs() {
|
|
2156
|
+
const node = this.live();
|
|
2157
|
+
const out = [];
|
|
2158
|
+
for (const child of node.children) if (child.type === "element" && child.tag === "text:span") out.push(new OdtRun(node.children, child, this.pkg));
|
|
2159
|
+
return out;
|
|
2160
|
+
}
|
|
2161
|
+
appendRun(init) {
|
|
2162
|
+
const node = this.live();
|
|
2163
|
+
const span = buildRun(this.pkg, init);
|
|
2164
|
+
node.children.push(span);
|
|
2165
|
+
return new OdtRun(node.children, span, this.pkg);
|
|
2166
|
+
}
|
|
2167
|
+
appendTab() {
|
|
2168
|
+
this.live().children.push(el("text:tab"));
|
|
2169
|
+
}
|
|
2170
|
+
insertRunAt(index, init) {
|
|
2171
|
+
const node = this.live();
|
|
2172
|
+
const span = buildRun(this.pkg, init);
|
|
2173
|
+
const spanIndices = [];
|
|
2174
|
+
node.children.forEach((child, i) => {
|
|
2175
|
+
if (child.type === "element" && child.tag === "text:span") spanIndices.push(i);
|
|
2176
|
+
});
|
|
2177
|
+
const insertAt = index < spanIndices.length ? spanIndices[index] ?? node.children.length : node.children.length;
|
|
2178
|
+
node.children.splice(insertAt, 0, span);
|
|
2179
|
+
return new OdtRun(node.children, span, this.pkg);
|
|
2180
|
+
}
|
|
2181
|
+
get styleId() {
|
|
2182
|
+
return (0, ooxml_js.attr)(this.live(), "text:style-name");
|
|
2183
|
+
}
|
|
2184
|
+
set styleId(value) {
|
|
2185
|
+
const node = this.live();
|
|
2186
|
+
if (value === void 0) {
|
|
2187
|
+
removeAttr(node, "text:style-name");
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2190
|
+
setAttr(node, "text:style-name", value);
|
|
2191
|
+
}
|
|
2192
|
+
get alignment() {
|
|
2193
|
+
return readCurrentStyleProperties(this.pkg, this.live(), "paragraph").alignment;
|
|
2194
|
+
}
|
|
2195
|
+
set alignment(value) {
|
|
2196
|
+
applyStyleChange(this.pkg, this.live(), "paragraph", { alignment: value });
|
|
2197
|
+
}
|
|
2198
|
+
remove() {
|
|
2199
|
+
removeChild(this.container, this.live());
|
|
2200
|
+
this.removed = true;
|
|
2201
|
+
}
|
|
2202
|
+
};
|
|
2203
|
+
function buildParagraph(pkg, init = {}) {
|
|
2204
|
+
const node = el("text:p");
|
|
2205
|
+
const paragraph = new OdtParagraph([], node, pkg);
|
|
2206
|
+
if (init.styleId !== void 0) paragraph.styleId = init.styleId;
|
|
2207
|
+
if (init.alignment !== void 0) paragraph.alignment = init.alignment;
|
|
2208
|
+
if (init.text !== void 0) node.children.push(buildRun(pkg, { text: init.text }));
|
|
2209
|
+
return node;
|
|
2210
|
+
}
|
|
2211
|
+
//#endregion
|
|
2212
|
+
//#region src/edit/odt/list.ts
|
|
2213
|
+
const LIST_STYLE_PREFIX = "OdtList";
|
|
2214
|
+
const MAX_LIST_LEVELS = 10;
|
|
2215
|
+
const LIST_LEVEL_INDENT_PT = 18;
|
|
2216
|
+
const LIST_LEVEL_LABEL_WIDTH_PT = 18;
|
|
2217
|
+
function buildBulletListStyle(name) {
|
|
2218
|
+
const levels = [];
|
|
2219
|
+
for (let level = 1; level <= MAX_LIST_LEVELS; level++) levels.push(el("text:list-level-style-bullet", {
|
|
2220
|
+
"text:level": String(level),
|
|
2221
|
+
"text:bullet-char": "•"
|
|
2222
|
+
}, [el("style:list-level-properties", {
|
|
2223
|
+
"text:space-before": (0, odf_js.formatOdfLength)(LIST_LEVEL_INDENT_PT * (level - 1), "pt"),
|
|
2224
|
+
"text:min-label-width": (0, odf_js.formatOdfLength)(LIST_LEVEL_LABEL_WIDTH_PT, "pt")
|
|
2225
|
+
})]));
|
|
2226
|
+
return el("text:list-style", { "style:name": name }, levels);
|
|
2227
|
+
}
|
|
2228
|
+
function internBulletListStyle(pkg) {
|
|
2229
|
+
const automaticStyles = ensureAutomaticStyles(pkg);
|
|
2230
|
+
const name = nextStyleName(automaticStyles, "text:list-style", LIST_STYLE_PREFIX);
|
|
2231
|
+
automaticStyles.children.push(buildBulletListStyle(name));
|
|
2232
|
+
return name;
|
|
2233
|
+
}
|
|
2234
|
+
var OdtListItem = class {
|
|
2235
|
+
node;
|
|
2236
|
+
pkg;
|
|
2237
|
+
constructor(node, pkg) {
|
|
2238
|
+
this.node = node;
|
|
2239
|
+
this.pkg = pkg;
|
|
2240
|
+
}
|
|
2241
|
+
appendParagraph(init) {
|
|
2242
|
+
const paragraphElement = buildParagraph(this.pkg, init);
|
|
2243
|
+
this.node.children.push(paragraphElement);
|
|
2244
|
+
return new OdtParagraph(this.node.children, paragraphElement, this.pkg);
|
|
2245
|
+
}
|
|
2246
|
+
addNestedList() {
|
|
2247
|
+
const listElement = el("text:list", { "text:style-name": internBulletListStyle(this.pkg) });
|
|
2248
|
+
this.node.children.push(listElement);
|
|
2249
|
+
return new OdtList(this.node.children, listElement, this.pkg);
|
|
2250
|
+
}
|
|
2251
|
+
};
|
|
2252
|
+
var OdtList = class {
|
|
2253
|
+
container;
|
|
2254
|
+
node;
|
|
2255
|
+
pkg;
|
|
2256
|
+
removed = false;
|
|
2257
|
+
constructor(container, node, pkg) {
|
|
2258
|
+
this.container = container;
|
|
2259
|
+
this.node = node;
|
|
2260
|
+
this.pkg = pkg;
|
|
2261
|
+
}
|
|
2262
|
+
live() {
|
|
2263
|
+
if (this.removed) throw new Error("this OdtList has been removed from its body and can no longer be used");
|
|
2264
|
+
return this.node;
|
|
2265
|
+
}
|
|
2266
|
+
items() {
|
|
2267
|
+
const out = [];
|
|
2268
|
+
for (const child of this.live().children) if (child.type === "element" && child.tag === "text:list-item") out.push(new OdtListItem(child, this.pkg));
|
|
2269
|
+
return out;
|
|
2270
|
+
}
|
|
2271
|
+
addItem() {
|
|
2272
|
+
const itemElement = el("text:list-item");
|
|
2273
|
+
this.live().children.push(itemElement);
|
|
2274
|
+
return new OdtListItem(itemElement, this.pkg);
|
|
2275
|
+
}
|
|
2276
|
+
remove() {
|
|
2277
|
+
removeChild(this.container, this.live());
|
|
2278
|
+
this.removed = true;
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
function buildList(pkg) {
|
|
2282
|
+
return el("text:list", { "text:style-name": internBulletListStyle(pkg) });
|
|
2283
|
+
}
|
|
2284
|
+
//#endregion
|
|
2285
|
+
//#region src/edit/odt/scaffold.ts
|
|
2286
|
+
const CONTENT_NS_PREFIXES = [
|
|
2287
|
+
"office",
|
|
2288
|
+
"style",
|
|
2289
|
+
"text",
|
|
2290
|
+
"table",
|
|
2291
|
+
"draw",
|
|
2292
|
+
"fo",
|
|
2293
|
+
"svg",
|
|
2294
|
+
"xlink"
|
|
2295
|
+
];
|
|
2296
|
+
const STYLES_NS_PREFIXES = [
|
|
2297
|
+
"office",
|
|
2298
|
+
"style",
|
|
2299
|
+
"text",
|
|
2300
|
+
"table",
|
|
2301
|
+
"draw",
|
|
2302
|
+
"fo",
|
|
2303
|
+
"svg",
|
|
2304
|
+
"xlink"
|
|
2305
|
+
];
|
|
2306
|
+
const META_NS_PREFIXES = [
|
|
2307
|
+
"office",
|
|
2308
|
+
"meta",
|
|
2309
|
+
"dc"
|
|
2310
|
+
];
|
|
2311
|
+
const ODF_VERSION = "1.3";
|
|
2312
|
+
const PAGE_LAYOUT_NAME = "PM1";
|
|
2313
|
+
const MASTER_PAGE_NAME = "Standard";
|
|
2314
|
+
const DEFAULT_MARGIN_PT = 72;
|
|
2315
|
+
function declaration() {
|
|
2316
|
+
return {
|
|
2317
|
+
type: "declaration",
|
|
2318
|
+
attributes: [
|
|
2319
|
+
{
|
|
2320
|
+
name: "version",
|
|
2321
|
+
value: "1.0"
|
|
2322
|
+
},
|
|
2323
|
+
{
|
|
2324
|
+
name: "encoding",
|
|
2325
|
+
value: "UTF-8"
|
|
2326
|
+
},
|
|
2327
|
+
{
|
|
2328
|
+
name: "standalone",
|
|
2329
|
+
value: "yes"
|
|
2330
|
+
}
|
|
2331
|
+
]
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
function buildPageLayout() {
|
|
2335
|
+
return el("style:page-layout", { "style:name": PAGE_LAYOUT_NAME }, [el("style:page-layout-properties", {
|
|
2336
|
+
"fo:page-width": `${document_content_model.PAGE_SIZE_LETTER.widthPt}pt`,
|
|
2337
|
+
"fo:page-height": `${document_content_model.PAGE_SIZE_LETTER.heightPt}pt`,
|
|
2338
|
+
"fo:margin-top": `${DEFAULT_MARGIN_PT}pt`,
|
|
2339
|
+
"fo:margin-right": `${DEFAULT_MARGIN_PT}pt`,
|
|
2340
|
+
"fo:margin-bottom": `${DEFAULT_MARGIN_PT}pt`,
|
|
2341
|
+
"fo:margin-left": `${DEFAULT_MARGIN_PT}pt`
|
|
2342
|
+
})]);
|
|
2343
|
+
}
|
|
2344
|
+
function buildStylesXml() {
|
|
2345
|
+
return el("office:document-styles", {
|
|
2346
|
+
...(0, odf_js.xmlnsAttributes)([...STYLES_NS_PREFIXES]),
|
|
2347
|
+
"office:version": ODF_VERSION
|
|
2348
|
+
}, [
|
|
2349
|
+
el("office:styles"),
|
|
2350
|
+
el("office:automatic-styles", {}, [buildPageLayout()]),
|
|
2351
|
+
el("office:master-styles", {}, [el("style:master-page", {
|
|
2352
|
+
"style:name": MASTER_PAGE_NAME,
|
|
2353
|
+
"style:page-layout-name": PAGE_LAYOUT_NAME
|
|
2354
|
+
})])
|
|
2355
|
+
]);
|
|
2356
|
+
}
|
|
2357
|
+
function buildContentXml() {
|
|
2358
|
+
return el("office:document-content", {
|
|
2359
|
+
...(0, odf_js.xmlnsAttributes)([...CONTENT_NS_PREFIXES]),
|
|
2360
|
+
"office:version": ODF_VERSION
|
|
2361
|
+
}, [el("office:automatic-styles"), el("office:body", {}, [el("office:text")])]);
|
|
2362
|
+
}
|
|
2363
|
+
function buildMetaXml() {
|
|
2364
|
+
return el("office:document-meta", {
|
|
2365
|
+
...(0, odf_js.xmlnsAttributes)([...META_NS_PREFIXES]),
|
|
2366
|
+
"office:version": ODF_VERSION
|
|
2367
|
+
}, [el("office:meta")]);
|
|
2368
|
+
}
|
|
2369
|
+
function createEmptyOdtPackage() {
|
|
2370
|
+
const pkg = { parts: {
|
|
2371
|
+
"content.xml": {
|
|
2372
|
+
kind: "xml",
|
|
2373
|
+
nodes: [declaration(), buildContentXml()]
|
|
2374
|
+
},
|
|
2375
|
+
"styles.xml": {
|
|
2376
|
+
kind: "xml",
|
|
2377
|
+
nodes: [declaration(), buildStylesXml()]
|
|
2378
|
+
},
|
|
2379
|
+
"meta.xml": {
|
|
2380
|
+
kind: "xml",
|
|
2381
|
+
nodes: [declaration(), buildMetaXml()]
|
|
2382
|
+
}
|
|
2383
|
+
} };
|
|
2384
|
+
(0, odf_js.setDocumentMediaType)(pkg, odf_js.ODF_MEDIA_TYPES.odt);
|
|
2385
|
+
(0, odf_js.syncManifest)(pkg);
|
|
2386
|
+
return pkg;
|
|
2387
|
+
}
|
|
2388
|
+
//#endregion
|
|
2389
|
+
//#region src/edit/odt/table.ts
|
|
2390
|
+
const DEFAULT_TABLE_WIDTH_PT = 468;
|
|
2391
|
+
const TABLE_COLUMN_STYLE_PREFIX = "OdtCol";
|
|
2392
|
+
function internTableColumnWidth(pkg, widthPt) {
|
|
2393
|
+
const automaticStyles = ensureAutomaticStyles(pkg);
|
|
2394
|
+
const formatted = (0, odf_js.formatOdfLength)(widthPt, "pt");
|
|
2395
|
+
for (const child of automaticStyles.children) {
|
|
2396
|
+
if (child.type !== "element" || child.tag !== "style:style" || (0, ooxml_js.attr)(child, "style:family") !== "table-column") continue;
|
|
2397
|
+
const props = child.children.find((c) => c.type === "element" && c.tag === "style:table-column-properties");
|
|
2398
|
+
if (props !== void 0 && (0, ooxml_js.attr)(props, "style:column-width") === formatted) {
|
|
2399
|
+
const existingName = (0, ooxml_js.attr)(child, "style:name");
|
|
2400
|
+
if (existingName !== void 0) return existingName;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
const name = nextStyleName(automaticStyles, "style:style", TABLE_COLUMN_STYLE_PREFIX);
|
|
2404
|
+
automaticStyles.children.push(el("style:style", {
|
|
2405
|
+
"style:name": name,
|
|
2406
|
+
"style:family": "table-column"
|
|
2407
|
+
}, [el("style:table-column-properties", { "style:column-width": formatted })]));
|
|
2408
|
+
return name;
|
|
2409
|
+
}
|
|
2410
|
+
var OdtTableCell = class {
|
|
2411
|
+
node;
|
|
2412
|
+
pkg;
|
|
2413
|
+
constructor(node, pkg) {
|
|
2414
|
+
this.node = node;
|
|
2415
|
+
this.pkg = pkg;
|
|
2416
|
+
}
|
|
2417
|
+
paragraphs() {
|
|
2418
|
+
const out = [];
|
|
2419
|
+
for (const child of this.node.children) if (child.type === "element" && child.tag === "text:p") out.push(new OdtParagraph(this.node.children, child, this.pkg));
|
|
2420
|
+
return out;
|
|
2421
|
+
}
|
|
2422
|
+
appendParagraph(init) {
|
|
2423
|
+
const paragraphElement = buildParagraph(this.pkg, init);
|
|
2424
|
+
this.node.children.push(paragraphElement);
|
|
2425
|
+
return new OdtParagraph(this.node.children, paragraphElement, this.pkg);
|
|
2426
|
+
}
|
|
2427
|
+
get text() {
|
|
2428
|
+
return this.paragraphs().map((p) => p.text).join("\n");
|
|
2429
|
+
}
|
|
2430
|
+
};
|
|
2431
|
+
var OdtTableRow = class {
|
|
2432
|
+
node;
|
|
2433
|
+
pkg;
|
|
2434
|
+
constructor(node, pkg) {
|
|
2435
|
+
this.node = node;
|
|
2436
|
+
this.pkg = pkg;
|
|
2437
|
+
}
|
|
2438
|
+
cells() {
|
|
2439
|
+
const out = [];
|
|
2440
|
+
for (const child of this.node.children) if (child.type === "element" && child.tag === "table:table-cell") out.push(new OdtTableCell(child, this.pkg));
|
|
2441
|
+
return out;
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2444
|
+
function buildCell(pkg) {
|
|
2445
|
+
return el("table:table-cell", {}, [buildParagraph(pkg)]);
|
|
2446
|
+
}
|
|
2447
|
+
function buildRow(pkg, columnCount) {
|
|
2448
|
+
const cells = [];
|
|
2449
|
+
for (let i = 0; i < columnCount; i++) cells.push(buildCell(pkg));
|
|
2450
|
+
return el("table:table-row", {}, cells);
|
|
2451
|
+
}
|
|
2452
|
+
var OdtTable = class {
|
|
2453
|
+
container;
|
|
2454
|
+
node;
|
|
2455
|
+
pkg;
|
|
2456
|
+
removed = false;
|
|
2457
|
+
constructor(container, node, pkg) {
|
|
2458
|
+
this.container = container;
|
|
2459
|
+
this.node = node;
|
|
2460
|
+
this.pkg = pkg;
|
|
2461
|
+
}
|
|
2462
|
+
live() {
|
|
2463
|
+
if (this.removed) throw new Error("this OdtTable has been removed and can no longer be used");
|
|
2464
|
+
return this.node;
|
|
2465
|
+
}
|
|
2466
|
+
rows() {
|
|
2467
|
+
const out = [];
|
|
2468
|
+
for (const child of this.live().children) if (child.type === "element" && child.tag === "table:table-row") out.push(new OdtTableRow(child, this.pkg));
|
|
2469
|
+
return out;
|
|
2470
|
+
}
|
|
2471
|
+
cell(rowIndex, columnIndex) {
|
|
2472
|
+
const row = this.rows()[rowIndex];
|
|
2473
|
+
if (row === void 0) throw new Error(`row ${rowIndex} does not exist in this table`);
|
|
2474
|
+
const cell = row.cells()[columnIndex];
|
|
2475
|
+
if (cell === void 0) throw new Error(`column ${columnIndex} does not exist in row ${rowIndex}`);
|
|
2476
|
+
return cell;
|
|
2477
|
+
}
|
|
2478
|
+
appendRow(columnCount) {
|
|
2479
|
+
const node = this.live();
|
|
2480
|
+
const row = buildRow(this.pkg, columnCount);
|
|
2481
|
+
node.children.push(row);
|
|
2482
|
+
return new OdtTableRow(row, this.pkg);
|
|
2483
|
+
}
|
|
2484
|
+
remove() {
|
|
2485
|
+
removeChild(this.container, this.live());
|
|
2486
|
+
this.removed = true;
|
|
2487
|
+
}
|
|
2488
|
+
};
|
|
2489
|
+
function buildTable(pkg, init) {
|
|
2490
|
+
const defaultWidth = DEFAULT_TABLE_WIDTH_PT / init.columns;
|
|
2491
|
+
const columns = [];
|
|
2492
|
+
for (let i = 0; i < init.columns; i++) {
|
|
2493
|
+
const widthPt = init.columnWidthsPt?.[i] ?? defaultWidth;
|
|
2494
|
+
columns.push(el("table:table-column", { "table:style-name": internTableColumnWidth(pkg, widthPt) }));
|
|
2495
|
+
}
|
|
2496
|
+
const rows = [];
|
|
2497
|
+
for (let r = 0; r < init.rows; r++) rows.push(buildRow(pkg, init.columns));
|
|
2498
|
+
return el("table:table", {}, [...columns, ...rows]);
|
|
2499
|
+
}
|
|
2500
|
+
//#endregion
|
|
2501
|
+
//#region src/edit/odt/editor.ts
|
|
2502
|
+
const CONTENT_PART_PATH = "content.xml";
|
|
2503
|
+
function findContentRoot(pkg) {
|
|
2504
|
+
const part = pkg.parts[CONTENT_PART_PATH];
|
|
2505
|
+
const root = part?.kind === "xml" ? part.nodes.find((n) => n.type === "element") : void 0;
|
|
2506
|
+
if (root === void 0) throw new Error(`package has no root element at ${CONTENT_PART_PATH}`);
|
|
2507
|
+
return root;
|
|
2508
|
+
}
|
|
2509
|
+
function directChild(parent, tag) {
|
|
2510
|
+
for (const child of parent.children) if (child.type === "element" && child.tag === tag) return child;
|
|
2511
|
+
}
|
|
2512
|
+
function findOfficeText(contentRoot) {
|
|
2513
|
+
const body = directChild(contentRoot, "office:body");
|
|
2514
|
+
const text = body === void 0 ? void 0 : directChild(body, "office:text");
|
|
2515
|
+
if (text === void 0) throw new Error(`${CONTENT_PART_PATH} has no office:body/office:text element`);
|
|
2516
|
+
return text;
|
|
2517
|
+
}
|
|
2518
|
+
var OdtBodyImpl = class {
|
|
2519
|
+
officeText;
|
|
2520
|
+
pkg;
|
|
2521
|
+
constructor(officeText, pkg) {
|
|
2522
|
+
this.officeText = officeText;
|
|
2523
|
+
this.pkg = pkg;
|
|
2524
|
+
}
|
|
2525
|
+
appendParagraph(init) {
|
|
2526
|
+
const paragraphElement = buildParagraph(this.pkg, init);
|
|
2527
|
+
this.officeText.children.push(paragraphElement);
|
|
2528
|
+
return new OdtParagraph(this.officeText.children, paragraphElement, this.pkg);
|
|
2529
|
+
}
|
|
2530
|
+
appendTable(init) {
|
|
2531
|
+
const tableElement = buildTable(this.pkg, init);
|
|
2532
|
+
this.officeText.children.push(tableElement);
|
|
2533
|
+
return new OdtTable(this.officeText.children, tableElement, this.pkg);
|
|
2534
|
+
}
|
|
2535
|
+
appendList() {
|
|
2536
|
+
const listElement = buildList(this.pkg);
|
|
2537
|
+
this.officeText.children.push(listElement);
|
|
2538
|
+
return new OdtList(this.officeText.children, listElement, this.pkg);
|
|
2539
|
+
}
|
|
2540
|
+
appendPageBreak() {
|
|
2541
|
+
const paragraphElement = buildParagraph(this.pkg);
|
|
2542
|
+
paragraphElement.attributes.push({
|
|
2543
|
+
name: "text:style-name",
|
|
2544
|
+
value: ensurePageBreakStyleName(this.pkg)
|
|
2545
|
+
});
|
|
2546
|
+
this.officeText.children.push(paragraphElement);
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
var OdtEditor = class {
|
|
2550
|
+
body;
|
|
2551
|
+
pkg;
|
|
2552
|
+
constructor(pkg) {
|
|
2553
|
+
this.pkg = pkg;
|
|
2554
|
+
const officeText = findOfficeText(findContentRoot(pkg));
|
|
2555
|
+
this.body = new OdtBodyImpl(officeText, pkg);
|
|
2556
|
+
}
|
|
2557
|
+
paragraphs() {
|
|
2558
|
+
const officeText = findOfficeText(findContentRoot(this.pkg));
|
|
2559
|
+
const out = [];
|
|
2560
|
+
for (const child of officeText.children) if (child.type === "element" && child.tag === "text:p") out.push(new OdtParagraph(officeText.children, child, this.pkg));
|
|
2561
|
+
return out;
|
|
2562
|
+
}
|
|
2563
|
+
tables() {
|
|
2564
|
+
const officeText = findOfficeText(findContentRoot(this.pkg));
|
|
2565
|
+
const out = [];
|
|
2566
|
+
for (const child of officeText.children) if (child.type === "element" && child.tag === "table:table") out.push(new OdtTable(officeText.children, child, this.pkg));
|
|
2567
|
+
return out;
|
|
2568
|
+
}
|
|
2569
|
+
lists() {
|
|
2570
|
+
const officeText = findOfficeText(findContentRoot(this.pkg));
|
|
2571
|
+
const out = [];
|
|
2572
|
+
for (const child of officeText.children) if (child.type === "element" && child.tag === "text:list") out.push(new OdtList(officeText.children, child, this.pkg));
|
|
2573
|
+
return out;
|
|
2574
|
+
}
|
|
2575
|
+
toPackage() {
|
|
2576
|
+
return this.pkg;
|
|
2577
|
+
}
|
|
2578
|
+
toBytes() {
|
|
2579
|
+
return (0, odf_js.encodePackage)(this.pkg);
|
|
2580
|
+
}
|
|
2581
|
+
};
|
|
2582
|
+
function openOdt(bytes) {
|
|
2583
|
+
return new OdtEditor((0, odf_js.decodePackage)(bytes));
|
|
2584
|
+
}
|
|
2585
|
+
function createOdt() {
|
|
2586
|
+
return new OdtEditor(createEmptyOdtPackage());
|
|
2587
|
+
}
|
|
2588
|
+
//#endregion
|
|
2589
|
+
//#region src/edit/odt/content.ts
|
|
2590
|
+
function buildOdtPackage(content) {
|
|
2591
|
+
if (content.kind !== "wordprocessing") throw new Error("buildOdtPackage requires a wordprocessing ContentDocument");
|
|
2592
|
+
const editor = createOdt();
|
|
2593
|
+
content.sections.forEach((section, sectionIndex) => {
|
|
2594
|
+
if (sectionIndex > 0) editor.body.appendPageBreak();
|
|
2595
|
+
for (const block of section.blocks) appendBlock(editor.body, block);
|
|
2596
|
+
});
|
|
2597
|
+
return editor.toPackage();
|
|
2598
|
+
}
|
|
2599
|
+
function populateParagraph(paragraph, block) {
|
|
2600
|
+
if (block.alignment !== void 0) paragraph.alignment = block.alignment;
|
|
2601
|
+
for (const run of block.runs) {
|
|
2602
|
+
if (run.text === " ") {
|
|
2603
|
+
paragraph.appendTab();
|
|
2604
|
+
continue;
|
|
2605
|
+
}
|
|
2606
|
+
const odtRun = paragraph.appendRun({ text: run.text });
|
|
2607
|
+
if (run.bold === true) odtRun.bold = true;
|
|
2608
|
+
if (run.italic === true) odtRun.italic = true;
|
|
2609
|
+
if (run.underline === true) odtRun.underline = true;
|
|
2610
|
+
if (run.fontFamily !== void 0) odtRun.fontFamily = run.fontFamily;
|
|
2611
|
+
if (run.sizePt !== void 0) odtRun.sizePt = run.sizePt;
|
|
2612
|
+
if (run.color !== void 0) odtRun.color = run.color;
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
function appendTable(body, block) {
|
|
2616
|
+
const columns = block.columnWidthsPt.length;
|
|
2617
|
+
if (block.rows.length === 0 || columns === 0) return;
|
|
2618
|
+
const table = body.appendTable({
|
|
2619
|
+
rows: block.rows.length,
|
|
2620
|
+
columns,
|
|
2621
|
+
columnWidthsPt: block.columnWidthsPt
|
|
2622
|
+
});
|
|
2623
|
+
block.rows.forEach((row, rowIndex) => {
|
|
2624
|
+
const tableRow = table.rows()[rowIndex];
|
|
2625
|
+
if (tableRow === void 0) return;
|
|
2626
|
+
row.cells.forEach((cell, cellIndex) => {
|
|
2627
|
+
const tableCell = tableRow.cells()[cellIndex];
|
|
2628
|
+
if (tableCell === void 0) return;
|
|
2629
|
+
const [firstBlock, ...restBlocks] = cell.blocks;
|
|
2630
|
+
const firstParagraph = tableCell.paragraphs()[0];
|
|
2631
|
+
if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock);
|
|
2632
|
+
else if (firstBlock !== void 0) appendCellBlock(tableCell, firstBlock);
|
|
2633
|
+
for (const remaining of restBlocks) appendCellBlock(tableCell, remaining);
|
|
2634
|
+
});
|
|
2635
|
+
});
|
|
2636
|
+
}
|
|
2637
|
+
function appendCellBlock(cell, block) {
|
|
2638
|
+
if (block.kind === "paragraph") populateParagraph(cell.appendParagraph(), block);
|
|
2639
|
+
}
|
|
2640
|
+
function appendBlock(body, block) {
|
|
2641
|
+
if (block.kind === "paragraph") populateParagraph(body.appendParagraph(), block);
|
|
2642
|
+
else if (block.kind === "pageBreak") body.appendPageBreak();
|
|
2643
|
+
else if (block.kind === "table") appendTable(body, block);
|
|
2644
|
+
}
|
|
2645
|
+
//#endregion
|
|
1955
2646
|
//#region src/bytes/crc32.ts
|
|
1956
2647
|
const CRC32_POLYNOMIAL = 3988292384;
|
|
1957
2648
|
const BYTE_VALUES = 256;
|
|
@@ -7747,6 +8438,13 @@ function pdfToPptx(bytes, options) {
|
|
|
7747
8438
|
}), { signal: options?.signal });
|
|
7748
8439
|
return (0, ooxml_js.encodePackage)(buildPptxPackage(content));
|
|
7749
8440
|
}
|
|
8441
|
+
function pdfToOdt(bytes, options) {
|
|
8442
|
+
const content = reconstructWordprocessing(readPdf(bytes, {
|
|
8443
|
+
signal: options?.signal,
|
|
8444
|
+
sink: options?.sink
|
|
8445
|
+
}), { signal: options?.signal });
|
|
8446
|
+
return (0, odf_js.encodePackage)(buildOdtPackage(content));
|
|
8447
|
+
}
|
|
7750
8448
|
//#endregion
|
|
7751
8449
|
//#region src/convert/codec.ts
|
|
7752
8450
|
const docxPdfCodec = zod.z.codec(DocxBytesSchema, PdfBytesSchema, {
|
|
@@ -7757,6 +8455,10 @@ const pptxPdfCodec = zod.z.codec(PptxBytesSchema, PdfBytesSchema, {
|
|
|
7757
8455
|
decode: (pptxBytes) => pptxToPdf(pptxBytes),
|
|
7758
8456
|
encode: (pdfBytes) => pdfToPptx(pdfBytes)
|
|
7759
8457
|
});
|
|
8458
|
+
zod.z.codec(OdtBytesSchema, PdfBytesSchema, {
|
|
8459
|
+
decode: (odtBytes) => odtToPdf(odtBytes),
|
|
8460
|
+
encode: (pdfBytes) => pdfToOdt(pdfBytes)
|
|
8461
|
+
});
|
|
7760
8462
|
//#endregion
|
|
7761
8463
|
//#region src/convert/local.ts
|
|
7762
8464
|
const SUPPORTED_CONVERSIONS = [
|
|
@@ -7779,6 +8481,10 @@ const SUPPORTED_CONVERSIONS = [
|
|
|
7779
8481
|
{
|
|
7780
8482
|
source: "pdf",
|
|
7781
8483
|
target: "pptx"
|
|
8484
|
+
},
|
|
8485
|
+
{
|
|
8486
|
+
source: "pdf",
|
|
8487
|
+
target: "odt"
|
|
7782
8488
|
}
|
|
7783
8489
|
];
|
|
7784
8490
|
function substitutionDiagnostic(substitution, context) {
|
|
@@ -7869,6 +8575,19 @@ function createLocalDocumentConverter() {
|
|
|
7869
8575
|
diagnostics
|
|
7870
8576
|
});
|
|
7871
8577
|
}
|
|
8578
|
+
if (source.format === "pdf" && targetFormat === "odt") {
|
|
8579
|
+
const bytes = pdfToOdt(source.bytes, {
|
|
8580
|
+
signal: options.signal,
|
|
8581
|
+
sink: (d) => diagnostics.push(fromPdfDiagnostic(d))
|
|
8582
|
+
});
|
|
8583
|
+
return Promise.resolve({
|
|
8584
|
+
document: {
|
|
8585
|
+
format: "odt",
|
|
8586
|
+
bytes
|
|
8587
|
+
},
|
|
8588
|
+
diagnostics
|
|
8589
|
+
});
|
|
8590
|
+
}
|
|
7872
8591
|
return Promise.reject(/* @__PURE__ */ new Error(`unsupported conversion: ${source.format} -> ${targetFormat}`));
|
|
7873
8592
|
}
|
|
7874
8593
|
};
|
|
@@ -8020,6 +8739,14 @@ exports.OdgBytesSchema = OdgBytesSchema;
|
|
|
8020
8739
|
exports.OdpBytesSchema = OdpBytesSchema;
|
|
8021
8740
|
exports.OdsBytesSchema = OdsBytesSchema;
|
|
8022
8741
|
exports.OdtBytesSchema = OdtBytesSchema;
|
|
8742
|
+
exports.OdtEditor = OdtEditor;
|
|
8743
|
+
exports.OdtList = OdtList;
|
|
8744
|
+
exports.OdtListItem = OdtListItem;
|
|
8745
|
+
exports.OdtParagraph = OdtParagraph;
|
|
8746
|
+
exports.OdtRun = OdtRun;
|
|
8747
|
+
exports.OdtTable = OdtTable;
|
|
8748
|
+
exports.OdtTableCell = OdtTableCell;
|
|
8749
|
+
exports.OdtTableRow = OdtTableRow;
|
|
8023
8750
|
Object.defineProperty(exports, "PAGE_SIZE_A4", {
|
|
8024
8751
|
enumerable: true,
|
|
8025
8752
|
get: function() {
|
|
@@ -8124,6 +8851,7 @@ Object.defineProperty(exports, "base64ToBytes", {
|
|
|
8124
8851
|
}
|
|
8125
8852
|
});
|
|
8126
8853
|
exports.buildDocxPackage = buildDocxPackage;
|
|
8854
|
+
exports.buildOdtPackage = buildOdtPackage;
|
|
8127
8855
|
exports.buildPptxPackage = buildPptxPackage;
|
|
8128
8856
|
Object.defineProperty(exports, "buildXml", {
|
|
8129
8857
|
enumerable: true,
|
|
@@ -8159,6 +8887,7 @@ exports.convertPresentationToLayout = convertPresentationToLayout;
|
|
|
8159
8887
|
exports.convertWordprocessingToLayout = convertWordprocessingToLayout;
|
|
8160
8888
|
exports.createDocx = createDocx;
|
|
8161
8889
|
exports.createLocalDocumentConverter = createLocalDocumentConverter;
|
|
8890
|
+
exports.createOdt = createOdt;
|
|
8162
8891
|
exports.createPptx = createPptx;
|
|
8163
8892
|
Object.defineProperty(exports, "decodeCompactPackage", {
|
|
8164
8893
|
enumerable: true,
|
|
@@ -8226,6 +8955,7 @@ Object.defineProperty(exports, "isXmlNode", {
|
|
|
8226
8955
|
});
|
|
8227
8956
|
exports.odtToPdf = odtToPdf;
|
|
8228
8957
|
exports.openDocx = openDocx;
|
|
8958
|
+
exports.openOdt = openOdt;
|
|
8229
8959
|
exports.openPptx = openPptx;
|
|
8230
8960
|
Object.defineProperty(exports, "packageCodec", {
|
|
8231
8961
|
enumerable: true,
|