@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
package/src/layout/flow.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { DocumentSettings } from "@folijs/core";
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* CSS pixels per millimetre (CSS fixes 1in = 96px = 25.4mm).
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
export const PX_PER_MM = 96 / 25.4;
|
|
5
8
|
|
|
6
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* A rendered block's border-box height and vertical margins, in CSS px.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
7
13
|
export interface BlockBox {
|
|
8
14
|
height: number;
|
|
9
15
|
marginTop: number;
|
|
@@ -48,7 +54,10 @@ export interface BlockBox {
|
|
|
48
54
|
endnotes?: readonly FlowNote[] | undefined;
|
|
49
55
|
}
|
|
50
56
|
|
|
51
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* A note, or a separator, as the flow sees it: lines, split between pages like a block's.
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
52
61
|
export interface FlowNote {
|
|
53
62
|
/** Its story. */
|
|
54
63
|
id: string;
|
|
@@ -56,7 +65,10 @@ export interface FlowNote {
|
|
|
56
65
|
lines(column: number): readonly number[];
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Lines `[fromLine, toLine)` of a note on a page, at the foot or (`end`) after the text.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
60
72
|
export interface NotePiece {
|
|
61
73
|
id: string;
|
|
62
74
|
page: number;
|
|
@@ -71,7 +83,10 @@ export interface NotePiece {
|
|
|
71
83
|
tail?: boolean;
|
|
72
84
|
}
|
|
73
85
|
|
|
74
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* What a page's layout depends on: first page, odd or even, by displayed number.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
75
90
|
export interface FlowPage {
|
|
76
91
|
/** The page's place in the document, from 0. */
|
|
77
92
|
index: number;
|
|
@@ -81,7 +96,10 @@ export interface FlowPage {
|
|
|
81
96
|
first: boolean;
|
|
82
97
|
}
|
|
83
98
|
|
|
84
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* A page as flowed: what decides its header and footer (its first section's).
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
85
103
|
export interface PageFacts extends FlowPage {
|
|
86
104
|
/** The first section on it, by its `index` (a page nothing is on: the next page's). */
|
|
87
105
|
section: number;
|
|
@@ -89,7 +107,10 @@ export interface PageFacts extends FlowPage {
|
|
|
89
107
|
sectionPages: number;
|
|
90
108
|
}
|
|
91
109
|
|
|
92
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* A section as the flow sees it.
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
93
114
|
export interface FlowSection {
|
|
94
115
|
/** Its place among the document's sections, from 0. */
|
|
95
116
|
index?: number;
|
|
@@ -112,6 +133,7 @@ export interface FlowSection {
|
|
|
112
133
|
/**
|
|
113
134
|
* The lines `[fromLine, toLine)` of a block, placed on one page (`toLine` Infinity: to the end).
|
|
114
135
|
* Line numbers are those of the column it is in, when columns' widths differ.
|
|
136
|
+
* @internal
|
|
115
137
|
*/
|
|
116
138
|
export interface Fragment {
|
|
117
139
|
page: number;
|
|
@@ -129,6 +151,7 @@ export interface Fragment {
|
|
|
129
151
|
notes?: NotePiece[];
|
|
130
152
|
}
|
|
131
153
|
|
|
154
|
+
/** @internal */
|
|
132
155
|
export interface FlowRules {
|
|
133
156
|
/** Fewest lines of a split block left at the bottom of a page. */
|
|
134
157
|
orphans: number;
|
|
@@ -153,9 +176,13 @@ export interface FlowRules {
|
|
|
153
176
|
notes?: { separator: FlowNote; continuation: FlowNote } | undefined;
|
|
154
177
|
}
|
|
155
178
|
|
|
179
|
+
/** @internal */
|
|
156
180
|
export const DEFAULT_RULES: FlowRules = { orphans: 2, widows: 2 };
|
|
157
181
|
|
|
158
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Height of a page's content box (page height minus top and bottom margins), in CSS px.
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
159
186
|
export function contentHeight({ pageSize, margins }: DocumentSettings): number {
|
|
160
187
|
return (pageSize.height - margins.top - margins.bottom) * PX_PER_MM;
|
|
161
188
|
}
|
|
@@ -163,7 +190,10 @@ export function contentHeight({ pageSize, margins }: DocumentSettings): number {
|
|
|
163
190
|
// Half a pixel of slack: measured heights are fractional and rounding must not add a page.
|
|
164
191
|
const SLACK = 0.5;
|
|
165
192
|
|
|
166
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* Where the flow stands before a block: shared by a full and an incremental flow.
|
|
195
|
+
* @internal
|
|
196
|
+
*/
|
|
167
197
|
export interface FlowState {
|
|
168
198
|
page: number;
|
|
169
199
|
/** The page's displayed number. */
|
|
@@ -238,6 +268,7 @@ export interface FlowState {
|
|
|
238
268
|
* no top margin.
|
|
239
269
|
*
|
|
240
270
|
* shortcut: positive margins only (negative margins collapse differently).
|
|
271
|
+
* @internal
|
|
241
272
|
*/
|
|
242
273
|
export function flow(
|
|
243
274
|
boxes: readonly BlockBox[],
|
|
@@ -247,7 +278,10 @@ export function flow(
|
|
|
247
278
|
return flowFrom(boxes, pageHeight, rules).fragments;
|
|
248
279
|
}
|
|
249
280
|
|
|
250
|
-
/**
|
|
281
|
+
/**
|
|
282
|
+
* A flow with the state before each block (and after the last), for the next incremental one.
|
|
283
|
+
* @internal
|
|
284
|
+
*/
|
|
251
285
|
export interface FlowResult {
|
|
252
286
|
fragments: Fragment[][];
|
|
253
287
|
states: FlowState[];
|
|
@@ -255,7 +289,10 @@ export interface FlowResult {
|
|
|
255
289
|
gaps: number[];
|
|
256
290
|
}
|
|
257
291
|
|
|
258
|
-
/**
|
|
292
|
+
/**
|
|
293
|
+
* What an incremental flow may reuse from the previous one.
|
|
294
|
+
* @internal
|
|
295
|
+
*/
|
|
259
296
|
export interface Reuse {
|
|
260
297
|
previous: FlowResult;
|
|
261
298
|
/** Blocks before this index are the previous flow's first blocks, with the same boxes. */
|
|
@@ -277,6 +314,7 @@ const slot = (f: Fragment | undefined) =>
|
|
|
277
314
|
* section, whose columns depend on all of it) with the previous state there, and once the state
|
|
278
315
|
* before an unchanged block equals the previous state before it, the rest is the previous flow's.
|
|
279
316
|
* The result is the same as a full flow.
|
|
317
|
+
* @internal
|
|
280
318
|
*/
|
|
281
319
|
export function flowFrom(
|
|
282
320
|
boxes: readonly BlockBox[],
|
|
@@ -1008,6 +1046,7 @@ export function flowFrom(
|
|
|
1008
1046
|
/**
|
|
1009
1047
|
* Each page of a flow: its number, its first section and whether that section starts on it. A page
|
|
1010
1048
|
* nothing is on (the blank page before an even or odd page section) has the next page's section.
|
|
1049
|
+
* @internal
|
|
1011
1050
|
*/
|
|
1012
1051
|
export function pagesOf(boxes: readonly BlockBox[], result: FlowResult): PageFacts[] {
|
|
1013
1052
|
const pages: (PageFacts | undefined)[] = [];
|
|
@@ -1050,6 +1089,7 @@ export function pagesOf(boxes: readonly BlockBox[], result: FlowResult): PageFac
|
|
|
1050
1089
|
* Notes of heights `parts` set in `columns` columns, as Word sets those of a section with columns
|
|
1051
1090
|
* (its PDFs): whole, in order, each column as full as the height the set needs. That height and
|
|
1052
1091
|
* the column of each. One column: their sum.
|
|
1092
|
+
* @internal
|
|
1053
1093
|
*/
|
|
1054
1094
|
export function arrangeNotes(
|
|
1055
1095
|
parts: readonly number[],
|
|
@@ -1092,7 +1132,10 @@ export function arrangeNotes(
|
|
|
1092
1132
|
const notesHeight = (parts: readonly number[], columns: number) =>
|
|
1093
1133
|
arrangeNotes(parts, columns).height;
|
|
1094
1134
|
|
|
1095
|
-
/**
|
|
1135
|
+
/**
|
|
1136
|
+
* The space after the last block of a column of a page, as flowed (what ends its text).
|
|
1137
|
+
* @internal
|
|
1138
|
+
*/
|
|
1096
1139
|
export function spaceAfterText(
|
|
1097
1140
|
boxes: readonly BlockBox[],
|
|
1098
1141
|
result: Pick<FlowResult, "fragments">,
|
|
@@ -1107,7 +1150,10 @@ export function spaceAfterText(
|
|
|
1107
1150
|
return 0;
|
|
1108
1151
|
}
|
|
1109
1152
|
|
|
1110
|
-
/**
|
|
1153
|
+
/**
|
|
1154
|
+
* Every note piece of a flow, in order.
|
|
1155
|
+
* @internal
|
|
1156
|
+
*/
|
|
1111
1157
|
export const notePieces = (result: Pick<FlowResult, "fragments">): NotePiece[] =>
|
|
1112
1158
|
result.fragments.flatMap((fragments) => fragments.flatMap((f) => f.notes ?? []));
|
|
1113
1159
|
|
package/src/print.ts
CHANGED
|
@@ -3,10 +3,16 @@
|
|
|
3
3
|
* that the editor's `print()` and `@folijs/pdf`'s `exportPdf` print pages the same way (11.12).
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* The attribute naming a page's page setup (its index among the document's) for print.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
export const SHEET_ATTR = "data-foli-sheet";
|
|
8
11
|
|
|
9
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* A page setup as print sees it: its sheet's size (CSS lengths) and its `SHEET_ATTR` value.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
10
16
|
export interface PrintSheet {
|
|
11
17
|
readonly width: string;
|
|
12
18
|
readonly height: string;
|
|
@@ -20,6 +26,7 @@ export interface PrintSheet {
|
|
|
20
26
|
* inside it; the exact height absorbs its half-pixel slack), with no gap after it. Content taller
|
|
21
27
|
* than a page (a line taller than a page) is not cut: it prints over the next sheet. `name` makes
|
|
22
28
|
* the named pages unique on the web page.
|
|
29
|
+
* @internal
|
|
23
30
|
*/
|
|
24
31
|
export function printStyles(
|
|
25
32
|
pages: string,
|
package/src/render.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { Node as ModelNode } from "@folijs/core";
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Marks the <br> of an explicit page break.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
4
7
|
export const PAGE_BREAK_ATTR = "data-page-break";
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* A rendered inline leaf (a text node or hard break) and where it sits in its block's content.
|
|
8
11
|
* A text node split across fragments is two leaves, one per fragment.
|
|
12
|
+
* @internal
|
|
9
13
|
*/
|
|
10
14
|
export interface LeafDesc {
|
|
11
15
|
readonly dom: Node;
|
|
@@ -16,6 +20,7 @@ export interface LeafDesc {
|
|
|
16
20
|
/**
|
|
17
21
|
* View descriptor of one block: the model node, its elements and its leaves. A block split
|
|
18
22
|
* across pages has one element per page (its fragments, in order); `dom` is the first.
|
|
23
|
+
* @internal
|
|
19
24
|
*/
|
|
20
25
|
export interface BlockDesc {
|
|
21
26
|
readonly node: ModelNode;
|