bun-docx 0.6.1 → 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 (3) hide show
  1. package/README.md +19 -11
  2. package/dist/index.js +1200 -198
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -31,7 +31,7 @@ bunx bun-docx read doc.docx
31
31
 
32
32
  ```sh
33
33
  docx create FILE [--title T] [--author A] [--text "..."]
34
- docx read FILE [--markdown [--from pN] [--to pN] [--changes] [--comments]]
34
+ docx read FILE [--markdown [--from pN] [--to pN] [--accepted | --baseline] [--comments]]
35
35
  docx insert FILE --after p3 --text "..." [--style HeadingN] [--color HEX] [--bold] [--italic] [--url URL]
36
36
  docx insert FILE --after p3 --runs '[{"type":"text","text":"X","bold":true}]'
37
37
  docx edit FILE --at p3 --text "..." | --runs '[...]'
@@ -40,7 +40,7 @@ docx delete FILE --at p3
40
40
  docx find FILE QUERY [--regex] [--ignore-case] [--all] [--nth N]
41
41
  docx replace FILE PATTERN REPLACEMENT [--regex] [--ignore-case] [--all] [--limit N] [--dry-run]
42
42
 
43
- docx wc FILE [LOCATOR]
43
+ docx wc FILE [LOCATOR] [--accepted | --baseline]
44
44
  docx outline FILE
45
45
 
46
46
  docx comments add FILE --range p3:5-20 --text "..." [--author NAME]
@@ -59,13 +59,16 @@ docx hyperlinks replace FILE --at linkN --with URL
59
59
  docx hyperlinks delete FILE --at linkN
60
60
 
61
61
  docx track-changes FILE on|off
62
+ docx track-changes list FILE
63
+ docx track-changes accept FILE (--at tcN | --all)
64
+ docx track-changes reject FILE (--at tcN | --all)
62
65
  docx info schema [--ts]
63
66
  docx info locators [--json]
64
67
  ```
65
68
 
66
69
  Every command has `--help`. Mutating commands accept `--dry-run` and `-o/--output PATH` (write to a parallel file instead of overwriting `FILE`). JSON output by default for `read` and `*.list`; structured `{ok, code, error, hint}` on failure.
67
70
 
68
- When `<w:trackChanges/>` is set in the doc (toggle via `docx track-changes FILE on`), `insert`/`edit`/`delete`/`replace` automatically emit `<w:ins>`/`<w:del>` markers. Author resolution: per-call `--author NAME` overrides `$DOCX_AUTHOR`, which falls back to `docx-cli`. To make a one-off untracked edit, flip the flag off, edit, then flip it back on. `find` results inside tracked-change wrappers carry a `trackedChanges` array so agents can decide what to do with hits in pending insertions/deletions.
71
+ When `<w:trackChanges/>` is set in the doc (toggle via `docx track-changes FILE on`), `insert`/`edit`/`delete`/`replace` automatically emit `<w:ins>`/`<w:del>` markers. Author resolution: per-call `--author NAME` overrides `$DOCX_AUTHOR`, which falls back to `docx-cli`. To make a one-off untracked edit, flip the flag off, edit, then flip it back on. `find` results inside tracked-change wrappers carry a `trackedChanges` array so agents can decide what to do with hits in pending insertions/deletions. `docx track-changes list FILE` returns a JSON inventory of every revision wrapper (`<w:ins>` / `<w:del>` / `<w:moveFrom>` / `<w:moveTo>`) with stable `tcN` ids, author, date, paragraph location, and the affected text. `docx track-changes accept FILE --at tcN | --all` incorporates changes — additive wrappers (`<w:ins>` / `<w:moveTo>`) get unwrapped, subtractive wrappers (`<w:del>` / `<w:moveFrom>`) get deleted; `reject` is the inverse (additive deleted, subtractive unwrapped after `<w:delText>` → `<w:t>`). moveFrom/moveTo halves are processed independently, so `--all` handles a complete move; targeting one half by `tcN` leaves the other in place. Accept/reject themselves bypass tracking — they're doc surgery, not edits.
69
72
 
70
73
  OOXML has no native tracked-change form for hyperlink edits or image swaps, so when track-changes is on, `hyperlinks add/replace/delete` and `images replace` auto-emit a `[docx-cli] …` comment anchored to the affected span/run instead. The comment carries the same `--author` attribution as the other tracked operations. Word itself silently bypasses tracking for these — we trade silence for an explicit audit trail.
71
74
 
@@ -85,9 +88,14 @@ OOXML has no native tracked-change form for hyperlink edits or image swaps, so w
85
88
  - Footnotes / endnotes → inline `[^fnN]` / `[^enN]` refs with GFM footnote definitions at end of output
86
89
  - Charts / SmartArt / shapes / other non-picture drawings → `` `[chart]` `` / `` `[smartart]` `` / `` `[shape]` `` / `` `[drawing]` `` placeholders
87
90
 
88
- `--from LOC` and `--to LOC` slice by top-level block (both inclusive). Accepts paragraph, table, cell, span, and range locators; cell/span/range collapse to their enclosing top-level block. Comment/image/hyperlink locators are rejected.
91
+ `--from LOC` and `--to LOC` slice by top-level block (both inclusive). Accepts paragraph, table, cell, span, and range locators; cell/span/range collapse to their enclosing top-level block. Comment/image/hyperlink/tracked-change locators are rejected.
89
92
 
90
- `--changes` renders tracked insertions and deletions as `<ins>`/`<del>` instead of producing the accepted view (which silently drops deletions and inlines insertions).
93
+ **Tracked changes three views.** By default, additive wrappers (`<w:ins>`, `<w:moveTo>`) render as CriticMarkup `{++text++}[^tcN]` and subtractive wrappers (`<w:del>`, `<w:moveFrom>`) as `{--text--}[^tcN]`, with `[^tcN]: insertion|deletion|moveTo|moveFrom by author (date)` definitions appended after any comment/footnote/endnote definitions. The `[^tcN]` reference is a stable positional id (`tc0`, `tc1`, …) that's also addressable as a locator and reported by `docx track-changes list`. Two flags switch view; they're mutually exclusive:
94
+
95
+ - `--accepted` — post-accept view: `<w:del>` and `<w:moveFrom>` runs are dropped, `<w:ins>` and `<w:moveTo>` runs render as plain text. No CriticMarkup, no `[^tcN]` refs, no appendix.
96
+ - `--baseline` — pre-change view: `<w:ins>` and `<w:moveTo>` runs are dropped, `<w:del>` and `<w:moveFrom>` runs render as plain text. No CriticMarkup, no `[^tcN]` refs, no appendix.
97
+
98
+ `docx wc` accepts the same `--accepted` / `--baseline` flags with parallel semantics: default counts everything currently on disk (plain + ins + del), `--accepted` skips deletions, `--baseline` skips insertions. The response includes a `view` field so agents know which mode the count was taken from.
91
99
 
92
100
  `--comments` appends a GFM footnote reference (`[^cN]`) at the end of each commented span and emits one footnote definition per comment at the end of the output:
93
101
 
@@ -103,11 +111,11 @@ Footnotes/endnotes (the document's own `<w:footnoteReference>` / `<w:endnoteRefe
103
111
  ### Locators
104
112
 
105
113
  ```
106
- pN paragraph N (e.g., p3)
107
- pN:S-E characters S..E within paragraph N
108
- pN:S-pM:E cross-paragraph range
109
- tN table N; tN:rRcC for cell at row R, col C
110
- cN, imgN, linkN comment / image / hyperlink ids
114
+ pN paragraph N (e.g., p3)
115
+ pN:S-E characters S..E within paragraph N
116
+ pN:S-pM:E cross-paragraph range
117
+ tN table N; tN:rRcC for cell at row R, col C
118
+ cN, imgN, linkN, tcN comment / image / hyperlink / tracked-change ids
111
119
  ```
112
120
 
113
121
  Run `docx info locators` for the full reference.
@@ -151,7 +159,7 @@ src/
151
159
  comments/ # add | reply | resolve | delete | list
152
160
  images/ # list | extract | replace
153
161
  hyperlinks/ # add | list | replace | delete
154
- track-changes/ # FILE on|off
162
+ track-changes/ # on|off | list | accept | reject (apply.ts holds the unwrap/delete logic)
155
163
  info/ # schema | locators (reference output)
156
164
  core/
157
165
  package/ # JSZip open/close, named-part read/write