epub-gen3 0.2.1 → 0.3.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.
@@ -0,0 +1,63 @@
1
+ //#region src/types.d.ts
2
+ /** Metadata for the EPUB document. */
3
+ interface EpubInfo {
4
+ title: string;
5
+ description: string;
6
+ publisher: string;
7
+ author: string;
8
+ /** Label used for the Table of Contents page. */
9
+ tocTitle: string;
10
+ lang: string;
11
+ fonts: string[];
12
+ /** Raw CSS injected as `styles.css`. Omit for an empty stylesheet. */
13
+ css?: string;
14
+ /** EPUB spec version (use `3`). */
15
+ version: number;
16
+ /** Raw XML written to `META-INF/encryption.xml`. Omit to skip. */
17
+ encryption?: string;
18
+ /** Raw XML written to `META-INF/metadata.xml`. Omit to skip. */
19
+ metadataXml?: string;
20
+ /** Raw XML written to `META-INF/manifest.xml`. Omit to skip. */
21
+ manifestXml?: string;
22
+ }
23
+ //#endregion
24
+ //#region src/browser.d.ts
25
+ interface EpubStylesheet {
26
+ id: string;
27
+ path: string;
28
+ content: string;
29
+ }
30
+ interface EpubImageBrowser {
31
+ id: string;
32
+ path: string;
33
+ /** Raw image bytes as a `Uint8Array`, or a base64-encoded string. */
34
+ data: Uint8Array | string;
35
+ /** When `true`, this image is the book cover (at most one). */
36
+ cover: boolean;
37
+ }
38
+ /** Typed wrapper around the WASM Epub for browser environments. */
39
+ declare class Epub {
40
+ private inner;
41
+ constructor(info: EpubInfo, chapters: string[][]);
42
+ /** Attach additional CSS stylesheets. Linked after `css` (from info), in order. */
43
+ setStylesheets(stylesheets: EpubStylesheet[]): void;
44
+ /** Attach images. `data` may be a `Uint8Array` or a base64-encoded string. */
45
+ setImages(images: EpubImageBrowser[]): void;
46
+ /**
47
+ * Build the EPUB and return its bytes as a `Uint8Array`.
48
+ * No filesystem access is performed — use `Blob` + `URL.createObjectURL` to download.
49
+ */
50
+ archive(): Uint8Array;
51
+ }
52
+ /**
53
+ * Resolves once the WASM module is initialised.
54
+ *
55
+ * ```ts
56
+ * import { Epub, ready } from 'epub-gen3/browser'
57
+ * await ready
58
+ * const epub = new Epub(info, chapters)
59
+ * ```
60
+ */
61
+ declare const ready: Promise<void>;
62
+ //#endregion
63
+ export { Epub, EpubImageBrowser, type EpubInfo, EpubStylesheet, ready };
@@ -0,0 +1,45 @@
1
+ import wasmInit, { Epub as Epub$1 } from "../wasm/epub_gen_wasm.js";
2
+ //#region src/browser.ts
3
+ function resolveData(data) {
4
+ if (typeof data !== "string") return data;
5
+ const binary = atob(data);
6
+ const out = new Uint8Array(binary.length);
7
+ for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
8
+ return out;
9
+ }
10
+ /** Typed wrapper around the WASM Epub for browser environments. */
11
+ var Epub = class {
12
+ constructor(info, chapters) {
13
+ this.inner = new Epub$1(info, chapters);
14
+ }
15
+ /** Attach additional CSS stylesheets. Linked after `css` (from info), in order. */
16
+ setStylesheets(stylesheets) {
17
+ this.inner.setStylesheets(stylesheets);
18
+ }
19
+ /** Attach images. `data` may be a `Uint8Array` or a base64-encoded string. */
20
+ setImages(images) {
21
+ this.inner.setImages(images.map((img) => ({
22
+ ...img,
23
+ data: resolveData(img.data)
24
+ })));
25
+ }
26
+ /**
27
+ * Build the EPUB and return its bytes as a `Uint8Array`.
28
+ * No filesystem access is performed — use `Blob` + `URL.createObjectURL` to download.
29
+ */
30
+ archive() {
31
+ return this.inner.archive();
32
+ }
33
+ };
34
+ /**
35
+ * Resolves once the WASM module is initialised.
36
+ *
37
+ * ```ts
38
+ * import { Epub, ready } from 'epub-gen3/browser'
39
+ * await ready
40
+ * const epub = new Epub(info, chapters)
41
+ * ```
42
+ */
43
+ const ready = wasmInit().then(() => void 0);
44
+ //#endregion
45
+ export { Epub, ready };
@@ -0,0 +1,59 @@
1
+ //#region src/types.d.ts
2
+ /** Metadata for the EPUB document. */
3
+ interface EpubInfo {
4
+ title: string;
5
+ description: string;
6
+ publisher: string;
7
+ author: string;
8
+ /** Label used for the Table of Contents page. */
9
+ tocTitle: string;
10
+ lang: string;
11
+ fonts: string[];
12
+ /** Raw CSS injected as `styles.css`. Omit for an empty stylesheet. */
13
+ css?: string;
14
+ /** EPUB spec version (use `3`). */
15
+ version: number;
16
+ /** Raw XML written to `META-INF/encryption.xml`. Omit to skip. */
17
+ encryption?: string;
18
+ /** Raw XML written to `META-INF/metadata.xml`. Omit to skip. */
19
+ metadataXml?: string;
20
+ /** Raw XML written to `META-INF/manifest.xml`. Omit to skip. */
21
+ manifestXml?: string;
22
+ }
23
+ //#endregion
24
+ //#region src/node.d.ts
25
+ interface EpubStylesheet {
26
+ id: string;
27
+ path: string;
28
+ content: string;
29
+ }
30
+ interface EpubImage {
31
+ id: string;
32
+ path: string;
33
+ /** Raw image bytes as a `Buffer`, or a base64-encoded string. */
34
+ data: Buffer | string;
35
+ /** When `true`, this image is the book cover (at most one). */
36
+ cover: boolean;
37
+ }
38
+ /** EPUB builder — Node.js native addon. */
39
+ declare class Epub {
40
+ private inner;
41
+ constructor(info: EpubInfo, chapters: string[][]);
42
+ /** Attach additional CSS stylesheets. Linked after `css` (from info), in order. */
43
+ setStylesheets(stylesheets: EpubStylesheet[]): void;
44
+ /** Attach images. `data` may be a `Buffer` or a base64-encoded string. */
45
+ setImages(images: EpubImage[]): void;
46
+ /** Build the EPUB and write it to `<title>.epub` in the current working directory. */
47
+ run(): void;
48
+ /**
49
+ * Build the EPUB and return its contents as a `Buffer`.
50
+ *
51
+ * ```ts
52
+ * const buf = epub.archive()
53
+ * fs.writeFileSync('book.epub', buf)
54
+ * ```
55
+ */
56
+ archive(): Buffer;
57
+ }
58
+ //#endregion
59
+ export { Epub, EpubImage, type EpubInfo, EpubStylesheet };
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { createRequire } from "node:module";
2
+ //#region src/node.ts
3
+ const NapiEpub = createRequire(import.meta.url)("../index.js").Epub;
4
+ function resolveData(data) {
5
+ return typeof data === "string" ? Buffer.from(data, "base64") : data;
6
+ }
7
+ /** EPUB builder — Node.js native addon. */
8
+ var Epub = class {
9
+ constructor(info, chapters) {
10
+ this.inner = new NapiEpub(info, chapters);
11
+ }
12
+ /** Attach additional CSS stylesheets. Linked after `css` (from info), in order. */
13
+ setStylesheets(stylesheets) {
14
+ this.inner.setStylesheets(stylesheets);
15
+ }
16
+ /** Attach images. `data` may be a `Buffer` or a base64-encoded string. */
17
+ setImages(images) {
18
+ this.inner.setImages(images.map((img) => ({
19
+ ...img,
20
+ data: resolveData(img.data)
21
+ })));
22
+ }
23
+ /** Build the EPUB and write it to `<title>.epub` in the current working directory. */
24
+ run() {
25
+ this.inner.run();
26
+ }
27
+ /**
28
+ * Build the EPUB and return its contents as a `Buffer`.
29
+ *
30
+ * ```ts
31
+ * const buf = epub.archive()
32
+ * fs.writeFileSync('book.epub', buf)
33
+ * ```
34
+ */
35
+ archive() {
36
+ return this.inner.archive();
37
+ }
38
+ };
39
+ //#endregion
40
+ export { Epub };
Binary file
package/index.d.ts CHANGED
@@ -24,6 +24,15 @@ export interface EpubInfo {
24
24
  /** Raw XML written to `META-INF/manifest.xml`. Pass `null` to omit. */
25
25
  manifestXml?: string
26
26
  }
27
+ /** A CSS stylesheet included in the EPUB. */
28
+ export interface EpubStylesheet {
29
+ /** Unique manifest id (letters, digits, `-`, `_`). */
30
+ id: string
31
+ /** Path relative to `OEBPS/`, e.g. `"css/typography.css"`. */
32
+ path: string
33
+ /** Raw CSS content. */
34
+ content: string
35
+ }
27
36
  /**
28
37
  * An image embedded in the EPUB.
29
38
  *
@@ -62,6 +71,8 @@ export interface EpubImage {
62
71
  export declare class Epub {
63
72
  /** Create a new EPUB builder. */
64
73
  constructor(info: EpubInfo, chapters: Array<Array<string>>)
74
+ /** Attach additional CSS stylesheets. Linked after `css` (from `EpubInfo`), in order. */
75
+ setStylesheets(stylesheets: Array<EpubStylesheet>): void
65
76
  /**
66
77
  * Attach images to the EPUB. Pass an array of `EpubImage` objects.
67
78
  * Flag exactly one with `cover: true` to set the book cover.
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "epub-gen3",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Generate EPUB files from Rust — Node.js native addon",
5
+ "type": "module",
5
6
  "main": "index.js",
6
- "browser": "./browser.js",
7
- "types": "index.d.ts",
7
+ "browser": "./dist/browser.mjs",
8
+ "types": "dist/index.d.mts",
8
9
  "exports": {
9
10
  ".": {
10
- "browser": "./browser.js",
11
- "import": "./index.mjs",
11
+ "browser": "./dist/browser.mjs",
12
+ "import": "./dist/index.mjs",
12
13
  "require": "./index.js"
13
14
  },
14
- "./browser": "./browser.js",
15
+ "./browser": {
16
+ "import": "./dist/browser.mjs",
17
+ "types": "./dist/browser.d.mts"
18
+ },
15
19
  "./wasm/*": "./wasm/*"
16
20
  },
17
21
  "napi": {
@@ -28,20 +32,24 @@
28
32
  "scripts": {
29
33
  "build": "napi build --platform --release",
30
34
  "build:debug": "napi build --platform",
31
- "build:wasm": "wasm-pack build ../wasm --target web --out-dir ../node/wasm",
32
- "build:all": "napi build --platform --release && npm run build:wasm"
35
+ "build:ts": "tsdown",
36
+ "build:wasm": "wasm-pack build ../wasm --target web --out-dir ../node/wasm && node -e \"require('fs').writeFileSync('wasm/.gitignore', '')\"",
37
+ "build:all": "napi build --platform --release && npm run build:wasm && npm run build:ts",
38
+ "prepublishOnly": "npm run build:wasm && npm run build:ts"
33
39
  },
34
40
  "devDependencies": {
35
41
  "@napi-rs/cli": "^2.18.0",
42
+ "@types/node": "^20.0.0",
43
+ "tsdown": "^0.22.2",
44
+ "typescript": "^5.4.0",
36
45
  "wasm-pack": "^0.13.1"
37
46
  },
38
47
  "files": [
39
48
  "index.js",
40
- "index.mjs",
41
- "browser.js",
42
49
  "index.d.ts",
50
+ "dist/",
43
51
  "*.node",
44
52
  "wasm/"
45
53
  ],
46
54
  "license": "MIT"
47
- }
55
+ }
@@ -0,0 +1,91 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * EPUB builder for browser environments.
6
+ *
7
+ * ```js
8
+ * import init, { Epub } from 'epub-gen3/wasm/epub_gen_wasm.js'
9
+ * await init()
10
+ *
11
+ * const epub = new Epub(
12
+ * { title: 'My Book', description: '...', publisher: '...', author: '...',
13
+ * tocTitle: 'Contents', lang: 'en', fonts: [], version: 3 },
14
+ * [['Chapter One', 'First paragraph.', 'Second paragraph.']]
15
+ * )
16
+ * const bytes = epub.archive() // Uint8Array
17
+ * const blob = new Blob([bytes], { type: 'application/epub+zip' })
18
+ * const url = URL.createObjectURL(blob)
19
+ * ```
20
+ */
21
+ export class Epub {
22
+ free(): void;
23
+ [Symbol.dispose](): void;
24
+ /**
25
+ * Build the EPUB and return its bytes as a `Uint8Array`.
26
+ *
27
+ * No filesystem access is performed — it is up to the caller to write or
28
+ * stream the returned bytes (e.g. via `Blob` + `URL.createObjectURL`).
29
+ */
30
+ archive(): Uint8Array;
31
+ /**
32
+ * Create a new EPUB builder.
33
+ *
34
+ * `info` — plain JS object matching `EpubInfo`.
35
+ * `chapters` — `string[][]` where index 0 of each inner array is the
36
+ * chapter title and remaining entries become `<p>` elements.
37
+ */
38
+ constructor(info: any, chapters: any);
39
+ /**
40
+ * Attach images. Pass an array of `{ id, path, data, cover }` objects
41
+ * where `data` is a `Uint8Array` of the raw image bytes. Flag exactly one
42
+ * with `cover: true` to set the book cover.
43
+ */
44
+ setImages(images: any): void;
45
+ /**
46
+ * Attach additional CSS stylesheets. Linked after `css` (from info), in order.
47
+ * Each entry: `{ id: string, path: string, content: string }`.
48
+ */
49
+ setStylesheets(stylesheets: any): void;
50
+ }
51
+
52
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
53
+
54
+ export interface InitOutput {
55
+ readonly memory: WebAssembly.Memory;
56
+ readonly __wbg_epub_free: (a: number, b: number) => void;
57
+ readonly epub_archive: (a: number) => [number, number, number, number];
58
+ readonly epub_new: (a: any, b: any) => [number, number, number];
59
+ readonly epub_setImages: (a: number, b: any) => [number, number];
60
+ readonly epub_setStylesheets: (a: number, b: any) => [number, number];
61
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
62
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
63
+ readonly __wbindgen_exn_store: (a: number) => void;
64
+ readonly __externref_table_alloc: () => number;
65
+ readonly __wbindgen_externrefs: WebAssembly.Table;
66
+ readonly __externref_table_dealloc: (a: number) => void;
67
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
68
+ readonly __wbindgen_start: () => void;
69
+ }
70
+
71
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
72
+
73
+ /**
74
+ * Instantiates the given `module`, which can either be bytes or
75
+ * a precompiled `WebAssembly.Module`.
76
+ *
77
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
78
+ *
79
+ * @returns {InitOutput}
80
+ */
81
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
82
+
83
+ /**
84
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
85
+ * for everything else, calls `WebAssembly.instantiate` directly.
86
+ *
87
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
88
+ *
89
+ * @returns {Promise<InitOutput>}
90
+ */
91
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,546 @@
1
+ /* @ts-self-types="./epub_gen_wasm.d.ts" */
2
+
3
+ /**
4
+ * EPUB builder for browser environments.
5
+ *
6
+ * ```js
7
+ * import init, { Epub } from 'epub-gen3/wasm/epub_gen_wasm.js'
8
+ * await init()
9
+ *
10
+ * const epub = new Epub(
11
+ * { title: 'My Book', description: '...', publisher: '...', author: '...',
12
+ * tocTitle: 'Contents', lang: 'en', fonts: [], version: 3 },
13
+ * [['Chapter One', 'First paragraph.', 'Second paragraph.']]
14
+ * )
15
+ * const bytes = epub.archive() // Uint8Array
16
+ * const blob = new Blob([bytes], { type: 'application/epub+zip' })
17
+ * const url = URL.createObjectURL(blob)
18
+ * ```
19
+ */
20
+ export class Epub {
21
+ __destroy_into_raw() {
22
+ const ptr = this.__wbg_ptr;
23
+ this.__wbg_ptr = 0;
24
+ EpubFinalization.unregister(this);
25
+ return ptr;
26
+ }
27
+ free() {
28
+ const ptr = this.__destroy_into_raw();
29
+ wasm.__wbg_epub_free(ptr, 0);
30
+ }
31
+ /**
32
+ * Build the EPUB and return its bytes as a `Uint8Array`.
33
+ *
34
+ * No filesystem access is performed — it is up to the caller to write or
35
+ * stream the returned bytes (e.g. via `Blob` + `URL.createObjectURL`).
36
+ * @returns {Uint8Array}
37
+ */
38
+ archive() {
39
+ const ret = wasm.epub_archive(this.__wbg_ptr);
40
+ if (ret[3]) {
41
+ throw takeFromExternrefTable0(ret[2]);
42
+ }
43
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
44
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
45
+ return v1;
46
+ }
47
+ /**
48
+ * Create a new EPUB builder.
49
+ *
50
+ * `info` — plain JS object matching `EpubInfo`.
51
+ * `chapters` — `string[][]` where index 0 of each inner array is the
52
+ * chapter title and remaining entries become `<p>` elements.
53
+ * @param {any} info
54
+ * @param {any} chapters
55
+ */
56
+ constructor(info, chapters) {
57
+ const ret = wasm.epub_new(info, chapters);
58
+ if (ret[2]) {
59
+ throw takeFromExternrefTable0(ret[1]);
60
+ }
61
+ this.__wbg_ptr = ret[0];
62
+ EpubFinalization.register(this, this.__wbg_ptr, this);
63
+ return this;
64
+ }
65
+ /**
66
+ * Attach images. Pass an array of `{ id, path, data, cover }` objects
67
+ * where `data` is a `Uint8Array` of the raw image bytes. Flag exactly one
68
+ * with `cover: true` to set the book cover.
69
+ * @param {any} images
70
+ */
71
+ setImages(images) {
72
+ const ret = wasm.epub_setImages(this.__wbg_ptr, images);
73
+ if (ret[1]) {
74
+ throw takeFromExternrefTable0(ret[0]);
75
+ }
76
+ }
77
+ /**
78
+ * Attach additional CSS stylesheets. Linked after `css` (from info), in order.
79
+ * Each entry: `{ id: string, path: string, content: string }`.
80
+ * @param {any} stylesheets
81
+ */
82
+ setStylesheets(stylesheets) {
83
+ const ret = wasm.epub_setStylesheets(this.__wbg_ptr, stylesheets);
84
+ if (ret[1]) {
85
+ throw takeFromExternrefTable0(ret[0]);
86
+ }
87
+ }
88
+ }
89
+ if (Symbol.dispose) Epub.prototype[Symbol.dispose] = Epub.prototype.free;
90
+ function __wbg_get_imports() {
91
+ const import0 = {
92
+ __proto__: null,
93
+ __wbg_Error_9dc85fe1bc224456: function(arg0, arg1) {
94
+ const ret = Error(getStringFromWasm0(arg0, arg1));
95
+ return ret;
96
+ },
97
+ __wbg_Number_4779d427bae39753: function(arg0) {
98
+ const ret = Number(arg0);
99
+ return ret;
100
+ },
101
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
102
+ const ret = String(arg1);
103
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
104
+ const len1 = WASM_VECTOR_LEN;
105
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
106
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
107
+ },
108
+ __wbg___wbindgen_boolean_get_b131b2f36d6b2f55: function(arg0) {
109
+ const v = arg0;
110
+ const ret = typeof(v) === 'boolean' ? v : undefined;
111
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
112
+ },
113
+ __wbg___wbindgen_debug_string_56c147eb1a51f0c4: function(arg0, arg1) {
114
+ const ret = debugString(arg1);
115
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
116
+ const len1 = WASM_VECTOR_LEN;
117
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
118
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
119
+ },
120
+ __wbg___wbindgen_in_ce8569b2fc6f5088: function(arg0, arg1) {
121
+ const ret = arg0 in arg1;
122
+ return ret;
123
+ },
124
+ __wbg___wbindgen_is_function_147961669f068cd4: function(arg0) {
125
+ const ret = typeof(arg0) === 'function';
126
+ return ret;
127
+ },
128
+ __wbg___wbindgen_is_object_3a2c414391dbf751: function(arg0) {
129
+ const val = arg0;
130
+ const ret = typeof(val) === 'object' && val !== null;
131
+ return ret;
132
+ },
133
+ __wbg___wbindgen_is_undefined_4410e3c20a99fa97: function(arg0) {
134
+ const ret = arg0 === undefined;
135
+ return ret;
136
+ },
137
+ __wbg___wbindgen_jsval_loose_eq_e07e3b1f5db6da6c: function(arg0, arg1) {
138
+ const ret = arg0 == arg1;
139
+ return ret;
140
+ },
141
+ __wbg___wbindgen_number_get_588ed6b97f0d7e14: function(arg0, arg1) {
142
+ const obj = arg1;
143
+ const ret = typeof(obj) === 'number' ? obj : undefined;
144
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
145
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
146
+ },
147
+ __wbg___wbindgen_string_get_fa2687d531ed17a5: function(arg0, arg1) {
148
+ const obj = arg1;
149
+ const ret = typeof(obj) === 'string' ? obj : undefined;
150
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
151
+ var len1 = WASM_VECTOR_LEN;
152
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
153
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
154
+ },
155
+ __wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
156
+ throw new Error(getStringFromWasm0(arg0, arg1));
157
+ },
158
+ __wbg_call_91f00ddc43e01490: function() { return handleError(function (arg0, arg1) {
159
+ const ret = arg0.call(arg1);
160
+ return ret;
161
+ }, arguments); },
162
+ __wbg_done_6a8439e544ec6206: function(arg0) {
163
+ const ret = arg0.done;
164
+ return ret;
165
+ },
166
+ __wbg_getRandomValues_a697888e9ba1eee3: function() { return handleError(function (arg0, arg1) {
167
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
168
+ }, arguments); },
169
+ __wbg_getTime_ef2e115ede346a26: function(arg0) {
170
+ const ret = arg0.getTime();
171
+ return ret;
172
+ },
173
+ __wbg_get_44e98e27bda25b5b: function() { return handleError(function (arg0, arg1) {
174
+ const ret = Reflect.get(arg0, arg1);
175
+ return ret;
176
+ }, arguments); },
177
+ __wbg_get_unchecked_46e778e3cec74b5e: function(arg0, arg1) {
178
+ const ret = arg0[arg1 >>> 0];
179
+ return ret;
180
+ },
181
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
182
+ const ret = arg0[arg1];
183
+ return ret;
184
+ },
185
+ __wbg_instanceof_ArrayBuffer_a581da923203f29f: function(arg0) {
186
+ let result;
187
+ try {
188
+ result = arg0 instanceof ArrayBuffer;
189
+ } catch (_) {
190
+ result = false;
191
+ }
192
+ const ret = result;
193
+ return ret;
194
+ },
195
+ __wbg_instanceof_Uint8Array_b6fe1ac89eba107e: function(arg0) {
196
+ let result;
197
+ try {
198
+ result = arg0 instanceof Uint8Array;
199
+ } catch (_) {
200
+ result = false;
201
+ }
202
+ const ret = result;
203
+ return ret;
204
+ },
205
+ __wbg_isArray_139f48e3c057ede8: function(arg0) {
206
+ const ret = Array.isArray(arg0);
207
+ return ret;
208
+ },
209
+ __wbg_isSafeInteger_c22ccb4af2201fe9: function(arg0) {
210
+ const ret = Number.isSafeInteger(arg0);
211
+ return ret;
212
+ },
213
+ __wbg_iterator_9b36cebf3be7b7cd: function() {
214
+ const ret = Symbol.iterator;
215
+ return ret;
216
+ },
217
+ __wbg_length_68a9d5278d084f4f: function(arg0) {
218
+ const ret = arg0.length;
219
+ return ret;
220
+ },
221
+ __wbg_length_fb04d16d7bdf6d4c: function(arg0) {
222
+ const ret = arg0.length;
223
+ return ret;
224
+ },
225
+ __wbg_new_0_878c6ec3a1c600f3: function() {
226
+ const ret = new Date();
227
+ return ret;
228
+ },
229
+ __wbg_new_b06772b280cc6e52: function(arg0) {
230
+ const ret = new Uint8Array(arg0);
231
+ return ret;
232
+ },
233
+ __wbg_next_8cb028b6ba50743f: function() { return handleError(function (arg0) {
234
+ const ret = arg0.next();
235
+ return ret;
236
+ }, arguments); },
237
+ __wbg_next_cfd0b146c9538df8: function(arg0) {
238
+ const ret = arg0.next;
239
+ return ret;
240
+ },
241
+ __wbg_prototypesetcall_956c7493c68e29b4: function(arg0, arg1, arg2) {
242
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
243
+ },
244
+ __wbg_value_3d3defe09fb1ffca: function(arg0) {
245
+ const ret = arg0.value;
246
+ return ret;
247
+ },
248
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
249
+ // Cast intrinsic for `Ref(String) -> Externref`.
250
+ const ret = getStringFromWasm0(arg0, arg1);
251
+ return ret;
252
+ },
253
+ __wbindgen_init_externref_table: function() {
254
+ const table = wasm.__wbindgen_externrefs;
255
+ const offset = table.grow(4);
256
+ table.set(0, undefined);
257
+ table.set(offset + 0, undefined);
258
+ table.set(offset + 1, null);
259
+ table.set(offset + 2, true);
260
+ table.set(offset + 3, false);
261
+ },
262
+ };
263
+ return {
264
+ __proto__: null,
265
+ "./epub_gen_wasm_bg.js": import0,
266
+ };
267
+ }
268
+
269
+ const EpubFinalization = (typeof FinalizationRegistry === 'undefined')
270
+ ? { register: () => {}, unregister: () => {} }
271
+ : new FinalizationRegistry(ptr => wasm.__wbg_epub_free(ptr, 1));
272
+
273
+ function addToExternrefTable0(obj) {
274
+ const idx = wasm.__externref_table_alloc();
275
+ wasm.__wbindgen_externrefs.set(idx, obj);
276
+ return idx;
277
+ }
278
+
279
+ function debugString(val) {
280
+ // primitive types
281
+ const type = typeof val;
282
+ if (type == 'number' || type == 'boolean' || val == null) {
283
+ return `${val}`;
284
+ }
285
+ if (type == 'string') {
286
+ return `"${val}"`;
287
+ }
288
+ if (type == 'symbol') {
289
+ const description = val.description;
290
+ if (description == null) {
291
+ return 'Symbol';
292
+ } else {
293
+ return `Symbol(${description})`;
294
+ }
295
+ }
296
+ if (type == 'function') {
297
+ const name = val.name;
298
+ if (typeof name == 'string' && name.length > 0) {
299
+ return `Function(${name})`;
300
+ } else {
301
+ return 'Function';
302
+ }
303
+ }
304
+ // objects
305
+ if (Array.isArray(val)) {
306
+ const length = val.length;
307
+ let debug = '[';
308
+ if (length > 0) {
309
+ debug += debugString(val[0]);
310
+ }
311
+ for(let i = 1; i < length; i++) {
312
+ debug += ', ' + debugString(val[i]);
313
+ }
314
+ debug += ']';
315
+ return debug;
316
+ }
317
+ // Test for built-in
318
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
319
+ let className;
320
+ if (builtInMatches && builtInMatches.length > 1) {
321
+ className = builtInMatches[1];
322
+ } else {
323
+ // Failed to match the standard '[object ClassName]'
324
+ return toString.call(val);
325
+ }
326
+ if (className == 'Object') {
327
+ // we're a user defined class or Object
328
+ // JSON.stringify avoids problems with cycles, and is generally much
329
+ // easier than looping through ownProperties of `val`.
330
+ try {
331
+ return 'Object(' + JSON.stringify(val) + ')';
332
+ } catch (_) {
333
+ return 'Object';
334
+ }
335
+ }
336
+ // errors
337
+ if (val instanceof Error) {
338
+ return `${val.name}: ${val.message}\n${val.stack}`;
339
+ }
340
+ // TODO we could test for more things here, like `Set`s and `Map`s.
341
+ return className;
342
+ }
343
+
344
+ function getArrayU8FromWasm0(ptr, len) {
345
+ ptr = ptr >>> 0;
346
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
347
+ }
348
+
349
+ let cachedDataViewMemory0 = null;
350
+ function getDataViewMemory0() {
351
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
352
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
353
+ }
354
+ return cachedDataViewMemory0;
355
+ }
356
+
357
+ function getStringFromWasm0(ptr, len) {
358
+ return decodeText(ptr >>> 0, len);
359
+ }
360
+
361
+ let cachedUint8ArrayMemory0 = null;
362
+ function getUint8ArrayMemory0() {
363
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
364
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
365
+ }
366
+ return cachedUint8ArrayMemory0;
367
+ }
368
+
369
+ function handleError(f, args) {
370
+ try {
371
+ return f.apply(this, args);
372
+ } catch (e) {
373
+ const idx = addToExternrefTable0(e);
374
+ wasm.__wbindgen_exn_store(idx);
375
+ }
376
+ }
377
+
378
+ function isLikeNone(x) {
379
+ return x === undefined || x === null;
380
+ }
381
+
382
+ function passStringToWasm0(arg, malloc, realloc) {
383
+ if (realloc === undefined) {
384
+ const buf = cachedTextEncoder.encode(arg);
385
+ const ptr = malloc(buf.length, 1) >>> 0;
386
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
387
+ WASM_VECTOR_LEN = buf.length;
388
+ return ptr;
389
+ }
390
+
391
+ let len = arg.length;
392
+ let ptr = malloc(len, 1) >>> 0;
393
+
394
+ const mem = getUint8ArrayMemory0();
395
+
396
+ let offset = 0;
397
+
398
+ for (; offset < len; offset++) {
399
+ const code = arg.charCodeAt(offset);
400
+ if (code > 0x7F) break;
401
+ mem[ptr + offset] = code;
402
+ }
403
+ if (offset !== len) {
404
+ if (offset !== 0) {
405
+ arg = arg.slice(offset);
406
+ }
407
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
408
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
409
+ const ret = cachedTextEncoder.encodeInto(arg, view);
410
+
411
+ offset += ret.written;
412
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
413
+ }
414
+
415
+ WASM_VECTOR_LEN = offset;
416
+ return ptr;
417
+ }
418
+
419
+ function takeFromExternrefTable0(idx) {
420
+ const value = wasm.__wbindgen_externrefs.get(idx);
421
+ wasm.__externref_table_dealloc(idx);
422
+ return value;
423
+ }
424
+
425
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
426
+ cachedTextDecoder.decode();
427
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
428
+ let numBytesDecoded = 0;
429
+ function decodeText(ptr, len) {
430
+ numBytesDecoded += len;
431
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
432
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
433
+ cachedTextDecoder.decode();
434
+ numBytesDecoded = len;
435
+ }
436
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
437
+ }
438
+
439
+ const cachedTextEncoder = new TextEncoder();
440
+
441
+ if (!('encodeInto' in cachedTextEncoder)) {
442
+ cachedTextEncoder.encodeInto = function (arg, view) {
443
+ const buf = cachedTextEncoder.encode(arg);
444
+ view.set(buf);
445
+ return {
446
+ read: arg.length,
447
+ written: buf.length
448
+ };
449
+ };
450
+ }
451
+
452
+ let WASM_VECTOR_LEN = 0;
453
+
454
+ let wasmModule, wasmInstance, wasm;
455
+ function __wbg_finalize_init(instance, module) {
456
+ wasmInstance = instance;
457
+ wasm = instance.exports;
458
+ wasmModule = module;
459
+ cachedDataViewMemory0 = null;
460
+ cachedUint8ArrayMemory0 = null;
461
+ wasm.__wbindgen_start();
462
+ return wasm;
463
+ }
464
+
465
+ async function __wbg_load(module, imports) {
466
+ if (typeof Response === 'function' && module instanceof Response) {
467
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
468
+ try {
469
+ return await WebAssembly.instantiateStreaming(module, imports);
470
+ } catch (e) {
471
+ const validResponse = module.ok && expectedResponseType(module.type);
472
+
473
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
474
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
475
+
476
+ } else { throw e; }
477
+ }
478
+ }
479
+
480
+ const bytes = await module.arrayBuffer();
481
+ return await WebAssembly.instantiate(bytes, imports);
482
+ } else {
483
+ const instance = await WebAssembly.instantiate(module, imports);
484
+
485
+ if (instance instanceof WebAssembly.Instance) {
486
+ return { instance, module };
487
+ } else {
488
+ return instance;
489
+ }
490
+ }
491
+
492
+ function expectedResponseType(type) {
493
+ switch (type) {
494
+ case 'basic': case 'cors': case 'default': return true;
495
+ }
496
+ return false;
497
+ }
498
+ }
499
+
500
+ function initSync(module) {
501
+ if (wasm !== undefined) return wasm;
502
+
503
+
504
+ if (module !== undefined) {
505
+ if (Object.getPrototypeOf(module) === Object.prototype) {
506
+ ({module} = module)
507
+ } else {
508
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
509
+ }
510
+ }
511
+
512
+ const imports = __wbg_get_imports();
513
+ if (!(module instanceof WebAssembly.Module)) {
514
+ module = new WebAssembly.Module(module);
515
+ }
516
+ const instance = new WebAssembly.Instance(module, imports);
517
+ return __wbg_finalize_init(instance, module);
518
+ }
519
+
520
+ async function __wbg_init(module_or_path) {
521
+ if (wasm !== undefined) return wasm;
522
+
523
+
524
+ if (module_or_path !== undefined) {
525
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
526
+ ({module_or_path} = module_or_path)
527
+ } else {
528
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
529
+ }
530
+ }
531
+
532
+ if (module_or_path === undefined) {
533
+ module_or_path = new URL('epub_gen_wasm_bg.wasm', import.meta.url);
534
+ }
535
+ const imports = __wbg_get_imports();
536
+
537
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
538
+ module_or_path = fetch(module_or_path);
539
+ }
540
+
541
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
542
+
543
+ return __wbg_finalize_init(instance, module);
544
+ }
545
+
546
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,16 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_epub_free: (a: number, b: number) => void;
5
+ export const epub_archive: (a: number) => [number, number, number, number];
6
+ export const epub_new: (a: any, b: any) => [number, number, number];
7
+ export const epub_setImages: (a: number, b: any) => [number, number];
8
+ export const epub_setStylesheets: (a: number, b: any) => [number, number];
9
+ export const __wbindgen_malloc: (a: number, b: number) => number;
10
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
11
+ export const __wbindgen_exn_store: (a: number) => void;
12
+ export const __externref_table_alloc: () => number;
13
+ export const __wbindgen_externrefs: WebAssembly.Table;
14
+ export const __externref_table_dealloc: (a: number) => void;
15
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
16
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "epub-gen-wasm",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "files": [
6
+ "epub_gen_wasm_bg.wasm",
7
+ "epub_gen_wasm.js",
8
+ "epub_gen_wasm.d.ts"
9
+ ],
10
+ "main": "epub_gen_wasm.js",
11
+ "types": "epub_gen_wasm.d.ts",
12
+ "sideEffects": [
13
+ "./snippets/*"
14
+ ]
15
+ }
package/browser.js DELETED
@@ -1,14 +0,0 @@
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()
package/index.mjs DELETED
@@ -1,4 +0,0 @@
1
- import { createRequire } from 'module'
2
- const require = createRequire(import.meta.url)
3
- const { Epub } = require('./index.js')
4
- export { Epub }