@file-viewer/docx 0.3.36 → 0.3.41
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.
- package/README.md +62 -0
- package/dist/document/common.d.ts +1 -0
- package/dist/document/grid-spacing.d.ts +4 -0
- package/dist/document/paragraph-spacing.d.ts +23 -0
- package/dist/document-parser.d.ts +1 -0
- package/dist/docx-preview.js +650 -46
- package/dist/docx-preview.min.js +2 -2
- package/dist/docx-preview.min.mjs +2 -2
- package/dist/docx-preview.mjs +650 -46
- package/dist/docx-preview.worker.js +99 -16
- package/dist/html-renderer.d.ts +27 -0
- package/dist/settings/settings.d.ts +2 -0
- package/dist/vml/vml.d.ts +1 -0
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
# @file-viewer/docx
|
|
4
4
|
|
|
5
|
+
[File Viewer on GitHub](https://github.com/flyfish-dev/file-viewer) · [Live demo](https://demo.file-viewer.app/) · [Documentation](https://doc.file-viewer.app/) · [Report an issue](https://github.com/flyfish-dev/file-viewer/issues)
|
|
6
|
+
|
|
5
7
|
Pure HTML DOCX renderer for browser-based Word previews. This package preserves the final non-canvas `docx-viewer` line as a stable maintenance track, converting WordprocessingML into HTML while keeping semantic structure, page layout, headers/footers, numbering, fields, tables, images and common DrawingML content as closely as browser layout allows.
|
|
6
8
|
|
|
7
9
|
This fork includes production hardening for large Word documents: optional Worker parsing with a main-thread fallback, asynchronous rendering yields, Word-saved pagination support, dynamic overflow pagination and layout telemetry.
|
|
8
10
|
|
|
11
|
+
This is the standalone DOCX engine, not the multi-format File Viewer component. Use the public links above for integration and support; the development repository is access-controlled.
|
|
12
|
+
|
|
9
13
|
## Installation
|
|
10
14
|
|
|
11
15
|
```bash
|
|
@@ -412,3 +416,61 @@ Manual dispatch defaults to a dry run and requires an existing release tag.
|
|
|
412
416
|
Retries verify the packed SHA-512 against the registry before skipping an
|
|
413
417
|
existing version. Different bytes or an uncertain write stop the run rather
|
|
414
418
|
than changing the version or repeating an authentication prompt.
|
|
419
|
+
|
|
420
|
+
### Picture layout in fixed-page previews
|
|
421
|
+
|
|
422
|
+
DrawingML `srcRect` cropping selects source pixels inside the authored picture frame, including asymmetric crops and rotation/mirroring. A cropped picture does not enlarge its surrounding paragraph or paint over following text.
|
|
423
|
+
|
|
424
|
+
During fixed-page pagination, an inline picture taller than a fresh page's body is scaled proportionally to fit, preserving the complete picture and its aspect ratio. Normal pictures keep their authored dimensions. This prevents repeatedly moving the same oversized picture through empty continuation pages. Continuous/flow previews keep their existing sizing behavior.
|
|
425
|
+
|
|
426
|
+
### Automatic paragraph spacing and theme languages
|
|
427
|
+
|
|
428
|
+
For `w:beforeAutospacing` / `w:afterAutospacing`, the HTML preview uses a `1em`
|
|
429
|
+
margin, matching the default HTML paragraph policy. When document compatibility
|
|
430
|
+
settings enable `w:doNotUseHTMLParagraphAutoSpacing`, automatic spacing instead
|
|
431
|
+
uses the specified 5pt before and 10pt after. Explicit false cancels inherited
|
|
432
|
+
automatic spacing and restores the inherited non-auto value, or zero when none
|
|
433
|
+
was specified. Automatic flags from numbering levels participate in the same
|
|
434
|
+
resolution. Explicit paragraph styles inherit their `basedOn` chain; a style
|
|
435
|
+
without `basedOn` does not acquire Normal's automatic spacing. Explicit zero
|
|
436
|
+
`beforeLines` / `afterLines` values remain zero;
|
|
437
|
+
they can clear positive spacing from a parent style. These rules follow the
|
|
438
|
+
[compatibility setting](https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.donotusehtmlparagraphautospacing?view=openxml-3.0.1)
|
|
439
|
+
and [HTML default paragraph margins](https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3).
|
|
440
|
+
|
|
441
|
+
The `1em` policy does not promise Word/WPS's exact spacing at page, table, list
|
|
442
|
+
or text-frame boundaries. Paragraph-margin collapse and pagination still depend
|
|
443
|
+
on native browser layout. No fixed 14pt or estimated font-metric constant is
|
|
444
|
+
used as a universal equivalent.
|
|
445
|
+
|
|
446
|
+
East Asian and complex theme font slots resolve against the effective run
|
|
447
|
+
language inherited from run/character style, paragraph style and document
|
|
448
|
+
defaults. Simplified Chinese, Traditional Chinese, Japanese and Korean retain
|
|
449
|
+
their separate theme script mappings. Explicit typefaces stay explicit; missing
|
|
450
|
+
script mappings keep the base theme fallback. This extends the existing
|
|
451
|
+
language-based font policy; it does not replace text shaping or guarantee that
|
|
452
|
+
the requested font is installed. Settings-only `w:themeFontLang` selection is
|
|
453
|
+
not added by this change.
|
|
454
|
+
|
|
455
|
+
Automatic complex-script formatting also recognizes pure runs in Devanagari,
|
|
456
|
+
Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala,
|
|
457
|
+
Thai, Lao, Tibetan, Myanmar and Khmer scripts. This preserves their inherited
|
|
458
|
+
CS font and independent `szCs` size without requiring a forced `w:cs` flag.
|
|
459
|
+
Explicit cs/rtl choices retain their existing precedence. The added path accepts
|
|
460
|
+
neutral punctuation, digits and joiners but does not change a mixed run with
|
|
461
|
+
another strong script into CS formatting. Existing mixed-run handling is retained;
|
|
462
|
+
per-character formatting inside those runs and native shaping remain separate
|
|
463
|
+
fidelity limits. This list is not a claim to cover every Unicode complex script.
|
|
464
|
+
|
|
465
|
+
The focused static parser/HTML checks run automatically through
|
|
466
|
+
`npm run test:regression`:
|
|
467
|
+
|
|
468
|
+
```bash
|
|
469
|
+
node tests/regression/check-paragraph-auto-spacing.cjs
|
|
470
|
+
node tests/regression/check-theme-language-inheritance.cjs
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
These checks include real generated DOCX packages and settings snapshot round
|
|
474
|
+
trips. They do not measure native browser layout or substitute for Word/WPS
|
|
475
|
+
reference renders. Document-grid line-height formulas are unchanged: evidence
|
|
476
|
+
for a universal `1.25em` metric or multiplication by the grid pitch is incomplete.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Resolve an enabled section grid's automatic line multiplier, without measuring glyphs. */
|
|
2
|
+
export declare function gridAutomaticLineHeight(lineHeight: string, linePitch: string): string;
|
|
3
|
+
/** Reserve whole grid slots for a font's normal line, and honor larger multiples. */
|
|
4
|
+
export declare function gridFontLineHeight(natural: number, pitch: number, multiplier?: number): number | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Word for Mac16.112.2:100 line units=12pt even with docDefaults10/Normal16/direct8–20pt. */
|
|
2
|
+
export declare const WORD_PARAGRAPH_LINE_UNIT_PT = 12;
|
|
3
|
+
/** Ordinary spacing values from one w:spacing declaration, before inheritance. */
|
|
4
|
+
export declare function paragraphSpacingDeclaration(points: string, lines: number): {
|
|
5
|
+
lines: string;
|
|
6
|
+
fallback: string;
|
|
7
|
+
};
|
|
8
|
+
/** Word for Mac16.112.2 HTML-auto policy, verified with8/12/18pt native controls. */
|
|
9
|
+
export declare const WORD_HTML_AUTO_SPACING_PT = 14;
|
|
10
|
+
export interface ParagraphSpacingState {
|
|
11
|
+
before: string;
|
|
12
|
+
after: string;
|
|
13
|
+
beforeAuto: boolean;
|
|
14
|
+
afterAuto: boolean;
|
|
15
|
+
beforeDeclared: boolean;
|
|
16
|
+
afterDeclared: boolean;
|
|
17
|
+
contextual: boolean;
|
|
18
|
+
styleId: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function effectiveParagraphSpacing(levels: Record<string, string>[], fixed: boolean, styleId: string): ParagraphSpacingState;
|
|
21
|
+
export declare function spacingPoints(length: string): number | null;
|
|
22
|
+
/** Word resolves the before remainder before contextual suppression, then sums. */
|
|
23
|
+
export declare function paragraphSpacingGap(previous: ParagraphSpacingState, next: ParagraphSpacingState, fixed: boolean): string | null;
|
|
@@ -83,6 +83,7 @@ export declare class DocumentParser {
|
|
|
83
83
|
parseDmlGroupTransform(elem: Element, parentTransform?: any): any;
|
|
84
84
|
parseDmlPositionedPicture(elem: Element, transform?: any): IDomImage;
|
|
85
85
|
parseDmlPositionedShape(elem: Element, transform?: any): IDomShape;
|
|
86
|
+
parseDmlRoundRectRadius(spPr: Element, width: number, height: number, transform?: any): string;
|
|
86
87
|
parseDmlShapeBounds(spPr: Element, transform?: any): {
|
|
87
88
|
left: number;
|
|
88
89
|
top: number;
|