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,40 @@
1
+ import { t as Prl } from "./sprm-DEyvdOo0.cjs";
2
+ //#region src/style/stsh.d.ts
3
+ /** StdfBase.sti's "0x0FFE for user-defined styles"; anything else is an application-defined style whose sti identifies it. */
4
+ declare const STI_USER_DEFINED = 4094;
5
+ /** StdfBase.stk, [MS-DOC] 2.9.269 -- which of ECMA-376's ST_StyleType values this style is. */
6
+ declare const STK: {
7
+ readonly paragraph: 1;
8
+ readonly character: 2;
9
+ readonly table: 3;
10
+ readonly numbering: 4;
11
+ };
12
+ interface Style {
13
+ /** The style's index in STSH.rglpstd, which is what sprmPIstd and sprmCIstd name. */
14
+ readonly istd: number;
15
+ /** The invariant application-defined style identifier, or STI_USER_DEFINED for a style the document itself defines. */
16
+ readonly sti: number;
17
+ readonly stk: number;
18
+ /** The istd this style inherits from, or undefined when StdfBase.istdBase is 0x0FFF ("this style does not inherit from any other style"). */
19
+ readonly istdBase: number | undefined;
20
+ /** The style's primary name, from the STD's own Xstz. */
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;
26
+ }
27
+ interface StyleSheet {
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"). */
29
+ readonly styles: readonly (Style | undefined)[];
30
+ }
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;
37
+ declare function headingLevelFromIstd(istd: number): number | undefined;
38
+ declare function buildStshForStyles(names: ReadonlyMap<number, string>): Uint8Array;
39
+ //#endregion
40
+ export { StyleSheet as a, parseStsh as c, Style as i, resolveStyleFormatting as l, STI_USER_DEFINED as n, buildStshForStyles as o, STK as r, headingLevelFromIstd as s, ResolvedStyleFormatting as t };
@@ -1,40 +1,2 @@
1
- import { t as Prl } from "../sprm-DEyvdOo0.cjs";
2
- //#region src/style/stsh.d.ts
3
- /** StdfBase.sti's "0x0FFE for user-defined styles"; anything else is an application-defined style whose sti identifies it. */
4
- declare const STI_USER_DEFINED = 4094;
5
- /** StdfBase.stk, [MS-DOC] 2.9.269 -- which of ECMA-376's ST_StyleType values this style is. */
6
- declare const STK: {
7
- readonly paragraph: 1;
8
- readonly character: 2;
9
- readonly table: 3;
10
- readonly numbering: 4;
11
- };
12
- interface Style {
13
- /** The style's index in STSH.rglpstd, which is what sprmPIstd and sprmCIstd name. */
14
- readonly istd: number;
15
- /** The invariant application-defined style identifier, or STI_USER_DEFINED for a style the document itself defines. */
16
- readonly sti: number;
17
- readonly stk: number;
18
- /** The istd this style inherits from, or undefined when StdfBase.istdBase is 0x0FFF ("this style does not inherit from any other style"). */
19
- readonly istdBase: number | undefined;
20
- /** The style's primary name, from the STD's own Xstz. */
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;
26
- }
27
- interface StyleSheet {
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"). */
29
- readonly styles: readonly (Style | undefined)[];
30
- }
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;
37
- declare function headingLevelFromIstd(istd: number): number | undefined;
38
- declare function buildStshForStyles(names: ReadonlyMap<number, string>): Uint8Array;
39
- //#endregion
1
+ import { a as StyleSheet, c as parseStsh, i as Style, l as resolveStyleFormatting, n as STI_USER_DEFINED, o as buildStshForStyles, r as STK, s as headingLevelFromIstd, t as ResolvedStyleFormatting } from "../stsh-CK59x6XG.cjs";
40
2
  export { ResolvedStyleFormatting, STI_USER_DEFINED, STK, Style, StyleSheet, buildStshForStyles, headingLevelFromIstd, parseStsh, resolveStyleFormatting };
@@ -1,40 +1,2 @@
1
- import { t as Prl } from "../sprm-DEyvdOo0.js";
2
- //#region src/style/stsh.d.ts
3
- /** StdfBase.sti's "0x0FFE for user-defined styles"; anything else is an application-defined style whose sti identifies it. */
4
- declare const STI_USER_DEFINED = 4094;
5
- /** StdfBase.stk, [MS-DOC] 2.9.269 -- which of ECMA-376's ST_StyleType values this style is. */
6
- declare const STK: {
7
- readonly paragraph: 1;
8
- readonly character: 2;
9
- readonly table: 3;
10
- readonly numbering: 4;
11
- };
12
- interface Style {
13
- /** The style's index in STSH.rglpstd, which is what sprmPIstd and sprmCIstd name. */
14
- readonly istd: number;
15
- /** The invariant application-defined style identifier, or STI_USER_DEFINED for a style the document itself defines. */
16
- readonly sti: number;
17
- readonly stk: number;
18
- /** The istd this style inherits from, or undefined when StdfBase.istdBase is 0x0FFF ("this style does not inherit from any other style"). */
19
- readonly istdBase: number | undefined;
20
- /** The style's primary name, from the STD's own Xstz. */
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;
26
- }
27
- interface StyleSheet {
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"). */
29
- readonly styles: readonly (Style | undefined)[];
30
- }
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;
37
- declare function headingLevelFromIstd(istd: number): number | undefined;
38
- declare function buildStshForStyles(names: ReadonlyMap<number, string>): Uint8Array;
39
- //#endregion
1
+ import { a as StyleSheet, c as parseStsh, i as Style, l as resolveStyleFormatting, n as STI_USER_DEFINED, o as buildStshForStyles, r as STK, s as headingLevelFromIstd, t as ResolvedStyleFormatting } from "../stsh-Bj0YSEOp.js";
40
2
  export { ResolvedStyleFormatting, STI_USER_DEFINED, STK, Style, StyleSheet, buildStshForStyles, headingLevelFromIstd, parseStsh, resolveStyleFormatting };
@@ -0,0 +1,20 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_bytes = require("./bytes.cjs");
3
+ const require_plc = require("./plc.cjs");
4
+ const require_text_paragraphs = require("./text/paragraphs.cjs");
5
+ const require_text_characters = require("./text/characters.cjs");
6
+ //#region src/subdocument.ts
7
+ function readSubdocumentStories(wordDocument, table, pieceTable, context, subdocStartCp, subdocLength, boundaryFc, boundaryLcb, what) {
8
+ if (subdocLength <= 0 || boundaryLcb <= 0) return [];
9
+ const range = require_text_characters.readTextRange(wordDocument, pieceTable, subdocStartCp, subdocStartCp + subdocLength);
10
+ const entries = require_text_paragraphs.readParagraphs(range.text, range.fcs, context);
11
+ const plc = require_plc.parsePlc(require_bytes.slice(table, boundaryFc, boundaryLcb, `${what} in the Table stream`), 0, what);
12
+ return require_text_paragraphs.splitEntriesByBoundaries(entries, plc.keys).slice(0, -1).map((story) => story.slice(0, -1));
13
+ }
14
+ /** Joins a story's own paragraphs into plain text -- one line per paragraph, matching how ooxml.js's own Footnote/Comment reading concatenates a footnote or comment body's `w:t` runs rather than preserving paragraph/run structure. A footnote, endnote, or comment in this family is carried as text alone; only a header or footer keeps real block flow (headers-footers.ts). Non-paragraph blocks a story's own entries produced (an inline picture split out of one of its paragraphs) contribute no text of their own here, the same way an image has no plain-text spelling in ooxml.js's own footnote/comment reading either. */
15
+ function storyText(entries) {
16
+ return entries.map((entry) => entry.blocks.flatMap((block) => block.kind === "paragraph" ? block.runs : []).map((run) => run.text).join("")).join("\n");
17
+ }
18
+ //#endregion
19
+ exports.readSubdocumentStories = readSubdocumentStories;
20
+ exports.storyText = storyText;
@@ -0,0 +1,8 @@
1
+ import { n as ReadContext, t as ParagraphEntry } from "./paragraphs-DQUp8_HB.cjs";
2
+ import { n as PieceTable } from "./piece-table-CA18mhjv.cjs";
3
+ //#region src/subdocument.d.ts
4
+ declare function readSubdocumentStories(wordDocument: Uint8Array, table: Uint8Array, pieceTable: PieceTable, context: ReadContext, subdocStartCp: number, subdocLength: number, boundaryFc: number, boundaryLcb: number, what: string): readonly ParagraphEntry[][];
5
+ /** Joins a story's own paragraphs into plain text -- one line per paragraph, matching how ooxml.js's own Footnote/Comment reading concatenates a footnote or comment body's `w:t` runs rather than preserving paragraph/run structure. A footnote, endnote, or comment in this family is carried as text alone; only a header or footer keeps real block flow (headers-footers.ts). Non-paragraph blocks a story's own entries produced (an inline picture split out of one of its paragraphs) contribute no text of their own here, the same way an image has no plain-text spelling in ooxml.js's own footnote/comment reading either. */
6
+ declare function storyText(entries: readonly ParagraphEntry[]): string;
7
+ //#endregion
8
+ export { readSubdocumentStories, storyText };
@@ -0,0 +1,8 @@
1
+ import { n as ReadContext, t as ParagraphEntry } from "./paragraphs-s2lJ6w2I.js";
2
+ import { n as PieceTable } from "./piece-table-CA18mhjv.js";
3
+ //#region src/subdocument.d.ts
4
+ declare function readSubdocumentStories(wordDocument: Uint8Array, table: Uint8Array, pieceTable: PieceTable, context: ReadContext, subdocStartCp: number, subdocLength: number, boundaryFc: number, boundaryLcb: number, what: string): readonly ParagraphEntry[][];
5
+ /** Joins a story's own paragraphs into plain text -- one line per paragraph, matching how ooxml.js's own Footnote/Comment reading concatenates a footnote or comment body's `w:t` runs rather than preserving paragraph/run structure. A footnote, endnote, or comment in this family is carried as text alone; only a header or footer keeps real block flow (headers-footers.ts). Non-paragraph blocks a story's own entries produced (an inline picture split out of one of its paragraphs) contribute no text of their own here, the same way an image has no plain-text spelling in ooxml.js's own footnote/comment reading either. */
6
+ declare function storyText(entries: readonly ParagraphEntry[]): string;
7
+ //#endregion
8
+ export { readSubdocumentStories, storyText };
@@ -0,0 +1,18 @@
1
+ import { slice } from "./bytes.js";
2
+ import { parsePlc } from "./plc.js";
3
+ import { readParagraphs, splitEntriesByBoundaries } from "./text/paragraphs.js";
4
+ import { readTextRange } from "./text/characters.js";
5
+ //#region src/subdocument.ts
6
+ function readSubdocumentStories(wordDocument, table, pieceTable, context, subdocStartCp, subdocLength, boundaryFc, boundaryLcb, what) {
7
+ if (subdocLength <= 0 || boundaryLcb <= 0) return [];
8
+ const range = readTextRange(wordDocument, pieceTable, subdocStartCp, subdocStartCp + subdocLength);
9
+ const entries = readParagraphs(range.text, range.fcs, context);
10
+ const plc = parsePlc(slice(table, boundaryFc, boundaryLcb, `${what} in the Table stream`), 0, what);
11
+ return splitEntriesByBoundaries(entries, plc.keys).slice(0, -1).map((story) => story.slice(0, -1));
12
+ }
13
+ /** Joins a story's own paragraphs into plain text -- one line per paragraph, matching how ooxml.js's own Footnote/Comment reading concatenates a footnote or comment body's `w:t` runs rather than preserving paragraph/run structure. A footnote, endnote, or comment in this family is carried as text alone; only a header or footer keeps real block flow (headers-footers.ts). Non-paragraph blocks a story's own entries produced (an inline picture split out of one of its paragraphs) contribute no text of their own here, the same way an image has no plain-text spelling in ooxml.js's own footnote/comment reading either. */
14
+ function storyText(entries) {
15
+ return entries.map((entry) => entry.blocks.flatMap((block) => block.kind === "paragraph" ? block.runs : []).map((run) => run.text).join("")).join("\n");
16
+ }
17
+ //#endregion
18
+ export { readSubdocumentStories, storyText };
@@ -23,30 +23,44 @@ function effectiveColumnBoundaryTolerance(definitions) {
23
23
  return narrowestRealGapTwips === void 0 ? TWIPS_PER_POINT : Math.min(TWIPS_PER_POINT, narrowestRealGapTwips - 1);
24
24
  }
25
25
  function assembleBlocks(entries) {
26
+ return walkBlocksAtDepth(entries, 0);
27
+ }
28
+ function effectiveTableDepth(properties) {
29
+ if (properties.tableDepth !== void 0) return properties.tableDepth;
30
+ return properties.inTable === true ? 1 : 0;
31
+ }
32
+ function isCellBoundary(entry, tableDepth) {
33
+ if (tableDepth === 1) return entry.terminator === 7 && entry.properties.tableRowEnd !== true;
34
+ return entry.terminator === 13 && entry.properties.innerTableCellMark === true;
35
+ }
36
+ function isRowBoundary(entry, tableDepth) {
37
+ return tableDepth === 1 ? entry.properties.tableRowEnd === true : entry.properties.innerTtpMark === true;
38
+ }
39
+ function walkBlocksAtDepth(entries, depth) {
26
40
  const blocks = [];
27
41
  let index = 0;
28
42
  while (index < entries.length) {
29
43
  const entry = entries[index];
30
44
  if (entry === void 0) break;
31
- if (entry.properties.inTable !== true) {
32
- blocks.push(entry.paragraph);
45
+ if (effectiveTableDepth(entry.properties) <= depth) {
46
+ blocks.push(...entry.blocks);
33
47
  index += 1;
34
48
  continue;
35
49
  }
36
- const { runEntries, nextIndex } = collectTableRun(entries, index);
37
- const table = tryAssembleTable(runEntries);
38
- blocks.push(...table !== void 0 ? [table] : runEntries.map((run) => run.paragraph));
50
+ const tableDepth = depth + 1;
51
+ const { runEntries, nextIndex } = collectTableRun(entries, index, tableDepth);
52
+ const table = tryAssembleTable(runEntries, tableDepth);
53
+ blocks.push(...table !== void 0 ? [table] : runEntries.flatMap((run) => run.blocks));
39
54
  index = nextIndex;
40
55
  }
41
56
  return blocks;
42
57
  }
43
- function collectTableRun(entries, start) {
58
+ function collectTableRun(entries, start, tableDepth) {
44
59
  const runEntries = [];
45
60
  let index = start;
46
61
  while (index < entries.length) {
47
62
  const entry = entries[index];
48
- if (entry?.properties.inTable !== true) break;
49
- if (entry.properties.tableDepth !== void 0 && entry.properties.tableDepth > 1 || entry.properties.nestedTableMark === true) throw new require_errors.DocUnsupportedError("doc-codec does not support a table nested inside a table cell (table depth greater than 1)");
63
+ if (entry === void 0 || effectiveTableDepth(entry.properties) < tableDepth) break;
50
64
  runEntries.push(entry);
51
65
  index += 1;
52
66
  }
@@ -55,15 +69,15 @@ function collectTableRun(entries, start) {
55
69
  nextIndex: index
56
70
  };
57
71
  }
58
- function tryAssembleTable(runEntries) {
72
+ function tryAssembleTable(runEntries, tableDepth) {
59
73
  const rawRows = [];
60
74
  const rowDefinitions = [];
61
75
  const rowHeights = [];
62
- let cellParagraphs = [];
76
+ let cellEntries = [];
63
77
  let rowCells = [];
64
78
  for (const entry of runEntries) {
65
- cellParagraphs.push(entry.paragraph);
66
- if (entry.properties.tableRowEnd === true) {
79
+ cellEntries.push(entry);
80
+ if (isRowBoundary(entry, tableDepth)) {
67
81
  const rowProperties = require_table_tap.applyTableSprms(entry.grpprl, {});
68
82
  const definition = rowProperties.definition;
69
83
  if (definition === void 0) return void 0;
@@ -83,15 +97,15 @@ function tryAssembleTable(runEntries) {
83
97
  rowDefinitions.push(definition);
84
98
  rowHeights.push(rowProperties.heightPt);
85
99
  rowCells = [];
86
- cellParagraphs = [];
100
+ cellEntries = [];
87
101
  continue;
88
102
  }
89
- if (entry.terminator === 7) {
90
- rowCells.push({ blocks: cellParagraphs });
91
- cellParagraphs = [];
103
+ if (isCellBoundary(entry, tableDepth)) {
104
+ rowCells.push({ blocks: walkBlocksAtDepth(cellEntries, tableDepth) });
105
+ cellEntries = [];
92
106
  }
93
107
  }
94
- if (cellParagraphs.length > 0 || rowCells.length > 0) throw new require_errors.DocFormatError("a table's paragraphs end without a row-ending mark to close the row's last cell");
108
+ if (cellEntries.length > 0 || rowCells.length > 0) throw new require_errors.DocFormatError("a table's paragraphs end without a row-ending mark to close the row's last cell");
95
109
  const toleranceTwips = effectiveColumnBoundaryTolerance(rowDefinitions);
96
110
  const columnBoundariesTwips = canonicalColumnBoundariesTwips(rowDefinitions, toleranceTwips);
97
111
  return {
@@ -1,4 +1,4 @@
1
- import { ParagraphEntry } from "../read.cjs";
1
+ import { t as ParagraphEntry } from "../paragraphs-DQUp8_HB.cjs";
2
2
  import { ContentBlock } from "document-schema.js";
3
3
  //#region src/table/read.d.ts
4
4
  declare function assembleBlocks(entries: readonly ParagraphEntry[]): ContentBlock[];
@@ -1,4 +1,4 @@
1
- import { ParagraphEntry } from "../read.js";
1
+ import { t as ParagraphEntry } from "../paragraphs-s2lJ6w2I.js";
2
2
  import { ContentBlock } from "document-schema.js";
3
3
  //#region src/table/read.d.ts
4
4
  declare function assembleBlocks(entries: readonly ParagraphEntry[]): ContentBlock[];
@@ -1,4 +1,4 @@
1
- import { DocFormatError, DocUnsupportedError } from "../errors.js";
1
+ import { DocFormatError } from "../errors.js";
2
2
  import "../text/special.js";
3
3
  import { cellBordersFrom } from "./decoration.js";
4
4
  import { applyTableSprms } from "./tap.js";
@@ -22,30 +22,44 @@ function effectiveColumnBoundaryTolerance(definitions) {
22
22
  return narrowestRealGapTwips === void 0 ? TWIPS_PER_POINT : Math.min(TWIPS_PER_POINT, narrowestRealGapTwips - 1);
23
23
  }
24
24
  function assembleBlocks(entries) {
25
+ return walkBlocksAtDepth(entries, 0);
26
+ }
27
+ function effectiveTableDepth(properties) {
28
+ if (properties.tableDepth !== void 0) return properties.tableDepth;
29
+ return properties.inTable === true ? 1 : 0;
30
+ }
31
+ function isCellBoundary(entry, tableDepth) {
32
+ if (tableDepth === 1) return entry.terminator === 7 && entry.properties.tableRowEnd !== true;
33
+ return entry.terminator === 13 && entry.properties.innerTableCellMark === true;
34
+ }
35
+ function isRowBoundary(entry, tableDepth) {
36
+ return tableDepth === 1 ? entry.properties.tableRowEnd === true : entry.properties.innerTtpMark === true;
37
+ }
38
+ function walkBlocksAtDepth(entries, depth) {
25
39
  const blocks = [];
26
40
  let index = 0;
27
41
  while (index < entries.length) {
28
42
  const entry = entries[index];
29
43
  if (entry === void 0) break;
30
- if (entry.properties.inTable !== true) {
31
- blocks.push(entry.paragraph);
44
+ if (effectiveTableDepth(entry.properties) <= depth) {
45
+ blocks.push(...entry.blocks);
32
46
  index += 1;
33
47
  continue;
34
48
  }
35
- const { runEntries, nextIndex } = collectTableRun(entries, index);
36
- const table = tryAssembleTable(runEntries);
37
- blocks.push(...table !== void 0 ? [table] : runEntries.map((run) => run.paragraph));
49
+ const tableDepth = depth + 1;
50
+ const { runEntries, nextIndex } = collectTableRun(entries, index, tableDepth);
51
+ const table = tryAssembleTable(runEntries, tableDepth);
52
+ blocks.push(...table !== void 0 ? [table] : runEntries.flatMap((run) => run.blocks));
38
53
  index = nextIndex;
39
54
  }
40
55
  return blocks;
41
56
  }
42
- function collectTableRun(entries, start) {
57
+ function collectTableRun(entries, start, tableDepth) {
43
58
  const runEntries = [];
44
59
  let index = start;
45
60
  while (index < entries.length) {
46
61
  const entry = entries[index];
47
- if (entry?.properties.inTable !== true) break;
48
- if (entry.properties.tableDepth !== void 0 && entry.properties.tableDepth > 1 || entry.properties.nestedTableMark === true) throw new DocUnsupportedError("doc-codec does not support a table nested inside a table cell (table depth greater than 1)");
62
+ if (entry === void 0 || effectiveTableDepth(entry.properties) < tableDepth) break;
49
63
  runEntries.push(entry);
50
64
  index += 1;
51
65
  }
@@ -54,15 +68,15 @@ function collectTableRun(entries, start) {
54
68
  nextIndex: index
55
69
  };
56
70
  }
57
- function tryAssembleTable(runEntries) {
71
+ function tryAssembleTable(runEntries, tableDepth) {
58
72
  const rawRows = [];
59
73
  const rowDefinitions = [];
60
74
  const rowHeights = [];
61
- let cellParagraphs = [];
75
+ let cellEntries = [];
62
76
  let rowCells = [];
63
77
  for (const entry of runEntries) {
64
- cellParagraphs.push(entry.paragraph);
65
- if (entry.properties.tableRowEnd === true) {
78
+ cellEntries.push(entry);
79
+ if (isRowBoundary(entry, tableDepth)) {
66
80
  const rowProperties = applyTableSprms(entry.grpprl, {});
67
81
  const definition = rowProperties.definition;
68
82
  if (definition === void 0) return void 0;
@@ -82,15 +96,15 @@ function tryAssembleTable(runEntries) {
82
96
  rowDefinitions.push(definition);
83
97
  rowHeights.push(rowProperties.heightPt);
84
98
  rowCells = [];
85
- cellParagraphs = [];
99
+ cellEntries = [];
86
100
  continue;
87
101
  }
88
- if (entry.terminator === 7) {
89
- rowCells.push({ blocks: cellParagraphs });
90
- cellParagraphs = [];
102
+ if (isCellBoundary(entry, tableDepth)) {
103
+ rowCells.push({ blocks: walkBlocksAtDepth(cellEntries, tableDepth) });
104
+ cellEntries = [];
91
105
  }
92
106
  }
93
- if (cellParagraphs.length > 0 || rowCells.length > 0) throw new DocFormatError("a table's paragraphs end without a row-ending mark to close the row's last cell");
107
+ if (cellEntries.length > 0 || rowCells.length > 0) throw new DocFormatError("a table's paragraphs end without a row-ending mark to close the row's last cell");
94
108
  const toleranceTwips = effectiveColumnBoundaryTolerance(rowDefinitions);
95
109
  const columnBoundariesTwips = canonicalColumnBoundariesTwips(rowDefinitions, toleranceTwips);
96
110
  return {
@@ -1,4 +1,4 @@
1
- import { PieceTable } from "./piece-table.cjs";
1
+ import { n as PieceTable } from "../piece-table-CA18mhjv.cjs";
2
2
  //#region src/text/characters.d.ts
3
3
  declare const COMPRESSED_CHARACTER_MAP: ReadonlyMap<number, number>;
4
4
  interface TextRange {
@@ -1,4 +1,4 @@
1
- import { PieceTable } from "./piece-table.js";
1
+ import { n as PieceTable } from "../piece-table-CA18mhjv.js";
2
2
  //#region src/text/characters.d.ts
3
3
  declare const COMPRESSED_CHARACTER_MAP: ReadonlyMap<number, number>;
4
4
  interface TextRange {
@@ -0,0 +1,189 @@
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("../prop/sprm.cjs");
5
+ const require_prop_chp = require("../prop/chp.cjs");
6
+ const require_prop_pap = require("../prop/pap.cjs");
7
+ const require_pictures = require("../pictures.cjs");
8
+ const require_style_stsh = require("../style/stsh.cjs");
9
+ const require_text_special = require("./special.cjs");
10
+ //#region src/text/paragraphs.ts
11
+ function readParagraphs(text, fcs, context) {
12
+ const entries = [];
13
+ let start = 0;
14
+ for (let index = 0; index < text.length; index += 1) {
15
+ const code = text.charCodeAt(index);
16
+ if (!require_text_special.endsParagraph(code)) continue;
17
+ const markFc = fcs[index];
18
+ if (markFc === void 0) throw new require_errors.DocFormatError(`character ${index} has no byte offset, so its paragraph's properties cannot be located`);
19
+ entries.push(buildParagraph(text.slice(start, index), fcs.slice(start, index), markFc, code, index + 1, context));
20
+ start = index + 1;
21
+ }
22
+ if (start < text.length) {
23
+ const firstFc = fcs[start];
24
+ if (firstFc === void 0) throw new require_errors.DocFormatError(`character ${start} has no byte offset, so the trailing paragraph's properties cannot be located`);
25
+ entries.push(buildParagraph(text.slice(start), fcs.slice(start), firstFc, 13, text.length, context));
26
+ }
27
+ return entries;
28
+ }
29
+ function buildParagraph(text, fcs, propertyFc, terminator, endCp, context) {
30
+ const papx = context.papxTable.papx(propertyFc);
31
+ const properties = {};
32
+ const grpprl = papx !== void 0 ? require_prop_sprm.readGrpprl(papx.grpprl) : [];
33
+ if (papx !== void 0) {
34
+ properties.istd = papx.istd;
35
+ if (context.styles !== void 0) require_prop_pap.applyParagraphSprms(require_style_stsh.resolveStyleFormatting(context.styles, papx.istd).paragraphPrls, properties);
36
+ require_prop_pap.applyParagraphSprms(grpprl, properties);
37
+ }
38
+ return {
39
+ blocks: buildParagraphBlocks(text, fcs, context, papx?.istd, paragraphAttributes(properties, context)),
40
+ properties,
41
+ grpprl,
42
+ terminator,
43
+ endCp
44
+ };
45
+ }
46
+ function buildParagraphBlocks(text, fcs, context, paragraphIstd, attributes) {
47
+ const blocks = [];
48
+ let segmentStart = 0;
49
+ const flushSegment = (end) => {
50
+ if (end <= segmentStart) return;
51
+ const runs = buildRuns(text.slice(segmentStart, end), fcs.slice(segmentStart, end), context, paragraphIstd);
52
+ blocks.push({
53
+ kind: "paragraph",
54
+ runs,
55
+ ...attributes
56
+ });
57
+ };
58
+ for (let index = 0; index < text.length; index += 1) {
59
+ if (text.charCodeAt(index) !== 1) continue;
60
+ flushSegment(index);
61
+ const fc = fcs[index];
62
+ const image = fc === void 0 ? void 0 : resolveInlinePicture(context, fc);
63
+ if (image !== void 0) blocks.push(image);
64
+ segmentStart = index + 1;
65
+ }
66
+ flushSegment(text.length);
67
+ if (blocks.length === 0) blocks.push({
68
+ kind: "paragraph",
69
+ runs: [],
70
+ ...attributes
71
+ });
72
+ return blocks;
73
+ }
74
+ const SPRM_C_PIC_LOCATION = 27139;
75
+ function resolveInlinePicture(context, fc) {
76
+ if (context.dataStream === void 0) return void 0;
77
+ const grpprl = context.chpxTable.chpxGrpprl(fc);
78
+ if (grpprl === void 0) return void 0;
79
+ for (const prl of require_prop_sprm.readGrpprl(grpprl)) {
80
+ if (prl.sprm.value !== SPRM_C_PIC_LOCATION) continue;
81
+ const picLocation = require_bytes.readInt32LE(prl.operand, 0);
82
+ return require_pictures.readInlinePicture(context.dataStream, picLocation);
83
+ }
84
+ }
85
+ function paragraphAttributes(properties, context) {
86
+ const attributes = {};
87
+ const istd = properties.istd;
88
+ if (istd !== void 0) {
89
+ const style = context.styles?.styles[istd];
90
+ if (style !== void 0 && style.name !== "") attributes.styleId = style.name;
91
+ const headingLevel = require_style_stsh.headingLevelFromIstd(istd);
92
+ if (headingLevel !== void 0) attributes.headingLevel = headingLevel;
93
+ }
94
+ if (attributes.headingLevel === void 0 && properties.outlineLevel !== void 0) attributes.headingLevel = properties.outlineLevel + 1;
95
+ if (properties.alignment !== void 0) attributes.alignment = properties.alignment;
96
+ if (properties.spacingBeforePt !== void 0) attributes.spacingBeforePt = properties.spacingBeforePt;
97
+ if (properties.spacingAfterPt !== void 0) attributes.spacingAfterPt = properties.spacingAfterPt;
98
+ if (properties.lineSpacing !== void 0) attributes.lineSpacing = properties.lineSpacing;
99
+ if (properties.indentLeftPt !== void 0) attributes.indentLeftPt = properties.indentLeftPt;
100
+ if (properties.indentRightPt !== void 0) attributes.indentRightPt = properties.indentRightPt;
101
+ if (properties.indentFirstLinePt !== void 0) attributes.indentFirstLinePt = properties.indentFirstLinePt;
102
+ if (properties.pageBreakBefore === true) attributes.pageBreakBefore = true;
103
+ if (properties.listId !== void 0) attributes.list = {
104
+ numId: String(properties.listId),
105
+ level: properties.listLevel ?? 0
106
+ };
107
+ return attributes;
108
+ }
109
+ function buildRuns(text, fcs, context, paragraphIstd) {
110
+ const runs = [];
111
+ let currentKey;
112
+ let currentText = "";
113
+ let currentProperties = {};
114
+ const paragraphStyleCharacterPrls = context.styles !== void 0 && paragraphIstd !== void 0 ? require_style_stsh.resolveStyleFormatting(context.styles, paragraphIstd).characterPrls : [];
115
+ const enclosingInstruction = [];
116
+ let inInstruction = false;
117
+ const flush = () => {
118
+ if (currentText !== "") runs.push({
119
+ text: currentText,
120
+ ...currentProperties
121
+ });
122
+ currentText = "";
123
+ };
124
+ for (let index = 0; index < text.length; index += 1) {
125
+ const code = text.charCodeAt(index);
126
+ if (code === 19) {
127
+ flush();
128
+ enclosingInstruction.push(inInstruction);
129
+ inInstruction = true;
130
+ continue;
131
+ }
132
+ if (code === 20) {
133
+ inInstruction = false;
134
+ continue;
135
+ }
136
+ if (code === 21) {
137
+ inInstruction = enclosingInstruction.pop() ?? inInstruction;
138
+ continue;
139
+ }
140
+ if (inInstruction || require_text_special.isAnchorOnly(code)) continue;
141
+ const fc = fcs[index];
142
+ if (fc === void 0) throw new require_errors.DocFormatError(`character ${index} of a paragraph has no byte offset, so its formatting cannot be located`);
143
+ const grpprl = context.chpxTable.chpxGrpprl(fc);
144
+ const chpxKey = grpprl === void 0 ? "none" : `${grpprl.byteOffset}:${grpprl.byteLength}`;
145
+ const key = `${paragraphIstd ?? "none"}:${chpxKey}`;
146
+ if (key !== currentKey) {
147
+ flush();
148
+ currentKey = key;
149
+ let properties = context.characterProperties.get(key);
150
+ if (properties === void 0) {
151
+ properties = {};
152
+ require_prop_chp.applyCharacterSprms(paragraphStyleCharacterPrls, properties, context.fonts);
153
+ if (grpprl !== void 0) {
154
+ const runPrls = require_prop_sprm.readGrpprl(grpprl);
155
+ const characterIstd = require_prop_chp.characterIstdFromGrpprl(runPrls);
156
+ if (characterIstd !== void 0 && context.styles !== void 0) require_prop_chp.applyCharacterSprms(require_style_stsh.resolveStyleFormatting(context.styles, characterIstd).characterPrls, properties, context.fonts);
157
+ require_prop_chp.applyCharacterSprms(runPrls, properties, context.fonts);
158
+ }
159
+ context.characterProperties.set(key, properties);
160
+ }
161
+ currentProperties = properties;
162
+ }
163
+ currentText += String.fromCharCode(code === 11 ? 10 : code);
164
+ }
165
+ flush();
166
+ return runs;
167
+ }
168
+ function splitEntriesByBoundaries(entries, boundaries) {
169
+ const groupCount = Math.max(boundaries.length - 1, 0);
170
+ const groups = Array.from({ length: groupCount }, () => []);
171
+ let index = 0;
172
+ const advancePastEmptyGroups = () => {
173
+ while (index < groupCount && boundaries[index] === boundaries[index + 1]) index += 1;
174
+ };
175
+ advancePastEmptyGroups();
176
+ for (const entry of entries) {
177
+ const group = groups[index];
178
+ if (group === void 0) break;
179
+ group.push(entry);
180
+ if (entry.endCp === boundaries[index + 1]) {
181
+ index += 1;
182
+ advancePastEmptyGroups();
183
+ }
184
+ }
185
+ return groups;
186
+ }
187
+ //#endregion
188
+ exports.readParagraphs = readParagraphs;
189
+ exports.splitEntriesByBoundaries = splitEntriesByBoundaries;
@@ -0,0 +1,2 @@
1
+ import { i as splitEntriesByBoundaries, n as ReadContext, r as readParagraphs, t as ParagraphEntry } from "../paragraphs-DQUp8_HB.cjs";
2
+ export { ParagraphEntry, ReadContext, readParagraphs, splitEntriesByBoundaries };
@@ -0,0 +1,2 @@
1
+ import { i as splitEntriesByBoundaries, n as ReadContext, r as readParagraphs, t as ParagraphEntry } from "../paragraphs-s2lJ6w2I.js";
2
+ export { ParagraphEntry, ReadContext, readParagraphs, splitEntriesByBoundaries };