fleuron 0.1.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 +132 -0
- package/dist/client.d.ts +74 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +124 -0
- package/dist/client.js.map +1 -0
- package/dist/engine.d.ts +50 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +163 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/preview.d.ts +193 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +303 -0
- package/dist/preview.js.map +1 -0
- package/dist/protocol.d.ts +153 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +19 -0
- package/dist/protocol.js.map +1 -0
- package/dist/svg.d.ts +57 -0
- package/dist/svg.d.ts.map +1 -0
- package/dist/svg.js +210 -0
- package/dist/svg.js.map +1 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +8 -0
- package/dist/version.js.map +1 -0
- package/dist/wire.d.ts +179 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +174 -0
- package/dist/wire.js.map +1 -0
- package/dist/worker.d.ts +16 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +23 -0
- package/dist/worker.js.map +1 -0
- package/package.json +45 -0
- package/wasm/fleuron.d.ts +221 -0
- package/wasm/fleuron.js +629 -0
- package/wasm/fleuron_bg.wasm +0 -0
- package/wasm/fleuron_bg.wasm.d.ts +30 -0
package/dist/wire.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire: postcard bytes in, a display structure out.
|
|
3
|
+
*
|
|
4
|
+
* The engine encodes with postcard, which sends no field names and
|
|
5
|
+
* packs small numbers into one byte. Nothing in the buffer says what
|
|
6
|
+
* it is, so this reader walks the same fields in the same order the
|
|
7
|
+
* engine wrote them, and the version in front of the bytes is what
|
|
8
|
+
* catches the day those two stop agreeing.
|
|
9
|
+
*/
|
|
10
|
+
/** The encoding this reader understands. */
|
|
11
|
+
export const WIRE_VERSION = 4;
|
|
12
|
+
/** A buffer this reader will not read, and why. */
|
|
13
|
+
export class WireError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'WireError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Walks a postcard buffer, one field at a time. */
|
|
20
|
+
class Reader {
|
|
21
|
+
view;
|
|
22
|
+
bytes;
|
|
23
|
+
at = 0;
|
|
24
|
+
constructor(bytes) {
|
|
25
|
+
this.bytes = bytes;
|
|
26
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
27
|
+
}
|
|
28
|
+
/** An unsigned varint, seven bits per byte, low group first. */
|
|
29
|
+
varint() {
|
|
30
|
+
let value = 0;
|
|
31
|
+
let shift = 0;
|
|
32
|
+
for (;;) {
|
|
33
|
+
const byte = this.bytes[this.at++];
|
|
34
|
+
if (byte === undefined) {
|
|
35
|
+
throw new WireError('the buffer ended mid-number');
|
|
36
|
+
}
|
|
37
|
+
value += (byte & 0x7f) * 2 ** shift;
|
|
38
|
+
if ((byte & 0x80) === 0) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
shift += 7;
|
|
42
|
+
if (shift > 63) {
|
|
43
|
+
throw new WireError('a varint ran past the width of a number');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
bool() {
|
|
48
|
+
return this.varint() !== 0;
|
|
49
|
+
}
|
|
50
|
+
f32() {
|
|
51
|
+
const value = this.view.getFloat32(this.at, true);
|
|
52
|
+
this.at += 4;
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
string() {
|
|
56
|
+
const length = this.varint();
|
|
57
|
+
const start = this.at;
|
|
58
|
+
this.at += length;
|
|
59
|
+
if (this.at > this.bytes.length) {
|
|
60
|
+
throw new WireError('the buffer ended mid-string');
|
|
61
|
+
}
|
|
62
|
+
return decoder.decode(this.bytes.subarray(start, this.at));
|
|
63
|
+
}
|
|
64
|
+
/** A `Vec<T>`: a count, then that many of them. */
|
|
65
|
+
seq(item) {
|
|
66
|
+
const length = this.varint();
|
|
67
|
+
const out = new Array(length);
|
|
68
|
+
for (let i = 0; i < length; i += 1) {
|
|
69
|
+
out[i] = item();
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/** An `Option<T>`: present or not, and the value when it is. */
|
|
74
|
+
option(item) {
|
|
75
|
+
return this.varint() === 0 ? null : item();
|
|
76
|
+
}
|
|
77
|
+
done() {
|
|
78
|
+
return this.at >= this.bytes.length;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const decoder = new TextDecoder();
|
|
82
|
+
const SIDES = ['recto', 'verso'];
|
|
83
|
+
function glyph(r) {
|
|
84
|
+
return { id: r.varint(), x: r.f32(), range: [r.varint(), r.varint()] };
|
|
85
|
+
}
|
|
86
|
+
function item(r) {
|
|
87
|
+
const variant = r.varint();
|
|
88
|
+
switch (variant) {
|
|
89
|
+
case 0:
|
|
90
|
+
return {
|
|
91
|
+
kind: 'text',
|
|
92
|
+
x: r.f32(),
|
|
93
|
+
y: r.f32(),
|
|
94
|
+
fontId: r.varint(),
|
|
95
|
+
size: r.f32(),
|
|
96
|
+
text: r.string(),
|
|
97
|
+
glyphs: r.seq(() => glyph(r)),
|
|
98
|
+
};
|
|
99
|
+
case 1:
|
|
100
|
+
return { kind: 'rect', x: r.f32(), y: r.f32(), w: r.f32(), h: r.f32() };
|
|
101
|
+
case 2:
|
|
102
|
+
return {
|
|
103
|
+
kind: 'image',
|
|
104
|
+
x: r.f32(),
|
|
105
|
+
y: r.f32(),
|
|
106
|
+
w: r.f32(),
|
|
107
|
+
h: r.f32(),
|
|
108
|
+
asset: r.varint(),
|
|
109
|
+
};
|
|
110
|
+
default:
|
|
111
|
+
throw new WireError(`draw item ${variant} is not one this reader knows`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function page(r) {
|
|
115
|
+
const number = r.varint();
|
|
116
|
+
const side = SIDES[r.varint()];
|
|
117
|
+
if (side === undefined) {
|
|
118
|
+
throw new WireError('a page fell on neither side of the spread');
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
number,
|
|
122
|
+
side,
|
|
123
|
+
width: r.f32(),
|
|
124
|
+
height: r.f32(),
|
|
125
|
+
sections: r.seq(() => r.varint()),
|
|
126
|
+
items: r.seq(() => item(r)),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function font(r) {
|
|
130
|
+
return {
|
|
131
|
+
family: r.string(),
|
|
132
|
+
name: r.string(),
|
|
133
|
+
style: r.string(),
|
|
134
|
+
attributes: { italic: r.bool(), weight: r.varint() },
|
|
135
|
+
variations: r.seq(() => ({ tag: r.string(), value: r.f32() })),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function asset(r) {
|
|
139
|
+
return {
|
|
140
|
+
url: r.string(),
|
|
141
|
+
intrinsic: { width: r.varint(), height: r.varint(), dpiX: r.f32(), dpiY: r.f32() },
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function warning(r) {
|
|
145
|
+
return { message: r.string(), origin: r.option(() => r.string()) };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The version a buffer leads with, without reading the rest of it.
|
|
149
|
+
*/
|
|
150
|
+
export function wireVersionOf(bytes) {
|
|
151
|
+
return new Reader(bytes).varint();
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Reads a display structure, refusing a version this reader does not know
|
|
155
|
+
* rather than painting whatever the bytes happen to decode to.
|
|
156
|
+
*/
|
|
157
|
+
export function decodeDisplayList(bytes) {
|
|
158
|
+
const r = new Reader(bytes);
|
|
159
|
+
const version = r.varint();
|
|
160
|
+
if (version !== WIRE_VERSION) {
|
|
161
|
+
throw new WireError(`wire version ${version}, expected ${WIRE_VERSION}`);
|
|
162
|
+
}
|
|
163
|
+
const output = {
|
|
164
|
+
pages: r.seq(() => page(r)),
|
|
165
|
+
fonts: r.seq(() => font(r)),
|
|
166
|
+
assets: r.seq(() => asset(r)),
|
|
167
|
+
warnings: r.seq(() => warning(r)),
|
|
168
|
+
};
|
|
169
|
+
if (!r.done()) {
|
|
170
|
+
throw new WireError('the buffer holds more than one display structure');
|
|
171
|
+
}
|
|
172
|
+
return output;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=wire.js.map
|
package/dist/wire.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,4CAA4C;AAC5C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AA0K9B,mDAAmD;AACnD,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,oDAAoD;AACpD,MAAM,MAAM;IACO,IAAI,CAAW;IACf,KAAK,CAAa;IAC3B,EAAE,GAAG,CAAC,CAAC;IAEf,YAAY,KAAiB;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC7E,CAAC;IAED,gEAAgE;IAChE,MAAM;QACJ,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,SAAS,CAAC;YACR,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,C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B;IACjD,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;IAC3B,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,gBAAgB,OAAO,cAAc,YAAY,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,MAAM,GAAiB;QAC3B,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7B,QAAQ,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KAClC,CAAC;IACF,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACd,MAAM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The worker, in the six lines it takes: load the module, hand every
|
|
3
|
+
* message to the engine, post what it says back.
|
|
4
|
+
*
|
|
5
|
+
* The handler goes on before the module has arrived, and every
|
|
6
|
+
* request waits on the same promise. A worker that installs its
|
|
7
|
+
* handler after the load loses whatever a host posted while the
|
|
8
|
+
* module was still coming down, and a host that mounts a preview and
|
|
9
|
+
* hands it a manuscript posts exactly then.
|
|
10
|
+
*
|
|
11
|
+
* A host that wants the module somewhere else, in an extension or a
|
|
12
|
+
* Node thread or a bundle that inlines the bytes, writes these lines
|
|
13
|
+
* itself over {@link createEngine}.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The worker, in the six lines it takes: load the module, hand every
|
|
3
|
+
* message to the engine, post what it says back.
|
|
4
|
+
*
|
|
5
|
+
* The handler goes on before the module has arrived, and every
|
|
6
|
+
* request waits on the same promise. A worker that installs its
|
|
7
|
+
* handler after the load loses whatever a host posted while the
|
|
8
|
+
* module was still coming down, and a host that mounts a preview and
|
|
9
|
+
* hands it a manuscript posts exactly then.
|
|
10
|
+
*
|
|
11
|
+
* A host that wants the module somewhere else, in an extension or a
|
|
12
|
+
* Node thread or a bundle that inlines the bytes, writes these lines
|
|
13
|
+
* itself over {@link createEngine}.
|
|
14
|
+
*/
|
|
15
|
+
import { createEngine } from './engine.js';
|
|
16
|
+
const engine = createEngine();
|
|
17
|
+
self.onmessage = ({ data }) => {
|
|
18
|
+
// Requests reach the engine in the order they arrived: promise
|
|
19
|
+
// callbacks run in the order they were registered, which is the
|
|
20
|
+
// order the messages did.
|
|
21
|
+
void engine.then((ready) => ready.submit(data, (response, transfer) => self.postMessage(response, transfer)));
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;AAE9B,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC5B,+DAA+D;IAC/D,gEAAgE;IAChE,0BAA0B;IAC1B,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CACzB,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CACjF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fleuron",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Paged-media layout in a worker: markdown and CSS in, a display structure or PDF bytes out",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/zachhannum/fleuron.git",
|
|
9
|
+
"directory": "crates/fleuron-wasm/npm"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://fleuron.typeworks.dev/",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./worker": {
|
|
20
|
+
"types": "./dist/worker.d.ts",
|
|
21
|
+
"default": "./dist/worker.js"
|
|
22
|
+
},
|
|
23
|
+
"./fleuron_bg.wasm": "./wasm/fleuron_bg.wasm"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"wasm"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "node scripts/prepare.mjs && tsc -p tsconfig.json",
|
|
31
|
+
"build:test": "tsc -p tsconfig.test.json",
|
|
32
|
+
"test": "npm run build:test && node build/harness.js",
|
|
33
|
+
"size": "npm run build:test && node build/size.js",
|
|
34
|
+
"test:browser": "npm run build:test && node build/browser.js",
|
|
35
|
+
"test:package": "npm run build && npm run build:test && node build/consumer.js"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.15.3",
|
|
39
|
+
"playwright": "1.56.1",
|
|
40
|
+
"typescript": "^5.9.2"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=20"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A retained pipeline, held in the module between calls.
|
|
6
|
+
*
|
|
7
|
+
* The session keeps the content tree, the styling and every stage
|
|
8
|
+
* between them and the page, so a second render pays for what
|
|
9
|
+
* changed and not for the book. What the stages cost, and what
|
|
10
|
+
* survives which edit, is the engine's own contract.
|
|
11
|
+
*/
|
|
12
|
+
export class Session {
|
|
13
|
+
free(): void;
|
|
14
|
+
[Symbol.dispose](): void;
|
|
15
|
+
/**
|
|
16
|
+
* Registers a face from font bytes, and returns the ids it was
|
|
17
|
+
* registered under. A variable file names several cuts and
|
|
18
|
+
* yields one id each.
|
|
19
|
+
*
|
|
20
|
+
* The bytes stay in the module. A host sends a face once, not
|
|
21
|
+
* once per render.
|
|
22
|
+
*/
|
|
23
|
+
addFont(bytes: Uint8Array): Uint16Array;
|
|
24
|
+
/**
|
|
25
|
+
* Registers one image by the url the content tree names it by,
|
|
26
|
+
* and returns the index `DrawItem::Image.asset` will carry.
|
|
27
|
+
* `undefined` for bytes no probe recognises, which is a
|
|
28
|
+
* diagnostic on the next display structure and no image.
|
|
29
|
+
*
|
|
30
|
+
* The engine opens nothing, and a worker has nothing to open:
|
|
31
|
+
* the host fetches the file and hands the bytes over, as it does
|
|
32
|
+
* with a face. The bytes stay in the module, so an image crosses
|
|
33
|
+
* once rather than once per render.
|
|
34
|
+
*/
|
|
35
|
+
addImage(url: string, bytes: Uint8Array): number | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The same run as PDF bytes. Both painters read the stages the
|
|
38
|
+
* preview settled, so an export cannot contradict what is on
|
|
39
|
+
* screen.
|
|
40
|
+
*/
|
|
41
|
+
exportPdf(): Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* The file a face was registered from, for a painter that has
|
|
44
|
+
* to draw with the bytes the engine shaped with.
|
|
45
|
+
*
|
|
46
|
+
* The bundled face is the case that needs this: it is inside
|
|
47
|
+
* the module and there is no URL a host could fetch it from.
|
|
48
|
+
* A variable file answers for every cut it named, so the same
|
|
49
|
+
* bytes come back for each of them, and the face's variations
|
|
50
|
+
* on the display structure say which instance to draw.
|
|
51
|
+
*/
|
|
52
|
+
fontBytes(font_id: number): Uint8Array;
|
|
53
|
+
/**
|
|
54
|
+
* A session over the bundled face, with no content and the
|
|
55
|
+
* built-in sheet alone.
|
|
56
|
+
*/
|
|
57
|
+
constructor();
|
|
58
|
+
/**
|
|
59
|
+
* The display structure, postcard-encoded, version first.
|
|
60
|
+
*/
|
|
61
|
+
preview(): Uint8Array;
|
|
62
|
+
/**
|
|
63
|
+
* Drops every section that came from one source, and the
|
|
64
|
+
* complaints reading it raised.
|
|
65
|
+
*/
|
|
66
|
+
removeMarkdown(name: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Sets the book from a content tree, as JSON.
|
|
69
|
+
*
|
|
70
|
+
* Markdown is the way in; this is the door for a host with a
|
|
71
|
+
* structured source of its own. Node ids are the engine's and
|
|
72
|
+
* are assigned on the way in, so a tree built by hand needs
|
|
73
|
+
* none.
|
|
74
|
+
*/
|
|
75
|
+
setContent(json: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Which markdown the sources are written in: `commonmark`,
|
|
78
|
+
* `gfm` or `obsidian`.
|
|
79
|
+
*/
|
|
80
|
+
setDialect(dialect: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Reads one markdown source as the whole book, its frontmatter
|
|
83
|
+
* the book's metadata.
|
|
84
|
+
*
|
|
85
|
+
* Everything below box construction is invalidated: this is the
|
|
86
|
+
* manuscript arriving, not an edit to it.
|
|
87
|
+
*/
|
|
88
|
+
setMarkdown(name: string, text: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Names the book, from JSON: `title`, `author`, and an `extra`
|
|
91
|
+
* object for whatever else a frontend carries.
|
|
92
|
+
*
|
|
93
|
+
* A book read from several sources has no frontmatter of its
|
|
94
|
+
* own, so this is how it gets a title. Nothing between the
|
|
95
|
+
* content tree and the page reads metadata, so a book renamed
|
|
96
|
+
* between renders re-runs no stage; the PDF writer is the one
|
|
97
|
+
* thing that reads it.
|
|
98
|
+
*/
|
|
99
|
+
setMetadata(json: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Reads several markdown sources as one book, in the order
|
|
102
|
+
* given.
|
|
103
|
+
*
|
|
104
|
+
* A lone source is the whole book, so its frontmatter is the
|
|
105
|
+
* book's. Several are chapters: each file's frontmatter belongs
|
|
106
|
+
* to the section it became, and the book is left unnamed rather
|
|
107
|
+
* than named after whichever chapter came first, which is what
|
|
108
|
+
* [`Session::set_metadata`] is for.
|
|
109
|
+
*/
|
|
110
|
+
setSources(names: string[], texts: string[]): void;
|
|
111
|
+
/**
|
|
112
|
+
* Where a source's sections begin: at a heading of this level
|
|
113
|
+
* or shallower, or nowhere at all when the level is zero, which
|
|
114
|
+
* makes each file one section.
|
|
115
|
+
*
|
|
116
|
+
* Sections are what a page can start on, so this sets a book's
|
|
117
|
+
* page count before any styling does.
|
|
118
|
+
*/
|
|
119
|
+
setSplit(level: number): void;
|
|
120
|
+
/**
|
|
121
|
+
* Sets the author styling from CSS text, cascading over the
|
|
122
|
+
* built-in sheet.
|
|
123
|
+
*
|
|
124
|
+
* Which stages this costs is the change's own business: a
|
|
125
|
+
* colour repaints nothing, page geometry re-fragments over the
|
|
126
|
+
* lines already broken, and only the measure or the face breaks
|
|
127
|
+
* them again.
|
|
128
|
+
*/
|
|
129
|
+
setStyle(css: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* How many times each stage has run since the session was made,
|
|
132
|
+
* as `[style, lines, flow, paint]`.
|
|
133
|
+
*
|
|
134
|
+
* What an edit cost, said in stage runs rather than
|
|
135
|
+
* milliseconds: a host watching this can see a cache serve
|
|
136
|
+
* where a clock would only see a fast machine.
|
|
137
|
+
*/
|
|
138
|
+
stages(): Uint32Array;
|
|
139
|
+
/**
|
|
140
|
+
* Replaces every section that came from one source, reparsing
|
|
141
|
+
* that source alone. A name the book does not carry appends
|
|
142
|
+
* instead, which is how a file it has not seen before arrives.
|
|
143
|
+
*
|
|
144
|
+
* This is the keystroke path: one file crosses, one file is
|
|
145
|
+
* read, and every other section keeps the lines it already has.
|
|
146
|
+
*/
|
|
147
|
+
updateMarkdown(name: string, text: string): void;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* One markdown source and one stylesheet, laid out once: the batch
|
|
152
|
+
* case, over the same session a live preview keeps.
|
|
153
|
+
*/
|
|
154
|
+
export function render(markdown: string, css: string): Uint8Array;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The same, as PDF bytes.
|
|
158
|
+
*/
|
|
159
|
+
export function renderPdf(markdown: string, css: string): Uint8Array;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The version the display structure is encoded at. A host reads the same
|
|
163
|
+
* number off the front of every buffer and refuses one it does not
|
|
164
|
+
* know.
|
|
165
|
+
*/
|
|
166
|
+
export function wireVersion(): number;
|
|
167
|
+
|
|
168
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
169
|
+
|
|
170
|
+
export interface InitOutput {
|
|
171
|
+
readonly memory: WebAssembly.Memory;
|
|
172
|
+
readonly __wbg_session_free: (a: number, b: number) => void;
|
|
173
|
+
readonly render: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
174
|
+
readonly renderPdf: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
175
|
+
readonly session_addFont: (a: number, b: number, c: number) => [number, number, number, number];
|
|
176
|
+
readonly session_addImage: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
177
|
+
readonly session_exportPdf: (a: number) => [number, number, number, number];
|
|
178
|
+
readonly session_fontBytes: (a: number, b: number) => [number, number, number, number];
|
|
179
|
+
readonly session_new: () => [number, number, number];
|
|
180
|
+
readonly session_preview: (a: number) => [number, number, number, number];
|
|
181
|
+
readonly session_removeMarkdown: (a: number, b: number, c: number) => void;
|
|
182
|
+
readonly session_setContent: (a: number, b: number, c: number) => [number, number];
|
|
183
|
+
readonly session_setDialect: (a: number, b: number, c: number) => [number, number];
|
|
184
|
+
readonly session_setMarkdown: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
185
|
+
readonly session_setMetadata: (a: number, b: number, c: number) => [number, number];
|
|
186
|
+
readonly session_setSources: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
187
|
+
readonly session_setSplit: (a: number, b: number) => [number, number];
|
|
188
|
+
readonly session_setStyle: (a: number, b: number, c: number) => void;
|
|
189
|
+
readonly session_stages: (a: number) => [number, number];
|
|
190
|
+
readonly session_updateMarkdown: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
191
|
+
readonly wireVersion: () => number;
|
|
192
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
193
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
194
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
195
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
196
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
197
|
+
readonly __externref_table_alloc: () => number;
|
|
198
|
+
readonly __wbindgen_start: () => void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
205
|
+
* a precompiled `WebAssembly.Module`.
|
|
206
|
+
*
|
|
207
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
208
|
+
*
|
|
209
|
+
* @returns {InitOutput}
|
|
210
|
+
*/
|
|
211
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
215
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
216
|
+
*
|
|
217
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
218
|
+
*
|
|
219
|
+
* @returns {Promise<InitOutput>}
|
|
220
|
+
*/
|
|
221
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|