doc-codec 0.0.0 → 1.0.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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +148 -0
  3. package/dist/bytes.cjs +44 -0
  4. package/dist/bytes.d.cts +9 -0
  5. package/dist/bytes.d.ts +9 -0
  6. package/dist/bytes.js +38 -0
  7. package/dist/detect.cjs +22 -0
  8. package/dist/detect.d.cts +6 -0
  9. package/dist/detect.d.ts +6 -0
  10. package/dist/detect.js +20 -0
  11. package/dist/errors.cjs +17 -0
  12. package/dist/errors.d.cts +9 -0
  13. package/dist/errors.d.ts +9 -0
  14. package/dist/errors.js +15 -0
  15. package/dist/fib/fib.cjs +50 -0
  16. package/dist/fib/fib.d.cts +29 -0
  17. package/dist/fib/fib.d.ts +29 -0
  18. package/dist/fib/fib.js +48 -0
  19. package/dist/fib/offsets.cjs +61 -0
  20. package/dist/fib/offsets.d.cts +47 -0
  21. package/dist/fib/offsets.d.ts +47 -0
  22. package/dist/fib/offsets.js +47 -0
  23. package/dist/index.cjs +79 -0
  24. package/dist/index.d.cts +16 -0
  25. package/dist/index.d.ts +16 -0
  26. package/dist/index.js +16 -0
  27. package/dist/plc.cjs +44 -0
  28. package/dist/plc.d.cts +12 -0
  29. package/dist/plc.d.ts +12 -0
  30. package/dist/plc.js +42 -0
  31. package/dist/prop/chp.cjs +172 -0
  32. package/dist/prop/chp.d.cts +16 -0
  33. package/dist/prop/chp.d.ts +16 -0
  34. package/dist/prop/chp.js +171 -0
  35. package/dist/prop/fkp.cjs +141 -0
  36. package/dist/prop/fkp.d.cts +33 -0
  37. package/dist/prop/fkp.d.ts +33 -0
  38. package/dist/prop/fkp.js +137 -0
  39. package/dist/prop/pap.cjs +134 -0
  40. package/dist/prop/pap.d.cts +25 -0
  41. package/dist/prop/pap.d.ts +25 -0
  42. package/dist/prop/pap.js +133 -0
  43. package/dist/prop/sprm.cjs +68 -0
  44. package/dist/prop/sprm.d.cts +26 -0
  45. package/dist/prop/sprm.d.ts +26 -0
  46. package/dist/prop/sprm.js +64 -0
  47. package/dist/read.cjs +171 -0
  48. package/dist/read.d.cts +12 -0
  49. package/dist/read.d.ts +12 -0
  50. package/dist/read.js +169 -0
  51. package/dist/style/stsh.cjs +65 -0
  52. package/dist/style/stsh.d.cts +29 -0
  53. package/dist/style/stsh.d.ts +29 -0
  54. package/dist/style/stsh.js +61 -0
  55. package/dist/text/characters.cjs +69 -0
  56. package/dist/text/characters.d.cts +14 -0
  57. package/dist/text/characters.d.ts +14 -0
  58. package/dist/text/characters.js +67 -0
  59. package/dist/text/piece-table.cjs +68 -0
  60. package/dist/text/piece-table.d.cts +28 -0
  61. package/dist/text/piece-table.d.ts +28 -0
  62. package/dist/text/piece-table.js +65 -0
  63. package/dist/text/special.cjs +48 -0
  64. package/dist/text/special.d.cts +30 -0
  65. package/dist/text/special.d.ts +30 -0
  66. package/dist/text/special.js +34 -0
  67. package/package.json +93 -2
@@ -0,0 +1,47 @@
1
+ //#region src/fib/offsets.d.ts
2
+ /** FibBase, [MS-DOC] 2.5.2 -- the fixed 32-byte head of every Fib. csw, the count of 16-bit values in FibRgW97, sits immediately after it, so this doubles as csw's own offset. */
3
+ declare const FIB_BASE_SIZE = 32;
4
+ /** csw MUST be 0x000E, fixing FibRgW97 at 28 bytes and every offset after it. */
5
+ declare const FIB_CSW_REQUIRED = 14;
6
+ /** FibRgW97, [MS-DOC] 2.5.3 -- 14 16-bit values, none of which this reader needs. */
7
+ declare const FIB_RG_W_OFFSET: number;
8
+ declare const FIB_RG_W_SIZE: number;
9
+ /** cslw, the count of 32-bit values in FibRgLw97. MUST be 0x0016. */
10
+ declare const FIB_CSLW_OFFSET: number;
11
+ declare const FIB_CSLW_REQUIRED = 22;
12
+ /** FibRgLw97, [MS-DOC] 2.5.4 -- 22 32-bit values holding cbMac and the per-subdocument CP counts. */
13
+ declare const FIB_RG_LW_OFFSET: number;
14
+ declare const FIB_RG_LW_SIZE: number;
15
+ /** cbRgFcLcb, the count of 64-bit values in FibRgFcLcbBlob. Varies by nFib (0x005D for 0x00C1 through 0x00B7 for 0x0112), so it is read rather than assumed. */
16
+ declare const FIB_CB_RG_FC_LCB_OFFSET: number;
17
+ /** FibRgFcLcb97, [MS-DOC] 2.5.5 -- the flat array of paired file offsets and lengths locating every other structure in the Table stream. */
18
+ declare const FIB_FC_LCB_BLOB_OFFSET: number;
19
+ declare const LW_OFFSET: {
20
+ readonly cbMac: 0;
21
+ readonly ccpText: 12;
22
+ readonly ccpFtn: 16;
23
+ readonly ccpHdd: 20;
24
+ readonly ccpAtn: 28;
25
+ readonly ccpEdn: 32;
26
+ readonly ccpTxbx: 36;
27
+ readonly ccpHdrTxbx: 40;
28
+ };
29
+ declare const FC_LCB_VALUE_INDEX: {
30
+ readonly fcStshf: 2;
31
+ readonly lcbStshf: 3;
32
+ readonly fcPlcfBteChpx: 24;
33
+ readonly lcbPlcfBteChpx: 25;
34
+ readonly fcPlcfBtePapx: 26;
35
+ readonly lcbPlcfBtePapx: 27;
36
+ readonly fcClx: 66;
37
+ readonly lcbClx: 67;
38
+ };
39
+ declare const FIB_BASE_FLAG: {
40
+ readonly fComplex: 4;
41
+ readonly fEncrypted: 256;
42
+ readonly fWhichTblStm: 512;
43
+ readonly fObfuscated: 32768;
44
+ };
45
+ declare const FIB_W_IDENT = 42476;
46
+ //#endregion
47
+ export { 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, LW_OFFSET };
@@ -0,0 +1,47 @@
1
+ //#region src/fib/offsets.d.ts
2
+ /** FibBase, [MS-DOC] 2.5.2 -- the fixed 32-byte head of every Fib. csw, the count of 16-bit values in FibRgW97, sits immediately after it, so this doubles as csw's own offset. */
3
+ declare const FIB_BASE_SIZE = 32;
4
+ /** csw MUST be 0x000E, fixing FibRgW97 at 28 bytes and every offset after it. */
5
+ declare const FIB_CSW_REQUIRED = 14;
6
+ /** FibRgW97, [MS-DOC] 2.5.3 -- 14 16-bit values, none of which this reader needs. */
7
+ declare const FIB_RG_W_OFFSET: number;
8
+ declare const FIB_RG_W_SIZE: number;
9
+ /** cslw, the count of 32-bit values in FibRgLw97. MUST be 0x0016. */
10
+ declare const FIB_CSLW_OFFSET: number;
11
+ declare const FIB_CSLW_REQUIRED = 22;
12
+ /** FibRgLw97, [MS-DOC] 2.5.4 -- 22 32-bit values holding cbMac and the per-subdocument CP counts. */
13
+ declare const FIB_RG_LW_OFFSET: number;
14
+ declare const FIB_RG_LW_SIZE: number;
15
+ /** cbRgFcLcb, the count of 64-bit values in FibRgFcLcbBlob. Varies by nFib (0x005D for 0x00C1 through 0x00B7 for 0x0112), so it is read rather than assumed. */
16
+ declare const FIB_CB_RG_FC_LCB_OFFSET: number;
17
+ /** FibRgFcLcb97, [MS-DOC] 2.5.5 -- the flat array of paired file offsets and lengths locating every other structure in the Table stream. */
18
+ declare const FIB_FC_LCB_BLOB_OFFSET: number;
19
+ declare const LW_OFFSET: {
20
+ readonly cbMac: 0;
21
+ readonly ccpText: 12;
22
+ readonly ccpFtn: 16;
23
+ readonly ccpHdd: 20;
24
+ readonly ccpAtn: 28;
25
+ readonly ccpEdn: 32;
26
+ readonly ccpTxbx: 36;
27
+ readonly ccpHdrTxbx: 40;
28
+ };
29
+ declare const FC_LCB_VALUE_INDEX: {
30
+ readonly fcStshf: 2;
31
+ readonly lcbStshf: 3;
32
+ readonly fcPlcfBteChpx: 24;
33
+ readonly lcbPlcfBteChpx: 25;
34
+ readonly fcPlcfBtePapx: 26;
35
+ readonly lcbPlcfBtePapx: 27;
36
+ readonly fcClx: 66;
37
+ readonly lcbClx: 67;
38
+ };
39
+ declare const FIB_BASE_FLAG: {
40
+ readonly fComplex: 4;
41
+ readonly fEncrypted: 256;
42
+ readonly fWhichTblStm: 512;
43
+ readonly fObfuscated: 32768;
44
+ };
45
+ declare const FIB_W_IDENT = 42476;
46
+ //#endregion
47
+ export { 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, LW_OFFSET };
@@ -0,0 +1,47 @@
1
+ //#region src/fib/offsets.ts
2
+ /** FibBase, [MS-DOC] 2.5.2 -- the fixed 32-byte head of every Fib. csw, the count of 16-bit values in FibRgW97, sits immediately after it, so this doubles as csw's own offset. */
3
+ const FIB_BASE_SIZE = 32;
4
+ /** csw MUST be 0x000E, fixing FibRgW97 at 28 bytes and every offset after it. */
5
+ const FIB_CSW_REQUIRED = 14;
6
+ /** FibRgW97, [MS-DOC] 2.5.3 -- 14 16-bit values, none of which this reader needs. */
7
+ const FIB_RG_W_OFFSET = 34;
8
+ const FIB_RG_W_SIZE = 28;
9
+ /** cslw, the count of 32-bit values in FibRgLw97. MUST be 0x0016. */
10
+ const FIB_CSLW_OFFSET = 62;
11
+ const FIB_CSLW_REQUIRED = 22;
12
+ /** FibRgLw97, [MS-DOC] 2.5.4 -- 22 32-bit values holding cbMac and the per-subdocument CP counts. */
13
+ const FIB_RG_LW_OFFSET = 64;
14
+ const FIB_RG_LW_SIZE = 88;
15
+ /** cbRgFcLcb, the count of 64-bit values in FibRgFcLcbBlob. Varies by nFib (0x005D for 0x00C1 through 0x00B7 for 0x0112), so it is read rather than assumed. */
16
+ const FIB_CB_RG_FC_LCB_OFFSET = 152;
17
+ /** FibRgFcLcb97, [MS-DOC] 2.5.5 -- the flat array of paired file offsets and lengths locating every other structure in the Table stream. */
18
+ const FIB_FC_LCB_BLOB_OFFSET = 154;
19
+ const LW_OFFSET = {
20
+ cbMac: 0,
21
+ ccpText: 12,
22
+ ccpFtn: 16,
23
+ ccpHdd: 20,
24
+ ccpAtn: 28,
25
+ ccpEdn: 32,
26
+ ccpTxbx: 36,
27
+ ccpHdrTxbx: 40
28
+ };
29
+ const FC_LCB_VALUE_INDEX = {
30
+ fcStshf: 2,
31
+ lcbStshf: 3,
32
+ fcPlcfBteChpx: 24,
33
+ lcbPlcfBteChpx: 25,
34
+ fcPlcfBtePapx: 26,
35
+ lcbPlcfBtePapx: 27,
36
+ fcClx: 66,
37
+ lcbClx: 67
38
+ };
39
+ const FIB_BASE_FLAG = {
40
+ fComplex: 4,
41
+ fEncrypted: 256,
42
+ fWhichTblStm: 512,
43
+ fObfuscated: 32768
44
+ };
45
+ const FIB_W_IDENT = 42476;
46
+ //#endregion
47
+ export { 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, LW_OFFSET };
package/dist/index.cjs ADDED
@@ -0,0 +1,79 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("./errors.cjs");
3
+ const require_bytes = require("./bytes.cjs");
4
+ const require_fib_offsets = require("./fib/offsets.cjs");
5
+ const require_detect = require("./detect.cjs");
6
+ const require_plc = require("./plc.cjs");
7
+ const require_fib_fib = require("./fib/fib.cjs");
8
+ const require_text_piece_table = require("./text/piece-table.cjs");
9
+ const require_text_characters = require("./text/characters.cjs");
10
+ const require_text_special = require("./text/special.cjs");
11
+ const require_prop_sprm = require("./prop/sprm.cjs");
12
+ const require_prop_fkp = require("./prop/fkp.cjs");
13
+ const require_prop_chp = require("./prop/chp.cjs");
14
+ const require_prop_pap = require("./prop/pap.cjs");
15
+ const require_style_stsh = require("./style/stsh.cjs");
16
+ const require_read = require("./read.cjs");
17
+ exports.ANNOTATION_REFERENCE = require_text_special.ANNOTATION_REFERENCE;
18
+ exports.CELL_MARK = require_text_special.CELL_MARK;
19
+ exports.COMPRESSED_CHARACTER_MAP = require_text_characters.COMPRESSED_CHARACTER_MAP;
20
+ exports.DRAWN_OBJECT = require_text_special.DRAWN_OBJECT;
21
+ exports.DocFormatError = require_errors.DocFormatError;
22
+ exports.DocUnsupportedError = require_errors.DocUnsupportedError;
23
+ exports.FC_LCB_VALUE_INDEX = require_fib_offsets.FC_LCB_VALUE_INDEX;
24
+ exports.FIB_BASE_FLAG = require_fib_offsets.FIB_BASE_FLAG;
25
+ exports.FIB_BASE_SIZE = require_fib_offsets.FIB_BASE_SIZE;
26
+ exports.FIB_CB_RG_FC_LCB_OFFSET = require_fib_offsets.FIB_CB_RG_FC_LCB_OFFSET;
27
+ exports.FIB_CSLW_OFFSET = require_fib_offsets.FIB_CSLW_OFFSET;
28
+ exports.FIB_CSLW_REQUIRED = require_fib_offsets.FIB_CSLW_REQUIRED;
29
+ exports.FIB_CSW_REQUIRED = require_fib_offsets.FIB_CSW_REQUIRED;
30
+ exports.FIB_FC_LCB_BLOB_OFFSET = require_fib_offsets.FIB_FC_LCB_BLOB_OFFSET;
31
+ exports.FIB_RG_LW_OFFSET = require_fib_offsets.FIB_RG_LW_OFFSET;
32
+ exports.FIB_RG_LW_SIZE = require_fib_offsets.FIB_RG_LW_SIZE;
33
+ exports.FIB_RG_W_OFFSET = require_fib_offsets.FIB_RG_W_OFFSET;
34
+ exports.FIB_RG_W_SIZE = require_fib_offsets.FIB_RG_W_SIZE;
35
+ exports.FIB_W_IDENT = require_fib_offsets.FIB_W_IDENT;
36
+ exports.FIELD_BEGIN = require_text_special.FIELD_BEGIN;
37
+ exports.FIELD_END = require_text_special.FIELD_END;
38
+ exports.FIELD_SEPARATOR = require_text_special.FIELD_SEPARATOR;
39
+ exports.FKP_PAGE_SIZE = require_prop_fkp.FKP_PAGE_SIZE;
40
+ exports.FOOTNOTE_REFERENCE = require_text_special.FOOTNOTE_REFERENCE;
41
+ exports.INLINE_PICTURE = require_text_special.INLINE_PICTURE;
42
+ exports.LINE_BREAK = require_text_special.LINE_BREAK;
43
+ exports.LW_OFFSET = require_fib_offsets.LW_OFFSET;
44
+ exports.PARAGRAPH_MARK = require_text_special.PARAGRAPH_MARK;
45
+ exports.PropertyBinTable = require_prop_fkp.PropertyBinTable;
46
+ exports.SECTION_MARK = require_text_special.SECTION_MARK;
47
+ exports.SGC = require_prop_sprm.SGC;
48
+ exports.STI_USER_DEFINED = require_style_stsh.STI_USER_DEFINED;
49
+ exports.STK = require_style_stsh.STK;
50
+ exports.SYMBOL_ANCHOR = require_text_special.SYMBOL_ANCHOR;
51
+ exports.WORD_DOCUMENT_STREAM = require_detect.WORD_DOCUMENT_STREAM;
52
+ exports.applyCharacterSprms = require_prop_chp.applyCharacterSprms;
53
+ exports.applyParagraphSprms = require_prop_pap.applyParagraphSprms;
54
+ exports.characterOffset = require_text_piece_table.characterOffset;
55
+ exports.characterSize = require_text_piece_table.characterSize;
56
+ exports.decodeSprm = require_prop_sprm.decodeSprm;
57
+ exports.endsParagraph = require_text_special.endsParagraph;
58
+ exports.findLargestAtMost = require_plc.findLargestAtMost;
59
+ exports.headingLevelFromIstd = require_style_stsh.headingLevelFromIstd;
60
+ exports.isAnchorOnly = require_text_special.isAnchorOnly;
61
+ exports.isDocBytes = require_detect.isDocBytes;
62
+ exports.operandSize = require_prop_sprm.operandSize;
63
+ exports.parseChpxFkp = require_prop_fkp.parseChpxFkp;
64
+ exports.parseClx = require_text_piece_table.parseClx;
65
+ exports.parseFib = require_fib_fib.parseFib;
66
+ exports.parsePapxFkp = require_prop_fkp.parsePapxFkp;
67
+ exports.parsePlc = require_plc.parsePlc;
68
+ exports.parseStsh = require_style_stsh.parseStsh;
69
+ exports.readDocContent = require_read.readDocContent;
70
+ exports.readDocStreams = require_read.readDocStreams;
71
+ exports.readGrpprl = require_prop_sprm.readGrpprl;
72
+ exports.readInt16LE = require_bytes.readInt16LE;
73
+ exports.readInt32LE = require_bytes.readInt32LE;
74
+ exports.readTextRange = require_text_characters.readTextRange;
75
+ exports.readUint16LE = require_bytes.readUint16LE;
76
+ exports.readUint32LE = require_bytes.readUint32LE;
77
+ exports.readUint8 = require_bytes.readUint8;
78
+ exports.slice = require_bytes.slice;
79
+ exports.tableStreamName = require_fib_fib.tableStreamName;
@@ -0,0 +1,16 @@
1
+ import { readInt16LE, readInt32LE, readUint16LE, readUint32LE, readUint8, slice } from "./bytes.cjs";
2
+ import { WORD_DOCUMENT_STREAM, isDocBytes } from "./detect.cjs";
3
+ import { DocFormatError, DocUnsupportedError } from "./errors.cjs";
4
+ import { Fib, parseFib, tableStreamName } from "./fib/fib.cjs";
5
+ import { 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, LW_OFFSET } from "./fib/offsets.cjs";
6
+ import { Plc, findLargestAtMost, parsePlc } from "./plc.cjs";
7
+ import { Piece, PieceTable, characterOffset, characterSize, parseClx } from "./text/piece-table.cjs";
8
+ import { COMPRESSED_CHARACTER_MAP, TextRange, readTextRange } from "./text/characters.cjs";
9
+ import { ANNOTATION_REFERENCE, CELL_MARK, DRAWN_OBJECT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FOOTNOTE_REFERENCE, INLINE_PICTURE, LINE_BREAK, PARAGRAPH_MARK, SECTION_MARK, SYMBOL_ANCHOR, endsParagraph, isAnchorOnly } from "./text/special.cjs";
10
+ import { Prl, SGC, Sprm, decodeSprm, operandSize, readGrpprl } from "./prop/sprm.cjs";
11
+ import { ChpxFkp, FKP_PAGE_SIZE, PapxFkp, PapxLookup, PapxRecord, PropertyBinTable, parseChpxFkp, parsePapxFkp } from "./prop/fkp.cjs";
12
+ import { CharacterProperties, applyCharacterSprms } from "./prop/chp.cjs";
13
+ import { ParagraphProperties, applyParagraphSprms } from "./prop/pap.cjs";
14
+ import { STI_USER_DEFINED, STK, Style, StyleSheet, headingLevelFromIstd, parseStsh } from "./style/stsh.cjs";
15
+ import { DocStreams, readDocContent, readDocStreams } from "./read.cjs";
16
+ export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, CharacterProperties, ChpxFkp, DRAWN_OBJECT, 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, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, PARAGRAPH_MARK, PapxFkp, PapxLookup, PapxRecord, ParagraphProperties, Piece, PieceTable, Plc, Prl, PropertyBinTable, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SYMBOL_ANCHOR, Sprm, Style, StyleSheet, TextRange, WORD_DOCUMENT_STREAM, applyCharacterSprms, applyParagraphSprms, characterOffset, characterSize, decodeSprm, endsParagraph, findLargestAtMost, headingLevelFromIstd, isAnchorOnly, isDocBytes, operandSize, parseChpxFkp, parseClx, parseFib, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readTextRange, readUint16LE, readUint32LE, readUint8, slice, tableStreamName };
@@ -0,0 +1,16 @@
1
+ import { readInt16LE, readInt32LE, readUint16LE, readUint32LE, readUint8, slice } from "./bytes.js";
2
+ import { WORD_DOCUMENT_STREAM, isDocBytes } from "./detect.js";
3
+ import { DocFormatError, DocUnsupportedError } from "./errors.js";
4
+ import { Fib, parseFib, tableStreamName } from "./fib/fib.js";
5
+ import { 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, LW_OFFSET } from "./fib/offsets.js";
6
+ import { Plc, findLargestAtMost, parsePlc } from "./plc.js";
7
+ import { Piece, PieceTable, characterOffset, characterSize, parseClx } from "./text/piece-table.js";
8
+ import { COMPRESSED_CHARACTER_MAP, TextRange, readTextRange } from "./text/characters.js";
9
+ import { ANNOTATION_REFERENCE, CELL_MARK, DRAWN_OBJECT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FOOTNOTE_REFERENCE, INLINE_PICTURE, LINE_BREAK, PARAGRAPH_MARK, SECTION_MARK, SYMBOL_ANCHOR, endsParagraph, isAnchorOnly } from "./text/special.js";
10
+ import { Prl, SGC, Sprm, decodeSprm, operandSize, readGrpprl } from "./prop/sprm.js";
11
+ import { ChpxFkp, FKP_PAGE_SIZE, PapxFkp, PapxLookup, PapxRecord, PropertyBinTable, parseChpxFkp, parsePapxFkp } from "./prop/fkp.js";
12
+ import { CharacterProperties, applyCharacterSprms } from "./prop/chp.js";
13
+ import { ParagraphProperties, applyParagraphSprms } from "./prop/pap.js";
14
+ import { STI_USER_DEFINED, STK, Style, StyleSheet, headingLevelFromIstd, parseStsh } from "./style/stsh.js";
15
+ import { DocStreams, readDocContent, readDocStreams } from "./read.js";
16
+ export { ANNOTATION_REFERENCE, CELL_MARK, COMPRESSED_CHARACTER_MAP, CharacterProperties, ChpxFkp, DRAWN_OBJECT, 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, INLINE_PICTURE, LINE_BREAK, LW_OFFSET, PARAGRAPH_MARK, PapxFkp, PapxLookup, PapxRecord, ParagraphProperties, Piece, PieceTable, Plc, Prl, PropertyBinTable, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SYMBOL_ANCHOR, Sprm, Style, StyleSheet, TextRange, WORD_DOCUMENT_STREAM, applyCharacterSprms, applyParagraphSprms, characterOffset, characterSize, decodeSprm, endsParagraph, findLargestAtMost, headingLevelFromIstd, isAnchorOnly, isDocBytes, operandSize, parseChpxFkp, parseClx, parseFib, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readTextRange, readUint16LE, readUint32LE, readUint8, slice, tableStreamName };
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import { DocFormatError, DocUnsupportedError } from "./errors.js";
2
+ import { readInt16LE, readInt32LE, readUint16LE, readUint32LE, readUint8, slice } from "./bytes.js";
3
+ import { 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, LW_OFFSET } from "./fib/offsets.js";
4
+ import { WORD_DOCUMENT_STREAM, isDocBytes } from "./detect.js";
5
+ import { findLargestAtMost, parsePlc } from "./plc.js";
6
+ import { parseFib, tableStreamName } from "./fib/fib.js";
7
+ import { characterOffset, characterSize, parseClx } from "./text/piece-table.js";
8
+ import { COMPRESSED_CHARACTER_MAP, readTextRange } from "./text/characters.js";
9
+ import { ANNOTATION_REFERENCE, CELL_MARK, DRAWN_OBJECT, FIELD_BEGIN, FIELD_END, FIELD_SEPARATOR, FOOTNOTE_REFERENCE, INLINE_PICTURE, LINE_BREAK, PARAGRAPH_MARK, SECTION_MARK, SYMBOL_ANCHOR, endsParagraph, isAnchorOnly } from "./text/special.js";
10
+ import { SGC, decodeSprm, operandSize, readGrpprl } from "./prop/sprm.js";
11
+ import { FKP_PAGE_SIZE, PropertyBinTable, parseChpxFkp, parsePapxFkp } from "./prop/fkp.js";
12
+ import { applyCharacterSprms } from "./prop/chp.js";
13
+ import { applyParagraphSprms } from "./prop/pap.js";
14
+ import { STI_USER_DEFINED, STK, headingLevelFromIstd, parseStsh } from "./style/stsh.js";
15
+ import { readDocContent, readDocStreams } from "./read.js";
16
+ 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, PARAGRAPH_MARK, PropertyBinTable, SECTION_MARK, SGC, STI_USER_DEFINED, STK, SYMBOL_ANCHOR, WORD_DOCUMENT_STREAM, applyCharacterSprms, applyParagraphSprms, characterOffset, characterSize, decodeSprm, endsParagraph, findLargestAtMost, headingLevelFromIstd, isAnchorOnly, isDocBytes, operandSize, parseChpxFkp, parseClx, parseFib, parsePapxFkp, parsePlc, parseStsh, readDocContent, readDocStreams, readGrpprl, readInt16LE, readInt32LE, readTextRange, readUint16LE, readUint32LE, readUint8, slice, tableStreamName };
package/dist/plc.cjs ADDED
@@ -0,0 +1,44 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("./errors.cjs");
3
+ const require_bytes = require("./bytes.cjs");
4
+ //#region src/plc.ts
5
+ function parsePlc(bytes, elementSize, what) {
6
+ if (!Number.isInteger(elementSize) || elementSize < 0) throw new require_errors.DocFormatError(`${what} was parsed with an element size of ${elementSize}, which is not a non-negative integer`);
7
+ if (bytes.length < 4) throw new require_errors.DocFormatError(`${what} is ${bytes.length} bytes, too short to hold even the single terminating CP every PLC ends with`);
8
+ const count = (bytes.length - 4) / (4 + elementSize);
9
+ if (!Number.isInteger(count)) throw new require_errors.DocFormatError(`${what} is ${bytes.length} bytes, which does not yield a whole number of ${elementSize}-byte data elements: (${bytes.length} - 4) / (4 + ${elementSize}) = ${count}`);
10
+ const keys = [];
11
+ for (let index = 0; index <= count; index += 1) {
12
+ const key = require_bytes.readUint32LE(bytes, index * 4);
13
+ const previous = keys[index - 1];
14
+ if (previous !== void 0 && key < previous) throw new require_errors.DocFormatError(`${what} key ${index} is ${key}, which is less than the preceding key ${previous}; a PLC's keys must be in ascending order`);
15
+ keys.push(key);
16
+ }
17
+ const dataStart = (count + 1) * 4;
18
+ return {
19
+ keys,
20
+ count,
21
+ element(index) {
22
+ if (!Number.isInteger(index) || index < 0 || index >= count) throw new require_errors.DocFormatError(`${what} has ${count} data elements; element ${index} was requested`);
23
+ return require_bytes.slice(bytes, dataStart + index * elementSize, elementSize, `${what} element ${index}`);
24
+ }
25
+ };
26
+ }
27
+ function findLargestAtMost(keys, value) {
28
+ let low = 0;
29
+ let high = keys.length - 1;
30
+ let found;
31
+ while (low <= high) {
32
+ const middle = low + high >> 1;
33
+ const key = keys[middle];
34
+ if (key === void 0) throw new require_errors.DocFormatError(`PLC key ${middle} is absent from a ${keys.length}-key array`);
35
+ if (key <= value) {
36
+ found = middle;
37
+ low = middle + 1;
38
+ } else high = middle - 1;
39
+ }
40
+ return found === void 0 || found >= keys.length - 1 ? void 0 : found;
41
+ }
42
+ //#endregion
43
+ exports.findLargestAtMost = findLargestAtMost;
44
+ exports.parsePlc = parsePlc;
package/dist/plc.d.cts ADDED
@@ -0,0 +1,12 @@
1
+ //#region src/plc.d.ts
2
+ interface Plc {
3
+ /** The (count + 1) keys, ascending. keys[i] and keys[i + 1] bracket element i. */
4
+ readonly keys: readonly number[];
5
+ readonly count: number;
6
+ /** The bytes of data element i, a view into the PLC's own bytes rather than a copy. */
7
+ element(index: number): Uint8Array;
8
+ }
9
+ declare function parsePlc(bytes: Uint8Array, elementSize: number, what: string): Plc;
10
+ declare function findLargestAtMost(keys: readonly number[], value: number): number | undefined;
11
+ //#endregion
12
+ export { Plc, findLargestAtMost, parsePlc };
package/dist/plc.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ //#region src/plc.d.ts
2
+ interface Plc {
3
+ /** The (count + 1) keys, ascending. keys[i] and keys[i + 1] bracket element i. */
4
+ readonly keys: readonly number[];
5
+ readonly count: number;
6
+ /** The bytes of data element i, a view into the PLC's own bytes rather than a copy. */
7
+ element(index: number): Uint8Array;
8
+ }
9
+ declare function parsePlc(bytes: Uint8Array, elementSize: number, what: string): Plc;
10
+ declare function findLargestAtMost(keys: readonly number[], value: number): number | undefined;
11
+ //#endregion
12
+ export { Plc, findLargestAtMost, parsePlc };
package/dist/plc.js ADDED
@@ -0,0 +1,42 @@
1
+ import { DocFormatError } from "./errors.js";
2
+ import { readUint32LE, slice } from "./bytes.js";
3
+ //#region src/plc.ts
4
+ function parsePlc(bytes, elementSize, what) {
5
+ if (!Number.isInteger(elementSize) || elementSize < 0) throw new DocFormatError(`${what} was parsed with an element size of ${elementSize}, which is not a non-negative integer`);
6
+ if (bytes.length < 4) throw new DocFormatError(`${what} is ${bytes.length} bytes, too short to hold even the single terminating CP every PLC ends with`);
7
+ const count = (bytes.length - 4) / (4 + elementSize);
8
+ if (!Number.isInteger(count)) throw new DocFormatError(`${what} is ${bytes.length} bytes, which does not yield a whole number of ${elementSize}-byte data elements: (${bytes.length} - 4) / (4 + ${elementSize}) = ${count}`);
9
+ const keys = [];
10
+ for (let index = 0; index <= count; index += 1) {
11
+ const key = readUint32LE(bytes, index * 4);
12
+ const previous = keys[index - 1];
13
+ if (previous !== void 0 && key < previous) throw new DocFormatError(`${what} key ${index} is ${key}, which is less than the preceding key ${previous}; a PLC's keys must be in ascending order`);
14
+ keys.push(key);
15
+ }
16
+ const dataStart = (count + 1) * 4;
17
+ return {
18
+ keys,
19
+ count,
20
+ element(index) {
21
+ if (!Number.isInteger(index) || index < 0 || index >= count) throw new DocFormatError(`${what} has ${count} data elements; element ${index} was requested`);
22
+ return slice(bytes, dataStart + index * elementSize, elementSize, `${what} element ${index}`);
23
+ }
24
+ };
25
+ }
26
+ function findLargestAtMost(keys, value) {
27
+ let low = 0;
28
+ let high = keys.length - 1;
29
+ let found;
30
+ while (low <= high) {
31
+ const middle = low + high >> 1;
32
+ const key = keys[middle];
33
+ if (key === void 0) throw new DocFormatError(`PLC key ${middle} is absent from a ${keys.length}-key array`);
34
+ if (key <= value) {
35
+ found = middle;
36
+ low = middle + 1;
37
+ } else high = middle - 1;
38
+ }
39
+ return found === void 0 || found >= keys.length - 1 ? void 0 : found;
40
+ }
41
+ //#endregion
42
+ export { findLargestAtMost, parsePlc };
@@ -0,0 +1,172 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("../errors.cjs");
3
+ const require_bytes = require("../bytes.cjs");
4
+ const require_prop_sprm = require("./sprm.cjs");
5
+ //#region src/prop/chp.ts
6
+ /** sprmCFBold: a ToggleOperand switching bold. */
7
+ const SPRM_C_F_BOLD = 2101;
8
+ /** sprmCFItalic. */
9
+ const SPRM_C_F_ITALIC = 2102;
10
+ /** sprmCFStrike. */
11
+ const SPRM_C_F_STRIKE = 2103;
12
+ /** sprmCKul: a Kul value giving the underline style; anything but 0x00 is some kind of underline. */
13
+ const SPRM_C_KUL = 10814;
14
+ /** sprmCHps: "an unsigned 2-byte integer, in half-points", so points are the operand halved. */
15
+ const SPRM_C_HPS = 19011;
16
+ /** sprmCIstd: the istd of a character style to apply. */
17
+ const SPRM_C_ISTD = 18992;
18
+ /** sprmCIco: an Ico value, an index into [MS-DOC] 2.9.126's fixed 17-entry palette. */
19
+ const SPRM_C_ICO = 10818;
20
+ /** sprmCCv: a COLORREF, the richer colour sprm that supersedes sprmCIco where both appear. */
21
+ const SPRM_C_CV = 26736;
22
+ /** ToggleOperand, [MS-DOC] 2.9.336. 0x80 and 0x81 are relative to the style's own value rather than absolute. */
23
+ const TOGGLE_OFF = 0;
24
+ const TOGGLE_ON = 1;
25
+ const TOGGLE_INHERIT_FROM_STYLE = 128;
26
+ const TOGGLE_INVERT_STYLE = 129;
27
+ const HALF_POINTS_PER_POINT = 2;
28
+ const COLOR_COMPONENT_MAX = 255;
29
+ const ICO_PALETTE = [
30
+ void 0,
31
+ [
32
+ 0,
33
+ 0,
34
+ 0
35
+ ],
36
+ [
37
+ 0,
38
+ 0,
39
+ 255
40
+ ],
41
+ [
42
+ 0,
43
+ 255,
44
+ 255
45
+ ],
46
+ [
47
+ 0,
48
+ 255,
49
+ 0
50
+ ],
51
+ [
52
+ 255,
53
+ 0,
54
+ 255
55
+ ],
56
+ [
57
+ 255,
58
+ 0,
59
+ 0
60
+ ],
61
+ [
62
+ 255,
63
+ 255,
64
+ 0
65
+ ],
66
+ [
67
+ 255,
68
+ 255,
69
+ 255
70
+ ],
71
+ [
72
+ 0,
73
+ 0,
74
+ 128
75
+ ],
76
+ [
77
+ 0,
78
+ 128,
79
+ 128
80
+ ],
81
+ [
82
+ 0,
83
+ 128,
84
+ 0
85
+ ],
86
+ [
87
+ 128,
88
+ 0,
89
+ 128
90
+ ],
91
+ [
92
+ 128,
93
+ 0,
94
+ 128
95
+ ],
96
+ [
97
+ 128,
98
+ 128,
99
+ 0
100
+ ],
101
+ [
102
+ 128,
103
+ 128,
104
+ 128
105
+ ],
106
+ [
107
+ 192,
108
+ 192,
109
+ 192
110
+ ]
111
+ ];
112
+ function toggle(operand, current) {
113
+ const value = require_bytes.readUint8(operand, 0);
114
+ switch (value) {
115
+ case TOGGLE_OFF: return false;
116
+ case TOGGLE_ON: return true;
117
+ case TOGGLE_INHERIT_FROM_STYLE: return current ?? false;
118
+ case TOGGLE_INVERT_STYLE: return !(current ?? false);
119
+ default: throw new require_errors.DocFormatError(`ToggleOperand value 0x${value.toString(16)} is none of the four [MS-DOC] 2.9.336 defines (0x00, 0x01, 0x80, 0x81)`);
120
+ }
121
+ }
122
+ function icoColor(value) {
123
+ if (value >= ICO_PALETTE.length) throw new require_errors.DocFormatError(`Ico value 0x${value.toString(16)} is not less than 0x11, the bound [MS-DOC] 2.9.126 places on the palette`);
124
+ const entry = ICO_PALETTE[value];
125
+ if (entry === void 0) return void 0;
126
+ const [r, g, b] = entry;
127
+ return {
128
+ r: r / COLOR_COMPONENT_MAX,
129
+ g: g / COLOR_COMPONENT_MAX,
130
+ b: b / COLOR_COMPONENT_MAX
131
+ };
132
+ }
133
+ function colorRefColor(operand) {
134
+ if (require_bytes.readUint8(operand, 3) !== 0) return void 0;
135
+ return {
136
+ r: require_bytes.readUint8(operand, 0) / COLOR_COMPONENT_MAX,
137
+ g: require_bytes.readUint8(operand, 1) / COLOR_COMPONENT_MAX,
138
+ b: require_bytes.readUint8(operand, 2) / COLOR_COMPONENT_MAX
139
+ };
140
+ }
141
+ function applyCharacterSprms(prls, into) {
142
+ for (const prl of prls) {
143
+ if (prl.sprm.sgc !== require_prop_sprm.SGC.character) continue;
144
+ switch (prl.sprm.value) {
145
+ case SPRM_C_F_BOLD:
146
+ into.bold = toggle(prl.operand, into.bold);
147
+ break;
148
+ case SPRM_C_F_ITALIC:
149
+ into.italic = toggle(prl.operand, into.italic);
150
+ break;
151
+ case SPRM_C_F_STRIKE:
152
+ into.strike = toggle(prl.operand, into.strike);
153
+ break;
154
+ case SPRM_C_KUL:
155
+ into.underline = require_bytes.readUint8(prl.operand, 0) !== 0;
156
+ break;
157
+ case SPRM_C_HPS:
158
+ into.sizePt = require_bytes.readUint16LE(prl.operand, 0) / HALF_POINTS_PER_POINT;
159
+ break;
160
+ case SPRM_C_ISTD:
161
+ into.istd = require_bytes.readUint16LE(prl.operand, 0);
162
+ break;
163
+ case SPRM_C_ICO:
164
+ into.color = icoColor(require_bytes.readUint8(prl.operand, 0));
165
+ break;
166
+ case SPRM_C_CV: into.color = colorRefColor(prl.operand);
167
+ }
168
+ }
169
+ return into;
170
+ }
171
+ //#endregion
172
+ exports.applyCharacterSprms = applyCharacterSprms;
@@ -0,0 +1,16 @@
1
+ import { Prl } from "./sprm.cjs";
2
+ import { Color } from "document-schema.js";
3
+ //#region src/prop/chp.d.ts
4
+ interface CharacterProperties {
5
+ bold?: boolean;
6
+ italic?: boolean;
7
+ underline?: boolean;
8
+ strike?: boolean;
9
+ sizePt?: number;
10
+ color?: Color;
11
+ /** The istd of a character style applied by sprmCIstd, carried so a caller can resolve the style's own name. */
12
+ istd?: number;
13
+ }
14
+ declare function applyCharacterSprms(prls: readonly Prl[], into: CharacterProperties): CharacterProperties;
15
+ //#endregion
16
+ export { CharacterProperties, applyCharacterSprms };
@@ -0,0 +1,16 @@
1
+ import { Prl } from "./sprm.js";
2
+ import { Color } from "document-schema.js";
3
+ //#region src/prop/chp.d.ts
4
+ interface CharacterProperties {
5
+ bold?: boolean;
6
+ italic?: boolean;
7
+ underline?: boolean;
8
+ strike?: boolean;
9
+ sizePt?: number;
10
+ color?: Color;
11
+ /** The istd of a character style applied by sprmCIstd, carried so a caller can resolve the style's own name. */
12
+ istd?: number;
13
+ }
14
+ declare function applyCharacterSprms(prls: readonly Prl[], into: CharacterProperties): CharacterProperties;
15
+ //#endregion
16
+ export { CharacterProperties, applyCharacterSprms };