epub-gen3 0.1.0 → 0.2.1

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/browser.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Browser entry-point for epub-gen3.
3
+ *
4
+ * Re-exports the WASM Epub class and a ready promise that resolves once the
5
+ * WASM module is initialised. Import this instead of the raw wasm glue:
6
+ *
7
+ * import { Epub, ready } from 'epub-gen3/browser'
8
+ * await ready
9
+ * const epub = new Epub(info, chapters)
10
+ */
11
+ import init, { Epub } from './wasm/epub_gen_wasm.js'
12
+
13
+ export { Epub }
14
+ export const ready = init()
Binary file
package/index.d.ts CHANGED
@@ -17,6 +17,32 @@ export interface EpubInfo {
17
17
  css?: string
18
18
  /** EPUB spec version (use `3`). */
19
19
  version: number
20
+ /** Raw XML written to `META-INF/encryption.xml`. Pass `null` to omit. */
21
+ encryption?: string
22
+ /** Raw XML written to `META-INF/metadata.xml`. Pass `null` to omit. */
23
+ metadataXml?: string
24
+ /** Raw XML written to `META-INF/manifest.xml`. Pass `null` to omit. */
25
+ manifestXml?: string
26
+ }
27
+ /**
28
+ * An image embedded in the EPUB.
29
+ *
30
+ * Images are written to `OEBPS/images/<path>` and can be referenced from
31
+ * chapter paragraphs with raw markup, e.g.
32
+ * `<img src="images/diagram.png" alt="Diagram" />`.
33
+ */
34
+ export interface EpubImage {
35
+ /** Unique manifest id (letters, digits, `-`, `_`). */
36
+ id: string
37
+ /**
38
+ * File name written under `OEBPS/images/`, e.g. `cover.png`.
39
+ * The extension determines the media-type.
40
+ */
41
+ path: string
42
+ /** Raw image bytes. */
43
+ data: Buffer
44
+ /** When `true`, this image is the book cover (at most one). */
45
+ cover: boolean
20
46
  }
21
47
  /**
22
48
  * EPUB builder.
@@ -28,11 +54,19 @@ export interface EpubInfo {
28
54
  * const epub = new Epub(info, [
29
55
  * ['Chapter One', 'First paragraph.', 'Second paragraph.'],
30
56
  * ]);
57
+ * epub.setImages([
58
+ * { id: 'cover-img', path: 'cover.png', data: coverBytes, cover: true },
59
+ * ]);
31
60
  * ```
32
61
  */
33
62
  export declare class Epub {
34
63
  /** Create a new EPUB builder. */
35
64
  constructor(info: EpubInfo, chapters: Array<Array<string>>)
65
+ /**
66
+ * Attach images to the EPUB. Pass an array of `EpubImage` objects.
67
+ * Flag exactly one with `cover: true` to set the book cover.
68
+ */
69
+ setImages(images: Array<EpubImage>): void
36
70
  /** Build the EPUB and write it to `<title>.epub` in the current working directory. */
37
71
  run(): void
38
72
  /**
package/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { createRequire } from 'module'
2
+ const require = createRequire(import.meta.url)
3
+ const { Epub } = require('./index.js')
4
+ export { Epub }
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "epub-gen3",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Generate EPUB files from Rust — Node.js native addon",
5
5
  "main": "index.js",
6
+ "browser": "./browser.js",
6
7
  "types": "index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "browser": "./browser.js",
11
+ "import": "./index.mjs",
12
+ "require": "./index.js"
13
+ },
14
+ "./browser": "./browser.js",
15
+ "./wasm/*": "./wasm/*"
16
+ },
7
17
  "napi": {
8
18
  "name": "epub-gen3",
9
19
  "triples": {
@@ -18,15 +28,20 @@
18
28
  "scripts": {
19
29
  "build": "napi build --platform --release",
20
30
  "build:debug": "napi build --platform",
21
- "prepublish": "napi build --platform --release"
31
+ "build:wasm": "wasm-pack build ../wasm --target web --out-dir ../node/wasm",
32
+ "build:all": "napi build --platform --release && npm run build:wasm"
22
33
  },
23
34
  "devDependencies": {
24
- "@napi-rs/cli": "^2.18.0"
35
+ "@napi-rs/cli": "^2.18.0",
36
+ "wasm-pack": "^0.13.1"
25
37
  },
26
38
  "files": [
27
39
  "index.js",
40
+ "index.mjs",
41
+ "browser.js",
28
42
  "index.d.ts",
29
- "*.node"
43
+ "*.node",
44
+ "wasm/"
30
45
  ],
31
46
  "license": "MIT"
32
47
  }