doc-codec 2.2.4 → 2.2.5
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 +13 -12
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/prop/chp.cjs +6 -0
- package/dist/prop/chp.d.cts +2 -1
- package/dist/prop/chp.d.ts +2 -1
- package/dist/prop/chp.js +6 -1
- package/dist/read.cjs +13 -4
- package/dist/read.js +15 -6
- package/dist/style/stsh.cjs +64 -2
- package/dist/style/stsh.d.cts +11 -1
- package/dist/style/stsh.d.ts +11 -1
- package/dist/style/stsh.js +64 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Built and shipped, on the read side:
|
|
|
16
16
|
- **The piece table** — `parseClx` resolves a `Clx` (skipping any leading `Prc` array) into the pieces the logical text stream is assembled from, including the compressed 8-bit spelling and its halved byte offset.
|
|
17
17
|
- **Text reconstruction** — `readTextRange` turns a range of character positions into real characters through [MS-DOC] 2.4.1's own Retrieving Text algorithm, applying the specification's byte-to-code-point mapping for compressed pieces, and returns each character's byte offset alongside it.
|
|
18
18
|
- **Character and paragraph formatting** — the `PlcBteChpx`/`PlcBtePapx` bin tables and the `ChpxFkp`/`PapxFkp` pages behind them, the `Sprm`/`Prl` operand-sizing rules, and the subset of the character- and paragraph-property tables listed under [What is converted](#what-is-converted), now including `sprmCRgFtc0`'s font-table lookup (see [The font table](#the-font-table)).
|
|
19
|
-
- **The style sheet** — `parseStsh` reads each style's index, name, kind
|
|
19
|
+
- **The style sheet** — `parseStsh` reads each style's index, name, kind, parent, and (for a paragraph or character style) its own `grLPUpxSw` formatting sets; `resolveStyleFormatting` walks the `istdBase` inheritance chain and folds each style's own paragraph/character properties, most-specific style winning, beneath a paragraph's or run's own direct exceptions ([ExaDev/documents.js#1005](https://github.com/ExaDev/documents.js/issues/1005)). `headingLevelFromIstd` applies `sprmPIstd`'s own rule that an `istd` of 1 through 9 states an outline level.
|
|
20
20
|
- **Tables** — `table/read.ts`'s `assembleBlocks` folds a contiguous run of table-depth-1 paragraphs into a real `ContentTable`: cell boundaries at each cell-mark (`0x07`) character, a cell holding more than one paragraph where only its last ends in a cell mark, and each row's own trailing mark (`sprmPFTtp`) resolved through `table/tap.ts`'s `applyTableSprms` for its TAP — column boundaries and every physical cell's own horizontal/vertical merge state, from `sprmTDefTable`'s `TDefTableOperand` (and a `sprmTMerge` range or `sprmTVertMerge` per-cell flag where a real producer states a merge that way instead — see [Tables](#tables) below for why both are read). A table nested inside a table cell (table depth greater than 1, detected via `sprmPItap`/`sprmPFInnerTableCell`/`sprmPFInnerTtp`) is refused with `DocUnsupportedError` rather than mis-read; a row whose own TAP this reader cannot resolve at all — no direct `sprmTDefTable` anywhere in its grpprl, or a cell-mark count that disagrees with it — degrades the whole run back to flat paragraphs instead, since that is a legal producer choice this reader does not yet follow rather than corruption (see [Tables](#tables)).
|
|
21
21
|
- **Table cell decoration** — `ContentTableCell.background` and `.borders`, from every encoding [MS-DOC] states them in: each cell's own four `Brc80` borders inside `TC80`, the exact-colour `sprmTSetBrc` layer a real producer writes beside them, the row-level shading arrays (`sprmTDefTableShd`/`2nd`/`3rd`, their `Raw` counterparts, the Word 97-era `sprmTDefTableShd80`, and `sprmTSetShd`/`sprmTSetShdOdd`), and, cascaded onto whichever cells and sides those leave unstated, the row/table-level `sprmTTableBorders`/`sprmTTableBorders80` border set and `sprmTSetShdTable`'s own per-row background. See [Cell decoration](#cell-decoration).
|
|
22
22
|
- **`readDocContent`** — the whole chain, producing a `'wordprocessing'` `ContentDocument` of paragraphs, runs and tables.
|
|
@@ -36,7 +36,8 @@ Built and shipped, on the write side — see [Writing](#writing) for the full sc
|
|
|
36
36
|
| --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
37
|
| **Nested tables** | A table inside a table cell (table depth greater than 1) is a genuinely different [MS-DOC] structure — `sprmPFInnerTableCell`/`sprmPFInnerTtp` mark its cell/row ends rather than `sprmPFInTable`/`sprmPFTtp`, and `sprmPItap`/`sprmPDtap` state the depth. Neither side of this package descends into one: `readDocContent` refuses with `DocUnsupportedError` the moment it detects a table depth greater than 1, and `writeDocContent` refuses a `ContentTable` block found inside a table cell's own blocks the same way. See [Tables](#tables) for the full scope of what a depth-1 table does resolve. |
|
|
38
38
|
| **Images and drawn objects** | The anchor characters (`U+0001`, `U+0008`) are dropped rather than emitted as control characters. No picture data is read. `writeDocContent` refuses an image block. |
|
|
39
|
-
| **Style-inherited formatting**
|
|
39
|
+
| **Style-inherited formatting on write** | A style's own property sets (`STD.grLPUpxSw`) are now resolved and folded on read ([ExaDev/documents.js#1005](https://github.com/ExaDev/documents.js/issues/1005)): a paragraph's formatting is its style's own grpprlPapx/grpprlChpx (walked up the full `istdBase` inheritance chain, most-specific style winning) plus its own direct exceptions on top, and a run's own referenced character style (`sprmCIstd`) folds in the same way. `writeDocContent` still writes no paragraph styles at all (every paragraph is `istd` 0) and does not round-trip `styleId`/`headingLevel` -- a genuinely separate write-side gap, since doc-codec's flat `ContentDocument` carries no style-vs-direct-formatting split to mint real style entries from. Tracked in [ExaDev/documents.js#1059](https://github.com/ExaDev/documents.js/issues/1059). |
|
|
40
|
+
| **Table and numbering style formatting** | `STD.grLPUpxSw` is resolved only for paragraph and character styles (`stk` 1/2, see the row above) -- a table style's `StkTableGRLPUPX` (its own `TAPX` plus `CNFC`-conditional per-region formatting, [MS-DOC] 2.4.6.6's own table-specific steps 6-9) and a numbering style's `StkListGRLPUPX` are neither read nor written. A table applying a named table style, or a paragraph using a numbering style rather than direct list formatting, reports none of the formatting either would supply. |
|
|
40
41
|
| **Subdocuments** | Only the main document (character positions 0 to `ccpText`) is converted. Footnotes, endnotes, headers, footers, comments and text boxes are not, in either direction. |
|
|
41
42
|
| **Section boundaries** | Section boundaries themselves are not read — the whole document is always treated as one section, spanning the entire main document — so a multi-section `.doc`'s later sections' own page size and margins are never consulted, only the first's (see the read-side page-size/margins bullet above for what is now read of that one section). `writeDocContent` refuses a `ContentDocument` with more than one section, rather than silently merging their content into what would read back as one. |
|
|
42
43
|
| **Extended and user-defined document properties** | `title`/`subject`/`author`/`keywords`/`createdIso`/`modifiedIso` are read from and written to a `"\x05SummaryInformation"` stream when present (see [Metadata](#metadata)); the sibling `"\x05DocumentSummaryInformation"` stream (company, manager, and custom user-defined properties) is not read or written at all. |
|
|
@@ -51,15 +52,15 @@ One construct is refused rather than mis-read: a `sprmPChgTabs` whose `cb` is th
|
|
|
51
52
|
|
|
52
53
|
Character properties, from `Chpx` grpprls:
|
|
53
54
|
|
|
54
|
-
| Sprm | Becomes
|
|
55
|
-
| ----------------------------------------------------------------------- |
|
|
56
|
-
| `sprmCFBold` (0x0835), `sprmCFItalic` (0x0836), `sprmCFStrike` (0x0837) | `bold` / `italic` / `strike`, honouring `ToggleOperand`'s inherit (0x80) and invert (0x81) values
|
|
57
|
-
| `sprmCKul` (0x2A3E) | `underline` (any non-zero `Kul` style)
|
|
58
|
-
| `sprmCHps` (0x4A43) | `sizePt`, the operand being half-points
|
|
59
|
-
| `sprmCIco` (0x2A42) | `color`, through [MS-DOC] 2.9.119's fixed palette
|
|
60
|
-
| `sprmCCv` (0x6870) | `color`, from a `COLORREF`
|
|
61
|
-
| `sprmCIstd` (0x4A30) | the character style
|
|
62
|
-
| `sprmCRgFtc0` (0x4A4F) | `fontFamily`, looked up by index in the document's own font table (see [The font table](#the-font-table))
|
|
55
|
+
| Sprm | Becomes |
|
|
56
|
+
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
57
|
+
| `sprmCFBold` (0x0835), `sprmCFItalic` (0x0836), `sprmCFStrike` (0x0837) | `bold` / `italic` / `strike`, honouring `ToggleOperand`'s inherit (0x80) and invert (0x81) values |
|
|
58
|
+
| `sprmCKul` (0x2A3E) | `underline` (any non-zero `Kul` style) |
|
|
59
|
+
| `sprmCHps` (0x4A43) | `sizePt`, the operand being half-points |
|
|
60
|
+
| `sprmCIco` (0x2A42) | `color`, through [MS-DOC] 2.9.119's fixed palette |
|
|
61
|
+
| `sprmCCv` (0x6870) | `color`, from a `COLORREF` |
|
|
62
|
+
| `sprmCIstd` (0x4A30) | resolves the named character style's own formatting and folds it in ([ExaDev/documents.js#1005](https://github.com/ExaDev/documents.js/issues/1005)), between the paragraph style's own defaults and this run's remaining direct exceptions |
|
|
63
|
+
| `sprmCRgFtc0` (0x4A4F) | `fontFamily`, looked up by index in the document's own font table (see [The font table](#the-font-table)) |
|
|
63
64
|
|
|
64
65
|
Paragraph properties, from `PapxInFkp` grpprls:
|
|
65
66
|
|
|
@@ -219,7 +220,7 @@ The modules layer in the order [MS-DOC]'s own algorithms chain:
|
|
|
219
220
|
| `src/prop/fkp.ts` | The formatted disk pages and the bin tables that address them. |
|
|
220
221
|
| `src/prop/chp.ts`, `src/prop/pap.ts` | Folding a grpprl into character and paragraph properties. |
|
|
221
222
|
| `src/list/numbering.ts` | Resolving `PlfLst`/`PlfLfo` into `NumberingDefinitions` (see [Numbering definitions](#numbering-definitions)). |
|
|
222
|
-
| `src/style/stsh.ts` | The style sheet.
|
|
223
|
+
| `src/style/stsh.ts` | The style sheet, plus resolving a style's own inherited formatting up its `istdBase` chain. |
|
|
223
224
|
| `src/style/fonts.ts` | The font table (`SttbfFfn`/`FFN`) — read and write together, since both directions share one small, self-contained field layout. |
|
|
224
225
|
| `src/metadata.ts` | Wraps `archive-codec`'s own `SummaryInformationProperties` <-> `LayoutMetadata` mapping with this package's `createdIso`/`modifiedIso` date validation, throwing `DocFormatError` for a malformed one rather than letting an opaque `RangeError` escape the FILETIME conversion (see [Metadata](#metadata)). |
|
|
225
226
|
| `src/table/decoration.ts` | A cell's border and background-shading encodings -- `Brc80`, `Brc`, `Shd`, `Shd80`, and the `BrcType`/`Ipat` vocabularies -- read and written in one place, so neither direction can drift from the other (see [Cell decoration](#cell-decoration)). |
|
package/dist/index.cjs
CHANGED
|
@@ -74,6 +74,7 @@ exports.buildPlcfSed = require_prop_sep_write.buildPlcfSed;
|
|
|
74
74
|
exports.buildPropertyBinTable = require_prop_fkp_write.buildPropertyBinTable;
|
|
75
75
|
exports.buildSepx = require_prop_sep_write.buildSepx;
|
|
76
76
|
exports.buildTextClx = require_text_piece_table_write.buildTextClx;
|
|
77
|
+
exports.characterIstdFromGrpprl = require_prop_chp.characterIstdFromGrpprl;
|
|
77
78
|
exports.characterOffset = require_text_piece_table.characterOffset;
|
|
78
79
|
exports.characterSize = require_text_piece_table.characterSize;
|
|
79
80
|
exports.decodeSprm = require_prop_sprm.decodeSprm;
|
|
@@ -107,6 +108,7 @@ exports.readTextRange = require_text_characters.readTextRange;
|
|
|
107
108
|
exports.readUint16LE = require_bytes.readUint16LE;
|
|
108
109
|
exports.readUint32LE = require_bytes.readUint32LE;
|
|
109
110
|
exports.readUint8 = require_bytes.readUint8;
|
|
111
|
+
exports.resolveStyleFormatting = require_style_stsh.resolveStyleFormatting;
|
|
110
112
|
exports.slice = require_bytes.slice;
|
|
111
113
|
exports.tableStreamName = require_fib_fib.tableStreamName;
|
|
112
114
|
exports.writeDocContent = require_write.writeDocContent;
|
package/dist/index.d.cts
CHANGED
|
@@ -13,15 +13,15 @@ import { ANNOTATION_REFERENCE, CELL_MARK, DRAWN_OBJECT, FIELD_BEGIN, FIELD_END,
|
|
|
13
13
|
import { a as operandSize, i as decodeSprm, n as SGC, o as readGrpprl, r as Sprm, t as Prl } from "./sprm-DEyvdOo0.cjs";
|
|
14
14
|
import { ChpxFkp, FKP_PAGE_SIZE, PapxFkp, PapxLookup, PapxRecord, PropertyBinTable, parseChpxFkp, parsePapxFkp } from "./prop/fkp.cjs";
|
|
15
15
|
import { ChpxRunToWrite, PapxParagraphToWrite, buildChpxPages, buildPapxPages, buildPropertyBinTable, firstFcOfPage, fitsAloneOnPapxPage } from "./prop/fkp-write.cjs";
|
|
16
|
-
import { CharacterProperties, applyCharacterSprms } from "./prop/chp.cjs";
|
|
16
|
+
import { CharacterProperties, applyCharacterSprms, characterIstdFromGrpprl } from "./prop/chp.cjs";
|
|
17
17
|
import { encodeCharacterGrpprl } from "./prop/chp-write.cjs";
|
|
18
18
|
import { n as applyParagraphSprms, t as ParagraphProperties } from "./pap-BT1p0uzu.cjs";
|
|
19
19
|
import { encodeParagraphGrpprl } from "./prop/pap-write.cjs";
|
|
20
20
|
import { SectionProperties, applySectionSprms, readSectionProperties } from "./prop/sep.cjs";
|
|
21
21
|
import { buildPlcfSed, buildSepx, encodeSectionGrpprl } from "./prop/sep-write.cjs";
|
|
22
|
-
import { STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh } from "./style/stsh.cjs";
|
|
22
|
+
import { ResolvedStyleFormatting, STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh, resolveStyleFormatting } from "./style/stsh.cjs";
|
|
23
23
|
import { buildFontTable, parseFontTable } from "./style/fonts.cjs";
|
|
24
24
|
import { a as readNumberingDefinitions, i as NumberingLevel, n as NumberingDefinition, r as NumberingDefinitions, t as NUMBER_FORMAT_BY_NFC } from "./numbering-Bivayss4.cjs";
|
|
25
25
|
import { DocContent, DocStreams, ParagraphEntry, readDocContent, readDocStreams } from "./read.cjs";
|
|
26
26
|
import { WriteDocContentOptions, writeDocContent } from "./write.cjs";
|
|
27
|
-
export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, CharacterProperties, ChpxFkp, ChpxRunToWrite, DRAWN_OBJECT, DocContent, DocFormatError, DocStreams, DocUnsupportedError, FC_LCB_VALUE_INDEX, FIB_BASE_FLAG, FIB_BASE_SIZE, FIB_CB_RG_FC_LCB_OFFSET, FIB_CSLW_OFFSET, FIB_CSLW_REQUIRED, FIB_CSW_REQUIRED, FIB_FC_LCB_BLOB_OFFSET, FIB_RG_LW_OFFSET, FIB_RG_LW_SIZE, FIB_RG_W_OFFSET, FIB_RG_W_SIZE, FIB_W_IDENT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FKP_PAGE_SIZE, FOOTNOTE_REFERENCE, Fib, FibWriteSpec, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, NUMBER_FORMAT_BY_NFC, NumberingDefinition, NumberingDefinitions, NumberingLevel, PARAGRAPH_MARK, PapxFkp, PapxLookup, PapxParagraphToWrite, PapxRecord, ParagraphEntry, ParagraphProperties, Piece, PieceTable, Plc, Prl, PropertyBinTable, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SUMMARY_INFORMATION_STREAM, SYMBOL_ANCHOR, SectionProperties, Sprm, Style, StyleSheet, TextRange, WORD_DOCUMENT_STREAM, WriteDocContentOptions, applyCharacterSprms, applyParagraphSprms, applySectionSprms, buildChpxPages, buildEmptyStsh, buildFib, buildFontTable, buildPapxPages, buildPlcfSed, buildPropertyBinTable, buildSepx, buildTextClx, characterOffset, characterSize, decodeSprm, encodeCharacterGrpprl, encodeParagraphGrpprl, encodeSectionGrpprl, endsParagraph, findLargestAtMost, firstFcOfPage, fitsAloneOnPapxPage, headingLevelFromIstd, isAnchorOnly, isDocBytes, layoutMetadataToSummaryInformation, operandSize, parseChpxFkp, parseClx, parseFib, parseFontTable, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readNumberingDefinitions, readSectionProperties, readTextRange, readUint16LE, readUint32LE, readUint8, slice, tableStreamName, writeDocContent };
|
|
27
|
+
export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, CharacterProperties, ChpxFkp, ChpxRunToWrite, DRAWN_OBJECT, DocContent, DocFormatError, DocStreams, DocUnsupportedError, FC_LCB_VALUE_INDEX, FIB_BASE_FLAG, FIB_BASE_SIZE, FIB_CB_RG_FC_LCB_OFFSET, FIB_CSLW_OFFSET, FIB_CSLW_REQUIRED, FIB_CSW_REQUIRED, FIB_FC_LCB_BLOB_OFFSET, FIB_RG_LW_OFFSET, FIB_RG_LW_SIZE, FIB_RG_W_OFFSET, FIB_RG_W_SIZE, FIB_W_IDENT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FKP_PAGE_SIZE, FOOTNOTE_REFERENCE, Fib, FibWriteSpec, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, NUMBER_FORMAT_BY_NFC, NumberingDefinition, NumberingDefinitions, NumberingLevel, PARAGRAPH_MARK, PapxFkp, PapxLookup, PapxParagraphToWrite, PapxRecord, ParagraphEntry, ParagraphProperties, Piece, PieceTable, Plc, Prl, PropertyBinTable, ResolvedStyleFormatting, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SUMMARY_INFORMATION_STREAM, SYMBOL_ANCHOR, SectionProperties, Sprm, Style, StyleSheet, TextRange, WORD_DOCUMENT_STREAM, WriteDocContentOptions, applyCharacterSprms, applyParagraphSprms, applySectionSprms, buildChpxPages, buildEmptyStsh, buildFib, buildFontTable, buildPapxPages, buildPlcfSed, buildPropertyBinTable, buildSepx, buildTextClx, characterIstdFromGrpprl, characterOffset, characterSize, decodeSprm, encodeCharacterGrpprl, encodeParagraphGrpprl, encodeSectionGrpprl, endsParagraph, findLargestAtMost, firstFcOfPage, fitsAloneOnPapxPage, headingLevelFromIstd, isAnchorOnly, isDocBytes, layoutMetadataToSummaryInformation, operandSize, parseChpxFkp, parseClx, parseFib, parseFontTable, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readNumberingDefinitions, readSectionProperties, readTextRange, readUint16LE, readUint32LE, readUint8, resolveStyleFormatting, slice, tableStreamName, writeDocContent };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,15 +13,15 @@ import { ANNOTATION_REFERENCE, CELL_MARK, DRAWN_OBJECT, FIELD_BEGIN, FIELD_END,
|
|
|
13
13
|
import { a as operandSize, i as decodeSprm, n as SGC, o as readGrpprl, r as Sprm, t as Prl } from "./sprm-DEyvdOo0.js";
|
|
14
14
|
import { ChpxFkp, FKP_PAGE_SIZE, PapxFkp, PapxLookup, PapxRecord, PropertyBinTable, parseChpxFkp, parsePapxFkp } from "./prop/fkp.js";
|
|
15
15
|
import { ChpxRunToWrite, PapxParagraphToWrite, buildChpxPages, buildPapxPages, buildPropertyBinTable, firstFcOfPage, fitsAloneOnPapxPage } from "./prop/fkp-write.js";
|
|
16
|
-
import { CharacterProperties, applyCharacterSprms } from "./prop/chp.js";
|
|
16
|
+
import { CharacterProperties, applyCharacterSprms, characterIstdFromGrpprl } from "./prop/chp.js";
|
|
17
17
|
import { encodeCharacterGrpprl } from "./prop/chp-write.js";
|
|
18
18
|
import { n as applyParagraphSprms, t as ParagraphProperties } from "./pap-DOFLMWcG.js";
|
|
19
19
|
import { encodeParagraphGrpprl } from "./prop/pap-write.js";
|
|
20
20
|
import { SectionProperties, applySectionSprms, readSectionProperties } from "./prop/sep.js";
|
|
21
21
|
import { buildPlcfSed, buildSepx, encodeSectionGrpprl } from "./prop/sep-write.js";
|
|
22
|
-
import { STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh } from "./style/stsh.js";
|
|
22
|
+
import { ResolvedStyleFormatting, STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh, resolveStyleFormatting } from "./style/stsh.js";
|
|
23
23
|
import { buildFontTable, parseFontTable } from "./style/fonts.js";
|
|
24
24
|
import { a as readNumberingDefinitions, i as NumberingLevel, n as NumberingDefinition, r as NumberingDefinitions, t as NUMBER_FORMAT_BY_NFC } from "./numbering-Co4jssbG.js";
|
|
25
25
|
import { DocContent, DocStreams, ParagraphEntry, readDocContent, readDocStreams } from "./read.js";
|
|
26
26
|
import { WriteDocContentOptions, writeDocContent } from "./write.js";
|
|
27
|
-
export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, CharacterProperties, ChpxFkp, ChpxRunToWrite, DRAWN_OBJECT, DocContent, DocFormatError, DocStreams, DocUnsupportedError, FC_LCB_VALUE_INDEX, FIB_BASE_FLAG, FIB_BASE_SIZE, FIB_CB_RG_FC_LCB_OFFSET, FIB_CSLW_OFFSET, FIB_CSLW_REQUIRED, FIB_CSW_REQUIRED, FIB_FC_LCB_BLOB_OFFSET, FIB_RG_LW_OFFSET, FIB_RG_LW_SIZE, FIB_RG_W_OFFSET, FIB_RG_W_SIZE, FIB_W_IDENT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FKP_PAGE_SIZE, FOOTNOTE_REFERENCE, Fib, FibWriteSpec, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, NUMBER_FORMAT_BY_NFC, NumberingDefinition, NumberingDefinitions, NumberingLevel, PARAGRAPH_MARK, PapxFkp, PapxLookup, PapxParagraphToWrite, PapxRecord, ParagraphEntry, ParagraphProperties, Piece, PieceTable, Plc, Prl, PropertyBinTable, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SUMMARY_INFORMATION_STREAM, SYMBOL_ANCHOR, SectionProperties, Sprm, Style, StyleSheet, TextRange, WORD_DOCUMENT_STREAM, WriteDocContentOptions, applyCharacterSprms, applyParagraphSprms, applySectionSprms, buildChpxPages, buildEmptyStsh, buildFib, buildFontTable, buildPapxPages, buildPlcfSed, buildPropertyBinTable, buildSepx, buildTextClx, characterOffset, characterSize, decodeSprm, encodeCharacterGrpprl, encodeParagraphGrpprl, encodeSectionGrpprl, endsParagraph, findLargestAtMost, firstFcOfPage, fitsAloneOnPapxPage, headingLevelFromIstd, isAnchorOnly, isDocBytes, layoutMetadataToSummaryInformation, operandSize, parseChpxFkp, parseClx, parseFib, parseFontTable, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readNumberingDefinitions, readSectionProperties, readTextRange, readUint16LE, readUint32LE, readUint8, slice, tableStreamName, writeDocContent };
|
|
27
|
+
export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, CharacterProperties, ChpxFkp, ChpxRunToWrite, DRAWN_OBJECT, DocContent, DocFormatError, DocStreams, DocUnsupportedError, FC_LCB_VALUE_INDEX, FIB_BASE_FLAG, FIB_BASE_SIZE, FIB_CB_RG_FC_LCB_OFFSET, FIB_CSLW_OFFSET, FIB_CSLW_REQUIRED, FIB_CSW_REQUIRED, FIB_FC_LCB_BLOB_OFFSET, FIB_RG_LW_OFFSET, FIB_RG_LW_SIZE, FIB_RG_W_OFFSET, FIB_RG_W_SIZE, FIB_W_IDENT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FKP_PAGE_SIZE, FOOTNOTE_REFERENCE, Fib, FibWriteSpec, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, NUMBER_FORMAT_BY_NFC, NumberingDefinition, NumberingDefinitions, NumberingLevel, PARAGRAPH_MARK, PapxFkp, PapxLookup, PapxParagraphToWrite, PapxRecord, ParagraphEntry, ParagraphProperties, Piece, PieceTable, Plc, Prl, PropertyBinTable, ResolvedStyleFormatting, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SUMMARY_INFORMATION_STREAM, SYMBOL_ANCHOR, SectionProperties, Sprm, Style, StyleSheet, TextRange, WORD_DOCUMENT_STREAM, WriteDocContentOptions, applyCharacterSprms, applyParagraphSprms, applySectionSprms, buildChpxPages, buildEmptyStsh, buildFib, buildFontTable, buildPapxPages, buildPlcfSed, buildPropertyBinTable, buildSepx, buildTextClx, characterIstdFromGrpprl, characterOffset, characterSize, decodeSprm, encodeCharacterGrpprl, encodeParagraphGrpprl, encodeSectionGrpprl, endsParagraph, findLargestAtMost, firstFcOfPage, fitsAloneOnPapxPage, headingLevelFromIstd, isAnchorOnly, isDocBytes, layoutMetadataToSummaryInformation, operandSize, parseChpxFkp, parseClx, parseFib, parseFontTable, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readNumberingDefinitions, readSectionProperties, readTextRange, readUint16LE, readUint32LE, readUint8, resolveStyleFormatting, slice, tableStreamName, writeDocContent };
|
package/dist/index.js
CHANGED
|
@@ -13,15 +13,15 @@ import { ANNOTATION_REFERENCE, CELL_MARK, DRAWN_OBJECT, FIELD_BEGIN, FIELD_END,
|
|
|
13
13
|
import { SGC, decodeSprm, operandSize, readGrpprl } from "./prop/sprm.js";
|
|
14
14
|
import { FKP_PAGE_SIZE, PropertyBinTable, parseChpxFkp, parsePapxFkp } from "./prop/fkp.js";
|
|
15
15
|
import { buildChpxPages, buildPapxPages, buildPropertyBinTable, firstFcOfPage, fitsAloneOnPapxPage } from "./prop/fkp-write.js";
|
|
16
|
-
import { applyCharacterSprms } from "./prop/chp.js";
|
|
16
|
+
import { applyCharacterSprms, characterIstdFromGrpprl } from "./prop/chp.js";
|
|
17
17
|
import { encodeCharacterGrpprl } from "./prop/chp-write.js";
|
|
18
18
|
import { applyParagraphSprms } from "./prop/pap.js";
|
|
19
19
|
import { encodeParagraphGrpprl } from "./prop/pap-write.js";
|
|
20
20
|
import { applySectionSprms, readSectionProperties } from "./prop/sep.js";
|
|
21
21
|
import { buildPlcfSed, buildSepx, encodeSectionGrpprl } from "./prop/sep-write.js";
|
|
22
|
-
import { STI_USER_DEFINED, STK, buildEmptyStsh, headingLevelFromIstd, parseStsh } from "./style/stsh.js";
|
|
22
|
+
import { STI_USER_DEFINED, STK, buildEmptyStsh, headingLevelFromIstd, parseStsh, resolveStyleFormatting } from "./style/stsh.js";
|
|
23
23
|
import { buildFontTable, parseFontTable } from "./style/fonts.js";
|
|
24
24
|
import { NUMBER_FORMAT_BY_NFC, readNumberingDefinitions } from "./list/numbering.js";
|
|
25
25
|
import { readDocContent, readDocStreams } from "./read.js";
|
|
26
26
|
import { writeDocContent } from "./write.js";
|
|
27
|
-
export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, DRAWN_OBJECT, DocFormatError, DocUnsupportedError, FC_LCB_VALUE_INDEX, FIB_BASE_FLAG, FIB_BASE_SIZE, FIB_CB_RG_FC_LCB_OFFSET, FIB_CSLW_OFFSET, FIB_CSLW_REQUIRED, FIB_CSW_REQUIRED, FIB_FC_LCB_BLOB_OFFSET, FIB_RG_LW_OFFSET, FIB_RG_LW_SIZE, FIB_RG_W_OFFSET, FIB_RG_W_SIZE, FIB_W_IDENT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FKP_PAGE_SIZE, FOOTNOTE_REFERENCE, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, NUMBER_FORMAT_BY_NFC, PARAGRAPH_MARK, PropertyBinTable, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SUMMARY_INFORMATION_STREAM, SYMBOL_ANCHOR, WORD_DOCUMENT_STREAM, applyCharacterSprms, applyParagraphSprms, applySectionSprms, buildChpxPages, buildEmptyStsh, buildFib, buildFontTable, buildPapxPages, buildPlcfSed, buildPropertyBinTable, buildSepx, buildTextClx, characterOffset, characterSize, decodeSprm, encodeCharacterGrpprl, encodeParagraphGrpprl, encodeSectionGrpprl, endsParagraph, findLargestAtMost, firstFcOfPage, fitsAloneOnPapxPage, headingLevelFromIstd, isAnchorOnly, isDocBytes, layoutMetadataToSummaryInformation, operandSize, parseChpxFkp, parseClx, parseFib, parseFontTable, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readNumberingDefinitions, readSectionProperties, readTextRange, readUint16LE, readUint32LE, readUint8, slice, tableStreamName, writeDocContent };
|
|
27
|
+
export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, DRAWN_OBJECT, DocFormatError, DocUnsupportedError, FC_LCB_VALUE_INDEX, FIB_BASE_FLAG, FIB_BASE_SIZE, FIB_CB_RG_FC_LCB_OFFSET, FIB_CSLW_OFFSET, FIB_CSLW_REQUIRED, FIB_CSW_REQUIRED, FIB_FC_LCB_BLOB_OFFSET, FIB_RG_LW_OFFSET, FIB_RG_LW_SIZE, FIB_RG_W_OFFSET, FIB_RG_W_SIZE, FIB_W_IDENT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FKP_PAGE_SIZE, FOOTNOTE_REFERENCE, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, NUMBER_FORMAT_BY_NFC, PARAGRAPH_MARK, PropertyBinTable, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SUMMARY_INFORMATION_STREAM, SYMBOL_ANCHOR, WORD_DOCUMENT_STREAM, applyCharacterSprms, applyParagraphSprms, applySectionSprms, buildChpxPages, buildEmptyStsh, buildFib, buildFontTable, buildPapxPages, buildPlcfSed, buildPropertyBinTable, buildSepx, buildTextClx, characterIstdFromGrpprl, characterOffset, characterSize, decodeSprm, encodeCharacterGrpprl, encodeParagraphGrpprl, encodeSectionGrpprl, endsParagraph, findLargestAtMost, firstFcOfPage, fitsAloneOnPapxPage, headingLevelFromIstd, isAnchorOnly, isDocBytes, layoutMetadataToSummaryInformation, operandSize, parseChpxFkp, parseClx, parseFib, parseFontTable, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readNumberingDefinitions, readSectionProperties, readTextRange, readUint16LE, readUint32LE, readUint8, resolveStyleFormatting, slice, tableStreamName, writeDocContent };
|
package/dist/prop/chp.cjs
CHANGED
|
@@ -76,5 +76,11 @@ function applyCharacterSprms(prls, into, fonts) {
|
|
|
76
76
|
}
|
|
77
77
|
return into;
|
|
78
78
|
}
|
|
79
|
+
function characterIstdFromGrpprl(prls) {
|
|
80
|
+
let istd;
|
|
81
|
+
for (const prl of prls) if (prl.sprm.sgc === require_prop_sprm.SGC.character && prl.sprm.value === SPRM_C_ISTD) istd = require_bytes.readUint16LE(prl.operand, 0);
|
|
82
|
+
return istd;
|
|
83
|
+
}
|
|
79
84
|
//#endregion
|
|
80
85
|
exports.applyCharacterSprms = applyCharacterSprms;
|
|
86
|
+
exports.characterIstdFromGrpprl = characterIstdFromGrpprl;
|
package/dist/prop/chp.d.cts
CHANGED
|
@@ -13,5 +13,6 @@ interface CharacterProperties {
|
|
|
13
13
|
istd?: number;
|
|
14
14
|
}
|
|
15
15
|
declare function applyCharacterSprms(prls: readonly Prl[], into: CharacterProperties, fonts?: readonly string[]): CharacterProperties;
|
|
16
|
+
declare function characterIstdFromGrpprl(prls: readonly Prl[]): number | undefined;
|
|
16
17
|
//#endregion
|
|
17
|
-
export { CharacterProperties, applyCharacterSprms };
|
|
18
|
+
export { CharacterProperties, applyCharacterSprms, characterIstdFromGrpprl };
|
package/dist/prop/chp.d.ts
CHANGED
|
@@ -13,5 +13,6 @@ interface CharacterProperties {
|
|
|
13
13
|
istd?: number;
|
|
14
14
|
}
|
|
15
15
|
declare function applyCharacterSprms(prls: readonly Prl[], into: CharacterProperties, fonts?: readonly string[]): CharacterProperties;
|
|
16
|
+
declare function characterIstdFromGrpprl(prls: readonly Prl[]): number | undefined;
|
|
16
17
|
//#endregion
|
|
17
|
-
export { CharacterProperties, applyCharacterSprms };
|
|
18
|
+
export { CharacterProperties, applyCharacterSprms, characterIstdFromGrpprl };
|
package/dist/prop/chp.js
CHANGED
|
@@ -75,5 +75,10 @@ function applyCharacterSprms(prls, into, fonts) {
|
|
|
75
75
|
}
|
|
76
76
|
return into;
|
|
77
77
|
}
|
|
78
|
+
function characterIstdFromGrpprl(prls) {
|
|
79
|
+
let istd;
|
|
80
|
+
for (const prl of prls) if (prl.sprm.sgc === SGC.character && prl.sprm.value === SPRM_C_ISTD) istd = readUint16LE(prl.operand, 0);
|
|
81
|
+
return istd;
|
|
82
|
+
}
|
|
78
83
|
//#endregion
|
|
79
|
-
export { applyCharacterSprms };
|
|
84
|
+
export { applyCharacterSprms, characterIstdFromGrpprl };
|
package/dist/read.cjs
CHANGED
|
@@ -105,12 +105,13 @@ function buildParagraph(text, fcs, propertyFc, terminator, context) {
|
|
|
105
105
|
const grpprl = papx !== void 0 ? require_prop_sprm.readGrpprl(papx.grpprl) : [];
|
|
106
106
|
if (papx !== void 0) {
|
|
107
107
|
properties.istd = papx.istd;
|
|
108
|
+
if (context.styles !== void 0) require_prop_pap.applyParagraphSprms(require_style_stsh.resolveStyleFormatting(context.styles, papx.istd).paragraphPrls, properties);
|
|
108
109
|
require_prop_pap.applyParagraphSprms(grpprl, properties);
|
|
109
110
|
}
|
|
110
111
|
return {
|
|
111
112
|
paragraph: {
|
|
112
113
|
kind: "paragraph",
|
|
113
|
-
runs: buildRuns(text, fcs, context),
|
|
114
|
+
runs: buildRuns(text, fcs, context, papx?.istd),
|
|
114
115
|
...paragraphAttributes(properties, context)
|
|
115
116
|
},
|
|
116
117
|
properties,
|
|
@@ -142,11 +143,12 @@ function paragraphAttributes(properties, context) {
|
|
|
142
143
|
};
|
|
143
144
|
return attributes;
|
|
144
145
|
}
|
|
145
|
-
function buildRuns(text, fcs, context) {
|
|
146
|
+
function buildRuns(text, fcs, context, paragraphIstd) {
|
|
146
147
|
const runs = [];
|
|
147
148
|
let currentKey;
|
|
148
149
|
let currentText = "";
|
|
149
150
|
let currentProperties = {};
|
|
151
|
+
const paragraphStyleCharacterPrls = context.styles !== void 0 && paragraphIstd !== void 0 ? require_style_stsh.resolveStyleFormatting(context.styles, paragraphIstd).characterPrls : [];
|
|
150
152
|
const enclosingInstruction = [];
|
|
151
153
|
let inInstruction = false;
|
|
152
154
|
const flush = () => {
|
|
@@ -176,14 +178,21 @@ function buildRuns(text, fcs, context) {
|
|
|
176
178
|
const fc = fcs[index];
|
|
177
179
|
if (fc === void 0) throw new require_errors.DocFormatError(`character ${index} of a paragraph has no byte offset, so its formatting cannot be located`);
|
|
178
180
|
const grpprl = context.chpxTable.chpxGrpprl(fc);
|
|
179
|
-
const
|
|
181
|
+
const chpxKey = grpprl === void 0 ? "none" : `${grpprl.byteOffset}:${grpprl.byteLength}`;
|
|
182
|
+
const key = `${paragraphIstd ?? "none"}:${chpxKey}`;
|
|
180
183
|
if (key !== currentKey) {
|
|
181
184
|
flush();
|
|
182
185
|
currentKey = key;
|
|
183
186
|
let properties = context.characterProperties.get(key);
|
|
184
187
|
if (properties === void 0) {
|
|
185
188
|
properties = {};
|
|
186
|
-
|
|
189
|
+
require_prop_chp.applyCharacterSprms(paragraphStyleCharacterPrls, properties, context.fonts);
|
|
190
|
+
if (grpprl !== void 0) {
|
|
191
|
+
const runPrls = require_prop_sprm.readGrpprl(grpprl);
|
|
192
|
+
const characterIstd = require_prop_chp.characterIstdFromGrpprl(runPrls);
|
|
193
|
+
if (characterIstd !== void 0 && context.styles !== void 0) require_prop_chp.applyCharacterSprms(require_style_stsh.resolveStyleFormatting(context.styles, characterIstd).characterPrls, properties, context.fonts);
|
|
194
|
+
require_prop_chp.applyCharacterSprms(runPrls, properties, context.fonts);
|
|
195
|
+
}
|
|
187
196
|
context.characterProperties.set(key, properties);
|
|
188
197
|
}
|
|
189
198
|
currentProperties = properties;
|
package/dist/read.js
CHANGED
|
@@ -7,10 +7,10 @@ import { readTextRange } from "./text/characters.js";
|
|
|
7
7
|
import { endsParagraph, isAnchorOnly } from "./text/special.js";
|
|
8
8
|
import { readGrpprl } from "./prop/sprm.js";
|
|
9
9
|
import { PropertyBinTable } from "./prop/fkp.js";
|
|
10
|
-
import { applyCharacterSprms } from "./prop/chp.js";
|
|
10
|
+
import { applyCharacterSprms, characterIstdFromGrpprl } from "./prop/chp.js";
|
|
11
11
|
import { applyParagraphSprms } from "./prop/pap.js";
|
|
12
12
|
import { readSectionProperties } from "./prop/sep.js";
|
|
13
|
-
import { headingLevelFromIstd, parseStsh } from "./style/stsh.js";
|
|
13
|
+
import { headingLevelFromIstd, parseStsh, resolveStyleFormatting } from "./style/stsh.js";
|
|
14
14
|
import { parseFontTable } from "./style/fonts.js";
|
|
15
15
|
import { readNumberingDefinitions } from "./list/numbering.js";
|
|
16
16
|
import { assembleBlocks } from "./table/read.js";
|
|
@@ -104,12 +104,13 @@ function buildParagraph(text, fcs, propertyFc, terminator, context) {
|
|
|
104
104
|
const grpprl = papx !== void 0 ? readGrpprl(papx.grpprl) : [];
|
|
105
105
|
if (papx !== void 0) {
|
|
106
106
|
properties.istd = papx.istd;
|
|
107
|
+
if (context.styles !== void 0) applyParagraphSprms(resolveStyleFormatting(context.styles, papx.istd).paragraphPrls, properties);
|
|
107
108
|
applyParagraphSprms(grpprl, properties);
|
|
108
109
|
}
|
|
109
110
|
return {
|
|
110
111
|
paragraph: {
|
|
111
112
|
kind: "paragraph",
|
|
112
|
-
runs: buildRuns(text, fcs, context),
|
|
113
|
+
runs: buildRuns(text, fcs, context, papx?.istd),
|
|
113
114
|
...paragraphAttributes(properties, context)
|
|
114
115
|
},
|
|
115
116
|
properties,
|
|
@@ -141,11 +142,12 @@ function paragraphAttributes(properties, context) {
|
|
|
141
142
|
};
|
|
142
143
|
return attributes;
|
|
143
144
|
}
|
|
144
|
-
function buildRuns(text, fcs, context) {
|
|
145
|
+
function buildRuns(text, fcs, context, paragraphIstd) {
|
|
145
146
|
const runs = [];
|
|
146
147
|
let currentKey;
|
|
147
148
|
let currentText = "";
|
|
148
149
|
let currentProperties = {};
|
|
150
|
+
const paragraphStyleCharacterPrls = context.styles !== void 0 && paragraphIstd !== void 0 ? resolveStyleFormatting(context.styles, paragraphIstd).characterPrls : [];
|
|
149
151
|
const enclosingInstruction = [];
|
|
150
152
|
let inInstruction = false;
|
|
151
153
|
const flush = () => {
|
|
@@ -175,14 +177,21 @@ function buildRuns(text, fcs, context) {
|
|
|
175
177
|
const fc = fcs[index];
|
|
176
178
|
if (fc === void 0) throw new DocFormatError(`character ${index} of a paragraph has no byte offset, so its formatting cannot be located`);
|
|
177
179
|
const grpprl = context.chpxTable.chpxGrpprl(fc);
|
|
178
|
-
const
|
|
180
|
+
const chpxKey = grpprl === void 0 ? "none" : `${grpprl.byteOffset}:${grpprl.byteLength}`;
|
|
181
|
+
const key = `${paragraphIstd ?? "none"}:${chpxKey}`;
|
|
179
182
|
if (key !== currentKey) {
|
|
180
183
|
flush();
|
|
181
184
|
currentKey = key;
|
|
182
185
|
let properties = context.characterProperties.get(key);
|
|
183
186
|
if (properties === void 0) {
|
|
184
187
|
properties = {};
|
|
185
|
-
|
|
188
|
+
applyCharacterSprms(paragraphStyleCharacterPrls, properties, context.fonts);
|
|
189
|
+
if (grpprl !== void 0) {
|
|
190
|
+
const runPrls = readGrpprl(grpprl);
|
|
191
|
+
const characterIstd = characterIstdFromGrpprl(runPrls);
|
|
192
|
+
if (characterIstd !== void 0 && context.styles !== void 0) applyCharacterSprms(resolveStyleFormatting(context.styles, characterIstd).characterPrls, properties, context.fonts);
|
|
193
|
+
applyCharacterSprms(runPrls, properties, context.fonts);
|
|
194
|
+
}
|
|
186
195
|
context.characterProperties.set(key, properties);
|
|
187
196
|
}
|
|
188
197
|
currentProperties = properties;
|
package/dist/style/stsh.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_errors = require("../errors.cjs");
|
|
3
3
|
const require_bytes = require("../bytes.cjs");
|
|
4
|
+
const require_prop_sprm = require("../prop/sprm.cjs");
|
|
4
5
|
//#region src/style/stsh.ts
|
|
5
6
|
/** Stshif is a fixed 18 bytes: cstd, cbSTDBaseInFile, a bit field, stiMaxWhenSaved, istdMaxFixedWhenSaved, nVerBuiltInNamesWhenSaved, and the three default font indexes. */
|
|
6
7
|
const STSHIF_SIZE = 18;
|
|
@@ -40,12 +41,17 @@ function parseStd(std, istd, cbStdBaseInFile) {
|
|
|
40
41
|
const word0 = require_bytes.readUint16LE(std, 0);
|
|
41
42
|
const word1 = require_bytes.readUint16LE(std, 2);
|
|
42
43
|
const istdBase = word1 >> 4 & 4095;
|
|
44
|
+
const stk = word1 & 15;
|
|
45
|
+
const name = readXstz(std, cbStdBaseInFile, `name of the style at istd ${istd}`);
|
|
46
|
+
const { grpprlPapx, grpprlChpx } = parseGrLPUpxSw(std, cbStdBaseInFile + xstzByteLength(std, cbStdBaseInFile), stk, istd);
|
|
43
47
|
return {
|
|
44
48
|
istd,
|
|
45
49
|
sti: word0 & 4095,
|
|
46
|
-
stk
|
|
50
|
+
stk,
|
|
47
51
|
istdBase: istdBase === ISTD_BASE_NONE ? void 0 : istdBase,
|
|
48
|
-
name
|
|
52
|
+
name,
|
|
53
|
+
grpprlPapx,
|
|
54
|
+
grpprlChpx
|
|
49
55
|
};
|
|
50
56
|
}
|
|
51
57
|
function readXstz(bytes, offset, what) {
|
|
@@ -55,6 +61,61 @@ function readXstz(bytes, offset, what) {
|
|
|
55
61
|
for (let index = 0; index < cch; index += 1) out += String.fromCharCode(require_bytes.readUint16LE(chars, index * 2));
|
|
56
62
|
return out;
|
|
57
63
|
}
|
|
64
|
+
function xstzByteLength(bytes, offset) {
|
|
65
|
+
return 2 + require_bytes.readUint16LE(bytes, offset) * 2 + 2;
|
|
66
|
+
}
|
|
67
|
+
function readLpUpx(std, offset, what) {
|
|
68
|
+
const cbUpx = require_bytes.readUint16LE(std, offset);
|
|
69
|
+
return {
|
|
70
|
+
upx: require_bytes.slice(std, offset + 2, cbUpx, what),
|
|
71
|
+
next: offset + 2 + cbUpx + cbUpx % 2
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function parseGrLPUpxSw(std, offset, stk, istd) {
|
|
75
|
+
if (stk === STK.paragraph) {
|
|
76
|
+
const papx = readLpUpx(std, offset, `UpxPapx for the paragraph style at istd ${istd}`);
|
|
77
|
+
const chpx = readLpUpx(std, papx.next, `UpxChpx for the paragraph style at istd ${istd}`);
|
|
78
|
+
const grpprlPapxBytes = require_bytes.slice(papx.upx, 2, papx.upx.length - 2, `grpprlPapx for the paragraph style at istd ${istd}`);
|
|
79
|
+
return {
|
|
80
|
+
grpprlPapx: require_prop_sprm.readGrpprl(grpprlPapxBytes),
|
|
81
|
+
grpprlChpx: require_prop_sprm.readGrpprl(chpx.upx)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (stk === STK.character) {
|
|
85
|
+
const chpx = readLpUpx(std, offset, `UpxChpx for the character style at istd ${istd}`);
|
|
86
|
+
return {
|
|
87
|
+
grpprlPapx: void 0,
|
|
88
|
+
grpprlChpx: require_prop_sprm.readGrpprl(chpx.upx)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
grpprlPapx: void 0,
|
|
93
|
+
grpprlChpx: void 0
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function resolveStyleFormatting(styleSheet, istd) {
|
|
97
|
+
const chain = [];
|
|
98
|
+
const seen = /* @__PURE__ */ new Set();
|
|
99
|
+
let current = styleSheet.styles[istd];
|
|
100
|
+
while (current !== void 0) {
|
|
101
|
+
if (seen.has(current.istd)) throw new require_errors.DocFormatError(`style inheritance chain starting at istd ${istd} loops back to istd ${current.istd}, which [MS-DOC] 2.9.260's own istdBase rule forbids`);
|
|
102
|
+
seen.add(current.istd);
|
|
103
|
+
chain.push(current);
|
|
104
|
+
current = current.istdBase === void 0 ? void 0 : styleSheet.styles[current.istdBase];
|
|
105
|
+
}
|
|
106
|
+
const paragraphPrls = [];
|
|
107
|
+
const characterPrls = [];
|
|
108
|
+
for (let index = chain.length - 1; index >= 0; index -= 1) {
|
|
109
|
+
const style = chain[index];
|
|
110
|
+
if (style === void 0) continue;
|
|
111
|
+
if (style.grpprlPapx !== void 0) paragraphPrls.push(...style.grpprlPapx);
|
|
112
|
+
if (style.grpprlChpx !== void 0) characterPrls.push(...style.grpprlChpx);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
paragraphPrls,
|
|
116
|
+
characterPrls
|
|
117
|
+
};
|
|
118
|
+
}
|
|
58
119
|
function headingLevelFromIstd(istd) {
|
|
59
120
|
return istd >= 1 && istd <= 9 ? istd : void 0;
|
|
60
121
|
}
|
|
@@ -86,3 +147,4 @@ exports.STK = STK;
|
|
|
86
147
|
exports.buildEmptyStsh = buildEmptyStsh;
|
|
87
148
|
exports.headingLevelFromIstd = headingLevelFromIstd;
|
|
88
149
|
exports.parseStsh = parseStsh;
|
|
150
|
+
exports.resolveStyleFormatting = resolveStyleFormatting;
|
package/dist/style/stsh.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as Prl } from "../sprm-DEyvdOo0.cjs";
|
|
1
2
|
//#region src/style/stsh.d.ts
|
|
2
3
|
/** StdfBase.sti's "0x0FFE for user-defined styles"; anything else is an application-defined style whose sti identifies it. */
|
|
3
4
|
declare const STI_USER_DEFINED = 4094;
|
|
@@ -18,13 +19,22 @@ interface Style {
|
|
|
18
19
|
readonly istdBase: number | undefined;
|
|
19
20
|
/** The style's primary name, from the STD's own Xstz. */
|
|
20
21
|
readonly name: string;
|
|
22
|
+
/** The style's own paragraph formatting -- StkParaGRLPUPX's lpUpxPapx.PAPX.grpprlPapx -- present only for a paragraph style (STK.paragraph). Undefined for every other stk: table and numbering styles carry their own formatting shapes this package does not read (see the README's own scope note). */
|
|
23
|
+
readonly grpprlPapx: readonly Prl[] | undefined;
|
|
24
|
+
/** The style's own character formatting -- a paragraph style's StkParaGRLPUPX.lpUpxChpx.CHPX.grpprlChpx (the run-level defaults a heading's own text falls back to) or a character style's StkCharGRLPUPX.lpUpxChpx.CHPX.grpprlChpx -- present for STK.paragraph and STK.character, undefined otherwise. */
|
|
25
|
+
readonly grpprlChpx: readonly Prl[] | undefined;
|
|
21
26
|
}
|
|
22
27
|
interface StyleSheet {
|
|
23
28
|
/** Indexed by istd; a hole is a slot [MS-DOC] permits to be empty ("A style definition can be empty, in which case cbStd MUST be 0"). */
|
|
24
29
|
readonly styles: readonly (Style | undefined)[];
|
|
25
30
|
}
|
|
26
31
|
declare function parseStsh(stsh: Uint8Array): StyleSheet;
|
|
32
|
+
interface ResolvedStyleFormatting {
|
|
33
|
+
readonly paragraphPrls: readonly Prl[];
|
|
34
|
+
readonly characterPrls: readonly Prl[];
|
|
35
|
+
}
|
|
36
|
+
declare function resolveStyleFormatting(styleSheet: StyleSheet, istd: number): ResolvedStyleFormatting;
|
|
27
37
|
declare function headingLevelFromIstd(istd: number): number | undefined;
|
|
28
38
|
declare function buildEmptyStsh(): Uint8Array;
|
|
29
39
|
//#endregion
|
|
30
|
-
export { STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh };
|
|
40
|
+
export { ResolvedStyleFormatting, STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh, resolveStyleFormatting };
|
package/dist/style/stsh.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as Prl } from "../sprm-DEyvdOo0.js";
|
|
1
2
|
//#region src/style/stsh.d.ts
|
|
2
3
|
/** StdfBase.sti's "0x0FFE for user-defined styles"; anything else is an application-defined style whose sti identifies it. */
|
|
3
4
|
declare const STI_USER_DEFINED = 4094;
|
|
@@ -18,13 +19,22 @@ interface Style {
|
|
|
18
19
|
readonly istdBase: number | undefined;
|
|
19
20
|
/** The style's primary name, from the STD's own Xstz. */
|
|
20
21
|
readonly name: string;
|
|
22
|
+
/** The style's own paragraph formatting -- StkParaGRLPUPX's lpUpxPapx.PAPX.grpprlPapx -- present only for a paragraph style (STK.paragraph). Undefined for every other stk: table and numbering styles carry their own formatting shapes this package does not read (see the README's own scope note). */
|
|
23
|
+
readonly grpprlPapx: readonly Prl[] | undefined;
|
|
24
|
+
/** The style's own character formatting -- a paragraph style's StkParaGRLPUPX.lpUpxChpx.CHPX.grpprlChpx (the run-level defaults a heading's own text falls back to) or a character style's StkCharGRLPUPX.lpUpxChpx.CHPX.grpprlChpx -- present for STK.paragraph and STK.character, undefined otherwise. */
|
|
25
|
+
readonly grpprlChpx: readonly Prl[] | undefined;
|
|
21
26
|
}
|
|
22
27
|
interface StyleSheet {
|
|
23
28
|
/** Indexed by istd; a hole is a slot [MS-DOC] permits to be empty ("A style definition can be empty, in which case cbStd MUST be 0"). */
|
|
24
29
|
readonly styles: readonly (Style | undefined)[];
|
|
25
30
|
}
|
|
26
31
|
declare function parseStsh(stsh: Uint8Array): StyleSheet;
|
|
32
|
+
interface ResolvedStyleFormatting {
|
|
33
|
+
readonly paragraphPrls: readonly Prl[];
|
|
34
|
+
readonly characterPrls: readonly Prl[];
|
|
35
|
+
}
|
|
36
|
+
declare function resolveStyleFormatting(styleSheet: StyleSheet, istd: number): ResolvedStyleFormatting;
|
|
27
37
|
declare function headingLevelFromIstd(istd: number): number | undefined;
|
|
28
38
|
declare function buildEmptyStsh(): Uint8Array;
|
|
29
39
|
//#endregion
|
|
30
|
-
export { STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh };
|
|
40
|
+
export { ResolvedStyleFormatting, STI_USER_DEFINED, STK, Style, StyleSheet, buildEmptyStsh, headingLevelFromIstd, parseStsh, resolveStyleFormatting };
|
package/dist/style/stsh.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DocFormatError } from "../errors.js";
|
|
2
2
|
import { readInt16LE, readUint16LE, slice } from "../bytes.js";
|
|
3
|
+
import { readGrpprl } from "../prop/sprm.js";
|
|
3
4
|
//#region src/style/stsh.ts
|
|
4
5
|
/** Stshif is a fixed 18 bytes: cstd, cbSTDBaseInFile, a bit field, stiMaxWhenSaved, istdMaxFixedWhenSaved, nVerBuiltInNamesWhenSaved, and the three default font indexes. */
|
|
5
6
|
const STSHIF_SIZE = 18;
|
|
@@ -39,12 +40,17 @@ function parseStd(std, istd, cbStdBaseInFile) {
|
|
|
39
40
|
const word0 = readUint16LE(std, 0);
|
|
40
41
|
const word1 = readUint16LE(std, 2);
|
|
41
42
|
const istdBase = word1 >> 4 & 4095;
|
|
43
|
+
const stk = word1 & 15;
|
|
44
|
+
const name = readXstz(std, cbStdBaseInFile, `name of the style at istd ${istd}`);
|
|
45
|
+
const { grpprlPapx, grpprlChpx } = parseGrLPUpxSw(std, cbStdBaseInFile + xstzByteLength(std, cbStdBaseInFile), stk, istd);
|
|
42
46
|
return {
|
|
43
47
|
istd,
|
|
44
48
|
sti: word0 & 4095,
|
|
45
|
-
stk
|
|
49
|
+
stk,
|
|
46
50
|
istdBase: istdBase === ISTD_BASE_NONE ? void 0 : istdBase,
|
|
47
|
-
name
|
|
51
|
+
name,
|
|
52
|
+
grpprlPapx,
|
|
53
|
+
grpprlChpx
|
|
48
54
|
};
|
|
49
55
|
}
|
|
50
56
|
function readXstz(bytes, offset, what) {
|
|
@@ -54,6 +60,61 @@ function readXstz(bytes, offset, what) {
|
|
|
54
60
|
for (let index = 0; index < cch; index += 1) out += String.fromCharCode(readUint16LE(chars, index * 2));
|
|
55
61
|
return out;
|
|
56
62
|
}
|
|
63
|
+
function xstzByteLength(bytes, offset) {
|
|
64
|
+
return 2 + readUint16LE(bytes, offset) * 2 + 2;
|
|
65
|
+
}
|
|
66
|
+
function readLpUpx(std, offset, what) {
|
|
67
|
+
const cbUpx = readUint16LE(std, offset);
|
|
68
|
+
return {
|
|
69
|
+
upx: slice(std, offset + 2, cbUpx, what),
|
|
70
|
+
next: offset + 2 + cbUpx + cbUpx % 2
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function parseGrLPUpxSw(std, offset, stk, istd) {
|
|
74
|
+
if (stk === STK.paragraph) {
|
|
75
|
+
const papx = readLpUpx(std, offset, `UpxPapx for the paragraph style at istd ${istd}`);
|
|
76
|
+
const chpx = readLpUpx(std, papx.next, `UpxChpx for the paragraph style at istd ${istd}`);
|
|
77
|
+
const grpprlPapxBytes = slice(papx.upx, 2, papx.upx.length - 2, `grpprlPapx for the paragraph style at istd ${istd}`);
|
|
78
|
+
return {
|
|
79
|
+
grpprlPapx: readGrpprl(grpprlPapxBytes),
|
|
80
|
+
grpprlChpx: readGrpprl(chpx.upx)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (stk === STK.character) {
|
|
84
|
+
const chpx = readLpUpx(std, offset, `UpxChpx for the character style at istd ${istd}`);
|
|
85
|
+
return {
|
|
86
|
+
grpprlPapx: void 0,
|
|
87
|
+
grpprlChpx: readGrpprl(chpx.upx)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
grpprlPapx: void 0,
|
|
92
|
+
grpprlChpx: void 0
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function resolveStyleFormatting(styleSheet, istd) {
|
|
96
|
+
const chain = [];
|
|
97
|
+
const seen = /* @__PURE__ */ new Set();
|
|
98
|
+
let current = styleSheet.styles[istd];
|
|
99
|
+
while (current !== void 0) {
|
|
100
|
+
if (seen.has(current.istd)) throw new DocFormatError(`style inheritance chain starting at istd ${istd} loops back to istd ${current.istd}, which [MS-DOC] 2.9.260's own istdBase rule forbids`);
|
|
101
|
+
seen.add(current.istd);
|
|
102
|
+
chain.push(current);
|
|
103
|
+
current = current.istdBase === void 0 ? void 0 : styleSheet.styles[current.istdBase];
|
|
104
|
+
}
|
|
105
|
+
const paragraphPrls = [];
|
|
106
|
+
const characterPrls = [];
|
|
107
|
+
for (let index = chain.length - 1; index >= 0; index -= 1) {
|
|
108
|
+
const style = chain[index];
|
|
109
|
+
if (style === void 0) continue;
|
|
110
|
+
if (style.grpprlPapx !== void 0) paragraphPrls.push(...style.grpprlPapx);
|
|
111
|
+
if (style.grpprlChpx !== void 0) characterPrls.push(...style.grpprlChpx);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
paragraphPrls,
|
|
115
|
+
characterPrls
|
|
116
|
+
};
|
|
117
|
+
}
|
|
57
118
|
function headingLevelFromIstd(istd) {
|
|
58
119
|
return istd >= 1 && istd <= 9 ? istd : void 0;
|
|
59
120
|
}
|
|
@@ -80,4 +141,4 @@ function buildEmptyStsh() {
|
|
|
80
141
|
]);
|
|
81
142
|
}
|
|
82
143
|
//#endregion
|
|
83
|
-
export { STI_USER_DEFINED, STK, buildEmptyStsh, headingLevelFromIstd, parseStsh };
|
|
144
|
+
export { STI_USER_DEFINED, STK, buildEmptyStsh, headingLevelFromIstd, parseStsh, resolveStyleFormatting };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doc-codec",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "A hand-written reader for the Word Binary File Format ([MS-DOC], .doc) against the shared document-schema.js content pivot: FIB parsing, piece-table text reconstruction, and CHPX/PAPX formatting exceptions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|