@veripublica/kepubverto-wasm 0.2.3 → 0.3.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/README.md CHANGED
@@ -31,10 +31,15 @@ const r = convert(new Uint8Array(await file.arrayBuffer()));
31
31
 
32
32
  // The CLI's --hyphens: "auto" turns hyphenation on, "none" off.
33
33
  convert(bytes, "auto");
34
+
35
+ // The CLI's --css, one string per value: CSS added after kepubverto's own.
36
+ convert(bytes, undefined, ["p { text-indent: 1.5em }"]);
34
37
  ```
35
38
 
36
- `convert` throws when the file cannot be read as an EPUB at all, and on a
37
- `hyphens` value other than `"auto"` or `"none"`.
39
+ `convert` throws when the file cannot be read as an EPUB at all, on a
40
+ `hyphens` value other than `"auto"` or `"none"`, and on a refused `css` value
41
+ (it refers to a file, has `@font-face`, or would add a finding epubveri
42
+ reports); the message starts `extra CSS:` and says why.
38
43
 
39
44
  ## License
40
45
 
@@ -42,10 +42,13 @@ export interface Conversion {
42
42
  /**
43
43
  * Convert an EPUB. `hyphens` mirrors the CLI's `--hyphens`: `"auto"` or
44
44
  * `"none"` adds CSS that turns hyphenation on or off; leave it out to let the
45
- * book decide. Throws on any other value, and when the book cannot be read
46
- * at all.
45
+ * book decide. `css` mirrors `--css`, one string per value: CSS added to
46
+ * every converted document, after kepubverto's own. Throws on any other
47
+ * `hyphens` value, on a refused `css` value (the message says why, prefixed
48
+ * `extra CSS:`, plus `value N` when there are several), and when the book
49
+ * cannot be read at all.
47
50
  */
48
- export function convert(epub: Uint8Array, hyphens?: string | null): Conversion;
51
+ export function convert(epub: Uint8Array, hyphens?: string | null, css?: string[] | null): Conversion;
49
52
 
50
53
  /**
51
54
  * The crate version, with the git hash it was built from.
@@ -1,18 +1,24 @@
1
1
  /**
2
2
  * Convert an EPUB. `hyphens` mirrors the CLI's `--hyphens`: `"auto"` or
3
3
  * `"none"` adds CSS that turns hyphenation on or off; leave it out to let the
4
- * book decide. Throws on any other value, and when the book cannot be read
5
- * at all.
4
+ * book decide. `css` mirrors `--css`, one string per value: CSS added to
5
+ * every converted document, after kepubverto's own. Throws on any other
6
+ * `hyphens` value, on a refused `css` value (the message says why, prefixed
7
+ * `extra CSS:`, plus `value N` when there are several), and when the book
8
+ * cannot be read at all.
6
9
  * @param {Uint8Array} epub
7
10
  * @param {string | null} [hyphens]
11
+ * @param {string[] | null} [css]
8
12
  * @returns {Conversion}
9
13
  */
10
- export function convert(epub, hyphens) {
14
+ export function convert(epub, hyphens, css) {
11
15
  const ptr0 = passArray8ToWasm0(epub, wasm.__wbindgen_malloc);
12
16
  const len0 = WASM_VECTOR_LEN;
13
17
  var ptr1 = isLikeNone(hyphens) ? 0 : passStringToWasm0(hyphens, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
14
18
  var len1 = WASM_VECTOR_LEN;
15
- const ret = wasm.convert(ptr0, len0, ptr1, len1);
19
+ var ptr2 = isLikeNone(css) ? 0 : passArrayJsValueToWasm0(css, wasm.__wbindgen_malloc);
20
+ var len2 = WASM_VECTOR_LEN;
21
+ const ret = wasm.convert(ptr0, len0, ptr1, len1, ptr2, len2);
16
22
  if (ret[2]) {
17
23
  throw takeFromExternrefTable0(ret[1]);
18
24
  }
@@ -46,6 +52,14 @@ export function __wbg_String_8564e559799eccda(arg0, arg1) {
46
52
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
47
53
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
48
54
  }
55
+ export function __wbg___wbindgen_string_get_0380ccaa2f57f0d9(arg0, arg1) {
56
+ const obj = arg1;
57
+ const ret = typeof(obj) === 'string' ? obj : undefined;
58
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
59
+ var len1 = WASM_VECTOR_LEN;
60
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
61
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
62
+ }
49
63
  export function __wbg___wbindgen_throw_41e9ee4f547fc59a(arg0, arg1) {
50
64
  throw new Error(getStringFromWasm0(arg0, arg1));
51
65
  }
@@ -100,6 +114,12 @@ export function __wbindgen_init_externref_table() {
100
114
  table.set(offset + 2, true);
101
115
  table.set(offset + 3, false);
102
116
  }
117
+ function addToExternrefTable0(obj) {
118
+ const idx = wasm.__externref_table_alloc();
119
+ wasm.__wbindgen_externrefs.set(idx, obj);
120
+ return idx;
121
+ }
122
+
103
123
  function getArrayU8FromWasm0(ptr, len) {
104
124
  ptr = ptr >>> 0;
105
125
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
@@ -136,6 +156,16 @@ function passArray8ToWasm0(arg, malloc) {
136
156
  return ptr;
137
157
  }
138
158
 
159
+ function passArrayJsValueToWasm0(array, malloc) {
160
+ const ptr = malloc(array.length * 4, 4) >>> 0;
161
+ for (let i = 0; i < array.length; i++) {
162
+ const add = addToExternrefTable0(array[i]);
163
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
164
+ }
165
+ WASM_VECTOR_LEN = array.length;
166
+ return ptr;
167
+ }
168
+
139
169
  function passStringToWasm0(arg, malloc, realloc) {
140
170
  if (realloc === undefined) {
141
171
  const buf = cachedTextEncoder.encode(arg);
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@veripublica/kepubverto-wasm",
3
3
  "type": "module",
4
4
  "description": "WebAssembly bindings for kepubverto — convert EPUB to KEPUB in the browser, no upload.",
5
- "version": "0.2.3",
5
+ "version": "0.3.1",
6
6
  "license": "AGPL-3.0-only OR LicenseRef-veripublica-Commercial",
7
7
  "repository": {
8
8
  "type": "git",