@senlinz/import-export-wasm 0.1.0-beta.23 → 0.1.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -9
- package/README.zh.md +87 -0
- package/package.json +4 -3
- package/pkg/imexport_wasm.d.ts +4 -4
- package/pkg/imexport_wasm.js +1 -1
- package/pkg/imexport_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,13 +1,87 @@
|
|
|
1
1
|
# @senlinz/import-export-wasm
|
|
2
|
-
**@senlinz/import-export-wasm** is the Rust WebAssembly core library for the **@senlinz/import-export** library. It provides the core logic for handling Excel data in browser environments.
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Direct Rust/WebAssembly bindings for importing, exporting, and templating Excel workbooks.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
- Rust WebAssembly core for efficient Excel data handling.
|
|
8
|
-
- Read using [calamine](https://docs.rs/calamine/).
|
|
9
|
-
- Write using [rust_xlsxwriter](https://docs.rs/rust_xlsxwriter/).
|
|
5
|
+
[中文文档](./README.zh.md)
|
|
10
6
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @senlinz/import-export-wasm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Initialization
|
|
14
|
+
|
|
15
|
+
Build the package and load the generated module in the browser:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import init, {
|
|
19
|
+
createTemplate,
|
|
20
|
+
exportData,
|
|
21
|
+
importData,
|
|
22
|
+
ExcelInfo,
|
|
23
|
+
ExcelColumnInfo,
|
|
24
|
+
ExcelData,
|
|
25
|
+
ExcelRowData,
|
|
26
|
+
ExcelColumnData,
|
|
27
|
+
} from '@senlinz/import-export-wasm';
|
|
28
|
+
|
|
29
|
+
await init();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Direct WASM usage
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const info = new ExcelInfo(
|
|
36
|
+
'TomAndJerry',
|
|
37
|
+
'sheet1',
|
|
38
|
+
[
|
|
39
|
+
new ExcelColumnInfo('name', 'Name'),
|
|
40
|
+
new ExcelColumnInfo('age', 'Age').withDataType('number'),
|
|
41
|
+
new ExcelColumnInfo('category', 'Category').withAllowedValues(['Cat', 'Mouse']),
|
|
42
|
+
],
|
|
43
|
+
'senlinz',
|
|
44
|
+
'2024-11-01T08:00:00',
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const template = createTemplate(info);
|
|
48
|
+
|
|
49
|
+
const data = new ExcelData([
|
|
50
|
+
new ExcelRowData([
|
|
51
|
+
new ExcelColumnData('name', 'Tom'),
|
|
52
|
+
new ExcelColumnData('age', '12'),
|
|
53
|
+
new ExcelColumnData('category', 'Cat'),
|
|
54
|
+
]),
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
const workbook = await exportData(info, data);
|
|
58
|
+
const imported = importData(info, workbook);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Supported schema rules
|
|
62
|
+
|
|
63
|
+
- Column keys must be unique.
|
|
64
|
+
- Header names must be non-empty.
|
|
65
|
+
- Supported `dataType` values are `text`, `number`, `date`, and `image`.
|
|
66
|
+
- Parent columns must be declared before child columns.
|
|
67
|
+
- `dataGroupParent` values must refer to a previously declared `dataGroup`.
|
|
68
|
+
|
|
69
|
+
## Direct WASM examples
|
|
70
|
+
|
|
71
|
+
- [Browser example](./examples/direct-browser.html)
|
|
72
|
+
|
|
73
|
+
The browser example is covered by Playwright tests in [`./tests/wasm.test.js`](./tests/wasm.test.js).
|
|
74
|
+
|
|
75
|
+
## Runtime notes
|
|
76
|
+
|
|
77
|
+
- Browser usage requires the generated JS/WASM assets from `wasm-pack build`.
|
|
78
|
+
- Image export requires `.withImageFetcher(...)`.
|
|
79
|
+
- Invalid schemas and invalid exported number/date values now fail with explicit errors.
|
|
80
|
+
|
|
81
|
+
## Development
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
cargo test --lib
|
|
85
|
+
wasm-pack build --release --target web
|
|
86
|
+
pnpm e2e-test
|
|
87
|
+
```
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @senlinz/import-export-wasm
|
|
2
|
+
|
|
3
|
+
用于导入、导出和生成 Excel 工作簿的 Rust / WebAssembly 直接绑定。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @senlinz/import-export-wasm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 初始化
|
|
14
|
+
|
|
15
|
+
先构建包,再在浏览器中加载生成的模块:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import init, {
|
|
19
|
+
createTemplate,
|
|
20
|
+
exportData,
|
|
21
|
+
importData,
|
|
22
|
+
ExcelInfo,
|
|
23
|
+
ExcelColumnInfo,
|
|
24
|
+
ExcelData,
|
|
25
|
+
ExcelRowData,
|
|
26
|
+
ExcelColumnData,
|
|
27
|
+
} from '@senlinz/import-export-wasm';
|
|
28
|
+
|
|
29
|
+
await init();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 直接使用 WASM
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const info = new ExcelInfo(
|
|
36
|
+
'TomAndJerry',
|
|
37
|
+
'sheet1',
|
|
38
|
+
[
|
|
39
|
+
new ExcelColumnInfo('name', 'Name'),
|
|
40
|
+
new ExcelColumnInfo('age', 'Age').withDataType('number'),
|
|
41
|
+
new ExcelColumnInfo('category', 'Category').withAllowedValues(['Cat', 'Mouse']),
|
|
42
|
+
],
|
|
43
|
+
'senlinz',
|
|
44
|
+
'2024-11-01T08:00:00',
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const template = createTemplate(info);
|
|
48
|
+
|
|
49
|
+
const data = new ExcelData([
|
|
50
|
+
new ExcelRowData([
|
|
51
|
+
new ExcelColumnData('name', 'Tom'),
|
|
52
|
+
new ExcelColumnData('age', '12'),
|
|
53
|
+
new ExcelColumnData('category', 'Cat'),
|
|
54
|
+
]),
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
const workbook = await exportData(info, data);
|
|
58
|
+
const imported = importData(info, workbook);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 支持的 Schema 规则
|
|
62
|
+
|
|
63
|
+
- 列 key 必须唯一。
|
|
64
|
+
- 表头名称不能为空。
|
|
65
|
+
- `dataType` 仅支持 `text`、`number`、`date`、`image`。
|
|
66
|
+
- 父级列必须先于子级列声明。
|
|
67
|
+
- `dataGroupParent` 必须引用已声明的 `dataGroup`。
|
|
68
|
+
|
|
69
|
+
## 直接 WASM 示例
|
|
70
|
+
|
|
71
|
+
- [浏览器示例](./examples/direct-browser.html)
|
|
72
|
+
|
|
73
|
+
该浏览器示例由 [`./tests/wasm.test.js`](./tests/wasm.test.js) 中的 Playwright 用例覆盖。
|
|
74
|
+
|
|
75
|
+
## 运行时说明
|
|
76
|
+
|
|
77
|
+
- 浏览器使用前需要通过 `wasm-pack build` 生成 JS / WASM 产物。
|
|
78
|
+
- 图片导出需要 `.withImageFetcher(...)`。
|
|
79
|
+
- 非法 schema、非法数字值、非法日期值都会返回明确错误。
|
|
80
|
+
|
|
81
|
+
## 开发
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
cargo test --lib
|
|
85
|
+
wasm-pack build --release --target web
|
|
86
|
+
pnpm e2e-test
|
|
87
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senlinz/import-export-wasm",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.24",
|
|
4
4
|
"description": "Rust WebAssembly for import/export excel files",
|
|
5
5
|
"main": "pkg/imexport_wasm.js",
|
|
6
6
|
"types": "pkg/imexport_wasm.d.ts",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"pkg/imexport_wasm.bg.wasm.d.ts",
|
|
10
10
|
"pkg/imexport_wasm.js",
|
|
11
11
|
"pkg/imexport_wasm.d.ts",
|
|
12
|
-
"README.md"
|
|
12
|
+
"README.md",
|
|
13
|
+
"README.zh.md"
|
|
13
14
|
],
|
|
14
15
|
"author": "senlin",
|
|
15
16
|
"license": "MIT",
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"build": "wasm-pack build --release --target web",
|
|
35
36
|
"publish-dry-run": "pnpm publish --dry-run --no-git-checks",
|
|
36
37
|
"cargo-test": "cargo test --lib",
|
|
37
|
-
"e2e-serve": "wasm-pack build --release --target web -d tests/dist && serve -l 8080
|
|
38
|
+
"e2e-serve": "wasm-pack build --release --target web -d tests/dist && serve -l 8080 .",
|
|
38
39
|
"e2e-test": "playwright test"
|
|
39
40
|
}
|
|
40
41
|
}
|
package/pkg/imexport_wasm.d.ts
CHANGED
|
@@ -246,6 +246,10 @@ export interface InitOutput {
|
|
|
246
246
|
readonly excelinfo_withTitle: (a: number, b: number, c: number) => number;
|
|
247
247
|
readonly excelinfo_withTitleFormat: (a: number, b: number) => number;
|
|
248
248
|
readonly excelinfo_withTitleHeight: (a: number, b: number) => number;
|
|
249
|
+
readonly __wbg_excelrowdata_free: (a: number, b: number) => void;
|
|
250
|
+
readonly __wbg_get_excelrowdata_columns: (a: number) => [number, number];
|
|
251
|
+
readonly __wbg_set_excelrowdata_columns: (a: number, b: number, c: number) => void;
|
|
252
|
+
readonly excelrowdata_new: (a: number, b: number) => number;
|
|
249
253
|
readonly __wbg_excelcolumndata_free: (a: number, b: number) => void;
|
|
250
254
|
readonly __wbg_get_excelcolumndata_children: (a: number) => [number, number];
|
|
251
255
|
readonly __wbg_get_excelcolumndata_key: (a: number) => [number, number];
|
|
@@ -257,10 +261,6 @@ export interface InitOutput {
|
|
|
257
261
|
readonly excelcolumndata_newGroup: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
|
258
262
|
readonly excelcolumndata_newRootGroup: (a: number, b: number, c: number, d: number) => number;
|
|
259
263
|
readonly excelcolumndata_withChildren: (a: number, b: number, c: number) => number;
|
|
260
|
-
readonly __wbg_excelrowdata_free: (a: number, b: number) => void;
|
|
261
|
-
readonly __wbg_get_excelrowdata_columns: (a: number) => [number, number];
|
|
262
|
-
readonly __wbg_set_excelrowdata_columns: (a: number, b: number, c: number) => void;
|
|
263
|
-
readonly excelrowdata_new: (a: number, b: number) => number;
|
|
264
264
|
readonly __wbg_exceldata_free: (a: number, b: number) => void;
|
|
265
265
|
readonly __wbg_get_exceldata_rows: (a: number) => [number, number];
|
|
266
266
|
readonly __wbg_set_exceldata_rows: (a: number, b: number, c: number) => void;
|
package/pkg/imexport_wasm.js
CHANGED
|
@@ -1570,7 +1570,7 @@ function __wbg_get_imports() {
|
|
|
1570
1570
|
return ret;
|
|
1571
1571
|
},
|
|
1572
1572
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
1573
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1573
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 227, function: Function { arguments: [Externref], shim_idx: 381, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
1574
1574
|
const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h1014a67ffc8653bf, wasm_bindgen__convert__closures_____invoke__h70bb320d972e2f25);
|
|
1575
1575
|
return ret;
|
|
1576
1576
|
},
|
|
Binary file
|