web-doc 0.6.2 → 0.7.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.
Files changed (188) hide show
  1. package/THIRD_PARTY_NOTICES.md +26 -1
  2. package/dist/adapters/docx-images.d.ts +13 -4
  3. package/dist/adapters/docx-images.js +3 -0
  4. package/dist/adapters/docx-paragraphs.d.ts +65 -0
  5. package/dist/adapters/docx-paragraphs.js +165 -0
  6. package/dist/adapters/docx-prepass.d.ts +17 -0
  7. package/dist/adapters/docx-prepass.js +230 -0
  8. package/dist/adapters/office.d.ts +31 -5
  9. package/dist/adapters/office.js +60 -29
  10. package/dist/adapters/pdf.d.ts +9 -0
  11. package/dist/adapters/pdf.js +10 -0
  12. package/dist/assets/pdfium/pdfium.wasm +0 -0
  13. package/dist/contracts.d.ts +47 -2
  14. package/dist/edit/assets.d.ts +23 -0
  15. package/dist/edit/assets.js +75 -0
  16. package/dist/edit/docx/elements.d.ts +6 -0
  17. package/dist/edit/docx/elements.js +90 -0
  18. package/dist/edit/docx/engine.d.ts +51 -0
  19. package/dist/edit/docx/engine.js +473 -0
  20. package/dist/edit/docx/handlers.d.ts +3 -0
  21. package/dist/edit/docx/handlers.js +15 -0
  22. package/dist/edit/docx/ids.d.ts +45 -0
  23. package/dist/edit/docx/ids.js +101 -0
  24. package/dist/edit/docx/model.d.ts +92 -0
  25. package/dist/edit/docx/model.js +339 -0
  26. package/dist/edit/docx/operations.d.ts +37 -0
  27. package/dist/edit/docx/operations.js +3 -0
  28. package/dist/edit/docx/provider.d.ts +13 -0
  29. package/dist/edit/docx/provider.js +34 -0
  30. package/dist/edit/docx/schemas.d.ts +6 -0
  31. package/dist/edit/docx/schemas.js +192 -0
  32. package/dist/edit/docx/session.d.ts +37 -0
  33. package/dist/edit/docx/session.js +426 -0
  34. package/dist/edit/docx/structure-ops.d.ts +6 -0
  35. package/dist/edit/docx/structure-ops.js +494 -0
  36. package/dist/edit/docx/style.d.ts +45 -0
  37. package/dist/edit/docx/style.js +375 -0
  38. package/dist/edit/docx/table-ops.d.ts +4 -0
  39. package/dist/edit/docx/table-ops.js +219 -0
  40. package/dist/edit/docx/text-ops.d.ts +18 -0
  41. package/dist/edit/docx/text-ops.js +458 -0
  42. package/dist/edit/docx/text.d.ts +34 -0
  43. package/dist/edit/docx/text.js +263 -0
  44. package/dist/edit/docx/types.d.ts +191 -0
  45. package/dist/edit/docx/types.js +1 -0
  46. package/dist/edit/docx/write.d.ts +50 -0
  47. package/dist/edit/docx/write.js +352 -0
  48. package/dist/edit/engine.d.ts +117 -0
  49. package/dist/edit/engine.js +1 -0
  50. package/dist/edit/history.d.ts +53 -0
  51. package/dist/edit/history.js +101 -0
  52. package/dist/edit/ooxml/names.d.ts +20 -0
  53. package/dist/edit/ooxml/names.js +61 -0
  54. package/dist/edit/ooxml/opc.d.ts +50 -0
  55. package/dist/edit/ooxml/opc.js +150 -0
  56. package/dist/edit/ooxml/package.d.ts +82 -0
  57. package/dist/edit/ooxml/package.js +233 -0
  58. package/dist/edit/ooxml/patch.d.ts +51 -0
  59. package/dist/edit/ooxml/patch.js +250 -0
  60. package/dist/edit/ooxml/transaction.d.ts +39 -0
  61. package/dist/edit/ooxml/transaction.js +316 -0
  62. package/dist/edit/ooxml/worker.d.ts +8 -0
  63. package/dist/edit/ooxml/worker.js +12 -0
  64. package/dist/edit/ooxml/writer.d.ts +21 -0
  65. package/dist/edit/ooxml/writer.js +187 -0
  66. package/dist/edit/ooxml/xml.d.ts +74 -0
  67. package/dist/edit/ooxml/xml.js +451 -0
  68. package/dist/edit/ooxml/zip.d.ts +54 -0
  69. package/dist/edit/ooxml/zip.js +280 -0
  70. package/dist/edit/operations.d.ts +19 -0
  71. package/dist/edit/operations.js +137 -0
  72. package/dist/edit/pdf/engine/compact.d.ts +6 -0
  73. package/dist/edit/pdf/engine/compact.js +442 -0
  74. package/dist/edit/pdf/engine/document.d.ts +95 -0
  75. package/dist/edit/pdf/engine/document.js +868 -0
  76. package/dist/edit/pdf/engine/elements.d.ts +45 -0
  77. package/dist/edit/pdf/engine/elements.js +313 -0
  78. package/dist/edit/pdf/engine/existing-text.d.ts +4 -0
  79. package/dist/edit/pdf/engine/existing-text.js +424 -0
  80. package/dist/edit/pdf/engine/fonts.d.ts +78 -0
  81. package/dist/edit/pdf/engine/fonts.js +466 -0
  82. package/dist/edit/pdf/engine/geometry.d.ts +36 -0
  83. package/dist/edit/pdf/engine/geometry.js +97 -0
  84. package/dist/edit/pdf/engine/handler.d.ts +21 -0
  85. package/dist/edit/pdf/engine/handler.js +108 -0
  86. package/dist/edit/pdf/engine/images.d.ts +33 -0
  87. package/dist/edit/pdf/engine/images.js +188 -0
  88. package/dist/edit/pdf/engine/layout.d.ts +23 -0
  89. package/dist/edit/pdf/engine/layout.js +177 -0
  90. package/dist/edit/pdf/engine/operations.d.ts +67 -0
  91. package/dist/edit/pdf/engine/operations.js +3 -0
  92. package/dist/edit/pdf/engine/pages.d.ts +6 -0
  93. package/dist/edit/pdf/engine/pages.js +98 -0
  94. package/dist/edit/pdf/engine/pdfium.d.ts +195 -0
  95. package/dist/edit/pdf/engine/pdfium.js +249 -0
  96. package/dist/edit/pdf/engine/shapes.d.ts +4 -0
  97. package/dist/edit/pdf/engine/shapes.js +183 -0
  98. package/dist/edit/pdf/engine/tables.d.ts +44 -0
  99. package/dist/edit/pdf/engine/tables.js +315 -0
  100. package/dist/edit/pdf/engine/text-box.d.ts +71 -0
  101. package/dist/edit/pdf/engine/text-box.js +317 -0
  102. package/dist/edit/pdf/engine/text-layout.d.ts +28 -0
  103. package/dist/edit/pdf/engine/text-layout.js +67 -0
  104. package/dist/edit/pdf/engine/transform.d.ts +5 -0
  105. package/dist/edit/pdf/engine/transform.js +137 -0
  106. package/dist/edit/pdf/provider.d.ts +35 -0
  107. package/dist/edit/pdf/provider.js +92 -0
  108. package/dist/edit/pdf/range-map.d.ts +14 -0
  109. package/dist/edit/pdf/range-map.js +107 -0
  110. package/dist/edit/pdf/schemas.d.ts +11 -0
  111. package/dist/edit/pdf/schemas.js +291 -0
  112. package/dist/edit/pdf/selection.d.ts +5 -0
  113. package/dist/edit/pdf/selection.js +152 -0
  114. package/dist/edit/pdf/session.d.ts +53 -0
  115. package/dist/edit/pdf/session.js +273 -0
  116. package/dist/edit/pdf/types.d.ts +336 -0
  117. package/dist/edit/pdf/types.js +1 -0
  118. package/dist/edit/pptx/elements.d.ts +74 -0
  119. package/dist/edit/pptx/elements.js +301 -0
  120. package/dist/edit/pptx/engine.d.ts +37 -0
  121. package/dist/edit/pptx/engine.js +466 -0
  122. package/dist/edit/pptx/geometry.d.ts +72 -0
  123. package/dist/edit/pptx/geometry.js +193 -0
  124. package/dist/edit/pptx/handler.d.ts +7 -0
  125. package/dist/edit/pptx/handler.js +91 -0
  126. package/dist/edit/pptx/handlers.d.ts +3 -0
  127. package/dist/edit/pptx/handlers.js +21 -0
  128. package/dist/edit/pptx/image-table-ops.d.ts +5 -0
  129. package/dist/edit/pptx/image-table-ops.js +233 -0
  130. package/dist/edit/pptx/model.d.ts +69 -0
  131. package/dist/edit/pptx/model.js +170 -0
  132. package/dist/edit/pptx/operations.d.ts +50 -0
  133. package/dist/edit/pptx/operations.js +11 -0
  134. package/dist/edit/pptx/provider.d.ts +17 -0
  135. package/dist/edit/pptx/provider.js +40 -0
  136. package/dist/edit/pptx/schemas.d.ts +6 -0
  137. package/dist/edit/pptx/schemas.js +220 -0
  138. package/dist/edit/pptx/session.d.ts +44 -0
  139. package/dist/edit/pptx/session.js +114 -0
  140. package/dist/edit/pptx/shape-ops.d.ts +10 -0
  141. package/dist/edit/pptx/shape-ops.js +486 -0
  142. package/dist/edit/pptx/slide-ops.d.ts +6 -0
  143. package/dist/edit/pptx/slide-ops.js +353 -0
  144. package/dist/edit/pptx/style.d.ts +31 -0
  145. package/dist/edit/pptx/style.js +181 -0
  146. package/dist/edit/pptx/text-ops.d.ts +13 -0
  147. package/dist/edit/pptx/text-ops.js +267 -0
  148. package/dist/edit/pptx/text-write.d.ts +67 -0
  149. package/dist/edit/pptx/text-write.js +293 -0
  150. package/dist/edit/pptx/text.d.ts +41 -0
  151. package/dist/edit/pptx/text.js +99 -0
  152. package/dist/edit/pptx/types.d.ts +232 -0
  153. package/dist/edit/pptx/types.js +1 -0
  154. package/dist/edit/schema.d.ts +11 -0
  155. package/dist/edit/schema.js +275 -0
  156. package/dist/edit/session.d.ts +66 -0
  157. package/dist/edit/session.js +701 -0
  158. package/dist/edit/sessions.d.ts +8 -0
  159. package/dist/edit/sessions.js +1 -0
  160. package/dist/edit/types.d.ts +276 -0
  161. package/dist/edit/types.js +1 -0
  162. package/dist/edit/worker-engine.d.ts +31 -0
  163. package/dist/edit/worker-engine.js +91 -0
  164. package/dist/fonts/THIRD_PARTY_NOTICES.md +3 -0
  165. package/dist/fonts/manifest.json +6 -1
  166. package/dist/fonts/noto-sans-latin-cyrillic.ttf +0 -0
  167. package/dist/fonts.d.ts +2 -0
  168. package/dist/fonts.js +4 -0
  169. package/dist/headless.d.ts +4 -0
  170. package/dist/headless.js +4 -0
  171. package/dist/index.d.ts +5 -0
  172. package/dist/index.js +5 -0
  173. package/dist/limits.js +3 -0
  174. package/dist/ooxml-edit-worker.d.ts +1 -0
  175. package/dist/ooxml-edit-worker.js +8 -0
  176. package/dist/pdf-edit-worker.d.ts +1 -0
  177. package/dist/pdf-edit-worker.js +35 -0
  178. package/dist/spreadsheet-viewport.d.ts +5 -0
  179. package/dist/spreadsheet-viewport.js +11 -0
  180. package/dist/ui.js +7 -0
  181. package/dist/viewer.d.ts +6 -0
  182. package/dist/viewer.js +293 -19
  183. package/dist/viewport.d.ts +13 -0
  184. package/dist/viewport.js +126 -1
  185. package/dist/worker-protocol.d.ts +39 -2
  186. package/dist/workers/ooxml-edit-worker.js +8671 -0
  187. package/dist/workers/pdf-edit-worker.js +10844 -0
  188. package/package.json +3 -3
@@ -0,0 +1,263 @@
1
+ var _a;
2
+ import { W_NS } from "./ids.js";
3
+ /*
4
+ * The text model of a paragraph: `w:t` text, a tab, a line break (`\v`), a
5
+ * page or column break (`\f`), an inline picture or an embedded object as
6
+ * one object character, a field (`w:fldSimple`, or a complex field from
7
+ * `fldChar begin` to `end`) as its cached result text, hyperlinks and
8
+ * inline `w:sdt` as their runs, hidden runs as text, deleted text (`w:del`)
9
+ * left out. Offsets are UTF-16 code units of the paragraph's text. Every
10
+ * item remembers the XML it came from, so a later patch can keep the bytes
11
+ * of what an edit does not touch.
12
+ */
13
+ export const TAB = "\t";
14
+ export const LINE_BREAK = "\u000b";
15
+ export const PAGE_BREAK = "\f";
16
+ /** The object replacement character: an inline picture or an embedded object. */
17
+ export const OBJECT = "";
18
+ /** Wrappers whose children are read as the paragraph's own runs. */
19
+ const TRANSPARENT = new Set([
20
+ "hyperlink",
21
+ "smartTag",
22
+ "customXml",
23
+ "dir",
24
+ "bdo",
25
+ "ins",
26
+ "moveTo",
27
+ "sdtContent",
28
+ "fldSimple",
29
+ ]);
30
+ /** Wrappers whose content is deleted text: left out, the paragraph is tracked. */
31
+ const DELETED = new Set(["del", "moveFrom"]);
32
+ class Reader {
33
+ part;
34
+ items = [];
35
+ text = "";
36
+ tracked = false;
37
+ #field;
38
+ constructor(part) {
39
+ this.part = part;
40
+ }
41
+ paragraph(paragraph) {
42
+ for (const child of paragraph.children)
43
+ this.#child(child, undefined);
44
+ if (this.#field)
45
+ this.#closeField();
46
+ }
47
+ #child(node, wrapper) {
48
+ if (node.namespace !== W_NS) {
49
+ // DrawingML, math and markup compatibility live outside w:; a math
50
+ // zone or an alternate-content block counts as one object.
51
+ if (node.local === "oMath" ||
52
+ node.local === "oMathPara" ||
53
+ node.local === "AlternateContent")
54
+ this.#push("object", OBJECT, node, node, wrapper);
55
+ return;
56
+ }
57
+ switch (node.local) {
58
+ case "r":
59
+ this.#run(node, wrapper);
60
+ return;
61
+ case "sdt": {
62
+ const content = node.children.find((child) => child.local === "sdtContent" && child.namespace === W_NS);
63
+ if (content)
64
+ for (const child of content.children)
65
+ this.#child(child, node);
66
+ return;
67
+ }
68
+ case "ins":
69
+ case "moveTo":
70
+ this.#tracked();
71
+ for (const child of node.children)
72
+ this.#child(child, node);
73
+ return;
74
+ default:
75
+ break;
76
+ }
77
+ if (DELETED.has(node.local)) {
78
+ this.#tracked();
79
+ return;
80
+ }
81
+ if (TRANSPARENT.has(node.local)) {
82
+ if (node.local === "fldSimple") {
83
+ this.#simpleField(node, wrapper);
84
+ return;
85
+ }
86
+ for (const child of node.children)
87
+ this.#child(child, node);
88
+ }
89
+ }
90
+ #tracked() {
91
+ this.tracked = true;
92
+ }
93
+ /** A simple field: one item carrying the text of its result runs. */
94
+ #simpleField(node, wrapper) {
95
+ const inner = new _a(this.part);
96
+ for (const child of node.children)
97
+ inner.#child(child, node);
98
+ this.tracked ||= inner.tracked;
99
+ this.#push("field", inner.text, node, node, wrapper);
100
+ }
101
+ #run(run, wrapper) {
102
+ const rPr = run.children.find((child) => child.local === "rPr" && child.namespace === W_NS);
103
+ if (rPr) {
104
+ const marked = rPr.children.some((child) => child.namespace === W_NS &&
105
+ (child.local === "ins" || child.local === "del"));
106
+ if (marked)
107
+ this.#tracked();
108
+ }
109
+ if (this.#field)
110
+ this.#field.runs.push(run);
111
+ for (const child of run.children) {
112
+ if (child.namespace !== W_NS) {
113
+ if (child.local === "AlternateContent")
114
+ this.#emit("object", OBJECT, run, child, rPr, wrapper);
115
+ continue;
116
+ }
117
+ switch (child.local) {
118
+ case "rPr":
119
+ case "lastRenderedPageBreak":
120
+ case "instrText":
121
+ case "delInstrText":
122
+ case "delText":
123
+ break;
124
+ case "fldChar":
125
+ this.#fieldChar(child, run);
126
+ break;
127
+ case "t":
128
+ this.#emit("text", this.part.textOf(child), run, child, rPr, wrapper);
129
+ break;
130
+ case "tab":
131
+ case "ptab":
132
+ this.#emit("tab", TAB, run, child, rPr, wrapper);
133
+ break;
134
+ case "br": {
135
+ const type = this.part.attribute(child, "w:type");
136
+ if (type === "page" || type === "column")
137
+ this.#emit("pageBreak", PAGE_BREAK, run, child, rPr, wrapper);
138
+ else
139
+ this.#emit("break", LINE_BREAK, run, child, rPr, wrapper);
140
+ break;
141
+ }
142
+ case "cr":
143
+ this.#emit("break", LINE_BREAK, run, child, rPr, wrapper);
144
+ break;
145
+ case "sym": {
146
+ const code = Number.parseInt(this.part.attribute(child, "w:char") ?? "", 16);
147
+ this.#emit("text", Number.isFinite(code) && code > 0 && code <= 0x10ffff
148
+ ? String.fromCodePoint(code)
149
+ : "", run, child, rPr, wrapper);
150
+ break;
151
+ }
152
+ case "noBreakHyphen":
153
+ this.#emit("text", "‑", run, child, rPr, wrapper);
154
+ break;
155
+ case "softHyphen":
156
+ this.#emit("text", "­", run, child, rPr, wrapper);
157
+ break;
158
+ case "drawing": {
159
+ const inline = child.children.some((node) => node.local === "inline");
160
+ if (inline)
161
+ this.#emit("picture", OBJECT, run, child, rPr, wrapper);
162
+ else
163
+ this.#emit("anchor", "", run, child, rPr, wrapper);
164
+ break;
165
+ }
166
+ case "object":
167
+ case "pict":
168
+ this.#emit("object", OBJECT, run, child, rPr, wrapper);
169
+ break;
170
+ case "footnoteReference":
171
+ case "endnoteReference":
172
+ this.#emit("note", "", run, child, rPr, wrapper);
173
+ break;
174
+ case "ruby": {
175
+ const base = child.children.find((node) => node.local === "rubyBase");
176
+ if (base)
177
+ for (const node of base.children)
178
+ this.#child(node, wrapper);
179
+ break;
180
+ }
181
+ default:
182
+ break;
183
+ }
184
+ }
185
+ }
186
+ #fieldChar(node, run) {
187
+ const type = this.part.attribute(node, "w:fldCharType");
188
+ if (type === "begin") {
189
+ if (this.#field)
190
+ this.#field.inResult.push(false);
191
+ else
192
+ this.#field = { begin: run, runs: [run], text: "", inResult: [false] };
193
+ return;
194
+ }
195
+ if (!this.#field)
196
+ return;
197
+ const levels = this.#field.inResult;
198
+ if (type === "separate") {
199
+ levels[levels.length - 1] = true;
200
+ return;
201
+ }
202
+ if (type === "end") {
203
+ if (levels.length > 1)
204
+ levels.pop();
205
+ else
206
+ this.#closeField();
207
+ }
208
+ }
209
+ #closeField() {
210
+ const field = this.#field;
211
+ this.#field = undefined;
212
+ const rPr = field.begin.children.find((child) => child.local === "rPr" && child.namespace === W_NS);
213
+ this.#append({
214
+ kind: "field",
215
+ start: this.text.length,
216
+ end: this.text.length + field.text.length,
217
+ text: field.text,
218
+ run: field.begin,
219
+ child: field.begin,
220
+ ...(rPr ? { rPr } : {}),
221
+ fieldRuns: field.runs,
222
+ });
223
+ }
224
+ /** Text inside an open field goes to its result; outside it is an item. */
225
+ #emit(kind, text, run, child, rPr, wrapper) {
226
+ const field = this.#field;
227
+ if (field) {
228
+ // What Word shows: the result of the outer field, which holds the
229
+ // results of the fields nested in it and none of their instructions.
230
+ if (field.inResult.every(Boolean))
231
+ field.text += text;
232
+ return;
233
+ }
234
+ this.#push(kind, text, run, child, wrapper, rPr);
235
+ }
236
+ #push(kind, text, run, child, wrapper, rPr) {
237
+ this.#append({
238
+ kind,
239
+ start: this.text.length,
240
+ end: this.text.length + text.length,
241
+ text,
242
+ run,
243
+ child,
244
+ ...(rPr ? { rPr } : {}),
245
+ ...(wrapper ? { wrapper } : {}),
246
+ });
247
+ }
248
+ #append(item) {
249
+ this.items.push(item);
250
+ this.text += item.text;
251
+ }
252
+ }
253
+ _a = Reader;
254
+ /** Reads the text of a `w:p`. */
255
+ export function readParagraphText(part, paragraph) {
256
+ const reader = new Reader(part);
257
+ reader.paragraph(paragraph);
258
+ return { text: reader.text, items: reader.items, tracked: reader.tracked };
259
+ }
260
+ /** The first item that draws text, for the resolved style of a paragraph. */
261
+ export function firstTextItem(model) {
262
+ return model.items.find((item) => (item.kind === "text" || item.kind === "field") && item.text.length > 0);
263
+ }
@@ -0,0 +1,191 @@
1
+ import type { ApplyOptions, BinaryData, EditColor, EditElement, EditReceipt, EditSessionBase, SavedDocument, SaveOptions, TextRange } from "../types.js";
2
+ export type DocxElementKind = "paragraph" | "table" | "image" | "other";
3
+ export type DocxTextAlign = "left" | "center" | "right" | "justify";
4
+ /** Word's sixteen highlight colours (`w:highlight/@w:val`). */
5
+ export type DocxHighlight = "yellow" | "green" | "cyan" | "magenta" | "blue" | "red" | "darkBlue" | "darkCyan" | "darkGreen" | "darkMagenta" | "darkRed" | "darkYellow" | "darkGray" | "lightGray" | "black" | "white";
6
+ /** The style of a paragraph's first run with text, resolved through the style chain and the theme. */
7
+ export interface DocxTextStyle {
8
+ /** Theme fonts resolved ("minorHAnsi" becomes the minor Latin face). */
9
+ readonly fontFamily: string;
10
+ /** Points. */
11
+ readonly fontSize: number;
12
+ readonly bold: boolean;
13
+ readonly italic: boolean;
14
+ readonly underline: boolean;
15
+ /** `#RRGGBB`, `{ theme }` for a theme colour, "auto" for Word's automatic colour. */
16
+ readonly color: EditColor;
17
+ readonly highlight?: DocxHighlight;
18
+ }
19
+ export interface DocxParagraphSpacing {
20
+ /** Points before the paragraph; absent when inherited. */
21
+ readonly before?: number;
22
+ /** Points after the paragraph; absent when inherited. */
23
+ readonly after?: number;
24
+ /**
25
+ * Line spacing: points for `exact` and `atLeast`, a multiple of single
26
+ * spacing (1 = single, 1.5, 2) for `auto`; absent when inherited.
27
+ */
28
+ readonly line?: number;
29
+ readonly lineRule?: "auto" | "exact" | "atLeast";
30
+ }
31
+ export interface DocxParagraphStyle {
32
+ /** `w:pStyle`, when the paragraph names a style. */
33
+ readonly styleId?: string;
34
+ readonly align: DocxTextAlign;
35
+ readonly spacing: DocxParagraphSpacing;
36
+ /** `w:numPr`: the paragraph belongs to a list. */
37
+ readonly numbering?: {
38
+ readonly numId: number;
39
+ readonly level: number;
40
+ };
41
+ }
42
+ /** Why a paragraph's text cannot be edited in place. */
43
+ export type DocxReadOnlyReason = "tracked-changes" | "section-break" | "unsupported-content";
44
+ /**
45
+ * An element of the body story. Geometry comes from the renderer: `bounds`
46
+ * and `fragments` are the unions of the element's text runs per page, so
47
+ * an element whose pages the viewer has not laid out yet, or which draws
48
+ * no run (an empty paragraph), has `pageIndex` −1, empty `bounds` and an
49
+ * empty `fragments` list until a query names its page.
50
+ */
51
+ export interface DocxElement extends EditElement {
52
+ readonly kind: DocxElementKind;
53
+ /** Present for a paragraph: resolved style of its first run with text. */
54
+ readonly textStyle?: DocxTextStyle;
55
+ /** Present for a paragraph. */
56
+ readonly paragraphStyle?: DocxParagraphStyle;
57
+ /** Present for a table: cell text by row. */
58
+ readonly table?: {
59
+ readonly rows: readonly (readonly string[])[];
60
+ };
61
+ /** Present for a paragraph whose text cannot be edited in place. */
62
+ readonly readOnlyReason?: DocxReadOnlyReason;
63
+ /** Present for an inline picture: its declared extent in page space (CSS pixels). */
64
+ readonly imageSize?: {
65
+ readonly width: number;
66
+ readonly height: number;
67
+ };
68
+ }
69
+ export interface DocxTextStyleChange {
70
+ /** `w:rFonts` ascii and hAnsi faces. */
71
+ readonly fontFamily?: string;
72
+ /** 1–400 points. */
73
+ readonly fontSize?: number;
74
+ readonly bold?: boolean;
75
+ readonly italic?: boolean;
76
+ /** `w:u` single or none. */
77
+ readonly underline?: boolean;
78
+ /** `#RRGGBB` writes `w:color`; `{ theme }` writes the theme colour and its resolved value. */
79
+ readonly color?: EditColor;
80
+ /** `w:highlight`; "none" removes it. */
81
+ readonly highlight?: DocxHighlight | "none";
82
+ }
83
+ export interface DocxParagraphStyleChange {
84
+ readonly align?: DocxTextAlign;
85
+ /** Points; a field absent keeps its bytes. */
86
+ readonly spacing?: {
87
+ readonly before?: number;
88
+ readonly after?: number;
89
+ /** A multiple of single spacing, written with `w:lineRule="auto"`. */
90
+ readonly line?: number;
91
+ };
92
+ }
93
+ export interface DocxReplaceTextOperation {
94
+ readonly op: "replaceText";
95
+ /** A `paragraph` element. */
96
+ readonly target: string;
97
+ readonly text: string;
98
+ /** Both ends on the target; absent, the whole text; collapsed, an insertion. */
99
+ readonly range?: TextRange;
100
+ }
101
+ export interface DocxSetTextStyleOperation {
102
+ readonly op: "setTextStyle";
103
+ readonly target: string;
104
+ readonly range?: TextRange;
105
+ readonly style: DocxTextStyleChange;
106
+ }
107
+ export interface DocxSetParagraphStyleOperation {
108
+ readonly op: "setParagraphStyle";
109
+ readonly target: string;
110
+ readonly style: DocxParagraphStyleChange;
111
+ }
112
+ export interface DocxInsertParagraphOperation {
113
+ readonly op: "insertParagraph";
114
+ /** Exactly one of `before` and `after`: a paragraph or table id. */
115
+ readonly before?: string;
116
+ readonly after?: string;
117
+ readonly text: string;
118
+ readonly style?: DocxTextStyleChange;
119
+ }
120
+ export interface DocxDeleteElementOperation {
121
+ readonly op: "deleteElement";
122
+ /** A paragraph, a table or an inline picture. */
123
+ readonly target: string;
124
+ }
125
+ export interface DocxMoveElementOperation {
126
+ readonly op: "moveElement";
127
+ /** A paragraph or a table. */
128
+ readonly target: string;
129
+ /** Exactly one of `before` and `after`: a paragraph or table id of the same container. */
130
+ readonly before?: string;
131
+ readonly after?: string;
132
+ }
133
+ export interface DocxInsertTableOperation {
134
+ readonly op: "insertTable";
135
+ readonly before?: string;
136
+ readonly after?: string;
137
+ /** Cell text by row; every row has the same number of cells. 1–100 rows, 1–20 columns. */
138
+ readonly rows: readonly (readonly string[])[];
139
+ /** Relative column weights, one per column; equal when omitted. */
140
+ readonly columnWidths?: readonly number[];
141
+ }
142
+ export interface DocxSetTableCellOperation {
143
+ readonly op: "setTableCell";
144
+ /** A `table` element. */
145
+ readonly target: string;
146
+ readonly row: number;
147
+ readonly column: number;
148
+ /** The cell's new text; empty clears the cell. */
149
+ readonly text: string;
150
+ }
151
+ export interface DocxInsertImageOperation {
152
+ readonly op: "insertImage";
153
+ readonly before?: string;
154
+ readonly after?: string;
155
+ /** PNG or JPEG bytes; base64 over pure-JSON transports. */
156
+ readonly data: BinaryData;
157
+ readonly mimeType: "image/png" | "image/jpeg";
158
+ /** Points. */
159
+ readonly size: {
160
+ readonly width: number;
161
+ readonly height: number;
162
+ };
163
+ }
164
+ /** The DOCX operation union; operations are added as they ship. */
165
+ export type DocxOperation = DocxReplaceTextOperation | DocxSetTextStyleOperation | DocxSetParagraphStyleOperation | DocxInsertParagraphOperation | DocxDeleteElementOperation | DocxMoveElementOperation | DocxInsertTableOperation | DocxSetTableCellOperation | DocxInsertImageOperation;
166
+ /** DOCX saves have no fields of their own. */
167
+ export type DocxSaveOptions = SaveOptions;
168
+ /** An operation's fields without its `op`, as the typed methods take them. */
169
+ export type DocxFields<T extends DocxOperation> = T extends unknown ? Omit<T, "op"> : never;
170
+ export interface DocxEditSession extends EditSessionBase<DocxOperation, DocxElement> {
171
+ readonly format: "docx";
172
+ save(options?: DocxSaveOptions): Promise<SavedDocument>;
173
+ /** Replaces the whole text of a paragraph, or the part a range covers. */
174
+ replaceText(fields: DocxFields<DocxReplaceTextOperation>, options?: ApplyOptions): Promise<EditReceipt>;
175
+ /** Changes run properties; unspecified ones keep their bytes. */
176
+ setTextStyle(fields: DocxFields<DocxSetTextStyleOperation>, options?: ApplyOptions): Promise<EditReceipt>;
177
+ /** Changes alignment and spacing of a paragraph. */
178
+ setParagraphStyle(fields: DocxFields<DocxSetParagraphStyleOperation>, options?: ApplyOptions): Promise<EditReceipt>;
179
+ /** Adds a paragraph next to another element; its id is in `createdIds`. */
180
+ insertParagraph(fields: DocxFields<DocxInsertParagraphOperation>, options?: ApplyOptions): Promise<EditReceipt>;
181
+ /** Removes a paragraph, a table or an inline picture. */
182
+ deleteElement(fields: DocxFields<DocxDeleteElementOperation>, options?: ApplyOptions): Promise<EditReceipt>;
183
+ /** Moves a paragraph or a table next to another element of the same container. */
184
+ moveElement(fields: DocxFields<DocxMoveElementOperation>, options?: ApplyOptions): Promise<EditReceipt>;
185
+ /** Adds a table with the given cell text. */
186
+ insertTable(fields: DocxFields<DocxInsertTableOperation>, options?: ApplyOptions): Promise<EditReceipt>;
187
+ /** Changes one cell's text. */
188
+ setTableCell(fields: DocxFields<DocxSetTableCellOperation>, options?: ApplyOptions): Promise<EditReceipt>;
189
+ /** Adds a paragraph holding an inline PNG or JPEG. */
190
+ insertImage(fields: DocxFields<DocxInsertImageOperation>, options?: ApplyOptions): Promise<EditReceipt>;
191
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import { type XmlPatch } from "../ooxml/patch.js";
2
+ import { type XmlElement, type XmlPart } from "../ooxml/xml.js";
3
+ import type { EditColor } from "../types.js";
4
+ import { type DocxStyles } from "./style.js";
5
+ import type { DocxParagraphStyleChange, DocxTextStyleChange } from "./types.js";
6
+ /** Why a text cannot be written, or undefined when it can. */
7
+ export declare function textProblem(text: string): string | undefined;
8
+ /** Why a value cannot be written as an attribute: text problems plus the breaks text may hold. */
9
+ export declare function attributeProblem(value: string): string | undefined;
10
+ export declare function colorProblem(color: unknown): string | undefined;
11
+ /** Text as the engine stores it: Windows and classic Mac line ends become "\n". */
12
+ export declare function normalizeText(text: string): string;
13
+ export declare function sliceOf(part: XmlPart, node: XmlElement | undefined): string;
14
+ export declare function escapeAttributeValue(value: string): string;
15
+ /** The content elements of a run for `text`: `w:t`, `w:tab`, `w:br`. */
16
+ export declare function runContentXml(text: string): string;
17
+ /** A run with `rPr` bytes (or "") and the given content; nothing for empty content. */
18
+ export declare function runXml(rPr: string, content: string): string;
19
+ /**
20
+ * Properties with changes merged in schema order: every child of `source`
21
+ * keeps its bytes unless `set` names its local name, in which case the
22
+ * replacement (or nothing, for `null`) takes its place; new children go
23
+ * where the schema puts them. Returns "" for no properties at all.
24
+ */
25
+ export declare function mergedProperties(part: XmlPart, source: XmlElement | undefined, tag: "w:rPr" | "w:pPr", order: readonly string[], set: ReadonlyMap<string, string | null>): string;
26
+ /** `w:rPr` bytes with a text style change applied. */
27
+ export declare function changedRunProperties(part: XmlPart, rPr: XmlElement | undefined, change: DocxTextStyleChange, styles: DocxStyles): string;
28
+ /** `w:color` for a colour: RGB, automatic, or a theme name with the theme's value. */
29
+ export declare function colorXml(color: EditColor, styles: DocxStyles): string;
30
+ /** `w:pPr` bytes with alignment and spacing changed, other children kept. */
31
+ export declare function changedParagraphProperties(part: XmlPart, pPr: XmlElement | undefined, change: DocxParagraphStyleChange): string;
32
+ export declare function alignValue(align: NonNullable<DocxParagraphStyleChange["align"]>): string;
33
+ /** `w:pPr` bytes with the paragraph mark's `w:rPr` changed (created when absent). */
34
+ export declare function paragraphMarkProperties(part: XmlPart, pPr: XmlElement | undefined, change: DocxTextStyleChange, styles: DocxStyles): string;
35
+ /** `w:pPr` bytes without the section properties, for a paragraph copied next to one that ends a section. */
36
+ export declare function paragraphPropertiesWithoutSection(part: XmlPart, pPr: XmlElement | undefined): string;
37
+ /**
38
+ * The start tag of a `w:p` with its id written: the paragraph's own
39
+ * attributes, `w14:paraId` and `w14:textId` replaced.
40
+ */
41
+ export declare function paragraphStartTag(source: XmlElement | undefined, id: string): string;
42
+ /** A whole paragraph from its start tag, property bytes and content. */
43
+ export declare function paragraphXml(source: XmlElement | undefined, id: string, pPr: string, content: string): string;
44
+ /**
45
+ * Patches that declare the `w14` namespace on the document root and list
46
+ * it as ignorable, when the root does not yet; nothing when it does.
47
+ */
48
+ export declare function namespacePatches(part: XmlPart): XmlPatch[];
49
+ /** Whether the paragraph already carries a `w14:paraId`. */
50
+ export declare function isAuthored(part: XmlPart, paragraph: XmlElement): boolean;