doc-codec 2.4.3 → 2.5.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 (86) hide show
  1. package/README.md +47 -16
  2. package/dist/chp-B6AOh85P.d.ts +18 -0
  3. package/dist/chp-BpCqpb7V.d.cts +18 -0
  4. package/dist/detect.cjs +3 -0
  5. package/dist/detect.d.cts +3 -1
  6. package/dist/detect.d.ts +3 -1
  7. package/dist/detect.js +3 -1
  8. package/dist/fib/fib.cjs +14 -0
  9. package/dist/fib/fib.d.cts +1 -1
  10. package/dist/fib/fib.d.ts +1 -1
  11. package/dist/fib/fib.js +14 -0
  12. package/dist/fib/offsets.cjs +14 -0
  13. package/dist/fib/offsets.d.cts +14 -0
  14. package/dist/fib/offsets.d.ts +14 -0
  15. package/dist/fib/offsets.js +14 -0
  16. package/dist/{fib-DWFta19r.d.cts → fib-6BFIx153.d.cts} +14 -0
  17. package/dist/{fib-DWFta19r.d.ts → fib-6BFIx153.d.ts} +14 -0
  18. package/dist/fkp-I-laf-8y.d.cts +33 -0
  19. package/dist/fkp-I-laf-8y.d.ts +33 -0
  20. package/dist/headers-footers.cjs +34 -0
  21. package/dist/headers-footers.d.cts +16 -0
  22. package/dist/headers-footers.d.ts +16 -0
  23. package/dist/headers-footers.js +33 -0
  24. package/dist/index.cjs +20 -9
  25. package/dist/index.d.cts +16 -12
  26. package/dist/index.d.ts +16 -12
  27. package/dist/index.js +15 -11
  28. package/dist/list/numbering-write.d.cts +1 -1
  29. package/dist/list/numbering-write.d.ts +1 -1
  30. package/dist/list/numbering.d.cts +23 -1
  31. package/dist/list/numbering.d.ts +23 -1
  32. package/dist/notes.cjs +26 -0
  33. package/dist/notes.d.cts +20 -0
  34. package/dist/notes.d.ts +20 -0
  35. package/dist/notes.js +25 -0
  36. package/dist/{pap-BT1p0uzu.d.cts → pap-BQ2E17K9.d.cts} +5 -3
  37. package/dist/{pap-DOFLMWcG.d.ts → pap-iWFIpCdo.d.ts} +5 -3
  38. package/dist/paragraphs-DQUp8_HB.d.cts +31 -0
  39. package/dist/paragraphs-s2lJ6w2I.d.ts +31 -0
  40. package/dist/pictures.cjs +93 -0
  41. package/dist/pictures.d.cts +6 -0
  42. package/dist/pictures.d.ts +6 -0
  43. package/dist/pictures.js +92 -0
  44. package/dist/piece-table-CA18mhjv.d.cts +28 -0
  45. package/dist/piece-table-CA18mhjv.d.ts +28 -0
  46. package/dist/prop/chp.d.cts +1 -17
  47. package/dist/prop/chp.d.ts +1 -17
  48. package/dist/prop/fkp.d.cts +1 -32
  49. package/dist/prop/fkp.d.ts +1 -32
  50. package/dist/prop/pap.cjs +4 -2
  51. package/dist/prop/pap.d.cts +1 -1
  52. package/dist/prop/pap.d.ts +1 -1
  53. package/dist/prop/pap.js +4 -2
  54. package/dist/prop/sep.cjs +20 -10
  55. package/dist/prop/sep.d.cts +8 -4
  56. package/dist/prop/sep.d.ts +8 -4
  57. package/dist/prop/sep.js +20 -10
  58. package/dist/read.cjs +47 -151
  59. package/dist/read.d.cts +13 -15
  60. package/dist/read.d.ts +13 -15
  61. package/dist/read.js +49 -153
  62. package/dist/stsh-Bj0YSEOp.d.ts +40 -0
  63. package/dist/stsh-CK59x6XG.d.cts +40 -0
  64. package/dist/style/stsh.d.cts +1 -39
  65. package/dist/style/stsh.d.ts +1 -39
  66. package/dist/subdocument.cjs +20 -0
  67. package/dist/subdocument.d.cts +8 -0
  68. package/dist/subdocument.d.ts +8 -0
  69. package/dist/subdocument.js +18 -0
  70. package/dist/table/read.cjs +31 -17
  71. package/dist/table/read.d.cts +1 -1
  72. package/dist/table/read.d.ts +1 -1
  73. package/dist/table/read.js +32 -18
  74. package/dist/text/characters.d.cts +1 -1
  75. package/dist/text/characters.d.ts +1 -1
  76. package/dist/text/paragraphs.cjs +189 -0
  77. package/dist/text/paragraphs.d.cts +2 -0
  78. package/dist/text/paragraphs.d.ts +2 -0
  79. package/dist/text/paragraphs.js +187 -0
  80. package/dist/text/piece-table.d.cts +1 -27
  81. package/dist/text/piece-table.d.ts +1 -27
  82. package/dist/write.cjs +3 -3
  83. package/dist/write.js +3 -3
  84. package/package.json +1 -1
  85. package/dist/numbering-DSpm9w6y.d.cts +0 -24
  86. package/dist/numbering-DayjnHXY.d.ts +0 -24
@@ -0,0 +1,93 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_bytes = require("./bytes.cjs");
3
+ //#region src/pictures.ts
4
+ const PICF_SIZE = 68;
5
+ const PICF_MM_OFFSET = 6;
6
+ const PICF_DXA_GOAL_OFFSET = 28;
7
+ const PICF_DYA_GOAL_OFFSET = 30;
8
+ const PICF_MX_OFFSET = 32;
9
+ const PICF_MY_OFFSET = 34;
10
+ /** MFPF.mm's MM_SHAPEFILE value, [MS-DOC] 2.9.181 -- the one case PICFAndOfficeArtData carries an extra cchPicName/stPicName pair (the picture's own source file name) before `picture` begins. */
11
+ const MM_SHAPEFILE = 102;
12
+ const RECORD_HEADER_SIZE = 8;
13
+ /** OfficeArtBlipJPEG, [MS-ODRAW] 2.2.27. */
14
+ const BLIP_JPEG = 61469;
15
+ /** OfficeArtBlipPNG, [MS-ODRAW] 2.2.28. */
16
+ const BLIP_PNG = 61470;
17
+ /** rh.recInstance values naming a single rgbUid (16 bytes) rather than two (32 bytes) -- [MS-ODRAW] 2.2.27's own table for JPEG (RGB and CMYK) and 2.2.28's for PNG. */
18
+ const ONE_UID_INSTANCES = /* @__PURE__ */ new Set([
19
+ 1130,
20
+ 1762,
21
+ 1760
22
+ ]);
23
+ const TWO_UID_INSTANCES = /* @__PURE__ */ new Set([
24
+ 1131,
25
+ 1763,
26
+ 1761
27
+ ]);
28
+ /** The one byte following rgbUid(1|2) in every OfficeArtBlip variant this module reads, before the raw file bytes themselves. */
29
+ const BLIP_TAG_SIZE = 1;
30
+ const TWIPS_PER_POINT = 20;
31
+ /** mx/my, [MS-DOC] PICMID: "the ratio, measured in tenths of a percent, between the final display width/height and the initial picture width/height". */
32
+ const SCALE_DENOMINATOR = 1e3;
33
+ function readRecordHeader(data, offset) {
34
+ return {
35
+ recInstance: require_bytes.readUint16LE(data, offset) >> 4 & 4095,
36
+ recType: require_bytes.readUint16LE(data, offset + 2),
37
+ recLen: require_bytes.readUint32LE(data, offset + 4)
38
+ };
39
+ }
40
+ /** Resolves one inline picture character's own sprmCPicLocation offset into a ContentImageBlock, or undefined when the picture's own blip is a format this package does not decode (see this module's own top comment) -- never thrown, since an unsupported picture format is exactly the kind of absence the rest of this reader already treats as "read with fewer properties than it states" rather than a document-level failure. */
41
+ function readInlinePicture(dataStream, picLocation) {
42
+ const picf = require_bytes.slice(dataStream, picLocation, PICF_SIZE, "PICF in the Data stream");
43
+ const mm = require_bytes.readUint16LE(picf, PICF_MM_OFFSET);
44
+ const dxaGoal = require_bytes.readInt16LE(picf, PICF_DXA_GOAL_OFFSET);
45
+ const dyaGoal = require_bytes.readInt16LE(picf, PICF_DYA_GOAL_OFFSET);
46
+ const mx = require_bytes.readUint16LE(picf, PICF_MX_OFFSET);
47
+ const my = require_bytes.readUint16LE(picf, PICF_MY_OFFSET);
48
+ let cursor = picLocation + PICF_SIZE;
49
+ if (mm === MM_SHAPEFILE) {
50
+ const cchPicName = require_bytes.readUint8(dataStream, cursor);
51
+ cursor += 1 + cchPicName;
52
+ }
53
+ const shapeHeader = readRecordHeader(dataStream, cursor);
54
+ cursor += RECORD_HEADER_SIZE + shapeHeader.recLen;
55
+ const blipHeader = readRecordHeader(dataStream, cursor);
56
+ const format = blipFormat(blipHeader.recType);
57
+ if (format === void 0) return void 0;
58
+ const uidBytes = ONE_UID_INSTANCES.has(blipHeader.recInstance) ? 16 : TWO_UID_INSTANCES.has(blipHeader.recInstance) ? 32 : void 0;
59
+ if (uidBytes === void 0) return void 0;
60
+ const blipDataStart = cursor + RECORD_HEADER_SIZE + uidBytes + BLIP_TAG_SIZE;
61
+ const blipDataLength = blipHeader.recLen - uidBytes - BLIP_TAG_SIZE;
62
+ return {
63
+ kind: "image",
64
+ format,
65
+ base64: bytesToBase64(require_bytes.slice(dataStream, blipDataStart, blipDataLength, "OfficeArtBlip file data in the Data stream")),
66
+ widthPt: dxaGoal * mx / SCALE_DENOMINATOR / TWIPS_PER_POINT,
67
+ heightPt: dyaGoal * my / SCALE_DENOMINATOR / TWIPS_PER_POINT
68
+ };
69
+ }
70
+ function blipFormat(recType) {
71
+ switch (recType) {
72
+ case BLIP_JPEG: return "jpeg";
73
+ case BLIP_PNG: return "png";
74
+ default: return;
75
+ }
76
+ }
77
+ const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
78
+ function bytesToBase64(bytes) {
79
+ let out = "";
80
+ const len = bytes.length;
81
+ for (let index = 0; index < len; index += 3) {
82
+ const b0 = bytes[index] ?? 0;
83
+ const b1 = index + 1 < len ? bytes[index + 1] ?? 0 : 0;
84
+ const b2 = index + 2 < len ? bytes[index + 2] ?? 0 : 0;
85
+ out += BASE64_TABLE.charAt(b0 >> 2);
86
+ out += BASE64_TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
87
+ out += index + 1 < len ? BASE64_TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
88
+ out += index + 2 < len ? BASE64_TABLE.charAt(b2 & 63) : "=";
89
+ }
90
+ return out;
91
+ }
92
+ //#endregion
93
+ exports.readInlinePicture = readInlinePicture;
@@ -0,0 +1,6 @@
1
+ import { ContentImageBlock } from "document-schema.js";
2
+ //#region src/pictures.d.ts
3
+ /** Resolves one inline picture character's own sprmCPicLocation offset into a ContentImageBlock, or undefined when the picture's own blip is a format this package does not decode (see this module's own top comment) -- never thrown, since an unsupported picture format is exactly the kind of absence the rest of this reader already treats as "read with fewer properties than it states" rather than a document-level failure. */
4
+ declare function readInlinePicture(dataStream: Uint8Array, picLocation: number): ContentImageBlock | undefined;
5
+ //#endregion
6
+ export { readInlinePicture };
@@ -0,0 +1,6 @@
1
+ import { ContentImageBlock } from "document-schema.js";
2
+ //#region src/pictures.d.ts
3
+ /** Resolves one inline picture character's own sprmCPicLocation offset into a ContentImageBlock, or undefined when the picture's own blip is a format this package does not decode (see this module's own top comment) -- never thrown, since an unsupported picture format is exactly the kind of absence the rest of this reader already treats as "read with fewer properties than it states" rather than a document-level failure. */
4
+ declare function readInlinePicture(dataStream: Uint8Array, picLocation: number): ContentImageBlock | undefined;
5
+ //#endregion
6
+ export { readInlinePicture };
@@ -0,0 +1,92 @@
1
+ import { readInt16LE, readUint16LE, readUint32LE, readUint8, slice } from "./bytes.js";
2
+ //#region src/pictures.ts
3
+ const PICF_SIZE = 68;
4
+ const PICF_MM_OFFSET = 6;
5
+ const PICF_DXA_GOAL_OFFSET = 28;
6
+ const PICF_DYA_GOAL_OFFSET = 30;
7
+ const PICF_MX_OFFSET = 32;
8
+ const PICF_MY_OFFSET = 34;
9
+ /** MFPF.mm's MM_SHAPEFILE value, [MS-DOC] 2.9.181 -- the one case PICFAndOfficeArtData carries an extra cchPicName/stPicName pair (the picture's own source file name) before `picture` begins. */
10
+ const MM_SHAPEFILE = 102;
11
+ const RECORD_HEADER_SIZE = 8;
12
+ /** OfficeArtBlipJPEG, [MS-ODRAW] 2.2.27. */
13
+ const BLIP_JPEG = 61469;
14
+ /** OfficeArtBlipPNG, [MS-ODRAW] 2.2.28. */
15
+ const BLIP_PNG = 61470;
16
+ /** rh.recInstance values naming a single rgbUid (16 bytes) rather than two (32 bytes) -- [MS-ODRAW] 2.2.27's own table for JPEG (RGB and CMYK) and 2.2.28's for PNG. */
17
+ const ONE_UID_INSTANCES = /* @__PURE__ */ new Set([
18
+ 1130,
19
+ 1762,
20
+ 1760
21
+ ]);
22
+ const TWO_UID_INSTANCES = /* @__PURE__ */ new Set([
23
+ 1131,
24
+ 1763,
25
+ 1761
26
+ ]);
27
+ /** The one byte following rgbUid(1|2) in every OfficeArtBlip variant this module reads, before the raw file bytes themselves. */
28
+ const BLIP_TAG_SIZE = 1;
29
+ const TWIPS_PER_POINT = 20;
30
+ /** mx/my, [MS-DOC] PICMID: "the ratio, measured in tenths of a percent, between the final display width/height and the initial picture width/height". */
31
+ const SCALE_DENOMINATOR = 1e3;
32
+ function readRecordHeader(data, offset) {
33
+ return {
34
+ recInstance: readUint16LE(data, offset) >> 4 & 4095,
35
+ recType: readUint16LE(data, offset + 2),
36
+ recLen: readUint32LE(data, offset + 4)
37
+ };
38
+ }
39
+ /** Resolves one inline picture character's own sprmCPicLocation offset into a ContentImageBlock, or undefined when the picture's own blip is a format this package does not decode (see this module's own top comment) -- never thrown, since an unsupported picture format is exactly the kind of absence the rest of this reader already treats as "read with fewer properties than it states" rather than a document-level failure. */
40
+ function readInlinePicture(dataStream, picLocation) {
41
+ const picf = slice(dataStream, picLocation, PICF_SIZE, "PICF in the Data stream");
42
+ const mm = readUint16LE(picf, PICF_MM_OFFSET);
43
+ const dxaGoal = readInt16LE(picf, PICF_DXA_GOAL_OFFSET);
44
+ const dyaGoal = readInt16LE(picf, PICF_DYA_GOAL_OFFSET);
45
+ const mx = readUint16LE(picf, PICF_MX_OFFSET);
46
+ const my = readUint16LE(picf, PICF_MY_OFFSET);
47
+ let cursor = picLocation + PICF_SIZE;
48
+ if (mm === MM_SHAPEFILE) {
49
+ const cchPicName = readUint8(dataStream, cursor);
50
+ cursor += 1 + cchPicName;
51
+ }
52
+ const shapeHeader = readRecordHeader(dataStream, cursor);
53
+ cursor += RECORD_HEADER_SIZE + shapeHeader.recLen;
54
+ const blipHeader = readRecordHeader(dataStream, cursor);
55
+ const format = blipFormat(blipHeader.recType);
56
+ if (format === void 0) return void 0;
57
+ const uidBytes = ONE_UID_INSTANCES.has(blipHeader.recInstance) ? 16 : TWO_UID_INSTANCES.has(blipHeader.recInstance) ? 32 : void 0;
58
+ if (uidBytes === void 0) return void 0;
59
+ const blipDataStart = cursor + RECORD_HEADER_SIZE + uidBytes + BLIP_TAG_SIZE;
60
+ const blipDataLength = blipHeader.recLen - uidBytes - BLIP_TAG_SIZE;
61
+ return {
62
+ kind: "image",
63
+ format,
64
+ base64: bytesToBase64(slice(dataStream, blipDataStart, blipDataLength, "OfficeArtBlip file data in the Data stream")),
65
+ widthPt: dxaGoal * mx / SCALE_DENOMINATOR / TWIPS_PER_POINT,
66
+ heightPt: dyaGoal * my / SCALE_DENOMINATOR / TWIPS_PER_POINT
67
+ };
68
+ }
69
+ function blipFormat(recType) {
70
+ switch (recType) {
71
+ case BLIP_JPEG: return "jpeg";
72
+ case BLIP_PNG: return "png";
73
+ default: return;
74
+ }
75
+ }
76
+ const BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
77
+ function bytesToBase64(bytes) {
78
+ let out = "";
79
+ const len = bytes.length;
80
+ for (let index = 0; index < len; index += 3) {
81
+ const b0 = bytes[index] ?? 0;
82
+ const b1 = index + 1 < len ? bytes[index + 1] ?? 0 : 0;
83
+ const b2 = index + 2 < len ? bytes[index + 2] ?? 0 : 0;
84
+ out += BASE64_TABLE.charAt(b0 >> 2);
85
+ out += BASE64_TABLE.charAt((b0 & 3) << 4 | b1 >> 4);
86
+ out += index + 1 < len ? BASE64_TABLE.charAt((b1 & 15) << 2 | b2 >> 6) : "=";
87
+ out += index + 2 < len ? BASE64_TABLE.charAt(b2 & 63) : "=";
88
+ }
89
+ return out;
90
+ }
91
+ //#endregion
92
+ export { readInlinePicture };
@@ -0,0 +1,28 @@
1
+ //#region src/text/piece-table.d.ts
2
+ interface Piece {
3
+ /** The first character position this piece supplies, PlcPcd.aCp[i]. */
4
+ readonly cpStart: number;
5
+ /** One past the last character position this piece supplies, PlcPcd.aCp[i + 1]. */
6
+ readonly cpEnd: number;
7
+ /** FcCompressed's 30-bit offset field as stored -- NOT yet halved for a compressed piece. Use characterOffset() rather than this directly. */
8
+ readonly fc: number;
9
+ /** True when the piece's characters occupy one byte each and its real byte offset is `fc / 2`. */
10
+ readonly compressed: boolean;
11
+ /** Pcd's fNoParaLast: "If this bit is 1, the text MUST NOT contain a paragraph mark." */
12
+ readonly noParaLast: boolean;
13
+ /** Pcd.Prm, [MS-DOC] 2.8.36 -- further property modifications for this piece's text, carried verbatim and not yet applied (see README's scope note). */
14
+ readonly prm: number;
15
+ }
16
+ interface PieceTable {
17
+ readonly pieces: readonly Piece[];
18
+ /** PlcPcd.aCp itself: one more entry than there are pieces, so a lookup can bracket every piece and terminate at the document's end. */
19
+ readonly cpKeys: readonly number[];
20
+ /** The final aCp entry, one past the last character position the document defines. */
21
+ readonly lastCp: number;
22
+ }
23
+ declare function parseClx(clx: Uint8Array): PieceTable;
24
+ declare function characterOffset(piece: Piece, cp: number): number;
25
+ /** The number of bytes one character occupies in this piece: one for a compressed (8-bit) piece, two for an uncompressed (16-bit) one. */
26
+ declare function characterSize(piece: Piece): 1 | 2;
27
+ //#endregion
28
+ export { parseClx as a, characterSize as i, PieceTable as n, characterOffset as r, Piece as t };
@@ -0,0 +1,28 @@
1
+ //#region src/text/piece-table.d.ts
2
+ interface Piece {
3
+ /** The first character position this piece supplies, PlcPcd.aCp[i]. */
4
+ readonly cpStart: number;
5
+ /** One past the last character position this piece supplies, PlcPcd.aCp[i + 1]. */
6
+ readonly cpEnd: number;
7
+ /** FcCompressed's 30-bit offset field as stored -- NOT yet halved for a compressed piece. Use characterOffset() rather than this directly. */
8
+ readonly fc: number;
9
+ /** True when the piece's characters occupy one byte each and its real byte offset is `fc / 2`. */
10
+ readonly compressed: boolean;
11
+ /** Pcd's fNoParaLast: "If this bit is 1, the text MUST NOT contain a paragraph mark." */
12
+ readonly noParaLast: boolean;
13
+ /** Pcd.Prm, [MS-DOC] 2.8.36 -- further property modifications for this piece's text, carried verbatim and not yet applied (see README's scope note). */
14
+ readonly prm: number;
15
+ }
16
+ interface PieceTable {
17
+ readonly pieces: readonly Piece[];
18
+ /** PlcPcd.aCp itself: one more entry than there are pieces, so a lookup can bracket every piece and terminate at the document's end. */
19
+ readonly cpKeys: readonly number[];
20
+ /** The final aCp entry, one past the last character position the document defines. */
21
+ readonly lastCp: number;
22
+ }
23
+ declare function parseClx(clx: Uint8Array): PieceTable;
24
+ declare function characterOffset(piece: Piece, cp: number): number;
25
+ /** The number of bytes one character occupies in this piece: one for a compressed (8-bit) piece, two for an uncompressed (16-bit) one. */
26
+ declare function characterSize(piece: Piece): 1 | 2;
27
+ //#endregion
28
+ export { parseClx as a, characterSize as i, PieceTable as n, characterOffset as r, Piece as t };
@@ -1,18 +1,2 @@
1
- import { t as Prl } from "../sprm-DEyvdOo0.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
- fontFamily?: string;
12
- /** The istd of a character style applied by sprmCIstd, carried so a caller can resolve the style's own name. */
13
- istd?: number;
14
- }
15
- declare function applyCharacterSprms(prls: readonly Prl[], into: CharacterProperties, fonts?: readonly string[]): CharacterProperties;
16
- declare function characterIstdFromGrpprl(prls: readonly Prl[]): number | undefined;
17
- //#endregion
1
+ import { n as applyCharacterSprms, r as characterIstdFromGrpprl, t as CharacterProperties } from "../chp-BpCqpb7V.cjs";
18
2
  export { CharacterProperties, applyCharacterSprms, characterIstdFromGrpprl };
@@ -1,18 +1,2 @@
1
- import { t as Prl } from "../sprm-DEyvdOo0.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
- fontFamily?: string;
12
- /** The istd of a character style applied by sprmCIstd, carried so a caller can resolve the style's own name. */
13
- istd?: number;
14
- }
15
- declare function applyCharacterSprms(prls: readonly Prl[], into: CharacterProperties, fonts?: readonly string[]): CharacterProperties;
16
- declare function characterIstdFromGrpprl(prls: readonly Prl[]): number | undefined;
17
- //#endregion
1
+ import { n as applyCharacterSprms, r as characterIstdFromGrpprl, t as CharacterProperties } from "../chp-B6AOh85P.js";
18
2
  export { CharacterProperties, applyCharacterSprms, characterIstdFromGrpprl };
@@ -1,33 +1,2 @@
1
- //#region src/prop/fkp.d.ts
2
- /** Every FKP is exactly one 512-byte page, whatever the compound file's own sector size. */
3
- declare const FKP_PAGE_SIZE = 512;
4
- interface ChpxFkp {
5
- readonly rgfc: readonly number[];
6
- /** The Chpx's grpprl for run `index`, or undefined when the run's rgb entry is zero and it carries no exception. */
7
- grpprl(index: number): Uint8Array | undefined;
8
- }
9
- interface PapxRecord {
10
- readonly istd: number;
11
- readonly grpprl: Uint8Array;
12
- }
13
- interface PapxFkp {
14
- readonly rgfc: readonly number[];
15
- /** The PapxInFkp for paragraph `index`, or undefined when its BxPap.bOffset is zero and the paragraph takes the defaults. */
16
- papx(index: number): PapxRecord | undefined;
17
- }
18
- declare function parseChpxFkp(page: Uint8Array): ChpxFkp;
19
- declare function parsePapxFkp(page: Uint8Array): PapxFkp;
20
- interface PapxLookup extends PapxRecord {
21
- /** The byte offset one past the end of the paragraph this record covers -- PapxFkp.rgfc[k + 1], the paragraph boundary [MS-DOC] 2.4.2 derives its own from. */
22
- readonly fcLim: number;
23
- }
24
- declare class PropertyBinTable {
25
- #private;
26
- constructor(wordDocument: Uint8Array, plc: Uint8Array, what: string);
27
- /** The direct character-formatting grpprl covering `fc`, or undefined when the offset is outside the table or its run carries no exception. */
28
- chpxGrpprl(fc: number): Uint8Array | undefined;
29
- /** The direct paragraph-formatting record covering `fc`, or undefined when the offset is outside the table or its paragraph carries no exception. */
30
- papx(fc: number): PapxLookup | undefined;
31
- }
32
- //#endregion
1
+ import { a as PapxRecord, c as parsePapxFkp, i as PapxLookup, n as FKP_PAGE_SIZE, o as PropertyBinTable, r as PapxFkp, s as parseChpxFkp, t as ChpxFkp } from "../fkp-I-laf-8y.cjs";
33
2
  export { ChpxFkp, FKP_PAGE_SIZE, PapxFkp, PapxLookup, PapxRecord, PropertyBinTable, parseChpxFkp, parsePapxFkp };
@@ -1,33 +1,2 @@
1
- //#region src/prop/fkp.d.ts
2
- /** Every FKP is exactly one 512-byte page, whatever the compound file's own sector size. */
3
- declare const FKP_PAGE_SIZE = 512;
4
- interface ChpxFkp {
5
- readonly rgfc: readonly number[];
6
- /** The Chpx's grpprl for run `index`, or undefined when the run's rgb entry is zero and it carries no exception. */
7
- grpprl(index: number): Uint8Array | undefined;
8
- }
9
- interface PapxRecord {
10
- readonly istd: number;
11
- readonly grpprl: Uint8Array;
12
- }
13
- interface PapxFkp {
14
- readonly rgfc: readonly number[];
15
- /** The PapxInFkp for paragraph `index`, or undefined when its BxPap.bOffset is zero and the paragraph takes the defaults. */
16
- papx(index: number): PapxRecord | undefined;
17
- }
18
- declare function parseChpxFkp(page: Uint8Array): ChpxFkp;
19
- declare function parsePapxFkp(page: Uint8Array): PapxFkp;
20
- interface PapxLookup extends PapxRecord {
21
- /** The byte offset one past the end of the paragraph this record covers -- PapxFkp.rgfc[k + 1], the paragraph boundary [MS-DOC] 2.4.2 derives its own from. */
22
- readonly fcLim: number;
23
- }
24
- declare class PropertyBinTable {
25
- #private;
26
- constructor(wordDocument: Uint8Array, plc: Uint8Array, what: string);
27
- /** The direct character-formatting grpprl covering `fc`, or undefined when the offset is outside the table or its run carries no exception. */
28
- chpxGrpprl(fc: number): Uint8Array | undefined;
29
- /** The direct paragraph-formatting record covering `fc`, or undefined when the offset is outside the table or its paragraph carries no exception. */
30
- papx(fc: number): PapxLookup | undefined;
31
- }
32
- //#endregion
1
+ import { a as PapxRecord, c as parsePapxFkp, i as PapxLookup, n as FKP_PAGE_SIZE, o as PropertyBinTable, r as PapxFkp, s as parseChpxFkp, t as ChpxFkp } from "../fkp-I-laf-8y.js";
33
2
  export { ChpxFkp, FKP_PAGE_SIZE, PapxFkp, PapxLookup, PapxRecord, PropertyBinTable, parseChpxFkp, parsePapxFkp };
package/dist/prop/pap.cjs CHANGED
@@ -36,7 +36,7 @@ const SPRM_P_ILVL = 9738;
36
36
  const SPRM_P_ILFO = 17931;
37
37
  /** sprmPItap: the paragraph's own table depth -- read only far enough to detect a depth greater than 1 (a table nested inside a table cell), which this package refuses rather than mis-reads. */
38
38
  const SPRM_P_ITAP = 26185;
39
- /** sprmPFInnerTableCell / sprmPFInnerTtp: a nested table's own cell-ending or row-ending mark. Neither is acted on beyond refusing the nested table it signals. */
39
+ /** sprmPFInnerTableCell / sprmPFInnerTtp: a nested table's (table depth greater than 1) own cell-ending or row-ending mark, [MS-DOC] 2.4.3's Overview of Tables -- the paragraph-mark (0x000D) analogues of sprmPFInTable's cell-mark (0x0007) boundary and sprmPFTtp's row-mark at depth 1. */
40
40
  const SPRM_P_F_INNER_TABLE_CELL = 9291;
41
41
  const SPRM_P_F_INNER_TTP = 9292;
42
42
  const TWIPS_PER_POINT = 20;
@@ -135,7 +135,9 @@ function applyParagraphSprms(prls, into) {
135
135
  into.tableDepth = require_bytes.readUint32LE(prl.operand, 0);
136
136
  break;
137
137
  case SPRM_P_F_INNER_TABLE_CELL:
138
- case SPRM_P_F_INNER_TTP: if (require_bytes.readUint8(prl.operand, 0) !== 0) into.nestedTableMark = true;
138
+ into.innerTableCellMark = require_bytes.readUint8(prl.operand, 0) !== 0;
139
+ break;
140
+ case SPRM_P_F_INNER_TTP: into.innerTtpMark = require_bytes.readUint8(prl.operand, 0) !== 0;
139
141
  }
140
142
  }
141
143
  return into;
@@ -1,2 +1,2 @@
1
- import { n as applyParagraphSprms, t as ParagraphProperties } from "../pap-BT1p0uzu.cjs";
1
+ import { n as applyParagraphSprms, t as ParagraphProperties } from "../pap-BQ2E17K9.cjs";
2
2
  export { ParagraphProperties, applyParagraphSprms };
@@ -1,2 +1,2 @@
1
- import { n as applyParagraphSprms, t as ParagraphProperties } from "../pap-DOFLMWcG.js";
1
+ import { n as applyParagraphSprms, t as ParagraphProperties } from "../pap-iWFIpCdo.js";
2
2
  export { ParagraphProperties, applyParagraphSprms };
package/dist/prop/pap.js CHANGED
@@ -35,7 +35,7 @@ const SPRM_P_ILVL = 9738;
35
35
  const SPRM_P_ILFO = 17931;
36
36
  /** sprmPItap: the paragraph's own table depth -- read only far enough to detect a depth greater than 1 (a table nested inside a table cell), which this package refuses rather than mis-reads. */
37
37
  const SPRM_P_ITAP = 26185;
38
- /** sprmPFInnerTableCell / sprmPFInnerTtp: a nested table's own cell-ending or row-ending mark. Neither is acted on beyond refusing the nested table it signals. */
38
+ /** sprmPFInnerTableCell / sprmPFInnerTtp: a nested table's (table depth greater than 1) own cell-ending or row-ending mark, [MS-DOC] 2.4.3's Overview of Tables -- the paragraph-mark (0x000D) analogues of sprmPFInTable's cell-mark (0x0007) boundary and sprmPFTtp's row-mark at depth 1. */
39
39
  const SPRM_P_F_INNER_TABLE_CELL = 9291;
40
40
  const SPRM_P_F_INNER_TTP = 9292;
41
41
  const TWIPS_PER_POINT = 20;
@@ -134,7 +134,9 @@ function applyParagraphSprms(prls, into) {
134
134
  into.tableDepth = readUint32LE(prl.operand, 0);
135
135
  break;
136
136
  case SPRM_P_F_INNER_TABLE_CELL:
137
- case SPRM_P_F_INNER_TTP: if (readUint8(prl.operand, 0) !== 0) into.nestedTableMark = true;
137
+ into.innerTableCellMark = readUint8(prl.operand, 0) !== 0;
138
+ break;
139
+ case SPRM_P_F_INNER_TTP: into.innerTtpMark = readUint8(prl.operand, 0) !== 0;
138
140
  }
139
141
  }
140
142
  return into;
package/dist/prop/sep.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("../errors.cjs");
2
3
  const require_bytes = require("../bytes.cjs");
3
4
  const require_plc = require("../plc.cjs");
4
5
  const require_prop_sprm = require("./sprm.cjs");
@@ -47,17 +48,26 @@ function applySectionSprms(prls, into) {
47
48
  }
48
49
  return into;
49
50
  }
50
- /** Resolves the document's first section's own page size and margins from PlcfSed/Sepx -- absent entirely when the file carries no PlcfSed at all (lcbPlcfSed 0), which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does. This reader only ever resolves the section covering the whole main document (see read.ts's own DocContent comment on why more than one section is out of scope), so it reads PlcfSed's first Sed regardless of how many the file actually carries. */
51
- function readSectionProperties(wordDocument, table, fib) {
52
- if (fib.lcbPlcfSed === 0) return {};
51
+ /** Resolves every section PlcfSed/Sepx states, in document order -- a single zero-start entry with no properties when the file carries no PlcfSed at all (lcbPlcfSed 0) or an empty one, which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does, matching what a single-section document with no PlcfSed at all would resolve to anyway. */
52
+ function readAllSectionProperties(wordDocument, table, fib) {
53
+ if (fib.lcbPlcfSed === 0) return [{ startCp: 0 }];
53
54
  const plc = require_plc.parsePlc(require_bytes.slice(table, fib.fcPlcfSed, fib.lcbPlcfSed, "PlcfSed in the Table stream"), SED_SIZE, "PlcfSed");
54
- if (plc.count === 0) return {};
55
- const sed = plc.element(0);
56
- const fcSepx = require_bytes.readUint32LE(sed, SED_FC_SEPX_OFFSET);
57
- const cb = require_bytes.readUint16LE(wordDocument, fcSepx);
58
- const grpprl = require_bytes.slice(wordDocument, fcSepx + 2, cb, "Sepx grpprl in the WordDocument stream");
59
- return applySectionSprms(require_prop_sprm.readGrpprl(grpprl), {});
55
+ if (plc.count === 0) return [{ startCp: 0 }];
56
+ const sections = [];
57
+ for (let index = 0; index < plc.count; index += 1) {
58
+ const startCp = plc.keys[index];
59
+ if (startCp === void 0) throw new require_errors.DocFormatError(`internal defect: PlcfSed key ${index} is absent from a PLC of ${plc.count} elements`);
60
+ const sed = plc.element(index);
61
+ const fcSepx = require_bytes.readUint32LE(sed, SED_FC_SEPX_OFFSET);
62
+ const cb = require_bytes.readUint16LE(wordDocument, fcSepx);
63
+ const grpprl = require_bytes.slice(wordDocument, fcSepx + 2, cb, "Sepx grpprl in the WordDocument stream");
64
+ sections.push({
65
+ startCp,
66
+ ...applySectionSprms(require_prop_sprm.readGrpprl(grpprl), {})
67
+ });
68
+ }
69
+ return sections;
60
70
  }
61
71
  //#endregion
62
72
  exports.applySectionSprms = applySectionSprms;
63
- exports.readSectionProperties = readSectionProperties;
73
+ exports.readAllSectionProperties = readAllSectionProperties;
@@ -1,4 +1,4 @@
1
- import { t as Fib } from "../fib-DWFta19r.cjs";
1
+ import { t as Fib } from "../fib-6BFIx153.cjs";
2
2
  import { t as Prl } from "../sprm-DEyvdOo0.cjs";
3
3
  //#region src/prop/sep.d.ts
4
4
  interface SectionProperties {
@@ -10,7 +10,11 @@ interface SectionProperties {
10
10
  marginBottomPt?: number;
11
11
  }
12
12
  declare function applySectionSprms(prls: readonly Prl[], into: SectionProperties): SectionProperties;
13
- /** Resolves the document's first section's own page size and margins from PlcfSed/Sepx -- absent entirely when the file carries no PlcfSed at all (lcbPlcfSed 0), which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does. This reader only ever resolves the section covering the whole main document (see read.ts's own DocContent comment on why more than one section is out of scope), so it reads PlcfSed's first Sed regardless of how many the file actually carries. */
14
- declare function readSectionProperties(wordDocument: Uint8Array, table: Uint8Array, fib: Pick<Fib, "fcPlcfSed" | "lcbPlcfSed">): SectionProperties;
13
+ /** One section's own resolved properties (page size, margins) alongside `startCp`, the character position PlcfSed.aCp[i] names as where its text begins in the main document -- [MS-DOC] 2.8.26: "Each CP specifies the beginning of a range of text in the main document that constitutes a section." read.ts's own splitIntoSections groups the main document's paragraph entries by these boundaries. */
14
+ interface DocSectionProperties extends SectionProperties {
15
+ readonly startCp: number;
16
+ }
17
+ /** Resolves every section PlcfSed/Sepx states, in document order -- a single zero-start entry with no properties when the file carries no PlcfSed at all (lcbPlcfSed 0) or an empty one, which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does, matching what a single-section document with no PlcfSed at all would resolve to anyway. */
18
+ declare function readAllSectionProperties(wordDocument: Uint8Array, table: Uint8Array, fib: Pick<Fib, "fcPlcfSed" | "lcbPlcfSed">): readonly DocSectionProperties[];
15
19
  //#endregion
16
- export { SectionProperties, applySectionSprms, readSectionProperties };
20
+ export { DocSectionProperties, SectionProperties, applySectionSprms, readAllSectionProperties };
@@ -1,4 +1,4 @@
1
- import { t as Fib } from "../fib-DWFta19r.js";
1
+ import { t as Fib } from "../fib-6BFIx153.js";
2
2
  import { t as Prl } from "../sprm-DEyvdOo0.js";
3
3
  //#region src/prop/sep.d.ts
4
4
  interface SectionProperties {
@@ -10,7 +10,11 @@ interface SectionProperties {
10
10
  marginBottomPt?: number;
11
11
  }
12
12
  declare function applySectionSprms(prls: readonly Prl[], into: SectionProperties): SectionProperties;
13
- /** Resolves the document's first section's own page size and margins from PlcfSed/Sepx -- absent entirely when the file carries no PlcfSed at all (lcbPlcfSed 0), which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does. This reader only ever resolves the section covering the whole main document (see read.ts's own DocContent comment on why more than one section is out of scope), so it reads PlcfSed's first Sed regardless of how many the file actually carries. */
14
- declare function readSectionProperties(wordDocument: Uint8Array, table: Uint8Array, fib: Pick<Fib, "fcPlcfSed" | "lcbPlcfSed">): SectionProperties;
13
+ /** One section's own resolved properties (page size, margins) alongside `startCp`, the character position PlcfSed.aCp[i] names as where its text begins in the main document -- [MS-DOC] 2.8.26: "Each CP specifies the beginning of a range of text in the main document that constitutes a section." read.ts's own splitIntoSections groups the main document's paragraph entries by these boundaries. */
14
+ interface DocSectionProperties extends SectionProperties {
15
+ readonly startCp: number;
16
+ }
17
+ /** Resolves every section PlcfSed/Sepx states, in document order -- a single zero-start entry with no properties when the file carries no PlcfSed at all (lcbPlcfSed 0) or an empty one, which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does, matching what a single-section document with no PlcfSed at all would resolve to anyway. */
18
+ declare function readAllSectionProperties(wordDocument: Uint8Array, table: Uint8Array, fib: Pick<Fib, "fcPlcfSed" | "lcbPlcfSed">): readonly DocSectionProperties[];
15
19
  //#endregion
16
- export { SectionProperties, applySectionSprms, readSectionProperties };
20
+ export { DocSectionProperties, SectionProperties, applySectionSprms, readAllSectionProperties };
package/dist/prop/sep.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { DocFormatError } from "../errors.js";
1
2
  import { readInt16LE, readUint16LE, readUint32LE, slice } from "../bytes.js";
2
3
  import { parsePlc } from "../plc.js";
3
4
  import { SGC, readGrpprl } from "./sprm.js";
@@ -46,16 +47,25 @@ function applySectionSprms(prls, into) {
46
47
  }
47
48
  return into;
48
49
  }
49
- /** Resolves the document's first section's own page size and margins from PlcfSed/Sepx -- absent entirely when the file carries no PlcfSed at all (lcbPlcfSed 0), which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does. This reader only ever resolves the section covering the whole main document (see read.ts's own DocContent comment on why more than one section is out of scope), so it reads PlcfSed's first Sed regardless of how many the file actually carries. */
50
- function readSectionProperties(wordDocument, table, fib) {
51
- if (fib.lcbPlcfSed === 0) return {};
50
+ /** Resolves every section PlcfSed/Sepx states, in document order -- a single zero-start entry with no properties when the file carries no PlcfSed at all (lcbPlcfSed 0) or an empty one, which read.ts's own DEFAULT_PAGE_SIZE/DEFAULT_MARGINS then stand in for field by field, exactly as an individual unstated sprm already does, matching what a single-section document with no PlcfSed at all would resolve to anyway. */
51
+ function readAllSectionProperties(wordDocument, table, fib) {
52
+ if (fib.lcbPlcfSed === 0) return [{ startCp: 0 }];
52
53
  const plc = parsePlc(slice(table, fib.fcPlcfSed, fib.lcbPlcfSed, "PlcfSed in the Table stream"), SED_SIZE, "PlcfSed");
53
- if (plc.count === 0) return {};
54
- const sed = plc.element(0);
55
- const fcSepx = readUint32LE(sed, SED_FC_SEPX_OFFSET);
56
- const cb = readUint16LE(wordDocument, fcSepx);
57
- const grpprl = slice(wordDocument, fcSepx + 2, cb, "Sepx grpprl in the WordDocument stream");
58
- return applySectionSprms(readGrpprl(grpprl), {});
54
+ if (plc.count === 0) return [{ startCp: 0 }];
55
+ const sections = [];
56
+ for (let index = 0; index < plc.count; index += 1) {
57
+ const startCp = plc.keys[index];
58
+ if (startCp === void 0) throw new DocFormatError(`internal defect: PlcfSed key ${index} is absent from a PLC of ${plc.count} elements`);
59
+ const sed = plc.element(index);
60
+ const fcSepx = readUint32LE(sed, SED_FC_SEPX_OFFSET);
61
+ const cb = readUint16LE(wordDocument, fcSepx);
62
+ const grpprl = slice(wordDocument, fcSepx + 2, cb, "Sepx grpprl in the WordDocument stream");
63
+ sections.push({
64
+ startCp,
65
+ ...applySectionSprms(readGrpprl(grpprl), {})
66
+ });
67
+ }
68
+ return sections;
59
69
  }
60
70
  //#endregion
61
- export { applySectionSprms, readSectionProperties };
71
+ export { applySectionSprms, readAllSectionProperties };