@folijs/view 0.5.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 (61) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/clipboard.d.ts +3 -1
  3. package/dist/clipboard.d.ts.map +1 -1
  4. package/dist/clipboard.js.map +1 -1
  5. package/dist/layout/flow.d.ts +193 -20
  6. package/dist/layout/flow.d.ts.map +1 -1
  7. package/dist/layout/flow.js +789 -101
  8. package/dist/layout/flow.js.map +1 -1
  9. package/dist/print.d.ts +22 -0
  10. package/dist/print.d.ts.map +1 -0
  11. package/dist/print.js +31 -0
  12. package/dist/print.js.map +1 -0
  13. package/dist/view.d.ts +220 -7
  14. package/dist/view.d.ts.map +1 -1
  15. package/dist/view.js +1753 -208
  16. package/dist/view.js.map +1 -1
  17. package/dist/word/blocks.d.ts +30 -1
  18. package/dist/word/blocks.d.ts.map +1 -1
  19. package/dist/word/blocks.js +193 -40
  20. package/dist/word/blocks.js.map +1 -1
  21. package/dist/word/columns.d.ts +23 -0
  22. package/dist/word/columns.d.ts.map +1 -0
  23. package/dist/word/columns.js +51 -0
  24. package/dist/word/columns.js.map +1 -0
  25. package/dist/word/controls.d.ts +63 -0
  26. package/dist/word/controls.d.ts.map +1 -0
  27. package/dist/word/controls.js +411 -0
  28. package/dist/word/controls.js.map +1 -0
  29. package/dist/word/edit.d.ts +17 -5
  30. package/dist/word/edit.d.ts.map +1 -1
  31. package/dist/word/edit.js +157 -26
  32. package/dist/word/edit.js.map +1 -1
  33. package/dist/word/matches.d.ts +23 -0
  34. package/dist/word/matches.d.ts.map +1 -0
  35. package/dist/word/matches.js +97 -0
  36. package/dist/word/matches.js.map +1 -0
  37. package/dist/word/notes.d.ts +105 -0
  38. package/dist/word/notes.d.ts.map +1 -0
  39. package/dist/word/notes.js +392 -0
  40. package/dist/word/notes.js.map +1 -0
  41. package/dist/word/pages.d.ts +18 -13
  42. package/dist/word/pages.d.ts.map +1 -1
  43. package/dist/word/pages.js +420 -229
  44. package/dist/word/pages.js.map +1 -1
  45. package/dist/word/regions.d.ts +113 -0
  46. package/dist/word/regions.d.ts.map +1 -0
  47. package/dist/word/regions.js +374 -0
  48. package/dist/word/regions.js.map +1 -0
  49. package/package.json +2 -2
  50. package/src/clipboard.ts +3 -0
  51. package/src/layout/flow.ts +945 -110
  52. package/src/print.ts +48 -0
  53. package/src/view.ts +1957 -229
  54. package/src/word/blocks.ts +219 -36
  55. package/src/word/columns.ts +66 -0
  56. package/src/word/controls.ts +447 -0
  57. package/src/word/edit.ts +175 -23
  58. package/src/word/matches.ts +99 -0
  59. package/src/word/notes.ts +451 -0
  60. package/src/word/pages.ts +501 -220
  61. package/src/word/regions.ts +469 -0
@@ -7,6 +7,8 @@
7
7
  import { type FoliDocument, type ListMarker, type NodeJSON, type ParagraphFormat, Resolver, type ResourceJSON, type RunFormat, type SectionJSON } from "@folijs/core";
8
8
  /** Marks the <br> of an explicit page break (the page flow ends the page after its line). */
9
9
  export declare const WORD_PAGE_BREAK_ATTR = "data-page-break";
10
+ /** Marks the <br> of an explicit column break (the flow ends the column after its line). */
11
+ export declare const WORD_COLUMN_BREAK_ATTR = "data-column-break";
10
12
  /** CSS px per twip (1/1440 inch; CSS: 96 px per inch). */
11
13
  export declare const PX_PER_TWIP: number;
12
14
  /** EMU (DrawingML's unit: 914 400 per inch) per CSS px. */
@@ -78,6 +80,8 @@ export declare function changeElement(doc: Document, inserted: boolean, author:
78
80
  export interface BlockOptions {
79
81
  /** `markup` (the default): insertions underlined, deletions struck through; `simple`, `final`: as if accepted. */
80
82
  review?: ReviewView;
83
+ /** Fields show their codes instead of their results (Word's Alt+F9). */
84
+ fieldCodes?: boolean;
81
85
  /**
82
86
  * The ratio of a font's normal line height to its size (`fontFamily`: a CSS font-family
83
87
  * list). Word's single line spacing is the font's own line height; multiples scale it.
@@ -90,7 +94,20 @@ export interface BlockOptions {
90
94
  * resource's own image `data:` URL or web URL (fetched as it is shown).
91
95
  */
92
96
  resource?: (key: string, resource: ResourceJSON) => string | null | undefined;
97
+ /** The document's resolver, when the caller has one (a story of it, drawn per page). */
98
+ resolver?: Resolver;
99
+ /** What note references show, by story, and what a note's own mark shows (never stored). */
100
+ notes?: {
101
+ references?: ReadonlyMap<string, string>;
102
+ mark?: string;
103
+ };
93
104
  }
105
+ /** On the element showing a note reference's number: the note's story. */
106
+ export declare const NOTE_REF_ATTR = "data-foli-note-ref";
107
+ /** On a number drawn for a note, at its reference or its mark: not text of the document. */
108
+ export declare const NOTE_NUMBER_ATTR = "data-foli-note-number";
109
+ /** The line a separator run draws, when `xml` is one (`w:separator`, `w:continuationSeparator`). */
110
+ export declare function separatorElement(xml: Element | null, doc: Document): HTMLElement | null;
94
111
  /** The source for a document's pictures: the app's URL, else the resource's own. */
95
112
  export declare function imageSource(resources: Readonly<Record<string, ResourceJSON>> | undefined, resolve?: (key: string, resource: ResourceJSON) => string | null | undefined): ImageSource;
96
113
  /** A rendered block and what the page flow needs to know about it. */
@@ -131,6 +148,18 @@ export declare function parseOpaque(xml: string, doc: Document): Element | null;
131
148
  * the next one, as accepting the deletion does.
132
149
  */
133
150
  export declare function renderBlocks(document: FoliDocument, doc: Document, options?: BlockOptions): WordBlock[];
151
+ /**
152
+ * Whether a paragraph's line holds nothing but inline pictures: Word's line then ends at the
153
+ * picture's foot (its PDFs of the corpus: no room below it for the text it does not have).
154
+ */
155
+ export declare function onlyPictures<T>(inline: Iterable<T>, type: (node: T) => string, floats: (node: T) => boolean): boolean;
156
+ /**
157
+ * The top margin of a paragraph after another (whose space after is `above`) in a box the page
158
+ * flow does not lay out (a table cell). Adjacent margins collapse to the larger: Word's rule. In
159
+ * a document where the two spaces add up this margin holds both, so the collapse gives the sum
160
+ * and no paragraph's shading or border grows.
161
+ */
162
+ export declare function marginAbove(before: number, above: number, resolver: Resolver): number;
134
163
  /** A paragraph's element: a heading of its outline level (1-6), else a paragraph. */
135
164
  export declare function tagOf(paragraph: ParagraphFormat): string;
136
165
  /** A list marker: its text, then what follows it (a tab to the text's indent, a space). */
@@ -142,7 +171,7 @@ export declare function markerElement(marker: ListMarker, paragraph: ParagraphFo
142
171
  */
143
172
  export declare function opaqueBlock(node: NodeJSON, index: number, resolver: Resolver, doc: Document, ratio: (family: string) => number, image?: ImageSource,
144
173
  /** The page floating pictures in its cells are placed against. */
145
- geometry?: FloatGeometry): WordBlock;
174
+ geometry?: FloatGeometry, codes?: boolean, notes?: BlockOptions["notes"]): WordBlock;
146
175
  /** A border of the model (`BorderJSON`) as CSS; undefined when it says none. */
147
176
  export declare function borderJsonCss(border: {
148
177
  style?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/word/blocks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,QAAQ,EACR,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,cAAc,CAAC;AAEtB,6FAA6F;AAC7F,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD,0DAA0D;AAC1D,eAAO,MAAM,WAAW,QAAY,CAAC;AACrC,2DAA2D;AAC3D,eAAO,MAAM,UAAU,QAAe,CAAC;AAEvC,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE9D,oDAAoD;AACpD,eAAO,MAAM,YAAY,sBAAsB,CAAC;AAEhD,gFAAgF;AAChF,eAAO,MAAM,YAAY,6BAA6B,CAAC;AAEvD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKlF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,C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AED,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAGxD;AAmCD,2FAA2F;AAC3F,wBAAgB,aAAa,CAC3B,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,eAAe,EAC1B,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAChC,WAAW,CA6Bb;AAwID;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,EACjC,KAAK,CAAC,EAAE,WAAW;AACnB,kEAAkE;AAClE,QAAQ,GAAE,aAAwC,EAClD,KAAK,UAAQ,EACb,KAAK,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,GAC5B,SAAS,CAqCX;AAkMD,gFAAgF;AAChF,wBAAgB,aAAa,CAC3B,MAAM,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,sBAOtE"}
@@ -4,9 +4,11 @@
4
4
  * anchors, and content the model keeps opaque shown as text. Read-only: built with
5
5
  * createElement/textContent only (never innerHTML); the page layout is in `pages.ts`.
6
6
  */
7
- import { Resolver, } from "@folijs/core";
7
+ import { fieldDisplay, Resolver, } from "@folijs/core";
8
8
  /** Marks the <br> of an explicit page break (the page flow ends the page after its line). */
9
9
  export const WORD_PAGE_BREAK_ATTR = "data-page-break";
10
+ /** Marks the <br> of an explicit column break (the flow ends the column after its line). */
11
+ export const WORD_COLUMN_BREAK_ATTR = "data-column-break";
10
12
  /** CSS px per twip (1/1440 inch; CSS: 96 px per inch). */
11
13
  export const PX_PER_TWIP = 96 / 1440;
12
14
  /** EMU (DrawingML's unit: 914 400 per inch) per CSS px. */
@@ -263,10 +265,34 @@ export function changeElement(doc, inserted, author, date, review) {
263
265
  }
264
266
  return element;
265
267
  }
268
+ /** On the element showing a note reference's number: the note's story. */
269
+ export const NOTE_REF_ATTR = "data-foli-note-ref";
270
+ /** On a number drawn for a note, at its reference or its mark: not text of the document. */
271
+ export const NOTE_NUMBER_ATTR = "data-foli-note-number";
272
+ /** Word's footnote separator is two inches long; its continuation line here is the same. */
273
+ const SEPARATOR_WIDTH = 192;
274
+ /** The line a separator run draws, when `xml` is one (`w:separator`, `w:continuationSeparator`). */
275
+ export function separatorElement(xml, doc) {
276
+ if (!xml)
277
+ return null;
278
+ const found = [xml, ...xml.getElementsByTagName("*")].some((e) => e.localName === "separator" || e.localName === "continuationSeparator");
279
+ if (!found)
280
+ return null;
281
+ const line = doc.createElement("span");
282
+ line.dataset.foliSeparator = "";
283
+ const { style } = line;
284
+ style.display = "inline-block";
285
+ style.width = `${SEPARATOR_WIDTH}px`;
286
+ style.maxWidth = "100%";
287
+ style.height = "0";
288
+ style.borderTop = "1px solid #000";
289
+ style.verticalAlign = "middle";
290
+ return line;
291
+ }
266
292
  /** The source for a document's pictures: the app's URL, else the resource's own. */
267
293
  export function imageSource(resources, resolve) {
268
294
  return (key) => {
269
- const resource = resources?.[key];
295
+ const resource = resources && Object.hasOwn(resources, key) ? resources[key] : undefined;
270
296
  if (!resource)
271
297
  return undefined;
272
298
  const url = resolve?.(key, resource);
@@ -502,6 +528,7 @@ export function parseOpaque(xml, doc) {
502
528
  */
503
529
  export function renderBlocks(document, doc, options = {}) {
504
530
  const review = options.review ?? "markup";
531
+ const codes = options.fieldCodes === true;
505
532
  const ratios = new Map();
506
533
  const ratio = (family) => {
507
534
  let value = ratios.get(family);
@@ -511,7 +538,7 @@ export function renderBlocks(document, doc, options = {}) {
511
538
  }
512
539
  return value;
513
540
  };
514
- const resolver = new Resolver(document);
541
+ const resolver = options.resolver ?? new Resolver(document);
515
542
  const image = imageSource(document.resources, options.resource);
516
543
  // shortcut: floating pictures are placed against the last section's page.
517
544
  const geometry = floatGeometry(document.section);
@@ -530,32 +557,35 @@ export function renderBlocks(document, doc, options = {}) {
530
557
  // A joined paragraph is numbered once, with the first paragraph's marker.
531
558
  const markers = resolver.markers(content.map((node, index) => node.type === "paragraph" && !joins(index - 1) ? attrsOf(node) : { numbering: { id: 0 } }));
532
559
  const blocks = [];
560
+ const displays = fieldDisplay(content.map(inlineTypes), codes);
533
561
  let carried = null;
534
562
  /** Comment ranges open at this point of the document. */
535
563
  const comments = new Set();
536
564
  content.forEach((node, index) => {
537
565
  if (node.type !== "paragraph") {
538
- blocks.push(opaqueBlock(node, index, resolver, doc, ratio, image, geometry));
566
+ blocks.push(opaqueBlock(node, index, resolver, doc, ratio, image, geometry, codes, options.notes));
539
567
  return;
540
568
  }
541
569
  const attrs = attrsOf(node);
570
+ const own = displays[index];
542
571
  if (joins(index)) {
543
- const previous = carried ?? {
544
- nodes: [],
545
- inline: [],
546
- };
572
+ const previous = carried ?? { nodes: [], inline: [], display: NO_DISPLAY };
547
573
  carried = {
548
574
  nodes: [...previous.nodes, index],
549
575
  inline: [...previous.inline, ...(node.content ?? [])],
576
+ display: joinDisplays(previous.display, previous.inline.length, own),
550
577
  };
551
578
  return;
552
579
  }
553
- const merged = carried ?? { nodes: [], inline: [] };
580
+ const merged = carried ?? { nodes: [], inline: [], display: NO_DISPLAY };
554
581
  carried = null;
582
+ const display = joinDisplays(merged.display, merged.inline.length, own);
555
583
  const { paragraph, run } = resolver.paragraph(attrs);
556
584
  const element = doc.createElement(tagOf(paragraph));
557
585
  styleParagraph(element, paragraph);
558
- styleRun(element, run, lineHeight(paragraph, run, ratio(fontStack(latin(run)))));
586
+ // The line's own height is the paragraph mark's (Word has none but its runs' and the mark's).
587
+ const mark = resolver.run(run, (attrs.markFormat ?? []));
588
+ styleRun(element, mark, lineHeight(paragraph, mark, ratio(fontStack(latin(mark)))));
559
589
  const marker = markers[index];
560
590
  const firstMerged = merged.nodes[0];
561
591
  const shownMarker = firstMerged !== undefined ? (markers[firstMerged] ?? null) : marker;
@@ -570,7 +600,15 @@ export function renderBlocks(document, doc, options = {}) {
570
600
  ratio,
571
601
  image,
572
602
  geometry,
603
+ codes,
604
+ display,
605
+ notes: options.notes,
573
606
  });
607
+ if (display.gone)
608
+ element.style.display = "none";
609
+ if (onlyPictures(inline, (node) => node.type, (node) => !!node.attrs?.float))
610
+ for (const picture of element.querySelectorAll(`[${PICTURE_ATTR}]`))
611
+ picture.style.verticalAlign = "bottom";
574
612
  // An empty paragraph, or one ending in a line break, shows its last (empty) line; after a
575
613
  // page break the paragraph mark stays on the break's line, as in Word.
576
614
  const last = element.lastChild;
@@ -586,8 +624,8 @@ export function renderBlocks(document, doc, options = {}) {
586
624
  blocks.push({
587
625
  element,
588
626
  nodes: [...merged.nodes, index],
589
- before: pt(spaceBefore),
590
- after: pt(spaceAfter),
627
+ before: display.gone ? 0 : pt(spaceBefore),
628
+ after: display.gone ? 0 : pt(spaceAfter),
591
629
  keepNext: paragraph.keepNext,
592
630
  keepLines: paragraph.keepLines,
593
631
  pageBreakBefore: paragraph.pageBreakBefore,
@@ -597,26 +635,86 @@ export function renderBlocks(document, doc, options = {}) {
597
635
  if (paragraph.contextualSpacing)
598
636
  element.dataset.contextual = "";
599
637
  });
600
- applyContextualSpacing(blocks);
638
+ applyContextualSpacing(blocks, resolver.addsParagraphSpacing);
601
639
  return blocks;
602
640
  }
641
+ const NO_DISPLAY = fieldDisplay([[]], false)[0];
642
+ const inlineTypes = (node) => node.type === "paragraph" ? (node.content ?? []).map((child) => child.type) : [];
643
+ /** `after`, whose nodes follow `length` others, added to `before` (paragraphs drawn as one). */
644
+ function joinDisplays(before, length, after) {
645
+ if (!length)
646
+ return after;
647
+ return {
648
+ hidden: new Set([...before.hidden, ...[...after.hidden].map((i) => i + length)]),
649
+ braces: new Map([
650
+ ...before.braces,
651
+ ...[...after.braces].map(([i, b]) => [i + length, b]),
652
+ ]),
653
+ gone: before.gone && after.gone,
654
+ };
655
+ }
656
+ /**
657
+ * Whether a paragraph's line holds nothing but inline pictures: Word's line then ends at the
658
+ * picture's foot (its PDFs of the corpus: no room below it for the text it does not have).
659
+ */
660
+ export function onlyPictures(inline, type, floats) {
661
+ let found = false;
662
+ for (const node of inline) {
663
+ const name = type(node);
664
+ if (name === "picture")
665
+ found ||= !floats(node);
666
+ else if (!INVISIBLE.has(name))
667
+ return false;
668
+ }
669
+ return found;
670
+ }
671
+ const INVISIBLE = new Set([
672
+ "bookmarkStart",
673
+ "bookmarkEnd",
674
+ "commentStart",
675
+ "commentEnd",
676
+ "commentReference",
677
+ "controlStart",
678
+ "controlEnd",
679
+ "fieldStart",
680
+ "fieldCode",
681
+ "fieldSeparator",
682
+ "fieldEnd",
683
+ ]);
684
+ /**
685
+ * The top margin of a paragraph after another (whose space after is `above`) in a box the page
686
+ * flow does not lay out (a table cell). Adjacent margins collapse to the larger: Word's rule. In
687
+ * a document where the two spaces add up this margin holds both, so the collapse gives the sum
688
+ * and no paragraph's shading or border grows.
689
+ */
690
+ export function marginAbove(before, above, resolver) {
691
+ return resolver.addsParagraphSpacing ? before + above : before;
692
+ }
603
693
  /** A paragraph's element: a heading of its outline level (1-6), else a paragraph. */
604
694
  export function tagOf(paragraph) {
605
695
  const level = paragraph.outlineLevel;
606
696
  return level !== null && level >= 0 && level < 6 ? `h${level + 1}` : "p";
607
697
  }
608
- /** Word ignores the space between paragraphs of the same style that ask for it. */
609
- function applyContextualSpacing(blocks) {
698
+ /**
699
+ * Word ignores the space between paragraphs of the same style that ask for it. When only the
700
+ * first asks, its space after still eats into the second's space before, unless the document
701
+ * adds the two (`adds`).
702
+ */
703
+ function applyContextualSpacing(blocks, adds) {
610
704
  for (let i = 1; i < blocks.length; i++) {
611
705
  const a = blocks[i - 1];
612
706
  const b = blocks[i];
613
707
  const style = a.element.dataset.style;
614
708
  if (style === undefined || style !== b.element.dataset.style)
615
709
  continue;
616
- if ("contextual" in a.element.dataset)
617
- a.after = 0;
618
- if ("contextual" in b.element.dataset)
710
+ const first = "contextual" in a.element.dataset;
711
+ const second = "contextual" in b.element.dataset;
712
+ if (second)
619
713
  b.before = 0;
714
+ else if (first && !adds)
715
+ b.before = Math.max(0, b.before - a.after);
716
+ if (first)
717
+ a.after = 0;
620
718
  }
621
719
  }
622
720
  /** Symbol and Wingdings bullets (`w:lvlText`, private-use code points) as Unicode. */
@@ -663,9 +761,11 @@ export function markerElement(marker, paragraph, doc, ratio) {
663
761
  }
664
762
  /** A paragraph's inline content: runs as spans, breaks, comment anchors, opaque inline content. */
665
763
  function renderInline(parent, inline, paragraphRun, paragraph, context) {
666
- const { resolver, doc, review, comments, ratio, image } = context;
764
+ const { resolver, doc, review, comments, ratio, image, codes, display } = context;
667
765
  const floats = [];
668
- for (const node of inline) {
766
+ for (const [index, node] of inline.entries()) {
767
+ if (display.hidden.has(index))
768
+ continue;
669
769
  const marks = (node.marks ?? []);
670
770
  const inserted = marks.some((m) => m.type === "insertion");
671
771
  const deleted = marks.some((m) => m.type === "deletion");
@@ -685,8 +785,17 @@ function renderInline(parent, inline, paragraphRun, paragraph, context) {
685
785
  parent.append(anchor);
686
786
  continue;
687
787
  }
688
- case "bookmarkStart":
788
+ case "bookmarkStart": {
789
+ // Where a link to it goes (`@folijs/pdf`); out of the flow, so no line changes.
790
+ const mark = doc.createElement("span");
791
+ mark.dataset.foliBookmark = String(attrs.name ?? "");
792
+ mark.style.position = "absolute";
793
+ parent.append(mark);
794
+ continue;
795
+ }
689
796
  case "bookmarkEnd":
797
+ case "controlStart":
798
+ case "controlEnd":
690
799
  continue;
691
800
  case "picture":
692
801
  if (attrs.float)
@@ -695,10 +804,14 @@ function renderInline(parent, inline, paragraphRun, paragraph, context) {
695
804
  parent.append(pictureElement(attrs, doc, image));
696
805
  continue;
697
806
  case "hardBreak":
698
- case "columnBreak":
699
- // shortcut: a column break ends the line; Foli lays out one column.
700
807
  parent.append(doc.createElement("br"));
701
808
  continue;
809
+ case "columnBreak": {
810
+ const br = doc.createElement("br");
811
+ br.setAttribute(WORD_COLUMN_BREAK_ATTR, "");
812
+ parent.append(br);
813
+ continue;
814
+ }
702
815
  case "pageBreak": {
703
816
  const br = doc.createElement("br");
704
817
  br.setAttribute(WORD_PAGE_BREAK_ATTR, "");
@@ -707,13 +820,25 @@ function renderInline(parent, inline, paragraphRun, paragraph, context) {
707
820
  }
708
821
  default:
709
822
  }
823
+ const code = display.braces.get(index) ?? (codes && node.type === "fieldCode" ? String(attrs.text) : "");
710
824
  let text;
711
- if (node.type === "text")
825
+ if (code)
826
+ text = code;
827
+ else if (node.type === "text")
712
828
  text = node.text ?? "";
713
829
  else if (node.type === "tab")
714
830
  text = "\t";
831
+ else if (node.type === "noteReference")
832
+ text = context.notes?.references?.get(String(attrs.story)) ?? "";
833
+ else if (node.type === "noteMark")
834
+ text = context.notes?.mark ?? "";
715
835
  else if (node.type === "opaqueInline") {
716
836
  const xml = parseOpaque(String(attrs.xml ?? ""), doc);
837
+ const separator = separatorElement(xml, doc);
838
+ if (separator) {
839
+ parent.append(separator);
840
+ continue;
841
+ }
717
842
  // A run's content (a drawing, a field character) shows as nothing; a content control or
718
843
  // simple field as its text.
719
844
  text = xml ? opaqueText(xml) : "";
@@ -730,6 +855,10 @@ function renderInline(parent, inline, paragraphRun, paragraph, context) {
730
855
  let element = doc.createElement("span");
731
856
  styleRun(element, run, lineHeight(paragraph, run, ratio(fontStack(latin(run)))));
732
857
  element.textContent = text;
858
+ if (node.type === "noteReference")
859
+ element.setAttribute(NOTE_REF_ATTR, String(attrs.story));
860
+ if (node.type === "noteReference" || node.type === "noteMark")
861
+ element.setAttribute(NOTE_NUMBER_ATTR, "");
733
862
  const link = marks.find((m) => m.type === "link");
734
863
  if (link)
735
864
  element.dataset.href = String(link.attrs?.href ?? `#${String(link.attrs?.anchor)}`);
@@ -759,7 +888,7 @@ function renderInline(parent, inline, paragraphRun, paragraph, context) {
759
888
  */
760
889
  export function opaqueBlock(node, index, resolver, doc, ratio, image,
761
890
  /** The page floating pictures in its cells are placed against. */
762
- geometry = floatGeometry(undefined)) {
891
+ geometry = floatGeometry(undefined), codes = false, notes) {
763
892
  const attrs = (node.attrs ?? {});
764
893
  const element = doc.createElement("div");
765
894
  element.dataset.foliOpaque = String(attrs.label ?? "");
@@ -768,17 +897,19 @@ geometry = floatGeometry(undefined)) {
768
897
  const xml = node.type === "table" ? null : parseOpaque(String(attrs.xml ?? ""), doc);
769
898
  let after = 0;
770
899
  if (node.type === "table")
771
- element.append(modelTable(node, resolver, doc, ratio, image, geometry));
900
+ element.append(modelTable(node, resolver, doc, ratio, image, geometry, codes, notes));
772
901
  else if (xml?.localName === "tbl")
773
902
  element.append(opaqueTable(xml, resolver, doc, ratio));
774
903
  else if (xml) {
775
904
  const paragraphs = outermost(xml, PARAGRAPHS);
905
+ let above = 0;
776
906
  paragraphs.forEach((p, i) => {
777
- const rendered = opaqueParagraph(p, resolver, doc, ratio);
907
+ const rendered = opaqueParagraph(p, resolver, doc, ratio, above);
778
908
  if (i < paragraphs.length - 1)
779
909
  rendered.element.style.marginBottom = `${rendered.after}px`;
780
910
  else
781
911
  after = rendered.after;
912
+ above = rendered.after;
782
913
  element.append(rendered.element);
783
914
  });
784
915
  }
@@ -816,7 +947,9 @@ function child(element, name) {
816
947
  return undefined;
817
948
  }
818
949
  /** A paragraph of opaque XML: its style's formatting and its text. */
819
- function opaqueParagraph(p, resolver, doc, ratio) {
950
+ function opaqueParagraph(p, resolver, doc, ratio,
951
+ /** The space after the paragraph before it in its box. */
952
+ above = 0) {
820
953
  const pPr = child(p, "pPr");
821
954
  const style = childValue(pPr, "pStyle");
822
955
  const justification = childValue(pPr, "jc");
@@ -838,8 +971,9 @@ function opaqueParagraph(p, resolver, doc, ratio) {
838
971
  }
839
972
  if (!element.textContent)
840
973
  element.append(doc.createElement("br"));
841
- if (paragraph.spacing.before)
842
- element.style.marginTop = `${paragraph.spacing.before * PX_PER_TWIP}px`;
974
+ const top = marginAbove(paragraph.spacing.before * PX_PER_TWIP, above, resolver);
975
+ if (top)
976
+ element.style.marginTop = `${top}px`;
843
977
  return { element, after: paragraph.spacing.after * PX_PER_TWIP };
844
978
  }
845
979
  /** The run properties of verbatim XML Foli reads for showing it (`w:rPr`) as marks. */
@@ -973,14 +1107,17 @@ function opaqueTable(tbl, resolver, doc, ratio) {
973
1107
  row.append(cell);
974
1108
  continue;
975
1109
  }
1110
+ let above = 0;
976
1111
  for (const p of outermost(tc, CELL_CONTENT)) {
977
1112
  if (p.localName === "tbl") {
978
1113
  cell.append(opaqueTable(p, resolver, doc, ratio));
1114
+ above = 0;
979
1115
  continue;
980
1116
  }
981
1117
  // Word counts the space after a cell's last paragraph in the row's height too.
982
- const rendered = opaqueParagraph(p, resolver, doc, ratio);
1118
+ const rendered = opaqueParagraph(p, resolver, doc, ratio, above);
983
1119
  rendered.element.style.marginBottom = `${rendered.after}px`;
1120
+ above = rendered.after;
984
1121
  cell.append(rendered.element);
985
1122
  }
986
1123
  row.append(cell);
@@ -1004,10 +1141,11 @@ export function borderJsonCss(border) {
1004
1141
  * A table of the model (schema v4), read-only, as opaque tables are shown: rows, cells with
1005
1142
  * their table style's formatting (`Resolver.cell`), their paragraphs and nested tables.
1006
1143
  *
1007
- * shortcut: a stopgap until tables are laid out on pages and edited (10.5, 10.6): one block,
1008
- * not split across pages; a cell merged into the one above is shown empty, as opaque tables are.
1144
+ * shortcut: `renderDocument`'s tables (the editing view draws its own, `table.ts`): one block,
1145
+ * split across pages as clips; a cell merged into the one above is shown empty, as opaque
1146
+ * tables are.
1009
1147
  */
1010
- function modelTable(node, resolver, doc, ratio, image, geometry) {
1148
+ function modelTable(node, resolver, doc, ratio, image, geometry, codes, notes) {
1011
1149
  const attrs = (node.attrs ?? {});
1012
1150
  const table = doc.createElement("table");
1013
1151
  table.style.borderCollapse = "collapse";
@@ -1034,6 +1172,7 @@ function modelTable(node, resolver, doc, ratio, image, geometry) {
1034
1172
  image,
1035
1173
  // shortcut: a floating picture in a cell is placed against the page, not its cell.
1036
1174
  geometry,
1175
+ codes,
1037
1176
  };
1038
1177
  rows.forEach((rowNode, r) => {
1039
1178
  const rowAttrs = (rowNode.attrs ?? {});
@@ -1069,13 +1208,18 @@ function modelTable(node, resolver, doc, ratio, image, geometry) {
1069
1208
  row.append(cell);
1070
1209
  if (cellAttrs.vMerge === "continue")
1071
1210
  return;
1072
- for (const block of cellNode.content ?? []) {
1211
+ let above = 0;
1212
+ const blocks = cellNode.content ?? [];
1213
+ const displays = fieldDisplay(blocks.map(inlineTypes), codes);
1214
+ for (const [b, block] of blocks.entries()) {
1073
1215
  if (block.type === "table") {
1074
- cell.append(modelTable(block, resolver, doc, ratio, image, geometry));
1216
+ cell.append(modelTable(block, resolver, doc, ratio, image, geometry, codes, notes));
1217
+ above = 0;
1075
1218
  continue;
1076
1219
  }
1077
1220
  if (block.type !== "paragraph") {
1078
- cell.append(opaqueBlock(block, 0, resolver, doc, ratio, image, geometry).element);
1221
+ cell.append(opaqueBlock(block, 0, resolver, doc, ratio, image, geometry, codes, notes).element);
1222
+ above = 0;
1079
1223
  continue;
1080
1224
  }
1081
1225
  const { paragraph, run } = resolver.paragraph(block.attrs ?? {}, format);
@@ -1084,12 +1228,21 @@ function modelTable(node, resolver, doc, ratio, image, geometry) {
1084
1228
  element.dataset.foliCell = "";
1085
1229
  styleParagraph(element, paragraph);
1086
1230
  styleRun(element, run, lineHeight(paragraph, run, ratio(fontStack(latin(run)))));
1087
- renderInline(element, block.content ?? [], run, paragraph, context);
1231
+ const display = displays[b];
1232
+ renderInline(element, block.content ?? [], run, paragraph, {
1233
+ ...context,
1234
+ display,
1235
+ notes,
1236
+ });
1237
+ if (display.gone)
1238
+ element.style.display = "none";
1088
1239
  if (!element.textContent)
1089
1240
  element.append(doc.createElement("br"));
1090
- element.style.marginTop = `${paragraph.spacing.before * PX_PER_TWIP}px`;
1241
+ const before = paragraph.spacing.before * PX_PER_TWIP;
1242
+ element.style.marginTop = `${marginAbove(before, above, resolver)}px`;
1091
1243
  // Word counts the space after a cell's last paragraph in the row's height too.
1092
- element.style.marginBottom = `${paragraph.spacing.after * PX_PER_TWIP}px`;
1244
+ above = paragraph.spacing.after * PX_PER_TWIP;
1245
+ element.style.marginBottom = `${above}px`;
1093
1246
  cell.append(element);
1094
1247
  }
1095
1248
  });