@paged-media/sdk 0.1.0-canary.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/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@paged-media/sdk",
3
+ "version": "0.1.0-canary.0",
4
+ "description": "WebGPU renderer-core ViewerSession (wasm) — the engine the @paged-media/idml-viewer wraps.",
5
+ "type": "module",
6
+ "main": "paged_sdk.js",
7
+ "types": "paged_sdk.d.ts",
8
+ "files": [
9
+ "paged_sdk.js",
10
+ "paged_sdk_bg.wasm",
11
+ "paged_sdk.d.ts"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/paged-media/core.git",
16
+ "directory": "crates/paged-sdk"
17
+ },
18
+ "license": "MPL-2.0 OR LicenseRef-PMEL"
19
+ }
package/paged_sdk.d.ts ADDED
@@ -0,0 +1,236 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Continuous-layout geometry for every page, so the TS wrapper
5
+ * computes fit / goToPage / currentPage / scroll extents without
6
+ * wasm round-trips. `y_pt` is the page top in doc space (vertical
7
+ * stack with `gap_pt` between pages — the same offsets
8
+ * `present()` uses).
9
+ */
10
+ export interface PagesLayout {
11
+ gapPt: number;
12
+ pages: PageRect[];
13
+ }
14
+
15
+ /**
16
+ * Stable page identity, independent of position in the page vector.
17
+ *
18
+ * Derived from the IDML `<Page Self=\"...\">` attribute where present;
19
+ * synthesised as `\"page-<spread_idx>-<local_idx>\"` when missing
20
+ * (older / synthetic fixtures without `Self`). The canvas keys
21
+ * display-list caches and LOD tiles by `PageId`, so the value must
22
+ * stay stable across re-layouts — only document-structural edits
23
+ * (insert/delete page) should ever change the set of `PageId`s.
24
+ */
25
+ export type PageId = string;
26
+
27
+ /**
28
+ * Structured, JSON-serialisable result of `load` / `render_*`. Unlike
29
+ * the legacy free functions, recoverable parse/layout problems are
30
+ * reported here (so the docs preview can surface them inline) rather
31
+ * than thrown as an opaque `JsError`.
32
+ */
33
+ export interface Diagnostics {
34
+ ok: boolean;
35
+ messages: Diagnostic[];
36
+ }
37
+
38
+ export interface Diagnostic {
39
+ /**
40
+ * `\"error\" | \"warning\" | \"info\"`.
41
+ */
42
+ severity: string;
43
+ /**
44
+ * Short machine code, e.g. `\"open\"`, `\"build\"`, `\"no_gpu\"`.
45
+ */
46
+ code: string;
47
+ message: string;
48
+ /**
49
+ * IDML part the problem originates from, when known.
50
+ */
51
+ part?: string;
52
+ line?: number;
53
+ }
54
+
55
+ export interface PageRect {
56
+ index: number;
57
+ yPt: number;
58
+ widthPt: number;
59
+ heightPt: number;
60
+ }
61
+
62
+
63
+ /**
64
+ * Headless readback result. `rgba` is tightly-packed RGBA8
65
+ * (`width * height * 4`), surfaced to JS as a `Uint8Array`.
66
+ */
67
+ export class RenderedRaster {
68
+ private constructor();
69
+ free(): void;
70
+ [Symbol.dispose](): void;
71
+ height: number;
72
+ rgba: Uint8Array;
73
+ width: number;
74
+ }
75
+
76
+ /**
77
+ * Renderer-core session. Holds the parsed+laid-out document and a
78
+ * lazily-created WebGPU presenter (device + surface). One per viewer
79
+ * instance / preview component.
80
+ */
81
+ export class ViewerSession {
82
+ private constructor();
83
+ free(): void;
84
+ [Symbol.dispose](): void;
85
+ /**
86
+ * Parse + build a complete IDML package. `font` is optional. Caches
87
+ * the built document and resets the current page to 0. Returns
88
+ * structured diagnostics; does not throw on recoverable problems.
89
+ */
90
+ load(idml: Uint8Array, font?: Uint8Array | null): Diagnostics;
91
+ /**
92
+ * Acquire the session, gating on WebGPU availability. Rejects when
93
+ * `navigator.gpu` is absent so the consumer can map that to the
94
+ * WebGPU-absent note. Exposed to JS as `ViewerSession.new()`
95
+ * returning a `Promise`.
96
+ */
97
+ static new(): Promise<ViewerSession>;
98
+ page_count(): number;
99
+ /**
100
+ * Continuous-layout page geometry (doc-space pt, vertical
101
+ * stack with `PAGE_GAP_PT` between pages). Empty until `load`
102
+ * succeeds. The TS wrapper derives fit zoom, scroll extents,
103
+ * `goToPage` targets and the current page from this — no
104
+ * per-frame wasm round-trips.
105
+ */
106
+ page_layout(): PagesLayout;
107
+ /**
108
+ * Camera-transformed present of the continuous page stack —
109
+ * the viewer's per-frame paint (ports the editor canvas's
110
+ * `presentFrame`). `zoom` is CSS px per pt; `scroll_x` /
111
+ * `scroll_y` place the doc origin in CSS px (positive moves
112
+ * content right/down); `dpr` brings CSS px to device px.
113
+ * Off-viewport pages are culled; per-page scenes build once
114
+ * and cache. `only_page` restricts the pass to one page laid
115
+ * out at y = 0 (the wrapper's `"single"` layout mode).
116
+ *
117
+ * Requires a bound presenter (any `render_to_canvas*` call
118
+ * binds one).
119
+ */
120
+ present(zoom: number, scroll_x: number, scroll_y: number, dpr: number, only_page?: number | null): Diagnostics;
121
+ /**
122
+ * Register a font for an IDML `AppliedFont` family (and optional
123
+ * style such as `"Bold"` / `"Italic"`). Accumulates across calls
124
+ * and is consulted on the next `load`; real documents reference
125
+ * many faces, so call this once per face before `load`. Mirrors
126
+ * the editor's `RegisterFont` and `paged-inspect`'s
127
+ * `--font-family "Family[/Style]=PATH"`.
128
+ */
129
+ register_font(family: string, style: string | null | undefined, bytes: Uint8Array): void;
130
+ /**
131
+ * Headless render of ONE page scaled to `target_width_px`
132
+ * (thumbnails / page strips). Aspect ratio preserved.
133
+ */
134
+ render_page_to_bytes(index: number, target_width_px: number): Promise<RenderedRaster>;
135
+ /**
136
+ * Headless path: render the current page off-surface and read it
137
+ * back as RGBA8 (replaces the legacy `render_to_png`). For
138
+ * screenshots / SSR. `dpi` controls resolution (72 = 1px per pt).
139
+ */
140
+ render_to_bytes(dpi: number): Promise<RenderedRaster>;
141
+ /**
142
+ * Present the current page to a worker-owned `OffscreenCanvas` via
143
+ * WebGPU. The presenter is created (bound to `canvas`) on the first
144
+ * call; later calls reuse it and re-present — pass the same canvas.
145
+ */
146
+ render_to_canvas(canvas: OffscreenCanvas): Promise<Diagnostics>;
147
+ /**
148
+ * Main-thread variant of [`Self::render_to_canvas`] for embedders
149
+ * that render on an `HtmlCanvasElement` instead of a worker
150
+ * `OffscreenCanvas`.
151
+ */
152
+ render_to_canvas_main(canvas: HTMLCanvasElement): Promise<Diagnostics>;
153
+ /**
154
+ * Resize the bound GPU surface. `width`/`height` are CSS pixels;
155
+ * `device_pixel_ratio` brings them to device pixels. No-op until a
156
+ * presenter exists.
157
+ */
158
+ resize(width: number, height: number, device_pixel_ratio: number): void;
159
+ set_page(index: number): void;
160
+ }
161
+
162
+ export function on_start(): void;
163
+
164
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
165
+
166
+ export interface InitOutput {
167
+ readonly memory: WebAssembly.Memory;
168
+ readonly __wbg_get_renderedraster_height: (a: number) => number;
169
+ readonly __wbg_get_renderedraster_rgba: (a: number) => [number, number];
170
+ readonly __wbg_get_renderedraster_width: (a: number) => number;
171
+ readonly __wbg_renderedraster_free: (a: number, b: number) => void;
172
+ readonly __wbg_set_renderedraster_height: (a: number, b: number) => void;
173
+ readonly __wbg_set_renderedraster_rgba: (a: number, b: number, c: number) => void;
174
+ readonly __wbg_set_renderedraster_width: (a: number, b: number) => void;
175
+ readonly __wbg_viewersession_free: (a: number, b: number) => void;
176
+ readonly viewersession_load: (a: number, b: number, c: number, d: number, e: number) => any;
177
+ readonly viewersession_new: () => any;
178
+ readonly viewersession_page_count: (a: number) => number;
179
+ readonly viewersession_page_layout: (a: number) => any;
180
+ readonly viewersession_present: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
181
+ readonly viewersession_register_font: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
182
+ readonly viewersession_render_page_to_bytes: (a: number, b: number, c: number) => any;
183
+ readonly viewersession_render_to_bytes: (a: number, b: number) => any;
184
+ readonly viewersession_render_to_canvas: (a: number, b: any) => any;
185
+ readonly viewersession_render_to_canvas_main: (a: number, b: any) => any;
186
+ readonly viewersession_resize: (a: number, b: number, c: number, d: number) => void;
187
+ readonly viewersession_set_page: (a: number, b: number) => void;
188
+ readonly on_start: () => void;
189
+ readonly qcms_enable_iccv4: () => void;
190
+ readonly qcms_profile_precache_output_transform: (a: number) => void;
191
+ readonly qcms_transform_data_bgra_out_lut: (a: number, b: number, c: number, d: number) => void;
192
+ readonly qcms_transform_data_bgra_out_lut_precache: (a: number, b: number, c: number, d: number) => void;
193
+ readonly qcms_transform_data_rgb_out_lut: (a: number, b: number, c: number, d: number) => void;
194
+ readonly qcms_transform_data_rgb_out_lut_precache: (a: number, b: number, c: number, d: number) => void;
195
+ readonly qcms_transform_data_rgba_out_lut: (a: number, b: number, c: number, d: number) => void;
196
+ readonly qcms_transform_data_rgba_out_lut_precache: (a: number, b: number, c: number, d: number) => void;
197
+ readonly qcms_transform_release: (a: number) => void;
198
+ readonly qcms_profile_is_bogus: (a: number) => number;
199
+ readonly qcms_white_point_sRGB: (a: number) => void;
200
+ readonly lut_inverse_interp16: (a: number, b: number, c: number) => number;
201
+ readonly lut_interp_linear16: (a: number, b: number, c: number) => number;
202
+ readonly wasm_bindgen__convert__closures_____invoke__hf764a550e1162210: (a: number, b: number, c: any) => [number, number];
203
+ readonly wasm_bindgen__convert__closures_____invoke__h341ac0c8ce0fce2e: (a: number, b: number, c: any, d: any) => void;
204
+ readonly wasm_bindgen__convert__closures_____invoke__h2c89ab360f192403: (a: number, b: number, c: any) => void;
205
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
206
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
207
+ readonly __wbindgen_exn_store: (a: number) => void;
208
+ readonly __externref_table_alloc: () => number;
209
+ readonly __wbindgen_externrefs: WebAssembly.Table;
210
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
211
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
212
+ readonly __externref_table_dealloc: (a: number) => void;
213
+ readonly __wbindgen_start: () => void;
214
+ }
215
+
216
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
217
+
218
+ /**
219
+ * Instantiates the given `module`, which can either be bytes or
220
+ * a precompiled `WebAssembly.Module`.
221
+ *
222
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
223
+ *
224
+ * @returns {InitOutput}
225
+ */
226
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
227
+
228
+ /**
229
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
230
+ * for everything else, calls `WebAssembly.instantiate` directly.
231
+ *
232
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
233
+ *
234
+ * @returns {Promise<InitOutput>}
235
+ */
236
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;