@folijs/docx 0.5.0 → 1.0.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 (123) hide show
  1. package/CHANGELOG.md +157 -0
  2. package/README.md +54 -17
  3. package/dist/custom.d.ts +2 -0
  4. package/dist/custom.d.ts.map +1 -0
  5. package/dist/custom.js +216 -0
  6. package/dist/custom.js.map +1 -0
  7. package/dist/export/balance.d.ts +2 -0
  8. package/dist/export/balance.d.ts.map +1 -0
  9. package/dist/export/balance.js +112 -0
  10. package/dist/export/balance.js.map +1 -0
  11. package/dist/export/content.d.ts +1 -14
  12. package/dist/export/content.d.ts.map +1 -1
  13. package/dist/export/content.js +157 -22
  14. package/dist/export/content.js.map +1 -1
  15. package/dist/export/controls.d.ts +2 -0
  16. package/dist/export/controls.d.ts.map +1 -0
  17. package/dist/export/controls.js +233 -0
  18. package/dist/export/controls.js.map +1 -0
  19. package/dist/export/index.d.ts +8 -2
  20. package/dist/export/index.d.ts.map +1 -1
  21. package/dist/export/index.js +218 -18
  22. package/dist/export/index.js.map +1 -1
  23. package/dist/export/parts.d.ts +1 -16
  24. package/dist/export/parts.d.ts.map +1 -1
  25. package/dist/export/parts.js +79 -11
  26. package/dist/export/parts.js.map +1 -1
  27. package/dist/export/pictures.d.ts +0 -42
  28. package/dist/export/pictures.d.ts.map +1 -1
  29. package/dist/export/pictures.js +24 -4
  30. package/dist/export/pictures.js.map +1 -1
  31. package/dist/export/properties.d.ts +1 -41
  32. package/dist/export/properties.d.ts.map +1 -1
  33. package/dist/export/properties.js +74 -15
  34. package/dist/export/properties.js.map +1 -1
  35. package/dist/export/tables.d.ts +0 -19
  36. package/dist/export/tables.d.ts.map +1 -1
  37. package/dist/export/tables.js +15 -3
  38. package/dist/export/tables.js.map +1 -1
  39. package/dist/export/xmlout.d.ts +1 -61
  40. package/dist/export/xmlout.d.ts.map +1 -1
  41. package/dist/export/xmlout.js +34 -7
  42. package/dist/export/xmlout.js.map +1 -1
  43. package/dist/import/content.d.ts +1 -33
  44. package/dist/import/content.d.ts.map +1 -1
  45. package/dist/import/content.js +208 -17
  46. package/dist/import/content.js.map +1 -1
  47. package/dist/import/controls.d.ts +2 -0
  48. package/dist/import/controls.d.ts.map +1 -0
  49. package/dist/import/controls.js +121 -0
  50. package/dist/import/controls.js.map +1 -0
  51. package/dist/import/index.d.ts +1 -1
  52. package/dist/import/index.d.ts.map +1 -1
  53. package/dist/import/index.js +82 -14
  54. package/dist/import/index.js.map +1 -1
  55. package/dist/import/ooxml.d.ts +1 -37
  56. package/dist/import/ooxml.d.ts.map +1 -1
  57. package/dist/import/ooxml.js +44 -8
  58. package/dist/import/ooxml.js.map +1 -1
  59. package/dist/import/parts.d.ts +1 -33
  60. package/dist/import/parts.d.ts.map +1 -1
  61. package/dist/import/parts.js +36 -10
  62. package/dist/import/parts.js.map +1 -1
  63. package/dist/import/pictures.d.ts +1 -33
  64. package/dist/import/pictures.d.ts.map +1 -1
  65. package/dist/import/pictures.js +7 -1
  66. package/dist/import/pictures.js.map +1 -1
  67. package/dist/import/properties.d.ts +1 -43
  68. package/dist/import/properties.d.ts.map +1 -1
  69. package/dist/import/properties.js +84 -6
  70. package/dist/import/properties.js.map +1 -1
  71. package/dist/import/report.d.ts +0 -10
  72. package/dist/import/report.d.ts.map +1 -1
  73. package/dist/import/report.js +1 -0
  74. package/dist/import/report.js.map +1 -1
  75. package/dist/import/stories.d.ts +2 -0
  76. package/dist/import/stories.d.ts.map +1 -0
  77. package/dist/import/stories.js +131 -0
  78. package/dist/import/stories.js.map +1 -0
  79. package/dist/import/tables.d.ts +0 -24
  80. package/dist/import/tables.d.ts.map +1 -1
  81. package/dist/import/tables.js +25 -6
  82. package/dist/import/tables.js.map +1 -1
  83. package/dist/package.d.ts +8 -4
  84. package/dist/package.d.ts.map +1 -1
  85. package/dist/package.js +38 -4
  86. package/dist/package.js.map +1 -1
  87. package/dist/settings.d.ts +1 -7
  88. package/dist/settings.d.ts.map +1 -1
  89. package/dist/settings.js +186 -26
  90. package/dist/settings.js.map +1 -1
  91. package/dist/xml.d.ts +8 -0
  92. package/dist/xml.d.ts.map +1 -1
  93. package/dist/xml.js +30 -2
  94. package/dist/xml.js.map +1 -1
  95. package/dist/zip.d.ts +0 -47
  96. package/dist/zip.d.ts.map +1 -1
  97. package/dist/zip.js +11 -2
  98. package/dist/zip.js.map +1 -1
  99. package/package.json +6 -5
  100. package/src/custom.ts +254 -0
  101. package/src/export/balance.ts +114 -0
  102. package/src/export/content.ts +203 -19
  103. package/src/export/controls.ts +260 -0
  104. package/src/export/index.ts +268 -20
  105. package/src/export/parts.ts +102 -10
  106. package/src/export/pictures.ts +21 -5
  107. package/src/export/properties.ts +90 -18
  108. package/src/export/tables.ts +15 -3
  109. package/src/export/xmlout.ts +36 -7
  110. package/src/import/content.ts +219 -17
  111. package/src/import/controls.ts +141 -0
  112. package/src/import/index.ts +103 -22
  113. package/src/import/ooxml.ts +44 -8
  114. package/src/import/parts.ts +44 -19
  115. package/src/import/pictures.ts +8 -1
  116. package/src/import/properties.ts +90 -6
  117. package/src/import/report.ts +1 -0
  118. package/src/import/stories.ts +134 -0
  119. package/src/import/tables.ts +25 -6
  120. package/src/package.ts +56 -6
  121. package/src/settings.ts +204 -27
  122. package/src/xml.ts +42 -2
  123. package/src/zip.ts +17 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,162 @@
1
1
  # @folijs/docx
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 7f252a3: **Foli 1.0.** The first stable release: from here the public API and the saved format change only
8
+ as [semver](https://semver.org/) allows. Moving from 0.x:
9
+ [the migration guide](https://foli.josepaudenis.com/docs/guides/migrating-from-0x/) (every
10
+ change since 0.6.0, each older minor's breaks, documents v1 to v5).
11
+
12
+ **What 1.0 promises** ([ADR-0008](https://foli.josepaudenis.com/docs/decisions/ADR-0008-1.0-contract-and-extensions/),
13
+ [versions and deprecation](https://foli.josepaudenis.com/docs/deprecation/)):
14
+ - **The API.** What each package's entry exports by name, as the
15
+ [API reference](https://foli.josepaudenis.com/docs/api/) lists it and its API report
16
+ (`api-report.d.ts`) records it, is the 1.x API: nothing is removed or changed before 2.0.
17
+ `@folijs/core/internal` is what the other Foli packages use from core, with no promise. The
18
+ `--foli-*` CSS variables and the documented classes are part of it.
19
+ - **Deprecation.** A name that will go is first deprecated in a minor (`@deprecated` naming its
20
+ replacement, a one-time development warning where cheap, listed in the changelog) and stays
21
+ until the next major at least.
22
+ - **One version.** The five packages share one version, and `@folijs/view`, `@folijs/react`,
23
+ `@folijs/docx` and `@folijs/pdf` take `@folijs/core` (React also `@folijs/view`) as a peer at
24
+ exactly that version: install and upgrade them together.
25
+ - **Saved documents.** Every 1.x reads every earlier format without loss: schema v1 to v5 (0.1.0
26
+ to 0.6.0), and any version a 1.x minor adds (only by adding, with a migration). A document is
27
+ saved with the lowest version its content needs: 1.0 saves v5, as 0.6.0 does. An older 1.x
28
+ refuses a document that needs a newer version with a `FoliDocumentError`; it never reads one
29
+ in part. Apps that walk the JSON must ignore node and mark types they do not know.
30
+
31
+ **New since 0.6.0** (details in the entries below):
32
+ - Custom nodes and marks (`Extension`: namespaced inline and block leaves and marks on Word's
33
+ schema), validated, saved in the JSON, copied and pasted, found, tracked, and written to `.docx`
34
+ as content controls tagged `foli:` and read back; without their extension they load as foreign
35
+ nodes and are kept.
36
+ - View extensions in `@folijs/view` (`ViewExtension`): node views (block ones laid out and split
37
+ across pages), mark views, decorations and plugin views, through `createEditor({ extensions })`
38
+ or React's `extensions` prop.
39
+ - Named commands from plugins (`PluginSpec.commands`, `editor.commands`, typed by augmenting
40
+ `FoliCommands`); a plugin's keymap overrides the view's own keys, the rest listed as reserved
41
+ ([keyboard](https://foli.josepaudenis.com/docs/keyboard/)).
42
+ - Toolbar items: `FoliToolbar`'s and `FoliEditor`'s `items`, the built-in items by name
43
+ (`toolbarItems`, `defaultToolbarItems`), app buttons and menus, `useCommand`.
44
+ - The public API listed by name, internals stripped from the published types, exact peers.
45
+ - Safer `.docx` import (`maxNodes`, a long paragraph in linear time), pictures copied into another
46
+ document with their images, faster keystrokes in long documents with lists.
47
+ - The docs site, [foli.josepaudenis.com/docs](https://foli.josepaudenis.com/docs/): getting
48
+ started, guides (extensions, theming, migration), the API reference per package, live examples,
49
+ the limitations.
50
+
51
+ **Known risks, accepted by the owner for 1.0 (2026-11-20):**
52
+ - The manual checks of ADR-0003 were never run on real devices: IME and dead keys on real
53
+ Windows, macOS, Android and iOS input methods (only Chromium's emulation is automated), screen
54
+ readers (NVDA, VoiceOver), macOS key bindings, spellcheck and autocorrect at a page edge, pastes
55
+ from real Word, Google Docs and LibreOffice, Safari (tests run on Playwright's WebKit on
56
+ Windows). A failure found later is fixed in a 1.x patch.
57
+ - Phase 5's speed targets are missed at 100 pages (104 pages, the owner's laptop, Chromium; Firefox
58
+ in brackets; [benchmarks](https://foli.josepaudenis.com/docs/benchmarks/#10-numbers)): the
59
+ first layout takes 118 ms (146; target 60), a full re-flow 148 ms (164; target 100), Enter's
60
+ handler 9.9 ms (14; target 8) and its paint p95 35 ms (49; target 25). Typing meets them in
61
+ Chromium (handler 7.9 ms, paint p95 14 ms), not in Firefox (11 and 28 ms). Every page is in the
62
+ DOM and laid out on load (no virtualization); the incremental redraw is for a 1.x minor.
63
+ - Everything else is a documented known limit:
64
+ [limitations](https://foli.josepaudenis.com/docs/limitations/).
65
+
66
+ ### Minor Changes
67
+
68
+ - 6e698b3: Custom nodes and marks (ADR-0008). An app declares its own types as an `Extension`
69
+ (`{ name, nodes?, marks?, plugins? }`) named `<namespace>:<name>` (`acme:mention`): inline or block
70
+ leaves with `text(attrs)`, the text they stand for, and marks. `createEditor({ extensions })`,
71
+ `parseDocument(document, { extensions })` and `exportDocx(document, package, { extensions })` take
72
+ them; they are stored as ordinary node and mark JSON and never change `schemaVersion`. Without its
73
+ extension a custom type is never dropped: it loads as a foreign node or mark (attributes checked as
74
+ plain JSON, at most 64 KiB), drawn as its type in brackets, and is saved back unchanged.
75
+ - Find matches a custom node's text as one position (replace leaves it, `locked`); inserting or
76
+ deleting one while tracking is a tracked change.
77
+ - `@folijs/view` draws custom nodes as their text (`data-foli-custom`) until node views; plain text
78
+ copies get their text, and a copy holding custom content carries its Foli JSON in the HTML too
79
+ (`data-foli-clipboard`), so pasting in Firefox keeps it.
80
+ - `@folijs/docx` writes a custom node as a locked plain text content control tagged `foli:` with
81
+ its type and attributes (a block node around a paragraph), each run of a custom mark as a rich
82
+ text control, and reads them back with or without the extension (a control holding anything
83
+ more stays a content control). A tag over 255 characters throws a `DocxError`. Checked through Word 16 (open, edit, save, read back).
84
+ - `NodeSpec` takes an optional `text(attrs)`. `parseContent(json, path?, fragment?)` becomes
85
+ `parseContent(json, { path?, fragment?, extensions? })` (`ContentOptions`).
86
+ - 68ee717: `readPackage` and `importDocx` take `maxNodes` (default 4 000 000, for all the parts read
87
+ together; every element, attribute, text, comment and processing instruction counts one, a
88
+ paragraph four), and `parseXml` takes it per document (no limit by default): a `.docx` of a few
89
+ kilobytes holding millions of empty paragraphs used to exhaust the memory of a browser tab or a
90
+ Node server (an uncatchable crash) before the 512 MiB `maxSize` was reached. Past the limit the
91
+ `DocxError` names it. `XmlDocument` gives its `nodes` count. A long paragraph of many runs
92
+ imports in linear time (200 000 line breaks took 18 s, now under a second).
93
+ - 2fac8e8: The public API is now listed by name (ADR-0008). `@folijs/core`'s entry exports each public name
94
+ explicitly; what the other Foli packages need from core without a promise moved to a second
95
+ entry, `@folijs/core/internal` (the Word context and envelope: `wordContext`, `withEnvelope`,
96
+ `setComments`, `StoryStep`, `CommentStep`, `EnvelopeStep`; the formatting resolver: `Resolver`,
97
+ `formatNumber`, `tableConditions` and their types; clipboard fitting: `copiedDefinitions`,
98
+ `fitPaste`, `fitPastedV2`; layout helpers; `schema`, `checkSection`, `checkControl`,
99
+ `RUN_PROPERTY_MARKS`), and a few helpers left the API (`defaultTextblockType`, `isNote`,
100
+ `storyBody`). Every other module export is tagged `@internal` and left out of the published
101
+ types. `@folijs/view` exports `RenderDocumentOptions`, the type of `renderDocument`'s options
102
+ (`review`, `fieldCodes`, `resource`). The model classes' constructors now appear in the types
103
+ with their parameters (create nodes and marks through `NodeType`, `MarkType` and `Schema`).
104
+ `@folijs/view`, `@folijs/react`, `@folijs/docx` and `@folijs/pdf` now take `@folijs/core` (and
105
+ `@folijs/react` also `@folijs/view`) as a peer dependency at exactly their own version instead of
106
+ a dependency: install the Foli packages together, at one version (npm 7+ and pnpm install peers
107
+ themselves).
108
+
109
+ ### Patch Changes
110
+
111
+ - 75d0cb6: `exportDocx` and `DocxPackage.write` return, and `exportPdf`'s `pdf` is, a
112
+ `Uint8Array<ArrayBuffer>` (they always were): with TypeScript 5.7 or later the bytes go into a
113
+ `Blob` or a `Response` without a cast. The published types now need TypeScript 5.7 or later.
114
+ - 785538a: `exportDocx` no longer refuses a document saved with schema v3 (0.3.0, 0.4.0) from a `.docx`
115
+ with "a changed table style cannot be exported yet": v3 kept a table style's properties in its
116
+ original XML only, so their absence from the model is now written as read, not taken as a change.
117
+ - Updated dependencies [0cb49e7]
118
+ - Updated dependencies [6e698b3]
119
+ - Updated dependencies [4f7197a]
120
+ - Updated dependencies [f96c3dc]
121
+ - Updated dependencies [c9c227d]
122
+ - Updated dependencies [2fac8e8]
123
+ - Updated dependencies [7f252a3]
124
+ - Updated dependencies [9a4a87f]
125
+ - @folijs/core@1.0.0
126
+
127
+ ## 0.6.0
128
+
129
+ ### Minor Changes
130
+
131
+ - cd343e4: Sections, headers and footers, notes, fields, content controls, find and replace, and PDF, as Word models them: imported, laid out on pages, edited there and written back to `.docx`.
132
+ - **Schema v5** (`@folijs/core`, ADR-0007): `stories` in the envelope (headers, footers, footnotes and endnotes, each a tree of blocks), `controls` (content controls' properties) and `settings` (even and odd headers, note options, `doNotUseHTMLParagraphAutoSpacing`); field markers (`fieldStart`, `fieldCode`, `fieldSeparator`, `fieldEnd`), content control markers (`controlStart`, `controlEnd`; a `controls` attribute on blocks, rows and cells), `noteReference` and `noteMark` nodes; sections gain `columns`, `pageNumbers`, note properties and a tracked setup change (`change`). `SCHEMA_VERSION` 5: v4 documents migrate on load (the version only: what was opaque stays so until the `.docx` is imported again).
133
+ - **Stories and undo** (`@folijs/core`): `editor.story(id)` gives an editor over a header, footer or note; its changes are `StoryStep`s of the body's history (one undo across the document), `EnvelopeStep` for the last section, settings and controls; accept and reject all reach every story.
134
+ - **Sections** (`@folijs/core`, `@folijs/view`, `@folijs/react`): columns (equal and set widths, the line between, column breaks), continuous, next-column and even and odd page sections with Word's blank page, balanced columns above a continuous break; `insertSectionBreak`, `removeSectionBreak`, `setSectionSetup`, `insertColumnBreak`, tracked as Word records them; a Section menu and Page setup dialog.
135
+ - **Headers and footers**: drawn in their margins on every page (first, even and default variants, linked to the previous section, a taller one pushing the text, page fields filled per page), edited in place (double click or the Header menu, Escape returns) with typing, formatting, pictures, tables, undo and tracking; `setDifferentFirstPage`, `setDifferentEvenPages`, `setStoryLinked`.
136
+ - **Footnotes and endnotes**: at their reference's page foot under a separator, continued on the next page, beneath the text or at the end of a section or the document; numbered in Word's formats with restarts (`noteNumbers`, never stored); `insertNote`, `setNoteProperties`, `convertNotes`; deleted with their reference, tracked, carried on the clipboard; edited in place (double click, Shift+Alt+N, the Notes menu and its options dialog).
137
+ - **Fields**: shown with their results, selected and deleted whole, codes hidden or shown (Alt+F9); `updateFields` (`PAGE`, `NUMPAGES`, `SECTIONPAGES`, `DATE`, `TIME`, `REF`, `PAGEREF`, `SEQ`, `TOC` from heading styles with their pages, `MERGEFIELD` from data; F9, Ctrl+A then F9, `view.updateFields`, `view.print()`) returning what it updated and what it left; `fieldsIn`, `insertField`, `insertPageNumber`, `insertDate`, `insertCrossReference`, `insertTableOfContents`; a Fields menu and cross-reference dialog.
138
+ - **Content controls**: plain and rich text, drop-down, combo box, date, check box, picture, repeating sections, with Word's locks, placeholders and what each kind holds; frames, titles, lists, a date picker and check boxes in the view (Alt+Down, Space); `insertControl`, `setControlValue` and `controlValues` (by id or tag), `setControlProperties`, `addRepeatingItem`; a Controls menu and properties dialog.
139
+ - **Navigation**: `findAll`, `replace`, `replaceAll` over the body and every story (match case, whole words, tracked while tracking, one undo step), `insertBookmark`, `renameBookmark`, `deleteBookmark`, `listBookmarks`, `goTo`, `documentOutline`; matches marked with the CSS Custom Highlight API; `FoliNavigation` (find, replace and go to panel, bookmarks dialog, outline), included in `FoliEditor`, with Word's keys (Ctrl+F, Ctrl+H, Ctrl+G, F3, Shift+F3, Ctrl+Shift+F5) and a Navigate menu.
140
+ - **DOCX** (`@folijs/docx`): headers, footers, footnotes and endnotes read and written as stories (unchanged ones byte for byte, new ones with their parts, relationships and content types), complex and simple fields, content controls at every level (properties patched into the kept `w:sdtPr`), sections' columns, page numbers and note properties, `word/settings.xml`'s even and odd headers and note options. Word reads Foli's sections, headers, notes, fields, controls and replacements back (`scripts/corpus/*-roundtrip.mjs`).
141
+ - **PDF** (`@folijs/pdf`, first released): `exportPdf(document, { page, resources, review, styles })` prints Foli's own pages with a headless Chromium page the app supplies (Playwright 1.42+; Puppeteer's page type fits): each section on its own sheet size, fields updated from the pages first, safe links and bookmark links as PDF links, headings as PDF bookmarks, a tagged PDF. The page loads nothing from the network (images and fonts as `data:` URLs only). Against Word's PDFs of the corpus it scores 0.954 over 24 pages.
142
+ - **Pages against Word**: all 158 paragraphs outside tables that the harness compares on Word's page; headers, footers and notes scored with the rest of the page (0.889 over 24 pages on screen).
143
+
144
+ 0.5.0 cannot read documents saved by 0.6.0 (schema v5). Known limits are in [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md) (content, finding and going places, print and PDF sections).
145
+
146
+ Changed behaviour (pre-1.0 minor):
147
+ - `.docx` headers, footers and notes import as `stories` (0.5.0 kept them as parts, never shown); note references, fields (`w:fldChar`, `w:instrText`, `w:fldSimple`) and content controls (`w:sdt`) that imported as `opaqueInline` or `opaqueBlock` now import as nodes. A v4 document's opaque content stays opaque until the `.docx` is imported again.
148
+ - Layout: between two paragraphs goes the larger of the first's space after and the second's space before, as in Word's PDFs (0.5.0 added them; they still add up with `w:doNotUseHTMLParagraphAutoSpacing`); a line is as tall as its runs and paragraph mark, not the paragraph style's font; a header or footer taller than its margin pushes the text. Pages break differently than in 0.5.0, closer to Word.
149
+ - `FoliEditor` includes `FoliNavigation` and takes Ctrl+F, Ctrl+H, Ctrl+G, F3, Shift+F3 and Ctrl+Shift+F5 while the focus is in the document or its panels (the browser's own find no longer opens there).
150
+ - `FoliToolbar` shows the Section, Header, Fields, Navigate, Notes and Controls menus.
151
+ - `view.print()` updates every field before printing; the print rules are shared with `exportPdf`.
152
+ - Backspace at a field's edge selects the field first, and a selection crossing a field's markers takes the whole field, as in Word; the caret steps over a field's code.
153
+ - `acceptAllChanges` and `rejectAllChanges` also settle the tracked changes in headers, footers and notes.
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies [cd343e4]
158
+ - @folijs/core@0.6.0
159
+
3
160
  ## 0.5.0
4
161
 
5
162
  ### Minor Changes
package/README.md CHANGED
@@ -1,11 +1,12 @@
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 v4 of `@folijs/core`), exports it back losslessly (`exportDocx`), and reads its package
4
+ (schema v5 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
- runs in the browser, workers and Node 20.12+. Depends only on `@folijs/core`.
6
+ runs in the browser, workers and Node 20.12+. Its only dependency is `@folijs/core`, a peer at
7
+ exactly its own version: `npm install @folijs/docx @folijs/core`.
7
8
 
8
- > Early release: the API may change in any 0.x minor version (changes in `CHANGELOG.md`).
9
+ > Stable since 1.0.0: the public API and the saved format follow semver ([versions and deprecation](https://foli.josepaudenis.com/docs/deprecation/)); changes in `CHANGELOG.md`. Docs: [foli.josepaudenis.com/docs](https://foli.josepaudenis.com/docs/).
9
10
 
10
11
  ```ts
11
12
  import { importDocx } from "@folijs/docx";
@@ -16,13 +17,14 @@ const {
16
17
  report,
17
18
  } = await importDocx(new Uint8Array(await file.arrayBuffer()));
18
19
  document.content; // paragraphs with Word's properties, runs as text with marks, tables
20
+ document.stories; // headers, footers, footnotes and endnotes, by id
19
21
  document.styles; // with basedOn, run and paragraph properties
20
- report.opaque; // { "w:fldChar": 3 }: content kept verbatim, not editable yet
22
+ report.opaque; // { "w:annotationRef": 4 }: content kept verbatim, not editable
21
23
  ```
22
24
 
23
25
  **Import** (`importDocx`, `importPackage`) reads the main document, styles (with the document
24
26
  defaults), numbering, the theme's fonts and colors, comments (with replies and resolved state
25
- from `commentsExtended`) and sections:
27
+ from `commentsExtended`), sections, headers, footers, footnotes, endnotes and settings:
26
28
 
27
29
  - **Paragraphs** with their properties (style, justification, indentation, spacing, keep rules,
28
30
  outline level, numbering, tab stops, borders, shading, the paragraph mark's formatting and
@@ -30,6 +32,24 @@ from `commentsExtended`) and sections:
30
32
  (`w14:paraId`…). **Runs** become text, tabs and breaks with their properties as marks; tracked
31
33
  insertions, deletions and moves, hyperlinks (target from the relationship, or a bookmark),
32
34
  bookmarks, comment ranges and references are modeled.
35
+ - **Sections** (11.6): page size and margins, how each starts, `w:cols` (equal or set widths, the
36
+ line between them), `w:pgNumType`, `w:footnotePr`, `w:endnotePr` and a tracked setup change
37
+ (`w:sectPrChange`), read and written; a section unchanged is exported byte for byte, a changed
38
+ one rewrites only what changed. A recorded setup is written with every value spelled out: Word
39
+ sees no change in what it leaves out.
40
+ - **Headers, footers and notes** (11.4) become `stories` holding the body's kinds of blocks
41
+ (tables and pictures included), a note's reference a `noteReference` node and its number in the
42
+ note a `noteMark`. What a story may not hold (a section break, a note reference, a comment, a
43
+ page or column break in a note) stays verbatim there, reported.
44
+ - **Fields** (11.5): complex fields (`w:fldChar`, `w:instrText`), nested and across runs and
45
+ paragraphs, become `fieldStart`, `fieldCode`, `fieldSeparator` and `fieldEnd` markers with their
46
+ result as ordinary content; `w:fldSimple` reads as the same markers and is written back as one.
47
+ Merge fields and form fields (`w:ffData` kept) are fields like the others.
48
+ - **Content controls** (11.5, 11.9) at run, block, row and cell level are modeled with their
49
+ properties (`controls`), `w:sdtPr` and `w:sdtEndPr` kept in `ext`: what changes is patched child
50
+ by child, the rest stays byte for byte, a new control gets a whole `w:sdtPr`, and the glossary
51
+ gives the text an emptied one shows. Data bindings are kept, not evaluated. An empty block
52
+ control stays verbatim.
33
53
  - **Tables** (10.4) become `table`, `tableRow` and `tableCell` nodes: the table's, rows' and
34
54
  cells' properties (`w:tblPr`, `w:tblGrid`, `w:tblPrEx`, `w:trPr`, `w:tcPr`) as attributes,
35
55
  merges as Word writes them (`gridSpan`, `vMerge`), a row inserted or deleted as a tracked
@@ -46,8 +66,7 @@ from `commentsExtended`) and sections:
46
66
  styles, numbering levels and definitions, the document defaults; `runExt` on runs; a comment's
47
67
  start tag), and unknown attributes of modeled elements go to attribute bags (paragraphs,
48
68
  links, tracked changes, bookmarks and comment anchors: `w16du:dateUtc`, `w14:paraId`…). Every
49
- element Foli does not model yet (content controls, pictures, fields' structure,
50
- footnote references, equations…) becomes an opaque node holding its source, and so does an
69
+ element Foli does not model yet (equations, charts, shapes…) becomes an opaque node holding its source, and so does an
51
70
  element the model rejects as a whole (a tracked change with an id past Word's range, a link in
52
71
  a link, a run with an unknown attribute): never stripped to plain text. Export (8.5) writes all
53
72
  of it back; keep `package` with the document, the parts Foli does not edit come from it. The
@@ -69,14 +88,17 @@ from `commentsExtended`) and sections:
69
88
  between elements, and the empty paragraph given to an empty body or comment. Text is read as
70
89
  Word reads it: without `xml:space="preserve"`, whitespace at the ends of a `w:t` is not text.
71
90
 
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.
91
+ **Settings.** Of `settings.xml`, `w:trackRevisions` is read (`DocxImport.trackRevisions`)
92
+ and, when `exportDocx` is given `trackRevisions`, written; `w:evenAndOddHeaders` and the note
93
+ properties of `w:footnotePr` and `w:endnotePr` are the document's `settings`, written when they
94
+ differ from the part (the separators listed in those elements stay). Each is added in its place
95
+ among the settings, or removed; the rest of the part is kept byte for byte, and all of it when
96
+ nothing differs. A new package gets a settings part only with tracking on or `settings`.
76
97
 
77
98
  **Export** (`exportDocx(document, package?, options?)`) writes the parts the editor owns
78
99
  (`document.xml`, `styles.xml`, `numbering.xml`, `comments.xml`, `commentsExtended.xml`,
79
- relationships for new hyperlink targets, and `settings.xml` when `trackRevisions` changes it)
100
+ relationships for new hyperlink targets, and `settings.xml` when `trackRevisions` or `settings`
101
+ change it)
80
102
  and copies every other part of the original package byte for byte (its compressed entry
81
103
  included). Within the parts it writes:
82
104
 
@@ -106,9 +128,15 @@ included). Within the parts it writes:
106
128
  into: one element of the expected kind, prefixes the part declares, no attribute the writer
107
129
  writes itself. What does not fit is a `DocxError`, never ill-formed XML.
108
130
  - Without a package, a new one is made (from a migrated v2 document, say), declaring Word's
109
- namespaces. A document that refers to parts of its original package (headers, footers,
110
- pictures, content kept verbatim with relationship ids) needs that package: exporting it
111
- without one is a `DocxError`.
131
+ namespaces. A document that refers to parts of its original package (headers and footers it
132
+ has no story for, pictures, content kept verbatim with relationship ids) needs that package:
133
+ exporting it without one is a `DocxError`.
134
+ - Headers, footers, footnotes and endnotes are the document's `stories`. An unchanged one keeps
135
+ its part (or, for a note, its element) byte for byte; a changed one is written from the model;
136
+ a new one gets its part, relationship and content type. A note whose story is gone is removed
137
+ from its part. A document without `stories` leaves those parts as they are. Notes inserted,
138
+ deleted, tracked, converted or given new options in the editor are written as Word writes them,
139
+ and Word reads them back (`scripts/corpus/story-roundtrip.mjs`).
112
140
  - Tables are written from the model: each properties element as paragraphs' are (verbatim
113
141
  while unchanged, else child by child), the grid as read while its widths are, rows and cells
114
142
  in order; Word reads every corpus table back with Foli's text, unchanged and edited
@@ -126,7 +154,8 @@ included). Within the parts it writes:
126
154
  `wp:posOffset` as `offset` in EMU or `wp:align` as `align`), `wrap` (`square`, `tight`,
127
155
  `through`, `topAndBottom`; `wp:wrapNone` is `behind` or `inFront` by `behindDoc`), `side`
128
156
  (`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
157
+ lock and wrap polygon stay in `ext`. A position given both an `offset` and an `align` (Foli's
158
+ schema allows it; Word's holds one) is written with the offset. One positioned by `simplePos`, hidden, sized relative to
130
159
  the page (`wp14:sizeRelH`/`sizeRelV`), or with no position or wrapping the model reads, stays
131
160
  opaque, as linked images, charts, shapes and other drawings do.
132
161
  - Pictures are written from their `ext` with only what the model changed from it written in
@@ -192,7 +221,15 @@ const bytes = await pkg.write(new Map([["/word/document.xml", new TextEncoder().
192
221
  ends and attribute whitespace normalized as XML defines; characters XML forbids, `--` in
193
222
  comments and `]]>` in text refused. No DTD: a document type declaration is refused (OOXML
194
223
  forbids one), so no entity expansion. Nesting limited (`maxDepth`, default 1000) so code
195
- walking the tree recursively is safe; linear time in the input.
224
+ walking the tree recursively is safe; linear time in the input. Nodes limited (`maxNodes`:
225
+ elements, attributes, text, comments and processing instructions, one each; no limit by
226
+ default for `parseXml` itself).
227
+ - **Memory:** a package's parts read together hold at most `maxNodes` nodes (default
228
+ 4 000 000; a paragraph counts four, as it costs that much more once imported), else a
229
+ `DocxError` naming the limit. A 659-page document of dense tables counts 1.9 million and
230
+ takes about 0.8 GB to import in Node; at the limit, the costliest crafted file (a few tens of
231
+ kilobytes) takes about 2.3 GB and 12-28 s depending on heap headroom. On a server, lower `maxSize` and `maxNodes` to what
232
+ your documents need and import in a worker with a time limit.
196
233
  - **Package:** part names compare case-insensitively and percent-decoded (never decoding a
197
234
  `/`), content types by override then default extension, relationship targets resolved
198
235
  against their source part (a target that is a full URI is not a part). The main part must be
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=custom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../src/custom.ts"],"names":[],"mappings":""}
package/dist/custom.js ADDED
@@ -0,0 +1,216 @@
1
+ import { CUSTOM_TYPE, foreignTextOf, withForeignText } from "@folijs/core/internal";
2
+ import { DocxError } from "./package.js";
3
+ const PREFIX = "foli:";
4
+ /** Word keeps a tag of 255 characters (ADR-0008's spike); `checkControl` takes no more. */
5
+ const MAX_TAG = 255;
6
+ const isCustom = (type) => CUSTOM_TYPE.test(type);
7
+ const sameMark = (a, b) => a.type === b.type && JSON.stringify(a.attrs ?? {}) === JSON.stringify(b.attrs ?? {});
8
+ const withMarks = (node, marks) => {
9
+ const { marks: _, ...rest } = node;
10
+ return marks.length ? { ...rest, marks: [...marks] } : rest;
11
+ };
12
+ const marker = (type, id) => ({
13
+ type,
14
+ attrs: { id },
15
+ });
16
+ /** Every content tree of a document (body, stories, comments), mapped by `map`. */
17
+ function mapTrees(document, map) {
18
+ return {
19
+ ...document,
20
+ content: map(document.content),
21
+ comments: document.comments.map((c) => ({
22
+ ...c,
23
+ content: map({ type: "doc", content: c.content }).content ?? [],
24
+ })),
25
+ ...(document.stories && {
26
+ stories: Object.fromEntries(Object.entries(document.stories).map(([id, s]) => [id, { ...s, content: map(s.content) }])),
27
+ }),
28
+ };
29
+ }
30
+ /**
31
+ * The document with its custom nodes and marks as tagged content controls.
32
+ * @internal
33
+ */
34
+ export function customToWord(document, extensions = []) {
35
+ const texts = new Map();
36
+ for (const e of extensions)
37
+ for (const [name, spec] of Object.entries(e.nodes ?? {}))
38
+ texts.set(name, spec.text);
39
+ const textOf = (node) => texts.get(node.type)?.(node.attrs ?? {}) ?? foreignTextOf(node) ?? `[${node.type}]`;
40
+ const controls = { ...document.controls };
41
+ let next = 0;
42
+ const add = (tagged, control) => {
43
+ const tag = PREFIX + JSON.stringify(tagged);
44
+ if (tag.length > MAX_TAG)
45
+ throw new DocxError(`${tagged.node ?? tagged.mark}: its attributes do not fit a content control's tag ` +
46
+ `(${tag.length} > ${MAX_TAG} characters)`);
47
+ let id;
48
+ do
49
+ id = `foli-${++next}`;
50
+ while (Object.hasOwn(controls, id));
51
+ controls[id] = { ...control, tag };
52
+ return id;
53
+ };
54
+ const inlines = (items) => {
55
+ const out = [];
56
+ for (let i = 0; i < items.length;) {
57
+ const item = items[i];
58
+ const mark = item.marks?.find((m) => isCustom(m.type));
59
+ if (mark) {
60
+ let j = i;
61
+ while (j < items.length && items[j]?.marks?.some((m) => sameMark(m, mark)))
62
+ j++;
63
+ const inner = items.slice(i, j).map((n) => withMarks(n, (n.marks ?? []).filter((m) => !sameMark(m, mark))));
64
+ const id = add({ mark: mark.type, attrs: mark.attrs ?? {} }, { kind: "richText" });
65
+ out.push(marker("controlStart", id), ...inlines(inner), marker("controlEnd", id));
66
+ i = j;
67
+ continue;
68
+ }
69
+ if (isCustom(item.type)) {
70
+ const id = add({ node: item.type, attrs: item.attrs ?? {} }, { kind: "text", lock: "contentLocked" });
71
+ const text = textOf(item);
72
+ out.push(marker("controlStart", id), ...(text ? [withMarks({ type: "text", text }, item.marks ?? [])] : []), marker("controlEnd", id));
73
+ }
74
+ else
75
+ out.push(item);
76
+ i++;
77
+ }
78
+ return out;
79
+ };
80
+ const blocks = (node) => {
81
+ if (isCustom(node.type)) {
82
+ const id = add({ node: node.type, attrs: node.attrs ?? {} }, { kind: "text", lock: "contentLocked" });
83
+ const text = textOf(node);
84
+ return {
85
+ type: "paragraph",
86
+ attrs: { controls: [id] },
87
+ ...(text ? { content: [{ type: "text", text }] } : {}),
88
+ };
89
+ }
90
+ if (!node.content)
91
+ return node;
92
+ if (node.type === "paragraph")
93
+ return { ...node, content: inlines(node.content) };
94
+ return { ...node, content: node.content.map(blocks) };
95
+ };
96
+ const mapped = mapTrees(document, blocks);
97
+ return next ? { ...mapped, controls } : mapped;
98
+ }
99
+ /**
100
+ * The document with controls tagged by `customToWord` back as custom nodes and marks.
101
+ * @internal
102
+ */
103
+ export function customFromWord(document) {
104
+ const controls = { ...document.controls };
105
+ // How often each control id is used: one used twice (a control split by an edit) stays.
106
+ const uses = new Map();
107
+ const count = (node) => {
108
+ const ids = node.type === "controlStart"
109
+ ? [node.attrs?.id]
110
+ : (node.attrs?.controls ?? []);
111
+ for (const id of ids)
112
+ if (typeof id === "string")
113
+ uses.set(id, (uses.get(id) ?? 0) + 1);
114
+ node.content?.forEach(count);
115
+ };
116
+ mapTrees(document, (tree) => {
117
+ count(tree);
118
+ return tree;
119
+ });
120
+ const read = (id, kind) => {
121
+ if (typeof id !== "string" || !Object.hasOwn(controls, id) || uses.get(id) !== 1)
122
+ return null;
123
+ const control = controls[id];
124
+ if (control.kind !== kind || control.placeholder?.showing || !control.tag?.startsWith(PREFIX))
125
+ return null;
126
+ try {
127
+ const value = JSON.parse(control.tag.slice(PREFIX.length));
128
+ const type = kind === "text" ? value.node : value.mark;
129
+ const attrs = value.attrs;
130
+ const plain = attrs === undefined ||
131
+ (typeof attrs === "object" && attrs !== null && !Array.isArray(attrs));
132
+ return typeof type === "string" && isCustom(type) && plain ? value : null;
133
+ }
134
+ catch {
135
+ return null; // Not ours after all: kept as the control it is.
136
+ }
137
+ };
138
+ const used = new Set();
139
+ const nodeOf = (value, text, marks = []) => withForeignText(withMarks({ type: value.node, ...(value.attrs ? { attrs: value.attrs } : {}) }, marks), text);
140
+ /** Text runs alone, all formatted alike: what a node's control holds when nothing else is in it. */
141
+ const plainText = (items) => items.every((n) => n.type === "text" && JSON.stringify(n.marks) === JSON.stringify(items[0]?.marks));
142
+ const inlines = (items) => {
143
+ const out = [];
144
+ // Where each control ends, found once: scanning (or copying) the rest of a paragraph per
145
+ // node took minutes on a long one (12.11).
146
+ const ends = new Map();
147
+ items.forEach((n, j) => {
148
+ if (n.type !== "controlEnd")
149
+ return;
150
+ const list = ends.get(n.attrs?.id);
151
+ if (list)
152
+ list.push(j);
153
+ else
154
+ ends.set(n.attrs?.id, [j]);
155
+ });
156
+ for (let i = 0; i < items.length; i++) {
157
+ const item = items[i];
158
+ const id = item.type === "controlStart" ? item.attrs?.id : undefined;
159
+ const end = id ? (ends.get(id)?.find((j) => j > i) ?? -1) : -1;
160
+ const inner = end > 0 ? items.slice(i + 1, end) : [];
161
+ // A node's control with text runs only, or a mark's around something: anything else (a
162
+ // bookmark or a field in a node's control, an empty control) stays the control it is.
163
+ const node = end > 0 && plainText(inner) ? read(id, "text") : null;
164
+ const mark = end > 0 && !node && inner.length ? read(id, "richText") : null;
165
+ if (node) {
166
+ out.push(nodeOf(node, inner.map((n) => n.text ?? "").join(""), inner[0]?.marks));
167
+ }
168
+ else if (mark) {
169
+ const type = {
170
+ type: mark.mark,
171
+ ...(mark.attrs && { attrs: mark.attrs }),
172
+ };
173
+ out.push(...inlines(inner).map((n) => withMarks(n, [...(n.marks ?? []), type])));
174
+ }
175
+ else {
176
+ out.push(item);
177
+ continue;
178
+ }
179
+ used.add(id);
180
+ i = end;
181
+ }
182
+ return out;
183
+ };
184
+ const blocks = (node) => {
185
+ const own = node.attrs?.controls;
186
+ // A block node's control holds one paragraph of plain text and nothing of its own: no other
187
+ // control around it, no properties, section or tracked change (Word's ids aside).
188
+ const { controls: _, attributes, ...rest } = (node.attrs ?? {});
189
+ const value = node.type === "paragraph" &&
190
+ own?.length === 1 &&
191
+ Object.values(rest).every((v) => v === null || v === undefined) &&
192
+ Object.keys(attributes ?? {}).every((k) => WORD_IDS.test(k)) &&
193
+ (node.content ?? []).every((n) => n.type === "text" && !n.marks?.length)
194
+ ? read(own[0], "text")
195
+ : null;
196
+ if (value?.node) {
197
+ used.add(own?.[0]);
198
+ return nodeOf(value, (node.content ?? []).map((n) => n.text ?? "").join(""));
199
+ }
200
+ if (!node.content)
201
+ return node;
202
+ if (node.type === "paragraph")
203
+ return { ...node, content: inlines(node.content) };
204
+ return { ...node, content: node.content.map(blocks) };
205
+ };
206
+ const mapped = mapTrees(document, blocks);
207
+ if (!used.size)
208
+ return document;
209
+ for (const id of used)
210
+ delete controls[id];
211
+ const { controls: _, ...rest } = mapped;
212
+ return Object.keys(controls).length ? { ...rest, controls } : rest;
213
+ }
214
+ /** A paragraph's attributes Word sets on every paragraph it saves: ids that say nothing of it. */
215
+ const WORD_IDS = /^(w14:paraId|w14:textId|w:rsid\w*)$/;
216
+ //# sourceMappingURL=custom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom.js","sourceRoot":"","sources":["../src/custom.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,MAAM,GAAG,OAAO,CAAC;AACvB,2FAA2F;AAC3F,MAAM,OAAO,GAAG,GAAG,CAAC;AASpB,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1D,MAAM,QAAQ,GAAG,CAAC,CAAW,EAAE,CAAW,EAAE,EAAE,CAC5C,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;AACvF,MAAM,SAAS,GAAG,CAAC,IAAc,EAAE,KAA0B,EAAY,EAAE;IACzE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACnC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9D,CAAC,CAAC;AACF,MAAM,MAAM,GAAG,CAAC,IAAmC,EAAE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