node-docx-html-converter 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 +60 -0
- package/index.cjs +34 -0
- package/index.d.ts +21 -0
- package/index.js +41 -0
- package/node_modules/docx-html-converter/README.md +118 -0
- package/node_modules/docx-html-converter/docx_html_converter.d.ts +29 -0
- package/node_modules/docx-html-converter/docx_html_converter.js +252 -0
- package/node_modules/docx-html-converter/docx_html_converter_bg.wasm +0 -0
- package/node_modules/docx-html-converter/package.json +12 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# node-docx-html-converter
|
|
2
|
+
|
|
3
|
+
DOCX ↔ HTML conversion via Rust WASM. Two main functions:
|
|
4
|
+
|
|
5
|
+
- **docxToHtml** — DOCX bytes → HTML string
|
|
6
|
+
- **htmlToDocx** — HTML string → DOCX bytes
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install node-docx-html-converter
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
### ESM (sync)
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { docxToHtml, htmlToDocx } from 'node-docx-html-converter';
|
|
20
|
+
import fs from 'fs';
|
|
21
|
+
|
|
22
|
+
// DOCX → HTML
|
|
23
|
+
const docxBuffer = fs.readFileSync('document.docx');
|
|
24
|
+
const html = docxToHtml(docxBuffer);
|
|
25
|
+
// or embeddable fragment:
|
|
26
|
+
const embed = docxToHtml(docxBuffer, { embed: true });
|
|
27
|
+
|
|
28
|
+
// HTML → DOCX
|
|
29
|
+
const htmlStr = fs.readFileSync('output.html', 'utf8');
|
|
30
|
+
const docxBytes = htmlToDocx(htmlStr);
|
|
31
|
+
fs.writeFileSync('output.docx', docxBytes);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### CommonJS (sync)
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const { docxToHtml, htmlToDocx } = require('node-docx-html-converter');
|
|
38
|
+
|
|
39
|
+
const html = docxToHtml(docxBuffer);
|
|
40
|
+
const docxBytes = htmlToDocx(htmlStr);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
### docxToHtml(docxBuffer, options?)
|
|
46
|
+
|
|
47
|
+
- `docxBuffer` — `Buffer` or `Uint8Array` with .docx file bytes
|
|
48
|
+
- `options.embed` — if true, returns embeddable fragment (no DOCTYPE)
|
|
49
|
+
- `options.noH4` — when true, bold from paragraph style not applied to list items
|
|
50
|
+
- `options.debugLayout` — when true, adds colored borders for debugging
|
|
51
|
+
- Returns: `string`
|
|
52
|
+
|
|
53
|
+
### htmlToDocx(html)
|
|
54
|
+
|
|
55
|
+
- `html` — HTML string (full document or embed fragment from docx-html-converter)
|
|
56
|
+
- Returns: `Buffer`
|
|
57
|
+
|
|
58
|
+
### calculate_html(html)
|
|
59
|
+
|
|
60
|
+
Recalculates page breaks for contentEditable. Returns reflowed HTML.
|
package/index.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node-docx-html-converter (CommonJS)
|
|
3
|
+
*/
|
|
4
|
+
const pkg = require('docx-html-converter');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Converts DOCX bytes to HTML.
|
|
8
|
+
* @param {Buffer|Uint8Array} docxBuffer - Raw .docx file bytes
|
|
9
|
+
* @param {{ embed?: boolean, noH4?: boolean, debugLayout?: boolean }} [options]
|
|
10
|
+
* @returns {string} HTML string
|
|
11
|
+
*/
|
|
12
|
+
function docxToHtml(docxBuffer, options = {}) {
|
|
13
|
+
const { embed = false, noH4 = false, debugLayout = false } = options;
|
|
14
|
+
const arr = docxBuffer instanceof Uint8Array ? docxBuffer : new Uint8Array(docxBuffer);
|
|
15
|
+
return embed
|
|
16
|
+
? pkg.convert_docx_embed(arr, noH4, debugLayout)
|
|
17
|
+
: pkg.convert_docx(arr, noH4, debugLayout);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Converts HTML to DOCX bytes.
|
|
22
|
+
* @param {string} html - HTML string
|
|
23
|
+
* @returns {Buffer} Raw .docx file bytes
|
|
24
|
+
*/
|
|
25
|
+
function htmlToDocx(html) {
|
|
26
|
+
const result = pkg.convert_html_to_docx(html);
|
|
27
|
+
return Buffer.from(result);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
docxToHtml,
|
|
32
|
+
htmlToDocx,
|
|
33
|
+
calculate_html: pkg.calculate_html,
|
|
34
|
+
};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts DOCX bytes to HTML.
|
|
3
|
+
*/
|
|
4
|
+
export function docxToHtml(
|
|
5
|
+
docxBuffer: Buffer | Uint8Array,
|
|
6
|
+
options?: {
|
|
7
|
+
embed?: boolean;
|
|
8
|
+
noH4?: boolean;
|
|
9
|
+
debugLayout?: boolean;
|
|
10
|
+
}
|
|
11
|
+
): string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Converts HTML (docx-html-converter format) to DOCX bytes.
|
|
15
|
+
*/
|
|
16
|
+
export function htmlToDocx(html: string): Buffer;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Recalculates page breaks in HTML "Word-style".
|
|
20
|
+
*/
|
|
21
|
+
export function calculate_html(html: string): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* node-docx-html-converter
|
|
3
|
+
* DOCX ↔ HTML conversion via Rust WASM.
|
|
4
|
+
*/
|
|
5
|
+
import pkg from 'docx-html-converter';
|
|
6
|
+
const { convert_docx, convert_docx_embed, convert_html_to_docx, calculate_html } = pkg;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts DOCX bytes to HTML.
|
|
10
|
+
* @param {Buffer|Uint8Array} docxBuffer - Raw .docx file bytes
|
|
11
|
+
* @param {{ embed?: boolean, noH4?: boolean, debugLayout?: boolean }} [options]
|
|
12
|
+
* - embed: if true, returns embeddable fragment (no DOCTYPE/html wrapper)
|
|
13
|
+
* - noH4: when true, bold from paragraph style is not applied to list items
|
|
14
|
+
* - debugLayout: when true, adds colored borders for debugging
|
|
15
|
+
* @returns {string} HTML string
|
|
16
|
+
*/
|
|
17
|
+
export function docxToHtml(docxBuffer, options = {}) {
|
|
18
|
+
const { embed = false, noH4 = false, debugLayout = false } = options;
|
|
19
|
+
const arr = docxBuffer instanceof Uint8Array ? docxBuffer : new Uint8Array(docxBuffer);
|
|
20
|
+
return embed
|
|
21
|
+
? convert_docx_embed(arr, noH4, debugLayout)
|
|
22
|
+
: convert_docx(arr, noH4, debugLayout);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Converts HTML (docx-html-converter format) to DOCX bytes.
|
|
27
|
+
* @param {string} html - HTML string (full document or embed fragment)
|
|
28
|
+
* @returns {Buffer} Raw .docx file bytes
|
|
29
|
+
*/
|
|
30
|
+
export function htmlToDocx(html) {
|
|
31
|
+
const result = convert_html_to_docx(html);
|
|
32
|
+
return Buffer.from(result);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Recalculates page breaks in HTML "Word-style".
|
|
37
|
+
* Use when the user edits text in a contentEditable div.
|
|
38
|
+
* @param {string} html - HTML string
|
|
39
|
+
* @returns {string} Reflowed HTML
|
|
40
|
+
*/
|
|
41
|
+
export { calculate_html };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# docx-html-converter
|
|
2
|
+
|
|
3
|
+
Конвертер DOCX в HTML на Rust с поддержкой WASM. Преобразует документы Word в HTML с сохранением стилей, таблиц, списков, заголовков и колонтитулов. Верхний padding основного контента равен высоте зоны header (вычисляется после рендера колонтитулов).
|
|
4
|
+
|
|
5
|
+
## Установка
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install docx-html-converter
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
### `convert_docx(docx_buffer, no_h4?, debug_layout?)`
|
|
14
|
+
|
|
15
|
+
Конвертирует DOCX в полный HTML-документ (DOCTYPE, html, head, body).
|
|
16
|
+
|
|
17
|
+
- **docx_buffer** — `Uint8Array` с байтами .docx файла
|
|
18
|
+
- **no_h4** — опционально; при `true` жирный из стиля параграфа (например, Heading 4) не применяется к элементам списка
|
|
19
|
+
- **debug_layout** — опционально; при `true` добавляет яркие цветные рамки для отладки (красный=страница, зелёный=контент, синий=header, оранжевый=footer, фиолетовый=таблица)
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { convert_docx } from 'docx-html-converter';
|
|
23
|
+
|
|
24
|
+
const response = await fetch('/document.docx');
|
|
25
|
+
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
26
|
+
const html = convert_docx(buffer);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### `convert_docx_embed(docx_buffer, no_h4?, debug_layout?)`
|
|
30
|
+
|
|
31
|
+
Конвертирует DOCX в встраиваемый HTML-фрагмент (div со стилями, без обёртки документа). Подходит для вставки в существующую страницу. При `debug_layout: true` — цветные рамки для отладки (см. выше).
|
|
32
|
+
|
|
33
|
+
Каждый div страницы (`.page`) имеет `id="document-docx-{номер}"` и атрибут `contenteditable` для редактирования на фронтенде.
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
import { convert_docx_embed } from 'docx-html-converter';
|
|
37
|
+
|
|
38
|
+
const embed = convert_docx_embed(buffer);
|
|
39
|
+
document.getElementById('editor').innerHTML = embed;
|
|
40
|
+
// Каждая страница: <div class="page" id="document-docx-1" contenteditable>...
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### `calculate_html(html)`
|
|
44
|
+
|
|
45
|
+
Пересчитывает разбиение на страницы в HTML «по-вордовски». Используйте при редактировании текста в contentEditable — передайте обновлённый HTML, чтобы получить переразбитый контент.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import { convert_docx_embed, calculate_html } from 'docx-html-converter';
|
|
49
|
+
|
|
50
|
+
const embed = convert_docx_embed(buffer);
|
|
51
|
+
const container = document.getElementById('editor');
|
|
52
|
+
container.innerHTML = embed;
|
|
53
|
+
|
|
54
|
+
// Для пересчёта страниц нужен полный HTML: обёртка docx-html-embed + стили + страницы
|
|
55
|
+
container.addEventListener('input', () => {
|
|
56
|
+
const htmlForRecalc = getHtmlForRecalculate(container);
|
|
57
|
+
const recalculated = calculate_html(htmlForRecalc);
|
|
58
|
+
container.innerHTML = recalculated;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Возвращает HTML, готовый для calculate_html.
|
|
63
|
+
* Нужен полный фрагмент: div.docx-html-embed + <style> + страницы.
|
|
64
|
+
* container — либо сам embed, либо родитель (например #editor).
|
|
65
|
+
*/
|
|
66
|
+
function getHtmlForRecalculate(container: HTMLElement): string {
|
|
67
|
+
const embed =
|
|
68
|
+
container.closest?.('.docx-html-embed') ??
|
|
69
|
+
container.querySelector?.('.docx-html-embed') ??
|
|
70
|
+
container;
|
|
71
|
+
return embed.outerHTML;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Сборка и запуск
|
|
76
|
+
|
|
77
|
+
### DOCX → HTML (Rust)
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
cargo run # выбор .docx из src/files/
|
|
81
|
+
cargo run -- file.docx # указать файл
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### HTML → DOCX
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Сначала: npm install в packages/html-docx-converter
|
|
88
|
+
cd packages/html-docx-converter && npm install && cd ../..
|
|
89
|
+
|
|
90
|
+
cargo run -- to-docx # выбор .html из списка
|
|
91
|
+
cargo run -- to-docx output-embed.html # указать файл
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Результат сохраняется в `packages/html-docx-converter/files/docx_results/`.
|
|
95
|
+
|
|
96
|
+
### npm (Node.js)
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Для bundler (webpack, vite и т.д.)
|
|
100
|
+
npm run build
|
|
101
|
+
|
|
102
|
+
# Для Node.js
|
|
103
|
+
npm run build:node
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Rust
|
|
107
|
+
|
|
108
|
+
Библиотека также доступна как Rust crate:
|
|
109
|
+
|
|
110
|
+
```rust
|
|
111
|
+
use docx_html_converter::{convert_docx_from_bytes, convert_docx_embed_from_bytes, calculate_html};
|
|
112
|
+
|
|
113
|
+
let html = convert_docx_from_bytes(&docx_bytes, false, false)?;
|
|
114
|
+
let embed = convert_docx_embed_from_bytes(&docx_bytes, false, false)?;
|
|
115
|
+
// With debug layout (bright borders: red=page, green=content, blue=header, orange=footer, magenta=table):
|
|
116
|
+
let embed_debug = convert_docx_embed_from_bytes(&docx_bytes, false, true)?;
|
|
117
|
+
let recalculated = calculate_html(&embed)?;
|
|
118
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Recalculates page breaks in HTML "Word-style". Call when the user edits text
|
|
6
|
+
* in a contentEditable div — pass the updated HTML to get reflowed pages.
|
|
7
|
+
*/
|
|
8
|
+
export function calculate_html(html: string): string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Converts DOCX bytes to HTML.
|
|
12
|
+
*
|
|
13
|
+
* * `docx_buffer` — Uint8Array with raw .docx file bytes
|
|
14
|
+
* * `no_h4` — optional; when true, bold from paragraph style is not applied to list items.
|
|
15
|
+
* Omit or pass false for correct default behavior.
|
|
16
|
+
*/
|
|
17
|
+
export function convert_docx(docx_buffer: Uint8Array, no_h4?: boolean | null, debug_layout?: boolean | null): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Converts DOCX bytes to an embeddable HTML fragment (div with styles, no document wrapper).
|
|
21
|
+
* Use when embedding into an existing page. Preserves all styles and fonts.
|
|
22
|
+
*/
|
|
23
|
+
export function convert_docx_embed(docx_buffer: Uint8Array, no_h4?: boolean | null, debug_layout?: boolean | null): string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Converts HTML (docx-html-converter format) to DOCX bytes.
|
|
27
|
+
* Returns Uint8Array with raw .docx file bytes.
|
|
28
|
+
*/
|
|
29
|
+
export function convert_html_to_docx(html: string): Uint8Array;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/* @ts-self-types="./docx_html_converter.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Recalculates page breaks in HTML "Word-style". Call when the user edits text
|
|
5
|
+
* in a contentEditable div — pass the updated HTML to get reflowed pages.
|
|
6
|
+
* @param {string} html
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
function calculate_html(html) {
|
|
10
|
+
let deferred3_0;
|
|
11
|
+
let deferred3_1;
|
|
12
|
+
try {
|
|
13
|
+
const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
14
|
+
const len0 = WASM_VECTOR_LEN;
|
|
15
|
+
const ret = wasm.calculate_html(ptr0, len0);
|
|
16
|
+
var ptr2 = ret[0];
|
|
17
|
+
var len2 = ret[1];
|
|
18
|
+
if (ret[3]) {
|
|
19
|
+
ptr2 = 0; len2 = 0;
|
|
20
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
21
|
+
}
|
|
22
|
+
deferred3_0 = ptr2;
|
|
23
|
+
deferred3_1 = len2;
|
|
24
|
+
return getStringFromWasm0(ptr2, len2);
|
|
25
|
+
} finally {
|
|
26
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.calculate_html = calculate_html;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Converts DOCX bytes to HTML.
|
|
33
|
+
*
|
|
34
|
+
* * `docx_buffer` — Uint8Array with raw .docx file bytes
|
|
35
|
+
* * `no_h4` — optional; when true, bold from paragraph style is not applied to list items.
|
|
36
|
+
* Omit or pass false for correct default behavior.
|
|
37
|
+
* @param {Uint8Array} docx_buffer
|
|
38
|
+
* @param {boolean | null} [no_h4]
|
|
39
|
+
* @param {boolean | null} [debug_layout]
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
function convert_docx(docx_buffer, no_h4, debug_layout) {
|
|
43
|
+
let deferred3_0;
|
|
44
|
+
let deferred3_1;
|
|
45
|
+
try {
|
|
46
|
+
const ptr0 = passArray8ToWasm0(docx_buffer, wasm.__wbindgen_malloc);
|
|
47
|
+
const len0 = WASM_VECTOR_LEN;
|
|
48
|
+
const ret = wasm.convert_docx(ptr0, len0, isLikeNone(no_h4) ? 0xFFFFFF : no_h4 ? 1 : 0, isLikeNone(debug_layout) ? 0xFFFFFF : debug_layout ? 1 : 0);
|
|
49
|
+
var ptr2 = ret[0];
|
|
50
|
+
var len2 = ret[1];
|
|
51
|
+
if (ret[3]) {
|
|
52
|
+
ptr2 = 0; len2 = 0;
|
|
53
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
54
|
+
}
|
|
55
|
+
deferred3_0 = ptr2;
|
|
56
|
+
deferred3_1 = len2;
|
|
57
|
+
return getStringFromWasm0(ptr2, len2);
|
|
58
|
+
} finally {
|
|
59
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.convert_docx = convert_docx;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Converts DOCX bytes to an embeddable HTML fragment (div with styles, no document wrapper).
|
|
66
|
+
* Use when embedding into an existing page. Preserves all styles and fonts.
|
|
67
|
+
* @param {Uint8Array} docx_buffer
|
|
68
|
+
* @param {boolean | null} [no_h4]
|
|
69
|
+
* @param {boolean | null} [debug_layout]
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
function convert_docx_embed(docx_buffer, no_h4, debug_layout) {
|
|
73
|
+
let deferred3_0;
|
|
74
|
+
let deferred3_1;
|
|
75
|
+
try {
|
|
76
|
+
const ptr0 = passArray8ToWasm0(docx_buffer, wasm.__wbindgen_malloc);
|
|
77
|
+
const len0 = WASM_VECTOR_LEN;
|
|
78
|
+
const ret = wasm.convert_docx_embed(ptr0, len0, isLikeNone(no_h4) ? 0xFFFFFF : no_h4 ? 1 : 0, isLikeNone(debug_layout) ? 0xFFFFFF : debug_layout ? 1 : 0);
|
|
79
|
+
var ptr2 = ret[0];
|
|
80
|
+
var len2 = ret[1];
|
|
81
|
+
if (ret[3]) {
|
|
82
|
+
ptr2 = 0; len2 = 0;
|
|
83
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
84
|
+
}
|
|
85
|
+
deferred3_0 = ptr2;
|
|
86
|
+
deferred3_1 = len2;
|
|
87
|
+
return getStringFromWasm0(ptr2, len2);
|
|
88
|
+
} finally {
|
|
89
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.convert_docx_embed = convert_docx_embed;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Converts HTML (docx-html-converter format) to DOCX bytes.
|
|
96
|
+
* Returns Uint8Array with raw .docx file bytes.
|
|
97
|
+
* @param {string} html
|
|
98
|
+
* @returns {Uint8Array}
|
|
99
|
+
*/
|
|
100
|
+
function convert_html_to_docx(html) {
|
|
101
|
+
const ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
102
|
+
const len0 = WASM_VECTOR_LEN;
|
|
103
|
+
const ret = wasm.convert_html_to_docx(ptr0, len0);
|
|
104
|
+
if (ret[3]) {
|
|
105
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
106
|
+
}
|
|
107
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
108
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
109
|
+
return v2;
|
|
110
|
+
}
|
|
111
|
+
exports.convert_html_to_docx = convert_html_to_docx;
|
|
112
|
+
|
|
113
|
+
function __wbg_get_imports() {
|
|
114
|
+
const import0 = {
|
|
115
|
+
__proto__: null,
|
|
116
|
+
__wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {
|
|
117
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
118
|
+
}, arguments); },
|
|
119
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
120
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
121
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
122
|
+
return ret;
|
|
123
|
+
},
|
|
124
|
+
__wbindgen_init_externref_table: function() {
|
|
125
|
+
const table = wasm.__wbindgen_externrefs;
|
|
126
|
+
const offset = table.grow(4);
|
|
127
|
+
table.set(0, undefined);
|
|
128
|
+
table.set(offset + 0, undefined);
|
|
129
|
+
table.set(offset + 1, null);
|
|
130
|
+
table.set(offset + 2, true);
|
|
131
|
+
table.set(offset + 3, false);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
__proto__: null,
|
|
136
|
+
"./docx_html_converter_bg.js": import0,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function addToExternrefTable0(obj) {
|
|
141
|
+
const idx = wasm.__externref_table_alloc();
|
|
142
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
143
|
+
return idx;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
147
|
+
ptr = ptr >>> 0;
|
|
148
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getStringFromWasm0(ptr, len) {
|
|
152
|
+
ptr = ptr >>> 0;
|
|
153
|
+
return decodeText(ptr, len);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let cachedUint8ArrayMemory0 = null;
|
|
157
|
+
function getUint8ArrayMemory0() {
|
|
158
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
159
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
160
|
+
}
|
|
161
|
+
return cachedUint8ArrayMemory0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function handleError(f, args) {
|
|
165
|
+
try {
|
|
166
|
+
return f.apply(this, args);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
const idx = addToExternrefTable0(e);
|
|
169
|
+
wasm.__wbindgen_exn_store(idx);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isLikeNone(x) {
|
|
174
|
+
return x === undefined || x === null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
178
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
179
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
180
|
+
WASM_VECTOR_LEN = arg.length;
|
|
181
|
+
return ptr;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
185
|
+
if (realloc === undefined) {
|
|
186
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
187
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
188
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
189
|
+
WASM_VECTOR_LEN = buf.length;
|
|
190
|
+
return ptr;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let len = arg.length;
|
|
194
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
195
|
+
|
|
196
|
+
const mem = getUint8ArrayMemory0();
|
|
197
|
+
|
|
198
|
+
let offset = 0;
|
|
199
|
+
|
|
200
|
+
for (; offset < len; offset++) {
|
|
201
|
+
const code = arg.charCodeAt(offset);
|
|
202
|
+
if (code > 0x7F) break;
|
|
203
|
+
mem[ptr + offset] = code;
|
|
204
|
+
}
|
|
205
|
+
if (offset !== len) {
|
|
206
|
+
if (offset !== 0) {
|
|
207
|
+
arg = arg.slice(offset);
|
|
208
|
+
}
|
|
209
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
210
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
211
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
212
|
+
|
|
213
|
+
offset += ret.written;
|
|
214
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
WASM_VECTOR_LEN = offset;
|
|
218
|
+
return ptr;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function takeFromExternrefTable0(idx) {
|
|
222
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
223
|
+
wasm.__externref_table_dealloc(idx);
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
228
|
+
cachedTextDecoder.decode();
|
|
229
|
+
function decodeText(ptr, len) {
|
|
230
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const cachedTextEncoder = new TextEncoder();
|
|
234
|
+
|
|
235
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
236
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
237
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
238
|
+
view.set(buf);
|
|
239
|
+
return {
|
|
240
|
+
read: arg.length,
|
|
241
|
+
written: buf.length
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
let WASM_VECTOR_LEN = 0;
|
|
247
|
+
|
|
248
|
+
const wasmPath = `${__dirname}/docx_html_converter_bg.wasm`;
|
|
249
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
250
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
251
|
+
let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
252
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "docx-html-converter",
|
|
3
|
+
"description": "Convert DOCX to HTML with styles, tables, lists. WASM + Rust. Includes calculate_html for contentEditable page recalculation.",
|
|
4
|
+
"version": "0.4.2",
|
|
5
|
+
"files": [
|
|
6
|
+
"docx_html_converter_bg.wasm",
|
|
7
|
+
"docx_html_converter.js",
|
|
8
|
+
"docx_html_converter.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"main": "docx_html_converter.js",
|
|
11
|
+
"types": "docx_html_converter.d.ts"
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-docx-html-converter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Convert DOCX ↔ HTML using Rust WASM. Two functions: docxToHtml and htmlToDocx.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.cjs",
|
|
7
|
+
"module": "index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./index.js",
|
|
12
|
+
"require": "./index.cjs",
|
|
13
|
+
"types": "./index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"index.cjs",
|
|
19
|
+
"index.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "cd .. && npm run build:node",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"docx-html-converter": "file:../pkg"
|
|
27
|
+
},
|
|
28
|
+
"bundledDependencies": [
|
|
29
|
+
"docx-html-converter"
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"docx",
|
|
33
|
+
"html",
|
|
34
|
+
"converter",
|
|
35
|
+
"word"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT"
|
|
38
|
+
}
|