@folijs/view 0.2.0 → 0.4.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 +55 -0
- package/README.md +4 -3
- package/dist/clipboard.d.ts +28 -9
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +53 -25
- package/dist/clipboard.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/layout/flow.d.ts +18 -1
- package/dist/layout/flow.d.ts.map +1 -1
- package/dist/layout/flow.js +20 -11
- package/dist/layout/flow.js.map +1 -1
- package/dist/render.d.ts +0 -20
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +0 -163
- package/dist/render.js.map +1 -1
- package/dist/view.d.ts +39 -16
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +380 -278
- package/dist/view.js.map +1 -1
- package/dist/word/blocks.d.ts +84 -0
- package/dist/word/blocks.d.ts.map +1 -0
- package/dist/word/blocks.js +756 -0
- package/dist/word/blocks.js.map +1 -0
- package/dist/word/edit.d.ts +63 -0
- package/dist/word/edit.d.ts.map +1 -0
- package/dist/word/edit.js +318 -0
- package/dist/word/edit.js.map +1 -0
- package/dist/word/pages.d.ts +45 -0
- package/dist/word/pages.d.ts.map +1 -0
- package/dist/word/pages.js +335 -0
- package/dist/word/pages.js.map +1 -0
- package/package.json +2 -2
- package/src/clipboard.ts +75 -25
- package/src/index.ts +6 -0
- package/src/layout/flow.ts +36 -13
- package/src/render.ts +1 -171
- package/src/view.ts +438 -286
- package/src/word/blocks.ts +826 -0
- package/src/word/edit.ts +387 -0
- package/src/word/pages.ts +372 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { flow } from "../layout/flow.js";
|
|
2
|
+
import { PX_PER_TWIP, renderBlocks, WORD_PAGE_BREAK_ATTR, } from "./blocks.js";
|
|
3
|
+
/** The class of each page element. */
|
|
4
|
+
export const WORD_PAGE_CLASS = "foli-word-page";
|
|
5
|
+
/** Word's defaults for what a section leaves out: Letter, 1 inch margins. */
|
|
6
|
+
const PAGE_DEFAULTS = { width: 12240, height: 15840, margin: 1440 };
|
|
7
|
+
function geometry(section) {
|
|
8
|
+
const m = section.margins ?? {};
|
|
9
|
+
// A negative top or bottom margin is measured the same way in Word (text may overlap headers).
|
|
10
|
+
return {
|
|
11
|
+
width: (section.pageSize?.width ?? PAGE_DEFAULTS.width) * PX_PER_TWIP,
|
|
12
|
+
height: (section.pageSize?.height ?? PAGE_DEFAULTS.height) * PX_PER_TWIP,
|
|
13
|
+
top: Math.abs(m.top ?? PAGE_DEFAULTS.margin) * PX_PER_TWIP,
|
|
14
|
+
right: (m.right ?? PAGE_DEFAULTS.margin) * PX_PER_TWIP,
|
|
15
|
+
bottom: Math.abs(m.bottom ?? PAGE_DEFAULTS.margin) * PX_PER_TWIP,
|
|
16
|
+
left: ((m.left ?? PAGE_DEFAULTS.margin) + (m.gutter ?? 0)) * PX_PER_TWIP,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const sameGeometry = (a, b) => a.width === b.width &&
|
|
20
|
+
a.height === b.height &&
|
|
21
|
+
a.top === b.top &&
|
|
22
|
+
a.bottom === b.bottom &&
|
|
23
|
+
a.left === b.left &&
|
|
24
|
+
a.right === b.right;
|
|
25
|
+
/** An empty page: the page box with its margins as padding, and its content box. */
|
|
26
|
+
function createPage(doc, g) {
|
|
27
|
+
const page = doc.createElement("div");
|
|
28
|
+
page.className = WORD_PAGE_CLASS;
|
|
29
|
+
const { style } = page;
|
|
30
|
+
style.boxSizing = "border-box";
|
|
31
|
+
style.position = "relative";
|
|
32
|
+
style.width = `${g.width}px`;
|
|
33
|
+
style.height = `${g.height}px`;
|
|
34
|
+
style.padding = `${g.top}px ${g.right}px ${g.bottom}px ${g.left}px`;
|
|
35
|
+
style.background = "#fff";
|
|
36
|
+
style.color = "#000";
|
|
37
|
+
style.overflow = "hidden";
|
|
38
|
+
const body = doc.createElement("div");
|
|
39
|
+
body.style.display = "flow-root";
|
|
40
|
+
page.append(body);
|
|
41
|
+
return { page, body };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The ratio of a font's normal line height to its size, measured: a line of 100 px text with
|
|
45
|
+
* `line-height: normal` (the font's own ascent, descent and gap, as Word's single spacing).
|
|
46
|
+
*/
|
|
47
|
+
export function measureLineRatio(container) {
|
|
48
|
+
return (family) => {
|
|
49
|
+
const probe = container.ownerDocument.createElement("div");
|
|
50
|
+
const { style } = probe;
|
|
51
|
+
style.position = "absolute";
|
|
52
|
+
style.visibility = "hidden";
|
|
53
|
+
style.fontFamily = family;
|
|
54
|
+
style.fontSize = "100px";
|
|
55
|
+
style.lineHeight = "normal";
|
|
56
|
+
style.whiteSpace = "nowrap";
|
|
57
|
+
probe.textContent = "x";
|
|
58
|
+
container.append(probe);
|
|
59
|
+
const height = probe.getBoundingClientRect().height;
|
|
60
|
+
probe.remove();
|
|
61
|
+
return height > 0 ? height / 100 : 1.2;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The bottom of each line of a rendered block, from its top. Lines are the vertical clusters of
|
|
66
|
+
* its contents' client rects; a boundary is halfway between one line's content and the next's,
|
|
67
|
+
* the last line ends at the block's bottom.
|
|
68
|
+
*
|
|
69
|
+
* shortcut: line boxes are inferred from content rects (exact for even line heights); a
|
|
70
|
+
* superscript or a much larger run on a line moves that line's boundaries slightly.
|
|
71
|
+
*/
|
|
72
|
+
export function lineBottoms(element) {
|
|
73
|
+
const box = element.getBoundingClientRect();
|
|
74
|
+
const doc = element.ownerDocument;
|
|
75
|
+
const range = doc.createRange();
|
|
76
|
+
const rects = [];
|
|
77
|
+
// Text and line breaks only: a range over the whole block also has the boxes of the
|
|
78
|
+
// elements inside it (a table's), which span many lines.
|
|
79
|
+
const walker = doc.createTreeWalker(element, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT);
|
|
80
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
81
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
82
|
+
range.selectNodeContents(node);
|
|
83
|
+
for (const rect of range.getClientRects())
|
|
84
|
+
rects.push({ rect, text: true });
|
|
85
|
+
}
|
|
86
|
+
else if (node.nodeName === "BR")
|
|
87
|
+
rects.push({ rect: node.getBoundingClientRect(), text: false });
|
|
88
|
+
}
|
|
89
|
+
rects.sort((a, b) => a.rect.top - b.rect.top);
|
|
90
|
+
const lines = [];
|
|
91
|
+
for (const { rect, text } of rects) {
|
|
92
|
+
if (rect.height <= 0)
|
|
93
|
+
continue;
|
|
94
|
+
const last = lines[lines.length - 1];
|
|
95
|
+
// Same line: it starts above the middle of the line so far.
|
|
96
|
+
if (last && rect.top < (last.top + last.bottom) / 2) {
|
|
97
|
+
// A line's text says where it is; a <br> only for a line without text (engines size
|
|
98
|
+
// its box differently).
|
|
99
|
+
if (text && !last.text)
|
|
100
|
+
Object.assign(last, { top: rect.top, bottom: rect.bottom, text });
|
|
101
|
+
else if (text === last.text) {
|
|
102
|
+
last.top = Math.min(last.top, rect.top);
|
|
103
|
+
last.bottom = Math.max(last.bottom, rect.bottom);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
lines.push({ top: rect.top, bottom: rect.bottom, text });
|
|
108
|
+
}
|
|
109
|
+
const bottoms = lines.slice(1).map((line, i) => {
|
|
110
|
+
const above = lines[i];
|
|
111
|
+
return (above.bottom + line.top) / 2 - box.top;
|
|
112
|
+
});
|
|
113
|
+
bottoms.push(box.height);
|
|
114
|
+
return bottoms;
|
|
115
|
+
}
|
|
116
|
+
/** The height of a table's leading header rows (repeated on each page it continues on), or 0. */
|
|
117
|
+
function headerHeight(element) {
|
|
118
|
+
let bottom = 0;
|
|
119
|
+
// The table's own rows: not those of a table nested in a cell.
|
|
120
|
+
for (const row of element.querySelectorAll(":scope > table > tbody > tr")) {
|
|
121
|
+
if (!row.dataset || !("foliHeader" in row.dataset))
|
|
122
|
+
break;
|
|
123
|
+
bottom = row.getBoundingClientRect().bottom;
|
|
124
|
+
}
|
|
125
|
+
return bottom ? bottom - element.getBoundingClientRect().top : 0;
|
|
126
|
+
}
|
|
127
|
+
/** The lines that end with an explicit page break, by the break's position. */
|
|
128
|
+
function breakLines(element, bottoms) {
|
|
129
|
+
const top = element.getBoundingClientRect().top;
|
|
130
|
+
return [...element.querySelectorAll(`br[${WORD_PAGE_BREAK_ATTR}]`)].map((br) => {
|
|
131
|
+
const y = br.getBoundingClientRect().top - top;
|
|
132
|
+
const line = bottoms.findIndex((bottom) => y < bottom);
|
|
133
|
+
return line < 0 ? bottoms.length - 1 : line;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Lays a v3 document out on pages inside `container`. Headers, footers, footnotes and floating
|
|
138
|
+
* content are not laid out yet (Phase 11); tables are shown from their verbatim XML until
|
|
139
|
+
* Phase 10.
|
|
140
|
+
*/
|
|
141
|
+
export function renderDocument(document, container, options = {}) {
|
|
142
|
+
const doc = container.ownerDocument;
|
|
143
|
+
const blocks = renderBlocks(document, doc, {
|
|
144
|
+
...options,
|
|
145
|
+
lineRatio: measureLineRatio(container),
|
|
146
|
+
});
|
|
147
|
+
// Sections: consecutive blocks with one page setup. A section starts a new page unless it is
|
|
148
|
+
// continuous with the same geometry (shortcut: a continuous section with another geometry
|
|
149
|
+
// starts a new page).
|
|
150
|
+
const groups = [];
|
|
151
|
+
let current = [];
|
|
152
|
+
const close = (section) => {
|
|
153
|
+
const g = geometry(section);
|
|
154
|
+
const previous = groups[groups.length - 1];
|
|
155
|
+
if (section.type === "continuous" && previous && sameGeometry(previous.geometry, g))
|
|
156
|
+
previous.blocks.push(...current);
|
|
157
|
+
else
|
|
158
|
+
groups.push({ geometry: g, blocks: current });
|
|
159
|
+
current = [];
|
|
160
|
+
};
|
|
161
|
+
for (const block of blocks) {
|
|
162
|
+
current.push(block);
|
|
163
|
+
if (block.section)
|
|
164
|
+
close(block.section);
|
|
165
|
+
}
|
|
166
|
+
if (current.length || !groups.length)
|
|
167
|
+
close(document.section);
|
|
168
|
+
const pages = [];
|
|
169
|
+
const firstPage = new Map();
|
|
170
|
+
/** Every fragment placed, in order: its page and how many lines it shows (measured lazily). */
|
|
171
|
+
const placements = [];
|
|
172
|
+
for (const group of groups) {
|
|
173
|
+
const g = group.geometry;
|
|
174
|
+
// Measure in a page of the section's width, out of view.
|
|
175
|
+
const measuring = createPage(doc, g);
|
|
176
|
+
measuring.page.style.position = "absolute";
|
|
177
|
+
measuring.page.style.visibility = "hidden";
|
|
178
|
+
measuring.page.style.height = "auto";
|
|
179
|
+
container.append(measuring.page);
|
|
180
|
+
for (const block of group.blocks)
|
|
181
|
+
measuring.body.append(block.element);
|
|
182
|
+
const lines = new Map();
|
|
183
|
+
const linesOf = (block) => {
|
|
184
|
+
let value = lines.get(block);
|
|
185
|
+
if (!value) {
|
|
186
|
+
value = lineBottoms(block.element);
|
|
187
|
+
lines.set(block, value);
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
};
|
|
191
|
+
const headers = new Map();
|
|
192
|
+
const pageHeight = g.height - g.top - g.bottom;
|
|
193
|
+
const boxes = group.blocks.map((block, i) => {
|
|
194
|
+
const height = block.element.getBoundingClientRect().height;
|
|
195
|
+
const repeat = block.element.querySelector("tr") ? headerHeight(block.element) : 0;
|
|
196
|
+
if (repeat)
|
|
197
|
+
headers.set(block, repeat);
|
|
198
|
+
const next = group.blocks[i + 1];
|
|
199
|
+
const hasBreak = !!block.element.querySelector(`br[${WORD_PAGE_BREAK_ATTR}]`);
|
|
200
|
+
// A paragraph kept together is one line to the flow, unless it cannot be: taller than a
|
|
201
|
+
// page, or broken by a page break.
|
|
202
|
+
const kept = block.keepLines && !hasBreak && height <= pageHeight;
|
|
203
|
+
return {
|
|
204
|
+
height,
|
|
205
|
+
marginTop: block.before,
|
|
206
|
+
marginBottom: block.after,
|
|
207
|
+
repeat,
|
|
208
|
+
keepWithNext: block.keepNext,
|
|
209
|
+
lines: () => (kept ? [height] : linesOf(block)),
|
|
210
|
+
breaksAfter: () => {
|
|
211
|
+
const breaks = hasBreak ? breakLines(block.element, linesOf(block)) : [];
|
|
212
|
+
// The next block starts a page: this one's last line ends it.
|
|
213
|
+
if (next?.pageBreakBefore)
|
|
214
|
+
breaks.push((kept ? 1 : linesOf(block).length) - 1);
|
|
215
|
+
return breaks;
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
});
|
|
219
|
+
// shortcut: widow and orphan control is on for every paragraph (Word's Normal has it; a
|
|
220
|
+
// paragraph turning it off is still kept to two lines).
|
|
221
|
+
const fragments = flow(boxes, pageHeight, { orphans: 2, widows: 2, spacing: "word" });
|
|
222
|
+
// What placing needs of the layout, read while the blocks are still laid out: the lines of
|
|
223
|
+
// split blocks, and which blocks end with an explicit page break.
|
|
224
|
+
const endsWithBreak = new Set();
|
|
225
|
+
group.blocks.forEach((block, b) => {
|
|
226
|
+
if ((fragments[b]?.length ?? 0) > 1)
|
|
227
|
+
linesOf(block);
|
|
228
|
+
if (!block.element.querySelector(`br[${WORD_PAGE_BREAK_ATTR}]`))
|
|
229
|
+
return;
|
|
230
|
+
const bottoms = linesOf(block);
|
|
231
|
+
if (breakLines(block.element, bottoms).includes(bottoms.length - 1))
|
|
232
|
+
endsWithBreak.add(block);
|
|
233
|
+
});
|
|
234
|
+
measuring.page.remove();
|
|
235
|
+
const count = Math.max(1, ...fragments.flat().map((f) => f.page + 1));
|
|
236
|
+
const groupPages = Array.from({ length: count }, () => createPage(doc, g));
|
|
237
|
+
let previousOnPage = null;
|
|
238
|
+
group.blocks.forEach((block, b) => {
|
|
239
|
+
const placed = fragments[b] ?? [];
|
|
240
|
+
const bottoms = placed.length > 1 ? linesOf(block) : [];
|
|
241
|
+
placed.forEach((fragment, f) => {
|
|
242
|
+
const target = groupPages[fragment.page];
|
|
243
|
+
let gap = 0;
|
|
244
|
+
if (fragment.fromLine === 0) {
|
|
245
|
+
if (previousOnPage?.page === fragment.page)
|
|
246
|
+
gap = group.blocks[previousOnPage.block].after + block.before;
|
|
247
|
+
else {
|
|
248
|
+
// The first block on a page: Word keeps its space before on the section's first
|
|
249
|
+
// page and after an explicit break only.
|
|
250
|
+
const prior = group.blocks[b - 1];
|
|
251
|
+
const forced = fragment.page === 0 ||
|
|
252
|
+
block.pageBreakBefore ||
|
|
253
|
+
(prior !== undefined && endsWithBreak.has(prior));
|
|
254
|
+
gap = forced ? block.before : 0;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let element = block.element;
|
|
258
|
+
if (placed.length > 1) {
|
|
259
|
+
// A split block: each fragment shows its lines of the whole block, clipped.
|
|
260
|
+
const top = fragment.fromLine ? (bottoms[fragment.fromLine - 1] ?? 0) : 0;
|
|
261
|
+
const end = fragment.toLine === Number.POSITIVE_INFINITY
|
|
262
|
+
? (bottoms[bottoms.length - 1] ?? 0)
|
|
263
|
+
: (bottoms[fragment.toLine - 1] ?? 0);
|
|
264
|
+
const clip = doc.createElement("div");
|
|
265
|
+
clip.style.overflow = "hidden";
|
|
266
|
+
clip.style.height = `${end - top}px`;
|
|
267
|
+
const inner = f === 0 ? block.element : block.element.cloneNode(true);
|
|
268
|
+
if (f > 0)
|
|
269
|
+
inner.setAttribute("aria-hidden", "true");
|
|
270
|
+
inner.style.marginTop = `${-top}px`;
|
|
271
|
+
clip.append(inner);
|
|
272
|
+
element = clip;
|
|
273
|
+
const repeat = f > 0 ? (headers.get(block) ?? 0) : 0;
|
|
274
|
+
if (repeat) {
|
|
275
|
+
// The header rows again above the continuation.
|
|
276
|
+
const header = doc.createElement("div");
|
|
277
|
+
header.style.overflow = "hidden";
|
|
278
|
+
header.style.height = `${repeat}px`;
|
|
279
|
+
const copy = block.element.cloneNode(true);
|
|
280
|
+
copy.setAttribute("aria-hidden", "true");
|
|
281
|
+
copy.style.marginTop = "0";
|
|
282
|
+
header.append(copy);
|
|
283
|
+
element = doc.createElement("div");
|
|
284
|
+
element.append(header, clip);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
element.style.marginTop = `${gap}px`;
|
|
288
|
+
target.body.append(element);
|
|
289
|
+
previousOnPage = { page: fragment.page, block: b };
|
|
290
|
+
placements.push({
|
|
291
|
+
page: pages.length + fragment.page,
|
|
292
|
+
nodes: f === 0 ? block.nodes : null,
|
|
293
|
+
lines: () => (fragment.toLine === Number.POSITIVE_INFINITY
|
|
294
|
+
? linesOf(block).length
|
|
295
|
+
: fragment.toLine) - fragment.fromLine,
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
const first = placed[0];
|
|
299
|
+
if (first)
|
|
300
|
+
for (const index of block.nodes)
|
|
301
|
+
firstPage.set(index, pages.length + first.page);
|
|
302
|
+
});
|
|
303
|
+
for (const { page } of groupPages) {
|
|
304
|
+
container.append(page);
|
|
305
|
+
pages.push(page);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
let firstLine = null;
|
|
309
|
+
return {
|
|
310
|
+
pages,
|
|
311
|
+
pageOf: (index) => firstPage.get(index),
|
|
312
|
+
lineOf: (index) => {
|
|
313
|
+
if (!firstLine) {
|
|
314
|
+
firstLine = new Map();
|
|
315
|
+
let page = -1;
|
|
316
|
+
let line = 1;
|
|
317
|
+
for (const placement of placements) {
|
|
318
|
+
if (placement.page !== page) {
|
|
319
|
+
page = placement.page;
|
|
320
|
+
line = 1;
|
|
321
|
+
}
|
|
322
|
+
for (const node of placement.nodes ?? [])
|
|
323
|
+
firstLine.set(node, line);
|
|
324
|
+
line += placement.lines();
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return firstLine.get(index);
|
|
328
|
+
},
|
|
329
|
+
destroy: () => {
|
|
330
|
+
for (const page of pages)
|
|
331
|
+
page.remove();
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=pages.js.map
|
|
@@ -0,0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C;YAClC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACvB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,IAAI,SAAS,GAA+B,IAAI,CAAC;IACjD,OAAO;QACL,KAAK;QACL,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;QACvC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YAChB,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;gBACtB,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC;gBACd,IAAI,IAAI,GAAG,CAAC,CAAC;gBACb,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;oBACnC,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;wBAC5B,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;wBACtB,IAAI,GAAG,CAAC,CAAC;oBACX,CAAC;oBACD,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,KAAK,IAAI,EAAE;wBAAE,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBACpE,IAAI,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;gBAC5B,CAAC;YACH,CAAC;YACD,OAAO,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folijs/view",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Framework-agnostic DOM view for the Foli document engine: rendering, input, selection, layout.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"!src/**/*.test.*"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@folijs/core": "^0.
|
|
28
|
+
"@folijs/core": "^0.4.0"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
package/src/clipboard.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Alignment,
|
|
3
|
+
copiedDefinitions,
|
|
3
4
|
type DocJSON,
|
|
4
5
|
Fragment,
|
|
5
6
|
type InlineJSON,
|
|
@@ -7,20 +8,36 @@ import {
|
|
|
7
8
|
type MarkJSON,
|
|
8
9
|
type Node as ModelNode,
|
|
9
10
|
type ParagraphJSON,
|
|
10
|
-
parseContent,
|
|
11
11
|
type SimpleMarkName,
|
|
12
|
+
type WordContext,
|
|
13
|
+
type WordEnvelope,
|
|
12
14
|
} from "@folijs/core";
|
|
13
|
-
import { PAGE_BREAK_ATTR
|
|
15
|
+
import { PAGE_BREAK_ATTR } from "./render.js";
|
|
16
|
+
import { opaqueParagraphsText, parseOpaque } from "./word/blocks.js";
|
|
17
|
+
import { clipboardBlocks } from "./word/edit.js";
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
|
-
* Clipboard type for Foli content, read back first on paste: `{ open, content }`, the
|
|
17
|
-
* blocks as `DocJSON
|
|
20
|
+
* Clipboard type for Foli content, read back first on paste: `{ open, content, word? }`, the
|
|
21
|
+
* copied blocks as `DocJSON`, whether they were cut out of one block (see `Pasted.open`), and
|
|
22
|
+
* from a schema v3 document the definitions they reference (`copiedDefinitions`).
|
|
18
23
|
*/
|
|
19
24
|
export const FOLI_MIME = "application/x-foli+json";
|
|
20
25
|
|
|
26
|
+
/** One clipboard format's content, before validation. */
|
|
27
|
+
export interface Found {
|
|
28
|
+
content: unknown;
|
|
29
|
+
open: boolean;
|
|
30
|
+
/** Read from HTML: schema v2 content as `htmlToDoc` reads it. */
|
|
31
|
+
html?: boolean;
|
|
32
|
+
/** The definitions (styles, numbering, comments) a copy carries. */
|
|
33
|
+
word?: unknown;
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
/** Validated clipboard content. */
|
|
22
37
|
export interface Pasted {
|
|
23
38
|
doc: ModelNode;
|
|
39
|
+
/** The target's envelope with what the content needs (styles, lists...), when it changed. */
|
|
40
|
+
envelope?: WordEnvelope;
|
|
24
41
|
/**
|
|
25
42
|
* True when no block boundary was copied (text from inside one block, plain text, inline
|
|
26
43
|
* HTML): the content always joins the block it is pasted into, which keeps its type. Closed
|
|
@@ -35,73 +52,106 @@ export interface ClipboardContent {
|
|
|
35
52
|
json: string;
|
|
36
53
|
}
|
|
37
54
|
|
|
38
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Serializes `from..to` of `doc` for the clipboard. Hard breaks and block ends become "\n". The
|
|
57
|
+
* HTML is the document as its Word renderer draws it (`word`: its context and the fonts' line
|
|
58
|
+
* height ratios): resolved formatting as inline CSS, list numbers as Word's HTML has them.
|
|
59
|
+
*/
|
|
39
60
|
export function serializeRange(
|
|
40
61
|
doc: ModelNode,
|
|
41
62
|
from: number,
|
|
42
63
|
to: number,
|
|
43
64
|
ownerDocument: Document,
|
|
65
|
+
word: { context: WordContext; ratio: (family: string) => number },
|
|
44
66
|
): ClipboardContent {
|
|
45
67
|
// A slice inside one textblock holds only inline content: wrap it back in its ancestors.
|
|
46
68
|
const $from = doc.resolve(from);
|
|
47
69
|
let content = doc.slice(from, to).content;
|
|
48
70
|
for (let depth = $from.sharedDepth(to); depth > 0; depth--)
|
|
49
71
|
content = Fragment.from($from.node(depth).copy(content));
|
|
50
|
-
// Not validated:
|
|
51
|
-
// when pasted; the HTML is only markup.
|
|
72
|
+
// Not validated: the JSON is validated when pasted; the HTML is only markup.
|
|
52
73
|
const blocks = doc.type.createOpen(null, content);
|
|
53
74
|
const container = ownerDocument.createElement("div");
|
|
54
|
-
// Built with createElement/textContent (
|
|
55
|
-
// A range inside one
|
|
56
|
-
// (a word copied from a list item must not paste as a one-item list); the JSON keeps
|
|
75
|
+
// Built with createElement/textContent (word/edit.ts); reading innerHTML only serializes it.
|
|
76
|
+
// A range inside one paragraph is that paragraph's text: its list number stays out of the HTML
|
|
77
|
+
// (a word copied from a list item must not paste as a one-item list); the JSON keeps it.
|
|
57
78
|
const $to = doc.resolve(to);
|
|
58
79
|
const inline = $from.parent.isTextblock && $from.sameParent($to);
|
|
59
80
|
const htmlBlocks = inline
|
|
60
81
|
? [$from.parent.copy(doc.slice(from, to).content)]
|
|
61
82
|
: blocks.content.content;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
const first = inline ? -1 : $from.index(0);
|
|
84
|
+
container.append(
|
|
85
|
+
...clipboardBlocks(word.context, doc, htmlBlocks, first, ownerDocument, word.ratio),
|
|
86
|
+
);
|
|
66
87
|
// How other apps (and print) recognize a page break; the editor itself does not need it.
|
|
67
88
|
for (const br of container.querySelectorAll(`br[${PAGE_BREAK_ATTR}]`))
|
|
68
89
|
(br as HTMLElement).style.cssText = "page-break-before: always; break-before: page";
|
|
69
90
|
return {
|
|
70
|
-
text: doc.textBetween(from, to, "\n",
|
|
91
|
+
text: doc.textBetween(from, to, "\n", (leaf) => leafText(leaf, ownerDocument)),
|
|
71
92
|
html: container.innerHTML,
|
|
72
|
-
json: JSON.stringify({
|
|
93
|
+
json: JSON.stringify({
|
|
94
|
+
open: $from.sharedDepth(to) > 0,
|
|
95
|
+
content: blocks.toJSON(),
|
|
96
|
+
word: copiedDefinitions(word.context, blocks),
|
|
97
|
+
}),
|
|
73
98
|
};
|
|
74
99
|
}
|
|
75
100
|
|
|
101
|
+
/**
|
|
102
|
+
* A leaf as plain text: breaks and rules as line feeds, a tab as a tab, opaque content as the
|
|
103
|
+
* text it shows (a field's result, a table's paragraphs on their lines), markers as nothing.
|
|
104
|
+
*/
|
|
105
|
+
function leafText(leaf: ModelNode, doc: Document): string {
|
|
106
|
+
const name = leaf.type.name;
|
|
107
|
+
if (name === "tab") return "\t";
|
|
108
|
+
if (name === "opaqueInline" || name === "opaqueBlock") {
|
|
109
|
+
const xml = parseOpaque(String(leaf.attrs.xml ?? ""), doc);
|
|
110
|
+
const text = xml ? opaqueParagraphsText(xml) : "";
|
|
111
|
+
return leaf.isBlock ? `\n${text}` : text;
|
|
112
|
+
}
|
|
113
|
+
return leaf.isBlock || name === "hardBreak" || name === "pageBreak" || name === "columnBreak"
|
|
114
|
+
? "\n"
|
|
115
|
+
: "";
|
|
116
|
+
}
|
|
117
|
+
|
|
76
118
|
/**
|
|
77
119
|
* The content of clipboard data, validated, or null. Priority: Foli JSON, then HTML, then plain
|
|
78
|
-
* text. Every format is validated
|
|
79
|
-
* through to the next. `marks` are given to plain text
|
|
80
|
-
* insertion point).
|
|
120
|
+
* text. Every format is validated and fitted to the document by `parse` (`fitPaste`,
|
|
121
|
+
* `fitPastedV2`); a format that fails falls through to the next. `marks` are given to plain text
|
|
122
|
+
* (the marks typing would get at the insertion point).
|
|
81
123
|
*/
|
|
82
124
|
export function docFromClipboard(
|
|
83
125
|
data: Pick<DataTransfer, "getData">,
|
|
84
|
-
marks: readonly MarkJSON[]
|
|
126
|
+
marks: readonly MarkJSON[],
|
|
127
|
+
parse: (found: Found) => Omit<Pasted, "open">,
|
|
85
128
|
): Pasted | null {
|
|
86
129
|
const json = data.getData(FOLI_MIME);
|
|
87
130
|
const html = data.getData("text/html");
|
|
88
131
|
const text = data.getData("text/plain");
|
|
89
|
-
const candidates: (() =>
|
|
132
|
+
const candidates: (() => Found | null)[] = [
|
|
90
133
|
() => {
|
|
91
134
|
if (!json) return null;
|
|
92
135
|
const value: unknown = JSON.parse(json);
|
|
93
136
|
if (typeof value !== "object" || value === null) return null;
|
|
94
|
-
const { open, content } = value as {
|
|
95
|
-
|
|
137
|
+
const { open, content, word } = value as {
|
|
138
|
+
open?: unknown;
|
|
139
|
+
content?: unknown;
|
|
140
|
+
word?: unknown;
|
|
141
|
+
};
|
|
142
|
+
return { content, open: open === true, word };
|
|
143
|
+
},
|
|
144
|
+
() => {
|
|
145
|
+
const read = html ? readHTML(html) : null;
|
|
146
|
+
return read && { ...read, html: true };
|
|
96
147
|
},
|
|
97
|
-
() => (html ? readHTML(html) : null),
|
|
98
148
|
() => (text ? { content: textToDoc(text, marks), open: true } : null),
|
|
99
149
|
];
|
|
100
150
|
for (const candidate of candidates) {
|
|
101
151
|
try {
|
|
102
152
|
const found = candidate();
|
|
103
153
|
if (!found) continue;
|
|
104
|
-
return {
|
|
154
|
+
return { ...parse(found), open: found.open };
|
|
105
155
|
} catch {
|
|
106
156
|
// Invalid or unreadable in this format: try the next one.
|
|
107
157
|
}
|
package/src/index.ts
CHANGED