@file-viewer/docx 0.3.33 → 0.3.35

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 (76) hide show
  1. package/README.md +49 -9
  2. package/dist/THIRD_PARTY_NOTICES.txt +1038 -0
  3. package/dist/anchor-layout.d.ts +20 -0
  4. package/dist/comment-layer.d.ts +40 -0
  5. package/dist/comments/comments-extended-part.d.ts +13 -0
  6. package/dist/comments/comments-part.d.ts +11 -0
  7. package/dist/comments/elements.d.ts +23 -0
  8. package/dist/common/content-types.d.ts +7 -0
  9. package/dist/common/open-xml-package.d.ts +25 -0
  10. package/dist/common/part.d.ts +12 -0
  11. package/dist/common/relationship.d.ts +46 -0
  12. package/dist/dark-mode-color.d.ts +29 -0
  13. package/dist/display-address.d.ts +5 -0
  14. package/dist/document/bookmarks.d.ts +13 -0
  15. package/dist/document/border.d.ts +18 -0
  16. package/dist/document/common.d.ts +38 -0
  17. package/dist/document/document-part.d.ts +10 -0
  18. package/dist/document/document.d.ts +9 -0
  19. package/dist/document/dom.d.ts +200 -0
  20. package/dist/document/fields.d.ts +14 -0
  21. package/dist/document/line-spacing.d.ts +9 -0
  22. package/dist/document/page-breaks.d.ts +8 -0
  23. package/dist/document/paragraph.d.ts +54 -0
  24. package/dist/document/run.d.ts +12 -0
  25. package/dist/document/section.d.ts +82 -0
  26. package/dist/document/style.d.ts +21 -0
  27. package/dist/document/symbol-encoding.d.ts +28 -0
  28. package/dist/document-parser.d.ts +156 -0
  29. package/dist/document-props/core-props-part.d.ts +6 -0
  30. package/dist/document-props/core-props.d.ts +12 -0
  31. package/dist/document-props/custom-props-part.d.ts +6 -0
  32. package/dist/document-props/custom-props.d.ts +8 -0
  33. package/dist/document-props/extended-props-part.d.ts +6 -0
  34. package/dist/document-props/extended-props.d.ts +14 -0
  35. package/dist/docx-preview-esm.d.mts +3 -0
  36. package/dist/docx-preview-worker.d.ts +1 -0
  37. package/dist/docx-preview.d.ts +84 -13
  38. package/dist/docx-preview.js +15397 -4
  39. package/dist/docx-preview.min.js +25 -4
  40. package/dist/docx-preview.min.mjs +25 -4
  41. package/dist/docx-preview.mjs +15396 -4
  42. package/dist/docx-preview.worker.js +15473 -4
  43. package/dist/font-table/font-table.d.ts +6 -0
  44. package/dist/font-table/fonts.d.ts +15 -0
  45. package/dist/header-footer/elements.d.ts +7 -0
  46. package/dist/header-footer/parts.d.ts +18 -0
  47. package/dist/html-renderer.d.ts +567 -0
  48. package/dist/html.d.ts +16 -0
  49. package/dist/input-validation.d.ts +2 -0
  50. package/dist/javascript.d.ts +8 -0
  51. package/dist/jszip.min.js +2 -2
  52. package/dist/layout-coordinates.d.ts +23 -0
  53. package/dist/layout-readiness.d.ts +17 -0
  54. package/dist/length.d.ts +11 -0
  55. package/dist/license-gate.d.ts +4 -0
  56. package/dist/metafile/emf-to-svg.d.ts +7 -0
  57. package/dist/metafile/wmf-to-svg.d.ts +7 -0
  58. package/dist/notes/elements.d.ts +12 -0
  59. package/dist/notes/parts.d.ts +17 -0
  60. package/dist/notes/properties.d.ts +33 -0
  61. package/dist/numbering/numbering-part.d.ts +14 -0
  62. package/dist/numbering/numbering.d.ts +49 -0
  63. package/dist/parser/xml-parser.d.ts +27 -0
  64. package/dist/review.d.ts +49 -0
  65. package/dist/security/links.d.ts +6 -0
  66. package/dist/security/trusted-types.d.ts +10 -0
  67. package/dist/settings/settings-part.d.ts +8 -0
  68. package/dist/settings/settings.d.ts +25 -0
  69. package/dist/styles/styles-part.d.ts +10 -0
  70. package/dist/table-diagonals.d.ts +2 -0
  71. package/dist/theme/theme-part.d.ts +8 -0
  72. package/dist/theme/theme.d.ts +25 -0
  73. package/dist/utils.d.ts +17 -0
  74. package/dist/vml/vml.d.ts +19 -0
  75. package/dist/word-document.d.ts +89 -0
  76. package/package.json +33 -26
package/README.md CHANGED
@@ -30,7 +30,6 @@ dist/jszip.min.js
30
30
  const options = {
31
31
  useWorker: true,
32
32
  workerUrl: "dist/docx-preview.worker.js",
33
- workerJsZipUrl: "dist/jszip.min.js",
34
33
  awaitLayout: true,
35
34
  strictWordCompatibility: true,
36
35
  ignoreLastRenderedPageBreak: false,
@@ -54,8 +53,7 @@ import { renderAsync } from "@file-viewer/docx";
54
53
 
55
54
  await renderAsync(fileOrArrayBuffer, container, null, {
56
55
  useWorker: true,
57
- workerUrl: new URL("@file-viewer/docx/dist/docx-preview.worker.js", import.meta.url).toString(),
58
- workerJsZipUrl: new URL("@file-viewer/docx/dist/jszip.min.js", import.meta.url).toString(),
56
+ workerUrl: new URL("@file-viewer/docx/worker", import.meta.url).toString(),
59
57
  awaitLayout: true
60
58
  });
61
59
  ```
@@ -119,6 +117,19 @@ await renderDocument(document, container, null, { reviewMode: "original" });
119
117
  Set `renderComments: false` explicitly when tracked changes are required without
120
118
  the comments surface.
121
119
 
120
+ The default `reviewPresentation: "balloon"` keeps deleted text as anchors for a
121
+ margin review rail. Hosts without a rail can pass `reviewPresentation: "inline"`
122
+ to show deletions with strikethrough using the engine's own styles.
123
+
124
+ Measured tabs, DrawingML/VML anchor origins, VML text viewports, merged-cell
125
+ edges and page backgrounds are handled by the engine. Drawing text boxes use
126
+ independent HTML stories so serialization preserves their paragraph boundaries;
127
+ exporters do not need to replace or repair generated elements. `renderAsync()`
128
+ updates coordinates after fonts, images, pagination and container resizing.
129
+ Call `disposeRenderedDocument(container)` when unmounting to release document
130
+ observers and bookmark handlers. Rendering again in the same container releases
131
+ the previous handlers automatically.
132
+
122
133
  The mode values follow Word's **Display for Review** semantics: `simple` keeps
123
134
  the current text with compact change indicators, `all` exposes every supported
124
135
  revision and comment anchor, `final` is the current document with markup hidden,
@@ -209,7 +220,6 @@ collectLayoutSnapshot(
209
220
  // Worker and responsiveness
210
221
  useWorker: true,
211
222
  workerUrl: "dist/docx-preview.worker.js",
212
- workerJsZipUrl: "dist/jszip.min.js",
213
223
  workerFallback: true,
214
224
  workerTimeout: 120000,
215
225
  renderPageBatchSize: 2,
@@ -242,12 +252,20 @@ collectLayoutSnapshot(
242
252
  The production path is intentionally split into stages:
243
253
 
244
254
  1. The main thread starts a Worker using `workerUrl`.
245
- 2. The Worker loads JSZip using `workerJsZipUrl`, unzips the package, parses XML parts, resolves relationships and serializes a compact document snapshot.
255
+ 2. The self-contained Worker uses its bundled JSZip and XML parser imports to unzip the package, parse XML parts, resolve relationships and serialize a compact document snapshot. The default needs no external script, global XML shim or separately appended bootstrap.
246
256
  3. The main thread restores the snapshot into `WordDocument` and renders HTML pages in batches, yielding to `requestIdleCallback`, `requestAnimationFrame` or `setTimeout` between page batches.
247
257
  4. `awaitRenderedLayout` waits for images and fonts, runs dynamic overflow pagination and returns a `LayoutSnapshot`.
248
258
  5. `collectLayoutSnapshot` can be used in CI or telemetry to detect overflow pages, unresolved media, page count, aggregate text length, fields and floating objects.
249
259
 
250
- Batch rendering and browser yields avoid the former demo-page freeze caused by inserting very large DOM trees in one task. When Worker parsing is enabled, keep `workerFallback: true` unless the target Worker runtime provides every required XML API.
260
+ An awaited layout includes font/image settlement and the resulting tab, drawing
261
+ and pagination measurements. It rejects if that render is replaced, its mounted
262
+ container is removed, or pagination cannot settle within
263
+ `maxDynamicPaginationPasses`. An `AbortError` identifies an obsolete or removed
264
+ render. With `awaitLayout: false`, rendering can return before these measurements
265
+ finish; call `awaitRenderedLayout` before measuring or exporting the result.
266
+ A detached `renderDocument` result may still be mounted and awaited later.
267
+
268
+ Batch rendering and browser yields avoid the former demo-page freeze caused by inserting very large DOM trees in one task. The supplied Worker includes its XML APIs. `workerFallback: true` remains useful when Worker startup is blocked by the host environment. If `workerJsZipUrl` is explicitly set, the Worker loads and uses that JSZip asset. The selection must be a non-empty same-origin HTTP(S) or Blob URL without credentials. Relative URLs resolve against the Worker script URL; a Blob Worker requires an absolute URL. Cross-origin URLs and opaque origins are rejected before import, even when a global JSZip implementation is already present. Omit this option to use the bundled dependency; an explicit invalid value does not select the default. A failed load or invalid JSZip export is reported as an error; it never silently substitutes the bundled dependency. `workerFallback` continues to control main-thread fallback; set it to `false` when any Worker or selected-dependency failure must reject the call.
251
269
 
252
270
  ## Pagination, headers/footers and TOC
253
271
 
@@ -281,7 +299,16 @@ URL-bearing attributes before it reaches a maximally restricted sandboxed iframe
281
299
 
282
300
  Set `darkMode: true` to reproduce Word Online's "Switch Modes" dark appearance. Every color the renderer emits — text, backgrounds/highlights, borders, underlines, theme colors and DrawingML/VML shape fills and strokes — is converted with the same lightness-inversion algorithm Microsoft uses for this exact purpose (see `roosterjs`'s `getDarkColor`): the color is converted to CIE Lab, only the lightness (`L`) channel is inverted around a fixed base value (the `L` of `#333333`), and hue/chroma (`a`/`b`) are left untouched. That guarantees every color stays legible on a dark page — pure black becomes pure white, pure white becomes `#333333`, and an arbitrary color such as `rgb(99, 36, 35)` keeps its reddish hue while becoming light enough to read — without the hue-flipping side effects of a naive per-channel RGB invert. The toggle is purely a rendering-time CSS transform — it does not change the parsed document model — and every transformed color is wrapped in a CSS variable so that `@media print` can restore the exact original light-mode value; print output always renders with Word's normal light appearance regardless of `darkMode`.
283
301
 
284
- Header/footer selection follows the WordprocessingML print-layout rules: `first` header/footer references are used only when the section has `w:titlePg`, and `even` references are used only when document settings contain `w:evenAndOddHeaders`; otherwise the default/odd header is used. This prevents even-page empty headers from hiding the normal header in documents that merely contain unused even header references.
302
+ Header/footer selection follows the WordprocessingML print-layout rules: `first` references apply to the first page of a section with `w:titlePg`, and `even` references apply only when settings contain `w:evenAndOddHeaders`. Each omitted reference inherits its own variant from the previous section. If a selected variant is absent in the first section, its header/footer is blank. Dynamic continuation pages select their own first/even/default variant instead of repeating a cloned first-page header/footer.
303
+
304
+ Adjacent saved page markers do not create extra blank pages, including a saved marker immediately after an authored page break. Repeated authored `w:br w:type="page"` breaks still preserve an intentional blank page.
305
+
306
+ Footnotes begin on the page containing their first visible reference. Long note
307
+ text continues in order across pages, preserving authored text, formatting and
308
+ embedded resources. Endnotes follow the final body content. Custom note marks
309
+ and section/page restart settings are kept separate from generated numbering.
310
+ An indivisible note object that cannot fit the printable page is retained and
311
+ reported as an unresolved layout error instead of being silently clipped.
285
312
 
286
313
  Complex-script formatting is kept script-aware. `w:iCs` and `w:bCs` now affect RTL/complex-script spans, but they are not applied to East Asian TOC text; this avoids turning Chinese TOC level 3 entries italic when the DOCX only specified complex-script italics.
287
314
 
@@ -305,20 +332,33 @@ It renders `tests/regression/database-design.docx` and asserts that TOC entries
305
332
 
306
333
  ## Build
307
334
 
308
- This repository includes a lightweight build script that emits synchronized, minified CommonJS, ESM and Worker bundles:
335
+ All JavaScript is generated by Rollup from the TypeScript source entry points. The build emits readable and minified UMD/CommonJS-compatible and ESM bundles, a self-contained Worker, and declarations generated by the local TypeScript compiler. Existing output is cleaned first, and `npm pack` rebuilds it automatically:
309
336
 
310
337
  ```bash
311
338
  npm run build
312
339
  ```
313
340
 
314
- Run the complete build and semantic regression suite with:
341
+ Install the lockfile dependencies with `npm ci`. No global compiler or `NODE_PATH` is required. `dist/jszip.min.js` is copied unchanged from the declared JSZip dependency for standalone main-thread use; bundled dependency licenses are retained in `dist/THIRD_PARTY_NOTICES.txt`.
342
+
343
+ Run the complete build, semantic regressions and package contract checks with:
315
344
 
316
345
  ```bash
317
346
  npm run verify
318
347
  ```
319
348
 
349
+ Run `npm run test:worker` for the isolated Node VM protocol checks. This is not a browser test. Run `npm run e2e:worker` (Chromium) and `npm run e2e:worker -- webkit` to verify the generated Worker, main-thread parity, genuine selected JSZip fetch/hash, and dependency/XML failure controls in real browsers. Set `DOCX_WORKER_JSZIP_PATH` to another installed JSZip browser asset when checking a consumer-resolved version. These checks never append parser code to the Worker.
350
+
320
351
  Browser-focused checks remain available through `npm run e2e`, `npm run e2e:chart` and `npm run e2e:header-guard`.
321
352
 
353
+ These commands run the existing Jasmine specs in the pinned Playwright browser,
354
+ served only on loopback. Install Chromium and Firefox with
355
+ `npx playwright install chromium firefox` before running them; `e2e:security`
356
+ runs both browsers with the strict CSP and Trusted Types fixture. Pass
357
+ `-- --browsers chromium,webkit` to select other installed engines.
358
+ `npm run e2e-watch` reruns the same specs after changes to `tests` or `dist`.
359
+ The runner uses native file enumeration and watching instead of the legacy
360
+ Karma glob dependencies, which included the unpatched `braces` recursion flaw.
361
+
322
362
  ## Local demo
323
363
 
324
364
  Serve the repository over HTTP and open the root page: