@folijs/docx 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENSE +21 -0
  3. package/README.md +151 -2
  4. package/dist/export/content.d.ts +17 -0
  5. package/dist/export/content.d.ts.map +1 -0
  6. package/dist/export/content.js +165 -0
  7. package/dist/export/content.js.map +1 -0
  8. package/dist/export/index.d.ts +21 -0
  9. package/dist/export/index.d.ts.map +1 -0
  10. package/dist/export/index.js +360 -0
  11. package/dist/export/index.js.map +1 -0
  12. package/dist/export/parts.d.ts +24 -0
  13. package/dist/export/parts.d.ts.map +1 -0
  14. package/dist/export/parts.js +413 -0
  15. package/dist/export/parts.js.map +1 -0
  16. package/dist/export/properties.d.ts +39 -0
  17. package/dist/export/properties.d.ts.map +1 -0
  18. package/dist/export/properties.js +506 -0
  19. package/dist/export/properties.js.map +1 -0
  20. package/dist/export/xmlout.d.ts +63 -0
  21. package/dist/export/xmlout.d.ts.map +1 -0
  22. package/dist/export/xmlout.js +194 -0
  23. package/dist/export/xmlout.js.map +1 -0
  24. package/dist/import/content.d.ts +35 -0
  25. package/dist/import/content.d.ts.map +1 -0
  26. package/dist/import/content.js +370 -0
  27. package/dist/import/content.js.map +1 -0
  28. package/dist/import/index.d.ts +31 -0
  29. package/dist/import/index.d.ts.map +1 -0
  30. package/dist/import/index.js +106 -0
  31. package/dist/import/index.js.map +1 -0
  32. package/dist/import/ooxml.d.ts +39 -0
  33. package/dist/import/ooxml.d.ts.map +1 -0
  34. package/dist/import/ooxml.js +71 -0
  35. package/dist/import/ooxml.js.map +1 -0
  36. package/dist/import/parts.d.ts +35 -0
  37. package/dist/import/parts.d.ts.map +1 -0
  38. package/dist/import/parts.js +365 -0
  39. package/dist/import/parts.js.map +1 -0
  40. package/dist/import/properties.d.ts +50 -0
  41. package/dist/import/properties.d.ts.map +1 -0
  42. package/dist/import/properties.js +404 -0
  43. package/dist/import/properties.js.map +1 -0
  44. package/dist/import/report.d.ts +28 -0
  45. package/dist/import/report.d.ts.map +1 -0
  46. package/dist/import/report.js +42 -0
  47. package/dist/import/report.js.map +1 -0
  48. package/dist/index.d.ts +6 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +6 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/package.d.ts +70 -0
  53. package/dist/package.d.ts.map +1 -0
  54. package/dist/package.js +259 -0
  55. package/dist/package.js.map +1 -0
  56. package/dist/settings.d.ts +8 -0
  57. package/dist/settings.d.ts.map +1 -0
  58. package/dist/settings.js +72 -0
  59. package/dist/settings.js.map +1 -0
  60. package/dist/xml.d.ts +79 -0
  61. package/dist/xml.d.ts.map +1 -0
  62. package/dist/xml.js +384 -0
  63. package/dist/xml.js.map +1 -0
  64. package/dist/zip.d.ts +66 -0
  65. package/dist/zip.d.ts.map +1 -0
  66. package/dist/zip.js +356 -0
  67. package/dist/zip.js.map +1 -0
  68. package/package.json +36 -3
  69. package/src/export/content.ts +229 -0
  70. package/src/export/index.ts +473 -0
  71. package/src/export/parts.ts +545 -0
  72. package/src/export/properties.ts +608 -0
  73. package/src/export/xmlout.ts +225 -0
  74. package/src/import/content.ts +413 -0
  75. package/src/import/index.ts +139 -0
  76. package/src/import/ooxml.ts +78 -0
  77. package/src/import/parts.ts +423 -0
  78. package/src/import/properties.ts +507 -0
  79. package/src/import/report.ts +64 -0
  80. package/src/index.ts +24 -0
  81. package/src/package.ts +328 -0
  82. package/src/settings.ts +75 -0
  83. package/src/xml.ts +443 -0
  84. package/src/zip.ts +401 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # @folijs/docx
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e2a6e23: Review as in Word: tracked changes recorded, shown, accepted and rejected; comments written, answered and resolved; both round-trip with Word.
8
+ - **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.
9
+ - **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.
10
+ - **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.
11
+ - **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`.
12
+ - **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.
13
+
14
+ 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).
15
+
16
+ Changed behaviour (pre-1.0 minor):
17
+ - 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).
18
+ - `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.
19
+ - `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).
20
+ - 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`.
21
+ - `withEnvelope` ignores comments: change them with `setComments` (or the comment commands).
22
+ - `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.
23
+ - 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 …".
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [e2a6e23]
28
+ - @folijs/core@0.4.0
29
+
30
+ ## 0.3.0
31
+
32
+ ### Minor Changes
33
+
34
+ - 8da5b98: Word documents (schema v3): Foli opens a `.docx`, shows it with the file's own styles on real pages, edits it, and saves it back without losing what it does not edit.
35
+ - **Model** (`@folijs/core`, schema v3, Word-shaped): paragraph properties as attributes (style, justification, indentation, spacing, keep and widow rules, page break before, outline level, numbering, tab stops, borders, shading); run properties as marks (character style, bold, italic, underline styles, strike, font, size, color, highlight, shading, vertical alignment, caps); headings as Word's heading styles; lists as Word's numbering (formats, starts, restarts, levels, legal numbering); sections with their own page size, orientation and margins; styles with `basedOn`, document defaults and the theme in the envelope; tracked insertions and deletions and comment anchors, with the comments; content the model does not hold kept as opaque nodes. Effective formatting and list numbers resolved as Word resolves them. Documents saved by 0.1.0 and 0.2.0 load through a migration without content loss.
36
+ - **DOCX** (`@folijs/docx`, new; browser, worker and Node, no third-party dependencies): `importDocx` to schema v3 with a report of what stayed opaque; `exportDocx` rewriting only the parts the editor owns, so a document saved without edits is the original under a canonical comparison, and parts the editor does not own are written back byte for byte. Checked with Word: every corpus document, exported unchanged and edited, opens without a repair prompt.
37
+ - **View** (`@folijs/view`): `renderDocument` lays a document out read-only on Word-like pages (tracked changes as markup or final); `EditorView` edits on the same pages, each section on pages of its own size and margins, and prints one sheet per page with each section's size. A font the machine lacks falls back to a metric-compatible substitute when one is installed (Carlito, Caladea, Liberation…).
38
+ - **React** (`@folijs/react`): `FoliEditor` and `useFoliEditor` take a document of any version and edit and report it as v3; the toolbar has a style box (the document's paragraph styles, headings included), font, size, line spacing and a page break, with Word-numbered bulleted and numbered lists.
39
+ - **Fidelity with Word** (corpus of five Word-written documents; `corpus/README.md`): 106 of 106 paragraphs start on Word's page and 103 on Word's line; pages scored against Word's PDF at 0.544.
40
+
41
+ Known risks, besides those of 0.2.0 (manual IME, screen-reader and real-paste checks not run): headers, footers, footnotes and floating pictures are kept and exported but not shown; tables are shown from their XML but are not editable or split across pages; page setups and section breaks cannot be edited yet; tracked changes are shown but not recorded, accepted or rejected (Phase 9). See [Known limitations](https://github.com/josep-audenis/foli/blob/main/docs/limitations.md).
42
+
43
+ Breaking (pre-1.0 minor): upgrade every app that reads your documents before saving with 0.3.0, since 0.2.0 cannot read version 3.
44
+ - Documents persist as v3: `FoliChange.document`, `getDocument()` and `useFoliEditor` give v3; `createEditor`, `setDocument` and `FoliEditor`'s `initialContent` take a document of any version (`EditorDocument`) and migrate it.
45
+ - Names: schema v3 takes the plain ones (`FoliDocument`, `parseDocument`, `parseContent`, `schema`, `SCHEMA_VERSION` 3). `createDocument(content?, section?)` makes a v3 document: its content is v3 and its second argument a section in twips (0.2.0's took v2 content and settings in millimetres; both still type-check, so a 0.2.0 call such as `createDocument(htmlToDoc(html))` fails in `createEditor` or gives a wrong page size). v2's are `FoliDocumentV2` and `parseContentV2`, and `htmlToDoc` still returns v2 content; v2's `schema`, `parseDocument` and `SCHEMA_VERSION` are no longer exported (`parseDocument` reads v1 and v2 documents and migrates them). `MARK_TYPES`, `HEADING_LEVELS` and the JSON types such as `DocJSON` still describe v2.
46
+ - Marks follow Word: text color is the `color` mark (`value`), and `highlight` takes a Word color name (the palette is Word's); there is no `textColor` mark. Use `setTextColor`, `setHighlight` and `colorAt(state, "textColor" | "highlight")` rather than `toggleMark` or `isMarkActive` with these marks.
47
+ - Links: `parseDocument` keeps any link target a file has (a `.docx` may hold `file:` links, say), where 0.2.0 rejected unsafe ones. Foli's view only makes a link of a safe target (`isSafeHref`); check it too wherever you turn a document's links into HTML yourself. Commands still refuse an unsafe href.
48
+ - Keyboard: Tab types a tab outside lists, as in Word (in 0.2.0 it moved the focus); Escape, then Tab, moves the focus out of the editor.
49
+ - Lists: `toggleList(kind)` and `wrapInList(kind)` take no attributes; `splitListItem`, `sinkListItem`, `liftListItem` and `liftListItemAtStart` are commands, not factories.
50
+ - On a state without a v3 envelope, `setBlockType` and the list and format commands do not apply.
51
+ - Removed: `insertHorizontalRule` (and `commands.insertHorizontalRule`), `listTypeAt`, the ¶, H1–H3 and rule toolbar buttons (the style box replaces them), and the CSS variables `--foli-font-family`, `--foli-font-size`, `--foli-line-height`, `--foli-link-color`, `--foli-marker-color`, `--foli-rule-color` and `--foli-rule-thickness` (the document's styles set them now).
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [8da5b98]
56
+ - @folijs/core@0.3.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Josep Audenis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,152 @@
1
- # Temporary Holding Version
1
+ # @folijs/docx
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
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`.
7
+
8
+ > Early release: the API may change in any 0.x minor version (changes in `CHANGELOG.md`).
9
+
10
+ ```ts
11
+ import { importDocx } from "@folijs/docx";
12
+
13
+ const {
14
+ document,
15
+ package: pkg,
16
+ report,
17
+ } = await importDocx(new Uint8Array(await file.arrayBuffer()));
18
+ document.content; // schema v3: paragraphs with Word's properties, runs as text with marks
19
+ document.styles; // with basedOn, run and paragraph properties
20
+ report.opaque; // { "w:tbl": 1, "w:drawing": 1 }: kept verbatim, not editable yet
21
+ ```
22
+
23
+ **Import** (`importDocx`, `importPackage`) reads the main document, styles (with the document
24
+ defaults), numbering, the theme's fonts and colors, comments (with replies and resolved state
25
+ from `commentsExtended`) and sections:
26
+
27
+ - **Paragraphs** with their properties (style, justification, indentation, spacing, keep rules,
28
+ outline level, numbering, tab stops, borders, shading, the paragraph mark's formatting and
29
+ tracked insertion or deletion, formatting changes, section breaks) and their own attributes
30
+ (`w14:paraId`…). **Runs** become text, tabs and breaks with their properties as marks; tracked
31
+ insertions, deletions and moves, hyperlinks (target from the relationship, or a bookmark),
32
+ bookmarks, comment ranges and references are modeled.
33
+ - **Lossless:** every properties element is kept verbatim (`ext` on paragraphs, sections,
34
+ styles, numbering levels and definitions, the document defaults; `runExt` on runs; a comment's
35
+ start tag), and unknown attributes of modeled elements go to attribute bags (paragraphs,
36
+ 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,
38
+ footnote references, equations…) becomes an opaque node holding its source, and so does an
39
+ element the model rejects as a whole (a tracked change with an id past Word's range, a link in
40
+ a link, a run with an unknown attribute): never stripped to plain text. Export (8.5) writes all
41
+ of it back; keep `package` with the document, the parts Foli does not edit come from it. The
42
+ tests check every attribute of the corpus's document and comments parts is kept.
43
+ - **What Word opens, imports:** each value is checked on its own; one the model cannot hold (out
44
+ of range, a unit such as `1.5cm`, a date without a time) is left out of the model, kept in the
45
+ verbatim element and listed in `report.unmodeled`. A style cycle is broken where it closes, a
46
+ reply that would close a cycle of replies is not kept. Not imported, because Word recomputes
47
+ them or they show nothing: spelling marks (`w:proofErr`), rendered page breaks
48
+ (`w:lastRenderedPageBreak`), editing session ids on runs (`w:rsid*`) and runs with no content:
49
+ counted in `report.dropped`. Import time is linear in the file (crafted files included).
50
+ - **Failures** are `DocxError` (or `ZipError` from the package): a file that is not a
51
+ WordprocessingML document, Strict Open XML (refused until a real file needs it), or an element
52
+ past the model's absolute limits (over 16 MiB kept verbatim).
53
+ - **Not kept exactly**, to be equal under export's canonical comparison: run boundaries
54
+ (adjacent runs with the same properties become one text), `w:cr` (read as a line break),
55
+ `w:noBreakHyphen` and `w:softHyphen` (read as U+2011 and U+00AD), an explicit
56
+ `w:type="textWrapping"` on a break, XML comments, processing instructions and whitespace
57
+ between elements, and the empty paragraph given to an empty body or comment. Text is read as
58
+ Word reads it: without `xml:space="preserve"`, whitespace at the ends of a `w:t` is not text.
59
+
60
+ **Settings.** Of `settings.xml` only `w:trackRevisions` is read (`DocxImport.trackRevisions`)
61
+ and, when `exportDocx` is given `trackRevisions`, written: added in its place among the
62
+ settings, or removed; the rest of the part is kept byte for byte. A new package gets a settings
63
+ part only with tracking on.
64
+
65
+ **Export** (`exportDocx(document, package?, options?)`) writes the parts the editor owns
66
+ (`document.xml`, `styles.xml`, `numbering.xml`, `comments.xml`, `commentsExtended.xml`,
67
+ relationships for new hyperlink targets, and `settings.xml` when `trackRevisions` changes it)
68
+ and copies every other part of the original package byte for byte (its compressed entry
69
+ included). Within the parts it writes:
70
+
71
+ - An element read from the file comes back verbatim while its values are what import read from
72
+ it (a paragraph's `w:pPr`, a run's `w:rPr`, a section, a style, a numbering level or
73
+ definition, a comment's start tag). Changed, it is rewritten child by child: unchanged
74
+ properties keep their original element (unknown attributes included), changed ones are
75
+ written from the model, and children Foli does not model stay in the order Word requires.
76
+ Recorded formatting changes inside a style's, a level's, the defaults' or a paragraph mark's
77
+ properties are not modeled: they stay as written.
78
+ - Opaque content, unknown attributes in bags, latent styles, picture bullets and anything else
79
+ the parts hold outside the model come back as they were; styles, definitions and comments the
80
+ editor removed are left out; new ones are added where Word expects them; a part the document
81
+ now needs (numbering, comments, comment threads) is added with its content type and
82
+ relationship. Comments made in the editor that are in a thread get a `w14:paraId`, so their
83
+ replies and resolved state are written. Tracked changes and comments the editor records (0.4.0: insertions,
84
+ deletions, run and paragraph formatting changes, comments, replies, resolved threads) are
85
+ written as Word writes them; Word reads them back with their authors and text, and Foli reads
86
+ Word's own changes and replies (checked with Word on the corpus: `corpus/README.md`). A run's
87
+ recorded formatting (`w:rPrChange`) is imported in canonical form, as the editor records it.
88
+ - Runs are regrouped from the model: hyperlinks outermost, then insertions (or move
89
+ destinations), deletions (or move sources) with `w:delText`, then runs of equal properties.
90
+ Line ends and vertical tabs in text become breaks, a tab character `w:tab` (read back as a
91
+ `tab` node); a character XML cannot hold (other control characters, lone surrogates) is
92
+ refused with a `DocxError`, never written.
93
+ - Verbatim content (opaque nodes, `ext`, attribute bags) is checked against the part it goes
94
+ into: one element of the expected kind, prefixes the part declares, no attribute the writer
95
+ writes itself. What does not fit is a `DocxError`, never ill-formed XML.
96
+ - Without a package, a new one is made (from a migrated v2 document, say), declaring Word's
97
+ namespaces. A document that refers to parts of its original package (headers, footers,
98
+ pictures, content kept verbatim with relationship ids) needs that package: exporting it
99
+ without one is a `DocxError`.
100
+ - Not written: the theme (read-only in the model: the original part is kept; a new package has
101
+ none, so Word's default applies). Page margins Word requires but the document leaves out are
102
+ written with Word's defaults. A part read as UTF-16 is written as UTF-8, declared so.
103
+
104
+ Checked: the corpus exported without edits equals the original under the canonical comparison
105
+ (`src/testing/canonical.ts`), with every other part, and every unchanged element, byte for byte;
106
+ re-imported, it is the same document; random edits leave every other paragraph identical and
107
+ the edited one's unknown properties in place; Word opens the exports (unchanged, edited, and new
108
+ packages) and finds the reference numbers in the unchanged ones
109
+ (`scripts/corpus/rewrite-corpus.mjs`).
110
+
111
+ The package layer underneath:
112
+
113
+ ```ts
114
+ import { readPackage } from "@folijs/docx";
115
+
116
+ const pkg = await readPackage(new Uint8Array(await file.arrayBuffer()));
117
+ pkg.mainDocument; // "/word/document.xml"
118
+ pkg.relationships(pkg.mainDocument); // [{ id: "rId1", type: ".../styles", partName: "/word/styles.xml", ... }]
119
+ const doc = pkg.xml(pkg.mainDocument); // elements with their offsets in doc.source
120
+ const body = doc.root.children.find((n) => n.kind === "element" && n.local === "body");
121
+
122
+ // Unchanged parts are copied from the original file as stored: written back with no
123
+ // replacements, the package is the identical file.
124
+ const bytes = await pkg.write(new Map([["/word/document.xml", new TextEncoder().encode(edited)]]));
125
+ ```
126
+
127
+ - **Zip:** central directory reader and writer on the platform's `DecompressionStream` and
128
+ `CompressionStream` (`deflate-raw`). Entries keep their headers and compressed data; only
129
+ replaced parts are compressed again (keeping their name bytes). Data descriptors supported;
130
+ encrypted entries, ZIP64 and methods other than stored and deflate are refused. Untrusted
131
+ files are expected: every local header must match its directory record, entries may not
132
+ overlap, an end record counts only with its directory right before it, declared sizes must be
133
+ ones deflate can produce, and every entry's size and CRC-32 is checked while inflating, one
134
+ entry at a time. Limits on entry count and uncompressed size (`maxEntries`, default 10 000;
135
+ `maxSize`, default 512 MiB).
136
+ - **XML:** `parseXml` keeps the source string and every node's offsets (`start`, `end`, and for
137
+ elements `openEnd` and `closeStart`), so content the importer does not understand is written
138
+ back as the exact characters it was read from (attributes also give `valueStart` and
139
+ `valueEnd`). Namespaces resolved (`ns`, reserved prefixes enforced), references decoded, line
140
+ ends and attribute whitespace normalized as XML defines; characters XML forbids, `--` in
141
+ comments and `]]>` in text refused. No DTD: a document type declaration is refused (OOXML
142
+ forbids one), so no entity expansion. Nesting limited (`maxDepth`, default 1000) so code
143
+ walking the tree recursively is safe; linear time in the input.
144
+ - **Package:** part names compare case-insensitively and percent-decoded (never decoding a
145
+ `/`), content types by override then default extension, relationship targets resolved
146
+ against their source part (a target that is a full URI is not a part). The main part must be
147
+ WordprocessingML (document, template, or their macro-enabled kinds). Text parts decode as
148
+ UTF-8 or UTF-16 by byte order mark; invalid bytes throw. Each XML part is parsed once.
149
+
150
+ Errors: `ZipError` (the container), `XmlError` (with the `offset`), `DocxError` (the package,
151
+ naming the part; an XML error is its `cause`). `readPackage` takes the zip limits and
152
+ `maxDepth`.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Schema v3 content back to WordprocessingML: paragraphs, runs grouped by their properties,
3
+ * hyperlinks and tracked changes around them, markers between them, opaque content verbatim.
4
+ */
5
+ import type { NodeJSON } from "@folijs/core";
6
+ import { type Namespaces } from "./xmlout.js";
7
+ export interface WriteContext {
8
+ readonly namespaces: Namespaces;
9
+ /**
10
+ * The relationship id for an external hyperlink target: the link's own when the package
11
+ * still has it with that target, otherwise a new one.
12
+ */
13
+ readonly hyperlink: (href: string, id: string | undefined) => string;
14
+ }
15
+ export declare function blocksXml(blocks: readonly NodeJSON[], context: WriteContext): string;
16
+ export declare function paragraphXml(p: NodeJSON, context: WriteContext): string;
17
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/export/content.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAY,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,CAAC;CACtE;AAWD,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAOpF;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAIvE"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Schema v3 content back to WordprocessingML: paragraphs, runs grouped by their properties,
3
+ * hyperlinks and tracked changes around them, markers between them, opaque content verbatim.
4
+ */
5
+ import { paragraphPropertiesXml, runPropertiesXml, same } from "./properties.js";
6
+ import { bagXml, el, escapeText, fragment } from "./xmlout.js";
7
+ /** Opaque XML as kept, once checked to be one element that fits the part (DocxError otherwise). */
8
+ function verbatim(xml, context) {
9
+ const text = typeof xml === "string" ? xml : "";
10
+ fragment(text, context.namespaces);
11
+ return text;
12
+ }
13
+ export function blocksXml(blocks, context) {
14
+ let out = "";
15
+ for (const block of blocks) {
16
+ if (block.type === "paragraph")
17
+ out += paragraphXml(block, context);
18
+ else if (block.type === "opaqueBlock")
19
+ out += verbatim(block.attrs?.xml, context);
20
+ }
21
+ return out;
22
+ }
23
+ export function paragraphXml(p, context) {
24
+ const attrs = (p.attrs ?? {});
25
+ const own = bagXml(attrs.attributes, context.namespaces);
26
+ return `<w:p${own}>${paragraphPropertiesXml(attrs, context.namespaces)}${inlinesXml(p.content ?? [], context)}</w:p>`;
27
+ }
28
+ const markOf = (node, type) => node.marks?.find((m) => m.type === type);
29
+ /** Consecutive nodes with the same `key`, each run of them given to `write`. */
30
+ function grouped(nodes, key, write) {
31
+ let out = "";
32
+ for (let i = 0; i < nodes.length;) {
33
+ const k = key(nodes[i]);
34
+ let j = i + 1;
35
+ while (j < nodes.length && same(key(nodes[j]), k))
36
+ j++;
37
+ out += write(nodes.slice(i, j), k);
38
+ i = j;
39
+ }
40
+ return out;
41
+ }
42
+ /** Hyperlinks outermost, then insertions (or move destinations), then deletions (or move sources). */
43
+ function inlinesXml(nodes, context) {
44
+ return grouped(nodes, (n) => markOf(n, "link"), (group, link) => {
45
+ const inner = grouped(group, (n) => markOf(n, "insertion"), (g, ins) => wrapChange(ins, "ins", "moveTo", grouped(g, (n) => markOf(n, "deletion"), (g2, del) => wrapChange(del, "del", "moveFrom", runsXml(g2, !!del, context), context)), context));
46
+ return link ? hyperlinkXml(link, inner, context) : inner;
47
+ });
48
+ }
49
+ const CHANGE_ATTRIBUTES = ["w:id", "w:author", "w:date"];
50
+ function wrapChange(mark, local, moveLocal, inner, context) {
51
+ if (!mark)
52
+ return inner;
53
+ const a = (mark.attrs ?? {});
54
+ const name = a.move ? `w:${moveLocal}` : `w:${local}`;
55
+ const open = el(name, {
56
+ "w:id": String(a.id),
57
+ "w:author": String(a.author ?? ""),
58
+ "w:date": a.date,
59
+ }).slice(0, -2);
60
+ return `${open}${bagXml(a.attributes, context.namespaces, CHANGE_ATTRIBUTES)}>${inner}</${name}>`;
61
+ }
62
+ function hyperlinkXml(link, inner, context) {
63
+ const a = (link.attrs ?? {});
64
+ const attributes = { ...(a.attributes ?? {}) };
65
+ const original = attributes["r:id"];
66
+ delete attributes["r:id"];
67
+ // A target: its relationship. None (a relationship the package does not have, read as no
68
+ // target): the original reference as it was.
69
+ const id = typeof a.href === "string" ? context.hyperlink(a.href, original) : original;
70
+ const open = el("w:hyperlink", {
71
+ "r:id": id,
72
+ "w:anchor": a.anchor,
73
+ "w:tooltip": a.tooltip,
74
+ }).slice(0, -2);
75
+ return `${open}${bagXml(attributes, context.namespaces, ["r:id", "w:anchor", "w:tooltip"])}>${inner}</w:hyperlink>`;
76
+ }
77
+ /** Inline nodes that are a run's content (the rest stands between runs). */
78
+ function inRun(node) {
79
+ if (node.type === "opaqueInline")
80
+ return node.attrs?.run === true;
81
+ return ["text", "tab", "hardBreak", "pageBreak", "columnBreak", "commentReference"].includes(node.type);
82
+ }
83
+ const STRUCTURE = new Set(["link", "insertion", "deletion"]);
84
+ /** A run's own properties: its marks without the hyperlink and tracked changes around it. */
85
+ function runMarks(node) {
86
+ return (node.marks ?? []).filter((m) => !STRUCTURE.has(m.type));
87
+ }
88
+ function runsXml(nodes, deleted, context) {
89
+ return grouped(nodes, (n) => (inRun(n) ? runMarks(n) : n), (group) => {
90
+ const first = group[0];
91
+ if (!inRun(first))
92
+ return group.map((n) => markerXml(n, context)).join("");
93
+ const marks = runMarks(first);
94
+ const ext = marks.find((m) => m.type === "runExt")?.attrs?.xml;
95
+ const rPr = runPropertiesXml(marks.filter((m) => m.type !== "runExt"), ext, context.namespaces);
96
+ return `<w:r>${rPr}${group.map((n) => runContentXml(n, deleted, context)).join("")}</w:r>`;
97
+ });
98
+ }
99
+ function markerXml(node, context) {
100
+ const a = (node.attrs ?? {});
101
+ const tag = (name, attrs) => `${el(name, attrs).slice(0, -2)}${bagXml(a.attributes, context.namespaces, Object.keys(attrs))}/>`;
102
+ switch (node.type) {
103
+ case "bookmarkStart":
104
+ return tag("w:bookmarkStart", { "w:id": String(a.id), "w:name": String(a.name ?? "") });
105
+ case "bookmarkEnd":
106
+ return tag("w:bookmarkEnd", { "w:id": String(a.id) });
107
+ case "commentStart":
108
+ return tag("w:commentRangeStart", { "w:id": String(a.id) });
109
+ case "commentEnd":
110
+ return tag("w:commentRangeEnd", { "w:id": String(a.id) });
111
+ case "opaqueInline":
112
+ return verbatim(a.xml, context);
113
+ default:
114
+ return "";
115
+ }
116
+ }
117
+ /**
118
+ * Text as `w:t` (or `w:delText`), with tabs and Word's special hyphens as their elements, and
119
+ * line ends and vertical tabs (Office's line break in pasted text) as breaks.
120
+ */
121
+ function textXml(text, deleted) {
122
+ const name = deleted ? "w:delText" : "w:t";
123
+ let out = "";
124
+ // A vertical tab (U+000B) is a line break, as Office pastes it.
125
+ const lines = text.split(String.fromCharCode(11)).join("\n");
126
+ for (const piece of lines.split(/(\r\n|[\t‑­\n\r])/)) {
127
+ if (piece === "")
128
+ continue;
129
+ if (piece === "\t")
130
+ out += "<w:tab/>";
131
+ else if (piece === "‑")
132
+ out += "<w:noBreakHyphen/>";
133
+ else if (piece === "­")
134
+ out += "<w:softHyphen/>";
135
+ else if (piece === "\n" || piece === "\r" || piece === "\r\n")
136
+ out += "<w:br/>";
137
+ else {
138
+ const preserve = /^\s|\s$/.test(piece) ? ' xml:space="preserve"' : "";
139
+ out += `<${name}${preserve}>${escapeText(piece)}</${name}>`;
140
+ }
141
+ }
142
+ return out;
143
+ }
144
+ function runContentXml(node, deleted, context) {
145
+ const a = (node.attrs ?? {});
146
+ switch (node.type) {
147
+ case "text":
148
+ return textXml(node.text ?? "", deleted);
149
+ case "tab":
150
+ return "<w:tab/>";
151
+ case "hardBreak":
152
+ return el("w:br", { "w:clear": a.clear });
153
+ case "pageBreak":
154
+ return el("w:br", { "w:type": "page" });
155
+ case "columnBreak":
156
+ return el("w:br", { "w:type": "column" });
157
+ case "commentReference":
158
+ return `${el("w:commentReference", { "w:id": String(a.id) }).slice(0, -2)}${bagXml(a.attributes, context.namespaces, ["w:id"])}/>`;
159
+ case "opaqueInline":
160
+ return verbatim(a.xml, context);
161
+ default:
162
+ return "";
163
+ }
164
+ }
165
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.js","sourceRoot":"","sources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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;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Schema v3 to `.docx` (ADR-0005): the parts the editor owns are written from the document
3
+ * (`document.xml`, `styles.xml`, `numbering.xml`, `comments.xml`, `commentsExtended.xml` and
4
+ * the relationships new hyperlinks need); every other part is copied from the original package
5
+ * byte for byte. Without a package, a new one is made.
6
+ */
7
+ import { type FoliDocument } from "@folijs/core";
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
+ /**
17
+ * The document as a `.docx`. With `original` (the package it was imported from), the parts
18
+ * Foli does not edit come back byte for byte and unchanged elements verbatim.
19
+ */
20
+ export declare function exportDocx(document: FoliDocument, original?: DocxPackage, options?: ExportOptions): Promise<Uint8Array>;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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;AAoG1E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,WAAW,EACtB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,UAAU,CAAC,CAGrB"}