@folijs/view 0.6.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.
- package/CHANGELOG.md +161 -0
- package/README.md +1 -1
- package/dist/clipboard.d.ts +1 -51
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +65 -13
- package/dist/clipboard.js.map +1 -1
- package/dist/extension.d.ts +90 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +152 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/layout/flow.d.ts +1 -282
- package/dist/layout/flow.d.ts.map +1 -1
- package/dist/layout/flow.js +21 -4
- package/dist/layout/flow.js.map +1 -1
- package/dist/print.d.ts +1 -17
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +5 -1
- package/dist/print.js.map +1 -1
- package/dist/render.d.ts +1 -24
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +4 -1
- package/dist/render.js.map +1 -1
- package/dist/view.d.ts +34 -67
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +209 -24
- package/dist/view.js.map +1 -1
- package/dist/word/blocks.d.ts +0 -175
- package/dist/word/blocks.d.ts.map +1 -1
- package/dist/word/blocks.js +106 -24
- package/dist/word/blocks.js.map +1 -1
- package/dist/word/columns.d.ts +1 -22
- package/dist/word/columns.d.ts.map +1 -1
- package/dist/word/columns.js +15 -3
- package/dist/word/columns.js.map +1 -1
- package/dist/word/controls.d.ts +1 -62
- package/dist/word/controls.d.ts.map +1 -1
- package/dist/word/controls.js +6 -1
- package/dist/word/controls.js.map +1 -1
- package/dist/word/edit.d.ts +1 -83
- package/dist/word/edit.d.ts.map +1 -1
- package/dist/word/edit.js +183 -5
- package/dist/word/edit.js.map +1 -1
- package/dist/word/matches.d.ts +1 -22
- package/dist/word/matches.d.ts.map +1 -1
- package/dist/word/matches.js +6 -1
- package/dist/word/matches.js.map +1 -1
- package/dist/word/notes.d.ts +0 -103
- package/dist/word/notes.d.ts.map +1 -1
- package/dist/word/notes.js +15 -4
- package/dist/word/notes.js.map +1 -1
- package/dist/word/pages.d.ts +15 -10
- package/dist/word/pages.d.ts.map +1 -1
- package/dist/word/pages.js +3 -2
- package/dist/word/pages.js.map +1 -1
- package/dist/word/regions.d.ts +0 -111
- package/dist/word/regions.d.ts.map +1 -1
- package/dist/word/regions.js +19 -5
- package/dist/word/regions.js.map +1 -1
- package/dist/word/table.d.ts +1 -78
- package/dist/word/table.d.ts.map +1 -1
- package/dist/word/table.js +13 -3
- package/dist/word/table.js.map +1 -1
- package/package.json +6 -3
- package/src/clipboard.ts +91 -21
- package/src/extension.ts +267 -0
- package/src/index.ts +10 -0
- package/src/layout/flow.ts +59 -13
- package/src/print.ts +9 -2
- package/src/render.ts +6 -1
- package/src/view.ts +245 -40
- package/src/word/blocks.ts +124 -30
- package/src/word/columns.ts +19 -4
- package/src/word/controls.ts +13 -3
- package/src/word/edit.ts +207 -9
- package/src/word/matches.ts +6 -1
- package/src/word/notes.ts +19 -6
- package/src/word/pages.ts +19 -3
- package/src/word/regions.ts +27 -8
- package/src/word/table.ts +33 -8
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The view's side of extensions (ADR-0008, 12.4): node views draw custom nodes, mark views style
|
|
3
|
+
* runs of custom marks, decorations put classes and attributes on drawn ranges, and plugin views
|
|
4
|
+
* live as long as the `EditorView`. Core has no DOM: these hooks are on `ViewExtension`, which an
|
|
5
|
+
* app gives to `createEditor` as an ordinary extension; the view reads them from
|
|
6
|
+
* `editor.extensions`.
|
|
7
|
+
*
|
|
8
|
+
* Everything here is drawn with DOM calls, never parsed from HTML: attribute names are checked
|
|
9
|
+
* (no `on*` handlers, no `contenteditable`, none of the view's own `data-foli-*`), and URL
|
|
10
|
+
* attributes must be safe links (`isSafeHref`).
|
|
11
|
+
*/
|
|
12
|
+
import { isSafeHref, } from "@folijs/core";
|
|
13
|
+
/** @internal */
|
|
14
|
+
export function viewsOf(extensions) {
|
|
15
|
+
return {
|
|
16
|
+
nodes: new Map(extensions.flatMap((e) => Object.entries(e.nodeViews ?? {}))),
|
|
17
|
+
marks: new Map(extensions.flatMap((e) => Object.entries(e.markViews ?? {}))),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const NAME = /^[a-z_][\w.:-]*$/i;
|
|
21
|
+
const URL_ATTRS = new Set([
|
|
22
|
+
"href",
|
|
23
|
+
"src",
|
|
24
|
+
"xlink:href",
|
|
25
|
+
"action",
|
|
26
|
+
"formaction",
|
|
27
|
+
"poster",
|
|
28
|
+
"background",
|
|
29
|
+
]);
|
|
30
|
+
/** Attributes holding several URLs: `srcset` (comma separated, each before its size), `ping`. */
|
|
31
|
+
const URL_LISTS = {
|
|
32
|
+
srcset: (value) => value.split(",").map((part) => part.trim().split(/\s+/)[0] ?? ""),
|
|
33
|
+
ping: (value) => value.split(/\s+/).filter(Boolean),
|
|
34
|
+
};
|
|
35
|
+
/** Style that fetches or runs something (escapes could spell it otherwise). */
|
|
36
|
+
const UNSAFE_STYLE = /url\s*\(|image-set|expression|@import|-moz-binding|behavior|\\/i;
|
|
37
|
+
/** Content elements a node view may make with `h` (no scripts, styles, forms, frames, `base`). */
|
|
38
|
+
const TAGS = new Set(("a abbr address article aside audio b bdi bdo blockquote br button canvas caption cite code " +
|
|
39
|
+
"col colgroup data dd del details dfn div dl dt em figcaption figure footer h1 h2 h3 h4 h5 h6 " +
|
|
40
|
+
"header hgroup hr i img ins kbd label li mark meter ol p picture pre progress q rp rt ruby s " +
|
|
41
|
+
"samp section small source span strong sub summary sup table tbody td tfoot th thead time tr " +
|
|
42
|
+
"track u ul var video wbr").split(" "));
|
|
43
|
+
/** Throws on an attribute a view must not set: handlers, editing, the view's own, unsafe URLs. */
|
|
44
|
+
function check(name, value) {
|
|
45
|
+
const lower = name.toLowerCase();
|
|
46
|
+
if (!NAME.test(name) ||
|
|
47
|
+
lower.startsWith("on") ||
|
|
48
|
+
lower === "contenteditable" ||
|
|
49
|
+
lower === "srcdoc" ||
|
|
50
|
+
lower.startsWith("data-foli-") ||
|
|
51
|
+
(URL_ATTRS.has(lower) && !isSafeHref(value)) ||
|
|
52
|
+
URL_LISTS[lower]?.(value).some((url) => !isSafeHref(url)) ||
|
|
53
|
+
(lower === "style" && UNSAFE_STYLE.test(value)) ||
|
|
54
|
+
(lower === "class" && /(^|\s)foli-/.test(value)))
|
|
55
|
+
throw new TypeError(`Foli: attribute ${name} is not allowed on drawn content`);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Throws when `attrs` holds one an extension must not set (`check`).
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export function checkAttrs(attrs) {
|
|
62
|
+
for (const [name, value] of Object.entries(attrs))
|
|
63
|
+
if (value !== undefined)
|
|
64
|
+
check(name, value);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Puts `attrs` on `element` (classes and style added, the rest set).
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export function applyAttrs(element, attrs) {
|
|
71
|
+
checkAttrs(attrs);
|
|
72
|
+
for (const [name, value] of Object.entries(attrs)) {
|
|
73
|
+
if (value === undefined)
|
|
74
|
+
continue;
|
|
75
|
+
if (name === "class")
|
|
76
|
+
element.classList.add(...value.split(/\s+/).filter(Boolean));
|
|
77
|
+
else if (name === "style") {
|
|
78
|
+
const style = element.getAttribute("style")?.trim() ?? "";
|
|
79
|
+
element.setAttribute("style", style && !style.endsWith(";") ? `${style};${value}` : style + value);
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
element.setAttribute(name, value);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Reports an extension's failure without stopping the editor.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export function reportError(error) {
|
|
90
|
+
console.error("Foli: an extension failed", error);
|
|
91
|
+
}
|
|
92
|
+
/** The DOM API node views draw with. @internal */
|
|
93
|
+
export function nodeViewDOM(document) {
|
|
94
|
+
return {
|
|
95
|
+
document,
|
|
96
|
+
h(tag, attrs, ...children) {
|
|
97
|
+
if (!TAGS.has(tag.toLowerCase()))
|
|
98
|
+
throw new TypeError(`Foli: element ${tag} is not allowed in a node view`);
|
|
99
|
+
const element = document.createElement(tag);
|
|
100
|
+
if (attrs)
|
|
101
|
+
applyAttrs(element, attrs);
|
|
102
|
+
element.append(...children);
|
|
103
|
+
return element;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The decorations of each block (`units`: the blocks drawn, in document order, with the position
|
|
109
|
+
* before each), relative to its content's start: a node decoration on the block itself is at -1.
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export function decorationsByBlock(units, decorations) {
|
|
113
|
+
const out = [];
|
|
114
|
+
const add = (i, d) => {
|
|
115
|
+
const list = out[i] ?? [];
|
|
116
|
+
out[i] = list;
|
|
117
|
+
list.push(d);
|
|
118
|
+
};
|
|
119
|
+
for (const decoration of decorations) {
|
|
120
|
+
const { from, to } = decoration;
|
|
121
|
+
if (!(from <= to) || (!decoration.node && from === to))
|
|
122
|
+
continue;
|
|
123
|
+
// The first block ending after `from` (blocks do not overlap: their ends are sorted too).
|
|
124
|
+
let low = 0;
|
|
125
|
+
let high = units.length;
|
|
126
|
+
while (low < high) {
|
|
127
|
+
const mid = (low + high) >> 1;
|
|
128
|
+
const unit = units[mid];
|
|
129
|
+
if (unit.pos + unit.node.nodeSize <= from)
|
|
130
|
+
low = mid + 1;
|
|
131
|
+
else
|
|
132
|
+
high = mid;
|
|
133
|
+
}
|
|
134
|
+
for (let i = low; i < units.length; i++) {
|
|
135
|
+
const { pos, node } = units[i];
|
|
136
|
+
const start = pos + 1;
|
|
137
|
+
if (decoration.node) {
|
|
138
|
+
if (from >= pos && from < pos + node.nodeSize)
|
|
139
|
+
add(i, { ...decoration, from: from - start, to: to - start });
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (pos >= to)
|
|
143
|
+
break;
|
|
144
|
+
const end = pos + node.nodeSize - 1;
|
|
145
|
+
// A block leaf has no text to decorate.
|
|
146
|
+
if (!node.isLeaf && from < end && to > start)
|
|
147
|
+
add(i, { ...decoration, from: from - start, to: to - start });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAGL,UAAU,GAGX,MAAM,cAAc,CAAC;AAuGtB,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAC,UAAoC;IAC1D,OAAO;QACL,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;QAC5E,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;KAC7E,CAAC;AACJ,CAAC;AAED,MAAM,IAAI,GAAG,mBAAmB,CAAC;AACjC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,MAAM;IACN,KAAK;IACL,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,YAAY;CACb,CAAC,CAAC;AACH,iGAAiG;AACjG,MAAM,SAAS,GAAgD;IAC7D,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC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ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { FOLI_MIME, htmlToDoc, textToDoc } from "./clipboard.js";
|
|
2
|
+
export type { Decoration, DecorationAttrs, MarkView, NodeView, NodeViewDOM, PluginView, ViewExtension, } from "./extension.js";
|
|
2
3
|
export { EditorView, type EditorViewOptions, keyName, measureImageFile, textWidthEmu, } from "./view.js";
|
|
3
4
|
export { EMU_PER_PX } from "./word/blocks.js";
|
|
4
|
-
export { type DocumentPages, type ReviewView, renderDocument, WORD_PAGE_CLASS, } from "./word/pages.js";
|
|
5
|
+
export { type DocumentPages, type RenderDocumentOptions, type ReviewView, renderDocument, WORD_PAGE_CLASS, } from "./word/pages.js";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,OAAO,EACP,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjE,YAAY,EACV,UAAU,EACV,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,OAAO,EACP,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAUjE,OAAO,EACL,UAAU,EAEV,OAAO,EACP,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAIL,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
|
package/dist/layout/flow.d.ts
CHANGED
|
@@ -1,283 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/** CSS pixels per millimetre (CSS fixes 1in = 96px = 25.4mm). */
|
|
3
|
-
export declare const PX_PER_MM: number;
|
|
4
|
-
/** A rendered block's border-box height and vertical margins, in CSS px. */
|
|
5
|
-
export interface BlockBox {
|
|
6
|
-
height: number;
|
|
7
|
-
marginTop: number;
|
|
8
|
-
marginBottom: number;
|
|
9
|
-
/**
|
|
10
|
-
* The bottom of each line box, from the block's top (the last one is `height`). Only called
|
|
11
|
-
* for a block that does not fit where it is, or has page breaks, since measuring lines is
|
|
12
|
-
* expensive.
|
|
13
|
-
*/
|
|
14
|
-
lines(): readonly number[];
|
|
15
|
-
/** Keep on the same page as the start of the next block (headings). */
|
|
16
|
-
keepWithNext?: boolean;
|
|
17
|
-
/** The lines that end with an explicit page break (indices into `lines()`), if any. */
|
|
18
|
-
breaksAfter?(column?: number): readonly number[];
|
|
19
|
-
/** Height shown again at the top of each fragment after the first (a table's header rows). */
|
|
20
|
-
repeat?: number;
|
|
21
|
-
/** Splits at any of its line ends, without widow and orphan control (a table's rows). */
|
|
22
|
-
anyLine?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* The lines that end with an explicit column break, if any: indices into the lines of column
|
|
25
|
-
* `column` (`inColumn`), as for `breaksAfter`.
|
|
26
|
-
*/
|
|
27
|
-
columnBreaksAfter?(column?: number): readonly number[];
|
|
28
|
-
/**
|
|
29
|
-
* Content height of the pages this block goes on, when not the flow's. A block with another
|
|
30
|
-
* page height than the one before it must start a page (an explicit break before it).
|
|
31
|
-
* `section`, when given, says it instead.
|
|
32
|
-
*/
|
|
33
|
-
pageHeight?: number;
|
|
34
|
-
/** The section it is in: its blocks are consecutive and share this object. */
|
|
35
|
-
section?: FlowSection;
|
|
36
|
-
/**
|
|
37
|
-
* An empty paragraph that only holds a section's break: Word gives it no room after text
|
|
38
|
-
* (not its line, not its spacing). Alone at the top of a column it is an ordinary line.
|
|
39
|
-
*/
|
|
40
|
-
sectionMark?: boolean;
|
|
41
|
-
/** Its height and lines in column `column` of its section, when the columns' widths differ. */
|
|
42
|
-
inColumn?: ((column: number) => Pick<BlockBox, "height" | "lines">) | undefined;
|
|
43
|
-
/** The footnotes referred to, with the line (of `column`'s lines) holding each reference. */
|
|
44
|
-
notes?: ((column: number) => readonly {
|
|
45
|
-
line: number;
|
|
46
|
-
note: FlowNote;
|
|
47
|
-
}[]) | undefined;
|
|
48
|
-
/** What follows this block in the text: the endnotes ending its section or the document. */
|
|
49
|
-
endnotes?: readonly FlowNote[] | undefined;
|
|
50
|
-
}
|
|
51
|
-
/** A note, or a separator, as the flow sees it: lines, split between pages like a block's. */
|
|
52
|
-
export interface FlowNote {
|
|
53
|
-
/** Its story. */
|
|
54
|
-
id: string;
|
|
55
|
-
/** The bottom of each of its lines from its top, in column `column`'s width. */
|
|
56
|
-
lines(column: number): readonly number[];
|
|
57
|
-
}
|
|
58
|
-
/** Lines `[fromLine, toLine)` of a note on a page, at the foot or (`end`) after the text. */
|
|
59
|
-
export interface NotePiece {
|
|
60
|
-
id: string;
|
|
61
|
-
page: number;
|
|
62
|
-
band?: number;
|
|
63
|
-
column?: number;
|
|
64
|
-
fromLine: number;
|
|
65
|
-
toLine: number;
|
|
66
|
-
/** An endnote, in the text's flow: the space above it when it starts there. */
|
|
67
|
-
end?: boolean;
|
|
68
|
-
lead?: number;
|
|
69
|
-
/** On a page after the last block's, for what was still to come. */
|
|
70
|
-
tail?: boolean;
|
|
71
|
-
}
|
|
72
|
-
/** What a page's layout depends on: first page, odd or even, by displayed number. */
|
|
73
|
-
export interface FlowPage {
|
|
74
|
-
/** The page's place in the document, from 0. */
|
|
75
|
-
index: number;
|
|
76
|
-
/** Its displayed number (`w:pgNumType` restarts count). */
|
|
77
|
-
number: number;
|
|
78
|
-
/** Whether its section starts on it. */
|
|
79
|
-
first: boolean;
|
|
80
|
-
}
|
|
81
|
-
/** A page as flowed: what decides its header and footer (its first section's). */
|
|
82
|
-
export interface PageFacts extends FlowPage {
|
|
83
|
-
/** The first section on it, by its `index` (a page nothing is on: the next page's). */
|
|
84
|
-
section: number;
|
|
85
|
-
/** How many pages that section has text on; 0 for a page nothing is on. */
|
|
86
|
-
sectionPages: number;
|
|
87
|
-
}
|
|
88
|
-
/** A section as the flow sees it. */
|
|
89
|
-
export interface FlowSection {
|
|
90
|
-
/** Its place among the document's sections, from 0. */
|
|
91
|
-
index?: number;
|
|
92
|
-
/** How it starts (Word's `w:type`). */
|
|
93
|
-
start: "nextPage" | "continuous" | "evenPage" | "oddPage" | "nextColumn";
|
|
94
|
-
columns: number;
|
|
95
|
-
/** A continuous section follows: its columns end level on its last page. */
|
|
96
|
-
balanced?: boolean;
|
|
97
|
-
/** The displayed number of its first page, when it restarts them. */
|
|
98
|
-
pageStart?: number | undefined;
|
|
99
|
-
/**
|
|
100
|
-
* The content box of a page that starts with this section. A section continuing on another's
|
|
101
|
-
* page has that page's box, less what is above its band.
|
|
102
|
-
*/
|
|
103
|
-
box(page: FlowPage): {
|
|
104
|
-
height: number;
|
|
105
|
-
};
|
|
106
|
-
/** Whether a page of this section is a page of `other` (a continuous one can share it). */
|
|
107
|
-
samePage(other: FlowSection): boolean;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* The lines `[fromLine, toLine)` of a block, placed on one page (`toLine` Infinity: to the end).
|
|
111
|
-
* Line numbers are those of the column it is in, when columns' widths differ.
|
|
112
|
-
*/
|
|
113
|
-
export interface Fragment {
|
|
114
|
-
page: number;
|
|
115
|
-
fromLine: number;
|
|
116
|
-
toLine: number;
|
|
117
|
-
/** Its band on the page (one per section on it), when not the first. */
|
|
118
|
-
band?: number;
|
|
119
|
-
/** Its column in the band, when not the first. */
|
|
120
|
-
column?: number;
|
|
121
|
-
/** The first fragment of a band after the first: the space between the two bands. */
|
|
122
|
-
lead?: number;
|
|
123
|
-
/** A `sectionMark` block given no room. */
|
|
124
|
-
mark?: boolean;
|
|
125
|
-
/** The notes this fragment brought onto their pages: those it refers to, what was carried. */
|
|
126
|
-
notes?: NotePiece[];
|
|
127
|
-
}
|
|
128
|
-
export interface FlowRules {
|
|
129
|
-
/** Fewest lines of a split block left at the bottom of a page. */
|
|
130
|
-
orphans: number;
|
|
131
|
-
/** Fewest lines of a split block carried to the top of the next page. */
|
|
132
|
-
widows: number;
|
|
133
|
-
/**
|
|
134
|
-
* How margins (paragraph spacing) combine. `css` (the default): as CSS in a padded page.
|
|
135
|
-
* `word`: as Word spaces paragraphs: the larger of the space after one and the space before
|
|
136
|
-
* the next (Word's PDFs of the corpus). A page or column that a block flowed onto (not one an
|
|
137
|
-
* explicit break started, nor the first) drops the space before its first block. The space
|
|
138
|
-
* after the last block on a page need not fit.
|
|
139
|
-
*/
|
|
140
|
-
spacing?: "css" | "word";
|
|
141
|
-
/**
|
|
142
|
-
* With `word` spacing: the two spaces add up instead (a document with Word's
|
|
143
|
-
* `w:doNotUseHTMLParagraphAutoSpacing`, in every compatibility mode).
|
|
144
|
-
*/
|
|
145
|
-
addSpacing?: boolean;
|
|
146
|
-
/** The document has even and odd headers: a section restarting its numbers still keeps sides. */
|
|
147
|
-
evenAndOddHeaders?: boolean;
|
|
148
|
-
/** What goes above footnotes: on a page they start on, and on one they continue on. */
|
|
149
|
-
notes?: {
|
|
150
|
-
separator: FlowNote;
|
|
151
|
-
continuation: FlowNote;
|
|
152
|
-
} | undefined;
|
|
153
|
-
}
|
|
154
|
-
export declare const DEFAULT_RULES: FlowRules;
|
|
155
|
-
/** Height of a page's content box (page height minus top and bottom margins), in CSS px. */
|
|
156
|
-
export declare function contentHeight({ pageSize, margins }: DocumentSettings): number;
|
|
157
|
-
/** Where the flow stands before a block: shared by a full and an incremental flow. */
|
|
158
|
-
export interface FlowState {
|
|
159
|
-
page: number;
|
|
160
|
-
/** The page's displayed number. */
|
|
161
|
-
number: number;
|
|
162
|
-
/** The page the current section started on. */
|
|
163
|
-
sectionPage: number;
|
|
164
|
-
band: number;
|
|
165
|
-
/** Where the band starts on its page, the space above it included. */
|
|
166
|
-
bandTop: number;
|
|
167
|
-
/** The space above the band: its first block's space before counts from there. */
|
|
168
|
-
lead: number;
|
|
169
|
-
column: number;
|
|
170
|
-
/** The height used in the column, from the band's top. */
|
|
171
|
-
used: number;
|
|
172
|
-
/** The tallest of the band's earlier columns. */
|
|
173
|
-
bandBottom: number;
|
|
174
|
-
previousMargin: number;
|
|
175
|
-
/** Blocks in the column. */
|
|
176
|
-
onPage: number;
|
|
177
|
-
/** An explicit page break ended the previous block: the next one starts a new page. */
|
|
178
|
-
breakPending: boolean;
|
|
179
|
-
/** An explicit column break ended it: the next one starts a new column. */
|
|
180
|
-
columnPending: boolean;
|
|
181
|
-
/** The column is the first or an explicit break started it (Word keeps its first space before). */
|
|
182
|
-
forcedPage: boolean;
|
|
183
|
-
/** On a page shared by sections: the first of them, which gives the page its box. */
|
|
184
|
-
owner: {
|
|
185
|
-
section: FlowSection;
|
|
186
|
-
first: boolean;
|
|
187
|
-
} | null;
|
|
188
|
-
/** The height footnotes take at the foot of the band, their separator included. */
|
|
189
|
-
notes: number;
|
|
190
|
-
/** The height of each of those notes. */
|
|
191
|
-
noteParts: readonly number[];
|
|
192
|
-
/** What the notes of the page's earlier bands take. */
|
|
193
|
-
pageNotes: number;
|
|
194
|
-
/** Footnotes still to be placed, from the line each has got to. */
|
|
195
|
-
carry: readonly {
|
|
196
|
-
note: FlowNote;
|
|
197
|
-
from: number;
|
|
198
|
-
}[];
|
|
199
|
-
/** Room kept at the foot of a band (by page and band) for notes its later columns refer to. */
|
|
200
|
-
reserves: Readonly<Record<string, number>>;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Page flow: the fragments of each block, in order. Blocks fill a page's columns in order; a
|
|
204
|
-
* block that does not fit is split at a line boundary, the lines that fit staying in the column,
|
|
205
|
-
* the rest continuing at the top of the next column or page (as many as it takes). A column with
|
|
206
|
-
* room for no line of the next block ends; an empty one always takes at least one line.
|
|
207
|
-
*
|
|
208
|
-
* Rules:
|
|
209
|
-
* - Explicit breaks: the line holding a page break ends its page, a column break its column.
|
|
210
|
-
* - Widows and orphans: a split leaves at least `orphans` lines at the bottom of a page and
|
|
211
|
-
* carries at least `widows` lines to the next; a block too short for both moves whole. Not
|
|
212
|
-
* applied where only an empty page could hold the lines, nor across an explicit break.
|
|
213
|
-
* - Keep with next: a `keepWithNext` block (and a chain of them) moves to the next column or page
|
|
214
|
-
* when the block after it would start there, unless it already starts its column or the move
|
|
215
|
-
* would not bring them together (then the flow stays as it was).
|
|
216
|
-
* - Sections (`BlockBox.section`): a new one starts as its `start` says, an even or odd page
|
|
217
|
-
* section after a blank page when the page's number asks for one. A continuous one with the
|
|
218
|
-
* same page opens a band below the last; each band has its section's columns. A band of a
|
|
219
|
-
* `balanced` section ends with its columns level: its last page's columns take the shortest
|
|
220
|
-
* height that holds them.
|
|
221
|
-
*
|
|
222
|
-
* - Footnotes (ADR-0007, on Word's PDFs): a line with a reference goes on a page only if it, the
|
|
223
|
-
* separator and the note's first line fit. The note then takes the room down to the text, up to
|
|
224
|
-
* all of it, so a long one fills the page; the rest is carried to the foot of the next page,
|
|
225
|
-
* under the continuation separator, before any text is placed there, as much as fits. Lines a widow, orphan or keep rule takes back take their notes with them. In a
|
|
226
|
-
* section with columns the notes are set in those columns across the foot of the band, whichever
|
|
227
|
-
* column refers to them, and every column's text ends above them.
|
|
228
|
-
* - Endnotes (`BlockBox.endnotes`) follow their block in the text, over as many pages as they need.
|
|
229
|
-
*
|
|
230
|
-
* Spacing follows CSS inside a padded page: the first block keeps its top margin, adjacent
|
|
231
|
-
* margins collapse to the larger, and the last block's bottom margin stays inside the page
|
|
232
|
-
* (it does not collapse into the padding), so it must fit too. Fragments are rendered without
|
|
233
|
-
* the margins at their split edges: a continued fragment has no bottom margin, a continuation
|
|
234
|
-
* no top margin.
|
|
235
|
-
*
|
|
236
|
-
* shortcut: positive margins only (negative margins collapse differently).
|
|
237
|
-
*/
|
|
238
|
-
export declare function flow(boxes: readonly BlockBox[], pageHeight: number, rules?: FlowRules): Fragment[][];
|
|
239
|
-
/** A flow with the state before each block (and after the last), for the next incremental one. */
|
|
240
|
-
export interface FlowResult {
|
|
241
|
-
fragments: Fragment[][];
|
|
242
|
-
states: FlowState[];
|
|
243
|
-
/** The space above each block's first fragment (what the renderers write as its margin). */
|
|
244
|
-
gaps: number[];
|
|
245
|
-
}
|
|
246
|
-
/** What an incremental flow may reuse from the previous one. */
|
|
247
|
-
export interface Reuse {
|
|
248
|
-
previous: FlowResult;
|
|
249
|
-
/** Blocks before this index are the previous flow's first blocks, with the same boxes. */
|
|
250
|
-
from: number;
|
|
251
|
-
/**
|
|
252
|
-
* The previous index of block `i` when it and every block after it are unchanged from the
|
|
253
|
-
* previous flow (the common tail of an edit), else -1.
|
|
254
|
-
*/
|
|
255
|
-
previousIndex(i: number): number;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* `flow`, reusing a previous one: it starts at `reuse.from` (backed up over a chain of
|
|
259
|
-
* keep-with-next blocks, whose placement depends on what follows, and to the start of a balanced
|
|
260
|
-
* section, whose columns depend on all of it) with the previous state there, and once the state
|
|
261
|
-
* before an unchanged block equals the previous state before it, the rest is the previous flow's.
|
|
262
|
-
* The result is the same as a full flow.
|
|
263
|
-
*/
|
|
264
|
-
export declare function flowFrom(boxes: readonly BlockBox[], flowHeight: number, rules?: FlowRules, reuse?: Reuse): FlowResult;
|
|
265
|
-
/**
|
|
266
|
-
* Each page of a flow: its number, its first section and whether that section starts on it. A page
|
|
267
|
-
* nothing is on (the blank page before an even or odd page section) has the next page's section.
|
|
268
|
-
*/
|
|
269
|
-
export declare function pagesOf(boxes: readonly BlockBox[], result: FlowResult): PageFacts[];
|
|
270
|
-
/**
|
|
271
|
-
* Notes of heights `parts` set in `columns` columns, as Word sets those of a section with columns
|
|
272
|
-
* (its PDFs): whole, in order, each column as full as the height the set needs. That height and
|
|
273
|
-
* the column of each. One column: their sum.
|
|
274
|
-
*/
|
|
275
|
-
export declare function arrangeNotes(parts: readonly number[], columns: number): {
|
|
276
|
-
height: number;
|
|
277
|
-
columnOf: number[];
|
|
278
|
-
};
|
|
279
|
-
/** The space after the last block of a column of a page, as flowed (what ends its text). */
|
|
280
|
-
export declare function spaceAfterText(boxes: readonly BlockBox[], result: Pick<FlowResult, "fragments">, page: number, band: number, column: number): number;
|
|
281
|
-
/** Every note piece of a flow, in order. */
|
|
282
|
-
export declare const notePieces: (result: Pick<FlowResult, "fragments">) => NotePiece[];
|
|
1
|
+
export {};
|
|
283
2
|
//# sourceMappingURL=flow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/layout/flow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/layout/flow.ts"],"names":[],"mappings":""}
|
package/dist/layout/flow.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* CSS pixels per millimetre (CSS fixes 1in = 96px = 25.4mm).
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
2
5
|
export const PX_PER_MM = 96 / 25.4;
|
|
6
|
+
/** @internal */
|
|
3
7
|
export const DEFAULT_RULES = { orphans: 2, widows: 2 };
|
|
4
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Height of a page's content box (page height minus top and bottom margins), in CSS px.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
5
12
|
export function contentHeight({ pageSize, margins }) {
|
|
6
13
|
return (pageSize.height - margins.top - margins.bottom) * PX_PER_MM;
|
|
7
14
|
}
|
|
@@ -42,6 +49,7 @@ const SLACK = 0.5;
|
|
|
42
49
|
* no top margin.
|
|
43
50
|
*
|
|
44
51
|
* shortcut: positive margins only (negative margins collapse differently).
|
|
52
|
+
* @internal
|
|
45
53
|
*/
|
|
46
54
|
export function flow(boxes, pageHeight, rules = DEFAULT_RULES) {
|
|
47
55
|
return flowFrom(boxes, pageHeight, rules).fragments;
|
|
@@ -54,6 +62,7 @@ const slot = (f) => f ? f.page * 1_000_000 + (f.band ?? 0) * 1000 + (f.column ??
|
|
|
54
62
|
* section, whose columns depend on all of it) with the previous state there, and once the state
|
|
55
63
|
* before an unchanged block equals the previous state before it, the rest is the previous flow's.
|
|
56
64
|
* The result is the same as a full flow.
|
|
65
|
+
* @internal
|
|
57
66
|
*/
|
|
58
67
|
export function flowFrom(boxes, flowHeight, rules = DEFAULT_RULES, reuse) {
|
|
59
68
|
let start = reuse ? Math.min(reuse.from, boxes.length, reuse.previous.fragments.length) : 0;
|
|
@@ -778,6 +787,7 @@ export function flowFrom(boxes, flowHeight, rules = DEFAULT_RULES, reuse) {
|
|
|
778
787
|
/**
|
|
779
788
|
* Each page of a flow: its number, its first section and whether that section starts on it. A page
|
|
780
789
|
* nothing is on (the blank page before an even or odd page section) has the next page's section.
|
|
790
|
+
* @internal
|
|
781
791
|
*/
|
|
782
792
|
export function pagesOf(boxes, result) {
|
|
783
793
|
const pages = [];
|
|
@@ -820,6 +830,7 @@ export function pagesOf(boxes, result) {
|
|
|
820
830
|
* Notes of heights `parts` set in `columns` columns, as Word sets those of a section with columns
|
|
821
831
|
* (its PDFs): whole, in order, each column as full as the height the set needs. That height and
|
|
822
832
|
* the column of each. One column: their sum.
|
|
833
|
+
* @internal
|
|
823
834
|
*/
|
|
824
835
|
export function arrangeNotes(parts, columns) {
|
|
825
836
|
const total = parts.reduce((sum, part) => sum + part, 0);
|
|
@@ -860,7 +871,10 @@ export function arrangeNotes(parts, columns) {
|
|
|
860
871
|
return best;
|
|
861
872
|
}
|
|
862
873
|
const notesHeight = (parts, columns) => arrangeNotes(parts, columns).height;
|
|
863
|
-
/**
|
|
874
|
+
/**
|
|
875
|
+
* The space after the last block of a column of a page, as flowed (what ends its text).
|
|
876
|
+
* @internal
|
|
877
|
+
*/
|
|
864
878
|
export function spaceAfterText(boxes, result, page, band, column) {
|
|
865
879
|
for (let i = result.fragments.length - 1; i >= 0; i--)
|
|
866
880
|
for (const f of result.fragments[i] ?? [])
|
|
@@ -868,7 +882,10 @@ export function spaceAfterText(boxes, result, page, band, column) {
|
|
|
868
882
|
return boxes[i]?.marginBottom ?? 0;
|
|
869
883
|
return 0;
|
|
870
884
|
}
|
|
871
|
-
/**
|
|
885
|
+
/**
|
|
886
|
+
* Every note piece of a flow, in order.
|
|
887
|
+
* @internal
|
|
888
|
+
*/
|
|
872
889
|
export const notePieces = (result) => result.fragments.flatMap((fragments) => fragments.flatMap((f) => f.notes ?? []));
|
|
873
890
|
function sameState(a, b) {
|
|
874
891
|
return (a.notes === b.notes &&
|