fleuron 0.1.1 → 0.2.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/README.md +7 -7
- package/dist/client.d.ts +33 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +35 -10
- package/dist/client.js.map +1 -1
- package/dist/engine.d.ts +2 -2
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +38 -9
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/preview.d.ts +153 -19
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +378 -38
- package/dist/preview.js.map +1 -1
- package/dist/protocol.d.ts +35 -5
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +10 -2
- package/dist/protocol.js.map +1 -1
- package/dist/svg.d.ts +13 -4
- package/dist/svg.d.ts.map +1 -1
- package/dist/svg.js +142 -15
- package/dist/svg.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wire.d.ts +55 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +36 -6
- package/dist/wire.js.map +1 -1
- package/package.json +1 -1
- package/wasm/fleuron.d.ts +26 -16
- package/wasm/fleuron.js +36 -18
- package/wasm/fleuron_bg.wasm +0 -0
- package/wasm/fleuron_bg.wasm.d.ts +2 -2
package/dist/preview.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* A preview, mounted: markdown in, a page on screen.
|
|
3
3
|
*
|
|
4
4
|
* The worker, the module, the postcard buffer and the display structure
|
|
5
|
-
* are what this is built out of, not what it asks a caller to
|
|
5
|
+
* are what this is built out of, not what it asks a caller to supply.
|
|
6
6
|
* A host that wants them keeps having them, since the client, the
|
|
7
7
|
* protocol, the reader and the painter are all still exported. A host
|
|
8
8
|
* that only wants to see the book says where to put it and hands over
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* one, and an engine with nothing to do repaints straight away. A
|
|
17
17
|
* host that wants a fixed delay puts one in front of these calls.
|
|
18
18
|
*/
|
|
19
|
-
import type
|
|
19
|
+
import { type Metadata, type Op, type Sheet, type Source } from './protocol.js';
|
|
20
20
|
import type { Asset, LayoutOutput, Warning } from './wire.js';
|
|
21
21
|
/** How a preview is set up. */
|
|
22
22
|
export interface PreviewOptions {
|
|
@@ -70,7 +70,13 @@ export interface PreviewOptions {
|
|
|
70
70
|
* {@link PreviewOptions.images} supplied.
|
|
71
71
|
*/
|
|
72
72
|
asset?: (asset: Asset, index: number) => string | null | undefined;
|
|
73
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Called after every render that reached the screen, with the
|
|
75
|
+
* reply the page on screen came from. `output.pages` is that page
|
|
76
|
+
* alone, not the whole book: `output.bookPages` is the book's own
|
|
77
|
+
* length, and `output.fonts`/`output.assets`/`output.warnings` are
|
|
78
|
+
* the whole run's regardless.
|
|
79
|
+
*/
|
|
74
80
|
onRender?: (output: LayoutOutput) => void;
|
|
75
81
|
}
|
|
76
82
|
/**
|
|
@@ -87,9 +93,55 @@ export declare class Preview {
|
|
|
87
93
|
private readonly client;
|
|
88
94
|
private readonly options;
|
|
89
95
|
private readonly faces;
|
|
90
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Every image's own bytes, by url, kept independent of the transfer
|
|
98
|
+
* that moved the ones sent across the wall: a copy taken before the
|
|
99
|
+
* op went out, since the buffer handed to the engine is empty on
|
|
100
|
+
* this side afterwards.
|
|
101
|
+
*/
|
|
102
|
+
private readonly imageBytes;
|
|
103
|
+
/**
|
|
104
|
+
* A blob url per image currently drawn by a held page, by its own
|
|
105
|
+
* url. Built and revoked by {@link syncAssetCache}: a book with
|
|
106
|
+
* more images than are ever on screen at once does not keep a blob
|
|
107
|
+
* open, and its decode, for every one of them.
|
|
108
|
+
*/
|
|
91
109
|
private readonly pixels;
|
|
92
|
-
|
|
110
|
+
/**
|
|
111
|
+
* The pages this preview currently keeps decoded, by folio. Bounded
|
|
112
|
+
* to a window around the page on screen rather than the whole
|
|
113
|
+
* book: what makes a page turn instant is prefetching a neighbour
|
|
114
|
+
* before it is asked for, not holding every page there is.
|
|
115
|
+
*/
|
|
116
|
+
private readonly held;
|
|
117
|
+
/**
|
|
118
|
+
* The generation `held` was built under. A reply for a different
|
|
119
|
+
* generation means an edit landed, and drops whatever was held
|
|
120
|
+
* before inserting: a page from the book before the edit is not
|
|
121
|
+
* one to paint over it.
|
|
122
|
+
*/
|
|
123
|
+
private heldGeneration;
|
|
124
|
+
/**
|
|
125
|
+
* Pages currently being asked for from the worker, whether the
|
|
126
|
+
* page turned to or a background prefetch of a neighbour, to the
|
|
127
|
+
* generation they were asked for under. Asking again for one
|
|
128
|
+
* already here — including a page left and come back to before its
|
|
129
|
+
* first request landed — joins it rather than opening a second
|
|
130
|
+
* request for the same page.
|
|
131
|
+
*
|
|
132
|
+
* Keyed on generation, not just the folio, so a fetch left over
|
|
133
|
+
* from the generation before an edit cannot clear the marker a
|
|
134
|
+
* fresh fetch for the same folio placed under the new one when the
|
|
135
|
+
* old one finally lands and finds itself answering a book that no
|
|
136
|
+
* longer stands.
|
|
137
|
+
*/
|
|
138
|
+
private readonly pending;
|
|
139
|
+
/** The whole run's tables and diagnostics, which ride every reply
|
|
140
|
+
* regardless of which pages it carried. */
|
|
141
|
+
private fonts;
|
|
142
|
+
private assets;
|
|
143
|
+
private bookWarnings;
|
|
144
|
+
private bookPages;
|
|
93
145
|
private showing;
|
|
94
146
|
private scale;
|
|
95
147
|
private constructor();
|
|
@@ -112,8 +164,9 @@ export declare class Preview {
|
|
|
112
164
|
/** Drops one source and leaves the rest of the book standing. */
|
|
113
165
|
remove(name: string): Promise<void>;
|
|
114
166
|
/**
|
|
115
|
-
* Names the book.
|
|
116
|
-
*
|
|
167
|
+
* Names the book. The PDF export reads the name, and layout reads
|
|
168
|
+
* `extra.language`, which chooses the hyphenation patterns, so a
|
|
169
|
+
* rename alone costs no layout.
|
|
117
170
|
*/
|
|
118
171
|
setMetadata(metadata: Metadata): Promise<void>;
|
|
119
172
|
/**
|
|
@@ -126,8 +179,13 @@ export declare class Preview {
|
|
|
126
179
|
* add a file to a book already open.
|
|
127
180
|
*/
|
|
128
181
|
edit(name: string, text: string): Promise<void>;
|
|
129
|
-
/**
|
|
130
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Sets the author styling, cascading over the built-in sheet:
|
|
184
|
+
* one sheet as CSS text, or the layers a host built its styling
|
|
185
|
+
* out of, in cascade order. Later sheets win, and a warning names
|
|
186
|
+
* the sheet its declaration was written in.
|
|
187
|
+
*/
|
|
188
|
+
setStyle(css: string | Sheet[]): Promise<void>;
|
|
131
189
|
/** Registers a face for the session's life. */
|
|
132
190
|
addFont(bytes: Uint8Array): Promise<void>;
|
|
133
191
|
/**
|
|
@@ -138,7 +196,11 @@ export declare class Preview {
|
|
|
138
196
|
* and a page with nothing where the image was.
|
|
139
197
|
*/
|
|
140
198
|
addImage(url: string, bytes: Uint8Array): Promise<void>;
|
|
141
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Lays the book out again and repaints, asking only for the page on
|
|
201
|
+
* screen rather than the whole book. An edit drops whatever pages
|
|
202
|
+
* were held, since the book they came from no longer stands.
|
|
203
|
+
*/
|
|
142
204
|
render(ops?: Op[]): Promise<void>;
|
|
143
205
|
/** How many pages the book set to. */
|
|
144
206
|
get pages(): number;
|
|
@@ -155,8 +217,8 @@ export declare class Preview {
|
|
|
155
217
|
/** Everything the run had to complain about. */
|
|
156
218
|
get warnings(): Warning[];
|
|
157
219
|
/**
|
|
158
|
-
* The markup on screen, or a page that is not
|
|
159
|
-
*
|
|
220
|
+
* The markup on screen, or a page that is not held. Empty before
|
|
221
|
+
* the first render, and for a page outside the held window.
|
|
160
222
|
*/
|
|
161
223
|
svg(number?: number): string;
|
|
162
224
|
/**
|
|
@@ -167,19 +229,91 @@ export declare class Preview {
|
|
|
167
229
|
/** Closes the worker and gives the element back. */
|
|
168
230
|
destroy(): void;
|
|
169
231
|
/**
|
|
170
|
-
* Keeps a
|
|
171
|
-
*
|
|
232
|
+
* Keeps a copy of an image's bytes and hands the original to the
|
|
233
|
+
* engine.
|
|
172
234
|
*
|
|
173
|
-
* The
|
|
235
|
+
* The copy is taken before the op is sent, because the bytes move
|
|
174
236
|
* across the wall rather than being copied and the buffer is empty
|
|
175
|
-
* on this side afterwards.
|
|
237
|
+
* on this side afterwards. No blob is made here: {@link
|
|
238
|
+
* syncAssetCache} makes one only once a held page actually draws
|
|
239
|
+
* this url, which for most images in a book-sized manuscript is
|
|
240
|
+
* never at the same time as every other one.
|
|
176
241
|
*/
|
|
177
|
-
private
|
|
242
|
+
private keepImage;
|
|
243
|
+
/**
|
|
244
|
+
* Fetches one page not already pending, absorbing it and painting
|
|
245
|
+
* it if it is — or by the time it lands, has become — the page on
|
|
246
|
+
* screen. Shared by a page turn and a neighbour prefetch, so
|
|
247
|
+
* whichever of them asks first, the other joins it rather than
|
|
248
|
+
* opening a second request for the same page: what the request was
|
|
249
|
+
* *for* is decided when it lands, by whether `showing` still names
|
|
250
|
+
* it, not by which caller happened to start it.
|
|
251
|
+
*
|
|
252
|
+
* Errors are swallowed the way a missing face is elsewhere:
|
|
253
|
+
* nothing here is awaited by a caller that could catch one, and the
|
|
254
|
+
* frame simply stays as it was, retried the next time this page is
|
|
255
|
+
* asked for.
|
|
256
|
+
*/
|
|
257
|
+
private fetchPage;
|
|
258
|
+
/**
|
|
259
|
+
* Warms the pages either side of the one on screen, so a page turn
|
|
260
|
+
* in either direction paints from what is already held rather than
|
|
261
|
+
* asking the worker.
|
|
262
|
+
*/
|
|
263
|
+
private prefetchNeighbours;
|
|
264
|
+
/**
|
|
265
|
+
* Folds a reply into the held pages, keyed by folio rather than by
|
|
266
|
+
* its position in the reply. A reply for a generation `held` was
|
|
267
|
+
* not built under drops whatever was held before inserting: an
|
|
268
|
+
* edit is not undone by a page fetched against the book before it.
|
|
269
|
+
*/
|
|
270
|
+
private absorb;
|
|
271
|
+
/** Drops whatever is held outside the window around the page on screen. */
|
|
272
|
+
private prune;
|
|
273
|
+
/**
|
|
274
|
+
* Blobs every image a held page draws that does not have one yet,
|
|
275
|
+
* and revokes every blob no held page draws any more. Run after
|
|
276
|
+
* {@link prune}, over `held` as a whole rather than page by page:
|
|
277
|
+
* an asset two held pages share is not revoked for one of them
|
|
278
|
+
* dropping out while the other still stands.
|
|
279
|
+
*
|
|
280
|
+
* A url the host has not supplied bytes for is simply absent from
|
|
281
|
+
* `imageBytes`, the same gap the painter's asset resolver already
|
|
282
|
+
* falls back from — this adds no failure mode of its own, only an
|
|
283
|
+
* eviction of what was already optional.
|
|
284
|
+
*/
|
|
285
|
+
private syncAssetCache;
|
|
178
286
|
private paint;
|
|
287
|
+
/**
|
|
288
|
+
* Copies the selection layer's own text, reconstructed from the
|
|
289
|
+
* range's own boundaries rather than trusted to the browser's
|
|
290
|
+
* default serialization across `<text>` siblings — SVG text
|
|
291
|
+
* elements are not block boxes, and nothing guarantees a browser
|
|
292
|
+
* puts a line break between two of them the way it would between
|
|
293
|
+
* paragraphs. This is the pdf.js pattern: the layer under the
|
|
294
|
+
* pointer draws nothing, and copy answers from what it holds.
|
|
295
|
+
*/
|
|
296
|
+
private readonly onCopy;
|
|
297
|
+
/**
|
|
298
|
+
* The selection's own text, one line's slice per line it touches,
|
|
299
|
+
* joined in reading order. `null` for a selection with nothing in
|
|
300
|
+
* it, or one that lies outside this preview altogether — a host's
|
|
301
|
+
* own text elsewhere on the page is not this preview's to answer
|
|
302
|
+
* for.
|
|
303
|
+
*/
|
|
304
|
+
private selectedText;
|
|
305
|
+
/**
|
|
306
|
+
* Calls {@link PreviewOptions.onRender}, if the page on screen is
|
|
307
|
+
* held: built fresh from `held` and the run's tables rather than
|
|
308
|
+
* threaded through from whichever fetch put it there, so a host
|
|
309
|
+
* hears about every page that reaches the screen the same way,
|
|
310
|
+
* cached or just arrived.
|
|
311
|
+
*/
|
|
312
|
+
private notify;
|
|
179
313
|
private painting;
|
|
180
314
|
/**
|
|
181
|
-
* Loads the faces the
|
|
182
|
-
* engine shaped with.
|
|
315
|
+
* Loads the faces the held pages draw with, from the same files
|
|
316
|
+
* the engine shaped with.
|
|
183
317
|
*
|
|
184
318
|
* The bundled face is why this asks the module rather than the
|
|
185
319
|
* network: it is inside the module, and there is no URL to fetch
|
package/dist/preview.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,EAAE,EAEP,KAAK,KAAK,EACV,KAAK,MAAM,EACZ,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,KAAK,EAAgB,YAAY,EAAQ,OAAO,EAAE,MAAM,WAAW,CAAC;AASlF,+BAA+B;AAC/B,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,OAAO,CAAC,EAAE,YAAY,GAAG,KAAK,GAAG,UAAU,CAAC;IAC5C,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC1B,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,6BAA6B;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;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