js.documents 7.13.0 → 7.15.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/codecs/registry.cjs +1 -1
- package/dist/codecs/registry.js +1 -1
- package/dist/convert/composition.cjs +1 -1
- package/dist/convert/composition.js +1 -1
- package/dist/edit/doc/editor.cjs +159 -0
- package/dist/edit/doc/editor.d.cts +59 -0
- package/dist/edit/doc/editor.d.ts +59 -0
- package/dist/edit/doc/editor.js +155 -0
- package/dist/edit/doc/paragraph.cjs +130 -0
- package/dist/edit/doc/paragraph.d.cts +2 -0
- package/dist/edit/doc/paragraph.d.ts +2 -0
- package/dist/edit/doc/paragraph.js +128 -0
- package/dist/edit/doc/run.cjs +98 -0
- package/dist/edit/doc/run.d.cts +2 -0
- package/dist/edit/doc/run.d.ts +2 -0
- package/dist/edit/doc/run.js +96 -0
- package/dist/edit/doc/table.cjs +110 -0
- package/dist/edit/doc/table.d.cts +41 -0
- package/dist/edit/doc/table.d.ts +41 -0
- package/dist/edit/doc/table.js +106 -0
- package/dist/edit/ppt/editor.cjs +51 -0
- package/dist/edit/ppt/editor.d.cts +22 -0
- package/dist/edit/ppt/editor.d.ts +22 -0
- package/dist/edit/ppt/editor.js +48 -0
- package/dist/edit/ppt/slide.cjs +104 -0
- package/dist/edit/ppt/slide.d.cts +39 -0
- package/dist/edit/ppt/slide.d.ts +39 -0
- package/dist/edit/ppt/slide.js +101 -0
- package/dist/edit/xls/editor.cjs +2 -1
- package/dist/edit/xls/editor.d.cts +2 -1
- package/dist/edit/xls/editor.d.ts +2 -1
- package/dist/edit/xls/editor.js +2 -1
- package/dist/index.cjs +22 -2
- package/dist/index.d.cts +15 -9
- package/dist/index.d.ts +14 -8
- package/dist/index.js +9 -3
- package/dist/paragraph-Byw2Y7xu.d.ts +43 -0
- package/dist/paragraph-DM9n9I4T.d.cts +43 -0
- package/dist/run-iYz2M-a_.d.cts +39 -0
- package/dist/run-iYz2M-a_.d.ts +39 -0
- package/package.json +1 -1
package/dist/codecs/registry.cjs
CHANGED
|
@@ -6,12 +6,12 @@ const require_edit_odp_content = require("../edit/odp/content.cjs");
|
|
|
6
6
|
const require_edit_ods_content = require("../edit/ods/content.cjs");
|
|
7
7
|
const require_edit_odg_content = require("../edit/odg/content.cjs");
|
|
8
8
|
const require_markdown_write = require("../markdown/write.cjs");
|
|
9
|
+
const require_ppt_write = require("../ppt/write.cjs");
|
|
9
10
|
const require_markdown_text = require("../markdown/text.cjs");
|
|
10
11
|
const require_csv_text = require("../csv/text.cjs");
|
|
11
12
|
const require_csv_write = require("../csv/write.cjs");
|
|
12
13
|
const require_svg_text = require("../svg/text.cjs");
|
|
13
14
|
const require_svg_write = require("../svg/write.cjs");
|
|
14
|
-
const require_ppt_write = require("../ppt/write.cjs");
|
|
15
15
|
const require_package_codec = require("../package-codec.cjs");
|
|
16
16
|
const require_codecs_read = require("./read.cjs");
|
|
17
17
|
let ooxml_js = require("ooxml.js");
|
package/dist/codecs/registry.js
CHANGED
|
@@ -5,12 +5,12 @@ import { buildOdpPackage } from "../edit/odp/content.js";
|
|
|
5
5
|
import { buildOdsPackage } from "../edit/ods/content.js";
|
|
6
6
|
import { buildOdgPackage } from "../edit/odg/content.js";
|
|
7
7
|
import { buildMarkdownText } from "../markdown/write.js";
|
|
8
|
+
import { writePptContent } from "../ppt/write.js";
|
|
8
9
|
import { encodeMarkdownText } from "../markdown/text.js";
|
|
9
10
|
import { encodeCsvText } from "../csv/text.js";
|
|
10
11
|
import { buildCsvText } from "../csv/write.js";
|
|
11
12
|
import { encodeSvgText } from "../svg/text.js";
|
|
12
13
|
import { buildSvgText } from "../svg/write.js";
|
|
13
|
-
import { writePptContent } from "../ppt/write.js";
|
|
14
14
|
import { encodeDocumentPackage } from "../package-codec.js";
|
|
15
15
|
import { CONTENT_READERS, readDocumentLayout } from "./read.js";
|
|
16
16
|
import { buildXlsxPackageFromContent } from "ooxml.js";
|
|
@@ -9,6 +9,7 @@ const require_edit_odg_content = require("../edit/odg/content.cjs");
|
|
|
9
9
|
const require_markdown_write = require("../markdown/write.cjs");
|
|
10
10
|
const require_markdown_read = require("../markdown/read.cjs");
|
|
11
11
|
const require_ppt_read = require("../ppt/read.cjs");
|
|
12
|
+
const require_ppt_write = require("../ppt/write.cjs");
|
|
12
13
|
const require_ooxml_docx_read = require("../ooxml/docx/read.cjs");
|
|
13
14
|
const require_ooxml_pptx_read = require("../ooxml/pptx/read.cjs");
|
|
14
15
|
const require_odf_odt_read = require("../odf/odt/read.cjs");
|
|
@@ -22,7 +23,6 @@ const require_csv_write = require("../csv/write.cjs");
|
|
|
22
23
|
const require_svg_text = require("../svg/text.cjs");
|
|
23
24
|
const require_svg_read = require("../svg/read.cjs");
|
|
24
25
|
const require_svg_write = require("../svg/write.cjs");
|
|
25
|
-
const require_ppt_write = require("../ppt/write.cjs");
|
|
26
26
|
const require_ports_abort = require("../ports/abort.cjs");
|
|
27
27
|
const require_layout_reconstruct = require("../layout/reconstruct.cjs");
|
|
28
28
|
const require_convert_pdf_package_tables = require("./pdf-package-tables.cjs");
|
|
@@ -8,6 +8,7 @@ import { buildOdgPackage } from "../edit/odg/content.js";
|
|
|
8
8
|
import { buildMarkdownText } from "../markdown/write.js";
|
|
9
9
|
import { readMarkdownContent as readMarkdownContent$1 } from "../markdown/read.js";
|
|
10
10
|
import { readPptContent } from "../ppt/read.js";
|
|
11
|
+
import { writePptContent } from "../ppt/write.js";
|
|
11
12
|
import { readDocxContent as readDocxContent$1 } from "../ooxml/docx/read.js";
|
|
12
13
|
import { readPptxContent as readPptxContent$1 } from "../ooxml/pptx/read.js";
|
|
13
14
|
import { readOdtContent as readOdtContent$1 } from "../odf/odt/read.js";
|
|
@@ -21,7 +22,6 @@ import { buildCsvText } from "../csv/write.js";
|
|
|
21
22
|
import { decodeSvgText, encodeSvgText } from "../svg/text.js";
|
|
22
23
|
import { readSvgContent } from "../svg/read.js";
|
|
23
24
|
import { buildSvgText } from "../svg/write.js";
|
|
24
|
-
import { writePptContent } from "../ppt/write.js";
|
|
25
25
|
import { throwIfAborted } from "../ports/abort.js";
|
|
26
26
|
import { reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing } from "../layout/reconstruct.js";
|
|
27
27
|
import { stampPdfPackageTables } from "./pdf-package-tables.js";
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_metadata_core_patch = require("../../metadata/core-patch.cjs");
|
|
3
|
+
const require_model_metadata = require("../../model/metadata.cjs");
|
|
4
|
+
const require_ports_clock = require("../../ports/clock.cjs");
|
|
5
|
+
const require_edit_doc_paragraph = require("./paragraph.cjs");
|
|
6
|
+
const require_edit_doc_table = require("./table.cjs");
|
|
7
|
+
let document_schema_js = require("document-schema.js");
|
|
8
|
+
let doc_codec = require("doc-codec");
|
|
9
|
+
//#region src/edit/doc/editor.ts
|
|
10
|
+
const DEFAULT_MARGINS = {
|
|
11
|
+
topPt: 72,
|
|
12
|
+
rightPt: 72,
|
|
13
|
+
bottomPt: 72,
|
|
14
|
+
leftPt: 72
|
|
15
|
+
};
|
|
16
|
+
var DocSection = class {
|
|
17
|
+
container;
|
|
18
|
+
node;
|
|
19
|
+
removed = false;
|
|
20
|
+
constructor(container, node) {
|
|
21
|
+
this.container = container;
|
|
22
|
+
this.node = node;
|
|
23
|
+
}
|
|
24
|
+
live() {
|
|
25
|
+
if (this.removed) throw new Error("this DocSection has been removed from its document and can no longer be used");
|
|
26
|
+
return this.node;
|
|
27
|
+
}
|
|
28
|
+
get pageSize() {
|
|
29
|
+
return this.live().pageSize;
|
|
30
|
+
}
|
|
31
|
+
set pageSize(value) {
|
|
32
|
+
this.live().pageSize = value;
|
|
33
|
+
}
|
|
34
|
+
get margins() {
|
|
35
|
+
return this.live().margins;
|
|
36
|
+
}
|
|
37
|
+
set margins(value) {
|
|
38
|
+
this.live().margins = value;
|
|
39
|
+
}
|
|
40
|
+
get breakType() {
|
|
41
|
+
return this.live().breakType;
|
|
42
|
+
}
|
|
43
|
+
set breakType(value) {
|
|
44
|
+
const node = this.live();
|
|
45
|
+
if (value === void 0) delete node.breakType;
|
|
46
|
+
else node.breakType = value;
|
|
47
|
+
}
|
|
48
|
+
paragraphs() {
|
|
49
|
+
return this.live().blocks.filter((block) => block.kind === "paragraph").map((block) => new require_edit_doc_paragraph.DocParagraph(this.live().blocks, block));
|
|
50
|
+
}
|
|
51
|
+
appendParagraph(init) {
|
|
52
|
+
const node = this.live();
|
|
53
|
+
const paragraph = require_edit_doc_paragraph.buildParagraph(init);
|
|
54
|
+
node.blocks.push(paragraph);
|
|
55
|
+
return new require_edit_doc_paragraph.DocParagraph(node.blocks, paragraph);
|
|
56
|
+
}
|
|
57
|
+
tables() {
|
|
58
|
+
return this.live().blocks.filter((block) => block.kind === "table").map((block) => new require_edit_doc_table.DocTable(this.live().blocks, block));
|
|
59
|
+
}
|
|
60
|
+
appendTable(init) {
|
|
61
|
+
const node = this.live();
|
|
62
|
+
const table = require_edit_doc_table.buildTable(init);
|
|
63
|
+
node.blocks.push(table);
|
|
64
|
+
return new require_edit_doc_table.DocTable(node.blocks, table);
|
|
65
|
+
}
|
|
66
|
+
remove() {
|
|
67
|
+
if (this.container.length === 1) throw new Error("a doc document must carry at least one section; the last one cannot be removed");
|
|
68
|
+
const index = this.container.indexOf(this.node);
|
|
69
|
+
if (index !== -1) this.container.splice(index, 1);
|
|
70
|
+
this.removed = true;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var DocBodyImpl = class {
|
|
74
|
+
section;
|
|
75
|
+
constructor(section) {
|
|
76
|
+
this.section = section;
|
|
77
|
+
}
|
|
78
|
+
paragraphs() {
|
|
79
|
+
return this.section.blocks.filter((block) => block.kind === "paragraph").map((block) => new require_edit_doc_paragraph.DocParagraph(this.section.blocks, block));
|
|
80
|
+
}
|
|
81
|
+
appendParagraph(init) {
|
|
82
|
+
const paragraph = require_edit_doc_paragraph.buildParagraph(init);
|
|
83
|
+
this.section.blocks.push(paragraph);
|
|
84
|
+
return new require_edit_doc_paragraph.DocParagraph(this.section.blocks, paragraph);
|
|
85
|
+
}
|
|
86
|
+
tables() {
|
|
87
|
+
return this.section.blocks.filter((block) => block.kind === "table").map((block) => new require_edit_doc_table.DocTable(this.section.blocks, block));
|
|
88
|
+
}
|
|
89
|
+
appendTable(init) {
|
|
90
|
+
const table = require_edit_doc_table.buildTable(init);
|
|
91
|
+
this.section.blocks.push(table);
|
|
92
|
+
return new require_edit_doc_table.DocTable(this.section.blocks, table);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var DocEditor = class {
|
|
96
|
+
body;
|
|
97
|
+
document;
|
|
98
|
+
constructor(document) {
|
|
99
|
+
if (document.kind !== "wordprocessing") throw new Error(`DocEditor requires a wordprocessing ContentDocument, got "${document.kind}"`);
|
|
100
|
+
const first = document.sections[0];
|
|
101
|
+
if (first === void 0) throw new Error("a doc document must carry at least one section");
|
|
102
|
+
this.document = document;
|
|
103
|
+
this.body = new DocBodyImpl(first);
|
|
104
|
+
}
|
|
105
|
+
get metadata() {
|
|
106
|
+
return this.document.metadata;
|
|
107
|
+
}
|
|
108
|
+
set metadata(value) {
|
|
109
|
+
this.document.metadata = require_metadata_core_patch.mergeMetadata(this.document.metadata, value);
|
|
110
|
+
}
|
|
111
|
+
sections() {
|
|
112
|
+
return this.document.sections.map((section) => new DocSection(this.document.sections, section));
|
|
113
|
+
}
|
|
114
|
+
paragraphs() {
|
|
115
|
+
return this.body.paragraphs();
|
|
116
|
+
}
|
|
117
|
+
appendParagraph(init) {
|
|
118
|
+
return this.body.appendParagraph(init);
|
|
119
|
+
}
|
|
120
|
+
tables() {
|
|
121
|
+
return this.body.tables();
|
|
122
|
+
}
|
|
123
|
+
appendTable(init) {
|
|
124
|
+
return this.body.appendTable(init);
|
|
125
|
+
}
|
|
126
|
+
appendSection(init = {}) {
|
|
127
|
+
const node = {
|
|
128
|
+
pageSize: init.pageSize ?? document_schema_js.PAGE_SIZE_LETTER,
|
|
129
|
+
margins: init.margins ?? DEFAULT_MARGINS,
|
|
130
|
+
blocks: []
|
|
131
|
+
};
|
|
132
|
+
if (init.breakType !== void 0) node.breakType = init.breakType;
|
|
133
|
+
this.document.sections.push(node);
|
|
134
|
+
return new DocSection(this.document.sections, node);
|
|
135
|
+
}
|
|
136
|
+
toBytes(options) {
|
|
137
|
+
return (0, doc_codec.writeDocContent)(this.document, options);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
function openDoc(bytes, password) {
|
|
141
|
+
return new DocEditor((0, doc_codec.readDocContent)(bytes, password));
|
|
142
|
+
}
|
|
143
|
+
function createDoc(options = {}) {
|
|
144
|
+
const clock = options.clock ?? require_ports_clock.systemClock;
|
|
145
|
+
return new DocEditor({
|
|
146
|
+
kind: "wordprocessing",
|
|
147
|
+
metadata: require_model_metadata.resolveMetadataTimestamps({}, clock),
|
|
148
|
+
sections: [{
|
|
149
|
+
pageSize: options.pageSize ?? document_schema_js.PAGE_SIZE_LETTER,
|
|
150
|
+
margins: options.margins ?? DEFAULT_MARGINS,
|
|
151
|
+
blocks: []
|
|
152
|
+
}]
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
exports.DocEditor = DocEditor;
|
|
157
|
+
exports.DocSection = DocSection;
|
|
158
|
+
exports.createDoc = createDoc;
|
|
159
|
+
exports.openDoc = openDoc;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { t as ClockPort } from "../../clock-C7SUuYN0.cjs";
|
|
2
|
+
import { MetadataOverrides } from "../../metadata/core-patch.cjs";
|
|
3
|
+
import { n as ParagraphInit, t as DocParagraph } from "../../paragraph-DM9n9I4T.cjs";
|
|
4
|
+
import { DocTable, TableInit } from "./table.cjs";
|
|
5
|
+
import { ContentDocument, ContentSection, LayoutMetadata, Margins, PageSize } from "document-schema.js";
|
|
6
|
+
import { WriteDocContentOptions } from "doc-codec";
|
|
7
|
+
//#region src/edit/doc/editor.d.ts
|
|
8
|
+
interface SectionInit {
|
|
9
|
+
readonly pageSize?: PageSize;
|
|
10
|
+
readonly margins?: Margins;
|
|
11
|
+
readonly breakType?: ContentSection["breakType"];
|
|
12
|
+
}
|
|
13
|
+
declare class DocSection {
|
|
14
|
+
private readonly container;
|
|
15
|
+
private readonly node;
|
|
16
|
+
private removed;
|
|
17
|
+
constructor(container: ContentSection[], node: ContentSection);
|
|
18
|
+
private live;
|
|
19
|
+
get pageSize(): PageSize;
|
|
20
|
+
set pageSize(value: PageSize);
|
|
21
|
+
get margins(): Margins;
|
|
22
|
+
set margins(value: Margins);
|
|
23
|
+
get breakType(): ContentSection["breakType"];
|
|
24
|
+
set breakType(value: ContentSection["breakType"]);
|
|
25
|
+
paragraphs(): DocParagraph[];
|
|
26
|
+
appendParagraph(init?: ParagraphInit): DocParagraph;
|
|
27
|
+
tables(): DocTable[];
|
|
28
|
+
appendTable(init: TableInit): DocTable;
|
|
29
|
+
remove(): void;
|
|
30
|
+
}
|
|
31
|
+
interface DocBody {
|
|
32
|
+
paragraphs(): DocParagraph[];
|
|
33
|
+
appendParagraph(init?: ParagraphInit): DocParagraph;
|
|
34
|
+
tables(): DocTable[];
|
|
35
|
+
appendTable(init: TableInit): DocTable;
|
|
36
|
+
}
|
|
37
|
+
interface CreateDocOptions {
|
|
38
|
+
readonly clock?: ClockPort;
|
|
39
|
+
readonly pageSize?: PageSize;
|
|
40
|
+
readonly margins?: Margins;
|
|
41
|
+
}
|
|
42
|
+
declare class DocEditor {
|
|
43
|
+
readonly body: DocBody;
|
|
44
|
+
private readonly document;
|
|
45
|
+
constructor(document: ContentDocument);
|
|
46
|
+
get metadata(): LayoutMetadata;
|
|
47
|
+
set metadata(value: MetadataOverrides);
|
|
48
|
+
sections(): DocSection[];
|
|
49
|
+
paragraphs(): DocParagraph[];
|
|
50
|
+
appendParagraph(init?: ParagraphInit): DocParagraph;
|
|
51
|
+
tables(): DocTable[];
|
|
52
|
+
appendTable(init: TableInit): DocTable;
|
|
53
|
+
appendSection(init?: SectionInit): DocSection;
|
|
54
|
+
toBytes(options?: WriteDocContentOptions): Uint8Array<ArrayBuffer>;
|
|
55
|
+
}
|
|
56
|
+
declare function openDoc(bytes: Uint8Array<ArrayBuffer>, password?: string): DocEditor;
|
|
57
|
+
declare function createDoc(options?: CreateDocOptions): DocEditor;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { CreateDocOptions, DocBody, DocEditor, DocSection, SectionInit, createDoc, openDoc };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { t as ClockPort } from "../../clock-C7SUuYN0.js";
|
|
2
|
+
import { MetadataOverrides } from "../../metadata/core-patch.js";
|
|
3
|
+
import { n as ParagraphInit, t as DocParagraph } from "../../paragraph-Byw2Y7xu.js";
|
|
4
|
+
import { DocTable, TableInit } from "./table.js";
|
|
5
|
+
import { ContentDocument, ContentSection, LayoutMetadata, Margins, PageSize } from "document-schema.js";
|
|
6
|
+
import { WriteDocContentOptions } from "doc-codec";
|
|
7
|
+
//#region src/edit/doc/editor.d.ts
|
|
8
|
+
interface SectionInit {
|
|
9
|
+
readonly pageSize?: PageSize;
|
|
10
|
+
readonly margins?: Margins;
|
|
11
|
+
readonly breakType?: ContentSection["breakType"];
|
|
12
|
+
}
|
|
13
|
+
declare class DocSection {
|
|
14
|
+
private readonly container;
|
|
15
|
+
private readonly node;
|
|
16
|
+
private removed;
|
|
17
|
+
constructor(container: ContentSection[], node: ContentSection);
|
|
18
|
+
private live;
|
|
19
|
+
get pageSize(): PageSize;
|
|
20
|
+
set pageSize(value: PageSize);
|
|
21
|
+
get margins(): Margins;
|
|
22
|
+
set margins(value: Margins);
|
|
23
|
+
get breakType(): ContentSection["breakType"];
|
|
24
|
+
set breakType(value: ContentSection["breakType"]);
|
|
25
|
+
paragraphs(): DocParagraph[];
|
|
26
|
+
appendParagraph(init?: ParagraphInit): DocParagraph;
|
|
27
|
+
tables(): DocTable[];
|
|
28
|
+
appendTable(init: TableInit): DocTable;
|
|
29
|
+
remove(): void;
|
|
30
|
+
}
|
|
31
|
+
interface DocBody {
|
|
32
|
+
paragraphs(): DocParagraph[];
|
|
33
|
+
appendParagraph(init?: ParagraphInit): DocParagraph;
|
|
34
|
+
tables(): DocTable[];
|
|
35
|
+
appendTable(init: TableInit): DocTable;
|
|
36
|
+
}
|
|
37
|
+
interface CreateDocOptions {
|
|
38
|
+
readonly clock?: ClockPort;
|
|
39
|
+
readonly pageSize?: PageSize;
|
|
40
|
+
readonly margins?: Margins;
|
|
41
|
+
}
|
|
42
|
+
declare class DocEditor {
|
|
43
|
+
readonly body: DocBody;
|
|
44
|
+
private readonly document;
|
|
45
|
+
constructor(document: ContentDocument);
|
|
46
|
+
get metadata(): LayoutMetadata;
|
|
47
|
+
set metadata(value: MetadataOverrides);
|
|
48
|
+
sections(): DocSection[];
|
|
49
|
+
paragraphs(): DocParagraph[];
|
|
50
|
+
appendParagraph(init?: ParagraphInit): DocParagraph;
|
|
51
|
+
tables(): DocTable[];
|
|
52
|
+
appendTable(init: TableInit): DocTable;
|
|
53
|
+
appendSection(init?: SectionInit): DocSection;
|
|
54
|
+
toBytes(options?: WriteDocContentOptions): Uint8Array<ArrayBuffer>;
|
|
55
|
+
}
|
|
56
|
+
declare function openDoc(bytes: Uint8Array<ArrayBuffer>, password?: string): DocEditor;
|
|
57
|
+
declare function createDoc(options?: CreateDocOptions): DocEditor;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { CreateDocOptions, DocBody, DocEditor, DocSection, SectionInit, createDoc, openDoc };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { mergeMetadata } from "../../metadata/core-patch.js";
|
|
2
|
+
import { resolveMetadataTimestamps } from "../../model/metadata.js";
|
|
3
|
+
import { systemClock } from "../../ports/clock.js";
|
|
4
|
+
import { DocParagraph, buildParagraph } from "./paragraph.js";
|
|
5
|
+
import { DocTable, buildTable } from "./table.js";
|
|
6
|
+
import { PAGE_SIZE_LETTER } from "document-schema.js";
|
|
7
|
+
import { readDocContent, writeDocContent } from "doc-codec";
|
|
8
|
+
//#region src/edit/doc/editor.ts
|
|
9
|
+
const DEFAULT_MARGINS = {
|
|
10
|
+
topPt: 72,
|
|
11
|
+
rightPt: 72,
|
|
12
|
+
bottomPt: 72,
|
|
13
|
+
leftPt: 72
|
|
14
|
+
};
|
|
15
|
+
var DocSection = class {
|
|
16
|
+
container;
|
|
17
|
+
node;
|
|
18
|
+
removed = false;
|
|
19
|
+
constructor(container, node) {
|
|
20
|
+
this.container = container;
|
|
21
|
+
this.node = node;
|
|
22
|
+
}
|
|
23
|
+
live() {
|
|
24
|
+
if (this.removed) throw new Error("this DocSection has been removed from its document and can no longer be used");
|
|
25
|
+
return this.node;
|
|
26
|
+
}
|
|
27
|
+
get pageSize() {
|
|
28
|
+
return this.live().pageSize;
|
|
29
|
+
}
|
|
30
|
+
set pageSize(value) {
|
|
31
|
+
this.live().pageSize = value;
|
|
32
|
+
}
|
|
33
|
+
get margins() {
|
|
34
|
+
return this.live().margins;
|
|
35
|
+
}
|
|
36
|
+
set margins(value) {
|
|
37
|
+
this.live().margins = value;
|
|
38
|
+
}
|
|
39
|
+
get breakType() {
|
|
40
|
+
return this.live().breakType;
|
|
41
|
+
}
|
|
42
|
+
set breakType(value) {
|
|
43
|
+
const node = this.live();
|
|
44
|
+
if (value === void 0) delete node.breakType;
|
|
45
|
+
else node.breakType = value;
|
|
46
|
+
}
|
|
47
|
+
paragraphs() {
|
|
48
|
+
return this.live().blocks.filter((block) => block.kind === "paragraph").map((block) => new DocParagraph(this.live().blocks, block));
|
|
49
|
+
}
|
|
50
|
+
appendParagraph(init) {
|
|
51
|
+
const node = this.live();
|
|
52
|
+
const paragraph = buildParagraph(init);
|
|
53
|
+
node.blocks.push(paragraph);
|
|
54
|
+
return new DocParagraph(node.blocks, paragraph);
|
|
55
|
+
}
|
|
56
|
+
tables() {
|
|
57
|
+
return this.live().blocks.filter((block) => block.kind === "table").map((block) => new DocTable(this.live().blocks, block));
|
|
58
|
+
}
|
|
59
|
+
appendTable(init) {
|
|
60
|
+
const node = this.live();
|
|
61
|
+
const table = buildTable(init);
|
|
62
|
+
node.blocks.push(table);
|
|
63
|
+
return new DocTable(node.blocks, table);
|
|
64
|
+
}
|
|
65
|
+
remove() {
|
|
66
|
+
if (this.container.length === 1) throw new Error("a doc document must carry at least one section; the last one cannot be removed");
|
|
67
|
+
const index = this.container.indexOf(this.node);
|
|
68
|
+
if (index !== -1) this.container.splice(index, 1);
|
|
69
|
+
this.removed = true;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var DocBodyImpl = class {
|
|
73
|
+
section;
|
|
74
|
+
constructor(section) {
|
|
75
|
+
this.section = section;
|
|
76
|
+
}
|
|
77
|
+
paragraphs() {
|
|
78
|
+
return this.section.blocks.filter((block) => block.kind === "paragraph").map((block) => new DocParagraph(this.section.blocks, block));
|
|
79
|
+
}
|
|
80
|
+
appendParagraph(init) {
|
|
81
|
+
const paragraph = buildParagraph(init);
|
|
82
|
+
this.section.blocks.push(paragraph);
|
|
83
|
+
return new DocParagraph(this.section.blocks, paragraph);
|
|
84
|
+
}
|
|
85
|
+
tables() {
|
|
86
|
+
return this.section.blocks.filter((block) => block.kind === "table").map((block) => new DocTable(this.section.blocks, block));
|
|
87
|
+
}
|
|
88
|
+
appendTable(init) {
|
|
89
|
+
const table = buildTable(init);
|
|
90
|
+
this.section.blocks.push(table);
|
|
91
|
+
return new DocTable(this.section.blocks, table);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var DocEditor = class {
|
|
95
|
+
body;
|
|
96
|
+
document;
|
|
97
|
+
constructor(document) {
|
|
98
|
+
if (document.kind !== "wordprocessing") throw new Error(`DocEditor requires a wordprocessing ContentDocument, got "${document.kind}"`);
|
|
99
|
+
const first = document.sections[0];
|
|
100
|
+
if (first === void 0) throw new Error("a doc document must carry at least one section");
|
|
101
|
+
this.document = document;
|
|
102
|
+
this.body = new DocBodyImpl(first);
|
|
103
|
+
}
|
|
104
|
+
get metadata() {
|
|
105
|
+
return this.document.metadata;
|
|
106
|
+
}
|
|
107
|
+
set metadata(value) {
|
|
108
|
+
this.document.metadata = mergeMetadata(this.document.metadata, value);
|
|
109
|
+
}
|
|
110
|
+
sections() {
|
|
111
|
+
return this.document.sections.map((section) => new DocSection(this.document.sections, section));
|
|
112
|
+
}
|
|
113
|
+
paragraphs() {
|
|
114
|
+
return this.body.paragraphs();
|
|
115
|
+
}
|
|
116
|
+
appendParagraph(init) {
|
|
117
|
+
return this.body.appendParagraph(init);
|
|
118
|
+
}
|
|
119
|
+
tables() {
|
|
120
|
+
return this.body.tables();
|
|
121
|
+
}
|
|
122
|
+
appendTable(init) {
|
|
123
|
+
return this.body.appendTable(init);
|
|
124
|
+
}
|
|
125
|
+
appendSection(init = {}) {
|
|
126
|
+
const node = {
|
|
127
|
+
pageSize: init.pageSize ?? PAGE_SIZE_LETTER,
|
|
128
|
+
margins: init.margins ?? DEFAULT_MARGINS,
|
|
129
|
+
blocks: []
|
|
130
|
+
};
|
|
131
|
+
if (init.breakType !== void 0) node.breakType = init.breakType;
|
|
132
|
+
this.document.sections.push(node);
|
|
133
|
+
return new DocSection(this.document.sections, node);
|
|
134
|
+
}
|
|
135
|
+
toBytes(options) {
|
|
136
|
+
return writeDocContent(this.document, options);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
function openDoc(bytes, password) {
|
|
140
|
+
return new DocEditor(readDocContent(bytes, password));
|
|
141
|
+
}
|
|
142
|
+
function createDoc(options = {}) {
|
|
143
|
+
const clock = options.clock ?? systemClock;
|
|
144
|
+
return new DocEditor({
|
|
145
|
+
kind: "wordprocessing",
|
|
146
|
+
metadata: resolveMetadataTimestamps({}, clock),
|
|
147
|
+
sections: [{
|
|
148
|
+
pageSize: options.pageSize ?? PAGE_SIZE_LETTER,
|
|
149
|
+
margins: options.margins ?? DEFAULT_MARGINS,
|
|
150
|
+
blocks: []
|
|
151
|
+
}]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
export { DocEditor, DocSection, createDoc, openDoc };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_edit_doc_run = require("./run.cjs");
|
|
3
|
+
//#region src/edit/doc/paragraph.ts
|
|
4
|
+
var DocParagraph = class {
|
|
5
|
+
container;
|
|
6
|
+
node;
|
|
7
|
+
removed = false;
|
|
8
|
+
constructor(container, node) {
|
|
9
|
+
this.container = container;
|
|
10
|
+
this.node = node;
|
|
11
|
+
}
|
|
12
|
+
live() {
|
|
13
|
+
if (this.removed) throw new Error("this DocParagraph has been removed from its container and can no longer be used");
|
|
14
|
+
return this.node;
|
|
15
|
+
}
|
|
16
|
+
get text() {
|
|
17
|
+
return this.live().runs.map((run) => run.text).join("");
|
|
18
|
+
}
|
|
19
|
+
set text(value) {
|
|
20
|
+
const node = this.live();
|
|
21
|
+
node.runs = [require_edit_doc_run.buildRun({ text: value })];
|
|
22
|
+
}
|
|
23
|
+
runs() {
|
|
24
|
+
return this.live().runs.map((run) => new require_edit_doc_run.DocRun(this.live().runs, run));
|
|
25
|
+
}
|
|
26
|
+
appendRun(init) {
|
|
27
|
+
const node = this.live();
|
|
28
|
+
const run = require_edit_doc_run.buildRun(init);
|
|
29
|
+
node.runs.push(run);
|
|
30
|
+
return new require_edit_doc_run.DocRun(node.runs, run);
|
|
31
|
+
}
|
|
32
|
+
insertRunAt(index, init) {
|
|
33
|
+
const node = this.live();
|
|
34
|
+
const run = require_edit_doc_run.buildRun(init);
|
|
35
|
+
node.runs.splice(index, 0, run);
|
|
36
|
+
return new require_edit_doc_run.DocRun(node.runs, run);
|
|
37
|
+
}
|
|
38
|
+
get styleId() {
|
|
39
|
+
return this.live().styleId;
|
|
40
|
+
}
|
|
41
|
+
set styleId(value) {
|
|
42
|
+
const node = this.live();
|
|
43
|
+
if (value === void 0) delete node.styleId;
|
|
44
|
+
else node.styleId = value;
|
|
45
|
+
}
|
|
46
|
+
get headingLevel() {
|
|
47
|
+
return this.live().headingLevel;
|
|
48
|
+
}
|
|
49
|
+
set headingLevel(level) {
|
|
50
|
+
const node = this.live();
|
|
51
|
+
if (level === void 0) delete node.headingLevel;
|
|
52
|
+
else node.headingLevel = level;
|
|
53
|
+
}
|
|
54
|
+
get alignment() {
|
|
55
|
+
return this.live().alignment;
|
|
56
|
+
}
|
|
57
|
+
set alignment(value) {
|
|
58
|
+
const node = this.live();
|
|
59
|
+
if (value === void 0) delete node.alignment;
|
|
60
|
+
else node.alignment = value;
|
|
61
|
+
}
|
|
62
|
+
get indentLeftPt() {
|
|
63
|
+
return this.live().indentLeftPt;
|
|
64
|
+
}
|
|
65
|
+
set indentLeftPt(value) {
|
|
66
|
+
const node = this.live();
|
|
67
|
+
if (value === void 0) delete node.indentLeftPt;
|
|
68
|
+
else node.indentLeftPt = value;
|
|
69
|
+
}
|
|
70
|
+
get indentRightPt() {
|
|
71
|
+
return this.live().indentRightPt;
|
|
72
|
+
}
|
|
73
|
+
set indentRightPt(value) {
|
|
74
|
+
const node = this.live();
|
|
75
|
+
if (value === void 0) delete node.indentRightPt;
|
|
76
|
+
else node.indentRightPt = value;
|
|
77
|
+
}
|
|
78
|
+
get indentFirstLinePt() {
|
|
79
|
+
return this.live().indentFirstLinePt;
|
|
80
|
+
}
|
|
81
|
+
set indentFirstLinePt(value) {
|
|
82
|
+
const node = this.live();
|
|
83
|
+
if (value === void 0) delete node.indentFirstLinePt;
|
|
84
|
+
else node.indentFirstLinePt = value;
|
|
85
|
+
}
|
|
86
|
+
get spacingBeforePt() {
|
|
87
|
+
return this.live().spacingBeforePt;
|
|
88
|
+
}
|
|
89
|
+
set spacingBeforePt(value) {
|
|
90
|
+
const node = this.live();
|
|
91
|
+
if (value === void 0) delete node.spacingBeforePt;
|
|
92
|
+
else node.spacingBeforePt = value;
|
|
93
|
+
}
|
|
94
|
+
get spacingAfterPt() {
|
|
95
|
+
return this.live().spacingAfterPt;
|
|
96
|
+
}
|
|
97
|
+
set spacingAfterPt(value) {
|
|
98
|
+
const node = this.live();
|
|
99
|
+
if (value === void 0) delete node.spacingAfterPt;
|
|
100
|
+
else node.spacingAfterPt = value;
|
|
101
|
+
}
|
|
102
|
+
get list() {
|
|
103
|
+
return this.live().list;
|
|
104
|
+
}
|
|
105
|
+
set list(value) {
|
|
106
|
+
const node = this.live();
|
|
107
|
+
if (value === void 0) delete node.list;
|
|
108
|
+
else node.list = value;
|
|
109
|
+
}
|
|
110
|
+
remove() {
|
|
111
|
+
const node = this.live();
|
|
112
|
+
const index = this.container.indexOf(node);
|
|
113
|
+
if (index !== -1) this.container.splice(index, 1);
|
|
114
|
+
this.removed = true;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function buildParagraph(init = {}) {
|
|
118
|
+
const node = {
|
|
119
|
+
kind: "paragraph",
|
|
120
|
+
runs: [require_edit_doc_run.buildRun({ text: init.text ?? "" })]
|
|
121
|
+
};
|
|
122
|
+
const paragraph = new DocParagraph([], node);
|
|
123
|
+
if (init.styleId !== void 0) paragraph.styleId = init.styleId;
|
|
124
|
+
if (init.headingLevel !== void 0) paragraph.headingLevel = init.headingLevel;
|
|
125
|
+
if (init.alignment !== void 0) paragraph.alignment = init.alignment;
|
|
126
|
+
return node;
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
exports.DocParagraph = DocParagraph;
|
|
130
|
+
exports.buildParagraph = buildParagraph;
|