bookcover-web 0.2.1 → 0.4.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/README.md CHANGED
@@ -26,26 +26,48 @@ Create a generator instance with an initialised WASM compiler and optional rende
26
26
  interface InitOptions {
27
27
  wasm_url: string // URL to typst_ts_web_compiler_bg.wasm
28
28
  renderer_wasm_url?: string // URL to typst_ts_renderer_bg.wasm (required for SVG/PNG)
29
- assets_prefix?: string // URL prefix for generator assets (fonts, templates, frames)
29
+ assets_prefix?: string // URL prefix for static assets (templates, frames, backgrounds)
30
+ fonts_prefix?: string // URL prefix for the fonts tree (manifest.json + families)
30
31
  }
31
32
  ```
32
33
 
33
- **`wasm_url` / `renderer_wasm_url`** — serve the `.wasm` files from your origin. With Vite, import them directly:
34
+ ## Assets
35
+
36
+ Generating fetches four kinds of assets at runtime, none of which ship inside the npm
37
+ packages: the WASM binaries, the Typst templates (`docs/`), frame images (`frames/`), and the
38
+ fonts tree. The easiest setup is the hosted tree at `https://assets.paper.bible/` (CORS
39
+ enabled):
34
40
 
35
41
  ```ts
36
- import wasm_url from '@myriaddreamin/typst-ts-web-compiler/pkg/typst_ts_web_compiler_bg.wasm?url'
37
- import renderer_wasm_url from '@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer_bg.wasm?url'
38
- ```
42
+ // Match the wasm version to your installed @myriaddreamin/typst-ts-web-compiler version
43
+ const typst_version = '0.7.0'
39
44
 
40
- Without a bundler, copy the files from `node_modules` into your `public/` dir and reference by path.
45
+ const generator = await init({
46
+ wasm_url: `https://assets.paper.bible/typst/${typst_version}/typst_ts_web_compiler_bg.wasm`,
47
+ renderer_wasm_url: `https://assets.paper.bible/typst/${typst_version}/typst_ts_renderer_bg.wasm`,
48
+ assets_prefix: 'https://assets.paper.bible/',
49
+ fonts_prefix: 'https://assets.paper.bible/fonts',
50
+ })
51
+ ```
41
52
 
42
- **`assets_prefix`** — points to the `generator/assets/` directory (fonts, Typst templates, frame images). The easiest setup is a symlink from your `public/` dir:
53
+ To self-host instead, serve the same layout under any prefix on your origin:
43
54
 
44
- ```bash
45
- ln -s ../node_modules/bookcover-core/assets public/generator_assets
46
- ```
55
+ - **WASM** — with Vite, import the URLs straight from the installed packages (no hosting
56
+ needed): `import wasm_url from
57
+ '@myriaddreamin/typst-ts-web-compiler/pkg/typst_ts_web_compiler_bg.wasm?url'` (and likewise
58
+ for the renderer). Without a bundler, copy them from `node_modules` into your `public/` dir.
59
+ - **`<assets_prefix>/docs/`** — `cover.typ` and `_helpers.typ`, copied from the
60
+ [repo's `assets/docs/`](https://github.com/gracious-tech/bookcover/tree/main/assets/docs).
61
+ - **`<assets_prefix>/frames/`** — `painted.png` and `torn.png`, copied from the repo's
62
+ `assets/frames/`. (`backgrounds/` is only needed if your UI offers the suggested
63
+ background images.)
64
+ - **`<fonts_prefix>/`** — the fonts tree (`manifest.json`, one dir per family, Noto fallbacks
65
+ under `_noto/`). Generate it with the repo's font config:
47
66
 
48
- Then pass `assets_prefix: '/generator_assets/'`. With Vite the symlink is served automatically at dev time and included in the production build.
67
+ ```bash
68
+ curl -O https://raw.githubusercontent.com/gracious-tech/bookcover/main/font_config.json
69
+ npx typst-fonts-download --fonts public/fonts --config font_config.json
70
+ ```
49
71
 
50
72
 
51
73
  ## `CoverGenerator.generate(options): Promise<GenerateResult>`
@@ -76,9 +98,10 @@ Revoke blob URLs to free memory. Call when the instance is no longer needed.
76
98
  import {init} from 'bookcover-web'
77
99
 
78
100
  const generator = await init({
79
- wasm_url: '/typst_ts_web_compiler_bg.wasm',
80
- renderer_wasm_url: '/typst_ts_renderer_bg.wasm',
81
- assets_prefix: '/generator_assets/',
101
+ wasm_url: 'https://assets.paper.bible/typst/0.7.0/typst_ts_web_compiler_bg.wasm',
102
+ renderer_wasm_url: 'https://assets.paper.bible/typst/0.7.0/typst_ts_renderer_bg.wasm',
103
+ assets_prefix: 'https://assets.paper.bible/',
104
+ fonts_prefix: 'https://assets.paper.bible/fonts',
82
105
  })
83
106
 
84
107
  const result = await generator.generate({
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kCAAkC,CAAA;AAInE,OAAO,KAAK,EAAC,YAAY,EAAE,WAAW,EAAY,MAAM,gBAAgB,CAAA;AAKxE,YAAY,EAAC,WAAW,EAAE,aAAa,EAAE,UAAU,EAC/C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAChE,YAAY,EAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,aAAa,CAAA;AACpE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAC,SAAS,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAA;AACvD,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,mBAAmB,EAAC,MAAM,gBAAgB,CAAA;AAGnG,OAAO,EAAC,sBAAsB,EAAE,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EACvF,aAAa,EAAE,mBAAmB,EAAE,UAAU,EAAE,aAAa,EAAC,MAAM,gBAAgB,CAAA;AACxF,YAAY,EAAC,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAC,MAAM,gBAAgB,CAAA;AAG7F,YAAY,EAAC,WAAW,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAA;AAI3E,MAAM,WAAW,WAAW;IAExB,QAAQ,EAAC,MAAM,CAAA;IAEf,iBAAiB,CAAC,EAAC,MAAM,CAAA;IAGzB,aAAa,CAAC,EAAC,MAAM,CAAA;IAKrB,YAAY,CAAC,EAAC,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAC,OAAO,CAAA;IAEd,KAAK,CAAC,EAAC,IAAI,CAAA;IAEX,MAA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,IAAI,CAAC,OAAO,EAAC,WAAW,GAAE,OAAO,CAAC,cAAc,CAAC,CAuBtE"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createTypstCompiler, CompileFormatEnum } from '@myriaddreamin/typst.ts/compiler';
3
3
  import { createTypstRenderer } from '@myriaddreamin/typst.ts/renderer';
4
4
  import { loadFonts } from '@myriaddreamin/typst.ts';
5
- import { build, cover_schema, split_svg, split_png, split_pdf, frame_image, frame_asset_path, asset_path, TYPST_DIR, TEMPLATE_FILES, collect_all_fonts } from 'bookcover-core';
5
+ import { build, cover_schema, split_svg, split_png, split_pdf, frame_image, frame_asset_path, asset_path, DOCS_DIR, TEMPLATE_FILES, collect_all_fonts } from 'bookcover-core';
6
6
  import { base_font } from 'typst-fonts';
7
7
  import { load_fonts_prefix, font_urls_for as build_font_urls, fetch_font_bytes, fonts_to_blob_urls, revoke_blob_urls } from 'typst-fonts/web';
8
8
  export { font_file_url } from 'typst-fonts/web';
@@ -235,10 +235,10 @@ export class CoverGenerator {
235
235
  const ext = '.' + (blob.type.split('/')[1] ?? 'jpg').replace('jpeg', 'jpg');
236
236
  image_input = { data: new Uint8Array(await blob.arrayBuffer()), ext };
237
237
  }
238
- // Load typst templates from assets
238
+ // Load typst templates from assets (docs/ subdir)
239
239
  const [cover_typ, helpers_typ] = await Promise.all([
240
- fetch(asset_path(assets, TYPST_DIR, TEMPLATE_FILES.cover)).then(r => r.text()),
241
- fetch(asset_path(assets, TYPST_DIR, TEMPLATE_FILES.helpers)).then(r => r.text()),
240
+ fetch(asset_path(assets, DOCS_DIR, TEMPLATE_FILES.cover)).then(r => r.text()),
241
+ fetch(asset_path(assets, DOCS_DIR, TEMPLATE_FILES.helpers)).then(r => r.text()),
242
242
  ]);
243
243
  const templates = { cover: cover_typ, helpers: helpers_typ };
244
244
  // Load the frame PNG from assets when the schema uses painted coverage
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":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,IAAI,CAAC,cAAc,GAAG,EAAE,CAAA;QACxB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,OAAmB;IAC1C,mFAAmF;IACnF,MAAM,iBAAiB,CAAC,OAAO,CAAC,YAAY,IAAI,SAAS,CAAC,CAAA;IAE1D,qFAAqF;IACrF,IAAI,QAAQ,GAAwB,IAAI,CAAA;IACxC,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAC5B,MAAM,kBAAkB,GAAG,SAAS,CAAC,EAAE,CAAC,CAAA;QACxC,MAAM,CAAC,GAAG,mBAAmB,EAAE,CAAA;QAC/B,MAAM,CAAC,CAAC,IAAI,CAAC;YACT,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,EAAC,cAAc,EAAE,OAAO,CAAC,iBAAkB,EAAC,CAAC;YAC/D,WAAW,EAAE,CAAC,kBAAkB,CAAC;SACpC,CAAC,CAAA;QACF,QAAQ,GAAG,CAAC,CAAA;IAChB,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAEjD,sFAAsF;IACtF,iFAAiF;IACjF,GAAG,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IAEjD,OAAO,GAAG,CAAA;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bookcover-web",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "license": "MIT-0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,6 +12,9 @@
12
12
  "type": "module",
13
13
  "main": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist/"
17
+ ],
15
18
  "scripts": {
16
19
  "build": "tsc",
17
20
  "dev": "tsc --watch"
@@ -20,7 +23,7 @@
20
23
  "@myriaddreamin/typst-ts-renderer": "^0.7.0",
21
24
  "@myriaddreamin/typst-ts-web-compiler": "^0.7.0",
22
25
  "@myriaddreamin/typst.ts": "^0.7.0",
23
- "bookcover-core": "^0.2.1",
26
+ "bookcover-core": "^0.4.0",
24
27
  "typst-fonts": "^0.1.0"
25
28
  }
26
29
  }
@@ -1,42 +0,0 @@
1
-
2
- // Protocol types for embedding the cover-editor widget in an iframe. The host sends one
3
- // InitMessage in reply to the widget's 'ready' message; the widget reports edits back with
4
- // WidgetMessage. Binaries (background image, custom font bytes) always travel as separate
5
- // structured-clone fields beside the pure-JSON form values, so hosts can persist `data`
6
- // as-is (e.g. to Firestore) and store the binaries elsewhere.
7
-
8
- import type {EmbedFormState} from 'bookcover-core'
9
- import type {CustomFont} from 'typst-fonts'
10
-
11
- /** Locales the widget UI supports. Lives in this published package, so adding a widget
12
- * locale requires a bookcover-web release. */
13
- export type AppLocale = 'eng' | 'vie'
14
-
15
- /** Host -> widget, answered to the widget's 'ready' message */
16
- export interface InitMessage {
17
- type: 'init'
18
- // Form values to preset — pure JSON, no binaries inside
19
- preset?: Partial<EmbedFormState>
20
- // Background image to restore into the editor (File structured-clones as a cheap blob ref)
21
- bg_image?: File | null
22
- // Previously uploaded font families to restore into the editor
23
- custom_fonts?: CustomFont[]
24
- // Swap the export button for a "Finished" signal, and show a Cancel button
25
- finished_mode?: boolean
26
- // Hide the Book Size sidebar section entirely
27
- hide_size_section?: boolean
28
- locale?: AppLocale
29
- }
30
-
31
- /** Widget -> host. `schema` is the renderable generator schema derived from `data` (also
32
- * derivable host-side via build_schema). `bg_image` rides on every data/finished message
33
- * (cloning a File is cheap); `custom_fonts` byte arrays are expensive to clone, so on 'data'
34
- * messages the field is only present when the font set changed since the last message
35
- * (absent = unchanged), while 'finished' always carries the complete array. */
36
- export type WidgetMessage =
37
- | {type: 'ready'}
38
- | {type: 'data', data: EmbedFormState, schema: Record<string, unknown>,
39
- bg_image: File | null, custom_fonts?: CustomFont[]}
40
- | {type: 'finished', data: EmbedFormState, schema: Record<string, unknown>,
41
- bg_image: File | null, custom_fonts: CustomFont[]}
42
- | {type: 'cancelled'}
package/src/index.ts DELETED
@@ -1,420 +0,0 @@
1
-
2
- // Browser cover generator — compiles typst files via WebAssembly, supports PDF/SVG/PNG output
3
-
4
- import {createTypstCompiler, CompileFormatEnum} from '@myriaddreamin/typst.ts/compiler'
5
- import {createTypstRenderer} from '@myriaddreamin/typst.ts/renderer'
6
- import type {TypstCompiler} from '@myriaddreamin/typst.ts/compiler'
7
- import type {TypstRenderer} from '@myriaddreamin/typst.ts/renderer'
8
- import {loadFonts} from '@myriaddreamin/typst.ts'
9
- import {build, cover_schema, split_svg, split_png, split_pdf, frame_image, frame_asset_path,
10
- asset_path, TYPST_DIR, TEMPLATE_FILES, collect_all_fonts} from 'bookcover-core'
11
- import type {OutputFormat, SplitResult, Templates} from 'bookcover-core'
12
- import {base_font} from 'typst-fonts'
13
- import {load_fonts_prefix, font_urls_for as build_font_urls, fetch_font_bytes,
14
- fonts_to_blob_urls, revoke_blob_urls} from 'typst-fonts/web'
15
-
16
- export type {CoverSchema, TitlePosition, FontConfig,
17
- OutputFormat, SplitResult, PatternDef} from 'bookcover-core'
18
- export type {BundledFont, CjkVariant, CustomFont} from 'typst-fonts'
19
- export {font_file_url} from 'typst-fonts/web'
20
- export {get_fonts, get_bundled_font} from 'typst-fonts'
21
- export {list_patterns, collect_fonts, collect_all_fonts, default_spine_title} from 'bookcover-core'
22
-
23
- // Form state + form->schema conversion, so hosts can derive the renderable schema themselves
24
- export {make_blank_form_values, build_schema, curly_quotes, parse_font_family, find_pattern,
25
- derive_colors, hex_override_to_hsl, hex_to_hsl, is_dark_color} from 'bookcover-core'
26
- export type {FormState, EmbedFormState, CustomFontStyle, DerivedColors} from 'bookcover-core'
27
-
28
- // Embed protocol types for iframing the widget
29
- export type {InitMessage, WidgetMessage, AppLocale} from './embed_types.js'
30
-
31
- const decoder = new TextDecoder()
32
-
33
- export interface InitOptions {
34
- // URL or path to typst_ts_web_compiler_bg.wasm — required
35
- wasm_url:string
36
- // URL or path to typst_ts_renderer_bg.wasm — required for SVG/PNG output
37
- renderer_wasm_url?:string
38
- // URL prefix for generator assets (e.g. '/generator_assets/').
39
- // Used to load typst templates, frames, backgrounds, etc.
40
- assets_prefix?:string
41
- // URL prefix for fonts — curated and Noto fallback alike (e.g.
42
- // 'http://localhost:5300/generator_assets/fonts' in dev, 'https://assets.paper.bible/fonts' in
43
- // production). Kept separate from assets_prefix since the fonts tree is managed and
44
- // published by its own separate repo.
45
- fonts_prefix?:string
46
- }
47
-
48
- export interface GenerateOptions {
49
- schema:unknown
50
- // Background image as a Blob (content type included)
51
- image?:Blob
52
- // Output format: 'pdf' (default), 'svg', or 'png'
53
- format?:OutputFormat
54
- // PPI for PNG output (default 144)
55
- ppi?:number
56
- // Whether to split the result into front/back/spine panels
57
- split?:boolean
58
- // Raw TTF bytes for user-uploaded custom fonts
59
- custom_fonts?:Uint8Array[]
60
- }
61
-
62
- export interface GenerateResult {
63
- // The full cover data (PDF/PNG bytes, or SVG string)
64
- data:Uint8Array | string
65
- // Split panel data (only present when split is true and format is svg/png)
66
- split?:SplitResult<Uint8Array> | SplitResult<string>
67
- }
68
-
69
-
70
- /** Format compilation diagnostics into a readable error */
71
- function throw_compile_error(diagnostics:unknown):never {
72
- const diag = Array.isArray(diagnostics)
73
- ? diagnostics.map((d) => (typeof d === 'string' ? d : JSON.stringify(d))).join('\n')
74
- : 'unknown error'
75
- throw new Error(`[generator-web] Typst compilation failed:\n${diag}`)
76
- }
77
-
78
- /** Create a 2D canvas — a DOM element on the main thread, OffscreenCanvas inside a worker */
79
- function make_canvas(width:number, height:number):HTMLCanvasElement | OffscreenCanvas {
80
- if (typeof document === 'undefined') {
81
- return new OffscreenCanvas(width, height)
82
- }
83
- const canvas = document.createElement('canvas')
84
- canvas.width = width
85
- canvas.height = height
86
- return canvas
87
- }
88
-
89
- /** Encode a canvas' contents as PNG bytes (handles both canvas types) */
90
- async function canvas_png_bytes(canvas:HTMLCanvasElement | OffscreenCanvas):Promise<Uint8Array> {
91
- const blob = 'convertToBlob' in canvas
92
- ? await canvas.convertToBlob({type: 'image/png'})
93
- : await new Promise<Blob>((resolve) => {
94
- canvas.toBlob((b) => resolve(b!), 'image/png')
95
- })
96
- return new Uint8Array(await blob.arrayBuffer())
97
- }
98
-
99
- /** Crop a region from a PNG using the Canvas API — used as PngCropFn */
100
- async function canvas_crop(
101
- data:Uint8Array,
102
- x:number,
103
- y:number,
104
- w:number,
105
- h:number,
106
- ):Promise<Uint8Array> {
107
- const blob = new Blob([data as BlobPart], {type: 'image/png'})
108
- const bitmap = await createImageBitmap(blob)
109
-
110
- const canvas = make_canvas(w, h)
111
- const ctx = (canvas as HTMLCanvasElement).getContext('2d')!
112
- ctx.drawImage(bitmap, x, y, w, h, 0, 0, w, h)
113
- bitmap.close()
114
-
115
- return canvas_png_bytes(canvas)
116
- }
117
-
118
- /** Stateful cover generator — each instance owns its own compiler and renderer */
119
- export class CoverGenerator {
120
- private opts:InitOptions
121
- // Created lazily on first generate() — the font set isn't known until a schema arrives,
122
- // so creating one earlier would just instantiate WASM with fonts that get replaced
123
- private compiler!:TypstCompiler
124
- private renderer:TypstRenderer | null
125
-
126
- // Cache key of the font set the current compiler was init'd with ('' = no compiler yet)
127
- private active_fonts = ''
128
- // Fetched font bytes keyed by URL, so a compiler reinit (any font-set change) never
129
- // refetches families already seen this session
130
- private font_bytes = new Map<string, Uint8Array>()
131
- // Blob URLs handed to the current compiler (bundled + custom) — revoked on reinit
132
- private font_blob_urls:string[] = []
133
- // Identity-based ids for custom font byte arrays (see custom_font_id)
134
- private custom_font_ids = new WeakMap<Uint8Array, number>()
135
- private next_custom_font_id = 1
136
-
137
- constructor(opts:InitOptions, renderer:TypstRenderer | null) {
138
- this.opts = opts
139
- this.renderer = renderer
140
- }
141
-
142
- /** Build fetch URLs for the given font families against fonts_prefix — curated families
143
- * live at <prefix>/<family>/, Noto fallback families at <prefix>/_noto/<family>/,
144
- * mirroring the top-level fonts/ directory's own layout exactly */
145
- private font_urls_for(families:string[]):string[] {
146
- return build_font_urls(this.opts.fonts_prefix ?? '/fonts/', families)
147
- }
148
-
149
- /** Fetch a font file's bytes, memoised in font_bytes (failures aren't cached, so a
150
- * later generate retries the fetch) */
151
- private async fetch_font(url:string):Promise<Uint8Array> {
152
- const cached = this.font_bytes.get(url)
153
- if (cached) {
154
- return cached
155
- }
156
- const bytes = await fetch_font_bytes(url)
157
- this.font_bytes.set(url, bytes)
158
- return bytes
159
- }
160
-
161
- /** Pre-fetch the given font families into the in-memory byte cache */
162
- async prefetch_fonts(families:string[]):Promise<void> {
163
- await Promise.all(this.font_urls_for(families).map(url => this.fetch_font(url)))
164
- }
165
-
166
- /** Stable id for a custom font's byte array. The widget passes the same Uint8Array
167
- * references across generates, so object identity distinguishes fonts without hashing
168
- * their bytes (byteLength alone could collide between two different fonts). */
169
- private custom_font_id(data:Uint8Array):number {
170
- let id = this.custom_font_ids.get(data)
171
- if (id === undefined) {
172
- id = this.next_custom_font_id
173
- this.next_custom_font_id += 1
174
- this.custom_font_ids.set(data, id)
175
- }
176
- return id
177
- }
178
-
179
- /** (Re)initialise the compiler with a different font set. Bundled font bytes come from
180
- * the in-memory cache (fetched at most once per session) and everything is handed to
181
- * loadFonts() as blob URLs, keeping the network out of the reinit path. The renderer
182
- * never needs reinitialisation because it reads glyph outlines from compiled vector
183
- * data. */
184
- private async reinit_compiler(font_urls:string[], custom_fonts?:Uint8Array[]):Promise<void> {
185
- // Fetch any fonts not yet cached, in parallel
186
- const bundled_bytes = await Promise.all(font_urls.map(url => this.fetch_font(url)))
187
-
188
- // Revoke the previous compiler's blob URLs to avoid memory leaks
189
- revoke_blob_urls(this.font_blob_urls)
190
-
191
- // One blob URL per font file (bundled + custom) for loadFonts() to read —
192
- // mapShadow only adds to the virtual filesystem, not the font book
193
- this.font_blob_urls = fonts_to_blob_urls([...bundled_bytes, ...(custom_fonts ?? [])])
194
-
195
- // assets:false stops typst.ts silently appending its default text fonts (NewCM,
196
- // Libertinus, DejaVu... fetched from jsdelivr) — all fonts we need are passed explicitly
197
- const compiler_font_opts = loadFonts(this.font_blob_urls, {assets: false})
198
-
199
- const c = createTypstCompiler()
200
- await c.init({
201
- getModule: () => ({module_or_path: this.opts.wasm_url}),
202
- beforeBuild: [compiler_font_opts],
203
- })
204
-
205
- this.compiler = c
206
- }
207
-
208
- /** Load the typst file map into the compiler's shadow filesystem */
209
- private load_files(files:Map<string, Uint8Array>):void {
210
- this.compiler.resetShadow()
211
- for (const [filename, bytes] of files) {
212
- const vpath = `/${filename}`
213
- if (filename.endsWith('.typ')) {
214
- this.compiler.addSource(vpath, decoder.decode(bytes))
215
- }
216
- else {
217
- this.compiler.mapShadow(vpath, bytes)
218
- }
219
- }
220
- }
221
-
222
- /** Compile to PDF and return raw bytes */
223
- private async compile_pdf():Promise<Uint8Array> {
224
- const result = await this.compiler.compile({
225
- mainFilePath: '/cover.typ',
226
- format: CompileFormatEnum.pdf,
227
- })
228
- if (!result.result) {
229
- throw_compile_error(result.diagnostics)
230
- }
231
- return result.result!
232
- }
233
-
234
- /** Compile to vector format, then render as SVG string covering the full canvas */
235
- private async compile_svg():Promise<string> {
236
- this.assert_renderer('SVG')
237
- const result = await this.compiler.compile({
238
- mainFilePath: '/cover.typ',
239
- format: CompileFormatEnum.vector,
240
- })
241
- if (!result.result) {
242
- throw_compile_error(result.diagnostics)
243
- }
244
-
245
- const svg = await this.renderer!.renderSvg({
246
- artifactContent: result.result!,
247
- format: 'vector',
248
- data_selection: {js: false, css: true, body: true, defs: true},
249
- })
250
-
251
- // Patch unitless width/height to add `pt` suffix (Typst SVG output uses pt) so
252
- // browsers render at 96 CSS px per inch, matching the split SVGs from split_svg()
253
- return svg.replace(/<svg([^>]*)>/, (_match, attrs:string) => {
254
- const patched = attrs
255
- .replace(/width="([\d.]+)"/, 'width="$1pt"')
256
- .replace(/height="([\d.]+)"/, 'height="$1pt"')
257
- return `<svg${patched}>`
258
- })
259
- }
260
-
261
- /** Compile to vector format, then render as PNG via offscreen canvas */
262
- private async compile_png(ppi:number):Promise<Uint8Array> {
263
- this.assert_renderer('PNG')
264
- const result = await this.compiler.compile({
265
- mainFilePath: '/cover.typ',
266
- format: CompileFormatEnum.vector,
267
- })
268
- if (!result.result) {
269
- throw_compile_error(result.diagnostics)
270
- }
271
-
272
- // Render to a canvas at the desired PPI (typst uses 72pt/inch)
273
- const scale = ppi / 72
274
- const canvas = document.createElement('canvas')
275
-
276
- await this.renderer!.renderCanvas({
277
- artifactContent: result.result!,
278
- format: 'vector',
279
- canvas,
280
- pageOffset: 0,
281
- pixelPerPt: scale,
282
- backgroundColor: '#ffffff',
283
- })
284
-
285
- // Extract PNG from canvas
286
- const blob = await new Promise<Blob>((resolve) => {
287
- canvas.toBlob((b) => resolve(b!), 'image/png')
288
- })
289
- return new Uint8Array(await blob.arrayBuffer())
290
- }
291
-
292
- /** Throw if the renderer was not initialised */
293
- private assert_renderer(format:string):void {
294
- if (!this.renderer) {
295
- throw new Error(
296
- `[generator-web] ${format} output requires renderer_wasm_url in init() options`
297
- )
298
- }
299
- }
300
-
301
- /** Generate a book cover using this instance's compiler and renderer */
302
- async generate(options:GenerateOptions):Promise<GenerateResult> {
303
- const format = options.format ?? 'pdf'
304
- // Default to 144 PPI (2x typographic resolution, 2 × 72pt/in)
305
- const ppi = options.ppi ?? 144
306
- const split = options.split ?? false
307
-
308
- // Parse schema and get dimensions from printing-services
309
- const parsed = cover_schema.parse(options.schema)
310
- const assets = this.opts.assets_prefix ?? '/assets/'
311
-
312
- // (Re)initialise the compiler when the set of required fonts changes — including on
313
- // the very first generate, since the compiler is created lazily ('' never matches).
314
- // Noto Serif (base font) is always included — it's not bundled in the WASM assets.
315
- // collect_all_fonts also includes every Noto fallback family needed to cover non-Latin
316
- // scripts detected in the schema's text, so only those specific families get fetched.
317
- const needed_fonts = collect_all_fonts(parsed)
318
- const custom_fonts_id = options.custom_fonts
319
- ? options.custom_fonts.map(b => String(this.custom_font_id(b))).join(':')
320
- : ''
321
- const cache_key = needed_fonts.join(',') + '|' + custom_fonts_id
322
- if (cache_key !== this.active_fonts) {
323
- await this.reinit_compiler(this.font_urls_for(needed_fonts), options.custom_fonts)
324
- this.active_fonts = cache_key
325
- }
326
-
327
- // Convert Blob to ImageInput (Uint8Array + extension) for the core builder
328
- let image_input:{data:Uint8Array, ext:string} | undefined
329
- if (options.image) {
330
- const blob = options.image
331
- const ext = '.' + (blob.type.split('/')[1] ?? 'jpg').replace('jpeg', 'jpg')
332
- image_input = {data: new Uint8Array(await blob.arrayBuffer()), ext}
333
- }
334
-
335
- // Load typst templates from assets
336
- const [cover_typ, helpers_typ] = await Promise.all([
337
- fetch(asset_path(assets, TYPST_DIR, TEMPLATE_FILES.cover)).then(r => r.text()),
338
- fetch(asset_path(assets, TYPST_DIR, TEMPLATE_FILES.helpers)).then(r => r.text()),
339
- ])
340
- const templates:Templates = {cover: cover_typ, helpers: helpers_typ}
341
-
342
- // Load the frame PNG from assets when the schema uses painted coverage
343
- let frame_blob:Blob | undefined
344
- if (parsed.bg_image_coverage === 'painted') {
345
- const url = frame_asset_path(assets, 'painted')
346
- const resp = await fetch(url)
347
- frame_blob = await resp.blob()
348
- }
349
-
350
- const {files, dims} = await build(templates, parsed, image_input, frame_image, frame_blob)
351
- this.load_files(files)
352
-
353
- // Compile to the requested format
354
- let data:Uint8Array | string
355
-
356
- if (format === 'pdf') {
357
- data = await this.compile_pdf()
358
- }
359
- else if (format === 'svg') {
360
- data = await this.compile_svg()
361
- }
362
- else {
363
- data = await this.compile_png(ppi)
364
- }
365
-
366
- const result:GenerateResult = {data}
367
-
368
- // Split into front/back/spine panels
369
- if (split) {
370
- if (format === 'pdf') {
371
- result.split = split_pdf(data as Uint8Array, dims)
372
- }
373
- else if (format === 'svg') {
374
- result.split = split_svg(data as string, dims)
375
- }
376
- else {
377
- result.split = await split_png(data as Uint8Array, dims, ppi, canvas_crop)
378
- }
379
- }
380
-
381
- return result
382
- }
383
-
384
- /** Revoke blob URLs and drop cached font bytes to free memory */
385
- destroy():void {
386
- revoke_blob_urls(this.font_blob_urls)
387
- this.font_blob_urls = []
388
- this.font_bytes.clear()
389
- }
390
- }
391
-
392
- /**
393
- * Create a CoverGenerator instance with an optional initialised WASM renderer.
394
- * The compiler itself is created lazily by the first generate() call, once the schema's
395
- * font set is known. Each instance is independent — multiple generators can run concurrently.
396
- */
397
- export async function init(options:InitOptions):Promise<CoverGenerator> {
398
- // Load the curated font manifest before anything else below resolves a font family
399
- await load_fonts_prefix(options.fonts_prefix ?? '/fonts/')
400
-
401
- // Renderer only needs base fonts (glyph shapes are embedded in compiled vector data)
402
- let renderer:TypstRenderer | null = null
403
- if (options.renderer_wasm_url) {
404
- const renderer_font_opts = loadFonts([])
405
- const r = createTypstRenderer()
406
- await r.init({
407
- getModule: () => ({module_or_path: options.renderer_wasm_url!}),
408
- beforeBuild: [renderer_font_opts],
409
- })
410
- renderer = r
411
- }
412
-
413
- const gen = new CoverGenerator(options, renderer)
414
-
415
- // Warm the font byte cache with the always-needed base font while the rest of the app
416
- // finishes loading — a failure here is fine, the first generate simply refetches
417
- gen.prefetch_fonts([base_font()]).catch(() => {})
418
-
419
- return gen
420
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
-
2
- {
3
- "compilerOptions": {
4
- "target": "ES2022",
5
- "module": "NodeNext",
6
- "moduleResolution": "NodeNext",
7
- "lib": ["ES2022", "DOM"],
8
- "outDir": "dist",
9
- "rootDir": "src",
10
- "strict": true,
11
- "declaration": true,
12
- "declarationMap": true,
13
- "sourceMap": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "skipLibCheck": true
16
- },
17
- "include": ["src"],
18
- "exclude": ["node_modules", "dist"]
19
- }
@@ -1 +0,0 @@
1
- {"root":["./src/index.ts"],"version":"5.9.3"}