hephaestus-wasm 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.
@@ -0,0 +1,205 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * One document bound to one canvas.
6
+ *
7
+ * The low-level binding. A page normally uses the `PlotView` class in
8
+ * `js/hephaestus.js`, which owns the resize and color-scheme wiring and
9
+ * calls through to this.
10
+ */
11
+ export class PlotHandle {
12
+ private constructor();
13
+ free(): void;
14
+ [Symbol.dispose](): void;
15
+ /**
16
+ * Read `doc` and attach it to `canvas`.
17
+ *
18
+ * Awaits GPU adapter and device acquisition, which a browser cannot do
19
+ * synchronously. Fails if the document is unreadable or if no WebGPU
20
+ * adapter is available — see [`is_supported`].
21
+ *
22
+ * `picking` allocates a second render target and reads it back after
23
+ * every frame, so it stays off unless [`Self::pick_at`] is going to be
24
+ * called.
25
+ */
26
+ static create(canvas: HTMLCanvasElement, doc: Uint8Array, picking: boolean): Promise<PlotHandle>;
27
+ /**
28
+ * Dots per inch the document's writer rendered at, if it recorded one.
29
+ */
30
+ hintDpi(): number | undefined;
31
+ /**
32
+ * Height, in points, the document's writer rendered at, if it recorded one.
33
+ */
34
+ hintHeight(): number | undefined;
35
+ /**
36
+ * Width, in points, the document's writer rendered at, if it recorded one.
37
+ *
38
+ * Advisory — a document can be drawn at any size. Useful as an aspect
39
+ * ratio for a container that has to be sized before anything is laid out.
40
+ */
41
+ hintWidth(): number | undefined;
42
+ /**
43
+ * Whether the inverted theme is in use.
44
+ */
45
+ isDark(): boolean;
46
+ /**
47
+ * The row id under a point, or `undefined` for empty space.
48
+ *
49
+ * Coordinates are device pixels — the canvas backing store, not CSS
50
+ * pixels, so scale a pointer event by the device pixel ratio. Always
51
+ * `undefined` unless `picking` was passed to [`Self::create`].
52
+ *
53
+ * The readback is never waited on, so this can answer from a frame or
54
+ * two ago. That is invisible for hover and is what keeps the call off
55
+ * the main thread's critical path.
56
+ */
57
+ pickAt(x: number, y: number): number | undefined;
58
+ /**
59
+ * Draw one frame at the current size.
60
+ */
61
+ render(): void;
62
+ /**
63
+ * Resize the drawing surface.
64
+ *
65
+ * `width` and `height` are device pixels — a CSS box times the device
66
+ * pixel ratio — and `ratio` is that same ratio, which sets the dpi so
67
+ * theme lengths in points come out the right physical size. Does not
68
+ * draw; call [`Self::render`] after.
69
+ */
70
+ resize(width: number, height: number, ratio: number): void;
71
+ /**
72
+ * Switch between the document's theme and its inverted form.
73
+ *
74
+ * Inversion swaps the palette's paper and ink anchors, which every
75
+ * chrome element references, so gridlines, axis text and titles all
76
+ * follow. A geom given an explicit color keeps it — marks adapt only
77
+ * when the plot expressed them as palette references.
78
+ *
79
+ * Does not draw; call [`Self::render`] after.
80
+ */
81
+ setDark(dark: boolean): void;
82
+ }
83
+
84
+ /**
85
+ * Major version of the plot-document format this build reads.
86
+ *
87
+ * A document whose major differs is refused outright — the check is equality,
88
+ * not a floor — so a site and whatever writes its documents have to agree on
89
+ * this number. Publish it alongside the bundle and assert on it in a build
90
+ * step: nothing at runtime can recover from a mismatch, and the failure is a
91
+ * plot that never appears.
92
+ */
93
+ export function documentFormatVersion(): number;
94
+
95
+ /**
96
+ * Whether any font family is available to shape with.
97
+ *
98
+ * A browser starts with none, so this answers "does this page still need a
99
+ * font?" — and it answers it after a document has been read, so a document
100
+ * carrying embedded faces counts. That is what lets a fallback be fetched
101
+ * only when it is genuinely needed rather than on a guess.
102
+ */
103
+ export function hasFonts(): boolean;
104
+
105
+ /**
106
+ * Whether this browser can run the renderer at all.
107
+ *
108
+ * What it tests depends on which backend was built. The wgpu build rasterises
109
+ * through compute pipelines, so WebGPU is a hard requirement rather than a
110
+ * preference. The WebGL2 build needs only a WebGL2 context, which is available
111
+ * essentially everywhere — so it is very nearly always `true`, and the check
112
+ * is kept so a page can use one code path for either bundle.
113
+ *
114
+ * A page should check this before creating a view and fall back to a static
115
+ * image when it is `false`.
116
+ */
117
+ export function isSupported(): boolean;
118
+
119
+ /**
120
+ * Register every font face in `bytes`, returning the family names they
121
+ * landed under.
122
+ *
123
+ * A browser starts with no fonts at all — nothing enumerates a system font
124
+ * set — so a page that registers none renders chrome with no text. Call
125
+ * this before creating any view: the first thing a document decodes is its
126
+ * theme, and that is enough to shape.
127
+ *
128
+ * Registration is process-global and permanent, so one call serves every
129
+ * view on the page for the lifetime of the module.
130
+ *
131
+ * The family names are the point of the return value: [`set_generic_family`]
132
+ * takes names, and the only place a family's name exists is inside the file,
133
+ * so a caller cannot pair the two without being told. Guessing from a
134
+ * filename does not survive contact with a real font.
135
+ *
136
+ * Accepts TTF, OTF, TTC, OTC and — with the `webfonts` feature, on by
137
+ * default — WOFF and WOFF2, which are unwrapped to the sfnt inside first.
138
+ * A blob holding no recognisable face is an error rather than an empty
139
+ * list, since registering nothing silently would render a textless plot
140
+ * with no indication why.
141
+ */
142
+ export function registerFont(bytes: Uint8Array): string[];
143
+
144
+ /**
145
+ * Point a generic family at concrete families already registered.
146
+ *
147
+ * `kind` is one of `serif`, `sans-serif`, `monospace`, `cursive`,
148
+ * `fantasy`, `system-ui`. A generic is an indirection through the font
149
+ * context rather than a name, so registering a font is not enough on its
150
+ * own — a theme asking for `sans-serif` resolves to nothing until this
151
+ * says what `sans-serif` means here. Call it after [`register_font`], since
152
+ * names that aren't registered are skipped.
153
+ */
154
+ export function setGenericFamily(kind: string, families: string[]): void;
155
+
156
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
157
+
158
+ export interface InitOutput {
159
+ readonly memory: WebAssembly.Memory;
160
+ readonly __wbg_plothandle_free: (a: number, b: number) => void;
161
+ readonly documentFormatVersion: () => number;
162
+ readonly hasFonts: () => number;
163
+ readonly isSupported: () => number;
164
+ readonly plothandle_create: (a: number, b: number, c: number, d: number) => number;
165
+ readonly plothandle_hintDpi: (a: number, b: number) => void;
166
+ readonly plothandle_hintHeight: (a: number, b: number) => void;
167
+ readonly plothandle_hintWidth: (a: number, b: number) => void;
168
+ readonly plothandle_isDark: (a: number) => number;
169
+ readonly plothandle_pickAt: (a: number, b: number, c: number) => number;
170
+ readonly plothandle_render: (a: number, b: number) => void;
171
+ readonly plothandle_resize: (a: number, b: number, c: number, d: number) => void;
172
+ readonly plothandle_setDark: (a: number, b: number) => void;
173
+ readonly registerFont: (a: number, b: number, c: number) => void;
174
+ readonly setGenericFamily: (a: number, b: number, c: number, d: number, e: number) => void;
175
+ readonly __wasm_bindgen_func_elem_4214: (a: number, b: number, c: number, d: number) => void;
176
+ readonly __wasm_bindgen_func_elem_4273: (a: number, b: number, c: number, d: number) => void;
177
+ readonly __wbindgen_export: (a: number, b: number) => number;
178
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
179
+ readonly __wbindgen_export3: (a: number) => void;
180
+ readonly __wbindgen_export4: (a: number, b: number) => void;
181
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
182
+ readonly __wbindgen_export5: (a: number, b: number, c: number) => void;
183
+ }
184
+
185
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
186
+
187
+ /**
188
+ * Instantiates the given `module`, which can either be bytes or
189
+ * a precompiled `WebAssembly.Module`.
190
+ *
191
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
192
+ *
193
+ * @returns {InitOutput}
194
+ */
195
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
196
+
197
+ /**
198
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
199
+ * for everything else, calls `WebAssembly.instantiate` directly.
200
+ *
201
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
202
+ *
203
+ * @returns {Promise<InitOutput>}
204
+ */
205
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;