bookcover-web 0.16.0 → 0.18.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/dist/index.d.ts +2 -0
- package/dist/index.js +25 -8
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,8 @@ export declare class CoverGenerator {
|
|
|
99
99
|
private compile_png;
|
|
100
100
|
/** Throw if the renderer was not initialised */
|
|
101
101
|
private assert_renderer;
|
|
102
|
+
/** Run the compiler (and, for svg/png, the renderer) for the requested output format */
|
|
103
|
+
private compile_format;
|
|
102
104
|
/** Generate a book cover using this instance's compiler and renderer */
|
|
103
105
|
generate(options: GenerateOptions): Promise<GenerateResult>;
|
|
104
106
|
/** Revoke blob URLs and drop cached font bytes to free memory */
|
package/dist/index.js
CHANGED
|
@@ -281,6 +281,14 @@ export class CoverGenerator {
|
|
|
281
281
|
throw new Error(`[generator-web] ${format} output requires renderer_wasm_url in init() options`);
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
+
/** Run the compiler (and, for svg/png, the renderer) for the requested output format */
|
|
285
|
+
async compile_format(format, ppi) {
|
|
286
|
+
if (format === 'pdf')
|
|
287
|
+
return this.compile_pdf();
|
|
288
|
+
if (format === 'svg')
|
|
289
|
+
return this.compile_svg();
|
|
290
|
+
return this.compile_png(ppi);
|
|
291
|
+
}
|
|
284
292
|
/** Generate a book cover using this instance's compiler and renderer */
|
|
285
293
|
async generate(options) {
|
|
286
294
|
const format = options.format ?? 'pdf';
|
|
@@ -339,16 +347,25 @@ export class CoverGenerator {
|
|
|
339
347
|
// bookcover-core — see its generated/templates_data.ts)
|
|
340
348
|
const { files, dims } = await build(parsed, image_input, frame_image, frame_blob, undefined, image_regions);
|
|
341
349
|
this.load_files(files);
|
|
342
|
-
// Compile to the requested format
|
|
350
|
+
// Compile to the requested format. iOS Safari/WebKit's WASM call stack inside a Worker
|
|
351
|
+
// is shallow enough that the Typst compiler (or, for svg/png, the renderer) can throw a
|
|
352
|
+
// RangeError stack overflow on a compile that succeeds on a freshly created WASM
|
|
353
|
+
// instance — some internal state survives compiler.reset()/the periodic renderer
|
|
354
|
+
// rebuild (see reset_memory_if_needed) as more generate() calls accumulate, regardless
|
|
355
|
+
// of the schema's own complexity. A hard reinit plus a single retry recovers
|
|
356
|
+
// transparently instead of hard-failing the whole session.
|
|
343
357
|
let data;
|
|
344
|
-
|
|
345
|
-
data = await this.
|
|
346
|
-
}
|
|
347
|
-
else if (format === 'svg') {
|
|
348
|
-
data = await this.compile_svg();
|
|
358
|
+
try {
|
|
359
|
+
data = await this.compile_format(format, ppi);
|
|
349
360
|
}
|
|
350
|
-
|
|
351
|
-
|
|
361
|
+
catch (error) {
|
|
362
|
+
if (!(error instanceof RangeError))
|
|
363
|
+
throw error;
|
|
364
|
+
await this.reinit_compiler(this.font_urls_for(needed_fonts), options.custom_fonts);
|
|
365
|
+
if (format !== 'pdf')
|
|
366
|
+
await this.reinit_renderer();
|
|
367
|
+
this.load_files(files);
|
|
368
|
+
data = await this.compile_format(format, ppi);
|
|
352
369
|
}
|
|
353
370
|
const result = { data };
|
|
354
371
|
// Split into front/back/spine panels
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bookcover-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"license": "MIT-0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@myriaddreamin/typst-ts-renderer": "0.7.0",
|
|
40
40
|
"@myriaddreamin/typst-ts-web-compiler": "0.7.0",
|
|
41
41
|
"@myriaddreamin/typst.ts": "0.7.0",
|
|
42
|
-
"bookcover-core": "^0.
|
|
42
|
+
"bookcover-core": "^0.18.0",
|
|
43
43
|
"typst-fonts": "^0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"sideEffects": false
|