@otisk/preview 1.1.1 → 1.1.2
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 +3 -7
- package/engine_wasm.d.ts +7 -98
- package/engine_wasm.js +7 -115
- package/engine_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,8 +7,9 @@ the preview shares the **same layout engine** as otisk's PDF output, so what
|
|
|
7
7
|
you see on screen matches the print geometry pixel-for-pixel; only the
|
|
8
8
|
rasteriser differs (tiny-skia here, the press RIP for the PDF).
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
generate
|
|
10
|
+
This package is **preview-only**: it renders pages to bitmaps for on-screen
|
|
11
|
+
display. It does not generate PDFs — produce the final PDF/X-4 on your
|
|
12
|
+
backend with the otisk engine, from the same `(html, css)` you previewed.
|
|
12
13
|
|
|
13
14
|
```
|
|
14
15
|
npm i @otisk/preview
|
|
@@ -63,11 +64,6 @@ out-of-range page, or degenerate dimensions.
|
|
|
63
64
|
|
|
64
65
|
How many pages the `(html, css)` pair lays out — for preview navigation.
|
|
65
66
|
|
|
66
|
-
### `render_pdf(html, css, marginMm, assets?, outputIntent?) → Uint8Array`
|
|
67
|
-
|
|
68
|
-
Render the whole document to a PDF (the production print artefact). Same
|
|
69
|
-
inputs as the preview, so the PDF matches what you previewed.
|
|
70
|
-
|
|
71
67
|
### `RasterResult`
|
|
72
68
|
|
|
73
69
|
| Member | Type | Notes |
|
package/engine_wasm.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export class RasterResult {
|
|
|
36
36
|
*
|
|
37
37
|
* # Errors
|
|
38
38
|
*
|
|
39
|
-
*
|
|
39
|
+
* A stringified [`otisk::RenderError`] via `JsValue::from_str`.
|
|
40
40
|
*/
|
|
41
41
|
export function page_count(html: string, css: string, margin_mm: number, assets?: any | null, output_intent?: any | null): number;
|
|
42
42
|
|
|
@@ -44,11 +44,10 @@ export function page_count(html: string, css: string, margin_mm: number, assets?
|
|
|
44
44
|
* Issue 297 — render one page of an `(html, css)` pair to an RGBA8
|
|
45
45
|
* bitmap for an HTML5-canvas print preview.
|
|
46
46
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* buffer.
|
|
47
|
+
* Takes the same `(html, css, margin_mm, assets?, output_intent?)`
|
|
48
|
+
* inputs the engine's PDF path uses, plus `page_index` (0-based) +
|
|
49
|
+
* `scale` (pixels-per-point, `scale = dpi / 72`). The returned
|
|
50
|
+
* [`RasterResult`] carries the device dimensions + the RGBA buffer.
|
|
52
51
|
*
|
|
53
52
|
* Because the preview reuses the **same** layout the PDF path produces,
|
|
54
53
|
* it is guaranteed to match print geometry; only the rasteriser differs
|
|
@@ -56,100 +55,11 @@ export function page_count(html: string, css: string, margin_mm: number, assets?
|
|
|
56
55
|
*
|
|
57
56
|
* # Errors
|
|
58
57
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* degenerate device dimensions.
|
|
58
|
+
* A stringified [`otisk::RenderError`] via `JsValue::from_str`, plus an
|
|
59
|
+
* out-of-range `page_index` or degenerate device dimensions.
|
|
62
60
|
*/
|
|
63
61
|
export function render_page_rgba(html: string, css: string, margin_mm: number, assets: any | null | undefined, output_intent: any | null | undefined, page_index: number, scale: number): RasterResult;
|
|
64
62
|
|
|
65
|
-
/**
|
|
66
|
-
* Render an `(html, css)` pair to a PDF/X-4 byte buffer.
|
|
67
|
-
*
|
|
68
|
-
* Thin shim over [`otisk::Engine`]: builds an engine with `margin_mm`
|
|
69
|
-
* applied uniformly to all four sides (see
|
|
70
|
-
* [`otisk::EngineBuilder::with_margins_mm`]), then forwards to
|
|
71
|
-
* [`otisk::Engine::render`] and returns [`otisk::RenderResult::bytes`].
|
|
72
|
-
*
|
|
73
|
-
* ## Optional asset resolver (Issue 115)
|
|
74
|
-
*
|
|
75
|
-
* The `assets` parameter is **optional**. wasm-bindgen surfaces it as
|
|
76
|
-
* a fourth positional argument that the JS caller may omit (older
|
|
77
|
-
* 3-arg call sites — `render_pdf(html, css, margin)` — keep working
|
|
78
|
-
* unchanged) or pass as `null` / `undefined` for the same behaviour.
|
|
79
|
-
* When `assets` is present it must be either:
|
|
80
|
-
*
|
|
81
|
-
* - a bare callable: `function(url: string): Uint8Array`, or
|
|
82
|
-
* - an object with the spec'd shape: `{ fetch(url: string): Uint8Array }`.
|
|
83
|
-
*
|
|
84
|
-
* Every engine-side asset lookup (`@font-face`, `<img>`,
|
|
85
|
-
* `background-image`, and — Phase 4 — `@color-profile`) is funneled
|
|
86
|
-
* through that callable. If `assets.fetch` returns a non-`Uint8Array`
|
|
87
|
-
* value, throws, or the method doesn't exist, the render fails with
|
|
88
|
-
* [`otisk::FetchError`] surfaced through the usual
|
|
89
|
-
* `JsValue`-stringified error channel.
|
|
90
|
-
*
|
|
91
|
-
* ### Why synchronous
|
|
92
|
-
*
|
|
93
|
-
* The native [`otisk::AssetResolver::fetch`] signature is synchronous
|
|
94
|
-
* (`SPECIFICATION.md` §3.7); the engine never spins up an async
|
|
95
|
-
* runtime to fetch an asset. Mirroring that on the JS side keeps the
|
|
96
|
-
* byte-identity contract trivial — every fetch returns bytes
|
|
97
|
-
* immediately, with the same byte-for-byte semantics on both sides.
|
|
98
|
-
* A `Promise<Uint8Array>` arm would either (a) require an async
|
|
99
|
-
* engine entry point — out of scope for this issue — or (b) demand
|
|
100
|
-
* host-side blocking that the browser doesn't permit on the main
|
|
101
|
-
* thread. The simpler synchronous arm is the load-bearing acceptance
|
|
102
|
-
* criterion (byte-identical parity for `font_face_load`,
|
|
103
|
-
* `image_embed`, `background_image`) and an async overload can ride
|
|
104
|
-
* on top of it later.
|
|
105
|
-
*
|
|
106
|
-
* ## Optional output intent (Issue 116)
|
|
107
|
-
*
|
|
108
|
-
* The `output_intent` parameter is **optional**. wasm-bindgen surfaces it
|
|
109
|
-
* as a fifth positional argument that the JS caller may omit (older
|
|
110
|
-
* 3-arg / 4-arg call sites keep working unchanged) or pass as `null` /
|
|
111
|
-
* `undefined` for the same default behaviour. When `output_intent` is
|
|
112
|
-
* present it must be a UTF-8 string naming a known
|
|
113
|
-
* [`otisk::ColorProfile`] variant — see [`parse_color_profile`] for the
|
|
114
|
-
* accepted spellings (`"srgb"`, `"fogra39"`, `"swop_v2"`,
|
|
115
|
-
* case-insensitive). An unknown string surfaces as the usual
|
|
116
|
-
* `JsValue`-stringified error so the JS caller can react.
|
|
117
|
-
*
|
|
118
|
-
* ## Diagnostics
|
|
119
|
-
*
|
|
120
|
-
* Diagnostics from the render are intentionally dropped on this entry
|
|
121
|
-
* point — the spec deliberately keeps the WASM surface minimal
|
|
122
|
-
* (Issue 30 §"Out of scope"). A richer entry point returning
|
|
123
|
-
* `{ bytes, diagnostics }` is deferred to a future issue once the
|
|
124
|
-
* parity harness has a concrete need for it.
|
|
125
|
-
*
|
|
126
|
-
* # Errors
|
|
127
|
-
*
|
|
128
|
-
* On any failure inside the pipeline ([`otisk::RenderError`] — HTML/CSS
|
|
129
|
-
* parse errors, layout failures, missing fonts, PDF emit errors, or
|
|
130
|
-
* resource-limit breaches), any failure inside the JS-side
|
|
131
|
-
* resolver, or an unrecognised `output_intent` string, the error is
|
|
132
|
-
* stringified via its `Display` impl and returned as a
|
|
133
|
-
* `JsValue::from_str`. JS sees a plain string error message; richer
|
|
134
|
-
* error objects can land alongside the diagnostic surface later.
|
|
135
|
-
*
|
|
136
|
-
* # Parameters
|
|
137
|
-
*
|
|
138
|
-
* - `html`: the input HTML source as a UTF-8 string.
|
|
139
|
-
* - `css`: the matching CSS source (currently the only style input — the
|
|
140
|
-
* engine has no `<style>` / `<link rel="stylesheet">` extraction yet).
|
|
141
|
-
* - `margin_mm`: uniform page margin applied to all four sides.
|
|
142
|
-
* - `assets` *(optional)*: a `{ fetch(url): Uint8Array }` object or a
|
|
143
|
-
* bare `(url) -> Uint8Array` callable; pass `null` / `undefined` /
|
|
144
|
-
* omit entirely for the empty-resolver baseline (byte-identical to
|
|
145
|
-
* the pre-Issue-115 3-arg call).
|
|
146
|
-
* - `output_intent` *(optional)*: a UTF-8 string naming a known
|
|
147
|
-
* [`otisk::ColorProfile`] variant (`"srgb"`, `"fogra39"`,
|
|
148
|
-
* `"swop_v2"`); pass `null` / `undefined` / omit entirely to keep
|
|
149
|
-
* the engine's default profile ([`ColorProfile::default`] — sRGB).
|
|
150
|
-
*/
|
|
151
|
-
export function render_pdf(html: string, css: string, margin_mm: number, assets?: any | null, output_intent?: any | null): Uint8Array;
|
|
152
|
-
|
|
153
63
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
154
64
|
|
|
155
65
|
export interface InitOutput {
|
|
@@ -160,7 +70,6 @@ export interface InitOutput {
|
|
|
160
70
|
readonly rasterresult_rgba: (a: number) => [number, number];
|
|
161
71
|
readonly rasterresult_width: (a: number) => number;
|
|
162
72
|
readonly render_page_rgba: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number, number];
|
|
163
|
-
readonly render_pdf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
164
73
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
165
74
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
166
75
|
readonly __wbindgen_exn_store: (a: number) => void;
|
package/engine_wasm.js
CHANGED
|
@@ -63,7 +63,7 @@ if (Symbol.dispose) RasterResult.prototype[Symbol.dispose] = RasterResult.protot
|
|
|
63
63
|
*
|
|
64
64
|
* # Errors
|
|
65
65
|
*
|
|
66
|
-
*
|
|
66
|
+
* A stringified [`otisk::RenderError`] via `JsValue::from_str`.
|
|
67
67
|
* @param {string} html
|
|
68
68
|
* @param {string} css
|
|
69
69
|
* @param {number} margin_mm
|
|
@@ -87,11 +87,10 @@ export function page_count(html, css, margin_mm, assets, output_intent) {
|
|
|
87
87
|
* Issue 297 — render one page of an `(html, css)` pair to an RGBA8
|
|
88
88
|
* bitmap for an HTML5-canvas print preview.
|
|
89
89
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* buffer.
|
|
90
|
+
* Takes the same `(html, css, margin_mm, assets?, output_intent?)`
|
|
91
|
+
* inputs the engine's PDF path uses, plus `page_index` (0-based) +
|
|
92
|
+
* `scale` (pixels-per-point, `scale = dpi / 72`). The returned
|
|
93
|
+
* [`RasterResult`] carries the device dimensions + the RGBA buffer.
|
|
95
94
|
*
|
|
96
95
|
* Because the preview reuses the **same** layout the PDF path produces,
|
|
97
96
|
* it is guaranteed to match print geometry; only the rasteriser differs
|
|
@@ -99,9 +98,8 @@ export function page_count(html, css, margin_mm, assets, output_intent) {
|
|
|
99
98
|
*
|
|
100
99
|
* # Errors
|
|
101
100
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* degenerate device dimensions.
|
|
101
|
+
* A stringified [`otisk::RenderError`] via `JsValue::from_str`, plus an
|
|
102
|
+
* out-of-range `page_index` or degenerate device dimensions.
|
|
105
103
|
* @param {string} html
|
|
106
104
|
* @param {string} css
|
|
107
105
|
* @param {number} margin_mm
|
|
@@ -122,112 +120,6 @@ export function render_page_rgba(html, css, margin_mm, assets, output_intent, pa
|
|
|
122
120
|
}
|
|
123
121
|
return RasterResult.__wrap(ret[0]);
|
|
124
122
|
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Render an `(html, css)` pair to a PDF/X-4 byte buffer.
|
|
128
|
-
*
|
|
129
|
-
* Thin shim over [`otisk::Engine`]: builds an engine with `margin_mm`
|
|
130
|
-
* applied uniformly to all four sides (see
|
|
131
|
-
* [`otisk::EngineBuilder::with_margins_mm`]), then forwards to
|
|
132
|
-
* [`otisk::Engine::render`] and returns [`otisk::RenderResult::bytes`].
|
|
133
|
-
*
|
|
134
|
-
* ## Optional asset resolver (Issue 115)
|
|
135
|
-
*
|
|
136
|
-
* The `assets` parameter is **optional**. wasm-bindgen surfaces it as
|
|
137
|
-
* a fourth positional argument that the JS caller may omit (older
|
|
138
|
-
* 3-arg call sites — `render_pdf(html, css, margin)` — keep working
|
|
139
|
-
* unchanged) or pass as `null` / `undefined` for the same behaviour.
|
|
140
|
-
* When `assets` is present it must be either:
|
|
141
|
-
*
|
|
142
|
-
* - a bare callable: `function(url: string): Uint8Array`, or
|
|
143
|
-
* - an object with the spec'd shape: `{ fetch(url: string): Uint8Array }`.
|
|
144
|
-
*
|
|
145
|
-
* Every engine-side asset lookup (`@font-face`, `<img>`,
|
|
146
|
-
* `background-image`, and — Phase 4 — `@color-profile`) is funneled
|
|
147
|
-
* through that callable. If `assets.fetch` returns a non-`Uint8Array`
|
|
148
|
-
* value, throws, or the method doesn't exist, the render fails with
|
|
149
|
-
* [`otisk::FetchError`] surfaced through the usual
|
|
150
|
-
* `JsValue`-stringified error channel.
|
|
151
|
-
*
|
|
152
|
-
* ### Why synchronous
|
|
153
|
-
*
|
|
154
|
-
* The native [`otisk::AssetResolver::fetch`] signature is synchronous
|
|
155
|
-
* (`SPECIFICATION.md` §3.7); the engine never spins up an async
|
|
156
|
-
* runtime to fetch an asset. Mirroring that on the JS side keeps the
|
|
157
|
-
* byte-identity contract trivial — every fetch returns bytes
|
|
158
|
-
* immediately, with the same byte-for-byte semantics on both sides.
|
|
159
|
-
* A `Promise<Uint8Array>` arm would either (a) require an async
|
|
160
|
-
* engine entry point — out of scope for this issue — or (b) demand
|
|
161
|
-
* host-side blocking that the browser doesn't permit on the main
|
|
162
|
-
* thread. The simpler synchronous arm is the load-bearing acceptance
|
|
163
|
-
* criterion (byte-identical parity for `font_face_load`,
|
|
164
|
-
* `image_embed`, `background_image`) and an async overload can ride
|
|
165
|
-
* on top of it later.
|
|
166
|
-
*
|
|
167
|
-
* ## Optional output intent (Issue 116)
|
|
168
|
-
*
|
|
169
|
-
* The `output_intent` parameter is **optional**. wasm-bindgen surfaces it
|
|
170
|
-
* as a fifth positional argument that the JS caller may omit (older
|
|
171
|
-
* 3-arg / 4-arg call sites keep working unchanged) or pass as `null` /
|
|
172
|
-
* `undefined` for the same default behaviour. When `output_intent` is
|
|
173
|
-
* present it must be a UTF-8 string naming a known
|
|
174
|
-
* [`otisk::ColorProfile`] variant — see [`parse_color_profile`] for the
|
|
175
|
-
* accepted spellings (`"srgb"`, `"fogra39"`, `"swop_v2"`,
|
|
176
|
-
* case-insensitive). An unknown string surfaces as the usual
|
|
177
|
-
* `JsValue`-stringified error so the JS caller can react.
|
|
178
|
-
*
|
|
179
|
-
* ## Diagnostics
|
|
180
|
-
*
|
|
181
|
-
* Diagnostics from the render are intentionally dropped on this entry
|
|
182
|
-
* point — the spec deliberately keeps the WASM surface minimal
|
|
183
|
-
* (Issue 30 §"Out of scope"). A richer entry point returning
|
|
184
|
-
* `{ bytes, diagnostics }` is deferred to a future issue once the
|
|
185
|
-
* parity harness has a concrete need for it.
|
|
186
|
-
*
|
|
187
|
-
* # Errors
|
|
188
|
-
*
|
|
189
|
-
* On any failure inside the pipeline ([`otisk::RenderError`] — HTML/CSS
|
|
190
|
-
* parse errors, layout failures, missing fonts, PDF emit errors, or
|
|
191
|
-
* resource-limit breaches), any failure inside the JS-side
|
|
192
|
-
* resolver, or an unrecognised `output_intent` string, the error is
|
|
193
|
-
* stringified via its `Display` impl and returned as a
|
|
194
|
-
* `JsValue::from_str`. JS sees a plain string error message; richer
|
|
195
|
-
* error objects can land alongside the diagnostic surface later.
|
|
196
|
-
*
|
|
197
|
-
* # Parameters
|
|
198
|
-
*
|
|
199
|
-
* - `html`: the input HTML source as a UTF-8 string.
|
|
200
|
-
* - `css`: the matching CSS source (currently the only style input — the
|
|
201
|
-
* engine has no `<style>` / `<link rel="stylesheet">` extraction yet).
|
|
202
|
-
* - `margin_mm`: uniform page margin applied to all four sides.
|
|
203
|
-
* - `assets` *(optional)*: a `{ fetch(url): Uint8Array }` object or a
|
|
204
|
-
* bare `(url) -> Uint8Array` callable; pass `null` / `undefined` /
|
|
205
|
-
* omit entirely for the empty-resolver baseline (byte-identical to
|
|
206
|
-
* the pre-Issue-115 3-arg call).
|
|
207
|
-
* - `output_intent` *(optional)*: a UTF-8 string naming a known
|
|
208
|
-
* [`otisk::ColorProfile`] variant (`"srgb"`, `"fogra39"`,
|
|
209
|
-
* `"swop_v2"`); pass `null` / `undefined` / omit entirely to keep
|
|
210
|
-
* the engine's default profile ([`ColorProfile::default`] — sRGB).
|
|
211
|
-
* @param {string} html
|
|
212
|
-
* @param {string} css
|
|
213
|
-
* @param {number} margin_mm
|
|
214
|
-
* @param {any | null} [assets]
|
|
215
|
-
* @param {any | null} [output_intent]
|
|
216
|
-
* @returns {Uint8Array}
|
|
217
|
-
*/
|
|
218
|
-
export function render_pdf(html, css, margin_mm, assets, output_intent) {
|
|
219
|
-
const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
220
|
-
const len0 = WASM_VECTOR_LEN;
|
|
221
|
-
const ptr1 = passStringToWasm0(css, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
222
|
-
const len1 = WASM_VECTOR_LEN;
|
|
223
|
-
const ret = wasm.render_pdf(ptr0, len0, ptr1, len1, margin_mm, isLikeNone(assets) ? 0 : addToExternrefTable0(assets), isLikeNone(output_intent) ? 0 : addToExternrefTable0(output_intent));
|
|
224
|
-
if (ret[3]) {
|
|
225
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
226
|
-
}
|
|
227
|
-
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
228
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
229
|
-
return v3;
|
|
230
|
-
}
|
|
231
123
|
function __wbg_get_imports() {
|
|
232
124
|
const import0 = {
|
|
233
125
|
__proto__: null,
|
package/engine_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@otisk/preview",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Raster print-preview for the otisk typesetting engine: render HTML/CSS pages to RGBA bitmaps (WASM) for an HTML5-canvas preview that matches the PDF print geometry.",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.2",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"engine_wasm_bg.wasm",
|