@folijs/docx 0.4.0 → 0.6.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 (107) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +95 -15
  3. package/dist/export/balance.d.ts +17 -0
  4. package/dist/export/balance.d.ts.map +1 -0
  5. package/dist/export/balance.js +111 -0
  6. package/dist/export/balance.js.map +1 -0
  7. package/dist/export/content.d.ts +7 -0
  8. package/dist/export/content.d.ts.map +1 -1
  9. package/dist/export/content.js +185 -14
  10. package/dist/export/content.js.map +1 -1
  11. package/dist/export/controls.d.ts +18 -0
  12. package/dist/export/controls.d.ts.map +1 -0
  13. package/dist/export/controls.js +232 -0
  14. package/dist/export/controls.js.map +1 -0
  15. package/dist/export/index.d.ts +6 -1
  16. package/dist/export/index.d.ts.map +1 -1
  17. package/dist/export/index.js +277 -28
  18. package/dist/export/index.js.map +1 -1
  19. package/dist/export/parts.d.ts +9 -1
  20. package/dist/export/parts.d.ts.map +1 -1
  21. package/dist/export/parts.js +69 -2
  22. package/dist/export/parts.js.map +1 -1
  23. package/dist/export/pictures.d.ts +54 -0
  24. package/dist/export/pictures.d.ts.map +1 -0
  25. package/dist/export/pictures.js +359 -0
  26. package/dist/export/pictures.js.map +1 -0
  27. package/dist/export/properties.d.ts +11 -1
  28. package/dist/export/properties.d.ts.map +1 -1
  29. package/dist/export/properties.js +57 -3
  30. package/dist/export/properties.js.map +1 -1
  31. package/dist/export/tables.d.ts +27 -0
  32. package/dist/export/tables.d.ts.map +1 -0
  33. package/dist/export/tables.js +344 -0
  34. package/dist/export/tables.js.map +1 -0
  35. package/dist/images.d.ts +21 -0
  36. package/dist/images.d.ts.map +1 -0
  37. package/dist/images.js +53 -0
  38. package/dist/images.js.map +1 -0
  39. package/dist/import/content.d.ts +15 -1
  40. package/dist/import/content.d.ts.map +1 -1
  41. package/dist/import/content.js +357 -15
  42. package/dist/import/content.js.map +1 -1
  43. package/dist/import/controls.d.ts +14 -0
  44. package/dist/import/controls.d.ts.map +1 -0
  45. package/dist/import/controls.js +123 -0
  46. package/dist/import/controls.js.map +1 -0
  47. package/dist/import/index.d.ts +10 -2
  48. package/dist/import/index.d.ts.map +1 -1
  49. package/dist/import/index.js +76 -13
  50. package/dist/import/index.js.map +1 -1
  51. package/dist/import/ooxml.d.ts +4 -0
  52. package/dist/import/ooxml.d.ts.map +1 -1
  53. package/dist/import/ooxml.js +4 -0
  54. package/dist/import/ooxml.js.map +1 -1
  55. package/dist/import/parts.d.ts.map +1 -1
  56. package/dist/import/parts.js +8 -1
  57. package/dist/import/parts.js.map +1 -1
  58. package/dist/import/pictures.d.ts +34 -0
  59. package/dist/import/pictures.d.ts.map +1 -0
  60. package/dist/import/pictures.js +147 -0
  61. package/dist/import/pictures.js.map +1 -0
  62. package/dist/import/properties.d.ts +2 -0
  63. package/dist/import/properties.d.ts.map +1 -1
  64. package/dist/import/properties.js +55 -0
  65. package/dist/import/properties.js.map +1 -1
  66. package/dist/import/report.d.ts +6 -0
  67. package/dist/import/report.d.ts.map +1 -1
  68. package/dist/import/report.js +5 -0
  69. package/dist/import/report.js.map +1 -1
  70. package/dist/import/stories.d.ts +19 -0
  71. package/dist/import/stories.d.ts.map +1 -0
  72. package/dist/import/stories.js +119 -0
  73. package/dist/import/stories.js.map +1 -0
  74. package/dist/import/tables.d.ts +31 -0
  75. package/dist/import/tables.d.ts.map +1 -0
  76. package/dist/import/tables.js +236 -0
  77. package/dist/import/tables.js.map +1 -0
  78. package/dist/index.d.ts +1 -0
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +1 -0
  81. package/dist/index.js.map +1 -1
  82. package/dist/settings.d.ts +18 -4
  83. package/dist/settings.d.ts.map +1 -1
  84. package/dist/settings.js +173 -26
  85. package/dist/settings.js.map +1 -1
  86. package/package.json +3 -3
  87. package/src/export/balance.ts +113 -0
  88. package/src/export/content.ts +240 -15
  89. package/src/export/controls.ts +259 -0
  90. package/src/export/index.ts +357 -32
  91. package/src/export/parts.ts +94 -2
  92. package/src/export/pictures.ts +411 -0
  93. package/src/export/properties.ts +69 -3
  94. package/src/export/tables.ts +386 -0
  95. package/src/images.ts +60 -0
  96. package/src/import/content.ts +365 -17
  97. package/src/import/controls.ts +137 -0
  98. package/src/import/index.ts +87 -12
  99. package/src/import/ooxml.ts +4 -0
  100. package/src/import/parts.ts +14 -1
  101. package/src/import/pictures.ts +176 -0
  102. package/src/import/properties.ts +59 -0
  103. package/src/import/report.ts +11 -0
  104. package/src/import/stories.ts +122 -0
  105. package/src/import/tables.ts +267 -0
  106. package/src/index.ts +1 -0
  107. package/src/settings.ts +191 -27
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.js","sourceRoot":"","sources":["../../src/export/tables.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3F,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAmB,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAgB9F,MAAM,CAAC,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAElF,SAAS,UAAU,CAAC,KAAa,EAAE,CAAU;IAC3C,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAClB,MAAM,CAAC,GAAG,CAAS,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC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AC,CAAC,CAAC,EAAE;CAC3E,CAAC,CAAC;AAEH,kFAAkF;AAClF,MAAM,UAAU,OAAO,CAAC,KAAW,EAAE,EAAc;IACjD,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAa,CAAC;IAC9C,MAAM,GAAG,GAAG,KAAK,CAAC,OAA6B,CAAC;IAChD,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;QAC9C,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;YAAE,OAAO,GAAG,CAAC;IAC1E,CAAC;IACD,OAAO,cAAc,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC;AAC/F,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { ResourceJSON } from "@folijs/core";
2
+ import type { DocxPackage } from "./package.js";
3
+ /** URLs for the images of a package's pictures, for the view to show them. */
4
+ export interface PackageImages {
5
+ /**
6
+ * An object URL for the image of resource `key` when it is a part of the package (made once,
7
+ * then reused); undefined otherwise. Fits `EditorViewOptions.resource`.
8
+ */
9
+ url(key: string, resource?: ResourceJSON): string | undefined;
10
+ /** Frees every URL made (they stop working). */
11
+ revoke(): void;
12
+ }
13
+ /**
14
+ * URLs for the pictures' images that live in `pkg` (`word/media/…`): the view cannot show a
15
+ * package part otherwise. Raster images get object URLs (`blob:`); an SVG gets a `data:` URL,
16
+ * never a `blob:` one (opened on its own, a `blob:` SVG would run its scripts as the app's
17
+ * origin; a `data:` document has none). Types browsers cannot show, and where there are no
18
+ * object URLs (no DOM), none.
19
+ */
20
+ export declare function packageImages(pkg: DocxPackage): PackageImages;
21
+ //# sourceMappingURL=images.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../src/images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,8EAA8E;AAC9E,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAAC;IAC9D,gDAAgD;IAChD,MAAM,IAAI,IAAI,CAAC;CAChB;AAaD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,GAAG,aAAa,CA2B7D"}
package/dist/images.js ADDED
@@ -0,0 +1,53 @@
1
+ /** Image types browsers show in an `img`; EMF, WMF and TIFF parts are shown as a box. */
2
+ // `image/jpg` as some producers write it.
3
+ const RASTER = new Set([
4
+ "image/png",
5
+ "image/jpeg",
6
+ "image/jpg",
7
+ "image/gif",
8
+ "image/webp",
9
+ "image/bmp",
10
+ ]);
11
+ /**
12
+ * URLs for the pictures' images that live in `pkg` (`word/media/…`): the view cannot show a
13
+ * package part otherwise. Raster images get object URLs (`blob:`); an SVG gets a `data:` URL,
14
+ * never a `blob:` one (opened on its own, a `blob:` SVG would run its scripts as the app's
15
+ * origin; a `data:` document has none). Types browsers cannot show, and where there are no
16
+ * object URLs (no DOM), none.
17
+ */
18
+ export function packageImages(pkg) {
19
+ const urls = new Map();
20
+ const blobs = [];
21
+ return {
22
+ url(key, resource) {
23
+ const known = urls.get(key);
24
+ if (known)
25
+ return known;
26
+ const part = resource?.part ? pkg.part(`/${resource.part}`) : undefined;
27
+ if (!part)
28
+ return undefined;
29
+ let url;
30
+ if (part.contentType === "image/svg+xml") {
31
+ let binary = "";
32
+ for (const byte of part.data)
33
+ binary += String.fromCharCode(byte);
34
+ url = `data:image/svg+xml;base64,${btoa(binary)}`;
35
+ }
36
+ else if (RASTER.has(part.contentType) && typeof URL.createObjectURL === "function") {
37
+ url = URL.createObjectURL(new Blob([part.data], { type: part.contentType }));
38
+ blobs.push(url);
39
+ }
40
+ else
41
+ return undefined;
42
+ urls.set(key, url);
43
+ return url;
44
+ },
45
+ revoke() {
46
+ for (const url of blobs)
47
+ URL.revokeObjectURL(url);
48
+ blobs.length = 0;
49
+ urls.clear();
50
+ },
51
+ };
52
+ }
53
+ //# sourceMappingURL=images.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"images.js","sourceRoot":"","sources":["../src/images.ts"],"names":[],"mappings":"AAcA,yFAAyF;AACzF,0CAA0C;AAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC;IACrB,WAAW;IACX,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,WAAW;CACZ,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,GAAgB;IAC5C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,OAAO;QACL,GAAG,CAAC,GAAG,EAAE,QAAQ;YACf,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,KAAK;gBAAE,OAAO,KAAK,CAAC;YACxB,MAAM,IAAI,GAAG,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACxE,IAAI,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAC;YAC5B,IAAI,GAAW,CAAC;YAChB,IAAI,IAAI,CAAC,WAAW,KAAK,eAAe,EAAE,CAAC;gBACzC,IAAI,MAAM,GAAG,EAAE,CAAC;gBAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI;oBAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBAClE,GAAG,GAAG,6BAA6B,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACpD,CAAC;iBAAM,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,OAAO,GAAG,CAAC,eAAe,KAAK,UAAU,EAAE,CAAC;gBACrF,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,IAAgB,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;gBACzF,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;;gBAAM,OAAO,SAAS,CAAC;YACxB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YACnB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,MAAM;YACJ,KAAK,MAAM,GAAG,IAAI,KAAK;gBAAE,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAClD,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YACjB,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -3,7 +3,7 @@
3
3
  * yet becomes an opaque node holding the element's source verbatim, with a label to show (none
4
4
  * for markers that have nothing to show: field characters, range ends).
5
5
  */
6
- import { type NodeJSON } from "@folijs/core";
6
+ import { type ControlJSON, type NodeJSON, type ResourceJSON } from "@folijs/core";
7
7
  import type { DocxPackage, Relationship } from "../package.js";
8
8
  import type { XmlElement, XmlNode } from "../xml.js";
9
9
  import { type Context } from "./properties.js";
@@ -15,6 +15,20 @@ export interface ContentContext extends Context {
15
15
  readonly moves: Moves;
16
16
  /** The part's relationship with this id (hyperlink targets). */
17
17
  readonly relationship: (id: string) => Relationship | undefined;
18
+ /** How many tables the content is in. */
19
+ readonly tableDepth?: number;
20
+ /** The envelope's resources (pictures' images), filled as content is read. */
21
+ readonly resources: Map<string, ResourceJSON>;
22
+ /** The envelope's content controls, filled as content is read. */
23
+ readonly controls: Map<string, ControlJSON>;
24
+ /** Numbers the part's controls: their ids are `<part>#<n>`, the same on every reading. */
25
+ readonly ordinals: {
26
+ next: number;
27
+ };
28
+ /**
29
+ * The kind of story being read (ADR-0007), or a comment: what one may not hold stays verbatim.
30
+ */
31
+ readonly story?: "header" | "footer" | "footnote" | "endnote" | "comment";
18
32
  }
19
33
  /**
20
34
  * Block content: paragraphs, and every other block element as an opaque block. `section` is the
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../src/import/content.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiB,KAAK,QAAQ,EAAU,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAEL,KAAK,OAAO,EAOb,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,cAAe,SAAQ,OAAO;IAC7C,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAC;CACjE;AA4DD;;;GAGG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,UAAU,GACnB,QAAQ,EAAE,CAeZ;AAMD,wBAAgB,SAAS,CAAC,CAAC,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CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC5C,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;CAC3E;AAkED;;;GAGG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,UAAU,GACnB,QAAQ,EAAE,CAqBZ;AA0LD,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,GAAG,QAAQ,CAc1E;AAsJD;;;GAGG;AACH,qBAAa,KAAK;;IAShB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAKxD;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAK3C;IAED,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CAK/C;CACF"}
@@ -3,9 +3,14 @@
3
3
  * yet becomes an opaque node holding the element's source verbatim, with a label to show (none
4
4
  * for markers that have nothing to show: field characters, range ends).
5
5
  */
6
- import { schema } from "@folijs/core";
7
- import { attr, child, deepText, integer, isW, R, REL, textOf, W } from "./ooxml.js";
6
+ import { schema, } from "@folijs/core";
7
+ import { controlProperties } from "./controls.js";
8
+ import { attr, child, deepText, elements, integer, isW, R, REL, textOf, W } from "./ooxml.js";
9
+ import { pictureAttrs } from "./pictures.js";
8
10
  import { attributeBag, mark, paragraphProperties, revisionMark, runProperties, setParagraph, sourceOf, } from "./properties.js";
11
+ import { cellProperties, grid, rowProperties, tableProperties } from "./tables.js";
12
+ /** Tables nested deeper stay opaque: within the model's depth (three levels per table). */
13
+ const MAX_TABLE_DEPTH = 64;
9
14
  /** Labels of the opaque elements that show something; anything else unknown shows its name. */
10
15
  const BLOCK_LABELS = {
11
16
  tbl: "table",
@@ -53,6 +58,8 @@ const INLINE_LABELS = {
53
58
  customXmlDelRangeStart: null,
54
59
  customXmlDelRangeEnd: null,
55
60
  };
61
+ /** What a separator note holds: kept in its run, with nothing to report or edit. */
62
+ const NOTE_SEPARATORS = new Set(["separator", "continuationSeparator", "continuationNotice"]);
56
63
  /** Recomputed by Word, never kept: spelling marks, the last rendered page breaks. */
57
64
  const DROPPED = new Set(["proofErr", "lastRenderedPageBreak"]);
58
65
  function label(table, element) {
@@ -66,28 +73,232 @@ function label(table, element) {
66
73
  */
67
74
  export function blocks(nodes, context, section) {
68
75
  const out = [];
76
+ const tables = new Map();
69
77
  for (const node of nodes) {
70
78
  if (node.kind !== "element" || node === section)
71
79
  continue;
72
80
  if (isW(node, "p"))
73
81
  out.push(paragraph(node, context));
82
+ else if (isW(node, "sdt"))
83
+ out.push(...(blockControl(node, context) ?? [opaqueOf(node, context)]));
84
+ else if (isW(node, "tbl")) {
85
+ // A table right after a table is one table to Word (it merges them): kept verbatim.
86
+ const table = out.at(-1)?.type === "table" ? undefined : tableOf(node, context);
87
+ if (table)
88
+ tables.set(table, node);
89
+ out.push(table ?? opaqueOf(node, context));
90
+ }
74
91
  else if (node.ns === W && DROPPED.has(node.local))
75
92
  context.report.dropped(node.name);
76
- else {
77
- context.report.opaque(node.name);
78
- out.push({
79
- type: "opaqueBlock",
80
- attrs: withLabel({ xml: sourceOf(context, node) }, label(BLOCK_LABELS, node)),
81
- });
93
+ else
94
+ out.push(opaqueOf(node, context));
95
+ }
96
+ // Content does not end with a table (Word always puts a paragraph after one).
97
+ const last = out.at(-1);
98
+ const source = last && tables.get(last);
99
+ if (source)
100
+ out[out.length - 1] = opaqueOf(source, context);
101
+ return out;
102
+ }
103
+ /** A control's properties taken into the envelope, its id and its content element. */
104
+ function controlOf(sdt, context) {
105
+ const content = child(sdt, "sdtContent");
106
+ if (!content || sdt.attributes.length)
107
+ return undefined;
108
+ const children = elements(sdt);
109
+ const once = (local) => children.filter((c) => isW(c, local)).length <= 1;
110
+ const known = new Set(["sdtPr", "sdtEndPr", "sdtContent"]);
111
+ if (children.some((c) => !isW(c) || !known.has(c.local)))
112
+ return undefined;
113
+ if (![...known].every(once))
114
+ return undefined;
115
+ const control = controlProperties(sdt, context);
116
+ if (!control)
117
+ return undefined;
118
+ const id = `${context.part}#${context.ordinals.next++}`;
119
+ context.controls.set(id, control);
120
+ return { id, content };
121
+ }
122
+ /** How many controls the model lets a block, row or cell be in. */
123
+ const MAX_CONTROLS = 64;
124
+ const roomForControl = (node) => (node.attrs?.controls?.length ?? 0) < MAX_CONTROLS;
125
+ /** `node` inside control `id`, outermost first. */
126
+ function inControl(node, id) {
127
+ const controls = [id, ...(node.attrs?.controls ?? [])];
128
+ return { ...node, attrs: { ...node.attrs, controls } };
129
+ }
130
+ /** A block-level control's blocks, each listing it; undefined keeps it verbatim (one that is empty). */
131
+ function blockControl(sdt, context) {
132
+ const control = controlOf(sdt, context);
133
+ if (!control)
134
+ return undefined;
135
+ const inner = blocks(control.content.children, context);
136
+ if (!inner.length || !inner.every(roomForControl))
137
+ return undefined;
138
+ return inner.map((block) => inControl(block, control.id));
139
+ }
140
+ /**
141
+ * The rows (or cells) among `nodes`, those in row-level (cell-level) controls listing them;
142
+ * undefined when anything else is there, which keeps the table verbatim.
143
+ */
144
+ function controlled(nodes, local, read, context) {
145
+ const out = [];
146
+ for (const node of nodes) {
147
+ if (node.kind !== "element")
148
+ continue;
149
+ if (isW(node, local)) {
150
+ const item = read(node);
151
+ if (!item)
152
+ return undefined;
153
+ out.push(item);
154
+ }
155
+ else if (isW(node, "sdt")) {
156
+ const control = controlOf(node, context);
157
+ const inner = control && controlled(control.content.children, local, read, context);
158
+ if (!control || !inner?.length || !inner.every(roomForControl))
159
+ return undefined;
160
+ out.push(...inner.map((item) => inControl(item, control.id)));
82
161
  }
162
+ else
163
+ return undefined;
83
164
  }
84
165
  return out;
85
166
  }
167
+ function opaqueOf(node, context) {
168
+ context.report.opaque(node.name);
169
+ return {
170
+ type: "opaqueBlock",
171
+ attrs: withLabel({ xml: sourceOf(context, node) }, label(BLOCK_LABELS, node)),
172
+ };
173
+ }
174
+ /**
175
+ * `w:tbl` as a table; undefined when the model cannot hold it as it is (rows or cells inside a
176
+ * content control or custom XML, markers between rows, elements out of Word's order, a cell
177
+ * not ending with a paragraph, tables nested too deep): the caller keeps it verbatim.
178
+ */
179
+ function tableOf(tbl, context) {
180
+ const tableDepth = (context.tableDepth ?? 0) + 1;
181
+ if (tableDepth > MAX_TABLE_DEPTH || tbl.attributes.length)
182
+ return undefined;
183
+ const inner = { ...context, tableDepth };
184
+ let tblPr;
185
+ let tblGrid;
186
+ const rows = [];
187
+ let stage = 0; // 0: w:tblPr may come, 1: w:tblGrid may come, 2: rows
188
+ for (const c of tbl.children) {
189
+ if (c.kind !== "element")
190
+ continue;
191
+ if (stage === 0 && isW(c, "tblPr")) {
192
+ tblPr = c;
193
+ stage = 1;
194
+ }
195
+ else if (stage <= 1 && isW(c, "tblGrid")) {
196
+ tblGrid = c;
197
+ stage = 2;
198
+ }
199
+ else if (isW(c, "tr") || isW(c, "sdt")) {
200
+ stage = 2;
201
+ const read = controlled([c], "tr", (tr) => rowOf(tr, inner), inner);
202
+ if (!read)
203
+ return undefined;
204
+ rows.push(...read);
205
+ }
206
+ else
207
+ return undefined;
208
+ }
209
+ if (!rows.length)
210
+ return undefined;
211
+ return {
212
+ type: "table",
213
+ attrs: {
214
+ ...tableProperties(tblPr, context, true),
215
+ grid: grid(tblGrid, context),
216
+ ...(tblGrid ? { gridExt: sourceOf(context, tblGrid) } : {}),
217
+ },
218
+ content: rows,
219
+ };
220
+ }
221
+ const ROW_ATTRS = schema.nodes.tableRow?.spec.attrs ?? {};
222
+ function rowOf(tr, context) {
223
+ let tblPrEx;
224
+ let trPr;
225
+ const cells = [];
226
+ let stage = 0; // 0: w:tblPrEx, 1: w:trPr, 2: cells
227
+ for (const c of tr.children) {
228
+ if (c.kind !== "element")
229
+ continue;
230
+ if (stage === 0 && isW(c, "tblPrEx")) {
231
+ tblPrEx = c;
232
+ stage = 1;
233
+ }
234
+ else if (stage <= 1 && isW(c, "trPr")) {
235
+ trPr = c;
236
+ stage = 2;
237
+ }
238
+ else if (isW(c, "tc") || isW(c, "sdt")) {
239
+ stage = 2;
240
+ const read = controlled([c], "tc", (tc) => cellOf(tc, context), context);
241
+ if (!read)
242
+ return undefined;
243
+ cells.push(...read);
244
+ }
245
+ else
246
+ return undefined;
247
+ }
248
+ if (!cells.length)
249
+ return undefined;
250
+ const attrs = rowProperties(trPr, context, true);
251
+ if (tblPrEx) {
252
+ const exceptions = tableProperties(tblPrEx, context, true);
253
+ // Not a row's to override (CT_TblPrEx): left in the element, not modeled.
254
+ for (const key of ["style", "rowBandSize", "columnBandSize"]) {
255
+ if (key in exceptions) {
256
+ context.report.unmodeled(tblPrEx.name, `${key} is not an exception (kept in the element)`);
257
+ delete exceptions[key];
258
+ }
259
+ }
260
+ const error = ROW_ATTRS.exceptions?.validate?.(exceptions);
261
+ // Its values are checked one by one: only a too-large element can fail here.
262
+ if (error)
263
+ return undefined;
264
+ attrs.exceptions = exceptions;
265
+ }
266
+ const bag = attributeBag(tr, [], context);
267
+ if (bag)
268
+ attrs.attributes = bag;
269
+ return { type: "tableRow", ...(Object.keys(attrs).length ? { attrs } : {}), content: cells };
270
+ }
271
+ function cellOf(tc, context) {
272
+ if (tc.attributes.length)
273
+ return undefined;
274
+ const first = tc.children.find((c) => c.kind === "element");
275
+ const tcPr = first && isW(first, "tcPr") ? first : undefined;
276
+ const content = blocks(tc.children.filter((c) => c !== tcPr), context);
277
+ if (content.at(-1)?.type !== "paragraph" || !content.every(allowedInCell))
278
+ return undefined;
279
+ const attrs = cellProperties(tcPr, context, true);
280
+ return { type: "tableCell", ...(Object.keys(attrs).length ? { attrs } : {}), content };
281
+ }
282
+ /**
283
+ * Whether a cell's block is one the model allows there: not a paragraph that ends a section or
284
+ * holds a page or column break. A table with one stays verbatim (lossless) instead.
285
+ */
286
+ function allowedInCell(block) {
287
+ if (block.type !== "paragraph")
288
+ return true;
289
+ if (block.attrs?.section)
290
+ return false;
291
+ return !block.content?.some((n) => n.type === "pageBreak" || n.type === "columnBreak");
292
+ }
86
293
  function withLabel(attrs, value) {
87
294
  return value === null ? attrs : { ...attrs, label: value.slice(0, 255) || null };
88
295
  }
89
296
  export function paragraph(p, context) {
90
- const attrs = paragraphProperties(child(p, "pPr"), context, true);
297
+ // A story ends no section: such a paragraph stays as it is.
298
+ const pPr = child(p, "pPr");
299
+ if (context.story && pPr && child(pPr, "sectPr"))
300
+ return opaqueOf(p, context);
301
+ const attrs = paragraphProperties(pPr, context, true);
91
302
  const bag = attributeBag(p, [], context);
92
303
  if (bag)
93
304
  setParagraph(attrs, "attributes", bag, p.name, context);
@@ -162,6 +373,11 @@ function inlines(nodes, marks, context, out) {
162
373
  case "commentRangeStart":
163
374
  case "commentRangeEnd": {
164
375
  const type = MARKER_TYPES[el.local];
376
+ // Stories hold no comments (ADR-0007): such an anchor stays verbatim.
377
+ if (type.startsWith("comment") && context.story && context.story !== "comment") {
378
+ opaque(el, BLOCK_LABELS);
379
+ break;
380
+ }
165
381
  const isStart = type === "bookmarkStart";
166
382
  const bag = attributeBag(el, isStart ? ["w:id", "w:name"] : ["w:id"], context);
167
383
  const attrs = { id: integer(attr(el, "id")) };
@@ -186,9 +402,36 @@ function inlines(nodes, marks, context, out) {
186
402
  context.moves.close(el.local.startsWith("moveFrom") ? "from" : "to", attr(el, "id") ?? "");
187
403
  opaque(el);
188
404
  break;
189
- case "fldSimple":
190
- opaque(el, INLINE_LABELS, deepText(el) || attr(el, "instr")?.trim() || "field");
405
+ case "fldSimple": {
406
+ const instruction = attr(el, "instr");
407
+ const start = node("fieldStart", {
408
+ simple: true,
409
+ // The start tag, as an element holding the result has it.
410
+ ext: context.source.slice(el.start, el.openEnd).replace(/\/>$/, ">"),
411
+ });
412
+ const code = node("fieldCode", { text: instruction ?? "" });
413
+ const leaves = valid(start, el, context) && valid(code, el, context);
414
+ if (instruction === undefined || !leaves) {
415
+ opaque(el, INLINE_LABELS, deepText(el) || "field");
416
+ break;
417
+ }
418
+ out.push(start, code, node("fieldSeparator"));
419
+ inlines(el.children, marks, context, out);
420
+ out.push(node("fieldEnd"));
191
421
  break;
422
+ }
423
+ case "sdt": {
424
+ const blocksInside = (c) => elements(c).some((e) => isW(e, "p") || isW(e, "tbl"));
425
+ const control = controlOf(el, context);
426
+ if (!control || blocksInside(control.content)) {
427
+ opaque(el);
428
+ break;
429
+ }
430
+ out.push(node("controlStart", { id: control.id }));
431
+ inlines(control.content.children, marks, context, out);
432
+ out.push(node("controlEnd", { id: control.id }));
433
+ break;
434
+ }
192
435
  default:
193
436
  if (DROPPED.has(el.local))
194
437
  context.report.dropped(el.name);
@@ -305,7 +548,10 @@ function run(r, outer, context, out) {
305
548
  break;
306
549
  case "br": {
307
550
  const type = attr(el, "type");
308
- if (type === "page")
551
+ const inNote = context.story === "footnote" || context.story === "endnote";
552
+ if ((type === "page" || type === "column") && inNote)
553
+ opaqueRun(el);
554
+ else if (type === "page")
309
555
  out.push(node("pageBreak", marks));
310
556
  else if (type === "column")
311
557
  out.push(node("columnBreak", marks));
@@ -328,7 +574,27 @@ function run(r, outer, context, out) {
328
574
  case "softHyphen":
329
575
  text("­");
330
576
  break;
577
+ case "drawing": {
578
+ const image = [];
579
+ const attrs = pictureAttrs(el, { ...context, partOf: (name) => context.pkg.part(name) }, image);
580
+ const leaf = attrs && valid(node("picture", marks, attrs), el, context);
581
+ if (!leaf) {
582
+ opaqueRun(el);
583
+ break;
584
+ }
585
+ out.push(leaf);
586
+ const [key, entry] = image;
587
+ if (key && entry && !context.resources.has(key))
588
+ context.resources.set(key, entry);
589
+ if (!attrs.alt && !attrs.decorative)
590
+ context.report.withoutAlt();
591
+ break;
592
+ }
331
593
  case "commentReference": {
594
+ if (context.story && context.story !== "comment") {
595
+ opaqueRun(el);
596
+ break;
597
+ }
332
598
  const bag = attributeBag(el, ["w:id"], context);
333
599
  const attrs = { id: integer(attr(el, "id")) };
334
600
  if (bag)
@@ -340,18 +606,94 @@ function run(r, outer, context, out) {
340
606
  opaqueRun(el);
341
607
  break;
342
608
  }
609
+ case "fldChar": {
610
+ const type = attr(el, "fldCharType");
611
+ const name = { begin: "fieldStart", separate: "fieldSeparator", end: "fieldEnd" }[type ?? ""];
612
+ if (!name) {
613
+ opaqueRun(el);
614
+ break;
615
+ }
616
+ const known = ["w:fldCharType", "w:dirty", "w:fldLock"];
617
+ const plain = !elements(el).length && el.attributes.every((a) => known.includes(a.name));
618
+ const flags = {};
619
+ if (name === "fieldStart" && plain) {
620
+ const dirty = attr(el, "dirty");
621
+ const locked = attr(el, "fldLock");
622
+ if (dirty !== undefined)
623
+ flags.dirty = !["0", "false", "off"].includes(dirty);
624
+ if (locked !== undefined)
625
+ flags.locked = !["0", "false", "off"].includes(locked);
626
+ }
627
+ // Form field data, or anything else on it: the element itself is kept.
628
+ const simple = plain && (name === "fieldStart" || el.attributes.length === 1);
629
+ const attrs = simple ? flags : { ext: sourceOf(context, el) };
630
+ const leaf = valid(node(name, marks, Object.keys(attrs).length ? attrs : undefined), el, context);
631
+ if (leaf)
632
+ out.push(leaf);
633
+ else
634
+ opaqueRun(el);
635
+ break;
636
+ }
637
+ case "instrText":
638
+ case "delInstrText": {
639
+ const bag = attributeBag(el, ["xml:space"], context);
640
+ const attrs = { text: spaced(el) };
641
+ if (bag)
642
+ attrs.attributes = bag;
643
+ const leaf = valid(node("fieldCode", marks, attrs), el, context);
644
+ if (leaf)
645
+ out.push(leaf);
646
+ else
647
+ opaqueRun(el);
648
+ break;
649
+ }
650
+ case "footnoteReference":
651
+ case "endnoteReference": {
652
+ const id = integer(attr(el, "id"));
653
+ const custom = attr(el, "customMarkFollows");
654
+ const on = custom === undefined ? null : ["1", "true", "on"].includes(custom);
655
+ // A story holds no references (ADR-0007), and a value the node cannot say stays verbatim.
656
+ if (context.story ||
657
+ id === undefined ||
658
+ (custom !== undefined && !["0", "1", "true", "false", "on", "off"].includes(custom))) {
659
+ opaqueRun(el);
660
+ break;
661
+ }
662
+ const bag = attributeBag(el, ["w:id", "w:customMarkFollows"], context);
663
+ const attrs = {
664
+ story: `${el.local === "footnoteReference" ? "footnote" : "endnote"}:${id}`,
665
+ };
666
+ if (on !== null)
667
+ attrs.customMark = on;
668
+ if (bag)
669
+ attrs.attributes = bag;
670
+ const leaf = valid(node("noteReference", marks, attrs), el, context);
671
+ if (leaf)
672
+ out.push(leaf);
673
+ else
674
+ opaqueRun(el);
675
+ break;
676
+ }
677
+ case "footnoteRef":
678
+ case "endnoteRef":
679
+ if (context.story === el.local.slice(0, -3) && !el.attributes.length)
680
+ out.push(node("noteMark", marks));
681
+ else
682
+ opaqueRun(el);
683
+ break;
343
684
  default:
344
685
  if (DROPPED.has(el.local))
345
686
  context.report.dropped(el.name);
346
687
  else
347
- opaqueRun(el);
688
+ opaqueRun(el, undefined, context.story && NOTE_SEPARATORS.has(el.local));
348
689
  }
349
690
  }
350
691
  // A run with properties and nothing else shows nothing; Word drops those too.
351
692
  if (out.length === before)
352
693
  context.report.dropped("w:r (empty)");
353
- function opaqueRun(el, labelValue = label(INLINE_LABELS, el)) {
354
- context.report.opaque(el.name);
694
+ function opaqueRun(el, labelValue = label(INLINE_LABELS, el), expected = false) {
695
+ if (!expected)
696
+ context.report.opaque(el.name);
355
697
  out.push(node("opaqueInline", marks, {
356
698
  ...withLabel({ xml: sourceOf(context, el) }, labelValue),
357
699
  run: true,