@folijs/view 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +1 -1
  3. package/dist/clipboard.d.ts +1 -49
  4. package/dist/clipboard.d.ts.map +1 -1
  5. package/dist/clipboard.js +65 -13
  6. package/dist/clipboard.js.map +1 -1
  7. package/dist/extension.d.ts +90 -0
  8. package/dist/extension.d.ts.map +1 -0
  9. package/dist/extension.js +152 -0
  10. package/dist/extension.js.map +1 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/layout/flow.d.ts +1 -109
  15. package/dist/layout/flow.d.ts.map +1 -1
  16. package/dist/layout/flow.js +808 -103
  17. package/dist/layout/flow.js.map +1 -1
  18. package/dist/print.d.ts +6 -0
  19. package/dist/print.d.ts.map +1 -0
  20. package/dist/print.js +35 -0
  21. package/dist/print.js.map +1 -0
  22. package/dist/render.d.ts +1 -24
  23. package/dist/render.d.ts.map +1 -1
  24. package/dist/render.js +4 -1
  25. package/dist/render.js.map +1 -1
  26. package/dist/view.d.ts +244 -64
  27. package/dist/view.d.ts.map +1 -1
  28. package/dist/view.js +1945 -215
  29. package/dist/view.js.map +1 -1
  30. package/dist/word/blocks.d.ts +0 -146
  31. package/dist/word/blocks.d.ts.map +1 -1
  32. package/dist/word/blocks.js +294 -59
  33. package/dist/word/blocks.js.map +1 -1
  34. package/dist/word/columns.d.ts +2 -0
  35. package/dist/word/columns.d.ts.map +1 -0
  36. package/dist/word/columns.js +63 -0
  37. package/dist/word/columns.js.map +1 -0
  38. package/dist/word/controls.d.ts +2 -0
  39. package/dist/word/controls.d.ts.map +1 -0
  40. package/dist/word/controls.js +416 -0
  41. package/dist/word/controls.js.map +1 -0
  42. package/dist/word/edit.d.ts +1 -71
  43. package/dist/word/edit.d.ts.map +1 -1
  44. package/dist/word/edit.js +338 -29
  45. package/dist/word/edit.js.map +1 -1
  46. package/dist/word/matches.d.ts +2 -0
  47. package/dist/word/matches.d.ts.map +1 -0
  48. package/dist/word/matches.js +102 -0
  49. package/dist/word/matches.js.map +1 -0
  50. package/dist/word/notes.d.ts +2 -0
  51. package/dist/word/notes.d.ts.map +1 -0
  52. package/dist/word/notes.js +403 -0
  53. package/dist/word/notes.js.map +1 -0
  54. package/dist/word/pages.d.ts +30 -20
  55. package/dist/word/pages.d.ts.map +1 -1
  56. package/dist/word/pages.js +421 -229
  57. package/dist/word/pages.js.map +1 -1
  58. package/dist/word/regions.d.ts +2 -0
  59. package/dist/word/regions.d.ts.map +1 -0
  60. package/dist/word/regions.js +388 -0
  61. package/dist/word/regions.js.map +1 -0
  62. package/dist/word/table.d.ts +1 -78
  63. package/dist/word/table.d.ts.map +1 -1
  64. package/dist/word/table.js +13 -3
  65. package/dist/word/table.js.map +1 -1
  66. package/package.json +6 -3
  67. package/src/clipboard.ts +93 -20
  68. package/src/extension.ts +267 -0
  69. package/src/index.ts +10 -0
  70. package/src/layout/flow.ts +997 -116
  71. package/src/print.ts +55 -0
  72. package/src/render.ts +6 -1
  73. package/src/view.ts +2178 -245
  74. package/src/word/blocks.ts +339 -62
  75. package/src/word/columns.ts +81 -0
  76. package/src/word/controls.ts +457 -0
  77. package/src/word/edit.ts +381 -31
  78. package/src/word/matches.ts +104 -0
  79. package/src/word/notes.ts +464 -0
  80. package/src/word/pages.ts +518 -221
  81. package/src/word/regions.ts +488 -0
  82. package/src/word/table.ts +33 -8
@@ -0,0 +1,488 @@
1
+ /**
2
+ * Headers and footers on pages (11.7, ADR-0007), for both renderers: which story a page shows, how
3
+ * tall it is with that page's fields filled in, how far it pushes the text, and its elements.
4
+ * A story is always drawn from the model here, by the read-only blocks renderer; `PAGE`, `NUMPAGES`
5
+ * and `SECTIONPAGES` are filled in the copy drawn, never in the document.
6
+ */
7
+ import {
8
+ type FoliDocument,
9
+ type NodeJSON,
10
+ pageVariant,
11
+ type SectionJSON,
12
+ type StoryJSON,
13
+ type StorySide,
14
+ storyOfSection,
15
+ } from "@folijs/core";
16
+ import { formatNumber, type Resolver } from "@folijs/core/internal";
17
+ import type { FlowPage, PageFacts } from "../layout/flow.js";
18
+ import { type BlockOptions, PX_PER_TWIP, renderBlocks, type WordBlock } from "./blocks.js";
19
+
20
+ /**
21
+ * On what shows a page field's number in a drawn copy of a story.
22
+ * @internal
23
+ */
24
+ export const PAGE_FIELD_ATTR = "data-foli-page-field";
25
+
26
+ /**
27
+ * The class of a page's header or footer element.
28
+ * @internal
29
+ */
30
+ export const REGION_CLASS = "foli-region";
31
+ /** @internal */
32
+ export const REGION_CONTENT_CLASS = "foli-region-content";
33
+
34
+ /** Word's distance from the page's edge when a section does not give one: half an inch. */
35
+ const EDGE = 720;
36
+
37
+ /**
38
+ * What the page fields of a page show.
39
+ * @internal
40
+ */
41
+ export interface FieldValues {
42
+ page: string;
43
+ pages: string;
44
+ sectionPages: string;
45
+ }
46
+
47
+ const PAGE_FIELDS = new Set(["PAGE", "NUMPAGES", "SECTIONPAGES"]);
48
+ /** `\\*` switches: `arabic` in any case, the others as Word spells their case. */
49
+ const FORMATS = new Map([
50
+ ["roman", "lowerRoman"],
51
+ ["ROMAN", "upperRoman"],
52
+ ["alphabetic", "lowerLetter"],
53
+ ["ALPHABETIC", "upperLetter"],
54
+ ]);
55
+
56
+ /** A page field in a story: which, and the format its own switch asks for. */
57
+ interface FieldSlot {
58
+ name: string;
59
+ format: string | undefined;
60
+ }
61
+
62
+ /** Stands in the drawn story for a slot's text: the private use area is not document text. */
63
+ const SLOT_MARK = "\uE000";
64
+ const SLOT_TEXT = /\uE000([\uE100-\uF8FF])/g;
65
+
66
+ /** The page field `code` (its instruction) is, or null. */
67
+ function pageField(code: string): FieldSlot | null {
68
+ const name = code.trim().split(/\s+/)[0]?.toUpperCase() ?? "";
69
+ if (!PAGE_FIELDS.has(name)) return null;
70
+ const asked = /\\\*\s*(\S+)/.exec(code)?.[1];
71
+ const format = asked?.toLowerCase() === "arabic" ? "decimal" : FORMATS.get(asked ?? "");
72
+ return { name, format };
73
+ }
74
+
75
+ /** What `slot` shows; the section's number format is the page number's, a switch goes first. */
76
+ function slotText(slot: FieldSlot, values: FieldValues, numbers: string | undefined): string {
77
+ const raw =
78
+ slot.name === "PAGE"
79
+ ? values.page
80
+ : slot.name === "NUMPAGES"
81
+ ? values.pages
82
+ : values.sectionPages;
83
+ return formatNumber(Number(raw), slot.format ?? (slot.name === "PAGE" ? numbers : undefined));
84
+ }
85
+
86
+ /**
87
+ * A paragraph's inline nodes with each page field's result replaced by a mark for its slot (one
88
+ * run, formatted as the result's first). Only whole fields inside the list: a page field does not
89
+ * span paragraphs.
90
+ */
91
+ function markInline(nodes: readonly NodeJSON[], slots: FieldSlot[]): NodeJSON[] {
92
+ const out: NodeJSON[] = [];
93
+ for (let i = 0; i < nodes.length; i++) {
94
+ const node = nodes[i] as NodeJSON;
95
+ out.push(node);
96
+ if (node.type !== "fieldStart") continue;
97
+ let depth = 1;
98
+ let separator = -1;
99
+ let end = -1;
100
+ let code = "";
101
+ for (let j = i + 1; j < nodes.length && end < 0; j++) {
102
+ const inner = nodes[j] as NodeJSON;
103
+ if (inner.type === "fieldStart") depth++;
104
+ else if (inner.type === "fieldEnd" && --depth === 0) end = j;
105
+ else if (depth === 1 && inner.type === "fieldSeparator" && separator < 0) separator = j;
106
+ else if (depth === 1 && separator < 0 && inner.type === "fieldCode")
107
+ code += String(inner.attrs?.text ?? "");
108
+ }
109
+ const slot = end < 0 ? null : pageField(code);
110
+ if (!slot) continue;
111
+ const codeEnd = separator < 0 ? end : separator + 1;
112
+ const result = nodes.slice(codeEnd, end);
113
+ const model = result.find((n) => n.type === "text") ?? nodes[codeEnd - 1];
114
+ out.push(...nodes.slice(i + 1, codeEnd));
115
+ out.push({
116
+ type: "text",
117
+ text: SLOT_MARK + String.fromCharCode(0xe100 + slots.length),
118
+ ...(model?.marks ? { marks: model.marks } : {}),
119
+ });
120
+ slots.push(slot);
121
+ out.push(nodes[end] as NodeJSON);
122
+ i = end;
123
+ }
124
+ return out;
125
+ }
126
+
127
+ /** `node` with the page fields in it marked. */
128
+ function marked(node: NodeJSON, slots: FieldSlot[]): NodeJSON {
129
+ if (!node.content) return node;
130
+ const content =
131
+ node.type === "paragraph"
132
+ ? markInline(node.content, slots)
133
+ : node.content.map((child) => marked(child, slots));
134
+ return { ...node, content };
135
+ }
136
+
137
+ /** A copy of `template` with each slot's text in it. */
138
+ function filledCopy(template: HTMLElement, texts: readonly string[]): HTMLElement {
139
+ const copy = template.cloneNode(true) as HTMLElement;
140
+ if (!texts.length) return copy;
141
+ const walker = template.ownerDocument.createTreeWalker(copy, NodeFilter.SHOW_TEXT);
142
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
143
+ const text = node as Text;
144
+ // A page's own number: not document text (find leaves it alone).
145
+ if (text.data.replace(SLOT_TEXT, "") === "" && text.data)
146
+ text.parentElement?.setAttribute(PAGE_FIELD_ATTR, "");
147
+ if (text.data.includes(SLOT_MARK))
148
+ text.data = text.data.replace(
149
+ SLOT_TEXT,
150
+ (_, slot: string) => texts[slot.charCodeAt(0) - 0xe100] ?? "",
151
+ );
152
+ }
153
+ return copy;
154
+ }
155
+
156
+ /** A story with some values: its height, and its content to draw (made when asked for). */
157
+ interface Drawn {
158
+ height: number;
159
+ readonly content: HTMLElement;
160
+ }
161
+
162
+ /** A story once drawn, its page fields left to fill: what every page starts from. */
163
+ interface StoryDrawing {
164
+ slots: FieldSlot[];
165
+ template: HTMLElement;
166
+ /** The last block's space after, which ends the story. */
167
+ after: number;
168
+ drawn: Map<string, Drawn>;
169
+ heights: Map<string, number>;
170
+ }
171
+
172
+ /**
173
+ * Per story (an object replaced when the story changes), what was measured and drawn of it.
174
+ * @internal
175
+ */
176
+ export type RegionCache = WeakMap<StoryJSON, StoryDrawing>;
177
+
178
+ /** A section's page as the regions need it, in CSS px. */
179
+ interface Edges {
180
+ top: number;
181
+ bottom: number;
182
+ /** Whether a header or footer can push the text (a negative margin is exact, as in Word). */
183
+ pushesTop: boolean;
184
+ pushesBottom: boolean;
185
+ header: number;
186
+ footer: number;
187
+ left: number;
188
+ right: number;
189
+ height: number;
190
+ width: number;
191
+ }
192
+
193
+ function edgesOf(section: SectionJSON): Edges {
194
+ const m = section.margins ?? {};
195
+ const top = m.top ?? 1440;
196
+ const bottom = m.bottom ?? 1440;
197
+ const left = (m.left ?? 1440) + (m.gutter ?? 0);
198
+ const right = m.right ?? 1440;
199
+ const width = section.pageSize?.width ?? 12_240;
200
+ return {
201
+ top: Math.abs(top) * PX_PER_TWIP,
202
+ bottom: Math.abs(bottom) * PX_PER_TWIP,
203
+ pushesTop: top >= 0,
204
+ pushesBottom: bottom >= 0,
205
+ header: (m.header ?? EDGE) * PX_PER_TWIP,
206
+ footer: (m.footer ?? EDGE) * PX_PER_TWIP,
207
+ left: left * PX_PER_TWIP,
208
+ right: right * PX_PER_TWIP,
209
+ height: (section.pageSize?.height ?? 15_840) * PX_PER_TWIP,
210
+ width: Math.max(width - left - right, 1) * PX_PER_TWIP,
211
+ };
212
+ }
213
+
214
+ /**
215
+ * Lays `blocks` out as a story: spacing as between the paragraphs of a page.
216
+ * @internal
217
+ */
218
+ export function stack(blocks: readonly WordBlock[], parent: HTMLElement, adds: boolean): number {
219
+ let previous = 0;
220
+ blocks.forEach((block, i) => {
221
+ const gap = !i
222
+ ? block.before
223
+ : adds
224
+ ? previous + block.before
225
+ : Math.max(previous, block.before);
226
+ block.element.style.marginTop = `${gap}px`;
227
+ block.element.style.marginBottom = "0";
228
+ previous = block.after;
229
+ parent.append(block.element);
230
+ });
231
+ return previous;
232
+ }
233
+
234
+ /** @internal */
235
+ export interface RegionOptions extends Omit<BlockOptions, "resolver"> {
236
+ /** Where stories are measured (hidden, for a moment). */
237
+ measureIn(): HTMLElement;
238
+ /** Layout px per measured px's inverse: what a scaled ancestor multiplies sizes by. */
239
+ scale?(): number;
240
+ }
241
+
242
+ /**
243
+ * What the layout of a document's pages needs to know of their headers and footers.
244
+ * @internal
245
+ */
246
+ export class PageRegions {
247
+ /** The page count and each section's, as of the last flow (the fields' values). */
248
+ private pages = 1;
249
+ private sectionPages = new Map<number, number>();
250
+ private edges: Edges[] = [];
251
+ /** The pages of the last flow. */
252
+ private flowed: readonly PageFacts[] = [];
253
+ private document: Omit<FoliDocument, "content"> | null = null;
254
+ /** The document's sections, in order. */
255
+ private sections: readonly SectionJSON[] = [];
256
+ private resolver: Resolver | null = null;
257
+
258
+ constructor(
259
+ private readonly doc: Document,
260
+ private readonly options: RegionOptions,
261
+ /** Kept across layouts by the view; replaced when what stories look like changes. */
262
+ public cache: RegionCache,
263
+ ) {}
264
+
265
+ /** What is laid out now. */
266
+ setDocument(
267
+ document: Omit<FoliDocument, "content">,
268
+ sections: readonly SectionJSON[],
269
+ resolver: Resolver,
270
+ ): void {
271
+ this.document = document;
272
+ this.sections = sections;
273
+ this.resolver = resolver;
274
+ this.edges = [];
275
+ }
276
+
277
+ /** A story by id: ids come from the file, and may name what every object inherits. */
278
+ private story(id: string): StoryJSON | undefined {
279
+ const stories = this.document?.stories;
280
+ return stories && Object.hasOwn(stories, id) ? stories[id] : undefined;
281
+ }
282
+
283
+ private edgesAt(index: number): Edges {
284
+ let found = this.edges[index];
285
+ if (!found) {
286
+ found = edgesOf(this.sections[index] ?? {});
287
+ this.edges[index] = found;
288
+ }
289
+ return found;
290
+ }
291
+
292
+ /** The story a page of section `index` shows, as `first` and its number say. */
293
+ storyId(index: number, side: StorySide, page: { first: boolean; number: number }): string | null {
294
+ const section = this.sections[index];
295
+ if (!section) return null;
296
+ const even = this.document?.settings?.evenAndOddHeaders === true;
297
+ const variant = pageVariant(section, page, even);
298
+ const found = storyOfSection(this.sections, index, side, variant);
299
+ return found && this.story(found.id) ? found.id : null;
300
+ }
301
+
302
+ private entry(story: StoryJSON): StoryDrawing {
303
+ let entry = this.cache.get(story);
304
+ if (!entry) {
305
+ const slots: FieldSlot[] = [];
306
+ const content = marked(story.content, slots);
307
+ const template = this.doc.createElement("div");
308
+ template.className = REGION_CONTENT_CLASS;
309
+ template.style.paddingTop = "0.01px";
310
+ const blocks = renderBlocks({ ...this.document, content } as FoliDocument, this.doc, {
311
+ ...this.options,
312
+ ...(this.resolver ? { resolver: this.resolver } : {}),
313
+ });
314
+ const after = stack(blocks, template, !!this.resolver?.addsParagraphSpacing);
315
+ // The last space after is the story's too: a footer sits above it.
316
+ template.style.paddingBottom = `${after}px`;
317
+ entry = { slots, template, after, drawn: new Map(), heights: new Map() };
318
+ this.cache.set(story, entry);
319
+ }
320
+ return entry;
321
+ }
322
+
323
+ private valuesFor(index: number, number: number): FieldValues {
324
+ return {
325
+ page: String(number),
326
+ pages: String(this.pages),
327
+ sectionPages: String(this.sectionPages.get(index) ?? 1),
328
+ };
329
+ }
330
+
331
+ private drawn(id: string, index: number, number: number): Drawn {
332
+ const entry = this.entry(this.story(id) as StoryJSON);
333
+ const edges = this.edgesAt(index);
334
+ const values = this.valuesFor(index, number);
335
+ const numbers = this.sections[index]?.pageNumbers?.format;
336
+ const texts = entry.slots.map((slot) => slotText(slot, values, numbers));
337
+ const key = `${edges.width}|${texts.join("|")}`;
338
+ let found = entry.drawn.get(key);
339
+ if (!found) {
340
+ let content: HTMLElement | null = null;
341
+ const made = () => {
342
+ content ??= filledCopy(entry.template, texts);
343
+ return content;
344
+ };
345
+ // shortcut: numbers of as many digits are taken to wrap alike (digits are about as wide);
346
+ // measuring each page's costs a layout per page per keystroke. Letters are not: `iii`, `vii`.
347
+ const shape = `${edges.width}|${texts
348
+ .map((text) => (/^\d*$/.test(text) ? text.length : text))
349
+ .join(" ")}`;
350
+ let height = entry.heights.get(shape);
351
+ if (height === undefined) {
352
+ height = this.measure(made(), edges.width, entry.after);
353
+ entry.heights.set(shape, height);
354
+ }
355
+ found = {
356
+ height,
357
+ get content() {
358
+ return made();
359
+ },
360
+ };
361
+ entry.drawn.set(key, found);
362
+ }
363
+ return found;
364
+ }
365
+
366
+ /** A story's height: down to its last block (floating pictures add none) and its space after. */
367
+ private measure(content: HTMLElement, width: number, after: number): number {
368
+ const { style } = content;
369
+ style.position = "absolute";
370
+ style.visibility = "hidden";
371
+ style.width = `${width}px`;
372
+ this.options.measureIn().append(content);
373
+ const last = content.lastElementChild;
374
+ const scale = this.options.scale?.() ?? 1;
375
+ const top = content.getBoundingClientRect().top;
376
+ const bottom = last ? last.getBoundingClientRect().bottom : top;
377
+ content.remove();
378
+ style.position = "";
379
+ style.visibility = "";
380
+ style.width = "";
381
+ return (bottom - top) / scale + after;
382
+ }
383
+
384
+ /** How tall the header or footer of a page is (0: none). */
385
+ private heightOf(index: number, side: StorySide, page: FlowPage): number {
386
+ const id = this.storyId(index, side, page);
387
+ return id ? this.drawn(id, index, page.number).height : 0;
388
+ }
389
+
390
+ /** The margins of a page, a header or footer taller than its own pushing the text. */
391
+ margins(index: number, page: FlowPage): { top: number; bottom: number } {
392
+ const edges = this.edgesAt(index);
393
+ const header = edges.pushesTop ? this.heightOf(index, "header", page) : 0;
394
+ const footer = edges.pushesBottom ? this.heightOf(index, "footer", page) : 0;
395
+ return {
396
+ top: header ? Math.max(edges.top, edges.header + header) : edges.top,
397
+ bottom: footer ? Math.max(edges.bottom, edges.footer + footer) : edges.bottom,
398
+ };
399
+ }
400
+
401
+ /** The height of a page's text. */
402
+ boxHeight(index: number, page: FlowPage): number {
403
+ const { top, bottom } = this.margins(index, page);
404
+ return this.edgesAt(index).height - top - bottom;
405
+ }
406
+
407
+ /**
408
+ * Takes the page counts of a finished flow. Whether its pages' text heights change with them
409
+ * (a `NUMPAGES` that wraps): the flow is then made again, at most twice (ADR-0007).
410
+ */
411
+ settle(pages: readonly PageFacts[]): boolean {
412
+ const heights = () =>
413
+ pages
414
+ .filter((p) => p.sectionPages)
415
+ .map((p) => this.boxHeight(p.section, p))
416
+ .join(" ");
417
+ const before = heights();
418
+ this.flowed = pages;
419
+ this.pages = pages.length;
420
+ this.sectionPages = new Map();
421
+ for (const page of pages)
422
+ if (page.sectionPages) this.sectionPages.set(page.section, page.sectionPages);
423
+ return heights() !== before;
424
+ }
425
+
426
+ /**
427
+ * The header and footer heights of what a section can show and of every flowed page (a page
428
+ * number can wrap from some page on): a change means a new flow.
429
+ */
430
+ key(): string {
431
+ const sides = ["header", "footer"] as const;
432
+ const sampled = this.sections.flatMap((_, index) =>
433
+ sides.flatMap((side) =>
434
+ [
435
+ { first: true, number: 1 },
436
+ { first: false, number: 1 },
437
+ { first: false, number: 2 },
438
+ ].map((page) => this.heightOf(index, side, { ...page, index: 0 })),
439
+ ),
440
+ );
441
+ const flowed = this.flowed
442
+ .filter((page) => page.sectionPages && page.section < this.sections.length)
443
+ .flatMap((page) => sides.map((side) => this.heightOf(page.section, side, page)));
444
+ return [...sampled, "|", ...flowed].join(" ");
445
+ }
446
+
447
+ /** What a page's region shows: equal keys, the same drawing. */
448
+ drawing(
449
+ index: number,
450
+ side: StorySide,
451
+ page: FlowPage,
452
+ ): { id: string; content: Drawn; story: StoryJSON } | null {
453
+ const id = this.storyId(index, side, page);
454
+ if (!id) return null;
455
+ return {
456
+ id,
457
+ content: this.drawn(id, index, page.number),
458
+ story: this.story(id) as StoryJSON,
459
+ };
460
+ }
461
+
462
+ /** A new header or footer element for a page of section `index`. */
463
+ element(index: number, side: StorySide): HTMLElement {
464
+ const edges = this.edgesAt(index);
465
+ const region = this.doc.createElement("div");
466
+ region.className = `${REGION_CLASS} foli-${side}`;
467
+ region.setAttribute("contenteditable", "false");
468
+ const { style } = region;
469
+ // As large as the page: floating pictures in it are placed against the page.
470
+ style.position = "absolute";
471
+ style.inset = "0";
472
+ style.boxSizing = "border-box";
473
+ style.pointerEvents = "none";
474
+ // Not part of what the body's selection shows.
475
+ style.userSelect = "none";
476
+ style.setProperty("-webkit-user-select", "none");
477
+ style.paddingLeft = `${edges.left}px`;
478
+ style.paddingRight = `${edges.right}px`;
479
+ if (side === "header") style.paddingTop = `${edges.header}px`;
480
+ else {
481
+ style.display = "flex";
482
+ style.flexDirection = "column";
483
+ style.justifyContent = "flex-end";
484
+ style.paddingBottom = `${edges.footer}px`;
485
+ }
486
+ return region;
487
+ }
488
+ }
package/src/word/table.ts CHANGED
@@ -5,19 +5,27 @@
5
5
  * table, row and cell elements around its units, built from the model for the rows a page holds.
6
6
  * Built with createElement only.
7
7
  */
8
- import type { CellFormat, Node as ModelNode, Resolver } from "@folijs/core";
8
+ import type { Node as ModelNode } from "@folijs/core";
9
+ import type { CellFormat, Resolver } from "@folijs/core/internal";
9
10
  import { borderJsonCss, PX_PER_TWIP } from "./blocks.js";
10
11
 
11
- /** A block the view renders: its node, the position before it, and the cell format it is in. */
12
+ /**
13
+ * A block the view renders: its node, the position before it, and the cell format it is in.
14
+ * @internal
15
+ */
12
16
  export interface Unit {
13
17
  readonly node: ModelNode;
14
18
  readonly pos: number;
15
19
  readonly cell: CellFormat | null;
16
20
  }
17
21
 
18
- /** What a cell holds, in order: units (by index) and nested tables. */
22
+ /**
23
+ * What a cell holds, in order: units (by index) and nested tables.
24
+ * @internal
25
+ */
19
26
  export type CellItem = { unit: number } | { frame: Frame };
20
27
 
28
+ /** @internal */
21
29
  export interface FrameCell {
22
30
  readonly node: ModelNode;
23
31
  /** The first grid column it covers, and how many. */
@@ -28,6 +36,7 @@ export interface FrameCell {
28
36
  readonly items: readonly CellItem[];
29
37
  }
30
38
 
39
+ /** @internal */
31
40
  export interface FrameRow {
32
41
  readonly node: ModelNode;
33
42
  readonly header: boolean;
@@ -37,7 +46,10 @@ export interface FrameRow {
37
46
  readonly cells: readonly FrameCell[];
38
47
  }
39
48
 
40
- /** A table as the view draws it. */
49
+ /**
50
+ * A table as the view draws it.
51
+ * @internal
52
+ */
41
53
  export interface Frame {
42
54
  readonly node: ModelNode;
43
55
  readonly pos: number;
@@ -52,10 +64,16 @@ export interface Frame {
52
64
  readonly end: number;
53
65
  }
54
66
 
55
- /** A top-level item of the page flow: a unit (paragraph, opaque block) or a table. */
67
+ /**
68
+ * A top-level item of the page flow: a unit (paragraph, opaque block) or a table.
69
+ * @internal
70
+ */
56
71
  export type FlowItem = { unit: number; frame?: undefined } | { frame: Frame; unit?: undefined };
57
72
 
58
- /** The units and flow items of `doc`, in document order. */
73
+ /**
74
+ * The units and flow items of `doc`, in document order.
75
+ * @internal
76
+ */
59
77
  export function collect(doc: ModelNode, resolver: Resolver): { units: Unit[]; items: FlowItem[] } {
60
78
  const units: Unit[] = [];
61
79
  const items: FlowItem[] = [];
@@ -142,9 +160,15 @@ function frameOf(table: ModelNode, pos: number, resolver: Resolver, units: Unit[
142
160
  };
143
161
  }
144
162
 
145
- /** Marks a table's elements (wrapper, table, rows, cells): they hold blocks, not content. */
163
+ /**
164
+ * Marks a table's elements (wrapper, table, rows, cells): they hold blocks, not content.
165
+ * @internal
166
+ */
146
167
  export const FRAME_ATTR = "data-foli-frame";
147
- /** Marks a repeated header row: shown, not document content. */
168
+ /**
169
+ * Marks a repeated header row: shown, not document content.
170
+ * @internal
171
+ */
148
172
  export const REPEATED_ATTR = "data-foli-repeated";
149
173
 
150
174
  /**
@@ -152,6 +176,7 @@ export const REPEATED_ATTR = "data-foli-repeated";
152
176
  * header rows drawn again above them, not editable). `content(row, cell)` gives what a cell
153
177
  * shows on this page; a cell a vertical merge covers is drawn by the merge's first cell when
154
178
  * that is on the page (spanning the rows it covers here), else as an empty cell of its own.
179
+ * @internal
155
180
  */
156
181
  export function frameElement(
157
182
  frame: Frame,