feat: try wasm build
parent
6967b32222
commit
9e2c2c2951
|
@ -45,6 +45,7 @@ name = "docx-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"xml-rs 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"zip 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"zip 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,26 @@
|
||||||
|
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([[1],{
|
||||||
|
|
||||||
|
/***/ "./pkg/index.js":
|
||||||
|
/*!**********************!*\
|
||||||
|
!*** ./pkg/index.js ***!
|
||||||
|
\**********************/
|
||||||
|
/*! exports provided: createDocx, StyleType, Docx, __wbindgen_throw */
|
||||||
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
eval("__webpack_require__.r(__webpack_exports__);\n/* WEBPACK VAR INJECTION */(function(TextDecoder) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"createDocx\", function() { return createDocx; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"StyleType\", function() { return StyleType; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Docx\", function() { return Docx; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"__wbindgen_throw\", function() { return __wbindgen_throw; });\n/* harmony import */ var _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index_bg.wasm */ \"./pkg/index_bg.wasm\");\n\n\n/**\n* @returns {Docx}\n*/\nfunction createDocx() {\n const ret = _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"createDocx\"]();\n return Docx.__wrap(ret);\n}\n\nfunction _assertNum(n) {\n if (typeof(n) !== 'number') throw new Error('expected a number argument');\n}\n\nlet cachegetInt32Memory = null;\nfunction getInt32Memory() {\n if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer) {\n cachegetInt32Memory = new Int32Array(_index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer);\n }\n return cachegetInt32Memory;\n}\n\nlet cachegetUint8Memory = null;\nfunction getUint8Memory() {\n if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer) {\n cachegetUint8Memory = new Uint8Array(_index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"memory\"].buffer);\n }\n return cachegetUint8Memory;\n}\n\nfunction getArrayU8FromWasm(ptr, len) {\n return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);\n}\n\nlet cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });\n\ncachedTextDecoder.decode();\n\nfunction getStringFromWasm(ptr, len) {\n return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));\n}\n/**\n*/\nconst StyleType = Object.freeze({ Paragraph:0,Character:1, });\n/**\n*/\nclass Docx {\n\n constructor() {\n throw new Error('cannot invoke `new` directly');\n }\n\n static __wrap(ptr) {\n const obj = Object.create(Docx.prototype);\n obj.ptr = ptr;\n\n return obj;\n }\n\n free() {\n const ptr = this.ptr;\n this.ptr = 0;\n\n _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"__wbg_docx_free\"](ptr);\n }\n /**\n * @returns {Docx}\n */\n add_paragraph() {\n if (this.ptr == 0) throw new Error('Attempt to use a moved value');\n const ptr = this.ptr;\n this.ptr = 0;\n _assertNum(ptr);\n const ret = _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"docx_add_paragraph\"](ptr);\n return Docx.__wrap(ret);\n }\n /**\n * @returns {Uint8Array}\n */\n build() {\n const retptr = 8;\n if (this.ptr == 0) throw new Error('Attempt to use a moved value');\n _assertNum(retptr);\n _assertNum(this.ptr);\n const ret = _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"docx_build\"](retptr, this.ptr);\n const memi32 = getInt32Memory();\n const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();\n _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"__wbindgen_free\"](memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1);\n return v0;\n }\n /**\n * @param {number} t\n */\n test(t) {\n if (this.ptr == 0) throw new Error('Attempt to use a moved value');\n _assertNum(this.ptr);\n _assertNum(t);\n _index_bg_wasm__WEBPACK_IMPORTED_MODULE_0__[\"docx_test\"](this.ptr, t);\n }\n}\n\nconst __wbindgen_throw = function(arg0, arg1) {\n throw new Error(getStringFromWasm(arg0, arg1));\n};\n\n\n/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! text-encoding */ \"./node_modules/text-encoding/index.js\")[\"TextDecoder\"]))\n\n//# sourceURL=webpack:///./pkg/index.js?");
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./pkg/index_bg.wasm":
|
||||||
|
/*!***************************!*\
|
||||||
|
!*** ./pkg/index_bg.wasm ***!
|
||||||
|
\***************************/
|
||||||
|
/*! exports provided: memory, __rustc_debug_gdb_scripts_section__, __wbg_docx_free, createDocx, docx_add_paragraph, docx_build, docx_test, __wbindgen_free */
|
||||||
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
eval("\"use strict\";\n// Instantiate WebAssembly module\nvar wasmExports = __webpack_require__.w[module.i];\n__webpack_require__.r(exports);\n// export exports from WebAssembly module\nfor(var name in wasmExports) if(name != \"__webpack_init__\") exports[name] = wasmExports[name];\n// exec imports from WebAssembly module (for esm order)\n/* harmony import */ var m0 = __webpack_require__(/*! ./index.js */ \"./pkg/index.js\");\n\n\n// exec wasm module\nwasmExports[\"__webpack_init__\"]()\n\n//# sourceURL=webpack:///./pkg/index_bg.wasm?");
|
||||||
|
|
||||||
|
/***/ })
|
||||||
|
|
||||||
|
}]);
|
Binary file not shown.
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Webpack App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"
|
||||||
|
></script>
|
||||||
|
<script type="text/javascript" src="index.js"></script></body>
|
||||||
|
</html>
|
|
@ -0,0 +1,267 @@
|
||||||
|
/******/ (function(modules) { // webpackBootstrap
|
||||||
|
/******/ // install a JSONP callback for chunk loading
|
||||||
|
/******/ function webpackJsonpCallback(data) {
|
||||||
|
/******/ var chunkIds = data[0];
|
||||||
|
/******/ var moreModules = data[1];
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ // add "moreModules" to the modules object,
|
||||||
|
/******/ // then flag all "chunkIds" as loaded and fire callback
|
||||||
|
/******/ var moduleId, chunkId, i = 0, resolves = [];
|
||||||
|
/******/ for(;i < chunkIds.length; i++) {
|
||||||
|
/******/ chunkId = chunkIds[i];
|
||||||
|
/******/ if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) {
|
||||||
|
/******/ resolves.push(installedChunks[chunkId][0]);
|
||||||
|
/******/ }
|
||||||
|
/******/ installedChunks[chunkId] = 0;
|
||||||
|
/******/ }
|
||||||
|
/******/ for(moduleId in moreModules) {
|
||||||
|
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
|
||||||
|
/******/ modules[moduleId] = moreModules[moduleId];
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/ if(parentJsonpFunction) parentJsonpFunction(data);
|
||||||
|
/******/
|
||||||
|
/******/ while(resolves.length) {
|
||||||
|
/******/ resolves.shift()();
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ // The module cache
|
||||||
|
/******/ var installedModules = {};
|
||||||
|
/******/
|
||||||
|
/******/ // object to store loaded and loading chunks
|
||||||
|
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
|
||||||
|
/******/ // Promise = chunk loading, 0 = chunk loaded
|
||||||
|
/******/ var installedChunks = {
|
||||||
|
/******/ "main": 0
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ // script path function
|
||||||
|
/******/ function jsonpScriptSrc(chunkId) {
|
||||||
|
/******/ return __webpack_require__.p + "" + chunkId + ".index.js"
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/ // object to store loaded and loading wasm modules
|
||||||
|
/******/ var installedWasmModules = {};
|
||||||
|
/******/
|
||||||
|
/******/ function promiseResolve() { return Promise.resolve(); }
|
||||||
|
/******/
|
||||||
|
/******/ var wasmImportObjects = {
|
||||||
|
/******/ "./pkg/index_bg.wasm": function() {
|
||||||
|
/******/ return {
|
||||||
|
/******/ "./index.js": {
|
||||||
|
/******/ "__wbindgen_throw": function(p0i32,p1i32) {
|
||||||
|
/******/ return installedModules["./pkg/index.js"].exports["__wbindgen_throw"](p0i32,p1i32);
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/ };
|
||||||
|
/******/ },
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // The require function
|
||||||
|
/******/ function __webpack_require__(moduleId) {
|
||||||
|
/******/
|
||||||
|
/******/ // Check if module is in cache
|
||||||
|
/******/ if(installedModules[moduleId]) {
|
||||||
|
/******/ return installedModules[moduleId].exports;
|
||||||
|
/******/ }
|
||||||
|
/******/ // Create a new module (and put it into the cache)
|
||||||
|
/******/ var module = installedModules[moduleId] = {
|
||||||
|
/******/ i: moduleId,
|
||||||
|
/******/ l: false,
|
||||||
|
/******/ exports: {}
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // Execute the module function
|
||||||
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||||
|
/******/
|
||||||
|
/******/ // Flag the module as loaded
|
||||||
|
/******/ module.l = true;
|
||||||
|
/******/
|
||||||
|
/******/ // Return the exports of the module
|
||||||
|
/******/ return module.exports;
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/ // This file contains only the entry chunk.
|
||||||
|
/******/ // The chunk loading function for additional chunks
|
||||||
|
/******/ __webpack_require__.e = function requireEnsure(chunkId) {
|
||||||
|
/******/ var promises = [];
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ // JSONP chunk loading for javascript
|
||||||
|
/******/
|
||||||
|
/******/ var installedChunkData = installedChunks[chunkId];
|
||||||
|
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
|
||||||
|
/******/
|
||||||
|
/******/ // a Promise means "currently loading".
|
||||||
|
/******/ if(installedChunkData) {
|
||||||
|
/******/ promises.push(installedChunkData[2]);
|
||||||
|
/******/ } else {
|
||||||
|
/******/ // setup Promise in chunk cache
|
||||||
|
/******/ var promise = new Promise(function(resolve, reject) {
|
||||||
|
/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject];
|
||||||
|
/******/ });
|
||||||
|
/******/ promises.push(installedChunkData[2] = promise);
|
||||||
|
/******/
|
||||||
|
/******/ // start chunk loading
|
||||||
|
/******/ var script = document.createElement('script');
|
||||||
|
/******/ var onScriptComplete;
|
||||||
|
/******/
|
||||||
|
/******/ script.charset = 'utf-8';
|
||||||
|
/******/ script.timeout = 120;
|
||||||
|
/******/ if (__webpack_require__.nc) {
|
||||||
|
/******/ script.setAttribute("nonce", __webpack_require__.nc);
|
||||||
|
/******/ }
|
||||||
|
/******/ script.src = jsonpScriptSrc(chunkId);
|
||||||
|
/******/
|
||||||
|
/******/ // create error before stack unwound to get useful stacktrace later
|
||||||
|
/******/ var error = new Error();
|
||||||
|
/******/ onScriptComplete = function (event) {
|
||||||
|
/******/ // avoid mem leaks in IE.
|
||||||
|
/******/ script.onerror = script.onload = null;
|
||||||
|
/******/ clearTimeout(timeout);
|
||||||
|
/******/ var chunk = installedChunks[chunkId];
|
||||||
|
/******/ if(chunk !== 0) {
|
||||||
|
/******/ if(chunk) {
|
||||||
|
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
|
||||||
|
/******/ var realSrc = event && event.target && event.target.src;
|
||||||
|
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
|
||||||
|
/******/ error.name = 'ChunkLoadError';
|
||||||
|
/******/ error.type = errorType;
|
||||||
|
/******/ error.request = realSrc;
|
||||||
|
/******/ chunk[1](error);
|
||||||
|
/******/ }
|
||||||
|
/******/ installedChunks[chunkId] = undefined;
|
||||||
|
/******/ }
|
||||||
|
/******/ };
|
||||||
|
/******/ var timeout = setTimeout(function(){
|
||||||
|
/******/ onScriptComplete({ type: 'timeout', target: script });
|
||||||
|
/******/ }, 120000);
|
||||||
|
/******/ script.onerror = script.onload = onScriptComplete;
|
||||||
|
/******/ document.head.appendChild(script);
|
||||||
|
/******/ }
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/ // Fetch + compile chunk loading for webassembly
|
||||||
|
/******/
|
||||||
|
/******/ var wasmModules = {"1":["./pkg/index_bg.wasm"]}[chunkId] || [];
|
||||||
|
/******/
|
||||||
|
/******/ wasmModules.forEach(function(wasmModuleId) {
|
||||||
|
/******/ var installedWasmModuleData = installedWasmModules[wasmModuleId];
|
||||||
|
/******/
|
||||||
|
/******/ // a Promise means "currently loading" or "already loaded".
|
||||||
|
/******/ if(installedWasmModuleData)
|
||||||
|
/******/ promises.push(installedWasmModuleData);
|
||||||
|
/******/ else {
|
||||||
|
/******/ var importObject = wasmImportObjects[wasmModuleId]();
|
||||||
|
/******/ var req = fetch(__webpack_require__.p + "" + {"./pkg/index_bg.wasm":"dc980d6e0664fbb7edfc"}[wasmModuleId] + ".module.wasm");
|
||||||
|
/******/ var promise;
|
||||||
|
/******/ if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {
|
||||||
|
/******/ promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {
|
||||||
|
/******/ return WebAssembly.instantiate(items[0], items[1]);
|
||||||
|
/******/ });
|
||||||
|
/******/ } else if(typeof WebAssembly.instantiateStreaming === 'function') {
|
||||||
|
/******/ promise = WebAssembly.instantiateStreaming(req, importObject);
|
||||||
|
/******/ } else {
|
||||||
|
/******/ var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });
|
||||||
|
/******/ promise = bytesPromise.then(function(bytes) {
|
||||||
|
/******/ return WebAssembly.instantiate(bytes, importObject);
|
||||||
|
/******/ });
|
||||||
|
/******/ }
|
||||||
|
/******/ promises.push(installedWasmModules[wasmModuleId] = promise.then(function(res) {
|
||||||
|
/******/ return __webpack_require__.w[wasmModuleId] = (res.instance || res).exports;
|
||||||
|
/******/ }));
|
||||||
|
/******/ }
|
||||||
|
/******/ });
|
||||||
|
/******/ return Promise.all(promises);
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // expose the modules object (__webpack_modules__)
|
||||||
|
/******/ __webpack_require__.m = modules;
|
||||||
|
/******/
|
||||||
|
/******/ // expose the module cache
|
||||||
|
/******/ __webpack_require__.c = installedModules;
|
||||||
|
/******/
|
||||||
|
/******/ // define getter function for harmony exports
|
||||||
|
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||||
|
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||||
|
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
||||||
|
/******/ }
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // define __esModule on exports
|
||||||
|
/******/ __webpack_require__.r = function(exports) {
|
||||||
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||||
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||||
|
/******/ }
|
||||||
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // create a fake namespace object
|
||||||
|
/******/ // mode & 1: value is a module id, require it
|
||||||
|
/******/ // mode & 2: merge all properties of value into the ns
|
||||||
|
/******/ // mode & 4: return value when already ns object
|
||||||
|
/******/ // mode & 8|1: behave like require
|
||||||
|
/******/ __webpack_require__.t = function(value, mode) {
|
||||||
|
/******/ if(mode & 1) value = __webpack_require__(value);
|
||||||
|
/******/ if(mode & 8) return value;
|
||||||
|
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
||||||
|
/******/ var ns = Object.create(null);
|
||||||
|
/******/ __webpack_require__.r(ns);
|
||||||
|
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
||||||
|
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
||||||
|
/******/ return ns;
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||||
|
/******/ __webpack_require__.n = function(module) {
|
||||||
|
/******/ var getter = module && module.__esModule ?
|
||||||
|
/******/ function getDefault() { return module['default']; } :
|
||||||
|
/******/ function getModuleExports() { return module; };
|
||||||
|
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||||
|
/******/ return getter;
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // Object.prototype.hasOwnProperty.call
|
||||||
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||||
|
/******/
|
||||||
|
/******/ // __webpack_public_path__
|
||||||
|
/******/ __webpack_require__.p = "";
|
||||||
|
/******/
|
||||||
|
/******/ // on error function for async loading
|
||||||
|
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
|
||||||
|
/******/
|
||||||
|
/******/ // object with all WebAssembly.instance exports
|
||||||
|
/******/ __webpack_require__.w = {};
|
||||||
|
/******/
|
||||||
|
/******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || [];
|
||||||
|
/******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);
|
||||||
|
/******/ jsonpArray.push = webpackJsonpCallback;
|
||||||
|
/******/ jsonpArray = jsonpArray.slice();
|
||||||
|
/******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);
|
||||||
|
/******/ var parentJsonpFunction = oldJsonpFunction;
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ // Load entry module and return exports
|
||||||
|
/******/ return __webpack_require__(__webpack_require__.s = "./index.js");
|
||||||
|
/******/ })
|
||||||
|
/************************************************************************/
|
||||||
|
/******/ ({
|
||||||
|
|
||||||
|
/***/ "./index.js":
|
||||||
|
/*!******************!*\
|
||||||
|
!*** ./index.js ***!
|
||||||
|
\******************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
eval("// Note that a dynamic `import` statement here is required due to\n// webpack/webpack#6615, but in theory `import { greet } from './pkg/hello_world';`\n// will work here one day as well!\nconst rust = Promise.all(/*! import() */[__webpack_require__.e(0), __webpack_require__.e(1)]).then(__webpack_require__.bind(null, /*! ./pkg */ \"./pkg/index.js\"));\n// webpack/webpack#6615, but in theory `import { greet } from './pkg/hello_world';`\n\nrust\n .then(m => {\n let docx = m.createDocx().add_paragraph();\n saveAs(new Blob([docx.build()]), \"example.docx\");\n })\n .catch(console.error);\n\n\n//# sourceURL=webpack:///./index.js?");
|
||||||
|
|
||||||
|
/***/ })
|
||||||
|
|
||||||
|
/******/ });
|
|
@ -8,6 +8,7 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
xml-rs = "0.8.0"
|
xml-rs = "0.8.0"
|
||||||
|
wasm-bindgen = "0.2.50"
|
||||||
zip = { version = "0.5", default-features = false }
|
zip = { version = "0.5", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ContentTypes {}
|
pub struct ContentTypes {}
|
||||||
|
|
||||||
impl ContentTypes {
|
impl ContentTypes {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct AppProps {
|
pub struct AppProps {
|
||||||
config: Option<AppPropsConfig>,
|
config: Option<AppPropsConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct AppPropsConfig {
|
pub struct AppPropsConfig {
|
||||||
template: Option<&'static str>,
|
template: Option<&'static str>,
|
||||||
total_time: Option<usize>,
|
total_time: Option<usize>,
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CoreProps {
|
pub struct CoreProps {
|
||||||
config: Option<CorePropsConfig>,
|
config: Option<CorePropsConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CorePropsConfig {
|
pub struct CorePropsConfig {
|
||||||
created: Option<String>,
|
created: Option<String>,
|
||||||
creator: Option<String>,
|
creator: Option<String>,
|
||||||
|
|
|
@ -5,6 +5,7 @@ pub use self::app::*;
|
||||||
pub use self::core::*;
|
pub use self::core::*;
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(crate) struct DocProps {
|
pub(crate) struct DocProps {
|
||||||
app: AppProps,
|
app: AppProps,
|
||||||
core: CoreProps,
|
core: CoreProps,
|
||||||
|
@ -28,6 +29,7 @@ impl DocProps {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct XMLDocProps {
|
pub struct XMLDocProps {
|
||||||
pub app: Vec<u8>,
|
pub app: Vec<u8>,
|
||||||
pub core: Vec<u8>,
|
pub core: Vec<u8>,
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
use crate::StyleType;
|
use crate::StyleType;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
paragraphs: Vec<Paragraph>,
|
paragraphs: Vec<Paragraph>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Color {
|
pub struct Color {
|
||||||
val: String,
|
val: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::xml_builder::*;
|
||||||
|
|
||||||
use super::run_property_default::*;
|
use super::run_property_default::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct DocDefaults {
|
pub struct DocDefaults {
|
||||||
run_property_default: RunPropertyDefault,
|
run_property_default: RunPropertyDefault,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Name {
|
pub struct Name {
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use super::{Run, RunProperty, Text};
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Paragraph {
|
pub struct Paragraph {
|
||||||
runs: Vec<Run>,
|
runs: Vec<Run>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct ParagraphProperty {}
|
pub struct ParagraphProperty {}
|
||||||
|
|
||||||
// 17.3.1.26
|
// 17.3.1.26
|
||||||
|
|
|
@ -2,6 +2,7 @@ use super::{RunProperty, Text};
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Run {
|
pub struct Run {
|
||||||
run_property: RunProperty,
|
run_property: RunProperty,
|
||||||
text: Text,
|
text: Text,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use super::{Color, Sz};
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RunProperty {
|
pub struct RunProperty {
|
||||||
sz: Option<Sz>,
|
sz: Option<Sz>,
|
||||||
color: Option<Color>,
|
color: Option<Color>,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use super::RunProperty;
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct RunPropertyDefault {
|
pub struct RunPropertyDefault {
|
||||||
run_property: RunProperty,
|
run_property: RunProperty,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::StyleType;
|
||||||
|
|
||||||
use super::{BasedOn, Name, Next, ParagraphProperty, QFormat, RunProperty};
|
use super::{BasedOn, Name, Next, ParagraphProperty, QFormat, RunProperty};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Style {
|
pub struct Style {
|
||||||
style_id: String,
|
style_id: String,
|
||||||
name: Name,
|
name: Name,
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::xml_builder::*;
|
||||||
|
|
||||||
use super::Name;
|
use super::Name;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Sz {
|
pub struct Sz {
|
||||||
val: usize,
|
val: usize,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use super::{RunProperty, Sz};
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
text: String,
|
text: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ mod document;
|
||||||
mod elements;
|
mod elements;
|
||||||
mod rels;
|
mod rels;
|
||||||
mod styles;
|
mod styles;
|
||||||
|
mod xml_docx;
|
||||||
|
|
||||||
pub(crate) use crate::xml_builder::*;
|
pub(crate) use crate::xml_builder::*;
|
||||||
pub(crate) use build_xml::*;
|
pub(crate) use build_xml::*;
|
||||||
|
@ -15,7 +16,9 @@ pub use document::*;
|
||||||
pub use elements::*;
|
pub use elements::*;
|
||||||
pub use rels::*;
|
pub use rels::*;
|
||||||
pub use styles::*;
|
pub use styles::*;
|
||||||
|
pub use xml_docx::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Docx {
|
pub struct Docx {
|
||||||
content_type: ContentTypes,
|
content_type: ContentTypes,
|
||||||
rels: Rels,
|
rels: Rels,
|
||||||
|
@ -41,14 +44,6 @@ impl Default for Docx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct XMLDocx {
|
|
||||||
pub content_type: Vec<u8>,
|
|
||||||
pub rels: Vec<u8>,
|
|
||||||
pub doc_props: XMLDocProps,
|
|
||||||
pub styles: Vec<u8>,
|
|
||||||
pub document: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Docx {
|
impl Docx {
|
||||||
pub fn new() -> Docx {
|
pub fn new() -> Docx {
|
||||||
Default::default()
|
Default::default()
|
||||||
|
@ -59,7 +54,7 @@ impl Docx {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build(&self) -> XMLDocx {
|
pub fn build(&self) -> XMLDocx {
|
||||||
XMLDocx {
|
XMLDocx {
|
||||||
content_type: self.content_type.build(),
|
content_type: self.content_type.build(),
|
||||||
rels: self.rels.build(),
|
rels: self.rels.build(),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Rels {}
|
pub struct Rels {}
|
||||||
|
|
||||||
impl Rels {
|
impl Rels {
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::documents::BuildXML;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
use crate::StyleType;
|
use crate::StyleType;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Styles {
|
pub struct Styles {
|
||||||
doc_defaults: DocDefaults,
|
doc_defaults: DocDefaults,
|
||||||
styles: Vec<Style>,
|
styles: Vec<Style>,
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
use super::XMLDocProps;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct XMLDocx {
|
||||||
|
pub content_type: Vec<u8>,
|
||||||
|
pub rels: Vec<u8>,
|
||||||
|
pub doc_props: XMLDocProps,
|
||||||
|
pub styles: Vec<u8>,
|
||||||
|
pub document: Vec<u8>,
|
||||||
|
}
|
|
@ -4,12 +4,14 @@ mod xml_builder;
|
||||||
mod zipper;
|
mod zipper;
|
||||||
|
|
||||||
pub use documents::*;
|
pub use documents::*;
|
||||||
use types::*;
|
pub use types::*;
|
||||||
use zipper::*;
|
pub use zipper::*;
|
||||||
|
|
||||||
pub fn simple() {
|
pub fn simple() {
|
||||||
let xml = Docx::new()
|
let xml = Docx::new()
|
||||||
.add_paragraph(Paragraph::new().add_run(Run::new("Hello")))
|
.add_paragraph(Paragraph::new().add_run(Run::new("Hello")))
|
||||||
.build();
|
.build();
|
||||||
zip("./test.docx", xml);
|
let path = std::path::Path::new("./test.docx");
|
||||||
|
let file = std::fs::File::create(&path).unwrap();
|
||||||
|
zip(file, xml);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum StyleType {
|
pub enum StyleType {
|
||||||
Paragraph,
|
Paragraph,
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use crate::XMLDocx;
|
use crate::XMLDocx;
|
||||||
|
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
use std::io::Seek;
|
||||||
use zip::write::FileOptions;
|
use zip::write::FileOptions;
|
||||||
|
|
||||||
pub fn zip(filename: &str, xml: XMLDocx) -> zip::result::ZipResult<()> {
|
pub fn zip<W>(w: W, xml: XMLDocx) -> zip::result::ZipResult<()>
|
||||||
let path = std::path::Path::new(filename);
|
where
|
||||||
let file = std::fs::File::create(&path).unwrap();
|
W: Write + Seek,
|
||||||
let mut zip = zip::ZipWriter::new(file);
|
{
|
||||||
|
let mut zip = zip::ZipWriter::new(w);
|
||||||
|
|
||||||
zip.add_directory("word/", Default::default())?;
|
zip.add_directory("word/", Default::default())?;
|
||||||
zip.add_directory("word/_rels", Default::default())?;
|
zip.add_directory("word/_rels", Default::default())?;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>Webpack App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"
|
||||||
|
></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -6,10 +6,7 @@ const rust = import("./pkg");
|
||||||
|
|
||||||
rust
|
rust
|
||||||
.then(m => {
|
.then(m => {
|
||||||
m.greet("World!");
|
let docx = m.createDocx().add_paragraph();
|
||||||
let hoge = m.create(2);
|
saveAs(new Blob([docx.build()]), "example.docx");
|
||||||
console.log(hoge);
|
|
||||||
hoge.add();
|
|
||||||
hoge.log();
|
|
||||||
})
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
|
|
|
@ -1,37 +1,34 @@
|
||||||
extern crate docx_core;
|
use docx_core;
|
||||||
|
|
||||||
use docx_core::*;
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern "C" {
|
|
||||||
fn alert(s: &str);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
pub fn greet(name: &str) {
|
|
||||||
alert(&format!("Hello, {}!", name));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Hoge {
|
pub struct Docx(docx_core::Docx);
|
||||||
pub inner: u32,
|
|
||||||
pub fuga: u32,
|
#[wasm_bindgen]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub fn createDocx() -> Docx {
|
||||||
|
Docx(docx_core::Docx::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn create(inner: u32) -> Hoge {
|
impl Docx {
|
||||||
Hoge { inner, fuga: 0 }
|
pub fn add_paragraph(mut self) -> Self {
|
||||||
|
self.0 = self
|
||||||
|
.0
|
||||||
|
.add_paragraph(docx_core::Paragraph::new().add_run(docx_core::Run::new("Hello")));
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
pub fn build(&self) -> Vec<u8> {
|
||||||
impl Hoge {
|
let buf = Vec::new();
|
||||||
pub fn add(&mut self) {
|
let mut cur = std::io::Cursor::new(buf);
|
||||||
self.fuga = 10;
|
let b = self.0.build();
|
||||||
|
docx_core::zip(&mut cur, b).unwrap();
|
||||||
|
cur.into_inner()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn log(&self) {
|
pub fn test(&self, t: docx_core::StyleType) {
|
||||||
alert(&format!("Hello, {:?}!", self));
|
()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ module.exports = {
|
||||||
filename: "index.js"
|
filename: "index.js"
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new HtmlWebpackPlugin(),
|
new HtmlWebpackPlugin({ template: "assets/template.html" }),
|
||||||
new WasmPackPlugin({
|
new WasmPackPlugin({
|
||||||
crateDirectory: path.resolve(__dirname, ".")
|
crateDirectory: path.resolve(__dirname, ".")
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue