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.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * What crosses between a host and the worker the engine runs in.
3
+ *
4
+ * A request is an edit plus, sometimes, a render: inputs travel when
5
+ * they change rather than once per frame, and the module keeps every
6
+ * stage between them. Each request carries a generation, which the
7
+ * worker echoes back untouched. The host raises it whenever the
8
+ * input goes stale, and a reply that comes back behind the current
9
+ * one is dropped rather than painted.
10
+ */
11
+ /** Whether a reply carries bytes. */
12
+ export function isRendered(response) {
13
+ return 'bytes' in response;
14
+ }
15
+ /** Whether a reply is the engine reporting trouble. */
16
+ export function isFailed(response) {
17
+ return 'error' in response;
18
+ }
19
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkHH,qCAAqC;AACrC,MAAM,UAAU,UAAU,CAAC,QAAkB;IAC3C,OAAO,OAAO,IAAI,QAAQ,CAAC;AAC7B,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,QAAQ,CAAC,QAAkB;IACzC,OAAO,OAAO,IAAI,QAAQ,CAAC;AAC7B,CAAC"}
package/dist/svg.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The preview painter: one page of the display structure, as SVG.
3
+ *
4
+ * The engine has already shaped and broken the text, so the browser
5
+ * is given no room to do either. Every run is one `<text>` carrying
6
+ * an x for each character it holds, taken from the glyph the shaper
7
+ * put there, and the face is the file the engine shaped with, pinned
8
+ * to the instance it shaped at. A preview that disagrees with the
9
+ * export about where a glyph sits therefore has a bug here, and
10
+ * nowhere else.
11
+ *
12
+ * The coordinate system is the display structure's: points, origin top
13
+ * left, on a `viewBox` the size of the trim. Zoom is the width and
14
+ * height the element is given, and moves nothing inside it.
15
+ */
16
+ import type { Asset, FontRefEntry, Page } from './wire.js';
17
+ /** How a page is painted. */
18
+ export interface PaintOptions {
19
+ /** The run's font table: `LayoutOutput.fonts`. */
20
+ fonts?: FontRefEntry[];
21
+ /** The run's asset table: `LayoutOutput.assets`. */
22
+ assets?: Asset[];
23
+ /** Points to CSS pixels. 1 draws the page at its trim size. */
24
+ zoom?: number;
25
+ /** What the page is printed on; `null` leaves it transparent. */
26
+ paper?: string | null;
27
+ /** What it is printed in. */
28
+ ink?: string;
29
+ /**
30
+ * Where an image's pixels come from: any url an `<img>` would
31
+ * take, including a `blob:` or `data:` one, or nothing when the
32
+ * host cannot supply them.
33
+ *
34
+ * Called with the asset the display structure placed, so a host keyed
35
+ * on urls needs no index of its own. It is only ever called when
36
+ * {@link PaintOptions.assets} is given, since the index means
37
+ * nothing without the table it indexes.
38
+ */
39
+ asset?: (asset: Asset, index: number) => string | null | undefined;
40
+ }
41
+ /**
42
+ * What a face is registered as, so a painter and whoever loaded the
43
+ * bytes agree on the name.
44
+ *
45
+ * Per id rather than per family: a variable file names several cuts,
46
+ * and each is drawn at its own place on the axes.
47
+ */
48
+ export declare function faceFamily(fontId: number): string;
49
+ /**
50
+ * Paints one page, as an `<svg>` element's markup.
51
+ *
52
+ * A face that is not loaded falls through the stack to whatever the
53
+ * browser has, so a page whose fonts never arrived is set in the
54
+ * wrong face rather than left blank.
55
+ */
56
+ export declare function paintPage(page: Page, options?: PaintOptions): string;
57
+ //# sourceMappingURL=svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAY,YAAY,EAAa,IAAI,EAAsB,MAAM,WAAW,CAAC;AAEpG,6BAA6B;AAC7B,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,oDAAoD;IACpD,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,6BAA6B;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACpE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAgBxE"}
package/dist/svg.js ADDED
@@ -0,0 +1,210 @@
1
+ /**
2
+ * The preview painter: one page of the display structure, as SVG.
3
+ *
4
+ * The engine has already shaped and broken the text, so the browser
5
+ * is given no room to do either. Every run is one `<text>` carrying
6
+ * an x for each character it holds, taken from the glyph the shaper
7
+ * put there, and the face is the file the engine shaped with, pinned
8
+ * to the instance it shaped at. A preview that disagrees with the
9
+ * export about where a glyph sits therefore has a bug here, and
10
+ * nowhere else.
11
+ *
12
+ * The coordinate system is the display structure's: points, origin top
13
+ * left, on a `viewBox` the size of the trim. Zoom is the width and
14
+ * height the element is given, and moves nothing inside it.
15
+ */
16
+ /**
17
+ * What a face is registered as, so a painter and whoever loaded the
18
+ * bytes agree on the name.
19
+ *
20
+ * Per id rather than per family: a variable file names several cuts,
21
+ * and each is drawn at its own place on the axes.
22
+ */
23
+ export function faceFamily(fontId) {
24
+ return `fleuron-face-${fontId}`;
25
+ }
26
+ /**
27
+ * Paints one page, as an `<svg>` element's markup.
28
+ *
29
+ * A face that is not loaded falls through the stack to whatever the
30
+ * browser has, so a page whose fonts never arrived is set in the
31
+ * wrong face rather than left blank.
32
+ */
33
+ export function paintPage(page, options = {}) {
34
+ const zoom = options.zoom ?? 1;
35
+ const paper = options.paper === undefined ? '#ffffff' : options.paper;
36
+ const body = page.items.map((item) => paint(item, options)).join('');
37
+ const ground = paper === null
38
+ ? ''
39
+ : `<rect x="0" y="0" width="${num(page.width)}" height="${num(page.height)}" fill="${escape(paper)}"/>`;
40
+ return (`<svg xmlns="http://www.w3.org/2000/svg"` +
41
+ ` viewBox="0 0 ${num(page.width)} ${num(page.height)}"` +
42
+ ` width="${num(page.width * zoom)}" height="${num(page.height * zoom)}"` +
43
+ ` fill="${escape(options.ink ?? '#000000')}"` +
44
+ ` data-page="${page.number}" data-side="${page.side}">` +
45
+ `${ground}${body}</svg>`);
46
+ }
47
+ function paint(item, options) {
48
+ switch (item.kind) {
49
+ case 'text':
50
+ return text(item, options);
51
+ case 'rect':
52
+ return rect(item);
53
+ case 'image':
54
+ return image(item, options);
55
+ }
56
+ }
57
+ function text(item, options) {
58
+ const entry = options.fonts?.[item.fontId];
59
+ const xs = positions(item);
60
+ // Slope and weight are the face's own rather than the container's.
61
+ // A host element that happens to be bold would otherwise have the
62
+ // browser synthesise a second bold over a face that is already
63
+ // one, and a face that did not arrive would fall back upright.
64
+ return (`<text x="${xs.map(num).join(' ')}" y="${num(item.y)}"` +
65
+ ` font-family="${escape(stack(item.fontId, entry))}"` +
66
+ ` font-size="${num(item.size)}"` +
67
+ ` font-weight="${entry?.attributes.weight ?? 400}"` +
68
+ ` font-style="${entry?.attributes.italic === true ? 'italic' : 'normal'}"` +
69
+ ` style="${escape(style(entry))}" xml:space="preserve"` +
70
+ (entry === undefined ? ` data-missing-font="${item.fontId}"` : '') +
71
+ `>${escape(item.text)}</text>`);
72
+ }
73
+ function rect(item) {
74
+ return `<rect x="${num(item.x)}" y="${num(item.y)}" width="${num(item.w)}" height="${num(item.h)}"/>`;
75
+ }
76
+ /**
77
+ * A placed image. The pixels are the host's, and one it cannot
78
+ * supply is drawn as the box layout reserved for it rather than as
79
+ * nothing.
80
+ */
81
+ function image(item, options) {
82
+ const box = `x="${num(item.x)}" y="${num(item.y)}"` +
83
+ ` width="${num(item.w)}" height="${num(item.h)}"`;
84
+ const asset = options.assets?.[item.asset];
85
+ const href = asset === undefined ? undefined : options.asset?.(asset, item.asset);
86
+ return href === null || href === undefined
87
+ ? `<rect ${box} fill="none" stroke="currentColor" stroke-dasharray="3 3" data-missing-asset="${item.asset}"/>`
88
+ : `<image ${box} href="${escape(href)}" preserveAspectRatio="none"/>`;
89
+ }
90
+ /**
91
+ * The families a run is drawn in, best first: the file the engine
92
+ * shaped with, then whatever the reader has under the same name,
93
+ * then a generic.
94
+ */
95
+ function stack(fontId, entry) {
96
+ const names = [faceFamily(fontId), ...(entry === undefined ? [] : [entry.family])];
97
+ return [...names.map((name) => `"${name.replace(/["\\]/g, '')}"`), 'serif'].join(', ');
98
+ }
99
+ /**
100
+ * Where on its axes the face is drawn. A cut the file named is a
101
+ * location on that file, not a file of its own, so a painter that
102
+ * does not pin it draws the default weight for every one of them.
103
+ */
104
+ function style(entry) {
105
+ const settings = (entry?.variations ?? [])
106
+ .map((axis) => `"${axis.tag}" ${num(axis.value)}`)
107
+ .join(', ');
108
+ // Runs carry the spaces the line was justified around, and SVG
109
+ // collapses them by default, which would slide every character
110
+ // after the first space one position along the x list.
111
+ return `white-space: pre` + (settings === '' ? '' : `; font-variation-settings: ${settings}`);
112
+ }
113
+ /**
114
+ * An x for each character of a run, from the glyph the shaper placed
115
+ * there.
116
+ *
117
+ * SVG positions characters, and the display structure positions glyphs,
118
+ * so the run's text is the join between them: each glyph carries the
119
+ * byte range it stands for, and its x lands on the character that
120
+ * range starts at. A character inside a ligature's range has no
121
+ * glyph of its own and is spaced evenly across it, which is what the
122
+ * browser does with it in the one case it matters: when the face that
123
+ * arrived forms no ligature and draws the characters separately.
124
+ */
125
+ function positions(item) {
126
+ const starts = characters(item.text);
127
+ const index = new Map(starts.map((byte, at) => [byte, at]));
128
+ const xs = new Array(starts.length);
129
+ for (const glyph of item.glyphs) {
130
+ const at = index.get(glyph.range[0]);
131
+ if (at === undefined) {
132
+ continue;
133
+ }
134
+ const held = xs[at];
135
+ if (held === undefined || glyph.x < held) {
136
+ xs[at] = glyph.x;
137
+ }
138
+ }
139
+ return fill(xs, item.x);
140
+ }
141
+ /** The byte offset each character of a string begins at. */
142
+ function characters(text) {
143
+ const starts = [];
144
+ let byte = 0;
145
+ for (const character of text) {
146
+ starts.push(byte);
147
+ const code = character.codePointAt(0) ?? 0;
148
+ byte += code < 0x80 ? 1 : code < 0x800 ? 2 : code < 0x10000 ? 3 : 4;
149
+ }
150
+ return starts;
151
+ }
152
+ /**
153
+ * Closes the gaps a glyph-to-character mapping leaves: interior ones
154
+ * are spaced evenly, and a run of them at the end is dropped, since
155
+ * an x list may be shorter than the text and the browser advances
156
+ * the rest itself.
157
+ */
158
+ function fill(xs, left) {
159
+ // Where the next placed character is, read off in one pass
160
+ // backwards, so a long gap costs no more than a short one.
161
+ const ahead = new Array(xs.length);
162
+ let next = -1;
163
+ let last = -1;
164
+ for (let at = xs.length - 1; at >= 0; at -= 1) {
165
+ ahead[at] = next;
166
+ if (xs[at] !== undefined) {
167
+ next = at;
168
+ if (last === -1) {
169
+ last = at;
170
+ }
171
+ }
172
+ }
173
+ if (last === -1) {
174
+ return [left];
175
+ }
176
+ const out = [];
177
+ let held = left;
178
+ for (let at = 0; at <= last; at += 1) {
179
+ const x = xs[at];
180
+ const to = ahead[at] ?? -1;
181
+ held = x ?? held + ((xs[to] ?? held) - held) / (to - at + 1);
182
+ out.push(held);
183
+ }
184
+ return out;
185
+ }
186
+ /**
187
+ * The shortest decimal that reads back as the same 32-bit float.
188
+ *
189
+ * The display structure is `f32`, and printing one as the double it
190
+ * widened to writes seventeen digits of a number that only has
191
+ * seven. Both are the same position; only one of them is worth
192
+ * sending a page's worth of.
193
+ */
194
+ function num(value) {
195
+ for (let digits = 0; digits <= 8; digits += 1) {
196
+ const text = value.toFixed(digits);
197
+ if (Math.fround(Number(text)) === Math.fround(value)) {
198
+ return digits === 0 ? text : text.replace(/\.?0+$/, '');
199
+ }
200
+ }
201
+ return String(value);
202
+ }
203
+ function escape(text) {
204
+ return text
205
+ .replace(/&/g, '&amp;')
206
+ .replace(/</g, '&lt;')
207
+ .replace(/>/g, '&gt;')
208
+ .replace(/"/g, '&quot;');
209
+ }
210
+ //# sourceMappingURL=svg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg.js","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA6BH;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,OAAO,gBAAgB,MAAM,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,IAAU,EAAE,UAAwB,EAAE;IAC9D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACtE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrE,MAAM,MAAM,GACV,KAAK,KAAK,IAAI;QACZ,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,4BAA4B,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;IAC5G,OAAO,CACL,yCAAyC;QACzC,iBAAiB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG;QACvD,WAAW,GAAG,CAAC,IAAI,CAAC,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GAAG,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,OAAO,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,IAAI;SACR,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * What this package is, so a bug report names the build without
3
+ * anyone opening `node_modules`. It is the version of the engine the
4
+ * module was built from as well: the workspace and both packages
5
+ * release together.
6
+ */
7
+ export declare const VERSION = "0.1.0";
8
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,OAAO,UAAU,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * What this package is, so a bug report names the build without
3
+ * anyone opening `node_modules`. It is the version of the engine the
4
+ * module was built from as well: the workspace and both packages
5
+ * release together.
6
+ */
7
+ export const VERSION = '0.1.0';
8
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
package/dist/wire.d.ts ADDED
@@ -0,0 +1,179 @@
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 declare const WIRE_VERSION = 4;
12
+ /** Which side of the spread a page falls on. */
13
+ export type Side = 'recto' | 'verso';
14
+ /** One glyph: an id in its font, an absolute x, and the text it stands for. */
15
+ export interface Glyph {
16
+ /** Glyph id in the run's font. */
17
+ id: number;
18
+ /** Absolute x of the glyph's origin, in points. */
19
+ x: number;
20
+ /** Byte range in the run's text this glyph came from. */
21
+ range: [number, number];
22
+ }
23
+ /** A run of shaped glyphs sharing a font, a size and a baseline. */
24
+ export interface TextItem {
25
+ kind: 'text';
26
+ /** Left edge of the run. */
27
+ x: number;
28
+ /** The run's baseline. */
29
+ y: number;
30
+ /** Index into {@link LayoutOutput.fonts}. */
31
+ fontId: number;
32
+ /** Em size in points. */
33
+ size: number;
34
+ /**
35
+ * The text the glyphs were shaped from. Only the shaper knew which
36
+ * glyph came from which character, so the correspondence travels
37
+ * with them: selection, copy-and-paste and accessible text read it
38
+ * through each glyph's range.
39
+ */
40
+ text: string;
41
+ /** The glyphs, in visual order. */
42
+ glyphs: Glyph[];
43
+ }
44
+ /** A filled rectangle: rules, borders, backgrounds. */
45
+ export interface RectItem {
46
+ kind: 'rect';
47
+ /** Left edge. */
48
+ x: number;
49
+ /** Top edge. */
50
+ y: number;
51
+ /** Width in points. */
52
+ w: number;
53
+ /** Height in points. */
54
+ h: number;
55
+ }
56
+ /** An image's own idea of its size, from its header. */
57
+ export interface Intrinsic {
58
+ /** Width in pixels. */
59
+ width: number;
60
+ /** Height in pixels. */
61
+ height: number;
62
+ /** Horizontal resolution in pixels per inch. */
63
+ dpiX: number;
64
+ /** Vertical resolution in pixels per inch. */
65
+ dpiY: number;
66
+ }
67
+ /**
68
+ * One image the book placed, as {@link ImageItem.asset} indexes it.
69
+ *
70
+ * All the display structure says about an image: layout read the header
71
+ * and decoded nothing, so a painter takes the url back to its own
72
+ * pixels.
73
+ */
74
+ export interface Asset {
75
+ /** The url the content tree named it by. */
76
+ url: string;
77
+ /** What the header says it is. */
78
+ intrinsic: Intrinsic;
79
+ }
80
+ /** A placed image. Layout never decoded it; the painter does. */
81
+ export interface ImageItem {
82
+ kind: 'image';
83
+ /** Left edge. */
84
+ x: number;
85
+ /** Top edge. */
86
+ y: number;
87
+ /** Width in points. */
88
+ w: number;
89
+ /** Height in points. */
90
+ h: number;
91
+ /** Index into {@link LayoutOutput.assets}. */
92
+ asset: number;
93
+ }
94
+ /** A single paint operation. */
95
+ export type DrawItem = TextItem | RectItem | ImageItem;
96
+ /** One typeset page, and what to paint on it. */
97
+ export interface Page {
98
+ /** Folio, counting from 1. */
99
+ number: number;
100
+ /** Which side of the spread this page falls on. */
101
+ side: Side;
102
+ /** Trimmed page width in points. */
103
+ width: number;
104
+ /** Trimmed page height in points. */
105
+ height: number;
106
+ /**
107
+ * The content-tree node ids of the sections this page holds content
108
+ * from, in the order their content appears on it. A chapter that
109
+ * ends mid-page is followed there by the next one opening, so the
110
+ * page names both. A blank leaf names none.
111
+ */
112
+ sections: number[];
113
+ /** What to paint, in paint order. */
114
+ items: DrawItem[];
115
+ }
116
+ /** One axis of a variable face, pinned. */
117
+ export interface AxisSetting {
118
+ /** The four-character OpenType axis tag, e.g. `wght`. */
119
+ tag: string;
120
+ /** The coordinate in the axis's own units. */
121
+ value: number;
122
+ }
123
+ /** The slope and weight a face answers for. */
124
+ export interface FaceAttributes {
125
+ /** True for italic and oblique alike. */
126
+ italic: boolean;
127
+ /** Weight on the CSS 1–1000 scale. */
128
+ weight: number;
129
+ }
130
+ /** A font's identity, as the display structure indexes it. */
131
+ export interface FontRefEntry {
132
+ /** Family for matching, lowercase. */
133
+ family: string;
134
+ /** Face name. */
135
+ name: string;
136
+ /** Style name. */
137
+ style: string;
138
+ /** What this face answers for. */
139
+ attributes: FaceAttributes;
140
+ /**
141
+ * Where on its file's axes this face sits, in user space. Empty
142
+ * for a static face and for a variable one at its default
143
+ * location. A painter pins these axes and draws the cut the run
144
+ * was shaped at rather than the file's default.
145
+ */
146
+ variations: AxisSetting[];
147
+ }
148
+ /** A book that laid out anyway, and what it had to complain about. */
149
+ export interface Warning {
150
+ /** What went wrong, in one line. */
151
+ message: string;
152
+ /** Where it was written, when the engine knows. */
153
+ origin: string | null;
154
+ }
155
+ /** Everything one run produced: pages, the fonts they index, diagnostics. */
156
+ export interface LayoutOutput {
157
+ /** The typeset pages, in reading order. */
158
+ pages: Page[];
159
+ /** The fonts this run used, indexed by `fontId`. */
160
+ fonts: FontRefEntry[];
161
+ /** The images this run placed, indexed by `ImageItem.asset`. */
162
+ assets: Asset[];
163
+ /** Everything the run had to complain about. */
164
+ warnings: Warning[];
165
+ }
166
+ /** A buffer this reader will not read, and why. */
167
+ export declare class WireError extends Error {
168
+ constructor(message: string);
169
+ }
170
+ /**
171
+ * The version a buffer leads with, without reading the rest of it.
172
+ */
173
+ export declare function wireVersionOf(bytes: Uint8Array): number;
174
+ /**
175
+ * Reads a display structure, refusing a version this reader does not know
176
+ * rather than painting whatever the bytes happen to decode to.
177
+ */
178
+ export declare function decodeDisplayList(bytes: Uint8Array): LayoutOutput;
179
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,4CAA4C;AAC5C,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B,gDAAgD;AAChD,MAAM,MAAM,IAAI,GAAG,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