ooxml-pages 0.0.0-stage → 0.1.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 (192) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +116 -2
  3. package/dist/docx/document.d.ts +52 -0
  4. package/dist/docx/document.d.ts.map +1 -0
  5. package/dist/docx/document.js +163 -0
  6. package/dist/docx/document.js.map +1 -0
  7. package/dist/docx/drawing.d.ts +30 -0
  8. package/dist/docx/drawing.d.ts.map +1 -0
  9. package/dist/docx/drawing.js +308 -0
  10. package/dist/docx/drawing.js.map +1 -0
  11. package/dist/docx/effects.d.ts +14 -0
  12. package/dist/docx/effects.d.ts.map +1 -0
  13. package/dist/docx/effects.js +68 -0
  14. package/dist/docx/effects.js.map +1 -0
  15. package/dist/docx/flow.d.ts +421 -0
  16. package/dist/docx/flow.d.ts.map +1 -0
  17. package/dist/docx/flow.js +1426 -0
  18. package/dist/docx/flow.js.map +1 -0
  19. package/dist/docx/fonts.d.ts +9 -0
  20. package/dist/docx/fonts.d.ts.map +1 -0
  21. package/dist/docx/fonts.js +72 -0
  22. package/dist/docx/fonts.js.map +1 -0
  23. package/dist/docx/line.d.ts +143 -0
  24. package/dist/docx/line.d.ts.map +1 -0
  25. package/dist/docx/line.js +743 -0
  26. package/dist/docx/line.js.map +1 -0
  27. package/dist/docx/math.d.ts +12 -0
  28. package/dist/docx/math.d.ts.map +1 -0
  29. package/dist/docx/math.js +230 -0
  30. package/dist/docx/math.js.map +1 -0
  31. package/dist/docx/measure.d.ts +45 -0
  32. package/dist/docx/measure.d.ts.map +1 -0
  33. package/dist/docx/measure.js +208 -0
  34. package/dist/docx/measure.js.map +1 -0
  35. package/dist/docx/media.d.ts +12 -0
  36. package/dist/docx/media.d.ts.map +1 -0
  37. package/dist/docx/media.js +46 -0
  38. package/dist/docx/media.js.map +1 -0
  39. package/dist/docx/metafile.d.ts +3 -0
  40. package/dist/docx/metafile.d.ts.map +1 -0
  41. package/dist/docx/metafile.js +1191 -0
  42. package/dist/docx/metafile.js.map +1 -0
  43. package/dist/docx/model.d.ts +253 -0
  44. package/dist/docx/model.d.ts.map +1 -0
  45. package/dist/docx/model.js +2 -0
  46. package/dist/docx/model.js.map +1 -0
  47. package/dist/docx/numbering.d.ts +42 -0
  48. package/dist/docx/numbering.d.ts.map +1 -0
  49. package/dist/docx/numbering.js +272 -0
  50. package/dist/docx/numbering.js.map +1 -0
  51. package/dist/docx/parse.d.ts +60 -0
  52. package/dist/docx/parse.d.ts.map +1 -0
  53. package/dist/docx/parse.js +899 -0
  54. package/dist/docx/parse.js.map +1 -0
  55. package/dist/docx/props.d.ts +228 -0
  56. package/dist/docx/props.d.ts.map +1 -0
  57. package/dist/docx/props.js +565 -0
  58. package/dist/docx/props.js.map +1 -0
  59. package/dist/docx/render.d.ts +18 -0
  60. package/dist/docx/render.d.ts.map +1 -0
  61. package/dist/docx/render.js +512 -0
  62. package/dist/docx/render.js.map +1 -0
  63. package/dist/docx/styles.d.ts +47 -0
  64. package/dist/docx/styles.d.ts.map +1 -0
  65. package/dist/docx/styles.js +129 -0
  66. package/dist/docx/styles.js.map +1 -0
  67. package/dist/docx/symbols.d.ts +13 -0
  68. package/dist/docx/symbols.d.ts.map +1 -0
  69. package/dist/docx/symbols.js +85 -0
  70. package/dist/docx/symbols.js.map +1 -0
  71. package/dist/docx/table.d.ts +6 -0
  72. package/dist/docx/table.d.ts.map +1 -0
  73. package/dist/docx/table.js +593 -0
  74. package/dist/docx/table.js.map +1 -0
  75. package/dist/docx/vml-render.d.ts +7 -0
  76. package/dist/docx/vml-render.d.ts.map +1 -0
  77. package/dist/docx/vml-render.js +368 -0
  78. package/dist/docx/vml-render.js.map +1 -0
  79. package/dist/docx/vml.d.ts +13 -0
  80. package/dist/docx/vml.d.ts.map +1 -0
  81. package/dist/docx/vml.js +119 -0
  82. package/dist/docx/vml.js.map +1 -0
  83. package/dist/docx/xml.d.ts +31 -0
  84. package/dist/docx/xml.d.ts.map +1 -0
  85. package/dist/docx/xml.js +123 -0
  86. package/dist/docx/xml.js.map +1 -0
  87. package/dist/docx.css +341 -0
  88. package/dist/docx.d.ts +58 -0
  89. package/dist/docx.d.ts.map +1 -0
  90. package/dist/docx.js +167 -0
  91. package/dist/docx.js.map +1 -0
  92. package/dist/dom.d.ts +9 -0
  93. package/dist/dom.d.ts.map +1 -0
  94. package/dist/dom.js +32 -0
  95. package/dist/dom.js.map +1 -0
  96. package/dist/lazy.d.ts +23 -0
  97. package/dist/lazy.d.ts.map +1 -0
  98. package/dist/lazy.js +62 -0
  99. package/dist/lazy.js.map +1 -0
  100. package/dist/pptx/chart.d.ts +6 -0
  101. package/dist/pptx/chart.d.ts.map +1 -0
  102. package/dist/pptx/chart.js +869 -0
  103. package/dist/pptx/chart.js.map +1 -0
  104. package/dist/pptx/color.d.ts +50 -0
  105. package/dist/pptx/color.d.ts.map +1 -0
  106. package/dist/pptx/color.js +298 -0
  107. package/dist/pptx/color.js.map +1 -0
  108. package/dist/pptx/env.d.ts +63 -0
  109. package/dist/pptx/env.d.ts.map +1 -0
  110. package/dist/pptx/env.js +88 -0
  111. package/dist/pptx/env.js.map +1 -0
  112. package/dist/pptx/fill.d.ts +81 -0
  113. package/dist/pptx/fill.d.ts.map +1 -0
  114. package/dist/pptx/fill.js +451 -0
  115. package/dist/pptx/fill.js.map +1 -0
  116. package/dist/pptx/fonts.d.ts +14 -0
  117. package/dist/pptx/fonts.d.ts.map +1 -0
  118. package/dist/pptx/fonts.js +119 -0
  119. package/dist/pptx/fonts.js.map +1 -0
  120. package/dist/pptx/geometry.d.ts +52 -0
  121. package/dist/pptx/geometry.d.ts.map +1 -0
  122. package/dist/pptx/geometry.js +1032 -0
  123. package/dist/pptx/geometry.js.map +1 -0
  124. package/dist/pptx/package.d.ts +28 -0
  125. package/dist/pptx/package.d.ts.map +1 -0
  126. package/dist/pptx/package.js +151 -0
  127. package/dist/pptx/package.js.map +1 -0
  128. package/dist/pptx/shapes.d.ts +63 -0
  129. package/dist/pptx/shapes.d.ts.map +1 -0
  130. package/dist/pptx/shapes.js +460 -0
  131. package/dist/pptx/shapes.js.map +1 -0
  132. package/dist/pptx/slide.d.ts +25 -0
  133. package/dist/pptx/slide.d.ts.map +1 -0
  134. package/dist/pptx/slide.js +337 -0
  135. package/dist/pptx/slide.js.map +1 -0
  136. package/dist/pptx/table.d.ts +5 -0
  137. package/dist/pptx/table.d.ts.map +1 -0
  138. package/dist/pptx/table.js +211 -0
  139. package/dist/pptx/table.js.map +1 -0
  140. package/dist/pptx/text.d.ts +112 -0
  141. package/dist/pptx/text.d.ts.map +1 -0
  142. package/dist/pptx/text.js +607 -0
  143. package/dist/pptx/text.js.map +1 -0
  144. package/dist/pptx/xml.d.ts +23 -0
  145. package/dist/pptx/xml.d.ts.map +1 -0
  146. package/dist/pptx/xml.js +109 -0
  147. package/dist/pptx/xml.js.map +1 -0
  148. package/dist/pptx.css +184 -0
  149. package/dist/pptx.d.ts +47 -0
  150. package/dist/pptx.d.ts.map +1 -0
  151. package/dist/pptx.js +66 -0
  152. package/dist/pptx.js.map +1 -0
  153. package/package.json +64 -4
  154. package/src/docx/document.ts +204 -0
  155. package/src/docx/docx.css +156 -0
  156. package/src/docx/drawing.ts +319 -0
  157. package/src/docx/effects.ts +77 -0
  158. package/src/docx/flow.ts +1575 -0
  159. package/src/docx/fonts.ts +74 -0
  160. package/src/docx/line.ts +846 -0
  161. package/src/docx/math.ts +219 -0
  162. package/src/docx/measure.ts +238 -0
  163. package/src/docx/media.ts +46 -0
  164. package/src/docx/metafile.ts +1176 -0
  165. package/src/docx/model.ts +229 -0
  166. package/src/docx/numbering.ts +288 -0
  167. package/src/docx/parse.ts +901 -0
  168. package/src/docx/props.ts +755 -0
  169. package/src/docx/render.ts +490 -0
  170. package/src/docx/styles.ts +143 -0
  171. package/src/docx/symbols.ts +91 -0
  172. package/src/docx/table.ts +569 -0
  173. package/src/docx/vml-render.ts +351 -0
  174. package/src/docx/vml.ts +119 -0
  175. package/src/docx/xml.ts +119 -0
  176. package/src/docx.ts +213 -0
  177. package/src/dom.ts +37 -0
  178. package/src/lazy.ts +85 -0
  179. package/src/pptx/chart.ts +886 -0
  180. package/src/pptx/color.ts +333 -0
  181. package/src/pptx/env.ts +128 -0
  182. package/src/pptx/fill.ts +459 -0
  183. package/src/pptx/fonts.ts +123 -0
  184. package/src/pptx/geometry.ts +1066 -0
  185. package/src/pptx/package.ts +166 -0
  186. package/src/pptx/pptx.css +184 -0
  187. package/src/pptx/shapes.ts +481 -0
  188. package/src/pptx/slide.ts +355 -0
  189. package/src/pptx/table.ts +208 -0
  190. package/src/pptx/text.ts +651 -0
  191. package/src/pptx/xml.ts +104 -0
  192. package/src/pptx.ts +107 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kai Jungsthoefel
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,117 @@
1
- # Temporary Holding Version
1
+ # ooxml-pages
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
+ Render Word (`.docx`) and PowerPoint (`.pptx`) files in the browser as real pages and slides.
4
+
5
+ - **Laid out like Word:** line breaking, page breaks, columns, sections, headers and footers, footnotes and endnotes, tables that split across pages, floating pictures with every wrap type, keep-with-next, widow control.
6
+ - **View only, and small:** about 160 KB (min + gzip) for Word including the PowerPoint drawing code, about 100 KB for PowerPoint alone. No framework, one dependency ([zip.js](https://github.com/gildas-lormeau/zip.js)).
7
+ - **Fast:** a typical document lays out in a few hundred milliseconds; pages are drawn lazily while scrolling.
8
+ - **Private:** everything happens in the browser. Nothing is uploaded, and no script from the document is ever run.
9
+
10
+ [Live demo](https://kai-jungsthoefel.github.io/ooxml-pages/) · [Changelog](CHANGELOG.md)
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install ooxml-pages
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```ts
21
+ import { renderDocx } from 'ooxml-pages/docx';
22
+ import 'ooxml-pages/docx.css';
23
+
24
+ const view = await renderDocx(file, document.getElementById('pages')!, {
25
+ root: document.getElementById('scroller'), // the element that scrolls, for lazy rendering
26
+ onProgress: ({ phase, fraction }) => console.log(phase, fraction),
27
+ });
28
+ console.log(view.pages.length, 'pages');
29
+ // later
30
+ view.destroy();
31
+ ```
32
+
33
+ ```ts
34
+ import { renderPptx } from 'ooxml-pages/pptx';
35
+ import 'ooxml-pages/pptx.css';
36
+
37
+ const view = await renderPptx(file, container, {
38
+ // Optional: wrap each slide, e.g. with a caption.
39
+ frame: (slide, { index, hidden }) => {
40
+ const figure = document.createElement('figure');
41
+ const caption = document.createElement('figcaption');
42
+ caption.textContent = `Slide ${index + 1}${hidden ? ' (hidden)' : ''}`;
43
+ figure.append(slide, caption);
44
+ return figure;
45
+ },
46
+ });
47
+ ```
48
+
49
+ `file` is any `Blob` (a `File` from an `<input>`, a `fetch` response's `blob()` …). Pages and slides are laid out at 96 dpi in CSS pixels; scale them with CSS (`zoom` or `transform`) to fit your layout.
50
+
51
+ ### Options
52
+
53
+ | Option | Default | |
54
+ |---|---|---|
55
+ | `lazy` | `true` | Draw pages only when they come near the visible area. `false` draws all of them in order. |
56
+ | `root` | viewport | The scrolling element, used for lazy rendering (and for scrolling to bookmarks in Word documents). |
57
+ | `preloadMargin` | `'1600px 0px'` (Word), `'1200px 0px'` (PowerPoint) | How far outside the visible area pages are prepared. |
58
+ | `errorText` | `'This page could not be displayed.'` | Shown in place of a page that fails to render. |
59
+ | `onProgress` | | Word: `{ phase: 'read' \| 'parse' \| 'layout' \| 'relayout', fraction? }`. PowerPoint: share of slides read (0–1). |
60
+ | `frame` | | PowerPoint only: wraps each slide element before it is added. |
61
+
62
+ Both views have `renderNow(index)`, `settled()` (resolves once everything started so far is drawn) and `destroy()`. A Word view also has `scrollToBookmark(name)`; links inside the document (tables of contents, cross references) already use it.
63
+
64
+ ### Lower level
65
+
66
+ To draw pages yourself (thumbnails, printing, your own virtual scrolling), load the document without any DOM output and render single pages into elements you own:
67
+
68
+ ```ts
69
+ import { layoutDocx } from 'ooxml-pages/docx';
70
+ import { loadPresentation } from 'ooxml-pages/pptx';
71
+
72
+ const doc = await layoutDocx(file); // { pages: [{ width, height, number }], bookmarks, renderPage, close }
73
+ await doc.renderPage(0, element);
74
+
75
+ const deck = await loadPresentation(file); // { width, height, slides: [{ hidden }], renderSlide, close }
76
+ await deck.renderSlide(0, element);
77
+ ```
78
+
79
+ Call `close()` when done: it releases the file, the picture URLs and embedded fonts.
80
+
81
+ ## What is supported
82
+
83
+ **Word:** styles and direct formatting, numbering and lists, tab stops with leaders, borders and shading, columns, sections with different page sizes and orientations, headers and footers (first page, even and odd), footnotes and endnotes, fields (page numbers, NUMPAGES, PAGEREF, table of contents), equations (Office Math), tables (merged cells, header rows that repeat, rows that split, cell spacing, vertical text), floating pictures and shapes with every wrap type and anchor, rotation, flips and cropping, text boxes, groups, charts and SmartArt, VML shapes, watermarks and horizontal rules, legacy form fields and content controls with check boxes, symbol fonts, drop caps and text frames, embedded fonts, page color and background pictures, page borders, Word 2010 text effects (gradient fill, outline, shadow), EMF and WMF pictures.
84
+
85
+ **PowerPoint:** slide → layout → master inheritance, themes and color maps, preset and custom shapes, fills (solid, gradient, picture, pattern), lines and arrowheads, text with bullets, autofit and columns, tables with table styles, charts (bar, line, pie, area, scatter …), SmartArt (from the drawing PowerPoint saved), groups, hidden slides.
86
+
87
+ ## Limits
88
+
89
+ - **View only.** There is no editing and no saving. If you need an editor, look at [folio](https://github.com/stella/folio) or [ooxml](https://github.com/ChristopherVR/ooxml).
90
+ - **Browser only.** Layout measures text with the browser's canvas, so it needs a DOM (no Node.js or server-side rendering).
91
+ - **Fonts decide the line breaks.** Text is measured in the fonts the browser has. Where a document's fonts (Calibri, Cambria …) are not installed, the browser falls back to metric-compatible ones if present (Carlito, Caladea, Liberation) and otherwise to similar fonts, and lines may break differently from Word. Fonts embedded in a document are used.
92
+ - **Approximations.** Art page borders (apples, stars …) are pictures built into Word; they are drawn as a dotted band of the same width. Text that Word sets slightly tighter can wrap a word earlier, so long documents may end up with a page more or less.
93
+ - **Not supported:** the binary formats `.doc` and `.ppt`, password-protected files, tracked changes (the document is shown as it was saved), comments, animations and transitions, embedded videos.
94
+
95
+ ## Security
96
+
97
+ Documents are untrusted input. The renderers never run scripts from a document, never load anything from the network, and show SVG only through `<img>` (where browsers run no scripts). Sizes, nesting and counts are capped so that a hostile file cannot exhaust memory. If you find a way around this, please report it privately (see [SECURITY.md](SECURITY.md)).
98
+
99
+ ## Development
100
+
101
+ ```sh
102
+ npm install
103
+ npm run dev # demo page with the test files on http://localhost:5180
104
+ npm test # renders every test file in a browser and checks the page counts against Word
105
+ npm run build # dist/: ES modules, type declarations, stylesheets
106
+ npm run samples # regenerates the test files in test/fixtures/
107
+ ```
108
+
109
+ Tests use Playwright. Run `npx playwright install chromium` once, or use an installed browser with `PW_CHANNEL=msedge npm test` (or `chrome`).
110
+
111
+ The files in `test/fixtures/` are written from scratch by the scripts in `scripts/`, so they can be shared freely. The expected page counts come from Word 365 and PowerPoint 365.
112
+
113
+ To release, set the version in `package.json` and `CHANGELOG.md`, commit, and push a tag `v<version>` on that commit. The release workflow publishes it to npm.
114
+
115
+ ## License
116
+
117
+ [MIT](LICENSE)
@@ -0,0 +1,52 @@
1
+ import { type Theme } from '../pptx/color.js';
2
+ import type { MediaSource, Source } from '../pptx/env.js';
3
+ import { Package } from '../pptx/package.js';
4
+ import { Numbering } from './numbering.js';
5
+ import { Styles } from './styles.js';
6
+ export interface NoteSettings {
7
+ numFmt: string;
8
+ numStart: number;
9
+ numRestart: string;
10
+ pos: string;
11
+ }
12
+ export interface Settings {
13
+ /** Default tab stop distance in twips. */
14
+ defaultTabStop: number;
15
+ evenAndOddHeaders: boolean;
16
+ /** Word version the layout follows: 11 (2003), 12 (2007), 14 (2010), 15 (2013 and later). */
17
+ compatMode: number;
18
+ footnotes: NoteSettings;
19
+ endnotes: NoteSettings;
20
+ /** w:clrSchemeMapping: bg1 → light1 … */
21
+ colorMap: Map<string, string>;
22
+ displayBackground: boolean;
23
+ /** Compatibility switches that change layout, e.g. doNotExpandShiftReturn. */
24
+ compat: Set<string>;
25
+ mirrorMargins: boolean;
26
+ gutterAtTop: boolean;
27
+ autoHyphenation: boolean;
28
+ decimalSymbol: string;
29
+ }
30
+ export interface DocxDocument {
31
+ pkg: Package;
32
+ media: MediaSource;
33
+ main: string;
34
+ source: Source;
35
+ body: Element;
36
+ background: Element | null;
37
+ styles: Styles;
38
+ numbering: Numbering;
39
+ theme: Theme;
40
+ settings: Settings;
41
+ footnotes: Map<string, Element>;
42
+ endnotes: Map<string, Element>;
43
+ /** Separator notes (type separator / continuationSeparator) of the footnotes part. */
44
+ footnoteSeparator: Element | null;
45
+ endnoteSeparator: Element | null;
46
+ footnoteSource: Source | null;
47
+ endnoteSource: Source | null;
48
+ /** Font table part, which lists embedded fonts. */
49
+ fontTable: string | null;
50
+ }
51
+ export declare function loadDocument(file: Blob): Promise<DocxDocument>;
52
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/docx/document.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,KAAK,EAA6B,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,0CAA0C;IAC1C,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,6FAA6F;IAC7F,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,YAAY,CAAC;IACxB,QAAQ,EAAE,YAAY,CAAC;IACvB,yCAAyC;IACzC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,8EAA8E;IAC9E,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,sFAAsF;IACtF,iBAAiB,EAAE,OAAO,GAAG,IAAI,CAAC;IAClC,gBAAgB,EAAE,OAAO,GAAG,IAAI,CAAC;IACjC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,mDAAmD;IACnD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AA0FD,wBAAsB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAwDpE"}
@@ -0,0 +1,163 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // The DOCX package: main document part, styles, numbering, theme, settings, notes, and the relationships the
3
+ // content needs. Headers and footers are read when a section refers to them.
4
+ import { parseColorMap, parseTheme } from '../pptx/color.js';
5
+ import { Package } from '../pptx/package.js';
6
+ import { DocxMedia } from './media.js';
7
+ import { Numbering } from './numbering.js';
8
+ import { Styles } from './styles.js';
9
+ import { clampNum, kid, kids, wa, wi, wv } from './xml.js';
10
+ /** Word's mapping names (light1, dark1 …) to DrawingML scheme slots. */
11
+ const MAP_SLOT = {
12
+ light1: 'lt1', dark1: 'dk1', light2: 'lt2', dark2: 'dk2', accent1: 'accent1', accent2: 'accent2', accent3: 'accent3',
13
+ accent4: 'accent4', accent5: 'accent5', accent6: 'accent6', hyperlink: 'hlink', followedHyperlink: 'folHlink',
14
+ };
15
+ /** Colors of the default Office theme, which Word uses when a document has no theme part. */
16
+ const DEFAULT_SCHEME = [
17
+ ['dk1', '000000'], ['lt1', 'FFFFFF'], ['dk2', '44546A'], ['lt2', 'E7E6E6'], ['accent1', '4472C4'], ['accent2', 'ED7D31'],
18
+ ['accent3', 'A5A5A5'], ['accent4', 'FFC000'], ['accent5', '5B9BD5'], ['accent6', '70AD47'], ['hlink', '0563C1'], ['folHlink', '954F72'],
19
+ ];
20
+ function defaultTheme() {
21
+ const slots = DEFAULT_SCHEME.map(([slot, rgb]) => `<a:${slot}><a:srgbClr val="${rgb}"/></a:${slot}>`).join('');
22
+ const xml = `<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:themeElements><a:clrScheme name="Office">${slots}</a:clrScheme></a:themeElements></a:theme>`;
23
+ return new DOMParser().parseFromString(xml, 'application/xml');
24
+ }
25
+ function noteSettings(el, fallbackFmt, base) {
26
+ return {
27
+ numFmt: wv(kid(el, 'numFmt')) ?? base?.numFmt ?? fallbackFmt,
28
+ numStart: clampNum(wi(kid(el, 'numStart')) ?? base?.numStart ?? 1, 0, 32767),
29
+ numRestart: wv(kid(el, 'numRestart')) ?? base?.numRestart ?? 'continuous',
30
+ pos: wv(kid(el, 'pos')) ?? base?.pos ?? 'pageBottom',
31
+ };
32
+ }
33
+ function parseSettings(doc) {
34
+ const root = doc?.documentElement ?? null;
35
+ const compat = kid(root, 'compat');
36
+ let compatMode = 12;
37
+ const flags = new Set();
38
+ for (const c of kids(compat)) {
39
+ if (c.localName === 'compatSetting') {
40
+ if (wa(c, 'name') === 'compatibilityMode')
41
+ compatMode = Number(wa(c, 'val')) || compatMode;
42
+ else if (wa(c, 'val') === '1' || wa(c, 'val') === 'true')
43
+ flags.add(wa(c, 'name') ?? '');
44
+ }
45
+ else if (wv(c) !== '0' && wv(c) !== 'false') {
46
+ flags.add(c.localName);
47
+ }
48
+ }
49
+ const mapEl = kid(root, 'clrSchemeMapping');
50
+ const colorMap = parseColorMap(null);
51
+ if (mapEl) {
52
+ for (const a of mapEl.attributes) {
53
+ const slot = MAP_SLOT[a.value];
54
+ // Word's attribute names: bg1, t1, bg2, t2, accent1 …
55
+ const key = a.localName === 't1' ? 'tx1' : a.localName === 't2' ? 'tx2' : a.localName;
56
+ if (slot)
57
+ colorMap.set(key, slot);
58
+ }
59
+ }
60
+ const on = (name) => {
61
+ const el = kid(root, name);
62
+ return !!el && wv(el) !== '0' && wv(el) !== 'false' && wv(el) !== 'off';
63
+ };
64
+ return {
65
+ defaultTabStop: clampNum(wi(kid(root, 'defaultTabStop')) ?? 720, 36, 31680),
66
+ evenAndOddHeaders: on('evenAndOddHeaders'),
67
+ compatMode,
68
+ footnotes: noteSettings(kid(root, 'footnotePr'), 'decimal'),
69
+ endnotes: noteSettings(kid(root, 'endnotePr'), 'lowerRoman'),
70
+ colorMap,
71
+ displayBackground: on('displayBackgroundShape'),
72
+ compat: flags,
73
+ mirrorMargins: on('mirrorMargins'),
74
+ gutterAtTop: on('gutterAtTop'),
75
+ autoHyphenation: on('autoHyphenation'),
76
+ decimalSymbol: (wv(kid(root, 'decimalSymbol')) ?? '.').slice(0, 1) || '.',
77
+ };
78
+ }
79
+ async function notes(pkg, rels, type, item) {
80
+ const out = new Map();
81
+ let separator = null;
82
+ for (const rel of rels.values()) {
83
+ if (rel.type !== type || rel.external)
84
+ continue;
85
+ const doc = await pkg.xml(rel.target);
86
+ for (const el of kids(doc?.documentElement)) {
87
+ if (el.localName !== item)
88
+ continue;
89
+ const id = wa(el, 'id');
90
+ const kind = wa(el, 'type');
91
+ if (kind === 'separator')
92
+ separator = el;
93
+ else if (id !== null && !kind)
94
+ out.set(id, el);
95
+ }
96
+ return { notes: out, separator, source: { part: rel.target, rels: await pkg.rels(rel.target) } };
97
+ }
98
+ return { notes: out, separator, source: null };
99
+ }
100
+ export async function loadDocument(file) {
101
+ const head = new Uint8Array(await file.slice(0, 4).arrayBuffer());
102
+ if (head[0] === 0xd0 && head[1] === 0xcf && head[2] === 0x11 && head[3] === 0xe0) {
103
+ throw new Error('This document is password-protected (encrypted) or in the old Word 97–2003 format and cannot be displayed.');
104
+ }
105
+ let pkg;
106
+ try {
107
+ pkg = await Package.open(file);
108
+ }
109
+ catch {
110
+ throw new Error('The file is not a valid Word document.');
111
+ }
112
+ try {
113
+ const main = (await pkg.related('', 'officeDocument')) ?? 'word/document.xml';
114
+ const doc = await pkg.xml(main);
115
+ const root = doc?.documentElement;
116
+ const body = kid(root, 'body');
117
+ if (!root || root.localName !== 'document' || !body)
118
+ throw new Error('The file is not a Word document.');
119
+ const rels = await pkg.rels(main);
120
+ const partOf = (type) => {
121
+ for (const rel of rels.values())
122
+ if (rel.type === type && !rel.external)
123
+ return rel.target;
124
+ return null;
125
+ };
126
+ const stylesPart = partOf('styles');
127
+ const styles = new Styles(stylesPart ? await pkg.xml(stylesPart) : null);
128
+ const numberingPart = partOf('numbering');
129
+ const numbering = new Numbering(numberingPart ? await pkg.xml(numberingPart) : null, styles);
130
+ const themePart = partOf('theme');
131
+ let theme = parseTheme(themePart ? await pkg.xml(themePart) : null);
132
+ if (!theme.colors.size)
133
+ theme = { ...theme, colors: parseTheme(defaultTheme()).colors };
134
+ const settingsPart = partOf('settings');
135
+ const settings = parseSettings(settingsPart ? await pkg.xml(settingsPart) : null);
136
+ const foot = await notes(pkg, rels, 'footnotes', 'footnote');
137
+ const end = await notes(pkg, rels, 'endnotes', 'endnote');
138
+ return {
139
+ pkg,
140
+ media: new DocxMedia(pkg),
141
+ main,
142
+ source: { part: main, rels },
143
+ body,
144
+ background: kid(root, 'background'),
145
+ styles,
146
+ numbering,
147
+ theme,
148
+ settings,
149
+ footnotes: foot.notes,
150
+ endnotes: end.notes,
151
+ footnoteSeparator: foot.separator,
152
+ endnoteSeparator: end.separator,
153
+ footnoteSource: foot.source,
154
+ endnoteSource: end.source,
155
+ fontTable: partOf('fontTable'),
156
+ };
157
+ }
158
+ catch (error) {
159
+ pkg.close();
160
+ throw error;
161
+ }
162
+ }
163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AG,CAAC;YACzB,IAAI;YACJ,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;YAC5B,IAAI;YACJ,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,YAAY,CAAC;YACnC,MAAM;YACN,SAAS;YACT,KAAK;YACL,QAAQ;YACR,SAAS,EAAE,IAAI,CAAC,KAAK;YACrB,QAAQ,EAAE,GAAG,CAAC,KAAK;YACnB,iBAAiB,EAAE,IAAI,CAAC,SAAS;YACjC,gBAAgB,EAAE,GAAG,CAAC,SAAS;YAC/B,cAAc,EAAE,IAAI,CAAC,MAAM;YAC3B,aAAa,EAAE,GAAG,CAAC,MAAM;YACzB,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC;SAC/B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type Env, type Source } from '../pptx/env.js';
2
+ import type { DocxDocument } from './document.js';
3
+ import { type FlowContext, type StoryLayout } from './flow.js';
4
+ import type { DrawingObj } from './model.js';
5
+ import { parseBlocks } from './parse.js';
6
+ import { wa } from './xml.js';
7
+ export interface DrawContext {
8
+ doc: DocxDocument;
9
+ flow: FlowContext;
10
+ env: Env;
11
+ /** Draws laid out story content (text box contents) into a container. */
12
+ drawStory(layout: StoryLayout, container: HTMLElement, source: Source): void;
13
+ /** Parse contexts for text box contents, by story part. */
14
+ parsed: WeakMap<Element, ReturnType<typeof parseBlocks>>;
15
+ }
16
+ /** Word text box content (wps:txbx or a linked box) inside a shape's text rectangle. */
17
+ declare function textBox(sp: Element, rect: {
18
+ x: number;
19
+ y: number;
20
+ w: number;
21
+ h: number;
22
+ rot: number;
23
+ }, dc: DrawContext, source: Source): HTMLElement | null;
24
+ /**
25
+ * Element for a drawing object of the given size; positioned by the caller. Resolves when pictures are in
26
+ * (through env.pending).
27
+ */
28
+ export declare function renderObject(obj: DrawingObj, dc: DrawContext, env: Env): Promise<HTMLElement | null>;
29
+ export { textBox, wa };
30
+ //# sourceMappingURL=drawing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drawing.d.ts","sourceRoot":"","sources":["../../src/docx/drawing.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,MAAM,EAAW,MAAM,gBAAgB,CAAC;AAIhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAe,MAAM,WAAW,CAAC;AAE5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAoC,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3E,OAAO,EAAuB,EAAE,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,YAAY,CAAC;IAClB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,GAAG,CAAC;IACT,yEAAyE;IACzE,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7E,2DAA2D;IAC3D,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC;CAC1D;AAwID,wFAAwF;AACxF,iBAAS,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CA4CpJ;AAkFD;;;G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