@folijs/docx 0.3.0 → 0.5.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 (85) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +72 -10
  3. package/dist/export/content.d.ts +2 -0
  4. package/dist/export/content.d.ts.map +1 -1
  5. package/dist/export/content.js +41 -3
  6. package/dist/export/content.js.map +1 -1
  7. package/dist/export/index.d.ts +14 -2
  8. package/dist/export/index.d.ts.map +1 -1
  9. package/dist/export/index.js +76 -15
  10. package/dist/export/index.js.map +1 -1
  11. package/dist/export/parts.d.ts.map +1 -1
  12. package/dist/export/parts.js +13 -0
  13. package/dist/export/parts.js.map +1 -1
  14. package/dist/export/pictures.d.ts +51 -0
  15. package/dist/export/pictures.d.ts.map +1 -0
  16. package/dist/export/pictures.js +346 -0
  17. package/dist/export/pictures.js.map +1 -0
  18. package/dist/export/properties.d.ts +11 -1
  19. package/dist/export/properties.d.ts.map +1 -1
  20. package/dist/export/properties.js +1 -1
  21. package/dist/export/properties.js.map +1 -1
  22. package/dist/export/tables.d.ts +27 -0
  23. package/dist/export/tables.d.ts.map +1 -0
  24. package/dist/export/tables.js +344 -0
  25. package/dist/export/tables.js.map +1 -0
  26. package/dist/images.d.ts +21 -0
  27. package/dist/images.d.ts.map +1 -0
  28. package/dist/images.js +53 -0
  29. package/dist/images.js.map +1 -0
  30. package/dist/import/content.d.ts +5 -1
  31. package/dist/import/content.d.ts.map +1 -1
  32. package/dist/import/content.js +161 -7
  33. package/dist/import/content.js.map +1 -1
  34. package/dist/import/index.d.ts +6 -1
  35. package/dist/import/index.d.ts.map +1 -1
  36. package/dist/import/index.js +16 -4
  37. package/dist/import/index.js.map +1 -1
  38. package/dist/import/ooxml.d.ts +1 -0
  39. package/dist/import/ooxml.d.ts.map +1 -1
  40. package/dist/import/ooxml.js +1 -0
  41. package/dist/import/ooxml.js.map +1 -1
  42. package/dist/import/parts.d.ts.map +1 -1
  43. package/dist/import/parts.js +7 -0
  44. package/dist/import/parts.js.map +1 -1
  45. package/dist/import/pictures.d.ts +34 -0
  46. package/dist/import/pictures.d.ts.map +1 -0
  47. package/dist/import/pictures.js +147 -0
  48. package/dist/import/pictures.js.map +1 -0
  49. package/dist/import/properties.d.ts.map +1 -1
  50. package/dist/import/properties.js +2 -1
  51. package/dist/import/properties.js.map +1 -1
  52. package/dist/import/report.d.ts +6 -0
  53. package/dist/import/report.d.ts.map +1 -1
  54. package/dist/import/report.js +5 -0
  55. package/dist/import/report.js.map +1 -1
  56. package/dist/import/tables.d.ts +31 -0
  57. package/dist/import/tables.d.ts.map +1 -0
  58. package/dist/import/tables.js +236 -0
  59. package/dist/import/tables.js.map +1 -0
  60. package/dist/index.d.ts +2 -1
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +1 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/settings.d.ts +8 -0
  65. package/dist/settings.d.ts.map +1 -0
  66. package/dist/settings.js +72 -0
  67. package/dist/settings.js.map +1 -0
  68. package/package.json +2 -2
  69. package/src/export/content.ts +49 -5
  70. package/src/export/index.ts +135 -19
  71. package/src/export/parts.ts +15 -0
  72. package/src/export/pictures.ts +405 -0
  73. package/src/export/properties.ts +1 -1
  74. package/src/export/tables.ts +386 -0
  75. package/src/images.ts +60 -0
  76. package/src/import/content.ts +154 -9
  77. package/src/import/index.ts +20 -5
  78. package/src/import/ooxml.ts +1 -0
  79. package/src/import/parts.ts +13 -0
  80. package/src/import/pictures.ts +176 -0
  81. package/src/import/properties.ts +4 -1
  82. package/src/import/report.ts +11 -0
  83. package/src/import/tables.ts +267 -0
  84. package/src/index.ts +2 -1
  85. package/src/settings.ts +75 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # @folijs/docx
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 18f838a: Tables and pictures as Word models them: imported, edited on pages and written back to `.docx`.
8
+ - **Schema v4** (`@folijs/core`, ADR-0006): `table`, `tableRow` and `tableCell` nodes with Word's table, row and cell properties (grid, merges, borders, shading, widths, header rows, `cantSplit`), table styles resolved as Word does (conditional formatting for first and last rows and columns, bands), `picture` nodes (inline or floating: `float` with Word's position and wrapping) and the envelope's `resources` (the pictures' images by key: content type, size, a URL or an opted-in `data:` URL; no base64 by default). `SCHEMA_VERSION` 4: v3 documents migrate on load.
9
+ - **Table editing** (`@folijs/core`, `@folijs/view`): cells isolate edits; typing, Enter, Backspace and Delete in cells; Tab and Shift+Tab between cells (Tab in the last cell adds a row); arrows across rows, pages and out of the table; `CellSelection` (drag, Shift+arrows) with copy, cut, paste and delete; commands `insertTable`, `insertRow`, `deleteRows`, `insertColumn`, `deleteColumns`, `deleteTable`, `mergeCells`, `splitCell`, `toggleHeaderRow`, `setTableStyle`, `setCellShading`, `setColumnWidth`; column borders dragged in the view. Rows inserted and deleted while tracking are tracked as Word records them.
10
+ - **Tables on pages** (`@folijs/view`): tables drawn from the model, rows flowed across pages (split at a line, header rows repeated, `cantSplit` kept whole); 277 of the corpus's 280 cell paragraphs on Word's page.
11
+ - **Pictures** (`@folijs/core`, `@folijs/view`): `insertPicture` (alt text required unless decorative, or `{ requireAlt: false }`: pasted and dropped files go in so and are marked), `setPictureSize`, `setPictureAlt`, `selectedPicture`; pictures drawn at their size, selected by a click, resized by a handle with their aspect ratio kept; image files pasted or dropped go through the app's `upload` hook (`EditorViewOptions.upload`, `view.insertFiles`), images shown through `EditorViewOptions.resource`; floating pictures laid out with the text around them (square, top and bottom, behind and in front of text), where Word places them in the corpus. `measureImageFile`, `textWidthEmu` and `EMU_PER_PX` are exported.
12
+ - **React** (`@folijs/react`): `FoliToolbar` gets a Table menu (insert table dialog, rows, columns, merge, split, header row, delete), a table style box, a cell shading menu and a Picture… dialog (insert from a file with alt text; edit a picture's alt text and size); `FoliEditor` and `FoliCanvas` take `upload` and `resource` props, `FoliToolbar` `upload`. Keyboard-usable and axe-clean in Chromium, Firefox and WebKit.
13
+ - **DOCX** (`@folijs/docx`): tables read into the model and written back (unchanged ones as written, changed ones child by child; tracked row changes); inline (`wp:inline`) and floating (`wp:anchor`) pictures read as picture nodes with their images as resources, written back byte for byte when unchanged, new images as media parts from `data:` URLs or `ExportOptions.resource`; `packageImages(pkg)` gives the view URLs for a package's images; `report.picturesWithoutAlt`. Word opens the corpus's tables and pictures exported unchanged and edited.
14
+
15
+ 0.4.0 cannot read documents saved by 0.5.0 (schema v4). Known limits are in [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md) (tables and pictures sections).
16
+
17
+ Changed behaviour (pre-1.0 minor):
18
+ - `.docx` tables and drawings that imported as `opaqueBlock` and `opaqueInline` now import as `table` and `picture` nodes; a v3 document's opaque tables stay opaque until the `.docx` is imported again.
19
+ - `exportDocx` needs the bytes of a picture added since import: a `data:` URL resource or `ExportOptions.resource(key, resource)`; without them it throws a `DocxError` (never drops the picture).
20
+ - The editor's pages are `position: relative; isolation: isolate; display: flow-root` (pictures behind and in front of text are positioned against them; a floating picture past the page's text makes the page taller).
21
+ - Inserting or deleting a table while tracking is recorded as tracked rows (0.4.0 did not make the edit), and `deleteComment` and `deleteAllComments` remove comments anchored in tables (0.4.0 kept them: tables were opaque).
22
+ - `FoliToolbar` shows the Table menu, table style box, cell shading menu and Picture… button.
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [18f838a]
27
+ - @folijs/core@0.5.0
28
+
29
+ ## 0.4.0
30
+
31
+ ### Minor Changes
32
+
33
+ - e2a6e23: Review as in Word: tracked changes recorded, shown, accepted and rejected; comments written, answered and resolved; both round-trip with Word.
34
+ - **Tracked changes** (`@folijs/core`): with tracking on (`createEditor({ author, trackChanges })`, `editor.commands.setTrackChanges`), every edit is recorded as Word records it: what is removed stays marked deleted, what is added is marked inserted, paragraph marks removed or added are recorded on the paragraph, formatting changes keep the properties from before the first change (`formatChange`), and deleting your own insertion removes it. Commands need no tracking code: the editor rebuilds each transaction it dispatches (`trackTransaction`). Accept and reject (`acceptChange`, `rejectChange` at the caret or in the selection, `acceptAllChanges(author?)`, `rejectAllChanges(author?)`, `nextChange`, `previousChange`, `trackedChanges(doc)`), each its own undo step; both ends of a move together. A property test checks that accepting everything gives the same document as the edits made untracked and rejecting everything gives the original.
35
+ - **Comments** (`@folijs/core`): `addComment`, `replyToComment`, `editComment`, `resolveComment`, `deleteComment`, `deleteAllComments`, with Word's anchors; comment changes are part of undo history (`CommentStep`); a comment whose text is deleted with its reference goes with it.
36
+ - **Review view** (`@folijs/core` state, drawn by `@folijs/view`): tracked changes shown as all markup (author colors, a bar beside changed paragraphs), simple markup or no markup while editing (`setReviewView`, `createEditor({ reviewView })`); while tracking, or where it is hidden, Backspace and Delete step over deleted text; the caret never goes into hidden text.
37
+ - **React** (`@folijs/react`): a review group in `FoliToolbar` (New comment, Track changes, Show changes as, previous and next change, Accept, Reject, Accept all, Reject all); `FoliComments`, a comments pane beside the pages (threads level with their text; reply, edit, resolve, delete), shown by `FoliEditor` while the document has comments (`comments` prop); `FoliEditor` props `author`, `trackChanges`, `reviewView`.
38
+ - **DOCX** (`@folijs/docx`): `DocxImport.trackRevisions` and `exportDocx(document, package?, { trackRevisions })` read and write Word's tracking setting. Checked with Word on the corpus: files with changes and comments made in Foli open without a repair prompt with those changes, authors and threads; Word's accepted and rejected text equals Foli's (case aside; table paragraphs, fields and content controls aside; one corpus document, with a content control around paragraphs, not compared); Foli reads Word's own changes and replies back.
39
+
40
+ No document format change (schema 3): 0.3.0 and 0.4.0 read each other's documents. Known limits are in [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md) (tables are not tracked yet; dates are written in UTC).
41
+
42
+ Changed behaviour (pre-1.0 minor):
43
+ - A paragraph left with nothing by a join or by a deletion from its start is removed whole: the next paragraph keeps its own properties (before, the merged paragraph took the first one's).
44
+ - `closeHistory` makes a transaction an undo step of its own on both sides: typing right after a paste, cut or drop is now its own step.
45
+ - `FoliToolbar` shows a review group by default (Track changes, Show changes as, previous and next change, Accept, Reject, Accept all, Reject all); New comment only with its new `comments` prop (`FoliEditor` passes it).
46
+ - Tracked changes in markup are drawn in each author's color (was one fixed red), with a bar beside changed paragraphs; commented text carries `data-foli-comments`.
47
+ - `withEnvelope` ignores comments: change them with `setComments` (or the comment commands).
48
+ - `FoliEditor` puts the canvas inside a `.foli-editor-body` element (beside the comments pane): CSS that relied on `.foli-canvas` being a direct child of the editor's parent needs updating.
49
+ - Imported `w:rPrChange` properties are in canonical form (default attributes left out); inserted and deleted text in `renderDocument` and the editor is titled "Inserted by …" / "Deleted by …".
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [e2a6e23]
54
+ - @folijs/core@0.4.0
55
+
3
56
  ## 0.3.0
4
57
 
5
58
  ### Minor Changes
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @folijs/docx
2
2
 
3
3
  DOCX for [Foli](https://github.com/josep-audenis/foli): imports a `.docx` into Foli's Word model
4
- (schema v3 of `@folijs/core`), exports it back losslessly (`exportDocx`), and reads its package
4
+ (schema v4 of `@folijs/core`), exports it back losslessly (`exportDocx`), and reads its package
5
5
  (zip, parts, content types, relationships) and XML keeping every byte it does not change. No DOM:
6
6
  runs in the browser, workers and Node 20.12+. Depends only on `@folijs/core`.
7
7
 
@@ -15,9 +15,9 @@ const {
15
15
  package: pkg,
16
16
  report,
17
17
  } = await importDocx(new Uint8Array(await file.arrayBuffer()));
18
- document.content; // schema v3: paragraphs with Word's properties, runs as text with marks
18
+ document.content; // paragraphs with Word's properties, runs as text with marks, tables
19
19
  document.styles; // with basedOn, run and paragraph properties
20
- report.opaque; // { "w:tbl": 1, "w:drawing": 1 }: kept verbatim, not editable yet
20
+ report.opaque; // { "w:fldChar": 3 }: content kept verbatim, not editable yet
21
21
  ```
22
22
 
23
23
  **Import** (`importDocx`, `importPackage`) reads the main document, styles (with the document
@@ -30,11 +30,23 @@ from `commentsExtended`) and sections:
30
30
  (`w14:paraId`…). **Runs** become text, tabs and breaks with their properties as marks; tracked
31
31
  insertions, deletions and moves, hyperlinks (target from the relationship, or a bookmark),
32
32
  bookmarks, comment ranges and references are modeled.
33
+ - **Tables** (10.4) become `table`, `tableRow` and `tableCell` nodes: the table's, rows' and
34
+ cells' properties (`w:tblPr`, `w:tblGrid`, `w:tblPrEx`, `w:trPr`, `w:tcPr`) as attributes,
35
+ merges as Word writes them (`gridSpan`, `vMerge`), a row inserted or deleted as a tracked
36
+ change, the cells' paragraphs and nested tables; a table style's parts and conditional
37
+ formats go to its `StyleJSON`. A table the model cannot hold as it is stays opaque, reported:
38
+ rows or cells inside a content control or custom XML, markers between rows, elements out of
39
+ Word's order, a cell not ending with a paragraph, tables nested more than 64 deep, a table
40
+ right after a table (Word merges the two) or ending the body, and a page, column or section
41
+ break in a cell (the model has none there). A row's `w:tblPrEx` keeps what a row may not
42
+ override (a style, band sizes) in its `ext`, and a table style's `wholeTable` conditional
43
+ format stays in its `ext`, both reported. A table made in the model is written as Word
44
+ requires (properties, grid, rows); Word opens it, with or without a grid.
33
45
  - **Lossless:** every properties element is kept verbatim (`ext` on paragraphs, sections,
34
46
  styles, numbering levels and definitions, the document defaults; `runExt` on runs; a comment's
35
47
  start tag), and unknown attributes of modeled elements go to attribute bags (paragraphs,
36
48
  links, tracked changes, bookmarks and comment anchors: `w16du:dateUtc`, `w14:paraId`…). Every
37
- element Foli does not model yet (tables, content controls, pictures, fields' structure,
49
+ element Foli does not model yet (content controls, pictures, fields' structure,
38
50
  footnote references, equations…) becomes an opaque node holding its source, and so does an
39
51
  element the model rejects as a whole (a tracked change with an id past Word's range, a link in
40
52
  a link, a run with an unknown attribute): never stripped to plain text. Export (8.5) writes all
@@ -57,10 +69,16 @@ from `commentsExtended`) and sections:
57
69
  between elements, and the empty paragraph given to an empty body or comment. Text is read as
58
70
  Word reads it: without `xml:space="preserve"`, whitespace at the ends of a `w:t` is not text.
59
71
 
60
- **Export** (`exportDocx(document, package?)`) writes the parts the editor owns (`document.xml`,
61
- `styles.xml`, `numbering.xml`, `comments.xml`, `commentsExtended.xml`, and relationships for new
62
- hyperlink targets) and copies every other part of the original package byte for byte (its
63
- compressed entry included). Within the parts it writes:
72
+ **Settings.** Of `settings.xml` only `w:trackRevisions` is read (`DocxImport.trackRevisions`)
73
+ and, when `exportDocx` is given `trackRevisions`, written: added in its place among the
74
+ settings, or removed; the rest of the part is kept byte for byte. A new package gets a settings
75
+ part only with tracking on.
76
+
77
+ **Export** (`exportDocx(document, package?, options?)`) writes the parts the editor owns
78
+ (`document.xml`, `styles.xml`, `numbering.xml`, `comments.xml`, `commentsExtended.xml`,
79
+ relationships for new hyperlink targets, and `settings.xml` when `trackRevisions` changes it)
80
+ and copies every other part of the original package byte for byte (its compressed entry
81
+ included). Within the parts it writes:
64
82
 
65
83
  - An element read from the file comes back verbatim while its values are what import read from
66
84
  it (a paragraph's `w:pPr`, a run's `w:rPr`, a section, a style, a numbering level or
@@ -74,7 +92,11 @@ compressed entry included). Within the parts it writes:
74
92
  editor removed are left out; new ones are added where Word expects them; a part the document
75
93
  now needs (numbering, comments, comment threads) is added with its content type and
76
94
  relationship. Comments made in the editor that are in a thread get a `w14:paraId`, so their
77
- replies and resolved state are written.
95
+ replies and resolved state are written. Tracked changes and comments the editor records (0.4.0: insertions,
96
+ deletions, run and paragraph formatting changes, comments, replies, resolved threads) are
97
+ written as Word writes them; Word reads them back with their authors and text, and Foli reads
98
+ Word's own changes and replies (checked with Word on the corpus: `corpus/README.md`). A run's
99
+ recorded formatting (`w:rPrChange`) is imported in canonical form, as the editor records it.
78
100
  - Runs are regrouped from the model: hyperlinks outermost, then insertions (or move
79
101
  destinations), deletions (or move sources) with `w:delText`, then runs of equal properties.
80
102
  Line ends and vertical tabs in text become breaks, a tab character `w:tab` (read back as a
@@ -87,12 +109,52 @@ compressed entry included). Within the parts it writes:
87
109
  namespaces. A document that refers to parts of its original package (headers, footers,
88
110
  pictures, content kept verbatim with relationship ids) needs that package: exporting it
89
111
  without one is a `DocxError`.
112
+ - Tables are written from the model: each properties element as paragraphs' are (verbatim
113
+ while unchanged, else child by child), the grid as read while its widths are, rows and cells
114
+ in order; Word reads every corpus table back with Foli's text, unchanged and edited
115
+ (`scripts/corpus/table-roundtrip.mjs`). A changed table style definition is refused
116
+ (`DocxError`): Foli has no command that changes one.
117
+ - **Pictures** (10.8, 10.9): a `w:drawing` holding one DrawingML picture (`wp:inline` or
118
+ `wp:anchor`, `pic:pic`, its image an embedded `image/*` part) becomes a `picture` node: `resource` (the
119
+ image part's name, `word/media/image1.png`, a key of the envelope's `resources`, which give
120
+ its content type, size and part), its size in EMU (`wp:extent`), `alt` and `title`
121
+ (`wp:docPr`), `decorative` (Office's `adec:decorative`), and the drawing verbatim in `ext`
122
+ (cropping, effects, ids; an SVG picture's SVG part stays there, its PNG fallback is the
123
+ resource). An empty description stays empty. A picture without alt text and not decorative is allowed and
124
+ counted (`report.picturesWithoutAlt`). A floating picture (`wp:anchor`) is a `picture` node
125
+ too, with `float`: `horizontal` and `vertical` (`relativeFrom` as `relativeTo`, and
126
+ `wp:posOffset` as `offset` in EMU or `wp:align` as `align`), `wrap` (`square`, `tight`,
127
+ `through`, `topAndBottom`; `wp:wrapNone` is `behind` or `inFront` by `behindDoc`), `side`
128
+ (`wrapText`), `distance` (`distT`…`distR`), `allowOverlap` and `layoutInCell`; its z-order,
129
+ lock and wrap polygon stay in `ext`. One positioned by `simplePos`, hidden, sized relative to
130
+ the page (`wp14:sizeRelH`/`sizeRelV`), or with no position or wrapping the model reads, stays
131
+ opaque, as linked images, charts, shapes and other drawings do.
132
+ - Pictures are written from their `ext` with only what the model changed from it written in
133
+ (the extent and the transform's size, alt text and title on `wp:docPr` and `pic:cNvPr`, the
134
+ image's relationship): an unchanged picture comes back byte for byte, values the file holds
135
+ twice (and differently) included. A copy of a drawing (the same id twice) gets new
136
+ `wp:docPr` and `pic:cNvPr` ids, its `wp14` anchor ids left to Word. One without `ext` (new) is
137
+ a fresh drawing, inline or `wp:anchor` (a position Word cannot read written as `column` or
138
+ `paragraph` at offset 0, tight and through wrapping with the picture's rectangle as the
139
+ polygon); so is a floating picture whose `float` differs from its `ext`'s, and one made
140
+ floating or inline: what only its `ext` held is then lost (cropping, effects, z-order, lock,
141
+ `hidden`, the wrap polygon, an SVG picture's SVG part, a click link; no command changes a
142
+ float yet); new ids are above every drawing id in the document's parts. Its image
143
+ is the package's part when the resource names one there of the size and an image type import
144
+ recorded (a part of that name in another package is another image); otherwise a new media
145
+ part (`word/media/foli-imageN.ext`, its content type declared) with the bytes of the
146
+ resource's `data:` URL (base64 or percent-encoded) or of `ExportOptions.resource(key,
147
+ resource)` (an app's upload); without bytes the export fails (`DocxError`), never drops the
148
+ picture. Image relationships are matched by the part they point to. A drawing read in another
149
+ part or package that refers to other relationships (an SVG's PNG fallback, a click link) is
150
+ written fresh.
90
151
  - Not written: the theme (read-only in the model: the original part is kept; a new package has
91
152
  none, so Word's default applies). Page margins Word requires but the document leaves out are
92
153
  written with Word's defaults. A part read as UTF-16 is written as UTF-8, declared so.
93
154
 
94
155
  Checked: the corpus exported without edits equals the original under the canonical comparison
95
- (`src/testing/canonical.ts`), with every other part, and every unchanged element, byte for byte;
156
+ (`src/testing/canonical.ts`), with every other part, and every unchanged element, byte for byte
157
+ (tables as written, but for what import drops everywhere);
96
158
  re-imported, it is the same document; random edits leave every other paragraph identical and
97
159
  the edited one's unknown properties in place; Word opens the exports (unchanged, edited, and new
98
160
  packages) and finds the reference numbers in the unchanged ones
@@ -11,6 +11,8 @@ export interface WriteContext {
11
11
  * still has it with that target, otherwise a new one.
12
12
  */
13
13
  readonly hyperlink: (href: string, id: string | undefined) => string;
14
+ /** A picture's `w:drawing` (its image related to the part, its media part allocated). */
15
+ readonly picture: (attrs: Record<string, unknown>) => string;
14
16
  }
15
17
  export declare function blocksXml(blocks: readonly NodeJSON[], context: WriteContext): string;
16
18
  export declare function paragraphXml(p: NodeJSON, context: WriteContext): string;
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.ts","sourceR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YAAY,GAAG,MAAM,CAMvE"}
@@ -2,7 +2,9 @@
2
2
  * Schema v3 content back to WordprocessingML: paragraphs, runs grouped by their properties,
3
3
  * hyperlinks and tracked changes around them, markers between them, opaque content verbatim.
4
4
  */
5
+ import { DocxError } from "../package.js";
5
6
  import { paragraphPropertiesXml, runPropertiesXml, same } from "./properties.js";
7
+ import { cellPropertiesXml, exceptionsXml, gridXml, rowPropertiesXml, tablePropertiesXml, } from "./tables.js";
6
8
  import { bagXml, el, escapeText, fragment } from "./xmlout.js";
7
9
  /** Opaque XML as kept, once checked to be one element that fits the part (DocxError otherwise). */
8
10
  function verbatim(xml, context) {
@@ -17,13 +19,39 @@ export function blocksXml(blocks, context) {
17
19
  out += paragraphXml(block, context);
18
20
  else if (block.type === "opaqueBlock")
19
21
  out += verbatim(block.attrs?.xml, context);
22
+ else if (block.type === "table")
23
+ out += tableXml(block, context);
24
+ else
25
+ notYet(block);
20
26
  }
21
27
  return out;
22
28
  }
29
+ /** A table: its properties, its grid, then each row's exceptions, properties and cells. */
30
+ function tableXml(table, context) {
31
+ const ns = context.namespaces;
32
+ const attrs = (table.attrs ?? {});
33
+ let out = `<w:tbl>${tablePropertiesXml(attrs, ns)}${gridXml(attrs, ns)}`;
34
+ for (const row of table.content ?? []) {
35
+ const r = (row.attrs ?? {});
36
+ out += `<w:tr${bagXml(r.attributes, ns)}>${exceptionsXml(r.exceptions, ns)}${rowPropertiesXml(r, ns)}`;
37
+ for (const cell of row.content ?? []) {
38
+ const c = (cell.attrs ?? {});
39
+ out += `<w:tc>${cellPropertiesXml(c, ns)}${blocksXml(cell.content ?? [], context)}</w:tc>`;
40
+ }
41
+ out += "</w:tr>";
42
+ }
43
+ return `${out}</w:tbl>`;
44
+ }
45
+ /** Content export does not write yet (pictures: 10.8): refused, never dropped. */
46
+ function notYet(node) {
47
+ throw new DocxError(`A ${node.type} cannot be exported to .docx yet`);
48
+ }
23
49
  export function paragraphXml(p, context) {
24
50
  const attrs = (p.attrs ?? {});
25
51
  const own = bagXml(attrs.attributes, context.namespaces);
26
- return `<w:p${own}>${paragraphPropertiesXml(attrs, context.namespaces)}${inlinesXml(p.content ?? [], context)}</w:p>`;
52
+ const inner = `${paragraphPropertiesXml(attrs, context.namespaces)}${inlinesXml(p.content ?? [], context)}`;
53
+ // An empty paragraph as Word writes it.
54
+ return inner ? `<w:p${own}>${inner}</w:p>` : `<w:p${own}/>`;
27
55
  }
28
56
  const markOf = (node, type) => node.marks?.find((m) => m.type === type);
29
57
  /** Consecutive nodes with the same `key`, each run of them given to `write`. */
@@ -78,7 +106,15 @@ function hyperlinkXml(link, inner, context) {
78
106
  function inRun(node) {
79
107
  if (node.type === "opaqueInline")
80
108
  return node.attrs?.run === true;
81
- return ["text", "tab", "hardBreak", "pageBreak", "columnBreak", "commentReference"].includes(node.type);
109
+ return [
110
+ "text",
111
+ "tab",
112
+ "hardBreak",
113
+ "pageBreak",
114
+ "columnBreak",
115
+ "commentReference",
116
+ "picture",
117
+ ].includes(node.type);
82
118
  }
83
119
  const STRUCTURE = new Set(["link", "insertion", "deletion"]);
84
120
  /** A run's own properties: its marks without the hyperlink and tracked changes around it. */
@@ -111,7 +147,7 @@ function markerXml(node, context) {
111
147
  case "opaqueInline":
112
148
  return verbatim(a.xml, context);
113
149
  default:
114
- return "";
150
+ return notYet(node);
115
151
  }
116
152
  }
117
153
  /**
@@ -158,6 +194,8 @@ function runContentXml(node, deleted, context) {
158
194
  return `${el("w:commentReference", { "w:id": String(a.id) }).slice(0, -2)}${bagXml(a.attributes, context.namespaces, ["w:id"])}/>`;
159
195
  case "opaqueInline":
160
196
  return verbatim(a.xml, context);
197
+ case "picture":
198
+ return context.picture(a);
161
199
  default:
162
200
  return "";
163
201
  }
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/export/content.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,iB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AAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAS,CAAC;IACrC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,MAAM;YACT,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3C,KAAK,KAAK;YACR,OAAO,UAAU,CAAC;QACpB,KAAK,WAAW;YACd,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,KAA2B,EAAE,CAAC,CAAC;QAClE,KAAK,WAAW;YACd,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1C,KAAK,aAAa;YAChB,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC5C,KAAK,kBAAkB;YACrB,OAAO,GAAG,EAAE,CAAC,oBAAoB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;QACrI,KAAK,cAAc;YACjB,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAClC,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC5B;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -4,11 +4,23 @@
4
4
  * the relationships new hyperlinks need); every other part is copied from the original package
5
5
  * byte for byte. Without a package, a new one is made.
6
6
  */
7
- import { type FoliDocument } from "@folijs/core";
7
+ import { type FoliDocument, type ResourceJSON } from "@folijs/core";
8
8
  import { type DocxPackage } from "../package.js";
9
+ export interface ExportOptions {
10
+ /**
11
+ * Whether Word records edits as tracked changes (`w:trackRevisions`). Left out: as the
12
+ * original package has it (off in a new one).
13
+ */
14
+ trackRevisions?: boolean;
15
+ /**
16
+ * The bytes of a picture's image the package does not hold and its resource gives no `data:`
17
+ * URL for (an app's upload, by its URL). Undefined: the export fails, never drops it.
18
+ */
19
+ resource?: (key: string, resource: ResourceJSON) => Promise<Uint8Array | undefined> | Uint8Array | undefined;
20
+ }
9
21
  /**
10
22
  * The document as a `.docx`. With `original` (the package it was imported from), the parts
11
23
  * Foli does not edit come back byte for byte and unchanged elements verbatim.
12
24
  */
13
- export declare function exportDocx(document: FoliDocument, original?: DocxPackage): Promise<Uint8Array>;
25
+ export declare function exportDocx(document: FoliDocument, original?: DocxPackage, options?: ExportOptions): Promise<Uint8Array>;
14
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/export/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAa,KAAK,WAAW,EAAgB,MAAM,eAAe,CAAC;AAkG1E;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,UAAU,CAAC,CAGrB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/export/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAiB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,EAAa,KAAK,WAAW,EAAgB,MAAM,eAAe,CAAC;AA2J1E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CACT,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,YAAY,KACnB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,UAAU,GAAG,SAAS,CAAC;CAC/D;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,WAAW,EACtB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,UAAU,CAAC,CAsBrB"}
@@ -7,9 +7,11 @@
7
7
  import { parseDocument } from "@folijs/core";
8
8
  import { child, REL } from "../import/ooxml.js";
9
9
  import { DocxError } from "../package.js";
10
+ import { newSettingsXml, withTrackRevisions } from "../settings.js";
10
11
  import { deflateEntry, writeZip } from "../zip.js";
11
12
  import { blocksXml } from "./content.js";
12
13
  import { commentsExtendedXml, commentsXml, numberingXml, stylesXml, } from "./parts.js";
14
+ import { drawingXml, Media, pictureBytes } from "./pictures.js";
13
15
  import { sectionXml } from "./properties.js";
14
16
  import { DEFAULT_NAMESPACES, escapeAttribute, NEW_ROOT_ATTRIBUTES, namespacesOf, } from "./xmlout.js";
15
17
  const CT = {
@@ -18,6 +20,7 @@ const CT = {
18
20
  numbering: "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml",
19
21
  comments: "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml",
20
22
  commentsExtended: "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml",
23
+ settings: "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
21
24
  rels: "application/vnd.openxmlformats-package.relationships+xml",
22
25
  };
23
26
  const encoder = new TextEncoder();
@@ -27,13 +30,41 @@ class Relationships {
27
30
  #ids;
28
31
  #byTarget = new Map();
29
32
  #existing;
33
+ /** The part each internal relationship points to (resolved, as the package resolves it). */
34
+ #parts = new Map();
30
35
  constructor(existing) {
31
36
  this.#existing = new Map(existing.map((r) => [r.id, r]));
37
+ for (const r of existing)
38
+ if (!r.external && r.partName)
39
+ this.#parts.set(r.id, r.partName);
32
40
  this.#ids = new Set(existing.map((r) => r.id));
33
41
  for (const r of existing)
34
42
  if (r.type === REL.hyperlink && r.external)
35
43
  this.#byTarget.set(r.target, r.id);
36
44
  }
45
+ /** The part relationship `id` points to (one it had, or one added), if internal. */
46
+ target(id) {
47
+ return this.#parts.get(id);
48
+ }
49
+ /**
50
+ * The relationship to image part `part` (absolute; `target` as this part refers to it):
51
+ * `current` when it is one, else a known or new one. Compared by part, not by the target's
52
+ * text (`/word/media/x.png`, `./media/x.png` and `media/x.png` are one part).
53
+ */
54
+ image(part, target, current) {
55
+ const isImage = (id) => {
56
+ const r = this.#existing.get(id) ?? this.added.find((a) => a.id === id);
57
+ return r?.type === REL_IMAGE && this.#parts.get(id)?.toLowerCase() === part.toLowerCase();
58
+ };
59
+ if (current !== undefined && isImage(current))
60
+ return current;
61
+ for (const id of this.#parts.keys())
62
+ if (isImage(id))
63
+ return id;
64
+ const id = this.add(REL_IMAGE, target, false);
65
+ this.#parts.set(id, part);
66
+ return id;
67
+ }
37
68
  hyperlink(href, id) {
38
69
  const own = id === undefined ? undefined : this.#existing.get(id);
39
70
  if (own && own.type === REL.hyperlink && own.target === href)
@@ -68,8 +99,16 @@ class Relationships {
68
99
  return original.slice(0, close) + entries + original.slice(close);
69
100
  }
70
101
  }
71
- function contextFor(namespaces, relationships) {
72
- return { namespaces, hyperlink: (href, id) => relationships.hyperlink(href, id) };
102
+ const REL_IMAGE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
103
+ function contextFor(namespaces, relationships, media, source) {
104
+ return {
105
+ namespaces,
106
+ hyperlink: (href, id) => relationships.hyperlink(href, id),
107
+ picture: (attrs) => drawingXml(attrs, {
108
+ image: (part, current) => relationships.image(part, relative(source, part), current),
109
+ target: (id) => relationships.target(id),
110
+ }, namespaces, media),
111
+ };
73
112
  }
74
113
  /** `/word/_rels/document.xml.rels` for `/word/document.xml`. */
75
114
  function relationshipsPartName(source) {
@@ -85,9 +124,26 @@ function relative(from, to) {
85
124
  * The document as a `.docx`. With `original` (the package it was imported from), the parts
86
125
  * Foli does not edit come back byte for byte and unchanged elements verbatim.
87
126
  */
88
- export async function exportDocx(document, original) {
127
+ export async function exportDocx(document, original, options = {}) {
89
128
  const doc = withThreadIds(parseDocument(document), original);
90
- return original ? intoPackage(doc, original) : newPackage(doc);
129
+ // Before the app is asked for any picture's bytes.
130
+ const reference = original ? undefined : packageReference(doc);
131
+ if (reference) {
132
+ throw new DocxError(`The document refers to a part of its original package (${reference}): export it with that package`);
133
+ }
134
+ // The parts written from the model: their drawings are the document's own.
135
+ const rewritten = original
136
+ ? [
137
+ original.mainDocument,
138
+ ...original
139
+ .relationships(original.mainDocument)
140
+ .filter((r) => r.type === REL.comments && r.partName)
141
+ .map((r) => r.partName),
142
+ ]
143
+ : [];
144
+ const bytes = await pictureBytes(doc, original, options.resource);
145
+ const media = new Media(doc, original, bytes, rewritten);
146
+ return original ? intoPackage(doc, original, options, media) : newPackage(doc, options, media);
91
147
  }
92
148
  const PARA_ID = "w14:paraId";
93
149
  /** A comment's last paragraph's `w14:paraId`: what `commentsExtended` keys its thread state by. */
@@ -144,7 +200,7 @@ function withThreadIds(doc, pkg) {
144
200
  }
145
201
  return copy;
146
202
  }
147
- async function intoPackage(doc, pkg) {
203
+ async function intoPackage(doc, pkg, options, media) {
148
204
  const mainName = pkg.mainDocument;
149
205
  const main = pkg.xml(mainName);
150
206
  const body = child(main.root, "body");
@@ -152,7 +208,7 @@ async function intoPackage(doc, pkg) {
152
208
  throw new DocxError(`${mainName}: no w:body`);
153
209
  const namespaces = namespacesOf(main.root, main.source);
154
210
  const rels = new Relationships(pkg.relationships(mainName));
155
- const context = contextFor(namespaces, rels);
211
+ const context = contextFor(namespaces, rels, media, mainName);
156
212
  const content = blocksXml(doc.content.content ?? [], context) + bodySection(doc, namespaces);
157
213
  const documentXml = body.openEnd === body.end
158
214
  ? `${main.source.slice(0, body.start)}<${body.name}>${content}</${body.name}>${main.source.slice(body.end)}`
@@ -198,15 +254,20 @@ async function intoPackage(doc, pkg) {
198
254
  .relationships(mainName)
199
255
  .find((r) => r.type === REL.comments && !r.external)?.partName;
200
256
  const commentRels = new Relationships(commentsName ? pkg.relationships(commentsName) : []);
201
- const comments = part(REL.comments, "/word/comments.xml", CT.comments, (o, ns) => commentsXml(doc, o, contextFor(ns, commentRels)), doc.comments.length > 0);
257
+ const comments = part(REL.comments, "/word/comments.xml", CT.comments, (o, ns) => commentsXml(doc, o, contextFor(ns, commentRels, media, commentsName ?? "/word/comments.xml")), doc.comments.length > 0);
202
258
  if (comments && commentRels.added.length)
203
259
  writeRelationships(comments, commentRels);
204
260
  // Replies and resolved state: rewritten only when they changed.
205
261
  if (comments && changedThreads(doc, pkg)) {
206
262
  part(REL.commentsExtended, "/word/commentsExtended.xml", CT.commentsExtended, (o) => commentsExtendedXml(doc, o), true);
207
263
  }
264
+ const { trackRevisions } = options;
265
+ if (trackRevisions !== undefined) {
266
+ part(REL.settings, "/word/settings.xml", CT.settings, (o) => (o ? withTrackRevisions(o.source, o.root, trackRevisions) : newSettingsXml()), trackRevisions);
267
+ }
208
268
  if (rels.added.length)
209
269
  writeRelationships(mainName, rels);
270
+ add.push(...media.added);
210
271
  return pkg.write(replace, add);
211
272
  function writeRelationships(source, relationships) {
212
273
  const relsName = relationshipsPartName(source);
@@ -255,13 +316,9 @@ function changedThreads(doc, pkg) {
255
316
  return false;
256
317
  }
257
318
  /** A new package: content types, relationships, the document and the parts it needs. */
258
- async function newPackage(doc) {
259
- const reference = packageReference(doc);
260
- if (reference) {
261
- throw new DocxError(`The document refers to a part of its original package (${reference}): export it with that package`);
262
- }
319
+ async function newPackage(doc, options, media) {
263
320
  const rels = new Relationships([]);
264
- const context = contextFor(DEFAULT_NAMESPACES, rels);
321
+ const context = contextFor(DEFAULT_NAMESPACES, rels, media, "/word/document.xml");
265
322
  const main = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n<w:document ${NEW_ROOT_ATTRIBUTES}><w:body>${blocksXml(doc.content.content ?? [], context)}${bodySection(doc, DEFAULT_NAMESPACES)}</w:body></w:document>`;
266
323
  const parts = [
267
324
  { name: "/word/document.xml", text: main, contentType: CT.main },
@@ -276,7 +333,7 @@ async function newPackage(doc) {
276
333
  }
277
334
  if (doc.comments.length) {
278
335
  const commentRels = new Relationships([]);
279
- add("/word/comments.xml", REL.comments, CT.comments, commentsXml(doc, undefined, contextFor(DEFAULT_NAMESPACES, commentRels)));
336
+ add("/word/comments.xml", REL.comments, CT.comments, commentsXml(doc, undefined, contextFor(DEFAULT_NAMESPACES, commentRels, media, "/word/comments.xml")));
280
337
  if (commentRels.added.length)
281
338
  parts.push({
282
339
  name: "/word/_rels/comments.xml.rels",
@@ -287,12 +344,14 @@ async function newPackage(doc) {
287
344
  add("/word/commentsExtended.xml", REL.commentsExtended, CT.commentsExtended, commentsExtendedXml(doc, undefined));
288
345
  }
289
346
  }
347
+ if (options.trackRevisions)
348
+ add("/word/settings.xml", REL.settings, CT.settings, newSettingsXml());
290
349
  parts.push({
291
350
  name: "/word/_rels/document.xml.rels",
292
351
  text: rels.xml(undefined),
293
352
  contentType: CT.rels,
294
353
  });
295
- const overrides = parts
354
+ const overrides = [...parts, ...media.added]
296
355
  .filter((p) => p.contentType !== CT.rels)
297
356
  .map((p) => `<Override PartName="${p.name}" ContentType="${p.contentType}"/>`)
298
357
  .join("");
@@ -310,6 +369,8 @@ async function newPackage(doc) {
310
369
  const entries = [];
311
370
  for (const [name, text] of files)
312
371
  entries.push(await deflateEntry(name, encoder.encode(text)));
372
+ for (const part of media.added)
373
+ entries.push(await deflateEntry(part.name.slice(1), part.data));
313
374
  return writeZip(entries);
314
375
  }
315
376
  /** The body's last section: written when the document has one or read one (an empty `{}` read