docxkeun 0.2.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -2,6 +2,58 @@
2
2
 
3
3
  All notable changes to docxkeun and docxkeun-fonts. Versions follow [semantic versioning](https://semver.org); while the version is 0.x, minor versions may contain breaking changes.
4
4
 
5
+ ## 0.4.0 (2026-11-24)
6
+
7
+ ### docxkeun
8
+
9
+ - The `words` effect style now colours only the letters. Its shimmer and the marks it leaves are drawn on the text itself, so shaded table cells, highlighted text and pictures in the paragraph keep their own colours, and the changed words no longer sit in a tinted glow. Before, the shimmer was a coloured band blended over the line, which tinted anything that was not white, and the marks added a blurred box behind the words. With `marks: false`, the changed letters now light up for a moment instead of a tinted band passing over them.
10
+
11
+ - **Charts:** `DocxEditor.insertChart()` adds a column, bar, line, area, pie, doughnut or scatter chart (stacked and 100% stacked for column, bar and area), with a title, axis titles and legend. It looks like a chart Word has just inserted (theme colours, a white chart area without a border, 9 pt grey text), and its numbers are written into an embedded workbook, so "Edit Data" in Word shows them. `chartInfo()` reads a chart's data back as a table, and `updateChart()` changes its title, legend or data while keeping its look, and rewrites the workbook; an added series is styled like the last one in the next accent colour (keeping transparency, but not the last one's single-point formatting, trendline or error bars). A chart linked to an outside file only has its cached numbers changed. Word does not track chart changes, so neither does this. Number formats carry through: a series' `formatCode` (such as `0%`) and a chart's `categoryFormat` (such as `mmm-yy` for dates) are written to the chart and to the workbook's cells, `chartInfo()` reads them back, an update keeps each series' format by position, and numeric or date categories stay numbers instead of turning into text. So `categories` in `insertChart()`, `chartInfo()` and `updateChart()` holds strings, numbers (dates as Excel serial numbers) or `null` for a missing one; TypeScript code reading `chartInfo().categories` should allow for all three. The chart types and `ChartDataError` are exported from `docxkeun/editor`.
12
+ - **Objects:** `objects()` lists pictures, charts, diagrams, shapes, text boxes and groups with numbers. `resizeObject()`, `setObjectAlt()`, `deleteObject()`, `moveObject()` and `placeObject()` change them; resizing, alt text and floating position are applied directly, since Word does not track them, while creating, deleting, moving and switching between inline and floating are tracked. Before, only pictures could be inserted and given alt text. For an object that already floats, `placeObject()` keeps what the placement leaves out (x, y, `from`, `wrap`), so its wrap or reference can change on its own; making an inline object float still needs x and y.
13
+ - **Shapes and text boxes:** `insertShape()` adds a text box or a shape (rectangle, rounded rectangle, oval, triangle, diamond, arrows, chevron, pentagon, star, callouts, line), inline or floating (square wrap, above and below, in front of or behind the text), with text, fill and outline colours. As in Word, only pictures go inside a text box: `insertShape()`, `insertChart()` and `moveObject()` refuse shapes, text boxes, charts, SmartArt and other graphics there.
14
+ - **Breaking:** `paragraphs()` now also lists the paragraphs inside text boxes, right after the paragraph that holds the box. `find()`, `replaceAll()` and `fillTemplate()` reach text in boxes too. Code that indexes `paragraphs()` by position will see its numbers shift in documents with text boxes. Before, text in boxes could only be changed through `storyParts()`.
15
+ - Copied content (`copyBlocks()`) now gives a copied chart its own chart part and workbook (Word 2016 charts such as waterfalls too), so changing one copy no longer changes the other. `updateChart()` first gives a chart its own part when copies made by docxkeun 0.3.0 or older still share it.
16
+ - `replaceRange()` takes `{ keepObjects: true }`: pictures, charts, shapes and text boxes inside the replaced range then stay, right after the new text in their original order, and are not marked deleted with Track Changes on. It returns how many objects it kept. Without the option, objects in the range go with the old text, as when someone selects and types over them.
17
+ - The AI's marks (`aiActivity`) also notice changed charts and objects, not only text, and text changed inside a text box or shape (marked on the paragraph holding it).
18
+
19
+ ### docxkeun chat
20
+
21
+ - Claude can now insert charts (column, bar, line, area, pie, doughnut, scatter), read and update their data, insert shapes and text boxes, and resize, move, describe or delete pictures, charts, shapes and text boxes. Text box paragraphs are numbered in line, so Claude edits them like any other paragraph. Before, it could only read these.
22
+
23
+ ### docxkeun-mcp 0.3.0
24
+
25
+ - New tools: `insert_chart`, `read_chart`, `update_chart`, `insert_shape`, `edit_object` and `delete_object`. `read_document` and `list_objects` give every picture, chart, shape and text box an object number that these tools use. `read_chart` names number formats other than General (and says when the categories are dates), and `update_chart` keeps them.
26
+ - Text box paragraphs are now numbered in line, right after the paragraph holding the box, so `edit_paragraph`, `replace_text`, `format_text` and the other paragraph tools work on them. Paragraph numbers after a text box shift when a box with text is added, moved or deleted; read the document again after those tools. `replace_story_text` still works.
27
+ - `edit_object` changes a floating object's wrap or reference on its own: x and y left out keep its position. `list_objects` says where a floating object sits and how text wraps around it ("floating, 36 pt right and 12 pt down from the margin, square wrap").
28
+ - `edit_paragraph` and `replace_text` keep the pictures, charts and text boxes that sat in the middle of the text they rewrite, right after the new text, and say how many they kept. Before, rewriting such a paragraph deleted them, text box and all.
29
+ - The live preview shows tracked changes as Word's All Markup view does: inserted text underlined and deleted text struck through, in a colour per author. Before, it always showed documents as if every change were accepted, so an AI's tracked edits looked like plain edits. A **Tracked changes** checkbox switches back to that view, and the browser remembers it. The AI's effects and the selection chip find the right paragraphs in both views, and `get_selection` reads a selection made where deleted text shows, saying when the text includes deleted words. Activity events now also carry read_document's paragraph numbers (`read`).
30
+
31
+ ## 0.3.0 (2026-11-23)
32
+
33
+ ### docxkeun
34
+
35
+ - **AI effect styles:** `aiActivity: { style }` and `viewer.activity.style` pick how the paragraph the AI is changing looks: `highlight` (the band, as before), `words` (the letters themselves shimmer), `underline`, `edge`, `spotlight`, `quiet` or `sparkles`. `ACTIVITY_STYLES` lists them with labels for a picker. The mark that stays after a change follows the style: a soft tint on the paragraph (`highlight`), glowing changed words (`words`), underlined changed words (`underline`), or the ✦ margin bar (the others); `marks: false` / `viewer.activity.marksShown` turn the marks off. Every style has a still form for `animate: false` and `prefers-reduced-motion`.
36
+ - The AI's marks now build up over a run of changes instead of showing only the latest one: each follows its paragraph as others are added or removed, a paragraph changed twice is marked against its text before the first change, and `clearMarks()` starts over. `ParagraphChange.from` gives a changed paragraph's index in the old text.
37
+ - The AI's marks and effects now follow zoom changes and the comment column's width (they kept their old positions before), and the change map's ticks show the text from before.
38
+ - **Tables:** `DocxEditor.insertTable()` adds a table that spans the text width, with an optional bold header row that repeats on each page, relative column widths and alignment. It uses Word's "Table Grid" style when the document has it, or plain borders. `insertTableRows()` adds rows formatted like the row they copy, `deleteTableRows()` and `deleteTable()` remove them, and `tableOf()` finds the table a cell paragraph is in. All of them record tracked changes when Track Changes is on, and rejecting an inserted table removes it whole.
39
+ - **Copying content:** `DocxEditor.copyBlocks()` copies paragraphs and tables with their formatting, lists and pictures, optionally starting on a new page. Lists in the copy start again at 1 (or continue with `restartLists: false`). Bookmarks, comment anchors and note references are left out and counted, and ids that must be unique are renewed.
40
+ - `DocxEditor.replaceRange()` also takes pieces of text, each formatted like a run you point to (`{ text, like, format }`), so rewritten text can keep which words were bold, underlined or coloured.
41
+ - `setList` with `sameListAs` now accepts the joined list's own `format`, and its errors say what to do instead: join a paragraph that is not in a list yet by making it one first; use `start` without `sameListAs` to number from a given value.
42
+
43
+ ### docxkeun chat
44
+
45
+ - "Appearance" also picks the effect style and whether marks stay after each change, with a live sample. A reply's marks cover all its changes; opening a document or undoing a reply clears them.
46
+ - Claude now sees which words are bold, italic, underlined, struck through, superscript or subscript, and keeps them when it rewrites or translates text (it used to flatten a rewritten paragraph to one formatting).
47
+ - Claude can now copy content with its formatting and make and change tables, so "translate this document onto a new page" keeps the tables and lists instead of retyping them as plain text.
48
+
49
+ ### docxkeun-mcp 0.2.0
50
+
51
+ - The live preview's header has a **Style** list and a **Marks** switch next to "AI effects", remembered in the browser. Marks build up while the AI works on a document and start over when you open another one.
52
+ - New tools: `copy_paragraphs` copies paragraphs and tables with their formatting and lists (for example onto a new page, to translate a document), `insert_table` makes a table, and `edit_table` adds or deletes rows or deletes a table.
53
+ - `set_list` explains how to join paragraphs that are not next to each other into one list, and accepts the list's own format with `sameListAs`.
54
+ - **Text formatting is visible and kept.** `read_document` tags text formatted differently from the rest of its paragraph (`<b>`, `<i>`, `<u>`, `<s>`, `<sup>`, `<sub>`) and names a paragraph's alignment and whole-paragraph formatting in its description, e.g. `[1] (centered; bold, underlined) AGREEMENT`. `edit_paragraph`, `insert_paragraphs`, `create_document` and `replace_text` take the same tags. When `edit_paragraph` rewrites a paragraph, each tagged part copies the formatting (font, size and colour too) of the matching phrase in the original, in order. Before, rewriting a paragraph gave all of it the first run's formatting, so bold names and amounts were lost in translations and small edits alike.
55
+ - New tool `copy_document` copies a document to a new file exactly as it is (an encrypted one stays encrypted), so "make a copy" or "translate it into a new file" keeps every bit of formatting. Before, the AI could only retype the text into `create_document`, which made a blank document and lost the text and paragraph formatting, lists and tables. `create_document`'s description now sends copies to `copy_document`.
56
+
5
57
  ## 0.2.0 (2026-11-22)
6
58
 
7
59
  ### docxkeun
package/README.md CHANGED
@@ -125,6 +125,20 @@ The effects are optional: `new DocxViewer(el, { aiActivity: false })` turns them
125
125
 
126
126
  Name and colours: `aiActivity: { name: 'Aria', color: ['#0b57d0', '#1e8e3e'] }` puts "Aria is editing…" on the caret and draws the caret, shimmer, glow and change marks from blue to green; one colour (`color: '#0b57d0'`) is used for both ends. Change them at run time with `viewer.activity.name` and `viewer.activity.color` (`undefined` goes back to the default purple to orange), or from CSS with `--docxkeun-ai-color-1` and `--docxkeun-ai-color-2` (any CSS colour). The caret's label turns dark when white text would be hard to read on the colours you pick.
127
127
 
128
+ Effect styles: `aiActivity: { style: 'words' }` (or `viewer.activity.style = 'words'` at run time) picks how the paragraph being changed looks, and so which mark stays after the change. `ACTIVITY_STYLES` lists them with a label and a line for a picker:
129
+
130
+ | Style | While the AI works | After the change |
131
+ |---|---|---|
132
+ | `highlight` (default) | a tinted band sweeps over the lines | the paragraph keeps a soft tint |
133
+ | `words` | the letters themselves shimmer; nothing behind them changes | the changed words' letters keep the colours |
134
+ | `underline` | a streak runs under each line | the changed words stay underlined |
135
+ | `edge` | a soft glow breathes around the paragraph | the ✦ bar in the margin |
136
+ | `spotlight` | the rest of the page dims | the ✦ bar in the margin |
137
+ | `quiet` | only the caret and a pulsing margin bar | the ✦ bar in the margin |
138
+ | `sparkles` | small ✦ drift over the paragraph | the ✦ bar in the margin |
139
+
140
+ Marks build up over a run of changes, each following its paragraph as others are added or removed (a paragraph changed twice is marked against its text before the first change), until `viewer.activity.clearMarks()`: the chat app clears them when you send a new message, the live preview when you open another document. `marks: false` (or `viewer.activity.marksShown = false`) leaves nothing behind. The change map on the right edge jumps to each change, and its ticks show the text from before.
141
+
128
142
  ### Viewer UI
129
143
 
130
144
  Four optional parts share one look and one frame: a toolbar, a navigation panel, a comment column and a right-click menu. With none enabled the viewer's DOM is unchanged.
@@ -181,7 +195,7 @@ await editor.resolveComment(id);
181
195
  const bytes = await viewer.document!.save();
182
196
  ```
183
197
 
184
- Also available: `insertText`, `appendText`, `replaceRange`, `replaceAll`, `deleteRange` (across paragraphs), `insertParagraph`, `deleteParagraph`, `setParagraphStyle`, `formatParagraph` (alignment, right-to-left, indents, spacing, keep rules), `insertImage`, `addFootnote`, `setHeader` / `setFooter` / `removeHeader` / `removeFooter` / `headersAndFooters()`, `await removeHyperlink` (async since it also drops the link's relationship when unused), `setHyperlinkTarget`, `setImageAlt`, `clearFormatting`, `hyperlinks()`, `bookmarks()`, `removeBookmark`, `editComment`, `deleteComment`, `addEditableRange`, `removeEditableRange`.
198
+ Also available: `insertText`, `appendText`, `replaceRange` (text, or pieces each formatted like a given run: `[{ text, like: boldRun }, { text, like: plainRun }]`; with `{ keepObjects: true }` pictures, charts and text boxes in the range stay, after the new text), `replaceAll`, `deleteRange` (across paragraphs), `insertParagraph`, `deleteParagraph`, `setParagraphStyle`, `formatParagraph` (alignment, right-to-left, indents, spacing, keep rules), `insertImage`, `addFootnote`, `setHeader` / `setFooter` / `removeHeader` / `removeFooter` / `headersAndFooters()`, `await removeHyperlink` (async since it also drops the link's relationship when unused), `setHyperlinkTarget`, `setImageAlt`, `clearFormatting`, `hyperlinks()`, `bookmarks()`, `removeBookmark`, `editComment`, `deleteComment`, `addEditableRange`, `removeEditableRange`.
185
199
 
186
200
  ```ts
187
201
  // Tracked changes: record edits as Word revisions, then review them.
@@ -220,6 +234,62 @@ await editor.setList([extra], { sameListAs: items[1]! }); // continue an ex
220
234
  await editor.setList(items, { format: 'none' }); // no longer a list
221
235
  ```
222
236
 
237
+ Tables and copies: `insertTable` builds a table that spans the text width (Word's "Table Grid" style when the document has it, otherwise plain borders), `insertTableRows` / `deleteTableRows` / `deleteTable` change one, and `tableOf(paragraph)` finds the table a cell paragraph is in. `copyBlocks` copies paragraphs and tables with their formatting, lists and pictures, for example to translate a document onto a new page. With Track Changes on, all of these are recorded as revisions.
238
+
239
+ ```ts
240
+ const [first, last] = [editor.paragraphs()[0]!.el, editor.paragraphs().at(-1)!.el];
241
+ const { blocks, dropped } = await editor.copyBlocks(first, last, 'end', { pageBreak: true }); // lists in the copy start again at 1
242
+ // dropped: { comments, notes, bookmarks } left out of the copy, since they can exist only once
243
+
244
+ const table = editor.insertTable({ after: blocks.at(-1)! }, [
245
+ ['No', 'Description', 'Total'],
246
+ ['1', 'Land benefit value', 'Rp 201.801.600'],
247
+ ], { header: true, widths: [1, 4, 2] }); // bold header row, repeated on each page
248
+ editor.insertTableRows(table, 2, [['2', 'Admin fee', 'Rp 500.000']]); // copies the formatting of the row above
249
+ editor.deleteTableRows(table, 2); // 0-based; deleting every row deletes the table
250
+ ```
251
+
252
+ Charts, shapes and objects: `insertChart` writes a chart with its data in an embedded workbook (Word's "Edit Data" opens it), `updateChart` changes it, and `insertShape` adds a text box or shape. `objects()` lists pictures, charts, shapes and text boxes in document order. A text box's paragraphs appear in `paragraphs()` right after the paragraph holding it, so `find` and `replaceAll` reach them too. As in Word, only pictures go inside a text box. Number formats (`formatCode` on a series, `categoryFormat` for numbers or dates) go into the chart and its workbook and survive updates. `placeObject` on an object that already floats keeps what you leave out, so `{ wrap: 'behind' }` alone re-wraps it.
253
+
254
+ ```ts
255
+ const at = editor.find('Quarterly sales')[0]!.end;
256
+ await editor.insertChart(at, {
257
+ type: 'column', title: 'Sales by quarter',
258
+ categories: ['Q1', 'Q2', 'Q3'],
259
+ series: [{ name: '2026', values: [120, 150, 170] }],
260
+ });
261
+ await editor.insertShape(at, { shape: 'textBox', text: 'Draft\nfigures', width: 150, place: { x: 300, y: 0, from: 'paragraph', wrap: 'square' } });
262
+
263
+ const chart = editor.objects().find((o) => o.kind === 'chart')!; // pictures, charts, diagrams, shapes, text boxes, groups
264
+ const table = editor.chartInfo(chart); // { kind, title, categories, series, legend, … }
265
+ await editor.updateChart(chart, { series: [...table.series, { name: '2027', values: [130, 160, 190] }] }); // replaces the whole table
266
+ editor.resizeObject(chart, { width: 400 }); // points; the height keeps the proportions
267
+ ```
268
+
269
+ ### Creating a document
270
+
271
+ `createDocx()` starts a blank document: A4 with 2.54 cm margins, Calibri 11 pt, and Word's Normal, Heading 1, Heading 2, Hyperlink and Table Grid styles. Every editing call above works on it, in Node or the browser, with no viewer needed.
272
+
273
+ ```ts
274
+ import { writeFile } from 'node:fs/promises';
275
+ import { createDocx } from 'docxkeun';
276
+ import { DocxEditor } from 'docxkeun/editor';
277
+
278
+ const doc = await createDocx();
279
+ const editor = new DocxEditor(doc);
280
+
281
+ const title = editor.paragraphs()[0]!.el; // a new document starts with one empty paragraph
282
+ editor.appendText(title, 'Quarterly report');
283
+ editor.setParagraphStyle(title, 'Heading1');
284
+
285
+ editor.insertParagraph('end', 'Sales grew in every quarter, helped by:');
286
+ const reasons = ['A new distributor in Surabaya', 'The online store'].map((text) => editor.insertParagraph('end', text));
287
+ await editor.setList(reasons, { format: 'bullet' });
288
+ editor.insertTable('end', [['Quarter', 'Sales'], ['Q1', '120'], ['Q2', '150']], { header: true, widths: [1, 2] });
289
+
290
+ await writeFile('report.docx', await doc.save());
291
+ ```
292
+
223
293
  ### PDF
224
294
 
225
295
  ```ts
@@ -302,6 +372,15 @@ const DocxView = createDocxViewerComponent(React); // no React dependency in do
302
372
 
303
373
  [`docxkeun-mcp`](packages/mcp#readme) is an [MCP](https://modelcontextprotocol.io) server built on docxkeun. It gives Claude Code, Claude Desktop and other MCP clients tools to read documents (including pictures, charts, equations, headers, footers and notes), find and replace text, fill templates, format paragraphs, insert pictures and footnotes, comment, record and review tracked changes, lock regions, set protection and passwords, and export PDFs, limited to the folders you choose and to a role (viewer, commenter, editor or owner).
304
374
 
375
+ ![An AI assistant edits a Word document through docxkeun-mcp while the live preview shows each change: it rewrites a summary, adds a column chart from a table, makes tracked edits, comments on a table cell and exports a PDF](https://raw.githubusercontent.com/kevinkjs/docxkeun/main/.github/assets/docxkeun-mcp-demo.gif)
376
+
377
+ <details>
378
+ <summary>The same demo as a 1080p video</summary>
379
+
380
+ https://github.com/user-attachments/assets/22feb021-8290-4024-ae5d-2ae4b8d345eb
381
+
382
+ </details>
383
+
305
384
  ```bash
306
385
  claude mcp add docxkeun -- npx -y docxkeun-mcp ~/Documents/contracts
307
386
  ```
@@ -360,7 +439,7 @@ Known limits:
360
439
  - **Pictures:** only the first frame of a GIF and the first page of a TIFF; JPEG-compressed and CMYK TIFFs are not decoded. EMF+-only pictures (some Office 2007+ charts pasted as pictures) and clipping inside metafiles are not supported.
361
440
  - **Equations:** no line breaks inside an equation and no equation numbers. Math symbols missing from your fonts fall back to other fonts (the bundled fonts have no math font such as Cambria Math).
362
441
  - **Right-to-left and complex scripts:** the bundled fonts have no Arabic or Indic letters; register a font that has them (for example Arial, Times New Roman or Noto) for PDF export. The viewer leaves shaping these scripts to the browser.
363
- - **Editing:** creating or changing shapes, charts and equations, moving or resizing pictures, and editing table structure (rows, columns, merging) are not supported. A keystroke still paginates the whole document, re-using the measured lines of unchanged paragraphs.
442
+ - **Editing:** creating or changing equations and SmartArt, and changing a table's columns or merged cells, are not supported. Charts, shapes, text boxes and pictures can be inserted, changed, resized and moved from code (`DocxEditor`), but not yet on the page. Rows can be added and deleted from code, not yet on the page. A keystroke still paginates the whole document, re-using the measured lines of unchanged paragraphs.
364
443
 
365
444
  ## Development
366
445
 
@@ -371,7 +450,7 @@ pnpm dev # playground at http://localhost:5199
371
450
  pnpm build # dist/
372
451
  ```
373
452
 
374
- Tests and the playground use the fonts in `packages/fonts`. Two optional checks compare them with Arial and Times New Roman when those are installed. See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute and release, and [SECURITY.md](SECURITY.md) to report a vulnerability.
453
+ Tests and the playground use the fonts in `packages/fonts`. Two optional checks compare them with Arial and Times New Roman when those are installed. After `pnpm build` and `pnpm build:mcp`, `node packages/mcp/demo/record.mjs` records the docxkeun-mcp demo again (it needs Google Chrome and writes `docxkeun-mcp-demo.mp4` and `.gif` to `packages/mcp/demo/out/`; the README GIF is a copy in `.github/assets`). See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute and release, and [SECURITY.md](SECURITY.md) to report a vulnerability.
375
454
 
376
455
  ## License
377
456
 
@@ -1,9 +1,12 @@
1
+ import { type ChartChanges, type NewChart } from '../charts/write.js';
1
2
  import { type HeaderFooterInfo, type HeaderFooterKind, type HeaderFooterOptions, type HeaderFooterType } from './headers.js';
2
3
  import type { DocParagraph, Block } from '../model/content.js';
3
4
  import type { DocxDocument } from '../model/document.js';
4
5
  import { type XmlElement } from '../xml/index.js';
5
6
  import { type ListFormat, type ListItem } from './lists.js';
7
+ import { type CopyDropped, type TableOptions } from './tables.js';
6
8
  import { type Revision, type RevisionFilter } from './revisions.js';
9
+ import { type ChartInfo, type ChartUpdate, type DocObject, type NewShape, type ObjectPlacement } from './objects.js';
7
10
  import { EditError, type DocPosition, type DocRange } from './positions.js';
8
11
  export type EditAction = 'edit' | 'format' | 'comment' | 'reply' | 'resolveComment' | 'editComment' | 'deleteComment' | 'link' | 'bookmark' | 'fillForm' | 'protect' | 'review';
9
12
  /**
@@ -70,6 +73,13 @@ export interface TextFormat {
70
73
  smallCaps?: boolean;
71
74
  hidden?: boolean;
72
75
  }
76
+ /** A piece of new text for `replaceRange`: formatted like the run `like` (default: the range's first run), then `format`. */
77
+ export interface TextPiece {
78
+ text: string;
79
+ /** A w:r element whose formatting the piece copies. */
80
+ like?: XmlElement;
81
+ format?: TextFormat;
82
+ }
73
83
  /** Paragraph formatting for `formatParagraph` (lengths in points; undefined leaves a property alone). */
74
84
  export interface ParagraphFormat {
75
85
  align?: 'left' | 'center' | 'right' | 'justify';
@@ -121,8 +131,13 @@ export interface ParagraphText {
121
131
  text: string;
122
132
  segments: TextSegment[];
123
133
  }
124
- /** Every paragraph of a block list (including table cells), in document order. */
125
- export declare function paragraphsOf(blocks: Block[], out?: DocParagraph[]): DocParagraph[];
134
+ /**
135
+ * Every paragraph of a block list (including table cells), in document order. With `textBoxes`,
136
+ * the paragraphs of the text boxes in a paragraph follow it (a group's boxes depth first).
137
+ */
138
+ export declare function paragraphsOf(blocks: Block[], out?: DocParagraph[], options?: {
139
+ textBoxes?: boolean;
140
+ }): DocParagraph[];
126
141
  export declare function paragraphText(para: DocParagraph, options?: {
127
142
  objects?: boolean;
128
143
  }): ParagraphText;
@@ -184,6 +199,17 @@ export declare class DocxEditor {
184
199
  private index;
185
200
  private changed;
186
201
  private check;
202
+ /**
203
+ * Permission for a change Word can't track (an object's size, a floating object's position or
204
+ * wrap, alt text, chart data): it applies directly even with Track Changes on, so it is refused
205
+ * where only tracked changes are allowed. Locks hold as for any edit.
206
+ */
207
+ private checkUntracked;
208
+ /**
209
+ * Word stores a text box twice: DrawingML in mc:Choice and an old VML copy in mc:Fallback. A
210
+ * change inside the box (at any of `nodes`) leaves the copy stale, so it goes.
211
+ */
212
+ private dropStaleFallbacks;
187
213
  /** The locked content control around a node, if any. */
188
214
  private lockAround;
189
215
  /** Throw LockedRegionError when a range touches a locked region (or would delete one). */
@@ -207,7 +233,10 @@ export declare class DocxEditor {
207
233
  offset: number;
208
234
  };
209
235
  }): DocRange;
210
- /** Every paragraph of the story (the body by default), including those in tables, in document order. */
236
+ /**
237
+ * Every paragraph of the story (the body by default), including those in tables, in document
238
+ * order. In the body, a text box's paragraphs come right after the paragraph holding the box.
239
+ */
211
240
  paragraphs(): DocParagraph[];
212
241
  /** Range covering a paragraph's text (undefined for paragraphs without text). */
213
242
  paragraphRange(paragraph: XmlElement | DocParagraph): DocRange | undefined;
@@ -234,6 +263,100 @@ export declare class DocxEditor {
234
263
  name?: string;
235
264
  maxWidth?: number;
236
265
  }): Promise<XmlElement>;
266
+ /** Declare namespace prefixes on the story's root element where they are missing. */
267
+ private declare;
268
+ /** An id for a new drawing (wp:docPr ids must be unique in the document); the root gets the prefixes drawings use. */
269
+ private newDrawingId;
270
+ /** Fresh ids for copied content (see `cleanCopy`): tracked changes, drawings and content controls stay unique. */
271
+ private copyIds;
272
+ /** Pictures, charts, SmartArt, shapes, text boxes and groups, numbered from 1 in document order. */
273
+ objects(): DocObject[];
274
+ /**
275
+ * The run's child holding an object (its w:drawing or w:pict, or the mc:AlternateContent around
276
+ * it), found in the tree as it is now; EditError when the object is no longer in the document or
277
+ * is marked deleted (as the original of a tracked move is).
278
+ */
279
+ private objectNodeOf;
280
+ /** The child of the nearest run that holds `node` (or is it). */
281
+ private runChildHolding;
282
+ /** The range of an object, for access and lock checks. */
283
+ private objectRange;
284
+ /**
285
+ * Insert a chart inline at a position, with its data in an embedded workbook (so Word's "Edit
286
+ * Data" shows it). Without a size it gets Word's 432 × 252 pt, shrunk to the section's text width;
287
+ * with one side, the other keeps those proportions. Not inside a text box (Word puts only pictures
288
+ * there). Returns the w:drawing.
289
+ */
290
+ insertChart(at: DocPosition, chart: NewChart & {
291
+ width?: number;
292
+ height?: number;
293
+ alt?: string;
294
+ }): Promise<XmlElement>;
295
+ /**
296
+ * Insert a text box or a preset shape at a position, with optional text (each line a paragraph,
297
+ * listed by `paragraphs()` right after the paragraph holding it). By default it floats at the top
298
+ * left of the paragraph with square wrap; see `NewShape` for sizes and colours. Not inside a
299
+ * text box (Word doesn't nest them). Returns the w:drawing.
300
+ */
301
+ insertShape(at: DocPosition, shape: NewShape): Promise<XmlElement>;
302
+ /** A chart's data (type, titles, legend, categories, series) and where it comes from. */
303
+ chartInfo(obj: DocObject): ChartInfo;
304
+ /**
305
+ * Change a chart's titles, legend or data, keeping its formatting (see `patchChartSpace`). New
306
+ * data must suit the chart's type, and rewrites the embedded workbook; a chart with an old embedded
307
+ * object or no workbook gets a new one. A chart linked to an outside file only has its cached data
308
+ * changed: the file is not, and Word's refresh brings its numbers back. A chart part other charts
309
+ * share is copied for this chart first (see `ownChart`). Word does not track chart changes, so
310
+ * neither does this.
311
+ */
312
+ updateChart(obj: DocObject, changes: ChartChanges): Promise<ChartUpdate>;
313
+ /**
314
+ * The chart part behind a chart object, for this chart alone: a part that other charts point at
315
+ * too (as copies made by docxkeun 0.3.0 and older do) is copied first, with its workbook, and this
316
+ * chart (and `obj.chartPart`) moves to the copy, so changing it leaves the others alone.
317
+ */
318
+ private ownChart;
319
+ /**
320
+ * Give every chart under `nodes` (c:chart, and Word 2016's cx:chart) its own copy of its chart part
321
+ * (and workbook), so copies change independently.
322
+ */
323
+ private copyChartParts;
324
+ /**
325
+ * Resize an object (points). With one side given, the other keeps the object's proportions. A
326
+ * group's shapes scale with it; a chart redraws to fit. Word doesn't track size, so this applies
327
+ * directly, and is refused where only tracked changes are allowed.
328
+ */
329
+ resizeObject(obj: DocObject, size: {
330
+ width?: number;
331
+ height?: number;
332
+ }): void;
333
+ /** Set an object's alt text (empty removes it). Not tracked, as in Word (see `resizeObject`). */
334
+ setObjectAlt(obj: DocObject, alt: string): void;
335
+ /** Delete an object. With Track Changes on the deletion is tracked: its run (and any text in it) is marked deleted. */
336
+ deleteObject(obj: DocObject): void;
337
+ /**
338
+ * Move an object to `at`, keeping its size and placement (a floating object is anchored there
339
+ * instead). With Track Changes on this is tracked as Word tracks a cut and paste: the original is
340
+ * marked deleted and a copy inserted (a chart's copy gets its own chart part and workbook). Only
341
+ * pictures can go inside a text box, and an object there can only be inline.
342
+ */
343
+ moveObject(obj: DocObject, at: DocPosition): Promise<void>;
344
+ /**
345
+ * Place an object inline, or floating at a position with a wrap style. Moving or re-wrapping a
346
+ * floating object (what `place` leaves out of x, y, `from` and `wrap`, it keeps) isn't tracked by Word, so it applies
347
+ * directly and is refused where only tracked changes are allowed. Switching between inline and
348
+ * floating is tracked like a move when Track Changes is on: the original is marked deleted and a
349
+ * copy inserted right after it.
350
+ */
351
+ placeObject(obj: DocObject, place: ObjectPlacement): Promise<void>;
352
+ /** A new, empty run at `at` (a tracked insertion when tracking) formatted like `like`, for an object. */
353
+ private objectRun;
354
+ /**
355
+ * A tracked move: a copy of the object (`node` is the run's child holding it), changed by
356
+ * `change`, goes in at `at` as an insertion, with its own drawing id and chart part; the original
357
+ * is marked deleted.
358
+ */
359
+ private replaceTracked;
237
360
  /** Add a footnote whose reference mark goes at a position. Returns the note's id. */
238
361
  addFootnote(at: DocPosition, text: string): Promise<string>;
239
362
  /** Headers and footers by section and page type, with their text ({PAGE} for page fields). */
@@ -280,8 +403,25 @@ export declare class DocxEditor {
280
403
  appendText(paragraph: XmlElement, text: string, format?: TextFormat): XmlElement;
281
404
  /** Delete a range (it may span paragraphs, but not table cells). */
282
405
  deleteRange(range: DocRange): void;
283
- /** Replace a range with text formatted like the range's first run. */
284
- replaceRange(range: DocRange, text: string, format?: TextFormat): void;
406
+ /**
407
+ * Replace a range with text formatted like the range's first run, or with pieces of text that are
408
+ * each formatted like their own `like` run (for example to rewrite a sentence and keep which words
409
+ * were bold). `format` is applied on top. Objects in the range (pictures, charts, shapes, text
410
+ * boxes) go with the old text, as when a user selects and types over them; with `keepObjects` they
411
+ * stay, right after the new text in their original order (not marked deleted when tracking).
412
+ * Returns how many objects were kept.
413
+ */
414
+ replaceRange(range: DocRange, text: string | TextPiece[], format?: TextFormat, options?: {
415
+ keepObjects?: boolean;
416
+ }): number;
417
+ /**
418
+ * Take the objects (see OBJECT_NODES) between two marks out of their runs, for `replaceRange`
419
+ * with keepObjects: they come back in `keep.runs`, in a run like the one they were in, and still in
420
+ * a tracked insertion when they were in one. Objects already marked deleted, and anything inside an
421
+ * object in the range (a text box's own runs), are left alone. A range inside a text box keeps the
422
+ * objects of its own runs: those share the range's holding run.
423
+ */
424
+ private takeObjects;
285
425
  /** Replace every match; returns how many were replaced. */
286
426
  replaceAll(query: string | RegExp, replacement: string | ((m: Match) => string)): number;
287
427
  /**
@@ -312,6 +452,51 @@ export declare class DocxEditor {
312
452
  format?: TextFormat;
313
453
  }): XmlElement;
314
454
  deleteParagraph(paragraph: XmlElement): void;
455
+ /** The block (paragraph, table or content control) of the body that holds `node`. */
456
+ private topBlock;
457
+ /** Put new blocks into the body before/after the block holding `ref`, or at the start or end. */
458
+ private placeBlocks;
459
+ /** Permission to add content next to `where`. */
460
+ private checkPlace;
461
+ /**
462
+ * Copy the body's blocks from the one holding `from` to the one holding `to` (a table is copied
463
+ * whole) and put the copies at `where`, with their formatting, lists, tables and pictures. Lists
464
+ * in the copy number from the start again unless `restartLists` is false, and `pageBreak` starts
465
+ * the copy on a new page. What may exist only once (bookmarks, comment anchors, note references)
466
+ * is left out of the copy and counted in `dropped`.
467
+ */
468
+ copyBlocks(from: XmlElement, to: XmlElement, where: {
469
+ before?: XmlElement;
470
+ after?: XmlElement;
471
+ } | 'start' | 'end', options?: {
472
+ pageBreak?: boolean;
473
+ restartLists?: boolean;
474
+ }): Promise<{
475
+ blocks: XmlElement[];
476
+ dropped: CopyDropped;
477
+ }>;
478
+ /**
479
+ * Insert a table of text (`rows` of cell texts; "\n" in a cell starts a new paragraph) before or
480
+ * after the block holding a paragraph, or at the start or end. It spans the text width.
481
+ */
482
+ insertTable(where: {
483
+ before?: XmlElement;
484
+ after?: XmlElement;
485
+ } | 'start' | 'end', rows: string[][], options?: TableOptions): XmlElement;
486
+ /** The table holding a paragraph (the innermost one). */
487
+ tableOf(paragraph: XmlElement): XmlElement;
488
+ /** Permission to change a table: its whole text. */
489
+ private checkTable;
490
+ /**
491
+ * Insert rows into a table before row `at` (0-based; the row count appends). Each new row copies
492
+ * the formatting of the row next to it and gets the texts of one entry of `rows`.
493
+ */
494
+ insertTableRows(table: XmlElement, at: number, rows: string[][]): XmlElement[];
495
+ /** Delete rows `from` to `to` (0-based, inclusive) of a table; deleting them all deletes the table. */
496
+ deleteTableRows(table: XmlElement, from: number, to?: number): void;
497
+ /** Delete a whole table. */
498
+ deleteTable(table: XmlElement): void;
499
+ private markRowDeleted;
315
500
  setParagraphStyle(paragraph: XmlElement, styleId: string): void;
316
501
  /** Change paragraph formatting: alignment, direction, indents, spacing and keep rules. */
317
502
  formatParagraph(paragraph: XmlElement, format: ParagraphFormat): void;
@@ -345,7 +530,7 @@ export declare class DocxEditor {
345
530
  }): Promise<void>;
346
531
  /** Remove a hyperlink relationship that nothing in this part refers to any more. */
347
532
  private dropHyperlinkRel;
348
- /** Set the alt text (wp:docPr/@descr) of a picture or drawing. */
533
+ /** Set the alt text (wp:docPr/@descr) of a picture or drawing. Not tracked, as in Word (see `setObjectAlt`). */
349
534
  setImageAlt(drawing: XmlElement, text: string): void;
350
535
  /** Unwrap a w:hyperlink, keeping its text. */
351
536
  removeHyperlink(link: XmlElement): Promise<void>;