epub-wasm 0.1.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 ADDED
@@ -0,0 +1,141 @@
1
+ # epub-wasm
2
+
3
+ A Rust crate that compiles to WebAssembly for parsing EPUB files into structured JSON format. This crate provides the core EPUB parsing logic that powers the [`epub-wasm` npm package](pkg/README.md).
4
+
5
+ ## Overview
6
+
7
+ This crate leverages the [`rbook`](https://crates.io/crates/rbook) and [`scraper`](https://crates.io/crates/scraper) crates to parse EPUB files and extract their content into a clean JSON structure with chapters, headings, and paragraphs. The parsed data is then exposed via WebAssembly bindings for use in web applications.
8
+
9
+ ## Features
10
+
11
+ - **EPUB parsing**: Extracts text content from EPUB files
12
+ - **Structured output**: Organizes content into books, chapters, and blocks
13
+ - **WebAssembly compatible**: Designed for compilation to WASM
14
+ - **Fast**: Leverages Rust's performance for efficient parsing
15
+
16
+ ## Building
17
+
18
+ ### Prerequisites
19
+
20
+ - [Rust](https://rustup.rs/) (latest stable)
21
+ - [wasm-pack](https://rustwasm.github.io/wasm-pack/)
22
+
23
+ ### Build for WebAssembly
24
+
25
+ ```bash
26
+ # Install wasm-pack if not installed
27
+ cargo install wasm-pack
28
+
29
+ # Build for bundler (recommended for Vite/SvelteKit)
30
+ wasm-pack build --release --target bundler --out-dir pkg
31
+
32
+ # Or build for web (serves WASM from URL)
33
+ wasm-pack build --release --target web --out-dir pkg
34
+ ```
35
+
36
+ ### Build for Native (Testing)
37
+
38
+ ```bash
39
+ cargo build --release
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ This crate is primarily designed to be compiled to WebAssembly. The main entry point is the `parse_epub` function:
45
+
46
+ ```rust
47
+ use epub_wasm::parse_epub;
48
+
49
+ // Parse EPUB bytes into JSON string
50
+ let epub_data: &[u8] = // ... load EPUB file
51
+ let json_result = parse_epub(epub_data);
52
+ let book: serde_json::Value = serde_json::from_str(&json_result).unwrap();
53
+ ```
54
+
55
+ ## API
56
+
57
+ ### `parse_epub(data: &[u8]) -> String`
58
+
59
+ Parses an EPUB file from raw bytes and returns a JSON string representation.
60
+
61
+ **Parameters:**
62
+
63
+ - `data`: Raw bytes of the EPUB file
64
+
65
+ **Returns:** JSON string with the following structure:
66
+
67
+ ```json
68
+ {
69
+ "id": "book_001",
70
+ "title": "Book Title",
71
+ "chapters": [
72
+ {
73
+ "title": "Chapter Title",
74
+ "id": "chapter_001",
75
+ "blocks": [
76
+ {
77
+ "type": "heading",
78
+ "text": "Heading Text"
79
+ },
80
+ {
81
+ "type": "paragraph",
82
+ "text": "Paragraph text..."
83
+ }
84
+ ]
85
+ }
86
+ ]
87
+ }
88
+ ```
89
+
90
+ ## Dependencies
91
+
92
+ - [`rbook`](https://crates.io/crates/rbook): EPUB parsing library
93
+ - [`scraper`](https://crates.io/crates/scraper): HTML parsing and CSS selector engine
94
+ - [`serde`](https://crates.io/crates/serde): Serialization framework
95
+ - [`wasm-bindgen`](https://crates.io/crates/wasm-bindgen): WebAssembly bindings
96
+
97
+ ## Project Structure
98
+
99
+ ```
100
+ epub-wasm/
101
+ ├── src/
102
+ │ └── lib.rs # Main library code with WASM bindings
103
+ ├── pkg/ # Generated WebAssembly package (after build)
104
+ │ ├── epub_wasm.js
105
+ │ ├── epub_wasm_bg.wasm
106
+ │ └── ...
107
+ ├── Cargo.toml # Package configuration
108
+ └── README.md # This file
109
+ ```
110
+
111
+ ## Development
112
+
113
+ ### Testing
114
+
115
+ ```bash
116
+ cargo test
117
+ ```
118
+
119
+ ### Running the Web Example
120
+
121
+ After building with wasm-pack, you can test the generated package:
122
+
123
+ ```bash
124
+ cd pkg
125
+ # Serve locally (requires a web server)
126
+ python3 -m http.server 8000
127
+ # Then open index.html in browser
128
+ ```
129
+
130
+ ## Contributing
131
+
132
+ Contributions are welcome! Please feel free to submit issues and pull requests.
133
+
134
+ ## License
135
+
136
+ Licensed under MIT/Apache-2.0.
137
+
138
+ ## Related Projects
139
+
140
+ - [`rs-epub`](https://github.com/0xmiki/rs-epub) - Parent Rust project with additional EPUB utilities
141
+ - [`epub-wasm` npm package](pkg/README.md) - The WebAssembly package published to npm
package/epub_wasm.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function parse_epub(data: Uint8Array): string;
package/epub_wasm.js ADDED
@@ -0,0 +1,4 @@
1
+ import * as wasm from "./epub_wasm_bg.wasm";
2
+ export * from "./epub_wasm_bg.js";
3
+ import { __wbg_set_wasm } from "./epub_wasm_bg.js";
4
+ __wbg_set_wasm(wasm);
Binary file
@@ -0,0 +1,8 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const parse_epub: (a: number, b: number, c: number) => void;
5
+ export const __wbindgen_export: (a: number) => void;
6
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
7
+ export const __wbindgen_export2: (a: number, b: number) => number;
8
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "epub-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Mikiyas <0xmik@proton.me>"
6
+ ],
7
+ "description": "EPUB utilities compiled to WebAssembly",
8
+ "version": "0.1.0",
9
+ "license": "MIT/Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/0xmiki/epub-wasm"
13
+ },
14
+ "files": [
15
+ "epub_wasm.js",
16
+ "epub_wasm_bg.wasm",
17
+ "epub_wasm.d.ts",
18
+ "epub_wasm_bg.wasm.d.ts",
19
+ "package.json",
20
+ "README.md"
21
+ ],
22
+ "sideEffects": false,
23
+ "main": "epub_wasm.js",
24
+ "types": "epub_wasm.d.ts"
25
+ }