diff --git a/.gitignore b/.gitignore index 1c7e3e2..be38787 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ target **/*.rs.bk dist node_modules -pkg +# pkg *.docx# test.docx output/*.docx diff --git a/docx-wasm/pkg/.gitignore b/docx-wasm/pkg/.gitignore new file mode 100644 index 0000000..234d3f7 --- /dev/null +++ b/docx-wasm/pkg/.gitignore @@ -0,0 +1 @@ +# * \ No newline at end of file diff --git a/docx-wasm/pkg/docx_rs.d.ts b/docx-wasm/pkg/docx_rs.d.ts new file mode 100644 index 0000000..32e6d93 --- /dev/null +++ b/docx-wasm/pkg/docx_rs.d.ts @@ -0,0 +1,365 @@ +/* tslint:disable */ +/** +* @returns {Docx} +*/ +export function createDocx(): Docx; +/** +* @returns {Delete} +*/ +export function createDelete(): Delete; +/** +* @returns {Insert} +*/ +export function createInsert(): Insert; +/** +* @param {number} id +* @returns {Numbering} +*/ +export function createNumbering(id: number): Numbering; +/** +* @returns {Table} +*/ +export function createTable(): Table; +/** +* @returns {TableRow} +*/ +export function createTableRow(): TableRow; +/** +* @returns {Paragraph} +*/ +export function createParagraph(): Paragraph; +/** +* @param {string} id +* @returns {Comment} +*/ +export function createComment(id: string): Comment; +/** +* @returns {Run} +*/ +export function createRun(): Run; +/** +* @param {number} id +* @param {number} start +* @param {string} format +* @param {string} text +* @param {string} jc +* @returns {Level} +*/ +export function createLevel(id: number, start: number, format: string, text: string, jc: string): Level; +/** +* @returns {TableCell} +*/ +export function createTableCell(): TableCell; +export enum SpecialIndentKind { + FirstLine, + Hanging, +} +/** +*/ +export enum StyleType { + Paragraph, + Character, +} +/** +*/ +export enum VMergeType { + Continue, + Restart, +} +/** +*/ +export enum WidthType { + DXA, + Auto, +} +/** +*/ +export enum BorderType { + None, + Single, + Thick, + Double, + Dotted, + Dashed, + DotDash, + DotDotDash, + Triple, +} +/** +*/ +export enum AlignmentType { + Center, + Left, + Right, + Justified, +} +/** +*/ +export enum FontPitchType { + Default, + Fixed, + Variable, +} +/** +*/ +export enum BreakType { + Page, + Column, + TextWrapping, +} +/** +*/ +export enum TableAlignmentType { + Center, + Left, + Right, +} +/** +*/ +/** +*/ +export class Comment { + free(): void; +/** +* @param {string} author +* @returns {Comment} +*/ + author(author: string): Comment; +/** +* @param {string} date +* @returns {Comment} +*/ + date(date: string): Comment; +/** +* @param {Paragraph} p +* @returns {Comment} +*/ + paragraph(p: Paragraph): Comment; +/** +* @returns {string} +*/ + id(): string; +} +/** +*/ +export class Delete { + free(): void; +} +/** +*/ +export class Docx { + free(): void; +/** +* @param {Paragraph} p +* @returns {Docx} +*/ + add_paragraph(p: Paragraph): Docx; +/** +* @param {Table} t +* @returns {Docx} +*/ + add_table(t: Table): Docx; +/** +* @param {Numbering} num +* @returns {Docx} +*/ + add_numbering(num: Numbering): Docx; +/** +* @returns {Uint8Array} +*/ + build(): Uint8Array; +} +/** +*/ +export class Insert { + free(): void; +} +/** +*/ +export class Level { + free(): void; +/** +* @param {number} left +* @param {number | undefined} special_indent_kind +* @param {number | undefined} special_indent_size +* @returns {Level} +*/ + indent(left: number, special_indent_kind?: number, special_indent_size?: number): Level; +} +/** +*/ +export class Numbering { + free(): void; +/** +* @param {Level} level +* @returns {Numbering} +*/ + add_level(level: Level): Numbering; +} +/** +*/ +export class Paragraph { + free(): void; +/** +* @param {Run} run +* @returns {Paragraph} +*/ + add_run(run: Run): Paragraph; +/** +* @param {Insert} i +* @returns {Paragraph} +*/ + add_insert(i: Insert): Paragraph; +/** +* @param {Delete} d +* @returns {Paragraph} +*/ + add_delete(d: Delete): Paragraph; +/** +* @param {string} id +* @param {string} name +* @returns {Paragraph} +*/ + add_bookmark_start(id: string, name: string): Paragraph; +/** +* @param {string} id +* @returns {Paragraph} +*/ + add_bookmark_end(id: string): Paragraph; +/** +* @param {Comment} comment +* @returns {Paragraph} +*/ + add_comment_start(comment: Comment): Paragraph; +/** +* @param {string} id +* @returns {Paragraph} +*/ + add_comment_end(id: string): Paragraph; +/** +* @param {number} alignment_type +* @returns {Paragraph} +*/ + align(alignment_type: number): Paragraph; +/** +* @param {string} style_id +* @returns {Paragraph} +*/ + style(style_id: string): Paragraph; +/** +* @param {number} left +* @param {number | undefined} special_indent_kind +* @param {number | undefined} special_indent_size +* @returns {Paragraph} +*/ + indent(left: number, special_indent_kind?: number, special_indent_size?: number): Paragraph; +/** +* @param {number} id +* @param {number} level +* @returns {Paragraph} +*/ + numbering(id: number, level: number): Paragraph; +} +/** +*/ +export class Run { + free(): void; +/** +* @param {string} text +* @returns {Run} +*/ + add_text(text: string): Run; +/** +* @param {string} text +* @returns {Run} +*/ + add_delete_text(text: string): Run; +/** +* @returns {Run} +*/ + add_tab(): Run; +/** +* @param {number} break_type +* @returns {Run} +*/ + add_break(break_type: number): Run; +/** +* @param {number} size +* @returns {Run} +*/ + size(size: number): Run; +/** +* @param {string} color +* @returns {Run} +*/ + color(color: string): Run; +/** +* @param {string} color +* @returns {Run} +*/ + highlight(color: string): Run; +/** +* @returns {Run} +*/ + bold(): Run; +/** +* @returns {Run} +*/ + italic(): Run; +/** +* @param {string} line_type +* @returns {Run} +*/ + underline(line_type: string): Run; +} +/** +*/ +export class Table { + free(): void; +/** +* @param {TableRow} row +* @returns {Table} +*/ + add_row(row: TableRow): Table; +} +/** +*/ +export class TableCell { + free(): void; +/** +* @param {Paragraph} p +* @returns {TableCell} +*/ + add_paragraph(p: Paragraph): TableCell; +/** +* @param {number} t +* @returns {TableCell} +*/ + vertical_merge(t: number): TableCell; +/** +* @param {number} v +* @returns {TableCell} +*/ + grid_span(v: number): TableCell; +} +/** +*/ +export class TableRow { + free(): void; +/** +* @param {TableCell} cell +* @returns {TableRow} +*/ + add_cell(cell: TableCell): TableRow; +} + +/** +* If `module_or_path` is {RequestInfo}, makes a request and +* for everything else, calls `WebAssembly.instantiate` directly. +* +* @param {RequestInfo | BufferSource | WebAssembly.Module} module_or_path +* +* @returns {Promise} +*/ +export default function init (module_or_path?: RequestInfo | BufferSource | WebAssembly.Module): Promise; + \ No newline at end of file diff --git a/docx-wasm/pkg/docx_rs.js b/docx-wasm/pkg/docx_rs.js new file mode 100644 index 0000000..6d4c729 --- /dev/null +++ b/docx-wasm/pkg/docx_rs.js @@ -0,0 +1,899 @@ + +let wasm; + +/** +* @returns {Docx} +*/ +export function createDocx() { + const ret = wasm.createDocx(); + return Docx.__wrap(ret); +} + +function _assertClass(instance, klass) { + if (!(instance instanceof klass)) { + throw new Error(`expected instance of ${klass.name}`); + } + return instance.ptr; +} + +let cachegetInt32Memory = null; +function getInt32Memory() { + if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) { + cachegetInt32Memory = new Int32Array(wasm.memory.buffer); + } + return cachegetInt32Memory; +} + +let cachegetUint8Memory = null; +function getUint8Memory() { + if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { + cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); + } + return cachegetUint8Memory; +} + +function getArrayU8FromWasm(ptr, len) { + return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); +} +/** +* @returns {Delete} +*/ +export function createDelete() { + const ret = wasm.createDelete(); + return Delete.__wrap(ret); +} + +/** +* @returns {Insert} +*/ +export function createInsert() { + const ret = wasm.createInsert(); + return Insert.__wrap(ret); +} + +/** +* @param {number} id +* @returns {Numbering} +*/ +export function createNumbering(id) { + const ret = wasm.createNumbering(id); + return Numbering.__wrap(ret); +} + +/** +* @returns {Table} +*/ +export function createTable() { + const ret = wasm.createTable(); + return Table.__wrap(ret); +} + +/** +* @returns {TableRow} +*/ +export function createTableRow() { + const ret = wasm.createTableRow(); + return TableRow.__wrap(ret); +} + +/** +* @returns {Paragraph} +*/ +export function createParagraph() { + const ret = wasm.createParagraph(); + return Paragraph.__wrap(ret); +} + +let WASM_VECTOR_LEN = 0; + +let cachedTextEncoder = new TextEncoder('utf-8'); + +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}); + +function passStringToWasm(arg) { + + let len = arg.length; + let ptr = wasm.__wbindgen_malloc(len); + + const mem = getUint8Memory(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = wasm.__wbindgen_realloc(ptr, len, len = offset + arg.length * 3); + const view = getUint8Memory().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +function isLikeNone(x) { + return x === undefined || x === null; +} +/** +* @param {string} id +* @returns {Comment} +*/ +export function createComment(id) { + const ret = wasm.createComment(passStringToWasm(id), WASM_VECTOR_LEN); + return Comment.__wrap(ret); +} + +let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); + +cachedTextDecoder.decode(); + +function getStringFromWasm(ptr, len) { + return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len)); +} +/** +* @returns {Run} +*/ +export function createRun() { + const ret = wasm.createRun(); + return Run.__wrap(ret); +} + +/** +* @param {number} id +* @param {number} start +* @param {string} format +* @param {string} text +* @param {string} jc +* @returns {Level} +*/ +export function createLevel(id, start, format, text, jc) { + const ret = wasm.createLevel(id, start, passStringToWasm(format), WASM_VECTOR_LEN, passStringToWasm(text), WASM_VECTOR_LEN, passStringToWasm(jc), WASM_VECTOR_LEN); + return Level.__wrap(ret); +} + +/** +* @returns {TableCell} +*/ +export function createTableCell() { + const ret = wasm.createTableCell(); + return TableCell.__wrap(ret); +} + +const heap = new Array(32); + +heap.fill(undefined); + +heap.push(undefined, null, true, false); + +let heap_next = heap.length; + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +function getObject(idx) { return heap[idx]; } + +function dropObject(idx) { + if (idx < 36) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} +/** +*/ +export const SpecialIndentKind = Object.freeze({ FirstLine:0,Hanging:1, }); +/** +*/ +export const StyleType = Object.freeze({ Paragraph:0,Character:1, }); +/** +*/ +export const VMergeType = Object.freeze({ Continue:0,Restart:1, }); +/** +*/ +export const WidthType = Object.freeze({ DXA:0,Auto:1, }); +/** +*/ +export const BorderType = Object.freeze({ None:0,Single:1,Thick:2,Double:3,Dotted:4,Dashed:5,DotDash:6,DotDotDash:7,Triple:8, }); +/** +*/ +export const AlignmentType = Object.freeze({ Center:0,Left:1,Right:2,Justified:3, }); +/** +*/ +export const FontPitchType = Object.freeze({ Default:0,Fixed:1,Variable:2, }); +/** +*/ +export const BreakType = Object.freeze({ Page:0,Column:1,TextWrapping:2, }); +/** +*/ +export const TableAlignmentType = Object.freeze({ Center:0,Left:1,Right:2, }); +/** +*/ +export class Comment { + + static __wrap(ptr) { + const obj = Object.create(Comment.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_comment_free(ptr); + } + /** + * @param {string} author + * @returns {Comment} + */ + author(author) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.comment_author(ptr, passStringToWasm(author), WASM_VECTOR_LEN); + return Comment.__wrap(ret); + } + /** + * @param {string} date + * @returns {Comment} + */ + date(date) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.comment_date(ptr, passStringToWasm(date), WASM_VECTOR_LEN); + return Comment.__wrap(ret); + } + /** + * @param {Paragraph} p + * @returns {Comment} + */ + paragraph(p) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(p, Paragraph); + const ptr0 = p.ptr; + p.ptr = 0; + const ret = wasm.comment_paragraph(ptr, ptr0); + return Comment.__wrap(ret); + } + /** + * @returns {string} + */ + id() { + const retptr = 8; + const ret = wasm.comment_id(retptr, this.ptr); + const memi32 = getInt32Memory(); + const v0 = getStringFromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice(); + wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1); + return v0; + } +} +/** +*/ +export class Delete { + + static __wrap(ptr) { + const obj = Object.create(Delete.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_delete_free(ptr); + } +} +/** +*/ +export class Docx { + + static __wrap(ptr) { + const obj = Object.create(Docx.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_docx_free(ptr); + } + /** + * @param {Paragraph} p + * @returns {Docx} + */ + add_paragraph(p) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(p, Paragraph); + const ptr0 = p.ptr; + p.ptr = 0; + const ret = wasm.docx_add_paragraph(ptr, ptr0); + return Docx.__wrap(ret); + } + /** + * @param {Table} t + * @returns {Docx} + */ + add_table(t) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(t, Table); + const ptr0 = t.ptr; + t.ptr = 0; + const ret = wasm.docx_add_table(ptr, ptr0); + return Docx.__wrap(ret); + } + /** + * @param {Numbering} num + * @returns {Docx} + */ + add_numbering(num) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(num, Numbering); + const ptr0 = num.ptr; + num.ptr = 0; + const ret = wasm.docx_add_numbering(ptr, ptr0); + return Docx.__wrap(ret); + } + /** + * @returns {Uint8Array} + */ + build() { + const retptr = 8; + const ret = wasm.docx_build(retptr, this.ptr); + const memi32 = getInt32Memory(); + const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice(); + wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1); + return v0; + } +} +/** +*/ +export class Insert { + + static __wrap(ptr) { + const obj = Object.create(Insert.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_insert_free(ptr); + } +} +/** +*/ +export class Level { + + static __wrap(ptr) { + const obj = Object.create(Level.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_level_free(ptr); + } + /** + * @param {number} left + * @param {number | undefined} special_indent_kind + * @param {number | undefined} special_indent_size + * @returns {Level} + */ + indent(left, special_indent_kind, special_indent_size) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.level_indent(ptr, left, isLikeNone(special_indent_kind) ? 2 : special_indent_kind, !isLikeNone(special_indent_size), isLikeNone(special_indent_size) ? 0 : special_indent_size); + return Level.__wrap(ret); + } +} +/** +*/ +export class Numbering { + + static __wrap(ptr) { + const obj = Object.create(Numbering.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_numbering_free(ptr); + } + /** + * @param {Level} level + * @returns {Numbering} + */ + add_level(level) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(level, Level); + const ptr0 = level.ptr; + level.ptr = 0; + const ret = wasm.numbering_add_level(ptr, ptr0); + return Numbering.__wrap(ret); + } +} +/** +*/ +export class Paragraph { + + static __wrap(ptr) { + const obj = Object.create(Paragraph.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_paragraph_free(ptr); + } + /** + * @param {Run} run + * @returns {Paragraph} + */ + add_run(run) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(run, Run); + const ptr0 = run.ptr; + run.ptr = 0; + const ret = wasm.paragraph_add_run(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {Insert} i + * @returns {Paragraph} + */ + add_insert(i) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(i, Insert); + const ptr0 = i.ptr; + i.ptr = 0; + const ret = wasm.paragraph_add_insert(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {Delete} d + * @returns {Paragraph} + */ + add_delete(d) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(d, Delete); + const ptr0 = d.ptr; + d.ptr = 0; + const ret = wasm.paragraph_add_delete(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {string} id + * @param {string} name + * @returns {Paragraph} + */ + add_bookmark_start(id, name) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.paragraph_add_bookmark_start(ptr, passStringToWasm(id), WASM_VECTOR_LEN, passStringToWasm(name), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {string} id + * @returns {Paragraph} + */ + add_bookmark_end(id) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.paragraph_add_bookmark_end(ptr, passStringToWasm(id), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {Comment} comment + * @returns {Paragraph} + */ + add_comment_start(comment) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(comment, Comment); + const ptr0 = comment.ptr; + comment.ptr = 0; + const ret = wasm.paragraph_add_comment_start(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {string} id + * @returns {Paragraph} + */ + add_comment_end(id) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.paragraph_add_comment_end(ptr, passStringToWasm(id), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {number} alignment_type + * @returns {Paragraph} + */ + align(alignment_type) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.paragraph_align(ptr, alignment_type); + return Paragraph.__wrap(ret); + } + /** + * @param {string} style_id + * @returns {Paragraph} + */ + style(style_id) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.paragraph_style(ptr, passStringToWasm(style_id), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {number} left + * @param {number | undefined} special_indent_kind + * @param {number | undefined} special_indent_size + * @returns {Paragraph} + */ + indent(left, special_indent_kind, special_indent_size) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.paragraph_indent(ptr, left, isLikeNone(special_indent_kind) ? 2 : special_indent_kind, !isLikeNone(special_indent_size), isLikeNone(special_indent_size) ? 0 : special_indent_size); + return Paragraph.__wrap(ret); + } + /** + * @param {number} id + * @param {number} level + * @returns {Paragraph} + */ + numbering(id, level) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.paragraph_numbering(ptr, id, level); + return Paragraph.__wrap(ret); + } +} +/** +*/ +export class Run { + + static __wrap(ptr) { + const obj = Object.create(Run.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_run_free(ptr); + } + /** + * @param {string} text + * @returns {Run} + */ + add_text(text) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_add_text(ptr, passStringToWasm(text), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @param {string} text + * @returns {Run} + */ + add_delete_text(text) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_add_delete_text(ptr, passStringToWasm(text), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @returns {Run} + */ + add_tab() { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_add_tab(ptr); + return Run.__wrap(ret); + } + /** + * @param {number} break_type + * @returns {Run} + */ + add_break(break_type) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_add_break(ptr, break_type); + return Run.__wrap(ret); + } + /** + * @param {number} size + * @returns {Run} + */ + size(size) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_size(ptr, size); + return Run.__wrap(ret); + } + /** + * @param {string} color + * @returns {Run} + */ + color(color) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_color(ptr, passStringToWasm(color), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @param {string} color + * @returns {Run} + */ + highlight(color) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_highlight(ptr, passStringToWasm(color), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @returns {Run} + */ + bold() { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_bold(ptr); + return Run.__wrap(ret); + } + /** + * @returns {Run} + */ + italic() { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_italic(ptr); + return Run.__wrap(ret); + } + /** + * @param {string} line_type + * @returns {Run} + */ + underline(line_type) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.run_underline(ptr, passStringToWasm(line_type), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } +} +/** +*/ +export class Table { + + static __wrap(ptr) { + const obj = Object.create(Table.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_table_free(ptr); + } + /** + * @param {TableRow} row + * @returns {Table} + */ + add_row(row) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(row, TableRow); + const ptr0 = row.ptr; + row.ptr = 0; + const ret = wasm.table_add_row(ptr, ptr0); + return Table.__wrap(ret); + } +} +/** +*/ +export class TableCell { + + static __wrap(ptr) { + const obj = Object.create(TableCell.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_tablecell_free(ptr); + } + /** + * @param {Paragraph} p + * @returns {TableCell} + */ + add_paragraph(p) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(p, Paragraph); + const ptr0 = p.ptr; + p.ptr = 0; + const ret = wasm.tablecell_add_paragraph(ptr, ptr0); + return TableCell.__wrap(ret); + } + /** + * @param {number} t + * @returns {TableCell} + */ + vertical_merge(t) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.tablecell_vertical_merge(ptr, t); + return TableCell.__wrap(ret); + } + /** + * @param {number} v + * @returns {TableCell} + */ + grid_span(v) { + const ptr = this.ptr; + this.ptr = 0; + const ret = wasm.tablecell_grid_span(ptr, v); + return TableCell.__wrap(ret); + } +} +/** +*/ +export class TableRow { + + static __wrap(ptr) { + const obj = Object.create(TableRow.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_tablerow_free(ptr); + } + /** + * @param {TableCell} cell + * @returns {TableRow} + */ + add_cell(cell) { + const ptr = this.ptr; + this.ptr = 0; + _assertClass(cell, TableCell); + const ptr0 = cell.ptr; + cell.ptr = 0; + const ret = wasm.tablerow_add_cell(ptr, ptr0); + return TableRow.__wrap(ret); + } +} + +function init(module) { + if (typeof module === 'undefined') { + module = import.meta.url.replace(/\.js$/, '_bg.wasm'); + } + let result; + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm(arg0, arg1)); + }; + imports.wbg.__wbindgen_rethrow = function(arg0) { + throw takeObject(arg0); + }; + + if ((typeof URL === 'function' && module instanceof URL) || typeof module === 'string' || (typeof Request === 'function' && module instanceof Request)) { + + const response = fetch(module); + if (typeof WebAssembly.instantiateStreaming === 'function') { + result = WebAssembly.instantiateStreaming(response, imports) + .catch(e => { + return response + .then(r => { + if (r.headers.get('Content-Type') != 'application/wasm') { + 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); + return r.arrayBuffer(); + } else { + throw e; + } + }) + .then(bytes => WebAssembly.instantiate(bytes, imports)); + }); + } else { + result = response + .then(r => r.arrayBuffer()) + .then(bytes => WebAssembly.instantiate(bytes, imports)); + } + } else { + + result = WebAssembly.instantiate(module, imports) + .then(result => { + if (result instanceof WebAssembly.Instance) { + return { instance: result, module }; + } else { + return result; + } + }); + } + return result.then(({instance, module}) => { + wasm = instance.exports; + init.__wbindgen_wasm_module = module; + + return wasm; + }); +} + +export default init; + diff --git a/docx-wasm/pkg/docx_rs_bg.d.ts b/docx-wasm/pkg/docx_rs_bg.d.ts new file mode 100644 index 0000000..c5a1105 --- /dev/null +++ b/docx-wasm/pkg/docx_rs_bg.d.ts @@ -0,0 +1,63 @@ +/* tslint:disable */ +export const memory: WebAssembly.Memory; +export function __wbg_docx_free(a: number): void; +export function createDocx(): number; +export function docx_add_paragraph(a: number, b: number): number; +export function docx_add_table(a: number, b: number): number; +export function docx_add_numbering(a: number, b: number): number; +export function docx_build(a: number, b: number): void; +export function __wbg_delete_free(a: number): void; +export function createDelete(): number; +export function createInsert(): number; +export function __wbg_insert_free(a: number): void; +export function __wbg_numbering_free(a: number): void; +export function createNumbering(a: number): number; +export function numbering_add_level(a: number, b: number): number; +export function __wbg_table_free(a: number): void; +export function createTable(): number; +export function table_add_row(a: number, b: number): number; +export function __wbg_tablerow_free(a: number): void; +export function createTableRow(): number; +export function tablerow_add_cell(a: number, b: number): number; +export function __wbg_paragraph_free(a: number): void; +export function createParagraph(): number; +export function paragraph_add_run(a: number, b: number): number; +export function paragraph_add_insert(a: number, b: number): number; +export function paragraph_add_delete(a: number, b: number): number; +export function paragraph_add_bookmark_start(a: number, b: number, c: number, d: number, e: number): number; +export function paragraph_add_bookmark_end(a: number, b: number, c: number): number; +export function paragraph_add_comment_start(a: number, b: number): number; +export function paragraph_add_comment_end(a: number, b: number, c: number): number; +export function paragraph_align(a: number, b: number): number; +export function paragraph_style(a: number, b: number, c: number): number; +export function paragraph_indent(a: number, b: number, c: number, d: number, e: number): number; +export function paragraph_numbering(a: number, b: number, c: number): number; +export function __wbg_comment_free(a: number): void; +export function createComment(a: number, b: number): number; +export function comment_author(a: number, b: number, c: number): number; +export function comment_date(a: number, b: number, c: number): number; +export function comment_paragraph(a: number, b: number): number; +export function comment_id(a: number, b: number): void; +export function __wbg_run_free(a: number): void; +export function createRun(): number; +export function run_add_text(a: number, b: number, c: number): number; +export function run_add_delete_text(a: number, b: number, c: number): number; +export function run_add_tab(a: number): number; +export function run_add_break(a: number, b: number): number; +export function run_size(a: number, b: number): number; +export function run_color(a: number, b: number, c: number): number; +export function run_highlight(a: number, b: number, c: number): number; +export function run_bold(a: number): number; +export function run_italic(a: number): number; +export function run_underline(a: number, b: number, c: number): number; +export function __wbg_level_free(a: number): void; +export function createLevel(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; +export function level_indent(a: number, b: number, c: number, d: number, e: number): number; +export function __wbg_tablecell_free(a: number): void; +export function createTableCell(): number; +export function tablecell_add_paragraph(a: number, b: number): number; +export function tablecell_vertical_merge(a: number, b: number): number; +export function tablecell_grid_span(a: number, b: number): number; +export function __wbindgen_malloc(a: number): number; +export function __wbindgen_realloc(a: number, b: number, c: number): number; +export function __wbindgen_free(a: number, b: number): void; diff --git a/docx-wasm/pkg/docx_rs_bg.wasm b/docx-wasm/pkg/docx_rs_bg.wasm new file mode 100644 index 0000000..a4978da Binary files /dev/null and b/docx-wasm/pkg/docx_rs_bg.wasm differ diff --git a/docx-wasm/pkg/index.d.ts b/docx-wasm/pkg/index.d.ts new file mode 100644 index 0000000..730691c --- /dev/null +++ b/docx-wasm/pkg/index.d.ts @@ -0,0 +1,354 @@ +/* tslint:disable */ +/** +* @returns {Run} +*/ +export function createRun(): Run; +/** +* @param {string} id +* @returns {Comment} +*/ +export function createComment(id: string): Comment; +/** +* @returns {TableCell} +*/ +export function createTableCell(): TableCell; +/** +* @returns {TableRow} +*/ +export function createTableRow(): TableRow; +/** +* @returns {Docx} +*/ +export function createDocx(): Docx; +/** +* @param {number} id +* @param {number} start +* @param {string} format +* @param {string} text +* @param {string} jc +* @returns {Level} +*/ +export function createLevel(id: number, start: number, format: string, text: string, jc: string): Level; +/** +* @returns {Insert} +*/ +export function createInsert(): Insert; +/** +* @returns {Table} +*/ +export function createTable(): Table; +/** +* @param {number} id +* @returns {Numbering} +*/ +export function createNumbering(id: number): Numbering; +/** +* @returns {Delete} +*/ +export function createDelete(): Delete; +/** +* @returns {Paragraph} +*/ +export function createParagraph(): Paragraph; +export enum SpecialIndentKind { + FirstLine, + Hanging, +} +/** +*/ +export enum VMergeType { + Continue, + Restart, +} +/** +*/ +export enum BreakType { + Page, + Column, + TextWrapping, +} +/** +*/ +export enum FontPitchType { + Default, + Fixed, + Variable, +} +/** +*/ +export enum WidthType { + DXA, + Auto, +} +/** +*/ +export enum BorderType { + None, + Single, + Thick, + Double, + Dotted, + Dashed, + DotDash, + DotDotDash, + Triple, +} +/** +*/ +export enum TableAlignmentType { + Center, + Left, + Right, +} +/** +*/ +export enum AlignmentType { + Center, + Left, + Right, + Justified, +} +/** +*/ +export enum StyleType { + Paragraph, + Character, +} +/** +*/ +/** +*/ +export class Comment { + free(): void; +/** +* @param {string} author +* @returns {Comment} +*/ + author(author: string): Comment; +/** +* @param {string} date +* @returns {Comment} +*/ + date(date: string): Comment; +/** +* @param {Paragraph} p +* @returns {Comment} +*/ + paragraph(p: Paragraph): Comment; +/** +* @returns {string} +*/ + id(): string; +} +/** +*/ +export class Delete { + free(): void; +} +/** +*/ +export class Docx { + free(): void; +/** +* @param {Paragraph} p +* @returns {Docx} +*/ + add_paragraph(p: Paragraph): Docx; +/** +* @param {Table} t +* @returns {Docx} +*/ + add_table(t: Table): Docx; +/** +* @param {Numbering} num +* @returns {Docx} +*/ + add_numbering(num: Numbering): Docx; +/** +* @returns {Uint8Array} +*/ + build(): Uint8Array; +} +/** +*/ +export class Insert { + free(): void; +} +/** +*/ +export class Level { + free(): void; +/** +* @param {number} left +* @param {number | undefined} special_indent_kind +* @param {number | undefined} special_indent_size +* @returns {Level} +*/ + indent(left: number, special_indent_kind?: number, special_indent_size?: number): Level; +} +/** +*/ +export class Numbering { + free(): void; +/** +* @param {Level} level +* @returns {Numbering} +*/ + add_level(level: Level): Numbering; +} +/** +*/ +export class Paragraph { + free(): void; +/** +* @param {Run} run +* @returns {Paragraph} +*/ + add_run(run: Run): Paragraph; +/** +* @param {Insert} i +* @returns {Paragraph} +*/ + add_insert(i: Insert): Paragraph; +/** +* @param {Delete} d +* @returns {Paragraph} +*/ + add_delete(d: Delete): Paragraph; +/** +* @param {string} id +* @param {string} name +* @returns {Paragraph} +*/ + add_bookmark_start(id: string, name: string): Paragraph; +/** +* @param {string} id +* @returns {Paragraph} +*/ + add_bookmark_end(id: string): Paragraph; +/** +* @param {Comment} comment +* @returns {Paragraph} +*/ + add_comment_start(comment: Comment): Paragraph; +/** +* @param {string} id +* @returns {Paragraph} +*/ + add_comment_end(id: string): Paragraph; +/** +* @param {number} alignment_type +* @returns {Paragraph} +*/ + align(alignment_type: number): Paragraph; +/** +* @param {string} style_id +* @returns {Paragraph} +*/ + style(style_id: string): Paragraph; +/** +* @param {number} left +* @param {number | undefined} special_indent_kind +* @param {number | undefined} special_indent_size +* @returns {Paragraph} +*/ + indent(left: number, special_indent_kind?: number, special_indent_size?: number): Paragraph; +/** +* @param {number} id +* @param {number} level +* @returns {Paragraph} +*/ + numbering(id: number, level: number): Paragraph; +} +/** +*/ +export class Run { + free(): void; +/** +* @param {string} text +* @returns {Run} +*/ + add_text(text: string): Run; +/** +* @param {string} text +* @returns {Run} +*/ + add_delete_text(text: string): Run; +/** +* @returns {Run} +*/ + add_tab(): Run; +/** +* @param {number} break_type +* @returns {Run} +*/ + add_break(break_type: number): Run; +/** +* @param {number} size +* @returns {Run} +*/ + size(size: number): Run; +/** +* @param {string} color +* @returns {Run} +*/ + color(color: string): Run; +/** +* @param {string} color +* @returns {Run} +*/ + highlight(color: string): Run; +/** +* @returns {Run} +*/ + bold(): Run; +/** +* @returns {Run} +*/ + italic(): Run; +/** +* @param {string} line_type +* @returns {Run} +*/ + underline(line_type: string): Run; +} +/** +*/ +export class Table { + free(): void; +/** +* @param {TableRow} row +* @returns {Table} +*/ + add_row(row: TableRow): Table; +} +/** +*/ +export class TableCell { + free(): void; +/** +* @param {Paragraph} p +* @returns {TableCell} +*/ + add_paragraph(p: Paragraph): TableCell; +/** +* @param {number} t +* @returns {TableCell} +*/ + vertical_merge(t: number): TableCell; +/** +* @param {number} v +* @returns {TableCell} +*/ + grid_span(v: number): TableCell; +} +/** +*/ +export class TableRow { + free(): void; +/** +* @param {TableCell} cell +* @returns {TableRow} +*/ + add_cell(cell: TableCell): TableRow; +} diff --git a/docx-wasm/pkg/index.js b/docx-wasm/pkg/index.js new file mode 100644 index 0000000..d39d22c --- /dev/null +++ b/docx-wasm/pkg/index.js @@ -0,0 +1,1039 @@ +import * as wasm from './index_bg.wasm'; + +/** +* @returns {Run} +*/ +export function createRun() { + const ret = wasm.createRun(); + return Run.__wrap(ret); +} + +function _assertNum(n) { + if (typeof(n) !== 'number') throw new Error('expected a number argument'); +} + +let WASM_VECTOR_LEN = 0; + +let cachedTextEncoder = new TextEncoder('utf-8'); + +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}); + +let cachegetUint8Memory = null; +function getUint8Memory() { + if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) { + cachegetUint8Memory = new Uint8Array(wasm.memory.buffer); + } + return cachegetUint8Memory; +} + +function passStringToWasm(arg) { + + if (typeof(arg) !== 'string') throw new Error('expected a string argument'); + + let len = arg.length; + let ptr = wasm.__wbindgen_malloc(len); + + const mem = getUint8Memory(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = wasm.__wbindgen_realloc(ptr, len, len = offset + arg.length * 3); + const view = getUint8Memory().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + if (ret.read != arg.length) throw new Error('failed to pass whole string'); + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} +/** +* @param {string} id +* @returns {Comment} +*/ +export function createComment(id) { + const ret = wasm.createComment(passStringToWasm(id), WASM_VECTOR_LEN); + return Comment.__wrap(ret); +} + +function _assertClass(instance, klass) { + if (!(instance instanceof klass)) { + throw new Error(`expected instance of ${klass.name}`); + } + return instance.ptr; +} + +let cachegetInt32Memory = null; +function getInt32Memory() { + if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) { + cachegetInt32Memory = new Int32Array(wasm.memory.buffer); + } + return cachegetInt32Memory; +} + +let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); + +cachedTextDecoder.decode(); + +function getStringFromWasm(ptr, len) { + return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len)); +} +/** +* @returns {TableCell} +*/ +export function createTableCell() { + const ret = wasm.createTableCell(); + return TableCell.__wrap(ret); +} + +/** +* @returns {TableRow} +*/ +export function createTableRow() { + const ret = wasm.createTableRow(); + return TableRow.__wrap(ret); +} + +/** +* @returns {Docx} +*/ +export function createDocx() { + const ret = wasm.createDocx(); + return Docx.__wrap(ret); +} + +function getArrayU8FromWasm(ptr, len) { + return getUint8Memory().subarray(ptr / 1, ptr / 1 + len); +} +/** +* @param {number} id +* @param {number} start +* @param {string} format +* @param {string} text +* @param {string} jc +* @returns {Level} +*/ +export function createLevel(id, start, format, text, jc) { + _assertNum(id); + _assertNum(start); + const ret = wasm.createLevel(id, start, passStringToWasm(format), WASM_VECTOR_LEN, passStringToWasm(text), WASM_VECTOR_LEN, passStringToWasm(jc), WASM_VECTOR_LEN); + return Level.__wrap(ret); +} + +function isLikeNone(x) { + return x === undefined || x === null; +} +/** +* @returns {Insert} +*/ +export function createInsert() { + const ret = wasm.createInsert(); + return Insert.__wrap(ret); +} + +/** +* @returns {Table} +*/ +export function createTable() { + const ret = wasm.createTable(); + return Table.__wrap(ret); +} + +/** +* @param {number} id +* @returns {Numbering} +*/ +export function createNumbering(id) { + _assertNum(id); + const ret = wasm.createNumbering(id); + return Numbering.__wrap(ret); +} + +/** +* @returns {Delete} +*/ +export function createDelete() { + const ret = wasm.createDelete(); + return Delete.__wrap(ret); +} + +/** +* @returns {Paragraph} +*/ +export function createParagraph() { + const ret = wasm.createParagraph(); + return Paragraph.__wrap(ret); +} + +const heap = new Array(32); + +heap.fill(undefined); + +heap.push(undefined, null, true, false); + +let heap_next = heap.length; + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + if (typeof(heap_next) !== 'number') throw new Error('corrupt heap'); + + heap[idx] = obj; + return idx; +} + +function getObject(idx) { return heap[idx]; } + +function dropObject(idx) { + if (idx < 36) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} +/** +*/ +export const SpecialIndentKind = Object.freeze({ FirstLine:0,Hanging:1, }); +/** +*/ +export const VMergeType = Object.freeze({ Continue:0,Restart:1, }); +/** +*/ +export const BreakType = Object.freeze({ Page:0,Column:1,TextWrapping:2, }); +/** +*/ +export const FontPitchType = Object.freeze({ Default:0,Fixed:1,Variable:2, }); +/** +*/ +export const WidthType = Object.freeze({ DXA:0,Auto:1, }); +/** +*/ +export const BorderType = Object.freeze({ None:0,Single:1,Thick:2,Double:3,Dotted:4,Dashed:5,DotDash:6,DotDotDash:7,Triple:8, }); +/** +*/ +export const TableAlignmentType = Object.freeze({ Center:0,Left:1,Right:2, }); +/** +*/ +export const AlignmentType = Object.freeze({ Center:0,Left:1,Right:2,Justified:3, }); +/** +*/ +export const StyleType = Object.freeze({ Paragraph:0,Character:1, }); +/** +*/ +export class Comment { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Comment.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_comment_free(ptr); + } + /** + * @param {string} author + * @returns {Comment} + */ + author(author) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.comment_author(ptr, passStringToWasm(author), WASM_VECTOR_LEN); + return Comment.__wrap(ret); + } + /** + * @param {string} date + * @returns {Comment} + */ + date(date) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.comment_date(ptr, passStringToWasm(date), WASM_VECTOR_LEN); + return Comment.__wrap(ret); + } + /** + * @param {Paragraph} p + * @returns {Comment} + */ + paragraph(p) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(p, Paragraph); + if (p.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = p.ptr; + p.ptr = 0; + const ret = wasm.comment_paragraph(ptr, ptr0); + return Comment.__wrap(ret); + } + /** + * @returns {string} + */ + id() { + const retptr = 8; + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + _assertNum(retptr); + _assertNum(this.ptr); + const ret = wasm.comment_id(retptr, this.ptr); + const memi32 = getInt32Memory(); + const v0 = getStringFromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice(); + wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1); + return v0; + } +} +/** +*/ +export class Delete { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Delete.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_delete_free(ptr); + } +} +/** +*/ +export class Docx { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Docx.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_docx_free(ptr); + } + /** + * @param {Paragraph} p + * @returns {Docx} + */ + add_paragraph(p) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(p, Paragraph); + if (p.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = p.ptr; + p.ptr = 0; + const ret = wasm.docx_add_paragraph(ptr, ptr0); + return Docx.__wrap(ret); + } + /** + * @param {Table} t + * @returns {Docx} + */ + add_table(t) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(t, Table); + if (t.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = t.ptr; + t.ptr = 0; + const ret = wasm.docx_add_table(ptr, ptr0); + return Docx.__wrap(ret); + } + /** + * @param {Numbering} num + * @returns {Docx} + */ + add_numbering(num) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(num, Numbering); + if (num.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = num.ptr; + num.ptr = 0; + const ret = wasm.docx_add_numbering(ptr, ptr0); + return Docx.__wrap(ret); + } + /** + * @returns {Uint8Array} + */ + build() { + const retptr = 8; + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + _assertNum(retptr); + _assertNum(this.ptr); + const ret = wasm.docx_build(retptr, this.ptr); + const memi32 = getInt32Memory(); + const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice(); + wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1); + return v0; + } +} +/** +*/ +export class Insert { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Insert.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_insert_free(ptr); + } +} +/** +*/ +export class Level { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Level.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_level_free(ptr); + } + /** + * @param {number} left + * @param {number | undefined} special_indent_kind + * @param {number | undefined} special_indent_size + * @returns {Level} + */ + indent(left, special_indent_kind, special_indent_size) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(left); + if (!isLikeNone(special_indent_kind)) { + _assertNum(special_indent_kind); + } + if (!isLikeNone(special_indent_size)) { + _assertNum(special_indent_size); + } + const ret = wasm.level_indent(ptr, left, isLikeNone(special_indent_kind) ? 2 : special_indent_kind, !isLikeNone(special_indent_size), isLikeNone(special_indent_size) ? 0 : special_indent_size); + return Level.__wrap(ret); + } +} +/** +*/ +export class Numbering { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Numbering.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_numbering_free(ptr); + } + /** + * @param {Level} level + * @returns {Numbering} + */ + add_level(level) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(level, Level); + if (level.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = level.ptr; + level.ptr = 0; + const ret = wasm.numbering_add_level(ptr, ptr0); + return Numbering.__wrap(ret); + } +} +/** +*/ +export class Paragraph { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Paragraph.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_paragraph_free(ptr); + } + /** + * @param {Run} run + * @returns {Paragraph} + */ + add_run(run) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(run, Run); + if (run.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = run.ptr; + run.ptr = 0; + const ret = wasm.paragraph_add_run(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {Insert} i + * @returns {Paragraph} + */ + add_insert(i) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(i, Insert); + if (i.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = i.ptr; + i.ptr = 0; + const ret = wasm.paragraph_add_insert(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {Delete} d + * @returns {Paragraph} + */ + add_delete(d) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(d, Delete); + if (d.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = d.ptr; + d.ptr = 0; + const ret = wasm.paragraph_add_delete(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {string} id + * @param {string} name + * @returns {Paragraph} + */ + add_bookmark_start(id, name) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.paragraph_add_bookmark_start(ptr, passStringToWasm(id), WASM_VECTOR_LEN, passStringToWasm(name), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {string} id + * @returns {Paragraph} + */ + add_bookmark_end(id) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.paragraph_add_bookmark_end(ptr, passStringToWasm(id), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {Comment} comment + * @returns {Paragraph} + */ + add_comment_start(comment) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(comment, Comment); + if (comment.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = comment.ptr; + comment.ptr = 0; + const ret = wasm.paragraph_add_comment_start(ptr, ptr0); + return Paragraph.__wrap(ret); + } + /** + * @param {string} id + * @returns {Paragraph} + */ + add_comment_end(id) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.paragraph_add_comment_end(ptr, passStringToWasm(id), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {number} alignment_type + * @returns {Paragraph} + */ + align(alignment_type) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(alignment_type); + const ret = wasm.paragraph_align(ptr, alignment_type); + return Paragraph.__wrap(ret); + } + /** + * @param {string} style_id + * @returns {Paragraph} + */ + style(style_id) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.paragraph_style(ptr, passStringToWasm(style_id), WASM_VECTOR_LEN); + return Paragraph.__wrap(ret); + } + /** + * @param {number} left + * @param {number | undefined} special_indent_kind + * @param {number | undefined} special_indent_size + * @returns {Paragraph} + */ + indent(left, special_indent_kind, special_indent_size) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(left); + if (!isLikeNone(special_indent_kind)) { + _assertNum(special_indent_kind); + } + if (!isLikeNone(special_indent_size)) { + _assertNum(special_indent_size); + } + const ret = wasm.paragraph_indent(ptr, left, isLikeNone(special_indent_kind) ? 2 : special_indent_kind, !isLikeNone(special_indent_size), isLikeNone(special_indent_size) ? 0 : special_indent_size); + return Paragraph.__wrap(ret); + } + /** + * @param {number} id + * @param {number} level + * @returns {Paragraph} + */ + numbering(id, level) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(id); + _assertNum(level); + const ret = wasm.paragraph_numbering(ptr, id, level); + return Paragraph.__wrap(ret); + } +} +/** +*/ +export class Run { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Run.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_run_free(ptr); + } + /** + * @param {string} text + * @returns {Run} + */ + add_text(text) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_add_text(ptr, passStringToWasm(text), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @param {string} text + * @returns {Run} + */ + add_delete_text(text) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_add_delete_text(ptr, passStringToWasm(text), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @returns {Run} + */ + add_tab() { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_add_tab(ptr); + return Run.__wrap(ret); + } + /** + * @param {number} break_type + * @returns {Run} + */ + add_break(break_type) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(break_type); + const ret = wasm.run_add_break(ptr, break_type); + return Run.__wrap(ret); + } + /** + * @param {number} size + * @returns {Run} + */ + size(size) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(size); + const ret = wasm.run_size(ptr, size); + return Run.__wrap(ret); + } + /** + * @param {string} color + * @returns {Run} + */ + color(color) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_color(ptr, passStringToWasm(color), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @param {string} color + * @returns {Run} + */ + highlight(color) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_highlight(ptr, passStringToWasm(color), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } + /** + * @returns {Run} + */ + bold() { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_bold(ptr); + return Run.__wrap(ret); + } + /** + * @returns {Run} + */ + italic() { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_italic(ptr); + return Run.__wrap(ret); + } + /** + * @param {string} line_type + * @returns {Run} + */ + underline(line_type) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + const ret = wasm.run_underline(ptr, passStringToWasm(line_type), WASM_VECTOR_LEN); + return Run.__wrap(ret); + } +} +/** +*/ +export class Table { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(Table.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_table_free(ptr); + } + /** + * @param {TableRow} row + * @returns {Table} + */ + add_row(row) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(row, TableRow); + if (row.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = row.ptr; + row.ptr = 0; + const ret = wasm.table_add_row(ptr, ptr0); + return Table.__wrap(ret); + } +} +/** +*/ +export class TableCell { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(TableCell.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_tablecell_free(ptr); + } + /** + * @param {Paragraph} p + * @returns {TableCell} + */ + add_paragraph(p) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(p, Paragraph); + if (p.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = p.ptr; + p.ptr = 0; + const ret = wasm.tablecell_add_paragraph(ptr, ptr0); + return TableCell.__wrap(ret); + } + /** + * @param {number} t + * @returns {TableCell} + */ + vertical_merge(t) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(t); + const ret = wasm.tablecell_vertical_merge(ptr, t); + return TableCell.__wrap(ret); + } + /** + * @param {number} v + * @returns {TableCell} + */ + grid_span(v) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertNum(v); + const ret = wasm.tablecell_grid_span(ptr, v); + return TableCell.__wrap(ret); + } +} +/** +*/ +export class TableRow { + + constructor() { + throw new Error('cannot invoke `new` directly'); + } + + static __wrap(ptr) { + const obj = Object.create(TableRow.prototype); + obj.ptr = ptr; + + return obj; + } + + free() { + const ptr = this.ptr; + this.ptr = 0; + + wasm.__wbg_tablerow_free(ptr); + } + /** + * @param {TableCell} cell + * @returns {TableRow} + */ + add_cell(cell) { + if (this.ptr == 0) throw new Error('Attempt to use a moved value'); + const ptr = this.ptr; + this.ptr = 0; + _assertNum(ptr); + _assertClass(cell, TableCell); + if (cell.ptr === 0) { + throw new Error('Attempt to use a moved value'); + } + const ptr0 = cell.ptr; + cell.ptr = 0; + const ret = wasm.tablerow_add_cell(ptr, ptr0); + return TableRow.__wrap(ret); + } +} + +export const __wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm(arg0, arg1); + return addHeapObject(ret); +}; + +export const __wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); +}; + +export const __wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm(arg0, arg1)); +}; + +export const __wbindgen_rethrow = function(arg0) { + throw takeObject(arg0); +}; + diff --git a/docx-wasm/pkg/index_bg.d.ts b/docx-wasm/pkg/index_bg.d.ts new file mode 100644 index 0000000..bed9c88 --- /dev/null +++ b/docx-wasm/pkg/index_bg.d.ts @@ -0,0 +1,63 @@ +/* tslint:disable */ +export const memory: WebAssembly.Memory; +export function __wbg_run_free(a: number): void; +export function createRun(): number; +export function run_add_text(a: number, b: number, c: number): number; +export function run_add_delete_text(a: number, b: number, c: number): number; +export function run_add_tab(a: number): number; +export function run_add_break(a: number, b: number): number; +export function run_size(a: number, b: number): number; +export function run_color(a: number, b: number, c: number): number; +export function run_highlight(a: number, b: number, c: number): number; +export function run_bold(a: number): number; +export function run_italic(a: number): number; +export function run_underline(a: number, b: number, c: number): number; +export function __wbg_comment_free(a: number): void; +export function createComment(a: number, b: number): number; +export function comment_author(a: number, b: number, c: number): number; +export function comment_date(a: number, b: number, c: number): number; +export function comment_paragraph(a: number, b: number): number; +export function comment_id(a: number, b: number): void; +export function __wbg_tablecell_free(a: number): void; +export function createTableCell(): number; +export function tablecell_add_paragraph(a: number, b: number): number; +export function tablecell_vertical_merge(a: number, b: number): number; +export function tablecell_grid_span(a: number, b: number): number; +export function __wbg_tablerow_free(a: number): void; +export function createTableRow(): number; +export function tablerow_add_cell(a: number, b: number): number; +export function __wbg_docx_free(a: number): void; +export function createDocx(): number; +export function docx_add_paragraph(a: number, b: number): number; +export function docx_add_table(a: number, b: number): number; +export function docx_add_numbering(a: number, b: number): number; +export function docx_build(a: number, b: number): void; +export function __wbg_level_free(a: number): void; +export function createLevel(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number): number; +export function level_indent(a: number, b: number, c: number, d: number, e: number): number; +export function __wbg_insert_free(a: number): void; +export function createInsert(): number; +export function __wbg_table_free(a: number): void; +export function createTable(): number; +export function table_add_row(a: number, b: number): number; +export function __wbg_numbering_free(a: number): void; +export function createNumbering(a: number): number; +export function numbering_add_level(a: number, b: number): number; +export function __wbg_delete_free(a: number): void; +export function createDelete(): number; +export function __wbg_paragraph_free(a: number): void; +export function createParagraph(): number; +export function paragraph_add_run(a: number, b: number): number; +export function paragraph_add_insert(a: number, b: number): number; +export function paragraph_add_delete(a: number, b: number): number; +export function paragraph_add_bookmark_start(a: number, b: number, c: number, d: number, e: number): number; +export function paragraph_add_bookmark_end(a: number, b: number, c: number): number; +export function paragraph_add_comment_start(a: number, b: number): number; +export function paragraph_add_comment_end(a: number, b: number, c: number): number; +export function paragraph_align(a: number, b: number): number; +export function paragraph_style(a: number, b: number, c: number): number; +export function paragraph_indent(a: number, b: number, c: number, d: number, e: number): number; +export function paragraph_numbering(a: number, b: number, c: number): number; +export function __wbindgen_malloc(a: number): number; +export function __wbindgen_realloc(a: number, b: number, c: number): number; +export function __wbindgen_free(a: number, b: number): void; diff --git a/docx-wasm/pkg/index_bg.wasm b/docx-wasm/pkg/index_bg.wasm new file mode 100644 index 0000000..b7e9305 Binary files /dev/null and b/docx-wasm/pkg/index_bg.wasm differ diff --git a/docx-wasm/pkg/package.json b/docx-wasm/pkg/package.json new file mode 100644 index 0000000..a69d8d8 --- /dev/null +++ b/docx-wasm/pkg/package.json @@ -0,0 +1,15 @@ +{ + "name": "docx-rs", + "collaborators": [ + "bokuweb " + ], + "version": "0.1.0", + "files": [ + "index_bg.wasm", + "index.js", + "index.d.ts" + ], + "module": "index.js", + "types": "index.d.ts", + "sideEffects": "false" +} \ No newline at end of file